Diffstat (limited to 'noncore/multimedia/opieplayer2/lib.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/multimedia/opieplayer2/lib.cpp | 90 |
1 files changed, 51 insertions, 39 deletions
diff --git a/noncore/multimedia/opieplayer2/lib.cpp b/noncore/multimedia/opieplayer2/lib.cpp index e3289bc..9f7a9c5 100644 --- a/noncore/multimedia/opieplayer2/lib.cpp +++ b/noncore/multimedia/opieplayer2/lib.cpp | |||
@@ -1,63 +1,63 @@ | |||
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 "xinevideowidget.h" | 34 | #include "xinevideowidget.h" |
35 | #include "lib.h" | 35 | #include "lib.h" |
36 | 36 | ||
37 | /* OPIE */ | 37 | /* OPIE */ |
38 | #include <opie2/odebug.h> | 38 | #include <opie2/odebug.h> |
39 | #include <qpe/global.h> | 39 | #include <qpe/global.h> |
40 | 40 | ||
41 | /* QT */ | 41 | /* QT */ |
42 | #include <qtextstream.h> | 42 | #include <qtextstream.h> |
43 | #include <qdir.h> | 43 | #include <qdir.h> |
44 | #include <qgfx_qws.h> | 44 | #include <qgfx_qws.h> |
45 | 45 | ||
46 | /* STD */ | 46 | /* STD */ |
47 | #include <assert.h> | 47 | #include <assert.h> |
48 | #include <unistd.h> | 48 | #include <unistd.h> |
49 | 49 | ||
50 | typedef void (*display_xine_frame_t) (void *user_data, uint8_t* frame, | 50 | typedef void (*display_xine_frame_t) (void *user_data, uint8_t* frame, |
51 | int width, int height,int bytes ); | 51 | int width, int height,int bytes ); |
52 | 52 | ||
53 | extern "C" { | 53 | extern "C" { |
54 | xine_vo_driver_t* init_video_out_plugin( xine_t *xine, void* video, display_xine_frame_t, void * ); | 54 | xine_vo_driver_t* init_video_out_plugin( xine_t *xine, void* video, display_xine_frame_t, void * ); |
55 | int null_is_showing_video( const xine_vo_driver_t* self ); | 55 | int null_is_showing_video( const xine_vo_driver_t* self ); |
56 | void null_set_show_video( const xine_vo_driver_t* self, int show ); | 56 | void null_set_show_video( const xine_vo_driver_t* self, int show ); |
57 | int null_is_fullscreen( const xine_vo_driver_t* self ); | 57 | int null_is_fullscreen( const xine_vo_driver_t* self ); |
58 | void null_set_fullscreen( const xine_vo_driver_t* self, int screen ); | 58 | void null_set_fullscreen( const xine_vo_driver_t* self, int screen ); |
59 | int null_is_scaling( const xine_vo_driver_t* self ); | 59 | int null_is_scaling( const xine_vo_driver_t* self ); |
60 | void null_set_scaling( const xine_vo_driver_t* self, int scale ); | 60 | void null_set_scaling( const xine_vo_driver_t* self, int scale ); |
61 | void null_set_gui_width( const xine_vo_driver_t* self, int width ); | 61 | void null_set_gui_width( const xine_vo_driver_t* self, int width ); |
62 | void null_set_gui_height( const xine_vo_driver_t* self, int height ); | 62 | void null_set_gui_height( const xine_vo_driver_t* self, int height ); |
63 | void null_set_mode( const xine_vo_driver_t* self, int depth, int rgb ); | 63 | void null_set_mode( const xine_vo_driver_t* self, int depth, int rgb ); |
@@ -180,24 +180,35 @@ int Lib::majorVersion() { | |||
180 | int Lib::minorVersion() { | 180 | int Lib::minorVersion() { |
181 | int major, minor, sub; | 181 | int major, minor, sub; |
182 | xine_get_version ( &major, &minor, &sub ); | 182 | xine_get_version ( &major, &minor, &sub ); |
183 | return minor; | 183 | return minor; |
184 | } | 184 | } |
185 | 185 | ||
186 | int Lib::subVersion() { | 186 | int Lib::subVersion() { |
187 | int major, minor, sub; | 187 | int major, minor, sub; |
188 | xine_get_version ( &major, &minor, &sub ); | 188 | xine_get_version ( &major, &minor, &sub ); |
189 | return sub; | 189 | return sub; |
190 | } | 190 | } |
191 | 191 | ||
192 | int Lib::setfile(const QString& fileName) | ||
193 | { | ||
194 | QString str = fileName.stripWhiteSpace(); | ||
195 | |||
196 | |||
197 | if ( !xine_open( m_stream, str.utf8().data() ) ) { | ||
198 | return 0; | ||
199 | } | ||
200 | return 1; | ||
201 | } | ||
202 | |||
192 | int Lib::play( const QString& fileName, int startPos, int start_time ) { | 203 | int Lib::play( const QString& fileName, int startPos, int start_time ) { |
193 | assert( m_initialized ); | 204 | assert( m_initialized ); |
194 | 205 | ||
195 | QString str = fileName.stripWhiteSpace(); | 206 | QString str = fileName.stripWhiteSpace(); |
196 | 207 | ||
197 | 208 | ||
198 | if ( !xine_open( m_stream, str.utf8().data() ) ) { | 209 | if ( !xine_open( m_stream, str.utf8().data() ) ) { |
199 | return 0; | 210 | return 0; |
200 | } | 211 | } |
201 | return xine_play( m_stream, startPos, start_time); | 212 | return xine_play( m_stream, startPos, start_time); |
202 | } | 213 | } |
203 | 214 | ||
@@ -205,25 +216,25 @@ void Lib::stop() { | |||
205 | assert( m_initialized ); | 216 | assert( m_initialized ); |
206 | xine_stop( m_stream ); | 217 | xine_stop( m_stream ); |
207 | xine_set_param( m_stream, XINE_PARAM_AUDIO_CLOSE_DEVICE, 1); | 218 | xine_set_param( m_stream, XINE_PARAM_AUDIO_CLOSE_DEVICE, 1); |
208 | } | 219 | } |
209 | 220 | ||
210 | void Lib::pause( bool toggle ) { | 221 | void Lib::pause( bool toggle ) { |
211 | assert( m_initialized ); | 222 | assert( m_initialized ); |
212 | 223 | ||
213 | if ( toggle ) { | 224 | if ( toggle ) { |
214 | xine_set_param( m_stream, XINE_PARAM_SPEED, XINE_SPEED_PAUSE ); | 225 | xine_set_param( m_stream, XINE_PARAM_SPEED, XINE_SPEED_PAUSE ); |
215 | xine_set_param( m_stream, XINE_PARAM_AUDIO_CLOSE_DEVICE, 1); | 226 | xine_set_param( m_stream, XINE_PARAM_AUDIO_CLOSE_DEVICE, 1); |
216 | } | 227 | } |
217 | 228 | ||
218 | else { | 229 | else { |
219 | xine_set_param( m_stream, XINE_PARAM_SPEED, XINE_SPEED_NORMAL ); | 230 | xine_set_param( m_stream, XINE_PARAM_SPEED, XINE_SPEED_NORMAL ); |
220 | } | 231 | } |
221 | } | 232 | } |
222 | 233 | ||
223 | int Lib::speed() const { | 234 | int Lib::speed() const { |
224 | assert( m_initialized ); | 235 | assert( m_initialized ); |
225 | 236 | ||
226 | return xine_get_param ( m_stream, XINE_PARAM_SPEED ); | 237 | return xine_get_param ( m_stream, XINE_PARAM_SPEED ); |
227 | } | 238 | } |
228 | 239 | ||
229 | void Lib::setSpeed( int speed ) { | 240 | void Lib::setSpeed( int speed ) { |
@@ -257,34 +268,34 @@ int Lib::currentTime() const { | |||
257 | else | 268 | else |
258 | return 0; | 269 | return 0; |
259 | } | 270 | } |
260 | 271 | ||
261 | int Lib::length() const { | 272 | int Lib::length() const { |
262 | assert( m_initialized ); | 273 | assert( m_initialized ); |
263 | 274 | ||
264 | int pos, time, length; | 275 | int pos, time, length; |
265 | /* dilb: patch to solve the wrong stream length reported to the GUI*/ | 276 | /* dilb: patch to solve the wrong stream length reported to the GUI*/ |
266 | int iRetVal=0, iTestLoop=0; | 277 | int iRetVal=0, iTestLoop=0; |
267 | 278 | ||
268 | do | 279 | do |
269 | { | 280 | { |
270 | iRetVal = xine_get_pos_length( m_stream, &pos, &time, &length ); | 281 | iRetVal = xine_get_pos_length( m_stream, &pos, &time, &length ); |
271 | if (iRetVal) | 282 | if (iRetVal) |
272 | {/* if the function didn't return 0, then pos, time and length are valid.*/ | 283 | {/* if the function didn't return 0, then pos, time and length are valid.*/ |
273 | return length/1000; | 284 | return length/1000; |
274 | } | 285 | } |
275 | /*don't poll too much*/ | 286 | /*don't poll too much*/ |
276 | usleep(100000); | 287 | usleep(100000); |
277 | iTestLoop++; | 288 | iTestLoop++; |
278 | } | 289 | } |
279 | while ( iTestLoop < 10 ); /* if after 1s, we still don't have any | 290 | while ( iTestLoop < 10 ); /* if after 1s, we still don't have any |
280 | valid stream, then return -1 (this value could be used to make the stream | 291 | valid stream, then return -1 (this value could be used to make the stream |
281 | unseekable, but it should never occur!! Mr. Murphy ? :) ) */ | 292 | unseekable, but it should never occur!! Mr. Murphy ? :) ) */ |
282 | 293 | ||
283 | return -1; | 294 | return -1; |
284 | } | 295 | } |
285 | 296 | ||
286 | bool Lib::isSeekable() const { | 297 | bool Lib::isSeekable() const { |
287 | assert( m_initialized ); | 298 | assert( m_initialized ); |
288 | 299 | ||
289 | return xine_get_stream_info( m_stream, XINE_STREAM_INFO_SEEKABLE ); | 300 | return xine_get_stream_info( m_stream, XINE_STREAM_INFO_SEEKABLE ); |
290 | } | 301 | } |
@@ -293,25 +304,25 @@ void Lib::seekTo( int time ) { | |||
293 | assert( m_initialized ); | 304 | assert( m_initialized ); |
294 | 305 | ||
295 | odebug << "Seeking to second " << time << oendl; | 306 | odebug << "Seeking to second " << time << oendl; |
296 | //Keep it paused if it was in that state | 307 | //Keep it paused if it was in that state |
297 | if ( xine_get_param( m_stream, XINE_PARAM_SPEED ) ) { | 308 | if ( xine_get_param( m_stream, XINE_PARAM_SPEED ) ) { |
298 | xine_play( m_stream, 0, time*1000 ); | 309 | xine_play( m_stream, 0, time*1000 ); |
299 | } | 310 | } |
300 | 311 | ||
301 | else { | 312 | else { |
302 | xine_play( m_stream, 0, time*1000 ); | 313 | xine_play( m_stream, 0, time*1000 ); |
303 | xine_set_param( m_stream, XINE_PARAM_SPEED, XINE_SPEED_PAUSE ); | 314 | xine_set_param( m_stream, XINE_PARAM_SPEED, XINE_SPEED_PAUSE ); |
304 | } | 315 | } |
305 | 316 | ||
306 | } | 317 | } |
307 | 318 | ||
308 | 319 | ||
309 | QString Lib::metaInfo( int number) const { | 320 | QString Lib::metaInfo( int number) const { |
310 | assert( m_initialized ); | 321 | assert( m_initialized ); |
311 | 322 | ||
312 | return xine_get_meta_info( m_stream, number ); | 323 | return xine_get_meta_info( m_stream, number ); |
313 | } | 324 | } |
314 | 325 | ||
315 | int Lib::error() const { | 326 | int Lib::error() const { |
316 | assert( m_initialized ); | 327 | assert( m_initialized ); |
317 | 328 | ||
@@ -322,27 +333,28 @@ void Lib::ensureInitialized() | |||
322 | { | 333 | { |
323 | if ( m_initialized ) | 334 | if ( m_initialized ) |
324 | return; | 335 | return; |
325 | 336 | ||
326 | odebug << "waiting for initialization thread to finish" << oendl; | 337 | odebug << "waiting for initialization thread to finish" << oendl; |
327 | wait(); | 338 | wait(); |
328 | odebug << "initialization thread finished!" << oendl; | 339 | odebug << "initialization thread finished!" << oendl; |
329 | } | 340 | } |
330 | 341 | ||
331 | void Lib::setWidget( XineVideoWidget *widget ) | 342 | void Lib::setWidget( XineVideoWidget *widget ) |
332 | { | 343 | { |
333 | m_wid = widget; | 344 | m_wid = widget; |
334 | resize ( m_wid-> size ( ) ); | 345 | if (m_wid) { |
335 | ::null_set_mode( m_videoOutput, qt_screen->depth(), qt_screen->pixelType() ); | 346 | resize ( m_wid-> size ( ) ); |
336 | m_wid->repaint(); | 347 | ::null_set_mode( m_videoOutput, qt_screen->depth(), qt_screen->pixelType() ); |
348 | } | ||
337 | } | 349 | } |
338 | 350 | ||
339 | void Lib::receiveMessage( ThreadUtil::ChannelMessage *msg, SendType sendType ) | 351 | void Lib::receiveMessage( ThreadUtil::ChannelMessage *msg, SendType sendType ) |
340 | { | 352 | { |
341 | assert( sendType == ThreadUtil::Channel::OneWay ); | 353 | assert( sendType == ThreadUtil::Channel::OneWay ); |
342 | handleXineEvent( msg->type(), msg->data(), msg->msg() ); | 354 | handleXineEvent( msg->type(), msg->data(), msg->msg() ); |
343 | delete msg; | 355 | delete msg; |
344 | } | 356 | } |
345 | 357 | ||
346 | void Lib::handleXineEvent( const xine_event_t* t ) { | 358 | void Lib::handleXineEvent( const xine_event_t* t ) { |
347 | int prog = -1; const char* name = 0; | 359 | int prog = -1; const char* name = 0; |
348 | if ( t->type == XINE_EVENT_PROGRESS ) { | 360 | if ( t->type == XINE_EVENT_PROGRESS ) { |
@@ -422,16 +434,16 @@ void Lib::xine_event_handler( void* user_data, const xine_event_t* t ) { | |||
422 | void Lib::xine_display_frame( void* user_data, uint8_t *frame, | 434 | void Lib::xine_display_frame( void* user_data, uint8_t *frame, |
423 | int width, int height, int bytes ) { | 435 | int width, int height, int bytes ) { |
424 | ( (Lib*)user_data)->drawFrame( frame, width, height, bytes ); | 436 | ( (Lib*)user_data)->drawFrame( frame, width, height, bytes ); |
425 | } | 437 | } |
426 | 438 | ||
427 | void Lib::drawFrame( uint8_t* frame, int width, int height, int bytes ) { | 439 | void Lib::drawFrame( uint8_t* frame, int width, int height, int bytes ) { |
428 | assert( m_initialized ); | 440 | assert( m_initialized ); |
429 | 441 | ||
430 | if ( !m_video ) { | 442 | if ( !m_video ) { |
431 | return; | 443 | return; |
432 | } | 444 | } |
433 | 445 | ||
434 | assert( m_wid ); | 446 | // assert( m_wid ); |
435 | 447 | ||
436 | m_wid-> setVideoFrame ( frame, width, height, bytes ); | 448 | if (m_wid) m_wid-> setVideoFrame ( frame, width, height, bytes ); |
437 | } | 449 | } |