http_streamer: Fix different issues
* Cleanup object management. * Remove Close() and use the destructor in place. * Release listener sem on exit. * Return when there's a request mismatch. * Add some debugging. * MediaPlayer crashes are fixed as result of the patchset.
This commit is contained in:
@@ -10,6 +10,8 @@
|
|||||||
#include <HttpRequest.h>
|
#include <HttpRequest.h>
|
||||||
#include <UrlProtocolRoster.h>
|
#include <UrlProtocolRoster.h>
|
||||||
|
|
||||||
|
#include "debug.h"
|
||||||
|
|
||||||
|
|
||||||
// 10 seconds timeout
|
// 10 seconds timeout
|
||||||
#define HTTP_TIMEOUT 10000000
|
#define HTTP_TIMEOUT 10000000
|
||||||
@@ -29,7 +31,10 @@ public:
|
|||||||
fInitSem = create_sem(0, "http_streamer init sem");
|
fInitSem = create_sem(0, "http_streamer init sem");
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~FileListener() {};
|
virtual ~FileListener()
|
||||||
|
{
|
||||||
|
_ReleaseInit();
|
||||||
|
}
|
||||||
|
|
||||||
bool ConnectionSuccessful() const
|
bool ConnectionSuccessful() const
|
||||||
{
|
{
|
||||||
@@ -47,8 +52,10 @@ public:
|
|||||||
void DataReceived(BUrlRequest* request, const char* data,
|
void DataReceived(BUrlRequest* request, const char* data,
|
||||||
off_t position, ssize_t size)
|
off_t position, ssize_t size)
|
||||||
{
|
{
|
||||||
if (request != fRequest)
|
if (request != fRequest) {
|
||||||
delete request;
|
delete request;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
BHttpRequest* httpReq = dynamic_cast<BHttpRequest*>(request);
|
BHttpRequest* httpReq = dynamic_cast<BHttpRequest*>(request);
|
||||||
if (httpReq != NULL) {
|
if (httpReq != NULL) {
|
||||||
@@ -111,16 +118,29 @@ HTTPMediaIO::HTTPMediaIO(BUrl url)
|
|||||||
BAdapterIO(B_MEDIA_STREAMING | B_MEDIA_SEEKABLE, HTTP_TIMEOUT),
|
BAdapterIO(B_MEDIA_STREAMING | B_MEDIA_SEEKABLE, HTTP_TIMEOUT),
|
||||||
fContext(NULL),
|
fContext(NULL),
|
||||||
fReq(NULL),
|
fReq(NULL),
|
||||||
fReqThread(-1),
|
|
||||||
fListener(NULL),
|
fListener(NULL),
|
||||||
|
fReqThread(-1),
|
||||||
fUrl(url),
|
fUrl(url),
|
||||||
fIsMutable(false)
|
fIsMutable(false)
|
||||||
{
|
{
|
||||||
|
CALLED();
|
||||||
|
|
||||||
|
// The context has the same life time of the object
|
||||||
|
fContext = new BUrlContext();
|
||||||
|
fContext->AcquireReference();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
HTTPMediaIO::~HTTPMediaIO()
|
HTTPMediaIO::~HTTPMediaIO()
|
||||||
{
|
{
|
||||||
|
CALLED();
|
||||||
|
|
||||||
|
fReq->Stop();
|
||||||
|
status_t status;
|
||||||
|
wait_for_thread(fReqThread, &status);
|
||||||
|
|
||||||
|
fContext->ReleaseReference();
|
||||||
|
delete fContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -150,8 +170,7 @@ HTTPMediaIO::SetSize(off_t size)
|
|||||||
status_t
|
status_t
|
||||||
HTTPMediaIO::Open()
|
HTTPMediaIO::Open()
|
||||||
{
|
{
|
||||||
fContext = new BUrlContext();
|
CALLED();
|
||||||
fContext->AcquireReference();
|
|
||||||
|
|
||||||
fListener = new FileListener(this);
|
fListener = new FileListener(this);
|
||||||
|
|
||||||
@@ -173,23 +192,6 @@ HTTPMediaIO::Open()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
HTTPMediaIO::Close()
|
|
||||||
{
|
|
||||||
fReq->Stop();
|
|
||||||
status_t status;
|
|
||||||
wait_for_thread(fReqThread, &status);
|
|
||||||
|
|
||||||
delete fReq;
|
|
||||||
delete fListener;
|
|
||||||
|
|
||||||
fContext->ReleaseReference();
|
|
||||||
delete fContext;
|
|
||||||
|
|
||||||
BAdapterIO::Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
HTTPMediaIO::IsRunning() const
|
HTTPMediaIO::IsRunning() const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ public:
|
|||||||
virtual status_t SetSize(off_t size);
|
virtual status_t SetSize(off_t size);
|
||||||
|
|
||||||
virtual status_t Open();
|
virtual status_t Open();
|
||||||
virtual void Close();
|
|
||||||
|
|
||||||
virtual bool IsRunning() const;
|
virtual bool IsRunning() const;
|
||||||
|
|
||||||
|
|||||||
@@ -8,21 +8,28 @@
|
|||||||
|
|
||||||
#include "HTTPMediaIO.h"
|
#include "HTTPMediaIO.h"
|
||||||
|
|
||||||
|
#include "debug.h"
|
||||||
|
|
||||||
|
|
||||||
HTTPStreamer::HTTPStreamer()
|
HTTPStreamer::HTTPStreamer()
|
||||||
{
|
{
|
||||||
|
CALLED();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
HTTPStreamer::~HTTPStreamer()
|
HTTPStreamer::~HTTPStreamer()
|
||||||
{
|
{
|
||||||
|
CALLED();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
HTTPStreamer::Sniff(const BUrl& url, BDataIO** source)
|
HTTPStreamer::Sniff(const BUrl& url, BDataIO** source)
|
||||||
{
|
{
|
||||||
|
CALLED();
|
||||||
|
|
||||||
HTTPMediaIO* outSource = new HTTPMediaIO(url);
|
HTTPMediaIO* outSource = new HTTPMediaIO(url);
|
||||||
|
|
||||||
status_t ret = outSource->Open();
|
status_t ret = outSource->Open();
|
||||||
if (ret == B_OK) {
|
if (ret == B_OK) {
|
||||||
*source = outSource;
|
*source = outSource;
|
||||||
|
|||||||
Reference in New Issue
Block a user