MediaClient: Distribute callbacks across derived classes
This commit is contained in:
@@ -166,16 +166,6 @@ public:
|
|||||||
void* cookie = NULL);
|
void* cookie = NULL);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void BufferReceived(BBuffer* buffer,
|
|
||||||
BMediaInput* input);
|
|
||||||
|
|
||||||
// When a connection is not binded with another, it's your job to send
|
|
||||||
// the buffer to the connection you want. You might want
|
|
||||||
// to ovverride it so that you can track something, in this case
|
|
||||||
// be sure to call the base version.
|
|
||||||
virtual status_t SendBuffer(BBuffer* buffer,
|
|
||||||
BMediaOutput* output);
|
|
||||||
|
|
||||||
// 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
|
||||||
// class. Take ownership of the object.
|
// class. Take ownership of the object.
|
||||||
@@ -237,6 +227,8 @@ private:
|
|||||||
|
|
||||||
friend class BMediaClientNode;
|
friend class BMediaClientNode;
|
||||||
friend class BMediaConnection;
|
friend class BMediaConnection;
|
||||||
|
friend class BMediaInput;
|
||||||
|
friend class BMediaOutput;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -42,8 +42,7 @@ public:
|
|||||||
B_FORMAT_PROPOSAL, // media_format* format
|
B_FORMAT_PROPOSAL, // media_format* format
|
||||||
|
|
||||||
B_ASK_FORMAT_CHANGE,
|
B_ASK_FORMAT_CHANGE,
|
||||||
B_FORMAT_CHANGED,
|
B_FORMAT_CHANGED
|
||||||
B_ASK_TIMER
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -89,9 +88,6 @@ public:
|
|||||||
|
|
||||||
bool IsConnected() const;
|
bool IsConnected() const;
|
||||||
|
|
||||||
void SetOutputEnabled(bool enabled);
|
|
||||||
bool IsOutputEnabled() const;
|
|
||||||
|
|
||||||
void SetCookie(void* cookie);
|
void SetCookie(void* cookie);
|
||||||
void* Cookie() const;
|
void* Cookie() const;
|
||||||
|
|
||||||
@@ -119,13 +115,9 @@ protected:
|
|||||||
media_connection_kind kind,
|
media_connection_kind kind,
|
||||||
media_connection_id id);
|
media_connection_id id);
|
||||||
|
|
||||||
// TODO: All notifications should be done into private callbacks like this.
|
// Those callbacks are shared between BMediaInput and BMediaOutput
|
||||||
void ConnectedCallback(const media_source& source,
|
virtual void Connected(const media_format& format);
|
||||||
const media_format& format);
|
virtual void Disconnected();
|
||||||
void DisconnectedCallback(const media_source& source);
|
|
||||||
|
|
||||||
void ConnectCallback(const media_destination& source);
|
|
||||||
void DisconnectCallback(const media_destination& source);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const media_source& Source() const;
|
const media_source& Source() const;
|
||||||
@@ -152,7 +144,6 @@ private:
|
|||||||
BBufferGroup* fBufferGroup;
|
BBufferGroup* fBufferGroup;
|
||||||
|
|
||||||
bool fConnected;
|
bool fConnected;
|
||||||
bool fOutputEnabled;
|
|
||||||
|
|
||||||
virtual void _ReservedMediaConnection0();
|
virtual void _ReservedMediaConnection0();
|
||||||
virtual void _ReservedMediaConnection1();
|
virtual void _ReservedMediaConnection1();
|
||||||
@@ -169,6 +160,9 @@ private:
|
|||||||
|
|
||||||
friend class BMediaClient;
|
friend class BMediaClient;
|
||||||
friend class BMediaClientNode;
|
friend class BMediaClientNode;
|
||||||
|
|
||||||
|
friend class BMediaInput;
|
||||||
|
friend class BMediaOutput;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -177,6 +171,12 @@ public:
|
|||||||
BMediaInput(BMediaClient* owner,
|
BMediaInput(BMediaClient* owner,
|
||||||
media_connection_id id);
|
media_connection_id id);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// Callbacks
|
||||||
|
virtual status_t FormatChanged(const media_format& format);
|
||||||
|
|
||||||
|
virtual void BufferReceived(BBuffer* buffer);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
media_input MediaInput() const;
|
media_input MediaInput() const;
|
||||||
|
|
||||||
@@ -189,9 +189,27 @@ public:
|
|||||||
BMediaOutput(BMediaClient* owner,
|
BMediaOutput(BMediaClient* owner,
|
||||||
media_connection_id id);
|
media_connection_id id);
|
||||||
|
|
||||||
|
void SetOutputEnabled(bool enabled);
|
||||||
|
bool IsOutputEnabled() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// Callbacks
|
||||||
|
virtual status_t PrepareToConnect(media_format* format);
|
||||||
|
|
||||||
|
virtual status_t FormatProposal(media_format* format);
|
||||||
|
virtual status_t FormatChangeRequested(media_format* format);
|
||||||
|
|
||||||
|
// When a connection is not binded with another, it's your job to send
|
||||||
|
// the buffer to the connection you want. You might want
|
||||||
|
// to ovverride it so that you can track something, in this case
|
||||||
|
// be sure to call the base version.
|
||||||
|
virtual status_t SendBuffer(BBuffer* buffer);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
media_output MediaOutput() const;
|
media_output MediaOutput() const;
|
||||||
|
|
||||||
|
bool fOutputEnabled;
|
||||||
|
|
||||||
friend class BMediaClientNode;
|
friend class BMediaClientNode;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -450,15 +450,6 @@ BMediaClient::CurrentTime() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
|
||||||
BMediaClient::SendBuffer(BBuffer* buffer, BMediaOutput* output)
|
|
||||||
{
|
|
||||||
CALLED();
|
|
||||||
|
|
||||||
return fNode->SendBuffer(buffer, output);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BMediaClient::AddInput(BMediaInput* input)
|
BMediaClient::AddInput(BMediaInput* input)
|
||||||
{
|
{
|
||||||
@@ -477,17 +468,6 @@ BMediaClient::AddOutput(BMediaOutput* output)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
BMediaClient::BufferReceived(BBuffer* buffer,
|
|
||||||
BMediaInput* connection)
|
|
||||||
{
|
|
||||||
CALLED();
|
|
||||||
|
|
||||||
if (connection->fProcessHook != NULL)
|
|
||||||
connection->fProcessHook(connection, buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
BMediaAddOn*
|
BMediaAddOn*
|
||||||
BMediaClient::AddOn(int32* id) const
|
BMediaClient::AddOn(int32* id) const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -169,7 +169,7 @@ BMediaClientNode::GetNextInput(int32* cookie,
|
|||||||
if (fOwner->CountInputs() == 0)
|
if (fOwner->CountInputs() == 0)
|
||||||
return B_BAD_INDEX;
|
return B_BAD_INDEX;
|
||||||
|
|
||||||
if (*cookie < 0 || *cookie > fOwner->CountInputs()) {
|
if (*cookie < 0 || *cookie >= fOwner->CountInputs()) {
|
||||||
*cookie = -1;
|
*cookie = -1;
|
||||||
input = NULL;
|
input = NULL;
|
||||||
} else {
|
} else {
|
||||||
@@ -230,7 +230,11 @@ BMediaClientNode::Connected(const media_source& source,
|
|||||||
if (conn == NULL)
|
if (conn == NULL)
|
||||||
return B_MEDIA_BAD_DESTINATION;
|
return B_MEDIA_BAD_DESTINATION;
|
||||||
|
|
||||||
conn->ConnectedCallback(source, format);
|
conn->fConnection.source = source;
|
||||||
|
conn->SetAcceptedFormat(format);
|
||||||
|
|
||||||
|
conn->Connected(format);
|
||||||
|
|
||||||
*outInput = conn->MediaInput();
|
*outInput = conn->MediaInput();
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@@ -246,7 +250,7 @@ BMediaClientNode::Disconnected(const media_source& source,
|
|||||||
if (conn == NULL)
|
if (conn == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
conn->DisconnectedCallback(source);
|
conn->Disconnected();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -261,12 +265,7 @@ BMediaClientNode::FormatChanged(const media_source& source,
|
|||||||
if (conn == NULL)
|
if (conn == NULL)
|
||||||
return B_MEDIA_BAD_DESTINATION;
|
return B_MEDIA_BAD_DESTINATION;
|
||||||
|
|
||||||
if (!format_is_compatible(format, conn->AcceptedFormat()))
|
return conn->FormatChanged(format);
|
||||||
return B_MEDIA_BAD_FORMAT;
|
|
||||||
|
|
||||||
conn->SetAcceptedFormat(format);
|
|
||||||
|
|
||||||
return B_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -307,13 +306,7 @@ BMediaClientNode::FormatProposal(const media_source& source,
|
|||||||
if (conn == NULL)
|
if (conn == NULL)
|
||||||
return B_MEDIA_BAD_DESTINATION;
|
return B_MEDIA_BAD_DESTINATION;
|
||||||
|
|
||||||
if (fOwner->fNotifyHook != NULL) {
|
return conn->FormatProposal(format);
|
||||||
return (*conn->fNotifyHook)(BMediaConnection::B_FORMAT_PROPOSAL,
|
|
||||||
conn, format);
|
|
||||||
} else
|
|
||||||
*format = conn->AcceptedFormat();
|
|
||||||
|
|
||||||
return B_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -324,7 +317,11 @@ BMediaClientNode::FormatChangeRequested(const media_source& source,
|
|||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
|
|
||||||
return B_ERROR;
|
BMediaOutput* conn = fOwner->FindOutput(source);
|
||||||
|
if (conn == NULL)
|
||||||
|
return B_MEDIA_BAD_DESTINATION;
|
||||||
|
|
||||||
|
return conn->FormatChangeRequested(format);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -345,7 +342,7 @@ BMediaClientNode::GetNextOutput(int32* cookie, media_output* output)
|
|||||||
if (fOwner->CountOutputs() == 0)
|
if (fOwner->CountOutputs() == 0)
|
||||||
return B_BAD_INDEX;
|
return B_BAD_INDEX;
|
||||||
|
|
||||||
if (*cookie < 0 || *cookie > fOwner->CountOutputs()) {
|
if (*cookie < 0 || *cookie >= fOwner->CountOutputs()) {
|
||||||
*cookie = -1;
|
*cookie = -1;
|
||||||
output = NULL;
|
output = NULL;
|
||||||
} else {
|
} else {
|
||||||
@@ -423,9 +420,14 @@ BMediaClientNode::PrepareToConnect(const media_source& source,
|
|||||||
}
|
}
|
||||||
|
|
||||||
conn->fConnection.destination = dest;
|
conn->fConnection.destination = dest;
|
||||||
conn->SetAcceptedFormat(*format);
|
|
||||||
|
status_t err = conn->PrepareToConnect(format);
|
||||||
|
if (err != B_OK)
|
||||||
|
return err;
|
||||||
|
|
||||||
*out_source = conn->Source();
|
*out_source = conn->Source();
|
||||||
strcpy(name, Name());
|
strcpy(name, Name());
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -447,12 +449,14 @@ BMediaClientNode::Connect(status_t status, const media_source& source,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
conn->ConnectCallback(dest);
|
conn->fConnection.destination = dest;
|
||||||
strcpy(name, Name());
|
|
||||||
conn->SetAcceptedFormat(format);
|
conn->SetAcceptedFormat(format);
|
||||||
|
strcpy(name, Name());
|
||||||
|
|
||||||
// TODO: Allocate buffers, add correct latency estimate
|
// TODO: Allocate buffers, add correct latency estimate
|
||||||
// and buffer duration mode.
|
// and buffer duration mode.
|
||||||
|
|
||||||
|
conn->Connected(format);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -469,7 +473,7 @@ BMediaClientNode::Disconnect(const media_source& source,
|
|||||||
if (source == conn->Source() && dest == conn->Destination())
|
if (source == conn->Source() && dest == conn->Destination())
|
||||||
conn->Reset();
|
conn->Reset();
|
||||||
|
|
||||||
conn->DisconnectCallback(dest);
|
conn->Disconnected();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -572,7 +576,7 @@ BMediaClientNode::_HandleBuffer(BBuffer* buffer)
|
|||||||
BMediaInput* conn = fOwner->FindInput(dest);
|
BMediaInput* conn = fOwner->FindInput(dest);
|
||||||
|
|
||||||
if (conn != NULL)
|
if (conn != NULL)
|
||||||
fOwner->BufferReceived(buffer, conn);
|
conn->BufferReceived(buffer);
|
||||||
// TODO: this should be logged someway
|
// TODO: this should be logged someway
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -115,15 +115,6 @@ BMediaConnection::IsConnected() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
|
||||||
BMediaConnection::IsOutputEnabled() const
|
|
||||||
{
|
|
||||||
CALLED();
|
|
||||||
|
|
||||||
return fOutputEnabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void*
|
void*
|
||||||
BMediaConnection::Cookie() const
|
BMediaConnection::Cookie() const
|
||||||
{
|
{
|
||||||
@@ -212,12 +203,8 @@ BMediaConnection::BufferDuration() const
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BMediaConnection::ConnectedCallback(const media_source& source,
|
BMediaConnection::Connected(const media_format& format)
|
||||||
const media_format& format)
|
|
||||||
{
|
{
|
||||||
fConnection.source = source;
|
|
||||||
SetAcceptedFormat(format);
|
|
||||||
|
|
||||||
if (fNotifyHook != NULL)
|
if (fNotifyHook != NULL)
|
||||||
(*fNotifyHook)(B_CONNECTED, this);
|
(*fNotifyHook)(B_CONNECTED, this);
|
||||||
|
|
||||||
@@ -226,7 +213,7 @@ BMediaConnection::ConnectedCallback(const media_source& source,
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BMediaConnection::DisconnectedCallback(const media_source& source)
|
BMediaConnection::Disconnected()
|
||||||
{
|
{
|
||||||
if (fNotifyHook != NULL)
|
if (fNotifyHook != NULL)
|
||||||
(*fNotifyHook)(B_DISCONNECTED, this);
|
(*fNotifyHook)(B_DISCONNECTED, this);
|
||||||
@@ -235,19 +222,6 @@ BMediaConnection::DisconnectedCallback(const media_source& source)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
BMediaConnection::ConnectCallback(const media_destination& destination)
|
|
||||||
{
|
|
||||||
fConnection.destination = destination;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
BMediaConnection::DisconnectCallback(const media_destination& destination)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BMediaConnection::_Init()
|
BMediaConnection::_Init()
|
||||||
{
|
{
|
||||||
@@ -300,6 +274,28 @@ BMediaInput::MediaInput() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
BMediaInput::FormatChanged(const media_format& format)
|
||||||
|
{
|
||||||
|
if (!format_is_compatible(format, AcceptedFormat()))
|
||||||
|
return B_MEDIA_BAD_FORMAT;
|
||||||
|
|
||||||
|
SetAcceptedFormat(format);
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
BMediaInput::BufferReceived(BBuffer* buffer)
|
||||||
|
{
|
||||||
|
CALLED();
|
||||||
|
|
||||||
|
if (fProcessHook != NULL)
|
||||||
|
fProcessHook(this, buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
BMediaOutput::BMediaOutput(BMediaClient* owner, media_connection_id id)
|
BMediaOutput::BMediaOutput(BMediaClient* owner, media_connection_id id)
|
||||||
:
|
:
|
||||||
BMediaConnection(owner, B_MEDIA_OUTPUT, id)
|
BMediaConnection(owner, B_MEDIA_OUTPUT, id)
|
||||||
@@ -307,6 +303,53 @@ BMediaOutput::BMediaOutput(BMediaClient* owner, media_connection_id id)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
BMediaOutput::IsOutputEnabled() const
|
||||||
|
{
|
||||||
|
CALLED();
|
||||||
|
|
||||||
|
return fOutputEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
BMediaOutput::PrepareToConnect(media_format* format)
|
||||||
|
{
|
||||||
|
SetAcceptedFormat(*format);
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
BMediaOutput::FormatProposal(media_format* format)
|
||||||
|
{
|
||||||
|
if (fOwner->fNotifyHook != NULL) {
|
||||||
|
return (*fNotifyHook)(BMediaConnection::B_FORMAT_PROPOSAL,
|
||||||
|
this, format);
|
||||||
|
} else
|
||||||
|
*format = AcceptedFormat();
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
BMediaOutput::FormatChangeRequested(media_format* format)
|
||||||
|
{
|
||||||
|
return B_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
BMediaOutput::SendBuffer(BBuffer* buffer)
|
||||||
|
{
|
||||||
|
CALLED();
|
||||||
|
|
||||||
|
return fOwner->fNode->SendBuffer(buffer, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
media_output
|
media_output
|
||||||
BMediaOutput::MediaOutput() const
|
BMediaOutput::MediaOutput() const
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user