Implement encoder usage with outputs

- Make it so that encoders can be assigned to outputs.  If an encoder
   is destroyed, it will automatically remove itself from that output.
   I specifically didn't want to do reference counting because it leaves
   too much potential for unchecked references and it just felt like it
   would be more trouble than it's worth.

 - Add a 'flags' value to the output definition structure.  This lets
   the output specify if it uses video/audio, and whether the output is
   meant to be used with OBS encoders or not.

 - Remove boilerplate code for outputs.  This makes it easier to program
   outputs.  The boilerplate code involved before was mostly just
   involving connecting to the audio/video data streams directly in each
   output plugin.

   Instead of doing that, simply add plugin callback functions for
   receiving video/audio (either encoded or non-encoded, whichever it's
   set to use), and then call obs_output_begin_data_capture and
   obs_output_end_data_capture to automatically handle setting up
   connections to raw or encoded video/audio streams for the plugin.

 - Remove 'active' function from output callbacks, as it's no longer
   really needed now that the libobs output context automatically knows
   when the output is active or not.

 - Make it so that an encoder cannot be destroyed until all data
   connections to the encoder have been removed.

 - Change the 'start' and 'stop' functions in the encoder interface to
   just an 'initialize' callback, which initializes the encoder.

 - Make it so that the encoder must be initialized first before the data
   stream can be started.  The reason why initialization was separated
   from starting the encoder stream was because we need to be able to
   check that the settings used with the encoder *can* be used first.

   This problem was especially annoying if you had both video/audio
   encoding.  Before, you'd have to check the return value from
   obs_encoder_start, and if that second encoder fails, then you
   basically had to stop the first encoder again, making for
   unnecessary boilerplate code whenever starting up two encoders.
This commit is contained in:
jp9000
2014-03-27 21:50:15 -07:00
parent a439177a58
commit 6da26a3a1c
9 changed files with 487 additions and 106 deletions

View File

@@ -741,19 +741,11 @@ static void *write_thread(void *data)
static bool try_connect(struct ffmpeg_output *output)
{
video_t video = obs_video();
audio_t audio = obs_audio();
const char *filename_test;
obs_data_t settings;
int audio_bitrate, video_bitrate;
int ret;
if (!video || !audio) {
blog(LOG_WARNING, "ffmpeg_output_start: audio and video must "
"both be active (as of this writing)");
return false;
}
settings = obs_output_get_settings(output->output);
filename_test = obs_data_getstring(settings, "filename");
video_bitrate = (int)obs_data_getint(settings, "video_bitrate");
@@ -785,8 +777,9 @@ static bool try_connect(struct ffmpeg_output *output)
return false;
}
video_output_connect(video, &vsi, receive_video, output);
audio_output_connect(audio, &aci, receive_audio, output);
obs_output_set_video_conversion(output->output, &vsi);
obs_output_set_audio_conversion(output->output, &aci);
obs_output_begin_data_capture(output->output, 0);
output->write_thread_active = true;
return true;
}
@@ -826,8 +819,7 @@ static void ffmpeg_output_stop(void *data)
struct ffmpeg_output *output = data;
if (output->active) {
video_output_disconnect(obs_video(), receive_video, data);
audio_output_disconnect(obs_audio(), receive_audio, data);
obs_output_end_data_capture(output->output);
if (output->write_thread_active) {
os_event_signal(output->stop_event);
@@ -848,18 +840,14 @@ static void ffmpeg_output_stop(void *data)
}
}
static bool ffmpeg_output_active(void *data)
{
struct ffmpeg_output *output = data;
return output->active;
}
struct obs_output_info ffmpeg_output = {
.id = "ffmpeg_output",
.getname = ffmpeg_output_getname,
.create = ffmpeg_output_create,
.destroy = ffmpeg_output_destroy,
.start = ffmpeg_output_start,
.stop = ffmpeg_output_stop,
.active = ffmpeg_output_active
.id = "ffmpeg_output",
.flags = OBS_OUTPUT_AUDIO | OBS_OUTPUT_VIDEO,
.getname = ffmpeg_output_getname,
.create = ffmpeg_output_create,
.destroy = ffmpeg_output_destroy,
.start = ffmpeg_output_start,
.stop = ffmpeg_output_stop,
.raw_video = receive_video,
.raw_audio = receive_audio,
};