x264enc: Select stream-format based on caps

Makes x264 select its stream-format based on what's available
on caps, the user selected option will be chosen as a fallback
when both options are available.

https://bugzilla.gnome.org/show_bug.cgi?id=644233
This commit is contained in:
Thiago Santos 2011-06-13 23:24:27 -03:00 committed by Olivier Crête
parent ac47d20fae
commit 7aafba6f82
2 changed files with 33 additions and 2 deletions

View file

@ -218,6 +218,13 @@ static GString *x264enc_defaults;
#define ARG_PSY_TUNE_DEFAULT 0 /* no psy tuning */
#define ARG_TUNE_DEFAULT 0 /* no tuning */
enum
{
GST_X264_ENC_STREAM_FORMAT_FROM_PROPERTY,
GST_X264_ENC_STREAM_FORMAT_AVC,
GST_X264_ENC_STREAM_FORMAT_BYTE_STREAM
};
enum
{
GST_X264_ENC_PASS_CBR = 0,
@ -940,6 +947,7 @@ gst_x264_enc_reset (GstX264Enc * encoder)
encoder->x264enc = NULL;
encoder->width = 0;
encoder->height = 0;
encoder->current_byte_stream = GST_X264_ENC_STREAM_FORMAT_FROM_PROPERTY;
GST_OBJECT_LOCK (encoder);
encoder->i_type = X264_TYPE_AUTO;
@ -1445,7 +1453,14 @@ gst_x264_enc_set_src_caps (GstX264Enc * encoder, GstPad * pad, GstCaps * caps)
structure = gst_caps_get_structure (outcaps, 0);
if (!encoder->byte_stream) {
if (encoder->current_byte_stream == GST_X264_ENC_STREAM_FORMAT_FROM_PROPERTY) {
if (encoder->byte_stream) {
encoder->current_byte_stream = GST_X264_ENC_STREAM_FORMAT_BYTE_STREAM;
} else {
encoder->current_byte_stream = GST_X264_ENC_STREAM_FORMAT_AVC;
}
}
if (encoder->current_byte_stream == GST_X264_ENC_STREAM_FORMAT_AVC) {
buf = gst_x264_enc_header_buf (encoder);
if (buf != NULL) {
gst_caps_set_simple (outcaps, "codec_data", GST_TYPE_BUFFER, buf, NULL);
@ -1566,6 +1581,7 @@ gst_x264_enc_sink_set_caps (GstPad * pad, GstCaps * caps)
GstStructure *s;
const gchar *profile;
const gchar *level;
const gchar *bytestream;
if (gst_caps_is_empty (allowed_caps)) {
gst_caps_unref (allowed_caps);
@ -1631,6 +1647,18 @@ gst_x264_enc_sink_set_caps (GstPad * pad, GstCaps * caps)
}
}
bytestream = gst_structure_get_string (s, "stream-format");
encoder->current_byte_stream = GST_X264_ENC_STREAM_FORMAT_FROM_PROPERTY;
if (bytestream) {
if (!strcmp (bytestream, "avc")) {
encoder->current_byte_stream = GST_X264_ENC_STREAM_FORMAT_AVC;
} else if (!strcmp (profile, "byte-stream")) {
encoder->current_byte_stream = GST_X264_ENC_STREAM_FORMAT_BYTE_STREAM;
} else {
/* means we have both in caps and _FROM_PROPERTY should be the option */
}
}
gst_caps_unref (allowed_caps);
}
@ -1904,7 +1932,9 @@ gst_x264_enc_encode_frame (GstX264Enc * encoder, x264_picture_t * pic_in,
nal_size =
x264_nal_encode (encoder->buffer + i_size + 4, &i_data, 0, &nal[i]);
if (encoder->byte_stream)
g_assert (encoder->current_byte_stream !=
GST_X264_ENC_STREAM_FORMAT_FROM_PROPERTY);
if (encoder->current_byte_stream == GST_X264_ENC_STREAM_FORMAT_BYTE_STREAM)
GST_WRITE_UINT32_BE (encoder->buffer + i_size, 1);
else
GST_WRITE_UINT32_BE (encoder->buffer + i_size, nal_size);

View file

@ -52,6 +52,7 @@ struct _GstX264Enc
x264_t *x264enc;
x264_param_t x264param;
gint current_byte_stream;
/* properties */
guint threads;