• 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 "gstmpdmultsegmentbasenode.h"
22 #include "gstmpdparser.h"
23 
24 G_DEFINE_TYPE (GstMPDMultSegmentBaseNode, gst_mpd_mult_segment_base_node,
25     GST_TYPE_MPD_NODE);
26 
27 enum
28 {
29   PROP_MPD_MULT_SEGMENT_BASE_0 = 100,
30   PROP_MPD_MULT_SEGMENT_BASE_DURATION,
31   PROP_MPD_MULT_SEGMENT_BASE_START_NUMBER,
32 };
33 
34 /* GObject VMethods */
35 
36 static void
gst_mpd_mult_segment_base_node_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)37 gst_mpd_mult_segment_base_node_set_property (GObject * object, guint prop_id,
38     const GValue * value, GParamSpec * pspec)
39 {
40   GstMPDMultSegmentBaseNode *self = GST_MPD_MULT_SEGMENT_BASE_NODE (object);
41   switch (prop_id) {
42     case PROP_MPD_MULT_SEGMENT_BASE_DURATION:
43       self->duration = g_value_get_uint (value);
44       break;
45     case PROP_MPD_MULT_SEGMENT_BASE_START_NUMBER:
46       self->startNumber = g_value_get_uint (value);
47       break;
48     default:
49       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
50       break;
51   }
52 }
53 
54 static void
gst_mpd_mult_segment_base_node_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)55 gst_mpd_mult_segment_base_node_get_property (GObject * object, guint prop_id,
56     GValue * value, GParamSpec * pspec)
57 {
58   GstMPDMultSegmentBaseNode *self = GST_MPD_MULT_SEGMENT_BASE_NODE (object);
59   switch (prop_id) {
60     case PROP_MPD_MULT_SEGMENT_BASE_DURATION:
61       g_value_set_uint (value, self->duration);
62       break;
63     case PROP_MPD_MULT_SEGMENT_BASE_START_NUMBER:
64       g_value_set_uint (value, self->startNumber);
65       break;
66     default:
67       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
68       break;
69   }
70 }
71 
72 static void
gst_mpd_mult_segment_base_node_finalize(GObject * object)73 gst_mpd_mult_segment_base_node_finalize (GObject * object)
74 {
75   GstMPDMultSegmentBaseNode *self = GST_MPD_MULT_SEGMENT_BASE_NODE (object);
76 
77   gst_mpd_segment_base_node_free (self->SegmentBase);
78   gst_mpd_segment_timeline_node_free (self->SegmentTimeline);
79   gst_mpd_url_type_node_free (self->BitstreamSwitching);
80 
81   G_OBJECT_CLASS (gst_mpd_mult_segment_base_node_parent_class)->finalize
82       (object);
83 }
84 
85 /* Base class */
86 
87 static void
gst_mpd_mult_segment_base_get_xml_node(GstMPDNode * node,xmlNodePtr mult_segment_base_node)88 gst_mpd_mult_segment_base_get_xml_node (GstMPDNode * node,
89     xmlNodePtr mult_segment_base_node)
90 {
91   GstMPDMultSegmentBaseNode *self = GST_MPD_MULT_SEGMENT_BASE_NODE (node);
92 
93   if (self->duration)
94     gst_xml_helper_set_prop_uint (mult_segment_base_node, "duration",
95         self->duration);
96   if (self->startNumber)
97     gst_xml_helper_set_prop_uint (mult_segment_base_node, "startNumber",
98         self->startNumber);
99   if (self->SegmentBase)
100     gst_mpd_node_add_child_node (GST_MPD_NODE (self->SegmentBase),
101         mult_segment_base_node);
102   if (self->SegmentTimeline)
103     gst_mpd_node_add_child_node (GST_MPD_NODE (self->SegmentTimeline),
104         mult_segment_base_node);
105   if (self->BitstreamSwitching)
106     gst_mpd_node_add_child_node (GST_MPD_NODE (self->BitstreamSwitching),
107         mult_segment_base_node);
108 }
109 
110 static void
gst_mpd_mult_segment_base_node_class_init(GstMPDMultSegmentBaseNodeClass * klass)111 gst_mpd_mult_segment_base_node_class_init (GstMPDMultSegmentBaseNodeClass *
112     klass)
113 {
114   GObjectClass *object_class;
115 
116   object_class = G_OBJECT_CLASS (klass);
117 
118   object_class->finalize = gst_mpd_mult_segment_base_node_finalize;
119   object_class->set_property = gst_mpd_mult_segment_base_node_set_property;
120   object_class->get_property = gst_mpd_mult_segment_base_node_get_property;
121 
122   g_object_class_install_property (object_class,
123       PROP_MPD_MULT_SEGMENT_BASE_DURATION, g_param_spec_uint ("duration",
124           "duration", "duration of segment", 0, G_MAXINT, 0,
125           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
126 
127   g_object_class_install_property (object_class,
128       PROP_MPD_MULT_SEGMENT_BASE_START_NUMBER,
129       g_param_spec_uint ("start-number", "start number",
130           "start number in the segment list", 0, G_MAXINT, 0,
131           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
132 }
133 
134 static void
gst_mpd_mult_segment_base_node_init(GstMPDMultSegmentBaseNode * self)135 gst_mpd_mult_segment_base_node_init (GstMPDMultSegmentBaseNode * self)
136 {
137   self->duration = 0;
138   self->startNumber = 0;
139   self->SegmentBase = NULL;
140   self->SegmentTimeline = NULL;
141   self->BitstreamSwitching = NULL;
142 }
143 
144 void
gst_mpd_mult_segment_base_node_add_child_node(GstMPDNode * node,xmlNodePtr parent_xml_node)145 gst_mpd_mult_segment_base_node_add_child_node (GstMPDNode * node,
146     xmlNodePtr parent_xml_node)
147 {
148   if (node) {
149     xmlNodePtr new_xml_node = gst_mpd_node_get_xml_pointer (node);
150     gst_mpd_mult_segment_base_get_xml_node (node, new_xml_node);
151     xmlAddChild (parent_xml_node, new_xml_node);
152   }
153 }
154