Debian Codegraph @

ext/adaptivedemux2/dash/gstmpdperiodnode.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 #include "gstmpdperiodnode.h"
22 #include "gstmpdparser.h"
23
24 G_DEFINE_TYPE (GstMPDPeriodNode2, gst_mpd_period_node, GST_TYPE_MPD_NODE);
25
26 enum
27 {
28 PROP_MPD_PERIOD_0,
29 PROP_MPD_PERIOD_ID,
30 PROP_MPD_PERIOD_START,
31 PROP_MPD_PERIOD_DURATION,
32 PROP_MPD_PERIOD_BITSTREAM_SWITCHING,
33 };
34
35 /* GObject VMethods */
36
37 static void
38 gst_mpd_period_node_set_property (GObject * object, guint prop_id,
39 const GValue * value, GParamSpec * pspec)
40 {
41 GstMPDPeriodNode *self = GST_MPD_PERIOD_NODE (object);
42 switch (prop_id) {
43 case PROP_MPD_PERIOD_ID:
44 g_free (self->id);
45 self->id = g_value_dup_string (value);
46 break;
47 case PROP_MPD_PERIOD_START:
48 self->start = g_value_get_uint64 (value);
49 break;
50 case PROP_MPD_PERIOD_DURATION:
51 self->duration = g_value_get_uint64 (value);
52 break;
53 case PROP_MPD_PERIOD_BITSTREAM_SWITCHING:
54 self->bitstreamSwitching = g_value_get_boolean (value);
55 break;
56 default:
57 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
58 break;
59 }
60 }
61
62 static void
63 gst_mpd_period_node_get_property (GObject * object, guint prop_id,
64 GValue * value, GParamSpec * pspec)
65 {
66 GstMPDPeriodNode *self = GST_MPD_PERIOD_NODE (object);
67 switch (prop_id) {
68 case PROP_MPD_PERIOD_ID:
69 g_value_set_string (value, self->id);
70 break;
71 case PROP_MPD_PERIOD_START:
72 g_value_set_uint64 (value, self->start);
73 break;
74 case PROP_MPD_PERIOD_DURATION:
75 g_value_set_uint64 (value, self->duration);
76 break;
77 case PROP_MPD_PERIOD_BITSTREAM_SWITCHING:
78 g_value_set_boolean (value, self->bitstreamSwitching);
79 break;
80 default:
81 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
82 break;
83 }
84 }
85
86 static void
87 gst_mpd_period_node_finalize (GObject * object)
88 {
89 GstMPDPeriodNode *self = GST_MPD_PERIOD_NODE (object);
90
91 g_free (self->id);
92 gst_mpd_segment_base_node_free (self->SegmentBase);
93 gst_mpd_segment_list_node_free (self->SegmentList);
94 gst_mpd_segment_template_node_free (self->SegmentTemplate);
95 g_list_free_full (self->AdaptationSets,
96 (GDestroyNotify) gst_mpd_adaptation_set_node_free);
97 g_list_free_full (self->Subsets, (GDestroyNotify) gst_mpd_subset_node_free);
98 g_list_free_full (self->BaseURLs, (GDestroyNotify) gst_mpd_baseurl_node_free);
99 if (self->xlink_href)
100 xmlFree (self->xlink_href);
101
102 G_OBJECT_CLASS (gst_mpd_period_node_parent_class)->finalize (object);
103 }
104
105 /* Base class */
106
107 static xmlNodePtr
108 gst_mpd_period_get_xml_node (GstMPDNode * node)
109 {
110 xmlNodePtr period_xml_node = NULL;
111 GstMPDPeriodNode *self = GST_MPD_PERIOD_NODE (node);
112
113 period_xml_node = xmlNewNode (NULL, (xmlChar *) "Period");
114
115 if (self->id)
116 gst_xml_helper_set_prop_string (period_xml_node, "id", self->id);
117
118 gst_xml_helper_set_prop_duration (period_xml_node, "start", self->start);
119 gst_xml_helper_set_prop_duration (period_xml_node, "duration",
120 self->duration);
121 gst_xml_helper_set_prop_boolean (period_xml_node, "bitstreamSwitching",
122 self->bitstreamSwitching);
123
124 if (self->SegmentBase)
125 gst_mpd_node_add_child_node (GST_MPD_NODE (self->SegmentBase),
126 period_xml_node);
127
128 if (self->SegmentList)
129 gst_mpd_mult_segment_base_node_add_child_node (GST_MPD_NODE
130 (self->SegmentList), period_xml_node);
131
132 if (self->SegmentTemplate)
133 gst_mpd_mult_segment_base_node_add_child_node (GST_MPD_NODE
134 (self->SegmentTemplate), period_xml_node);
135
136 g_list_foreach (self->AdaptationSets,
137 gst_mpd_representation_base_node_get_list_item, period_xml_node);
138 g_list_foreach (self->Subsets, gst_mpd_node_get_list_item, period_xml_node);
139 g_list_foreach (self->BaseURLs, gst_mpd_node_get_list_item, period_xml_node);
140
141
142 return period_xml_node;
143 }
144
145 static void
146 gst_mpd_period_node_class_init (GstMPDPeriodNodeClass * klass)
147 {
148 GObjectClass *object_class;
149 GstMPDNodeClass *m_klass;
150
151
152 object_class = G_OBJECT_CLASS (klass);
153 m_klass = GST_MPD_NODE_CLASS (klass);
154
155 object_class->finalize = gst_mpd_period_node_finalize;
156 object_class->set_property = gst_mpd_period_node_set_property;
157 object_class->get_property = gst_mpd_period_node_get_property;
158
159 m_klass->get_xml_node = gst_mpd_period_get_xml_node;
160
161 g_object_class_install_property (object_class, PROP_MPD_PERIOD_ID,
162 g_param_spec_string ("id", "id",
163 "unique id for period", NULL,
164 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
165
166 g_object_class_install_property (object_class, PROP_MPD_PERIOD_START,
167 g_param_spec_uint64 ("start", "Period start",
168 "Period start",
169 0, G_MAXUINT64, 0,
170 (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
171
172 g_object_class_install_property (object_class, PROP_MPD_PERIOD_DURATION,
173 g_param_spec_uint64 ("duration", "period duration",
174 "Period duration",
175 0, G_MAXUINT64, 0,
176 (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
177
178 g_object_class_install_property (object_class,
179 PROP_MPD_PERIOD_BITSTREAM_SWITCHING,
180 g_param_spec_boolean ("bitstream-switching", "Bitstream switching",
181 "Bitstream switching", FALSE,
182 (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
183 }
184
185 static void
186 gst_mpd_period_node_init (GstMPDPeriodNode * self)
187 {
188 self->id = NULL;
189 self->start = 0; /* [ms] */
190 self->duration = 0; /* [ms] */
191 self->bitstreamSwitching = 0;
192 self->SegmentBase = NULL;
193 self->SegmentList = NULL;
194 self->SegmentTemplate = NULL;
195 self->AdaptationSets = NULL;
196 self->Subsets = NULL;
197 self->BaseURLs = NULL;
198 self->xlink_href = NULL;
199 self->actuate = 0;
200 }
201
202 GstMPDPeriodNode *
203 gst_mpd_period_node_new (void)
204 {
205 return g_object_new (GST_TYPE_MPD_PERIOD_NODE, NULL);
206 }
207
208 void
209 gst_mpd_period_node_free (GstMPDPeriodNode * self)
210 {
211 if (self)
212 gst_object_unref (self);
213 }