[vlc-commits] DASH: implement Seek()

Frédéric Yhuel git at videolan.org
Thu Mar 29 14:59:34 CEST 2012


vlc | branch: master | Frédéric Yhuel <fyhuel at viotech.net> | Mon Mar 26 16:38:46 2012 +0200| [7fc906082f1d8252d572fcdbc01107839d904181] | committer: Hugo Beauzée-Luyssen

DASH: implement Seek()

This is needed for DASH module to work with (not yet ready) VLC MP4
demux. Forward seeking is implemented by calling Read() with a NULL
argument (= skipping), while backward seeking is limited to the current
block in the block_bytestream_t upon which is built the internal buffer.
This limitation is not really a problem because backward seeking will be
needed only for the parsing of the initialization fragment.

Signed-off-by: Hugo Beauzée-Luyssen <beauze.h at gmail.com>

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

 modules/stream_filter/dash/DASHManager.cpp        |    5 ++
 modules/stream_filter/dash/DASHManager.h          |    1 +
 modules/stream_filter/dash/buffer/BlockBuffer.cpp |   16 ++++++
 modules/stream_filter/dash/buffer/BlockBuffer.h   |    1 +
 modules/stream_filter/dash/dash.cpp               |   53 ++++++++++++++++++++-
 5 files changed, 74 insertions(+), 2 deletions(-)

diff --git a/modules/stream_filter/dash/DASHManager.cpp b/modules/stream_filter/dash/DASHManager.cpp
index f649015..8483c9d 100644
--- a/modules/stream_filter/dash/DASHManager.cpp
+++ b/modules/stream_filter/dash/DASHManager.cpp
@@ -74,6 +74,11 @@ int     DASHManager::read( void *p_buffer, size_t len )
     return this->buffer->get(p_buffer, len);
 }
 
+int     DASHManager::seekBackwards( unsigned i_len )
+{
+    return this->buffer->seekBackwards( i_len );
+}
+
 int     DASHManager::peek( const uint8_t **pp_peek, size_t i_peek )
 {
     return this->buffer->peek(pp_peek, i_peek);
diff --git a/modules/stream_filter/dash/DASHManager.h b/modules/stream_filter/dash/DASHManager.h
index a09e98e..90d9317 100644
--- a/modules/stream_filter/dash/DASHManager.h
+++ b/modules/stream_filter/dash/DASHManager.h
@@ -47,6 +47,7 @@ namespace dash
             bool    start   ();
             int     read    ( void *p_buffer, size_t len );
             int     peek    ( const uint8_t **pp_peek, size_t i_peek );
+            int     seekBackwards ( unsigned len );
 
             const mpd::IMPDManager*         getMpdManager   () const;
             const logic::IAdaptationLogic*  getAdaptionLogic() const;
diff --git a/modules/stream_filter/dash/buffer/BlockBuffer.cpp b/modules/stream_filter/dash/buffer/BlockBuffer.cpp
index 056c481..1db9168 100644
--- a/modules/stream_filter/dash/buffer/BlockBuffer.cpp
+++ b/modules/stream_filter/dash/buffer/BlockBuffer.cpp
@@ -85,6 +85,22 @@ int     BlockBuffer::peek                 (const uint8_t **pp_peek, unsigned int
     vlc_mutex_unlock(&this->monitorMutex);
     return ret;
 }
+
+int     BlockBuffer::seekBackwards       (unsigned len)
+{
+    vlc_mutex_lock(&this->monitorMutex);
+    if( this->buffer.i_offset > len )
+    {
+        this->buffer.i_offset -= len;
+        this->sizeBytes += len;
+        vlc_mutex_unlock(&this->monitorMutex);
+        return VLC_SUCCESS;
+    }
+
+    vlc_mutex_unlock(&this->monitorMutex);
+    return VLC_EGENERIC;
+}
+
 int     BlockBuffer::get                  (void *p_data, unsigned int len)
 {
     vlc_mutex_lock(&this->monitorMutex);
diff --git a/modules/stream_filter/dash/buffer/BlockBuffer.h b/modules/stream_filter/dash/buffer/BlockBuffer.h
index 570861f..2c39db1 100644
--- a/modules/stream_filter/dash/buffer/BlockBuffer.h
+++ b/modules/stream_filter/dash/buffer/BlockBuffer.h
@@ -49,6 +49,7 @@ namespace dash
                 void    put         (block_t *block);
                 int     get         (void *p_data, unsigned int len);
                 int     peek        (const uint8_t **pp_peek, unsigned int i_peek);
+                int     seekBackwards (unsigned len);
                 void    setEOF      (bool value);
                 bool    getEOF      ();
                 mtime_t size        ();
diff --git a/modules/stream_filter/dash/dash.cpp b/modules/stream_filter/dash/dash.cpp
index b503f27..9003a9d 100644
--- a/modules/stream_filter/dash/dash.cpp
+++ b/modules/stream_filter/dash/dash.cpp
@@ -77,7 +77,7 @@ struct stream_sys_t
         dash::DASHManager                   *p_dashManager;
         dash::http::HTTPConnectionManager   *p_conManager;
         dash::mpd::MPD                      *p_mpd;
-        int                                 position;
+        uint64_t                            position;
         bool                                isLive;
 };
 
@@ -160,6 +160,46 @@ static void Close(vlc_object_t *p_obj)
 /*****************************************************************************
  * Callbacks:
  *****************************************************************************/
+static int  Seek            ( stream_t *p_stream, uint64_t pos )
+{
+    stream_sys_t        *p_sys          = (stream_sys_t *) p_stream->p_sys;
+    dash::DASHManager   *p_dashManager  = p_sys->p_dashManager;
+    int                 i_ret           = 0;
+    unsigned            i_len           = 0;
+    long                i_read          = 0;
+
+    if( pos < p_sys->position )
+    {
+        if( p_sys->position - pos > UINT_MAX )
+        {
+            msg_Err( p_stream, "Cannot seek backward that far!" );
+            return VLC_EGENERIC;
+        }
+        i_len = p_sys->position - pos;
+        i_ret = p_dashManager->seekBackwards( i_len );
+        if( i_ret == VLC_EGENERIC )
+        {
+            msg_Err( p_stream, "Cannot seek backward outside the current block :-/" );
+            return VLC_EGENERIC;
+        }
+        else
+            return VLC_SUCCESS;
+    }
+
+    /* Seek forward */
+    if( pos - p_sys->position > UINT_MAX )
+    {
+        msg_Err( p_stream, "Cannot seek forward that far!" );
+        return VLC_EGENERIC;
+    }
+    i_len = pos - p_sys->position;
+    i_read = Read( p_stream, (void *)NULL, i_len );
+    if( (unsigned)i_read == i_len )
+        return VLC_SUCCESS;
+    else
+        return VLC_EGENERIC;
+}
+
 static int  Read            (stream_t *p_stream, void *p_ptr, unsigned int i_len)
 {
     stream_sys_t        *p_sys          = (stream_sys_t *) p_stream->p_sys;
@@ -221,7 +261,16 @@ static int  Control         (stream_t *p_stream, int i_query, va_list args)
             *(va_arg (args, uint64_t *)) = p_sys->position;
             break;
         case STREAM_SET_POSITION:
-            return VLC_EGENERIC;
+        {
+            uint64_t pos = (uint64_t)va_arg(args, uint64_t);
+            if(Seek(p_stream, pos) == VLC_SUCCESS)
+            {
+                p_sys->position = pos;
+                break;
+            }
+            else
+                return VLC_EGENERIC;
+        }
         case STREAM_GET_SIZE:
         {
             uint64_t*   res = (va_arg (args, uint64_t *));



More information about the vlc-commits mailing list