Debian Codegraph @

ext/adaptivedemux2/dash/gstmpdhelper.c

raw
1 /* GStreamer
2 *
3 * Copyright (C) 2019 Collabora Ltd.
4 * Author: Stéphane Cerveau <[email protected]>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 *
20 */
21
22 #include "gstmpdhelper.h"
23 #include "gstmpdbaseurlnode.h"
24
25 #include <gst/pbutils/pbutils.h>
26
27 #define GST_CAT_DEFAULT gst_dash_demux2_debug
28
29 gboolean
30 gst_mpd_helper_get_mpd_type (xmlNode * a_node,
31 const gchar * property_name, GstMPDFileType * property_value)
32 {
33 xmlChar *prop_string;
34 gboolean exists = FALSE;
35
36 *property_value = GST_MPD_FILE_TYPE_STATIC; /* default */
37 prop_string = xmlGetProp (a_node, (const xmlChar *) property_name);
38 if (prop_string) {
39 if (xmlStrcmp (prop_string, (xmlChar *) "OnDemand") == 0
40 || xmlStrcmp (prop_string, (xmlChar *) "static") == 0) {
41 exists = TRUE;
42 *property_value = GST_MPD_FILE_TYPE_STATIC;
43 GST_LOG (" - %s: static", property_name);
44 } else if (xmlStrcmp (prop_string, (xmlChar *) "Live") == 0
45 || xmlStrcmp (prop_string, (xmlChar *) "dynamic") == 0) {
46 exists = TRUE;
47 *property_value = GST_MPD_FILE_TYPE_DYNAMIC;
48 GST_LOG (" - %s: dynamic", property_name);
49 } else {
50 GST_WARNING ("failed to parse MPD type property %s from xml string %s",
51 property_name, prop_string);
52 }
53 xmlFree (prop_string);
54 }
55
56 return exists;
57 }
58
59 gboolean
60 gst_mpd_helper_get_SAP_type (xmlNode * a_node,
61 const gchar * property_name, GstMPDSAPType * property_value)
62 {
63 xmlChar *prop_string;
64 guint prop_SAP_type = 0;
65 gboolean exists = FALSE;
66
67 prop_string = xmlGetProp (a_node, (const xmlChar *) property_name);
68 if (prop_string) {
69 if (sscanf ((gchar *) prop_string, "%u", &prop_SAP_type) == 1
70 && prop_SAP_type <= 6) {
71 exists = TRUE;
72 *property_value = (GstMPDSAPType) prop_SAP_type;
73 GST_LOG (" - %s: %u", property_name, prop_SAP_type);
74 } else {
75 GST_WARNING
76 ("failed to parse unsigned integer property %s from xml string %s",
77 property_name, prop_string);
78 }
79 xmlFree (prop_string);
80 }
81
82 return exists;
83 }
84
85 const gchar *
86 gst_mpd_helper_mimetype_to_caps (const gchar * mimeType)
87 {
88 if (mimeType == NULL)
89 return NULL;
90 if (strcmp (mimeType, "video/mp2t") == 0) {
91 return "video/mpegts, systemstream=(bool) true";
92 } else if (strcmp (mimeType, "video/mp4") == 0) {
93 return "video/quicktime";
94 } else if (strcmp (mimeType, "audio/mp4") == 0) {
95 return "audio/x-m4a";
96 } else if (strcmp (mimeType, "text/vtt") == 0) {
97 return "application/x-subtitle-vtt";
98 } else
99 return mimeType;
100 }
101
102 /* Some top-level mime types directly tell us which
103 * codec is inside */
104 GstCaps *
105 gst_mpd_helper_mimetype_to_codec_caps (const gchar * mimeType)
106 {
107 if (mimeType == NULL)
108 return NULL;
109
110 if (strcmp (mimeType, "text/vtt") == 0)
111 return gst_caps_new_empty_simple ("application/x-subtitle-vtt");
112
113 return NULL;
114 }
115
116 /*
117 * Combine a base url with the current stream base url from the list of
118 * baseURLs. Takes ownership of base and returns a new base.
119 */
120 GstUri *
121 gst_mpd_helper_combine_urls (GstUri * base, GList * list, gchar ** query,
122 guint idx)
123 {
124 GstMPDBaseURLNode *baseURL;
125 GstUri *ret = base;
126
127 if (list != NULL) {
128 baseURL = g_list_nth_data (list, idx);
129 if (!baseURL) {
130 baseURL = list->data;
131 }
132
133 ret = gst_uri_from_string_with_base (base, baseURL->baseURL);
134 gst_uri_unref (base);
135
136 if (ret && query) {
137 g_free (*query);
138 *query = gst_uri_get_query_string (ret);
139 if (*query) {
140 ret = gst_uri_make_writable (ret);
141 gst_uri_set_query_table (ret, NULL);
142 }
143 }
144 }
145
146 return ret;
147 }
148
149 /* comparison functions */
150 int
151 gst_mpd_helper_strncmp_ext (const char *s1, const char *s2)
152 {
153 if (s1 == NULL && s2 == NULL)
154 return 0;
155 if (s1 == NULL && s2 != NULL)
156 return 1;
157 if (s2 == NULL && s1 != NULL)
158 return 1;
159 return strncmp (s1, s2, strlen (s2));
160 }