Implement encoder interface (still preliminary)

- Implement OBS encoder interface.  It was previously incomplete, but
   now is reaching some level of completion, though probably should
   still be considered preliminary.

   I had originally implemented it so that encoders only have a 'reset'
   function to reset their parameters, but I felt that having both a
   'start' and 'stop' function would be useful.

   Encoders are now assigned to a specific video/audio media output each
   rather than implicitely assigned to the main obs video/audio
   contexts.  This allows separate encoder contexts that aren't
   necessarily assigned to the main video/audio context (which is useful
   for things such as recording specific sources).  Will probably have
   to do this for regular obs outputs as well.

   When creating an encoder, you must now explicitely state whether that
   encoder is an audio or video encoder.

   Audio and video can optionally be automatically converted depending
   on what the encoder specifies.

   When something 'attaches' to an encoder, the first attachment starts
   the encoder, and the encoder automatically attaches to the media
   output context associated with it.  Subsequent attachments won't have
   the same effect, they will just start receiving the same encoder data
   when the next keyframe plays (along with SEI if any).  When detaching
   from the encoder, the last detachment will fully stop the encoder and
   detach the encoder from the media output context associated with the
   encoder.

   SEI must actually be exported separately; because new encoder
   attachments may not always be at the beginning of the stream, the
   first keyframe they get must have that SEI data in it.  If the
   encoder has SEI data, it needs only add one small function to simply
   query that SEI data, and then that data will be handled automatically
   by libobs for all subsequent encoder attachments.

 - Implement x264 encoder plugin, move x264 files to separate plugin to
   separate necessary dependencies.

 - Change video/audio frame output structures to not use const
   qualifiers to prevent issues with non-const function usage elsewhere.
   This was an issue when writing the x264 encoder, as the x264 encoder
   expects non-const frame data.

   Change stagesurf_map to return a non-const data type to prevent this
   as well.

 - Change full range parameter of video scaler to be an enum rather than
   boolean
This commit is contained in:
jp9000
2014-03-16 16:21:34 -07:00
parent 04d07831cc
commit fd37d9e9a8
36 changed files with 1423 additions and 310 deletions

View File

@@ -5,17 +5,10 @@ include_directories(${Libx264_INCLUDE_DIR})
set(obs-outputs_SOURCES
obs-outputs.c
obs-x264.c
rtmp-stream.c)
set(obs-outputs_HEADERS
obs-outputs.h
obs-x264.h
rtmp-stream.h)
add_library(obs-outputs MODULE
${obs-outputs_SOURCES}
${obs-outputs_HEADERS})
${obs-outputs_SOURCES})
target_link_libraries(obs-outputs
libobs
${Libx264_LIBRARIES})

View File

@@ -1,12 +1,10 @@
#include <string.h>
#include "obs-outputs.h"
#include <obs-module.h>
static const char *outputs[] = {"rtmp_stream"};
OBS_DECLARE_MODULE()
const char *enum_outputs(size_t idx)
bool obs_module_load(uint32_t libobs_ver)
{
if (idx >= sizeof(outputs)/sizeof(const char*))
return NULL;
return outputs[idx];
UNUSED_PARAMETER(libobs_ver);
return true;
}

View File

@@ -1,5 +0,0 @@
#pragma once
#include <util/c99defs.h>
EXPORT const char *enum_outputs(size_t idx);

View File

@@ -1,58 +0,0 @@
/******************************************************************************
Copyright (C) 2013 by Hugh Bailey <obs.jim@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
#include "obs-x264.h"
const char *obs_x264_getname(const char *locale)
{
/* TODO locale lookup */
return "x264 (Software)";
}
struct obs_x264 *obs_x264_create(obs_data_t settings, obs_encoder_t encoder)
{
struct obs_x264 *data = bmalloc(sizeof(struct obs_x264));
}
void obs_x264_destroy(struct obs_x264 *data)
{
}
void obs_x264_update(struct obs_x264 *data, obs_data_t settings)
{
}
void obs_x264_reset(struct obs_x264 *data)
{
}
int obs_x264_encode(struct obs_x264 *data, struct encoder_packet **packets)
{
}
int obs_x264_getheader(struct obs_x264 *data, struct encoder_packet **packets)
{
}
void obs_x264_setbitrate(struct obs_x264 *data, uint32_t bitrate,
uint32_t buffersize)
{
}
void obs_x264_request_keyframe(struct obs_x264 *data)
{
}

View File

@@ -1,49 +0,0 @@
/******************************************************************************
Copyright (C) 2013 by Hugh Bailey <obs.jim@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
#pragma once
#include <util/c99defs.h>
#include <obs.h>
#include <x264.h>
struct obs_x264 {
obs_encoder_t encoder;
x264_param_t params;
x264_t *context;
x264_picture_t pic_out;
};
EXPORT const char *obs_x264_getname(const char *locale);
EXPORT struct obs_x264 *obs_x264_create(obs_data_t settings,
obs_encoder_t encoder);
EXPORT void obs_x264_destroy(struct obs_x264 *data);
EXPORT void obs_x264_update(struct obs_x264 *data, obs_data_t settings);
EXPORT void obs_x264_reset(struct obs_x264 *data);
EXPORT int obs_x264_encode(struct obs_x264 *data,
struct encoder_packet **packets);
EXPORT int obs_x264_getheader(struct obs_x264 *data,
struct encoder_packet **packets);
EXPORT void obs_x264_setbitrate(struct obs_x264 *data, uint32_t bitrate,
uint32_t buffersize);
EXPORT void obs_x264_request_keyframe(struct obs_x264 *data);

View File

@@ -15,36 +15,45 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
#include "rtmp-stream.h"
#include <obs.h>
const char *rtmp_stream_getname(const char *locale)
struct rtmp_stream {
obs_output_t output;
obs_encoder_t video_encoder;
obs_encoder_t audio_encoder;
obs_service_t service;
bool active;
};
static const char *rtmp_stream_getname(const char *locale)
{
/* TODO: locale stuff */
return "RTMP Stream";
}
void *rtmp_stream_create(obs_data_t settings, obs_output_t output)
static void *rtmp_stream_create(obs_data_t settings, obs_output_t output)
{
struct rtmp_stream *stream = bmalloc(sizeof(struct rtmp_stream));
memset(stream, 0, sizeof(struct rtmp_stream));
}
void rtmp_stream_destroy(struct rtmp_stream *stream)
static void rtmp_stream_destroy(struct rtmp_stream *stream)
{
}
void rtmp_stream_update(struct rtmp_stream *stream, obs_data_t settings)
static void rtmp_stream_update(struct rtmp_stream *stream, obs_data_t settings)
{
}
bool rtmp_stream_start(struct rtmp_stream *stream)
static bool rtmp_stream_start(struct rtmp_stream *stream)
{
}
void rtmp_stream_stop(struct rtmp_stream *stream)
static void rtmp_stream_stop(struct rtmp_stream *stream)
{
}
bool rtmp_stream_active(struct rtmp_stream *stream)
static bool rtmp_stream_active(struct rtmp_stream *stream)
{
}

View File

@@ -1,38 +0,0 @@
/******************************************************************************
Copyright (C) 2013 by Hugh Bailey <obs.jim@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
#pragma once
#include <util/c99defs.h>
#include <obs.h>
struct rtmp_stream {
obs_output_t output;
obs_encoder_t video_encoder;
obs_encoder_t audio_encoder;
obs_service_t service;
bool active;
};
EXPORT const char *rtmp_stream_getname(const char *locale);
EXPORT void *rtmp_stream_create(obs_data_t settings, obs_output_t output);
EXPORT void rtmp_stream_destroy(struct rtmp_stream *stream);
EXPORT void rtmp_stream_update(struct rtmp_stream *stream, obs_data_t settings);
EXPORT bool rtmp_stream_start(struct rtmp_stream *stream);
EXPORT void rtmp_stream_stop(struct rtmp_stream *stream);
EXPORT bool rtmp_stream_active(struct rtmp_stream *stream);