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

demux: hls: set demux only from file extensions

we can no longer rely on codecs to guess format
parent a1b3900b
......@@ -77,13 +77,18 @@ void SegmentTracker::setAdaptationLogic(AbstractAdaptationLogic *logic_)
registerListener(logic);
}
StreamFormat SegmentTracker::initialFormat() const
StreamFormat SegmentTracker::getCurrentFormat() const
{
BaseRepresentation *rep = curRepresentation;
if(!rep)
rep = logic->getNextRepresentation(adaptationSet, NULL);
if(rep)
{
/* Ensure ephemere content is updated/loaded */
if(rep->needsUpdate())
(void) rep->runLocalUpdates(0, curNumber, false);
return rep->getStreamFormat();
}
return StreamFormat();
}
......@@ -167,6 +172,26 @@ SegmentChunk * SegmentTracker::getNextChunk(bool switch_allowed, HTTPConnectionM
curRepresentation->scheduleNextUpdate(next);
}
if(rep->getStreamFormat() != format)
{
/* Initial format ? */
if(format == StreamFormat(StreamFormat::UNSUPPORTED))
{
format = rep->getStreamFormat();
}
else
{
format = rep->getStreamFormat();
notify(SegmentTrackerEvent(&format)); /* Notify new demux format */
return NULL; /* Force current demux to end */
}
}
if(format == StreamFormat(StreamFormat::UNSUPPORTED))
{
return NULL; /* Can't return chunk because no demux will be created */
}
if(!init_sent)
{
init_sent = true;
......
......@@ -91,7 +91,7 @@ namespace adaptive
~SegmentTracker();
void setAdaptationLogic(AbstractAdaptationLogic *);
StreamFormat initialFormat() const;
StreamFormat getCurrentFormat() const;
bool segmentsListReady() const;
void reset();
SegmentChunk* getNextChunk(bool, HTTPConnectionManager *);
......
......@@ -274,7 +274,7 @@ AbstractStream::buffering_status AbstractStream::bufferize(mtime_t nz_deadline,
if(!demuxer)
{
format = segmentTracker->initialFormat();
format = segmentTracker->getCurrentFormat();
if(!startDemux())
{
/* If demux fails because of probing failure / wrong format*/
......
......@@ -58,9 +58,6 @@ AbstractDemuxer * HLSStream::createDemux(const StreamFormat &format)
AbstractDemuxer *ret = NULL;
switch((unsigned)format)
{
case StreamFormat::UNKNOWN:
ret = new Demuxer(p_realdemux, "any", fakeesout->getEsOut(), demuxersource);
break;
case StreamFormat::PACKEDAAC:
ret = new Demuxer(p_realdemux, "avformat", fakeesout->getEsOut(), demuxersource);
......
......@@ -73,37 +73,6 @@ static void releaseTagsList(std::list<Tag *> &list)
list.clear();
}
void M3U8Parser::setFormatFromCodecs(Representation *rep, const std::string codecsstring)
{
std::list<std::string> codecs;
std::list<std::string> tokens = Helper::tokenize(codecsstring, ',');
std::list<std::string>::const_iterator it;
for(it=tokens.begin(); it!=tokens.end(); ++it)
{
/* Truncate init data */
std::size_t pos = (*it).find_first_of('.', 0);
if(pos != std::string::npos)
codecs.push_back((*it).substr(0, pos));
else
codecs.push_back(*it);
}
if(!codecs.empty())
{
if(codecs.size() == 1)
{
std::string codec = codecs.front();
transform(codec.begin(), codec.end(), codec.begin(), (int (*)(int))std::tolower);
if(codec == "mp4a")
rep->streamFormat = StreamFormat(StreamFormat::PACKEDAAC);
}
else
{
rep->streamFormat = StreamFormat(StreamFormat::MPEG2TS);
}
}
}
void M3U8Parser::setFormatFromExtension(Representation *rep, const std::string &filename)
{
std::size_t pos = filename.find_last_of('.');
......@@ -115,10 +84,14 @@ void M3U8Parser::setFormatFromExtension(Representation *rep, const std::string &
{
rep->streamFormat = StreamFormat(StreamFormat::PACKEDAAC);
}
else if(extension == "ts" || extension == "mp2t" || extension == "mpeg")
else if(extension == "ts" || extension == "mp2t" || extension == "mpeg" || extension == "m2ts")
{
rep->streamFormat = StreamFormat(StreamFormat::MPEG2TS);
}
else
{
rep->streamFormat = StreamFormat(StreamFormat::UNSUPPORTED);
}
}
}
......@@ -126,7 +99,6 @@ Representation * M3U8Parser::createRepresentation(BaseAdaptationSet *adaptSet, c
{
const Attribute *uriAttr = tag->getAttributeByName("URI");
const Attribute *bwAttr = tag->getAttributeByName("BANDWIDTH");
const Attribute *codecsAttr = tag->getAttributeByName("CODECS");
const Attribute *resAttr = tag->getAttributeByName("RESOLUTION");
Representation *rep = new (std::nothrow) Representation(adaptSet);
......@@ -156,9 +128,6 @@ Representation * M3U8Parser::createRepresentation(BaseAdaptationSet *adaptSet, c
if(bwAttr)
rep->setBandwidth(bwAttr->decimal());
if(codecsAttr)
setFormatFromCodecs(rep, codecsAttr->quotedString());
if(resAttr)
{
std::pair<int, int> res = resAttr->getResolution();
......
......@@ -63,7 +63,6 @@ namespace hls
void createAndFillRepresentation(vlc_object_t *, BaseAdaptationSet *,
const AttributesTag *, const std::list<Tag *>&);
void parseSegments(vlc_object_t *, Representation *, const std::list<Tag *>&);
void setFormatFromCodecs(Representation *, const std::string);
void setFormatFromExtension(Representation *rep, const std::string &);
std::list<Tag *> parseEntries(stream_t *);
};
......
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