| 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 "gstmpdadaptationsetnode.h" |
| 22 |
#include "gstmpdparser.h" |
| 23 |
|
| 24 |
G_DEFINE_TYPE (GstMPDAdaptationSetNode2, gst_mpd_adaptation_set_node, |
| 25 |
GST_TYPE_MPD_REPRESENTATION_BASE_NODE); |
| 26 |
|
| 27 |
enum |
| 28 |
{ |
| 29 |
PROP_MPD_ADAPTATION_SET_0, |
| 30 |
PROP_MPD_ADAPTATION_SET_ID, |
| 31 |
PROP_MPD_ADAPTATION_SET_CONTENT_TYPE, |
| 32 |
}; |
| 33 |
|
| 34 |
/* GObject VMethods */ |
| 35 |
|
| 36 |
static void |
| 37 |
gst_mpd_adaptation_set_node_set_property (GObject * object, guint prop_id, |
| 38 |
const GValue * value, GParamSpec * pspec) |
| 39 |
{ |
| 40 |
GstMPDAdaptationSetNode *self = GST_MPD_ADAPTATION_SET_NODE (object); |
| 41 |
switch (prop_id) { |
| 42 |
case PROP_MPD_ADAPTATION_SET_ID: |
| 43 |
self->id = g_value_get_int (value); |
| 44 |
break; |
| 45 |
case PROP_MPD_ADAPTATION_SET_CONTENT_TYPE: |
| 46 |
g_free (self->contentType); |
| 47 |
self->contentType = g_value_dup_string (value); |
| 48 |
break; |
| 49 |
default: |
| 50 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
| 51 |
break; |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
static void |
| 56 |
gst_mpd_adaptation_set_node_get_property (GObject * object, guint prop_id, |
| 57 |
GValue * value, GParamSpec * pspec) |
| 58 |
{ |
| 59 |
GstMPDAdaptationSetNode *self = GST_MPD_ADAPTATION_SET_NODE (object); |
| 60 |
switch (prop_id) { |
| 61 |
case PROP_MPD_ADAPTATION_SET_ID: |
| 62 |
g_value_set_int (value, self->id); |
| 63 |
break; |
| 64 |
case PROP_MPD_ADAPTATION_SET_CONTENT_TYPE: |
| 65 |
g_value_set_string (value, self->contentType); |
| 66 |
break; |
| 67 |
default: |
| 68 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
| 69 |
break; |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
static void |
| 74 |
gst_mpd_adaptation_set_node_finalize (GObject * object) |
| 75 |
{ |
| 76 |
GstMPDAdaptationSetNode *self = GST_MPD_ADAPTATION_SET_NODE (object); |
| 77 |
|
| 78 |
if (self->lang) |
| 79 |
xmlFree (self->lang); |
| 80 |
g_free (self->contentType); |
| 81 |
g_free (self->par); |
| 82 |
g_free (self->segmentAlignment); |
| 83 |
g_free (self->subsegmentAlignment); |
| 84 |
g_list_free_full (self->Accessibility, |
| 85 |
(GDestroyNotify) gst_mpd_descriptor_type_node_free); |
| 86 |
g_list_free_full (self->Role, |
| 87 |
(GDestroyNotify) gst_mpd_descriptor_type_node_free); |
| 88 |
g_list_free_full (self->Rating, |
| 89 |
(GDestroyNotify) gst_mpd_descriptor_type_node_free); |
| 90 |
g_list_free_full (self->Viewpoint, |
| 91 |
(GDestroyNotify) gst_mpd_descriptor_type_node_free); |
| 92 |
gst_mpd_segment_base_node_free (self->SegmentBase); |
| 93 |
gst_mpd_segment_list_node_free (self->SegmentList); |
| 94 |
gst_mpd_segment_template_node_free (self->SegmentTemplate); |
| 95 |
g_list_free_full (self->BaseURLs, (GDestroyNotify) gst_mpd_baseurl_node_free); |
| 96 |
g_list_free_full (self->Representations, |
| 97 |
(GDestroyNotify) gst_mpd_representation_node_free); |
| 98 |
g_list_free_full (self->ContentComponents, |
| 99 |
(GDestroyNotify) gst_mpd_content_component_node_free); |
| 100 |
if (self->xlink_href) |
| 101 |
xmlFree (self->xlink_href); |
| 102 |
|
| 103 |
G_OBJECT_CLASS (gst_mpd_adaptation_set_node_parent_class)->finalize (object); |
| 104 |
} |
| 105 |
|
| 106 |
/* Base class */ |
| 107 |
|
| 108 |
static xmlNodePtr |
| 109 |
gst_mpd_adaptation_set_get_xml_node (GstMPDNode * node) |
| 110 |
{ |
| 111 |
xmlNodePtr adaptation_set_xml_node = NULL; |
| 112 |
GstMPDAdaptationSetNode *self = GST_MPD_ADAPTATION_SET_NODE (node); |
| 113 |
|
| 114 |
adaptation_set_xml_node = xmlNewNode (NULL, (xmlChar *) "AdaptationSet"); |
| 115 |
|
| 116 |
if (self->id) |
| 117 |
gst_xml_helper_set_prop_uint (adaptation_set_xml_node, "id", self->id); |
| 118 |
if (self->group) |
| 119 |
gst_xml_helper_set_prop_uint (adaptation_set_xml_node, "group", |
| 120 |
self->group); |
| 121 |
|
| 122 |
if (self->lang) |
| 123 |
gst_xml_helper_set_prop_string (adaptation_set_xml_node, "lang", |
| 124 |
self->lang); |
| 125 |
|
| 126 |
if (self->contentType) |
| 127 |
gst_xml_helper_set_prop_string (adaptation_set_xml_node, "contentType", |
| 128 |
self->contentType); |
| 129 |
|
| 130 |
if (self->minBandwidth) |
| 131 |
gst_xml_helper_set_prop_uint (adaptation_set_xml_node, "minBandwidth", |
| 132 |
self->minBandwidth); |
| 133 |
if (self->maxBandwidth) |
| 134 |
gst_xml_helper_set_prop_uint (adaptation_set_xml_node, "maxBandwidth", |
| 135 |
self->maxBandwidth); |
| 136 |
if (self->minWidth) |
| 137 |
gst_xml_helper_set_prop_uint (adaptation_set_xml_node, "minWidth", |
| 138 |
self->minWidth); |
| 139 |
if (self->maxWidth) |
| 140 |
gst_xml_helper_set_prop_uint (adaptation_set_xml_node, "maxWidth", |
| 141 |
self->maxWidth); |
| 142 |
if (self->minHeight) |
| 143 |
gst_xml_helper_set_prop_uint (adaptation_set_xml_node, "minHeight", |
| 144 |
self->minHeight); |
| 145 |
if (self->maxHeight) |
| 146 |
gst_xml_helper_set_prop_uint (adaptation_set_xml_node, "maxHeight", |
| 147 |
self->maxHeight); |
| 148 |
|
| 149 |
if (self->par) |
| 150 |
gst_xml_helper_set_prop_ratio (adaptation_set_xml_node, "par", self->par); |
| 151 |
|
| 152 |
gst_xml_helper_set_prop_cond_uint (adaptation_set_xml_node, |
| 153 |
"segmentAlignment", self->segmentAlignment); |
| 154 |
gst_xml_helper_set_prop_cond_uint (adaptation_set_xml_node, |
| 155 |
"subsegmentAlignment", self->subsegmentAlignment); |
| 156 |
gst_xml_helper_set_prop_uint (adaptation_set_xml_node, |
| 157 |
"subsegmentStartsWithSAP", self->subsegmentStartsWithSAP); |
| 158 |
gst_xml_helper_set_prop_boolean (adaptation_set_xml_node, |
| 159 |
"bitstreamSwitching", self->bitstreamSwitching); |
| 160 |
|
| 161 |
g_list_foreach (self->Accessibility, gst_mpd_node_get_list_item, |
| 162 |
adaptation_set_xml_node); |
| 163 |
g_list_foreach (self->Role, gst_mpd_node_get_list_item, |
| 164 |
adaptation_set_xml_node); |
| 165 |
g_list_foreach (self->Rating, gst_mpd_node_get_list_item, |
| 166 |
adaptation_set_xml_node); |
| 167 |
g_list_foreach (self->Viewpoint, gst_mpd_node_get_list_item, |
| 168 |
adaptation_set_xml_node); |
| 169 |
|
| 170 |
gst_mpd_node_add_child_node (GST_MPD_NODE (self->SegmentBase), |
| 171 |
adaptation_set_xml_node); |
| 172 |
gst_mpd_mult_segment_base_node_add_child_node (GST_MPD_NODE |
| 173 |
(self->SegmentList), adaptation_set_xml_node); |
| 174 |
gst_mpd_mult_segment_base_node_add_child_node (GST_MPD_NODE |
| 175 |
(self->SegmentTemplate), adaptation_set_xml_node); |
| 176 |
|
| 177 |
g_list_foreach (self->BaseURLs, gst_mpd_node_get_list_item, |
| 178 |
adaptation_set_xml_node); |
| 179 |
g_list_foreach (self->Representations, |
| 180 |
gst_mpd_representation_base_node_get_list_item, adaptation_set_xml_node); |
| 181 |
g_list_foreach (self->ContentComponents, gst_mpd_node_get_list_item, |
| 182 |
adaptation_set_xml_node); |
| 183 |
|
| 184 |
if (self->xlink_href) |
| 185 |
gst_xml_helper_set_prop_string (adaptation_set_xml_node, "xlink_href", |
| 186 |
self->xlink_href); |
| 187 |
if (self->actuate == GST_MPD_XLINK_ACTUATE_ON_LOAD) |
| 188 |
gst_xml_helper_set_prop_string (adaptation_set_xml_node, "actuate", |
| 189 |
(gchar *) GST_MPD_XLINK_ACTUATE_ON_LOAD_STR); |
| 190 |
return adaptation_set_xml_node; |
| 191 |
} |
| 192 |
|
| 193 |
static void |
| 194 |
gst_mpd_adaptation_set_node_class_init (GstMPDAdaptationSetNodeClass * klass) |
| 195 |
{ |
| 196 |
GObjectClass *object_class; |
| 197 |
GstMPDNodeClass *m_klass; |
| 198 |
|
| 199 |
object_class = G_OBJECT_CLASS (klass); |
| 200 |
m_klass = GST_MPD_NODE_CLASS (klass); |
| 201 |
|
| 202 |
object_class->finalize = gst_mpd_adaptation_set_node_finalize; |
| 203 |
object_class->set_property = gst_mpd_adaptation_set_node_set_property; |
| 204 |
object_class->get_property = gst_mpd_adaptation_set_node_get_property; |
| 205 |
|
| 206 |
m_klass->get_xml_node = gst_mpd_adaptation_set_get_xml_node; |
| 207 |
|
| 208 |
g_object_class_install_property (object_class, PROP_MPD_ADAPTATION_SET_ID, |
| 209 |
g_param_spec_int ("id", "id", |
| 210 |
"adaptation set id", 0, G_MAXINT, 0, |
| 211 |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); |
| 212 |
g_object_class_install_property (object_class, |
| 213 |
PROP_MPD_ADAPTATION_SET_CONTENT_TYPE, g_param_spec_string ("content-type", |
| 214 |
"content type", "content type of the adaptation set", NULL, |
| 215 |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); |
| 216 |
} |
| 217 |
|
| 218 |
static void |
| 219 |
gst_mpd_adaptation_set_node_init (GstMPDAdaptationSetNode * self) |
| 220 |
{ |
| 221 |
self->id = 0; |
| 222 |
self->group = 0; |
| 223 |
self->lang = NULL; /* LangVectorType RFC 5646 */ |
| 224 |
self->contentType = NULL; |
| 225 |
self->par = 0; |
| 226 |
self->minBandwidth = 0; |
| 227 |
self->maxBandwidth = 0; |
| 228 |
self->minWidth = 0; |
| 229 |
self->maxWidth = 0; |
| 230 |
self->minHeight = 0; |
| 231 |
self->maxHeight = 0; |
| 232 |
self->segmentAlignment = NULL; |
| 233 |
self->subsegmentAlignment = NULL; |
| 234 |
self->subsegmentStartsWithSAP = GST_SAP_TYPE_0; |
| 235 |
self->bitstreamSwitching = FALSE; |
| 236 |
/* list of Accessibility DescriptorType nodes */ |
| 237 |
self->Accessibility = NULL; |
| 238 |
/* list of Role DescriptorType nodes */ |
| 239 |
self->Role = NULL; |
| 240 |
/* list of Rating DescriptorType nodes */ |
| 241 |
self->Rating = NULL; |
| 242 |
/* list of Viewpoint DescriptorType nodes */ |
| 243 |
self->Viewpoint = NULL; |
| 244 |
/* SegmentBase node */ |
| 245 |
self->SegmentBase = NULL; |
| 246 |
/* SegmentList node */ |
| 247 |
self->SegmentList = NULL; |
| 248 |
/* SegmentTemplate node */ |
| 249 |
self->SegmentTemplate = NULL; |
| 250 |
/* list of BaseURL nodes */ |
| 251 |
self->BaseURLs = NULL; |
| 252 |
/* list of Representation nodes */ |
| 253 |
self->Representations = NULL; |
| 254 |
/* list of ContentComponent nodes */ |
| 255 |
self->ContentComponents = NULL; |
| 256 |
|
| 257 |
self->xlink_href = NULL; |
| 258 |
self->actuate = GST_MPD_XLINK_ACTUATE_ON_REQUEST; |
| 259 |
} |
| 260 |
|
| 261 |
GstMPDAdaptationSetNode * |
| 262 |
gst_mpd_adaptation_set_node_new (void) |
| 263 |
{ |
| 264 |
return g_object_new (GST_TYPE_MPD_ADAPTATION_SET_NODE, NULL); |
| 265 |
} |
| 266 |
|
| 267 |
void |
| 268 |
gst_mpd_adaptation_set_node_free (GstMPDAdaptationSetNode * self) |
| 269 |
{ |
| 270 |
if (self) |
| 271 |
gst_object_unref (self); |
| 272 |
} |