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);
70 rtp_storage_set_size (self->storage, g_value_get_uint64 (value));
73 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
79 gst_rtp_storage_get_property (GObject * object, guint prop_id,
80 GValue * value, GParamSpec * pspec)
82 GstRtpStorage *self = GST_RTP_STORAGE (object);
85 g_value_set_uint64 (value, rtp_storage_get_size (self->storage));
87 case PROP_INTERNAL_STORAGE:
89 g_value_set_object (value, self->storage);
93 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
99 gst_rtp_storage_init (GstRtpStorage * self)
101 self->srcpad = gst_pad_new_from_static_template (&srctemplate, "src");
102 self->sinkpad = gst_pad_new_from_static_template (&sinktemplate, "sink");
103 GST_PAD_SET_PROXY_CAPS (self->sinkpad);
104 GST_PAD_SET_PROXY_ALLOCATION (self->sinkpad);
105 gst_pad_set_chain_function (self->sinkpad, gst_rtp_storage_chain);
107 gst_element_add_pad (GST_ELEMENT (self), self->srcpad);
108 gst_element_add_pad (GST_ELEMENT (self), self->sinkpad);
110 self->storage = rtp_storage_new ();
114 gst_rtp_storage_dispose (GObject * obj)
116 GstRtpStorage *self = GST_RTP_STORAGE (obj);
117 g_object_unref (self->storage);
118 G_OBJECT_CLASS (gst_rtp_storage_parent_class)->dispose (obj);
122 gst_rtp_storage_class_init (GstRtpStorageClass * klass)
124 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
125 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
127 GST_DEBUG_CATEGORY_INIT (gst_rtp_storage_debug,
128 "rtpstorage", 0, "RTP Storage");
130 gst_element_class_add_pad_template (element_class,
131 gst_static_pad_template_get (&srctemplate));
132 gst_element_class_add_pad_template (element_class,
133 gst_static_pad_template_get (&sinktemplate));
135 gst_element_class_set_static_metadata (element_class,
138 "Helper element for various purposes "
139 "(ex. recovering from packet loss using RED/FEC). "
140 "Saves given number of RTP packets. "
141 "Should be instantiated before jitterbuffer",
142 "Mikhail Fludkov <misha@pexip.com>");
144 gobject_class->set_property = gst_rtp_storage_set_property;
145 gobject_class->get_property = gst_rtp_storage_get_property;
146 gobject_class->dispose = gst_rtp_storage_dispose;
148 klass_properties[PROP_SIZE_TIME] =
149 g_param_spec_uint64 ("size-time", "Storage size (in ns)",
150 "The amount of data to keep in the storage (in ns, 0-disable)", 0,
151 G_MAXUINT64, DEFAULT_SIZE_TIME,
152 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
154 klass_properties[PROP_INTERNAL_STORAGE] =
155 g_param_spec_object ("internal-storage", "Internal storage",
156 "Internal RtpStorage object", G_TYPE_OBJECT,
157 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
159 g_object_class_install_properties (gobject_class, N_PROPERTIES,