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 "gstmpdrepresentationnode.h"
22 #include "gstmpdparser.h"
23
24 G_DEFINE_TYPE (GstMPDRepresentationNode, gst_mpd_representation_node,
25 GST_TYPE_MPD_REPRESENTATION_BASE_NODE);
26
27 enum
28 {
29 PROP_MPD_REPRESENTATION_0,
30 PROP_MPD_REPRESENTATION_ID,
31 PROP_MPD_REPRESENTATION_BANDWIDTH,
32 PROP_MPD_REPRESENTATION_QUALITY_RANKING,
33 };
34
35 /* GObject VMethods */
36
37 static void
gst_mpd_representation_node_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)38 gst_mpd_representation_node_set_property (GObject * object, guint prop_id,
39 const GValue * value, GParamSpec * pspec)
40 {
41 GstMPDRepresentationNode *self = GST_MPD_REPRESENTATION_NODE (object);
42 switch (prop_id) {
43 case PROP_MPD_REPRESENTATION_ID:
44 g_free (self->id);
45 self->id = g_value_dup_string (value);
46 break;
47 case PROP_MPD_REPRESENTATION_BANDWIDTH:
48 self->bandwidth = g_value_get_uint (value);
49 break;
50 case PROP_MPD_REPRESENTATION_QUALITY_RANKING:
51 self->qualityRanking = g_value_get_uint (value);
52 break;
53 default:
54 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
55 break;
56 }
57 }
58
59 static void
gst_mpd_representation_node_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)60 gst_mpd_representation_node_get_property (GObject * object, guint prop_id,
61 GValue * value, GParamSpec * pspec)
62 {
63 GstMPDRepresentationNode *self = GST_MPD_REPRESENTATION_NODE (object);
64 switch (prop_id) {
65 case PROP_MPD_REPRESENTATION_ID:
66 g_value_set_string (value, self->id);
67 break;
68 case PROP_MPD_REPRESENTATION_BANDWIDTH:
69 g_value_set_uint (value, self->bandwidth);
70 break;
71 case PROP_MPD_REPRESENTATION_QUALITY_RANKING:
72 g_value_set_uint (value, self->qualityRanking);
73 break;
74 default:
75 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
76 break;
77 }
78 }
79
80 static void
gst_mpd_representation_node_finalize(GObject * object)81 gst_mpd_representation_node_finalize (GObject * object)
82 {
83 GstMPDRepresentationNode *self = GST_MPD_REPRESENTATION_NODE (object);
84
85 if (self->id)
86 xmlFree (self->id);
87 g_strfreev (self->dependencyId);
88 g_strfreev (self->mediaStreamStructureId);
89 g_list_free_full (self->SubRepresentations,
90 (GDestroyNotify) gst_mpd_sub_representation_node_free);
91 gst_mpd_segment_base_node_free (self->SegmentBase);
92 gst_mpd_segment_template_node_free (self->SegmentTemplate);
93 gst_mpd_segment_list_node_free (self->SegmentList);
94 g_list_free_full (self->BaseURLs, (GDestroyNotify) gst_mpd_baseurl_node_free);
95
96 G_OBJECT_CLASS (gst_mpd_representation_node_parent_class)->finalize (object);
97 }
98
99 /* Base class */
100
101 static xmlNodePtr
gst_mpd_representation_get_xml_node(GstMPDNode * node)102 gst_mpd_representation_get_xml_node (GstMPDNode * node)
103 {
104 gchar *value;
105 xmlNodePtr representation_xml_node = NULL;
106 GstMPDRepresentationNode *self = GST_MPD_REPRESENTATION_NODE (node);
107
108 representation_xml_node = xmlNewNode (NULL, (xmlChar *) "Representation");
109
110 gst_xml_helper_set_prop_string (representation_xml_node, "id", self->id);
111 gst_xml_helper_set_prop_uint (representation_xml_node, "bandwidth",
112 self->bandwidth);
113 if (self->qualityRanking)
114 gst_xml_helper_set_prop_uint (representation_xml_node, "qualityRanking",
115 self->qualityRanking);
116
117
118 if (self->dependencyId) {
119 value = g_strjoinv (" ", self->dependencyId);
120 gst_xml_helper_set_prop_string (representation_xml_node, "dependencyId",
121 value);
122 g_free (value);
123 }
124 if (self->mediaStreamStructureId) {
125 value = g_strjoinv (" ", self->mediaStreamStructureId);
126 gst_xml_helper_set_prop_string (representation_xml_node,
127 "mediaStreamStructureId", value);
128 g_free (value);
129 }
130
131 g_list_foreach (self->BaseURLs, gst_mpd_node_get_list_item,
132 representation_xml_node);
133 g_list_foreach (self->SubRepresentations,
134 gst_mpd_representation_base_node_get_list_item, representation_xml_node);
135
136 gst_mpd_node_add_child_node (GST_MPD_NODE (self->SegmentBase),
137 representation_xml_node);
138 gst_mpd_mult_segment_base_node_add_child_node (GST_MPD_NODE
139 (self->SegmentTemplate), representation_xml_node);
140 gst_mpd_mult_segment_base_node_add_child_node (GST_MPD_NODE
141 (self->SegmentList), representation_xml_node);
142
143 return representation_xml_node;
144 }
145
146 static void
gst_mpd_representation_node_class_init(GstMPDRepresentationNodeClass * klass)147 gst_mpd_representation_node_class_init (GstMPDRepresentationNodeClass * klass)
148 {
149 GObjectClass *object_class;
150 GstMPDNodeClass *m_klass;
151
152 object_class = G_OBJECT_CLASS (klass);
153 m_klass = GST_MPD_NODE_CLASS (klass);
154
155 object_class->finalize = gst_mpd_representation_node_finalize;
156 object_class->set_property = gst_mpd_representation_node_set_property;
157 object_class->get_property = gst_mpd_representation_node_get_property;
158
159 m_klass->get_xml_node = gst_mpd_representation_get_xml_node;
160
161 g_object_class_install_property (object_class,
162 PROP_MPD_REPRESENTATION_BANDWIDTH, g_param_spec_uint ("bandwidth",
163 "bandwidth", "representation bandwidth", 0, G_MAXUINT, 0,
164 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
165 g_object_class_install_property (object_class,
166 PROP_MPD_REPRESENTATION_QUALITY_RANKING,
167 g_param_spec_uint ("quality-ranking", "quality ranking",
168 "representation quality ranking", 0, G_MAXUINT, 0,
169 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
170 }
171
172 static void
gst_mpd_representation_node_init(GstMPDRepresentationNode * self)173 gst_mpd_representation_node_init (GstMPDRepresentationNode * self)
174 {
175 self->id = NULL;
176 self->bandwidth = 0;
177 self->qualityRanking = 0;
178 self->dependencyId = NULL;
179 self->mediaStreamStructureId = NULL;
180 self->BaseURLs = NULL;
181 self->SubRepresentations = NULL;
182 self->SegmentBase = NULL;
183 self->SegmentTemplate = NULL;
184 self->SegmentList = NULL;
185 }
186
187 GstMPDRepresentationNode *
gst_mpd_representation_node_new(void)188 gst_mpd_representation_node_new (void)
189 {
190 return g_object_new (GST_TYPE_MPD_REPRESENTATION_NODE, NULL);
191 }
192
193 void
gst_mpd_representation_node_free(GstMPDRepresentationNode * self)194 gst_mpd_representation_node_free (GstMPDRepresentationNode * self)
195 {
196 if (self)
197 gst_object_unref (self);
198 }
199