1 /* ================ 2 3 FILE: MediaModule.h 4 REVS: $Revision: 1.1 $ 5 NAME: marc 6 7 Copyright (c) 1997 by Be Incorporated. All Rights Reserved. 8 9 ================ */ 10 11 #ifndef _MEDIA_MODULE_H 12 #define _MEDIA_MODULE_H 13 14 #include <List.h> 15 #include <Locker.h> 16 17 typedef double mk_time; 18 typedef double mk_rate; 19 typedef void (*mk_deferred_call)(void*); 20 21 #define B_UNDEFINED_MK_TIME ((mk_time) -1) 22 23 enum transport_status { 24 B_TRANSPORT_RUNNING, 25 B_TRANSPORT_STOPPED, 26 B_TRANSPORT_PAUSED 27 }; 28 29 enum channel_selector { 30 B_VIDEO_MAIN_CHANNEL, 31 B_VIDEO_MONITOR_CHANNEL, 32 B_AUDIO_FRONT_CHANNEL, 33 B_AUDIO_CENTER_CHANNEL, 34 B_AUDIO_REAR_CHANNEL, 35 B_AUDIO_SUB_CHANNEL, 36 B_AUDIO_MONITOR_CHANNEL, 37 B_MIDI_CHANNEL, 38 B_MISC_CHANNEL 39 }; 40 41 42 class BMediaRenderer; 43 class BTransport; 44 class BTimeBase; 45 class BMessage; 46 class BMediaChannel; 47 48 49 class BMediaEvent { 50 public: ~BMediaEvent()51 virtual ~BMediaEvent() {}; 52 virtual mk_time Start() = 0; 53 virtual mk_time Duration(); 54 virtual bigtime_t CaptureTime(); 55 }; 56 57 58 class BEventStream { 59 public: 60 BEventStream(); 61 virtual ~BEventStream(); 62 63 virtual mk_time Start(); 64 virtual void SetStart(mk_time); 65 virtual mk_time Duration(); 66 virtual void SetDuration(mk_time); 67 virtual BMediaEvent* GetEvent(BMediaChannel* channel) = 0; 68 virtual BMediaEvent* PeekEvent(BMediaChannel* channel, 69 mk_time asap = 0) = 0; 70 virtual status_t SeekToTime(BMediaChannel* channel, 71 mk_time time); 72 73 private: 74 mk_time fStart; 75 mk_time fDuration; 76 }; 77 78 79 class BMediaRenderer { 80 public: 81 BMediaRenderer(const char* name = NULL, int32 priority = B_NORMAL_PRIORITY); 82 virtual ~BMediaRenderer(); 83 84 virtual char* Name(); 85 virtual mk_time Latency(); 86 virtual BTransport* Transport(); 87 virtual void SetTransport(BTransport*); 88 virtual mk_time Start(); 89 virtual mk_time Duration(); 90 virtual BTimeBase* TimeBase(); 91 92 virtual void Open(); 93 virtual void Close(); 94 virtual void WakeUp(); 95 virtual void TransportChanged(mk_time time, mk_rate rate, 96 transport_status status); 97 virtual void StreamChanged(); 98 99 virtual void OpenReceived(); 100 virtual void CloseReceived(); 101 virtual void WakeUpReceived(); 102 virtual void TransportChangedReceived(mk_time time, mk_rate rate, 103 transport_status status); 104 virtual void StreamChangedReceived(); 105 106 private: 107 static int32 _LoopThread(void* arg); 108 void LoopThread(); 109 110 thread_id fLoopThread; 111 sem_id fLoopSem; 112 int32 fFlags; 113 mk_time fTCTime; 114 mk_rate fTCRate; 115 transport_status fTCStatus; 116 BLocker fLoopLock; 117 118 char* fName; 119 BTransport* fTransport; 120 }; 121 122 123 class BTransport { 124 public: 125 BTransport(); 126 virtual ~BTransport(); 127 128 virtual BTimeBase* TimeBase(); 129 virtual void SetTimeBase(BTimeBase*); 130 virtual BList* Renderers(); 131 virtual void AddRenderer(BMediaRenderer*); 132 virtual bool RemoveRenderer(BMediaRenderer*); 133 virtual transport_status Status(); 134 virtual void SetStatus(transport_status); 135 virtual mk_time PerformanceTime(); 136 virtual mk_rate PerformanceRate(); 137 virtual mk_time TimeOffset(); 138 virtual void SetTimeOffset(mk_time); 139 virtual mk_time MaximumLatency(); 140 virtual mk_time PerformanceStart(); 141 virtual mk_time PerformanceEnd(); 142 virtual void Open(); 143 virtual void Close(); 144 virtual void TransportChanged(); 145 virtual void TimeSkipped(); 146 virtual void RequestWakeUp(mk_time, BMediaRenderer*); 147 virtual void SeekToTime(mk_time); 148 virtual BMediaChannel* GetChannel(int32 selector); 149 150 private: 151 BTimeBase* fTimeBase; 152 BList fRenderers; 153 BList fChannels; 154 BLocker fChannelListLock; 155 transport_status fStatus; 156 mk_time fTimeOffset; 157 }; 158 159 160 class BTimeBase { 161 public: 162 BTimeBase(mk_rate rate = 1.0); 163 virtual ~BTimeBase(); 164 165 virtual BList* Transports(); 166 virtual void AddTransport(BTransport*); 167 virtual bool RemoveTransport(BTransport*); 168 virtual void TimeSkipped(); 169 virtual status_t CallAt(mk_time time, mk_deferred_call function, void* arg); 170 virtual mk_time Time(); 171 virtual mk_rate Rate(); 172 virtual mk_time TimeAt(bigtime_t system_time); 173 virtual bigtime_t SystemTimeAt(mk_time time); 174 virtual void Sync(mk_time time, bigtime_t system_time); 175 virtual bool IsAbsolute(); 176 177 private: 178 static int32 _SnoozeThread(void* arg); 179 void SnoozeThread(); 180 181 BList fTransports; 182 BList fDeferredCalls; 183 BLocker fLock; 184 mk_rate fRate; 185 mk_time fSyncT; 186 bigtime_t fSyncS; 187 mk_time fSnoozeUntil; 188 thread_id fSnoozeThread; 189 }; 190 191 192 class BMediaChannel { 193 public: 194 BMediaChannel(mk_rate rate, 195 BMediaRenderer* renderer = NULL, 196 BEventStream* source = NULL); 197 virtual ~BMediaChannel(); 198 199 virtual BMediaRenderer* Renderer(); 200 virtual void SetRenderer(BMediaRenderer*); 201 virtual BEventStream* Source(); 202 virtual void SetSource(BEventStream*); 203 virtual mk_rate Rate(); 204 virtual void SetRate(mk_rate); 205 bool LockChannel(); 206 status_t LockWithTimeout(bigtime_t); 207 void UnlockChannel(); 208 virtual void StreamChanged(); 209 210 private: 211 mk_rate fRate; 212 BMediaRenderer* fRenderer; 213 BEventStream* fSource; 214 BLocker fChannelLock; 215 }; 216 217 218 #endif 219