[vlc-commits] demux: smooth: move smooth specific codec parameters to own class

Francois Cartegnie git at videolan.org
Thu Feb 25 09:55:37 UTC 2021


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Mon Jan 11 15:53:09 2021 +0100| [a51fedf5a7c4b1522140be3da7373e7dff050df7] | committer: Francois Cartegnie

demux: smooth: move smooth specific codec parameters to own class

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=a51fedf5a7c4b1522140be3da7373e7dff050df7
---

 modules/demux/Makefile.am                          |   2 +
 modules/demux/smooth/playlist/CodecParameters.cpp  | 202 ++++++++++++++++++++
 modules/demux/smooth/playlist/CodecParameters.hpp  |  60 ++++++
 .../demux/smooth/playlist/ForgedInitSegment.cpp    | 206 ++-------------------
 .../demux/smooth/playlist/ForgedInitSegment.hpp    |  21 +--
 modules/demux/smooth/playlist/QualityLevel.cpp     |  10 +
 modules/demux/smooth/playlist/QualityLevel.hpp     |   7 +
 modules/demux/smooth/playlist/SmoothParser.cpp     |  53 +++---
 8 files changed, 328 insertions(+), 233 deletions(-)

diff --git a/modules/demux/Makefile.am b/modules/demux/Makefile.am
index 6e2b5bfa00..c336255eca 100644
--- a/modules/demux/Makefile.am
+++ b/modules/demux/Makefile.am
@@ -466,6 +466,8 @@ libvlc_adaptive_la_SOURCES += meta_engine/ID3Meta.h
 libvlc_adaptive_la_SOURCES += \
     demux/smooth/mp4/SmoothIndexReader.cpp \
     demux/smooth/mp4/SmoothIndexReader.hpp \
+    demux/smooth/playlist/CodecParameters.cpp \
+    demux/smooth/playlist/CodecParameters.hpp \
     demux/smooth/playlist/ForgedInitSegment.hpp \
     demux/smooth/playlist/ForgedInitSegment.cpp \
     demux/smooth/playlist/Manifest.hpp \
diff --git a/modules/demux/smooth/playlist/CodecParameters.cpp b/modules/demux/smooth/playlist/CodecParameters.cpp
new file mode 100644
index 0000000000..f95122a2a0
--- /dev/null
+++ b/modules/demux/smooth/playlist/CodecParameters.cpp
@@ -0,0 +1,202 @@
+/*
+ * CodecParameters.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 "CodecParameters.hpp"
+
+using namespace smooth::playlist;
+
+CodecParameters::CodecParameters()
+{
+    formatex.cbSize = 0;
+    formatex.nAvgBytesPerSec = 0;
+    formatex.nBlockAlign = 0;
+    formatex.nChannels = 0;
+    formatex.nSamplesPerSec = 0;
+    formatex.wBitsPerSample = 0;
+    formatex.wFormatTag = 0;
+    fourcc = 0;
+    es_type = UNKNOWN_ES;
+}
+
+CodecParameters::~CodecParameters()
+{}
+
+static void HexDecode(const std::string &s, std::vector<uint8_t> &v)
+{
+    v.resize(s.size() / 2);
+    for(std::vector<uint8_t>::size_type i=0; i<v.size(); i++)
+        v[i] = std::strtoul(s.substr(i*2, 2).c_str(), nullptr, 16);
+}
+
+void CodecParameters::setCodecPrivateData(const std::string &extra)
+{
+    HexDecode(extra, extradata);
+    if(fourcc == VLC_CODEC_WMAP)
+    {
+        //fromWaveFormatEx(const std::string &extra);
+    }
+}
+
+void CodecParameters::setWaveFormatEx(const std::string &waveformat)
+{
+    std::vector<uint8_t> decoded;
+    HexDecode(waveformat, decoded);
+    fromWaveFormatEx(decoded);
+}
+
+void CodecParameters::setChannels(uint16_t i)
+{
+    formatex.nChannels = i;
+}
+
+void CodecParameters::setPacketSize(uint16_t i)
+{
+    formatex.nBlockAlign = i;
+}
+
+void CodecParameters::setSamplingRate(uint32_t i)
+{
+    formatex.nSamplesPerSec = i;
+}
+
+void CodecParameters::setBitsPerSample(uint16_t i)
+{
+    formatex.wBitsPerSample = i;
+}
+
+void CodecParameters::setAudioTag(uint16_t i)
+{
+    wf_tag_to_fourcc(i, &fourcc, nullptr);
+}
+
+static void FillExtradata(es_format_t *fmt, const std::vector<uint8_t> &extradata)
+{
+    if(extradata.size())
+    {
+        free(fmt->p_extra);
+        fmt->i_extra = 0;
+        fmt->p_extra = malloc(extradata.size());
+        if(fmt->p_extra)
+        {
+            memcpy(fmt->p_extra, &extradata[0], extradata.size());
+            fmt->i_extra = extradata.size();
+        }
+    }
+}
+
+void CodecParameters::initAndFillEsFmt(es_format_t *fmt) const
+{
+    es_format_Init(fmt, es_type, fourcc);
+    fmt->i_original_fourcc = fmt->i_codec;
+    switch(fmt->i_cat)
+    {
+        case VIDEO_ES:
+            if( fmt->i_codec == VLC_FOURCC( 'A', 'V', 'C', '1' ) ||
+                fmt->i_codec == VLC_FOURCC( 'A', 'V', 'C', 'B' ) ||
+                fmt->i_codec == VLC_FOURCC( 'H', '2', '6', '4' ) )
+            {
+                fmt->i_codec = VLC_CODEC_H264;
+            }
+            else if( fmt->i_codec == VLC_FOURCC( 'W', 'V', 'C', '1' ) )
+            {
+                fmt->i_codec = VLC_CODEC_VC1;
+//                fmt->video.i_bits_per_pixel = 0x18; // No clue why this was set in smooth streamfilter
+            }
+
+            FillExtradata(fmt, extradata);
+            break;
+
+        case AUDIO_ES:
+            fmt->audio.i_channels = formatex.nChannels;
+            fmt->audio.i_rate = formatex.nSamplesPerSec;
+            fmt->audio.i_bitspersample = formatex.wBitsPerSample;
+            fmt->audio.i_blockalign = formatex.nBlockAlign;
+            fmt->i_bitrate = formatex.nAvgBytesPerSec * 8; // FIXME (use bitrate) ?
+
+            FillExtradata(fmt, extradata);
+            break;
+
+        case SPU_ES:
+            break;
+
+        default:
+            break;
+    }
+}
+
+void CodecParameters::setFourCC(const std::string &fcc)
+{
+    if(fcc.size() == 4)
+    {
+        fourcc = VLC_FOURCC(fcc[0], fcc[1], fcc[2], fcc[3]);
+        switch(fourcc)
+        {
+            case VLC_FOURCC( 'A', 'V', 'C', '1' ):
+            case VLC_FOURCC( 'A', 'V', 'C', 'B' ):
+            case VLC_FOURCC( 'H', '2', '6', '4' ):
+            case VLC_FOURCC( 'W', 'V', 'C', '1' ):
+                es_type = VIDEO_ES;
+                break;
+            case VLC_FOURCC( 'T', 'T', 'M', 'L' ):
+                es_type = SPU_ES;
+                break;
+            case VLC_FOURCC( 'A', 'A', 'C', 'L' ):
+            case VLC_FOURCC( 'W', 'M', 'A', 'P' ):
+            default:
+                es_type = AUDIO_ES;
+                break;
+        }
+    }
+}
+
+void CodecParameters::fromWaveFormatEx(const std::vector<uint8_t> &data)
+{
+    if(data.size() >= sizeof(WAVEFORMATEX))
+    {
+        formatex.wFormatTag = GetWLE(&data[0]);
+        wf_tag_to_fourcc(formatex.wFormatTag, &fourcc, nullptr);
+        formatex.nChannels = GetWLE(&data[2]);
+        formatex.nSamplesPerSec = GetDWLE(&data[4]);
+        formatex.nAvgBytesPerSec = GetDWLE(&data[8]);
+        formatex.nBlockAlign = GetWLE(&data[12]);
+        formatex.wBitsPerSample = GetWLE(&data[14]);
+        formatex.cbSize = GetWLE(&data[16]);
+        if(data.size() > sizeof(WAVEFORMATEX))
+        {
+            formatex.cbSize = std::min(data.size() - sizeof(WAVEFORMATEX),
+                                       (std::vector<uint8_t>::size_type) formatex.cbSize);
+            if(formatex.cbSize)
+            {
+                extradata.resize(formatex.cbSize);
+                memcpy(&extradata[0], &data[sizeof(WAVEFORMATEX)], formatex.cbSize);
+            }
+        }
+        es_type = AUDIO_ES;
+    }
+}
+
+void CodecParameters::fromVideoInfoHeader(const std::vector<uint8_t> &)
+{
+//    VIDEOINFOHEADER
+    es_type = VIDEO_ES;
+}
diff --git a/modules/demux/smooth/playlist/CodecParameters.hpp b/modules/demux/smooth/playlist/CodecParameters.hpp
new file mode 100644
index 0000000000..f45bb2e670
--- /dev/null
+++ b/modules/demux/smooth/playlist/CodecParameters.hpp
@@ -0,0 +1,60 @@
+/*
+ * CodecParameters.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 CODECPARAMETERS_HPP
+#define CODECPARAMETERS_HPP
+
+#include <vlc_es.h>
+#include <vlc_codecs.h>
+
+#include <string>
+#include <vector>
+
+namespace smooth
+{
+    namespace playlist
+    {
+        class CodecParameters
+        {
+            public:
+                CodecParameters();
+                ~CodecParameters();
+                void setFourCC(const std::string &);
+                void setWaveFormatEx(const std::string &);
+                void setCodecPrivateData(const std::string &);
+                void setChannels(uint16_t);
+                void setPacketSize(uint16_t);
+                void setSamplingRate(uint32_t);
+                void setBitsPerSample(uint16_t);
+                void setAudioTag(uint16_t);
+                void initAndFillEsFmt(es_format_t *) const;
+
+                std::vector<uint8_t> extradata;
+                WAVEFORMATEX formatex;
+                vlc_fourcc_t fourcc;
+                enum es_format_category_e es_type;
+
+            private:
+                void fromWaveFormatEx(const std::vector<uint8_t> &);
+                void fromVideoInfoHeader(const std::vector<uint8_t> &);
+        };
+    }
+}
+
+#endif // CODECPARAMETERS_HPP
diff --git a/modules/demux/smooth/playlist/ForgedInitSegment.cpp b/modules/demux/smooth/playlist/ForgedInitSegment.cpp
index b858919576..4c62d632a7 100644
--- a/modules/demux/smooth/playlist/ForgedInitSegment.cpp
+++ b/modules/demux/smooth/playlist/ForgedInitSegment.cpp
@@ -24,6 +24,8 @@
 #include "ForgedInitSegment.hpp"
 #include "MemoryChunk.hpp"
 #include "../../adaptive/playlist/SegmentChunk.hpp"
+#include "QualityLevel.hpp"
+#include "CodecParameters.hpp"
 
 #include <vlc_common.h>
 
@@ -48,118 +50,13 @@ ForgedInitSegment::ForgedInitSegment(ICanonicalUrl *parent,
 {
     type = type_;
     duration.Set(duration_);
-    extradata = nullptr;
-    i_extradata = 0;
     timescale = timescale_;
-    formatex.cbSize = 0;
-    formatex.nAvgBytesPerSec = 0;
-    formatex.nBlockAlign = 0;
-    formatex.nChannels = 0;
-    formatex.nSamplesPerSec = 0;
-    formatex.wBitsPerSample = 0;
-    formatex.wFormatTag = 0;
     width = height = 0;
-    fourcc = 0;
-    es_type = UNKNOWN_ES;
     track_id = 1;
 }
 
 ForgedInitSegment::~ForgedInitSegment()
 {
-    free(extradata);
-}
-
-static uint8_t *HexDecode(const std::string &s, size_t *decoded_size)
-{
-    *decoded_size = s.size() / 2;
-    uint8_t *data = (uint8_t *) malloc(*decoded_size);
-    if(data)
-    {
-        for(size_t i=0; i<*decoded_size; i++)
-            data[i] = std::strtoul(s.substr(i*2, 2).c_str(), nullptr, 16);
-    }
-    return data;
-}
-
-void ForgedInitSegment::fromWaveFormatEx(const uint8_t *p_data, size_t i_data)
-{
-    if(i_data >= sizeof(WAVEFORMATEX))
-    {
-        formatex.wFormatTag = GetWLE(p_data);
-        wf_tag_to_fourcc(formatex.wFormatTag, &fourcc, nullptr);
-        formatex.nChannels = GetWLE(&p_data[2]);
-        formatex.nSamplesPerSec = GetDWLE(&p_data[4]);
-        formatex.nAvgBytesPerSec = GetDWLE(&p_data[8]);
-        formatex.nBlockAlign = GetWLE(&p_data[12]);
-        formatex.wBitsPerSample = GetWLE(&p_data[14]);
-        formatex.cbSize = GetWLE(&p_data[16]);
-        if(i_data > sizeof(WAVEFORMATEX))
-        {
-            if(extradata)
-            {
-                free(extradata);
-                extradata = nullptr;
-                i_extradata = 0;
-            }
-            formatex.cbSize = __MIN(i_data - sizeof(WAVEFORMATEX), formatex.cbSize);
-            extradata = (uint8_t*)malloc(formatex.cbSize);
-            if(extradata)
-            {
-                memcpy(extradata, &p_data[sizeof(WAVEFORMATEX)], formatex.cbSize);
-                i_extradata = formatex.cbSize;
-            }
-        }
-        es_type = AUDIO_ES;
-    }
-}
-
-void ForgedInitSegment::fromVideoInfoHeader(const uint8_t *, size_t)
-{
-//    VIDEOINFOHEADER
-    es_type = VIDEO_ES;
-}
-
-void ForgedInitSegment::setWaveFormatEx(const std::string &waveformat)
-{
-    size_t i_data;
-    uint8_t *p_data = HexDecode(waveformat, &i_data);
-    fromWaveFormatEx(p_data, i_data);
-    free(p_data);
-}
-
-void ForgedInitSegment::setCodecPrivateData(const std::string &extra)
-{
-    if(extradata)
-    {
-        free(extradata);
-        extradata = nullptr;
-        i_extradata = 0;
-    }
-    extradata = HexDecode(extra, &i_extradata);
-    if(fourcc == VLC_CODEC_WMAP)
-    {
-        //fromWaveFormatEx(const std::string &extra);
-    }
-}
-
-void ForgedInitSegment::setChannels(uint16_t i)
-{
-    formatex.nChannels = i;
-}
-
-void ForgedInitSegment::setPacketSize(uint16_t i)
-{
-    formatex.nBlockAlign = i;
-}
-
-void ForgedInitSegment::setSamplingRate(uint32_t i)
-{
-    formatex.nSamplesPerSec = i;
-}
-
-void ForgedInitSegment::setBitsPerSample(uint16_t i)
-{
-    formatex.wBitsPerSample = i;
 }
 
 void ForgedInitSegment::setVideoSize(unsigned w, unsigned h)
@@ -173,100 +70,21 @@ void ForgedInitSegment::setTrackID(unsigned i)
     track_id = i;
 }
 
-void ForgedInitSegment::setAudioTag(uint16_t i)
-{
-    wf_tag_to_fourcc(i, &fourcc, nullptr);
-}
-
-void ForgedInitSegment::setFourCC(const std::string &fcc)
-{
-    if(fcc.size() == 4)
-    {
-        fourcc = VLC_FOURCC(fcc[0], fcc[1], fcc[2], fcc[3]);
-        switch(fourcc)
-        {
-            case VLC_FOURCC( 'A', 'V', 'C', '1' ):
-            case VLC_FOURCC( 'A', 'V', 'C', 'B' ):
-            case VLC_FOURCC( 'H', '2', '6', '4' ):
-            case VLC_FOURCC( 'W', 'V', 'C', '1' ):
-                es_type = VIDEO_ES;
-                break;
-            case VLC_FOURCC( 'T', 'T', 'M', 'L' ):
-                es_type = SPU_ES;
-                break;
-            case VLC_FOURCC( 'A', 'A', 'C', 'L' ):
-            case VLC_FOURCC( 'W', 'M', 'A', 'P' ):
-            default:
-                es_type = AUDIO_ES;
-                break;
-        }
-    }
-}
-
 void ForgedInitSegment::setLanguage(const std::string &lang)
 {
     language = lang;
 }
 
-block_t * ForgedInitSegment::buildMoovBox()
+block_t * ForgedInitSegment::buildMoovBox(const CodecParameters &codecparameters)
 {
     es_format_t fmt;
-    es_format_Init(&fmt, es_type, vlc_fourcc_GetCodec(es_type, fourcc));
-    fmt.i_original_fourcc = fourcc;
-    switch(es_type)
+    codecparameters.initAndFillEsFmt(&fmt);
+    if(fmt.i_cat == VIDEO_ES)
     {
-        case VIDEO_ES:
-            if( fourcc == VLC_FOURCC( 'A', 'V', 'C', '1' ) ||
-                fourcc == VLC_FOURCC( 'A', 'V', 'C', 'B' ) ||
-                fourcc == VLC_FOURCC( 'H', '2', '6', '4' ) )
-            {
-                fmt.i_codec = VLC_CODEC_H264;
-            }
-            else if( fourcc == VLC_FOURCC( 'W', 'V', 'C', '1' ) )
-            {
-                fmt.i_codec = VLC_CODEC_VC1;
-//                fmt.video.i_bits_per_pixel = 0x18; // No clue why this was set in smooth streamfilter
-            }
-
-            fmt.video.i_width = width;
-            fmt.video.i_height = height;
-            fmt.video.i_visible_width = width;
-            fmt.video.i_visible_height = height;
-
-            if(i_extradata && extradata)
-            {
-                fmt.p_extra = malloc(i_extradata);
-                if(fmt.p_extra)
-                {
-                    memcpy(fmt.p_extra, extradata, i_extradata);
-                    fmt.i_extra = i_extradata;
-                }
-            }
-            break;
-
-        case AUDIO_ES:
-            fmt.audio.i_channels = formatex.nChannels;
-            fmt.audio.i_rate = formatex.nSamplesPerSec;
-            fmt.audio.i_bitspersample = formatex.wBitsPerSample;
-            fmt.audio.i_blockalign = formatex.nBlockAlign;
-            fmt.i_bitrate = formatex.nAvgBytesPerSec * 8; // FIXME (use bitrate) ?
-
-            if(i_extradata && extradata)
-            {
-                fmt.p_extra = malloc(i_extradata);
-                if(fmt.p_extra)
-                {
-                    memcpy(fmt.p_extra, extradata, i_extradata);
-                    fmt.i_extra = i_extradata;
-                }
-            }
-            break;
-
-        case SPU_ES:
-            break;
-
-        default:
-            break;
+        fmt.video.i_width = width;
+        fmt.video.i_height = height;
+        fmt.video.i_visible_width = width;
+        fmt.video.i_visible_height = height;
     }
 
     if(!language.empty())
@@ -319,7 +137,11 @@ block_t * ForgedInitSegment::buildMoovBox()
 SegmentChunk* ForgedInitSegment::toChunk(SharedResources *, AbstractConnectionManager *,
                                          size_t, BaseRepresentation *rep)
 {
-    block_t *moov = buildMoovBox();
+    QualityLevel *lvl = dynamic_cast<QualityLevel *>(rep);
+    if(lvl == nullptr)
+        return nullptr;
+
+    block_t *moov = buildMoovBox(lvl->getCodecParameters());
     if(moov)
     {
         MemoryChunkSource *source = new (std::nothrow) MemoryChunkSource(moov);
diff --git a/modules/demux/smooth/playlist/ForgedInitSegment.hpp b/modules/demux/smooth/playlist/ForgedInitSegment.hpp
index f2cb65d393..a22664c407 100644
--- a/modules/demux/smooth/playlist/ForgedInitSegment.hpp
+++ b/modules/demux/smooth/playlist/ForgedInitSegment.hpp
@@ -21,6 +21,7 @@
 #define FORGEDINITSEGMENT_HPP
 
 #include "../../adaptive/playlist/Segment.h"
+#include "CodecParameters.hpp"
 
 #include <vlc_es.h>
 #include <vlc_codecs.h>
@@ -33,6 +34,8 @@ namespace smooth
         using namespace adaptive::playlist;
         using namespace adaptive::http;
 
+        class CodecParameters;
+
         class ForgedInitSegment : public InitSegment
         {
             public:
@@ -41,31 +44,15 @@ namespace smooth
                 virtual ~ForgedInitSegment();
                 virtual SegmentChunk* toChunk(SharedResources *, AbstractConnectionManager *,
                                               size_t, BaseRepresentation *) override;
-                void setWaveFormatEx(const std::string &);
-                void setCodecPrivateData(const std::string &);
-                void setChannels(uint16_t);
-                void setPacketSize(uint16_t);
-                void setSamplingRate(uint32_t);
-                void setBitsPerSample(uint16_t);
                 void setVideoSize(unsigned w, unsigned h);
-                void setFourCC(const std::string &);
-                void setAudioTag(uint16_t);
                 void setTrackID(unsigned);
                 void setLanguage(const std::string &);
 
             private:
-                void fromWaveFormatEx(const uint8_t *p_data, size_t i_data);
-                void fromVideoInfoHeader(const uint8_t *p_data, size_t i_data);
-                block_t * buildMoovBox();
-                std::string data;
+                block_t * buildMoovBox(const CodecParameters &);
                 std::string type;
                 std::string language;
-                uint8_t *extradata;
-                size_t   i_extradata;
-                WAVEFORMATEX formatex;
                 unsigned width, height;
-                vlc_fourcc_t fourcc;
-                enum es_format_category_e es_type;
                 unsigned track_id;
                 Timescale timescale;
         };
diff --git a/modules/demux/smooth/playlist/QualityLevel.cpp b/modules/demux/smooth/playlist/QualityLevel.cpp
index 83d08c5664..5bb1c46ee8 100644
--- a/modules/demux/smooth/playlist/QualityLevel.cpp
+++ b/modules/demux/smooth/playlist/QualityLevel.cpp
@@ -91,3 +91,13 @@ std::string QualityLevel::contextualize(size_t number, const std::string &compon
 
     return ret;
 }
+
+const CodecParameters & QualityLevel::getCodecParameters() const
+{
+    return codecParameters;
+}
+
+void QualityLevel::setCodecParameters(const CodecParameters &c)
+{
+    codecParameters = c;
+}
diff --git a/modules/demux/smooth/playlist/QualityLevel.hpp b/modules/demux/smooth/playlist/QualityLevel.hpp
index 6e9c3d4623..afea48d4fb 100644
--- a/modules/demux/smooth/playlist/QualityLevel.hpp
+++ b/modules/demux/smooth/playlist/QualityLevel.hpp
@@ -22,6 +22,7 @@
 
 #include "../../adaptive/playlist/SegmentBaseType.hpp"
 #include "../../adaptive/playlist/BaseRepresentation.h"
+#include "CodecParameters.hpp"
 
 namespace adaptive
 {
@@ -51,6 +52,12 @@ namespace smooth
                 /* for segment templates */
                 virtual std::string contextualize(size_t, const std::string &,
                                                   const SegmentTemplate *) const override;
+
+                void setCodecParameters( const CodecParameters & );
+                const CodecParameters & getCodecParameters() const;
+
+            protected:
+                CodecParameters codecParameters;
         };
     }
 }
diff --git a/modules/demux/smooth/playlist/SmoothParser.cpp b/modules/demux/smooth/playlist/SmoothParser.cpp
index 8e1af33332..5d1a56759b 100644
--- a/modules/demux/smooth/playlist/SmoothParser.cpp
+++ b/modules/demux/smooth/playlist/SmoothParser.cpp
@@ -27,6 +27,7 @@
 #include "QualityLevel.hpp"
 #include "ForgedInitSegment.hpp"
 #include "SmoothSegment.hpp"
+#include "CodecParameters.hpp"
 #include "../../adaptive/playlist/BasePeriod.h"
 #include "../../adaptive/playlist/BaseAdaptationSet.h"
 #include "../../adaptive/playlist/SegmentTimeline.h"
@@ -167,6 +168,34 @@ static void ParseQualityLevel(BaseAdaptationSet *adaptSet, Node *qualNode, const
         if(qualNode->hasAttribute("FourCC"))
             rep->addCodecs(qualNode->getAttributeValue("FourCC"));
 
+        CodecParameters params;
+
+        if(qualNode->hasAttribute("FourCC"))
+            params.setFourCC(qualNode->getAttributeValue("FourCC"));
+
+        if(qualNode->hasAttribute("PacketSize"))
+            params.setPacketSize(Integer<uint16_t>(qualNode->getAttributeValue("PacketSize")));
+
+        if(qualNode->hasAttribute("Channels"))
+            params.setChannels(Integer<uint16_t>(qualNode->getAttributeValue("Channels")));
+
+        if(qualNode->hasAttribute("SamplingRate"))
+            params.setSamplingRate(Integer<uint32_t>(qualNode->getAttributeValue("SamplingRate")));
+
+        if(qualNode->hasAttribute("BitsPerSample"))
+            params.setBitsPerSample(Integer<uint32_t>(qualNode->getAttributeValue("BitsPerSample")));
+
+        if(qualNode->hasAttribute("CodecPrivateData"))
+            params.setCodecPrivateData(qualNode->getAttributeValue("CodecPrivateData"));
+
+        if(qualNode->hasAttribute("AudioTag"))
+            params.setAudioTag(Integer<uint16_t>(qualNode->getAttributeValue("AudioTag")));
+
+        if(qualNode->hasAttribute("WaveFormatEx"))
+            params.setWaveFormatEx(qualNode->getAttributeValue("WaveFormatEx"));
+
+        rep->setCodecParameters(params);
+
         ForgedInitSegment *initSegment = new (std::nothrow)
                 ForgedInitSegment(rep, type,
                                   timescale,
@@ -181,30 +210,6 @@ static void ParseQualityLevel(BaseAdaptationSet *adaptSet, Node *qualNode, const
             if(rep->getWidth() > 0 && rep->getHeight() > 0)
                 initSegment->setVideoSize(rep->getWidth(), rep->getHeight());
 
-            if(qualNode->hasAttribute("FourCC"))
-                initSegment->setFourCC(qualNode->getAttributeValue("FourCC"));
-
-            if(qualNode->hasAttribute("PacketSize"))
-                initSegment->setPacketSize(Integer<uint16_t>(qualNode->getAttributeValue("PacketSize")));
-
-            if(qualNode->hasAttribute("Channels"))
-                initSegment->setChannels(Integer<uint16_t>(qualNode->getAttributeValue("Channels")));
-
-            if(qualNode->hasAttribute("SamplingRate"))
-                initSegment->setSamplingRate(Integer<uint32_t>(qualNode->getAttributeValue("SamplingRate")));
-
-            if(qualNode->hasAttribute("BitsPerSample"))
-                initSegment->setBitsPerSample(Integer<uint32_t>(qualNode->getAttributeValue("BitsPerSample")));
-
-            if(qualNode->hasAttribute("CodecPrivateData"))
-                initSegment->setCodecPrivateData(qualNode->getAttributeValue("CodecPrivateData"));
-
-            if(qualNode->hasAttribute("AudioTag"))
-                initSegment->setAudioTag(Integer<uint16_t>(qualNode->getAttributeValue("AudioTag")));
-
-            if(qualNode->hasAttribute("WaveFormatEx"))
-                initSegment->setWaveFormatEx(qualNode->getAttributeValue("WaveFormatEx"));
-
             initSegment->setSourceUrl("forged://");
 
             rep->initialisationSegment.Set(initSegment);



More information about the vlc-commits mailing list