From 93a1f9d274a4c2d0a54da4d90b5154acb26b6eb8 Mon Sep 17 00:00:00 2001 From: Dario Casalinuovo Date: Thu, 30 Jun 2016 16:30:07 +0200 Subject: [PATCH] http_streamer: Sync with BAdapterIO changes --- .../plugins/http_streamer/HTTPMediaIO.cpp | 79 +++++++++++-------- .../media/plugins/http_streamer/HTTPMediaIO.h | 10 ++- .../http_streamer/HTTPStreamerPlugin.cpp | 11 +-- 3 files changed, 60 insertions(+), 40 deletions(-) diff --git a/src/add-ons/media/plugins/http_streamer/HTTPMediaIO.cpp b/src/add-ons/media/plugins/http_streamer/HTTPMediaIO.cpp index 26b79f3aef..fa7f72b8a1 100644 --- a/src/add-ons/media/plugins/http_streamer/HTTPMediaIO.cpp +++ b/src/add-ons/media/plugins/http_streamer/HTTPMediaIO.cpp @@ -59,7 +59,7 @@ public: delete request; } - off_t TotalSize() const + off_t TotalSize() const { return fTotalSize; } @@ -74,43 +74,17 @@ private: HTTPMediaIO::HTTPMediaIO(BUrl url) : - BAdapterIO( - B_MEDIA_STREAMING | B_MEDIA_SEEK_BACKWARD, - B_INFINITE_TIMEOUT), - fInitErr(B_ERROR) + BAdapterIO(B_MEDIA_STREAMING | B_MEDIA_SEEK_BACKWARD, B_INFINITE_TIMEOUT), + fContext(NULL), + fReq(NULL), + fListener(NULL), + fUrl(url) { - fContext = new BUrlContext(); - fContext->AcquireReference(); - - fListener = new FileListener(this); - - fReq = BUrlProtocolRoster::MakeRequest(url, - fListener, fContext); - - if (fReq == NULL) - return; - - if (fReq->Run() < 0) - return; - - fInitErr = B_OK; } HTTPMediaIO::~HTTPMediaIO() { - delete fReq; - delete fListener; - - fContext->ReleaseReference(); - delete fContext; -} - - -status_t -HTTPMediaIO::InitCheck() const -{ - return fInitErr; } @@ -134,3 +108,44 @@ HTTPMediaIO::GetSize(off_t* size) const *size = fListener->TotalSize(); return B_OK; } + + +status_t +HTTPMediaIO::Open() +{ + fContext = new BUrlContext(); + fContext->AcquireReference(); + + fListener = new FileListener(this); + + fReq = BUrlProtocolRoster::MakeRequest(fUrl, + fListener, fContext); + + if (fReq == NULL) + return B_ERROR; + + if (fReq->Run() < 0) + return B_ERROR; + + return BAdapterIO::Open(); +} + + +void +HTTPMediaIO::Close() +{ + delete fReq; + delete fListener; + + fContext->ReleaseReference(); + delete fContext; + + BAdapterIO::Close(); +} + + +status_t +HTTPMediaIO::SeekRequested(off_t position) +{ + return BAdapterIO::SeekRequested(position); +} diff --git a/src/add-ons/media/plugins/http_streamer/HTTPMediaIO.h b/src/add-ons/media/plugins/http_streamer/HTTPMediaIO.h index cc4634e47a..598105f0b1 100644 --- a/src/add-ons/media/plugins/http_streamer/HTTPMediaIO.h +++ b/src/add-ons/media/plugins/http_streamer/HTTPMediaIO.h @@ -20,20 +20,24 @@ public: HTTPMediaIO(BUrl url); virtual ~HTTPMediaIO(); - status_t InitCheck() 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(); + +protected: + virtual status_t SeekRequested(off_t position); + private: BUrlContext* fContext; BUrlRequest* fReq; FileListener* fListener; - status_t fInitErr; + BUrl fUrl; }; #endif diff --git a/src/add-ons/media/plugins/http_streamer/HTTPStreamerPlugin.cpp b/src/add-ons/media/plugins/http_streamer/HTTPStreamerPlugin.cpp index eb49d88097..60f5dac380 100644 --- a/src/add-ons/media/plugins/http_streamer/HTTPStreamerPlugin.cpp +++ b/src/add-ons/media/plugins/http_streamer/HTTPStreamerPlugin.cpp @@ -22,13 +22,14 @@ HTTPStreamer::~HTTPStreamer() status_t HTTPStreamer::Sniff(const BUrl& url, BDataIO** source) { - HTTPMediaIO* ret = new HTTPMediaIO(url); - if (ret->InitCheck() == B_OK) { - *source = ret; + HTTPMediaIO* outSource = new HTTPMediaIO(url); + status_t ret = outSource->Open(); + if (ret == B_OK) { + *source = outSource; return B_OK; } - delete ret; - return B_ERROR; + delete outSource; + return ret; }