2 * \brief VP Stages. Output SDL stage declaration
3 * \author Sylvain Gaeremynck <sylvain.gaeremynck@parrot.fr>
4 * \author Aurelien Morelle <aurelien.morelle@parrot.fr>
5 * \author Thomas Landais <thomas.landais@parrot.fr>
7 * \date first release 16/03/2007
8 * \date modification 19/03/2007
13 ///////////////////////////////////////////////
16 #include <VP_Stages/vp_stages_o_sdl.h>
17 #include <VP_Api/vp_api_picture.h>
18 #include <VP_Api/vp_api_error.h>
19 #include <VP_Os/vp_os_print.h>
20 #include <VP_Os/vp_os_malloc.h>
21 #include <VP_Os/vp_os_delay.h>
22 #include <VP_Os/vp_os_signal.h>
23 #include <VP_Api/vp_api_thread_helper.h>
26 static int pipeline_opened = 0;
27 static vp_os_mutex_t xlib_mutex;
29 #if defined(_CK4215_) && defined(WIN32)
30 static void * main_windows;
31 static void * child_windows;
32 static BOOL exit_pipeline;
35 static BOOL show_hide;
39 vp_stages_init_display(void * handle)
41 main_windows = handle;
45 vp_stages_get_child_window( void )
50 void manage_events(void)
53 static uint16_t x =0, y = 0;
56 if(SDL_PollEvent(&event))
60 #if defined(_CK4215_) && defined(WIN32)
65 ShowWindow((HWND)child_windows,SW_HIDE);
67 ShowWindow((HWND)child_windows,SW_SHOW);
84 SDL_KeyboardEvent *kb_event = (SDL_KeyboardEvent *)&event;
85 switch(kb_event->keysym.sym)
103 PROTO_THREAD_ROUTINE(escaper,nomParams)
107 while(!pipeline_opened)
112 while(pipeline_opened)
114 vp_os_mutex_lock(&xlib_mutex);
115 if(SDL_PollEvent(&event))
117 vp_os_mutex_unlock(&xlib_mutex);
123 SDL_KeyboardEvent *kb_event = (SDL_KeyboardEvent *)&event;
124 switch(kb_event->keysym.sym)
139 vp_os_mutex_unlock(&xlib_mutex);
142 return (THREAD_RET)0;
147 vp_stages_buffer_to_overlay(SDL_Overlay *overlay, vp_stages_output_sdl_config_t *cfg, vp_api_picture_t *picture)
149 uint8_t *dst0, *dst1, *dst2, *dst3;
150 uint8_t *src0, *src1, *src2, *src3;
155 SDL_LockYUVOverlay(overlay);
157 dst0 = overlay->pixels[0];
158 src0 = picture->y_buf;
159 dst1 = overlay->pixels[1];
160 src1 = picture->cr_buf;
161 dst2 = overlay->pixels[2];
162 src2 = picture->cb_buf;
164 d0 = overlay->pitches[0];
165 d1 = overlay->pitches[1];
166 d2 = overlay->pitches[2];
168 s0 = picture->y_line_size;
169 s1 = picture->cb_line_size;
170 s2 = picture->cr_line_size;
172 dst3 = dst0 + d0 * cfg->pic_height/2;
173 src3 = src0 + s0 * picture->height/2;
177 vp_os_memset(dst1, 0x80, ((cfg->pic_width/2+d1)*cfg->pic_height/2)/2);
178 vp_os_memset(dst2, 0x80, ((cfg->pic_width/2+d2)*cfg->pic_height/2)/2);
181 for(i = 0 ; i < (int32_t)cfg->pic_height/2 ; i++)
183 memcpy(dst0, src0, cfg->pic_width*sizeof(char));
189 memcpy(dst1, src1, cfg->pic_width/2*sizeof(char));
193 memcpy(dst2, src2, cfg->pic_width/2*sizeof(char));
198 memcpy(dst3, src3, cfg->pic_width*sizeof(char));
203 SDL_UnlockYUVOverlay(overlay);
208 vp_stages_display_frame(vp_stages_output_sdl_config_t *cfg, vp_api_picture_t *picture)
214 dstrect.x = (cfg->window_width-cfg->width)/2;
215 dstrect.y = (cfg->window_height-cfg->height)/2;
216 dstrect.w = cfg->width;
217 dstrect.h = cfg->height;
219 vp_os_mutex_lock(&xlib_mutex);
221 vp_stages_buffer_to_overlay(cfg->overlay, cfg, picture);
222 SDL_DisplayYUVOverlay(cfg->overlay, &dstrect);
224 vp_os_mutex_unlock(&xlib_mutex);
232 vp_stages_output_sdl_stage_open(vp_stages_output_sdl_config_t *cfg)
234 vp_os_mutex_init(&xlib_mutex);
236 if(SDL_Init(SDL_INIT_TIMER|SDL_INIT_VIDEO))
238 PRINT("Error initializing SDL\n");
241 #if defined(_CK4215_) && defined(WIN32)
242 child_windows = NULL;
243 exit_pipeline = FALSE;
246 show_hide = TRUE;//show
255 vp_stages_output_sdl_stage_transform(vp_stages_output_sdl_config_t *cfg, vp_api_io_data_t *in, vp_api_io_data_t *out)
257 #if defined(_CK4215_) && defined(WIN32)
258 struct SDL_SysWMinfo wmInfo;
261 vp_os_mutex_lock(&out->lock);
263 #if defined(_CK4215_) && defined(WIN32)
264 if( exit_pipeline == TRUE )
266 /* It let the VPSDK handles the closing of the SDL */
267 out->status = VP_API_STATUS_ENDED;
272 if(out->status == VP_API_STATUS_INIT)
275 out->size = cfg->y_size + 2*cfg->c_size;
276 out->buffers = (int8_t**)vp_os_malloc(sizeof(uint8_t*)+out->size*sizeof(uint8_t));
277 out->buffers[0] = (int8_t*)(out->buffers+1);
278 out->indexBuffer = 0;
280 #if defined(_CK4215_) && defined(WIN32)
283 cfg->surface = SDL_SetVideoMode(cfg->width, cfg->height, cfg->bpp, SDL_NOFRAME);
285 cfg->surface = SDL_SetVideoMode(cfg->width, cfg->height, cfg->bpp, SDL_HWSURFACE);
288 cfg->surface = SDL_SetVideoMode(cfg->width, cfg->height, cfg->bpp, SDL_HWSURFACE);
290 SDL_ShowCursor(SDL_DISABLE);
291 cfg->overlay = SDL_CreateYUVOverlay(cfg->pic_width, cfg->pic_height, SDL_YV12_OVERLAY, cfg->surface);
293 #if defined(_CK4215_) && defined(WIN32)
294 SDL_VERSION(&wmInfo.version);
296 if(-1 == SDL_GetWMInfo(&wmInfo))
298 OutputDebugString(SDL_GetError());
302 child_windows = (void *) wmInfo.window;
304 //Attach to parent windows
306 SetParent((HWND)child_windows,(HWND) main_windows);
310 //Put the child windows at the good position
311 //MoveWindow((HWND)child_windows, 0,0,/*g_x, g_y,*/ cfg->width, cfg->height, FALSE);
312 MoveWindow((HWND)child_windows, cfg->window_pos_x, cfg->window_pos_y, cfg->width, cfg->height, FALSE);
319 cfg->window_pos_x, //0, // X
320 cfg->window_pos_y,//0, // Y
323 SWP_SHOWWINDOW//SWP_NOREPOSITION//SWP_NOREDRAW //uFlags
330 out->status = (in->status == VP_API_STATUS_STILL_RUNNING ? VP_API_STATUS_PROCESSING : in->status);
334 if((out->status == VP_API_STATUS_PROCESSING || out->status == VP_API_STATUS_STILL_RUNNING) && in->size > 0)
336 vp_stages_display_frame(cfg, (vp_api_picture_t*)in->buffers);
337 #if defined(_CK4215_) && defined(WIN32)
340 vp_os_memcpy(out->buffers[0], ((vp_api_picture_t*)in->buffers)->y_buf, cfg->y_size);
343 vp_os_memcpy(out->buffers[0]+cfg->y_size, ((vp_api_picture_t*)in->buffers)->cb_buf, cfg->c_size);
344 vp_os_memcpy(out->buffers[0]+cfg->y_size+cfg->c_size, ((vp_api_picture_t*)in->buffers)->cr_buf, cfg->c_size);
349 if(in->status == VP_API_STATUS_ENDED)
352 vp_os_free(out->buffers);
355 vp_os_mutex_unlock(&out->lock);
362 vp_stages_output_sdl_stage_close(vp_stages_output_sdl_config_t *cfg)
364 vp_os_mutex_lock(&xlib_mutex);
366 SDL_ShowCursor(SDL_ENABLE);
367 SDL_FreeYUVOverlay(cfg->overlay);
368 SDL_FreeSurface(cfg->surface);
372 vp_os_mutex_unlock(&xlib_mutex);