[vlc-commits] demux: adaptative: add switch event
Francois Cartegnie
git at videolan.org
Mon Nov 9 11:04:51 CET 2015
vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Sat Nov 7 20:52:42 2015 +0100| [62cbf970154ff421010b6dc4345161c084219c74] | committer: Francois Cartegnie
demux: adaptative: add switch event
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=62cbf970154ff421010b6dc4345161c084219c74
---
modules/demux/adaptative/SegmentTracker.cpp | 35 ++++++++++++++++++++-------
modules/demux/adaptative/SegmentTracker.hpp | 34 ++++++++++++++++++++------
modules/demux/adaptative/Streams.cpp | 1 +
3 files changed, 54 insertions(+), 16 deletions(-)
diff --git a/modules/demux/adaptative/SegmentTracker.cpp b/modules/demux/adaptative/SegmentTracker.cpp
index b8f030e..9ef9968 100644
--- a/modules/demux/adaptative/SegmentTracker.cpp
+++ b/modules/demux/adaptative/SegmentTracker.cpp
@@ -28,6 +28,19 @@ using namespace adaptative;
using namespace adaptative::logic;
using namespace adaptative::playlist;
+SegmentTrackerEvent::SegmentTrackerEvent(ISegment *s)
+{
+ type = DISCONTINUITY;
+ u.discontinuity.s = s;
+}
+
+SegmentTrackerEvent::SegmentTrackerEvent(BaseRepresentation *prev, BaseRepresentation *next)
+{
+ type = SWITCHING;
+ u.switching.prev = prev;
+ u.switching.next = next;
+}
+
SegmentTracker::SegmentTracker(AbstractAdaptationLogic *logic_, BaseAdaptationSet *adaptSet)
{
count = 0;
@@ -41,7 +54,7 @@ SegmentTracker::SegmentTracker(AbstractAdaptationLogic *logic_, BaseAdaptationSe
SegmentTracker::~SegmentTracker()
{
-
+ reset();
}
void SegmentTracker::setAdaptationLogic(AbstractAdaptationLogic *logic_)
@@ -49,14 +62,18 @@ void SegmentTracker::setAdaptationLogic(AbstractAdaptationLogic *logic_)
logic = logic_;
}
-void SegmentTracker::resetCounter()
+void SegmentTracker::reset()
{
+ notify(SegmentTrackerEvent(prevRepresentation, NULL));
prevRepresentation = NULL;
+ init_sent = false;
+ index_sent = false;
+ initializing = true;
}
SegmentChunk * SegmentTracker::getNextChunk(bool switch_allowed, HTTPConnectionManager *connManager)
{
- BaseRepresentation *rep;
+ BaseRepresentation *rep = NULL;
ISegment *segment;
if(!adaptationSet)
@@ -70,13 +87,14 @@ SegmentChunk * SegmentTracker::getNextChunk(bool switch_allowed, HTTPConnectionM
(prevRepresentation && prevRepresentation->getSwitchPolicy() == SegmentInformation::SWITCH_UNAVAILABLE) )
rep = prevRepresentation;
else
- rep = logic->getCurrentRepresentation(adaptationSet);
+ rep = logic->getNextRepresentation(adaptationSet, prevRepresentation);
if ( rep == NULL )
return NULL;
if(rep != prevRepresentation)
{
+ notify(SegmentTrackerEvent(prevRepresentation, rep));
prevRepresentation = rep;
init_sent = false;
index_sent = false;
@@ -107,13 +125,12 @@ SegmentChunk * SegmentTracker::getNextChunk(bool switch_allowed, HTTPConnectionM
segment = rep->getNextSegment(BaseRepresentation::INFOTYPE_MEDIA, count, &count, &b_gap);
if(b_gap && count)
{
- notify(SegmentTrackerListenerInterface::notifications::NOTIFICATION_DISCONTINUITY,
- segment);
+ notify(SegmentTrackerEvent(segment));
}
if(!segment)
{
- resetCounter();
+ reset();
return NULL;
}
@@ -177,9 +194,9 @@ void SegmentTracker::updateSelected()
prevRepresentation->runLocalUpdates(getSegmentStart(), count);
}
-void SegmentTracker::notify(SegmentTrackerListenerInterface::notifications type, ISegment *segment)
+void SegmentTracker::notify(const SegmentTrackerEvent &event)
{
std::list<SegmentTrackerListenerInterface *>::const_iterator it;
for(it=listeners.begin();it != listeners.end(); ++it)
- (*it)->trackerNotification(type, segment);
+ (*it)->trackerEvent(event);
}
diff --git a/modules/demux/adaptative/SegmentTracker.hpp b/modules/demux/adaptative/SegmentTracker.hpp
index 7cc5649..d659dfd 100644
--- a/modules/demux/adaptative/SegmentTracker.hpp
+++ b/modules/demux/adaptative/SegmentTracker.hpp
@@ -51,14 +51,34 @@ namespace adaptative
using namespace logic;
using namespace http;
- class SegmentTrackerListenerInterface
+ class SegmentTrackerEvent
{
public:
- enum notifications
+ SegmentTrackerEvent(ISegment *);
+ SegmentTrackerEvent(BaseRepresentation *, BaseRepresentation *);
+ enum
+ {
+ DISCONTINUITY,
+ SWITCHING,
+ } type;
+ union
{
- NOTIFICATION_DISCONTINUITY = 0
- };
- virtual void trackerNotification(notifications, ISegment *) = 0;
+ struct
+ {
+ ISegment *s;
+ } discontinuity;
+ struct
+ {
+ BaseRepresentation *prev;
+ BaseRepresentation *next;
+ } switching;
+ } u;
+ };
+
+ class SegmentTrackerListenerInterface
+ {
+ public:
+ virtual void trackerEvent(const SegmentTrackerEvent &) = 0;
};
class SegmentTracker
@@ -68,7 +88,7 @@ namespace adaptative
~SegmentTracker();
void setAdaptationLogic(AbstractAdaptationLogic *);
- void resetCounter();
+ void reset();
SegmentChunk* getNextChunk(bool, HTTPConnectionManager *);
bool setPositionByTime(mtime_t, bool, bool);
void setPositionByNumber(uint64_t, bool);
@@ -78,7 +98,7 @@ namespace adaptative
void updateSelected();
private:
- void notify(SegmentTrackerListenerInterface::notifications, ISegment *);
+ void notify(const SegmentTrackerEvent &);
bool initializing;
bool index_sent;
bool init_sent;
diff --git a/modules/demux/adaptative/Streams.cpp b/modules/demux/adaptative/Streams.cpp
index 3c2f20d..fd41eb7 100644
--- a/modules/demux/adaptative/Streams.cpp
+++ b/modules/demux/adaptative/Streams.cpp
@@ -142,6 +142,7 @@ SegmentChunk * AbstractStream::getChunk()
if(esCount() && !isSelected())
{
disabled = true;
+ segmentTracker->reset();
return NULL;
}
currentChunk = segmentTracker->getNextChunk(!fakeesout->restarting(), connManager);
More information about the vlc-commits
mailing list