/* * 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 #include 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