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:
@@ -153,6 +153,7 @@ SYSTEM_ADD_ONS_MEDIA += [ FFilterByBuildFeatures
|
|||||||
SYSTEM_ADD_ONS_MEDIA_PLUGINS += [ FFilterByBuildFeatures
|
SYSTEM_ADD_ONS_MEDIA_PLUGINS += [ FFilterByBuildFeatures
|
||||||
ape_reader@x86
|
ape_reader@x86
|
||||||
ffmpeg@ffmpeg
|
ffmpeg@ffmpeg
|
||||||
|
http_streamer
|
||||||
raw_decoder
|
raw_decoder
|
||||||
] ;
|
] ;
|
||||||
|
|
||||||
|
|||||||
@@ -6,32 +6,95 @@
|
|||||||
|
|
||||||
#include "HTTPMediaIO.h"
|
#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)
|
HTTPMediaIO::HTTPMediaIO(BUrl* url)
|
||||||
:
|
:
|
||||||
fContext(),
|
BAdapterIO(
|
||||||
fBuffer(),
|
B_MEDIA_STREAMING | B_MEDIA_MUTABLE_SIZE | B_MEDIA_SEEK_BACKWARD,
|
||||||
fInitErr(B_ERROR)
|
B_INFINITE_TIMEOUT),
|
||||||
|
fInitErr(B_OK)
|
||||||
{
|
{
|
||||||
|
fContext = new BUrlContext();
|
||||||
fContext->AcquireReference();
|
fContext->AcquireReference();
|
||||||
|
|
||||||
fReq = new BHttpRequest(*url);
|
fListener = new FileListener(this);
|
||||||
fReq->SetContext(fContext);
|
|
||||||
|
fReq = BUrlProtocolRoster::MakeRequest(*url,
|
||||||
|
fListener, fContext);
|
||||||
|
|
||||||
fReq->Run();
|
fReq->Run();
|
||||||
fReq->AdoptInputData(fBuffer);
|
|
||||||
|
|
||||||
if (!fReq->IsRunning())
|
|
||||||
return;
|
|
||||||
|
|
||||||
fInitErr = _IntegrityCheck();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
HTTPMediaIO::~HTTPMediaIO()
|
HTTPMediaIO::~HTTPMediaIO()
|
||||||
{
|
{
|
||||||
|
delete fReq;
|
||||||
|
delete fListener;
|
||||||
|
|
||||||
fContext->ReleaseReference();
|
fContext->ReleaseReference();
|
||||||
delete fContext;
|
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
|
ssize_t
|
||||||
HTTPMediaIO::WriteAt(off_t position, const void* buffer, size_t size)
|
HTTPMediaIO::WriteAt(off_t position, const void* buffer, size_t size)
|
||||||
{
|
{
|
||||||
return B_NOT_SUPPORTED;
|
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
|
#define _HTTP_MEDIA_IO_H
|
||||||
|
|
||||||
|
|
||||||
#include <DataIO.h>
|
#include <AdapterIO.h>
|
||||||
#include <HttpRequest.h>
|
#include <FileRequest.h>
|
||||||
#include <Url.h>
|
#include <Url.h>
|
||||||
#include <UrlContext.h>
|
#include <UrlContext.h>
|
||||||
|
#include <UrlProtocolAsynchronousListener.h>
|
||||||
|
|
||||||
|
|
||||||
class HTTPMediaIO : public BMediaIO {
|
class FileListener;
|
||||||
|
|
||||||
|
class HTTPMediaIO : public BAdapterIO {
|
||||||
public:
|
public:
|
||||||
HTTPMediaIO(BUrl* url);
|
HTTPMediaIO(BUrl* url);
|
||||||
virtual ~HTTPMediaIO();
|
virtual ~HTTPMediaIO();
|
||||||
|
|
||||||
status_t InitCheck() const;
|
status_t InitCheck() const;
|
||||||
|
|
||||||
virtual ssize_t ReadAt(off_t position, void* buffer,
|
virtual ssize_t WriteAt(off_t position,
|
||||||
size_t size);
|
const 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;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
status_t _IntegrityCheck();
|
BUrlContext* fContext;
|
||||||
|
BUrlRequest* fReq;
|
||||||
|
FileListener* fListener;
|
||||||
|
|
||||||
BUrlContext* fContext;
|
status_t fInitErr;
|
||||||
BHttpRequest* fReq;
|
|
||||||
|
|
||||||
BMallocIO* fBuffer;
|
|
||||||
status_t fInitErr;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ HTTPStreamer::~HTTPStreamer()
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
HTTPStreamer::Sniff(BUrl* url, BMediaIO** source)
|
HTTPStreamer::Sniff(BUrl* url, BDataIO** source)
|
||||||
{
|
{
|
||||||
HTTPMediaIO* ret = new HTTPMediaIO(url);
|
HTTPMediaIO* ret = new HTTPMediaIO(url);
|
||||||
if (ret->InitCheck() == B_OK) {
|
if (ret->InitCheck() == B_OK) {
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ public:
|
|||||||
HTTPStreamer();
|
HTTPStreamer();
|
||||||
virtual ~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 ;
|
SubDir HAIKU_TOP src add-ons media plugins http_streamer ;
|
||||||
|
|
||||||
UsePrivateHeaders media ;
|
UsePrivateHeaders media shared ;
|
||||||
|
|
||||||
local architectureObject ;
|
local architectureObject ;
|
||||||
for architectureObject in [ MultiArchSubDirSetup ] {
|
for architectureObject in [ MultiArchSubDirSetup ] {
|
||||||
@@ -8,7 +8,7 @@ for architectureObject in [ MultiArchSubDirSetup ] {
|
|||||||
Addon [ MultiArchDefaultGristFiles http_streamer ] :
|
Addon [ MultiArchDefaultGristFiles http_streamer ] :
|
||||||
HTTPStreamerPlugin.cpp
|
HTTPStreamerPlugin.cpp
|
||||||
HTTPMediaIO.cpp
|
HTTPMediaIO.cpp
|
||||||
: be media bnetapi [ BuildFeatureAttribute curl : library ]
|
: be media bnetapi shared
|
||||||
[ TargetLibsupc++ ]
|
[ TargetLibsupc++ ]
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user