-rw-r--r-- | noncore/multimedia/opieplayer2/lib.cpp | 15 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/lib.h | 8 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/threadutil.cpp | 284 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/threadutil.h | 176 |
4 files changed, 481 insertions, 2 deletions
diff --git a/noncore/multimedia/opieplayer2/lib.cpp b/noncore/multimedia/opieplayer2/lib.cpp index 19b64e8..1ac9809 100644 --- a/noncore/multimedia/opieplayer2/lib.cpp +++ b/noncore/multimedia/opieplayer2/lib.cpp | |||
@@ -1,279 +1,292 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | 3 | ||
4 | Copyright (c) 2002 Max Reiss <harlekin@handhelds.org> | 4 | Copyright (c) 2002 Max Reiss <harlekin@handhelds.org> |
5 | Copyright (c) 2002 LJP <> | 5 | Copyright (c) 2002 LJP <> |
6 | Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> | 6 | Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> |
7 | =. | 7 | =. |
8 | .=l. | 8 | .=l. |
9 | .>+-= | 9 | .>+-= |
10 | _;:, .> :=|. This program is free software; you can | 10 | _;:, .> :=|. This program is free software; you can |
11 | .> <`_, > . <= redistribute it and/or modify it under | 11 | .> <`_, > . <= redistribute it and/or modify it under |
12 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | 12 | :`=1 )Y*s>-.-- : the terms of the GNU General Public |
13 | .="- .-=="i, .._ License as published by the Free Software | 13 | .="- .-=="i, .._ License as published by the Free Software |
14 | - . .-<_> .<> Foundation; either version 2 of the License, | 14 | - . .-<_> .<> Foundation; either version 2 of the License, |
15 | ._= =} : or (at your option) any later version. | 15 | ._= =} : or (at your option) any later version. |
16 | .%`+i> _;_. | 16 | .%`+i> _;_. |
17 | .i_,=:_. -<s. This program is distributed in the hope that | 17 | .i_,=:_. -<s. This program is distributed in the hope that |
18 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 18 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
19 | : .. .:, . . . without even the implied warranty of | 19 | : .. .:, . . . without even the implied warranty of |
20 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 20 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
21 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 21 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
22 | ..}^=.= = ; Library General Public License for more | 22 | ..}^=.= = ; Library General Public License for more |
23 | ++= -. .` .: details. | 23 | ++= -. .` .: details. |
24 | : = ...= . :.=- | 24 | : = ...= . :.=- |
25 | -. .:....=;==+<; You should have received a copy of the GNU | 25 | -. .:....=;==+<; You should have received a copy of the GNU |
26 | -_. . . )=. = Library General Public License along with | 26 | -_. . . )=. = Library General Public License along with |
27 | -- :-=` this library; see the file COPYING.LIB. | 27 | -- :-=` this library; see the file COPYING.LIB. |
28 | If not, write to the Free Software Foundation, | 28 | If not, write to the Free Software Foundation, |
29 | Inc., 59 Temple Place - Suite 330, | 29 | Inc., 59 Temple Place - Suite 330, |
30 | Boston, MA 02111-1307, USA. | 30 | Boston, MA 02111-1307, USA. |
31 | 31 | ||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #include <stdio.h> | 34 | #include <stdio.h> |
35 | #include <stdlib.h> | 35 | #include <stdlib.h> |
36 | #include <qimage.h> | 36 | #include <qimage.h> |
37 | #include <qtextstream.h> | 37 | #include <qtextstream.h> |
38 | #include <qpe/resource.h> | 38 | #include <qpe/resource.h> |
39 | 39 | ||
40 | #include <qfile.h> | 40 | #include <qfile.h> |
41 | 41 | ||
42 | #include <qgfx_qws.h> | 42 | #include <qgfx_qws.h> |
43 | #include <qdirectpainter_qws.h> | 43 | #include <qdirectpainter_qws.h> |
44 | 44 | ||
45 | #include <assert.h> | ||
46 | |||
45 | #include "xinevideowidget.h" | 47 | #include "xinevideowidget.h" |
46 | #include "frame.h" | 48 | #include "frame.h" |
47 | #include "lib.h" | 49 | #include "lib.h" |
48 | 50 | ||
49 | typedef void (*display_xine_frame_t) (void *user_data, uint8_t* frame, | 51 | typedef void (*display_xine_frame_t) (void *user_data, uint8_t* frame, |
50 | int width, int height,int bytes ); | 52 | int width, int height,int bytes ); |
51 | 53 | ||
52 | extern "C" { | 54 | extern "C" { |
53 | xine_vo_driver_t* init_video_out_plugin( xine_cfg_entry_t* conf, void* video); | 55 | xine_vo_driver_t* init_video_out_plugin( xine_cfg_entry_t* conf, void* video); |
54 | int null_is_showing_video( const xine_vo_driver_t* self ); | 56 | int null_is_showing_video( const xine_vo_driver_t* self ); |
55 | void null_set_show_video( const xine_vo_driver_t* self, int show ); | 57 | void null_set_show_video( const xine_vo_driver_t* self, int show ); |
56 | int null_is_fullscreen( const xine_vo_driver_t* self ); | 58 | int null_is_fullscreen( const xine_vo_driver_t* self ); |
57 | void null_set_fullscreen( const xine_vo_driver_t* self, int screen ); | 59 | void null_set_fullscreen( const xine_vo_driver_t* self, int screen ); |
58 | int null_is_scaling( const xine_vo_driver_t* self ); | 60 | int null_is_scaling( const xine_vo_driver_t* self ); |
59 | void null_set_scaling( const xine_vo_driver_t* self, int scale ); | 61 | void null_set_scaling( const xine_vo_driver_t* self, int scale ); |
60 | void null_set_gui_width( const xine_vo_driver_t* self, int width ); | 62 | void null_set_gui_width( const xine_vo_driver_t* self, int width ); |
61 | void null_set_gui_height( const xine_vo_driver_t* self, int height ); | 63 | void null_set_gui_height( const xine_vo_driver_t* self, int height ); |
62 | void null_set_mode( const xine_vo_driver_t* self, int depth, int rgb ); | 64 | void null_set_mode( const xine_vo_driver_t* self, int depth, int rgb ); |
63 | void null_set_videoGamma( const xine_vo_driver_t* self , int value ); | 65 | void null_set_videoGamma( const xine_vo_driver_t* self , int value ); |
64 | void null_display_handler( const xine_vo_driver_t* self, display_xine_frame_t t, void* user_data ); | 66 | void null_display_handler( const xine_vo_driver_t* self, display_xine_frame_t t, void* user_data ); |
65 | } | 67 | } |
66 | 68 | ||
67 | using namespace XINE; | 69 | using namespace XINE; |
68 | 70 | ||
69 | Lib::Lib( XineVideoWidget* widget ) { | 71 | Lib::Lib( XineVideoWidget* widget ) { |
70 | m_video = false; | 72 | m_video = false; |
71 | m_wid = widget; | 73 | m_wid = widget; |
72 | printf("Lib"); | 74 | printf("Lib"); |
73 | QCString str( getenv("HOME") ); | 75 | QCString str( getenv("HOME") ); |
74 | str += "/Settings/opiexine.cf"; | 76 | str += "/Settings/opiexine.cf"; |
75 | // get the configuration | 77 | // get the configuration |
76 | 78 | ||
77 | // not really OO, should be an extra class, later | 79 | // not really OO, should be an extra class, later |
78 | if ( !QFile(str).exists() ) { | 80 | if ( !QFile(str).exists() ) { |
79 | QFile f(str); | 81 | QFile f(str); |
80 | f.open(IO_WriteOnly); | 82 | f.open(IO_WriteOnly); |
81 | QTextStream ts( &f ); | 83 | QTextStream ts( &f ); |
82 | ts << "misc.memcpy_method:glibc\n"; | 84 | ts << "misc.memcpy_method:glibc\n"; |
83 | f.close(); | 85 | f.close(); |
84 | } | 86 | } |
85 | 87 | ||
86 | m_xine = xine_new( ); | 88 | m_xine = xine_new( ); |
87 | 89 | ||
88 | xine_config_load( m_xine, str.data() ); | 90 | xine_config_load( m_xine, str.data() ); |
89 | 91 | ||
90 | xine_init( m_xine ); | 92 | xine_init( m_xine ); |
91 | 93 | ||
92 | // allocate oss for sound | 94 | // allocate oss for sound |
93 | // and fb for framebuffer | 95 | // and fb for framebuffer |
94 | m_audioOutput = xine_open_audio_driver( m_xine, "oss", NULL ); | 96 | m_audioOutput = xine_open_audio_driver( m_xine, "oss", NULL ); |
95 | m_videoOutput = ::init_video_out_plugin( m_config, NULL ); | 97 | m_videoOutput = ::init_video_out_plugin( m_config, NULL ); |
96 | 98 | ||
97 | 99 | ||
98 | //xine_open_video_driver( m_xine, NULL, XINE_VISUAL_TYPE_FB, NULL); | 100 | //xine_open_video_driver( m_xine, NULL, XINE_VISUAL_TYPE_FB, NULL); |
99 | 101 | ||
100 | 102 | ||
101 | null_display_handler( m_videoOutput, xine_display_frame, this ); | 103 | null_display_handler( m_videoOutput, xine_display_frame, this ); |
102 | 104 | ||
103 | m_stream = xine_stream_new (m_xine, m_audioOutput, m_videoOutput ); | 105 | m_stream = xine_stream_new (m_xine, m_audioOutput, m_videoOutput ); |
104 | 106 | ||
105 | if (m_wid != 0 ) { | 107 | if (m_wid != 0 ) { |
106 | printf( "!0\n" ); | 108 | printf( "!0\n" ); |
107 | resize ( m_wid-> size ( ) ); | 109 | resize ( m_wid-> size ( ) ); |
108 | ::null_set_mode( m_videoOutput, qt_screen->depth(), qt_screen->pixelType() ); | 110 | ::null_set_mode( m_videoOutput, qt_screen->depth(), qt_screen->pixelType() ); |
109 | 111 | ||
110 | m_wid->repaint(); | 112 | m_wid->repaint(); |
111 | } | 113 | } |
112 | 114 | ||
113 | m_queue = xine_event_new_queue (m_stream); | 115 | m_queue = xine_event_new_queue (m_stream); |
114 | 116 | ||
115 | xine_event_create_listener_thread (m_queue, xine_event_handler, this); | 117 | xine_event_create_listener_thread (m_queue, xine_event_handler, this); |
116 | } | 118 | } |
117 | 119 | ||
118 | Lib::~Lib() { | 120 | Lib::~Lib() { |
119 | // free( m_config ); | 121 | // free( m_config ); |
120 | xine_exit( m_xine ); | 122 | xine_exit( m_xine ); |
121 | /* FIXME either free or delete but valgrind bitches against both */ | 123 | /* FIXME either free or delete but valgrind bitches against both */ |
122 | //free( m_videoOutput ); | 124 | //free( m_videoOutput ); |
123 | //delete m_audioOutput; | 125 | //delete m_audioOutput; |
124 | } | 126 | } |
125 | 127 | ||
126 | void Lib::resize ( const QSize &s ) { | 128 | void Lib::resize ( const QSize &s ) { |
127 | if ( s. width ( ) && s. height ( ) ) { | 129 | if ( s. width ( ) && s. height ( ) ) { |
128 | ::null_set_gui_width( m_videoOutput, s. width() ); | 130 | ::null_set_gui_width( m_videoOutput, s. width() ); |
129 | ::null_set_gui_height( m_videoOutput, s. height() ); | 131 | ::null_set_gui_height( m_videoOutput, s. height() ); |
130 | } | 132 | } |
131 | } | 133 | } |
132 | 134 | ||
133 | QCString Lib::version() { | 135 | QCString Lib::version() { |
134 | // QCString str( xine_get_str_version() ); | 136 | // QCString str( xine_get_str_version() ); |
135 | // return str; | 137 | // return str; |
136 | return "test"; | 138 | return "test"; |
137 | } | 139 | } |
138 | 140 | ||
139 | int Lib::majorVersion() { | 141 | int Lib::majorVersion() { |
140 | xine_get_version ( &m_major_version, &m_minor_version, &m_sub_version ); | 142 | xine_get_version ( &m_major_version, &m_minor_version, &m_sub_version ); |
141 | return m_major_version; | 143 | return m_major_version; |
142 | } | 144 | } |
143 | 145 | ||
144 | int Lib::minorVersion() { | 146 | int Lib::minorVersion() { |
145 | xine_get_version ( &m_major_version, &m_minor_version, &m_sub_version ); | 147 | xine_get_version ( &m_major_version, &m_minor_version, &m_sub_version ); |
146 | return m_minor_version; | 148 | return m_minor_version; |
147 | } | 149 | } |
148 | 150 | ||
149 | int Lib::subVersion() { | 151 | int Lib::subVersion() { |
150 | xine_get_version ( &m_major_version, &m_minor_version, &m_sub_version ); | 152 | xine_get_version ( &m_major_version, &m_minor_version, &m_sub_version ); |
151 | return m_sub_version; | 153 | return m_sub_version; |
152 | } | 154 | } |
153 | 155 | ||
154 | int Lib::play( const QString& fileName, int startPos, int start_time ) { | 156 | int Lib::play( const QString& fileName, int startPos, int start_time ) { |
155 | QString str = fileName.stripWhiteSpace(); | 157 | QString str = fileName.stripWhiteSpace(); |
156 | if ( !xine_open( m_stream, QFile::encodeName(str.utf8() ).data() ) ) { | 158 | if ( !xine_open( m_stream, QFile::encodeName(str.utf8() ).data() ) ) { |
157 | return 0; | 159 | return 0; |
158 | } | 160 | } |
159 | return xine_play( m_stream, startPos, start_time); | 161 | return xine_play( m_stream, startPos, start_time); |
160 | } | 162 | } |
161 | 163 | ||
162 | void Lib::stop() { | 164 | void Lib::stop() { |
163 | qDebug("<<<<<<<< STOP IN LIB TRIGGERED >>>>>>>"); | 165 | qDebug("<<<<<<<< STOP IN LIB TRIGGERED >>>>>>>"); |
164 | xine_stop( m_stream ); | 166 | xine_stop( m_stream ); |
165 | } | 167 | } |
166 | 168 | ||
167 | void Lib::pause() { | 169 | void Lib::pause() { |
168 | xine_set_param( m_stream, XINE_PARAM_SPEED, XINE_SPEED_PAUSE ); | 170 | xine_set_param( m_stream, XINE_PARAM_SPEED, XINE_SPEED_PAUSE ); |
169 | } | 171 | } |
170 | 172 | ||
171 | int Lib::speed() { | 173 | int Lib::speed() { |
172 | return xine_get_param ( m_stream, XINE_PARAM_SPEED ); | 174 | return xine_get_param ( m_stream, XINE_PARAM_SPEED ); |
173 | } | 175 | } |
174 | 176 | ||
175 | void Lib::setSpeed( int speed ) { | 177 | void Lib::setSpeed( int speed ) { |
176 | xine_set_param ( m_stream, XINE_PARAM_SPEED, speed ); | 178 | xine_set_param ( m_stream, XINE_PARAM_SPEED, speed ); |
177 | } | 179 | } |
178 | 180 | ||
179 | int Lib::status() { | 181 | int Lib::status() { |
180 | return xine_get_status( m_stream ); | 182 | return xine_get_status( m_stream ); |
181 | } | 183 | } |
182 | 184 | ||
183 | int Lib::currentPosition() { | 185 | int Lib::currentPosition() { |
184 | xine_get_pos_length( m_stream, &m_pos, &m_time, &m_length ); | 186 | xine_get_pos_length( m_stream, &m_pos, &m_time, &m_length ); |
185 | return m_pos; | 187 | return m_pos; |
186 | } | 188 | } |
187 | 189 | ||
188 | int Lib::currentTime() { | 190 | int Lib::currentTime() { |
189 | xine_get_pos_length( m_stream, &m_pos, &m_time, &m_length ); | 191 | xine_get_pos_length( m_stream, &m_pos, &m_time, &m_length ); |
190 | return m_time/1000; | 192 | return m_time/1000; |
191 | } | 193 | } |
192 | 194 | ||
193 | int Lib::length() { | 195 | int Lib::length() { |
194 | xine_get_pos_length( m_stream, &m_pos, &m_time, &m_length ); | 196 | xine_get_pos_length( m_stream, &m_pos, &m_time, &m_length ); |
195 | return m_length/1000; | 197 | return m_length/1000; |
196 | } | 198 | } |
197 | 199 | ||
198 | bool Lib::isSeekable() { | 200 | bool Lib::isSeekable() { |
199 | return xine_get_stream_info( m_stream, XINE_STREAM_INFO_SEEKABLE ); | 201 | return xine_get_stream_info( m_stream, XINE_STREAM_INFO_SEEKABLE ); |
200 | } | 202 | } |
201 | 203 | ||
202 | void Lib::seekTo( int time ) { | 204 | void Lib::seekTo( int time ) { |
203 | //xine_trick_mode ( m_stream, XINE_TRICK_MODE_SEEK_TO_TIME, time ); NOT IMPLEMENTED YET IN XINE :_( | 205 | //xine_trick_mode ( m_stream, XINE_TRICK_MODE_SEEK_TO_TIME, time ); NOT IMPLEMENTED YET IN XINE :_( |
204 | // since its now milliseconds we need *1000 | 206 | // since its now milliseconds we need *1000 |
205 | xine_play( m_stream, 0, time*1000 ); | 207 | xine_play( m_stream, 0, time*1000 ); |
206 | } | 208 | } |
207 | 209 | ||
208 | 210 | ||
209 | Frame Lib::currentFrame() { | 211 | Frame Lib::currentFrame() { |
210 | Frame frame; | 212 | Frame frame; |
211 | return frame; | 213 | return frame; |
212 | }; | 214 | }; |
213 | 215 | ||
214 | QString Lib::metaInfo( int number) { | 216 | QString Lib::metaInfo( int number) { |
215 | return xine_get_meta_info( m_stream, number ); | 217 | return xine_get_meta_info( m_stream, number ); |
216 | } | 218 | } |
217 | 219 | ||
218 | int Lib::error() { | 220 | int Lib::error() { |
219 | return xine_get_error( m_stream ); | 221 | return xine_get_error( m_stream ); |
220 | }; | 222 | }; |
221 | 223 | ||
224 | void Lib::receiveMessage( ThreadUtil::ChannelMessage *msg, SendType sendType ) | ||
225 | { | ||
226 | assert( sendType == ThreadUtil::Channel::OneWay ); | ||
227 | handleXineEvent( msg->type() ); | ||
228 | delete msg; | ||
229 | } | ||
230 | |||
222 | void Lib::handleXineEvent( const xine_event_t* t ) { | 231 | void Lib::handleXineEvent( const xine_event_t* t ) { |
223 | if ( t->type == XINE_EVENT_UI_PLAYBACK_FINISHED ) { | 232 | send( new ThreadUtil::ChannelMessage( t->type ), OneWay ); |
233 | } | ||
234 | |||
235 | void Lib::handleXineEvent( int type ) { | ||
236 | if ( type == XINE_EVENT_UI_PLAYBACK_FINISHED ) { | ||
224 | emit stopped(); | 237 | emit stopped(); |
225 | } | 238 | } |
226 | } | 239 | } |
227 | 240 | ||
228 | 241 | ||
229 | void Lib::setShowVideo( bool video ) { | 242 | void Lib::setShowVideo( bool video ) { |
230 | m_video = video; | 243 | m_video = video; |
231 | ::null_set_show_video( m_videoOutput, video ); | 244 | ::null_set_show_video( m_videoOutput, video ); |
232 | } | 245 | } |
233 | 246 | ||
234 | bool Lib::isShowingVideo() { | 247 | bool Lib::isShowingVideo() { |
235 | return ::null_is_showing_video( m_videoOutput ); | 248 | return ::null_is_showing_video( m_videoOutput ); |
236 | } | 249 | } |
237 | 250 | ||
238 | bool Lib::hasVideo() { | 251 | bool Lib::hasVideo() { |
239 | return xine_get_stream_info( m_stream, 18 ); | 252 | return xine_get_stream_info( m_stream, 18 ); |
240 | } | 253 | } |
241 | 254 | ||
242 | void Lib::showVideoFullScreen( bool fullScreen ) { | 255 | void Lib::showVideoFullScreen( bool fullScreen ) { |
243 | ::null_set_fullscreen( m_videoOutput, fullScreen ); | 256 | ::null_set_fullscreen( m_videoOutput, fullScreen ); |
244 | } | 257 | } |
245 | 258 | ||
246 | bool Lib::isVideoFullScreen() { | 259 | bool Lib::isVideoFullScreen() { |
247 | return ::null_is_fullscreen( m_videoOutput ); | 260 | return ::null_is_fullscreen( m_videoOutput ); |
248 | } | 261 | } |
249 | 262 | ||
250 | void Lib::setScaling( bool scale ) { | 263 | void Lib::setScaling( bool scale ) { |
251 | ::null_set_scaling( m_videoOutput, scale ); | 264 | ::null_set_scaling( m_videoOutput, scale ); |
252 | } | 265 | } |
253 | 266 | ||
254 | void Lib::setGamma( int value ) { | 267 | void Lib::setGamma( int value ) { |
255 | //qDebug( QString( "%1").arg(value) ); | 268 | //qDebug( QString( "%1").arg(value) ); |
256 | /* int gammaValue = ( 100 + value ); */ | 269 | /* int gammaValue = ( 100 + value ); */ |
257 | ::null_set_videoGamma( m_videoOutput, value ); | 270 | ::null_set_videoGamma( m_videoOutput, value ); |
258 | } | 271 | } |
259 | 272 | ||
260 | bool Lib::isScaling() { | 273 | bool Lib::isScaling() { |
261 | return ::null_is_scaling( m_videoOutput ); | 274 | return ::null_is_scaling( m_videoOutput ); |
262 | } | 275 | } |
263 | 276 | ||
264 | void Lib::xine_event_handler( void* user_data, const xine_event_t* t ) { | 277 | void Lib::xine_event_handler( void* user_data, const xine_event_t* t ) { |
265 | ( (Lib*)user_data)->handleXineEvent( t ); | 278 | ( (Lib*)user_data)->handleXineEvent( t ); |
266 | } | 279 | } |
267 | 280 | ||
268 | void Lib::xine_display_frame( void* user_data, uint8_t *frame, | 281 | void Lib::xine_display_frame( void* user_data, uint8_t *frame, |
269 | int width, int height, int bytes ) { | 282 | int width, int height, int bytes ) { |
270 | ( (Lib*)user_data)->drawFrame( frame, width, height, bytes ); | 283 | ( (Lib*)user_data)->drawFrame( frame, width, height, bytes ); |
271 | } | 284 | } |
272 | 285 | ||
273 | void Lib::drawFrame( uint8_t* frame, int width, int height, int bytes ) { | 286 | void Lib::drawFrame( uint8_t* frame, int width, int height, int bytes ) { |
274 | if ( !m_video ) { | 287 | if ( !m_video ) { |
275 | qWarning("not showing video now"); | 288 | qWarning("not showing video now"); |
276 | return; | 289 | return; |
277 | } | 290 | } |
278 | m_wid-> setVideoFrame ( frame, width, height, bytes ); | 291 | m_wid-> setVideoFrame ( frame, width, height, bytes ); |
279 | } | 292 | } |
diff --git a/noncore/multimedia/opieplayer2/lib.h b/noncore/multimedia/opieplayer2/lib.h index 38938a1..75b9f12 100644 --- a/noncore/multimedia/opieplayer2/lib.h +++ b/noncore/multimedia/opieplayer2/lib.h | |||
@@ -1,202 +1,208 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | 3 | ||
4 | Copyright (c) 2002 Max Reiss <harlekin@handhelds.org> | 4 | Copyright (c) 2002 Max Reiss <harlekin@handhelds.org> |
5 | Copyright (c) 2002 LJP <> | 5 | Copyright (c) 2002 LJP <> |
6 | Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> | 6 | Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> |
7 | =. | 7 | =. |
8 | .=l. | 8 | .=l. |
9 | .>+-= | 9 | .>+-= |
10 | _;:, .> :=|. This program is free software; you can | 10 | _;:, .> :=|. This program is free software; you can |
11 | .> <`_, > . <= redistribute it and/or modify it under | 11 | .> <`_, > . <= redistribute it and/or modify it under |
12 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | 12 | :`=1 )Y*s>-.-- : the terms of the GNU General Public |
13 | .="- .-=="i, .._ License as published by the Free Software | 13 | .="- .-=="i, .._ License as published by the Free Software |
14 | - . .-<_> .<> Foundation; either version 2 of the License, | 14 | - . .-<_> .<> Foundation; either version 2 of the License, |
15 | ._= =} : or (at your option) any later version. | 15 | ._= =} : or (at your option) any later version. |
16 | .%`+i> _;_. | 16 | .%`+i> _;_. |
17 | .i_,=:_. -<s. This program is distributed in the hope that | 17 | .i_,=:_. -<s. This program is distributed in the hope that |
18 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 18 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
19 | : .. .:, . . . without even the implied warranty of | 19 | : .. .:, . . . without even the implied warranty of |
20 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 20 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
21 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 21 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
22 | ..}^=.= = ; Library General Public License for more | 22 | ..}^=.= = ; Library General Public License for more |
23 | ++= -. .` .: details. | 23 | ++= -. .` .: details. |
24 | : = ...= . :.=- | 24 | : = ...= . :.=- |
25 | -. .:....=;==+<; You should have received a copy of the GNU | 25 | -. .:....=;==+<; You should have received a copy of the GNU |
26 | -_. . . )=. = Library General Public License along with | 26 | -_. . . )=. = Library General Public License along with |
27 | -- :-=` this library; see the file COPYING.LIB. | 27 | -- :-=` this library; see the file COPYING.LIB. |
28 | If not, write to the Free Software Foundation, | 28 | If not, write to the Free Software Foundation, |
29 | Inc., 59 Temple Place - Suite 330, | 29 | Inc., 59 Temple Place - Suite 330, |
30 | Boston, MA 02111-1307, USA. | 30 | Boston, MA 02111-1307, USA. |
31 | 31 | ||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #ifndef ZECKEXINELIB_H | 34 | #ifndef ZECKEXINELIB_H |
35 | #define ZECKEXINELIB_H | 35 | #define ZECKEXINELIB_H |
36 | 36 | ||
37 | #include <qcstring.h> | 37 | #include <qcstring.h> |
38 | #include <qstring.h> | 38 | #include <qstring.h> |
39 | #include <qobject.h> | 39 | #include <qobject.h> |
40 | 40 | ||
41 | #include <xine.h> | 41 | #include <xine.h> |
42 | //#include "xine.h" | 42 | //#include "xine.h" |
43 | 43 | ||
44 | #include "threadutil.h" | ||
45 | |||
44 | class XineVideoWidget; | 46 | class XineVideoWidget; |
45 | 47 | ||
46 | namespace XINE { | 48 | namespace XINE { |
47 | 49 | ||
48 | /** | 50 | /** |
49 | * Lib wrapps the simple interface | 51 | * Lib wrapps the simple interface |
50 | * of libxine for easy every day use | 52 | * of libxine for easy every day use |
51 | * This will become a full C++ Wrapper | 53 | * This will become a full C++ Wrapper |
52 | * It supports playing, pausing, info, | 54 | * It supports playing, pausing, info, |
53 | * stooping, seeking. | 55 | * stooping, seeking. |
54 | */ | 56 | */ |
55 | class Frame; | 57 | class Frame; |
56 | class Lib : public QObject { | 58 | class Lib : public ThreadUtil::Channel { |
57 | Q_OBJECT | 59 | Q_OBJECT |
58 | public: | 60 | public: |
59 | Lib(XineVideoWidget* = 0); | 61 | Lib(XineVideoWidget* = 0); |
60 | ~Lib(); | 62 | ~Lib(); |
61 | QCString version(); | 63 | QCString version(); |
62 | int majorVersion()/*const*/; | 64 | int majorVersion()/*const*/; |
63 | int minorVersion()/*const*/; | 65 | int minorVersion()/*const*/; |
64 | int subVersion()/*const*/; | 66 | int subVersion()/*const*/; |
65 | 67 | ||
66 | 68 | ||
67 | void resize ( const QSize &s ); | 69 | void resize ( const QSize &s ); |
68 | 70 | ||
69 | int play( const QString& fileName, | 71 | int play( const QString& fileName, |
70 | int startPos = 0, | 72 | int startPos = 0, |
71 | int start_time = 0 ); | 73 | int start_time = 0 ); |
72 | void stop() /*const*/; | 74 | void stop() /*const*/; |
73 | void pause()/*const*/; | 75 | void pause()/*const*/; |
74 | 76 | ||
75 | int speed() /*const*/; | 77 | int speed() /*const*/; |
76 | 78 | ||
77 | /** | 79 | /** |
78 | * Set the speed of the stream, if codec supports it | 80 | * Set the speed of the stream, if codec supports it |
79 | * XINE_SPEED_PAUSE 0 | 81 | * XINE_SPEED_PAUSE 0 |
80 | * XINE_SPEED_SLOW_4 1 | 82 | * XINE_SPEED_SLOW_4 1 |
81 | * XINE_SPEED_SLOW_2 2 | 83 | * XINE_SPEED_SLOW_2 2 |
82 | * XINE_SPEED_NORMAL 4 | 84 | * XINE_SPEED_NORMAL 4 |
83 | * XINE_SPEED_FAST_2 8 | 85 | * XINE_SPEED_FAST_2 8 |
84 | *XINE_SPEED_FAST_4 16 | 86 | *XINE_SPEED_FAST_4 16 |
85 | */ | 87 | */ |
86 | void setSpeed( int speed = XINE_SPEED_PAUSE ); | 88 | void setSpeed( int speed = XINE_SPEED_PAUSE ); |
87 | 89 | ||
88 | int status() /*const*/; | 90 | int status() /*const*/; |
89 | 91 | ||
90 | int currentPosition()/*const*/; | 92 | int currentPosition()/*const*/; |
91 | //in seconds | 93 | //in seconds |
92 | int currentTime()/*const*/; | 94 | int currentTime()/*const*/; |
93 | 95 | ||
94 | int length() /*const*/; | 96 | int length() /*const*/; |
95 | 97 | ||
96 | bool isSeekable()/*const*/; | 98 | bool isSeekable()/*const*/; |
97 | 99 | ||
98 | /** | 100 | /** |
99 | * Whether or not to show video output | 101 | * Whether or not to show video output |
100 | */ | 102 | */ |
101 | void setShowVideo(bool video); | 103 | void setShowVideo(bool video); |
102 | 104 | ||
103 | /** | 105 | /** |
104 | * is we show video | 106 | * is we show video |
105 | */ | 107 | */ |
106 | bool isShowingVideo() /*const*/; | 108 | bool isShowingVideo() /*const*/; |
107 | 109 | ||
108 | /** | 110 | /** |
109 | * | 111 | * |
110 | */ | 112 | */ |
111 | void showVideoFullScreen( bool fullScreen ); | 113 | void showVideoFullScreen( bool fullScreen ); |
112 | 114 | ||
113 | /** | 115 | /** |
114 | * | 116 | * |
115 | */ | 117 | */ |
116 | bool isVideoFullScreen()/*const*/ ; | 118 | bool isVideoFullScreen()/*const*/ ; |
117 | 119 | ||
118 | 120 | ||
119 | /** | 121 | /** |
120 | * Get the meta info (like author etc) from the stream | 122 | * Get the meta info (like author etc) from the stream |
121 | * XINE_META_INFO_TITLE 0 | 123 | * XINE_META_INFO_TITLE 0 |
122 | * XINE_META_INFO_COMMENT 1 | 124 | * XINE_META_INFO_COMMENT 1 |
123 | * XINE_META_INFO_ARTIST 2 | 125 | * XINE_META_INFO_ARTIST 2 |
124 | * XINE_META_INFO_GENRE 3 | 126 | * XINE_META_INFO_GENRE 3 |
125 | * XINE_META_INFO_ALBUM 4 | 127 | * XINE_META_INFO_ALBUM 4 |
126 | * XINE_META_INFO_YEAR 5 | 128 | * XINE_META_INFO_YEAR 5 |
127 | * XINE_META_INFO_VIDEOCODEC 6 | 129 | * XINE_META_INFO_VIDEOCODEC 6 |
128 | * XINE_META_INFO_AUDIOCODEC 7 | 130 | * XINE_META_INFO_AUDIOCODEC 7 |
129 | * XINE_META_INFO_SYSTEMLAYER 8 | 131 | * XINE_META_INFO_SYSTEMLAYER 8 |
130 | * XINE_META_INFO_INPUT_PLUGIN 9 | 132 | * XINE_META_INFO_INPUT_PLUGIN 9 |
131 | */ | 133 | */ |
132 | QString metaInfo( int number ); | 134 | QString metaInfo( int number ); |
133 | 135 | ||
134 | /** | 136 | /** |
135 | * | 137 | * |
136 | */ | 138 | */ |
137 | bool isScaling(); | 139 | bool isScaling(); |
138 | 140 | ||
139 | /** | 141 | /** |
140 | * seek to a position | 142 | * seek to a position |
141 | */ | 143 | */ |
142 | void seekTo( int time ); | 144 | void seekTo( int time ); |
143 | 145 | ||
144 | /** | 146 | /** |
145 | * | 147 | * |
146 | * @return is media stream has video | 148 | * @return is media stream has video |
147 | */ | 149 | */ |
148 | bool hasVideo(); | 150 | bool hasVideo(); |
149 | 151 | ||
150 | /** | 152 | /** |
151 | * | 153 | * |
152 | */ | 154 | */ |
153 | void setScaling( bool ); | 155 | void setScaling( bool ); |
154 | 156 | ||
155 | /** | 157 | /** |
156 | * Set the Gamma value for video output | 158 | * Set the Gamma value for video output |
157 | * @param int the value between -100 and 100, 0 is original | 159 | * @param int the value between -100 and 100, 0 is original |
158 | */ | 160 | */ |
159 | void setGamma( int ); | 161 | void setGamma( int ); |
160 | 162 | ||
161 | /** | 163 | /** |
162 | * test | 164 | * test |
163 | */ | 165 | */ |
164 | Frame currentFrame()/*const*/; | 166 | Frame currentFrame()/*const*/; |
165 | 167 | ||
166 | /** | 168 | /** |
167 | * Returns the error code | 169 | * Returns the error code |
168 | * XINE_ERROR_NONE 0 | 170 | * XINE_ERROR_NONE 0 |
169 | * XINE_ERROR_NO_INPUT_PLUGIN 1 | 171 | * XINE_ERROR_NO_INPUT_PLUGIN 1 |
170 | * XINE_ERROR_NO_DEMUXER_PLUGIN 2 | 172 | * XINE_ERROR_NO_DEMUXER_PLUGIN 2 |
171 | * XINE_ERROR_DEMUXER_FAILED 3 | 173 | * XINE_ERROR_DEMUXER_FAILED 3 |
172 | */ | 174 | */ |
173 | int error() /*const*/; | 175 | int error() /*const*/; |
174 | 176 | ||
175 | signals: | 177 | signals: |
176 | 178 | ||
177 | void stopped(); | 179 | void stopped(); |
178 | 180 | ||
181 | protected: | ||
182 | virtual void receiveMessage( ThreadUtil::ChannelMessage *msg, SendType sendType ); | ||
183 | |||
179 | private: | 184 | private: |
180 | int m_bytes_per_pixel; | 185 | int m_bytes_per_pixel; |
181 | int m_length, m_pos, m_time; | 186 | int m_length, m_pos, m_time; |
182 | int m_major_version, m_minor_version, m_sub_version; | 187 | int m_major_version, m_minor_version, m_sub_version; |
183 | bool m_video:1; | 188 | bool m_video:1; |
184 | XineVideoWidget *m_wid; | 189 | XineVideoWidget *m_wid; |
185 | xine_t *m_xine; | 190 | xine_t *m_xine; |
186 | xine_stream_t *m_stream; | 191 | xine_stream_t *m_stream; |
187 | xine_cfg_entry_t *m_config; | 192 | xine_cfg_entry_t *m_config; |
188 | xine_vo_driver_t *m_videoOutput; | 193 | xine_vo_driver_t *m_videoOutput; |
189 | xine_ao_driver_t* m_audioOutput; | 194 | xine_ao_driver_t* m_audioOutput; |
190 | xine_event_queue_t *m_queue; | 195 | xine_event_queue_t *m_queue; |
191 | 196 | ||
192 | void handleXineEvent( const xine_event_t* t ); | 197 | void handleXineEvent( const xine_event_t* t ); |
198 | void handleXineEvent( int type ); | ||
193 | void drawFrame( uint8_t* frame, int width, int height, int bytes ); | 199 | void drawFrame( uint8_t* frame, int width, int height, int bytes ); |
194 | // C -> C++ bridge for the event system | 200 | // C -> C++ bridge for the event system |
195 | static void xine_event_handler( void* user_data, const xine_event_t* t); | 201 | static void xine_event_handler( void* user_data, const xine_event_t* t); |
196 | static void xine_display_frame( void* user_data, uint8_t* frame , | 202 | static void xine_display_frame( void* user_data, uint8_t* frame , |
197 | int width, int height, int bytes ); | 203 | int width, int height, int bytes ); |
198 | }; | 204 | }; |
199 | }; | 205 | }; |
200 | 206 | ||
201 | 207 | ||
202 | #endif | 208 | #endif |
diff --git a/noncore/multimedia/opieplayer2/threadutil.cpp b/noncore/multimedia/opieplayer2/threadutil.cpp new file mode 100644 index 0000000..63863b4 --- a/dev/null +++ b/noncore/multimedia/opieplayer2/threadutil.cpp | |||
@@ -0,0 +1,284 @@ | |||
1 | /* This file is part of the KDE project | ||
2 | Copyright (C) 1999 Simon Hausmann <hausmann@kde.org> | ||
3 | |||
4 | This library is free software; you can redistribute it and/or | ||
5 | modify it under the terms of the GNU Library General Public | ||
6 | License as published by the Free Software Foundation; either | ||
7 | version 2 of the License, or (at your option) any later version. | ||
8 | |||
9 | This library is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | Library General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this library; see the file COPYING.LIB. If not, write to | ||
16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
17 | Boston, MA 02111-1307, USA. | ||
18 | */ | ||
19 | |||
20 | #include "threadutil.h" | ||
21 | |||
22 | #include <qsocketnotifier.h> | ||
23 | |||
24 | #include <pthread.h> | ||
25 | #include <assert.h> | ||
26 | #include <unistd.h> | ||
27 | |||
28 | using namespace ThreadUtil; | ||
29 | |||
30 | struct Mutex::Data | ||
31 | { | ||
32 | Data() | ||
33 | { | ||
34 | pthread_mutex_init( &mutex, 0 ); | ||
35 | } | ||
36 | ~Data() | ||
37 | { | ||
38 | pthread_mutex_destroy( &mutex ); | ||
39 | } | ||
40 | |||
41 | pthread_mutex_t mutex; | ||
42 | }; | ||
43 | |||
44 | Mutex::Mutex() | ||
45 | : d( new Data ) | ||
46 | { | ||
47 | } | ||
48 | |||
49 | Mutex::~Mutex() | ||
50 | { | ||
51 | delete d; | ||
52 | } | ||
53 | |||
54 | void Mutex::lock() | ||
55 | { | ||
56 | pthread_mutex_lock( &d->mutex ); | ||
57 | } | ||
58 | |||
59 | void Mutex::unlock() | ||
60 | { | ||
61 | pthread_mutex_unlock( &d->mutex ); | ||
62 | } | ||
63 | |||
64 | bool Mutex::tryLock() | ||
65 | { | ||
66 | return pthread_mutex_trylock( &d->mutex ) == 0; | ||
67 | } | ||
68 | |||
69 | bool Mutex::isLocked() | ||
70 | { | ||
71 | if ( !tryLock() ) | ||
72 | return true; | ||
73 | |||
74 | unlock(); | ||
75 | return false; | ||
76 | } | ||
77 | |||
78 | struct WaitCondition::Data | ||
79 | { | ||
80 | Data() | ||
81 | { | ||
82 | int result = pthread_cond_init( &waitCondition, 0 ); | ||
83 | assert( result == 0 ); | ||
84 | } | ||
85 | ~Data() | ||
86 | { | ||
87 | pthread_cond_destroy( &waitCondition ); | ||
88 | } | ||
89 | |||
90 | pthread_cond_t waitCondition; | ||
91 | }; | ||
92 | |||
93 | WaitCondition::WaitCondition() | ||
94 | : d( new Data ) | ||
95 | { | ||
96 | } | ||
97 | |||
98 | WaitCondition::~WaitCondition() | ||
99 | { | ||
100 | delete d; | ||
101 | } | ||
102 | |||
103 | bool WaitCondition::wait() | ||
104 | { | ||
105 | Mutex m; | ||
106 | m.lock(); | ||
107 | return wait( m ); | ||
108 | } | ||
109 | |||
110 | bool WaitCondition::wait( Mutex &mutex ) | ||
111 | { | ||
112 | return pthread_cond_wait( &d->waitCondition, &mutex.d->mutex ); | ||
113 | } | ||
114 | |||
115 | void WaitCondition::wakeOne() | ||
116 | { | ||
117 | pthread_cond_signal( &d->waitCondition ); | ||
118 | } | ||
119 | |||
120 | void WaitCondition::wakeAll() | ||
121 | { | ||
122 | pthread_cond_broadcast( &d->waitCondition ); | ||
123 | } | ||
124 | |||
125 | OnewayNotifier::OnewayNotifier() | ||
126 | { | ||
127 | int fds[ 2 ]; | ||
128 | pipe( fds ); | ||
129 | m_readFd = fds[ 0 ]; | ||
130 | m_writeFd = fds[ 1 ]; | ||
131 | |||
132 | m_notifier = new QSocketNotifier( m_readFd, QSocketNotifier::Read ); | ||
133 | connect( m_notifier, SIGNAL( activated( int ) ), | ||
134 | this, SLOT( wakeUp() ) ); | ||
135 | } | ||
136 | |||
137 | OnewayNotifier::~OnewayNotifier() | ||
138 | { | ||
139 | delete m_notifier; | ||
140 | |||
141 | ::close( m_readFd ); | ||
142 | ::close( m_writeFd ); | ||
143 | } | ||
144 | |||
145 | void OnewayNotifier::notify() | ||
146 | { | ||
147 | const char c = 42; | ||
148 | ::write( m_writeFd, &c, 1 ); | ||
149 | } | ||
150 | |||
151 | void OnewayNotifier::wakeUp() | ||
152 | { | ||
153 | char c = 0; | ||
154 | |||
155 | if ( ::read( m_readFd, &c, 1 ) != 1 ) | ||
156 | return; | ||
157 | |||
158 | emit awake(); | ||
159 | } | ||
160 | |||
161 | ChannelMessage::ChannelMessage( int type ) | ||
162 | : m_type( type ), m_isCall( false ), m_replied( false ), | ||
163 | m_inEventHandler( false ) | ||
164 | { | ||
165 | } | ||
166 | |||
167 | ChannelMessage::~ChannelMessage() | ||
168 | { | ||
169 | if ( m_guard.isLocked() ) | ||
170 | m_guard.unlock(); | ||
171 | } | ||
172 | |||
173 | void ChannelMessage::reply() | ||
174 | { | ||
175 | if ( !m_isCall ) | ||
176 | { | ||
177 | qDebug( "ChannelMessage::reply() - can't reply oneway message!" ); | ||
178 | return; | ||
179 | } | ||
180 | |||
181 | if ( m_inEventHandler ) | ||
182 | { | ||
183 | m_replied = true; | ||
184 | return; | ||
185 | } | ||
186 | |||
187 | m_condition.wakeOne(); | ||
188 | m_guard.unlock(); | ||
189 | } | ||
190 | |||
191 | struct Channel::Private | ||
192 | { | ||
193 | Private() | ||
194 | { | ||
195 | ownerThread = pthread_self(); | ||
196 | } | ||
197 | |||
198 | pthread_t ownerThread; | ||
199 | }; | ||
200 | |||
201 | Channel::Channel( QObject *parent, const char *name ) | ||
202 | : QObject( parent, name ), d( new Private ) | ||
203 | { | ||
204 | connect( &m_notifier, SIGNAL( awake() ), | ||
205 | this, SLOT( deliver() ) ); | ||
206 | } | ||
207 | |||
208 | Channel::~Channel() | ||
209 | { | ||
210 | delete d; | ||
211 | } | ||
212 | |||
213 | void Channel::send( ChannelMessage *message, SendType type ) | ||
214 | { | ||
215 | if ( type == WaitForReply ) | ||
216 | { | ||
217 | message->m_guard.lock(); | ||
218 | message->m_isCall = true; | ||
219 | } | ||
220 | |||
221 | m_pendingMessagesGuard.lock(); | ||
222 | m_pendingMessages << MsgEnvelope( type, message ); | ||
223 | m_pendingMessagesGuard.unlock(); | ||
224 | |||
225 | if ( d->ownerThread == pthread_self() ) { | ||
226 | assert( type != WaitForReply ); | ||
227 | |||
228 | deliver(); | ||
229 | } | ||
230 | else | ||
231 | m_notifier.notify(); | ||
232 | //QThread::postEvent( this, new QCustomEvent( QEvent::User, envelope ) ); | ||
233 | |||
234 | if ( type == WaitForReply ) | ||
235 | { | ||
236 | message->m_condition.wait( message->m_guard ); | ||
237 | message->m_guard.unlock(); | ||
238 | } | ||
239 | } | ||
240 | |||
241 | void Channel::deliver() | ||
242 | { | ||
243 | AutoLock lock( m_pendingMessagesGuard ); | ||
244 | |||
245 | while ( !m_pendingMessages.isEmpty() ) { | ||
246 | MsgEnvelope envelope = m_pendingMessages.first(); | ||
247 | |||
248 | m_pendingMessages.remove( m_pendingMessages.begin() ); | ||
249 | |||
250 | m_pendingMessagesGuard.unlock(); | ||
251 | deliverOne( envelope ); | ||
252 | m_pendingMessagesGuard.lock(); | ||
253 | } | ||
254 | } | ||
255 | |||
256 | void Channel::deliverOne( const MsgEnvelope &envelope ) | ||
257 | { | ||
258 | ChannelMessage *msg = envelope.msg; | ||
259 | |||
260 | assert( msg ); | ||
261 | |||
262 | if ( envelope.type == WaitForReply ) | ||
263 | { | ||
264 | msg->m_guard.lock(); | ||
265 | msg->m_inEventHandler = true; | ||
266 | } | ||
267 | |||
268 | receiveMessage( msg, envelope.type ); | ||
269 | |||
270 | if ( envelope.type == WaitForReply ) | ||
271 | { | ||
272 | msg->m_inEventHandler = false; | ||
273 | if ( msg->m_replied ) | ||
274 | { | ||
275 | msg->m_condition.wakeOne(); | ||
276 | // this is a bit tricky. we unlock only when we reply. | ||
277 | // reply() does an unlock as well. | ||
278 | msg->m_guard.unlock(); | ||
279 | } | ||
280 | } | ||
281 | } | ||
282 | |||
283 | /* vim: et sw=4 ts=4 | ||
284 | */ | ||
diff --git a/noncore/multimedia/opieplayer2/threadutil.h b/noncore/multimedia/opieplayer2/threadutil.h new file mode 100644 index 0000000..bcb9db9 --- a/dev/null +++ b/noncore/multimedia/opieplayer2/threadutil.h | |||
@@ -0,0 +1,176 @@ | |||
1 | /* This file is part of the KDE project | ||
2 | Copyright (C) 1999 Simon Hausmann <hausmann@kde.org> | ||
3 | |||
4 | This library is free software; you can redistribute it and/or | ||
5 | modify it under the terms of the GNU Library General Public | ||
6 | License as published by the Free Software Foundation; either | ||
7 | version 2 of the License, or (at your option) any later version. | ||
8 | |||
9 | This library is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | Library General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this library; see the file COPYING.LIB. If not, write to | ||
16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
17 | Boston, MA 02111-1307, USA. | ||
18 | */ | ||
19 | |||
20 | #ifndef THREADUTIL_H | ||
21 | #define THREADUTIL_H | ||
22 | |||
23 | #include <qvaluelist.h> | ||
24 | #include <qobject.h> | ||
25 | #include <qguardedptr.h> | ||
26 | |||
27 | class QSocketNotifier; | ||
28 | |||
29 | namespace ThreadUtil | ||
30 | { | ||
31 | |||
32 | class Mutex | ||
33 | { | ||
34 | friend class WaitCondition; | ||
35 | public: | ||
36 | Mutex(); | ||
37 | ~Mutex(); | ||
38 | |||
39 | void lock(); | ||
40 | void unlock(); | ||
41 | bool tryLock(); | ||
42 | bool isLocked(); | ||
43 | |||
44 | private: | ||
45 | struct Data; | ||
46 | Data *d; | ||
47 | |||
48 | Mutex( const Mutex & ); | ||
49 | Mutex &operator=( const Mutex & ); | ||
50 | }; | ||
51 | |||
52 | class AutoLock | ||
53 | { | ||
54 | public: | ||
55 | AutoLock( Mutex &mutex ) : m_mutex( mutex ) { m_mutex.lock(); } | ||
56 | ~AutoLock() { m_mutex.unlock(); } | ||
57 | |||
58 | Mutex *operator &() const { return &m_mutex; } | ||
59 | |||
60 | private: | ||
61 | Mutex &m_mutex; | ||
62 | }; | ||
63 | |||
64 | class WaitCondition | ||
65 | { | ||
66 | public: | ||
67 | WaitCondition(); | ||
68 | ~WaitCondition(); | ||
69 | |||
70 | bool wait(); | ||
71 | bool wait( Mutex &mutex ); | ||
72 | |||
73 | void wakeOne(); | ||
74 | void wakeAll(); | ||
75 | |||
76 | private: | ||
77 | struct Data; | ||
78 | Data *d; | ||
79 | |||
80 | WaitCondition( const WaitCondition & ); | ||
81 | WaitCondition &operator=( const WaitCondition & ); | ||
82 | }; | ||
83 | |||
84 | class OnewayNotifier : public QObject | ||
85 | { | ||
86 | Q_OBJECT | ||
87 | public: | ||
88 | OnewayNotifier(); | ||
89 | ~OnewayNotifier(); | ||
90 | |||
91 | void notify(); | ||
92 | |||
93 | signals: | ||
94 | void awake(); | ||
95 | |||
96 | private slots: | ||
97 | void wakeUp(); | ||
98 | |||
99 | private: | ||
100 | int m_readFd; | ||
101 | int m_writeFd; | ||
102 | QSocketNotifier *m_notifier; | ||
103 | }; | ||
104 | |||
105 | |||
106 | class Channel; | ||
107 | |||
108 | class ChannelMessage | ||
109 | { | ||
110 | friend class Channel; | ||
111 | public: | ||
112 | ChannelMessage( int type = -1 ); | ||
113 | virtual ~ChannelMessage(); | ||
114 | |||
115 | int type() const { return m_type; } | ||
116 | |||
117 | void reply(); | ||
118 | |||
119 | private: | ||
120 | ChannelMessage( const ChannelMessage & ); | ||
121 | ChannelMessage &operator=( const ChannelMessage ); | ||
122 | |||
123 | int m_type; | ||
124 | bool m_isCall : 1; | ||
125 | bool m_replied : 1; | ||
126 | bool m_inEventHandler : 1; | ||
127 | Mutex m_guard; | ||
128 | WaitCondition m_condition; | ||
129 | QGuardedPtr<Channel> m_channel; | ||
130 | }; | ||
131 | |||
132 | class Channel : public QObject | ||
133 | { | ||
134 | Q_OBJECT | ||
135 | public: | ||
136 | enum SendType { OneWay, WaitForReply }; | ||
137 | Channel( QObject *parent = 0, const char *name = 0 ); | ||
138 | virtual ~Channel(); | ||
139 | |||
140 | void send( ChannelMessage *message, SendType type ); | ||
141 | |||
142 | protected: | ||
143 | virtual void receiveMessage( ChannelMessage *message, SendType type ) = 0; | ||
144 | |||
145 | private slots: | ||
146 | void deliver(); | ||
147 | |||
148 | private: | ||
149 | OnewayNotifier m_notifier; | ||
150 | |||
151 | struct MsgEnvelope | ||
152 | { | ||
153 | MsgEnvelope() : type( OneWay ), msg( 0 ) {} | ||
154 | MsgEnvelope( SendType _type , ChannelMessage *_msg ) | ||
155 | : type( _type ), msg( _msg ) {} | ||
156 | |||
157 | SendType type; | ||
158 | ChannelMessage *msg; | ||
159 | }; | ||
160 | |||
161 | void deliverOne( const MsgEnvelope &envelope ); | ||
162 | |||
163 | typedef QValueList<MsgEnvelope> MsgEnvelopeList; | ||
164 | |||
165 | MsgEnvelopeList m_pendingMessages; | ||
166 | Mutex m_pendingMessagesGuard; | ||
167 | |||
168 | struct Private; | ||
169 | Private *d; | ||
170 | }; | ||
171 | |||
172 | } | ||
173 | |||
174 | #endif // THREADUTIL_H | ||
175 | /* vim: et sw=4 ts=4 | ||
176 | */ | ||