1 /* 2 * Copyright 2009, Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _MEDIA_NODE_H 6 #define _MEDIA_NODE_H 7 8 9 #include <MediaDefs.h> 10 #include <Point.h> 11 12 #include <new> 13 14 15 class BBufferConsumer; 16 class BBufferProducer; 17 class BControllable; 18 class BFileInterface; 19 class BMediaAddOn; 20 class BTimeSource; 21 22 23 class media_node { 24 public: 25 media_node(); 26 ~media_node(); 27 28 media_node_id node; 29 port_id port; 30 uint32 kind; 31 32 static media_node null; 33 34 private: 35 uint32 _reserved_[3]; 36 }; 37 38 39 struct media_input { 40 media_input(); 41 ~media_input(); 42 43 media_node node; 44 media_source source; 45 media_destination destination; 46 media_format format; 47 char name[B_MEDIA_NAME_LENGTH]; 48 49 private: 50 uint32 _reserved_media_input_[4]; 51 }; 52 53 54 struct media_output { 55 media_output(); 56 ~media_output(); 57 58 media_node node; 59 media_source source; 60 media_destination destination; 61 media_format format; 62 char name[B_MEDIA_NAME_LENGTH]; 63 64 private: 65 uint32 _reserved_media_output_[4]; 66 }; 67 68 69 struct live_node_info { 70 live_node_info(); 71 ~live_node_info(); 72 73 media_node node; 74 BPoint hint_point; 75 char name[B_MEDIA_NAME_LENGTH]; 76 77 private: 78 char reserved[160]; 79 }; 80 81 82 struct media_request_info { 83 enum what_code { 84 B_SET_VIDEO_CLIPPING_FOR = 1, 85 B_REQUEST_FORMAT_CHANGE, 86 B_SET_OUTPUT_ENABLED, 87 B_SET_OUTPUT_BUFFERS_FOR, 88 89 B_FORMAT_CHANGED = 4097 90 }; 91 92 what_code what; 93 int32 change_tag; 94 status_t status; 95 int32 cookie; 96 void* user_data; 97 media_source source; 98 media_destination destination; 99 media_format format; 100 101 uint32 _reserved_[32]; 102 }; 103 104 105 struct media_node_attribute { 106 enum { 107 B_R40_COMPILED = 1, 108 B_USER_ATTRIBUTE_NAME = 0x1000000, 109 B_FIRST_USER_ATTRIBUTE 110 }; 111 112 uint32 what; 113 uint32 flags; 114 int64 data; 115 }; 116 117 118 namespace BPrivate { namespace media { 119 class TimeSourceObject; 120 class SystemTimeSourceObject; 121 class BMediaRosterEx; 122 } } // BPrivate::media 123 124 125 /*! BMediaNode is the indirect base class for all Media Kit participants. 126 However, you should use the more specific BBufferConsumer, BBufferProducer 127 and others rather than BMediaNode directly. It's OK to multiply inherit. 128 */ 129 class BMediaNode { 130 protected: 131 // NOTE: Call Release() to destroy a node. 132 virtual ~BMediaNode(); 133 134 public: 135 enum run_mode { 136 B_OFFLINE = 1, 137 // This mode has realtime constraint. 138 B_DECREASE_PRECISION, 139 // When late, try to catch up by reducing quality. 140 B_INCREASE_LATENCY, 141 // When late, increase the presentation time offset. 142 B_DROP_DATA, 143 // When late, try to catch up by dropping buffers. 144 B_RECORDING 145 // For nodes on the receiving end of recording. 146 // Buffers will always be late. 147 }; 148 149 BMediaNode* Acquire(); 150 BMediaNode* Release(); 151 152 const char* Name() const; 153 media_node_id ID() const; 154 uint64 Kinds() const; 155 media_node Node() const; 156 run_mode RunMode() const; 157 BTimeSource* TimeSource() const; 158 159 // ID of the port used to listen to control messages. 160 virtual port_id ControlPort() const; 161 162 // Who instantiated this node or NULL for application internal class. 163 virtual BMediaAddOn* AddOn(int32* internalID) const = 0; 164 165 // Message constants which will be sent to anyone watching the 166 // MediaRoster. The message field "be:node_id" will contain the node ID. 167 enum node_error { 168 // Note that these belong with the notifications in 169 // MediaDefs.h! They are here to provide compiler type 170 // checking in ReportError(). 171 B_NODE_FAILED_START = 'TRI0', 172 B_NODE_FAILED_STOP = 'TRI1', 173 B_NODE_FAILED_SEEK = 'TRI2', 174 B_NODE_FAILED_SET_RUN_MODE = 'TRI3', 175 B_NODE_FAILED_TIME_WARP = 'TRI4', 176 B_NODE_FAILED_PREROLL = 'TRI5', 177 B_NODE_FAILED_SET_TIME_SOURCE_FOR = 'TRI6', 178 B_NODE_IN_DISTRESS = 'TRI7' 179 // What field 'TRIA' and up are used in MediaDefs.h 180 }; 181 182 protected: 183 // Sends one of the above codes to anybody who's watching. You can 184 // provide an optional message with additional information. 185 status_t ReportError(node_error what, 186 const BMessage* info = NULL); 187 188 // When you've handled a stop request, call this function. If anyone is 189 // listening for stop information from you, they will be notified. 190 // Especially important for offline capable Nodes. 191 status_t NodeStopped(bigtime_t performanceTime); 192 void TimerExpired(bigtime_t notifyPerformanceTime, 193 int32 cookie, status_t error = B_OK); 194 195 // NOTE: Constructor initializes the reference count to 1. 196 explicit BMediaNode(const char* name); 197 198 status_t WaitForMessage(bigtime_t waitUntil, 199 uint32 flags = 0, void* _reserved_ = 0); 200 201 // These don't return errors; instead, they use the global error condition 202 // reporter. A node is required to have a queue of at least one pending 203 // command (plus TimeWarp) and is recommended to allow for at least one 204 // pending command of each type. Allowing an arbitrary number of 205 // outstanding commands might be nice, but apps cannot depend on that 206 // happening. 207 virtual void Start(bigtime_t atPerformanceTime); 208 virtual void Stop(bigtime_t atPerformanceTime, 209 bool immediate); 210 virtual void Seek(bigtime_t toMediaTime, 211 bigtime_t atPerformanceTime); 212 virtual void SetRunMode(run_mode mode); 213 virtual void TimeWarp(bigtime_t atRealTime, 214 bigtime_t toPerformanceTime); 215 virtual void Preroll(); 216 virtual void SetTimeSource(BTimeSource* timeSource); 217 218 public: 219 virtual status_t HandleMessage(int32 message, const void* data, 220 size_t size); 221 222 // Call this with messages you and your superclasses don't recognize. 223 void HandleBadMessage(int32 code, 224 const void* buffer, size_t size); 225 226 // Called from derived system classes; you don't need to 227 void AddNodeKind(uint64 kind); 228 229 // These just call the default global versions for now. 230 void* operator new(size_t size); 231 void* operator new(size_t size, 232 const std::nothrow_t&) throw(); 233 void operator delete(void* ptr); 234 void operator delete(void* ptr, 235 const std::nothrow_t&) throw(); 236 237 protected: 238 // Hook method which is called when requests have completed, or failed. 239 virtual status_t RequestCompleted( 240 const media_request_info & info); 241 242 virtual status_t DeleteHook(BMediaNode* node); 243 244 virtual void NodeRegistered(); 245 246 public: 247 248 // Fill out your attributes in the provided array, returning however 249 // many you have. 250 virtual status_t GetNodeAttributes( 251 media_node_attribute* _attributes, 252 size_t inMaxCount); 253 254 virtual status_t AddTimer(bigtime_t atPerformanceTime, 255 int32 cookie); 256 257 private: 258 friend class BTimeSource; 259 friend class BMediaRoster; 260 friend class BBufferProducer; 261 friend class BPrivate::media::TimeSourceObject; 262 friend class BPrivate::media::SystemTimeSourceObject; 263 friend class BPrivate::media::BMediaRosterEx; 264 265 // Deprecated in BeOS R4.1 266 int32 IncrementChangeTag(); 267 int32 ChangeTag(); 268 int32 MintChangeTag(); 269 status_t ApplyChangeTag(int32 previouslyReserved); 270 271 private: 272 // FBC padding and forbidden methods 273 status_t _Reserved_MediaNode_0(void*); 274 // RequestCompletionHook() 275 status_t _Reserved_MediaNode_1(void*); 276 // DeleteHook() 277 status_t _Reserved_MediaNode_2(void*); 278 // NodeRegistered() 279 status_t _Reserved_MediaNode_3(void*); 280 // GetNodeAttributes() 281 status_t _Reserved_MediaNode_4(void*); 282 // AddTimer() 283 virtual status_t _Reserved_MediaNode_5(void*); 284 virtual status_t _Reserved_MediaNode_6(void*); 285 virtual status_t _Reserved_MediaNode_7(void*); 286 virtual status_t _Reserved_MediaNode_8(void*); 287 virtual status_t _Reserved_MediaNode_9(void*); 288 virtual status_t _Reserved_MediaNode_10(void*); 289 virtual status_t _Reserved_MediaNode_11(void*); 290 virtual status_t _Reserved_MediaNode_12(void*); 291 virtual status_t _Reserved_MediaNode_13(void*); 292 virtual status_t _Reserved_MediaNode_14(void*); 293 virtual status_t _Reserved_MediaNode_15(void*); 294 295 BMediaNode(); 296 BMediaNode(const BMediaNode& other); 297 BMediaNode& operator=(const BMediaNode& other); 298 299 private: 300 BMediaNode(const char* name, 301 media_node_id id, uint32 kinds); 302 303 void _InitObject(const char* name, 304 media_node_id id, uint64 kinds); 305 306 private: 307 media_node_id fNodeID; 308 BTimeSource* fTimeSource; 309 int32 fRefCount; 310 char fName[B_MEDIA_NAME_LENGTH]; 311 run_mode fRunMode; 312 313 int32 _reserved[2]; 314 315 uint64 fKinds; 316 media_node_id fTimeSourceID; 317 318 BBufferProducer* fProducerThis; 319 BBufferConsumer* fConsumerThis; 320 BFileInterface* fFileInterfaceThis; 321 BControllable* fControllableThis; 322 BTimeSource* fTimeSourceThis; 323 324 bool _reservedBool[4]; 325 326 mutable port_id fControlPort; 327 328 uint32 _reserved_media_node_[8]; 329 330 protected: 331 static int32 NewChangeTag(); 332 // for use by BBufferConsumer, mostly 333 334 private: 335 // NOTE: Dont' rename this one, it's static and needed for binary 336 // compatibility 337 static int32 _m_changeTag; 338 // not to be confused with _mChangeCount 339 }; 340 341 #endif // _MEDIA_NODE_H 342