-rw-r--r-- | noncore/multimedia/opieplayer2/lib.cpp | 67 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/lib.h | 5 |
2 files changed, 71 insertions, 1 deletions
diff --git a/noncore/multimedia/opieplayer2/lib.cpp b/noncore/multimedia/opieplayer2/lib.cpp index 641cbca..99d5de6 100644 --- a/noncore/multimedia/opieplayer2/lib.cpp +++ b/noncore/multimedia/opieplayer2/lib.cpp | |||
@@ -71,6 +71,7 @@ extern "C" { | |||
71 | using namespace XINE; | 71 | using namespace XINE; |
72 | 72 | ||
73 | Lib::Lib( XineVideoWidget* widget ) { | 73 | Lib::Lib( XineVideoWidget* widget ) { |
74 | m_initialized = false; | ||
74 | m_video = false; | 75 | m_video = false; |
75 | m_wid = widget; | 76 | m_wid = widget; |
76 | printf("Lib"); | 77 | printf("Lib"); |
@@ -116,16 +117,21 @@ void Lib::initialize() | |||
116 | resize ( m_wid-> size ( ) ); | 117 | resize ( m_wid-> size ( ) ); |
117 | ::null_set_mode( m_videoOutput, qt_screen->depth(), qt_screen->pixelType() ); | 118 | ::null_set_mode( m_videoOutput, qt_screen->depth(), qt_screen->pixelType() ); |
118 | 119 | ||
119 | m_wid->repaint(); | 120 | // m_wid->repaint(); |
120 | } | 121 | } |
121 | 122 | ||
122 | m_queue = xine_event_new_queue (m_stream); | 123 | m_queue = xine_event_new_queue (m_stream); |
123 | 124 | ||
124 | xine_event_create_listener_thread (m_queue, xine_event_handler, this); | 125 | xine_event_create_listener_thread (m_queue, xine_event_handler, this); |
125 | 126 | ||
127 | m_initialized = true; | ||
126 | } | 128 | } |
127 | 129 | ||
128 | Lib::~Lib() { | 130 | Lib::~Lib() { |
131 | ThreadUtil::AutoLock lock( m_initGuard ); | ||
132 | |||
133 | assert( m_initialized ); | ||
134 | |||
129 | // free( m_config ); | 135 | // free( m_config ); |
130 | 136 | ||
131 | xine_close( m_stream ); | 137 | xine_close( m_stream ); |
@@ -140,6 +146,17 @@ Lib::~Lib() { | |||
140 | //delete m_audioOutput; | 146 | //delete m_audioOutput; |
141 | } | 147 | } |
142 | 148 | ||
149 | void Lib::assertInitialized() const | ||
150 | { | ||
151 | ThreadUtil::AutoLock lock( m_initGuard ); | ||
152 | |||
153 | if ( m_initialized ) | ||
154 | return; | ||
155 | |||
156 | qDebug( "LibXine: xine function called while not being initialized, yet! Fix the caller!" ); | ||
157 | assert( m_initialized ); | ||
158 | } | ||
159 | |||
143 | void Lib::resize ( const QSize &s ) { | 160 | void Lib::resize ( const QSize &s ) { |
144 | if ( s. width ( ) && s. height ( ) ) { | 161 | if ( s. width ( ) && s. height ( ) ) { |
145 | ::null_set_gui_width( m_videoOutput, s. width() ); | 162 | ::null_set_gui_width( m_videoOutput, s. width() ); |
@@ -166,6 +183,8 @@ int Lib::subVersion() { | |||
166 | } | 183 | } |
167 | 184 | ||
168 | int Lib::play( const QString& fileName, int startPos, int start_time ) { | 185 | int Lib::play( const QString& fileName, int startPos, int start_time ) { |
186 | assertInitialized(); | ||
187 | |||
169 | QString str = fileName.stripWhiteSpace(); | 188 | QString str = fileName.stripWhiteSpace(); |
170 | if ( !xine_open( m_stream, QFile::encodeName(str.utf8() ).data() ) ) { | 189 | if ( !xine_open( m_stream, QFile::encodeName(str.utf8() ).data() ) ) { |
171 | return 0; | 190 | return 0; |
@@ -174,49 +193,69 @@ int Lib::play( const QString& fileName, int startPos, int start_time ) { | |||
174 | } | 193 | } |
175 | 194 | ||
176 | void Lib::stop() { | 195 | void Lib::stop() { |
196 | assertInitialized(); | ||
197 | |||
177 | qDebug("<<<<<<<< STOP IN LIB TRIGGERED >>>>>>>"); | 198 | qDebug("<<<<<<<< STOP IN LIB TRIGGERED >>>>>>>"); |
178 | xine_stop( m_stream ); | 199 | xine_stop( m_stream ); |
179 | } | 200 | } |
180 | 201 | ||
181 | void Lib::pause( bool toggle ) { | 202 | void Lib::pause( bool toggle ) { |
203 | assertInitialized(); | ||
204 | |||
182 | xine_set_param( m_stream, XINE_PARAM_SPEED, toggle ? XINE_SPEED_PAUSE : XINE_SPEED_NORMAL ); | 205 | xine_set_param( m_stream, XINE_PARAM_SPEED, toggle ? XINE_SPEED_PAUSE : XINE_SPEED_NORMAL ); |
183 | } | 206 | } |
184 | 207 | ||
185 | int Lib::speed() const { | 208 | int Lib::speed() const { |
209 | assertInitialized(); | ||
210 | |||
186 | return xine_get_param ( m_stream, XINE_PARAM_SPEED ); | 211 | return xine_get_param ( m_stream, XINE_PARAM_SPEED ); |
187 | } | 212 | } |
188 | 213 | ||
189 | void Lib::setSpeed( int speed ) { | 214 | void Lib::setSpeed( int speed ) { |
215 | assertInitialized(); | ||
216 | |||
190 | xine_set_param ( m_stream, XINE_PARAM_SPEED, speed ); | 217 | xine_set_param ( m_stream, XINE_PARAM_SPEED, speed ); |
191 | } | 218 | } |
192 | 219 | ||
193 | int Lib::status() const { | 220 | int Lib::status() const { |
221 | assertInitialized(); | ||
222 | |||
194 | return xine_get_status( m_stream ); | 223 | return xine_get_status( m_stream ); |
195 | } | 224 | } |
196 | 225 | ||
197 | int Lib::currentPosition() const { | 226 | int Lib::currentPosition() const { |
227 | assertInitialized(); | ||
228 | |||
198 | int pos, time, length; | 229 | int pos, time, length; |
199 | xine_get_pos_length( m_stream, &pos, &time, &length ); | 230 | xine_get_pos_length( m_stream, &pos, &time, &length ); |
200 | return pos; | 231 | return pos; |
201 | } | 232 | } |
202 | 233 | ||
203 | int Lib::currentTime() const { | 234 | int Lib::currentTime() const { |
235 | assertInitialized(); | ||
236 | |||
204 | int pos, time, length; | 237 | int pos, time, length; |
205 | xine_get_pos_length( m_stream, &pos, &time, &length ); | 238 | xine_get_pos_length( m_stream, &pos, &time, &length ); |
206 | return time/1000; | 239 | return time/1000; |
207 | } | 240 | } |
208 | 241 | ||
209 | int Lib::length() const { | 242 | int Lib::length() const { |
243 | assertInitialized(); | ||
244 | |||
210 | int pos, time, length; | 245 | int pos, time, length; |
211 | xine_get_pos_length( m_stream, &pos, &time, &length ); | 246 | xine_get_pos_length( m_stream, &pos, &time, &length ); |
212 | return length/1000; | 247 | return length/1000; |
213 | } | 248 | } |
214 | 249 | ||
215 | bool Lib::isSeekable() const { | 250 | bool Lib::isSeekable() const { |
251 | assertInitialized(); | ||
252 | |||
216 | return xine_get_stream_info( m_stream, XINE_STREAM_INFO_SEEKABLE ); | 253 | return xine_get_stream_info( m_stream, XINE_STREAM_INFO_SEEKABLE ); |
217 | } | 254 | } |
218 | 255 | ||
219 | void Lib::seekTo( int time ) { | 256 | void Lib::seekTo( int time ) { |
257 | assertInitialized(); | ||
258 | |||
220 | //xine_trick_mode ( m_stream, XINE_TRICK_MODE_SEEK_TO_TIME, time ); NOT IMPLEMENTED YET IN XINE :_( | 259 | //xine_trick_mode ( m_stream, XINE_TRICK_MODE_SEEK_TO_TIME, time ); NOT IMPLEMENTED YET IN XINE :_( |
221 | // since its now milliseconds we need *1000 | 260 | // since its now milliseconds we need *1000 |
222 | xine_play( m_stream, 0, time*1000 ); | 261 | xine_play( m_stream, 0, time*1000 ); |
@@ -224,15 +263,21 @@ void Lib::seekTo( int time ) { | |||
224 | 263 | ||
225 | 264 | ||
226 | Frame Lib::currentFrame() const { | 265 | Frame Lib::currentFrame() const { |
266 | assertInitialized(); | ||
267 | |||
227 | Frame frame; | 268 | Frame frame; |
228 | return frame; | 269 | return frame; |
229 | }; | 270 | }; |
230 | 271 | ||
231 | QString Lib::metaInfo( int number) const { | 272 | QString Lib::metaInfo( int number) const { |
273 | assertInitialized(); | ||
274 | |||
232 | return xine_get_meta_info( m_stream, number ); | 275 | return xine_get_meta_info( m_stream, number ); |
233 | } | 276 | } |
234 | 277 | ||
235 | int Lib::error() const { | 278 | int Lib::error() const { |
279 | assertInitialized(); | ||
280 | |||
236 | return xine_get_error( m_stream ); | 281 | return xine_get_error( m_stream ); |
237 | }; | 282 | }; |
238 | 283 | ||
@@ -248,6 +293,8 @@ void Lib::handleXineEvent( const xine_event_t* t ) { | |||
248 | } | 293 | } |
249 | 294 | ||
250 | void Lib::handleXineEvent( int type ) { | 295 | void Lib::handleXineEvent( int type ) { |
296 | assertInitialized(); | ||
297 | |||
251 | if ( type == XINE_EVENT_UI_PLAYBACK_FINISHED ) { | 298 | if ( type == XINE_EVENT_UI_PLAYBACK_FINISHED ) { |
252 | emit stopped(); | 299 | emit stopped(); |
253 | } | 300 | } |
@@ -255,37 +302,53 @@ void Lib::handleXineEvent( int type ) { | |||
255 | 302 | ||
256 | 303 | ||
257 | void Lib::setShowVideo( bool video ) { | 304 | void Lib::setShowVideo( bool video ) { |
305 | assertInitialized(); | ||
306 | |||
258 | m_video = video; | 307 | m_video = video; |
259 | ::null_set_show_video( m_videoOutput, video ); | 308 | ::null_set_show_video( m_videoOutput, video ); |
260 | } | 309 | } |
261 | 310 | ||
262 | bool Lib::isShowingVideo() const { | 311 | bool Lib::isShowingVideo() const { |
312 | assertInitialized(); | ||
313 | |||
263 | return ::null_is_showing_video( m_videoOutput ); | 314 | return ::null_is_showing_video( m_videoOutput ); |
264 | } | 315 | } |
265 | 316 | ||
266 | bool Lib::hasVideo() const { | 317 | bool Lib::hasVideo() const { |
318 | assertInitialized(); | ||
319 | |||
267 | return xine_get_stream_info( m_stream, 18 ); | 320 | return xine_get_stream_info( m_stream, 18 ); |
268 | } | 321 | } |
269 | 322 | ||
270 | void Lib::showVideoFullScreen( bool fullScreen ) { | 323 | void Lib::showVideoFullScreen( bool fullScreen ) { |
324 | assertInitialized(); | ||
325 | |||
271 | ::null_set_fullscreen( m_videoOutput, fullScreen ); | 326 | ::null_set_fullscreen( m_videoOutput, fullScreen ); |
272 | } | 327 | } |
273 | 328 | ||
274 | bool Lib::isVideoFullScreen() const { | 329 | bool Lib::isVideoFullScreen() const { |
330 | assertInitialized(); | ||
331 | |||
275 | return ::null_is_fullscreen( m_videoOutput ); | 332 | return ::null_is_fullscreen( m_videoOutput ); |
276 | } | 333 | } |
277 | 334 | ||
278 | void Lib::setScaling( bool scale ) { | 335 | void Lib::setScaling( bool scale ) { |
336 | assertInitialized(); | ||
337 | |||
279 | ::null_set_scaling( m_videoOutput, scale ); | 338 | ::null_set_scaling( m_videoOutput, scale ); |
280 | } | 339 | } |
281 | 340 | ||
282 | void Lib::setGamma( int value ) { | 341 | void Lib::setGamma( int value ) { |
342 | assertInitialized(); | ||
343 | |||
283 | //qDebug( QString( "%1").arg(value) ); | 344 | //qDebug( QString( "%1").arg(value) ); |
284 | /* int gammaValue = ( 100 + value ); */ | 345 | /* int gammaValue = ( 100 + value ); */ |
285 | ::null_set_videoGamma( m_videoOutput, value ); | 346 | ::null_set_videoGamma( m_videoOutput, value ); |
286 | } | 347 | } |
287 | 348 | ||
288 | bool Lib::isScaling() const { | 349 | bool Lib::isScaling() const { |
350 | assertInitialized(); | ||
351 | |||
289 | return ::null_is_scaling( m_videoOutput ); | 352 | return ::null_is_scaling( m_videoOutput ); |
290 | } | 353 | } |
291 | 354 | ||
@@ -299,6 +362,8 @@ void Lib::xine_display_frame( void* user_data, uint8_t *frame, | |||
299 | } | 362 | } |
300 | 363 | ||
301 | void Lib::drawFrame( uint8_t* frame, int width, int height, int bytes ) { | 364 | void Lib::drawFrame( uint8_t* frame, int width, int height, int bytes ) { |
365 | assertInitialized(); | ||
366 | |||
302 | if ( !m_video ) { | 367 | if ( !m_video ) { |
303 | qWarning("not showing video now"); | 368 | qWarning("not showing video now"); |
304 | return; | 369 | return; |
diff --git a/noncore/multimedia/opieplayer2/lib.h b/noncore/multimedia/opieplayer2/lib.h index d546c99..4b8dc81 100644 --- a/noncore/multimedia/opieplayer2/lib.h +++ b/noncore/multimedia/opieplayer2/lib.h | |||
@@ -183,6 +183,11 @@ namespace XINE { | |||
183 | private: | 183 | private: |
184 | void initialize(); | 184 | void initialize(); |
185 | 185 | ||
186 | void assertInitialized() const; | ||
187 | |||
188 | mutable ThreadUtil::Mutex m_initGuard; | ||
189 | bool m_initialized : 1; | ||
190 | |||
186 | int m_bytes_per_pixel; | 191 | int m_bytes_per_pixel; |
187 | bool m_video:1; | 192 | bool m_video:1; |
188 | XineVideoWidget *m_wid; | 193 | XineVideoWidget *m_wid; |