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 "gstmpdsegmenttemplatenode.h"
22 #include "gstmpdparser.h"
23
24 G_DEFINE_TYPE (GstMPDSegmentTemplateNode, gst_mpd_segment_template_node,
25 GST_TYPE_MPD_MULT_SEGMENT_BASE_NODE);
26
27 enum
28 {
29 PROP_MPD_SEGMENT_TEMPLATE_0,
30 PROP_MPD_SEGMENT_TEMPLATE_MEDIA,
31 PROP_MPD_SEGMENT_TEMPLATE_INDEX,
32 PROP_MPD_SEGMENT_TEMPLATE_INITIALIZATION,
33 PROP_MPD_SEGMENT_TEMPLATE_BITSTREAM_SWITCHING,
34 };
35
36 /* GObject VMethods */
37
38 static void
gst_mpd_segment_template_node_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)39 gst_mpd_segment_template_node_set_property (GObject * object, guint prop_id,
40 const GValue * value, GParamSpec * pspec)
41 {
42 GstMPDSegmentTemplateNode *self = GST_MPD_SEGMENT_TEMPLATE_NODE (object);
43 switch (prop_id) {
44 case PROP_MPD_SEGMENT_TEMPLATE_MEDIA:
45 self->media = g_value_dup_string (value);
46 break;
47 case PROP_MPD_SEGMENT_TEMPLATE_INDEX:
48 self->index = g_value_dup_string (value);
49 break;
50 case PROP_MPD_SEGMENT_TEMPLATE_INITIALIZATION:
51 self->initialization = g_value_dup_string (value);
52 break;
53 case PROP_MPD_SEGMENT_TEMPLATE_BITSTREAM_SWITCHING:
54 self->bitstreamSwitching = g_value_dup_string (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_segment_template_node_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)63 gst_mpd_segment_template_node_get_property (GObject * object, guint prop_id,
64 GValue * value, GParamSpec * pspec)
65 {
66 GstMPDSegmentTemplateNode *self = GST_MPD_SEGMENT_TEMPLATE_NODE (object);
67 switch (prop_id) {
68 case PROP_MPD_SEGMENT_TEMPLATE_MEDIA:
69 g_value_set_string (value, self->media);
70 break;
71 case PROP_MPD_SEGMENT_TEMPLATE_INDEX:
72 g_value_set_string (value, self->index);
73 break;
74 case PROP_MPD_SEGMENT_TEMPLATE_INITIALIZATION:
75 g_value_set_string (value, self->initialization);
76 break;
77 case PROP_MPD_SEGMENT_TEMPLATE_BITSTREAM_SWITCHING:
78 g_value_set_string (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_segment_template_node_finalize(GObject * object)87 gst_mpd_segment_template_node_finalize (GObject * object)
88 {
89 GstMPDSegmentTemplateNode *self = GST_MPD_SEGMENT_TEMPLATE_NODE (object);
90
91 if (self->media)
92 xmlFree (self->media);
93 if (self->index)
94 xmlFree (self->index);
95 if (self->initialization)
96 xmlFree (self->initialization);
97 if (self->bitstreamSwitching)
98 xmlFree (self->bitstreamSwitching);
99
100 G_OBJECT_CLASS (gst_mpd_segment_template_node_parent_class)->finalize
101 (object);
102 }
103
104 /* Base class */
105
106 static xmlNodePtr
gst_mpd_segment_template_get_xml_node(GstMPDNode * node)107 gst_mpd_segment_template_get_xml_node (GstMPDNode * node)
108 {
109 xmlNodePtr segment_template_xml_node = NULL;
110 GstMPDSegmentTemplateNode *self = GST_MPD_SEGMENT_TEMPLATE_NODE (node);
111
112 segment_template_xml_node = xmlNewNode (NULL, (xmlChar *) "SegmentTemplate");
113
114 if (self->media)
115 gst_xml_helper_set_prop_string (segment_template_xml_node, "media",
116 self->media);
117
118 if (self->index)
119 gst_xml_helper_set_prop_string (segment_template_xml_node, "index",
120 self->index);
121
122 if (self->initialization)
123 gst_xml_helper_set_prop_string (segment_template_xml_node, "initialization",
124 self->initialization);
125
126 if (self->bitstreamSwitching)
127 gst_xml_helper_set_prop_string (segment_template_xml_node,
128 "bitstreamSwitching", self->bitstreamSwitching);
129
130 return segment_template_xml_node;
131 }
132
133 static void
gst_mpd_segment_template_node_class_init(GstMPDSegmentTemplateNodeClass * klass)134 gst_mpd_segment_template_node_class_init (GstMPDSegmentTemplateNodeClass *
135 klass)
136 {
137 GObjectClass *object_class;
138 GstMPDNodeClass *m_klass;
139
140 object_class = G_OBJECT_CLASS (klass);
141 m_klass = GST_MPD_NODE_CLASS (klass);
142
143 object_class->finalize = gst_mpd_segment_template_node_finalize;
144 object_class->set_property = gst_mpd_segment_template_node_set_property;
145 object_class->get_property = gst_mpd_segment_template_node_get_property;
146
147 m_klass->get_xml_node = gst_mpd_segment_template_get_xml_node;
148
149 g_object_class_install_property (object_class,
150 PROP_MPD_SEGMENT_TEMPLATE_MEDIA, g_param_spec_string ("media",
151 "media", "media", NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
152 g_object_class_install_property (object_class,
153 PROP_MPD_SEGMENT_TEMPLATE_INDEX, g_param_spec_string ("index",
154 "index", "index", NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
155 g_object_class_install_property (object_class,
156 PROP_MPD_SEGMENT_TEMPLATE_INITIALIZATION,
157 g_param_spec_string ("initialization", "initialization", "initialization",
158 NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
159 g_object_class_install_property (object_class,
160 PROP_MPD_SEGMENT_TEMPLATE_BITSTREAM_SWITCHING,
161 g_param_spec_string ("bitstream-switching", "bitstream switching",
162 "bitstream switching", NULL,
163 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
164 }
165
166 static void
gst_mpd_segment_template_node_init(GstMPDSegmentTemplateNode * self)167 gst_mpd_segment_template_node_init (GstMPDSegmentTemplateNode * self)
168 {
169 self->media = NULL;
170 self->index = NULL;
171 self->initialization = NULL;
172 self->bitstreamSwitching = NULL;
173 }
174
175 GstMPDSegmentTemplateNode *
gst_mpd_segment_template_node_new(void)176 gst_mpd_segment_template_node_new (void)
177 {
178 return g_object_new (GST_TYPE_MPD_SEGMENT_TEMPLATE_NODE, NULL);
179 }
180
181 void
gst_mpd_segment_template_node_free(GstMPDSegmentTemplateNode * self)182 gst_mpd_segment_template_node_free (GstMPDSegmentTemplateNode * self)
183 {
184 if (self)
185 gst_object_unref (self);
186 }
187