http_streamer: Mutable flag is chosen at runtime

* BeOS Radio now works.
This commit is contained in:
Dario Casalinuovo 2016-07-03 15:25:42 +02:00
parent 9f2deec26f
commit b4e751b890
2 changed files with 22 additions and 15 deletions

View File

@ -81,12 +81,12 @@ private:
HTTPMediaIO::HTTPMediaIO(BUrl url) HTTPMediaIO::HTTPMediaIO(BUrl url)
: :
BAdapterIO(B_MEDIA_STREAMING | B_MEDIA_SEEK_BACKWARD, HTTP_TIMEOUT), BAdapterIO(HTTP_TIMEOUT),
fContext(NULL), fContext(NULL),
fReq(NULL), fReq(NULL),
fListener(NULL), fListener(NULL),
fUrl(url), 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 ssize_t
HTTPMediaIO::WriteAt(off_t position, const void* buffer, size_t size) 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 status_t
HTTPMediaIO::Open() HTTPMediaIO::Open()
{ {
@ -142,7 +140,14 @@ HTTPMediaIO::Open()
if (ret != B_OK) if (ret != B_OK)
return ret; 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(); return BAdapterIO::Open();
} }

View File

@ -20,11 +20,12 @@ public:
HTTPMediaIO(BUrl url); HTTPMediaIO(BUrl url);
virtual ~HTTPMediaIO(); virtual ~HTTPMediaIO();
virtual void GetFlags(int32* flags) const;
virtual ssize_t WriteAt(off_t position, virtual ssize_t WriteAt(off_t position,
const void* buffer, size_t size); const void* buffer, size_t size);
virtual status_t SetSize(off_t size); virtual status_t SetSize(off_t size);
virtual status_t GetSize(off_t* size) const;
virtual status_t Open(); virtual status_t Open();
virtual void Close(); virtual void Close();
@ -39,6 +40,7 @@ private:
BUrl fUrl; BUrl fUrl;
off_t fTotalSize; off_t fTotalSize;
bool fIsMutable;
}; };
#endif #endif