1 /* 2 * Controller.h - Media Player for the Haiku Operating System 3 * 4 * Copyright (C) 2006 Marcus Overhagen <marcus@overhagen.de> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License 8 * version 2 as published by the Free Software Foundation. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 * 19 */ 20 #ifndef __CONTROLLER_H 21 #define __CONTROLLER_H 22 23 #include <MediaDefs.h> 24 #include <MediaNode.h> 25 #include <Locker.h> 26 #include <String.h> 27 28 class BBitmap; 29 class BMediaFile; 30 class BMediaTrack; 31 class SoundOutput; 32 class VideoView; 33 class ControllerView; 34 35 class Controller 36 { 37 public: 38 Controller(); 39 virtual ~Controller(); 40 41 status_t SetTo(const entry_ref &ref); 42 void GetSize(int *width, int *height); 43 44 int AudioTrackCount(); 45 int VideoTrackCount(); 46 47 status_t SelectAudioTrack(int n); 48 status_t SelectVideoTrack(int n); 49 50 bigtime_t Duration(); 51 bigtime_t Position(); 52 53 status_t Seek(bigtime_t pos); 54 55 void Stop(); 56 void Play(); 57 void Pause(); 58 bool IsPaused(); 59 bool IsStopped(); 60 61 void SetVideoView(VideoView *view); 62 void SetControllerView(ControllerView *view); 63 64 bool IsOverlayActive(); 65 66 void LockBitmap(); 67 void UnlockBitmap(); 68 BBitmap * Bitmap(); 69 70 void VolumeUp(); 71 void VolumeDown(); 72 73 void SetVolume(float value); 74 75 void SetPosition(float value); 76 77 void UpdateVolume(float value); 78 void UpdatePosition(float value); 79 80 private: 81 static int32 audio_decode_thread(void *self); 82 static int32 video_decode_thread(void *self); 83 static int32 audio_play_thread(void *self); 84 static int32 video_play_thread(void *self); 85 86 void AudioDecodeThread(); 87 void VideoDecodeThread(); 88 void AudioPlayThread(); 89 void VideoPlayThread(); 90 91 void StartThreads(); 92 void StopThreads(); 93 94 private: 95 96 enum { 97 MAX_AUDIO_BUFFERS = 8, 98 MAX_VIDEO_BUFFERS = 3, 99 }; 100 101 struct buffer_info { 102 char * buffer; 103 BBitmap * bitmap; 104 size_t sizeUsed; 105 size_t sizeMax; 106 bigtime_t startTime; 107 bool formatChanged; 108 media_format mediaFormat; 109 }; 110 111 VideoView * fVideoView; 112 ControllerView * fControllerView; 113 BString fName; 114 volatile bool fPaused; 115 volatile bool fStopped; 116 BMediaFile * fMediaFile; 117 BMediaTrack * fAudioTrack; 118 BMediaTrack * fVideoTrack; 119 120 BLocker fAudioTrackLock; 121 BLocker fVideoTrackLock; 122 123 BList * fAudioTrackList; 124 BList * fVideoTrackList; 125 bigtime_t fPosition; 126 media_format fAudioFormat; 127 media_format fVideoFormat; 128 129 sem_id fAudioDecodeSem; 130 sem_id fVideoDecodeSem; 131 sem_id fAudioPlaySem; 132 sem_id fVideoPlaySem; 133 sem_id fThreadWaitSem; 134 thread_id fAudioDecodeThread; 135 thread_id fVideoDecodeThread; 136 thread_id fAudioPlayThread; 137 thread_id fVideoPlayThread; 138 139 SoundOutput * fSoundOutput; 140 volatile bool fSeekAudio; 141 volatile bool fSeekVideo; 142 volatile bigtime_t fSeekPosition; 143 bigtime_t fDuration; 144 145 int32 fAudioBufferCount; 146 int32 fAudioBufferReadIndex; 147 int32 fAudioBufferWriteIndex; 148 int32 fVideoBufferCount; 149 int32 fVideoBufferReadIndex; 150 int32 fVideoBufferWriteIndex; 151 152 buffer_info fAudioBuffer[MAX_AUDIO_BUFFERS]; 153 buffer_info fVideoBuffer[MAX_VIDEO_BUFFERS]; 154 155 BLocker fTimeSourceLock; 156 bigtime_t fTimeSourceSysTime; 157 bigtime_t fTimeSourcePerfTime; 158 bool fAutoplay; 159 160 BBitmap * fCurrentBitmap; 161 162 }; 163 164 165 #endif 166 167