Commit 229fe32c authored by Jean-Paul Saman's avatar Jean-Paul Saman Committed by Jean-Paul Saman

Backport of swscale functionality from trunk.

parent 469e9790
......@@ -4,11 +4,13 @@ SOURCES_ffmpeg = \
video.c \
audio.c \
video_filter.c \
deinterlace.c \
chroma.c \
encoder.c \
postprocess.c \
demux.c \
mux.c \
scale.c \
$(NULL)
SOURCES_ffmpegaltivec = \
......@@ -17,6 +19,7 @@ SOURCES_ffmpegaltivec = \
video.c \
audio.c \
video_filter.c \
deinterlace.c \
chroma.c \
encoder.c \
postprocess.c \
......
......@@ -36,6 +36,7 @@
#include "ffmpeg.h"
#if !defined(HAVE_FFMPEG_SWSCALE_H) && !defined(HAVE_LIBSWSCALE_TREE)
void E_(InitLibavcodec) ( vlc_object_t *p_object );
static void ChromaConversion( vout_thread_t *, picture_t *, picture_t * );
......@@ -187,3 +188,4 @@ void E_(CloseChroma)( vlc_object_t *p_this )
}
free( p_vout->chroma.p_sys );
}
#endif
/*****************************************************************************
* video filter: video filter doing chroma conversion and resizing
* using the ffmpeg library
*****************************************************************************
* Copyright (C) 1999-2001 the VideoLAN team
* $Id$
*
* Authors: Gildas Bazin <gbazin@videolan.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
/*****************************************************************************
* Preamble
*****************************************************************************/
#include <vlc/vlc.h>
#include <vlc/vout.h>
#include <vlc_codec.h>
#include <vlc_filter.h>
/* ffmpeg header */
#ifdef HAVE_FFMPEG_AVCODEC_H
# include <ffmpeg/avcodec.h>
#else
# include <avcodec.h>
#endif
#include "ffmpeg.h"
static picture_t *Deinterlace( filter_t *p_filter, picture_t *p_pic );
/*****************************************************************************
* filter_sys_t : filter descriptor
*****************************************************************************/
struct filter_sys_t
{
vlc_bool_t b_resize;
vlc_bool_t b_convert;
vlc_bool_t b_resize_first;
vlc_bool_t b_enable_croppadd;
es_format_t fmt_in;
int i_src_ffmpeg_chroma;
es_format_t fmt_out;
int i_dst_ffmpeg_chroma;
AVPicture tmp_pic;
};
/*****************************************************************************
* OpenDeinterlace: probe the filter and return score
*****************************************************************************/
int E_(OpenDeinterlace)( vlc_object_t *p_this )
{
filter_t *p_filter = (filter_t*)p_this;
filter_sys_t *p_sys;
/* Check if we can handle that formats */
if( E_(GetFfmpegChroma)( p_filter->fmt_in.video.i_chroma ) < 0 )
{
return VLC_EGENERIC;
}
/* Allocate the memory needed to store the decoder's structure */
if( ( p_filter->p_sys = p_sys =
(filter_sys_t *)malloc(sizeof(filter_sys_t)) ) == NULL )
{
msg_Err( p_filter, "out of memory" );
return VLC_EGENERIC;
}
/* Misc init */
p_sys->i_src_ffmpeg_chroma =
E_(GetFfmpegChroma)( p_filter->fmt_in.video.i_chroma );
p_filter->pf_video_filter = Deinterlace;
msg_Dbg( p_filter, "deinterlacing" );
/* libavcodec needs to be initialized for some chroma conversions */
E_(InitLibavcodec)(p_this);
return VLC_SUCCESS;
}
/*****************************************************************************
* CloseDeinterlace: clean up the filter
*****************************************************************************/
void E_(CloseDeinterlace)( vlc_object_t *p_this )
{
filter_t *p_filter = (filter_t*)p_this;
filter_sys_t *p_sys = p_filter->p_sys;
free( p_sys );
}
/*****************************************************************************
* Do the processing here
*****************************************************************************/
static picture_t *Deinterlace( filter_t *p_filter, picture_t *p_pic )
{
filter_sys_t *p_sys = p_filter->p_sys;
AVPicture src_pic, dest_pic;
picture_t *p_pic_dst;
int i;
/* Request output picture */
p_pic_dst = p_filter->pf_vout_buffer_new( p_filter );
if( !p_pic_dst )
{
msg_Warn( p_filter, "can't get output picture" );
return NULL;
}
/* Prepare the AVPictures for the conversion */
for( i = 0; i < p_pic->i_planes; i++ )
{
src_pic.data[i] = p_pic->p[i].p_pixels;
src_pic.linesize[i] = p_pic->p[i].i_pitch;
}
for( i = 0; i < p_pic_dst->i_planes; i++ )
{
dest_pic.data[i] = p_pic_dst->p[i].p_pixels;
dest_pic.linesize[i] = p_pic_dst->p[i].i_pitch;
}
avpicture_deinterlace( &dest_pic, &src_pic, p_sys->i_src_ffmpeg_chroma,
p_filter->fmt_in.video.i_width,
p_filter->fmt_in.video.i_height );
p_pic_dst->date = p_pic->date;
p_pic_dst->b_force = p_pic->b_force;
p_pic_dst->i_nb_fields = p_pic->i_nb_fields;
p_pic_dst->b_progressive = VLC_TRUE;
p_pic_dst->b_top_field_first = p_pic->b_top_field_first;
p_pic->pf_release( p_pic );
return p_pic_dst;
}
This diff is collapsed.
......@@ -2,7 +2,7 @@
* ffmpeg.h: decoder using the ffmpeg library
*****************************************************************************
* Copyright (C) 2001 the VideoLAN team
* $Id$
* $Id: f2ea5ef3a73821145591172cfb79c3d8813f66ad $
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
*
......@@ -23,12 +23,6 @@
#include "codecs.h" /* BITMAPINFOHEADER */
#if LIBAVCODEC_BUILD >= 4663
# define LIBAVCODEC_PP
#else
# undef LIBAVCODEC_PP
#endif
struct picture_t;
struct AVFrame;
struct AVCodecContext;
......@@ -78,6 +72,8 @@ int E_(OpenCropPadd)( vlc_object_t * );
void E_(CloseFilter)( vlc_object_t * );
int E_(OpenDeinterlace)( vlc_object_t * );
void E_(CloseDeinterlace)( vlc_object_t * );
int E_(OpenScaler)( vlc_object_t * );
void E_(CloseScaler)( vlc_object_t * );
/* Postprocessing module */
void *E_(OpenPostproc)( decoder_t *, vlc_bool_t * );
......@@ -297,3 +293,6 @@ N_("<filterName>[:<option>[:<option>...]][[,|/][-]<filterName>[:<option>...]]...
#define ENC_CHROMA_ELIM_LONGTEXT N_( "Eliminates chrominance blocks when " \
"the PSNR isn't much changed (default: 0.0). The H264 specification " \
"recommends 7." )
#define SCALEMODE_TEXT N_("Scaling mode")
#define SCALEMODE_LONGTEXT N_("Scaling mode to use.")
......@@ -2,7 +2,7 @@
* postprocess.c: video postprocessing using the ffmpeg library
*****************************************************************************
* Copyright (C) 1999-2001 the VideoLAN team
* $Id$
* $Id: 2c9471842b31cdcdd4bfad33cff706829f7d72e9 $
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
* Gildas Bazin <gbazin@netcourrier.com>
......@@ -35,8 +35,6 @@
#include "ffmpeg.h"
#ifdef LIBAVCODEC_PP
#ifdef HAVE_POSTPROC_POSTPROCESS_H
# include <postproc/postprocess.h>
#else
......@@ -265,5 +263,3 @@ static int PPQCallback( vlc_object_t *p_this, char const *psz_cmd,
return VLC_SUCCESS;
}
#endif /* LIBAVCODEC_PP */
This diff is collapsed.
......@@ -2,7 +2,7 @@
* video.c: video decoder using the ffmpeg library
*****************************************************************************
* Copyright (C) 1999-2001 the VideoLAN team
* $Id$
* $Id: 5376a0d2d02a3ecdf7cb2c4c200d5749e803182b $
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
* Gildas Bazin <gbazin@videolan.org>
......@@ -130,6 +130,8 @@ static uint32_t ffmpeg_PixFmtToChroma( int i_ff_chroma )
return VLC_FOURCC('R','V','2','4');
case PIX_FMT_RGBA32:
return VLC_FOURCC('R','V','3','2');
case PIX_FMT_RGBA:
return VLC_FOURCC('R','G','B','A');
case PIX_FMT_GRAY8:
return VLC_FOURCC('G','R','E','Y');
......@@ -170,16 +172,12 @@ static inline picture_t *ffmpeg_NewPictBuf( decoder_t *p_dec,
}
else
{
#if LIBAVCODEC_BUILD >= 4687
p_dec->fmt_out.video.i_aspect =
VOUT_ASPECT_FACTOR * ( av_q2d(p_context->sample_aspect_ratio) *
p_context->width / p_context->height );
p_dec->fmt_out.video.i_sar_num = p_context->sample_aspect_ratio.num;
p_dec->fmt_out.video.i_sar_den = p_context->sample_aspect_ratio.den;
#else
p_dec->fmt_out.video.i_aspect =
VOUT_ASPECT_FACTOR * p_context->aspect_ratio;
#endif
if( p_dec->fmt_out.video.i_aspect == 0 )
{
p_dec->fmt_out.video.i_aspect =
......@@ -195,31 +193,20 @@ static inline picture_t *ffmpeg_NewPictBuf( decoder_t *p_dec,
p_dec->fmt_out.video.i_frame_rate_base =
p_dec->fmt_in.video.i_frame_rate_base;
}
else
#if LIBAVCODEC_BUILD >= 4754
if( p_context->time_base.num > 0 && p_context->time_base.den > 0 )
else if( p_context->time_base.num > 0 && p_context->time_base.den > 0 )
{
p_dec->fmt_out.video.i_frame_rate = p_context->time_base.den;
p_dec->fmt_out.video.i_frame_rate_base = p_context->time_base.num;
}
#else
if( p_context->frame_rate > 0 && p_context->frame_rate_base > 0 )
{
p_dec->fmt_out.video.i_frame_rate = p_context->frame_rate;
p_dec->fmt_out.video.i_frame_rate_base = p_context->frame_rate_base;
}
#endif
p_pic = p_dec->pf_vout_buffer_new( p_dec );
#ifdef LIBAVCODEC_PP
if( p_sys->p_pp && p_sys->b_pp && !p_sys->b_pp_init )
{
E_(InitPostproc)( p_dec, p_sys->p_pp, p_context->width,
p_context->height, p_context->pix_fmt );
p_sys->b_pp_init = VLC_TRUE;
}
#endif
return p_pic;
}
......@@ -271,25 +258,19 @@ int E_(InitVideoDec)( decoder_t *p_dec, AVCodecContext *p_context,
var_Create( p_dec, "ffmpeg-vismv", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
var_Get( p_dec, "ffmpeg-vismv", &val );
#if LIBAVCODEC_BUILD >= 4698
if( val.i_int ) p_sys->p_context->debug_mv = val.i_int;
#endif
var_Create( p_dec, "ffmpeg-lowres", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
var_Get( p_dec, "ffmpeg-lowres", &val );
#if LIBAVCODEC_BUILD >= 4723
if( val.i_int > 0 && val.i_int <= 2 ) p_sys->p_context->lowres = val.i_int;
#endif
var_Create( p_dec, "ffmpeg-skiploopfilter",
VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
var_Get( p_dec, "ffmpeg-skiploopfilter", &val );
#if LIBAVCODEC_BUILD >= 4758
if( val.i_int > 0 ) p_sys->p_context->skip_loop_filter = AVDISCARD_NONREF;
if( val.i_int > 1 ) p_sys->p_context->skip_loop_filter = AVDISCARD_BIDIR;
if( val.i_int > 2 ) p_sys->p_context->skip_loop_filter = AVDISCARD_NONKEY;
if( val.i_int > 3 ) p_sys->p_context->skip_loop_filter = AVDISCARD_ALL;
#endif
/* ***** ffmpeg frame skipping ***** */
var_Create( p_dec, "ffmpeg-hurry-up", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
......@@ -305,22 +286,16 @@ int E_(InitVideoDec)( decoder_t *p_dec, AVCodecContext *p_context,
p_sys->p_context->pix_fmt != PIX_FMT_YUV422P &&
/* H264 uses too many reference frames */
p_sys->i_codec_id != CODEC_ID_H264 &&
#if LIBAVCODEC_BUILD >= 4698
!p_sys->p_context->debug_mv )
#else
1 )
#endif
{
/* Some codecs set pix_fmt only after the 1st frame has been decoded,
* so we need to do another check in ffmpeg_GetFrameBuf() */
p_sys->b_direct_rendering = 1;
}
#ifdef LIBAVCODEC_PP
p_sys->p_pp = NULL;
p_sys->b_pp = p_sys->b_pp_async = p_sys->b_pp_init = VLC_FALSE;
p_sys->p_pp = E_(OpenPostproc)( p_dec, &p_sys->b_pp_async );
#endif
/* ffmpeg doesn't properly release old pictures when frames are skipped */
//if( p_sys->b_hurry_up ) p_sys->b_direct_rendering = 0;
......@@ -354,13 +329,11 @@ int E_(InitVideoDec)( decoder_t *p_dec, AVCodecContext *p_context,
p_dec->fmt_out.i_codec = ffmpeg_PixFmtToChroma( p_context->pix_fmt );
/* Setup palette */
#if LIBAVCODEC_BUILD >= 4688
if( p_dec->fmt_in.video.p_palette )
p_sys->p_context->palctrl =
(AVPaletteControl *)p_dec->fmt_in.video.p_palette;
else
p_sys->p_context->palctrl = &palette_control;
#endif
/* ***** Open the codec ***** */
vlc_mutex_lock( lockval.p_address );
......@@ -374,7 +347,6 @@ int E_(InitVideoDec)( decoder_t *p_dec, AVCodecContext *p_context,
vlc_mutex_unlock( lockval.p_address );
msg_Dbg( p_dec, "ffmpeg codec (%s) started", p_sys->psz_namecodec );
return VLC_SUCCESS;
}
......@@ -602,7 +574,6 @@ picture_t *E_(DecodeVideo)( decoder_t *p_dec, block_t **pp_block )
if( !p_dec->fmt_in.video.i_aspect )
{
/* Fetch again the aspect ratio in case it changed */
#if LIBAVCODEC_BUILD >= 4687
p_dec->fmt_out.video.i_aspect =
VOUT_ASPECT_FACTOR
* ( av_q2d(p_sys->p_context->sample_aspect_ratio)
......@@ -611,10 +582,7 @@ picture_t *E_(DecodeVideo)( decoder_t *p_dec, block_t **pp_block )
= p_sys->p_context->sample_aspect_ratio.num;
p_dec->fmt_out.video.i_sar_den
= p_sys->p_context->sample_aspect_ratio.den;
#else
p_dec->fmt_out.video.i_aspect =
VOUT_ASPECT_FACTOR * p_sys->p_context->aspect_ratio;
#endif
if( p_dec->fmt_out.video.i_aspect == 0 )
{
p_dec->fmt_out.video.i_aspect = VOUT_ASPECT_FACTOR
......@@ -628,7 +596,6 @@ picture_t *E_(DecodeVideo)( decoder_t *p_dec, block_t **pp_block )
p_pic->date = p_sys->i_pts;
/* interpolate the next PTS */
#if LIBAVCODEC_BUILD >= 4754
if( p_dec->fmt_in.video.i_frame_rate > 0 &&
p_dec->fmt_in.video.i_frame_rate_base > 0 )
{
......@@ -646,16 +613,6 @@ picture_t *E_(DecodeVideo)( decoder_t *p_dec, block_t **pp_block )
p_block->i_rate / INPUT_RATE_DEFAULT /
(2 * p_sys->p_context->time_base.den);
}
#else
if( p_sys->p_context->frame_rate > 0 )
{
p_sys->i_pts += I64C(1000000) *
(2 + p_sys->p_ff_pic->repeat_pict) *
p_sys->p_context->frame_rate_base *
p_block->i_rate / INPUT_RATE_DEFAULT /
(2 * p_sys->p_context->frame_rate);
}
#endif
if( p_sys->b_first_frame )
{
......@@ -665,10 +622,8 @@ picture_t *E_(DecodeVideo)( decoder_t *p_dec, block_t **pp_block )
}
p_pic->i_nb_fields = 2 + p_sys->p_ff_pic->repeat_pict;
#if LIBAVCODEC_BUILD >= 4685
p_pic->b_progressive = !p_sys->p_ff_pic->interlaced_frame;
p_pic->b_top_field_first = p_sys->p_ff_pic->top_field_first;
#endif
return p_pic;
}
......@@ -694,9 +649,7 @@ void E_(EndVideoDec)( decoder_t *p_dec )
if( p_sys->p_ff_pic ) av_free( p_sys->p_ff_pic );
#ifdef LIBAVCODEC_PP
E_(ClosePostproc)( p_dec, p_sys->p_pp );
#endif
free( p_sys->p_buffer_orig );
}
......@@ -792,11 +745,9 @@ static void ffmpeg_CopyPicture( decoder_t *p_dec,
uint8_t *p_dst, *p_src;
int i_src_stride, i_dst_stride;
#ifdef LIBAVCODEC_PP
if( p_sys->p_pp && p_sys->b_pp )
E_(PostprocPict)( p_dec, p_sys->p_pp, p_pic, p_ff_pic );
else
#endif
for( i_plane = 0; i_plane < p_pic->i_planes; i_plane++ )
{
p_src = p_ff_pic->data[i_plane];
......@@ -831,11 +782,13 @@ static void ffmpeg_CopyPicture( decoder_t *p_dec,
dest_pic.data[i] = p_pic->p[i].p_pixels;
dest_pic.linesize[i] = p_pic->p[i].i_pitch;
}
#if !defined(HAVE_FFMPEG_SWSCALE_H) && !defined(HAVE_LIBSWSCALE_TREE)
img_convert( &dest_pic, PIX_FMT_YUV420P,
(AVPicture *)p_ff_pic,
p_sys->p_context->pix_fmt,
p_sys->p_context->width,
p_sys->p_context->height );
#endif
break;
default:
msg_Err( p_dec, "don't know how to convert chroma %i",
......
......@@ -3,7 +3,7 @@
* using the ffmpeg library
*****************************************************************************
* Copyright (C) 1999-2001 the VideoLAN team
* $Id$
* $Id: a6d66457c73a31abbe49d51c6f0ef10b6a57234b $
*
* Authors: Gildas Bazin <gbazin@videolan.org>
*
......@@ -38,6 +38,7 @@
#include "ffmpeg.h"
#if !defined(HAVE_FFMPEG_SWSCALE_H) && !defined(HAVE_LIBSWSCALE_TREE)
void E_(InitLibavcodec) ( vlc_object_t *p_object );
static int CheckInit( filter_t *p_filter );
static picture_t *Process( filter_t *p_filter, picture_t *p_pic );
......@@ -691,3 +692,4 @@ static picture_t *Deinterlace( filter_t *p_filter, picture_t *p_pic )
p_pic->pf_release( p_pic );
return p_pic_dst;
}
#endif
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment