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"
29 GQuark rtp_quark_meta_tag_video;
30 GQuark rtp_quark_meta_tag_audio;
33 foreach_metadata_copy (GstBuffer * inbuf, GstMeta ** meta, gpointer user_data)
35 CopyMetaData *data = user_data;
36 GstElement *element = data->element;
37 GstBuffer *outbuf = data->outbuf;
38 GQuark copy_tag = data->copy_tag;
39 const GstMetaInfo *info = (*meta)->info;
40 const gchar *const *tags = gst_meta_api_type_get_tags (info->api);
42 if (info->transform_func && (!tags || !tags[0] || (copy_tag != 0
43 && g_strv_length ((gchar **) tags) == 1
44 && gst_meta_api_type_has_tag (info->api, copy_tag)))) {
45 GstMetaTransformCopy copy_data = { FALSE, 0, -1 };
46 GST_DEBUG_OBJECT (element, "copy metadata %s", g_type_name (info->api));
47 /* simply copy then */
48 info->transform_func (outbuf, *meta, inbuf,
49 _gst_meta_transform_copy, ©_data);
51 GST_DEBUG_OBJECT (element, "not copying metadata %s",
52 g_type_name (info->api));
58 /* TODO: Should probably make copy_tag an array at some point */
60 gst_rtp_copy_meta (GstElement * element, GstBuffer * outbuf, GstBuffer * inbuf,
63 CopyMetaData data = { element, outbuf, copy_tag };
65 gst_buffer_foreach_meta (inbuf, foreach_metadata_copy, &data);
69 gst_rtp_copy_video_meta (gpointer element, GstBuffer * outbuf,
72 gst_rtp_copy_meta (element, outbuf, inbuf, rtp_quark_meta_tag_video);
76 gst_rtp_copy_audio_meta (gpointer element, GstBuffer * outbuf,
79 gst_rtp_copy_meta (element, outbuf, inbuf, rtp_quark_meta_tag_audio);
89 foreach_metadata_drop (GstBuffer * inbuf, GstMeta ** meta, gpointer user_data)
91 DropMetaData *data = user_data;
92 GstElement *element = data->element;
93 GQuark keep_tag = data->keep_tag;
94 const GstMetaInfo *info = (*meta)->info;
95 const gchar *const *tags = gst_meta_api_type_get_tags (info->api);
97 if (!tags || !tags[0] || (keep_tag != 0
98 && g_strv_length ((gchar **) tags) == 1
99 && gst_meta_api_type_has_tag (info->api, keep_tag))) {
100 GST_DEBUG_OBJECT (element, "keeping metadata %s", g_type_name (info->api));
102 GST_DEBUG_OBJECT (element, "dropping metadata %s", g_type_name (info->api));
109 /* TODO: Should probably make keep_tag an array at some point */
111 gst_rtp_drop_meta (GstElement * element, GstBuffer * buf, GQuark keep_tag)
113 DropMetaData data = { element, keep_tag };
115 gst_buffer_foreach_meta (buf, foreach_metadata_drop, &data);
119 gst_rtp_drop_non_audio_meta (gpointer element, GstBuffer * buf)
121 gst_rtp_drop_meta (element, buf, rtp_quark_meta_tag_audio);
125 gst_rtp_drop_non_video_meta (gpointer element, GstBuffer * buf)
127 gst_rtp_drop_meta (element, buf, rtp_quark_meta_tag_video);
130 /* Stolen from bad/gst/mpegtsdemux/payloader_parsers.c */
131 /* variable length Exp-Golomb parsing according to H.265 spec section 9.2*/
133 gst_rtp_read_golomb (GstBitReader * br, guint32 * value)
135 guint8 b, leading_zeros = -1;
138 for (b = 0; !b; leading_zeros++) {
139 if (!gst_bit_reader_get_bits_uint8 (br, &b, 1))
144 *value = (*value >> 1) - 1;
145 if (leading_zeros > 0) {
147 if (!gst_bit_reader_get_bits_uint32 (br, &tmp, leading_zeros))