aboutsummaryrefslogtreecommitdiffstats
path: root/Managers/MultimediaManager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Managers/MultimediaManager.cpp')
-rw-r--r--Managers/MultimediaManager.cpp176
1 files changed, 120 insertions, 56 deletions
diff --git a/Managers/MultimediaManager.cpp b/Managers/MultimediaManager.cpp
index faab66cf..23118464 100644
--- a/Managers/MultimediaManager.cpp
+++ b/Managers/MultimediaManager.cpp
@@ -14,6 +14,7 @@
#include <fstream>
using namespace libdash::framework::adaptation;
+using namespace libdash::framework::mpd;
using namespace libdash::framework::buffer;
using namespace viper::managers;
using namespace dash::mpd;
@@ -25,17 +26,11 @@ MultimediaManager::MultimediaManager(ViperGui *viperGui, int segBufSize, std::st
segmentBufferSize (segBufSize),
downloadPath (downloadPath),
offset (offset),
- mpd (NULL),
- period (NULL),
- videoAdaptationSet (NULL),
- videoRepresentation (NULL),
videoLogic (NULL),
videoStream (NULL),
- audioAdaptationSet (NULL),
- audioRepresentation (NULL),
audioLogic (NULL),
- videoRendererHandle (NULL),
- audioRendererHandle (NULL),
+ videoRendererHandle (NULL),
+ audioRendererHandle (NULL),
audioStream (NULL),
started (false),
stopping (false),
@@ -45,7 +40,8 @@ MultimediaManager::MultimediaManager(ViperGui *viperGui, int segBufSize, std::st
isAudioRendering (false),
eos (false),
playing (false),
- noDecoding (nodecoding)
+ noDecoding (nodecoding),
+ mpdWrapper (NULL)
{
InitializeCriticalSection (&this->monitorMutex);
InitializeCriticalSection (&this->monitorBufferMutex);
@@ -71,28 +67,39 @@ MultimediaManager::~MultimediaManager ()
IMPD* MultimediaManager::getMPD()
{
- return this->mpd;
+ return this->mpdWrapper->getMPD();
+}
+
+MPDWrapper* MultimediaManager::getMPDWrapper()
+{
+ return this->mpdWrapper;
}
bool MultimediaManager::init(const std::string& url)
{
+ this->url = url;
EnterCriticalSection(&this->monitorMutex);
- this->mpd = this->manager->Open((char *)url.c_str());
+ IMPD* mpd = this->manager->Open((char *)url.c_str());
Debug("url : %s\n", url.c_str());
- if(this->mpd == NULL)
+ if(mpd == NULL)
{
LeaveCriticalSection(&this->monitorMutex);
return false;
}
Debug("Done DL the mpd\n");
+ this->mpdWrapper->setIsStopping(false);
+ this->mpdWrapper->updateMPD(mpd);
+ for (size_t i = 0; i < this->managerObservers.size(); i++)
+ this->managerObservers.at(i)->setMPDWrapper(this->mpdWrapper);
LeaveCriticalSection(&this->monitorMutex);
return true;
}
bool MultimediaManager::initICN(const std::string& url)
{
+ this->url = url;
EnterCriticalSection(&this->monitorMutex);
- libdash::framework::input::IICNConnection* icnConn = new libdash::framework::input::ICNConnectionConsumerApi(20.0, this->beta, this->drop);
+ this->icnConn = new libdash::framework::input::ICNConnectionConsumerApi(20.0, this->beta, this->drop);
icnConn->InitForMPD(url);
int ret = 0;
char * data = (char *)malloc(4096);
@@ -123,22 +130,69 @@ bool MultimediaManager::initICN(const std::string& url)
ret = icnConn->Read((uint8_t*)data,4096);
}
fclose(fp);
- this->mpd = this->manager->Open(const_cast<char*>(downloadFile.c_str()), url);
- if(this->mpd == NULL)
+ IMPD* mpd = this->manager->Open(const_cast<char*>(downloadFile.c_str()), url);
+ remove(downloadFile.c_str());
+ free(data);
+ if(mpd == NULL)
{
- remove(downloadFile.c_str());
- free(data);
delete icnConn;
LeaveCriticalSection(&this->monitorMutex);
return false;
}
- remove(downloadFile.c_str());
- free(data);
- delete icnConn;
+ this->mpdWrapper->setIsStopping(false);
+ this->mpdWrapper->updateMPD(mpd);
+ for (size_t i = 0; i < this->managerObservers.size(); i++)
+ this->managerObservers.at(i)->setMPDWrapper(this->mpdWrapper);
+ if( !strcmp(this->mpdWrapper->getType().c_str(), "static") )
+ {
+ delete icnConn;
+ }
+
LeaveCriticalSection(&this->monitorMutex);
return true;
}
+void MultimediaManager::updateMPD()
+{
+ this->mpdWrapper->updateMPD(this->manager->Open((char *)url.c_str()));
+}
+
+void MultimediaManager::updateMPDICN()
+{
+ this->icnConn->InitForMPD(this->url);
+ int ret = 0;
+ char * data = (char *)malloc(4096);
+ int pos = this->url.find_last_of("/");
+ if(pos == std::string::npos)
+ {
+ pos = strlen(this->url.c_str());
+ }
+ else
+ {
+ pos = pos + 1;
+ }
+
+ std::string downloadFile(this->downloadPath + this->url.substr(pos).c_str());
+ FILE *fp;
+ fp = fopen(downloadFile.c_str(), "w");
+ if(fp == NULL)
+ {
+ free(data);
+ return;
+ }
+ ret = icnConn->Read((uint8_t*)data, 4096);
+ while(ret)
+ {
+ fwrite(data, sizeof(char), ret, fp);
+ ret = icnConn->Read((uint8_t*)data,4096);
+ }
+ fclose(fp);
+ this->mpdWrapper->updateMPD(this->manager->Open(const_cast<char*>(downloadFile.c_str()), this->url));
+
+ remove(downloadFile.c_str());
+ free(data);
+}
+
bool MultimediaManager::isStarted()
{
return this->started;
@@ -154,6 +208,11 @@ bool MultimediaManager::isICN()
return this->icn;
}
+void MultimediaManager::setMPDWrapper(MPDWrapper* mpdWrapper)
+{
+ this->mpdWrapper = mpdWrapper;
+}
+
void MultimediaManager::start(bool icnEnabled, double icnAlpha, uint32_t nextOffset)
{
this->icn = icnEnabled;
@@ -168,7 +227,7 @@ void MultimediaManager::start(bool icnEnabled, double icnAlpha, uint32_t nextOff
qDebug("normal rate estimation\n");
}
EnterCriticalSection(&this->monitorMutex);
- if (this->videoAdaptationSet && this->videoRepresentation)
+ if(this->mpdWrapper->hasVideoAdaptationSetAndVideoRepresentation())
{
this->initVideoRendering(nextOffset);
this->videoStream->setAdaptationLogic(this->videoLogic);
@@ -185,6 +244,8 @@ void MultimediaManager::stop()
{
if (!this->started)
return;
+
+ this->mpdWrapper->setIsStopping(true);
this->stopping = true;
EnterCriticalSection(&this->monitorMutex);
this->stopVideo();
@@ -192,10 +253,8 @@ void MultimediaManager::stop()
this->started = false;
LeaveCriticalSection(&this->monitorMutex);
Debug("VIDEO STOPPED\n");
- this->period = this->mpd->GetPeriods().at(0);
- this->videoAdaptationSet = this->period->GetAdaptationSets().at(0);
- this->videoRepresentation = this->videoAdaptationSet->GetRepresentation().at(0);
-
+ this->mpdWrapper->reInit(viper::managers::StreamType::VIDEO);
+ this->mpdWrapper->reInit(viper::managers::StreamType::AUDIO);
}
void MultimediaManager::stopVideo()
@@ -219,30 +278,18 @@ void MultimediaManager::stopAudio()
}
}
-bool MultimediaManager::setVideoQuality(IPeriod* period, IAdaptationSet *adaptationSet, IRepresentation *representation)
+bool MultimediaManager::setVideoQuality()
{
- EnterCriticalSection(&this->monitorMutex);
- this->period = period;
- this->videoAdaptationSet = adaptationSet;
- this->videoRepresentation = representation;
if (this->videoStream)
- this->videoStream->setRepresentation(this->period, this->videoAdaptationSet, this->videoRepresentation);
-
- LeaveCriticalSection(&this->monitorMutex);
+ this->videoStream->setRepresentation();
return true;
}
-bool MultimediaManager::setAudioQuality(IPeriod* period, IAdaptationSet *adaptationSet, IRepresentation *representation)
+bool MultimediaManager::setAudioQuality()
{
- EnterCriticalSection(&this->monitorMutex);
-
- this->period = period;
- this->audioAdaptationSet = adaptationSet;
- this->audioRepresentation = representation;
if (this->audioStream)
- this->audioStream->setRepresentation(this->period, this->audioAdaptationSet, this->audioRepresentation);
- LeaveCriticalSection(&this->monitorMutex);
+ this->audioStream->setRepresentation();
return true;
}
@@ -256,11 +303,11 @@ bool MultimediaManager::isUserDependent()
bool MultimediaManager::setVideoAdaptationLogic(libdash::framework::adaptation::LogicType type, struct libdash::framework::adaptation::AdaptationParameters *params)
{
- if(this->videoAdaptationSet)
+ if(this->mpdWrapper->hasVideoAdaptationSetAndVideoRepresentation())
{
if(this->videoLogic)
delete(this->videoLogic);
- this->videoLogic = AdaptationLogicFactory::create(type, this->mpd, this->period, this->videoAdaptationSet, 1, params);
+ this->videoLogic = AdaptationLogicFactory::create(type, viper::managers::StreamType::VIDEO, this->mpdWrapper, params);
this->logicName = LogicType_string[type];
}
else
@@ -297,9 +344,11 @@ void MultimediaManager::setTargetDownloadingTime(bool isVideo, double target)
bool MultimediaManager::setAudioAdaptationLogic(libdash::framework::adaptation::LogicType type, struct libdash::framework::adaptation::AdaptationParameters *params)
{
- if(this->audioAdaptationSet)
+ if(this->mpdWrapper->hasAudioAdaptationSetAndAudioRepresentation())
{
- this->audioLogic = AdaptationLogicFactory::create(type, this->mpd, this->period, this->audioAdaptationSet, 0, params);
+ if(this->audioLogic)
+ delete(this->audioLogic);
+ this->audioLogic = AdaptationLogicFactory::create(type, viper::managers::StreamType::AUDIO, this->mpdWrapper, params);
this->logicName = LogicType_string[type];
}
else
@@ -344,17 +393,15 @@ void MultimediaManager::notifyAudioBufferObservers(uint32_t fillstateInPercent)
void MultimediaManager::initVideoRendering(uint32_t offset)
{
- this->videoStream = new MultimediaStream(viper::managers::VIDEO, this->mpd, this->segmentBufferSize, this->isICN(), this->icnAlpha, this->noDecoding, this->beta, this->drop);
+ this->videoStream = new MultimediaStream(viper::managers::VIDEO, this->mpdWrapper, this->segmentBufferSize, this->isICN(), this->icnAlpha, this->noDecoding, this->beta, this->drop);
this->videoStream->attachStreamObserver(this);
- this->videoStream->setRepresentation(this->period, this->videoAdaptationSet, this->videoRepresentation);
this->videoStream->setPosition(offset);
}
void MultimediaManager::initAudioPlayback(uint32_t offset)
{
- this->audioStream = new MultimediaStream(viper::managers::AUDIO, this->mpd, this->segmentBufferSize, this->isICN(), this->icnAlpha, this->noDecoding, this->beta, this->drop);
+ this->audioStream = new MultimediaStream(viper::managers::AUDIO, this->mpdWrapper, this->segmentBufferSize, this->isICN(), this->icnAlpha, this->noDecoding, this->beta, this->drop);
this->audioStream->attachStreamObserver(this);
- this->audioStream->setRepresentation(this->period, this->audioAdaptationSet, this->audioRepresentation);
this->audioStream->setPosition(offset);
}
@@ -506,14 +553,12 @@ void* MultimediaManager::pushVideoNoOut(void *data)
{
Debug("MANAGER:\tRebuffered %d ms\n", actualPosition *(-1));
manager->lastPointInTime = timeOfInsertion;
- //TODO Replace the 2 by a variable with segmentDuration
- manager->bufferingLimit = manager->lastPointInTime + std::chrono::seconds(2);
+ manager->bufferingLimit = manager->lastPointInTime + std::chrono::seconds(((int)manager->getSegmentDuration() / 1000));
}
else
{
- //TODO Replace the 2 by a variable with segmentDuration
Debug("MANAGER: INSERT TO BUFFER old_fillness: %f, new_fillness: %f\n", (double)((double)actualPosition/1000.0) / (double) this->segmentBufferSize, (double)((double)(actualPosition + 2000)/1000.0) / (double) manager->segmentBufferSize);
- manager->bufferingLimit = manager->bufferingLimit + std::chrono::seconds(2);
+ manager->bufferingLimit = manager->bufferingLimit + std::chrono::seconds(((int)manager->getSegmentDuration() /1000));
manager->lastPointInTime = timeOfInsertion;
}
delete segment;
@@ -566,7 +611,7 @@ int MultimediaManager::getBufferLevel()
uint32_t MultimediaManager::getUBufferLevel()
{
int mBufferLevel = 0;
- int segmentDurationInMs = 2000;
+ int segmentDurationInMs = (int) this->segmentDuration;
if(noDecoding)
{
@@ -587,7 +632,7 @@ uint32_t MultimediaManager::getUBufferLevel()
bool MultimediaManager::canPush()
{
- int segmentDurationInMs = 2000;
+ int segmentDurationInMs = (int)this->segmentDuration;
while(this->getUBufferLevel() >= 100 && !this->stopping)
{
sleep(segmentDurationInMs / 1000);
@@ -599,7 +644,7 @@ void* MultimediaManager::pushVideo(void *data)
{
MultimediaManager *manager = (MultimediaManager*) data;
libdash::framework::input::MediaObject *segment = manager->videoStream->getSegment();
- long int segmentDurationInMs = 2000;
+ int segmentDurationInMs = (int)manager->getSegmentDuration();
while(manager->isVideoRendering)
{
if (segment)
@@ -627,3 +672,22 @@ void MultimediaManager::setDrop(float drop)
{
this->drop = drop;
}
+
+void MultimediaManager::fetchMPD()
+{
+ if(this->icn)
+ this->updateMPDICN();
+ else
+ this->updateMPD();
+}
+
+//SegmentDuration is in ms
+void MultimediaManager::setSegmentDuration(float segDuration)
+{
+ this->segmentDuration = segDuration;
+}
+
+float MultimediaManager::getSegmentDuration()
+{
+ return this->segmentDuration;
+}