author | schurig <schurig> | 2003-06-04 10:30:28 (UTC) |
---|---|---|
committer | schurig <schurig> | 2003-06-04 10:30:28 (UTC) |
commit | df76591a8ee920c6549bc55b026ab66926917667 (patch) (unidiff) | |
tree | 3d11b883a8f4a54fd11569cc9856a32f32de8e9d | |
parent | 77eff544a1a3421679f978d322e2cdcfab958c8f (diff) | |
download | opie-df76591a8ee920c6549bc55b026ab66926917667.zip opie-df76591a8ee920c6549bc55b026ab66926917667.tar.gz opie-df76591a8ee920c6549bc55b026ab66926917667.tar.bz2 |
ramses want's realtime, too
-rw-r--r-- | core/multimedia/opieplayer/loopcontrol_threaded.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/core/multimedia/opieplayer/loopcontrol_threaded.cpp b/core/multimedia/opieplayer/loopcontrol_threaded.cpp index 6817d5b..e99c97b 100644 --- a/core/multimedia/opieplayer/loopcontrol_threaded.cpp +++ b/core/multimedia/opieplayer/loopcontrol_threaded.cpp | |||
@@ -1,170 +1,170 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
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 | #define _REENTRANT | 20 | #define _REENTRANT |
21 | 21 | ||
22 | #include <qpe/qpeapplication.h> | 22 | #include <qpe/qpeapplication.h> |
23 | #include <qimage.h> | 23 | #include <qimage.h> |
24 | #include <qpainter.h> | 24 | #include <qpainter.h> |
25 | #ifdef Q_WS_QWS | 25 | #ifdef Q_WS_QWS |
26 | #include <qpe/qcopenvelope_qws.h> | 26 | #include <qpe/qcopenvelope_qws.h> |
27 | #endif | 27 | #endif |
28 | #include "mediaplayerplugininterface.h" | 28 | #include "mediaplayerplugininterface.h" |
29 | #include <stdio.h> | 29 | #include <stdio.h> |
30 | #include <stdlib.h> | 30 | #include <stdlib.h> |
31 | #include <string.h> | 31 | #include <string.h> |
32 | #include <time.h> | 32 | #include <time.h> |
33 | #include <unistd.h> | 33 | #include <unistd.h> |
34 | #include <pthread.h> | 34 | #include <pthread.h> |
35 | #include "loopcontrol.h" | 35 | #include "loopcontrol.h" |
36 | #include "audiodevice.h" | 36 | #include "audiodevice.h" |
37 | #include "videowidget.h" | 37 | #include "videowidget.h" |
38 | #include "audiowidget.h" | 38 | #include "audiowidget.h" |
39 | #include "mediaplayerstate.h" | 39 | #include "mediaplayerstate.h" |
40 | 40 | ||
41 | 41 | ||
42 | #if defined(QT_QWS_SL5XXX) || defined(QT_QWS_IPAQ) | 42 | #if defined(QT_QWS_SL5XXX) || defined(QT_QWS_IPAQ) || defined(QT_QWS_RAMSES) |
43 | #define USE_REALTIME_AUDIO_THREAD | 43 | #define USE_REALTIME_AUDIO_THREAD |
44 | #endif | 44 | #endif |
45 | 45 | ||
46 | 46 | ||
47 | extern VideoWidget *videoUI; // now only needed to tell it to play a frame | 47 | extern VideoWidget *videoUI; // now only needed to tell it to play a frame |
48 | extern MediaPlayerState *mediaPlayerState; | 48 | extern MediaPlayerState *mediaPlayerState; |
49 | 49 | ||
50 | 50 | ||
51 | #define DecodeLoopDebug(x) qDebug x | 51 | #define DecodeLoopDebug(x) qDebug x |
52 | //#define DecodeLoopDebug(x) | 52 | //#define DecodeLoopDebug(x) |
53 | 53 | ||
54 | 54 | ||
55 | static char *audioBuffer = NULL; | 55 | static char *audioBuffer = NULL; |
56 | static AudioDevice *audioDevice = NULL; | 56 | static AudioDevice *audioDevice = NULL; |
57 | static bool disabledSuspendScreenSaver = FALSE; | 57 | static bool disabledSuspendScreenSaver = FALSE; |
58 | 58 | ||
59 | 59 | ||
60 | pthread_tvideo_tid; | 60 | pthread_tvideo_tid; |
61 | pthread_attr_t video_attr; | 61 | pthread_attr_t video_attr; |
62 | pthread_taudio_tid; | 62 | pthread_taudio_tid; |
63 | pthread_attr_t audio_attr; | 63 | pthread_attr_t audio_attr; |
64 | 64 | ||
65 | 65 | ||
66 | bool emitPlayFinished = FALSE; | 66 | bool emitPlayFinished = FALSE; |
67 | bool emitChangePos = FALSE; | 67 | bool emitChangePos = FALSE; |
68 | 68 | ||
69 | 69 | ||
70 | class Mutex { | 70 | class Mutex { |
71 | public: | 71 | public: |
72 | Mutex() { | 72 | Mutex() { |
73 | pthread_mutexattr_t attr; | 73 | pthread_mutexattr_t attr; |
74 | pthread_mutexattr_init( &attr ); | 74 | pthread_mutexattr_init( &attr ); |
75 | pthread_mutex_init( &mutex, &attr ); | 75 | pthread_mutex_init( &mutex, &attr ); |
76 | pthread_mutexattr_destroy( &attr ); | 76 | pthread_mutexattr_destroy( &attr ); |
77 | } | 77 | } |
78 | 78 | ||
79 | ~Mutex() { | 79 | ~Mutex() { |
80 | pthread_mutex_destroy( &mutex ); | 80 | pthread_mutex_destroy( &mutex ); |
81 | } | 81 | } |
82 | 82 | ||
83 | void lock() { | 83 | void lock() { |
84 | pthread_mutex_lock( &mutex ); | 84 | pthread_mutex_lock( &mutex ); |
85 | } | 85 | } |
86 | 86 | ||
87 | void unlock() { | 87 | void unlock() { |
88 | pthread_mutex_unlock( &mutex ); | 88 | pthread_mutex_unlock( &mutex ); |
89 | } | 89 | } |
90 | /* | 90 | /* |
91 | bool locked() { | 91 | bool locked() { |
92 | switch ( pthread_mutex_trylock( &mutex ) ) { | 92 | switch ( pthread_mutex_trylock( &mutex ) ) { |
93 | case EBUSY: | 93 | case EBUSY: |
94 | return TRUE; | 94 | return TRUE; |
95 | case 0: | 95 | case 0: |
96 | pthread_mutex_unlock( &mutex ); | 96 | pthread_mutex_unlock( &mutex ); |
97 | default: | 97 | default: |
98 | return FALSE; | 98 | return FALSE; |
99 | } | 99 | } |
100 | } | 100 | } |
101 | */ | 101 | */ |
102 | private: | 102 | private: |
103 | pthread_mutex_t mutex; | 103 | pthread_mutex_t mutex; |
104 | }; | 104 | }; |
105 | 105 | ||
106 | 106 | ||
107 | class currentFrameObj { | 107 | class currentFrameObj { |
108 | public: | 108 | public: |
109 | currentFrameObj() : value( 0 ) { } | 109 | currentFrameObj() : value( 0 ) { } |
110 | void set( long f ) { | 110 | void set( long f ) { |
111 | mutex.lock(); | 111 | mutex.lock(); |
112 | value = f; | 112 | value = f; |
113 | mediaPlayerState->curDecoder()->videoSetFrame( f, 0 ); | 113 | mediaPlayerState->curDecoder()->videoSetFrame( f, 0 ); |
114 | mutex.unlock(); | 114 | mutex.unlock(); |
115 | } | 115 | } |
116 | long get() { | 116 | long get() { |
117 | return value; | 117 | return value; |
118 | } | 118 | } |
119 | private: | 119 | private: |
120 | long value; | 120 | long value; |
121 | Mutex mutex; | 121 | Mutex mutex; |
122 | }; | 122 | }; |
123 | 123 | ||
124 | 124 | ||
125 | Mutex *videoMutex; | 125 | Mutex *videoMutex; |
126 | Mutex *audioMutex; | 126 | Mutex *audioMutex; |
127 | Mutex *globalMutex; | 127 | Mutex *globalMutex; |
128 | 128 | ||
129 | 129 | ||
130 | clock_tbegin; | 130 | clock_tbegin; |
131 | 131 | ||
132 | 132 | ||
133 | LoopControl::LoopControl( QObject *parent, const char *name ) | 133 | LoopControl::LoopControl( QObject *parent, const char *name ) |
134 | : QObject( parent, name ) { | 134 | : QObject( parent, name ) { |
135 | isMuted = FALSE; | 135 | isMuted = FALSE; |
136 | connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( setMute(bool) ) ); | 136 | connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( setMute(bool) ) ); |
137 | timerid = startTimer( 200 ); | 137 | timerid = startTimer( 200 ); |
138 | videoMutex = new Mutex; | 138 | videoMutex = new Mutex; |
139 | audioMutex = new Mutex; | 139 | audioMutex = new Mutex; |
140 | globalMutex = new Mutex; | 140 | globalMutex = new Mutex; |
141 | //begin = clock(); | 141 | //begin = clock(); |
142 | } | 142 | } |
143 | 143 | ||
144 | 144 | ||
145 | LoopControl::~LoopControl() { | 145 | LoopControl::~LoopControl() { |
146 | stop(); | 146 | stop(); |
147 | killTimer( timerid ); | 147 | killTimer( timerid ); |
148 | } | 148 | } |
149 | 149 | ||
150 | 150 | ||
151 | static bool sendingNewPos = FALSE; | 151 | static bool sendingNewPos = FALSE; |
152 | static long prev_frame = 0; | 152 | static long prev_frame = 0; |
153 | static int currentSample = 0; | 153 | static int currentSample = 0; |
154 | 154 | ||
155 | 155 | ||
156 | void LoopControl::timerEvent( QTimerEvent* ) { | 156 | void LoopControl::timerEvent( QTimerEvent* ) { |
157 | // We need to emit playFinished from the main thread, not one of the | 157 | // We need to emit playFinished from the main thread, not one of the |
158 | // decoding threads else we'll have all kinds of yucky things happen (reentrance). | 158 | // decoding threads else we'll have all kinds of yucky things happen (reentrance). |
159 | // playFinished will eventually call stop() which stops these threads. | 159 | // playFinished will eventually call stop() which stops these threads. |
160 | if ( emitPlayFinished ) { | 160 | if ( emitPlayFinished ) { |
161 | emitPlayFinished = FALSE; | 161 | emitPlayFinished = FALSE; |
162 | mediaPlayerState->setPlaying( FALSE ); | 162 | mediaPlayerState->setPlaying( FALSE ); |
163 | } | 163 | } |
164 | 164 | ||
165 | if ( emitChangePos ) { | 165 | if ( emitChangePos ) { |
166 | 166 | ||
167 | emitChangePos = FALSE; | 167 | emitChangePos = FALSE; |
168 | 168 | ||
169 | if ( hasVideoChannel && hasAudioChannel ) { | 169 | if ( hasVideoChannel && hasAudioChannel ) { |
170 | sendingNewPos = TRUE; | 170 | sendingNewPos = TRUE; |