]> git.sesse.net Git - vlc/blobdiff - modules/stream_filter/dash/mpd/BasicCMParser.cpp
dash: Group element contains the "common" attributes/elements
[vlc] / modules / stream_filter / dash / mpd / BasicCMParser.cpp
index b4543b9f861d16f4b6a8db138370cd3cb3a30074..071dc49c4c6e8961929cf068da780763394177a1 100644 (file)
@@ -27,6 +27,9 @@
 
 #include "BasicCMParser.h"
 
+#include <cstdlib>
+#include <sstream>
+
 using namespace dash::mpd;
 using namespace dash::xml;
 
@@ -77,6 +80,11 @@ void    BasicCMParser::setGroups            (Node *root, Period *period)
     for(size_t i = 0; i < groups.size(); i++)
     {
         Group *group = new Group(groups.at(i)->getAttributes());
+        if ( this->parseCommonAttributesElements( groups.at( i ), group ) == false )
+        {
+            delete group;
+            continue ;
+        }
         this->setRepresentations(groups.at(i), group);
         period->addGroup(group);
     }
@@ -87,24 +95,32 @@ void    BasicCMParser::setRepresentations   (Node *root, Group *group)
 
     for(size_t i = 0; i < representations.size(); i++)
     {
-        Representation *rep = new Representation(representations.at(i)->getAttributes());
+        const std::map<std::string, std::string>    attributes = representations.at(i)->getAttributes();
+
+        Representation *rep = new Representation( attributes );
+        if ( this->parseCommonAttributesElements( representations.at( i ), rep ) == false )
+        {
+            delete rep;
+            continue ;
+        }
         this->setSegmentInfo(representations.at(i), rep);
-        group->addRepresentation(rep);
+        if ( rep->getSegmentInfo() && rep->getSegmentInfo()->getSegments().size() > 0 )
+            group->addRepresentation(rep);
     }
 }
 void    BasicCMParser::setSegmentInfo       (Node *root, Representation *rep)
 {
-    std::vector<Node *> segmentInfo = DOMHelper::getChildElementByTagName(root, "SegmentInfo");
+    Node    *segmentInfo = DOMHelper::getFirstChildElementByName( root, "SegmentInfo");
 
-    for(size_t i = 0; i < segmentInfo.size(); i++)
+    if ( segmentInfo )
     {
-        SegmentInfo *info = new SegmentInfo(segmentInfo.at(i)->getAttributes());
-        this->setInitSegment(segmentInfo.at(i), info);
-        this->setSegments(segmentInfo.at(i), info);
+        SegmentInfo *info = new SegmentInfo( segmentInfo->getAttributes() );
+        this->setInitSegment( segmentInfo, info );
+        this->setSegments(segmentInfo, info );
         rep->setSegmentInfo(info);
-        return;
     }
 }
+
 void    BasicCMParser::setInitSegment       (Node *root, SegmentInfo *info)
 {
     std::vector<Node *> initSeg = DOMHelper::getChildElementByTagName(root, "InitialisationSegmentURL");
@@ -130,3 +146,70 @@ MPD*    BasicCMParser::getMPD               ()
 {
     return this->mpd;
 }
+
+bool    BasicCMParser::parseCommonAttributesElements( Node *node, CommonAttributesElements *common) const
+{
+    const std::map<std::string, std::string>                &attr = node->getAttributes();
+    std::map<std::string, std::string>::const_iterator      it;
+    //Parse mandatory elements first.
+    it = attr.find( "mimeType" );
+    if ( it == attr.end() )
+    {
+        std::cerr << "Missing mandatory attribute: @mimeType" << std::endl;
+        return false;
+    }
+    common->setMimeType( it->second );
+    //Everything else is optionnal.
+    it = attr.find( "width" );
+    if ( it != attr.end() )
+        common->setWidth( atoi( it->second.c_str() ) );
+    it = attr.find( "height" );
+    if ( it != attr.end() )
+        common->setHeight( atoi( it->second.c_str() ) );
+    it = attr.find( "parx" );
+    if ( it != attr.end() )
+        common->setParX( atoi( it->second.c_str() ) );
+    it = attr.find( "pary" );
+    if ( it != attr.end() )
+        common->setParY( atoi( it->second.c_str() ) );
+    it = attr.find( "frameRate" );
+    if ( it != attr.end() )
+        common->setFrameRate( atoi( it->second.c_str() ) );
+    it = attr.find( "lang" );
+
+    if ( it != attr.end() && it->second.empty() == false )
+    {
+        std::istringstream  s( it->second );
+        while ( s )
+        {
+            std::string     lang;
+            s >> lang;
+            common->addLang( lang );
+        }
+    }
+    it = attr.find( "numberOfChannels" );
+    if ( it != attr.end() )
+    {
+        std::istringstream  s( it->second );
+        while ( s )
+        {
+            std::string     channel;
+            s >> channel;
+            common->addChannel( channel );
+        }
+    }
+    it = attr.find( "samplingRate" );
+    if ( it != attr.end() )
+    {
+        std::istringstream  s( it->second );
+        while ( s )
+        {
+            int         rate;
+            s >> rate;
+            common->addSampleRate( rate );
+        }
+    }
+    //FIXME: Handle : group, maximumRAPPeriod startWithRAP attributes
+    //FIXME: Handle : ContentProtection Accessibility Rating Viewpoing MultipleViews elements
+    return true;
+}