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