Introduce BSimpleMediaClient

* The idea is to move the callback based mechanism into a derived
class. The objects can be composed to create working systems.
* The BMediaClient class supply RegisterInput/RegisterOutput
and BeginInput/BeginOutput is moved to BSimpleMediaClient.
* Various minor fixes.
This commit is contained in:
Dario Casalinuovo
2016-11-29 01:22:35 +01:00
parent 8ab68339fb
commit ecb395852e
10 changed files with 548 additions and 277 deletions
+22 -37
View File
@@ -32,24 +32,6 @@ class BMediaOutput;
// performance_time. // performance_time.
class BMediaClient { class BMediaClient {
public: public:
enum notification {
B_WILL_START = 1, // performance_time
B_WILL_STOP, // performance_time immediate
B_WILL_SEEK, // performance_time media_time
B_WILL_TIMEWARP, // real_time performance_time
B_FORMAT_SUGGESTION, // media_type type, int32 quality,
// media_format* format
};
typedef void (*notify_hook)(void* cookie,
notification what,
...);
// TODO: Should allow BControllable capabilities
// TODO: Add file interface
// TODO: Offline mode is still missing
BMediaClient(const char* name, BMediaClient(const char* name,
media_type type media_type type
= B_MEDIA_UNKNOWN_TYPE, = B_MEDIA_UNKNOWN_TYPE,
@@ -67,19 +49,17 @@ public:
status_t InitCheck() const; status_t InitCheck() const;
// TODO: Should allow BControllable capabilities
// TODO: Add file interface
// TODO: Offline mode is still missing
// To connect pass the BMediaConnection to this class or to another BMediaClient, // To connect pass the BMediaConnection to this class or to another BMediaClient,
// also in another team the connection object will be valid. // also in another team the connection object will be valid.
// When those functions return, the BMediaConnection is added to the // When those functions return, the BMediaConnection is added to the
// list and is visible to other nodes as not connected. // list and is visible to other nodes as not connected.
// This is supplied to support generic connections not related virtual status_t RegisterInput(BMediaInput* input);
// to a certain destination or source node, however for various ambiguity virtual status_t RegisterOutput(BMediaOutput* output);
// reasons we want the BMediaConnection to be declared as input or output.
// You can pass the object returned by this function to another
// BMediaClient::BeginConnection() and then Connect(), so that it
// will automatically connect to this node.
virtual BMediaInput* BeginInput();
virtual BMediaOutput* BeginOutput();
// Bind internally two connections of the same BMediaClient, so that the // Bind internally two connections of the same BMediaClient, so that the
// input will be automatically forwarded to the output just after the // input will be automatically forwarded to the output just after the
@@ -126,8 +106,8 @@ public:
bool IsRunning() const; bool IsRunning() const;
virtual status_t Start(bool force = false); status_t Start(bool force = false);
virtual status_t Stop(bool force = false); status_t Stop(bool force = false);
status_t Seek(bigtime_t mediaTime, status_t Seek(bigtime_t mediaTime,
bigtime_t performanceTime); bigtime_t performanceTime);
status_t Roll(bigtime_t start, bigtime_t stop, status_t Roll(bigtime_t start, bigtime_t stop,
@@ -162,9 +142,6 @@ public:
// Default version just return NULL. // Default version just return NULL.
virtual BMediaAddOn* AddOn(int32* id) const; virtual BMediaAddOn* AddOn(int32* id) const;
void SetNotificationHook(notify_hook notifyHook = NULL,
void* cookie = NULL);
protected: protected:
// This is used when the user want to override the BeginConnection // This is used when the user want to override the BeginConnection
// mechanism, for example to supply your BMediaConnection derived // mechanism, for example to supply your BMediaConnection derived
@@ -172,9 +149,21 @@ protected:
virtual void AddInput(BMediaInput* input); virtual void AddInput(BMediaInput* input);
virtual void AddOutput(BMediaOutput* output); virtual void AddOutput(BMediaOutput* output);
virtual void HandleStart(bigtime_t performanceTime);
virtual void HandleStop(bigtime_t performanceTime);
virtual void HandleSeek(bigtime_t mediaTime,
bigtime_t performanceTime);
virtual void HandleTimeWarp(bigtime_t realTime,
bigtime_t performanceTime);
virtual status_t HandleFormatSuggestion(media_type type,
int32 quality, media_format* format);
// Called from BMediaConnection // Called from BMediaConnection
status_t DisconnectConnection(BMediaConnection* conn); status_t ConnectionDisconnected(BMediaConnection* conn);
status_t ReleaseConnection(BMediaConnection* conn); status_t ConnectionReleased(BMediaConnection* conn);
private: private:
BMediaInput* FindInput( BMediaInput* FindInput(
@@ -202,10 +191,6 @@ private:
bigtime_t fMinLatency; bigtime_t fMinLatency;
bigtime_t fMaxLatency; bigtime_t fMaxLatency;
notify_hook fNotifyHook;
void* fNotifyCookie;
BObjectList<BMediaInput> fInputs; BObjectList<BMediaInput> fInputs;
BObjectList<BMediaOutput> fOutputs; BObjectList<BMediaOutput> fOutputs;
-8
View File
@@ -132,14 +132,6 @@ private:
void _ProduceNewBuffer(const media_timed_event* event, void _ProduceNewBuffer(const media_timed_event* event,
bigtime_t late); bigtime_t late);
void _HandleStart(bigtime_t performanceTime);
void _HandleStop(bigtime_t performanceTime,
bool immediate);
void _HandleSeek(bigtime_t mediaTime,
bigtime_t performanceTime);
void _HandleTimeWarp(bigtime_t realTime,
bigtime_t performanceTime);
BMediaClient* fOwner; BMediaClient* fOwner;
}; };
+8 -51
View File
@@ -30,42 +30,14 @@ namespace BPrivate { namespace media {
// recycle the buffer when you don't want to do anything further. // recycle the buffer when you don't want to do anything further.
class BMediaConnection { class BMediaConnection {
public: public:
enum notification {
B_CONNECTED = 1,
B_DISCONNECTED,
B_PREPARE_TO_CONNECT, // media_format* format, media_source* source,
// char* name
B_CONNECT,
B_DISCONNECT,
B_FORMAT_PROPOSAL, // media_format* format
B_ASK_FORMAT_CHANGE,
B_FORMAT_CHANGED
};
// This function is called when it is the moment to handle a buffer.
typedef void (*process_hook)(BMediaConnection* connection,
BBuffer* buffer);
// Used to notify or inquire the client about what to do when certain
// events happen.
typedef status_t (*notify_hook)(notification what,
BMediaConnection* connection,
...);
virtual ~BMediaConnection(); virtual ~BMediaConnection();
const media_connection& Connection() const; const media_connection& Connection() const;
media_connection_id Id() const; media_connection_id Id() const;
const char* Name() const; const char* Name() const;
// TODO: while most of the objects for both kinds are common BMediaClient* MediaClient() const;
// it would be worthwile to have a private implementation
// so that we can better model the differences and avoid
// problems.
bool IsInput() const; bool IsInput() const;
bool IsOutput() const; bool IsOutput() const;
@@ -88,9 +60,6 @@ public:
bool IsConnected() const; bool IsConnected() const;
void SetCookie(void* cookie);
void* Cookie() const;
// Disconnect this connection. When a connection is disconnected, // Disconnect this connection. When a connection is disconnected,
// it can be reused as brand new. // it can be reused as brand new.
status_t Disconnect(); status_t Disconnect();
@@ -101,26 +70,20 @@ public:
// want to preserve it for future connections just Disconnect() it. // want to preserve it for future connections just Disconnect() it.
status_t Release(); status_t Release();
// Use this to set your callbacks.
void SetHooks(process_hook processHook = NULL,
notify_hook notifyHook = NULL,
void* cookie = NULL);
protected: protected:
BMediaConnection(BMediaClient* owner, BMediaConnection(media_connection_kind kind);
media_connection_kind kind,
media_connection_id id);
// Those callbacks are shared between BMediaInput and BMediaOutput // Those callbacks are shared between BMediaInput and BMediaOutput
virtual void Connected(const media_format& format); virtual void Connected(const media_format& format);
virtual void Disconnected(); virtual void Disconnected();
private: private:
void ConnectionRegistered(BMediaClient* owner,
media_connection_id id);
const media_source& Source() const; const media_source& Source() const;
const media_destination& Destination() const; const media_destination& Destination() const;
void _Init();
media_connection fConnection; media_connection fConnection;
BMediaClient* fOwner; BMediaClient* fOwner;
@@ -130,10 +93,6 @@ private:
// see BMediaClient::Bind. // see BMediaClient::Bind.
BMediaConnection* fBind; BMediaConnection* fBind;
process_hook fProcessHook;
notify_hook fNotifyHook;
void* fBufferCookie;
size_t fBufferSize; size_t fBufferSize;
bigtime_t fBufferDuration; bigtime_t fBufferDuration;
@@ -164,8 +123,7 @@ private:
class BMediaInput : public BMediaConnection { class BMediaInput : public BMediaConnection {
public: public:
BMediaInput(BMediaClient* owner, BMediaInput();
media_connection_id id);
protected: protected:
// Callbacks // Callbacks
@@ -195,8 +153,7 @@ private:
class BMediaOutput : public BMediaConnection { class BMediaOutput : public BMediaConnection {
public: public:
BMediaOutput(BMediaClient* owner, BMediaOutput();
media_connection_id id);
void SetOutputEnabled(bool enabled); void SetOutputEnabled(bool enabled);
bool IsOutputEnabled() const; bool IsOutputEnabled() const;
+178
View File
@@ -0,0 +1,178 @@
/*
* Copyright 2015, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _MEDIA_SIMPLE_CLIENT_H
#define _MEDIA_SIMPLE_CLIENT_H
#include <MediaClient.h>
#include <MediaConnection.h>
namespace BPrivate { namespace media {
class BSimpleMediaInput;
class BSimpleMediaOutput;
class BSimpleMediaClient : public BMediaClient {
public:
enum notification {
B_WILL_START = 1, // performance_time
B_WILL_STOP, // performance_time immediate
B_WILL_SEEK, // performance_time media_time
B_WILL_TIMEWARP, // real_time performance_time
B_FORMAT_SUGGESTION, // media_type type, int32 quality,
// media_format* format
};
typedef void (*notify_hook)(void* cookie,
notification what,
...);
BSimpleMediaClient(const char* name,
media_type type
= B_MEDIA_UNKNOWN_TYPE,
media_client_kind
kind = B_MEDIA_PLAYER
& B_MEDIA_RECORDER);
virtual ~BSimpleMediaClient();
// This is supplied to support generic connections not related
// to a certain destination or source node, however for various ambiguity
// reasons we want the BMediaConnection to be declared as input or output.
// You can pass the object returned by this function to another
// BMediaClient::Connect(), so that it will automatically connect to this node.
virtual BSimpleMediaInput* BeginInput();
virtual BSimpleMediaOutput* BeginOutput();
void SetNotificationHook(notify_hook notifyHook = NULL,
void* cookie = NULL);
protected:
virtual void HandleStart(bigtime_t performanceTime);
virtual void HandleStop(bigtime_t performanceTime);
virtual void HandleSeek(bigtime_t mediaTime,
bigtime_t performanceTime);
virtual void HandleTimeWarp(bigtime_t realTime,
bigtime_t performanceTime);
virtual status_t HandleFormatSuggestion(media_type type,
int32 quality, media_format* format);
private:
notify_hook fNotifyHook;
void* fNotifyCookie;
virtual void _ReservedSimpleMediaClient0();
virtual void _ReservedSimpleMediaClient1();
virtual void _ReservedSimpleMediaClient2();
virtual void _ReservedSimpleMediaClient3();
virtual void _ReservedSimpleMediaClient4();
virtual void _ReservedSimpleMediaClient5();
uint32 fPadding[32];
};
class BSimpleMediaInput : public BMediaInput {
public:
enum notification {
B_CONNECTED = 1,
B_DISCONNECTED,
B_FORMAT_CHANGED
};
// This function is called when it is the moment to handle a buffer.
typedef void (*process_hook)(
BMediaConnection* connection,
BBuffer* buffer);
// Used to notify or inquire the client about what to do when certain
// events happen.
typedef status_t (*notify_hook)(
notification what,
BMediaConnection* connection,
...);
BSimpleMediaInput();
// Use this to set your callbacks.
void SetHooks(process_hook processHook = NULL,
notify_hook notifyHook = NULL,
void* cookie = NULL);
void* Cookie() const;
protected:
virtual void Connected(const media_format& format);
virtual void Disconnected();
void BufferReceived(BBuffer* buffer);
private:
process_hook fProcessHook;
notify_hook fNotifyHook;
void* fBufferCookie;
};
class BSimpleMediaOutput : public BMediaOutput {
public:
enum notification {
B_CONNECTED = 1,
B_DISCONNECTED,
B_PREPARE_TO_CONNECT, // media_format* format, media_source* source,
// char* name
B_FORMAT_PROPOSAL, // media_format* format
B_ASK_FORMAT_CHANGE,
};
// This function is called when it is the moment to handle a buffer.
typedef void (*process_hook)(
BMediaConnection* connection,
BBuffer* buffer);
// Used to notify or inquire the client about what to do when certain
// events happen.
typedef status_t (*notify_hook)(
notification what,
BMediaConnection* connection,
...);
BSimpleMediaOutput();
// Use this to set your callbacks.
void SetHooks(process_hook processHook = NULL,
notify_hook notifyHook = NULL,
void* cookie = NULL);
void* Cookie() const;
protected:
virtual void Connected(const media_format& format);
virtual void Disconnected();
virtual status_t FormatProposal(media_format* format);
private:
process_hook fProcessHook;
notify_hook fNotifyHook;
void* fBufferCookie;
};
}
}
using namespace BPrivate::media;
#endif
+1 -1
View File
@@ -30,7 +30,7 @@ for architectureObject in [ MultiArchSubDirSetup ] {
MediaClientDefs.cpp MediaClientDefs.cpp
MediaConnection.cpp MediaConnection.cpp
MediaRecorder.cpp MediaRecorder.cpp
SimpleMediaClient.cpp
# Public Media Kit # Public Media Kit
Buffer.cpp Buffer.cpp
+48 -37
View File
@@ -71,25 +71,21 @@ BMediaClient::MediaType() const
} }
BMediaInput* status_t
BMediaClient::BeginInput() BMediaClient::RegisterInput(BMediaInput* input)
{ {
CALLED(); input->ConnectionRegistered(this, fLastID++);
BMediaInput* input = new BMediaInput(this, fLastID++);
AddInput(input); AddInput(input);
return input; return B_OK;
} }
BMediaOutput* status_t
BMediaClient::BeginOutput() BMediaClient::RegisterOutput(BMediaOutput* output)
{ {
CALLED(); output->ConnectionRegistered(this, fLastID++);
BMediaOutput* output = new BMediaOutput(this, fLastID++);
AddOutput(output); AddOutput(output);
return output; return B_OK;
} }
@@ -186,24 +182,6 @@ BMediaClient::Disconnect()
} }
status_t
BMediaClient::DisconnectConnection(BMediaConnection* conn)
{
CALLED();
return B_OK;
}
status_t
BMediaClient::ReleaseConnection(BMediaConnection* conn)
{
CALLED();
return B_OK;
}
int32 int32
BMediaClient::CountInputs() const BMediaClient::CountInputs() const
{ {
@@ -469,12 +447,48 @@ BMediaClient::AddOn(int32* id) const
void void
BMediaClient::SetNotificationHook(notify_hook notifyHook, void* cookie) BMediaClient::HandleStart(bigtime_t performanceTime)
{ {
CALLED(); }
fNotifyHook = notifyHook;
fNotifyCookie = cookie; void
BMediaClient::HandleStop(bigtime_t performanceTime)
{
}
void
BMediaClient::HandleSeek(bigtime_t mediaTime, bigtime_t performanceTime)
{
}
void
BMediaClient::HandleTimeWarp(bigtime_t realTime, bigtime_t performanceTime)
{
}
status_t
BMediaClient::HandleFormatSuggestion(media_type type, int32 quality,
media_format* format)
{
return B_ERROR;
}
status_t
BMediaClient::ConnectionReleased(BMediaConnection* connection)
{
return B_OK;
}
status_t
BMediaClient::ConnectionDisconnected(BMediaConnection* connection)
{
return B_OK;
} }
@@ -483,9 +497,6 @@ BMediaClient::_Init()
{ {
CALLED(); CALLED();
fNotifyHook = NULL;
fNotifyCookie = NULL;
BMediaRoster* roster = BMediaRoster::Roster(&fInitErr); BMediaRoster* roster = BMediaRoster::Roster(&fInitErr);
if (fInitErr == B_OK && roster != NULL) if (fInitErr == B_OK && roster != NULL)
fInitErr = roster->RegisterNode(fNode); fInitErr = roster->RegisterNode(fNode);
+13 -68
View File
@@ -280,19 +280,16 @@ BMediaClientNode::FormatSuggestionRequested(media_type type,
return B_MEDIA_BAD_FORMAT; return B_MEDIA_BAD_FORMAT;
} }
if (fOwner->fNotifyHook != NULL) { status_t ret = fOwner->HandleFormatSuggestion(type, quality, format);
status_t result = B_OK; if (ret != B_OK) {
(*fOwner->fNotifyHook)(fOwner->fNotifyCookie,
BMediaClient::B_FORMAT_SUGGESTION,
type, quality, format, &result);
return result;
} else {
// In that case we return just a very generic format. // In that case we return just a very generic format.
media_format outFormat; media_format outFormat;
outFormat.type = fOwner->MediaType(); outFormat.type = fOwner->MediaType();
*format = outFormat; *format = outFormat;
return B_OK; return B_OK;
} }
return ret;
} }
@@ -539,20 +536,25 @@ BMediaClientNode::HandleEvent(const media_timed_event* event,
case BTimedEventQueue::B_START: case BTimedEventQueue::B_START:
{ {
if (RunState() != B_STARTED) if (RunState() != B_STARTED)
_HandleStart(event->event_time); fOwner->HandleStart(event->event_time);
break; break;
} }
case BTimedEventQueue::B_STOP: case BTimedEventQueue::B_STOP:
_HandleStop(event->event_time, true); {
fOwner->HandleStop(event->event_time);
EventQueue()->FlushEvents(0, BTimedEventQueue::B_ALWAYS, true,
BTimedEventQueue::B_HANDLE_BUFFER);
break; break;
}
case BTimedEventQueue::B_SEEK: case BTimedEventQueue::B_SEEK:
_HandleSeek(event->event_time, event->bigdata); fOwner->HandleSeek(event->event_time, event->bigdata);
break; break;
case BTimedEventQueue::B_WARP: case BTimedEventQueue::B_WARP:
_HandleTimeWarp(event->event_time, event->bigdata); fOwner->HandleTimeWarp(event->event_time, event->bigdata);
break; break;
} }
} }
@@ -595,60 +597,3 @@ BMediaClientNode::_ProduceNewBuffer(const media_timed_event* event,
// event.pointer == connection // event.pointer == connection
} }
void
BMediaClientNode::_HandleStart(bigtime_t performanceTime)
{
CALLED();
if (fOwner->fNotifyHook != NULL) {
(*fOwner->fNotifyHook)(fOwner->fNotifyCookie,
BMediaClient::B_WILL_START,
performanceTime);
}
}
void
BMediaClientNode::_HandleStop(bigtime_t performanceTime,
bool immediate)
{
CALLED();
if (fOwner->fNotifyHook != NULL) {
(*fOwner->fNotifyHook)(fOwner->fNotifyCookie,
BMediaClient::B_WILL_STOP,
performanceTime, immediate);
}
EventQueue()->FlushEvents(0, BTimedEventQueue::B_ALWAYS, true,
BTimedEventQueue::B_HANDLE_BUFFER);
}
void
BMediaClientNode::_HandleSeek(bigtime_t mediaTime,
bigtime_t performanceTime)
{
CALLED();
if (fOwner->fNotifyHook != NULL) {
(*fOwner->fNotifyHook)(fOwner->fNotifyCookie,
BMediaClient::B_WILL_SEEK,
performanceTime, mediaTime);
}
}
void
BMediaClientNode::_HandleTimeWarp(bigtime_t realTime,
bigtime_t performanceTime)
{
CALLED();
if (fOwner->fNotifyHook != NULL) {
(*fOwner->fNotifyHook)(fOwner->fNotifyCookie,
BMediaClient::B_WILL_TIMEWARP,
realTime, performanceTime);
}
}
+28 -67
View File
@@ -8,33 +8,17 @@
#include "debug.h" #include "debug.h"
BMediaConnection::BMediaConnection(BMediaClient* owner, BMediaConnection::BMediaConnection(media_connection_kind kind)
media_connection_kind kind,
media_connection_id id)
: :
fOwner(owner), fOwner(NULL),
fBind(NULL) fBind(NULL),
fBufferGroup(NULL)
{ {
CALLED(); CALLED();
_Init();
fConnection.kind = kind; fConnection.kind = kind;
fConnection.id = id; fConnection.id = -1;
fConnection.client = fOwner->Client(); //fConnection.client = media_client::null;
if (IsOutput()) {
fConnection.source.port = fOwner->fNode->ControlPort();
fConnection.source.id = fConnection.id;
fConnection.destination = media_destination::null;
} else {
// IsInput()
fConnection.destination.port = fOwner->fNode->ControlPort();
fConnection.destination.id = fConnection.id;
fConnection.source = media_source::null;
}
} }
@@ -115,15 +99,6 @@ BMediaConnection::IsConnected() const
} }
void*
BMediaConnection::Cookie() const
{
CALLED();
return fBufferCookie;
}
status_t status_t
BMediaConnection::Disconnect() BMediaConnection::Disconnect()
{ {
@@ -132,7 +107,7 @@ BMediaConnection::Disconnect()
delete fBufferGroup; delete fBufferGroup;
fBufferGroup = NULL; fBufferGroup = NULL;
return fOwner->DisconnectConnection(this); return fOwner->ConnectionDisconnected(this);
} }
@@ -141,19 +116,7 @@ BMediaConnection::Release()
{ {
CALLED(); CALLED();
return fOwner->ReleaseConnection(this); return fOwner->ConnectionReleased(this);
}
void
BMediaConnection::SetHooks(process_hook processHook,
notify_hook notifyHook, void* cookie)
{
CALLED();
fProcessHook = processHook;
fNotifyHook = notifyHook;
fBufferCookie = cookie;
} }
@@ -196,9 +159,6 @@ BMediaConnection::BufferDuration() const
void void
BMediaConnection::Connected(const media_format& format) BMediaConnection::Connected(const media_format& format)
{ {
if (fNotifyHook != NULL)
(*fNotifyHook)(B_CONNECTED, this);
fConnected = true; fConnected = true;
} }
@@ -206,21 +166,29 @@ BMediaConnection::Connected(const media_format& format)
void void
BMediaConnection::Disconnected() BMediaConnection::Disconnected()
{ {
if (fNotifyHook != NULL)
(*fNotifyHook)(B_DISCONNECTED, this);
fConnected = false; fConnected = false;
} }
void void
BMediaConnection::_Init() BMediaConnection::ConnectionRegistered(BMediaClient* owner,
media_connection_id id)
{ {
CALLED(); fOwner = owner;
fConnection.id = id;
fConnection.client = fOwner->Client();
fBufferGroup = NULL; if (IsOutput()) {
fNotifyHook = NULL; fConnection.source.port = fOwner->fNode->ControlPort();
fProcessHook = NULL; fConnection.source.id = fConnection.id;
fConnection.destination = media_destination::null;
} else {
fConnection.destination.port = fOwner->fNode->ControlPort();
fConnection.destination.id = fConnection.id;
fConnection.source = media_source::null;
}
} }
@@ -251,9 +219,9 @@ void BMediaConnection::_ReservedMediaConnection9() {}
void BMediaConnection::_ReservedMediaConnection10() {} void BMediaConnection::_ReservedMediaConnection10() {}
BMediaInput::BMediaInput(BMediaClient* owner, media_connection_id id) BMediaInput::BMediaInput()
: :
BMediaConnection(owner, B_MEDIA_INPUT, id) BMediaConnection(B_MEDIA_INPUT)
{ {
} }
@@ -282,8 +250,6 @@ BMediaInput::BufferReceived(BBuffer* buffer)
{ {
CALLED(); CALLED();
if (fProcessHook != NULL)
fProcessHook(this, buffer);
} }
@@ -300,9 +266,9 @@ void BMediaInput::_ReservedMediaInput9() {}
void BMediaInput::_ReservedMediaInput10() {} void BMediaInput::_ReservedMediaInput10() {}
BMediaOutput::BMediaOutput(BMediaClient* owner, media_connection_id id) BMediaOutput::BMediaOutput()
: :
BMediaConnection(owner, B_MEDIA_OUTPUT, id) BMediaConnection(B_MEDIA_OUTPUT)
{ {
} }
@@ -328,12 +294,7 @@ BMediaOutput::PrepareToConnect(media_format* format)
status_t status_t
BMediaOutput::FormatProposal(media_format* format) BMediaOutput::FormatProposal(media_format* format)
{ {
if (fOwner->fNotifyHook != NULL) {
return (*fNotifyHook)(BMediaConnection::B_FORMAT_PROPOSAL,
this, format);
} else
*format = AcceptedFormat(); *format = AcceptedFormat();
return B_OK; return B_OK;
} }
+242
View File
@@ -0,0 +1,242 @@
/*
* Copyright 2015, Dario Casalinuovo. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#include <SimpleMediaClient.h>
#include <debug.h>
BSimpleMediaClient::BSimpleMediaClient(const char* name,
media_type type, media_client_kind kind)
:
BMediaClient(name, type, kind),
fNotifyHook(NULL),
fNotifyCookie(NULL)
{
CALLED();
}
BSimpleMediaClient::~BSimpleMediaClient()
{
CALLED();
}
BSimpleMediaInput*
BSimpleMediaClient::BeginInput()
{
CALLED();
BSimpleMediaInput* input = new BSimpleMediaInput();
RegisterInput(input);
return input;
}
BSimpleMediaOutput*
BSimpleMediaClient::BeginOutput()
{
CALLED();
BSimpleMediaOutput* output = new BSimpleMediaOutput();
RegisterOutput(output);
return output;
}
void
BSimpleMediaClient::SetNotificationHook(notify_hook notifyHook, void* cookie)
{
CALLED();
fNotifyHook = notifyHook;
fNotifyCookie = cookie;
}
void
BSimpleMediaClient::HandleStart(bigtime_t performanceTime)
{
if (fNotifyHook != NULL) {
(*fNotifyHook)(fNotifyCookie,
BSimpleMediaClient::B_WILL_START,
performanceTime);
}
}
void
BSimpleMediaClient::HandleStop(bigtime_t performanceTime)
{
if (fNotifyHook != NULL) {
(*fNotifyHook)(fNotifyCookie,
BSimpleMediaClient::B_WILL_STOP,
performanceTime);
}
}
void
BSimpleMediaClient::HandleSeek(bigtime_t mediaTime, bigtime_t performanceTime)
{
if (fNotifyHook != NULL) {
(*fNotifyHook)(fNotifyCookie,
BSimpleMediaClient::B_WILL_SEEK,
performanceTime, mediaTime);
}
}
void
BSimpleMediaClient::HandleTimeWarp(bigtime_t realTime, bigtime_t performanceTime)
{
if (fNotifyHook != NULL) {
(*fNotifyHook)(fNotifyCookie,
BSimpleMediaClient::B_WILL_TIMEWARP,
realTime, performanceTime);
}
}
status_t
BSimpleMediaClient::HandleFormatSuggestion(media_type type, int32 quality,
media_format* format)
{
if (fNotifyHook != NULL) {
status_t result = B_ERROR;
(*fNotifyHook)(fNotifyCookie,
BSimpleMediaClient::B_FORMAT_SUGGESTION,
type, quality, format, &result);
return result;
}
return B_ERROR;
}
void BSimpleMediaClient::_ReservedSimpleMediaClient0() {}
void BSimpleMediaClient::_ReservedSimpleMediaClient1() {}
void BSimpleMediaClient::_ReservedSimpleMediaClient2() {}
void BSimpleMediaClient::_ReservedSimpleMediaClient3() {}
void BSimpleMediaClient::_ReservedSimpleMediaClient4() {}
void BSimpleMediaClient::_ReservedSimpleMediaClient5() {}
BSimpleMediaInput::BSimpleMediaInput()
:
BMediaInput()
{
}
void
BSimpleMediaInput::Connected(const media_format& format)
{
if (fNotifyHook != NULL)
(*fNotifyHook)(B_CONNECTED, this);
BMediaInput::Connected(format);
}
void
BSimpleMediaInput::Disconnected()
{
if (fNotifyHook != NULL)
(*fNotifyHook)(B_DISCONNECTED, this);
BMediaConnection::Disconnected();
}
void
BSimpleMediaInput::SetHooks(process_hook processHook,
notify_hook notifyHook, void* cookie)
{
CALLED();
fProcessHook = processHook;
fNotifyHook = notifyHook;
fBufferCookie = cookie;
}
void*
BSimpleMediaInput::Cookie() const
{
CALLED();
return fBufferCookie;
}
void
BSimpleMediaInput::BufferReceived(BBuffer* buffer)
{
CALLED();
if (fProcessHook != NULL)
(*fProcessHook)((BMediaConnection*)this, buffer);
}
BSimpleMediaOutput::BSimpleMediaOutput()
:
BMediaOutput()
{
}
status_t
BSimpleMediaOutput::FormatProposal(media_format* format)
{
if (fNotifyHook != NULL) {
return (*fNotifyHook)(BSimpleMediaOutput::B_FORMAT_PROPOSAL,
this, format);
}
return BMediaOutput::FormatProposal(format);
}
void
BSimpleMediaOutput::Connected(const media_format& format)
{
if (fNotifyHook != NULL)
(*fNotifyHook)(B_CONNECTED, this);
BMediaConnection::Connected(format);
}
void
BSimpleMediaOutput::Disconnected()
{
if (fNotifyHook != NULL)
(*fNotifyHook)(B_DISCONNECTED, this);
BMediaConnection::Disconnected();
}
void
BSimpleMediaOutput::SetHooks(process_hook processHook,
notify_hook notifyHook, void* cookie)
{
CALLED();
fProcessHook = processHook;
fNotifyHook = notifyHook;
fBufferCookie = cookie;
}
void*
BSimpleMediaOutput::Cookie() const
{
CALLED();
return fBufferCookie;
}
@@ -3,7 +3,7 @@
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#include <MediaClient.h> #include <SimpleMediaClient.h>
#include <MediaConnection.h> #include <MediaConnection.h>
#include <SupportDefs.h> #include <SupportDefs.h>
@@ -18,18 +18,18 @@
#endif #endif
static BMediaClient* sProducer = NULL; static BSimpleMediaClient* sProducer = NULL;
static BMediaClient* sConsumer = NULL; static BSimpleMediaClient* sConsumer = NULL;
static BMediaClient* sFilter = NULL; static BSimpleMediaClient* sFilter = NULL;
void _InitClients(bool hasFilter) void _InitClients(bool hasFilter)
{ {
sProducer = new BMediaClient("MediaClientProducer"); sProducer = new BSimpleMediaClient("MediaClientProducer");
sConsumer = new BMediaClient("MediaClientConsumer"); sConsumer = new BSimpleMediaClient("MediaClientConsumer");
if (hasFilter) if (hasFilter)
sFilter = new BMediaClient("MediaClientFilter"); sFilter = new BSimpleMediaClient("MediaClientFilter");
else else
sFilter = NULL; sFilter = NULL;
} }