diff --git a/src/add-ons/media/plugins/http_streamer/HTTPMediaIO.cpp b/src/add-ons/media/plugins/http_streamer/HTTPMediaIO.cpp new file mode 100644 index 0000000000..1498a5abe1 --- /dev/null +++ b/src/add-ons/media/plugins/http_streamer/HTTPMediaIO.cpp @@ -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(fReq->Result()); + if (r.StatusCode() != 200) + return B_ERROR; + + if (BString("OK")!= r.StatusText()) + return B_ERROR; + + return B_OK; +} diff --git a/src/add-ons/media/plugins/http_streamer/HTTPMediaIO.h b/src/add-ons/media/plugins/http_streamer/HTTPMediaIO.h new file mode 100644 index 0000000000..e769c2c34c --- /dev/null +++ b/src/add-ons/media/plugins/http_streamer/HTTPMediaIO.h @@ -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 +#include +#include +#include + + +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 diff --git a/src/add-ons/media/plugins/http_streamer/HTTPStreamerPlugin.cpp b/src/add-ons/media/plugins/http_streamer/HTTPStreamerPlugin.cpp new file mode 100644 index 0000000000..bd1f945740 --- /dev/null +++ b/src/add-ons/media/plugins/http_streamer/HTTPStreamerPlugin.cpp @@ -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(); +} diff --git a/src/add-ons/media/plugins/http_streamer/HTTPStreamerPlugin.h b/src/add-ons/media/plugins/http_streamer/HTTPStreamerPlugin.h new file mode 100644 index 0000000000..c51f43c408 --- /dev/null +++ b/src/add-ons/media/plugins/http_streamer/HTTPStreamerPlugin.h @@ -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 diff --git a/src/add-ons/media/plugins/http_streamer/Jamfile b/src/add-ons/media/plugins/http_streamer/Jamfile new file mode 100644 index 0000000000..5ed6564eca --- /dev/null +++ b/src/add-ons/media/plugins/http_streamer/Jamfile @@ -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++ ] + ; + } +}