Skip to content

Commit

Permalink
http_streamer: Sync with BAdapterIO changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Numerio committed Jun 30, 2016
1 parent 345dba5 commit 93a1f9d
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 40 deletions.
79 changes: 47 additions & 32 deletions src/add-ons/media/plugins/http_streamer/HTTPMediaIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class FileListener : public BUrlProtocolAsynchronousListener
delete request;
}

off_t TotalSize() const
off_t TotalSize() const
{
return fTotalSize;
}
Expand All @@ -74,43 +74,17 @@ class FileListener : public BUrlProtocolAsynchronousListener

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;
}


Expand All @@ -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);
}
10 changes: 7 additions & 3 deletions src/add-ons/media/plugins/http_streamer/HTTPMediaIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,24 @@ class HTTPMediaIO : public BAdapterIO {
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
11 changes: 6 additions & 5 deletions src/add-ons/media/plugins/http_streamer/HTTPStreamerPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand Down

0 comments on commit 93a1f9d

Please sign in to comment.