1 /* 2 * Copyright 2015-2018, Dario Casalinuovo. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 #ifndef _MEDIA_SIMPLE_CLIENT_H 7 #define _MEDIA_SIMPLE_CLIENT_H 8 9 #include <MediaClient.h> 10 #include <MediaConnection.h> 11 12 13 namespace BPrivate { namespace media { 14 15 16 class BSimpleMediaInput; 17 class BSimpleMediaOutput; 18 19 class BSimpleMediaClient : public BMediaClient { 20 public: 21 enum notification { 22 B_WILL_START = 1, // performance_time 23 B_WILL_STOP, // performance_time immediate 24 B_WILL_SEEK, // performance_time media_time 25 26 B_FORMAT_SUGGESTION, // media_type type, int32 quality, 27 // media_format* format 28 }; 29 30 typedef void (*notify_hook)(void* cookie, 31 notification what, 32 ...); 33 34 BSimpleMediaClient(const char* name, 35 media_type type 36 = B_MEDIA_UNKNOWN_TYPE, 37 media_client_kinds 38 kinds = B_MEDIA_PLAYER 39 & B_MEDIA_RECORDER); 40 41 virtual ~BSimpleMediaClient(); 42 43 // This is supplied to support generic connections not related 44 // to a certain destination or source node, however for various ambiguity 45 // reasons we want the BMediaConnection to be declared as input or output. 46 // You can pass the object returned by this function to another 47 // BMediaClient::Connect(), so that it will automatically connect to this node. 48 virtual BSimpleMediaInput* BeginInput(); 49 virtual BSimpleMediaOutput* BeginOutput(); 50 51 void SetHook(notify_hook notifyHook = NULL, 52 void* cookie = NULL); 53 54 protected: 55 virtual void HandleStart(bigtime_t performanceTime); 56 virtual void HandleStop(bigtime_t performanceTime); 57 58 virtual void HandleSeek(bigtime_t mediaTime, 59 bigtime_t performanceTime); 60 61 virtual status_t FormatSuggestion(media_type type, 62 int32 quality, media_format* format); 63 64 private: 65 notify_hook fNotifyHook; 66 void* fNotifyCookie; 67 68 virtual void _ReservedSimpleMediaClient0(); 69 virtual void _ReservedSimpleMediaClient1(); 70 virtual void _ReservedSimpleMediaClient2(); 71 virtual void _ReservedSimpleMediaClient3(); 72 virtual void _ReservedSimpleMediaClient4(); 73 virtual void _ReservedSimpleMediaClient5(); 74 uint32 fPadding[32]; 75 }; 76 77 78 class BSimpleMediaConnection : public virtual BMediaConnection { 79 public: 80 enum notification { 81 // Inputs 82 B_INPUT_CONNECTED = 1, 83 B_INPUT_DISCONNECTED, 84 85 B_FORMAT_CHANGED, 86 87 // Outputs 88 B_OUTPUT_CONNECTED, 89 B_OUTPUT_DISCONNECTED, 90 91 B_PREPARE_TO_CONNECT, // media_format* format, media_source* source, 92 // char* name 93 94 B_FORMAT_PROPOSAL, // media_format* format 95 B_ASK_FORMAT_CHANGE, 96 }; 97 98 // This function is called when it is the moment to handle a buffer. 99 typedef void (*process_hook)( 100 BMediaConnection* connection, 101 BBuffer* buffer); 102 103 // Used to notify or inquire the client about what to do when certain 104 // events happen. 105 typedef status_t (*notify_hook)( 106 BMediaConnection* connection, 107 notification what, 108 ...); 109 110 // Use this to set your callbacks. 111 void SetHooks(process_hook processHook = NULL, 112 notify_hook notifyHook = NULL, 113 void* cookie = NULL); 114 115 void* Cookie() const; 116 117 virtual size_t BufferSize() const; 118 virtual void SetBufferSize(size_t bufferSize); 119 120 protected: 121 BSimpleMediaConnection( 122 media_connection_kinds kinds); 123 virtual ~BSimpleMediaConnection(); 124 125 // TODO: move those to private and introduce protected methods 126 process_hook fProcessHook; 127 notify_hook fNotifyHook; 128 void* fBufferCookie; 129 130 size_t fBufferSize; 131 }; 132 133 134 class BSimpleMediaInput : public BSimpleMediaConnection, public BMediaInput { 135 public: 136 BSimpleMediaInput(); 137 138 protected: 139 virtual ~BSimpleMediaInput(); 140 141 virtual void Connected(const media_format& format); 142 virtual void Disconnected(); 143 144 virtual void HandleBuffer(BBuffer* buffer); 145 }; 146 147 148 class BSimpleMediaOutput : public BSimpleMediaConnection, public BMediaOutput { 149 public: 150 BSimpleMediaOutput(); 151 152 protected: 153 virtual ~BSimpleMediaOutput(); 154 155 virtual void Connected(const media_format& format); 156 virtual void Disconnected(); 157 158 virtual status_t FormatProposal(media_format* format); 159 }; 160 161 162 } 163 164 } 165 166 using namespace BPrivate::media; 167 168 #endif 169