Commit dbcef6f7 authored by François Cartegnie's avatar François Cartegnie 🤞

stream_filter: dash: Split monolithic segments using index

parent 98b674d7
...@@ -67,15 +67,19 @@ bool AtomsReader::parseBlock(void *buffer, size_t size) ...@@ -67,15 +67,19 @@ bool AtomsReader::parseBlock(void *buffer, size_t size)
MP4_Box_t *sidxbox = MP4_BoxGet(rootbox, "sidx"); MP4_Box_t *sidxbox = MP4_BoxGet(rootbox, "sidx");
if (sidxbox) if (sidxbox)
{ {
Representation::SplitPoint point;
std::vector<Representation::SplitPoint> splitlist;
MP4_Box_data_sidx_t *sidx = sidxbox->data.p_sidx; MP4_Box_data_sidx_t *sidx = sidxbox->data.p_sidx;
size_t offset = sidx->i_first_offset; point.offset = sidx->i_first_offset;
point.time = 0;
for(uint16_t i=0; i<sidx->i_reference_count; i++) for(uint16_t i=0; i<sidx->i_reference_count; i++)
{ {
std::cerr << " offset " << offset << std::endl; splitlist.push_back(point);
offset += sidx->p_items[i].i_referenced_size; point.offset += sidx->p_items[i].i_referenced_size;
point.time += sidx->p_items[i].i_subsegment_duration;
} }
segment->getRepresentation()->SplitUsingIndex(splitlist);
} }
std::cerr << "index seg " << ((uint8_t *)buffer)[4] << ((uint8_t *)buffer)[5] << std::endl;
} }
stream_Delete(stream); stream_Delete(stream);
} }
......
...@@ -229,3 +229,47 @@ MPD * Representation::getMPD() const ...@@ -229,3 +229,47 @@ MPD * Representation::getMPD() const
{ {
return mpd; return mpd;
} }
static void insertIntoSegment(std::vector<Segment *> &seglist, size_t start,
size_t end)
{
std::vector<Segment *>::iterator segIt;
for(segIt = seglist.begin(); segIt < seglist.end(); segIt++)
{
Segment *segment = *segIt;
if(segment->getClassId() == Segment::CLASSID_SEGMENT &&
segment->contains(end + segment->getOffset()))
{
SubSegment *subsegment = new SubSegment(segment,
start + segment->getOffset(),
end + segment->getOffset());
segment->addSubSegment(subsegment);
break;
}
}
}
void Representation::SplitUsingIndex(std::vector<SplitPoint> &splitlist)
{
std::vector<Segment *> seglist = segmentList->getSegments();
std::vector<SplitPoint>::const_iterator splitIt;
size_t start = 0, end = 0;
for(splitIt = splitlist.begin(); splitIt < splitlist.end(); splitIt++)
{
start = end;
SplitPoint split = *splitIt;
end = split.offset;
if(splitIt == splitlist.begin() && split.offset == 0)
continue;
insertIntoSegment(seglist, start, end);
end++;
}
if(start != 0)
{
start = end;
end = 0;
insertIntoSegment(seglist, start, end);
}
}
...@@ -89,6 +89,14 @@ namespace dash ...@@ -89,6 +89,14 @@ namespace dash
std::vector<std::string> toString() const; std::vector<std::string> toString() const;
virtual std::string getUrlSegment () const; /* impl */ virtual std::string getUrlSegment () const; /* impl */
class SplitPoint
{
public:
size_t offset;
mtime_t time;
};
void SplitUsingIndex(std::vector<SplitPoint>&);
private: private:
MPD *mpd; MPD *mpd;
uint64_t bandwidth; uint64_t bandwidth;
......
...@@ -81,6 +81,11 @@ void ISegment::setByteRange(size_t start, size_t end) ...@@ -81,6 +81,11 @@ void ISegment::setByteRange(size_t start, size_t end)
endByte = end; endByte = end;
} }
size_t ISegment::getOffset() const
{
return startByte;
}
std::string ISegment::toString() const std::string ISegment::toString() const
{ {
std::stringstream ss(" "); std::stringstream ss(" ");
...@@ -90,6 +95,14 @@ std::string ISegment::toString() const ...@@ -90,6 +95,14 @@ std::string ISegment::toString() const
return ss.str(); return ss.str();
} }
bool ISegment::contains(size_t byte) const
{
if (startByte == endByte)
return false;
return (byte >= startByte &&
(!endByte || byte <= endByte) );
}
int ISegment::getClassId() const int ISegment::getClassId() const
{ {
return classId; return classId;
...@@ -118,6 +131,11 @@ Segment::Segment(Representation *parent) : ...@@ -118,6 +131,11 @@ Segment::Segment(Representation *parent) :
classId = CLASSID_SEGMENT; classId = CLASSID_SEGMENT;
} }
void Segment::addSubSegment(SubSegment *subsegment)
{
subsegments.push_back(subsegment);
}
Segment::~Segment() Segment::~Segment()
{ {
std::vector<SubSegment*>::iterator it; std::vector<SubSegment*>::iterator it;
...@@ -214,6 +232,8 @@ IndexSegment::IndexSegmentChunk::IndexSegmentChunk(ISegment *segment) ...@@ -214,6 +232,8 @@ IndexSegment::IndexSegmentChunk::IndexSegmentChunk(ISegment *segment)
void IndexSegment::IndexSegmentChunk::onDownload(void *buffer, size_t size) void IndexSegment::IndexSegmentChunk::onDownload(void *buffer, size_t size)
{ {
dash::mp4::AtomsReader br(segment);
br.parseBlock(buffer, size);
} }
SubSegment::SubSegment(Segment *main, size_t start, size_t end) : SubSegment::SubSegment(Segment *main, size_t start, size_t end) :
......
...@@ -53,9 +53,11 @@ namespace dash ...@@ -53,9 +53,11 @@ namespace dash
virtual void done (); virtual void done ();
virtual dash::http::Chunk* toChunk (); virtual dash::http::Chunk* toChunk ();
virtual void setByteRange (size_t start, size_t end); virtual void setByteRange (size_t start, size_t end);
virtual size_t getOffset () const;
virtual std::vector<ISegment*> subSegments () = 0; virtual std::vector<ISegment*> subSegments () = 0;
virtual std::string toString () const; virtual std::string toString () const;
virtual Representation* getRepresentation() const = 0; virtual Representation* getRepresentation() const = 0;
virtual bool contains (size_t byte) const;
int getClassId () const; int getClassId () const;
static const int CLASSID_ISEGMENT = 0; static const int CLASSID_ISEGMENT = 0;
...@@ -89,6 +91,8 @@ namespace dash ...@@ -89,6 +91,8 @@ namespace dash
virtual dash::http::Chunk* toChunk(); virtual dash::http::Chunk* toChunk();
virtual std::vector<ISegment*> subSegments(); virtual std::vector<ISegment*> subSegments();
virtual Representation* getRepresentation() const; virtual Representation* getRepresentation() const;
virtual std::string toString() const;
virtual void addSubSegment(SubSegment *);
static const int CLASSID_SEGMENT = 1; static const int CLASSID_SEGMENT = 1;
protected: protected:
......
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