1 /* 2 * Controller.h - Media Player for the Haiku Operating System 3 * 4 * Copyright (C) 2006 Marcus Overhagen <marcus@overhagen.de> 5 * Copyright (C) 2007-2008 Stephan Aßmus <superstippi@gmx.de> (MIT Ok) 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * version 2 as published by the Free Software Foundation. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 * 20 */ 21 #ifndef __CONTROLLER_H 22 #define __CONTROLLER_H 23 24 #include <Entry.h> 25 #include <MediaDefs.h> 26 #include <MediaFormats.h> 27 #include <MediaNode.h> 28 #include <List.h> 29 #include <Locker.h> 30 #include <String.h> 31 32 #include "ListenerAdapter.h" 33 #include "NodeManager.h" 34 35 class AudioTrackSupplier; 36 class BBitmap; 37 class BMediaFile; 38 class BMediaTrack; 39 class ProxyAudioSupplier; 40 class ProxyVideoSupplier; 41 class SoundOutput; 42 class VideoTrackSupplier; 43 class VideoView; 44 45 class Controller : public NodeManager { 46 public: 47 48 class Listener { 49 public: 50 Listener(); 51 virtual ~Listener(); 52 53 virtual void FileFinished(); 54 virtual void FileChanged(); 55 56 virtual void VideoTrackChanged(int32 index); 57 virtual void AudioTrackChanged(int32 index); 58 59 virtual void VideoStatsChanged(); 60 virtual void AudioStatsChanged(); 61 62 virtual void PlaybackStateChanged(uint32 state); 63 virtual void PositionChanged(float position); 64 virtual void VolumeChanged(float volume); 65 virtual void MutedChanged(bool muted); 66 }; 67 68 Controller(); 69 virtual ~Controller(); 70 71 // PlaybackManager interface 72 virtual void MessageReceived(BMessage* message); 73 virtual int64 Duration(); 74 75 // NodeManager interface 76 virtual VideoTarget* CreateVideoTarget(); 77 virtual VideoSupplier* CreateVideoSupplier(); 78 virtual AudioSupplier* CreateAudioSupplier(); 79 80 // Controller 81 status_t SetTo(const entry_ref &ref); 82 entry_ref Ref() const 83 { return fRef; } 84 void PlayerActivated(bool active); 85 86 void GetSize(int *width, int *height); 87 88 int AudioTrackCount(); 89 int VideoTrackCount(); 90 91 status_t SelectAudioTrack(int n); 92 int CurrentAudioTrack(); 93 status_t SelectVideoTrack(int n); 94 int CurrentVideoTrack(); 95 96 void Stop(); 97 void Play(); 98 void Pause(); 99 void TogglePlaying(); 100 101 uint32 PlaybackState(); 102 103 bigtime_t TimeDuration(); 104 bigtime_t TimePosition(); 105 106 virtual void SetVolume(float factor); 107 float Volume(); 108 void VolumeUp(); 109 void VolumeDown(); 110 void ToggleMute(); 111 void SetPosition(float value); 112 113 bool HasFile(); 114 status_t GetFileFormatInfo( 115 media_file_format* fileFormat); 116 status_t GetCopyright(BString* copyright); 117 status_t GetLocation(BString* location); 118 status_t GetName(BString* name); 119 status_t GetEncodedVideoFormat(media_format* format); 120 status_t GetVideoCodecInfo(media_codec_info* info); 121 status_t GetEncodedAudioFormat(media_format* format); 122 status_t GetAudioCodecInfo(media_codec_info* info); 123 124 // video view 125 void SetVideoView(VideoView *view); 126 127 bool IsOverlayActive(); 128 129 // notification support 130 bool AddListener(Listener* listener); 131 void RemoveListener(Listener* listener); 132 133 private: 134 void _AdoptGlobalSettings(); 135 136 uint32 _PlaybackState(int32 playingMode) const; 137 138 void _NotifyFileChanged() const; 139 void _NotifyFileFinished() const; 140 void _NotifyVideoTrackChanged(int32 index) const; 141 void _NotifyAudioTrackChanged(int32 index) const; 142 143 void _NotifyVideoStatsChanged() const; 144 void _NotifyAudioStatsChanged() const; 145 146 void _NotifyPlaybackStateChanged(uint32 state) const; 147 void _NotifyPositionChanged(float position) const; 148 void _NotifyVolumeChanged(float volume) const; 149 void _NotifyMutedChanged(bool muted) const; 150 151 // overridden from PlaybackManager so that we 152 // can use our own Listener mechanism 153 virtual void NotifyPlayModeChanged(int32 mode) const; 154 virtual void NotifyLoopModeChanged(int32 mode) const; 155 virtual void NotifyLoopingEnabledChanged( 156 bool enabled) const; 157 virtual void NotifyVideoBoundsChanged(BRect bounds) const; 158 virtual void NotifyFPSChanged(float fps) const; 159 virtual void NotifyCurrentFrameChanged(int32 frame) const; 160 virtual void NotifySpeedChanged(float speed) const; 161 virtual void NotifyFrameDropped() const; 162 virtual void NotifyStopFrameReached() const; 163 164 165 VideoView* fVideoView; 166 float fVolume; 167 float fActiveVolume; 168 bool fMuted; 169 170 entry_ref fRef; 171 BMediaFile* fMediaFile; 172 173 ProxyVideoSupplier* fVideoSupplier; 174 ProxyAudioSupplier* fAudioSupplier; 175 VideoTrackSupplier* fVideoTrackSupplier; 176 AudioTrackSupplier* fAudioTrackSupplier; 177 178 BList fAudioTrackList; 179 BList fVideoTrackList; 180 181 mutable bigtime_t fPosition; 182 bigtime_t fDuration; 183 float fVideoFrameRate; 184 mutable int32 fSeekFrame; 185 bigtime_t fLastSeekEventTime; 186 187 ListenerAdapter fGlobalSettingsListener; 188 189 bool fAutoplaySetting; 190 // maintains the auto-play setting 191 bool fAutoplay; 192 // is true if the player is already playing 193 // otherwise it's the same as fAutoplaySetting 194 bool fLoopMovies; 195 bool fLoopSounds; 196 uint32 fBackgroundMovieVolumeMode; 197 198 BList fListeners; 199 }; 200 201 202 #endif 203 204