From da3e23d3758e7c5b38b27c4894f1f0845e5231e9 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 29 Mar 2007 14:03:21 +0000 Subject: [PATCH] gst/rtp/: Use more efficient adapter and rtpbuffer methods when possible. Original commit message from CVS: * gst/rtp/gstrtpL16depay.c: (gst_rtp_L16_depay_process): * gst/rtp/gstrtpgsmdepay.c: (gst_rtp_gsm_depay_process): * gst/rtp/gstrtpilbcdepay.c: (gst_rtp_ilbc_depay_process): * gst/rtp/gstrtpmp2tdepay.c: (gst_rtp_mp2t_depay_process): * gst/rtp/gstrtpmp4gdepay.c: (gst_rtp_mp4g_depay_process): * gst/rtp/gstrtpmp4gpay.c: (gst_rtp_mp4g_pay_flush): * gst/rtp/gstrtpmp4vdepay.c: (gst_rtp_mp4v_depay_setcaps), (gst_rtp_mp4v_depay_process): * gst/rtp/gstrtpmp4vpay.c: (gst_rtp_mp4v_pay_flush): * gst/rtp/gstrtpmpadepay.c: (gst_rtp_mpa_depay_process): * gst/rtp/gstrtpmpapay.c: (gst_rtp_mpa_pay_flush): * gst/rtp/gstrtpmpvdepay.c: (gst_rtp_mpv_depay_process): * gst/rtp/gstrtppcmadepay.c: (gst_rtp_pcma_depay_process): * gst/rtp/gstrtppcmudepay.c: (gst_rtp_pcmu_depay_process): * gst/rtp/gstrtpsv3vdepay.c: (gst_rtp_sv3v_depay_process): Use more efficient adapter and rtpbuffer methods when possible. --- ChangeLog | 19 +++++++++++++++++++ gst/rtp/gstrtpL16depay.c | 2 -- gst/rtp/gstrtpgsmdepay.c | 7 +------ gst/rtp/gstrtpilbcdepay.c | 7 +------ gst/rtp/gstrtpmp2tdepay.c | 6 ------ gst/rtp/gstrtpmp4gdepay.c | 17 ++++++++--------- gst/rtp/gstrtpmp4gpay.c | 6 ++---- gst/rtp/gstrtpmp4vdepay.c | 2 -- gst/rtp/gstrtpmp4vpay.c | 4 +--- gst/rtp/gstrtpmpadepay.c | 13 ++----------- gst/rtp/gstrtpmpapay.c | 4 +--- gst/rtp/gstrtpmpvdepay.c | 11 +++++------ gst/rtp/gstrtppcmadepay.c | 7 +------ gst/rtp/gstrtppcmudepay.c | 7 +------ gst/rtp/gstrtpsv3vdepay.c | 6 +----- 15 files changed, 43 insertions(+), 75 deletions(-) diff --git a/ChangeLog b/ChangeLog index a84ee4b..ddd59b6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2007-03-29 Wim Taymans + + * gst/rtp/gstrtpL16depay.c: (gst_rtp_L16_depay_process): + * gst/rtp/gstrtpgsmdepay.c: (gst_rtp_gsm_depay_process): + * gst/rtp/gstrtpilbcdepay.c: (gst_rtp_ilbc_depay_process): + * gst/rtp/gstrtpmp2tdepay.c: (gst_rtp_mp2t_depay_process): + * gst/rtp/gstrtpmp4gdepay.c: (gst_rtp_mp4g_depay_process): + * gst/rtp/gstrtpmp4gpay.c: (gst_rtp_mp4g_pay_flush): + * gst/rtp/gstrtpmp4vdepay.c: (gst_rtp_mp4v_depay_setcaps), + (gst_rtp_mp4v_depay_process): + * gst/rtp/gstrtpmp4vpay.c: (gst_rtp_mp4v_pay_flush): + * gst/rtp/gstrtpmpadepay.c: (gst_rtp_mpa_depay_process): + * gst/rtp/gstrtpmpapay.c: (gst_rtp_mpa_pay_flush): + * gst/rtp/gstrtpmpvdepay.c: (gst_rtp_mpv_depay_process): + * gst/rtp/gstrtppcmadepay.c: (gst_rtp_pcma_depay_process): + * gst/rtp/gstrtppcmudepay.c: (gst_rtp_pcmu_depay_process): + * gst/rtp/gstrtpsv3vdepay.c: (gst_rtp_sv3v_depay_process): + Use more efficient adapter and rtpbuffer methods when possible. + 2007-03-29 Sebastian Dröge * gst/wavenc/gstwavenc.c: (gst_wavenc_create_header_buf), diff --git a/gst/rtp/gstrtpL16depay.c b/gst/rtp/gstrtpL16depay.c index 1f37a22..fb753b7 100644 --- a/gst/rtp/gstrtpL16depay.c +++ b/gst/rtp/gstrtpL16depay.c @@ -220,10 +220,8 @@ gst_rtp_L16_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf) { gint payload_len; - guint8 *payload; payload_len = gst_rtp_buffer_get_payload_len (buf); - payload = gst_rtp_buffer_get_payload (buf); if (payload_len <= 0) goto empty_packet; diff --git a/gst/rtp/gstrtpgsmdepay.c b/gst/rtp/gstrtpgsmdepay.c index 1b0bde0..e1e595e 100644 --- a/gst/rtp/gstrtpgsmdepay.c +++ b/gst/rtp/gstrtpgsmdepay.c @@ -123,19 +123,14 @@ static GstBuffer * gst_rtp_gsm_depay_process (GstBaseRTPDepayload * _depayload, GstBuffer * buf) { GstBuffer *outbuf = NULL; - gint payload_len; - guint8 *payload; GST_DEBUG ("process : got %d bytes, mark %d ts %u seqn %d", GST_BUFFER_SIZE (buf), gst_rtp_buffer_get_marker (buf), gst_rtp_buffer_get_timestamp (buf), gst_rtp_buffer_get_seq (buf)); - payload_len = gst_rtp_buffer_get_payload_len (buf); - payload = gst_rtp_buffer_get_payload (buf); + outbuf = gst_rtp_buffer_get_payload_buffer (buf); - outbuf = gst_buffer_new_and_alloc (payload_len); - memcpy (GST_BUFFER_DATA (outbuf), payload, payload_len); return outbuf; } diff --git a/gst/rtp/gstrtpilbcdepay.c b/gst/rtp/gstrtpilbcdepay.c index 057944e..df21acf 100644 --- a/gst/rtp/gstrtpilbcdepay.c +++ b/gst/rtp/gstrtpilbcdepay.c @@ -169,18 +169,13 @@ static GstBuffer * gst_rtp_ilbc_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf) { GstBuffer *outbuf = NULL; - gint payload_len; - gint header_len; GST_DEBUG ("process : got %d bytes, mark %d ts %u seqn %d", GST_BUFFER_SIZE (buf), gst_rtp_buffer_get_marker (buf), gst_rtp_buffer_get_timestamp (buf), gst_rtp_buffer_get_seq (buf)); - payload_len = gst_rtp_buffer_get_payload_len (buf); - header_len = gst_rtp_buffer_calc_header_len (0); - - outbuf = gst_buffer_create_sub (buf, header_len, payload_len); + outbuf = gst_rtp_buffer_get_payload_buffer (buf); return outbuf; } diff --git a/gst/rtp/gstrtpmp2tdepay.c b/gst/rtp/gstrtpmp2tdepay.c index 9c41b3a..2f2cdf8 100644 --- a/gst/rtp/gstrtpmp2tdepay.c +++ b/gst/rtp/gstrtpmp2tdepay.c @@ -173,7 +173,6 @@ gst_rtp_mp2t_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf) GstRtpMP2TDepay *rtpmp2tdepay; GstBuffer *outbuf; gint payload_len; - guint32 timestamp; rtpmp2tdepay = GST_RTP_MP2T_DEPAY (depayload); @@ -185,15 +184,10 @@ gst_rtp_mp2t_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf) if (G_UNLIKELY (payload_len <= rtpmp2tdepay->skip_first_bytes)) goto empty_packet; - timestamp = gst_rtp_buffer_get_timestamp (buf); - outbuf = gst_rtp_buffer_get_payload_subbuffer (buf, rtpmp2tdepay->skip_first_bytes, -1); - gst_buffer_set_caps (outbuf, GST_PAD_CAPS (depayload->srcpad)); - GST_BUFFER_TIMESTAMP (outbuf) = - gst_util_uint64_scale_int (timestamp, GST_SECOND, depayload->clock_rate); GST_DEBUG ("gst_rtp_mp2t_depay_chain: pushing buffer of size %d", GST_BUFFER_SIZE (outbuf)); diff --git a/gst/rtp/gstrtpmp4gdepay.c b/gst/rtp/gstrtpmp4gdepay.c index 5eb8724..3483a6d 100644 --- a/gst/rtp/gstrtpmp4gdepay.c +++ b/gst/rtp/gstrtpmp4gdepay.c @@ -276,7 +276,7 @@ gst_rtp_mp4g_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf) goto bad_packet; { - gint payload_len; + gint payload_len, payload_header; guint8 *payload; guint32 timestamp; guint AU_headers_len; @@ -284,6 +284,7 @@ gst_rtp_mp4g_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf) payload_len = gst_rtp_buffer_get_payload_len (buf); payload = gst_rtp_buffer_get_payload (buf); + payload_header = 0; if (rtpmp4gdepay->sizelength > 0) { /* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- .. -+-+-+-+-+-+-+-+-+-+ @@ -298,6 +299,7 @@ gst_rtp_mp4g_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf) /* skip header */ payload += 2; + payload_header += 2; payload_len -= 2; /* FIXME, use bits */ @@ -309,14 +311,15 @@ gst_rtp_mp4g_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf) /* skip special headers */ payload += (AU_headers_len + 7) / 8; + payload_header += (AU_headers_len + 7) / 8; payload_len = AU_size; } timestamp = gst_rtp_buffer_get_timestamp (buf); - outbuf = gst_buffer_new_and_alloc (payload_len); - memcpy (GST_BUFFER_DATA (outbuf), payload, payload_len); - + /* strip header from payload and push in the adapter */ + outbuf = + gst_rtp_buffer_get_payload_subbuffer (buf, payload_header, payload_len); gst_adapter_push (rtpmp4gdepay->adapter, outbuf); /* if this was the last packet of the VOP, create and push a buffer */ @@ -325,11 +328,7 @@ gst_rtp_mp4g_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf) avail = gst_adapter_available (rtpmp4gdepay->adapter); - outbuf = gst_buffer_new (); - GST_BUFFER_SIZE (outbuf) = avail; - GST_BUFFER_MALLOCDATA (outbuf) = - gst_adapter_take (rtpmp4gdepay->adapter, avail); - GST_BUFFER_DATA (outbuf) = GST_BUFFER_MALLOCDATA (outbuf); + outbuf = gst_adapter_take_buffer (rtpmp4gdepay->adapter, avail); gst_buffer_set_caps (outbuf, GST_PAD_CAPS (depayload->srcpad)); GST_BUFFER_TIMESTAMP (outbuf) = gst_util_uint64_scale_int (timestamp, GST_SECOND, depayload->clock_rate); diff --git a/gst/rtp/gstrtpmp4gpay.c b/gst/rtp/gstrtpmp4gpay.c index fae66c5..4e4c817 100644 --- a/gst/rtp/gstrtpmp4gpay.c +++ b/gst/rtp/gstrtpmp4gpay.c @@ -453,7 +453,6 @@ gst_rtp_mp4g_pay_flush (GstRtpMP4GPay * rtpmp4gpay) while (avail > 0) { guint towrite; guint8 *payload; - guint8 *data; guint payload_len; guint packet_len; @@ -511,9 +510,8 @@ gst_rtp_mp4g_pay_flush (GstRtpMP4GPay * rtpmp4gpay) payload[2] = (total & 0x1fe0) >> 5; payload[3] = (total & 0x1f) << 3; /* we use 13 bits for the size, 3 bits index */ - data = (guint8 *) gst_adapter_peek (rtpmp4gpay->adapter, payload_len); - memcpy (&payload[4], data, payload_len); - + /* copy stuff from adapter to payload */ + gst_adapter_copy (rtpmp4gpay->adapter, &payload[4], 0, payload_len); gst_adapter_flush (rtpmp4gpay->adapter, payload_len); /* marker only if the packet is complete */ diff --git a/gst/rtp/gstrtpmp4vdepay.c b/gst/rtp/gstrtpmp4vdepay.c index 8a73b32..79526d3 100644 --- a/gst/rtp/gstrtpmp4vdepay.c +++ b/gst/rtp/gstrtpmp4vdepay.c @@ -207,7 +207,6 @@ gst_rtp_mp4v_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf) gst_adapter_clear (rtpmp4vdepay->adapter); outbuf = gst_rtp_buffer_get_payload_buffer (buf); - gst_adapter_push (rtpmp4vdepay->adapter, outbuf); /* if this was the last packet of the VOP, create and push a buffer */ @@ -217,7 +216,6 @@ gst_rtp_mp4v_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf) avail = gst_adapter_available (rtpmp4vdepay->adapter); outbuf = gst_adapter_take_buffer (rtpmp4vdepay->adapter, avail); - gst_buffer_set_caps (outbuf, GST_PAD_CAPS (depayload->srcpad)); GST_DEBUG ("gst_rtp_mp4v_depay_chain: pushing buffer of size %d", diff --git a/gst/rtp/gstrtpmp4vpay.c b/gst/rtp/gstrtpmp4vpay.c index d3cff33..41e9009 100644 --- a/gst/rtp/gstrtpmp4vpay.c +++ b/gst/rtp/gstrtpmp4vpay.c @@ -262,7 +262,6 @@ gst_rtp_mp4v_pay_flush (GstRtpMP4VPay * rtpmp4vpay) while (avail > 0) { guint towrite; guint8 *payload; - guint8 *data; guint payload_len; guint packet_len; @@ -280,9 +279,8 @@ gst_rtp_mp4v_pay_flush (GstRtpMP4VPay * rtpmp4vpay) /* copy payload */ payload = gst_rtp_buffer_get_payload (outbuf); - data = (guint8 *) gst_adapter_peek (rtpmp4vpay->adapter, payload_len); - memcpy (payload, data, payload_len); + gst_adapter_copy (rtpmp4vpay->adapter, payload, 0, payload_len); gst_adapter_flush (rtpmp4vpay->adapter, payload_len); avail -= payload_len; diff --git a/gst/rtp/gstrtpmpadepay.c b/gst/rtp/gstrtpmpadepay.c index e5622be..9cf409a 100644 --- a/gst/rtp/gstrtpmpadepay.c +++ b/gst/rtp/gstrtpmpadepay.c @@ -161,7 +161,6 @@ gst_rtp_mpa_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf) gint payload_len; guint8 *payload; guint16 frag_offset; - guint32 timestamp; payload_len = gst_rtp_buffer_get_payload_len (buf); payload = gst_rtp_buffer_get_payload (buf); @@ -179,16 +178,8 @@ gst_rtp_mpa_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf) */ frag_offset = (payload[2] << 8) | payload[3]; - payload_len -= 4; - payload += 4; - - timestamp = gst_rtp_buffer_get_timestamp (buf); - - outbuf = gst_buffer_new_and_alloc (payload_len); - - //GST_BUFFER_TIMESTAMP (outbuf) = timestamp * GST_SECOND / 90000; - - memcpy (GST_BUFFER_DATA (outbuf), payload, payload_len); + /* subbuffer skipping the 4 header bytes */ + outbuf = gst_rtp_buffer_get_payload_subbuffer (buf, 4, -1); GST_DEBUG_OBJECT (rtpmpadepay, "gst_rtp_mpa_depay_chain: pushing buffer of size %d", diff --git a/gst/rtp/gstrtpmpapay.c b/gst/rtp/gstrtpmpapay.c index 2fe208d..b4459c8 100644 --- a/gst/rtp/gstrtpmpapay.c +++ b/gst/rtp/gstrtpmpapay.c @@ -174,7 +174,6 @@ gst_rtp_mpa_pay_flush (GstRtpMPAPay * rtpmpapay) while (avail > 0) { guint towrite; guint8 *payload; - guint8 *data; guint payload_len; guint packet_len; @@ -207,8 +206,7 @@ gst_rtp_mpa_pay_flush (GstRtpMPAPay * rtpmpapay) payload[2] = frag_offset >> 8; payload[3] = frag_offset & 0xff; - data = (guint8 *) gst_adapter_peek (rtpmpapay->adapter, payload_len); - memcpy (&payload[4], data, payload_len); + gst_adapter_copy (rtpmpapay->adapter, &payload[4], 0, payload_len); gst_adapter_flush (rtpmpapay->adapter, payload_len); avail -= payload_len; diff --git a/gst/rtp/gstrtpmpvdepay.c b/gst/rtp/gstrtpmpvdepay.c index 2f82829..08d92a5 100644 --- a/gst/rtp/gstrtpmpvdepay.c +++ b/gst/rtp/gstrtpmpvdepay.c @@ -158,13 +158,13 @@ gst_rtp_mpv_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf) goto bad_packet; { - gint payload_len; + gint payload_len, payload_header; guint8 *payload; guint8 T; - guint32 timestamp; payload_len = gst_rtp_buffer_get_payload_len (buf); payload = gst_rtp_buffer_get_payload (buf); + payload_header = 0; if (payload_len <= 4) goto empty_packet; @@ -181,6 +181,7 @@ gst_rtp_mpv_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf) T = (payload[0] & 0x04); payload_len -= 4; + payload_header += 4; payload += 4; if (T) { @@ -197,13 +198,11 @@ gst_rtp_mpv_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf) goto empty_packet; payload_len -= 4; + payload_header += 4; payload += 4; } - timestamp = gst_rtp_buffer_get_timestamp (buf); - - outbuf = gst_buffer_new_and_alloc (payload_len); - memcpy (GST_BUFFER_DATA (outbuf), payload, payload_len); + outbuf = gst_rtp_buffer_get_payload_subbuffer (buf, payload_header, -1); GST_DEBUG_OBJECT (rtpmpvdepay, "gst_rtp_mpv_depay_chain: pushing buffer of size %d", diff --git a/gst/rtp/gstrtppcmadepay.c b/gst/rtp/gstrtppcmadepay.c index a941ebc..6b03ba5 100644 --- a/gst/rtp/gstrtppcmadepay.c +++ b/gst/rtp/gstrtppcmadepay.c @@ -136,8 +136,6 @@ gst_rtp_pcma_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf) { GstCaps *srccaps; GstBuffer *outbuf = NULL; - gint payload_len; - guint8 *payload; GST_DEBUG ("process : got %d bytes, mark %d ts %u seqn %d", GST_BUFFER_SIZE (buf), @@ -153,11 +151,8 @@ gst_rtp_pcma_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf) gst_caps_unref (srccaps); } - payload_len = gst_rtp_buffer_get_payload_len (buf); - payload = gst_rtp_buffer_get_payload (buf); + outbuf = gst_rtp_buffer_get_payload_buffer (buf); - outbuf = gst_buffer_new_and_alloc (payload_len); - memcpy (GST_BUFFER_DATA (outbuf), payload, payload_len); return outbuf; } diff --git a/gst/rtp/gstrtppcmudepay.c b/gst/rtp/gstrtppcmudepay.c index 9a4f5ab..aca02b8 100644 --- a/gst/rtp/gstrtppcmudepay.c +++ b/gst/rtp/gstrtppcmudepay.c @@ -136,8 +136,6 @@ gst_rtp_pcmu_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf) { GstCaps *srccaps; GstBuffer *outbuf = NULL; - gint payload_len; - guint8 *payload; GST_DEBUG ("process : got %d bytes, mark %d ts %u seqn %d", GST_BUFFER_SIZE (buf), @@ -153,11 +151,8 @@ gst_rtp_pcmu_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf) gst_caps_unref (srccaps); } - payload_len = gst_rtp_buffer_get_payload_len (buf); - payload = gst_rtp_buffer_get_payload (buf); + outbuf = gst_rtp_buffer_get_payload_buffer (buf); - outbuf = gst_buffer_new_and_alloc (payload_len); - memcpy (GST_BUFFER_DATA (outbuf), payload, payload_len); return outbuf; } diff --git a/gst/rtp/gstrtpsv3vdepay.c b/gst/rtp/gstrtpsv3vdepay.c index c67b5ef..f2df179 100644 --- a/gst/rtp/gstrtpsv3vdepay.c +++ b/gst/rtp/gstrtpsv3vdepay.c @@ -252,14 +252,10 @@ gst_rtp_sv3v_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf) if (M) { /* frame is completed: push contents of adapter */ guint avail; - guint8 *data; guint32 timestamp; avail = gst_adapter_available (rtpsv3vdepay->adapter); - data = gst_adapter_take (rtpsv3vdepay->adapter, avail); - - /* create buffer with data */ - outbuf = gst_rtp_buffer_new_take_data (data, avail); + outbuf = gst_adapter_take_buffer (rtpsv3vdepay->adapter, avail); /* timestamp for complete buffer is that of last buffer as well */ timestamp = gst_rtp_buffer_get_timestamp (buf); -- 2.7.4