MediaClient: Distribute callbacks across derived classes
This commit is contained in:
@@ -166,16 +166,6 @@ public:
|
||||
void* cookie = NULL);
|
||||
|
||||
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
|
||||
// mechanism, for example to supply your BMediaConnection derived
|
||||
// class. Take ownership of the object.
|
||||
@@ -237,6 +227,8 @@ private:
|
||||
|
||||
friend class BMediaClientNode;
|
||||
friend class BMediaConnection;
|
||||
friend class BMediaInput;
|
||||
friend class BMediaOutput;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -42,8 +42,7 @@ public:
|
||||
B_FORMAT_PROPOSAL, // media_format* format
|
||||
|
||||
B_ASK_FORMAT_CHANGE,
|
||||
B_FORMAT_CHANGED,
|
||||
B_ASK_TIMER
|
||||
B_FORMAT_CHANGED
|
||||
};
|
||||
|
||||
|
||||
@@ -89,9 +88,6 @@ public:
|
||||
|
||||
bool IsConnected() const;
|
||||
|
||||
void SetOutputEnabled(bool enabled);
|
||||
bool IsOutputEnabled() const;
|
||||
|
||||
void SetCookie(void* cookie);
|
||||
void* Cookie() const;
|
||||
|
||||
@@ -119,13 +115,9 @@ protected:
|
||||
media_connection_kind kind,
|
||||
media_connection_id id);
|
||||
|
||||
// TODO: All notifications should be done into private callbacks like this.
|
||||
void ConnectedCallback(const media_source& source,
|
||||
const media_format& format);
|
||||
void DisconnectedCallback(const media_source& source);
|
||||
|
||||
void ConnectCallback(const media_destination& source);
|
||||
void DisconnectCallback(const media_destination& source);
|
||||
// Those callbacks are shared between BMediaInput and BMediaOutput
|
||||
virtual void Connected(const media_format& format);
|
||||
virtual void Disconnected();
|
||||
|
||||
private:
|
||||
const media_source& Source() const;
|
||||
@@ -152,7 +144,6 @@ private:
|
||||
BBufferGroup* fBufferGroup;
|
||||
|
||||
bool fConnected;
|
||||
bool fOutputEnabled;
|
||||
|
||||
virtual void _ReservedMediaConnection0();
|
||||
virtual void _ReservedMediaConnection1();
|
||||
@@ -169,6 +160,9 @@ private:
|
||||
|
||||
friend class BMediaClient;
|
||||
friend class BMediaClientNode;
|
||||
|
||||
friend class BMediaInput;
|
||||
friend class BMediaOutput;
|
||||
};
|
||||
|
||||
|
||||
@@ -177,6 +171,12 @@ public:
|
||||
BMediaInput(BMediaClient* owner,
|
||||
media_connection_id id);
|
||||
|
||||
protected:
|
||||
// Callbacks
|
||||
virtual status_t FormatChanged(const media_format& format);
|
||||
|
||||
virtual void BufferReceived(BBuffer* buffer);
|
||||
|
||||
private:
|
||||
media_input MediaInput() const;
|
||||
|
||||
@@ -189,9 +189,27 @@ public:
|
||||
BMediaOutput(BMediaClient* owner,
|
||||
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:
|
||||
media_output MediaOutput() const;
|
||||
|
||||
bool fOutputEnabled;
|
||||
|
||||
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
|
||||
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*
|
||||
BMediaClient::AddOn(int32* id) const
|
||||
{
|
||||
|
||||
@@ -169,7 +169,7 @@ BMediaClientNode::GetNextInput(int32* cookie,
|
||||
if (fOwner->CountInputs() == 0)
|
||||
return B_BAD_INDEX;
|
||||
|
||||
if (*cookie < 0 || *cookie > fOwner->CountInputs()) {
|
||||
if (*cookie < 0 || *cookie >= fOwner->CountInputs()) {
|
||||
*cookie = -1;
|
||||
input = NULL;
|
||||
} else {
|
||||
@@ -230,7 +230,11 @@ BMediaClientNode::Connected(const media_source& source,
|
||||
if (conn == NULL)
|
||||
return B_MEDIA_BAD_DESTINATION;
|
||||
|
||||
conn->ConnectedCallback(source, format);
|
||||
conn->fConnection.source = source;
|
||||
conn->SetAcceptedFormat(format);
|
||||
|
||||
conn->Connected(format);
|
||||
|
||||
*outInput = conn->MediaInput();
|
||||
return B_OK;
|
||||
}
|
||||
@@ -246,7 +250,7 @@ BMediaClientNode::Disconnected(const media_source& source,
|
||||
if (conn == NULL)
|
||||
return;
|
||||
|
||||
conn->DisconnectedCallback(source);
|
||||
conn->Disconnected();
|
||||
}
|
||||
|
||||
|
||||
@@ -261,12 +265,7 @@ BMediaClientNode::FormatChanged(const media_source& source,
|
||||
if (conn == NULL)
|
||||
return B_MEDIA_BAD_DESTINATION;
|
||||
|
||||
if (!format_is_compatible(format, conn->AcceptedFormat()))
|
||||
return B_MEDIA_BAD_FORMAT;
|
||||
|
||||
conn->SetAcceptedFormat(format);
|
||||
|
||||
return B_OK;
|
||||
return conn->FormatChanged(format);
|
||||
}
|
||||
|
||||
|
||||
@@ -307,13 +306,7 @@ BMediaClientNode::FormatProposal(const media_source& source,
|
||||
if (conn == NULL)
|
||||
return B_MEDIA_BAD_DESTINATION;
|
||||
|
||||
if (fOwner->fNotifyHook != NULL) {
|
||||
return (*conn->fNotifyHook)(BMediaConnection::B_FORMAT_PROPOSAL,
|
||||
conn, format);
|
||||
} else
|
||||
*format = conn->AcceptedFormat();
|
||||
|
||||
return B_OK;
|
||||
return conn->FormatProposal(format);
|
||||
}
|
||||
|
||||
|
||||
@@ -324,7 +317,11 @@ BMediaClientNode::FormatChangeRequested(const media_source& source,
|
||||
{
|
||||
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)
|
||||
return B_BAD_INDEX;
|
||||
|
||||
if (*cookie < 0 || *cookie > fOwner->CountOutputs()) {
|
||||
if (*cookie < 0 || *cookie >= fOwner->CountOutputs()) {
|
||||
*cookie = -1;
|
||||
output = NULL;
|
||||
} else {
|
||||
@@ -423,9 +420,14 @@ BMediaClientNode::PrepareToConnect(const media_source& source,
|
||||
}
|
||||
|
||||
conn->fConnection.destination = dest;
|
||||
conn->SetAcceptedFormat(*format);
|
||||
|
||||
status_t err = conn->PrepareToConnect(format);
|
||||
if (err != B_OK)
|
||||
return err;
|
||||
|
||||
*out_source = conn->Source();
|
||||
strcpy(name, Name());
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
@@ -447,12 +449,14 @@ BMediaClientNode::Connect(status_t status, const media_source& source,
|
||||
return;
|
||||
}
|
||||
|
||||
conn->ConnectCallback(dest);
|
||||
strcpy(name, Name());
|
||||
conn->fConnection.destination = dest;
|
||||
conn->SetAcceptedFormat(format);
|
||||
strcpy(name, Name());
|
||||
|
||||
// TODO: Allocate buffers, add correct latency estimate
|
||||
// and buffer duration mode.
|
||||
|
||||
conn->Connected(format);
|
||||
}
|
||||
|
||||
|
||||
@@ -469,7 +473,7 @@ BMediaClientNode::Disconnect(const media_source& source,
|
||||
if (source == conn->Source() && dest == conn->Destination())
|
||||
conn->Reset();
|
||||
|
||||
conn->DisconnectCallback(dest);
|
||||
conn->Disconnected();
|
||||
}
|
||||
|
||||
|
||||
@@ -572,7 +576,7 @@ BMediaClientNode::_HandleBuffer(BBuffer* buffer)
|
||||
BMediaInput* conn = fOwner->FindInput(dest);
|
||||
|
||||
if (conn != NULL)
|
||||
fOwner->BufferReceived(buffer, conn);
|
||||
conn->BufferReceived(buffer);
|
||||
// TODO: this should be logged someway
|
||||
}
|
||||
|
||||
|
||||
@@ -115,15 +115,6 @@ BMediaConnection::IsConnected() const
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
BMediaConnection::IsOutputEnabled() const
|
||||
{
|
||||
CALLED();
|
||||
|
||||
return fOutputEnabled;
|
||||
}
|
||||
|
||||
|
||||
void*
|
||||
BMediaConnection::Cookie() const
|
||||
{
|
||||
@@ -212,12 +203,8 @@ BMediaConnection::BufferDuration() const
|
||||
|
||||
|
||||
void
|
||||
BMediaConnection::ConnectedCallback(const media_source& source,
|
||||
const media_format& format)
|
||||
BMediaConnection::Connected(const media_format& format)
|
||||
{
|
||||
fConnection.source = source;
|
||||
SetAcceptedFormat(format);
|
||||
|
||||
if (fNotifyHook != NULL)
|
||||
(*fNotifyHook)(B_CONNECTED, this);
|
||||
|
||||
@@ -226,7 +213,7 @@ BMediaConnection::ConnectedCallback(const media_source& source,
|
||||
|
||||
|
||||
void
|
||||
BMediaConnection::DisconnectedCallback(const media_source& source)
|
||||
BMediaConnection::Disconnected()
|
||||
{
|
||||
if (fNotifyHook != NULL)
|
||||
(*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
|
||||
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)
|
||||
:
|
||||
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
|
||||
BMediaOutput::MediaOutput() const
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user