1 /* GStreamer plugin for forward error correction
2 * Copyright (C) 2017 Pexip
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 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 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 * Author: Mikhail Fludkov <misha@pexip.com>
21 #include "gstrtpstorage.h"
23 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
26 GST_STATIC_CAPS ("application/x-rtp")
29 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
32 GST_STATIC_CAPS ("application/x-rtp")
39 PROP_INTERNAL_STORAGE,
43 static GParamSpec *klass_properties[N_PROPERTIES] = { NULL, };
45 #define DEFAULT_SIZE_TIME (0)
47 GST_DEBUG_CATEGORY_STATIC (gst_rtp_storage_debug);
48 #define GST_CAT_DEFAULT (gst_rtp_storage_debug)
50 G_DEFINE_TYPE (GstRtpStorage, gst_rtp_storage, GST_TYPE_ELEMENT);
53 gst_rtp_storage_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
55 GstRtpStorage *self = GST_RTP_STORAGE (parent);;
57 if (rtp_storage_append_buffer (self->storage, buf))
58 return gst_pad_push (self->srcpad, buf);
63 gst_rtp_storage_set_property (GObject * object, guint prop_id,
64 const GValue * value, GParamSpec * pspec)
66 GstRtpStorage *self = GST_RTP_STORAGE (object);
68 if (GST_LEVEL_DEBUG <= gst_debug_category_get_threshold (GST_CAT_DEFAULT)) {
69 gchar *val_str = gst_value_serialize (value);
70 GST_DEBUG_OBJECT (object, "Setting property \"%s\" to %s", pspec->name,
77 rtp_storage_set_size (self->storage, g_value_get_uint64 (value));
80 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
86 gst_rtp_storage_get_property (GObject * object, guint prop_id,
87 GValue * value, GParamSpec * pspec)
89 GstRtpStorage *self = GST_RTP_STORAGE (object);
92 g_value_set_uint64 (value, rtp_storage_get_size (self->storage));
94 case PROP_INTERNAL_STORAGE:
96 g_value_set_object (value, self->storage);
100 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
104 if (GST_LEVEL_LOG <= gst_debug_category_get_threshold (GST_CAT_DEFAULT)) {
105 gchar *val_str = gst_value_serialize (value);
106 GST_LOG_OBJECT (object, "Returning property \"%s\" %s", pspec->name,
113 gst_rtp_storage_init (GstRtpStorage * self)
115 self->srcpad = gst_pad_new_from_static_template (&srctemplate, "src");
116 self->sinkpad = gst_pad_new_from_static_template (&sinktemplate, "sink");
117 GST_PAD_SET_PROXY_CAPS (self->sinkpad);
118 GST_PAD_SET_PROXY_ALLOCATION (self->sinkpad);
119 gst_pad_set_chain_function (self->sinkpad, gst_rtp_storage_chain);
121 gst_element_add_pad (GST_ELEMENT (self), self->srcpad);
122 gst_element_add_pad (GST_ELEMENT (self), self->sinkpad);
124 self->storage = rtp_storage_new ();
128 gst_rtp_storage_dispose (GObject * obj)
130 GstRtpStorage *self = GST_RTP_STORAGE (obj);
131 g_object_unref (self->storage);
132 G_OBJECT_CLASS (gst_rtp_storage_parent_class)->dispose (obj);
136 gst_rtp_storage_class_init (GstRtpStorageClass * klass)
138 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
139 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
141 GST_DEBUG_CATEGORY_INIT (gst_rtp_storage_debug,
142 "rtpstorage", 0, "RTP Storage");
144 gst_element_class_add_pad_template (element_class,
145 gst_static_pad_template_get (&srctemplate));
146 gst_element_class_add_pad_template (element_class,
147 gst_static_pad_template_get (&sinktemplate));
149 gst_element_class_set_static_metadata (element_class,
152 "Helper element for various purposes "
153 "(ex. recovering from packet loss using RED/FEC). "
154 "Saves given number of RTP packets. "
155 "Should be instantiated before jitterbuffer",
156 "Mikhail Fludkov <misha@pexip.com>");
158 gobject_class->set_property = gst_rtp_storage_set_property;
159 gobject_class->get_property = gst_rtp_storage_get_property;
160 gobject_class->dispose = gst_rtp_storage_dispose;
162 klass_properties[PROP_SIZE_TIME] =
163 g_param_spec_uint64 ("size-time", "Storage size (in ns)",
164 "The amount of data to keep in the storage (in ns, 0-disable)", 0,
165 G_MAXUINT64, DEFAULT_SIZE_TIME,
166 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
168 klass_properties[PROP_INTERNAL_STORAGE] =
169 g_param_spec_object ("internal-storage", "Internal storage",
170 "Internal RtpStorage object", G_TYPE_OBJECT,
171 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
173 g_object_class_install_properties (gobject_class, N_PROPERTIES,