[vlc-devel] [PATCH 2/2] demux: hls: support pause of PLAYLIST-TYPE event
Zhao Zhili
quinkblack at foxmail.com
Fri Apr 13 05:30:38 CEST 2018
---
modules/demux/hls/playlist/M3U8.cpp | 29 +++++++++++++++++++++++++++
modules/demux/hls/playlist/M3U8.hpp | 1 +
modules/demux/hls/playlist/Parser.cpp | 14 +++++++++++--
modules/demux/hls/playlist/Representation.cpp | 6 ++++++
modules/demux/hls/playlist/Representation.hpp | 2 ++
5 files changed, 50 insertions(+), 2 deletions(-)
diff --git a/modules/demux/hls/playlist/M3U8.cpp b/modules/demux/hls/playlist/M3U8.cpp
index 830fefa..67944c7 100644
--- a/modules/demux/hls/playlist/M3U8.cpp
+++ b/modules/demux/hls/playlist/M3U8.cpp
@@ -105,6 +105,35 @@ bool M3U8::isLive() const
return b_live;
}
+bool M3U8::canPause() const
+{
+ bool b_canPause = true;
+ std::vector<BasePeriod *>::const_iterator itp;
+ for(itp = periods.begin(); itp != periods.end(); ++itp)
+ {
+ const BasePeriod *period = *itp;
+ std::vector<BaseAdaptationSet *>::const_iterator ita;
+ for(ita = period->getAdaptationSets().begin(); ita != period->getAdaptationSets().end(); ++ita)
+ {
+ BaseAdaptationSet *adaptSet = *ita;
+ std::vector<BaseRepresentation *>::iterator itr;
+ for(itr = adaptSet->getRepresentations().begin(); itr != adaptSet->getRepresentations().end(); ++itr)
+ {
+ const Representation *rep = dynamic_cast<const Representation *>(*itr);
+ if(rep->initialized())
+ {
+ if(rep->canPause())
+ return true;
+ else
+ b_canPause = false;
+ }
+ }
+ }
+ }
+
+ return b_canPause;
+}
+
AuthStorage * M3U8::getAuth()
{
return auth;
diff --git a/modules/demux/hls/playlist/M3U8.hpp b/modules/demux/hls/playlist/M3U8.hpp
index 5fdcc4a..4f36034 100644
--- a/modules/demux/hls/playlist/M3U8.hpp
+++ b/modules/demux/hls/playlist/M3U8.hpp
@@ -47,6 +47,7 @@ namespace hls
std::vector<uint8_t> getEncryptionKey(const std::string &);
virtual bool isLive() const;
+ virtual bool canPause() const;
virtual void debug();
adaptive::http::AuthStorage * getAuth(); /* ugly data ref, tobefixed */
diff --git a/modules/demux/hls/playlist/Parser.cpp b/modules/demux/hls/playlist/Parser.cpp
index 10c1855..5a659b9 100644
--- a/modules/demux/hls/playlist/Parser.cpp
+++ b/modules/demux/hls/playlist/Parser.cpp
@@ -292,8 +292,18 @@ void M3U8Parser::parseSegments(vlc_object_t *, Representation *rep, const std::l
break;
case SingleValueTag::EXTXPLAYLISTTYPE:
- rep->b_live = (static_cast<const SingleValueTag *>(tag)->getValue().value != "VOD");
- break;
+ {
+ std::string value = static_cast<const SingleValueTag *>(tag)->getValue().value;
+ if(value == "EVENT")
+ {
+ rep->b_live = rep->b_eventPlaylist = true;
+ }
+ else if(value == "VOD")
+ {
+ rep->b_live = rep->b_eventPlaylist = false;
+ }
+ }
+ break;
case SingleValueTag::EXTXBYTERANGE:
ctx_byterange = static_cast<const SingleValueTag *>(tag);
diff --git a/modules/demux/hls/playlist/Representation.cpp b/modules/demux/hls/playlist/Representation.cpp
index 94b4c59..75d7e3f 100644
--- a/modules/demux/hls/playlist/Representation.cpp
+++ b/modules/demux/hls/playlist/Representation.cpp
@@ -41,6 +41,7 @@ Representation::Representation ( BaseAdaptationSet *set ) :
BaseRepresentation( set )
{
b_live = true;
+ b_eventPlaylist = false;
b_loaded = false;
switchpolicy = SegmentInformation::SWITCH_SEGMENT_ALIGNED; /* FIXME: based on streamformat */
nextUpdateTime = 0;
@@ -62,6 +63,11 @@ bool Representation::isLive() const
return b_live;
}
+bool Representation::canPause() const
+{
+ return (b_live == false || b_eventPlaylist == true);
+}
+
bool Representation::initialized() const
{
return b_loaded;
diff --git a/modules/demux/hls/playlist/Representation.hpp b/modules/demux/hls/playlist/Representation.hpp
index 6bdc5f5..d1a7d63 100644
--- a/modules/demux/hls/playlist/Representation.hpp
+++ b/modules/demux/hls/playlist/Representation.hpp
@@ -46,6 +46,7 @@ namespace hls
void setPlaylistUrl(const std::string &);
Url getPlaylistUrl() const;
bool isLive() const;
+ bool canPause() const;
bool initialized() const;
virtual void scheduleNextUpdate(uint64_t); /* reimpl */
virtual bool needsUpdate() const; /* reimpl */
@@ -56,6 +57,7 @@ namespace hls
private:
StreamFormat streamFormat;
bool b_live;
+ bool b_eventPlaylist;
bool b_loaded;
time_t nextUpdateTime;
time_t targetDuration;
--
2.9.5
More information about the vlc-devel
mailing list