2 * Opus Payloader Gst Element
4 * @author: Danilo Cesar Lemes de Paula <danilo.cesar@collabora.co.uk>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
28 #include <gst/rtp/gstrtpbuffer.h>
30 #include "gstrtpopuspay.h"
32 GST_DEBUG_CATEGORY_STATIC (rtpopuspay_debug);
33 #define GST_CAT_DEFAULT (rtpopuspay_debug)
36 static GstStaticPadTemplate gst_rtp_opus_pay_sink_template =
37 GST_STATIC_PAD_TEMPLATE ("sink",
40 GST_STATIC_CAPS ("audio/x-opus, multistream = (boolean) FALSE")
43 static GstStaticPadTemplate gst_rtp_opus_pay_src_template =
44 GST_STATIC_PAD_TEMPLATE ("src",
47 GST_STATIC_CAPS ("application/x-rtp, "
48 "media = (string) \"audio\", "
49 "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
50 "clock-rate = (int) 48000, "
51 "encoding-name = (string) { \"OPUS\", \"X-GST-OPUS-DRAFT-SPITTKA-00\" }")
54 static gboolean gst_rtp_opus_pay_setcaps (GstRTPBasePayload * payload,
56 static GstFlowReturn gst_rtp_opus_pay_handle_buffer (GstRTPBasePayload *
57 payload, GstBuffer * buffer);
59 G_DEFINE_TYPE (GstRtpOPUSPay, gst_rtp_opus_pay, GST_TYPE_RTP_BASE_PAYLOAD);
62 gst_rtp_opus_pay_class_init (GstRtpOPUSPayClass * klass)
64 GstRTPBasePayloadClass *gstbasertppayload_class;
65 GstElementClass *element_class;
67 gstbasertppayload_class = (GstRTPBasePayloadClass *) klass;
68 element_class = GST_ELEMENT_CLASS (klass);
70 gstbasertppayload_class->set_caps = gst_rtp_opus_pay_setcaps;
71 gstbasertppayload_class->handle_buffer = gst_rtp_opus_pay_handle_buffer;
73 gst_element_class_add_pad_template (element_class,
74 gst_static_pad_template_get (&gst_rtp_opus_pay_src_template));
75 gst_element_class_add_pad_template (element_class,
76 gst_static_pad_template_get (&gst_rtp_opus_pay_sink_template));
78 gst_element_class_set_static_metadata (element_class,
80 "Codec/Payloader/Network/RTP",
81 "Puts Opus audio in RTP packets",
82 "Danilo Cesar Lemes de Paula <danilo.cesar@collabora.co.uk>");
84 GST_DEBUG_CATEGORY_INIT (rtpopuspay_debug, "rtpopuspay", 0,
85 "Opus RTP Payloader");
89 gst_rtp_opus_pay_init (GstRtpOPUSPay * rtpopuspay)
94 gst_rtp_opus_pay_setcaps (GstRTPBasePayload * payload, GstCaps * caps)
101 src_caps = gst_pad_get_allowed_caps (GST_RTP_BASE_PAYLOAD_SRCPAD (payload));
103 src_caps = gst_caps_make_writable (src_caps);
104 src_caps = gst_caps_truncate (src_caps);
105 s = gst_caps_get_structure (src_caps, 0);
106 gst_structure_fixate_field_string (s, "encoding-name",
107 "X-GST-OPUS-DRAFT-SPITTKA-00");
108 encoding_name = g_strdup (gst_structure_get_string (s, "encoding-name"));
109 gst_caps_unref (src_caps);
111 encoding_name = g_strdup ("X-GST-OPUS-DRAFT-SPITTKA-00");
114 gst_rtp_base_payload_set_options (payload, "audio", FALSE,
115 encoding_name, 48000);
116 g_free (encoding_name);
117 res = gst_rtp_base_payload_set_outcaps (payload, NULL);
123 gst_rtp_opus_pay_handle_buffer (GstRTPBasePayload * basepayload,
127 GstClockTime pts, dts, duration;
129 pts = GST_BUFFER_PTS (buffer);
130 dts = GST_BUFFER_DTS (buffer);
131 duration = GST_BUFFER_DURATION (buffer);
133 outbuf = gst_rtp_buffer_new_allocate (0, 0, 0);
134 outbuf = gst_buffer_append (outbuf, buffer);
136 GST_BUFFER_PTS (outbuf) = pts;
137 GST_BUFFER_DTS (outbuf) = dts;
138 GST_BUFFER_DURATION (outbuf) = duration;
141 return gst_rtp_base_payload_push (basepayload, outbuf);