rtp: fec: fix build with gstreamer debug log system disabled
[platform/upstream/gst-plugins-good.git] / gst / rtp / gstrtpstorage.c
1 /* GStreamer plugin for forward error correction
2  * Copyright (C) 2017 Pexip
3  *
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.
8  *
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.
13  *
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
17  *
18  * Author: Mikhail Fludkov <misha@pexip.com>
19  */
20
21 #include "gstrtpstorage.h"
22
23 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
24     GST_PAD_SINK,
25     GST_PAD_ALWAYS,
26     GST_STATIC_CAPS ("application/x-rtp")
27     );
28
29 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
30     GST_PAD_SRC,
31     GST_PAD_ALWAYS,
32     GST_STATIC_CAPS ("application/x-rtp")
33     );
34
35 enum
36 {
37   PROP_0,
38   PROP_SIZE_TIME,
39   PROP_INTERNAL_STORAGE,
40   N_PROPERTIES
41 };
42
43 static GParamSpec *klass_properties[N_PROPERTIES] = { NULL, };
44
45 #define DEFAULT_SIZE_TIME (0)
46
47 GST_DEBUG_CATEGORY_STATIC (gst_rtp_storage_debug);
48 #define GST_CAT_DEFAULT (gst_rtp_storage_debug)
49
50 G_DEFINE_TYPE (GstRtpStorage, gst_rtp_storage, GST_TYPE_ELEMENT);
51
52 static GstFlowReturn
53 gst_rtp_storage_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
54 {
55   GstRtpStorage *self = GST_RTP_STORAGE (parent);;
56
57   if (rtp_storage_append_buffer (self->storage, buf))
58     return gst_pad_push (self->srcpad, buf);
59   return GST_FLOW_OK;
60 }
61
62 static void
63 gst_rtp_storage_set_property (GObject * object, guint prop_id,
64     const GValue * value, GParamSpec * pspec)
65 {
66   GstRtpStorage *self = GST_RTP_STORAGE (object);
67
68   switch (prop_id) {
69     case PROP_SIZE_TIME:
70       rtp_storage_set_size (self->storage, g_value_get_uint64 (value));
71       break;
72     default:
73       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
74       break;
75   }
76 }
77
78 static void
79 gst_rtp_storage_get_property (GObject * object, guint prop_id,
80     GValue * value, GParamSpec * pspec)
81 {
82   GstRtpStorage *self = GST_RTP_STORAGE (object);
83   switch (prop_id) {
84     case PROP_SIZE_TIME:
85       g_value_set_uint64 (value, rtp_storage_get_size (self->storage));
86       break;
87     case PROP_INTERNAL_STORAGE:
88     {
89       g_value_set_object (value, self->storage);
90       break;
91     }
92     default:
93       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
94       break;
95   }
96 }
97
98 static void
99 gst_rtp_storage_init (GstRtpStorage * self)
100 {
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);
106
107   gst_element_add_pad (GST_ELEMENT (self), self->srcpad);
108   gst_element_add_pad (GST_ELEMENT (self), self->sinkpad);
109
110   self->storage = rtp_storage_new ();
111 }
112
113 static void
114 gst_rtp_storage_dispose (GObject * obj)
115 {
116   GstRtpStorage *self = GST_RTP_STORAGE (obj);
117   g_object_unref (self->storage);
118   G_OBJECT_CLASS (gst_rtp_storage_parent_class)->dispose (obj);
119 }
120
121 static void
122 gst_rtp_storage_class_init (GstRtpStorageClass * klass)
123 {
124   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
125   GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
126
127   GST_DEBUG_CATEGORY_INIT (gst_rtp_storage_debug,
128       "rtpstorage", 0, "RTP Storage");
129
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));
134
135   gst_element_class_set_static_metadata (element_class,
136       "RTP storage",
137       "Analyzer/RTP",
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>");
143
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;
147
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);
153
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);
158
159   g_object_class_install_properties (gobject_class, N_PROPERTIES,
160       klass_properties);
161 }