From b4e751b890320dec0f64237a10a4d8f7e61a340f Mon Sep 17 00:00:00 2001 From: Dario Casalinuovo Date: Sun, 3 Jul 2016 15:25:42 +0200 Subject: [PATCH] http_streamer: Mutable flag is chosen at runtime * BeOS Radio now works. --- .../plugins/http_streamer/HTTPMediaIO.cpp | 33 +++++++++++-------- .../media/plugins/http_streamer/HTTPMediaIO.h | 4 ++- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/add-ons/media/plugins/http_streamer/HTTPMediaIO.cpp b/src/add-ons/media/plugins/http_streamer/HTTPMediaIO.cpp index 98ddecdef6..ae32db06fc 100644 --- a/src/add-ons/media/plugins/http_streamer/HTTPMediaIO.cpp +++ b/src/add-ons/media/plugins/http_streamer/HTTPMediaIO.cpp @@ -81,12 +81,12 @@ private: HTTPMediaIO::HTTPMediaIO(BUrl url) : - BAdapterIO(B_MEDIA_STREAMING | B_MEDIA_SEEK_BACKWARD, HTTP_TIMEOUT), + BAdapterIO(HTTP_TIMEOUT), fContext(NULL), fReq(NULL), fListener(NULL), fUrl(url), - fTotalSize(0) + fIsMutable(false) { } @@ -96,6 +96,15 @@ HTTPMediaIO::~HTTPMediaIO() } +void +HTTPMediaIO::GetFlags(int32* flags) const +{ + *flags = B_MEDIA_STREAMING | B_MEDIA_SEEK_BACKWARD; + if (fIsMutable) + *flags = *flags | B_MEDIA_MUTABLE_SIZE; +} + + ssize_t HTTPMediaIO::WriteAt(off_t position, const void* buffer, size_t size) { @@ -110,17 +119,6 @@ HTTPMediaIO::SetSize(off_t size) } -status_t -HTTPMediaIO::GetSize(off_t* size) const -{ - if (fReq == NULL) - return B_ERROR; - - *size = fTotalSize; - return B_OK; -} - - status_t HTTPMediaIO::Open() { @@ -142,7 +140,14 @@ HTTPMediaIO::Open() if (ret != B_OK) return ret; - fTotalSize = fReq->Result().Length(); + off_t totalSize = fReq->Result().Length(); + + // At this point we decide if our size is fixed or mutable, + // this will change the behavior of our parent. + if (totalSize > 0) + BAdapterIO::SetSize(totalSize); + else + fIsMutable = true; return BAdapterIO::Open(); } diff --git a/src/add-ons/media/plugins/http_streamer/HTTPMediaIO.h b/src/add-ons/media/plugins/http_streamer/HTTPMediaIO.h index 1367e693fb..fa5f0b116b 100644 --- a/src/add-ons/media/plugins/http_streamer/HTTPMediaIO.h +++ b/src/add-ons/media/plugins/http_streamer/HTTPMediaIO.h @@ -20,11 +20,12 @@ public: HTTPMediaIO(BUrl url); virtual ~HTTPMediaIO(); + virtual void GetFlags(int32* flags) const; + virtual ssize_t WriteAt(off_t position, const void* buffer, size_t size); virtual status_t SetSize(off_t size); - virtual status_t GetSize(off_t* size) const; virtual status_t Open(); virtual void Close(); @@ -39,6 +40,7 @@ private: BUrl fUrl; off_t fTotalSize; + bool fIsMutable; }; #endif