http_streamer: General refactor making use of new API
* Use BUrlProtocolRoster instead of BFileRequest. * Removed HTTPMediaIO custom code that now inherits BAdapterIO and make the whole thing more simple. * It work with some formats (flv, mp3, mkv) but ffmpeg fail on others (mp4, 3gp). * GetSize needs improvements.
This commit is contained in:
parent
2a8ae5e815
commit
fbabc74ddf
@ -153,6 +153,7 @@ SYSTEM_ADD_ONS_MEDIA += [ FFilterByBuildFeatures
|
||||
SYSTEM_ADD_ONS_MEDIA_PLUGINS += [ FFilterByBuildFeatures
|
||||
ape_reader@x86
|
||||
ffmpeg@ffmpeg
|
||||
http_streamer
|
||||
raw_decoder
|
||||
] ;
|
||||
|
||||
|
@ -6,32 +6,95 @@
|
||||
|
||||
#include "HTTPMediaIO.h"
|
||||
|
||||
#include <Handler.h>
|
||||
#include <UrlProtocolRoster.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
class FileListener : public BUrlProtocolAsynchronousListener
|
||||
{
|
||||
public:
|
||||
FileListener(BAdapterIO* owner)
|
||||
:
|
||||
BUrlProtocolAsynchronousListener(true),
|
||||
fRequest(NULL),
|
||||
fAdapterIO(owner)
|
||||
{
|
||||
fInputAdapter = fAdapterIO->BuildInputAdapter();
|
||||
}
|
||||
|
||||
virtual ~FileListener() {};
|
||||
|
||||
bool ConnectionSuccessful() const
|
||||
{
|
||||
printf("ConnectionSuccessful\n");
|
||||
return fRequest != NULL;
|
||||
}
|
||||
|
||||
void ConnectionOpened(BUrlRequest* request)
|
||||
{
|
||||
printf("Connection opened\n");
|
||||
if (fRequest != NULL)
|
||||
fRequest->Stop();
|
||||
|
||||
fRequest = request;
|
||||
}
|
||||
|
||||
void DataReceived(BUrlRequest* request, const char* data,
|
||||
off_t position, ssize_t size)
|
||||
{
|
||||
printf("Data received\n");
|
||||
if (request != fRequest)
|
||||
delete request;
|
||||
|
||||
fInputAdapter->Write(data, size);
|
||||
}
|
||||
|
||||
void RequestCompleted(BUrlRequest* request, bool success)
|
||||
{
|
||||
printf("Request completed\n");
|
||||
printf("Success: %s\n", success ? "true" : "false");
|
||||
if (request != fRequest)
|
||||
return;
|
||||
|
||||
fRequest = NULL;
|
||||
delete request;
|
||||
}
|
||||
|
||||
private:
|
||||
BUrlRequest* fRequest;
|
||||
BAdapterIO* fAdapterIO;
|
||||
BInputAdapter* fInputAdapter;
|
||||
};
|
||||
|
||||
|
||||
HTTPMediaIO::HTTPMediaIO(BUrl* url)
|
||||
:
|
||||
fContext(),
|
||||
fBuffer(),
|
||||
fInitErr(B_ERROR)
|
||||
BAdapterIO(
|
||||
B_MEDIA_STREAMING | B_MEDIA_MUTABLE_SIZE | B_MEDIA_SEEK_BACKWARD,
|
||||
B_INFINITE_TIMEOUT),
|
||||
fInitErr(B_OK)
|
||||
{
|
||||
fContext = new BUrlContext();
|
||||
fContext->AcquireReference();
|
||||
|
||||
fReq = new BHttpRequest(*url);
|
||||
fReq->SetContext(fContext);
|
||||
fListener = new FileListener(this);
|
||||
|
||||
fReq = BUrlProtocolRoster::MakeRequest(*url,
|
||||
fListener, fContext);
|
||||
|
||||
fReq->Run();
|
||||
fReq->AdoptInputData(fBuffer);
|
||||
|
||||
if (!fReq->IsRunning())
|
||||
return;
|
||||
|
||||
fInitErr = _IntegrityCheck();
|
||||
}
|
||||
|
||||
|
||||
HTTPMediaIO::~HTTPMediaIO()
|
||||
{
|
||||
delete fReq;
|
||||
delete fListener;
|
||||
|
||||
fContext->ReleaseReference();
|
||||
delete fContext;
|
||||
delete fReq;
|
||||
}
|
||||
|
||||
|
||||
@ -42,70 +105,8 @@ HTTPMediaIO::InitCheck() const
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
HTTPMediaIO::ReadAt(off_t position, void* buffer, size_t size)
|
||||
{
|
||||
return fBuffer->ReadAt(position, buffer, size);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
HTTPMediaIO::WriteAt(off_t position, const void* buffer, size_t size)
|
||||
{
|
||||
return B_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
|
||||
off_t
|
||||
HTTPMediaIO::Seek(off_t position, uint32 seekMode)
|
||||
{
|
||||
return fBuffer->Seek(position, seekMode);
|
||||
}
|
||||
|
||||
off_t
|
||||
HTTPMediaIO::Position() const
|
||||
{
|
||||
return fBuffer->Position();
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
HTTPMediaIO::SetSize(off_t size)
|
||||
{
|
||||
return B_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
HTTPMediaIO::GetSize(off_t* size) const
|
||||
{
|
||||
return B_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
HTTPMediaIO::IsSeekable() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
HTTPMediaIO::IsEndless() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
HTTPMediaIO::_IntegrityCheck()
|
||||
{
|
||||
const BHttpResult& r = dynamic_cast<const BHttpResult&>(fReq->Result());
|
||||
if (r.StatusCode() != 200)
|
||||
return B_ERROR;
|
||||
|
||||
if (BString("OK")!= r.StatusText())
|
||||
return B_ERROR;
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
@ -6,40 +6,31 @@
|
||||
#define _HTTP_MEDIA_IO_H
|
||||
|
||||
|
||||
#include <DataIO.h>
|
||||
#include <HttpRequest.h>
|
||||
#include <AdapterIO.h>
|
||||
#include <FileRequest.h>
|
||||
#include <Url.h>
|
||||
#include <UrlContext.h>
|
||||
#include <UrlProtocolAsynchronousListener.h>
|
||||
|
||||
|
||||
class HTTPMediaIO : public BMediaIO {
|
||||
class FileListener;
|
||||
|
||||
class HTTPMediaIO : public BAdapterIO {
|
||||
public:
|
||||
HTTPMediaIO(BUrl* url);
|
||||
virtual ~HTTPMediaIO();
|
||||
HTTPMediaIO(BUrl* url);
|
||||
virtual ~HTTPMediaIO();
|
||||
|
||||
status_t InitCheck() const;
|
||||
status_t InitCheck() const;
|
||||
|
||||
virtual ssize_t ReadAt(off_t position, void* buffer,
|
||||
size_t size);
|
||||
virtual ssize_t WriteAt(off_t position, const void* buffer,
|
||||
size_t size);
|
||||
virtual off_t Seek(off_t position, uint32 seekMode);
|
||||
virtual off_t Position() const;
|
||||
|
||||
virtual status_t SetSize(off_t size);
|
||||
virtual status_t GetSize(off_t* size) const;
|
||||
|
||||
virtual bool IsSeekable() const;
|
||||
virtual bool IsEndless() const;
|
||||
virtual ssize_t WriteAt(off_t position,
|
||||
const void* buffer, size_t size);
|
||||
|
||||
private:
|
||||
status_t _IntegrityCheck();
|
||||
BUrlContext* fContext;
|
||||
BUrlRequest* fReq;
|
||||
FileListener* fListener;
|
||||
|
||||
BUrlContext* fContext;
|
||||
BHttpRequest* fReq;
|
||||
|
||||
BMallocIO* fBuffer;
|
||||
status_t fInitErr;
|
||||
status_t fInitErr;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -20,7 +20,7 @@ HTTPStreamer::~HTTPStreamer()
|
||||
|
||||
|
||||
status_t
|
||||
HTTPStreamer::Sniff(BUrl* url, BMediaIO** source)
|
||||
HTTPStreamer::Sniff(BUrl* url, BDataIO** source)
|
||||
{
|
||||
HTTPMediaIO* ret = new HTTPMediaIO(url);
|
||||
if (ret->InitCheck() == B_OK) {
|
||||
|
@ -13,7 +13,7 @@ public:
|
||||
HTTPStreamer();
|
||||
virtual ~HTTPStreamer();
|
||||
|
||||
status_t Sniff(BUrl* url, BMediaIO** source);
|
||||
virtual status_t Sniff(BUrl* url, BDataIO** source);
|
||||
};
|
||||
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
SubDir HAIKU_TOP src add-ons media plugins http_streamer ;
|
||||
|
||||
UsePrivateHeaders media ;
|
||||
UsePrivateHeaders media shared ;
|
||||
|
||||
local architectureObject ;
|
||||
for architectureObject in [ MultiArchSubDirSetup ] {
|
||||
@ -8,7 +8,7 @@ for architectureObject in [ MultiArchSubDirSetup ] {
|
||||
Addon [ MultiArchDefaultGristFiles http_streamer ] :
|
||||
HTTPStreamerPlugin.cpp
|
||||
HTTPMediaIO.cpp
|
||||
: be media bnetapi [ BuildFeatureAttribute curl : library ]
|
||||
: be media bnetapi shared
|
||||
[ TargetLibsupc++ ]
|
||||
;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user