1 /* 2 * Copyright 2009, Haiku Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _TIME_SOURCE_H 6 #define _TIME_SOURCE_H 7 8 9 #include <MediaDefs.h> 10 #include <MediaNode.h> 11 12 13 class _BSlaveNodeStorageP; 14 15 namespace BPrivate { 16 namespace media { 17 class BMediaRosterEx; 18 class TimeSourceObject; 19 class SystemTimeSourceObject; 20 class SlaveNodes; 21 struct TimeSourceTransmit; 22 } 23 } 24 25 26 class BTimeSource : public virtual BMediaNode { 27 protected: 28 virtual ~BTimeSource(); 29 30 public: 31 virtual status_t SnoozeUntil(bigtime_t performanceTime, 32 bigtime_t withLatency = 0, 33 bool retrySignals = false); 34 35 bigtime_t Now(); 36 bigtime_t PerformanceTimeFor(bigtime_t realTime); 37 bigtime_t RealTimeFor(bigtime_t performanceTime, 38 bigtime_t withLatency); 39 bool IsRunning(); 40 41 status_t GetTime(bigtime_t* _performanceTime, 42 bigtime_t* _realTime, float* _drift); 43 status_t GetStartLatency(bigtime_t* _latency); 44 45 static bigtime_t RealTime(); 46 47 protected: 48 BTimeSource(); 49 50 virtual status_t HandleMessage(int32 message, const void* data, 51 size_t size); 52 53 void PublishTime(bigtime_t performanceTime, 54 bigtime_t realTime, float drift); 55 56 void BroadcastTimeWarp(bigtime_t atRealTime, 57 bigtime_t newPerformanceTime); 58 59 void SendRunMode(run_mode mode); 60 virtual void SetRunMode(run_mode mode); 61 62 enum time_source_op { 63 B_TIMESOURCE_START = 1, 64 B_TIMESOURCE_STOP, 65 B_TIMESOURCE_STOP_IMMEDIATELY, 66 B_TIMESOURCE_SEEK 67 }; 68 69 struct time_source_op_info { 70 time_source_op op; 71 int32 _reserved1; 72 bigtime_t real_time; 73 bigtime_t performance_time; 74 int32 _reserved2[6]; 75 }; 76 77 virtual status_t TimeSourceOp(const time_source_op_info& op, 78 void* _reserved) = 0; 79 80 private: 81 friend class BMediaNode; 82 friend class BMediaRoster; 83 friend class BPrivate::media::BMediaRosterEx; 84 friend class BPrivate::media::SystemTimeSourceObject; 85 friend class BPrivate::media::TimeSourceObject; 86 87 BTimeSource(const BTimeSource& other); 88 BTimeSource& operator=(const BTimeSource& other); 89 // not implemented 90 91 explicit BTimeSource(media_node_id id); 92 93 status_t _Reserved_TimeSource_0(void*); 94 // used for TimeSourceOp() 95 virtual status_t _Reserved_TimeSource_1(void*); 96 virtual status_t _Reserved_TimeSource_2(void*); 97 virtual status_t _Reserved_TimeSource_3(void*); 98 virtual status_t _Reserved_TimeSource_4(void*); 99 virtual status_t _Reserved_TimeSource_5(void*); 100 101 virtual status_t RemoveMe(BMediaNode* node); 102 virtual status_t AddMe(BMediaNode* node); 103 104 void FinishCreate(); 105 106 void DirectStart(bigtime_t at); 107 void DirectStop(bigtime_t at, bool immediate); 108 void DirectSeek(bigtime_t to, bigtime_t at); 109 void DirectSetRunMode(run_mode mode); 110 void DirectAddMe(const media_node& node); 111 void DirectRemoveMe(const media_node& node); 112 113 private: 114 bool fStarted; 115 area_id fArea; 116 volatile BPrivate::media::TimeSourceTransmit* fBuf; 117 BPrivate::media::SlaveNodes* fSlaveNodes; 118 119 area_id _reserved_area; 120 bool fIsRealtime; 121 bool _reserved_bool_[3]; 122 uint32 _reserved_time_source_[10]; 123 }; 124 125 126 #endif // _TIME_SOURCE_H 127