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:
parent
8ab68339fb
commit
ecb395852e
|
@ -32,24 +32,6 @@ class BMediaOutput;
|
|||
// performance_time.
|
||||
class 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,
|
||||
...);
|
||||
|
||||
// TODO: Should allow BControllable capabilities
|
||||
// TODO: Add file interface
|
||||
// TODO: Offline mode is still missing
|
||||
|
||||
BMediaClient(const char* name,
|
||||
media_type type
|
||||
= B_MEDIA_UNKNOWN_TYPE,
|
||||
|
@ -67,19 +49,17 @@ public:
|
|||
|
||||
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,
|
||||
// also in another team the connection object will be valid.
|
||||
// When those functions return, the BMediaConnection is added to the
|
||||
// list and is visible to other nodes as not connected.
|
||||
|
||||
// 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::BeginConnection() and then Connect(), so that it
|
||||
// will automatically connect to this node.
|
||||
virtual BMediaInput* BeginInput();
|
||||
virtual BMediaOutput* BeginOutput();
|
||||
virtual status_t RegisterInput(BMediaInput* input);
|
||||
virtual status_t RegisterOutput(BMediaOutput* output);
|
||||
|
||||
// Bind internally two connections of the same BMediaClient, so that the
|
||||
// input will be automatically forwarded to the output just after the
|
||||
|
@ -126,8 +106,8 @@ public:
|
|||
|
||||
bool IsRunning() const;
|
||||
|
||||
virtual status_t Start(bool force = false);
|
||||
virtual status_t Stop(bool force = false);
|
||||
status_t Start(bool force = false);
|
||||
status_t Stop(bool force = false);
|
||||
status_t Seek(bigtime_t mediaTime,
|
||||
bigtime_t performanceTime);
|
||||
status_t Roll(bigtime_t start, bigtime_t stop,
|
||||
|
@ -162,9 +142,6 @@ public:
|
|||
// Default version just return NULL.
|
||||
virtual BMediaAddOn* AddOn(int32* id) const;
|
||||
|
||||
void SetNotificationHook(notify_hook notifyHook = NULL,
|
||||
void* cookie = NULL);
|
||||
|
||||
protected:
|
||||
// This is used when the user want to override the BeginConnection
|
||||
// mechanism, for example to supply your BMediaConnection derived
|
||||
|
@ -172,9 +149,21 @@ protected:
|
|||
virtual void AddInput(BMediaInput* input);
|
||||
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
|
||||
status_t DisconnectConnection(BMediaConnection* conn);
|
||||
status_t ReleaseConnection(BMediaConnection* conn);
|
||||
status_t ConnectionDisconnected(BMediaConnection* conn);
|
||||
status_t ConnectionReleased(BMediaConnection* conn);
|
||||
|
||||
private:
|
||||
BMediaInput* FindInput(
|
||||
|
@ -202,10 +191,6 @@ private:
|
|||
bigtime_t fMinLatency;
|
||||
bigtime_t fMaxLatency;
|
||||
|
||||
notify_hook fNotifyHook;
|
||||
|
||||
void* fNotifyCookie;
|
||||
|
||||
BObjectList<BMediaInput> fInputs;
|
||||
BObjectList<BMediaOutput> fOutputs;
|
||||
|
||||
|
|
|
@ -132,14 +132,6 @@ private:
|
|||
void _ProduceNewBuffer(const media_timed_event* event,
|
||||
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;
|
||||
};
|
||||
|
||||
|
|
|
@ -30,42 +30,14 @@ namespace BPrivate { namespace media {
|
|||
// recycle the buffer when you don't want to do anything further.
|
||||
class BMediaConnection {
|
||||
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();
|
||||
|
||||
const media_connection& Connection() const;
|
||||
media_connection_id Id() const;
|
||||
const char* Name() const;
|
||||
|
||||
// TODO: while most of the objects for both kinds are common
|
||||
// it would be worthwile to have a private implementation
|
||||
// so that we can better model the differences and avoid
|
||||
// problems.
|
||||
BMediaClient* MediaClient() const;
|
||||
|
||||
bool IsInput() const;
|
||||
bool IsOutput() const;
|
||||
|
||||
|
@ -88,9 +60,6 @@ public:
|
|||
|
||||
bool IsConnected() const;
|
||||
|
||||
void SetCookie(void* cookie);
|
||||
void* Cookie() const;
|
||||
|
||||
// Disconnect this connection. When a connection is disconnected,
|
||||
// it can be reused as brand new.
|
||||
status_t Disconnect();
|
||||
|
@ -101,26 +70,20 @@ public:
|
|||
// want to preserve it for future connections just Disconnect() it.
|
||||
status_t Release();
|
||||
|
||||
// Use this to set your callbacks.
|
||||
void SetHooks(process_hook processHook = NULL,
|
||||
notify_hook notifyHook = NULL,
|
||||
void* cookie = NULL);
|
||||
|
||||
protected:
|
||||
BMediaConnection(BMediaClient* owner,
|
||||
media_connection_kind kind,
|
||||
media_connection_id id);
|
||||
BMediaConnection(media_connection_kind kind);
|
||||
|
||||
// Those callbacks are shared between BMediaInput and BMediaOutput
|
||||
virtual void Connected(const media_format& format);
|
||||
virtual void Disconnected();
|
||||
|
||||
private:
|
||||
void ConnectionRegistered(BMediaClient* owner,
|
||||
media_connection_id id);
|
||||
|
||||
const media_source& Source() const;
|
||||
const media_destination& Destination() const;
|
||||
|
||||
void _Init();
|
||||
|
||||
media_connection fConnection;
|
||||
|
||||
BMediaClient* fOwner;
|
||||
|
@ -130,10 +93,6 @@ private:
|
|||
// see BMediaClient::Bind.
|
||||
BMediaConnection* fBind;
|
||||
|
||||
process_hook fProcessHook;
|
||||
notify_hook fNotifyHook;
|
||||
void* fBufferCookie;
|
||||
|
||||
size_t fBufferSize;
|
||||
bigtime_t fBufferDuration;
|
||||
|
||||
|
@ -164,8 +123,7 @@ private:
|
|||
|
||||
class BMediaInput : public BMediaConnection {
|
||||
public:
|
||||
BMediaInput(BMediaClient* owner,
|
||||
media_connection_id id);
|
||||
BMediaInput();
|
||||
|
||||
protected:
|
||||
// Callbacks
|
||||
|
@ -195,8 +153,7 @@ private:
|
|||
|
||||
class BMediaOutput : public BMediaConnection {
|
||||
public:
|
||||
BMediaOutput(BMediaClient* owner,
|
||||
media_connection_id id);
|
||||
BMediaOutput();
|
||||
|
||||
void SetOutputEnabled(bool enabled);
|
||||
bool IsOutputEnabled() const;
|
||||
|
|
|
@ -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
|
|
@ -30,7 +30,7 @@ for architectureObject in [ MultiArchSubDirSetup ] {
|
|||
MediaClientDefs.cpp
|
||||
MediaConnection.cpp
|
||||
MediaRecorder.cpp
|
||||
|
||||
SimpleMediaClient.cpp
|
||||
|
||||
# Public Media Kit
|
||||
Buffer.cpp
|
||||
|
|
|
@ -71,25 +71,21 @@ BMediaClient::MediaType() const
|
|||
}
|
||||
|
||||
|
||||
BMediaInput*
|
||||
BMediaClient::BeginInput()
|
||||
status_t
|
||||
BMediaClient::RegisterInput(BMediaInput* input)
|
||||
{
|
||||
CALLED();
|
||||
|
||||
BMediaInput* input = new BMediaInput(this, fLastID++);
|
||||
input->ConnectionRegistered(this, fLastID++);
|
||||
AddInput(input);
|
||||
return input;
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
BMediaOutput*
|
||||
BMediaClient::BeginOutput()
|
||||
status_t
|
||||
BMediaClient::RegisterOutput(BMediaOutput* output)
|
||||
{
|
||||
CALLED();
|
||||
|
||||
BMediaOutput* output = new BMediaOutput(this, fLastID++);
|
||||
output->ConnectionRegistered(this, fLastID++);
|
||||
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
|
||||
BMediaClient::CountInputs() const
|
||||
{
|
||||
|
@ -469,12 +447,48 @@ BMediaClient::AddOn(int32* id) const
|
|||
|
||||
|
||||
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();
|
||||
|
||||
fNotifyHook = NULL;
|
||||
fNotifyCookie = NULL;
|
||||
|
||||
BMediaRoster* roster = BMediaRoster::Roster(&fInitErr);
|
||||
if (fInitErr == B_OK && roster != NULL)
|
||||
fInitErr = roster->RegisterNode(fNode);
|
||||
|
|
|
@ -280,19 +280,16 @@ BMediaClientNode::FormatSuggestionRequested(media_type type,
|
|||
return B_MEDIA_BAD_FORMAT;
|
||||
}
|
||||
|
||||
if (fOwner->fNotifyHook != NULL) {
|
||||
status_t result = B_OK;
|
||||
(*fOwner->fNotifyHook)(fOwner->fNotifyCookie,
|
||||
BMediaClient::B_FORMAT_SUGGESTION,
|
||||
type, quality, format, &result);
|
||||
return result;
|
||||
} else {
|
||||
status_t ret = fOwner->HandleFormatSuggestion(type, quality, format);
|
||||
if (ret != B_OK) {
|
||||
// In that case we return just a very generic format.
|
||||
media_format outFormat;
|
||||
outFormat.type = fOwner->MediaType();
|
||||
*format = outFormat;
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
@ -539,20 +536,25 @@ BMediaClientNode::HandleEvent(const media_timed_event* event,
|
|||
case BTimedEventQueue::B_START:
|
||||
{
|
||||
if (RunState() != B_STARTED)
|
||||
_HandleStart(event->event_time);
|
||||
fOwner->HandleStart(event->event_time);
|
||||
break;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
case BTimedEventQueue::B_SEEK:
|
||||
_HandleSeek(event->event_time, event->bigdata);
|
||||
fOwner->HandleSeek(event->event_time, event->bigdata);
|
||||
break;
|
||||
|
||||
case BTimedEventQueue::B_WARP:
|
||||
_HandleTimeWarp(event->event_time, event->bigdata);
|
||||
fOwner->HandleTimeWarp(event->event_time, event->bigdata);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -595,60 +597,3 @@ BMediaClientNode::_ProduceNewBuffer(const media_timed_event* event,
|
|||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,33 +8,17 @@
|
|||
#include "debug.h"
|
||||
|
||||
|
||||
BMediaConnection::BMediaConnection(BMediaClient* owner,
|
||||
media_connection_kind kind,
|
||||
media_connection_id id)
|
||||
BMediaConnection::BMediaConnection(media_connection_kind kind)
|
||||
:
|
||||
fOwner(owner),
|
||||
fBind(NULL)
|
||||
fOwner(NULL),
|
||||
fBind(NULL),
|
||||
fBufferGroup(NULL)
|
||||
{
|
||||
CALLED();
|
||||
|
||||
_Init();
|
||||
|
||||
fConnection.kind = kind;
|
||||
fConnection.id = id;
|
||||
fConnection.client = fOwner->Client();
|
||||
|
||||
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;
|
||||
}
|
||||
fConnection.id = -1;
|
||||
//fConnection.client = media_client::null;
|
||||
}
|
||||
|
||||
|
||||
|
@ -115,15 +99,6 @@ BMediaConnection::IsConnected() const
|
|||
}
|
||||
|
||||
|
||||
void*
|
||||
BMediaConnection::Cookie() const
|
||||
{
|
||||
CALLED();
|
||||
|
||||
return fBufferCookie;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BMediaConnection::Disconnect()
|
||||
{
|
||||
|
@ -132,7 +107,7 @@ BMediaConnection::Disconnect()
|
|||
delete fBufferGroup;
|
||||
fBufferGroup = NULL;
|
||||
|
||||
return fOwner->DisconnectConnection(this);
|
||||
return fOwner->ConnectionDisconnected(this);
|
||||
}
|
||||
|
||||
|
||||
|
@ -141,19 +116,7 @@ BMediaConnection::Release()
|
|||
{
|
||||
CALLED();
|
||||
|
||||
return fOwner->ReleaseConnection(this);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BMediaConnection::SetHooks(process_hook processHook,
|
||||
notify_hook notifyHook, void* cookie)
|
||||
{
|
||||
CALLED();
|
||||
|
||||
fProcessHook = processHook;
|
||||
fNotifyHook = notifyHook;
|
||||
fBufferCookie = cookie;
|
||||
return fOwner->ConnectionReleased(this);
|
||||
}
|
||||
|
||||
|
||||
|
@ -196,9 +159,6 @@ BMediaConnection::BufferDuration() const
|
|||
void
|
||||
BMediaConnection::Connected(const media_format& format)
|
||||
{
|
||||
if (fNotifyHook != NULL)
|
||||
(*fNotifyHook)(B_CONNECTED, this);
|
||||
|
||||
fConnected = true;
|
||||
}
|
||||
|
||||
|
@ -206,21 +166,29 @@ BMediaConnection::Connected(const media_format& format)
|
|||
void
|
||||
BMediaConnection::Disconnected()
|
||||
{
|
||||
if (fNotifyHook != NULL)
|
||||
(*fNotifyHook)(B_DISCONNECTED, this);
|
||||
|
||||
fConnected = false;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BMediaConnection::_Init()
|
||||
BMediaConnection::ConnectionRegistered(BMediaClient* owner,
|
||||
media_connection_id id)
|
||||
{
|
||||
CALLED();
|
||||
fOwner = owner;
|
||||
fConnection.id = id;
|
||||
fConnection.client = fOwner->Client();
|
||||
|
||||
fBufferGroup = NULL;
|
||||
fNotifyHook = NULL;
|
||||
fProcessHook = NULL;
|
||||
if (IsOutput()) {
|
||||
fConnection.source.port = fOwner->fNode->ControlPort();
|
||||
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() {}
|
||||
|
||||
|
||||
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();
|
||||
|
||||
if (fProcessHook != NULL)
|
||||
fProcessHook(this, buffer);
|
||||
}
|
||||
|
||||
|
||||
|
@ -300,9 +266,9 @@ void BMediaInput::_ReservedMediaInput9() {}
|
|||
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
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
||||
#include <MediaClient.h>
|
||||
#include <SimpleMediaClient.h>
|
||||
#include <MediaConnection.h>
|
||||
#include <SupportDefs.h>
|
||||
|
||||
|
@ -18,18 +18,18 @@
|
|||
#endif
|
||||
|
||||
|
||||
static BMediaClient* sProducer = NULL;
|
||||
static BMediaClient* sConsumer = NULL;
|
||||
static BMediaClient* sFilter = NULL;
|
||||
static BSimpleMediaClient* sProducer = NULL;
|
||||
static BSimpleMediaClient* sConsumer = NULL;
|
||||
static BSimpleMediaClient* sFilter = NULL;
|
||||
|
||||
|
||||
void _InitClients(bool hasFilter)
|
||||
{
|
||||
sProducer = new BMediaClient("MediaClientProducer");
|
||||
sConsumer = new BMediaClient("MediaClientConsumer");
|
||||
sProducer = new BSimpleMediaClient("MediaClientProducer");
|
||||
sConsumer = new BSimpleMediaClient("MediaClientConsumer");
|
||||
|
||||
if (hasFilter)
|
||||
sFilter = new BMediaClient("MediaClientFilter");
|
||||
sFilter = new BSimpleMediaClient("MediaClientFilter");
|
||||
else
|
||||
sFilter = NULL;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue