[vlc-commits] demux: hls: handle packed audio ID3 time offset

Francois Cartegnie git at videolan.org
Thu Jul 16 23:04:28 CEST 2015


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Wed Jul 15 21:41:40 2015 +0200| [9875cd9a2e957049c12309b576a8ca4e016c8fd1] | committer: Francois Cartegnie

demux: hls: handle packed audio ID3 time offset

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

 modules/demux/Makefile.am        |    2 +
 modules/demux/hls/HLSManager.cpp |   18 ---------
 modules/demux/hls/HLSManager.hpp |    6 ---
 modules/demux/hls/HLSStreams.cpp |   77 ++++++++++++++++++++++++++++++++++++++
 modules/demux/hls/HLSStreams.hpp |   47 +++++++++++++++++++++++
 modules/demux/hls/hls.cpp        |    1 +
 6 files changed, 127 insertions(+), 24 deletions(-)

diff --git a/modules/demux/Makefile.am b/modules/demux/Makefile.am
index 8c5342a..7f3b93a 100644
--- a/modules/demux/Makefile.am
+++ b/modules/demux/Makefile.am
@@ -374,6 +374,8 @@ libhls_plugin_la_SOURCES = \
     demux/hls/HLSManager.hpp \
     demux/hls/HLSManager.cpp \
     demux/hls/HLSStreamFormat.hpp \
+    demux/hls/HLSStreams.hpp \
+    demux/hls/HLSStreams.cpp \
     demux/hls/hls.cpp \
     demux/hls/hls.hpp
 
diff --git a/modules/demux/hls/HLSManager.cpp b/modules/demux/hls/HLSManager.cpp
index e9308fd..a6e9b21 100644
--- a/modules/demux/hls/HLSManager.cpp
+++ b/modules/demux/hls/HLSManager.cpp
@@ -23,7 +23,6 @@
 #endif
 
 #include "HLSManager.hpp"
-#include "HLSStreamFormat.hpp"
 #include "../adaptative/logic/RateBasedAdaptationLogic.h"
 #include "../adaptative/tools/Retrieve.hpp"
 #include "playlist/Parser.hpp"
@@ -35,23 +34,6 @@ using namespace adaptative::logic;
 using namespace hls;
 using namespace hls::playlist;
 
-AbstractStreamOutput *HLSStreamOutputFactory::create(demux_t *demux, const StreamFormat &format) const
-{
-    unsigned fmt = format;
-    switch(fmt)
-    {
-        case HLSStreamFormat::PACKEDAAC:
-            return new BaseStreamOutput(demux, format, "any");
-            break;
-
-        default:
-        case HLSStreamFormat::UNKNOWN:
-        case HLSStreamFormat::MPEG2TS:
-            return new BaseStreamOutput(demux, format, "ts");
-    }
-    return NULL;
-}
-
 HLSManager::HLSManager(M3U8 *playlist,
                        AbstractStreamOutputFactory *factory,
                        AbstractAdaptationLogic::LogicType type, stream_t *stream) :
diff --git a/modules/demux/hls/HLSManager.hpp b/modules/demux/hls/HLSManager.hpp
index 0fedb5c..09fe3bb 100644
--- a/modules/demux/hls/HLSManager.hpp
+++ b/modules/demux/hls/HLSManager.hpp
@@ -28,12 +28,6 @@ namespace hls
 {
     using namespace adaptative;
 
-    class HLSStreamOutputFactory : public AbstractStreamOutputFactory
-    {
-        public:
-            virtual AbstractStreamOutput *create(demux_t*, const StreamFormat &) const;
-    };
-
     class HLSManager : public PlaylistManager
     {
         public:
diff --git a/modules/demux/hls/HLSStreams.cpp b/modules/demux/hls/HLSStreams.cpp
new file mode 100644
index 0000000..1d75edc
--- /dev/null
+++ b/modules/demux/hls/HLSStreams.cpp
@@ -0,0 +1,77 @@
+/*
+ * HLSStreams.cpp
+ *****************************************************************************
+ * Copyright (C) 2015 - VideoLAN 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.
+ *****************************************************************************/
+#include "HLSStreams.hpp"
+#include "HLSStreamFormat.hpp"
+#include <vlc_demux.h>
+
+using namespace hls;
+
+AbstractStreamOutput *HLSStreamOutputFactory::create(demux_t *demux, const StreamFormat &format) const
+{
+    unsigned fmt = format;
+    switch(fmt)
+    {
+        case HLSStreamFormat::PACKEDAAC:
+            return new HLSPackedStreamOutput(demux, format, "any");
+            break;
+
+        default:
+        case HLSStreamFormat::UNKNOWN:
+        case HLSStreamFormat::MPEG2TS:
+            return new BaseStreamOutput(demux, format, "ts");
+    }
+    return NULL;
+}
+
+HLSPackedStreamOutput::HLSPackedStreamOutput(demux_t *demux, const StreamFormat &format, const std::string &name) :
+    BaseStreamOutput(demux, format, name)
+{
+
+}
+
+void HLSPackedStreamOutput::pushBlock(block_t *p_block, bool b_first)
+{
+    if(b_first && p_block && p_block->i_buffer >= 10 && !memcmp(p_block->p_buffer, "ID3", 3))
+    {
+        uint32_t size = GetDWBE(&p_block->p_buffer[6]) + 10;
+        size = __MIN(p_block->i_buffer, size);
+        if(size >= 73 && timestamps_offset == VLC_TS_INVALID)
+        {
+            if(!memcmp(&p_block->p_buffer[10], "PRIV", 4) &&
+               !memcmp(&p_block->p_buffer[20], "com.apple.streaming.transportStreamTimestamp", 45))
+            {
+                setTimestampOffset( GetQWBE(&p_block->p_buffer[65]) * 100 / 9 );
+            }
+        }
+
+        /* Skip ID3 for demuxer */
+        p_block->p_buffer += size;
+        p_block->i_buffer -= size;
+    }
+
+    BaseStreamOutput::pushBlock(p_block, b_first);
+}
+
+void HLSPackedStreamOutput::setPosition(mtime_t nztime)
+{
+    BaseStreamOutput::setPosition(nztime);
+    /* Should be correct, has a restarted demux shouldn't have been fed with data yet */
+    setTimestampOffset(VLC_TS_INVALID - VLC_TS_0);
+}
diff --git a/modules/demux/hls/HLSStreams.hpp b/modules/demux/hls/HLSStreams.hpp
new file mode 100644
index 0000000..93e1eaf
--- /dev/null
+++ b/modules/demux/hls/HLSStreams.hpp
@@ -0,0 +1,47 @@
+/*
+ * HLSStreams.hpp
+ *****************************************************************************
+ * Copyright (C) 2015 - VideoLAN 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 HLSSTREAM_HPP
+#define HLSSTREAM_HPP
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "../adaptative/Streams.hpp"
+
+namespace hls
+{
+    using namespace adaptative;
+
+    class HLSStreamOutputFactory : public AbstractStreamOutputFactory
+    {
+        public:
+            virtual AbstractStreamOutput *create(demux_t*, const StreamFormat &) const;
+    };
+
+    class HLSPackedStreamOutput : public BaseStreamOutput
+    {
+        public:
+            HLSPackedStreamOutput(demux_t *, const StreamFormat &, const std::string &);
+            virtual void pushBlock(block_t *, bool); /* reimpl */
+            virtual void setPosition(mtime_t); /* reimpl */
+    };
+}
+#endif // HLSSTREAMS_HPP
diff --git a/modules/demux/hls/hls.cpp b/modules/demux/hls/hls.cpp
index d40070c..19984dd 100644
--- a/modules/demux/hls/hls.cpp
+++ b/modules/demux/hls/hls.cpp
@@ -37,6 +37,7 @@
 
 #include "../adaptative/logic/AbstractAdaptationLogic.h"
 #include "HLSManager.hpp"
+#include "HLSStreams.hpp"
 
 #include "playlist/Parser.hpp"
 #include "playlist/M3U8.hpp"



More information about the vlc-commits mailing list