summaryrefslogtreecommitdiff
authoralwin <alwin>2005-04-09 21:37:02 (UTC)
committer alwin <alwin>2005-04-09 21:37:02 (UTC)
commit274690da3f91a808b77a7b9bf98b6bc09a302fc9 (patch) (unidiff)
tree7f87991f04a8ad41f2178871f75ba1c2466217c8
parentaf5f26910ae74bd5446db73fd9c870d4aad94f52 (diff)
downloadopie-274690da3f91a808b77a7b9bf98b6bc09a302fc9.zip
opie-274690da3f91a808b77a7b9bf98b6bc09a302fc9.tar.gz
opie-274690da3f91a808b77a7b9bf98b6bc09a302fc9.tar.bz2
cleanup audio/videooutput the right way
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/lib.cpp2
1 files changed, 2 insertions, 0 deletions
diff --git a/noncore/multimedia/opieplayer2/lib.cpp b/noncore/multimedia/opieplayer2/lib.cpp
index 6ed4cea..9f0d448 100644
--- a/noncore/multimedia/opieplayer2/lib.cpp
+++ b/noncore/multimedia/opieplayer2/lib.cpp
@@ -29,256 +29,258 @@
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 "xinevideowidget.h" 34#include "xinevideowidget.h"
35#include "frame.h" 35#include "frame.h"
36#include "lib.h" 36#include "lib.h"
37 37
38/* OPIE */ 38/* OPIE */
39#include <opie2/odebug.h> 39#include <opie2/odebug.h>
40#include <qpe/global.h> 40#include <qpe/global.h>
41 41
42/* QT */ 42/* QT */
43#include <qtextstream.h> 43#include <qtextstream.h>
44#include <qdir.h> 44#include <qdir.h>
45#include <qgfx_qws.h> 45#include <qgfx_qws.h>
46 46
47/* STD */ 47/* STD */
48#include <assert.h> 48#include <assert.h>
49#include <unistd.h> 49#include <unistd.h>
50 50
51typedef void (*display_xine_frame_t) (void *user_data, uint8_t* frame, 51typedef void (*display_xine_frame_t) (void *user_data, uint8_t* frame,
52 int width, int height,int bytes ); 52 int width, int height,int bytes );
53 53
54extern "C" { 54extern "C" {
55 xine_vo_driver_t* init_video_out_plugin( xine_t *xine, void* video, display_xine_frame_t, void * ); 55 xine_vo_driver_t* init_video_out_plugin( xine_t *xine, void* video, display_xine_frame_t, void * );
56 int null_is_showing_video( const xine_vo_driver_t* self ); 56 int null_is_showing_video( const xine_vo_driver_t* self );
57 void null_set_show_video( const xine_vo_driver_t* self, int show ); 57 void null_set_show_video( const xine_vo_driver_t* self, int show );
58 int null_is_fullscreen( const xine_vo_driver_t* self ); 58 int null_is_fullscreen( const xine_vo_driver_t* self );
59 void null_set_fullscreen( const xine_vo_driver_t* self, int screen ); 59 void null_set_fullscreen( const xine_vo_driver_t* self, int screen );
60 int null_is_scaling( const xine_vo_driver_t* self ); 60 int null_is_scaling( const xine_vo_driver_t* self );
61 void null_set_scaling( const xine_vo_driver_t* self, int scale ); 61 void null_set_scaling( const xine_vo_driver_t* self, int scale );
62 void null_set_gui_width( const xine_vo_driver_t* self, int width ); 62 void null_set_gui_width( const xine_vo_driver_t* self, int width );
63 void null_set_gui_height( const xine_vo_driver_t* self, int height ); 63 void null_set_gui_height( const xine_vo_driver_t* self, int height );
64 void null_set_mode( const xine_vo_driver_t* self, int depth, int rgb ); 64 void null_set_mode( const xine_vo_driver_t* self, int depth, int rgb );
65 void null_set_videoGamma( const xine_vo_driver_t* self , int value ); 65 void null_set_videoGamma( const xine_vo_driver_t* self , int value );
66 void null_display_handler( const xine_vo_driver_t* self, display_xine_frame_t t, void* user_data ); 66 void null_display_handler( const xine_vo_driver_t* self, display_xine_frame_t t, void* user_data );
67 67
68 void null_preload_decoders( xine_stream_t *stream ); 68 void null_preload_decoders( xine_stream_t *stream );
69} 69}
70 70
71using namespace XINE; 71using namespace XINE;
72 72
73Lib::Lib( InitializationMode initMode, XineVideoWidget* widget ) 73Lib::Lib( InitializationMode initMode, XineVideoWidget* widget )
74{ 74{
75 m_initialized = false; 75 m_initialized = false;
76 m_duringInitialization = false; 76 m_duringInitialization = false;
77 m_video = false; 77 m_video = false;
78 m_wid = widget; 78 m_wid = widget;
79 printf("Lib"); 79 printf("Lib");
80 QString configPath = QDir::homeDirPath() + "/Settings/opiexine.cf"; 80 QString configPath = QDir::homeDirPath() + "/Settings/opiexine.cf";
81 // get the configuration 81 // get the configuration
82 82
83 // not really OO, should be an extra class, later 83 // not really OO, should be an extra class, later
84 if ( !QFile::exists(configPath) ) { 84 if ( !QFile::exists(configPath) ) {
85 QFile f(configPath); 85 QFile f(configPath);
86 f.open(IO_WriteOnly); 86 f.open(IO_WriteOnly);
87 QTextStream ts( &f ); 87 QTextStream ts( &f );
88 ts << "misc.memcpy_method:glibc\n"; 88 ts << "misc.memcpy_method:glibc\n";
89 ts << "# uncomment if you experience double speed audio \n #audio.oss_sync_method:softsync\n"; 89 ts << "# uncomment if you experience double speed audio \n #audio.oss_sync_method:softsync\n";
90 ts << "codec.ffmpeg_pp_quality:3\n"; 90 ts << "codec.ffmpeg_pp_quality:3\n";
91 ts << "audio.num_buffers:50\n"; 91 ts << "audio.num_buffers:50\n";
92 ts << "audio.size_buffers:4096\n"; 92 ts << "audio.size_buffers:4096\n";
93 ts << "video.num_buffers:20\n"; 93 ts << "video.num_buffers:20\n";
94 ts << "video.size_buffers:4096\n"; 94 ts << "video.size_buffers:4096\n";
95 ts << "audio.out_num_audio_buf:16\n"; 95 ts << "audio.out_num_audio_buf:16\n";
96 ts << "audio.out_size_audio_buf:8096\n"; 96 ts << "audio.out_size_audio_buf:8096\n";
97 ts << "audio.out_size_zero_buf:1024\n"; 97 ts << "audio.out_size_zero_buf:1024\n";
98 ts << "audio.passthrough_offset:0\n"; 98 ts << "audio.passthrough_offset:0\n";
99 f.close(); 99 f.close();
100 } 100 }
101 101
102 if ( initMode == InitializeImmediately ) { 102 if ( initMode == InitializeImmediately ) {
103 initialize(); 103 initialize();
104 m_initialized = true; 104 m_initialized = true;
105 } 105 }
106 else 106 else
107 start(); 107 start();
108} 108}
109 109
110void Lib::run() 110void 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
118void Lib::initialize() 118void 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 m_stream = xine_stream_new (m_xine, m_audioOutput, m_videoOutput ); 133 m_stream = xine_stream_new (m_xine, m_audioOutput, m_videoOutput );
134 xine_set_param( m_stream, XINE_PARAM_AUDIO_CLOSE_DEVICE, 1); 134 xine_set_param( m_stream, XINE_PARAM_AUDIO_CLOSE_DEVICE, 1);
135 135
136 if (m_wid != 0 ) 136 if (m_wid != 0 )
137 setWidget( m_wid ); 137 setWidget( m_wid );
138 138
139 139
140 m_queue = xine_event_new_queue (m_stream); 140 m_queue = xine_event_new_queue (m_stream);
141 xine_event_create_listener_thread (m_queue, xine_event_handler, this); 141 xine_event_create_listener_thread (m_queue, xine_event_handler, this);
142 142
143 ::null_preload_decoders( m_stream ); 143 ::null_preload_decoders( m_stream );
144 144
145 m_duringInitialization = false; 145 m_duringInitialization = false;
146} 146}
147 147
148Lib::~Lib() { 148Lib::~Lib() {
149 assert( isRunning() == false ); 149 assert( isRunning() == false );
150 assert( m_initialized ); 150 assert( m_initialized );
151 151
152// free( m_config ); 152// free( m_config );
153 153
154 xine_close( m_stream ); 154 xine_close( m_stream );
155 xine_event_dispose_queue( m_queue ); 155 xine_event_dispose_queue( m_queue );
156 xine_dispose( m_stream ); 156 xine_dispose( m_stream );
157 xine_close_audio_driver(m_xine,m_audioOutput);
158 xine_close_video_driver(m_xine,m_videoOutput);
157 xine_exit( m_xine ); 159 xine_exit( m_xine );
158 160
159 /* FIXME either free or delete but valgrind bitches against both */ 161 /* FIXME either free or delete but valgrind bitches against both */
160 //free( m_videoOutput ); 162 //free( m_videoOutput );
161 //delete m_audioOutput; 163 //delete m_audioOutput;
162} 164}
163 165
164void Lib::resize ( const QSize &s ) { 166void Lib::resize ( const QSize &s ) {
165 assert( m_initialized || m_duringInitialization ); 167 assert( m_initialized || m_duringInitialization );
166 168
167 if ( s. width ( ) && s. height ( ) ) { 169 if ( s. width ( ) && s. height ( ) ) {
168 ::null_set_gui_width( m_videoOutput, s. width() ); 170 ::null_set_gui_width( m_videoOutput, s. width() );
169 ::null_set_gui_height( m_videoOutput, s. height() ); 171 ::null_set_gui_height( m_videoOutput, s. height() );
170 } 172 }
171} 173}
172 174
173int Lib::majorVersion() { 175int Lib::majorVersion() {
174 int major, minor, sub; 176 int major, minor, sub;
175 xine_get_version ( &major, &minor, &sub ); 177 xine_get_version ( &major, &minor, &sub );
176 return major; 178 return major;
177} 179}
178 180
179int Lib::minorVersion() { 181int Lib::minorVersion() {
180 int major, minor, sub; 182 int major, minor, sub;
181 xine_get_version ( &major, &minor, &sub ); 183 xine_get_version ( &major, &minor, &sub );
182 return minor; 184 return minor;
183} 185}
184 186
185int Lib::subVersion() { 187int Lib::subVersion() {
186 int major, minor, sub; 188 int major, minor, sub;
187 xine_get_version ( &major, &minor, &sub ); 189 xine_get_version ( &major, &minor, &sub );
188 return sub; 190 return sub;
189} 191}
190 192
191int Lib::play( const QString& fileName, int startPos, int start_time ) { 193int Lib::play( const QString& fileName, int startPos, int start_time ) {
192 assert( m_initialized ); 194 assert( m_initialized );
193 195
194 QString str = fileName.stripWhiteSpace(); 196 QString str = fileName.stripWhiteSpace();
195 197
196 198
197 if ( !xine_open( m_stream, str.utf8().data() ) ) { 199 if ( !xine_open( m_stream, str.utf8().data() ) ) {
198 return 0; 200 return 0;
199 } 201 }
200 return xine_play( m_stream, startPos, start_time); 202 return xine_play( m_stream, startPos, start_time);
201} 203}
202 204
203void Lib::stop() { 205void Lib::stop() {
204 assert( m_initialized ); 206 assert( m_initialized );
205 xine_stop( m_stream ); 207 xine_stop( m_stream );
206 xine_set_param( m_stream, XINE_PARAM_AUDIO_CLOSE_DEVICE, 1); 208 xine_set_param( m_stream, XINE_PARAM_AUDIO_CLOSE_DEVICE, 1);
207} 209}
208 210
209void Lib::pause( bool toggle ) { 211void Lib::pause( bool toggle ) {
210 assert( m_initialized ); 212 assert( m_initialized );
211 213
212 if ( toggle ) { 214 if ( toggle ) {
213 xine_set_param( m_stream, XINE_PARAM_SPEED, XINE_SPEED_PAUSE ); 215 xine_set_param( m_stream, XINE_PARAM_SPEED, XINE_SPEED_PAUSE );
214 xine_set_param( m_stream, XINE_PARAM_AUDIO_CLOSE_DEVICE, 1); 216 xine_set_param( m_stream, XINE_PARAM_AUDIO_CLOSE_DEVICE, 1);
215 } 217 }
216 218
217 else { 219 else {
218 xine_set_param( m_stream, XINE_PARAM_SPEED, XINE_SPEED_NORMAL ); 220 xine_set_param( m_stream, XINE_PARAM_SPEED, XINE_SPEED_NORMAL );
219 } 221 }
220} 222}
221 223
222int Lib::speed() const { 224int Lib::speed() const {
223 assert( m_initialized ); 225 assert( m_initialized );
224 226
225 return xine_get_param ( m_stream, XINE_PARAM_SPEED ); 227 return xine_get_param ( m_stream, XINE_PARAM_SPEED );
226} 228}
227 229
228void Lib::setSpeed( int speed ) { 230void Lib::setSpeed( int speed ) {
229 assert( m_initialized ); 231 assert( m_initialized );
230 232
231 xine_set_param ( m_stream, XINE_PARAM_SPEED, speed ); 233 xine_set_param ( m_stream, XINE_PARAM_SPEED, speed );
232} 234}
233 235
234int Lib::status() const { 236int Lib::status() const {
235 assert( m_initialized ); 237 assert( m_initialized );
236 238
237 return xine_get_status( m_stream ); 239 return xine_get_status( m_stream );
238} 240}
239 241
240int Lib::currentPosition() const { 242int Lib::currentPosition() const {
241 assert( m_initialized ); 243 assert( m_initialized );
242 244
243 int pos, time, length; 245 int pos, time, length;
244 xine_get_pos_length( m_stream, &pos, &time, &length ); 246 xine_get_pos_length( m_stream, &pos, &time, &length );
245 return pos; 247 return pos;
246} 248}
247 249
248int Lib::currentTime() const { 250int Lib::currentTime() const {
249 assert( m_initialized ); 251 assert( m_initialized );
250 252
251 int pos, time, length; 253 int pos, time, length;
252 pos = time = length = 0; 254 pos = time = length = 0;
253 255
254 if ( xine_get_pos_length( m_stream, &pos, &time, &length ) ) 256 if ( xine_get_pos_length( m_stream, &pos, &time, &length ) )
255 return time/1000; 257 return time/1000;
256 else 258 else
257 return 0; 259 return 0;
258} 260}
259 261
260int Lib::length() const { 262int Lib::length() const {
261 assert( m_initialized ); 263 assert( m_initialized );
262 264
263 int pos, time, length; 265 int pos, time, length;
264/* dilb: patch to solve the wrong stream length reported to the GUI*/ 266/* dilb: patch to solve the wrong stream length reported to the GUI*/
265 int iRetVal=0, iTestLoop=0; 267 int iRetVal=0, iTestLoop=0;
266 268
267 do 269 do
268 { 270 {
269 iRetVal = xine_get_pos_length( m_stream, &pos, &time, &length ); 271 iRetVal = xine_get_pos_length( m_stream, &pos, &time, &length );
270 if (iRetVal) 272 if (iRetVal)
271 {/* if the function didn't return 0, then pos, time and length are valid.*/ 273 {/* if the function didn't return 0, then pos, time and length are valid.*/
272 return length/1000; 274 return length/1000;
273 } 275 }
274 /*don't poll too much*/ 276 /*don't poll too much*/
275 usleep(100000); 277 usleep(100000);
276 iTestLoop++; 278 iTestLoop++;
277 } 279 }
278 while ( iTestLoop < 10 ); /* if after 1s, we still don't have any 280 while ( iTestLoop < 10 ); /* if after 1s, we still don't have any
279valid stream, then return -1 (this value could be used to make the stream 281valid stream, then return -1 (this value could be used to make the stream
280unseekable, but it should never occur!! Mr. Murphy ? :) ) */ 282unseekable, but it should never occur!! Mr. Murphy ? :) ) */
281 283
282 return -1; 284 return -1;
283} 285}
284 286