author | alwin <alwin> | 2005-04-02 21:55:07 (UTC) |
---|---|---|
committer | alwin <alwin> | 2005-04-02 21:55:07 (UTC) |
commit | a5020219d43b9dd788cc090ae565c28f27dd6a58 (patch) (unidiff) | |
tree | c60f0ae6554817db54e45ea2eb6b1c9896193b3e | |
parent | b92357d5566b9ee220ff5f4e8eb612b2db32e20b (diff) | |
download | opie-a5020219d43b9dd788cc090ae565c28f27dd6a58.zip opie-a5020219d43b9dd788cc090ae565c28f27dd6a58.tar.gz opie-a5020219d43b9dd788cc090ae565c28f27dd6a58.tar.bz2 |
my last try to get mediaplayer2 more stable.
-> protected the videobuffer with mutex, make a deep copy of it so xine may
destruct its internal buffers as wanted
-rw-r--r-- | noncore/multimedia/opieplayer2/xinevideowidget.cpp | 97 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/xinevideowidget.h | 52 |
2 files changed, 97 insertions, 52 deletions
diff --git a/noncore/multimedia/opieplayer2/xinevideowidget.cpp b/noncore/multimedia/opieplayer2/xinevideowidget.cpp index 9e86041..211791b 100644 --- a/noncore/multimedia/opieplayer2/xinevideowidget.cpp +++ b/noncore/multimedia/opieplayer2/xinevideowidget.cpp | |||
@@ -1,29 +1,30 @@ | |||
1 | 1 | ||
2 | /* | 2 | /* |
3 | This file is part of the Opie Project | 3 | Â Â Â Â Â Â Â Â This file is part of the Opie Project |
4 | 4 | ||
5 | Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> | 5 | Â Â Â Â Â Â Â Copyright (c) 2002 Max Reiss <harlekin@handhelds.org> |
6 | Copyright (c) 2002 L. Potter <ljp@llornkcor.com> | ||
6 | Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> | 7 | Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> |
7 | =. | 8 | =. |
8 | .=l. | 9 | .=l. |
9 | .>+-= | 10 | Â Â Â Â Â Â .>+-= |
10 | _;:, .> :=|. This program is free software; you can | 11 | Â _;:, Â Â .> Â Â :=|. This program is free software; you can |
11 | .> <`_, > . <= redistribute it and/or modify it under | 12 | .> <`_, Â > Â . Â <= redistribute it and/or modify it under |
12 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | 13 | :`=1 )Y*s>-.-- Â : the terms of the GNU General Public |
13 | .="- .-=="i, .._ License as published by the Free Software | 14 | .="- .-=="i, Â Â .._ License as published by the Free Software |
14 | - . .-<_> .<> Foundation; either version 2 of the License, | 15 | Â - . Â .-<_> Â Â .<> Foundation; either version 2 of the License, |
15 | ._= =} : or (at your option) any later version. | 16 | Â Â Â ._= =} Â Â Â : or (at your option) any later version. |
16 | .%`+i> _;_. | 17 | Â Â .%`+i> Â Â Â _;_. |
17 | .i_,=:_. -<s. This program is distributed in the hope that | 18 | Â Â .i_,=:_. Â Â Â -<s. This program is distributed in the hope that |
18 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 19 | Â Â Â + Â . Â -:. Â Â Â = it will be useful, but WITHOUT ANY WARRANTY; |
19 | : .. .:, . . . without even the implied warranty of | 20 | Â Â : .. Â Â .:, Â Â . . . without even the implied warranty of |
20 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 21 | Â Â =_ Â Â Â Â + Â Â =;=|` MERCHANTABILITY or FITNESS FOR A |
21 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 22 | Â _.=:. Â Â Â : Â Â :=>`: PARTICULAR PURPOSE. See the GNU |
22 | ..}^=.= = ; Library General Public License for more | 23 | ..}^=.= Â Â Â = Â Â Â ; Library General Public License for more |
23 | ++= -. .` .: details. | 24 | ++= Â -. Â Â .` Â Â .: details. |
24 | : = ...= . :.=- | 25 | Â : Â Â = Â ...= . :.=- |
25 | -. .:....=;==+<; You should have received a copy of the GNU | 26 | Â -. Â .:....=;==+<; You should have received a copy of the GNU |
26 | -_. . . )=. = Library General Public License along with | 27 | Â -_. . . Â )=. Â = Library General Public License along with |
27 | -- :-=` this library; see the file COPYING.LIB. | 28 | Â Â -- Â Â Â Â :-=` this library; see the file COPYING.LIB. |
28 | If not, write to the Free Software Foundation, | 29 | If not, write to the Free Software Foundation, |
29 | Inc., 59 Temple Place - Suite 330, | 30 | Inc., 59 Temple Place - Suite 330, |
@@ -32,4 +33,7 @@ | |||
32 | */ | 33 | */ |
33 | 34 | ||
35 | #include "xinevideowidget.h" | ||
36 | #include <opie2/odebug.h> | ||
37 | |||
34 | #include <qimage.h> | 38 | #include <qimage.h> |
35 | #include <qdirectpainter_qws.h> | 39 | #include <qdirectpainter_qws.h> |
@@ -40,5 +44,6 @@ | |||
40 | #include <qpe/resource.h> | 44 | #include <qpe/resource.h> |
41 | 45 | ||
42 | #include "xinevideowidget.h" | 46 | #include <pthread.h> |
47 | |||
43 | 48 | ||
44 | 49 | ||
@@ -122,4 +127,5 @@ XineVideoWidget::XineVideoWidget ( QWidget* parent, const char* name ) | |||
122 | m_bytes_per_pixel = ( qt_screen->depth() + 7 ) / 8; | 127 | m_bytes_per_pixel = ( qt_screen->depth() + 7 ) / 8; |
123 | m_rotation = 0; | 128 | m_rotation = 0; |
129 | m_lastsize = 0; | ||
124 | } | 130 | } |
125 | 131 | ||
@@ -127,10 +133,23 @@ XineVideoWidget::XineVideoWidget ( QWidget* parent, const char* name ) | |||
127 | XineVideoWidget::~XineVideoWidget ( ) | 133 | XineVideoWidget::~XineVideoWidget ( ) |
128 | { | 134 | { |
135 | ThreadUtil::AutoLock a(m_bufmutex); | ||
136 | if (m_buff) { | ||
137 | delete[]m_buff; | ||
138 | m_lastsize=0; | ||
139 | m_buff = 0; | ||
140 | } | ||
141 | if (m_logo) { | ||
129 | delete m_logo; | 142 | delete m_logo; |
130 | } | 143 | } |
144 | } | ||
131 | 145 | ||
132 | void XineVideoWidget::clear ( ) | 146 | void XineVideoWidget::clear ( ) |
133 | { | 147 | { |
148 | ThreadUtil::AutoLock a(m_bufmutex); | ||
149 | if (m_buff) { | ||
150 | delete[]m_buff; | ||
151 | m_lastsize=0; | ||
134 | m_buff = 0; | 152 | m_buff = 0; |
153 | } | ||
135 | repaint ( false ); | 154 | repaint ( false ); |
136 | } | 155 | } |
@@ -153,4 +172,14 @@ QSize XineVideoWidget::videoSize() const | |||
153 | void XineVideoWidget::paintEvent ( QPaintEvent * ) | 172 | void XineVideoWidget::paintEvent ( QPaintEvent * ) |
154 | { | 173 | { |
174 | ThreadUtil::AutoLock a(m_bufmutex); | ||
175 | QPainter p ( this ); | ||
176 | p. fillRect ( rect (), black ); | ||
177 | if (m_logo) | ||
178 | p. drawImage ( 0, 0, *m_logo ); | ||
179 | } | ||
180 | |||
181 | void XineVideoWidget::paintEvent2 ( QPaintEvent * ) | ||
182 | { | ||
183 | ThreadUtil::AutoLock a(m_bufmutex); | ||
155 | if ( m_buff == 0 ) { | 184 | if ( m_buff == 0 ) { |
156 | QPainter p ( this ); | 185 | QPainter p ( this ); |
@@ -273,5 +302,20 @@ void XineVideoWidget::setLogo ( QImage* logo ) | |||
273 | void XineVideoWidget::setVideoFrame ( uchar* img, int w, int h, int bpl ) | 302 | void XineVideoWidget::setVideoFrame ( uchar* img, int w, int h, int bpl ) |
274 | { | 303 | { |
304 | // mutex area for AutoLock | ||
305 | { | ||
306 | if (m_bufmutex.isLocked()) { | ||
307 | // no time to wait - drop frame | ||
308 | return; | ||
309 | } | ||
310 | ThreadUtil::AutoLock a(m_bufmutex); | ||
275 | bool rot90 = (( -m_rotation ) & 1 ); | 311 | bool rot90 = (( -m_rotation ) & 1 ); |
312 | int l = h*m_bytes_per_pixel*w; | ||
313 | if (l>m_lastsize) { | ||
314 | if (m_buff) { | ||
315 | delete[]m_buff; | ||
316 | } | ||
317 | m_buff = new uchar[l]; | ||
318 | m_lastsize=l; | ||
319 | } | ||
276 | 320 | ||
277 | if ( rot90 ) { // if the rotation is 90 or 270 we have to swap width / height | 321 | if ( rot90 ) { // if the rotation is 90 or 270 we have to swap width / height |
@@ -284,12 +328,9 @@ void XineVideoWidget::setVideoFrame ( uchar* img, int w, int h, int bpl ) | |||
284 | m_thisframe. setRect (( width ( ) - w ) / 2, ( height ( ) - h ) / 2, w , h ); | 328 | m_thisframe. setRect (( width ( ) - w ) / 2, ( height ( ) - h ) / 2, w , h ); |
285 | 329 | ||
286 | m_buff = img; | 330 | memcpy(m_buff,img,m_lastsize); |
287 | m_bytes_per_line_frame = bpl; | 331 | m_bytes_per_line_frame = bpl; |
332 | } // Release Mutex | ||
288 | 333 | ||
289 | // only repaint the area that *really* needs to be repainted | 334 | paintEvent2(0); |
290 | |||
291 | repaint ((( m_thisframe & m_lastframe ) != m_lastframe ) ? m_lastframe : m_thisframe, false ); | ||
292 | // ensure that we always have a valid frame! | ||
293 | m_buff = 0; | ||
294 | } | 335 | } |
295 | 336 | ||
diff --git a/noncore/multimedia/opieplayer2/xinevideowidget.h b/noncore/multimedia/opieplayer2/xinevideowidget.h index 8b3a3ea..7f00aaa 100644 --- a/noncore/multimedia/opieplayer2/xinevideowidget.h +++ b/noncore/multimedia/opieplayer2/xinevideowidget.h | |||
@@ -1,28 +1,30 @@ | |||
1 | |||
1 | /* | 2 | /* |
2 | This file is part of the Opie Project | 3 | Â Â Â Â Â Â Â Â This file is part of the Opie Project |
3 | 4 | ||
4 | Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> | 5 | Â Â Â Â Â Â Â Copyright (c) 2002 Max Reiss <harlekin@handhelds.org> |
6 | Copyright (c) 2002 L. Potter <ljp@llornkcor.com> | ||
5 | Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> | 7 | Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> |
6 | =. | 8 | =. |
7 | .=l. | 9 | .=l. |
8 | .>+-= | 10 | Â Â Â Â Â Â .>+-= |
9 | _;:, .> :=|. This program is free software; you can | 11 | Â _;:, Â Â .> Â Â :=|. This program is free software; you can |
10 | .> <`_, > . <= redistribute it and/or modify it under | 12 | .> <`_, Â > Â . Â <= redistribute it and/or modify it under |
11 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | 13 | :`=1 )Y*s>-.-- Â : the terms of the GNU General Public |
12 | .="- .-=="i, .._ License as published by the Free Software | 14 | .="- .-=="i, Â Â .._ License as published by the Free Software |
13 | - . .-<_> .<> Foundation; either version 2 of the License, | 15 | Â - . Â .-<_> Â Â .<> Foundation; either version 2 of the License, |
14 | ._= =} : or (at your option) any later version. | 16 | Â Â Â ._= =} Â Â Â : or (at your option) any later version. |
15 | .%`+i> _;_. | 17 | Â Â .%`+i> Â Â Â _;_. |
16 | .i_,=:_. -<s. This program is distributed in the hope that | 18 | Â Â .i_,=:_. Â Â Â -<s. This program is distributed in the hope that |
17 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 19 | Â Â Â + Â . Â -:. Â Â Â = it will be useful, but WITHOUT ANY WARRANTY; |
18 | : .. .:, . . . without even the implied warranty of | 20 | Â Â : .. Â Â .:, Â Â . . . without even the implied warranty of |
19 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 21 | Â Â =_ Â Â Â Â + Â Â =;=|` MERCHANTABILITY or FITNESS FOR A |
20 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 22 | Â _.=:. Â Â Â : Â Â :=>`: PARTICULAR PURPOSE. See the GNU |
21 | ..}^=.= = ; Library General Public License for more | 23 | ..}^=.= Â Â Â = Â Â Â ; Library General Public License for more |
22 | ++= -. .` .: details. | 24 | ++= Â -. Â Â .` Â Â .: details. |
23 | : = ...= . :.=- | 25 | Â : Â Â = Â ...= . :.=- |
24 | -. .:....=;==+<; You should have received a copy of the GNU | 26 | Â -. Â .:....=;==+<; You should have received a copy of the GNU |
25 | -_. . . )=. = Library General Public License along with | 27 | Â -_. . . Â )=. Â = Library General Public License along with |
26 | -- :-=` this library; see the file COPYING.LIB. | 28 | Â Â -- Â Â Â Â :-=` this library; see the file COPYING.LIB. |
27 | If not, write to the Free Software Foundation, | 29 | If not, write to the Free Software Foundation, |
28 | Inc., 59 Temple Place - Suite 330, | 30 | Inc., 59 Temple Place - Suite 330, |
@@ -32,5 +34,4 @@ | |||
32 | 34 | ||
33 | 35 | ||
34 | |||
35 | #include <qwidget.h> | 36 | #include <qwidget.h> |
36 | 37 | ||
@@ -54,6 +55,7 @@ public: | |||
54 | 55 | ||
55 | protected: | 56 | protected: |
56 | void paintEvent( QPaintEvent *p ); | 57 | void paintEvent2( QPaintEvent *p ); |
57 | void resizeEvent ( QResizeEvent *r ); | 58 | virtual void paintEvent(QPaintEvent*); |
59 | virtual void resizeEvent ( QResizeEvent *r ); | ||
58 | 60 | ||
59 | void mouseReleaseEvent ( QMouseEvent *e ); | 61 | void mouseReleaseEvent ( QMouseEvent *e ); |
@@ -71,6 +73,8 @@ private: | |||
71 | int m_bytes_per_line_frame; | 73 | int m_bytes_per_line_frame; |
72 | int m_bytes_per_pixel; | 74 | int m_bytes_per_pixel; |
75 | int m_lastsize; | ||
73 | QImage *m_logo; | 76 | QImage *m_logo; |
74 | mutable int m_rotation; | 77 | mutable int m_rotation; |
78 | ThreadUtil::Mutex m_bufmutex; | ||
75 | }; | 79 | }; |
76 | 80 | ||