Changeset a2caeb589c2a22159eccda561298807fe961adc7

Show
Ignore:
Timestamp:
06/09/08 10:05:35 (3 months ago)
Author:
Antoine Cellerier <dionoea@videolan.org>
git-committer:
Antoine Cellerier <dionoea@videolan.org> 1212998735 +0200
git-parent:

[24463d005000387f52b962cc29558981e6975025]

git-author:
Antoine Cellerier <dionoea@videolan.org> 1212878840 +0200
Message:

Remove crop/padd code from imgresample module. Imgresample is now only
1 submodule (well, 1 main module) which can take care of resizing and
chroma conversion (basically it's the old chroma.c code). All the files
have been merged in imgresample.c. In the long run I might split
resizing and chroma conversion to 2 submodules (performance impact would
be nil). (This is untested.)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/codec/ffmpeg/Modules.am

    r21574c3 ra2caeb5  
    2020SOURCES_imgresample = \ 
    2121    imgresample.c \ 
    22     imgresample.h \ 
    23     chroma.c \ 
    24     video_filter.c \ 
    2522    chroma.h \ 
    2623    $(NULL) 
  • modules/codec/ffmpeg/imgresample.c

    r24463d0 ra2caeb5  
    3232#include <vlc_common.h> 
    3333#include <vlc_plugin.h> 
    34 #include <vlc_codec.h> 
    35  
    36 #include "imgresample.h" 
     34#include <vlc_vout.h> 
     35#include <vlc_filter.h> 
     36 
     37/* ffmpeg header */ 
     38#ifdef HAVE_LIBAVCODEC_AVCODEC_H 
     39#   include <libavcodec/avcodec.h> 
     40#elif defined(HAVE_FFMPEG_AVCODEC_H) 
     41#   include <ffmpeg/avcodec.h> 
     42#else 
     43#   include <avcodec.h> 
     44#endif 
     45 
     46#include "chroma.h" 
     47 
     48/***************************************************************************** 
     49 * Local prototypes 
     50 *****************************************************************************/ 
     51static int  OpenFilter( vlc_object_t * ); 
     52static void CloseFilter( vlc_object_t * ); 
     53 
     54static void Conversion( filter_t *, picture_t *, picture_t * ); 
     55static picture_t *Conversion_Filter( filter_t *, picture_t * ); 
    3756 
    3857/***************************************************************************** 
     
    4362    set_callbacks( OpenFilter, CloseFilter ); 
    4463    set_description( N_("FFmpeg video filter") ); 
    45  
    46     /* crop/padd submodule */ 
    47     add_submodule(); 
    48     set_capability( "crop padd", 10 ); /* FIXME / Remove */ 
    49     set_callbacks( OpenCropPadd, CloseFilter ); 
    50     set_description( N_("FFmpeg crop padd filter") ); 
    51  
    52     /* chroma conversion submodule */ 
    53     add_submodule(); 
    54     set_capability( "video filter2", 50 ); 
    55     set_callbacks( OpenChroma, CloseChroma ); 
    56     set_description( N_("FFmpeg chroma conversion") ); 
    5764vlc_module_end(); 
     65 
     66/***************************************************************************** 
     67 * chroma_sys_t: chroma method descriptor 
     68 ***************************************************************************** 
     69 * This structure is part of the chroma transformation descriptor, it 
     70 * describes the chroma plugin specific properties. 
     71 *****************************************************************************/ 
     72struct filter_sys_t 
     73{ 
     74    int i_src_vlc_chroma; 
     75    int i_src_ffmpeg_chroma; 
     76    int i_dst_vlc_chroma; 
     77    int i_dst_ffmpeg_chroma; 
     78    AVPicture tmp_pic; 
     79    ImgReSampleContext *p_rsc; 
     80}; 
     81 
     82/***************************************************************************** 
     83 * OpenFilter: allocate a chroma function 
     84 ***************************************************************************** 
     85 * This function allocates and initializes a chroma function 
     86 *****************************************************************************/ 
     87int OpenFilter( vlc_object_t *p_this ) 
     88{ 
     89    filter_t *p_filter = (filter_t *)p_this; 
     90    int i_ffmpeg_chroma[2], i_vlc_chroma[2], i; 
     91 
     92    /* 
     93     * Check the source chroma first, then the destination chroma 
     94     */ 
     95    i_vlc_chroma[0] = p_filter->fmt_in.video.i_chroma; 
     96    i_vlc_chroma[1] = p_filter->fmt_out.video.i_chroma; 
     97    for( i = 0; i < 2; i++ ) 
     98    { 
     99        i_ffmpeg_chroma[i] = GetFfmpegChroma( i_vlc_chroma[i] ); 
     100        if( i_ffmpeg_chroma[i] < 0 ) return VLC_EGENERIC; 
     101    } 
     102 
     103    p_filter->pf_video_filter = Conversion_Filter; 
     104 
     105    p_filter->p_sys = malloc( sizeof( filter_sys_t ) ); 
     106    if( p_filter->p_sys == NULL ) 
     107    { 
     108        return VLC_ENOMEM; 
     109    } 
     110 
     111    p_filter->p_sys->i_src_vlc_chroma = p_filter->fmt_in.video.i_chroma; 
     112    p_filter->p_sys->i_dst_vlc_chroma = p_filter->fmt_out.video.i_chroma; 
     113    p_filter->p_sys->i_src_ffmpeg_chroma = i_ffmpeg_chroma[0]; 
     114    p_filter->p_sys->i_dst_ffmpeg_chroma = i_ffmpeg_chroma[1]; 
     115 
     116    if( ( p_filter->fmt_in.video.i_height != p_filter->fmt_out.video.i_height || 
     117          p_filter->fmt_in.video.i_width != p_filter->fmt_out.video.i_width ) && 
     118        ( p_filter->p_sys->i_dst_vlc_chroma == VLC_FOURCC('I','4','2','0') || 
     119          p_filter->p_sys->i_dst_vlc_chroma == VLC_FOURCC('Y','V','1','2') )) 
     120    { 
     121        msg_Dbg( p_filter, "preparing to resample picture" ); 
     122        p_filter->p_sys->p_rsc = 
     123            img_resample_init( p_filter->fmt_out.video.i_width, 
     124                               p_filter->fmt_out.video.i_height, 
     125                               p_filter->fmt_in.video.i_width, 
     126                               p_filter->fmt_in.video.i_height ); 
     127        avpicture_alloc( &p_filter->p_sys->tmp_pic, 
     128                         p_filter->p_sys->i_dst_ffmpeg_chroma, 
     129                         p_filter->fmt_in.video.i_width, 
     130                         p_filter->fmt_in.video.i_height ); 
     131    } 
     132    else 
     133    { 
     134        msg_Dbg( p_filter, "no resampling" ); 
     135        p_filter->p_sys->p_rsc = NULL; 
     136    } 
     137 
     138    return VLC_SUCCESS; 
     139} 
     140 
     141VIDEO_FILTER_WRAPPER( Conversion ) 
     142 
     143/***************************************************************************** 
     144 * ChromaConversion: actual chroma conversion function 
     145 *****************************************************************************/ 
     146static void Conversion( filter_t *p_filter, 
     147                        picture_t *p_src, picture_t *p_dest ) 
     148{ 
     149    AVPicture src_pic; 
     150    AVPicture dest_pic; 
     151    int i; 
     152 
     153    /* Prepare the AVPictures for converion */ 
     154    for( i = 0; i < p_src->i_planes; i++ ) 
     155    { 
     156        src_pic.data[i] = p_src->p[i].p_pixels; 
     157        src_pic.linesize[i] = p_src->p[i].i_pitch; 
     158    } 
     159    for( i = 0; i < p_dest->i_planes; i++ ) 
     160    { 
     161        dest_pic.data[i] = p_dest->p[i].p_pixels; 
     162        dest_pic.linesize[i] = p_dest->p[i].i_pitch; 
     163    } 
     164 
     165    /* Special cases */ 
     166    if( p_filter->p_sys->i_src_vlc_chroma == VLC_FOURCC('Y','V','1','2') || 
     167        p_filter->p_sys->i_src_vlc_chroma == VLC_FOURCC('Y','V','U','9') ) 
     168    { 
     169        /* Invert U and V */ 
     170        src_pic.data[1] = p_src->p[2].p_pixels; 
     171        src_pic.data[2] = p_src->p[1].p_pixels; 
     172    } 
     173    if( p_filter->p_sys->i_dst_vlc_chroma == VLC_FOURCC('Y','V','1','2') || 
     174        p_filter->p_sys->i_dst_vlc_chroma == VLC_FOURCC('Y','V','U','9') ) 
     175    { 
     176        /* Invert U and V */ 
     177        dest_pic.data[1] = p_dest->p[2].p_pixels; 
     178        dest_pic.data[2] = p_dest->p[1].p_pixels; 
     179    } 
     180    if( p_filter->p_sys->i_src_ffmpeg_chroma == PIX_FMT_RGB24 ) 
     181        if( p_filter->fmt_in.video.i_bmask == 0x00ff0000 ) 
     182            p_filter->p_sys->i_src_ffmpeg_chroma = PIX_FMT_BGR24; 
     183 
     184    if( p_filter->p_sys->p_rsc ) 
     185    { 
     186        img_convert( &p_filter->p_sys->tmp_pic, 
     187                     p_filter->p_sys->i_dst_ffmpeg_chroma, 
     188                     &src_pic, p_filter->p_sys->i_src_ffmpeg_chroma, 
     189                     p_filter->fmt_in.video.i_width, 
     190                     p_filter->fmt_in.video.i_height ); 
     191        img_resample( p_filter->p_sys->p_rsc, &dest_pic, 
     192                      &p_filter->p_sys->tmp_pic ); 
     193    } 
     194    else 
     195    { 
     196        img_convert( &dest_pic, p_filter->p_sys->i_dst_ffmpeg_chroma, 
     197                     &src_pic, p_filter->p_sys->i_src_ffmpeg_chroma, 
     198                     p_filter->fmt_in.video.i_width, 
     199                     p_filter->fmt_in.video.i_height ); 
     200    } 
     201} 
     202 
     203/***************************************************************************** 
     204 * CloseFilter: free the chroma function 
     205 ***************************************************************************** 
     206 * This function frees the previously allocated chroma function 
     207 *****************************************************************************/ 
     208void CloseFilter( vlc_object_t *p_this ) 
     209{ 
     210    filter_t *p_filter = (filter_t *)p_this; 
     211    if( p_filter->p_sys->p_rsc ) 
     212    { 
     213        img_resample_close( p_filter->p_sys->p_rsc ); 
     214        avpicture_free( &p_filter->p_sys->tmp_pic ); 
     215    } 
     216    free( p_filter->p_sys ); 
     217}