Commit d84d7803 authored by Francois Cartegnie's avatar Francois Cartegnie

demux: adaptative: refactor atoms reader

parent 05663f7b
...@@ -292,6 +292,8 @@ libadaptative_plugin_la_SOURCES = \ ...@@ -292,6 +292,8 @@ libadaptative_plugin_la_SOURCES = \
demux/adaptative/logic/RateBasedAdaptationLogic.cpp \ demux/adaptative/logic/RateBasedAdaptationLogic.cpp \
demux/adaptative/logic/Representationselectors.hpp \ demux/adaptative/logic/Representationselectors.hpp \
demux/adaptative/logic/Representationselectors.cpp \ demux/adaptative/logic/Representationselectors.cpp \
demux/adaptative/mp4/AtomsReader.cpp \
demux/adaptative/mp4/AtomsReader.hpp \
demux/adaptative/http/BytesRange.cpp \ demux/adaptative/http/BytesRange.cpp \
demux/adaptative/http/BytesRange.hpp \ demux/adaptative/http/BytesRange.hpp \
demux/adaptative/http/Chunk.cpp \ demux/adaptative/http/Chunk.cpp \
...@@ -362,8 +364,8 @@ libadaptative_dash_SOURCES = \ ...@@ -362,8 +364,8 @@ libadaptative_dash_SOURCES = \
demux/dash/mpd/Representation.h \ demux/dash/mpd/Representation.h \
demux/dash/mpd/TrickModeType.cpp \ demux/dash/mpd/TrickModeType.cpp \
demux/dash/mpd/TrickModeType.h \ demux/dash/mpd/TrickModeType.h \
demux/dash/mp4/AtomsReader.cpp \ demux/dash/mp4/IndexReader.cpp \
demux/dash/mp4/AtomsReader.hpp \ demux/dash/mp4/IndexReader.hpp \
demux/dash/DASHManager.cpp \ demux/dash/DASHManager.cpp \
demux/dash/DASHManager.h \ demux/dash/DASHManager.h \
demux/dash/DASHStream.cpp \ demux/dash/DASHStream.cpp \
......
...@@ -18,11 +18,8 @@ ...@@ -18,11 +18,8 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/ *****************************************************************************/
#include "AtomsReader.hpp" #include "AtomsReader.hpp"
#include "../mpd/Representation.h"
#include "../mpd/MPD.h"
using namespace dash::mp4; using namespace adaptative::mp4;
using namespace dash::mpd;
AtomsReader::AtomsReader(vlc_object_t *object_) AtomsReader::AtomsReader(vlc_object_t *object_)
{ {
...@@ -31,6 +28,11 @@ AtomsReader::AtomsReader(vlc_object_t *object_) ...@@ -31,6 +28,11 @@ AtomsReader::AtomsReader(vlc_object_t *object_)
} }
AtomsReader::~AtomsReader() AtomsReader::~AtomsReader()
{
clean();
}
void AtomsReader::clean()
{ {
while(rootbox && rootbox->p_first) while(rootbox && rootbox->p_first)
{ {
...@@ -39,12 +41,13 @@ AtomsReader::~AtomsReader() ...@@ -39,12 +41,13 @@ AtomsReader::~AtomsReader()
rootbox->p_first = p_next; rootbox->p_first = p_next;
} }
delete rootbox; delete rootbox;
rootbox = NULL;
} }
bool AtomsReader::parseBlock(block_t *p_block, BaseRepresentation *rep) bool AtomsReader::parseBlock(block_t *p_block)
{ {
if(!rep) if(rootbox)
return false; clean();
stream_t *stream = stream_MemoryNew( object, p_block->p_buffer, p_block->i_buffer, true); stream_t *stream = stream_MemoryNew( object, p_block->p_buffer, p_block->i_buffer, true);
if (stream) if (stream)
...@@ -63,24 +66,6 @@ bool AtomsReader::parseBlock(block_t *p_block, BaseRepresentation *rep) ...@@ -63,24 +66,6 @@ bool AtomsReader::parseBlock(block_t *p_block, BaseRepresentation *rep)
#ifndef NDEBUG #ifndef NDEBUG
MP4_BoxDumpStructure(stream, rootbox); MP4_BoxDumpStructure(stream, rootbox);
#endif #endif
MP4_Box_t *sidxbox = MP4_BoxGet(rootbox, "sidx");
if (sidxbox)
{
Representation::SplitPoint point;
std::vector<Representation::SplitPoint> splitlist;
MP4_Box_data_sidx_t *sidx = sidxbox->data.p_sidx;
point.offset = sidx->i_first_offset;
point.time = 0;
for(uint16_t i=0; i<sidx->i_reference_count && sidx->i_timescale; i++)
{
splitlist.push_back(point);
point.offset += sidx->p_items[i].i_referenced_size;
point.time += CLOCK_FREQ * sidx->p_items[i].i_subsegment_duration /
sidx->i_timescale;
}
rep->SplitUsingIndex(splitlist);
rep->getPlaylist()->debug();
}
} }
stream_Delete(stream); stream_Delete(stream);
} }
......
...@@ -31,14 +31,6 @@ extern "C" { ...@@ -31,14 +31,6 @@ extern "C" {
} }
namespace adaptative namespace adaptative
{
namespace playlist
{
class BaseRepresentation;
}
}
namespace dash
{ {
namespace mp4 namespace mp4
{ {
...@@ -47,7 +39,8 @@ namespace dash ...@@ -47,7 +39,8 @@ namespace dash
public: public:
AtomsReader(vlc_object_t *); AtomsReader(vlc_object_t *);
~AtomsReader(); ~AtomsReader();
bool parseBlock(block_t *, adaptative::playlist::BaseRepresentation *); void clean();
bool parseBlock(block_t *);
protected: protected:
vlc_object_t *object; vlc_object_t *object;
......
/*
* IndexReader.cpp
*****************************************************************************
* Copyright (C) 2015 - VideoLAN and VLC authors
*
* 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 Lesser 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.
*****************************************************************************/
#include "IndexReader.hpp"
#include "../mpd/Representation.h"
#include "../mpd/MPD.h"
using namespace adaptative::mp4;
using namespace dash::mp4;
using namespace dash::mpd;
IndexReader::IndexReader(vlc_object_t *obj)
: AtomsReader(obj)
{
}
bool IndexReader::parseIndex(block_t *p_block, BaseRepresentation *rep)
{
if(!rep || !parseBlock(p_block))
return false;
MP4_Box_t *sidxbox = MP4_BoxGet(rootbox, "sidx");
if (sidxbox)
{
Representation::SplitPoint point;
std::vector<Representation::SplitPoint> splitlist;
MP4_Box_data_sidx_t *sidx = sidxbox->data.p_sidx;
point.offset = sidx->i_first_offset;
point.time = 0;
for(uint16_t i=0; i<sidx->i_reference_count && sidx->i_timescale; i++)
{
splitlist.push_back(point);
point.offset += sidx->p_items[i].i_referenced_size;
point.time += CLOCK_FREQ * sidx->p_items[i].i_subsegment_duration /
sidx->i_timescale;
}
rep->SplitUsingIndex(splitlist);
rep->getPlaylist()->debug();
}
return true;
}
/*
* IndexReader.hpp
*****************************************************************************
* Copyright (C) 2015 - VideoLAN and VLC authors
*
* 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 Lesser 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 INDEXREADER_HPP
#define INDEXREADER_HPP
#include "../adaptative/mp4/AtomsReader.hpp"
namespace adaptative
{
namespace playlist
{
class BaseRepresentation;
}
}
namespace dash
{
namespace mp4
{
using namespace adaptative::mp4;
using namespace adaptative::playlist;
class IndexReader : public AtomsReader
{
public:
IndexReader(vlc_object_t *);
bool parseIndex(block_t *, BaseRepresentation *);
};
}
}
#endif // INDEXREADER_HPP
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
#include "DASHSegment.h" #include "DASHSegment.h"
#include "../adaptative/playlist/BaseRepresentation.h" #include "../adaptative/playlist/BaseRepresentation.h"
#include "../mp4/AtomsReader.hpp" #include "../mp4/IndexReader.hpp"
#include "../adaptative/playlist/AbstractPlaylist.hpp" #include "../adaptative/playlist/AbstractPlaylist.hpp"
#include "../adaptative/playlist/SegmentChunk.hpp" #include "../adaptative/playlist/SegmentChunk.hpp"
...@@ -46,6 +46,6 @@ void DashIndexSegment::onChunkDownload(block_t **pp_block, SegmentChunk *, BaseR ...@@ -46,6 +46,6 @@ void DashIndexSegment::onChunkDownload(block_t **pp_block, SegmentChunk *, BaseR
if(!rep) if(!rep)
return; return;
AtomsReader br(rep->getPlaylist()->getVLCObject()); IndexReader br(rep->getPlaylist()->getVLCObject());
br.parseBlock(*pp_block, rep); br.parseIndex(*pp_block, rep);
} }
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