[vlc-commits] demux: adaptive: create description list for declaring es
Francois Cartegnie
git at videolan.org
Thu Feb 25 09:55:38 UTC 2021
vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Mon Jan 11 16:35:55 2021 +0100| [57a1fb0ee608afca54bc5e60ccda69027b9e3043] | committer: Francois Cartegnie
demux: adaptive: create description list for declaring es
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=57a1fb0ee608afca54bc5e60ccda69027b9e3043
---
modules/demux/Makefile.am | 2 +
modules/demux/adaptive/SegmentTracker.cpp | 15 +----
modules/demux/adaptive/SegmentTracker.hpp | 5 +-
modules/demux/adaptive/Streams.cpp | 51 ++------------
.../demux/adaptive/playlist/BaseRepresentation.cpp | 33 ++++++++++
.../demux/adaptive/playlist/BaseRepresentation.h | 3 +
.../demux/adaptive/playlist/CodecDescription.cpp | 77 ++++++++++++++++++++++
.../demux/adaptive/playlist/CodecDescription.hpp | 58 ++++++++++++++++
8 files changed, 181 insertions(+), 63 deletions(-)
diff --git a/modules/demux/Makefile.am b/modules/demux/Makefile.am
index c336255eca..48f5d7a97d 100644
--- a/modules/demux/Makefile.am
+++ b/modules/demux/Makefile.am
@@ -304,6 +304,8 @@ libvlc_adaptive_la_SOURCES = \
demux/adaptive/playlist/BasePlaylist.hpp \
demux/adaptive/playlist/BaseRepresentation.cpp \
demux/adaptive/playlist/BaseRepresentation.h \
+ demux/adaptive/playlist/CodecDescription.cpp \
+ demux/adaptive/playlist/CodecDescription.hpp \
demux/adaptive/playlist/CommonAttributesElements.cpp \
demux/adaptive/playlist/CommonAttributesElements.h \
demux/adaptive/playlist/ICanonicalUrl.hpp \
diff --git a/modules/demux/adaptive/SegmentTracker.cpp b/modules/demux/adaptive/SegmentTracker.cpp
index ffe4418212..84c4f257d8 100644
--- a/modules/demux/adaptive/SegmentTracker.cpp
+++ b/modules/demux/adaptive/SegmentTracker.cpp
@@ -194,24 +194,13 @@ StreamFormat SegmentTracker::getCurrentFormat() const
return StreamFormat();
}
-std::list<std::string> SegmentTracker::getCurrentCodecs() const
+void SegmentTracker::getCodecsDesc(CodecDescriptionList *descs) const
{
BaseRepresentation *rep = current.rep;
if(!rep)
rep = logic->getNextRepresentation(adaptationSet, nullptr);
if(rep)
- return rep->getCodecs();
- return std::list<std::string>();
-}
-
-const std::string & SegmentTracker::getStreamDescription() const
-{
- return adaptationSet->description.Get();
-}
-
-const std::string & SegmentTracker::getStreamLanguage() const
-{
- return adaptationSet->getLang();
+ rep->getCodecsDesc(descs);
}
const Role & SegmentTracker::getStreamRole() const
diff --git a/modules/demux/adaptive/SegmentTracker.hpp b/modules/demux/adaptive/SegmentTracker.hpp
index 0be108c7b4..3171e7ccf9 100644
--- a/modules/demux/adaptive/SegmentTracker.hpp
+++ b/modules/demux/adaptive/SegmentTracker.hpp
@@ -21,6 +21,7 @@
#define SEGMENTTRACKER_HPP
#include "StreamFormat.hpp"
+#include "playlist/CodecDescription.hpp"
#include "playlist/Role.hpp"
#include <vlc_common.h>
@@ -178,9 +179,7 @@ namespace adaptive
};
StreamFormat getCurrentFormat() const;
- std::list<std::string> getCurrentCodecs() const;
- const std::string & getStreamDescription() const;
- const std::string & getStreamLanguage() const;
+ void getCodecsDesc(CodecDescriptionList *) const;
const Role & getStreamRole() const;
void reset();
SegmentChunk* getNextChunk(bool, AbstractConnectionManager *);
diff --git a/modules/demux/adaptive/Streams.cpp b/modules/demux/adaptive/Streams.cpp
index 9cf5be89c2..46692e19ae 100644
--- a/modules/demux/adaptive/Streams.cpp
+++ b/modules/demux/adaptive/Streams.cpp
@@ -31,7 +31,6 @@
#include "playlist/SegmentChunk.hpp"
#include "plumbing/SourceStream.hpp"
#include "plumbing/CommandsQueue.hpp"
-#include "tools/FormatNamespace.hpp"
#include "tools/Debug.hpp"
#include <vlc_demux.h>
@@ -713,54 +712,12 @@ void AbstractStream::trackerEvent(const TrackerEvent &ev)
}
}
-static void add_codec_string_from_fourcc(vlc_fourcc_t fourcc,
- std::list<std::string> &codecs)
-{
- std::string codec;
- codec.insert(0, reinterpret_cast<const char *>(&fourcc), 4);
- codecs.push_back(codec);
-}
-
void AbstractStream::declaredCodecs()
{
- const std::string & streamDesc = segmentTracker->getStreamDescription();
- const std::string & streamLang = segmentTracker->getStreamLanguage();
- std::list<std::string> codecs = segmentTracker->getCurrentCodecs();
-
- if(codecs.empty())
- {
- const StreamFormat format = segmentTracker->getCurrentFormat();
- switch(format)
- {
- case StreamFormat::TTML:
- add_codec_string_from_fourcc(VLC_CODEC_TTML, codecs);
- break;
- case StreamFormat::WEBVTT:
- add_codec_string_from_fourcc(VLC_CODEC_WEBVTT, codecs);
- break;
- default:
- break;
- }
- }
-
- for(std::list<std::string>::const_iterator it = codecs.begin();
- it != codecs.end(); ++it)
- {
- FormatNamespace fnsp(*it);
-
- es_format_t fmt;
- es_format_Init(&fmt, fnsp.getFmt()->i_cat, fnsp.getFmt()->i_codec);
- es_format_Copy(&fmt, fnsp.getFmt());
-
- if(!streamLang.empty())
- fmt.psz_language = strdup(streamLang.c_str());
- if(!streamDesc.empty())
- fmt.psz_description = strdup(streamDesc.c_str());
-
- fakeEsOut()->declareEs( &fmt );
-
- es_format_Clean(&fmt);
- }
+ CodecDescriptionList descs;
+ segmentTracker->getCodecsDesc(&descs);
+ for(auto it = descs.cbegin(); it != descs.cend(); ++it)
+ fakeEsOut()->declareEs((*it)->getFmt());
}
FakeESOut::LockedFakeEsOut AbstractStream::fakeEsOut()
diff --git a/modules/demux/adaptive/playlist/BaseRepresentation.cpp b/modules/demux/adaptive/playlist/BaseRepresentation.cpp
index 1f31d6b159..1cee48bf56 100644
--- a/modules/demux/adaptive/playlist/BaseRepresentation.cpp
+++ b/modules/demux/adaptive/playlist/BaseRepresentation.cpp
@@ -87,6 +87,39 @@ void BaseRepresentation::addCodecs(const std::string &s)
codecs.push_back(*it);
}
+void BaseRepresentation::getCodecsDesc(CodecDescriptionList *desc) const
+{
+ std::list<std::string> codecs = getCodecs();
+ if(codecs.empty())
+ {
+ const StreamFormat format = getStreamFormat();
+ switch(format)
+ {
+ case StreamFormat::TTML:
+ codecs.push_front("stpp");
+ break;
+ case StreamFormat::WEBVTT:
+ codecs.push_front("wvtt");
+ break;
+ default:
+ break;
+ }
+ }
+
+ for(auto it = codecs.cbegin(); it != codecs.cend(); ++it)
+ {
+ CodecDescription *dsc = makeCodecDescription(*it);
+ dsc->setDescription(adaptationSet->description.Get());
+ dsc->setLanguage(adaptationSet->getLang());
+ desc->push_back(dsc);
+ }
+}
+
+CodecDescription * BaseRepresentation::makeCodecDescription(const std::string &codec) const
+{
+ return new CodecDescription(codec);
+}
+
bool BaseRepresentation::needsUpdate(uint64_t) const
{
return false;
diff --git a/modules/demux/adaptive/playlist/BaseRepresentation.h b/modules/demux/adaptive/playlist/BaseRepresentation.h
index e6b639fe62..1844536d39 100644
--- a/modules/demux/adaptive/playlist/BaseRepresentation.h
+++ b/modules/demux/adaptive/playlist/BaseRepresentation.h
@@ -29,6 +29,7 @@
#include <list>
#include "CommonAttributesElements.h"
+#include "CodecDescription.hpp"
#include "SegmentInformation.hpp"
#include "../StreamFormat.hpp"
@@ -61,6 +62,7 @@ namespace adaptive
void setBandwidth ( uint64_t bandwidth );
const std::list<std::string> & getCodecs () const;
void addCodecs (const std::string &);
+ void getCodecsDesc (CodecDescriptionList *) const;
bool consistentSegmentNumber () const;
virtual void pruneByPlaybackTime (vlc_tick_t) override;
@@ -86,6 +88,7 @@ namespace adaptive
vlc_tick_t *rangeEnd,
vlc_tick_t *rangeLength) const;
protected:
+ virtual CodecDescription * makeCodecDescription(const std::string &) const;
virtual bool validateCodec(const std::string &) const;
BaseAdaptationSet *adaptationSet;
uint64_t bandwidth;
diff --git a/modules/demux/adaptive/playlist/CodecDescription.cpp b/modules/demux/adaptive/playlist/CodecDescription.cpp
new file mode 100644
index 0000000000..43546cc962
--- /dev/null
+++ b/modules/demux/adaptive/playlist/CodecDescription.cpp
@@ -0,0 +1,77 @@
+/*
+ * CodecDescription.cpp
+ *****************************************************************************
+ * Copyright (C) 2021 - VideoLabs, VideoLAN and VLC Authors
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_es.h>
+
+#include "CodecDescription.hpp"
+#include "../tools/FormatNamespace.hpp"
+
+using namespace adaptive::playlist;
+
+CodecDescription::CodecDescription()
+{
+ es_format_Init(&fmt, UNKNOWN_ES, 0);
+}
+
+CodecDescription::CodecDescription(const std::string &codec)
+{
+ FormatNamespace fnsp(codec);
+ es_format_Init(&fmt, fnsp.getFmt()->i_cat, fnsp.getFmt()->i_codec);
+ es_format_Copy(&fmt, fnsp.getFmt());
+}
+
+CodecDescription::~CodecDescription()
+{
+ es_format_Clean(&fmt);
+}
+
+const es_format_t * CodecDescription::getFmt() const
+{
+ return &fmt;
+}
+
+void CodecDescription::setDescription(const std::string &d)
+{
+ free(fmt.psz_description);
+ fmt.psz_description = ::strdup(d.c_str());
+}
+
+void CodecDescription::setLanguage(const std::string &l)
+{
+ free(fmt.psz_language);
+ fmt.psz_language = ::strdup(l.c_str());
+}
+
+CodecDescriptionList::CodecDescriptionList()
+{
+
+}
+
+CodecDescriptionList::~CodecDescriptionList()
+{
+ while(!empty())
+ {
+ delete front();
+ pop_front();
+ }
+}
diff --git a/modules/demux/adaptive/playlist/CodecDescription.hpp b/modules/demux/adaptive/playlist/CodecDescription.hpp
new file mode 100644
index 0000000000..b0f5b7a714
--- /dev/null
+++ b/modules/demux/adaptive/playlist/CodecDescription.hpp
@@ -0,0 +1,58 @@
+/*
+ * CodecDescription.hpp
+ *****************************************************************************
+ * Copyright (C) 2021 - VideoLabs, VideoLAN and VLC Authors
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+#ifndef CODECDESCRIPTION_HPP
+#define CODECDESCRIPTION_HPP
+
+#include <vlc_es.h>
+#include <string>
+#include <list>
+
+namespace adaptive
+{
+ namespace playlist
+ {
+ class CodecDescription
+ {
+ public:
+ CodecDescription();
+ CodecDescription(const std::string &);
+ CodecDescription(const CodecDescription &) = delete;
+ void operator=(const CodecDescription&) = delete;
+ virtual ~CodecDescription();
+ const es_format_t *getFmt() const;
+ void setDescription(const std::string &);
+ void setLanguage(const std::string &);
+
+ protected:
+ es_format_t fmt;
+ };
+
+ class CodecDescriptionList : public std::list<CodecDescription *>
+ {
+ public:
+ CodecDescriptionList();
+ ~CodecDescriptionList();
+ CodecDescriptionList(const CodecDescriptionList &) = delete;
+ void operator=(const CodecDescriptionList&) = delete;
+ };
+ }
+}
+
+#endif // CODECDESCRIPTION_HPP
More information about the vlc-commits
mailing list