/*****************************************************************************
* avcodec.c: video and audio decoder and encoder using libavcodec
*****************************************************************************
- * Copyright (C) 1999-2008 the VideoLAN team
+ * Copyright (C) 1999-2008 VLC authors and VideoLAN
* $Id$
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
* 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
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 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.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser 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.
+ * You should have received a copy of the GNU Lesser 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.
*****************************************************************************/
/*****************************************************************************
#include <vlc_avcodec.h>
#include <vlc_cpu.h>
-/* ffmpeg header */
#define HAVE_MMX 1
-#ifdef HAVE_LIBAVCODEC_AVCODEC_H
-# include <libavcodec/avcodec.h>
-#else
-# include <avcodec.h>
-#endif
+#include <libavcodec/avcodec.h>
#include "avcodec.h"
#include "chroma.h"
#include "avcommon.h"
-#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 52, 25, 0 )
-# error You must update libavcodec to a version >= 52.25.0
-#endif
-
/*****************************************************************************
* decoder_sys_t: decoder descriptor
*****************************************************************************/
add_integer ( "avcodec-vismv", 0, VISMV_TEXT, VISMV_LONGTEXT,
true )
add_obsolete_integer ( "ffmpeg-lowres" ) /* removed since 2.1.0 */
- add_integer ( "avcodec-lowres", 0, LOWRES_TEXT, LOWRES_LONGTEXT,
- true )
- change_integer_range( 0, 2 )
add_obsolete_bool( "ffmpeg-fast" ) /* removed since 2.1.0 */
add_bool( "avcodec-fast", false, FAST_TEXT, FAST_LONGTEXT, false )
add_obsolete_integer ( "ffmpeg-skiploopfilter" ) /* removed since 2.1.0 */
true )
add_obsolete_string( "ffmpeg-codec" ) /* removed since 2.1.0 */
add_string( "avcodec-codec", NULL, CODEC_TEXT, CODEC_LONGTEXT, true )
-#if defined(HAVE_AVCODEC_VAAPI) || defined(HAVE_AVCODEC_DXVA2)
add_obsolete_bool( "ffmpeg-hw" ) /* removed since 2.1.0 */
- add_bool( "avcodec-hw", false, HW_TEXT, HW_LONGTEXT, false )
-#endif
+ add_module( "avcodec-hw", "hw decoder", "any", HW_TEXT, HW_LONGTEXT, false )
#if defined(FF_THREAD_FRAME)
add_obsolete_integer( "ffmpeg-threads" ) /* removed since 2.1.0 */
add_integer( "avcodec-threads", 0, THREADS_TEXT, THREADS_LONGTEXT, true );
#endif
+ add_string( "avcodec-options", NULL, AV_OPTIONS_TEXT, AV_OPTIONS_LONGTEXT, true )
#ifdef ENABLE_SOUT
add_string( ENC_CFG_PREFIX "codec", NULL, CODEC_TEXT, CODEC_LONGTEXT, true )
- add_string( ENC_CFG_PREFIX "hq", "simple", ENC_HQ_TEXT,
+ add_string( ENC_CFG_PREFIX "hq", "rd", ENC_HQ_TEXT,
ENC_HQ_LONGTEXT, false )
- change_string_list( enc_hq_list, enc_hq_list_text, 0 )
+ change_string_list( enc_hq_list, enc_hq_list_text )
add_integer( ENC_CFG_PREFIX "keyint", 0, ENC_KEYINT_TEXT,
ENC_KEYINT_LONGTEXT, false )
add_integer( ENC_CFG_PREFIX "bframes", 0, ENC_BFRAMES_TEXT,
/* Audio AAC encoder profile */
add_string( ENC_CFG_PREFIX "aac-profile", "low",
ENC_PROFILE_TEXT, ENC_PROFILE_LONGTEXT, true )
-#endif /* ENABLE_SOUT */
- /* video filter submodule */
- add_submodule ()
- set_capability( "video filter2", 0 )
- set_callbacks( OpenDeinterlace, CloseDeinterlace )
- set_description( N_("FFmpeg deinterlace video filter") )
- add_shortcut( "ffmpeg-deinterlace" )
+ add_string( ENC_CFG_PREFIX "options", NULL, AV_OPTIONS_TEXT, AV_OPTIONS_LONGTEXT, true )
+#endif /* ENABLE_SOUT */
#ifdef MERGE_FFMPEG
add_submodule ()
static int OpenDecoder( vlc_object_t *p_this )
{
decoder_t *p_dec = (decoder_t*) p_this;
- int i_cat, i_codec_id, i_result;
+ unsigned i_codec_id;
+ int i_cat, i_result;
const char *psz_namecodec;
AVCodecContext *p_context = NULL;
}
/* Initialization must be done before avcodec_find_decoder() */
- vlc_init_avcodec();
+ vlc_init_avcodec(p_this);
/* *** ask ffmpeg for a decoder *** */
char *psz_decoder = var_CreateGetString( p_this, "avcodec-codec" );
}
/* *** get a p_context *** */
-#if LIBAVCODEC_VERSION_MAJOR >= 54
p_context = avcodec_alloc_context3(p_codec);
-#else
- p_context = avcodec_alloc_context();
-#endif
if( !p_context )
return VLC_ENOMEM;
p_context->debug = var_InheritInteger( p_dec, "avcodec-debug" );
p_context->opaque = (void *)p_this;
- /* Set CPU capabilities */
- unsigned i_cpu = vlc_CPU();
- p_context->dsp_mask = 0;
- if( !(i_cpu & CPU_CAPABILITY_MMX) )
- {
- p_context->dsp_mask |= AV_CPU_FLAG_MMX;
- }
- if( !(i_cpu & CPU_CAPABILITY_MMXEXT) )
- {
- p_context->dsp_mask |= AV_CPU_FLAG_MMX2;
- }
- if( !(i_cpu & CPU_CAPABILITY_3DNOW) )
- {
- p_context->dsp_mask |= AV_CPU_FLAG_3DNOW;
- }
- if( !(i_cpu & CPU_CAPABILITY_SSE) )
- {
- p_context->dsp_mask |= AV_CPU_FLAG_SSE;
- }
- if( !(i_cpu & CPU_CAPABILITY_SSE2) )
- {
- p_context->dsp_mask |= AV_CPU_FLAG_SSE2;
- }
-#ifdef AV_CPU_FLAG_SSE3
- if( !(i_cpu & CPU_CAPABILITY_SSE3) )
- p_context->dsp_mask |= AV_CPU_FLAG_SSE3;
-#endif
-#ifdef AV_CPU_FLAG_SSSE3
- if( !(i_cpu & CPU_CAPABILITY_SSSE3) )
- p_context->dsp_mask |= AV_CPU_FLAG_SSSE3;
-#endif
-#ifdef AV_CPU_FLAG_SSE4
- if( !(i_cpu & CPU_CAPABILITY_SSE4_1) )
- p_context->dsp_mask |= AV_CPU_FLAG_SSE4;
-#endif
-#ifdef AV_CPU_FLAG_SSE42
- if( !(i_cpu & CPU_CAPABILITY_SSE4_2) )
- p_context->dsp_mask |= AV_CPU_FLAG_SSE42;
-#endif
-
p_dec->b_need_packetized = true;
switch( i_cat )
{
switch( p_sys->i_cat )
{
- case AUDIO_ES:
- EndAudioDec ( p_dec );
- break;
case VIDEO_ES:
EndVideoDec ( p_dec );
break;
- case SPU_ES:
- EndSubtitleDec( p_dec );
- break;
}
if( p_sys->p_context )
{
- free( p_sys->p_context->extradata );
+ av_free( p_sys->p_context->extradata );
p_sys->p_context->extradata = NULL;
if( !p_sys->b_delayed_open )
if( p_sys->p_context->extradata_size <= 0 )
{
- if( p_sys->i_codec_id == CODEC_ID_VC1 ||
- p_sys->i_codec_id == CODEC_ID_VORBIS ||
- p_sys->i_codec_id == CODEC_ID_THEORA ||
- ( p_sys->i_codec_id == CODEC_ID_AAC &&
+ if( p_sys->i_codec_id == AV_CODEC_ID_VC1 ||
+ p_sys->i_codec_id == AV_CODEC_ID_VORBIS ||
+ p_sys->i_codec_id == AV_CODEC_ID_THEORA ||
+ ( p_sys->i_codec_id == AV_CODEC_ID_AAC &&
!p_dec->fmt_in.b_packetized ) )
{
msg_Warn( p_dec, "waiting for extra data for codec %s",
}
if( p_dec->fmt_in.i_cat == VIDEO_ES )
{
- p_sys->p_context->width = p_dec->fmt_in.video.i_width;
- p_sys->p_context->height = p_dec->fmt_in.video.i_height;
+ p_sys->p_context->width = p_dec->fmt_in.video.i_visible_width;
+ p_sys->p_context->height = p_dec->fmt_in.video.i_visible_height;
+ if (p_sys->p_context->width == 0)
+ p_sys->p_context->width = p_dec->fmt_in.video.i_width;
+ else if (p_sys->p_context->width != p_dec->fmt_in.video.i_width)
+ p_sys->p_context->coded_width = p_dec->fmt_in.video.i_width;
+ if (p_sys->p_context->height == 0)
+ p_sys->p_context->height = p_dec->fmt_in.video.i_height;
+ else if (p_sys->p_context->height != p_dec->fmt_in.video.i_height)
+ p_sys->p_context->coded_height = p_dec->fmt_in.video.i_height;
p_sys->p_context->bits_per_coded_sample = p_dec->fmt_in.video.i_bits_per_pixel;
}
else if( p_dec->fmt_in.i_cat == AUDIO_ES )
p_sys->p_context->block_align = p_dec->fmt_in.audio.i_blockalign;
p_sys->p_context->bit_rate = p_dec->fmt_in.i_bitrate;
p_sys->p_context->bits_per_coded_sample = p_dec->fmt_in.audio.i_bitspersample;
- if( p_sys->i_codec_id == CODEC_ID_ADPCM_G726 &&
+ if( p_sys->i_codec_id == AV_CODEC_ID_ADPCM_G726 &&
p_sys->p_context->bit_rate > 0 &&
p_sys->p_context->sample_rate > 0)
p_sys->p_context->bits_per_coded_sample = p_sys->p_context->bit_rate /
p_sys->p_context->sample_rate;
}
int ret;
+ char *psz_opts = var_InheritString( p_dec, "avcodec-options" );
+ AVDictionary *options = NULL;
+ if (psz_opts && *psz_opts)
+ options = vlc_av_get_options(psz_opts);
+ free(psz_opts);
+
vlc_avcodec_lock();
-#if LIBAVCODEC_VERSION_MAJOR >= 54
- ret = avcodec_open2( p_sys->p_context, p_sys->p_codec, NULL /* options */ );
-#else
- ret = avcodec_open( p_sys->p_context, p_sys->p_codec );
-#endif
+ ret = avcodec_open2( p_sys->p_context, p_sys->p_codec, options ? &options : NULL );
vlc_avcodec_unlock();
+
+ AVDictionaryEntry *t = NULL;
+ while ((t = av_dict_get(options, "", t, AV_DICT_IGNORE_SUFFIX))) {
+ msg_Err( p_dec, "Unknown option \"%s\"", t->key );
+ }
+ av_dict_free(&options);
+
if( ret < 0 )
return VLC_EGENERIC;
- msg_Dbg( p_dec, "ffmpeg codec (%s) started", p_sys->psz_namecodec );
+ msg_Dbg( p_dec, "avcodec codec (%s) started", p_sys->psz_namecodec );
#ifdef HAVE_AVCODEC_MT
if( p_dec->fmt_in.i_cat == VIDEO_ES )