• 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 "gstmpdperiodnode.h"
22 #include "gstmpdparser.h"
23 
24 G_DEFINE_TYPE (GstMPDPeriodNode, 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
gst_mpd_period_node_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)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
gst_mpd_period_node_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)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
gst_mpd_period_node_finalize(GObject * object)87 gst_mpd_period_node_finalize (GObject * object)
88 {
89   GstMPDPeriodNode *self = GST_MPD_PERIOD_NODE (object);
90 
91   if (self->id)
92     xmlFree (self->id);
93   gst_mpd_segment_base_node_free (self->SegmentBase);
94   gst_mpd_segment_list_node_free (self->SegmentList);
95   gst_mpd_segment_template_node_free (self->SegmentTemplate);
96   g_list_free_full (self->AdaptationSets,
97       (GDestroyNotify) gst_mpd_adaptation_set_node_free);
98   g_list_free_full (self->Subsets, (GDestroyNotify) gst_mpd_subset_node_free);
99   g_list_free_full (self->BaseURLs, (GDestroyNotify) gst_mpd_baseurl_node_free);
100   if (self->xlink_href)
101     xmlFree (self->xlink_href);
102 
103   G_OBJECT_CLASS (gst_mpd_period_node_parent_class)->finalize (object);
104 }
105 
106 /* Base class */
107 
108 static xmlNodePtr
gst_mpd_period_get_xml_node(GstMPDNode * node)109 gst_mpd_period_get_xml_node (GstMPDNode * node)
110 {
111   xmlNodePtr period_xml_node = NULL;
112   GstMPDPeriodNode *self = GST_MPD_PERIOD_NODE (node);
113 
114   period_xml_node = xmlNewNode (NULL, (xmlChar *) "Period");
115 
116   if (self->id)
117     gst_xml_helper_set_prop_string (period_xml_node, "id", self->id);
118 
119   gst_xml_helper_set_prop_duration (period_xml_node, "start", self->start);
120   gst_xml_helper_set_prop_duration (period_xml_node, "duration",
121       self->duration);
122   gst_xml_helper_set_prop_boolean (period_xml_node, "bitstreamSwitching",
123       self->bitstreamSwitching);
124 
125   if (self->SegmentBase)
126     gst_mpd_node_add_child_node (GST_MPD_NODE (self->SegmentBase),
127         period_xml_node);
128 
129   if (self->SegmentList)
130     gst_mpd_mult_segment_base_node_add_child_node (GST_MPD_NODE
131         (self->SegmentList), period_xml_node);
132 
133   if (self->SegmentTemplate)
134     gst_mpd_mult_segment_base_node_add_child_node (GST_MPD_NODE
135         (self->SegmentTemplate), period_xml_node);
136 
137   g_list_foreach (self->AdaptationSets,
138       gst_mpd_representation_base_node_get_list_item, period_xml_node);
139   g_list_foreach (self->Subsets, gst_mpd_node_get_list_item, period_xml_node);
140   g_list_foreach (self->BaseURLs, gst_mpd_node_get_list_item, period_xml_node);
141 
142 
143   return period_xml_node;
144 }
145 
146 static void
gst_mpd_period_node_class_init(GstMPDPeriodNodeClass * klass)147 gst_mpd_period_node_class_init (GstMPDPeriodNodeClass * klass)
148 {
149   GObjectClass *object_class;
150   GstMPDNodeClass *m_klass;
151 
152 
153   object_class = G_OBJECT_CLASS (klass);
154   m_klass = GST_MPD_NODE_CLASS (klass);
155 
156   object_class->finalize = gst_mpd_period_node_finalize;
157   object_class->set_property = gst_mpd_period_node_set_property;
158   object_class->get_property = gst_mpd_period_node_get_property;
159 
160   m_klass->get_xml_node = gst_mpd_period_get_xml_node;
161 
162   g_object_class_install_property (object_class, PROP_MPD_PERIOD_ID,
163       g_param_spec_string ("id", "id",
164           "unique id for period", NULL,
165           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
166 
167   g_object_class_install_property (object_class, PROP_MPD_PERIOD_START,
168       g_param_spec_uint64 ("start", "Period start",
169           "Period start",
170           0, G_MAXUINT64, 0,
171           (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
172 
173   g_object_class_install_property (object_class, PROP_MPD_PERIOD_DURATION,
174       g_param_spec_uint64 ("duration", "period duration",
175           "Period duration",
176           0, G_MAXUINT64, 0,
177           (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
178 
179   g_object_class_install_property (object_class,
180       PROP_MPD_PERIOD_BITSTREAM_SWITCHING,
181       g_param_spec_boolean ("bitstream-switching", "Bitstream switching",
182           "Bitstream switching", FALSE,
183           (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
184 }
185 
186 static void
gst_mpd_period_node_init(GstMPDPeriodNode * self)187 gst_mpd_period_node_init (GstMPDPeriodNode * self)
188 {
189   self->id = NULL;
190   self->start = 0;              /* [ms] */
191   self->duration = 0;           /* [ms] */
192   self->bitstreamSwitching = 0;
193   self->SegmentBase = NULL;
194   self->SegmentList = NULL;
195   self->SegmentTemplate = NULL;
196   self->AdaptationSets = NULL;
197   self->Subsets = NULL;
198   self->BaseURLs = NULL;
199   self->xlink_href = NULL;
200   self->actuate = 0;
201 }
202 
203 GstMPDPeriodNode *
gst_mpd_period_node_new(void)204 gst_mpd_period_node_new (void)
205 {
206   return g_object_new (GST_TYPE_MPD_PERIOD_NODE, NULL);
207 }
208 
209 void
gst_mpd_period_node_free(GstMPDPeriodNode * self)210 gst_mpd_period_node_free (GstMPDPeriodNode * self)
211 {
212   if (self)
213     gst_object_unref (self);
214 }
215