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