aboutsummaryrefslogtreecommitdiffstats
path: root/MPD
diff options
context:
space:
mode:
Diffstat (limited to 'MPD')
-rw-r--r--MPD/AbstractRepresentationStream.h2
-rw-r--r--MPD/IRepresentationStream.h2
-rw-r--r--MPD/MPDWrapper.cpp9
-rw-r--r--MPD/SegmentListStream.cpp13
-rw-r--r--MPD/SegmentListStream.h3
-rw-r--r--MPD/SegmentTemplateStream.cpp22
-rw-r--r--MPD/SegmentTemplateStream.h3
-rw-r--r--MPD/SingleMediaSegmentStream.cpp2
-rw-r--r--MPD/SingleMediaSegmentStream.h2
9 files changed, 41 insertions, 17 deletions
diff --git a/MPD/AbstractRepresentationStream.h b/MPD/AbstractRepresentationStream.h
index 113720ed..da847c3c 100644
--- a/MPD/AbstractRepresentationStream.h
+++ b/MPD/AbstractRepresentationStream.h
@@ -43,7 +43,7 @@ public:
virtual dash::mpd::ISegment* getInitializationSegment() = 0;
virtual dash::mpd::ISegment* getIndexSegment(size_t segmentNumber) = 0;
- virtual dash::mpd::ISegment* getMediaSegment(size_t segmentNumber) = 0;
+ virtual dash::mpd::ISegment* getMediaSegment(size_t segmentNumber, uint64_t& segmentDuration) = 0;
virtual dash::mpd::ISegment* getBitstreamSwitchingSegment() = 0;
virtual RepresentationStreamType getStreamType() = 0;
diff --git a/MPD/IRepresentationStream.h b/MPD/IRepresentationStream.h
index bf8b08c4..124216ba 100644
--- a/MPD/IRepresentationStream.h
+++ b/MPD/IRepresentationStream.h
@@ -35,7 +35,7 @@ public:
virtual dash::mpd::ISegment* getInitializationSegment() = 0;
virtual dash::mpd::ISegment* getIndexSegment(size_t segmentNumber) = 0;
- virtual dash::mpd::ISegment* getMediaSegment(size_t segmentNumber) = 0;
+ virtual dash::mpd::ISegment* getMediaSegment(size_t segmentNumber, uint64_t& segmentDuration) = 0;
virtual dash::mpd::ISegment* getBitstreamSwitchingSegment() = 0;
virtual RepresentationStreamType getStreamType() = 0;
virtual uint32_t getSize() = 0;
diff --git a/MPD/MPDWrapper.cpp b/MPD/MPDWrapper.cpp
index 20d4aa5e..c7bdee9f 100644
--- a/MPD/MPDWrapper.cpp
+++ b/MPD/MPDWrapper.cpp
@@ -645,10 +645,13 @@ MediaObject* MPDWrapper::getNextSegment (viper::managers::StreamType type, bool
representationStream = representations->find(representation)->second;
}
}
- seg = representationStream->getMediaSegment(segmentNumber);
+ uint64_t segDuration = 0;
+ //Returns the segmentDuration in milliseconds
+ seg = representationStream->getMediaSegment(segmentNumber, segDuration);
if(seg != NULL)
{
MediaObject *media = new MediaObject(seg, representation, withFeedBack);
+ media->SetSegmentDuration(segDuration);
segmentNumber++;
switch(type)
{
@@ -696,10 +699,12 @@ MediaObject* MPDWrapper::getSegment (viper::managers::StreamType type, uint32_t
LeaveCriticalSection(&this->monitorMutex);
return NULL;
}
- seg = representationStream->getMediaSegment(segNum);
+ uint64_t segDuration =0;
+ seg = representationStream->getMediaSegment(segNum, segDuration);
if(seg != NULL)
{
MediaObject *media = new MediaObject(seg, representation);
+ media->SetSegmentDuration(segDuration);
LeaveCriticalSection(&this->monitorMutex);
return media;
}
diff --git a/MPD/SegmentListStream.cpp b/MPD/SegmentListStream.cpp
index c3530086..86d36e68 100644
--- a/MPD/SegmentListStream.cpp
+++ b/MPD/SegmentListStream.cpp
@@ -53,11 +53,15 @@ ISegment* SegmentListStream::getIndexSegment(size_t segmentNumber)
return NULL;
}
-ISegment* SegmentListStream::getMediaSegment(size_t segmentNumber)
+ISegment* SegmentListStream::getMediaSegment(size_t segmentNumber, uint64_t& segmentDuration)
{
if (this->segmentList->GetSegmentURLs().size() > segmentNumber)
+ {
+ uint32_t duration = representation->GetSegmentList()->GetDuration();
+ uint32_t timescale = representation->GetSegmentList()->GetTimescale();
+ segmentDuration = (uint64_t)(((float)duration/(float)timescale) * 1000);
return this->segmentList->GetSegmentURLs().at(segmentNumber)->ToMediaSegment(this->baseUrls);
-
+ }
return NULL;
}
@@ -93,6 +97,11 @@ ISegmentList* SegmentListStream::findSegmentList()
return NULL;
}
+uint32_t SegmentListStream::getTimescale ()
+{
+ return this->segmentList->GetTimescale();
+}
+
uint32_t SegmentListStream::getAverageSegmentDuration()
{
/* TODO calculate average segment durations for SegmentTimeline */
diff --git a/MPD/SegmentListStream.h b/MPD/SegmentListStream.h
index 264ac9cc..589896ff 100644
--- a/MPD/SegmentListStream.h
+++ b/MPD/SegmentListStream.h
@@ -33,11 +33,12 @@ public:
virtual dash::mpd::ISegment* getInitializationSegment();
virtual dash::mpd::ISegment* getIndexSegment(size_t segmentNumber);
- virtual dash::mpd::ISegment* getMediaSegment(size_t segmentNumber);
+ virtual dash::mpd::ISegment* getMediaSegment(size_t segmentNumber, uint64_t& segmentDuration);
virtual dash::mpd::ISegment* getBitstreamSwitchingSegment();
virtual RepresentationStreamType getStreamType();
virtual uint32_t getSize();
virtual uint32_t getAverageSegmentDuration();
+ virtual uint32_t getTimescale();
private:
dash::mpd::ISegmentList *findSegmentList();
diff --git a/MPD/SegmentTemplateStream.cpp b/MPD/SegmentTemplateStream.cpp
index ee51cf07..50801896 100644
--- a/MPD/SegmentTemplateStream.cpp
+++ b/MPD/SegmentTemplateStream.cpp
@@ -64,16 +64,19 @@ ISegment* SegmentTemplateStream::getIndexSegment(size_t segmentNumber)
this->segmentTemplate->GetStartNumber() + segmentNumber);
}
-ISegment* SegmentTemplateStream::getMediaSegment(size_t segmentNumber)
+ISegment* SegmentTemplateStream::getMediaSegment(size_t segmentNumber, uint64_t& segmentDuration)
{
/* time-based template */
if (this->segmentTemplate->GetSegmentTimeline())
{//Get the one at segmentNumber
- if(this->segmentStartTimes.size() > segmentNumber)
- return this->segmentTemplate->GetMediaSegmentFromTime(baseUrls, representation->GetId(), representation->GetBandwidth(), this->segmentStartTimes.at(segmentNumber));
- else
- return NULL;
-
+ if(this->segmentStartTimes.size() > segmentNumber)
+ {
+ segmentDuration = (uint64_t)(((float)this->segmentDurationTimes.at(segmentNumber)/(float)this->getTimescale()) * 1000);
+ return this->segmentTemplate->GetMediaSegmentFromTime(baseUrls, representation->GetId(), representation->GetBandwidth(), this->segmentStartTimes.at(segmentNumber));
+ }
+ else
+ return NULL;
+
//The following is to be used if you wish to start directly from the right time
/* {
if(this->inSync)
@@ -110,6 +113,9 @@ ISegment* SegmentTemplateStream::getMediaSegment(size_t segmentNumber)
}
/* number-based template */
+ uint32_t duration = representation->GetSegmentTemplate()->GetDuration();
+ uint32_t timescale = representation->GetSegmentTemplate()->GetTimescale();
+ segmentDuration = (uint64_t)(((float)duration/(float)timescale) * 1000);
return this->segmentTemplate->GetMediaSegmentFromNumber(baseUrls, representation->GetId(), representation->GetBandwidth(),
this->segmentTemplate->GetStartNumber() + segmentNumber);
@@ -199,6 +205,7 @@ void SegmentTemplateStream::calculateSegmentStartTimes()
if (segStartTime > 0)
{
this->segmentStartTimes.push_back(segStartTime + segDuration * j);
+ this->segmentDurationTimes.push_back(segDuration);
}
else
{
@@ -209,6 +216,7 @@ void SegmentTemplateStream::calculateSegmentStartTimes()
else
{
this->segmentStartTimes.push_back(segStartTime);
+ this->segmentDurationTimes.push_back(segDuration);
}
}
this->averageDuration = totalDuration / numOfTimelines;
@@ -227,7 +235,7 @@ size_t SegmentTemplateStream::getSegmentNumber(uint64_t time)
size_t i;
for(i = 0; i < this->segmentStartTimes.size(); i ++)
{
- if(time <= this->segmentStartTimes.at(i))
+ if(time < this->segmentStartTimes.at(i))
{
break;
}
diff --git a/MPD/SegmentTemplateStream.h b/MPD/SegmentTemplateStream.h
index 0bd0ad13..8485b56b 100644
--- a/MPD/SegmentTemplateStream.h
+++ b/MPD/SegmentTemplateStream.h
@@ -34,7 +34,7 @@ public:
virtual dash::mpd::ISegment* getInitializationSegment();
virtual dash::mpd::ISegment* getIndexSegment(size_t segmentNumber);
- virtual dash::mpd::ISegment* getMediaSegment(size_t segmentNumber);
+ virtual dash::mpd::ISegment* getMediaSegment(size_t segmentNumber, uint64_t& segmentDuration);
virtual dash::mpd::ISegment* getBitstreamSwitchingSegment();
virtual RepresentationStreamType getStreamType();
virtual uint32_t getSize();
@@ -49,6 +49,7 @@ private:
dash::mpd::ISegmentTemplate *segmentTemplate;
std::vector<uint64_t> segmentStartTimes;
+ std::vector<uint64_t> segmentDurationTimes;
uint32_t averageDuration;
bool inSync;
uint32_t currentSegment;
diff --git a/MPD/SingleMediaSegmentStream.cpp b/MPD/SingleMediaSegmentStream.cpp
index 39301928..3eccbefe 100644
--- a/MPD/SingleMediaSegmentStream.cpp
+++ b/MPD/SingleMediaSegmentStream.cpp
@@ -51,7 +51,7 @@ ISegment* SingleMediaSegmentStream::getIndexSegment(size_t segmentNumber)
return NULL;
}
-ISegment* SingleMediaSegmentStream::getMediaSegment(size_t segmentNumber)
+ISegment* SingleMediaSegmentStream::getMediaSegment(size_t segmentNumber, uint64_t& segmentDuration)
{
/* segmentNumber equals the desired BaseUrl */
if (this->representation->GetBaseURLs().size() > segmentNumber)
diff --git a/MPD/SingleMediaSegmentStream.h b/MPD/SingleMediaSegmentStream.h
index e619a7f8..44fead38 100644
--- a/MPD/SingleMediaSegmentStream.h
+++ b/MPD/SingleMediaSegmentStream.h
@@ -31,7 +31,7 @@ public:
virtual dash::mpd::ISegment* getInitializationSegment();
virtual dash::mpd::ISegment* getIndexSegment(size_t segmentNumber);
- virtual dash::mpd::ISegment* getMediaSegment(size_t segmentNumber);
+ virtual dash::mpd::ISegment* getMediaSegment(size_t segmentNumber, uint64_t& segmentDuration);
virtual dash::mpd::ISegment* getBitstreamSwitchingSegment();
virtual RepresentationStreamType getStreamType();