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 *****************************************************************************/
32 #include <vlc_common.h>
33 #include <vlc_codec.h>
35 #include <vlc_filter.h>
38 #ifdef HAVE_LIBAVCODEC_AVCODEC_H
39 # include <libavcodec/avcodec.h>
40 #elif defined(HAVE_FFMPEG_AVCODEC_H)
41 # include <ffmpeg/avcodec.h>
49 static picture_t *Deinterlace( filter_t *p_filter, picture_t *p_pic );
51 /*****************************************************************************
52 * filter_sys_t : filter descriptor
53 *****************************************************************************/
59 bool b_enable_croppadd;
62 int i_src_ffmpeg_chroma;
64 int i_dst_ffmpeg_chroma;
69 /*****************************************************************************
70 * OpenDeinterlace: probe the filter and return score
71 *****************************************************************************/
72 int OpenDeinterlace( vlc_object_t *p_this )
74 filter_t *p_filter = (filter_t*)p_this;
77 /* Check if we can handle that formats */
78 if( GetFfmpegChroma( p_filter->fmt_in.video.i_chroma ) < 0 )
83 /* Allocate the memory needed to store the decoder's structure */
84 if( ( p_filter->p_sys = p_sys =
85 (filter_sys_t *)malloc(sizeof(filter_sys_t)) ) == NULL )
87 msg_Err( p_filter, "out of memory" );
92 p_sys->i_src_ffmpeg_chroma =
93 GetFfmpegChroma( p_filter->fmt_in.video.i_chroma );
94 p_filter->pf_video_filter = Deinterlace;
96 msg_Dbg( p_filter, "deinterlacing" );
98 /* libavcodec needs to be initialized for some chroma conversions */
99 InitLibavcodec(p_this);
104 /*****************************************************************************
105 * CloseDeinterlace: clean up the filter
106 *****************************************************************************/
107 void CloseDeinterlace( vlc_object_t *p_this )
109 filter_t *p_filter = (filter_t*)p_this;
110 filter_sys_t *p_sys = p_filter->p_sys;
115 /*****************************************************************************
116 * Do the processing here
117 *****************************************************************************/
118 static picture_t *Deinterlace( filter_t *p_filter, picture_t *p_pic )
120 filter_sys_t *p_sys = p_filter->p_sys;
121 AVPicture src_pic, dest_pic;
122 picture_t *p_pic_dst;
125 /* Request output picture */
126 p_pic_dst = p_filter->pf_vout_buffer_new( p_filter );
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 i_res = 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 );
147 msg_Err( p_filter, "deinterlacing picture failed" );
148 p_filter->pf_vout_buffer_del( p_filter, p_pic_dst );
151 p_pic_dst->date = p_pic->date;
152 p_pic_dst->b_force = p_pic->b_force;
153 p_pic_dst->i_nb_fields = p_pic->i_nb_fields;
154 p_pic_dst->b_progressive = true;
155 p_pic_dst->b_top_field_first = p_pic->b_top_field_first;
157 p_pic->pf_release( p_pic );