2 * Copyright (C) <2010> Wim Taymans <wim.taymans@gmail.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
26 #include <gst/rtp/gstrtpbuffer.h>
28 #include "gstrtpgstpay.h"
32 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
33 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
34 * |C| CV |D|X|Y|Z| MBZ |
35 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
37 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
39 * C: caps inlined flag
40 * When C set, first part of payload contains caps definition. Caps definition
41 * starts with variable-length length prefix and then a string of that length.
42 * the length is encoded in big endian 7 bit chunks, the top 1 bit of a byte
43 * is the continuation marker and the 7 next bits the data. A continuation
44 * marker of 1 means that the next byte contains more data.
46 * CV: caps version, 0 = caps from SDP, 1 - 7 inlined caps
47 * D: delta unit buffer
55 static GstStaticPadTemplate gst_rtp_gst_pay_sink_template =
56 GST_STATIC_PAD_TEMPLATE ("sink",
61 static GstStaticPadTemplate gst_rtp_gst_pay_src_template =
62 GST_STATIC_PAD_TEMPLATE ("src",
65 GST_STATIC_CAPS ("application/x-rtp, "
66 "media = (string) \"application\", "
67 "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
68 "clock-rate = (int) 90000, " "encoding-name = (string) \"X-GST\"")
71 static gboolean gst_rtp_gst_pay_setcaps (GstBaseRTPPayload * payload,
73 static GstFlowReturn gst_rtp_gst_pay_handle_buffer (GstBaseRTPPayload * payload,
76 GST_BOILERPLATE (GstRtpGSTPay, gst_rtp_gst_pay, GstBaseRTPPayload,
77 GST_TYPE_BASE_RTP_PAYLOAD)
79 static void gst_rtp_gst_pay_base_init (gpointer klass)
81 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
83 gst_element_class_add_static_pad_template (element_class,
84 &gst_rtp_gst_pay_src_template);
85 gst_element_class_add_static_pad_template (element_class,
86 &gst_rtp_gst_pay_sink_template);
88 gst_element_class_set_details_simple (element_class,
89 "RTP GStreamer payloader", "Codec/Payloader/Network/RTP",
90 "Payload GStreamer buffers as RTP packets",
91 "Wim Taymans <wim.taymans@gmail.com>");
95 gst_rtp_gst_pay_class_init (GstRtpGSTPayClass * klass)
97 GstBaseRTPPayloadClass *gstbasertppayload_class;
99 gstbasertppayload_class = (GstBaseRTPPayloadClass *) klass;
101 gstbasertppayload_class->set_caps = gst_rtp_gst_pay_setcaps;
102 gstbasertppayload_class->handle_buffer = gst_rtp_gst_pay_handle_buffer;
106 gst_rtp_gst_pay_init (GstRtpGSTPay * rtpgstpay, GstRtpGSTPayClass * klass)
111 gst_rtp_gst_pay_setcaps (GstBaseRTPPayload * payload, GstCaps * caps)
114 gchar *capsstr, *capsenc;
116 capsstr = gst_caps_to_string (caps);
117 capsenc = g_base64_encode ((guchar *) capsstr, strlen (capsstr));
120 gst_basertppayload_set_options (payload, "application", TRUE, "X-GST", 90000);
122 gst_basertppayload_set_outcaps (payload, "caps", G_TYPE_STRING, capsenc,
130 gst_rtp_gst_pay_handle_buffer (GstBaseRTPPayload * basepayload,
133 GstRtpGSTPay *rtpgstpay;
138 GstClockTime timestamp;
142 rtpgstpay = GST_RTP_GST_PAY (basepayload);
144 size = GST_BUFFER_SIZE (buffer);
145 data = GST_BUFFER_DATA (buffer);
146 timestamp = GST_BUFFER_TIMESTAMP (buffer);
150 /* caps always from SDP for now */
152 if (GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DELTA_UNIT))
154 if (GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_MEDIA1))
156 if (GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_MEDIA2))
158 if (GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_MEDIA3))
163 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
164 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
165 * |C| CV |D|X|Y|Z| MBZ |
166 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
168 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
178 /* this will be the total lenght of the packet */
179 packet_len = gst_rtp_buffer_calc_packet_len (8 + size, 0, 0);
181 /* fill one MTU or all available bytes */
182 towrite = MIN (packet_len, GST_BASE_RTP_PAYLOAD_MTU (rtpgstpay));
184 /* this is the payload length */
185 payload_len = gst_rtp_buffer_calc_payload_len (towrite, 0, 0);
187 /* create buffer to hold the payload */
188 outbuf = gst_rtp_buffer_new_allocate (payload_len, 0, 0);
189 payload = gst_rtp_buffer_get_payload (outbuf);
192 payload[1] = payload[2] = payload[3] = 0;
193 payload[4] = frag_offset >> 24;
194 payload[5] = frag_offset >> 16;
195 payload[6] = frag_offset >> 8;
196 payload[7] = frag_offset & 0xff;
201 memcpy (payload, data, payload_len);
205 frag_offset += payload_len;
208 gst_rtp_buffer_set_marker (outbuf, TRUE);
210 GST_BUFFER_TIMESTAMP (outbuf) = timestamp;
212 ret = gst_basertppayload_push (basepayload, outbuf);
214 gst_buffer_unref (buffer);
220 gst_rtp_gst_pay_plugin_init (GstPlugin * plugin)
222 return gst_element_register (plugin, "rtpgstpay",
223 GST_RANK_NONE, GST_TYPE_RTP_GST_PAY);