xref: /haiku/src/apps/mediaplayer/Controller.h (revision aa3083e086e5a929c061c72983e09d916c548a38)
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 TrackSupplier;
40 class PlaylistItem;
41 class ProxyAudioSupplier;
42 class ProxyVideoSupplier;
43 class SubTitles;
44 class VideoTrackSupplier;
45 class VideoView;
46 
47 
48 class Controller : public NodeManager {
49 public:
50 	class Listener {
51 	public:
52 								Listener();
53 		virtual					~Listener();
54 
55 		virtual	void			FileFinished();
56 		virtual	void			FileChanged(PlaylistItem* item,
57 									status_t result);
58 
59 		virtual	void			VideoTrackChanged(int32 index);
60 		virtual	void			AudioTrackChanged(int32 index);
61 		virtual	void			SubTitleTrackChanged(int32 index);
62 
63 		virtual	void			VideoStatsChanged();
64 		virtual	void			AudioStatsChanged();
65 
66 		virtual	void			PlaybackStateChanged(uint32 state);
67 		virtual	void			PositionChanged(float position);
68 		virtual	void			SeekHandled(int64 seekFrame);
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 			int					SubTitleTrackCount();
99 
100 			status_t			SelectAudioTrack(int n);
101 			int					CurrentAudioTrack();
102 			int					AudioTrackChannelCount();
103 			status_t			SelectVideoTrack(int n);
104 			int					CurrentVideoTrack();
105 			status_t			SelectSubTitleTrack(int n);
106 			int					CurrentSubTitleTrack();
107 			const char*			SubTitleTrackName(int n);
108 
109 			void				Stop();
110 			void				Play();
111 			void				Pause();
112 			void				TogglePlaying();
113 
114 			uint32				PlaybackState();
115 
116 			bigtime_t			TimeDuration();
117 			bigtime_t			TimePosition();
118 
119 	virtual	void				SetVolume(float factor);
120 			float				Volume();
121 			void				VolumeUp();
122 			void				VolumeDown();
123 			void				ToggleMute();
124 
125 			int64				SetPosition(float value);
126 			int64				SetFramePosition(int64 frame);
127 			int64				SetTimePosition(bigtime_t position);
128 
129 			bool				HasFile();
130 			status_t			GetFileFormatInfo(
131 									media_file_format* fileFormat);
132 			status_t			GetCopyright(BString* copyright);
133 			status_t			GetLocation(BString* location);
134 			status_t			GetName(BString* name);
135 			status_t			GetEncodedVideoFormat(media_format* format);
136 			status_t			GetVideoCodecInfo(media_codec_info* info);
137 			status_t			GetEncodedAudioFormat(media_format* format);
138 			status_t			GetAudioCodecInfo(media_codec_info* info);
139 
140 			status_t			GetMetaData(BMessage* metaData);
141 			status_t			GetVideoMetaData(int32 track,
142 									BMessage* metaData);
143 			status_t			GetAudioMetaData(int32 track,
144 									BMessage* metaData);
145 
146 	// video view
147 			void				SetVideoView(VideoView *view);
148 
149 			bool				IsOverlayActive();
150 
151 	// notification support
152 			bool				AddListener(Listener* listener);
153 			void				RemoveListener(Listener* listener);
154 
155 private:
156 			void				_AdoptGlobalSettings();
157 
158 			uint32				_PlaybackState(int32 playingMode) const;
159 			int64				_FrameDuration() const;
160 			bigtime_t			_TimePosition() const;
161 
162 			void				_NotifyFileChanged(PlaylistItem* item,
163 									status_t result) const;
164 			void				_NotifyFileFinished() const;
165 			void				_NotifyVideoTrackChanged(int32 index) const;
166 			void				_NotifyAudioTrackChanged(int32 index) const;
167 			void				_NotifySubTitleTrackChanged(int32 index) const;
168 
169 			void				_NotifyVideoStatsChanged() const;
170 			void				_NotifyAudioStatsChanged() const;
171 
172 			void				_NotifyPlaybackStateChanged(uint32 state) const;
173 			void				_NotifyPositionChanged(float position) const;
174 			void				_NotifySeekHandled(int64 seekFrame) const;
175 			void				_NotifyVolumeChanged(float volume) const;
176 			void				_NotifyMutedChanged(bool muted) const;
177 
178 	// overridden from PlaybackManager so that we
179 	// can use our own Listener mechanism
180 	virtual	void				NotifyPlayModeChanged(int32 mode) const;
181 	virtual	void				NotifyLoopModeChanged(int32 mode) const;
182 	virtual	void				NotifyLoopingEnabledChanged(
183 									bool enabled) const;
184 	virtual	void				NotifyVideoBoundsChanged(BRect bounds) const;
185 	virtual	void				NotifyFPSChanged(float fps) const;
186 	virtual	void				NotifyCurrentFrameChanged(int64 frame) const;
187 	virtual	void				NotifySpeedChanged(float speed) const;
188 	virtual	void				NotifyFrameDropped() const;
189 	virtual	void				NotifyStopFrameReached() const;
190 	virtual	void				NotifySeekHandled(int64 seekedFrame) const;
191 
192 
193 private:
194 			VideoView*			fVideoView;
195 			float				fVolume;
196 			float				fActiveVolume;
197 			bool				fMuted;
198 
199 			PlaylistItemRef		fItem;
200 
201 			ProxyVideoSupplier*	fVideoSupplier;
202 			ProxyAudioSupplier*	fAudioSupplier;
203 			VideoTrackSupplier*	fVideoTrackSupplier;
204 			AudioTrackSupplier*	fAudioTrackSupplier;
205 			const SubTitles*	fSubTitles;
206 			int32				fSubTitlesIndex;
207 
208 	mutable	int64				fCurrentFrame;
209 			bigtime_t			fDuration;
210 			float				fVideoFrameRate;
211 
212 	mutable	int32				fPendingSeekRequests;
213 	mutable int64				fSeekFrame;
214 	mutable int64				fRequestedSeekFrame;
215 
216 			ListenerAdapter		fGlobalSettingsListener;
217 
218 			bool				fAutoplaySetting;
219 				// maintains the auto-play setting
220 			bool 				fAutoplay;
221 				// is true if the player is already playing
222 				// otherwise it's the same as fAutoplaySetting
223 			bool				fLoopMovies;
224 			bool				fLoopSounds;
225 			uint32				fBackgroundMovieVolumeMode;
226 
227 			BList				fListeners;
228 };
229 
230 
231 #endif	// __CONTROLLER_H
232