| 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 | |
|---|
| 32 | struct _MSDisplay; |
|---|
| 33 | |
|---|
| 34 | typedef enum _MSDisplayEventType{ |
|---|
| 35 | MS_DISPLAY_RESIZE_EVENT |
|---|
| 36 | }MSDisplayEventType; |
|---|
| 37 | |
|---|
| 38 | typedef struct _MSDisplayEvent{ |
|---|
| 39 | MSDisplayEventType evtype; |
|---|
| 40 | int w,h; |
|---|
| 41 | }MSDisplayEvent; |
|---|
| 42 | |
|---|
| 43 | typedef struct _MSDisplayDesc{ |
|---|
| 44 | /*init requests setup of the display window at the proper size, given |
|---|
| 45 | in frame_buffer argument. Memory buffer (data,strides) must be fulfilled |
|---|
| 46 | at return. init() might be called several times upon screen resize*/ |
|---|
| 47 | bool_t (*init)(struct _MSDisplay *, struct _MSFilter *f, MSPicture *frame_buffer, MSPicture *selfview_buffer); |
|---|
| 48 | void (*lock)(struct _MSDisplay *);/*lock before writing to the framebuffer*/ |
|---|
| 49 | void (*unlock)(struct _MSDisplay *);/*unlock after writing to the framebuffer*/ |
|---|
| 50 | void (*update)(struct _MSDisplay *, int new_image, int new_selfview); /*display the picture to the screen*/ |
|---|
| 51 | void (*uninit)(struct _MSDisplay *); |
|---|
| 52 | int (*pollevent)(struct _MSDisplay *, MSDisplayEvent *ev); |
|---|
| 53 | long default_window_id; |
|---|
| 54 | }MSDisplayDesc; |
|---|
| 55 | |
|---|
| 56 | typedef struct _MSDisplay{ |
|---|
| 57 | MSDisplayDesc *desc; |
|---|
| 58 | long window_id; /*window id if the display should use an existing window*/ |
|---|
| 59 | void *data; |
|---|
| 60 | bool_t use_external_window; |
|---|
| 61 | } MSDisplay; |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | #define ms_display_init(d,f,fbuf,fbuf_selfview) (d)->desc->init(d,f,fbuf,fbuf_selfview) |
|---|
| 65 | #define ms_display_lock(d) if ((d)->desc->lock) (d)->desc->lock(d) |
|---|
| 66 | #define ms_display_unlock(d) if ((d)->desc->unlock) (d)->desc->unlock(d) |
|---|
| 67 | #define ms_display_update(d, A, B) if ((d)->desc->update) (d)->desc->update(d, A, B) |
|---|
| 68 | |
|---|
| 69 | int ms_display_poll_event(MSDisplay *d, MSDisplayEvent *ev); |
|---|
| 70 | |
|---|
| 71 | extern MSDisplayDesc ms_sdl_display_desc; |
|---|
| 72 | |
|---|
| 73 | #if (defined(WIN32) || defined(_WIN32_WCE)) && !defined(MEDIASTREAMER_STATIC) |
|---|
| 74 | #if defined(MEDIASTREAMER2_EXPORTS) && defined(INVIDEOUT_C) |
|---|
| 75 | #define MSVAR_DECLSPEC __declspec(dllexport) |
|---|
| 76 | #else |
|---|
| 77 | #define MSVAR_DECLSPEC __declspec(dllimport) |
|---|
| 78 | #endif |
|---|
| 79 | #else |
|---|
| 80 | #define MSVAR_DECLSPEC extern |
|---|
| 81 | #endif |
|---|
| 82 | |
|---|
| 83 | #ifdef __cplusplus |
|---|
| 84 | extern "C"{ |
|---|
| 85 | #endif |
|---|
| 86 | |
|---|
| 87 | /*plugins can set their own display using this method:*/ |
|---|
| 88 | void ms_display_desc_set_default(MSDisplayDesc *desc); |
|---|
| 89 | |
|---|
| 90 | MSDisplayDesc * ms_display_desc_get_default(void); |
|---|
| 91 | void ms_display_desc_set_default_window_id(MSDisplayDesc *desc, long id); |
|---|
| 92 | |
|---|
| 93 | MSVAR_DECLSPEC MSDisplayDesc ms_win_display_desc; |
|---|
| 94 | |
|---|
| 95 | MSDisplay *ms_display_new(MSDisplayDesc *desc); |
|---|
| 96 | void ms_display_set_window_id(MSDisplay *d, long window_id); |
|---|
| 97 | void ms_display_destroy(MSDisplay *d); |
|---|
| 98 | |
|---|
| 99 | #define MS_VIDEO_OUT_SET_DISPLAY MS_FILTER_METHOD(MS_VIDEO_OUT_ID,0,MSDisplay*) |
|---|
| 100 | #define MS_VIDEO_OUT_HANDLE_RESIZING MS_FILTER_METHOD_NO_ARG(MS_VIDEO_OUT_ID,1) |
|---|
| 101 | #define MS_VIDEO_OUT_SET_CORNER MS_FILTER_METHOD(MS_VIDEO_OUT_ID,2,int) |
|---|
| 102 | #define MS_VIDEO_OUT_AUTO_FIT MS_FILTER_METHOD(MS_VIDEO_OUT_ID,3,int) |
|---|
| 103 | #define MS_VIDEO_OUT_ENABLE_MIRRORING MS_FILTER_METHOD(MS_VIDEO_OUT_ID,4,int) |
|---|
| 104 | #define MS_VIDEO_OUT_GET_NATIVE_WINDOW_ID MS_FILTER_METHOD(MS_VIDEO_OUT_ID,5,unsigned long) |
|---|
| 105 | #define MS_VIDEO_OUT_GET_CORNER MS_FILTER_METHOD(MS_VIDEO_OUT_ID,6,int) |
|---|
| 106 | #define MS_VIDEO_OUT_SET_SCALE_FACTOR MS_FILTER_METHOD(MS_VIDEO_OUT_ID,7,float) |
|---|
| 107 | #define MS_VIDEO_OUT_GET_SCALE_FACTOR MS_FILTER_METHOD(MS_VIDEO_OUT_ID,8,float) |
|---|
| 108 | #define MS_VIDEO_OUT_SET_SELFVIEW_POS MS_FILTER_METHOD(MS_VIDEO_OUT_ID,9,float[3]) |
|---|
| 109 | #define MS_VIDEO_OUT_GET_SELFVIEW_POS MS_FILTER_METHOD(MS_VIDEO_OUT_ID,10,float[3]) |
|---|
| 110 | #define MS_VIDEO_OUT_SET_BACKGROUND_COLOR MS_FILTER_METHOD(MS_VIDEO_OUT_ID,11,int[3]) |
|---|
| 111 | #define MS_VIDEO_OUT_GET_BACKGROUND_COLOR MS_FILTER_METHOD(MS_VIDEO_OUT_ID,12,int[3]) |
|---|
| 112 | |
|---|
| 113 | #ifdef __cplusplus |
|---|
| 114 | } |
|---|
| 115 | #endif |
|---|
| 116 | |
|---|
| 117 | #define SCALE_FACTOR 4.0f |
|---|
| 118 | #define SELVIEW_POS_INACTIVE -100.0 |
|---|
| 119 | |
|---|
| 120 | static int video_out_set_vsize(MSFilter *f,void *arg); |
|---|
| 121 | |
|---|
| 122 | int ms_display_poll_event(MSDisplay *d, MSDisplayEvent *ev){ |
|---|
| 123 | if (d->desc->pollevent) |
|---|
| 124 | return d->desc->pollevent(d,ev); |
|---|
| 125 | else return -1; |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | |
|---|
| 129 | static int gcd(int m, int n) |
|---|
| 130 | { |
|---|
| 131 | if(n == 0) |
|---|
| 132 | return m; |
|---|
| 133 | else |
|---|
| 134 | return gcd(n, m % n); |
|---|
| 135 | } |
|---|
| 136 | |
|---|
| 137 | static void reduce(int *num, int *denom) |
|---|
| 138 | { |
|---|
| 139 | int divisor = gcd(*num, *denom); |
|---|
| 140 | *num /= divisor; |
|---|
| 141 | *denom /= divisor; |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | #include <SDL/SDL.h> |
|---|
| 145 | #include <SDL/SDL_video.h> |
|---|
| 146 | |
|---|
| 147 | typedef struct _SdlDisplay{ |
|---|
| 148 | MSFilter *filter; |
|---|
| 149 | bool_t sdl_initialized; |
|---|
| 150 | ms_mutex_t sdl_mutex; |
|---|
| 151 | SDL_Surface *sdl_screen; |
|---|
| 152 | SDL_Overlay *lay; |
|---|
| 153 | |
|---|
| 154 | float sv_scalefactor; |
|---|
| 155 | MSVideoSize screen_size; |
|---|
| 156 | } SdlDisplay; |
|---|
| 157 | |
|---|
| 158 | #ifdef HAVE_X11_XLIB_H |
|---|
| 159 | |
|---|
| 160 | #include <SDL/SDL_syswm.h> |
|---|
| 161 | |
|---|
| 162 | static long sdl_get_native_window_id(){ |
|---|
| 163 | SDL_SysWMinfo info; |
|---|
| 164 | SDL_VERSION(&info.version); |
|---|
| 165 | if ( SDL_GetWMInfo(&info) ) { |
|---|
| 166 | if ( info.subsystem == SDL_SYSWM_X11 ) { |
|---|
| 167 | return (long) info.info.x11.wmwindow; |
|---|
| 168 | } |
|---|
| 169 | } |
|---|
| 170 | return 0; |
|---|
| 171 | } |
|---|
| 172 | |
|---|
| 173 | static void sdl_show_window(bool_t show){ |
|---|
| 174 | SDL_SysWMinfo info; |
|---|
| 175 | SDL_VERSION(&info.version); |
|---|
| 176 | if ( SDL_GetWMInfo(&info) ) { |
|---|
| 177 | if ( info.subsystem == SDL_SYSWM_X11 ) { |
|---|
| 178 | Display *display; |
|---|
| 179 | Window window; |
|---|
| 180 | |
|---|
| 181 | info.info.x11.lock_func(); |
|---|
| 182 | display = info.info.x11.display; |
|---|
| 183 | window = info.info.x11.wmwindow; |
|---|
| 184 | if (show) |
|---|
| 185 | XMapWindow(display,window); |
|---|
| 186 | else |
|---|
| 187 | XUnmapWindow(display,window); |
|---|
| 188 | info.info.x11.unlock_func(); |
|---|
| 189 | } |
|---|
| 190 | } |
|---|
| 191 | } |
|---|
| 192 | |
|---|
| 193 | #else |
|---|
| 194 | |
|---|
| 195 | static void sdl_show_window(bool_t show){ |
|---|
| 196 | ms_warning("SDL window show/hide not implemented"); |
|---|
| 197 | } |
|---|
| 198 | |
|---|
| 199 | static long sdl_get_native_window_id(){ |
|---|
| 200 | ms_warning("sdl_get_native_window_id not implemented"); |
|---|
| 201 | return 0; |
|---|
| 202 | } |
|---|
| 203 | |
|---|
| 204 | #endif |
|---|
| 205 | |
|---|
| 206 | static void sdl_display_uninit(MSDisplay *obj); |
|---|
| 207 | |
|---|
| 208 | static int sdl_create_window(SdlDisplay *wd, int w, int h){ |
|---|
| 209 | static bool_t once=TRUE; |
|---|
| 210 | uint32_t flags = SDL_ANYFORMAT | SDL_DOUBLEBUF | SDL_RESIZABLE; |
|---|
| 211 | const SDL_VideoInfo *info; |
|---|
| 212 | info =SDL_GetVideoInfo(); |
|---|
| 213 | if (info->wm_available) { |
|---|
| 214 | ms_message("Using window manager"); |
|---|
| 215 | } |
|---|
| 216 | if (info->hw_available) { |
|---|
| 217 | ms_message("hw surface available (%dk memory)", info->video_mem); |
|---|
| 218 | flags |= SDL_HWSURFACE; |
|---|
| 219 | } |
|---|
| 220 | else |
|---|
| 221 | flags |= SDL_SWSURFACE; |
|---|
| 222 | |
|---|
| 223 | if (info->blit_hw) { |
|---|
| 224 | ms_message("hw surface available (%dk memory)", info->video_mem); |
|---|
| 225 | flags |= SDL_ASYNCBLIT; |
|---|
| 226 | } |
|---|
| 227 | if (info->blit_hw_CC) |
|---|
| 228 | ms_message("Colorkey blits between hw surfaces: accelerated"); |
|---|
| 229 | if (info->blit_hw_A) |
|---|
| 230 | ms_message("Alpha blits between hw surfaces: accelerated"); |
|---|
| 231 | if (info->blit_sw) |
|---|
| 232 | ms_message("Copy blits from sw to hw surfaces: accelerated"); |
|---|
| 233 | if (info->blit_hw_CC) |
|---|
| 234 | ms_message("Colorkey blits between sw to hw surfaces: accelerated"); |
|---|
| 235 | if (info->blit_hw_A) |
|---|
| 236 | ms_message("Alpha blits between sw to hw surfaces: accelerated"); |
|---|
| 237 | |
|---|
| 238 | wd->sdl_screen = SDL_SetVideoMode(w,h, 0,flags); |
|---|
| 239 | if (wd->sdl_screen == NULL ) { |
|---|
| 240 | ms_warning("no hardware for video mode: %s\n", |
|---|
| 241 | SDL_GetError()); |
|---|
| 242 | } |
|---|
| 243 | wd->screen_size.width = w; |
|---|
| 244 | wd->screen_size.height = h; |
|---|
| 245 | if (wd->sdl_screen->flags & SDL_HWSURFACE) ms_message("SDL surface created in hardware"); |
|---|
| 246 | if (once) { |
|---|
| 247 | SDL_WM_SetCaption("Video window", NULL); |
|---|
| 248 | once=FALSE; |
|---|
| 249 | } |
|---|
| 250 | wd->lay=SDL_CreateYUVOverlay(w , h ,SDL_YV12_OVERLAY,wd->sdl_screen); |
|---|
| 251 | if (wd->lay==NULL){ |
|---|
| 252 | ms_warning("Couldn't create yuv overlay: %s\n", |
|---|
| 253 | SDL_GetError()); |
|---|
| 254 | return -1; |
|---|
| 255 | }else{ |
|---|
| 256 | 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, |
|---|
| 257 | wd->lay->pitches[0],wd->lay->pitches[1],wd->lay->pitches[2]); |
|---|
| 258 | ms_message("planes= %p %p %p %i %i",wd->lay->pixels[0],wd->lay->pixels[1],wd->lay->pixels[2], |
|---|
| 259 | wd->lay->pixels[1]-wd->lay->pixels[0],wd->lay->pixels[2]-wd->lay->pixels[1]); |
|---|
| 260 | } |
|---|
| 261 | SDL_ShowCursor(0);//Hide the mouse cursor if was displayed |
|---|
| 262 | return 0; |
|---|
| 263 | } |
|---|
| 264 | |
|---|
| 265 | static bool_t sdl_display_init(MSDisplay *obj, MSFilter *f, MSPicture *fbuf, MSPicture *fbuf_selfview){ |
|---|
| 266 | SdlDisplay *wd = (SdlDisplay*)obj->data; |
|---|
| 267 | int i; |
|---|
| 268 | if (wd==NULL){ |
|---|
| 269 | char driver[128]; |
|---|
| 270 | /* Initialize the SDL library */ |
|---|
| 271 | wd=(SdlDisplay*)ms_new0(SdlDisplay,1); |
|---|
| 272 | wd->filter = f; |
|---|
| 273 | obj->data=wd; |
|---|
| 274 | |
|---|
| 275 | if( SDL_Init(SDL_INIT_VIDEO) < 0 ) { |
|---|
| 276 | ms_error("Couldn't initialize SDL: %s", SDL_GetError()); |
|---|
| 277 | return FALSE; |
|---|
| 278 | } |
|---|
| 279 | wd->sdl_initialized=TRUE; |
|---|
| 280 | if (SDL_VideoDriverName(driver, sizeof(driver))){ |
|---|
| 281 | ms_message("Video driver: %s", driver); |
|---|
| 282 | } |
|---|
| 283 | ms_mutex_init(&wd->sdl_mutex,NULL); |
|---|
| 284 | ms_mutex_lock(&wd->sdl_mutex); |
|---|
| 285 | |
|---|
| 286 | }else { |
|---|
| 287 | ms_mutex_lock(&wd->sdl_mutex); |
|---|
| 288 | if (wd->lay!=NULL) |
|---|
| 289 | SDL_FreeYUVOverlay(wd->lay); |
|---|
| 290 | if (wd->sdl_screen!=NULL) |
|---|
| 291 | SDL_FreeSurface(wd->sdl_screen); |
|---|
| 292 | wd->lay=NULL; |
|---|
| 293 | wd->sdl_screen=NULL; |
|---|
| 294 | } |
|---|
| 295 | wd->filter = f; |
|---|
| 296 | |
|---|
| 297 | i=sdl_create_window(wd, fbuf->w, fbuf->h); |
|---|
| 298 | if (i==0){ |
|---|
| 299 | fbuf->planes[0]=wd->lay->pixels[0]; |
|---|
| 300 | fbuf->planes[1]=wd->lay->pixels[2]; |
|---|
| 301 | fbuf->planes[2]=wd->lay->pixels[1]; |
|---|
| 302 | fbuf->planes[3]=NULL; |
|---|
| 303 | fbuf->strides[0]=wd->lay->pitches[0]; |
|---|
| 304 | fbuf->strides[1]=wd->lay->pitches[2]; |
|---|
| 305 | fbuf->strides[2]=wd->lay->pitches[1]; |
|---|
| 306 | fbuf->strides[3]=0; |
|---|
| 307 | fbuf->w=wd->lay->w; |
|---|
| 308 | fbuf->h=wd->lay->h; |
|---|
| 309 | sdl_show_window(TRUE); |
|---|
| 310 | obj->window_id=sdl_get_native_window_id(); |
|---|
| 311 | ms_mutex_unlock(&wd->sdl_mutex); |
|---|
| 312 | return TRUE; |
|---|
| 313 | } |
|---|
| 314 | ms_mutex_unlock(&wd->sdl_mutex); |
|---|
| 315 | return FALSE; |
|---|
| 316 | } |
|---|
| 317 | |
|---|
| 318 | static void sdl_display_lock(MSDisplay *obj){ |
|---|
| 319 | SdlDisplay *wd = (SdlDisplay*)obj->data; |
|---|
| 320 | ms_mutex_lock(&wd->sdl_mutex); |
|---|
| 321 | SDL_LockYUVOverlay(wd->lay); |
|---|
| 322 | ms_mutex_unlock(&wd->sdl_mutex); |
|---|
| 323 | } |
|---|
| 324 | |
|---|
| 325 | static void sdl_display_unlock(MSDisplay *obj){ |
|---|
| 326 | SdlDisplay *wd = (SdlDisplay*)obj->data; |
|---|
| 327 | ms_mutex_lock(&wd->sdl_mutex); |
|---|
| 328 | SDL_UnlockYUVOverlay(wd->lay); |
|---|
| 329 | ms_mutex_unlock(&wd->sdl_mutex); |
|---|
| 330 | } |
|---|
| 331 | |
|---|
| 332 | static void sdl_display_update(MSDisplay *obj, int new_image, int new_selfview){ |
|---|
| 333 | SdlDisplay *wd = (SdlDisplay*)obj->data; |
|---|
| 334 | SDL_Rect rect; |
|---|
| 335 | int ratiow; |
|---|
| 336 | int ratioh; |
|---|
| 337 | int w; |
|---|
| 338 | int h; |
|---|
| 339 | |
|---|
| 340 | rect.x=0; |
|---|
| 341 | rect.y=0; |
|---|
| 342 | ms_mutex_lock(&wd->sdl_mutex); |
|---|
| 343 | |
|---|
| 344 | ratiow=wd->lay->w; |
|---|
| 345 | ratioh=wd->lay->h; |
|---|
| 346 | reduce(&ratiow, &ratioh); |
|---|
| 347 | w = wd->screen_size.width/ratiow*ratiow; |
|---|
| 348 | h = wd->screen_size.height/ratioh*ratioh; |
|---|
| 349 | |
|---|
| 350 | if (h*ratiow>w*ratioh) |
|---|
| 351 | { |
|---|
| 352 | w = w; |
|---|
| 353 | h = w*ratioh/ratiow; |
|---|
| 354 | } |
|---|
| 355 | else |
|---|
| 356 | { |
|---|
| 357 | h = h; |
|---|
| 358 | w = h*ratiow/ratioh; |
|---|
| 359 | } |
|---|
| 360 | |
|---|
| 361 | if (h*wd->lay->w!=w*wd->lay->h) |
|---|
| 362 | ms_error("wrong ratio"); |
|---|
| 363 | |
|---|
| 364 | rect.x = (wd->screen_size.width-w)/2; |
|---|
| 365 | rect.y = (wd->screen_size.height-h)/2; |
|---|
| 366 | rect.w = w; |
|---|
| 367 | rect.h = h; |
|---|
| 368 | SDL_DisplayYUVOverlay(wd->lay,&rect); |
|---|
| 369 | ms_mutex_unlock(&wd->sdl_mutex); |
|---|
| 370 | } |
|---|
| 371 | |
|---|
| 372 | static int sdl_poll_event(MSDisplay *obj, MSDisplayEvent *ev){ |
|---|
| 373 | SdlDisplay *wd = (SdlDisplay*)obj->data; |
|---|
| 374 | SDL_Event event; |
|---|
| 375 | if (wd->sdl_screen==NULL) return -1; |
|---|
| 376 | ms_mutex_lock(&wd->sdl_mutex); |
|---|
| 377 | if (SDL_PollEvent(&event)){ |
|---|
| 378 | ms_mutex_unlock(&wd->sdl_mutex); |
|---|
| 379 | switch(event.type){ |
|---|
| 380 | case SDL_VIDEORESIZE: |
|---|
| 381 | ev->evtype=MS_DISPLAY_RESIZE_EVENT; |
|---|
| 382 | ev->w=event.resize.w; |
|---|
| 383 | ev->h=event.resize.h; |
|---|
| 384 | wd->screen_size.width = event.resize.w; |
|---|
| 385 | wd->screen_size.height = event.resize.h; |
|---|
| 386 | return 1; |
|---|
| 387 | break; |
|---|
| 388 | default: |
|---|
| 389 | return 0; |
|---|
| 390 | break; |
|---|
| 391 | } |
|---|
| 392 | }else ms_mutex_unlock(&wd->sdl_mutex); |
|---|
| 393 | return -1; |
|---|
| 394 | } |
|---|
| 395 | |
|---|
| 396 | static void sdl_display_uninit(MSDisplay *obj){ |
|---|
| 397 | SdlDisplay *wd = (SdlDisplay*)obj->data; |
|---|
| 398 | SDL_Event event; |
|---|
| 399 | int i; |
|---|
| 400 | if (wd==NULL) |
|---|
| 401 | return; |
|---|
| 402 | if (wd->lay!=NULL) |
|---|
| 403 | SDL_FreeYUVOverlay(wd->lay); |
|---|
| 404 | if (wd->sdl_screen!=NULL){ |
|---|
| 405 | SDL_FreeSurface(wd->sdl_screen); |
|---|
| 406 | wd->sdl_screen=NULL; |
|---|
| 407 | } |
|---|
| 408 | wd->lay=NULL; |
|---|
| 409 | wd->sdl_screen=NULL; |
|---|
| 410 | ms_free(wd); |
|---|
| 411 | #ifdef __linux |
|---|
| 412 | /*purge the event queue before leaving*/ |
|---|
| 413 | for(i=0;SDL_PollEvent(&event) && i<100;++i){ |
|---|
| 414 | } |
|---|
| 415 | #endif |
|---|
| 416 | sdl_show_window(FALSE); |
|---|
| 417 | SDL_Quit(); |
|---|
| 418 | } |
|---|
| 419 | |
|---|
| 420 | MSDisplayDesc ms_sdl_display_desc={ |
|---|
| 421 | .init=sdl_display_init, |
|---|
| 422 | .lock=sdl_display_lock, |
|---|
| 423 | .unlock=sdl_display_unlock, |
|---|
| 424 | .update=sdl_display_update, |
|---|
| 425 | .uninit=sdl_display_uninit, |
|---|
| 426 | .pollevent=sdl_poll_event, |
|---|
| 427 | }; |
|---|
| 428 | |
|---|
| 429 | |
|---|
| 430 | MSDisplay *ms_display_new(MSDisplayDesc *desc){ |
|---|
| 431 | MSDisplay *obj=(MSDisplay *)ms_new0(MSDisplay,1); |
|---|
| 432 | obj->desc=desc; |
|---|
| 433 | obj->data=NULL; |
|---|
| 434 | return obj; |
|---|
| 435 | } |
|---|
| 436 | |
|---|
| 437 | void ms_display_set_window_id(MSDisplay *d, long id){ |
|---|
| 438 | d->window_id=id; |
|---|
| 439 | d->use_external_window=TRUE; |
|---|
| 440 | } |
|---|
| 441 | |
|---|
| 442 | void ms_display_destroy(MSDisplay *obj){ |
|---|
| 443 | obj->desc->uninit(obj); |
|---|
| 444 | ms_free(obj); |
|---|
| 445 | } |
|---|
| 446 | |
|---|
| 447 | static MSDisplayDesc *default_display_desc=&ms_sdl_display_desc; |
|---|
| 448 | |
|---|
| 449 | void ms_display_desc_set_default(MSDisplayDesc *desc){ |
|---|
| 450 | default_display_desc=desc; |
|---|
| 451 | } |
|---|
| 452 | |
|---|
| 453 | MSDisplayDesc * ms_display_desc_get_default(void){ |
|---|
| 454 | return default_display_desc; |
|---|
| 455 | } |
|---|
| 456 | |
|---|
| 457 | void ms_display_desc_set_default_window_id(MSDisplayDesc *desc, long id){ |
|---|
| 458 | desc->default_window_id=id; |
|---|
| 459 | } |
|---|
| 460 | |
|---|
| 461 | typedef struct VideoOut |
|---|
| 462 | { |
|---|
| 463 | struct Rational {int num; int den;} ratio; |
|---|
| 464 | MSPicture fbuf; |
|---|
| 465 | MSPicture fbuf_selfview; |
|---|
| 466 | MSPicture local_pic; |
|---|
| 467 | MSRect local_rect; |
|---|
| 468 | mblk_t *local_msg; |
|---|
| 469 | MSVideoSize prevsize; |
|---|
| 470 | int corner; /*for selfview*/ |
|---|
| 471 | float scale_factor; /*for selfview*/ |
|---|
| 472 | float sv_posx,sv_posy; |
|---|
| 473 | int background_color[3]; |
|---|
| 474 | |
|---|
| 475 | MSScalerContext *sws1; |
|---|
| 476 | MSScalerContext *sws2; |
|---|
| 477 | MSDisplay *display; |
|---|
| 478 | bool_t own_display; |
|---|
| 479 | bool_t ready; |
|---|
| 480 | bool_t autofit; |
|---|
| 481 | bool_t mirror; |
|---|
| 482 | } VideoOut; |
|---|
| 483 | |
|---|
| 484 | static void set_corner(VideoOut *s, int corner) |
|---|
| 485 | { |
|---|
| 486 | s->corner=corner; |
|---|
| 487 | s->local_pic.w=((int)(s->fbuf.w/s->scale_factor)) & ~0x1; |
|---|
| 488 | s->local_pic.h=((int)(s->fbuf.h/s->scale_factor)) & ~0x1; |
|---|
| 489 | s->local_rect.w=s->local_pic.w; |
|---|
| 490 | s->local_rect.h=s->local_pic.h; |
|---|
| 491 | if (corner==1) { |
|---|
| 492 | /* top left corner */ |
|---|
| 493 | s->local_rect.x=0; |
|---|
| 494 | s->local_rect.y=0; |
|---|
| 495 | } else if (corner==2) { |
|---|
| 496 | /* top right corner */ |
|---|
| 497 | s->local_rect.x=s->fbuf.w-s->local_pic.w; |
|---|
| 498 | s->local_rect.y=0; |
|---|
| 499 | } else if (corner==3) { |
|---|
| 500 | /* bottom left corner */ |
|---|
| 501 | s->local_rect.x=0; |
|---|
| 502 | s->local_rect.y=s->fbuf.h-s->local_pic.h; |
|---|
| 503 | } else { |
|---|
| 504 | /* default: bottom right corner */ |
|---|
| 505 | /* corner can be set to -1: to disable the self view... */ |
|---|
| 506 | s->local_rect.x=s->fbuf.w-s->local_pic.w; |
|---|
| 507 | s->local_rect.y=s->fbuf.h-s->local_pic.h; |
|---|
| 508 | } |
|---|
| 509 | s->fbuf_selfview.w=(s->fbuf.w/1) & ~0x1; |
|---|
| 510 | s->fbuf_selfview.h=(s->fbuf.h/1) & ~0x1; |
|---|
| 511 | } |
|---|
| 512 | |
|---|
| 513 | |
|---|
| 514 | |
|---|
| 515 | static void set_vsize(VideoOut *s, MSVideoSize *sz){ |
|---|
| 516 | s->fbuf.w=sz->width & ~0x1; |
|---|
| 517 | s->fbuf.h=sz->height & ~0x1; |
|---|
| 518 | set_corner(s,s->corner); |
|---|
| 519 | ms_message("Video size set to %ix%i",s->fbuf.w,s->fbuf.h); |
|---|
| 520 | } |
|---|
| 521 | |
|---|
| 522 | static void video_out_init(MSFilter *f){ |
|---|
| 523 | VideoOut *obj=(VideoOut*)ms_new0(VideoOut,1); |
|---|
| 524 | MSVideoSize def_size; |
|---|
| 525 | obj->ratio.num=11; |
|---|
| 526 | obj->ratio.den=9; |
|---|
| 527 | def_size.width=MS_VIDEO_SIZE_CIF_W; |
|---|
| 528 | def_size.height=MS_VIDEO_SIZE_CIF_H; |
|---|
| 529 | obj->prevsize.width=0; |
|---|
| 530 | obj->prevsize.height=0; |
|---|
| 531 | obj->local_msg=NULL; |
|---|
| 532 | obj->corner=0; |
|---|
| 533 | obj->scale_factor=SCALE_FACTOR; |
|---|
| 534 | obj->sv_posx=obj->sv_posy=SELVIEW_POS_INACTIVE; |
|---|
| 535 | obj->background_color[0]=obj->background_color[1]=obj->background_color[2]=0; |
|---|
| 536 | obj->sws1=NULL; |
|---|
| 537 | obj->sws2=NULL; |
|---|
| 538 | obj->display=NULL; |
|---|
| 539 | obj->own_display=FALSE; |
|---|
| 540 | obj->ready=FALSE; |
|---|
| 541 | obj->autofit=FALSE; |
|---|
| 542 | obj->mirror=FALSE; |
|---|
| 543 | set_vsize(obj,&def_size); |
|---|
| 544 | f->data=obj; |
|---|
| 545 | } |
|---|
| 546 | |
|---|
| 547 | |
|---|
| 548 | static void video_out_uninit(MSFilter *f){ |
|---|
| 549 | VideoOut *obj=(VideoOut*)f->data; |
|---|
| 550 | if (obj->display!=NULL && obj->own_display) |
|---|
| 551 | ms_display_destroy(obj->display); |
|---|
| 552 | if (obj->sws1!=NULL){ |
|---|
| 553 | ms_scaler_context_free(obj->sws1); |
|---|
| 554 | obj->sws1=NULL; |
|---|
| 555 | } |
|---|
| 556 | if (obj->sws2!=NULL){ |
|---|
| 557 | ms_scaler_context_free(obj->sws2); |
|---|
| 558 | obj->sws2=NULL; |
|---|
| 559 | } |
|---|
| 560 | if (obj->local_msg!=NULL) { |
|---|
| 561 | freemsg(obj->local_msg); |
|---|
| 562 | obj->local_msg=NULL; |
|---|
| 563 | } |
|---|
| 564 | ms_free(obj); |
|---|
| 565 | } |
|---|
| 566 | |
|---|
| 567 | static void video_out_prepare(MSFilter *f){ |
|---|
| 568 | VideoOut *obj=(VideoOut*)f->data; |
|---|
| 569 | if (obj->display==NULL){ |
|---|
| 570 | if (default_display_desc==NULL){ |
|---|
| 571 | ms_error("No default display built in !"); |
|---|
| 572 | return; |
|---|
| 573 | } |
|---|
| 574 | obj->display=ms_display_new(default_display_desc); |
|---|
| 575 | obj->own_display=TRUE; |
|---|
| 576 | } |
|---|
| 577 | if (!ms_display_init(obj->display,f,&obj->fbuf,&obj->fbuf_selfview)){ |
|---|
| 578 | if (obj->own_display) ms_display_destroy(obj->display); |
|---|
| 579 | obj->display=NULL; |
|---|
| 580 | } |
|---|
| 581 | if (obj->sws1!=NULL){ |
|---|
| 582 | ms_scaler_context_free(obj->sws1); |
|---|
| 583 | obj->sws1=NULL; |
|---|
| 584 | } |
|---|
| 585 | if (obj->sws2!=NULL){ |
|---|
| 586 | ms_scaler_context_free(obj->sws2); |
|---|
| 587 | obj->sws2=NULL; |
|---|
| 588 | } |
|---|
| 589 | if (obj->local_msg!=NULL) { |
|---|
| 590 | freemsg(obj->local_msg); |
|---|
| 591 | obj->local_msg=NULL; |
|---|
| 592 | } |
|---|
| 593 | set_corner(obj,obj->corner); |
|---|
| 594 | obj->ready=TRUE; |
|---|
| 595 | } |
|---|
| 596 | |
|---|
| 597 | static int video_out_handle_resizing(MSFilter *f, void *data){ |
|---|
| 598 | /* to be removed */ |
|---|
| 599 | return -1; |
|---|
| 600 | } |
|---|
| 601 | |
|---|
| 602 | static int _video_out_handle_resizing(MSFilter *f, void *data){ |
|---|
| 603 | VideoOut *s=(VideoOut*)f->data; |
|---|
| 604 | MSDisplay *disp=s->display; |
|---|
| 605 | int ret = -1; |
|---|
| 606 | if (disp!=NULL){ |
|---|
| 607 | MSDisplayEvent ev; |
|---|
| 608 | ret = ms_display_poll_event(disp,&ev); |
|---|
| 609 | if (ret>0){ |
|---|
| 610 | if (ev.evtype==MS_DISPLAY_RESIZE_EVENT){ |
|---|
| 611 | MSVideoSize sz; |
|---|
| 612 | sz.width=ev.w; |
|---|
| 613 | sz.height=ev.h; |
|---|
| 614 | ms_filter_lock(f); |
|---|
| 615 | if (s->ready){ |
|---|
| 616 | set_vsize(s,&sz); |
|---|
| 617 | s->ready=FALSE; |
|---|
| 618 | } |
|---|
| 619 | ms_filter_unlock(f); |
|---|
| 620 | } |
|---|
| 621 | return 1; |
|---|
| 622 | } |
|---|
| 623 | } |
|---|
| 624 | return ret; |
|---|
| 625 | } |
|---|
| 626 | |
|---|
| 627 | static void video_out_preprocess(MSFilter *f){ |
|---|
| 628 | video_out_prepare(f); |
|---|
| 629 | } |
|---|
| 630 | |
|---|
| 631 | |
|---|
| 632 | static void video_out_process(MSFilter *f){ |
|---|
| 633 | VideoOut *obj=(VideoOut*)f->data; |
|---|
| 634 | mblk_t *inm; |
|---|
| 635 | int update=0; |
|---|
| 636 | int update_selfview=0; |
|---|
| 637 | int i; |
|---|
| 638 | |
|---|
| 639 | for(i=0;i<100;++i){ |
|---|
| 640 | int ret = _video_out_handle_resizing(f, NULL); |
|---|
| 641 | if (ret<0) |
|---|
| 642 | break; |
|---|
| 643 | } |
|---|
| 644 | ms_filter_lock(f); |
|---|
| 645 | if (!obj->ready) video_out_prepare(f); |
|---|
| 646 | if (obj->display==NULL){ |
|---|
| 647 | ms_filter_unlock(f); |
|---|
| 648 | if (f->inputs[0]!=NULL) |
|---|
| 649 | ms_queue_flush(f->inputs[0]); |
|---|
| 650 | if (f->inputs[1]!=NULL) |
|---|
| 651 | ms_queue_flush(f->inputs[1]); |
|---|
| 652 | return; |
|---|
| 653 | } |
|---|
| 654 | /*get most recent message and draw it*/ |
|---|
| 655 | if (f->inputs[1]!=NULL && (inm=ms_queue_peek_last(f->inputs[1]))!=0) { |
|---|
| 656 | if (obj->corner==-1){ |
|---|
| 657 | if (obj->local_msg!=NULL) { |
|---|
| 658 | freemsg(obj->local_msg); |
|---|
| 659 | obj->local_msg=NULL; |
|---|
| 660 | } |
|---|
| 661 | }else if (obj->fbuf_selfview.planes[0]!=NULL) { |
|---|
| 662 | MSPicture src; |
|---|
| 663 | if (ms_yuv_buf_init_from_mblk(&src,inm)==0){ |
|---|
| 664 | |
|---|
| 665 | if (obj->sws2==NULL){ |
|---|
| 666 | obj->sws2=ms_scaler_create_context(src.w,src.h,MS_YUV420P, |
|---|
| 667 | obj->fbuf_selfview.w,obj->fbuf_selfview.h,MS_YUV420P, |
|---|
| 668 | MS_SCALER_METHOD_BILINEAR); |
|---|
| 669 | } |
|---|
| 670 | ms_display_lock(obj->display); |
|---|
| 671 | if (ms_scaler_process(obj->sws2,src.planes,src.strides,obj->fbuf_selfview.planes, obj->fbuf_selfview.strides)<0){ |
|---|
| 672 | ms_error("Error in ms_sws_scale()."); |
|---|
| 673 | } |
|---|
| 674 | if (!mblk_get_precious_flag(inm)) ms_yuv_buf_mirror(&obj->fbuf_selfview); |
|---|
| 675 | ms_display_unlock(obj->display); |
|---|
| 676 | update_selfview=1; |
|---|
| 677 | } |
|---|
| 678 | }else{ |
|---|
| 679 | MSPicture src; |
|---|
| 680 | if (ms_yuv_buf_init_from_mblk(&src,inm)==0){ |
|---|
| 681 | |
|---|
| 682 | if (obj->sws2==NULL){ |
|---|
| 683 | obj->sws2=ms_scaler_create_context(src.w,src.h,MS_YUV420P, |
|---|
| 684 | obj->local_pic.w,obj->local_pic.h,MS_YUV420P, |
|---|
| 685 | MS_SCALER_METHOD_BILINEAR); |
|---|
| 686 | } |
|---|
| 687 | if (obj->local_msg==NULL){ |
|---|
| 688 | obj->local_msg=ms_yuv_buf_alloc(&obj->local_pic, |
|---|
| 689 | obj->local_pic.w,obj->local_pic.h); |
|---|
| 690 | } |
|---|
| 691 | if (obj->local_pic.planes[0]!=NULL) |
|---|
| 692 | { |
|---|
| 693 | if (ms_scaler_process(obj->sws2,src.planes,src.strides,obj->local_pic.planes, obj->local_pic.strides)<0){ |
|---|
| 694 | ms_error("Error in ms_sws_scale()."); |
|---|
| 695 | } |
|---|
| 696 | if (!mblk_get_precious_flag(inm)) ms_yuv_buf_mirror(&obj->local_pic); |
|---|
| 697 | update=1; |
|---|
| 698 | } |
|---|
| 699 | } |
|---|
| 700 | } |
|---|
| 701 | ms_queue_flush(f->inputs[1]); |
|---|
| 702 | } |
|---|
| 703 | |
|---|
| 704 | if (f->inputs[0]!=NULL && (inm=ms_queue_peek_last(f->inputs[0]))!=0) { |
|---|
| 705 | MSPicture src; |
|---|
| 706 | if (ms_yuv_buf_init_from_mblk(&src,inm)==0){ |
|---|
| 707 | MSVideoSize cur,newsize; |
|---|
| 708 | cur.width=obj->fbuf.w; |
|---|
| 709 | cur.height=obj->fbuf.h; |
|---|
| 710 | newsize.width=src.w; |
|---|
| 711 | newsize.height=src.h; |
|---|
| 712 | if (obj->autofit && !ms_video_size_equal(newsize,obj->prevsize) ) { |
|---|
| 713 | MSVideoSize qvga_size; |
|---|
| 714 | qvga_size.width=MS_VIDEO_SIZE_QVGA_W; |
|---|
| 715 | qvga_size.height=MS_VIDEO_SIZE_QVGA_H; |
|---|
| 716 | obj->prevsize=newsize; |
|---|
| 717 | ms_message("received size is %ix%i",newsize.width,newsize.height); |
|---|
| 718 | /*don't resize less than QVGA, it is too small*/ |
|---|
| 719 | if (ms_video_size_greater_than(qvga_size,newsize)){ |
|---|
| 720 | newsize.width=MS_VIDEO_SIZE_QVGA_W; |
|---|
| 721 | newsize.height=MS_VIDEO_SIZE_QVGA_H; |
|---|
| 722 | } |
|---|
| 723 | if (!ms_video_size_equal(newsize,cur)){ |
|---|
| 724 | set_vsize(obj,&newsize); |
|---|
| 725 | ms_message("autofit: new size is %ix%i",newsize.width,newsize.height); |
|---|
| 726 | video_out_prepare(f); |
|---|
| 727 | } |
|---|
| 728 | } |
|---|
| 729 | if (obj->sws1==NULL){ |
|---|
| 730 | obj->sws1=ms_scaler_create_context(src.w,src.h,MS_YUV420P, |
|---|
| 731 | obj->fbuf.w,obj->fbuf.h,MS_YUV420P, |
|---|
| 732 | MS_SCALER_METHOD_BILINEAR); |
|---|
| 733 | } |
|---|
| 734 | ms_display_lock(obj->display); |
|---|
| 735 | if (ms_scaler_process(obj->sws1,src.planes,src.strides,obj->fbuf.planes, obj->fbuf.strides)<0){ |
|---|
| 736 | ms_error("Error in ms_sws_scale()."); |
|---|
| 737 | } |
|---|
| 738 | if (obj->mirror && !mblk_get_precious_flag(inm)) ms_yuv_buf_mirror(&obj->fbuf); |
|---|
| 739 | ms_display_unlock(obj->display); |
|---|
| 740 | } |
|---|
| 741 | update=1; |
|---|
| 742 | ms_queue_flush(f->inputs[0]); |
|---|
| 743 | } |
|---|
| 744 | |
|---|
| 745 | /*copy resized local view into main buffer, at bottom left corner:*/ |
|---|
| 746 | if (obj->local_msg!=NULL){ |
|---|
| 747 | MSPicture corner=obj->fbuf; |
|---|
| 748 | MSVideoSize roi; |
|---|
| 749 | roi.width=obj->local_pic.w; |
|---|
| 750 | roi.height=obj->local_pic.h; |
|---|
| 751 | corner.w=obj->local_pic.w; |
|---|
| 752 | corner.h=obj->local_pic.h; |
|---|
| 753 | corner.planes[0]+=obj->local_rect.x+(obj->local_rect.y*corner.strides[0]); |
|---|
| 754 | corner.planes[1]+=(obj->local_rect.x/2)+((obj->local_rect.y/2)*corner.strides[1]); |
|---|
| 755 | corner.planes[2]+=(obj->local_rect.x/2)+((obj->local_rect.y/2)*corner.strides[2]); |
|---|
| 756 | corner.planes[3]=0; |
|---|
| 757 | ms_display_lock(obj->display); |
|---|
| 758 | ms_yuv_buf_copy(obj->local_pic.planes,obj->local_pic.strides, |
|---|
| 759 | corner.planes,corner.strides,roi); |
|---|
| 760 | ms_display_unlock(obj->display); |
|---|
| 761 | } |
|---|
| 762 | |
|---|
| 763 | ms_display_update(obj->display, update, update_selfview); |
|---|
| 764 | ms_filter_unlock(f); |
|---|
| 765 | } |
|---|
| 766 | |
|---|
| 767 | static int video_out_set_vsize(MSFilter *f,void *arg){ |
|---|
| 768 | VideoOut *s=(VideoOut*)f->data; |
|---|
| 769 | ms_filter_lock(f); |
|---|
| 770 | set_vsize(s,(MSVideoSize*)arg); |
|---|
| 771 | ms_filter_unlock(f); |
|---|
| 772 | return 0; |
|---|
| 773 | } |
|---|
| 774 | |
|---|
| 775 | static int video_out_set_display(MSFilter *f,void *arg){ |
|---|
| 776 | VideoOut *s=(VideoOut*)f->data; |
|---|
| 777 | s->display=(MSDisplay*)arg; |
|---|
| 778 | return 0; |
|---|
| 779 | } |
|---|
| 780 | |
|---|
| 781 | static int video_out_auto_fit(MSFilter *f, void *arg){ |
|---|
| 782 | VideoOut *s=(VideoOut*)f->data; |
|---|
| 783 | s->autofit=*(int*)arg; |
|---|
| 784 | return 0; |
|---|
| 785 | } |
|---|
| 786 | |
|---|
| 787 | static int video_out_set_corner(MSFilter *f,void *arg){ |
|---|
| 788 | VideoOut *s=(VideoOut*)f->data; |
|---|
| 789 | s->sv_posx=s->sv_posy=SELVIEW_POS_INACTIVE; |
|---|
| 790 | ms_filter_lock(f); |
|---|
| 791 | set_corner(s, *(int*)arg); |
|---|
| 792 | if (s->display){ |
|---|
| 793 | ms_display_lock(s->display); |
|---|
| 794 | { |
|---|
| 795 | int w=s->fbuf.w; |
|---|
| 796 | int h=s->fbuf.h; |
|---|
| 797 | int ysize=w*h; |
|---|
| 798 | int usize=ysize/4; |
|---|
| 799 | |
|---|
| 800 | memset(s->fbuf.planes[0], 0, ysize); |
|---|
| 801 | memset(s->fbuf.planes[1], 0, usize); |
|---|
| 802 | memset(s->fbuf.planes[2], 0, usize); |
|---|
| 803 | s->fbuf.planes[3]=NULL; |
|---|
| 804 | } |
|---|
| 805 | ms_display_unlock(s->display); |
|---|
| 806 | } |
|---|
| 807 | ms_filter_unlock(f); |
|---|
| 808 | return 0; |
|---|
| 809 | } |
|---|
| 810 | |
|---|
| 811 | static int video_out_get_corner(MSFilter *f,void *arg){ |
|---|
| 812 | VideoOut *s=(VideoOut*)f->data; |
|---|
| 813 | *((int*)arg)=s->corner; |
|---|
| 814 | return 0; |
|---|
| 815 | } |
|---|
| 816 | |
|---|
| 817 | static int video_out_set_scalefactor(MSFilter *f,void *arg){ |
|---|
| 818 | VideoOut *s=(VideoOut*)f->data; |
|---|
| 819 | s->scale_factor = *(float*)arg; |
|---|
| 820 | if (s->scale_factor<0.5f) |
|---|
| 821 | s->scale_factor = 0.5f; |
|---|
| 822 | ms_filter_lock(f); |
|---|
| 823 | set_corner(s, s->corner); |
|---|
| 824 | if (s->display){ |
|---|
| 825 | ms_display_lock(s->display); |
|---|
| 826 | { |
|---|
| 827 | int w=s->fbuf.w; |
|---|
| 828 | int h=s->fbuf.h; |
|---|
| 829 | int ysize=w*h; |
|---|
| 830 | int usize=ysize/4; |
|---|
| 831 | |
|---|
| 832 | memset(s->fbuf.planes[0], 0, ysize); |
|---|
| 833 | memset(s->fbuf.planes[1], 0, usize); |
|---|
| 834 | memset(s->fbuf.planes[2], 0, usize); |
|---|
| 835 | s->fbuf.planes[3]=NULL; |
|---|
| 836 | } |
|---|
| 837 | ms_display_unlock(s->display); |
|---|
| 838 | } |
|---|
| 839 | ms_filter_unlock(f); |
|---|
| 840 | return 0; |
|---|
| 841 | } |
|---|
| 842 | |
|---|
| 843 | static int video_out_get_scalefactor(MSFilter *f,void *arg){ |
|---|
| 844 | VideoOut *s=(VideoOut*)f->data; |
|---|
| 845 | *((float*)arg)=(float)s->scale_factor; |
|---|
| 846 | return 0; |
|---|
| 847 | } |
|---|
| 848 | |
|---|
| 849 | |
|---|
| 850 | static int video_out_enable_mirroring(MSFilter *f,void *arg){ |
|---|
| 851 | VideoOut *s=(VideoOut*)f->data; |
|---|
| 852 | s->mirror=*(int*)arg; |
|---|
| 853 | return 0; |
|---|
| 854 | } |
|---|
| 855 | |
|---|
| 856 | static int video_out_get_native_window_id(MSFilter *f, void*arg){ |
|---|
| 857 | VideoOut *s=(VideoOut*)f->data; |
|---|
| 858 | unsigned long *id=(unsigned long*)arg; |
|---|
| 859 | *id=0; |
|---|
| 860 | if (s->display){ |
|---|
| 861 | *id=s->display->window_id; |
|---|
| 862 | return 0; |
|---|
| 863 | } |
|---|
| 864 | return -1; |
|---|
| 865 | } |
|---|
| 866 | |
|---|
| 867 | static int video_out_set_selfview_pos(MSFilter *f,void *arg){ |
|---|
| 868 | VideoOut *s=(VideoOut*)f->data; |
|---|
| 869 | s->sv_posx=((float*)arg)[0]; |
|---|
| 870 | s->sv_posy=((float*)arg)[1]; |
|---|
| 871 | s->scale_factor=(float)100.0/((float*)arg)[2]; |
|---|
| 872 | return 0; |
|---|
| 873 | } |
|---|
| 874 | |
|---|
| 875 | static int video_out_get_selfview_pos(MSFilter *f,void *arg){ |
|---|
| 876 | VideoOut *s=(VideoOut*)f->data; |
|---|
| 877 | ((float*)arg)[0]=s->sv_posx; |
|---|
| 878 | ((float*)arg)[1]=s->sv_posy; |
|---|
| 879 | ((float*)arg)[2]=(float)100.0/s->scale_factor; |
|---|
| 880 | return 0; |
|---|
| 881 | } |
|---|
| 882 | |
|---|
| 883 | static int video_out_set_background_color(MSFilter *f,void *arg){ |
|---|
| 884 | VideoOut *s=(VideoOut*)f->data; |
|---|
| 885 | s->background_color[0]=((int*)arg)[0]; |
|---|
| 886 | s->background_color[1]=((int*)arg)[1]; |
|---|
| 887 | s->background_color[2]=((int*)arg)[2]; |
|---|
| 888 | return 0; |
|---|
| 889 | } |
|---|
| 890 | |
|---|
| 891 | static int video_out_get_background_color(MSFilter *f,void *arg){ |
|---|
| 892 | VideoOut *s=(VideoOut*)f->data; |
|---|
| 893 | ((int*)arg)[0]=s->background_color[0]; |
|---|
| 894 | ((int*)arg)[1]=s->background_color[1]; |
|---|
| 895 | ((int*)arg)[2]=s->background_color[2]; |
|---|
| 896 | return 0; |
|---|
| 897 | } |
|---|
| 898 | |
|---|
| 899 | static MSFilterMethod methods[]={ |
|---|
| 900 | { MS_FILTER_SET_VIDEO_SIZE , video_out_set_vsize }, |
|---|
| 901 | { MS_VIDEO_OUT_SET_DISPLAY , video_out_set_display}, |
|---|
| 902 | { MS_VIDEO_OUT_SET_CORNER , video_out_set_corner}, |
|---|
| 903 | { MS_VIDEO_OUT_AUTO_FIT , video_out_auto_fit}, |
|---|
| 904 | { MS_VIDEO_OUT_HANDLE_RESIZING , video_out_handle_resizing}, |
|---|
| 905 | { MS_VIDEO_OUT_ENABLE_MIRRORING , video_out_enable_mirroring}, |
|---|
| 906 | { MS_VIDEO_OUT_GET_NATIVE_WINDOW_ID, video_out_get_native_window_id}, |
|---|
| 907 | { MS_VIDEO_OUT_GET_CORNER , video_out_get_corner}, |
|---|
| 908 | { MS_VIDEO_OUT_SET_SCALE_FACTOR , video_out_set_scalefactor}, |
|---|
| 909 | { MS_VIDEO_OUT_GET_SCALE_FACTOR , video_out_get_scalefactor}, |
|---|
| 910 | { MS_VIDEO_OUT_SET_SELFVIEW_POS , video_out_set_selfview_pos}, |
|---|
| 911 | { MS_VIDEO_OUT_GET_SELFVIEW_POS , video_out_get_selfview_pos}, |
|---|
| 912 | { MS_VIDEO_OUT_SET_BACKGROUND_COLOR , video_out_set_background_color}, |
|---|
| 913 | { MS_VIDEO_OUT_GET_BACKGROUND_COLOR , video_out_get_background_color}, |
|---|
| 914 | /* methods for compatibility with the MSVideoDisplay interface*/ |
|---|
| 915 | { MS_VIDEO_DISPLAY_SET_LOCAL_VIEW_MODE , video_out_set_corner }, |
|---|
| 916 | { MS_VIDEO_DISPLAY_ENABLE_AUTOFIT , video_out_auto_fit }, |
|---|
| 917 | { MS_VIDEO_DISPLAY_ENABLE_MIRRORING , video_out_enable_mirroring }, |
|---|
| 918 | { MS_VIDEO_DISPLAY_GET_NATIVE_WINDOW_ID , video_out_get_native_window_id }, |
|---|
| 919 | { MS_VIDEO_DISPLAY_SET_LOCAL_VIEW_SCALEFACTOR , video_out_set_scalefactor }, |
|---|
| 920 | { MS_VIDEO_DISPLAY_SET_BACKGROUND_COLOR , video_out_set_background_color}, |
|---|
| 921 | |
|---|
| 922 | { 0 ,NULL} |
|---|
| 923 | }; |
|---|
| 924 | |
|---|
| 925 | MSFilterDesc ms_video_out_desc={ |
|---|
| 926 | .id=MS_VIDEO_OUT_ID, |
|---|
| 927 | .name="MSVideoOut", |
|---|
| 928 | .text=N_("A SDL-based video display"), |
|---|
| 929 | .category=MS_FILTER_OTHER, |
|---|
| 930 | .ninputs=2, |
|---|
| 931 | .noutputs=0, |
|---|
| 932 | .init=video_out_init, |
|---|
| 933 | .preprocess=video_out_preprocess, |
|---|
| 934 | .process=video_out_process, |
|---|
| 935 | .uninit=video_out_uninit, |
|---|
| 936 | .methods=methods |
|---|
| 937 | }; |
|---|
| 938 | |
|---|
| 939 | |
|---|
| 940 | MS_FILTER_DESC_EXPORT(ms_video_out_desc) |
|---|
| 941 | |
|---|