• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer
2  *
3  * Copyright (C) 2019 Collabora Ltd.
4  *   Author: Stéphane Cerveau <scerveau@collabora.com>
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 "gstmpdbaseurlnode.h"
22 #include "gstmpdparser.h"
23 
24 G_DEFINE_TYPE (GstMPDBaseURLNode, gst_mpd_baseurl_node, GST_TYPE_MPD_NODE);
25 
26 enum
27 {
28   PROP_MPD_BASEURL_0,
29   PROP_MPD_BASEURL_URL,
30   PROP_MPD_BASEURL_SERVICE_LOCATION,
31   PROP_MPD_BASEURL_BYTE_RANGE,
32 };
33 
34 /* GObject VMethods */
35 
36 static void
gst_mpd_baseurl_node_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)37 gst_mpd_baseurl_node_set_property (GObject * object, guint prop_id,
38     const GValue * value, GParamSpec * pspec)
39 {
40   GstMPDBaseURLNode *self = GST_MPD_BASEURL_NODE (object);
41   switch (prop_id) {
42     case PROP_MPD_BASEURL_URL:
43       g_free (self->baseURL);
44       self->baseURL = g_value_dup_string (value);
45       break;
46     case PROP_MPD_BASEURL_SERVICE_LOCATION:
47       g_free (self->serviceLocation);
48       self->serviceLocation = g_value_dup_string (value);
49       break;
50     case PROP_MPD_BASEURL_BYTE_RANGE:
51       g_free (self->byteRange);
52       self->byteRange = g_value_dup_string (value);
53       break;
54     default:
55       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
56       break;
57   }
58 }
59 
60 static void
gst_mpd_baseurl_node_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)61 gst_mpd_baseurl_node_get_property (GObject * object, guint prop_id,
62     GValue * value, GParamSpec * pspec)
63 {
64   GstMPDBaseURLNode *self = GST_MPD_BASEURL_NODE (object);
65   switch (prop_id) {
66     case PROP_MPD_BASEURL_URL:
67       g_value_set_string (value, self->baseURL);
68       break;
69     case PROP_MPD_BASEURL_SERVICE_LOCATION:
70       g_value_set_string (value, self->serviceLocation);
71       break;
72     case PROP_MPD_BASEURL_BYTE_RANGE:
73       g_value_set_string (value, self->byteRange);
74       break;
75     default:
76       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
77       break;
78   }
79 }
80 
81 static void
gst_mpd_baseurl_node_finalize(GObject * object)82 gst_mpd_baseurl_node_finalize (GObject * object)
83 {
84   GstMPDBaseURLNode *self = GST_MPD_BASEURL_NODE (object);
85 
86   g_free (self->baseURL);
87   g_free (self->serviceLocation);
88   g_free (self->byteRange);
89 
90   G_OBJECT_CLASS (gst_mpd_baseurl_node_parent_class)->finalize (object);
91 }
92 
93 /* Base class */
94 
95 static xmlNodePtr
gst_mpd_baseurl_get_xml_node(GstMPDNode * node)96 gst_mpd_baseurl_get_xml_node (GstMPDNode * node)
97 {
98   xmlNodePtr baseurl_xml_node = NULL;
99   GstMPDBaseURLNode *self = GST_MPD_BASEURL_NODE (node);
100 
101   baseurl_xml_node = xmlNewNode (NULL, (xmlChar *) "BaseURL");
102 
103   if (self->serviceLocation)
104     gst_xml_helper_set_prop_string (baseurl_xml_node, "serviceLocation",
105         self->serviceLocation);
106 
107   if (self->byteRange)
108     gst_xml_helper_set_prop_string (baseurl_xml_node, "byteRange",
109         self->byteRange);
110 
111   if (self->baseURL)
112     gst_xml_helper_set_content (baseurl_xml_node, self->baseURL);
113 
114   return baseurl_xml_node;
115 }
116 
117 static void
gst_mpd_baseurl_node_class_init(GstMPDBaseURLNodeClass * klass)118 gst_mpd_baseurl_node_class_init (GstMPDBaseURLNodeClass * klass)
119 {
120   GObjectClass *object_class;
121   GstMPDNodeClass *m_klass;
122 
123   object_class = G_OBJECT_CLASS (klass);
124   m_klass = GST_MPD_NODE_CLASS (klass);
125 
126   object_class->finalize = gst_mpd_baseurl_node_finalize;
127   object_class->set_property = gst_mpd_baseurl_node_set_property;
128   object_class->get_property = gst_mpd_baseurl_node_get_property;
129 
130   m_klass->get_xml_node = gst_mpd_baseurl_get_xml_node;
131 
132   g_object_class_install_property (object_class, PROP_MPD_BASEURL_URL,
133       g_param_spec_string ("url", "base url",
134           "url of the base url", NULL,
135           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
136   g_object_class_install_property (object_class,
137       PROP_MPD_BASEURL_SERVICE_LOCATION,
138       g_param_spec_string ("service-location", "service location",
139           "service location", NULL,
140           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
141   g_object_class_install_property (object_class, PROP_MPD_BASEURL_BYTE_RANGE,
142       g_param_spec_string ("byte-range", "byte range", "byte range", NULL,
143           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
144 
145 }
146 
147 static void
gst_mpd_baseurl_node_init(GstMPDBaseURLNode * self)148 gst_mpd_baseurl_node_init (GstMPDBaseURLNode * self)
149 {
150   self->baseURL = NULL;
151   self->serviceLocation = NULL;
152   self->byteRange = NULL;
153 }
154 
155 GstMPDBaseURLNode *
gst_mpd_baseurl_node_new(void)156 gst_mpd_baseurl_node_new (void)
157 {
158   return g_object_new (GST_TYPE_MPD_BASEURL_NODE, NULL);
159 }
160 
161 void
gst_mpd_baseurl_node_free(GstMPDBaseURLNode * self)162 gst_mpd_baseurl_node_free (GstMPDBaseURLNode * self)
163 {
164   if (self)
165     gst_object_unref (self);
166 }
167