2 * Copyright (C) 2012 Smart TV Alliance
3 * Author: Thiago Sousa Santos <thiago.sousa.santos@collabora.com>, Collabora Ltd.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
25 #include <libxml/parser.h>
26 #include <libxml/tree.h>
28 #include "gstmssmanifest.h"
30 struct _GstMssManifestStream
34 gint selectedQualityIndex;
37 struct _GstMssManifest
40 xmlNodePtr xmlrootnode;
46 gst_mss_manifest_new (const GstBuffer * data)
48 GstMssManifest *manifest;
52 manifest = g_malloc0 (sizeof (GstMssManifest));
54 manifest->xml = xmlReadMemory ((const gchar *) GST_BUFFER_DATA (data),
55 GST_BUFFER_SIZE (data), "manifest", NULL, 0);
56 root = manifest->xmlrootnode = xmlDocGetRootElement (manifest->xml);
58 for (nodeiter = root->children; nodeiter; nodeiter = nodeiter->next) {
59 if (nodeiter->type == XML_ELEMENT_NODE
60 && (strcmp ((const char *) nodeiter->name, "StreamIndex") == 0)) {
61 GstMssManifestStream *stream = g_new0 (GstMssManifestStream, 1);
63 manifest->streams = g_slist_append (manifest->streams, stream);
64 stream->xmlnode = nodeiter;
72 gst_mss_manifest_free (GstMssManifest * manifest)
74 g_return_if_fail (manifest != NULL);
76 g_slist_free_full (manifest->streams, g_free);
78 xmlFreeDoc (manifest->xml);
83 gst_mss_manifest_get_streams (GstMssManifest * manifest)
85 return manifest->streams;
88 GstMssManifestStreamType
89 gst_mss_manifest_stream_get_type (GstMssManifestStream * stream)
91 gchar *prop = (gchar *) xmlGetProp (stream->xmlnode, (xmlChar *) "Type");
92 GstMssManifestStreamType ret = MSS_STREAM_TYPE_UNKNOWN;
94 if (strcmp (prop, "video") == 0) {
95 ret = MSS_STREAM_TYPE_VIDEO;
96 } else if (strcmp (prop, "audio") == 0) {
97 ret = MSS_STREAM_TYPE_AUDIO;
104 _gst_mss_manifest_stream_video_caps_from_fourcc (gchar * fourcc)
109 if (strcmp (fourcc, "H264") == 0) {
110 return gst_caps_new_simple ("video/x-h264", NULL);
116 _gst_mss_manifest_stream_audio_caps_from_fourcc (gchar * fourcc)
121 if (strcmp (fourcc, "AACL") == 0) {
122 return gst_caps_new_simple ("audio/mpeg", "mpegversion", G_TYPE_INT, 4,
129 _gst_mss_manifest_stream_video_caps_from_qualitylevel_xml (xmlNodePtr node)
132 GstStructure *structure;
133 gchar *fourcc = (gchar *) xmlGetProp (node, (xmlChar *) "FourCC");
134 gchar *max_width = (gchar *) xmlGetProp (node, (xmlChar *) "MaxWidth");
135 gchar *max_height = (gchar *) xmlGetProp (node, (xmlChar *) "MaxHeight");
137 (gchar *) xmlGetProp (node, (xmlChar *) "CodecPrivateData");
139 caps = _gst_mss_manifest_stream_video_caps_from_fourcc (fourcc);
143 structure = gst_caps_get_structure (caps, 0);
146 gst_structure_set (structure, "width", G_TYPE_INT, atoi (max_width), NULL);
148 gst_structure_set (structure, "height", G_TYPE_INT, atoi (max_height),
152 GValue *value = g_new0 (GValue, 1);
153 g_value_init (value, GST_TYPE_BUFFER);
154 gst_value_deserialize (value, (gchar *) codec_data);
155 gst_structure_take_value (structure, "codec_data", value);
168 _gst_mss_manifest_stream_audio_caps_from_qualitylevel_xml (xmlNodePtr node)
171 GstStructure *structure;
172 gchar *fourcc = (gchar *) xmlGetProp (node, (xmlChar *) "FourCC");
173 gchar *channels = (gchar *) xmlGetProp (node, (xmlChar *) "Channels");
174 gchar *rate = (gchar *) xmlGetProp (node, (xmlChar *) "SamplingRate");
176 (gchar *) xmlGetProp (node, (xmlChar *) "CodecPrivateData");
178 caps = _gst_mss_manifest_stream_audio_caps_from_fourcc (fourcc);
182 structure = gst_caps_get_structure (caps, 0);
185 gst_structure_set (structure, "channels", G_TYPE_INT, atoi (channels),
188 gst_structure_set (structure, "rate", G_TYPE_INT, atoi (rate), NULL);
191 GValue *value = g_new0 (GValue, 1);
192 g_value_init (value, GST_TYPE_BUFFER);
193 gst_value_deserialize (value, (gchar *) codec_data);
194 gst_structure_take_value (structure, "codec_data", value);
207 gst_mss_manifest_stream_get_caps (GstMssManifestStream * stream)
209 GstMssManifestStreamType streamtype =
210 gst_mss_manifest_stream_get_type (stream);
212 /* TODO properly get the stream */
213 xmlNodePtr qualitylevel = stream->xmlnode->children;
214 while (strcmp ((gchar *) qualitylevel->name, "QualityLevel")) {
215 qualitylevel = qualitylevel->next;
218 if (streamtype == MSS_STREAM_TYPE_VIDEO)
220 _gst_mss_manifest_stream_video_caps_from_qualitylevel_xml
222 else if (streamtype == MSS_STREAM_TYPE_AUDIO)
224 _gst_mss_manifest_stream_audio_caps_from_qualitylevel_xml
231 gst_mss_manifest_stream_type_name (GstMssManifestStreamType streamtype)
233 switch (streamtype) {
234 case MSS_STREAM_TYPE_VIDEO:
236 case MSS_STREAM_TYPE_AUDIO:
238 case MSS_STREAM_TYPE_UNKNOWN: