[vlc-commits] stream_filter: dash: fix double buffer alloc

Francois Cartegnie git at videolan.org
Thu Dec 18 22:39:49 CET 2014


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Sun Nov 23 23:56:02 2014 +0100| [cba9fffaf2c49f2992057ff12969330ae2f65df1] | committer: Francois Cartegnie

stream_filter: dash: fix double buffer alloc

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

 modules/stream_filter/dash/DASHDownloader.cpp             |   13 +++----------
 modules/stream_filter/dash/http/HTTPConnectionManager.cpp |   12 ++++++++++--
 modules/stream_filter/dash/http/HTTPConnectionManager.h   |    2 +-
 3 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/modules/stream_filter/dash/DASHDownloader.cpp b/modules/stream_filter/dash/DASHDownloader.cpp
index 69150a6..81f7fca 100644
--- a/modules/stream_filter/dash/DASHDownloader.cpp
+++ b/modules/stream_filter/dash/DASHDownloader.cpp
@@ -58,24 +58,17 @@ void*       DASHDownloader::download    (void *thread_sys)
     thread_sys_t            *t_sys              = (thread_sys_t *) thread_sys;
     HTTPConnectionManager   *conManager         = t_sys->conManager;
     BlockBuffer             *buffer             = t_sys->buffer;
-    block_t                 *block              = block_Alloc(BLOCKSIZE);
     int                     ret                 = 0;
 
     do
     {
-        ret = conManager->read(block);
+        block_t *block = NULL;
+        ret = conManager->read(&block, BLOCKSIZE);
         if(ret > 0)
-        {
-            block_t *bufBlock = block_Alloc(ret);
-            memcpy(bufBlock->p_buffer, block->p_buffer, ret);
-
-            bufBlock->i_length = block->i_length;
-            buffer->put(bufBlock);
-        }
+            buffer->put(block);
     }while(ret && !buffer->getEOF());
 
     buffer->setEOF(true);
-    block_Release(block);
 
     return NULL;
 }
diff --git a/modules/stream_filter/dash/http/HTTPConnectionManager.cpp b/modules/stream_filter/dash/http/HTTPConnectionManager.cpp
index 7bdc144..c5dd95e 100644
--- a/modules/stream_filter/dash/http/HTTPConnectionManager.cpp
+++ b/modules/stream_filter/dash/http/HTTPConnectionManager.cpp
@@ -58,7 +58,7 @@ void                                HTTPConnectionManager::closeAllConnections
     vlc_delete_all(this->connectionPool);
     vlc_delete_all(this->downloadQueue);
 }
-int                                 HTTPConnectionManager::read                     (block_t *block)
+int HTTPConnectionManager::read(block_t **pp_block, size_t len)
 {
     if(this->downloadQueue.size() == 0)
         if(!this->addChunk(this->adaptationLogic->getNextChunk()))
@@ -70,6 +70,10 @@ int                                 HTTPConnectionManager::read
 
     int ret = 0;
 
+    block_t *block = block_Alloc(len);
+    if(!block)
+        return -1;
+
     mtime_t start = mdate();
     ret = this->downloadQueue.front()->getConnection()->read(block->p_buffer, block->i_buffer);
     mtime_t end = mdate();
@@ -80,6 +84,7 @@ int                                 HTTPConnectionManager::read
 
     if(ret <= 0)
     {
+        block_Release(block);
         this->bpsLastChunk   = this->bpsCurrentChunk;
         this->bytesReadChunk = 0;
         this->timeChunk      = 0;
@@ -87,13 +92,16 @@ int                                 HTTPConnectionManager::read
         delete(this->downloadQueue.front());
         this->downloadQueue.pop_front();
 
-        return this->read(block);
+        return this->read(pp_block, len);
     }
     else
     {
         this->updateStatistics(ret, time);
+        block->i_buffer = ret;
     }
 
+    *pp_block = block;
+
     return ret;
 }
 void                                HTTPConnectionManager::attach                   (IDownloadRateObserver *observer)
diff --git a/modules/stream_filter/dash/http/HTTPConnectionManager.h b/modules/stream_filter/dash/http/HTTPConnectionManager.h
index 1206006..30fc877 100644
--- a/modules/stream_filter/dash/http/HTTPConnectionManager.h
+++ b/modules/stream_filter/dash/http/HTTPConnectionManager.h
@@ -49,7 +49,7 @@ namespace dash
 
                 void    closeAllConnections ();
                 bool    addChunk            (Chunk *chunk);
-                int     read                (block_t *block);
+                int     read                (block_t **, size_t);
                 void    attach              (dash::logic::IDownloadRateObserver *observer);
                 void    notify              ();
 



More information about the vlc-commits mailing list