vorbisenc: use more accurate sink pad template caps
authorThiago Santos <thiagoss@osg.samsung.com>
Sun, 16 Aug 2015 15:20:51 +0000 (12:20 -0300)
committerThiago Santos <thiagoss@osg.samsung.com>
Sun, 16 Aug 2015 15:30:30 +0000 (12:30 -0300)
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.

ext/vorbis/gstvorbisenc.c

index 7e9f504..5026527 100644 (file)
 GST_DEBUG_CATEGORY_EXTERN (vorbisenc_debug);
 #define GST_CAT_DEFAULT vorbisenc_debug
 
-static GstStaticPadTemplate vorbis_enc_sink_factory =
-GST_STATIC_PAD_TEMPLATE ("sink",
-    GST_PAD_SINK,
-    GST_PAD_ALWAYS,
-    GST_STATIC_CAPS ("audio/x-raw, "
-        "format = (string) " GST_AUDIO_NE (F32) ", "
-        "layout = (string) interleaved, "
-        "rate = (int) [ 1, 200000 ], " "channels = (int) [ 1, 255 ]")
-    );
-
 static GstStaticPadTemplate vorbis_enc_src_factory =
 GST_STATIC_PAD_TEMPLATE ("src",
     GST_PAD_SRC,
@@ -86,6 +76,7 @@ enum
 };
 
 static GstFlowReturn gst_vorbis_enc_output_buffers (GstVorbisEnc * vorbisenc);
+static GstCaps *gst_vorbis_enc_generate_sink_caps (void);
 
 
 #define MAX_BITRATE_DEFAULT     -1
@@ -101,8 +92,6 @@ static gboolean gst_vorbis_enc_set_format (GstAudioEncoder * enc,
     GstAudioInfo * info);
 static GstFlowReturn gst_vorbis_enc_handle_frame (GstAudioEncoder * enc,
     GstBuffer * in_buf);
-static GstCaps *gst_vorbis_enc_getcaps (GstAudioEncoder * enc,
-    GstCaps * filter);
 static gboolean gst_vorbis_enc_sink_event (GstAudioEncoder * enc,
     GstEvent * event);
 
@@ -125,6 +114,8 @@ gst_vorbis_enc_class_init (GstVorbisEncClass * klass)
   GObjectClass *gobject_class;
   GstElementClass *gstelement_class;
   GstAudioEncoderClass *base_class;
+  GstCaps *sink_caps;
+  GstPadTemplate *sink_templ;
 
   gobject_class = (GObjectClass *) klass;
   gstelement_class = (GstElementClass *) klass;
@@ -165,10 +156,14 @@ gst_vorbis_enc_class_init (GstVorbisEncClass * klass)
           "The last status message", NULL,
           G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
 
+  sink_caps = gst_vorbis_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_add_pad_template (gstelement_class,
       gst_static_pad_template_get (&vorbis_enc_src_factory));
-  gst_element_class_add_pad_template (gstelement_class,
-      gst_static_pad_template_get (&vorbis_enc_sink_factory));
 
   gst_element_class_set_static_metadata (gstelement_class,
       "Vorbis audio encoder", "Codec/Encoder/Audio",
@@ -179,7 +174,6 @@ gst_vorbis_enc_class_init (GstVorbisEncClass * klass)
   base_class->stop = GST_DEBUG_FUNCPTR (gst_vorbis_enc_stop);
   base_class->set_format = GST_DEBUG_FUNCPTR (gst_vorbis_enc_set_format);
   base_class->handle_frame = GST_DEBUG_FUNCPTR (gst_vorbis_enc_handle_frame);
-  base_class->getcaps = GST_DEBUG_FUNCPTR (gst_vorbis_enc_getcaps);
   base_class->sink_event = GST_DEBUG_FUNCPTR (gst_vorbis_enc_sink_event);
   base_class->flush = GST_DEBUG_FUNCPTR (gst_vorbis_enc_flush);
 }
@@ -289,27 +283,6 @@ gst_vorbis_enc_generate_sink_caps (void)
   return caps;
 }
 
-static GstCaps *
-gst_vorbis_enc_getcaps (GstAudioEncoder * enc, GstCaps * filter)
-{
-  GstVorbisEnc *vorbisenc = GST_VORBISENC (enc);
-  GstCaps *caps;
-
-  if (vorbisenc->sinkcaps == NULL)
-    vorbisenc->sinkcaps = gst_vorbis_enc_generate_sink_caps ();
-
-  if (filter) {
-    GstCaps *int_caps = gst_caps_intersect_full (filter, vorbisenc->sinkcaps,
-        GST_CAPS_INTERSECT_FIRST);
-    caps = gst_audio_encoder_proxy_getcaps (enc, int_caps, filter);
-    gst_caps_unref (int_caps);
-  } else {
-    caps = gst_audio_encoder_proxy_getcaps (enc, vorbisenc->sinkcaps, filter);
-  }
-
-  return caps;
-}
-
 static gint64
 gst_vorbis_enc_get_latency (GstVorbisEnc * vorbisenc)
 {