[vlc-commits] [Git][videolan/vlc][master] 3 commits: demux: adaptive: use enum class for format
François Cartegnie
gitlab at videolan.org
Thu Jun 3 07:35:57 UTC 2021
François Cartegnie pushed to branch master at VideoLAN / VLC
Commits:
7fd99fbf by Francois Cartegnie at 2021-06-02T22:01:15+00:00
demux: adaptive: use enum class for format
- - - - -
fb6354a1 by Francois Cartegnie at 2021-06-02T22:01:15+00:00
demux: hls: handle packed MP3 and AC-3
refs #25781
- - - - -
baca970d by Francois Cartegnie at 2021-06-02T22:01:15+00:00
demux: hls: add support for Ogg streams
Ignore the worst standard for the worse
refs #25781
- - - - -
11 changed files:
- modules/demux/adaptive/SegmentTracker.cpp
- modules/demux/adaptive/StreamFormat.cpp
- modules/demux/adaptive/StreamFormat.hpp
- modules/demux/adaptive/Streams.cpp
- modules/demux/adaptive/playlist/BaseRepresentation.cpp
- modules/demux/dash/DASHStream.cpp
- modules/demux/hls/HLSStreams.cpp
- modules/demux/hls/playlist/HLSRepresentation.cpp
- modules/demux/hls/playlist/Parser.cpp
- modules/demux/smooth/SmoothStream.cpp
- modules/demux/smooth/playlist/QualityLevel.cpp
Changes:
=====================================
modules/demux/adaptive/SegmentTracker.cpp
=====================================
@@ -119,7 +119,7 @@ SegmentTracker::SegmentTracker(SharedResources *res,
bufferingLogic = bl;
setAdaptationLogic(logic_);
adaptationSet = adaptSet;
- format = StreamFormat::UNKNOWN;
+ format = StreamFormat::Type::Unknown;
}
SegmentTracker::~SegmentTracker()
@@ -220,7 +220,7 @@ void SegmentTracker::reset()
next = Position();
resetChunksSequence();
initializing = true;
- format = StreamFormat::UNKNOWN;
+ format = StreamFormat::Type::Unknown;
}
SegmentTracker::ChunkEntry::ChunkEntry()
@@ -363,7 +363,7 @@ ChunkInterface * SegmentTracker::getNextChunk(bool switch_allowed,
/* advance or don't trigger duplicate events */
next = current = chunk.pos;
- if(format == StreamFormat(StreamFormat::UNSUPPORTED))
+ if(format == StreamFormat(StreamFormat::Type::Unsupported))
return nullptr; /* Can't return chunk because no demux will be created */
/* From this point chunk must be returned */
@@ -371,14 +371,14 @@ ChunkInterface * SegmentTracker::getNextChunk(bool switch_allowed,
StreamFormat chunkformat = chunk.chunk->getStreamFormat();
/* Wrap and probe format */
- if(chunkformat == StreamFormat(StreamFormat::UNKNOWN))
+ if(chunkformat == StreamFormat(StreamFormat::Type::Unknown))
{
ProbeableChunk *wrappedck = new ProbeableChunk(chunk.chunk);
const uint8_t *p_peek;
size_t i_peek = wrappedck->peek(&p_peek);
chunkformat = StreamFormat(p_peek, i_peek);
/* fallback on Mime type */
- if(chunkformat == StreamFormat(StreamFormat::UNKNOWN))
+ if(chunkformat == StreamFormat(StreamFormat::Type::Unknown))
format = StreamFormat(chunk.chunk->getContentType());
chunk.chunk->setStreamFormat(chunkformat);
returnedChunk = wrappedck;
@@ -386,7 +386,7 @@ ChunkInterface * SegmentTracker::getNextChunk(bool switch_allowed,
else returnedChunk = chunk.chunk;
if(chunkformat != format &&
- chunkformat != StreamFormat(StreamFormat::UNKNOWN))
+ chunkformat != StreamFormat(StreamFormat::Type::Unknown))
{
format = chunkformat;
notify(FormatChangedEvent(&format));
=====================================
modules/demux/adaptive/StreamFormat.cpp
=====================================
@@ -35,38 +35,44 @@ extern "C"
using namespace adaptive;
-StreamFormat::operator unsigned() const
+StreamFormat::operator StreamFormat::Type() const
{
- return formatid;
+ return type;
}
std::string StreamFormat::str() const
{
- switch(formatid)
+ switch(type)
{
- case MPEG2TS:
+ case Type::MPEG2TS:
return "TS";
- case MP4:
+ case Type::MP4:
return "MP4";
- case WEBVTT:
+ case Type::WebVTT:
return "WebVTT";
- case TTML:
+ case Type::TTML:
return "Timed Text";
- case PACKEDAAC:
+ case Type::PackedAAC:
return "Packed AAC";
- case WEBM:
+ case Type::PackedMP3:
+ return "Packed MP3";
+ case Type::PackedAC3:
+ return "Packed AC-3";
+ case Type::WebM:
return "WebM";
- case UNSUPPORTED:
+ case Type::Ogg:
+ return "Ogg";
+ case Type::Unsupported:
return "Unsupported";
default:
- case UNKNOWN:
+ case Type::Unknown:
return "Unknown";
}
}
-StreamFormat::StreamFormat( unsigned formatid_ )
+StreamFormat::StreamFormat( Type type_ )
{
- formatid = formatid_;
+ type = type_;
}
StreamFormat::StreamFormat( const std::string &mimetype )
@@ -74,22 +80,26 @@ StreamFormat::StreamFormat( const std::string &mimetype )
std::string mime = mimetype;
std::transform(mime.begin(), mime.end(), mime.begin(), ::tolower);
std::string::size_type pos = mime.find("/");
- formatid = UNKNOWN;
+ type = Type::Unknown;
if(pos != std::string::npos)
{
std::string tail = mime.substr(pos + 1);
if(tail == "mp4")
- formatid = StreamFormat::MP4;
+ type = StreamFormat::Type::MP4;
else if(tail == "aac")
- formatid = StreamFormat::PACKEDAAC;
+ type = StreamFormat::Type::PackedAAC;
+ else if(tail == "mpeg" || tail == "mp3")
+ type = StreamFormat::Type::PackedMP3;
+ else if(tail == "ac3")
+ type = StreamFormat::Type::PackedAC3;
else if (tail == "mp2t")
- formatid = StreamFormat::MPEG2TS;
+ type = StreamFormat::Type::MPEG2TS;
else if (tail == "vtt")
- formatid = StreamFormat::WEBVTT;
+ type = StreamFormat::Type::WebVTT;
else if (tail == "ttml+xml")
- formatid = StreamFormat::TTML;
+ type = StreamFormat::Type::TTML;
else if (tail == "webm")
- formatid = StreamFormat::WEBM;
+ type = StreamFormat::Type::WebM;
}
}
@@ -101,20 +111,22 @@ static int ID3Callback(uint32_t, const uint8_t *, size_t, void *)
StreamFormat::StreamFormat(const void *data_, size_t sz)
{
const uint8_t *data = reinterpret_cast<const uint8_t *>(data_);
- formatid = UNKNOWN;
+ type = Type::Unknown;
const char moov[] = "ftypmoovmoof";
if(sz > 188 && data[0] == 0x47 && data[188] == 0x47)
- formatid = StreamFormat::MPEG2TS;
+ type = StreamFormat::Type::MPEG2TS;
else if(sz > 8 && (!memcmp(&moov, &data[4], 4) ||
!memcmp(&moov[4], &data[4], 4) ||
!memcmp(&moov[8], &data[4], 4)))
- formatid = StreamFormat::MP4;
+ type = StreamFormat::Type::MP4;
else if(sz > 7 && !memcmp("WEBVTT", data, 6) &&
std::isspace(static_cast<unsigned char>(data[7])))
- formatid = StreamFormat::WEBVTT;
+ type = StreamFormat::Type::WebVTT;
else if(sz > 4 && !memcmp("\x1A\x45\xDF\xA3", data, 4))
- formatid = StreamFormat::WEBM;
+ type = StreamFormat::Type::WebM;
+ else if(sz > 4 && !memcmp("OggS", data, 4))
+ type = StreamFormat::Type::Ogg;
else /* Check Packet Audio formats */
{
/* It MUST have ID3 header, but HLS spec is an oxymoron */
@@ -130,7 +142,15 @@ StreamFormat::StreamFormat(const void *data_, size_t sz)
if(sz > 3 && (!memcmp("\xFF\xF1", data, 2) ||
!memcmp("\xFF\xF9", data, 2)))
{
- formatid = StreamFormat::PACKEDAAC;
+ type = StreamFormat::Type::PackedAAC;
+ }
+ else if(sz > 4 && data[0] == 0xFF && (data[1] & 0xE6) > 0xE0)
+ {
+ type = StreamFormat::Type::PackedMP3;
+ }
+ else if(sz > 4 && data[0] == 0x0b && data[1] == 0x77)
+ {
+ type = StreamFormat::Type::PackedAC3;
}
}
}
@@ -140,12 +160,22 @@ StreamFormat::~StreamFormat()
}
+bool StreamFormat::operator ==(Type t) const
+{
+ return type == t;
+}
+
+bool StreamFormat::operator !=(Type t) const
+{
+ return type != t;
+}
+
bool StreamFormat::operator ==(const StreamFormat &other) const
{
- return formatid == other.formatid;
+ return type == other.type;
}
bool StreamFormat::operator !=(const StreamFormat &other) const
{
- return formatid != other.formatid;
+ return type != other.type;
}
=====================================
modules/demux/adaptive/StreamFormat.hpp
=====================================
@@ -28,27 +28,35 @@ namespace adaptive
class StreamFormat
{
public:
- static const unsigned UNSUPPORTED = 0;
- static const unsigned MPEG2TS = 1;
- static const unsigned MP4 = 2;
- static const unsigned WEBVTT = 3;
- static const unsigned TTML = 4;
- static const unsigned PACKEDAAC = 5;
- static const unsigned WEBM = 6;
- static const unsigned UNKNOWN = 0xFF; /* will probe */
+ enum class Type
+ {
+ Unsupported,
+ MPEG2TS,
+ MP4,
+ WebM,
+ Ogg,
+ WebVTT,
+ TTML,
+ PackedAAC,
+ PackedMP3,
+ PackedAC3,
+ Unknown,
+ };
static const unsigned PEEK_SIZE = 4096;
- StreamFormat( unsigned = UNSUPPORTED );
+ StreamFormat( Type = Type::Unsupported );
explicit StreamFormat( const std::string &mime );
StreamFormat( const void *, size_t );
~StreamFormat();
- operator unsigned() const;
+ operator Type() const;
std::string str() const;
+ bool operator==(Type) const;
+ bool operator!=(Type) const;
bool operator==(const StreamFormat &) const;
bool operator!=(const StreamFormat &) const;
private:
- unsigned formatid;
+ Type type;
};
}
=====================================
modules/demux/adaptive/Streams.cpp
=====================================
@@ -42,7 +42,7 @@ using namespace adaptive::http;
AbstractStream::AbstractStream(demux_t * demux_)
{
p_realdemux = demux_;
- format = StreamFormat::UNKNOWN;
+ format = StreamFormat::Type::Unknown;
currentChunk = nullptr;
eof = false;
valid = true;
@@ -63,7 +63,7 @@ AbstractStream::AbstractStream(demux_t * demux_)
bool AbstractStream::init(const StreamFormat &format_, SegmentTracker *tracker, AbstractConnectionManager *conn)
{
/* Don't even try if not supported or already init */
- if((unsigned)format_ == StreamFormat::UNSUPPORTED || demuxersource)
+ if(format_ == StreamFormat::Type::Unsupported || demuxersource)
return false;
demuxersource = new (std::nothrow) BufferedChunksSourceStream( VLC_OBJECT(p_realdemux), this );
@@ -613,18 +613,18 @@ AbstractDemuxer *AbstractStream::newDemux(vlc_object_t *p_obj, const StreamForma
es_out_t *out, AbstractSourceStream *source) const
{
AbstractDemuxer *ret = nullptr;
- switch((unsigned)format)
+ switch(format)
{
- case StreamFormat::MP4:
+ case StreamFormat::Type::MP4:
ret = new Demuxer(p_obj, "mp4", out, source);
break;
- case StreamFormat::MPEG2TS:
+ case StreamFormat::Type::MPEG2TS:
ret = new Demuxer(p_obj, "ts", out, source);
break;
default:
- case StreamFormat::UNSUPPORTED:
+ case StreamFormat::Type::Unsupported:
break;
}
return ret;
@@ -662,7 +662,7 @@ void AbstractStream::trackerEvent(const TrackerEvent &ev)
{
if(!demuxer->bitstreamSwitchCompatible() ||
/* HLS variants can move from TS to Raw AAC */
- format == StreamFormat(StreamFormat::UNKNOWN) ||
+ format == StreamFormat(StreamFormat::Type::Unknown) ||
(event.next &&
!event.next->getAdaptationSet()->isBitSwitchable()))
needrestart = true;
=====================================
modules/demux/adaptive/playlist/BaseRepresentation.cpp
=====================================
@@ -96,10 +96,10 @@ void BaseRepresentation::getCodecsDesc(CodecDescriptionList *desc) const
const StreamFormat format = getStreamFormat();
switch(format)
{
- case StreamFormat::TTML:
+ case StreamFormat::Type::TTML:
codecs.push_front("stpp");
break;
- case StreamFormat::WEBVTT:
+ case StreamFormat::Type::WebVTT:
codecs.push_front("wvtt");
break;
default:
=====================================
modules/demux/dash/DASHStream.cpp
=====================================
@@ -39,27 +39,27 @@ AbstractDemuxer *DASHStream::newDemux(vlc_object_t *p_obj, const StreamFormat &f
es_out_t *out, AbstractSourceStream *source) const
{
AbstractDemuxer *ret = nullptr;
- switch((unsigned)format)
+ switch(format)
{
- case StreamFormat::MP4:
- case StreamFormat::MPEG2TS:
+ case StreamFormat::Type::MP4:
+ case StreamFormat::Type::MPEG2TS:
ret = AbstractStream::newDemux(p_obj, format, out, source);
break;
- case StreamFormat::WEBM:
+ case StreamFormat::Type::WebM:
ret = new Demuxer(p_obj, "mkv_trusted", out, source);
break;
- case StreamFormat::WEBVTT:
+ case StreamFormat::Type::WebVTT:
ret = new SlaveDemuxer(p_obj, "webvtt", out, source);
break;
- case StreamFormat::TTML:
+ case StreamFormat::Type::TTML:
ret = new SlaveDemuxer(p_obj, "ttml", out, source);
break;
default:
- case StreamFormat::UNSUPPORTED:
+ case StreamFormat::Type::Unsupported:
break;
}
=====================================
modules/demux/hls/HLSStreams.cpp
=====================================
@@ -128,24 +128,30 @@ AbstractDemuxer *HLSStream::newDemux(vlc_object_t *p_obj, const StreamFormat &fo
es_out_t *out, AbstractSourceStream *source) const
{
AbstractDemuxer *ret = nullptr;
- switch((unsigned)format)
+ switch(format)
{
- case StreamFormat::PACKEDAAC:
- ret = new Demuxer(p_obj, "aac", out, source);
+ case StreamFormat::Type::PackedAAC:
+ case StreamFormat::Type::PackedMP3:
+ case StreamFormat::Type::PackedAC3:
+ ret = new Demuxer(p_obj, "es", out, source);
break;
- case StreamFormat::MPEG2TS:
+ case StreamFormat::Type::MPEG2TS:
ret = new Demuxer(p_obj, "ts", out, source);
if(ret)
ret->setBitstreamSwitchCompatible(false); /* HLS and unique PAT/PMT versions */
break;
- case StreamFormat::MP4:
+ case StreamFormat::Type::MP4:
ret = AbstractStream::newDemux(p_obj, format, out, source);
break;
+ case StreamFormat::Type::Ogg:
+ ret = new Demuxer(p_obj, "ogg", out, source);
+ break;
+
/* Disabled until we can handle empty segments/cue and absolute time
- case StreamFormat::WEBVTT:
+ case StreamFormat::Type::WebVTT:
ret = new Demuxer(p_obj, "webvttstream", out, source);
if(ret)
ret->setRestartsOnEachSegment(true);
@@ -153,8 +159,8 @@ AbstractDemuxer *HLSStream::newDemux(vlc_object_t *p_obj, const StreamFormat &fo
*/
default:
- case StreamFormat::UNKNOWN:
- case StreamFormat::UNSUPPORTED:
+ case StreamFormat::Type::Unknown:
+ case StreamFormat::Type::Unsupported:
break;
}
return ret;
=====================================
modules/demux/hls/playlist/HLSRepresentation.cpp
=====================================
@@ -47,7 +47,7 @@ HLSRepresentation::HLSRepresentation ( BaseAdaptationSet *set ) :
b_failed = false;
lastUpdateTime = 0;
targetDuration = 0;
- streamFormat = StreamFormat::UNKNOWN;
+ streamFormat = StreamFormat::Type::Unknown;
}
HLSRepresentation::~HLSRepresentation ()
=====================================
modules/demux/hls/playlist/Parser.cpp
=====================================
@@ -556,11 +556,11 @@ M3U8 * M3U8Parser::parse(vlc_object_t *p_object, stream_t *p_stream, const std::
if(typeattr->value == "SUBTITLES")
{
altAdaptSet->setRole(Role(Role::ROLE_SUBTITLE));
- rep->streamFormat = StreamFormat(StreamFormat::UNSUPPORTED);
+ rep->streamFormat = StreamFormat(StreamFormat::Type::Unsupported);
}
else if(typeattr->value != "AUDIO" && typeattr->value != "VIDEO")
{
- rep->streamFormat = StreamFormat(StreamFormat::UNSUPPORTED);
+ rep->streamFormat = StreamFormat(StreamFormat::Type::Unsupported);
}
if(pair.second->getAttributeByName("LANGUAGE"))
=====================================
modules/demux/smooth/SmoothStream.cpp
=====================================
@@ -34,7 +34,7 @@ SmoothStream::SmoothStream(demux_t *demux)
AbstractDemuxer *SmoothStream::newDemux(vlc_object_t *p_obj, const StreamFormat &format,
es_out_t *out, AbstractSourceStream *source) const
{
- if((unsigned)format != StreamFormat::MP4)
+ if(format != StreamFormat::Type::MP4)
return nullptr;
return AbstractStream::newDemux(p_obj, format, out, source);
}
=====================================
modules/demux/smooth/playlist/QualityLevel.cpp
=====================================
@@ -50,7 +50,7 @@ QualityLevel::~QualityLevel ()
StreamFormat QualityLevel::getStreamFormat() const
{
- return StreamFormat(StreamFormat::MP4);
+ return StreamFormat(StreamFormat::Type::MP4);
}
CodecDescription * QualityLevel::makeCodecDescription(const std::string &) const
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/c68d89c46028f2a4b148f4fdb37f0c9878d84ba0...baca970d740ba35b4653d96fb57573e8c72b4783
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/c68d89c46028f2a4b148f4fdb37f0c9878d84ba0...baca970d740ba35b4653d96fb57573e8c72b4783
You're receiving this email because of your account on code.videolan.org.
More information about the vlc-commits
mailing list