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

@@ -17,10 +17,19 @@
#pragma once
#define OBS_OUTPUT_VIDEO (1<<0)
#define OBS_OUTPUT_AUDIO (1<<1)
#define OBS_OUTPUT_AV (OBS_OUTPUT_VIDEO | OBS_OUTPUT_AUDIO)
#define OBS_OUTPUT_ENCODED (1<<2)
struct encoder_packet;
struct obs_output_info {
/* required */
const char *id;
uint32_t flags;
const char *(*getname)(const char *locale);
void *(*create)(obs_data_t settings, obs_output_t output);
@@ -29,7 +38,11 @@ struct obs_output_info {
bool (*start)(void *data);
void (*stop)(void *data);
bool (*active)(void *data);
void (*raw_video)(void *data, struct video_data *frame);
void (*raw_audio)(void *data, struct audio_data *frames);
void (*encoded_video)(void *data, struct encoder_packet *packet);
void (*encoded_audio)(void *data, struct encoder_packet *packet);
/* optional */
void (*update)(void *data, obs_data_t settings);