xref: /haiku/src/apps/mediaplayer/Controller.h (revision 2f470aec1c92ce6917b8a903e343795dc77af41f)
1 /*
2  * Controller.h - Media Player for the Haiku Operating System
3  *
4  * Copyright (C) 2006 Marcus Overhagen <marcus@overhagen.de>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * version 2 as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18  *
19  */
20 #ifndef __CONTROLLER_H
21 #define __CONTROLLER_H
22 
23 #include <MediaDefs.h>
24 #include <MediaNode.h>
25 #include <Locker.h>
26 #include <String.h>
27 
28 class BBitmap;
29 class BMediaFile;
30 class BMediaTrack;
31 class SoundOutput;
32 class VideoView;
33 class ControllerView;
34 
35 class Controller
36 {
37 public:
38 							Controller();
39 	virtual 				~Controller();
40 
41 	status_t				SetTo(const entry_ref &ref);
42 	void					GetSize(int *width, int *height);
43 
44 	int						AudioTrackCount();
45 	int						VideoTrackCount();
46 
47 	status_t				SelectAudioTrack(int n);
48 	status_t				SelectVideoTrack(int n);
49 
50 	bigtime_t				Duration();
51 	bigtime_t				Position();
52 
53 	status_t				Seek(bigtime_t pos);
54 
55 	void					Stop();
56 	void					Play();
57 	void					Pause();
58 	bool					IsPaused();
59 	bool					IsStopped();
60 
61 	void					SetVideoView(VideoView *view);
62 	void					SetControllerView(ControllerView *view);
63 
64 	bool					IsOverlayActive();
65 
66 	void					LockBitmap();
67 	void					UnlockBitmap();
68 	BBitmap *				Bitmap();
69 
70 	void					VolumeUp();
71 	void					VolumeDown();
72 
73 	void					SetVolume(float value);
74 
75 	void					SetPosition(float value);
76 
77 	void					UpdateVolume(float value);
78 	void					UpdatePosition(float value);
79 
80 private:
81 	static int32			audio_decode_thread(void *self);
82 	static int32			video_decode_thread(void *self);
83 	static int32			audio_play_thread(void *self);
84 	static int32			video_play_thread(void *self);
85 
86 	void					AudioDecodeThread();
87 	void					VideoDecodeThread();
88 	void					AudioPlayThread();
89 	void					VideoPlayThread();
90 
91 	void					StartThreads();
92 	void					StopThreads();
93 
94 private:
95 	friend class InfoWin;
96 
97 	enum {
98 		MAX_AUDIO_BUFFERS = 8,
99 		MAX_VIDEO_BUFFERS = 3,
100 	};
101 
102 	struct buffer_info {
103 		char *	 		buffer;
104 		BBitmap *		bitmap;
105 		size_t			sizeUsed;
106 		size_t			sizeMax;
107 		bigtime_t		startTime;
108 		bool			formatChanged;
109 		media_format	mediaFormat;
110 	};
111 
112 	VideoView *				fVideoView;
113 	ControllerView *		fControllerView;
114 	BString					fName;
115 	volatile bool			fPaused;
116 	volatile bool			fStopped;
117 	BMediaFile *			fMediaFile;
118 	BMediaTrack *			fAudioTrack;
119 	BMediaTrack *			fVideoTrack;
120 
121 	BLocker					fAudioTrackLock;
122 	BLocker					fVideoTrackLock;
123 
124 	BList *					fAudioTrackList;
125 	BList *					fVideoTrackList;
126 	bigtime_t				fPosition;
127 	media_format			fAudioFormat;
128 	media_format			fVideoFormat;
129 
130 	sem_id					fAudioDecodeSem;
131 	sem_id					fVideoDecodeSem;
132 	sem_id					fAudioPlaySem;
133 	sem_id					fVideoPlaySem;
134 	sem_id					fThreadWaitSem;
135 	thread_id				fAudioDecodeThread;
136 	thread_id				fVideoDecodeThread;
137 	thread_id				fAudioPlayThread;
138 	thread_id				fVideoPlayThread;
139 
140 	SoundOutput	*			fSoundOutput;
141 	volatile bool			fSeekAudio;
142 	volatile bool			fSeekVideo;
143 	volatile bigtime_t		fSeekPosition;
144 	bigtime_t				fDuration;
145 
146 	int32					fAudioBufferCount;
147 	int32					fAudioBufferReadIndex;
148 	int32					fAudioBufferWriteIndex;
149 	int32					fVideoBufferCount;
150 	int32					fVideoBufferReadIndex;
151 	int32					fVideoBufferWriteIndex;
152 
153 	buffer_info				fAudioBuffer[MAX_AUDIO_BUFFERS];
154 	buffer_info				fVideoBuffer[MAX_VIDEO_BUFFERS];
155 
156 	BLocker					fTimeSourceLock;
157 	bigtime_t				fTimeSourceSysTime;
158 	bigtime_t				fTimeSourcePerfTime;
159 	bool 					fAutoplay;
160 
161 	BBitmap *				fCurrentBitmap;
162 
163 };
164 
165 
166 #endif
167 
168