author | simon <simon> | 2002-12-10 23:24:48 (UTC) |
---|---|---|
committer | simon <simon> | 2002-12-10 23:24:48 (UTC) |
commit | 7f4bd526d59aacbf750e9ee58337b6cf640ba28b (patch) (unidiff) | |
tree | 162f849f529cefe24ff5c6f9c0bdceee0cde772c | |
parent | 763b6ad10dbb7a23c446347cb7fb88cfbadd3e27 (diff) | |
download | opie-7f4bd526d59aacbf750e9ee58337b6cf640ba28b.zip opie-7f4bd526d59aacbf750e9ee58337b6cf640ba28b.tar.gz opie-7f4bd526d59aacbf750e9ee58337b6cf640ba28b.tar.bz2 |
- added an m_initialized flag and a guard for it, along with an
assertion method called from all methods that access variables depending
on initialization (basically all :)
-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 | |||
@@ -1,307 +1,372 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | 3 | ||
4 | Copyright (c) 2002 Max Reiss <harlekin@handhelds.org> | 4 | Copyright (c) 2002 Max Reiss <harlekin@handhelds.org> |
5 | Copyright (c) 2002 LJP <> | 5 | Copyright (c) 2002 LJP <> |
6 | Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> | 6 | Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> |
7 | =. | 7 | =. |
8 | .=l. | 8 | .=l. |
9 | .>+-= | 9 | .>+-= |
10 | _;:, .> :=|. This program is free software; you can | 10 | _;:, .> :=|. This program is free software; you can |
11 | .> <`_, > . <= redistribute it and/or modify it under | 11 | .> <`_, > . <= redistribute it and/or modify it under |
12 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | 12 | :`=1 )Y*s>-.-- : the terms of the GNU General Public |
13 | .="- .-=="i, .._ License as published by the Free Software | 13 | .="- .-=="i, .._ License as published by the Free Software |
14 | - . .-<_> .<> Foundation; either version 2 of the License, | 14 | - . .-<_> .<> Foundation; either version 2 of the License, |
15 | ._= =} : or (at your option) any later version. | 15 | ._= =} : or (at your option) any later version. |
16 | .%`+i> _;_. | 16 | .%`+i> _;_. |
17 | .i_,=:_. -<s. This program is distributed in the hope that | 17 | .i_,=:_. -<s. This program is distributed in the hope that |
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 | #include <stdio.h> |
35 | #include <stdlib.h> | 35 | #include <stdlib.h> |
36 | #include <qimage.h> | 36 | #include <qimage.h> |
37 | #include <qtextstream.h> | 37 | #include <qtextstream.h> |
38 | #include <qpe/resource.h> | 38 | #include <qpe/resource.h> |
39 | 39 | ||
40 | #include <qfile.h> | 40 | #include <qfile.h> |
41 | #include <qdir.h> | 41 | #include <qdir.h> |
42 | 42 | ||
43 | #include <qgfx_qws.h> | 43 | #include <qgfx_qws.h> |
44 | #include <qdirectpainter_qws.h> | 44 | #include <qdirectpainter_qws.h> |
45 | 45 | ||
46 | #include <assert.h> | 46 | #include <assert.h> |
47 | 47 | ||
48 | #include "xinevideowidget.h" | 48 | #include "xinevideowidget.h" |
49 | #include "frame.h" | 49 | #include "frame.h" |
50 | #include "lib.h" | 50 | #include "lib.h" |
51 | 51 | ||
52 | 52 | ||
53 | typedef void (*display_xine_frame_t) (void *user_data, uint8_t* frame, | 53 | typedef void (*display_xine_frame_t) (void *user_data, uint8_t* frame, |
54 | int width, int height,int bytes ); | 54 | int width, int height,int bytes ); |
55 | 55 | ||
56 | extern "C" { | 56 | extern "C" { |
57 | xine_vo_driver_t* init_video_out_plugin( xine_t *xine, void* video, display_xine_frame_t, void * ); | 57 | xine_vo_driver_t* init_video_out_plugin( xine_t *xine, void* video, display_xine_frame_t, void * ); |
58 | int null_is_showing_video( const xine_vo_driver_t* self ); | 58 | int null_is_showing_video( const xine_vo_driver_t* self ); |
59 | void null_set_show_video( const xine_vo_driver_t* self, int show ); | 59 | void null_set_show_video( const xine_vo_driver_t* self, int show ); |
60 | int null_is_fullscreen( const xine_vo_driver_t* self ); | 60 | int null_is_fullscreen( const xine_vo_driver_t* self ); |
61 | void null_set_fullscreen( const xine_vo_driver_t* self, int screen ); | 61 | void null_set_fullscreen( const xine_vo_driver_t* self, int screen ); |
62 | int null_is_scaling( const xine_vo_driver_t* self ); | 62 | int null_is_scaling( const xine_vo_driver_t* self ); |
63 | void null_set_scaling( const xine_vo_driver_t* self, int scale ); | 63 | 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 ); | 64 | 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 ); | 65 | 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 ); | 66 | 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 ); | 67 | 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 ); | 68 | void null_display_handler( const xine_vo_driver_t* self, display_xine_frame_t t, void* user_data ); |
69 | } | 69 | } |
70 | 70 | ||
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"); |
77 | QString configPath = QDir::homeDirPath() + "/Settings/opiexine.cf"; | 78 | QString configPath = QDir::homeDirPath() + "/Settings/opiexine.cf"; |
78 | // get the configuration | 79 | // get the configuration |
79 | 80 | ||
80 | // not really OO, should be an extra class, later | 81 | // not really OO, should be an extra class, later |
81 | if ( !QFile::exists(configPath) ) { | 82 | if ( !QFile::exists(configPath) ) { |
82 | QFile f(configPath); | 83 | QFile f(configPath); |
83 | f.open(IO_WriteOnly); | 84 | f.open(IO_WriteOnly); |
84 | QTextStream ts( &f ); | 85 | QTextStream ts( &f ); |
85 | ts << "misc.memcpy_method:glibc\n"; | 86 | ts << "misc.memcpy_method:glibc\n"; |
86 | f.close(); | 87 | f.close(); |
87 | } | 88 | } |
88 | 89 | ||
89 | initialize(); | 90 | initialize(); |
90 | } | 91 | } |
91 | 92 | ||
92 | void Lib::initialize() | 93 | void Lib::initialize() |
93 | { | 94 | { |
94 | m_xine = xine_new( ); | 95 | m_xine = xine_new( ); |
95 | 96 | ||
96 | QString configPath = QDir::homeDirPath() + "/Settings/opiexine.cf"; | 97 | QString configPath = QDir::homeDirPath() + "/Settings/opiexine.cf"; |
97 | xine_config_load( m_xine, QFile::encodeName( configPath ) ); | 98 | xine_config_load( m_xine, QFile::encodeName( configPath ) ); |
98 | 99 | ||
99 | xine_init( m_xine ); | 100 | xine_init( m_xine ); |
100 | 101 | ||
101 | // allocate oss for sound | 102 | // allocate oss for sound |
102 | // and fb for framebuffer | 103 | // and fb for framebuffer |
103 | m_audioOutput = xine_open_audio_driver( m_xine, "oss", NULL ); | 104 | m_audioOutput = xine_open_audio_driver( m_xine, "oss", NULL ); |
104 | m_videoOutput = ::init_video_out_plugin( m_xine, NULL, xine_display_frame, this ); | 105 | m_videoOutput = ::init_video_out_plugin( m_xine, NULL, xine_display_frame, this ); |
105 | 106 | ||
106 | 107 | ||
107 | //xine_open_video_driver( m_xine, NULL, XINE_VISUAL_TYPE_FB, NULL); | 108 | //xine_open_video_driver( m_xine, NULL, XINE_VISUAL_TYPE_FB, NULL); |
108 | 109 | ||
109 | 110 | ||
110 | // null_display_handler( m_videoOutput, xine_display_frame, this ); | 111 | // null_display_handler( m_videoOutput, xine_display_frame, this ); |
111 | 112 | ||
112 | m_stream = xine_stream_new (m_xine, m_audioOutput, m_videoOutput ); | 113 | m_stream = xine_stream_new (m_xine, m_audioOutput, m_videoOutput ); |
113 | 114 | ||
114 | if (m_wid != 0 ) { | 115 | if (m_wid != 0 ) { |
115 | printf( "!0\n" ); | 116 | printf( "!0\n" ); |
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 ); |
132 | 138 | ||
133 | xine_event_dispose_queue( m_queue ); | 139 | xine_event_dispose_queue( m_queue ); |
134 | 140 | ||
135 | xine_dispose( m_stream ); | 141 | xine_dispose( m_stream ); |
136 | 142 | ||
137 | xine_exit( m_xine ); | 143 | xine_exit( m_xine ); |
138 | /* FIXME either free or delete but valgrind bitches against both */ | 144 | /* FIXME either free or delete but valgrind bitches against both */ |
139 | //free( m_videoOutput ); | 145 | //free( m_videoOutput ); |
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() ); |
146 | ::null_set_gui_height( m_videoOutput, s. height() ); | 163 | ::null_set_gui_height( m_videoOutput, s. height() ); |
147 | } | 164 | } |
148 | } | 165 | } |
149 | 166 | ||
150 | int Lib::majorVersion() { | 167 | int Lib::majorVersion() { |
151 | int major, minor, sub; | 168 | int major, minor, sub; |
152 | xine_get_version ( &major, &minor, &sub ); | 169 | xine_get_version ( &major, &minor, &sub ); |
153 | return major; | 170 | return major; |
154 | } | 171 | } |
155 | 172 | ||
156 | int Lib::minorVersion() { | 173 | int Lib::minorVersion() { |
157 | int major, minor, sub; | 174 | int major, minor, sub; |
158 | xine_get_version ( &major, &minor, &sub ); | 175 | xine_get_version ( &major, &minor, &sub ); |
159 | return minor; | 176 | return minor; |
160 | } | 177 | } |
161 | 178 | ||
162 | int Lib::subVersion() { | 179 | int Lib::subVersion() { |
163 | int major, minor, sub; | 180 | int major, minor, sub; |
164 | xine_get_version ( &major, &minor, &sub ); | 181 | xine_get_version ( &major, &minor, &sub ); |
165 | return sub; | 182 | return sub; |
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; |
172 | } | 191 | } |
173 | return xine_play( m_stream, startPos, start_time); | 192 | return xine_play( m_stream, startPos, 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 ); |
223 | } | 262 | } |
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 | ||
239 | void Lib::receiveMessage( ThreadUtil::ChannelMessage *msg, SendType sendType ) | 284 | void Lib::receiveMessage( ThreadUtil::ChannelMessage *msg, SendType sendType ) |
240 | { | 285 | { |
241 | assert( sendType == ThreadUtil::Channel::OneWay ); | 286 | assert( sendType == ThreadUtil::Channel::OneWay ); |
242 | handleXineEvent( msg->type() ); | 287 | handleXineEvent( msg->type() ); |
243 | delete msg; | 288 | delete msg; |
244 | } | 289 | } |
245 | 290 | ||
246 | void Lib::handleXineEvent( const xine_event_t* t ) { | 291 | void Lib::handleXineEvent( const xine_event_t* t ) { |
247 | send( new ThreadUtil::ChannelMessage( t->type ), OneWay ); | 292 | send( new ThreadUtil::ChannelMessage( t->type ), OneWay ); |
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 | } |
254 | } | 301 | } |
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 | ||
292 | void Lib::xine_event_handler( void* user_data, const xine_event_t* t ) { | 355 | void Lib::xine_event_handler( void* user_data, const xine_event_t* t ) { |
293 | ( (Lib*)user_data)->handleXineEvent( t ); | 356 | ( (Lib*)user_data)->handleXineEvent( t ); |
294 | } | 357 | } |
295 | 358 | ||
296 | void Lib::xine_display_frame( void* user_data, uint8_t *frame, | 359 | void Lib::xine_display_frame( void* user_data, uint8_t *frame, |
297 | int width, int height, int bytes ) { | 360 | int width, int height, int bytes ) { |
298 | ( (Lib*)user_data)->drawFrame( frame, width, height, bytes ); | 361 | ( (Lib*)user_data)->drawFrame( frame, width, height, bytes ); |
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; |
305 | } | 370 | } |
306 | m_wid-> setVideoFrame ( frame, width, height, bytes ); | 371 | m_wid-> setVideoFrame ( frame, width, height, bytes ); |
307 | } | 372 | } |
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 | |||
@@ -1,207 +1,212 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | 3 | ||
4 | Copyright (c) 2002 Max Reiss <harlekin@handhelds.org> | 4 | Copyright (c) 2002 Max Reiss <harlekin@handhelds.org> |
5 | Copyright (c) 2002 LJP <> | 5 | Copyright (c) 2002 LJP <> |
6 | Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> | 6 | Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> |
7 | =. | 7 | =. |
8 | .=l. | 8 | .=l. |
9 | .>+-= | 9 | .>+-= |
10 | _;:, .> :=|. This program is free software; you can | 10 | _;:, .> :=|. This program is free software; you can |
11 | .> <`_, > . <= redistribute it and/or modify it under | 11 | .> <`_, > . <= redistribute it and/or modify it under |
12 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | 12 | :`=1 )Y*s>-.-- : the terms of the GNU General Public |
13 | .="- .-=="i, .._ License as published by the Free Software | 13 | .="- .-=="i, .._ License as published by the Free Software |
14 | - . .-<_> .<> Foundation; either version 2 of the License, | 14 | - . .-<_> .<> Foundation; either version 2 of the License, |
15 | ._= =} : or (at your option) any later version. | 15 | ._= =} : or (at your option) any later version. |
16 | .%`+i> _;_. | 16 | .%`+i> _;_. |
17 | .i_,=:_. -<s. This program is distributed in the hope that | 17 | .i_,=:_. -<s. This program is distributed in the hope that |
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 | #ifndef ZECKEXINELIB_H | 34 | #ifndef ZECKEXINELIB_H |
35 | #define ZECKEXINELIB_H | 35 | #define ZECKEXINELIB_H |
36 | 36 | ||
37 | #include <qcstring.h> | 37 | #include <qcstring.h> |
38 | #include <qstring.h> | 38 | #include <qstring.h> |
39 | #include <qobject.h> | 39 | #include <qobject.h> |
40 | 40 | ||
41 | #include <xine.h> | 41 | #include <xine.h> |
42 | //#include "xine.h" | 42 | //#include "xine.h" |
43 | 43 | ||
44 | #include "threadutil.h" | 44 | #include "threadutil.h" |
45 | 45 | ||
46 | class XineVideoWidget; | 46 | class XineVideoWidget; |
47 | 47 | ||
48 | namespace XINE { | 48 | namespace XINE { |
49 | 49 | ||
50 | /** | 50 | /** |
51 | * Lib wrapps the simple interface | 51 | * Lib wrapps the simple interface |
52 | * of libxine for easy every day use | 52 | * of libxine for easy every day use |
53 | * This will become a full C++ Wrapper | 53 | * This will become a full C++ Wrapper |
54 | * It supports playing, pausing, info, | 54 | * It supports playing, pausing, info, |
55 | * stooping, seeking. | 55 | * stooping, seeking. |
56 | */ | 56 | */ |
57 | class Frame; | 57 | class Frame; |
58 | class Lib : public ThreadUtil::Channel { | 58 | class Lib : public ThreadUtil::Channel { |
59 | Q_OBJECT | 59 | Q_OBJECT |
60 | public: | 60 | public: |
61 | Lib(XineVideoWidget* = 0); | 61 | Lib(XineVideoWidget* = 0); |
62 | ~Lib(); | 62 | ~Lib(); |
63 | static int majorVersion(); | 63 | static int majorVersion(); |
64 | static int minorVersion(); | 64 | static int minorVersion(); |
65 | static int subVersion(); | 65 | static int subVersion(); |
66 | 66 | ||
67 | 67 | ||
68 | void resize ( const QSize &s ); | 68 | void resize ( const QSize &s ); |
69 | 69 | ||
70 | int play( const QString& fileName, | 70 | int play( const QString& fileName, |
71 | int startPos = 0, | 71 | int startPos = 0, |
72 | int start_time = 0 ); | 72 | int start_time = 0 ); |
73 | void stop(); | 73 | void stop(); |
74 | void pause( bool toggle ); | 74 | void pause( bool toggle ); |
75 | 75 | ||
76 | int speed() const; | 76 | int speed() const; |
77 | 77 | ||
78 | /** | 78 | /** |
79 | * Set the speed of the stream, if codec supports it | 79 | * Set the speed of the stream, if codec supports it |
80 | * XINE_SPEED_PAUSE 0 | 80 | * XINE_SPEED_PAUSE 0 |
81 | * XINE_SPEED_SLOW_4 1 | 81 | * XINE_SPEED_SLOW_4 1 |
82 | * XINE_SPEED_SLOW_2 2 | 82 | * XINE_SPEED_SLOW_2 2 |
83 | * XINE_SPEED_NORMAL 4 | 83 | * XINE_SPEED_NORMAL 4 |
84 | * XINE_SPEED_FAST_2 8 | 84 | * XINE_SPEED_FAST_2 8 |
85 | *XINE_SPEED_FAST_4 16 | 85 | *XINE_SPEED_FAST_4 16 |
86 | */ | 86 | */ |
87 | void setSpeed( int speed = XINE_SPEED_PAUSE ); | 87 | void setSpeed( int speed = XINE_SPEED_PAUSE ); |
88 | 88 | ||
89 | int status() const; | 89 | int status() const; |
90 | 90 | ||
91 | int currentPosition()const; | 91 | int currentPosition()const; |
92 | //in seconds | 92 | //in seconds |
93 | int currentTime()const; | 93 | int currentTime()const; |
94 | 94 | ||
95 | int length() const; | 95 | int length() const; |
96 | 96 | ||
97 | bool isSeekable()const; | 97 | bool isSeekable()const; |
98 | 98 | ||
99 | /** | 99 | /** |
100 | * Whether or not to show video output | 100 | * Whether or not to show video output |
101 | */ | 101 | */ |
102 | void setShowVideo(bool video); | 102 | void setShowVideo(bool video); |
103 | 103 | ||
104 | /** | 104 | /** |
105 | * is we show video | 105 | * is we show video |
106 | */ | 106 | */ |
107 | bool isShowingVideo() const; | 107 | bool isShowingVideo() const; |
108 | 108 | ||
109 | /** | 109 | /** |
110 | * | 110 | * |
111 | */ | 111 | */ |
112 | void showVideoFullScreen( bool fullScreen ); | 112 | void showVideoFullScreen( bool fullScreen ); |
113 | 113 | ||
114 | /** | 114 | /** |
115 | * | 115 | * |
116 | */ | 116 | */ |
117 | bool isVideoFullScreen() const; | 117 | bool isVideoFullScreen() const; |
118 | 118 | ||
119 | 119 | ||
120 | /** | 120 | /** |
121 | * Get the meta info (like author etc) from the stream | 121 | * Get the meta info (like author etc) from the stream |
122 | * XINE_META_INFO_TITLE 0 | 122 | * XINE_META_INFO_TITLE 0 |
123 | * XINE_META_INFO_COMMENT 1 | 123 | * XINE_META_INFO_COMMENT 1 |
124 | * XINE_META_INFO_ARTIST 2 | 124 | * XINE_META_INFO_ARTIST 2 |
125 | * XINE_META_INFO_GENRE 3 | 125 | * XINE_META_INFO_GENRE 3 |
126 | * XINE_META_INFO_ALBUM 4 | 126 | * XINE_META_INFO_ALBUM 4 |
127 | * XINE_META_INFO_YEAR 5 | 127 | * XINE_META_INFO_YEAR 5 |
128 | * XINE_META_INFO_VIDEOCODEC 6 | 128 | * XINE_META_INFO_VIDEOCODEC 6 |
129 | * XINE_META_INFO_AUDIOCODEC 7 | 129 | * XINE_META_INFO_AUDIOCODEC 7 |
130 | * XINE_META_INFO_SYSTEMLAYER 8 | 130 | * XINE_META_INFO_SYSTEMLAYER 8 |
131 | * XINE_META_INFO_INPUT_PLUGIN 9 | 131 | * XINE_META_INFO_INPUT_PLUGIN 9 |
132 | */ | 132 | */ |
133 | QString metaInfo( int number ) const; | 133 | QString metaInfo( int number ) const; |
134 | 134 | ||
135 | /** | 135 | /** |
136 | * | 136 | * |
137 | */ | 137 | */ |
138 | bool isScaling() const; | 138 | bool isScaling() const; |
139 | 139 | ||
140 | /** | 140 | /** |
141 | * seek to a position | 141 | * seek to a position |
142 | */ | 142 | */ |
143 | void seekTo( int time ); | 143 | void seekTo( int time ); |
144 | 144 | ||
145 | /** | 145 | /** |
146 | * | 146 | * |
147 | * @return is media stream has video | 147 | * @return is media stream has video |
148 | */ | 148 | */ |
149 | bool hasVideo() const; | 149 | bool hasVideo() const; |
150 | 150 | ||
151 | /** | 151 | /** |
152 | * | 152 | * |
153 | */ | 153 | */ |
154 | void setScaling( bool ); | 154 | void setScaling( bool ); |
155 | 155 | ||
156 | /** | 156 | /** |
157 | * Set the Gamma value for video output | 157 | * Set the Gamma value for video output |
158 | * @param int the value between -100 and 100, 0 is original | 158 | * @param int the value between -100 and 100, 0 is original |
159 | */ | 159 | */ |
160 | void setGamma( int ); | 160 | void setGamma( int ); |
161 | 161 | ||
162 | /** | 162 | /** |
163 | * test | 163 | * test |
164 | */ | 164 | */ |
165 | Frame currentFrame() const; | 165 | Frame currentFrame() const; |
166 | 166 | ||
167 | /** | 167 | /** |
168 | * Returns the error code | 168 | * Returns the error code |
169 | * XINE_ERROR_NONE 0 | 169 | * XINE_ERROR_NONE 0 |
170 | * XINE_ERROR_NO_INPUT_PLUGIN 1 | 170 | * XINE_ERROR_NO_INPUT_PLUGIN 1 |
171 | * XINE_ERROR_NO_DEMUXER_PLUGIN 2 | 171 | * XINE_ERROR_NO_DEMUXER_PLUGIN 2 |
172 | * XINE_ERROR_DEMUXER_FAILED 3 | 172 | * XINE_ERROR_DEMUXER_FAILED 3 |
173 | */ | 173 | */ |
174 | int error() const; | 174 | int error() const; |
175 | 175 | ||
176 | signals: | 176 | signals: |
177 | 177 | ||
178 | void stopped(); | 178 | void stopped(); |
179 | 179 | ||
180 | protected: | 180 | protected: |
181 | virtual void receiveMessage( ThreadUtil::ChannelMessage *msg, SendType sendType ); | 181 | virtual void receiveMessage( ThreadUtil::ChannelMessage *msg, SendType sendType ); |
182 | 182 | ||
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; |
189 | xine_t *m_xine; | 194 | xine_t *m_xine; |
190 | xine_stream_t *m_stream; | 195 | xine_stream_t *m_stream; |
191 | xine_cfg_entry_t *m_config; | 196 | xine_cfg_entry_t *m_config; |
192 | xine_vo_driver_t *m_videoOutput; | 197 | xine_vo_driver_t *m_videoOutput; |
193 | xine_ao_driver_t* m_audioOutput; | 198 | xine_ao_driver_t* m_audioOutput; |
194 | xine_event_queue_t *m_queue; | 199 | xine_event_queue_t *m_queue; |
195 | 200 | ||
196 | void handleXineEvent( const xine_event_t* t ); | 201 | void handleXineEvent( const xine_event_t* t ); |
197 | void handleXineEvent( int type ); | 202 | void handleXineEvent( int type ); |
198 | void drawFrame( uint8_t* frame, int width, int height, int bytes ); | 203 | void drawFrame( uint8_t* frame, int width, int height, int bytes ); |
199 | // C -> C++ bridge for the event system | 204 | // C -> C++ bridge for the event system |
200 | static void xine_event_handler( void* user_data, const xine_event_t* t); | 205 | static void xine_event_handler( void* user_data, const xine_event_t* t); |
201 | static void xine_display_frame( void* user_data, uint8_t* frame , | 206 | static void xine_display_frame( void* user_data, uint8_t* frame , |
202 | int width, int height, int bytes ); | 207 | int width, int height, int bytes ); |
203 | }; | 208 | }; |
204 | }; | 209 | }; |
205 | 210 | ||
206 | 211 | ||
207 | #endif | 212 | #endif |