Commit 62cbf970 authored by François Cartegnie's avatar François Cartegnie 🤞

demux: adaptative: add switch event

parent 24b586c7
......@@ -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);
}
......@@ -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;
......
......@@ -142,6 +142,7 @@ SegmentChunk * AbstractStream::getChunk()
if(esCount() && !isSelected())
{
disabled = true;
segmentTracker->reset();
return NULL;
}
currentChunk = segmentTracker->getNextChunk(!fakeesout->restarting(), connManager);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment