[vlc-commits] demux: dash: Update MPD
Francois Cartegnie
git at videolan.org
Mon Jan 12 20:22:09 CET 2015
vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Sun Jan 11 23:22:39 2015 +0100| [882b9a82f14051ef70317839997b6ceb2ce3a557] | committer: Francois Cartegnie
demux: dash: Update MPD
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=882b9a82f14051ef70317839997b6ceb2ce3a557
---
modules/demux/dash/DASHManager.cpp | 65 +++++++++++++++++++++++++++++++++++-
modules/demux/dash/DASHManager.h | 2 ++
modules/demux/dash/dash.cpp | 4 +++
3 files changed, 70 insertions(+), 1 deletion(-)
diff --git a/modules/demux/dash/DASHManager.cpp b/modules/demux/dash/DASHManager.cpp
index 5b891f9..5652c8a 100644
--- a/modules/demux/dash/DASHManager.cpp
+++ b/modules/demux/dash/DASHManager.cpp
@@ -28,8 +28,12 @@
#endif
#include "DASHManager.h"
+#include "mpd/MPDFactory.h"
+#include "mpd/SegmentTimeline.h"
+#include "xml/DOMParser.h"
#include "adaptationlogic/AdaptationLogicFactory.h"
#include "SegmentTracker.hpp"
+#include <vlc_stream.h>
using namespace dash;
using namespace dash::http;
@@ -41,7 +45,8 @@ DASHManager::DASHManager ( MPD *mpd,
conManager ( NULL ),
logicType ( type ),
mpd ( mpd ),
- stream ( stream )
+ stream ( stream ),
+ nextMPDupdate ( 0 )
{
for(int i=0; i<Streams::count; i++)
streams[i] = NULL;
@@ -97,6 +102,7 @@ bool DASHManager::start(demux_t *demux)
return false;
mpd->playbackStart.Set(time(NULL));
+ nextMPDupdate = mpd->playbackStart.Get();
return true;
}
@@ -189,3 +195,60 @@ bool DASHManager::seekAble() const
}
return true;
}
+
+bool DASHManager::updateMPD()
+{
+ if(!mpd->isLive() || !mpd->minUpdatePeriod.Get())
+ return true;
+
+ mtime_t now = time(NULL);
+ if(nextMPDupdate && now < nextMPDupdate)
+ return true;
+
+ /* do update */
+ if(nextMPDupdate)
+ {
+ std::string url(stream->psz_access);
+ url.append("://");
+ url.append(stream->psz_path);
+
+ stream_t *mpdstream = stream_UrlNew(stream, url.c_str());
+ if(!mpdstream)
+ return false;
+
+ xml::DOMParser parser(mpdstream);
+ if(!parser.parse())
+ {
+ stream_Delete(mpdstream);
+ return false;
+ }
+
+ MPD *newmpd = MPDFactory::create(parser.getRootNode(), mpdstream, parser.getProfile());
+ if(newmpd)
+ {
+ mpd->mergeWith(newmpd);
+ delete newmpd;
+ }
+ stream_Delete(mpdstream);
+ }
+
+ /* Compute new MPD update time */
+ mtime_t mininterval = 0;
+ mtime_t maxinterval = 0;
+ mpd->getTimeLinesBoundaries(&mininterval, &maxinterval);
+ if(maxinterval > mininterval)
+ maxinterval = (maxinterval - mininterval) / CLOCK_FREQ;
+ else
+ maxinterval = 60;
+ maxinterval = std::max(maxinterval, (mtime_t)60);
+
+ mininterval = std::max(mpd->minUpdatePeriod.Get(),
+ mpd->maxSegmentDuration.Get());
+
+ nextMPDupdate = now + (maxinterval - mininterval) / 2;
+
+ msg_Dbg(stream, "Updated MPD, next update in %"PRId64"s (%"PRId64"..%"PRId64")",
+ nextMPDupdate - now, mininterval, maxinterval );
+
+ return true;
+}
diff --git a/modules/demux/dash/DASHManager.h b/modules/demux/dash/DASHManager.h
index b2fc7e3..11398c4 100644
--- a/modules/demux/dash/DASHManager.h
+++ b/modules/demux/dash/DASHManager.h
@@ -46,6 +46,7 @@ namespace dash
int esCount() const;
bool setPosition(mtime_t);
bool seekAble() const;
+ bool updateMPD();
private:
http::HTTPConnectionManager *conManager;
@@ -53,6 +54,7 @@ namespace dash
mpd::MPD *mpd;
stream_t *stream;
Streams::Stream *streams[Streams::count];
+ mtime_t nextMPDupdate;
};
}
diff --git a/modules/demux/dash/dash.cpp b/modules/demux/dash/dash.cpp
index e81d945..ee9bada 100644
--- a/modules/demux/dash/dash.cpp
+++ b/modules/demux/dash/dash.cpp
@@ -182,6 +182,10 @@ static int Demux(demux_t *p_demux)
else
es_out_Control(p_demux->out, ES_OUT_SET_PCR, pcr);
}
+
+ if( !p_sys->p_dashManager->updateMPD() )
+ return VLC_DEMUXER_EOF;
+
return VLC_DEMUXER_SUCCESS;
}
else
More information about the vlc-commits
mailing list