[vlc-commits] demux: adaptive: pass content-type though streams

Francois Cartegnie git at videolan.org
Mon Feb 26 12:14:35 CET 2018


vlc/vlc-3.0 | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Tue Feb 20 22:40:10 2018 +0100| [0aa14f99ace03b801abdc71ad7d9fa9187fbe58a] | committer: Francois Cartegnie

demux: adaptive: pass content-type though streams

(cherry picked from commit 44751cd70149e17c971a113bdb386e550211669f)

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

 modules/demux/adaptive/ChunksSource.hpp          |  1 +
 modules/demux/adaptive/Streams.cpp               | 10 +++++++++
 modules/demux/adaptive/Streams.hpp               |  3 +++
 modules/demux/adaptive/http/Chunk.cpp            | 15 +++++++++++++
 modules/demux/adaptive/http/Chunk.h              |  3 +++
 modules/demux/adaptive/plumbing/SourceStream.cpp | 27 ++++++++++++++++++++++--
 modules/demux/adaptive/plumbing/SourceStream.hpp |  2 ++
 7 files changed, 59 insertions(+), 2 deletions(-)

diff --git a/modules/demux/adaptive/ChunksSource.hpp b/modules/demux/adaptive/ChunksSource.hpp
index 9eac7006d9..afe84abeba 100644
--- a/modules/demux/adaptive/ChunksSource.hpp
+++ b/modules/demux/adaptive/ChunksSource.hpp
@@ -29,6 +29,7 @@ namespace adaptive
         public:
             virtual ~ChunksSource() {}
             virtual block_t *readNextBlock() = 0;
+            virtual std::string getContentType() = 0;
     };
 }
 
diff --git a/modules/demux/adaptive/Streams.cpp b/modules/demux/adaptive/Streams.cpp
index 6bdd2139ae..0cc195f0ce 100644
--- a/modules/demux/adaptive/Streams.cpp
+++ b/modules/demux/adaptive/Streams.cpp
@@ -449,6 +449,16 @@ AbstractStream::status AbstractStream::dequeue(mtime_t nz_deadline, mtime_t *pi_
     return AbstractStream::status_buffering;
 }
 
+std::string AbstractStream::getContentType()
+{
+    if (currentChunk == NULL && !eof)
+        currentChunk = segmentTracker->getNextChunk(!fakeesout->restarting(), connManager);
+    if(currentChunk)
+        return currentChunk->getContentType();
+    else
+        return std::string();
+}
+
 block_t * AbstractStream::readNextBlock()
 {
     if (currentChunk == NULL && !eof)
diff --git a/modules/demux/adaptive/Streams.hpp b/modules/demux/adaptive/Streams.hpp
index 0e1ca07b4e..5a8c29e7ed 100644
--- a/modules/demux/adaptive/Streams.hpp
+++ b/modules/demux/adaptive/Streams.hpp
@@ -92,8 +92,11 @@ namespace adaptive
         mtime_t getPlaybackTime() const;
         void runUpdates();
 
+        /* Used by demuxers fake streams */
+        virtual std::string getContentType(); /* impl */
         virtual block_t *readNextBlock(); /* impl */
 
+        /**/
         virtual void fillExtraFMTInfo( es_format_t * ) const; /* impl */
         virtual void trackerEvent(const SegmentTrackerEvent &); /* impl */
 
diff --git a/modules/demux/adaptive/http/Chunk.cpp b/modules/demux/adaptive/http/Chunk.cpp
index e8826514e7..20a5644612 100644
--- a/modules/demux/adaptive/http/Chunk.cpp
+++ b/modules/demux/adaptive/http/Chunk.cpp
@@ -59,6 +59,11 @@ const BytesRange & AbstractChunkSource::getBytesRange() const
     return bytesRange;
 }
 
+std::string AbstractChunkSource::getContentType() const
+{
+    return std::string();
+}
+
 AbstractChunk::AbstractChunk(AbstractChunkSource *source_)
 {
     bytesRead = 0;
@@ -70,6 +75,11 @@ AbstractChunk::~AbstractChunk()
     delete source;
 }
 
+std::string AbstractChunk::getContentType()
+{
+    return source->getContentType();
+}
+
 size_t AbstractChunk::getBytesRead() const
 {
     return this->bytesRead;
@@ -204,6 +214,11 @@ block_t * HTTPChunkSource::read(size_t readsize)
     return p_block;
 }
 
+std::string HTTPChunkSource::getContentType() const
+{
+    return connection->getContentType();
+}
+
 bool HTTPChunkSource::prepare()
 {
     if(prepared)
diff --git a/modules/demux/adaptive/http/Chunk.h b/modules/demux/adaptive/http/Chunk.h
index a92c20ee6a..a8e73a0522 100644
--- a/modules/demux/adaptive/http/Chunk.h
+++ b/modules/demux/adaptive/http/Chunk.h
@@ -52,6 +52,7 @@ namespace adaptive
                 virtual bool        hasMoreData     () const = 0;
                 void                setBytesRange   (const BytesRange &);
                 const BytesRange &  getBytesRange   () const;
+                virtual std::string getContentType  () const;
 
             protected:
                 size_t              contentLength;
@@ -63,6 +64,7 @@ namespace adaptive
             public:
                 virtual ~AbstractChunk();
 
+                std::string         getContentType          ();
                 size_t              getBytesRead            () const;
                 uint64_t            getStartByteInFile      () const;
                 bool                isEmpty                 () const;
@@ -90,6 +92,7 @@ namespace adaptive
                 virtual block_t *   readBlock       (); /* impl */
                 virtual block_t *   read            (size_t); /* impl */
                 virtual bool        hasMoreData     () const; /* impl */
+                virtual std::string getContentType  () const; /* reimpl */
 
                 static const size_t CHUNK_SIZE = 32768;
 
diff --git a/modules/demux/adaptive/plumbing/SourceStream.cpp b/modules/demux/adaptive/plumbing/SourceStream.cpp
index c12e2e67ea..08cf27c54b 100644
--- a/modules/demux/adaptive/plumbing/SourceStream.cpp
+++ b/modules/demux/adaptive/plumbing/SourceStream.cpp
@@ -65,6 +65,16 @@ stream_t * ChunksSourceStream::makeStream()
     return p_stream;
 }
 
+std::string ChunksSourceStream::getContentType()
+{
+    if(!b_eof && !p_block)
+    {
+        p_block = source->readNextBlock();
+        b_eof = !p_block;
+    }
+    return source->getContentType();
+}
+
 ssize_t ChunksSourceStream::Read(uint8_t *buf, size_t size)
 {
     size_t i_copied = 0;
@@ -112,8 +122,9 @@ int ChunksSourceStream::seek_Callback(stream_t *, uint64_t)
     return VLC_EGENERIC;
 }
 
-int ChunksSourceStream::control_Callback(stream_t *, int i_query, va_list args)
+int ChunksSourceStream::control_Callback(stream_t *s, int i_query, va_list args)
 {
+    ChunksSourceStream *me = reinterpret_cast<ChunksSourceStream *>(s->p_sys);
     switch( i_query )
     {
         case STREAM_GET_SIZE:
@@ -127,13 +138,25 @@ int ChunksSourceStream::control_Callback(stream_t *, int i_query, va_list args)
             *va_arg( args, bool * ) = false;
             return VLC_SUCCESS;
 
+        case STREAM_GET_CONTENT_TYPE:
+        {
+            std::string type = me->getContentType();
+            if(!type.empty())
+            {
+                *va_arg( args, char ** ) = strdup(type.c_str());
+                return VLC_SUCCESS;
+            }
+        }
+        break;
+
         case STREAM_GET_PTS_DELAY:
             *(va_arg( args, uint64_t * )) = DEFAULT_PTS_DELAY;
             return VLC_SUCCESS;
 
         default:
-            return VLC_EGENERIC;
+            break;
     }
+    return VLC_EGENERIC;
 }
 
 void ChunksSourceStream::delete_Callback(stream_t *)
diff --git a/modules/demux/adaptive/plumbing/SourceStream.hpp b/modules/demux/adaptive/plumbing/SourceStream.hpp
index 6ab9c4e2b0..af0e4fd555 100644
--- a/modules/demux/adaptive/plumbing/SourceStream.hpp
+++ b/modules/demux/adaptive/plumbing/SourceStream.hpp
@@ -22,6 +22,7 @@
 
 #include <vlc_common.h>
 #include <vlc_block.h>
+#include <string>
 
 namespace adaptive
 {
@@ -44,6 +45,7 @@ namespace adaptive
             virtual void Reset(); /* impl */
 
         protected:
+            std::string getContentType();
             ssize_t Read(uint8_t *, size_t);
 
         private:



More information about the vlc-commits mailing list