| 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 "gstmpdrepresentationnode.h" |
| 22 |
#include "gstmpdparser.h" |
| 23 |
|
| 24 |
G_DEFINE_TYPE (GstMPDRepresentationNode2, gst_mpd_representation_node, |
| 25 |
GST_TYPE_MPD_REPRESENTATION_BASE_NODE); |
| 26 |
|
| 27 |
enum |
| 28 |
{ |
| 29 |
PROP_MPD_REPRESENTATION_0, |
| 30 |
PROP_MPD_REPRESENTATION_ID, |
| 31 |
PROP_MPD_REPRESENTATION_BANDWIDTH, |
| 32 |
PROP_MPD_REPRESENTATION_QUALITY_RANKING, |
| 33 |
}; |
| 34 |
|
| 35 |
/* GObject VMethods */ |
| 36 |
|
| 37 |
static void |
| 38 |
gst_mpd_representation_node_set_property (GObject * object, guint prop_id, |
| 39 |
const GValue * value, GParamSpec * pspec) |
| 40 |
{ |
| 41 |
GstMPDRepresentationNode *self = GST_MPD_REPRESENTATION_NODE (object); |
| 42 |
switch (prop_id) { |
| 43 |
case PROP_MPD_REPRESENTATION_ID: |
| 44 |
g_free (self->id); |
| 45 |
self->id = g_value_dup_string (value); |
| 46 |
break; |
| 47 |
case PROP_MPD_REPRESENTATION_BANDWIDTH: |
| 48 |
self->bandwidth = g_value_get_uint (value); |
| 49 |
break; |
| 50 |
case PROP_MPD_REPRESENTATION_QUALITY_RANKING: |
| 51 |
self->qualityRanking = g_value_get_uint (value); |
| 52 |
break; |
| 53 |
default: |
| 54 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
| 55 |
break; |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
static void |
| 60 |
gst_mpd_representation_node_get_property (GObject * object, guint prop_id, |
| 61 |
GValue * value, GParamSpec * pspec) |
| 62 |
{ |
| 63 |
GstMPDRepresentationNode *self = GST_MPD_REPRESENTATION_NODE (object); |
| 64 |
switch (prop_id) { |
| 65 |
case PROP_MPD_REPRESENTATION_ID: |
| 66 |
g_value_set_string (value, self->id); |
| 67 |
break; |
| 68 |
case PROP_MPD_REPRESENTATION_BANDWIDTH: |
| 69 |
g_value_set_uint (value, self->bandwidth); |
| 70 |
break; |
| 71 |
case PROP_MPD_REPRESENTATION_QUALITY_RANKING: |
| 72 |
g_value_set_uint (value, self->qualityRanking); |
| 73 |
break; |
| 74 |
default: |
| 75 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
| 76 |
break; |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
static void |
| 81 |
gst_mpd_representation_node_finalize (GObject * object) |
| 82 |
{ |
| 83 |
GstMPDRepresentationNode *self = GST_MPD_REPRESENTATION_NODE (object); |
| 84 |
|
| 85 |
g_free (self->id); |
| 86 |
g_strfreev (self->dependencyId); |
| 87 |
g_strfreev (self->mediaStreamStructureId); |
| 88 |
g_list_free_full (self->SubRepresentations, |
| 89 |
(GDestroyNotify) gst_mpd_sub_representation_node_free); |
| 90 |
gst_mpd_segment_base_node_free (self->SegmentBase); |
| 91 |
gst_mpd_segment_template_node_free (self->SegmentTemplate); |
| 92 |
gst_mpd_segment_list_node_free (self->SegmentList); |
| 93 |
g_list_free_full (self->BaseURLs, (GDestroyNotify) gst_mpd_baseurl_node_free); |
| 94 |
|
| 95 |
G_OBJECT_CLASS (gst_mpd_representation_node_parent_class)->finalize (object); |
| 96 |
} |
| 97 |
|
| 98 |
/* Base class */ |
| 99 |
|
| 100 |
static xmlNodePtr |
| 101 |
gst_mpd_representation_get_xml_node (GstMPDNode * node) |
| 102 |
{ |
| 103 |
gchar *value; |
| 104 |
xmlNodePtr representation_xml_node = NULL; |
| 105 |
GstMPDRepresentationNode *self = GST_MPD_REPRESENTATION_NODE (node); |
| 106 |
|
| 107 |
representation_xml_node = xmlNewNode (NULL, (xmlChar *) "Representation"); |
| 108 |
|
| 109 |
gst_xml_helper_set_prop_string (representation_xml_node, "id", self->id); |
| 110 |
gst_xml_helper_set_prop_uint (representation_xml_node, "bandwidth", |
| 111 |
self->bandwidth); |
| 112 |
if (self->qualityRanking) |
| 113 |
gst_xml_helper_set_prop_uint (representation_xml_node, "qualityRanking", |
| 114 |
self->qualityRanking); |
| 115 |
|
| 116 |
|
| 117 |
if (self->dependencyId) { |
| 118 |
value = g_strjoinv (" ", self->dependencyId); |
| 119 |
gst_xml_helper_set_prop_string (representation_xml_node, "dependencyId", |
| 120 |
value); |
| 121 |
g_free (value); |
| 122 |
} |
| 123 |
if (self->mediaStreamStructureId) { |
| 124 |
value = g_strjoinv (" ", self->mediaStreamStructureId); |
| 125 |
gst_xml_helper_set_prop_string (representation_xml_node, |
| 126 |
"mediaStreamStructureId", value); |
| 127 |
g_free (value); |
| 128 |
} |
| 129 |
|
| 130 |
g_list_foreach (self->BaseURLs, gst_mpd_node_get_list_item, |
| 131 |
representation_xml_node); |
| 132 |
g_list_foreach (self->SubRepresentations, |
| 133 |
gst_mpd_representation_base_node_get_list_item, representation_xml_node); |
| 134 |
|
| 135 |
gst_mpd_node_add_child_node (GST_MPD_NODE (self->SegmentBase), |
| 136 |
representation_xml_node); |
| 137 |
gst_mpd_mult_segment_base_node_add_child_node (GST_MPD_NODE |
| 138 |
(self->SegmentTemplate), representation_xml_node); |
| 139 |
gst_mpd_mult_segment_base_node_add_child_node (GST_MPD_NODE |
| 140 |
(self->SegmentList), representation_xml_node); |
| 141 |
|
| 142 |
return representation_xml_node; |
| 143 |
} |
| 144 |
|
| 145 |
static void |
| 146 |
gst_mpd_representation_node_class_init (GstMPDRepresentationNodeClass * klass) |
| 147 |
{ |
| 148 |
GObjectClass *object_class; |
| 149 |
GstMPDNodeClass *m_klass; |
| 150 |
|
| 151 |
object_class = G_OBJECT_CLASS (klass); |
| 152 |
m_klass = GST_MPD_NODE_CLASS (klass); |
| 153 |
|
| 154 |
object_class->finalize = gst_mpd_representation_node_finalize; |
| 155 |
object_class->set_property = gst_mpd_representation_node_set_property; |
| 156 |
object_class->get_property = gst_mpd_representation_node_get_property; |
| 157 |
|
| 158 |
m_klass->get_xml_node = gst_mpd_representation_get_xml_node; |
| 159 |
|
| 160 |
g_object_class_install_property (object_class, |
| 161 |
PROP_MPD_REPRESENTATION_BANDWIDTH, g_param_spec_uint ("bandwidth", |
| 162 |
"bandwidth", "representation bandwidth", 0, G_MAXUINT, 0, |
| 163 |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); |
| 164 |
g_object_class_install_property (object_class, |
| 165 |
PROP_MPD_REPRESENTATION_QUALITY_RANKING, |
| 166 |
g_param_spec_uint ("quality-ranking", "quality ranking", |
| 167 |
"representation quality ranking", 0, G_MAXUINT, 0, |
| 168 |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); |
| 169 |
} |
| 170 |
|
| 171 |
static void |
| 172 |
gst_mpd_representation_node_init (GstMPDRepresentationNode * self) |
| 173 |
{ |
| 174 |
self->id = NULL; |
| 175 |
self->bandwidth = 0; |
| 176 |
self->qualityRanking = 0; |
| 177 |
self->dependencyId = NULL; |
| 178 |
self->mediaStreamStructureId = NULL; |
| 179 |
self->BaseURLs = NULL; |
| 180 |
self->SubRepresentations = NULL; |
| 181 |
self->SegmentBase = NULL; |
| 182 |
self->SegmentTemplate = NULL; |
| 183 |
self->SegmentList = NULL; |
| 184 |
} |
| 185 |
|
| 186 |
GstMPDRepresentationNode * |
| 187 |
gst_mpd_representation_node_new (void) |
| 188 |
{ |
| 189 |
return g_object_new (GST_TYPE_MPD_REPRESENTATION_NODE, NULL); |
| 190 |
} |
| 191 |
|
| 192 |
void |
| 193 |
gst_mpd_representation_node_free (GstMPDRepresentationNode * self) |
| 194 |
{ |
| 195 |
if (self) |
| 196 |
gst_object_unref (self); |
| 197 |
} |