/*****************************************************************************
- * ffmpeg_vdec.h: video decoder using ffmpeg library
+ * ffmpeg.h: decoder using the ffmpeg library
*****************************************************************************
* Copyright (C) 2001 VideoLAN
- * $Id: ffmpeg.h,v 1.5 2002/10/20 17:28:01 fenrir Exp $
+ * $Id$
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
- *
+ *
* 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
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
-/* Pour un flux video */
-typedef struct bitmapinfoheader_s
-{
- u32 i_size; /* size of header */
- u32 i_width;
- u32 i_height;
- u16 i_planes;
- u16 i_bitcount;
- u32 i_compression;
- u32 i_sizeimage;
- u32 i_xpelspermeter;
- u32 i_ypelspermeter;
- u32 i_clrused;
- u32 i_clrimportant;
-
- int i_data;
- u8 *p_data;
-} bitmapinfoheader_t;
-
-
-#if 0
-typedef struct statistic_s
-{
- mtime_t i_frame_time[3]; /* total time to decode frame */
- int i_frame_count[3]; /* number of frame to calculate frame_time */
-
- int i_frame_late[3]; /* number of frame consecutively late */
- int i_frame_skip[3]; /* number of frame skip */
-
-} statistic_t;
-#endif
-
-typedef struct videodec_thread_s
-{
- decoder_fifo_t *p_fifo;
-
- bitmapinfoheader_t format;
-
- AVCodecContext *p_context;
- AVCodec *p_codec;
- vout_thread_t *p_vout;
-
- /* for post processing */
- u32 i_pp_mode; /* valid only with I420 and YV12 */
- postprocessing_t *p_pp;
-
- char *psz_namecodec;
-
- /* for frame skipping algo */
-// statistic_s statistic;
-
- int b_hurry_up;
- int i_frame_error;
- int i_frame_skip;
- int i_frame_late; /* how may frame decoded are in late */
-
- /* private */
- mtime_t i_pts;
- int i_framesize;
- u8 *p_framedata;
-
- u8 *p_buffer; /* buffer for gather pes */
- int i_buffer_size; /* size of allocated p_framedata */
-
-} videodec_thread_t;
-
-/* MPEG4 video */
-#define FOURCC_DIVX VLC_FOURCC('D','I','V','X')
-#define FOURCC_divx VLC_FOURCC('d','i','v','x')
-#define FOURCC_DIV1 VLC_FOURCC('D','I','V','1')
-#define FOURCC_div1 VLC_FOURCC('d','i','v','1')
-#define FOURCC_MP4S VLC_FOURCC('M','P','4','S')
-#define FOURCC_mp4s VLC_FOURCC('m','p','4','s')
-#define FOURCC_M4S2 VLC_FOURCC('M','4','S','2')
-#define FOURCC_m4s2 VLC_FOURCC('m','4','s','2')
-#define FOURCC_xvid VLC_FOURCC('x','v','i','d')
-#define FOURCC_XVID VLC_FOURCC('X','V','I','D')
-#define FOURCC_XviD VLC_FOURCC('X','v','i','D')
-#define FOURCC_DX50 VLC_FOURCC('D','X','5','0')
-#define FOURCC_mp4v VLC_FOURCC('m','p','4','v')
-#define FOURCC_4 VLC_FOURCC( 4, 0, 0, 0 )
-
-/* MSMPEG4 v2 */
-#define FOURCC_MPG4 VLC_FOURCC('M','P','G','4')
-#define FOURCC_mpg4 VLC_FOURCC('m','p','g','4')
-#define FOURCC_DIV2 VLC_FOURCC('D','I','V','2')
-#define FOURCC_div2 VLC_FOURCC('d','i','v','2')
-#define FOURCC_MP42 VLC_FOURCC('M','P','4','2')
-#define FOURCC_mp42 VLC_FOURCC('m','p','4','2')
-
-/* MSMPEG4 v3 / M$ mpeg4 v3 */
-#define FOURCC_MPG3 VLC_FOURCC('M','P','G','3')
-#define FOURCC_mpg3 VLC_FOURCC('m','p','g','3')
-#define FOURCC_div3 VLC_FOURCC('d','i','v','3')
-#define FOURCC_MP43 VLC_FOURCC('M','P','4','3')
-#define FOURCC_mp43 VLC_FOURCC('m','p','4','3')
-
-/* DivX 3.20 */
-#define FOURCC_DIV3 VLC_FOURCC('D','I','V','3')
-#define FOURCC_DIV4 VLC_FOURCC('D','I','V','4')
-#define FOURCC_div4 VLC_FOURCC('d','i','v','4')
-#define FOURCC_DIV5 VLC_FOURCC('D','I','V','5')
-#define FOURCC_div5 VLC_FOURCC('d','i','v','5')
-#define FOURCC_DIV6 VLC_FOURCC('D','I','V','6')
-#define FOURCC_div6 VLC_FOURCC('d','i','v','6')
-
-/* AngelPotion stuff */
-#define FOURCC_AP41 VLC_FOURCC('A','P','4','1')
-
-/* ?? */
-#define FOURCC_3IV1 VLC_FOURCC('3','I','V','1')
-#define FOURCC_3IV2 VLC_FOURCC('3','I','V','2')
-
-/* H263 and H263i */
-#define FOURCC_H263 VLC_FOURCC('H','2','6','3')
-#define FOURCC_h263 VLC_FOURCC('h','2','6','3')
-#define FOURCC_U263 VLC_FOURCC('U','2','6','3')
-#define FOURCC_I263 VLC_FOURCC('I','2','6','3')
-#define FOURCC_i263 VLC_FOURCC('i','2','6','3')
-
-/* Sorenson v1 */
-#define FOURCC_SVQ1 VLC_FOURCC( 'S', 'V', 'Q', '1' )
-
-/* wmv */
-#define FOURCC_WMV1 VLC_FOURCC('W','M','V','1')
-#define FOURCC_WMV2 VLC_FOURCC('W','M','V','2')
-
-static int ffmpeg_GetFfmpegCodec( vlc_fourcc_t i_fourcc,
- int *pi_ffmpeg_codec,
- char **ppsz_name )
-{
- int i_codec = 0;
- char *psz_name = NULL;
-
- switch( i_fourcc )
- {
-#if LIBAVCODEC_BUILD >= 4608
- case FOURCC_DIV1:
- case FOURCC_div1:
- case FOURCC_MPG4:
- case FOURCC_mpg4:
- i_codec = CODEC_ID_MSMPEG4V1;
- psz_name = "MS MPEG-4 v1";
- break;
-
- case FOURCC_DIV2:
- case FOURCC_div2:
- case FOURCC_MP42:
- case FOURCC_mp42:
- i_codec = CODEC_ID_MSMPEG4V2;
- psz_name = "MS MPEG-4 v2";
- break;
-#endif
+#include "codecs.h" /* BITMAPINFOHEADER */
- case FOURCC_MPG3:
- case FOURCC_mpg3:
- case FOURCC_div3:
- case FOURCC_MP43:
- case FOURCC_mp43:
- case FOURCC_DIV3:
- case FOURCC_DIV4:
- case FOURCC_div4:
- case FOURCC_DIV5:
- case FOURCC_div5:
- case FOURCC_DIV6:
- case FOURCC_div6:
- case FOURCC_AP41:
- case FOURCC_3IV1:
-#if LIBAVCODEC_BUILD >= 4608
- i_codec = CODEC_ID_MSMPEG4V3;
+#if LIBAVCODEC_BUILD >= 4663
+# define LIBAVCODEC_PP
#else
- i_codec = CODEC_ID_MSMPEG4;
-#endif
- psz_name = "MS MPEG-4 v3";
- break;
-
-#if LIBAVCODEC_BUILD >= 4615
- case FOURCC_SVQ1:
- i_codec = CODEC_ID_SVQ1;
- psz_name = "SVQ-1 (Sorenson Video v1)";
- break;
+# undef LIBAVCODEC_PP
#endif
- case FOURCC_DIVX:
- case FOURCC_divx:
- case FOURCC_MP4S:
- case FOURCC_mp4s:
- case FOURCC_M4S2:
- case FOURCC_m4s2:
- case FOURCC_xvid:
- case FOURCC_XVID:
- case FOURCC_XviD:
- case FOURCC_DX50:
- case FOURCC_mp4v:
- case FOURCC_4:
- case FOURCC_3IV2:
-
- i_codec = CODEC_ID_MPEG4;
- psz_name = "MPEG-4";
- break;
-/* FIXME FOURCC_H263P exist but what fourcc ? */
- case FOURCC_H263:
- case FOURCC_h263:
- case FOURCC_U263:
- i_codec = CODEC_ID_H263;
- psz_name = "H263";
- break;
-
- case FOURCC_I263:
- case FOURCC_i263:
- i_codec = CODEC_ID_H263I;
- psz_name = "I263.I";
- break;
- case FOURCC_WMV1:
- i_codec = CODEC_ID_WMV1;
- psz_name ="Windows Media Video 1";
- break;
- case FOURCC_WMV2:
- i_codec = CODEC_ID_WMV2;
- psz_name ="Windows Media Video 2";
- break;
-
- }
-
- if( i_codec )
- {
- if( pi_ffmpeg_codec ) *pi_ffmpeg_codec = i_codec;
- if( ppsz_name ) *ppsz_name = psz_name;
- return VLC_TRUE;
- }
-
- return VLC_FALSE;
-}
-
-/* FIXME FIXME some of them are wrong */
-static int i_ffmpeg_PixFmtToChroma[] =
-{
- /* PIX_FMT_ANY = -1, PIX_FMT_YUV420P,
- PIX_FMT_YUV422, PIX_FMT_RGB24,
- PIX_FMT_BGR24, PIX_FMT_YUV422P,
- PIX_FMT_YUV444P, PIX_FMT_YUV410P
- */
- 0, VLC_FOURCC('I','4','2','0'),
- VLC_FOURCC('I','4','2','0'), VLC_FOURCC('R','V','2','4'),
- 0, VLC_FOURCC('Y','4','2','2'),
- VLC_FOURCC('I','4','4','4'), 0
-};
-
-static inline u32 ffmpeg_PixFmtToChroma( int i_ffmpegchroma )
-{
- if( ++i_ffmpegchroma > 7 )
- {
- return( 0 );
- }
- else
- {
- return( i_ffmpeg_PixFmtToChroma[i_ffmpegchroma] );
- }
-}
-
-static inline int ffmpeg_FfAspect( int i_width, int i_height, int i_ffaspect )
-{
- switch( i_ffaspect )
- {
- case( FF_ASPECT_4_3_625 ):
- case( FF_ASPECT_4_3_525 ):
- return( VOUT_ASPECT_FACTOR * 4 / 3);
- case( FF_ASPECT_16_9_625 ):
- case( FF_ASPECT_16_9_525 ):
- return( VOUT_ASPECT_FACTOR * 16 / 9 );
- case( FF_ASPECT_SQUARE ):
- default:
- return( VOUT_ASPECT_FACTOR * i_width / i_height );
- }
-}
+struct picture_t;
+struct AVFrame;
+struct AVCodecContext;
+struct AVCodec;
+
+void E_(InitLibavcodec)( vlc_object_t * );
+int E_(GetFfmpegCodec) ( vlc_fourcc_t, int *, int *, char ** );
+int E_(GetVlcFourcc) ( int, int *, vlc_fourcc_t *, char ** );
+int E_(GetFfmpegChroma)( vlc_fourcc_t );
+vlc_fourcc_t E_(GetVlcChroma)( int );
+
+/* Video decoder module */
+int E_( InitVideoDec )( decoder_t *, AVCodecContext *, AVCodec *,
+ int, char * );
+void E_( EndVideoDec ) ( decoder_t * );
+picture_t *E_( DecodeVideo ) ( decoder_t *, block_t ** );
+
+/* Audio decoder module */
+int E_( InitAudioDec )( decoder_t *, AVCodecContext *, AVCodec *,
+ int, char * );
+void E_( EndAudioDec ) ( decoder_t * );
+aout_buffer_t *E_( DecodeAudio ) ( decoder_t *, block_t ** );
+
+/* Chroma conversion module */
+int E_(OpenChroma)( vlc_object_t * );
+void E_(CloseChroma)( vlc_object_t * );
+
+/* Video encoder module */
+int E_(OpenEncoder) ( vlc_object_t * );
+void E_(CloseEncoder)( vlc_object_t * );
+
+/* Audio encoder module */
+int E_(OpenAudioEncoder) ( vlc_object_t * );
+void E_(CloseAudioEncoder)( vlc_object_t * );
+
+/* Demux module */
+int E_(OpenDemux) ( vlc_object_t * );
+void E_(CloseDemux)( vlc_object_t * );
+
+/* Video filter module */
+int E_(OpenFilter)( vlc_object_t * );
+void E_(CloseFilter)( vlc_object_t * );
+
+/* Postprocessing module */
+void *E_(OpenPostproc)( decoder_t *, vlc_bool_t * );
+int E_(InitPostproc)( decoder_t *, void *, int, int, int );
+int E_(PostprocPict)( decoder_t *, void *, picture_t *, AVFrame * );
+void E_(ClosePostproc)( decoder_t *, void * );
+/*****************************************************************************
+ * Module descriptor help strings
+ *****************************************************************************/
+#define DR_TEXT N_("Direct rendering")
+
+#define ERROR_TEXT N_("Error resilience")
+#define ERROR_LONGTEXT N_( \
+ "ffmpeg can do error resilience.\n" \
+ "However, with a buggy encoder (such as the ISO MPEG-4 encoder from M$) " \
+ "this can produce a lot of errors.\n" \
+ "Valid values range from 0 to 4 (0 disables all errors resilience).")
+
+#define BUGS_TEXT N_("Workaround bugs")
+#define BUGS_LONGTEXT N_( \
+ "Try to fix some bugs\n" \
+ "1 autodetect\n" \
+ "2 old msmpeg4\n" \
+ "4 xvid interlaced\n" \
+ "8 ump4 \n" \
+ "16 no padding\n" \
+ "32 ac vlc\n" \
+ "64 Qpel chroma")
+
+#define HURRYUP_TEXT N_("Hurry up")
+#define HURRYUP_LONGTEXT N_( \
+ "Allow the decoder to partially decode or skip frame(s) " \
+ "when there is not enough time. It's useful with low CPU power " \
+ "but it can produce distorted pictures.")
+
+#define PP_Q_TEXT N_("Post processing quality")
+#define PP_Q_LONGTEXT N_( \
+ "Quality of post processing. Valid range is 0 to 6\n" \
+ "Higher levels require considerable more CPU power, but produce " \
+ "better looking pictures." )
+
+#define DEBUG_TEXT N_( "Debug mask" )
+#define DEBUG_LONGTEXT N_( "Set ffmpeg debug mask" )
+
+#define VISMV_TEXT N_( "Visualize motion vectors" )
+#define VISMV_LONGTEXT N_( "Set motion vectors visualization mask.\n" \
+ "1 - visualize forward predicted MVs of P frames\n" \
+ "2 - visualize forward predicted MVs of B frames\n" \
+ "4 - visualize backward predicted MVs of B frames" )
+
+#define LIBAVCODEC_PP_TEXT N_("ffmpeg post processing filter chains")
+/* FIXME (cut/past from ffmpeg */
+#define LIBAVCODEC_PP_LONGTEXT \
+"<filterName>[:<option>[:<option>...]][[,|/][-]<filterName>[:<option>...]]...\n" \
+"long form example:\n" \
+"vdeblock:autoq/hdeblock:autoq/linblenddeint default,-vdeblock\n" \
+"short form example:\n" \
+"vb:a/hb:a/lb de,-vb\n" \
+"more examples:\n" \
+"tn:64:128:256\n" \
+"Filters Options\n" \
+"short long name short long option Description\n" \
+"* * a autoq cpu power dependant enabler\n" \
+" c chrom chrominance filtring enabled\n" \
+" y nochrom chrominance filtring disabled\n" \
+"hb hdeblock (2 Threshold) horizontal deblocking filter\n" \
+" 1. difference factor: default=64, higher -> more deblocking\n" \
+" 2. flatness threshold: default=40, lower -> more deblocking\n" \
+" the h & v deblocking filters share these\n" \
+" so u cant set different thresholds for h / v\n" \
+"vb vdeblock (2 Threshold) vertical deblocking filter\n" \
+"h1 x1hdeblock Experimental h deblock filter 1\n" \
+"v1 x1vdeblock Experimental v deblock filter 1\n" \
+"dr dering Deringing filter\n" \
+"al autolevels automatic brightness / contrast\n" \
+" f fullyrange stretch luminance to (0..255)\n" \
+"lb linblenddeint linear blend deinterlacer\n" \
+"li linipoldeint linear interpolating deinterlace\n" \
+"ci cubicipoldeint cubic interpolating deinterlacer\n" \
+"md mediandeint median deinterlacer\n" \
+"fd ffmpegdeint ffmpeg deinterlacer\n" \
+"de default hb:a,vb:a,dr:a,al\n" \
+"fa fast h1:a,v1:a,dr:a,al\n" \
+"tn tmpnoise (3 Thresholds) Temporal Noise Reducer\n" \
+" 1. <= 2. <= 3. larger -> stronger filtering\n" \
+"fq forceQuant <quantizer> Force quantizer\n"
+
+/*
+ * Encoder options
+ */
+#define ENC_CFG_PREFIX "sout-ffmpeg-"
+
+#define ENC_KEYINT_TEXT N_( "Ratio of key frames" )
+#define ENC_KEYINT_LONGTEXT N_( "Allows you to specify the number of frames " \
+ "that will be coded for one key frame." )
+
+#define ENC_BFRAMES_TEXT N_( "Ratio of B frames" )
+#define ENC_BFRAMES_LONGTEXT N_( "Allows you to specify the number of " \
+ "B frames that will be coded between two reference frames." )
+
+#define ENC_VT_TEXT N_( "Video bitrate tolerance" )
+#define ENC_VT_LONGTEXT N_( "Allows you to specify the video bitrate " \
+ "tolerance in kbit/s." )
+
+#define ENC_INTERLACE_TEXT N_( "Enable interlaced encoding" )
+#define ENC_INTERLACE_LONGTEXT N_( "Allows you to enable dedicated " \
+ "algorithms for interlaced frames." )
+
+#define ENC_PRE_ME_TEXT N_( "Enable pre motion estimation" )
+#define ENC_PRE_ME_LONGTEXT N_( "Allows you to enable the pre motion " \
+ "estimation." )
+
+#define ENC_RC_STRICT_TEXT N_( "Enable strict rate control" )
+#define ENC_RC_STRICT_LONGTEXT N_( "Allows you to enable the strict rate " \
+ "control algorithm." )
+
+#define ENC_RC_BUF_TEXT N_( "Rate control buffer size" )
+#define ENC_RC_BUF_LONGTEXT N_( "Allows you to specify the rate control " \
+ "buffer size." )
+
+#define ENC_RC_BUF_AGGR_TEXT N_( "Rate control buffer aggressiveness" )
+#define ENC_RC_BUF_AGGR_LONGTEXT N_( "Allows you to specify the rate control "\
+ "buffer aggressiveness." )
+
+#define ENC_IQUANT_FACTOR_TEXT N_( "I quantization factor" )
+#define ENC_IQUANT_FACTOR_LONGTEXT N_( "Allows you to specify the " \
+ "quantization factor of I frames, compared with P frames (for instance " \
+ "1.0 => same qscale for I and P frames)." )
+
+#define ENC_NOISE_RED_TEXT N_( "Noise reduction" )
+#define ENC_NOISE_RED_LONGTEXT N_( "Allows you to enable a simple noise " \
+ "reduction algorithm to lower the encoding length and bitrate, at the " \
+ "expense of lower quality frames." )
+
+#define ENC_MPEG4_MATRIX_TEXT N_( "Enable MPEG4 quantization matrix" )
+#define ENC_MPEG4_MATRIX_LONGTEXT N_( "Allows you to use the MPEG4 " \
+ "quantization matrix for mpeg2 encoding. This generally yields a " \
+ "better looking picture, while still retaining the compatibility with " \
+ "standard MPEG-2 decoders.")
+
+#define ENC_HQ_TEXT N_( "Quality level" )
+#define ENC_HQ_LONGTEXT N_( "Allows you to specify the quality level " \
+ "for the encoding of motions vectors (this can slow down the encoding " \
+ "very much)." )
+
+#define ENC_HURRYUP_TEXT N_( "Hurry up" )
+#define ENC_HURRYUP_LONGTEXT N_( "Allows you to specify if the encoder " \
+ "should make on-the-fly quality tradeoffs if your CPU can't keep up with " \
+ "the encoding rate. It will disable trellis quantization, then the rate " \
+ "distortion of motion vectors (hq), and raise the noise reduction " \
+ "threshold to ease the encoder's task." )
+
+#define ENC_QMIN_TEXT N_( "Minimum video quantizer scale" )
+#define ENC_QMIN_LONGTEXT N_( "Allows you to specify the minimum video " \
+ "quantizer scale." )
+
+#define ENC_QMAX_TEXT N_( "Maximum video quantizer scale" )
+#define ENC_QMAX_LONGTEXT N_( "Allows you to specify the maximum video " \
+ "quantizer scale." )
+
+#define ENC_TRELLIS_TEXT N_( "Enable trellis quantization" )
+#define ENC_TRELLIS_LONGTEXT N_( "Allows you to enable trellis " \
+ "quantization (rate distortion for block coefficients)." )
+
+#define ENC_QSCALE_TEXT N_( "Use fixed video quantizer scale" )
+#define ENC_QSCALE_LONGTEXT N_( "Allows you to specify a fixed video " \
+ "quantizer scale for VBR encoding (accepted values: 0.01 to 255.0)." )
+
+#define ENC_STRICT_TEXT N_( "Strict standard compliance" )
+#define ENC_STRICT_LONGTEXT N_( "Allows you to force a strict standard " \
+ "compliance when encoding (accepted values: -1, 0, 1)." )