[vlc-commits] demux: adaptive: fix sidx handling (fix #16949, #16950)
Francois Cartegnie
git at videolan.org
Sun May 15 22:03:33 CEST 2016
vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Sat May 14 19:33:44 2016 +0200| [7d6ddb374339897b428bbcad3b237ca6d1e236d5] | committer: Jean-Baptiste Kempf
demux: adaptive: fix sidx handling (fix #16949, #16950)
Offset references refers to atom end when in same file
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=7d6ddb374339897b428bbcad3b237ca6d1e236d5
---
modules/demux/adaptive/http/Chunk.cpp | 8 +++++
modules/demux/adaptive/http/Chunk.h | 1 +
.../demux/adaptive/playlist/SegmentInformation.cpp | 38 ++++++++++----------
modules/demux/dash/mp4/IndexReader.cpp | 5 +--
modules/demux/dash/mp4/IndexReader.hpp | 2 +-
modules/demux/dash/mpd/DASHSegment.cpp | 4 +--
6 files changed, 35 insertions(+), 23 deletions(-)
diff --git a/modules/demux/adaptive/http/Chunk.cpp b/modules/demux/adaptive/http/Chunk.cpp
index fa4eb10..38c8ec9 100644
--- a/modules/demux/adaptive/http/Chunk.cpp
+++ b/modules/demux/adaptive/http/Chunk.cpp
@@ -75,6 +75,14 @@ size_t AbstractChunk::getBytesRead() const
return this->bytesRead;
}
+uint64_t AbstractChunk::getStartByteInFile() const
+{
+ if(!source || !source->getBytesRange().isValid())
+ return 0;
+
+ return source->getBytesRange().getStartByte();
+}
+
block_t * AbstractChunk::doRead(size_t size, bool b_block)
{
if(!source)
diff --git a/modules/demux/adaptive/http/Chunk.h b/modules/demux/adaptive/http/Chunk.h
index 41ea6aa..127d98b 100644
--- a/modules/demux/adaptive/http/Chunk.h
+++ b/modules/demux/adaptive/http/Chunk.h
@@ -63,6 +63,7 @@ namespace adaptive
virtual ~AbstractChunk();
size_t getBytesRead () const;
+ uint64_t getStartByteInFile () const;
bool isEmpty () const;
virtual block_t * readBlock ();
diff --git a/modules/demux/adaptive/playlist/SegmentInformation.cpp b/modules/demux/adaptive/playlist/SegmentInformation.cpp
index 8b14348..018a4f8 100644
--- a/modules/demux/adaptive/playlist/SegmentInformation.cpp
+++ b/modules/demux/adaptive/playlist/SegmentInformation.cpp
@@ -484,11 +484,9 @@ static void insertIntoSegment(std::vector<ISegment *> &seglist, size_t start,
{
ISegment *segment = *segIt;
if(segment->getClassId() == Segment::CLASSID_SEGMENT &&
- segment->contains(end + segment->getOffset()))
+ (end == 0 || segment->contains(end)))
{
- SubSegment *subsegment = new SubSegment(segment,
- start + segment->getOffset(),
- (end != 0) ? end + segment->getOffset() : 0);
+ SubSegment *subsegment = new SubSegment(segment, start, (end != 0) ? end : 0);
subsegment->startTime.Set(time);
segment->addSubSegment(subsegment);
break;
@@ -500,27 +498,31 @@ void SegmentInformation::SplitUsingIndex(std::vector<SplitPoint> &splitlist)
{
std::vector<ISegment *> seglist;
getSegments(INFOTYPE_MEDIA, seglist);
- std::vector<SplitPoint>::const_iterator splitIt;
- size_t start = 0, end = 0;
- mtime_t time = 0;
+ size_t prevstart = 0;
+ stime_t prevtime = 0;
const uint64_t i_timescale = inheritTimescale();
+ SplitPoint split = {0,0};
+ std::vector<SplitPoint>::const_iterator splitIt;
for(splitIt = splitlist.begin(); splitIt < splitlist.end(); ++splitIt)
{
- start = end;
- SplitPoint split = *splitIt;
- end = split.offset;
- if(splitIt == splitlist.begin() && split.offset == 0)
- continue;
- time = split.time;
- insertIntoSegment(seglist, start, end - 1, time * i_timescale / CLOCK_FREQ);
+ split = *splitIt;
+ if(splitIt != splitlist.begin())
+ {
+ /* do previous splitpoint */
+ insertIntoSegment(seglist, prevstart, split.offset - 1, prevtime);
+ }
+ prevstart = split.offset;
+ prevtime = split.time * i_timescale / CLOCK_FREQ;
}
- if(start != 0)
+ if(splitlist.size() == 1)
+ {
+ insertIntoSegment(seglist, prevstart, 0, prevtime);
+ }
+ else if(splitlist.size() > 1)
{
- start = end;
- end = 0;
- insertIntoSegment(seglist, start, end, time * i_timescale / CLOCK_FREQ);
+ insertIntoSegment(seglist, prevstart, split.offset - 1, prevtime);
}
}
diff --git a/modules/demux/dash/mp4/IndexReader.cpp b/modules/demux/dash/mp4/IndexReader.cpp
index 06df9e1..92a2727 100644
--- a/modules/demux/dash/mp4/IndexReader.cpp
+++ b/modules/demux/dash/mp4/IndexReader.cpp
@@ -34,7 +34,7 @@ IndexReader::IndexReader(vlc_object_t *obj)
{
}
-bool IndexReader::parseIndex(block_t *p_block, BaseRepresentation *rep)
+bool IndexReader::parseIndex(block_t *p_block, BaseRepresentation *rep, uint64_t i_fileoffset)
{
if(!rep || !parseBlock(p_block))
return false;
@@ -45,7 +45,8 @@ bool IndexReader::parseIndex(block_t *p_block, BaseRepresentation *rep)
Representation::SplitPoint point;
std::vector<Representation::SplitPoint> splitlist;
MP4_Box_data_sidx_t *sidx = sidxbox->data.p_sidx;
- point.offset = sidx->i_first_offset;
+ /* sidx refers to offsets from end of sidx pos in the file + first offset */
+ point.offset = sidx->i_first_offset + i_fileoffset + sidxbox->i_pos + sidxbox->i_size;
point.time = 0;
for(uint16_t i=0; i<sidx->i_reference_count && sidx->i_timescale; i++)
{
diff --git a/modules/demux/dash/mp4/IndexReader.hpp b/modules/demux/dash/mp4/IndexReader.hpp
index dcaf12a..7c19e87 100644
--- a/modules/demux/dash/mp4/IndexReader.hpp
+++ b/modules/demux/dash/mp4/IndexReader.hpp
@@ -41,7 +41,7 @@ namespace dash
{
public:
IndexReader(vlc_object_t *);
- bool parseIndex(block_t *, BaseRepresentation *);
+ bool parseIndex(block_t *, BaseRepresentation *, uint64_t);
};
}
}
diff --git a/modules/demux/dash/mpd/DASHSegment.cpp b/modules/demux/dash/mpd/DASHSegment.cpp
index 3bdeaf2..c21b201 100644
--- a/modules/demux/dash/mpd/DASHSegment.cpp
+++ b/modules/demux/dash/mpd/DASHSegment.cpp
@@ -41,11 +41,11 @@ DashIndexSegment::DashIndexSegment(ICanonicalUrl *parent) :
{
}
-void DashIndexSegment::onChunkDownload(block_t **pp_block, SegmentChunk *, BaseRepresentation *rep)
+void DashIndexSegment::onChunkDownload(block_t **pp_block, SegmentChunk *p_chunk, BaseRepresentation *rep)
{
if(!rep || ((*pp_block)->i_flags & BLOCK_FLAG_HEADER) == 0 )
return;
IndexReader br(rep->getPlaylist()->getVLCObject());
- br.parseIndex(*pp_block, rep);
+ br.parseIndex(*pp_block, rep, p_chunk->getStartByteInFile());
}
More information about the vlc-commits
mailing list