3 *****************************************************************************
4 * Copyright (C) 2014 - VideoLAN authors
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published
8 * by the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
20 #include "SegmentTracker.hpp"
24 using namespace dash::logic;
25 using namespace dash::http;
26 using namespace dash::mpd;
28 SegmentTracker::SegmentTracker(AbstractAdaptationLogic *logic_, mpd::MPD *mpd_)
32 prevRepresentation = NULL;
33 currentPeriod = mpd_->getFirstPeriod();
34 setAdaptationLogic(logic_);
38 SegmentTracker::~SegmentTracker()
43 void SegmentTracker::setAdaptationLogic(AbstractAdaptationLogic *logic_)
48 void SegmentTracker::resetCounter()
51 prevRepresentation = NULL;
54 Chunk * SegmentTracker::getNextChunk(Streams::Type type)
62 if(prevRepresentation && !prevRepresentation->canBitswitch())
63 rep = prevRepresentation;
65 rep = logic->getCurrentRepresentation(type, currentPeriod);
70 if(rep != prevRepresentation)
72 prevRepresentation = rep;
79 segment = rep->getSegment(Representation::INFOTYPE_INIT);
81 return segment->toChunk(count, rep);
84 segment = rep->getSegment(Representation::INFOTYPE_MEDIA, count);
87 currentPeriod = mpd->getNextPeriod(currentPeriod);
89 return getNextChunk(type);
92 Chunk *chunk = segment->toChunk(count, rep);
99 bool SegmentTracker::setPosition(mtime_t time, bool tryonly)
102 if(prevRepresentation &&
103 prevRepresentation->getSegmentNumberByTime(time, &segcount))
112 mtime_t SegmentTracker::getSegmentStart() const
114 if(prevRepresentation)
115 return prevRepresentation->getPlaybackTimeBySegmentNumber(count);