Commit 0e2b401c authored by Christopher Mueller's avatar Christopher Mueller Committed by Hugo Beauzée-Luyssen

dash: added downloader and bitrate to chunk

Signed-off-by: default avatarHugo Beauzée-Luyssen <beauze.h@gmail.com>
parent 152916ce
/*
* DASHDownloader.h
*****************************************************************************
* Copyright (C) 2010 - 2011 Klagenfurt University
*
* Created on: Aug 10, 2010
* Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
* Christian Timmerer <christian.timmerer@itec.uni-klu.ac.at>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "DASHDownloader.h"
using namespace dash;
using namespace dash::http;
using namespace dash::logic;
using namespace dash::exception;
using namespace dash::buffer;
DASHDownloader::DASHDownloader (HTTPConnectionManager *conManager, IAdaptationLogic *adaptationLogic, BlockBuffer *buffer)
{
this->t_sys = (thread_sys_t *) malloc(sizeof(thread_sys_t));
this->t_sys->conManager = conManager;
this->t_sys->adaptationLogic = adaptationLogic;
this->t_sys->buffer = buffer;
}
DASHDownloader::~DASHDownloader ()
{
std::cout << "Downloader set eof" << std::endl;
this->t_sys->buffer->setEOF(true);
std::cout << "Downloader try to join" << std::endl;
vlc_join(this->dashDLThread, NULL);
free(this->t_sys);
std::cout << "Downloader thread joined tsys freed" << std::endl;
}
bool DASHDownloader::start ()
{
if(vlc_clone(&(this->dashDLThread), download, (void*)this->t_sys, VLC_THREAD_PRIORITY_LOW))
return false;
return true;
}
void* DASHDownloader::download (void *thread_sys)
{
thread_sys_t *t_sys = (thread_sys_t *) thread_sys;
HTTPConnectionManager *conManager = t_sys->conManager;
IAdaptationLogic *adaptationLogic = t_sys->adaptationLogic;
BlockBuffer *buffer = t_sys->buffer;
Chunk *currentChunk = NULL;
block_t *block = block_Alloc(BLOCKSIZE);
do
{
if(currentChunk == NULL)
{
try
{
currentChunk = adaptationLogic->getNextChunk();
}
catch(EOFException &e)
{
buffer->setEOF(true);
}
}
else
{
int ret = conManager->read(currentChunk, block->p_buffer, block->i_buffer);
if(ret <= 0)
{
currentChunk = NULL;
}
else
{
block_t *bufBlock = block_Alloc(ret);
memcpy(bufBlock->p_buffer, block->p_buffer, ret);
bufBlock->i_length = (mtime_t)((ret * 8) / ((float)currentChunk->getBitrate() / 1000000));
std::cout << "Put block into buffer MilliSeconds: " << bufBlock->i_length
<< " Bytes: " << bufBlock->i_buffer
<< " Bitrate: " << currentChunk->getBitrate() << std::endl;
buffer->put(bufBlock);
}
}
}while(!buffer->getEOF());
std::cout << "Downloader end: " << std::endl;
block_Release(block);
return NULL;
}
/*
* DASHDownloader.h
*****************************************************************************
* Copyright (C) 2010 - 2011 Klagenfurt University
*
* Created on: Aug 10, 2010
* Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
* Christian Timmerer <christian.timmerer@itec.uni-klu.ac.at>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef DASHDOWNLOADER_H_
#define DASHDOWNLOADER_H_
#include "http/HTTPConnectionManager.h"
#include "adaptationlogic/IAdaptationLogic.h"
#include "exceptions/EOFException.h"
#include "buffer/BlockBuffer.h"
#define BLOCKSIZE 32768
#include <iostream>
namespace dash
{
struct thread_sys_t
{
dash::http::HTTPConnectionManager *conManager;
logic::IAdaptationLogic *adaptationLogic;
buffer::BlockBuffer *buffer;
};
class DASHDownloader
{
public:
DASHDownloader (http::HTTPConnectionManager *conManager, logic::IAdaptationLogic *adaptationLogic, buffer::BlockBuffer *buffer);
virtual ~DASHDownloader ();
bool start ();
static void* download (void *);
private:
thread_sys_t *t_sys;
vlc_thread_t dashDLThread;
};
}
#endif /* DASHDOWNLOADER_H_ */
...@@ -76,6 +76,8 @@ SOURCES_stream_filter_dash = \ ...@@ -76,6 +76,8 @@ SOURCES_stream_filter_dash = \
xml/Node.cpp \ xml/Node.cpp \
xml/Node.h \ xml/Node.h \
dash.cpp \ dash.cpp \
DASHDownloader.cpp \
DASHDownloader.h \
DASHManager.cpp \ DASHManager.cpp \
DASHManager.h \ DASHManager.h \
$(NULL) $(NULL)
......
...@@ -72,3 +72,11 @@ void Chunk::setUseByteRange (bool value) ...@@ -72,3 +72,11 @@ void Chunk::setUseByteRange (bool value)
{ {
this->hasByteRange = value; this->hasByteRange = value;
} }
void Chunk::setBitrate (int bitrate)
{
this->bitrate = bitrate;
}
int Chunk::getBitrate ()
{
return this->bitrate;
}
...@@ -46,6 +46,8 @@ namespace dash ...@@ -46,6 +46,8 @@ namespace dash
void addOptionalUrl (const std::string& url); void addOptionalUrl (const std::string& url);
bool useByteRange (); bool useByteRange ();
void setUseByteRange (bool value); void setUseByteRange (bool value);
void setBitrate (int bitrate);
int getBitrate ();
private: private:
std::string url; std::string url;
...@@ -53,6 +55,7 @@ namespace dash ...@@ -53,6 +55,7 @@ namespace dash
int startByte; int startByte;
int endByte; int endByte;
bool hasByteRange; bool hasByteRange;
int bitrate;
}; };
} }
......
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