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

@@ -34,7 +34,7 @@ struct audio_input {
struct audio_convert_info conversion;
audio_resampler_t resampler;
void (*callback)(void *param, const struct audio_data *data);
void (*callback)(void *param, struct audio_data *data);
void *param;
};
@@ -337,7 +337,8 @@ static bool resample_audio_output(struct audio_input *input,
success = audio_resampler_resample(input->resampler,
output, &frames, &offset,
data->data, data->frames);
(const uint8_t *const *)data->data,
data->frames);
for (size_t i = 0; i < MAX_AV_PLANES; i++)
data->data[i] = output[i];
@@ -455,7 +456,7 @@ static void *audio_thread(void *param)
/* ------------------------------------------------------------------------- */
static size_t audio_get_input_idx(audio_t video,
void (*callback)(void *param, const struct audio_data *data),
void (*callback)(void *param, struct audio_data *data),
void *param)
{
for (size_t i = 0; i < video->inputs.num; i++) {
@@ -500,7 +501,7 @@ static inline bool audio_input_init(struct audio_input *input,
bool audio_output_connect(audio_t audio,
const struct audio_convert_info *conversion,
void (*callback)(void *param, const struct audio_data *data),
void (*callback)(void *param, struct audio_data *data),
void *param)
{
bool success = false;
@@ -542,7 +543,7 @@ bool audio_output_connect(audio_t audio,
}
void audio_output_disconnect(audio_t audio,
void (*callback)(void *param, const struct audio_data *data),
void (*callback)(void *param, struct audio_data *data),
void *param)
{
if (!audio) return;

View File

@@ -63,7 +63,7 @@ enum speaker_layout {
};
struct audio_data {
const uint8_t *data[MAX_AV_PLANES];
uint8_t *data[MAX_AV_PLANES];
uint32_t frames;
uint64_t timestamp;
float volume;
@@ -174,10 +174,10 @@ EXPORT void audio_output_close(audio_t audio);
EXPORT bool audio_output_connect(audio_t video,
const struct audio_convert_info *conversion,
void (*callback)(void *param, const struct audio_data *data),
void (*callback)(void *param, struct audio_data *data),
void *param);
EXPORT void audio_output_disconnect(audio_t video,
void (*callback)(void *param, const struct audio_data *data),
void (*callback)(void *param, struct audio_data *data),
void *param);
EXPORT bool audio_output_active(audio_t audio);

View File

@@ -34,7 +34,7 @@ struct video_input {
struct video_frame frame[MAX_CONVERT_BUFFERS];
int cur_frame;
void (*callback)(void *param, const struct video_data *frame);
void (*callback)(void *param, struct video_data *frame);
void *param;
};
@@ -91,7 +91,8 @@ static inline bool scale_video_output(struct video_input *input,
success = video_scaler_scale(input->scaler,
frame->data, frame->linesize,
data->data, data->linesize);
(const uint8_t * const*)data->data,
data->linesize);
if (success) {
for (size_t i = 0; i < MAX_AV_PLANES; i++) {
@@ -209,7 +210,7 @@ void video_output_close(video_t video)
}
static size_t video_get_input_idx(video_t video,
void (*callback)(void *param, const struct video_data *frame),
void (*callback)(void *param, struct video_data *frame),
void *param)
{
for (size_t i = 0; i < video->inputs.num; i++) {
@@ -259,7 +260,7 @@ static inline bool video_input_init(struct video_input *input,
bool video_output_connect(video_t video,
const struct video_scale_info *conversion,
void (*callback)(void *param, const struct video_data *frame),
void (*callback)(void *param, struct video_data *frame),
void *param)
{
bool success = false;
@@ -300,7 +301,7 @@ bool video_output_connect(video_t video,
}
void video_output_disconnect(video_t video,
void (*callback)(void *param, const struct video_data *frame),
void (*callback)(void *param, struct video_data *frame),
void *param)
{
if (!video || !callback)

View File

@@ -47,7 +47,7 @@ enum video_format {
};
struct video_data {
const uint8_t *data[MAX_AV_PLANES];
uint8_t *data[MAX_AV_PLANES];
uint32_t linesize[MAX_AV_PLANES];
uint64_t timestamp;
};
@@ -82,24 +82,30 @@ static inline bool format_is_yuv(enum video_format format)
}
enum video_scale_type {
VIDEO_SCALE_POINT = 0,
VIDEO_SCALE_FAST_BILINEAR = 1,
VIDEO_SCALE_DEFAULT = VIDEO_SCALE_FAST_BILINEAR,
VIDEO_SCALE_BILINEAR = 2,
VIDEO_SCALE_BICUBIC = 3,
VIDEO_SCALE_DEFAULT,
VIDEO_SCALE_POINT,
VIDEO_SCALE_FAST_BILINEAR,
VIDEO_SCALE_BILINEAR,
VIDEO_SCALE_BICUBIC,
};
enum video_colorspace {
VIDEO_CS_601 = 0,
VIDEO_CS_DEFAULT = VIDEO_CS_601,
VIDEO_CS_709 = 1,
VIDEO_CS_DEFAULT,
VIDEO_CS_601,
VIDEO_CS_709,
};
enum video_range_type {
VIDEO_RANGE_DEFAULT,
VIDEO_RANGE_PARTIAL,
VIDEO_RANGE_FULL
};
struct video_scale_info {
enum video_format format;
uint32_t width;
uint32_t height;
bool full_range;
enum video_range_type range;
enum video_colorspace colorspace;
};
@@ -112,10 +118,10 @@ EXPORT void video_output_close(video_t video);
EXPORT bool video_output_connect(video_t video,
const struct video_scale_info *conversion,
void (*callback)(void *param, const struct video_data *frame),
void (*callback)(void *param, struct video_data *frame),
void *param);
EXPORT void video_output_disconnect(video_t video,
void (*callback)(void *param, const struct video_data *frame),
void (*callback)(void *param, struct video_data *frame),
void *param);
EXPORT bool video_output_active(video_t video);

View File

@@ -46,6 +46,7 @@ static inline enum AVPixelFormat get_ffmpeg_video_format(
static inline int get_ffmpeg_scale_type(enum video_scale_type type)
{
switch (type) {
case VIDEO_SCALE_DEFAULT: return SWS_FAST_BILINEAR;
case VIDEO_SCALE_POINT: return SWS_POINT;
case VIDEO_SCALE_FAST_BILINEAR: return SWS_FAST_BILINEAR;
case VIDEO_SCALE_BILINEAR: return SWS_BILINEAR | SWS_AREA;
@@ -58,13 +59,25 @@ static inline int get_ffmpeg_scale_type(enum video_scale_type type)
static inline const int *get_ffmpeg_coeffs(enum video_colorspace cs)
{
switch (cs) {
case VIDEO_CS_601: return sws_getCoefficients(SWS_CS_ITU601);
case VIDEO_CS_709: return sws_getCoefficients(SWS_CS_ITU709);
case VIDEO_CS_DEFAULT: return sws_getCoefficients(SWS_CS_ITU601);
case VIDEO_CS_601: return sws_getCoefficients(SWS_CS_ITU601);
case VIDEO_CS_709: return sws_getCoefficients(SWS_CS_ITU709);
}
return sws_getCoefficients(SWS_CS_ITU601);
}
static inline int get_ffmpeg_range_type(enum video_range_type type)
{
switch (type) {
case VIDEO_RANGE_DEFAULT: return 0;
case VIDEO_RANGE_PARTIAL: return 0;
case VIDEO_RANGE_FULL: return 1;
}
return 0;
}
#define FIXED_1_0 (1<<16)
int video_scaler_create(video_scaler_t *scaler_out,
@@ -77,6 +90,8 @@ int video_scaler_create(video_scaler_t *scaler_out,
int scale_type = get_ffmpeg_scale_type(type);
const int *coeff_src = get_ffmpeg_coeffs(src->colorspace);
const int *coeff_dst = get_ffmpeg_coeffs(dst->colorspace);
int range_src = get_ffmpeg_range_type(src->range);
int range_dst = get_ffmpeg_range_type(dst->range);
struct video_scaler *scaler;
int ret;
@@ -101,8 +116,8 @@ int video_scaler_create(video_scaler_t *scaler_out,
}
ret = sws_setColorspaceDetails(scaler->swscale,
coeff_src, src->full_range,
coeff_dst, dst->full_range,
coeff_src, range_src,
coeff_dst, range_dst,
0, FIXED_1_0, FIXED_1_0);
if (ret < 0) {
blog(LOG_DEBUG, "video_scaler_create: "