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