SimpleMediaClient: Use virtual inheritance to reduce duplication
This commit is contained in:
parent
d1742cc336
commit
83cd87d033
@ -79,54 +79,18 @@ private:
|
||||
};
|
||||
|
||||
|
||||
class BSimpleMediaInput : public BMediaInput {
|
||||
class BSimpleMediaConnection : public virtual BMediaConnection {
|
||||
public:
|
||||
enum notification {
|
||||
B_CONNECTED = 1,
|
||||
B_DISCONNECTED,
|
||||
// Inputs
|
||||
B_INPUT_CONNECTED = 1,
|
||||
B_INPUT_DISCONNECTED,
|
||||
|
||||
B_FORMAT_CHANGED
|
||||
};
|
||||
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,
|
||||
// Outputs
|
||||
B_OUTPUT_CONNECTED,
|
||||
B_OUTPUT_DISCONNECTED,
|
||||
|
||||
B_PREPARE_TO_CONNECT, // media_format* format, media_source* source,
|
||||
// char* name
|
||||
@ -147,8 +111,6 @@ public:
|
||||
BMediaConnection* connection,
|
||||
...);
|
||||
|
||||
BSimpleMediaOutput();
|
||||
|
||||
// Use this to set your callbacks.
|
||||
void SetHooks(process_hook processHook = NULL,
|
||||
notify_hook notifyHook = NULL,
|
||||
@ -156,16 +118,37 @@ public:
|
||||
|
||||
void* Cookie() const;
|
||||
|
||||
protected:
|
||||
BSimpleMediaConnection(
|
||||
media_connection_kinds kinds);
|
||||
|
||||
process_hook fProcessHook;
|
||||
notify_hook fNotifyHook;
|
||||
void* fBufferCookie;
|
||||
};
|
||||
|
||||
|
||||
class BSimpleMediaInput : public BSimpleMediaConnection, public BMediaInput {
|
||||
public:
|
||||
BSimpleMediaInput();
|
||||
|
||||
protected:
|
||||
virtual void Connected(const media_format& format);
|
||||
virtual void Disconnected();
|
||||
|
||||
virtual void BufferReceived(BBuffer* buffer);
|
||||
};
|
||||
|
||||
|
||||
class BSimpleMediaOutput : public BSimpleMediaConnection, public BMediaOutput {
|
||||
public:
|
||||
BSimpleMediaOutput();
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
|
@ -61,7 +61,7 @@ void
|
||||
BSimpleMediaClient::HandleStart(bigtime_t performanceTime)
|
||||
{
|
||||
if (fNotifyHook != NULL) {
|
||||
(*fNotifyHook)(fNotifyCookie,
|
||||
(*fNotifyHook)(BSimpleMediaClient::fNotifyCookie,
|
||||
BSimpleMediaClient::B_WILL_START,
|
||||
performanceTime);
|
||||
}
|
||||
@ -72,7 +72,7 @@ void
|
||||
BSimpleMediaClient::HandleStop(bigtime_t performanceTime)
|
||||
{
|
||||
if (fNotifyHook != NULL) {
|
||||
(*fNotifyHook)(fNotifyCookie,
|
||||
(*fNotifyHook)(BSimpleMediaClient::fNotifyCookie,
|
||||
BSimpleMediaClient::B_WILL_STOP,
|
||||
performanceTime);
|
||||
}
|
||||
@ -83,7 +83,7 @@ void
|
||||
BSimpleMediaClient::HandleSeek(bigtime_t mediaTime, bigtime_t performanceTime)
|
||||
{
|
||||
if (fNotifyHook != NULL) {
|
||||
(*fNotifyHook)(fNotifyCookie,
|
||||
(*fNotifyHook)(BSimpleMediaClient::fNotifyCookie,
|
||||
BSimpleMediaClient::B_WILL_SEEK,
|
||||
performanceTime, mediaTime);
|
||||
}
|
||||
@ -94,7 +94,7 @@ void
|
||||
BSimpleMediaClient::HandleTimeWarp(bigtime_t realTime, bigtime_t performanceTime)
|
||||
{
|
||||
if (fNotifyHook != NULL) {
|
||||
(*fNotifyHook)(fNotifyCookie,
|
||||
(*fNotifyHook)(BSimpleMediaClient::fNotifyCookie,
|
||||
BSimpleMediaClient::B_WILL_TIMEWARP,
|
||||
realTime, performanceTime);
|
||||
}
|
||||
@ -107,7 +107,7 @@ BSimpleMediaClient::HandleFormatSuggestion(media_type type, int32 quality,
|
||||
{
|
||||
if (fNotifyHook != NULL) {
|
||||
status_t result = B_ERROR;
|
||||
(*fNotifyHook)(fNotifyCookie,
|
||||
(*fNotifyHook)(BSimpleMediaClient::fNotifyCookie,
|
||||
BSimpleMediaClient::B_FORMAT_SUGGESTION,
|
||||
type, quality, format, &result);
|
||||
return result;
|
||||
@ -124,35 +124,18 @@ void BSimpleMediaClient::_ReservedSimpleMediaClient4() {}
|
||||
void BSimpleMediaClient::_ReservedSimpleMediaClient5() {}
|
||||
|
||||
|
||||
BSimpleMediaInput::BSimpleMediaInput()
|
||||
BSimpleMediaConnection::BSimpleMediaConnection(media_connection_kinds kinds)
|
||||
:
|
||||
BMediaInput()
|
||||
BMediaConnection(kinds),
|
||||
fProcessHook(NULL),
|
||||
fNotifyHook(NULL),
|
||||
fBufferCookie(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
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,
|
||||
BSimpleMediaConnection::SetHooks(process_hook processHook,
|
||||
notify_hook notifyHook, void* cookie)
|
||||
{
|
||||
CALLED();
|
||||
@ -164,7 +147,7 @@ BSimpleMediaInput::SetHooks(process_hook processHook,
|
||||
|
||||
|
||||
void*
|
||||
BSimpleMediaInput::Cookie() const
|
||||
BSimpleMediaConnection::Cookie() const
|
||||
{
|
||||
CALLED();
|
||||
|
||||
@ -172,6 +155,35 @@ BSimpleMediaInput::Cookie() const
|
||||
}
|
||||
|
||||
|
||||
BSimpleMediaInput::BSimpleMediaInput()
|
||||
:
|
||||
BMediaConnection(B_MEDIA_INPUT),
|
||||
BSimpleMediaConnection(B_MEDIA_INPUT),
|
||||
BMediaInput()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BSimpleMediaInput::Connected(const media_format& format)
|
||||
{
|
||||
if (fNotifyHook != NULL)
|
||||
(*fNotifyHook)(BSimpleMediaConnection::B_INPUT_CONNECTED, this);
|
||||
|
||||
BMediaInput::Connected(format);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BSimpleMediaInput::Disconnected()
|
||||
{
|
||||
if (fNotifyHook != NULL)
|
||||
(*fNotifyHook)(BSimpleMediaConnection::B_INPUT_DISCONNECTED, this);
|
||||
|
||||
BMediaConnection::Disconnected();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BSimpleMediaInput::BufferReceived(BBuffer* buffer)
|
||||
{
|
||||
@ -184,6 +196,8 @@ BSimpleMediaInput::BufferReceived(BBuffer* buffer)
|
||||
|
||||
BSimpleMediaOutput::BSimpleMediaOutput()
|
||||
:
|
||||
BMediaConnection(B_MEDIA_INPUT),
|
||||
BSimpleMediaConnection(B_MEDIA_OUTPUT),
|
||||
BMediaOutput()
|
||||
{
|
||||
}
|
||||
@ -193,7 +207,7 @@ status_t
|
||||
BSimpleMediaOutput::FormatProposal(media_format* format)
|
||||
{
|
||||
if (fNotifyHook != NULL) {
|
||||
return (*fNotifyHook)(BSimpleMediaOutput::B_FORMAT_PROPOSAL,
|
||||
return (*fNotifyHook)(BSimpleMediaConnection::B_FORMAT_PROPOSAL,
|
||||
this, format);
|
||||
}
|
||||
|
||||
@ -205,9 +219,9 @@ void
|
||||
BSimpleMediaOutput::Connected(const media_format& format)
|
||||
{
|
||||
if (fNotifyHook != NULL)
|
||||
(*fNotifyHook)(B_CONNECTED, this);
|
||||
(*fNotifyHook)(BSimpleMediaConnection::B_OUTPUT_CONNECTED, this);
|
||||
|
||||
BMediaConnection::Connected(format);
|
||||
BSimpleMediaConnection::Connected(format);
|
||||
}
|
||||
|
||||
|
||||
@ -215,28 +229,7 @@ void
|
||||
BSimpleMediaOutput::Disconnected()
|
||||
{
|
||||
if (fNotifyHook != NULL)
|
||||
(*fNotifyHook)(B_DISCONNECTED, this);
|
||||
(*fNotifyHook)(BSimpleMediaConnection::B_OUTPUT_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;
|
||||
BSimpleMediaConnection::Disconnected();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user