static GstBuffer * gst_rtp_mp4v_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf) { GstRtpMP4VDepay *rtpmp4vdepay; GstBuffer *outbuf; rtpmp4vdepay = GST_RTP_MP4V_DEPAY (depayload); /* flush remaining data on discont */ if (GST_BUFFER_IS_DISCONT (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 */ if (gst_rtp_buffer_get_marker (buf)) { guint avail; avail = gst_adapter_available (rtpmp4vdepay->adapter); outbuf = gst_adapter_take_buffer (rtpmp4vdepay->adapter, avail); GST_DEBUG ("gst_rtp_mp4v_depay_chain: pushing buffer of size %d", GST_BUFFER_SIZE (outbuf)); return outbuf; } return NULL; }
static GstBuffer * gst_rtp_pcma_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf) { GstBuffer *outbuf = NULL; gboolean marker; guint len; marker = gst_rtp_buffer_get_marker (buf); GST_DEBUG ("process : got %d bytes, mark %d ts %u seqn %d", GST_BUFFER_SIZE (buf), marker, gst_rtp_buffer_get_timestamp (buf), gst_rtp_buffer_get_seq (buf)); len = gst_rtp_buffer_get_payload_len (buf); outbuf = gst_rtp_buffer_get_payload_buffer (buf); if (outbuf) { GST_BUFFER_DURATION (outbuf) = gst_util_uint64_scale_int (len, GST_SECOND, depayload->clock_rate); if (marker) { /* mark start of talkspurt with DISCONT */ GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT); } } return outbuf; }
static GstBuffer * gst_rtp_mp4v_depay_process (GstRTPBaseDepayload * depayload, GstBuffer * buf) { GstRtpMP4VDepay *rtpmp4vdepay; GstBuffer *pbuf, *outbuf = NULL; GstRTPBuffer rtp = { NULL }; gboolean marker; rtpmp4vdepay = GST_RTP_MP4V_DEPAY (depayload); /* flush remaining data on discont */ if (GST_BUFFER_IS_DISCONT (buf)) gst_adapter_clear (rtpmp4vdepay->adapter); gst_rtp_buffer_map (buf, GST_MAP_READ, &rtp); pbuf = gst_rtp_buffer_get_payload_buffer (&rtp); marker = gst_rtp_buffer_get_marker (&rtp); gst_rtp_buffer_unmap (&rtp); gst_adapter_push (rtpmp4vdepay->adapter, pbuf); /* if this was the last packet of the VOP, create and push a buffer */ if (marker) { guint avail; avail = gst_adapter_available (rtpmp4vdepay->adapter); outbuf = gst_adapter_take_buffer (rtpmp4vdepay->adapter, avail); GST_DEBUG ("gst_rtp_mp4v_depay_chain: pushing buffer of size %" G_GSIZE_FORMAT, gst_buffer_get_size (outbuf)); } return outbuf; }
static GstBuffer * gst_rtp_g722_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf) { GstRtpG722Depay *rtpg722depay; GstBuffer *outbuf; gint payload_len; gboolean marker; rtpg722depay = GST_RTP_G722_DEPAY (depayload); payload_len = gst_rtp_buffer_get_payload_len (buf); if (payload_len <= 0) goto empty_packet; GST_DEBUG_OBJECT (rtpg722depay, "got payload of %d bytes", payload_len); outbuf = gst_rtp_buffer_get_payload_buffer (buf); marker = gst_rtp_buffer_get_marker (buf); if (marker) { /* mark talk spurt with DISCONT */ GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT); } return outbuf; /* ERRORS */ empty_packet: { GST_ELEMENT_WARNING (rtpg722depay, STREAM, DECODE, ("Empty Payload."), (NULL)); return NULL; } }
static GstBuffer * gst_rtp_pcmu_depay_process (GstRTPBaseDepayload * depayload, GstBuffer * buf) { GstBuffer *outbuf = NULL; guint len; gboolean marker; GstRTPBuffer rtp = { NULL }; gst_rtp_buffer_map (buf, GST_MAP_READ, &rtp); marker = gst_rtp_buffer_get_marker (&rtp); GST_DEBUG ("process : got %" G_GSIZE_FORMAT " bytes, mark %d ts %u seqn %d", gst_buffer_get_size (buf), marker, gst_rtp_buffer_get_timestamp (&rtp), gst_rtp_buffer_get_seq (&rtp)); len = gst_rtp_buffer_get_payload_len (&rtp); outbuf = gst_rtp_buffer_get_payload_buffer (&rtp); gst_rtp_buffer_unmap (&rtp); if (outbuf) { GST_BUFFER_DURATION (outbuf) = gst_util_uint64_scale_int (len, GST_SECOND, depayload->clock_rate); if (marker) { /* mark start of talkspurt with RESYNC */ GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_RESYNC); } } return outbuf; }
static GstBuffer * gst_rtp_ilbc_depay_process (GstRTPBaseDepayload * depayload, GstBuffer * buf) { GstBuffer *outbuf; gboolean marker; GstRTPBuffer rtp = { NULL }; gst_rtp_buffer_map (buf, GST_MAP_READ, &rtp); marker = gst_rtp_buffer_get_marker (&rtp); GST_DEBUG ("process : got %" G_GSIZE_FORMAT " bytes, mark %d ts %u seqn %d", gst_buffer_get_size (buf), marker, gst_rtp_buffer_get_timestamp (&rtp), gst_rtp_buffer_get_seq (&rtp)); outbuf = gst_rtp_buffer_get_payload_buffer (&rtp); gst_rtp_buffer_unmap (&rtp); if (marker && outbuf) { /* mark start of talkspurt with DISCONT */ GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT); } return outbuf; }
static GstBuffer * gst_rtp_gsm_depay_process (GstRTPBaseDepayload * depayload, GstRTPBuffer * rtp) { GstBuffer *outbuf = NULL; gboolean marker; marker = gst_rtp_buffer_get_marker (rtp); GST_DEBUG ("process : got %" G_GSIZE_FORMAT " bytes, mark %d ts %u seqn %d", gst_buffer_get_size (rtp->buffer), marker, gst_rtp_buffer_get_timestamp (rtp), gst_rtp_buffer_get_seq (rtp)); outbuf = gst_rtp_buffer_get_payload_buffer (rtp); if (marker && outbuf) { /* mark start of talkspurt with RESYNC */ GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_RESYNC); } if (outbuf) { gst_rtp_drop_meta (GST_ELEMENT_CAST (depayload), outbuf, g_quark_from_static_string (GST_META_TAG_AUDIO_STR)); } return outbuf; }
static GstBuffer * gst_rtp_L16_depay_process (GstRTPBaseDepayload * depayload, GstBuffer * buf) { GstRtpL16Depay *rtpL16depay; GstBuffer *outbuf; gint payload_len; gboolean marker; GstRTPBuffer rtp = { NULL }; rtpL16depay = GST_RTP_L16_DEPAY (depayload); gst_rtp_buffer_map (buf, GST_MAP_READ, &rtp); payload_len = gst_rtp_buffer_get_payload_len (&rtp); if (payload_len <= 0) goto empty_packet; GST_DEBUG_OBJECT (rtpL16depay, "got payload of %d bytes", payload_len); outbuf = gst_rtp_buffer_get_payload_buffer (&rtp); marker = gst_rtp_buffer_get_marker (&rtp); if (marker) { /* mark talk spurt with DISCONT */ GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT); } outbuf = gst_buffer_make_writable (outbuf); if (rtpL16depay->order && !gst_audio_buffer_reorder_channels (outbuf, rtpL16depay->info.finfo->format, rtpL16depay->info.channels, rtpL16depay->info.position, rtpL16depay->order->pos)) { goto reorder_failed; } gst_rtp_buffer_unmap (&rtp); return outbuf; /* ERRORS */ empty_packet: { GST_ELEMENT_WARNING (rtpL16depay, STREAM, DECODE, ("Empty Payload."), (NULL)); gst_rtp_buffer_unmap (&rtp); return NULL; } reorder_failed: { GST_ELEMENT_ERROR (rtpL16depay, STREAM, DECODE, ("Channel reordering failed."), (NULL)); gst_rtp_buffer_unmap (&rtp); return NULL; } }
static GstBuffer * gst_rtp_opus_depay_process (GstRTPBaseDepayload * depayload, GstBuffer * buf) { GstBuffer *outbuf; GstRTPBuffer rtpbuf = { NULL, }; gst_rtp_buffer_map (buf, GST_MAP_READ, &rtpbuf); outbuf = gst_rtp_buffer_get_payload_buffer (&rtpbuf); gst_rtp_buffer_unmap (&rtpbuf); return outbuf; }
static GstBuffer * gst_rtp_mp1s_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf) { GstBuffer *outbuf; outbuf = gst_rtp_buffer_get_payload_buffer (buf); if (outbuf) GST_DEBUG ("gst_rtp_mp1s_depay_chain: pushing buffer of size %d", GST_BUFFER_SIZE (outbuf)); return outbuf; }
static GstBuffer * gst_rtp_g729_depay_process (GstRTPBaseDepayload * depayload, GstBuffer * buf) { GstRtpG729Depay *rtpg729depay; GstBuffer *outbuf = NULL; gint payload_len; gboolean marker; GstRTPBuffer rtp = { NULL }; rtpg729depay = GST_RTP_G729_DEPAY (depayload); gst_rtp_buffer_map (buf, GST_MAP_READ, &rtp); payload_len = gst_rtp_buffer_get_payload_len (&rtp); /* At least 2 bytes (CNG from G729 Annex B) */ if (payload_len < 2) { GST_ELEMENT_WARNING (rtpg729depay, STREAM, DECODE, (NULL), ("G729 RTP payload too small (%d)", payload_len)); goto bad_packet; } GST_LOG_OBJECT (rtpg729depay, "payload len %d", payload_len); if ((payload_len % 10) == 2) { GST_LOG_OBJECT (rtpg729depay, "G729 payload contains CNG frame"); } outbuf = gst_rtp_buffer_get_payload_buffer (&rtp); marker = gst_rtp_buffer_get_marker (&rtp); gst_rtp_buffer_unmap (&rtp); if (marker) { /* marker bit starts talkspurt */ GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_RESYNC); } GST_LOG_OBJECT (depayload, "pushing buffer of size %" G_GSIZE_FORMAT, gst_buffer_get_size (outbuf)); return outbuf; /* ERRORS */ bad_packet: { /* no fatal error */ return NULL; } }
static GstBuffer * gst_rtp_opus_depay_process (GstRTPBaseDepayload * depayload, GstBuffer * buf) { GstBuffer *outbuf; GstRTPBuffer rtpbuf = { NULL, }; gst_rtp_buffer_map (buf, GST_MAP_READ, &rtpbuf); outbuf = gst_rtp_buffer_get_payload_buffer (&rtpbuf); gst_rtp_buffer_unmap (&rtpbuf); outbuf = gst_buffer_make_writable (outbuf); /* Filter away all metas that are not sensible to copy */ gst_buffer_foreach_meta (outbuf, foreach_metadata, depayload); return outbuf; }
static GstBuffer * gst_rtp_g722_depay_process (GstRTPBaseDepayload * depayload, GstBuffer * buf) { GstRtpG722Depay *rtpg722depay; GstBuffer *outbuf; gint payload_len; gboolean marker; GstRTPBuffer rtp = { NULL }; rtpg722depay = GST_RTP_G722_DEPAY (depayload); gst_rtp_buffer_map (buf, GST_MAP_READ, &rtp); payload_len = gst_rtp_buffer_get_payload_len (&rtp); if (payload_len <= 0) goto empty_packet; GST_DEBUG_OBJECT (rtpg722depay, "got payload of %d bytes", payload_len); outbuf = gst_rtp_buffer_get_payload_buffer (&rtp); marker = gst_rtp_buffer_get_marker (&rtp); gst_rtp_buffer_unmap (&rtp); if (marker && outbuf) { /* mark talk spurt with RESYNC */ GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_RESYNC); } if (outbuf) { gst_rtp_drop_meta (GST_ELEMENT_CAST (rtpg722depay), outbuf, g_quark_from_static_string (GST_META_TAG_AUDIO_STR)); } return outbuf; /* ERRORS */ empty_packet: { GST_ELEMENT_WARNING (rtpg722depay, STREAM, DECODE, ("Empty Payload."), (NULL)); gst_rtp_buffer_unmap (&rtp); return NULL; } }
static GstBuffer * gst_rtp_g723_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf) { GstRtpG723Depay *rtpg723depay; GstBuffer *outbuf = NULL; gint payload_len; gboolean marker; rtpg723depay = GST_RTP_G723_DEPAY (depayload); payload_len = gst_rtp_buffer_get_payload_len (buf); /* At least 4 bytes */ if (payload_len < 4) goto too_small; GST_LOG_OBJECT (rtpg723depay, "payload len %d", payload_len); outbuf = gst_rtp_buffer_get_payload_buffer (buf); marker = gst_rtp_buffer_get_marker (buf); if (marker) { /* marker bit starts talkspurt */ GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT); } GST_LOG_OBJECT (depayload, "pushing buffer of size %d", GST_BUFFER_SIZE (outbuf)); return outbuf; /* ERRORS */ too_small: { GST_ELEMENT_WARNING (rtpg723depay, STREAM, DECODE, (NULL), ("G723 RTP payload too small (%d)", payload_len)); goto bad_packet; } bad_packet: { /* no fatal error */ return NULL; } }
static GstBuffer * gst_rtp_ilbc_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf) { GstBuffer *outbuf; gboolean marker; marker = gst_rtp_buffer_get_marker (buf); GST_DEBUG ("process : got %d bytes, mark %d ts %u seqn %d", GST_BUFFER_SIZE (buf), marker, gst_rtp_buffer_get_timestamp (buf), gst_rtp_buffer_get_seq (buf)); outbuf = gst_rtp_buffer_get_payload_buffer (buf); if (marker && outbuf) { /* mark start of talkspurt with DISCONT */ GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT); } return outbuf; }
static GstBuffer * gst_rtp_ilbc_depay_process (GstRTPBaseDepayload * depayload, GstRTPBuffer * rtp) { GstBuffer *outbuf; gboolean marker; marker = gst_rtp_buffer_get_marker (rtp); GST_DEBUG ("process : got %" G_GSIZE_FORMAT " bytes, mark %d ts %u seqn %d", gst_buffer_get_size (rtp->buffer), marker, gst_rtp_buffer_get_timestamp (rtp), gst_rtp_buffer_get_seq (rtp)); outbuf = gst_rtp_buffer_get_payload_buffer (rtp); if (marker && outbuf) { /* mark start of talkspurt with RESYNC */ GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_RESYNC); } return outbuf; }
static GstBuffer * gst_rtp_speex_depay_process (GstRTPBaseDepayload * depayload, GstBuffer * buf) { GstBuffer *outbuf = NULL; GstRTPBuffer rtp = { NULL }; gst_rtp_buffer_map (buf, GST_MAP_READ, &rtp); GST_DEBUG ("process : got %" G_GSIZE_FORMAT " bytes, mark %d ts %u seqn %d", gst_buffer_get_size (buf), gst_rtp_buffer_get_marker (&rtp), gst_rtp_buffer_get_timestamp (&rtp), gst_rtp_buffer_get_seq (&rtp)); /* nothing special to be done */ outbuf = gst_rtp_buffer_get_payload_buffer (&rtp); gst_rtp_buffer_unmap (&rtp); if (outbuf) GST_BUFFER_DURATION (outbuf) = 20 * GST_MSECOND; return outbuf; }
/* Process one RTP packet. Accumulate RTP payload in the proper place in a DV * frame, and return that frame if we detect a new frame, or NULL otherwise. * We assume a DV frame is 144000 bytes. That should accomodate PAL as well as * NTSC. */ static GstBuffer * gst_rtp_dv_depay_process (GstRTPBaseDepayload * base, GstRTPBuffer * rtp) { GstBuffer *out = NULL; GstBuffer *payload_buf; guint8 *payload; guint32 rtp_ts; guint payload_len, location; GstRTPDVDepay *dvdepay = GST_RTP_DV_DEPAY (base); gboolean marker; GstMapInfo map; marker = gst_rtp_buffer_get_marker (rtp); /* Check if the received packet contains (the start of) a new frame, we do * this by checking the RTP timestamp. */ rtp_ts = gst_rtp_buffer_get_timestamp (rtp); /* we cannot copy the packet yet if the marker is set, we will do that below * after taking out the data */ if (dvdepay->prev_ts != -1 && rtp_ts != dvdepay->prev_ts && !marker) { /* the timestamp changed */ GST_DEBUG_OBJECT (dvdepay, "new frame with ts %u, old ts %u", rtp_ts, dvdepay->prev_ts); /* return copy of accumulator. */ out = gst_buffer_copy (dvdepay->acc); gst_buffer_foreach_meta (dvdepay->acc, foreach_metadata_drop, NULL); } /* Extract the payload */ payload_len = gst_rtp_buffer_get_payload_len (rtp); payload = gst_rtp_buffer_get_payload (rtp); payload_buf = gst_rtp_buffer_get_payload_buffer (rtp); /* copy all DIF chunks in their place. */ gst_buffer_map (dvdepay->acc, &map, GST_MAP_READWRITE); while (payload_len >= 80) { guint offset; /* Calculate where in the frame the payload should go */ location = calculate_difblock_location (payload); if (location < 6) { /* part of a header, set the flag to mark that we have the header. */ dvdepay->header_mask |= (1 << location); GST_LOG_OBJECT (dvdepay, "got header at location %d, now %02x", location, dvdepay->header_mask); } else { GST_LOG_OBJECT (dvdepay, "got block at location %d", location); } if (location != -1) { /* get the byte offset of the dif block */ offset = location * 80; /* And copy it in, provided the location is sane. */ if (offset <= dvdepay->frame_size - 80) { memcpy (map.data + offset, payload, 80); gst_rtp_copy_meta (GST_ELEMENT_CAST (dvdepay), dvdepay->acc, payload_buf, 0); } } payload += 80; payload_len -= 80; } gst_buffer_unmap (dvdepay->acc, &map); gst_buffer_unref (payload_buf); if (marker) { GST_DEBUG_OBJECT (dvdepay, "marker bit complete frame %u", rtp_ts); /* only copy the frame when we have a complete header */ if (dvdepay->header_mask == 0x3f) { /* The marker marks the end of a frame that we need to push. The next frame * will change the timestamp but we won't copy the accumulator again because * we set the prev_ts to -1. */ out = gst_buffer_copy (dvdepay->acc); gst_buffer_foreach_meta (dvdepay->acc, foreach_metadata_drop, NULL); } else { GST_WARNING_OBJECT (dvdepay, "waiting for frame headers %02x", dvdepay->header_mask); } dvdepay->prev_ts = -1; } else { /* save last timestamp */ dvdepay->prev_ts = rtp_ts; } return out; }
static GstBuffer * gst_rtp_L16_depay_process (GstRTPBaseDepayload * depayload, GstRTPBuffer * rtp) { GstRtpL16Depay *rtpL16depay; GstBuffer *outbuf; gint payload_len; gboolean marker; GstAudioInfo *info; rtpL16depay = GST_RTP_L16_DEPAY (depayload); payload_len = gst_rtp_buffer_get_payload_len (rtp); if (payload_len <= 0) goto empty_packet; GST_DEBUG_OBJECT (rtpL16depay, "got payload of %d bytes", payload_len); outbuf = gst_rtp_buffer_get_payload_buffer (rtp); marker = gst_rtp_buffer_get_marker (rtp); if (marker) { /* mark talk spurt with RESYNC */ GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_RESYNC); } outbuf = gst_buffer_make_writable (outbuf); info = &rtpL16depay->info; if (payload_len % ((info->finfo->width * info->channels) / 8) != 0) goto wrong_payload_size; if (rtpL16depay->order && !gst_audio_buffer_reorder_channels (outbuf, info->finfo->format, info->channels, info->position, rtpL16depay->order->pos)) { goto reorder_failed; } gst_rtp_drop_meta (GST_ELEMENT_CAST (rtpL16depay), outbuf, g_quark_from_static_string (GST_META_TAG_AUDIO_STR)); return outbuf; /* ERRORS */ empty_packet: { GST_ELEMENT_WARNING (rtpL16depay, STREAM, DECODE, ("Empty Payload."), (NULL)); return NULL; } wrong_payload_size: { GST_ELEMENT_WARNING (rtpL16depay, STREAM, DECODE, ("Wrong Payload Size."), (NULL)); return NULL; } reorder_failed: { GST_ELEMENT_ERROR (rtpL16depay, STREAM, DECODE, ("Channel reordering failed."), (NULL)); return NULL; } }