Merge branch 'master' into 0.11
[platform/upstream/gst-plugins-base.git] / ext / theora / gsttheoraparse.c
index ed5e934..a9fedae 100644 (file)
@@ -89,34 +89,26 @@ enum
   PROP_SYNCHRONIZATION_POINTS
 };
 
-GST_BOILERPLATE (GstTheoraParse, gst_theora_parse, GstElement,
-    GST_TYPE_ELEMENT);
+#define gst_theora_parse_parent_class parent_class
+G_DEFINE_TYPE (GstTheoraParse, gst_theora_parse, GST_TYPE_ELEMENT);
 
 static void theora_parse_dispose (GObject * object);
+
+#if 0
 static void theora_parse_get_property (GObject * object, guint prop_id,
     GValue * value, GParamSpec * pspec);
 static void theora_parse_set_property (GObject * object, guint prop_id,
     const GValue * value, GParamSpec * pspec);
+#endif
 
-static GstFlowReturn theora_parse_chain (GstPad * pad, GstBuffer * buffer);
+static GstFlowReturn theora_parse_chain (GstPad * pad, GstObject * parent,
+    GstBuffer * buffer);
 static GstStateChangeReturn theora_parse_change_state (GstElement * element,
     GstStateChange transition);
-static gboolean theora_parse_sink_event (GstPad * pad, GstEvent * event);
-static gboolean theora_parse_src_query (GstPad * pad, GstQuery * query);
-
-static void
-gst_theora_parse_base_init (gpointer g_class)
-{
-  GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
-
-  gst_element_class_add_static_pad_template (element_class,
-      &theora_parse_src_factory);
-  gst_element_class_add_static_pad_template (element_class,
-      &theora_parse_sink_factory);
-  gst_element_class_set_details_simple (element_class,
-      "Theora video parser", "Codec/Parser/Video",
-      "parse raw theora streams", "Andy Wingo <wingo@pobox.com>");
-}
+static gboolean theora_parse_sink_event (GstPad * pad, GstObject * parent,
+    GstEvent * event);
+static gboolean theora_parse_src_query (GstPad * pad, GstObject * parent,
+    GstQuery * query);
 
 static void
 gst_theora_parse_class_init (GstTheoraParseClass * klass)
@@ -125,6 +117,8 @@ gst_theora_parse_class_init (GstTheoraParseClass * klass)
   GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
 
   gobject_class->dispose = theora_parse_dispose;
+
+#if 0
   gobject_class->get_property = theora_parse_get_property;
   gobject_class->set_property = theora_parse_set_property;
 
@@ -143,6 +137,15 @@ gst_theora_parse_class_init (GstTheoraParseClass * klass)
               "Time (either granuletime or buffertime)", 0, G_MAXUINT64, 0,
               G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS),
           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+#endif
+
+  gst_element_class_add_pad_template (gstelement_class,
+      gst_static_pad_template_get (&theora_parse_src_factory));
+  gst_element_class_add_pad_template (gstelement_class,
+      gst_static_pad_template_get (&theora_parse_sink_factory));
+  gst_element_class_set_details_simple (gstelement_class,
+      "Theora video parser", "Codec/Parser/Video",
+      "parse raw theora streams", "Andy Wingo <wingo@pobox.com>");
 
   gstelement_class->change_state = theora_parse_change_state;
 
@@ -151,7 +154,7 @@ gst_theora_parse_class_init (GstTheoraParseClass * klass)
 }
 
 static void
-gst_theora_parse_init (GstTheoraParse * parse, GstTheoraParseClass * g_class)
+gst_theora_parse_init (GstTheoraParse * parse)
 {
   parse->sinkpad =
       gst_pad_new_from_static_template (&theora_parse_sink_factory, "sink");
@@ -176,6 +179,7 @@ theora_parse_dispose (GObject * object)
   G_OBJECT_CLASS (parent_class)->dispose (object);
 }
 
+#if 0
 static void
 theora_parse_set_property (GObject * object, guint prop_id,
     const GValue * value, GParamSpec * pspec)
@@ -253,6 +257,7 @@ theora_parse_get_property (GObject * object, guint prop_id,
       break;
   }
 }
+#endif
 
 static void
 theora_parse_set_header_on_caps (GstTheoraParse * parse, GstCaps * caps)
@@ -271,8 +276,8 @@ theora_parse_set_header_on_caps (GstTheoraParse * parse, GstCaps * caps)
     if (bufs[i] == NULL)
       continue;
 
-    bufs[i] = gst_buffer_make_metadata_writable (bufs[i]);
-    GST_BUFFER_FLAG_SET (bufs[i], GST_BUFFER_FLAG_IN_CAPS);
+    bufs[i] = gst_buffer_make_writable (bufs[i]);
+    GST_BUFFER_FLAG_SET (bufs[i], GST_BUFFER_FLAG_HEADER);
 
     g_value_init (&value, GST_TYPE_BUFFER);
     gst_value_set_buffer (&value, bufs[i]);
@@ -296,7 +301,7 @@ theora_parse_set_streamheader (GstTheoraParse * parse)
 
   g_assert (!parse->streamheader_received);
 
-  caps = gst_caps_make_writable (gst_pad_get_caps (parse->srcpad));
+  caps = gst_caps_make_writable (gst_pad_query_caps (parse->srcpad, NULL));
   theora_parse_set_header_on_caps (parse, caps);
   GST_DEBUG_OBJECT (parse, "here are the caps: %" GST_PTR_FORMAT, caps);
   gst_pad_set_caps (parse->srcpad, caps);
@@ -306,18 +311,21 @@ theora_parse_set_streamheader (GstTheoraParse * parse)
     ogg_packet packet;
     GstBuffer *buf;
     int ret;
+    GstMapInfo map;
 
     buf = parse->streamheader[i];
     if (buf == NULL)
       continue;
 
-    packet.packet = GST_BUFFER_DATA (buf);
-    packet.bytes = GST_BUFFER_SIZE (buf);
+    gst_buffer_map (buf, &map, GST_MAP_READ);
+    packet.packet = map.data;
+    packet.bytes = map.size;
     packet.granulepos = GST_BUFFER_OFFSET_END (buf);
     packet.packetno = i + 1;
     packet.e_o_s = 0;
     packet.b_o_s = (i == 0);
     ret = th_decode_headerin (&parse->info, &parse->comment, &setup, &packet);
+    gst_buffer_unmap (buf, &map);
     if (ret < 0) {
       GST_WARNING_OBJECT (parse, "Failed to decode Theora header %d: %d\n",
           i + 1, ret);
@@ -351,7 +359,7 @@ theora_parse_drain_event_queue (GstTheoraParse * parse)
     GstEvent *event;
 
     event = GST_EVENT_CAST (g_queue_pop_head (parse->event_queue));
-    gst_pad_event_default (parse->sinkpad, event);
+    gst_pad_event_default (parse->sinkpad, GST_OBJECT_CAST (parse), event);
   }
 }
 
@@ -371,8 +379,6 @@ theora_parse_push_headers (GstTheoraParse * parse)
     GstBuffer *buf;
 
     if ((buf = parse->streamheader[i])) {
-      buf = gst_buffer_make_metadata_writable (buf);
-      gst_buffer_set_caps (buf, GST_PAD_CAPS (parse->srcpad));
       gst_pad_push (parse->srcpad, buf);
       parse->streamheader[i] = NULL;
     }
@@ -439,11 +445,16 @@ parse_granulepos (GstTheoraParse * parse, gint64 granulepos,
 static gboolean
 is_keyframe (GstBuffer * buf)
 {
-  if (!GST_BUFFER_DATA (buf))
-    return FALSE;
-  if (!GST_BUFFER_SIZE (buf))
+  gsize size;
+  guint8 data[1];
+
+  size = gst_buffer_get_size (buf);
+  if (size == 0)
     return FALSE;
-  return ((GST_BUFFER_DATA (buf)[0] & 0x40) == 0);
+
+  gst_buffer_extract (buf, 0, data, 1);
+
+  return ((data[0] & 0x40) == 0);
 }
 
 static void
@@ -500,8 +511,6 @@ theora_parse_push_buffer (GstTheoraParse * parse, GstBuffer * buf,
   GST_BUFFER_TIMESTAMP (buf) = this_time;
   GST_BUFFER_DURATION (buf) = next_time - this_time;
 
-  gst_buffer_set_caps (buf, GST_PAD_CAPS (parse->srcpad));
-
   if (parse->times)
     theora_parse_munge_granulepos (parse, buf, keyframe, frame);
 
@@ -628,7 +637,7 @@ theora_parse_queue_buffer (GstTheoraParse * parse, GstBuffer * buf)
 {
   GstFlowReturn ret = GST_FLOW_OK;
 
-  buf = gst_buffer_make_metadata_writable (buf);
+  buf = gst_buffer_make_writable (buf);
 
   g_queue_push_tail (parse->buffer_queue, buf);
 
@@ -644,22 +653,24 @@ theora_parse_queue_buffer (GstTheoraParse * parse, GstBuffer * buf)
 }
 
 static GstFlowReturn
-theora_parse_chain (GstPad * pad, GstBuffer * buffer)
+theora_parse_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
 {
   GstFlowReturn ret;
   GstTheoraParse *parse;
-  guint8 *data;
-  guint size;
+  GstMapInfo map;
+  guint8 header;
   gboolean have_header;
 
-  parse = GST_THEORA_PARSE (gst_pad_get_parent (pad));
-
-  data = GST_BUFFER_DATA (buffer);
-  size = GST_BUFFER_SIZE (buffer);
+  parse = GST_THEORA_PARSE (parent);
 
   have_header = FALSE;
-  if (size >= 1) {
-    if (data[0] & 0x80)
+
+  gst_buffer_map (buffer, &map, GST_MAP_READ);
+  header = map.data[0];
+  gst_buffer_unmap (buffer, &map);
+
+  if (map.size >= 1) {
+    if (header & 0x80)
       have_header = TRUE;
   }
 
@@ -667,8 +678,8 @@ theora_parse_chain (GstPad * pad, GstBuffer * buffer)
     if (parse->send_streamheader) {
       /* we need to collect the headers still */
       /* so put it on the streamheader list and return */
-      if (data[0] >= 0x80 && data[0] <= 0x82)
-        parse->streamheader[data[0] - 0x80] = buffer;
+      if (header >= 0x80 && header <= 0x82)
+        parse->streamheader[header - 0x80] = buffer;
     }
     ret = GST_FLOW_OK;
   } else {
@@ -681,8 +692,6 @@ theora_parse_chain (GstPad * pad, GstBuffer * buffer)
     ret = theora_parse_queue_buffer (parse, buffer);
   }
 
-  gst_object_unref (parse);
-
   return ret;
 }
 
@@ -694,34 +703,32 @@ theora_parse_queue_event (GstTheoraParse * parse, GstEvent * event)
 }
 
 static gboolean
-theora_parse_sink_event (GstPad * pad, GstEvent * event)
+theora_parse_sink_event (GstPad * pad, GstObject * parent, GstEvent * event)
 {
   gboolean ret;
   GstTheoraParse *parse;
 
-  parse = GST_THEORA_PARSE (gst_pad_get_parent (pad));
+  parse = GST_THEORA_PARSE (parent);
 
   switch (GST_EVENT_TYPE (event)) {
     case GST_EVENT_FLUSH_STOP:
       theora_parse_clear_queue (parse);
       parse->prev_keyframe = -1;
       parse->prev_frame = -1;
-      ret = gst_pad_event_default (pad, event);
+      ret = gst_pad_event_default (pad, parent, event);
       break;
     case GST_EVENT_EOS:
       theora_parse_drain_queue_prematurely (parse);
-      ret = gst_pad_event_default (pad, event);
+      ret = gst_pad_event_default (pad, parent, event);
       break;
     default:
       if (parse->send_streamheader && GST_EVENT_IS_SERIALIZED (event))
         ret = theora_parse_queue_event (parse, event);
       else
-        ret = gst_pad_event_default (pad, event);
+        ret = gst_pad_event_default (pad, parent, event);
       break;
   }
 
-  gst_object_unref (parse);
-
   return ret;
 }
 
@@ -805,13 +812,12 @@ no_header:
 }
 
 static gboolean
-theora_parse_src_query (GstPad * pad, GstQuery * query)
+theora_parse_src_query (GstPad * pad, GstObject * parent, GstQuery * query)
 {
   GstTheoraParse *parse;
-
   gboolean res = FALSE;
 
-  parse = GST_THEORA_PARSE (gst_pad_get_parent (pad));
+  parse = GST_THEORA_PARSE (parent);
 
   switch (GST_QUERY_TYPE (query)) {
     case GST_QUERY_POSITION:
@@ -876,11 +882,10 @@ theora_parse_src_query (GstPad * pad, GstQuery * query)
       break;
     }
     default:
-      res = gst_pad_query_default (pad, query);
+      res = gst_pad_query_default (pad, parent, query);
       break;
   }
 done:
-  gst_object_unref (parse);
 
   return res;
 
@@ -914,7 +919,7 @@ theora_parse_change_state (GstElement * element, GstStateChange transition)
       break;
   }
 
-  ret = parent_class->change_state (element, transition);
+  ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
 
   switch (transition) {
     case GST_STATE_CHANGE_PAUSED_TO_READY: