]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/video_widget.cpp
qt4/*: buildsytem fix + cosmetic+ copyright dates + svn Id
[vlc] / modules / gui / qt4 / components / video_widget.cpp
1 /*****************************************************************************
2  * video_widget.cpp : Embedded video output
3  ****************************************************************************
4  * Copyright (C) 2006 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #include "dialogs_provider.hpp"
25 #include <vlc/vout.h>
26 #include "qt4.hpp"
27 #include "components/video_widget.hpp"
28 #include "main_interface.hpp"
29
30 static void *DoRequest( intf_thread_t *, vout_thread_t *, int*,int*,
31                         unsigned int *, unsigned int * );
32 static void DoRelease( intf_thread_t *, void * );
33 static int DoControl( intf_thread_t *, void *, int, va_list );
34
35 bool need_update;
36        
37 VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ),
38                                                               p_intf( _p_i )
39 {
40     vlc_mutex_init( p_intf, &lock );
41
42     p_intf->pf_request_window  = ::DoRequest;
43     p_intf->pf_release_window  = ::DoRelease;
44     p_intf->pf_control_window  = ::DoControl;
45     p_intf->p_sys->p_video = this;
46     p_vout = NULL;
47
48     setFrameStyle(QFrame::Panel | QFrame::Raised);
49
50     setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
51
52     connect( DialogsProvider::getInstance(NULL)->fixed_timer,
53              SIGNAL( timeout() ), this, SLOT( update() ) );
54
55     need_update = false;
56 }
57
58 void VideoWidget::update()
59 {
60     if( need_update )
61     {
62         p_intf->p_sys->p_mi->resize( p_intf->p_sys->p_mi->sizeHint() );
63         need_update = false;
64     }
65 }
66
67 VideoWidget::~VideoWidget()
68 {
69     vlc_mutex_lock( &lock );
70     if( p_vout )
71     {
72         if( !p_intf->psz_switch_intf )
73         {
74             if( vout_Control( p_vout, VOUT_CLOSE ) != VLC_SUCCESS )
75                 vout_Control( p_vout, VOUT_REPARENT );
76         }
77         else
78         {
79             if( vout_Control( p_vout, VOUT_REPARENT ) != VLC_SUCCESS )
80                 vout_Control( p_vout, VOUT_CLOSE );
81         }
82     }
83     p_intf->pf_request_window = NULL;
84     p_intf->pf_release_window = NULL;
85     p_intf->pf_control_window = NULL;
86     vlc_mutex_unlock( &lock );
87     vlc_mutex_destroy( &lock );
88 }
89
90 QSize VideoWidget::sizeHint() const
91 {
92     return p_intf->p_sys->p_mi->videoSize;
93 }
94
95 static void *DoRequest( intf_thread_t *p_intf, vout_thread_t *p_vout,
96                         int *pi1, int *pi2, unsigned int*pi3,unsigned int*pi4)
97 {
98     return p_intf->p_sys->p_video->Request( p_vout, pi1, pi2, pi3, pi4 );
99 }
100
101 void *VideoWidget::Request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
102                            unsigned int *pi_width, unsigned int *pi_height )
103 {
104     if( p_vout )
105     {
106         msg_Dbg( p_intf, "embedded video already in use" );
107         return NULL;
108     }
109     p_vout = p_nvout;
110
111     fprintf( stderr, "[Before update] MI constraints %ix%i -> %ix%i\n",
112                     p_intf->p_sys->p_mi->minimumSize().width(),
113                     p_intf->p_sys->p_mi->minimumSize().height(),
114                     p_intf->p_sys->p_mi->maximumSize().width(),
115                     p_intf->p_sys->p_mi->maximumSize().height() );
116
117     setMinimumSize( 1,1 );
118     p_intf->p_sys->p_mi->videoSize = QSize( *pi_width, *pi_height );
119     updateGeometry();
120     need_update = true;
121     fprintf( stderr, "[After update] MI constraints %ix%i -> %ix%i - Fr %ix%i -> %ix%i (hint %ix%i)\n",
122                     p_intf->p_sys->p_mi->minimumSize().width(),
123                     p_intf->p_sys->p_mi->minimumSize().height(),
124                     p_intf->p_sys->p_mi->maximumSize().width(),
125                     p_intf->p_sys->p_mi->maximumSize().height(),
126                     minimumSize().width(),
127                     minimumSize().height(),
128                     maximumSize().width(),
129                     maximumSize().height(),
130                     sizeHint().width(),sizeHint().height() 
131            );
132     
133     return  (void*)winId();
134 }
135
136 static void DoRelease( intf_thread_t *p_intf, void *p_win )
137 {
138     return p_intf->p_sys->p_video->Release( p_win );
139 }
140
141 void VideoWidget::Release( void *p_win )
142 {
143     if( !config_GetInt( p_intf, "qt-always-video" ) );
144     {
145         p_intf->p_sys->p_mi->videoSize = QSize ( 1,1 );
146     }
147     fprintf( stderr, "[Before R update] MI constraints %ix%i -> %ix%i\n",
148                     p_intf->p_sys->p_mi->minimumSize().width(),
149                     p_intf->p_sys->p_mi->minimumSize().height(),
150                     p_intf->p_sys->p_mi->maximumSize().width(),
151                     p_intf->p_sys->p_mi->maximumSize().height() );
152
153     updateGeometry();
154
155 //    p_intf->p_sys->p_mi->setMinimumSize( 500,
156 //                                       p_intf->p_sys->p_mi->addSize.height() );
157     if( !config_GetInt( p_intf, "qt-always-video" ) )
158         need_update = true;
159
160     fprintf( stderr, "[After R update] MI constraints %ix%i -> %ix%i\n",
161                     p_intf->p_sys->p_mi->minimumSize().width(),
162                     p_intf->p_sys->p_mi->minimumSize().height(),
163                     p_intf->p_sys->p_mi->maximumSize().width(),
164                     p_intf->p_sys->p_mi->maximumSize().height() );
165     
166     p_vout = NULL;
167 }
168
169
170 static int DoControl( intf_thread_t *p_intf, void *p_win, int i_q, va_list a )
171 {
172     return p_intf->p_sys->p_video->Control( p_win, i_q, a );
173
174
175 int VideoWidget::Control( void *p_window, int i_query, va_list args )
176 {
177     int i_ret = VLC_EGENERIC;
178     vlc_mutex_lock( &lock );
179     switch( i_query )
180     {
181         case VOUT_GET_SIZE:
182         {
183             unsigned int *pi_width  = va_arg( args, unsigned int * );
184             unsigned int *pi_height = va_arg( args, unsigned int * );
185             *pi_width = frame->width();
186             *pi_height = frame->height();
187             i_ret = VLC_SUCCESS;
188             break;
189         }
190         case VOUT_SET_SIZE:
191         {
192             unsigned int i_width  = va_arg( args, unsigned int );
193             unsigned int i_height = va_arg( args, unsigned int );
194
195             if( !i_width && p_vout ) i_width = p_vout->i_window_width;
196             if( !i_height && p_vout ) i_height = p_vout->i_window_height;
197            
198             frame->resize( i_width, i_height );
199             i_ret = VLC_SUCCESS;
200             break; 
201         }
202         case VOUT_SET_STAY_ON_TOP:
203         {
204             /// \todo
205             break;
206         }   
207         default:
208             msg_Warn( p_intf, "unsupported control query" );
209             break;
210     }
211     vlc_mutex_unlock( &lock );
212     return i_ret;
213 }