Diffstat (limited to 'noncore/multimedia/opieplayer2/lib.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/multimedia/opieplayer2/lib.cpp | 59 |
1 files changed, 46 insertions, 13 deletions
diff --git a/noncore/multimedia/opieplayer2/lib.cpp b/noncore/multimedia/opieplayer2/lib.cpp index d04af08..11ad745 100644 --- a/noncore/multimedia/opieplayer2/lib.cpp +++ b/noncore/multimedia/opieplayer2/lib.cpp | |||
@@ -18,39 +18,35 @@ | |||
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 <stdio.h> | 34 | |
35 | #include <stdlib.h> | ||
36 | #include <qimage.h> | ||
37 | #include <qtextstream.h> | 35 | #include <qtextstream.h> |
38 | #include <qpe/resource.h> | ||
39 | 36 | ||
40 | #include <qfile.h> | ||
41 | #include <qdir.h> | 37 | #include <qdir.h> |
42 | 38 | ||
43 | #include <qgfx_qws.h> | 39 | #include <qgfx_qws.h> |
44 | #include <qdirectpainter_qws.h> | 40 | #include <qdirectpainter_qws.h> |
45 | 41 | ||
46 | #include <assert.h> | 42 | #include <assert.h> |
47 | 43 | ||
48 | #include "xinevideowidget.h" | 44 | #include "xinevideowidget.h" |
49 | #include "frame.h" | 45 | #include "frame.h" |
50 | #include "lib.h" | 46 | #include "lib.h" |
51 | 47 | ||
52 | 48 | ||
53 | typedef void (*display_xine_frame_t) (void *user_data, uint8_t* frame, | 49 | typedef void (*display_xine_frame_t) (void *user_data, uint8_t* frame, |
54 | int width, int height,int bytes ); | 50 | int width, int height,int bytes ); |
55 | 51 | ||
56 | extern "C" { | 52 | extern "C" { |
@@ -59,48 +55,58 @@ extern "C" { | |||
59 | void null_set_show_video( const xine_vo_driver_t* self, int show ); | 55 | void null_set_show_video( const xine_vo_driver_t* self, int show ); |
60 | int null_is_fullscreen( const xine_vo_driver_t* self ); | 56 | int null_is_fullscreen( const xine_vo_driver_t* self ); |
61 | void null_set_fullscreen( const xine_vo_driver_t* self, int screen ); | 57 | void null_set_fullscreen( const xine_vo_driver_t* self, int screen ); |
62 | int null_is_scaling( const xine_vo_driver_t* self ); | 58 | int null_is_scaling( const xine_vo_driver_t* self ); |
63 | void null_set_scaling( const xine_vo_driver_t* self, int scale ); | 59 | void null_set_scaling( const xine_vo_driver_t* self, int scale ); |
64 | void null_set_gui_width( const xine_vo_driver_t* self, int width ); | 60 | void null_set_gui_width( const xine_vo_driver_t* self, int width ); |
65 | void null_set_gui_height( const xine_vo_driver_t* self, int height ); | 61 | void null_set_gui_height( const xine_vo_driver_t* self, int height ); |
66 | void null_set_mode( const xine_vo_driver_t* self, int depth, int rgb ); | 62 | void null_set_mode( const xine_vo_driver_t* self, int depth, int rgb ); |
67 | void null_set_videoGamma( const xine_vo_driver_t* self , int value ); | 63 | void null_set_videoGamma( const xine_vo_driver_t* self , int value ); |
68 | void null_display_handler( const xine_vo_driver_t* self, display_xine_frame_t t, void* user_data ); | 64 | void null_display_handler( const xine_vo_driver_t* self, display_xine_frame_t t, void* user_data ); |
69 | 65 | ||
70 | void null_preload_decoders( xine_stream_t *stream ); | 66 | void null_preload_decoders( xine_stream_t *stream ); |
71 | } | 67 | } |
72 | 68 | ||
73 | using namespace XINE; | 69 | using namespace XINE; |
74 | 70 | ||
75 | Lib::Lib( InitializationMode initMode, XineVideoWidget* widget ) | 71 | Lib::Lib( InitializationMode initMode, XineVideoWidget* widget ) |
76 | { | 72 | { |
77 | m_initialized = false; | 73 | m_initialized = false; |
78 | m_duringInitialization = false; | 74 | m_duringInitialization = false; |
79 | m_video = false; | 75 | m_video = false; |
80 | m_wid = widget; | 76 | m_wid = widget; |
81 | printf("Lib"); | 77 | printf("Lib"); |
82 | QString configPath = QDir::homeDirPath() + "/Settings/opiexine.cf"; | 78 | QString configPath = QDir::homeDirPath() + "/Settings/opiexine.cf"; |
83 | // get the configuration | 79 | // get the configuration |
84 | 80 | ||
85 | // not really OO, should be an extra class, later | 81 | // not really OO, should be an extra class, later |
86 | if ( !QFile::exists(configPath) ) { | 82 | if ( !QFile::exists(configPath) ) { |
87 | QFile f(configPath); | 83 | QFile f(configPath); |
88 | f.open(IO_WriteOnly); | 84 | f.open(IO_WriteOnly); |
89 | QTextStream ts( &f ); | 85 | QTextStream ts( &f ); |
90 | ts << "misc.memcpy_method:glibc\n"; | 86 | ts << "misc.memcpy_method:glibc\n"; |
87 | ts << "# uncomment if you experience double speed audio \n #audio.oss_sync_method:softsync\n"; | ||
88 | ts << "codec.ffmpeg_pp_quality:3\n"; | ||
89 | ts << "audio.num_buffers:50\n"; | ||
90 | ts << "audio.size_buffers:4160\n"; | ||
91 | ts << "video.num_buffers:20\n"; | ||
92 | ts << "video.size_buffers:4096\n"; | ||
93 | ts << "audio.out_num_audio_buf:16\n"; | ||
94 | ts << "audio.out_size_audio_buf:8096\n"; | ||
95 | ts << "audio.out_size_zero_buf:1024\n"; | ||
96 | ts << "audio.passthrough_offset:0\n"; | ||
91 | f.close(); | 97 | f.close(); |
92 | } | 98 | } |
93 | 99 | ||
94 | if ( initMode == InitializeImmediately ) { | 100 | if ( initMode == InitializeImmediately ) { |
95 | initialize(); | 101 | initialize(); |
96 | m_initialized = true; | 102 | m_initialized = true; |
97 | } | 103 | } |
98 | else | 104 | else |
99 | start(); | 105 | start(); |
100 | } | 106 | } |
101 | 107 | ||
102 | void Lib::run() | 108 | void Lib::run() |
103 | { | 109 | { |
104 | qDebug( "Lib::run() started" ); | 110 | qDebug( "Lib::run() started" ); |
105 | initialize(); | 111 | initialize(); |
106 | m_initialized = true; | 112 | m_initialized = true; |
@@ -126,33 +132,33 @@ void Lib::initialize() | |||
126 | //xine_open_video_driver( m_xine, NULL, XINE_VISUAL_TYPE_FB, NULL); | 132 | //xine_open_video_driver( m_xine, NULL, XINE_VISUAL_TYPE_FB, NULL); |
127 | 133 | ||
128 | 134 | ||
129 | // null_display_handler( m_videoOutput, xine_display_frame, this ); | 135 | // null_display_handler( m_videoOutput, xine_display_frame, this ); |
130 | 136 | ||
131 | m_stream = xine_stream_new (m_xine, m_audioOutput, m_videoOutput ); | 137 | m_stream = xine_stream_new (m_xine, m_audioOutput, m_videoOutput ); |
132 | 138 | ||
133 | if (m_wid != 0 ) { | 139 | if (m_wid != 0 ) { |
134 | printf( "!0\n" ); | 140 | printf( "!0\n" ); |
135 | setWidget( m_wid ); | 141 | setWidget( m_wid ); |
136 | } | 142 | } |
137 | 143 | ||
138 | m_queue = xine_event_new_queue (m_stream); | 144 | m_queue = xine_event_new_queue (m_stream); |
139 | 145 | ||
140 | xine_event_create_listener_thread (m_queue, xine_event_handler, this); | 146 | xine_event_create_listener_thread (m_queue, xine_event_handler, this); |
141 | 147 | ||
142 | ::null_preload_decoders( m_stream ); | 148 | ::null_preload_decoders( m_stream ); |
143 | 149 | ||
144 | m_duringInitialization = false; | 150 | m_duringInitialization = false; |
145 | } | 151 | } |
146 | 152 | ||
147 | Lib::~Lib() { | 153 | Lib::~Lib() { |
148 | assert( isRunning() == false ); | 154 | assert( isRunning() == false ); |
149 | assert( m_initialized ); | 155 | assert( m_initialized ); |
150 | 156 | ||
151 | // free( m_config ); | 157 | // free( m_config ); |
152 | 158 | ||
153 | xine_close( m_stream ); | 159 | xine_close( m_stream ); |
154 | 160 | ||
155 | xine_event_dispose_queue( m_queue ); | 161 | xine_event_dispose_queue( m_queue ); |
156 | 162 | ||
157 | xine_dispose( m_stream ); | 163 | xine_dispose( m_stream ); |
158 | 164 | ||
@@ -178,34 +184,42 @@ int Lib::majorVersion() { | |||
178 | } | 184 | } |
179 | 185 | ||
180 | int Lib::minorVersion() { | 186 | int Lib::minorVersion() { |
181 | int major, minor, sub; | 187 | int major, minor, sub; |
182 | xine_get_version ( &major, &minor, &sub ); | 188 | xine_get_version ( &major, &minor, &sub ); |
183 | return minor; | 189 | return minor; |
184 | } | 190 | } |
185 | 191 | ||
186 | int Lib::subVersion() { | 192 | int Lib::subVersion() { |
187 | int major, minor, sub; | 193 | int major, minor, sub; |
188 | xine_get_version ( &major, &minor, &sub ); | 194 | xine_get_version ( &major, &minor, &sub ); |
189 | return sub; | 195 | return sub; |
190 | } | 196 | } |
191 | 197 | ||
192 | int Lib::play( const QString& fileName, int startPos, int start_time ) { | 198 | int Lib::play( const QString& fileName, int startPos, int start_time ) { |
193 | assert( m_initialized ); | 199 | assert( m_initialized ); |
200 | // FIXME actually a hack imho. Should not be needed to dispose the whole stream | ||
201 | // but without we get wrong media length reads from libxine for the second media | ||
202 | //xine_dispose ( m_stream ); | ||
194 | 203 | ||
195 | QString str = fileName.stripWhiteSpace(); | 204 | QString str = fileName.stripWhiteSpace(); |
205 | |||
206 | //m_stream = xine_stream_new (m_xine, m_audioOutput, m_videoOutput ); | ||
207 | //m_queue = xine_event_new_queue (m_stream); | ||
208 | //xine_event_create_listener_thread (m_queue, xine_event_handler, this); | ||
209 | |||
196 | if ( !xine_open( m_stream, QFile::encodeName(str.utf8() ).data() ) ) { | 210 | if ( !xine_open( m_stream, QFile::encodeName(str.utf8() ).data() ) ) { |
197 | return 0; | 211 | return 0; |
198 | } | 212 | } |
199 | return xine_play( m_stream, startPos, start_time); | 213 | return xine_play( m_stream, startPos, start_time); |
200 | } | 214 | } |
201 | 215 | ||
202 | void Lib::stop() { | 216 | void Lib::stop() { |
203 | assert( m_initialized ); | 217 | assert( m_initialized ); |
204 | 218 | ||
205 | qDebug("<<<<<<<< STOP IN LIB TRIGGERED >>>>>>>"); | 219 | qDebug("<<<<<<<< STOP IN LIB TRIGGERED >>>>>>>"); |
206 | xine_stop( m_stream ); | 220 | xine_stop( m_stream ); |
207 | } | 221 | } |
208 | 222 | ||
209 | void Lib::pause( bool toggle ) { | 223 | void Lib::pause( bool toggle ) { |
210 | assert( m_initialized ); | 224 | assert( m_initialized ); |
211 | 225 | ||
@@ -230,41 +244,62 @@ int Lib::status() const { | |||
230 | return xine_get_status( m_stream ); | 244 | return xine_get_status( m_stream ); |
231 | } | 245 | } |
232 | 246 | ||
233 | int Lib::currentPosition() const { | 247 | int Lib::currentPosition() const { |
234 | assert( m_initialized ); | 248 | assert( m_initialized ); |
235 | 249 | ||
236 | int pos, time, length; | 250 | int pos, time, length; |
237 | xine_get_pos_length( m_stream, &pos, &time, &length ); | 251 | xine_get_pos_length( m_stream, &pos, &time, &length ); |
238 | return pos; | 252 | return pos; |
239 | } | 253 | } |
240 | 254 | ||
241 | int Lib::currentTime() const { | 255 | int Lib::currentTime() const { |
242 | assert( m_initialized ); | 256 | assert( m_initialized ); |
243 | 257 | ||
244 | int pos, time, length; | 258 | int pos, time, length; |
245 | xine_get_pos_length( m_stream, &pos, &time, &length ); | 259 | xine_get_pos_length( m_stream, &pos, &time, &length ); |
246 | return time/1000; | 260 | if ( time > 0 ) { |
261 | return time/1000; | ||
262 | } else { | ||
263 | return 0; | ||
264 | } | ||
247 | } | 265 | } |
248 | 266 | ||
249 | int Lib::length() const { | 267 | int Lib::length() const { |
250 | assert( m_initialized ); | 268 | assert( m_initialized ); |
251 | 269 | ||
252 | int pos, time, length; | 270 | int pos, time, length; |
253 | xine_get_pos_length( m_stream, &pos, &time, &length ); | 271 | /* dilb: patch to solve the wrong stream length reported to the GUI*/ |
254 | return length/1000; | 272 | int iRetVal=0, iTestLoop=0; |
273 | |||
274 | do | ||
275 | { | ||
276 | iRetVal = xine_get_pos_length( m_stream, &pos, &time, &length ); | ||
277 | if (iRetVal) | ||
278 | {/* if the function didn't return 0, then pos, time and length are valid.*/ | ||
279 | return length/1000; | ||
280 | } | ||
281 | /*don't poll too much*/ | ||
282 | usleep(100000); | ||
283 | iTestLoop++; | ||
284 | } | ||
285 | while ( iTestLoop < 10 ); /* if after 1s, we still don't have any | ||
286 | valid stream, then return -1 (this value could be used to make the stream | ||
287 | unseekable, but it should never occur!! Mr. Murphy ? :) ) */ | ||
288 | |||
289 | return -1; | ||
255 | } | 290 | } |
256 | 291 | ||
257 | bool Lib::isSeekable() const { | 292 | bool Lib::isSeekable() const { |
258 | assert( m_initialized ); | 293 | assert( m_initialized ); |
259 | 294 | ||
260 | return xine_get_stream_info( m_stream, XINE_STREAM_INFO_SEEKABLE ); | 295 | return xine_get_stream_info( m_stream, XINE_STREAM_INFO_SEEKABLE ); |
261 | } | 296 | } |
262 | 297 | ||
263 | void Lib::seekTo( int time ) { | 298 | void Lib::seekTo( int time ) { |
264 | assert( m_initialized ); | 299 | assert( m_initialized ); |
265 | 300 | ||
266 | //xine_trick_mode ( m_stream, XINE_TRICK_MODE_SEEK_TO_TIME, time ); NOT IMPLEMENTED YET IN XINE :_( | 301 | //xine_trick_mode ( m_stream, XINE_TRICK_MODE_SEEK_TO_TIME, time ); NOT IMPLEMENTED YET IN XINE :_( |
267 | // since its now milliseconds we need *1000 | 302 | // since its now milliseconds we need *1000 |
268 | xine_play( m_stream, 0, time*1000 ); | 303 | xine_play( m_stream, 0, time*1000 ); |
269 | } | 304 | } |
270 | 305 | ||
@@ -353,35 +388,33 @@ void Lib::showVideoFullScreen( bool fullScreen ) { | |||
353 | 388 | ||
354 | bool Lib::isVideoFullScreen() const { | 389 | bool Lib::isVideoFullScreen() const { |
355 | assert( m_initialized ); | 390 | assert( m_initialized ); |
356 | 391 | ||
357 | return ::null_is_fullscreen( m_videoOutput ); | 392 | return ::null_is_fullscreen( m_videoOutput ); |
358 | } | 393 | } |
359 | 394 | ||
360 | void Lib::setScaling( bool scale ) { | 395 | void Lib::setScaling( bool scale ) { |
361 | assert( m_initialized ); | 396 | assert( m_initialized ); |
362 | 397 | ||
363 | ::null_set_scaling( m_videoOutput, scale ); | 398 | ::null_set_scaling( m_videoOutput, scale ); |
364 | } | 399 | } |
365 | 400 | ||
366 | void Lib::setGamma( int value ) { | 401 | void Lib::setGamma( int value ) { |
367 | assert( m_initialized ); | 402 | assert( m_initialized ); |
368 | 403 | ||
369 | //qDebug( QString( "%1").arg(value) ); | 404 | ::null_set_videoGamma( m_videoOutput, value ); |
370 | /* int gammaValue = ( 100 + value ); */ | ||
371 | ::null_set_videoGamma( m_videoOutput, value ); | ||
372 | } | 405 | } |
373 | 406 | ||
374 | bool Lib::isScaling() const { | 407 | bool Lib::isScaling() const { |
375 | assert( m_initialized ); | 408 | assert( m_initialized ); |
376 | 409 | ||
377 | return ::null_is_scaling( m_videoOutput ); | 410 | return ::null_is_scaling( m_videoOutput ); |
378 | } | 411 | } |
379 | 412 | ||
380 | void Lib::xine_event_handler( void* user_data, const xine_event_t* t ) { | 413 | void Lib::xine_event_handler( void* user_data, const xine_event_t* t ) { |
381 | ( (Lib*)user_data)->handleXineEvent( t ); | 414 | ( (Lib*)user_data)->handleXineEvent( t ); |
382 | } | 415 | } |
383 | 416 | ||
384 | void Lib::xine_display_frame( void* user_data, uint8_t *frame, | 417 | void Lib::xine_display_frame( void* user_data, uint8_t *frame, |
385 | int width, int height, int bytes ) { | 418 | int width, int height, int bytes ) { |
386 | ( (Lib*)user_data)->drawFrame( frame, width, height, bytes ); | 419 | ( (Lib*)user_data)->drawFrame( frame, width, height, bytes ); |
387 | } | 420 | } |