author | llornkcor <llornkcor> | 2003-02-25 23:38:02 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2003-02-25 23:38:02 (UTC) |
commit | 94cb45ce60cc00d719a802baeb8acf74f42150d2 (patch) (unidiff) | |
tree | 27f70d60579a5301f04986e56cf4bfa2067dad9c | |
parent | bde9ed97c92b6f7eefa8a66d9f58aa4c78127733 (diff) | |
download | opie-94cb45ce60cc00d719a802baeb8acf74f42150d2.zip opie-94cb45ce60cc00d719a802baeb8acf74f42150d2.tar.gz opie-94cb45ce60cc00d719a802baeb8acf74f42150d2.tar.bz2 |
remove libmad depending on libmpeg3, and fix crash when skin not found
-rw-r--r-- | core/multimedia/opieplayer/audiowidget.cpp | 12 | ||||
-rw-r--r-- | core/multimedia/opieplayer/loopcontrol.cpp | 20 |
2 files changed, 18 insertions, 14 deletions
diff --git a/core/multimedia/opieplayer/audiowidget.cpp b/core/multimedia/opieplayer/audiowidget.cpp index 9a55608..3dfe182 100644 --- a/core/multimedia/opieplayer/audiowidget.cpp +++ b/core/multimedia/opieplayer/audiowidget.cpp | |||
@@ -6,49 +6,49 @@ | |||
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #include <qpe/qpeapplication.h> | 20 | #include <qpe/qpeapplication.h> |
21 | #include <qpe/resource.h> | 21 | #include <qpe/resource.h> |
22 | #include <qpe/config.h> | 22 | #include <qpe/config.h> |
23 | 23 | ||
24 | #include <qwidget.h> | 24 | #include <qwidget.h> |
25 | #include <qpixmap.h> | 25 | #include <qpixmap.h> |
26 | #include <qbutton.h> | 26 | #include <qbutton.h> |
27 | #include <qpainter.h> | 27 | #include <qpainter.h> |
28 | #include <qframe.h> | 28 | #include <qframe.h> |
29 | #include <qlayout.h> | 29 | #include <qlayout.h> |
30 | 30 | #include <qdir.h> | |
31 | #include "audiowidget.h" | 31 | #include "audiowidget.h" |
32 | #include "mediaplayerstate.h" | 32 | #include "mediaplayerstate.h" |
33 | 33 | ||
34 | #include <stdlib.h> | 34 | #include <stdlib.h> |
35 | #include <stdio.h> | 35 | #include <stdio.h> |
36 | 36 | ||
37 | extern MediaPlayerState *mediaPlayerState; | 37 | extern MediaPlayerState *mediaPlayerState; |
38 | 38 | ||
39 | 39 | ||
40 | static const int xo = -2; // movable x offset | 40 | static const int xo = -2; // movable x offset |
41 | static const int yo = 22; // movable y offset | 41 | static const int yo = 22; // movable y offset |
42 | 42 | ||
43 | struct MediaButton { | 43 | struct MediaButton { |
44 | bool isToggle, isHeld, isDown; | 44 | bool isToggle, isHeld, isDown; |
45 | }; | 45 | }; |
46 | 46 | ||
47 | //Layout information for the audioButtons (and if it is a toggle button or not) | 47 | //Layout information for the audioButtons (and if it is a toggle button or not) |
48 | MediaButton audioButtons[] = { | 48 | MediaButton audioButtons[] = { |
49 | { TRUE, FALSE, FALSE }, // play | 49 | { TRUE, FALSE, FALSE }, // play |
50 | { FALSE, FALSE, FALSE }, // stop | 50 | { FALSE, FALSE, FALSE }, // stop |
51 | { FALSE, FALSE, FALSE }, // next | 51 | { FALSE, FALSE, FALSE }, // next |
52 | { FALSE, FALSE, FALSE }, // previous | 52 | { FALSE, FALSE, FALSE }, // previous |
53 | { FALSE, FALSE, FALSE }, // volume up | 53 | { FALSE, FALSE, FALSE }, // volume up |
54 | { FALSE, FALSE, FALSE }, // volume down | 54 | { FALSE, FALSE, FALSE }, // volume down |
@@ -60,54 +60,58 @@ MediaButton audioButtons[] = { | |||
60 | 60 | ||
61 | const char *skin_mask_file_names[10] = { | 61 | const char *skin_mask_file_names[10] = { |
62 | "play", "stop", "next", "prev", "up", | 62 | "play", "stop", "next", "prev", "up", |
63 | "down", "loop", "playlist", "forward", "back" | 63 | "down", "loop", "playlist", "forward", "back" |
64 | }; | 64 | }; |
65 | 65 | ||
66 | static void changeTextColor( QWidget *w ) { | 66 | static void changeTextColor( QWidget *w ) { |
67 | QPalette p = w->palette(); | 67 | QPalette p = w->palette(); |
68 | p.setBrush( QColorGroup::Background, QColor( 167, 212, 167 ) ); | 68 | p.setBrush( QColorGroup::Background, QColor( 167, 212, 167 ) ); |
69 | p.setBrush( QColorGroup::Base, QColor( 167, 212, 167 ) ); | 69 | p.setBrush( QColorGroup::Base, QColor( 167, 212, 167 ) ); |
70 | w->setPalette( p ); | 70 | w->setPalette( p ); |
71 | } | 71 | } |
72 | 72 | ||
73 | static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); | 73 | static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); |
74 | 74 | ||
75 | AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : | 75 | AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : |
76 | QWidget( parent, name, f ), songInfo( this ), slider( Qt::Horizontal, this ), time( this ) | 76 | QWidget( parent, name, f ), songInfo( this ), slider( Qt::Horizontal, this ), time( this ) |
77 | { | 77 | { |
78 | setCaption( tr("OpiePlayer") ); | 78 | setCaption( tr("OpiePlayer") ); |
79 | qDebug("<<<<<audioWidget"); | 79 | qDebug("<<<<<audioWidget"); |
80 | 80 | ||
81 | Config cfg("OpiePlayer"); | 81 | Config cfg("OpiePlayer"); |
82 | cfg.setGroup("Options"); | 82 | cfg.setGroup("Options"); |
83 | skin = cfg.readEntry("Skin","default"); | 83 | skin = cfg.readEntry("Skin","default"); |
84 | //skin = "scaleTest"; | 84 | //skin = "scaleTest"; |
85 | // color of background, frame, degree of transparency | 85 | // color of background, frame, degree of transparency |
86 | 86 | ||
87 | // QString skinPath = "opieplayer/skins/" + skin; | 87 | // QString skinPath = "opieplayer/skins/" + skin; |
88 | QString skinPath = "opieplayer2/skins/" + skin; | 88 | QString skinPath; |
89 | qDebug("skin path "+skinPath); | 89 | skinPath = "opieplayer2/skins/" + skin; |
90 | if(!QDir(skinPath).exists()) | ||
91 | skinPath = "opieplayer2/skins/default"; | ||
92 | |||
93 | qDebug("skin path " + skinPath); | ||
90 | 94 | ||
91 | pixBg = new QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); | 95 | pixBg = new QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); |
92 | imgUp = new QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) ); | 96 | imgUp = new QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) ); |
93 | imgDn = new QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) ); | 97 | imgDn = new QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) ); |
94 | 98 | ||
95 | imgButtonMask = new QImage( imgUp->width(), imgUp->height(), 8, 255 ); | 99 | imgButtonMask = new QImage( imgUp->width(), imgUp->height(), 8, 255 ); |
96 | imgButtonMask->fill( 0 ); | 100 | imgButtonMask->fill( 0 ); |
97 | 101 | ||
98 | for ( int i = 0; i < 10; i++ ) { | 102 | for ( int i = 0; i < 10; i++ ) { |
99 | QString filename = QString(getenv("OPIEDIR")) + "/pics/" + skinPath + "/skin_mask_" + skin_mask_file_names[i] + ".png"; | 103 | QString filename = QString(getenv("OPIEDIR")) + "/pics/" + skinPath + "/skin_mask_" + skin_mask_file_names[i] + ".png"; |
100 | masks[i] = new QBitmap( filename ); | 104 | masks[i] = new QBitmap( filename ); |
101 | 105 | ||
102 | if ( !masks[i]->isNull() ) { | 106 | if ( !masks[i]->isNull() ) { |
103 | QImage imgMask = masks[i]->convertToImage(); | 107 | QImage imgMask = masks[i]->convertToImage(); |
104 | uchar **dest = imgButtonMask->jumpTable(); | 108 | uchar **dest = imgButtonMask->jumpTable(); |
105 | for ( int y = 0; y < imgUp->height(); y++ ) { | 109 | for ( int y = 0; y < imgUp->height(); y++ ) { |
106 | uchar *line = dest[y]; | 110 | uchar *line = dest[y]; |
107 | for ( int x = 0; x < imgUp->width(); x++ ) | 111 | for ( int x = 0; x < imgUp->width(); x++ ) |
108 | if ( !qRed( imgMask.pixel( x, y ) ) ) | 112 | if ( !qRed( imgMask.pixel( x, y ) ) ) |
109 | line[x] = i + 1; | 113 | line[x] = i + 1; |
110 | } | 114 | } |
111 | } | 115 | } |
112 | 116 | ||
113 | } | 117 | } |
diff --git a/core/multimedia/opieplayer/loopcontrol.cpp b/core/multimedia/opieplayer/loopcontrol.cpp index ba14882..8cf0a75 100644 --- a/core/multimedia/opieplayer/loopcontrol.cpp +++ b/core/multimedia/opieplayer/loopcontrol.cpp | |||
@@ -79,66 +79,66 @@ public: | |||
79 | private: | 79 | private: |
80 | pthread_mutex_t mutex; | 80 | pthread_mutex_t mutex; |
81 | }; | 81 | }; |
82 | 82 | ||
83 | 83 | ||
84 | void *startAudioThread( void *ptr ) { | 84 | void *startAudioThread( void *ptr ) { |
85 | LoopControl *mpegView = (LoopControl *)ptr; | 85 | LoopControl *mpegView = (LoopControl *)ptr; |
86 | while ( TRUE ) { | 86 | while ( TRUE ) { |
87 | if ( threadOkToGo && mpegView->moreAudio ) | 87 | if ( threadOkToGo && mpegView->moreAudio ) |
88 | mpegView->startAudio(); | 88 | mpegView->startAudio(); |
89 | else | 89 | else |
90 | usleep( 10000 ); // Semi-buzy-wait till we are playing again | 90 | usleep( 10000 ); // Semi-buzy-wait till we are playing again |
91 | } | 91 | } |
92 | return 0; | 92 | return 0; |
93 | } | 93 | } |
94 | 94 | ||
95 | 95 | ||
96 | Mutex *audioMutex; | 96 | Mutex *audioMutex; |
97 | 97 | ||
98 | 98 | ||
99 | LoopControl::LoopControl( QObject *parent, const char *name ) | 99 | LoopControl::LoopControl( QObject *parent, const char *name ) |
100 | : QObject( parent, name ) { | 100 | : QObject( parent, name ) { |
101 | isMuted = FALSE; | 101 | isMuted = FALSE; |
102 | connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( setMute(bool) ) ); | 102 | connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( setMute(bool) ) ); |
103 | //qDebug("starting loopcontrol"); | 103 | qDebug("starting loopcontrol"); |
104 | audioMutex = new Mutex; | 104 | audioMutex = new Mutex; |
105 | 105 | ||
106 | pthread_attr_init(&audio_attr); | 106 | pthread_attr_init(&audio_attr); |
107 | #define USE_REALTIME_AUDIO_THREAD | 107 | #define USE_REALTIME_AUDIO_THREAD |
108 | #ifdef USE_REALTIME_AUDIO_THREAD | 108 | #ifdef USE_REALTIME_AUDIO_THREAD |
109 | // Attempt to set it to real-time round robin | 109 | // Attempt to set it to real-time round robin |
110 | if ( pthread_attr_setschedpolicy( &audio_attr, SCHED_RR ) == 0 ) { | 110 | if ( pthread_attr_setschedpolicy( &audio_attr, SCHED_RR ) == 0 ) { |
111 | sched_param params; | 111 | sched_param params; |
112 | params.sched_priority = 50; | 112 | params.sched_priority = 50; |
113 | pthread_attr_setschedparam(&audio_attr,¶ms); | 113 | pthread_attr_setschedparam(&audio_attr,¶ms); |
114 | } else { | 114 | } else { |
115 | qDebug( "Error setting up a realtime thread, reverting to using a normal thread." ); | 115 | qDebug( "Error setting up a realtime thread, reverting to using a normal thread." ); |
116 | pthread_attr_destroy(&audio_attr); | 116 | pthread_attr_destroy(&audio_attr); |
117 | pthread_attr_init(&audio_attr); | 117 | pthread_attr_init(&audio_attr); |
118 | } | 118 | } |
119 | #endif | 119 | #endif |
120 | //qDebug("create audio thread"); | 120 | qDebug("create audio thread"); |
121 | pthread_create(&audio_tid, &audio_attr, (void * (*)(void *))startAudioThread, this); | 121 | pthread_create(&audio_tid, &audio_attr, (void * (*)(void *))startAudioThread, this); |
122 | } | 122 | } |
123 | 123 | ||
124 | 124 | ||
125 | LoopControl::~LoopControl() { | 125 | LoopControl::~LoopControl() { |
126 | stop(); | 126 | stop(); |
127 | } | 127 | } |
128 | 128 | ||
129 | 129 | ||
130 | static long prev_frame = 0; | 130 | static long prev_frame = 0; |
131 | static int currentSample = 0; | 131 | static int currentSample = 0; |
132 | 132 | ||
133 | 133 | ||
134 | void LoopControl::timerEvent( QTimerEvent *te ) { | 134 | void LoopControl::timerEvent( QTimerEvent *te ) { |
135 | 135 | ||
136 | if ( te->timerId() == videoId ) | 136 | if ( te->timerId() == videoId ) |
137 | startVideo(); | 137 | startVideo(); |
138 | 138 | ||
139 | if ( te->timerId() == sliderId ) { | 139 | if ( te->timerId() == sliderId ) { |
140 | if ( hasAudioChannel && !hasVideoChannel && moreAudio ) { | 140 | if ( hasAudioChannel && !hasVideoChannel && moreAudio ) { |
141 | mediaPlayerState->updatePosition( audioSampleCounter ); | 141 | mediaPlayerState->updatePosition( audioSampleCounter ); |
142 | } else if ( hasVideoChannel && moreVideo ) { | 142 | } else if ( hasVideoChannel && moreVideo ) { |
143 | mediaPlayerState->updatePosition( current_frame ); | 143 | mediaPlayerState->updatePosition( current_frame ); |
144 | } | 144 | } |
@@ -343,78 +343,78 @@ void LoopControl::stop( bool willPlayAgainShortly ) { | |||
343 | delete audioBuffer; | 343 | delete audioBuffer; |
344 | audioDevice = 0; | 344 | audioDevice = 0; |
345 | audioBuffer = 0; | 345 | audioBuffer = 0; |
346 | } | 346 | } |
347 | 347 | ||
348 | audioMutex->unlock(); | 348 | audioMutex->unlock(); |
349 | } | 349 | } |
350 | audioSampleCounter=0; | 350 | audioSampleCounter=0; |
351 | current_frame=0; | 351 | current_frame=0; |
352 | total_audio_samples=0; | 352 | total_audio_samples=0; |
353 | } | 353 | } |
354 | 354 | ||
355 | 355 | ||
356 | bool LoopControl::init( const QString& filename ) { | 356 | bool LoopControl::init( const QString& filename ) { |
357 | stop(); | 357 | stop(); |
358 | audioMutex->lock(); | 358 | audioMutex->lock(); |
359 | 359 | ||
360 | fileName = filename; | 360 | fileName = filename; |
361 | stream = 0; // only play stream 0 for now | 361 | stream = 0; // only play stream 0 for now |
362 | current_frame = total_video_frames = total_audio_samples = 0; | 362 | current_frame = total_video_frames = total_audio_samples = 0; |
363 | 363 | ||
364 | qDebug( "Using the %s decoder", mediaPlayerState->curDecoder()->pluginName() ); | 364 | qDebug( "Using the %s decoder", mediaPlayerState->curDecoder()->pluginName() ); |
365 | 365 | ||
366 | // ### Hack to use libmpeg3plugin to get the number of audio samples if we are using the libmad plugin | 366 | // ### Hack to use libmpeg3plugin to get the number of audio samples if we are using the libmad plugin |
367 | if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMadPlugin") ) { | 367 | // if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMadPlugin") ) { |
368 | if ( mediaPlayerState->libMpeg3Decoder() && mediaPlayerState->libMpeg3Decoder()->open( filename )) { | 368 | // if ( mediaPlayerState->libMpeg3Decoder() && mediaPlayerState->libMpeg3Decoder()->open( filename )) { |
369 | total_audio_samples = mediaPlayerState->libMpeg3Decoder()->audioSamples( 0 ); | 369 | // total_audio_samples = mediaPlayerState->libMpeg3Decoder()->audioSamples( 0 ); |
370 | mediaPlayerState->libMpeg3Decoder()->close(); | 370 | // mediaPlayerState->libMpeg3Decoder()->close(); |
371 | } | 371 | // } |
372 | } | 372 | // } |
373 | 373 | ||
374 | if ( !mediaPlayerState->curDecoder()|| !mediaPlayerState->curDecoder()->open( filename ) ) { | 374 | if ( !mediaPlayerState->curDecoder()|| !mediaPlayerState->curDecoder()->open( filename ) ) { |
375 | audioMutex->unlock(); | 375 | audioMutex->unlock(); |
376 | return FALSE; | 376 | return FALSE; |
377 | } | 377 | } |
378 | 378 | ||
379 | hasAudioChannel = mediaPlayerState->curDecoder()->audioStreams() > 0; | 379 | hasAudioChannel = mediaPlayerState->curDecoder()->audioStreams() > 0; |
380 | hasVideoChannel = mediaPlayerState->curDecoder()->videoStreams() > 0; | 380 | hasVideoChannel = mediaPlayerState->curDecoder()->videoStreams() > 0; |
381 | 381 | ||
382 | if ( hasAudioChannel ) { | 382 | if ( hasAudioChannel ) { |
383 | int astream = 0; | 383 | int astream = 0; |
384 | 384 | ||
385 | if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMpeg3Plugin") ) | 385 | if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMpeg3Plugin") ) |
386 | channels = 2; //dont akx me why, but it needs this hack | 386 | channels = 2; //dont akx me why, but it needs this hack |
387 | else | 387 | else |
388 | channels = mediaPlayerState->curDecoder()->audioChannels( astream ); | 388 | channels = mediaPlayerState->curDecoder()->audioChannels( astream ); |
389 | 389 | ||
390 | qDebug( "LC- channels = %d", channels ); | 390 | qDebug( "LC- channels = %d", channels ); |
391 | 391 | ||
392 | if ( !total_audio_samples ) | 392 | // if ( !total_audio_samples ) |
393 | total_audio_samples = mediaPlayerState->curDecoder()->audioSamples( astream ); | 393 | total_audio_samples = mediaPlayerState->curDecoder()->audioSamples( astream ); |
394 | 394 | ||
395 | total_audio_samples += 1000; | 395 | total_audio_samples += 1000; |
396 | 396 | qDebug("total samples %d", total_audio_samples); | |
397 | mediaPlayerState->setLength( total_audio_samples ); | 397 | mediaPlayerState->setLength( total_audio_samples ); |
398 | 398 | ||
399 | freq = mediaPlayerState->curDecoder()->audioFrequency( astream ); | 399 | freq = mediaPlayerState->curDecoder()->audioFrequency( astream ); |
400 | qDebug( "LC- frequency = %d", freq ); | 400 | qDebug( "LC- frequency = %d", freq ); |
401 | 401 | ||
402 | audioSampleCounter = 0; | 402 | audioSampleCounter = 0; |
403 | int bits_per_sample; | 403 | int bits_per_sample; |
404 | if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibWavPlugin") ) { | 404 | if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibWavPlugin") ) { |
405 | bits_per_sample =(int) mediaPlayerState->curDecoder()->getTime(); | 405 | bits_per_sample =(int) mediaPlayerState->curDecoder()->getTime(); |
406 | qDebug("using stupid hack"); | 406 | qDebug("using stupid hack"); |
407 | } else { | 407 | } else { |
408 | bits_per_sample=0; | 408 | bits_per_sample=0; |
409 | } | 409 | } |
410 | 410 | ||
411 | audioDevice = new AudioDevice( freq, channels, bits_per_sample); | 411 | audioDevice = new AudioDevice( freq, channels, bits_per_sample); |
412 | audioBuffer = new char[ audioDevice->bufferSize() ]; | 412 | audioBuffer = new char[ audioDevice->bufferSize() ]; |
413 | channels = audioDevice->channels(); | 413 | channels = audioDevice->channels(); |
414 | 414 | ||
415 | //### must check which frequency is actually used. | 415 | //### must check which frequency is actually used. |
416 | static const int size = 1; | 416 | static const int size = 1; |
417 | short int buf[size]; | 417 | short int buf[size]; |
418 | long samplesRead = 0; | 418 | long samplesRead = 0; |
419 | mediaPlayerState->curDecoder()->audioReadSamples( buf, channels, size, samplesRead, stream ); | 419 | mediaPlayerState->curDecoder()->audioReadSamples( buf, channels, size, samplesRead, stream ); |
420 | } | 420 | } |