Commit 7d6ddb37 authored by François Cartegnie's avatar François Cartegnie 🤞 Committed by Jean-Baptiste Kempf

demux: adaptive: fix sidx handling (fix #16949, #16950)

Offset references refers to atom end when in same file
parent 73761ab7
......@@ -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)
......
......@@ -63,6 +63,7 @@ namespace adaptive
virtual ~AbstractChunk();
size_t getBytesRead () const;
uint64_t getStartByteInFile () const;
bool isEmpty () const;
virtual block_t * readBlock ();
......
......@@ -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);
}
}
......
......@@ -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++)
{
......
......@@ -41,7 +41,7 @@ namespace dash
{
public:
IndexReader(vlc_object_t *);
bool parseIndex(block_t *, BaseRepresentation *);
bool parseIndex(block_t *, BaseRepresentation *, uint64_t);
};
}
}
......
......@@ -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());
}
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