rtpvorbisdepay: remove dead code
[platform/upstream/gst-plugins-good.git] / gst / rtp / gstrtputils.c
1 /* GStreamer
2  * Copyright (C) 2015 Sebastian Dröge <sebastian@centricular.com>
3  *
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.
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  * Library General Public License for more details.
13  *
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., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19
20 #include "gstrtputils.h"
21
22 typedef struct
23 {
24   GstElement *element;
25   GstBuffer *outbuf;
26   GQuark copy_tag;
27 } CopyMetaData;
28
29 static gboolean
30 foreach_metadata_copy (GstBuffer * inbuf, GstMeta ** meta, gpointer user_data)
31 {
32   CopyMetaData *data = user_data;
33   GstElement *element = data->element;
34   GstBuffer *outbuf = data->outbuf;
35   GQuark copy_tag = data->copy_tag;
36   const GstMetaInfo *info = (*meta)->info;
37   const gchar *const *tags = gst_meta_api_type_get_tags (info->api);
38
39   if (!tags || (copy_tag != 0 && g_strv_length ((gchar **) tags) == 1
40           && gst_meta_api_type_has_tag (info->api, copy_tag))) {
41     GstMetaTransformCopy copy_data = { FALSE, 0, -1 };
42     GST_DEBUG_OBJECT (element, "copy metadata %s", g_type_name (info->api));
43     /* simply copy then */
44     info->transform_func (outbuf, *meta, inbuf,
45         _gst_meta_transform_copy, &copy_data);
46   } else {
47     GST_DEBUG_OBJECT (element, "not copying metadata %s",
48         g_type_name (info->api));
49   }
50
51   return TRUE;
52 }
53
54 /* TODO: Should probably make copy_tag an array at some point */
55 void
56 gst_rtp_copy_meta (GstElement * element, GstBuffer * outbuf, GstBuffer * inbuf,
57     GQuark copy_tag)
58 {
59   CopyMetaData data = { element, outbuf, copy_tag };
60
61   gst_buffer_foreach_meta (inbuf, foreach_metadata_copy, &data);
62 }
63
64 typedef struct
65 {
66   GstElement *element;
67   GQuark keep_tag;
68 } DropMetaData;
69
70 static gboolean
71 foreach_metadata_drop (GstBuffer * inbuf, GstMeta ** meta, gpointer user_data)
72 {
73   DropMetaData *data = user_data;
74   GstElement *element = data->element;
75   GQuark keep_tag = data->keep_tag;
76   const GstMetaInfo *info = (*meta)->info;
77   const gchar *const *tags = gst_meta_api_type_get_tags (info->api);
78
79   if (!tags || (keep_tag != 0 && g_strv_length ((gchar **) tags) == 1
80           && gst_meta_api_type_has_tag (info->api, keep_tag))) {
81     GST_DEBUG_OBJECT (element, "keeping metadata %s", g_type_name (info->api));
82   } else {
83     GST_DEBUG_OBJECT (element, "dropping metadata %s", g_type_name (info->api));
84     *meta = NULL;
85   }
86
87   return TRUE;
88 }
89
90 /* TODO: Should probably make keep_tag an array at some point */
91 void
92 gst_rtp_drop_meta (GstElement * element, GstBuffer * buf, GQuark keep_tag)
93 {
94   DropMetaData data = { element, keep_tag };
95
96   gst_buffer_foreach_meta (buf, foreach_metadata_drop, &data);
97 }
98
99 /* Stolen from bad/gst/mpegtsdemux/payloader_parsers.c */
100 /* variable length Exp-Golomb parsing according to H.265 spec section 9.2*/
101 gboolean
102 gst_rtp_read_golomb (GstBitReader * br, guint32 * value)
103 {
104   guint8 b, leading_zeros = -1;
105   *value = 1;
106
107   for (b = 0; !b; leading_zeros++) {
108     if (!gst_bit_reader_get_bits_uint8 (br, &b, 1))
109       return FALSE;
110     *value *= 2;
111   }
112
113   *value = (*value >> 1) - 1;
114   if (leading_zeros > 0) {
115     guint32 tmp = 0;
116     if (!gst_bit_reader_get_bits_uint32 (br, &tmp, leading_zeros))
117       return FALSE;
118     *value += tmp;
119   }
120
121   return TRUE;
122 }