Changeset 896:92f3fa1b08d7 in mediastreamer2


Ignore:
Timestamp:
Feb 25, 2010 4:14:37 PM (3 years ago)
Author:
Aymeric Moizard <jack@…>
Branch:
default
Message:

improve performance for SDL display upon resizing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/videoout.c

    r890 r896  
    4040                return d->desc->pollevent(d,ev); 
    4141        else return FALSE; 
     42} 
     43 
     44static int gcd(int m, int n) 
     45{ 
     46   if(n == 0) 
     47     return m; 
     48   else 
     49     return gcd(n, m % n); 
     50} 
     51    
     52static void reduce(int *num, int *denom) 
     53{ 
     54   int divisor = gcd(*num, *denom); 
     55   *num /= divisor; 
     56   *denom /= divisor; 
    4257} 
    4358 
     
    5570 
    5671        float sv_scalefactor; 
     72        MSVideoSize screen_size; 
    5773} SdlDisplay; 
    5874 
     
    109125static int sdl_create_window(SdlDisplay *wd, int w, int h){ 
    110126        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; 
    111139         
    112         wd->sdl_screen = SDL_SetVideoMode(w,h, 0,SDL_HWSURFACE|SDL_RESIZABLE); 
     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); 
    113156        if (wd->sdl_screen == NULL ) { 
    114157                ms_warning("no hardware for video mode: %s\n", 
    115                                                 SDL_GetError()); 
    116         } 
    117         if (wd->sdl_screen == NULL ) 
    118                 wd->sdl_screen = SDL_SetVideoMode(w,h, 0,SDL_SWSURFACE|SDL_RESIZABLE); 
    119         if (wd->sdl_screen == NULL ) { 
    120                 ms_warning("Couldn't set video mode: %s\n", 
    121                                                 SDL_GetError()); 
    122                 return -1; 
     158                                   SDL_GetError()); 
    123159        } 
    124160        if (wd->sdl_screen->flags & SDL_HWSURFACE) ms_message("SDL surface created in hardware"); 
     
    127163                once=FALSE; 
    128164        } 
    129         ms_message("Using yuv overlay."); 
    130165        wd->lay=SDL_CreateYUVOverlay(w , h ,SDL_YV12_OVERLAY,wd->sdl_screen); 
    131166        if (wd->lay==NULL){ 
     
    147182        int i; 
    148183        if (wd==NULL){ 
     184                char driver[128]; 
    149185                /* Initialize the SDL library */ 
    150186                wd=(SdlDisplay*)ms_new0(SdlDisplay,1); 
     
    157193                } 
    158194                wd->sdl_initialized=TRUE; 
     195                if (SDL_VideoDriverName(driver, sizeof(driver))){ 
     196                        ms_message("Video driver: %s", driver); 
     197                } 
    159198                ms_mutex_init(&wd->sdl_mutex,NULL); 
    160199                ms_mutex_lock(&wd->sdl_mutex); 
     200                wd->screen_size.width = fbuf->w; 
     201                wd->screen_size.height = fbuf->h; 
     202                 
    161203        }else { 
    162204                ms_mutex_lock(&wd->sdl_mutex); 
     
    170212        } 
    171213        wd->filter = f; 
    172          
     214                 
    173215        i=sdl_create_window(wd, fbuf->w, fbuf->h); 
    174216        if (i==0){ 
     
    209251        SdlDisplay *wd = (SdlDisplay*)obj->data; 
    210252        SDL_Rect rect; 
     253        int ratiow; 
     254        int ratioh; 
     255        int w; 
     256        int h; 
     257         
    211258        rect.x=0; 
    212259        rect.y=0; 
    213260        ms_mutex_lock(&wd->sdl_mutex); 
    214         rect.w=wd->lay->w; 
    215         rect.h=wd->lay->h; 
     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; 
    216286        SDL_DisplayYUVOverlay(wd->lay,&rect); 
    217287        ms_mutex_unlock(&wd->sdl_mutex); 
     
    231301                                ev->w=event.resize.w; 
    232302                                ev->h=event.resize.h; 
     303                                wd->screen_size.width = event.resize.w; 
     304                                wd->screen_size.height = event.resize.h; 
    233305                                return TRUE; 
    234306                        break; 
     
    516588                ms_error("Error in 420->rgb ms_sws_scale()."); 
    517589        } 
    518 } 
    519  
    520 static int gcd(int m, int n) 
    521 { 
    522    if(n == 0) 
    523      return m; 
    524    else 
    525      return gcd(n, m % n); 
    526 } 
    527     
    528 static void reduce(int *num, int *denom) 
    529 { 
    530    int divisor = gcd(*num, *denom); 
    531    *num /= divisor; 
    532    *denom /= divisor; 
    533590} 
    534591 
     
    924981} 
    925982 
     983static void re_vsize(VideoOut *s, MSVideoSize *sz){ 
     984        ms_message("Windows size set to %ix%i",sz->width,sz->height); 
     985} 
     986 
     987 
    926988static void set_vsize(VideoOut *s, MSVideoSize *sz){ 
    927989        s->fbuf.w=sz->width & ~0x1; 
     
    10071069 
    10081070static int video_out_handle_resizing(MSFilter *f, void *data){ 
     1071        /* to be removed */ 
     1072} 
     1073 
     1074static int _video_out_handle_resizing(MSFilter *f, void *data){ 
    10091075        VideoOut *s=(VideoOut*)f->data; 
    10101076        MSDisplay *disp=s->display; 
     
    10181084                                ms_filter_lock(f); 
    10191085                                if (s->ready){ 
    1020                                         set_vsize(s,&sz); 
     1086                                        re_vsize(s,&sz); 
    10211087                                        s->ready=FALSE; 
    10221088                                } 
     
    10381104        int update=0; 
    10391105        int update_selfview=0; 
    1040  
     1106        int i; 
     1107 
     1108        for(i=0;i<100;++i){ 
     1109                _video_out_handle_resizing(f, NULL); 
     1110        } 
    10411111        ms_filter_lock(f); 
    10421112        if (!obj->ready) video_out_prepare(f); 
Note: See TracChangeset for help on using the changeset viewer.