[haiku-commits] haiku: hrev50400 - src/kits/media src/add-ons/media/plugins/http_streamer headers/private/media

  • From: b.vitruvio@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sat, 9 Jul 2016 16:30:26 +0200 (CEST)

hrev50400 adds 2 changesets to branch 'master'
old head: 5c05bb48f4191d8f4179e1a8d0deaf0d51bbaffc
new head: eed8ce57b828343ecbdbd240e125519f11746803
overview: 
http://cgit.haiku-os.org/haiku/log/?qt=range&q=eed8ce57b828+%5E5c05bb48f419

----------------------------------------------------------------------------

0474db50d0de: AdapterIO: Add IsRunning method
  
  * The backend need to know if we can really get data.
  * Adapt WaitForData to be more reliable using this method.

eed8ce57b828: http_streamer: Implement IsRunning, more reliability
  
  * The init sem is released also when the request is completed
  to be sure the backend doesn't lock on us.
  * Implement IsRunning relying on BUrlRequest::IsRunning.

                                [ Dario Casalinuovo <b.vitruvio@xxxxxxxxx> ]

----------------------------------------------------------------------------

4 files changed, 38 insertions(+), 8 deletions(-)
headers/private/media/AdapterIO.h                |  2 ++
.../media/plugins/http_streamer/HTTPMediaIO.cpp  | 24 ++++++++++++++++----
.../media/plugins/http_streamer/HTTPMediaIO.h    |  2 ++
src/kits/media/AdapterIO.cpp                     | 18 ++++++++++++---

############################################################################

Commit:      0474db50d0de3ff50900db4e80a19a03e54a00bb
URL:         http://cgit.haiku-os.org/haiku/commit/?id=0474db50d0de
Author:      Dario Casalinuovo <b.vitruvio@xxxxxxxxx>
Date:        Sat Jul  9 14:18:09 2016 UTC

AdapterIO: Add IsRunning method

* The backend need to know if we can really get data.
* Adapt WaitForData to be more reliable using this method.

----------------------------------------------------------------------------

diff --git a/headers/private/media/AdapterIO.h 
b/headers/private/media/AdapterIO.h
index 119b31f..bf09c16 100644
--- a/headers/private/media/AdapterIO.h
+++ b/headers/private/media/AdapterIO.h
@@ -58,6 +58,8 @@ public:
        virtual status_t                                Open();
        virtual void                                    Close();
 
+       virtual bool                                    IsRunning() const;
+
                        void                                    SeekCompleted();
                        status_t                                
SetBuffer(BPositionIO* buffer);
 
diff --git a/src/kits/media/AdapterIO.cpp b/src/kits/media/AdapterIO.cpp
index 1c38ca2..d3ef490 100644
--- a/src/kits/media/AdapterIO.cpp
+++ b/src/kits/media/AdapterIO.cpp
@@ -67,7 +67,7 @@ public:
                return B_OK;
        }
 
-       status_t WaitForData(off_t position)
+       status_t WaitForData(off_t position, off_t size)
        {
                off_t bufferSize = 0;
                status_t ret = GetSize(&bufferSize);
@@ -76,7 +76,12 @@ public:
 
                bigtime_t totalTimeOut = 0;
 
-               while(bufferSize <= position) {
+               while(bufferSize < position+size) {
+                       // We are not running, no luck to receive
+                       // more data, let's return and avoid locking.
+                       if (!fOwner->IsRunning())
+                               return B_NOT_SUPPORTED;
+
                        if (fTimeout != B_INFINITE_TIMEOUT && totalTimeOut >= 
fTimeout)
                                return B_TIMED_OUT;
 
@@ -346,6 +351,13 @@ BAdapterIO::Close()
 }
 
 
+bool
+BAdapterIO::IsRunning() const
+{
+       return fOpened;
+}
+
+
 void
 BAdapterIO::SeekCompleted()
 {
@@ -415,7 +427,7 @@ BAdapterIO::_EvaluateWait(off_t pos, off_t size)
 
        TRACE("BAdapterIO::_EvaluateWait: waiting for data\n");
 
-       return fBuffer->WaitForData(pos+size);
+       return fBuffer->WaitForData(pos, size);
 }
 
 

############################################################################

Revision:    hrev50400
Commit:      eed8ce57b828343ecbdbd240e125519f11746803
URL:         http://cgit.haiku-os.org/haiku/commit/?id=eed8ce57b828
Author:      Dario Casalinuovo <b.vitruvio@xxxxxxxxx>
Date:        Sat Jul  9 14:19:31 2016 UTC

http_streamer: Implement IsRunning, more reliability

* The init sem is released also when the request is completed
to be sure the backend doesn't lock on us.
* Implement IsRunning relying on BUrlRequest::IsRunning.

----------------------------------------------------------------------------

diff --git a/src/add-ons/media/plugins/http_streamer/HTTPMediaIO.cpp 
b/src/add-ons/media/plugins/http_streamer/HTTPMediaIO.cpp
index 62b3d18..9aecb8b 100644
--- a/src/add-ons/media/plugins/http_streamer/HTTPMediaIO.cpp
+++ b/src/add-ons/media/plugins/http_streamer/HTTPMediaIO.cpp
@@ -45,11 +45,7 @@ public:
                void DataReceived(BUrlRequest* request, const char* data,
                        off_t position, ssize_t size)
                {
-                       if (fInitSem != -1) {
-                               release_sem(fInitSem);
-                               delete_sem(fInitSem);
-                               fInitSem = -1;
-                       }
+                       _ReleaseInit();
 
                        if (request != fRequest)
                                delete request;
@@ -59,6 +55,8 @@ public:
 
                void RequestCompleted(BUrlRequest* request, bool success)
                {
+                       _ReleaseInit();
+
                        if (request != fRequest)
                                return;
 
@@ -72,6 +70,15 @@ public:
                }
 
 private:
+               void _ReleaseInit()
+               {
+                       if (fInitSem != -1) {
+                               release_sem(fInitSem);
+                               delete_sem(fInitSem);
+                               fInitSem = -1;
+                       }
+               }
+
                BUrlRequest*    fRequest;
                BAdapterIO*             fAdapterIO;
                BInputAdapter*  fInputAdapter;
@@ -166,6 +173,13 @@ HTTPMediaIO::Close()
 }
 
 
+bool
+HTTPMediaIO::IsRunning() const
+{
+       return fReq != NULL && fReq->IsRunning();
+}
+
+
 status_t
 HTTPMediaIO::SeekRequested(off_t position)
 {
diff --git a/src/add-ons/media/plugins/http_streamer/HTTPMediaIO.h 
b/src/add-ons/media/plugins/http_streamer/HTTPMediaIO.h
index fa5f0b1..778b322 100644
--- a/src/add-ons/media/plugins/http_streamer/HTTPMediaIO.h
+++ b/src/add-ons/media/plugins/http_streamer/HTTPMediaIO.h
@@ -30,6 +30,8 @@ public:
        virtual status_t                                        Open();
        virtual void                                            Close();
 
+       virtual bool                                            IsRunning() 
const;
+
 protected:
        virtual status_t                                        
SeekRequested(off_t position);
 


Other related posts: