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 void PlayerActivated(bool active); 83 84 void GetSize(int *width, int *height); 85 86 int AudioTrackCount(); 87 int VideoTrackCount(); 88 89 status_t SelectAudioTrack(int n); 90 int CurrentAudioTrack(); 91 status_t SelectVideoTrack(int n); 92 int CurrentVideoTrack(); 93 94 void Stop(); 95 void Play(); 96 void Pause(); 97 void TogglePlaying(); 98 99 uint32 PlaybackState(); 100 101 bigtime_t TimeDuration(); 102 bigtime_t TimePosition(); 103 104 virtual void SetVolume(float factor); 105 float Volume(); 106 void VolumeUp(); 107 void VolumeDown(); 108 void ToggleMute(); 109 void SetPosition(float value); 110 111 bool HasFile(); 112 status_t GetFileFormatInfo( 113 media_file_format* fileFormat); 114 status_t GetCopyright(BString* copyright); 115 status_t GetLocation(BString* location); 116 status_t GetName(BString* name); 117 status_t GetEncodedVideoFormat(media_format* format); 118 status_t GetVideoCodecInfo(media_codec_info* info); 119 status_t GetEncodedAudioFormat(media_format* format); 120 status_t GetAudioCodecInfo(media_codec_info* info); 121 122 // video view 123 void SetVideoView(VideoView *view); 124 125 bool IsOverlayActive(); 126 127 // notification support 128 bool AddListener(Listener* listener); 129 void RemoveListener(Listener* listener); 130 131 private: 132 void _AdoptGlobalSettings(); 133 134 uint32 _PlaybackState(int32 playingMode) const; 135 136 void _NotifyFileChanged() const; 137 void _NotifyFileFinished() const; 138 void _NotifyVideoTrackChanged(int32 index) const; 139 void _NotifyAudioTrackChanged(int32 index) const; 140 141 void _NotifyVideoStatsChanged() const; 142 void _NotifyAudioStatsChanged() const; 143 144 void _NotifyPlaybackStateChanged(uint32 state) const; 145 void _NotifyPositionChanged(float position) const; 146 void _NotifyVolumeChanged(float volume) const; 147 void _NotifyMutedChanged(bool muted) const; 148 149 // overridden from PlaybackManager so that we 150 // can use our own Listener mechanism 151 virtual void NotifyPlayModeChanged(int32 mode) const; 152 virtual void NotifyLoopModeChanged(int32 mode) const; 153 virtual void NotifyLoopingEnabledChanged( 154 bool enabled) const; 155 virtual void NotifyVideoBoundsChanged(BRect bounds) const; 156 virtual void NotifyFPSChanged(float fps) const; 157 virtual void NotifyCurrentFrameChanged(int32 frame) const; 158 virtual void NotifySpeedChanged(float speed) const; 159 virtual void NotifyFrameDropped() const; 160 virtual void NotifyStopFrameReached() const; 161 162 163 VideoView* fVideoView; 164 float fVolume; 165 float fActiveVolume; 166 bool fMuted; 167 168 entry_ref fRef; 169 BMediaFile* fMediaFile; 170 171 ProxyVideoSupplier* fVideoSupplier; 172 ProxyAudioSupplier* fAudioSupplier; 173 VideoTrackSupplier* fVideoTrackSupplier; 174 AudioTrackSupplier* fAudioTrackSupplier; 175 176 BList fAudioTrackList; 177 BList fVideoTrackList; 178 179 mutable bigtime_t fPosition; 180 bigtime_t fDuration; 181 float fVideoFrameRate; 182 mutable int32 fSeekFrame; 183 bigtime_t fLastSeekEventTime; 184 185 ListenerAdapter fGlobalSettingsListener; 186 bool fAutoplay; 187 bool fLoopMovies; 188 bool fLoopSounds; 189 uint32 fBackgroundMovieVolumeMode; 190 191 BList fListeners; 192 }; 193 194 195 #endif 196 197