mad: Post bitrate tag whenever the bitrate changes
authorSebastian Dröge <sebastian.droege@collabora.co.uk>
Fri, 29 Apr 2011 07:19:19 +0000 (09:19 +0200)
committerSebastian Dröge <sebastian.droege@collabora.co.uk>
Sat, 14 May 2011 10:05:56 +0000 (12:05 +0200)
Also send the layer/mode/emphasis/bitrate tags as an event too.

ext/mad/gstmad.c

index 664ab1b..4d51d71 100644 (file)
@@ -889,6 +889,7 @@ gst_mad_update_info (GstMad * mad)
 {
   struct mad_header *header = &mad->frame.header;
   gboolean changed = FALSE;
+  GstTagList *list = NULL;
 
 #define CHECK_HEADER(h1,str)                                    \
 G_STMT_START{                                                   \
@@ -911,11 +912,9 @@ G_STMT_START{                                                   \
   CHECK_HEADER (layer, "layer");
   CHECK_HEADER (mode, "mode");
   CHECK_HEADER (emphasis, "emphasis");
-  mad->header.bitrate = header->bitrate;
   mad->new_header = FALSE;
 
   if (changed) {
-    GstTagList *list;
     GEnumValue *mode;
     GEnumValue *emphasis;
 
@@ -938,15 +937,29 @@ G_STMT_START{                                                   \
           GST_TAG_AUDIO_CODEC, str, NULL);
       g_free (str);
     }
-    if (!mad->xing_found) {
-      gst_tag_list_add (list, GST_TAG_MERGE_REPLACE,
-          GST_TAG_BITRATE, mad->header.bitrate, NULL);
-    }
-    gst_element_post_message (GST_ELEMENT (mad),
-        gst_message_new_tag (GST_OBJECT (mad), list));
   }
+
+  changed = FALSE;
+  CHECK_HEADER (bitrate, "bitrate");
+  if (!mad->xing_found && changed) {
+    if (!list)
+      list = gst_tag_list_new ();
+    gst_tag_list_add (list, GST_TAG_MERGE_REPLACE,
+        GST_TAG_BITRATE, mad->header.bitrate, NULL);
+  }
+  mad->header.bitrate = header->bitrate;
 #undef CHECK_HEADER
 
+  if (list) {
+    gst_element_post_message (GST_ELEMENT (mad),
+        gst_message_new_tag (GST_OBJECT (mad), gst_tag_list_copy (list)));
+
+    if (mad->need_newsegment)
+      mad->pending_events =
+          g_list_append (mad->pending_events, gst_event_new_tag (list));
+    else
+      gst_pad_push_event (mad->srcpad, gst_event_new_tag (list));
+  }
 }
 
 static gboolean