[Nice] [nice/master] Create a netbuffer directly instead of using gst_pad_buffer_alloc

Olivier Crête olivier.crete at collabora.co.uk
Wed Nov 5 14:02:35 PST 2008


---
 configure.ac     |    1 +
 gst/gstnicesrc.c |   21 ++++++++++++---------
 gst/gstnicesrc.h |    3 +--
 3 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/configure.ac b/configure.ac
index 8f9cee1..c3154e4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -59,6 +59,7 @@ AS_IF([test "$with_gstreamer" != no], [
 	PKG_CHECK_MODULES(GST, [
 		gstreamer-0.10 >= 0.10.0
 		gstreamer-base-0.10 >= 0.10.0
+		gstreamer-netbuffer-0.10 >= 0.10.0
 		],
 		[
 		with_gstreamer=yes
diff --git a/gst/gstnicesrc.c b/gst/gstnicesrc.c
index e83eade..895c8bd 100644
--- a/gst/gstnicesrc.c
+++ b/gst/gstnicesrc.c
@@ -195,15 +195,18 @@ gst_nice_src_read_callback (NiceAgent *agent,
 {
   GstBaseSrc *basesrc = GST_BASE_SRC (data);
   GstNiceSrc *nicesrc = GST_NICE_SRC (basesrc);
+  GstNetBuffer *mybuf;
 
   GST_LOG_OBJECT (agent, "Got buffer, getting out of the main loop");
 
-  nicesrc->flow_ret = gst_pad_alloc_buffer (basesrc->srcpad, nicesrc->offset,
-      len, GST_PAD_CAPS (basesrc->srcpad), &nicesrc->outbuf);
-  if (nicesrc->flow_ret == GST_FLOW_OK) {
-    memcpy (nicesrc->outbuf->data, buf, len);
-    nicesrc->outbuf->size = len;
-  }
+  mybuf = gst_netbuffer_new ();
+  GST_BUFFER_MALLOCDATA (mybuf) = g_memdup (buf, len);
+  GST_BUFFER_SIZE (mybuf) = len;
+  GST_BUFFER_DATA (mybuf) = GST_BUFFER_MALLOCDATA (mybuf);
+  if (GST_PAD_CAPS (basesrc->srcpad))
+    GST_BUFFER_CAPS (mybuf) = gst_caps_ref (GST_PAD_CAPS (basesrc->srcpad));
+
+  nicesrc->outbuf = GST_BUFFER_CAST (mybuf);
 
   g_main_loop_quit (nicesrc->mainloop);
 }
@@ -267,7 +270,6 @@ gst_nice_src_create (
   GST_LOG_OBJECT (nicesrc, "create called");
 
   nicesrc->outbuf = NULL;
-  nicesrc->offset = offset;
 
   GST_OBJECT_LOCK (basesrc);
   if (nicesrc->unlocked) {
@@ -282,12 +284,13 @@ gst_nice_src_create (
     GST_LOG_OBJECT (nicesrc, "Got buffer, pushing");
 
     *buffer = nicesrc->outbuf;
-    return nicesrc->flow_ret;
+    GST_BUFFER_OFFSET (*buffer) = offset;
+
+    return GST_FLOW_OK;
   } else {
     GST_LOG_OBJECT (nicesrc, "Got interrupting, returning wrong-state");
     return GST_FLOW_WRONG_STATE;
   }
-
 }
 
 static void
diff --git a/gst/gstnicesrc.h b/gst/gstnicesrc.h
index 96e8f2a..bac19a2 100644
--- a/gst/gstnicesrc.h
+++ b/gst/gstnicesrc.h
@@ -40,6 +40,7 @@
 
 #include <gst/gst.h>
 #include <gst/base/gstbasesrc.h>
+#include <gst/netbuffer/gstnetbuffer.h>
 
 #include <nice/nice.h>
 
@@ -66,8 +67,6 @@ struct _GstNiceSrc
   guint stream_id;
   guint component_id;
   GMainLoop *mainloop;
-  guint64 offset;
-  GstFlowReturn flow_ret;
   GstBuffer *outbuf;
   gboolean unlocked;
   GSource *idle_source;
-- 
1.5.6.5




More information about the Nice mailing list