Diffstat (limited to 'noncore/multimedia/opieplayer2/lib.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/multimedia/opieplayer2/lib.cpp | 39 |
1 files changed, 9 insertions, 30 deletions
diff --git a/noncore/multimedia/opieplayer2/lib.cpp b/noncore/multimedia/opieplayer2/lib.cpp index 248221b..8afb318 100644 --- a/noncore/multimedia/opieplayer2/lib.cpp +++ b/noncore/multimedia/opieplayer2/lib.cpp | |||
@@ -109,220 +109,200 @@ Lib::Lib( InitializationMode initMode, XineVideoWidget* widget ) | |||
109 | 109 | ||
110 | void Lib::run() | 110 | void Lib::run() |
111 | { | 111 | { |
112 | odebug << "Lib::run() started" << oendl; | 112 | odebug << "Lib::run() started" << oendl; |
113 | initialize(); | 113 | initialize(); |
114 | m_initialized = true; | 114 | m_initialized = true; |
115 | odebug << "Lib::run() finished" << oendl; | 115 | odebug << "Lib::run() finished" << oendl; |
116 | } | 116 | } |
117 | 117 | ||
118 | void Lib::initialize() | 118 | void Lib::initialize() |
119 | { | 119 | { |
120 | m_duringInitialization = true; | 120 | m_duringInitialization = true; |
121 | m_xine = xine_new( ); | 121 | m_xine = xine_new( ); |
122 | 122 | ||
123 | QString configPath = QDir::homeDirPath() + "/Settings/opiexine.cf"; | 123 | QString configPath = QDir::homeDirPath() + "/Settings/opiexine.cf"; |
124 | xine_config_load( m_xine, QFile::encodeName( configPath ) ); | 124 | xine_config_load( m_xine, QFile::encodeName( configPath ) ); |
125 | 125 | ||
126 | xine_init( m_xine ); | 126 | xine_init( m_xine ); |
127 | 127 | ||
128 | // allocate oss for sound | 128 | // allocate oss for sound |
129 | // and fb for framebuffer | 129 | // and fb for framebuffer |
130 | m_audioOutput = xine_open_audio_driver( m_xine, "oss", NULL ); | 130 | m_audioOutput = xine_open_audio_driver( m_xine, "oss", NULL ); |
131 | m_videoOutput = ::init_video_out_plugin( m_xine, NULL, xine_display_frame, this ); | 131 | m_videoOutput = ::init_video_out_plugin( m_xine, NULL, xine_display_frame, this ); |
132 | 132 | ||
133 | |||
134 | //xine_open_video_driver( m_xine, NULL, XINE_VISUAL_TYPE_FB, NULL); | ||
135 | |||
136 | |||
137 | // null_display_handler( m_videoOutput, xine_display_frame, this ); | ||
138 | |||
139 | m_stream = xine_stream_new (m_xine, m_audioOutput, m_videoOutput ); | 133 | m_stream = xine_stream_new (m_xine, m_audioOutput, m_videoOutput ); |
140 | 134 | ||
141 | if (m_wid != 0 ) { | 135 | if (m_wid != 0 ) |
142 | printf( "!0\n" ); | ||
143 | setWidget( m_wid ); | 136 | setWidget( m_wid ); |
144 | } | ||
145 | 137 | ||
146 | m_queue = xine_event_new_queue (m_stream); | ||
147 | 138 | ||
139 | m_queue = xine_event_new_queue (m_stream); | ||
148 | xine_event_create_listener_thread (m_queue, xine_event_handler, this); | 140 | xine_event_create_listener_thread (m_queue, xine_event_handler, this); |
149 | 141 | ||
150 | ::null_preload_decoders( m_stream ); | 142 | ::null_preload_decoders( m_stream ); |
151 | 143 | ||
152 | m_duringInitialization = false; | 144 | m_duringInitialization = false; |
153 | } | 145 | } |
154 | 146 | ||
155 | Lib::~Lib() { | 147 | Lib::~Lib() { |
156 | assert( isRunning() == false ); | 148 | assert( isRunning() == false ); |
157 | assert( m_initialized ); | 149 | assert( m_initialized ); |
158 | 150 | ||
159 | // free( m_config ); | 151 | // free( m_config ); |
160 | 152 | ||
161 | xine_close( m_stream ); | 153 | xine_close( m_stream ); |
162 | |||
163 | xine_event_dispose_queue( m_queue ); | 154 | xine_event_dispose_queue( m_queue ); |
164 | |||
165 | xine_dispose( m_stream ); | 155 | xine_dispose( m_stream ); |
166 | |||
167 | xine_exit( m_xine ); | 156 | xine_exit( m_xine ); |
157 | |||
168 | /* FIXME either free or delete but valgrind bitches against both */ | 158 | /* FIXME either free or delete but valgrind bitches against both */ |
169 | //free( m_videoOutput ); | 159 | //free( m_videoOutput ); |
170 | //delete m_audioOutput; | 160 | //delete m_audioOutput; |
171 | } | 161 | } |
172 | 162 | ||
173 | void Lib::resize ( const QSize &s ) { | 163 | void Lib::resize ( const QSize &s ) { |
174 | assert( m_initialized || m_duringInitialization ); | 164 | assert( m_initialized || m_duringInitialization ); |
175 | 165 | ||
176 | if ( s. width ( ) && s. height ( ) ) { | 166 | if ( s. width ( ) && s. height ( ) ) { |
177 | ::null_set_gui_width( m_videoOutput, s. width() ); | 167 | ::null_set_gui_width( m_videoOutput, s. width() ); |
178 | ::null_set_gui_height( m_videoOutput, s. height() ); | 168 | ::null_set_gui_height( m_videoOutput, s. height() ); |
179 | } | 169 | } |
180 | } | 170 | } |
181 | 171 | ||
182 | int Lib::majorVersion() { | 172 | int Lib::majorVersion() { |
183 | int major, minor, sub; | 173 | int major, minor, sub; |
184 | xine_get_version ( &major, &minor, &sub ); | 174 | xine_get_version ( &major, &minor, &sub ); |
185 | return major; | 175 | return major; |
186 | } | 176 | } |
187 | 177 | ||
188 | int Lib::minorVersion() { | 178 | int Lib::minorVersion() { |
189 | int major, minor, sub; | 179 | int major, minor, sub; |
190 | xine_get_version ( &major, &minor, &sub ); | 180 | xine_get_version ( &major, &minor, &sub ); |
191 | return minor; | 181 | return minor; |
192 | } | 182 | } |
193 | 183 | ||
194 | int Lib::subVersion() { | 184 | int Lib::subVersion() { |
195 | int major, minor, sub; | 185 | int major, minor, sub; |
196 | xine_get_version ( &major, &minor, &sub ); | 186 | xine_get_version ( &major, &minor, &sub ); |
197 | return sub; | 187 | return sub; |
198 | } | 188 | } |
199 | 189 | ||
200 | int Lib::play( const QString& fileName, int startPos, int start_time ) { | 190 | int Lib::play( const QString& fileName, int startPos, int start_time ) { |
201 | assert( m_initialized ); | 191 | assert( m_initialized ); |
202 | // FIXME actually a hack imho. Should not be needed to dispose the whole stream | ||
203 | // but without we get wrong media length reads from libxine for the second media | ||
204 | //xine_dispose ( m_stream ); | ||
205 | 192 | ||
206 | QString str = fileName.stripWhiteSpace(); | 193 | QString str = fileName.stripWhiteSpace(); |
207 | 194 | ||
208 | //m_stream = xine_stream_new (m_xine, m_audioOutput, m_videoOutput ); | ||
209 | //m_queue = xine_event_new_queue (m_stream); | ||
210 | //xine_event_create_listener_thread (m_queue, xine_event_handler, this); | ||
211 | 195 | ||
212 | if ( !xine_open( m_stream, str.utf8().data() ) ) { | 196 | if ( !xine_open( m_stream, str.utf8().data() ) ) { |
213 | return 0; | 197 | return 0; |
214 | } | 198 | } |
215 | return xine_play( m_stream, startPos, start_time); | 199 | return xine_play( m_stream, startPos, start_time); |
216 | } | 200 | } |
217 | 201 | ||
218 | void Lib::stop() { | 202 | void Lib::stop() { |
219 | assert( m_initialized ); | 203 | assert( m_initialized ); |
220 | |||
221 | odebug << "<<<<<<<< STOP IN LIB TRIGGERED >>>>>>>" << oendl; | ||
222 | xine_stop( m_stream ); | 204 | xine_stop( m_stream ); |
223 | } | 205 | } |
224 | 206 | ||
225 | void Lib::pause( bool toggle ) { | 207 | void Lib::pause( bool toggle ) { |
226 | assert( m_initialized ); | 208 | assert( m_initialized ); |
227 | 209 | ||
228 | xine_set_param( m_stream, XINE_PARAM_SPEED, toggle ? XINE_SPEED_PAUSE : XINE_SPEED_NORMAL ); | 210 | xine_set_param( m_stream, XINE_PARAM_SPEED, toggle ? XINE_SPEED_PAUSE : XINE_SPEED_NORMAL ); |
229 | } | 211 | } |
230 | 212 | ||
231 | int Lib::speed() const { | 213 | int Lib::speed() const { |
232 | assert( m_initialized ); | 214 | assert( m_initialized ); |
233 | 215 | ||
234 | return xine_get_param ( m_stream, XINE_PARAM_SPEED ); | 216 | return xine_get_param ( m_stream, XINE_PARAM_SPEED ); |
235 | } | 217 | } |
236 | 218 | ||
237 | void Lib::setSpeed( int speed ) { | 219 | void Lib::setSpeed( int speed ) { |
238 | assert( m_initialized ); | 220 | assert( m_initialized ); |
239 | 221 | ||
240 | xine_set_param ( m_stream, XINE_PARAM_SPEED, speed ); | 222 | xine_set_param ( m_stream, XINE_PARAM_SPEED, speed ); |
241 | } | 223 | } |
242 | 224 | ||
243 | int Lib::status() const { | 225 | int Lib::status() const { |
244 | assert( m_initialized ); | 226 | assert( m_initialized ); |
245 | 227 | ||
246 | return xine_get_status( m_stream ); | 228 | return xine_get_status( m_stream ); |
247 | } | 229 | } |
248 | 230 | ||
249 | int Lib::currentPosition() const { | 231 | int Lib::currentPosition() const { |
250 | assert( m_initialized ); | 232 | assert( m_initialized ); |
251 | 233 | ||
252 | int pos, time, length; | 234 | int pos, time, length; |
253 | xine_get_pos_length( m_stream, &pos, &time, &length ); | 235 | xine_get_pos_length( m_stream, &pos, &time, &length ); |
254 | return pos; | 236 | return pos; |
255 | } | 237 | } |
256 | 238 | ||
257 | int Lib::currentTime() const { | 239 | int Lib::currentTime() const { |
258 | assert( m_initialized ); | 240 | assert( m_initialized ); |
259 | 241 | ||
260 | int pos, time, length; | 242 | int pos, time, length; |
261 | xine_get_pos_length( m_stream, &pos, &time, &length ); | 243 | pos = time = length = 0; |
262 | if ( time > 0 ) { | 244 | |
245 | if ( xine_get_pos_length( m_stream, &pos, &time, &length ) ) | ||
263 | return time/1000; | 246 | return time/1000; |
264 | } else { | 247 | else |
265 | return 0; | 248 | return 0; |
266 | } | ||
267 | } | 249 | } |
268 | 250 | ||
269 | int Lib::length() const { | 251 | int Lib::length() const { |
270 | assert( m_initialized ); | 252 | assert( m_initialized ); |
271 | 253 | ||
272 | int pos, time, length; | 254 | int pos, time, length; |
273 | /* dilb: patch to solve the wrong stream length reported to the GUI*/ | 255 | /* dilb: patch to solve the wrong stream length reported to the GUI*/ |
274 | int iRetVal=0, iTestLoop=0; | 256 | int iRetVal=0, iTestLoop=0; |
275 | 257 | ||
276 | do | 258 | do |
277 | { | 259 | { |
278 | iRetVal = xine_get_pos_length( m_stream, &pos, &time, &length ); | 260 | iRetVal = xine_get_pos_length( m_stream, &pos, &time, &length ); |
279 | if (iRetVal) | 261 | if (iRetVal) |
280 | {/* if the function didn't return 0, then pos, time and length are valid.*/ | 262 | {/* if the function didn't return 0, then pos, time and length are valid.*/ |
281 | return length/1000; | 263 | return length/1000; |
282 | } | 264 | } |
283 | /*don't poll too much*/ | 265 | /*don't poll too much*/ |
284 | usleep(100000); | 266 | usleep(100000); |
285 | iTestLoop++; | 267 | iTestLoop++; |
286 | } | 268 | } |
287 | while ( iTestLoop < 10 ); /* if after 1s, we still don't have any | 269 | while ( iTestLoop < 10 ); /* if after 1s, we still don't have any |
288 | valid stream, then return -1 (this value could be used to make the stream | 270 | valid stream, then return -1 (this value could be used to make the stream |
289 | unseekable, but it should never occur!! Mr. Murphy ? :) ) */ | 271 | unseekable, but it should never occur!! Mr. Murphy ? :) ) */ |
290 | 272 | ||
291 | return -1; | 273 | return -1; |
292 | } | 274 | } |
293 | 275 | ||
294 | bool Lib::isSeekable() const { | 276 | bool Lib::isSeekable() const { |
295 | assert( m_initialized ); | 277 | assert( m_initialized ); |
296 | 278 | ||
297 | return xine_get_stream_info( m_stream, XINE_STREAM_INFO_SEEKABLE ); | 279 | return xine_get_stream_info( m_stream, XINE_STREAM_INFO_SEEKABLE ); |
298 | } | 280 | } |
299 | 281 | ||
300 | void Lib::seekTo( int time ) { | 282 | void Lib::seekTo( int time ) { |
301 | assert( m_initialized ); | 283 | assert( m_initialized ); |
302 | 284 | ||
303 | //xine_trick_mode ( m_stream, XINE_TRICK_MODE_SEEK_TO_TIME, time ); NOT IMPLEMENTED YET IN XINE :_( | ||
304 | // since its now milliseconds we need *1000 | ||
305 | xine_play( m_stream, 0, time*1000 ); | 285 | xine_play( m_stream, 0, time*1000 ); |
306 | } | 286 | } |
307 | 287 | ||
308 | 288 | ||
309 | Frame Lib::currentFrame() const { | 289 | Frame Lib::currentFrame() const { |
310 | assert( m_initialized ); | 290 | assert( m_initialized ); |
311 | 291 | ||
312 | Frame frame; | 292 | Frame frame; |
313 | return frame; | 293 | return frame; |
314 | }; | 294 | }; |
315 | 295 | ||
316 | QString Lib::metaInfo( int number) const { | 296 | QString Lib::metaInfo( int number) const { |
317 | assert( m_initialized ); | 297 | assert( m_initialized ); |
318 | 298 | ||
319 | return xine_get_meta_info( m_stream, number ); | 299 | return xine_get_meta_info( m_stream, number ); |
320 | } | 300 | } |
321 | 301 | ||
322 | int Lib::error() const { | 302 | int Lib::error() const { |
323 | assert( m_initialized ); | 303 | assert( m_initialized ); |
324 | 304 | ||
325 | return xine_get_error( m_stream ); | 305 | return xine_get_error( m_stream ); |
326 | }; | 306 | }; |
327 | 307 | ||
328 | void Lib::ensureInitialized() | 308 | void Lib::ensureInitialized() |
@@ -404,32 +384,31 @@ void Lib::setGamma( int value ) { | |||
404 | assert( m_initialized ); | 384 | assert( m_initialized ); |
405 | 385 | ||
406 | ::null_set_videoGamma( m_videoOutput, value ); | 386 | ::null_set_videoGamma( m_videoOutput, value ); |
407 | } | 387 | } |
408 | 388 | ||
409 | bool Lib::isScaling() const { | 389 | bool Lib::isScaling() const { |
410 | assert( m_initialized ); | 390 | assert( m_initialized ); |
411 | 391 | ||
412 | return ::null_is_scaling( m_videoOutput ); | 392 | return ::null_is_scaling( m_videoOutput ); |
413 | } | 393 | } |
414 | 394 | ||
415 | void Lib::xine_event_handler( void* user_data, const xine_event_t* t ) { | 395 | void Lib::xine_event_handler( void* user_data, const xine_event_t* t ) { |
416 | ( (Lib*)user_data)->handleXineEvent( t ); | 396 | ( (Lib*)user_data)->handleXineEvent( t ); |
417 | } | 397 | } |
418 | 398 | ||
419 | void Lib::xine_display_frame( void* user_data, uint8_t *frame, | 399 | void Lib::xine_display_frame( void* user_data, uint8_t *frame, |
420 | int width, int height, int bytes ) { | 400 | int width, int height, int bytes ) { |
421 | ( (Lib*)user_data)->drawFrame( frame, width, height, bytes ); | 401 | ( (Lib*)user_data)->drawFrame( frame, width, height, bytes ); |
422 | } | 402 | } |
423 | 403 | ||
424 | void Lib::drawFrame( uint8_t* frame, int width, int height, int bytes ) { | 404 | void Lib::drawFrame( uint8_t* frame, int width, int height, int bytes ) { |
425 | assert( m_initialized ); | 405 | assert( m_initialized ); |
426 | 406 | ||
427 | if ( !m_video ) { | 407 | if ( !m_video ) { |
428 | owarn << "not showing video now" << oendl; | ||
429 | return; | 408 | return; |
430 | } | 409 | } |
431 | 410 | ||
432 | assert( m_wid ); | 411 | assert( m_wid ); |
433 | 412 | ||
434 | m_wid-> setVideoFrame ( frame, width, height, bytes ); | 413 | m_wid-> setVideoFrame ( frame, width, height, bytes ); |
435 | } | 414 | } |