| 1 | /* |
|---|
| 2 | mediastreamer2 library - modular sound and video processing and streaming |
|---|
| 3 | Copyright (C) 2006 Simon MORLAT (simon.morlat@linphone.org) |
|---|
| 4 | |
|---|
| 5 | This program is free software; you can redistribute it and/or |
|---|
| 6 | modify it under the terms of the GNU General Public License |
|---|
| 7 | as published by the Free Software Foundation; either version 2 |
|---|
| 8 | of the License, or (at your option) any later version. |
|---|
| 9 | |
|---|
| 10 | This program is distributed in the hope that it will be useful, |
|---|
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 13 | GNU General Public License for more details. |
|---|
| 14 | |
|---|
| 15 | You should have received a copy of the GNU General Public License |
|---|
| 16 | along with this program; if not, write to the Free Software |
|---|
| 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 18 | */ |
|---|
| 19 | |
|---|
| 20 | #ifdef HAVE_CONFIG_H |
|---|
| 21 | #include "mediastreamer-config.h" |
|---|
| 22 | #endif |
|---|
| 23 | |
|---|
| 24 | #include "mediastreamer2/msfilter.h" |
|---|
| 25 | #include "mediastreamer2/msvideo.h" |
|---|
| 26 | |
|---|
| 27 | /*required for dllexport of win_display_desc */ |
|---|
| 28 | #define INVIDEOUT_C 1 |
|---|
| 29 | #include "mediastreamer2/msvideoout.h" |
|---|
| 30 | |
|---|
| 31 | #include "ffmpeg-priv.h" |
|---|
| 32 | |
|---|
| 33 | #define SCALE_FACTOR 4.0f |
|---|
| 34 | #define SELVIEW_POS_INACTIVE -100.0 |
|---|
| 35 | |
|---|
| 36 | static int video_out_set_vsize(MSFilter *f,void *arg); |
|---|
| 37 | |
|---|
| 38 | bool_t ms_display_poll_event(MSDisplay *d, MSDisplayEvent *ev){ |
|---|
| 39 | if (d->desc->pollevent) |
|---|
| 40 | return d->desc->pollevent(d,ev); |
|---|
| 41 | else return FALSE; |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | static int gcd(int m, int n) |
|---|
| 45 | { |
|---|
| 46 | if(n == 0) |
|---|
| 47 | return m; |
|---|
| 48 | else |
|---|
| 49 | return gcd(n, m % n); |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | static void reduce(int *num, int *denom) |
|---|
| 53 | { |
|---|
| 54 | int divisor = gcd(*num, *denom); |
|---|
| 55 | *num /= divisor; |
|---|
| 56 | *denom /= divisor; |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | #ifdef HAVE_SDL |
|---|
| 60 | |
|---|
| 61 | #include <SDL/SDL.h> |
|---|
| 62 | #include <SDL/SDL_video.h> |
|---|
| 63 | |
|---|
| 64 | typedef struct _SdlDisplay{ |
|---|
| 65 | MSFilter *filter; |
|---|
| 66 | bool_t sdl_initialized; |
|---|
| 67 | ms_mutex_t sdl_mutex; |
|---|
| 68 | SDL_Surface *sdl_screen; |
|---|
| 69 | SDL_Overlay *lay; |
|---|
| 70 | |
|---|
| 71 | float sv_scalefactor; |
|---|
| 72 | MSVideoSize screen_size; |
|---|
| 73 | } SdlDisplay; |
|---|
| 74 | |
|---|
| 75 | #ifdef HAVE_X11_XLIB_H |
|---|
| 76 | |
|---|
| 77 | #include <SDL/SDL_syswm.h> |
|---|
| 78 | |
|---|
| 79 | static long sdl_get_native_window_id(){ |
|---|
| 80 | SDL_SysWMinfo info; |
|---|
| 81 | SDL_VERSION(&info.version); |
|---|
| 82 | if ( SDL_GetWMInfo(&info) ) { |
|---|
| 83 | if ( info.subsystem == SDL_SYSWM_X11 ) { |
|---|
| 84 | return (long) info.info.x11.wmwindow; |
|---|
| 85 | } |
|---|
| 86 | } |
|---|
| 87 | return 0; |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | static void sdl_show_window(bool_t show){ |
|---|
| 91 | SDL_SysWMinfo info; |
|---|
| 92 | SDL_VERSION(&info.version); |
|---|
| 93 | if ( SDL_GetWMInfo(&info) ) { |
|---|
| 94 | if ( info.subsystem == SDL_SYSWM_X11 ) { |
|---|
| 95 | Display *display; |
|---|
| 96 | Window window; |
|---|
| 97 | |
|---|
| 98 | info.info.x11.lock_func(); |
|---|
| 99 | display = info.info.x11.display; |
|---|
| 100 | window = info.info.x11.wmwindow; |
|---|
| 101 | if (show) |
|---|
| 102 | XMapWindow(display,window); |
|---|
| 103 | else |
|---|
| 104 | XUnmapWindow(display,window); |
|---|
| 105 | info.info.x11.unlock_func(); |
|---|
| 106 | } |
|---|
| 107 | } |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | #else |
|---|
| 111 | |
|---|
| 112 | static void sdl_show_window(bool_t show){ |
|---|
| 113 | ms_warning("SDL window show/hide not implemented"); |
|---|
| 114 | } |
|---|
| 115 | |
|---|
| 116 | static long sdl_get_native_window_id(){ |
|---|
| 117 | ms_warning("sdl_get_native_window_id not implemented"); |
|---|
| 118 | return 0; |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | #endif |
|---|
| 122 | |
|---|
| 123 | static void sdl_display_uninit(MSDisplay *obj); |
|---|
| 124 | |
|---|
| 125 | static int sdl_create_window(SdlDisplay *wd, int w, int h){ |
|---|
| 126 | static bool_t once=TRUE; |
|---|
| 127 | uint32_t flags = SDL_ANYFORMAT | SDL_DOUBLEBUF | SDL_RESIZABLE; |
|---|
| 128 | const SDL_VideoInfo *info; |
|---|
| 129 | info =SDL_GetVideoInfo(); |
|---|
| 130 | if (info->wm_available) { |
|---|
| 131 | ms_message("Using window manager"); |
|---|
| 132 | } |
|---|
| 133 | if (info->hw_available) { |
|---|
| 134 | ms_message("hw surface available (%dk memory)", info->video_mem); |
|---|
| 135 | flags |= SDL_HWSURFACE; |
|---|
| 136 | } |
|---|
| 137 | else |
|---|
| 138 | flags |= SDL_SWSURFACE; |
|---|
| 139 | |
|---|
| 140 | if (info->blit_hw) { |
|---|
| 141 | ms_message("hw surface available (%dk memory)", info->video_mem); |
|---|
| 142 | flags |= SDL_ASYNCBLIT; |
|---|
| 143 | } |
|---|
| 144 | if (info->blit_hw_CC) |
|---|
| 145 | ms_message("Colorkey blits between hw surfaces: accelerated"); |
|---|
| 146 | if (info->blit_hw_A) |
|---|
| 147 | ms_message("Alpha blits between hw surfaces: accelerated"); |
|---|
| 148 | if (info->blit_sw) |
|---|
| 149 | ms_message("Copy blits from sw to hw surfaces: accelerated"); |
|---|
| 150 | if (info->blit_hw_CC) |
|---|
| 151 | ms_message("Colorkey blits between sw to hw surfaces: accelerated"); |
|---|
| 152 | if (info->blit_hw_A) |
|---|
| 153 | ms_message("Alpha blits between sw to hw surfaces: accelerated"); |
|---|
| 154 | |
|---|
| 155 | wd->sdl_screen = SDL_SetVideoMode(wd->screen_size.width,wd->screen_size.height, 0,flags); |
|---|
| 156 | if (wd->sdl_screen == NULL ) { |
|---|
| 157 | ms_warning("no hardware for video mode: %s\n", |
|---|
| 158 | SDL_GetError()); |
|---|
| 159 | } |
|---|
| 160 | if (wd->sdl_screen->flags & SDL_HWSURFACE) ms_message("SDL surface created in hardware"); |
|---|
| 161 | if (once) { |
|---|
| 162 | SDL_WM_SetCaption("Video window", NULL); |
|---|
| 163 | once=FALSE; |
|---|
| 164 | } |
|---|
| 165 | wd->lay=SDL_CreateYUVOverlay(w , h ,SDL_YV12_OVERLAY,wd->sdl_screen); |
|---|
| 166 | if (wd->lay==NULL){ |
|---|
| 167 | ms_warning("Couldn't create yuv overlay: %s\n", |
|---|
| 168 | SDL_GetError()); |
|---|
| 169 | return -1; |
|---|
| 170 | }else{ |
|---|
| 171 | ms_message("%i x %i YUV overlay created: hw_accel=%i, pitches=%i,%i,%i",wd->lay->w,wd->lay->h,wd->lay->hw_overlay, |
|---|
| 172 | wd->lay->pitches[0],wd->lay->pitches[1],wd->lay->pitches[2]); |
|---|
| 173 | ms_message("planes= %p %p %p %i %i",wd->lay->pixels[0],wd->lay->pixels[1],wd->lay->pixels[2], |
|---|
| 174 | wd->lay->pixels[1]-wd->lay->pixels[0],wd->lay->pixels[2]-wd->lay->pixels[1]); |
|---|
| 175 | } |
|---|
| 176 | SDL_ShowCursor(0);//Hide the mouse cursor if was displayed |
|---|
| 177 | return 0; |
|---|
| 178 | } |
|---|
| 179 | |
|---|
| 180 | static bool_t sdl_display_init(MSDisplay *obj, MSFilter *f, MSPicture *fbuf, MSPicture *fbuf_selfview){ |
|---|
| 181 | SdlDisplay *wd = (SdlDisplay*)obj->data; |
|---|
| 182 | int i; |
|---|
| 183 | if (wd==NULL){ |
|---|
| 184 | char driver[128]; |
|---|
| 185 | /* Initialize the SDL library */ |
|---|
| 186 | wd=(SdlDisplay*)ms_new0(SdlDisplay,1); |
|---|
| 187 | wd->filter = f; |
|---|
| 188 | obj->data=wd; |
|---|
| 189 | |
|---|
| 190 | if( SDL_Init(SDL_INIT_VIDEO) < 0 ) { |
|---|
| 191 | ms_error("Couldn't initialize SDL: %s", SDL_GetError()); |
|---|
| 192 | return FALSE; |
|---|
| 193 | } |
|---|
| 194 | wd->sdl_initialized=TRUE; |
|---|
| 195 | if (SDL_VideoDriverName(driver, sizeof(driver))){ |
|---|
| 196 | ms_message("Video driver: %s", driver); |
|---|
| 197 | } |
|---|
| 198 | ms_mutex_init(&wd->sdl_mutex,NULL); |
|---|
| 199 | ms_mutex_lock(&wd->sdl_mutex); |
|---|
| 200 | wd->screen_size.width = fbuf->w; |
|---|
| 201 | wd->screen_size.height = fbuf->h; |
|---|
| 202 | |
|---|
| 203 | }else { |
|---|
| 204 | ms_mutex_lock(&wd->sdl_mutex); |
|---|
| 205 | |
|---|
| 206 | if (wd->lay!=NULL) |
|---|
| 207 | SDL_FreeYUVOverlay(wd->lay); |
|---|
| 208 | if (wd->sdl_screen!=NULL) |
|---|
| 209 | SDL_FreeSurface(wd->sdl_screen); |
|---|
| 210 | wd->lay=NULL; |
|---|
| 211 | wd->sdl_screen=NULL; |
|---|
| 212 | } |
|---|
| 213 | wd->filter = f; |
|---|
| 214 | |
|---|
| 215 | i=sdl_create_window(wd, fbuf->w, fbuf->h); |
|---|
| 216 | if (i==0){ |
|---|
| 217 | fbuf->planes[0]=wd->lay->pixels[0]; |
|---|
| 218 | fbuf->planes[1]=wd->lay->pixels[2]; |
|---|
| 219 | fbuf->planes[2]=wd->lay->pixels[1]; |
|---|
| 220 | fbuf->planes[3]=NULL; |
|---|
| 221 | fbuf->strides[0]=wd->lay->pitches[0]; |
|---|
| 222 | fbuf->strides[1]=wd->lay->pitches[2]; |
|---|
| 223 | fbuf->strides[2]=wd->lay->pitches[1]; |
|---|
| 224 | fbuf->strides[3]=0; |
|---|
| 225 | fbuf->w=wd->lay->w; |
|---|
| 226 | fbuf->h=wd->lay->h; |
|---|
| 227 | sdl_show_window(TRUE); |
|---|
| 228 | obj->window_id=sdl_get_native_window_id(); |
|---|
| 229 | ms_mutex_unlock(&wd->sdl_mutex); |
|---|
| 230 | return TRUE; |
|---|
| 231 | } |
|---|
| 232 | ms_mutex_unlock(&wd->sdl_mutex); |
|---|
| 233 | return FALSE; |
|---|
| 234 | } |
|---|
| 235 | |
|---|
| 236 | static void sdl_display_lock(MSDisplay *obj){ |
|---|
| 237 | SdlDisplay *wd = (SdlDisplay*)obj->data; |
|---|
| 238 | ms_mutex_lock(&wd->sdl_mutex); |
|---|
| 239 | SDL_LockYUVOverlay(wd->lay); |
|---|
| 240 | ms_mutex_unlock(&wd->sdl_mutex); |
|---|
| 241 | } |
|---|
| 242 | |
|---|
| 243 | static void sdl_display_unlock(MSDisplay *obj){ |
|---|
| 244 | SdlDisplay *wd = (SdlDisplay*)obj->data; |
|---|
| 245 | ms_mutex_lock(&wd->sdl_mutex); |
|---|
| 246 | SDL_UnlockYUVOverlay(wd->lay); |
|---|
| 247 | ms_mutex_unlock(&wd->sdl_mutex); |
|---|
| 248 | } |
|---|
| 249 | |
|---|
| 250 | static void sdl_display_update(MSDisplay *obj, int new_image, int new_selfview){ |
|---|
| 251 | SdlDisplay *wd = (SdlDisplay*)obj->data; |
|---|
| 252 | SDL_Rect rect; |
|---|
| 253 | int ratiow; |
|---|
| 254 | int ratioh; |
|---|
| 255 | int w; |
|---|
| 256 | int h; |
|---|
| 257 | |
|---|
| 258 | rect.x=0; |
|---|
| 259 | rect.y=0; |
|---|
| 260 | ms_mutex_lock(&wd->sdl_mutex); |
|---|
| 261 | |
|---|
| 262 | ratiow=wd->lay->w; |
|---|
| 263 | ratioh=wd->lay->h; |
|---|
| 264 | reduce(&ratiow, &ratioh); |
|---|
| 265 | w = wd->screen_size.width/ratiow*ratiow; |
|---|
| 266 | h = wd->screen_size.height/ratioh*ratioh; |
|---|
| 267 | |
|---|
| 268 | if (h*ratiow>w*ratioh) |
|---|
| 269 | { |
|---|
| 270 | w = w; |
|---|
| 271 | h = w*ratioh/ratiow; |
|---|
| 272 | } |
|---|
| 273 | else |
|---|
| 274 | { |
|---|
| 275 | h = h; |
|---|
| 276 | w = h*ratiow/ratioh; |
|---|
| 277 | } |
|---|
| 278 | |
|---|
| 279 | if (h*wd->lay->w!=w*wd->lay->h) |
|---|
| 280 | ms_error("wrong ratio"); |
|---|
| 281 | |
|---|
| 282 | rect.x = (wd->screen_size.width-w)/2; |
|---|
| 283 | rect.y = (wd->screen_size.height-h)/2; |
|---|
| 284 | rect.w = w; |
|---|
| 285 | rect.h = h; |
|---|
| 286 | SDL_DisplayYUVOverlay(wd->lay,&rect); |
|---|
| 287 | ms_mutex_unlock(&wd->sdl_mutex); |
|---|
| 288 | } |
|---|
| 289 | |
|---|
| 290 | static bool_t sdl_poll_event(MSDisplay *obj, MSDisplayEvent *ev){ |
|---|
| 291 | SdlDisplay *wd = (SdlDisplay*)obj->data; |
|---|
| 292 | SDL_Event event; |
|---|
| 293 | bool_t ret=FALSE; |
|---|
| 294 | if (wd->sdl_screen==NULL) return FALSE; |
|---|
| 295 | ms_mutex_lock(&wd->sdl_mutex); |
|---|
| 296 | if (SDL_PollEvent(&event)){ |
|---|
| 297 | ms_mutex_unlock(&wd->sdl_mutex); |
|---|
| 298 | switch(event.type){ |
|---|
| 299 | case SDL_VIDEORESIZE: |
|---|
| 300 | ev->evtype=MS_DISPLAY_RESIZE_EVENT; |
|---|
| 301 | ev->w=event.resize.w; |
|---|
| 302 | ev->h=event.resize.h; |
|---|
| 303 | wd->screen_size.width = event.resize.w; |
|---|
| 304 | wd->screen_size.height = event.resize.h; |
|---|
| 305 | return TRUE; |
|---|
| 306 | break; |
|---|
| 307 | default: |
|---|
| 308 | break; |
|---|
| 309 | } |
|---|
| 310 | }else ms_mutex_unlock(&wd->sdl_mutex); |
|---|
| 311 | return ret; |
|---|
| 312 | } |
|---|
| 313 | |
|---|
| 314 | static void sdl_display_uninit(MSDisplay *obj){ |
|---|
| 315 | SdlDisplay *wd = (SdlDisplay*)obj->data; |
|---|
| 316 | SDL_Event event; |
|---|
| 317 | int i; |
|---|
| 318 | if (wd==NULL) |
|---|
| 319 | return; |
|---|
| 320 | if (wd->lay!=NULL) |
|---|
| 321 | SDL_FreeYUVOverlay(wd->lay); |
|---|
| 322 | if (wd->sdl_screen!=NULL){ |
|---|
| 323 | SDL_FreeSurface(wd->sdl_screen); |
|---|
| 324 | wd->sdl_screen=NULL; |
|---|
| 325 | } |
|---|
| 326 | wd->lay=NULL; |
|---|
| 327 | wd->sdl_screen=NULL; |
|---|
| 328 | ms_free(wd); |
|---|
| 329 | #ifdef __linux |
|---|
| 330 | /*purge the event queue before leaving*/ |
|---|
| 331 | for(i=0;SDL_PollEvent(&event) && i<100;++i){ |
|---|
| 332 | } |
|---|
| 333 | #endif |
|---|
| 334 | sdl_show_window(FALSE); |
|---|
| 335 | SDL_Quit(); |
|---|
| 336 | } |
|---|
| 337 | |
|---|
| 338 | MSDisplayDesc ms_sdl_display_desc={ |
|---|
| 339 | .init=sdl_display_init, |
|---|
| 340 | .lock=sdl_display_lock, |
|---|
| 341 | .unlock=sdl_display_unlock, |
|---|
| 342 | .update=sdl_display_update, |
|---|
| 343 | .uninit=sdl_display_uninit, |
|---|
| 344 | .pollevent=sdl_poll_event, |
|---|
| 345 | }; |
|---|
| 346 | |
|---|
| 347 | #elif defined(WIN32) |
|---|
| 348 | |
|---|
| 349 | #include <Vfw.h> |
|---|
| 350 | |
|---|
| 351 | typedef struct _WinDisplay{ |
|---|
| 352 | MSFilter *filter; |
|---|
| 353 | HWND window; |
|---|
| 354 | HDRAWDIB ddh; |
|---|
| 355 | MSPicture fb; |
|---|
| 356 | MSPicture fb_selfview; |
|---|
| 357 | uint8_t *rgb_selfview; |
|---|
| 358 | int rgb_len_selfview; |
|---|
| 359 | struct ms_SwsContext *sws_selfview; |
|---|
| 360 | MSDisplayEvent last_rsz; |
|---|
| 361 | uint8_t *rgb; |
|---|
| 362 | int last_rect_w; |
|---|
| 363 | int last_rect_h; |
|---|
| 364 | int rgb_len; |
|---|
| 365 | struct ms_SwsContext *sws; |
|---|
| 366 | bool_t new_ev; |
|---|
| 367 | }WinDisplay; |
|---|
| 368 | |
|---|
| 369 | static LRESULT CALLBACK window_proc( |
|---|
| 370 | HWND hwnd, // handle to window |
|---|
| 371 | UINT uMsg, // message identifier |
|---|
| 372 | WPARAM wParam, // first message parameter |
|---|
| 373 | LPARAM lParam) // second message parameter |
|---|
| 374 | { |
|---|
| 375 | switch(uMsg){ |
|---|
| 376 | case WM_DESTROY: |
|---|
| 377 | break; |
|---|
| 378 | case WM_SIZE: |
|---|
| 379 | if (wParam==SIZE_RESTORED){ |
|---|
| 380 | int h=(lParam>>16) & 0xffff; |
|---|
| 381 | int w=lParam & 0xffff; |
|---|
| 382 | MSDisplay *obj; |
|---|
| 383 | WinDisplay *wd; |
|---|
| 384 | ms_message("Resized to %i,%i",w,h); |
|---|
| 385 | obj=(MSDisplay*)GetWindowLongPtr(hwnd,GWLP_USERDATA); |
|---|
| 386 | if (obj!=NULL){ |
|---|
| 387 | wd=(WinDisplay*)obj->data; |
|---|
| 388 | wd->last_rsz.evtype=MS_DISPLAY_RESIZE_EVENT; |
|---|
| 389 | wd->last_rsz.w=w; |
|---|
| 390 | wd->last_rsz.h=h; |
|---|
| 391 | wd->new_ev=TRUE; |
|---|
| 392 | }else{ |
|---|
| 393 | ms_error("Could not retrieve MSDisplay from window !"); |
|---|
| 394 | } |
|---|
| 395 | } |
|---|
| 396 | break; |
|---|
| 397 | default: |
|---|
| 398 | return DefWindowProc(hwnd, uMsg, wParam, lParam); |
|---|
| 399 | } |
|---|
| 400 | return 0; |
|---|
| 401 | } |
|---|
| 402 | |
|---|
| 403 | static HWND create_window(int w, int h) |
|---|
| 404 | { |
|---|
| 405 | WNDCLASS wc; |
|---|
| 406 | HINSTANCE hInstance = GetModuleHandle(NULL); |
|---|
| 407 | HWND hwnd; |
|---|
| 408 | RECT rect; |
|---|
| 409 | wc.style = 0 ; |
|---|
| 410 | wc.lpfnWndProc = window_proc; |
|---|
| 411 | wc.cbClsExtra = 0; |
|---|
| 412 | wc.cbWndExtra = 0; |
|---|
| 413 | wc.hInstance = NULL; |
|---|
| 414 | wc.hIcon = NULL; |
|---|
| 415 | wc.hCursor = LoadCursor(hInstance, IDC_ARROW); |
|---|
| 416 | wc.hbrBackground = NULL; |
|---|
| 417 | wc.lpszMenuName = NULL; |
|---|
| 418 | wc.lpszClassName = "Video Window"; |
|---|
| 419 | |
|---|
| 420 | if(!RegisterClass(&wc)) |
|---|
| 421 | { |
|---|
| 422 | /* already registred! */ |
|---|
| 423 | } |
|---|
| 424 | rect.left=100; |
|---|
| 425 | rect.top=100; |
|---|
| 426 | rect.right=rect.left+w; |
|---|
| 427 | rect.bottom=rect.top+h; |
|---|
| 428 | if (!AdjustWindowRect(&rect,WS_OVERLAPPEDWINDOW|WS_VISIBLE /*WS_CAPTION WS_TILED|WS_BORDER*/,FALSE)){ |
|---|
| 429 | ms_error("AdjustWindowRect failed."); |
|---|
| 430 | } |
|---|
| 431 | ms_message("AdjustWindowRect: %li,%li %li,%li",rect.left,rect.top,rect.right,rect.bottom); |
|---|
| 432 | hwnd=CreateWindow("Video Window", "Video window", |
|---|
| 433 | WS_OVERLAPPEDWINDOW /*WS_THICKFRAME*/ | WS_VISIBLE , |
|---|
| 434 | CW_USEDEFAULT, CW_USEDEFAULT, rect.right-rect.left,rect.bottom-rect.top, |
|---|
| 435 | NULL, NULL, hInstance, NULL); |
|---|
| 436 | if (hwnd==NULL){ |
|---|
| 437 | ms_error("Fail to create video window"); |
|---|
| 438 | } |
|---|
| 439 | return hwnd; |
|---|
| 440 | } |
|---|
| 441 | |
|---|
| 442 | static bool_t win_display_init(MSDisplay *obj, MSFilter *f, MSPicture *fbuf, MSPicture *fbuf_selfview){ |
|---|
| 443 | WinDisplay *wd=(WinDisplay*)obj->data; |
|---|
| 444 | int ysize,usize; |
|---|
| 445 | |
|---|
| 446 | if (wd!=NULL) |
|---|
| 447 | { |
|---|
| 448 | wd->filter = NULL; |
|---|
| 449 | if (wd->ddh) DrawDibClose(wd->ddh); |
|---|
| 450 | wd->ddh=NULL; |
|---|
| 451 | if (wd->fb.planes[0]) ms_free(wd->fb.planes[0]); |
|---|
| 452 | wd->fb.planes[0]=NULL; |
|---|
| 453 | wd->fb.planes[1]=NULL; |
|---|
| 454 | wd->fb.planes[2]=NULL; |
|---|
| 455 | wd->fb.planes[3]=NULL; |
|---|
| 456 | if (wd->rgb) ms_free(wd->rgb); |
|---|
| 457 | wd->rgb=NULL; |
|---|
| 458 | wd->rgb_len=0; |
|---|
| 459 | ms_sws_freeContext(wd->sws); |
|---|
| 460 | wd->sws=NULL; |
|---|
| 461 | if (wd->fb_selfview.planes[0]) ms_free(wd->fb_selfview.planes[0]); |
|---|
| 462 | wd->fb_selfview.planes[0]=NULL; |
|---|
| 463 | wd->fb_selfview.planes[1]=NULL; |
|---|
| 464 | wd->fb_selfview.planes[2]=NULL; |
|---|
| 465 | wd->fb_selfview.planes[3]=NULL; |
|---|
| 466 | if (wd->rgb_selfview) ms_free(wd->rgb_selfview); |
|---|
| 467 | wd->rgb_selfview=NULL; |
|---|
| 468 | wd->rgb_len_selfview=0; |
|---|
| 469 | ms_sws_freeContext(wd->sws_selfview); |
|---|
| 470 | wd->sws_selfview=NULL; |
|---|
| 471 | wd->last_rect_w=0; |
|---|
| 472 | wd->last_rect_h=0; |
|---|
| 473 | } |
|---|
| 474 | else |
|---|
| 475 | wd=(WinDisplay*)ms_new0(WinDisplay,1); |
|---|
| 476 | |
|---|
| 477 | wd->filter = f; |
|---|
| 478 | obj->data=wd; |
|---|
| 479 | |
|---|
| 480 | wd->fb.w=fbuf->w; |
|---|
| 481 | wd->fb.h=fbuf->h; |
|---|
| 482 | wd->fb_selfview.w=fbuf_selfview->w; |
|---|
| 483 | wd->fb_selfview.h=fbuf_selfview->h; |
|---|
| 484 | |
|---|
| 485 | if (wd->window==NULL){ |
|---|
| 486 | if (obj->use_external_window && obj->window_id!=0){ |
|---|
| 487 | void *p; |
|---|
| 488 | wd->window=(HWND)obj->window_id; |
|---|
| 489 | p=(void*)GetWindowLongPtr(wd->window,GWLP_USERDATA); |
|---|
| 490 | if (p!=NULL){ |
|---|
| 491 | ms_error("Gulp: this externally supplied windows seems to " |
|---|
| 492 | "already have a userdata ! resizing will crash !"); |
|---|
| 493 | }else SetWindowLongPtr(wd->window,GWLP_USERDATA,(LONG_PTR)obj); |
|---|
| 494 | }else{ |
|---|
| 495 | wd->window=create_window(wd->fb.w,wd->fb.h); |
|---|
| 496 | obj->window_id=(long)wd->window; |
|---|
| 497 | if (wd->window!=NULL) SetWindowLongPtr(wd->window,GWLP_USERDATA,(LONG_PTR)obj); |
|---|
| 498 | else return FALSE; |
|---|
| 499 | } |
|---|
| 500 | }else if (!obj->use_external_window){ |
|---|
| 501 | /* the window might need to be resized*/ |
|---|
| 502 | RECT cur; |
|---|
| 503 | GetWindowRect(wd->window,&cur); |
|---|
| 504 | MoveWindow(wd->window,cur.left, cur.top, wd->fb.w, wd->fb.h,TRUE); |
|---|
| 505 | } |
|---|
| 506 | |
|---|
| 507 | if (wd->ddh==NULL) wd->ddh=DrawDibOpen(); |
|---|
| 508 | if (wd->ddh==NULL){ |
|---|
| 509 | ms_error("DrawDibOpen() failed."); |
|---|
| 510 | return FALSE; |
|---|
| 511 | } |
|---|
| 512 | |
|---|
| 513 | /*allocate yuv and rgb buffers*/ |
|---|
| 514 | if (wd->fb_selfview.planes[0]) ms_free(wd->fb_selfview.planes[0]); |
|---|
| 515 | if (wd->rgb_selfview) ms_free(wd->rgb_selfview); |
|---|
| 516 | ysize=wd->fb_selfview.w*wd->fb_selfview.h; |
|---|
| 517 | usize=ysize/4; |
|---|
| 518 | fbuf_selfview->planes[0]=wd->fb_selfview.planes[0]=(uint8_t*)ms_malloc0(ysize+2*usize); |
|---|
| 519 | fbuf_selfview->planes[1]=wd->fb_selfview.planes[1]=wd->fb_selfview.planes[0]+ysize; |
|---|
| 520 | fbuf_selfview->planes[2]=wd->fb_selfview.planes[2]=wd->fb_selfview.planes[1]+usize; |
|---|
| 521 | fbuf_selfview->planes[3]=NULL; |
|---|
| 522 | fbuf_selfview->strides[0]=wd->fb_selfview.strides[0]=wd->fb_selfview.w; |
|---|
| 523 | fbuf_selfview->strides[1]=wd->fb_selfview.strides[1]=wd->fb_selfview.w/2; |
|---|
| 524 | fbuf_selfview->strides[2]=wd->fb_selfview.strides[2]=wd->fb_selfview.w/2; |
|---|
| 525 | fbuf_selfview->strides[3]=0; |
|---|
| 526 | |
|---|
| 527 | wd->rgb_len_selfview=ysize*3; |
|---|
| 528 | wd->rgb_selfview=(uint8_t*)ms_malloc0(wd->rgb_len_selfview); |
|---|
| 529 | |
|---|
| 530 | if (wd->fb.planes[0]) ms_free(wd->fb.planes[0]); |
|---|
| 531 | if (wd->rgb) ms_free(wd->rgb); |
|---|
| 532 | ysize=wd->fb.w*wd->fb.h; |
|---|
| 533 | usize=ysize/4; |
|---|
| 534 | fbuf->planes[0]=wd->fb.planes[0]=(uint8_t*)ms_malloc0(ysize+2*usize); |
|---|
| 535 | fbuf->planes[1]=wd->fb.planes[1]=wd->fb.planes[0]+ysize; |
|---|
| 536 | fbuf->planes[2]=wd->fb.planes[2]=wd->fb.planes[1]+usize; |
|---|
| 537 | fbuf->planes[3]=NULL; |
|---|
| 538 | fbuf->strides[0]=wd->fb.strides[0]=wd->fb.w; |
|---|
| 539 | fbuf->strides[1]=wd->fb.strides[1]=wd->fb.w/2; |
|---|
| 540 | fbuf->strides[2]=wd->fb.strides[2]=wd->fb.w/2; |
|---|
| 541 | fbuf->strides[3]=0; |
|---|
| 542 | |
|---|
| 543 | wd->rgb_len=ysize*3; |
|---|
| 544 | wd->rgb=(uint8_t*)ms_malloc0(wd->rgb_len); |
|---|
| 545 | wd->last_rect_w=0; |
|---|
| 546 | wd->last_rect_h=0; |
|---|
| 547 | return TRUE; |
|---|
| 548 | } |
|---|
| 549 | |
|---|
| 550 | typedef struct rgb{ |
|---|
| 551 | uint8_t r,g,b; |
|---|
| 552 | } rgb_t; |
|---|
| 553 | |
|---|
| 554 | typedef struct yuv{ |
|---|
| 555 | uint8_t y,u,v; |
|---|
| 556 | } yuv_t; |
|---|
| 557 | |
|---|
| 558 | |
|---|
| 559 | |
|---|
| 560 | static void yuv420p_to_rgb(WinDisplay *wd, MSPicture *src, uint8_t *rgb){ |
|---|
| 561 | int rgb_stride=-src->w*3; |
|---|
| 562 | uint8_t *p; |
|---|
| 563 | |
|---|
| 564 | p=rgb+(src->w*3*(src->h-1)); |
|---|
| 565 | if (wd->sws==NULL){ |
|---|
| 566 | wd->sws=ms_sws_getContext(src->w,src->h,PIX_FMT_YUV420P, |
|---|
| 567 | src->w,src->h, PIX_FMT_BGR24, |
|---|
| 568 | SWS_FAST_BILINEAR, NULL, NULL, NULL); |
|---|
| 569 | } |
|---|
| 570 | if (ms_sws_scale(wd->sws,src->planes,src->strides, 0, |
|---|
| 571 | src->h, &p, &rgb_stride)<0){ |
|---|
| 572 | ms_error("Error in 420->rgb ms_sws_scale()."); |
|---|
| 573 | } |
|---|
| 574 | } |
|---|
| 575 | |
|---|
| 576 | static void yuv420p_to_rgb_selfview(WinDisplay *wd, MSPicture *src, uint8_t *rgb){ |
|---|
| 577 | int rgb_stride=-src->w*3; |
|---|
| 578 | uint8_t *p; |
|---|
| 579 | |
|---|
| 580 | p=rgb+(src->w*3*(src->h-1)); |
|---|
| 581 | if (wd->sws_selfview==NULL){ |
|---|
| 582 | wd->sws_selfview=ms_sws_getContext(src->w,src->h,PIX_FMT_YUV420P, |
|---|
| 583 | src->w,src->h, PIX_FMT_BGR24, |
|---|
| 584 | SWS_FAST_BILINEAR, NULL, NULL, NULL); |
|---|
| 585 | } |
|---|
| 586 | if (ms_sws_scale(wd->sws_selfview,src->planes,src->strides, 0, |
|---|
| 587 | src->h, &p, &rgb_stride)<0){ |
|---|
| 588 | ms_error("Error in 420->rgb ms_sws_scale()."); |
|---|
| 589 | } |
|---|
| 590 | } |
|---|
| 591 | |
|---|
| 592 | static void win_display_update(MSDisplay *obj, int new_image, int new_selfview){ |
|---|
| 593 | WinDisplay *wd=(WinDisplay*)obj->data; |
|---|
| 594 | HDC hdc; |
|---|
| 595 | BITMAPINFOHEADER bi; |
|---|
| 596 | RECT rect; |
|---|
| 597 | bool_t ret; |
|---|
| 598 | int ratiow; |
|---|
| 599 | int ratioh; |
|---|
| 600 | int w; |
|---|
| 601 | int h; |
|---|
| 602 | int corner; |
|---|
| 603 | float sv_scalefactor; |
|---|
| 604 | float sv_pos[3]; |
|---|
| 605 | int color[3]; |
|---|
| 606 | |
|---|
| 607 | HDC dd_hdc; |
|---|
| 608 | HBITMAP dd_bmp; |
|---|
| 609 | HBRUSH brush; |
|---|
| 610 | BOOL dont_draw; |
|---|
| 611 | |
|---|
| 612 | if (wd->window==NULL) return; |
|---|
| 613 | hdc=GetDC(wd->window); |
|---|
| 614 | if (hdc==NULL) { |
|---|
| 615 | ms_error("Could not get window dc"); |
|---|
| 616 | return; |
|---|
| 617 | } |
|---|
| 618 | if (new_image>0) |
|---|
| 619 | yuv420p_to_rgb(wd, &wd->fb, wd->rgb); |
|---|
| 620 | memset(&bi,0,sizeof(bi)); |
|---|
| 621 | bi.biSize=sizeof(bi); |
|---|
| 622 | GetClientRect(wd->window,&rect); |
|---|
| 623 | |
|---|
| 624 | bi.biWidth=wd->fb.w; |
|---|
| 625 | bi.biHeight=wd->fb.h; |
|---|
| 626 | bi.biPlanes=1; |
|---|
| 627 | bi.biBitCount=24; |
|---|
| 628 | bi.biCompression=BI_RGB; |
|---|
| 629 | bi.biSizeImage=wd->rgb_len; |
|---|
| 630 | |
|---|
| 631 | ratiow=wd->fb.w; |
|---|
| 632 | ratioh=wd->fb.h; |
|---|
| 633 | reduce(&ratiow, &ratioh); |
|---|
| 634 | w = rect.right/ratiow*ratiow; |
|---|
| 635 | h = rect.bottom/ratioh*ratioh; |
|---|
| 636 | |
|---|
| 637 | if (h*ratiow>w*ratioh) |
|---|
| 638 | { |
|---|
| 639 | w = w; |
|---|
| 640 | h = w*ratioh/ratiow; |
|---|
| 641 | } |
|---|
| 642 | else |
|---|
| 643 | { |
|---|
| 644 | h = h; |
|---|
| 645 | w = h*ratiow/ratioh; |
|---|
| 646 | } |
|---|
| 647 | |
|---|
| 648 | if (h*wd->fb.w!=w*wd->fb.h) |
|---|
| 649 | ms_error("wrong ratio"); |
|---|
| 650 | |
|---|
| 651 | dd_hdc = CreateCompatibleDC(hdc); |
|---|
| 652 | if (dd_hdc==NULL) { |
|---|
| 653 | ms_error("Could not get CreateCompatibleDC"); |
|---|
| 654 | return; |
|---|
| 655 | } |
|---|
| 656 | dd_bmp = CreateCompatibleBitmap(hdc, rect.right, rect.bottom); |
|---|
| 657 | if (dd_bmp==NULL) { |
|---|
| 658 | ms_error("Could not get CreateCompatibleBitmap"); |
|---|
| 659 | return; |
|---|
| 660 | } |
|---|
| 661 | |
|---|
| 662 | HGDIOBJ old_object = SelectObject(dd_hdc, dd_bmp); |
|---|
| 663 | |
|---|
| 664 | dont_draw = DrawDibBegin(wd->ddh,dd_hdc, 0, 0, &bi, 0, 0, DDF_BUFFER); |
|---|
| 665 | |
|---|
| 666 | /* full screen in background color */ |
|---|
| 667 | color[0]=color[1]=color[2]=0; |
|---|
| 668 | if (wd->filter) |
|---|
| 669 | ms_filter_call_method(wd->filter, MS_VIDEO_OUT_GET_BACKGROUND_COLOR, &color); |
|---|
| 670 | |
|---|
| 671 | brush = CreateSolidBrush(RGB(color[0],color[1],color[2])); |
|---|
| 672 | FillRect(dd_hdc, &rect, brush); |
|---|
| 673 | DeleteObject(brush); |
|---|
| 674 | |
|---|
| 675 | corner = 0; |
|---|
| 676 | sv_scalefactor = SCALE_FACTOR; |
|---|
| 677 | sv_pos[0] = SELVIEW_POS_INACTIVE; |
|---|
| 678 | sv_pos[1] = SELVIEW_POS_INACTIVE; |
|---|
| 679 | sv_pos[2] = 0; |
|---|
| 680 | if (wd->filter) |
|---|
| 681 | ms_filter_call_method(wd->filter, MS_VIDEO_OUT_GET_CORNER, &corner); |
|---|
| 682 | if (wd->filter) |
|---|
| 683 | ms_filter_call_method(wd->filter, MS_VIDEO_OUT_GET_SCALE_FACTOR, &sv_scalefactor); |
|---|
| 684 | if (wd->filter) |
|---|
| 685 | ms_filter_call_method(wd->filter, MS_VIDEO_OUT_GET_SELFVIEW_POS, sv_pos); |
|---|
| 686 | |
|---|
| 687 | if (wd->rgb_selfview==NULL || corner==-1) { |
|---|
| 688 | ret=DrawDibDraw(wd->ddh,dd_hdc, |
|---|
| 689 | (rect.right-w)/2, |
|---|
| 690 | (rect.bottom-h)/2, |
|---|
| 691 | w, |
|---|
| 692 | h, |
|---|
| 693 | &bi,wd->rgb, |
|---|
| 694 | 0,0,bi.biWidth,bi.biHeight,dont_draw?DDF_DONTDRAW:0); |
|---|
| 695 | |
|---|
| 696 | } else { |
|---|
| 697 | |
|---|
| 698 | int w_selfview = rect.right - w; |
|---|
| 699 | int h_selfview = rect.bottom - h; |
|---|
| 700 | |
|---|
| 701 | if ((h_selfview < h/sv_scalefactor && w_selfview < w/sv_scalefactor) || corner<=3 || sv_pos[0]!=SELVIEW_POS_INACTIVE) |
|---|
| 702 | { |
|---|
| 703 | ret=DrawDibDraw(wd->ddh,dd_hdc, |
|---|
| 704 | (rect.right-w)/2, |
|---|
| 705 | (rect.bottom-h)/2, |
|---|
| 706 | w, |
|---|
| 707 | h, |
|---|
| 708 | &bi,wd->rgb, |
|---|
| 709 | 0,0,bi.biWidth,bi.biHeight,dont_draw?DDF_DONTDRAW:0); |
|---|
| 710 | |
|---|
| 711 | //preserve ratio |
|---|
| 712 | ratiow=wd->fb_selfview.w; |
|---|
| 713 | ratioh=wd->fb_selfview.h; |
|---|
| 714 | reduce(&ratiow, &ratioh); |
|---|
| 715 | |
|---|
| 716 | w_selfview = (int)(w/sv_scalefactor); |
|---|
| 717 | w_selfview = w_selfview/ratiow*ratiow; |
|---|
| 718 | h_selfview = w_selfview*ratioh/ratiow; |
|---|
| 719 | |
|---|
| 720 | if (rect.right>100 && rect.bottom>100) |
|---|
| 721 | { |
|---|
| 722 | int x_sv; |
|---|
| 723 | int y_sv; |
|---|
| 724 | if (new_selfview>0) |
|---|
| 725 | yuv420p_to_rgb_selfview(wd, &wd->fb_selfview, wd->rgb_selfview); |
|---|
| 726 | |
|---|
| 727 | //HPEN hpenDot; |
|---|
| 728 | //hpenDot = CreatePen(PS_SOLID, 1, RGB(10, 10, 10)); |
|---|
| 729 | //SelectObject(dd_hdc, hpenDot); |
|---|
| 730 | if (sv_pos[0]!=SELVIEW_POS_INACTIVE) |
|---|
| 731 | { |
|---|
| 732 | x_sv = (int)((rect.right*sv_pos[0])/100.0-w_selfview/2); |
|---|
| 733 | y_sv = (int)((rect.bottom*sv_pos[1])/100.0-h_selfview/2); |
|---|
| 734 | } |
|---|
| 735 | else if (corner==1 || corner==4+1) |
|---|
| 736 | { |
|---|
| 737 | /* top left corner */ |
|---|
| 738 | x_sv = 20; |
|---|
| 739 | y_sv = 20; |
|---|
| 740 | } |
|---|
| 741 | else if (corner==2 || corner==4+2) |
|---|
| 742 | { |
|---|
| 743 | /* top right corner */ |
|---|
| 744 | x_sv = (rect.right-w_selfview-20); |
|---|
| 745 | y_sv = 20; |
|---|
| 746 | } |
|---|
| 747 | else if (corner==3 || corner==4+3) |
|---|
| 748 | { |
|---|
| 749 | /* bottom left corner */ |
|---|
| 750 | x_sv = 20; |
|---|
| 751 | y_sv = (rect.bottom-h_selfview-20); |
|---|
| 752 | } |
|---|
| 753 | else /* corner = 0: default */ |
|---|
| 754 | { |
|---|
| 755 | /* bottom right corner */ |
|---|
| 756 | x_sv = (rect.right-w_selfview-20); |
|---|
| 757 | y_sv = (rect.bottom-h_selfview-20); |
|---|
| 758 | } |
|---|
| 759 | |
|---|
| 760 | |
|---|
| 761 | Rectangle(dd_hdc, x_sv-2, y_sv-2, x_sv+w_selfview+2, y_sv+h_selfview+2); |
|---|
| 762 | ret=DrawDibDraw(wd->ddh,dd_hdc, |
|---|
| 763 | x_sv, |
|---|
| 764 | y_sv, |
|---|
| 765 | w_selfview, |
|---|
| 766 | h_selfview, |
|---|
| 767 | &bi,wd->rgb_selfview, |
|---|
| 768 | 0,0,bi.biWidth,bi.biHeight,dont_draw?DDF_DONTDRAW:0); |
|---|
| 769 | } |
|---|
| 770 | } |
|---|
| 771 | else |
|---|
| 772 | { |
|---|
| 773 | //preserve ratio |
|---|
| 774 | ratiow=wd->fb_selfview.w; |
|---|
| 775 | ratioh=wd->fb_selfview.h; |
|---|
| 776 | reduce(&ratiow, &ratioh); |
|---|
| 777 | |
|---|
| 778 | if (new_selfview>0) |
|---|
| 779 | yuv420p_to_rgb_selfview(wd, &wd->fb_selfview, wd->rgb_selfview); |
|---|
| 780 | if (w_selfview >= w/sv_scalefactor) |
|---|
| 781 | { |
|---|
| 782 | w_selfview = w_selfview/ratiow*ratiow; |
|---|
| 783 | h_selfview = w_selfview*ratioh/ratiow; |
|---|
| 784 | |
|---|
| 785 | ret=DrawDibDraw(wd->ddh,dd_hdc, |
|---|
| 786 | 0, |
|---|
| 787 | (rect.bottom-h)/2, |
|---|
| 788 | w, |
|---|
| 789 | h, |
|---|
| 790 | &bi,wd->rgb, |
|---|
| 791 | 0,0,bi.biWidth,bi.biHeight,dont_draw?DDF_DONTDRAW:0); |
|---|
| 792 | |
|---|
| 793 | Rectangle(dd_hdc, |
|---|
| 794 | (rect.right-w_selfview)-4-2, |
|---|
| 795 | (rect.bottom-h_selfview)/2-2, |
|---|
| 796 | (rect.right)-4+2, |
|---|
| 797 | (rect.bottom+h_selfview)/2+2); |
|---|
| 798 | |
|---|
| 799 | ret=DrawDibDraw(wd->ddh,dd_hdc, |
|---|
| 800 | (rect.right-w_selfview)-4, |
|---|
| 801 | (rect.bottom-h_selfview)/2, |
|---|
| 802 | w_selfview, |
|---|
| 803 | h_selfview, |
|---|
| 804 | &bi,wd->rgb_selfview, |
|---|
| 805 | 0,0,bi.biWidth,bi.biHeight,dont_draw?DDF_DONTDRAW:0); |
|---|
| 806 | } |
|---|
| 807 | else |
|---|
| 808 | { |
|---|
| 809 | h_selfview = h_selfview/ratioh*ratioh; |
|---|
| 810 | w_selfview = h_selfview*ratiow/ratioh; |
|---|
| 811 | |
|---|
| 812 | ret=DrawDibDraw(wd->ddh,dd_hdc, |
|---|
| 813 | (rect.right-w)/2, |
|---|
| 814 | 0, |
|---|
| 815 | w, |
|---|
| 816 | h, |
|---|
| 817 | &bi,wd->rgb, |
|---|
| 818 | 0,0,bi.biWidth,bi.biHeight,dont_draw?DDF_DONTDRAW:0); |
|---|
| 819 | |
|---|
| 820 | Rectangle(dd_hdc, |
|---|
| 821 | (rect.right-w_selfview)/2-2, |
|---|
| 822 | (rect.bottom-h_selfview)-4-2, |
|---|
| 823 | (rect.right+w_selfview)/2+2, |
|---|
| 824 | (rect.bottom)-4+2); |
|---|
| 825 | |
|---|
| 826 | ret=DrawDibDraw(wd->ddh,dd_hdc, |
|---|
| 827 | (rect.right-w_selfview)/2, |
|---|
| 828 | (rect.bottom-h_selfview)-4, |
|---|
| 829 | w_selfview, |
|---|
| 830 | h_selfview, |
|---|
| 831 | &bi,wd->rgb_selfview, |
|---|
| 832 | 0,0,bi.biWidth,bi.biHeight,dont_draw?DDF_DONTDRAW:0); |
|---|
| 833 | } |
|---|
| 834 | } |
|---|
| 835 | } |
|---|
| 836 | |
|---|
| 837 | DrawDibEnd(wd->ddh); |
|---|
| 838 | BitBlt(hdc, 0, 0, rect.right, rect.bottom, dd_hdc, 0, 0, SRCCOPY); |
|---|
| 839 | SelectObject(dd_hdc, old_object); |
|---|
| 840 | |
|---|
| 841 | DeleteObject(dd_bmp); |
|---|
| 842 | DeleteDC(dd_hdc); |
|---|
| 843 | |
|---|
| 844 | wd->last_rect_w=rect.right; |
|---|
| 845 | wd->last_rect_h=rect.bottom; |
|---|
| 846 | |
|---|
| 847 | if (!ret) ms_error("DrawDibDraw failed."); |
|---|
| 848 | ReleaseDC(NULL,hdc); |
|---|
| 849 | } |
|---|
| 850 | |
|---|
| 851 | static void win_display_uninit(MSDisplay *obj){ |
|---|
| 852 | WinDisplay *wd=(WinDisplay*)obj->data; |
|---|
| 853 | if (wd==NULL) |
|---|
| 854 | return; |
|---|
| 855 | if (wd->window && !obj->use_external_window) DestroyWindow(wd->window); |
|---|
| 856 | if (wd->ddh) DrawDibClose(wd->ddh); |
|---|
| 857 | if (wd->fb_selfview.planes[0]) ms_free(wd->fb_selfview.planes[0]); |
|---|
| 858 | if (wd->rgb_selfview) ms_free(wd->rgb_selfview); |
|---|
| 859 | if (wd->sws_selfview) ms_sws_freeContext(wd->sws_selfview); |
|---|
| 860 | if (wd->fb.planes[0]) ms_free(wd->fb.planes[0]); |
|---|
| 861 | if (wd->rgb) ms_free(wd->rgb); |
|---|
| 862 | if (wd->sws) ms_sws_freeContext(wd->sws); |
|---|
| 863 | ms_free(wd); |
|---|
| 864 | } |
|---|
| 865 | |
|---|
| 866 | bool_t win_display_pollevent(MSDisplay *d, MSDisplayEvent *ev){ |
|---|
| 867 | return FALSE; |
|---|
| 868 | } |
|---|
| 869 | |
|---|
| 870 | #ifdef _MSC_VER |
|---|
| 871 | |
|---|
| 872 | extern MSDisplayDesc ms_win_display_desc={ |
|---|
| 873 | win_display_init, |
|---|
| 874 | NULL, |
|---|
| 875 | NULL, |
|---|
| 876 | win_display_update, |
|---|
| 877 | win_display_uninit, |
|---|
| 878 | win_display_pollevent |
|---|
| 879 | }; |
|---|
| 880 | |
|---|
| 881 | #else |
|---|
| 882 | |
|---|
| 883 | MSDisplayDesc ms_win_display_desc={ |
|---|
| 884 | .init=win_display_init, |
|---|
| 885 | .update=win_display_update, |
|---|
| 886 | .uninit=win_display_uninit, |
|---|
| 887 | .pollevent=win_display_pollevent |
|---|
| 888 | }; |
|---|
| 889 | |
|---|
| 890 | #endif |
|---|
| 891 | |
|---|
| 892 | #endif |
|---|
| 893 | |
|---|
| 894 | MSDisplay *ms_display_new(MSDisplayDesc *desc){ |
|---|
| 895 | MSDisplay *obj=(MSDisplay *)ms_new0(MSDisplay,1); |
|---|
| 896 | obj->desc=desc; |
|---|
| 897 | obj->data=NULL; |
|---|
| 898 | return obj; |
|---|
| 899 | } |
|---|
| 900 | |
|---|
| 901 | void ms_display_set_window_id(MSDisplay *d, long id){ |
|---|
| 902 | d->window_id=id; |
|---|
| 903 | d->use_external_window=TRUE; |
|---|
| 904 | } |
|---|
| 905 | |
|---|
| 906 | void ms_display_destroy(MSDisplay *obj){ |
|---|
| 907 | obj->desc->uninit(obj); |
|---|
| 908 | ms_free(obj); |
|---|
| 909 | } |
|---|
| 910 | |
|---|
| 911 | #ifdef HAVE_SDL |
|---|
| 912 | static MSDisplayDesc *default_display_desc=&ms_sdl_display_desc; |
|---|
| 913 | #elif defined(WIN32) |
|---|
| 914 | static MSDisplayDesc *default_display_desc=&ms_win_display_desc; |
|---|
| 915 | #else |
|---|
| 916 | static MSDisplayDesc *default_display_desc=NULL; |
|---|
| 917 | #endif |
|---|
| 918 | |
|---|
| 919 | void ms_display_desc_set_default(MSDisplayDesc *desc){ |
|---|
| 920 | default_display_desc=desc; |
|---|
| 921 | } |
|---|
| 922 | |
|---|
| 923 | MSDisplayDesc * ms_display_desc_get_default(void){ |
|---|
| 924 | return default_display_desc; |
|---|
| 925 | } |
|---|
| 926 | |
|---|
| 927 | void ms_display_desc_set_default_window_id(MSDisplayDesc *desc, long id){ |
|---|
| 928 | desc->default_window_id=id; |
|---|
| 929 | } |
|---|
| 930 | |
|---|
| 931 | typedef struct VideoOut |
|---|
| 932 | { |
|---|
| 933 | AVRational ratio; |
|---|
| 934 | MSPicture fbuf; |
|---|
| 935 | MSPicture fbuf_selfview; |
|---|
| 936 | MSPicture local_pic; |
|---|
| 937 | MSRect local_rect; |
|---|
| 938 | mblk_t *local_msg; |
|---|
| 939 | MSVideoSize prevsize; |
|---|
| 940 | int corner; /*for selfview*/ |
|---|
| 941 | float scale_factor; /*for selfview*/ |
|---|
| 942 | float sv_posx,sv_posy; |
|---|
| 943 | int background_color[3]; |
|---|
| 944 | |
|---|
| 945 | struct ms_SwsContext *sws1; |
|---|
| 946 | struct ms_SwsContext *sws2; |
|---|
| 947 | MSDisplay *display; |
|---|
| 948 | bool_t own_display; |
|---|
| 949 | bool_t ready; |
|---|
| 950 | bool_t autofit; |
|---|
| 951 | bool_t mirror; |
|---|
| 952 | } VideoOut; |
|---|
| 953 | |
|---|
| 954 | static void set_corner(VideoOut *s, int corner) |
|---|
| 955 | { |
|---|
| 956 | s->corner=corner; |
|---|
| 957 | s->local_pic.w=((int)(s->fbuf.w/s->scale_factor)) & ~0x1; |
|---|
| 958 | s->local_pic.h=((int)(s->fbuf.h/s->scale_factor)) & ~0x1; |
|---|
| 959 | s->local_rect.w=s->local_pic.w; |
|---|
| 960 | s->local_rect.h=s->local_pic.h; |
|---|
| 961 | if (corner==1) { |
|---|
| 962 | /* top left corner */ |
|---|
| 963 | s->local_rect.x=0; |
|---|
| 964 | s->local_rect.y=0; |
|---|
| 965 | } else if (corner==2) { |
|---|
| 966 | /* top right corner */ |
|---|
| 967 | s->local_rect.x=s->fbuf.w-s->local_pic.w; |
|---|
| 968 | s->local_rect.y=0; |
|---|
| 969 | } else if (corner==3) { |
|---|
| 970 | /* bottom left corner */ |
|---|
| 971 | s->local_rect.x=0; |
|---|
| 972 | s->local_rect.y=s->fbuf.h-s->local_pic.h; |
|---|
| 973 | } else { |
|---|
| 974 | /* default: bottom right corner */ |
|---|
| 975 | /* corner can be set to -1: to disable the self view... */ |
|---|
| 976 | s->local_rect.x=s->fbuf.w-s->local_pic.w; |
|---|
| 977 | s->local_rect.y=s->fbuf.h-s->local_pic.h; |
|---|
| 978 | } |
|---|
| 979 | s->fbuf_selfview.w=(s->fbuf.w/1) & ~0x1; |
|---|
| 980 | s->fbuf_selfview.h=(s->fbuf.h/1) & ~0x1; |
|---|
| 981 | } |
|---|
| 982 | |
|---|
| 983 | static void re_vsize(VideoOut *s, MSVideoSize *sz){ |
|---|
| 984 | ms_message("Windows size set to %ix%i",sz->width,sz->height); |
|---|
| 985 | } |
|---|
| 986 | |
|---|
| 987 | |
|---|
| 988 | static void set_vsize(VideoOut *s, MSVideoSize *sz){ |
|---|
| 989 | s->fbuf.w=sz->width & ~0x1; |
|---|
| 990 | s->fbuf.h=sz->height & ~0x1; |
|---|
| 991 | set_corner(s,s->corner); |
|---|
| 992 | ms_message("Video size set to %ix%i",s->fbuf.w,s->fbuf.h); |
|---|
| 993 | } |
|---|
| 994 | |
|---|
| 995 | static void video_out_init(MSFilter *f){ |
|---|
| 996 | VideoOut *obj=(VideoOut*)ms_new0(VideoOut,1); |
|---|
| 997 | MSVideoSize def_size; |
|---|
| 998 | obj->ratio.num=11; |
|---|
| 999 | obj->ratio.den=9; |
|---|
| 1000 | def_size.width=MS_VIDEO_SIZE_CIF_W; |
|---|
| 1001 | def_size.height=MS_VIDEO_SIZE_CIF_H; |
|---|
| 1002 | obj->prevsize.width=0; |
|---|
| 1003 | obj->prevsize.height=0; |
|---|
| 1004 | obj->local_msg=NULL; |
|---|
| 1005 | obj->corner=0; |
|---|
| 1006 | obj->scale_factor=SCALE_FACTOR; |
|---|
| 1007 | obj->sv_posx=obj->sv_posy=SELVIEW_POS_INACTIVE; |
|---|
| 1008 | obj->background_color[0]=obj->background_color[1]=obj->background_color[2]=0; |
|---|
| 1009 | obj->sws1=NULL; |
|---|
| 1010 | obj->sws2=NULL; |
|---|
| 1011 | obj->display=NULL; |
|---|
| 1012 | obj->own_display=FALSE; |
|---|
| 1013 | obj->ready=FALSE; |
|---|
| 1014 | obj->autofit=FALSE; |
|---|
| 1015 | obj->mirror=FALSE; |
|---|
| 1016 | set_vsize(obj,&def_size); |
|---|
| 1017 | f->data=obj; |
|---|
| 1018 | } |
|---|
| 1019 | |
|---|
| 1020 | |
|---|
| 1021 | static void video_out_uninit(MSFilter *f){ |
|---|
| 1022 | VideoOut *obj=(VideoOut*)f->data; |
|---|
| 1023 | if (obj->display!=NULL && obj->own_display) |
|---|
| 1024 | ms_display_destroy(obj->display); |
|---|
| 1025 | if (obj->sws1!=NULL){ |
|---|
| 1026 | ms_sws_freeContext(obj->sws1); |
|---|
| 1027 | obj->sws1=NULL; |
|---|
| 1028 | } |
|---|
| 1029 | if (obj->sws2!=NULL){ |
|---|
| 1030 | ms_sws_freeContext(obj->sws2); |
|---|
| 1031 | obj->sws2=NULL; |
|---|
| 1032 | } |
|---|
| 1033 | if (obj->local_msg!=NULL) { |
|---|
| 1034 | freemsg(obj->local_msg); |
|---|
| 1035 | obj->local_msg=NULL; |
|---|
| 1036 | } |
|---|
| 1037 | ms_free(obj); |
|---|
| 1038 | } |
|---|
| 1039 | |
|---|
| 1040 | static void video_out_prepare(MSFilter *f){ |
|---|
| 1041 | VideoOut *obj=(VideoOut*)f->data; |
|---|
| 1042 | if (obj->display==NULL){ |
|---|
| 1043 | if (default_display_desc==NULL){ |
|---|
| 1044 | ms_error("No default display built in !"); |
|---|
| 1045 | return; |
|---|
| 1046 | } |
|---|
| 1047 | obj->display=ms_display_new(default_display_desc); |
|---|
| 1048 | obj->own_display=TRUE; |
|---|
| 1049 | } |
|---|
| 1050 | if (!ms_display_init(obj->display,f,&obj->fbuf,&obj->fbuf_selfview)){ |
|---|
| 1051 | if (obj->own_display) ms_display_destroy(obj->display); |
|---|
| 1052 | obj->display=NULL; |
|---|
| 1053 | } |
|---|
| 1054 | if (obj->sws1!=NULL){ |
|---|
| 1055 | ms_sws_freeContext(obj->sws1); |
|---|
| 1056 | obj->sws1=NULL; |
|---|
| 1057 | } |
|---|
| 1058 | if (obj->sws2!=NULL){ |
|---|
| 1059 | ms_sws_freeContext(obj->sws2); |
|---|
| 1060 | obj->sws2=NULL; |
|---|
| 1061 | } |
|---|
| 1062 | if (obj->local_msg!=NULL) { |
|---|
| 1063 | freemsg(obj->local_msg); |
|---|
| 1064 | obj->local_msg=NULL; |
|---|
| 1065 | } |
|---|
| 1066 | set_corner(obj,obj->corner); |
|---|
| 1067 | obj->ready=TRUE; |
|---|
| 1068 | } |
|---|
| 1069 | |
|---|
| 1070 | static int video_out_handle_resizing(MSFilter *f, void *data){ |
|---|
| 1071 | /* to be removed */ |
|---|
| 1072 | } |
|---|
| 1073 | |
|---|
| 1074 | static int _video_out_handle_resizing(MSFilter *f, void *data){ |
|---|
| 1075 | VideoOut *s=(VideoOut*)f->data; |
|---|
| 1076 | MSDisplay *disp=s->display; |
|---|
| 1077 | if (disp!=NULL){ |
|---|
| 1078 | MSDisplayEvent ev; |
|---|
| 1079 | if (ms_display_poll_event(disp,&ev)){ |
|---|
| 1080 | if (ev.evtype==MS_DISPLAY_RESIZE_EVENT){ |
|---|
| 1081 | MSVideoSize sz; |
|---|
| 1082 | sz.width=ev.w; |
|---|
| 1083 | sz.height=ev.h; |
|---|
| 1084 | ms_filter_lock(f); |
|---|
| 1085 | if (s->ready){ |
|---|
| 1086 | re_vsize(s,&sz); |
|---|
| 1087 | s->ready=FALSE; |
|---|
| 1088 | } |
|---|
| 1089 | ms_filter_unlock(f); |
|---|
| 1090 | } |
|---|
| 1091 | } |
|---|
| 1092 | } |
|---|
| 1093 | return 0; |
|---|
| 1094 | } |
|---|
| 1095 | |
|---|
| 1096 | static void video_out_preprocess(MSFilter *f){ |
|---|
| 1097 | video_out_prepare(f); |
|---|
| 1098 | } |
|---|
| 1099 | |
|---|
| 1100 | |
|---|
| 1101 | static void video_out_process(MSFilter *f){ |
|---|
| 1102 | VideoOut *obj=(VideoOut*)f->data; |
|---|
| 1103 | mblk_t *inm; |
|---|
| 1104 | int update=0; |
|---|
| 1105 | int update_selfview=0; |
|---|
| 1106 | int i; |
|---|
| 1107 | |
|---|
| 1108 | for(i=0;i<100;++i){ |
|---|
| 1109 | _video_out_handle_resizing(f, NULL); |
|---|
| 1110 | } |
|---|
| 1111 | ms_filter_lock(f); |
|---|
| 1112 | if (!obj->ready) video_out_prepare(f); |
|---|
| 1113 | if (obj->display==NULL){ |
|---|
| 1114 | ms_filter_unlock(f); |
|---|
| 1115 | if (f->inputs[0]!=NULL) |
|---|
| 1116 | ms_queue_flush(f->inputs[0]); |
|---|
| 1117 | if (f->inputs[1]!=NULL) |
|---|
| 1118 | ms_queue_flush(f->inputs[1]); |
|---|
| 1119 | return; |
|---|
| 1120 | } |
|---|
| 1121 | /*get most recent message and draw it*/ |
|---|
| 1122 | if (f->inputs[1]!=NULL && (inm=ms_queue_peek_last(f->inputs[1]))!=0) { |
|---|
| 1123 | if (obj->corner==-1){ |
|---|
| 1124 | if (obj->local_msg!=NULL) { |
|---|
| 1125 | freemsg(obj->local_msg); |
|---|
| 1126 | obj->local_msg=NULL; |
|---|
| 1127 | } |
|---|
| 1128 | }else if (obj->fbuf_selfview.planes[0]!=NULL) { |
|---|
| 1129 | MSPicture src; |
|---|
| 1130 | if (yuv_buf_init_from_mblk(&src,inm)==0){ |
|---|
| 1131 | |
|---|
| 1132 | if (obj->sws2==NULL){ |
|---|
| 1133 | obj->sws2=ms_sws_getContext(src.w,src.h,PIX_FMT_YUV420P, |
|---|
| 1134 | obj->fbuf_selfview.w,obj->fbuf_selfview.h,PIX_FMT_YUV420P, |
|---|
| 1135 | SWS_FAST_BILINEAR, NULL, NULL, NULL); |
|---|
| 1136 | } |
|---|
| 1137 | ms_display_lock(obj->display); |
|---|
| 1138 | if (ms_sws_scale(obj->sws2,src.planes,src.strides, 0, |
|---|
| 1139 | src.h, obj->fbuf_selfview.planes, obj->fbuf_selfview.strides)<0){ |
|---|
| 1140 | ms_error("Error in ms_sws_scale()."); |
|---|
| 1141 | } |
|---|
| 1142 | if (!mblk_get_precious_flag(inm)) ms_yuv_buf_mirror(&obj->fbuf_selfview); |
|---|
| 1143 | ms_display_unlock(obj->display); |
|---|
| 1144 | update_selfview=1; |
|---|
| 1145 | } |
|---|
| 1146 | }else{ |
|---|
| 1147 | MSPicture src; |
|---|
| 1148 | if (yuv_buf_init_from_mblk(&src,inm)==0){ |
|---|
| 1149 | |
|---|
| 1150 | if (obj->sws2==NULL){ |
|---|
| 1151 | obj->sws2=ms_sws_getContext(src.w,src.h,PIX_FMT_YUV420P, |
|---|
| 1152 | obj->local_pic.w,obj->local_pic.h,PIX_FMT_YUV420P, |
|---|
| 1153 | SWS_FAST_BILINEAR, NULL, NULL, NULL); |
|---|
| 1154 | } |
|---|
| 1155 | if (obj->local_msg==NULL){ |
|---|
| 1156 | obj->local_msg=yuv_buf_alloc(&obj->local_pic, |
|---|
| 1157 | obj->local_pic.w,obj->local_pic.h); |
|---|
| 1158 | } |
|---|
| 1159 | if (obj->local_pic.planes[0]!=NULL) |
|---|
| 1160 | { |
|---|
| 1161 | if (ms_sws_scale(obj->sws2,src.planes,src.strides, 0, |
|---|
| 1162 | src.h, obj->local_pic.planes, obj->local_pic.strides)<0){ |
|---|
| 1163 | ms_error("Error in ms_sws_scale()."); |
|---|
| 1164 | } |
|---|
| 1165 | if (!mblk_get_precious_flag(inm)) ms_yuv_buf_mirror(&obj->local_pic); |
|---|
| 1166 | update=1; |
|---|
| 1167 | } |
|---|
| 1168 | } |
|---|
| 1169 | } |
|---|
| 1170 | ms_queue_flush(f->inputs[1]); |
|---|
| 1171 | } |
|---|
| 1172 | |
|---|
| 1173 | if (f->inputs[0]!=NULL && (inm=ms_queue_peek_last(f->inputs[0]))!=0) { |
|---|
| 1174 | MSPicture src; |
|---|
| 1175 | if (yuv_buf_init_from_mblk(&src,inm)==0){ |
|---|
| 1176 | MSVideoSize cur,newsize; |
|---|
| 1177 | cur.width=obj->fbuf.w; |
|---|
| 1178 | cur.height=obj->fbuf.h; |
|---|
| 1179 | newsize.width=src.w; |
|---|
| 1180 | newsize.height=src.h; |
|---|
| 1181 | if (obj->autofit && !ms_video_size_equal(newsize,obj->prevsize) ) { |
|---|
| 1182 | MSVideoSize qvga_size; |
|---|
| 1183 | qvga_size.width=MS_VIDEO_SIZE_QVGA_W; |
|---|
| 1184 | qvga_size.height=MS_VIDEO_SIZE_QVGA_H; |
|---|
| 1185 | obj->prevsize=newsize; |
|---|
| 1186 | ms_message("received size is %ix%i",newsize.width,newsize.height); |
|---|
| 1187 | /*don't resize less than QVGA, it is too small*/ |
|---|
| 1188 | if (ms_video_size_greater_than(qvga_size,newsize)){ |
|---|
| 1189 | newsize.width=MS_VIDEO_SIZE_QVGA_W; |
|---|
| 1190 | newsize.height=MS_VIDEO_SIZE_QVGA_H; |
|---|
| 1191 | } |
|---|
| 1192 | if (!ms_video_size_equal(newsize,cur)){ |
|---|
| 1193 | set_vsize(obj,&newsize); |
|---|
| 1194 | ms_message("autofit: new size is %ix%i",newsize.width,newsize.height); |
|---|
| 1195 | video_out_prepare(f); |
|---|
| 1196 | } |
|---|
| 1197 | } |
|---|
| 1198 | if (obj->sws1==NULL){ |
|---|
| 1199 | obj->sws1=ms_sws_getContext(src.w,src.h,PIX_FMT_YUV420P, |
|---|
| 1200 | obj->fbuf.w,obj->fbuf.h,PIX_FMT_YUV420P, |
|---|
| 1201 | SWS_FAST_BILINEAR, NULL, NULL, NULL); |
|---|
| 1202 | } |
|---|
| 1203 | ms_display_lock(obj->display); |
|---|
| 1204 | if (ms_sws_scale(obj->sws1,src.planes,src.strides, 0, |
|---|
| 1205 | src.h, obj->fbuf.planes, obj->fbuf.strides)<0){ |
|---|
| 1206 | ms_error("Error in ms_sws_scale()."); |
|---|
| 1207 | } |
|---|
| 1208 | if (obj->mirror && !mblk_get_precious_flag(inm)) ms_yuv_buf_mirror(&obj->fbuf); |
|---|
| 1209 | ms_display_unlock(obj->display); |
|---|
| 1210 | } |
|---|
| 1211 | update=1; |
|---|
| 1212 | ms_queue_flush(f->inputs[0]); |
|---|
| 1213 | } |
|---|
| 1214 | |
|---|
| 1215 | /*copy resized local view into main buffer, at bottom left corner:*/ |
|---|
| 1216 | if (obj->local_msg!=NULL){ |
|---|
| 1217 | MSPicture corner=obj->fbuf; |
|---|
| 1218 | MSVideoSize roi; |
|---|
| 1219 | roi.width=obj->local_pic.w; |
|---|
| 1220 | roi.height=obj->local_pic.h; |
|---|
| 1221 | corner.w=obj->local_pic.w; |
|---|
| 1222 | corner.h=obj->local_pic.h; |
|---|
| 1223 | corner.planes[0]+=obj->local_rect.x+(obj->local_rect.y*corner.strides[0]); |
|---|
| 1224 | corner.planes[1]+=(obj->local_rect.x/2)+((obj->local_rect.y/2)*corner.strides[1]); |
|---|
| 1225 | corner.planes[2]+=(obj->local_rect.x/2)+((obj->local_rect.y/2)*corner.strides[2]); |
|---|
| 1226 | corner.planes[3]=0; |
|---|
| 1227 | ms_display_lock(obj->display); |
|---|
| 1228 | yuv_buf_copy(obj->local_pic.planes,obj->local_pic.strides, |
|---|
| 1229 | corner.planes,corner.strides,roi); |
|---|
| 1230 | ms_display_unlock(obj->display); |
|---|
| 1231 | } |
|---|
| 1232 | |
|---|
| 1233 | ms_display_update(obj->display, update, update_selfview); |
|---|
| 1234 | ms_filter_unlock(f); |
|---|
| 1235 | } |
|---|
| 1236 | |
|---|
| 1237 | static int video_out_set_vsize(MSFilter *f,void *arg){ |
|---|
| 1238 | VideoOut *s=(VideoOut*)f->data; |
|---|
| 1239 | ms_filter_lock(f); |
|---|
| 1240 | set_vsize(s,(MSVideoSize*)arg); |
|---|
| 1241 | ms_filter_unlock(f); |
|---|
| 1242 | return 0; |
|---|
| 1243 | } |
|---|
| 1244 | |
|---|
| 1245 | static int video_out_set_display(MSFilter *f,void *arg){ |
|---|
| 1246 | VideoOut *s=(VideoOut*)f->data; |
|---|
| 1247 | s->display=(MSDisplay*)arg; |
|---|
| 1248 | return 0; |
|---|
| 1249 | } |
|---|
| 1250 | |
|---|
| 1251 | static int video_out_auto_fit(MSFilter *f, void *arg){ |
|---|
| 1252 | VideoOut *s=(VideoOut*)f->data; |
|---|
| 1253 | s->autofit=*(int*)arg; |
|---|
| 1254 | return 0; |
|---|
| 1255 | } |
|---|
| 1256 | |
|---|
| 1257 | static int video_out_set_corner(MSFilter *f,void *arg){ |
|---|
| 1258 | VideoOut *s=(VideoOut*)f->data; |
|---|
| 1259 | s->sv_posx=s->sv_posy=SELVIEW_POS_INACTIVE; |
|---|
| 1260 | ms_filter_lock(f); |
|---|
| 1261 | set_corner(s, *(int*)arg); |
|---|
| 1262 | if (s->display){ |
|---|
| 1263 | ms_display_lock(s->display); |
|---|
| 1264 | { |
|---|
| 1265 | int w=s->fbuf.w; |
|---|
| 1266 | int h=s->fbuf.h; |
|---|
| 1267 | int ysize=w*h; |
|---|
| 1268 | int usize=ysize/4; |
|---|
| 1269 | |
|---|
| 1270 | memset(s->fbuf.planes[0], 0, ysize); |
|---|
| 1271 | memset(s->fbuf.planes[1], 0, usize); |
|---|
| 1272 | memset(s->fbuf.planes[2], 0, usize); |
|---|
| 1273 | s->fbuf.planes[3]=NULL; |
|---|
| 1274 | } |
|---|
| 1275 | ms_display_unlock(s->display); |
|---|
| 1276 | } |
|---|
| 1277 | ms_filter_unlock(f); |
|---|
| 1278 | return 0; |
|---|
| 1279 | } |
|---|
| 1280 | |
|---|
| 1281 | static int video_out_get_corner(MSFilter *f,void *arg){ |
|---|
| 1282 | VideoOut *s=(VideoOut*)f->data; |
|---|
| 1283 | *((int*)arg)=s->corner; |
|---|
| 1284 | return 0; |
|---|
| 1285 | } |
|---|
| 1286 | |
|---|
| 1287 | static int video_out_set_scalefactor(MSFilter *f,void *arg){ |
|---|
| 1288 | VideoOut *s=(VideoOut*)f->data; |
|---|
| 1289 | s->scale_factor = *(float*)arg; |
|---|
| 1290 | if (s->scale_factor<0.5f) |
|---|
| 1291 | s->scale_factor = 0.5f; |
|---|
| 1292 | ms_filter_lock(f); |
|---|
| 1293 | set_corner(s, s->corner); |
|---|
| 1294 | if (s->display){ |
|---|
| 1295 | ms_display_lock(s->display); |
|---|
| 1296 | { |
|---|
| 1297 | int w=s->fbuf.w; |
|---|
| 1298 | int h=s->fbuf.h; |
|---|
| 1299 | int ysize=w*h; |
|---|
| 1300 | int usize=ysize/4; |
|---|
| 1301 | |
|---|
| 1302 | memset(s->fbuf.planes[0], 0, ysize); |
|---|
| 1303 | memset(s->fbuf.planes[1], 0, usize); |
|---|
| 1304 | memset(s->fbuf.planes[2], 0, usize); |
|---|
| 1305 | s->fbuf.planes[3]=NULL; |
|---|
| 1306 | } |
|---|
| 1307 | ms_display_unlock(s->display); |
|---|
| 1308 | } |
|---|
| 1309 | ms_filter_unlock(f); |
|---|
| 1310 | return 0; |
|---|
| 1311 | } |
|---|
| 1312 | |
|---|
| 1313 | static int video_out_get_scalefactor(MSFilter *f,void *arg){ |
|---|
| 1314 | VideoOut *s=(VideoOut*)f->data; |
|---|
| 1315 | *((float*)arg)=(float)s->scale_factor; |
|---|
| 1316 | return 0; |
|---|
| 1317 | } |
|---|
| 1318 | |
|---|
| 1319 | |
|---|
| 1320 | static int video_out_enable_mirroring(MSFilter *f,void *arg){ |
|---|
| 1321 | VideoOut *s=(VideoOut*)f->data; |
|---|
| 1322 | s->mirror=*(int*)arg; |
|---|
| 1323 | return 0; |
|---|
| 1324 | } |
|---|
| 1325 | |
|---|
| 1326 | static int video_out_get_native_window_id(MSFilter *f, void*arg){ |
|---|
| 1327 | VideoOut *s=(VideoOut*)f->data; |
|---|
| 1328 | unsigned long *id=(unsigned long*)arg; |
|---|
| 1329 | *id=0; |
|---|
| 1330 | if (s->display){ |
|---|
| 1331 | *id=s->display->window_id; |
|---|
| 1332 | return 0; |
|---|
| 1333 | } |
|---|
| 1334 | return -1; |
|---|
| 1335 | } |
|---|
| 1336 | |
|---|
| 1337 | static int video_out_set_selfview_pos(MSFilter *f,void *arg){ |
|---|
| 1338 | VideoOut *s=(VideoOut*)f->data; |
|---|
| 1339 | s->sv_posx=((float*)arg)[0]; |
|---|
| 1340 | s->sv_posy=((float*)arg)[1]; |
|---|
| 1341 | s->scale_factor=(float)100.0/((float*)arg)[2]; |
|---|
| 1342 | return 0; |
|---|
| 1343 | } |
|---|
| 1344 | |
|---|
| 1345 | static int video_out_get_selfview_pos(MSFilter *f,void *arg){ |
|---|
| 1346 | VideoOut *s=(VideoOut*)f->data; |
|---|
| 1347 | ((float*)arg)[0]=s->sv_posx; |
|---|
| 1348 | ((float*)arg)[1]=s->sv_posy; |
|---|
| 1349 | ((float*)arg)[2]=(float)100.0/s->scale_factor; |
|---|
| 1350 | return 0; |
|---|
| 1351 | } |
|---|
| 1352 | |
|---|
| 1353 | static int video_out_set_background_color(MSFilter *f,void *arg){ |
|---|
| 1354 | VideoOut *s=(VideoOut*)f->data; |
|---|
| 1355 | s->background_color[0]=((int*)arg)[0]; |
|---|
| 1356 | s->background_color[1]=((int*)arg)[1]; |
|---|
| 1357 | s->background_color[2]=((int*)arg)[2]; |
|---|
| 1358 | return 0; |
|---|
| 1359 | } |
|---|
| 1360 | |
|---|
| 1361 | static int video_out_get_background_color(MSFilter *f,void *arg){ |
|---|
| 1362 | VideoOut *s=(VideoOut*)f->data; |
|---|
| 1363 | ((int*)arg)[0]=s->background_color[0]; |
|---|
| 1364 | ((int*)arg)[1]=s->background_color[1]; |
|---|
| 1365 | ((int*)arg)[2]=s->background_color[2]; |
|---|
| 1366 | return 0; |
|---|
| 1367 | } |
|---|
| 1368 | |
|---|
| 1369 | static MSFilterMethod methods[]={ |
|---|
| 1370 | { MS_FILTER_SET_VIDEO_SIZE , video_out_set_vsize }, |
|---|
| 1371 | { MS_VIDEO_OUT_SET_DISPLAY , video_out_set_display}, |
|---|
| 1372 | { MS_VIDEO_OUT_SET_CORNER , video_out_set_corner}, |
|---|
| 1373 | { MS_VIDEO_OUT_AUTO_FIT , video_out_auto_fit}, |
|---|
| 1374 | { MS_VIDEO_OUT_HANDLE_RESIZING , video_out_handle_resizing}, |
|---|
| 1375 | { MS_VIDEO_OUT_ENABLE_MIRRORING , video_out_enable_mirroring}, |
|---|
| 1376 | { MS_VIDEO_OUT_GET_NATIVE_WINDOW_ID, video_out_get_native_window_id}, |
|---|
| 1377 | { MS_VIDEO_OUT_GET_CORNER , video_out_get_corner}, |
|---|
| 1378 | { MS_VIDEO_OUT_SET_SCALE_FACTOR , video_out_set_scalefactor}, |
|---|
| 1379 | { MS_VIDEO_OUT_GET_SCALE_FACTOR , video_out_get_scalefactor}, |
|---|
| 1380 | { MS_VIDEO_OUT_SET_SELFVIEW_POS , video_out_set_selfview_pos}, |
|---|
| 1381 | { MS_VIDEO_OUT_GET_SELFVIEW_POS , video_out_get_selfview_pos}, |
|---|
| 1382 | { MS_VIDEO_OUT_SET_BACKGROUND_COLOR , video_out_set_background_color}, |
|---|
| 1383 | { MS_VIDEO_OUT_GET_BACKGROUND_COLOR , video_out_get_background_color}, |
|---|
| 1384 | |
|---|
| 1385 | { 0 ,NULL} |
|---|
| 1386 | }; |
|---|
| 1387 | |
|---|
| 1388 | #ifdef _MSC_VER |
|---|
| 1389 | |
|---|
| 1390 | MSFilterDesc ms_video_out_desc={ |
|---|
| 1391 | MS_VIDEO_OUT_ID, |
|---|
| 1392 | "MSVideoOut", |
|---|
| 1393 | N_("A generic video display"), |
|---|
| 1394 | MS_FILTER_OTHER, |
|---|
| 1395 | NULL, |
|---|
| 1396 | 2, |
|---|
| 1397 | 0, |
|---|
| 1398 | video_out_init, |
|---|
| 1399 | video_out_preprocess, |
|---|
| 1400 | video_out_process, |
|---|
| 1401 | NULL, |
|---|
| 1402 | video_out_uninit, |
|---|
| 1403 | methods |
|---|
| 1404 | }; |
|---|
| 1405 | |
|---|
| 1406 | #else |
|---|
| 1407 | |
|---|
| 1408 | MSFilterDesc ms_video_out_desc={ |
|---|
| 1409 | .id=MS_VIDEO_OUT_ID, |
|---|
| 1410 | .name="MSVideoOut", |
|---|
| 1411 | .text=N_("A generic video display"), |
|---|
| 1412 | .category=MS_FILTER_OTHER, |
|---|
| 1413 | .ninputs=2, |
|---|
| 1414 | .noutputs=0, |
|---|
| 1415 | .init=video_out_init, |
|---|
| 1416 | .preprocess=video_out_preprocess, |
|---|
| 1417 | .process=video_out_process, |
|---|
| 1418 | .uninit=video_out_uninit, |
|---|
| 1419 | .methods=methods |
|---|
| 1420 | }; |
|---|
| 1421 | |
|---|
| 1422 | #endif |
|---|
| 1423 | |
|---|
| 1424 | MS_FILTER_DESC_EXPORT(ms_video_out_desc) |
|---|