1 /******************************************************************************* 2 / 3 / File: TimeSource.h 4 / 5 / Description: A BTimeSource is something to which others can slave timing information 6 / using the Media Kit. 7 / 8 / Copyright 1997-98, Be Incorporated, All Rights Reserved 9 / 10 *******************************************************************************/ 11 12 #if !defined(_TIME_SOURCE_H) 13 #define _TIME_SOURCE_H 14 15 #include <MediaDefs.h> 16 #include <MediaNode.h> 17 18 19 class _BSlaveNodeStorageP; 20 21 namespace BPrivate { namespace media { 22 class BMediaRosterEx; 23 class TimeSourceObject; 24 class SystemTimeSourceObject; 25 class SlaveNodes; 26 struct TimeSourceTransmit; 27 } } 28 29 30 class BTimeSource : 31 public virtual BMediaNode 32 { 33 protected: 34 /* this has to be at the top to force a vtable */ 35 virtual ~BTimeSource(); 36 37 public: 38 39 virtual status_t SnoozeUntil( /* returns error if stopped */ 40 bigtime_t performance_time, 41 bigtime_t with_latency = 0, 42 bool retry_signals = false); 43 44 bigtime_t Now(); /* convenience, less accurate */ 45 bigtime_t PerformanceTimeFor( /* all three go through GetTime() */ 46 bigtime_t real_time); 47 bigtime_t RealTimeFor( 48 bigtime_t performance_time, 49 bigtime_t with_latency); 50 bool IsRunning(); 51 52 status_t GetTime( /* return B_OK if reading is usable */ 53 bigtime_t * performance_time, 54 bigtime_t * real_time, 55 float * drift); 56 57 static bigtime_t RealTime(); /* this produces real time, nothing else is guaranteed to */ 58 59 status_t GetStartLatency( 60 bigtime_t * out_latency); 61 62 protected: 63 64 BTimeSource(); 65 66 virtual status_t HandleMessage( 67 int32 message, 68 const void * data, 69 size_t size); 70 71 void PublishTime( /* call this at convenient times to update approximation */ 72 bigtime_t performance_time, 73 bigtime_t real_time, 74 float drift); 75 76 void BroadcastTimeWarp( 77 bigtime_t at_real_time, 78 bigtime_t new_performance_time); /* when running */ 79 void SendRunMode( 80 run_mode mode); 81 82 virtual void SetRunMode( 83 run_mode mode); /* or, instead, SendRunMode() */ 84 85 enum time_source_op { 86 B_TIMESOURCE_START = 1, 87 B_TIMESOURCE_STOP, 88 B_TIMESOURCE_STOP_IMMEDIATELY, 89 B_TIMESOURCE_SEEK 90 }; 91 struct time_source_op_info { 92 time_source_op op; 93 int32 _reserved1; 94 bigtime_t real_time; 95 bigtime_t performance_time; 96 int32 _reserved2[6]; 97 }; 98 virtual status_t TimeSourceOp( 99 const time_source_op_info & op, 100 void * _reserved) = 0; 101 102 private: 103 104 friend class BMediaNode; 105 friend class BMediaRoster; 106 friend class BPrivate::media::BMediaRosterEx; 107 friend class BPrivate::media::TimeSourceObject; 108 friend class BPrivate::media::SystemTimeSourceObject; 109 110 BTimeSource( /* private unimplemented */ 111 const BTimeSource & clone); 112 BTimeSource & operator=( 113 const BTimeSource & clone); 114 115 /* Mmmh, stuffing! */ 116 status_t _Reserved_TimeSource_0(void *); // TimeSourceOp() 117 virtual status_t _Reserved_TimeSource_1(void *); 118 virtual status_t _Reserved_TimeSource_2(void *); 119 virtual status_t _Reserved_TimeSource_3(void *); 120 virtual status_t _Reserved_TimeSource_4(void *); 121 virtual status_t _Reserved_TimeSource_5(void *); 122 123 bool fStarted; 124 area_id fArea; 125 volatile BPrivate::media::TimeSourceTransmit *fBuf; 126 BPrivate::media::SlaveNodes *fSlaveNodes; 127 128 area_id _reserved_area; 129 bool fIsRealtime; 130 bool _reserved_bool_[3]; 131 uint32 _reserved_time_source_[10]; 132 133 explicit BTimeSource( 134 media_node_id id); 135 void FinishCreate(); /* called by roster and/or server */ 136 137 virtual status_t RemoveMe(BMediaNode * node); 138 virtual status_t AddMe(BMediaNode * node); 139 140 void DirectStart(bigtime_t at); 141 void DirectStop(bigtime_t at, bool immediate); 142 void DirectSeek(bigtime_t to, bigtime_t at); 143 void DirectSetRunMode(run_mode mode); 144 void DirectAddMe(const media_node &node); 145 void DirectRemoveMe(const media_node &node); 146 }; 147 148 149 #endif /* _TIME_SOURCE_H */ 150 151