flacenc: improve sink pad template caps

Removes the need for custom caps query handling and makes it more
correct from the beginning on the template. It is a bit uglier
to read because there is 1 entry per channel but makes code easier
to maintain.
This commit is contained in:
Thiago Santos 2015-08-16 13:03:36 -03:00
parent 5838940681
commit 3553493d96

View File

@ -97,31 +97,12 @@ static const GstAudioChannelPosition channel_positions[8][8] = {
GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT}
};
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
#define FORMATS "{ S24LE, S24_32LE, S16LE, S8 } "
#else
#define FORMATS "{ S24BE, S24_32BE, S16BE, S8 } "
#endif
#define FLAC_SINK_CAPS \
"audio/x-raw, " \
"format = (string) " FORMATS ", " \
"layout = (string) interleaved, " \
"rate = (int) [ 1, 655350 ], " \
"channels = (int) [ 1, 8 ]"
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("audio/x-flac")
);
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS (FLAC_SINK_CAPS)
);
enum
{
PROP_0,
@ -163,6 +144,8 @@ static gboolean gst_flac_enc_sink_event (GstAudioEncoder * enc,
static void gst_flac_enc_finalize (GObject * object);
static GstCaps *gst_flac_enc_generate_sink_caps (void);
static gboolean gst_flac_enc_update_quality (GstFlacEnc * flacenc,
gint quality);
static void gst_flac_enc_set_property (GObject * object, guint prop_id,
@ -246,6 +229,8 @@ gst_flac_enc_class_init (GstFlacEncClass * klass)
GObjectClass *gobject_class;
GstElementClass *gstelement_class;
GstAudioEncoderClass *base_class;
GstCaps *sink_caps;
GstPadTemplate *sink_templ;
gobject_class = (GObjectClass *) klass;
gstelement_class = (GstElementClass *) klass;
@ -356,8 +341,12 @@ gst_flac_enc_class_init (GstFlacEncClass * klass)
gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&src_factory));
gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&sink_factory));
sink_caps = gst_flac_enc_generate_sink_caps ();
sink_templ = gst_pad_template_new ("sink",
GST_PAD_SINK, GST_PAD_ALWAYS, sink_caps);
gst_element_class_add_pad_template (gstelement_class, sink_templ);
gst_caps_unref (sink_caps);
gst_element_class_set_static_metadata (gstelement_class, "FLAC audio encoder",
"Codec/Encoder/Audio",
@ -718,16 +707,9 @@ gst_flac_enc_set_metadata (GstFlacEnc * flacenc, GstAudioInfo * info,
}
static GstCaps *
gst_flac_enc_getcaps (GstAudioEncoder * enc, GstCaps * filter)
gst_flac_enc_generate_sink_caps (void)
{
GstCaps *ret = NULL, *caps = NULL;
GstPad *pad;
pad = GST_AUDIO_ENCODER_SINK_PAD (enc);
if (gst_pad_has_current_caps (pad)) {
ret = gst_pad_get_current_caps (pad);
} else {
GstCaps *ret;
gint i;
GValue v_list = { 0, };
GValue v = { 0, };
@ -736,6 +718,7 @@ gst_flac_enc_getcaps (GstAudioEncoder * enc, GstCaps * filter)
g_value_init (&v_list, GST_TYPE_LIST);
g_value_init (&v, G_TYPE_STRING);
/* Use system's endianness */
g_value_set_static_string (&v, "S8");
gst_value_list_append_value (&v_list, &v);
g_value_set_static_string (&v, GST_AUDIO_NE (S16));
@ -770,6 +753,22 @@ gst_flac_enc_getcaps (GstAudioEncoder * enc, GstCaps * filter)
gst_caps_append_structure (ret, s2);
}
gst_structure_free (s);
return ret;
}
static GstCaps *
gst_flac_enc_getcaps (GstAudioEncoder * enc, GstCaps * filter)
{
GstCaps *ret = NULL, *caps = NULL;
GstPad *pad;
pad = GST_AUDIO_ENCODER_SINK_PAD (enc);
if (gst_pad_has_current_caps (pad)) {
ret = gst_pad_get_current_caps (pad);
} else {
ret = gst_pad_get_pad_template_caps (pad);
}
GST_DEBUG_OBJECT (pad, "Return caps %" GST_PTR_FORMAT, ret);