1 /* 2 * Copyright 2015, Haiku, Inc. 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 SetNotificationHook(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 HandleFormatSuggestion(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 notification what, 107 BMediaConnection* connection, 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 protected: 118 BSimpleMediaConnection( 119 media_connection_kinds kinds); 120 virtual ~BSimpleMediaConnection(); 121 122 process_hook fProcessHook; 123 notify_hook fNotifyHook; 124 void* fBufferCookie; 125 }; 126 127 128 class BSimpleMediaInput : public BSimpleMediaConnection, public BMediaInput { 129 public: 130 BSimpleMediaInput(); 131 132 protected: 133 virtual ~BSimpleMediaInput(); 134 135 virtual void Connected(const media_format& format); 136 virtual void Disconnected(); 137 138 virtual void HandleBuffer(BBuffer* buffer); 139 }; 140 141 142 class BSimpleMediaOutput : public BSimpleMediaConnection, public BMediaOutput { 143 public: 144 BSimpleMediaOutput(); 145 146 protected: 147 virtual ~BSimpleMediaOutput(); 148 149 virtual void Connected(const media_format& format); 150 virtual void Disconnected(); 151 152 virtual status_t FormatProposal(media_format* format); 153 }; 154 155 156 } 157 158 } 159 160 using namespace BPrivate::media; 161 162 #endif 163