http_streamer: Add basic draft version
This commit is contained in:
@@ -0,0 +1,111 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016, Dario Casalinuovo
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "HTTPMediaIO.h"
|
||||||
|
|
||||||
|
|
||||||
|
HTTPMediaIO::HTTPMediaIO(BUrl* url)
|
||||||
|
:
|
||||||
|
fContext(),
|
||||||
|
fBuffer(),
|
||||||
|
fInitErr(B_ERROR)
|
||||||
|
{
|
||||||
|
fContext->AcquireReference();
|
||||||
|
|
||||||
|
fReq = new BHttpRequest(*url);
|
||||||
|
fReq->SetContext(fContext);
|
||||||
|
fReq->Run();
|
||||||
|
fReq->AdoptInputData(fBuffer);
|
||||||
|
|
||||||
|
if (!fReq->IsRunning())
|
||||||
|
return;
|
||||||
|
|
||||||
|
fInitErr = _IntegrityCheck();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
HTTPMediaIO::~HTTPMediaIO()
|
||||||
|
{
|
||||||
|
fContext->ReleaseReference();
|
||||||
|
delete fContext;
|
||||||
|
delete fReq;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
HTTPMediaIO::InitCheck() const
|
||||||
|
{
|
||||||
|
return fInitErr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016, Dario Casalinuovo
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
#ifndef _HTTP_MEDIA_IO_H
|
||||||
|
#define _HTTP_MEDIA_IO_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <DataIO.h>
|
||||||
|
#include <HttpRequest.h>
|
||||||
|
#include <Url.h>
|
||||||
|
#include <UrlContext.h>
|
||||||
|
|
||||||
|
|
||||||
|
class HTTPMediaIO : public BMediaIO {
|
||||||
|
public:
|
||||||
|
HTTPMediaIO(BUrl* url);
|
||||||
|
virtual ~HTTPMediaIO();
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
private:
|
||||||
|
status_t _IntegrityCheck();
|
||||||
|
|
||||||
|
BUrlContext* fContext;
|
||||||
|
BHttpRequest* fReq;
|
||||||
|
|
||||||
|
BMallocIO* fBuffer;
|
||||||
|
status_t fInitErr;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016, Dario Casalinuovo
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "HTTPStreamerPlugin.h"
|
||||||
|
|
||||||
|
#include "HTTPMediaIO.h"
|
||||||
|
|
||||||
|
|
||||||
|
HTTPStreamer::HTTPStreamer()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
HTTPStreamer::~HTTPStreamer()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
HTTPStreamer::Sniff(BUrl* url, BMediaIO** source)
|
||||||
|
{
|
||||||
|
HTTPMediaIO* ret = new HTTPMediaIO(url);
|
||||||
|
if (ret->InitCheck() == B_OK) {
|
||||||
|
*source = ret;
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
delete ret;
|
||||||
|
return B_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Streamer*
|
||||||
|
HTTPStreamerPlugin::NewStreamer()
|
||||||
|
{
|
||||||
|
return new HTTPStreamer();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
MediaPlugin *instantiate_plugin()
|
||||||
|
{
|
||||||
|
return new HTTPStreamerPlugin();
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016, Dario Casalinuovo
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
#ifndef _HTTP_STREAMER_PLUGIN_H
|
||||||
|
#define _HTTP_STREAMER_PLUGIN_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "StreamerPlugin.h"
|
||||||
|
|
||||||
|
class HTTPStreamer : public Streamer {
|
||||||
|
public:
|
||||||
|
HTTPStreamer();
|
||||||
|
virtual ~HTTPStreamer();
|
||||||
|
|
||||||
|
status_t Sniff(BUrl* url, BMediaIO** source);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class HTTPStreamerPlugin : public StreamerPlugin {
|
||||||
|
public:
|
||||||
|
virtual Streamer* NewStreamer();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // _HTTP_STREAMER_PLUGIN_H
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
SubDir HAIKU_TOP src add-ons media plugins http_streamer ;
|
||||||
|
|
||||||
|
UsePrivateHeaders media ;
|
||||||
|
|
||||||
|
local architectureObject ;
|
||||||
|
for architectureObject in [ MultiArchSubDirSetup ] {
|
||||||
|
on $(architectureObject) {
|
||||||
|
Addon [ MultiArchDefaultGristFiles http_streamer ] :
|
||||||
|
HTTPStreamerPlugin.cpp
|
||||||
|
HTTPMediaIO.cpp
|
||||||
|
: be media bnetapi [ BuildFeatureAttribute curl : library ]
|
||||||
|
[ TargetLibsupc++ ]
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user