2 * Copyright (C) 2015 Sebastian Dröge <sebastian@centricular.com>
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.
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.
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.
20 #include "gstrtputils.h"
30 foreach_metadata_copy (GstBuffer * inbuf, GstMeta ** meta, gpointer user_data)
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);
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, ©_data);
47 GST_DEBUG_OBJECT (element, "not copying metadata %s",
48 g_type_name (info->api));
54 /* TODO: Should probably make copy_tag an array at some point */
56 gst_rtp_copy_meta (GstElement * element, GstBuffer * outbuf, GstBuffer * inbuf,
59 CopyMetaData data = { element, outbuf, copy_tag };
61 gst_buffer_foreach_meta (inbuf, foreach_metadata_copy, &data);
71 foreach_metadata_drop (GstBuffer * inbuf, GstMeta ** meta, gpointer user_data)
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);
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));
83 GST_DEBUG_OBJECT (element, "dropping metadata %s", g_type_name (info->api));
90 /* TODO: Should probably make keep_tag an array at some point */
92 gst_rtp_drop_meta (GstElement * element, GstBuffer * buf, GQuark keep_tag)
94 DropMetaData data = { element, keep_tag };
96 gst_buffer_foreach_meta (buf, foreach_metadata_drop, &data);
99 /* Stolen from bad/gst/mpegtsdemux/payloader_parsers.c */
100 /* variable length Exp-Golomb parsing according to H.265 spec section 9.2*/
102 gst_rtp_read_golomb (GstBitReader * br, guint32 * value)
104 guint8 b, leading_zeros = -1;
107 for (b = 0; !b; leading_zeros++) {
108 if (!gst_bit_reader_get_bits_uint8 (br, &b, 1))
113 *value = (*value >> 1) - 1;
114 if (leading_zeros > 0) {
116 if (!gst_bit_reader_get_bits_uint32 (br, &tmp, leading_zeros))