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