| 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 |
#include "gstmpdutctimingnode.h" |
| 22 |
#include "gstmpdparser.h" |
| 23 |
|
| 24 |
G_DEFINE_TYPE (GstMPDUTCTimingNode2, gst_mpd_utctiming_node, GST_TYPE_MPD_NODE); |
| 25 |
|
| 26 |
static const struct GstMPDUTCTimingMethod gst_mpd_utctiming_methods[] = { |
| 27 |
{"urn:mpeg:dash:utc:ntp:2014", GST_MPD_UTCTIMING_TYPE_NTP}, |
| 28 |
{"urn:mpeg:dash:utc:sntp:2014", GST_MPD_UTCTIMING_TYPE_SNTP}, |
| 29 |
{"urn:mpeg:dash:utc:http-head:2014", GST_MPD_UTCTIMING_TYPE_HTTP_HEAD}, |
| 30 |
{"urn:mpeg:dash:utc:http-xsdate:2014", GST_MPD_UTCTIMING_TYPE_HTTP_XSDATE}, |
| 31 |
{"urn:mpeg:dash:utc:http-iso:2014", GST_MPD_UTCTIMING_TYPE_HTTP_ISO}, |
| 32 |
{"urn:mpeg:dash:utc:http-ntp:2014", GST_MPD_UTCTIMING_TYPE_HTTP_NTP}, |
| 33 |
{"urn:mpeg:dash:utc:direct:2014", GST_MPD_UTCTIMING_TYPE_DIRECT}, |
| 34 |
/* |
| 35 |
* Early working drafts used the :2012 namespace and this namespace is |
| 36 |
* used by some DASH packagers. To work-around these packagers, we also |
| 37 |
* accept the early draft scheme names. |
| 38 |
*/ |
| 39 |
{"urn:mpeg:dash:utc:ntp:2012", GST_MPD_UTCTIMING_TYPE_NTP}, |
| 40 |
{"urn:mpeg:dash:utc:sntp:2012", GST_MPD_UTCTIMING_TYPE_SNTP}, |
| 41 |
{"urn:mpeg:dash:utc:http-head:2012", GST_MPD_UTCTIMING_TYPE_HTTP_HEAD}, |
| 42 |
{"urn:mpeg:dash:utc:http-xsdate:2012", GST_MPD_UTCTIMING_TYPE_HTTP_XSDATE}, |
| 43 |
{"urn:mpeg:dash:utc:http-iso:2012", GST_MPD_UTCTIMING_TYPE_HTTP_ISO}, |
| 44 |
{"urn:mpeg:dash:utc:http-ntp:2012", GST_MPD_UTCTIMING_TYPE_HTTP_NTP}, |
| 45 |
{"urn:mpeg:dash:utc:direct:2012", GST_MPD_UTCTIMING_TYPE_DIRECT}, |
| 46 |
{NULL, 0} |
| 47 |
}; |
| 48 |
|
| 49 |
/* GObject VMethods */ |
| 50 |
|
| 51 |
static void |
| 52 |
gst_mpd_utctiming_node_finalize (GObject * object) |
| 53 |
{ |
| 54 |
GstMPDUTCTimingNode *self = GST_MPD_UTCTIMING_NODE (object); |
| 55 |
|
| 56 |
g_strfreev (self->urls); |
| 57 |
|
| 58 |
G_OBJECT_CLASS (gst_mpd_utctiming_node_parent_class)->finalize (object); |
| 59 |
} |
| 60 |
|
| 61 |
/* Base class */ |
| 62 |
|
| 63 |
static xmlNodePtr |
| 64 |
gst_mpd_utc_timing_get_xml_node (GstMPDNode * node) |
| 65 |
{ |
| 66 |
xmlNodePtr utc_timing_xml_node = NULL; |
| 67 |
gchar *value = NULL; |
| 68 |
GstMPDUTCTimingNode *self = GST_MPD_UTCTIMING_NODE (node); |
| 69 |
|
| 70 |
utc_timing_xml_node = xmlNewNode (NULL, (xmlChar *) "UTCTiming"); |
| 71 |
|
| 72 |
if (self->method) { |
| 73 |
gst_xml_helper_set_prop_string (utc_timing_xml_node, "schemeiduri", |
| 74 |
(gchar *) gst_mpd_utctiming_get_scheme_id_uri (self->method)); |
| 75 |
} |
| 76 |
if (self->urls) { |
| 77 |
value = g_strjoinv (" ", self->urls); |
| 78 |
gst_xml_helper_set_prop_string (utc_timing_xml_node, "value", value); |
| 79 |
g_free (value); |
| 80 |
} |
| 81 |
|
| 82 |
return utc_timing_xml_node; |
| 83 |
} |
| 84 |
|
| 85 |
static void |
| 86 |
gst_mpd_utctiming_node_class_init (GstMPDUTCTimingNodeClass * klass) |
| 87 |
{ |
| 88 |
GObjectClass *object_class; |
| 89 |
GstMPDNodeClass *m_klass; |
| 90 |
|
| 91 |
object_class = G_OBJECT_CLASS (klass); |
| 92 |
m_klass = GST_MPD_NODE_CLASS (klass); |
| 93 |
|
| 94 |
object_class->finalize = gst_mpd_utctiming_node_finalize; |
| 95 |
|
| 96 |
m_klass->get_xml_node = gst_mpd_utc_timing_get_xml_node; |
| 97 |
} |
| 98 |
|
| 99 |
static void |
| 100 |
gst_mpd_utctiming_node_init (GstMPDUTCTimingNode * self) |
| 101 |
{ |
| 102 |
self->method = 0; |
| 103 |
self->urls = NULL; |
| 104 |
} |
| 105 |
|
| 106 |
GstMPDUTCTimingNode * |
| 107 |
gst_mpd_utctiming_node_new (void) |
| 108 |
{ |
| 109 |
return g_object_new (GST_TYPE_MPD_UTCTIMING_NODE, NULL); |
| 110 |
} |
| 111 |
|
| 112 |
void |
| 113 |
gst_mpd_utctiming_node_free (GstMPDUTCTimingNode * self) |
| 114 |
{ |
| 115 |
if (self) |
| 116 |
gst_object_unref (self); |
| 117 |
} |
| 118 |
|
| 119 |
const gchar * |
| 120 |
gst_mpd_utctiming_get_scheme_id_uri (GstMPDUTCTimingType type) |
| 121 |
{ |
| 122 |
int i; |
| 123 |
for (i = 0; gst_mpd_utctiming_methods[i].name; ++i) { |
| 124 |
if (type == gst_mpd_utctiming_methods[i].method) |
| 125 |
return gst_mpd_utctiming_methods[i].name; |
| 126 |
} |
| 127 |
return NULL; |
| 128 |
} |
| 129 |
|
| 130 |
GstMPDUTCTimingType |
| 131 |
gst_mpd_utctiming_get_method (gchar * schemeIDURI) |
| 132 |
{ |
| 133 |
int i; |
| 134 |
for (i = 0; gst_mpd_utctiming_methods[i].name; ++i) { |
| 135 |
if (g_ascii_strncasecmp (gst_mpd_utctiming_methods[i].name, |
| 136 |
schemeIDURI, strlen (gst_mpd_utctiming_methods[i].name)) == 0) |
| 137 |
return gst_mpd_utctiming_methods[i].method; |
| 138 |
} |
| 139 |
return GST_MPD_UTCTIMING_TYPE_UNKNOWN; |
| 140 |
} |