Skip to content

Commit

Permalink
[DASH] YT manifest adaptions (tbc)
Browse files Browse the repository at this point in the history
  • Loading branch information
peak3d committed Aug 22, 2017
1 parent 0c7e975 commit 701f590
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 12 deletions.
4 changes: 4 additions & 0 deletions src/common/AdaptiveStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ bool AdaptiveStream::download_segment()
if (!(current_rep_->flags_ & AdaptiveTree::Representation::TEMPLATE))
{
if (current_rep_->flags_ & AdaptiveTree::Representation::URLSEGMENTS)
{
strURL = current_seg_->url;
if (strURL.find("://", 0) == std::string::npos)
strURL = current_rep_->url_ + strURL;
}
else
{
strURL = current_rep_->url_;
Expand Down
16 changes: 10 additions & 6 deletions src/common/AdaptiveTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,10 @@ namespace adaptive

struct AdaptationSet
{
AdaptationSet() :type_(NOTYPE), timescale_(0), startPTS_(0), startNumber_(1), impaired_(false){ language_ = "unk"; };
AdaptationSet() :type_(NOTYPE), timescale_(0), duration_(0), startPTS_(0), startNumber_(1), impaired_(false){ language_ = "unk"; };
~AdaptationSet() { for (std::vector<Representation* >::const_iterator b(repesentations_.begin()), e(repesentations_.end()); b != e; ++b) delete *b; };
StreamType type_;
uint32_t timescale_;
uint32_t timescale_, duration_;
uint64_t startPTS_;
unsigned int startNumber_;
bool impaired_;
Expand All @@ -230,23 +230,27 @@ namespace adaptive
std::string codecs_;
std::vector<Representation*> repesentations_;
SPINCACHE<uint32_t> segment_durations_;
SegmentTemplate segtpl_;

const uint32_t get_segment_duration(uint32_t pos)const
{
return *segment_durations_[pos];
};

static bool compare(const AdaptationSet* a, const AdaptationSet *b) { return a->type_ < b->type_; };

SegmentTemplate segtpl_;
}*current_adaptationset_;

struct Period
{
Period() {};
Period(): timescale_(0), duration_(0), startPTS_(0), startNumber_(1) {};
~Period() { for (std::vector<AdaptationSet* >::const_iterator b(adaptationSets_.begin()), e(adaptationSets_.end()); b != e; ++b) delete *b; };
std::vector<AdaptationSet*> adaptationSets_;
std::string base_url_;
uint32_t duration_, timescale_;
uint64_t startPTS_;
unsigned int startNumber_;
SPINCACHE<uint32_t> segment_durations_;
SegmentTemplate segtpl_;
}*current_period_;

std::vector<Period*> periods_;
Expand Down Expand Up @@ -293,7 +297,7 @@ namespace adaptive
uint16_t adpwidth_, adpheight_;
uint32_t adpfpsRate_;
float adpaspect_;
bool adp_timelined_;
bool adp_timelined_, period_timelined_;

bool current_hasRepURN_, current_hasAdpURN_;
std::string current_pssh_, current_defaultKID_, current_iv_;
Expand Down
116 changes: 110 additions & 6 deletions src/parser/DASHTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,13 @@ start(void *data, const char *el, const char **attr)
seg.SetRange((const char*)*(attr + 1));
break;
}
else if (strcmp((const char*)*attr, "media") == 0)
{
dash->current_representation_->flags_ |= DASHTree::Representation::URLSEGMENTS;
size_t sz(strlen((const char*)*(attr + 1)) + 1);
seg.url = new char[sz];
memcpy((char*)seg.url, (const char*)*(attr + 1), sz);
}
attr += 2;
}
dash->current_representation_->segments_.data.push_back(seg);
Expand Down Expand Up @@ -484,22 +491,29 @@ start(void *data, const char *el, const char **attr)
}
else if (strcmp(el, "SegmentList") == 0)
{

uint32_t dur(0), ts(0);
for (; *attr;)
{
if (strcmp((const char*)*attr, "duration") == 0)
dash->current_representation_->duration_ = atoi((const char*)*(attr + 1));
dur = atoi((const char*)*(attr + 1));
else if (strcmp((const char*)*attr, "timescale") == 0)
dash->current_representation_->timescale_ = atoi((const char*)*(attr + 1));
ts = atoi((const char*)*(attr + 1));
attr += 2;
}
if (dash->current_representation_->timescale_)
if (ts)
{
dash->current_representation_->segments_.data.reserve(dash->estimate_segcount(
dash->current_representation_->duration_,
dash->current_representation_->timescale_));
dash->currentNode_ |= DASHTree::MPDNODE_SEGMENTLIST;
}
else if (dash->current_adaptationset_->segment_durations_.data.size())
{
dash->current_representation_->segments_.data.reserve(
dash->current_adaptationset_->segment_durations_.data.size());
}
else
return;
dash->currentNode_ |= DASHTree::MPDNODE_SEGMENTLIST;
}
else if (strcmp(el, "SegmentBase") == 0)
{
Expand Down Expand Up @@ -626,6 +640,7 @@ start(void *data, const char *el, const char **attr)
dash->current_representation_->codecs_ = dash->current_adaptationset_->codecs_;
dash->current_representation_->url_ = dash->current_adaptationset_->base_url_;
dash->current_representation_->timescale_ = dash->current_adaptationset_->timescale_;
dash->current_representation_->duration_ = dash->current_adaptationset_->duration_;
dash->current_adaptationset_->repesentations_.push_back(dash->current_representation_);
dash->current_representation_->width_ = dash->adpwidth_;
dash->current_representation_->height_ = dash->adpheight_;
Expand Down Expand Up @@ -710,6 +725,51 @@ start(void *data, const char *el, const char **attr)
dash->currentNode_ |= DASHTree::MPDNODE_BASEURL;
}
}
else if (dash->currentNode_ & (DASHTree::MPDNODE_SEGMENTLIST | DASHTree::MPDNODE_SEGMENTTEMPLATE))
{
if (dash->currentNode_ & DASHTree::MPDNODE_SEGMENTTIMELINE)
{
// <S t="3600" d="900000" r="2398"/>
unsigned int d(0), r(1);
uint64_t t(0);
for (; *attr;)
{
if (strcmp((const char*)*attr, "t") == 0)
t = atoll((const char*)*(attr + 1));
else if (strcmp((const char*)*attr, "d") == 0)
d = atoi((const char*)*(attr + 1));
if (strcmp((const char*)*attr, "r") == 0)
r = atoi((const char*)*(attr + 1)) + 1;
attr += 2;
}
if (dash->current_period_->segment_durations_.data.empty())
{
if (!dash->current_period_->duration_ && d)
dash->current_period_->segment_durations_.data.reserve(dash->estimate_segcount(d, dash->current_period_->timescale_));
dash->current_period_->startPTS_ = dash->pts_helper_ = t;
}
else if (t)
{
//Go back to the previous timestamp to calculate the real gap.
dash->pts_helper_ -= dash->current_adaptationset_->segment_durations_.data.back();
dash->current_period_->segment_durations_.data.back() = static_cast<uint32_t>(t - dash->pts_helper_);
dash->pts_helper_ = t;
}
if (d && r)
{
for (; r; --r)
{
dash->current_period_->segment_durations_.data.push_back(d);
dash->pts_helper_ += d;
}
}
}
else if (strcmp(el, "SegmentTimeline") == 0)
{
dash->currentNode_ |= DASHTree::MPDNODE_SEGMENTTIMELINE;
dash->period_timelined_ = true;
}
}
else if (strcmp(el, "AdaptationSet") == 0)
{
//<AdaptationSet contentType="video" group="2" lang="en" mimeType="video/mp4" par="16:9" segmentAlignment="true" startWithSAP="1" subsegmentAlignment="true" subsegmentStartsWithSAP="1">
Expand All @@ -724,7 +784,12 @@ start(void *data, const char *el, const char **attr)
dash->adpaspect_ = 0.0f;
dash->adp_pssh_set_ = 0;
dash->current_hasAdpURN_ = false;
dash->adp_timelined_ = false;
dash->adp_timelined_ = dash->period_timelined_;
dash->current_adaptationset_->timescale_ = dash->current_period_->timescale_;
dash->current_adaptationset_->duration_ = dash->current_period_->duration_;
dash->current_adaptationset_->segment_durations_ = dash->current_period_->segment_durations_;
dash->current_adaptationset_->segtpl_ = dash->current_period_->segtpl_;
dash->current_adaptationset_->startNumber_ = dash->current_period_->startNumber_;

for (; *attr;)
{
Expand Down Expand Up @@ -770,6 +835,31 @@ start(void *data, const char *el, const char **attr)
dash->segcount_ = 0;
dash->currentNode_ |= DASHTree::MPDNODE_ADAPTIONSET;
}
else if (strcmp(el, "SegmentTemplate") == 0)
{
dash->current_period_->startNumber_ = ParseSegmentTemplate(attr, dash->current_period_->base_url_, dash->current_period_->segtpl_);
dash->current_period_->timescale_ = dash->current_period_->segtpl_.timescale;
dash->currentNode_ |= DASHTree::MPDNODE_SEGMENTTEMPLATE;
}
else if (strcmp(el, "SegmentList") == 0)
{
for (; *attr;)
{
if (strcmp((const char*)*attr, "duration") == 0)
dash->current_period_->duration_ = atoi((const char*)*(attr + 1));
else if (strcmp((const char*)*attr, "timescale") == 0)
dash->current_period_->timescale_ = atoi((const char*)*(attr + 1));
attr += 2;
}
if (dash->current_period_->timescale_)
{
if (dash->current_period_->duration_)
dash->current_period_->segment_durations_.data.reserve(dash->estimate_segcount(
dash->current_period_->duration_,
dash->current_period_->timescale_));
dash->currentNode_ |= DASHTree::MPDNODE_SEGMENTLIST;
}
}
else if (strcmp(el, "BaseURL") == 0) // Inside Period
{
dash->strXMLText_.clear();
Expand All @@ -786,6 +876,7 @@ start(void *data, const char *el, const char **attr)
dash->current_period_ = new DASHTree::Period();
dash->current_period_->base_url_ = dash->base_url_;
dash->periods_.push_back(dash->current_period_);
dash->period_timelined_ = false;
dash->currentNode_ |= DASHTree::MPDNODE_PERIOD;
}
}
Expand Down Expand Up @@ -1134,6 +1225,19 @@ end(void *data, const char *el)
dash->currentNode_ &= ~DASHTree::MPDNODE_BASEURL;
}
}
else if (dash->currentNode_ & (DASHTree::MPDNODE_SEGMENTLIST | DASHTree::MPDNODE_SEGMENTTEMPLATE))
{
if (dash->currentNode_ & DASHTree::MPDNODE_SEGMENTTIMELINE)
{
if (strcmp(el, "SegmentTimeline") == 0)
dash->currentNode_ &= ~DASHTree::MPDNODE_SEGMENTTIMELINE;

}
else if (strcmp(el, "SegmentList") == 0)
dash->currentNode_ &= ~DASHTree::MPDNODE_SEGMENTLIST;
else if (strcmp(el, "SegmentTemplate") == 0)
dash->currentNode_ &= ~DASHTree::MPDNODE_SEGMENTTEMPLATE;
}
else if (strcmp(el, "Period") == 0)
{
dash->currentNode_ &= ~DASHTree::MPDNODE_PERIOD;
Expand Down

0 comments on commit 701f590

Please sign in to comment.