diff options
author | Christoffer Stengren <christsn.gs@gmail.com> | 2016-03-31 11:21:35 +0200 |
---|---|---|
committer | Sebastian Dröge <sebastian@centricular.com> | 2016-04-03 11:45:09 +0300 |
commit | de3b2cc171fea6f00b33a034dfbc9d47d61f06ee (patch) | |
tree | 2ddcfb66d92d1c5ff46c80d29de21c92dd844e08 /gst/gdp | |
parent | e6c3446d010ceb94bb3beb4abc9db8d7ead896c6 (diff) | |
download | gstreamer-plugins-bad-de3b2cc171fea6f00b33a034dfbc9d47d61f06ee.tar.gz |
gdpdepay: Query for buffer allocator before using default
https://bugzilla.gnome.org/show_bug.cgi?id=764361
Diffstat (limited to 'gst/gdp')
-rw-r--r-- | gst/gdp/dataprotocol.c | 9 | ||||
-rw-r--r-- | gst/gdp/dataprotocol.h | 4 | ||||
-rw-r--r-- | gst/gdp/gstgdpdepay.c | 56 | ||||
-rw-r--r-- | gst/gdp/gstgdpdepay.h | 3 |
4 files changed, 67 insertions, 5 deletions
diff --git a/gst/gdp/dataprotocol.c b/gst/gdp/dataprotocol.c index fbb46a6a9..d6534ba94 100644 --- a/gst/gdp/dataprotocol.c +++ b/gst/gdp/dataprotocol.c @@ -477,6 +477,8 @@ gst_dp_header_payload_type (const guint8 * header) * gst_dp_buffer_from_header: * @header_length: the length of the packet header * @header: the byte array of the packet header + * @allocator: the allocator used to allocate the new #GstBuffer + * @allocation_params: the allocations parameters used to allocate the new #GstBuffer * * Creates a newly allocated #GstBuffer from the given header. * The buffer data needs to be copied into it before validating. @@ -490,7 +492,8 @@ gst_dp_header_payload_type (const guint8 * header) * Returns: A #GstBuffer if the buffer was successfully created, or NULL. */ GstBuffer * -gst_dp_buffer_from_header (guint header_length, const guint8 * header) +gst_dp_buffer_from_header (guint header_length, const guint8 * header, + GstAllocator * allocator, GstAllocationParams * allocation_params) { GstBuffer *buffer; @@ -500,8 +503,8 @@ gst_dp_buffer_from_header (guint header_length, const guint8 * header) GST_DP_PAYLOAD_BUFFER, NULL); buffer = - gst_buffer_new_allocate (NULL, - (guint) GST_DP_HEADER_PAYLOAD_LENGTH (header), NULL); + gst_buffer_new_allocate (allocator, + (guint) GST_DP_HEADER_PAYLOAD_LENGTH (header), allocation_params); GST_BUFFER_TIMESTAMP (buffer) = GST_DP_HEADER_TIMESTAMP (header); GST_BUFFER_DTS (buffer) = GST_DP_HEADER_DTS (header); diff --git a/gst/gdp/dataprotocol.h b/gst/gdp/dataprotocol.h index ac1d0107d..397bf4315 100644 --- a/gst/gdp/dataprotocol.h +++ b/gst/gdp/dataprotocol.h @@ -78,7 +78,9 @@ GstDPPayloadType /* converting to GstBuffer/GstEvent/GstCaps */ GstBuffer * gst_dp_buffer_from_header (guint header_length, - const guint8 * header); + const guint8 * header, + GstAllocator * allocator, + GstAllocationParams * allocation_params); GstCaps * gst_dp_caps_from_packet (guint header_length, const guint8 * header, const guint8 * payload); diff --git a/gst/gdp/gstgdpdepay.c b/gst/gdp/gstgdpdepay.c index 78524f073..b7269bd68 100644 --- a/gst/gdp/gstgdpdepay.c +++ b/gst/gdp/gstgdpdepay.c @@ -86,6 +86,7 @@ static void gst_gdp_depay_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec); static void gst_gdp_depay_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec); +static void gst_gdp_depay_decide_allocation (GstGDPDepay * depay); static void gst_gdp_depay_class_init (GstGDPDepayClass * klass) @@ -140,6 +141,9 @@ gst_gdp_depay_init (GstGDPDepay * gdpdepay) gst_element_add_pad (GST_ELEMENT (gdpdepay), gdpdepay->srcpad); gdpdepay->adapter = gst_adapter_new (); + + gdpdepay->allocator = NULL; + gst_allocation_params_init (&gdpdepay->allocation_params); } static void @@ -153,6 +157,8 @@ gst_gdp_depay_finalize (GObject * gobject) g_free (this->header); gst_adapter_clear (this->adapter); g_object_unref (this->adapter); + if (this->allocator) + gst_object_unref (this->allocator); GST_CALL_PARENT (G_OBJECT_CLASS, finalize, (gobject)); } @@ -265,6 +271,10 @@ gst_gdp_depay_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer) this = GST_GDP_DEPAY (parent); + if (gst_pad_check_reconfigure (this->srcpad)) { + gst_gdp_depay_decide_allocation (this); + } + /* On DISCONT, get rid of accumulated data. We assume a buffer after the * DISCONT contains (part of) a new valid header, if not we error because we * lost sync */ @@ -352,7 +362,9 @@ gst_gdp_depay_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer) goto no_caps; GST_LOG_OBJECT (this, "reading GDP buffer from adapter"); - buf = gst_dp_buffer_from_header (GST_DP_HEADER_LENGTH, this->header); + buf = + gst_dp_buffer_from_header (GST_DP_HEADER_LENGTH, this->header, + this->allocator, &this->allocation_params); if (!buf) goto buffer_failed; @@ -411,6 +423,7 @@ gst_gdp_depay_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer) GST_DEBUG_OBJECT (this, "deserialized caps %" GST_PTR_FORMAT, caps); gst_caps_replace (&(this->caps), caps); gst_pad_set_caps (this->srcpad, caps); + gst_gdp_depay_decide_allocation (this); /* drop the creation ref we still have */ gst_caps_unref (caps); @@ -521,6 +534,10 @@ gst_gdp_depay_change_state (GstElement * element, GstStateChange transition) this->caps = NULL; } gst_adapter_clear (this->adapter); + if (this->allocator) + gst_object_unref (this->allocator); + this->allocator = NULL; + gst_allocation_params_init (&this->allocation_params); break; default: break; @@ -528,6 +545,43 @@ gst_gdp_depay_change_state (GstElement * element, GstStateChange transition) return ret; } +static void +gst_gdp_depay_decide_allocation (GstGDPDepay * gdpdepay) +{ + GstAllocator *allocator; + GstAllocationParams params; + GstQuery *query = NULL; + GstCaps *caps; + + caps = gst_pad_query_caps (gdpdepay->srcpad, NULL); + if (!caps) { + GST_LOG_OBJECT (gdpdepay, + "No peer pad caps found. Using default allocator."); + return; + } + + query = gst_query_new_allocation (caps, TRUE); + if (!gst_pad_peer_query (gdpdepay->srcpad, query)) { + GST_WARNING_OBJECT (gdpdepay, "Peer allocation query failed."); + } + + if (gst_query_get_n_allocation_params (query) > 0) { + gst_query_parse_nth_allocation_param (query, 0, &allocator, ¶ms); + } else { + allocator = NULL; + gst_allocation_params_init (¶ms); + } + + if (gdpdepay->allocator) + gst_object_unref (gdpdepay->allocator); + + gdpdepay->allocator = allocator; + gdpdepay->allocation_params = params; + + gst_caps_unref (caps); + gst_query_unref (query); +} + gboolean gst_gdp_depay_plugin_init (GstPlugin * plugin) { diff --git a/gst/gdp/gstgdpdepay.h b/gst/gdp/gstgdpdepay.h index 43bbf9da5..c21f302be 100644 --- a/gst/gdp/gstgdpdepay.h +++ b/gst/gdp/gstgdpdepay.h @@ -68,6 +68,9 @@ struct _GstGDPDepay GstDPPayloadType payload_type; gint64 ts_offset; + + GstAllocator *allocator; + GstAllocationParams allocation_params; }; struct _GstGDPDepayClass |