1 /*****************************************************************************
2 * video filter: video filter doing chroma conversion and resizing
3 * using the ffmpeg library
4 *****************************************************************************
5 * Copyright (C) 1999-2001 the VideoLAN team
8 * Authors: Gildas Bazin <gbazin@videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
33 #include <vlc_codec.h>
35 #include <vlc_filter.h>
38 #ifdef HAVE_LIBAVCODEC_AVCODEC_H
39 # include <libavcodec/avcodec.h>
46 static picture_t *Deinterlace( filter_t *p_filter, picture_t *p_pic );
48 /*****************************************************************************
49 * filter_sys_t : filter descriptor
50 *****************************************************************************/
55 vlc_bool_t b_resize_first;
56 vlc_bool_t b_enable_croppadd;
59 int i_src_ffmpeg_chroma;
61 int i_dst_ffmpeg_chroma;
66 /*****************************************************************************
67 * OpenDeinterlace: probe the filter and return score
68 *****************************************************************************/
69 int E_(OpenDeinterlace)( vlc_object_t *p_this )
71 filter_t *p_filter = (filter_t*)p_this;
74 /* Check if we can handle that formats */
75 if( E_(GetFfmpegChroma)( p_filter->fmt_in.video.i_chroma ) < 0 )
80 /* Allocate the memory needed to store the decoder's structure */
81 if( ( p_filter->p_sys = p_sys =
82 (filter_sys_t *)malloc(sizeof(filter_sys_t)) ) == NULL )
84 msg_Err( p_filter, "out of memory" );
89 p_sys->i_src_ffmpeg_chroma =
90 E_(GetFfmpegChroma)( p_filter->fmt_in.video.i_chroma );
91 p_filter->pf_video_filter = Deinterlace;
93 msg_Dbg( p_filter, "deinterlacing" );
95 /* libavcodec needs to be initialized for some chroma conversions */
96 E_(InitLibavcodec)(p_this);
101 /*****************************************************************************
102 * CloseDeinterlace: clean up the filter
103 *****************************************************************************/
104 void E_(CloseDeinterlace)( vlc_object_t *p_this )
106 filter_t *p_filter = (filter_t*)p_this;
107 filter_sys_t *p_sys = p_filter->p_sys;
112 /*****************************************************************************
113 * Do the processing here
114 *****************************************************************************/
115 static picture_t *Deinterlace( filter_t *p_filter, picture_t *p_pic )
117 filter_sys_t *p_sys = p_filter->p_sys;
118 AVPicture src_pic, dest_pic;
119 picture_t *p_pic_dst;
122 /* Request output picture */
123 p_pic_dst = p_filter->pf_vout_buffer_new( p_filter );
126 msg_Warn( p_filter, "can't get output picture" );
130 /* Prepare the AVPictures for the conversion */
131 for( i = 0; i < p_pic->i_planes; i++ )
133 src_pic.data[i] = p_pic->p[i].p_pixels;
134 src_pic.linesize[i] = p_pic->p[i].i_pitch;
136 for( i = 0; i < p_pic_dst->i_planes; i++ )
138 dest_pic.data[i] = p_pic_dst->p[i].p_pixels;
139 dest_pic.linesize[i] = p_pic_dst->p[i].i_pitch;
142 avpicture_deinterlace( &dest_pic, &src_pic, p_sys->i_src_ffmpeg_chroma,
143 p_filter->fmt_in.video.i_width,
144 p_filter->fmt_in.video.i_height );
146 p_pic_dst->date = p_pic->date;
147 p_pic_dst->b_force = p_pic->b_force;
148 p_pic_dst->i_nb_fields = p_pic->i_nb_fields;
149 p_pic_dst->b_progressive = VLC_TRUE;
150 p_pic_dst->b_top_field_first = p_pic->b_top_field_first;
152 p_pic->pf_release( p_pic );