Commit 9a96783a authored by Wim Taymans's avatar Wim Taymans

rtp: port some more elements

parent bf9b4f83
......@@ -111,31 +111,27 @@ static gboolean gst_rtp_amr_depay_setcaps (GstBaseRTPDepayload * depayload,
static GstBuffer *gst_rtp_amr_depay_process (GstBaseRTPDepayload * depayload,
GstBuffer * buf);
GST_BOILERPLATE (GstRtpAMRDepay, gst_rtp_amr_depay, GstBaseRTPDepayload,
GST_TYPE_BASE_RTP_DEPAYLOAD);
#define gst_rtp_amr_depay_parent_class parent_class
G_DEFINE_TYPE (GstRtpAMRDepay, gst_rtp_amr_depay, GST_TYPE_BASE_RTP_DEPAYLOAD);
static void
gst_rtp_amr_depay_base_init (gpointer klass)
gst_rtp_amr_depay_class_init (GstRtpAMRDepayClass * klass)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
GstElementClass *gstelement_class;
GstBaseRTPDepayloadClass *gstbasertpdepayload_class;
gstelement_class = (GstElementClass *) klass;
gstbasertpdepayload_class = (GstBaseRTPDepayloadClass *) klass;
gst_element_class_add_pad_template (element_class,
gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&gst_rtp_amr_depay_src_template));
gst_element_class_add_pad_template (element_class,
gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&gst_rtp_amr_depay_sink_template));
gst_element_class_set_details_simple (element_class, "RTP AMR depayloader",
gst_element_class_set_details_simple (gstelement_class, "RTP AMR depayloader",
"Codec/Depayloader/Network/RTP",
"Extracts AMR or AMR-WB audio from RTP packets (RFC 3267)",
"Wim Taymans <wim.taymans@gmail.com>");
}
static void
gst_rtp_amr_depay_class_init (GstRtpAMRDepayClass * klass)
{
GstBaseRTPDepayloadClass *gstbasertpdepayload_class;
gstbasertpdepayload_class = (GstBaseRTPDepayloadClass *) klass;
gstbasertpdepayload_class->process = gst_rtp_amr_depay_process;
gstbasertpdepayload_class->set_caps = gst_rtp_amr_depay_setcaps;
......@@ -145,8 +141,7 @@ gst_rtp_amr_depay_class_init (GstRtpAMRDepayClass * klass)
}
static void
gst_rtp_amr_depay_init (GstRtpAMRDepay * rtpamrdepay,
GstRtpAMRDepayClass * klass)
gst_rtp_amr_depay_init (GstRtpAMRDepay * rtpamrdepay)
{
GstBaseRTPDepayload *depayload;
......@@ -277,6 +272,9 @@ gst_rtp_amr_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
const gint *frame_size;
GstBuffer *outbuf = NULL;
gint payload_len;
GstRTPBuffer rtp = { NULL };
guint8 *odata;
gsize osize;
rtpamrdepay = GST_RTP_AMR_DEPAY (depayload);
......@@ -286,6 +284,8 @@ gst_rtp_amr_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
else
frame_size = wb_frame_size;
gst_rtp_buffer_map (buf, GST_MAP_READ, &rtp);
/* when we get here, 1 channel, 8000/16000 Hz, octet aligned, no CRC,
* no robust sorting, no interleaving data is to be depayloaded */
{
......@@ -294,13 +294,13 @@ gst_rtp_amr_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
gint amr_len;
gint ILL, ILP;
payload_len = gst_rtp_buffer_get_payload_len (buf);
payload_len = gst_rtp_buffer_get_payload_len (&rtp);
/* need at least 2 bytes for the header */
if (payload_len < 2)
goto too_small;
payload = gst_rtp_buffer_get_payload (buf);
payload = gst_rtp_buffer_get_payload (&rtp);
/* depay CMR. The CMR is used by the sender to request
* a new encoding mode.
......@@ -375,8 +375,10 @@ gst_rtp_amr_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
outbuf = gst_buffer_new_and_alloc (payload_len);
/* point to destination */
p = GST_BUFFER_DATA (outbuf);
odata = gst_buffer_map (outbuf, &osize, NULL, GST_MAP_WRITE);
/* point to first data packet */
p = odata;
dp = payload + num_packets;
if (rtpamrdepay->crc) {
/* skip CRC if present */
......@@ -398,17 +400,19 @@ gst_rtp_amr_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
dp += fr_size;
}
}
gst_buffer_unmap (outbuf, odata, osize);
/* we can set the duration because each packet is 20 milliseconds */
GST_BUFFER_DURATION (outbuf) = num_packets * 20 * GST_MSECOND;
if (gst_rtp_buffer_get_marker (buf)) {
if (gst_rtp_buffer_get_marker (&rtp)) {
/* marker bit marks a discont buffer after a talkspurt. */
GST_DEBUG_OBJECT (depayload, "marker bit was set");
GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
}
GST_DEBUG_OBJECT (depayload, "pushing buffer of size %d",
GST_BUFFER_SIZE (outbuf));
gst_buffer_get_size (outbuf));
}
return outbuf;
......
......@@ -93,35 +93,29 @@ static GstFlowReturn gst_rtp_amr_pay_handle_buffer (GstBaseRTPPayload * pad,
static GstStateChangeReturn
gst_rtp_amr_pay_change_state (GstElement * element, GstStateChange transition);
GST_BOILERPLATE (GstRtpAMRPay, gst_rtp_amr_pay, GstBaseRTPPayload,
GST_TYPE_BASE_RTP_PAYLOAD);
#define gst_rtp_amr_pay_parent_class parent_class
G_DEFINE_TYPE (GstRtpAMRPay, gst_rtp_amr_pay, GST_TYPE_BASE_RTP_PAYLOAD);
static void
gst_rtp_amr_pay_base_init (gpointer klass)
gst_rtp_amr_pay_class_init (GstRtpAMRPayClass * klass)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
GstElementClass *gstelement_class;
GstBaseRTPPayloadClass *gstbasertppayload_class;
gstelement_class = (GstElementClass *) klass;
gstbasertppayload_class = (GstBaseRTPPayloadClass *) klass;
gst_element_class_add_pad_template (element_class,
gstelement_class->change_state = gst_rtp_amr_pay_change_state;
gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&gst_rtp_amr_pay_src_template));
gst_element_class_add_pad_template (element_class,
gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&gst_rtp_amr_pay_sink_template));
gst_element_class_set_details_simple (element_class, "RTP AMR payloader",
gst_element_class_set_details_simple (gstelement_class, "RTP AMR payloader",
"Codec/Payloader/Network/RTP",
"Payload-encode AMR or AMR-WB audio into RTP packets (RFC 3267)",
"Wim Taymans <wim.taymans@gmail.com>");
}
static void
gst_rtp_amr_pay_class_init (GstRtpAMRPayClass * klass)
{
GstBaseRTPPayloadClass *gstbasertppayload_class;
GstElementClass *gstelement_class;
gstelement_class = (GstElementClass *) klass;
gstelement_class->change_state = gst_rtp_amr_pay_change_state;
gstbasertppayload_class = (GstBaseRTPPayloadClass *) klass;
gstbasertppayload_class->set_caps = gst_rtp_amr_pay_setcaps;
gstbasertppayload_class->handle_buffer = gst_rtp_amr_pay_handle_buffer;
......@@ -131,9 +125,8 @@ gst_rtp_amr_pay_class_init (GstRtpAMRPayClass * klass)
}
static void
gst_rtp_amr_pay_init (GstRtpAMRPay * rtpamrpay, GstRtpAMRPayClass * klass)
gst_rtp_amr_pay_init (GstRtpAMRPay * rtpamrpay)
{
/* needed because of GST_BOILERPLATE */
}
static void
......@@ -234,20 +227,22 @@ gst_rtp_amr_pay_handle_buffer (GstBaseRTPPayload * basepayload,
GstRtpAMRPay *rtpamrpay;
const gint *frame_size;
GstFlowReturn ret;
guint size, payload_len;
guint payload_len;
gsize size;
GstBuffer *outbuf;
guint8 *payload, *data, *payload_amr;
guint8 *payload, *data, *ptr, *payload_amr;
GstClockTime timestamp, duration;
guint packet_len, mtu;
gint i, num_packets, num_nonempty_packets;
gint amr_len;
gboolean sid = FALSE;
GstRTPBuffer rtp = { NULL };
rtpamrpay = GST_RTP_AMR_PAY (basepayload);
mtu = GST_BASE_RTP_PAYLOAD_MTU (rtpamrpay);
size = GST_BUFFER_SIZE (buffer);
data = GST_BUFFER_DATA (buffer);
data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ);
timestamp = GST_BUFFER_TIMESTAMP (buffer);
duration = GST_BUFFER_DURATION (buffer);
......@@ -301,6 +296,8 @@ gst_rtp_amr_pay_handle_buffer (GstBaseRTPPayload * basepayload,
/* now alloc output buffer */
outbuf = gst_rtp_buffer_new_allocate (payload_len, 0, 0);
gst_rtp_buffer_map (outbuf, GST_MAP_WRITE, &rtp);
/* copy timestamp */
GST_BUFFER_TIMESTAMP (outbuf) = timestamp;
......@@ -313,7 +310,7 @@ gst_rtp_amr_pay_handle_buffer (GstBaseRTPPayload * basepayload,
if (GST_BUFFER_IS_DISCONT (buffer)) {
GST_DEBUG_OBJECT (basepayload, "discont, setting marker bit");
GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
gst_rtp_buffer_set_marker (outbuf, TRUE);
gst_rtp_buffer_set_marker (&rtp, TRUE);
gst_rtp_amr_pay_recalc_rtp_time (rtpamrpay, timestamp);
}
......@@ -331,7 +328,7 @@ gst_rtp_amr_pay_handle_buffer (GstBaseRTPPayload * basepayload,
(num_packets * 160) << (rtpamrpay->mode == GST_RTP_AMR_P_MODE_WB);
/* get payload, this is now writable */
payload = gst_rtp_buffer_get_payload (outbuf);
payload = gst_rtp_buffer_get_payload (&rtp);
/* 0 1 2 3 4 5 6 7
* +-+-+-+-+-+-+-+-+
......@@ -346,6 +343,7 @@ gst_rtp_amr_pay_handle_buffer (GstBaseRTPPayload * basepayload,
/* copy data in payload, first we copy all the FTs then all
* the AMR data. The last FT has to have the F flag cleared. */
ptr = data;
for (i = 1; i <= num_packets; i++) {
guint8 FT;
gint fr_size;
......@@ -355,26 +353,29 @@ gst_rtp_amr_pay_handle_buffer (GstBaseRTPPayload * basepayload,
* |F| FT |Q|P|P| more FT...
* +-+-+-+-+-+-+-+-+
*/
FT = (*data & 0x78) >> 3;
FT = (*ptr & 0x78) >> 3;
fr_size = frame_size[FT];
if (i == num_packets)
/* last packet, clear F flag */
payload[i] = *data & 0x7f;
payload[i] = *ptr & 0x7f;
else
/* set F flag */
payload[i] = *data | 0x80;
payload[i] = *ptr | 0x80;
memcpy (payload_amr, &data[1], fr_size);
memcpy (payload_amr, &ptr[1], fr_size);
/* all sizes are > 0 since we checked for that above */
data += fr_size + 1;
ptr += fr_size + 1;
payload_amr += fr_size;
}
gst_buffer_unmap (buffer, data, size);
gst_buffer_unref (buffer);
gst_rtp_buffer_unmap (&rtp);
ret = gst_basertppayload_push (basepayload, outbuf);
return ret;
......@@ -384,6 +385,7 @@ wrong_size:
{
GST_ELEMENT_ERROR (basepayload, STREAM, FORMAT,
(NULL), ("received AMR frame with size <= 0"));
gst_buffer_unmap (buffer, data, size);
gst_buffer_unref (buffer);
return GST_FLOW_ERROR;
......@@ -392,6 +394,7 @@ incomplete_frame:
{
GST_ELEMENT_ERROR (basepayload, STREAM, FORMAT,
(NULL), ("received incomplete AMR frames"));
gst_buffer_unmap (buffer, data, size);
gst_buffer_unref (buffer);
return GST_FLOW_ERROR;
......@@ -400,6 +403,7 @@ too_big:
{
GST_ELEMENT_ERROR (basepayload, STREAM, FORMAT,
(NULL), ("received too many AMR frames for MTU"));
gst_buffer_unmap (buffer, data, size);
gst_buffer_unref (buffer);
return GST_FLOW_ERROR;
......
......@@ -61,7 +61,8 @@ static GstStaticPadTemplate gst_rtp_h263_depay_sink_template =
"clock-rate = (int) 90000, " "encoding-name = (string) \"H263\"")
);
GST_BOILERPLATE (GstRtpH263Depay, gst_rtp_h263_depay, GstBaseRTPDepayload,
#define gst_rtp_h263_depay_parent_class parent_class
G_DEFINE_TYPE (GstRtpH263Depay, gst_rtp_h263_depay,
GST_TYPE_BASE_RTP_DEPAYLOAD);
static void gst_rtp_h263_depay_finalize (GObject * object);
......@@ -74,23 +75,6 @@ static GstBuffer *gst_rtp_h263_depay_process (GstBaseRTPDepayload * depayload,
gboolean gst_rtp_h263_depay_setcaps (GstBaseRTPDepayload * filter,
GstCaps * caps);
static void
gst_rtp_h263_depay_base_init (gpointer klass)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_rtp_h263_depay_src_template));
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_rtp_h263_depay_sink_template));
gst_element_class_set_details_simple (element_class, "RTP H263 depayloader",
"Codec/Depayloader/Network/RTP",
"Extracts H263 video from RTP packets (RFC 2190)",
"Philippe Kalaf <philippe.kalaf@collabora.co.uk>, "
"Edward Hervey <bilboed@bilboed.com>");
}
static void
gst_rtp_h263_depay_class_init (GstRtpH263DepayClass * klass)
{
......@@ -98,19 +82,30 @@ gst_rtp_h263_depay_class_init (GstRtpH263DepayClass * klass)
GstElementClass *gstelement_class;
GstBaseRTPDepayloadClass *gstbasertpdepayload_class;
GST_DEBUG_CATEGORY_INIT (rtph263depay_debug, "rtph263depay", 0,
"H263 Video RTP Depayloader");
gobject_class = (GObjectClass *) klass;
gstelement_class = (GstElementClass *) klass;
gstbasertpdepayload_class = (GstBaseRTPDepayloadClass *) klass;
gstbasertpdepayload_class->process = gst_rtp_h263_depay_process;
gstbasertpdepayload_class->set_caps = gst_rtp_h263_depay_setcaps;
gobject_class->finalize = gst_rtp_h263_depay_finalize;
gstelement_class->change_state = gst_rtp_h263_depay_change_state;
GST_DEBUG_CATEGORY_INIT (rtph263depay_debug, "rtph263depay", 0,
"H263 Video RTP Depayloader");
gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&gst_rtp_h263_depay_src_template));
gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&gst_rtp_h263_depay_sink_template));
gst_element_class_set_details_simple (gstelement_class,
"RTP H263 depayloader", "Codec/Depayloader/Network/RTP",
"Extracts H263 video from RTP packets (RFC 2190)",
"Philippe Kalaf <philippe.kalaf@collabora.co.uk>, "
"Edward Hervey <bilboed@bilboed.com>");
gstbasertpdepayload_class->process = gst_rtp_h263_depay_process;
gstbasertpdepayload_class->set_caps = gst_rtp_h263_depay_setcaps;
}
static void
......
......@@ -78,7 +78,8 @@ static GstStaticPadTemplate gst_rtp_h263p_depay_sink_template =
)
);
GST_BOILERPLATE (GstRtpH263PDepay, gst_rtp_h263p_depay, GstBaseRTPDepayload,
#define gst_rtp_h263p_depay_parent_class parent_class
G_DEFINE_TYPE (GstRtpH263PDepay, gst_rtp_h263p_depay,
GST_TYPE_BASE_RTP_DEPAYLOAD);
static void gst_rtp_h263p_depay_finalize (GObject * object);
......@@ -91,23 +92,6 @@ static GstBuffer *gst_rtp_h263p_depay_process (GstBaseRTPDepayload * depayload,
gboolean gst_rtp_h263p_depay_setcaps (GstBaseRTPDepayload * filter,
GstCaps * caps);
static void
gst_rtp_h263p_depay_base_init (gpointer klass)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_rtp_h263p_depay_src_template));
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_rtp_h263p_depay_sink_template));
gst_element_class_set_details_simple (element_class, "RTP H263 depayloader",
"Codec/Depayloader/Network/RTP",
"Extracts H263/+/++ video from RTP packets (RFC 4629)",
"Wim Taymans <wim.taymans@gmail.com>");
}
static void
gst_rtp_h263p_depay_class_init (GstRtpH263PDepayClass * klass)
{
......@@ -119,17 +103,26 @@ gst_rtp_h263p_depay_class_init (GstRtpH263PDepayClass * klass)
gstelement_class = (GstElementClass *) klass;
gstbasertpdepayload_class = (GstBaseRTPDepayloadClass *) klass;
gstbasertpdepayload_class->process = gst_rtp_h263p_depay_process;
gstbasertpdepayload_class->set_caps = gst_rtp_h263p_depay_setcaps;
gobject_class->finalize = gst_rtp_h263p_depay_finalize;
gstelement_class->change_state = gst_rtp_h263p_depay_change_state;
gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&gst_rtp_h263p_depay_src_template));
gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&gst_rtp_h263p_depay_sink_template));
gst_element_class_set_details_simple (gstelement_class,
"RTP H263 depayloader", "Codec/Depayloader/Network/RTP",
"Extracts H263/+/++ video from RTP packets (RFC 4629)",
"Wim Taymans <wim.taymans@gmail.com>");
gstbasertpdepayload_class->process = gst_rtp_h263p_depay_process;
gstbasertpdepayload_class->set_caps = gst_rtp_h263p_depay_setcaps;
}
static void
gst_rtp_h263p_depay_init (GstRtpH263PDepay * rtph263pdepay,
GstRtpH263PDepayClass * klass)
gst_rtp_h263p_depay_init (GstRtpH263PDepay * rtph263pdepay)
{
rtph263pdepay->adapter = gst_adapter_new ();
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment