• 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 "gstmpdsegmenturlnode.h"
22 #include "gstmpdparser.h"
23 #include "gstmpdhelper.h"
24 
25 G_DEFINE_TYPE (GstMPDSegmentURLNode, gst_mpd_segment_url_node,
26     GST_TYPE_MPD_NODE);
27 
28 enum
29 {
30   PROP_MPD_SEGMENT_URL_0,
31   PROP_MPD_SEGMENT_URL_MEDIA,
32 };
33 
34 /* GObject VMethods */
35 
36 static void
gst_mpd_segment_url_node_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)37 gst_mpd_segment_url_node_set_property (GObject * object, guint prop_id,
38     const GValue * value, GParamSpec * pspec)
39 {
40   GstMPDSegmentURLNode *self = GST_MPD_SEGMENT_URL_NODE (object);
41   switch (prop_id) {
42     case PROP_MPD_SEGMENT_URL_MEDIA:
43       g_free (self->media);
44       self->media = g_value_dup_string (value);
45       break;
46     default:
47       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
48       break;
49   }
50 }
51 
52 static void
gst_mpd_segment_url_node_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)53 gst_mpd_segment_url_node_get_property (GObject * object, guint prop_id,
54     GValue * value, GParamSpec * pspec)
55 {
56   GstMPDSegmentURLNode *self = GST_MPD_SEGMENT_URL_NODE (object);
57   switch (prop_id) {
58     case PROP_MPD_SEGMENT_URL_MEDIA:
59       g_value_set_string (value, self->media);
60       break;
61     default:
62       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
63       break;
64   }
65 }
66 
67 static void
gst_mpd_segment_url_node_finalize(GObject * object)68 gst_mpd_segment_url_node_finalize (GObject * object)
69 {
70   GstMPDSegmentURLNode *self = GST_MPD_SEGMENT_URL_NODE (object);
71 
72   if (self->media)
73     xmlFree (self->media);
74   g_slice_free (GstXMLRange, self->mediaRange);
75   if (self->index)
76     xmlFree (self->index);
77   g_slice_free (GstXMLRange, self->indexRange);
78 
79   G_OBJECT_CLASS (gst_mpd_segment_url_node_parent_class)->finalize (object);
80 }
81 
82 /* Base class */
83 
84 static xmlNodePtr
gst_mpd_segment_url_get_xml_node(GstMPDNode * node)85 gst_mpd_segment_url_get_xml_node (GstMPDNode * node)
86 {
87   xmlNodePtr segment_url_xml_node = NULL;
88   GstMPDSegmentURLNode *self = GST_MPD_SEGMENT_URL_NODE (node);
89 
90   segment_url_xml_node = xmlNewNode (NULL, (xmlChar *) "SegmentURL");
91 
92   if (self->media)
93     gst_xml_helper_set_prop_string (segment_url_xml_node, "media", self->media);
94 
95   if (self->mediaRange)
96     gst_xml_helper_set_prop_range (segment_url_xml_node, "mediaRange",
97         self->mediaRange);
98 
99   if (self->index)
100     gst_xml_helper_set_prop_string (segment_url_xml_node, "index", self->index);
101 
102   if (self->indexRange)
103     gst_xml_helper_set_prop_range (segment_url_xml_node, "indexRange",
104         self->indexRange);
105 
106   return segment_url_xml_node;
107 }
108 
109 static void
gst_mpd_segment_url_node_class_init(GstMPDSegmentURLNodeClass * klass)110 gst_mpd_segment_url_node_class_init (GstMPDSegmentURLNodeClass * klass)
111 {
112   GObjectClass *object_class;
113   GstMPDNodeClass *m_klass;
114 
115   object_class = G_OBJECT_CLASS (klass);
116   m_klass = GST_MPD_NODE_CLASS (klass);
117 
118   object_class->finalize = gst_mpd_segment_url_node_finalize;
119   object_class->set_property = gst_mpd_segment_url_node_set_property;
120   object_class->get_property = gst_mpd_segment_url_node_get_property;
121 
122   m_klass->get_xml_node = gst_mpd_segment_url_get_xml_node;
123 
124   g_object_class_install_property (object_class,
125       PROP_MPD_SEGMENT_URL_MEDIA, g_param_spec_string ("media",
126           "media", "media description", NULL,
127           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
128 }
129 
130 static void
gst_mpd_segment_url_node_init(GstMPDSegmentURLNode * self)131 gst_mpd_segment_url_node_init (GstMPDSegmentURLNode * self)
132 {
133   self->media = NULL;
134   self->mediaRange = NULL;
135   self->index = NULL;
136   self->indexRange = NULL;
137 }
138 
139 GstMPDSegmentURLNode *
gst_mpd_segment_url_node_new(void)140 gst_mpd_segment_url_node_new (void)
141 {
142   return g_object_new (GST_TYPE_MPD_SEGMENT_URL_NODE, NULL);
143 }
144 
145 void
gst_mpd_segment_url_node_free(GstMPDSegmentURLNode * self)146 gst_mpd_segment_url_node_free (GstMPDSegmentURLNode * self)
147 {
148   if (self)
149     gst_object_unref (self);
150 }
151 
152 GstMPDSegmentURLNode *
gst_mpd_segment_url_node_clone(GstMPDSegmentURLNode * seg_url)153 gst_mpd_segment_url_node_clone (GstMPDSegmentURLNode * seg_url)
154 {
155   GstMPDSegmentURLNode *clone = NULL;
156 
157   if (seg_url) {
158     clone = gst_mpd_segment_url_node_new ();
159     clone->media = xmlMemStrdup (seg_url->media);
160     clone->mediaRange = gst_xml_helper_clone_range (seg_url->mediaRange);
161     clone->index = xmlMemStrdup (seg_url->index);
162     clone->indexRange = gst_xml_helper_clone_range (seg_url->indexRange);
163   }
164 
165   return clone;
166 }
167