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 { class TimeSourceObject; class SystemTimeSourceObject; } } 115 116 117 class BMediaNode 118 { 119 protected: 120 /* this has to be on top rather than bottom to force a vtable in mwcc */ 121 virtual ~BMediaNode(); /* should be called through Release() */ 122 public: 123 124 enum run_mode { 125 B_OFFLINE = 1, /* data accurate, no realtime constraint */ 126 B_DECREASE_PRECISION, /* when slipping, try to catch up */ 127 B_INCREASE_LATENCY, /* when slipping, increase playout delay */ 128 B_DROP_DATA, /* when slipping, skip data */ 129 B_RECORDING /* you're on the receiving end of recording; buffers are guaranteed to be late */ 130 }; 131 132 133 BMediaNode * Acquire(); /* return itself */ 134 BMediaNode * Release(); /* release will decrement refcount, and delete if 0 */ 135 136 const char * Name() const; 137 media_node_id ID() const; 138 uint64 Kinds() const; 139 media_node Node() const; 140 run_mode RunMode() const; 141 BTimeSource * TimeSource() const; 142 143 /* this port is what a media node listens to for commands */ 144 virtual port_id ControlPort() const; 145 146 virtual BMediaAddOn* AddOn( 147 int32 * internal_id) const = 0; /* Who instantiated you -- or NULL for app class */ 148 149 /* These will be sent to anyone watching the MediaRoster. */ 150 /* The message field "be:node_id" will contain the node ID. */ 151 enum node_error { 152 /* Note that these belong with the notifications in MediaDefs.h! */ 153 /* They are here to provide compiler type checking in ReportError(). */ 154 B_NODE_FAILED_START = 'TRI0', 155 B_NODE_FAILED_STOP, // TRI1 156 B_NODE_FAILED_SEEK, // TRI2 157 B_NODE_FAILED_SET_RUN_MODE, // TRI3 158 B_NODE_FAILED_TIME_WARP, // TRI4 159 B_NODE_FAILED_PREROLL, // TRI5 160 B_NODE_FAILED_SET_TIME_SOURCE_FOR, // TRI6 161 /* display this node with a blinking exclamation mark or something */ 162 B_NODE_IN_DISTRESS // TRI7 163 /* TRIA and up are used in MediaDefs.h */ 164 }; 165 166 protected: 167 168 /* Send one of the above codes to anybody who's watching. */ 169 status_t ReportError( 170 node_error what, 171 const BMessage * info = NULL); /* String "message" for instance */ 172 173 /* When you've handled a stop request, call this function. If anyone is */ 174 /* listening for stop information from you, they will be notified. Especially */ 175 /* important for offline capable Nodes. */ 176 status_t NodeStopped( 177 bigtime_t whenPerformance); // performance time 178 void TimerExpired( 179 bigtime_t notifyPoint, // performance time 180 int32 cookie, 181 status_t error = B_OK); 182 183 explicit BMediaNode( /* constructor sets refcount to 1 */ 184 const char * name); 185 186 status_t WaitForMessage( 187 bigtime_t waitUntil, 188 uint32 flags = 0, 189 void * _reserved_ = 0); 190 191 /* These don't return errors; instead, they use the global error condition reporter. */ 192 /* A node is required to have a queue of at least one pending command (plus TimeWarp) */ 193 /* and is recommended to allow for at least one pending command of each type. */ 194 /* Allowing an arbitrary number of outstanding commands might be nice, but apps */ 195 /* cannot depend on that happening. */ 196 virtual void Start( 197 bigtime_t performance_time); 198 virtual void Stop( 199 bigtime_t performance_time, 200 bool immediate); 201 virtual void Seek( 202 bigtime_t media_time, 203 bigtime_t performance_time); 204 virtual void SetRunMode( 205 run_mode mode); 206 virtual void TimeWarp( 207 bigtime_t at_real_time, 208 bigtime_t to_performance_time); 209 virtual void Preroll(); 210 virtual void SetTimeSource( 211 BTimeSource * time_source); 212 213 public: 214 215 virtual status_t HandleMessage( 216 int32 message, 217 const void * data, 218 size_t size); 219 void HandleBadMessage( /* call this with messages you and your superclasses don't recognize */ 220 int32 code, 221 const void * buffer, 222 size_t size); 223 224 /* Called from derived system classes; you don't need to */ 225 void AddNodeKind( 226 uint64 kind); 227 228 // These were not in 4.0. 229 // We added them in 4.1 for future use. They just call 230 // the default global versions for now. 231 void * operator new( 232 size_t size); 233 void * operator new( 234 size_t size, 235 const nothrow_t &) throw(); 236 void operator delete( 237 void * ptr); 238 #if !__MWERKS__ 239 // there's a bug in MWCC under R4.1 and earlier 240 void operator delete( 241 void * ptr, 242 const nothrow_t &) throw(); 243 #endif 244 245 protected: 246 247 /* Called when requests have completed, or failed. */ 248 virtual status_t RequestCompleted( /* reserved 0 */ 249 const media_request_info & info); 250 251 private: 252 friend class BTimeSource; 253 friend class _BTimeSourceP; 254 friend class BMediaRoster; 255 friend class _BMediaRosterP; 256 friend class MNodeManager; 257 friend class BBufferProducer; // for getting _mNodeID 258 friend class BPrivate::media::TimeSourceObject; 259 friend class BPrivate::media::SystemTimeSourceObject; 260 261 // Deprecated in 4.1 262 int32 IncrementChangeTag(); 263 int32 ChangeTag(); 264 int32 MintChangeTag(); 265 status_t ApplyChangeTag( 266 int32 previously_reserved); 267 268 /* Mmmh, stuffing! */ 269 protected: 270 271 virtual status_t DeleteHook(BMediaNode * node); /* reserved 1 */ 272 273 virtual void NodeRegistered(); /* reserved 2 */ 274 275 public: 276 277 /* fill out your attributes in the provided array, returning however many you have. */ 278 virtual status_t GetNodeAttributes( /* reserved 3 */ 279 media_node_attribute * outAttributes, 280 size_t inMaxCount); 281 282 virtual status_t AddTimer( 283 bigtime_t at_performance_time, 284 int32 cookie); 285 286 private: 287 288 status_t _Reserved_MediaNode_0(void *); /* DeleteHook() */ 289 status_t _Reserved_MediaNode_1(void *); /* RequestCompletionHook() */ 290 status_t _Reserved_MediaNode_2(void *); /* NodeRegistered() */ 291 status_t _Reserved_MediaNode_3(void *); /* GetNodeAttributes() */ 292 status_t _Reserved_MediaNode_4(void *); /* AddTimer() */ 293 virtual status_t _Reserved_MediaNode_5(void *); 294 virtual status_t _Reserved_MediaNode_6(void *); 295 virtual status_t _Reserved_MediaNode_7(void *); 296 virtual status_t _Reserved_MediaNode_8(void *); 297 virtual status_t _Reserved_MediaNode_9(void *); 298 virtual status_t _Reserved_MediaNode_10(void *); 299 virtual status_t _Reserved_MediaNode_11(void *); 300 virtual status_t _Reserved_MediaNode_12(void *); 301 virtual status_t _Reserved_MediaNode_13(void *); 302 virtual status_t _Reserved_MediaNode_14(void *); 303 virtual status_t _Reserved_MediaNode_15(void *); 304 305 BMediaNode(); /* private unimplemented */ 306 BMediaNode( 307 const BMediaNode & clone); 308 BMediaNode & operator=( 309 const BMediaNode & clone); 310 311 BMediaNode( /* constructor sets refcount to 1 */ 312 const char * name, 313 media_node_id id, 314 uint32 kinds); 315 316 void _InitObject(const char *, media_node_id, uint64); 317 318 media_node_id fNodeID; 319 BTimeSource * fTimeSource; 320 int32 fRefCount; 321 char fName[B_MEDIA_NAME_LENGTH]; 322 run_mode fRunMode; 323 int32 _mChangeCount; // deprecated 324 int32 _mChangeCountReserved; // deprecated 325 uint64 fKinds; 326 media_node_id _unused; 327 328 BBufferProducer * fProducerThis; 329 BBufferConsumer * fConsumerThis; 330 BFileInterface * fFileInterfaceThis; 331 BControllable * fControllableThis; 332 BTimeSource * fTimeSourceThis; 333 334 bool _mReservedBool[4]; 335 336 mutable port_id fControlPort; 337 338 uint32 _reserved_media_node_[8]; 339 340 341 342 protected: 343 344 static int32 NewChangeTag(); // for use by BBufferConsumer, mostly 345 346 private: 347 // dont' rename this one, it's static and needed for binary compatibility 348 static int32 _m_changeTag; // not to be confused with _mChangeCount 349 }; 350 351 352 353 #endif /* _MEDIA_NODE_H */ 354 355