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 25 #include <Entry.h> 26 #include <MediaDefs.h> 27 #include <MediaFormats.h> 28 #include <MediaNode.h> 29 #include <List.h> 30 #include <Locker.h> 31 #include <String.h> 32 33 #include "ListenerAdapter.h" 34 #include "NodeManager.h" 35 #include "PlaylistItem.h" 36 37 38 class AudioTrackSupplier; 39 class BBitmap; 40 class BMediaFile; 41 class BMediaTrack; 42 class PlaylistItem; 43 class ProxyAudioSupplier; 44 class ProxyVideoSupplier; 45 class SoundOutput; 46 class VideoTrackSupplier; 47 class VideoView; 48 49 50 class Controller : public NodeManager { 51 public: 52 class Listener { 53 public: 54 Listener(); 55 virtual ~Listener(); 56 57 virtual void FileFinished(); 58 virtual void FileChanged(PlaylistItem* item, 59 status_t result); 60 61 virtual void VideoTrackChanged(int32 index); 62 virtual void AudioTrackChanged(int32 index); 63 64 virtual void VideoStatsChanged(); 65 virtual void AudioStatsChanged(); 66 67 virtual void PlaybackStateChanged(uint32 state); 68 virtual void PositionChanged(float position); 69 virtual void VolumeChanged(float volume); 70 virtual void MutedChanged(bool muted); 71 }; 72 73 Controller(); 74 virtual ~Controller(); 75 76 // PlaybackManager interface 77 virtual void MessageReceived(BMessage* message); 78 virtual int64 Duration(); 79 80 // NodeManager interface 81 virtual VideoTarget* CreateVideoTarget(); 82 virtual VideoSupplier* CreateVideoSupplier(); 83 virtual AudioSupplier* CreateAudioSupplier(); 84 85 // Controller 86 status_t SetToAsync(const PlaylistItemRef& item); 87 status_t SetTo(const PlaylistItemRef& item); 88 const PlaylistItem* Item() const 89 { return fItem.Get(); } 90 void PlayerActivated(bool active); 91 92 void GetSize(int *width, int *height, 93 int* widthAspect = NULL, 94 int* heightAspect = NULL); 95 96 int AudioTrackCount(); 97 int VideoTrackCount(); 98 99 status_t SelectAudioTrack(int n); 100 int CurrentAudioTrack(); 101 status_t SelectVideoTrack(int n); 102 int CurrentVideoTrack(); 103 104 void Stop(); 105 void Play(); 106 void Pause(); 107 void TogglePlaying(); 108 109 uint32 PlaybackState(); 110 111 bigtime_t TimeDuration(); 112 bigtime_t TimePosition(); 113 114 virtual void SetVolume(float factor); 115 float Volume(); 116 void VolumeUp(); 117 void VolumeDown(); 118 void ToggleMute(); 119 void SetPosition(float value); 120 void SetFramePosition(int32 frame); 121 void SetTimePosition(bigtime_t position); 122 123 bool HasFile(); 124 status_t GetFileFormatInfo( 125 media_file_format* fileFormat); 126 status_t GetCopyright(BString* copyright); 127 status_t GetLocation(BString* location); 128 status_t GetName(BString* name); 129 status_t GetEncodedVideoFormat(media_format* format); 130 status_t GetVideoCodecInfo(media_codec_info* info); 131 status_t GetEncodedAudioFormat(media_format* format); 132 status_t GetAudioCodecInfo(media_codec_info* info); 133 134 // video view 135 void SetVideoView(VideoView *view); 136 137 bool IsOverlayActive(); 138 139 // notification support 140 bool AddListener(Listener* listener); 141 void RemoveListener(Listener* listener); 142 143 private: 144 void _AdoptGlobalSettings(); 145 146 uint32 _PlaybackState(int32 playingMode) const; 147 148 void _NotifyFileChanged(PlaylistItem* item, 149 status_t result) const; 150 void _NotifyFileFinished() const; 151 void _NotifyVideoTrackChanged(int32 index) const; 152 void _NotifyAudioTrackChanged(int32 index) const; 153 154 void _NotifyVideoStatsChanged() const; 155 void _NotifyAudioStatsChanged() const; 156 157 void _NotifyPlaybackStateChanged(uint32 state) const; 158 void _NotifyPositionChanged(float position) const; 159 void _NotifyVolumeChanged(float volume) const; 160 void _NotifyMutedChanged(bool muted) const; 161 162 // overridden from PlaybackManager so that we 163 // can use our own Listener mechanism 164 virtual void NotifyPlayModeChanged(int32 mode) const; 165 virtual void NotifyLoopModeChanged(int32 mode) const; 166 virtual void NotifyLoopingEnabledChanged( 167 bool enabled) const; 168 virtual void NotifyVideoBoundsChanged(BRect bounds) const; 169 virtual void NotifyFPSChanged(float fps) const; 170 virtual void NotifyCurrentFrameChanged(int32 frame) const; 171 virtual void NotifySpeedChanged(float speed) const; 172 virtual void NotifyFrameDropped() const; 173 virtual void NotifyStopFrameReached() const; 174 virtual void NotifySeekHandled() const; 175 176 177 VideoView* fVideoView; 178 float fVolume; 179 float fActiveVolume; 180 bool fMuted; 181 182 PlaylistItemRef fItem; 183 BMediaFile* fMediaFile; 184 185 ProxyVideoSupplier* fVideoSupplier; 186 ProxyAudioSupplier* fAudioSupplier; 187 VideoTrackSupplier* fVideoTrackSupplier; 188 AudioTrackSupplier* fAudioTrackSupplier; 189 190 BList fAudioTrackList; 191 BList fVideoTrackList; 192 193 mutable bigtime_t fPosition; 194 bigtime_t fDuration; 195 float fVideoFrameRate; 196 197 mutable bool fSeekRequested; 198 mutable int32 fSeekFrame; 199 200 ListenerAdapter fGlobalSettingsListener; 201 202 bool fAutoplaySetting; 203 // maintains the auto-play setting 204 bool fAutoplay; 205 // is true if the player is already playing 206 // otherwise it's the same as fAutoplaySetting 207 bool fLoopMovies; 208 bool fLoopSounds; 209 uint32 fBackgroundMovieVolumeMode; 210 211 BList fListeners; 212 }; 213 214 215 #endif // __CONTROLLER_H 216