summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore11
-rw-r--r--CREDITS2
-rw-r--r--Changelog147
-rw-r--r--Doxyfile8
-rw-r--r--INSTALL9
-rw-r--r--LICENSE24
-rw-r--r--MAINTAINERS401
-rw-r--r--Makefile98
-rw-r--r--README4
-rw-r--r--RELEASE2
-rw-r--r--avconv.c4274
-rw-r--r--cmdutils.c715
-rw-r--r--cmdutils.h188
-rw-r--r--cmdutils_common_opts.h27
-rw-r--r--common.mak78
-rwxr-xr-xconfigure428
-rw-r--r--doc/APIchanges242
-rw-r--r--doc/RELEASE_NOTES43
-rw-r--r--doc/TODO82
-rw-r--r--doc/avconv.texi979
-rw-r--r--doc/avtools-common-opts.texi157
-rw-r--r--doc/bitstream_filters.texi2
-rw-r--r--doc/build_system.txt24
-rw-r--r--doc/decoders.texi50
-rw-r--r--doc/demuxers.texi4
-rw-r--r--doc/developer.texi259
-rw-r--r--doc/encoders.texi190
-rw-r--r--doc/eval.texi42
-rw-r--r--doc/examples/Makefile21
-rw-r--r--doc/examples/decoding_encoding.c (renamed from libavcodec/api-example.c)80
-rw-r--r--doc/examples/filtering.c230
-rw-r--r--doc/examples/metadata.c (renamed from libavformat/metadata-example.c)1
-rw-r--r--doc/examples/muxing.c (renamed from libavformat/output-example.c)66
-rw-r--r--doc/faq.texi85
-rw-r--r--doc/fate.txt6
-rw-r--r--doc/ffmpeg-mt-authorship.txt4561
-rw-r--r--doc/ffmpeg.texi464
-rw-r--r--doc/ffmpeg.txt47
-rw-r--r--doc/ffplay.texi45
-rw-r--r--doc/ffprobe.texi73
-rw-r--r--doc/ffserver.conf2
-rw-r--r--doc/ffserver.texi6
-rw-r--r--doc/fftools-common-opts.texi93
-rw-r--r--doc/filters.texi1278
-rw-r--r--doc/general.texi173
-rw-r--r--doc/git-howto.txt18
-rw-r--r--doc/indevs.texi286
-rw-r--r--doc/issue_tracker.txt213
-rw-r--r--doc/libavfilter.texi20
-rw-r--r--doc/metadata.texi4
-rw-r--r--doc/multithreading.txt4
-rw-r--r--doc/muxers.texi20
-rw-r--r--doc/optimization.txt8
-rw-r--r--doc/outdevs.texi44
-rw-r--r--doc/protocols.texi29
-rw-r--r--doc/soc.txt6
-rw-r--r--doc/swresample.txt46
-rwxr-xr-xdoc/texi2pod.pl1
-rw-r--r--ffmpeg.c4595
-rw-r--r--ffplay.c1154
-rw-r--r--ffpresets/libvpx-1080p.ffpreset17
-rw-r--r--ffpresets/libvpx-1080p50_60.ffpreset17
-rw-r--r--ffpresets/libvpx-360p.ffpreset16
-rw-r--r--ffpresets/libvpx-720p.ffpreset17
-rw-r--r--ffpresets/libvpx-720p50_60.ffpreset17
-rw-r--r--ffpresets/libx264-baseline.ffpreset4
-rw-r--r--ffpresets/libx264-fast.ffpreset23
-rw-r--r--ffpresets/libx264-fast_firstpass.ffpreset23
-rw-r--r--ffpresets/libx264-faster.ffpreset23
-rw-r--r--ffpresets/libx264-faster_firstpass.ffpreset23
-rw-r--r--ffpresets/libx264-ipod320.ffpreset7
-rw-r--r--ffpresets/libx264-ipod640.ffpreset8
-rw-r--r--ffpresets/libx264-lossless_fast.ffpreset20
-rw-r--r--ffpresets/libx264-lossless_max.ffpreset21
-rw-r--r--ffpresets/libx264-lossless_medium.ffpreset20
-rw-r--r--ffpresets/libx264-lossless_slow.ffpreset21
-rw-r--r--ffpresets/libx264-lossless_slower.ffpreset21
-rw-r--r--ffpresets/libx264-lossless_ultrafast.ffpreset19
-rw-r--r--ffpresets/libx264-main.ffpreset1
-rw-r--r--ffpresets/libx264-medium.ffpreset22
-rw-r--r--ffpresets/libx264-medium_firstpass.ffpreset22
-rw-r--r--ffpresets/libx264-placebo.ffpreset23
-rw-r--r--ffpresets/libx264-placebo_firstpass.ffpreset23
-rw-r--r--ffpresets/libx264-slow.ffpreset23
-rw-r--r--ffpresets/libx264-slow_firstpass.ffpreset23
-rw-r--r--ffpresets/libx264-slower.ffpreset23
-rw-r--r--ffpresets/libx264-slower_firstpass.ffpreset23
-rw-r--r--ffpresets/libx264-superfast.ffpreset23
-rw-r--r--ffpresets/libx264-superfast_firstpass.ffpreset23
-rw-r--r--ffpresets/libx264-ultrafast.ffpreset24
-rw-r--r--ffpresets/libx264-ultrafast_firstpass.ffpreset24
-rw-r--r--ffpresets/libx264-veryfast.ffpreset23
-rw-r--r--ffpresets/libx264-veryfast_firstpass.ffpreset23
-rw-r--r--ffpresets/libx264-veryslow.ffpreset23
-rw-r--r--ffpresets/libx264-veryslow_firstpass.ffpreset23
-rw-r--r--ffprobe.c762
-rw-r--r--ffserver.c65
-rw-r--r--libavcodec/4xm.c132
-rw-r--r--libavcodec/8bps.c28
-rw-r--r--libavcodec/8svx.c204
-rw-r--r--libavcodec/Makefile124
-rw-r--r--libavcodec/a64colors.h8
-rw-r--r--libavcodec/a64enc.h8
-rw-r--r--libavcodec/a64multienc.c8
-rw-r--r--libavcodec/a64tables.h8
-rw-r--r--libavcodec/aac.h18
-rw-r--r--libavcodec/aac_ac3_parser.c8
-rw-r--r--libavcodec/aac_ac3_parser.h8
-rw-r--r--libavcodec/aac_adtstoasc_bsf.c14
-rw-r--r--libavcodec/aac_parser.c10
-rw-r--r--libavcodec/aac_tablegen.c8
-rw-r--r--libavcodec/aac_tablegen.h8
-rw-r--r--libavcodec/aac_tablegen_decl.h8
-rw-r--r--libavcodec/aacadtsdec.c14
-rw-r--r--libavcodec/aacadtsdec.h10
-rw-r--r--libavcodec/aaccoder.c9
-rw-r--r--libavcodec/aacdec.c96
-rw-r--r--libavcodec/aacdectab.h8
-rw-r--r--libavcodec/aacenc.c71
-rw-r--r--libavcodec/aacenc.h8
-rw-r--r--libavcodec/aacps.c59
-rw-r--r--libavcodec/aacps.h16
-rw-r--r--libavcodec/aacps_tablegen.c8
-rw-r--r--libavcodec/aacps_tablegen.h10
-rw-r--r--libavcodec/aacpsdata.c8
-rw-r--r--libavcodec/aacpsy.c8
-rw-r--r--libavcodec/aacpsy.h8
-rw-r--r--libavcodec/aacsbr.c13
-rw-r--r--libavcodec/aacsbr.h8
-rw-r--r--libavcodec/aacsbrdata.h8
-rw-r--r--libavcodec/aactab.c8
-rw-r--r--libavcodec/aactab.h8
-rw-r--r--libavcodec/aandcttab.c8
-rw-r--r--libavcodec/aandcttab.h8
-rw-r--r--libavcodec/aasc.c27
-rw-r--r--libavcodec/ac3.c8
-rw-r--r--libavcodec/ac3.h10
-rw-r--r--libavcodec/ac3_parser.c12
-rw-r--r--libavcodec/ac3_parser.h10
-rw-r--r--libavcodec/ac3dec.c73
-rw-r--r--libavcodec/ac3dec.h21
-rw-r--r--libavcodec/ac3dec_data.c8
-rw-r--r--libavcodec/ac3dec_data.h8
-rw-r--r--libavcodec/ac3dsp.c8
-rw-r--r--libavcodec/ac3dsp.h8
-rw-r--r--libavcodec/ac3enc.c605
-rw-r--r--libavcodec/ac3enc.h51
-rw-r--r--libavcodec/ac3enc_fixed.c57
-rw-r--r--libavcodec/ac3enc_float.c65
-rw-r--r--libavcodec/ac3enc_opts_template.c88
-rw-r--r--libavcodec/ac3enc_template.c172
-rw-r--r--libavcodec/ac3tab.c8
-rw-r--r--libavcodec/ac3tab.h8
-rw-r--r--libavcodec/acelp_filters.c8
-rw-r--r--libavcodec/acelp_filters.h8
-rw-r--r--libavcodec/acelp_pitch_delay.c8
-rw-r--r--libavcodec/acelp_pitch_delay.h8
-rw-r--r--libavcodec/acelp_vectors.c8
-rw-r--r--libavcodec/acelp_vectors.h8
-rw-r--r--libavcodec/adpcm.c1395
-rw-r--r--libavcodec/adpcm.h46
-rw-r--r--libavcodec/adpcm_data.c78
-rw-r--r--libavcodec/adpcm_data.h39
-rw-r--r--libavcodec/adpcmenc.c686
-rw-r--r--libavcodec/adx.h8
-rw-r--r--libavcodec/adxdec.c22
-rw-r--r--libavcodec/adxenc.c23
-rw-r--r--libavcodec/alac.c38
-rw-r--r--libavcodec/alacenc.c27
-rw-r--r--libavcodec/allcodecs.c49
-rw-r--r--libavcodec/alpha/asm.h8
-rw-r--r--libavcodec/alpha/dsputil_alpha.c15
-rw-r--r--libavcodec/alpha/dsputil_alpha.h8
-rw-r--r--libavcodec/alpha/dsputil_alpha_asm.S8
-rw-r--r--libavcodec/alpha/motion_est_alpha.c8
-rw-r--r--libavcodec/alpha/motion_est_mvi_asm.S8
-rw-r--r--libavcodec/alpha/mpegvideo_alpha.c8
-rw-r--r--libavcodec/alpha/regdef.h8
-rw-r--r--libavcodec/alpha/simple_idct_alpha.c8
-rw-r--r--libavcodec/alsdec.c25
-rw-r--r--libavcodec/amr.h8
-rw-r--r--libavcodec/amrnbdata.h8
-rw-r--r--libavcodec/amrnbdec.c11
-rw-r--r--libavcodec/amrwbdata.h8
-rw-r--r--libavcodec/amrwbdec.c8
-rw-r--r--libavcodec/anm.c37
-rw-r--r--libavcodec/ansi.c9
-rw-r--r--libavcodec/apedec.c23
-rw-r--r--libavcodec/arm/Makefile3
-rw-r--r--libavcodec/arm/aac.h8
-rw-r--r--libavcodec/arm/ac3dsp_armv6.S4
-rw-r--r--libavcodec/arm/ac3dsp_init_arm.c8
-rw-r--r--libavcodec/arm/asm-offsets.h20
-rw-r--r--libavcodec/arm/asm.S20
-rw-r--r--libavcodec/arm/dca.h49
-rw-r--r--libavcodec/arm/dcadsp_init_arm.c8
-rw-r--r--libavcodec/arm/dcadsp_neon.S8
-rw-r--r--libavcodec/arm/dsputil_arm.S8
-rw-r--r--libavcodec/arm/dsputil_arm.h8
-rw-r--r--libavcodec/arm/dsputil_armv6.S8
-rw-r--r--libavcodec/arm/dsputil_init_arm.c12
-rw-r--r--libavcodec/arm/dsputil_init_armv5te.c13
-rw-r--r--libavcodec/arm/dsputil_init_armv6.c18
-rw-r--r--libavcodec/arm/dsputil_init_neon.c29
-rw-r--r--libavcodec/arm/dsputil_init_vfp.c8
-rw-r--r--libavcodec/arm/dsputil_iwmmxt.c10
-rw-r--r--libavcodec/arm/dsputil_iwmmxt_rnd_template.c8
-rw-r--r--libavcodec/arm/dsputil_neon.S142
-rw-r--r--libavcodec/arm/dsputil_vfp.S8
-rw-r--r--libavcodec/arm/fft_fixed_init_arm.c8
-rw-r--r--libavcodec/arm/fft_fixed_neon.S2
-rw-r--r--libavcodec/arm/fft_init_arm.c8
-rw-r--r--libavcodec/arm/fft_neon.S24
-rw-r--r--libavcodec/arm/fmtconvert_init_arm.c8
-rw-r--r--libavcodec/arm/fmtconvert_neon.S8
-rw-r--r--libavcodec/arm/fmtconvert_vfp.S8
-rw-r--r--libavcodec/arm/h264dsp_init_arm.c96
-rw-r--r--libavcodec/arm/h264dsp_neon.S94
-rw-r--r--libavcodec/arm/h264idct_neon.S13
-rw-r--r--libavcodec/arm/h264pred_init_arm.c17
-rw-r--r--libavcodec/arm/h264pred_neon.S15
-rw-r--r--libavcodec/arm/int_neon.S8
-rw-r--r--libavcodec/arm/mathops.h8
-rw-r--r--libavcodec/arm/mdct_neon.S8
-rw-r--r--libavcodec/arm/mpegvideo_arm.c8
-rw-r--r--libavcodec/arm/mpegvideo_arm.h8
-rw-r--r--libavcodec/arm/mpegvideo_armv5te.c8
-rw-r--r--libavcodec/arm/mpegvideo_armv5te_s.S8
-rw-r--r--libavcodec/arm/mpegvideo_iwmmxt.c28
-rw-r--r--libavcodec/arm/mpegvideo_neon.S8
-rw-r--r--libavcodec/arm/rdft_neon.S8
-rw-r--r--libavcodec/arm/simple_idct_arm.S10
-rw-r--r--libavcodec/arm/simple_idct_armv5te.S8
-rw-r--r--libavcodec/arm/simple_idct_armv6.S8
-rw-r--r--libavcodec/arm/simple_idct_neon.S13
-rw-r--r--libavcodec/arm/synth_filter_neon.S8
-rw-r--r--libavcodec/arm/vp3dsp_neon.S16
-rw-r--r--libavcodec/arm/vp56_arith.h8
-rw-r--r--libavcodec/arm/vp56dsp_init_arm.c8
-rw-r--r--libavcodec/arm/vp56dsp_neon.S8
-rw-r--r--libavcodec/arm/vp8.h8
-rw-r--r--libavcodec/arm/vp8_armv6.S12
-rw-r--r--libavcodec/arm/vp8dsp_armv6.S2328
-rw-r--r--libavcodec/arm/vp8dsp_init_arm.c332
-rw-r--r--libavcodec/arm/vp8dsp_neon.S37
-rw-r--r--libavcodec/ass.c38
-rw-r--r--libavcodec/ass.h34
-rw-r--r--libavcodec/ass_split.c468
-rw-r--r--libavcodec/ass_split.h172
-rw-r--r--libavcodec/assdec.c24
-rw-r--r--libavcodec/assenc.c8
-rw-r--r--libavcodec/asv1.c68
-rw-r--r--libavcodec/atrac.c8
-rw-r--r--libavcodec/atrac.h8
-rw-r--r--libavcodec/atrac1.c10
-rw-r--r--libavcodec/atrac1data.h8
-rw-r--r--libavcodec/atrac3.c8
-rw-r--r--libavcodec/atrac3data.h8
-rw-r--r--libavcodec/audioconvert.c8
-rw-r--r--libavcodec/audioconvert.h8
-rw-r--r--libavcodec/aura.c27
-rw-r--r--libavcodec/avcodec.h970
-rw-r--r--libavcodec/avfft.c8
-rw-r--r--libavcodec/avfft.h8
-rw-r--r--libavcodec/avpacket.c89
-rw-r--r--libavcodec/avr32/mathops.h8
-rw-r--r--libavcodec/avs.c39
-rw-r--r--libavcodec/bethsoftvideo.c13
-rw-r--r--libavcodec/bethsoftvideo.h8
-rw-r--r--libavcodec/bfi.c15
-rw-r--r--libavcodec/bfin/config_bfin.h8
-rw-r--r--libavcodec/bfin/dsputil_bfin.c40
-rw-r--r--libavcodec/bfin/dsputil_bfin.h8
-rw-r--r--libavcodec/bfin/fdct_bfin.S8
-rw-r--r--libavcodec/bfin/idct_bfin.S8
-rw-r--r--libavcodec/bfin/mathops.h8
-rw-r--r--libavcodec/bfin/mpegvideo_bfin.c17
-rw-r--r--libavcodec/bfin/pixels_bfin.S8
-rw-r--r--libavcodec/bfin/vp3_bfin.c8
-rw-r--r--libavcodec/bfin/vp3_idct_bfin.S8
-rw-r--r--libavcodec/bgmc.c8
-rw-r--r--libavcodec/bgmc.h8
-rw-r--r--libavcodec/bink.c113
-rw-r--r--libavcodec/binkaudio.c40
-rw-r--r--libavcodec/binkdata.h12
-rw-r--r--libavcodec/binkdsp.c (renamed from libavcodec/binkidct.c)46
-rw-r--r--libavcodec/binkdsp.h40
-rw-r--r--libavcodec/bintext.c250
-rw-r--r--libavcodec/bintext.h37
-rw-r--r--libavcodec/bit_depth_template.c31
-rw-r--r--libavcodec/bitstream.c16
-rw-r--r--libavcodec/bitstream_filter.c8
-rw-r--r--libavcodec/bmp.c27
-rw-r--r--libavcodec/bmp.h8
-rw-r--r--libavcodec/bmpenc.c21
-rw-r--r--libavcodec/bytestream.h8
-rw-r--r--libavcodec/c93.c29
-rw-r--r--libavcodec/cabac.c165
-rw-r--r--libavcodec/cabac.h180
-rw-r--r--libavcodec/cavs.c32
-rw-r--r--libavcodec/cavs.h8
-rw-r--r--libavcodec/cavs_parser.c8
-rw-r--r--libavcodec/cavsdata.h8
-rw-r--r--libavcodec/cavsdec.c63
-rw-r--r--libavcodec/cavsdsp.c8
-rw-r--r--libavcodec/cavsdsp.h8
-rw-r--r--libavcodec/cbrt_tablegen.c8
-rw-r--r--libavcodec/cbrt_tablegen.h8
-rw-r--r--libavcodec/cdgraphics.c30
-rw-r--r--libavcodec/celp_filters.c12
-rw-r--r--libavcodec/celp_filters.h11
-rw-r--r--libavcodec/celp_math.c20
-rw-r--r--libavcodec/celp_math.h18
-rw-r--r--libavcodec/cga_data.c8
-rw-r--r--libavcodec/cga_data.h8
-rw-r--r--libavcodec/chomp_bsf.c8
-rw-r--r--libavcodec/cinepak.c34
-rw-r--r--libavcodec/cljr.c42
-rwxr-xr-xlibavcodec/codec_names.sh85
-rw-r--r--libavcodec/cook.c13
-rw-r--r--libavcodec/cookdata.h8
-rw-r--r--libavcodec/cos_tablegen.c8
-rw-r--r--libavcodec/crystalhd.c1141
-rw-r--r--libavcodec/cscd.c26
-rw-r--r--libavcodec/cyuv.c45
-rw-r--r--libavcodec/dca.c56
-rw-r--r--libavcodec/dca.h8
-rw-r--r--libavcodec/dca_parser.c8
-rw-r--r--libavcodec/dcadata.h10
-rw-r--r--libavcodec/dcadsp.c8
-rw-r--r--libavcodec/dcadsp.h8
-rw-r--r--libavcodec/dcaenc.c586
-rw-r--r--libavcodec/dcaenc.h544
-rw-r--r--libavcodec/dcahuff.h8
-rw-r--r--libavcodec/dct-test.c198
-rw-r--r--libavcodec/dct.c8
-rw-r--r--libavcodec/dct.h8
-rw-r--r--libavcodec/dct32.c8
-rw-r--r--libavcodec/dctref.c8
-rw-r--r--libavcodec/dctref.h14
-rw-r--r--libavcodec/dfa.c25
-rw-r--r--libavcodec/dirac.c28
-rw-r--r--libavcodec/dirac.h12
-rw-r--r--libavcodec/dirac_parser.c8
-rw-r--r--libavcodec/dnxhd_parser.c8
-rw-r--r--libavcodec/dnxhddata.c852
-rw-r--r--libavcodec/dnxhddata.h10
-rw-r--r--libavcodec/dnxhddec.c203
-rw-r--r--libavcodec/dnxhdenc.c333
-rw-r--r--libavcodec/dnxhdenc.h12
-rw-r--r--libavcodec/dpcm.c268
-rw-r--r--libavcodec/dpx.c25
-rw-r--r--libavcodec/dpxenc.c18
-rw-r--r--libavcodec/dsicinav.c44
-rw-r--r--libavcodec/dsputil.c373
-rw-r--r--libavcodec/dsputil.h88
-rw-r--r--libavcodec/dsputil_template.c409
-rw-r--r--libavcodec/dump_extradata_bsf.c8
-rw-r--r--libavcodec/dv.c51
-rw-r--r--libavcodec/dv_tablegen.c8
-rw-r--r--libavcodec/dv_tablegen.h8
-rw-r--r--libavcodec/dv_vlc_data.h8
-rw-r--r--libavcodec/dvbsub.c101
-rw-r--r--libavcodec/dvbsub_parser.c10
-rw-r--r--libavcodec/dvbsubdec.c196
-rw-r--r--libavcodec/dvdata.c30
-rw-r--r--libavcodec/dvdata.h14
-rw-r--r--libavcodec/dvdsub_parser.c8
-rw-r--r--libavcodec/dvdsubdec.c117
-rw-r--r--libavcodec/dvdsubenc.c18
-rw-r--r--libavcodec/dwt.c8
-rw-r--r--libavcodec/dwt.h8
-rw-r--r--libavcodec/dxa.c28
-rw-r--r--libavcodec/dxva2.c10
-rw-r--r--libavcodec/dxva2.h14
-rw-r--r--libavcodec/dxva2_h264.c67
-rw-r--r--libavcodec/dxva2_internal.h8
-rw-r--r--libavcodec/dxva2_mpeg2.c16
-rw-r--r--libavcodec/dxva2_vc1.c16
-rw-r--r--libavcodec/eac3_data.c (renamed from libavcodec/eac3dec_data.c)12
-rw-r--r--libavcodec/eac3_data.h (renamed from libavcodec/eac3dec_data.h)16
-rw-r--r--libavcodec/eac3dec.c10
-rw-r--r--libavcodec/eac3enc.c147
-rw-r--r--libavcodec/eac3enc.h10
-rw-r--r--libavcodec/eacmv.c47
-rw-r--r--libavcodec/eaidct.c8
-rw-r--r--libavcodec/eamad.c41
-rw-r--r--libavcodec/eatgq.c25
-rw-r--r--libavcodec/eatgv.c50
-rw-r--r--libavcodec/eatqi.c31
-rw-r--r--libavcodec/elbg.c8
-rw-r--r--libavcodec/elbg.h8
-rw-r--r--libavcodec/error_resilience.c212
-rw-r--r--libavcodec/escape124.c29
-rw-r--r--libavcodec/faandct.h8
-rw-r--r--libavcodec/faanidct.c8
-rw-r--r--libavcodec/faanidct.h8
-rw-r--r--libavcodec/faxcompr.c10
-rw-r--r--libavcodec/faxcompr.h10
-rw-r--r--libavcodec/fft-fixed-test.c8
-rw-r--r--libavcodec/fft-internal.h8
-rw-r--r--libavcodec/fft-test.c8
-rw-r--r--libavcodec/fft.c8
-rw-r--r--libavcodec/fft.h8
-rw-r--r--libavcodec/fft_fixed.c8
-rw-r--r--libavcodec/fft_float.c8
-rw-r--r--libavcodec/ffv1.c112
-rw-r--r--libavcodec/flac.c12
-rw-r--r--libavcodec/flac.h22
-rw-r--r--libavcodec/flac_parser.c8
-rw-r--r--libavcodec/flacdata.c8
-rw-r--r--libavcodec/flacdata.h8
-rw-r--r--libavcodec/flacdec.c47
-rw-r--r--libavcodec/flacenc.c79
-rw-r--r--libavcodec/flashsv.c434
-rw-r--r--libavcodec/flashsv2enc.c907
-rw-r--r--libavcodec/flashsvenc.c118
-rw-r--r--libavcodec/flicvideo.c83
-rw-r--r--libavcodec/flv.h8
-rw-r--r--libavcodec/flvdec.c25
-rw-r--r--libavcodec/flvenc.c24
-rw-r--r--libavcodec/fmtconvert.c39
-rw-r--r--libavcodec/fmtconvert.h22
-rw-r--r--libavcodec/fraps.c36
-rw-r--r--libavcodec/frwu.c26
-rw-r--r--libavcodec/g722.c9
-rw-r--r--libavcodec/g723_1.c2216
-rw-r--r--libavcodec/g723_1_data.h1315
-rw-r--r--libavcodec/g726.c38
-rw-r--r--libavcodec/g729.h29
-rw-r--r--libavcodec/g729data.h114
-rw-r--r--libavcodec/g729dec.c480
-rw-r--r--libavcodec/g729postfilter.c610
-rw-r--r--libavcodec/g729postfilter.h115
-rw-r--r--libavcodec/get_bits.h18
-rw-r--r--libavcodec/gif.c22
-rw-r--r--libavcodec/gifdec.c25
-rw-r--r--libavcodec/golomb.c8
-rw-r--r--libavcodec/golomb.h22
-rw-r--r--libavcodec/gsmdec.c36
-rw-r--r--libavcodec/gsmdec_data.c8
-rw-r--r--libavcodec/gsmdec_data.h8
-rw-r--r--libavcodec/gsmdec_template.c8
-rw-r--r--libavcodec/h261.c8
-rw-r--r--libavcodec/h261.h8
-rw-r--r--libavcodec/h261_parser.c22
-rw-r--r--libavcodec/h261data.h8
-rw-r--r--libavcodec/h261dec.c43
-rw-r--r--libavcodec/h261enc.c24
-rw-r--r--libavcodec/h263.c56
-rw-r--r--libavcodec/h263.h8
-rw-r--r--libavcodec/h263_parser.c22
-rw-r--r--libavcodec/h263_parser.h8
-rw-r--r--libavcodec/h263data.h8
-rw-r--r--libavcodec/h263dec.c69
-rw-r--r--libavcodec/h264.c1119
-rw-r--r--libavcodec/h264.h524
-rw-r--r--libavcodec/h264_cabac.c134
-rw-r--r--libavcodec/h264_cavlc.c145
-rw-r--r--libavcodec/h264_direct.c67
-rw-r--r--libavcodec/h264_loopfilter.c425
-rw-r--r--libavcodec/h264_mp4toannexb_bsf.c16
-rw-r--r--libavcodec/h264_mvpred.h599
-rw-r--r--libavcodec/h264_parser.c52
-rw-r--r--libavcodec/h264_ps.c68
-rw-r--r--libavcodec/h264_refs.c84
-rw-r--r--libavcodec/h264_sei.c11
-rw-r--r--libavcodec/h264data.h17
-rw-r--r--libavcodec/h264dsp.c74
-rw-r--r--libavcodec/h264dsp.h26
-rw-r--r--libavcodec/h264dsp_template.c90
-rw-r--r--libavcodec/h264idct.c8
-rw-r--r--libavcodec/h264idct_template.c137
-rw-r--r--libavcodec/h264pred.c76
-rw-r--r--libavcodec/h264pred.h14
-rw-r--r--libavcodec/h264pred_template.c368
-rw-r--r--libavcodec/huffman.c17
-rw-r--r--libavcodec/huffman.h17
-rw-r--r--libavcodec/huffyuv.c73
-rw-r--r--libavcodec/idcinvideo.c26
-rw-r--r--libavcodec/iff.c278
-rw-r--r--libavcodec/iirfilter.c8
-rw-r--r--libavcodec/iirfilter.h8
-rw-r--r--libavcodec/imc.c8
-rw-r--r--libavcodec/imcdata.h8
-rw-r--r--libavcodec/imgconvert.c430
-rw-r--r--libavcodec/imgconvert.h8
-rw-r--r--libavcodec/imx_dump_header_bsf.c8
-rw-r--r--libavcodec/indeo2.c39
-rw-r--r--libavcodec/indeo2data.h8
-rw-r--r--libavcodec/indeo3.c47
-rw-r--r--libavcodec/indeo3data.h8
-rw-r--r--libavcodec/indeo5.c10
-rw-r--r--libavcodec/indeo5data.h8
-rw-r--r--libavcodec/intelh263dec.c25
-rw-r--r--libavcodec/internal.h20
-rw-r--r--libavcodec/interplayvideo.c28
-rw-r--r--libavcodec/intrax8.c32
-rw-r--r--libavcodec/intrax8.h8
-rw-r--r--libavcodec/intrax8dsp.c8
-rw-r--r--libavcodec/intrax8huf.h8
-rw-r--r--libavcodec/ituh263dec.c41
-rw-r--r--libavcodec/ituh263enc.c21
-rw-r--r--libavcodec/ivi_common.c8
-rw-r--r--libavcodec/ivi_common.h10
-rw-r--r--libavcodec/ivi_dsp.c8
-rw-r--r--libavcodec/ivi_dsp.h8
-rw-r--r--libavcodec/j2k.c392
-rw-r--r--libavcodec/j2k.h234
-rw-r--r--libavcodec/j2k_dwt.c386
-rw-r--r--libavcodec/j2k_dwt.h63
-rw-r--r--libavcodec/j2kdec.c1071
-rw-r--r--libavcodec/j2kenc.c1053
-rw-r--r--libavcodec/jfdctint.c413
-rw-r--r--libavcodec/jfdctint_template.c405
-rw-r--r--libavcodec/jpegls.c8
-rw-r--r--libavcodec/jpegls.h10
-rw-r--r--libavcodec/jpeglsdec.c47
-rw-r--r--libavcodec/jpeglsdec.h8
-rw-r--r--libavcodec/jpeglsenc.c27
-rw-r--r--libavcodec/jvdec.c10
-rw-r--r--libavcodec/kbdwin.c8
-rw-r--r--libavcodec/kbdwin.h8
-rw-r--r--libavcodec/kgv1dec.c25
-rw-r--r--libavcodec/kmvc.c26
-rw-r--r--libavcodec/lagarith.c25
-rw-r--r--libavcodec/lagarithrac.c8
-rw-r--r--libavcodec/lagarithrac.h8
-rw-r--r--libavcodec/latm_parser.c8
-rw-r--r--libavcodec/lcl.h8
-rw-r--r--libavcodec/lcldec.c43
-rw-r--r--libavcodec/lclenc.c22
-rw-r--r--libavcodec/libaacplus.c136
-rw-r--r--libavcodec/libavcodec.v34
-rw-r--r--libavcodec/libcelt_dec.c136
-rw-r--r--libavcodec/libdirac.h10
-rw-r--r--libavcodec/libdirac_libschro.c8
-rw-r--r--libavcodec/libdirac_libschro.h8
-rw-r--r--libavcodec/libdiracdec.c29
-rw-r--r--libavcodec/libdiracenc.c22
-rw-r--r--libavcodec/libfaac.c32
-rw-r--r--libavcodec/libgsm.c143
-rw-r--r--libavcodec/libmp3lame.c117
-rw-r--r--libavcodec/libopencore-amr.c55
-rw-r--r--libavcodec/libopenjpeg.c77
-rw-r--r--libavcodec/libschroedinger.c8
-rw-r--r--libavcodec/libschroedinger.h8
-rw-r--r--libavcodec/libschroedingerdec.c31
-rw-r--r--libavcodec/libschroedingerenc.c22
-rw-r--r--libavcodec/libspeexdec.c93
-rw-r--r--libavcodec/libspeexenc.c324
-rw-r--r--libavcodec/libstagefright.cpp552
-rw-r--r--libavcodec/libtheoraenc.c10
-rw-r--r--libavcodec/libutvideo.cpp230
-rw-r--r--libavcodec/libvo-aacenc.c25
-rw-r--r--libavcodec/libvo-amrwbenc.c25
-rw-r--r--libavcodec/libvorbis.c63
-rw-r--r--libavcodec/libvpxdec.c24
-rw-r--r--libavcodec/libvpxenc.c157
-rw-r--r--libavcodec/libx264.c528
-rw-r--r--libavcodec/libxavs.c134
-rw-r--r--libavcodec/libxvid_internal.h8
-rw-r--r--libavcodec/libxvid_rc.c11
-rw-r--r--libavcodec/libxvidff.c71
-rw-r--r--libavcodec/ljpegenc.c24
-rw-r--r--libavcodec/loco.c27
-rw-r--r--libavcodec/lpc.c14
-rw-r--r--libavcodec/lpc.h8
-rw-r--r--libavcodec/lsp.c12
-rw-r--r--libavcodec/lsp.h10
-rw-r--r--libavcodec/lzw.c10
-rw-r--r--libavcodec/lzw.h10
-rw-r--r--libavcodec/lzwenc.c10
-rw-r--r--libavcodec/mace.c36
-rw-r--r--libavcodec/mathops.h12
-rw-r--r--libavcodec/mdct.c8
-rw-r--r--libavcodec/mdct_fixed.c8
-rw-r--r--libavcodec/mdct_float.c8
-rw-r--r--libavcodec/mdec.c31
-rw-r--r--libavcodec/mimic.c27
-rw-r--r--libavcodec/mips/mathops.h8
-rw-r--r--libavcodec/mjpeg.c8
-rw-r--r--libavcodec/mjpeg.h8
-rw-r--r--libavcodec/mjpeg2jpeg_bsf.c8
-rw-r--r--libavcodec/mjpeg_parser.c8
-rw-r--r--libavcodec/mjpega_dump_header_bsf.c8
-rw-r--r--libavcodec/mjpegbdec.c34
-rw-r--r--libavcodec/mjpegdec.c192
-rw-r--r--libavcodec/mjpegdec.h13
-rw-r--r--libavcodec/mjpegenc.c62
-rw-r--r--libavcodec/mjpegenc.h8
-rw-r--r--libavcodec/mlib/dsputil_mlib.c13
-rw-r--r--libavcodec/mlp.c8
-rw-r--r--libavcodec/mlp.h8
-rw-r--r--libavcodec/mlp_parser.c42
-rw-r--r--libavcodec/mlp_parser.h11
-rw-r--r--libavcodec/mlpdec.c221
-rw-r--r--libavcodec/mlpdsp.c8
-rw-r--r--libavcodec/mmvideo.c26
-rw-r--r--libavcodec/motion-test.c10
-rw-r--r--libavcodec/motion_est.c213
-rw-r--r--libavcodec/motion_est_template.c187
-rw-r--r--libavcodec/motionpixels.c38
-rw-r--r--libavcodec/motionpixels_tablegen.c8
-rw-r--r--libavcodec/motionpixels_tablegen.h10
-rw-r--r--libavcodec/movsub_bsf.c8
-rw-r--r--libavcodec/mp3_header_compress_bsf.c8
-rw-r--r--libavcodec/mp3_header_decompress_bsf.c12
-rw-r--r--libavcodec/mpc.c8
-rw-r--r--libavcodec/mpc.h8
-rw-r--r--libavcodec/mpc7.c33
-rw-r--r--libavcodec/mpc7data.h8
-rw-r--r--libavcodec/mpc8.c36
-rw-r--r--libavcodec/mpc8data.h8
-rw-r--r--libavcodec/mpc8huff.h8
-rw-r--r--libavcodec/mpcdata.h8
-rw-r--r--libavcodec/mpeg12.c2582
-rw-r--r--libavcodec/mpeg12.h8
-rw-r--r--libavcodec/mpeg12data.c10
-rw-r--r--libavcodec/mpeg12data.h10
-rw-r--r--libavcodec/mpeg12decdata.h8
-rw-r--r--libavcodec/mpeg12enc.c129
-rw-r--r--libavcodec/mpeg4audio.c18
-rw-r--r--libavcodec/mpeg4audio.h18
-rw-r--r--libavcodec/mpeg4data.h8
-rw-r--r--libavcodec/mpeg4video.c16
-rw-r--r--libavcodec/mpeg4video.h8
-rw-r--r--libavcodec/mpeg4video_parser.c9
-rw-r--r--libavcodec/mpeg4video_parser.h8
-rw-r--r--libavcodec/mpeg4videodec.c219
-rw-r--r--libavcodec/mpeg4videoenc.c105
-rw-r--r--libavcodec/mpegaudio.c8
-rw-r--r--libavcodec/mpegaudio.h8
-rw-r--r--libavcodec/mpegaudio_parser.c13
-rw-r--r--libavcodec/mpegaudio_tablegen.c8
-rw-r--r--libavcodec/mpegaudio_tablegen.h8
-rw-r--r--libavcodec/mpegaudiodata.c12
-rw-r--r--libavcodec/mpegaudiodata.h12
-rw-r--r--libavcodec/mpegaudiodec.c223
-rw-r--r--libavcodec/mpegaudiodec_float.c122
-rw-r--r--libavcodec/mpegaudiodecheader.c18
-rw-r--r--libavcodec/mpegaudiodecheader.h12
-rw-r--r--libavcodec/mpegaudiodectab.h8
-rw-r--r--libavcodec/mpegaudiodsp.c8
-rw-r--r--libavcodec/mpegaudiodsp_template.c8
-rw-r--r--libavcodec/mpegaudioenc.c40
-rw-r--r--libavcodec/mpegaudiotab.h8
-rw-r--r--libavcodec/mpegvideo.c576
-rw-r--r--libavcodec/mpegvideo.h34
-rw-r--r--libavcodec/mpegvideo_common.h40
-rw-r--r--libavcodec/mpegvideo_enc.c391
-rw-r--r--libavcodec/mpegvideo_parser.c19
-rw-r--r--libavcodec/mpegvideo_xvmc.c22
-rw-r--r--libavcodec/mqc.c108
-rw-r--r--libavcodec/mqc.h75
-rw-r--r--libavcodec/mqcdec.c93
-rw-r--r--libavcodec/mqcenc.c119
-rw-r--r--libavcodec/msgsmdec.c8
-rw-r--r--libavcodec/msgsmdec.h8
-rw-r--r--libavcodec/msmpeg4.c88
-rw-r--r--libavcodec/msmpeg4.h12
-rw-r--r--libavcodec/msmpeg4data.c8
-rw-r--r--libavcodec/msmpeg4data.h8
-rw-r--r--libavcodec/msrle.c33
-rw-r--r--libavcodec/msrledec.c8
-rw-r--r--libavcodec/msrledec.h8
-rw-r--r--libavcodec/msvideo1.c26
-rw-r--r--libavcodec/msvideo1enc.c298
-rw-r--r--libavcodec/mxpegdec.c21
-rw-r--r--libavcodec/nellymoserdec.c71
-rw-r--r--libavcodec/nellymoserenc.c10
-rw-r--r--libavcodec/noise_bsf.c8
-rw-r--r--libavcodec/nuv.c25
-rw-r--r--libavcodec/options.c928
-rw-r--r--libavcodec/pamenc.c20
-rw-r--r--libavcodec/parser.c18
-rw-r--r--libavcodec/parser.h8
-rw-r--r--libavcodec/pcm-mpeg.c20
-rw-r--r--libavcodec/pcm.c89
-rw-r--r--libavcodec/pcm_tablegen.c8
-rw-r--r--libavcodec/pcm_tablegen.h8
-rw-r--r--libavcodec/pcx.c26
-rw-r--r--libavcodec/pcxenc.c25
-rw-r--r--libavcodec/pgssubdec.c24
-rw-r--r--libavcodec/pictordec.c33
-rw-r--r--libavcodec/png.c8
-rw-r--r--libavcodec/png.h48
-rw-r--r--libavcodec/pngdec.c182
-rw-r--r--libavcodec/pngenc.c21
-rw-r--r--libavcodec/pnm.c10
-rw-r--r--libavcodec/pnm.h8
-rw-r--r--libavcodec/pnm_parser.c8
-rw-r--r--libavcodec/pnmdec.c115
-rw-r--r--libavcodec/pnmenc.c56
-rw-r--r--libavcodec/ppc/asm.S27
-rw-r--r--libavcodec/ppc/dsputil_altivec.c26
-rw-r--r--libavcodec/ppc/dsputil_altivec.h8
-rw-r--r--libavcodec/ppc/dsputil_ppc.c35
-rw-r--r--libavcodec/ppc/fdct_altivec.c32
-rw-r--r--libavcodec/ppc/fft_altivec.c8
-rw-r--r--libavcodec/ppc/fft_altivec_s.S15
-rw-r--r--libavcodec/ppc/float_altivec.c8
-rw-r--r--libavcodec/ppc/fmtconvert_altivec.c8
-rw-r--r--libavcodec/ppc/gmc_altivec.c8
-rw-r--r--libavcodec/ppc/h264_altivec.c59
-rw-r--r--libavcodec/ppc/h264_template_altivec.c8
-rw-r--r--libavcodec/ppc/idct_altivec.c12
-rw-r--r--libavcodec/ppc/int_altivec.c8
-rw-r--r--libavcodec/ppc/mathops.h8
-rw-r--r--libavcodec/ppc/mpegaudiodec_altivec.c8
-rw-r--r--libavcodec/ppc/mpegvideo_altivec.c44
-rw-r--r--libavcodec/ppc/regs.h8
-rw-r--r--libavcodec/ppc/types_altivec.h8
-rw-r--r--libavcodec/ppc/util_altivec.h8
-rw-r--r--libavcodec/ppc/vc1dsp_altivec.c8
-rw-r--r--libavcodec/ppc/vp3dsp_altivec.c8
-rw-r--r--libavcodec/ppc/vp8dsp_altivec.c8
-rw-r--r--libavcodec/proresdec.h53
-rw-r--r--libavcodec/proresdec2.c593
-rw-r--r--libavcodec/proresdec_lgpl.c705
-rw-r--r--libavcodec/proresdsp.c63
-rw-r--r--libavcodec/proresdsp.h40
-rw-r--r--libavcodec/ps2/dsputil_mmi.c15
-rw-r--r--libavcodec/ps2/idct_mmi.c8
-rw-r--r--libavcodec/ps2/mmi.h8
-rw-r--r--libavcodec/ps2/mpegvideo_mmi.c8
-rw-r--r--libavcodec/psymodel.c8
-rw-r--r--libavcodec/psymodel.h8
-rw-r--r--libavcodec/pthread.c49
-rw-r--r--libavcodec/ptx.c33
-rw-r--r--libavcodec/put_bits.h19
-rw-r--r--libavcodec/qcelpdata.h10
-rw-r--r--libavcodec/qcelpdec.c202
-rw-r--r--libavcodec/qdm2.c30
-rw-r--r--libavcodec/qdm2_tablegen.c8
-rw-r--r--libavcodec/qdm2_tablegen.h10
-rw-r--r--libavcodec/qdm2data.h8
-rw-r--r--libavcodec/qdrw.c40
-rw-r--r--libavcodec/qpeg.c59
-rw-r--r--libavcodec/qtrle.c33
-rw-r--r--libavcodec/qtrleenc.c70
-rw-r--r--libavcodec/r210dec.c40
-rw-r--r--libavcodec/ra144.c48
-rw-r--r--libavcodec/ra144.h8
-rw-r--r--libavcodec/ra144dec.c55
-rw-r--r--libavcodec/ra144enc.c27
-rw-r--r--libavcodec/ra288.c52
-rw-r--r--libavcodec/ra288.h8
-rw-r--r--libavcodec/rangecoder.c8
-rw-r--r--libavcodec/rangecoder.h8
-rw-r--r--libavcodec/ratecontrol.c26
-rw-r--r--libavcodec/ratecontrol.h8
-rw-r--r--libavcodec/raw.c14
-rw-r--r--libavcodec/raw.h9
-rw-r--r--libavcodec/rawdec.c74
-rw-r--r--libavcodec/rawenc.c20
-rw-r--r--libavcodec/rdft.c8
-rw-r--r--libavcodec/rdft.h8
-rw-r--r--libavcodec/rectangle.h8
-rw-r--r--libavcodec/remove_extradata_bsf.c8
-rw-r--r--libavcodec/resample.c79
-rw-r--r--libavcodec/resample2.c8
-rw-r--r--libavcodec/rl.h8
-rw-r--r--libavcodec/rl2.c31
-rw-r--r--libavcodec/rle.c8
-rw-r--r--libavcodec/rle.h8
-rw-r--r--libavcodec/roqaudioenc.c23
-rw-r--r--libavcodec/roqvideo.c8
-rw-r--r--libavcodec/roqvideo.h8
-rw-r--r--libavcodec/roqvideodec.c39
-rw-r--r--libavcodec/roqvideoenc.c31
-rw-r--r--libavcodec/rpza.c26
-rw-r--r--libavcodec/rtjpeg.c8
-rw-r--r--libavcodec/rtjpeg.h8
-rw-r--r--libavcodec/rv10.c165
-rw-r--r--libavcodec/rv10enc.c24
-rw-r--r--libavcodec/rv20enc.c22
-rw-r--r--libavcodec/rv30.c58
-rw-r--r--libavcodec/rv30data.h8
-rw-r--r--libavcodec/rv30dsp.c125
-rw-r--r--libavcodec/rv34.c417
-rw-r--r--libavcodec/rv34.h16
-rw-r--r--libavcodec/rv34_parser.c95
-rw-r--r--libavcodec/rv34data.h8
-rw-r--r--libavcodec/rv34dsp.c106
-rw-r--r--libavcodec/rv34dsp.h54
-rw-r--r--libavcodec/rv34vlc.h8
-rw-r--r--libavcodec/rv40.c46
-rw-r--r--libavcodec/rv40data.h8
-rw-r--r--libavcodec/rv40dsp.c275
-rw-r--r--libavcodec/rv40vlc2.h8
-rw-r--r--libavcodec/s302m.c22
-rw-r--r--libavcodec/s3tc.c8
-rw-r--r--libavcodec/s3tc.h16
-rw-r--r--libavcodec/sbr.h8
-rw-r--r--libavcodec/sgi.h8
-rw-r--r--libavcodec/sgidec.c23
-rw-r--r--libavcodec/sgienc.c21
-rw-r--r--libavcodec/sh4/dsputil_align.c10
-rw-r--r--libavcodec/sh4/dsputil_sh4.c13
-rw-r--r--libavcodec/sh4/dsputil_sh4.h8
-rw-r--r--libavcodec/sh4/idct_sh4.c8
-rw-r--r--libavcodec/sh4/qpel.c8
-rw-r--r--libavcodec/sh4/sh4.h8
-rw-r--r--libavcodec/shorten.c540
-rw-r--r--libavcodec/simple_idct.c401
-rw-r--r--libavcodec/simple_idct.h25
-rw-r--r--libavcodec/simple_idct_template.c326
-rw-r--r--libavcodec/sinewin.c8
-rw-r--r--libavcodec/sinewin.h8
-rw-r--r--libavcodec/sinewin_tablegen.c8
-rw-r--r--libavcodec/sinewin_tablegen.h8
-rw-r--r--libavcodec/sipr.c39
-rw-r--r--libavcodec/sipr.h8
-rw-r--r--libavcodec/sipr16k.c8
-rw-r--r--libavcodec/sipr16kdata.h8
-rw-r--r--libavcodec/siprdata.h8
-rw-r--r--libavcodec/smacker.c88
-rw-r--r--libavcodec/smc.c26
-rw-r--r--libavcodec/snow.c86
-rw-r--r--libavcodec/snow.h8
-rw-r--r--libavcodec/sonic.c977
-rw-r--r--libavcodec/sp5x.h104
-rw-r--r--libavcodec/sp5xdec.c44
-rw-r--r--libavcodec/sparc/dsputil_vis.c13
-rw-r--r--libavcodec/sparc/dsputil_vis.h8
-rw-r--r--libavcodec/sparc/simple_idct_vis.c8
-rw-r--r--libavcodec/sparc/vis.h8
-rw-r--r--libavcodec/srtdec.c10
-rw-r--r--libavcodec/srtenc.c301
-rw-r--r--libavcodec/sunrast.c56
-rw-r--r--libavcodec/svq1.c8
-rw-r--r--libavcodec/svq1.h8
-rw-r--r--libavcodec/svq1_cb.h8
-rw-r--r--libavcodec/svq1_vlc.h8
-rw-r--r--libavcodec/svq1dec.c35
-rw-r--r--libavcodec/svq1enc.c40
-rw-r--r--libavcodec/svq1enc_cb.h8
-rw-r--r--libavcodec/svq3.c131
-rw-r--r--libavcodec/synth_filter.c8
-rw-r--r--libavcodec/synth_filter.h8
-rw-r--r--libavcodec/tableprint.h8
-rw-r--r--libavcodec/targa.c53
-rw-r--r--libavcodec/targa.h8
-rw-r--r--libavcodec/targaenc.c8
-rw-r--r--libavcodec/thread.h8
-rw-r--r--libavcodec/tiertexseqv.c91
-rw-r--r--libavcodec/tiff.c165
-rw-r--r--libavcodec/tiff.h15
-rw-r--r--libavcodec/tiffenc.c59
-rw-r--r--libavcodec/timecode.c83
-rw-r--r--libavcodec/timecode.h75
-rw-r--r--libavcodec/tmv.c21
-rw-r--r--libavcodec/truemotion1.c26
-rw-r--r--libavcodec/truemotion1data.h8
-rw-r--r--libavcodec/truemotion2.c28
-rw-r--r--libavcodec/truespeech.c226
-rw-r--r--libavcodec/truespeech_data.h8
-rw-r--r--libavcodec/tscc.c28
-rw-r--r--libavcodec/tta.c94
-rw-r--r--libavcodec/twinvq.c28
-rw-r--r--libavcodec/twinvq_data.h8
-rw-r--r--libavcodec/txd.c48
-rw-r--r--libavcodec/ulti.c27
-rw-r--r--libavcodec/ulti_cb.h8
-rw-r--r--libavcodec/unary.h8
-rw-r--r--libavcodec/utils.c320
-rw-r--r--libavcodec/utvideo.c460
-rw-r--r--libavcodec/v210dec.c124
-rw-r--r--libavcodec/v210dec.h (renamed from ffserver.h)21
-rw-r--r--libavcodec/v210enc.c43
-rw-r--r--libavcodec/v210x.c24
-rw-r--r--libavcodec/vaapi.c8
-rw-r--r--libavcodec/vaapi.h12
-rw-r--r--libavcodec/vaapi_h264.c38
-rw-r--r--libavcodec/vaapi_internal.h10
-rw-r--r--libavcodec/vaapi_mpeg2.c14
-rw-r--r--libavcodec/vaapi_mpeg4.c12
-rw-r--r--libavcodec/vaapi_vc1.c26
-rw-r--r--libavcodec/vb.c24
-rw-r--r--libavcodec/vc1.c988
-rw-r--r--libavcodec/vc1.h156
-rw-r--r--libavcodec/vc1_parser.c23
-rw-r--r--libavcodec/vc1acdata.h8
-rw-r--r--libavcodec/vc1data.c1042
-rw-r--r--libavcodec/vc1data.h72
-rw-r--r--libavcodec/vc1dec.c4797
-rw-r--r--libavcodec/vc1dsp.c97
-rw-r--r--libavcodec/vc1dsp.h18
-rw-r--r--libavcodec/vcr1.c41
-rw-r--r--libavcodec/vdpau.c84
-rw-r--r--libavcodec/vdpau.h28
-rw-r--r--libavcodec/vdpau_internal.h8
-rw-r--r--libavcodec/version.h43
-rw-r--r--libavcodec/vmdav.c253
-rw-r--r--libavcodec/vmnc.c26
-rw-r--r--libavcodec/vorbis.c14
-rw-r--r--libavcodec/vorbis.h8
-rw-r--r--libavcodec/vorbis_data.c8
-rw-r--r--libavcodec/vorbis_enc_data.h8
-rw-r--r--libavcodec/vorbisdec.c45
-rw-r--r--libavcodec/vorbisenc.c24
-rw-r--r--libavcodec/vp3.c79
-rw-r--r--libavcodec/vp3_parser.c8
-rw-r--r--libavcodec/vp3data.h8
-rw-r--r--libavcodec/vp3dsp.c8
-rw-r--r--libavcodec/vp5.c38
-rw-r--r--libavcodec/vp56.c41
-rw-r--r--libavcodec/vp56.h20
-rw-r--r--libavcodec/vp56data.c18
-rw-r--r--libavcodec/vp56data.h18
-rw-r--r--libavcodec/vp56dsp.c8
-rw-r--r--libavcodec/vp56dsp.h8
-rw-r--r--libavcodec/vp56rac.c8
-rw-r--r--libavcodec/vp5data.h18
-rw-r--r--libavcodec/vp6.c112
-rw-r--r--libavcodec/vp6data.h18
-rw-r--r--libavcodec/vp6dsp.c18
-rw-r--r--libavcodec/vp8.c127
-rw-r--r--libavcodec/vp8.h19
-rw-r--r--libavcodec/vp8_parser.c8
-rw-r--r--libavcodec/vp8data.h17
-rw-r--r--libavcodec/vp8dsp.c17
-rw-r--r--libavcodec/vp8dsp.h16
-rw-r--r--libavcodec/vqavideo.c42
-rw-r--r--libavcodec/w32pthreads.h207
-rw-r--r--libavcodec/w32thread.c174
-rw-r--r--libavcodec/wavpack.c108
-rw-r--r--libavcodec/wma.c10
-rw-r--r--libavcodec/wma.h10
-rw-r--r--libavcodec/wmadata.h10
-rw-r--r--libavcodec/wmadec.c74
-rw-r--r--libavcodec/wmaenc.c54
-rw-r--r--libavcodec/wmaprodata.h8
-rw-r--r--libavcodec/wmaprodec.c53
-rw-r--r--libavcodec/wmavoice.c43
-rw-r--r--libavcodec/wmavoice_data.h8
-rw-r--r--libavcodec/wmv2.c10
-rw-r--r--libavcodec/wmv2.h10
-rw-r--r--libavcodec/wmv2dec.c40
-rw-r--r--libavcodec/wmv2enc.c24
-rw-r--r--libavcodec/wnv1.c26
-rw-r--r--libavcodec/ws-snd1.c147
-rw-r--r--libavcodec/x86/Makefile9
-rw-r--r--libavcodec/x86/ac3dsp.asm12
-rw-r--r--libavcodec/x86/ac3dsp_mmx.c10
-rw-r--r--libavcodec/x86/cabac.h15
-rw-r--r--libavcodec/x86/cavsdsp_mmx.c8
-rw-r--r--libavcodec/x86/dct32_sse.asm51
-rw-r--r--libavcodec/x86/deinterlace.asm12
-rw-r--r--libavcodec/x86/dnxhd_mmx.c11
-rw-r--r--libavcodec/x86/dsputil_mmx.c194
-rw-r--r--libavcodec/x86/dsputil_mmx.h8
-rw-r--r--libavcodec/x86/dsputil_mmx_avg_template.c8
-rw-r--r--libavcodec/x86/dsputil_mmx_qns_template.c8
-rw-r--r--libavcodec/x86/dsputil_mmx_rnd_template.c8
-rw-r--r--libavcodec/x86/dsputil_yasm.asm52
-rw-r--r--libavcodec/x86/dsputilenc_mmx.c18
-rw-r--r--libavcodec/x86/dsputilenc_yasm.asm12
-rw-r--r--libavcodec/x86/fdct_mmx.c8
-rw-r--r--libavcodec/x86/fft.c10
-rw-r--r--libavcodec/x86/fft.h9
-rw-r--r--libavcodec/x86/fft_3dn.c8
-rw-r--r--libavcodec/x86/fft_3dn2.c12
-rw-r--r--libavcodec/x86/fft_mmx.asm11
-rw-r--r--libavcodec/x86/fft_sse.c12
-rw-r--r--libavcodec/x86/fmtconvert.asm152
-rw-r--r--libavcodec/x86/fmtconvert_mmx.c221
-rw-r--r--libavcodec/x86/h264_chromamc.asm56
-rw-r--r--libavcodec/x86/h264_deblock.asm37
-rw-r--r--libavcodec/x86/h264_deblock_10bit.asm24
-rw-r--r--libavcodec/x86/h264_i386.h51
-rw-r--r--libavcodec/x86/h264_idct.asm40
-rw-r--r--libavcodec/x86/h264_idct_10bit.asm4
-rw-r--r--libavcodec/x86/h264_intrapred.asm17
-rw-r--r--libavcodec/x86/h264_intrapred_10bit.asm953
-rw-r--r--libavcodec/x86/h264_intrapred_init.c143
-rw-r--r--libavcodec/x86/h264_qpel_mmx.c16
-rw-r--r--libavcodec/x86/h264_weight.asm220
-rw-r--r--libavcodec/x86/h264_weight_10bit.asm145
-rw-r--r--libavcodec/x86/h264dsp_mmx.c215
-rw-r--r--libavcodec/x86/idct_mmx_xvid.c8
-rw-r--r--libavcodec/x86/idct_sse2_xvid.c8
-rw-r--r--libavcodec/x86/idct_xvid.h8
-rw-r--r--libavcodec/x86/lpc_mmx.c8
-rw-r--r--libavcodec/x86/mathops.h8
-rw-r--r--libavcodec/x86/mlpdsp.c8
-rw-r--r--libavcodec/x86/motion_est_mmx.c8
-rw-r--r--libavcodec/x86/mpegaudiodec_mmx.c8
-rw-r--r--libavcodec/x86/mpegvideo_mmx.c8
-rw-r--r--libavcodec/x86/mpegvideo_mmx_template.c21
-rw-r--r--libavcodec/x86/png_mmx.c143
-rw-r--r--libavcodec/x86/proresdsp-init.c57
-rw-r--r--libavcodec/x86/proresdsp.asm312
-rw-r--r--libavcodec/x86/rv40dsp.c60
-rw-r--r--libavcodec/x86/simple_idct_mmx.c141
-rw-r--r--libavcodec/x86/snowdsp_mmx.c12
-rw-r--r--libavcodec/x86/v210-init.c48
-rw-r--r--libavcodec/x86/v210.asm85
-rw-r--r--libavcodec/x86/vc1dsp_yasm.asm12
-rw-r--r--libavcodec/x86/vp3dsp.asm12
-rw-r--r--libavcodec/x86/vp56_arith.h8
-rw-r--r--libavcodec/x86/vp56dsp.asm12
-rw-r--r--libavcodec/x86/vp56dsp_init.c8
-rw-r--r--libavcodec/x86/vp8dsp-init.c10
-rw-r--r--libavcodec/x86/vp8dsp.asm12
-rw-r--r--libavcodec/xan.c130
-rw-r--r--libavcodec/xiph.c12
-rw-r--r--libavcodec/xiph.h16
-rw-r--r--libavcodec/xl.c28
-rw-r--r--libavcodec/xsubdec.c39
-rw-r--r--libavcodec/xsubenc.c26
-rw-r--r--libavcodec/xvmc.h8
-rw-r--r--libavcodec/xvmc_internal.h8
-rw-r--r--libavcodec/xxan.c38
-rw-r--r--libavcodec/yop.c27
-rw-r--r--libavcodec/zmbv.c28
-rw-r--r--libavcodec/zmbvenc.c22
-rw-r--r--libavdevice/Makefile17
-rw-r--r--libavdevice/alldevices.c15
-rw-r--r--libavdevice/alsa-audio-common.c16
-rw-r--r--libavdevice/alsa-audio-dec.c92
-rw-r--r--libavdevice/alsa-audio-enc.c43
-rw-r--r--libavdevice/alsa-audio.h20
-rw-r--r--libavdevice/avdevice.c12
-rw-r--r--libavdevice/avdevice.h11
-rw-r--r--libavdevice/bktr.c66
-rw-r--r--libavdevice/dshow.c960
-rw-r--r--libavdevice/dshow.h268
-rw-r--r--libavdevice/dshow_common.c190
-rw-r--r--libavdevice/dshow_enummediatypes.c103
-rw-r--r--libavdevice/dshow_enumpins.c105
-rw-r--r--libavdevice/dshow_filter.c202
-rw-r--r--libavdevice/dshow_pin.c362
-rw-r--r--libavdevice/dv1394.c38
-rw-r--r--libavdevice/dv1394.h8
-rw-r--r--libavdevice/fbdev.c53
-rw-r--r--libavdevice/jack_audio.c52
-rw-r--r--libavdevice/lavfi.c344
-rw-r--r--libavdevice/libcdio.c187
-rw-r--r--libavdevice/libdc1394.c452
-rw-r--r--libavdevice/openal-dec.c250
-rw-r--r--libavdevice/oss_audio.c67
-rw-r--r--libavdevice/pulse.c191
-rw-r--r--libavdevice/sdl.c230
-rw-r--r--libavdevice/sndio_common.c10
-rw-r--r--libavdevice/sndio_common.h10
-rw-r--r--libavdevice/sndio_dec.c21
-rw-r--r--libavdevice/sndio_enc.c11
-rw-r--r--libavdevice/timefilter.c (renamed from libavformat/timefilter.c)10
-rw-r--r--libavdevice/timefilter.h (renamed from libavformat/timefilter.h)14
-rw-r--r--libavdevice/v4l.c47
-rw-r--r--libavdevice/v4l2.c138
-rw-r--r--libavdevice/vfwcap.c83
-rw-r--r--libavdevice/x11grab.c230
-rw-r--r--libavfilter/Makefile101
-rw-r--r--libavfilter/af_aconvert.c418
-rw-r--r--libavfilter/af_aconvert_rematrix.c172
-rw-r--r--libavfilter/af_aformat.c108
-rw-r--r--libavfilter/af_anull.c8
-rw-r--r--libavfilter/af_aresample.c348
-rw-r--r--libavfilter/af_ashowinfo.c103
-rw-r--r--libavfilter/all_channel_layouts.h68
-rw-r--r--libavfilter/allfilters.c31
-rw-r--r--libavfilter/asink_anullsink.c8
-rw-r--r--libavfilter/asrc_abuffer.c372
-rw-r--r--libavfilter/asrc_abuffer.h80
-rw-r--r--libavfilter/asrc_aevalsrc.c226
-rw-r--r--libavfilter/asrc_anullsrc.c108
-rw-r--r--libavfilter/avcodec.c73
-rw-r--r--libavfilter/avcodec.h71
-rw-r--r--libavfilter/avfilter.c260
-rw-r--r--libavfilter/avfilter.h192
-rw-r--r--libavfilter/avfiltergraph.c192
-rw-r--r--libavfilter/avfiltergraph.h70
-rw-r--r--libavfilter/buffersink.h88
-rw-r--r--libavfilter/defaults.c231
-rw-r--r--libavfilter/drawutils.c8
-rw-r--r--libavfilter/drawutils.h8
-rw-r--r--libavfilter/formats.c207
-rw-r--r--libavfilter/gradfun.h22
-rw-r--r--libavfilter/graphparser.c95
-rw-r--r--libavfilter/internal.h77
-rw-r--r--libavfilter/libmpcodecs/cpudetect.h59
-rw-r--r--libavfilter/libmpcodecs/help_mp.h2136
-rw-r--r--libavfilter/libmpcodecs/img_format.c170
-rw-r--r--libavfilter/libmpcodecs/img_format.h214
-rw-r--r--libavfilter/libmpcodecs/libvo/fastmemcpy.h99
-rw-r--r--libavfilter/libmpcodecs/libvo/video_out.h287
-rw-r--r--libavfilter/libmpcodecs/mp_image.c200
-rw-r--r--libavfilter/libmpcodecs/mp_image.h150
-rw-r--r--libavfilter/libmpcodecs/mp_msg.h164
-rw-r--r--libavfilter/libmpcodecs/mpbswap.h34
-rw-r--r--libavfilter/libmpcodecs/mpc_info.h43
-rw-r--r--libavfilter/libmpcodecs/pullup.c822
-rw-r--r--libavfilter/libmpcodecs/pullup.h102
-rw-r--r--libavfilter/libmpcodecs/vd_ffmpeg.h24
-rw-r--r--libavfilter/libmpcodecs/vf.h169
-rw-r--r--libavfilter/libmpcodecs/vf_2xsai.c336
-rw-r--r--libavfilter/libmpcodecs/vf_decimate.c198
-rw-r--r--libavfilter/libmpcodecs/vf_denoise3d.c268
-rw-r--r--libavfilter/libmpcodecs/vf_detc.c453
-rw-r--r--libavfilter/libmpcodecs/vf_dint.c214
-rw-r--r--libavfilter/libmpcodecs/vf_divtc.c721
-rw-r--r--libavfilter/libmpcodecs/vf_down3dright.c166
-rw-r--r--libavfilter/libmpcodecs/vf_dsize.c123
-rw-r--r--libavfilter/libmpcodecs/vf_eq.c240
-rw-r--r--libavfilter/libmpcodecs/vf_eq2.c519
-rw-r--r--libavfilter/libmpcodecs/vf_field.c89
-rw-r--r--libavfilter/libmpcodecs/vf_fil.c116
-rw-r--r--libavfilter/libmpcodecs/vf_filmdint.c1461
-rw-r--r--libavfilter/libmpcodecs/vf_fixpts.c137
-rw-r--r--libavfilter/libmpcodecs/vf_framestep.c205
-rw-r--r--libavfilter/libmpcodecs/vf_fspp.c2117
-rw-r--r--libavfilter/libmpcodecs/vf_geq.c196
-rw-r--r--libavfilter/libmpcodecs/vf_harddup.c92
-rw-r--r--libavfilter/libmpcodecs/vf_hqdn3d.c373
-rw-r--r--libavfilter/libmpcodecs/vf_hue.c181
-rw-r--r--libavfilter/libmpcodecs/vf_il.c148
-rw-r--r--libavfilter/libmpcodecs/vf_ilpack.c456
-rw-r--r--libavfilter/libmpcodecs/vf_ivtc.c550
-rw-r--r--libavfilter/libmpcodecs/vf_kerndeint.c345
-rw-r--r--libavfilter/libmpcodecs/vf_mcdeint.c337
-rw-r--r--libavfilter/libmpcodecs/vf_mirror.c131
-rw-r--r--libavfilter/libmpcodecs/vf_noise.c474
-rw-r--r--libavfilter/libmpcodecs/vf_ow.c322
-rw-r--r--libavfilter/libmpcodecs/vf_palette.c236
-rw-r--r--libavfilter/libmpcodecs/vf_perspective.c345
-rw-r--r--libavfilter/libmpcodecs/vf_phase.c301
-rw-r--r--libavfilter/libmpcodecs/vf_pp7.c493
-rw-r--r--libavfilter/libmpcodecs/vf_pullup.c314
-rw-r--r--libavfilter/libmpcodecs/vf_qp.c177
-rw-r--r--libavfilter/libmpcodecs/vf_rectangle.c181
-rw-r--r--libavfilter/libmpcodecs/vf_remove_logo.c906
-rw-r--r--libavfilter/libmpcodecs/vf_rotate.c152
-rw-r--r--libavfilter/libmpcodecs/vf_sab.c323
-rw-r--r--libavfilter/libmpcodecs/vf_scale.h34
-rw-r--r--libavfilter/libmpcodecs/vf_screenshot.c322
-rw-r--r--libavfilter/libmpcodecs/vf_smartblur.c264
-rw-r--r--libavfilter/libmpcodecs/vf_softpulldown.c164
-rw-r--r--libavfilter/libmpcodecs/vf_softskip.c102
-rw-r--r--libavfilter/libmpcodecs/vf_spp.c620
-rw-r--r--libavfilter/libmpcodecs/vf_stereo3d.c512
-rw-r--r--libavfilter/libmpcodecs/vf_swapuv.c106
-rw-r--r--libavfilter/libmpcodecs/vf_telecine.c155
-rw-r--r--libavfilter/libmpcodecs/vf_tile.c330
-rw-r--r--libavfilter/libmpcodecs/vf_tinterlace.c235
-rw-r--r--libavfilter/libmpcodecs/vf_unsharp.c324
-rw-r--r--libavfilter/libmpcodecs/vf_uspp.c385
-rw-r--r--libavfilter/libmpcodecs/vf_yuvcsp.c120
-rw-r--r--libavfilter/libmpcodecs/vf_yvu9.c105
-rw-r--r--libavfilter/libmpcodecs/vfcap.h56
-rw-r--r--libavfilter/sink_buffer.c263
-rw-r--r--libavfilter/src_movie.c (renamed from libavfilter/vsrc_movie.c)301
-rw-r--r--libavfilter/transform.c182
-rw-r--r--libavfilter/transform.h124
-rw-r--r--libavfilter/vf_aspect.c10
-rw-r--r--libavfilter/vf_blackframe.c21
-rw-r--r--libavfilter/vf_boxblur.c345
-rw-r--r--libavfilter/vf_copy.c8
-rw-r--r--libavfilter/vf_crop.c34
-rw-r--r--libavfilter/vf_cropdetect.c10
-rw-r--r--libavfilter/vf_delogo.c288
-rw-r--r--libavfilter/vf_deshake.c560
-rw-r--r--libavfilter/vf_drawbox.c12
-rw-r--r--libavfilter/vf_drawtext.c314
-rw-r--r--libavfilter/vf_fade.c10
-rw-r--r--libavfilter/vf_fieldorder.c8
-rw-r--r--libavfilter/vf_fifo.c8
-rw-r--r--libavfilter/vf_format.c22
-rw-r--r--libavfilter/vf_frei0r.c15
-rw-r--r--libavfilter/vf_gradfun.c16
-rw-r--r--libavfilter/vf_hflip.c10
-rw-r--r--libavfilter/vf_hqdn3d.c10
-rw-r--r--libavfilter/vf_libopencv.c12
-rw-r--r--libavfilter/vf_lut.c383
-rw-r--r--libavfilter/vf_mp.c900
-rw-r--r--libavfilter/vf_null.c8
-rw-r--r--libavfilter/vf_overlay.c18
-rw-r--r--libavfilter/vf_pad.c30
-rw-r--r--libavfilter/vf_pixdesctest.c10
-rw-r--r--libavfilter/vf_scale.c103
-rw-r--r--libavfilter/vf_select.c340
-rw-r--r--libavfilter/vf_setpts.c17
-rw-r--r--libavfilter/vf_settb.c17
-rw-r--r--libavfilter/vf_showinfo.c98
-rw-r--r--libavfilter/vf_slicify.c8
-rw-r--r--libavfilter/vf_split.c66
-rw-r--r--libavfilter/vf_transpose.c21
-rw-r--r--libavfilter/vf_unsharp.c48
-rw-r--r--libavfilter/vf_vflip.c8
-rw-r--r--libavfilter/vf_yadif.c52
-rw-r--r--libavfilter/vsink_nullsink.c8
-rw-r--r--libavfilter/vsrc_buffer.c179
-rw-r--r--libavfilter/vsrc_buffer.h29
-rw-r--r--libavfilter/vsrc_color.c22
-rw-r--r--libavfilter/vsrc_mptestsrc.c392
-rw-r--r--libavfilter/vsrc_nullsrc.c17
-rw-r--r--libavfilter/vsrc_testsrc.c498
-rw-r--r--libavfilter/x86/gradfun.c14
-rw-r--r--libavfilter/x86/yadif.c8
-rw-r--r--libavfilter/x86/yadif_template.c40
-rw-r--r--libavfilter/yadif.h8
-rw-r--r--libavformat/4xm.c40
-rw-r--r--libavformat/Makefile38
-rw-r--r--libavformat/a64.c14
-rw-r--r--libavformat/aacdec.c22
-rw-r--r--libavformat/ac3dec.c32
-rw-r--r--libavformat/act.c207
-rw-r--r--libavformat/adts.h8
-rw-r--r--libavformat/adtsenc.c34
-rw-r--r--libavformat/aea.c24
-rw-r--r--libavformat/aiff.h8
-rw-r--r--libavformat/aiffdec.c59
-rw-r--r--libavformat/aiffenc.c35
-rw-r--r--libavformat/allformats.c29
-rw-r--r--libavformat/amr.c42
-rw-r--r--libavformat/anm.c47
-rw-r--r--libavformat/apc.c21
-rw-r--r--libavformat/ape.c41
-rw-r--r--libavformat/apetag.c8
-rw-r--r--libavformat/apetag.h8
-rw-r--r--libavformat/applehttp.c37
-rw-r--r--libavformat/applehttpproto.c10
-rw-r--r--libavformat/asf.c8
-rw-r--r--libavformat/asf.h18
-rw-r--r--libavformat/asfcrypt.c8
-rw-r--r--libavformat/asfcrypt.h8
-rw-r--r--libavformat/asfdec.c91
-rw-r--r--libavformat/asfenc.c68
-rw-r--r--libavformat/assdec.c12
-rw-r--r--libavformat/assenc.c8
-rw-r--r--libavformat/au.c56
-rw-r--r--libavformat/audiointerleave.c8
-rw-r--r--libavformat/audiointerleave.h8
-rw-r--r--libavformat/avc.c8
-rw-r--r--libavformat/avc.h8
-rw-r--r--libavformat/avformat.h262
-rw-r--r--libavformat/avi.c8
-rw-r--r--libavformat/avi.h8
-rw-r--r--libavformat/avidec.c212
-rw-r--r--libavformat/avienc.c43
-rw-r--r--libavformat/avio.c24
-rw-r--r--libavformat/avio.h33
-rw-r--r--libavformat/avio_internal.h8
-rw-r--r--libavformat/aviobuf.c56
-rw-r--r--libavformat/avisynth.c42
-rw-r--r--libavformat/avlanguage.c11
-rw-r--r--libavformat/avlanguage.h8
-rw-r--r--libavformat/avs.c30
-rw-r--r--libavformat/bethsoftvid.c30
-rw-r--r--libavformat/bfi.c30
-rw-r--r--libavformat/bink.c38
-rw-r--r--libavformat/bintext.c375
-rw-r--r--libavformat/bit.c135
-rw-r--r--libavformat/c93.c24
-rw-r--r--libavformat/cache.c144
-rw-r--r--libavformat/caf.c55
-rw-r--r--libavformat/caf.h8
-rw-r--r--libavformat/cafdec.c57
-rw-r--r--libavformat/cafenc.c262
-rw-r--r--libavformat/cavsvideodec.c8
-rw-r--r--libavformat/cdg.c26
-rw-r--r--libavformat/concat.c8
-rw-r--r--libavformat/crcenc.c27
-rw-r--r--libavformat/crypto.c4
-rw-r--r--libavformat/cutils.c29
-rw-r--r--libavformat/daud.c45
-rw-r--r--libavformat/dfa.c21
-rw-r--r--libavformat/diracdec.c8
-rw-r--r--libavformat/dnxhddec.c8
-rw-r--r--libavformat/dsicin.c26
-rw-r--r--libavformat/dtsdec.c19
-rw-r--r--libavformat/dv.c60
-rw-r--r--libavformat/dv.h14
-rw-r--r--libavformat/dvenc.c94
-rw-r--r--libavformat/dxa.c28
-rw-r--r--libavformat/eacdata.c32
-rw-r--r--libavformat/electronicarts.c36
-rw-r--r--libavformat/ffm.h8
-rw-r--r--libavformat/ffmdec.c62
-rw-r--r--libavformat/ffmenc.c30
-rw-r--r--libavformat/ffmeta.h8
-rw-r--r--libavformat/ffmetadec.c16
-rw-r--r--libavformat/ffmetaenc.c8
-rw-r--r--libavformat/file.c14
-rw-r--r--libavformat/filmstripdec.c29
-rw-r--r--libavformat/filmstripenc.c27
-rw-r--r--libavformat/flacdec.c27
-rw-r--r--libavformat/flacenc.c29
-rw-r--r--libavformat/flacenc.h8
-rw-r--r--libavformat/flacenc_header.c10
-rw-r--r--libavformat/flic.c26
-rw-r--r--libavformat/flv.h31
-rw-r--r--libavformat/flvdec.c219
-rw-r--r--libavformat/flvenc.c142
-rw-r--r--libavformat/framecrcenc.c24
-rw-r--r--libavformat/g723_1.c83
-rw-r--r--libavformat/gif.c57
-rw-r--r--libavformat/gopher.c8
-rw-r--r--libavformat/gxf.c61
-rw-r--r--libavformat/gxf.h8
-rw-r--r--libavformat/gxfenc.c58
-rw-r--r--libavformat/h261dec.c8
-rw-r--r--libavformat/h263dec.c8
-rw-r--r--libavformat/h264dec.c10
-rw-r--r--libavformat/http.c12
-rw-r--r--libavformat/http.h8
-rw-r--r--libavformat/httpauth.c8
-rw-r--r--libavformat/httpauth.h8
-rw-r--r--libavformat/id3v1.c8
-rw-r--r--libavformat/id3v1.h8
-rw-r--r--libavformat/id3v2.c447
-rw-r--r--libavformat/id3v2.h38
-rw-r--r--libavformat/idcin.c26
-rw-r--r--libavformat/idroqdec.c26
-rw-r--r--libavformat/idroqenc.c27
-rw-r--r--libavformat/iff.c177
-rw-r--r--libavformat/img2.c71
-rw-r--r--libavformat/ingenientdec.c23
-rw-r--r--libavformat/internal.h23
-rw-r--r--libavformat/ipmovie.c30
-rw-r--r--libavformat/isom.c137
-rw-r--r--libavformat/isom.h11
-rw-r--r--libavformat/iss.c25
-rw-r--r--libavformat/iv8.c21
-rw-r--r--libavformat/ivfdec.c21
-rw-r--r--libavformat/ivfenc.c8
-rw-r--r--libavformat/jvdec.c17
-rw-r--r--libavformat/latmenc.c198
-rw-r--r--libavformat/libavformat.v30
-rw-r--r--libavformat/libmodplug.c367
-rw-r--r--libavformat/libnut.c46
-rw-r--r--libavformat/librtmp.c9
-rw-r--r--libavformat/lmlm4.c23
-rw-r--r--libavformat/loasdec.c88
-rw-r--r--libavformat/lxfdec.c14
-rw-r--r--libavformat/m4vdec.c10
-rw-r--r--libavformat/matroska.c32
-rw-r--r--libavformat/matroska.h22
-rw-r--r--libavformat/matroskadec.c338
-rw-r--r--libavformat/matroskaenc.c228
-rw-r--r--libavformat/md5enc.c44
-rw-r--r--libavformat/md5proto.c8
-rw-r--r--libavformat/metadata.c8
-rw-r--r--libavformat/metadata.h8
-rw-r--r--libavformat/microdvddec.c129
-rw-r--r--libavformat/microdvdenc.c51
-rw-r--r--libavformat/mm.c24
-rw-r--r--libavformat/mmf.c47
-rw-r--r--libavformat/mms.c8
-rw-r--r--libavformat/mms.h8
-rw-r--r--libavformat/mmsh.c12
-rw-r--r--libavformat/mmst.c10
-rw-r--r--libavformat/mov.c332
-rw-r--r--libavformat/movenc.c216
-rw-r--r--libavformat/movenc.h8
-rw-r--r--libavformat/movenchint.c10
-rw-r--r--libavformat/mp3dec.c31
-rw-r--r--libavformat/mp3enc.c286
-rw-r--r--libavformat/mpc.c42
-rw-r--r--libavformat/mpc8.c34
-rw-r--r--libavformat/mpeg.c58
-rw-r--r--libavformat/mpeg.h8
-rw-r--r--libavformat/mpegenc.c142
-rw-r--r--libavformat/mpegts.c340
-rw-r--r--libavformat/mpegts.h8
-rw-r--r--libavformat/mpegtsenc.c169
-rw-r--r--libavformat/mpegvideodec.c8
-rw-r--r--libavformat/mpjpeg.c27
-rw-r--r--libavformat/msnwc_tcp.c25
-rw-r--r--libavformat/mtv.c30
-rw-r--r--libavformat/mvi.c23
-rw-r--r--libavformat/mxf.c13
-rw-r--r--libavformat/mxf.h8
-rw-r--r--libavformat/mxfdec.c190
-rw-r--r--libavformat/mxfenc.c155
-rw-r--r--libavformat/mxg.c20
-rw-r--r--libavformat/ncdec.c23
-rw-r--r--libavformat/network.h10
-rw-r--r--libavformat/nsvdec.c74
-rw-r--r--libavformat/nullenc.c22
-rw-r--r--libavformat/nut.c8
-rw-r--r--libavformat/nut.h8
-rw-r--r--libavformat/nutdec.c32
-rw-r--r--libavformat/nutenc.c49
-rw-r--r--libavformat/nuv.c111
-rw-r--r--libavformat/oggdec.c57
-rw-r--r--libavformat/oggdec.h2
-rw-r--r--libavformat/oggenc.c63
-rw-r--r--libavformat/oggparsecelt.c95
-rw-r--r--libavformat/oggparsedirac.c10
-rw-r--r--libavformat/oggparseflac.c10
-rw-r--r--libavformat/oggparseskeleton.c8
-rw-r--r--libavformat/oggparsespeex.c20
-rw-r--r--libavformat/oggparsevorbis.c2
-rw-r--r--libavformat/oma.c291
-rw-r--r--libavformat/options.c109
-rw-r--r--libavformat/os_support.c8
-rw-r--r--libavformat/os_support.h8
-rw-r--r--libavformat/pcm.c8
-rw-r--r--libavformat/pcm.h8
-rw-r--r--libavformat/pcmdec.c48
-rw-r--r--libavformat/pcmenc.c29
-rw-r--r--libavformat/pmpdec.c172
-rw-r--r--libavformat/psxstr.c82
-rw-r--r--libavformat/pva.c41
-rw-r--r--libavformat/qcp.c17
-rw-r--r--libavformat/qtpalette.h8
-rw-r--r--libavformat/r3d.c31
-rw-r--r--libavformat/rawdec.c137
-rw-r--r--libavformat/rawdec.h23
-rw-r--r--libavformat/rawenc.c284
-rw-r--r--libavformat/rawenc.h8
-rw-r--r--libavformat/rawvideodec.c37
-rw-r--r--libavformat/rdt.c11
-rw-r--r--libavformat/rdt.h22
-rw-r--r--libavformat/riff.c83
-rw-r--r--libavformat/riff.h34
-rw-r--r--libavformat/rl2.c30
-rw-r--r--libavformat/rm.c8
-rw-r--r--libavformat/rm.h8
-rw-r--r--libavformat/rmdec.c173
-rw-r--r--libavformat/rmenc.c28
-rw-r--r--libavformat/rpl.c24
-rw-r--r--libavformat/rso.c8
-rw-r--r--libavformat/rso.h8
-rw-r--r--libavformat/rsodec.c10
-rw-r--r--libavformat/rsoenc.c8
-rw-r--r--libavformat/rtmp.h8
-rw-r--r--libavformat/rtmppkt.c8
-rw-r--r--libavformat/rtmppkt.h8
-rw-r--r--libavformat/rtmpproto.c57
-rw-r--r--libavformat/rtp.c34
-rw-r--r--libavformat/rtp.h18
-rw-r--r--libavformat/rtpdec.c54
-rw-r--r--libavformat/rtpdec.h32
-rw-r--r--libavformat/rtpdec_amr.c8
-rw-r--r--libavformat/rtpdec_asf.c16
-rw-r--r--libavformat/rtpdec_formats.h8
-rw-r--r--libavformat/rtpdec_h263.c8
-rw-r--r--libavformat/rtpdec_h264.c8
-rw-r--r--libavformat/rtpdec_latm.c8
-rw-r--r--libavformat/rtpdec_mpeg4.c8
-rw-r--r--libavformat/rtpdec_qcelp.c8
-rw-r--r--libavformat/rtpdec_qdm2.c8
-rw-r--r--libavformat/rtpdec_qt.c8
-rw-r--r--libavformat/rtpdec_svq3.c10
-rw-r--r--libavformat/rtpdec_vp8.c10
-rw-r--r--libavformat/rtpdec_xiph.c8
-rw-r--r--libavformat/rtpenc.c33
-rw-r--r--libavformat/rtpenc.h12
-rw-r--r--libavformat/rtpenc_aac.c8
-rw-r--r--libavformat/rtpenc_amr.c8
-rw-r--r--libavformat/rtpenc_chain.c24
-rw-r--r--libavformat/rtpenc_chain.h8
-rw-r--r--libavformat/rtpenc_h263.c8
-rw-r--r--libavformat/rtpenc_h264.c40
-rw-r--r--libavformat/rtpenc_latm.c4
-rw-r--r--libavformat/rtpenc_mpv.c10
-rw-r--r--libavformat/rtpenc_vp8.c8
-rw-r--r--libavformat/rtpenc_xiph.c8
-rw-r--r--libavformat/rtpproto.c40
-rw-r--r--libavformat/rtsp.c153
-rw-r--r--libavformat/rtsp.h39
-rw-r--r--libavformat/rtspcodes.h8
-rw-r--r--libavformat/rtspdec.c45
-rw-r--r--libavformat/rtspenc.c35
-rw-r--r--libavformat/sapdec.c28
-rw-r--r--libavformat/sapenc.c26
-rw-r--r--libavformat/sauce.c8
-rw-r--r--libavformat/sauce.h8
-rw-r--r--libavformat/sdp.c17
-rw-r--r--libavformat/seek-test.c (renamed from tests/seek_test.c)10
-rw-r--r--libavformat/seek.c8
-rw-r--r--libavformat/seek.h8
-rw-r--r--libavformat/segafilm.c71
-rw-r--r--libavformat/segment.c234
-rw-r--r--libavformat/sierravmd.c26
-rw-r--r--libavformat/siff.c24
-rw-r--r--libavformat/smacker.c70
-rw-r--r--libavformat/sol.c28
-rw-r--r--libavformat/sox.h8
-rw-r--r--libavformat/soxdec.c30
-rw-r--r--libavformat/soxenc.c31
-rw-r--r--libavformat/spdif.c8
-rw-r--r--libavformat/spdif.h8
-rw-r--r--libavformat/spdifdec.c25
-rw-r--r--libavformat/spdifenc.c49
-rw-r--r--libavformat/srtdec.c12
-rw-r--r--libavformat/swf.h8
-rw-r--r--libavformat/swfdec.c40
-rw-r--r--libavformat/swfenc.c49
-rw-r--r--libavformat/tcp.c10
-rw-r--r--libavformat/thp.c24
-rw-r--r--libavformat/tiertexseq.c26
-rw-r--r--libavformat/tmv.c36
-rw-r--r--libavformat/tta.c28
-rw-r--r--libavformat/tty.c30
-rw-r--r--libavformat/txd.c26
-rw-r--r--libavformat/udp.c141
-rw-r--r--libavformat/url.h14
-rw-r--r--libavformat/utils.c754
-rw-r--r--libavformat/vc1test.c23
-rw-r--r--libavformat/vc1testenc.c28
-rw-r--r--libavformat/version.h37
-rw-r--r--libavformat/voc.c8
-rw-r--r--libavformat/voc.h8
-rw-r--r--libavformat/vocdec.c24
-rw-r--r--libavformat/vocenc.c28
-rw-r--r--libavformat/vorbiscomment.c8
-rw-r--r--libavformat/vorbiscomment.h8
-rw-r--r--libavformat/vqf.c25
-rw-r--r--libavformat/wav.c452
-rw-r--r--libavformat/wc3movie.c30
-rw-r--r--libavformat/westwood.c42
-rw-r--r--libavformat/wtv.c1114
-rw-r--r--libavformat/wtv.h55
-rw-r--r--libavformat/wtvdec.c1038
-rw-r--r--libavformat/wtvenc.c722
-rw-r--r--libavformat/wv.c34
-rw-r--r--libavformat/xa.c22
-rw-r--r--libavformat/xmv.c557
-rw-r--r--libavformat/xwma.c22
-rw-r--r--libavformat/yop.c39
-rw-r--r--libavformat/yuv4mpeg.c46
-rw-r--r--libavutil/Makefile6
-rw-r--r--libavutil/adler32.h8
-rw-r--r--libavutil/aes.c8
-rw-r--r--libavutil/aes.h8
-rw-r--r--libavutil/arm/bswap.h8
-rw-r--r--libavutil/arm/cpu.c8
-rw-r--r--libavutil/arm/intmath.h10
-rw-r--r--libavutil/arm/intreadwrite.h8
-rw-r--r--libavutil/arm/timer.h8
-rw-r--r--libavutil/attributes.h28
-rw-r--r--libavutil/audioconvert.c56
-rw-r--r--libavutil/audioconvert.h13
-rw-r--r--libavutil/avassert.h8
-rw-r--r--libavutil/avr32/bswap.h8
-rw-r--r--libavutil/avr32/intreadwrite.h8
-rw-r--r--libavutil/avstring.c67
-rw-r--r--libavutil/avstring.h42
-rw-r--r--libavutil/avutil.h41
-rw-r--r--libavutil/base64.c8
-rw-r--r--libavutil/base64.h8
-rw-r--r--libavutil/bfin/bswap.h8
-rw-r--r--libavutil/bfin/timer.h8
-rw-r--r--libavutil/bswap.h14
-rw-r--r--libavutil/colorspace.h8
-rw-r--r--libavutil/common.h10
-rw-r--r--libavutil/cpu.c19
-rw-r--r--libavutil/cpu.h17
-rw-r--r--libavutil/crc.c10
-rw-r--r--libavutil/crc.h8
-rw-r--r--libavutil/crc_data.h8
-rw-r--r--libavutil/des.c23
-rw-r--r--libavutil/des.h19
-rw-r--r--libavutil/dict.c12
-rw-r--r--libavutil/dict.h53
-rw-r--r--libavutil/error.c11
-rw-r--r--libavutil/error.h10
-rw-r--r--libavutil/eval.c108
-rw-r--r--libavutil/eval.h41
-rw-r--r--libavutil/fifo.c69
-rw-r--r--libavutil/fifo.h65
-rw-r--r--libavutil/file.c54
-rw-r--r--libavutil/file.h17
-rw-r--r--libavutil/imgutils.c52
-rw-r--r--libavutil/imgutils.h8
-rw-r--r--libavutil/integer.c197
-rw-r--r--libavutil/integer.h86
-rw-r--r--libavutil/internal.h15
-rw-r--r--libavutil/intfloat_readwrite.c12
-rw-r--r--libavutil/intfloat_readwrite.h8
-rw-r--r--libavutil/intmath.h8
-rw-r--r--libavutil/intreadwrite.h8
-rw-r--r--libavutil/inverse.c8
-rw-r--r--libavutil/lfg.c8
-rw-r--r--libavutil/lfg.h8
-rw-r--r--libavutil/libm.h8
-rw-r--r--libavutil/lls.c146
-rw-r--r--libavutil/lls.h8
-rw-r--r--libavutil/log.c22
-rw-r--r--libavutil/log.h30
-rw-r--r--libavutil/lzo.c8
-rw-r--r--libavutil/lzo.h8
-rw-r--r--libavutil/mathematics.c11
-rw-r--r--libavutil/mathematics.h8
-rw-r--r--libavutil/md5.c8
-rw-r--r--libavutil/md5.h8
-rw-r--r--libavutil/mem.c77
-rw-r--r--libavutil/mem.h61
-rw-r--r--libavutil/mips/intreadwrite.h8
-rw-r--r--libavutil/opt.c636
-rw-r--r--libavutil/opt.h383
-rw-r--r--libavutil/parseutils.c43
-rw-r--r--libavutil/parseutils.h10
-rw-r--r--libavutil/pca.c245
-rw-r--r--libavutil/pca.h35
-rw-r--r--libavutil/pixdesc.c100
-rw-r--r--libavutil/pixdesc.h8
-rw-r--r--libavutil/pixfmt.h28
-rw-r--r--libavutil/ppc/cpu.c8
-rw-r--r--libavutil/ppc/intreadwrite.h8
-rw-r--r--libavutil/ppc/timer.h8
-rw-r--r--libavutil/random_seed.c12
-rw-r--r--libavutil/random_seed.h19
-rw-r--r--libavutil/rational.c8
-rw-r--r--libavutil/rational.h8
-rw-r--r--libavutil/rc4.c8
-rw-r--r--libavutil/rc4.h8
-rw-r--r--libavutil/samplefmt.c57
-rw-r--r--libavutil/samplefmt.h55
-rw-r--r--libavutil/sh4/bswap.h8
-rw-r--r--libavutil/sha.c8
-rw-r--r--libavutil/sha.h8
-rw-r--r--libavutil/softfloat.c72
-rw-r--r--libavutil/softfloat.h126
-rw-r--r--libavutil/timer.h18
-rw-r--r--libavutil/tomi/intreadwrite.h8
-rw-r--r--libavutil/tree.c8
-rw-r--r--libavutil/tree.h8
-rw-r--r--libavutil/utils.c24
-rw-r--r--libavutil/x86/bswap.h8
-rw-r--r--libavutil/x86/cpu.c19
-rw-r--r--libavutil/x86/intmath.h8
-rw-r--r--libavutil/x86/intreadwrite.h8
-rw-r--r--libavutil/x86/timer.h8
-rw-r--r--libavutil/x86/x86inc.asm (renamed from libavcodec/x86/x86inc.asm)0
-rw-r--r--libavutil/x86/x86util.asm (renamed from libavcodec/x86/x86util.asm)65
-rw-r--r--libavutil/x86_cpu.h8
-rw-r--r--libpostproc/Makefile2
-rw-r--r--libpostproc/postprocess.c56
-rw-r--r--libpostproc/postprocess.h18
-rw-r--r--libpostproc/postprocess_altivec_template.c8
-rw-r--r--libpostproc/postprocess_internal.h8
-rw-r--r--libpostproc/postprocess_template.c77
-rw-r--r--libswresample/Makefile12
-rw-r--r--libswresample/audioconvert.c113
-rw-r--r--libswresample/audioconvert.h65
-rw-r--r--libswresample/libswresample.v4
-rw-r--r--libswresample/rematrix.c280
-rw-r--r--libswresample/rematrix_template.c38
-rw-r--r--libswresample/resample2.c351
-rw-r--r--libswresample/swresample.c459
-rw-r--r--libswresample/swresample.h79
-rw-r--r--libswresample/swresample_internal.h79
-rw-r--r--libswresample/swresample_test.c186
-rw-r--r--libswscale/Makefile5
-rw-r--r--libswscale/bfin/internal_bfin.S8
-rw-r--r--libswscale/bfin/swscale_bfin.c8
-rw-r--r--libswscale/bfin/yuv2rgb_bfin.c11
-rw-r--r--libswscale/colorspace-test.c8
-rw-r--r--libswscale/mlib/yuv2rgb_mlib.c8
-rw-r--r--libswscale/options.c67
-rw-r--r--libswscale/ppc/swscale_altivec.c43
-rw-r--r--libswscale/ppc/yuv2rgb_altivec.c23
-rw-r--r--libswscale/ppc/yuv2rgb_altivec.h8
-rw-r--r--libswscale/ppc/yuv2yuv_altivec.c8
-rw-r--r--libswscale/rgb2rgb.c8
-rw-r--r--libswscale/rgb2rgb.h8
-rw-r--r--libswscale/rgb2rgb_template.c11
-rw-r--r--libswscale/sparc/yuv2rgb_vis.c8
-rw-r--r--libswscale/swscale-test.c8
-rw-r--r--libswscale/swscale.c671
-rw-r--r--libswscale/swscale.h27
-rw-r--r--libswscale/swscale_internal.h196
-rw-r--r--libswscale/swscale_unscaled.c246
-rw-r--r--libswscale/utils.c415
-rw-r--r--libswscale/x86/rgb2rgb.c8
-rw-r--r--libswscale/x86/rgb2rgb_template.c8
-rw-r--r--libswscale/x86/scale.asm431
-rw-r--r--libswscale/x86/swscale_mmx.c103
-rw-r--r--libswscale/x86/swscale_template.c415
-rw-r--r--libswscale/x86/yuv2rgb_mmx.c8
-rw-r--r--libswscale/x86/yuv2rgb_template.c33
-rw-r--r--libswscale/yuv2rgb.c16
-rw-r--r--mt-work/email.sh6
-rw-r--r--mt-work/mplayer.diff13
-rw-r--r--mt-work/raw.sh10
-rw-r--r--mt-work/test.sh13
-rw-r--r--mt-work/todo.txt95
-rw-r--r--mt-work/valgrind-check.sh5
-rw-r--r--mt-work/yuvcmp.c182
-rw-r--r--presets/libvpx-1080p.ffpreset17
-rw-r--r--presets/libvpx-1080p50_60.ffpreset17
-rw-r--r--presets/libvpx-360p.ffpreset16
-rw-r--r--presets/libvpx-720p.ffpreset17
-rw-r--r--presets/libvpx-720p50_60.ffpreset17
-rw-r--r--presets/libx264-ipod320.ffpreset4
-rw-r--r--presets/libx264-ipod640.ffpreset4
-rw-r--r--subdir.mak33
-rw-r--r--tests/Makefile38
-rw-r--r--tests/audiogen.c8
-rw-r--r--tests/base64.c8
-rwxr-xr-xtests/codec-regression.sh50
-rw-r--r--tests/copy.regression.ref465
-rwxr-xr-xtests/copycooker.sh4
-rwxr-xr-xtests/fate-run.sh21
-rwxr-xr-xtests/fate-update.sh55
-rw-r--r--tests/fate.mak12
-rwxr-xr-xtests/fate.sh4
-rw-r--r--tests/fate/h264.mak24
-rw-r--r--tests/fate/libavutil.mak4
-rw-r--r--tests/fate/mp3.mak12
-rw-r--r--tests/fate/prores.mak15
-rw-r--r--tests/fate2.mak8
-rwxr-xr-xtests/lavf-regression.sh61
-rwxr-xr-xtests/lavfi-regression.sh10
-rw-r--r--tests/ref/acodec/ac3_fixed2
-rw-r--r--tests/ref/acodec/adpcm_ima_qt6
-rw-r--r--tests/ref/acodec/adpcm_ima_wav2
-rw-r--r--tests/ref/acodec/adpcm_ms2
-rw-r--r--tests/ref/acodec/adpcm_swf2
-rw-r--r--tests/ref/acodec/adpcm_yam6
-rw-r--r--tests/ref/acodec/alac4
-rw-r--r--tests/ref/acodec/aref4
-rw-r--r--tests/ref/acodec/flac2
-rw-r--r--tests/ref/acodec/g723_14
-rw-r--r--tests/ref/acodec/g7268
-rw-r--r--tests/ref/acodec/mp22
-rw-r--r--tests/ref/acodec/pcm68
-rw-r--r--tests/ref/fate/aasc1
-rw-r--r--tests/ref/fate/cdgraphics351
-rw-r--r--tests/ref/fate/cscd414
-rw-r--r--tests/ref/fate/cvid1
-rw-r--r--tests/ref/fate/duck-dk32
-rw-r--r--tests/ref/fate/eval34
-rw-r--r--tests/ref/fate/feeble-dxa1
-rw-r--r--tests/ref/fate/fifo27
-rw-r--r--tests/ref/fate/film-cvid-pcm-stereo-8bit179
-rw-r--r--tests/ref/fate/fraps-v51
-rw-r--r--tests/ref/fate/g722enc1
-rw-r--r--tests/ref/fate/g729-01000
-rw-r--r--tests/ref/fate/g729-11000
-rw-r--r--tests/ref/fate/h264-conformance-frext-hi422fr10_sony_b5
-rw-r--r--tests/ref/fate/h264-conformance-frext-hi422fr13_sony_b5
-rw-r--r--tests/ref/fate/h264-conformance-frext-hi422fr1_sony_a5
-rw-r--r--tests/ref/fate/h264-conformance-frext-hi422fr6_sony_a5
-rw-r--r--tests/ref/fate/h264-conformance-frext-pph422i1_panasonic_a10
-rw-r--r--tests/ref/fate/h264-conformance-frext-pph422i2_panasonic_a10
-rw-r--r--tests/ref/fate/h264-conformance-frext-pph422i3_panasonic_a10
-rw-r--r--tests/ref/fate/h264-conformance-frext-pph422i4_panasonic_a10
-rw-r--r--tests/ref/fate/h264-conformance-frext-pph422i5_panasonic_a10
-rw-r--r--tests/ref/fate/h264-conformance-frext-pph422i6_panasonic_a10
-rw-r--r--tests/ref/fate/h264-conformance-frext-pph422i7_panasonic_a10
-rw-r--r--tests/ref/fate/iff-fibonacci2
-rw-r--r--tests/ref/fate/lmlm4-demux332
-rw-r--r--tests/ref/fate/lossless-shortenaudio2
-rw-r--r--tests/ref/fate/motionpixels1
-rw-r--r--tests/ref/fate/mpeg2-field-enc61
-rw-r--r--tests/ref/fate/prores-4222
-rw-r--r--tests/ref/fate/prores-422_hq2
-rw-r--r--tests/ref/fate/prores-422_lt2
-rw-r--r--tests/ref/fate/prores-422_proxy2
-rw-r--r--tests/ref/fate/prores-alpha2
-rw-r--r--tests/ref/fate/qt-ima4-mono2
-rw-r--r--tests/ref/fate/qt-ima4-stereo2
-rw-r--r--tests/ref/fate/quickdraw1
-rw-r--r--tests/ref/fate/real-rv40359
-rw-r--r--tests/ref/fate/rv30153
-rw-r--r--tests/ref/fate/smacker160
-rw-r--r--tests/ref/fate/tiertex-seq35
-rw-r--r--tests/ref/fate/truemotion1-15226
-rw-r--r--tests/ref/fate/truemotion1-2457
-rw-r--r--tests/ref/fate/tscc-32bit51
-rw-r--r--tests/ref/fate/vmnc-32bit89
-rw-r--r--tests/ref/fate/vp51
-rw-r--r--tests/ref/fate/vp8-sign-bias15
-rw-r--r--tests/ref/fate/zmbv-8bit1
-rw-r--r--tests/ref/lavf/dv_fmt4
-rw-r--r--tests/ref/lavf/ffm2
-rw-r--r--tests/ref/lavf/gif4
-rw-r--r--tests/ref/lavf/gxf2
-rw-r--r--tests/ref/lavf/mov2
-rw-r--r--tests/ref/lavf/mxf7
-rw-r--r--tests/ref/lavf/mxf_d103
-rw-r--r--tests/ref/lavf/pixfmt14
-rw-r--r--tests/ref/lavf/ts2
-rw-r--r--tests/ref/lavf/wav4
-rw-r--r--tests/ref/lavfi/pixdesc40
-rw-r--r--tests/ref/lavfi/pixfmts_copy40
-rw-r--r--tests/ref/lavfi/pixfmts_crop24
-rw-r--r--tests/ref/lavfi/pixfmts_hflip24
-rw-r--r--tests/ref/lavfi/pixfmts_null40
-rw-r--r--tests/ref/lavfi/pixfmts_scale72
-rw-r--r--tests/ref/lavfi/pixfmts_vflip40
-rw-r--r--tests/ref/seek/ac3_rm18
-rw-r--r--tests/ref/seek/adpcm_yam_wav54
-rw-r--r--tests/ref/seek/dv411_dv54
-rw-r--r--tests/ref/seek/dv50_dv54
-rw-r--r--tests/ref/seek/dv_dv54
-rw-r--r--tests/ref/seek/g726_wav54
-rw-r--r--tests/ref/seek/lavf_asf36
-rw-r--r--tests/ref/seek/lavf_avi16
-rw-r--r--tests/ref/seek/lavf_dv54
-rw-r--r--tests/ref/seek/lavf_ffm8
-rw-r--r--tests/ref/seek/lavf_gif2
-rw-r--r--tests/ref/seek/lavf_rm18
-rw-r--r--tests/ref/seek/lavf_ts34
-rw-r--r--tests/ref/seek/lavf_wav30
-rw-r--r--tests/ref/seek/pcm_alaw_wav54
-rw-r--r--tests/ref/seek/pcm_mulaw_wav54
-rw-r--r--tests/ref/seek/pcm_s16le_wav54
-rw-r--r--tests/ref/seek/pcm_u8_wav54
-rw-r--r--tests/ref/seek/pcm_zork_wav54
-rw-r--r--tests/ref/seek/wmav1_asf2
-rw-r--r--tests/ref/seek/wmav2_asf2
-rw-r--r--tests/ref/vsynth1/amv/vsynth1-amv4
-rw-r--r--tests/ref/vsynth1/dnxhd_720p_10bit4
-rw-r--r--tests/ref/vsynth1/dv4
-rw-r--r--tests/ref/vsynth1/dv502
-rw-r--r--tests/ref/vsynth1/error2
-rw-r--r--tests/ref/vsynth1/flashsv4
-rw-r--r--tests/ref/vsynth1/flashsv26
-rw-r--r--tests/ref/vsynth1/jpeg20004
-rw-r--r--tests/ref/vsynth1/jpegls4
-rw-r--r--tests/ref/vsynth1/mpeg42
-rw-r--r--tests/ref/vsynth1/msvideo14
-rw-r--r--tests/ref/vsynth1/qtrle4
-rw-r--r--tests/ref/vsynth1/qtrlegray4
-rw-r--r--tests/ref/vsynth1/rgb4
-rw-r--r--tests/ref/vsynth2/amv/vsynth2-amv4
-rw-r--r--tests/ref/vsynth2/dnxhd_720p_10bit4
-rw-r--r--tests/ref/vsynth2/dv4
-rw-r--r--tests/ref/vsynth2/dv502
-rw-r--r--tests/ref/vsynth2/error2
-rw-r--r--tests/ref/vsynth2/flashsv4
-rw-r--r--tests/ref/vsynth2/flashsv26
-rw-r--r--tests/ref/vsynth2/jpeg20004
-rw-r--r--tests/ref/vsynth2/jpegls4
-rw-r--r--tests/ref/vsynth2/mpeg42
-rw-r--r--tests/ref/vsynth2/msvideo14
-rw-r--r--tests/ref/vsynth2/qtrle4
-rw-r--r--tests/ref/vsynth2/qtrlegray4
-rw-r--r--tests/ref/vsynth2/rgb4
-rwxr-xr-xtests/regression-funcs.sh33
-rw-r--r--tests/rotozoom.c8
-rw-r--r--tests/tiny_psnr.c23
-rw-r--r--tests/videogen.c8
-rw-r--r--tools/build_libstagefright56
-rwxr-xr-xtools/clean-diff11
-rw-r--r--tools/graph2dot.c13
-rw-r--r--tools/lavfi-showfiltfmts.c74
-rwxr-xr-xtools/patcheck2
-rw-r--r--tools/pktdumper.c12
-rw-r--r--tools/probetest.c8
-rw-r--r--tools/qt-faststart.c2
-rw-r--r--tools/trasher.c8
-rwxr-xr-xtools/unwrap-diff2
-rwxr-xr-xversion.sh26
1852 files changed, 130198 insertions, 38547 deletions
diff --git a/.gitignore b/.gitignore
index 8887980bc0..833ae7911b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,6 +6,11 @@
*.ho
*-example
*-test
+*_g
+*.def
+*.dll
+*.lib
+*.exp
config.*
doc/*.1
doc/*.html
@@ -15,22 +20,25 @@ ffmpeg
ffplay
ffprobe
ffserver
+avconv
libavcodec/*_tablegen
libavcodec/*_tables.c
libavcodec/*_tables.h
+libavcodec/codec_names.h
libavcodec/libavcodec*
+libavcore/libavcore*
libavdevice/libavdevice*
libavfilter/libavfilter*
libavformat/libavformat*
libavutil/avconfig.h
libavutil/libavutil*
libpostproc/libpostproc*
+libswresample/libswresample*
libswscale/libswscale*
tests/audiogen
tests/base64
tests/data
tests/rotozoom
-tests/seek_test
tests/tiny_psnr
tests/videogen
tests/vsynth1
@@ -42,5 +50,4 @@ tools/pktdumper
tools/probetest
tools/qt-faststart
tools/trasher
-tools/trasher*.d
version.h
diff --git a/CREDITS b/CREDITS
index 4a537786f0..1d0666b6df 100644
--- a/CREDITS
+++ b/CREDITS
@@ -1,5 +1,5 @@
This file contains the names of some of the people who have contributed to
-Libav/FFmpeg. The names are sorted alphabetically by last name. As this file is
+FFmpeg. The names are sorted alphabetically by last name. As this file is
currently quite outdated and git serves as a much better tool for determining
authorship, it remains here for historical reasons only.
diff --git a/Changelog b/Changelog
index b785197083..5c9ccb5ccd 100644
--- a/Changelog
+++ b/Changelog
@@ -1,33 +1,79 @@
Entries are sorted chronologically from oldest to youngest within each release,
releases are sorted from youngest to oldest.
-
-version 0.7:
-
-- E-AC-3 audio encoder
-- ac3enc: add channel coupling support
-- floating-point sample format support to the ac3, eac3, dca, aac, and vorbis decoders.
-- H264/MPEG frame-level multi-threading
-- All av_metadata_* functions renamed to av_dict_* and moved to libavutil
-- 4:4:4 H.264 decoding support
-- 10-bit H.264 optimizations for x86
-- Bump libswscale for recently reported ABI break
-
-
-version 0.7_beta2:
-
-- VP8 frame-multithreading
-- NEON optimizations for VP8
-- Lots of deprecated API cruft removed
-- fft and imdct optimizations for AVX (Sandy Bridge) processors
-- DPX image encoder
-- SMPTE 302M AES3 audio decoder
-- Remove support for quitting ffmpeg with 'q', ctrl+c should be used.
-- 9bit and 10bit per sample support in the H.264 decoder
-
-
-version 0.7_beta1:
-
+version next:
+
+- openal input device added
+- boxblur filter added
+- BWF muxer
+- Flash Screen Video 2 decoder
+- lavfi input device added
+- added avconv, which is almost the same for now, except
+for a few incompatible changes in the options, which will hopefully make them
+easier to use. The changes are:
+ * -newvideo/-newaudio/-newsubtitle are gone, because they were redundant and
+ worked in a nonstandard way. -map is sufficient to add streams to output
+ files.
+ * -map now has slightly different and more powerful syntax.
+ + it's possible to specify stream type. E.g. -map 0:a:2 means 'third
+ audio stream'.
+ + omitting the stream index now maps all the streams of the given
+ type, not just the first. E.g. -map 0:s maps all the subtitle streams.
+ + colons (':') are used to separate file index/stream type/stream
+ index. Comma (',') is used to separate the sync stream. This is done
+ for consistency with other options.
+ + since -map can now match multiple streams, negative mappings were
+ introduced. Negative mappings disable some streams from an already
+ defined map. E.g. '-map 0 -map -0:a:1' means 'map everything except
+ for the second audio stream'.
+ * -vcodec/-acodec/-scodec are replaced by -c (or -codec), which
+ allows to precisely specify target stream(s) consistently with other
+ options. E.g. '-c:v libx264' sets the codec for all video streams,
+ '-c:a:0 libvorbis' sets the codec for the first audio stream and '-c
+ copy' copies all the streams.
+ * It is now possible to precisely specify which stream should an AVOption
+ apply to. See the manual for detailed explanation.
+ * -map_chapters now takes only an input file index and applies to the next
+ output file. This is consistent with how all the other options work.
+ * -map_metadata now takes only an input metadata specifier and applies to
+ the next output file. Output metadata specifier is now part of the option
+ name, similarly to the AVOptions/map/codec feature above.
+ * Presets in avconv are disabled, because only libx264 used them and
+ presets for libx264 can now be specified using a private option
+ '-preset <presetname>'.
+ * -intra option was removed, it's equivalent to -g 0.
+- XMV demuxer
+- LOAS demuxer
+- ashowinfo filter added
+- Windows Media Image decoder
+- amovie source added
+- LATM muxer/demuxer
+- Speex encoder via libspeex
+- JSON output in ffprobe
+- WTV muxer
+- Optional C++ Support (needed for libstagefright)
+- H.264 Decoding on Android via Stagefright
+- Prores decoder
+- BIN/XBIN/ADF/IDF text file decoder
+- aconvert audio filter added
+- audio support to lavfi input device added
+- libcdio-paranoia input device for audio CD grabbing
+- Apple ProRes decoder
+- CELT in Ogg demuxing
+- G.723.1 demuxer and decoder
+- libmodplug support (--enable-libmodplug)
+- VC-1 interlaced decoding
+- libutvideo wrapper (--enable-libutvideo)
+- aevalsrc audio source added
+- Ut Video decoder
+- Speex encoding via libspeex
+- 4:2:2 H.264 decoding support
+- Pulseaudio input device
+
+version 0.8:
+
+
+- many many things we forgot because we rather write code than changelogs
- WebM support in Matroska de/muxer
- low overhead Ogg muxing
- MMS-TCP support
@@ -35,6 +81,7 @@ version 0.7_beta1:
- Demuxer for On2's IVF format
- Pictor/PC Paint decoder
- HE-AAC v2 decoder
+- HE-AAC v2 encoding with libaacplus
- libfaad2 wrapper removed
- DTS-ES extension (XCh) decoding support
- native VP8 decoder
@@ -46,6 +93,7 @@ version 0.7_beta1:
- RTP depacketization of QDM2
- ANSI/ASCII art playback system
- Lego Mindstorms RSO de/muxer
+- libavcore added (and subsequently removed)
- SubRip subtitle file muxer and demuxer
- Chinese AVS encoding via libxavs
- ffprobe -show_packets option added
@@ -75,10 +123,10 @@ version 0.7_beta1:
- demuxer for receiving raw rtp:// URLs without an SDP description
- single stream LATM/LOAS decoder
- setpts filter added
-- Win64 support for optimized asm functions
+- Win64 support for optimized x86 assembly functions
- MJPEG/AVI1 to JPEG/JFIF bitstream filter
- ASS subtitle encoder and decoder
-- IEC 61937 encapsulation for E-AC3, TrueHD, DTS-HD (for HDMI passthrough)
+- IEC 61937 encapsulation for E-AC-3, TrueHD, DTS-HD (for HDMI passthrough)
- overlay filter added
- rename aspect filter to setdar, and pixelaspect to setsar
- IEC 61937 demuxer
@@ -92,7 +140,7 @@ version 0.7_beta1:
- replace the ocv_smooth filter with a more generic ocv filter
- Windows Televison (WTV) demuxer
- FFmpeg metadata format muxer and demuxer
-- SubRip (srt) subtitle decoder
+- SubRip (srt) subtitle encoder and decoder
- floating-point AC-3 encoder added
- Lagarith decoder
- ffmpeg -copytb option added
@@ -105,11 +153,45 @@ version 0.7_beta1:
- sndio support for playback and record
- Linux framebuffer input device added
- Chronomaster DFA decoder
-- Mobotix MxPEG decoder
+- DPX image encoder
+- MicroDVD subtitle file muxer and demuxer
+- Playstation Portable PMP format demuxer
+- fieldorder video filter added
- AAC encoding via libvo-aacenc
- AMR-WB encoding via libvo-amrwbenc
- xWMA demuxer
-- fieldorder video filter added
+- Mobotix MxPEG decoder
+- VP8 frame-multithreading
+- NEON optimizations for VP8
+- Lots of deprecated API cruft removed
+- fft and imdct optimizations for AVX (Sandy Bridge) processors
+- showinfo filter added
+- SMPTE 302M AES3 audio decoder
+- Apple Core Audio Format muxer
+- 9bit and 10bit per sample support in the H.264 decoder
+- 9bit and 10bit FFV1 encoding / decoding
+- split filter added
+- select filter added
+- sdl output device added
+- libmpcodecs video filter support (3 times as many filters than before)
+- mpeg2 aspect ratio dection fixed
+- libxvid aspect pickiness fixed
+- Frame multithreaded decoding
+- E-AC-3 audio encoder
+- ac3enc: add channel coupling support
+- floating-point sample format support to the ac3, eac3, dca, aac, and vorbis decoders.
+- H264/MPEG frame-level multi-threading
+- All av_metadata_* functions renamed to av_dict_* and moved to libavutil
+- 4:4:4 H.264 decoding support
+- 10-bit H.264 optimizations for x86
+- lut, lutrgb, and lutyuv filters added
+- buffersink libavfilter sink added
+- Bump libswscale for recently reported ABI break
+
+
+version 0.7:
+
+- all the changes for 0.8, but keeping API/ABI compatibility with the 0.6 release
version 0.6:
@@ -350,6 +432,7 @@ version 0.5:
- Gopher client support
- MXF D-10 muxer
- generic metadata API
+- flash ScreenVideo2 encoder
version 0.4.9-pre1:
diff --git a/Doxyfile b/Doxyfile
index a4beaba323..dfa51ccb5f 100644
--- a/Doxyfile
+++ b/Doxyfile
@@ -25,7 +25,7 @@ DOXYFILE_ENCODING = UTF-8
# The PROJECT_NAME tag is a single word (or a sequence of words surrounded
# by quotes) that should identify the project.
-PROJECT_NAME = Libav
+PROJECT_NAME = FFmpeg
# The PROJECT_NUMBER tag can be used to enter a project or revision number.
# This could be handy for archiving the generated documentation or
@@ -625,7 +625,8 @@ EXCLUDE_SYMLINKS = NO
# for example use the pattern */test/*
EXCLUDE_PATTERNS = *.git \
- *.d
+ *.d \
+ avconv.c
# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
# (namespaces, classes, functions, etc.) that should be excluded from the
@@ -1382,7 +1383,8 @@ PREDEFINED = "__attribute__(x)=" \
# The macro definition that is found in the sources will be used.
# Use the PREDEFINED tag if you want to use a different macro definition.
-EXPAND_AS_DEFINED = declare_idct
+EXPAND_AS_DEFINED = declare_idct \
+ READ_PAR_DATA \
# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then
# doxygen's preprocessor will remove all function-like macros that are alone
diff --git a/INSTALL b/INSTALL
index ac5dc5dbb6..9549346302 100644
--- a/INSTALL
+++ b/INSTALL
@@ -2,17 +2,14 @@
1) Type './configure' to create the configuration. A list of configure
options is printed by running 'configure --help'.
-'configure' can be launched from a directory different from the Libav
+'configure' can be launched from a directory different from the FFmpeg
sources to build the objects out of tree. To do this, use an absolute
-path when launching 'configure', e.g. '/libavdir/libav/configure'.
+path when launching 'configure', e.g. '/ffmpegdir/ffmpeg/configure'.
-2) Then type 'make' to build Libav. GNU Make 3.81 or later is required.
+2) Then type 'make' to build FFmpeg. GNU Make 3.81 or later is required.
3) Type 'make install' to install all binaries and libraries you built.
NOTICE
- Non system dependencies (e.g. libx264, libvpx) are disabled by default.
-
- - The default cflags include -g, if you want lean libraries you can either
- pass --disable-debug or strip the debug symbols at a later time.
diff --git a/LICENSE b/LICENSE
index 725995da56..7272b90f8d 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,17 +1,17 @@
-Libav:
-------
+FFmpeg:
+-------
-Most files in Libav are under the GNU Lesser General Public License version 2.1
+Most files in FFmpeg are under the GNU Lesser General Public License version 2.1
or later (LGPL v2.1+). Read the file COPYING.LGPLv2.1 for details. Some other
files have MIT/X11/BSD-style licenses. In combination the LGPL v2.1+ applies to
-Libav.
+FFmpeg.
-Some optional parts of Libav are licensed under the GNU General Public License
+Some optional parts of FFmpeg are licensed under the GNU General Public License
version 2 or later (GPL v2+). See the file COPYING.GPLv2 for details. None of
these parts are used by default, you have to explicitly pass --enable-gpl to
-configure to activate them. In this case, Libav's license changes to GPL v2+.
+configure to activate them. In this case, FFmpeg's license changes to GPL v2+.
-Specifically, the GPL parts of Libav are
+Specifically, the GPL parts of FFmpeg are
- libpostproc
- optional x86 optimizations in the files
@@ -33,14 +33,14 @@ external libraries:
-------------------
Some external libraries, e.g. libx264, are under GPL and can be used in
-conjunction with Libav. They require --enable-gpl to be passed to configure
+conjunction with FFmpeg. They require --enable-gpl to be passed to configure
as well.
The OpenCORE external libraries are under the Apache License 2.0. That license
is incompatible with the LGPL v2.1 and the GPL v2, but not with version 3 of
-those licenses. So to combine the OpenCORE libraries with Libav, the license
+those licenses. So to combine the OpenCORE libraries with FFmpeg, the license
version needs to be upgraded by passing --enable-version3 to configure.
-The nonfree external library libfaac can be hooked up in Libav. You need to
-pass --enable-nonfree to configure to enable it. Employ this option with care
-as Libav then becomes nonfree and unredistributable.
+The nonfree external libraries libfaac and libaacplus can be hooked up in FFmpeg.
+You need to pass --enable-nonfree to configure to enable it. Employ this option
+with care as FFmpeg then becomes nonfree and unredistributable.
diff --git a/MAINTAINERS b/MAINTAINERS
new file mode 100644
index 0000000000..319a79ae68
--- /dev/null
+++ b/MAINTAINERS
@@ -0,0 +1,401 @@
+FFmpeg maintainers
+==================
+
+Below is a list of the people maintaining different parts of the
+FFmpeg code.
+
+
+Project Leader
+==============
+
+Michael Niedermayer
+ final design decisions
+
+
+Applications
+============
+
+ffmpeg:
+ ffmpeg.c Michael Niedermayer
+
+ffplay:
+ ffplay.c Marton Balint
+
+ffprobe:
+ ffprobe.c Stefano Sabatini
+
+ffserver:
+ ffserver.c, ffserver.h Baptiste Coudurier
+
+Commandline utility code:
+ cmdutils.c, cmdutils.h Michael Niedermayer
+
+QuickTime faststart:
+ tools/qt-faststart.c Baptiste Coudurier
+
+
+Miscellaneous Areas
+===================
+
+documentation Mike Melanson
+website Robert Swain
+build system (configure,Makefiles) Diego Biurrun, Mans Rullgard
+project server Diego Biurrun, Mans Rullgard
+mailinglists Michael Niedermayer, Baptiste Coudurier
+presets Robert Swain
+metadata subsystem Aurelien Jacobs
+release management Diego Biurrun, Reinhard Tartler
+
+
+libavutil
+=========
+
+External Interfaces:
+ libavutil/avutil.h Michael Niedermayer
+Internal Interfaces:
+ libavutil/common.h Michael Niedermayer
+
+Other:
+ intfloat* Michael Niedermayer
+ rational.c, rational.h Michael Niedermayer
+ mathematics.c, mathematics.h Michael Niedermayer
+ integer.c, integer.h Michael Niedermayer
+ bswap.h
+
+
+libavcodec
+==========
+
+Generic Parts:
+ External Interfaces:
+ avcodec.h Michael Niedermayer
+ utility code:
+ utils.c Michael Niedermayer
+ mem.c Michael Niedermayer
+ opt.c, opt.h Michael Niedermayer
+ arithmetic expression evaluator:
+ eval.c Michael Niedermayer
+ audio and video frame extraction:
+ parser.c Michael Niedermayer
+ bitstream reading:
+ bitstream.c, bitstream.h Michael Niedermayer
+ CABAC:
+ cabac.h, cabac.c Michael Niedermayer
+ DSP utilities:
+ dsputils.c, dsputils.h Michael Niedermayer
+ entropy coding:
+ rangecoder.c, rangecoder.h Michael Niedermayer
+ lzw.* Michael Niedermayer
+ floating point AAN DCT:
+ faandct.c, faandct.h Michael Niedermayer
+ Golomb coding:
+ golomb.c, golomb.h Michael Niedermayer
+ LPC:
+ lpc.c, lpc.h Justin Ruggles
+ motion estimation:
+ motion* Michael Niedermayer
+ rate control:
+ ratecontrol.c Michael Niedermayer
+ libxvid_rc.c Michael Niedermayer
+ simple IDCT:
+ simple_idct.c, simple_idct.h Michael Niedermayer
+ postprocessing:
+ libpostproc/* Michael Niedermayer
+ table generation:
+ tableprint.c, tableprint.h Reimar Doeffinger
+
+Codecs:
+ 4xm.c Michael Niedermayer
+ 8bps.c Roberto Togni
+ 8svx.c Jaikrishnan Menon
+ aasc.c Kostya Shishkov
+ ac3* Justin Ruggles
+ alacenc.c Jaikrishnan Menon
+ alsdec.c Thilo Borgmann
+ apedec.c Kostya Shishkov
+ ass* Aurelien Jacobs
+ asv* Michael Niedermayer
+ atrac3* Benjamin Larsson
+ bgmc.c, bgmc.h Thilo Borgmann
+ bink.c Kostya Shishkov
+ binkaudio.c Peter Ross
+ bmp.c Mans Rullgard, Kostya Shishkov
+ cavs* Stefan Gehrer
+ celp_filters.* Vitor Sessak
+ cinepak.c Roberto Togni
+ cljr Alex Beregszaszi
+ cook.c, cookdata.h Benjamin Larsson
+ crystalhd.c Philip Langdale
+ cscd.c Reimar Doeffinger
+ dca.c Kostya Shishkov, Benjamin Larsson
+ dnxhd* Baptiste Coudurier
+ dpcm.c Mike Melanson
+ dxa.c Kostya Shishkov
+ dv.c Roman Shaposhnik
+ eacmv*, eaidct*, eat* Peter Ross
+ ffv1.c Michael Niedermayer
+ flac* Justin Ruggles
+ flashsv* Benjamin Larsson
+ flicvideo.c Mike Melanson
+ g722.c Martin Storsjo
+ g726.c Roman Shaposhnik
+ gifdec.c Baptiste Coudurier
+ h264* Loren Merritt, Michael Niedermayer
+ h261* Michael Niedermayer
+ h263* Michael Niedermayer
+ huffyuv.c Michael Niedermayer
+ idcinvideo.c Mike Melanson
+ imc* Benjamin Larsson
+ indeo2* Kostya Shishkov
+ indeo5* Kostya Shishkov
+ interplayvideo.c Mike Melanson
+ ivi* Kostya Shishkov
+ jpeg_ls.c Kostya Shishkov
+ jvdec.c Peter Ross
+ kmvc.c Kostya Shishkov
+ lcl*.c Roberto Togni, Reimar Doeffinger
+ libgsm.c Michel Bardiaux
+ libdirac* David Conrad
+ libopenjpeg.c Jaikrishnan Menon
+ libschroedinger* David Conrad
+ libspeexdec.c Justin Ruggles
+ libtheoraenc.c David Conrad
+ libvorbis.c David Conrad
+ libxavs.c Stefan Gehrer
+ libx264.c Mans Rullgard, Jason Garrett-Glaser
+ loco.c Kostya Shishkov
+ lzo.h, lzo.c Reimar Doeffinger
+ mdec.c Michael Niedermayer
+ mimic.c Ramiro Polla
+ mjpeg.c Michael Niedermayer
+ mlp* Ramiro Polla
+ mmvideo.c Peter Ross
+ mpc* Kostya Shishkov
+ mpeg12.c, mpeg12data.h Michael Niedermayer
+ mpegvideo.c, mpegvideo.h Michael Niedermayer
+ msmpeg4.c, msmpeg4data.h Michael Niedermayer
+ msrle.c Mike Melanson
+ msvideo1.c Mike Melanson
+ nellymoserdec.c Benjamin Larsson
+ nuv.c Reimar Doeffinger
+ pcx.c Ivo van Poorten
+ pgssubdec.c Reimar Doeffinger
+ ptx.c Ivo van Poorten
+ qcelp* Reynaldo H. Verdejo Pinochet
+ qdm2.c, qdm2data.h Roberto Togni, Benjamin Larsson
+ qdrw.c Kostya Shishkov
+ qpeg.c Kostya Shishkov
+ qtrle.c Mike Melanson
+ ra144.c, ra144.h, ra288.c, ra288.h Roberto Togni
+ resample2.c Michael Niedermayer
+ rl2.c Sascha Sommer
+ rpza.c Roberto Togni
+ rtjpeg.c, rtjpeg.h Reimar Doeffinger
+ rv10.c Michael Niedermayer
+ rv3* Kostya Shishkov
+ rv4* Kostya Shishkov
+ s3tc* Ivo van Poorten
+ smacker.c Kostya Shishkov
+ smc.c Mike Melanson
+ snow.c Michael Niedermayer, Loren Merritt
+ sonic.c Alex Beregszaszi
+ srt* Aurelien Jacobs
+ sunrast.c Ivo van Poorten
+ svq3.c Michael Niedermayer
+ targa.c Kostya Shishkov
+ tiff.c Kostya Shishkov
+ truemotion1* Mike Melanson
+ truemotion2* Kostya Shishkov
+ truespeech.c Kostya Shishkov
+ tscc.c Kostya Shishkov
+ tta.c Alex Beregszaszi, Jaikrishnan Menon
+ txd.c Ivo van Poorten
+ ulti* Kostya Shishkov
+ vb.c Kostya Shishkov
+ vc1* Kostya Shishkov
+ vcr1.c Michael Niedermayer
+ vmnc.c Kostya Shishkov
+ vorbis_enc.c Oded Shimon
+ vorbis_dec.c Denes Balatoni, David Conrad
+ vp3* Mike Melanson
+ vp5 Aurelien Jacobs
+ vp6 Aurelien Jacobs
+ vp8 David Conrad, Jason Garrett-Glaser, Ronald Bultje
+ vqavideo.c Mike Melanson
+ wavpack.c Kostya Shishkov
+ wmaprodec.c Sascha Sommer
+ wmavoice.c Ronald S. Bultje
+ wmv2.c Michael Niedermayer
+ wnv1.c Kostya Shishkov
+ xan.c Mike Melanson
+ xl.c Kostya Shishkov
+ xvmc.c Ivan Kalvachev
+ zmbv* Kostya Shishkov
+
+Hardware acceleration:
+ crystalhd.c Philip Langdale
+ dxva2* Laurent Aimar
+ vaapi* Gwenole Beauchesne
+ vdpau* Carl Eugen Hoyos
+
+
+libavdevice
+===========
+ External Interface:
+ libavdevice/avdevice.h
+
+
+ libdc1394.c Roman Shaposhnik
+ v4l2.c Luca Abeni
+ vfwcap.c Ramiro Polla
+
+
+libavformat
+===========
+
+Generic parts:
+ External Interface:
+ libavformat/avformat.h Michael Niedermayer
+ Utility Code:
+ libavformat/utils.c Michael Niedermayer
+
+
+Muxers/Demuxers:
+ 4xm.c Mike Melanson
+ adtsenc.c Robert Swain
+ aiff.c Baptiste Coudurier
+ ape.c Kostya Shishkov
+ ass* Aurelien Jacobs
+ avi* Michael Niedermayer
+ bink.c Peter Ross
+ caf* Peter Ross
+ crc.c Michael Niedermayer
+ daud.c Reimar Doeffinger
+ dv.c Roman Shaposhnik
+ dxa.c Kostya Shishkov
+ electronicarts.c Peter Ross
+ ffm* Baptiste Coudurier
+ flac* Justin Ruggles
+ flic.c Mike Melanson
+ flvdec.c, flvenc.c Michael Niedermayer
+ gxf.c Reimar Doeffinger
+ gxfenc.c Baptiste Coudurier
+ idcin.c Mike Melanson
+ idroqdec.c Mike Melanson
+ iff.c Jaikrishnan Menon
+ ipmovie.c Mike Melanson
+ img2.c Michael Niedermayer
+ iss.c Stefan Gehrer
+ jvdec.c Peter Ross
+ libmodplug.c Clément Bœsch
+ libnut.c Oded Shimon
+ lmlm4.c Ivo van Poorten
+ lxfdec.c Tomas Härdin
+ matroska.c Aurelien Jacobs
+ matroskadec.c Aurelien Jacobs
+ matroskaenc.c David Conrad
+ metadata* Aurelien Jacobs
+ microdvd* Aurelien Jacobs
+ mm.c Peter Ross
+ mov.c Michael Niedermayer, Baptiste Coudurier
+ movenc.c Michael Niedermayer, Baptiste Coudurier
+ mpc.c Kostya Shishkov
+ mpeg.c Michael Niedermayer
+ mpegenc.c Michael Niedermayer
+ mpegts* Baptiste Coudurier
+ msnwc_tcp.c Ramiro Polla
+ mtv.c Reynaldo H. Verdejo Pinochet
+ mxf* Baptiste Coudurier
+ nsvdec.c Francois Revol
+ nut.c Michael Niedermayer
+ nuv.c Reimar Doeffinger
+ oggdec.c, oggdec.h David Conrad
+ oggenc.c Baptiste Coudurier
+ oggparse*.c David Conrad
+ oma.c Maxim Poliakovski
+ psxstr.c Mike Melanson
+ pva.c Ivo van Poorten
+ r3d.c Baptiste Coudurier
+ raw.c Michael Niedermayer
+ rdt.c Ronald S. Bultje
+ rl2.c Sascha Sommer
+ rmdec.c, rmenc.c Ronald S. Bultje, Kostya Shishkov
+ rtmp* Kostya Shishkov
+ rtp.c, rtpenc.c Martin Storsjo
+ rtpdec_asf.* Ronald S. Bultje
+ rtpenc_mpv.*, rtpenc_aac.* Martin Storsjo
+ rtsp.c Luca Barbato
+ sdp.c Martin Storsjo
+ segafilm.c Mike Melanson
+ siff.c Kostya Shishkov
+ smacker.c Kostya Shishkov
+ srtdec.c Aurelien Jacobs
+ swf.c Baptiste Coudurier
+ tta.c Alex Beregszaszi
+ txd.c Ivo van Poorten
+ voc.c Aurelien Jacobs
+ wav.c Michael Niedermayer
+ wc3movie.c Mike Melanson
+ westwood.c Mike Melanson
+ wtv.c Peter Ross
+ wv.c Kostya Shishkov
+
+Protocols:
+ http.c Ronald S. Bultje
+ mms*.c Ronald S. Bultje
+ udp.c Luca Abeni
+
+
+Operating systems / CPU architectures
+=====================================
+
+Alpha Mans Rullgard, Falk Hueffner
+ARM Mans Rullgard
+AVR32 Mans Rullgard
+MIPS Mans Rullgard
+Mac OS X / PowerPC Romain Dolbeau, Guillaume Poirier
+Amiga / PowerPC Colin Ward
+Linux / PowerPC Luca Barbato
+Windows MinGW Alex Beregszaszi, Ramiro Polla
+Windows Cygwin Victor Paesa
+ADI/Blackfin DSP Marc Hoffman
+Sparc Roman Shaposhnik
+x86 Michael Niedermayer
+
+
+Releases
+========
+
+0.5 *Deprecated/Unmaintained*
+0.6 *Deprecated/Unmaintained*
+0.7 Michael Niedermayer
+0.8 Michael Niedermayer
+
+
+
+GnuPG Fingerprints of maintainers and contributors
+==================================================
+
+Anssi Hannula 1A92 FF42 2DD9 8D2E 8AF7 65A9 4278 C520 513D F3CB
+Anton Khirnov 6D0C 6625 56F8 65D1 E5F5 814B B50A 1241 C067 07AB
+Attila Kinali 11F0 F9A6 A1D2 11F6 C745 D10C 6520 BCDD F2DF E765
+Baptiste Coudurier 8D77 134D 20CC 9220 201F C5DB 0AC9 325C 5C1A BAAA
+Ben Littler 3EE3 3723 E560 3214 A8CD 4DEB 2CDB FCE7 768C 8D2C
+Benoit Fouet B22A 4F4F 43EF 636B BB66 FCDC 0023 AE1E 2985 49C8
+Daniel Verkamp 78A6 07ED 782C 653E C628 B8B9 F0EB 8DD8 2F0E 21C7
+Diego Biurrun 8227 1E31 B6D9 4994 7427 E220 9CAE D6CC 4757 FCC5
+Gwenole Beauchesne 2E63 B3A6 3E44 37E2 017D 2704 53C7 6266 B153 99C4
+Jaikrishnan Menon 61A1 F09F 01C9 2D45 78E1 C862 25DC 8831 AF70 D368
+Justin Ruggles 3136 ECC0 C10D 6C04 5F43 CA29 FCBE CD2A 3787 1EBF
+Loren Merritt ABD9 08F4 C920 3F65 D8BE 35D7 1540 DAA7 060F 56DE
+Luca Barbato 6677 4209 213C 8843 5B67 29E7 E84C 78C2 84E9 0E34
+Michael Niedermayer 9FF2 128B 147E F673 0BAD F133 611E C787 040B 0FAB
+Panagiotis Issaris 515C E262 10A8 FDCE 5481 7B9C 3AD7 D9A5 071D B3A9
+Peter Ross A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B
+Reimar Döffinger C61D 16E5 9E2C D10C 8958 38A4 0899 A2B9 06D4 D9C7
+Reinhard Tartler 9300 5DC2 7E87 6C37 ED7B CA9A 9808 3544 9453 48A4
+Reynaldo H. Verdejo Pinochet 6E27 CD34 170C C78E 4D4F 5F40 C18E 077F 3114 452A
+Robert Swain EE7A 56EA 4A81 A7B5 2001 A521 67FA 362D A2FC 3E71
+Sascha Sommer 38A0 F88B 868E 9D3A 97D4 D6A0 E823 706F 1E07 0D3C
+Stefano Sabatini 9A43 10F8 D32C D33C 48E7 C52C 5DF2 8E4D B2EE 066B
+Tomas Härdin D133 29CA 4EEC 9DB4 7076 F697 B04B 7403 3313 41FD
diff --git a/Makefile b/Makefile
index 9f7b4361d4..94fb830723 100644
--- a/Makefile
+++ b/Makefile
@@ -1,90 +1,62 @@
+MAIN_MAKEFILE=1
include config.mak
vpath %.c $(SRC_PATH)
+vpath %.cpp $(SRC_PATH)
vpath %.h $(SRC_PATH)
vpath %.S $(SRC_PATH)
vpath %.asm $(SRC_PATH)
vpath %.v $(SRC_PATH)
vpath %.texi $(SRC_PATH)
-ifndef V
-Q = @
-ECHO = printf "$(1)\t%s\n" $(2)
-BRIEF = CC AS YASM AR LD HOSTCC
-SILENT = DEPCC YASMDEP RM RANLIB
-MSG = $@
-M = @$(call ECHO,$(TAG),$@);
-$(foreach VAR,$(BRIEF), \
- $(eval override $(VAR) = @$$(call ECHO,$(VAR),$$(MSG)); $($(VAR))))
-$(foreach VAR,$(SILENT),$(eval override $(VAR) = @$($(VAR))))
-$(eval INSTALL = @$(call ECHO,INSTALL,$$(^:$(SRC_PATH)/%=%)); $(INSTALL))
-endif
-
-IFLAGS := -I. -I$(SRC_PATH)
-CPPFLAGS := $(IFLAGS) $(CPPFLAGS)
-CFLAGS += $(ECFLAGS)
-CCFLAGS = $(CFLAGS)
-YASMFLAGS += $(IFLAGS) -Pconfig.asm
-HOSTCFLAGS += $(IFLAGS)
-
-define COMPILE
- $($(1)DEP)
- $($(1)) $(CPPFLAGS) $($(1)FLAGS) $($(1)_DEPFLAGS) -c $($(1)_O) $<
-endef
-
-COMPILE_C = $(call COMPILE,CC)
-COMPILE_S = $(call COMPILE,AS)
-
-%.o: %.c
- $(COMPILE_C)
-
-%.o: %.S
- $(COMPILE_S)
-
-%.ho: %.h
- $(CC) $(CPPFLAGS) $(CFLAGS) -Wno-unused -c -o $@ -x c $<
-
-%.ver: %.v
- $(Q)sed 's/$$MAJOR/$($(basename $(@F))_VERSION_MAJOR)/' $^ > $@
-
-%.c %.h: TAG = GEN
-
PROGS-$(CONFIG_FFMPEG) += ffmpeg
+PROGS-$(CONFIG_AVCONV) += avconv
PROGS-$(CONFIG_FFPLAY) += ffplay
PROGS-$(CONFIG_FFPROBE) += ffprobe
PROGS-$(CONFIG_FFSERVER) += ffserver
PROGS := $(PROGS-yes:%=%$(EXESUF))
+INSTPROGS = $(PROGS-yes:%=%$(PROGSSUF)$(EXESUF))
OBJS = $(PROGS-yes:%=%.o) cmdutils.o
TESTTOOLS = audiogen videogen rotozoom tiny_psnr base64
HOSTPROGS := $(TESTTOOLS:%=tests/%)
+TOOLS = qt-faststart trasher
+TOOLS-$(CONFIG_ZLIB) += cws2fws
-BASENAMES = ffmpeg ffplay ffprobe ffserver
-ALLPROGS = $(BASENAMES:%=%$(EXESUF))
+BASENAMES = ffmpeg avconv ffplay ffprobe ffserver
+ALLPROGS = $(BASENAMES:%=%$(PROGSSUF)$(EXESUF))
+ALLPROGS_G = $(BASENAMES:%=%$(PROGSSUF)_g$(EXESUF))
ALLMANPAGES = $(BASENAMES:%=%.1)
-ALLFFLIBS = avcodec avdevice avfilter avformat avutil postproc swscale
-
FFLIBS-$(CONFIG_AVDEVICE) += avdevice
FFLIBS-$(CONFIG_AVFILTER) += avfilter
FFLIBS-$(CONFIG_AVFORMAT) += avformat
FFLIBS-$(CONFIG_AVCODEC) += avcodec
FFLIBS-$(CONFIG_POSTPROC) += postproc
+FFLIBS-$(CONFIG_SWRESAMPLE)+= swresample
FFLIBS-$(CONFIG_SWSCALE) += swscale
FFLIBS := avutil
-DATA_FILES := $(wildcard $(SRC_PATH)/ffpresets/*.ffpreset)
+DATA_FILES := $(wildcard $(SRC_PATH)/presets/*.ffpreset)
SKIPHEADERS = cmdutils_common_opts.h
include $(SRC_PATH)/common.mak
-FF_LDFLAGS := $(FFLDFLAGS)
FF_EXTRALIBS := $(FFEXTRALIBS)
FF_DEP_LIBS := $(DEP_LIBS)
-all: $(FF_DEP_LIBS) $(PROGS)
+all: $(PROGS)
+
+$(PROGS): %$(EXESUF): %$(PROGSSUF)_g$(EXESUF)
+ $(CP) $< $@$(PROGSSUF)
+ $(STRIP) $@$(PROGSSUF)
+
+$(TOOLS): %$(EXESUF): %.o
+ $(LD) $(LDFLAGS) -o $@ $< $(ELIBS)
+
+tools/cws2fws$(EXESUF): ELIBS = -lz
config.h: .config
.config: $(wildcard $(FFLIBS:%=$(SRC_PATH)/lib%/all*.c))
@@ -94,7 +66,7 @@ config.h: .config
SUBDIR_VARS := OBJS FFLIBS CLEANFILES DIRS TESTPROGS EXAMPLES SKIPHEADERS \
ALTIVEC-OBJS MMX-OBJS NEON-OBJS X86-OBJS YASM-OBJS-FFT YASM-OBJS \
- HOSTPROGS BUILT_HEADERS TESTOBJS ARCH_HEADERS ARMV6-OBJS
+ HOSTPROGS BUILT_HEADERS TESTOBJS ARCH_HEADERS ARMV6-OBJS TOOLS
define RESET
$(1) :=
@@ -110,23 +82,11 @@ endef
$(foreach D,$(FFLIBS),$(eval $(call DOSUBDIR,lib$(D))))
ffplay.o: CFLAGS += $(SDL_CFLAGS)
-ffplay$(EXESUF): FF_EXTRALIBS += $(SDL_LIBS)
-ffserver$(EXESUF): FF_LDFLAGS += $(FFSERVERLDFLAGS)
-
-$(PROGS): %$(EXESUF): %.o cmdutils.o $(FF_DEP_LIBS)
- $(LD) $(FF_LDFLAGS) -o $@ $< cmdutils.o $(FF_EXTRALIBS)
-
-TOOLS = cws2fws graph2dot lavfi-showfiltfmts pktdumper probetest qt-faststart trasher
-TOOLOBJS := $(TOOLS:%=tools/%.o)
-TOOLS := $(TOOLS:%=tools/%$(EXESUF))
-
-alltools: $(TOOLS)
-
-tools/%$(EXESUF): tools/%.o
- $(LD) $(FF_LDFLAGS) -o $@ $< $(FF_EXTRALIBS)
+ffplay_g$(EXESUF): FF_EXTRALIBS += $(SDL_LIBS)
+ffserver_g$(EXESUF): LDFLAGS += $(FFSERVERLDFLAGS)
-$(TOOLOBJS): %.o: %.c | tools
- $(CC) $(CPPFLAGS) $(CFLAGS) -c $(CC_O) $<
+%$(PROGSSUF)_g$(EXESUF): %.o cmdutils.o $(FF_DEP_LIBS)
+ $(LD) $(LDFLAGS) -o $@ $< cmdutils.o $(FF_EXTRALIBS)
OBJDIRS += tools
@@ -158,7 +118,7 @@ install-progs-$(CONFIG_SHARED): install-libs
install-progs: install-progs-yes $(PROGS)
$(Q)mkdir -p "$(BINDIR)"
- $(INSTALL) -c -m 755 $(PROGS) "$(BINDIR)"
+ $(INSTALL) -c -m 755 $(INSTPROGS) "$(BINDIR)"
install-data: $(DATA_FILES)
$(Q)mkdir -p "$(DATADIR)"
@@ -173,7 +133,7 @@ uninstall-data:
$(RM) -r "$(DATADIR)"
clean::
- $(RM) $(ALLPROGS)
+ $(RM) $(ALLPROGS) $(ALLPROGS_G)
$(RM) $(CLEANSUFFIXES)
$(RM) $(TOOLS)
$(RM) $(CLEANSUFFIXES:%=tools/%)
@@ -183,7 +143,7 @@ distclean::
$(RM) config.* .version version.h libavutil/avconfig.h
config:
- $(SRC_PATH)/configure $(value LIBAV_CONFIGURATION)
+ $(SRC_PATH)/configure $(value FFMPEG_CONFIGURATION)
include $(SRC_PATH)/doc/Makefile
include $(SRC_PATH)/tests/Makefile
diff --git a/README b/README
index afef671611..e907e90223 100644
--- a/README
+++ b/README
@@ -1,5 +1,5 @@
-Libav README
-------------
+FFmpeg README
+-------------
1) Documentation
----------------
diff --git a/RELEASE b/RELEASE
index eb49d7c7fd..cdaabb83b7 100644
--- a/RELEASE
+++ b/RELEASE
@@ -1 +1 @@
-0.7
+0.8.5.git
diff --git a/avconv.c b/avconv.c
new file mode 100644
index 0000000000..e8fd7eae65
--- /dev/null
+++ b/avconv.c
@@ -0,0 +1,4274 @@
+/*
+ * ffmpeg main
+ * Copyright (c) 2000-2003 Fabrice Bellard
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config.h"
+#include <ctype.h>
+#include <string.h>
+#include <math.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <signal.h>
+#include <limits.h>
+#include <unistd.h>
+#include "libavformat/avformat.h"
+#include "libavdevice/avdevice.h"
+#include "libswscale/swscale.h"
+#include "libavutil/opt.h"
+#include "libavcodec/audioconvert.h"
+#include "libavutil/audioconvert.h"
+#include "libavutil/parseutils.h"
+#include "libavutil/samplefmt.h"
+#include "libavutil/colorspace.h"
+#include "libavutil/fifo.h"
+#include "libavutil/intreadwrite.h"
+#include "libavutil/dict.h"
+#include "libavutil/mathematics.h"
+#include "libavutil/pixdesc.h"
+#include "libavutil/avstring.h"
+#include "libavutil/libm.h"
+#include "libavformat/os_support.h"
+
+#include "libavformat/ffm.h" // not public API
+
+#if CONFIG_AVFILTER
+# include "libavfilter/avcodec.h"
+# include "libavfilter/avfilter.h"
+# include "libavfilter/avfiltergraph.h"
+# include "libavfilter/buffersink.h"
+# include "libavfilter/vsrc_buffer.h"
+#endif
+
+#if HAVE_SYS_RESOURCE_H
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+#elif HAVE_GETPROCESSTIMES
+#include <windows.h>
+#endif
+#if HAVE_GETPROCESSMEMORYINFO
+#include <windows.h>
+#include <psapi.h>
+#endif
+
+#if HAVE_SYS_SELECT_H
+#include <sys/select.h>
+#endif
+
+#if HAVE_TERMIOS_H
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <sys/time.h>
+#include <termios.h>
+#elif HAVE_KBHIT
+#include <conio.h>
+#endif
+#include <time.h>
+
+#include "cmdutils.h"
+
+#include "libavutil/avassert.h"
+
+const char program_name[] = "avconv";
+const int program_birth_year = 2000;
+
+/* select an input stream for an output stream */
+typedef struct StreamMap {
+ int disabled; /** 1 is this mapping is disabled by a negative map */
+ int file_index;
+ int stream_index;
+ int sync_file_index;
+ int sync_stream_index;
+} StreamMap;
+
+/**
+ * select an input file for an output file
+ */
+typedef struct MetadataMap {
+ int file; ///< file index
+ char type; ///< type of metadata to copy -- (g)lobal, (s)tream, (c)hapter or (p)rogram
+ int index; ///< stream/chapter/program number
+} MetadataMap;
+
+static const OptionDef options[];
+
+#define MAX_STREAMS 1024 /* arbitrary sanity check value */
+
+static int frame_bits_per_raw_sample = 0;
+static int video_discard = 0;
+static int same_quant = 0;
+static int do_deinterlace = 0;
+static int intra_dc_precision = 8;
+static int qp_hist = 0;
+
+static int file_overwrite = 0;
+static int do_benchmark = 0;
+static int do_hex_dump = 0;
+static int do_pkt_dump = 0;
+static int do_pass = 0;
+static const char *pass_logfilename_prefix;
+static int video_sync_method= -1;
+static int audio_sync_method= 0;
+static float audio_drift_threshold= 0.1;
+static int copy_ts= 0;
+static int copy_tb= 0;
+static int opt_shortest = 0;
+static char *vstats_filename;
+static FILE *vstats_file;
+static int copy_initial_nonkeyframes = 0;
+
+static int audio_volume = 256;
+
+static int exit_on_error = 0;
+static int using_stdin = 0;
+static int run_as_daemon = 0;
+static int q_pressed = 0;
+static int64_t video_size = 0;
+static int64_t audio_size = 0;
+static int64_t extra_size = 0;
+static int nb_frames_dup = 0;
+static int nb_frames_drop = 0;
+static int input_sync;
+
+static float dts_delta_threshold = 10;
+
+static int print_stats = 1;
+
+static uint8_t *audio_buf;
+static uint8_t *audio_out;
+static unsigned int allocated_audio_out_size, allocated_audio_buf_size;
+
+static void *samples;
+
+#define DEFAULT_PASS_LOGFILENAME_PREFIX "av2pass"
+
+typedef struct InputStream {
+ int file_index;
+ AVStream *st;
+ int discard; /* true if stream data should be discarded */
+ int decoding_needed; /* true if the packets must be decoded in 'raw_fifo' */
+ AVCodec *dec;
+
+ int64_t start; /* time when read started */
+ int64_t next_pts; /* synthetic pts for cases where pkt.pts
+ is not defined */
+ int64_t pts; /* current pts */
+ double ts_scale;
+ int is_start; /* is 1 at the start and after a discontinuity */
+ int showed_multi_packet_warning;
+ AVDictionary *opts;
+} InputStream;
+
+typedef struct InputFile {
+ AVFormatContext *ctx;
+ int eof_reached; /* true if eof reached */
+ int ist_index; /* index of first stream in ist_table */
+ int buffer_size; /* current total buffer size */
+ int64_t ts_offset;
+ int nb_streams; /* number of stream that avconv is aware of; may be different
+ from ctx.nb_streams if new streams appear during av_read_frame() */
+ int rate_emu;
+} InputFile;
+
+typedef struct OutputStream {
+ int file_index; /* file index */
+ int index; /* stream index in the output file */
+ int source_index; /* InputStream index */
+ AVStream *st; /* stream in the output file */
+ int encoding_needed; /* true if encoding needed for this stream */
+ int frame_number;
+ /* input pts and corresponding output pts
+ for A/V sync */
+ //double sync_ipts; /* dts from the AVPacket of the demuxer in second units */
+ struct InputStream *sync_ist; /* input stream to sync against */
+ int64_t sync_opts; /* output frame counter, could be changed to some true timestamp */ //FIXME look at frame_number
+ AVBitStreamFilterContext *bitstream_filters;
+ AVCodec *enc;
+ int64_t max_frames;
+
+ /* video only */
+ int video_resample;
+ AVFrame resample_frame; /* temporary frame for image resampling */
+ struct SwsContext *img_resample_ctx; /* for image resampling */
+ int resample_height;
+ int resample_width;
+ int resample_pix_fmt;
+ AVRational frame_rate;
+ int force_fps;
+ int top_field_first;
+
+ float frame_aspect_ratio;
+
+ /* forced key frames */
+ int64_t *forced_kf_pts;
+ int forced_kf_count;
+ int forced_kf_index;
+
+ /* audio only */
+ int audio_resample;
+ ReSampleContext *resample; /* for audio resampling */
+ int resample_sample_fmt;
+ int resample_channels;
+ int resample_sample_rate;
+ int reformat_pair;
+ AVAudioConvert *reformat_ctx;
+ AVFifoBuffer *fifo; /* for compression: one audio fifo per codec */
+ FILE *logfile;
+
+#if CONFIG_AVFILTER
+ AVFilterContext *output_video_filter;
+ AVFilterContext *input_video_filter;
+ AVFilterBufferRef *picref;
+ char *avfilter;
+ AVFilterGraph *graph;
+#endif
+
+ int64_t sws_flags;
+ AVDictionary *opts;
+ int is_past_recording_time;
+} OutputStream;
+
+#if HAVE_TERMIOS_H
+
+/* init terminal so that we can grab keys */
+static struct termios oldtty;
+#endif
+
+typedef struct OutputFile {
+ AVFormatContext *ctx;
+ AVDictionary *opts;
+ int ost_index; /* index of the first stream in output_streams */
+ int64_t recording_time; /* desired length of the resulting file in microseconds */
+ int64_t start_time; /* start time in microseconds */
+ uint64_t limit_filesize;
+} OutputFile;
+
+static InputStream *input_streams = NULL;
+static int nb_input_streams = 0;
+static InputFile *input_files = NULL;
+static int nb_input_files = 0;
+
+static OutputStream *output_streams = NULL;
+static int nb_output_streams = 0;
+static OutputFile *output_files = NULL;
+static int nb_output_files = 0;
+
+typedef struct OptionsContext {
+ /* input/output options */
+ int64_t start_time;
+ const char *format;
+
+ SpecifierOpt *codec_names;
+ int nb_codec_names;
+ SpecifierOpt *audio_channels;
+ int nb_audio_channels;
+ SpecifierOpt *audio_sample_rate;
+ int nb_audio_sample_rate;
+ SpecifierOpt *frame_rates;
+ int nb_frame_rates;
+ SpecifierOpt *frame_sizes;
+ int nb_frame_sizes;
+ SpecifierOpt *frame_pix_fmts;
+ int nb_frame_pix_fmts;
+
+ /* input options */
+ int64_t input_ts_offset;
+ int rate_emu;
+
+ SpecifierOpt *ts_scale;
+ int nb_ts_scale;
+
+ /* output options */
+ StreamMap *stream_maps;
+ int nb_stream_maps;
+ /* first item specifies output metadata, second is input */
+ MetadataMap (*meta_data_maps)[2];
+ int nb_meta_data_maps;
+ int metadata_global_manual;
+ int metadata_streams_manual;
+ int metadata_chapters_manual;
+
+ int chapters_input_file;
+
+ int64_t recording_time;
+ uint64_t limit_filesize;
+ float mux_preload;
+ float mux_max_delay;
+
+ int video_disable;
+ int audio_disable;
+ int subtitle_disable;
+ int data_disable;
+
+ /* indexed by output file stream index */
+ int *streamid_map;
+ int nb_streamid_map;
+
+ SpecifierOpt *metadata;
+ int nb_metadata;
+ SpecifierOpt *max_frames;
+ int nb_max_frames;
+ SpecifierOpt *bitstream_filters;
+ int nb_bitstream_filters;
+ SpecifierOpt *codec_tags;
+ int nb_codec_tags;
+ SpecifierOpt *sample_fmts;
+ int nb_sample_fmts;
+ SpecifierOpt *qscale;
+ int nb_qscale;
+ SpecifierOpt *forced_key_frames;
+ int nb_forced_key_frames;
+ SpecifierOpt *force_fps;
+ int nb_force_fps;
+ SpecifierOpt *frame_aspect_ratios;
+ int nb_frame_aspect_ratios;
+ SpecifierOpt *rc_overrides;
+ int nb_rc_overrides;
+ SpecifierOpt *intra_matrices;
+ int nb_intra_matrices;
+ SpecifierOpt *inter_matrices;
+ int nb_inter_matrices;
+ SpecifierOpt *top_field_first;
+ int nb_top_field_first;
+ SpecifierOpt *presets;
+ int nb_presets;
+#if CONFIG_AVFILTER
+ SpecifierOpt *filters;
+ int nb_filters;
+#endif
+} OptionsContext;
+
+#define MATCH_PER_STREAM_OPT(name, type, outvar, fmtctx, st)\
+{\
+ int i, ret;\
+ for (i = 0; i < o->nb_ ## name; i++) {\
+ char *spec = o->name[i].specifier;\
+ if ((ret = check_stream_specifier(fmtctx, st, spec)) > 0)\
+ outvar = o->name[i].u.type;\
+ else if (ret < 0)\
+ exit_program(1);\
+ }\
+}
+
+static void reset_options(OptionsContext *o)
+{
+ const OptionDef *po = options;
+
+ /* all OPT_SPEC and OPT_STRING can be freed in generic way */
+ while (po->name) {
+ void *dst = (uint8_t*)o + po->u.off;
+
+ if (po->flags & OPT_SPEC) {
+ SpecifierOpt **so = dst;
+ int i, *count = (int*)(so + 1);
+ for (i = 0; i < *count; i++) {
+ av_freep(&(*so)[i].specifier);
+ if (po->flags & OPT_STRING)
+ av_freep(&(*so)[i].u.str);
+ }
+ av_freep(so);
+ *count = 0;
+ } else if (po->flags & OPT_OFFSET && po->flags & OPT_STRING)
+ av_freep(dst);
+ po++;
+ }
+
+ av_freep(&o->stream_maps);
+ av_freep(&o->meta_data_maps);
+ av_freep(&o->streamid_map);
+
+ memset(o, 0, sizeof(*o));
+
+ o->mux_preload = 0.5;
+ o->mux_max_delay = 0.7;
+ o->recording_time = INT64_MAX;
+ o->limit_filesize = UINT64_MAX;
+ o->chapters_input_file = INT_MAX;
+
+ uninit_opts();
+ init_opts();
+}
+
+#if CONFIG_AVFILTER
+
+static int configure_video_filters(InputStream *ist, OutputStream *ost)
+{
+ AVFilterContext *last_filter, *filter;
+ /** filter graph containing all filters including input & output */
+ AVCodecContext *codec = ost->st->codec;
+ AVCodecContext *icodec = ist->st->codec;
+ enum PixelFormat pix_fmts[] = { codec->pix_fmt, PIX_FMT_NONE };
+ AVBufferSinkParams *buffersink_params = av_buffersink_params_alloc();
+ AVRational sample_aspect_ratio;
+ char args[255];
+ int ret;
+
+ ost->graph = avfilter_graph_alloc();
+
+ if (ist->st->sample_aspect_ratio.num){
+ sample_aspect_ratio = ist->st->sample_aspect_ratio;
+ }else
+ sample_aspect_ratio = ist->st->codec->sample_aspect_ratio;
+
+ snprintf(args, 255, "%d:%d:%d:%d:%d:%d:%d", ist->st->codec->width,
+ ist->st->codec->height, ist->st->codec->pix_fmt, 1, AV_TIME_BASE,
+ sample_aspect_ratio.num, sample_aspect_ratio.den);
+
+ ret = avfilter_graph_create_filter(&ost->input_video_filter, avfilter_get_by_name("buffer"),
+ "src", args, NULL, ost->graph);
+ if (ret < 0)
+ return ret;
+#if FF_API_OLD_VSINK_API
+ ret = avfilter_graph_create_filter(&ost->output_video_filter, avfilter_get_by_name("buffersink"),
+ "out", NULL, pix_fmts, ost->graph);
+#else
+ buffersink_params->pixel_fmts = pix_fmts;
+ ret = avfilter_graph_create_filter(&ost->output_video_filter, avfilter_get_by_name("buffersink"),
+ "out", NULL, buffersink_params, ost->graph);
+#endif
+ av_freep(&buffersink_params);
+ if (ret < 0)
+ return ret;
+ last_filter = ost->input_video_filter;
+
+ if (codec->width != icodec->width || codec->height != icodec->height) {
+ snprintf(args, 255, "%d:%d:flags=0x%X",
+ codec->width,
+ codec->height,
+ (unsigned)ost->sws_flags);
+ if ((ret = avfilter_graph_create_filter(&filter, avfilter_get_by_name("scale"),
+ NULL, args, NULL, ost->graph)) < 0)
+ return ret;
+ if ((ret = avfilter_link(last_filter, 0, filter, 0)) < 0)
+ return ret;
+ last_filter = filter;
+ }
+
+ snprintf(args, sizeof(args), "flags=0x%X", (unsigned)ost->sws_flags);
+ ost->graph->scale_sws_opts = av_strdup(args);
+
+ if (ost->avfilter) {
+ AVFilterInOut *outputs = avfilter_inout_alloc();
+ AVFilterInOut *inputs = avfilter_inout_alloc();
+
+ outputs->name = av_strdup("in");
+ outputs->filter_ctx = last_filter;
+ outputs->pad_idx = 0;
+ outputs->next = NULL;
+
+ inputs->name = av_strdup("out");
+ inputs->filter_ctx = ost->output_video_filter;
+ inputs->pad_idx = 0;
+ inputs->next = NULL;
+
+ if ((ret = avfilter_graph_parse(ost->graph, ost->avfilter, &inputs, &outputs, NULL)) < 0)
+ return ret;
+ av_freep(&ost->avfilter);
+ } else {
+ if ((ret = avfilter_link(last_filter, 0, ost->output_video_filter, 0)) < 0)
+ return ret;
+ }
+
+ if ((ret = avfilter_graph_config(ost->graph, NULL)) < 0)
+ return ret;
+
+ codec->width = ost->output_video_filter->inputs[0]->w;
+ codec->height = ost->output_video_filter->inputs[0]->h;
+ codec->sample_aspect_ratio = ost->st->sample_aspect_ratio =
+ ost->frame_aspect_ratio ? // overridden by the -aspect cli option
+ av_d2q(ost->frame_aspect_ratio*codec->height/codec->width, 255) :
+ ost->output_video_filter->inputs[0]->sample_aspect_ratio;
+
+ return 0;
+}
+#endif /* CONFIG_AVFILTER */
+
+static void term_exit(void)
+{
+ av_log(NULL, AV_LOG_QUIET, "%s", "");
+#if HAVE_TERMIOS_H
+ if(!run_as_daemon)
+ tcsetattr (0, TCSANOW, &oldtty);
+#endif
+}
+
+static volatile int received_sigterm = 0;
+
+static void
+sigterm_handler(int sig)
+{
+ received_sigterm = sig;
+ q_pressed++;
+ term_exit();
+}
+
+static void term_init(void)
+{
+#if HAVE_TERMIOS_H
+ if(!run_as_daemon){
+ struct termios tty;
+
+ tcgetattr (0, &tty);
+ oldtty = tty;
+ atexit(term_exit);
+
+ tty.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP
+ |INLCR|IGNCR|ICRNL|IXON);
+ tty.c_oflag |= OPOST;
+ tty.c_lflag &= ~(ECHO|ECHONL|ICANON|IEXTEN);
+ tty.c_cflag &= ~(CSIZE|PARENB);
+ tty.c_cflag |= CS8;
+ tty.c_cc[VMIN] = 1;
+ tty.c_cc[VTIME] = 0;
+
+ tcsetattr (0, TCSANOW, &tty);
+ signal(SIGQUIT, sigterm_handler); /* Quit (POSIX). */
+ }
+#endif
+
+ signal(SIGINT , sigterm_handler); /* Interrupt (ANSI). */
+ signal(SIGTERM, sigterm_handler); /* Termination (ANSI). */
+#ifdef SIGXCPU
+ signal(SIGXCPU, sigterm_handler);
+#endif
+}
+
+/* read a key without blocking */
+static int read_key(void)
+{
+#if HAVE_TERMIOS_H
+ int n = 1;
+ unsigned char ch;
+ struct timeval tv;
+ fd_set rfds;
+
+ if(run_as_daemon)
+ return -1;
+
+ FD_ZERO(&rfds);
+ FD_SET(0, &rfds);
+ tv.tv_sec = 0;
+ tv.tv_usec = 0;
+ n = select(1, &rfds, NULL, NULL, &tv);
+ if (n > 0) {
+ n = read(0, &ch, 1);
+ if (n == 1)
+ return ch;
+
+ return n;
+ }
+#elif HAVE_KBHIT
+ if(kbhit())
+ return(getch());
+#endif
+ return -1;
+}
+
+static int decode_interrupt_cb(void)
+{
+ q_pressed += read_key() == 'q';
+ return q_pressed > 1;
+}
+
+void exit_program(int ret)
+{
+ int i;
+
+ /* close files */
+ for(i=0;i<nb_output_files;i++) {
+ AVFormatContext *s = output_files[i].ctx;
+ if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb)
+ avio_close(s->pb);
+ avformat_free_context(s);
+ av_dict_free(&output_files[i].opts);
+ }
+ for(i=0;i<nb_input_files;i++) {
+ av_close_input_file(input_files[i].ctx);
+ }
+ for (i = 0; i < nb_input_streams; i++)
+ av_dict_free(&input_streams[i].opts);
+
+ if (vstats_file)
+ fclose(vstats_file);
+ av_free(vstats_filename);
+
+ av_freep(&input_streams);
+ av_freep(&input_files);
+ av_freep(&output_streams);
+ av_freep(&output_files);
+
+ uninit_opts();
+ av_free(audio_buf);
+ av_free(audio_out);
+ allocated_audio_buf_size= allocated_audio_out_size= 0;
+ av_free(samples);
+
+#if CONFIG_AVFILTER
+ avfilter_uninit();
+#endif
+
+ if (received_sigterm) {
+ av_log(NULL, AV_LOG_INFO, "Received signal %d: terminating.\n",
+ (int) received_sigterm);
+ exit (255);
+ }
+
+ exit(ret); /* not all OS-es handle main() return value */
+}
+
+static void assert_avoptions(AVDictionary *m)
+{
+ AVDictionaryEntry *t;
+ if ((t = av_dict_get(m, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
+ av_log(NULL, AV_LOG_FATAL, "Option %s not found.\n", t->key);
+ exit_program(1);
+ }
+}
+
+static void assert_codec_experimental(AVCodecContext *c, int encoder)
+{
+ const char *codec_string = encoder ? "encoder" : "decoder";
+ AVCodec *codec;
+ if (c->codec->capabilities & CODEC_CAP_EXPERIMENTAL &&
+ c->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) {
+ av_log(NULL, AV_LOG_FATAL, "%s '%s' is experimental and might produce bad "
+ "results.\nAdd '-strict experimental' if you want to use it.\n",
+ codec_string, c->codec->name);
+ codec = encoder ? avcodec_find_encoder(c->codec->id) : avcodec_find_decoder(c->codec->id);
+ if (!(codec->capabilities & CODEC_CAP_EXPERIMENTAL))
+ av_log(NULL, AV_LOG_FATAL, "Or use the non experimental %s '%s'.\n",
+ codec_string, codec->name);
+ exit_program(1);
+ }
+}
+
+static void choose_sample_fmt(AVStream *st, AVCodec *codec)
+{
+ if(codec && codec->sample_fmts){
+ const enum AVSampleFormat *p= codec->sample_fmts;
+ for(; *p!=-1; p++){
+ if(*p == st->codec->sample_fmt)
+ break;
+ }
+ if (*p == -1) {
+ if((codec->capabilities & CODEC_CAP_LOSSLESS) && av_get_sample_fmt_name(st->codec->sample_fmt) > av_get_sample_fmt_name(codec->sample_fmts[0]))
+ av_log(NULL, AV_LOG_ERROR, "Convertion will not be lossless'\n");
+ if(av_get_sample_fmt_name(st->codec->sample_fmt))
+ av_log(NULL, AV_LOG_WARNING,
+ "Incompatible sample format '%s' for codec '%s', auto-selecting format '%s'\n",
+ av_get_sample_fmt_name(st->codec->sample_fmt),
+ codec->name,
+ av_get_sample_fmt_name(codec->sample_fmts[0]));
+ st->codec->sample_fmt = codec->sample_fmts[0];
+ }
+ }
+}
+
+static void choose_sample_rate(AVStream *st, AVCodec *codec)
+{
+ if(codec && codec->supported_samplerates){
+ const int *p= codec->supported_samplerates;
+ int best=0;
+ int best_dist=INT_MAX;
+ for(; *p; p++){
+ int dist= abs(st->codec->sample_rate - *p);
+ if(dist < best_dist){
+ best_dist= dist;
+ best= *p;
+ }
+ }
+ if(best_dist){
+ av_log(st->codec, AV_LOG_WARNING, "Requested sampling rate unsupported using closest supported (%d)\n", best);
+ }
+ st->codec->sample_rate= best;
+ }
+}
+
+static void choose_pixel_fmt(AVStream *st, AVCodec *codec)
+{
+ if(codec && codec->pix_fmts){
+ const enum PixelFormat *p= codec->pix_fmts;
+ if(st->codec->strict_std_compliance <= FF_COMPLIANCE_UNOFFICIAL){
+ if(st->codec->codec_id==CODEC_ID_MJPEG){
+ p= (const enum PixelFormat[]){PIX_FMT_YUVJ420P, PIX_FMT_YUVJ422P, PIX_FMT_YUV420P, PIX_FMT_YUV422P, PIX_FMT_NONE};
+ }else if(st->codec->codec_id==CODEC_ID_LJPEG){
+ p= (const enum PixelFormat[]){PIX_FMT_YUVJ420P, PIX_FMT_YUVJ422P, PIX_FMT_YUVJ444P, PIX_FMT_YUV420P, PIX_FMT_YUV422P, PIX_FMT_YUV444P, PIX_FMT_BGRA, PIX_FMT_NONE};
+ }
+ }
+ for(; *p!=-1; p++){
+ if(*p == st->codec->pix_fmt)
+ break;
+ }
+ if (*p == -1) {
+ if(st->codec->pix_fmt != PIX_FMT_NONE)
+ av_log(NULL, AV_LOG_WARNING,
+ "Incompatible pixel format '%s' for codec '%s', auto-selecting format '%s'\n",
+ av_pix_fmt_descriptors[st->codec->pix_fmt].name,
+ codec->name,
+ av_pix_fmt_descriptors[codec->pix_fmts[0]].name);
+ st->codec->pix_fmt = codec->pix_fmts[0];
+ }
+ }
+}
+
+static double
+get_sync_ipts(const OutputStream *ost)
+{
+ const InputStream *ist = ost->sync_ist;
+ OutputFile *of = &output_files[ost->file_index];
+ return (double)(ist->pts - of->start_time)/AV_TIME_BASE;
+}
+
+static void write_frame(AVFormatContext *s, AVPacket *pkt, AVCodecContext *avctx, AVBitStreamFilterContext *bsfc){
+ int ret;
+
+ while(bsfc){
+ AVPacket new_pkt= *pkt;
+ int a= av_bitstream_filter_filter(bsfc, avctx, NULL,
+ &new_pkt.data, &new_pkt.size,
+ pkt->data, pkt->size,
+ pkt->flags & AV_PKT_FLAG_KEY);
+ if(a>0){
+ av_free_packet(pkt);
+ new_pkt.destruct= av_destruct_packet;
+ } else if(a<0){
+ av_log(NULL, AV_LOG_ERROR, "%s failed for stream %d, codec %s",
+ bsfc->filter->name, pkt->stream_index,
+ avctx->codec ? avctx->codec->name : "copy");
+ print_error("", a);
+ if (exit_on_error)
+ exit_program(1);
+ }
+ *pkt= new_pkt;
+
+ bsfc= bsfc->next;
+ }
+
+ ret= av_interleaved_write_frame(s, pkt);
+ if(ret < 0){
+ print_error("av_interleaved_write_frame()", ret);
+ exit_program(1);
+ }
+}
+
+static void do_audio_out(AVFormatContext *s,
+ OutputStream *ost,
+ InputStream *ist,
+ unsigned char *buf, int size)
+{
+ uint8_t *buftmp;
+ int64_t audio_out_size, audio_buf_size;
+ int64_t allocated_for_size= size;
+
+ int size_out, frame_bytes, ret, resample_changed;
+ AVCodecContext *enc= ost->st->codec;
+ AVCodecContext *dec= ist->st->codec;
+ int osize = av_get_bytes_per_sample(enc->sample_fmt);
+ int isize = av_get_bytes_per_sample(dec->sample_fmt);
+ const int coded_bps = av_get_bits_per_sample(enc->codec->id);
+
+need_realloc:
+ audio_buf_size= (allocated_for_size + isize*dec->channels - 1) / (isize*dec->channels);
+ audio_buf_size= (audio_buf_size*enc->sample_rate + dec->sample_rate) / dec->sample_rate;
+ audio_buf_size= audio_buf_size*2 + 10000; //safety factors for the deprecated resampling API
+ audio_buf_size= FFMAX(audio_buf_size, enc->frame_size);
+ audio_buf_size*= osize*enc->channels;
+
+ audio_out_size= FFMAX(audio_buf_size, enc->frame_size * osize * enc->channels);
+ if(coded_bps > 8*osize)
+ audio_out_size= audio_out_size * coded_bps / (8*osize);
+ audio_out_size += FF_MIN_BUFFER_SIZE;
+
+ if(audio_out_size > INT_MAX || audio_buf_size > INT_MAX){
+ av_log(NULL, AV_LOG_FATAL, "Buffer sizes too large\n");
+ exit_program(1);
+ }
+
+ av_fast_malloc(&audio_buf, &allocated_audio_buf_size, audio_buf_size);
+ av_fast_malloc(&audio_out, &allocated_audio_out_size, audio_out_size);
+ if (!audio_buf || !audio_out){
+ av_log(NULL, AV_LOG_FATAL, "Out of memory in do_audio_out\n");
+ exit_program(1);
+ }
+
+ if (enc->channels != dec->channels)
+ ost->audio_resample = 1;
+
+ resample_changed = ost->resample_sample_fmt != dec->sample_fmt ||
+ ost->resample_channels != dec->channels ||
+ ost->resample_sample_rate != dec->sample_rate;
+
+ if ((ost->audio_resample && !ost->resample) || resample_changed) {
+ if (resample_changed) {
+ av_log(NULL, AV_LOG_INFO, "Input stream #%d.%d frame changed from rate:%d fmt:%s ch:%d to rate:%d fmt:%s ch:%d\n",
+ ist->file_index, ist->st->index,
+ ost->resample_sample_rate, av_get_sample_fmt_name(ost->resample_sample_fmt), ost->resample_channels,
+ dec->sample_rate, av_get_sample_fmt_name(dec->sample_fmt), dec->channels);
+ ost->resample_sample_fmt = dec->sample_fmt;
+ ost->resample_channels = dec->channels;
+ ost->resample_sample_rate = dec->sample_rate;
+ if (ost->resample)
+ audio_resample_close(ost->resample);
+ }
+ /* if audio_sync_method is >1 the resampler is needed for audio drift compensation */
+ if (audio_sync_method <= 1 &&
+ ost->resample_sample_fmt == enc->sample_fmt &&
+ ost->resample_channels == enc->channels &&
+ ost->resample_sample_rate == enc->sample_rate) {
+ ost->resample = NULL;
+ ost->audio_resample = 0;
+ } else {
+ if (dec->sample_fmt != AV_SAMPLE_FMT_S16)
+ av_log(NULL, AV_LOG_WARNING, "Using s16 intermediate sample format for resampling\n");
+ ost->resample = av_audio_resample_init(enc->channels, dec->channels,
+ enc->sample_rate, dec->sample_rate,
+ enc->sample_fmt, dec->sample_fmt,
+ 16, 10, 0, 0.8);
+ if (!ost->resample) {
+ av_log(NULL, AV_LOG_FATAL, "Can not resample %d channels @ %d Hz to %d channels @ %d Hz\n",
+ dec->channels, dec->sample_rate,
+ enc->channels, enc->sample_rate);
+ exit_program(1);
+ }
+ }
+ }
+
+#define MAKE_SFMT_PAIR(a,b) ((a)+AV_SAMPLE_FMT_NB*(b))
+ if (!ost->audio_resample && dec->sample_fmt!=enc->sample_fmt &&
+ MAKE_SFMT_PAIR(enc->sample_fmt,dec->sample_fmt)!=ost->reformat_pair) {
+ if (ost->reformat_ctx)
+ av_audio_convert_free(ost->reformat_ctx);
+ ost->reformat_ctx = av_audio_convert_alloc(enc->sample_fmt, 1,
+ dec->sample_fmt, 1, NULL, 0);
+ if (!ost->reformat_ctx) {
+ av_log(NULL, AV_LOG_FATAL, "Cannot convert %s sample format to %s sample format\n",
+ av_get_sample_fmt_name(dec->sample_fmt),
+ av_get_sample_fmt_name(enc->sample_fmt));
+ exit_program(1);
+ }
+ ost->reformat_pair=MAKE_SFMT_PAIR(enc->sample_fmt,dec->sample_fmt);
+ }
+
+ if(audio_sync_method){
+ double delta = get_sync_ipts(ost) * enc->sample_rate - ost->sync_opts
+ - av_fifo_size(ost->fifo)/(enc->channels * 2);
+ double idelta= delta*dec->sample_rate / enc->sample_rate;
+ int byte_delta= ((int)idelta)*2*dec->channels;
+
+ //FIXME resample delay
+ if(fabs(delta) > 50){
+ if(ist->is_start || fabs(delta) > audio_drift_threshold*enc->sample_rate){
+ if(byte_delta < 0){
+ byte_delta= FFMAX(byte_delta, -size);
+ size += byte_delta;
+ buf -= byte_delta;
+ av_log(NULL, AV_LOG_VERBOSE, "discarding %d audio samples\n", (int)-delta);
+ if(!size)
+ return;
+ ist->is_start=0;
+ }else{
+ static uint8_t *input_tmp= NULL;
+ input_tmp= av_realloc(input_tmp, byte_delta + size);
+
+ if(byte_delta > allocated_for_size - size){
+ allocated_for_size= byte_delta + (int64_t)size;
+ goto need_realloc;
+ }
+ ist->is_start=0;
+
+ memset(input_tmp, 0, byte_delta);
+ memcpy(input_tmp + byte_delta, buf, size);
+ buf= input_tmp;
+ size += byte_delta;
+ av_log(NULL, AV_LOG_VERBOSE, "adding %d audio samples of silence\n", (int)delta);
+ }
+ }else if(audio_sync_method>1){
+ int comp= av_clip(delta, -audio_sync_method, audio_sync_method);
+ av_assert0(ost->audio_resample);
+ av_log(NULL, AV_LOG_VERBOSE, "compensating audio timestamp drift:%f compensation:%d in:%d\n",
+ delta, comp, enc->sample_rate);
+// fprintf(stderr, "drift:%f len:%d opts:%"PRId64" ipts:%"PRId64" fifo:%d\n", delta, -1, ost->sync_opts, (int64_t)(get_sync_ipts(ost) * enc->sample_rate), av_fifo_size(ost->fifo)/(ost->st->codec->channels * 2));
+ av_resample_compensate(*(struct AVResampleContext**)ost->resample, comp, enc->sample_rate);
+ }
+ }
+ }else
+ ost->sync_opts= lrintf(get_sync_ipts(ost) * enc->sample_rate)
+ - av_fifo_size(ost->fifo)/(enc->channels * 2); //FIXME wrong
+
+ if (ost->audio_resample) {
+ buftmp = audio_buf;
+ size_out = audio_resample(ost->resample,
+ (short *)buftmp, (short *)buf,
+ size / (dec->channels * isize));
+ size_out = size_out * enc->channels * osize;
+ } else {
+ buftmp = buf;
+ size_out = size;
+ }
+
+ if (!ost->audio_resample && dec->sample_fmt!=enc->sample_fmt) {
+ const void *ibuf[6]= {buftmp};
+ void *obuf[6]= {audio_buf};
+ int istride[6]= {isize};
+ int ostride[6]= {osize};
+ int len= size_out/istride[0];
+ if (av_audio_convert(ost->reformat_ctx, obuf, ostride, ibuf, istride, len)<0) {
+ printf("av_audio_convert() failed\n");
+ if (exit_on_error)
+ exit_program(1);
+ return;
+ }
+ buftmp = audio_buf;
+ size_out = len*osize;
+ }
+
+ /* now encode as many frames as possible */
+ if (enc->frame_size > 1) {
+ /* output resampled raw samples */
+ if (av_fifo_realloc2(ost->fifo, av_fifo_size(ost->fifo) + size_out) < 0) {
+ av_log(NULL, AV_LOG_FATAL, "av_fifo_realloc2() failed\n");
+ exit_program(1);
+ }
+ av_fifo_generic_write(ost->fifo, buftmp, size_out, NULL);
+
+ frame_bytes = enc->frame_size * osize * enc->channels;
+
+ while (av_fifo_size(ost->fifo) >= frame_bytes) {
+ AVPacket pkt;
+ av_init_packet(&pkt);
+
+ av_fifo_generic_read(ost->fifo, audio_buf, frame_bytes, NULL);
+
+ //FIXME pass ost->sync_opts as AVFrame.pts in avcodec_encode_audio()
+
+ ret = avcodec_encode_audio(enc, audio_out, audio_out_size,
+ (short *)audio_buf);
+ if (ret < 0) {
+ av_log(NULL, AV_LOG_FATAL, "Audio encoding failed\n");
+ exit_program(1);
+ }
+ audio_size += ret;
+ pkt.stream_index= ost->index;
+ pkt.data= audio_out;
+ pkt.size= ret;
+ if(enc->coded_frame && enc->coded_frame->pts != AV_NOPTS_VALUE)
+ pkt.pts= av_rescale_q(enc->coded_frame->pts, enc->time_base, ost->st->time_base);
+ pkt.flags |= AV_PKT_FLAG_KEY;
+ write_frame(s, &pkt, enc, ost->bitstream_filters);
+
+ ost->sync_opts += enc->frame_size;
+ }
+ } else {
+ AVPacket pkt;
+ av_init_packet(&pkt);
+
+ ost->sync_opts += size_out / (osize * enc->channels);
+
+ /* output a pcm frame */
+ /* determine the size of the coded buffer */
+ size_out /= osize;
+ if (coded_bps)
+ size_out = size_out*coded_bps/8;
+
+ if(size_out > audio_out_size){
+ av_log(NULL, AV_LOG_FATAL, "Internal error, buffer size too small\n");
+ exit_program(1);
+ }
+
+ //FIXME pass ost->sync_opts as AVFrame.pts in avcodec_encode_audio()
+ ret = avcodec_encode_audio(enc, audio_out, size_out,
+ (short *)buftmp);
+ if (ret < 0) {
+ av_log(NULL, AV_LOG_FATAL, "Audio encoding failed\n");
+ exit_program(1);
+ }
+ audio_size += ret;
+ pkt.stream_index= ost->index;
+ pkt.data= audio_out;
+ pkt.size= ret;
+ if(enc->coded_frame && enc->coded_frame->pts != AV_NOPTS_VALUE)
+ pkt.pts= av_rescale_q(enc->coded_frame->pts, enc->time_base, ost->st->time_base);
+ pkt.flags |= AV_PKT_FLAG_KEY;
+ write_frame(s, &pkt, enc, ost->bitstream_filters);
+ }
+}
+
+static void pre_process_video_frame(InputStream *ist, AVPicture *picture, void **bufp)
+{
+ AVCodecContext *dec;
+ AVPicture *picture2;
+ AVPicture picture_tmp;
+ uint8_t *buf = 0;
+
+ dec = ist->st->codec;
+
+ /* deinterlace : must be done before any resize */
+ if (do_deinterlace) {
+ int size;
+
+ /* create temporary picture */
+ size = avpicture_get_size(dec->pix_fmt, dec->width, dec->height);
+ buf = av_malloc(size);
+ if (!buf)
+ return;
+
+ picture2 = &picture_tmp;
+ avpicture_fill(picture2, buf, dec->pix_fmt, dec->width, dec->height);
+
+ if(avpicture_deinterlace(picture2, picture,
+ dec->pix_fmt, dec->width, dec->height) < 0) {
+ /* if error, do not deinterlace */
+ av_log(NULL, AV_LOG_WARNING, "Deinterlacing failed\n");
+ av_free(buf);
+ buf = NULL;
+ picture2 = picture;
+ }
+ } else {
+ picture2 = picture;
+ }
+
+ if (picture != picture2)
+ *picture = *picture2;
+ *bufp = buf;
+}
+
+static void do_subtitle_out(AVFormatContext *s,
+ OutputStream *ost,
+ InputStream *ist,
+ AVSubtitle *sub,
+ int64_t pts)
+{
+ static uint8_t *subtitle_out = NULL;
+ int subtitle_out_max_size = 1024 * 1024;
+ int subtitle_out_size, nb, i;
+ AVCodecContext *enc;
+ AVPacket pkt;
+
+ if (pts == AV_NOPTS_VALUE) {
+ av_log(NULL, AV_LOG_ERROR, "Subtitle packets must have a pts\n");
+ if (exit_on_error)
+ exit_program(1);
+ return;
+ }
+
+ enc = ost->st->codec;
+
+ if (!subtitle_out) {
+ subtitle_out = av_malloc(subtitle_out_max_size);
+ }
+
+ /* Note: DVB subtitle need one packet to draw them and one other
+ packet to clear them */
+ /* XXX: signal it in the codec context ? */
+ if (enc->codec_id == CODEC_ID_DVB_SUBTITLE)
+ nb = 2;
+ else
+ nb = 1;
+
+ for(i = 0; i < nb; i++) {
+ sub->pts = av_rescale_q(pts, ist->st->time_base, AV_TIME_BASE_Q);
+ // start_display_time is required to be 0
+ sub->pts += av_rescale_q(sub->start_display_time, (AVRational){1, 1000}, AV_TIME_BASE_Q);
+ sub->end_display_time -= sub->start_display_time;
+ sub->start_display_time = 0;
+ subtitle_out_size = avcodec_encode_subtitle(enc, subtitle_out,
+ subtitle_out_max_size, sub);
+ if (subtitle_out_size < 0) {
+ av_log(NULL, AV_LOG_FATAL, "Subtitle encoding failed\n");
+ exit_program(1);
+ }
+
+ av_init_packet(&pkt);
+ pkt.stream_index = ost->index;
+ pkt.data = subtitle_out;
+ pkt.size = subtitle_out_size;
+ pkt.pts = av_rescale_q(sub->pts, AV_TIME_BASE_Q, ost->st->time_base);
+ if (enc->codec_id == CODEC_ID_DVB_SUBTITLE) {
+ /* XXX: the pts correction is handled here. Maybe handling
+ it in the codec would be better */
+ if (i == 0)
+ pkt.pts += 90 * sub->start_display_time;
+ else
+ pkt.pts += 90 * sub->end_display_time;
+ }
+ write_frame(s, &pkt, ost->st->codec, ost->bitstream_filters);
+ }
+}
+
+static int bit_buffer_size= 1024*256;
+static uint8_t *bit_buffer= NULL;
+
+static void do_video_resample(OutputStream *ost,
+ InputStream *ist,
+ AVFrame *in_picture,
+ AVFrame **out_picture)
+{
+ int resample_changed = 0;
+ AVCodecContext *dec = ist->st->codec;
+ AVCodecContext *enc = ost->st->codec;
+ *out_picture = in_picture;
+
+ resample_changed = ost->resample_width != dec->width ||
+ ost->resample_height != dec->height ||
+ ost->resample_pix_fmt != dec->pix_fmt;
+
+#if !CONFIG_AVFILTER
+ if (resample_changed) {
+ av_log(NULL, AV_LOG_INFO,
+ "Input stream #%d.%d frame changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s\n",
+ ist->file_index, ist->st->index,
+ ost->resample_width, ost->resample_height, av_get_pix_fmt_name(ost->resample_pix_fmt),
+ dec->width , dec->height , av_get_pix_fmt_name(dec->pix_fmt));
+ ost->resample_width = dec->width;
+ ost->resample_height = dec->height;
+ ost->resample_pix_fmt = dec->pix_fmt;
+ }
+
+ ost->video_resample = dec->width != enc->width ||
+ dec->height != enc->height ||
+ dec->pix_fmt != enc->pix_fmt;
+
+ if (ost->video_resample) {
+ *out_picture = &ost->resample_frame;
+ if (!ost->img_resample_ctx || resample_changed) {
+ /* initialize the destination picture */
+ if (!ost->resample_frame.data[0]) {
+ avcodec_get_frame_defaults(&ost->resample_frame);
+ if (avpicture_alloc((AVPicture *)&ost->resample_frame, enc->pix_fmt,
+ enc->width, enc->height)) {
+ fprintf(stderr, "Cannot allocate temp picture, check pix fmt\n");
+ exit_program(1);
+ }
+ }
+ /* initialize a new scaler context */
+ sws_freeContext(ost->img_resample_ctx);
+ ost->img_resample_ctx = sws_getContext(dec->width, dec->height, dec->pix_fmt,
+ enc->width, enc->height, enc->pix_fmt,
+ ost->sws_flags, NULL, NULL, NULL);
+ if (ost->img_resample_ctx == NULL) {
+ av_log(NULL, AV_LOG_FATAL, "Cannot get resampling context\n");
+ exit_program(1);
+ }
+ }
+ sws_scale(ost->img_resample_ctx, in_picture->data, in_picture->linesize,
+ 0, ost->resample_height, (*out_picture)->data, (*out_picture)->linesize);
+ }
+#else
+ if (resample_changed) {
+ avfilter_graph_free(&ost->graph);
+ if (configure_video_filters(ist, ost)) {
+ av_log(NULL, AV_LOG_FATAL, "Error reinitializing filters!\n");
+ exit_program(1);
+ }
+ }
+#endif
+ if (resample_changed) {
+ ost->resample_width = dec->width;
+ ost->resample_height = dec->height;
+ ost->resample_pix_fmt = dec->pix_fmt;
+ }
+}
+
+
+static void do_video_out(AVFormatContext *s,
+ OutputStream *ost,
+ InputStream *ist,
+ AVFrame *in_picture,
+ int *frame_size, float quality)
+{
+ int nb_frames, i, ret, format_video_sync;
+ AVFrame *final_picture;
+ AVCodecContext *enc;
+ double sync_ipts;
+
+ enc = ost->st->codec;
+
+ sync_ipts = get_sync_ipts(ost) / av_q2d(enc->time_base);
+
+ /* by default, we output a single frame */
+ nb_frames = 1;
+
+ *frame_size = 0;
+
+ format_video_sync = video_sync_method;
+ if (format_video_sync < 0)
+ format_video_sync = (s->oformat->flags & AVFMT_VARIABLE_FPS) ? 2 : 1;
+
+ if (format_video_sync) {
+ double vdelta = sync_ipts - ost->sync_opts;
+ //FIXME set to 0.5 after we fix some dts/pts bugs like in avidec.c
+ if (vdelta < -1.1)
+ nb_frames = 0;
+ else if (format_video_sync == 2) {
+ if(vdelta<=-0.6){
+ nb_frames=0;
+ }else if(vdelta>0.6)
+ ost->sync_opts= lrintf(sync_ipts);
+ }else if (vdelta > 1.1)
+ nb_frames = lrintf(vdelta);
+//fprintf(stderr, "vdelta:%f, ost->sync_opts:%"PRId64", ost->sync_ipts:%f nb_frames:%d\n", vdelta, ost->sync_opts, get_sync_ipts(ost), nb_frames);
+ if (nb_frames == 0){
+ ++nb_frames_drop;
+ av_log(NULL, AV_LOG_VERBOSE, "*** drop!\n");
+ }else if (nb_frames > 1) {
+ nb_frames_dup += nb_frames - 1;
+ av_log(NULL, AV_LOG_VERBOSE, "*** %d dup!\n", nb_frames-1);
+ }
+ }else
+ ost->sync_opts= lrintf(sync_ipts);
+
+ nb_frames = FFMIN(nb_frames, ost->max_frames - ost->frame_number);
+ if (nb_frames <= 0)
+ return;
+
+ do_video_resample(ost, ist, in_picture, &final_picture);
+
+ /* duplicates frame if needed */
+ for(i=0;i<nb_frames;i++) {
+ AVPacket pkt;
+ av_init_packet(&pkt);
+ pkt.stream_index= ost->index;
+
+ if (s->oformat->flags & AVFMT_RAWPICTURE) {
+ /* raw pictures are written as AVPicture structure to
+ avoid any copies. We support temporarily the older
+ method. */
+ enc->coded_frame->interlaced_frame = in_picture->interlaced_frame;
+ enc->coded_frame->top_field_first = in_picture->top_field_first;
+ pkt.data= (uint8_t *)final_picture;
+ pkt.size= sizeof(AVPicture);
+ pkt.pts= av_rescale_q(ost->sync_opts, enc->time_base, ost->st->time_base);
+ pkt.flags |= AV_PKT_FLAG_KEY;
+
+ write_frame(s, &pkt, ost->st->codec, ost->bitstream_filters);
+ } else {
+ AVFrame big_picture;
+
+ big_picture= *final_picture;
+ /* better than nothing: use input picture interlaced
+ settings */
+ big_picture.interlaced_frame = in_picture->interlaced_frame;
+ if (ost->st->codec->flags & (CODEC_FLAG_INTERLACED_DCT|CODEC_FLAG_INTERLACED_ME)) {
+ if (ost->top_field_first == -1)
+ big_picture.top_field_first = in_picture->top_field_first;
+ else
+ big_picture.top_field_first = !!ost->top_field_first;
+ }
+
+ /* handles same_quant here. This is not correct because it may
+ not be a global option */
+ big_picture.quality = quality;
+ if (!enc->me_threshold)
+ big_picture.pict_type = 0;
+// big_picture.pts = AV_NOPTS_VALUE;
+ big_picture.pts= ost->sync_opts;
+// big_picture.pts= av_rescale(ost->sync_opts, AV_TIME_BASE*(int64_t)enc->time_base.num, enc->time_base.den);
+//av_log(NULL, AV_LOG_DEBUG, "%"PRId64" -> encoder\n", ost->sync_opts);
+ if (ost->forced_kf_index < ost->forced_kf_count &&
+ big_picture.pts >= ost->forced_kf_pts[ost->forced_kf_index]) {
+ big_picture.pict_type = AV_PICTURE_TYPE_I;
+ ost->forced_kf_index++;
+ }
+ ret = avcodec_encode_video(enc,
+ bit_buffer, bit_buffer_size,
+ &big_picture);
+ if (ret < 0) {
+ av_log(NULL, AV_LOG_FATAL, "Video encoding failed\n");
+ exit_program(1);
+ }
+
+ if(ret>0){
+ pkt.data= bit_buffer;
+ pkt.size= ret;
+ if(enc->coded_frame->pts != AV_NOPTS_VALUE)
+ pkt.pts= av_rescale_q(enc->coded_frame->pts, enc->time_base, ost->st->time_base);
+/*av_log(NULL, AV_LOG_DEBUG, "encoder -> %"PRId64"/%"PRId64"\n",
+ pkt.pts != AV_NOPTS_VALUE ? av_rescale(pkt.pts, enc->time_base.den, AV_TIME_BASE*(int64_t)enc->time_base.num) : -1,
+ pkt.dts != AV_NOPTS_VALUE ? av_rescale(pkt.dts, enc->time_base.den, AV_TIME_BASE*(int64_t)enc->time_base.num) : -1);*/
+
+ if(enc->coded_frame->key_frame)
+ pkt.flags |= AV_PKT_FLAG_KEY;
+ write_frame(s, &pkt, ost->st->codec, ost->bitstream_filters);
+ *frame_size = ret;
+ video_size += ret;
+ //fprintf(stderr,"\nFrame: %3d size: %5d type: %d",
+ // enc->frame_number-1, ret, enc->pict_type);
+ /* if two pass, output log */
+ if (ost->logfile && enc->stats_out) {
+ fprintf(ost->logfile, "%s", enc->stats_out);
+ }
+ }
+ }
+ ost->sync_opts++;
+ ost->frame_number++;
+ }
+}
+
+static double psnr(double d){
+ return -10.0*log(d)/log(10.0);
+}
+
+static void do_video_stats(AVFormatContext *os, OutputStream *ost,
+ int frame_size)
+{
+ AVCodecContext *enc;
+ int frame_number;
+ double ti1, bitrate, avg_bitrate;
+
+ /* this is executed just the first time do_video_stats is called */
+ if (!vstats_file) {
+ vstats_file = fopen(vstats_filename, "w");
+ if (!vstats_file) {
+ perror("fopen");
+ exit_program(1);
+ }
+ }
+
+ enc = ost->st->codec;
+ if (enc->codec_type == AVMEDIA_TYPE_VIDEO) {
+ frame_number = ost->frame_number;
+ fprintf(vstats_file, "frame= %5d q= %2.1f ", frame_number, enc->coded_frame->quality/(float)FF_QP2LAMBDA);
+ if (enc->flags&CODEC_FLAG_PSNR)
+ fprintf(vstats_file, "PSNR= %6.2f ", psnr(enc->coded_frame->error[0]/(enc->width*enc->height*255.0*255.0)));
+
+ fprintf(vstats_file,"f_size= %6d ", frame_size);
+ /* compute pts value */
+ ti1 = ost->sync_opts * av_q2d(enc->time_base);
+ if (ti1 < 0.01)
+ ti1 = 0.01;
+
+ bitrate = (frame_size * 8) / av_q2d(enc->time_base) / 1000.0;
+ avg_bitrate = (double)(video_size * 8) / ti1 / 1000.0;
+ fprintf(vstats_file, "s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ",
+ (double)video_size / 1024, ti1, bitrate, avg_bitrate);
+ fprintf(vstats_file, "type= %c\n", av_get_picture_type_char(enc->coded_frame->pict_type));
+ }
+}
+
+static void print_report(OutputFile *output_files,
+ OutputStream *ost_table, int nb_ostreams,
+ int is_last_report, int64_t timer_start)
+{
+ char buf[1024];
+ OutputStream *ost;
+ AVFormatContext *oc;
+ int64_t total_size;
+ AVCodecContext *enc;
+ int frame_number, vid, i;
+ double bitrate;
+ int64_t pts = INT64_MAX;
+ static int64_t last_time = -1;
+ static int qp_histogram[52];
+ int hours, mins, secs, us;
+
+ if (!print_stats && !is_last_report)
+ return;
+
+ if (!is_last_report) {
+ int64_t cur_time;
+ /* display the report every 0.5 seconds */
+ cur_time = av_gettime();
+ if (last_time == -1) {
+ last_time = cur_time;
+ return;
+ }
+ if ((cur_time - last_time) < 500000)
+ return;
+ last_time = cur_time;
+ }
+
+
+ oc = output_files[0].ctx;
+
+ total_size = avio_size(oc->pb);
+ if(total_size<0) // FIXME improve avio_size() so it works with non seekable output too
+ total_size= avio_tell(oc->pb);
+
+ buf[0] = '\0';
+ vid = 0;
+ for(i=0;i<nb_ostreams;i++) {
+ float q = -1;
+ ost = &ost_table[i];
+ enc = ost->st->codec;
+ if (!ost->st->stream_copy && enc->coded_frame)
+ q = enc->coded_frame->quality/(float)FF_QP2LAMBDA;
+ if (vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) {
+ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "q=%2.1f ", q);
+ }
+ if (!vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) {
+ float t = (av_gettime()-timer_start) / 1000000.0;
+
+ frame_number = ost->frame_number;
+ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "frame=%5d fps=%3d q=%3.1f ",
+ frame_number, (t>1)?(int)(frame_number/t+0.5) : 0, q);
+ if(is_last_report)
+ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "L");
+ if(qp_hist){
+ int j;
+ int qp = lrintf(q);
+ if(qp>=0 && qp<FF_ARRAY_ELEMS(qp_histogram))
+ qp_histogram[qp]++;
+ for(j=0; j<32; j++)
+ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%X", (int)lrintf(log(qp_histogram[j]+1)/log(2)));
+ }
+ if (enc->flags&CODEC_FLAG_PSNR){
+ int j;
+ double error, error_sum=0;
+ double scale, scale_sum=0;
+ char type[3]= {'Y','U','V'};
+ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "PSNR=");
+ for(j=0; j<3; j++){
+ if(is_last_report){
+ error= enc->error[j];
+ scale= enc->width*enc->height*255.0*255.0*frame_number;
+ }else{
+ error= enc->coded_frame->error[j];
+ scale= enc->width*enc->height*255.0*255.0;
+ }
+ if(j) scale/=4;
+ error_sum += error;
+ scale_sum += scale;
+ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%c:%2.2f ", type[j], psnr(error/scale));
+ }
+ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "*:%2.2f ", psnr(error_sum/scale_sum));
+ }
+ vid = 1;
+ }
+ /* compute min output value */
+ pts = FFMIN(pts, av_rescale_q(ost->st->pts.val,
+ ost->st->time_base, AV_TIME_BASE_Q));
+ }
+
+ secs = pts / AV_TIME_BASE;
+ us = pts % AV_TIME_BASE;
+ mins = secs / 60;
+ secs %= 60;
+ hours = mins / 60;
+ mins %= 60;
+
+ bitrate = pts ? total_size * 8 / (pts / 1000.0) : 0;
+
+ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
+ "size=%8.0fkB time=", total_size / 1024.0);
+ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
+ "%02d:%02d:%02d.%02d ", hours, mins, secs,
+ (100 * us) / AV_TIME_BASE);
+ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
+ "bitrate=%6.1fkbits/s", bitrate);
+
+ if (nb_frames_dup || nb_frames_drop)
+ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " dup=%d drop=%d",
+ nb_frames_dup, nb_frames_drop);
+
+ av_log(NULL, AV_LOG_INFO, "%s \r", buf);
+
+ fflush(stderr);
+
+ if (is_last_report) {
+ int64_t raw= audio_size + video_size + extra_size;
+ av_log(NULL, AV_LOG_INFO, "\n");
+ av_log(NULL, AV_LOG_INFO, "video:%1.0fkB audio:%1.0fkB global headers:%1.0fkB muxing overhead %f%%\n",
+ video_size/1024.0,
+ audio_size/1024.0,
+ extra_size/1024.0,
+ 100.0*(total_size - raw)/raw
+ );
+ }
+}
+
+static void generate_silence(uint8_t* buf, enum AVSampleFormat sample_fmt, size_t size)
+{
+ int fill_char = 0x00;
+ if (sample_fmt == AV_SAMPLE_FMT_U8)
+ fill_char = 0x80;
+ memset(buf, fill_char, size);
+}
+
+static void flush_encoders(OutputStream *ost_table, int nb_ostreams)
+{
+ int i, ret;
+
+ for (i = 0; i < nb_ostreams; i++) {
+ OutputStream *ost = &ost_table[i];
+ AVCodecContext *enc = ost->st->codec;
+ AVFormatContext *os = output_files[ost->file_index].ctx;
+
+ if (!ost->encoding_needed)
+ continue;
+
+ if (ost->st->codec->codec_type == AVMEDIA_TYPE_AUDIO && enc->frame_size <=1)
+ continue;
+ if (ost->st->codec->codec_type == AVMEDIA_TYPE_VIDEO && (os->oformat->flags & AVFMT_RAWPICTURE))
+ continue;
+
+ for(;;) {
+ AVPacket pkt;
+ int fifo_bytes;
+ av_init_packet(&pkt);
+ pkt.stream_index= ost->index;
+
+ switch (ost->st->codec->codec_type) {
+ case AVMEDIA_TYPE_AUDIO:
+ fifo_bytes = av_fifo_size(ost->fifo);
+ ret = 0;
+ /* encode any samples remaining in fifo */
+ if (fifo_bytes > 0) {
+ int osize = av_get_bytes_per_sample(enc->sample_fmt);
+ int fs_tmp = enc->frame_size;
+
+ av_fifo_generic_read(ost->fifo, audio_buf, fifo_bytes, NULL);
+ if (enc->codec->capabilities & CODEC_CAP_SMALL_LAST_FRAME) {
+ enc->frame_size = fifo_bytes / (osize * enc->channels);
+ } else { /* pad */
+ int frame_bytes = enc->frame_size*osize*enc->channels;
+ if (allocated_audio_buf_size < frame_bytes)
+ exit_program(1);
+ generate_silence(audio_buf+fifo_bytes, enc->sample_fmt, frame_bytes - fifo_bytes);
+ }
+
+ ret = avcodec_encode_audio(enc, bit_buffer, bit_buffer_size, (short *)audio_buf);
+ pkt.duration = av_rescale((int64_t)enc->frame_size*ost->st->time_base.den,
+ ost->st->time_base.num, enc->sample_rate);
+ enc->frame_size = fs_tmp;
+ }
+ if (ret <= 0) {
+ ret = avcodec_encode_audio(enc, bit_buffer, bit_buffer_size, NULL);
+ }
+ if (ret < 0) {
+ av_log(NULL, AV_LOG_FATAL, "Audio encoding failed\n");
+ exit_program(1);
+ }
+ audio_size += ret;
+ pkt.flags |= AV_PKT_FLAG_KEY;
+ break;
+ case AVMEDIA_TYPE_VIDEO:
+ ret = avcodec_encode_video(enc, bit_buffer, bit_buffer_size, NULL);
+ if (ret < 0) {
+ av_log(NULL, AV_LOG_FATAL, "Video encoding failed\n");
+ exit_program(1);
+ }
+ video_size += ret;
+ if(enc->coded_frame && enc->coded_frame->key_frame)
+ pkt.flags |= AV_PKT_FLAG_KEY;
+ if (ost->logfile && enc->stats_out) {
+ fprintf(ost->logfile, "%s", enc->stats_out);
+ }
+ break;
+ default:
+ ret=-1;
+ }
+
+ if (ret <= 0)
+ break;
+ pkt.data = bit_buffer;
+ pkt.size = ret;
+ if (enc->coded_frame && enc->coded_frame->pts != AV_NOPTS_VALUE)
+ pkt.pts= av_rescale_q(enc->coded_frame->pts, enc->time_base, ost->st->time_base);
+ write_frame(os, &pkt, ost->st->codec, ost->bitstream_filters);
+ }
+ }
+}
+
+/* pkt = NULL means EOF (needed to flush decoder buffers) */
+static int output_packet(InputStream *ist, int ist_index,
+ OutputStream *ost_table, int nb_ostreams,
+ const AVPacket *pkt)
+{
+ AVFormatContext *os;
+ OutputStream *ost;
+ int ret = 0, i;
+ int got_output;
+ void *buffer_to_free = NULL;
+ static unsigned int samples_size= 0;
+ AVSubtitle subtitle, *subtitle_to_free;
+ int64_t pkt_pts = AV_NOPTS_VALUE;
+#if CONFIG_AVFILTER
+ int frame_available;
+#endif
+ float quality;
+
+ AVPacket avpkt;
+ int bps = av_get_bytes_per_sample(ist->st->codec->sample_fmt);
+
+ if(ist->next_pts == AV_NOPTS_VALUE)
+ ist->next_pts= ist->pts;
+
+ if (pkt == NULL) {
+ /* EOF handling */
+ av_init_packet(&avpkt);
+ avpkt.data = NULL;
+ avpkt.size = 0;
+ goto handle_eof;
+ } else {
+ avpkt = *pkt;
+ }
+
+ if(pkt->dts != AV_NOPTS_VALUE)
+ ist->next_pts = ist->pts = av_rescale_q(pkt->dts, ist->st->time_base, AV_TIME_BASE_Q);
+ if(pkt->pts != AV_NOPTS_VALUE)
+ pkt_pts = av_rescale_q(pkt->pts, ist->st->time_base, AV_TIME_BASE_Q);
+
+ //while we have more to decode or while the decoder did output something on EOF
+ while (avpkt.size > 0 || (!pkt && got_output)) {
+ uint8_t *data_buf, *decoded_data_buf;
+ int data_size, decoded_data_size;
+ AVFrame *decoded_frame, *filtered_frame;
+ handle_eof:
+ ist->pts= ist->next_pts;
+
+ if(avpkt.size && avpkt.size != pkt->size)
+ av_log(NULL, ist->showed_multi_packet_warning ? AV_LOG_VERBOSE : AV_LOG_WARNING,
+ "Multiple frames in a packet from stream %d\n", pkt->stream_index);
+ ist->showed_multi_packet_warning=1;
+
+ /* decode the packet if needed */
+ decoded_frame = filtered_frame = NULL;
+ decoded_data_buf = NULL; /* fail safe */
+ decoded_data_size= 0;
+ data_buf = avpkt.data;
+ data_size = avpkt.size;
+ subtitle_to_free = NULL;
+ if (ist->decoding_needed) {
+ switch(ist->st->codec->codec_type) {
+ case AVMEDIA_TYPE_AUDIO:{
+ if(pkt && samples_size < FFMAX(pkt->size * bps, AVCODEC_MAX_AUDIO_FRAME_SIZE)) {
+ samples_size = FFMAX(pkt->size * bps, AVCODEC_MAX_AUDIO_FRAME_SIZE);
+ av_free(samples);
+ samples= av_malloc(samples_size);
+ }
+ decoded_data_size= samples_size;
+ /* XXX: could avoid copy if PCM 16 bits with same
+ endianness as CPU */
+ ret = avcodec_decode_audio3(ist->st->codec, samples, &decoded_data_size,
+ &avpkt);
+ if (ret < 0)
+ return ret;
+ avpkt.data += ret;
+ avpkt.size -= ret;
+ data_size = ret;
+ got_output = decoded_data_size > 0;
+ /* Some bug in mpeg audio decoder gives */
+ /* decoded_data_size < 0, it seems they are overflows */
+ if (!got_output) {
+ /* no audio frame */
+ continue;
+ }
+ decoded_data_buf = (uint8_t *)samples;
+ ist->next_pts += ((int64_t)AV_TIME_BASE/bps * decoded_data_size) /
+ (ist->st->codec->sample_rate * ist->st->codec->channels);
+ break;}
+ case AVMEDIA_TYPE_VIDEO:
+ if (!(decoded_frame = avcodec_alloc_frame()))
+ return AVERROR(ENOMEM);
+ avpkt.pts = pkt_pts;
+ avpkt.dts = ist->pts;
+ pkt_pts = AV_NOPTS_VALUE;
+
+ ret = avcodec_decode_video2(ist->st->codec,
+ decoded_frame, &got_output, &avpkt);
+ quality = same_quant ? decoded_frame->quality : 0;
+ if (ret < 0)
+ goto fail;
+ if (!got_output) {
+ /* no picture yet */
+ av_freep(&decoded_frame);
+ goto discard_packet;
+ }
+ ist->next_pts = ist->pts = decoded_frame->best_effort_timestamp;
+ if (ist->st->codec->time_base.num != 0) {
+ int ticks= ist->st->parser ? ist->st->parser->repeat_pict+1 : ist->st->codec->ticks_per_frame;
+ ist->next_pts += ((int64_t)AV_TIME_BASE *
+ ist->st->codec->time_base.num * ticks) /
+ ist->st->codec->time_base.den;
+ }
+ avpkt.size = 0;
+ buffer_to_free = NULL;
+ pre_process_video_frame(ist, (AVPicture *)decoded_frame, &buffer_to_free);
+ break;
+ case AVMEDIA_TYPE_SUBTITLE:
+ ret = avcodec_decode_subtitle2(ist->st->codec,
+ &subtitle, &got_output, &avpkt);
+ if (ret < 0)
+ return ret;
+ if (!got_output) {
+ goto discard_packet;
+ }
+ subtitle_to_free = &subtitle;
+ avpkt.size = 0;
+ break;
+ default:
+ return -1;
+ }
+ } else {
+ switch(ist->st->codec->codec_type) {
+ case AVMEDIA_TYPE_AUDIO:
+ ist->next_pts += ((int64_t)AV_TIME_BASE * ist->st->codec->frame_size) /
+ ist->st->codec->sample_rate;
+ break;
+ case AVMEDIA_TYPE_VIDEO:
+ if (ist->st->codec->time_base.num != 0) {
+ int ticks= ist->st->parser ? ist->st->parser->repeat_pict+1 : ist->st->codec->ticks_per_frame;
+ ist->next_pts += ((int64_t)AV_TIME_BASE *
+ ist->st->codec->time_base.num * ticks) /
+ ist->st->codec->time_base.den;
+ }
+ break;
+ }
+ avpkt.size = 0;
+ }
+
+ // preprocess audio (volume)
+ if (ist->st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
+ if (audio_volume != 256) {
+ switch (ist->st->codec->sample_fmt) {
+ case AV_SAMPLE_FMT_U8:
+ {
+ uint8_t *volp = samples;
+ for (i = 0; i < (decoded_data_size / sizeof(*volp)); i++) {
+ int v = (((*volp - 128) * audio_volume + 128) >> 8) + 128;
+ *volp++ = av_clip_uint8(v);
+ }
+ break;
+ }
+ case AV_SAMPLE_FMT_S16:
+ {
+ int16_t *volp = samples;
+ for (i = 0; i < (decoded_data_size / sizeof(*volp)); i++) {
+ int v = ((*volp) * audio_volume + 128) >> 8;
+ *volp++ = av_clip_int16(v);
+ }
+ break;
+ }
+ case AV_SAMPLE_FMT_S32:
+ {
+ int32_t *volp = samples;
+ for (i = 0; i < (decoded_data_size / sizeof(*volp)); i++) {
+ int64_t v = (((int64_t)*volp * audio_volume + 128) >> 8);
+ *volp++ = av_clipl_int32(v);
+ }
+ break;
+ }
+ case AV_SAMPLE_FMT_FLT:
+ {
+ float *volp = samples;
+ float scale = audio_volume / 256.f;
+ for (i = 0; i < (decoded_data_size / sizeof(*volp)); i++) {
+ *volp++ *= scale;
+ }
+ break;
+ }
+ case AV_SAMPLE_FMT_DBL:
+ {
+ double *volp = samples;
+ double scale = audio_volume / 256.;
+ for (i = 0; i < (decoded_data_size / sizeof(*volp)); i++) {
+ *volp++ *= scale;
+ }
+ break;
+ }
+ default:
+ av_log(NULL, AV_LOG_FATAL,
+ "Audio volume adjustment on sample format %s is not supported.\n",
+ av_get_sample_fmt_name(ist->st->codec->sample_fmt));
+ exit_program(1);
+ }
+ }
+ }
+
+ /* frame rate emulation */
+ if (input_files[ist->file_index].rate_emu) {
+ int64_t pts = av_rescale(ist->pts, 1000000, AV_TIME_BASE);
+ int64_t now = av_gettime() - ist->start;
+ if (pts > now)
+ usleep(pts - now);
+ }
+ /* if output time reached then transcode raw format,
+ encode packets and output them */
+ for (i = 0; i < nb_ostreams; i++) {
+ OutputFile *of = &output_files[ost_table[i].file_index];
+ int frame_size;
+
+ ost = &ost_table[i];
+ if (ost->source_index != ist_index)
+ continue;
+
+ if (of->start_time && ist->pts < of->start_time)
+ continue;
+
+ if (of->recording_time != INT64_MAX &&
+ av_compare_ts(ist->pts, AV_TIME_BASE_Q, of->recording_time + of->start_time,
+ (AVRational){1, 1000000}) >= 0) {
+ ost->is_past_recording_time = 1;
+ continue;
+ }
+
+#if CONFIG_AVFILTER
+ if (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO &&
+ ost->input_video_filter) {
+ if (!decoded_frame->sample_aspect_ratio.num)
+ decoded_frame->sample_aspect_ratio = ist->st->sample_aspect_ratio;
+ decoded_frame->pts = ist->pts;
+
+ av_vsrc_buffer_add_frame(ost->input_video_filter, decoded_frame, AV_VSRC_BUF_FLAG_OVERWRITE);
+ if (!(filtered_frame = avcodec_alloc_frame())) {
+ ret = AVERROR(ENOMEM);
+ goto fail;
+ }
+ }
+ frame_available = ist->st->codec->codec_type != AVMEDIA_TYPE_VIDEO ||
+ !ost->output_video_filter || avfilter_poll_frame(ost->output_video_filter->inputs[0]);
+ while (frame_available) {
+ if (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO && ost->output_video_filter) {
+ AVRational ist_pts_tb = ost->output_video_filter->inputs[0]->time_base;
+ if (av_buffersink_get_buffer_ref(ost->output_video_filter, &ost->picref, 0) < 0)
+ goto cont;
+ if (ost->picref) {
+ avfilter_fill_frame_from_video_buffer_ref(filtered_frame, ost->picref);
+ ist->pts = av_rescale_q(ost->picref->pts, ist_pts_tb, AV_TIME_BASE_Q);
+ }
+ }
+#else
+ filtered_frame = decoded_frame;
+#endif
+ os = output_files[ost->file_index].ctx;
+
+ /* set the input output pts pairs */
+ //ost->sync_ipts = (double)(ist->pts + input_files[ist->file_index].ts_offset - start_time)/ AV_TIME_BASE;
+
+ if (ost->encoding_needed) {
+ av_assert0(ist->decoding_needed);
+ switch(ost->st->codec->codec_type) {
+ case AVMEDIA_TYPE_AUDIO:
+ do_audio_out(os, ost, ist, decoded_data_buf, decoded_data_size);
+ break;
+ case AVMEDIA_TYPE_VIDEO:
+#if CONFIG_AVFILTER
+ if (ost->picref->video && !ost->frame_aspect_ratio)
+ ost->st->codec->sample_aspect_ratio = ost->picref->video->sample_aspect_ratio;
+#endif
+ do_video_out(os, ost, ist, filtered_frame, &frame_size,
+ same_quant ? quality : ost->st->codec->global_quality);
+ if (vstats_filename && frame_size)
+ do_video_stats(os, ost, frame_size);
+ break;
+ case AVMEDIA_TYPE_SUBTITLE:
+ do_subtitle_out(os, ost, ist, &subtitle,
+ pkt->pts);
+ break;
+ default:
+ abort();
+ }
+ } else {
+ AVPicture pict;
+ AVPacket opkt;
+ int64_t ost_tb_start_time= av_rescale_q(of->start_time, AV_TIME_BASE_Q, ost->st->time_base);
+ av_init_packet(&opkt);
+
+ if ((!ost->frame_number && !(pkt->flags & AV_PKT_FLAG_KEY)) && !copy_initial_nonkeyframes)
+#if !CONFIG_AVFILTER
+ continue;
+#else
+ goto cont;
+#endif
+
+ /* no reencoding needed : output the packet directly */
+ /* force the input stream PTS */
+
+ if(ost->st->codec->codec_type == AVMEDIA_TYPE_AUDIO)
+ audio_size += data_size;
+ else if (ost->st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
+ video_size += data_size;
+ ost->sync_opts++;
+ }
+
+ opkt.stream_index= ost->index;
+ if(pkt->pts != AV_NOPTS_VALUE)
+ opkt.pts= av_rescale_q(pkt->pts, ist->st->time_base, ost->st->time_base) - ost_tb_start_time;
+ else
+ opkt.pts= AV_NOPTS_VALUE;
+
+ if (pkt->dts == AV_NOPTS_VALUE)
+ opkt.dts = av_rescale_q(ist->pts, AV_TIME_BASE_Q, ost->st->time_base);
+ else
+ opkt.dts = av_rescale_q(pkt->dts, ist->st->time_base, ost->st->time_base);
+ opkt.dts -= ost_tb_start_time;
+
+ opkt.duration = av_rescale_q(pkt->duration, ist->st->time_base, ost->st->time_base);
+ opkt.flags= pkt->flags;
+
+ //FIXME remove the following 2 lines they shall be replaced by the bitstream filters
+ if( ost->st->codec->codec_id != CODEC_ID_H264
+ && ost->st->codec->codec_id != CODEC_ID_MPEG1VIDEO
+ && ost->st->codec->codec_id != CODEC_ID_MPEG2VIDEO
+ ) {
+ if(av_parser_change(ist->st->parser, ost->st->codec, &opkt.data, &opkt.size, data_buf, data_size, pkt->flags & AV_PKT_FLAG_KEY))
+ opkt.destruct= av_destruct_packet;
+ } else {
+ opkt.data = data_buf;
+ opkt.size = data_size;
+ }
+
+ if (os->oformat->flags & AVFMT_RAWPICTURE) {
+ /* store AVPicture in AVPacket, as expected by the output format */
+ avpicture_fill(&pict, opkt.data, ost->st->codec->pix_fmt, ost->st->codec->width, ost->st->codec->height);
+ opkt.data = (uint8_t *)&pict;
+ opkt.size = sizeof(AVPicture);
+ opkt.flags |= AV_PKT_FLAG_KEY;
+ }
+ write_frame(os, &opkt, ost->st->codec, ost->bitstream_filters);
+ ost->st->codec->frame_number++;
+ ost->frame_number++;
+ av_free_packet(&opkt);
+ }
+#if CONFIG_AVFILTER
+ cont:
+ frame_available = (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO) &&
+ ost->output_video_filter && avfilter_poll_frame(ost->output_video_filter->inputs[0]);
+ if (ost->picref)
+ avfilter_unref_buffer(ost->picref);
+ }
+ av_freep(&filtered_frame);
+#endif
+ }
+
+fail:
+ av_free(buffer_to_free);
+ /* XXX: allocate the subtitles in the codec ? */
+ if (subtitle_to_free) {
+ avsubtitle_free(subtitle_to_free);
+ subtitle_to_free = NULL;
+ }
+ av_freep(&decoded_frame);
+ if (ret < 0)
+ return ret;
+ }
+ discard_packet:
+
+ return 0;
+}
+
+static void print_sdp(OutputFile *output_files, int n)
+{
+ char sdp[2048];
+ int i;
+ AVFormatContext **avc = av_malloc(sizeof(*avc)*n);
+
+ if (!avc)
+ exit_program(1);
+ for (i = 0; i < n; i++)
+ avc[i] = output_files[i].ctx;
+
+ av_sdp_create(avc, n, sdp, sizeof(sdp));
+ printf("SDP:\n%s\n", sdp);
+ fflush(stdout);
+ av_freep(&avc);
+}
+
+static int init_input_stream(int ist_index, OutputStream *output_streams, int nb_output_streams,
+ char *error, int error_len)
+{
+ int i;
+ InputStream *ist = &input_streams[ist_index];
+ if (ist->decoding_needed) {
+ AVCodec *codec = ist->dec;
+ if (!codec) {
+ snprintf(error, error_len, "Decoder (codec id %d) not found for input stream #%d.%d",
+ ist->st->codec->codec_id, ist->file_index, ist->st->index);
+ return AVERROR(EINVAL);
+ }
+
+ if (avcodec_open2(ist->st->codec, codec, &ist->opts) < 0) {
+ snprintf(error, error_len, "Error while opening decoder for input stream #%d.%d",
+ ist->file_index, ist->st->index);
+ return AVERROR(EINVAL);
+ }
+ assert_codec_experimental(ist->st->codec, 0);
+ assert_avoptions(ist->opts);
+ }
+
+ ist->pts = ist->st->avg_frame_rate.num ? - ist->st->codec->has_b_frames*AV_TIME_BASE / av_q2d(ist->st->avg_frame_rate) : 0;
+ ist->next_pts = AV_NOPTS_VALUE;
+ ist->is_start = 1;
+
+ return 0;
+}
+
+static int transcode_init(OutputFile *output_files,
+ int nb_output_files,
+ InputFile *input_files,
+ int nb_input_files)
+{
+ int ret = 0, i, j, k;
+ AVFormatContext *os;
+ AVCodecContext *codec, *icodec;
+ OutputStream *ost;
+ InputStream *ist;
+ char error[1024];
+ int want_sdp = 1;
+
+ /* init framerate emulation */
+ for (i = 0; i < nb_input_files; i++) {
+ InputFile *ifile = &input_files[i];
+ if (ifile->rate_emu)
+ for (j = 0; j < ifile->nb_streams; j++)
+ input_streams[j + ifile->ist_index].start = av_gettime();
+ }
+
+ /* output stream init */
+ for(i=0;i<nb_output_files;i++) {
+ os = output_files[i].ctx;
+ if (!os->nb_streams && !(os->oformat->flags & AVFMT_NOSTREAMS)) {
+ av_dump_format(os, i, os->filename, 1);
+ av_log(NULL, AV_LOG_ERROR, "Output file #%d does not contain any stream\n", i);
+ return AVERROR(EINVAL);
+ }
+ }
+
+ /* for each output stream, we compute the right encoding parameters */
+ for (i = 0; i < nb_output_streams; i++) {
+ ost = &output_streams[i];
+ os = output_files[ost->file_index].ctx;
+ ist = &input_streams[ost->source_index];
+
+ codec = ost->st->codec;
+ icodec = ist->st->codec;
+
+ ost->st->disposition = ist->st->disposition;
+ codec->bits_per_raw_sample= icodec->bits_per_raw_sample;
+ codec->chroma_sample_location = icodec->chroma_sample_location;
+
+ if (ost->st->stream_copy) {
+ uint64_t extra_size = (uint64_t)icodec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE;
+
+ if (extra_size > INT_MAX) {
+ return AVERROR(EINVAL);
+ }
+
+ /* if stream_copy is selected, no need to decode or encode */
+ codec->codec_id = icodec->codec_id;
+ codec->codec_type = icodec->codec_type;
+
+ if(!codec->codec_tag){
+ if( !os->oformat->codec_tag
+ || av_codec_get_id (os->oformat->codec_tag, icodec->codec_tag) == codec->codec_id
+ || av_codec_get_tag(os->oformat->codec_tag, icodec->codec_id) <= 0)
+ codec->codec_tag = icodec->codec_tag;
+ }
+
+ codec->bit_rate = icodec->bit_rate;
+ codec->rc_max_rate = icodec->rc_max_rate;
+ codec->rc_buffer_size = icodec->rc_buffer_size;
+ codec->extradata= av_mallocz(extra_size);
+ if (!codec->extradata) {
+ return AVERROR(ENOMEM);
+ }
+ memcpy(codec->extradata, icodec->extradata, icodec->extradata_size);
+ codec->extradata_size= icodec->extradata_size;
+
+ codec->time_base = ist->st->time_base;
+ if(!strcmp(os->oformat->name, "avi")) {
+ if(!copy_tb && av_q2d(icodec->time_base)*icodec->ticks_per_frame > 2*av_q2d(ist->st->time_base) && av_q2d(ist->st->time_base) < 1.0/500){
+ codec->time_base = icodec->time_base;
+ codec->time_base.num *= icodec->ticks_per_frame;
+ codec->time_base.den *= 2;
+ }
+ } else if(!(os->oformat->flags & AVFMT_VARIABLE_FPS)) {
+ if(!copy_tb && av_q2d(icodec->time_base)*icodec->ticks_per_frame > av_q2d(ist->st->time_base) && av_q2d(ist->st->time_base) < 1.0/500){
+ codec->time_base = icodec->time_base;
+ codec->time_base.num *= icodec->ticks_per_frame;
+ }
+ }
+ av_reduce(&codec->time_base.num, &codec->time_base.den,
+ codec->time_base.num, codec->time_base.den, INT_MAX);
+
+ switch(codec->codec_type) {
+ case AVMEDIA_TYPE_AUDIO:
+ if(audio_volume != 256) {
+ av_log(NULL, AV_LOG_FATAL, "-acodec copy and -vol are incompatible (frames are not decoded)\n");
+ exit_program(1);
+ }
+ codec->channel_layout = icodec->channel_layout;
+ codec->sample_rate = icodec->sample_rate;
+ codec->channels = icodec->channels;
+ codec->frame_size = icodec->frame_size;
+ codec->audio_service_type = icodec->audio_service_type;
+ codec->block_align= icodec->block_align;
+ if(codec->block_align == 1 && codec->codec_id == CODEC_ID_MP3)
+ codec->block_align= 0;
+ if(codec->codec_id == CODEC_ID_AC3)
+ codec->block_align= 0;
+ break;
+ case AVMEDIA_TYPE_VIDEO:
+ codec->pix_fmt = icodec->pix_fmt;
+ codec->width = icodec->width;
+ codec->height = icodec->height;
+ codec->has_b_frames = icodec->has_b_frames;
+ if (!codec->sample_aspect_ratio.num) {
+ codec->sample_aspect_ratio =
+ ost->st->sample_aspect_ratio =
+ ist->st->sample_aspect_ratio.num ? ist->st->sample_aspect_ratio :
+ ist->st->codec->sample_aspect_ratio.num ?
+ ist->st->codec->sample_aspect_ratio : (AVRational){0, 1};
+ }
+ break;
+ case AVMEDIA_TYPE_SUBTITLE:
+ codec->width = icodec->width;
+ codec->height = icodec->height;
+ break;
+ case AVMEDIA_TYPE_DATA:
+ case AVMEDIA_TYPE_ATTACHMENT:
+ break;
+ default:
+ abort();
+ }
+ } else {
+ if (!ost->enc)
+ ost->enc = avcodec_find_encoder(ost->st->codec->codec_id);
+ ist->decoding_needed = 1;
+ ost->encoding_needed = 1;
+ switch(codec->codec_type) {
+ case AVMEDIA_TYPE_AUDIO:
+ ost->fifo= av_fifo_alloc(1024);
+ if (!ost->fifo) {
+ return AVERROR(ENOMEM);
+ }
+ ost->reformat_pair = MAKE_SFMT_PAIR(AV_SAMPLE_FMT_NONE,AV_SAMPLE_FMT_NONE);
+ if (!codec->sample_rate) {
+ codec->sample_rate = icodec->sample_rate;
+ }
+ choose_sample_rate(ost->st, ost->enc);
+ codec->time_base = (AVRational){1, codec->sample_rate};
+ if (codec->sample_fmt == AV_SAMPLE_FMT_NONE)
+ codec->sample_fmt = icodec->sample_fmt;
+ choose_sample_fmt(ost->st, ost->enc);
+ if (!codec->channels) {
+ codec->channels = icodec->channels;
+ codec->channel_layout = icodec->channel_layout;
+ }
+ if (av_get_channel_layout_nb_channels(codec->channel_layout) != codec->channels)
+ codec->channel_layout = 0;
+ ost->audio_resample = codec->sample_rate != icodec->sample_rate || audio_sync_method > 1;
+ icodec->request_channels = codec->channels;
+ ost->resample_sample_fmt = icodec->sample_fmt;
+ ost->resample_sample_rate = icodec->sample_rate;
+ ost->resample_channels = icodec->channels;
+ break;
+ case AVMEDIA_TYPE_VIDEO:
+ if (codec->pix_fmt == PIX_FMT_NONE)
+ codec->pix_fmt = icodec->pix_fmt;
+ choose_pixel_fmt(ost->st, ost->enc);
+
+ if (ost->st->codec->pix_fmt == PIX_FMT_NONE) {
+ av_log(NULL, AV_LOG_FATAL, "Video pixel format is unknown, stream cannot be encoded\n");
+ exit_program(1);
+ }
+
+ if (!codec->width || !codec->height) {
+ codec->width = icodec->width;
+ codec->height = icodec->height;
+ }
+
+ ost->video_resample = codec->width != icodec->width ||
+ codec->height != icodec->height ||
+ codec->pix_fmt != icodec->pix_fmt;
+ if (ost->video_resample) {
+ codec->bits_per_raw_sample= frame_bits_per_raw_sample;
+ }
+
+ ost->resample_height = icodec->height;
+ ost->resample_width = icodec->width;
+ ost->resample_pix_fmt= icodec->pix_fmt;
+
+ if (!ost->frame_rate.num)
+ ost->frame_rate = ist->st->r_frame_rate.num ? ist->st->r_frame_rate : (AVRational){25,1};
+ if (ost->enc && ost->enc->supported_framerates && !ost->force_fps) {
+ int idx = av_find_nearest_q_idx(ost->frame_rate, ost->enc->supported_framerates);
+ ost->frame_rate = ost->enc->supported_framerates[idx];
+ }
+ codec->time_base = (AVRational){ost->frame_rate.den, ost->frame_rate.num};
+ if( av_q2d(codec->time_base) < 0.001 && video_sync_method
+ && (video_sync_method==1 || (video_sync_method<0 && !(os->oformat->flags & AVFMT_VARIABLE_FPS)))){
+ av_log(os, AV_LOG_WARNING, "Frame rate very high for a muxer not effciciently supporting it.\n"
+ "Please consider specifiying a lower framerate, a different muxer or -vsync 2\n");
+ }
+
+#if CONFIG_AVFILTER
+ if (configure_video_filters(ist, ost)) {
+ av_log(NULL, AV_LOG_FATAL, "Error opening filters!\n");
+ exit(1);
+ }
+#endif
+ break;
+ case AVMEDIA_TYPE_SUBTITLE:
+ break;
+ default:
+ abort();
+ break;
+ }
+ /* two pass mode */
+ if (codec->codec_id != CODEC_ID_H264 &&
+ (codec->flags & (CODEC_FLAG_PASS1 | CODEC_FLAG_PASS2))) {
+ char logfilename[1024];
+ FILE *f;
+
+ snprintf(logfilename, sizeof(logfilename), "%s-%d.log",
+ pass_logfilename_prefix ? pass_logfilename_prefix : DEFAULT_PASS_LOGFILENAME_PREFIX,
+ i);
+ if (codec->flags & CODEC_FLAG_PASS1) {
+ f = fopen(logfilename, "wb");
+ if (!f) {
+ av_log(NULL, AV_LOG_FATAL, "Cannot write log file '%s' for pass-1 encoding: %s\n",
+ logfilename, strerror(errno));
+ exit_program(1);
+ }
+ ost->logfile = f;
+ } else {
+ char *logbuffer;
+ size_t logbuffer_size;
+ if (read_file(logfilename, &logbuffer, &logbuffer_size) < 0) {
+ av_log(NULL, AV_LOG_FATAL, "Error reading log file '%s' for pass-2 encoding\n",
+ logfilename);
+ exit_program(1);
+ }
+ codec->stats_in = logbuffer;
+ }
+ }
+ }
+ if(codec->codec_type == AVMEDIA_TYPE_VIDEO){
+ /* maximum video buffer size is 6-bytes per pixel, plus DPX header size */
+ int size= codec->width * codec->height;
+ bit_buffer_size= FFMAX(bit_buffer_size, 6*size + 1664);
+ }
+ }
+
+ if (!bit_buffer)
+ bit_buffer = av_malloc(bit_buffer_size);
+ if (!bit_buffer) {
+ av_log(NULL, AV_LOG_ERROR, "Cannot allocate %d bytes output buffer\n",
+ bit_buffer_size);
+ return AVERROR(ENOMEM);
+ }
+
+ /* open each encoder */
+ for (i = 0; i < nb_output_streams; i++) {
+ ost = &output_streams[i];
+ if (ost->encoding_needed) {
+ AVCodec *codec = ost->enc;
+ AVCodecContext *dec = input_streams[ost->source_index].st->codec;
+ if (!codec) {
+ snprintf(error, sizeof(error), "Encoder (codec id %d) not found for output stream #%d.%d",
+ ost->st->codec->codec_id, ost->file_index, ost->index);
+ ret = AVERROR(EINVAL);
+ goto dump_format;
+ }
+ if (dec->subtitle_header) {
+ ost->st->codec->subtitle_header = av_malloc(dec->subtitle_header_size);
+ if (!ost->st->codec->subtitle_header) {
+ ret = AVERROR(ENOMEM);
+ goto dump_format;
+ }
+ memcpy(ost->st->codec->subtitle_header, dec->subtitle_header, dec->subtitle_header_size);
+ ost->st->codec->subtitle_header_size = dec->subtitle_header_size;
+ }
+ if (avcodec_open2(ost->st->codec, codec, &ost->opts) < 0) {
+ snprintf(error, sizeof(error), "Error while opening encoder for output stream #%d.%d - maybe incorrect parameters such as bit_rate, rate, width or height",
+ ost->file_index, ost->index);
+ ret = AVERROR(EINVAL);
+ goto dump_format;
+ }
+ assert_codec_experimental(ost->st->codec, 1);
+ assert_avoptions(ost->opts);
+ if (ost->st->codec->bit_rate && ost->st->codec->bit_rate < 1000)
+ av_log(NULL, AV_LOG_WARNING, "The bitrate parameter is set too low."
+ "It takes bits/s as argument, not kbits/s\n");
+ extra_size += ost->st->codec->extradata_size;
+
+ if (ost->st->codec->me_threshold)
+ input_streams[ost->source_index].st->codec->debug |= FF_DEBUG_MV;
+ }
+ }
+
+ /* init input streams */
+ for (i = 0; i < nb_input_streams; i++)
+ if ((ret = init_input_stream(i, output_streams, nb_output_streams, error, sizeof(error))) < 0)
+ goto dump_format;
+
+ /* discard unused programs */
+ for (i = 0; i < nb_input_files; i++) {
+ InputFile *ifile = &input_files[i];
+ for (j = 0; j < ifile->ctx->nb_programs; j++) {
+ AVProgram *p = ifile->ctx->programs[j];
+ int discard = AVDISCARD_ALL;
+
+ for (k = 0; k < p->nb_stream_indexes; k++)
+ if (!input_streams[ifile->ist_index + p->stream_index[k]].discard) {
+ discard = AVDISCARD_DEFAULT;
+ break;
+ }
+ p->discard = discard;
+ }
+ }
+
+ /* open files and write file headers */
+ for (i = 0; i < nb_output_files; i++) {
+ os = output_files[i].ctx;
+ if (avformat_write_header(os, &output_files[i].opts) < 0) {
+ snprintf(error, sizeof(error), "Could not write header for output file #%d (incorrect codec parameters ?)", i);
+ ret = AVERROR(EINVAL);
+ goto dump_format;
+ }
+// assert_avoptions(output_files[i].opts);
+ if (strcmp(os->oformat->name, "rtp")) {
+ want_sdp = 0;
+ }
+ }
+
+ dump_format:
+ /* dump the file output parameters - cannot be done before in case
+ of stream copy */
+ for(i=0;i<nb_output_files;i++) {
+ av_dump_format(output_files[i].ctx, i, output_files[i].ctx->filename, 1);
+ }
+
+ /* dump the stream mapping */
+ av_log(NULL, AV_LOG_INFO, "Stream mapping:\n");
+ for (i = 0; i < nb_output_streams; i++) {
+ ost = &output_streams[i];
+ av_log(NULL, AV_LOG_INFO, " Stream #%d.%d -> #%d.%d",
+ input_streams[ost->source_index].file_index,
+ input_streams[ost->source_index].st->index,
+ ost->file_index,
+ ost->index);
+ if (ost->sync_ist != &input_streams[ost->source_index])
+ av_log(NULL, AV_LOG_INFO, " [sync #%d.%d]",
+ ost->sync_ist->file_index,
+ ost->sync_ist->st->index);
+ if (ost->st->stream_copy)
+ av_log(NULL, AV_LOG_INFO, " (copy)");
+ else
+ av_log(NULL, AV_LOG_INFO, " (%s -> %s)", input_streams[ost->source_index].dec ?
+ input_streams[ost->source_index].dec->name : "?",
+ ost->enc ? ost->enc->name : "?");
+ av_log(NULL, AV_LOG_INFO, "\n");
+ }
+
+ if (ret) {
+ av_log(NULL, AV_LOG_ERROR, "%s\n", error);
+ return ret;
+ }
+
+ if (want_sdp) {
+ print_sdp(output_files, nb_output_files);
+ }
+
+ return 0;
+}
+
+/*
+ * The following code is the main loop of the file converter
+ */
+static int transcode(OutputFile *output_files,
+ int nb_output_files,
+ InputFile *input_files,
+ int nb_input_files)
+{
+ int ret, i;
+ AVFormatContext *is, *os;
+ OutputStream *ost;
+ InputStream *ist;
+ uint8_t *no_packet;
+ int no_packet_count=0;
+ int64_t timer_start;
+ int key;
+
+ if (!(no_packet = av_mallocz(nb_input_files)))
+ exit_program(1);
+
+ ret = transcode_init(output_files, nb_output_files, input_files, nb_input_files);
+ if (ret < 0)
+ goto fail;
+
+ if (!using_stdin) {
+ av_log(NULL, AV_LOG_INFO, "Press [q] to stop, [?] for help\n");
+ avio_set_interrupt_cb(decode_interrupt_cb);
+ }
+ term_init();
+
+ timer_start = av_gettime();
+
+ for(; received_sigterm == 0;) {
+ int file_index, ist_index;
+ AVPacket pkt;
+ int64_t ipts_min;
+ double opts_min;
+
+ ipts_min = INT64_MAX;
+ opts_min= 1e100;
+ /* if 'q' pressed, exits */
+ if (!using_stdin) {
+ if (q_pressed)
+ break;
+ /* read_key() returns 0 on EOF */
+ key = read_key();
+ if (key == 'q')
+ break;
+ if (key == '+') av_log_set_level(av_log_get_level()+10);
+ if (key == '-') av_log_set_level(av_log_get_level()-10);
+ if (key == 's') qp_hist ^= 1;
+ if (key == 'h'){
+ if (do_hex_dump){
+ do_hex_dump = do_pkt_dump = 0;
+ } else if(do_pkt_dump){
+ do_hex_dump = 1;
+ } else
+ do_pkt_dump = 1;
+ av_log_set_level(AV_LOG_DEBUG);
+ }
+ if (key == 'd' || key == 'D'){
+ int debug=0;
+ if(key == 'D') {
+ debug = input_streams[0].st->codec->debug<<1;
+ if(!debug) debug = 1;
+ while(debug & (FF_DEBUG_DCT_COEFF|FF_DEBUG_VIS_QP|FF_DEBUG_VIS_MB_TYPE)) //unsupported, would just crash
+ debug += debug;
+ }else
+ scanf("%d", &debug);
+ for(i=0;i<nb_input_streams;i++) {
+ input_streams[i].st->codec->debug = debug;
+ }
+ for(i=0;i<nb_output_streams;i++) {
+ ost = &output_streams[i];
+ ost->st->codec->debug = debug;
+ }
+ if(debug) av_log_set_level(AV_LOG_DEBUG);
+ fprintf(stderr,"debug=%d\n", debug);
+ }
+ if (key == '?'){
+ fprintf(stderr, "key function\n"
+ "? show this help\n"
+ "+ increase verbosity\n"
+ "- decrease verbosity\n"
+ "D cycle through available debug modes\n"
+ "h dump packets/hex press to cycle through the 3 states\n"
+ "q quit\n"
+ "s Show QP histogram\n"
+ );
+ }
+ }
+
+ /* select the stream that we must read now by looking at the
+ smallest output pts */
+ file_index = -1;
+ for (i = 0; i < nb_output_streams; i++) {
+ OutputFile *of;
+ int64_t ipts;
+ double opts;
+ ost = &output_streams[i];
+ of = &output_files[ost->file_index];
+ os = output_files[ost->file_index].ctx;
+ ist = &input_streams[ost->source_index];
+ if (ost->is_past_recording_time || no_packet[ist->file_index] ||
+ (os->pb && avio_tell(os->pb) >= of->limit_filesize))
+ continue;
+ opts = ost->st->pts.val * av_q2d(ost->st->time_base);
+ ipts = ist->pts;
+ if (!input_files[ist->file_index].eof_reached){
+ if(ipts < ipts_min) {
+ ipts_min = ipts;
+ if(input_sync ) file_index = ist->file_index;
+ }
+ if(opts < opts_min) {
+ opts_min = opts;
+ if(!input_sync) file_index = ist->file_index;
+ }
+ }
+ if (ost->frame_number >= ost->max_frames) {
+ int j;
+ for (j = 0; j < of->ctx->nb_streams; j++)
+ output_streams[of->ost_index + j].is_past_recording_time = 1;
+ continue;
+ }
+ }
+ /* if none, if is finished */
+ if (file_index < 0) {
+ if(no_packet_count){
+ no_packet_count=0;
+ memset(no_packet, 0, nb_input_files);
+ usleep(10000);
+ continue;
+ }
+ break;
+ }
+
+ /* read a frame from it and output it in the fifo */
+ is = input_files[file_index].ctx;
+ ret= av_read_frame(is, &pkt);
+ if(ret == AVERROR(EAGAIN)){
+ no_packet[file_index]=1;
+ no_packet_count++;
+ continue;
+ }
+ if (ret < 0) {
+ input_files[file_index].eof_reached = 1;
+ if (opt_shortest)
+ break;
+ else
+ continue;
+ }
+
+ no_packet_count=0;
+ memset(no_packet, 0, nb_input_files);
+
+ if (do_pkt_dump) {
+ av_pkt_dump_log2(NULL, AV_LOG_DEBUG, &pkt, do_hex_dump,
+ is->streams[pkt.stream_index]);
+ }
+ /* the following test is needed in case new streams appear
+ dynamically in stream : we ignore them */
+ if (pkt.stream_index >= input_files[file_index].nb_streams)
+ goto discard_packet;
+ ist_index = input_files[file_index].ist_index + pkt.stream_index;
+ ist = &input_streams[ist_index];
+ if (ist->discard)
+ goto discard_packet;
+
+ if (pkt.dts != AV_NOPTS_VALUE)
+ pkt.dts += av_rescale_q(input_files[ist->file_index].ts_offset, AV_TIME_BASE_Q, ist->st->time_base);
+ if (pkt.pts != AV_NOPTS_VALUE)
+ pkt.pts += av_rescale_q(input_files[ist->file_index].ts_offset, AV_TIME_BASE_Q, ist->st->time_base);
+
+ if(pkt.pts != AV_NOPTS_VALUE)
+ pkt.pts *= ist->ts_scale;
+ if(pkt.dts != AV_NOPTS_VALUE)
+ pkt.dts *= ist->ts_scale;
+
+// fprintf(stderr, "next:%"PRId64" dts:%"PRId64" off:%"PRId64" %d\n", ist->next_pts, pkt.dts, input_files[ist->file_index].ts_offset, ist->st->codec->codec_type);
+ if (pkt.dts != AV_NOPTS_VALUE && ist->next_pts != AV_NOPTS_VALUE
+ && (is->iformat->flags & AVFMT_TS_DISCONT)) {
+ int64_t pkt_dts= av_rescale_q(pkt.dts, ist->st->time_base, AV_TIME_BASE_Q);
+ int64_t delta= pkt_dts - ist->next_pts;
+ if((FFABS(delta) > 1LL*dts_delta_threshold*AV_TIME_BASE || pkt_dts+1<ist->pts)&& !copy_ts){
+ input_files[ist->file_index].ts_offset -= delta;
+ av_log(NULL, AV_LOG_DEBUG, "timestamp discontinuity %"PRId64", new offset= %"PRId64"\n",
+ delta, input_files[ist->file_index].ts_offset);
+ pkt.dts-= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base);
+ if(pkt.pts != AV_NOPTS_VALUE)
+ pkt.pts-= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base);
+ }
+ }
+
+ //fprintf(stderr,"read #%d.%d size=%d\n", ist->file_index, ist->st->index, pkt.size);
+ if (output_packet(ist, ist_index, output_streams, nb_output_streams, &pkt) < 0) {
+
+ av_log(NULL, AV_LOG_ERROR, "Error while decoding stream #%d.%d\n",
+ ist->file_index, ist->st->index);
+ if (exit_on_error)
+ exit_program(1);
+ av_free_packet(&pkt);
+ continue;
+ }
+
+ discard_packet:
+ av_free_packet(&pkt);
+
+ /* dump report by using the output first video and audio streams */
+ print_report(output_files, output_streams, nb_output_streams, 0, timer_start);
+ }
+
+ /* at the end of stream, we must flush the decoder buffers */
+ for (i = 0; i < nb_input_streams; i++) {
+ ist = &input_streams[i];
+ if (ist->decoding_needed) {
+ output_packet(ist, i, output_streams, nb_output_streams, NULL);
+ }
+ }
+ flush_encoders(output_streams, nb_output_streams);
+
+ term_exit();
+
+ /* write the trailer if needed and close file */
+ for(i=0;i<nb_output_files;i++) {
+ os = output_files[i].ctx;
+ av_write_trailer(os);
+ }
+
+ /* dump report by using the first video and audio streams */
+ print_report(output_files, output_streams, nb_output_streams, 1, timer_start);
+
+ /* close each encoder */
+ for (i = 0; i < nb_output_streams; i++) {
+ ost = &output_streams[i];
+ if (ost->encoding_needed) {
+ av_freep(&ost->st->codec->stats_in);
+ avcodec_close(ost->st->codec);
+ }
+#if CONFIG_AVFILTER
+ avfilter_graph_free(&ost->graph);
+#endif
+ }
+
+ /* close each decoder */
+ for (i = 0; i < nb_input_streams; i++) {
+ ist = &input_streams[i];
+ if (ist->decoding_needed) {
+ avcodec_close(ist->st->codec);
+ }
+ }
+
+ /* finished ! */
+ ret = 0;
+
+ fail:
+ av_freep(&bit_buffer);
+ av_freep(&no_packet);
+
+ if (output_streams) {
+ for (i = 0; i < nb_output_streams; i++) {
+ ost = &output_streams[i];
+ if (ost) {
+ if (ost->st->stream_copy)
+ av_freep(&ost->st->codec->extradata);
+ if (ost->logfile) {
+ fclose(ost->logfile);
+ ost->logfile = NULL;
+ }
+ av_fifo_free(ost->fifo); /* works even if fifo is not
+ initialized but set to zero */
+ av_freep(&ost->st->codec->subtitle_header);
+ av_free(ost->resample_frame.data[0]);
+ av_free(ost->forced_kf_pts);
+ if (ost->video_resample)
+ sws_freeContext(ost->img_resample_ctx);
+ if (ost->resample)
+ audio_resample_close(ost->resample);
+ if (ost->reformat_ctx)
+ av_audio_convert_free(ost->reformat_ctx);
+ av_dict_free(&ost->opts);
+ }
+ }
+ }
+ return ret;
+}
+
+static double parse_frame_aspect_ratio(const char *arg)
+{
+ int x = 0, y = 0;
+ double ar = 0;
+ const char *p;
+ char *end;
+
+ p = strchr(arg, ':');
+ if (p) {
+ x = strtol(arg, &end, 10);
+ if (end == p)
+ y = strtol(end+1, &end, 10);
+ if (x > 0 && y > 0)
+ ar = (double)x / (double)y;
+ } else
+ ar = strtod(arg, NULL);
+
+ if (!ar) {
+ av_log(NULL, AV_LOG_FATAL, "Incorrect aspect ratio specification.\n");
+ exit_program(1);
+ }
+ return ar;
+}
+
+static int opt_audio_codec(OptionsContext *o, const char *opt, const char *arg)
+{
+ return parse_option(o, "codec:a", arg, options);
+}
+
+static int opt_video_codec(OptionsContext *o, const char *opt, const char *arg)
+{
+ return parse_option(o, "codec:v", arg, options);
+}
+
+static int opt_subtitle_codec(OptionsContext *o, const char *opt, const char *arg)
+{
+ return parse_option(o, "codec:s", arg, options);
+}
+
+static int opt_data_codec(OptionsContext *o, const char *opt, const char *arg)
+{
+ return parse_option(o, "codec:d", arg, options);
+}
+
+static int opt_map(OptionsContext *o, const char *opt, const char *arg)
+{
+ StreamMap *m = NULL;
+ int i, negative = 0, file_idx;
+ int sync_file_idx = -1, sync_stream_idx;
+ char *p, *sync;
+ char *map;
+
+ if (*arg == '-') {
+ negative = 1;
+ arg++;
+ }
+ map = av_strdup(arg);
+
+ /* parse sync stream first, just pick first matching stream */
+ if (sync = strchr(map, ',')) {
+ *sync = 0;
+ sync_file_idx = strtol(sync + 1, &sync, 0);
+ if (sync_file_idx >= nb_input_files || sync_file_idx < 0) {
+ av_log(NULL, AV_LOG_FATAL, "Invalid sync file index: %d.\n", sync_file_idx);
+ exit_program(1);
+ }
+ if (*sync)
+ sync++;
+ for (i = 0; i < input_files[sync_file_idx].nb_streams; i++)
+ if (check_stream_specifier(input_files[sync_file_idx].ctx,
+ input_files[sync_file_idx].ctx->streams[i], sync) == 1) {
+ sync_stream_idx = i;
+ break;
+ }
+ if (i == input_files[sync_file_idx].nb_streams) {
+ av_log(NULL, AV_LOG_FATAL, "Sync stream specification in map %s does not "
+ "match any streams.\n", arg);
+ exit_program(1);
+ }
+ }
+
+
+ file_idx = strtol(map, &p, 0);
+ if (file_idx >= nb_input_files || file_idx < 0) {
+ av_log(NULL, AV_LOG_FATAL, "Invalid input file index: %d.\n", file_idx);
+ exit_program(1);
+ }
+ if (negative)
+ /* disable some already defined maps */
+ for (i = 0; i < o->nb_stream_maps; i++) {
+ m = &o->stream_maps[i];
+ if (check_stream_specifier(input_files[m->file_index].ctx,
+ input_files[m->file_index].ctx->streams[m->stream_index],
+ *p == ':' ? p + 1 : p) > 0)
+ m->disabled = 1;
+ }
+ else
+ for (i = 0; i < input_files[file_idx].nb_streams; i++) {
+ if (check_stream_specifier(input_files[file_idx].ctx, input_files[file_idx].ctx->streams[i],
+ *p == ':' ? p + 1 : p) <= 0)
+ continue;
+ o->stream_maps = grow_array(o->stream_maps, sizeof(*o->stream_maps),
+ &o->nb_stream_maps, o->nb_stream_maps + 1);
+ m = &o->stream_maps[o->nb_stream_maps - 1];
+
+ m->file_index = file_idx;
+ m->stream_index = i;
+
+ if (sync_file_idx >= 0) {
+ m->sync_file_index = sync_file_idx;
+ m->sync_stream_index = sync_stream_idx;
+ } else {
+ m->sync_file_index = file_idx;
+ m->sync_stream_index = i;
+ }
+ }
+
+ if (!m) {
+ av_log(NULL, AV_LOG_FATAL, "Stream map '%s' matches no streams.\n", arg);
+ exit_program(1);
+ }
+
+ av_freep(&map);
+ return 0;
+}
+
+static void parse_meta_type(char *arg, char *type, int *index)
+{
+ if (*arg) {
+ *type = *arg;
+ switch (*arg) {
+ case 'g':
+ break;
+ case 's':
+ case 'c':
+ case 'p':
+ if (*(++arg) == ':')
+ *index = strtol(++arg, NULL, 0);
+ break;
+ default:
+ av_log(NULL, AV_LOG_FATAL, "Invalid metadata type %c.\n", *arg);
+ exit_program(1);
+ }
+ } else
+ *type = 'g';
+}
+
+static int opt_map_metadata(OptionsContext *o, const char *opt, const char *arg)
+{
+ MetadataMap *m, *m1;
+ char *p;
+
+ o->meta_data_maps = grow_array(o->meta_data_maps, sizeof(*o->meta_data_maps),
+ &o->nb_meta_data_maps, o->nb_meta_data_maps + 1);
+
+ m = &o->meta_data_maps[o->nb_meta_data_maps - 1][1];
+ m->file = strtol(arg, &p, 0);
+ parse_meta_type(*p ? p + 1 : p, &m->type, &m->index);
+
+ m1 = &o->meta_data_maps[o->nb_meta_data_maps - 1][0];
+ if (p = strchr(opt, ':'))
+ parse_meta_type(p + 1, &m1->type, &m1->index);
+ else
+ m1->type = 'g';
+
+ if (m->type == 'g' || m1->type == 'g')
+ o->metadata_global_manual = 1;
+ if (m->type == 's' || m1->type == 's')
+ o->metadata_streams_manual = 1;
+ if (m->type == 'c' || m1->type == 'c')
+ o->metadata_chapters_manual = 1;
+
+ return 0;
+}
+
+static enum CodecID find_codec_or_die(const char *name, enum AVMediaType type, int encoder)
+{
+ const char *codec_string = encoder ? "encoder" : "decoder";
+ AVCodec *codec;
+
+ if(!name)
+ return CODEC_ID_NONE;
+ codec = encoder ?
+ avcodec_find_encoder_by_name(name) :
+ avcodec_find_decoder_by_name(name);
+ if(!codec) {
+ av_log(NULL, AV_LOG_FATAL, "Unknown %s '%s'\n", codec_string, name);
+ exit_program(1);
+ }
+ if(codec->type != type) {
+ av_log(NULL, AV_LOG_FATAL, "Invalid %s type '%s'\n", codec_string, name);
+ exit_program(1);
+ }
+ return codec->id;
+}
+
+static AVCodec *choose_codec(OptionsContext *o, AVFormatContext *s, AVStream *st, enum AVMediaType type)
+{
+ char *codec_name = NULL;
+
+ MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, st);
+
+ if (!codec_name) {
+ if (s->oformat) {
+ st->codec->codec_id = av_guess_codec(s->oformat, NULL, s->filename, NULL, type);
+ return avcodec_find_encoder(st->codec->codec_id);
+ }
+ } else if (!strcmp(codec_name, "copy"))
+ st->stream_copy = 1;
+ else {
+ st->codec->codec_id = find_codec_or_die(codec_name, type, s->iformat == NULL);
+ return s->oformat ? avcodec_find_encoder_by_name(codec_name) :
+ avcodec_find_decoder_by_name(codec_name);
+ }
+
+ return NULL;
+}
+
+/**
+ * Add all the streams from the given input file to the global
+ * list of input streams.
+ */
+static void add_input_streams(OptionsContext *o, AVFormatContext *ic)
+{
+ int i, rfps, rfps_base;
+
+ for (i = 0; i < ic->nb_streams; i++) {
+ AVStream *st = ic->streams[i];
+ AVCodecContext *dec = st->codec;
+ InputStream *ist;
+ double scale = 1.0;
+
+ input_streams = grow_array(input_streams, sizeof(*input_streams), &nb_input_streams, nb_input_streams + 1);
+ ist = &input_streams[nb_input_streams - 1];
+ ist->st = st;
+ ist->file_index = nb_input_files;
+ ist->discard = 1;
+ ist->opts = filter_codec_opts(codec_opts, ist->st->codec->codec_id, ic, st);
+
+ MATCH_PER_STREAM_OPT(ts_scale, dbl, scale, ic, st);
+ ist->ts_scale = scale;
+
+ ist->dec = choose_codec(o, ic, st, dec->codec_type);
+ if (!ist->dec)
+ ist->dec = avcodec_find_decoder(dec->codec_id);
+
+ switch (dec->codec_type) {
+ case AVMEDIA_TYPE_AUDIO:
+ if(!ist->dec)
+ ist->dec = avcodec_find_decoder(dec->codec_id);
+ if(o->audio_disable)
+ st->discard= AVDISCARD_ALL;
+ break;
+ case AVMEDIA_TYPE_VIDEO:
+ if(!ist->dec)
+ ist->dec = avcodec_find_decoder(dec->codec_id);
+ rfps = ic->streams[i]->r_frame_rate.num;
+ rfps_base = ic->streams[i]->r_frame_rate.den;
+ if (dec->lowres) {
+ dec->flags |= CODEC_FLAG_EMU_EDGE;
+ }
+
+ if (dec->time_base.den != rfps*dec->ticks_per_frame || dec->time_base.num != rfps_base) {
+
+ av_log(NULL, AV_LOG_INFO,"\nSeems stream %d codec frame rate differs from container frame rate: %2.2f (%d/%d) -> %2.2f (%d/%d)\n",
+ i, (float)dec->time_base.den / dec->time_base.num, dec->time_base.den, dec->time_base.num,
+ (float)rfps / rfps_base, rfps, rfps_base);
+ }
+
+ if (o->video_disable)
+ st->discard= AVDISCARD_ALL;
+ else if(video_discard)
+ st->discard= video_discard;
+ break;
+ case AVMEDIA_TYPE_DATA:
+ break;
+ case AVMEDIA_TYPE_SUBTITLE:
+ if(!ist->dec)
+ ist->dec = avcodec_find_decoder(dec->codec_id);
+ if(o->subtitle_disable)
+ st->discard = AVDISCARD_ALL;
+ break;
+ case AVMEDIA_TYPE_ATTACHMENT:
+ case AVMEDIA_TYPE_UNKNOWN:
+ break;
+ default:
+ abort();
+ }
+ }
+}
+
+static int opt_input_file(OptionsContext *o, const char *opt, const char *filename)
+{
+ AVFormatContext *ic;
+ AVInputFormat *file_iformat = NULL;
+ int err, i, ret;
+ int64_t timestamp;
+ uint8_t buf[128];
+ AVDictionary **opts;
+ int orig_nb_streams; // number of streams before avformat_find_stream_info
+
+ if (o->format) {
+ if (!(file_iformat = av_find_input_format(o->format))) {
+ av_log(NULL, AV_LOG_FATAL, "Unknown input format: '%s'\n", o->format);
+ exit_program(1);
+ }
+ }
+
+ if (!strcmp(filename, "-"))
+ filename = "pipe:";
+
+ using_stdin |= !strncmp(filename, "pipe:", 5) ||
+ !strcmp(filename, "/dev/stdin");
+
+ /* get default parameters from command line */
+ ic = avformat_alloc_context();
+ if (!ic) {
+ print_error(filename, AVERROR(ENOMEM));
+ exit_program(1);
+ }
+ if (o->nb_audio_sample_rate) {
+ snprintf(buf, sizeof(buf), "%d", o->audio_sample_rate[o->nb_audio_sample_rate - 1].u.i);
+ av_dict_set(&format_opts, "sample_rate", buf, 0);
+ }
+ if (o->nb_audio_channels) {
+ snprintf(buf, sizeof(buf), "%d", o->audio_channels[o->nb_audio_channels - 1].u.i);
+ av_dict_set(&format_opts, "channels", buf, 0);
+ }
+ if (o->nb_frame_rates) {
+ av_dict_set(&format_opts, "framerate", o->frame_rates[o->nb_frame_rates - 1].u.str, 0);
+ }
+ if (o->nb_frame_sizes) {
+ av_dict_set(&format_opts, "video_size", o->frame_sizes[o->nb_frame_sizes - 1].u.str, 0);
+ }
+ if (o->nb_frame_pix_fmts)
+ av_dict_set(&format_opts, "pixel_format", o->frame_pix_fmts[o->nb_frame_pix_fmts - 1].u.str, 0);
+
+ ic->flags |= AVFMT_FLAG_NONBLOCK;
+
+ /* open the input file with generic libav function */
+ err = avformat_open_input(&ic, filename, file_iformat, &format_opts);
+ if (err < 0) {
+ print_error(filename, err);
+ exit_program(1);
+ }
+ assert_avoptions(format_opts);
+
+ /* apply forced codec ids */
+ for (i = 0; i < ic->nb_streams; i++)
+ choose_codec(o, ic, ic->streams[i], ic->streams[i]->codec->codec_type);
+
+ /* Set AVCodecContext options for avformat_find_stream_info */
+ opts = setup_find_stream_info_opts(ic, codec_opts);
+ orig_nb_streams = ic->nb_streams;
+
+ /* If not enough info to get the stream parameters, we decode the
+ first frames to get it. (used in mpeg case for example) */
+ ret = avformat_find_stream_info(ic, opts);
+ if (ret < 0) {
+ av_log(NULL, AV_LOG_FATAL, "%s: could not find codec parameters\n", filename);
+ av_close_input_file(ic);
+ exit_program(1);
+ }
+
+ timestamp = o->start_time;
+ /* add the stream start time */
+ if (ic->start_time != AV_NOPTS_VALUE)
+ timestamp += ic->start_time;
+
+ /* if seeking requested, we execute it */
+ if (o->start_time != 0) {
+ ret = av_seek_frame(ic, -1, timestamp, AVSEEK_FLAG_BACKWARD);
+ if (ret < 0) {
+ av_log(NULL, AV_LOG_WARNING, "%s: could not seek to position %0.3f\n",
+ filename, (double)timestamp / AV_TIME_BASE);
+ }
+ }
+
+ /* update the current parameters so that they match the one of the input stream */
+ add_input_streams(o, ic);
+
+ /* dump the file content */
+ av_dump_format(ic, nb_input_files, filename, 0);
+
+ input_files = grow_array(input_files, sizeof(*input_files), &nb_input_files, nb_input_files + 1);
+ input_files[nb_input_files - 1].ctx = ic;
+ input_files[nb_input_files - 1].ist_index = nb_input_streams - ic->nb_streams;
+ input_files[nb_input_files - 1].ts_offset = o->input_ts_offset - (copy_ts ? 0 : timestamp);
+ input_files[nb_input_files - 1].nb_streams = ic->nb_streams;
+ input_files[nb_input_files - 1].rate_emu = o->rate_emu;
+
+ for (i = 0; i < orig_nb_streams; i++)
+ av_dict_free(&opts[i]);
+ av_freep(&opts);
+
+ reset_options(o);
+ return 0;
+}
+
+static void parse_forced_key_frames(char *kf, OutputStream *ost,
+ AVCodecContext *avctx)
+{
+ char *p;
+ int n = 1, i;
+ int64_t t;
+
+ for (p = kf; *p; p++)
+ if (*p == ',')
+ n++;
+ ost->forced_kf_count = n;
+ ost->forced_kf_pts = av_malloc(sizeof(*ost->forced_kf_pts) * n);
+ if (!ost->forced_kf_pts) {
+ av_log(NULL, AV_LOG_FATAL, "Could not allocate forced key frames array.\n");
+ exit_program(1);
+ }
+ for (i = 0; i < n; i++) {
+ p = i ? strchr(p, ',') + 1 : kf;
+ t = parse_time_or_die("force_key_frames", p, 1);
+ ost->forced_kf_pts[i] = av_rescale_q(t, AV_TIME_BASE_Q, avctx->time_base);
+ }
+}
+
+static uint8_t *get_line(AVIOContext *s)
+{
+ AVIOContext *line;
+ uint8_t *buf;
+ char c;
+
+ if (avio_open_dyn_buf(&line) < 0) {
+ av_log(NULL, AV_LOG_FATAL, "Could not alloc buffer for reading preset.\n");
+ exit_program(1);
+ }
+
+ while ((c = avio_r8(s)) && c != '\n')
+ avio_w8(line, c);
+ avio_w8(line, 0);
+ avio_close_dyn_buf(line, &buf);
+
+ return buf;
+}
+
+static int get_preset_file_2(const char *preset_name, const char *codec_name, AVIOContext **s)
+{
+ int i, ret = 1;
+ char filename[1000];
+ const char *base[3] = { getenv("AVCONV_DATADIR"),
+ getenv("HOME"),
+ AVCONV_DATADIR,
+ };
+
+ for (i = 0; i < FF_ARRAY_ELEMS(base) && ret; i++) {
+ if (!base[i])
+ continue;
+ if (codec_name) {
+ snprintf(filename, sizeof(filename), "%s%s/%s-%s.avpreset", base[i],
+ i != 1 ? "" : "/.avconv", codec_name, preset_name);
+ ret = avio_open(s, filename, AVIO_FLAG_READ);
+ }
+ if (ret) {
+ snprintf(filename, sizeof(filename), "%s%s/%s.avpreset", base[i],
+ i != 1 ? "" : "/.avconv", preset_name);
+ ret = avio_open(s, filename, AVIO_FLAG_READ);
+ }
+ }
+ return ret;
+}
+
+static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, enum AVMediaType type)
+{
+ OutputStream *ost;
+ AVStream *st = avformat_new_stream(oc, NULL);
+ int idx = oc->nb_streams - 1, ret = 0;
+ int64_t max_frames = INT64_MAX;
+ char *bsf = NULL, *next, *codec_tag = NULL;
+ AVBitStreamFilterContext *bsfc, *bsfc_prev = NULL;
+ double qscale = -1;
+ char *buf = NULL, *arg = NULL, *preset = NULL;
+ AVIOContext *s = NULL;
+
+ if (!st) {
+ av_log(NULL, AV_LOG_FATAL, "Could not alloc stream.\n");
+ exit_program(1);
+ }
+
+ if (oc->nb_streams - 1 < o->nb_streamid_map)
+ st->id = o->streamid_map[oc->nb_streams - 1];
+
+ output_streams = grow_array(output_streams, sizeof(*output_streams), &nb_output_streams,
+ nb_output_streams + 1);
+ ost = &output_streams[nb_output_streams - 1];
+ ost->file_index = nb_output_files;
+ ost->index = idx;
+ ost->st = st;
+ st->codec->codec_type = type;
+ ost->enc = choose_codec(o, oc, st, type);
+ if (ost->enc) {
+ ost->opts = filter_codec_opts(codec_opts, ost->enc->id, oc, st);
+ }
+
+ avcodec_get_context_defaults3(st->codec, ost->enc);
+ st->codec->codec_type = type; // XXX hack, avcodec_get_context_defaults2() sets type to unknown for stream copy
+
+ MATCH_PER_STREAM_OPT(presets, str, preset, oc, st);
+ if (preset && (!(ret = get_preset_file_2(preset, ost->enc->name, &s)))) {
+ do {
+ buf = get_line(s);
+ if (!buf[0] || buf[0] == '#') {
+ av_free(buf);
+ continue;
+ }
+ if (!(arg = strchr(buf, '='))) {
+ av_log(NULL, AV_LOG_FATAL, "Invalid line found in the preset file.\n");
+ exit_program(1);
+ }
+ *arg++ = 0;
+ av_dict_set(&ost->opts, buf, arg, AV_DICT_DONT_OVERWRITE);
+ av_free(buf);
+ } while (!s->eof_reached);
+ avio_close(s);
+ }
+ if (ret) {
+ av_log(NULL, AV_LOG_FATAL,
+ "Preset %s specified for stream %d:%d, but could not be opened.\n",
+ preset, ost->file_index, ost->index);
+ exit_program(1);
+ }
+
+ MATCH_PER_STREAM_OPT(max_frames, i64, max_frames, oc, st);
+ ost->max_frames = max_frames;
+
+ MATCH_PER_STREAM_OPT(bitstream_filters, str, bsf, oc, st);
+ while (bsf) {
+ if (next = strchr(bsf, ','))
+ *next++ = 0;
+ if (!(bsfc = av_bitstream_filter_init(bsf))) {
+ av_log(NULL, AV_LOG_FATAL, "Unknown bitstream filter %s\n", bsf);
+ exit_program(1);
+ }
+ if (bsfc_prev)
+ bsfc_prev->next = bsfc;
+ else
+ ost->bitstream_filters = bsfc;
+
+ bsfc_prev = bsfc;
+ bsf = next;
+ }
+
+ MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, oc, st);
+ if (codec_tag) {
+ uint32_t tag = strtol(codec_tag, &next, 0);
+ if (*next)
+ tag = AV_RL32(codec_tag);
+ st->codec->codec_tag = tag;
+ }
+
+ MATCH_PER_STREAM_OPT(qscale, dbl, qscale, oc, st);
+ if (qscale >= 0 || same_quant) {
+ st->codec->flags |= CODEC_FLAG_QSCALE;
+ st->codec->global_quality = FF_QP2LAMBDA * qscale;
+ }
+
+ if (oc->oformat->flags & AVFMT_GLOBALHEADER)
+ st->codec->flags |= CODEC_FLAG_GLOBAL_HEADER;
+
+ av_opt_get_int(sws_opts, "sws_flags", 0, &ost->sws_flags);
+ return ost;
+}
+
+static void parse_matrix_coeffs(uint16_t *dest, const char *str)
+{
+ int i;
+ const char *p = str;
+ for(i = 0;; i++) {
+ dest[i] = atoi(p);
+ if(i == 63)
+ break;
+ p = strchr(p, ',');
+ if(!p) {
+ av_log(NULL, AV_LOG_FATAL, "Syntax error in matrix \"%s\" at coeff %d\n", str, i);
+ exit_program(1);
+ }
+ p++;
+ }
+}
+
+static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc)
+{
+ AVStream *st;
+ OutputStream *ost;
+ AVCodecContext *video_enc;
+
+ ost = new_output_stream(o, oc, AVMEDIA_TYPE_VIDEO);
+ st = ost->st;
+ video_enc = st->codec;
+
+ if (!st->stream_copy) {
+ const char *p = NULL;
+ char *forced_key_frames = NULL, *frame_rate = NULL, *frame_size = NULL;
+ char *frame_aspect_ratio = NULL, *frame_pix_fmt = NULL;
+ char *intra_matrix = NULL, *inter_matrix = NULL, *filters = NULL;
+ int i, force_fps = 0, top_field_first = -1;
+
+ MATCH_PER_STREAM_OPT(frame_rates, str, frame_rate, oc, st);
+ if (frame_rate && av_parse_video_rate(&ost->frame_rate, frame_rate) < 0) {
+ av_log(NULL, AV_LOG_FATAL, "Invalid framerate value: %s\n", frame_rate);
+ exit_program(1);
+ }
+
+ MATCH_PER_STREAM_OPT(frame_sizes, str, frame_size, oc, st);
+ if (frame_size && av_parse_video_size(&video_enc->width, &video_enc->height, frame_size) < 0) {
+ av_log(NULL, AV_LOG_FATAL, "Invalid frame size: %s.\n", frame_size);
+ exit_program(1);
+ }
+
+ MATCH_PER_STREAM_OPT(frame_aspect_ratios, str, frame_aspect_ratio, oc, st);
+ if (frame_aspect_ratio)
+ ost->frame_aspect_ratio = parse_frame_aspect_ratio(frame_aspect_ratio);
+
+ MATCH_PER_STREAM_OPT(frame_pix_fmts, str, frame_pix_fmt, oc, st);
+ if (frame_pix_fmt && (video_enc->pix_fmt = av_get_pix_fmt(frame_pix_fmt)) == PIX_FMT_NONE) {
+ av_log(NULL, AV_LOG_FATAL, "Unknown pixel format requested: %s.\n", frame_pix_fmt);
+ exit_program(1);
+ }
+ st->sample_aspect_ratio = video_enc->sample_aspect_ratio;
+
+ MATCH_PER_STREAM_OPT(intra_matrices, str, intra_matrix, oc, st);
+ if (intra_matrix) {
+ if (!(video_enc->intra_matrix = av_mallocz(sizeof(*video_enc->intra_matrix) * 64))) {
+ av_log(NULL, AV_LOG_FATAL, "Could not allocate memory for intra matrix.\n");
+ exit_program(1);
+ }
+ parse_matrix_coeffs(video_enc->intra_matrix, intra_matrix);
+ }
+ MATCH_PER_STREAM_OPT(inter_matrices, str, inter_matrix, oc, st);
+ if (inter_matrix) {
+ if (!(video_enc->inter_matrix = av_mallocz(sizeof(*video_enc->inter_matrix) * 64))) {
+ av_log(NULL, AV_LOG_FATAL, "Could not allocate memory for inter matrix.\n");
+ exit_program(1);
+ }
+ parse_matrix_coeffs(video_enc->inter_matrix, inter_matrix);
+ }
+
+ MATCH_PER_STREAM_OPT(rc_overrides, str, p, oc, st);
+ for(i=0; p; i++){
+ int start, end, q;
+ int e=sscanf(p, "%d,%d,%d", &start, &end, &q);
+ if(e!=3){
+ av_log(NULL, AV_LOG_FATAL, "error parsing rc_override\n");
+ exit_program(1);
+ }
+ video_enc->rc_override=
+ av_realloc(video_enc->rc_override,
+ sizeof(RcOverride)*(i+1));
+ video_enc->rc_override[i].start_frame= start;
+ video_enc->rc_override[i].end_frame = end;
+ if(q>0){
+ video_enc->rc_override[i].qscale= q;
+ video_enc->rc_override[i].quality_factor= 1.0;
+ }
+ else{
+ video_enc->rc_override[i].qscale= 0;
+ video_enc->rc_override[i].quality_factor= -q/100.0;
+ }
+ p= strchr(p, '/');
+ if(p) p++;
+ }
+ video_enc->rc_override_count=i;
+ if (!video_enc->rc_initial_buffer_occupancy)
+ video_enc->rc_initial_buffer_occupancy = video_enc->rc_buffer_size*3/4;
+ video_enc->intra_dc_precision= intra_dc_precision - 8;
+
+ /* two pass mode */
+ if (do_pass) {
+ if (do_pass == 1) {
+ video_enc->flags |= CODEC_FLAG_PASS1;
+ } else {
+ video_enc->flags |= CODEC_FLAG_PASS2;
+ }
+ }
+
+ MATCH_PER_STREAM_OPT(forced_key_frames, str, forced_key_frames, oc, st);
+ if (forced_key_frames)
+ parse_forced_key_frames(forced_key_frames, ost, video_enc);
+
+ MATCH_PER_STREAM_OPT(force_fps, i, force_fps, oc, st);
+ ost->force_fps = force_fps;
+
+ MATCH_PER_STREAM_OPT(top_field_first, i, top_field_first, oc, st);
+ ost->top_field_first = top_field_first;
+
+#if CONFIG_AVFILTER
+ MATCH_PER_STREAM_OPT(filters, str, filters, oc, st);
+ if (filters)
+ ost->avfilter = av_strdup(filters);
+#endif
+ }
+
+ return ost;
+}
+
+static OutputStream *new_audio_stream(OptionsContext *o, AVFormatContext *oc)
+{
+ AVStream *st;
+ OutputStream *ost;
+ AVCodecContext *audio_enc;
+
+ ost = new_output_stream(o, oc, AVMEDIA_TYPE_AUDIO);
+ st = ost->st;
+
+ audio_enc = st->codec;
+ audio_enc->codec_type = AVMEDIA_TYPE_AUDIO;
+
+ if (!st->stream_copy) {
+ char *sample_fmt = NULL;
+
+ MATCH_PER_STREAM_OPT(audio_channels, i, audio_enc->channels, oc, st);
+
+ MATCH_PER_STREAM_OPT(sample_fmts, str, sample_fmt, oc, st);
+ if (sample_fmt &&
+ (audio_enc->sample_fmt = av_get_sample_fmt(sample_fmt)) == AV_SAMPLE_FMT_NONE) {
+ av_log(NULL, AV_LOG_FATAL, "Invalid sample format '%s'\n", sample_fmt);
+ exit_program(1);
+ }
+
+ MATCH_PER_STREAM_OPT(audio_sample_rate, i, audio_enc->sample_rate, oc, st);
+ }
+
+ return ost;
+}
+
+static OutputStream *new_data_stream(OptionsContext *o, AVFormatContext *oc)
+{
+ AVStream *st;
+ OutputStream *ost;
+
+ ost = new_output_stream(o, oc, AVMEDIA_TYPE_DATA);
+ st = ost->st;
+ if (!st->stream_copy) {
+ av_log(NULL, AV_LOG_FATAL, "Data stream encoding not supported yet (only streamcopy)\n");
+ exit_program(1);
+ }
+
+ return ost;
+}
+
+static OutputStream *new_attachment_stream(OptionsContext *o, AVFormatContext *oc)
+{
+ OutputStream *ost = new_output_stream(o, oc, AVMEDIA_TYPE_ATTACHMENT);
+ ost->st->stream_copy = 1;
+ return ost;
+}
+
+static OutputStream *new_subtitle_stream(OptionsContext *o, AVFormatContext *oc)
+{
+ AVStream *st;
+ OutputStream *ost;
+ AVCodecContext *subtitle_enc;
+
+ ost = new_output_stream(o, oc, AVMEDIA_TYPE_SUBTITLE);
+ st = ost->st;
+ subtitle_enc = st->codec;
+
+ subtitle_enc->codec_type = AVMEDIA_TYPE_SUBTITLE;
+
+ return ost;
+}
+
+/* arg format is "output-stream-index:streamid-value". */
+static int opt_streamid(OptionsContext *o, const char *opt, const char *arg)
+{
+ int idx;
+ char *p;
+ char idx_str[16];
+
+ av_strlcpy(idx_str, arg, sizeof(idx_str));
+ p = strchr(idx_str, ':');
+ if (!p) {
+ av_log(NULL, AV_LOG_FATAL,
+ "Invalid value '%s' for option '%s', required syntax is 'index:value'\n",
+ arg, opt);
+ exit_program(1);
+ }
+ *p++ = '\0';
+ idx = parse_number_or_die(opt, idx_str, OPT_INT, 0, MAX_STREAMS-1);
+ o->streamid_map = grow_array(o->streamid_map, sizeof(*o->streamid_map), &o->nb_streamid_map, idx+1);
+ o->streamid_map[idx] = parse_number_or_die(opt, p, OPT_INT, 0, INT_MAX);
+ return 0;
+}
+
+static int copy_chapters(InputFile *ifile, OutputFile *ofile, int copy_metadata)
+{
+ AVFormatContext *is = ifile->ctx;
+ AVFormatContext *os = ofile->ctx;
+ int i;
+
+ for (i = 0; i < is->nb_chapters; i++) {
+ AVChapter *in_ch = is->chapters[i], *out_ch;
+ int64_t ts_off = av_rescale_q(ofile->start_time - ifile->ts_offset,
+ AV_TIME_BASE_Q, in_ch->time_base);
+ int64_t rt = (ofile->recording_time == INT64_MAX) ? INT64_MAX :
+ av_rescale_q(ofile->recording_time, AV_TIME_BASE_Q, in_ch->time_base);
+
+
+ if (in_ch->end < ts_off)
+ continue;
+ if (rt != INT64_MAX && in_ch->start > rt + ts_off)
+ break;
+
+ out_ch = av_mallocz(sizeof(AVChapter));
+ if (!out_ch)
+ return AVERROR(ENOMEM);
+
+ out_ch->id = in_ch->id;
+ out_ch->time_base = in_ch->time_base;
+ out_ch->start = FFMAX(0, in_ch->start - ts_off);
+ out_ch->end = FFMIN(rt, in_ch->end - ts_off);
+
+ if (copy_metadata)
+ av_dict_copy(&out_ch->metadata, in_ch->metadata, 0);
+
+ os->nb_chapters++;
+ os->chapters = av_realloc(os->chapters, sizeof(AVChapter)*os->nb_chapters);
+ if (!os->chapters)
+ return AVERROR(ENOMEM);
+ os->chapters[os->nb_chapters - 1] = out_ch;
+ }
+ return 0;
+}
+
+static int read_ffserver_streams(OptionsContext *o, AVFormatContext *s, const char *filename)
+{
+ int i, err;
+ AVFormatContext *ic = NULL;
+
+ err = avformat_open_input(&ic, filename, NULL, NULL);
+ if (err < 0)
+ return err;
+ /* copy stream format */
+ for(i=0;i<ic->nb_streams;i++) {
+ AVStream *st;
+ OutputStream *ost;
+ AVCodec *codec;
+
+ codec = avcodec_find_encoder(ic->streams[i]->codec->codec_id);
+ ost = new_output_stream(o, s, codec->type);
+ st = ost->st;
+
+ // FIXME: a more elegant solution is needed
+ memcpy(st, ic->streams[i], sizeof(AVStream));
+ st->info = av_malloc(sizeof(*st->info));
+ memcpy(st->info, ic->streams[i]->info, sizeof(*st->info));
+ avcodec_copy_context(st->codec, ic->streams[i]->codec);
+
+ if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && !st->stream_copy)
+ choose_sample_fmt(st, codec);
+ else if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO && !st->stream_copy)
+ choose_pixel_fmt(st, codec);
+ }
+
+ av_close_input_file(ic);
+ return 0;
+}
+
+static void opt_output_file(void *optctx, const char *filename)
+{
+ OptionsContext *o = optctx;
+ AVFormatContext *oc;
+ int i, err;
+ AVOutputFormat *file_oformat;
+ OutputStream *ost;
+ InputStream *ist;
+
+ if (!strcmp(filename, "-"))
+ filename = "pipe:";
+
+ err = avformat_alloc_output_context2(&oc, NULL, o->format, filename);
+ if (!oc) {
+ print_error(filename, err);
+ exit_program(1);
+ }
+
+ file_oformat= oc->oformat;
+
+ if (!strcmp(file_oformat->name, "ffm") &&
+ av_strstart(filename, "http:", NULL)) {
+ /* special case for files sent to ffserver: we get the stream
+ parameters from ffserver */
+ int err = read_ffserver_streams(o, oc, filename);
+ if (err < 0) {
+ print_error(filename, err);
+ exit_program(1);
+ }
+ } else if (!o->nb_stream_maps) {
+ /* pick the "best" stream of each type */
+#define NEW_STREAM(type, index)\
+ if (index >= 0) {\
+ ost = new_ ## type ## _stream(o, oc);\
+ ost->source_index = index;\
+ ost->sync_ist = &input_streams[index];\
+ input_streams[index].discard = 0;\
+ }
+
+ /* video: highest resolution */
+ if (!o->video_disable && oc->oformat->video_codec != CODEC_ID_NONE) {
+ int area = 0, idx = -1;
+ for (i = 0; i < nb_input_streams; i++) {
+ ist = &input_streams[i];
+ if (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO &&
+ ist->st->codec->width * ist->st->codec->height > area) {
+ area = ist->st->codec->width * ist->st->codec->height;
+ idx = i;
+ }
+ }
+ NEW_STREAM(video, idx);
+ }
+
+ /* audio: most channels */
+ if (!o->audio_disable && oc->oformat->audio_codec != CODEC_ID_NONE) {
+ int channels = 0, idx = -1;
+ for (i = 0; i < nb_input_streams; i++) {
+ ist = &input_streams[i];
+ if (ist->st->codec->codec_type == AVMEDIA_TYPE_AUDIO &&
+ ist->st->codec->channels > channels) {
+ channels = ist->st->codec->channels;
+ idx = i;
+ }
+ }
+ NEW_STREAM(audio, idx);
+ }
+
+ /* subtitles: pick first */
+ if (!o->subtitle_disable && oc->oformat->subtitle_codec != CODEC_ID_NONE) {
+ for (i = 0; i < nb_input_streams; i++)
+ if (input_streams[i].st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) {
+ NEW_STREAM(subtitle, i);
+ break;
+ }
+ }
+ /* do something with data? */
+ } else {
+ for (i = 0; i < o->nb_stream_maps; i++) {
+ StreamMap *map = &o->stream_maps[i];
+
+ if (map->disabled)
+ continue;
+
+ ist = &input_streams[input_files[map->file_index].ist_index + map->stream_index];
+ switch (ist->st->codec->codec_type) {
+ case AVMEDIA_TYPE_VIDEO: ost = new_video_stream(o, oc); break;
+ case AVMEDIA_TYPE_AUDIO: ost = new_audio_stream(o, oc); break;
+ case AVMEDIA_TYPE_SUBTITLE: ost = new_subtitle_stream(o, oc); break;
+ case AVMEDIA_TYPE_DATA: ost = new_data_stream(o, oc); break;
+ case AVMEDIA_TYPE_ATTACHMENT: ost = new_attachment_stream(o, oc); break;
+ default:
+ av_log(NULL, AV_LOG_FATAL, "Cannot map stream #%d.%d - unsupported type.\n",
+ map->file_index, map->stream_index);
+ exit_program(1);
+ }
+
+ ost->source_index = input_files[map->file_index].ist_index + map->stream_index;
+ ost->sync_ist = &input_streams[input_files[map->sync_file_index].ist_index +
+ map->sync_stream_index];
+ ist->discard = 0;
+ }
+ }
+
+ output_files = grow_array(output_files, sizeof(*output_files), &nb_output_files, nb_output_files + 1);
+ output_files[nb_output_files - 1].ctx = oc;
+ output_files[nb_output_files - 1].ost_index = nb_output_streams - oc->nb_streams;
+ output_files[nb_output_files - 1].recording_time = o->recording_time;
+ output_files[nb_output_files - 1].start_time = o->start_time;
+ output_files[nb_output_files - 1].limit_filesize = o->limit_filesize;
+ av_dict_copy(&output_files[nb_output_files - 1].opts, format_opts, 0);
+
+ /* check filename in case of an image number is expected */
+ if (oc->oformat->flags & AVFMT_NEEDNUMBER) {
+ if (!av_filename_number_test(oc->filename)) {
+ print_error(oc->filename, AVERROR(EINVAL));
+ exit_program(1);
+ }
+ }
+
+ if (!(oc->oformat->flags & AVFMT_NOFILE)) {
+ /* test if it already exists to avoid loosing precious files */
+ if (!file_overwrite &&
+ (strchr(filename, ':') == NULL ||
+ filename[1] == ':' ||
+ av_strstart(filename, "file:", NULL))) {
+ if (avio_check(filename, 0) == 0) {
+ if (!using_stdin) {
+ fprintf(stderr,"File '%s' already exists. Overwrite ? [y/N] ", filename);
+ fflush(stderr);
+ if (!read_yesno()) {
+ fprintf(stderr, "Not overwriting - exiting\n");
+ exit_program(1);
+ }
+ }
+ else {
+ fprintf(stderr,"File '%s' already exists. Exiting.\n", filename);
+ exit_program(1);
+ }
+ }
+ }
+
+ /* open the file */
+ if ((err = avio_open(&oc->pb, filename, AVIO_FLAG_WRITE)) < 0) {
+ print_error(filename, err);
+ exit_program(1);
+ }
+ }
+
+ oc->preload = (int)(o->mux_preload * AV_TIME_BASE);
+ oc->max_delay = (int)(o->mux_max_delay * AV_TIME_BASE);
+
+ /* copy chapters */
+ if (o->chapters_input_file >= nb_input_files) {
+ if (o->chapters_input_file == INT_MAX) {
+ /* copy chapters from the first input file that has them*/
+ o->chapters_input_file = -1;
+ for (i = 0; i < nb_input_files; i++)
+ if (input_files[i].ctx->nb_chapters) {
+ o->chapters_input_file = i;
+ break;
+ }
+ } else {
+ av_log(NULL, AV_LOG_FATAL, "Invalid input file index %d in chapter mapping.\n",
+ o->chapters_input_file);
+ exit_program(1);
+ }
+ }
+ if (o->chapters_input_file >= 0)
+ copy_chapters(&input_files[o->chapters_input_file], &output_files[nb_output_files - 1],
+ !o->metadata_chapters_manual);
+
+ /* copy metadata */
+ for (i = 0; i < o->nb_meta_data_maps; i++) {
+ AVFormatContext *files[2];
+ AVDictionary **meta[2];
+ int j;
+
+#define METADATA_CHECK_INDEX(index, nb_elems, desc)\
+ if ((index) < 0 || (index) >= (nb_elems)) {\
+ av_log(NULL, AV_LOG_FATAL, "Invalid %s index %d while processing metadata maps\n",\
+ (desc), (index));\
+ exit_program(1);\
+ }
+
+ int in_file_index = o->meta_data_maps[i][1].file;
+ if (in_file_index < 0)
+ continue;
+ METADATA_CHECK_INDEX(in_file_index, nb_input_files, "input file")
+
+ files[0] = oc;
+ files[1] = input_files[in_file_index].ctx;
+
+ for (j = 0; j < 2; j++) {
+ MetadataMap *map = &o->meta_data_maps[i][j];
+
+ switch (map->type) {
+ case 'g':
+ meta[j] = &files[j]->metadata;
+ break;
+ case 's':
+ METADATA_CHECK_INDEX(map->index, files[j]->nb_streams, "stream")
+ meta[j] = &files[j]->streams[map->index]->metadata;
+ break;
+ case 'c':
+ METADATA_CHECK_INDEX(map->index, files[j]->nb_chapters, "chapter")
+ meta[j] = &files[j]->chapters[map->index]->metadata;
+ break;
+ case 'p':
+ METADATA_CHECK_INDEX(map->index, files[j]->nb_programs, "program")
+ meta[j] = &files[j]->programs[map->index]->metadata;
+ break;
+ }
+ }
+
+ av_dict_copy(meta[0], *meta[1], AV_DICT_DONT_OVERWRITE);
+ }
+
+ /* copy global metadata by default */
+ if (!o->metadata_global_manual && nb_input_files)
+ av_dict_copy(&oc->metadata, input_files[0].ctx->metadata,
+ AV_DICT_DONT_OVERWRITE);
+ if (!o->metadata_streams_manual)
+ for (i = output_files[nb_output_files - 1].ost_index; i < nb_output_streams; i++) {
+ InputStream *ist = &input_streams[output_streams[i].source_index];
+ av_dict_copy(&output_streams[i].st->metadata, ist->st->metadata, AV_DICT_DONT_OVERWRITE);
+ }
+
+ /* process manually set metadata */
+ for (i = 0; i < o->nb_metadata; i++) {
+ AVDictionary **m;
+ char type, *val;
+ int index = 0;
+
+ val = strchr(o->metadata[i].u.str, '=');
+ if (!val) {
+ av_log(NULL, AV_LOG_FATAL, "No '=' character in metadata string %s.\n",
+ o->metadata[i].u.str);
+ exit_program(1);
+ }
+ *val++ = 0;
+
+ parse_meta_type(o->metadata[i].specifier, &type, &index);
+ switch (type) {
+ case 'g':
+ m = &oc->metadata;
+ break;
+ case 's':
+ if (index < 0 || index >= oc->nb_streams) {
+ av_log(NULL, AV_LOG_FATAL, "Invalid stream index %d in metadata specifier.\n", index);
+ exit_program(1);
+ }
+ m = &oc->streams[index]->metadata;
+ break;
+ case 'c':
+ if (index < 0 || index >= oc->nb_chapters) {
+ av_log(NULL, AV_LOG_FATAL, "Invalid chapter index %d in metadata specifier.\n", index);
+ exit_program(1);
+ }
+ m = &oc->chapters[index]->metadata;
+ break;
+ default:
+ av_log(NULL, AV_LOG_FATAL, "Invalid metadata specifier %s.\n", o->metadata[i].specifier);
+ exit_program(1);
+ }
+
+ av_dict_set(m, o->metadata[i].u.str, *val ? val : NULL, 0);
+ }
+
+ reset_options(o);
+}
+
+/* same option as mencoder */
+static int opt_pass(const char *opt, const char *arg)
+{
+ do_pass = parse_number_or_die(opt, arg, OPT_INT, 1, 2);
+ return 0;
+}
+
+static int64_t getutime(void)
+{
+#if HAVE_GETRUSAGE
+ struct rusage rusage;
+
+ getrusage(RUSAGE_SELF, &rusage);
+ return (rusage.ru_utime.tv_sec * 1000000LL) + rusage.ru_utime.tv_usec;
+#elif HAVE_GETPROCESSTIMES
+ HANDLE proc;
+ FILETIME c, e, k, u;
+ proc = GetCurrentProcess();
+ GetProcessTimes(proc, &c, &e, &k, &u);
+ return ((int64_t) u.dwHighDateTime << 32 | u.dwLowDateTime) / 10;
+#else
+ return av_gettime();
+#endif
+}
+
+static int64_t getmaxrss(void)
+{
+#if HAVE_GETRUSAGE && HAVE_STRUCT_RUSAGE_RU_MAXRSS
+ struct rusage rusage;
+ getrusage(RUSAGE_SELF, &rusage);
+ return (int64_t)rusage.ru_maxrss * 1024;
+#elif HAVE_GETPROCESSMEMORYINFO
+ HANDLE proc;
+ PROCESS_MEMORY_COUNTERS memcounters;
+ proc = GetCurrentProcess();
+ memcounters.cb = sizeof(memcounters);
+ GetProcessMemoryInfo(proc, &memcounters, sizeof(memcounters));
+ return memcounters.PeakPagefileUsage;
+#else
+ return 0;
+#endif
+}
+
+static int opt_audio_qscale(OptionsContext *o, const char *opt, const char *arg)
+{
+ return parse_option(o, "q:a", arg, options);
+}
+
+static void show_usage(void)
+{
+ printf("Hyper fast Audio and Video encoder\n");
+ printf("usage: %s [options] [[infile options] -i infile]... {[outfile options] outfile}...\n", program_name);
+ printf("\n");
+}
+
+static int opt_help(const char *opt, const char *arg)
+{
+ int flags = AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_ENCODING_PARAM;
+ av_log_set_callback(log_callback_help);
+ show_usage();
+ show_help_options(options, "Main options:\n",
+ OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_SUBTITLE | OPT_GRAB, 0);
+ show_help_options(options, "\nAdvanced options:\n",
+ OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_SUBTITLE | OPT_GRAB,
+ OPT_EXPERT);
+ show_help_options(options, "\nVideo options:\n",
+ OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_GRAB,
+ OPT_VIDEO);
+ show_help_options(options, "\nAdvanced Video options:\n",
+ OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_GRAB,
+ OPT_VIDEO | OPT_EXPERT);
+ show_help_options(options, "\nAudio options:\n",
+ OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_GRAB,
+ OPT_AUDIO);
+ show_help_options(options, "\nAdvanced Audio options:\n",
+ OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_GRAB,
+ OPT_AUDIO | OPT_EXPERT);
+ show_help_options(options, "\nSubtitle options:\n",
+ OPT_SUBTITLE | OPT_GRAB,
+ OPT_SUBTITLE);
+ show_help_options(options, "\nAudio/Video grab options:\n",
+ OPT_GRAB,
+ OPT_GRAB);
+ printf("\n");
+ show_help_children(avcodec_get_class(), flags);
+ show_help_children(avformat_get_class(), flags);
+ show_help_children(sws_get_class(), flags);
+
+ return 0;
+}
+
+static int opt_target(OptionsContext *o, const char *opt, const char *arg)
+{
+ enum { PAL, NTSC, FILM, UNKNOWN } norm = UNKNOWN;
+ static const char *const frame_rates[] = {"25", "30000/1001", "24000/1001"};
+
+ if(!strncmp(arg, "pal-", 4)) {
+ norm = PAL;
+ arg += 4;
+ } else if(!strncmp(arg, "ntsc-", 5)) {
+ norm = NTSC;
+ arg += 5;
+ } else if(!strncmp(arg, "film-", 5)) {
+ norm = FILM;
+ arg += 5;
+ } else {
+ /* Try to determine PAL/NTSC by peeking in the input files */
+ if(nb_input_files) {
+ int i, j, fr;
+ for (j = 0; j < nb_input_files; j++) {
+ for (i = 0; i < input_files[j].nb_streams; i++) {
+ AVCodecContext *c = input_files[j].ctx->streams[i]->codec;
+ if(c->codec_type != AVMEDIA_TYPE_VIDEO)
+ continue;
+ fr = c->time_base.den * 1000 / c->time_base.num;
+ if(fr == 25000) {
+ norm = PAL;
+ break;
+ } else if((fr == 29970) || (fr == 23976)) {
+ norm = NTSC;
+ break;
+ }
+ }
+ if(norm != UNKNOWN)
+ break;
+ }
+ }
+ if (norm != UNKNOWN)
+ av_log(NULL, AV_LOG_INFO, "Assuming %s for target.\n", norm == PAL ? "PAL" : "NTSC");
+ }
+
+ if(norm == UNKNOWN) {
+ av_log(NULL, AV_LOG_FATAL, "Could not determine norm (PAL/NTSC/NTSC-Film) for target.\n");
+ av_log(NULL, AV_LOG_FATAL, "Please prefix target with \"pal-\", \"ntsc-\" or \"film-\",\n");
+ av_log(NULL, AV_LOG_FATAL, "or set a framerate with \"-r xxx\".\n");
+ exit_program(1);
+ }
+
+ if(!strcmp(arg, "vcd")) {
+ opt_video_codec(o, "c:v", "mpeg1video");
+ opt_audio_codec(o, "c:a", "mp2");
+ parse_option(o, "f", "vcd", options);
+
+ parse_option(o, "s", norm == PAL ? "352x288" : "352x240", options);
+ parse_option(o, "r", frame_rates[norm], options);
+ opt_default("g", norm == PAL ? "15" : "18");
+
+ opt_default("b", "1150000");
+ opt_default("maxrate", "1150000");
+ opt_default("minrate", "1150000");
+ opt_default("bufsize", "327680"); // 40*1024*8;
+
+ opt_default("b:a", "224000");
+ parse_option(o, "ar", "44100", options);
+ parse_option(o, "ac", "2", options);
+
+ opt_default("packetsize", "2324");
+ opt_default("muxrate", "1411200"); // 2352 * 75 * 8;
+
+ /* We have to offset the PTS, so that it is consistent with the SCR.
+ SCR starts at 36000, but the first two packs contain only padding
+ and the first pack from the other stream, respectively, may also have
+ been written before.
+ So the real data starts at SCR 36000+3*1200. */
+ o->mux_preload = (36000+3*1200) / 90000.0; //0.44
+ } else if(!strcmp(arg, "svcd")) {
+
+ opt_video_codec(o, "c:v", "mpeg2video");
+ opt_audio_codec(o, "c:a", "mp2");
+ parse_option(o, "f", "svcd", options);
+
+ parse_option(o, "s", norm == PAL ? "480x576" : "480x480", options);
+ parse_option(o, "r", frame_rates[norm], options);
+ opt_default("g", norm == PAL ? "15" : "18");
+
+ opt_default("b", "2040000");
+ opt_default("maxrate", "2516000");
+ opt_default("minrate", "0"); //1145000;
+ opt_default("bufsize", "1835008"); //224*1024*8;
+ opt_default("flags", "+scan_offset");
+
+
+ opt_default("b:a", "224000");
+ parse_option(o, "ar", "44100", options);
+
+ opt_default("packetsize", "2324");
+
+ } else if(!strcmp(arg, "dvd")) {
+
+ opt_video_codec(o, "c:v", "mpeg2video");
+ opt_audio_codec(o, "c:a", "ac3");
+ parse_option(o, "f", "dvd", options);
+
+ parse_option(o, "s", norm == PAL ? "720x576" : "720x480", options);
+ parse_option(o, "r", frame_rates[norm], options);
+ opt_default("g", norm == PAL ? "15" : "18");
+
+ opt_default("b", "6000000");
+ opt_default("maxrate", "9000000");
+ opt_default("minrate", "0"); //1500000;
+ opt_default("bufsize", "1835008"); //224*1024*8;
+
+ opt_default("packetsize", "2048"); // from www.mpucoder.com: DVD sectors contain 2048 bytes of data, this is also the size of one pack.
+ opt_default("muxrate", "10080000"); // from mplex project: data_rate = 1260000. mux_rate = data_rate * 8
+
+ opt_default("b:a", "448000");
+ parse_option(o, "ar", "48000", options);
+
+ } else if(!strncmp(arg, "dv", 2)) {
+
+ parse_option(o, "f", "dv", options);
+
+ parse_option(o, "s", norm == PAL ? "720x576" : "720x480", options);
+ parse_option(o, "pix_fmt", !strncmp(arg, "dv50", 4) ? "yuv422p" :
+ norm == PAL ? "yuv420p" : "yuv411p", options);
+ parse_option(o, "r", frame_rates[norm], options);
+
+ parse_option(o, "ar", "48000", options);
+ parse_option(o, "ac", "2", options);
+
+ } else {
+ av_log(NULL, AV_LOG_ERROR, "Unknown target: %s\n", arg);
+ return AVERROR(EINVAL);
+ }
+ return 0;
+}
+
+static int opt_vstats_file(const char *opt, const char *arg)
+{
+ av_free (vstats_filename);
+ vstats_filename=av_strdup (arg);
+ return 0;
+}
+
+static int opt_vstats(const char *opt, const char *arg)
+{
+ char filename[40];
+ time_t today2 = time(NULL);
+ struct tm *today = localtime(&today2);
+
+ snprintf(filename, sizeof(filename), "vstats_%02d%02d%02d.log", today->tm_hour, today->tm_min,
+ today->tm_sec);
+ return opt_vstats_file(opt, filename);
+}
+
+static int opt_video_frames(OptionsContext *o, const char *opt, const char *arg)
+{
+ return parse_option(o, "frames:v", arg, options);
+}
+
+static int opt_audio_frames(OptionsContext *o, const char *opt, const char *arg)
+{
+ return parse_option(o, "frames:a", arg, options);
+}
+
+static int opt_data_frames(OptionsContext *o, const char *opt, const char *arg)
+{
+ return parse_option(o, "frames:d", arg, options);
+}
+
+static void log_callback_null(void* ptr, int level, const char* fmt, va_list vl)
+{
+}
+
+static int opt_passlogfile(const char *opt, const char *arg)
+{
+ pass_logfilename_prefix = arg;
+#if CONFIG_LIBX264_ENCODER
+ return opt_default("passlogfile", arg);
+#else
+ return 0;
+#endif
+}
+
+static int opt_video_tag(OptionsContext *o, const char *opt, const char *arg)
+{
+ return parse_option(o, "tag:v", arg, options);
+}
+
+static int opt_audio_tag(OptionsContext *o, const char *opt, const char *arg)
+{
+ return parse_option(o, "tag:a", arg, options);
+}
+
+static int opt_subtitle_tag(OptionsContext *o, const char *opt, const char *arg)
+{
+ return parse_option(o, "tag:s", arg, options);
+}
+
+static int opt_video_filters(OptionsContext *o, const char *opt, const char *arg)
+{
+ return parse_option(o, "filter:v", arg, options);
+}
+
+#define OFFSET(x) offsetof(OptionsContext, x)
+static const OptionDef options[] = {
+ /* main options */
+#include "cmdutils_common_opts.h"
+ { "f", HAS_ARG | OPT_STRING | OPT_OFFSET, {.off = OFFSET(format)}, "force format", "fmt" },
+ { "i", HAS_ARG | OPT_FUNC2, {(void*)opt_input_file}, "input file name", "filename" },
+ { "y", OPT_BOOL, {(void*)&file_overwrite}, "overwrite output files" },
+ { "c", HAS_ARG | OPT_STRING | OPT_SPEC, {.off = OFFSET(codec_names)}, "codec name", "codec" },
+ { "codec", HAS_ARG | OPT_STRING | OPT_SPEC, {.off = OFFSET(codec_names)}, "codec name", "codec" },
+ { "pre", HAS_ARG | OPT_STRING | OPT_SPEC, {.off = OFFSET(presets)}, "preset name", "preset" },
+ { "map", HAS_ARG | OPT_EXPERT | OPT_FUNC2, {(void*)opt_map}, "set input stream mapping", "file.stream[:syncfile.syncstream]" },
+ { "map_metadata", HAS_ARG | OPT_EXPERT | OPT_FUNC2, {(void*)opt_map_metadata}, "set metadata information of outfile from infile",
+ "outfile[,metadata]:infile[,metadata]" },
+ { "map_chapters", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_OFFSET, {.off = OFFSET(chapters_input_file)}, "set chapters mapping", "input_file_index" },
+ { "t", HAS_ARG | OPT_TIME | OPT_OFFSET, {.off = OFFSET(recording_time)}, "record or transcode \"duration\" seconds of audio/video", "duration" },
+ { "fs", HAS_ARG | OPT_INT64 | OPT_OFFSET, {.off = OFFSET(limit_filesize)}, "set the limit file size in bytes", "limit_size" }, //
+ { "ss", HAS_ARG | OPT_TIME | OPT_OFFSET, {.off = OFFSET(start_time)}, "set the start time offset", "time_off" },
+ { "itsoffset", HAS_ARG | OPT_TIME | OPT_OFFSET, {.off = OFFSET(input_ts_offset)}, "set the input ts offset", "time_off" },
+ { "itsscale", HAS_ARG | OPT_DOUBLE | OPT_SPEC, {.off = OFFSET(ts_scale)}, "set the input ts scale", "scale" },
+ { "metadata", HAS_ARG | OPT_STRING | OPT_SPEC, {.off = OFFSET(metadata)}, "add metadata", "string=string" },
+ { "dframes", HAS_ARG | OPT_FUNC2, {(void*)opt_data_frames}, "set the number of data frames to record", "number" },
+ { "benchmark", OPT_BOOL | OPT_EXPERT, {(void*)&do_benchmark},
+ "add timings for benchmarking" },
+ { "timelimit", HAS_ARG, {(void*)opt_timelimit}, "set max runtime in seconds", "limit" },
+ { "dump", OPT_BOOL | OPT_EXPERT, {(void*)&do_pkt_dump},
+ "dump each input packet" },
+ { "hex", OPT_BOOL | OPT_EXPERT, {(void*)&do_hex_dump},
+ "when dumping packets, also dump the payload" },
+ { "re", OPT_BOOL | OPT_EXPERT | OPT_OFFSET, {.off = OFFSET(rate_emu)}, "read input at native frame rate", "" },
+ { "target", HAS_ARG | OPT_FUNC2, {(void*)opt_target}, "specify target file type (\"vcd\", \"svcd\", \"dvd\", \"dv\", \"dv50\", \"pal-vcd\", \"ntsc-svcd\", ...)", "type" },
+ { "vsync", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&video_sync_method}, "video sync method", "" },
+ { "async", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&audio_sync_method}, "audio sync method", "" },
+ { "adrift_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, {(void*)&audio_drift_threshold}, "audio drift threshold", "threshold" },
+ { "copyts", OPT_BOOL | OPT_EXPERT, {(void*)&copy_ts}, "copy timestamps" },
+ { "copytb", OPT_BOOL | OPT_EXPERT, {(void*)&copy_tb}, "copy input stream time base when stream copying" },
+ { "shortest", OPT_BOOL | OPT_EXPERT, {(void*)&opt_shortest}, "finish encoding within shortest input" }, //
+ { "dts_delta_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, {(void*)&dts_delta_threshold}, "timestamp discontinuity delta threshold", "threshold" },
+ { "xerror", OPT_BOOL, {(void*)&exit_on_error}, "exit on error", "error" },
+ { "copyinkf", OPT_BOOL | OPT_EXPERT, {(void*)&copy_initial_nonkeyframes}, "copy initial non-keyframes" },
+ { "frames", OPT_INT64 | HAS_ARG | OPT_SPEC, {.off = OFFSET(max_frames)}, "set the number of frames to record", "number" },
+ { "tag", OPT_STRING | HAS_ARG | OPT_SPEC, {.off = OFFSET(codec_tags)}, "force codec tag/fourcc", "fourcc/tag" },
+ { "q", HAS_ARG | OPT_EXPERT | OPT_DOUBLE | OPT_SPEC, {.off = OFFSET(qscale)}, "use fixed quality scale (VBR)", "q" },
+ { "qscale", HAS_ARG | OPT_EXPERT | OPT_DOUBLE | OPT_SPEC, {.off = OFFSET(qscale)}, "use fixed quality scale (VBR)", "q" },
+#if CONFIG_AVFILTER
+ { "filter", HAS_ARG | OPT_STRING | OPT_SPEC, {.off = OFFSET(filters)}, "set stream filterchain", "filter_list" },
+#endif
+ { "stats", OPT_BOOL, {&print_stats}, "print progress report during encoding", },
+
+ /* video options */
+ { "vframes", HAS_ARG | OPT_VIDEO | OPT_FUNC2, {(void*)opt_video_frames}, "set the number of video frames to record", "number" },
+ { "r", HAS_ARG | OPT_VIDEO | OPT_STRING | OPT_SPEC, {.off = OFFSET(frame_rates)}, "set frame rate (Hz value, fraction or abbreviation)", "rate" },
+ { "s", HAS_ARG | OPT_VIDEO | OPT_STRING | OPT_SPEC, {.off = OFFSET(frame_sizes)}, "set frame size (WxH or abbreviation)", "size" },
+ { "aspect", HAS_ARG | OPT_VIDEO | OPT_STRING | OPT_SPEC, {.off = OFFSET(frame_aspect_ratios)}, "set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)", "aspect" },
+ { "pix_fmt", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_STRING | OPT_SPEC, {.off = OFFSET(frame_pix_fmts)}, "set pixel format", "format" },
+ { "bits_per_raw_sample", OPT_INT | HAS_ARG | OPT_VIDEO, {(void*)&frame_bits_per_raw_sample}, "set the number of bits per raw sample", "number" },
+ { "vn", OPT_BOOL | OPT_VIDEO | OPT_OFFSET, {.off = OFFSET(video_disable)}, "disable video" },
+ { "vdt", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)&video_discard}, "discard threshold", "n" },
+ { "rc_override", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_STRING | OPT_SPEC, {.off = OFFSET(rc_overrides)}, "rate control override for specific intervals", "override" },
+ { "vcodec", HAS_ARG | OPT_VIDEO | OPT_FUNC2, {(void*)opt_video_codec}, "force video codec ('copy' to copy stream)", "codec" },
+ { "same_quant", OPT_BOOL | OPT_VIDEO, {(void*)&same_quant},
+ "use same quantizer as source (implies VBR)" },
+ { "pass", HAS_ARG | OPT_VIDEO, {(void*)opt_pass}, "select the pass number (1 or 2)", "n" },
+ { "passlogfile", HAS_ARG | OPT_VIDEO, {(void*)&opt_passlogfile}, "select two pass log file name prefix", "prefix" },
+ { "deinterlace", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&do_deinterlace},
+ "deinterlace pictures" },
+ { "vstats", OPT_EXPERT | OPT_VIDEO, {(void*)&opt_vstats}, "dump video coding statistics to file" },
+ { "vstats_file", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_vstats_file}, "dump video coding statistics to file", "file" },
+#if CONFIG_AVFILTER
+ { "vf", HAS_ARG | OPT_VIDEO | OPT_FUNC2, {(void*)opt_video_filters}, "video filters", "filter list" },
+#endif
+ { "intra_matrix", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_STRING | OPT_SPEC, {.off = OFFSET(intra_matrices)}, "specify intra matrix coeffs", "matrix" },
+ { "inter_matrix", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_STRING | OPT_SPEC, {.off = OFFSET(inter_matrices)}, "specify inter matrix coeffs", "matrix" },
+ { "top", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_INT| OPT_SPEC, {.off = OFFSET(top_field_first)}, "top=1/bottom=0/auto=-1 field first", "" },
+ { "dc", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)&intra_dc_precision}, "intra_dc_precision", "precision" },
+ { "vtag", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_FUNC2, {(void*)opt_video_tag}, "force video tag/fourcc", "fourcc/tag" },
+ { "qphist", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, { (void *)&qp_hist }, "show QP histogram" },
+ { "force_fps", OPT_BOOL | OPT_EXPERT | OPT_VIDEO | OPT_SPEC, {.off = OFFSET(force_fps)}, "force the selected framerate, disable the best supported framerate selection" },
+ { "streamid", HAS_ARG | OPT_EXPERT | OPT_FUNC2, {(void*)opt_streamid}, "set the value of an outfile streamid", "streamIndex:value" },
+ { "force_key_frames", OPT_STRING | HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_SPEC, {.off = OFFSET(forced_key_frames)}, "force key frames at specified timestamps", "timestamps" },
+
+ /* audio options */
+ { "aframes", HAS_ARG | OPT_AUDIO | OPT_FUNC2, {(void*)opt_audio_frames}, "set the number of audio frames to record", "number" },
+ { "aq", HAS_ARG | OPT_AUDIO | OPT_FUNC2, {(void*)opt_audio_qscale}, "set audio quality (codec-specific)", "quality", },
+ { "ar", HAS_ARG | OPT_AUDIO | OPT_INT | OPT_SPEC, {.off = OFFSET(audio_sample_rate)}, "set audio sampling rate (in Hz)", "rate" },
+ { "ac", HAS_ARG | OPT_AUDIO | OPT_INT | OPT_SPEC, {.off = OFFSET(audio_channels)}, "set number of audio channels", "channels" },
+ { "an", OPT_BOOL | OPT_AUDIO | OPT_OFFSET, {.off = OFFSET(audio_disable)}, "disable audio" },
+ { "acodec", HAS_ARG | OPT_AUDIO | OPT_FUNC2, {(void*)opt_audio_codec}, "force audio codec ('copy' to copy stream)", "codec" },
+ { "atag", HAS_ARG | OPT_EXPERT | OPT_AUDIO | OPT_FUNC2, {(void*)opt_audio_tag}, "force audio tag/fourcc", "fourcc/tag" },
+ { "vol", OPT_INT | HAS_ARG | OPT_AUDIO, {(void*)&audio_volume}, "change audio volume (256=normal)" , "volume" }, //
+ { "sample_fmt", HAS_ARG | OPT_EXPERT | OPT_AUDIO | OPT_SPEC | OPT_STRING, {.off = OFFSET(sample_fmts)}, "set sample format", "format" },
+
+ /* subtitle options */
+ { "sn", OPT_BOOL | OPT_SUBTITLE | OPT_OFFSET, {.off = OFFSET(subtitle_disable)}, "disable subtitle" },
+ { "scodec", HAS_ARG | OPT_SUBTITLE | OPT_FUNC2, {(void*)opt_subtitle_codec}, "force subtitle codec ('copy' to copy stream)", "codec" },
+ { "stag", HAS_ARG | OPT_EXPERT | OPT_SUBTITLE | OPT_FUNC2, {(void*)opt_subtitle_tag}, "force subtitle tag/fourcc", "fourcc/tag" },
+
+ /* grab options */
+ { "isync", OPT_BOOL | OPT_EXPERT | OPT_GRAB, {(void*)&input_sync}, "sync read on input", "" },
+
+ /* muxer options */
+ { "muxdelay", OPT_FLOAT | HAS_ARG | OPT_EXPERT | OPT_OFFSET, {.off = OFFSET(mux_max_delay)}, "set the maximum demux-decode delay", "seconds" },
+ { "muxpreload", OPT_FLOAT | HAS_ARG | OPT_EXPERT | OPT_OFFSET, {.off = OFFSET(mux_preload)}, "set the initial demux-decode delay", "seconds" },
+
+ { "bsf", HAS_ARG | OPT_STRING | OPT_SPEC, {.off = OFFSET(bitstream_filters)}, "A comma-separated list of bitstream filters", "bitstream_filters" },
+
+ /* data codec support */
+ { "dcodec", HAS_ARG | OPT_DATA | OPT_FUNC2, {(void*)opt_data_codec}, "force data codec ('copy' to copy stream)", "codec" },
+
+ { "default", HAS_ARG | OPT_AUDIO | OPT_VIDEO | OPT_EXPERT, {(void*)opt_default}, "generic catch all option", "" },
+ { NULL, },
+};
+
+int main(int argc, char **argv)
+{
+ OptionsContext o = { 0 };
+ int64_t ti;
+
+ reset_options(&o);
+
+ av_log_set_flags(AV_LOG_SKIP_REPEATED);
+ parse_loglevel(argc, argv, options);
+
+ if(argc>1 && !strcmp(argv[1], "-d")){
+ run_as_daemon=1;
+ av_log_set_callback(log_callback_null);
+ argc--;
+ argv++;
+ }
+
+ avcodec_register_all();
+#if CONFIG_AVDEVICE
+ avdevice_register_all();
+#endif
+#if CONFIG_AVFILTER
+ avfilter_register_all();
+#endif
+ av_register_all();
+
+#if HAVE_ISATTY
+ if(isatty(STDIN_FILENO))
+ avio_set_interrupt_cb(decode_interrupt_cb);
+#endif
+
+ show_banner();
+
+ /* parse options */
+ parse_options(&o, argc, argv, options, opt_output_file);
+
+ if(nb_output_files <= 0 && nb_input_files == 0) {
+ show_usage();
+ av_log(NULL, AV_LOG_WARNING, "Use -h to get full help or, even better, run 'man %s'\n", program_name);
+ exit_program(1);
+ }
+
+ /* file converter / grab */
+ if (nb_output_files <= 0) {
+ fprintf(stderr, "At least one output file must be specified\n");
+ exit_program(1);
+ }
+
+ if (nb_input_files == 0) {
+ av_log(NULL, AV_LOG_FATAL, "At least one input file must be specified\n");
+ exit_program(1);
+ }
+
+ ti = getutime();
+ if (transcode(output_files, nb_output_files, input_files, nb_input_files) < 0)
+ exit_program(1);
+ ti = getutime() - ti;
+ if (do_benchmark) {
+ int maxrss = getmaxrss() / 1024;
+ printf("bench: utime=%0.3fs maxrss=%ikB\n", ti / 1000000.0, maxrss);
+ }
+
+ exit_program(0);
+ return 0;
+}
diff --git a/cmdutils.c b/cmdutils.c
index 943a77c82c..00c5d71144 100644
--- a/cmdutils.c
+++ b/cmdutils.c
@@ -2,20 +2,20 @@
* Various utilities for command line tools
* Copyright (c) 2000-2003 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -49,22 +49,13 @@
#include <sys/resource.h>
#endif
-const char **opt_names;
-const char **opt_values;
-static int opt_name_count;
-AVCodecContext *avcodec_opts[AVMEDIA_TYPE_NB];
-AVFormatContext *avformat_opts;
struct SwsContext *sws_opts;
-AVDictionary *format_opts, *video_opts, *audio_opts, *sub_opts;
+AVDictionary *format_opts, *codec_opts;
static const int this_year = 2011;
void init_opts(void)
{
- int i;
- for (i = 0; i < AVMEDIA_TYPE_NB; i++)
- avcodec_opts[i] = avcodec_alloc_context2(i);
- avformat_opts = avformat_alloc_context();
#if CONFIG_SWSCALE
sws_opts = sws_getContext(16, 16, 0, 16, 16, 0, SWS_BICUBIC, NULL, NULL, NULL);
#endif
@@ -72,30 +63,12 @@ void init_opts(void)
void uninit_opts(void)
{
- int i;
- for (i = 0; i < AVMEDIA_TYPE_NB; i++)
- av_freep(&avcodec_opts[i]);
- av_freep(&avformat_opts->key);
- av_freep(&avformat_opts);
#if CONFIG_SWSCALE
sws_freeContext(sws_opts);
sws_opts = NULL;
#endif
- for (i = 0; i < opt_name_count; i++) {
- //opt_values are only stored for codec-specific options in which case
- //both the name and value are dup'd
- if (opt_values[i]) {
- av_freep(&opt_names[i]);
- av_freep(&opt_values[i]);
- }
- }
- av_freep(&opt_names);
- av_freep(&opt_values);
- opt_name_count = 0;
av_dict_free(&format_opts);
- av_dict_free(&video_opts);
- av_dict_free(&audio_opts);
- av_dict_free(&sub_opts);
+ av_dict_free(&codec_opts);
}
void log_callback_help(void* ptr, int level, const char* fmt, va_list vl)
@@ -118,17 +91,18 @@ double parse_number_or_die(const char *context, const char *numstr, int type, do
error= "Expected int for %s but found %s\n";
else
return d;
- fprintf(stderr, error, context, numstr, min, max);
- exit(1);
+ av_log(NULL, AV_LOG_FATAL, error, context, numstr, min, max);
+ exit_program(1);
+ return 0;
}
int64_t parse_time_or_die(const char *context, const char *timestr, int is_duration)
{
int64_t us;
if (av_parse_time(&us, timestr, is_duration) < 0) {
- fprintf(stderr, "Invalid %s specification for %s: %s\n",
- is_duration ? "duration" : "date", context, timestr);
- exit(1);
+ av_log(NULL, AV_LOG_FATAL, "Invalid %s specification for %s: %s\n",
+ is_duration ? "duration" : "date", context, timestr);
+ exit_program(1);
}
return us;
}
@@ -156,9 +130,22 @@ void show_help_options(const OptionDef *options, const char *msg, int mask, int
}
}
+void show_help_children(const AVClass *class, int flags)
+{
+ const AVClass *child = NULL;
+ av_opt_show2(&class, NULL, flags, 0);
+ printf("\n");
+
+ while (child = av_opt_child_class_next(class, child))
+ show_help_children(child, flags);
+}
+
static const OptionDef* find_option(const OptionDef *po, const char *name){
+ const char *p = strchr(name, ':');
+ int len = p ? p - name : strlen(name);
+
while (po->name != NULL) {
- if (!strcmp(name, po->name))
+ if (!strncmp(name, po->name, len) && strlen(po->name) == len)
break;
po++;
}
@@ -226,12 +213,82 @@ static inline void prepare_app_arguments(int *argc_ptr, char ***argv_ptr)
}
#endif /* WIN32 && !__MINGW32CE__ */
-void parse_options(int argc, char **argv, const OptionDef *options,
- void (* parse_arg_function)(const char*))
+
+int parse_option(void *optctx, const char *opt, const char *arg, const OptionDef *options)
{
- const char *opt, *arg;
- int optindex, handleoptions=1;
const OptionDef *po;
+ int bool_val = 1;
+ int *dstcount;
+ void *dst;
+
+ po = find_option(options, opt);
+ if (!po->name && opt[0] == 'n' && opt[1] == 'o') {
+ /* handle 'no' bool option */
+ po = find_option(options, opt + 2);
+ if (!(po->name && (po->flags & OPT_BOOL)))
+ goto unknown_opt;
+ bool_val = 0;
+ }
+ if (!po->name)
+ po = find_option(options, "default");
+ if (!po->name) {
+unknown_opt:
+ av_log(NULL, AV_LOG_ERROR, "Unrecognized option '%s'\n", opt);
+ return AVERROR(EINVAL);
+ }
+ if (po->flags & HAS_ARG && !arg) {
+ av_log(NULL, AV_LOG_ERROR, "Missing argument for option '%s'\n", opt);
+ return AVERROR(EINVAL);
+ }
+
+ /* new-style options contain an offset into optctx, old-style address of
+ * a global var*/
+ dst = po->flags & (OPT_OFFSET|OPT_SPEC) ? (uint8_t*)optctx + po->u.off : po->u.dst_ptr;
+
+ if (po->flags & OPT_SPEC) {
+ SpecifierOpt **so = dst;
+ char *p = strchr(opt, ':');
+
+ dstcount = (int*)(so + 1);
+ *so = grow_array(*so, sizeof(**so), dstcount, *dstcount + 1);
+ (*so)[*dstcount - 1].specifier = av_strdup(p ? p + 1 : "");
+ dst = &(*so)[*dstcount - 1].u;
+ }
+
+ if (po->flags & OPT_STRING) {
+ char *str;
+ str = av_strdup(arg);
+ *(char**)dst = str;
+ } else if (po->flags & OPT_BOOL) {
+ *(int*)dst = bool_val;
+ } else if (po->flags & OPT_INT) {
+ *(int*)dst = parse_number_or_die(opt, arg, OPT_INT64, INT_MIN, INT_MAX);
+ } else if (po->flags & OPT_INT64) {
+ *(int64_t*)dst = parse_number_or_die(opt, arg, OPT_INT64, INT64_MIN, INT64_MAX);
+ } else if (po->flags & OPT_TIME) {
+ *(int64_t*)dst = parse_time_or_die(opt, arg, 1);
+ } else if (po->flags & OPT_FLOAT) {
+ *(float*)dst = parse_number_or_die(opt, arg, OPT_FLOAT, -INFINITY, INFINITY);
+ } else if (po->flags & OPT_DOUBLE) {
+ *(double*)dst = parse_number_or_die(opt, arg, OPT_DOUBLE, -INFINITY, INFINITY);
+ } else if (po->u.func_arg) {
+ int ret = po->flags & OPT_FUNC2 ? po->u.func2_arg(optctx, opt, arg) :
+ po->u.func_arg(opt, arg);
+ if (ret < 0) {
+ av_log(NULL, AV_LOG_ERROR, "Failed to set value '%s' for option '%s'\n", arg, opt);
+ return ret;
+ }
+ }
+ if (po->flags & OPT_EXIT)
+ exit_program(0);
+ return !!(po->flags & HAS_ARG);
+}
+
+void parse_options(void *optctx, int argc, char **argv, const OptionDef *options,
+ void (* parse_arg_function)(void *, const char*))
+{
+ const char *opt;
+ int optindex, handleoptions = 1, ret;
/* perform system-dependent conversions for arguments list */
prepare_app_arguments(&argc, &argv);
@@ -242,159 +299,95 @@ void parse_options(int argc, char **argv, const OptionDef *options,
opt = argv[optindex++];
if (handleoptions && opt[0] == '-' && opt[1] != '\0') {
- int bool_val = 1;
if (opt[1] == '-' && opt[2] == '\0') {
handleoptions = 0;
continue;
}
opt++;
- po= find_option(options, opt);
- if (!po->name && opt[0] == 'n' && opt[1] == 'o') {
- /* handle 'no' bool option */
- po = find_option(options, opt + 2);
- if (!(po->name && (po->flags & OPT_BOOL)))
- goto unknown_opt;
- bool_val = 0;
- }
- if (!po->name)
- po= find_option(options, "default");
- if (!po->name) {
-unknown_opt:
- fprintf(stderr, "%s: unrecognized option '%s'\n", argv[0], opt);
- exit(1);
- }
- arg = NULL;
- if (po->flags & HAS_ARG) {
- arg = argv[optindex++];
- if (!arg) {
- fprintf(stderr, "%s: missing argument for option '%s'\n", argv[0], opt);
- exit(1);
- }
- }
- if (po->flags & OPT_STRING) {
- char *str;
- str = av_strdup(arg);
- *po->u.str_arg = str;
- } else if (po->flags & OPT_BOOL) {
- *po->u.int_arg = bool_val;
- } else if (po->flags & OPT_INT) {
- *po->u.int_arg = parse_number_or_die(opt, arg, OPT_INT64, INT_MIN, INT_MAX);
- } else if (po->flags & OPT_INT64) {
- *po->u.int64_arg = parse_number_or_die(opt, arg, OPT_INT64, INT64_MIN, INT64_MAX);
- } else if (po->flags & OPT_FLOAT) {
- *po->u.float_arg = parse_number_or_die(opt, arg, OPT_FLOAT, -INFINITY, INFINITY);
- } else if (po->u.func_arg) {
- if (po->u.func_arg(opt, arg) < 0) {
- fprintf(stderr, "%s: failed to set value '%s' for option '%s'\n", argv[0], arg, opt);
- exit(1);
- }
- }
- if(po->flags & OPT_EXIT)
- exit(0);
+
+ if ((ret = parse_option(optctx, opt, argv[optindex], options)) < 0)
+ exit_program(1);
+ optindex += ret;
} else {
if (parse_arg_function)
- parse_arg_function(opt);
+ parse_arg_function(optctx, opt);
}
}
}
-#define FLAGS (o->type == FF_OPT_TYPE_FLAGS) ? AV_DICT_APPEND : 0
-#define SET_PREFIXED_OPTS(ch, flag, output) \
- if (opt[0] == ch && avcodec_opts[0] && (o = av_opt_find(avcodec_opts[0], opt+1, NULL, flag, 0)))\
- av_dict_set(&output, opt+1, arg, FLAGS);
-static int opt_default2(const char *opt, const char *arg)
-{
- const AVOption *o;
- if ((o = av_opt_find(avcodec_opts[0], opt, NULL, 0, AV_OPT_SEARCH_CHILDREN))) {
- if (o->flags & AV_OPT_FLAG_VIDEO_PARAM)
- av_dict_set(&video_opts, opt, arg, FLAGS);
- if (o->flags & AV_OPT_FLAG_AUDIO_PARAM)
- av_dict_set(&audio_opts, opt, arg, FLAGS);
- if (o->flags & AV_OPT_FLAG_SUBTITLE_PARAM)
- av_dict_set(&sub_opts, opt, arg, FLAGS);
- } else if ((o = av_opt_find(avformat_opts, opt, NULL, 0, AV_OPT_SEARCH_CHILDREN)))
- av_dict_set(&format_opts, opt, arg, FLAGS);
- else if ((o = av_opt_find(sws_opts, opt, NULL, 0, AV_OPT_SEARCH_CHILDREN))) {
+/*
+ * Return index of option opt in argv or 0 if not found.
+ */
+static int locate_option(int argc, char **argv, const OptionDef *options, const char *optname)
+{
+ const OptionDef *po;
+ int i;
+
+ for (i = 1; i < argc; i++) {
+ const char *cur_opt = argv[i];
+
+ if (*cur_opt++ != '-')
+ continue;
+
+ po = find_option(options, cur_opt);
+ if (!po->name && cur_opt[0] == 'n' && cur_opt[1] == 'o')
+ po = find_option(options, cur_opt + 2);
+
+ if ((!po->name && !strcmp(cur_opt, optname)) ||
+ (po->name && !strcmp(optname, po->name)))
+ return i;
+
+ if (!po || po->flags & HAS_ARG)
+ i++;
+ }
+ return 0;
+}
+
+void parse_loglevel(int argc, char **argv, const OptionDef *options)
+{
+ int idx = locate_option(argc, argv, options, "loglevel");
+ if (!idx)
+ idx = locate_option(argc, argv, options, "v");
+ if (idx && argv[idx + 1])
+ opt_loglevel("loglevel", argv[idx + 1]);
+}
+
+#define FLAGS(o) ((o)->type == AV_OPT_TYPE_FLAGS) ? AV_DICT_APPEND : 0
+int opt_default(const char *opt, const char *arg)
+{
+ const AVOption *oc, *of, *os;
+ char opt_stripped[128];
+ const char *p;
+ const AVClass *cc = avcodec_get_class(), *fc = avformat_get_class(), *sc;
+
+ if (!(p = strchr(opt, ':')))
+ p = opt + strlen(opt);
+ av_strlcpy(opt_stripped, opt, FFMIN(sizeof(opt_stripped), p - opt + 1));
+
+ if ((oc = av_opt_find(&cc, opt_stripped, NULL, 0, AV_OPT_SEARCH_CHILDREN|AV_OPT_SEARCH_FAKE_OBJ)) ||
+ ((opt[0] == 'v' || opt[0] == 'a' || opt[0] == 's') &&
+ (oc = av_opt_find(&cc, opt+1, NULL, 0, AV_OPT_SEARCH_FAKE_OBJ))))
+ av_dict_set(&codec_opts, opt, arg, FLAGS(oc));
+ if ((of = av_opt_find(&fc, opt, NULL, 0, AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ)))
+ av_dict_set(&format_opts, opt, arg, FLAGS(of));
+#if CONFIG_SWSCALE
+ sc = sws_get_class();
+ if ((os = av_opt_find(&sc, opt, NULL, 0, AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) {
// XXX we only support sws_flags, not arbitrary sws options
- int ret = av_set_string3(sws_opts, opt, arg, 1, NULL);
+ int ret = av_opt_set(sws_opts, opt, arg, 0);
if (ret < 0) {
av_log(NULL, AV_LOG_ERROR, "Error setting option %s.\n", opt);
return ret;
}
}
+#endif
- if (!o) {
- SET_PREFIXED_OPTS('v', AV_OPT_FLAG_VIDEO_PARAM, video_opts)
- SET_PREFIXED_OPTS('a', AV_OPT_FLAG_AUDIO_PARAM, audio_opts)
- SET_PREFIXED_OPTS('s', AV_OPT_FLAG_SUBTITLE_PARAM, sub_opts)
- }
-
- if (o)
+ if (oc || of || os)
return 0;
- fprintf(stderr, "Unrecognized option '%s'\n", opt);
+ av_log(NULL, AV_LOG_ERROR, "Unrecognized option '%s'\n", opt);
return AVERROR_OPTION_NOT_FOUND;
}
-int opt_default(const char *opt, const char *arg){
- int type;
- int ret= 0;
- const AVOption *o= NULL;
- int opt_types[]={AV_OPT_FLAG_VIDEO_PARAM, AV_OPT_FLAG_AUDIO_PARAM, 0, AV_OPT_FLAG_SUBTITLE_PARAM, 0};
-
- for(type=0; *avcodec_opts && type<AVMEDIA_TYPE_NB && ret>= 0; type++){
- const AVOption *o2 = av_opt_find(avcodec_opts[0], opt, NULL, opt_types[type], 0);
- if(o2)
- ret = av_set_string3(avcodec_opts[type], opt, arg, 1, &o);
- }
- if(!o && avformat_opts)
- ret = av_set_string3(avformat_opts, opt, arg, 1, &o);
- if(!o && sws_opts)
- ret = av_set_string3(sws_opts, opt, arg, 1, &o);
- if(!o){
- if (opt[0] == 'a' && avcodec_opts[AVMEDIA_TYPE_AUDIO])
- ret = av_set_string3(avcodec_opts[AVMEDIA_TYPE_AUDIO], opt+1, arg, 1, &o);
- else if(opt[0] == 'v' && avcodec_opts[AVMEDIA_TYPE_VIDEO])
- ret = av_set_string3(avcodec_opts[AVMEDIA_TYPE_VIDEO], opt+1, arg, 1, &o);
- else if(opt[0] == 's' && avcodec_opts[AVMEDIA_TYPE_SUBTITLE])
- ret = av_set_string3(avcodec_opts[AVMEDIA_TYPE_SUBTITLE], opt+1, arg, 1, &o);
- }
- if (o && ret < 0) {
- fprintf(stderr, "Invalid value '%s' for option '%s'\n", arg, opt);
- exit(1);
- }
- if (!o) {
- AVCodec *p = NULL;
- AVOutputFormat *oformat = NULL;
- while ((p=av_codec_next(p))){
- const AVClass *c = p->priv_class;
- if(c && av_opt_find(&c, opt, NULL, 0, 0))
- break;
- }
- if (!p) {
- while ((oformat = av_oformat_next(oformat))) {
- const AVClass *c = oformat->priv_class;
- if (c && av_opt_find(&c, opt, NULL, 0, 0))
- break;
- }
- }
- }
-
- if ((ret = opt_default2(opt, arg)) < 0)
- return ret;
-
-// av_log(NULL, AV_LOG_ERROR, "%s:%s: %f 0x%0X\n", opt, arg, av_get_double(avcodec_opts, opt, NULL), (int)av_get_int(avcodec_opts, opt, NULL));
-
- //FIXME we should always use avcodec_opts, ... for storing options so there will not be any need to keep track of what i set over this
- opt_values= av_realloc(opt_values, sizeof(void*)*(opt_name_count+1));
- opt_values[opt_name_count]= o ? NULL : av_strdup(arg);
- opt_names= av_realloc(opt_names, sizeof(void*)*(opt_name_count+1));
- opt_names[opt_name_count++]= o ? o->name : av_strdup(opt);
-
- if ((*avcodec_opts && avcodec_opts[0]->debug) || (avformat_opts && avformat_opts->debug))
- av_log_set_level(AV_LOG_DEBUG);
- return 0;
-}
-
int opt_loglevel(const char *opt, const char *arg)
{
const struct { const char *name; int level; } log_levels[] = {
@@ -420,16 +413,22 @@ int opt_loglevel(const char *opt, const char *arg)
level = strtol(arg, &tail, 10);
if (*tail) {
- fprintf(stderr, "Invalid loglevel \"%s\". "
- "Possible levels are numbers or:\n", arg);
+ av_log(NULL, AV_LOG_FATAL, "Invalid loglevel \"%s\". "
+ "Possible levels are numbers or:\n", arg);
for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++)
- fprintf(stderr, "\"%s\"\n", log_levels[i].name);
- exit(1);
+ av_log(NULL, AV_LOG_FATAL, "\"%s\"\n", log_levels[i].name);
+ exit_program(1);
}
av_log_set_level(level);
return 0;
}
+int opt_codec_debug(const char *opt, const char *arg)
+{
+ av_log_set_level(AV_LOG_DEBUG);
+ return opt_default(opt, arg);
+}
+
int opt_timelimit(const char *opt, const char *arg)
{
#if HAVE_SETRLIMIT
@@ -438,43 +437,11 @@ int opt_timelimit(const char *opt, const char *arg)
if (setrlimit(RLIMIT_CPU, &rl))
perror("setrlimit");
#else
- fprintf(stderr, "Warning: -%s not implemented on this OS\n", opt);
+ av_log(NULL, AV_LOG_WARNING, "-%s not implemented on this OS\n", opt);
#endif
return 0;
}
-void set_context_opts(void *ctx, void *opts_ctx, int flags, AVCodec *codec)
-{
- int i;
- void *priv_ctx=NULL;
- if(!strcmp("AVCodecContext", (*(AVClass**)ctx)->class_name)){
- AVCodecContext *avctx= ctx;
- if(codec && codec->priv_class && avctx->priv_data){
- priv_ctx= avctx->priv_data;
- }
- } else if (!strcmp("AVFormatContext", (*(AVClass**)ctx)->class_name)) {
- AVFormatContext *avctx = ctx;
- if (avctx->oformat && avctx->oformat->priv_class) {
- priv_ctx = avctx->priv_data;
- }
- }
-
- for(i=0; i<opt_name_count; i++){
- char buf[256];
- const AVOption *opt;
- const char *str= av_get_string(opts_ctx, opt_names[i], &opt, buf, sizeof(buf));
- /* if an option with name opt_names[i] is present in opts_ctx then str is non-NULL */
- if(str && ((opt->flags & flags) == flags))
- av_set_string3(ctx, opt_names[i], str, 1, NULL);
- /* We need to use a differnt system to pass options to the private context because
- it is not known which codec and thus context kind that will be when parsing options
- we thus use opt_values directly instead of opts_ctx */
- if(!str && priv_ctx && av_get_string(priv_ctx, opt_names[i], &opt, buf, sizeof(buf))){
- av_set_string3(priv_ctx, opt_names[i], opt_values[i], 1, NULL);
- }
- }
-}
-
void print_error(const char *filename, int err)
{
char errbuf[128];
@@ -482,7 +449,7 @@ void print_error(const char *filename, int err)
if (av_strerror(err, errbuf, sizeof(errbuf)) < 0)
errbuf_ptr = strerror(AVUNERROR(err));
- fprintf(stderr, "%s: %s\n", filename, errbuf_ptr);
+ av_log(NULL, AV_LOG_ERROR, "%s: %s\n", filename, errbuf_ptr);
}
static int warned_cfg = 0;
@@ -491,61 +458,63 @@ static int warned_cfg = 0;
#define SHOW_VERSION 2
#define SHOW_CONFIG 4
-#define PRINT_LIB_INFO(outstream,libname,LIBNAME,flags) \
+#define PRINT_LIB_INFO(libname, LIBNAME, flags, level) \
if (CONFIG_##LIBNAME) { \
const char *indent = flags & INDENT? " " : ""; \
if (flags & SHOW_VERSION) { \
unsigned int version = libname##_version(); \
- fprintf(outstream, "%slib%-9s %2d.%3d.%2d / %2d.%3d.%2d\n", \
- indent, #libname, \
- LIB##LIBNAME##_VERSION_MAJOR, \
- LIB##LIBNAME##_VERSION_MINOR, \
- LIB##LIBNAME##_VERSION_MICRO, \
- version >> 16, version >> 8 & 0xff, version & 0xff); \
+ av_log(NULL, level, "%slib%-9s %2d.%3d.%2d / %2d.%3d.%2d\n",\
+ indent, #libname, \
+ LIB##LIBNAME##_VERSION_MAJOR, \
+ LIB##LIBNAME##_VERSION_MINOR, \
+ LIB##LIBNAME##_VERSION_MICRO, \
+ version >> 16, version >> 8 & 0xff, version & 0xff); \
} \
if (flags & SHOW_CONFIG) { \
const char *cfg = libname##_configuration(); \
- if (strcmp(LIBAV_CONFIGURATION, cfg)) { \
+ if (strcmp(FFMPEG_CONFIGURATION, cfg)) { \
if (!warned_cfg) { \
- fprintf(outstream, \
+ av_log(NULL, level, \
"%sWARNING: library configuration mismatch\n", \
indent); \
warned_cfg = 1; \
} \
- fprintf(stderr, "%s%-11s configuration: %s\n", \
+ av_log(NULL, level, "%s%-11s configuration: %s\n", \
indent, #libname, cfg); \
} \
} \
} \
-static void print_all_libs_info(FILE* outstream, int flags)
+static void print_all_libs_info(int flags, int level)
{
- PRINT_LIB_INFO(outstream, avutil, AVUTIL, flags);
- PRINT_LIB_INFO(outstream, avcodec, AVCODEC, flags);
- PRINT_LIB_INFO(outstream, avformat, AVFORMAT, flags);
- PRINT_LIB_INFO(outstream, avdevice, AVDEVICE, flags);
- PRINT_LIB_INFO(outstream, avfilter, AVFILTER, flags);
- PRINT_LIB_INFO(outstream, swscale, SWSCALE, flags);
- PRINT_LIB_INFO(outstream, postproc, POSTPROC, flags);
+ PRINT_LIB_INFO(avutil, AVUTIL, flags, level);
+ PRINT_LIB_INFO(avcodec, AVCODEC, flags, level);
+ PRINT_LIB_INFO(avformat, AVFORMAT, flags, level);
+ PRINT_LIB_INFO(avdevice, AVDEVICE, flags, level);
+ PRINT_LIB_INFO(avfilter, AVFILTER, flags, level);
+ PRINT_LIB_INFO(swscale, SWSCALE, flags, level);
+ PRINT_LIB_INFO(postproc, POSTPROC, flags, level);
}
void show_banner(void)
{
- fprintf(stderr, "%s version " LIBAV_VERSION ", Copyright (c) %d-%d the Libav developers\n",
- program_name, program_birth_year, this_year);
- fprintf(stderr, " built on %s %s with %s %s\n",
- __DATE__, __TIME__, CC_TYPE, CC_VERSION);
- fprintf(stderr, " configuration: " LIBAV_CONFIGURATION "\n");
- print_all_libs_info(stderr, INDENT|SHOW_CONFIG);
- print_all_libs_info(stderr, INDENT|SHOW_VERSION);
-}
-
-void show_version(void) {
- printf("%s " LIBAV_VERSION "\n", program_name);
- print_all_libs_info(stdout, SHOW_VERSION);
+ av_log(NULL, AV_LOG_INFO, "%s version " FFMPEG_VERSION ", Copyright (c) %d-%d the FFmpeg developers\n",
+ program_name, program_birth_year, this_year);
+ av_log(NULL, AV_LOG_INFO, " built on %s %s with %s %s\n",
+ __DATE__, __TIME__, CC_TYPE, CC_VERSION);
+ av_log(NULL, AV_LOG_INFO, " configuration: " FFMPEG_CONFIGURATION "\n");
+ print_all_libs_info(INDENT|SHOW_CONFIG, AV_LOG_INFO);
+ print_all_libs_info(INDENT|SHOW_VERSION, AV_LOG_INFO);
+}
+
+int opt_version(const char *opt, const char *arg) {
+ av_log_set_callback(log_callback_help);
+ printf("%s " FFMPEG_VERSION "\n", program_name);
+ print_all_libs_info(SHOW_VERSION, AV_LOG_INFO);
+ return 0;
}
-void show_license(void)
+int opt_license(const char *opt, const char *arg)
{
printf(
#if CONFIG_NONFREE
@@ -612,9 +581,10 @@ void show_license(void)
program_name, program_name, program_name
#endif
);
+ return 0;
}
-void show_formats(void)
+int opt_formats(const char *opt, const char *arg)
{
AVInputFormat *ifmt=NULL;
AVOutputFormat *ofmt=NULL;
@@ -661,9 +631,10 @@ void show_formats(void)
name,
long_name ? long_name:" ");
}
+ return 0;
}
-void show_codecs(void)
+int opt_codecs(const char *opt, const char *arg)
{
AVCodec *p=NULL, *p2;
const char *last_name;
@@ -737,9 +708,10 @@ void show_codecs(void)
"even though both encoding and decoding are supported. For example, the h263\n"
"decoder corresponds to the h263 and h263p encoders, for file formats it is even\n"
"worse.\n");
+ return 0;
}
-void show_bsfs(void)
+int opt_bsfs(const char *opt, const char *arg)
{
AVBitStreamFilter *bsf=NULL;
@@ -747,23 +719,29 @@ void show_bsfs(void)
while((bsf = av_bitstream_filter_next(bsf)))
printf("%s\n", bsf->name);
printf("\n");
+ return 0;
}
-void show_protocols(void)
+int opt_protocols(const char *opt, const char *arg)
{
- void *opaque = NULL;
- const char *name;
+ URLProtocol *up=NULL;
printf("Supported file protocols:\n"
- "Input:\n");
- while ((name = avio_enum_protocols(&opaque, 0)))
- printf("%s\n", name);
- printf("Output:\n");
- while ((name = avio_enum_protocols(&opaque, 1)))
- printf("%s\n", name);
+ "I.. = Input supported\n"
+ ".O. = Output supported\n"
+ "..S = Seek supported\n"
+ "FLAGS NAME\n"
+ "----- \n");
+ while((up = av_protocol_next(up)))
+ printf("%c%c%c %s\n",
+ up->url_read ? 'I' : '.',
+ up->url_write ? 'O' : '.',
+ up->url_seek ? 'S' : '.',
+ up->name);
+ return 0;
}
-void show_filters(void)
+int opt_filters(const char *opt, const char *arg)
{
AVFilter av_unused(**filter) = NULL;
@@ -772,9 +750,10 @@ void show_filters(void)
while ((filter = av_filter_next(filter)) && *filter)
printf("%-16s %s\n", (*filter)->name, (*filter)->description);
#endif
+ return 0;
}
-void show_pix_fmts(void)
+int opt_pix_fmts(const char *opt, const char *arg)
{
enum PixelFormat pix_fmt;
@@ -805,6 +784,16 @@ void show_pix_fmts(void)
pix_desc->nb_components,
av_get_bits_per_pixel(pix_desc));
}
+ return 0;
+}
+
+int show_sample_fmts(const char *opt, const char *arg)
+{
+ int i;
+ char fmt_str[128];
+ for (i = -1; i < AV_SAMPLE_FMT_NB; i++)
+ printf("%s\n", av_get_sample_fmt_string(fmt_str, sizeof(fmt_str), i));
+ return 0;
}
int read_yesno(void)
@@ -823,7 +812,7 @@ int read_file(const char *filename, char **bufptr, size_t *size)
FILE *f = fopen(filename, "rb");
if (!f) {
- fprintf(stderr, "Cannot read file '%s': %s\n", filename, strerror(errno));
+ av_log(NULL, AV_LOG_ERROR, "Cannot read file '%s': %s\n", filename, strerror(errno));
return AVERROR(errno);
}
fseek(f, 0, SEEK_END);
@@ -831,7 +820,7 @@ int read_file(const char *filename, char **bufptr, size_t *size)
fseek(f, 0, SEEK_SET);
*bufptr = av_malloc(*size + 1);
if (!*bufptr) {
- fprintf(stderr, "Could not allocate file buffer\n");
+ av_log(NULL, AV_LOG_ERROR, "Could not allocate file buffer\n");
fclose(f);
return AVERROR(ENOMEM);
}
@@ -842,33 +831,6 @@ int read_file(const char *filename, char **bufptr, size_t *size)
return 0;
}
-void init_pts_correction(PtsCorrectionContext *ctx)
-{
- ctx->num_faulty_pts = ctx->num_faulty_dts = 0;
- ctx->last_pts = ctx->last_dts = INT64_MIN;
-}
-
-int64_t guess_correct_pts(PtsCorrectionContext *ctx, int64_t reordered_pts, int64_t dts)
-{
- int64_t pts = AV_NOPTS_VALUE;
-
- if (dts != AV_NOPTS_VALUE) {
- ctx->num_faulty_dts += dts <= ctx->last_dts;
- ctx->last_dts = dts;
- }
- if (reordered_pts != AV_NOPTS_VALUE) {
- ctx->num_faulty_pts += reordered_pts <= ctx->last_pts;
- ctx->last_pts = reordered_pts;
- }
- if ((ctx->num_faulty_pts<=ctx->num_faulty_dts || dts == AV_NOPTS_VALUE)
- && reordered_pts != AV_NOPTS_VALUE)
- pts = reordered_pts;
- else
- pts = dts;
-
- return pts;
-}
-
FILE *get_preset_file(char *filename, size_t filename_size,
const char *preset_name, int is_path, const char *codec_name)
{
@@ -883,6 +845,23 @@ FILE *get_preset_file(char *filename, size_t filename_size,
av_strlcpy(filename, preset_name, filename_size);
f = fopen(filename, "r");
} else {
+#ifdef _WIN32
+ char datadir[MAX_PATH], *ls;
+ base[2] = NULL;
+
+ if (GetModuleFileNameA(GetModuleHandleA(NULL), datadir, sizeof(datadir) - 1))
+ {
+ for (ls = datadir; ls < datadir + strlen(datadir); ls++)
+ if (*ls == '\\') *ls = '/';
+
+ if (ls = strrchr(datadir, '/'))
+ {
+ *ls = 0;
+ strncat(datadir, "/ffpresets", sizeof(datadir) - 1 - strlen(datadir));
+ base[2] = datadir;
+ }
+ }
+#endif
for (i = 0; i < 3 && !f; i++) {
if (!base[i])
continue;
@@ -899,67 +878,131 @@ FILE *get_preset_file(char *filename, size_t filename_size,
return f;
}
-#if CONFIG_AVFILTER
-
-static int ffsink_init(AVFilterContext *ctx, const char *args, void *opaque)
+int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
{
- FFSinkContext *priv = ctx->priv;
+ if (*spec <= '9' && *spec >= '0') /* opt:index */
+ return strtol(spec, NULL, 0) == st->index;
+ else if (*spec == 'v' || *spec == 'a' || *spec == 's' || *spec == 'd' || *spec == 't') { /* opt:[vasdt] */
+ enum AVMediaType type;
+
+ switch (*spec++) {
+ case 'v': type = AVMEDIA_TYPE_VIDEO; break;
+ case 'a': type = AVMEDIA_TYPE_AUDIO; break;
+ case 's': type = AVMEDIA_TYPE_SUBTITLE; break;
+ case 'd': type = AVMEDIA_TYPE_DATA; break;
+ case 't': type = AVMEDIA_TYPE_ATTACHMENT; break;
+ default: abort(); // never reached, silence warning
+ }
+ if (type != st->codec->codec_type)
+ return 0;
+ if (*spec++ == ':') { /* possibly followed by :index */
+ int i, index = strtol(spec, NULL, 0);
+ for (i = 0; i < s->nb_streams; i++)
+ if (s->streams[i]->codec->codec_type == type && index-- == 0)
+ return i == st->index;
+ return 0;
+ }
+ return 1;
+ } else if (*spec == 'p' && *(spec + 1) == ':') {
+ int prog_id, i, j;
+ char *endptr;
+ spec += 2;
+ prog_id = strtol(spec, &endptr, 0);
+ for (i = 0; i < s->nb_programs; i++) {
+ if (s->programs[i]->id != prog_id)
+ continue;
- if (!opaque)
- return AVERROR(EINVAL);
- *priv = *(FFSinkContext *)opaque;
+ if (*endptr++ == ':') {
+ int stream_idx = strtol(endptr, NULL, 0);
+ return (stream_idx >= 0 && stream_idx < s->programs[i]->nb_stream_indexes &&
+ st->index == s->programs[i]->stream_index[stream_idx]);
+ }
- return 0;
-}
+ for (j = 0; j < s->programs[i]->nb_stream_indexes; j++)
+ if (st->index == s->programs[i]->stream_index[j])
+ return 1;
+ }
+ return 0;
+ } else if (!*spec) /* empty specifier, matches everything */
+ return 1;
-static void null_end_frame(AVFilterLink *inlink) { }
+ av_log(s, AV_LOG_ERROR, "Invalid stream specifier: %s.\n", spec);
+ return AVERROR(EINVAL);
+}
-static int ffsink_query_formats(AVFilterContext *ctx)
+AVDictionary *filter_codec_opts(AVDictionary *opts, enum CodecID codec_id, AVFormatContext *s, AVStream *st)
{
- FFSinkContext *priv = ctx->priv;
- enum PixelFormat pix_fmts[] = { priv->pix_fmt, PIX_FMT_NONE };
+ AVDictionary *ret = NULL;
+ AVDictionaryEntry *t = NULL;
+ AVCodec *codec = s->oformat ? avcodec_find_encoder(codec_id) : avcodec_find_decoder(codec_id);
+ int flags = s->oformat ? AV_OPT_FLAG_ENCODING_PARAM : AV_OPT_FLAG_DECODING_PARAM;
+ char prefix = 0;
+ const AVClass *cc = avcodec_get_class();
+
+ if (!codec)
+ return NULL;
+
+ switch (codec->type) {
+ case AVMEDIA_TYPE_VIDEO: prefix = 'v'; flags |= AV_OPT_FLAG_VIDEO_PARAM; break;
+ case AVMEDIA_TYPE_AUDIO: prefix = 'a'; flags |= AV_OPT_FLAG_AUDIO_PARAM; break;
+ case AVMEDIA_TYPE_SUBTITLE: prefix = 's'; flags |= AV_OPT_FLAG_SUBTITLE_PARAM; break;
+ }
- avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts));
- return 0;
-}
+ while (t = av_dict_get(opts, "", t, AV_DICT_IGNORE_SUFFIX)) {
+ char *p = strchr(t->key, ':');
-AVFilter ffsink = {
- .name = "ffsink",
- .priv_size = sizeof(FFSinkContext),
- .init = ffsink_init,
+ /* check stream specification in opt name */
+ if (p)
+ switch (check_stream_specifier(s, st, p + 1)) {
+ case 1: *p = 0; break;
+ case 0: continue;
+ default: return NULL;
+ }
- .query_formats = ffsink_query_formats,
+ if (av_opt_find(&cc, t->key, NULL, flags, AV_OPT_SEARCH_FAKE_OBJ) ||
+ (codec && codec->priv_class && av_opt_find(&codec->priv_class, t->key, NULL, flags, AV_OPT_SEARCH_FAKE_OBJ)))
+ av_dict_set(&ret, t->key, t->value, 0);
+ else if (t->key[0] == prefix && av_opt_find(&cc, t->key+1, NULL, flags, AV_OPT_SEARCH_FAKE_OBJ))
+ av_dict_set(&ret, t->key+1, t->value, 0);
- .inputs = (AVFilterPad[]) {{ .name = "default",
- .type = AVMEDIA_TYPE_VIDEO,
- .end_frame = null_end_frame,
- .min_perms = AV_PERM_READ, },
- { .name = NULL }},
- .outputs = (AVFilterPad[]) {{ .name = NULL }},
-};
+ if (p)
+ *p = ':';
+ }
+ return ret;
+}
-int get_filtered_video_frame(AVFilterContext *ctx, AVFrame *frame,
- AVFilterBufferRef **picref_ptr, AVRational *tb)
+AVDictionary **setup_find_stream_info_opts(AVFormatContext *s, AVDictionary *codec_opts)
{
- int ret;
- AVFilterBufferRef *picref;
-
- if ((ret = avfilter_request_frame(ctx->inputs[0])) < 0)
- return ret;
- if (!(picref = ctx->inputs[0]->cur_buf))
- return AVERROR(ENOENT);
- *picref_ptr = picref;
- ctx->inputs[0]->cur_buf = NULL;
- *tb = ctx->inputs[0]->time_base;
-
- memcpy(frame->data, picref->data, sizeof(frame->data));
- memcpy(frame->linesize, picref->linesize, sizeof(frame->linesize));
- frame->interlaced_frame = picref->video->interlaced;
- frame->top_field_first = picref->video->top_field_first;
- frame->key_frame = picref->video->key_frame;
- frame->pict_type = picref->video->pict_type;
-
- return 1;
+ int i;
+ AVDictionary **opts;
+
+ if (!s->nb_streams)
+ return NULL;
+ opts = av_mallocz(s->nb_streams * sizeof(*opts));
+ if (!opts) {
+ av_log(NULL, AV_LOG_ERROR, "Could not alloc memory for stream options.\n");
+ return NULL;
+ }
+ for (i = 0; i < s->nb_streams; i++)
+ opts[i] = filter_codec_opts(codec_opts, s->streams[i]->codec->codec_id, s, s->streams[i]);
+ return opts;
}
-#endif /* CONFIG_AVFILTER */
+void *grow_array(void *array, int elem_size, int *size, int new_size)
+{
+ if (new_size >= INT_MAX / elem_size) {
+ av_log(NULL, AV_LOG_ERROR, "Array too big.\n");
+ exit_program(1);
+ }
+ if (*size < new_size) {
+ uint8_t *tmp = av_realloc(array, new_size*elem_size);
+ if (!tmp) {
+ av_log(NULL, AV_LOG_ERROR, "Could not alloc buffer.\n");
+ exit_program(1);
+ }
+ memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size);
+ *size = new_size;
+ return tmp;
+ }
+ return array;
+}
diff --git a/cmdutils.h b/cmdutils.h
index 02fcea4426..6d2e82b4eb 100644
--- a/cmdutils.h
+++ b/cmdutils.h
@@ -2,25 +2,25 @@
* Various utilities for command line tools
* copyright (c) 2003 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef LIBAV_CMDUTILS_H
-#define LIBAV_CMDUTILS_H
+#ifndef FFMPEG_CMDUTILS_H
+#define FFMPEG_CMDUTILS_H
#include <stdint.h>
@@ -29,6 +29,10 @@
#include "libavformat/avformat.h"
#include "libswscale/swscale.h"
+#ifdef __MINGW32__
+#undef main /* We don't want SDL to override our main() */
+#endif
+
/**
* program name, defined by the program for show_version().
*/
@@ -39,11 +43,10 @@ extern const char program_name[];
*/
extern const int program_birth_year;
-extern const char **opt_names;
extern AVCodecContext *avcodec_opts[AVMEDIA_TYPE_NB];
extern AVFormatContext *avformat_opts;
extern struct SwsContext *sws_opts;
-extern AVDictionary *format_opts, *video_opts, *audio_opts, *sub_opts;
+extern AVDictionary *format_opts, *codec_opts;
/**
* Initialize the cmdutils option system, in particular
@@ -58,7 +61,7 @@ void uninit_opts(void);
/**
* Trivial log callback.
- * Only suitable for show_help and similar since it lacks prefix handling.
+ * Only suitable for opt_help and similar since it lacks prefix handling.
*/
void log_callback_help(void* ptr, int level, const char* fmt, va_list vl);
@@ -73,6 +76,8 @@ int opt_default(const char *opt, const char *arg);
*/
int opt_loglevel(const char *opt, const char *arg);
+int opt_codec_debug(const char *opt, const char *arg);
+
/**
* Limit the execution time.
*/
@@ -109,6 +114,17 @@ double parse_number_or_die(const char *context, const char *numstr, int type, do
*/
int64_t parse_time_or_die(const char *context, const char *timestr, int is_duration);
+typedef struct SpecifierOpt {
+ char *specifier; /**< stream/chapter/program/... specifier */
+ union {
+ uint8_t *str;
+ int i;
+ int64_t i64;
+ float f;
+ double dbl;
+ } u;
+} SpecifierOpt;
+
typedef struct {
const char *name;
int flags;
@@ -125,12 +141,18 @@ typedef struct {
#define OPT_INT64 0x0400
#define OPT_EXIT 0x0800
#define OPT_DATA 0x1000
+#define OPT_FUNC2 0x2000
+#define OPT_OFFSET 0x4000 /* option is specified as an offset in a passed optctx */
+#define OPT_SPEC 0x8000 /* option is to be stored in an array of SpecifierOpt.
+ Implies OPT_OFFSET. Next element after the offset is
+ an int containing element count in the array. */
+#define OPT_TIME 0x10000
+#define OPT_DOUBLE 0x20000
union {
- int *int_arg;
- char **str_arg;
- float *float_arg;
+ void *dst_ptr;
int (*func_arg)(const char *, const char *);
- int64_t *int64_arg;
+ int (*func2_arg)(void *, const char *, const char *);
+ size_t off;
} u;
const char *help;
const char *argname;
@@ -139,17 +161,71 @@ typedef struct {
void show_help_options(const OptionDef *options, const char *msg, int mask, int value);
/**
+ * Show help for all options with given flags in class and all its
+ * children.
+ */
+void show_help_children(const AVClass *class, int flags);
+
+/**
* Parse the command line arguments.
+ *
+ * @param optctx an opaque options context
* @param options Array with the definitions required to interpret every
* option of the form: -option_name [argument]
* @param parse_arg_function Name of the function called to process every
* argument without a leading option name flag. NULL if such arguments do
* not have to be processed.
*/
-void parse_options(int argc, char **argv, const OptionDef *options,
- void (* parse_arg_function)(const char*));
+void parse_options(void *optctx, int argc, char **argv, const OptionDef *options,
+ void (* parse_arg_function)(void *optctx, const char*));
+
+/**
+ * Parse one given option.
+ *
+ * @return on success 1 if arg was consumed, 0 otherwise; negative number on error
+ */
+int parse_option(void *optctx, const char *opt, const char *arg, const OptionDef *options);
+
+/**
+ * Find the '-loglevel' option in the commandline args and apply it.
+ */
+void parse_loglevel(int argc, char **argv, const OptionDef *options);
+
+/**
+ * Check if the given stream matches a stream specifier.
+ *
+ * @param s Corresponding format context.
+ * @param st Stream from s to be checked.
+ * @param spec A stream specifier of the [v|a|s|d]:[<stream index>] form.
+ *
+ * @return 1 if the stream matches, 0 if it doesn't, <0 on error
+ */
+int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec);
+
+/**
+ * Filter out options for given codec.
+ *
+ * Create a new options dictionary containing only the options from
+ * opts which apply to the codec with ID codec_id.
+ *
+ * @param s Corresponding format context.
+ * @param st A stream from s for which the options should be filtered.
+ * @return a pointer to the created dictionary
+ */
+AVDictionary *filter_codec_opts(AVDictionary *opts, enum CodecID codec_id, AVFormatContext *s, AVStream *st);
-void set_context_opts(void *ctx, void *opts_ctx, int flags, AVCodec *codec);
+/**
+ * Setup AVCodecContext options for avformat_find_stream_info().
+ *
+ * Create an array of dictionaries, one dictionary for each stream
+ * contained in s.
+ * Each dictionary will contain the options from codec_opts which can
+ * be applied to the corresponding stream codec context.
+ *
+ * @return pointer to the created array of dictionaries, NULL if it
+ * cannot be created
+ */
+AVDictionary **setup_find_stream_info_opts(AVFormatContext *s, AVDictionary *codec_opts);
/**
* Print an error message to stderr, indicating filename and a human
@@ -173,50 +249,64 @@ void show_banner(void);
* Print the version of the program to stdout. The version message
* depends on the current versions of the repository and of the libav*
* libraries.
+ * This option processing function does not utilize the arguments.
*/
-void show_version(void);
+int opt_version(const char *opt, const char *arg);
/**
* Print the license of the program to stdout. The license depends on
* the license of the libraries compiled into the program.
+ * This option processing function does not utilize the arguments.
*/
-void show_license(void);
+int opt_license(const char *opt, const char *arg);
/**
* Print a listing containing all the formats supported by the
* program.
+ * This option processing function does not utilize the arguments.
*/
-void show_formats(void);
+int opt_formats(const char *opt, const char *arg);
/**
* Print a listing containing all the codecs supported by the
* program.
+ * This option processing function does not utilize the arguments.
*/
-void show_codecs(void);
+int opt_codecs(const char *opt, const char *arg);
/**
* Print a listing containing all the filters supported by the
* program.
+ * This option processing function does not utilize the arguments.
*/
-void show_filters(void);
+int opt_filters(const char *opt, const char *arg);
/**
* Print a listing containing all the bit stream filters supported by the
* program.
+ * This option processing function does not utilize the arguments.
*/
-void show_bsfs(void);
+int opt_bsfs(const char *opt, const char *arg);
/**
* Print a listing containing all the protocols supported by the
* program.
+ * This option processing function does not utilize the arguments.
*/
-void show_protocols(void);
+int opt_protocols(const char *opt, const char *arg);
/**
* Print a listing containing all the pixel formats supported by the
* program.
+ * This option processing function does not utilize the arguments.
*/
-void show_pix_fmts(void);
+int opt_pix_fmts(const char *opt, const char *arg);
+
+/**
+ * Print a listing containing all the sample formats supported by the
+ * program.
+ */
+int show_sample_fmts(const char *opt, const char *arg);
/**
* Return a positive value if a line read from standard input
@@ -235,37 +325,14 @@ int read_yesno(void);
*/
int read_file(const char *filename, char **bufptr, size_t *size);
-typedef struct {
- int64_t num_faulty_pts; /// Number of incorrect PTS values so far
- int64_t num_faulty_dts; /// Number of incorrect DTS values so far
- int64_t last_pts; /// PTS of the last frame
- int64_t last_dts; /// DTS of the last frame
-} PtsCorrectionContext;
-
-/**
- * Reset the state of the PtsCorrectionContext.
- */
-void init_pts_correction(PtsCorrectionContext *ctx);
-
-/**
- * Attempt to guess proper monotonic timestamps for decoded video frames
- * which might have incorrect times. Input timestamps may wrap around, in
- * which case the output will as well.
- *
- * @param pts the pts field of the decoded AVPacket, as passed through
- * AVCodecContext.reordered_opaque
- * @param dts the dts field of the decoded AVPacket
- * @return one of the input values, may be AV_NOPTS_VALUE
- */
-int64_t guess_correct_pts(PtsCorrectionContext *ctx, int64_t pts, int64_t dts);
-
/**
* Get a file corresponding to a preset file.
*
* If is_path is non-zero, look for the file in the path preset_name.
* Otherwise search for a file named arg.ffpreset in the directories
* $FFMPEG_DATADIR (if set), $HOME/.ffmpeg, and in the datadir defined
- * at configuration time, in that order. If no such file is found and
+ * at configuration time or in a "ffpresets" folder along the executable
+ * on win32, in that order. If no such file is found and
* codec_name is defined, then search for a file named
* codec_name-preset_name.ffpreset in the above-mentioned directories.
*
@@ -279,19 +346,20 @@ int64_t guess_correct_pts(PtsCorrectionContext *ctx, int64_t pts, int64_t dts);
FILE *get_preset_file(char *filename, size_t filename_size,
const char *preset_name, int is_path, const char *codec_name);
-typedef struct {
- enum PixelFormat pix_fmt;
-} FFSinkContext;
-
-extern AVFilter ffsink;
+/**
+ * Do all the necessary cleanup and abort.
+ * This function is implemented in the avtools, not cmdutils.
+ */
+void exit_program(int ret);
/**
- * Extract a frame from sink.
+ * Realloc array to hold new_size elements of elem_size.
+ * Calls exit_program() on failure.
*
- * @return a negative error in case of failure, 1 if one frame has
- * been extracted successfully.
+ * @param elem_size size in bytes of each element
+ * @param size new element count will be written here
+ * @return reallocated array
*/
-int get_filtered_video_frame(AVFilterContext *sink, AVFrame *frame,
- AVFilterBufferRef **picref, AVRational *pts_tb);
+void *grow_array(void *array, int elem_size, int *size, int new_size);
-#endif /* LIBAV_CMDUTILS_H */
+#endif /* CMDUTILS_H */
diff --git a/cmdutils_common_opts.h b/cmdutils_common_opts.h
index 9b5e5d22cd..cced0bb895 100644
--- a/cmdutils_common_opts.h
+++ b/cmdutils_common_opts.h
@@ -1,13 +1,16 @@
- { "L", OPT_EXIT, {(void*)show_license}, "show license" },
- { "h", OPT_EXIT, {(void*)show_help}, "show help" },
- { "?", OPT_EXIT, {(void*)show_help}, "show help" },
- { "help", OPT_EXIT, {(void*)show_help}, "show help" },
- { "-help", OPT_EXIT, {(void*)show_help}, "show help" },
- { "version", OPT_EXIT, {(void*)show_version}, "show version" },
- { "formats" , OPT_EXIT, {(void*)show_formats }, "show available formats" },
- { "codecs" , OPT_EXIT, {(void*)show_codecs }, "show available codecs" },
- { "bsfs" , OPT_EXIT, {(void*)show_bsfs }, "show available bit stream filters" },
- { "protocols", OPT_EXIT, {(void*)show_protocols}, "show available protocols" },
- { "filters", OPT_EXIT, {(void*)show_filters }, "show available filters" },
- { "pix_fmts" , OPT_EXIT, {(void*)show_pix_fmts }, "show available pixel formats" },
+ { "L", OPT_EXIT, {(void*)opt_license}, "show license" },
+ { "h", OPT_EXIT, {(void*)opt_help}, "show help" },
+ { "?", OPT_EXIT, {(void*)opt_help}, "show help" },
+ { "help", OPT_EXIT, {(void*)opt_help}, "show help" },
+ { "-help", OPT_EXIT, {(void*)opt_help}, "show help" },
+ { "version", OPT_EXIT, {(void*)opt_version}, "show version" },
+ { "formats" , OPT_EXIT, {(void*)opt_formats }, "show available formats" },
+ { "codecs" , OPT_EXIT, {(void*)opt_codecs }, "show available codecs" },
+ { "bsfs" , OPT_EXIT, {(void*)opt_bsfs }, "show available bit stream filters" },
+ { "protocols", OPT_EXIT, {(void*)opt_protocols}, "show available protocols" },
+ { "filters", OPT_EXIT, {(void*)opt_filters }, "show available filters" },
+ { "pix_fmts" , OPT_EXIT, {(void*)opt_pix_fmts }, "show available pixel formats" },
+ { "sample_fmts", OPT_EXIT, {.func_arg = show_sample_fmts }, "show available audio sample formats" },
{ "loglevel", HAS_ARG, {(void*)opt_loglevel}, "set libav* logging level", "loglevel" },
+ { "v", HAS_ARG, {(void*)opt_loglevel}, "set libav* logging level", "loglevel" },
+ { "debug", HAS_ARG, {(void*)opt_codec_debug}, "set debug flags", "flags" },
diff --git a/common.mak b/common.mak
index bd210462b9..8dd24396d2 100644
--- a/common.mak
+++ b/common.mak
@@ -5,6 +5,71 @@
# first so "all" becomes default target
all: all-yes
+ifndef SUBDIR
+
+ifndef V
+Q = @
+ECHO = printf "$(1)\t%s\n" $(2)
+BRIEF = CC CXX AS YASM AR LD HOSTCC STRIP CP
+SILENT = DEPCC YASMDEP RM RANLIB
+MSG = $@
+M = @$(call ECHO,$(TAG),$@);
+$(foreach VAR,$(BRIEF), \
+ $(eval override $(VAR) = @$$(call ECHO,$(VAR),$$(MSG)); $($(VAR))))
+$(foreach VAR,$(SILENT),$(eval override $(VAR) = @$($(VAR))))
+$(eval INSTALL = @$(call ECHO,INSTALL,$$(^:$(SRC_DIR)/%=%)); $(INSTALL))
+endif
+
+ALLFFLIBS = avcodec avdevice avfilter avformat avutil postproc swscale swresample
+
+# NASM requires -I path terminated with /
+IFLAGS := -I. -I$(SRC_PATH)/
+CPPFLAGS := $(IFLAGS) $(CPPFLAGS)
+CFLAGS += $(ECFLAGS)
+CCFLAGS = $(CFLAGS)
+CXXFLAGS := $(CFLAGS) $(CXXFLAGS)
+YASMFLAGS += $(IFLAGS) -I$(SRC_PATH)/libavutil/x86/ -Pconfig.asm
+HOSTCFLAGS += $(IFLAGS)
+LDFLAGS := $(ALLFFLIBS:%=-Llib%) $(LDFLAGS)
+
+define COMPILE
+ $($(1)DEP)
+ $($(1)) $(CPPFLAGS) $($(1)FLAGS) $($(1)_DEPFLAGS) -c $($(1)_O) $<
+endef
+
+COMPILE_C = $(call COMPILE,CC)
+COMPILE_CXX = $(call COMPILE,CXX)
+COMPILE_S = $(call COMPILE,AS)
+
+%.o: %.c
+ $(COMPILE_C)
+
+%.o: %.cpp
+ $(COMPILE_CXX)
+
+%.o: %.S
+ $(COMPILE_S)
+
+%.ho: %.h
+ $(CC) $(CPPFLAGS) $(CFLAGS) -Wno-unused -c -o $@ -x c $<
+
+%.ver: %.v
+ $(Q)sed 's/$$MAJOR/$($(basename $(@F))_VERSION_MAJOR)/' $^ > $@
+
+%.c %.h: TAG = GEN
+
+# Dummy rule to stop make trying to rebuild removed or renamed headers
+%.h:
+ @:
+
+# Disable suffix rules. Most of the builtin rules are suffix rules,
+# so this saves some time on slow systems.
+.SUFFIXES:
+
+# Do not delete intermediate files from chains of implicit rules
+$(OBJS):
+endif
+
OBJS-$(HAVE_MMX) += $(MMX-OBJS-yes)
OBJS += $(OBJS-yes)
@@ -12,7 +77,6 @@ FFLIBS := $(FFLIBS-yes) $(FFLIBS)
TESTPROGS += $(TESTPROGS-yes)
FFEXTRALIBS := $(FFLIBS:%=-l%$(BUILDSUF)) $(EXTRALIBS)
-FFLDFLAGS := $(ALLFFLIBS:%=-Llib%) $(LDFLAGS)
EXAMPLES := $(EXAMPLES:%=$(SUBDIR)%-example$(EXESUF))
OBJS := $(sort $(OBJS:%=$(SUBDIR)%))
@@ -20,6 +84,9 @@ TESTOBJS := $(TESTOBJS:%=$(SUBDIR)%) $(TESTPROGS:%=$(SUBDIR)%-test.o)
TESTPROGS := $(TESTPROGS:%=$(SUBDIR)%-test$(EXESUF))
HOSTOBJS := $(HOSTPROGS:%=$(SUBDIR)%.o)
HOSTPROGS := $(HOSTPROGS:%=$(SUBDIR)%$(HOSTEXESUF))
+TOOLS += $(TOOLS-yes)
+TOOLOBJS := $(TOOLS:%=tools/%.o)
+TOOLS := $(TOOLS:%=tools/%$(EXESUF))
DEP_LIBS := $(foreach NAME,$(FFLIBS),lib$(NAME)/$($(CONFIG_SHARED:yes=S)LIBNAME))
@@ -28,15 +95,18 @@ SKIPHEADERS += $(ARCH_HEADERS:%=$(ARCH)/%) $(SKIPHEADERS-)
SKIPHEADERS := $(SKIPHEADERS:%=$(SUBDIR)%)
checkheaders: $(filter-out $(SKIPHEADERS:.h=.ho),$(ALLHEADERS:.h=.ho))
+alltools: $(TOOLS)
+
$(HOSTOBJS): %.o: %.c
$(HOSTCC) $(HOSTCFLAGS) -c -o $@ $<
$(HOSTPROGS): %$(HOSTEXESUF): %.o
$(HOSTCC) $(HOSTLDFLAGS) -o $@ $< $(HOSTLIBS)
-$(OBJS): | $(dir $(OBJS))
-$(HOSTOBJS): | $(dir $(HOSTOBJS))
-$(TESTOBJS): | $(dir $(TESTOBJS))
+$(OBJS): | $(sort $(dir $(OBJS)))
+$(HOSTOBJS): | $(sort $(dir $(HOSTOBJS)))
+$(TESTOBJS): | $(sort $(dir $(TESTOBJS)))
+$(TOOLOBJS): | tools
OBJDIRS := $(OBJDIRS) $(dir $(OBJS) $(HOSTOBJS) $(TESTOBJS))
diff --git a/configure b/configure
index e77340f74a..6d2879d832 100755
--- a/configure
+++ b/configure
@@ -1,6 +1,6 @@
#!/bin/sh
#
-# Libav configure script
+# FFmpeg configure script
#
# Copyright (c) 2000-2002 Fabrice Bellard
# Copyright (c) 2005-2008 Diego Biurrun
@@ -44,9 +44,9 @@ if test "$E1" != 0 || test "$E2" = 0; then
echo "No compatible shell script interpreter found."
echo "This configure script requires a POSIX-compatible shell"
echo "such as bash or ksh."
- echo "THIS IS NOT A BUG IN LIBAV, DO NOT REPORT IT AS SUCH."
+ echo "THIS IS NOT A BUG IN FFMPEG, DO NOT REPORT IT AS SUCH."
echo "Instead, install a working POSIX-compatible shell."
- echo "Disabling this configure test will create a broken Libav."
+ echo "Disabling this configure test will create a broken FFmpeg."
if test "$BASH_VERSION" = '2.04.0(1)-release'; then
echo "This bash version ($BASH_VERSION) is broken on your platform."
echo "Upgrade to a later version if available."
@@ -81,12 +81,14 @@ Configuration options:
and binaries will be unredistributable [no]
--disable-doc do not build documentation
--disable-ffmpeg disable ffmpeg build
+ --disable-avconv disable avconv build
--disable-ffplay disable ffplay build
--disable-ffprobe disable ffprobe build
--disable-ffserver disable ffserver build
--disable-avdevice disable libavdevice build
--disable-avcodec disable libavcodec build
--disable-avformat disable libavformat build
+ --disable-swresample disable libswresample build
--disable-swscale disable libswscale build
--disable-postproc disable libpostproc build
--disable-avfilter disable video filter support [no]
@@ -106,8 +108,8 @@ Configuration options:
--disable-lpc disable LPC code
--disable-mdct disable MDCT code
--disable-rdft disable RDFT code
- --enable-vaapi enable VAAPI code
- --enable-vdpau enable VDPAU code
+ --enable-vaapi enable VAAPI code [autodetect]
+ --enable-vdpau enable VDPAU code [autodetect]
--disable-dxva2 disable DXVA2 code
--enable-runtime-cpudetect detect cpu capabilities at runtime (bigger binary)
--enable-hardcoded-tables use hardcoded tables instead of runtime generation
@@ -160,24 +162,30 @@ Configuration options:
External library support:
--enable-avisynth enable reading of AVISynth script files [no]
--enable-bzlib enable bzlib [autodetect]
+ --enable-libcelt enable CELT/Opus decoding via libcelt [no]
--enable-frei0r enable frei0r video filtering
+ --enable-libaacplus enable AAC+ encoding via libaacplus [no]
--enable-libopencore-amrnb enable AMR-NB de/encoding via libopencore-amrnb [no]
--enable-libopencore-amrwb enable AMR-WB decoding via libopencore-amrwb [no]
--enable-libopencv enable video filtering via libopencv [no]
+ --enable-libcdio enable audio CD grabbing with libcdio
--enable-libdc1394 enable IIDC-1394 grabbing using libdc1394
and libraw1394 [no]
--enable-libdirac enable Dirac support via libdirac [no]
--enable-libfaac enable FAAC support via libfaac [no]
--enable-libfreetype enable libfreetype [no]
--enable-libgsm enable GSM support via libgsm [no]
+ --enable-libmodplug enable ModPlug via libmodplug [no]
--enable-libmp3lame enable MP3 encoding via libmp3lame [no]
--enable-libnut enable NUT (de)muxing via libnut,
native (de)muxer exists [no]
--enable-libopenjpeg enable JPEG 2000 decoding via OpenJPEG [no]
--enable-librtmp enable RTMP[E] support via librtmp [no]
--enable-libschroedinger enable Dirac support via libschroedinger [no]
- --enable-libspeex enable Speex decoding via libspeex [no]
+ --enable-libspeex enable Speex support via libspeex [no]
+ --enable-libstagefright-h264 enable H.264 decoding via libstagefright [no]
--enable-libtheora enable Theora encoding via libtheora [no]
+ --enable-libutvideo enable Ut Video decoding via libutvideo [no]
--enable-libvo-aacenc enable AAC encoding via libvo-aacenc [no]
--enable-libvo-amrwbenc enable AMR-WB encoding via libvo-amrwbenc [no]
--enable-libvorbis enable Vorbis encoding via libvorbis,
@@ -187,6 +195,7 @@ External library support:
--enable-libxavs enable AVS encoding via xavs [no]
--enable-libxvid enable Xvid encoding via xvidcore,
native MPEG-4/Xvid encoder exists [no]
+ --enable-openal enable OpenAL 1.1 capture support [no]
--enable-mlib enable Sun medialib [no]
--enable-zlib enable zlib [autodetect]
@@ -202,16 +211,19 @@ Advanced options (experts only):
--ar=AR use archive tool AR [$ar_default]
--as=AS use assembler AS [$as_default]
--cc=CC use C compiler CC [$cc_default]
+ --cxx=CXX use C compiler CXX [$cxx_default]
--ld=LD use linker LD
--host-cc=HOSTCC use host C compiler HOSTCC
--host-cflags=HCFLAGS use HCFLAGS when compiling for host
--host-ldflags=HLDFLAGS use HLDFLAGS when linking for host
--host-libs=HLIBS use libs HLIBS when linking for host
--extra-cflags=ECFLAGS add ECFLAGS to CFLAGS [$CFLAGS]
+ --extra-cxxflags=ECFLAGS add ECFLAGS to CXXFLAGS [$CXXFLAGS]
--extra-ldflags=ELDFLAGS add ELDFLAGS to LDFLAGS [$LDFLAGS]
--extra-libs=ELIBS add ELIBS [$ELIBS]
--extra-version=STRING version string suffix []
--build-suffix=SUFFIX library name suffix []
+ --progs-suffix=SUFFIX program name suffix []
--arch=ARCH select architecture [$arch]
--cpu=CPU select the minimum required CPU (affects
instruction selection, may crash on older CPUs)
@@ -239,11 +251,12 @@ Advanced options (experts only):
--disable-symver disable symbol versioning
--optflags override optimization-related compiler flags
-Developer options (useful when working on Libav itself):
+Developer options (useful when working on FFmpeg itself):
--disable-debug disable debugging symbols
--enable-debug=LEVEL set the debug level [$debuglevel]
--disable-optimizations disable compiler optimizations
--enable-extra-warnings enable more compiler warnings
+ --disable-stripping disable stripping of executables and shared libraries
--samples=PATH location of test samples for FATE, if not set use
\$FATE_SAMPLES at make invocation time.
@@ -280,7 +293,7 @@ die(){
If you think configure made a mistake, make sure you are using the latest
version from Git. If the latest version fails, report the problem to the
-libav-user@libav.org mailing list or IRC #libav on irc.freenode.net.
+ffmpeg-user@ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net.
EOF
if disabled logging; then
cat <<EOF
@@ -577,6 +590,10 @@ add_cflags(){
append CFLAGS $($filter_cflags "$@")
}
+add_cxxflags(){
+ append CXXFLAGS $($filter_cflags "$@")
+}
+
add_asflags(){
append ASFLAGS $($filter_asflags "$@")
}
@@ -601,6 +618,13 @@ check_cc(){
check_cmd $cc $CPPFLAGS $CFLAGS "$@" -c -o $TMPO $TMPC
}
+check_cxx(){
+ log check_cxx "$@"
+ cat > $TMPCPP
+ log_file $TMPCPP
+ check_cmd $cxx $CPPFLAGS $CFLAGS $CXXFLAGS "$@" -c -o $TMPO $TMPCPP
+}
+
check_cpp(){
log check_cpp "$@"
cat > $TMPC
@@ -636,12 +660,14 @@ check_yasm(){
check_ld(){
log check_ld "$@"
+ type=$1
+ shift 1
flags=''
libs=''
for f; do
test "${f}" = "${f#-l}" && flags="$flags $f" || libs="$libs $f"
done
- check_cc $($filter_cflags $flags) || return
+ check_$type $($filter_cflags $flags) || return
check_cmd $ld $LDFLAGS $flags -o $TMPE $TMPO $libs $extralibs
}
@@ -661,9 +687,17 @@ int x;
EOF
}
+check_cxxflags(){
+ log check_cxxflags "$@"
+ set -- $($filter_cflags "$@")
+ check_cxx "$@" <<EOF && append CXXFLAGS "$@"
+int x;
+EOF
+}
+
test_ldflags(){
log test_ldflags "$@"
- check_ld "$@" <<EOF
+ check_ld "cc" "$@" <<EOF
int main(void){ return 0; }
EOF
}
@@ -689,7 +723,7 @@ check_func(){
func=$1
shift
disable $func
- check_ld "$@" <<EOF && enable $func
+ check_ld "cc" "$@" <<EOF && enable $func
extern int $func();
int main(void){ $func(); }
EOF
@@ -700,10 +734,10 @@ check_mathfunc(){
func=$1
shift
disable $func
- check_ld "$@" <<EOF && enable $func
+ check_ld "cc" "$@" <<EOF && enable $func
#include <math.h>
float foo(float f) { return $func(f); }
-int main(void){ return 0; }
+int main(void){ return (int) foo; }
EOF
}
@@ -720,7 +754,26 @@ check_func_headers(){
echo "long check_$func(void) { return (long) $func; }"
done
echo "int main(void) { return 0; }"
- } | check_ld "$@" && enable $funcs && enable_safe $headers
+ } | check_ld "cc" "$@" && enable $funcs && enable_safe $headers
+}
+
+check_class_headers_cpp(){
+ log check_class_headers_cpp "$@"
+ headers=$1
+ classes=$2
+ shift 2
+ {
+ for hdr in $headers; do
+ echo "#include <$hdr>"
+ done
+ echo "int main(void) { "
+ i=1
+ for class in $classes; do
+ echo "$class obj$i;"
+ i=$(expr $i + 1)
+ done
+ echo "return 0; }"
+ } | check_ld "cxx" "$@" && enable $funcs && enable_safe $headers
}
check_cpp_condition(){
@@ -752,13 +805,21 @@ check_lib2(){
check_func_headers "$headers" "$funcs" "$@" && add_extralibs "$@"
}
+check_lib_cpp(){
+ log check_lib_cpp "$@"
+ headers="$1"
+ classes="$2"
+ shift 2
+ check_class_headers_cpp "$headers" "$classes" "$@" && add_extralibs "$@"
+}
+
check_pkg_config(){
log check_pkg_config "$@"
pkg="$1"
headers="$2"
funcs="$3"
shift 3
- $pkg_config --exists $pkg || return
+ $pkg_config --exists $pkg 2>/dev/null || return
pkg_cflags=$($pkg_config --cflags $pkg)
pkg_libs=$($pkg_config --libs $pkg)
check_func_headers "$headers" "$funcs" $pkg_cflags $pkg_libs "$@" &&
@@ -767,7 +828,7 @@ check_pkg_config(){
}
check_exec(){
- check_ld "$@" && { enabled cross_compile || $TMPE >> $logfile 2>&1; }
+ check_ld "cc" "$@" && { enabled cross_compile || $TMPE >> $logfile 2>&1; }
}
check_exec_crash(){
@@ -784,6 +845,9 @@ check_exec_crash(){
static void sighandler(int sig){
raise(SIGTERM);
}
+int func(void){
+ $code
+}
int main(void){
signal(SIGILL, sighandler);
signal(SIGFPE, sighandler);
@@ -791,7 +855,7 @@ int main(void){
#ifdef SIGBUS
signal(SIGBUS, sighandler);
#endif
- { $code }
+ return func();
}
EOF
}
@@ -847,6 +911,14 @@ require2(){
check_lib2 "$headers" $func "$@" || die "ERROR: $name not found"
}
+require_cpp(){
+ name="$1"
+ headers="$2"
+ classes="$3"
+ shift 3
+ check_lib_cpp "$headers" "$classes" "$@" || die "ERROR: $name not found"
+}
+
require_pkg_config(){
pkg="$1"
check_pkg_config "$@" || die "ERROR: $pkg not found"
@@ -907,12 +979,14 @@ CONFIG_LIST="
avformat
avisynth
bzlib
+ crystalhd
dct
doc
dwt
dxva2
fastdiv
ffmpeg
+ avconv
ffplay
ffprobe
ffserver
@@ -925,21 +999,28 @@ CONFIG_LIST="
h264pred
hardcoded_tables
huffman
+ libaacplus
+ libcdio
+ libcelt
libdc1394
libdirac
libfaac
libfreetype
libgsm
+ libmodplug
libmp3lame
libnut
libopencore_amrnb
libopencore_amrwb
libopencv
libopenjpeg
+ libpulse
librtmp
libschroedinger
libspeex
+ libstagefright_h264
libtheora
+ libutvideo
libvo_aacenc
libvo_amrwbenc
libvorbis
@@ -955,6 +1036,7 @@ CONFIG_LIST="
mpegaudiodsp
network
nonfree
+ openal
pic
postproc
rdft
@@ -965,6 +1047,7 @@ CONFIG_LIST="
small
sram
static
+ swresample
swscale
swscale_alpha
thumb
@@ -1038,6 +1121,7 @@ HAVE_LIST="
alsa_asoundlib_h
altivec_h
arpa_inet_h
+ asm_mod_y
attribute_may_alias
attribute_packed
bswap
@@ -1072,9 +1156,8 @@ HAVE_LIST="
inet_aton
inline_asm
isatty
+ kbhit
ldbrx
- libdc1394_1
- libdc1394_2
llrint
llrintf
local_aligned_16
@@ -1093,6 +1176,7 @@ HAVE_LIST="
memalign
mkstemp
mmap
+ PeekNamedPipe
posix_memalign
round
roundf
@@ -1105,7 +1189,7 @@ HAVE_LIST="
poll_h
setrlimit
strerror_r
- strtok_r
+ strptime
struct_addrinfo
struct_ipv6_mreq
struct_sockaddr_in6
@@ -1119,6 +1203,7 @@ HAVE_LIST="
sys_select_h
sys_soundcard_h
sys_videoio_h
+ termios_h
threads
trunc
truncf
@@ -1147,6 +1232,7 @@ CMDLINE_SELECT="
extra_warnings
logging
optimizations
+ stripping
symver
yasm
"
@@ -1167,9 +1253,11 @@ CMDLINE_SET="
arch
as
build_suffix
+ progs_suffix
cc
cpu
cross_prefix
+ cxx
dep_cc
extra_version
host_cc
@@ -1177,6 +1265,7 @@ CMDLINE_SET="
host_ldflags
host_libs
host_os
+ install
ld
logfile
malloc_prefix
@@ -1184,6 +1273,7 @@ CMDLINE_SET="
optflags
pkg_config
samples
+ strip
sysinclude
sysroot
target_exec
@@ -1193,6 +1283,7 @@ CMDLINE_SET="
CMDLINE_APPEND="
extra_cflags
+ extra_cxxflags
"
# code dependency declarations
@@ -1269,6 +1360,8 @@ flac_decoder_select="golomb"
flac_encoder_select="golomb lpc"
flashsv_decoder_select="zlib"
flashsv_encoder_select="zlib"
+flashsv2_encoder_select="zlib"
+flashsv2_decoder_select="zlib"
flv_decoder_select="h263_decoder"
flv_encoder_select="h263_encoder"
fraps_decoder_select="huffman"
@@ -1279,6 +1372,7 @@ h263_vaapi_hwaccel_select="vaapi h263_decoder"
h263i_decoder_select="h263_decoder"
h263p_encoder_select="h263_encoder"
h264_decoder_select="golomb h264dsp h264pred"
+h264_crystalhd_decoder_select="crystalhd h264_mp4toannexb_bsf h264_parser"
h264_dxva2_hwaccel_deps="dxva2api_h"
h264_dxva2_hwaccel_select="dxva2 h264_decoder"
h264_vaapi_hwaccel_select="vaapi"
@@ -1306,13 +1400,18 @@ mpeg4_decoder_select="h263_decoder mpeg4video_parser"
mpeg4_encoder_select="h263_encoder"
mpeg_vdpau_decoder_select="vdpau mpegvideo_decoder"
mpeg1_vdpau_decoder_select="vdpau mpeg1video_decoder"
+mpeg1_vdpau_hwaccel_select="vdpau mpeg1video_decoder"
+mpeg2_crystalhd_decoder_select="crystalhd"
mpeg2_dxva2_hwaccel_deps="dxva2api_h"
mpeg2_dxva2_hwaccel_select="dxva2 mpeg2video_decoder"
+mpeg2_vdpau_hwaccel_select="vdpau mpeg2video_decoder"
mpeg2_vaapi_hwaccel_select="vaapi mpeg2video_decoder"
+mpeg4_crystalhd_decoder_select="crystalhd"
mpeg4_vaapi_hwaccel_select="vaapi mpeg4_decoder"
mpeg4_vdpau_decoder_select="vdpau mpeg4_decoder"
mpeg_xvmc_decoder_deps="X11_extensions_XvMClib_h"
mpeg_xvmc_decoder_select="mpegvideo_decoder"
+msmpeg4_crystalhd_decoder_select="crystalhd"
msmpeg4v1_decoder_select="h263_decoder"
msmpeg4v1_encoder_select="h263_encoder"
msmpeg4v2_decoder_select="h263_decoder"
@@ -1336,6 +1435,9 @@ shorten_decoder_select="golomb"
sipr_decoder_select="lsp"
snow_decoder_select="dwt"
snow_encoder_select="aandct dwt"
+sonic_decoder_select="golomb"
+sonic_encoder_select="golomb"
+sonic_ls_encoder_select="golomb"
svq1_encoder_select="aandct"
svq3_decoder_select="golomb h264dsp h264pred"
svq3_decoder_suggest="zlib"
@@ -1346,10 +1448,12 @@ truehd_decoder_select="mlp_decoder"
tscc_decoder_select="zlib"
twinvq_decoder_select="mdct lsp sinewin"
vc1_decoder_select="h263_decoder"
-vc1_dxva2_hwaccel_deps="dxva2api_h DXVA_PictureParameters_wDecodedPictureIndex"
+vc1_crystalhd_decoder_select="crystalhd"
+vc1_dxva2_hwaccel_deps="dxva2api_h"
vc1_dxva2_hwaccel_select="dxva2 vc1_decoder"
vc1_vaapi_hwaccel_select="vaapi vc1_decoder"
vc1_vdpau_decoder_select="vdpau vc1_decoder"
+vc1image_decoder_select="vc1_decoder"
vorbis_decoder_select="mdct"
vorbis_encoder_select="mdct"
vp6_decoder_select="huffman"
@@ -1367,14 +1471,17 @@ wmv1_encoder_select="h263_encoder"
wmv2_decoder_select="h263_decoder"
wmv2_encoder_select="h263_encoder"
wmv3_decoder_select="vc1_decoder"
+wmv3_crystalhd_decoder_select="crystalhd"
wmv3_dxva2_hwaccel_select="vc1_dxva2_hwaccel"
wmv3_vaapi_hwaccel_select="vc1_vaapi_hwaccel"
wmv3_vdpau_decoder_select="vc1_vdpau_decoder"
+wmv3image_decoder_select="wmv3_decoder"
zlib_decoder_select="zlib"
zlib_encoder_select="zlib"
zmbv_decoder_select="zlib"
zmbv_encoder_select="zlib"
+crystalhd_deps="libcrystalhd_libcrystalhd_if_h"
vaapi_deps="va_va_h"
vdpau_deps="vdpau_vdpau_h vdpau_vdpau_x11_h"
@@ -1382,6 +1489,8 @@ vdpau_deps="vdpau_vdpau_h vdpau_vdpau_x11_h"
h264_parser_select="golomb h264dsp h264pred"
# external libraries
+libaacplus_encoder_deps="libaacplus"
+libcelt_decoder_deps="libcelt"
libdirac_decoder_deps="libdirac !libschroedinger"
libdirac_encoder_deps="libdirac"
libfaac_encoder_deps="libfaac"
@@ -1389,6 +1498,7 @@ libgsm_decoder_deps="libgsm"
libgsm_encoder_deps="libgsm"
libgsm_ms_decoder_deps="libgsm"
libgsm_ms_encoder_deps="libgsm"
+libmodplug_demuxer_deps="libmodplug"
libmp3lame_encoder_deps="libmp3lame"
libopencore_amrnb_decoder_deps="libopencore_amrnb"
libopencore_amrnb_encoder_deps="libopencore_amrnb"
@@ -1397,6 +1507,8 @@ libopenjpeg_decoder_deps="libopenjpeg"
libschroedinger_decoder_deps="libschroedinger"
libschroedinger_encoder_deps="libschroedinger"
libspeex_decoder_deps="libspeex"
+libspeex_encoder_deps="libspeex"
+libstagefright_h264_decoder_deps="libstagefright_h264"
libtheora_encoder_deps="libtheora"
libvo_aacenc_encoder_deps="libvo_aacenc"
libvo_amrwbenc_encoder_deps="libvo_amrwbenc"
@@ -1406,6 +1518,7 @@ libvpx_encoder_deps="libvpx"
libx264_encoder_deps="libx264"
libxavs_encoder_deps="libxavs"
libxvid_encoder_deps="libxvid"
+libutvideo_decoder_deps="libutvideo gpl"
# demuxers / muxers
ac3_demuxer_select="ac3_parser"
@@ -1442,12 +1555,19 @@ w64_demuxer_deps="wav_demuxer"
alsa_indev_deps="alsa_asoundlib_h snd_pcm_htimestamp"
alsa_outdev_deps="alsa_asoundlib_h"
bktr_indev_deps_any="dev_bktr_ioctl_bt848_h machine_ioctl_bt848_h dev_video_bktr_ioctl_bt848_h dev_ic_bt8xx_h"
+dshow_indev_deps="IBaseFilter"
+dshow_indev_extralibs="-lpsapi -lole32 -lstrmiids -luuid"
dv1394_indev_deps="dv1394 dv_demuxer"
fbdev_indev_deps="linux_fb_h"
-jack_indev_deps="jack_jack_h"
+jack_indev_deps="jack_jack_h sem_timedwait"
+lavfi_indev_deps="avfilter"
+libcdio_indev_deps="libcdio"
libdc1394_indev_deps="libdc1394"
+openal_indev_deps="openal"
oss_indev_deps_any="soundcard_h sys_soundcard_h"
oss_outdev_deps_any="soundcard_h sys_soundcard_h"
+pulse_indev_deps="libpulse"
+sdl_outdev_deps="sdl"
sndio_indev_deps="sndio_h"
sndio_outdev_deps="sndio_h"
v4l_indev_deps="linux_videodev_h"
@@ -1469,12 +1589,19 @@ tcp_protocol_deps="network"
udp_protocol_deps="network"
# filters
+amovie_filter_deps="avcodec avformat"
blackframe_filter_deps="gpl"
+boxblur_filter_deps="gpl"
cropdetect_filter_deps="gpl"
+delogo_filter_deps="gpl"
drawtext_filter_deps="libfreetype"
-frei0r_filter_deps="frei0r dlopen strtok_r"
-frei0r_src_filter_deps="frei0r dlopen strtok_r"
+frei0r_filter_deps="frei0r dlopen"
+frei0r_src_filter_deps="frei0r dlopen"
hqdn3d_filter_deps="gpl"
+movie_filter_deps="avcodec avformat"
+mp_filter_deps="gpl avcodec"
+mptestsrc_filter_deps="gpl"
+negate_filter_deps="lut_filter"
ocv_filter_deps="libopencv"
scale_filter_deps="swscale"
yadif_filter_deps="gpl"
@@ -1485,10 +1612,12 @@ avformat_deps="avcodec"
postproc_deps="gpl"
# programs
-ffmpeg_deps="avcodec avformat swscale"
-ffmpeg_select="buffer_filter"
+ffmpeg_deps="avcodec avformat swscale swresample"
+ffmpeg_select="buffer_filter buffersink_filter"
+avconv_deps="avcodec avformat swscale"
+avconv_select="buffer_filter"
ffplay_deps="avcodec avformat swscale sdl"
-ffplay_select="rdft"
+ffplay_select="buffersink_filter rdft"
ffprobe_deps="avcodec avformat"
ffserver_deps="avformat ffm_muxer fork rtp_protocol rtsp_demuxer"
ffserver_extralibs='$ldl'
@@ -1505,11 +1634,14 @@ test_deps(){
dep=${v%=*}
tests=${v#*=}
for name in ${tests}; do
- eval ${name}_test_deps="'${dep}$suf1 ${dep}$suf2'"
+ append ${name}_test_deps ${dep}$suf1 ${dep}$suf2
done
done
}
+mxf_d10_test_deps="avfilter"
+seek_lavf_mxf_d10_test_deps="mxf_d10_test"
+
test_deps _encoder _decoder \
adpcm_g726=g726 \
adpcm_ima_qt \
@@ -1572,7 +1704,7 @@ test_deps _muxer _demuxer \
mmf \
mov \
pcm_mulaw=mulaw \
- mxf \
+ mxf="mxf mxf_d10" \
nut \
ogg \
rawvideo=pixfmt \
@@ -1602,13 +1734,16 @@ shlibdir_default="$libdir_default"
# toolchain
ar_default="ar"
cc_default="gcc"
+cxx_default="g++"
cc_version=\"unknown\"
host_cc_default="gcc"
+install="install"
ln_s="ln -sf"
nm_default="nm"
objformat="elf"
pkg_config_default=pkg-config
ranlib="ranlib"
+strip_default="strip"
yasmexe="yasm"
nogas=":"
@@ -1633,6 +1768,7 @@ enable debug
enable doc
enable fastdiv
enable ffmpeg
+enable avconv
enable ffplay
enable ffprobe
enable ffserver
@@ -1641,6 +1777,8 @@ enable optimizations
enable postproc
enable protocols
enable static
+enable stripping
+enable swresample
enable swscale
enable swscale_alpha
@@ -1657,9 +1795,12 @@ SLIBNAME='$(SLIBPREF)$(FULLNAME)$(SLIBSUF)'
SLIBNAME_WITH_VERSION='$(SLIBNAME).$(LIBVERSION)'
SLIBNAME_WITH_MAJOR='$(SLIBNAME).$(LIBMAJOR)'
LIB_INSTALL_EXTRA_CMD='$$(RANLIB) "$(LIBDIR)/$(LIBNAME)"'
+SLIB_INSTALL_NAME='$(SLIBNAME_WITH_VERSION)'
+SLIB_INSTALL_LINKS='$(SLIBNAME_WITH_MAJOR) $(SLIBNAME)'
AS_O='-o $@'
CC_O='-o $@'
+CXX_O='-o $@'
host_cflags='-D_ISOC99_SOURCE -O3 -g'
host_libs='-lm'
@@ -1686,7 +1827,7 @@ for v in "$@"; do
r=${v#*=}
l=${v%"$r"}
r=$(sh_quote "$r")
- LIBAV_CONFIGURATION="${LIBAV_CONFIGURATION# } ${l}${r}"
+ FFMPEG_CONFIGURATION="${FFMPEG_CONFIGURATION# } ${l}${r}"
done
find_things(){
@@ -1798,7 +1939,7 @@ done
disabled logging && logfile=/dev/null
-echo "# $0 $LIBAV_CONFIGURATION" > $logfile
+echo "# $0 $FFMPEG_CONFIGURATION" > $logfile
set >> $logfile
test -n "$cross_prefix" && enable cross_compile
@@ -1812,13 +1953,15 @@ set_default arch target_os
ar_default="${cross_prefix}${ar_default}"
cc_default="${cross_prefix}${cc_default}"
+cxx_default="${cross_prefix}${cxx_default}"
nm_default="${cross_prefix}${nm_default}"
pkg_config_default="${cross_prefix}${pkg_config_default}"
ranlib="${cross_prefix}${ranlib}"
+strip_default="${cross_prefix}${strip_default}"
sysinclude_default="${sysroot}/usr/include"
-set_default cc nm pkg_config sysinclude
+set_default cc cxx nm pkg_config strip sysinclude
enabled cross_compile || host_cc_default=$cc
set_default host_cc
@@ -1860,6 +2003,7 @@ tmpfile(){
trap 'rm -f -- $TMPFILES' EXIT
tmpfile TMPC .c
+tmpfile TMPCPP .cpp
tmpfile TMPE $EXESUF
tmpfile TMPH .h
tmpfile TMPO .o
@@ -2011,6 +2155,7 @@ elif $cc -V 2>&1 | grep -q Sun; then
cc_ident=$($cc -V 2>&1 | head -n1 | cut -d' ' -f 2-)
DEPEND_CMD='$(DEPCC) $(DEPFLAGS) $< | sed -e "1s,^.*: ,$@: ," -e "\$$!s,\$$, \\\," -e "1!s,^.*: , ," > $(@:.o=.d)'
DEPFLAGS='$(CPPFLAGS) $(CFLAGS) -xM1'
+ add_ldflags -xc99
speed_cflags='-O5'
size_cflags='-O5 -xspace'
filter_cflags=suncc_flags
@@ -2076,9 +2221,11 @@ test -n "$cc_type" && enable $cc_type ||
set_default ar as dep_cc ld
test -n "$CC_DEPFLAGS" || CCDEP=$DEPEND_CMD
+test -n "$CXX_DEPFLAGS" || CXXDEP=$DEPEND_CMD
test -n "$AS_DEPFLAGS" || ASDEP=$DEPEND_CMD
add_cflags $extra_cflags
+add_cxxflags $extra_cxxflags
add_asflags $extra_cflags
if test -n "$sysroot"; then
@@ -2101,7 +2248,7 @@ if test "$cpu" = host; then
gcc|llvm_gcc)
check_native(){
$cc $1=native -v -c -o $TMPO $TMPC >$TMPE 2>&1 || return
- sed -n "/$1=/{
+ sed -n "/cc1.*$1=/{
s/.*$1=\\([^ ]*\\).*/\\1/
p
q
@@ -2133,12 +2280,8 @@ case "$arch" in
arch="parisc"
subarch="parisc64"
;;
- "Power Macintosh"|ppc|powerpc)
- arch="ppc"
- ;;
- ppc64|powerpc64)
+ "Power Macintosh"|ppc|powerpc|ppc64|powerpc64)
arch="ppc"
- subarch="ppc64"
;;
s390|s390x)
arch="s390"
@@ -2313,6 +2456,7 @@ if test "$?" != 0; then
fi
add_cppflags -D_ISOC99_SOURCE
+add_cxxflags -D__STDC_CONSTANT_MACROS
check_cflags -std=c99
check_cc -D_FILE_OFFSET_BITS=64 <<EOF && add_cppflags -D_FILE_OFFSET_BITS=64
#include <stdlib.h>
@@ -2337,6 +2481,11 @@ EOF
spic=$shared
fi
;;
+ ppc)
+ check_cc <<EOF && subarch="ppc64"
+ int test[(int)sizeof(char*) - 7];
+EOF
+ ;;
esac
enable $subarch
@@ -2355,6 +2504,12 @@ case $target_os in
enabled x86 && SHFLAGS="-mimpure-text $SHFLAGS"
network_extralibs="-lsocket -lnsl"
add_cppflags -D__EXTENSIONS__
+ # When using suncc to build, the Solaris linker will mark
+ # an executable with each instruction set encountered by
+ # the Solaris assembler. As our libraries contain their own
+ # guards for processor-specific code, instead suppress
+ # generation of the HWCAPS ELF section on Solaris x86 only.
+ enabled_all suncc x86 && echo "hwcap_1 = OVERRIDE;" > mapfile && add_ldflags -Wl,-M,mapfile
nm_opts='-P -g'
;;
netbsd)
@@ -2365,7 +2520,7 @@ case $target_os in
openbsd)
enable malloc_aligned
# On OpenBSD 4.5. the compiler does not use PIC unless
- # explicitly using -fPIC. Libav builds fine without PIC,
+ # explicitly using -fPIC. FFmpeg builds fine without PIC,
# however the generated executable will not do anything
# (simply quits with exit-code 1, no crash, no output).
# Thus explicitly enable PIC here.
@@ -2384,6 +2539,7 @@ case $target_os in
;;
bsd/os)
add_extralibs -lpoll -lgnugetopt
+ strip="strip -d"
;;
darwin)
enable malloc_aligned
@@ -2391,6 +2547,7 @@ case $target_os in
enabled ppc && add_asflags -force_cpusubtype_ALL
SHFLAGS='-dynamiclib -Wl,-single_module -Wl,-install_name,$(SHLIBDIR)/$(SLIBNAME),-current_version,$(LIBVERSION),-compatibility_version,$(LIBMAJOR)'
enabled x86_32 && append SHFLAGS -Wl,-read_only_relocs,suppress
+ strip="${strip} -x"
add_ldflags -Wl,-dynamic,-search_paths_first
SLIBSUF=".dylib"
SLIBNAME_WITH_VERSION='$(SLIBPREF)$(FULLNAME).$(LIBVERSION)$(SLIBSUF)'
@@ -2410,7 +2567,7 @@ case $target_os in
LIBTARGET=i386
if enabled x86_64; then
enable malloc_aligned
- LIBTARGET="i386:x86-64"
+ LIBTARGET=x64
elif enabled arm; then
LIBTARGET=arm-wince
fi
@@ -2419,15 +2576,13 @@ case $target_os in
SLIBSUF=".dll"
SLIBNAME_WITH_VERSION='$(SLIBPREF)$(FULLNAME)-$(LIBVERSION)$(SLIBSUF)'
SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'
- SLIB_EXTRA_CMD=-'$(DLLTOOL) -m $(LIBTARGET) -d $$(@:$(SLIBSUF)=.def) -l $(SUBDIR)$(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.lib) -D $(SLIBNAME_WITH_MAJOR)'
- SLIB_INSTALL_EXTRA_CMD='-install -m 644 $(SUBDIR)$(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.lib) "$(SHLIBDIR)/$(SLIBNAME:$(SLIBSUF)=.lib)"; \
- install -m 644 $(SUBDIR)$(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.lib) "$(SHLIBDIR)/$(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.lib)"; \
- install -d "$(LIBDIR)"; \
- install -m 644 $(SUBDIR)lib$(SLIBNAME:$(SLIBSUF)=.dll.a) "$(LIBDIR)/lib$(SLIBNAME:$(SLIBSUF)=.dll.a)"'
- SLIB_UNINSTALL_EXTRA_CMD='rm -f "$(SHLIBDIR)/$(SLIBNAME:$(SLIBSUF)=.lib)"'
+ SLIB_EXTRA_CMD='-lib.exe /machine:$(LIBTARGET) /def:$$(@:$(SLIBSUF)=.def) /out:$(SUBDIR)$(SLIBNAME:$(SLIBSUF)=.lib)'
+ SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)'
+ SLIB_INSTALL_LINKS=
+ SLIB_INSTALL_EXTRA_SHLIB='$(SLIBNAME:$(SLIBSUF)=.lib)'
+ SLIB_INSTALL_EXTRA_LIB='lib$(SLIBNAME:$(SLIBSUF)=.dll.a) $(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.def)'
SHFLAGS='-shared -Wl,--output-def,$$(@:$(SLIBSUF)=.def) -Wl,--out-implib,$(SUBDIR)lib$(SLIBNAME:$(SLIBSUF)=.dll.a) -Wl,--enable-runtime-pseudo-reloc -Wl,--enable-auto-image-base'
objformat="win32"
- dlltool="${cross_prefix}dlltool"
enable dos_paths
check_cflags -fno-common
check_cpp_condition _mingw.h "defined (__MINGW64_VERSION_MAJOR) || (__MINGW32_MAJOR_VERSION > 3) \
@@ -2463,6 +2618,7 @@ case $target_os in
ranlib="echo ignoring ranlib"
;;
os/2*)
+ strip="lxlite -CS"
ln_s="cp -f"
objformat="aout"
add_cppflags -D_GNU_SOURCE
@@ -2482,14 +2638,14 @@ case $target_os in
emxexp -o $(OBJS) >> $(SUBDIR)$(NAME).def'
SLIB_EXTRA_CMD='emximp -o $(SUBDIR)$(LIBPREF)$(NAME)_dll.a $(SUBDIR)$(NAME).def; \
emximp -o $(SUBDIR)$(LIBPREF)$(NAME)_dll.lib $(SUBDIR)$(NAME).def;'
- SLIB_INSTALL_EXTRA_CMD='install -m 644 $(SUBDIR)$(LIBPREF)$(NAME)_dll.a $(SUBDIR)$(LIBPREF)$(NAME)_dll.lib "$(LIBDIR)"'
- SLIB_UNINSTALL_EXTRA_CMD='rm -f "$(LIBDIR)"/$(LIBPREF)$(NAME)_dll.a "$(LIBDIR)"/$(LIBPREF)$(NAME)_dll.lib'
+ SLIB_INSTALL_EXTRA_LIB='$(LIBPREF)$(NAME)_dll.a $(LIBPREF)$(NAME)_dll.lib'
enable dos_paths
;;
gnu/kfreebsd)
add_cppflags -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 -D_BSD_SOURCE
;;
gnu)
+ add_cppflags -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600
;;
qnx)
add_cppflags -D_QNX_SOURCE
@@ -2498,7 +2654,14 @@ case $target_os in
symbian)
SLIBSUF=".dll"
enable dos_paths
- add_cflags --include=$sysinclude/gcce/gcce.h
+ add_cflags --include=$sysinclude/gcce/gcce.h -fvisibility=default
+ add_cppflags -D__GCCE__ -D__SYMBIAN32__ -DSYMBIAN_OE_POSIX_SIGNALS
+ add_ldflags -Wl,--target1-abs,--no-undefined \
+ -Wl,-Ttext,0x80000,-Tdata,0x1000000 -shared \
+ -Wl,--entry=_E32Startup -Wl,-u,_E32Startup
+ add_extralibs -l:eexe.lib -l:usrt2_2.lib -l:dfpaeabi.dso \
+ -l:drtaeabi.dso -l:scppnwdl.dso -lsupc++ -lgcc \
+ -l:libc.dso -l:libm.dso -l:euser.dso -l:libcrt0.lib
;;
none)
;;
@@ -2507,7 +2670,7 @@ case $target_os in
;;
esac
-echo "config:$arch:$subarch:$cpu:$target_os:$cc_ident:$LIBAV_CONFIGURATION" >config.fate
+echo "config:$arch:$subarch:$cpu:$target_os:$cc_ident:$FFMPEG_CONFIGURATION" >config.fate
check_cpp_condition stdlib.h "defined(__PIC__) || defined(__pic__) || defined(PIC)" && enable pic
@@ -2528,11 +2691,13 @@ die_license_disabled() {
enabled $1 || { enabled $2 && die "$2 is $1 and --enable-$1 is not specified."; }
}
+die_license_disabled gpl libcdio
die_license_disabled gpl libx264
die_license_disabled gpl libxavs
die_license_disabled gpl libxvid
die_license_disabled gpl x11grab
+die_license_disabled nonfree libaacplus
die_license_disabled nonfree libfaac
die_license_disabled version3 libopencore_amrnb
@@ -2597,7 +2762,7 @@ elif enabled arm; then
elif ! check_cpp_condition stddef.h "defined __ARM_PCS || defined __SOFTFP__"; then
case "${cross_prefix:-$cc}" in
*hardfloat*) enable vfp_args; fpabi=vfp ;;
- *) check_ld <<EOF && enable vfp_args && fpabi=vfp || fpabi=soft ;;
+ *) check_ld "cc" <<EOF && enable vfp_args && fpabi=vfp || fpabi=soft ;;
__asm__ (".eabi_attribute 28, 1");
int main(void) { return 0; }
EOF
@@ -2613,6 +2778,8 @@ EOF
enabled neon && check_asm neon '"vadd.i16 q0, q0, q0"'
enabled vfpv3 && check_asm vfpv3 '"vmov.f32 s0, #1.0"'
+ check_asm asm_mod_y '"vmul.i32 d0, d0, %y0" :: "x"(0)'
+
enabled_all armv6t2 shared !pic && enable_pic
elif enabled mips; then
@@ -2775,7 +2942,9 @@ check_func mmap
check_func ${malloc_prefix}posix_memalign && enable posix_memalign
check_func setrlimit
check_func strerror_r
-check_func strtok_r
+check_func strptime
+check_func_headers conio.h kbhit
+check_func_headers windows.h PeekNamedPipe
check_func_headers io.h setmode
check_func_headers lzo/lzo1x.h lzo1x_999_compress
check_lib2 "windows.h psapi.h" GetProcessMemoryInfo -lpsapi
@@ -2784,18 +2953,18 @@ check_func_headers windows.h MapViewOfFile
check_func_headers windows.h VirtualAlloc
check_header dlfcn.h
-check_header dxva2api.h
+check_header dxva2api.h -D_WIN32_WINNT=0x0600
+check_header libcrystalhd/libcrystalhd_if.h
check_header malloc.h
check_header poll.h
check_header sys/mman.h
check_header sys/resource.h
check_header sys/select.h
+check_header termios.h
check_header vdpau/vdpau.h
check_header vdpau/vdpau_x11.h
check_header X11/extensions/XvMClib.h
-check_struct dxva2api.h DXVA_PictureParameters wDecodedPictureIndex
-
disabled zlib || check_lib zlib.h zlibVersion -lz || disable zlib
disabled bzlib || check_lib2 bzlib.h BZ2_bzlibVersion -lbz2 || disable bzlib
@@ -2827,6 +2996,7 @@ for thread in $THREADS_LIST; do
done
check_lib math.h sin -lm && LIBM="-lm"
+disabled crystalhd || check_lib libcrystalhd/libcrystalhd_if.h DtsCrystalHDVersion -lcrystalhd || disable crystalhd
enabled vaapi && require vaapi va/va.h vaInitialize -lva
check_mathfunc exp2
@@ -2844,52 +3014,68 @@ check_mathfunc truncf
# these are off by default, so fail if requested and not available
enabled avisynth && require2 vfw32 "windows.h vfw.h" AVIFileInit -lavifil32
+enabled libcelt && require libcelt celt/celt.h celt_decode -lcelt0
enabled frei0r && { check_header frei0r.h || die "ERROR: frei0r.h header not found"; }
+enabled libaacplus && require "libaacplus >= 2.0.0" aacplus.h aacplusEncOpen -laacplus
+enabled libdc1394 && require_pkg_config libdc1394-2 dc1394/dc1394.h dc1394_new
enabled libdirac && require_pkg_config dirac \
"libdirac_decoder/dirac_parser.h libdirac_encoder/dirac_encoder.h" \
"dirac_decoder_init dirac_encoder_init"
enabled libfaac && require2 libfaac "stdint.h faac.h" faacEncGetVersion -lfaac
enabled libfreetype && require_pkg_config freetype2 "ft2build.h freetype/freetype.h" FT_Init_FreeType
enabled libgsm && require libgsm gsm/gsm.h gsm_create -lgsm
+enabled libmodplug && require libmodplug libmodplug/modplug.h ModPlug_Load -lmodplug
enabled libmp3lame && require "libmp3lame >= 3.98.3" lame/lame.h lame_set_VBR_quality -lmp3lame
enabled libnut && require libnut libnut.h nut_demuxer_init -lnut
enabled libopencore_amrnb && require libopencore_amrnb opencore-amrnb/interf_dec.h Decoder_Interface_init -lopencore-amrnb
enabled libopencore_amrwb && require libopencore_amrwb opencore-amrwb/dec_if.h D_IF_init -lopencore-amrwb
-enabled libopencv && require_pkg_config opencv opencv/cv.h cvCreateImageHeader
+enabled libopencv && require_pkg_config opencv opencv/cxcore.h cvCreateImageHeader
enabled libopenjpeg && require libopenjpeg openjpeg.h opj_version -lopenjpeg
+enabled libpulse && require_pkg_config libpulse-simple pulse/simple.h pa_simple_new
enabled librtmp && require_pkg_config librtmp librtmp/rtmp.h RTMP_Socket
enabled libschroedinger && require_pkg_config schroedinger-1.0 schroedinger/schro.h schro_init
enabled libspeex && require libspeex speex/speex.h speex_decoder_init -lspeex
+enabled libstagefright_h264 && require_cpp libstagefright_h264 "binder/ProcessState.h media/stagefright/MetaData.h
+ media/stagefright/MediaBufferGroup.h media/stagefright/MediaDebug.h media/stagefright/MediaDefs.h
+ media/stagefright/OMXClient.h media/stagefright/OMXCodec.h" android::OMXClient -lstagefright -lmedia -lutils -lbinder
enabled libtheora && require libtheora theora/theoraenc.h th_info_init -ltheoraenc -ltheoradec -logg
+enabled libutvideo && require_cpp utvideo "stdint.h stdlib.h utvideo/utvideo.h utvideo/Codec.h" 'CCodec*' -lutvideo -lstdc++
enabled libvo_aacenc && require libvo_aacenc vo-aacenc/voAAC.h voGetAACEncAPI -lvo-aacenc
enabled libvo_amrwbenc && require libvo_amrwbenc vo-amrwbenc/enc_if.h E_IF_init -lvo-amrwbenc
enabled libvorbis && require libvorbis vorbis/vorbisenc.h vorbis_info_init -lvorbisenc -lvorbis -logg
enabled libvpx && {
enabled libvpx_decoder && { check_lib2 "vpx/vpx_decoder.h vpx/vp8dx.h" vpx_codec_dec_init_ver -lvpx ||
die "ERROR: libvpx decoder version must be >=0.9.1"; }
- enabled libvpx_encoder && { check_lib2 "vpx/vpx_encoder.h vpx/vp8cx.h" vpx_codec_enc_init_ver -lvpx ||
- die "ERROR: libvpx encoder version must be >=0.9.1"; } }
+ enabled libvpx_encoder && { check_lib2 "vpx/vpx_encoder.h vpx/vp8cx.h" "vpx_codec_enc_init_ver VPX_CQ" -lvpx ||
+ die "ERROR: libvpx encoder version must be >=0.9.6"; } }
enabled libx264 && require libx264 x264.h x264_encoder_encode -lx264 &&
- { check_cpp_condition x264.h "X264_BUILD >= 115" ||
- die "ERROR: libx264 version must be >= 0.115."; }
+ { check_cpp_condition x264.h "X264_BUILD >= 118" ||
+ die "ERROR: libx264 version must be >= 0.118."; }
enabled libxavs && require libxavs xavs.h xavs_encoder_encode -lxavs
enabled libxvid && require libxvid xvid.h xvid_global -lxvidcore
+enabled openal && { { for al_libs in "${OPENAL_LIBS}" "-lopenal" "-lOpenAL32"; do
+ check_lib 'AL/al.h' alGetError "${al_libs}" && break; done } ||
+ die "ERROR: openal not found"; } &&
+ { check_cpp_condition "AL/al.h" "defined(AL_VERSION_1_1)" ||
+ die "ERROR: openal version must be 1.1 or compatible"; }
enabled mlib && require mediaLib mlib_types.h mlib_VectorSub_S16_U8_Mod -lmlib
-# libdc1394 check
-if enabled libdc1394; then
- { check_lib dc1394/dc1394.h dc1394_new -ldc1394 -lraw1394 &&
- enable libdc1394_2; } ||
- { check_lib libdc1394/dc1394_control.h dc1394_create_handle -ldc1394_control -lraw1394 &&
- enable libdc1394_1; } ||
- die "ERROR: No version of libdc1394 found "
-fi
-
+SDL_CONFIG="${cross_prefix}sdl-config"
if check_pkg_config sdl SDL_version.h SDL_Linked_Version; then
check_cpp_condition SDL.h "(SDL_MAJOR_VERSION<<16 | SDL_MINOR_VERSION<<8 | SDL_PATCHLEVEL) >= 0x010201" $sdl_cflags &&
enable sdl &&
check_struct SDL.h SDL_VideoInfo current_w $sdl_cflags && enable sdl_video_size
+else
+ if "${SDL_CONFIG}" --version > /dev/null 2>&1; then
+ sdl_cflags=$("${SDL_CONFIG}" --cflags)
+ sdl_libs=$("${SDL_CONFIG}" --libs)
+ check_func_headers SDL_version.h SDL_Linked_Version $sdl_cflags $sdl_libs &&
+ check_cpp_condition SDL.h "(SDL_MAJOR_VERSION<<16 | SDL_MINOR_VERSION<<8 | SDL_PATCHLEVEL) >= 0x010201" $sdl_cflags &&
+ enable sdl &&
+ check_struct SDL.h SDL_VideoInfo current_w $sdl_cflags && enable sdl_video_size
+ fi
fi
+enabled sdl && add_cflags $sdl_cflags && add_extralibs $sdl_libs
texi2html -version > /dev/null 2>&1 && enable texi2html || disable texi2html
@@ -2903,6 +3089,8 @@ check_func_headers "windows.h vfw.h" capCreateCaptureWindow "$vfwcap_indev_extra
# w32api 3.12 had it defined wrong
check_cpp_condition vfw.h "WM_CAP_DRIVER_CONNECT > WM_USER" && enable vfwcap_defines
+check_type "dshow.h" IBaseFilter
+
# check for ioctl_meteor.h, ioctl_bt848.h and alternatives
{ check_header dev/bktr/ioctl_meteor.h &&
check_header dev/bktr/ioctl_bt848.h; } ||
@@ -2913,15 +3101,25 @@ check_cpp_condition vfw.h "WM_CAP_DRIVER_CONNECT > WM_USER" && enable vfwcap_def
check_header dev/ic/bt8xx.h
check_header sndio.h
-check_header sys/soundcard.h
+if check_struct sys/soundcard.h audio_buf_info bytes; then
+ enable_safe sys/soundcard.h
+else
+ check_cc -D__BSD_VISIBLE -D__XSI_VISIBLE <<EOF && add_cppflags -D__BSD_VISIBLE -D__XSI_VISIBLE && enable_safe sys/soundcard.h
+ #include <sys/soundcard.h>
+ audio_buf_info abc;
+EOF
+fi
check_header soundcard.h
enabled_any alsa_indev alsa_outdev && check_lib2 alsa/asoundlib.h snd_pcm_htimestamp -lasound
-enabled jack_indev && check_lib2 jack/jack.h jack_client_open -ljack
+enabled jack_indev && check_lib2 jack/jack.h jack_client_open -ljack && check_func sem_timedwait
enabled_any sndio_indev sndio_outdev && check_lib2 sndio.h sio_open -lsndio
+enabled libcdio &&
+ check_lib2 "cdio/cdda.h cdio/paranoia.h" cdio_cddap_open "-lcdio_paranoia -lcdio_cdda -lcdio"
+
enabled x11grab &&
check_header X11/Xlib.h &&
check_header X11/extensions/XShm.h &&
@@ -2930,6 +3128,13 @@ check_func XOpenDisplay -lX11 &&
check_func XShmCreateImage -lX11 -lXext &&
check_func XFixesGetCursorImage -lX11 -lXext -lXfixes
+if ! disabled vaapi; then
+ check_lib va/va.h vaInitialize -lva && {
+ check_cpp_condition va/va_version.h "VA_CHECK_VERSION(0,32,0)" ||
+ warn "Please upgrade to VA-API >= 0.32 if you would like full VA-API support.";
+ } || disable vaapi
+fi
+
if ! disabled vdpau && enabled vdpau_vdpau_h; then
check_cpp_condition \
vdpau/vdpau.h "defined VDP_DECODER_PROFILE_MPEG4_PART2_ASP" ||
@@ -2954,11 +3159,13 @@ check_cflags -Wwrite-strings
check_cflags -Wtype-limits
check_cflags -Wundef
check_cflags -Wmissing-prototypes
+check_cflags -Wno-pointer-to-int-cast
+check_cflags -Wstrict-prototypes
enabled extra_warnings && check_cflags -Winline
# add some linker flags
check_ldflags -Wl,--warn-common
-check_ldflags -Wl,-rpath-link=libpostproc:libswscale:libavfilter:libavdevice:libavformat:libavcodec:libavutil
+check_ldflags -Wl,-rpath-link=libpostproc:libswresample:libswscale:libavfilter:libavdevice:libavformat:libavcodec:libavutil
test_ldflags -Wl,-Bsymbolic && append SHFLAGS -Wl,-Bsymbolic
echo "X{};" > $TMPV
@@ -2985,6 +3192,10 @@ else
fi
check_cflags -fno-math-errno
check_cflags -fno-signed-zeros
+check_cc -mno-red-zone <<EOF && noredzone_flags="-mno-red-zone"
+int x;
+EOF
+
if enabled icc; then
# Just warnings, no remarks
@@ -3063,6 +3274,11 @@ check_deps $CONFIG_LIST \
enabled asm || { arch=c; disable $ARCH_LIST $ARCH_EXT_LIST; }
+if test $target_os = "haiku"; then
+ disable memalign
+ disable posix_memalign
+fi
+
! enabled_any memalign posix_memalign malloc_aligned &&
enabled_any $need_memalign && enable memalign_hack
@@ -3073,6 +3289,9 @@ echo "ARCH $arch ($cpu)"
if test "$build_suffix" != ""; then
echo "build suffix $build_suffix"
fi
+if test "$progs_suffix" != ""; then
+ echo "progs suffix $progs_suffix"
+fi
if test "$extra_version" != ""; then
echo "version string suffix $extra_version"
fi
@@ -3112,6 +3331,7 @@ if enabled sparc; then
echo "VIS enabled ${vis-no}"
fi
echo "debug symbols ${debug-no}"
+echo "strip symbols ${stripping-no}"
echo "optimize for size ${small-no}"
echo "optimizations ${optimizations-no}"
echo "static ${static-no}"
@@ -3126,21 +3346,28 @@ echo "libdxva2 enabled ${dxva2-no}"
echo "libva enabled ${vaapi-no}"
echo "libvdpau enabled ${vdpau-no}"
echo "AVISynth enabled ${avisynth-no}"
+echo "libcelt enabled ${libcelt-no}"
echo "frei0r enabled ${frei0r-no}"
+echo "libcdio support ${libcdio-no}"
echo "libdc1394 support ${libdc1394-no}"
echo "libdirac enabled ${libdirac-no}"
echo "libfaac enabled ${libfaac-no}"
+echo "libaacplus enabled ${libaacplus-no}"
echo "libgsm enabled ${libgsm-no}"
+echo "libmodplug enabled ${libmodplug-no}"
echo "libmp3lame enabled ${libmp3lame-no}"
echo "libnut enabled ${libnut-no}"
echo "libopencore-amrnb support ${libopencore_amrnb-no}"
echo "libopencore-amrwb support ${libopencore_amrwb-no}"
echo "libopencv support ${libopencv-no}"
echo "libopenjpeg enabled ${libopenjpeg-no}"
+echo "libpulse enabled ${libpulse-no}"
echo "librtmp enabled ${librtmp-no}"
echo "libschroedinger enabled ${libschroedinger-no}"
echo "libspeex enabled ${libspeex-no}"
+echo "libstagefright-h264 enabled ${libstagefright_h264-no}"
echo "libtheora enabled ${libtheora-no}"
+echo "libutvideo enabled ${libutvideo-no}"
echo "libvo-aacenc support ${libvo_aacenc-no}"
echo "libvo-amrwbenc support ${libvo_amrwbenc-no}"
echo "libvorbis enabled ${libvorbis-no}"
@@ -3148,6 +3375,7 @@ echo "libvpx enabled ${libvpx-no}"
echo "libx264 enabled ${libx264-no}"
echo "libxavs enabled ${libxavs-no}"
echo "libxvid enabled ${libxvid-no}"
+echo "openal enabled ${openal-no}"
echo "zlib enabled ${zlib-no}"
echo "bzlib enabled ${bzlib-no}"
echo
@@ -3176,11 +3404,15 @@ echo "Creating config.mak and config.h..."
test -e Makefile || $ln_s "$source_path/Makefile" .
+enabled stripping || strip="echo skipping strip"
+
config_files="$TMPH config.mak"
cat > config.mak <<EOF
# Automatically generated by configure - do not modify!
-LIBAV_CONFIGURATION=$LIBAV_CONFIGURATION
+ifndef FFMPEG_CONFIG_MAK
+FFMPEG_CONFIG_MAK=1
+FFMPEG_CONFIGURATION=$FFMPEG_CONFIGURATION
prefix=$prefix
LIBDIR=\$(DESTDIR)$libdir
SHLIBDIR=\$(DESTDIR)$shlibdir
@@ -3189,9 +3421,13 @@ BINDIR=\$(DESTDIR)$bindir
DATADIR=\$(DESTDIR)$datadir
MANDIR=\$(DESTDIR)$mandir
SRC_PATH=$source_path
+ifndef MAIN_MAKEFILE
+SRC_PATH:=\$(SRC_PATH:.%=..%)
+endif
CC_IDENT=$cc_ident
ARCH=$arch
CC=$cc
+CXX=$cxx
AS=$as
LD=$ld
DEPCC=$dep_cc
@@ -3199,18 +3435,22 @@ YASM=$yasmexe
YASMDEP=$yasmexe
AR=$ar
RANLIB=$ranlib
+CP=cp -p
LN_S=$ln_s
+STRIP=$strip
CPPFLAGS=$CPPFLAGS
CFLAGS=$CFLAGS
+CXXFLAGS=$CXXFLAGS
ASFLAGS=$ASFLAGS
AS_O=$CC_O
CC_O=$CC_O
-DLLTOOL=$dlltool
+CXX_O=$CXX_O
LDFLAGS=$LDFLAGS
FFSERVERLDFLAGS=$FFSERVERLDFLAGS
SHFLAGS=$SHFLAGS
YASMFLAGS=$YASMFLAGS
BUILDSUF=$build_suffix
+PROGSSUF=$progs_suffix
FULLNAME=$FULLNAME
LIBPREF=$LIBPREF
LIBSUF=$LIBSUF
@@ -3221,6 +3461,7 @@ EXESUF=$EXESUF
EXTRA_VERSION=$extra_version
DEPFLAGS=$DEPFLAGS
CCDEP=$CCDEP
+CXXDEP=$CXXDEP
ASDEP=$ASDEP
CC_DEPFLAGS=$CC_DEPFLAGS
AS_DEPFLAGS=$AS_DEPFLAGS
@@ -3235,16 +3476,19 @@ SDL_LIBS=$sdl_libs
SDL_CFLAGS=$sdl_cflags
LIB_INSTALL_EXTRA_CMD=$LIB_INSTALL_EXTRA_CMD
EXTRALIBS=$extralibs
-INSTALL=install
+INSTALL=$install
LIBTARGET=${LIBTARGET}
SLIBNAME=${SLIBNAME}
SLIBNAME_WITH_VERSION=${SLIBNAME_WITH_VERSION}
SLIBNAME_WITH_MAJOR=${SLIBNAME_WITH_MAJOR}
SLIB_CREATE_DEF_CMD=${SLIB_CREATE_DEF_CMD}
SLIB_EXTRA_CMD=${SLIB_EXTRA_CMD}
-SLIB_INSTALL_EXTRA_CMD=${SLIB_INSTALL_EXTRA_CMD}
-SLIB_UNINSTALL_EXTRA_CMD=${SLIB_UNINSTALL_EXTRA_CMD}
+SLIB_INSTALL_NAME=${SLIB_INSTALL_NAME}
+SLIB_INSTALL_LINKS=${SLIB_INSTALL_LINKS}
+SLIB_INSTALL_EXTRA_LIB=${SLIB_INSTALL_EXTRA_LIB}
+SLIB_INSTALL_EXTRA_SHLIB=${SLIB_INSTALL_EXTRA_SHLIB}
SAMPLES:=${samples:-\$(FATE_SAMPLES)}
+NOREDZONE_FLAGS=$noredzone_flags
EOF
get_version(){
@@ -3258,6 +3502,7 @@ get_version(){
}
get_version LIBSWSCALE libswscale/swscale.h
+get_version LIBSWRESAMPLE libswresample/swresample.h
get_version LIBPOSTPROC libpostproc/postprocess.h
get_version LIBAVCODEC libavcodec/version.h
get_version LIBAVDEVICE libavdevice/avdevice.h
@@ -3267,11 +3512,12 @@ get_version LIBAVFILTER libavfilter/avfilter.h
cat > $TMPH <<EOF
/* Automatically generated by configure - do not modify! */
-#ifndef LIBAV_CONFIG_H
-#define LIBAV_CONFIG_H
-#define LIBAV_CONFIGURATION "$(c_escape $LIBAV_CONFIGURATION)"
-#define LIBAV_LICENSE "$(c_escape $license)"
+#ifndef FFMPEG_CONFIG_H
+#define FFMPEG_CONFIG_H
+#define FFMPEG_CONFIGURATION "$(c_escape $FFMPEG_CONFIGURATION)"
+#define FFMPEG_LICENSE "$(c_escape $license)"
#define FFMPEG_DATADIR "$(eval c_escape $datadir)"
+#define AVCONV_DATADIR "$(eval c_escape $datadir)"
#define CC_TYPE "$cc_type"
#define CC_VERSION $cc_version
#define restrict $_restrict
@@ -3321,7 +3567,8 @@ LAVFI_TESTS=$(print_enabled -n _test $LAVFI_TESTS)
SEEK_TESTS=$(print_enabled -n _test $SEEK_TESTS)
EOF
-echo "#endif /* LIBAV_CONFIG_H */" >> $TMPH
+echo "#endif /* FFMPEG_CONFIG_H */" >> $TMPH
+echo "endif # FFMPEG_CONFIG_MAK" >> config.mak
# Do not overwrite an unchanged config.h to avoid superfluous rebuilds.
cp_if_changed $TMPH config.h
@@ -3386,10 +3633,11 @@ Cflags: -I\${includedir}
EOF
}
-pkgconfig_generate libavutil "Libav utility library" "$LIBAVUTIL_VERSION" "$LIBM"
-pkgconfig_generate libavcodec "Libav codec library" "$LIBAVCODEC_VERSION" "$extralibs" "libavutil = $LIBAVUTIL_VERSION"
-pkgconfig_generate libavformat "Libav container format library" "$LIBAVFORMAT_VERSION" "$extralibs" "libavcodec = $LIBAVCODEC_VERSION"
-pkgconfig_generate libavdevice "Libav device handling library" "$LIBAVDEVICE_VERSION" "$extralibs" "libavformat = $LIBAVFORMAT_VERSION"
-pkgconfig_generate libavfilter "Libav video filtering library" "$LIBAVFILTER_VERSION" "$extralibs"
-pkgconfig_generate libpostproc "Libav post processing library" "$LIBPOSTPROC_VERSION" "" "libavutil = $LIBAVUTIL_VERSION"
-pkgconfig_generate libswscale "Libav image rescaling library" "$LIBSWSCALE_VERSION" "$LIBM" "libavutil = $LIBAVUTIL_VERSION"
+pkgconfig_generate libavutil "FFmpeg utility library" "$LIBAVUTIL_VERSION" "$LIBM"
+pkgconfig_generate libavcodec "FFmpeg codec library" "$LIBAVCODEC_VERSION" "$extralibs" "libavutil = $LIBAVUTIL_VERSION"
+pkgconfig_generate libavformat "FFmpeg container format library" "$LIBAVFORMAT_VERSION" "$extralibs" "libavcodec = $LIBAVCODEC_VERSION"
+pkgconfig_generate libavdevice "FFmpeg device handling library" "$LIBAVDEVICE_VERSION" "$extralibs" "libavformat = $LIBAVFORMAT_VERSION"
+pkgconfig_generate libavfilter "FFmpeg video filtering library" "$LIBAVFILTER_VERSION" "$extralibs"
+pkgconfig_generate libpostproc "FFmpeg postprocessing library" "$LIBPOSTPROC_VERSION" "" "libavutil = $LIBAVUTIL_VERSION"
+pkgconfig_generate libswscale "FFmpeg image rescaling library" "$LIBSWSCALE_VERSION" "$LIBM" "libavutil = $LIBAVUTIL_VERSION"
+pkgconfig_generate libswresample "FFmpeg audio rescaling library" "$LIBSWRESAMPLE_VERSION" "$LIBM" "libavutil = $LIBAVUTIL_VERSION"
diff --git a/doc/APIchanges b/doc/APIchanges
index 65e1da7a62..c2415f0be8 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,50 +13,257 @@ libavutil: 2011-04-18
API changes, most recent first:
-2011-06-xx - xxxxxxx - lavu 51.8.0 - attributes.h
+2011-10-20 - b35e9e1 - lavu 51.22.0
+ Add av_strtok() to avstring.h.
+
+2011-10-xx - xxxxxxx - lavf 53.10.0
+ Add avformat_new_stream(). Deprecate av_new_stream().
+
+2011-xx-xx - xxxxxxx - lavf 53.9.0
+ Add AVFMT_NO_BYTE_SEEK AVInputFormat flag.
+
+2011-10-12 - lavu 51.12.0
+ AVOptions API rewrite.
+
+ - 145f741 FF_OPT_TYPE* renamed to AV_OPT_TYPE_*
+ - new setting/getting functions with slightly different semantics:
+ dac66da av_set_string3 -> av_opt_set
+ av_set_double -> av_opt_set_double
+ av_set_q -> av_opt_set_q
+ av_set_int -> av_opt_set_int
+
+ 41d9d51 av_get_string -> av_opt_get
+ av_get_double -> av_opt_get_double
+ av_get_q -> av_opt_get_q
+ av_get_int -> av_opt_get_int
+
+ - 8c5dcaa trivial rename av_next_option -> av_opt_next
+ - 641c7af new functions - av_opt_child_next, av_opt_child_class_next
+ and av_opt_find2()
+
+2011-09-22 - xxxxxxx - lavu 51.17.0
+ Add av_x_if_null().
+
+2011-09-18 - xxxxxxx - lavc 53.16.0
+ Add showall flag2
+
+2011-09-16 - xxxxxxx - lavfi 2.42.0
+ Add avfilter_all_channel_layouts.
+
+2011-09-16 - xxxxxxx - lavfi 2.41.0
+ Rename avfilter_all_* function names to avfilter_make_all_*.
+
+ In particular, apply the renames:
+ avfilter_all_formats -> avfilter_make_all_formats
+ avfilter_all_channel_layouts -> avfilter_make_all_channel_layouts
+ avfilter_all_packing_formats -> avfilter_make_all_packing_formats
+
+2011-09-12 - xxxxxxx - lavfi 2.40.0
+ Change AVFilterBufferRefAudioProps.sample_rate type from uint32_t to int.
+
+2011-09-12 - xxxxxxx - lavfi 2.40.0
+ Simplify signature for avfilter_get_audio_buffer(), make it
+ consistent with avfilter_get_video_buffer().
+
+2011-09-06 - xxxxxxx - lavfi 2.39.0
+ Rename libavfilter/vsink_buffer.h to libavfilter/buffersink.h.
+
+2011-09-06 - xxxxxxx - lavfi 2.38.0
+ Unify video and audio sink API.
+
+ In particular, add av_buffersink_get_buffer_ref(), deprecate
+ av_vsink_buffer_get_video_buffer_ref() and change the value for the
+ opaque field passed to the abuffersink init function.
+
+2011-09-xx - xxxxxxx - lavu 51.16.0
+ Add av_asprintf().
+
+2011-08-22 - dacd827 - lavf 53.10.0
+ Add av_find_program_from_stream().
+
+2011-08-20 - 69e2c1a - lavu 51.13.0
+ Add av_get_media_type_string().
+
+2011-09-03 - fb4ca26 - lavc 53.13.0
+ lavf 53.11.0
+ lsws 2.1.0
+ Add {avcodec,avformat,sws}_get_class().
+
+2011-08-03 - c11fb82 - lavu 51.15.0
+ Add AV_OPT_SEARCH_FAKE_OBJ flag for av_opt_find() function.
+
+2011-08-14 - 323b930 - lavu 51.12.0
+ Add av_fifo_peek2(), deprecate av_fifo_peek().
+
+2011-08-16 - 48f9e45 - lavf 53.8.0
+ Add avformat_query_codec().
+
+2011-08-16 - bca06e7 - lavc 53.11.0
+ Add avcodec_get_type().
+
+2011-08-06 - 2f63440 - lavf 53.7.0
+ Add error_recognition to AVFormatContext.
+
+2011-08-02 - 9d39cbf - lavc 53.9.1
+ Add AV_PKT_FLAG_CORRUPT AVPacket flag.
+
+2011-07-16 - b57df29 - lavfi 2.27.0
+ Add audio packing negotiation fields and helper functions.
+
+ In particular, add AVFilterPacking enum, planar, in_packings and
+ out_packings fields to AVFilterLink, and the functions:
+ avfilter_set_common_packing_formats()
+ avfilter_all_packing_formats()
+
+2011-07-10 - a67c061 - lavf 53.6.0
+ Add avformat_find_stream_info(), deprecate av_find_stream_info().
+
+2011-07-10 - 0b950fe - lavc 53.8.0
+ Add avcodec_open2(), deprecate avcodec_open().
+
+2011-07-01 - b442ca6 - lavf 53.5.0 - avformat.h
+ Add function av_get_output_timestamp().
+
+2011-06-28 - 5129336 - lavu 51.11.0 - avutil.h
+ Define the AV_PICTURE_TYPE_NONE value in AVPictureType enum.
+
+2011-06-19 - fd2c0a5 - lavfi 2.23.0 - avfilter.h
+ Add layout negotiation fields and helper functions.
+
+ In particular, add in_chlayouts and out_chlayouts to AVFilterLink,
+ and the functions:
+ avfilter_set_common_sample_formats()
+ avfilter_set_common_channel_layouts()
+ avfilter_all_channel_layouts()
+
+2011-06-19 - 527ca39 - lavfi 2.22.0 - AVFilterFormats
+ Change type of AVFilterFormats.formats from int * to int64_t *,
+ and update formats handling API accordingly.
+
+ avfilter_make_format_list() still takes a int32_t array and converts
+ it to int64_t. A new function, avfilter_make_format64_list(), that
+ takes int64_t arrays has been added.
+
+2011-06-19 - 44f669e - lavfi 2.21.0 - vsink_buffer.h
+ Add video sink buffer and vsink_buffer.h public header.
+
+2011-06-12 - 9fdf772 - lavfi 2.18.0 - avcodec.h
+ Add avfilter_get_video_buffer_ref_from_frame() function in
+ libavfilter/avcodec.h.
+
+2011-06-12 - c535494 - lavfi 2.17.0 - avfiltergraph.h
+ Add avfilter_inout_alloc() and avfilter_inout_free() functions.
+
+2011-06-12 - 6119b23 - lavfi 2.16.0 - avfilter_graph_parse()
+ Change avfilter_graph_parse() signature.
+
+2011-06-23 - 67e9ae1 - lavu 51.8.0 - attributes.h
Add av_printf_format().
-2011-06-xx - xxxxxxx - lavf 53.2.0 - avformat.h
+2011-06-16 - 05e84c9, 25de595 - lavf 53.2.0 - avformat.h
Add avformat_open_input and avformat_write_header().
Deprecate av_open_input_stream, av_open_input_file,
AVFormatParameters and av_write_header.
-2011-06-xx - xxxxxxx - lavu 51.7.0 - opt.h
+2011-06-16 - 7e83e1c, dc59ec5 - lavu 51.7.0 - opt.h
Add av_opt_set_dict() and av_opt_find().
Deprecate av_find_opt().
Add AV_DICT_APPEND flag.
-2011-06-xx - xxxxxxx - lavu 51.6.0 - opt.h
+2011-06-10 - cb7c11c - lavu 51.6.0 - opt.h
Add av_opt_flag_is_set().
-2011-06-xx - xxxxxxx - lavu 51.5.0 - AVMetadata
+2011-06-10 - c381960 - lavfi 2.15.0 - avfilter_get_audio_buffer_ref_from_arrays
+ Add avfilter_get_audio_buffer_ref_from_arrays() to avfilter.h.
+
+2011-06-09 - d9f80ea - lavu 51.8.0 - AVMetadata
Move AVMetadata from lavf to lavu and rename it to
AVDictionary -- new installed header dict.h.
All av_metadata_* functions renamed to av_dict_*.
-2011-06-07 - a6703fa - lavu 51.4.0 - av_get_bytes_per_sample()
+2011-06-07 - a6703fa - lavu 51.8.0 - av_get_bytes_per_sample()
Add av_get_bytes_per_sample() in libavutil/samplefmt.h.
Deprecate av_get_bits_per_sample_fmt().
-2011-06-xx - xxxxxxx - lavu 51.3.0 - opt.h
+2011-06-xx - b39b062 - lavu 51.8.0 - opt.h
Add av_opt_free convenience function.
-2011-05-28 - 0420bd7 - lavu 51.2.0 - pixdesc.h
+2011-06-06 - 95a0242 - lavfi 2.14.0 - AVFilterBufferRefAudioProps
+ Remove AVFilterBufferRefAudioProps.size, and use nb_samples in
+ avfilter_get_audio_buffer() and avfilter_default_get_audio_buffer() in
+ place of size.
+
+2011-06-06 - 0bc2cca - lavu 51.6.0 - av_samples_alloc()
+ Switch nb_channels and nb_samples parameters order in
+ av_samples_alloc().
+
+2011-06-06 - e1c7414 - lavu 51.5.0 - av_samples_*
+ Change the data layout created by av_samples_fill_arrays() and
+ av_samples_alloc().
+
+2011-06-06 - 27bcf55 - lavfi 2.13.0 - vsrc_buffer.h
+ Make av_vsrc_buffer_add_video_buffer_ref() accepts an additional
+ flags parameter in input.
+
+2011-06-03 - e977ca2 - lavfi 2.12.0 - avfilter_link_free()
+ Add avfilter_link_free() function.
+
+2011-06-02 - 5ad38d9 - lavu 51.4.0 - av_force_cpu_flags()
+ Add av_cpu_flags() in libavutil/cpu.h.
+
+2011-05-28 - e71f260 - lavu 51.3.0 - pixdesc.h
Add av_get_pix_fmt_name() in libavutil/pixdesc.h, and deprecate
avcodec_get_pix_fmt_name() in libavcodec/avcodec.h in its favor.
-2011-05-25 - 30315a8 - lavf 53.1.0 - avformat.h
+2011-05-25 - 30315a8 - lavf 53.3.0 - avformat.h
Add fps_probe_size to AVFormatContext.
-2011-05-18 - 64150ff - lavc 53.4.0 - AVCodecContext.request_sample_fmt
+2011-05-22 - 5ecdfd0 - lavf 53.2.0 - avformat.h
+ Introduce avformat_alloc_output_context2() and deprecate
+ avformat_alloc_output_context().
+
+2011-05-22 - 83db719 - lavfi 2.10.0 - vsrc_buffer.h
+ Make libavfilter/vsrc_buffer.h public.
+
+2011-05-19 - c000a9f - lavfi 2.8.0 - avcodec.h
+ Add av_vsrc_buffer_add_frame() to libavfilter/avcodec.h.
+
+2011-05-14 - 9fdf772 - lavfi 2.6.0 - avcodec.h
+ Add avfilter_get_video_buffer_ref_from_frame() to libavfilter/avcodec.h.
+
+2011-05-18 - 64150ff - lavc 53.7.0 - AVCodecContext.request_sample_fmt
Add request_sample_fmt field to AVCodecContext.
-2011-05-10 - 188dea1 - lavc 53.3.0 - avcodec.h
+2011-05-10 - 188dea1 - lavc 53.6.0 - avcodec.h
Deprecate AVLPCType and the following fields in
AVCodecContext: lpc_coeff_precision, prediction_order_method,
min_partition_order, max_partition_order, lpc_type, lpc_passes.
Corresponding FLAC encoder options should be used instead.
+2011-05-07 - 9fdf772 - lavfi 2.5.0 - avcodec.h
+ Add libavfilter/avcodec.h header and avfilter_copy_frame_props()
+ function.
+
+2011-05-07 - 18ded93 - lavc 53.5.0 - AVFrame
+ Add format field to AVFrame.
+
+2011-05-07 - 22333a6 - lavc 53.4.0 - AVFrame
+ Add width and height fields to AVFrame.
+
+2011-05-01 - 35fe66a - lavfi 2.4.0 - avfilter.h
+ Rename AVFilterBufferRefVideoProps.pixel_aspect to
+ sample_aspect_ratio.
+
+2011-05-01 - 77e9dee - lavc 53.3.0 - AVFrame
+ Add a sample_aspect_ratio field to AVFrame.
+
+2011-05-01 - 1ba5727 - lavc 53.2.0 - AVFrame
+ Add a pkt_pos field to AVFrame.
+
+2011-04-29 - 35ceaa7 - lavu 51.2.0 - mem.h
+ Add av_dynarray_add function for adding
+ an element to a dynamic array.
+
2011-04-26 - bebe72f - lavu 51.1.0 - avutil.h
Add AVPictureType enum and av_get_picture_type_char(), deprecate
FF_*_TYPE defines and av_get_pict_type_char() defined in
@@ -108,9 +315,6 @@ API changes, most recent first:
333e894 deprecate url_open_protocol
e230705 deprecate url_poll and URLPollEntry
-2011-04-10 - lavu 50.40.0 - pixfmt.h
- Add PIX_FMT_BGR48LE and PIX_FMT_BGR48BE pixel formats
-
2011-04-08 - lavf 52.106.0 - avformat.h
Minor avformat.h cleanup:
a9bf9d8 deprecate av_guess_image2_codec
@@ -135,7 +339,6 @@ API changes, most recent first:
d9d86e0 rename url_fprintf -> avio_printf
59f65d9 deprecate url_setbufsize
3e68b3b deprecate url_ferror
- 66e5b1d deprecate url_feof
e8bb2e2 deprecate url_fget_max_packet_size
76aa876 rename url_fsize -> avio_size
e519753 deprecate url_fgetc
@@ -159,6 +362,9 @@ API changes, most recent first:
2011-03-25 - 34b47d7 - lavc 52.115.0 - AVCodecContext.audio_service_type
Add audio_service_type field to AVCodecContext.
+2011-03-17 - e309fdc - lavu 50.40.0 - pixfmt.h
+ Add PIX_FMT_BGR48LE and PIX_FMT_BGR48BE pixel formats
+
2011-03-02 - 863c471 - lavf 52.103.0 - av_pkt_dump2, av_pkt_dump_log2
Add new functions av_pkt_dump2, av_pkt_dump_log2 that uses the
source stream timebase for outputting timestamps. Deprecate
@@ -225,6 +431,12 @@ API changes, most recent first:
2011-02-02 - dfd2a00 - lavu 50.37.0 - log.h
Make av_dlog public.
+2011-01-31 - 7b3ea55 - lavfi 1.76.0 - vsrc_buffer
+ Add sample_aspect_ratio fields to vsrc_buffer arguments
+
+2011-01-31 - 910b5b8 - lavfi 1.75.0 - AVFilterLink sample_aspect_ratio
+ Add sample_aspect_ratio field to AVFilterLink.
+
2011-01-15 - r26374 - lavfi 1.74.0 - AVFilterBufferRefAudioProps
Rename AVFilterBufferRefAudioProps.samples_nb to nb_samples.
diff --git a/doc/RELEASE_NOTES b/doc/RELEASE_NOTES
index 97875e9360..7861bfd4bc 100644
--- a/doc/RELEASE_NOTES
+++ b/doc/RELEASE_NOTES
@@ -1,45 +1,58 @@
Release Notes
=============
-* 0.7 "The Big Bump" June, 2011
+* 0.8 "Love" June, 2011
+* 0.7 "Peace" June, 2011 (identical to 0.8 but using 0.6 ABI/API)
+
General notes
-------------
This release enables frame-based multithreaded decoding for a number of codecs,
-including VP8, H.263 and H.264. Additionally, there has been a major cleanup of
+including theora, huffyuv, VP8, H.263, mpeg4 and H.264. Additionally, there has
+been a major cleanup of
both internal and external APIs. For this reason, the major versions of all
-libraries have been bumped. On the one hand, this means that 0.7 can be installed
-side-by-side with previous releases, on the other hand, in order to benefit
-from the new features, applications need to be recompiled.
+libraries except libpostproc have been bumped. This means that 0.8 can be installed
+side-by-side with previous releases, on the other hand applications need to be
+recompiled to use 0.8.
-Other important changes are additions of decoders including, but not limited to,
+Other important changes are more than 200 bugfixes, known regressions were fixed
+w.r.t 0.5 and 0.6, additions of decoders including, but not limited to,
AMR-WB, single stream LATM/LOAS, G.722 ADPCM, a native VP8 decoder
and HE-AACv2. Additionally, many new de/muxers such as WebM in Matroska, Apple
HTTP Live Streaming, SAP, IEC 61937 (S/PDIF) have been added.
See the Changelog file for a list of significant changes.
-Please note that our policy on bug reports has not changed. We still only accept
-bug reports against HEAD of the Libav trunk repository. If you are experiencing
-issues with any formally released version of Libav, please try a current version
-of the development code to check if the issue still exists. If it does, make your
-report against the development code following the usual bug reporting guidelines.
+Bugreports against FFmpeg git master or the most recent FFmpeg release are
+accepted. If you are experiencing issues with any formally released version of
+FFmpeg, please try git master to check if the issue still exists. If it does,
+make your report against the development code following the usual bug reporting
+guidelines.
+
+Note, if you have difficulty building for mingw, try --disable-outdev=sdl
API changes
-----------
-Please see the file doc/APIchanges for programmer-centric information. Note that a
-lot of long-time deprecated APIs have been removed. Also, a number of additional
-APIs have been deprecated and are scheduled for removal in the next release.
+Please see git log of the public headers or the file doc/APIchanges for
+programmer-centric information. Note that some long-time deprecated APIs have
+been removed. Also, a number of additional APIs have been deprecated and might
+be removed in the next release.
Other notable changes
---------------------
+- high quality dithering in swscale to fix banding issues
+- ffmpeg is now interactive and various information can be turned on/off while its running
+- resolution changing support in ffmpeg
+- sdl output device
+- optimizations in libavfilter that make it much faster
+- split, buffer, select, lut, negate filters amongth others
+- more than 50 new video filters from mplayers libmpcodecs
- many ARM NEON optimizations
-- libswscale cleanup started, optimizations should become easier in the future
- nonfree libfaad support for AAC decoding removed
- 4:4:4 H.264 decoding
- 9/10bit H.264 decoding
diff --git a/doc/TODO b/doc/TODO
deleted file mode 100644
index 8ff8a6b388..0000000000
--- a/doc/TODO
+++ /dev/null
@@ -1,82 +0,0 @@
-ffmpeg TODO list:
-----------------
-
-Fabrice's TODO list: (unordered)
--------------------
-Short term:
-
-- use AVFMTCTX_DISCARD_PKT in ffplay so that DV has a chance to work
-- add RTSP regression test (both client and server)
-- make ffserver allocate AVFormatContext
-- clean up (incompatible change, for 0.5.0):
- * AVStream -> AVComponent
- * AVFormatContext -> AVInputStream/AVOutputStream
- * suppress rate_emu from AVCodecContext
-- add new float/integer audio filterting and conversion : suppress
- CODEC_ID_PCM_xxc and use CODEC_ID_RAWAUDIO.
-- fix telecine and frame rate conversion
-
-Long term (ask me if you want to help):
-
-- commit new imgconvert API and new PIX_FMT_xxx alpha formats
-- commit new LGPL'ed float and integer-only AC3 decoder
-- add WMA integer-only decoder
-- add new MPEG4-AAC audio decoder (both integer-only and float version)
-
-Michael's TODO list: (unordered) (if anyone wanna help with sth, just ask)
--------------------
-- optimize H264 CABAC
-- more optimizations
-- simper rate control
-
-Philip'a TODO list: (alphabetically ordered) (please help)
-------------------
-- Add a multi-ffm filetype so that feeds can be recorded into multiple files rather
- than one big file.
-- Authenticated users support -- where the authentication is in the URL
-- Change ASF files so that the embedded timestamp in the frames is right rather
- than being an offset from the start of the stream
-- Make ffm files more resilient to changes in the codec structures so that you
- can play old ffm files.
-
-Baptiste's TODO list:
------------------
-- mov edit list support (AVEditList)
-- YUV 10 bit per component support "2vuy"
-- mxf muxer
-- mpeg2 non linear quantizer
-
-unassigned TODO: (unordered)
----------------
-- use AVFrame for audio codecs too
-- rework aviobuf.c buffering strategy and fix url_fskip
-- generate optimal huffman tables for mjpeg encoding
-- fix ffserver regression tests
-- support xvids motion estimation
-- support x264s motion estimation
-- support x264s rate control
-- SNOW: non translational motion compensation
-- SNOW: more optimal quantization
-- SNOW: 4x4 block support
-- SNOW: 1/8 pel motion compensation support
-- SNOW: iterative motion estimation based on subsampled images
-- SNOW: try B frames and MCTF and see how their PSNR/bitrate/complexity behaves
-- SNOW: try to use the wavelet transformed MC-ed reference frame as context for the entropy coder
-- SNOW: think about/analyize how to make snow use multiple cpus/threads
-- SNOW: finish spec
-- FLAC: lossy encoding (viterbi and naive scalar quantization)
-- libavfilter
-- JPEG2000 decoder & encoder
-- MPEG4 GMC encoding support
-- macroblock based pixel format (better cache locality, somewhat complex, one paper claimed it faster for high res)
-- regression tests for codecs which do not have an encoder (I+P-frame bitstream in the 'master' branch)
-- add support for using mplayers video filters to ffmpeg
-- H264 encoder
-- per MB ratecontrol (so VCD and such do work better)
-- write a script which iteratively changes all functions between always_inline and noinline and benchmarks the result to find the best set of inlined functions
-- convert all the non SIMD asm into small asm vs. C testcases and submit them to the gcc devels so they can improve gcc
-- generic audio mixing API
-- extract PES packetizer from PS muxer and use it for new TS muxer
-- implement automatic AVBistreamFilter activation
-- make cabac encoder use bytestream (see http://trac.videolan.org/x264/changeset/?format=diff&new=651)
-- merge imdct and windowing, the current code does considerable amounts of redundant work
diff --git a/doc/avconv.texi b/doc/avconv.texi
new file mode 100644
index 0000000000..056b9cd8db
--- /dev/null
+++ b/doc/avconv.texi
@@ -0,0 +1,979 @@
+\input texinfo @c -*- texinfo -*-
+
+@settitle avconv Documentation
+@titlepage
+@center @titlefont{avconv Documentation}
+@end titlepage
+
+@top
+
+@contents
+
+@chapter Synopsis
+
+The generic syntax is:
+
+@example
+@c man begin SYNOPSIS
+avconv [global options] [[infile options][@option{-i} @var{infile}]]... @{[outfile options] @var{outfile}@}...
+@c man end
+@end example
+
+@chapter Description
+@c man begin DESCRIPTION
+
+avconv is a very fast video and audio converter that can also grab from
+a live audio/video source. It can also convert between arbitrary sample
+rates and resize video on the fly with a high quality polyphase filter.
+
+As a general rule, options are applied to the next specified
+file. Therefore, order is important, and you can have the same
+option on the command line multiple times. Each occurrence is
+then applied to the next input or output file.
+Exceptions from this rule are the global options (e.g. verbosity level),
+which should be specified first.
+
+@itemize
+@item
+To set the video bitrate of the output file to 64kbit/s:
+@example
+avconv -i input.avi -b 64k output.avi
+@end example
+
+@item
+To force the frame rate of the output file to 24 fps:
+@example
+avconv -i input.avi -r 24 output.avi
+@end example
+
+@item
+To force the frame rate of the input file (valid for raw formats only)
+to 1 fps and the frame rate of the output file to 24 fps:
+@example
+avconv -r 1 -i input.m2v -r 24 output.avi
+@end example
+@end itemize
+
+The format option may be needed for raw input files.
+
+@c man end DESCRIPTION
+
+@chapter Stream selection
+@c man begin STREAM SELECTION
+
+By default avconv tries to pick the "best" stream of each type present in input
+files and add them to each output file. For video, this means the highest
+resolution, for audio the highest channel count. For subtitle it's simply the
+first subtitle stream.
+
+You can disable some of those defaults by using @code{-vn/-an/-sn} options. For
+full manual control, use the @code{-map} option, which disables the defaults just
+described.
+
+@c man end STREAM SELECTION
+
+@chapter Options
+@c man begin OPTIONS
+
+@include avtools-common-opts.texi
+
+@section Main options
+
+@table @option
+
+@item -f @var{fmt} (@emph{input/output})
+Force input or output file format. The format is normally autodetected for input
+files and guessed from file extension for output files, so this option is not
+needed in most cases.
+
+@item -i @var{filename} (@emph{input})
+input file name
+
+@item -y (@emph{global})
+Overwrite output files without asking.
+
+@item -c[:@var{stream_specifier}] @var{codec} (@emph{input/output,per-stream})
+@itemx -codec[:@var{stream_specifier}] @var{codec} (@emph{input/output,per-stream})
+Select an encoder (when used before an output file) or a decoder (when used
+before an input file) for one or more streams. @var{codec} is the name of a
+decoder/encoder or a special value @code{copy} (output only) to indicate that
+the stream is not to be reencoded.
+
+For example
+@example
+avconv -i INPUT -map 0 -c:v libx264 -c:a copy OUTPUT
+@end example
+encodes all video streams with libx264 and copies all audio streams.
+
+For each stream, the last matching @code{c} option is applied, so
+@example
+avconv -i INPUT -map 0 -c copy -c:v:1 libx264 -c:a:137 libvorbis OUTPUT
+@end example
+will copy all the streams except the second video, which will be encoded with
+libx264, and the 138th audio, which will be encoded with libvorbis.
+
+@item -t @var{duration} (@emph{output})
+Stop writing the output after its duration reaches @var{duration}.
+@var{duration} may be a number in seconds, or in @code{hh:mm:ss[.xxx]} form.
+
+@item -fs @var{limit_size} (@emph{output})
+Set the file size limit.
+
+@item -ss @var{position} (@emph{input/output})
+When used as an input option (before @code{-i}), seeks in this input file to
+@var{position}. When used as an output option (before an output filename),
+decodes but discards input until the timestamps reach @var{position}. This is
+slower, but more accurate.
+
+@var{position} may be either in seconds or in @code{hh:mm:ss[.xxx]} form.
+
+@item -itsoffset @var{offset} (@emph{input})
+Set the input time offset in seconds.
+@code{[-]hh:mm:ss[.xxx]} syntax is also supported.
+The offset is added to the timestamps of the input files.
+Specifying a positive offset means that the corresponding
+streams are delayed by @var{offset} seconds.
+
+@item -metadata[:metadata_specifier] @var{key}=@var{value} (@emph{output,per-metadata})
+Set a metadata key/value pair.
+
+An optional @var{metadata_specifier} may be given to set metadata
+on streams or chapters. See @code{-map_metadata} documentation for
+details.
+
+This option overrides metadata set with @code{-map_metadata}. It is
+also possible to delete metadata by using an empty value.
+
+For example, for setting the title in the output file:
+@example
+avconv -i in.avi -metadata title="my title" out.flv
+@end example
+
+To set the language of the second stream:
+@example
+avconv -i INPUT -metadata:s:1 language=eng OUTPUT
+@end example
+
+@item -target @var{type} (@emph{output})
+Specify target file type (@code{vcd}, @code{svcd}, @code{dvd}, @code{dv},
+@code{dv50}). @var{type} may be prefixed with @code{pal-}, @code{ntsc-} or
+@code{film-} to use the corresponding standard. All the format options
+(bitrate, codecs, buffer sizes) are then set automatically. You can just type:
+
+@example
+avconv -i myfile.avi -target vcd /tmp/vcd.mpg
+@end example
+
+Nevertheless you can specify additional options as long as you know
+they do not conflict with the standard, as in:
+
+@example
+avconv -i myfile.avi -target vcd -bf 2 /tmp/vcd.mpg
+@end example
+
+@item -dframes @var{number} (@emph{output})
+Set the number of data frames to record. This is an alias for @code{-frames:d}.
+
+@item -frames[:@var{stream_specifier}] @var{framecount} (@emph{output,per-stream})
+Stop writing to the stream after @var{framecount} frames.
+
+@item -q[:@var{stream_specifier}] @var{q} (@emph{output,per-stream})
+@itemx -qscale[:@var{stream_specifier}] @var{q} (@emph{output,per-stream})
+Use fixed quality scale (VBR). The meaning of @var{q} is
+codec-dependent.
+
+@item -filter[:@var{stream_specifier}] @var{filter_graph} (@emph{output,per-stream})
+@var{filter_graph} is a description of the filter graph to apply to
+the stream. Use @code{-filters} to show all the available filters
+(including also sources and sinks).
+@item -pre[:@var{stream_specifier}] @var{preset_name} (@emph{output,per-stream})
+Specify the preset for matching stream(s).
+
+@item -stats (@emph{global})
+Print encoding progress/statistics. On by default.
+
+@end table
+
+@section Video Options
+
+@table @option
+@item -vframes @var{number} (@emph{output})
+Set the number of video frames to record. This is an alias for @code{-frames:v}.
+@item -r[:@var{stream_specifier}] @var{fps} (@emph{input/output,per-stream})
+Set frame rate (Hz value, fraction or abbreviation), (default = 25).
+@item -s[:@var{stream_specifier}] @var{size} (@emph{input/output,per-stream})
+Set frame size. The format is @samp{wxh} (ffserver default = 160x128, avconv default = same as source).
+The following abbreviations are recognized:
+@table @samp
+@item sqcif
+128x96
+@item qcif
+176x144
+@item cif
+352x288
+@item 4cif
+704x576
+@item 16cif
+1408x1152
+@item qqvga
+160x120
+@item qvga
+320x240
+@item vga
+640x480
+@item svga
+800x600
+@item xga
+1024x768
+@item uxga
+1600x1200
+@item qxga
+2048x1536
+@item sxga
+1280x1024
+@item qsxga
+2560x2048
+@item hsxga
+5120x4096
+@item wvga
+852x480
+@item wxga
+1366x768
+@item wsxga
+1600x1024
+@item wuxga
+1920x1200
+@item woxga
+2560x1600
+@item wqsxga
+3200x2048
+@item wquxga
+3840x2400
+@item whsxga
+6400x4096
+@item whuxga
+7680x4800
+@item cga
+320x200
+@item ega
+640x350
+@item hd480
+852x480
+@item hd720
+1280x720
+@item hd1080
+1920x1080
+@end table
+
+@item -aspect[:@var{stream_specifier}] @var{aspect} (@emph{output,per-stream})
+Set the video display aspect ratio specified by @var{aspect}.
+
+@var{aspect} can be a floating point number string, or a string of the
+form @var{num}:@var{den}, where @var{num} and @var{den} are the
+numerator and denominator of the aspect ratio. For example "4:3",
+"16:9", "1.3333", and "1.7777" are valid argument values.
+
+@item -vn (@emph{output})
+Disable video recording.
+@item -bt @var{tolerance}
+Set video bitrate tolerance (in bits, default 4000k).
+Has a minimum value of: (target_bitrate/target_framerate).
+In 1-pass mode, bitrate tolerance specifies how far ratecontrol is
+willing to deviate from the target average bitrate value. This is
+not related to min/max bitrate. Lowering tolerance too much has
+an adverse effect on quality.
+@item -maxrate @var{bitrate}
+Set max video bitrate (in bit/s).
+Requires -bufsize to be set.
+@item -minrate @var{bitrate}
+Set min video bitrate (in bit/s).
+Most useful in setting up a CBR encode:
+@example
+avconv -i myfile.avi -b 4000k -minrate 4000k -maxrate 4000k -bufsize 1835k out.m2v
+@end example
+It is of little use elsewise.
+@item -bufsize @var{size}
+Set video buffer verifier buffer size (in bits).
+@item -vcodec @var{codec} (@emph{output})
+Set the video codec. This is an alias for @code{-codec:v}.
+@item -same_quant
+Use same quantizer as source (implies VBR).
+
+Note that this is NOT SAME QUALITY. Do not use this option unless you know you
+need it.
+
+@item -pass @var{n}
+Select the pass number (1 or 2). It is used to do two-pass
+video encoding. The statistics of the video are recorded in the first
+pass into a log file (see also the option -passlogfile),
+and in the second pass that log file is used to generate the video
+at the exact requested bitrate.
+On pass 1, you may just deactivate audio and set output to null,
+examples for Windows and Unix:
+@example
+avconv -i foo.mov -c:v libxvid -pass 1 -an -f rawvideo -y NUL
+avconv -i foo.mov -c:v libxvid -pass 1 -an -f rawvideo -y /dev/null
+@end example
+
+@item -passlogfile @var{prefix} (@emph{global})
+Set two-pass log file name prefix to @var{prefix}, the default file name
+prefix is ``av2pass''. The complete file name will be
+@file{PREFIX-N.log}, where N is a number specific to the output
+stream.
+
+@item -vf @var{filter_graph} (@emph{output})
+@var{filter_graph} is a description of the filter graph to apply to
+the input video.
+Use the option "-filters" to show all the available filters (including
+also sources and sinks). This is an alias for @code{-filter:v}.
+
+@end table
+
+@section Advanced Video Options
+
+@table @option
+@item -pix_fmt[:@var{stream_specifier}] @var{format} (@emph{input/output,per-stream})
+Set pixel format. Use @code{-pix_fmts} to show all the supported
+pixel formats.
+@item -sws_flags @var{flags} (@emph{input/output})
+Set SwScaler flags.
+@item -g @var{gop_size}
+Set the group of pictures size.
+@item -vdt @var{n}
+Discard threshold.
+@item -qmin @var{q}
+minimum video quantizer scale (VBR)
+@item -qmax @var{q}
+maximum video quantizer scale (VBR)
+@item -qdiff @var{q}
+maximum difference between the quantizer scales (VBR)
+@item -qblur @var{blur}
+video quantizer scale blur (VBR) (range 0.0 - 1.0)
+@item -qcomp @var{compression}
+video quantizer scale compression (VBR) (default 0.5).
+Constant of ratecontrol equation. Recommended range for default rc_eq: 0.0-1.0
+
+@item -lmin @var{lambda}
+minimum video lagrange factor (VBR)
+@item -lmax @var{lambda}
+max video lagrange factor (VBR)
+@item -mblmin @var{lambda}
+minimum macroblock quantizer scale (VBR)
+@item -mblmax @var{lambda}
+maximum macroblock quantizer scale (VBR)
+
+These four options (lmin, lmax, mblmin, mblmax) use 'lambda' units,
+but you may use the QP2LAMBDA constant to easily convert from 'q' units:
+@example
+avconv -i src.ext -lmax 21*QP2LAMBDA dst.ext
+@end example
+
+@item -rc_init_cplx @var{complexity}
+initial complexity for single pass encoding
+@item -b_qfactor @var{factor}
+qp factor between P- and B-frames
+@item -i_qfactor @var{factor}
+qp factor between P- and I-frames
+@item -b_qoffset @var{offset}
+qp offset between P- and B-frames
+@item -i_qoffset @var{offset}
+qp offset between P- and I-frames
+@item -rc_eq @var{equation}
+Set rate control equation (see section "Expression Evaluation")
+(default = @code{tex^qComp}).
+
+When computing the rate control equation expression, besides the
+standard functions defined in the section "Expression Evaluation", the
+following functions are available:
+@table @var
+@item bits2qp(bits)
+@item qp2bits(qp)
+@end table
+
+and the following constants are available:
+@table @var
+@item iTex
+@item pTex
+@item tex
+@item mv
+@item fCode
+@item iCount
+@item mcVar
+@item var
+@item isI
+@item isP
+@item isB
+@item avgQP
+@item qComp
+@item avgIITex
+@item avgPITex
+@item avgPPTex
+@item avgBPTex
+@item avgTex
+@end table
+
+@item -rc_override[:@var{stream_specifier}] @var{override} (@emph{output,per-stream})
+rate control override for specific intervals
+@item -me_method @var{method}
+Set motion estimation method to @var{method}.
+Available methods are (from lowest to best quality):
+@table @samp
+@item zero
+Try just the (0, 0) vector.
+@item phods
+@item log
+@item x1
+@item hex
+@item umh
+@item epzs
+(default method)
+@item full
+exhaustive search (slow and marginally better than epzs)
+@end table
+
+@item -er @var{n}
+Set error resilience to @var{n}.
+@table @samp
+@item 1
+FF_ER_CAREFUL (default)
+@item 2
+FF_ER_COMPLIANT
+@item 3
+FF_ER_AGGRESSIVE
+@item 4
+FF_ER_VERY_AGGRESSIVE
+@end table
+
+@item -ec @var{bit_mask}
+Set error concealment to @var{bit_mask}. @var{bit_mask} is a bit mask of
+the following values:
+@table @samp
+@item 1
+FF_EC_GUESS_MVS (default = enabled)
+@item 2
+FF_EC_DEBLOCK (default = enabled)
+@end table
+
+@item -bf @var{frames}
+Use 'frames' B-frames (supported for MPEG-1, MPEG-2 and MPEG-4).
+@item -mbd @var{mode}
+macroblock decision
+@table @samp
+@item 0
+FF_MB_DECISION_SIMPLE: Use mb_cmp (cannot change it yet in avconv).
+@item 1
+FF_MB_DECISION_BITS: Choose the one which needs the fewest bits.
+@item 2
+FF_MB_DECISION_RD: rate distortion
+@end table
+
+@item -bug @var{param}
+Work around encoder bugs that are not auto-detected.
+@item -strict @var{strictness}
+How strictly to follow the standards.
+
+@item -deinterlace
+Deinterlace pictures.
+@item -vstats
+Dump video coding statistics to @file{vstats_HHMMSS.log}.
+@item -vstats_file @var{file}
+Dump video coding statistics to @var{file}.
+@item -top[:@var{stream_specifier}] @var{n} (@emph{output,per-stream})
+top=1/bottom=0/auto=-1 field first
+@item -dc @var{precision}
+Intra_dc_precision.
+@item -vtag @var{fourcc/tag} (@emph{output})
+Force video tag/fourcc. This is an alias for @code{-tag:v}.
+@item -qphist (@emph{global})
+Show QP histogram.
+@item -force_key_frames[:@var{stream_specifier}] @var{time}[,@var{time}...] (@emph{output,per-stream})
+Force key frames at the specified timestamps, more precisely at the first
+frames after each specified time.
+This option can be useful to ensure that a seek point is present at a
+chapter mark or any other designated place in the output file.
+The timestamps must be specified in ascending order.
+@end table
+
+@section Audio Options
+
+@table @option
+@item -aframes @var{number} (@emph{output})
+Set the number of audio frames to record. This is an alias for @code{-frames:a}.
+@item -ar[:@var{stream_specifier}] @var{freq} (@emph{input/output,per-stream})
+Set the audio sampling frequency. For output streams it is set by
+default to the frequency of the corresponding input stream. For input
+streams this option only makes sense for audio grabbing devices and raw
+demuxers and is mapped to the corresponding demuxer options.
+@item -aq @var{q} (@emph{output})
+Set the audio quality (codec-specific, VBR). This is an alias for -q:a.
+@item -ac[:@var{stream_specifier}] @var{channels} (@emph{input/output,per-stream})
+Set the number of audio channels. For output streams it is set by
+default to the number of input audio channels. For input streams
+this option only makes sense for audio grabbing devices and raw demuxers
+and is mapped to the corresponding demuxer options.
+@item -an (@emph{output})
+Disable audio recording.
+@item -acodec @var{codec} (@emph{input/output})
+Set the audio codec. This is an alias for @code{-codec:a}.
+@item -sample_fmt[:@var{stream_specifier}] @var{sample_fmt} (@emph{output,per-stream})
+Set the audio sample format. Use @code{-help sample_fmts} to get a list
+of supported sample formats.
+@end table
+
+@section Advanced Audio options:
+
+@table @option
+@item -atag @var{fourcc/tag} (@emph{output})
+Force audio tag/fourcc. This is an alias for @code{-tag:a}.
+@item -audio_service_type @var{type}
+Set the type of service that the audio stream contains.
+@table @option
+@item ma
+Main Audio Service (default)
+@item ef
+Effects
+@item vi
+Visually Impaired
+@item hi
+Hearing Impaired
+@item di
+Dialogue
+@item co
+Commentary
+@item em
+Emergency
+@item vo
+Voice Over
+@item ka
+Karaoke
+@end table
+@end table
+
+@section Subtitle options:
+
+@table @option
+@item -scodec @var{codec} (@emph{input/output})
+Set the subtitle codec. This is an alias for @code{-codec:s}.
+@item -sn (@emph{output})
+Disable subtitle recording.
+@end table
+
+@section Audio/Video grab options
+
+@table @option
+@item -isync (@emph{global})
+Synchronize read on input.
+@end table
+
+@section Advanced options
+
+@table @option
+@item -map [-]@var{input_file_id}[:@var{stream_specifier}][,@var{sync_file_id}[:@var{stream_specifier}]] (@emph{output})
+
+Designate one or more input streams as a source for the output file. Each input
+stream is identified by the input file index @var{input_file_id} and
+the input stream index @var{input_stream_id} within the input
+file. Both indices start at 0. If specified,
+@var{sync_file_id}:@var{stream_specifier} sets which input stream
+is used as a presentation sync reference.
+
+The first @code{-map} option on the command line specifies the
+source for output stream 0, the second @code{-map} option specifies
+the source for output stream 1, etc.
+
+A @code{-} character before the stream identifier creates a "negative" mapping.
+It disables matching streams from already created mappings.
+
+For example, to map ALL streams from the first input file to output
+@example
+avconv -i INPUT -map 0 output
+@end example
+
+For example, if you have two audio streams in the first input file,
+these streams are identified by "0:0" and "0:1". You can use
+@code{-map} to select which streams to place in an output file. For
+example:
+@example
+avconv -i INPUT -map 0:1 out.wav
+@end example
+will map the input stream in @file{INPUT} identified by "0:1" to
+the (single) output stream in @file{out.wav}.
+
+For example, to select the stream with index 2 from input file
+@file{a.mov} (specified by the identifier "0:2"), and stream with
+index 6 from input @file{b.mov} (specified by the identifier "1:6"),
+and copy them to the output file @file{out.mov}:
+@example
+avconv -i a.mov -i b.mov -c copy -map 0:2 -map 1:6 out.mov
+@end example
+
+To select all video and the third audio stream from an input file:
+@example
+avconv -i INPUT -map 0:v -map 0:a:2 OUTPUT
+@end example
+
+To map all the streams except the second audio, use negative mappings
+@example
+avconv -i INPUT -map 0 -map -0:a:1 OUTPUT
+@end example
+
+Note that using this option disables the default mappings for this output file.
+
+@item -map_metadata[:@var{metadata_type}][:@var{index}] @var{infile}[:@var{metadata_type}][:@var{index}] (@emph{output,per-metadata})
+Set metadata information of the next output file from @var{infile}. Note that
+those are file indices (zero-based), not filenames.
+Optional @var{metadata_type} parameters specify, which metadata to copy - (g)lobal
+(i.e. metadata that applies to the whole file), per-(s)tream, per-(c)hapter or
+per-(p)rogram. All metadata specifiers other than global must be followed by the
+stream/chapter/program index. If metadata specifier is omitted, it defaults to
+global.
+
+By default, global metadata is copied from the first input file,
+per-stream and per-chapter metadata is copied along with streams/chapters. These
+default mappings are disabled by creating any mapping of the relevant type. A negative
+file index can be used to create a dummy mapping that just disables automatic copying.
+
+For example to copy metadata from the first stream of the input file to global metadata
+of the output file:
+@example
+avconv -i in.ogg -map_metadata 0:s:0 out.mp3
+@end example
+@item -map_chapters @var{input_file_index} (@emph{output})
+Copy chapters from input file with index @var{input_file_index} to the next
+output file. If no chapter mapping is specified, then chapters are copied from
+the first input file with at least one chapter. Use a negative file index to
+disable any chapter copying.
+@item -debug
+Print specific debug info.
+@item -benchmark (@emph{global})
+Show benchmarking information at the end of an encode.
+Shows CPU time used and maximum memory consumption.
+Maximum memory consumption is not supported on all systems,
+it will usually display as 0 if not supported.
+@item -timelimit @var{duration} (@emph{global})
+Exit after avconv has been running for @var{duration} seconds.
+@item -dump (@emph{global})
+Dump each input packet to stderr.
+@item -hex (@emph{global})
+When dumping packets, also dump the payload.
+@item -ps @var{size}
+Set RTP payload size in bytes.
+@item -re (@emph{input})
+Read input at native frame rate. Mainly used to simulate a grab device.
+@item -threads @var{count}
+Thread count.
+@item -vsync @var{parameter}
+Video sync method.
+
+@table @option
+@item 0
+Each frame is passed with its timestamp from the demuxer to the muxer.
+@item 1
+Frames will be duplicated and dropped to achieve exactly the requested
+constant framerate.
+@item 2
+Frames are passed through with their timestamp or dropped so as to
+prevent 2 frames from having the same timestamp.
+@item -1
+Chooses between 1 and 2 depending on muxer capabilities. This is the
+default method.
+@end table
+
+With -map you can select from which stream the timestamps should be
+taken. You can leave either video or audio unchanged and sync the
+remaining stream(s) to the unchanged one.
+
+@item -async @var{samples_per_second}
+Audio sync method. "Stretches/squeezes" the audio stream to match the timestamps,
+the parameter is the maximum samples per second by which the audio is changed.
+-async 1 is a special case where only the start of the audio stream is corrected
+without any later correction.
+@item -copyts
+Copy timestamps from input to output.
+@item -copytb
+Copy input stream time base from input to output when stream copying.
+@item -shortest
+Finish encoding when the shortest input stream ends.
+@item -dts_delta_threshold
+Timestamp discontinuity delta threshold.
+@item -muxdelay @var{seconds} (@emph{input})
+Set the maximum demux-decode delay.
+@item -muxpreload @var{seconds} (@emph{input})
+Set the initial demux-decode delay.
+@item -streamid @var{output-stream-index}:@var{new-value} (@emph{output})
+Assign a new stream-id value to an output stream. This option should be
+specified prior to the output filename to which it applies.
+For the situation where multiple output files exist, a streamid
+may be reassigned to a different value.
+
+For example, to set the stream 0 PID to 33 and the stream 1 PID to 36 for
+an output mpegts file:
+@example
+avconv -i infile -streamid 0:33 -streamid 1:36 out.ts
+@end example
+
+@item -bsf[:@var{stream_specifier}] @var{bitstream_filters} (@emph{output,per-stream})
+Set bitstream filters for matching streams. @var{bistream_filters} is
+a comma-separated list of bitstream filters. Use the @code{-bsfs} option
+to get the list of bitstream filters.
+@example
+avconv -i h264.mp4 -c:v copy -vbsf h264_mp4toannexb -an out.h264
+@end example
+@example
+avconv -i file.mov -an -vn -sbsf mov2textsub -c:s copy -f rawvideo sub.txt
+@end example
+
+@item -tag[:@var{stream_specifier}] @var{codec_tag} (@emph{output,per-stream})
+Force a tag/fourcc for matching streams.
+@end table
+@c man end OPTIONS
+
+@chapter Tips
+@c man begin TIPS
+
+@itemize
+@item
+For streaming at very low bitrate application, use a low frame rate
+and a small GOP size. This is especially true for RealVideo where
+the Linux player does not seem to be very fast, so it can miss
+frames. An example is:
+
+@example
+avconv -g 3 -r 3 -t 10 -b 50k -s qcif -f rv10 /tmp/b.rm
+@end example
+
+@item
+The parameter 'q' which is displayed while encoding is the current
+quantizer. The value 1 indicates that a very good quality could
+be achieved. The value 31 indicates the worst quality. If q=31 appears
+too often, it means that the encoder cannot compress enough to meet
+your bitrate. You must either increase the bitrate, decrease the
+frame rate or decrease the frame size.
+
+@item
+If your computer is not fast enough, you can speed up the
+compression at the expense of the compression ratio. You can use
+'-me zero' to speed up motion estimation, and '-intra' to disable
+motion estimation completely (you have only I-frames, which means it
+is about as good as JPEG compression).
+
+@item
+To have very low audio bitrates, reduce the sampling frequency
+(down to 22050 Hz for MPEG audio, 22050 or 11025 for AC-3).
+
+@item
+To have a constant quality (but a variable bitrate), use the option
+'-qscale n' when 'n' is between 1 (excellent quality) and 31 (worst
+quality).
+
+@end itemize
+@c man end TIPS
+
+@chapter Examples
+@c man begin EXAMPLES
+
+@section Preset files
+
+A preset file contains a sequence of @var{option=value} pairs, one for
+each line, specifying a sequence of options which can be specified also on
+the command line. Lines starting with the hash ('#') character are ignored and
+are used to provide comments. Empty lines are also ignored. Check the
+@file{presets} directory in the Libav source tree for examples.
+
+Preset files are specified with the @code{pre} option, this option takes a
+preset name as input. Avconv searches for a file named @var{preset_name}.avpreset in
+the directories @file{$AVCONV_DATADIR} (if set), and @file{$HOME/.avconv}, and in
+the data directory defined at configuration time (usually @file{$PREFIX/share/avconv})
+in that order. For example, if the argument is @code{libx264-max}, it will
+search for the file @file{libx264-max.avpreset}.
+
+@section Video and Audio grabbing
+
+If you specify the input format and device then avconv can grab video
+and audio directly.
+
+@example
+avconv -f oss -i /dev/dsp -f video4linux2 -i /dev/video0 /tmp/out.mpg
+@end example
+
+Note that you must activate the right video source and channel before
+launching avconv with any TV viewer such as
+@uref{http://linux.bytesex.org/xawtv/, xawtv} by Gerd Knorr. You also
+have to set the audio recording levels correctly with a
+standard mixer.
+
+@section X11 grabbing
+
+Grab the X11 display with avconv via
+
+@example
+avconv -f x11grab -s cif -r 25 -i :0.0 /tmp/out.mpg
+@end example
+
+0.0 is display.screen number of your X11 server, same as
+the DISPLAY environment variable.
+
+@example
+avconv -f x11grab -s cif -r 25 -i :0.0+10,20 /tmp/out.mpg
+@end example
+
+0.0 is display.screen number of your X11 server, same as the DISPLAY environment
+variable. 10 is the x-offset and 20 the y-offset for the grabbing.
+
+@section Video and Audio file format conversion
+
+Any supported file format and protocol can serve as input to avconv:
+
+Examples:
+@itemize
+@item
+You can use YUV files as input:
+
+@example
+avconv -i /tmp/test%d.Y /tmp/out.mpg
+@end example
+
+It will use the files:
+@example
+/tmp/test0.Y, /tmp/test0.U, /tmp/test0.V,
+/tmp/test1.Y, /tmp/test1.U, /tmp/test1.V, etc...
+@end example
+
+The Y files use twice the resolution of the U and V files. They are
+raw files, without header. They can be generated by all decent video
+decoders. You must specify the size of the image with the @option{-s} option
+if avconv cannot guess it.
+
+@item
+You can input from a raw YUV420P file:
+
+@example
+avconv -i /tmp/test.yuv /tmp/out.avi
+@end example
+
+test.yuv is a file containing raw YUV planar data. Each frame is composed
+of the Y plane followed by the U and V planes at half vertical and
+horizontal resolution.
+
+@item
+You can output to a raw YUV420P file:
+
+@example
+avconv -i mydivx.avi hugefile.yuv
+@end example
+
+@item
+You can set several input files and output files:
+
+@example
+avconv -i /tmp/a.wav -s 640x480 -i /tmp/a.yuv /tmp/a.mpg
+@end example
+
+Converts the audio file a.wav and the raw YUV video file a.yuv
+to MPEG file a.mpg.
+
+@item
+You can also do audio and video conversions at the same time:
+
+@example
+avconv -i /tmp/a.wav -ar 22050 /tmp/a.mp2
+@end example
+
+Converts a.wav to MPEG audio at 22050 Hz sample rate.
+
+@item
+You can encode to several formats at the same time and define a
+mapping from input stream to output streams:
+
+@example
+avconv -i /tmp/a.wav -map 0:a -b 64k /tmp/a.mp2 -map 0:a -b 128k /tmp/b.mp2
+@end example
+
+Converts a.wav to a.mp2 at 64 kbits and to b.mp2 at 128 kbits. '-map
+file:index' specifies which input stream is used for each output
+stream, in the order of the definition of output streams.
+
+@item
+You can transcode decrypted VOBs:
+
+@example
+avconv -i snatch_1.vob -f avi -c:v mpeg4 -b:v 800k -g 300 -bf 2 -c:a libmp3lame -b:a 128k snatch.avi
+@end example
+
+This is a typical DVD ripping example; the input is a VOB file, the
+output an AVI file with MPEG-4 video and MP3 audio. Note that in this
+command we use B-frames so the MPEG-4 stream is DivX5 compatible, and
+GOP size is 300 which means one intra frame every 10 seconds for 29.97fps
+input video. Furthermore, the audio stream is MP3-encoded so you need
+to enable LAME support by passing @code{--enable-libmp3lame} to configure.
+The mapping is particularly useful for DVD transcoding
+to get the desired audio language.
+
+NOTE: To see the supported input formats, use @code{avconv -formats}.
+
+@item
+You can extract images from a video, or create a video from many images:
+
+For extracting images from a video:
+@example
+avconv -i foo.avi -r 1 -s WxH -f image2 foo-%03d.jpeg
+@end example
+
+This will extract one video frame per second from the video and will
+output them in files named @file{foo-001.jpeg}, @file{foo-002.jpeg},
+etc. Images will be rescaled to fit the new WxH values.
+
+If you want to extract just a limited number of frames, you can use the
+above command in combination with the -vframes or -t option, or in
+combination with -ss to start extracting from a certain point in time.
+
+For creating a video from many images:
+@example
+avconv -f image2 -i foo-%03d.jpeg -r 12 -s WxH foo.avi
+@end example
+
+The syntax @code{foo-%03d.jpeg} specifies to use a decimal number
+composed of three digits padded with zeroes to express the sequence
+number. It is the same syntax supported by the C printf function, but
+only formats accepting a normal integer are suitable.
+
+@item
+You can put many streams of the same type in the output:
+
+@example
+avconv -i test1.avi -i test2.avi -map 0.3 -map 0.2 -map 0.1 -map 0.0 -c copy test12.nut
+@end example
+
+The resulting output file @file{test12.avi} will contain first four streams from
+the input file in reverse order.
+
+@end itemize
+@c man end EXAMPLES
+
+@include eval.texi
+@include encoders.texi
+@include demuxers.texi
+@include muxers.texi
+@include indevs.texi
+@include outdevs.texi
+@include protocols.texi
+@include bitstream_filters.texi
+@include filters.texi
+@include metadata.texi
+
+@ignore
+
+@setfilename avconv
+@settitle avconv video converter
+
+@c man begin SEEALSO
+ffplay(1), ffprobe(1), ffserver(1) and the FFmpeg HTML documentation
+@c man end
+
+@c man begin AUTHORS
+The Libav developers
+@c man end
+
+@end ignore
+
+@bye
diff --git a/doc/avtools-common-opts.texi b/doc/avtools-common-opts.texi
new file mode 100644
index 0000000000..33b3b481b6
--- /dev/null
+++ b/doc/avtools-common-opts.texi
@@ -0,0 +1,157 @@
+All the numerical options, if not specified otherwise, accept in input
+a string representing a number, which may contain one of the
+International System number postfixes, for example 'K', 'M', 'G'.
+If 'i' is appended after the postfix, powers of 2 are used instead of
+powers of 10. The 'B' postfix multiplies the value for 8, and can be
+appended after another postfix or used alone. This allows using for
+example 'KB', 'MiB', 'G' and 'B' as postfix.
+
+Options which do not take arguments are boolean options, and set the
+corresponding value to true. They can be set to false by prefixing
+with "no" the option name, for example using "-nofoo" in the
+commandline will set to false the boolean option with name "foo".
+
+@section Stream specifiers
+Some options are applied per-stream, e.g. bitrate or codec. Stream specifiers
+are used to precisely specify which stream(s) does a given option belong to.
+
+A stream specifier is a string generally appended to the option name and
+separated from it by a colon. E.g. @code{-codec:a:1 ac3} option contains
+@code{a:1} stream specifer, which matches the second audio stream. Therefore it
+would select the ac3 codec for the second audio stream.
+
+A stream specifier can match several stream, the option is then applied to all
+of them. E.g. the stream specifier in @code{-b:a 128k} matches all audio
+streams.
+
+An empty stream specifier matches all streams, for example @code{-codec copy}
+or @code{-codec: copy} would copy all the streams without reencoding.
+
+Possible forms of stream specifiers are:
+@table @option
+@item @var{stream_index}
+Matches the stream with this index. E.g. @code{-threads:1 4} would set the
+thread count for the second stream to 4.
+@item @var{stream_type}[:@var{stream_index}]
+@var{stream_type} is one of: 'v' for video, 'a' for audio, 's' for subtitle,
+'d' for data and 't' for attachments. If @var{stream_index} is given, then
+matches stream number @var{stream_index} of this type. Otherwise matches all
+streams of this type.
+@item p:@var{program_id}[:@var{stream_index}]
+If @var{stream_index} is given, then matches stream number @var{stream_index} in
+program with id @var{program_id}. Otherwise matches all streams in this program.
+@end table
+@section Generic options
+
+These options are shared amongst the av* tools.
+
+@table @option
+
+@item -L
+Show license.
+
+@item -h, -?, -help, --help
+Show help.
+
+@item -version
+Show version.
+
+@item -formats
+Show available formats.
+
+The fields preceding the format names have the following meanings:
+@table @samp
+@item D
+Decoding available
+@item E
+Encoding available
+@end table
+
+@item -codecs
+Show available codecs.
+
+The fields preceding the codec names have the following meanings:
+@table @samp
+@item D
+Decoding available
+@item E
+Encoding available
+@item V/A/S
+Video/audio/subtitle codec
+@item S
+Codec supports slices
+@item D
+Codec supports direct rendering
+@item T
+Codec can handle input truncated at random locations instead of only at frame boundaries
+@end table
+
+@item -bsfs
+Show available bitstream filters.
+
+@item -protocols
+Show available protocols.
+
+@item -filters
+Show available libavfilter filters.
+
+@item -pix_fmts
+Show available pixel formats.
+
+@item -sample_fmts
+Show available sample formats.
+
+@item -loglevel @var{loglevel} | -v @var{loglevel}
+Set the logging level used by the library.
+@var{loglevel} is a number or a string containing one of the following values:
+@table @samp
+@item quiet
+@item panic
+@item fatal
+@item error
+@item warning
+@item info
+@item verbose
+@item debug
+@end table
+
+By default the program logs to stderr, if coloring is supported by the
+terminal, colors are used to mark errors and warnings. Log coloring
+can be disabled setting the environment variable
+@env{FFMPEG_FORCE_NOCOLOR} or @env{NO_COLOR}, or can be forced setting
+the environment variable @env{FFMPEG_FORCE_COLOR}.
+The use of the environment variable @env{NO_COLOR} is deprecated and
+will be dropped in a following FFmpeg version.
+
+@end table
+
+@section AVOptions
+
+These options are provided directly by the libavformat, libavdevice and
+libavcodec libraries. To see the list of available AVOptions, use the
+@option{-help} option. They are separated into two categories:
+@table @option
+@item generic
+These options can be set for any container, codec or device. Generic options are
+listed under AVFormatContext options for containers/devices and under
+AVCodecContext options for codecs.
+@item private
+These options are specific to the given container, device or codec. Private
+options are listed under their corresponding containers/devices/codecs.
+@end table
+
+For example to write an ID3v2.3 header instead of a default ID3v2.4 to
+an MP3 file, use the @option{id3v2_version} private option of the MP3
+muxer:
+@example
+ffmpeg -i input.flac -id3v2_version 3 out.mp3
+@end example
+
+All codec AVOptions are obviously per-stream, so the chapter on stream
+specifiers applies to them
+
+Note -nooption syntax cannot be used for boolean AVOptions, use -option
+0/-option 1.
+
+Note2 old undocumented way of specifying per-stream AVOptions by prepending
+v/a/s to the options name is now obsolete and will be removed soon.
diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
index c33fca6c51..1ad67cd5ef 100644
--- a/doc/bitstream_filters.texi
+++ b/doc/bitstream_filters.texi
@@ -1,7 +1,7 @@
@chapter Bitstream Filters
@c man begin BITSTREAM FILTERS
-When you configure your Libav build, all the supported bitstream
+When you configure your FFmpeg build, all the supported bitstream
filters are enabled by default. You can list all available ones using
the configure option @code{--list-bsfs}.
diff --git a/doc/build_system.txt b/doc/build_system.txt
index 1011f57f66..36c141e9e4 100644
--- a/doc/build_system.txt
+++ b/doc/build_system.txt
@@ -1,4 +1,4 @@
-Libav currently uses a custom build system, this text attempts to document
+FFmpeg currently uses a custom build system, this text attempts to document
some of its obscure features and options.
Makefile variables:
@@ -9,13 +9,19 @@ V
DESTDIR
Destination directory for the install targets, useful to prepare packages
- or install Libav in cross-environments.
+ or install FFmpeg in cross-environments.
Makefile targets:
all
Default target, builds all the libraries and the executables.
+fate
+ Run the fate test suite, note you must have installed it
+
+fate-list
+ Will list all fate/regression test targets
+
install
Install headers, libraries and programs.
@@ -28,3 +34,17 @@ libavcodec/api-example
libswscale/swscale-test
Build the swscale self-test (useful also as example).
+
+Useful standard make commands:
+make -t <target>
+ Touch all files that otherwise would be build, this is useful to reduce
+ unneeded rebuilding when changing headers, but note you must force rebuilds
+ of files that actually need it by hand then.
+
+make -j<num>
+ rebuild with multiple jobs at the same time. Faster on multi processor systems
+
+make -k
+ continue build in case of errors, this is useful for the regression tests
+ sometimes but note it will still not run all reg tests.
+
diff --git a/doc/decoders.texi b/doc/decoders.texi
new file mode 100644
index 0000000000..18ac2fa8db
--- /dev/null
+++ b/doc/decoders.texi
@@ -0,0 +1,50 @@
+@chapter Decoders
+@c man begin DECODERS
+
+Decoders are configured elements in FFmpeg which allow the decoding of
+multimedia streams.
+
+When you configure your FFmpeg build, all the supported native decoders
+are enabled by default. Decoders requiring an external library must be enabled
+manually via the corresponding @code{--enable-lib} option. You can list all
+available decoders using the configure option @code{--list-decoders}.
+
+You can disable all the decoders with the configure option
+@code{--disable-decoders} and selectively enable / disable single decoders
+with the options @code{--enable-decoder=@var{DECODER}} /
+@code{--disable-decoder=@var{DECODER}}.
+
+The option @code{-codecs} of the ff* tools will display the list of
+enabled decoders.
+
+@c man end DECODERS
+
+@chapter Video Decoders
+@c man begin VIDEO DECODERS
+
+A description of some of the currently available video decoders
+follows.
+
+@section rawvideo
+
+Rawvideo decoder.
+
+This decoder decodes rawvideo streams.
+
+@subsection Options
+
+@table @option
+@item top @var{top_field_first}
+Specify the assumed field type of the input video.
+@table @option
+@item -1
+the video is assumed to be progressive (default)
+@item 0
+bottom-field-first is assumed
+@item 1
+top-field-first is assumed
+@end table
+
+@end table
+
+@c man end VIDEO DECODERS
diff --git a/doc/demuxers.texi b/doc/demuxers.texi
index 98f9fdeff8..ffaadfe4f9 100644
--- a/doc/demuxers.texi
+++ b/doc/demuxers.texi
@@ -1,10 +1,10 @@
@chapter Demuxers
@c man begin DEMUXERS
-Demuxers are configured elements in Libav which allow to read the
+Demuxers are configured elements in FFmpeg which allow to read the
multimedia streams from a particular type of file.
-When you configure your Libav build, all the supported demuxers
+When you configure your FFmpeg build, all the supported demuxers
are enabled by default. You can list all available ones using the
configure option "--list-demuxers".
diff --git a/doc/developer.texi b/doc/developer.texi
index 37b9f3e889..29291d0c71 100644
--- a/doc/developer.texi
+++ b/doc/developer.texi
@@ -23,27 +23,37 @@ audio or video streams.
@end itemize
-@section Integrating libav in your program
-
-Shared libraries should be used whenever is possible in order to reduce
-the effort distributors have to pour to support programs and to ensure
-only the public api is used.
-
-You can use Libav in your commercial program, but you must abide to the
-license, LGPL or GPL depending on the specific features used, please refer
-to @url{http://libav.org/legal.html} for a quick checklist and to
-@url{http://git.libav.org/?p=libav.git;a=blob;f=COPYING.GPLv2},
-@url{http://git.libav.org/?p=libav.git;a=blob;f=COPYING.GPLv3},
-@url{http://git.libav.org/?p=libav.git;a=blob;f=COPYING.LGPLv2.1},
-@url{http://git.libav.org/?p=libav.git;a=blob;f=COPYING.LGPLv3} for the
-exact text of the licenses.
-Any modification to the source code can be suggested for inclusion.
-The best way to proceed is to send your patches to the Libav mailing list.
+@section Integrating libavcodec or libavformat in your program
+
+You can integrate all the source code of the libraries to link them
+statically to avoid any version problem. All you need is to provide a
+'config.mak' and a 'config.h' in the parent directory. See the defines
+generated by ./configure to understand what is needed.
+
+You can use libavcodec or libavformat in your commercial program, but
+@emph{any patch you make must be published}. The best way to proceed is
+to send your patches to the FFmpeg mailing list.
+
+@section Contributing
+
+There are 3 ways by which code gets into ffmpeg.
+@itemize @bullet
+@item Submiting Patches to the main developer mailing list
+ see @ref{Submitting patches} for details.
+@item Directly commiting changes to the main tree.
+@item Commiting changes to a git clone, for example on github.com or
+ gitorious.org. And asking us to merge these changes.
+@end itemize
+
+Whichever way, changes should be reviewed by the maintainer of the code
+before they are commited. And they should follow the @ref{Coding Rules}.
+The developer making the commit and the author are responsible for their changes
+and should try to fix issues their commit causes.
@anchor{Coding Rules}
@section Coding Rules
-Libav is programmed in the ISO C90 language with a few additional
+FFmpeg is programmed in the ISO C90 language with a few additional
features from ISO C99, namely:
@itemize @bullet
@item
@@ -60,10 +70,8 @@ These features are supported by all compilers we care about, so we will not
accept patches to remove their use unless they absolutely do not impair
clarity and performance.
-All code must compile with GCC 2.95 and GCC 3.3. Currently, Libav also
-compiles with several other compilers, such as the Compaq ccc compiler
-or Sun Studio 9, and we would like to keep it that way unless it would
-be exceedingly involved. To ensure compatibility, please do not use any
+All code must compile with recent versions of GCC and a number of other
+currently supported compilers. To ensure compatibility, please do not use
additional C99 features or GCC extensions. Especially watch out for:
@itemize @bullet
@item
@@ -82,7 +90,7 @@ The TAB character is forbidden outside of Makefiles as is any
form of trailing whitespace. Commits containing either will be
rejected by the git repository.
-The main priority in Libav is simplicity and small code size in order to
+The main priority in FFmpeg is simplicity and small code size in order to
minimize the bug count.
Comments: Use the JavaDoc/Doxygen
@@ -92,7 +100,7 @@ above them explaining what the function does, even if it is just one sentence.
All structures and their member variables should be documented, too.
@example
/**
- * @@file mpeg.c
+ * @@file
* MPEG codec.
* @@author ...
*/
@@ -135,33 +143,17 @@ should also be avoided if they don't make the code easier to understand.
an "or any later version" clause is also acceptable, but LGPL is
preferred.
@item
- All the patches MUST be reviewed in the mailing list before they are
- committed.
-@item
- The Libav coding style should remain consistent. Changes to
- conform will be suggested during the review or implemented on commit.
-@item
- Patches should be generated using @code{git format-patch} or directly sent
- using @code{git send-email}.
- Please make sure you give the proper credit by setting the correct author
- in the commit.
-@item
- The commit message should have a short first line in the form of
- @samp{topic: short description} as header, separated by a newline
- from the body consting in few lines explaining the reason of the patch.
- Referring to the issue on the bug tracker does not exempt to report an
- excerpt of the bug.
+ You must not commit code which breaks FFmpeg! (Meaning unfinished but
+ enabled code which breaks compilation or compiles but does not work or
+ breaks the regression tests)
+ You can commit unfinished stuff (for testing etc), but it must be disabled
+ (#ifdef etc) by default so it does not interfere with other developers'
+ work.
@item
- Work in progress patches should be sent to the mailing list with the [WIP]
- or the [RFC] tag.
-@item
- Branches in public personal repos are advised as way to
- work on issues collaboratively.
-@item
- You do not have to over-test things. If it works for you and you think it
- should work for others, send it to the mailing list for review.
- If you have doubt about portability please state it in the submission so
- people with specific hardware could test it.
+ You do not have to over-test things. If it works for you, and you think it
+ should work for others, then commit. If your code has problems
+ (portability, triggers compiler bugs, unusual environment etc) they will be
+ reported and eventually fixed.
@item
Do not commit unrelated changes together, split them into self-contained
pieces. Also do not forget that if part B depends on part A, but A does not
@@ -169,32 +161,73 @@ should also be avoided if they don't make the code easier to understand.
Keeping changes well split into self-contained parts makes reviewing and
understanding them on the commit log mailing list easier. This also helps
in case of debugging later on.
-@item
- Patches that change behavior of the programs (renaming options etc) or
- public API or ABI should be discussed in depth and possible few days should
- pass between discussion and commit.
- Changes to the build system (Makefiles, configure script) which alter
- the expected behavior should be considered in the same regard.
+ Also if you have doubts about splitting or not splitting, do not hesitate to
+ ask/discuss it on the developer mailing list.
+@item
+ Do not change behavior of the programs (renaming options etc) or public
+ API or ABI without first discussing it on the ffmpeg-devel mailing list.
+ Do not remove functionality from the code. Just improve!
+
+ Note: Redundant code can be removed.
+@item
+ Do not commit changes to the build system (Makefiles, configure script)
+ which change behavior, defaults etc, without asking first. The same
+ applies to compiler warning fixes, trivial looking fixes and to code
+ maintained by other developers. We usually have a reason for doing things
+ the way we do. Send your changes as patches to the ffmpeg-devel mailing
+ list, and if the code maintainers say OK, you may commit. This does not
+ apply to files you wrote and/or maintain.
+@item
+ We refuse source indentation and other cosmetic changes if they are mixed
+ with functional changes, such commits will be rejected and removed. Every
+ developer has his own indentation style, you should not change it. Of course
+ if you (re)write something, you can use your own style, even though we would
+ prefer if the indentation throughout FFmpeg was consistent (Many projects
+ force a given indentation style - we do not.). If you really need to make
+ indentation changes (try to avoid this), separate them strictly from real
+ changes.
+
+ NOTE: If you had to put if()@{ .. @} over a large (> 5 lines) chunk of code,
+ then either do NOT change the indentation of the inner part within (do not
+ move it to the right)! or do so in a separate commit
+@item
+ Always fill out the commit log message. Describe in a few lines what you
+ changed and why. You can refer to mailing list postings if you fix a
+ particular bug. Comments such as "fixed!" or "Changed it." are unacceptable.
+ Recommanded format:
+ area changed: Short 1 line description
+
+ details describing what and why and giving references.
+@item
+ Make sure the author of the commit is set correctly. (see git commit --author)
+ If you apply a patch, send an
+ answer to ffmpeg-devel (or wherever you got the patch from) saying that
+ you applied the patch.
@item
When applying patches that have been discussed (at length) on the mailing
list, reference the thread in the log message.
@item
- Subscribe to the libav-devel and libav-commits mailing list.
- Bugs and possible improvements or general questions regarding commits
- are discussed on libav-devel. We expect you to react if problems with
- your code are uncovered.
+ Do NOT commit to code actively maintained by others without permission.
+ Send a patch to ffmpeg-devel instead. If no one answers within a reasonable
+ timeframe (12h for build failures and security fixes, 3 days small changes,
+ 1 week for big patches) then commit your patch if you think it is OK.
+ Also note, the maintainer can simply ask for more time to review!
+@item
+ Subscribe to the ffmpeg-cvslog mailing list. The diffs of all commits
+ are sent there and reviewed by all the other developers. Bugs and possible
+ improvements or general questions regarding commits are discussed there. We
+ expect you to react if problems with your code are uncovered.
@item
Update the documentation if you change behavior or add features. If you are
- unsure how best to do this, send an [RFC] patch to libav-devel.
+ unsure how best to do this, send a patch to ffmpeg-devel, the documentation
+ maintainer(s) will review and commit your stuff.
@item
- All discussions and decisions should be reported on the public developer
- mailing list, so that there is a reference to them.
- Other media (e.g. IRC) should be used for coordination and immediate
- collaboration.
+ Try to keep important discussions and requests (also) on the public
+ developer mailing list, so that all developers can benefit from them.
@item
Never write to unallocated memory, never write over the end of arrays,
always check values read from some untrusted source before using them
- as array index or other risky things. Always use valgrind to doublecheck.
+ as array index or other risky things.
@item
Remember to check if you need to bump versions for the specific libav
parts (libavutil, libavcodec, libavformat) you are changing. You need
@@ -207,12 +240,13 @@ should also be avoided if they don't make the code easier to understand.
Incrementing the third component means a noteworthy binary compatible
change (e.g. encoder bug fix that matters for the decoder).
@item
- Compiler warnings indicate potential bugs or code with bad style.
+ Compiler warnings indicate potential bugs or code with bad style. If a type of
+ warning always points to correct and clean code, that warning should
+ be disabled, not the code changed.
+ Thus the remaining warnings can either be bugs or correct code.
If it is a bug, the bug has to be fixed. If it is not, the code should
be changed to not generate a warning unless that causes a slowdown
or obfuscates the code.
- If a type of warning leads to too many false positives, that warning
- should be disabled, not the code changed.
@item
If you add a new file, give it a proper license header. Do not copy and
paste it from a random place, use an existing file as template.
@@ -220,48 +254,47 @@ should also be avoided if they don't make the code easier to understand.
We think our rules are not too hard. If you have comments, contact us.
-Note, some rules were borrowed from the MPlayer project.
+Note, these rules are mostly borrowed from the MPlayer project.
+@anchor{Submitting patches}
@section Submitting patches
-First, read the (@pxref{Coding Rules}) above if you did not yet, in particular
+First, read the @ref{Coding Rules} above if you did not yet, in particular
the rules regarding patch submission.
-As stated already, please do not submit a patch which contains several
-unrelated changes.
+When you submit your patch, please use @code{git format-patch} or
+@code{git send-email}. We cannot read other diffs :-)
+
+Also please do not submit a patch which contains several unrelated changes.
Split it into separate, self-contained pieces. This does not mean splitting
file by file. Instead, make the patch as small as possible while still
keeping it as a logical unit that contains an individual change, even
if it spans multiple files. This makes reviewing your patches much easier
for us and greatly increases your chances of getting your patch applied.
-Use the patcheck tool of Libav to check your patch.
+Use the patcheck tool of FFmpeg to check your patch.
The tool is located in the tools directory.
-Run the @pxref{Regression Tests} before submitting a patch in order to verify
+Run the @ref{Regression Tests} before submitting a patch in order to verify
it does not cause unexpected problems.
Patches should be posted as base64 encoded attachments (or any other
encoding which ensures that the patch will not be trashed during
-transmission) to the libav-devel mailing list, see
-@url{https://lists.libav.org/mailman/listinfo/libav-devel}
+transmission) to the ffmpeg-devel mailing list, see
+@url{http://lists.ffmpeg.org/mailman/listinfo/ffmpeg-devel}
It also helps quite a bit if you tell us what the patch does (for example
'replaces lrint by lrintf'), and why (for example '*BSD isn't C99 compliant
-and has no lrint()'). This kind of explanation should be the body of the
-commit message.
+and has no lrint()')
Also please if you send several patches, send each patch as a separate mail,
do not attach several unrelated patches to the same mail.
-Use @code{git send-email} when possible since it will properly send patches
-without requiring extra care.
-
Your patch will be reviewed on the mailing list. You will likely be asked
to make some changes and are expected to send in an improved version that
incorporates the requests from the review. This process may go through
-several iterations. Once your patch is deemed good enough, it will be
-committed to the official Libav tree.
+several iterations. Once your patch is deemed good enough, some developer
+will pick it up and commit it to the official FFmpeg tree.
Give us a few days to react. But if some time passes without reaction,
send a reminder by email. Your patch should eventually be dealt with.
@@ -277,7 +310,7 @@ send a reminder by email. Your patch should eventually be dealt with.
AVInputFormat/AVOutputFormat struct?
@item
Did you bump the minor version number (and reset the micro version
- number) in @file{avcodec.h} or @file{avformat.h}?
+ number) in @file{libavcodec/version.h} or @file{libavformat/version.h}?
@item
Did you register it in @file{allcodecs.c} or @file{allformats.c}?
@item
@@ -287,8 +320,8 @@ send a reminder by email. Your patch should eventually be dealt with.
even if it is only a decoder?
@item
Did you add a rule to compile the appropriate files in the Makefile?
- Remember to do this even if you are just adding a format to a file that
- is already being compiled by some other rule, like a raw demuxer.
+ Remember to do this even if you're just adding a format to a file that is
+ already being compiled by some other rule, like a raw demuxer.
@item
Did you add an entry to the table of supported formats or codecs in
@file{doc/general.texi}?
@@ -310,15 +343,20 @@ send a reminder by email. Your patch should eventually be dealt with.
@enumerate
@item
- Do the regression tests pass with the patch applied?
+ Does @code{make fate} pass with the patch applied?
+@item
+ Was the patch generated with git format-patch or send-email?
+@item
+ Did you sign off your patch? (git commit -s)
+ See @url{http://kerneltrap.org/files/Jeremy/DCO.txt} for the meaning
+ of sign off.
@item
- Does @code{make checkheaders} pass with the patch applied?
+ Did you provide a clear git commit log message?
@item
- Is the patch against latest Libav git master branch?
+ Is the patch against latest FFmpeg git master branch?
@item
- Are you subscribed to libav-devel?
- (@url{https://lists.libav.org/mailman/listinfo/libav-devel}
- the list is subscribers)
+ Are you subscribed to ffmpeg-devel?
+ (the list is subscribers only due to spam)
@item
Have you checked that the changes are minimal, so that the same cannot be
achieved with a smaller patch and/or simpler final code?
@@ -348,7 +386,7 @@ send a reminder by email. Your patch should eventually be dealt with.
If the patch fixes a bug, did you provide enough information, including
a sample, so the bug can be reproduced and the fix can be verified?
Note please do not attach samples >100k to mails but rather provide a
- URL, you can upload to ftp://upload.libav.org
+ URL, you can upload to ftp://upload.ffmpeg.org
@item
Did you provide a verbose summary about what the patch does change?
@item
@@ -361,18 +399,22 @@ send a reminder by email. Your patch should eventually be dealt with.
patch easily?
@item
If you added a new file, did you insert a license header? It should be
- taken from Libav, not randomly copied and pasted from somewhere else.
+ taken from FFmpeg, not randomly copied and pasted from somewhere else.
@item
You should maintain alphabetical order in alphabetically ordered lists as
long as doing so does not break API/ABI compatibility.
@item
Lines with similar content should be aligned vertically when doing so
improves readability.
+@item
+ Consider to add a regression test for your code.
+@item
+ If you added YASM code please check that things still work with --disable-yasm
@end enumerate
@section Patch review process
-All patches posted to libav-devel will be reviewed, unless they contain a
+All patches posted to ffmpeg-devel will be reviewed, unless they contain a
clear note that the patch is not for the git master branch.
Reviews and comments will be posted as replies to the patch on the
mailing list. The patch submitter then has to take care of every comment,
@@ -386,22 +428,25 @@ After a patch is approved it will be committed to the repository.
We will review all submitted patches, but sometimes we are quite busy so
especially for large patches this can take several weeks.
-When resubmitting patches, if their size grew or during the review different
-issues arisen please split the patch so each issue has a specific patch.
+If you feel that the review process is too slow and you are willing to try to
+take over maintainership of the area of code you change then just clone
+git master and maintain the area of code there. We will merge each area from
+where its best maintained.
-@anchor{Regression Tests}
-@section Regression Tests
+When resubmitting patches, please do not make any significant changes
+not related to the comments received during review. Such patches will
+be rejected. Instead, submit significant changes or new features as
+separate patches.
-Before submitting a patch (or committing to the repository), you should at
-least make sure that it does not break anything.
+@section Regression tests
-If the code changed has already a test present in FATE you should run it,
-otherwise it is advised to add it.
+Before submitting a patch (or committing to the repository), you should at least
+test that you did not break anything.
-Improvements to codec or demuxer might change the FATE results. Make sure
-to commit the update reference with the change and to explain in the comment
-why the expected result changed.
+Running 'make fate' accomplishes this, please see @file{doc/fate.txt} for details.
-Please refer to @file{doc/fate.txt}.
+[Of course, some patches may change the results of the regression tests. In
+this case, the reference results of the regression tests shall be modified
+accordingly].
@bye
diff --git a/doc/encoders.texi b/doc/encoders.texi
index d507b66f51..3607bb1d1b 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -1,10 +1,10 @@
@chapter Encoders
@c man begin ENCODERS
-Encoders are configured elements in Libav which allow the encoding of
+Encoders are configured elements in FFmpeg which allow the encoding of
multimedia streams.
-When you configure your Libav build, all the supported native encoders
+When you configure your FFmpeg build, all the supported native encoders
are enabled by default. Encoders requiring an external library must be enabled
manually via the corresponding @code{--enable-lib} option. You can list all
available encoders using the configure option @code{--list-encoders}.
@@ -320,10 +320,10 @@ apply Dolby Surround EX processing.
Not Indicated (default)
@item 1
@itemx on
-Dolby Surround EX On
+Dolby Surround EX Off
@item 2
@itemx off
-Dolby Surround EX Off
+Dolby Surround EX On
@end table
@item -dheadphone_mode @var{mode}
@@ -337,10 +337,10 @@ processing.
Not Indicated (default)
@item 1
@itemx on
-Dolby Headphone On
+Dolby Headphone Off
@item 2
@itemx off
-Dolby Headphone Off
+Dolby Headphone On
@end table
@item -ad_conv_type @var{type}
@@ -369,7 +369,7 @@ is highly recommended that it be left as enabled except for testing purposes.
@end table
-@subheading Floating-Point-Only AC-3 Encoding Options
+@subsection Floating-Point-Only AC-3 Encoding Options
These options are only valid for the floating-point encoder and do not exist
for the fixed-point encoder due to the corresponding features not being
@@ -413,3 +413,179 @@ Selected by Encoder (default)
@end table
@c man end AUDIO ENCODERS
+
+@chapter Video Encoders
+@c man begin VIDEO ENCODERS
+
+A description of some of the currently available video encoders
+follows.
+
+@section libvpx
+
+VP8 format supported through libvpx.
+
+Requires the presence of the libvpx headers and library during configuration.
+You need to explicitly configure the build with @code{--enable-libvpx}.
+
+@subsection Options
+
+Mapping from FFmpeg to libvpx options with conversion notes in parentheses.
+
+@table @option
+
+@item threads
+g_threads
+
+@item profile
+g_profile
+
+@item vb
+rc_target_bitrate
+
+@item g
+kf_max_dist
+
+@item keyint_min
+kf_min_dist
+
+@item qmin
+rc_min_quantizer
+
+@item qmax
+rc_max_quantizer
+
+@item bufsize, vb
+rc_buf_sz
+@code{(bufsize * 1000 / vb)}
+
+rc_buf_optimal_sz
+@code{(bufsize * 1000 / vb * 5 / 6)}
+
+@item rc_init_occupancy, vb
+rc_buf_initial_sz
+@code{(rc_init_occupancy * 1000 / vb)}
+
+@item rc_buffer_aggressivity
+rc_undershoot_pct
+
+@item skip_threshold
+rc_dropframe_thresh
+
+@item qcomp
+rc_2pass_vbr_bias_pct
+
+@item maxrate, vb
+rc_2pass_vbr_maxsection_pct
+@code{(maxrate * 100 / vb)}
+
+@item minrate, vb
+rc_2pass_vbr_minsection_pct
+@code{(minrate * 100 / vb)}
+
+@item minrate, maxrate, vb
+@code{VPX_CBR}
+@code{(minrate == maxrate == vb)}
+
+@item crf
+@code{VPX_CQ}, @code{VP8E_SET_CQ_LEVEL}
+
+@item quality
+@table @option
+@item @var{best}
+@code{VPX_DL_BEST_QUALITY}
+@item @var{good}
+@code{VPX_DL_GOOD_QUALITY}
+@item @var{realtime}
+@code{VPX_DL_REALTIME}
+@end table
+
+@item speed
+@code{VP8E_SET_CPUUSED}
+
+@item nr
+@code{VP8E_SET_NOISE_SENSITIVITY}
+
+@item mb_threshold
+@code{VP8E_SET_STATIC_THRESHOLD}
+
+@item slices
+@code{VP8E_SET_TOKEN_PARTITIONS}
+
+@item Alternate reference frame related
+@table @option
+@item vp8flags altref
+@code{VP8E_SET_ENABLEAUTOALTREF}
+@item @var{arnr_max_frames}
+@code{VP8E_SET_ARNR_MAXFRAMES}
+@item @var{arnr_type}
+@code{VP8E_SET_ARNR_TYPE}
+@item @var{arnr_strength}
+@code{VP8E_SET_ARNR_STRENGTH}
+@item @var{rc_lookahead}
+g_lag_in_frames
+@end table
+
+@item vp8flags error_resilient
+g_error_resilient
+
+@end table
+
+For more information about libvpx see:
+@url{http://www.webmproject.org/}
+
+@section libx264
+
+H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 format supported through
+libx264.
+
+Requires the presence of the libx264 headers and library during
+configuration. You need to explicitly configure the build with
+@code{--enable-libx264}.
+
+@subsection Options
+
+@table @option
+
+@item preset @var{preset_name}
+Set the encoding preset.
+
+@item tune @var{tune_name}
+Tune the encoding params.
+Deprecated in favor of @var{x264opts}
+
+@item fastfirstpass @var{bool}
+Use fast settings when encoding first pass, default value is 1.
+Deprecated in favor of @var{x264opts}.
+
+@item profile @var{profile_name}
+Set profile restrictions.
+Deprecated in favor of @var{x264opts}.
+
+@item level @var{level}
+Specify level (as defined by Annex A).
+Deprecated in favor of @var{x264opts}.
+
+@item passlogfile @var{filename}
+Specify filename for 2 pass stats.
+Deprecated in favor of @var{x264opts}.
+
+@item wpredp @var{wpred_type}
+Specify Weighted prediction for P-frames.
+Deprecated in favor of @var{x264opts}.
+
+@item x264opts @var{options}
+Allow to set any x264 option, see x264 manual for a list.
+
+@var{options} is a list of @var{key}=@var{value} couples separated by
+":".
+@end table
+
+For example to specify libx264 encoding options with @file{ffmpeg}:
+@example
+ffmpeg -i foo.mpg -vcodec libx264 -x264opts keyint=123:min-keyint=20 -an out.mkv
+@end example
+
+For more information about libx264 and the supported options see:
+@url{http://www.videolan.org/developers/x264.html}
+
+@c man end VIDEO ENCODERS
diff --git a/doc/eval.texi b/doc/eval.texi
index d8c693f304..18d848749a 100644
--- a/doc/eval.texi
+++ b/doc/eval.texi
@@ -1,7 +1,7 @@
@chapter Expression Evaluation
@c man begin EXPRESSION EVALUATION
-When evaluating an arithemetic expression, Libav uses an internal
+When evaluating an arithemetic expression, FFmpeg uses an internal
formula evaluator, implemented through the @file{libavutil/eval.h}
interface.
@@ -72,6 +72,41 @@ integer. For example, "floor(-1.5)" is "-2.0".
@item trunc(expr)
Round the value of expression @var{expr} towards zero to the nearest
integer. For example, "trunc(-1.5)" is "-1.0".
+
+@item sqrt(expr)
+Compute the square root of @var{expr}. This is equivalent to
+"(@var{expr})^.5".
+
+@item not(expr)
+Return 1.0 if @var{expr} is zero, 0.0 otherwise.
+
+@item pow(x, y)
+Compute the power of @var{x} elevated @var{y}, it is equivalent to
+"(@var{x})^(@var{y})".
+
+@item random(x)
+Return a pseudo random value between 0.0 and 1.0. @var{x} is the index of the
+internal variable which will be used to save the seed/state.
+
+@item hypot(x, y)
+This function is similar to the C function with the same name; it returns
+"sqrt(@var{x}*@var{x} + @var{y}*@var{y})", the length of the hypotenuse of a
+right triangle with sides of length @var{x} and @var{y}, or the distance of the
+point (@var{x}, @var{y}) from the origin.
+
+@item gcd(x, y)
+Return the greatest common divisor of @var{x} and @var{y}. If both @var{x} and
+@var{y} are 0 or either or both are less than zero then behavior is undefined.
+@end table
+
+The following constants are available:
+@table @option
+@item PI
+area of the unit disc, approximatively 3.14
+@item E
+exp(1) (Euler's number), approximatively 2.718
+@item PHI
+golden ratio (1+sqrt(5))/2, approximatively 1.618
@end table
Note that:
@@ -89,11 +124,6 @@ is equivalent to
A*B + not(A)*C
@end example
-When A evaluates to either 1 or 0, that is the same as
-@example
-A*B + eq(A,0)*C
-@end example
-
In your C code, you can extend the list of unary and binary functions,
and define recognized constants, so that they are available for your
expressions.
diff --git a/doc/examples/Makefile b/doc/examples/Makefile
new file mode 100644
index 0000000000..b363590d53
--- /dev/null
+++ b/doc/examples/Makefile
@@ -0,0 +1,21 @@
+# use pkg-config for getting CFLAGS abd LDFLAGS
+FFMPEG_LIBS=libavdevice libavformat libavfilter libavcodec libswscale libavutil
+CFLAGS+=$(shell pkg-config --cflags $(FFMPEG_LIBS))
+LDFLAGS+=$(shell pkg-config --libs $(FFMPEG_LIBS))
+
+EXAMPLES=decoding_encoding filtering metadata muxing
+
+OBJS=$(addsuffix .o,$(EXAMPLES))
+
+%: %.o
+ $(CC) $< $(LDFLAGS) -o $@
+
+%.o: %.c
+ $(CC) $< $(CFLAGS) -c -o $@
+
+.phony: all clean
+
+all: $(OBJS) $(EXAMPLES)
+
+clean:
+ rm -rf $(EXAMPLES) $(OBJS)
diff --git a/libavcodec/api-example.c b/doc/examples/decoding_encoding.c
index 1792d60d77..ee0cb585f5 100644
--- a/libavcodec/api-example.c
+++ b/doc/examples/decoding_encoding.c
@@ -1,41 +1,36 @@
/*
- * copyright (c) 2001 Fabrice Bellard
+ * Copyright (c) 2001 Fabrice Bellard
*
- * This file is part of Libav.
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
*
- * Libav 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
*
- * Libav 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
*/
/**
* @file
* libavcodec API use example.
*
- * @example libavcodec/api-example.c
- * Note that this library only handles codecs (mpeg, mpeg4, etc...),
- * not file formats (avi, vob, etc...). See library 'libavformat' for the
+ * Note that libavcodec only handles codecs (mpeg, mpeg4, etc...),
+ * not file formats (avi, vob, mp4, mov, mkv, mxf, flv, mpegts, mpegps, etc...). See library 'libavformat' for the
* format handling
*/
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#ifdef HAVE_AV_CONFIG_H
-#undef HAVE_AV_CONFIG_H
-#endif
-
+#include "libavutil/imgutils.h"
+#include "libavutil/opt.h"
#include "libavcodec/avcodec.h"
#include "libavutil/mathematics.h"
@@ -65,12 +60,13 @@ static void audio_encode_example(const char *filename)
exit(1);
}
- c= avcodec_alloc_context();
+ c = avcodec_alloc_context3(codec);
/* put sample parameters */
c->bit_rate = 64000;
c->sample_rate = 44100;
c->channels = 2;
+ c->sample_fmt = AV_SAMPLE_FMT_S16;
/* open it */
if (avcodec_open(c, codec) < 0) {
@@ -135,7 +131,7 @@ static void audio_decode_example(const char *outfilename, const char *filename)
exit(1);
}
- c= avcodec_alloc_context();
+ c = avcodec_alloc_context3(codec);
/* open it */
if (avcodec_open(c, codec) < 0) {
@@ -198,25 +194,25 @@ static void audio_decode_example(const char *outfilename, const char *filename)
/*
* Video encoding example
*/
-static void video_encode_example(const char *filename)
+static void video_encode_example(const char *filename, int codec_id)
{
AVCodec *codec;
AVCodecContext *c= NULL;
int i, out_size, size, x, y, outbuf_size;
FILE *f;
AVFrame *picture;
- uint8_t *outbuf, *picture_buf;
+ uint8_t *outbuf;
printf("Video encoding\n");
/* find the mpeg1 video encoder */
- codec = avcodec_find_encoder(CODEC_ID_MPEG1VIDEO);
+ codec = avcodec_find_encoder(codec_id);
if (!codec) {
fprintf(stderr, "codec not found\n");
exit(1);
}
- c= avcodec_alloc_context();
+ c = avcodec_alloc_context3(codec);
picture= avcodec_alloc_frame();
/* put sample parameters */
@@ -230,6 +226,9 @@ static void video_encode_example(const char *filename)
c->max_b_frames=1;
c->pix_fmt = PIX_FMT_YUV420P;
+ if(codec_id == CODEC_ID_H264)
+ av_opt_set(c->priv_data, "preset", "slow", 0);
+
/* open it */
if (avcodec_open(c, codec) < 0) {
fprintf(stderr, "could not open codec\n");
@@ -245,15 +244,11 @@ static void video_encode_example(const char *filename)
/* alloc image and output buffer */
outbuf_size = 100000;
outbuf = malloc(outbuf_size);
- size = c->width * c->height;
- picture_buf = malloc((size * 3) / 2); /* size for YUV 420 */
- picture->data[0] = picture_buf;
- picture->data[1] = picture->data[0] + size;
- picture->data[2] = picture->data[1] + size / 4;
- picture->linesize[0] = c->width;
- picture->linesize[1] = c->width / 2;
- picture->linesize[2] = c->width / 2;
+ /* the image can be allocated by any means and av_image_alloc() is
+ * just the most convenient way if av_malloc() is to be used */
+ av_image_alloc(picture->data, picture->linesize,
+ c->width, c->height, c->pix_fmt, 1);
/* encode 1 second of video */
for(i=0;i<25;i++) {
@@ -296,11 +291,11 @@ static void video_encode_example(const char *filename)
outbuf[3] = 0xb7;
fwrite(outbuf, 1, 4, f);
fclose(f);
- free(picture_buf);
free(outbuf);
avcodec_close(c);
av_free(c);
+ av_free(picture->data[0]);
av_free(picture);
printf("\n");
}
@@ -347,7 +342,7 @@ static void video_decode_example(const char *outfilename, const char *filename)
exit(1);
}
- c= avcodec_alloc_context();
+ c = avcodec_alloc_context3(codec);
picture= avcodec_alloc_frame();
if(codec->capabilities&CODEC_CAP_TRUNCATED)
@@ -455,7 +450,8 @@ int main(int argc, char **argv)
audio_encode_example("/tmp/test.mp2");
audio_decode_example("/tmp/test.sw", "/tmp/test.mp2");
- video_encode_example("/tmp/test.mpg");
+ video_encode_example("/tmp/test.h264", CODEC_ID_H264);
+ video_encode_example("/tmp/test.mpg", CODEC_ID_MPEG1VIDEO);
filename = "/tmp/test.mpg";
} else {
filename = argv[1];
diff --git a/doc/examples/filtering.c b/doc/examples/filtering.c
new file mode 100644
index 0000000000..369cc03e80
--- /dev/null
+++ b/doc/examples/filtering.c
@@ -0,0 +1,230 @@
+/*
+ * Copyright (c) 2010 Nicolas George
+ * Copyright (c) 2011 Stefano Sabatini
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+/**
+ * @file
+ * API example for decoding and filtering
+ */
+
+#define _XOPEN_SOURCE 600 /* for usleep */
+
+#include <libavcodec/avcodec.h>
+#include <libavformat/avformat.h>
+#include <libavfilter/avfiltergraph.h>
+#include <libavfilter/vsink_buffer.h>
+#include <libavfilter/vsrc_buffer.h>
+
+const char *filter_descr = "scale=78:24";
+
+static AVFormatContext *fmt_ctx;
+static AVCodecContext *dec_ctx;
+AVFilterContext *buffersink_ctx;
+AVFilterContext *buffersrc_ctx;
+AVFilterGraph *filter_graph;
+static int video_stream_index = -1;
+static int64_t last_pts = AV_NOPTS_VALUE;
+
+static int open_input_file(const char *filename)
+{
+ int ret, i;
+ AVCodec *dec;
+
+ if ((ret = avformat_open_input(&fmt_ctx, filename, NULL, NULL)) < 0) {
+ av_log(NULL, AV_LOG_ERROR, "Cannot open input file\n");
+ return ret;
+ }
+
+ if ((ret = av_find_stream_info(fmt_ctx)) < 0) {
+ av_log(NULL, AV_LOG_ERROR, "Cannot find stream information\n");
+ return ret;
+ }
+
+ /* select the video stream */
+ ret = av_find_best_stream(fmt_ctx, AVMEDIA_TYPE_VIDEO, -1, -1, &dec, 0);
+ if (ret < 0) {
+ av_log(NULL, AV_LOG_ERROR, "Cannot find a video stream in the input file\n");
+ return ret;
+ }
+ video_stream_index = ret;
+ dec_ctx = fmt_ctx->streams[video_stream_index]->codec;
+
+ /* init the video decoder */
+ if ((ret = avcodec_open(dec_ctx, dec)) < 0) {
+ av_log(NULL, AV_LOG_ERROR, "Cannot open video decoder\n");
+ return ret;
+ }
+
+ return 0;
+}
+
+static int init_filters(const char *filters_descr)
+{
+ char args[512];
+ int ret;
+ AVFilter *buffersrc = avfilter_get_by_name("buffer");
+ AVFilter *buffersink = avfilter_get_by_name("buffersink");
+ AVFilterInOut *outputs = avfilter_inout_alloc();
+ AVFilterInOut *inputs = avfilter_inout_alloc();
+ enum PixelFormat pix_fmts[] = { PIX_FMT_GRAY8, PIX_FMT_NONE };
+ filter_graph = avfilter_graph_alloc();
+
+ /* buffer video source: the decoded frames from the decoder will be inserted here. */
+ snprintf(args, sizeof(args), "%d:%d:%d:%d:%d:%d:%d",
+ dec_ctx->width, dec_ctx->height, dec_ctx->pix_fmt,
+ dec_ctx->time_base.num, dec_ctx->time_base.den,
+ dec_ctx->sample_aspect_ratio.num, dec_ctx->sample_aspect_ratio.den);
+ ret = avfilter_graph_create_filter(&buffersrc_ctx, buffersrc, "in",
+ args, NULL, filter_graph);
+ if (ret < 0) {
+ av_log(NULL, AV_LOG_ERROR, "Cannot create buffer source\n");
+ return ret;
+ }
+
+ /* buffer video sink: to terminate the filter chain. */
+ ret = avfilter_graph_create_filter(&buffersink_ctx, buffersink, "out",
+ NULL, pix_fmts, filter_graph);
+ if (ret < 0) {
+ av_log(NULL, AV_LOG_ERROR, "Cannot create buffer sink\n");
+ return ret;
+ }
+
+ /* Endpoints for the filter graph. */
+ outputs->name = av_strdup("in");
+ outputs->filter_ctx = buffersrc_ctx;
+ outputs->pad_idx = 0;
+ outputs->next = NULL;
+
+ inputs->name = av_strdup("out");
+ inputs->filter_ctx = buffersink_ctx;
+ inputs->pad_idx = 0;
+ inputs->next = NULL;
+
+ if ((ret = avfilter_graph_parse(filter_graph, filter_descr,
+ &inputs, &outputs, NULL)) < 0)
+ return ret;
+
+ if ((ret = avfilter_graph_config(filter_graph, NULL)) < 0)
+ return ret;
+}
+
+static void display_picref(AVFilterBufferRef *picref, AVRational time_base)
+{
+ int x, y;
+ uint8_t *p0, *p;
+ int64_t delay;
+
+ if (picref->pts != AV_NOPTS_VALUE) {
+ if (last_pts != AV_NOPTS_VALUE) {
+ /* sleep roughly the right amount of time;
+ * usleep is in microseconds, just like AV_TIME_BASE. */
+ delay = av_rescale_q(picref->pts - last_pts,
+ time_base, AV_TIME_BASE_Q);
+ if (delay > 0 && delay < 1000000)
+ usleep(delay);
+ }
+ last_pts = picref->pts;
+ }
+
+ /* Trivial ASCII grayscale display. */
+ p0 = picref->data[0];
+ puts("\033c");
+ for (y = 0; y < picref->video->h; y++) {
+ p = p0;
+ for (x = 0; x < picref->video->w; x++)
+ putchar(" .-+#"[*(p++) / 52]);
+ putchar('\n');
+ p0 += picref->linesize[0];
+ }
+ fflush(stdout);
+}
+
+int main(int argc, char **argv)
+{
+ int ret;
+ AVPacket packet;
+ AVFrame frame;
+ int got_frame;
+
+ if (argc != 2) {
+ fprintf(stderr, "Usage: %s file\n", argv[0]);
+ exit(1);
+ }
+
+ avcodec_register_all();
+ av_register_all();
+ avfilter_register_all();
+
+ if ((ret = open_input_file(argv[1]) < 0))
+ goto end;
+ if ((ret = init_filters(filter_descr)) < 0)
+ goto end;
+
+ /* read all packets */
+ while (1) {
+ AVFilterBufferRef *picref;
+ if ((ret = av_read_frame(fmt_ctx, &packet)) < 0)
+ break;
+
+ if (packet.stream_index == video_stream_index) {
+ avcodec_get_frame_defaults(&frame);
+ got_frame = 0;
+ ret = avcodec_decode_video2(dec_ctx, &frame, &got_frame, &packet);
+ av_free_packet(&packet);
+ if (ret < 0) {
+ av_log(NULL, AV_LOG_ERROR, "Error decoding video\n");
+ break;
+ }
+
+ if (got_frame) {
+ if (frame.pts == AV_NOPTS_VALUE)
+ frame.pts = frame.pkt_dts == AV_NOPTS_VALUE ?
+ frame.pkt_dts : frame.pkt_pts;
+ /* push the decoded frame into the filtergraph */
+ av_vsrc_buffer_add_frame(buffersrc_ctx, &frame);
+
+ /* pull filtered pictures from the filtergraph */
+ while (avfilter_poll_frame(buffersink_ctx->inputs[0])) {
+ av_vsink_buffer_get_video_buffer_ref(buffersink_ctx, &picref, 0);
+ if (picref) {
+ display_picref(picref, buffersink_ctx->inputs[0]->time_base);
+ avfilter_unref_buffer(picref);
+ }
+ }
+ }
+ }
+ }
+end:
+ avfilter_graph_free(&filter_graph);
+ if (dec_ctx)
+ avcodec_close(dec_ctx);
+ av_close_input_file(fmt_ctx);
+
+ if (ret < 0 && ret != AVERROR_EOF) {
+ char buf[1024];
+ av_strerror(ret, buf, sizeof(buf));
+ fprintf(stderr, "Error occurred: %s\n", buf);
+ exit(1);
+ }
+
+ exit(0);
+}
diff --git a/libavformat/metadata-example.c b/doc/examples/metadata.c
index 7bf77e7378..7d29be7049 100644
--- a/libavformat/metadata-example.c
+++ b/doc/examples/metadata.c
@@ -22,7 +22,6 @@
/**
* @file
- * @example libavformat/metadata-example.c
* Shows how the metadata API can be used in application programs.
*/
diff --git a/libavformat/output-example.c b/doc/examples/muxing.c
index 3b28b7c7c6..0cdc895df8 100644
--- a/libavformat/output-example.c
+++ b/doc/examples/muxing.c
@@ -24,7 +24,6 @@
* @file
* libavformat API example.
*
- * @example libavformat/output-example.c
* Output a media file in any supported libavformat format.
* The default codecs are used.
*/
@@ -41,7 +40,7 @@
#undef exit
/* 5 seconds stream duration */
-#define STREAM_DURATION 5.0
+#define STREAM_DURATION 200.0
#define STREAM_FRAME_RATE 25 /* 25 images/s */
#define STREAM_NB_FRAMES ((int)(STREAM_DURATION * STREAM_FRAME_RATE))
#define STREAM_PIX_FMT PIX_FMT_YUV420P /* default pix_fmt */
@@ -82,7 +81,7 @@ static AVStream *add_audio_stream(AVFormatContext *oc, enum CodecID codec_id)
c->channels = 2;
// some formats want stream headers to be separate
- if(oc->oformat->flags & AVFMT_GLOBALHEADER)
+ if (oc->oformat->flags & AVFMT_GLOBALHEADER)
c->flags |= CODEC_FLAG_GLOBAL_HEADER;
return st;
@@ -145,7 +144,7 @@ static void get_audio_frame(int16_t *samples, int frame_size, int nb_channels)
int16_t *q;
q = samples;
- for(j=0;j<frame_size;j++) {
+ for (j = 0; j < frame_size; j++) {
v = (int)(sin(t) * 10000);
for(i = 0; i < nb_channels; i++)
*q++ = v;
@@ -164,13 +163,13 @@ static void write_audio_frame(AVFormatContext *oc, AVStream *st)
get_audio_frame(samples, audio_input_frame_size, c->channels);
- pkt.size= avcodec_encode_audio(c, audio_outbuf, audio_outbuf_size, samples);
+ pkt.size = avcodec_encode_audio(c, audio_outbuf, audio_outbuf_size, samples);
if (c->coded_frame && c->coded_frame->pts != AV_NOPTS_VALUE)
pkt.pts= av_rescale_q(c->coded_frame->pts, c->time_base, st->time_base);
pkt.flags |= AV_PKT_FLAG_KEY;
- pkt.stream_index= st->index;
- pkt.data= audio_outbuf;
+ pkt.stream_index = st->index;
+ pkt.data = audio_outbuf;
/* write the compressed frame in the media file */
if (av_interleaved_write_frame(oc, &pkt) != 0) {
@@ -200,7 +199,7 @@ static AVStream *add_video_stream(AVFormatContext *oc, enum CodecID codec_id)
AVCodecContext *c;
AVStream *st;
- st = av_new_stream(oc, 0);
+ st = avformat_new_stream(oc, NULL);
if (!st) {
fprintf(stderr, "Could not alloc stream\n");
exit(1);
@@ -234,7 +233,7 @@ static AVStream *add_video_stream(AVFormatContext *oc, enum CodecID codec_id)
c->mb_decision=2;
}
// some formats want stream headers to be separate
- if(oc->oformat->flags & AVFMT_GLOBALHEADER)
+ if (oc->oformat->flags & AVFMT_GLOBALHEADER)
c->flags |= CODEC_FLAG_GLOBAL_HEADER;
return st;
@@ -320,15 +319,15 @@ static void fill_yuv_image(AVFrame *pict, int frame_index, int width, int height
i = frame_index;
/* Y */
- for(y=0;y<height;y++) {
- for(x=0;x<width;x++) {
+ for (y = 0; y < height; y++) {
+ for (x = 0; x < width; x++) {
pict->data[0][y * pict->linesize[0] + x] = x + y + i * 3;
}
}
/* Cb and Cr */
- for(y=0;y<height/2;y++) {
- for(x=0;x<width/2;x++) {
+ for (y = 0; y < height/2; y++) {
+ for (x = 0; x < width/2; x++) {
pict->data[1][y * pict->linesize[1] + x] = 128 + y + i * 2;
pict->data[2][y * pict->linesize[2] + x] = 64 + x + i * 5;
}
@@ -373,14 +372,14 @@ static void write_video_frame(AVFormatContext *oc, AVStream *st)
if (oc->oformat->flags & AVFMT_RAWPICTURE) {
/* raw video case. The API will change slightly in the near
- futur for that */
+ future for that. */
AVPacket pkt;
av_init_packet(&pkt);
pkt.flags |= AV_PKT_FLAG_KEY;
- pkt.stream_index= st->index;
- pkt.data= (uint8_t *)picture;
- pkt.size= sizeof(AVPicture);
+ pkt.stream_index = st->index;
+ pkt.data = (uint8_t *)picture;
+ pkt.size = sizeof(AVPicture);
ret = av_interleaved_write_frame(oc, &pkt);
} else {
@@ -395,9 +394,9 @@ static void write_video_frame(AVFormatContext *oc, AVStream *st)
pkt.pts= av_rescale_q(c->coded_frame->pts, c->time_base, st->time_base);
if(c->coded_frame->key_frame)
pkt.flags |= AV_PKT_FLAG_KEY;
- pkt.stream_index= st->index;
- pkt.data= video_outbuf;
- pkt.size= out_size;
+ pkt.stream_index = st->index;
+ pkt.data = video_outbuf;
+ pkt.size = out_size;
/* write the compressed frame in the media file */
ret = av_interleaved_write_frame(oc, &pkt);
@@ -450,26 +449,16 @@ int main(int argc, char **argv)
filename = argv[1];
- /* auto detect the output format from the name. default is
- mpeg. */
- fmt = av_guess_format(NULL, filename, NULL);
- if (!fmt) {
+ /* allocate the output media context */
+ avformat_alloc_output_context2(&oc, NULL, NULL, filename);
+ if (!oc) {
printf("Could not deduce output format from file extension: using MPEG.\n");
- fmt = av_guess_format("mpeg", NULL, NULL);
+ avformat_alloc_output_context2(&oc, NULL, "mpeg", filename);
}
- if (!fmt) {
- fprintf(stderr, "Could not find suitable output format\n");
- exit(1);
- }
-
- /* allocate the output media context */
- oc = avformat_alloc_context();
if (!oc) {
- fprintf(stderr, "Memory error\n");
exit(1);
}
- oc->oformat = fmt;
- snprintf(oc->filename, sizeof(oc->filename), "%s", filename);
+ fmt = oc->oformat;
/* add the audio and video streams using the default format codecs
and initialize the codecs */
@@ -482,13 +471,6 @@ int main(int argc, char **argv)
audio_st = add_audio_stream(oc, fmt->audio_codec);
}
- /* set the output parameters (must be done even if no
- parameters). */
- if (av_set_parameters(oc, NULL) < 0) {
- fprintf(stderr, "Invalid output format parameters\n");
- exit(1);
- }
-
av_dump_format(oc, 0, filename, 1);
/* now that all the parameters are set, we can open the audio and
diff --git a/doc/faq.texi b/doc/faq.texi
index 3d7a275f89..7ea0c8d857 100644
--- a/doc/faq.texi
+++ b/doc/faq.texi
@@ -1,8 +1,8 @@
\input texinfo @c -*- texinfo -*-
-@settitle Libav FAQ
+@settitle FFmpeg FAQ
@titlepage
-@center @titlefont{Libav FAQ}
+@center @titlefont{FFmpeg FAQ}
@end titlepage
@top
@@ -11,42 +11,42 @@
@chapter General Questions
-@section When will the next Libav version be released? / Why are Libav releases so few and far between?
+@section When will the next FFmpeg version be released? / Why are FFmpeg releases so few and far between?
-Like most open source projects Libav suffers from a certain lack of
+Like most open source projects FFmpeg suffers from a certain lack of
manpower. For this reason the developers have to prioritize the work
they do and putting out releases is not at the top of the list, fixing
bugs and reviewing patches takes precedence. Please don't complain or
request more timely and/or frequent releases unless you are willing to
help out creating them.
-@section I have a problem with an old version of Libav; where should I report it?
-Nowhere. We do not support old Libav versions in any way, we simply lack
+@section I have a problem with an old version of FFmpeg; where should I report it?
+Nowhere. We do not support old FFmpeg versions in any way, we simply lack
the time, motivation and manpower to do so. If you have a problem with an
-old version of Libav, upgrade to the latest git snapshot. If you
+old version of FFmpeg, upgrade to the latest git snapshot. If you
still experience the problem, then you can report it according to the
-guidelines in @url{http://libav.org/bugreports.html}.
+guidelines in @url{http://ffmpeg.org/bugreports.html}.
-@section Why doesn't Libav support feature [xyz]?
+@section Why doesn't FFmpeg support feature [xyz]?
-Because no one has taken on that task yet. Libav development is
+Because no one has taken on that task yet. FFmpeg development is
driven by the tasks that are important to the individual developers.
If there is a feature that is important to you, the best way to get
it implemented is to undertake the task yourself or sponsor a developer.
-@section Libav does not support codec XXX. Can you include a Windows DLL loader to support it?
+@section FFmpeg does not support codec XXX. Can you include a Windows DLL loader to support it?
No. Windows DLLs are not portable, bloated and often slow.
-Moreover Libav strives to support all codecs natively.
+Moreover FFmpeg strives to support all codecs natively.
A DLL loader is not conducive to that goal.
-@section My bug report/mail to libav-devel/user has not received any replies.
+@section My bug report/mail to ffmpeg-devel/user has not received any replies.
Likely reasons
@itemize
@item We are busy and haven't had time yet to read your report or
investigate the issue.
-@item You didn't follow @url{http://libav.org/bugreports.html}.
+@item You didn't follow @url{http://ffmpeg.org/bugreports.html}.
@item You didn't use git master.
@item You reported a segmentation fault without gdb output.
@item You describe a problem but not how to reproduce it.
@@ -55,10 +55,10 @@ libav* from another application.
@item You speak about a video having problems on playback but
not what you use to play it.
@item We have no faint clue what you are talking about besides
-that it is related to Libav.
+that it is related to FFmpeg.
@end itemize
-@section Is there a forum for Libav? I do not like mailing lists.
+@section Is there a forum for FFmpeg? I do not like mailing lists.
You may view our mailing lists with a more forum-alike look here:
@url{http://dir.gmane.org/gmane.comp.video.ffmpeg.user},
@@ -123,8 +123,9 @@ problem and an NP-hard problem...
@section ffmpeg does not work; what is wrong?
-Try a @code{make distclean} in the ffmpeg source directory before the build. If this does not help see
-(@url{http://libav.org/bugreports.html}).
+Try a @code{make distclean} in the ffmpeg source directory before the build.
+If this does not help see
+(@url{http://ffmpeg.org/bugreports.html}).
@section How do I encode single pictures into movies?
@@ -272,7 +273,7 @@ material, and try '-top 0/1' if the result looks really messed-up.
@section How can I read DirectShow files?
-If you have built Libav with @code{./configure --enable-avisynth}
+If you have built FFmpeg with @code{./configure --enable-avisynth}
(only possible on MinGW/Cygwin platforms),
then you may use any file that DirectShow can read as input.
@@ -285,7 +286,8 @@ Just create an "input.avs" text file with this single line ...
ffmpeg -i input.avs
@end example
-For ANY other help on Avisynth, please visit @url{http://www.avisynth.org/}.
+For ANY other help on Avisynth, please visit the
+@uref{http://www.avisynth.org/, Avisynth homepage}.
@section How can I join video files?
@@ -368,11 +370,11 @@ examining all of the vbv_delay values and making complicated computations."
@chapter Development
-@section Are there examples illustrating how to use the Libav libraries, particularly libavcodec and libavformat?
+@section Are there examples illustrating how to use the FFmpeg libraries, particularly libavcodec and libavformat?
-Yes. Read the Developers Guide of the Libav documentation. Alternatively,
+Yes. Read the Developers Guide of the FFmpeg documentation. Alternatively,
examine the source code for one of the many open source projects that
-already incorporate Libav at (@url{projects.html}).
+already incorporate FFmpeg at (@url{projects.html}).
@section Can you support my C compiler XXX?
@@ -383,14 +385,14 @@ with @code{#ifdef}s related to the compiler.
@section Is Microsoft Visual C++ supported?
No. Microsoft Visual C++ is not compliant to the C99 standard and does
-not - among other things - support the inline assembly used in Libav.
+not - among other things - support the inline assembly used in FFmpeg.
If you wish to use MSVC++ for your
project then you can link the MSVC++ code with libav* as long as
you compile the latter with a working C compiler. For more information, see
-the @emph{Microsoft Visual C++ compatibility} section in the Libav
+the @emph{Microsoft Visual C++ compatibility} section in the FFmpeg
documentation.
-There have been efforts to make Libav compatible with MSVC++ in the
+There have been efforts to make FFmpeg compatible with MSVC++ in the
past. However, they have all been rejected as too intrusive, especially
since MinGW does the job adequately. None of the core developers
work with MSVC++ and thus this item is low priority. Should you find
@@ -398,22 +400,32 @@ the silver bullet that solves this problem, feel free to shoot it at us.
We strongly recommend you to move over from MSVC++ to MinGW tools.
-@section Can I use Libav or libavcodec under Windows?
+@section Can I use FFmpeg or libavcodec under Windows?
-Yes, but the Cygwin or MinGW tools @emph{must} be used to compile Libav.
-Read the @emph{Windows} section in the Libav documentation to find more
+Yes, but the Cygwin or MinGW tools @emph{must} be used to compile FFmpeg.
+Read the @emph{Windows} section in the FFmpeg documentation to find more
information.
+To get help and instructions for building FFmpeg under Windows, check out
+the FFmpeg Windows Help Forum at
+@url{http://ffmpeg.arrozcru.org/}.
+
@section Can you add automake, libtool or autoconf support?
No. These tools are too bloated and they complicate the build.
@section Why not rewrite ffmpeg in object-oriented C++?
-Libav is already organized in a highly modular manner and does not need to
+FFmpeg is already organized in a highly modular manner and does not need to
be rewritten in a formal object language. Further, many of the developers
favor straight C; it works for them. For more arguments on this matter,
-read "Programming Religion" at (@url{http://www.tux.org/lkml/#s15}).
+read @uref{http://www.tux.org/lkml/#s15, "Programming Religion"}.
+
+@section Why are the ffmpeg programs devoid of debugging symbols?
+
+The build process creates ffmpeg_g, ffplay_g, etc. which contain full debug
+information. Those binaries are stripped to create ffmpeg, ffplay, etc. If
+you need the debug information, use the *_g versions.
@section I do not like the LGPL, can I contribute code under the GPL instead?
@@ -431,16 +443,21 @@ the compilation failure then you are probably not qualified for this.
@section I'm using libavcodec from within my C++ application but the linker complains about missing symbols which seem to be available.
-Libav is a pure C project, so to use the libraries within your C++ application
+FFmpeg is a pure C project, so to use the libraries within your C++ application
you need to explicitly state that you are using a C library. You can do this by
-encompassing your Libav includes using @code{extern "C"}.
+encompassing your FFmpeg includes using @code{extern "C"}.
See @url{http://www.parashift.com/c++-faq-lite/mixing-c-and-cpp.html#faq-32.3}
+@section I'm using libavutil from within my C++ application but the compiler complains about 'UINT64_C' was not declared in this scope
+
+Libav is a pure C project using C99 math features, in order to enable C++
+to use them you have to append -D__STDC_CONSTANT_MACROS to your CXXFLAGS
+
@section I have a file in memory / a API different from *open/*read/ libc how do I use it with libavformat?
You have to implement a URLProtocol, see @file{libavformat/file.c} in
-Libav and @file{libmpdemux/demux_lavf.c} in MPlayer sources.
+FFmpeg and @file{libmpdemux/demux_lavf.c} in MPlayer sources.
@section I get "No compatible shell script interpreter found." in MSys.
diff --git a/doc/fate.txt b/doc/fate.txt
index b23d3f6a64..6ca302c024 100644
--- a/doc/fate.txt
+++ b/doc/fate.txt
@@ -1,19 +1,19 @@
FATE Automated Testing Environment
FATE provides a regression testsuite that can be run locally or configured
-to send reports to fate.libav.org.
+to send reports to fate.ffmpeg.org.
In order to run, it needs a large amount of data (samples and references)
that is provided separately from the actual source distribution.
Use the following command to get the fate test samples
-# rsync -aL rsync://fate-suite.libav.org:/fate-suite/ fate-suite
+# make fate-rsync SAMPLES=fate-suite/
To inform the build system about the testsuite location, pass
`--samples=<path to the samples>` to configure or set the SAMPLES Make
variable or the FATE_SAMPLES environment variable to a suitable value.
-For information on how to set up FATE to send results to the official Libav
+For information on how to set up FATE to send results to the official FFmpeg
testing framework, please refer to the following wiki page:
http://wiki.multimedia.cx/index.php?title=FATE
diff --git a/doc/ffmpeg-mt-authorship.txt b/doc/ffmpeg-mt-authorship.txt
new file mode 100644
index 0000000000..d8c405f948
--- /dev/null
+++ b/doc/ffmpeg-mt-authorship.txt
@@ -0,0 +1,4561 @@
+This file lists authorship of commits that have been merged from
+ffmpeg-mt. These commits where not classically merged because this
+would have pulled in duplicated history of all commits in ffmpeg.
+Which a majority of developers opposed.
+
+
+commit 002a0939cdf01faa8270d41b3045c08ac12d8975
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Feb 20 20:24:36 2010 -0500
+
+ Update todo
+
+commit 0040d6f2ba7189ca9bab4cf17c0d150416391dec
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Jan 24 18:33:16 2010 -0500
+
+ Remove a malloc() per frame by keeping an array of 32 buffers.
+
+ Requested in original review. Should be slightly faster but does
+ have a 32-element linear search (since buffers are freed out of order).
+
+ Introducing array_next_nonzero or something would speed up this
+ and h264 decoding.
+
+commit 00425e98fba903dceecb89763b57b8f3b7a1abf3
+Merge: 20997d6 e320c22
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Jul 2 04:59:42 2009 -0400
+
+ Merge mainline.
+
+ Having to move the setting of key_frame confused me for far too
+ long.
+
+commit 0097d3b01e33d1e0f636a19778a0435a730d4590
+Merge: 9e981c8 44c4fd1
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Sep 9 19:19:34 2010 -0400
+
+ Merge mainline and libswscale.
+
+ Another one coming after h264 is converted to yasm.
+
+ Conflicts:
+ libavcodec/avcodec.h
+
+commit 00bbca77f3fe0960cbf0986ea214ce022204837c
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Jan 16 02:18:12 2011 -0500
+
+ h264: Early-exit condition for await_references()
+
+ Saves even more zero checking in refs[][], although it still leaves many
+ useless checks when nrefs[i]>1, because the array indexes are scattered.
+
+ About ~.8% faster decoding.
+
+commit 00c4b0bb5a7801d14627015d38762ec314639d3d
+Merge: 63d086d feadf1b
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Fri Mar 13 23:50:33 2009 -0400
+
+ Merge mainline.
+
+ Conflicts:
+ libavcodec/avcodec.h
+ libavcodec/h263.c
+ libavcodec/h263dec.c
+ libavcodec/h264.c
+ libavcodec/mpeg12.c
+ libavcodec/mpegvideo.c
+ libavcodec/options.c
+ libavutil/log.c
+
+commit 01006069782b1b8fe0bfe0eabe4876062e057c11
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Jan 13 01:30:01 2009 -0500
+
+ Fix possibly not allocating obmc_scratchpad with PAFF/weighted prediction
+
+commit 011a76824f384a315ce4b0474a2811d463b5746b
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Sep 1 00:40:40 2008 -0400
+
+ Whitespace and variable name cosmetics for clarity.
+
+commit 02376cec6531a931330798af67c62a029a3435a1
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Jun 11 14:40:27 2009 -0700
+
+ Normalize how decode_postinit() is called.
+
+ Move it next to the hwaccel call to save an if statement.
+
+commit 031abc50708c616058020dcf7a1b62bc9b895446
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Fri Aug 22 20:43:38 2008 -0400
+
+ Improve comments in thread.h
+
+commit 032432ad56fd88a7e9ba6ce9ccd39925854b027a
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Feb 20 20:48:10 2010 -0500
+
+ Remove FF_THREAD_DEFAULT.
+
+ It obviously makes no sense to define the default in a public header.
+
+commit 03980f22907206b52e64439ebcc4445719801035
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Fri Jul 11 17:22:22 2008 -0400
+
+ Mark functions inline to avoid unused function warnings.
+
+commit 0488ed2d9ff609ec4a6be008c81603b62ce67785
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed Jun 4 15:55:00 2008 -0400
+
+ Align the stack in decode_frame_thread.
+
+commit 0553196aa797d58f0687890c66e1b1cdfa52f419
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed May 28 00:44:13 2008 -0400
+
+ Add the frame-threading support code.
+
+commit 056dce6c969acec1224eaa9fc73d930d1e56b299
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Fri Aug 15 16:44:33 2008 -0400
+
+ h264: Redo finding the output frame during header parsing after merging mainline.
+
+ This works with PAFF and CODEC_FLAG2_CHUNKS, though the second is useless and should be removed.
+
+commit 05a3af85edd15fef223f0376d3241cc5c7aa3ed5
+Merge: 8ba50a9 fa43cf8
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Apr 19 02:41:54 2010 -0400
+
+ Merge mainline.
+
+ Conflicts:
+ libavcodec/avcodec.h
+ libavcodec/h264.c
+
+commit 05e37cada02dc1ac58e7ce93418cbf33e3a09ad6
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue May 27 21:00:34 2008 -0400
+
+ Add the AVCodec/AVCodecContext fields needed for multithreading and increment the API minor version.
+
+commit 061586a260a564080be8c1ed9af4e83888fe3543
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Sep 4 01:41:53 2008 -0400
+
+ Remove error check that can never fail.
+
+commit 06407ff8706c7fe28c5b925c4b1dd52641714cb9
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Jun 16 18:21:04 2008 -0400
+
+ Multithreading support for MPEG-1.
+
+commit 065ee0d04a6539c08bddfa1edc628906494c22f2
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Nov 1 12:24:37 2010 -0400
+
+ vp3: Report INT_MAX instead of height at the end of a frame
+
+ This saves having to clip to height in await_reference_row.
+
+commit 067c30c63499d5cca5613725de936fb70047aec3
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Jun 22 03:29:23 2008 -0400
+
+ Cosmetics: opening function braces on their own line.
+
+commit 06ac5ac98dbf03889eb7cccf67fe0cb95615613d
+Merge: febe154 987789a
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Jun 20 04:29:03 2010 -0700
+
+ Merge mainline.
+
+ Document ONLY_IF_THREADS_ENABLED along the way.
+
+ Conflicts:
+ libavutil/internal.h
+
+commit 07474003407915e5462ed3582a1dae8baa06f296
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed Jun 10 11:25:48 2009 -0700
+
+ Move frame_thread_init() down to avoid prototyping its callees.
+
+commit 076bf916d79c39ec055a53f2ee5eadf20c21b988
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Aug 25 14:32:41 2008 -0400
+
+ Increase max delayed buffers for safety
+
+commit 079cd64ef92cb1670a420a16e38c645cc8f28caa
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Sep 2 11:38:29 2008 -0400
+
+ Ignore codecs returning NULL when draining frames.
+
+commit 090c1f4c99b9c5cefa3bad7698f33516baa87c6e
+Author: benoit <benoit@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
+Date: Tue Nov 6 13:08:04 2007 +0000
+
+ fix predictor initialization for adpcm-ima encoder not to lose first sample
+ in block in adpcm-ima decoder
+ Patch by Timofei V. Bondarenko: tim commit 09bb0dafa746203f98ff478a5121b3b0ffb3f46e
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Jul 22 22:20:47 2008 -0400
+
+ Switch from MB row to pixel row precision for h264 progress.
+
+ This makes it easier to think about interlacing and the deblock filter, and also fixes decoding entirely.
+
+commit 0a51c1e9ebf09d302e44daaca3147e7cca2f0457
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Jun 3 16:04:31 2008 -0400
+
+ Use threading macros in mpeg12.c.
+
+commit 0ac282b447075a0645036fba56d2881bbcc8f471
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Jan 17 03:44:26 2011 -0500
+
+ Update multithreading.txt for thread_safe_callbacks and pkt_dts
+
+commit 0b64ceb6b15560313d0a6ac7cffe9270d7b8e0e8
+Merge: 9ec9f08 e220e91
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Aug 10 03:22:51 2010 -0700
+
+ Merge mainline.
+
+ Conflicts:
+ libavcodec/avcodec.h
+
+commit 0b8add0862f841dfc8dbbc8d89dfb3712ce3a698
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Aug 18 16:47:21 2008 -0400
+
+ Allow avcodec_default_release_buffer to be called after avcodec_default_free_buffers.
+
+commit 0b8c3d23339b5f646ae702f30141e223596f9ff9
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Jul 27 21:55:53 2008 -0400
+
+ Reindent.
+
+commit 0be0d5714347f63b0e391ad3e9202f9d5107bb5f
+Merge: f550857 8c00628
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Mar 28 03:40:27 2010 -0400
+
+ Merge mainline.
+
+commit 0c73945d0cc40a6ade8ca78dfa0d9bea178f4743
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Aug 19 01:07:17 2008 -0400
+
+ Clarify comment for new AVFrame members
+
+ They are set by libavcodec even if they aren't used for anything useful ATM.
+
+commit 0cac0f3bd81287db20bbbae5aaff22e381e09663
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Jul 13 02:40:22 2008 -0400
+
+ Add report/await_decode_progress for progressive H264
+ Multithreading works with no visible problems for progressive sequences, but there is still some problem causing framecrc differences.
+ 1 thread - 99% cpu 14s
+ 2 threads - 183% cpu 8.6s
+
+commit 0cae6d85e8a33b826611ced69902f2a4d16f0c7a
+Author: benoit <benoit@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
+Date: Fri Jun 1 12:03:33 2007 +0000
+
+ A bit more clear FAQ 1.2
+ Patch by V
+�commit 0d25fc9993407335bc98b91296f9f78b634dd8a0
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Jun 24 21:39:39 2008 -0400
+
+ Remove newly-duplicated memset().
+
+commit 0e41f7596f06a758c0f1cb9e48e67ef896c5c05a
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Fri Jul 11 18:09:02 2008 -0400
+
+ Reindent.
+
+commit 0ef99ed28b24757a30b1e805f2ff1ea6d90b9b71
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Jan 25 03:17:46 2010 -0500
+
+ Remove item from todo
+
+commit 0fad6cca0a7e34dfa62c3934eb5316e2c9649e66
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Jul 22 01:00:07 2008 -0400
+
+ Fix height passed to ff_draw_band for interlaced H.264.
+
+ Without this, it passes y 0 h 16, y 32 h 16, etc.
+
+commit 0fb994fbdbf4f985ec9c0d5a681e7a5bf620a765
+Merge: 5eb0c64 ace7af3
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed Jan 20 01:58:15 2010 -0500
+
+ Merge mainline.
+
+ This was done by hand since git can't track the h264/h263 decoder
+ splits properly.
+
+ Conflicts:
+ libavcodec/avcodec.h
+ libavcodec/h263.c
+ libavcodec/h263dec.c
+ libavcodec/h264.c
+
+commit 0ff629947b15955603cdb7978770ca64c2323262
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Jun 18 05:09:01 2009 -0400
+
+ Don't call report_field_progress for non-referenced H264 frames.
+
+commit 111fa56db1bfefc245c499f465783a5abc04f7c2
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Jul 19 00:12:00 2008 -0400
+
+ Set start/end_mb_y properly in MpegEncContext.
+
+commit 115adc279240b6c7155781b5a16177a140eaad4f
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Jun 21 23:10:18 2008 -0400
+
+ Add an update_context for codecs that just use MpegEncContext.
+
+commit 116ca147f03ca02b55c2fceef7b82c1b251b32f6
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Aug 16 14:10:31 2008 -0400
+
+ Merge fallout: move AVCodec additions back to the end of the struct
+
+commit 11b1a8ee92128524a3259903c28da54ffd9a60fa
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun May 30 10:02:16 2010 -0700
+
+ Update todo.
+
+ I appear to have fixed the bug (the problem doesn't show in test.sh
+ anymore). Of course, there might be more.
+
+commit 120d790a3918f77444eed295aec6d8c34e4b532a
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Jul 17 18:00:07 2008 -0400
+
+ Simplify draw_edges changes and handle interlacing properly.
+
+commit 1239bcba12d0c57005ae59405e8b080ac3c7bd65
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Aug 18 18:59:29 2008 -0400
+
+ Simplify: store FrameThreadContext in the user's context.
+
+commit 1292a1840bb5319f1438b63b7be35363ba4fe5b6
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Jan 13 01:33:47 2009 -0500
+
+ Copy width/height between thread contexts for all codecs.
+
+ This makes it user-visible and fixes compatibility with
+ bad demuxers that don't set it in avctx.
+
+commit 12c5de8ead7c7a1b4c03eb095a2db4357aa2538d
+Author: benoit <benoit@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
+Date: Thu Jan 3 08:39:38 2008 +0000
+
+ Make filterDelimiters and optionDelimiters two static constant array of
+ characters, should move them to .rodata.
+ Patch by Diego 'Flameeyes' Petten
+� flameeyes commit 1327c17ca423f248dbce8172476dd69208f7d74b
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat May 23 21:52:24 2009 -0400
+
+ Stopgap hack: don't crash with size-changing streams+frame threads
+
+ MPEG1 and H.264 need their own checks, otherwise they immediately
+ deallocate shared data and crash. Another check is added to get_buffer
+ to cover remaining codecs (although it may not actually do this).
+
+ This currently involves ugly code duplication, which can hopefully
+ be eventually removed. Unfortunately this is already not handled
+ well on mainline (such as in the previous commit).
+
+commit 138ec8aad228862d58582aa4bbd367b7fa7b8d81
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Jul 24 16:06:17 2008 -0400
+
+ Factor out copying picture pointers in update_context.
+
+commit 13c48792ac24329c9055f6e98b5e61c278f1aa57
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Mar 9 00:02:20 2010 -0500
+
+ Fix wrong timestamps with -threads 2 and BBB 1080p Theora
+
+ It was caused by adding thread delay to has_b_frames.
+ -threads 2 -> has_b_frames 1 -> "delay==1" is true and the
+ "invalid dts/pts combination" was triggered. Not sure about this fix,
+ but I think it's harmless.
+
+commit 141516ca4f2b0008539ceeb70b46ebb6cfe4a1c0
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Jun 15 17:44:29 2008 -0400
+
+ Cosmetics: use USE_ macro.
+
+commit 14476d56276a77a237834e88b28427fe491ac689
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Aug 16 14:11:41 2008 -0400
+
+ Correct AVCodec member comments
+
+commit 14bdf768314413a099fe570891761360733b148c
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Mar 9 01:15:03 2010 -0500
+
+ Update sws.
+
+commit 14df94ceacecf041d33b8600bc9097d4befd79dd
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Feb 14 23:57:37 2010 -0500
+
+ Add a convenience function for avoiding deadlocks with decoder errors
+
+commit 156f6ba4db96f57c3c105b71986acaa9be13d5ab
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Aug 17 00:19:10 2008 -0400
+
+ Update todo
+
+commit 16343b25d2ffc7c18a00ec62db8e76d7f8217de5
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Feb 20 22:39:05 2010 -0500
+
+ Rewrite comments for new codec callbacks
+
+commit 16b71c003150c3a44135ffa1bbc870ea43c15f7a
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Dec 18 14:37:04 2008 -0500
+
+ Some todo entries I forgot to add
+
+commit 16bde8c7df438f5283de102e3c872ef309a8d0b5
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Jun 5 00:11:43 2008 -0400
+
+ Implement avcodec_flush_buffers for multithreaded codecs.
+
+commit 17b3c2a080f7ec1f548494e0e2b905ad0e2690c0
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Aug 18 20:36:54 2008 -0400
+
+ Clarify use of is_copy
+
+commit 17d7a98c7aadc2be1ceadf875ae2ca71b08a5611
+Merge: 0097d3b 981f8d0
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed Sep 29 22:55:44 2010 -0400
+
+ Merge mainline.
+
+ Fix misplaced lowres check from previous merge. (or maybe it was fine?)
+
+ Conflicts:
+ libavcodec/avcodec.h
+ libavcodec/utils.c
+
+commit 17dcbec74c0630e44029dd5e4efd8f9bb2ddee13
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Fri Jul 24 16:51:14 2009 -0400
+
+ Fix typo in huffyuv, broke mt decoding with newer huffyuv versions.
+
+commit 17ef916da54e5cbaf2ce97cba565ba4730dcd847
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue May 11 14:39:44 2010 -0400
+
+ Cosmetics: remove stray spaces in pthread.c
+
+commit 1846cc0549bf3d45fb2a5a2152b7335c794146e8
+Merge: 5323bc6 cd23ede
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Mar 8 04:30:32 2010 -0500
+
+ Merge mainline.
+
+ The VP3 decoder has been heavily changed upstream and this commit
+ removes mt optimizations. They will be readded later.
+
+ Conflicts:
+ libavcodec/avcodec.h
+ libavcodec/h264.c
+ libavcodec/h264.h
+ libavcodec/h264_direct.c
+ libavcodec/vp3.c
+
+commit 1878dce0e65b2fab94612c950fac51e3de741636
+Merge: b7d1826 2b13612
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun May 24 01:37:21 2009 -0400
+
+ Merge mainline.
+
+commit 1884de3ffb775bb23cbfbf977ea48841c2b2ae16
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Fri May 8 00:15:50 2009 -0400
+
+ Correct comment about decoding delay.
+
+commit 18893e1423c3d8a65ca753806638ac160fefe342
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Oct 23 18:13:56 2010 -0400
+
+ Add a -vsync test to test.sh.
+
+ The files x-1-vsync.txt and x-3-vsync.txt should have the same MD5.
+ Even more ideally, all files should have the same MD5, but it's not our problem if they don't.
+
+ h264 and theora pass, didn't test others.
+
+commit 18dc6b6010200c45827d14594a5d7b7b2b28d8e0
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed Aug 6 20:31:04 2008 -0400
+
+ Move ff_frame_thread_init above its uses and make it static since it has only one caller.
+
+commit 190d65b24795208e30c06369e34769ffeb9b5cc8
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Aug 24 01:31:00 2008 -0400
+
+ Add a longer comment for update_context
+
+commit 19b159260eb5eddfd296cac179d59ba218f881ac
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Fri Jan 21 01:22:43 2011 -0500
+
+ Adopt pkt_pts/pkt_dts in lavc clients
+
+ This makes DTS reliable with threads.
+
+commit 1a0d8d0cd0d7d0dc44d1747b2c8c93c73bc09cd8
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Jan 4 03:59:20 2010 -0500
+
+ Note in todo that 'make test' doesn't pass ATM.
+
+ Also note a harmless warning emitted, which I haven't
+ though of a good fix for yet.
+
+commit 1a216093ed2f201814287a32b5d8f22781c6d8d1
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Aug 25 01:02:29 2008 -0400
+
+ Comment another strange line
+
+commit 1a4740fed38a69202c762e3cd786dd3c7c23dd40
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Jan 15 17:02:46 2011 -0500
+
+ Make ARM asm #error out, since the offset values are out of date here
+
+commit 1ac02d2ff0dd39d8baf68cf7e0490de4db9b88cc
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Fri Jul 10 14:24:40 2009 -0400
+
+ Fix the error in avcodec_thread_init to actually not do anything.
+
+commit 1b735c493b0fe8c1aaff3d06214c24e8556b111c
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Aug 25 14:40:54 2008 -0400
+
+ Remove some context variable copies which were overwriting user settings
+
+commit 1b755181905bed35b2edd723c137b8f0af9c31c3
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Aug 23 23:14:20 2008 -0400
+
+ Add a FIXME for PAFF
+
+commit 1c187ba01c332b3d99681cfffb90f0247a836303
+Merge: 8022069 0309093
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Nov 15 05:32:06 2010 -0500
+
+ Merge mainline.
+
+ Conflicts:
+ doc/APIchanges
+ libavcodec/avcodec.h
+
+commit 1c39407876cb6689e313ce27a51d83d77ac0c4e4
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun May 23 03:40:43 2010 -0400
+
+ Fix crash with ffplay.
+
+ Caused by the buffer functions being changed after codec init.
+
+commit 1c70dfb14a5e6e322f66d1175045eb13ac96d2f8
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Feb 20 22:10:38 2010 -0500
+
+ Rewrite thread.h comments for clarity
+
+commit 1c8037ec029ffe790b39b0cf0e67468db5f8c4a8
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Jan 25 03:59:02 2010 -0500
+
+ Fix references to renamed avail_motion() in the todo.
+
+ Delete the second entry mentioning it, since I don't think it's a
+ good idea anymore.
+
+commit 1ca44079c06a2080c2a0deb9cbc8fa757a5be540
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Jun 15 20:34:08 2008 -0400
+
+ Delete unused variables. The frame counters will stay around for now for debugging.
+
+commit 1d15df4fd2b4583d56159a7938ef3699c7f46261
+Merge: 8f759fa b3b80f1
+Author: Luca Barbato <lu_zero@gentoo.org>
+Date: Sat May 31 17:56:44 2008 +0200
+
+ Merge branch 'master' of git://git.mplayerhq.hu/ffmpeg
+
+commit 1da82befe53bc245ba94cf1012fcd0156040353c
+Author: benoit <benoit@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
+Date: Mon Jan 7 12:40:39 2008 +0000
+
+ Remove unused symbol.
+
+ Patch by Diego 'Flameeyes' Petten
+� flameeyes commit 1e8abec2eecd831c55e34c09fc9a38833d69c180
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Fri Jul 10 14:28:54 2009 -0400
+
+ Fix default value of thread_count.
+
+ Adding a flag named "threads" somehow disabled the default value
+ of the option named "threads", which allowed thread_count to be 0
+ for non-ffmpeg/ffplay clients (which don't always reset it).
+
+ Not sure why AVOption works this way.
+
+commit 1eff8ec8e1772334cd74129f8cc068483c757b40
+Author: benoit <benoit@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
+Date: Fri Aug 10 07:28:18 2007 +0000
+
+ Prefix with "opt_" the functions ffmpeg.c:show_{version,license,formats}.
+ patch by Stefano Sabatini [stefano tod sabatini-lala commit 1fae9e952cee3c499313b5a9b5c2e3dda096ee30
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Mar 10 01:44:05 2011 -0500
+
+ Delete the libswscale submodule for svn->git merge.
+
+commit 2037d9714bc51ccb57a82aba95a52a5b49bdc401
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Aug 24 21:16:50 2008 -0400
+
+ Comment this just in case someone doesn't get it
+
+commit 2063f77f904af3544021e16d6da76acf5d9beaed
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Nov 15 05:40:04 2010 -0500
+
+ Delete beosthread.c which is gone from mainline
+
+commit 207f434446b40b29311e81233167bd03de16bf0c
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed Jul 30 20:14:56 2008 -0400
+
+ Cosmetics: whitespace adjustments.
+
+commit 20997d60c8ec84dd0dd68055901e847c4b4e171a
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Jun 27 22:33:17 2009 -0400
+
+ Frame threading for VP3 [2/2].
+
+ The performance with different thread counts is different from
+ MPEG codecs; trying more or less granular synchronization would
+ be interesting.
+
+commit 20a85842c46b547331c5884e015dd781108c6d17
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Oct 11 16:43:39 2008 -0400
+
+ Save PAFF vs MBAFF information for pictures.
+
+ This already exists differently in mainline, but this way is more useful
+ since MPEG-2 has field pictures but not MBAFF.
+
+commit 20d6c336b37a7bf7313865a397f19ef33595adf8
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Dec 23 17:49:51 2008 -0500
+
+ More todo entries
+
+commit 210b4a63100e5f4ba5ab23e84460614ca59b7817
+Merge: fc957c7 59b0bd5
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon May 24 22:26:23 2010 -0400
+
+ Merge mainline.
+
+commit 21cede4223d4bcfcc0f6a91bbc84354238201fea
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Apr 19 03:30:45 2010 -0400
+
+ Fix possible overlapping memcpy()+crash at the end of decode
+
+ Increasingly dissatisfied with having to do this.
+
+commit 22a56df3f22e5c32c5f2fd06db8d644157da1877
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Jul 14 23:12:17 2008 -0400
+
+ Remove dead code.
+
+commit 22d953bd1ef2b61ec272be03aa8f81587e0ac046
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed Jun 25 04:54:34 2008 -0400
+
+ Remove zeroing mbskip_table
+ It's unnecessary with the previous commit.
+
+commit 22e9455a663acc4d34f76130f2603b41b3940b9e
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Fri Aug 22 16:25:45 2008 -0400
+
+ Comment and rename context variables in pthread.c.
+
+commit 2331711a5ff0908a37005a0e500804a5a8a61e5d
+Author: Michael Niedermayer <michaelni@gmx.at>
+Date: Wed Apr 6 00:15:42 2011 +0200
+
+ Fix ffmpeg-mt fixme in h264
+
+ Uncommenting this code no longer seems to cause valgrind problems or crashes.
+ Behavior is unchanged.
+
+commit 234887b836f9b0306388d20499c8025ac916e11b
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Aug 19 21:17:15 2008 -0400
+
+ Normalize if (err)
+
+commit 2412ad4778734a19638c997d5567f5d53d135a9a
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Jan 17 15:57:00 2011 -0500
+
+ pthread: Document release_delayed_buffers
+
+commit 24345e509df0b92a3592cfb15db12b1aecd78ffe
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Aug 26 02:26:07 2008 -0400
+
+ Fix spelling and rewrap multithreading.txt to the right number of columns.
+
+commit 2485cfd74cf5012fdce8582b7094ddbd09bd70c9
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun May 24 03:38:22 2009 -0400
+
+ 10l: pred_direct_motion fix missed several mb_type accesses
+
+ I have not proven this correct yet; it's not too hard with some work
+ (record the last row accessed and waited for, and make sure they
+ correspond). Therefore, I suspect it still isn't correct, since
+ framecrc still shows mismatches. It does fix the worst visible
+ errors, though.
+
+commit 25a2f117ad6d6dc2592e77369bed23e53241b218
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Fri Jan 21 03:24:41 2011 -0500
+
+ Cosmetic: shorter line variable declaration
+
+commit 26151296236e0381c1c40e0d97ead8c5ab26b57c
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Nov 2 02:33:12 2010 -0400
+
+ vp3: Lift up loop-invariant checks and simplify away 'border' which == 1
+
+commit 27026500c9a25bf409b55186d9bceada4bf2ba5c
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Jul 19 02:09:18 2008 -0400
+
+ Fix mpegvideo crashing without --enable-pthreads due to the number of thread_contexts changing.
+
+ -threads X no longer has any effect since all threading code is now gone without an actual threading library.
+ I think this is a nice minor size optimization, but if it's necessary to keep regression tests working with frame-threaded encoding I'll have to revisit it.
+
+commit 2742b2a142ff98e4611f96ddf47ab5a5233f4692
+Author: benoit <benoit@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
+Date: Thu Jan 10 10:15:07 2008 +0000
+
+ Reduce the size of the replaceTable entries.
+ Patch by Diego 'Flameeyes' Petten
+� flameeyes commit 287e761820e85514e00eb6c5958496ecb61825cb
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Dec 24 22:21:37 2009 -0500
+
+ Fix error return being ignored in VP3 allocate_tables().
+
+ Based on a patch by Yuriy M. Kaminskiy.
+
+commit 29c2b04f5074e49aa63cf50fb90e3a51e853ad9d
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Apr 4 00:35:28 2009 -0400
+
+ More todos related to init api
+
+commit 2a7a86a64f153befafabcbb987e2793fa4bb0e18
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Jun 27 22:17:41 2009 -0400
+
+ Split out error returns in VP3.
+
+commit 2a9b493a5a0f46f43959ce2466849dd6a6217012
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed Feb 2 02:12:29 2011 -0500
+
+ Fix memory abandonment + unnecessary realloc in mpeg4
+
+ Fixes Sample1.mkv from ffms running out of address space (and more).
+ Note the file doesn't display properly in ffplay, so there's still bugs left.
+
+commit 2ae310bf292c1f34be006e9be7fbceb4c0f1b068
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Jun 3 04:20:42 2008 -0400
+
+ Comment next_*_index.
+
+commit 2b74560715c3d4f331156d8745ce801c1de4d467
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Nov 18 14:31:17 2008 -0500
+
+ Revert accidental warning change
+
+commit 2b7d2acccb45e89bfc77564bcdaee68fcb4ac4c7
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Feb 1 23:05:43 2011 -0500
+
+ Revert 99ed04d4d7b7183a4d0a1b8833eee3b506e13ff0
+
+ Broke big_buck_bunny_720p_stereo.ogg with 2 threads.
+
+commit 2bbb64dae018cbb09ea47a6bdcb184f551136c26
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed Dec 15 16:15:21 2010 -0500
+
+ Fix definition of CODEC_CAP_FRAME_THREADS to not conflict.
+
+commit 2bc23e009291d727eed7a4f803a2793f5fa715b0
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Aug 26 03:03:38 2008 -0400
+
+ Update avcodec.h comments
+
+commit 2bcbffdbf53bd2918ba6ade66d12fb97021032c7
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Jun 15 20:26:59 2008 -0400
+
+ Combine all the condition variables into one.
+
+commit 2beb042a202d00dbb2baef3970f058994aeec027
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Aug 23 19:32:56 2008 -0400
+
+ Split thread_algorithm into two more sanely defined variables.
+
+ Also improves correctness in some ways.
+
+commit 2c0e016af759adfdc34a6a1b8592ec0a1ef56da9
+Merge: d5ea5fc c2c8552
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu May 7 17:36:13 2009 -0400
+
+ Merge mainline.
+
+ Uses the minimal changes to get the new AVPacket API working.
+
+ Conflicts:
+ libavcodec/avcodec.h
+ libavcodec/h264.c
+ libavcodec/mimic.c
+ libavcodec/options.c
+ libavcodec/utils.c
+
+commit 2c3cd96bf1cb1757407c973416f7928d492e2156
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Aug 18 22:59:19 2008 -0400
+
+ Cosmetic rearranging of MPEG update_context functions
+
+commit 2cb0db5ba7d77ed8180f0551462c836047ea262e
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Jun 18 16:19:33 2009 -0400
+
+ Fix invalid Mimic stream handling + frame threads
+
+ Releasing a frame after frame_setup_done isn't allowed, and
+ it must do report_decode_progress as if it was finished.
+
+commit 2d0370118996148f1c64b9c6b4a2ff632fcaf609
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Aug 31 03:56:04 2008 -0400
+
+ Add fixme for copying packet data.
+
+commit 2e121780400cb6630a66a0b7bd3fe84ad539b882
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Fri Jul 11 18:21:08 2008 -0400
+
+ Increase the released buffer size to 16. H264 can release this many at an IDR, can other codecs have even more?
+
+commit 2e5a5baf540ae0d1ac16ae52f66254b7233aabf7
+Merge: 5d82241 31f0027
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Mar 29 04:35:46 2011 -0400
+
+ Merge branch 'master' of git://git.libav.org/libav
+
+ Conflicts:
+ libavcodec/dsputil.c
+ libavcodec/mpegvideo.c
+ libavcodec/snow.c
+ libavcodec/vp8.c
+ libavcodec/x86/dsputil_mmx.c
+
+commit 2e9d8893eac232b782b479378cf13d484ab9cc1e
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed May 28 22:49:33 2008 -0400
+
+ Add thread.h
+
+commit 2eeab8f6ad07611e46b3377ddf73e1d7f1f2bb78
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Aug 24 21:16:31 2008 -0400
+
+ General description and porting guide
+
+commit 2f1fec650f4bb351fa819fb7e11b4766a43fa30f
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Aug 19 01:20:32 2008 -0400
+
+ Simplify mimic_decode_end changes
+
+commit 2f48eac011767ba2d60329c10a22499c228a31d8
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Nov 18 15:27:24 2008 -0500
+
+ Missed fixing pthread.c in merge.
+
+commit 2f8f77021011eec5af8cab80ee7bdc574ad3f37b
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Fri Jan 21 03:01:42 2011 -0500
+
+ pthread: Style and comment nitpick for validate_thread_parameters()
+
+commit 300b5819426ed6b35aaa480502070382e5295111
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Aug 17 14:07:06 2008 -0400
+
+ Copy aspect ratio info between contexts.
+
+commit 3029628ce39e37c9ae77cb78f22ab9d4846e6610
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Aug 31 15:15:15 2008 -0400
+
+ Fix compiler warnings
+
+commit 303cd6307958792faac1ce8c8c81eea2651b002f
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Jun 19 18:31:17 2008 -0400
+
+ Use MPV_report_decode_progress in mpeg12, and call it before mb_y++.
+
+commit 30e540672df8523a47013d92592b744459040904
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Oct 13 15:00:39 2008 -0400
+
+ Make every thread lock the same buffer_mutex for get_buffer.
+
+ Otherwise it isn't actually protecting anything...
+
+commit 3106e8ebe7c55eba3e41f3a11cc23eb249a4ff3b
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Jul 14 23:09:47 2008 -0400
+
+ Always set thread_context[0] in MpegEncContext.
+ This fixes mpeg* encoders always crashing, but most of the regression tests are still failing.
+
+commit 3127a4bd6e36bb2d9cd2fe12a96fa776d94fed94
+Author: michaelni <michaelni@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
+Date: Sat Nov 2 10:47:44 2002 +0000
+
+ added BeOS net_server support (R5 network stack), basically the same
+ problems as with winsock (sockets != fd), and the broken select().
+ based on older patch by Andrew Bachmann.
+ patch by (Fran
+commit 314c2b1d2f94be3b6aca3dd1ae0f30c05f10f2ee
+Merge: 9816b66 bd8850b
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Feb 17 22:41:31 2009 -0500
+
+ Merge branch 'master' of git://git.mplayerhq.hu/ffmpeg
+
+ Conflicts:
+
+ libavcodec/avcodec.h
+ libavcodec/mimic.c
+ libavcodec/mpeg12.c
+ libavcodec/mpegvideo.c
+
+commit 314e5630e389457319ff2d11e856fab6b1d8b250
+Author: benoit <benoit@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
+Date: Mon Jan 7 12:47:14 2008 +0000
+
+ Move wmv1_scantable to .rodata section by making it an array of arrays.
+ Patch by Diego 'Flameeyes' Petten
+� flameeyes commit 31e3f669b598302b2a487dab84e08bf4d1e79983
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu May 7 18:06:52 2009 -0400
+
+ Fix mplayer patch's calculation of extra delay.
+
+ It's only (num_threads-1) frames with MT on, not num_threads.
+
+commit 31f1a603dcfe885c41d123832f102a3ccc55c6dd
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Aug 24 00:20:03 2008 -0400
+
+ Rename threading functions with 'decode' in their name
+
+commit 333777b56b942a11db5d672433357bcbbf0d6e47
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Aug 19 01:14:48 2008 -0400
+
+ Cosmetic changes to mimic
+
+commit 33bc3cc94a5a6e2679306da899afb1e0ce6b78c6
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Aug 14 14:01:15 2008 -0400
+
+ Reindent.
+
+commit 3444ffe523dd65b788791dfb2c6cbd7031cfec97
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed Aug 6 20:24:44 2008 -0400
+
+ Cosmetics: rename last_thread to prev_thread to avoid final vs. previous confusion.
+
+commit 344df336a0b5e70ef9fcea33f612f759bc045552
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Apr 19 03:31:30 2010 -0400
+
+ Reindent
+
+commit 3547c7f44108f1080f90de1844c36fb172528994
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Feb 20 19:40:48 2010 -0500
+
+ API simplification: remove ff_report/await_frame_progress()
+
+ The field variants are enough.
+ Note that mpegvideo.c thread code doesn't need to support any codecs
+ with field pictures.
+
+commit 3630d89a7bd6443f9aeda2f6997fb2ea5da5c97d
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Dec 18 12:36:20 2008 -0500
+
+ Copy dequant4/8_buffer between H264 decoding threads.
+
+ Fixes at least:
+ MSG00 ED.mkv
+ freedom EP1 sample.mkv
+ made with unknown encoders.
+
+commit 36977df5243521eaa3ab1b67f3c89d1a1ba4c8f7
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Aug 18 22:03:25 2008 -0400
+
+ Move copying idct_algo to the right place
+
+commit 379271216e0d522b675e97189ab5d4e5cf7f5f70
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Apr 19 03:35:28 2010 -0400
+
+ Update todo.
+
+commit 37b38ff868fa39f75df9c1bd543fd1c2dc7134ae
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Feb 20 20:31:16 2010 -0500
+
+ Update the comment for FF_THREAD_FRAME.
+
+commit 382e06ef4ba568c565b9d67b33b1688a32b2b80e
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue May 11 06:21:06 2010 -0400
+
+ pthread: Use av_fast_malloc to allocate the frame buffer
+
+ Also delete the FIXME; it's impossible because the AVPacket memory
+ API doesn't actually work.
+
+commit 3934d02026fb67b46441176c4160c0f854c12825
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Jul 21 18:10:58 2008 -0400
+
+ Reindent.
+
+commit 39eee0b91b9b6b75c54ff68d51ecc0ba1816c88f
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Jun 22 03:36:24 2008 -0400
+
+ Multithreading support for MPEG-4
+ This requires more parallelism barriers than usual because of the horrible skip MB structure in B-frames.
+
+commit 3ad85b1741ca6d36126bbf674f5b82d550107bae
+Merge: ff4c627 4495490
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Oct 6 16:12:06 2009 -0400
+
+ Merge branch 'master' of git://git.mplayerhq.hu/ffmpeg
+
+ Conflicts:
+ libavcodec/avcodec.h
+ libavcodec/mpegvideo_enc.c
+ libavcodec/snow.c
+ libavcodec/vp3.c
+
+commit 3afd3f52b940d0bfa756e1a7496a20d103c5a7f0
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Fri Jul 25 03:25:00 2008 -0400
+
+ Merge MPV_update_picture_pointers() into its only caller.
+
+commit 3ba8143c5da92197eb45fa120bfa95b38adfd3bf
+Author: michaelni <michaelni@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
+Date: Sat Nov 2 10:35:07 2002 +0000
+
+ added BeOS net_server support (R5 network stack), basically the same
+ problems as with winsock (sockets != fd), and the broken select().
+ based on older patch by Andrew Bachmann.
+ patch by (Fran
+commit 3bac11e47a0ec7c6036c53a1173bce276abccfeb
+Merge: 53fff22 3d42d49
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Apr 9 21:30:16 2011 -0400
+
+ Merge mainline.
+
+ Conflicts:
+ libavcodec/h264.c
+
+commit 3bef1503e0f23c0f30c2e3b2de64a9b2618807d2
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Jun 27 16:18:44 2009 -0400
+
+ Add debugging hooks to show ff_report/ff_await calls.
+
+commit 3c3a3648317737830fc863371b455624d093f8e6
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Oct 18 17:39:17 2008 -0400
+
+ Fix possible null pointer access after seek.
+
+commit 3c7a8d94b97003b118c2438343d06ad7cf26198a
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Mar 9 00:04:51 2010 -0500
+
+ Reimplement VP3 multithreading.
+
+ Synchronization is now not very fine-grained, because it reuses
+ vp3_draw_horiz_band which runs every ~64 pixel rows.
+
+commit 3cfd7b2e788c3d8e31c91ed529f3e3730f836395
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Jun 23 23:14:05 2008 -0400
+
+ Wrong kind of #if.
+
+commit 3f7521893b9072181763ea176ef8da0c0ad1922a
+Merge: ed42183 206c937
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Oct 10 01:47:32 2010 -0400
+
+ Merge mainline.
+
+ API change: CODEC_CAP_FRAME_THREADS is now defined as 0x800.
+
+ Conflicts:
+ libavcodec/avcodec.h
+
+commit 3f858091f8f3cd43f1eed396e85f6956ee5068a0
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Aug 19 02:35:52 2008 -0400
+
+ Fix losing frames at the end of an encode
+
+commit 3ffe81697018042b27a31f20c1d30c988b688d60
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Jun 12 18:22:42 2008 -0400
+
+ Reindent.
+
+commit 401a6bc7f0fe26963f63778c5092ae96c4262634
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Jun 25 19:07:58 2009 -0400
+
+ Frame threading for VP3 [1/2]
+
+ update_context function and compatibility fixes.
+
+commit 40265f10de7698bb2fe23857cf261a0f04fe18a1
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Oct 13 14:19:27 2008 -0400
+
+ Fix edge drawing for non-mod-16 files.
+
+commit 4074c8bfba918988029ce106eda3d41486f12966
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Jul 12 00:11:35 2008 -0400
+
+ Copy more MpegEncContext variables.
+ These are needed for proper DivX/H.264 decoding.
+
+commit 40ffd3a664e36f44ebdf4d2603e42c7c59502599
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Jul 23 21:40:06 2009 -0400
+
+ 100l, fix compile error introduced by automerge
+
+commit 4118a72e28be1cee657561a1f45dc3ce160dbf07
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Mar 10 02:46:14 2011 -0500
+
+ Update todo.txt
+
+commit 41e0f81a58493a0a15cb18c7ff00920f0fd124a3
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Aug 24 02:52:18 2008 -0400
+
+ Remove unneeded stubs from thread.h
+
+commit 4259f9fcf4edc5c92bc02d37d85493b3eb917075
+Merge: 2615129 fb61692
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Nov 2 02:36:20 2010 -0400
+
+ Merge branch 'master' of git://git.mplayerhq.hu/ffmpeg
+
+commit 4293f5ba301cd751257705bfe6fc8b12337dccab
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Jul 14 23:20:17 2008 -0400
+
+ Disable multithreading for packed B-frames.
+ The bitstream buffer is updated after decoding, so it has to be changed to find the frame end before starting the actual decode. Assuming that's not too slow.
+
+commit 42b521db9177ed2d4e62845659fdcd44c59757f9
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Fri May 8 00:40:57 2009 -0400
+
+ 10l: dequant_coeff must be copied along with dequant_buffer
+
+ Fixes more Blu-Ray streams which change CQM, including Slumdog
+ Millionaire.
+
+ Noticed by Haruhiko Yamagata.
+
+commit 435ace7689e2794ddbb4013de097bdaf487f7365
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Apr 9 21:47:12 2011 -0400
+
+ Update test scripts to use ffmpeg instead of ffmpeg_g
+
+commit 435adcd213762869c6a6f806481450216720b364
+Merge: 6ee99a7 11dcccd
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Mar 10 01:25:24 2011 -0500
+
+ Merge remote-tracking branch 'socrep/last_mainline_point' into last_git_point
+
+commit 451af22792e7bec6f3b347ba801ba186102a85da
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Jul 14 04:13:33 2008 -0400
+
+ Call draw_edges per-MB-row instead of per-frame when possible.
+ This is necessary for multithreading, since rows aren't complete until their edges are mirrored.
+ It should also be somewhat more cache-efficient, but I haven't benchmarked it properly yet.
+ I don't like adding new MpegEncContext variables, but edge_y lets it do the right thing wrt. error resilience and codecs that don't call ff_draw_horiz_slice.
+
+commit 452fb04633126605afbb2cd0d6383bb75fe01f38
+Author: michaelni <michaelni@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
+Date: Fri Nov 8 20:54:44 2002 +0000
+
+ ringbuffer patch by (Fran
+commit 4681ac8f618586d4a3ecb04784b9cf896d070f1b
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue May 11 14:43:29 2010 -0400
+
+ Cosmetics: vertical alignment
+
+commit 468eba33060aa87117ac6b617d4eae776951cbf6
+Merge: 3c7a8d9 aa86abc
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Mar 9 00:55:42 2010 -0500
+
+ Merge mainline.
+
+ The error condition in vp3_decode_frame was uglified to make the
+ diff simpler.
+
+ Conflicts:
+ libavcodec/vp3.c
+
+commit 46a45ad599db4037006b335fca2c7b7bed7018ab
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Aug 2 00:22:16 2008 -0400
+
+ Clear thread variables in avcodec after freeing them.
+
+commit 46b495ebc4a7fb7662580791e4ed10130b00fead
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Jun 12 17:16:31 2008 -0400
+
+ Don't allocate duplicate contexts if they're not going to be used.
+
+commit 46ec6b90e7b2d6b1d83a207025a691c56176d686
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Jun 16 18:21:04 2008 -0400
+
+ Multithreading support for MPEG-1.
+
+commit 46fc25f5c225e2f33430e31a0d0ad375455e9cef
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Nov 1 12:20:12 2010 -0400
+
+ Update todo.txt
+
+commit 473799e0c3b647d73046c3b4de30e85bf57ba610
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Aug 19 21:16:59 2008 -0400
+
+ Whitespace fix
+
+commit 47869edb7f0aede0a2bfd178ef9937e28bf8b01f
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Feb 14 23:41:12 2010 -0500
+
+ Fix buffer leak in VP3 by allowing update_context() with the same context.
+
+ I assumed update_context() would only be used to copy values, so skipped
+ calling it with duplicate parameters (during flush and free) for optimization.
+
+ But VP3's release_buffer call was moved from the end of decoding to the
+ end of update_context(), so flushing would skip releasing a frame and
+ eventually run out of buffers.
+
+ Unfortunately this makes update_context() much uglier in codecs that
+ already worked, because memcpy doesn't allow src and dst to be the same.
+
+commit 480a82da7912bc5034a4b0bc2090879920567521
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Sep 30 01:13:43 2010 -0400
+
+ Update todo.
+
+ ffplay/ffmpeg support for better a/v sync support is in progress.
+ If Theora uses PTS (I think it does), then once ffmpeg.c i
+ ready it can be submitted to mainline.
+
+commit 4845b04ed3d6bc513a272da718629d110bc8186f
+Author: benoit <benoit@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
+Date: Mon Jan 7 12:43:04 2008 +0000
+
+ Mark the tables in g726.c as constant.
+ Patch by Diego 'Flameeyes' Petten
+� flameeyes commit 485d8e9e3c5de803075c8440922e6e09b10a1e57
+Author: Alexander Strange <astrange@resnet-022-195.spsu.edu>
+Date: Sun Sep 14 20:45:58 2008 -0400
+
+ Fix ff_report_*_progress side of H264 multithreading and merge draw_horiz_band into it.
+
+commit 4874d258345ec305b0eca78c41491878d42a900d
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue May 11 14:45:39 2010 -0400
+
+ Cosmetics: reorder variable declarations
+
+commit 48d2183d902db7cc42c9f84d2bad6eccc35d0221
+Author: Ronald Bultje <rbultje@google.com>
+Date: Mon Apr 11 14:58:11 2011 -0400
+
+ Release unused pictures even when not calling ff_h264_frame_start()
+
+ Unused pictures assigned to the thread can build up and cause it to
+ run out of buffers if the thread only ever decodes bottom field pictures.
+
+commit 48d7f5a8f3f14535d74f0e4b0a736e3f5dc336b2
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Aug 18 19:58:18 2008 -0400
+
+ Factor out freeing delayed released buffers.
+
+commit 49652059c673eb977e5b69ffb0c8a543c3210e16
+Merge: a2efd25 48e59eb
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Jan 15 17:01:41 2011 -0500
+
+ Merge mainline.
+
+ Conflicts:
+ doc/APIchanges
+ libavcodec/avcodec.h
+ libavcodec/h264.c
+ libavcodec/utils.c
+
+commit 4969bb89e592c003a560e321f3cacb412a192db9
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Jul 31 14:30:40 2008 -0400
+
+ Copy avcC variables in H264Context.
+
+commit 496ec27adcef84278e650b29f4d22aba383d705a
+Author: Alexander Strange <astrange@resnet-022-195.spsu.edu>
+Date: Sat Sep 13 16:20:03 2008 -0400
+
+ Correct interlaced draw_edges.
+
+ There is still a race condition when fields are decoded in different threads,
+ so for now we pretend EMU_EDGE is set instead of using the edges.
+
+commit 498ddbb3b2d78819540c1b8fff9a2bc495a33346
+Merge: aaa05da 95b6213
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed Nov 3 18:34:04 2010 -0400
+
+ Merge mainline.
+
+ Conflicts:
+ libavcodec/avcodec.h
+
+commit 49e377f9f23904ed790e98175b1575bba6ecc6cb
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Jul 15 03:30:28 2008 -0400
+
+ Add update_context() for H.264.
+ This seems to lose reference frames for my PAFF sample, which I'll fix after I find out how PAFF works.
+
+commit 4adb7fbed7dcb12dda0f3919188334a3b96efb0a
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Aug 18 20:02:12 2008 -0400
+
+ Cosmetics: get rid of unhelpful comments, useless braces, and some whitespace/align issues
+
+commit 4af5480a021156089c193ce2215994cfd170e4e6
+Merge: 2f48eac 1bf5327
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Fri Nov 28 22:48:24 2008 -0500
+
+ Merge mainline.
+
+ Conflicts:
+
+ libavcodec/h264.c
+ libavcodec/mpegvideo_enc.c
+
+commit 4b9ce55576ab27f6a45d542bfda7c1e21fb967f8
+Merge: 1fae9e9 435adcd
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Mar 10 01:54:16 2011 -0500
+
+ Merge branch 'git_equiv_of_mainline'
+
+commit 4c726e5e30e1f48619eecbec5442acd63e895318
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed May 28 22:40:30 2008 -0400
+
+ Rename pthread.c to thread.c
+ The remaining *thread.c files will be merged into it later.
+
+commit 4c802e44f13672dd4527f51fc2f07a1e21be4a5c
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Jun 2 04:31:45 2008 -0400
+
+ Simplify ff_await_decode_progress.
+
+ Always set and allocate the progress pointer, so ff_await_decode_progress doesn't have to check for threading to be on.
+
+commit 4cdd15a3cf5dfec32ace278cd445f04130ddbee0
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Jan 15 19:26:14 2011 -0500
+
+ pthread: Call external get_buffer() on the client's thread by default
+
+ This fixes several mplayer VOs that crashed when they were called from decoding
+ threads.
+
+ Not a complete fix as mplayer still doesn't work right with draw_horiz_band()
+ being called from decoding threads, but that doesn't crash at least.
+
+commit 4d2f536b72ec9121b5afe858b69c93d9cc75f20a
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Aug 30 04:20:20 2008 -0400
+
+ Simplify draw_edges changes by removing edge_y (which is useless with slices)
+
+commit 4d8525ab388d34e128629b08ab88c6a16f3aa406
+Author: michaelni <michaelni@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
+Date: Sun Jul 21 07:59:17 2002 +0000
+
+ nanosleep patch by Fran
+commit 4edb9a7f780a6eaef36512724e6a34c3f38d67ce
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Feb 15 00:31:31 2010 -0500
+
+ Disable mpeg1 frame threading.
+
+ Seeking doesn't work (it triggers false error conditions) and it doesn't
+ pass test.sh (-threads 2-4 match but 1 doesn't somehow). Will be reenabled
+ when those are fixed.
+
+commit 4f9364563f388af84b9a02930b375ff52eee1394
+Merge: 3bac11e 347b375
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Apr 9 21:30:47 2011 -0400
+
+ Merge branch 'master' of git://git.libav.org/libav
+
+commit 4fb1fdf1ca1a48aff176b8f833ca596d245d6d36
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Jul 15 03:30:50 2008 -0400
+
+ Reindent.
+
+commit 4fb33e68ec34cbc135ce4ebb86f7e1399ba97115
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Jun 23 22:11:58 2008 -0400
+
+ Merge statements.
+
+commit 5022ee29ac6d4b2ee992115c3bf997e7bd1ab7a4
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Jun 5 20:30:27 2008 -0400
+
+ Add delayed_release_buffer for handling reference frames.
+
+commit 5066a4656963dd3b4e847a540353bf71d318de14
+Author: michaelni <michaelni@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
+Date: Tue Nov 5 00:07:05 2002 +0000
+
+ lrintf detection (based upon a patch by Fran
+commit 50d1ce2db57e39b6115642d3c4397e9f67f758e3
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun May 24 00:08:03 2009 -0400
+
+ Call codec init at a more reasonable time.
+
+ Previously it was delayed until the first decode_video() call,
+ but it can be moved into avcodec_thread_init(). This makes pix_fmt
+ available to clients after init again, which should make them happier.
+
+commit 50eaf4979eb085e2c58c06912bb0c885404d4470
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Aug 28 17:39:28 2008 -0400
+
+ Simplify changes to non-pthreads and don't call thread_init from open if it was already called.
+
+ This will cause an assert failure if clients call thread_init again after open.
+
+commit 51428e56c71512a57f81d85acee3ced7cc0d2983
+Merge: 00425e9 03586fd
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Jul 4 16:41:31 2009 -0400
+
+ Merge branch 'master' of git://git.mplayerhq.hu/ffmpeg
+
+commit 517d68c2642aee3c14fc71031c1e44c0803a664e
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Mar 8 04:43:06 2010 -0500
+
+ h264: change the definition of col_fieldoff to avoid divisions
+
+commit 5186276ed120294fb6a4f2cf5a40d5019012482f
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Jan 16 22:01:18 2011 -0500
+
+ libavfilter input_get_buffer is thread-safe
+
+ Slightly faster ffplay playback
+
+commit 51ead6d2c40c5defdd211f435aec49b19f5f6a18
+Author: Ronald Bultje <rbultje@google.com>
+Date: Mon Apr 11 10:14:38 2011 -0400
+
+ h264: Fix decoding race condition with PAFF
+
+ A thread can release a Picture and immediately reuse the same Picture
+ for a different frame. This is fine, unless the picture released was
+ a field-picture. In that case, there may be a future thread still decoding
+ the second field of the picture, and reusing it overwrites the shared fields
+ in the Picture.
+
+ Fixed by tracking ownership of Pictures and allowing it to be reassigned
+ to the second thread's context.
+
+ Fixes conformance sample HPCAMAPALQ_BRCM_B.264.
+ vsync still fails, and therefore FATE does as well.
+
+commit 521f07e3cf2dfb9b0473027ae2fbb6bd4f203ce4
+Merge: 7d0709e 4a8d06e
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun May 31 00:08:08 2009 -0400
+
+ Merge mainline.
+
+ Conflicts:
+ libavcodec/avcodec.h
+
+commit 52b214211060b56e7aac6b9743fa27bc79f789d1
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed May 28 02:15:47 2008 -0400
+
+ Enable multithreading for Mimic.
+
+commit 5323bc6e8adbff2b6849a08e9e071f22241fd807
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Feb 20 22:48:51 2010 -0500
+
+ Cosmetics: add () to function name
+
+commit 5340d1ffae10b1545d88b9dd8ca86a5a3aaffca7
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed May 28 02:15:47 2008 -0400
+
+ Enable multithreading for Mimic.
+
+commit 534516ac79adc69d8773ff934955532a92db2cf1
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Aug 16 00:01:07 2008 -0400
+
+ Fix a memory corruption bug in update_context and reenable H264 multithreading.
+
+commit 535de6d374ab6b06041f5e3cb392327abd2ce054
+Merge: 6abde3d cc8161e
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue May 11 04:08:37 2010 -0400
+
+ Merge mainline.
+
+commit 5380fee33a871580fe9f3424767eaf2362c8cde0
+Merge: ef2d866 08c0efd
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Jun 13 23:43:37 2010 -0700
+
+ Merge mainline.
+
+commit 538a29e12f115390a64ceb3d4909a4a67cad26cd
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Aug 19 15:48:55 2008 -0400
+
+ Make diff smaller
+
+commit 53c86e82af6757c12df3a99aede6862a311f050b
+Merge: fa8a82e ae2df26
+Author: Luca Barbato <lu_zero@gentoo.org>
+Date: Sat May 3 16:13:06 2008 +0200
+
+ Merge branch 'master' of git://git.mplayerhq.hu/ffmpeg
+
+commit 53cd195c8885125351a03cfb6f1d93e66d433b86
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Nov 15 05:00:01 2010 -0500
+
+ Rewrite multithreading.txt
+
+commit 53fff221cdb9f18df2f2f52bd48731ce0fa9e114
+Author: Maksym Veremeyenko <verem@m1.tv>
+Date: Wed Mar 30 13:20:23 2011 +0300
+
+ mingw32 compilation after 'unbreak avcodec_thread_init'
+
+commit 5402adfa2e9c159e7d13ee07e142cb035a77ef95
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Dec 16 16:54:20 2008 -0500
+
+ Only write to stderr once for each av_log().
+
+ This makes logging somewhat easier to read with multiple threads.
+
+commit 541d79def90226cc9b17e6ccc9eb2ff2549bea46
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Fri May 15 17:54:20 2009 -0400
+
+ Remove useless volatile qualifiers
+
+ All such accesses must be protected by a mutex anyway, which is
+ already a memory barrier, so this doesn't change anything (assuming
+ a working compiler).
+
+commit 544c6a6709833f1a449b8faf4478ab529e269240
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Mar 29 02:28:29 2009 -0400
+
+ Frame threading support for HuffYUV decoding
+
+commit 54c0c3d2ce69606a5aa508659d3322f48ada77cb
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed Sep 3 11:59:59 2008 -0400
+
+ Call decode_postinit from the right place to avoid race conditions
+
+commit 552a89508fddc64d4217b9d845e458f504b63593
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Jun 27 15:22:52 2009 -0400
+
+ Print md5s of test output files in test.sh.
+
+commit 55c511eedb24ffb09aef7072c02e911576c9900b
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Jan 25 02:47:19 2010 -0500
+
+ Did a todo item
+
+commit 574d2e5b942aa1e093bf768cc6321f3b081d3aeb
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Jul 5 23:36:08 2008 -0400
+
+ Merge enum with its only use.
+
+commit 578f45c15026e778ef54694d98a9ec446810a897
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Jun 15 17:42:56 2008 -0400
+
+ Reindent.
+
+commit 5918efedbb7928031b6af745acb8b4233c08fb06
+Merge: 7d09b68 c2a400d
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Aug 14 21:37:03 2008 -0400
+
+ Merge branch 'mainline'
+
+commit 59d787ffccaf42e992229649c23e624ea7d71635
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Nov 15 05:39:12 2010 -0500
+
+ Delete os2thread.c which is gone from mainline
+
+commit 5a7146bf75a2170f33ff25b88b91f667574d2919
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed Aug 11 01:33:20 2010 -0700
+
+ vp3: Fix a crash decoding files with <thread_count frames
+
+commit 5a75822b584676672fbb887d4b828abc80ffd89c
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Fri Apr 1 19:19:34 2011 -0400
+
+ pthread: validate_thread_parameters() ignored slice-threading being intentionally off
+
+commit 5b7c668d1f64facfe8b9f86e2491085595fa9bc7
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Aug 12 20:26:26 2008 -0400
+
+ Document thread-safety requirements for user callbacks in AVCodecContext.
+
+commit 5bacdcc1a52e2b1d32bad9e9f250ceb6cc37f366
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Oct 11 15:40:47 2008 -0400
+
+ Fix progressive height values in avail_motion()
+
+commit 5c46573ed07b092aea0db6560ade77bc299c28cb
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon May 25 22:16:23 2009 -0400
+
+ Whitespace error
+
+commit 5c4c8ed51da0be4f141a4de339db77f4a0a6c783
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Sep 1 03:18:55 2008 -0400
+
+ Remove unused variable
+
+commit 5d3c2f7512746dd0adf067952ed38d8111d7571d
+Merge: 7041a16 5a70b15
+Author: Luca Barbato <lu_zero@gentoo.org>
+Date: Sun Jul 6 12:38:18 2008 +0900
+
+ Merge branch 'master' of git://git.mplayerhq.hu/ffmpeg
+
+commit 5d53ada4cbd323d66b61965b1442d0abd63361b2
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Jan 24 17:00:18 2010 -0500
+
+ Don't load PerThreadContext until it's needed in ff_await/report_*.
+
+ Should avoid crashes if anything calls them without using ff_get_buffer.
+
+commit 5d7dfbb887f263b036224bf4510db176fa6cff73
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Jun 16 18:18:53 2008 -0400
+
+ Utility functions for mpegvideo threading.
+
+commit 5d82241b49a1fb1dbecd1b279045cce9f099c775
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Mar 24 03:34:48 2011 -0400
+
+ Update todo.
+
+commit 5eb0c649c780e26a77085bd213f945d88761ad00
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Jan 4 04:12:44 2010 -0500
+
+ Make ffplay -drp the default.
+
+ Ignoring reordered/delayed PTS never works with frame threading.
+ This may be changing behavior too much; I haven't tested this
+ with non-mt files, but I think the current behavior must cause
+ A/V desync even there.
+
+commit 5eb679f0fff432ba2c9e0cdada254dbe4bd4a45d
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Nov 15 02:53:14 2010 -0500
+
+ Remove width/height changing checks from h264/mpeg12
+
+ These should be moved to pthread.c update_context_from_thread() if they're needed,
+ not kept in specific codecs. Hopefully the error return from get_buffer() is
+ enough to make it not crash anyway.
+
+commit 5edf2cc5acbb410ba50a3770e8565fb39206f406
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Jun 16 18:20:54 2008 -0400
+
+ Multithreading support for mpegvideo decoding in general.
+
+commit 5ef4af7de47c3913ddc1e09e43887ac04ecfaba3
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Jun 15 01:58:15 2008 -0400
+
+ Fix ff_delayed_release_buffer crashing with slice-threading.
+
+commit 604ee5471f21d310f4014011a20c00c28a31995b
+Merge: 3792712 7838828
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed Apr 21 22:04:21 2010 -0400
+
+ Merge branch 'master' of git://git.mplayerhq.hu/ffmpeg
+
+commit 607edd221a3b7a300fbaa4a5495ffd30f8dc9fa8
+Author: stefano <stefano@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
+Date: Mon Jul 26 14:30:47 2010 +0000
+
+ Define static functions fill_image_linesize() and
+ fill_image_data_ptr(). ff_fill_linesize() and ff_fill_pointer() now wrap
+ these functions.
+
+ The new functions are more generic, and are going to be exported in a
+ future patch.
+
+ Patch by S.N. Hemanth Meenakshisundaram smeenaks # ucsd commit 60be6c15c4d23c5107f14e408043988918a44c76
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Jun 20 16:07:58 2009 -0400
+
+ Add a valgrind script so I don't have to type it all the time.
+
+commit 614d2308b343ec6af6bf72ada08884684bb66df0
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed Sep 3 22:55:22 2008 -0400
+
+ Update header guard
+
+commit 62830f5772dd8971032aa9f8d52a8f6c00c92487
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Jul 17 19:04:19 2008 -0400
+
+ Remove next_delayed_pic, it doesn't prevent any race conditions.
+
+ This part is now entirely out of sync with mainline.
+
+commit 62ba7a4acc98b691ab3152356cf0c21a52f7e03b
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Jun 15 19:22:41 2008 -0400
+
+ Fix the main thread hanging if there's an error before all of the frame is decoded.
+
+commit 63d086d2585d3275a6b9068ee1ca957617ecf902
+Merge: 314c2b1 712afbf
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed Feb 18 21:29:44 2009 -0500
+
+ Merge branch 'master' of git://git.mplayerhq.hu/ffmpeg
+
+commit 63f663f09320851b9ed76f489fdab590da2fc7f0
+Merge: 64df3aa d61efce
+Author: Luca Barbato <lu_zero@gentoo.org>
+Date: Sat May 10 07:51:22 2008 +0200
+
+ Merge branch 'master' of git://git.mplayerhq.hu/ffmpeg
+
+commit 63ff6aa525faf65f86dfbc8ec571fd260844100f
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Oct 23 18:07:14 2010 -0400
+
+ Don't set avctx->thread_count to 0 in avcodec_thread_init.
+
+ h264 crashes during decode init with 0 (instead of 1) threads.
+ Note that this isn't a regression from -mt, but is actually a bug present in mainline.
+
+ -threads 0 should preferrably set auto threads, but doesn't.
+
+commit 641f2752c16aaa25c5854d34726b72f226003b87
+Author: Luca Barbato <lu_zero@gentoo.org>
+Date: Sat May 3 12:20:42 2008 +0200
+
+ Ignore stuff
+
+commit 6446d2b0931c6a9637077b18b98af911d438057f
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu May 7 01:38:16 2009 -0400
+
+ Update mplayer.diff line numbers to match mplayer r29269 (20090505)
+
+commit 647f6cf3144934e3c2c22b06601d23a1217a2b86
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat May 23 20:09:07 2009 -0400
+
+ H264: Print an error instead of failing silently for size changes with slice threads.
+
+commit 64df3aa6a32a87d96f650b8535c88e1d65b52524
+Merge: 53c86e8 72c8992
+Author: Luca Barbato <lu_zero@gentoo.org>
+Date: Sun May 4 22:24:35 2008 +0200
+
+ Merge branch 'master' of git://git.mplayerhq.hu/ffmpeg
+
+commit 65b3e34fc8a52f4f1a48fce7c8cddd80db8fade9
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Nov 1 12:20:24 2010 -0400
+
+ Update the test script to show results more clearly
+
+commit 65e8486a1dd1efbf2750d0bc25c326f8dc836bcd
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Mar 29 03:10:53 2009 -0400
+
+ Fix nonsense 2am code - left the huffman tables uninited.
+
+ It would be faster to copy the VLCs but it would require more code.
+ And this could be factored into another function.
+
+commit 661ca4010c548e135ce1c0c819d0c05a94b66985
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Fri Jul 10 14:32:04 2009 -0400
+
+ Cosmetics: get rid of pointless parameter.
+
+commit 66204771dd8e479d30ef71ad85c162e1a34e4104
+Merge: 3f75218 76dd0e7
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Oct 23 17:41:42 2010 -0400
+
+ Merge mainline.
+
+ Conflicts:
+ libavcodec/avcodec.h
+ libavcodec/options.c
+
+commit 66a34dee4443dd6ccabb53ca09a1c45bc95f4d24
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Aug 12 00:39:28 2008 -0400
+
+ Don't run the last part of decode_update_context() when the last frame was dropped.
+
+ This fixes mplayer -framedrop crashing. Of course, they're still run in some cases when it wouldn't be without threads, but those are all error conditions.
+
+commit 66cf3f781d73fed502d80cce01dbd16b25bc3a71
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Aug 2 19:27:12 2008 -0400
+
+ Correct 6b037a88 for PAFF/MBAFF.
+
+commit 66d9c0c9f6b2a4309dd4a41f88dd9a1dccb323e3
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Aug 23 19:56:21 2008 -0400
+
+ Wait for predecode to finish just before calling update_context, instead of as soon as possible.
+
+commit 66ef4712c357514602f6b47311874e9ebf7376e3
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed Jun 4 15:57:36 2008 -0400
+
+ Handle zero-byte input correctly. (for CODEC_CAP_DELAY)
+
+commit 68682144289b05c830fd64a651526c4708666874
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Aug 19 04:08:42 2008 -0400
+
+ Fix accidentally calling execute_ref_pic_marking() while draining delayed_pics at the end.
+
+commit 686ea24614fded4d7501f71901aae61f5160f018
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Jan 16 22:15:28 2011 -0500
+
+ Update APIchanges to match mainline_patches branch
+
+commit 68ef172444124e9e6dd2a69df00ae72a64e795cb
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue May 11 05:34:20 2010 -0400
+
+ Pass the complete AVPacket through pthread.c decoding
+
+ Part of a patch from VLC.
+
+commit 6913bf9451bdaef16cd7748c93358baeec57d33b
+Author: Michael Niedermayer <michaelni@gmx.at>
+Date: Wed Apr 6 00:14:56 2011 +0200
+
+ Fix REBASE_PICTURE with h.264
+
+ It was possible for last_picture_ptr to point into h.ref_list
+ instead of h.s.picture, which caused a bad pointer to be set.
+ Fixes some valgrind warnings, presumably improves behavior but
+ no changes were found.
+
+commit 6998f46dec036f2ab39d6389747a95a7f5808f19
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Feb 20 22:32:39 2010 -0500
+
+ Cosmetics: Rename init_copy and update_context to have 'thread' in the name
+
+commit 69f085cebf61a64352e623d3c4a5d6032329473d
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed Jun 10 11:33:47 2009 -0700
+
+ Don't change avctx->thread_count if frame_thread_init() fails.
+
+commit 69f6e77a9a9ddfc386d43f5a350df5c960c0203d
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Aug 24 04:11:52 2008 -0400
+
+ Remove useless check
+
+commit 6a26fe72383c0ab088c8d92733221bf2911231ce
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Fri Oct 17 14:45:47 2008 -0400
+
+ Fix nonsense logic in copy_parameter_set()
+
+commit 6a3821cf92ef5aaba020a0b7c8d06df5926bd362
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Jun 3 04:13:55 2008 -0400
+
+ Merge statements in mimic.
+
+commit 6abde3d9e6ccfb062c6f547334171665386b0d85
+Merge: d8014c6 4448f8c
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Fri May 7 04:42:38 2010 -0400
+
+ Merge mainline.
+
+ Conflicts:
+ libavcodec/avcodec.h
+ libavcodec/options.c
+
+commit 6ae441be729df8064f1b1244acc82fead9cb1918
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Aug 19 01:27:54 2008 -0400
+
+ Reduce code duplication in MPV_lowest_referenced_row
+
+commit 6b037a889a34f8f2dd8ad188cda6f4d09d9f4710
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Jul 27 00:58:54 2008 -0400
+
+ Avoid a deadlock in damaged streams where the current picture ends up in h->ref_list.
+
+commit 6b5aa5cb4d105c4ed118d5ea07f64bbe1e94d135
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat May 23 23:10:33 2009 -0400
+
+ Remove inaccurate comment.
+
+ ff_report_frame_setup_done() is called properly for the first field.
+
+commit 6c575595d9d0e2974e326ad86db61bb61163753a
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Aug 19 21:01:51 2008 -0400
+
+ Add flag for thread algorithm
+
+commit 6d4679e9d5fedff6aa1eed964aa1449716f02682
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed Jan 20 02:17:36 2010 -0500
+
+ Add a FIXME comment to a commented-out part of h264.c.
+
+commit 6e508a7ab927ce7280688d822d3529dfbf17ec88
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Sep 4 17:40:59 2008 -0400
+
+ Fix field progress allocation.
+
+commit 6fad2f2300fb9e6288d4c9cdf3028d07d3dd63a9
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Jan 17 15:41:20 2011 -0500
+
+ pthread: Fix missing mutex unlock in error condition
+
+ Also remove stray ;
+
+commit 700a6622f378b5169d8d54ea5bdb4d8b67262a22
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Jun 24 23:29:40 2008 -0400
+
+ Merge another ++.
+
+commit 701ddc74e17de9f76eabf00a9e8d16adac7c2954
+Author: michaelni <michaelni@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
+Date: Tue Nov 5 00:38:06 2002 +0000
+
+ BeOS Audio ouput patch by (Fran
+commit 7041a164baed1c643f0cfa1207fbb2fd06d81f38
+Merge: 84cde2e 483385a
+Author: Luca Barbato <lu_zero@gentoo.org>
+Date: Sun Jun 29 16:34:45 2008 +0900
+
+ Merge branch 'master' of git://git.mplayerhq.hu/ffmpeg
+
+commit 70595dcbdbc01bb1f8f331c0998ee11f04577091
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Jan 24 17:33:22 2010 -0500
+
+ unnecessary freep
+
+commit 706e94d6531daa0b179613dbef51af8ec5bbe1dd
+Merge: 7e928f6 e42b282
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Jul 17 18:47:45 2010 -0700
+
+ Merge mainline and swscale.
+
+ One valgrind test currently fails.
+
+ Conflicts:
+ libavcodec/avcodec.h
+ libavcodec/beosthread.c
+ libavcodec/h264.c
+ libavcodec/options.c
+ libavcodec/os2thread.c
+ libavcodec/utils.c
+ tests/ref/vsynth1/rgb
+ tests/ref/vsynth1/yuv
+ tests/ref/vsynth2/rgb
+ tests/ref/vsynth2/yuv
+
+commit 70bf5912700d0519f3d607784654c394633effac
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed Jun 18 21:58:17 2008 -0400
+
+ Add an mpegvideo wrapper around ff_report_decode_progress.
+
+commit 70fb3fdcf2c5f01a555d87f8113efb50286493f7
+Merge: 1d15df4 0b034be
+Author: Luca Barbato <lu_zero@gentoo.org>
+Date: Mon Jun 9 18:03:54 2008 +0200
+
+ Merge branch 'master' of git://git.mplayerhq.hu/ffmpeg
+
+commit 71419720215a7ca7d1b1780564f21cb51d9df0a2
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed Aug 6 15:45:52 2008 -0400
+
+ Copy all the MPEG-2 interlacing flags, as well as *_picture, in ff_mpeg_update_context().
+
+commit 73608e1fa14434599aab86d2198a05ec4ca21c59
+Merge: a5285ae 6a7ac9c
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed Sep 16 14:38:47 2009 -0400
+
+ Merge branch 'master' of git://git.mplayerhq.hu/ffmpeg
+
+ The definition of CODEC_CAP_FRAME_THREADS changed, but
+ clients shouldn't have had to check it for anything.
+
+commit 73ad08d3b0867db89e5a81b9aec44b053e855ab3
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Mar 24 03:31:14 2011 -0400
+
+ Draw edges in MPV_frame_end when encoding
+
+ These pictures don't get draw_horiz_band called on them.
+ I thought I had tried this, but after thinking about it realized I'd made
+ a typo the first time.
+
+ Fixes make test.
+
+commit 74f382ae597d9cf69c885bc03c716d18fdbd413c
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Mar 16 23:12:44 2009 -0400
+
+ Disable frame threading for MPEG-4
+
+ It seems to have problems with packed B-frames in mplayer.
+ I don't know if any other players work (at least ffplay does).
+
+commit 753aecc29f8f4727326f0f371fa99fefbc369d0c
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Jul 15 02:58:51 2008 -0400
+
+ Lift H.264 display-order code before decode_slices.
+ This is needed for multithreading and should get us closer to CODEC_CAP_DRAW_HORIZ_BAND.
+
+commit 759176e401ebe8911e071f860f59b05d482315d0
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Mar 10 02:36:33 2011 -0500
+
+ Reorder picture_count in mpegvideo to fix ARM asm
+
+commit 75d4208c3a6ea4b9973b05ce930258ca8c3db224
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed Jun 25 01:06:31 2008 -0400
+
+ Disable mbskip copy avoidance harder with threads on
+ Fixes seeking in mpeg4.
+
+commit 76211d5890819ae687cc73520bcda17115a65697
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Aug 23 23:14:10 2008 -0400
+
+ Update threading comments in avcodec.h
+
+commit 776e2fc2d7df09d184caf414cb1d93829fe1c38d
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Mar 9 01:11:58 2010 -0500
+
+ Fix missed things in previous VP3 commits
+
+ Optimization improvements only, because the pessimizations hid the bugs.
+
+commit 77f7818ac7b881a5aa024e31147255ed3a413141
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Jan 24 19:00:24 2010 -0500
+
+ Fixed memory leak in todo
+
+commit 78c5ca40fac2dc13dac72cada9cc4b80551ee94c
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Jan 16 02:31:44 2011 -0500
+
+ Update todo.txt
+
+commit 78feacc6fae50a72dff68e75d0f718bc136dbe7b
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Jun 21 23:05:45 2008 -0400
+
+ Copy the other parts of MpegEncContext needed for h263
+ I'm not sure if mbskip can be made compatible with frame threads yet, so it's all zeroed for now.
+
+commit 795b6f2d87b241e98472c8d9771d4327712c6db9
+Merge: 20d6c33 4f24e1c
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Jan 13 01:52:27 2009 -0500
+
+ Merge mainline.
+
+ The conflict fix in h264.c has a strange-looking diff
+ but probably isn't a problem.
+ Reverted regression tests to mainline's.
+
+ Conflicts:
+
+ libavcodec/avcodec.h
+ libavcodec/h264.c
+ libavcodec/mpegvideo.c
+ libavcodec/utils.c
+ tests/seek.regression.ref
+
+commit 79f3159ebbc55b4f2f885943badc5a847ecd612f
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Aug 26 03:09:09 2008 -0400
+
+ Split longer lines
+
+commit 7a08d7653f38851bd950264fa78174616395fd9a
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Jun 21 22:09:12 2008 -0400
+
+ Park all the threads in ff_frame_thread_free before ending them.
+
+commit 7aabc98254731f46d39fb0770b1445fe332797de
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed Jan 20 02:38:42 2010 -0500
+
+ The mplayer patch doesn't need to change vd_ffmpeg anymore.
+
+commit 7b14ed499f5dab39586f3b75ee03e29425b9383e
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Fri Aug 22 16:25:59 2008 -0400
+
+ Remove an unused variable.
+
+commit 7b46b8dc0c04a77108f0150a6fdf58a9b65d4aed
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Fri Jul 11 18:02:57 2008 -0400
+
+ Use USE_AVCODEC_EXECUTE instead of checking thread_count in h264.
+
+commit 7c7f43547b0ad8907d097b99a66f0fc3f171c9f3
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Jul 31 18:22:55 2008 -0400
+
+ Rename H264Context got_avcC to got_extradata.
+
+commit 7d0709ea04d6f2023052506c969d6db9b79f2963
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue May 26 00:39:26 2009 -0400
+
+ Reindent
+
+commit 7d09b684e9948bbe0e663e40ff0ce616018c0091
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Aug 14 20:30:42 2008 -0400
+
+ Revert some h264 multithreading changes to make merging easier.
+
+commit 7e85791de30c9005ac722afd59c713c7faef5d7e
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Aug 19 15:41:14 2008 -0400
+
+ Retypeset/fix comments
+
+commit 7e8d959053b29d975c600eb89eb453496a860961
+Author: stefano <stefano@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
+Date: Sat May 15 17:34:45 2010 +0000
+
+ Avoid mixed declaration and code, fix C89 compatibility.
+
+ Patch by Fran
+commit 7e928f69148f6c90d35715f4380accb6fc4e88c4
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Jun 24 02:41:43 2010 -0700
+
+ todo: Add secondary bug not fixed in last commit
+
+commit 7eac0bccc22daa54db7c40b530cf692af3f41274
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Jun 18 16:55:03 2009 -0400
+
+ Update todo.
+
+commit 7ec92357ae09969eb5254ab6954b712d95b4630f
+Author: benoit <benoit@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
+Date: Tue May 22 07:58:22 2007 +0000
+
+ cosmetic v1/v2 renaming
+ patch by Andreas
+�commit 7f86539559480910beab0ef568571dbe524ecda1
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Jan 25 02:46:29 2010 -0500
+
+ Rename avail_motion() and associated functions to something better.
+
+ What did "avail" mean, anyway?
+
+commit 7fc3b0d1f996b8a832017095244a3187b8d80f38
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Apr 4 00:23:21 2009 -0400
+
+ Remove client calls to avcodec_thread_init.
+
+ This function has no effect under ffmpeg-mt, since avcodec_open()
+ calls it anyway.
+
+commit 802206985550e6f685e42595f529133186388acc
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Nov 15 05:19:58 2010 -0500
+
+ Update todo.txt
+
+commit 8047714299aa3fb377b011cd68858b76a666c7cc
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Aug 25 19:39:24 2008 -0400
+
+ Whitespace nits
+
+commit 80a20f0fda854e6c8de05b971164d25425105c82
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Aug 23 21:52:47 2008 -0400
+
+ Don't call ff_report_decode_progress for h264 B-frames.
+
+commit 80a7538f955a9cd931d840e1cb4e4c81e9d85165
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Nov 15 04:14:51 2010 -0500
+
+ Write APIchanges.
+
+ avcodec_thread_init() will not be deprecated in this repository to
+ avoid generating warnings for users who shouldn't remove it just yet.
+
+commit 80ab88e74f9864442afca19ecc6ee0428623ff22
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Jun 15 17:46:30 2008 -0400
+
+ Cosmetics: rename context variable.
+
+commit 8218d5319067aa1ac06c601e5dc530ebdab7c01f
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Aug 18 18:43:02 2008 -0400
+
+ Properly handle error returns from codec functions.
+
+commit 821c4d0996689ab27d5ab1b6bca0695503b02670
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Jun 21 22:54:52 2008 -0400
+
+ Add 16x8 and 8x8 MVs to MPV_lowest_referenced_row()
+
+commit 822ed86c0ac4de7c38d443e23fcabf1b627118ea
+Merge: e340cac 17c125c
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Nov 18 13:58:23 2008 -0500
+
+ Merge mainline.
+
+ Conflicts:
+
+ libavcodec/h264.c
+ libavcodec/mpegvideo_enc.c
+
+commit 82324906156d303d5f3b3e10a1855bf05614ebfc
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Jul 18 02:24:09 2010 -0700
+
+ Revisit d812c6f8b1d897734d6f7b5f1a5c95d3aa10a3ea
+
+ The sps/pps_buffers logic wasn't correct, considering that SPS/PPS
+ can be found far before the first working frame.
+
+ Unfortunately this adds more code than it removes.
+
+ Fixes a crash and a memory leak in premiere_paff.ts.
+
+commit 824ee1ac826b89b84cc93fb77f38ec6530909f2b
+Merge: 686ea24 11dcccd
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Jan 17 03:39:49 2011 -0500
+
+ Merge remote branch 'mainline/master'
+
+commit 83b344d87b97ef6b72e84c145f2185f87ce22e9b
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Apr 4 00:27:47 2009 -0400
+
+ Forbid calling avcodec_thread_init after avcodec_open.
+
+ Although ffplay used to do this, it never worked, since codecs
+ were free to check thread_count in their init functions.
+
+commit 83c7cc1ca1afe68b339b8554634a3a1effc76b45
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Aug 19 21:24:03 2008 -0400
+
+ Add more to todo
+
+commit 83cbbb1a92d58a850d5b254b5f54e78a7bad8ca5
+Merge: ae7e6bb 7e61a90
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun May 30 09:59:29 2010 -0700
+
+ Merge mainline.
+
+ Conflicts:
+ libavcodec/avcodec.h
+ libavcodec/h264.c
+
+commit 8414fc85d03776bc622c9451e9b08f047af42676
+Author: Uoti Urpala <uau@glyph.nonexistent.invalid>
+Date: Sun Jan 2 11:52:30 2011 +0200
+
+ pthread: fix failure to initialize frame fields after flush
+
+ Commit b67d7055bf ("Clear returned pictures immediately after copying
+ them.") moved some code used to (re)initialize per-thread data before
+ starting to decode a new frame. The commit changed this to be done
+ after the results of decoding the previous frame had been returned to
+ the caller. This was buggy: when decoding state is flushed some
+ decoded frames may never be returned to caller, and thus there would
+ be no reinitialization before reusing the same thread for another
+ frame after the flush. In particular, *got_picture_ptr could be
+ incorrectly set when calling avcodec_decode_video2() after seeking.
+
+ Move the initialization code back to the previous location before
+ starting to decode a frame, but leave a line setting
+ PerThreadContext->got_picture to 0 also after returning a frame and
+ add a comment explaining why it is there.
+
+commit 846ae640182b4775db5b32cb027d964bf85d54a5
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Fri Jan 21 03:16:03 2011 -0500
+
+ Longer comments in thread.h
+
+commit 84a94407509525ffca2e1691a73d186d0d10b1fd
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Aug 19 01:14:36 2008 -0400
+
+ Remove whitespace change from mainline
+
+commit 84cde2e4c7d97f3a9b5f9d4a4c722ccf38c82742
+Merge: f139f42 e73c602
+Author: Luca Barbato <lu_zero@gentoo.org>
+Date: Tue Jun 24 13:31:01 2008 +0200
+
+ Merge branch 'master' of git://git.mplayerhq.hu/ffmpeg
+
+commit 854cff1a75a0c4433d6a25517326b2660a56693d
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed May 28 01:05:33 2008 -0400
+
+ Enable multithreaded MDEC.
+
+commit 85730bc96115f75524f2780059a26ee6dbd8695e
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Aug 16 01:30:59 2008 -0400
+
+ H264: Skip filling in the parts of frame num gaps that are bigger than the number of reference frames.
+
+ My sample with a 256 frame or so gap doesn't work with ff_delayed_release_buffer otherwise.
+ No change on MR3_TANDBERG_B.264.
+
+commit 8666b987a1df652d830db8bae9c2d56287a8fc88
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Aug 16 14:18:13 2008 -0400
+
+ Clarify comment for AVCodecContext frame_number
+
+ Number of frames returned vs. decoded isn't the same anymore
+
+commit 8682f8c0c7396bfe1bf9b4be3293beb4c6a10927
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Fri Aug 22 03:25:03 2008 -0400
+
+ Rename and update comments for AVCodecContext variables.
+
+commit 86c6c4cff0bf8a734592f31591ec6fafb456387b
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Mar 9 01:46:32 2010 -0500
+
+ Cosmetics: fix overindent
+
+commit 878ad7601ad8eddec124877eb9b30b3df4a8c8b8
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Feb 1 21:45:18 2011 -0500
+
+ Add missing test script.
+
+ Haven't used this one in a while.
+
+commit 87a9ad1b28ec7a4c9b08b949486010098c06a752
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Jul 14 23:17:13 2008 -0400
+
+ Don't copy padding_bug_score.
+ This changes during h263 decode so it introduces a race condition.
+ Having a score for only every 1/n-threads frames is hopefully not too much less inaccurate.
+
+commit 880990f352fd8d557538535fc0496aec47d1c407
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Aug 19 00:42:56 2008 -0400
+
+ Cosmetics: rename input and output context members
+
+commit 8884655418183d2ccde654febc9a88e8398c978a
+Merge: 8232490 f991c07
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Aug 1 04:46:21 2010 -0700
+
+ Merge mainline.
+
+ Conflicts:
+ libavcodec/avcodec.h
+ libavcodec/vp8.c
+
+commit 8919a66d8ff492adc9455fd73f1da05d154281ff
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Jan 15 19:27:39 2011 -0500
+
+ Re-enable multithreaded mpeg4.
+
+ Seems to work in mplayer, and is needed so I can investigate fixing the buffer
+ age+skip optimization.
+
+commit 8969edf8b07437e9110db82b7c75e57c00c3e842
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Fri Aug 22 02:53:04 2008 -0400
+
+ Split a long line further.
+
+commit 899a30063b23ff008bbea3560c28fa194cfb1d77
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Aug 11 18:04:42 2008 -0400
+
+ Simple patch to keep the non-pthreads OSes working.
+
+ They ignore thread_algorithm being set by the user for some minor simplicity gain, since I'd still like to see these files gone from mainline.
+
+commit 8a2e487269389d778ddf517baaff590b0a7b3f46
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Jan 24 16:55:35 2010 -0500
+
+ Don't allocate thread_opaque progress with frame threading off.
+
+ It's not needed for anything and the extra check in ff_await/report_*
+ isn't slow.
+
+commit 8aa204a70a7f068f46f00e0983b4617f8030544a
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu May 29 00:19:26 2008 -0400
+
+ Fix comments for new avcodec fields.
+
+commit 8ae6601b670156b36b227e2a3c0d9cdc72294bd5
+Merge: c91d7a2 cef0309
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun May 23 01:43:27 2010 -0400
+
+ Merge mainline.
+
+ Conflicts:
+ libavcodec/avcodec.h
+
+commit 8ae9683ebce1e42c5bd1a24a2bcdcbf2cbfe6ccb
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Jan 16 02:29:08 2011 -0500
+
+ Update mplayer.diff to work around incompatibility with draw_horiz_band()
+
+commit 8af63f450185c3b15cc2ca32d2bc1a19f5d2a28e
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Feb 20 20:02:34 2010 -0500
+
+ Cosmetics: rename thread.h functions for consistency
+
+commit 8b7a5375ad0956f546c2b614594b79c3ec54de3d
+Merge: 3ad85b1 875fcc3
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed Oct 28 13:11:58 2009 -0400
+
+ Merge mainline.
+
+commit 8ba50a98f87edb2b87df042f09573ea8be4a8696
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Mar 28 03:54:31 2010 -0400
+
+ h264: Fix ff_h264_execute_ref_pic_marking() not being called with PAFF+threads
+
+ With some PAFF files, field_end() can call ff_h264_execute_ref_pic_marking()
+ during slice header decoding. This was disabled with threads on, which was wrong.
+
+ This patch fixes it at the cost of making control flow more confusing.
+
+ Partial fix for Chalet-Tire.mp4 from ffdshow.
+
+commit 8c946d1672281fc997dfb2679e7cbed48dd09216
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Jul 14 23:07:07 2008 -0400
+
+ Set decoding progress as high as possible when multithreading is off.
+ This avoids possible crashes from trying to lock progress_mutex when it hasn't been created.
+
+commit 8d466e182aa89ca8cfbe57ce60f2a1e2a7ecebc7
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Oct 13 14:37:22 2008 -0400
+
+ Fix incorrect frame num gap handling.
+
+ Fixes ORF1HD.Demo-Loop.720p.DD5.1.mkv from x264 samples.
+
+commit 8d8229014f489e1b2417676d9753f784d995e6c0
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Dec 1 17:21:38 2008 -0500
+
+ Don't crash if flush_buffers is called after init and before the first decode.
+
+ Fixes mplayer -ss
+
+commit 8f759fa0e956f8cc33ccd423cefae23e25c16caf
+Merge: 9be00ab 1e8ecf7
+Author: Luca Barbato <lu_zero@gentoo.org>
+Date: Tue May 20 11:46:04 2008 +0200
+
+ Merge branch 'master' of git://git.mplayerhq.hu/ffmpeg
+
+commit 9017898687ebedca27e47fdd13e6e5e208a5fbb6
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Aug 28 00:52:29 2008 -0400
+
+ Pad the frame data properly
+
+commit 9059683b29cd601361e477289a194e679aa72f8c
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Jun 12 16:22:27 2008 -0400
+
+ Limit ff_find_unused_picture to only part of s->picture.
+
+ Otherwise, a thread may call delayed_release_buffer and then later allocate a picture in the same place, reusing the other Picture variables while they're still in use.
+
+commit 9077d0ba4ed18e1f106723d155e81461c8951764
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed Feb 17 00:55:36 2010 -0500
+
+ Comment recent change to update_context API.
+
+ Notes:
+ - It might be possible to revert this by making the vp3 decoder
+ behave like mpegvideo. Not faster but the code will be simpler.
+ - I don't like any of the old comments, they're too wordy.
+
+commit 9153938f1c1f0933ec59cee14cc26b8f99bd9090
+Merge: 661ca40 e48fb07
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Jul 23 21:14:58 2009 -0400
+
+ Merge mainline.
+
+commit 91a7b18346baf82e0ccf6dfb53ada22299396f17
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Aug 16 16:42:33 2008 -0400
+
+ Call codec init and free on the first thread context instead of the main context.
+
+ This is needed so we can stop using the main context for decoding threads.
+
+commit 91a7c2254bb3e82862c4cd916bd9f2ac1dd4c170
+Author: lucabe <lucabe@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
+Date: Thu Sep 23 09:16:05 2010 +0000
+
+ Allow to set the frame rate in v4l2 devices
+ Patch by Jos
+� Miguel Gon
+commit 91cd95a84759702b85de68047d21a6ef9d32eaca
+Merge: 77f7818 f9f7b02
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Jan 24 21:39:20 2010 -0500
+
+ Merge mainline and libswscale.
+
+ Upstream now always calls avcodec_thread_init().
+ It's better to do that differently here, so the
+ current code in ffmpeg.c has been kept.
+
+commit 92672ea0eee93244cc78e5023f6469c5b21754b5
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Aug 18 19:10:01 2008 -0400
+
+ Simplify: better use of variable names instead of weird struct accesses
+
+commit 93ac615ccf788df20279aa613f3fdc78d4bfcf18
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Jul 14 23:56:22 2008 -0400
+
+ Simplify assert.
+
+commit 9457fb1458998f893b7e1f06f1144f8203cd0025
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon May 25 22:38:36 2009 -0400
+
+ Don't try to check list1 when it's not filled.
+
+ 9.1s -> 9.0s on 5cm.mp4
+
+commit 94985fa9745e2affd0cf3145fa35cb8ae87e7848
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun May 31 00:08:41 2009 -0400
+
+ Ensure the minor version is higher than mainline.
+
+ Missed this in previous merges, but I think it's important
+ to avoid confusing anyone reading ffmpeg tool output.
+
+commit 9576774bbee0215c0ab7bbb868ff35dff00ab900
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Aug 24 03:02:44 2008 -0400
+
+ Merge ff_*_release_buffer into one function for simplicity and correctness (the non-delayed version was not really ever safe).
+
+commit 967e65496780c089956f2dc199b541dae3a3d9cb
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Dec 18 14:37:04 2008 -0500
+
+ Some todo entries I forgot to add
+
+commit 96d6751af35556785037bdddb500eeb7b47795e6
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Jul 14 23:08:45 2008 -0400
+
+ Call ff_thread_init() before the codec init.
+ This makes USE_AVCODEC_EXECUTE() properly available during init.
+
+commit 9816b66fb55fe03fd6f2a4db9390bdaa59eac697
+Merge: 1292a18 918f7b5
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Jan 22 03:39:04 2009 -0500
+
+ Merge branch 'master' of git://git.mplayerhq.hu/ffmpeg
+
+ Changed the value of CODEC_CAP_FRAME_THREADS and
+ adjusted use of config variables to match mainline.
+
+ Conflicts:
+
+ libavcodec/h263.c
+ libavcodec/h264.c
+ libavcodec/mpeg12.c
+ libavcodec/mpegvideo.c
+ libavcodec/pthread.c
+ libavutil/common.h
+
+commit 99ed04d4d7b7183a4d0a1b8833eee3b506e13ff0
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Fri Jan 21 01:34:57 2011 -0500
+
+ Remove change to compute_pkt_fields which is no longer needed
+
+ May have been fixed by introduction of pkt_dts, but I'm not sure.
+ Either way, tests pass.
+
+commit 9a88884c03cd40d1fcbd247f1b004848fb629a11
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed Aug 6 20:55:20 2008 -0400
+
+ Simplify thread init and make more of its functions static.
+
+commit 9b27ce1e721a021128380e47e83a06f25c52e998
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Fri May 15 15:53:28 2009 -0400
+
+ Fix race condition decoding H264 direct prediction
+
+ There may be some code merging possible here.
+
+commit 9bac2ee137d9b8152e3beb98681b07f665cd58ee
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Jun 5 20:36:38 2008 -0400
+
+ Cosmetics: rename ff_mt_*_buffer.
+
+commit 9be00ab6113d71a020eea4fd4483b8483efbb29d
+Merge: 63f663f 1531623
+Author: Luca Barbato <lu_zero@gentoo.org>
+Date: Sun May 11 08:53:10 2008 +0200
+
+ Merge branch 'master' of git://git.mplayerhq.hu/ffmpeg
+
+commit 9c241058a255e1da6adec7db81e22d4ff8b2b6b2
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Aug 19 04:09:25 2008 -0400
+
+ Copy the entire reference list arrays in case they're used.
+
+ And that's it for SoC period commits.
+
+commit 9cd1083269334de974acdf13dd94451c178a0eca
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Mar 29 04:47:23 2011 -0400
+
+ Fix mdec
+
+ init_copy rotted due to data structure changes.
+
+commit 9e0e492fe88ec0c7ec400e9afdbef8356280fc16
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Aug 5 00:21:25 2008 -0400
+
+ Update the guard clause on avcodec_thread_execute().
+
+ It already works fine, since all codecs check USE_AVCODEC_EXECUTE themselves before calling it, but the function is for some reason part of the public API.
+
+commit 9e615b8534c98947cbbe6ada5047e95c36e14cde
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed Sep 3 20:40:45 2008 -0400
+
+ Rename symbols to not mention decoding
+
+commit 9e981c8d263986e67de6170895125b1de7e62ddd
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed Aug 11 02:05:50 2010 -0700
+
+ vp3: fix mt decode of 4:2:2 and 4:4:4 content
+
+ The threading improvements are poor and looks strange:
+ real 0m14.337s
+ user 0m13.200s
+ sys 0m1.132s
+
+ real 0m13.434s
+ user 0m19.409s
+ sys 0m7.091s
+
+ real 0m11.610s
+ user 0m21.870s
+ sys 0m7.303s
+
+ real 0m7.976s
+ user 0m20.681s
+ sys 0m3.277s
+
+ There may be a bug related to await_reference_row() being called too many times,
+ as it's in a loop per-chroma superblock and there are 2x as many of those
+ in 4:2:2, but not 2x as many MVs.
+
+ No idea why 4 threads have less sys overhead.
+
+commit 9ec47e33af6776b94875c91288db852a333a6f63
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Jun 21 22:01:43 2008 -0400
+
+ Split the code for completing all current frames out of ff_frame_thread_flush.
+
+commit 9ec9f0868de2df3d3448dec887e7440ebb006b27
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Aug 2 16:14:21 2010 -0700
+
+ Fix the last commit testing the wrong variable.
+
+ Luckily the idea was still right.
+
+commit 9ede817a98a263093ca7965f8754a1770ef031de
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Fri Jul 11 23:01:47 2008 -0400
+
+ Add a new -debug for tracing get_buffer calls.
+
+commit 9f15b87679392902206264383c16c7440d8c0f06
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Jul 6 15:35:10 2008 -0400
+
+ Extra line snuck in while merging mainline.
+
+commit 9f6a425684e0fd0ac3f8bbd37ca4e2bc96e05d5b
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon May 25 20:30:08 2009 -0400
+
+ Fix race condition with MBAFF frames.
+
+ mb_linesize is 2*linesize for MB_MBAFF too, which wasn't counted
+ in mc_dir_part_y, so the part of the MV added to 16*mb_y was 1/2
+ the right magnitude. Fix this by halving mb_y too (safe) and
+ doubling row values for MBAFF later.
+
+commit 9ff8764a15cce3fcf3f64270d7d4ec52a3ca7d1a
+Merge: 94985fa 08bbd7d
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun May 31 01:19:07 2009 -0400
+
+ Merge branch 'master' of git://git.mplayerhq.hu/ffmpeg
+
+commit a1005396f05f5bc13c6aa6875337dbd0e6c4cd03
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed Aug 6 20:45:06 2008 -0400
+
+ Merge framethread.c into pthread.c.
+
+ Git doesn't track this very well...
+
+commit a1a5c549efd3a376fd5c8c77d49acfab89f8fdba
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Jul 12 02:19:59 2008 -0400
+
+ Factor out size of delayed_pic.
+
+commit a210b422361b051ba73c115fe6bf65eaa745b19a
+Merge: f9515a4 ec6213f
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Dec 24 22:08:34 2009 -0500
+
+ Merge mainline and update swscale.
+
+ As a side effect, this fixes Theora/VP3 decode being broken.
+
+ Conflicts:
+ ffmpeg.c
+ libavcodec/avcodec.h
+ libavcodec/h264.c
+ libavcodec/mpeg12.c
+ libavcodec/mpegvideo.c
+ libavcodec/vp3.c
+
+commit a2371d6c9b8837b472e22539642883979eac2ddf
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Nov 18 14:26:37 2008 -0500
+
+ Update todo.
+
+commit a2efd25ba04e0cb61823cbf765651f437b691b09
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Jan 6 06:31:45 2011 -0500
+
+ Update todo.txt and move one issue out of bug fixes that isn't a major issue
+
+commit a2fb22fb6988742ee28ee61e2e21fa05125517a9
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Aug 30 04:20:03 2008 -0400
+
+ Don't prefix static function names.
+
+commit a3a2674e27f8f2641d1603ee9e92e854289a0527
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Feb 1 23:13:49 2011 -0500
+
+ Fix pkt_pts change to ffmpeg.c
+
+ Caused tons of regressions in make fate.
+ This needs to be merged to mainline_patches.
+
+commit a4599a7f4e4a865a0b402297b4f5a11e9ca34a27
+Author: benoit <benoit@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
+Date: Thu Jan 10 10:16:36 2008 +0000
+
+ Make pp_help a constant array of characters to move it to .rodata.
+ Patch by Diego 'Flameeyes' Petten
+� flameeyes commit a5285ae4d452abed92f43e2a7a24dd821343a39c
+Merge: a7b8cb3 6a3f0e9
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Aug 23 22:31:19 2009 -0400
+
+ Merge branch 'master' of git://git.mplayerhq.hu/ffmpeg
+
+commit a564fda546ce3bfd04cf8a0e4ec4fb1b6d40e010
+Merge: 287e761 5b4608b
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Jan 4 03:56:32 2010 -0500
+
+ Merge mainline and libswscale.
+
+ Auto-merge failed on h263.c for no apparent reason; the patch was
+ reimplemented by hand. Note that mt isn't enabled for h263 at the moment.
+
+ Conflicts:
+ ffmpeg.c
+ ffplay.c
+ libavcodec/h263.c
+
+commit a5cdcc9d4efcc043c01019f632dc1e5ad318802a
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon May 25 20:16:54 2009 -0400
+
+ Rewrite mc_dir_part_y().
+
+ The previous one used a completely wrong value for filter_height
+ and didn't properly account for MVs extending past the top of the screen.
+ I'm not sure if MVs can be more than -pic_height, if they can this
+ may still be wrong.
+
+commit a61ab604725f647c1bcb46aa8cfb303a5c78a2b0
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Jun 25 16:39:14 2009 -0400
+
+ Theora: factor out updating last_frame.
+
+commit a74b85567073a424d5b7fc4bd8cc1e125df170f5
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Sep 1 02:34:59 2008 -0400
+
+ Comment adjustment
+
+commit a7b8cb3c942fed6c80111519ba5505f11d61f3af
+Merge: 17dcbec 23e6da5
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Aug 20 16:47:50 2009 -0400
+
+ Merge branch 'master' of git://git.mplayerhq.hu/ffmpeg
+
+commit a903974adc7c8dd33dfb0acc4e2d6d10c09a23c8
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed Nov 11 12:45:09 2009 -0500
+
+ Add a next_outputed_poc to H264Context.
+
+ Doesn't do anything yet, but makes the next merge easier.
+
+commit aa11b5e0df5dfcaba21552e4864807f7aa65f5c5
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue May 11 06:36:55 2010 -0400
+
+ pthread: Remove pointless line from frame_worker_thread()
+
+ It was introduced in the first commit, where it probably did something.
+
+commit aaa05da15fa7710503544d4a94319cb10d49a8f2
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Nov 2 02:59:16 2010 -0400
+
+ vp3: Remove redundant y*fragment_width+x calculations
+
+commit aacc74c0e2b047340a1a22f5c28aa03a4294aa03
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Jul 14 03:40:15 2008 -0400
+
+ Reindent.
+
+commit ab4c84dd28c0375a6ed4f77f37ada3b94b2136a0
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Dec 1 17:20:10 2008 -0500
+
+ Don't hide the warning about direct rendering in mplayer.
+
+commit abb53ce0e02d31fb282f55cecb58f9b0c4f5c136
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Feb 6 19:18:31 2011 -0500
+
+ pthread: Remove useless line
+
+commit ac2e1b12b5e608b80581d731c4f3a0d6c033e9e0
+Author: benoit <benoit@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
+Date: Tue May 29 14:35:29 2007 +0000
+
+ allocate PPS and SPS dynamically
+ patch by Andreas
+�commit ac4539fba6d825d683d4a7d27f0045d068fe4595
+Author: benoit <benoit@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
+Date: Mon Jan 7 12:48:42 2008 +0000
+
+ Mark the ff_svq1_frame_size_table as constant.
+ Patch by Diego 'Flameeyes' Petten
+� flameeyes commit ac4c37360b21a14e9b26502a299f831b8448a10b
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Nov 15 02:43:15 2010 -0500
+
+ Cosmetics: remove the COPY() macro
+
+commit ac7f2102c4249a89144c36944e13bf6be56e9190
+Author: kabi <kabi@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
+Date: Mon Apr 8 12:32:01 2002 +0000
+
+ * support for .au .gif .mov .mp4 by Fran
+commit adfaa1f86196156e30c54799303269f4a4f84a2d
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Jul 26 16:14:00 2008 -0400
+
+ Cosmetics: split a long line.
+
+commit ae2790af78a332a6aa836607a14546c5cc1865e5
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Oct 12 18:55:48 2008 -0400
+
+ Add multithreading for PAFF/MBAFF.
+
+commit ae4251429ee5e333fc705c61959417c1d9364b9e
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Nov 18 14:15:24 2008 -0500
+
+ Switch to mphq git module
+
+commit ae7e6bb9708a0f0dac89295c788266e0f15899d2
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue May 25 03:14:27 2010 -0400
+
+ H.264: Fix rare race condition.
+
+ h->mb was not cleared when initializing a new decoder thread.
+ This could cause wrong pixel values in the first macroblock of
+ the first frame to be decoded by each thread.
+
+ I suspect this is nearly the last visible bug affecting x264 content.
+
+ Fixes [SS]_Angel_Beats!_-_06_(1280x720_H.264)_[A01DDBD8].mkv.
+
+commit af52a126f36cd6339f9f4a1152103ef88b4b8fee
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Jun 27 18:09:49 2009 -0400
+
+ Call handle_delayed_releases() before update_context().
+
+ This allows releasing frames in update_context(), which would
+ previously cause a race condition/deadlock.
+
+commit af79370b65b396e05c319d29356e456a8f5e8233
+Author: benoit <benoit@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
+Date: Mon Jan 7 12:44:49 2008 +0000
+
+ Make the av_class member of PPContext a poiner to constant AVClass.
+ Patch by Diego 'Flameeyes' Petten
+� flameeyes commit afafe7361da5a9373d02dc60d597da8f2185edd3
+Author: michaelni <michaelni@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
+Date: Sat Nov 2 10:31:37 2002 +0000
+
+ added perm inheritance from ffmpeg_g (it looks like 'strip' in BeOS doesn't keep them, though the Linux one does !?)
+ patch by (Fran
+commit afc391b7ab5eda271733bbe55ef46118aba75bff
+Author: michaelni <michaelni@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
+Date: Sat Jul 20 20:05:50 2002 +0000
+
+ beos/mov/adpcm patch by Fran
+commit afe0428ae38f68a467b43cc9358b7a1a2f85d36b
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Aug 16 18:09:11 2008 -0400
+
+ Fix memory leak in mpegvideo
+
+commit b05eb30ba838b981c769217e1d2215777484f25a
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Fri Jan 21 02:34:46 2011 -0500
+
+ Make the src parameter of update_thread_context() const
+
+commit b07e45974b2772e3a747502f976dc08d0ffcff74
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Jun 18 16:21:03 2009 -0400
+
+ Indent.
+
+commit b125b68fe6dc2d0064d45d0cffc3bcb47263f32c
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Jan 24 18:50:32 2010 -0500
+
+ Remove fixed entry from the todo.
+
+commit b18683e3adc997b19cf56f459ce5f8a7428c0909
+Author: diego <diego@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
+Date: Sun Oct 18 14:34:45 2009 +0000
+
+ Fix typo that mistakenly slipped into previous commit:
+ CONFIG_MPEG_XVMC_DECODER was changed to CONFIG_MPEGVIDEO_XVMC_DECODER.
+ patch by Onur K
+�
+commit b1c8c18fe11d3155b1df6a19117d14fa633bcd15
+Author: michaelni <michaelni@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
+Date: Sat Nov 2 10:39:22 2002 +0000
+
+ added MACE (Macintosh Audio Compression/Expansion) 3:1 & 6:1 support
+ contribution by Laszlo Torok <torokl@alpha.dfmk.hu>
+ 4CC 'MAC3' and 'MAC6' in Quicktime.
+ It works for mono streams, needs to be fixed for stereo when I get my hands on a stereo sample :)
+ patch by (Fran
+commit b3cdfccd2b11e247e0c17e02d0c958888da5585b
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Nov 15 04:14:41 2010 -0500
+
+ avcodec.h: Update comments
+
+commit b3d5e9333051802b20446076605b404e418323c4
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue May 26 00:34:11 2009 -0400
+
+ Skip unnecessary lock-wait-unlocks for condition variables.
+
+commit b3e3f071ca5ad99444bac95e4128c01a8ae7bae3
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Jun 11 11:32:00 2009 -0700
+
+ Split out if (current_slice == 1)
+
+commit b4221d5453d6dc893e87b77eecc845da121ddb56
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Aug 18 17:06:32 2008 -0400
+
+ Reorder ff_frame_thread_free to fix memory errors.
+
+ This fixes using mutexes after they're destroyed and not calling release_buffer on every buffer.
+ Unfortunately the change to MPV_common_end is exactly the opposite of what's needed for supporting width/height changes.
+
+commit b483ed4f4af9444cfaa6ff9336645d799d2254dd
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed Aug 6 20:33:51 2008 -0400
+
+ Remove the unused debugging counters from frame threading.
+
+commit b67d7055bf60313c40b6369f98cfc9d1eae3aefb
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Sep 2 00:52:48 2008 -0400
+
+ Clear returned pictures immediately after copying them.
+
+ This isn't protected by a mutex but is still safe.
+ Needed for the next commit.
+
+commit b68110d079914d16c9fc5d1cc8c6e10d78dbdbca
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Aug 16 15:05:49 2008 -0400
+
+ H264: Set the decode progress for fake reference frames to the maximum.
+
+ Fixes deadlock in premiere-paff.ts at the expense of some indeterminism on the first frame.
+
+commit b77accec9077ae8f072091fc7301d661bc9487ba
+Merge: 5d3c2f7 392faa1
+Author: Luca Barbato <lu_zero@gentoo.org>
+Date: Tue Jul 29 15:11:05 2008 +0200
+
+ Merge branch 'master' of git://git.mplayerhq.hu/ffmpeg
+
+commit b7d182610b592eef0714c1d2de18c3233a289b69
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun May 24 01:06:33 2009 -0400
+
+ Update mplayer.diff whitespace
+
+commit b7e0f1a3bfd00b0256dcdd3efc4b7b77c086e70e
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Aug 24 22:38:42 2008 -0400
+
+ Rename doxygen group to not conflict with h264
+
+commit b88c3baf94247f2687ca0c05b0ce6af7c905e02a
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon May 24 22:40:00 2010 -0400
+
+ Fix more old merge glitches.
+
+commit b9a8973031be583af53be890ccdef07841394385
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Jun 15 22:31:35 2008 -0400
+
+ Use output_cond for notifying the main thread.
+
+commit ba073d39f18679835b48b96f20feae96dad1f343
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Apr 11 23:00:19 2011 -0400
+
+ h264: cosmetic whitespace change
+
+commit ba8b789143dc6a14c29393e40fb361c1a3e2ccd4
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Aug 16 01:53:10 2008 -0400
+
+ Update todo
+
+commit babb66241ae51e2956aa698d425c645ad056936e
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Fri Oct 17 14:52:35 2008 -0400
+
+ Copy avctx->height/width for mpegvideo.
+
+ Not sure what the difference between the three width variables is, really.
+
+commit bad2bf8621c04791f0d9a0a2873a3b6042d4ba83
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun May 24 00:48:57 2009 -0400
+
+ Copy new fields in update_context_from_copy().
+
+commit bb67674aa57e23893f2f19bd4ffb4a92b5a01e83
+Merge: 06ac5ac 6051838
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Jun 20 17:39:15 2010 -0700
+
+ Merge branch 'master' of git://git.mplayerhq.hu/ffmpeg
+
+commit bba0e098a75f14af80bfd4fdfdf9edcaf8f3fee5
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Jun 20 03:32:19 2009 -0400
+
+ Factor out vp3 table allocation into new function.
+
+commit bbc5744117da188c43e00c4f02f6ff0fe984d4f8
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Jul 13 15:52:21 2008 -0400
+
+ Print the AVCodecContext address in av_log instead of AVClass.
+ This makes logging much easier to read when there's more than one context.
+
+commit bc1cc6f39a0f6df2cc1d0fecd3eb14efd150763a
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed Feb 3 01:29:21 2010 -0500
+
+ Cosmetics: Don't use #if HAVE_PTHREADS in thread.h.
+
+ These two macros will be removed entirely in the future.
+
+commit bd392934097dc5c909e9b06550ec1d13d92fa134
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Fri Aug 15 23:34:32 2008 -0400
+
+ Set output_size properly before calling the decoder so it doesn't return nonsense and crash at the end
+
+commit bd63cf4721466aea490f6f0455a32060d572d5ba
+Author: michaelni <michaelni@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
+Date: Sun Jul 21 07:54:53 2002 +0000
+
+ YUV410P to YUV420P patch by Fran
+commit bdaeaaa58f24393027e112c02896b23fe0b3cc01
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Oct 13 11:23:47 2008 -0400
+
+ Add buffer padding to the end of bitstream_buffer.
+
+ Fixes a warning in valgrind.
+
+commit bdef29429d4f488012cb492e61cf20ffe0b858a7
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Jul 6 15:48:52 2008 -0400
+
+ Fix compilation with threads disabled.
+
+commit be45bc423ba576e1d06df3664cfe91e02d78ffa5
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Feb 15 00:00:35 2010 -0500
+
+ Fix a deadlock in mpeg1 threaded decoding
+
+ Fake frames need their progress set to INT_MAX.
+
+ This can be triggered by seeking in mpeg1, but this is not the correct fix,
+ since seeking to keyframes does seem to work properly without threads.
+
+commit bf806642ab67148d93a4f24e7dbdc8644575c45b
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Jan 24 18:59:28 2010 -0500
+
+ When frame_thread_init() fails, free the failed thread context as well.
+
+commit bffb1c874ec2c9f7ea9c6830d852955a3c2805a0
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed Aug 6 20:51:34 2008 -0400
+
+ Make ff_*_thread_free static.
+
+commit c01185fe11dd2ce35f798d16faec17fcfc64c7c4
+Author: kabi <kabi@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
+Date: Fri Mar 8 09:09:57 2002 +0000
+
+ * BeOS patch by Fran
+commit c05a51580b56d1479083b1460dc29492b3fb6b16
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Aug 19 00:53:15 2008 -0400
+
+ Track allocated buffer size properly. Don't allocate buffer padding since the user already did it.
+
+commit c1b0bddeaf947ef49c63b412918d73fe7a645ba5
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Nov 15 04:08:01 2010 -0500
+
+ pthread: Update and sort the fields copied in update_context_from_thread/update_context_from_user
+
+ Changes to pthread.c are finished.
+
+commit c29d645dfd2c8168e7c9009638ddb88928e706be
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue May 11 06:12:26 2010 -0400
+
+ Copy time_base between threads.
+
+ Appears to be used by the h263 decoder.
+
+commit c2a400d3a5da10f8f2a9c2aa89d9396efe428029
+Merge: b77acce e96a4b0
+Author: Luca Barbato <lu_zero@gentoo.org>
+Date: Thu Aug 14 22:16:09 2008 +0200
+
+ Merge branch 'master' of git://git.mplayerhq.hu/ffmpeg
+
+commit c2e19261fe08c2d96d4bf082e97bebcdf12566f2
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Feb 20 21:24:24 2010 -0500
+
+ Remove USE_FRAME_THREADING and USE_AVCODEC_EXECUTE macros.
+
+ Requested in original review, might help making sure pthread emulation
+ works for encoding tests.
+
+commit c2e9a1fc965de63271c7c4ddffd7e938ce1bfd93
+Author: benoit <benoit@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
+Date: Tue Nov 6 16:28:32 2007 +0000
+
+ ffplay currently needs special handling for pausing in some protocols.
+ Patch by Bj
+�rn Axelsson: bjorn ; axelsson commit c2eed2a91101a90f2172e81755ca4d655de90443
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed Nov 3 22:13:07 2010 -0400
+
+ vp3: Cosmetic changes
+
+commit c370b927b6d1f0e092e43d58ee29046e5accad1a
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Feb 6 19:18:10 2011 -0500
+
+ Improve comment in avcodec.h
+
+commit c378f545f65d536e55ebe1ac85d170a15e7748eb
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed Aug 6 20:12:01 2008 -0400
+
+ Reindent.
+
+commit c45bb41ec61522dcdb97618a0f6fafd8a32d529b
+Author: benoit <benoit@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
+Date: Mon Jan 7 12:42:02 2008 +0000
+
+ Make v4l.c's video_formats constant and static.
+ Patch by Diego 'Flameeyes' Petten
+� flameeyes commit c4649d2e370c04c7f5cfcf0b444edc6116ba03f8
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Jan 25 03:16:09 2010 -0500
+
+ Avoid freeing buffers twice when closing mpegvideo.
+
+ This fixes a harmless "unreleased buffers" warning due to the design
+ of delayed releasing. This is probably a bad way to do it (won't
+ work if resolution changing is supported) but I can't think of a
+ better one that's simple.
+
+commit c5137d0d9e355aecc7e60cef0d2314468b77a147
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Jan 15 22:52:30 2011 -0500
+
+ Update todo.txt
+
+commit c563b57b187279c1af0f723110bdab815fac6385
+Merge: 65e8486 6a3327b
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Fri Apr 3 21:23:47 2009 -0400
+
+ Merge mainline.
+
+ Conflicts:
+ libavcodec/avcodec.h
+ libavcodec/mpegvideo.c
+
+commit c58218c681e51a1b392ddb0177dcff8fc8e99d1c
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Aug 12 00:45:01 2008 -0400
+
+ Use HAVE_PTHREADS instead of ENABLE_PTHREADS for mplayer compatibility.
+
+commit c5ca1f6b5227f8f7a26f889c123c4358ee15596e
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Jan 15 22:51:43 2011 -0500
+
+ Pass pkt_dts properly through multithreading
+
+ A/V sync should work in all cases now once guess_correct_pts()/clients
+ adopt AVFrame.pkt_dts.
+
+commit c6a59ddd734c7ca92862bce47ec686e16da627ee
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Fri Jun 19 18:32:12 2009 -0400
+
+ Remove frame_num stuff from todo.
+
+ The current code is actually correct.
+
+commit c6bbd5d91408d6dd795dfbbdfba2cef62696d765
+Author: michael <michael@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
+Date: Sun Jan 8 17:06:26 2006 +0000
+
+ fixing second last time Fran
+commit c6f5097967de5ed420cd56a1a77b60a705fcee48
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Aug 16 05:09:03 2008 -0400
+
+ Disable frame threading if low_delay or randomly truncated frames are used.
+
+commit c75cec5217fc23206476e2d1c894e8a6ddcd81b9
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Mar 29 02:25:19 2009 -0400
+
+ Fix missing ff_get/release_buffer calls in mdec.
+
+commit c83670eeb613b9509555d4ddcac559a37cc1c5bc
+Merge: 2063f77 dde06af
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed Dec 15 15:20:06 2010 -0500
+
+ Merge mainline.
+
+ Version wasn't updated this time.
+
+ Conflicts:
+ doc/APIchanges
+ libavcodec/avcodec.h
+
+commit c91d7a205df4dd224461b96749b9ce12e2bf6825
+Merge: 4874d25 04c74fc
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed May 19 16:51:42 2010 -0400
+
+ Merge mainline.
+
+ Conflicts:
+ libavcodec/avcodec.h
+ libavcodec/options.c
+ libavcodec/utils.c
+
+commit ca89b49eff34604b1354888cd041f474d988c122
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Jun 23 04:16:16 2008 -0400
+
+ Fix ff_frame_thread_flush()
+ It should setup the context to be just like decoding starting from scratch.
+
+commit cac4bca0570a9b9ffdd3b49590fe1e41fd5568b0
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Jun 27 15:02:21 2009 -0400
+
+ Fix conditions for drawing edges.
+
+ They shouldn't be drawn for B-frames/intra only (for speed)
+ and when hwaccel is on (for correctness).
+
+commit cba830597c99b7a6de57b3cd2209d22598bb72b1
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Feb 13 22:45:07 2010 -0500
+
+ Backport VP3 crash/deadlock fix from mainline r21781.
+
+ Previously, if get_buffer() failed when allocating a golden frame,
+ it would access it in a later frame without checking it first.
+ r21781 unintentionally fixed this.
+
+ This should be impossible to trigger, but some other bug in -mt
+ causes this with frequent seeking.
+
+commit cbaa375d4cb1320093199e8abe1ce7bcf389036d
+Author: michaelni <michaelni@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
+Date: Sat Nov 2 21:05:54 2002 +0000
+
+ gcc optimization on BeOS (patch by Fran
+commit cbc8d8bec42b371522b0724f27454a96881c4164
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Apr 19 02:47:32 2010 -0400
+
+ Disable multithreading the first field in PAFF.
+
+ At least one PAFF .mp4 file has two fields per packet, which can't
+ work with -mt - instead it needs to split the fields up like packed
+ B-frames do.
+
+ Fixes Chalet-Tire.mp4. Pessimizes otherwise working files.
+
+commit cc33ba7cd7ebbf14b62b0783fb7272e41b484aea
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue May 11 14:41:53 2010 -0400
+
+ Cosmetics: arbitrary reordering of some pthread struct members
+
+commit ccd0d039a3d2fd70a9e947cc2faf79ca091dd687
+Author: Luca Barbato <lu_zero@gentoo.org>
+Date: Fri Apr 25 21:52:45 2008 +0200
+
+ Incorporate swscale as submodule
+
+commit cd71fb4386961bc860c3abc4cf464b580366d57d
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Jan 25 16:33:26 2011 -0500
+
+ Forgot to git add the test failures list
+
+commit cdc193d0dbc2f0775d177f46036eca0d813f56ff
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Jul 6 15:53:33 2008 -0400
+
+ Use static functions instead of macros for consistency.
+
+commit cf2561f8dcc3143f9c479bba1d9be91339f23726
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Fri Jan 21 02:22:56 2011 -0500
+
+ Write longer comments for callbacks
+
+ Also neglected to update get_buffer to mention thread_safe_callbacks
+
+commit cf528d74cd7321219880eb06b94a8de0ba5741ff
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Aug 17 16:50:51 2008 -0400
+
+ Fix another memory leak.
+
+commit cf56bb126e7c056740e51c6c13304b03260b4b47
+Merge: ccd0d03 08baa31
+Author: Luca Barbato <lu_zero@gentoo.org>
+Date: Sat May 3 12:18:40 2008 +0200
+
+ Merge branch 'master' of git://git.mplayerhq.hu/ffmpeg
+
+commit d0c772c8021702ca79ce2aceeba75902231c0101
+Author: michaelni <michaelni@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
+Date: Tue Jul 23 22:05:35 2002 +0000
+
+ patch by Fran
+commit d103d4fac41b32915b45534d49d1e6a195b4220b
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed Feb 3 01:00:14 2010 -0500
+
+ Simplify thread.h by removing the stub functions.
+
+ They don't really help anything, if (HAVE_PTHREADS && ...) is sufficient.
+
+commit d15ab0f03a257293c0e13eac8b9b031da73c48f3
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Jun 3 04:41:33 2008 -0400
+
+ Macroize some threading checks.
+
+commit d21f769ead6bd4c24d867b7e9beeb8ffcc86b271
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed Aug 6 20:36:04 2008 -0400
+
+ Revert renaming pthread.c.
+
+commit d2f8287d8526f814bcc88d827775d39ddc5c5f22
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Jan 17 14:34:22 2011 -0500
+
+ Update todo.txt to put important things at the top
+
+commit d359ab19a25afa7dae20229e62dc0e37b6179ea7
+Author: michaelni <michaelni@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
+Date: Mon Jul 22 01:44:08 2002 +0000
+
+ adpcm encoding patch by Fran
+commit d419a1c1d30e1b171fba7dc31a909e77a08016ba
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Aug 24 03:51:18 2008 -0400
+
+ Comment utility functions in pthread.c
+
+commit d460fd8d253c90f20536dffe69a6ea20dc113106
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Aug 19 15:57:28 2008 -0400
+
+ Simplify codec close
+
+commit d4fad7c7f05e6fd7d677eaf1069e04c94b946a0c
+Merge: f3f3d11 980ab8d
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Feb 2 21:41:11 2010 -0500
+
+ Merge mainline and libswscale.
+
+ ffplay's pts reordering is better now, so ffplay.c has been reverted
+ to mainline.
+
+ Conflicts:
+ ffplay.c
+ libavcodec/avcodec.h
+ libavcodec/h264.c
+
+commit d5227efafd855f028338480f937b6ad4a86ef7ac
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Jun 12 18:24:28 2008 -0400
+
+ Don't check MAX_THREADS unless slice threading is on.
+
+commit d5c16c23327d84373fca125b884254550b79c8d7
+Author: mmu_man <mmu_man@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
+Date: Sun Jan 23 09:59:36 2005 +0000
+
+ Revert the fixed-size-sample patch as it brokes and others
+ WTF I thought I had commited this yesterday... was probably too asleep :commit d5ea5fc7342e3a1b082659bccd5ffd90a911b780
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu May 7 01:19:55 2009 -0400
+
+ Replace the number of frames option with a number of frames to skip.
+
+ The old option wasn't really useful (ffmpeg -t saves more time)
+ and this is needed to deal with broken stream clips, which are
+ common and tend to decode differently under mt anyway, which I
+ don't really care about.
+
+commit d611b2bcb3ce231242f566cee08a61798a36abc8
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Jun 18 05:03:36 2009 -0400
+
+ Fix race condition upon return from decode_init().
+
+ We can't call report_frame_progress on every returned frame,
+ because they may be returned while a past thread is still decoding
+ them. Instead ensure frames always have this called on them after
+ their decode is done.
+
+ Should fix all bugs for valid H.264 streams without frame num gaps.
+
+commit d62b7c03b163c3dc067f122ab9fec44de87b37ae
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Mar 9 01:54:27 2010 -0500
+
+ VP3: Only call await_reference_row() for luma
+
+ 4.3% -> 2.1% cpu on big_buck_bunny_1080p_stereo.ogg.
+ It should be further reducable since VP3 has limited MV range.
+
+commit d6bb0443c9b316b8cf29720524b4819fb2e6b6a1
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Sep 4 01:50:20 2008 -0400
+
+ Don't mention nonexistant variables in comments
+
+commit d71a7eef9e540b00b0f91d840116e43206390645
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon May 24 16:45:27 2010 -0400
+
+ h264: Delete lines accidentally left behind during a merge
+
+commit d7cfe6d5cbffa42e178d88d7c647d37431e21861
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Feb 1 22:20:19 2011 -0500
+
+ Fix dropped frames at the beginning of h264 decoding, fixes FATE tests
+
+ Patch by Ronald Bultje (rsbultje@gmail.com)
+
+commit d8014c67ff1ef20ca05302dea9e262a3089d996e
+Merge: 604ee54 4ce0d81
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat May 1 04:03:03 2010 -0400
+
+ Merge branch 'master' of git://git.mplayerhq.hu/ffmpeg
+
+commit d812c6f8b1d897734d6f7b5f1a5c95d3aa10a3ea
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Jun 24 02:25:25 2010 -0700
+
+ Fix crash on close when decoding a single-frame h264 file with 3+ threads
+
+ Problematic code path:
+ 1. sps_buffers[0] is allocated in the first thread's codec context when the
+ decoder is opened.
+ 2. The first thread context is memcpy'd to the other threads by frame_thread_init().
+ 3. The first thread is closed and its sps_buffers[0] is freed.
+ 4. The third thread is closed.
+ Because it never got to decode a frame, update_thread_context was never called,
+ and sps_buffers[0] still contained the first thread's pointer.
+
+ Fixed by not trying to free sps/pps buffers if the thread wasn't initialized.
+ I didn't properly consider this when designing it but this seems to be the
+ best approach anyway.
+
+ Fixes still2.mp4 crash from Chromium
+
+commit d84fc3dfd3e051c782d063ccba4cc8cadba38797
+Author: michaelni <michaelni@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
+Date: Tue Nov 5 00:56:08 2002 +0000
+
+ MIN/MAX sys/param.h patch by (Fran
+commit d93fe0ea6b1b8121fdb9521fa7eeac0dc494deeb
+Author: benoit <benoit@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
+Date: Tue Nov 6 16:19:09 2007 +0000
+
+ Allow propagation of stream selection through the ASF demuxer to the
+ MMSH protocol handler.
+ Patch by Bj
+�rn Axelsson: bjorn ; axelsson commit d955ab0dfa73578eaa6a9d1dcb821ce9db409738
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Mar 29 04:53:11 2011 -0400
+
+ Update todo. More items appeared...
+
+commit da70ded7141aa191b92672c343cd29a0014d861f
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Dec 18 13:27:51 2008 -0500
+
+ Update todo
+
+commit da7bdb1273da15a90bfe08ead91e397247916d11
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Jun 24 03:24:17 2008 -0400
+
+ Get rid of tabs
+
+commit da86d2da9f6a76238a9d788ecd77f714981e666d
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Sep 4 01:40:51 2008 -0400
+
+ Reindent.
+
+commit da95175e7ce1f911db992fef213322345200feaf
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Jul 14 01:52:37 2008 -0400
+
+ Add a parameter to not draw top/bottom in draw_edges.
+
+commit db2a99d28931128c8598067ae06444ab79f579f8
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Jun 9 17:29:47 2009 -0700
+
+ Fix typo in comment.
+
+commit dbfbadaa095b65a724ac848d551cfa2aa33e2f6a
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue May 11 05:16:14 2010 -0400
+
+ Update todo.
+
+ Got another h264 bug report with the same cause as before.
+
+commit dc53861aadac1d43391b28e4e9793393b26394b9
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed Jun 18 20:52:34 2008 -0400
+
+ Always set decode progress to the maximum at the end of decoding
+ This saves doing it for frames with AC partitioning and such.
+ We can't do it if the codec didn't return a frame, so there is still an opportunity for deadlocks here, maybe.
+
+commit dc7c4d436681e43a9f351dd18f70d0dc008aa55e
+Author: benoit <benoit@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
+Date: Thu Jan 10 10:18:00 2008 +0000
+
+ Make MMX vectors constants.
+ Patch by Diego 'Flameeyes' Petten
+� flameeyes commit dd9e04497937b7fffdcc65a2b41e36089412d975
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Mar 29 17:18:21 2011 -0400
+
+ Remove unnecessary parameter from ff_thread_init() and fix behavior
+
+ thread_count passed to ff_thread_init() is only used to set AVCodecContext.
+ thread_count, and can be removed. Instead move it to the legacy implementation
+ of avcodec_thread_init().
+
+ This also fixes the problem that calling avcodec_thread_init() with pthreads
+ enabled did not set it since ff1efc524cb3c60f2f746e3b4550bb1a86c65316.
+
+commit ddc8310d2a9300139d1821954dfa2d0b775edaa1
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Feb 11 22:12:03 2010 -0500
+
+ Fix mutex leak introduced in 0040d6f2ba.
+
+ If allocate_progress() failed, the error condition returned before
+ unlocking its mutex.
+
+commit de365823ec9546a3bd688690e79fc15281a68f1f
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed Jun 23 01:26:42 2010 -0700
+
+ todo: fix ugly word wrapping
+
+commit de736aacd945d66109197a6f04baf915d458f5ac
+Merge: 7eac0bc 780a37c
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Jun 18 17:53:09 2009 -0400
+
+ Merge mainline.
+
+commit de8abf54671555bb166bb1d44a34fe14e360e2a5
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Jan 24 16:37:24 2010 -0500
+
+ Rename and document MAX_DELAYED_RELEASED_BUFFERS.
+
+commit dedc2982f2f845357f28dff401fe5df8510c6a8f
+Author: benoit <benoit@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
+Date: Tue May 22 08:28:32 2007 +0000
+
+ id3v2 writer
+ patch by Andreas
+�commit df444fadf045bf70058da9b074b8f848fc2209b1
+Merge: 14bdf76 1476e6a
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Mar 9 02:04:43 2010 -0500
+
+ Merge branch 'master' of git://git.mplayerhq.hu/ffmpeg
+
+commit df5d7acdcd0dcbfca6f8fd4f76c9369cb1674435
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Aug 16 17:32:24 2008 -0400
+
+ Don't reuse the user's AVCodecContext for the first decoding thread, and copy more values between them as needed.
+
+ This fixes a large class of race conditions (coded_frame works again) and should improve frame dropping.
+
+commit dfb8be0a60b9562cf7bb6e54dd67088ff51f83b0
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Jun 24 21:35:14 2008 -0400
+
+ Call avcodec_get_frame_defaults() before decoding.
+
+commit e0285f04bed7fefba5f75d05c81b145f44fc49f5
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Jul 31 18:40:46 2008 -0400
+
+ Use got_extradata instead of frame_number to guard against rereading extradata.
+
+ frame_number is no longer valid internally, since I don't want to change its definition from the user's perspective.
+ mpeg12 does the same thing, but I can't find or create any mpeg1+extradata samples to check it.
+
+commit e044d5c79ab340cf52842ba8452d670959eb37c0
+Merge: 3c3a364 5115473
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Fri Nov 7 04:54:47 2008 -0500
+
+ Merge mainline into ffmpeg-mt
+
+ - Handle reordered_opaque properly
+ - Picture.field_picture is a duplicate of Picture.mbaff,
+ but is necessary, since interlaced_frame can't be trusted
+ and mbaff can't be interpreted without it.
+
+commit e0dc361e0f0aa315320a549a4fda3424226c556f
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Sep 1 03:35:23 2008 -0400
+
+ Update todo
+
+commit e174657cbb973abf5de9085d00d85ac04d29a475
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Aug 28 17:11:09 2008 -0400
+
+ Move avcodec_thread_init call before avcodec_open in ffplay.
+
+ It makes no sense to have it after, since a decoder is not forbidden from reading it during init.
+ Encoders already do.
+
+commit e1f49541b976cdd091aa41f116e7c9fd0c740cf3
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Jun 17 23:35:55 2008 -0400
+
+ Fix rounding for mpeg1 MVs.
+
+commit e23b687201a076161384fbc7a2f76bd0092dd34c
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed Jan 20 02:36:18 2010 -0500
+
+ Include the delay from frame threads in has_b_frames.
+
+ This is an API change, but anything that already counted thread_count
+ just has an incorrectly high max delay size, which shouldn't be a
+ problem.
+
+commit e2b9383929e2c703eabd1df8afcb9fa5ad7106ec
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Jun 15 17:36:59 2008 -0400
+
+ Add choice of threading algorithm to AVCodecContext.
+
+ Use it to simplify USE_* macros.
+ FF_THREAD_AUTO needs to be handled better - even if a codec can handle frame-threads, we still don't want to use them if there are enough slices available.
+
+commit e2ecdd48d664f2660bfd661f1cef6276b986743b
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Fri Jul 25 03:12:58 2008 -0400
+
+ Simplify mpeg_decode_update_context.
+
+commit e303003362829a7f2f1dcbc45d6abc9ac7a59b6a
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Aug 14 22:59:01 2008 -0400
+
+ Reindent.
+
+commit e340cacc56545c5fc3a903c68fec99e8921d579e
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Nov 8 06:13:23 2008 -0500
+
+ Disable r15412 for now to avoid crashes.
+
+ update_context can't handle picture pts not pointing to picture and I couldn't think of a better way to do it at 5 am.
+ May not actually fix anything.
+
+commit e345a54e5f86d9777e4c3ccb04aad84f9cd77ff0
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Mar 8 04:55:43 2010 -0500
+
+ Add optimization note to todo.
+
+commit e39c3828e02fe71ce627170bc8c26a558f29f4b8
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Feb 15 00:39:39 2010 -0500
+
+ Update todo
+
+commit e3f13a4f70b1310309ebb462b1011721cb3692fe
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Sep 4 14:05:31 2008 -0400
+
+ Rename new symbols to be shorter
+
+commit e4565c5731bfcd8808d02f47f115e21dc6fc8b35
+Merge: 4b9ce55 fb61a7c
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Mar 10 02:25:55 2011 -0500
+
+ Merge branch 'master' of git://git.ffmpeg.org/ffmpeg
+
+ Conflicts:
+ .gitignore
+ doc/APIchanges
+ ffplay.c
+ libavcodec/arm/asm-offsets.h
+ libavcodec/avcodec.h
+ libavcodec/h264.c
+ libavcodec/mpegvideo.h
+ libavcodec/options.c
+ libavcodec/pthread.c
+ libavcodec/thread.h
+ libavcodec/utils.c
+ libavcodec/vp3.c
+ libavcodec/vp8.c
+ libavformat/utils.c
+
+commit e45cf6d46cb45e6edcf9e4ac368b2a013ba30158
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Aug 14 04:01:08 2008 -0400
+
+ Add todo and some other files.
+
+ Trailing whitespace in mplayer isn't my fault.
+
+commit e4df986f3d2d3e1be9b0f4eeda463fa854910b8f
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Aug 28 00:41:52 2008 -0400
+
+ Revert unnecessary setting of the wrong variable
+
+commit e53d020b37ca26ffa4cdb22d2b40321897f52ba9
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Aug 23 20:39:06 2008 -0400
+
+ Warn if users try to use frame threading without pthreads.
+
+commit e717770ee8437c296e012e908b772ba2eaeb2ed3
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Jul 15 03:16:22 2008 -0400
+
+ Create next_delayed_pic for multithreading purposes
+ unreference_pic is intentionally unchanged.
+
+commit e71a2b5017728022fa1f992a8b541260615016b2
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed Jun 18 23:22:01 2008 -0400
+
+ Use USE_FRAME_THREADING instead of checking for thread_opaque, since it might be the wrong type.
+
+commit e74ef89858732b9fc4a90c8ec8fbb701407eb987
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed May 28 22:50:22 2008 -0400
+
+ Split setting avctx->thread_count from the rest of pthread init.
+ Make sure it's called from whichever of avcodec_open and avcodec_thread_init comes later.
+
+commit e7519b6532409e332fc9727ea5a57e148e6655a6
+Author: benoit <benoit@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
+Date: Thu May 15 01:03:48 2008 +0000
+
+ Make av_set_string() fail when number could not be set.
+ Patch by Stefano Sabatini stefanocommit e8bc7da9d69234ebbcbde371c5a0e20f8b5cfccc
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Jan 25 02:59:00 2010 -0500
+
+ Remove accidental extra variable declaration
+
+commit e95251807c0ae66ffef1e4ad113b9773a287fa5a
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Jun 27 22:14:45 2009 -0400
+
+ Get rid of static variables in VP3.
+
+ These are pointless and might behave wrong with thread-local
+ statics.
+
+commit e9a0e5eaf5207321baf90160b1094300f3810ecf
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Jun 23 21:21:44 2008 -0400
+
+ Use FF_INPUT_BUFFER_PADDING_SIZE for the buffer.
+
+commit ea396d38059476a54c5855e0bd81955c60238b22
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed Nov 3 22:50:02 2010 -0400
+
+ Rewrite comments in thread.h and fix parameter names in ff_thread_decode_frame
+
+commit ebce21c15f3aaf1b4512436ed8fc2e71a504bb11
+Merge: 3630d89 5570afd
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Dec 18 12:49:54 2008 -0500
+
+ Merge mainline.
+
+ Conflicts:
+
+ libavcodec/avcodec.h
+ libavcodec/mpegvideo.c
+ libavcodec/utils.c
+
+commit ed3e2ae1277cc425ef133f10700ace86629381ef
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Jul 13 16:05:09 2008 -0400
+
+ Remove useless variable.
+
+commit ed42183540e2a886a7368b8220e0b50aaf363551
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Sep 30 16:53:03 2010 -0400
+
+ Fix hang decoding VP3/Theora.
+
+ draw_horiz_band changed to only draw the displayed height instead of the
+ decoded height. This meant that we never reported progress for the last few
+ decoded pixels, but still awaited them, which deadlocked.
+
+ This shouldn't cause any race conditions, because it always decodes the last
+ few pixels along with the last decoded pixels.
+
+ Patch by Yuriy Kaminsky (yumkam mail ru).
+
+commit ed5e8392e2fce8e6b0468de4ae1a4310d338ee46
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Aug 28 02:29:08 2008 -0400
+
+ Simplify(?) threaded avcodec_flush_buffers
+
+commit ed728b0a05c2154b07cc3d8330d5900dbc45f1d7
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue May 27 23:25:47 2008 -0400
+
+ Guard against avcodec_thread_execute() being called without being setup.
+
+commit edb60439feb2c5d39cda314178686eea151185b3
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Nov 1 12:54:47 2010 -0400
+
+ vp3: Assume MVs are their maximum length of 16 pixels
+
+ This makes it worse (although slightly simpler) in preparation for further
+ optimization.
+
+commit ee8430539ec7cc23b7cf6332e26751f539315d5b
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Jul 6 15:56:28 2008 -0400
+
+ Don't include the codecs' threading support functions without some kind of threading enabled.
+ As a side effect this makes non-pthreads threading even more problematic.
+
+commit eed4b9708287066ccc1b3042110f7c3379f63ee2
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Aug 28 01:44:44 2008 -0400
+
+ Simplify disabling MB skipping
+
+commit ef26f878e0e581cb61f1e9b376bec4f7ff07397a
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Mar 9 01:48:18 2010 -0500
+
+ Cosmetics: fix outdated comment
+
+commit ef2d8664f1eff56e969801ecd1c5b7c729902819
+Merge: 11b1a8e 9c7037f
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Jun 8 14:29:22 2010 -0700
+
+ Merge mainline and libswscale
+
+commit efd1fb08db3e7964357dc00fd514cfb156b4ee69
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Jun 11 11:33:09 2009 -0700
+
+ Reindent.
+
+commit f139f42301a5ee861f1a91cdfcceb2a85349fa29
+Merge: 70fb3fd 7210b4e
+Author: Luca Barbato <lu_zero@gentoo.org>
+Date: Sun Jun 22 12:08:59 2008 +0200
+
+ Merge branch 'master' of git://git.mplayerhq.hu/ffmpeg
+
+commit f143b66d9bf8b23985bf8ec6acf8273c3e9ccd1d
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Aug 19 21:12:32 2008 -0400
+
+ Handle NULL threads if they aren't started because of an init error.
+
+commit f1936d87290c7444090d6cb101b0d7c9270f0a81
+Author: benoit <benoit@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
+Date: Thu Jun 24 15:22:33 2010 +0000
+
+ Set an opaque alpha value when decoding rgba ffv1.
+ Patch by Thad Ward coderjoe69commit f1fe312cb47cbc540da764cbab3582739a20a8d2
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Jun 5 20:30:58 2008 -0400
+
+ Cosmetics: make thread.h look like other prototypes.
+
+commit f374d2ee585d7f6c98ffd3a7803223552497904e
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Fri Jan 21 04:13:06 2011 -0500
+
+ Simplify change to avcodec_close() and fix a merge glitch in avcodec_open()
+
+commit f3c88f32b8c806b352cf6e00d6ac80fd32e9f54c
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed Sep 3 11:45:09 2008 -0400
+
+ Field picture API support
+
+commit f3f3d1189de648862ca204676dd7591262f590df
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Jan 25 04:12:34 2010 -0500
+
+ Add todo note about a change to thread.h I mean to do.
+
+commit f4d4d43f3a596941b2214ac1e71bb818eb230d6b
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Fri Jan 21 02:43:30 2011 -0500
+
+ Minor update to thread.h comment
+
+commit f4fb456b114eafc22b8ab9bb0bb3e7f13a4fbd9a
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Nov 2 02:56:12 2010 -0400
+
+ vp3: Revert motion_y removal
+
+ Although it doesn't have much of an effect on speed either way, I reconsidered
+ the simplification I wanted to do, and now I'd rather keep this as an example
+ of proper multithreading structure.
+
+commit f52df8ebae0ad1db15c5e804a458ca81e04c6156
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Aug 25 14:33:09 2008 -0400
+
+ Fix whitespace mistake
+
+commit f550857de3ffcb6b2980c4c952b7e84db478d399
+Merge: d62b7c0 a175a04
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Mar 27 02:01:59 2010 -0400
+
+ Merge mainline.
+
+ Conflicts:
+ libavcodec/avcodec.h
+ libavcodec/h264.c
+ libavcodec/options.c
+ libavcodec/vp3.c
+
+commit f5596f046c05bc7d8afda7658f891d69587934f0
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon Nov 15 01:38:36 2010 -0500
+
+ Rewrite comments and cosmetic changes to pthread.c
+
+ Some small code changes, but there shouldn't be any behavior change.
+
+commit f695698a78e07a45f4cc9d24ae95fd73f25600e7
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed Jan 26 12:43:05 2011 -0500
+
+ Update todo.txt with review feedback
+
+commit f6d7d0c03c8d7c91a39c9374d9cee83e32627681
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Feb 6 19:04:21 2011 -0500
+
+ pthread: Cosmetic changes and renaming
+
+ Rename frame->packet, picture->frame.
+ Use /**< to point to the right field in doxygen.
+ Fix some typos.
+
+commit f71e7068faabecc32abc798a09b9df403f85e33f
+Merge: 2bbb64d a4f892e
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Jan 6 05:45:03 2011 -0500
+
+ Merge mainline.
+
+ Conflicts:
+ doc/APIchanges
+
+commit f7cc4441b7046a542ef655575ce3e8684ff12e02
+Merge: bba0e09 9eac0a6
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Jun 20 15:58:38 2009 -0400
+
+ Merge mainline.
+
+commit f9515a4e57356bce4d652451fbaccd071d91dbe9
+Merge: a903974 0c28ee7
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed Nov 11 15:38:20 2009 -0500
+
+ Merge mainline.
+
+ In h264, next_outputed_poc is now used in decode_postinit()
+ where mainline uses outputed_poc.
+
+ Conflicts:
+ libavcodec/avcodec.h
+ libavcodec/h263dec.c
+ libavcodec/h264.c
+ libavcodec/utils.c
+
+commit f9b01bbf85d68f23a81ec5325fae81c8518cc385
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon May 25 20:06:00 2009 -0400
+
+ Remove unnecessary check from mc_dir_part_y().
+
+ This was already remove from mc_dir_part(). I hope it's unnecessary
+ here too.
+
+commit fa3f68f39f4a96a1170eadfe6ba4677d5d25017f
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Aug 16 04:23:20 2008 -0400
+
+ Document functions in thread.h
+
+commit fa8a82e991280b7ccac89ed2a29b332e609bc370
+Author: Luca Barbato <lu_zero@gentoo.org>
+Date: Sat May 3 15:18:01 2008 +0200
+
+ Switch to the gitorius mirror of libswscale
+
+commit fafaae289235b361b6786745dcbdf6fa938c3c2e
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Dec 4 01:46:22 2008 -0500
+
+ Don't compare pthread_t to NULL
+
+ It's not required to be a pointer, and it doesn't
+ need to be validated since pthread_join will just
+ return an error if it doesn't exist.
+
+ Reverts f143b66d9bf8b23985bf8ec6acf8273c3e9ccd1d
+
+commit fb1afd9eba5fe2752b83c4b3de24ed88e14b534a
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Mar 14 00:56:54 2009 -0400
+
+ Rewrite todo (again...) split up so other people should be able to understand it.
+ Add yuvcmp, though maybe it should go somewhere else.
+
+commit fb1f31ff6cbcbbde72920e731223fd0fb8f05d02
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Aug 30 04:26:47 2008 -0400
+
+ Update multithreading doc
+
+commit fb7dfc0e9e9ff8a5030cde46e28d49d6ce73e453
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Jan 24 22:15:56 2010 -0500
+
+ Always call avcodec_thread_init() in avcodec_open().
+
+ This matches upstream behavior, but neither of them have any effect.
+ It allows implementing automatic thread counts, though.
+
+commit fbb871069bd106bfd47d215216be01d1ef30aec8
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Feb 14 23:47:42 2010 -0500
+
+ Reindent vp3.c.
+
+commit fc957c71da6c9a7e5c769e15f256652352f7b4a4
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon May 24 17:31:38 2010 -0400
+
+ Fix compile with --disable-optimizations.
+
+ gcc can't remove dead code like:
+ int threaded = HAVE_PTHREADS;
+ if (threaded) ...
+
+commit fd1b8587a4186b30c5922e3053c869726cca23df
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Nov 4 03:55:19 2010 -0400
+
+ Remove ff_thread_finish_frame() as it seems not useful enough
+
+commit fd9ae0065aa268c4b3e46706d775cf4ba1df8ed3
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed May 28 01:34:30 2008 -0400
+
+ Obfusticate the decoder to make the context copyable earlier.
+
+commit fda3e64cd474b5886457c6a1ffff8906f76a9bbc
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Thu Jun 18 16:11:26 2009 -0400
+
+ Mimic: move up a line changing buf_ptrs.
+
+ No effect on decoding, but it breaks the rule about changing
+ things after frame_setup_done.
+
+commit fdb381e68a3828dcc7eb1c93cf174b702cc78d2c
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed Feb 17 00:39:42 2010 -0500
+
+ Cosmetics: rename function parameters
+
+commit fe4e238f573bab53760408b3376dbba0255e5b51
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon May 25 20:00:50 2009 -0400
+
+ Fix unnecessarily long wait for direct+progressive MBs.
+
+commit fe529c93b41f2d7406b76e7e5943b82acd789cb4
+Author: benoit <benoit@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
+Date: Tue May 22 08:23:45 2007 +0000
+
+ id3v2 reader
+ patch by Andreas
+�commit febe154099b8f31817e8c047cb3c8dee51b52117
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Wed Jun 16 14:54:00 2010 -0700
+
+ Fix merge glitch: pix_fmts should have been deleted
+
+commit feca6e0009da2b344b2c1be8f30a55c23623d77e
+Merge: 2485cfd feaafaa
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Mon May 25 19:58:17 2009 -0400
+
+ Merge branch 'master' of git://git.mplayerhq.hu/ffmpeg
+
+commit ff08d3a1629ab442f78a1d2fde496b727a1a9deb
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sat Jul 12 22:26:43 2008 -0400
+
+ Fix MPV_lowest_referenced_row to not be completely wrong.
+ The not handling qpel and emu_edge bugs were masked by the other bugs preventing almost all parallelism.
+
+commit ff4c627baab555a4ea6275c919d9f4259adc0e58
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Tue Oct 6 15:41:35 2009 -0400
+
+ Word-wrap todo.txt.
+
+ Try to make some of it cleaner
+ so other people can actually
+ use it.
+
+commit ff69da3564ab912f7e7331f8c8389a96a254e16f
+Author: Alexander Strange <astrange@ithinksw.com>
+Date: Sun Aug 1 20:33:57 2010 -0700
+
+ Fix the decoder not returning any frames if the frame count is less than the number of threads
+
+ Fixes ./mt-work/test.sh with still2.mp4
+
diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index cabf395582..c59c757535 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -15,7 +15,7 @@ The generic syntax is:
@example
@c man begin SYNOPSIS
-ffmpeg [[infile options][@option{-i} @var{infile}]]... @{[outfile options] @var{outfile}@}...
+ffmpeg [global options] [[infile options][@option{-i} @var{infile}]]... @{[outfile options] @var{outfile}@}...
@c man end
@end example
@@ -26,15 +26,12 @@ ffmpeg is a very fast video and audio converter that can also grab from
a live audio/video source. It can also convert between arbitrary sample
rates and resize video on the fly with a high quality polyphase filter.
-The command line interface is designed to be intuitive, in the sense
-that ffmpeg tries to figure out all parameters that can possibly be
-derived automatically. You usually only have to specify the target
-bitrate you want.
-
As a general rule, options are applied to the next specified
file. Therefore, order is important, and you can have the same
option on the command line multiple times. Each occurrence is
then applied to the next input or output file.
+Exceptions from this rule are the global options (e.g. verbosity level),
+which should be specified first.
@itemize
@item
@@ -59,51 +56,85 @@ ffmpeg -r 1 -i input.m2v -r 24 output.avi
The format option may be needed for raw input files.
-By default ffmpeg tries to convert as losslessly as possible: It
-uses the same audio and video parameters for the outputs as the one
-specified for the inputs.
-
@c man end DESCRIPTION
+@chapter Stream selection
+@c man begin STREAM SELECTION
+
+By default ffmpeg tries to pick the "best" stream of each type present in input
+files and add them to each output file. For video, this means the highest
+resolution, for audio the highest channel count. For subtitle it's simply the
+first subtitle stream.
+
+You can disable some of those defaults by using @code{-vn/-an/-sn} options. For
+full manual control, use the @code{-map} option, which disables the defaults just
+described.
+
+@c man end STREAM SELECTION
+
@chapter Options
@c man begin OPTIONS
-@include fftools-common-opts.texi
+@include avtools-common-opts.texi
@section Main options
@table @option
-@item -f @var{fmt}
-Force format.
+@item -f @var{fmt} (@emph{input/output})
+Force input or output file format. The format is normally autodetected for input
+files and guessed from file extension for output files, so this option is not
+needed in most cases.
-@item -i @var{filename}
+@item -i @var{filename} (@emph{input})
input file name
-@item -y
-Overwrite output files.
+@item -y (@emph{global})
+Overwrite output files without asking.
+
+@item -c[:@var{stream_specifier}] @var{codec} (@emph{input/output,per-stream})
+@itemx -codec[:@var{stream_specifier}] @var{codec} (@emph{input/output,per-stream})
+Select an encoder (when used before an output file) or a decoder (when used
+before an input file) for one or more streams. @var{codec} is the name of a
+decoder/encoder or a special value @code{copy} (output only) to indicate that
+the stream is not to be reencoded.
-@item -t @var{duration}
-Restrict the transcoded/captured video sequence
-to the duration specified in seconds.
-@code{hh:mm:ss[.xxx]} syntax is also supported.
+For example
+@example
+ffmpeg -i INPUT -map 0 -c:v libx264 -c:a copy OUTPUT
+@end example
+encodes all video streams with libx264 and copies all audio streams.
-@item -fs @var{limit_size}
+For each stream, the last matching @code{c} option is applied, so
+@example
+ffmpeg -i INPUT -map 0 -c copy -c:v:1 libx264 -c:a:137 libvorbis OUTPUT
+@end example
+will copy all the streams except the second video, which will be encoded with
+libx264, and the 138th audio, which will be encoded with libvorbis.
+
+@item -t @var{duration} (@emph{output})
+Stop writing the output after its duration reaches @var{duration}.
+@var{duration} may be a number in seconds, or in @code{hh:mm:ss[.xxx]} form.
+
+@item -fs @var{limit_size} (@emph{output})
Set the file size limit.
-@item -ss @var{position}
-Seek to given time position in seconds.
-@code{hh:mm:ss[.xxx]} syntax is also supported.
+@item -ss @var{position} (@emph{input/output})
+When used as an input option (before @code{-i}), seeks in this input file to
+@var{position}. When used as an output option (before an output filename),
+decodes but discards input until the timestamps reach @var{position}. This is
+slower, but more accurate.
+
+@var{position} may be either in seconds or in @code{hh:mm:ss[.xxx]} form.
-@item -itsoffset @var{offset}
+@item -itsoffset @var{offset} (@emph{input})
Set the input time offset in seconds.
@code{[-]hh:mm:ss[.xxx]} syntax is also supported.
-This option affects all the input files that follow it.
The offset is added to the timestamps of the input files.
Specifying a positive offset means that the corresponding
-streams are delayed by 'offset' seconds.
+streams are delayed by @var{offset} seconds.
-@item -timestamp @var{time}
+@item -timestamp @var{time} (@emph{output})
Set the recording timestamp in the container.
The syntax for @var{time} is:
@example
@@ -115,21 +146,35 @@ interpreted as UTC.
If the year-month-day part is not specified it takes the current
year-month-day.
-@item -metadata @var{key}=@var{value}
+@item -metadata[:metadata_specifier] @var{key}=@var{value} (@emph{output,per-metadata})
Set a metadata key/value pair.
+An optional @var{metadata_specifier} may be given to set metadata
+on streams or chapters. See @code{-map_metadata} documentation for
+details.
+
+This option overrides metadata set with @code{-map_metadata}. It is
+also possible to delete metadata by using an empty value.
+
For example, for setting the title in the output file:
@example
ffmpeg -i in.avi -metadata title="my title" out.flv
@end example
-@item -v @var{number}
-Set the logging verbosity level.
+To set the language of the second stream:
+@example
+ffmpeg -i INPUT -metadata:s:1 language=eng OUTPUT
+@end example
-@item -target @var{type}
-Specify target file type ("vcd", "svcd", "dvd", "dv", "dv50", "pal-vcd",
-"ntsc-svcd", ... ). All the format options (bitrate, codecs,
-buffer sizes) are then set automatically. You can just type:
+@item -v @var{number} (@emph{global})
+This option is deprecated and has no effect, use -loglevel
+to set verbosity level.
+
+@item -target @var{type} (@emph{output})
+Specify target file type (@code{vcd}, @code{svcd}, @code{dvd}, @code{dv},
+@code{dv50}). @var{type} may be prefixed with @code{pal-}, @code{ntsc-} or
+@code{film-} to use the corresponding standard. All the format options
+(bitrate, codecs, buffer sizes) are then set automatically. You can just type:
@example
ffmpeg -i myfile.avi -target vcd /tmp/vcd.mpg
@@ -142,30 +187,32 @@ they do not conflict with the standard, as in:
ffmpeg -i myfile.avi -target vcd -bf 2 /tmp/vcd.mpg
@end example
-@item -dframes @var{number}
-Set the number of data frames to record.
+@item -dframes @var{number} (@emph{output})
+Set the number of data frames to record. This is an alias for @code{-frames:d}.
-@item -scodec @var{codec}
-Force subtitle codec ('copy' to copy stream).
+@item -frames[:@var{stream_specifier}] @var{framecount} (@emph{output,per-stream})
+Stop writing to the stream after @var{framecount} frames.
-@item -newsubtitle
-Add a new subtitle stream to the current output stream.
+@item -q[:@var{stream_specifier}] @var{q} (@emph{output,per-stream})
+@itemx -qscale[:@var{stream_specifier}] @var{q} (@emph{output,per-stream})
+Use fixed quality scale (VBR). The meaning of @var{q} is
+codec-dependent.
-@item -slang @var{code}
-Set the ISO 639 language code (3 letters) of the current subtitle stream.
+@item -filter[:@var{stream_specifier}] @var{filter_graph}
+@var{filter_graph} is a description of the filter graph to apply to
+the stream. Use @code{-filters} to show all the available filters
+(including also sources and sinks).
@end table
@section Video Options
@table @option
-@item -b @var{bitrate}
-Set the video bitrate in bit/s (default = 200 kb/s).
-@item -vframes @var{number}
-Set the number of video frames to record.
-@item -r @var{fps}
+@item -vframes @var{number} (@emph{output})
+Set the number of video frames to record. This is an alias for @code{-frames:v}.
+@item -r[:@var{stream_specifier}] @var{fps} (@emph{input/output,per-stream})
Set frame rate (Hz value, fraction or abbreviation), (default = 25).
-@item -s @var{size}
+@item -s[:@var{stream_specifier}] @var{size} (@emph{input/output,per-stream})
Set frame size. The format is @samp{wxh} (ffserver default = 160x128, ffmpeg default = same as source).
The following abbreviations are recognized:
@table @samp
@@ -229,7 +276,7 @@ The following abbreviations are recognized:
1920x1080
@end table
-@item -aspect @var{aspect}
+@item -aspect[:@var{stream_specifier}] @var{aspect} (@emph{output,per-stream})
Set the video display aspect ratio specified by @var{aspect}.
@var{aspect} can be a floating point number string, or a string of the
@@ -251,7 +298,8 @@ crop=width:height:x:y instead.
@item -padcolor @var{hex_color}
All the pad options have been removed. Use -vf
pad=width:height:x:y:color instead.
-@item -vn
+
+@item -vn (@emph{output})
Disable video recording.
@item -bt @var{tolerance}
Set video bitrate tolerance (in bits, default 4000k).
@@ -272,12 +320,14 @@ ffmpeg -i myfile.avi -b 4000k -minrate 4000k -maxrate 4000k -bufsize 1835k out.m
It is of little use elsewise.
@item -bufsize @var{size}
Set video buffer verifier buffer size (in bits).
-@item -vcodec @var{codec}
-Force video codec to @var{codec}. Use the @code{copy} special value to
-tell that the raw codec data must be copied as is.
-@item -sameq
+@item -vcodec @var{codec} (@emph{output})
+Set the video codec. This is an alias for @code{-codec:v}.
+@item -same_quant
Use same quantizer as source (implies VBR).
+Note that this is NOT SAME QUALITY. Do not use this option unless you know you
+need it.
+
@item -pass @var{n}
Select the pass number (1 or 2). It is used to do two-pass
video encoding. The statistics of the video are recorded in the first
@@ -287,46 +337,41 @@ at the exact requested bitrate.
On pass 1, you may just deactivate audio and set output to null,
examples for Windows and Unix:
@example
-ffmpeg -i foo.mov -vcodec libxvid -pass 1 -an -f rawvideo -y NUL
-ffmpeg -i foo.mov -vcodec libxvid -pass 1 -an -f rawvideo -y /dev/null
+ffmpeg -i foo.mov -c:v libxvid -pass 1 -an -f rawvideo -y NUL
+ffmpeg -i foo.mov -c:v libxvid -pass 1 -an -f rawvideo -y /dev/null
@end example
-@item -passlogfile @var{prefix}
+@item -passlogfile @var{prefix} (@emph{global})
Set two-pass log file name prefix to @var{prefix}, the default file name
prefix is ``ffmpeg2pass''. The complete file name will be
@file{PREFIX-N.log}, where N is a number specific to the output
-stream.
-
-@item -newvideo
-Add a new video stream to the current output stream.
+stream
@item -vlang @var{code}
Set the ISO 639 language code (3 letters) of the current video stream.
-@item -vf @var{filter_graph}
+@item -vf @var{filter_graph} (@emph{output})
@var{filter_graph} is a description of the filter graph to apply to
the input video.
Use the option "-filters" to show all the available filters (including
-also sources and sinks).
+also sources and sinks). This is an alias for @code{-filter:v}.
@end table
@section Advanced Video Options
@table @option
-@item -pix_fmt @var{format}
-Set pixel format. Use 'list' as parameter to show all the supported
+@item -pix_fmt[:@var{stream_specifier}] @var{format} (@emph{input/output,per-stream})
+Set pixel format. Use @code{-pix_fmts} to show all the supported
pixel formats.
-@item -sws_flags @var{flags}
+@item -sws_flags @var{flags} (@emph{input/output})
Set SwScaler flags.
@item -g @var{gop_size}
Set the group of pictures size.
@item -intra
-Use only intra frames.
+deprecated, use -g 1
@item -vdt @var{n}
Discard threshold.
-@item -qscale @var{q}
-Use fixed video quantizer scale (VBR).
@item -qmin @var{q}
minimum video quantizer scale (VBR)
@item -qmax @var{q}
@@ -398,8 +443,11 @@ and the following constants are available:
@item avgTex
@end table
-@item -rc_override @var{override}
-rate control override for specific intervals
+@item -rc_override[:@var{stream_specifier}] @var{override} (@emph{output,per-stream})
+Rate control override for specific intervals, formated as "int,int,int"
+list separated with slashes. Two first values are the beginning and
+end frame numbers, last one is quantizer to use if positive, or quality
+factor if negative.
@item -me_method @var{method}
Set motion estimation method to @var{method}.
Available methods are (from lowest to best quality):
@@ -524,20 +572,17 @@ Calculate PSNR of compressed frames.
Dump video coding statistics to @file{vstats_HHMMSS.log}.
@item -vstats_file @var{file}
Dump video coding statistics to @var{file}.
-@item -top @var{n}
+@item -top[:@var{stream_specifier}] @var{n} (@emph{output,per-stream})
top=1/bottom=0/auto=-1 field first
@item -dc @var{precision}
Intra_dc_precision.
-@item -vtag @var{fourcc/tag}
-Force video tag/fourcc.
-@item -qphist
-Show QP histogram.
+@item -vtag @var{fourcc/tag} (@emph{output})
+Force video tag/fourcc. This is an alias for @code{-tag:v}.
+@item -qphist (@emph{global})
+Show QP histogram
@item -vbsf @var{bitstream_filter}
-Bitstream filters available are "dump_extra", "remove_extra", "noise", "h264_mp4toannexb", "imxdump", "mjpegadump", "mjpeg2jpeg".
-@example
-ffmpeg -i h264.mp4 -vcodec copy -vbsf h264_mp4toannexb -an out.h264
-@end example
-@item -force_key_frames @var{time}[,@var{time}...]
+Deprecated see -bsf
+@item -force_key_frames[:@var{stream_specifier}] @var{time}[,@var{time}...] (@emph{output,per-stream})
Force key frames at the specified timestamps, more precisely at the first
frames after each specified time.
This option can be useful to ensure that a seek point is present at a
@@ -548,48 +593,34 @@ The timestamps must be specified in ascending order.
@section Audio Options
@table @option
-@item -aframes @var{number}
-Set the number of audio frames to record.
-@item -ar @var{freq}
-Set the audio sampling frequency. For input streams it is set by
-default to 44100 Hz, for output streams it is set by default to the
-frequency of the input stream. If the input file has audio streams
-with different frequencies, the behaviour is undefined.
-@item -ab @var{bitrate}
-Set the audio bitrate in bit/s (default = 64k).
-@item -aq @var{q}
-Set the audio quality (codec-specific, VBR).
-@item -ac @var{channels}
-Set the number of audio channels. For input streams it is set by
-default to 1, for output streams it is set by default to the same
-number of audio channels in input. If the input file has audio streams
-with different channel count, the behaviour is undefined.
-@item -an
+@item -aframes @var{number} (@emph{output})
+Set the number of audio frames to record. This is an alias for @code{-frames:a}.
+@item -ar[:@var{stream_specifier}] @var{freq} (@emph{input/output,per-stream})
+Set the audio sampling frequency. For output streams it is set by
+default to the frequency of the corresponding input stream. For input
+streams this option only makes sense for audio grabbing devices and raw
+demuxers and is mapped to the corresponding demuxer options.
+@item -aq @var{q} (@emph{output})
+Set the audio quality (codec-specific, VBR). This is an alias for -q:a.
+@item -ac[:@var{stream_specifier}] @var{channels} (@emph{input/output,per-stream})
+Set the number of audio channels. For output streams it is set by
+default to the number of input audio channels. For input streams
+this option only makes sense for audio grabbing devices and raw demuxers
+and is mapped to the corresponding demuxer options.
+@item -an (@emph{output})
Disable audio recording.
-@item -acodec @var{codec}
-Force audio codec to @var{codec}. Use the @code{copy} special value to
-specify that the raw codec data must be copied as is.
-@item -newaudio
-Add a new audio track to the output file. If you want to specify parameters,
-do so before @code{-newaudio} (@code{-acodec}, @code{-ab}, etc..).
-
-Mapping will be done automatically, if the number of output streams is equal to
-the number of input streams, else it will pick the first one that matches. You
-can override the mapping using @code{-map} as usual.
-
-Example:
-@example
-ffmpeg -i file.mpg -vcodec copy -acodec ac3 -ab 384k test.mpg -acodec mp2 -ab 192k -newaudio
-@end example
-@item -alang @var{code}
-Set the ISO 639 language code (3 letters) of the current audio stream.
+@item -acodec @var{codec} (@emph{input/output})
+Set the audio codec. This is an alias for @code{-codec:a}.
+@item -sample_fmt[:@var{stream_specifier}] @var{sample_fmt} (@emph{output,per-stream})
+Set the audio sample format. Use @code{-help sample_fmts} to get a list
+of supported sample formats.
@end table
@section Advanced Audio options:
@table @option
-@item -atag @var{fourcc/tag}
-Force audio tag/fourcc.
+@item -atag @var{fourcc/tag} (@emph{output})
+Force audio tag/fourcc. This is an alias for @code{-tag:a}.
@item -audio_service_type @var{type}
Set the type of service that the audio stream contains.
@table @option
@@ -613,91 +644,93 @@ Voice Over
Karaoke
@end table
@item -absf @var{bitstream_filter}
-Bitstream filters available are "dump_extra", "remove_extra", "noise", "mp3comp", "mp3decomp".
+Deprecated, see -bsf
@end table
@section Subtitle options:
@table @option
-@item -scodec @var{codec}
-Force subtitle codec ('copy' to copy stream).
-@item -newsubtitle
-Add a new subtitle stream to the current output stream.
@item -slang @var{code}
Set the ISO 639 language code (3 letters) of the current subtitle stream.
-@item -sn
+@item -scodec @var{codec} (@emph{input/output})
+Set the subtitle codec. This is an alias for @code{-codec:s}.
+@item -sn (@emph{output})
Disable subtitle recording.
@item -sbsf @var{bitstream_filter}
-Bitstream filters available are "mov2textsub", "text2movsub".
-@example
-ffmpeg -i file.mov -an -vn -sbsf mov2textsub -scodec copy -f rawvideo sub.txt
-@end example
+Deprecated, see -bsf
@end table
@section Audio/Video grab options
@table @option
-@item -vc @var{channel}
-Set video grab channel (DV1394 only).
-@item -tvstd @var{standard}
-Set television standard (NTSC, PAL (SECAM)).
-@item -isync
+@item -isync (@emph{global})
Synchronize read on input.
@end table
@section Advanced options
@table @option
-@item -map @var{input_file_id}.@var{input_stream_id}[:@var{sync_file_id}.@var{sync_stream_id}]
+@item -map [-]@var{input_file_id}[:@var{stream_specifier}][,@var{sync_file_id}[:@var{stream_specifier}]] (@emph{output})
-Designate an input stream as a source for the output file. Each input
+Designate one or more input streams as a source for the output file. Each input
stream is identified by the input file index @var{input_file_id} and
the input stream index @var{input_stream_id} within the input
-file. Both indexes start at 0. If specified,
-@var{sync_file_id}.@var{sync_stream_id} sets which input stream
+file. Both indices start at 0. If specified,
+@var{sync_file_id}:@var{stream_specifier} sets which input stream
is used as a presentation sync reference.
-The @code{-map} options must be specified just after the output file.
-If any @code{-map} options are used, the number of @code{-map} options
-on the command line must match the number of streams in the output
-file. The first @code{-map} option on the command line specifies the
+The first @code{-map} option on the command line specifies the
source for output stream 0, the second @code{-map} option specifies
the source for output stream 1, etc.
+A @code{-} character before the stream identifier creates a "negative" mapping.
+It disables matching streams from already created mappings.
+
+For example, to map ALL streams from the first input file to output
+@example
+ffmpeg -i INPUT -map 0 output
+@end example
+
For example, if you have two audio streams in the first input file,
-these streams are identified by "0.0" and "0.1". You can use
-@code{-map} to select which stream to place in an output file. For
+these streams are identified by "0:0" and "0:1". You can use
+@code{-map} to select which streams to place in an output file. For
example:
@example
-ffmpeg -i INPUT out.wav -map 0.1
+ffmpeg -i INPUT -map 0:1 out.wav
@end example
-will map the input stream in @file{INPUT} identified by "0.1" to
+will map the input stream in @file{INPUT} identified by "0:1" to
the (single) output stream in @file{out.wav}.
For example, to select the stream with index 2 from input file
-@file{a.mov} (specified by the identifier "0.2"), and stream with
-index 6 from input @file{b.mov} (specified by the identifier "1.6"),
+@file{a.mov} (specified by the identifier "0:2"), and stream with
+index 6 from input @file{b.mov} (specified by the identifier "1:6"),
and copy them to the output file @file{out.mov}:
@example
-ffmpeg -i a.mov -i b.mov -vcodec copy -acodec copy out.mov -map 0.2 -map 1.6
+ffmpeg -i a.mov -i b.mov -c copy -map 0:2 -map 1:6 out.mov
@end example
-To add more streams to the output file, you can use the
-@code{-newaudio}, @code{-newvideo}, @code{-newsubtitle} options.
+To select all video and the third audio stream from an input file:
+@example
+ffmpeg -i INPUT -map 0:v -map 0:a:2 OUTPUT
+@end example
-@item -map_meta_data @var{outfile}[,@var{metadata}]:@var{infile}[,@var{metadata}]
-Deprecated, use @var{-map_metadata} instead.
+To map all the streams except the second audio, use negative mappings
+@example
+ffmpeg -i INPUT -map 0 -map -0:a:1 OUTPUT
+@end example
+
+Note that using this option disables the default mappings for this output file.
-@item -map_metadata @var{outfile}[,@var{metadata}]:@var{infile}[,@var{metadata}]
-Set metadata information of @var{outfile} from @var{infile}. Note that those
-are file indices (zero-based), not filenames.
-Optional @var{metadata} parameters specify, which metadata to copy - (g)lobal
+@item -map_metadata[:@var{metadata_type}][:@var{index}] @var{infile}[:@var{metadata_type}][:@var{index}] (@emph{output,per-metadata})
+Set metadata information of the next output file from @var{infile}. Note that
+those are file indices (zero-based), not filenames.
+Optional @var{metadata_type} parameters specify, which metadata to copy - (g)lobal
(i.e. metadata that applies to the whole file), per-(s)tream, per-(c)hapter or
per-(p)rogram. All metadata specifiers other than global must be followed by the
-stream/chapter/program number. If metadata specifier is omitted, it defaults to
+stream/chapter/program index. If metadata specifier is omitted, it defaults to
global.
-By default, global metadata is copied from the first input file to all output files,
+By default, global metadata is copied from the first input file,
per-stream and per-chapter metadata is copied along with streams/chapters. These
default mappings are disabled by creating any mapping of the relevant type. A negative
file index can be used to create a dummy mapping that just disables automatic copying.
@@ -705,35 +738,69 @@ file index can be used to create a dummy mapping that just disables automatic co
For example to copy metadata from the first stream of the input file to global metadata
of the output file:
@example
-ffmpeg -i in.ogg -map_metadata 0:0,s0 out.mp3
+ffmpeg -i in.ogg -map_metadata 0:s:0 out.mp3
@end example
-@item -map_chapters @var{outfile}:@var{infile}
-Copy chapters from @var{infile} to @var{outfile}. If no chapter mapping is specified,
-then chapters are copied from the first input file with at least one chapter to all
-output files. Use a negative file index to disable any chapter copying.
-@item -debug
+@item -map_chapters @var{input_file_index} (@emph{output})
+Copy chapters from input file with index @var{input_file_index} to the next
+output file. If no chapter mapping is specified, then chapters are copied from
+the first input file with at least one chapter. Use a negative file index to
+disable any chapter copying.
+@item -debug @var{category}
Print specific debug info.
-@item -benchmark
+@var{category} is a number or a string containing one of the following values:
+@table @samp
+@item bitstream
+@item buffers
+picture buffer allocations
+@item bugs
+@item dct_coeff
+@item er
+error recognition
+@item mb_type
+macroblock (MB) type
+@item mmco
+memory management control operations (H.264)
+@item mv
+motion vector
+@item pict
+picture info
+@item pts
+@item qp
+per-block quantization parameter (QP)
+@item rc
+rate control
+@item skip
+@item startcode
+@item thread_ops
+threading operations
+@item vis_mb_type
+visualize block types
+@item vis_qp
+visualize quantization parameter (QP), lower QP are tinted greener
+@end table
+@item -benchmark (@emph{global})
Show benchmarking information at the end of an encode.
Shows CPU time used and maximum memory consumption.
Maximum memory consumption is not supported on all systems,
it will usually display as 0 if not supported.
-@item -dump
-Dump each input packet.
-@item -hex
+@item -timelimit @var{duration} (@emph{global})
+Exit after ffmpeg has been running for @var{duration} seconds.
+@item -dump (@emph{global})
+Dump each input packet to stderr.
+@item -hex (@emph{global})
When dumping packets, also dump the payload.
-@item -bitexact
-Only use bit exact algorithms (for codec testing).
@item -ps @var{size}
Set RTP payload size in bytes.
-@item -re
+@item -re (@emph{input})
Read input at native frame rate. Mainly used to simulate a grab device.
@item -loop_input
Loop over the input stream. Currently it works only for image
streams. This option is used for automatic FFserver testing.
+This option is deprecated, use -loop 1.
@item -loop_output @var{number_of_times}
Repeatedly loop output for formats that support looping such as animated GIF
(0 will loop the output infinitely).
+This option is deprecated, use -loop.
@item -threads @var{count}
Thread count.
@item -vsync @var{parameter}
@@ -770,11 +837,11 @@ Copy input stream time base from input to output when stream copying.
Finish encoding when the shortest input stream ends.
@item -dts_delta_threshold
Timestamp discontinuity delta threshold.
-@item -muxdelay @var{seconds}
+@item -muxdelay @var{seconds} (@emph{input})
Set the maximum demux-decode delay.
-@item -muxpreload @var{seconds}
+@item -muxpreload @var{seconds} (@emph{input})
Set the initial demux-decode delay.
-@item -streamid @var{output-stream-index}:@var{new-value}
+@item -streamid @var{output-stream-index}:@var{new-value} (@emph{output})
Assign a new stream-id value to an output stream. This option should be
specified prior to the output filename to which it applies.
For the situation where multiple output files exist, a streamid
@@ -785,15 +852,28 @@ an output mpegts file:
@example
ffmpeg -i infile -streamid 0:33 -streamid 1:36 out.ts
@end example
+
+@item -bsf[:@var{stream_specifier}] @var{bitstream_filters} (@emph{output,per-stream})
+Set bitstream filters for matching streams. @var{bistream_filters} is
+a comma-separated list of bitstream filters. Use the @code{-bsfs} option
+to get the list of bitstream filters.
+@example
+ffmpeg -i h264.mp4 -c:v copy -vbsf h264_mp4toannexb -an out.h264
+@end example
+@example
+ffmpeg -i file.mov -an -vn -sbsf mov2textsub -c:s copy -f rawvideo sub.txt
+@end example
+
+@item -tag[:@var{stream_specifier}] @var{codec_tag} (@emph{per-stream})
+Force a tag/fourcc for matching streams.
@end table
@section Preset files
-
A preset file contains a sequence of @var{option}=@var{value} pairs,
one for each line, specifying a sequence of options which would be
awkward to specify on the command line. Lines starting with the hash
('#') character are ignored and are used to provide comments. Check
-the @file{ffpresets} directory in the Libav source tree for examples.
+the @file{presets} directory in the FFmpeg source tree for examples.
Preset files are specified with the @code{vpre}, @code{apre},
@code{spre}, and @code{fpre} options. The @code{fpre} option takes the
@@ -810,6 +890,7 @@ following rules:
First ffmpeg searches for a file named @var{arg}.ffpreset in the
directories @file{$FFMPEG_DATADIR} (if set), and @file{$HOME/.ffmpeg}, and in
the datadir defined at configuration time (usually @file{PREFIX/share/ffmpeg})
+or in a @file{ffpresets} folder along the executable on win32,
in that order. For example, if the argument is @code{libx264-max}, it will
search for the file @file{libx264-max.ffpreset}.
@@ -819,7 +900,7 @@ directories, where @var{codec_name} is the name of the codec to which
the preset file options will be applied. For example, if you select
the video codec with @code{-vcodec libx264} and use @code{-vpre max},
then it will search for the file @file{libx264-max.ffpreset}.
-@c man end
+@c man end OPTIONS
@chapter Tips
@c man begin TIPS
@@ -859,11 +940,6 @@ To have a constant quality (but a variable bitrate), use the option
'-qscale n' when 'n' is between 1 (excellent quality) and 31 (worst
quality).
-@item
-When converting video files, you can use the '-sameq' option which
-uses the same quality factor in the encoder as in the decoder.
-It allows almost lossless encoding.
-
@end itemize
@c man end TIPS
@@ -880,8 +956,8 @@ ffmpeg -f oss -i /dev/dsp -f video4linux2 -i /dev/video0 /tmp/out.mpg
@end example
Note that you must activate the right video source and channel before
-launching ffmpeg with any TV viewer such as xawtv
-(@url{http://linux.bytesex.org/xawtv/}) by Gerd Knorr. You also
+launching ffmpeg with any TV viewer such as
+@uref{http://linux.bytesex.org/xawtv/, xawtv} by Gerd Knorr. You also
have to set the audio recording levels correctly with a
standard mixer.
@@ -969,7 +1045,7 @@ You can encode to several formats at the same time and define a
mapping from input stream to output streams:
@example
-ffmpeg -i /tmp/a.wav -ab 64k /tmp/a.mp2 -ab 128k /tmp/b.mp2 -map 0:0 -map 0:0
+ffmpeg -i /tmp/a.wav -map 0:a -b 64k /tmp/a.mp2 -map 0:a -b 128k /tmp/b.mp2
@end example
Converts a.wav to a.mp2 at 64 kbits and to b.mp2 at 128 kbits. '-map
@@ -980,7 +1056,7 @@ stream, in the order of the definition of output streams.
You can transcode decrypted VOBs:
@example
-ffmpeg -i snatch_1.vob -f avi -vcodec mpeg4 -b 800k -g 300 -bf 2 -acodec libmp3lame -ab 128k snatch.avi
+ffmpeg -i snatch_1.vob -f avi -c:v mpeg4 -b:v 800k -g 300 -bf 2 -c:a libmp3lame -b:a 128k snatch.avi
@end example
This is a typical DVD ripping example; the input is a VOB file, the
@@ -1024,21 +1100,17 @@ only formats accepting a normal integer are suitable.
You can put many streams of the same type in the output:
@example
-ffmpeg -i test1.avi -i test2.avi -vcodec copy -acodec copy -vcodec copy -acodec copy test12.avi -newvideo -newaudio
+ffmpeg -i test1.avi -i test2.avi -map 0.3 -map 0.2 -map 0.1 -map 0.0 -c copy test12.nut
@end example
-In addition to the first video and audio streams, the resulting
-output file @file{test12.avi} will contain the second video
-and the second audio stream found in the input streams list.
-
-The @code{-newvideo}, @code{-newaudio} and @code{-newsubtitle}
-options have to be specified immediately after the name of the output
-file to which you want to add them.
+The resulting output file @file{test12.avi} will contain first four streams from
+the input file in reverse order.
@end itemize
@c man end EXAMPLES
@include eval.texi
+@include decoders.texi
@include encoders.texi
@include demuxers.texi
@include muxers.texi
@@ -1055,11 +1127,11 @@ file to which you want to add them.
@settitle ffmpeg video converter
@c man begin SEEALSO
-ffplay(1), ffprobe(1), ffserver(1) and the Libav HTML documentation
+ffplay(1), ffprobe(1), ffserver(1) and the FFmpeg HTML documentation
@c man end
@c man begin AUTHORS
-The Libav developers
+See git history
@c man end
@end ignore
diff --git a/doc/ffmpeg.txt b/doc/ffmpeg.txt
new file mode 100644
index 0000000000..1fa42e78ee
--- /dev/null
+++ b/doc/ffmpeg.txt
@@ -0,0 +1,47 @@
+ :
+ ffmpeg.c : libav*
+ ======== : ======
+ :
+ :
+ --------------------------------:---> AVStream...
+ InputStream input_streams[] / :
+ / :
+ InputFile input_files[] +==========================+ / ^ :
+ ------> 0 | : st ---:-----------:--/ : :
+ ^ +------+-----------+-----+ / +--------------------------+ : :
+ : | :ist_index--:-----:---------/ 1 | : st : | : :
+ : +------+-----------+-----+ +==========================+ : :
+ nb_input_files : | :ist_index--:-----:------------------> 2 | : st : | : :
+ : +------+-----------+-----+ +--------------------------+ : nb_input_streams :
+ : | :ist_index : | 3 | ... | : :
+ v +------+-----------+-----+ +--------------------------+ : :
+ --> 4 | | : :
+ | +--------------------------+ : :
+ | 5 | | : :
+ | +==========================+ v :
+ | :
+ | :
+ | :
+ | :
+ --------- --------------------------------:---> AVStream...
+ \ / :
+ OutputStream output_streams[] / :
+ \ / :
+ +======\======================/======+ ^ :
+ ------> 0 | : source_index : st-:--- | : :
+ OuputFile output_files[] / +------------------------------------+ : :
+ / 1 | : : : | : :
+ ^ +------+------------+-----+ / +------------------------------------+ : :
+ : | : ost_index -:-----:------/ 2 | : : : | : :
+ nb_output_files : +------+------------+-----+ +====================================+ : :
+ : | : ost_index -:-----|-----------------> 3 | : : : | : :
+ : +------+------------+-----+ +------------------------------------+ : nb_output_streams :
+ : | : : | 4 | | : :
+ : +------+------------+-----+ +------------------------------------+ : :
+ : | : : | 5 | | : :
+ v +------+------------+-----+ +------------------------------------+ : :
+ 6 | | : :
+ +------------------------------------+ : :
+ 7 | | : :
+ +====================================+ v :
+ :
diff --git a/doc/ffplay.texi b/doc/ffplay.texi
index e5de3d2d6d..b4d6dbcdcb 100644
--- a/doc/ffplay.texi
+++ b/doc/ffplay.texi
@@ -13,22 +13,22 @@
@example
@c man begin SYNOPSIS
-ffplay [options] @file{input_file}
+ffplay [options] [@file{input_file}]
@c man end
@end example
@chapter Description
@c man begin DESCRIPTION
-FFplay is a very simple and portable media player using the Libav
+FFplay is a very simple and portable media player using the FFmpeg
libraries and the SDL library. It is mostly used as a testbed for the
-various Libav APIs.
+various FFmpeg APIs.
@c man end
@chapter Options
@c man begin OPTIONS
-@include fftools-common-opts.texi
+@include avtools-common-opts.texi
@section Main options
@@ -38,8 +38,9 @@ Force displayed width.
@item -y @var{height}
Force displayed height.
@item -s @var{size}
-Set frame size (WxH or abbreviation), needed for videos which don't
-contain a header with the frame size like raw YUV.
+Set frame size (WxH or abbreviation), needed for videos which do
+not contain a header with the frame size like raw YUV. This option
+has been deprecated in favor of private options, try -video_size.
@item -an
Disable audio.
@item -vn
@@ -58,27 +59,44 @@ Force format.
Set window title (default is the input filename).
@item -loop @var{number}
Loops movie playback <number> times. 0 means forever.
+@item -showmode @var{mode}
+Set the show mode to use.
+Available values for @var{mode} are:
+@table @samp
+@item 0, video
+show video
+@item 1, waves
+show audio waves
+@item 2, rdft
+show audio frequency band using RDFT ((Inverse) Real Discrete Fourier Transform)
+@end table
+
+Default value is "video", if video is not present or cannot be played
+"rdft" is automatically selected.
+
+You can interactively cycle through the available show modes by
+pressing the key @key{w}.
+
@item -vf @var{filter_graph}
@var{filter_graph} is a description of the filter graph to apply to
the input video.
Use the option "-filters" to show all the available filters (including
also sources and sinks).
+@item -i @var{input_file}
+Read @var{input_file}.
@end table
@section Advanced options
@table @option
@item -pix_fmt @var{format}
Set pixel format.
+This option has been deprecated in favor of private options, try -pixel_format.
@item -stats
Show the stream duration, the codec parameters, the current position in
the stream and the audio/video synchronisation drift.
-@item -debug
-Print specific debug info.
@item -bug
Work around bugs.
-@item -vismv
-Visualize motion vectors.
@item -fast
Non-spec-compliant optimizations.
@item -genpts
@@ -116,6 +134,8 @@ Exit when video is done playing.
Exit if any key is pressed.
@item -exitonmousedown
Exit if any mouse button is pressed.
+@item -codec:@var{stream_type}
+Force a specific decoder implementation
@end table
@section While playing
@@ -156,6 +176,7 @@ Seek to percentage in file corresponding to fraction of width.
@c man end
@include eval.texi
+@include decoders.texi
@include demuxers.texi
@include muxers.texi
@include indevs.texi
@@ -169,11 +190,11 @@ Seek to percentage in file corresponding to fraction of width.
@settitle FFplay media player
@c man begin SEEALSO
-ffmpeg(1), ffprobe(1), ffserver(1) and the Libav HTML documentation
+ffmpeg(1), ffprobe(1), ffserver(1) and the FFmpeg HTML documentation
@c man end
@c man begin AUTHORS
-The Libav developers
+The FFmpeg developers
@c man end
@end ignore
diff --git a/doc/ffprobe.texi b/doc/ffprobe.texi
index 5e856e6645..9496fc95be 100644
--- a/doc/ffprobe.texi
+++ b/doc/ffprobe.texi
@@ -42,25 +42,18 @@ for specifying which information to display, and for setting how
ffprobe will show it.
ffprobe output is designed to be easily parsable by a textual filter,
-and consists of one or more sections of the form:
-@example
-[SECTION]
-key1=val1
-...
-keyN=valN
-[/SECTION]
-@end example
+and consists of one or more sections of a form defined by the selected
+writer, which is specified by the @option{print_format} option.
Metadata tags stored in the container or in the streams are recognized
-and printed in the corresponding "FORMAT" or "STREAM" section, and
-are prefixed by the string "TAG:".
+and printed in the corresponding "FORMAT" or "STREAM" section.
@c man end
@chapter Options
@c man begin OPTIONS
-@include fftools-common-opts.texi
+@include avtools-common-opts.texi
@section Main options
@@ -87,6 +80,20 @@ Use sexagesimal format HH:MM:SS.MICROSECONDS for time values.
Prettify the format of the displayed values, it corresponds to the
options "-unit -prefix -byte_binary_prefix -sexagesimal".
+@item -print_format @var{writer_name}[=@var{writer_options}]
+Set the output printing format.
+
+@var{writer_name} specifies the name of the writer, and
+@var{writer_options} specifies the options to be passed to the writer.
+
+For example for printing the output in JSON format, specify:
+@example
+-print_format json
+@end example
+
+For more details on the available output printing formats, see the
+Writers section below.
+
@item -show_format
Show information about the container format of the input multimedia
stream.
@@ -108,11 +115,49 @@ multimedia stream.
Each media stream information is printed within a dedicated section
with name "STREAM".
+@item -i @var{input_file}
+Read @var{input_file}.
+
@end table
@c man end
+@chapter Writers
+@c man begin WRITERS
+
+A writer defines the output format adopted by @file{ffprobe}, and will be
+used for printing all the parts of the output.
+
+A writer may accept one or more arguments, which specify the options to
+adopt.
+
+A description of the currently available writers follows.
+
+@section default
+Default format.
+
+Print each section in the form:
+@example
+[SECTION]
+key1=val1
+...
+keyN=valN
+[/SECTION]
+@end example
+
+Metadata tags are printed as a line in the corresponding FORMAT or
+STREAM section, and are prefixed by the string "TAG:".
+
+@section json
+JSON based format.
+
+Each section is printed using JSON notation.
+
+For more information about JSON, see @url{http://www.json.org/}.
+
+@c man end WRITERS
+
+@include decoders.texi
@include demuxers.texi
-@include muxers.texi
@include protocols.texi
@include indevs.texi
@@ -122,11 +167,11 @@ with name "STREAM".
@settitle ffprobe media prober
@c man begin SEEALSO
-ffmpeg(1), ffplay(1), ffserver(1) and the Libav HTML documentation
+ffmpeg(1), ffplay(1), ffserver(1) and the FFmpeg HTML documentation
@c man end
@c man begin AUTHORS
-The Libav developers
+The FFmpeg developers
@c man end
@end ignore
diff --git a/doc/ffserver.conf b/doc/ffserver.conf
index 62728b036c..217117005c 100644
--- a/doc/ffserver.conf
+++ b/doc/ffserver.conf
@@ -371,7 +371,7 @@ ACL allow 192.168.0.0 192.168.255.255
# Redirect index.html to the appropriate site
<Redirect index.html>
-URL http://www.libav.org/
+URL http://www.ffmpeg.org/
</Redirect>
diff --git a/doc/ffserver.texi b/doc/ffserver.texi
index d247016bbc..c7084833d3 100644
--- a/doc/ffserver.texi
+++ b/doc/ffserver.texi
@@ -240,7 +240,7 @@ For example: @samp{http://localhost:8080/test.asf?date=2002-07-26T23:05:00}.
@chapter Options
@c man begin OPTIONS
-@include fftools-common-opts.texi
+@include avtools-common-opts.texi
@section Main options
@@ -266,11 +266,11 @@ rather than as a daemon.
@c man begin SEEALSO
ffmpeg(1), ffplay(1), ffprobe(1), the @file{ffmpeg/doc/ffserver.conf}
-example and the Libav HTML documentation
+example and the FFmpeg HTML documentation
@c man end
@c man begin AUTHORS
-The Libav developers
+The FFmpeg developers
@c man end
@end ignore
diff --git a/doc/fftools-common-opts.texi b/doc/fftools-common-opts.texi
deleted file mode 100644
index 3a1cb3b23c..0000000000
--- a/doc/fftools-common-opts.texi
+++ /dev/null
@@ -1,93 +0,0 @@
-All the numerical options, if not specified otherwise, accept in input
-a string representing a number, which may contain one of the
-International System number postfixes, for example 'K', 'M', 'G'.
-If 'i' is appended after the postfix, powers of 2 are used instead of
-powers of 10. The 'B' postfix multiplies the value for 8, and can be
-appended after another postfix or used alone. This allows using for
-example 'KB', 'MiB', 'G' and 'B' as postfix.
-
-Options which do not take arguments are boolean options, and set the
-corresponding value to true. They can be set to false by prefixing
-with "no" the option name, for example using "-nofoo" in the
-commandline will set to false the boolean option with name "foo".
-
-@section Generic options
-
-These options are shared amongst the ff* tools.
-
-@table @option
-
-@item -L
-Show license.
-
-@item -h, -?, -help, --help
-Show help.
-
-@item -version
-Show version.
-
-@item -formats
-Show available formats.
-
-The fields preceding the format names have the following meanings:
-@table @samp
-@item D
-Decoding available
-@item E
-Encoding available
-@end table
-
-@item -codecs
-Show available codecs.
-
-The fields preceding the codec names have the following meanings:
-@table @samp
-@item D
-Decoding available
-@item E
-Encoding available
-@item V/A/S
-Video/audio/subtitle codec
-@item S
-Codec supports slices
-@item D
-Codec supports direct rendering
-@item T
-Codec can handle input truncated at random locations instead of only at frame boundaries
-@end table
-
-@item -bsfs
-Show available bitstream filters.
-
-@item -protocols
-Show available protocols.
-
-@item -filters
-Show available libavfilter filters.
-
-@item -pix_fmts
-Show available pixel formats.
-
-@item -loglevel @var{loglevel}
-Set the logging level used by the library.
-@var{loglevel} is a number or a string containing one of the following values:
-@table @samp
-@item quiet
-@item panic
-@item fatal
-@item error
-@item warning
-@item info
-@item verbose
-@item debug
-@end table
-
-By default the program logs to stderr, if coloring is supported by the
-terminal, colors are used to mark errors and warnings. Log coloring
-can be disabled setting the environment variable
-@env{FFMPEG_FORCE_NOCOLOR} or @env{NO_COLOR}, or can be forced setting
-the environment variable @env{FFMPEG_FORCE_COLOR}.
-The use of the environment variable @env{NO_COLOR} is deprecated and
-will be dropped in a following Libav version.
-
-@end table
diff --git a/doc/filters.texi b/doc/filters.texi
index 9666f582f2..b389ba21e8 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -18,8 +18,8 @@ output pads is called a "sink".
A filtergraph can be represented using a textual representation, which
is recognized by the @code{-vf} and @code{-af} options of the ff*
-tools, and by the @code{av_parse_graph()} function defined in
-@file{libavfilter/avfiltergraph}.
+tools, and by the @code{avfilter_graph_parse()} function defined in
+@file{libavfilter/avfiltergraph.h}.
A filterchain consists of a sequence of connected filters, each one
connected to the previous one in the sequence. A filterchain is
@@ -92,17 +92,137 @@ Follows a BNF description for the filtergraph syntax:
@chapter Audio Filters
@c man begin AUDIO FILTERS
-When you configure your Libav build, you can disable any of the
+When you configure your FFmpeg build, you can disable any of the
existing filters using --disable-filters.
The configure output will show the audio filters included in your
build.
Below is a description of the currently available audio filters.
+@section aconvert
+
+Convert the input audio format to the specified formats.
+
+The filter accepts a string of the form:
+"@var{sample_format}:@var{channel_layout}:@var{packing_format}".
+
+@var{sample_format} specifies the sample format, and can be a string or
+the corresponding numeric value defined in @file{libavutil/samplefmt.h}.
+
+@var{channel_layout} specifies the channel layout, and can be a string
+or the corresponding number value defined in @file{libavutil/chlayout.h}.
+
+@var{packing_format} specifies the type of packing in output, can be one
+of "planar" or "packed", or the corresponding numeric values "0" or "1".
+
+The special parameter "auto", signifies that the filter will
+automatically select the output format depending on the output filter.
+
+Some examples follow.
+
+@itemize
+@item
+Convert input to unsigned 8-bit, stereo, packed:
+@example
+aconvert=u8:stereo:packed
+@end example
+
+@item
+Convert input to unsigned 8-bit, automatically select out channel layout
+and packing format:
+@example
+aconvert=u8:auto:auto
+@end example
+@end itemize
+
+@section aformat
+
+Convert the input audio to one of the specified formats. The framework will
+negotiate the most appropriate format to minimize conversions.
+
+The filter accepts three lists of formats, separated by ":", in the form:
+"@var{sample_formats}:@var{channel_layouts}:@var{packing_formats}".
+
+Elements in each list are separated by "," which has to be escaped in the
+filtergraph specification.
+
+The special parameter "all", in place of a list of elements, signifies all
+supported formats.
+
+Some examples follow:
+@example
+aformat=u8\\,s16:mono:packed
+
+aformat=s16:mono\\,stereo:all
+@end example
+
@section anull
Pass the audio source unchanged to the output.
+@section aresample
+
+Resample the input audio to the specified sample rate.
+
+The filter accepts exactly one parameter, the output sample rate. If not
+specified then the filter will automatically convert between its input
+and output sample rates.
+
+For example, to resample the input audio to 44100Hz:
+@example
+aresample=44100
+@end example
+
+@section ashowinfo
+
+Show a line containing various information for each input audio frame.
+The input audio is not modified.
+
+The shown line contains a sequence of key/value pairs of the form
+@var{key}:@var{value}.
+
+A description of each shown parameter follows:
+
+@table @option
+@item n
+sequential number of the input frame, starting from 0
+
+@item pts
+presentation TimeStamp of the input frame, expressed as a number of
+time base units. The time base unit depends on the filter input pad, and
+is usually 1/@var{sample_rate}.
+
+@item pts_time
+presentation TimeStamp of the input frame, expressed as a number of
+seconds
+
+@item pos
+position of the frame in the input stream, -1 if this information in
+unavailable and/or meanigless (for example in case of synthetic audio)
+
+@item fmt
+sample format name
+
+@item chlayout
+channel layout description
+
+@item nb_samples
+number of samples (per each channel) contained in the filtered frame
+
+@item rate
+sample rate for the audio frame
+
+@item planar
+if the packing format is planar, 0 if packed
+
+@item checksum
+Adler-32 checksum of all the planes of the input frame
+
+@item plane_checksum
+Adler-32 checksum for each input frame plane, expressed in the form
+"[@var{c0} @var{c1} @var{c2} @var{c3} @var{c4} @var{c5} @var{c6} @var{c7}]"
+@end table
+
@c man end AUDIO FILTERS
@chapter Audio Sources
@@ -110,31 +230,202 @@ Pass the audio source unchanged to the output.
Below is a description of the currently available audio sources.
+@section abuffer
+
+Buffer audio frames, and make them available to the filter chain.
+
+This source is mainly intended for a programmatic use, in particular
+through the interface defined in @file{libavfilter/asrc_abuffer.h}.
+
+It accepts the following mandatory parameters:
+@var{sample_rate}:@var{sample_fmt}:@var{channel_layout}:@var{packing}
+
+@table @option
+
+@item sample_rate
+The sample rate of the incoming audio buffers.
+
+@item sample_fmt
+The sample format of the incoming audio buffers.
+Either a sample format name or its corresponging integer representation from
+the enum AVSampleFormat in @file{libavutil/samplefmt.h}
+
+@item channel_layout
+The channel layout of the incoming audio buffers.
+Either a channel layout name from channel_layout_map in
+@file{libavutil/audioconvert.c} or its corresponding integer representation
+from the AV_CH_LAYOUT_* macros in @file{libavutil/audioconvert.h}
+
+@item packing
+Either "packed" or "planar", or their integer representation: 0 or 1
+respectively.
+
+@end table
+
+For example:
+@example
+abuffer=44100:s16:stereo:planar
+@end example
+
+will instruct the source to accept planar 16bit signed stereo at 44100Hz.
+Since the sample format with name "s16" corresponds to the number
+1 and the "stereo" channel layout corresponds to the value 3, this is
+equivalent to:
+@example
+abuffer=44100:1:3:1
+@end example
+
+@section aevalsrc
+
+Generate an audio signal specified by an expression.
+
+This source accepts in input one or more expressions (one for each
+channel), which are evaluated and used to generate a corresponding
+audio signal.
+
+It accepts the syntax: @var{exprs}[::@var{options}].
+@var{exprs} is a list of expressions separated by ":", one for each
+separate channel. The output channel layout depends on the number of
+provided expressions, up to 8 channels are supported.
+
+@var{options} is an optional sequence of @var{key}=@var{value} pairs,
+separated by ":".
+
+The description of the accepted options follows.
+
+@table @option
+
+@item nb_samples, n
+Set the number of samples per channel per each output frame,
+default to 1024.
+
+@item sample_rate, s
+Specify the sample rate, default to 44100.
+@end table
+
+Each expression in @var{exprs} can contain the following constants:
+
+@table @option
+@item n
+number of the evaluated sample, starting from 0
+
+@item t
+time of the evaluated sample expressed in seconds, starting from 0
+
+@item s
+sample rate
+
+@end table
+
+@subsection Examples
+
+@itemize
+
+@item
+Generate silence:
+@example
+aevalsrc=0
+@end example
+
+@item
+
+Generate a sin signal with frequence of 440 Hz, set sample rate to
+8000 Hz:
+@example
+aevalsrc="sin(440*2*PI*t)::s=8000"
+@end example
+
+@item
+Generate white noise:
+@example
+aevalsrc="-2+random(0)"
+@end example
+
+@item
+Generate an amplitude modulated signal:
+@example
+aevalsrc="sin(10*2*PI*t)*sin(880*2*PI*t)"
+@end example
+
+@item
+Generate 2.5 Hz binaural beats on a 360 Hz carrier:
+@example
+aevalsrc="0.1*sin(2*PI*(360-2.5/2)*t) : 0.1*sin(2*PI*(360+2.5/2)*t)"
+@end example
+
+@end itemize
+
+@section amovie
+
+Read an audio stream from a movie container.
+
+It accepts the syntax: @var{movie_name}[:@var{options}] where
+@var{movie_name} is the name of the resource to read (not necessarily
+a file but also a device or a stream accessed through some protocol),
+and @var{options} is an optional sequence of @var{key}=@var{value}
+pairs, separated by ":".
+
+The description of the accepted options follows.
+
+@table @option
+
+@item format_name, f
+Specify the format assumed for the movie to read, and can be either
+the name of a container or an input device. If not specified the
+format is guessed from @var{movie_name} or by probing.
+
+@item seek_point, sp
+Specify the seek point in seconds, the frames will be output
+starting from this seek point, the parameter is evaluated with
+@code{av_strtod} so the numerical value may be suffixed by an IS
+postfix. Default value is "0".
+
+@item stream_index, si
+Specify the index of the audio stream to read. If the value is -1,
+the best suited audio stream will be automatically selected. Default
+value is "-1".
+
+@end table
+
@section anullsrc
-Null audio source, never return audio frames. It is mainly useful as a
-template and to be employed in analysis / debugging tools.
+Null audio source, return unprocessed audio frames. It is mainly useful
+as a template and to be employed in analysis / debugging tools, or as
+the source for filters which ignore the input data (for example the sox
+synth filter).
-It accepts as optional parameter a string of the form
-@var{sample_rate}:@var{channel_layout}.
+It accepts an optional sequence of @var{key}=@var{value} pairs,
+separated by ":".
+
+The description of the accepted options follows.
+
+@table @option
-@var{sample_rate} specify the sample rate, and defaults to 44100.
+@item sample_rate, s
+Specify the sample rate, and defaults to 44100.
-@var{channel_layout} specify the channel layout, and can be either an
-integer or a string representing a channel layout. The default value
-of @var{channel_layout} is 3, which corresponds to CH_LAYOUT_STEREO.
+@item channel_layout, cl
+
+Specify the channel layout, and can be either an integer or a string
+representing a channel layout. The default value of @var{channel_layout}
+is "stereo".
Check the channel_layout_map definition in
@file{libavcodec/audioconvert.c} for the mapping between strings and
channel layout values.
+@item nb_samples, n
+Set the number of samples per requested frames.
+
+@end table
+
Follow some examples:
@example
-# set the sample rate to 48000 Hz and the channel layout to CH_LAYOUT_MONO.
-anullsrc=48000:4
+# set the sample rate to 48000 Hz and the channel layout to AV_CH_LAYOUT_MONO.
+anullsrc=r=48000:cl=4
# same as
-anullsrc=48000:mono
+anullsrc=r=48000:cl=mono
@end example
@c man end AUDIO SOURCES
@@ -144,6 +435,17 @@ anullsrc=48000:mono
Below is a description of the currently available audio sinks.
+@section abuffersink
+
+Buffer audio frames, and make them available to the end of filter chain.
+
+This sink is mainly intended for programmatic use, in particular
+through the interface defined in @file{libavfilter/buffersink.h}.
+
+It requires a pointer to an AVABufferSinkContext structure, which
+defines the incoming buffers' formats, to be passed as the opaque
+parameter to @code{avfilter_init_filter} for initialization.
+
@section anullsink
Null audio sink, do absolutely nothing with the input audio. It is
@@ -155,7 +457,7 @@ tools.
@chapter Video Filters
@c man begin VIDEO FILTERS
-When you configure your Libav build, you can disable any of the
+When you configure your FFmpeg build, you can disable any of the
existing filters using --disable-filters.
The configure output will show the video filters included in your
build.
@@ -183,6 +485,66 @@ threshold, and defaults to 98.
@var{threshold} is the threshold below which a pixel value is
considered black, and defaults to 32.
+@section boxblur
+
+Apply boxblur algorithm to the input video.
+
+This filter accepts the parameters:
+@var{luma_radius}:@var{luma_power}:@var{chroma_radius}:@var{chroma_power}:@var{alpha_radius}:@var{alpha_power}
+
+Chroma and alpha parameters are optional, if not specified they default
+to the corresponding values set for @var{luma_radius} and
+@var{luma_power}.
+
+@var{luma_radius}, @var{chroma_radius}, and @var{alpha_radius} represent
+the radius in pixels of the box used for blurring the corresponding
+input plane. They are expressions, and can contain the following
+constants:
+@table @option
+@item w, h
+the input width and heigth in pixels
+
+@item cw, ch
+the input chroma image width and height in pixels
+
+@item hsub, vsub
+horizontal and vertical chroma subsample values. For example for the
+pixel format "yuv422p" @var{hsub} is 2 and @var{vsub} is 1.
+@end table
+
+The radius must be a non-negative number, and must not be greater than
+the value of the expression @code{min(w,h)/2} for the luma and alpha planes,
+and of @code{min(cw,ch)/2} for the chroma planes.
+
+@var{luma_power}, @var{chroma_power}, and @var{alpha_power} represent
+how many times the boxblur filter is applied to the corresponding
+plane.
+
+Some examples follow:
+
+@itemize
+
+@item
+Apply a boxblur filter with luma, chroma, and alpha radius
+set to 2:
+@example
+boxblur=2:1
+@end example
+
+@item
+Set luma radius to 2, alpha and chroma radius to 0
+@example
+boxblur=2:1:0:0:0:0
+@end example
+
+@item
+Set luma and chroma radius to a fraction of the video dimension
+@example
+boxblur=min(h\,w)/10:1:min(cw\,ch)/10:1
+@end example
+
+@end itemize
+
@section copy
Copy the input source unchanged to the output. Mainly useful for
@@ -195,26 +557,35 @@ Crop the input video to @var{out_w}:@var{out_h}:@var{x}:@var{y}.
The parameters are expressions containing the following constants:
@table @option
-@item E, PI, PHI
-the corresponding mathematical approximated values for e
-(euler number), pi (greek PI), PHI (golden ratio)
-
@item x, y
the computed values for @var{x} and @var{y}. They are evaluated for
each new frame.
@item in_w, in_h
-the input width and heigth
+the input width and height
@item iw, ih
same as @var{in_w} and @var{in_h}
@item out_w, out_h
-the output (cropped) width and heigth
+the output (cropped) width and height
@item ow, oh
same as @var{out_w} and @var{out_h}
+@item a
+same as @var{iw} / @var{ih}
+
+@item sar
+input sample aspect ratio
+
+@item dar
+input display aspect ratio, it is the same as (@var{iw} / @var{ih}) * @var{sar}
+
+@item hsub, vsub
+horizontal and vertical chroma subsample values. For example for the
+pixel format "yuv422p" @var{hsub} is 2 and @var{vsub} is 1.
+
@item n
the number of input frame, starting from 0
@@ -321,6 +692,128 @@ indicates never reset and return the largest area encountered during
playback.
@end table
+@section delogo
+
+Suppress a TV station logo by a simple interpolation of the surrounding
+pixels. Just set a rectangle covering the logo and watch it disappear
+(and sometimes something even uglier appear - your mileage may vary).
+
+The filter accepts parameters as a string of the form
+"@var{x}:@var{y}:@var{w}:@var{h}:@var{band}", or as a list of
+@var{key}=@var{value} pairs, separated by ":".
+
+The description of the accepted parameters follows.
+
+@table @option
+
+@item x, y
+Specify the top left corner coordinates of the logo. They must be
+specified.
+
+@item w, h
+Specify the width and height of the logo to clear. They must be
+specified.
+
+@item band, t
+Specify the thickness of the fuzzy edge of the rectangle (added to
+@var{w} and @var{h}). The default value is 4.
+
+@item show
+When set to 1, a green rectangle is drawn on the screen to simplify
+finding the right @var{x}, @var{y}, @var{w}, @var{h} parameters, and
+@var{band} is set to 4. The default value is 0.
+
+@end table
+
+Some examples follow.
+
+@itemize
+
+@item
+Set a rectangle covering the area with top left corner coordinates 0,0
+and size 100x77, setting a band of size 10:
+@example
+delogo=0:0:100:77:10
+@end example
+
+@item
+As the previous example, but use named options:
+@example
+delogo=x=0:y=0:w=100:h=77:band=10
+@end example
+
+@end itemize
+
+@section deshake
+
+Attempt to fix small changes in horizontal and/or vertical shift. This
+filter helps remove camera shake from hand-holding a camera, bumping a
+tripod, moving on a vehicle, etc.
+
+The filter accepts parameters as a string of the form
+"@var{x}:@var{y}:@var{w}:@var{h}:@var{rx}:@var{ry}:@var{edge}:@var{blocksize}:@var{contrast}:@var{search}:@var{filename}"
+
+A description of the accepted parameters follows.
+
+@table @option
+
+@item x, y, w, h
+Specify a rectangular area where to limit the sarch for motion
+vectors.
+If desired the search for motion vectors can be limited to a
+rectangular area of the frame defined by its top left corner, width
+and height. These parameters have the same meaning as the drawbox
+filter which can be used to visualise the position of the bounding
+box.
+
+This is useful when simultaneous movement of subjects within the frame
+might be confused for camera motion by the motion vector search.
+
+If any or all of @var{x}, @var{y}, @var{w} and @var{h} are set to -1
+then the full frame is used. This allows later options to be set
+without specifying the bounding box for the motion vector search.
+
+Default - search the whole frame.
+
+@item rx, ry
+Specify the maximum extent of movement in x and y directions in the
+range 0-64 pixels. Default 16.
+
+@item edge
+Specify how to generate pixels to fill blanks at the edge of the
+frame. An integer from 0 to 3 as follows:
+@table @option
+@item 0
+Fill zeroes at blank locations
+@item 1
+Original image at blank locations
+@item 2
+Extruded edge value at blank locations
+@item 3
+Mirrored edge at blank locations
+@end table
+
+The default setting is mirror edge at blank locations.
+
+@item blocksize
+Specify the blocksize to use for motion search. Range 4-128 pixels,
+default 8.
+
+@item contrast
+Specify the contrast threshold for blocks. Only blocks with more than
+the specified contrast (difference between darkest and lightest
+pixels) will be considered. Range 1-255, default 125.
+
+@item search
+Specify the search strategy 0 = exhaustive search, 1 = less exhaustive
+search. Default - exhaustive search.
+
+@item filename
+If set then a detailed log of the motion search is written to the
+specified file.
+
+@end table
+
@section drawbox
Draw a colored box on the input image.
@@ -391,10 +884,13 @@ parameter @var{text}.
If both text and textfile are specified, an error is thrown.
@item x, y
-The offsets where text will be drawn within the video frame.
-Relative to the top/left border of the output image.
+The expressions which specify the offsets where text will be drawn
+within the video frame. They are relative to the top/left border of the
+output image.
-The default value of @var{x} and @var{y} is 0.
+The default value of @var{x} and @var{y} is "0".
+
+See below for the list of accepted constants.
@item fontsize
The font size to be used for drawing text.
@@ -462,28 +958,117 @@ The size in number of spaces to use for rendering the tab.
Default value is 4.
@end table
-For example the command:
+The parameters for @var{x} and @var{y} are expressions containing the
+following constants:
+
+@table @option
+@item w, h
+the input width and heigth
+
+@item tw, text_w
+the width of the rendered text
+
+@item th, text_h
+the height of the rendered text
+
+@item lh, line_h
+the height of each text line
+
+@item sar
+input sample aspect ratio
+
+@item dar
+input display aspect ratio, it is the same as (@var{w} / @var{h}) * @var{sar}
+
+@item hsub, vsub
+horizontal and vertical chroma subsample values. For example for the
+pixel format "yuv422p" @var{hsub} is 2 and @var{vsub} is 1.
+
+@item max_glyph_w
+maximum glyph width, that is the maximum width for all the glyphs
+contained in the rendered text
+
+@item max_glyph_h
+maximum glyph height, that is the maximum height for all the glyphs
+contained in the rendered text, it is equivalent to @var{ascent} -
+@var{descent}.
+
+@item max_glyph_a, ascent
+
+the maximum distance from the baseline to the highest/upper grid
+coordinate used to place a glyph outline point, for all the rendered
+glyphs.
+It is a positive value, due to the grid's orientation with the Y axis
+upwards.
+
+@item max_glyph_d, descent
+the maximum distance from the baseline to the lowest grid coordinate
+used to place a glyph outline point, for all the rendered glyphs.
+This is a negative value, due to the grid's orientation, with the Y axis
+upwards.
+
+@item n
+the number of input frame, starting from 0
+
+@item t
+timestamp expressed in seconds, NAN if the input timestamp is unknown
+@end table
+
+Some examples follow.
+
+@itemize
+
+@item
+Draw "Test Text" with font FreeSerif, using the default values for the
+optional parameters.
+
@example
drawtext="fontfile=/usr/share/fonts/truetype/freefont/FreeSerif.ttf: text='Test Text'"
@end example
-will draw "Test Text" with font FreeSerif, using the default values
-for the optional parameters.
+@item
+Draw 'Test Text' with font FreeSerif of size 24 at position x=100
+and y=50 (counting from the top-left corner of the screen), text is
+yellow with a red box around it. Both the text and the box have an
+opacity of 20%.
-The command:
@example
drawtext="fontfile=/usr/share/fonts/truetype/freefont/FreeSerif.ttf: text='Test Text':\
x=100: y=50: fontsize=24: fontcolor=yellow@@0.2: box=1: boxcolor=red@@0.2"
@end example
-will draw 'Test Text' with font FreeSerif of size 24 at position x=100
-and y=50 (counting from the top-left corner of the screen), text is
-yellow with a red box around it. Both the text and the box have an
-opacity of 20%.
-
Note that the double quotes are not necessary if spaces are not used
within the parameter list.
+@item
+Show the text at the center of the video frame:
+@example
+drawtext=fontsize=30:fontfile=FreeSerif.ttf:text='hello world':x=(w-text_w)/2:y=(h-text_h-line_h)/2"
+@end example
+
+@item
+Show a text line sliding from right to left in the last row of the video
+frame. The file @file{LONG_LINE} is assumed to contain a single line
+with no newlines.
+@example
+drawtext=fontsize=15:fontfile=FreeSerif.ttf:text=LONG_LINE:y=h-line_h:x=-50*t
+@end example
+
+@item
+Show the content of file @file{CREDITS} off the bottom of the frame and scroll up.
+@example
+drawtext=fontsize=20:fontfile=FreeSerif.ttf:textfile=CREDITS:y=h-20*t"
+@end example
+
+@item
+Draw a single green letter "g", at the center of the input video.
+The glyph baseline is placed at half screen height.
+@example
+drawtext=fontsize=60:fontfile=FreeSerif.ttf:fontcolor=green:text=g:x=(w-max_glyph_w)/2:y=h/2-ascent
+@end example
+
+@end itemize
+
For more information about libfreetype, check:
@url{http://www.freetype.org/}.
@@ -586,7 +1171,7 @@ format=yuv420p:yuv444p:yuv410p
Apply a frei0r effect to the input video.
To enable compilation of this filter you need to install the frei0r
-header and configure Libav with --enable-frei0r.
+header and configure FFmpeg with --enable-frei0r.
The filter supports the syntax:
@example
@@ -701,6 +1286,224 @@ a float number which specifies chroma temporal strength, defaults to
@var{luma_tmp}*@var{chroma_spatial}/@var{luma_spatial}
@end table
+@section lut, lutrgb, lutyuv
+
+Compute a look-up table for binding each pixel component input value
+to an output value, and apply it to input video.
+
+@var{lutyuv} applies a lookup table to a YUV input video, @var{lutrgb}
+to an RGB input video.
+
+These filters accept in input a ":"-separated list of options, which
+specify the expressions used for computing the lookup table for the
+corresponding pixel component values.
+
+The @var{lut} filter requires either YUV or RGB pixel formats in
+input, and accepts the options:
+@table @option
+@item c0
+first pixel component
+@item c1
+second pixel component
+@item c2
+third pixel component
+@item c3
+fourth pixel component, corresponds to the alpha component
+@end table
+
+The exact component associated to each option depends on the format in
+input.
+
+The @var{lutrgb} filter requires RGB pixel formats in input, and
+accepts the options:
+@table @option
+@item r
+red component
+@item g
+green component
+@item b
+blue component
+@item a
+alpha component
+@end table
+
+The @var{lutyuv} filter requires YUV pixel formats in input, and
+accepts the options:
+@table @option
+@item y
+Y/luminance component
+@item u
+U/Cb component
+@item v
+V/Cr component
+@item a
+alpha component
+@end table
+
+The expressions can contain the following constants and functions:
+
+@table @option
+@item w, h
+the input width and heigth
+
+@item val
+input value for the pixel component
+
+@item clipval
+the input value clipped in the @var{minval}-@var{maxval} range
+
+@item maxval
+maximum value for the pixel component
+
+@item minval
+minimum value for the pixel component
+
+@item negval
+the negated value for the pixel component value clipped in the
+@var{minval}-@var{maxval} range , it corresponds to the expression
+"maxval-clipval+minval"
+
+@item clip(val)
+the computed value in @var{val} clipped in the
+@var{minval}-@var{maxval} range
+
+@item gammaval(gamma)
+the computed gamma correction value of the pixel component value
+clipped in the @var{minval}-@var{maxval} range, corresponds to the
+expression
+"pow((clipval-minval)/(maxval-minval)\,@var{gamma})*(maxval-minval)+minval"
+
+@end table
+
+All expressions default to "val".
+
+Some examples follow:
+@example
+# negate input video
+lutrgb="r=maxval+minval-val:g=maxval+minval-val:b=maxval+minval-val"
+lutyuv="y=maxval+minval-val:u=maxval+minval-val:v=maxval+minval-val"
+
+# the above is the same as
+lutrgb="r=negval:g=negval:b=negval"
+lutyuv="y=negval:u=negval:v=negval"
+
+# negate luminance
+lutyuv=y=negval
+
+# remove chroma components, turns the video into a graytone image
+lutyuv="u=128:v=128"
+
+# apply a luma burning effect
+lutyuv="y=2*val"
+
+# remove green and blue components
+lutrgb="g=0:b=0"
+
+# set a constant alpha channel value on input
+format=rgba,lutrgb=a="maxval-minval/2"
+
+# correct luminance gamma by a 0.5 factor
+lutyuv=y=gammaval(0.5)
+@end example
+
+@section mp
+
+Apply an MPlayer filter to the input video.
+
+This filter provides a wrapper around most of the filters of
+MPlayer/MEncoder.
+
+This wrapper is considered experimental. Some of the wrapped filters
+may not work properly and we may drop support for them, as they will
+be implemented natively into FFmpeg. Thus you should avoid
+depending on them when writing portable scripts.
+
+The filters accepts the parameters:
+@var{filter_name}[:=]@var{filter_params}
+
+@var{filter_name} is the name of a supported MPlayer filter,
+@var{filter_params} is a string containing the parameters accepted by
+the named filter.
+
+The list of the currently supported filters follows:
+@table @var
+@item 2xsai
+@item decimate
+@item denoise3d
+@item detc
+@item dint
+@item divtc
+@item down3dright
+@item dsize
+@item eq2
+@item eq
+@item field
+@item fil
+@item fixpts
+@item framestep
+@item fspp
+@item geq
+@item harddup
+@item hqdn3d
+@item hue
+@item il
+@item ilpack
+@item ivtc
+@item kerndeint
+@item mcdeint
+@item mirror
+@item noise
+@item ow
+@item palette
+@item perspective
+@item phase
+@item pp7
+@item pullup
+@item qp
+@item rectangle
+@item remove-logo
+@item rotate
+@item sab
+@item screenshot
+@item smartblur
+@item softpulldown
+@item softskip
+@item spp
+@item swapuv
+@item telecine
+@item tile
+@item tinterlace
+@item unsharp
+@item uspp
+@item yuvcsp
+@item yvu9
+@end table
+
+The parameter syntax and behavior for the listed filters are the same
+of the corresponding MPlayer filters. For detailed instructions check
+the "VIDEO FILTERS" section in the MPlayer manual.
+
+Some examples follow:
+@example
+# remove a logo by interpolating the surrounding pixels
+mp=delogo=200:200:80:20:1
+
+# adjust gamma, brightness, contrast
+mp=eq2=1.0:2:0.5
+
+# tweak hue and saturation
+mp=hue=100:-10
+@end example
+
+See also mplayer(1), @url{http://www.mplayerhq.hu/}.
+
+@section negate
+
+Negate input video.
+
+This filter accepts an integer in input, if non-zero it negates the
+alpha component (if available). The default value in input is 0.
+
@section noformat
Force libavfilter not to use any of the specified pixel formats for the
@@ -728,7 +1531,7 @@ Pass the video source unchanged to the output.
Apply video transform using libopencv.
To enable this filter install libopencv library and headers and
-configure Libav with --enable-libopencv.
+configure FFmpeg with --enable-libopencv.
The filter takes the parameters: @var{filter_name}@{:=@}@var{filter_params}.
@@ -796,8 +1599,7 @@ Erode an image by using a specific structuring element.
This filter corresponds to the libopencv function @code{cvErode}.
The filter accepts the parameters: @var{struct_el}:@var{nb_iterations},
-with the same meaning and use of those of the dilate filter
-(@pxref{dilate}).
+with the same syntax and semantics as the @ref{dilate} filter.
@subsection smooth
@@ -891,18 +1693,14 @@ The parameters @var{width}, @var{height}, @var{x}, and @var{y} are
expressions containing the following constants:
@table @option
-@item E, PI, PHI
-the corresponding mathematical approximated values for e
-(euler number), pi (greek PI), phi (golden ratio)
-
@item in_w, in_h
-the input video width and heigth
+the input video width and height
@item iw, ih
same as @var{in_w} and @var{in_h}
@item out_w, out_h
-the output width and heigth, that is the size of the padded area as
+the output width and height, that is the size of the padded area as
specified by the @var{width} and @var{height} expressions
@item ow, oh
@@ -913,7 +1711,13 @@ x and y offsets as specified by the @var{x} and @var{y}
expressions, or NAN if not yet specified
@item a
-input display aspect ratio, same as @var{iw} / @var{ih}
+same as @var{iw} / @var{ih}
+
+@item sar
+input sample aspect ratio
+
+@item dar
+input display aspect ratio, it is the same as (@var{iw} / @var{ih}) * @var{sar}
@item hsub, vsub
horizontal and vertical chroma subsample values. For example for the
@@ -973,6 +1777,12 @@ pad="max(iw\,ih):ow:(ow-iw)/2:(oh-ih)/2"
# pad the input to get a final w/h ratio of 16:9
pad="ih*16/9:ih:(ow-iw)/2:(oh-ih)/2"
+# for anamorphic video, in order to set the output display aspect ratio,
+# it is necessary to use sar in the expression, according to the relation:
+# (ih * X / ih) * sar = output_dar
+# X = output_dar / sar
+pad="ih*16/9/sar:ih:(ow-iw)/2:(oh-ih)/2"
+
# double output size and put the input video in the bottom-right
# corner of the output padded area
pad="2*iw:2*ih:ow-iw:oh-ih"
@@ -998,24 +1808,29 @@ The parameters @var{width} and @var{height} are expressions containing
the following constants:
@table @option
-@item E, PI, PHI
-the corresponding mathematical approximated values for e
-(euler number), pi (greek PI), phi (golden ratio)
-
@item in_w, in_h
-the input width and heigth
+the input width and height
@item iw, ih
same as @var{in_w} and @var{in_h}
@item out_w, out_h
-the output (cropped) width and heigth
+the output (cropped) width and height
@item ow, oh
same as @var{out_w} and @var{out_h}
@item a
-input display aspect ratio, same as @var{iw} / @var{ih}
+same as @var{iw} / @var{ih}
+
+@item sar
+input sample aspect ratio
+
+@item dar
+input display aspect ratio, it is the same as (@var{iw} / @var{ih}) * @var{sar}
+
+@item sar
+input sample aspect ratio
@item hsub, vsub
horizontal and vertical chroma subsample values. For example for the
@@ -1065,6 +1880,113 @@ scale="trunc(3/2*iw/hsub)*hsub:trunc(3/2*ih/vsub)*vsub"
scale='min(500\, iw*3/2):-1'
@end example
+@section select
+Select frames to pass in output.
+
+It accepts in input an expression, which is evaluated for each input
+frame. If the expression is evaluated to a non-zero value, the frame
+is selected and passed to the output, otherwise it is discarded.
+
+The expression can contain the following constants:
+
+@table @option
+@item n
+the sequential number of the filtered frame, starting from 0
+
+@item selected_n
+the sequential number of the selected frame, starting from 0
+
+@item prev_selected_n
+the sequential number of the last selected frame, NAN if undefined
+
+@item TB
+timebase of the input timestamps
+
+@item pts
+the PTS (Presentation TimeStamp) of the filtered video frame,
+expressed in @var{TB} units, NAN if undefined
+
+@item t
+the PTS (Presentation TimeStamp) of the filtered video frame,
+expressed in seconds, NAN if undefined
+
+@item prev_pts
+the PTS of the previously filtered video frame, NAN if undefined
+
+@item prev_selected_pts
+the PTS of the last previously filtered video frame, NAN if undefined
+
+@item prev_selected_t
+the PTS of the last previously selected video frame, NAN if undefined
+
+@item start_pts
+the PTS of the first video frame in the video, NAN if undefined
+
+@item start_t
+the time of the first video frame in the video, NAN if undefined
+
+@item pict_type
+the type of the filtered frame, can assume one of the following
+values:
+@table @option
+@item I
+@item P
+@item B
+@item S
+@item SI
+@item SP
+@item BI
+@end table
+
+@item interlace_type
+the frame interlace type, can assume one of the following values:
+@table @option
+@item PROGRESSIVE
+the frame is progressive (not interlaced)
+@item TOPFIRST
+the frame is top-field-first
+@item BOTTOMFIRST
+the frame is bottom-field-first
+@end table
+
+@item key
+1 if the filtered frame is a key-frame, 0 otherwise
+
+@item pos
+the position in the file of the filtered frame, -1 if the information
+is not available (e.g. for synthetic video)
+@end table
+
+The default value of the select expression is "1".
+
+Some examples follow:
+
+@example
+# select all frames in input
+select
+
+# the above is the same as:
+select=1
+
+# skip all frames:
+select=0
+
+# select only I-frames
+select='eq(pict_type\,I)'
+
+# select one frame every 100
+select='not(mod(n\,100))'
+
+# select only frames contained in the 10-20 time interval
+select='gte(t\,10)*lte(t\,20)'
+
+# select only I frames contained in the 10-20 time interval
+select='gte(t\,10)*lte(t\,20)*eq(pict_type\,I)'
+
+# select frames with a minimum distance of 10 seconds
+select='isnan(prev_selected_t)+gte(t-prev_selected_t\,10)'
+@end example
+
@anchor{setdar}
@section setdar
@@ -1093,7 +2015,7 @@ setdar=16:9
setdar=1.77777
@end example
-See also the "setsar" filter documentation (@pxref{setsar}).
+See also the @ref{setsar} filter documentation.
@section setpts
@@ -1106,15 +2028,6 @@ can contain the following constants:
@item PTS
the presentation timestamp in input
-@item PI
-Greek PI
-
-@item PHI
-golden ratio
-
-@item E
-Euler number
-
@item N
the count of the input frame, starting from 0.
@@ -1187,7 +2100,7 @@ Set the timebase to use for the output frames timestamps.
It is mainly useful for testing timebase configuration.
It accepts in input an arithmetic expression representing a rational.
-The expression can contain the constants "PI", "E", "PHI", "AVTB" (the
+The expression can contain the constants "AVTB" (the
default timebase), and "intb" (the input timebase).
The default value for the input is "intb".
@@ -1211,6 +2124,65 @@ settb=2*intb
settb=AVTB
@end example
+@section showinfo
+
+Show a line containing various information for each input video frame.
+The input video is not modified.
+
+The shown line contains a sequence of key/value pairs of the form
+@var{key}:@var{value}.
+
+A description of each shown parameter follows:
+
+@table @option
+@item n
+sequential number of the input frame, starting from 0
+
+@item pts
+Presentation TimeStamp of the input frame, expressed as a number of
+time base units. The time base unit depends on the filter input pad.
+
+@item pts_time
+Presentation TimeStamp of the input frame, expressed as a number of
+seconds
+
+@item pos
+position of the frame in the input stream, -1 if this information in
+unavailable and/or meanigless (for example in case of synthetic video)
+
+@item fmt
+pixel format name
+
+@item sar
+sample aspect ratio of the input frame, expressed in the form
+@var{num}/@var{den}
+
+@item s
+size of the input frame, expressed in the form
+@var{width}x@var{height}
+
+@item i
+interlaced mode ("P" for "progressive", "T" for top field first, "B"
+for bottom field first)
+
+@item iskey
+1 if the frame is a key frame, 0 otherwise
+
+@item type
+picture type of the input frame ("I" for an I-frame, "P" for a
+P-frame, "B" for a B-frame, "?" for unknown type).
+Check also the documentation of the @code{AVPictureType} enum and of
+the @code{av_get_picture_type_char} function defined in
+@file{libavutil/avutil.h}.
+
+@item checksum
+Adler-32 checksum of all the planes of the input frame
+
+@item plane_checksum
+Adler-32 checksum of each plane of the input frame, expressed in the form
+"[@var{c0} @var{c1} @var{c2} @var{c3}]"
+@end table
+
@section slicify
Pass the images of input video on to next video filter as multiple
@@ -1226,6 +2198,21 @@ not specified it will use the default value of 16.
Adding this in the beginning of filter chains should make filtering
faster due to better use of the memory cache.
+@section split
+
+Pass on the input video to two outputs. Both outputs are identical to
+the input video.
+
+For example:
+@example
+[in] split [splitout1][splitout2];
+[splitout1] crop=100:100:0:0 [cropout];
+[splitout2] pad=200:200:100:100 [padout];
+@end example
+
+will create two separate outputs from the same input, one cropped and
+one padded.
+
@section transpose
Transpose rows with columns in the input video and optionally flip it.
@@ -1276,7 +2263,7 @@ It accepts the following parameters:
Negative values for the amount will blur the input video, while positive
values will sharpen. All parameters are optional and default to the
-equivalent of the string '5:5:1.0:0:0:0.0'.
+equivalent of the string '5:5:1.0:5:5:0.0'.
@table @option
@@ -1294,13 +2281,13 @@ and 5.0, default value is 1.0.
@item chroma_msize_x
Set the chroma matrix horizontal size. It can be an integer between 3
-and 13, default value is 0.
+and 13, default value is 5.
@item chroma_msize_y
Set the chroma matrix vertical size. It can be an integer between 3
-and 13, default value is 0.
+and 13, default value is 5.
-@item luma_amount
+@item chroma_amount
Set the chroma effect strength. It can be a float number between -2.0
and 5.0, default value is 0.0.
@@ -1330,7 +2317,7 @@ Flip the input video vertically.
Deinterlace the input video ("yadif" means "yet another deinterlacing
filter").
-It accepts the optional parameters: @var{mode}:@var{parity}.
+It accepts the optional parameters: @var{mode}:@var{parity}:@var{auto}.
@var{mode} specifies the interlacing mode to adopt, accepts one of the
following values:
@@ -1353,9 +2340,9 @@ interlaced video, accepts one of the following values:
@table @option
@item 0
-assume bottom field first
-@item 1
assume top field first
+@item 1
+assume bottom field first
@item -1
enable automatic detection
@end table
@@ -1364,6 +2351,18 @@ Default value is -1.
If interlacing is unknown or decoder does not export this information,
top field first will be assumed.
+@var{auto} specifies if deinterlacer should trust the interlaced flag
+and only deinterlace frames marked as interlaced
+
+@table @option
+@item 0
+deinterlace all frames
+@item 1
+only deinterlace frames marked as interlaced
+@end table
+
+Default value is 0.
+
@c man end VIDEO FILTERS
@chapter Video Sources
@@ -1379,9 +2378,10 @@ This source is mainly intended for a programmatic use, in particular
through the interface defined in @file{libavfilter/vsrc_buffer.h}.
It accepts the following parameters:
-@var{width}:@var{height}:@var{pix_fmt_string}:@var{timebase_num}:@var{timebase_den}:@var{sample_aspect_ratio_num}:@var{sample_aspect_ratio.den}
+@var{width}:@var{height}:@var{pix_fmt_string}:@var{timebase_num}:@var{timebase_den}:@var{sample_aspect_ratio_num}:@var{sample_aspect_ratio.den}:@var{scale_params}
-All the parameters need to be explicitely defined.
+All the parameters but @var{scale_params} need to be explicitely
+defined.
Follows the list of the accepted parameters.
@@ -1402,6 +2402,11 @@ timestamps of the buffered frames.
@item sample_aspect_ratio.num, sample_aspect_ratio.den
Specify numerator and denominator of the sample aspect ratio assumed
by the video frames.
+
+@item scale_params
+Specify the optional parameters to be used for the scale filter which
+is automatically inserted when an input change is detected in the
+input size or format.
@end table
For example:
@@ -1416,7 +2421,7 @@ Since the pixel format with name "yuv410p" corresponds to the number 6
(check the enum PixelFormat definition in @file{libavutil/pixfmt.h}),
this example corresponds to:
@example
-buffer=320:240:6:1:24
+buffer=320:240:6:1:24:1:1
@end example
@section color
@@ -1437,7 +2442,7 @@ alpha specifier. The default value is "black".
@item frame_size
Specify the size of the sourced video, it may be a string of the form
-@var{width}x@var{heigth}, or the name of a size abbreviation. The
+@var{width}x@var{height}, or the name of a size abbreviation. The
default value is "320x240".
@item frame_rate
@@ -1513,6 +2518,63 @@ movie=/dev/video0:f=video4linux2, scale=180:-1, setpts=PTS-STARTPTS [movie];
@end example
+@section mptestsrc
+
+Generate various test patterns, as generated by the MPlayer test filter.
+
+The size of the generated video is fixed, and is 256x256.
+This source is useful in particular for testing encoding features.
+
+This source accepts an optional sequence of @var{key}=@var{value} pairs,
+separated by ":". The description of the accepted options follows.
+
+@table @option
+
+@item rate, r
+Specify the frame rate of the sourced video, as the number of frames
+generated per second. It has to be a string in the format
+@var{frame_rate_num}/@var{frame_rate_den}, an integer number, a float
+number or a valid video frame rate abbreviation. The default value is
+"25".
+
+@item duration, d
+Set the video duration of the sourced video. The accepted syntax is:
+@example
+[-]HH[:MM[:SS[.m...]]]
+[-]S+[.m...]
+@end example
+See also the function @code{av_parse_time()}.
+
+If not specified, or the expressed duration is negative, the video is
+supposed to be generated forever.
+
+@item test, t
+
+Set the number or the name of the test to perform. Supported tests are:
+@table @option
+@item dc_luma
+@item dc_chroma
+@item freq_luma
+@item freq_chroma
+@item amp_luma
+@item amp_chroma
+@item cbp
+@item mv
+@item ring1
+@item ring2
+@item all
+@end table
+
+Default value is "all", which will cycle through the list of all tests.
+@end table
+
+For example the following:
+@example
+testsrc=t=dc_luma
+@end example
+
+will generate a "dc_luma" test pattern.
+
@section nullsrc
Null video source, never return images. It is mainly useful as a
@@ -1526,7 +2588,7 @@ source. The default values of @var{width} and @var{height} are
respectively 352 and 288 (corresponding to the CIF size format).
@var{timebase} specifies an arithmetic expression representing a
-timebase. The expression can contain the constants "PI", "E", "PHI",
+timebase. The expression can contain the constant
"AVTB" (the default timebase), and defaults to the value "AVTB".
@section frei0r_src
@@ -1534,7 +2596,7 @@ timebase. The expression can contain the constants "PI", "E", "PHI",
Provide a frei0r source.
To enable compilation of this filter you need to install the frei0r
-header and configure Libav with --enable-frei0r.
+header and configure FFmpeg with --enable-frei0r.
The source supports the syntax:
@example
@@ -1547,8 +2609,7 @@ form @var{width}x@var{height} or a frame size abbreviation.
the form @var{num}/@var{den} or a frame rate abbreviation.
@var{src_name} is the name to the frei0r source to load. For more
information regarding frei0r and how to set the parameters read the
-section "frei0r" (@pxref{frei0r}) in the description of the video
-filters.
+section @ref{frei0r} in the description of the video filters.
Some examples follow:
@example
@@ -1557,6 +2618,56 @@ Some examples follow:
frei0r_src=200x200:10:partik0l=1234 [overlay]; [in][overlay] overlay
@end example
+@section rgbtestsrc, testsrc
+
+The @code{rgbtestsrc} source generates an RGB test pattern useful for
+detecting RGB vs BGR issues. You should see a red, green and blue
+stripe from top to bottom.
+
+The @code{testsrc} source generates a test video pattern, showing a
+color pattern, a scrolling gradient and a timestamp. This is mainly
+intended for testing purposes.
+
+Both sources accept an optional sequence of @var{key}=@var{value} pairs,
+separated by ":". The description of the accepted options follows.
+
+@table @option
+
+@item size, s
+Specify the size of the sourced video, it may be a string of the form
+@var{width}x@var{heigth}, or the name of a size abbreviation. The
+default value is "320x240".
+
+@item rate, r
+Specify the frame rate of the sourced video, as the number of frames
+generated per second. It has to be a string in the format
+@var{frame_rate_num}/@var{frame_rate_den}, an integer number, a float
+number or a valid video frame rate abbreviation. The default value is
+"25".
+
+@item sar
+Set the sample aspect ratio of the sourced video.
+
+@item duration
+Set the video duration of the sourced video. The accepted syntax is:
+@example
+[-]HH[:MM[:SS[.m...]]]
+[-]S+[.m...]
+@end example
+See also the function @code{av_parse_time()}.
+
+If not specified, or the expressed duration is negative, the video is
+supposed to be generated forever.
+@end table
+
+For example the following:
+@example
+testsrc=duration=5.3:size=qcif:rate=10
+@end example
+
+will generate a video with a duration of 5.3 seconds, with size
+176x144 and a framerate of 10 frames per second.
+
@c man end VIDEO SOURCES
@chapter Video Sinks
@@ -1564,6 +2675,19 @@ frei0r_src=200x200:10:partik0l=1234 [overlay]; [in][overlay] overlay
Below is a description of the currently available video sinks.
+@section buffersink
+
+Buffer video frames, and make them available to the end of the filter
+graph.
+
+This sink is mainly intended for a programmatic use, in particular
+through the interface defined in @file{libavfilter/buffersink.h}.
+
+It does not require a string parameter in input, but you need to
+specify a pointer to a list of supported pixel formats terminated by
+-1 in the opaque parameter provided to @code{avfilter_init_filter}
+when initializing this sink.
+
@section nullsink
Null video sink, do absolutely nothing with the input video. It is
diff --git a/doc/general.texi b/doc/general.texi
index 775bf5d03f..3ba3c58f47 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -11,13 +11,13 @@
@chapter external libraries
-Libav can be hooked up with a number of external libraries to add support
+FFmpeg can be hooked up with a number of external libraries to add support
for more formats. None of them are used by default, their use has to be
explicitly requested by passing the appropriate flags to @file{./configure}.
@section OpenCORE AMR
-Libav can make use of the OpenCORE libraries for AMR-NB
+FFmpeg can make use of the OpenCORE libraries for AMR-NB
decoding/encoding and AMR-WB decoding.
Go to @url{http://sourceforge.net/projects/opencore-amr/} and follow the instructions for
@@ -27,7 +27,7 @@ installing the libraries. Then pass @code{--enable-libopencore-amrnb} and/or
Note that OpenCORE is under the Apache License 2.0 (see
@url{http://www.apache.org/licenses/LICENSE-2.0} for details), which is
incompatible with the LGPL version 2.1 and GPL version 2. You have to
-upgrade Libav's license to LGPL version 3 (or if you have enabled
+upgrade FFmpeg's license to LGPL version 3 (or if you have enabled
GPL components, GPL version 3) to use it.
@@ -37,7 +37,7 @@ You can use the @code{-formats} and @code{-codecs} options to have an exhaustive
@section File Formats
-Libav supports the following file formats through the @code{libavformat}
+FFmpeg supports the following file formats through the @code{libavformat}
library:
@multitable @columnfractions .4 .1 .1 .4
@@ -45,12 +45,15 @@ library:
@item 4xm @tab @tab X
@tab 4X Technologies format, used in some games.
@item 8088flex TMV @tab @tab X
+@item ACT Voice @tab @tab X
+ @tab contains G.729 audio
@item Adobe Filmstrip @tab X @tab X
@item Audio IFF (AIFF) @tab X @tab X
@item American Laser Games MM @tab @tab X
@tab Multimedia format used in games like Mad Dog McCree.
@item 3GPP AMR @tab X @tab X
@item Apple HTTP Live Streaming @tab @tab X
+@item Artworx Data Format @tab @tab X
@item ASF @tab X @tab X
@item AVI @tab X @tab X
@item AVISynth @tab @tab X
@@ -60,19 +63,21 @@ library:
@tab Audio and video format used in some games by Beam Software.
@item Bethesda Softworks VID @tab @tab X
@tab Used in some games from Bethesda Softworks.
+@item Binary text @tab @tab X
@item Bink @tab @tab X
@tab Multimedia format used by many games.
@item Bitmap Brothers JV @tab @tab X
@tab Used in Z and Z95 games.
@item Brute Force & Ignorance @tab @tab X
@tab Used in the game Flash Traffic: City of Angels.
+@item BWF @tab X @tab X
@item Interplay C93 @tab @tab X
@tab Used in the game Cyberia from Interplay.
@item Delphine Software International CIN @tab @tab X
@tab Multimedia format used by Delphine Software games.
@item CD+G @tab @tab X
@tab Video format used by CD+G karaoke disks
-@item Core Audio Format @tab @tab X
+@item Core Audio Format @tab X @tab X
@tab Apple Core Audio Format
@item CRC testing format @tab X @tab
@item Creative Voice @tab X @tab X
@@ -101,10 +106,13 @@ library:
@item framecrc testing format @tab X @tab
@item FunCom ISS @tab @tab X
@tab Audio format used in various games from FunCom like The Longest Journey.
+@item G.723.1 @tab X @tab X
+@item G.729 BIT @tab X @tab X
@item GIF Animation @tab X @tab
@item GXF @tab X @tab X
@tab General eXchange Format SMPTE 360M, used by Thomson Grass Valley
playout servers.
+@item iCEDraw File @tab @tab X
@item id Quake II CIN video @tab @tab X
@item id RoQ @tab X @tab X
@tab Used in Quake III, Jedi Knight 2, other computer games.
@@ -117,8 +125,11 @@ library:
@tab A format generated by IndigoVision 8000 video server.
@item IVF (On2) @tab X @tab X
@tab A format used by libvpx
+@item LATM @tab X @tab X
@item LMLM4 @tab @tab X
@tab Used by Linux Media Labs MPEG-4 PCI boards
+@item LOAS @tab @tab X
+ @tab contains LATM multiplexed AAC audio
@item LXF @tab @tab X
@tab VR native stream format, used by Leitch/Harris' video servers.
@item Matroska @tab X @tab X
@@ -162,6 +173,7 @@ library:
@item NUT @tab X @tab X
@tab NUT Open Container Format
@item Ogg @tab X @tab X
+@item Playstation Portable PMP @tab @tab X
@item TechnoTrend PVA @tab @tab X
@tab Used by TechnoTrend DVB PCI boards.
@item QCP @tab @tab X
@@ -251,15 +263,18 @@ library:
@item WAV @tab X @tab X
@item WavPack @tab @tab X
@item WebM @tab X @tab X
-@item Windows Televison (WTV) @tab @tab X
+@item Windows Televison (WTV) @tab X @tab X
@item Wing Commander III movie @tab @tab X
@tab Multimedia format used in Origin's Wing Commander III computer game.
@item Westwood Studios audio @tab @tab X
@tab Multimedia format used in Westwood Studios games.
@item Westwood Studios VQA @tab @tab X
@tab Multimedia format used in Westwood Studios games.
+@item XMV @tab @tab X
+ @tab Microsoft video container used in Xbox games.
@item xWMA @tab @tab X
@tab Microsoft audio container used by XAudio 2.
+@item eXtended BINary text (XBIN) @tab @tab X
@item YUV4MPEG pipe @tab X @tab X
@item Psygnosis YOP @tab @tab X
@end multitable
@@ -268,7 +283,7 @@ library:
@section Image Formats
-Libav can read and write images for each frame of a video sequence. The
+FFmpeg can read and write images for each frame of a video sequence. The
following image formats are supported:
@multitable @columnfractions .4 .1 .1 .4
@@ -283,8 +298,7 @@ following image formats are supported:
@tab Digital Picture Exchange
@item JPEG @tab X @tab X
@tab Progressive JPEG is not supported.
-@item JPEG 2000 @tab @tab E
- @tab decoding supported through external library libopenjpeg
+@item JPEG 2000 @tab X @tab X
@item JPEG-LS @tab X @tab X
@item LJPEG @tab X @tab
@tab Lossless JPEG
@@ -301,7 +315,6 @@ following image formats are supported:
@item PIC @tab @tab X
@tab Pictor/PC Paint
@item PNG @tab X @tab X
- @tab 2/4 bpp not supported yet
@item PPM @tab X @tab X
@tab Portable PixelMap image
@item PTX @tab @tab X
@@ -333,10 +346,11 @@ following image formats are supported:
@tab Creates video suitable to be played on a commodore 64 (multicolor mode).
@item American Laser Games MM @tab @tab X
@tab Used in games like Mad Dog McCree.
-@item AMV Video @tab @tab X
+@item AMV Video @tab X @tab X
@tab Used in Chinese MP3 players.
@item ANSI/ASCII art @tab @tab X
@item Apple MJPEG-B @tab @tab X
+@item Apple ProRes @tab @tab X
@item Apple QuickDraw @tab @tab X
@tab fourcc: qdrw
@item Asus v1 @tab X @tab X
@@ -400,6 +414,7 @@ following image formats are supported:
@tab experimental lossless codec (fourcc: FFV1)
@item Flash Screen Video v1 @tab X @tab X
@tab fourcc: FSV1
+@item Flash Screen Video v2 @tab X @tab X
@item Flash Video (FLV) @tab X @tab X
@tab Sorenson H.263 used in Flash
@item Fraps @tab @tab X
@@ -469,6 +484,8 @@ following image formats are supported:
@tab fourcc: VP80, encoding supported through external library libvpx
@item planar RGB @tab @tab X
@tab fourcc: 8BPS
+@item Prores @tab @tab X
+ @tab fourcc: apch,apcn,apcs,apco
@item Q-team QPEG @tab @tab X
@tab fourccs: QPEG, Q1.0, Q1.1
@item QuickTime 8BPS video @tab @tab X
@@ -510,10 +527,12 @@ following image formats are supported:
@tab encoding supported through external library libtheora
@item Tiertex Limited SEQ video @tab @tab X
@tab Codec used in DOS CD-ROM FlashBack game.
+@item Ut Video @tab @tab X
@item V210 Quicktime Uncompressed 4:2:2 10-bit @tab X @tab X
@item VMware Screen Codec / VMware Video @tab @tab X
@tab Codec used in videos captured by VMware.
@item Westwood Studios VQA (Vector Quantized Animation) video @tab @tab X
+@item Windows Media Image @tab @tab X
@item Windows Media Video 7 @tab X @tab X
@item Windows Media Video 8 @tab X @tab X
@item Windows Media Video 9 @tab @tab X
@@ -541,6 +560,8 @@ following image formats are supported:
@multitable @columnfractions .4 .1 .1 .4
@item Name @tab Encoding @tab Decoding @tab Comments
@item 8SVX audio @tab @tab X
+@item AAC+ @tab E @tab X
+ @tab encoding supported through external library libaacplus
@item AAC @tab E @tab X
@tab encoding supported through external library libfaac and libvo-aacenc
@item AC-3 @tab IX @tab X
@@ -598,11 +619,13 @@ following image formats are supported:
@item Atrac 3 @tab @tab X
@item Bink Audio @tab @tab X
@tab Used in Bink and Smacker files in many games.
+@item CELT (Opus) @tab @tab E
+ @tab decoding supported through external library libcelt
@item Delphine Software International CIN audio @tab @tab X
@tab Codec used in Delphine Software International games.
@item COOK @tab @tab X
@tab All versions except 5.1 are supported.
-@item DCA (DTS Coherent Acoustics) @tab @tab X
+@item DCA (DTS Coherent Acoustics) @tab X @tab X
@item DPCM id RoQ @tab X @tab X
@tab Used in Quake III, Jedi Knight 2, other computer games.
@item DPCM Interplay @tab @tab X
@@ -616,6 +639,8 @@ following image formats are supported:
@item DV audio @tab @tab X
@item Enhanced AC-3 @tab X @tab X
@item FLAC (Free Lossless Audio Codec) @tab X @tab IX
+@item G.723.1 @tab X @tab X
+@item G.729 @tab @tab X
@item GSM @tab E @tab X
@tab encoding supported through external library libgsm
@item GSM Microsoft variant @tab E @tab X
@@ -674,7 +699,11 @@ following image formats are supported:
@tab Used in Sierra VMD files.
@item Smacker audio @tab @tab X
@item SMPTE 302M AES3 audio @tab @tab X
-@item Speex @tab @tab E
+@item Sonic @tab X @tab X
+ @tab experimental codec
+@item Sonic lossless @tab X @tab X
+ @tab experimental codec
+@item Speex @tab E @tab E
@tab supported through external library libspeex
@item True Audio (TTA) @tab @tab X
@item TrueHD @tab @tab X
@@ -704,8 +733,9 @@ performance on systems without hardware floating point support).
@item SSA/ASS @tab X @tab X @tab X @tab X
@item DVB @tab X @tab X @tab X @tab X
@item DVD @tab X @tab X @tab X @tab X
+@item MicroDVD @tab X @tab X @tab @tab
@item PGS @tab @tab @tab @tab X
-@item SubRip (SRT) @tab X @tab X @tab @tab X
+@item SubRip (SRT) @tab X @tab X @tab X @tab X
@item XSUB @tab @tab @tab X @tab X
@end multitable
@@ -756,12 +786,12 @@ Using a cross-compiler is preferred for various reasons.
@section OS/2
-For information about compiling Libav on OS/2 see
+For information about compiling FFmpeg on OS/2 see
@url{http://www.edm2.com/index.php/FFmpeg}.
@section Unix-like
-Some parts of Libav cannot be built with version 2.15 of the GNU
+Some parts of FFmpeg cannot be built with version 2.15 of the GNU
assembler which is still provided by a few AMD64 distributions. To
make sure your compiler really uses the required version of gas
after a binutils upgrade, run:
@@ -776,12 +806,12 @@ to configure.
@subsection BSD
-BSD make will not build Libav, you need to install and use GNU Make
+BSD make will not build FFmpeg, you need to install and use GNU Make
(@file{gmake}).
@subsection (Open)Solaris
-GNU Make is required to build Libav, so you have to invoke (@file{gmake}),
+GNU Make is required to build FFmpeg, so you have to invoke (@file{gmake}),
standard Solaris Make will not work. When building with a non-c99 front-end
(gcc, generic suncc) add either @code{--extra-libs=/usr/lib/values-xpg6.o}
or @code{--extra-libs=/usr/lib/64/values-xpg6.o} to the configure options
@@ -799,18 +829,22 @@ bash ./configure
MacOS X on PowerPC or ARM (iPhone) requires a preprocessor from
@url{http://github.com/yuvi/gas-preprocessor} to build the optimized
assembler functions. Just download the Perl script and put it somewhere
-in your PATH, Libav's configure will pick it up automatically.
+in your PATH, FFmpeg's configure will pick it up automatically.
@section Windows
+To get help and instructions for building FFmpeg under Windows, check out
+the FFmpeg Windows Help Forum at
+@url{http://ffmpeg.arrozcru.org/}.
+
@subsection Native Windows compilation
-Libav can be built to run natively on Windows using the MinGW tools. Install
+FFmpeg can be built to run natively on Windows using the MinGW tools. Install
the latest versions of MSYS and MinGW from @url{http://www.mingw.org/}.
-You can find detailed installation
-instructions in the download section and the FAQ.
+You can find detailed installation instructions in the download
+section and the FAQ.
-Libav does not build out-of-the-box with the packages the automated MinGW
+FFmpeg does not build out-of-the-box with the packages the automated MinGW
installer provides. It also requires coreutils to be installed and many other
packages updated to the latest version. The minimum version for some packages
are listed below:
@@ -822,7 +856,7 @@ are listed below:
@item mingw-runtime 3.15
@end itemize
-Libav automatically passes @code{-fno-common} to the compiler to work around
+FFmpeg automatically passes @code{-fno-common} to the compiler to work around
a GCC bug (see @url{http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37216}).
Notes:
@@ -836,19 +870,20 @@ noticeable when running make for a second time (for example in
@code{make install}).
@item In order to compile FFplay, you must have the MinGW development library
-of SDL. Get it from @url{http://www.libsdl.org}.
+of @uref{http://www.libsdl.org/, SDL}.
Edit the @file{bin/sdl-config} script so that it points to the correct prefix
where SDL was installed. Verify that @file{sdl-config} can be launched from
the MSYS command line.
-@item By using @code{./configure --enable-shared} when configuring Libav,
-you can build libavutil, libavcodec and libavformat as DLLs.
+@item By using @code{./configure --enable-shared} when configuring FFmpeg,
+you can build the FFmpeg libraries (e.g. libavutil, libavcodec,
+libavformat) as DLLs.
@end itemize
@subsection Microsoft Visual C++ compatibility
-As stated in the FAQ, Libav will not compile under MSVC++. However, if you
+As stated in the FAQ, FFmpeg will not compile under MSVC++. However, if you
want to use the libav* libraries in your own applications, you can still
compile those applications using MSVC++. But the libav* libraries you link
to @emph{must} be built with MinGW. However, you will not be able to debug
@@ -856,13 +891,13 @@ inside the libav* libraries, since MSVC++ does not recognize the debug
symbols generated by GCC.
We strongly recommend you to move over from MSVC++ to MinGW tools.
-This description of how to use the Libav libraries with MSVC++ is based on
+This description of how to use the FFmpeg libraries with MSVC++ is based on
Microsoft Visual C++ 2005 Express Edition. If you have a different version,
you might have to modify the procedures slightly.
@subsubsection Using static libraries
-Assuming you have just built and installed Libav in @file{/usr/local}.
+Assuming you have just built and installed FFmpeg in @file{/usr/local}.
@enumerate
@@ -873,13 +908,13 @@ Application Wizard, uncheck the "Precompiled headers" option.
@item Write the source code for your application, or, for testing, just
copy the code from an existing sample application into the source file
that MSVC++ has already created for you. For example, you can copy
-@file{libavformat/output-example.c} from the Libav distribution.
+@file{libavformat/output-example.c} from the FFmpeg distribution.
@item Open the "Project / Properties" dialog box. In the "Configuration"
combo box, select "All Configurations" so that the changes you make will
affect both debug and release builds. In the tree view on the left hand
side, select "C/C++ / General", then edit the "Additional Include
-Directories" setting to contain the path where the Libav includes were
+Directories" setting to contain the path where the FFmpeg includes were
installed (i.e. @file{c:\msys\1.0\local\include}).
Do not add MinGW's include directory here, or the include files will
conflict with MSVC's.
@@ -887,7 +922,7 @@ conflict with MSVC's.
@item Still in the "Project / Properties" dialog box, select
"Linker / General" from the tree view and edit the
"Additional Library Directories" setting to contain the @file{lib}
-directory where Libav was installed (i.e. @file{c:\msys\1.0\local\lib}),
+directory where FFmpeg was installed (i.e. @file{c:\msys\1.0\local\lib}),
the directory where MinGW libs are installed (i.e. @file{c:\mingw\lib}),
and the directory where MinGW's GCC libs are installed
(i.e. @file{C:\mingw\lib\gcc\mingw32\4.2.1-sjlj}). Then select
@@ -904,13 +939,13 @@ set to "Multi-threaded DLL".
@item Click "OK" to close the "Project / Properties" dialog box.
-@item MSVC++ lacks some C99 header files that are fundamental for Libav.
+@item MSVC++ lacks some C99 header files that are fundamental for FFmpeg.
Get msinttypes from @url{http://code.google.com/p/msinttypes/downloads/list}
and install it in MSVC++'s include directory
(i.e. @file{C:\Program Files\Microsoft Visual Studio 8\VC\include}).
@item MSVC++ also does not understand the @code{inline} keyword used by
-Libav, so you must add this line before @code{#include}ing libav*:
+FFmpeg, so you must add this line before @code{#include}ing libav*:
@example
#define inline _inline
@end example
@@ -943,13 +978,13 @@ and run @file{c:\msys\1.0\msys.bat} from there.
@item Within the MSYS shell, run @code{lib.exe}. If you get a help message
from @file{Microsoft (R) Library Manager}, this means your environment
variables are set up correctly, the @file{Microsoft (R) Library Manager}
-is on the path and will be used by Libav to create
+is on the path and will be used by FFmpeg to create
MSVC++-compatible import libraries.
-@item Build Libav with
+@item Build FFmpeg with
@example
-./configure --enable-shared --enable-memalign-hack
+./configure --enable-shared
make
make install
@end example
@@ -957,7 +992,8 @@ make install
Your install path (@file{/usr/local/} by default) should now have the
necessary DLL and LIB files under the @file{bin} directory.
-@end enumerate
+Alternatively, build the libraries with a cross compiler, according to
+the instructions below in @ref{Cross compilation for Windows with Linux}.
To use those files with MSVC++, do the same as you would do with
the static libraries, as described above. But in Step 4,
@@ -970,12 +1006,9 @@ libraries (@file{libxxx.a} files) you should add the MSVC import libraries
libraries (@file{libxxx.dll.a} files), as these will give you undefined
reference errors. There should be no need for @file{libmingwex.a},
@file{libgcc.a}, and @file{wsock32.lib}, nor any other external library
-statically linked into the DLLs. The @file{bin} directory contains a bunch
-of DLL files, but the ones that are actually used to run your application
-are the ones with a major version number in their filenames
-(i.e. @file{avcodec-51.dll}).
+statically linked into the DLLs.
-Libav headers do not declare global data for Windows DLLs through the usual
+FFmpeg headers do not declare global data for Windows DLLs through the usual
dllexport/dllimport interface. Such data will be exported properly while
building, but to use them in your MSVC++ code you will have to edit the
appropriate headers and mark the data as dllimport. For example, in
@@ -986,24 +1019,54 @@ extern __declspec(dllimport) const AVPixFmtDescriptor av_pix_fmt_descriptors[];
Note that using import libraries created by dlltool requires
the linker optimization option to be set to
-"References: Keep Unreferenced Data (/OPT:NOREF)", otherwise
+"References: Keep Unreferenced Data (@code{/OPT:NOREF})", otherwise
the resulting binaries will fail during runtime. This isn't
required when using import libraries generated by lib.exe.
+This issue is reported upstream at
+@url{http://sourceware.org/bugzilla/show_bug.cgi?id=12633}.
+
+To create import libraries that work with the @code{/OPT:REF} option
+(which is enabled by default in Release mode), follow these steps:
+
+@enumerate
+
+@item Open @file{Visual Studio 2005 Command Prompt}.
+
+Alternatively, in a normal command line prompt, call @file{vcvars32.bat}
+which sets up the environment variables for the Visual C++ tools
+(the standard location for this file is
+@file{C:\Program Files\Microsoft Visual Studio 8\VC\bin\vcvars32.bat}).
+
+@item Enter the @file{bin} directory where the created LIB and DLL files
+are stored.
+
+@item Generate new import libraries with @file{lib.exe}:
+
+@example
+lib /machine:i386 /def:..\lib\avcodec-53.def /out:avcodec.lib
+lib /machine:i386 /def:..\lib\avdevice-53.def /out:avdevice.lib
+lib /machine:i386 /def:..\lib\avfilter-2.def /out:avfilter.lib
+lib /machine:i386 /def:..\lib\avformat-53.def /out:avformat.lib
+lib /machine:i386 /def:..\lib\avutil-51.def /out:avutil.lib
+lib /machine:i386 /def:..\lib\swscale-2.def /out:swscale.lib
+@end example
+
+@end enumerate
+@anchor{Cross compilation for Windows with Linux}
@subsection Cross compilation for Windows with Linux
You must use the MinGW cross compilation tools available at
@url{http://www.mingw.org/}.
-Then configure Libav with the following options:
+Then configure FFmpeg with the following options:
@example
./configure --target-os=mingw32 --cross-prefix=i386-mingw32msvc-
@end example
(you can change the cross-prefix according to the prefix chosen for the
MinGW tools).
-Then you can easily test Libav with Wine
-(@url{http://www.winehq.com/}).
+Then you can easily test FFmpeg with @uref{http://www.winehq.com/, Wine}.
@subsection Compilation under Cygwin
@@ -1024,7 +1087,7 @@ diffutils
Then run
@example
-./configure --enable-static --disable-shared
+./configure
@end example
to make a static build.
@@ -1036,17 +1099,17 @@ shared libraries:
./configure --enable-shared --disable-static --extra-cflags=-fno-reorder-functions
@end example
-If you want to build Libav with additional libraries, download Cygwin
+If you want to build FFmpeg with additional libraries, download Cygwin
"Devel" packages for Ogg and Vorbis from any Cygwin packages repository:
@example
libogg-devel, libvorbis-devel
@end example
-These library packages are only available from Cygwin Ports
-(@url{http://sourceware.org/cygwinports/}) :
+These library packages are only available from
+@uref{http://sourceware.org/cygwinports/, Cygwin Ports}:
@example
-yasm, libSDL-devel, libdirac-devel, libfaac-devel, libgsm-devel,
+yasm, libSDL-devel, libdirac-devel, libfaac-devel, libaacplus-devel, libgsm-devel,
libmp3lame-devel, libschroedinger1.0-devel, speex-devel, libtheora-devel,
libxvidcore-devel
@end example
@@ -1071,12 +1134,12 @@ and add some special flags to your configure invocation.
For a static build run
@example
-./configure --target-os=mingw32 --enable-memalign-hack --enable-static --disable-shared --extra-cflags=-mno-cygwin --extra-libs=-mno-cygwin
+./configure --target-os=mingw32 --extra-cflags=-mno-cygwin --extra-libs=-mno-cygwin
@end example
and for a build with shared libraries
@example
-./configure --target-os=mingw32 --enable-memalign-hack --enable-shared --disable-static --extra-cflags=-mno-cygwin --extra-libs=-mno-cygwin
+./configure --target-os=mingw32 --enable-shared --disable-static --extra-cflags=-mno-cygwin --extra-libs=-mno-cygwin
@end example
@bye
diff --git a/doc/git-howto.txt b/doc/git-howto.txt
index ba377c99e0..72cde72eed 100644
--- a/doc/git-howto.txt
+++ b/doc/git-howto.txt
@@ -28,9 +28,9 @@ Consult these resources whenever you have problems, they are quite exhaustive.
You do not need a special username or password.
All you need is to provide a ssh public key to the Git server admin.
-What follows now is a basic introduction to Git and some Libav-specific
+What follows now is a basic introduction to Git and some FFmpeg-specific
guidelines. Read it at least once, if you are granted commit privileges to the
-Libav project you are expected to be familiar with these rules.
+FFmpeg project you are expected to be familiar with these rules.
@@ -44,13 +44,13 @@ I. BASICS:
1. Cloning the source tree:
- git clone git://git.libav.org/libav.git <target>
+ git clone git://git.videolan.org/ffmpeg <target>
- This will put the Libav sources into the directory <target>.
+ This will put the FFmpeg sources into the directory <target>.
- git clone git@git.libav.org:libav.git <target>
+ git clone git@git.videolan.org:ffmpeg <target>
- This will put the Libav sources into the directory <target> and let
+ This will put the FFmpeg sources into the directory <target> and let
you push back your changes to the remote repository.
@@ -72,7 +72,7 @@ I. BASICS:
fetches the changes from the main repository and replays your local commits
over it. This is required to keep all your local changes at the top of
- Libav's master tree. The master tree will reject pushes with merge commits.
+ FFmpeg's master tree. The master tree will reject pushes with merge commits.
3. Adding/removing files/directories:
@@ -97,7 +97,7 @@ I. BASICS:
git log <filename(s)>
You may also use the graphical tools like gitview or gitk or the web
- interface available at http://git.libav.org/
+ interface available at http://git.videolan.org
6. Checking source tree status:
@@ -255,5 +255,5 @@ I. BASICS:
where $SHA1 is the commit SHA1 from the 'git log' output.
-Contact the project admins <git at libav dot org> if you have technical
+Contact the project admins <root at ffmpeg dot org> if you have technical
problems with the GIT server.
diff --git a/doc/indevs.texi b/doc/indevs.texi
index c5e04b029e..79f786f8e0 100644
--- a/doc/indevs.texi
+++ b/doc/indevs.texi
@@ -1,10 +1,10 @@
@chapter Input Devices
@c man begin INPUT DEVICES
-Input devices are configured elements in Libav which allow to access
+Input devices are configured elements in FFmpeg which allow to access
the data coming from a multimedia device attached to your system.
-When you configure your Libav build, all the supported input devices
+When you configure your FFmpeg build, all the supported input devices
are enabled by default. You can list all available ones using the
configure option "--list-indevs".
@@ -55,6 +55,87 @@ For more information see:
BSD video input device.
+@section dshow
+
+Windows DirectShow input device.
+
+DirectShow support is enabled when FFmpeg is built with mingw-w64.
+Currently only audio and video devices are supported.
+
+Multiple devices may be opened as separate inputs, but they may also be
+opened on the same input, which should improve synchronism between them.
+
+The input name should be in the format:
+
+@example
+@var{TYPE}=@var{NAME}[:@var{TYPE}=@var{NAME}]
+@end example
+
+where @var{TYPE} can be either @var{audio} or @var{video},
+and @var{NAME} is the device's name.
+
+@subsection Options
+
+If no options are specified, the device's defaults are used.
+If the device does not support the requested options, it will
+fail to open.
+
+@table @option
+
+@item video_size
+Set the video size in the captured video.
+
+@item framerate
+Set the framerate in the captured video.
+
+@item sample_rate
+Set the sample rate (in Hz) of the captured audio.
+
+@item sample_size
+Set the sample size (in bits) of the captured audio.
+
+@item channels
+Set the number of channels in the captured audio.
+
+@item list_devices
+If set to @option{true}, print a list of devices and exit.
+
+@item list_options
+If set to @option{true}, print a list of selected device's options
+and exit.
+
+@end table
+
+@subsection Examples
+
+@itemize
+
+@item
+Print the list of DirectShow supported devices and exit:
+@example
+$ ffmpeg -list_devices true -f dshow -i dummy
+@end example
+
+@item
+Open video device @var{Camera}:
+@example
+$ ffmpeg -f dshow -i video="Camera"
+@end example
+
+@item
+Open video device @var{Camera} and audio device @var{Microphone}:
+@example
+$ ffmpeg -f dshow -i video="Camera":audio="Microphone"
+@end example
+
+@item
+Print the list of supported options in selected device and exit:
+@example
+$ ffmpeg -list_options true -f dshow -i video="Camera"
+@end example
+
+@end itemize
+
@section dv1394
Linux DV 1394 input device.
@@ -95,7 +176,7 @@ A JACK input device creates one or more JACK writable clients, one for
each audio channel, with name @var{client_name}:input_@var{N}, where
@var{client_name} is the name provided by the application, and @var{N}
is a number which identifies the channel.
-Each writable client will send the acquired data to the Libav input
+Each writable client will send the acquired data to the FFmpeg input
device.
Once you have created one or more JACK readable clients, you need to
@@ -133,10 +214,168 @@ $ jack_connect metro:120_bpm ffmpeg:input_1
For more information read:
@url{http://jackaudio.org/}
+@section lavfi
+
+Libavfilter input virtual device.
+
+This input device reads data from the open output pads of a libavfilter
+filtergraph.
+
+For each filtergraph open output, the input device will create a
+corresponding stream which is mapped to the generated output. Currently
+only video data is supported. The filtergraph is specified through the
+option @option{graph}.
+
+To enable this input device, you need to configure your build with
+@code{--enable-libavfilter}.
+
+@subsection Options
+
+@table @option
+
+@item graph
+Specify the filtergraph to use as input. Each video open output must be
+labelled by a unique string of the form "out@var{N}", where @var{N} is a
+number starting from 0 corresponding to the mapped input stream
+generated by the device.
+The first unlabelled output is automatically assigned to the "out0"
+label, but all the others need to be specified explicitely.
+
+If not specified defaults to the filename specified for the input
+device.
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Create a color video stream and play it back with @file{ffplay}:
+@example
+ffplay -f lavfi -graph "color=pink [out0]" dummy
+@end example
+
+@item
+As the previous example, but use filename for specifying the graph
+description, and omit the "out0" label:
+@example
+ffplay -f lavfi color=pink
+@end example
+
+@item
+Create three different video test filtered sources and play them:
+@example
+ffplay -f lavfi -graph "testsrc [out0]; testsrc,hflip [out1]; testsrc,negate [out2]" test3
+@end example
+
+@item
+Read an audio stream from a file using the amovie source and play it
+back with @file{ffplay}:
+@example
+ffplay -f lavfi "amovie=test.wav"
+@end example
+
+@item
+Read an audio stream and a video stream and play it back with
+@file{ffplay}:
+@example
+ffplay -f lavfi "movie=test.avi[out0];amovie=test.wav[out1]"
+@end example
+
+@end itemize
+
@section libdc1394
IIDC1394 input device, based on libdc1394 and libraw1394.
+@section openal
+
+The OpenAL input device provides audio capture on all systems with a
+working OpenAL 1.1 implementation.
+
+To enable this input device during configuration, you need OpenAL
+headers and libraries installed on your system, and need to configure
+FFmpeg with @code{--enable-openal}.
+
+OpenAL headers and libraries should be provided as part of your OpenAL
+implementation, or as an additional download (an SDK). Depending on your
+installation you may need to specify additional flags via the
+@code{--extra-cflags} and @code{--extra-ldflags} for allowing the build
+system to locate the OpenAL headers and libraries.
+
+An incomplete list of OpenAL implementations follows:
+
+@table @strong
+@item Creative
+The official Windows implementation, providing hardware acceleration
+with supported devices and software fallback.
+See @url{http://openal.org/}.
+@item OpenAL Soft
+Portable, open source (LGPL) software implementation. Includes
+backends for the most common sound APIs on the Windows, Linux,
+Solaris, and BSD operating systems.
+See @url{http://kcat.strangesoft.net/openal.html}.
+@item Apple
+OpenAL is part of Core Audio, the official Mac OS X Audio interface.
+See @url{http://developer.apple.com/technologies/mac/audio-and-video.html}
+@end table
+
+This device allows to capture from an audio input device handled
+through OpenAL.
+
+You need to specify the name of the device to capture in the provided
+filename. If the empty string is provided, the device will
+automatically select the default device. You can get the list of the
+supported devices by using the option @var{list_devices}.
+
+@subsection Options
+
+@table @option
+
+@item channels
+Set the number of channels in the captured audio. Only the values
+@option{1} (monaural) and @option{2} (stereo) are currently supported.
+Defaults to @option{2}.
+
+@item sample_size
+Set the sample size (in bits) of the captured audio. Only the values
+@option{8} and @option{16} are currently supported. Defaults to
+@option{16}.
+
+@item sample_rate
+Set the sample rate (in Hz) of the captured audio.
+Defaults to @option{44.1k}.
+
+@item list_devices
+If set to @option{true}, print a list of devices and exit.
+Defaults to @option{false}.
+
+@end table
+
+@subsection Examples
+
+Print the list of OpenAL supported devices and exit:
+@example
+$ ffmpeg -list_devices true -f openal -i dummy out.ogg
+@end example
+
+Capture from the OpenAL device @file{DR-BT101 via PulseAudio}:
+@example
+$ ffmpeg -f openal -i 'DR-BT101 via PulseAudio' out.ogg
+@end example
+
+Capture from the default device (note the empty string '' as filename):
+@example
+$ ffmpeg -f openal -i '' out.ogg
+@end example
+
+Capture from two devices simultaneously, writing to two different files,
+within the same @file{ffmpeg} command:
+@example
+$ ffmpeg -f openal -i 'DR-BT101 via PulseAudio' out1.ogg -f openal -i 'ALSA Default' out2.ogg
+@end example
+Note: not all OpenAL implementations support multiple simultaneous capture -
+try the latest OpenAL Soft if the above does not work.
+
@section oss
Open Sound System input device.
@@ -248,7 +487,46 @@ For example to grab from @file{:0.0} using @file{ffmpeg}:
ffmpeg -f x11grab -r 25 -s cif -i :0.0 out.mpg
# Grab at position 10,20.
-ffmpeg -f x11grab -25 -s cif -i :0.0+10,20 out.mpg
+ffmpeg -f x11grab -r 25 -s cif -i :0.0+10,20 out.mpg
+@end example
+
+@subsection @var{follow_mouse} AVOption
+
+The syntax is:
+@example
+-follow_mouse centered|@var{PIXELS}
+@end example
+
+When it is specified with "centered", the grabbing region follows the mouse
+pointer and keeps the pointer at the center of region; otherwise, the region
+follows only when the mouse pointer reaches within @var{PIXELS} (greater than
+zero) to the edge of region.
+
+For example:
+@example
+ffmpeg -f x11grab -follow_mouse centered -r 25 -s cif -i :0.0 out.mpg
+
+# Follows only when the mouse pointer reaches within 100 pixels to edge
+ffmpeg -f x11grab -follow_mouse 100 -r 25 -s cif -i :0.0 out.mpg
+@end example
+
+@subsection @var{show_region} AVOption
+
+The syntax is:
+@example
+-show_region 1
+@end example
+
+If @var{show_region} AVOption is specified with @var{1}, then the grabbing
+region will be indicated on screen. With this option, it's easy to know what is
+being grabbed if only a portion of the screen is grabbed.
+
+For example:
+@example
+ffmpeg -f x11grab -show_region 1 -r 25 -s cif -i :0.0+10,20 out.mpg
+
+# With follow_mouse
+ffmpeg -f x11grab -follow_mouse centered -show_region 1 -r 25 -s cif -i :0.0 out.mpg
@end example
@c man end INPUT DEVICES
diff --git a/doc/issue_tracker.txt b/doc/issue_tracker.txt
new file mode 100644
index 0000000000..d487f66830
--- /dev/null
+++ b/doc/issue_tracker.txt
@@ -0,0 +1,213 @@
+FFmpeg's bug/patch/feature request tracker manual
+=================================================
+
+NOTE: This is a draft.
+
+Overview:
+---------
+
+FFmpeg uses Trac for tracking issues, new issues and changes to
+existing issues can be done through a web interface.
+
+Issues can be different kinds of things we want to keep track of
+but that do not belong into the source tree itself. This includes
+bug reports, patches, feature requests and license violations. We
+might add more items to this list in the future, so feel free to
+propose a new `type of issue' on the ffmpeg-devel mailing list if
+you feel it is worth tracking.
+
+It is possible to subscribe to individual issues by adding yourself to the
+Cc list or to subscribe to the ffmpeg-trac mailing list which receives
+a mail for every change to every issue.
+(the above does all work already after light testing)
+
+The subscription URL for the ffmpeg-trac list is:
+http(s)://ffmpeg.org/mailman/listinfo/ffmpeg-trac
+The URL of the webinterface of the tracker is:
+http(s)://ffmpeg.org/trac/ffmpeg
+
+Type:
+-----
+bug / defect
+ An error, flaw, mistake, failure, or fault in FFmpeg or libav* that
+ prevents it from behaving as intended.
+
+feature request / enhancement
+ Request of support for encoding or decoding of a new codec, container
+ or variant.
+ Request of support for more, less or plain different output or behavior
+ where the current implementation cannot be considered wrong.
+
+license violation
+ ticket to keep track of (L)GPL violations of ffmpeg by others
+
+patch
+ A patch as generated by diff which conforms to the patch submission and
+ development policy.
+
+
+Priority:
+---------
+critical
+ Bugs and patches which deal with data loss and security issues.
+ No feature request can be critical.
+
+important
+ Bugs which make FFmpeg unusable for a significant number of users, and
+ patches fixing them.
+ Examples here might be completely broken MPEG-4 decoding or a build issue
+ on Linux.
+ While broken 4xm decoding or a broken OS/2 build would not be important,
+ the separation to normal is somewhat fuzzy.
+ For feature requests this priority would be used for things many people
+ want.
+ Regressions also should be marked as important, regressions are bugs that
+ don't exist in a past revision or another branch.
+
+normal
+
+
+minor
+ Bugs and patches about things like spelling errors, "mp2" instead of
+ "mp3" being shown and such.
+ Feature requests about things few people want or which do not make a big
+ difference.
+
+wish
+ Something that is desirable to have but that there is no urgency at
+ all to implement, e.g. something completely cosmetic like a website
+ restyle or a personalized doxy template or the FFmpeg logo.
+ This priority is not valid for bugs.
+
+
+Status:
+-------
+new
+ initial state
+
+open
+ intermediate states
+
+closed
+ final state
+
+
+Analyzed flag:
+--------------
+Bugs which have been analyzed and where it is understood what causes them
+and which exact chain of events triggers them. This analysis should be
+available as a message in the bug report.
+Note, do not change the status to analyzed without also providing a clear
+and understandable analysis.
+This state implicates that the bug either has been reproduced or that
+reproduction is not needed as the bug is already understood.
+
+
+Type/Status/Substatus:
+----------
+*/new/new
+ Initial state of new bugs, patches and feature requests submitted by
+ users.
+
+*/open/open
+ Issues which have been briefly looked at and which did not look outright
+ invalid.
+ This implicates that no real more detailed state applies yet. Conversely,
+ the more detailed states below implicate that the issue has been briefly
+ looked at.
+
+*/closed/duplicate
+ Bugs, patches or feature requests which are duplicates.
+ Note that patches dealing with the same thing in a different way are not
+ duplicates.
+ Note, if you mark something as duplicate, do not forget setting the
+ superseder so bug reports are properly linked.
+
+*/closed/invalid
+ Bugs caused by user errors, random ineligible or otherwise nonsense stuff.
+
+*/closed/needs_more_info
+ Issues for which some information has been requested by the developers,
+ but which has not been provided by anyone within reasonable time.
+
+
+bug/closed/fixed
+ Bugs which have to the best of our knowledge been fixed.
+
+bug/closed/wont_fix
+ Bugs which we will not fix. Possible reasons include legality, high
+ complexity for the sake of supporting obscure corner cases, speed loss
+ for similarly esoteric purposes, et cetera.
+ This also means that we would reject a patch.
+ If we are just too lazy to fix a bug then the correct state is open
+ and unassigned. Closed means that the case is closed which is not
+ the case if we are just waiting for a patch.
+
+bug/closed/works_for_me
+ Bugs for which sufficient information was provided to reproduce but
+ reproduction failed - that is the code seems to work correctly to the
+ best of our knowledge.
+
+patch/open/approved
+ Patches which have been reviewed and approved by a developer.
+ Such patches can be applied anytime by any other developer after some
+ reasonable testing (compile + regression tests + does the patch do
+ what the author claimed).
+
+patch/open/needs_changes
+ Patches which have been reviewed and need changes to be accepted.
+
+patch/closed/applied
+ Patches which have been applied.
+
+patch/closed/rejected
+ Patches which have been rejected.
+
+feature_request/closed/implemented
+ Feature requests which have been implemented.
+
+feature_request/closed/wont_implement
+ Feature requests which will not be implemented. The reasons here could
+ be legal, philosophical or others.
+
+Note, please do not use type-status-substatus combinations other than the
+above without asking on ffmpeg-dev first!
+
+Note2, if you provide the requested info do not forget to remove the
+needs_more_info substatus.
+
+Component:
+----------
+
+avcodec
+ issues in libavcodec/*
+
+avformat
+ issues in libavformat/*
+
+avutil
+ issues in libavutil/*
+
+regression test
+ issues in tests/*
+
+ffmpeg
+ issues in or related to ffmpeg.c
+
+ffplay
+ issues in or related to ffplay.c
+
+ffprobe
+ issues in or related to ffprobe.c
+
+ffserver
+ issues in or related to ffserver.c
+
+build system
+ issues in or related to configure/Makefile
+
+regression
+ bugs which were not present in a past revision
+
+trac
+ issues related to our issue tracker
diff --git a/doc/libavfilter.texi b/doc/libavfilter.texi
index 1c1220541c..5bb5b1a84d 100644
--- a/doc/libavfilter.texi
+++ b/doc/libavfilter.texi
@@ -11,23 +11,11 @@
@chapter Introduction
-Libavfilter is the filtering API of Libav. It is the substitute of the
+Libavfilter is the filtering API of FFmpeg. It is the substitute of the
now deprecated 'vhooks' and started as a Google Summer of Code project.
-Integrating libavfilter into the main Libav repository is a work in
-progress. If you wish to try the unfinished development code of
-libavfilter then check it out from the libavfilter repository into
-some directory of your choice by:
-
-@example
- svn checkout svn://svn.libav.org/soc/libavfilter
-@end example
-
-And then read the README file in the top directory to learn how to
-integrate it into ffmpeg and ffplay.
-
-But note that there may still be serious bugs in the code and its API
-and ABI should not be considered stable yet!
+Audio filtering integration into the main FFmpeg repository is a work in
+progress, so audio API and ABI should not be considered stable yet.
@chapter Tutorial
@@ -74,7 +62,7 @@ not have video output.
@chapter graph2dot
-The @file{graph2dot} program included in the Libav @file{tools}
+The @file{graph2dot} program included in the FFmpeg @file{tools}
directory can be used to parse a filter graph description and issue a
corresponding textual representation in the dot language.
diff --git a/doc/metadata.texi b/doc/metadata.texi
index cfaf491c2d..2a285757cc 100644
--- a/doc/metadata.texi
+++ b/doc/metadata.texi
@@ -1,7 +1,7 @@
@chapter Metadata
@c man begin METADATA
-Libav is able to dump metadata from media files into a simple UTF-8-encoded
+FFmpeg is able to dump metadata from media files into a simple UTF-8-encoded
INI-like text file and then load it back using the metadata muxer/demuxer.
The file format is as follows:
@@ -53,7 +53,7 @@ A ffmetadata file might look like this:
;FFMETADATA1
title=bike\\shed
;this is a comment
-artist=Libav troll team
+artist=FFmpeg troll team
[CHAPTER]
TIMEBASE=1/1000
diff --git a/doc/multithreading.txt b/doc/multithreading.txt
index b72bc16079..a1068425cd 100644
--- a/doc/multithreading.txt
+++ b/doc/multithreading.txt
@@ -1,7 +1,7 @@
-Libav multithreading methods
+FFmpeg multithreading methods
==============================================
-Libav provides two methods for multithreading codecs.
+FFmpeg provides two methods for multithreading codecs.
Slice threading decodes multiple parts of a frame at the same time, using
AVCodecContext execute() and execute2().
diff --git a/doc/muxers.texi b/doc/muxers.texi
index 74c014bc70..66ea95ec18 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -1,10 +1,10 @@
@chapter Muxers
@c man begin MUXERS
-Muxers are configured elements in Libav which allow writing
+Muxers are configured elements in FFmpeg which allow writing
multimedia streams to a particular type of file.
-When you configure your Libav build, all the supported muxers
+When you configure your FFmpeg build, all the supported muxers
are enabled by default. You can list all available muxers using the
configure option @code{--list-muxers}.
@@ -51,7 +51,7 @@ and the input video converted to MPEG-2 video, use the command:
ffmpeg -i INPUT -acodec pcm_u8 -vcodec mpeg2video -f crc -
@end example
-See also the @code{framecrc} muxer (@pxref{framecrc}).
+See also the @ref{framecrc} muxer.
@anchor{framecrc}
@section framecrc
@@ -88,7 +88,7 @@ MPEG-2 video, use the command:
ffmpeg -i INPUT -acodec pcm_u8 -vcodec mpeg2video -f framecrc -
@end example
-See also the @code{crc} muxer (@pxref{crc}).
+See also the @ref{crc} muxer.
@section image2
@@ -141,6 +141,12 @@ Note also that the pattern must not necessarily contain "%d" or
ffmpeg -i in.avi -f image2 -vframes 1 img.jpeg
@end example
+The image muxer supports the .Y.U.V image file format. This format is
+special in that that each image frame consists of three files, for
+each of the YUV420P components. To read or write this image file format,
+specify the name of the '.Y' file. The muxer will automatically open the
+'.U' and '.V' files as required.
+
@section mpegts
MPEG transport stream muxer.
@@ -167,7 +173,7 @@ Set the first PID for data packets (default 0x0100, max 0x0f00).
The recognized metadata settings in mpegts muxer are @code{service_provider}
and @code{service_name}. If they are not set the default for
-@code{service_provider} is "Libav" and the default for
+@code{service_provider} is "FFmpeg" and the default for
@code{service_name} is "Service01".
@example
@@ -226,7 +232,7 @@ Specifies the language of the track in the Matroska languages form
@table @option
-@item STEREO_MODE=@var{mode}
+@item stereo_mode=@var{mode}
Stereo 3D video layout of two views in a single video track
@table @option
@item mono
@@ -264,7 +270,7 @@ Both eyes laced in one Block, Right-eye view is first
For example a 3D WebM clip can be created using the following command line:
@example
-ffmpeg -i sample_left_right_clip.mpg -an -vcodec libvpx -metadata STEREO_MODE=left_right -y stereo_clip.webm
+ffmpeg -i sample_left_right_clip.mpg -an -vcodec libvpx -metadata stereo_mode=left_right -y stereo_clip.webm
@end example
@c man end MUXERS
diff --git a/doc/optimization.txt b/doc/optimization.txt
index 78e0077e30..b027efef2f 100644
--- a/doc/optimization.txt
+++ b/doc/optimization.txt
@@ -17,15 +17,15 @@ Understanding these overoptimized functions:
As many functions tend to be a bit difficult to understand because
of optimizations, it can be hard to optimize them further, or write
architecture-specific versions. It is recommended to look at older
-revisions of the interesting files (web frontends for the various Libav
-branches are listed at http://libav.org/download.html).
+revisions of the interesting files (web frontends for the various FFmpeg
+branches are listed at http://ffmpeg.org/download.html).
Alternatively, look into the other architecture-specific versions in
the x86/, ppc/, alpha/ subdirectories. Even if you don't exactly
comprehend the instructions, it could help understanding the functions
and how they can be optimized.
NOTE: If you still don't understand some function, ask at our mailing list!!!
-(https://lists.libav.org/mailman/listinfo/libav-devel)
+(http://lists.ffmpeg.org/mailman/listinfo/ffmpeg-devel)
When is an optimization justified?
@@ -201,7 +201,7 @@ Inline asm vs. external asm
---------------------------
Both inline asm (__asm__("..") in a .c file, handled by a compiler such as gcc)
and external asm (.s or .asm files, handled by an assembler such as yasm/nasm)
-are accepted in Libav. Which one to use differs per specific case.
+are accepted in FFmpeg. Which one to use differs per specific case.
- if your code is intended to be inlined in a C function, inline asm is always
better, because external asm cannot be inlined
diff --git a/doc/outdevs.texi b/doc/outdevs.texi
index 938909c784..79619f80b9 100644
--- a/doc/outdevs.texi
+++ b/doc/outdevs.texi
@@ -1,10 +1,10 @@
@chapter Output Devices
@c man begin OUTPUT DEVICES
-Output devices are configured elements in Libav which allow to write
+Output devices are configured elements in FFmpeg which allow to write
multimedia data to an output device attached to your system.
-When you configure your Libav build, all the supported output devices
+When you configure your FFmpeg build, all the supported output devices
are enabled by default. You can list all available ones using the
configure option "--list-outdevs".
@@ -26,6 +26,46 @@ ALSA (Advanced Linux Sound Architecture) output device.
OSS (Open Sound System) output device.
+@section sdl
+
+SDL (Simple Directmedia Layer) output device.
+
+This output devices allows to show a video stream in an SDL
+window. Only one SDL window is allowed per application, so you can
+have only one instance of this output device in an application.
+
+To enable this output device you need libsdl installed on your system
+when configuring your build.
+
+For more information about SDL, check:
+@url{http://www.libsdl.org/}
+
+@subsection Options
+
+@table @option
+
+@item window_title
+Set the SDL window title, if not specified default to the filename
+specified for the output device.
+
+@item icon_title
+Set the name of the iconified SDL window, if not specified it is set
+to the same value of @var{window_title}.
+
+@item window_size
+Set the SDL window size, can be a string of the form
+@var{width}x@var{height} or a video size abbreviation.
+If not specified it defaults to the size of the input video.
+@end table
+
+@subsection Examples
+
+The following command shows the @file{ffmpeg} output is an
+SDL window, forcing its size to the qcif format:
+@example
+ffmpeg -i INPUT -vcodec rawvideo -pix_fmt yuv420p -window_size qcif -f sdl "SDL output"
+@end example
+
@section sndio
sndio audio output device.
diff --git a/doc/protocols.texi b/doc/protocols.texi
index 18749efbfb..df3248968c 100644
--- a/doc/protocols.texi
+++ b/doc/protocols.texi
@@ -1,10 +1,10 @@
@chapter Protocols
@c man begin PROTOCOLS
-Protocols are configured elements in Libav which allow to access
+Protocols are configured elements in FFmpeg which allow to access
resources which require the use of a particular protocol.
-When you configure your Libav build, all the supported protocols are
+When you configure your FFmpeg build, all the supported protocols are
enabled by default. You can list all available ones using the
configure option "--list-protocols".
@@ -242,16 +242,19 @@ data transferred over RDT).
The muxer can be used to send a stream using RTSP ANNOUNCE to a server
supporting it (currently Darwin Streaming Server and Mischa Spiegelmock's
-RTSP server, @url{http://github.com/revmischa/rtsp-server}).
+@uref{http://github.com/revmischa/rtsp-server, RTSP server}).
The required syntax for a RTSP url is:
@example
-rtsp://@var{hostname}[:@var{port}]/@var{path}[?@var{options}]
+rtsp://@var{hostname}[:@var{port}]/@var{path}
@end example
-@var{options} is a @code{&}-separated list. The following options
+The following options (set on the @file{ffmpeg}/@file{ffplay} command
+line, or set in code via @code{AVOption}s or in @code{avformat_open_input}),
are supported:
+Flags for @code{rtsp_transport}:
+
@table @option
@item udp
@@ -261,21 +264,25 @@ Use UDP as lower transport protocol.
Use TCP (interleaving within the RTSP control channel) as lower
transport protocol.
-@item multicast
+@item udp_multicast
Use UDP multicast as lower transport protocol.
@item http
Use HTTP tunneling as lower transport protocol, which is useful for
passing proxies.
-
-@item filter_src
-Accept packets only from negotiated peer address and port.
@end table
Multiple lower transport protocols may be specified, in that case they are
tried one at a time (if the setup of one fails, the next one is tried).
For the muxer, only the @code{tcp} and @code{udp} options are supported.
+Flags for @code{rtsp_flags}:
+
+@table @option
+@item filter_src
+Accept packets only from negotiated peer address and port.
+@end table
+
When receiving data over UDP, the demuxer tries to reorder received packets
(since they may arrive out of order, or packets may get lost totally). In
order for this to be enabled, a maximum delay must be specified in the
@@ -291,13 +298,13 @@ Example command lines:
To watch a stream over UDP, with a max reordering delay of 0.5 seconds:
@example
-ffplay -max_delay 500000 rtsp://server/video.mp4?udp
+ffplay -max_delay 500000 -rtsp_transport udp rtsp://server/video.mp4
@end example
To watch a stream tunneled over HTTP:
@example
-ffplay rtsp://server/video.mp4?http
+ffplay -rtsp_transport http rtsp://server/video.mp4
@end example
To send a stream in realtime to a RTSP server, for others to watch:
diff --git a/doc/soc.txt b/doc/soc.txt
index e45bd6ce3b..79d77d1cd7 100644
--- a/doc/soc.txt
+++ b/doc/soc.txt
@@ -8,9 +8,9 @@ it's a little late for this year's soc (2006).
The Goal:
Our goal in respect to soc is and must be of course exactly one thing and
-that is to improve Libav, to reach this goal, code must
+that is to improve FFmpeg, to reach this goal, code must
* conform to the development policy and patch submission guidelines
-* must improve Libav somehow (faster, smaller, "better",
+* must improve FFmpeg somehow (faster, smaller, "better",
more codecs supported, fewer bugs, cleaner, ...)
for mentors and other developers to help students to reach that goal it is
@@ -20,5 +20,5 @@ easy reviewable that again leads us to:
* separation of cosmetic from non-cosmetic changes (this is almost entirely
ignored by mentors and students in soc 2006 which might lead to a suprise
when the code will be reviewed at the end before a possible inclusion in
- Libav, individual changes were generally not reviewable due to cosmetics).
+ FFmpeg, individual changes were generally not reviewable due to cosmetics).
* frequent commits, so that comments can be provided early
diff --git a/doc/swresample.txt b/doc/swresample.txt
new file mode 100644
index 0000000000..4daa181b0e
--- /dev/null
+++ b/doc/swresample.txt
@@ -0,0 +1,46 @@
+ The official guide to swresample for confused developers.
+ =========================================================
+
+Current (simplified) Architecture:
+---------------------------------
+ Input
+ v
+ __________________/|\___________
+ / | \
+ / input sample format convert v
+ / | ___________/
+ | |/
+ | v
+ | ___________/|\___________ _____________
+ | / | \ | |
+ | Rematrix | resample <---->| Buffers |
+ | \___________ | ___________/ |_____________|
+ v \|/
+Special Converter v
+ v ___________/|\___________ _____________
+ | / | \ | |
+ | Rematrix | resample <---->| Buffers |
+ | \___________ | ___________/ |_____________|
+ | \|/
+ | v
+ | |\___________
+ \ | \
+ \ output sample format convert v
+ \_________________ | ___________/
+ \|/
+ v
+ Output
+
+Planar/Packed convertion is done when needed during sample format convertion
+Every step can be skiped without memcpy when its not needed.
+Either Resampling and Rematrixing can be performed first depending on which
+way its faster.
+The Buffers are needed for resampling due to resamplng being a process that
+requires future and past data, it thus also introduces inevitably a delay when
+used.
+Internally 32bit float and 16bit int is supported currently, other formats can
+easily be added
+Externally all sample formats in packed and planar configuration are supported
+Its also trivial to add special converters for common cases
+If only sample format and or packed/planar convertion is needed it
+is performed from input to output directly in a single pass with no intermediates.
diff --git a/doc/texi2pod.pl b/doc/texi2pod.pl
index 84c36ff1e1..0eb5e8d9fe 100755
--- a/doc/texi2pod.pl
+++ b/doc/texi2pod.pl
@@ -352,6 +352,7 @@ sub postprocess
s/\(?\@xref\{(?:[^\}]*)\}(?:[^.<]|(?:<[^<>]*>))*\.\)?//g;
s/\s+\(\@pxref\{(?:[^\}]*)\}\)//g;
s/;\s+\@pxref\{(?:[^\}]*)\}//g;
+ s/\@ref\{([^\}]*)\}/$1/g;
s/\@noindent\s*//g;
s/\@refill//g;
s/\@gol//g;
diff --git a/ffmpeg.c b/ffmpeg.c
index 1a4d2a1204..347c324a9d 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -2,20 +2,20 @@
* ffmpeg main
* Copyright (c) 2000-2003 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -45,10 +45,15 @@
#include "libavutil/avstring.h"
#include "libavutil/libm.h"
#include "libavformat/os_support.h"
+#include "libswresample/swresample.h"
+
+#include "libavformat/ffm.h" // not public API
#if CONFIG_AVFILTER
+# include "libavfilter/avcodec.h"
# include "libavfilter/avfilter.h"
# include "libavfilter/avfiltergraph.h"
+# include "libavfilter/buffersink.h"
# include "libavfilter/vsrc_buffer.h"
#endif
@@ -68,6 +73,14 @@
#include <sys/select.h>
#endif
+#if HAVE_TERMIOS_H
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <sys/time.h>
+#include <termios.h>
+#elif HAVE_KBHIT
+#include <conio.h>
+#endif
#include <time.h>
#include "cmdutils.h"
@@ -78,199 +91,136 @@ const char program_name[] = "ffmpeg";
const int program_birth_year = 2000;
/* select an input stream for an output stream */
-typedef struct AVStreamMap {
+typedef struct StreamMap {
+ int disabled; /** 1 is this mapping is disabled by a negative map */
int file_index;
int stream_index;
int sync_file_index;
int sync_stream_index;
-} AVStreamMap;
+} StreamMap;
/**
* select an input file for an output file
*/
-typedef struct AVMetaDataMap {
- int file; //< file index
- char type; //< type of metadata to copy -- (g)lobal, (s)tream, (c)hapter or (p)rogram
- int index; //< stream/chapter/program number
-} AVMetaDataMap;
-
-typedef struct AVChapterMap {
- int in_file;
- int out_file;
-} AVChapterMap;
+typedef struct MetadataMap {
+ int file; ///< file index
+ char type; ///< type of metadata to copy -- (g)lobal, (s)tream, (c)hapter or (p)rogram
+ int index; ///< stream/chapter/program number
+} MetadataMap;
static const OptionDef options[];
-#define MAX_FILES 100
#define MAX_STREAMS 1024 /* arbitrary sanity check value */
-#define FFM_PACKET_SIZE 4096 //XXX a duplicate of the line in ffm.h
-
-static const char *last_asked_format = NULL;
-static int64_t input_files_ts_offset[MAX_FILES];
-static double *input_files_ts_scale[MAX_FILES] = {NULL};
-static AVCodec **input_codecs = NULL;
-static int nb_input_codecs = 0;
-static int nb_input_files_ts_scale[MAX_FILES] = {0};
-
-static AVFormatContext *output_files[MAX_FILES];
-static AVDictionary *output_opts[MAX_FILES];
-static int nb_output_files = 0;
-
-static AVStreamMap *stream_maps = NULL;
-static int nb_stream_maps;
-
-/* first item specifies output metadata, second is input */
-static AVMetaDataMap (*meta_data_maps)[2] = NULL;
-static int nb_meta_data_maps;
-static int metadata_global_autocopy = 1;
-static int metadata_streams_autocopy = 1;
-static int metadata_chapters_autocopy = 1;
-
-static AVChapterMap *chapter_maps = NULL;
-static int nb_chapter_maps;
-
-/* indexed by output file stream index */
-static int *streamid_map = NULL;
-static int nb_streamid_map = 0;
-
-static int frame_width = 0;
-static int frame_height = 0;
-static float frame_aspect_ratio = 0;
-static enum PixelFormat frame_pix_fmt = PIX_FMT_NONE;
-static enum AVSampleFormat audio_sample_fmt = AV_SAMPLE_FMT_NONE;
-static int max_frames[4] = {INT_MAX, INT_MAX, INT_MAX, INT_MAX};
-static AVRational frame_rate;
-static float video_qscale = 0;
-static uint16_t *intra_matrix = NULL;
-static uint16_t *inter_matrix = NULL;
-static const char *video_rc_override_string=NULL;
-static int video_disable = 0;
+static int frame_bits_per_raw_sample = 0;
static int video_discard = 0;
-static char *video_codec_name = NULL;
-static unsigned int video_codec_tag = 0;
-static char *video_language = NULL;
-static int same_quality = 0;
+static int same_quant = 0;
static int do_deinterlace = 0;
-static int top_field_first = -1;
-static int me_threshold = 0;
static int intra_dc_precision = 8;
static int loop_input = 0;
static int loop_output = AVFMT_NOOUTPUTLOOP;
static int qp_hist = 0;
-#if CONFIG_AVFILTER
-static char *vfilters = NULL;
-#endif
-
static int intra_only = 0;
-static int audio_sample_rate = 0;
-static int64_t channel_layout = 0;
-#define QSCALE_NONE -99999
-static float audio_qscale = QSCALE_NONE;
-static int audio_disable = 0;
-static int audio_channels = 0;
-static char *audio_codec_name = NULL;
-static unsigned int audio_codec_tag = 0;
-static char *audio_language = NULL;
-
-static int subtitle_disable = 0;
-static char *subtitle_codec_name = NULL;
-static char *subtitle_language = NULL;
-static unsigned int subtitle_codec_tag = 0;
-
-static int data_disable = 0;
-static char *data_codec_name = NULL;
-static unsigned int data_codec_tag = 0;
-
-static float mux_preload= 0.5;
-static float mux_max_delay= 0.7;
-
-static int64_t recording_time = INT64_MAX;
-static int64_t start_time = 0;
-static int64_t recording_timestamp = 0;
-static int64_t input_ts_offset = 0;
+static const char *video_codec_name = NULL;
+static const char *audio_codec_name = NULL;
+static const char *subtitle_codec_name = NULL;
+
static int file_overwrite = 0;
-static AVDictionary *metadata;
static int do_benchmark = 0;
static int do_hex_dump = 0;
static int do_pkt_dump = 0;
-static int do_psnr = 0;
static int do_pass = 0;
-static char *pass_logfilename_prefix = NULL;
-static int audio_stream_copy = 0;
-static int video_stream_copy = 0;
-static int subtitle_stream_copy = 0;
-static int data_stream_copy = 0;
+static const char *pass_logfilename_prefix;
static int video_sync_method= -1;
static int audio_sync_method= 0;
static float audio_drift_threshold= 0.1;
static int copy_ts= 0;
-static int copy_tb;
+static int copy_tb= 0;
static int opt_shortest = 0;
static char *vstats_filename;
static FILE *vstats_file;
-static int opt_programid = 0;
static int copy_initial_nonkeyframes = 0;
-static int rate_emu = 0;
-
static int audio_volume = 256;
static int exit_on_error = 0;
static int using_stdin = 0;
-static int verbose = 1;
-static int thread_count= 1;
+static int run_as_daemon = 0;
+static volatile int received_nb_signals = 0;
static int64_t video_size = 0;
static int64_t audio_size = 0;
static int64_t extra_size = 0;
static int nb_frames_dup = 0;
static int nb_frames_drop = 0;
static int input_sync;
-static uint64_t limit_filesize = 0;
-static int force_fps = 0;
-static char *forced_key_frames = NULL;
static float dts_delta_threshold = 10;
-static int64_t timer_start;
+static int print_stats = 1;
static uint8_t *audio_buf;
static uint8_t *audio_out;
static unsigned int allocated_audio_out_size, allocated_audio_buf_size;
-static short *samples;
-
-static AVBitStreamFilterContext *video_bitstream_filters=NULL;
-static AVBitStreamFilterContext *audio_bitstream_filters=NULL;
-static AVBitStreamFilterContext *subtitle_bitstream_filters=NULL;
+static void *samples;
+static uint8_t *input_tmp= NULL;
#define DEFAULT_PASS_LOGFILENAME_PREFIX "ffmpeg2pass"
-struct AVInputStream;
+typedef struct InputStream {
+ int file_index;
+ AVStream *st;
+ int discard; /* true if stream data should be discarded */
+ int decoding_needed; /* true if the packets must be decoded in 'raw_fifo' */
+ AVCodec *dec;
+
+ int64_t start; /* time when read started */
+ int64_t next_pts; /* synthetic pts for cases where pkt.pts
+ is not defined */
+ int64_t pts; /* current pts */
+ double ts_scale;
+ int is_start; /* is 1 at the start and after a discontinuity */
+ int showed_multi_packet_warning;
+ AVDictionary *opts;
+} InputStream;
+
+typedef struct InputFile {
+ AVFormatContext *ctx;
+ int eof_reached; /* true if eof reached */
+ int ist_index; /* index of first stream in input_streams */
+ int buffer_size; /* current total buffer size */
+ int64_t ts_offset;
+ int nb_streams; /* number of stream that ffmpeg is aware of; may be different
+ from ctx.nb_streams if new streams appear during av_read_frame() */
+ int rate_emu;
+} InputFile;
-typedef struct AVOutputStream {
+typedef struct OutputStream {
int file_index; /* file index */
int index; /* stream index in the output file */
- int source_index; /* AVInputStream index */
+ int source_index; /* InputStream index */
AVStream *st; /* stream in the output file */
int encoding_needed; /* true if encoding needed for this stream */
int frame_number;
/* input pts and corresponding output pts
for A/V sync */
//double sync_ipts; /* dts from the AVPacket of the demuxer in second units */
- struct AVInputStream *sync_ist; /* input stream to sync against */
+ struct InputStream *sync_ist; /* input stream to sync against */
int64_t sync_opts; /* output frame counter, could be changed to some true timestamp */ //FIXME look at frame_number
AVBitStreamFilterContext *bitstream_filters;
AVCodec *enc;
+ int64_t max_frames;
/* video only */
int video_resample;
- AVFrame pict_tmp; /* temporary image for resampling */
+ AVFrame resample_frame; /* temporary frame for image resampling */
struct SwsContext *img_resample_ctx; /* for image resampling */
int resample_height;
int resample_width;
int resample_pix_fmt;
AVRational frame_rate;
+ int force_fps;
+ int top_field_first;
float frame_aspect_ratio;
@@ -281,15 +231,14 @@ typedef struct AVOutputStream {
/* audio only */
int audio_resample;
- ReSampleContext *resample; /* for audio resampling */
int resample_sample_fmt;
int resample_channels;
int resample_sample_rate;
- int reformat_pair;
- AVAudioConvert *reformat_ctx;
AVFifoBuffer *fifo; /* for compression: one audio fifo per codec */
FILE *logfile;
+ struct SwrContext *swr;
+
#if CONFIG_AVFILTER
AVFilterContext *output_video_filter;
AVFilterContext *input_video_filter;
@@ -298,54 +247,185 @@ typedef struct AVOutputStream {
AVFilterGraph *graph;
#endif
- int sws_flags;
-} AVOutputStream;
+ int64_t sws_flags;
+ AVDictionary *opts;
+ int is_past_recording_time;
+} OutputStream;
-static AVOutputStream **output_streams_for_file[MAX_FILES] = { NULL };
-static int nb_output_streams_for_file[MAX_FILES] = { 0 };
-typedef struct AVInputStream {
- int file_index;
- AVStream *st;
- int discard; /* true if stream data should be discarded */
- int decoding_needed; /* true if the packets must be decoded in 'raw_fifo' */
- int64_t sample_index; /* current sample */
+#if HAVE_TERMIOS_H
- int64_t start; /* time when read started */
- int64_t next_pts; /* synthetic pts for cases where pkt.pts
- is not defined */
- int64_t pts; /* current pts */
- PtsCorrectionContext pts_ctx;
- int is_start; /* is 1 at the start and after a discontinuity */
- int showed_multi_packet_warning;
- int is_past_recording_time;
-#if CONFIG_AVFILTER
- AVFrame *filter_frame;
- int has_filter_frame;
+/* init terminal so that we can grab keys */
+static struct termios oldtty;
#endif
-} AVInputStream;
-typedef struct AVInputFile {
+typedef struct OutputFile {
AVFormatContext *ctx;
- int eof_reached; /* true if eof reached */
- int ist_index; /* index of first stream in ist_table */
- int buffer_size; /* current total buffer size */
-} AVInputFile;
-
-static AVInputStream *input_streams = NULL;
+ AVDictionary *opts;
+ int ost_index; /* index of the first stream in output_streams */
+ int64_t recording_time; /* desired length of the resulting file in microseconds */
+ int64_t start_time; /* start time in microseconds */
+ uint64_t limit_filesize;
+} OutputFile;
+
+static InputStream *input_streams = NULL;
static int nb_input_streams = 0;
-static AVInputFile *input_files = NULL;
+static InputFile *input_files = NULL;
static int nb_input_files = 0;
+static OutputStream *output_streams = NULL;
+static int nb_output_streams = 0;
+static OutputFile *output_files = NULL;
+static int nb_output_files = 0;
+
+typedef struct OptionsContext {
+ /* input/output options */
+ int64_t start_time;
+ const char *format;
+
+ SpecifierOpt *codec_names;
+ int nb_codec_names;
+ SpecifierOpt *audio_channels;
+ int nb_audio_channels;
+ SpecifierOpt *audio_sample_rate;
+ int nb_audio_sample_rate;
+ SpecifierOpt *frame_rates;
+ int nb_frame_rates;
+ SpecifierOpt *frame_sizes;
+ int nb_frame_sizes;
+ SpecifierOpt *frame_pix_fmts;
+ int nb_frame_pix_fmts;
+
+ /* input options */
+ int64_t input_ts_offset;
+ int rate_emu;
+
+ SpecifierOpt *ts_scale;
+ int nb_ts_scale;
+
+ /* output options */
+ StreamMap *stream_maps;
+ int nb_stream_maps;
+ /* first item specifies output metadata, second is input */
+ MetadataMap (*meta_data_maps)[2];
+ int nb_meta_data_maps;
+ int metadata_global_manual;
+ int metadata_streams_manual;
+ int metadata_chapters_manual;
+
+ int chapters_input_file;
+
+ int64_t recording_time;
+ uint64_t limit_filesize;
+ float mux_preload;
+ float mux_max_delay;
+
+ int video_disable;
+ int audio_disable;
+ int subtitle_disable;
+ int data_disable;
+
+ /* indexed by output file stream index */
+ int *streamid_map;
+ int nb_streamid_map;
+
+ SpecifierOpt *metadata;
+ int nb_metadata;
+ SpecifierOpt *max_frames;
+ int nb_max_frames;
+ SpecifierOpt *bitstream_filters;
+ int nb_bitstream_filters;
+ SpecifierOpt *codec_tags;
+ int nb_codec_tags;
+ SpecifierOpt *sample_fmts;
+ int nb_sample_fmts;
+ SpecifierOpt *qscale;
+ int nb_qscale;
+ SpecifierOpt *forced_key_frames;
+ int nb_forced_key_frames;
+ SpecifierOpt *force_fps;
+ int nb_force_fps;
+ SpecifierOpt *frame_aspect_ratios;
+ int nb_frame_aspect_ratios;
+ SpecifierOpt *rc_overrides;
+ int nb_rc_overrides;
+ SpecifierOpt *intra_matrices;
+ int nb_intra_matrices;
+ SpecifierOpt *inter_matrices;
+ int nb_inter_matrices;
+ SpecifierOpt *top_field_first;
+ int nb_top_field_first;
+ SpecifierOpt *presets;
+ int nb_presets;
#if CONFIG_AVFILTER
+ SpecifierOpt *filters;
+ int nb_filters;
+#endif
+} OptionsContext;
+
+#define MATCH_PER_STREAM_OPT(name, type, outvar, fmtctx, st)\
+{\
+ int i, ret;\
+ for (i = 0; i < o->nb_ ## name; i++) {\
+ char *spec = o->name[i].specifier;\
+ if ((ret = check_stream_specifier(fmtctx, st, spec)) > 0)\
+ outvar = o->name[i].u.type;\
+ else if (ret < 0)\
+ exit_program(1);\
+ }\
+}
-static int configure_video_filters(AVInputStream *ist, AVOutputStream *ost)
+static void reset_options(OptionsContext *o, int is_input)
+{
+ const OptionDef *po = options;
+ OptionsContext bak= *o;
+
+ /* all OPT_SPEC and OPT_STRING can be freed in generic way */
+ while (po->name) {
+ void *dst = (uint8_t*)o + po->u.off;
+
+ if (po->flags & OPT_SPEC) {
+ SpecifierOpt **so = dst;
+ int i, *count = (int*)(so + 1);
+ for (i = 0; i < *count; i++) {
+ av_freep(&(*so)[i].specifier);
+ if (po->flags & OPT_STRING)
+ av_freep(&(*so)[i].u.str);
+ }
+ av_freep(so);
+ *count = 0;
+ } else if (po->flags & OPT_OFFSET && po->flags & OPT_STRING)
+ av_freep(dst);
+ po++;
+ }
+
+ av_freep(&o->stream_maps);
+ av_freep(&o->meta_data_maps);
+ av_freep(&o->streamid_map);
+
+ memset(o, 0, sizeof(*o));
+
+ if(is_input) o->recording_time = bak.recording_time;
+ else o->recording_time = INT64_MAX;
+ o->mux_preload = 0.5;
+ o->mux_max_delay = 0.7;
+ o->limit_filesize = UINT64_MAX;
+ o->chapters_input_file = INT_MAX;
+
+ uninit_opts();
+ init_opts();
+}
+
+#if CONFIG_AVFILTER
+
+static int configure_video_filters(InputStream *ist, OutputStream *ost)
{
AVFilterContext *last_filter, *filter;
/** filter graph containing all filters including input & output */
AVCodecContext *codec = ost->st->codec;
AVCodecContext *icodec = ist->st->codec;
- FFSinkContext ffsink_ctx = { .pix_fmt = codec->pix_fmt };
+ enum PixelFormat pix_fmts[] = { codec->pix_fmt, PIX_FMT_NONE };
+ AVBufferSinkParams *buffersink_params = av_buffersink_params_alloc();
AVRational sample_aspect_ratio;
char args[255];
int ret;
@@ -365,8 +445,15 @@ static int configure_video_filters(AVInputStream *ist, AVOutputStream *ost)
"src", args, NULL, ost->graph);
if (ret < 0)
return ret;
- ret = avfilter_graph_create_filter(&ost->output_video_filter, &ffsink,
- "out", NULL, &ffsink_ctx, ost->graph);
+#if FF_API_OLD_VSINK_API
+ ret = avfilter_graph_create_filter(&ost->output_video_filter, avfilter_get_by_name("buffersink"),
+ "out", NULL, pix_fmts, ost->graph);
+#else
+ buffersink_params->pixel_fmts = pix_fmts;
+ ret = avfilter_graph_create_filter(&ost->output_video_filter, avfilter_get_by_name("buffersink"),
+ "out", NULL, buffersink_params, ost->graph);
+#endif
+ av_freep(&buffersink_params);
if (ret < 0)
return ret;
last_filter = ost->input_video_filter;
@@ -375,7 +462,7 @@ static int configure_video_filters(AVInputStream *ist, AVOutputStream *ost)
snprintf(args, 255, "%d:%d:flags=0x%X",
codec->width,
codec->height,
- ost->sws_flags);
+ (unsigned)ost->sws_flags);
if ((ret = avfilter_graph_create_filter(&filter, avfilter_get_by_name("scale"),
NULL, args, NULL, ost->graph)) < 0)
return ret;
@@ -384,12 +471,12 @@ static int configure_video_filters(AVInputStream *ist, AVOutputStream *ost)
last_filter = filter;
}
- snprintf(args, sizeof(args), "flags=0x%X", ost->sws_flags);
+ snprintf(args, sizeof(args), "flags=0x%X", (unsigned)ost->sws_flags);
ost->graph->scale_sws_opts = av_strdup(args);
if (ost->avfilter) {
- AVFilterInOut *outputs = av_malloc(sizeof(AVFilterInOut));
- AVFilterInOut *inputs = av_malloc(sizeof(AVFilterInOut));
+ AVFilterInOut *outputs = avfilter_inout_alloc();
+ AVFilterInOut *inputs = avfilter_inout_alloc();
outputs->name = av_strdup("in");
outputs->filter_ctx = last_filter;
@@ -401,7 +488,7 @@ static int configure_video_filters(AVInputStream *ist, AVOutputStream *ost)
inputs->pad_idx = 0;
inputs->next = NULL;
- if ((ret = avfilter_graph_parse(ost->graph, ost->avfilter, inputs, outputs, NULL)) < 0)
+ if ((ret = avfilter_graph_parse(ost->graph, ost->avfilter, &inputs, &outputs, NULL)) < 0)
return ret;
av_freep(&ost->avfilter);
} else {
@@ -415,7 +502,7 @@ static int configure_video_filters(AVInputStream *ist, AVOutputStream *ost)
codec->width = ost->output_video_filter->inputs[0]->w;
codec->height = ost->output_video_filter->inputs[0]->h;
codec->sample_aspect_ratio = ost->st->sample_aspect_ratio =
- ost->frame_aspect_ratio ? // overriden by the -aspect cli option
+ ost->frame_aspect_ratio ? // overridden by the -aspect cli option
av_d2q(ost->frame_aspect_ratio*codec->height/codec->width, 255) :
ost->output_video_filter->inputs[0]->sample_aspect_ratio;
@@ -425,14 +512,16 @@ static int configure_video_filters(AVInputStream *ist, AVOutputStream *ost)
static void term_exit(void)
{
- av_log(NULL, AV_LOG_QUIET, "");
+ av_log(NULL, AV_LOG_QUIET, "%s", "");
+#if HAVE_TERMIOS_H
+ if(!run_as_daemon)
+ tcsetattr (0, TCSANOW, &oldtty);
+#endif
}
static volatile int received_sigterm = 0;
-static volatile int received_nb_signals = 0;
-static void
-sigterm_handler(int sig)
+static void sigterm_handler(int sig)
{
received_sigterm = sig;
received_nb_signals++;
@@ -441,6 +530,28 @@ sigterm_handler(int sig)
static void term_init(void)
{
+#if HAVE_TERMIOS_H
+ if(!run_as_daemon){
+ struct termios tty;
+
+ tcgetattr (0, &tty);
+ oldtty = tty;
+ atexit(term_exit);
+
+ tty.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP
+ |INLCR|IGNCR|ICRNL|IXON);
+ tty.c_oflag |= OPOST;
+ tty.c_lflag &= ~(ECHO|ECHONL|ICANON|IEXTEN);
+ tty.c_cflag &= ~(CSIZE|PARENB);
+ tty.c_cflag |= CS8;
+ tty.c_cc[VMIN] = 1;
+ tty.c_cc[VTIME] = 0;
+
+ tcsetattr (0, TCSANOW, &tty);
+ signal(SIGQUIT, sigterm_handler); /* Quit (POSIX). */
+ }
+#endif
+
signal(SIGINT , sigterm_handler); /* Interrupt (ANSI). */
signal(SIGTERM, sigterm_handler); /* Termination (ANSI). */
#ifdef SIGXCPU
@@ -448,48 +559,91 @@ static void term_init(void)
#endif
}
+/* read a key without blocking */
+static int read_key(void)
+{
+ unsigned char ch;
+#if HAVE_TERMIOS_H
+ int n = 1;
+ struct timeval tv;
+ fd_set rfds;
+
+ FD_ZERO(&rfds);
+ FD_SET(0, &rfds);
+ tv.tv_sec = 0;
+ tv.tv_usec = 0;
+ n = select(1, &rfds, NULL, NULL, &tv);
+ if (n > 0) {
+ n = read(0, &ch, 1);
+ if (n == 1)
+ return ch;
+
+ return n;
+ }
+#elif HAVE_KBHIT
+# if HAVE_PEEKNAMEDPIPE
+ static int is_pipe;
+ static HANDLE input_handle;
+ DWORD dw, nchars;
+ if(!input_handle){
+ input_handle = GetStdHandle(STD_INPUT_HANDLE);
+ is_pipe = !GetConsoleMode(input_handle, &dw);
+ }
+
+ if (stdin->_cnt > 0) {
+ read(0, &ch, 1);
+ return ch;
+ }
+ if (is_pipe) {
+ /* When running under a GUI, you will end here. */
+ if (!PeekNamedPipe(input_handle, NULL, 0, NULL, &nchars, NULL))
+ return -1;
+ //Read it
+ if(nchars != 0) {
+ read(0, &ch, 1);
+ return ch;
+ }else{
+ return -1;
+ }
+ }
+# endif
+ if(kbhit())
+ return(getch());
+#endif
+ return -1;
+}
+
static int decode_interrupt_cb(void)
{
return received_nb_signals > 1;
}
-static int ffmpeg_exit(int ret)
+void exit_program(int ret)
{
int i;
/* close files */
for(i=0;i<nb_output_files;i++) {
- AVFormatContext *s = output_files[i];
+ AVFormatContext *s = output_files[i].ctx;
if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb)
avio_close(s->pb);
avformat_free_context(s);
- av_free(output_streams_for_file[i]);
- av_dict_free(&output_opts[i]);
+ av_dict_free(&output_files[i].opts);
}
for(i=0;i<nb_input_files;i++) {
av_close_input_file(input_files[i].ctx);
- av_free(input_files_ts_scale[i]);
}
-
- av_free(intra_matrix);
- av_free(inter_matrix);
+ for (i = 0; i < nb_input_streams; i++)
+ av_dict_free(&input_streams[i].opts);
if (vstats_file)
fclose(vstats_file);
av_free(vstats_filename);
- av_free(streamid_map);
- av_free(input_codecs);
- av_free(stream_maps);
- av_free(meta_data_maps);
-
av_freep(&input_streams);
av_freep(&input_files);
-
- av_free(video_codec_name);
- av_free(audio_codec_name);
- av_free(subtitle_codec_name);
- av_free(data_codec_name);
+ av_freep(&output_streams);
+ av_freep(&output_files);
uninit_opts();
av_free(audio_buf);
@@ -501,44 +655,41 @@ static int ffmpeg_exit(int ret)
avfilter_uninit();
#endif
+ av_freep(&input_tmp);
+
if (received_sigterm) {
- fprintf(stderr,
- "Received signal %d: terminating.\n",
- (int) received_sigterm);
+ av_log(NULL, AV_LOG_INFO, "Received signal %d: terminating.\n",
+ (int) received_sigterm);
exit (255);
}
exit(ret); /* not all OS-es handle main() return value */
- return ret;
}
static void assert_avoptions(AVDictionary *m)
{
AVDictionaryEntry *t;
if ((t = av_dict_get(m, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
- av_log(NULL, AV_LOG_ERROR, "Option %s not found.\n", t->key);
- ffmpeg_exit(1);
+ av_log(NULL, AV_LOG_FATAL, "Option %s not found.\n", t->key);
+ exit_program(1);
}
}
-/* similar to ff_dynarray_add() and av_fast_realloc() */
-static void *grow_array(void *array, int elem_size, int *size, int new_size)
+static void assert_codec_experimental(AVCodecContext *c, int encoder)
{
- if (new_size >= INT_MAX / elem_size) {
- fprintf(stderr, "Array too big.\n");
- ffmpeg_exit(1);
- }
- if (*size < new_size) {
- uint8_t *tmp = av_realloc(array, new_size*elem_size);
- if (!tmp) {
- fprintf(stderr, "Could not alloc buffer.\n");
- ffmpeg_exit(1);
- }
- memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size);
- *size = new_size;
- return tmp;
+ const char *codec_string = encoder ? "encoder" : "decoder";
+ AVCodec *codec;
+ if (c->codec->capabilities & CODEC_CAP_EXPERIMENTAL &&
+ c->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) {
+ av_log(NULL, AV_LOG_FATAL, "%s '%s' is experimental and might produce bad "
+ "results.\nAdd '-strict experimental' if you want to use it.\n",
+ codec_string, c->codec->name);
+ codec = encoder ? avcodec_find_encoder(c->codec->id) : avcodec_find_decoder(c->codec->id);
+ if (!(codec->capabilities & CODEC_CAP_EXPERIMENTAL))
+ av_log(NULL, AV_LOG_FATAL, "Or use the non experimental %s '%s'.\n",
+ codec_string, codec->name);
+ exit_program(1);
}
- return array;
}
static void choose_sample_fmt(AVStream *st, AVCodec *codec)
@@ -550,6 +701,9 @@ static void choose_sample_fmt(AVStream *st, AVCodec *codec)
break;
}
if (*p == -1) {
+ if((codec->capabilities & CODEC_CAP_LOSSLESS) && av_get_sample_fmt_name(st->codec->sample_fmt) > av_get_sample_fmt_name(codec->sample_fmts[0]))
+ av_log(NULL, AV_LOG_ERROR, "Convertion will not be lossless'\n");
+ if(av_get_sample_fmt_name(st->codec->sample_fmt))
av_log(NULL, AV_LOG_WARNING,
"Incompatible sample format '%s' for codec '%s', auto-selecting format '%s'\n",
av_get_sample_fmt_name(st->codec->sample_fmt),
@@ -560,46 +714,6 @@ static void choose_sample_fmt(AVStream *st, AVCodec *codec)
}
}
-/**
- * Update the requested input sample format based on the output sample format.
- * This is currently only used to request float output from decoders which
- * support multiple sample formats, one of which is AV_SAMPLE_FMT_FLT.
- * Ideally this will be removed in the future when decoders do not do format
- * conversion and only output in their native format.
- */
-static void update_sample_fmt(AVCodecContext *dec, AVCodec *dec_codec,
- AVCodecContext *enc)
-{
- /* if sample formats match or a decoder sample format has already been
- requested, just return */
- if (enc->sample_fmt == dec->sample_fmt ||
- dec->request_sample_fmt > AV_SAMPLE_FMT_NONE)
- return;
-
- /* if decoder supports more than one output format */
- if (dec_codec && dec_codec->sample_fmts &&
- dec_codec->sample_fmts[0] != AV_SAMPLE_FMT_NONE &&
- dec_codec->sample_fmts[1] != AV_SAMPLE_FMT_NONE) {
- const enum AVSampleFormat *p;
- int min_dec = -1, min_inc = -1;
-
- /* find a matching sample format in the encoder */
- for (p = dec_codec->sample_fmts; *p != AV_SAMPLE_FMT_NONE; p++) {
- if (*p == enc->sample_fmt) {
- dec->request_sample_fmt = *p;
- return;
- } else if (*p > enc->sample_fmt) {
- min_inc = FFMIN(min_inc, *p - enc->sample_fmt);
- } else
- min_dec = FFMIN(min_dec, enc->sample_fmt - *p);
- }
-
- /* if none match, provide the one that matches quality closest */
- dec->request_sample_fmt = min_inc > 0 ? enc->sample_fmt + min_inc :
- enc->sample_fmt - min_dec;
- }
-}
-
static void choose_sample_rate(AVStream *st, AVCodec *codec)
{
if(codec && codec->supported_samplerates){
@@ -647,93 +761,15 @@ static void choose_pixel_fmt(AVStream *st, AVCodec *codec)
}
}
-static AVOutputStream *new_output_stream(AVFormatContext *oc, int file_idx)
+static double get_sync_ipts(const OutputStream *ost)
{
- int idx = oc->nb_streams - 1;
- AVOutputStream *ost;
-
- output_streams_for_file[file_idx] =
- grow_array(output_streams_for_file[file_idx],
- sizeof(*output_streams_for_file[file_idx]),
- &nb_output_streams_for_file[file_idx],
- oc->nb_streams);
- ost = output_streams_for_file[file_idx][idx] =
- av_mallocz(sizeof(AVOutputStream));
- if (!ost) {
- fprintf(stderr, "Could not alloc output stream\n");
- ffmpeg_exit(1);
- }
- ost->file_index = file_idx;
- ost->index = idx;
-
- ost->sws_flags = av_get_int(sws_opts, "sws_flags", NULL);
- return ost;
+ const InputStream *ist = ost->sync_ist;
+ OutputFile *of = &output_files[ost->file_index];
+ return (double)(ist->pts - of->start_time)/AV_TIME_BASE;
}
-static int read_ffserver_streams(AVFormatContext *s, const char *filename)
+static void write_frame(AVFormatContext *s, AVPacket *pkt, AVCodecContext *avctx, AVBitStreamFilterContext *bsfc)
{
- int i, err;
- AVFormatContext *ic = NULL;
- int nopts = 0;
-
- err = avformat_open_input(&ic, filename, NULL, NULL);
- if (err < 0)
- return err;
- /* copy stream format */
- s->nb_streams = 0;
- s->streams = av_mallocz(sizeof(AVStream *) * ic->nb_streams);
- for(i=0;i<ic->nb_streams;i++) {
- AVStream *st;
- AVCodec *codec;
-
- s->nb_streams++;
-
- // FIXME: a more elegant solution is needed
- st = av_mallocz(sizeof(AVStream));
- memcpy(st, ic->streams[i], sizeof(AVStream));
- st->info = NULL;
- st->codec = avcodec_alloc_context();
- if (!st->codec) {
- print_error(filename, AVERROR(ENOMEM));
- ffmpeg_exit(1);
- }
- avcodec_copy_context(st->codec, ic->streams[i]->codec);
- s->streams[i] = st;
-
- codec = avcodec_find_encoder(st->codec->codec_id);
- if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
- if (audio_stream_copy) {
- st->stream_copy = 1;
- } else
- choose_sample_fmt(st, codec);
- } else if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
- if (video_stream_copy) {
- st->stream_copy = 1;
- } else
- choose_pixel_fmt(st, codec);
- }
-
- if(st->codec->flags & CODEC_FLAG_BITEXACT)
- nopts = 1;
-
- new_output_stream(s, nb_output_files);
- }
-
- if (!nopts)
- s->timestamp = av_gettime();
-
- av_close_input_file(ic);
- return 0;
-}
-
-static double
-get_sync_ipts(const AVOutputStream *ost)
-{
- const AVInputStream *ist = ost->sync_ist;
- return (double)(ist->pts - start_time)/AV_TIME_BASE;
-}
-
-static void write_frame(AVFormatContext *s, AVPacket *pkt, AVCodecContext *avctx, AVBitStreamFilterContext *bsfc){
int ret;
while(bsfc){
@@ -746,12 +782,12 @@ static void write_frame(AVFormatContext *s, AVPacket *pkt, AVCodecContext *avctx
av_free_packet(pkt);
new_pkt.destruct= av_destruct_packet;
} else if(a<0){
- fprintf(stderr, "%s failed for stream %d, codec %s",
- bsfc->filter->name, pkt->stream_index,
- avctx->codec ? avctx->codec->name : "copy");
+ av_log(NULL, AV_LOG_ERROR, "%s failed for stream %d, codec %s",
+ bsfc->filter->name, pkt->stream_index,
+ avctx->codec ? avctx->codec->name : "copy");
print_error("", a);
if (exit_on_error)
- ffmpeg_exit(1);
+ exit_program(1);
}
*pkt= new_pkt;
@@ -761,15 +797,13 @@ static void write_frame(AVFormatContext *s, AVPacket *pkt, AVCodecContext *avctx
ret= av_interleaved_write_frame(s, pkt);
if(ret < 0){
print_error("av_interleaved_write_frame()", ret);
- ffmpeg_exit(1);
+ exit_program(1);
}
}
-#define MAX_AUDIO_PACKET_SIZE (128 * 1024)
-
static void do_audio_out(AVFormatContext *s,
- AVOutputStream *ost,
- AVInputStream *ist,
+ OutputStream *ost,
+ InputStream *ist,
unsigned char *buf, int size)
{
uint8_t *buftmp;
@@ -796,25 +830,26 @@ need_realloc:
audio_out_size += FF_MIN_BUFFER_SIZE;
if(audio_out_size > INT_MAX || audio_buf_size > INT_MAX){
- fprintf(stderr, "Buffer sizes too large\n");
- ffmpeg_exit(1);
+ av_log(NULL, AV_LOG_FATAL, "Buffer sizes too large\n");
+ exit_program(1);
}
av_fast_malloc(&audio_buf, &allocated_audio_buf_size, audio_buf_size);
av_fast_malloc(&audio_out, &allocated_audio_out_size, audio_out_size);
if (!audio_buf || !audio_out){
- fprintf(stderr, "Out of memory in do_audio_out\n");
- ffmpeg_exit(1);
+ av_log(NULL, AV_LOG_FATAL, "Out of memory in do_audio_out\n");
+ exit_program(1);
}
- if (enc->channels != dec->channels || enc->sample_rate != dec->sample_rate)
+ if (enc->channels != dec->channels
+ || enc->sample_fmt != dec->sample_fmt)
ost->audio_resample = 1;
resample_changed = ost->resample_sample_fmt != dec->sample_fmt ||
ost->resample_channels != dec->channels ||
ost->resample_sample_rate != dec->sample_rate;
- if ((ost->audio_resample && !ost->resample) || resample_changed) {
+ if ((ost->audio_resample && !ost->swr) || resample_changed) {
if (resample_changed) {
av_log(NULL, AV_LOG_INFO, "Input stream #%d.%d frame changed from rate:%d fmt:%s ch:%d to rate:%d fmt:%s ch:%d\n",
ist->file_index, ist->st->index,
@@ -823,47 +858,38 @@ need_realloc:
ost->resample_sample_fmt = dec->sample_fmt;
ost->resample_channels = dec->channels;
ost->resample_sample_rate = dec->sample_rate;
- if (ost->resample)
- audio_resample_close(ost->resample);
+ swr_free(&ost->swr);
}
/* if audio_sync_method is >1 the resampler is needed for audio drift compensation */
if (audio_sync_method <= 1 &&
ost->resample_sample_fmt == enc->sample_fmt &&
ost->resample_channels == enc->channels &&
ost->resample_sample_rate == enc->sample_rate) {
- ost->resample = NULL;
+ //ost->swr = NULL;
ost->audio_resample = 0;
- } else if (ost->audio_resample) {
- if (dec->sample_fmt != AV_SAMPLE_FMT_S16)
- fprintf(stderr, "Warning, using s16 intermediate sample format for resampling\n");
- ost->resample = av_audio_resample_init(enc->channels, dec->channels,
- enc->sample_rate, dec->sample_rate,
- enc->sample_fmt, dec->sample_fmt,
- 16, 10, 0, 0.8);
- if (!ost->resample) {
- fprintf(stderr, "Can not resample %d channels @ %d Hz to %d channels @ %d Hz\n",
+ } else {
+ ost->swr = swr_alloc2(ost->swr,
+ enc->channel_layout, enc->sample_fmt, enc->sample_rate,
+ dec->channel_layout, dec->sample_fmt, dec->sample_rate,
+ 0, NULL);
+ av_set_int(ost->swr, "ich", dec->channels);
+ av_set_int(ost->swr, "och", enc->channels);
+ if(audio_sync_method>1) av_set_int(ost->swr, "flags", SWR_FLAG_RESAMPLE);
+ if(ost->swr && swr_init(ost->swr) < 0){
+ av_log(NULL, AV_LOG_FATAL, "swr_init() failed\n");
+ swr_free(&ost->swr);
+ }
+
+ if (!ost->swr) {
+ av_log(NULL, AV_LOG_FATAL, "Can not resample %d channels @ %d Hz to %d channels @ %d Hz\n",
dec->channels, dec->sample_rate,
enc->channels, enc->sample_rate);
- ffmpeg_exit(1);
+ exit_program(1);
}
}
}
-#define MAKE_SFMT_PAIR(a,b) ((a)+AV_SAMPLE_FMT_NB*(b))
- if (!ost->audio_resample && dec->sample_fmt!=enc->sample_fmt &&
- MAKE_SFMT_PAIR(enc->sample_fmt,dec->sample_fmt)!=ost->reformat_pair) {
- if (ost->reformat_ctx)
- av_audio_convert_free(ost->reformat_ctx);
- ost->reformat_ctx = av_audio_convert_alloc(enc->sample_fmt, 1,
- dec->sample_fmt, 1, NULL, 0);
- if (!ost->reformat_ctx) {
- fprintf(stderr, "Cannot convert %s sample format to %s sample format\n",
- av_get_sample_fmt_name(dec->sample_fmt),
- av_get_sample_fmt_name(enc->sample_fmt));
- ffmpeg_exit(1);
- }
- ost->reformat_pair=MAKE_SFMT_PAIR(enc->sample_fmt,dec->sample_fmt);
- }
+ av_assert0(ost->audio_resample || dec->sample_fmt==enc->sample_fmt);
if(audio_sync_method){
double delta = get_sync_ipts(ost) * enc->sample_rate - ost->sync_opts
@@ -878,13 +904,11 @@ need_realloc:
byte_delta= FFMAX(byte_delta, -size);
size += byte_delta;
buf -= byte_delta;
- if(verbose > 2)
- fprintf(stderr, "discarding %d audio samples\n", (int)-delta);
+ av_log(NULL, AV_LOG_VERBOSE, "discarding %d audio samples\n", (int)-delta);
if(!size)
return;
ist->is_start=0;
}else{
- static uint8_t *input_tmp= NULL;
input_tmp= av_realloc(input_tmp, byte_delta + size);
if(byte_delta > allocated_for_size - size){
@@ -897,16 +921,15 @@ need_realloc:
memcpy(input_tmp + byte_delta, buf, size);
buf= input_tmp;
size += byte_delta;
- if(verbose > 2)
- fprintf(stderr, "adding %d audio samples of silence\n", (int)delta);
+ av_log(NULL, AV_LOG_VERBOSE, "adding %d audio samples of silence\n", (int)delta);
}
}else if(audio_sync_method>1){
int comp= av_clip(delta, -audio_sync_method, audio_sync_method);
av_assert0(ost->audio_resample);
- if(verbose > 2)
- fprintf(stderr, "compensating audio timestamp drift:%f compensation:%d in:%d\n", delta, comp, enc->sample_rate);
+ av_log(NULL, AV_LOG_VERBOSE, "compensating audio timestamp drift:%f compensation:%d in:%d\n",
+ delta, comp, enc->sample_rate);
// fprintf(stderr, "drift:%f len:%d opts:%"PRId64" ipts:%"PRId64" fifo:%d\n", delta, -1, ost->sync_opts, (int64_t)(get_sync_ipts(ost) * enc->sample_rate), av_fifo_size(ost->fifo)/(ost->st->codec->channels * 2));
- av_resample_compensate(*(struct AVResampleContext**)ost->resample, comp, enc->sample_rate);
+ swr_compensate(ost->swr, comp, enc->sample_rate);
}
}
}else
@@ -915,37 +938,22 @@ need_realloc:
if (ost->audio_resample) {
buftmp = audio_buf;
- size_out = audio_resample(ost->resample,
- (short *)buftmp, (short *)buf,
- size / (dec->channels * isize));
+ size_out = swr_convert(ost->swr, ( uint8_t*[]){buftmp}, audio_buf_size / (enc->channels * osize),
+ (const uint8_t*[]){buf }, size / (dec->channels * isize));
size_out = size_out * enc->channels * osize;
} else {
buftmp = buf;
size_out = size;
}
- if (!ost->audio_resample && dec->sample_fmt!=enc->sample_fmt) {
- const void *ibuf[6]= {buftmp};
- void *obuf[6]= {audio_buf};
- int istride[6]= {isize};
- int ostride[6]= {osize};
- int len= size_out/istride[0];
- if (av_audio_convert(ost->reformat_ctx, obuf, ostride, ibuf, istride, len)<0) {
- printf("av_audio_convert() failed\n");
- if (exit_on_error)
- ffmpeg_exit(1);
- return;
- }
- buftmp = audio_buf;
- size_out = len*osize;
- }
+ av_assert0(ost->audio_resample || dec->sample_fmt==enc->sample_fmt);
/* now encode as many frames as possible */
if (enc->frame_size > 1) {
/* output resampled raw samples */
if (av_fifo_realloc2(ost->fifo, av_fifo_size(ost->fifo) + size_out) < 0) {
- fprintf(stderr, "av_fifo_realloc2() failed\n");
- ffmpeg_exit(1);
+ av_log(NULL, AV_LOG_FATAL, "av_fifo_realloc2() failed\n");
+ exit_program(1);
}
av_fifo_generic_write(ost->fifo, buftmp, size_out, NULL);
@@ -962,8 +970,8 @@ need_realloc:
ret = avcodec_encode_audio(enc, audio_out, audio_out_size,
(short *)audio_buf);
if (ret < 0) {
- fprintf(stderr, "Audio encoding failed\n");
- ffmpeg_exit(1);
+ av_log(NULL, AV_LOG_FATAL, "Audio encoding failed\n");
+ exit_program(1);
}
audio_size += ret;
pkt.stream_index= ost->index;
@@ -989,16 +997,16 @@ need_realloc:
size_out = size_out*coded_bps/8;
if(size_out > audio_out_size){
- fprintf(stderr, "Internal error, buffer size too small\n");
- ffmpeg_exit(1);
+ av_log(NULL, AV_LOG_FATAL, "Internal error, buffer size too small\n");
+ exit_program(1);
}
//FIXME pass ost->sync_opts as AVFrame.pts in avcodec_encode_audio()
ret = avcodec_encode_audio(enc, audio_out, size_out,
(short *)buftmp);
if (ret < 0) {
- fprintf(stderr, "Audio encoding failed\n");
- ffmpeg_exit(1);
+ av_log(NULL, AV_LOG_FATAL, "Audio encoding failed\n");
+ exit_program(1);
}
audio_size += ret;
pkt.stream_index= ost->index;
@@ -1011,7 +1019,7 @@ need_realloc:
}
}
-static void pre_process_video_frame(AVInputStream *ist, AVPicture *picture, void **bufp)
+static void pre_process_video_frame(InputStream *ist, AVPicture *picture, void **bufp)
{
AVCodecContext *dec;
AVPicture *picture2;
@@ -1036,7 +1044,7 @@ static void pre_process_video_frame(AVInputStream *ist, AVPicture *picture, void
if(avpicture_deinterlace(picture2, picture,
dec->pix_fmt, dec->width, dec->height) < 0) {
/* if error, do not deinterlace */
- fprintf(stderr, "Deinterlacing failed\n");
+ av_log(NULL, AV_LOG_WARNING, "Deinterlacing failed\n");
av_free(buf);
buf = NULL;
picture2 = picture;
@@ -1050,12 +1058,9 @@ static void pre_process_video_frame(AVInputStream *ist, AVPicture *picture, void
*bufp = buf;
}
-/* we begin to correct av delay at this threshold */
-#define AV_DELAY_MAX 0.100
-
static void do_subtitle_out(AVFormatContext *s,
- AVOutputStream *ost,
- AVInputStream *ist,
+ OutputStream *ost,
+ InputStream *ist,
AVSubtitle *sub,
int64_t pts)
{
@@ -1066,9 +1071,9 @@ static void do_subtitle_out(AVFormatContext *s,
AVPacket pkt;
if (pts == AV_NOPTS_VALUE) {
- fprintf(stderr, "Subtitle packets must have a pts\n");
+ av_log(NULL, AV_LOG_ERROR, "Subtitle packets must have a pts\n");
if (exit_on_error)
- ffmpeg_exit(1);
+ exit_program(1);
return;
}
@@ -1095,8 +1100,8 @@ static void do_subtitle_out(AVFormatContext *s,
subtitle_out_size = avcodec_encode_subtitle(enc, subtitle_out,
subtitle_out_max_size, sub);
if (subtitle_out_size < 0) {
- fprintf(stderr, "Subtitle encoding failed\n");
- ffmpeg_exit(1);
+ av_log(NULL, AV_LOG_FATAL, "Subtitle encoding failed\n");
+ exit_program(1);
}
av_init_packet(&pkt);
@@ -1119,19 +1124,86 @@ static void do_subtitle_out(AVFormatContext *s,
static int bit_buffer_size= 1024*256;
static uint8_t *bit_buffer= NULL;
+static void do_video_resample(OutputStream *ost,
+ InputStream *ist,
+ AVFrame *in_picture,
+ AVFrame **out_picture)
+{
+#if CONFIG_AVFILTER
+ *out_picture = in_picture;
+#else
+ AVCodecContext *dec = ist->st->codec;
+ AVCodecContext *enc = ost->st->codec;
+ int resample_changed = ost->resample_width != dec->width ||
+ ost->resample_height != dec->height ||
+ ost->resample_pix_fmt != dec->pix_fmt;
+
+ *out_picture = in_picture;
+ if (resample_changed) {
+ av_log(NULL, AV_LOG_INFO,
+ "Input stream #%d.%d frame changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s\n",
+ ist->file_index, ist->st->index,
+ ost->resample_width, ost->resample_height, av_get_pix_fmt_name(ost->resample_pix_fmt),
+ dec->width , dec->height , av_get_pix_fmt_name(dec->pix_fmt));
+ ost->resample_width = dec->width;
+ ost->resample_height = dec->height;
+ ost->resample_pix_fmt = dec->pix_fmt;
+ }
+
+ ost->video_resample = dec->width != enc->width ||
+ dec->height != enc->height ||
+ dec->pix_fmt != enc->pix_fmt;
+
+ if (ost->video_resample) {
+ *out_picture = &ost->resample_frame;
+ if (!ost->img_resample_ctx || resample_changed) {
+ /* initialize the destination picture */
+ if (!ost->resample_frame.data[0]) {
+ avcodec_get_frame_defaults(&ost->resample_frame);
+ if (avpicture_alloc((AVPicture *)&ost->resample_frame, enc->pix_fmt,
+ enc->width, enc->height)) {
+ av_log(NULL, AV_LOG_FATAL, "Cannot allocate temp picture, check pix fmt\n");
+ exit_program(1);
+ }
+ }
+ /* initialize a new scaler context */
+ sws_freeContext(ost->img_resample_ctx);
+ ost->img_resample_ctx = sws_getContext(dec->width, dec->height, dec->pix_fmt,
+ enc->width, enc->height, enc->pix_fmt,
+ ost->sws_flags, NULL, NULL, NULL);
+ if (ost->img_resample_ctx == NULL) {
+ av_log(NULL, AV_LOG_FATAL, "Cannot get resampling context\n");
+ exit_program(1);
+ }
+ }
+ sws_scale(ost->img_resample_ctx, in_picture->data, in_picture->linesize,
+ 0, ost->resample_height, (*out_picture)->data, (*out_picture)->linesize);
+ }
+#endif
+}
+
+
static void do_video_out(AVFormatContext *s,
- AVOutputStream *ost,
- AVInputStream *ist,
+ OutputStream *ost,
+ InputStream *ist,
AVFrame *in_picture,
- int *frame_size)
+ int *frame_size, float quality)
{
- int nb_frames, i, ret, resample_changed;
- AVFrame *final_picture, *formatted_picture;
- AVCodecContext *enc, *dec;
+ int nb_frames, i, ret, format_video_sync;
+ AVFrame *final_picture;
+ AVCodecContext *enc;
double sync_ipts;
+ double duration = 0;
enc = ost->st->codec;
- dec = ist->st->codec;
+
+ if (ist->st->start_time != AV_NOPTS_VALUE && ist->st->first_dts != AV_NOPTS_VALUE) {
+ duration = FFMAX(av_q2d(ist->st->time_base), av_q2d(ist->st->codec->time_base));
+ if(ist->st->avg_frame_rate.num)
+ duration= FFMAX(duration, 1/av_q2d(ist->st->avg_frame_rate));
+
+ duration /= av_q2d(enc->time_base);
+ }
sync_ipts = get_sync_ipts(ost) / av_q2d(enc->time_base);
@@ -1140,12 +1212,16 @@ static void do_video_out(AVFormatContext *s,
*frame_size = 0;
- if(video_sync_method){
- double vdelta = sync_ipts - ost->sync_opts;
+ format_video_sync = video_sync_method;
+ if (format_video_sync < 0)
+ format_video_sync = (s->oformat->flags & AVFMT_VARIABLE_FPS) ? 2 : 1;
+
+ if (format_video_sync) {
+ double vdelta = sync_ipts - ost->sync_opts + duration;
//FIXME set to 0.5 after we fix some dts/pts bugs like in avidec.c
if (vdelta < -1.1)
nb_frames = 0;
- else if (video_sync_method == 2 || (video_sync_method<0 && (s->oformat->flags & AVFMT_VARIABLE_FPS))){
+ else if (format_video_sync == 2) {
if(vdelta<=-0.6){
nb_frames=0;
}else if(vdelta>0.6)
@@ -1155,60 +1231,19 @@ static void do_video_out(AVFormatContext *s,
//fprintf(stderr, "vdelta:%f, ost->sync_opts:%"PRId64", ost->sync_ipts:%f nb_frames:%d\n", vdelta, ost->sync_opts, get_sync_ipts(ost), nb_frames);
if (nb_frames == 0){
++nb_frames_drop;
- if (verbose>2)
- fprintf(stderr, "*** drop!\n");
+ av_log(NULL, AV_LOG_VERBOSE, "*** drop!\n");
}else if (nb_frames > 1) {
nb_frames_dup += nb_frames - 1;
- if (verbose>2)
- fprintf(stderr, "*** %d dup!\n", nb_frames-1);
+ av_log(NULL, AV_LOG_VERBOSE, "*** %d dup!\n", nb_frames-1);
}
}else
ost->sync_opts= lrintf(sync_ipts);
- nb_frames= FFMIN(nb_frames, max_frames[AVMEDIA_TYPE_VIDEO] - ost->frame_number);
+ nb_frames = FFMIN(nb_frames, ost->max_frames - ost->frame_number);
if (nb_frames <= 0)
return;
- formatted_picture = in_picture;
- final_picture = formatted_picture;
-
- resample_changed = ost->resample_width != dec->width ||
- ost->resample_height != dec->height ||
- ost->resample_pix_fmt != dec->pix_fmt;
-
- if (resample_changed) {
- av_log(NULL, AV_LOG_INFO,
- "Input stream #%d.%d frame changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s\n",
- ist->file_index, ist->st->index,
- ost->resample_width, ost->resample_height, av_get_pix_fmt_name(ost->resample_pix_fmt),
- dec->width , dec->height , av_get_pix_fmt_name(dec->pix_fmt));
- if(!ost->video_resample)
- ffmpeg_exit(1);
- }
-
-#if !CONFIG_AVFILTER
- if (ost->video_resample) {
- final_picture = &ost->pict_tmp;
- if (resample_changed) {
- /* initialize a new scaler context */
- sws_freeContext(ost->img_resample_ctx);
- ost->img_resample_ctx = sws_getContext(
- ist->st->codec->width,
- ist->st->codec->height,
- ist->st->codec->pix_fmt,
- ost->st->codec->width,
- ost->st->codec->height,
- ost->st->codec->pix_fmt,
- ost->sws_flags, NULL, NULL, NULL);
- if (ost->img_resample_ctx == NULL) {
- fprintf(stderr, "Cannot get resampling context\n");
- ffmpeg_exit(1);
- }
- }
- sws_scale(ost->img_resample_ctx, formatted_picture->data, formatted_picture->linesize,
- 0, ost->resample_height, final_picture->data, final_picture->linesize);
- }
-#endif
+ do_video_resample(ost, ist, in_picture, &final_picture);
/* duplicates frame if needed */
for(i=0;i<nb_frames;i++) {
@@ -1218,17 +1253,16 @@ static void do_video_out(AVFormatContext *s,
if (s->oformat->flags & AVFMT_RAWPICTURE) {
/* raw pictures are written as AVPicture structure to
- avoid any copies. We support temorarily the older
+ avoid any copies. We support temporarily the older
method. */
- AVFrame* old_frame = enc->coded_frame;
- enc->coded_frame = dec->coded_frame; //FIXME/XXX remove this hack
+ enc->coded_frame->interlaced_frame = in_picture->interlaced_frame;
+ enc->coded_frame->top_field_first = in_picture->top_field_first;
pkt.data= (uint8_t *)final_picture;
pkt.size= sizeof(AVPicture);
pkt.pts= av_rescale_q(ost->sync_opts, enc->time_base, ost->st->time_base);
pkt.flags |= AV_PKT_FLAG_KEY;
write_frame(s, &pkt, ost->st->codec, ost->bitstream_filters);
- enc->coded_frame = old_frame;
} else {
AVFrame big_picture;
@@ -1237,16 +1271,16 @@ static void do_video_out(AVFormatContext *s,
settings */
big_picture.interlaced_frame = in_picture->interlaced_frame;
if (ost->st->codec->flags & (CODEC_FLAG_INTERLACED_DCT|CODEC_FLAG_INTERLACED_ME)) {
- if(top_field_first == -1)
+ if (ost->top_field_first == -1)
big_picture.top_field_first = in_picture->top_field_first;
else
- big_picture.top_field_first = top_field_first;
+ big_picture.top_field_first = !!ost->top_field_first;
}
- /* handles sameq here. This is not correct because it may
+ /* handles same_quant here. This is not correct because it may
not be a global option */
- big_picture.quality = same_quality ? ist->st->quality : ost->st->quality;
- if(!me_threshold)
+ big_picture.quality = quality;
+ if (!enc->me_threshold)
big_picture.pict_type = 0;
// big_picture.pts = AV_NOPTS_VALUE;
big_picture.pts= ost->sync_opts;
@@ -1261,8 +1295,8 @@ static void do_video_out(AVFormatContext *s,
bit_buffer, bit_buffer_size,
&big_picture);
if (ret < 0) {
- fprintf(stderr, "Video encoding failed\n");
- ffmpeg_exit(1);
+ av_log(NULL, AV_LOG_FATAL, "Video encoding failed\n");
+ exit_program(1);
}
if(ret>0){
@@ -1292,11 +1326,12 @@ static void do_video_out(AVFormatContext *s,
}
}
-static double psnr(double d){
+static double psnr(double d)
+{
return -10.0*log(d)/log(10.0);
}
-static void do_video_stats(AVFormatContext *os, AVOutputStream *ost,
+static void do_video_stats(AVFormatContext *os, OutputStream *ost,
int frame_size)
{
AVCodecContext *enc;
@@ -1308,7 +1343,7 @@ static void do_video_stats(AVFormatContext *os, AVOutputStream *ost,
vstats_file = fopen(vstats_filename, "w");
if (!vstats_file) {
perror("fopen");
- ffmpeg_exit(1);
+ exit_program(1);
}
}
@@ -1333,24 +1368,26 @@ static void do_video_stats(AVFormatContext *os, AVOutputStream *ost,
}
}
-static void print_report(AVFormatContext **output_files,
- AVOutputStream **ost_table, int nb_ostreams,
- int is_last_report)
+static void print_report(OutputFile *output_files,
+ OutputStream *ost_table, int nb_ostreams,
+ int is_last_report, int64_t timer_start, int64_t cur_time)
{
char buf[1024];
- AVOutputStream *ost;
+ OutputStream *ost;
AVFormatContext *oc;
int64_t total_size;
AVCodecContext *enc;
int frame_number, vid, i;
- double bitrate, ti1, pts;
+ double bitrate;
+ int64_t pts = INT64_MAX;
static int64_t last_time = -1;
static int qp_histogram[52];
+ int hours, mins, secs, us;
+
+ if (!print_stats && !is_last_report)
+ return;
if (!is_last_report) {
- int64_t cur_time;
- /* display the report every 0.5 seconds */
- cur_time = av_gettime();
if (last_time == -1) {
last_time = cur_time;
return;
@@ -1361,18 +1398,17 @@ static void print_report(AVFormatContext **output_files,
}
- oc = output_files[0];
+ oc = output_files[0].ctx;
total_size = avio_size(oc->pb);
if(total_size<0) // FIXME improve avio_size() so it works with non seekable output too
total_size= avio_tell(oc->pb);
buf[0] = '\0';
- ti1 = 1e10;
vid = 0;
for(i=0;i<nb_ostreams;i++) {
float q = -1;
- ost = ost_table[i];
+ ost = &ost_table[i];
enc = ost->st->codec;
if (!ost->st->stream_copy && enc->coded_frame)
q = enc->coded_frame->quality/(float)FF_QP2LAMBDA;
@@ -1380,7 +1416,7 @@ static void print_report(AVFormatContext **output_files,
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "q=%2.1f ", q);
}
if (!vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) {
- float t = (av_gettime()-timer_start) / 1000000.0;
+ float t = (cur_time-timer_start) / 1000000.0;
frame_number = ost->frame_number;
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "frame=%5d fps=%3d q=%3.1f ",
@@ -1419,43 +1455,48 @@ static void print_report(AVFormatContext **output_files,
vid = 1;
}
/* compute min output value */
- pts = (double)ost->st->pts.val * av_q2d(ost->st->time_base);
- if ((pts < ti1) && (pts > 0))
- ti1 = pts;
+ pts = FFMIN(pts, av_rescale_q(ost->st->pts.val,
+ ost->st->time_base, AV_TIME_BASE_Q));
}
- if (ti1 < 0.01)
- ti1 = 0.01;
- if (verbose > 0 || is_last_report) {
- bitrate = (double)(total_size * 8) / ti1 / 1000.0;
+ secs = pts / AV_TIME_BASE;
+ us = pts % AV_TIME_BASE;
+ mins = secs / 60;
+ secs %= 60;
+ hours = mins / 60;
+ mins %= 60;
- snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
- "size=%8.0fkB time=%0.2f bitrate=%6.1fkbits/s",
- (double)total_size / 1024, ti1, bitrate);
+ bitrate = pts ? total_size * 8 / (pts / 1000.0) : 0;
- if (nb_frames_dup || nb_frames_drop)
- snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " dup=%d drop=%d",
- nb_frames_dup, nb_frames_drop);
+ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
+ "size=%8.0fkB time=", total_size / 1024.0);
+ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
+ "%02d:%02d:%02d.%02d ", hours, mins, secs,
+ (100 * us) / AV_TIME_BASE);
+ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
+ "bitrate=%6.1fkbits/s", bitrate);
- if (verbose >= 0)
- fprintf(stderr, "%s \r", buf);
+ if (nb_frames_dup || nb_frames_drop)
+ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " dup=%d drop=%d",
+ nb_frames_dup, nb_frames_drop);
- fflush(stderr);
- }
+ av_log(NULL, AV_LOG_INFO, "%s \r", buf);
+
+ fflush(stderr);
- if (is_last_report && verbose >= 0){
+ if (is_last_report) {
int64_t raw= audio_size + video_size + extra_size;
- fprintf(stderr, "\n");
- fprintf(stderr, "video:%1.0fkB audio:%1.0fkB global headers:%1.0fkB muxing overhead %f%%\n",
- video_size/1024.0,
- audio_size/1024.0,
- extra_size/1024.0,
- 100.0*(total_size - raw)/raw
+ av_log(NULL, AV_LOG_INFO, "\n");
+ av_log(NULL, AV_LOG_INFO, "video:%1.0fkB audio:%1.0fkB global headers:%1.0fkB muxing overhead %f%%\n",
+ video_size/1024.0,
+ audio_size/1024.0,
+ extra_size/1024.0,
+ 100.0*(total_size - raw)/raw
);
}
}
-static void generate_silence(uint8_t* buf, enum AVSampleFormat sample_fmt, size_t size)
+static void generate_silence(uint8_t *buf, enum AVSampleFormat sample_fmt, size_t size)
{
int fill_char = 0x00;
if (sample_fmt == AV_SAMPLE_FMT_U8)
@@ -1463,16 +1504,100 @@ static void generate_silence(uint8_t* buf, enum AVSampleFormat sample_fmt, size_
memset(buf, fill_char, size);
}
+static void flush_encoders(OutputStream *ost_table, int nb_ostreams)
+{
+ int i, ret;
+
+ for (i = 0; i < nb_ostreams; i++) {
+ OutputStream *ost = &ost_table[i];
+ AVCodecContext *enc = ost->st->codec;
+ AVFormatContext *os = output_files[ost->file_index].ctx;
+
+ if (!ost->encoding_needed)
+ continue;
+
+ if (ost->st->codec->codec_type == AVMEDIA_TYPE_AUDIO && enc->frame_size <=1)
+ continue;
+ if (ost->st->codec->codec_type == AVMEDIA_TYPE_VIDEO && (os->oformat->flags & AVFMT_RAWPICTURE))
+ continue;
+
+ for(;;) {
+ AVPacket pkt;
+ int fifo_bytes;
+ av_init_packet(&pkt);
+ pkt.stream_index= ost->index;
+
+ switch (ost->st->codec->codec_type) {
+ case AVMEDIA_TYPE_AUDIO:
+ fifo_bytes = av_fifo_size(ost->fifo);
+ ret = 0;
+ /* encode any samples remaining in fifo */
+ if (fifo_bytes > 0) {
+ int osize = av_get_bytes_per_sample(enc->sample_fmt);
+ int fs_tmp = enc->frame_size;
+
+ av_fifo_generic_read(ost->fifo, audio_buf, fifo_bytes, NULL);
+ if (enc->codec->capabilities & CODEC_CAP_SMALL_LAST_FRAME) {
+ enc->frame_size = fifo_bytes / (osize * enc->channels);
+ } else { /* pad */
+ int frame_bytes = enc->frame_size*osize*enc->channels;
+ if (allocated_audio_buf_size < frame_bytes)
+ exit_program(1);
+ generate_silence(audio_buf+fifo_bytes, enc->sample_fmt, frame_bytes - fifo_bytes);
+ }
+
+ ret = avcodec_encode_audio(enc, bit_buffer, bit_buffer_size, (short *)audio_buf);
+ pkt.duration = av_rescale((int64_t)enc->frame_size*ost->st->time_base.den,
+ ost->st->time_base.num, enc->sample_rate);
+ enc->frame_size = fs_tmp;
+ }
+ if (ret <= 0) {
+ ret = avcodec_encode_audio(enc, bit_buffer, bit_buffer_size, NULL);
+ }
+ if (ret < 0) {
+ av_log(NULL, AV_LOG_FATAL, "Audio encoding failed\n");
+ exit_program(1);
+ }
+ audio_size += ret;
+ pkt.flags |= AV_PKT_FLAG_KEY;
+ break;
+ case AVMEDIA_TYPE_VIDEO:
+ ret = avcodec_encode_video(enc, bit_buffer, bit_buffer_size, NULL);
+ if (ret < 0) {
+ av_log(NULL, AV_LOG_FATAL, "Video encoding failed\n");
+ exit_program(1);
+ }
+ video_size += ret;
+ if(enc->coded_frame && enc->coded_frame->key_frame)
+ pkt.flags |= AV_PKT_FLAG_KEY;
+ if (ost->logfile && enc->stats_out) {
+ fprintf(ost->logfile, "%s", enc->stats_out);
+ }
+ break;
+ default:
+ ret=-1;
+ }
+
+ if (ret <= 0)
+ break;
+ pkt.data = bit_buffer;
+ pkt.size = ret;
+ if (enc->coded_frame && enc->coded_frame->pts != AV_NOPTS_VALUE)
+ pkt.pts= av_rescale_q(enc->coded_frame->pts, enc->time_base, ost->st->time_base);
+ write_frame(os, &pkt, ost->st->codec, ost->bitstream_filters);
+ }
+ }
+}
+
/* pkt = NULL means EOF (needed to flush decoder buffers) */
-static int output_packet(AVInputStream *ist, int ist_index,
- AVOutputStream **ost_table, int nb_ostreams,
+static int output_packet(InputStream *ist, int ist_index,
+ OutputStream *ost_table, int nb_ostreams,
const AVPacket *pkt)
{
AVFormatContext *os;
- AVOutputStream *ost;
- int ret, i;
+ OutputStream *ost;
+ int ret = 0, i;
int got_output;
- AVFrame picture;
void *buffer_to_free = NULL;
static unsigned int samples_size= 0;
AVSubtitle subtitle, *subtitle_to_free;
@@ -1480,6 +1605,7 @@ static int output_packet(AVInputStream *ist, int ist_index,
#if CONFIG_AVFILTER
int frame_available;
#endif
+ float quality;
AVPacket avpkt;
int bps = av_get_bytes_per_sample(ist->st->codec->sample_fmt);
@@ -1506,16 +1632,17 @@ static int output_packet(AVInputStream *ist, int ist_index,
while (avpkt.size > 0 || (!pkt && got_output)) {
uint8_t *data_buf, *decoded_data_buf;
int data_size, decoded_data_size;
+ AVFrame *decoded_frame, *filtered_frame;
handle_eof:
ist->pts= ist->next_pts;
- if(avpkt.size && avpkt.size != pkt->size &&
- ((!ist->showed_multi_packet_warning && verbose>0) || verbose>1)){
- fprintf(stderr, "Multiple frames in a packet from stream %d\n", pkt->stream_index);
+ if(avpkt.size && avpkt.size != pkt->size)
+ av_log(NULL, ist->showed_multi_packet_warning ? AV_LOG_VERBOSE : AV_LOG_WARNING,
+ "Multiple frames in a packet from stream %d\n", pkt->stream_index);
ist->showed_multi_packet_warning=1;
- }
/* decode the packet if needed */
+ decoded_frame = filtered_frame = NULL;
decoded_data_buf = NULL; /* fail safe */
decoded_data_size= 0;
data_buf = avpkt.data;
@@ -1524,8 +1651,8 @@ static int output_packet(AVInputStream *ist, int ist_index,
if (ist->decoding_needed) {
switch(ist->st->codec->codec_type) {
case AVMEDIA_TYPE_AUDIO:{
- if(pkt && samples_size < FFMAX(pkt->size*sizeof(*samples), AVCODEC_MAX_AUDIO_FRAME_SIZE)) {
- samples_size = FFMAX(pkt->size*sizeof(*samples), AVCODEC_MAX_AUDIO_FRAME_SIZE);
+ if(pkt && samples_size < FFMAX(pkt->size * bps, AVCODEC_MAX_AUDIO_FRAME_SIZE)) {
+ samples_size = FFMAX(pkt->size * bps, AVCODEC_MAX_AUDIO_FRAME_SIZE);
av_free(samples);
samples= av_malloc(samples_size);
}
@@ -1535,7 +1662,7 @@ static int output_packet(AVInputStream *ist, int ist_index,
ret = avcodec_decode_audio3(ist->st->codec, samples, &decoded_data_size,
&avpkt);
if (ret < 0)
- goto fail_decode;
+ return ret;
avpkt.data += ret;
avpkt.size -= ret;
data_size = ret;
@@ -1551,23 +1678,23 @@ static int output_packet(AVInputStream *ist, int ist_index,
(ist->st->codec->sample_rate * ist->st->codec->channels);
break;}
case AVMEDIA_TYPE_VIDEO:
- decoded_data_size = (ist->st->codec->width * ist->st->codec->height * 3) / 2;
- /* XXX: allocate picture correctly */
- avcodec_get_frame_defaults(&picture);
+ if (!(decoded_frame = avcodec_alloc_frame()))
+ return AVERROR(ENOMEM);
avpkt.pts = pkt_pts;
avpkt.dts = ist->pts;
pkt_pts = AV_NOPTS_VALUE;
ret = avcodec_decode_video2(ist->st->codec,
- &picture, &got_output, &avpkt);
- ist->st->quality= picture.quality;
+ decoded_frame, &got_output, &avpkt);
+ quality = same_quant ? decoded_frame->quality : 0;
if (ret < 0)
- goto fail_decode;
+ goto fail;
if (!got_output) {
/* no picture yet */
+ av_freep(&decoded_frame);
goto discard_packet;
}
- ist->next_pts = ist->pts = guess_correct_pts(&ist->pts_ctx, picture.pkt_pts, picture.pkt_dts);
+ ist->next_pts = ist->pts = decoded_frame->best_effort_timestamp;
if (ist->st->codec->time_base.num != 0) {
int ticks= ist->st->parser ? ist->st->parser->repeat_pict+1 : ist->st->codec->ticks_per_frame;
ist->next_pts += ((int64_t)AV_TIME_BASE *
@@ -1576,13 +1703,13 @@ static int output_packet(AVInputStream *ist, int ist_index,
}
avpkt.size = 0;
buffer_to_free = NULL;
- pre_process_video_frame(ist, (AVPicture *)&picture, &buffer_to_free);
+ pre_process_video_frame(ist, (AVPicture *)decoded_frame, &buffer_to_free);
break;
case AVMEDIA_TYPE_SUBTITLE:
ret = avcodec_decode_subtitle2(ist->st->codec,
&subtitle, &got_output, &avpkt);
if (ret < 0)
- goto fail_decode;
+ return ret;
if (!got_output) {
goto discard_packet;
}
@@ -1590,7 +1717,7 @@ static int output_packet(AVInputStream *ist, int ist_index,
avpkt.size = 0;
break;
default:
- goto fail_decode;
+ return -1;
}
} else {
switch(ist->st->codec->codec_type) {
@@ -1607,24 +1734,21 @@ static int output_packet(AVInputStream *ist, int ist_index,
}
break;
}
- ret = avpkt.size;
avpkt.size = 0;
}
#if CONFIG_AVFILTER
- if (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
- for (i = 0; i < nb_ostreams; i++) {
- ost = ost_table[i];
+ if(ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO)
+ for(i=0;i<nb_ostreams;i++) {
+ OutputFile *of = &output_files[ost_table[i].file_index];
+ if (of->start_time == 0 || ist->pts >= of->start_time) {
+ ost = &ost_table[i];
if (ost->input_video_filter && ost->source_index == ist_index) {
- AVRational sar;
- if (ist->st->sample_aspect_ratio.num)
- sar = ist->st->sample_aspect_ratio;
- else
- sar = ist->st->codec->sample_aspect_ratio;
- // add it to be filtered
- av_vsrc_buffer_add_frame(ost->input_video_filter, &picture,
- ist->pts,
- sar);
+ if (!decoded_frame->sample_aspect_ratio.num)
+ decoded_frame->sample_aspect_ratio = ist->st->sample_aspect_ratio;
+ decoded_frame->pts = ist->pts;
+
+ av_vsrc_buffer_add_frame(ost->input_video_filter, decoded_frame, AV_VSRC_BUF_FLAG_OVERWRITE);
}
}
}
@@ -1633,19 +1757,63 @@ static int output_packet(AVInputStream *ist, int ist_index,
// preprocess audio (volume)
if (ist->st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
if (audio_volume != 256) {
- short *volp;
- volp = samples;
- for(i=0;i<(decoded_data_size / sizeof(short));i++) {
- int v = ((*volp) * audio_volume + 128) >> 8;
- if (v < -32768) v = -32768;
- if (v > 32767) v = 32767;
- *volp++ = v;
+ switch (ist->st->codec->sample_fmt) {
+ case AV_SAMPLE_FMT_U8:
+ {
+ uint8_t *volp = samples;
+ for (i = 0; i < (decoded_data_size / sizeof(*volp)); i++) {
+ int v = (((*volp - 128) * audio_volume + 128) >> 8) + 128;
+ *volp++ = av_clip_uint8(v);
+ }
+ break;
+ }
+ case AV_SAMPLE_FMT_S16:
+ {
+ int16_t *volp = samples;
+ for (i = 0; i < (decoded_data_size / sizeof(*volp)); i++) {
+ int v = ((*volp) * audio_volume + 128) >> 8;
+ *volp++ = av_clip_int16(v);
+ }
+ break;
+ }
+ case AV_SAMPLE_FMT_S32:
+ {
+ int32_t *volp = samples;
+ for (i = 0; i < (decoded_data_size / sizeof(*volp)); i++) {
+ int64_t v = (((int64_t)*volp * audio_volume + 128) >> 8);
+ *volp++ = av_clipl_int32(v);
+ }
+ break;
+ }
+ case AV_SAMPLE_FMT_FLT:
+ {
+ float *volp = samples;
+ float scale = audio_volume / 256.f;
+ for (i = 0; i < (decoded_data_size / sizeof(*volp)); i++) {
+ *volp++ *= scale;
+ }
+ break;
+ }
+ case AV_SAMPLE_FMT_DBL:
+ {
+ double *volp = samples;
+ double scale = audio_volume / 256.;
+ for (i = 0; i < (decoded_data_size / sizeof(*volp)); i++) {
+ *volp++ *= scale;
+ }
+ break;
+ }
+ default:
+ av_log(NULL, AV_LOG_FATAL,
+ "Audio volume adjustment on sample format %s is not supported.\n",
+ av_get_sample_fmt_name(ist->st->codec->sample_fmt));
+ exit_program(1);
}
}
}
/* frame rate emulation */
- if (rate_emu) {
+ if (input_files[ist->file_index].rate_emu) {
int64_t pts = av_rescale(ist->pts, 1000000, AV_TIME_BASE);
int64_t now = av_gettime() - ist->start;
if (pts > now)
@@ -1653,448 +1821,243 @@ static int output_packet(AVInputStream *ist, int ist_index,
}
/* if output time reached then transcode raw format,
encode packets and output them */
- if (start_time == 0 || ist->pts >= start_time)
- for(i=0;i<nb_ostreams;i++) {
- int frame_size;
+ for (i = 0; i < nb_ostreams; i++) {
+ OutputFile *of = &output_files[ost_table[i].file_index];
+ int frame_size;
+
+ ost = &ost_table[i];
+ if (ost->source_index != ist_index)
+ continue;
+
+ if (of->start_time && ist->pts < of->start_time)
+ continue;
+
+ if (of->recording_time != INT64_MAX &&
+ av_compare_ts(ist->pts, AV_TIME_BASE_Q, of->recording_time + of->start_time,
+ (AVRational){1, 1000000}) >= 0) {
+ ost->is_past_recording_time = 1;
+ continue;
+ }
- ost = ost_table[i];
- if (ost->source_index == ist_index) {
#if CONFIG_AVFILTER
- frame_available = ist->st->codec->codec_type != AVMEDIA_TYPE_VIDEO ||
- !ost->output_video_filter || avfilter_poll_frame(ost->output_video_filter->inputs[0]);
- while (frame_available) {
- AVRational ist_pts_tb;
- if (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO && ost->output_video_filter)
- get_filtered_video_frame(ost->output_video_filter, &picture, &ost->picref, &ist_pts_tb);
- if (ost->picref)
+ frame_available = ist->st->codec->codec_type != AVMEDIA_TYPE_VIDEO ||
+ !ost->output_video_filter || avfilter_poll_frame(ost->output_video_filter->inputs[0]);
+ while (frame_available) {
+ if (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO && ost->output_video_filter) {
+ AVRational ist_pts_tb = ost->output_video_filter->inputs[0]->time_base;
+ if (av_buffersink_get_buffer_ref(ost->output_video_filter, &ost->picref, 0) < 0)
+ goto cont;
+ if (!filtered_frame && !(filtered_frame = avcodec_alloc_frame())) {
+ ret = AVERROR(ENOMEM);
+ goto fail;
+ }
+ *filtered_frame= *decoded_frame; //for me_threshold
+ if (ost->picref) {
+ avfilter_fill_frame_from_video_buffer_ref(filtered_frame, ost->picref);
ist->pts = av_rescale_q(ost->picref->pts, ist_pts_tb, AV_TIME_BASE_Q);
+ }
+ }
+#else
+ filtered_frame = decoded_frame;
#endif
- os = output_files[ost->file_index];
-
- /* set the input output pts pairs */
- //ost->sync_ipts = (double)(ist->pts + input_files_ts_offset[ist->file_index] - start_time)/ AV_TIME_BASE;
-
- if (ost->encoding_needed) {
- av_assert0(ist->decoding_needed);
- switch(ost->st->codec->codec_type) {
- case AVMEDIA_TYPE_AUDIO:
- do_audio_out(os, ost, ist, decoded_data_buf, decoded_data_size);
- break;
- case AVMEDIA_TYPE_VIDEO:
+ os = output_files[ost->file_index].ctx;
+
+ /* set the input output pts pairs */
+ //ost->sync_ipts = (double)(ist->pts + input_files[ist->file_index].ts_offset - start_time)/ AV_TIME_BASE;
+
+ if (ost->encoding_needed) {
+ av_assert0(ist->decoding_needed);
+ switch(ost->st->codec->codec_type) {
+ case AVMEDIA_TYPE_AUDIO:
+ do_audio_out(os, ost, ist, decoded_data_buf, decoded_data_size);
+ break;
+ case AVMEDIA_TYPE_VIDEO:
#if CONFIG_AVFILTER
- if (ost->picref->video && !ost->frame_aspect_ratio)
- ost->st->codec->sample_aspect_ratio = ost->picref->video->pixel_aspect;
+ if (ost->picref->video && !ost->frame_aspect_ratio)
+ ost->st->codec->sample_aspect_ratio = ost->picref->video->sample_aspect_ratio;
#endif
- do_video_out(os, ost, ist, &picture, &frame_size);
- if (vstats_filename && frame_size)
- do_video_stats(os, ost, frame_size);
- break;
- case AVMEDIA_TYPE_SUBTITLE:
- do_subtitle_out(os, ost, ist, &subtitle,
- pkt->pts);
- break;
- default:
- abort();
- }
- } else {
- AVFrame avframe; //FIXME/XXX remove this
- AVPacket opkt;
- int64_t ost_tb_start_time= av_rescale_q(start_time, AV_TIME_BASE_Q, ost->st->time_base);
-
- av_init_packet(&opkt);
+ do_video_out(os, ost, ist, filtered_frame, &frame_size,
+ same_quant ? quality : ost->st->codec->global_quality);
+ if (vstats_filename && frame_size)
+ do_video_stats(os, ost, frame_size);
+ break;
+ case AVMEDIA_TYPE_SUBTITLE:
+ do_subtitle_out(os, ost, ist, &subtitle,
+ pkt->pts);
+ break;
+ default:
+ abort();
+ }
+ } else {
+ AVPicture pict;
+ AVPacket opkt;
+ int64_t ost_tb_start_time= av_rescale_q(of->start_time, AV_TIME_BASE_Q, ost->st->time_base);
+ av_init_packet(&opkt);
- if ((!ost->frame_number && !(pkt->flags & AV_PKT_FLAG_KEY)) && !copy_initial_nonkeyframes)
+ if ((!ost->frame_number && !(pkt->flags & AV_PKT_FLAG_KEY)) && !copy_initial_nonkeyframes)
#if !CONFIG_AVFILTER
- continue;
+ continue;
#else
- goto cont;
+ goto cont;
#endif
- /* no reencoding needed : output the packet directly */
- /* force the input stream PTS */
+ /* no reencoding needed : output the packet directly */
+ /* force the input stream PTS */
- avcodec_get_frame_defaults(&avframe);
- ost->st->codec->coded_frame= &avframe;
- avframe.key_frame = pkt->flags & AV_PKT_FLAG_KEY;
+ if(ost->st->codec->codec_type == AVMEDIA_TYPE_AUDIO)
+ audio_size += data_size;
+ else if (ost->st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
+ video_size += data_size;
+ ost->sync_opts++;
+ }
- if(ost->st->codec->codec_type == AVMEDIA_TYPE_AUDIO)
- audio_size += data_size;
- else if (ost->st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
- video_size += data_size;
- ost->sync_opts++;
- }
+ opkt.stream_index= ost->index;
+ if(pkt->pts != AV_NOPTS_VALUE)
+ opkt.pts= av_rescale_q(pkt->pts, ist->st->time_base, ost->st->time_base) - ost_tb_start_time;
+ else
+ opkt.pts= AV_NOPTS_VALUE;
- opkt.stream_index= ost->index;
- if(pkt->pts != AV_NOPTS_VALUE)
- opkt.pts= av_rescale_q(pkt->pts, ist->st->time_base, ost->st->time_base) - ost_tb_start_time;
- else
- opkt.pts= AV_NOPTS_VALUE;
-
- if (pkt->dts == AV_NOPTS_VALUE)
- opkt.dts = av_rescale_q(ist->pts, AV_TIME_BASE_Q, ost->st->time_base);
- else
- opkt.dts = av_rescale_q(pkt->dts, ist->st->time_base, ost->st->time_base);
- opkt.dts -= ost_tb_start_time;
-
- opkt.duration = av_rescale_q(pkt->duration, ist->st->time_base, ost->st->time_base);
- opkt.flags= pkt->flags;
-
- //FIXME remove the following 2 lines they shall be replaced by the bitstream filters
- if( ost->st->codec->codec_id != CODEC_ID_H264
- && ost->st->codec->codec_id != CODEC_ID_MPEG1VIDEO
- && ost->st->codec->codec_id != CODEC_ID_MPEG2VIDEO
- ) {
- if(av_parser_change(ist->st->parser, ost->st->codec, &opkt.data, &opkt.size, data_buf, data_size, pkt->flags & AV_PKT_FLAG_KEY))
- opkt.destruct= av_destruct_packet;
- } else {
- opkt.data = data_buf;
- opkt.size = data_size;
- }
+ if (pkt->dts == AV_NOPTS_VALUE)
+ opkt.dts = av_rescale_q(ist->pts, AV_TIME_BASE_Q, ost->st->time_base);
+ else
+ opkt.dts = av_rescale_q(pkt->dts, ist->st->time_base, ost->st->time_base);
+ opkt.dts -= ost_tb_start_time;
+
+ opkt.duration = av_rescale_q(pkt->duration, ist->st->time_base, ost->st->time_base);
+ opkt.flags= pkt->flags;
+
+ //FIXME remove the following 2 lines they shall be replaced by the bitstream filters
+ if( ost->st->codec->codec_id != CODEC_ID_H264
+ && ost->st->codec->codec_id != CODEC_ID_MPEG1VIDEO
+ && ost->st->codec->codec_id != CODEC_ID_MPEG2VIDEO
+ ) {
+ if(av_parser_change(ist->st->parser, ost->st->codec, &opkt.data, &opkt.size, data_buf, data_size, pkt->flags & AV_PKT_FLAG_KEY))
+ opkt.destruct= av_destruct_packet;
+ } else {
+ opkt.data = data_buf;
+ opkt.size = data_size;
+ }
- write_frame(os, &opkt, ost->st->codec, ost->bitstream_filters);
- ost->st->codec->frame_number++;
- ost->frame_number++;
- av_free_packet(&opkt);
+ if (os->oformat->flags & AVFMT_RAWPICTURE) {
+ /* store AVPicture in AVPacket, as expected by the output format */
+ avpicture_fill(&pict, opkt.data, ost->st->codec->pix_fmt, ost->st->codec->width, ost->st->codec->height);
+ opkt.data = (uint8_t *)&pict;
+ opkt.size = sizeof(AVPicture);
+ opkt.flags |= AV_PKT_FLAG_KEY;
}
-#if CONFIG_AVFILTER
- cont:
- frame_available = (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO) &&
- ost->output_video_filter && avfilter_poll_frame(ost->output_video_filter->inputs[0]);
- if (ost->picref)
- avfilter_unref_buffer(ost->picref);
- }
-#endif
+ write_frame(os, &opkt, ost->st->codec, ost->bitstream_filters);
+ ost->st->codec->frame_number++;
+ ost->frame_number++;
+ av_free_packet(&opkt);
}
+#if CONFIG_AVFILTER
+ cont:
+ frame_available = (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO) &&
+ ost->output_video_filter && avfilter_poll_frame(ost->output_video_filter->inputs[0]);
+ avfilter_unref_buffer(ost->picref);
}
+ av_freep(&filtered_frame);
+#endif
+ }
+fail:
av_free(buffer_to_free);
/* XXX: allocate the subtitles in the codec ? */
if (subtitle_to_free) {
avsubtitle_free(subtitle_to_free);
subtitle_to_free = NULL;
}
+ av_freep(&decoded_frame);
+ if (ret < 0)
+ return ret;
}
discard_packet:
- if (pkt == NULL) {
- /* EOF handling */
-
- for(i=0;i<nb_ostreams;i++) {
- ost = ost_table[i];
- if (ost->source_index == ist_index) {
- AVCodecContext *enc= ost->st->codec;
- os = output_files[ost->file_index];
-
- if(ost->st->codec->codec_type == AVMEDIA_TYPE_AUDIO && enc->frame_size <=1)
- continue;
- if(ost->st->codec->codec_type == AVMEDIA_TYPE_VIDEO && (os->oformat->flags & AVFMT_RAWPICTURE))
- continue;
-
- if (ost->encoding_needed) {
- for(;;) {
- AVPacket pkt;
- int fifo_bytes;
- av_init_packet(&pkt);
- pkt.stream_index= ost->index;
-
- switch(ost->st->codec->codec_type) {
- case AVMEDIA_TYPE_AUDIO:
- fifo_bytes = av_fifo_size(ost->fifo);
- ret = 0;
- /* encode any samples remaining in fifo */
- if (fifo_bytes > 0) {
- int osize = av_get_bytes_per_sample(enc->sample_fmt);
- int fs_tmp = enc->frame_size;
-
- av_fifo_generic_read(ost->fifo, audio_buf, fifo_bytes, NULL);
- if (enc->codec->capabilities & CODEC_CAP_SMALL_LAST_FRAME) {
- enc->frame_size = fifo_bytes / (osize * enc->channels);
- } else { /* pad */
- int frame_bytes = enc->frame_size*osize*enc->channels;
- if (allocated_audio_buf_size < frame_bytes)
- ffmpeg_exit(1);
- generate_silence(audio_buf+fifo_bytes, enc->sample_fmt, frame_bytes - fifo_bytes);
- }
-
- ret = avcodec_encode_audio(enc, bit_buffer, bit_buffer_size, (short *)audio_buf);
- pkt.duration = av_rescale((int64_t)enc->frame_size*ost->st->time_base.den,
- ost->st->time_base.num, enc->sample_rate);
- enc->frame_size = fs_tmp;
- }
- if(ret <= 0) {
- ret = avcodec_encode_audio(enc, bit_buffer, bit_buffer_size, NULL);
- }
- if (ret < 0) {
- fprintf(stderr, "Audio encoding failed\n");
- ffmpeg_exit(1);
- }
- audio_size += ret;
- pkt.flags |= AV_PKT_FLAG_KEY;
- break;
- case AVMEDIA_TYPE_VIDEO:
- ret = avcodec_encode_video(enc, bit_buffer, bit_buffer_size, NULL);
- if (ret < 0) {
- fprintf(stderr, "Video encoding failed\n");
- ffmpeg_exit(1);
- }
- video_size += ret;
- if(enc->coded_frame && enc->coded_frame->key_frame)
- pkt.flags |= AV_PKT_FLAG_KEY;
- if (ost->logfile && enc->stats_out) {
- fprintf(ost->logfile, "%s", enc->stats_out);
- }
- break;
- default:
- ret=-1;
- }
-
- if(ret<=0)
- break;
- pkt.data= bit_buffer;
- pkt.size= ret;
- if(enc->coded_frame && enc->coded_frame->pts != AV_NOPTS_VALUE)
- pkt.pts= av_rescale_q(enc->coded_frame->pts, enc->time_base, ost->st->time_base);
- write_frame(os, &pkt, ost->st->codec, ost->bitstream_filters);
- }
- }
- }
- }
- }
return 0;
- fail_decode:
- return -1;
}
-static void print_sdp(AVFormatContext **avc, int n)
+static void print_sdp(OutputFile *output_files, int n)
{
char sdp[2048];
+ int i;
+ AVFormatContext **avc = av_malloc(sizeof(*avc)*n);
+
+ if (!avc)
+ exit_program(1);
+ for (i = 0; i < n; i++)
+ avc[i] = output_files[i].ctx;
av_sdp_create(avc, n, sdp, sizeof(sdp));
printf("SDP:\n%s\n", sdp);
fflush(stdout);
+ av_freep(&avc);
}
-static int copy_chapters(int infile, int outfile)
+static int init_input_stream(int ist_index, OutputStream *output_streams, int nb_output_streams,
+ char *error, int error_len)
{
- AVFormatContext *is = input_files[infile].ctx;
- AVFormatContext *os = output_files[outfile];
- int i;
-
- for (i = 0; i < is->nb_chapters; i++) {
- AVChapter *in_ch = is->chapters[i], *out_ch;
- int64_t ts_off = av_rescale_q(start_time - input_files_ts_offset[infile],
- AV_TIME_BASE_Q, in_ch->time_base);
- int64_t rt = (recording_time == INT64_MAX) ? INT64_MAX :
- av_rescale_q(recording_time, AV_TIME_BASE_Q, in_ch->time_base);
-
-
- if (in_ch->end < ts_off)
- continue;
- if (rt != INT64_MAX && in_ch->start > rt + ts_off)
- break;
-
- out_ch = av_mallocz(sizeof(AVChapter));
- if (!out_ch)
- return AVERROR(ENOMEM);
-
- out_ch->id = in_ch->id;
- out_ch->time_base = in_ch->time_base;
- out_ch->start = FFMAX(0, in_ch->start - ts_off);
- out_ch->end = FFMIN(rt, in_ch->end - ts_off);
-
- if (metadata_chapters_autocopy)
- av_dict_copy(&out_ch->metadata, in_ch->metadata, 0);
-
- os->nb_chapters++;
- os->chapters = av_realloc(os->chapters, sizeof(AVChapter)*os->nb_chapters);
- if (!os->chapters)
- return AVERROR(ENOMEM);
- os->chapters[os->nb_chapters - 1] = out_ch;
+ InputStream *ist = &input_streams[ist_index];
+ if (ist->decoding_needed) {
+ AVCodec *codec = ist->dec;
+ if (!codec) {
+ snprintf(error, error_len, "Decoder (codec %s) not found for input stream #%d.%d",
+ avcodec_get_name(ist->st->codec->codec_id), ist->file_index, ist->st->index);
+ return AVERROR(EINVAL);
+ }
+ if (avcodec_open2(ist->st->codec, codec, &ist->opts) < 0) {
+ snprintf(error, error_len, "Error while opening decoder for input stream #%d.%d",
+ ist->file_index, ist->st->index);
+ return AVERROR(EINVAL);
+ }
+ assert_codec_experimental(ist->st->codec, 0);
+ assert_avoptions(ist->opts);
}
- return 0;
-}
-static void parse_forced_key_frames(char *kf, AVOutputStream *ost,
- AVCodecContext *avctx)
-{
- char *p;
- int n = 1, i;
- int64_t t;
+ ist->pts = ist->st->avg_frame_rate.num ? - ist->st->codec->has_b_frames*AV_TIME_BASE / av_q2d(ist->st->avg_frame_rate) : 0;
+ ist->next_pts = AV_NOPTS_VALUE;
+ ist->is_start = 1;
- for (p = kf; *p; p++)
- if (*p == ',')
- n++;
- ost->forced_kf_count = n;
- ost->forced_kf_pts = av_malloc(sizeof(*ost->forced_kf_pts) * n);
- if (!ost->forced_kf_pts) {
- av_log(NULL, AV_LOG_FATAL, "Could not allocate forced key frames array.\n");
- ffmpeg_exit(1);
- }
- for (i = 0; i < n; i++) {
- p = i ? strchr(p, ',') + 1 : kf;
- t = parse_time_or_die("force_key_frames", p, 1);
- ost->forced_kf_pts[i] = av_rescale_q(t, AV_TIME_BASE_Q, avctx->time_base);
- }
+ return 0;
}
-/*
- * The following code is the main loop of the file converter
- */
-static int transcode(AVFormatContext **output_files,
- int nb_output_files,
- AVInputFile *input_files,
- int nb_input_files,
- AVStreamMap *stream_maps, int nb_stream_maps)
+static int transcode_init(OutputFile *output_files, int nb_output_files,
+ InputFile *input_files, int nb_input_files)
{
- int ret = 0, i, j, k, n, nb_ostreams = 0;
- AVFormatContext *is, *os;
+ int ret = 0, i, j, k;
+ AVFormatContext *os;
AVCodecContext *codec, *icodec;
- AVOutputStream *ost, **ost_table = NULL;
- AVInputStream *ist;
+ OutputStream *ost;
+ InputStream *ist;
char error[1024];
int want_sdp = 1;
- uint8_t no_packet[MAX_FILES]={0};
- int no_packet_count=0;
- if (rate_emu)
- for (i = 0; i < nb_input_streams; i++)
- input_streams[i].start = av_gettime();
+ /* init framerate emulation */
+ for (i = 0; i < nb_input_files; i++) {
+ InputFile *ifile = &input_files[i];
+ if (ifile->rate_emu)
+ for (j = 0; j < ifile->nb_streams; j++)
+ input_streams[j + ifile->ist_index].start = av_gettime();
+ }
/* output stream init */
- nb_ostreams = 0;
for(i=0;i<nb_output_files;i++) {
- os = output_files[i];
+ os = output_files[i].ctx;
if (!os->nb_streams && !(os->oformat->flags & AVFMT_NOSTREAMS)) {
- av_dump_format(output_files[i], i, output_files[i]->filename, 1);
- fprintf(stderr, "Output file #%d does not contain any stream\n", i);
- ret = AVERROR(EINVAL);
- goto fail;
- }
- nb_ostreams += os->nb_streams;
- }
- if (nb_stream_maps > 0 && nb_stream_maps != nb_ostreams) {
- fprintf(stderr, "Number of stream maps must match number of output streams\n");
- ret = AVERROR(EINVAL);
- goto fail;
- }
-
- /* Sanity check the mapping args -- do the input files & streams exist? */
- for(i=0;i<nb_stream_maps;i++) {
- int fi = stream_maps[i].file_index;
- int si = stream_maps[i].stream_index;
-
- if (fi < 0 || fi > nb_input_files - 1 ||
- si < 0 || si > input_files[fi].ctx->nb_streams - 1) {
- fprintf(stderr,"Could not find input stream #%d.%d\n", fi, si);
- ret = AVERROR(EINVAL);
- goto fail;
- }
- fi = stream_maps[i].sync_file_index;
- si = stream_maps[i].sync_stream_index;
- if (fi < 0 || fi > nb_input_files - 1 ||
- si < 0 || si > input_files[fi].ctx->nb_streams - 1) {
- fprintf(stderr,"Could not find sync stream #%d.%d\n", fi, si);
- ret = AVERROR(EINVAL);
- goto fail;
- }
- }
-
- ost_table = av_mallocz(sizeof(AVOutputStream *) * nb_ostreams);
- if (!ost_table)
- goto fail;
- n = 0;
- for(k=0;k<nb_output_files;k++) {
- os = output_files[k];
- for(i=0;i<os->nb_streams;i++,n++) {
- int found;
- ost = ost_table[n] = output_streams_for_file[k][i];
- ost->st = os->streams[i];
- if (nb_stream_maps > 0) {
- ost->source_index = input_files[stream_maps[n].file_index].ist_index +
- stream_maps[n].stream_index;
-
- /* Sanity check that the stream types match */
- if (input_streams[ost->source_index].st->codec->codec_type != ost->st->codec->codec_type) {
- int i= ost->file_index;
- av_dump_format(output_files[i], i, output_files[i]->filename, 1);
- fprintf(stderr, "Codec type mismatch for mapping #%d.%d -> #%d.%d\n",
- stream_maps[n].file_index, stream_maps[n].stream_index,
- ost->file_index, ost->index);
- ffmpeg_exit(1);
- }
-
- } else {
- int best_nb_frames=-1;
- /* get corresponding input stream index : we select the first one with the right type */
- found = 0;
- for (j = 0; j < nb_input_streams; j++) {
- int skip=0;
- ist = &input_streams[j];
- if(opt_programid){
- int pi,si;
- AVFormatContext *f = input_files[ist->file_index].ctx;
- skip=1;
- for(pi=0; pi<f->nb_programs; pi++){
- AVProgram *p= f->programs[pi];
- if(p->id == opt_programid)
- for(si=0; si<p->nb_stream_indexes; si++){
- if(f->streams[ p->stream_index[si] ] == ist->st)
- skip=0;
- }
- }
- }
- if (ist->discard && ist->st->discard != AVDISCARD_ALL && !skip &&
- ist->st->codec->codec_type == ost->st->codec->codec_type) {
- if(best_nb_frames < ist->st->codec_info_nb_frames){
- best_nb_frames= ist->st->codec_info_nb_frames;
- ost->source_index = j;
- found = 1;
- }
- }
- }
-
- if (!found) {
- if(! opt_programid) {
- /* try again and reuse existing stream */
- for (j = 0; j < nb_input_streams; j++) {
- ist = &input_streams[j];
- if ( ist->st->codec->codec_type == ost->st->codec->codec_type
- && ist->st->discard != AVDISCARD_ALL) {
- ost->source_index = j;
- found = 1;
- }
- }
- }
- if (!found) {
- int i= ost->file_index;
- av_dump_format(output_files[i], i, output_files[i]->filename, 1);
- fprintf(stderr, "Could not find input stream matching output stream #%d.%d\n",
- ost->file_index, ost->index);
- ffmpeg_exit(1);
- }
- }
- }
- ist = &input_streams[ost->source_index];
- ist->discard = 0;
- ost->sync_ist = (nb_stream_maps > 0) ?
- &input_streams[input_files[stream_maps[n].sync_file_index].ist_index +
- stream_maps[n].sync_stream_index] : ist;
+ av_dump_format(os, i, os->filename, 1);
+ av_log(NULL, AV_LOG_ERROR, "Output file #%d does not contain any stream\n", i);
+ return AVERROR(EINVAL);
}
}
/* for each output stream, we compute the right encoding parameters */
- for(i=0;i<nb_ostreams;i++) {
- ost = ost_table[i];
- os = output_files[ost->file_index];
+ for (i = 0; i < nb_output_streams; i++) {
+ ost = &output_streams[i];
+ os = output_files[ost->file_index].ctx;
ist = &input_streams[ost->source_index];
codec = ost->st->codec;
icodec = ist->st->codec;
- if (metadata_streams_autocopy)
- av_dict_copy(&ost->st->metadata, ist->st->metadata,
- AV_DICT_DONT_OVERWRITE);
-
ost->st->disposition = ist->st->disposition;
codec->bits_per_raw_sample= icodec->bits_per_raw_sample;
codec->chroma_sample_location = icodec->chroma_sample_location;
@@ -2102,8 +2065,9 @@ static int transcode(AVFormatContext **output_files,
if (ost->st->stream_copy) {
uint64_t extra_size = (uint64_t)icodec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE;
- if (extra_size > INT_MAX)
- goto fail;
+ if (extra_size > INT_MAX) {
+ return AVERROR(EINVAL);
+ }
/* if stream_copy is selected, no need to decode or encode */
codec->codec_id = icodec->codec_id;
@@ -2120,22 +2084,33 @@ static int transcode(AVFormatContext **output_files,
codec->rc_max_rate = icodec->rc_max_rate;
codec->rc_buffer_size = icodec->rc_buffer_size;
codec->extradata= av_mallocz(extra_size);
- if (!codec->extradata)
- goto fail;
+ if (!codec->extradata) {
+ return AVERROR(ENOMEM);
+ }
memcpy(codec->extradata, icodec->extradata, icodec->extradata_size);
codec->extradata_size= icodec->extradata_size;
- if(!copy_tb && av_q2d(icodec->time_base)*icodec->ticks_per_frame > av_q2d(ist->st->time_base) && av_q2d(ist->st->time_base) < 1.0/500){
- codec->time_base = icodec->time_base;
- codec->time_base.num *= icodec->ticks_per_frame;
- av_reduce(&codec->time_base.num, &codec->time_base.den,
- codec->time_base.num, codec->time_base.den, INT_MAX);
- }else
- codec->time_base = ist->st->time_base;
+
+ codec->time_base = ist->st->time_base;
+ if(!strcmp(os->oformat->name, "avi")) {
+ if(!copy_tb && av_q2d(icodec->time_base)*icodec->ticks_per_frame > 2*av_q2d(ist->st->time_base) && av_q2d(ist->st->time_base) < 1.0/500){
+ codec->time_base = icodec->time_base;
+ codec->time_base.num *= icodec->ticks_per_frame;
+ codec->time_base.den *= 2;
+ }
+ } else if(!(os->oformat->flags & AVFMT_VARIABLE_FPS)) {
+ if(!copy_tb && av_q2d(icodec->time_base)*icodec->ticks_per_frame > av_q2d(ist->st->time_base) && av_q2d(ist->st->time_base) < 1.0/500){
+ codec->time_base = icodec->time_base;
+ codec->time_base.num *= icodec->ticks_per_frame;
+ }
+ }
+ av_reduce(&codec->time_base.num, &codec->time_base.den,
+ codec->time_base.num, codec->time_base.den, INT_MAX);
+
switch(codec->codec_type) {
case AVMEDIA_TYPE_AUDIO:
if(audio_volume != 256) {
- fprintf(stderr,"-acodec copy and -vol are incompatible (frames are not decoded)\n");
- ffmpeg_exit(1);
+ av_log(NULL, AV_LOG_FATAL, "-acodec copy and -vol are incompatible (frames are not decoded)\n");
+ exit_program(1);
}
codec->channel_layout = icodec->channel_layout;
codec->sample_rate = icodec->sample_rate;
@@ -2166,6 +2141,7 @@ static int transcode(AVFormatContext **output_files,
codec->height = icodec->height;
break;
case AVMEDIA_TYPE_DATA:
+ case AVMEDIA_TYPE_ATTACHMENT:
break;
default:
abort();
@@ -2173,27 +2149,32 @@ static int transcode(AVFormatContext **output_files,
} else {
if (!ost->enc)
ost->enc = avcodec_find_encoder(ost->st->codec->codec_id);
+ ist->decoding_needed = 1;
+ ost->encoding_needed = 1;
switch(codec->codec_type) {
case AVMEDIA_TYPE_AUDIO:
ost->fifo= av_fifo_alloc(1024);
- if(!ost->fifo)
- goto fail;
- ost->reformat_pair = MAKE_SFMT_PAIR(AV_SAMPLE_FMT_NONE,AV_SAMPLE_FMT_NONE);
+ if (!ost->fifo) {
+ return AVERROR(ENOMEM);
+ }
if (!codec->sample_rate) {
codec->sample_rate = icodec->sample_rate;
- if (icodec->lowres)
- codec->sample_rate >>= icodec->lowres;
}
choose_sample_rate(ost->st, ost->enc);
codec->time_base = (AVRational){1, codec->sample_rate};
- if (!codec->channels)
+ if (codec->sample_fmt == AV_SAMPLE_FMT_NONE)
+ codec->sample_fmt = icodec->sample_fmt;
+ choose_sample_fmt(ost->st, ost->enc);
+ if (!codec->channels) {
codec->channels = icodec->channels;
+ codec->channel_layout = icodec->channel_layout;
+ }
if (av_get_channel_layout_nb_channels(codec->channel_layout) != codec->channels)
codec->channel_layout = 0;
ost->audio_resample = codec->sample_rate != icodec->sample_rate || audio_sync_method > 1;
+ ost->audio_resample |= codec->sample_fmt != icodec->sample_fmt
+ || codec->channel_layout != icodec->channel_layout;
icodec->request_channels = codec->channels;
- ist->decoding_needed = 1;
- ost->encoding_needed = 1;
ost->resample_sample_fmt = icodec->sample_fmt;
ost->resample_sample_rate = icodec->sample_rate;
ost->resample_channels = icodec->channels;
@@ -2204,70 +2185,58 @@ static int transcode(AVFormatContext **output_files,
choose_pixel_fmt(ost->st, ost->enc);
if (ost->st->codec->pix_fmt == PIX_FMT_NONE) {
- fprintf(stderr, "Video pixel format is unknown, stream cannot be encoded\n");
- ffmpeg_exit(1);
+ av_log(NULL, AV_LOG_FATAL, "Video pixel format is unknown, stream cannot be encoded\n");
+ exit_program(1);
}
+
+ if (!codec->width || !codec->height) {
+ codec->width = icodec->width;
+ codec->height = icodec->height;
+ }
+
ost->video_resample = codec->width != icodec->width ||
codec->height != icodec->height ||
codec->pix_fmt != icodec->pix_fmt;
if (ost->video_resample) {
-#if !CONFIG_AVFILTER
- avcodec_get_frame_defaults(&ost->pict_tmp);
- if(avpicture_alloc((AVPicture*)&ost->pict_tmp, codec->pix_fmt,
- codec->width, codec->height)) {
- fprintf(stderr, "Cannot allocate temp picture, check pix fmt\n");
- ffmpeg_exit(1);
- }
- ost->img_resample_ctx = sws_getContext(
- icodec->width,
- icodec->height,
- icodec->pix_fmt,
- codec->width,
- codec->height,
- codec->pix_fmt,
- ost->sws_flags, NULL, NULL, NULL);
- if (ost->img_resample_ctx == NULL) {
- fprintf(stderr, "Cannot get resampling context\n");
- ffmpeg_exit(1);
- }
-#endif
- codec->bits_per_raw_sample= 0;
- }
- if (!codec->width || !codec->height) {
- codec->width = icodec->width;
- codec->height = icodec->height;
+ codec->bits_per_raw_sample= frame_bits_per_raw_sample;
}
+
ost->resample_height = icodec->height;
ost->resample_width = icodec->width;
ost->resample_pix_fmt= icodec->pix_fmt;
- ost->encoding_needed = 1;
- ist->decoding_needed = 1;
if (!ost->frame_rate.num)
ost->frame_rate = ist->st->r_frame_rate.num ? ist->st->r_frame_rate : (AVRational){25,1};
- if (ost->enc && ost->enc->supported_framerates && !force_fps) {
+ if (ost->enc && ost->enc->supported_framerates && !ost->force_fps) {
int idx = av_find_nearest_q_idx(ost->frame_rate, ost->enc->supported_framerates);
ost->frame_rate = ost->enc->supported_framerates[idx];
}
codec->time_base = (AVRational){ost->frame_rate.den, ost->frame_rate.num};
+ if( av_q2d(codec->time_base) < 0.001 && video_sync_method
+ && (video_sync_method==1 || (video_sync_method<0 && !(os->oformat->flags & AVFMT_VARIABLE_FPS)))){
+ av_log(os, AV_LOG_WARNING, "Frame rate very high for a muxer not effciciently supporting it.\n"
+ "Please consider specifiying a lower framerate, a different muxer or -vsync 2\n");
+ }
+ for (j = 0; j < ost->forced_kf_count; j++)
+ ost->forced_kf_pts[j] = av_rescale_q(ost->forced_kf_pts[j],
+ AV_TIME_BASE_Q,
+ codec->time_base);
#if CONFIG_AVFILTER
if (configure_video_filters(ist, ost)) {
- fprintf(stderr, "Error opening filters!\n");
+ av_log(NULL, AV_LOG_FATAL, "Error opening filters!\n");
exit(1);
}
#endif
break;
case AVMEDIA_TYPE_SUBTITLE:
- ost->encoding_needed = 1;
- ist->decoding_needed = 1;
break;
default:
abort();
break;
}
/* two pass mode */
- if (ost->encoding_needed &&
+ if (codec->codec_id != CODEC_ID_H264 &&
(codec->flags & (CODEC_FLAG_PASS1 | CODEC_FLAG_PASS2))) {
char logfilename[1024];
FILE *f;
@@ -2278,45 +2247,47 @@ static int transcode(AVFormatContext **output_files,
if (codec->flags & CODEC_FLAG_PASS1) {
f = fopen(logfilename, "wb");
if (!f) {
- fprintf(stderr, "Cannot write log file '%s' for pass-1 encoding: %s\n", logfilename, strerror(errno));
- ffmpeg_exit(1);
+ av_log(NULL, AV_LOG_FATAL, "Cannot write log file '%s' for pass-1 encoding: %s\n",
+ logfilename, strerror(errno));
+ exit_program(1);
}
ost->logfile = f;
} else {
char *logbuffer;
size_t logbuffer_size;
if (read_file(logfilename, &logbuffer, &logbuffer_size) < 0) {
- fprintf(stderr, "Error reading log file '%s' for pass-2 encoding\n", logfilename);
- ffmpeg_exit(1);
+ av_log(NULL, AV_LOG_FATAL, "Error reading log file '%s' for pass-2 encoding\n",
+ logfilename);
+ exit_program(1);
}
codec->stats_in = logbuffer;
}
}
}
if(codec->codec_type == AVMEDIA_TYPE_VIDEO){
+ /* maximum video buffer size is 6-bytes per pixel, plus DPX header size (1664)*/
int size= codec->width * codec->height;
- bit_buffer_size= FFMAX(bit_buffer_size, 6*size + 200);
+ bit_buffer_size= FFMAX(bit_buffer_size, 7*size + 10000);
}
}
if (!bit_buffer)
bit_buffer = av_malloc(bit_buffer_size);
if (!bit_buffer) {
- fprintf(stderr, "Cannot allocate %d bytes output buffer\n",
- bit_buffer_size);
- ret = AVERROR(ENOMEM);
- goto fail;
+ av_log(NULL, AV_LOG_ERROR, "Cannot allocate %d bytes output buffer\n",
+ bit_buffer_size);
+ return AVERROR(ENOMEM);
}
/* open each encoder */
- for(i=0;i<nb_ostreams;i++) {
- ost = ost_table[i];
+ for (i = 0; i < nb_output_streams; i++) {
+ ost = &output_streams[i];
if (ost->encoding_needed) {
AVCodec *codec = ost->enc;
AVCodecContext *dec = input_streams[ost->source_index].st->codec;
if (!codec) {
- snprintf(error, sizeof(error), "Encoder (codec id %d) not found for output stream #%d.%d",
- ost->st->codec->codec_id, ost->file_index, ost->index);
+ snprintf(error, sizeof(error), "Encoder (codec %s) not found for output stream #%d.%d",
+ avcodec_get_name(ost->st->codec->codec_id), ost->file_index, ost->index);
ret = AVERROR(EINVAL);
goto dump_format;
}
@@ -2329,161 +2300,55 @@ static int transcode(AVFormatContext **output_files,
memcpy(ost->st->codec->subtitle_header, dec->subtitle_header, dec->subtitle_header_size);
ost->st->codec->subtitle_header_size = dec->subtitle_header_size;
}
- if (avcodec_open(ost->st->codec, codec) < 0) {
+ if (avcodec_open2(ost->st->codec, codec, &ost->opts) < 0) {
snprintf(error, sizeof(error), "Error while opening encoder for output stream #%d.%d - maybe incorrect parameters such as bit_rate, rate, width or height",
ost->file_index, ost->index);
ret = AVERROR(EINVAL);
goto dump_format;
}
+ assert_codec_experimental(ost->st->codec, 1);
+ assert_avoptions(ost->opts);
+ if (ost->st->codec->bit_rate && ost->st->codec->bit_rate < 1000)
+ av_log(NULL, AV_LOG_WARNING, "The bitrate parameter is set too low."
+ " It takes bits/s as argument, not kbits/s\n");
extra_size += ost->st->codec->extradata_size;
- }
- }
- /* open each decoder */
- for (i = 0; i < nb_input_streams; i++) {
- ist = &input_streams[i];
- if (ist->decoding_needed) {
- AVCodec *codec = i < nb_input_codecs ? input_codecs[i] : NULL;
- if (!codec)
- codec = avcodec_find_decoder(ist->st->codec->codec_id);
- if (!codec) {
- snprintf(error, sizeof(error), "Decoder (codec id %d) not found for input stream #%d.%d",
- ist->st->codec->codec_id, ist->file_index, ist->st->index);
- ret = AVERROR(EINVAL);
- goto dump_format;
- }
-
- /* update requested sample format for the decoder based on the
- corresponding encoder sample format */
- for (j = 0; j < nb_ostreams; j++) {
- ost = ost_table[j];
- if (ost->source_index == i) {
- update_sample_fmt(ist->st->codec, codec, ost->st->codec);
- break;
- }
- }
-
- if (avcodec_open(ist->st->codec, codec) < 0) {
- snprintf(error, sizeof(error), "Error while opening decoder for input stream #%d.%d",
- ist->file_index, ist->st->index);
- ret = AVERROR(EINVAL);
- goto dump_format;
- }
- //if (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO)
- // ist->st->codec->flags |= CODEC_FLAG_REPEAT_FIELD;
+ if (ost->st->codec->me_threshold)
+ input_streams[ost->source_index].st->codec->debug |= FF_DEBUG_MV;
}
}
- /* init pts */
- for (i = 0; i < nb_input_streams; i++) {
- AVStream *st;
- ist = &input_streams[i];
- st= ist->st;
- ist->pts = st->avg_frame_rate.num ? - st->codec->has_b_frames*AV_TIME_BASE / av_q2d(st->avg_frame_rate) : 0;
- ist->next_pts = AV_NOPTS_VALUE;
- init_pts_correction(&ist->pts_ctx);
- ist->is_start = 1;
- }
-
- /* set meta data information from input file if required */
- for (i=0;i<nb_meta_data_maps;i++) {
- AVFormatContext *files[2];
- AVDictionary **meta[2];
- int j;
-
-#define METADATA_CHECK_INDEX(index, nb_elems, desc)\
- if ((index) < 0 || (index) >= (nb_elems)) {\
- snprintf(error, sizeof(error), "Invalid %s index %d while processing metadata maps\n",\
- (desc), (index));\
- ret = AVERROR(EINVAL);\
- goto dump_format;\
- }
-
- int out_file_index = meta_data_maps[i][0].file;
- int in_file_index = meta_data_maps[i][1].file;
- if (in_file_index < 0 || out_file_index < 0)
- continue;
- METADATA_CHECK_INDEX(out_file_index, nb_output_files, "output file")
- METADATA_CHECK_INDEX(in_file_index, nb_input_files, "input file")
-
- files[0] = output_files[out_file_index];
- files[1] = input_files[in_file_index].ctx;
-
- for (j = 0; j < 2; j++) {
- AVMetaDataMap *map = &meta_data_maps[i][j];
-
- switch (map->type) {
- case 'g':
- meta[j] = &files[j]->metadata;
- break;
- case 's':
- METADATA_CHECK_INDEX(map->index, files[j]->nb_streams, "stream")
- meta[j] = &files[j]->streams[map->index]->metadata;
- break;
- case 'c':
- METADATA_CHECK_INDEX(map->index, files[j]->nb_chapters, "chapter")
- meta[j] = &files[j]->chapters[map->index]->metadata;
- break;
- case 'p':
- METADATA_CHECK_INDEX(map->index, files[j]->nb_programs, "program")
- meta[j] = &files[j]->programs[map->index]->metadata;
- break;
- }
- }
-
- av_dict_copy(meta[0], *meta[1], AV_DICT_DONT_OVERWRITE);
- }
-
- /* copy global metadata by default */
- if (metadata_global_autocopy) {
-
- for (i = 0; i < nb_output_files; i++)
- av_dict_copy(&output_files[i]->metadata, input_files[0].ctx->metadata,
- AV_DICT_DONT_OVERWRITE);
- }
-
- /* copy chapters according to chapter maps */
- for (i = 0; i < nb_chapter_maps; i++) {
- int infile = chapter_maps[i].in_file;
- int outfile = chapter_maps[i].out_file;
-
- if (infile < 0 || outfile < 0)
- continue;
- if (infile >= nb_input_files) {
- snprintf(error, sizeof(error), "Invalid input file index %d in chapter mapping.\n", infile);
- ret = AVERROR(EINVAL);
+ /* init input streams */
+ for (i = 0; i < nb_input_streams; i++)
+ if ((ret = init_input_stream(i, output_streams, nb_output_streams, error, sizeof(error))) < 0)
goto dump_format;
- }
- if (outfile >= nb_output_files) {
- snprintf(error, sizeof(error), "Invalid output file index %d in chapter mapping.\n",outfile);
- ret = AVERROR(EINVAL);
- goto dump_format;
- }
- copy_chapters(infile, outfile);
- }
- /* copy chapters from the first input file that has them*/
- if (!nb_chapter_maps)
- for (i = 0; i < nb_input_files; i++) {
- if (!input_files[i].ctx->nb_chapters)
- continue;
+ /* discard unused programs */
+ for (i = 0; i < nb_input_files; i++) {
+ InputFile *ifile = &input_files[i];
+ for (j = 0; j < ifile->ctx->nb_programs; j++) {
+ AVProgram *p = ifile->ctx->programs[j];
+ int discard = AVDISCARD_ALL;
- for (j = 0; j < nb_output_files; j++)
- if ((ret = copy_chapters(i, j)) < 0)
- goto dump_format;
- break;
+ for (k = 0; k < p->nb_stream_indexes; k++)
+ if (!input_streams[ifile->ist_index + p->stream_index[k]].discard) {
+ discard = AVDISCARD_DEFAULT;
+ break;
+ }
+ p->discard = discard;
}
+ }
/* open files and write file headers */
- for(i=0;i<nb_output_files;i++) {
- os = output_files[i];
- if (avformat_write_header(os, &output_opts[i]) < 0) {
+ for (i = 0; i < nb_output_files; i++) {
+ os = output_files[i].ctx;
+ if (avformat_write_header(os, &output_files[i].opts) < 0) {
snprintf(error, sizeof(error), "Could not write header for output file #%d (incorrect codec parameters ?)", i);
ret = AVERROR(EINVAL);
goto dump_format;
}
- assert_avoptions(output_opts[i]);
- if (strcmp(output_files[i]->oformat->name, "rtp")) {
+// assert_avoptions(output_files[i].opts);
+ if (strcmp(os->oformat->name, "rtp")) {
want_sdp = 0;
}
}
@@ -2492,64 +2357,189 @@ static int transcode(AVFormatContext **output_files,
/* dump the file output parameters - cannot be done before in case
of stream copy */
for(i=0;i<nb_output_files;i++) {
- av_dump_format(output_files[i], i, output_files[i]->filename, 1);
+ av_dump_format(output_files[i].ctx, i, output_files[i].ctx->filename, 1);
}
/* dump the stream mapping */
- if (verbose >= 0) {
- fprintf(stderr, "Stream mapping:\n");
- for(i=0;i<nb_ostreams;i++) {
- ost = ost_table[i];
- fprintf(stderr, " Stream #%d.%d -> #%d.%d",
- input_streams[ost->source_index].file_index,
- input_streams[ost->source_index].st->index,
- ost->file_index,
- ost->index);
- if (ost->sync_ist != &input_streams[ost->source_index])
- fprintf(stderr, " [sync #%d.%d]",
- ost->sync_ist->file_index,
- ost->sync_ist->st->index);
- fprintf(stderr, "\n");
- }
+ av_log(NULL, AV_LOG_INFO, "Stream mapping:\n");
+ for (i = 0; i < nb_output_streams; i++) {
+ ost = &output_streams[i];
+ av_log(NULL, AV_LOG_INFO, " Stream #%d.%d -> #%d.%d",
+ input_streams[ost->source_index].file_index,
+ input_streams[ost->source_index].st->index,
+ ost->file_index,
+ ost->index);
+ if (ost->sync_ist != &input_streams[ost->source_index])
+ av_log(NULL, AV_LOG_INFO, " [sync #%d.%d]",
+ ost->sync_ist->file_index,
+ ost->sync_ist->st->index);
+ if (ost->st->stream_copy)
+ av_log(NULL, AV_LOG_INFO, " (copy)");
+ else
+ av_log(NULL, AV_LOG_INFO, " (%s -> %s)", input_streams[ost->source_index].dec ?
+ input_streams[ost->source_index].dec->name : "?",
+ ost->enc ? ost->enc->name : "?");
+ av_log(NULL, AV_LOG_INFO, "\n");
}
if (ret) {
- fprintf(stderr, "%s\n", error);
- goto fail;
+ av_log(NULL, AV_LOG_ERROR, "%s\n", error);
+ return ret;
}
if (want_sdp) {
print_sdp(output_files, nb_output_files);
}
- if (verbose >= 0)
- fprintf(stderr, "Press ctrl-c to stop encoding\n");
- term_init();
+ return 0;
+}
+
+/*
+ * The following code is the main loop of the file converter
+ */
+static int transcode(OutputFile *output_files, int nb_output_files,
+ InputFile *input_files, int nb_input_files)
+{
+ int ret, i;
+ AVFormatContext *is, *os;
+ OutputStream *ost;
+ InputStream *ist;
+ uint8_t *no_packet;
+ int no_packet_count=0;
+ int64_t timer_start;
+ int key;
+
+ if (!(no_packet = av_mallocz(nb_input_files)))
+ exit_program(1);
+
+ ret = transcode_init(output_files, nb_output_files, input_files, nb_input_files);
+ if (ret < 0)
+ goto fail;
+
+ if (!using_stdin) {
+ av_log(NULL, AV_LOG_INFO, "Press [q] to stop, [?] for help\n");
+ avio_set_interrupt_cb(decode_interrupt_cb);
+ }
timer_start = av_gettime();
for(; received_sigterm == 0;) {
int file_index, ist_index;
AVPacket pkt;
- double ipts_min;
+ int64_t ipts_min;
double opts_min;
+ int64_t cur_time= av_gettime();
- redo:
- ipts_min= 1e100;
+ ipts_min= INT64_MAX;
opts_min= 1e100;
+ /* if 'q' pressed, exits */
+ if (!using_stdin) {
+ static int64_t last_time;
+ if (received_nb_signals)
+ break;
+ /* read_key() returns 0 on EOF */
+ if(cur_time - last_time >= 100000 && !run_as_daemon){
+ key = read_key();
+ last_time = cur_time;
+ }else
+ key = -1;
+ if (key == 'q')
+ break;
+ if (key == '+') av_log_set_level(av_log_get_level()+10);
+ if (key == '-') av_log_set_level(av_log_get_level()-10);
+ if (key == 's') qp_hist ^= 1;
+ if (key == 'h'){
+ if (do_hex_dump){
+ do_hex_dump = do_pkt_dump = 0;
+ } else if(do_pkt_dump){
+ do_hex_dump = 1;
+ } else
+ do_pkt_dump = 1;
+ av_log_set_level(AV_LOG_DEBUG);
+ }
+#if CONFIG_AVFILTER
+ if (key == 'c' || key == 'C'){
+ char buf[4096], target[64], command[256], arg[256] = {0};
+ double time;
+ int k, n = 0;
+ fprintf(stderr, "\nEnter command: <target> <time> <command>[ <argument>]\n");
+ i = 0;
+ while ((k = read_key()) != '\n' && k != '\r' && i < sizeof(buf)-1)
+ if (k > 0)
+ buf[i++] = k;
+ buf[i] = 0;
+ if (k > 0 &&
+ (n = sscanf(buf, "%63[^ ] %lf %255[^ ] %255[^\n]", target, &time, command, arg)) >= 3) {
+ av_log(NULL, AV_LOG_DEBUG, "Processing command target:%s time:%f command:%s arg:%s",
+ target, time, command, arg);
+ for (i = 0; i < nb_output_streams; i++) {
+ ost = &output_streams[i];
+ if (ost->graph) {
+ if (time < 0) {
+ ret = avfilter_graph_send_command(ost->graph, target, command, arg, buf, sizeof(buf),
+ key == 'c' ? AVFILTER_CMD_FLAG_ONE : 0);
+ fprintf(stderr, "Command reply for stream %d: ret:%d res:%s\n", i, ret, buf);
+ } else {
+ ret = avfilter_graph_queue_command(ost->graph, target, command, arg, 0, time);
+ }
+ }
+ }
+ } else {
+ av_log(NULL, AV_LOG_ERROR,
+ "Parse error, at least 3 arguments were expected, "
+ "only %d given in string '%s'\n", n, buf);
+ }
+ }
+#endif
+ if (key == 'd' || key == 'D'){
+ int debug=0;
+ if(key == 'D') {
+ debug = input_streams[0].st->codec->debug<<1;
+ if(!debug) debug = 1;
+ while(debug & (FF_DEBUG_DCT_COEFF|FF_DEBUG_VIS_QP|FF_DEBUG_VIS_MB_TYPE)) //unsupported, would just crash
+ debug += debug;
+ }else
+ scanf("%d", &debug);
+ for(i=0;i<nb_input_streams;i++) {
+ input_streams[i].st->codec->debug = debug;
+ }
+ for(i=0;i<nb_output_streams;i++) {
+ ost = &output_streams[i];
+ ost->st->codec->debug = debug;
+ }
+ if(debug) av_log_set_level(AV_LOG_DEBUG);
+ fprintf(stderr,"debug=%d\n", debug);
+ }
+ if (key == '?'){
+ fprintf(stderr, "key function\n"
+ "? show this help\n"
+ "+ increase verbosity\n"
+ "- decrease verbosity\n"
+ "c Send command to filtergraph\n"
+ "D cycle through available debug modes\n"
+ "h dump packets/hex press to cycle through the 3 states\n"
+ "q quit\n"
+ "s Show QP histogram\n"
+ );
+ }
+ }
/* select the stream that we must read now by looking at the
smallest output pts */
file_index = -1;
- for(i=0;i<nb_ostreams;i++) {
- double ipts, opts;
- ost = ost_table[i];
- os = output_files[ost->file_index];
+ for (i = 0; i < nb_output_streams; i++) {
+ OutputFile *of;
+ int64_t ipts;
+ double opts;
+ ost = &output_streams[i];
+ of = &output_files[ost->file_index];
+ os = output_files[ost->file_index].ctx;
ist = &input_streams[ost->source_index];
- if(ist->is_past_recording_time || no_packet[ist->file_index])
+ if (ost->is_past_recording_time || no_packet[ist->file_index] ||
+ (os->pb && avio_tell(os->pb) >= of->limit_filesize))
continue;
- opts = ost->st->pts.val * av_q2d(ost->st->time_base);
- ipts = (double)ist->pts;
+ opts = ost->st->pts.val * av_q2d(ost->st->time_base);
+ ipts = ist->pts;
if (!input_files[ist->file_index].eof_reached){
if(ipts < ipts_min) {
ipts_min = ipts;
@@ -2560,26 +2550,24 @@ static int transcode(AVFormatContext **output_files,
if(!input_sync) file_index = ist->file_index;
}
}
- if(ost->frame_number >= max_frames[ost->st->codec->codec_type]){
- file_index= -1;
- break;
+ if (ost->frame_number >= ost->max_frames) {
+ int j;
+ for (j = 0; j < of->ctx->nb_streams; j++)
+ output_streams[of->ost_index + j].is_past_recording_time = 1;
+ continue;
}
}
/* if none, if is finished */
if (file_index < 0) {
if(no_packet_count){
no_packet_count=0;
- memset(no_packet, 0, sizeof(no_packet));
+ memset(no_packet, 0, nb_input_files);
usleep(10000);
continue;
}
break;
}
- /* finish if limit size exhausted */
- if (limit_filesize != 0 && limit_filesize <= avio_tell(output_files[0]->pb))
- break;
-
/* read a frame from it and output it in the fifo */
is = input_files[file_index].ctx;
ret= av_read_frame(is, &pkt);
@@ -2597,7 +2585,7 @@ static int transcode(AVFormatContext **output_files,
}
no_packet_count=0;
- memset(no_packet, 0, sizeof(no_packet));
+ memset(no_packet, 0, nb_input_files);
if (do_pkt_dump) {
av_pkt_dump_log2(NULL, AV_LOG_DEBUG, &pkt, do_hex_dump,
@@ -2605,7 +2593,7 @@ static int transcode(AVFormatContext **output_files,
}
/* the following test is needed in case new streams appear
dynamically in stream : we ignore them */
- if (pkt.stream_index >= input_files[file_index].ctx->nb_streams)
+ if (pkt.stream_index >= input_files[file_index].nb_streams)
goto discard_packet;
ist_index = input_files[file_index].ist_index + pkt.stream_index;
ist = &input_streams[ist_index];
@@ -2613,81 +2601,74 @@ static int transcode(AVFormatContext **output_files,
goto discard_packet;
if (pkt.dts != AV_NOPTS_VALUE)
- pkt.dts += av_rescale_q(input_files_ts_offset[ist->file_index], AV_TIME_BASE_Q, ist->st->time_base);
+ pkt.dts += av_rescale_q(input_files[ist->file_index].ts_offset, AV_TIME_BASE_Q, ist->st->time_base);
if (pkt.pts != AV_NOPTS_VALUE)
- pkt.pts += av_rescale_q(input_files_ts_offset[ist->file_index], AV_TIME_BASE_Q, ist->st->time_base);
-
- if (pkt.stream_index < nb_input_files_ts_scale[file_index]
- && input_files_ts_scale[file_index][pkt.stream_index]){
- if(pkt.pts != AV_NOPTS_VALUE)
- pkt.pts *= input_files_ts_scale[file_index][pkt.stream_index];
- if(pkt.dts != AV_NOPTS_VALUE)
- pkt.dts *= input_files_ts_scale[file_index][pkt.stream_index];
- }
+ pkt.pts += av_rescale_q(input_files[ist->file_index].ts_offset, AV_TIME_BASE_Q, ist->st->time_base);
-// fprintf(stderr, "next:%"PRId64" dts:%"PRId64" off:%"PRId64" %d\n", ist->next_pts, pkt.dts, input_files_ts_offset[ist->file_index], ist->st->codec->codec_type);
+ if(pkt.pts != AV_NOPTS_VALUE)
+ pkt.pts *= ist->ts_scale;
+ if(pkt.dts != AV_NOPTS_VALUE)
+ pkt.dts *= ist->ts_scale;
+
+// fprintf(stderr, "next:%"PRId64" dts:%"PRId64" off:%"PRId64" %d\n", ist->next_pts, pkt.dts, input_files[ist->file_index].ts_offset, ist->st->codec->codec_type);
if (pkt.dts != AV_NOPTS_VALUE && ist->next_pts != AV_NOPTS_VALUE
&& (is->iformat->flags & AVFMT_TS_DISCONT)) {
int64_t pkt_dts= av_rescale_q(pkt.dts, ist->st->time_base, AV_TIME_BASE_Q);
int64_t delta= pkt_dts - ist->next_pts;
- if((FFABS(delta) > 1LL*dts_delta_threshold*AV_TIME_BASE || pkt_dts+1<ist->pts)&& !copy_ts){
- input_files_ts_offset[ist->file_index]-= delta;
- if (verbose > 2)
- fprintf(stderr, "timestamp discontinuity %"PRId64", new offset= %"PRId64"\n", delta, input_files_ts_offset[ist->file_index]);
+ if((delta < -1LL*dts_delta_threshold*AV_TIME_BASE ||
+ (delta > 1LL*dts_delta_threshold*AV_TIME_BASE &&
+ ist->st->codec->codec_type != AVMEDIA_TYPE_SUBTITLE) ||
+ pkt_dts+1<ist->pts)&& !copy_ts){
+ input_files[ist->file_index].ts_offset -= delta;
+ av_log(NULL, AV_LOG_DEBUG, "timestamp discontinuity %"PRId64", new offset= %"PRId64"\n",
+ delta, input_files[ist->file_index].ts_offset);
pkt.dts-= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base);
if(pkt.pts != AV_NOPTS_VALUE)
pkt.pts-= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base);
}
}
- /* finish if recording time exhausted */
- if (recording_time != INT64_MAX &&
- av_compare_ts(pkt.pts, ist->st->time_base, recording_time + start_time, (AVRational){1, 1000000}) >= 0) {
- ist->is_past_recording_time = 1;
- goto discard_packet;
- }
-
//fprintf(stderr,"read #%d.%d size=%d\n", ist->file_index, ist->st->index, pkt.size);
- if (output_packet(ist, ist_index, ost_table, nb_ostreams, &pkt) < 0) {
+ if (output_packet(ist, ist_index, output_streams, nb_output_streams, &pkt) < 0) {
- if (verbose >= 0)
- fprintf(stderr, "Error while decoding stream #%d.%d\n",
- ist->file_index, ist->st->index);
+ av_log(NULL, AV_LOG_ERROR, "Error while decoding stream #%d.%d\n",
+ ist->file_index, ist->st->index);
if (exit_on_error)
- ffmpeg_exit(1);
+ exit_program(1);
av_free_packet(&pkt);
- goto redo;
+ continue;
}
discard_packet:
av_free_packet(&pkt);
/* dump report by using the output first video and audio streams */
- print_report(output_files, ost_table, nb_ostreams, 0);
+ print_report(output_files, output_streams, nb_output_streams, 0, timer_start, cur_time);
}
/* at the end of stream, we must flush the decoder buffers */
for (i = 0; i < nb_input_streams; i++) {
ist = &input_streams[i];
if (ist->decoding_needed) {
- output_packet(ist, i, ost_table, nb_ostreams, NULL);
+ output_packet(ist, i, output_streams, nb_output_streams, NULL);
}
}
+ flush_encoders(output_streams, nb_output_streams);
term_exit();
/* write the trailer if needed and close file */
for(i=0;i<nb_output_files;i++) {
- os = output_files[i];
+ os = output_files[i].ctx;
av_write_trailer(os);
}
/* dump report by using the first video and audio streams */
- print_report(output_files, ost_table, nb_ostreams, 1);
+ print_report(output_files, output_streams, nb_output_streams, 1, timer_start, av_gettime());
/* close each encoder */
- for(i=0;i<nb_ostreams;i++) {
- ost = ost_table[i];
+ for (i = 0; i < nb_output_streams; i++) {
+ ost = &output_streams[i];
if (ost->encoding_needed) {
av_freep(&ost->st->codec->stats_in);
avcodec_close(ost->st->codec);
@@ -2710,10 +2691,11 @@ static int transcode(AVFormatContext **output_files,
fail:
av_freep(&bit_buffer);
+ av_freep(&no_packet);
- if (ost_table) {
- for(i=0;i<nb_ostreams;i++) {
- ost = ost_table[i];
+ if (output_streams) {
+ for (i = 0; i < nb_output_streams; i++) {
+ ost = &output_streams[i];
if (ost) {
if (ost->st->stream_copy)
av_freep(&ost->st->codec->extradata);
@@ -2724,103 +2706,31 @@ static int transcode(AVFormatContext **output_files,
av_fifo_free(ost->fifo); /* works even if fifo is not
initialized but set to zero */
av_freep(&ost->st->codec->subtitle_header);
- av_free(ost->pict_tmp.data[0]);
+ av_free(ost->resample_frame.data[0]);
av_free(ost->forced_kf_pts);
if (ost->video_resample)
sws_freeContext(ost->img_resample_ctx);
- if (ost->resample)
- audio_resample_close(ost->resample);
- if (ost->reformat_ctx)
- av_audio_convert_free(ost->reformat_ctx);
- av_free(ost);
+ swr_free(&ost->swr);
+ av_dict_free(&ost->opts);
}
}
- av_free(ost_table);
}
return ret;
}
-static int opt_format(const char *opt, const char *arg)
-{
- last_asked_format = arg;
- return 0;
-}
-
-static int opt_video_rc_override_string(const char *opt, const char *arg)
-{
- video_rc_override_string = arg;
- return 0;
-}
-
-static int opt_me_threshold(const char *opt, const char *arg)
-{
- me_threshold = parse_number_or_die(opt, arg, OPT_INT64, INT_MIN, INT_MAX);
- return 0;
-}
-
-static int opt_verbose(const char *opt, const char *arg)
-{
- verbose = parse_number_or_die(opt, arg, OPT_INT64, -10, 10);
- return 0;
-}
-
-static int opt_frame_rate(const char *opt, const char *arg)
-{
- if (av_parse_video_rate(&frame_rate, arg) < 0) {
- fprintf(stderr, "Incorrect value for %s: %s\n", opt, arg);
- ffmpeg_exit(1);
- }
- return 0;
-}
-
-static int opt_bitrate(const char *opt, const char *arg)
-{
- int codec_type = opt[0]=='a' ? AVMEDIA_TYPE_AUDIO : AVMEDIA_TYPE_VIDEO;
-
- opt_default(opt, arg);
-
- if (av_get_int(avcodec_opts[codec_type], "b", NULL) < 1000)
- fprintf(stderr, "WARNING: The bitrate parameter is set too low. It takes bits/s as argument, not kbits/s\n");
-
- return 0;
-}
-
static int opt_frame_crop(const char *opt, const char *arg)
{
- fprintf(stderr, "Option '%s' has been removed, use the crop filter instead\n", opt);
+ av_log(NULL, AV_LOG_FATAL, "Option '%s' has been removed, use the crop filter instead\n", opt);
return AVERROR(EINVAL);
}
-static int opt_frame_size(const char *opt, const char *arg)
+static int opt_pad(const char *opt, const char *arg)
{
- if (av_parse_video_size(&frame_width, &frame_height, arg) < 0) {
- fprintf(stderr, "Incorrect frame size\n");
- return AVERROR(EINVAL);
- }
- return 0;
-}
-
-static int opt_pad(const char *opt, const char *arg) {
- fprintf(stderr, "Option '%s' has been removed, use the pad filter instead\n", opt);
+ av_log(NULL, AV_LOG_FATAL, "Option '%s' has been removed, use the pad filter instead\n", opt);
return -1;
}
-static int opt_frame_pix_fmt(const char *opt, const char *arg)
-{
- if (strcmp(arg, "list")) {
- frame_pix_fmt = av_get_pix_fmt(arg);
- if (frame_pix_fmt == PIX_FMT_NONE) {
- fprintf(stderr, "Unknown pixel format requested: %s\n", arg);
- return AVERROR(EINVAL);
- }
- } else {
- show_pix_fmts();
- ffmpeg_exit(0);
- }
- return 0;
-}
-
-static int opt_frame_aspect_ratio(const char *opt, const char *arg)
+static double parse_frame_aspect_ratio(const char *arg)
{
int x = 0, y = 0;
double ar = 0;
@@ -2838,290 +2748,199 @@ static int opt_frame_aspect_ratio(const char *opt, const char *arg)
ar = strtod(arg, NULL);
if (!ar) {
- fprintf(stderr, "Incorrect aspect ratio specification.\n");
- return AVERROR(EINVAL);
- }
- frame_aspect_ratio = ar;
- return 0;
-}
-
-static int opt_metadata(const char *opt, const char *arg)
-{
- char *mid= strchr(arg, '=');
-
- if(!mid){
- fprintf(stderr, "Missing =\n");
- ffmpeg_exit(1);
- }
- *mid++= 0;
-
- av_dict_set(&metadata, arg, mid, 0);
-
- return 0;
-}
-
-static int opt_qscale(const char *opt, const char *arg)
-{
- video_qscale = parse_number_or_die(opt, arg, OPT_FLOAT, 0, 255);
- if (video_qscale == 0) {
- fprintf(stderr, "qscale must be > 0.0 and <= 255\n");
- return AVERROR(EINVAL);
- }
- return 0;
-}
-
-static int opt_top_field_first(const char *opt, const char *arg)
-{
- top_field_first = parse_number_or_die(opt, arg, OPT_INT, 0, 1);
- return 0;
-}
-
-static int opt_thread_count(const char *opt, const char *arg)
-{
- thread_count= parse_number_or_die(opt, arg, OPT_INT64, 0, INT_MAX);
-#if !HAVE_THREADS
- if (verbose >= 0)
- fprintf(stderr, "Warning: not compiled with thread support, using thread emulation\n");
-#endif
- return 0;
-}
-
-static int opt_audio_sample_fmt(const char *opt, const char *arg)
-{
- if (strcmp(arg, "list")) {
- audio_sample_fmt = av_get_sample_fmt(arg);
- if (audio_sample_fmt == AV_SAMPLE_FMT_NONE) {
- av_log(NULL, AV_LOG_ERROR, "Invalid sample format '%s'\n", arg);
- return AVERROR(EINVAL);
- }
- } else {
- int i;
- char fmt_str[128];
- for (i = -1; i < AV_SAMPLE_FMT_NB; i++)
- printf("%s\n", av_get_sample_fmt_string(fmt_str, sizeof(fmt_str), i));
- ffmpeg_exit(0);
+ av_log(NULL, AV_LOG_FATAL, "Incorrect aspect ratio specification.\n");
+ exit_program(1);
}
- return 0;
-}
-
-static int opt_audio_rate(const char *opt, const char *arg)
-{
- audio_sample_rate = parse_number_or_die(opt, arg, OPT_INT64, 0, INT_MAX);
- return 0;
-}
-
-static int opt_audio_channels(const char *opt, const char *arg)
-{
- audio_channels = parse_number_or_die(opt, arg, OPT_INT64, 0, INT_MAX);
- return 0;
+ return ar;
}
static int opt_video_channel(const char *opt, const char *arg)
{
av_log(NULL, AV_LOG_WARNING, "This option is deprecated, use -channel.\n");
- opt_default("channel", arg);
- return 0;
+ return opt_default("channel", arg);
}
static int opt_video_standard(const char *opt, const char *arg)
{
av_log(NULL, AV_LOG_WARNING, "This option is deprecated, use -standard.\n");
- opt_default("standard", arg);
- return 0;
+ return opt_default("standard", arg);
}
-static int opt_codec(int *pstream_copy, char **pcodec_name,
- int codec_type, const char *arg)
+static int opt_audio_codec(OptionsContext *o, const char *opt, const char *arg)
{
- av_freep(pcodec_name);
- if (!strcmp(arg, "copy")) {
- *pstream_copy = 1;
- } else {
- *pcodec_name = av_strdup(arg);
- }
- return 0;
+ audio_codec_name = arg;
+ return parse_option(o, "codec:a", arg, options);
}
-static int opt_audio_codec(const char *opt, const char *arg)
+static int opt_video_codec(OptionsContext *o, const char *opt, const char *arg)
{
- return opt_codec(&audio_stream_copy, &audio_codec_name, AVMEDIA_TYPE_AUDIO, arg);
+ video_codec_name = arg;
+ return parse_option(o, "codec:v", arg, options);
}
-static int opt_video_codec(const char *opt, const char *arg)
+static int opt_subtitle_codec(OptionsContext *o, const char *opt, const char *arg)
{
- return opt_codec(&video_stream_copy, &video_codec_name, AVMEDIA_TYPE_VIDEO, arg);
+ subtitle_codec_name = arg;
+ return parse_option(o, "codec:s", arg, options);
}
-static int opt_subtitle_codec(const char *opt, const char *arg)
+static int opt_data_codec(OptionsContext *o, const char *opt, const char *arg)
{
- return opt_codec(&subtitle_stream_copy, &subtitle_codec_name, AVMEDIA_TYPE_SUBTITLE, arg);
+ return parse_option(o, "codec:d", arg, options);
}
-static int opt_data_codec(const char *opt, const char *arg)
+static int opt_map(OptionsContext *o, const char *opt, const char *arg)
{
- return opt_codec(&data_stream_copy, &data_codec_name, AVMEDIA_TYPE_DATA, arg);
-}
-
-static int opt_codec_tag(const char *opt, const char *arg)
-{
- char *tail;
- uint32_t *codec_tag;
-
- codec_tag = !strcmp(opt, "atag") ? &audio_codec_tag :
- !strcmp(opt, "vtag") ? &video_codec_tag :
- !strcmp(opt, "stag") ? &subtitle_codec_tag : NULL;
- if (!codec_tag)
- return -1;
-
- *codec_tag = strtol(arg, &tail, 0);
- if (!tail || *tail)
- *codec_tag = AV_RL32(arg);
+ StreamMap *m = NULL;
+ int i, negative = 0, file_idx;
+ int sync_file_idx = -1, sync_stream_idx;
+ char *p, *sync;
+ char *map;
+
+ if (*arg == '-') {
+ negative = 1;
+ arg++;
+ }
+ map = av_strdup(arg);
+
+ /* parse sync stream first, just pick first matching stream */
+ if (sync = strchr(map, ',')) {
+ *sync = 0;
+ sync_file_idx = strtol(sync + 1, &sync, 0);
+ if (sync_file_idx >= nb_input_files || sync_file_idx < 0) {
+ av_log(NULL, AV_LOG_FATAL, "Invalid sync file index: %d.\n", sync_file_idx);
+ exit_program(1);
+ }
+ if (*sync)
+ sync++;
+ for (i = 0; i < input_files[sync_file_idx].nb_streams; i++)
+ if (check_stream_specifier(input_files[sync_file_idx].ctx,
+ input_files[sync_file_idx].ctx->streams[i], sync) == 1) {
+ sync_stream_idx = i;
+ break;
+ }
+ if (i == input_files[sync_file_idx].nb_streams) {
+ av_log(NULL, AV_LOG_FATAL, "Sync stream specification in map %s does not "
+ "match any streams.\n", arg);
+ exit_program(1);
+ }
+ }
- return 0;
-}
-static int opt_map(const char *opt, const char *arg)
-{
- AVStreamMap *m;
- char *p;
+ file_idx = strtol(map, &p, 0);
+ if (file_idx >= nb_input_files || file_idx < 0) {
+ av_log(NULL, AV_LOG_FATAL, "Invalid input file index: %d.\n", file_idx);
+ exit_program(1);
+ }
+ if (negative)
+ /* disable some already defined maps */
+ for (i = 0; i < o->nb_stream_maps; i++) {
+ m = &o->stream_maps[i];
+ if (check_stream_specifier(input_files[m->file_index].ctx,
+ input_files[m->file_index].ctx->streams[m->stream_index],
+ *p == ':' ? p + 1 : p) > 0)
+ m->disabled = 1;
+ }
+ else
+ for (i = 0; i < input_files[file_idx].nb_streams; i++) {
+ if (check_stream_specifier(input_files[file_idx].ctx, input_files[file_idx].ctx->streams[i],
+ *p == ':' ? p + 1 : p) <= 0)
+ continue;
+ o->stream_maps = grow_array(o->stream_maps, sizeof(*o->stream_maps),
+ &o->nb_stream_maps, o->nb_stream_maps + 1);
+ m = &o->stream_maps[o->nb_stream_maps - 1];
- stream_maps = grow_array(stream_maps, sizeof(*stream_maps), &nb_stream_maps, nb_stream_maps + 1);
- m = &stream_maps[nb_stream_maps-1];
+ m->file_index = file_idx;
+ m->stream_index = i;
- m->file_index = strtol(arg, &p, 0);
- if (*p)
- p++;
+ if (sync_file_idx >= 0) {
+ m->sync_file_index = sync_file_idx;
+ m->sync_stream_index = sync_stream_idx;
+ } else {
+ m->sync_file_index = file_idx;
+ m->sync_stream_index = i;
+ }
+ }
- m->stream_index = strtol(p, &p, 0);
- if (*p) {
- p++;
- m->sync_file_index = strtol(p, &p, 0);
- if (*p)
- p++;
- m->sync_stream_index = strtol(p, &p, 0);
- } else {
- m->sync_file_index = m->file_index;
- m->sync_stream_index = m->stream_index;
+ if (!m) {
+ av_log(NULL, AV_LOG_FATAL, "Stream map '%s' matches no streams.\n", arg);
+ exit_program(1);
}
+
+ av_freep(&map);
return 0;
}
-static void parse_meta_type(char *arg, char *type, int *index, char **endptr)
+static void parse_meta_type(char *arg, char *type, int *index)
{
- *endptr = arg;
- if (*arg == ',') {
- *type = *(++arg);
+ if (*arg) {
+ *type = *arg;
switch (*arg) {
case 'g':
break;
case 's':
case 'c':
case 'p':
- *index = strtol(++arg, endptr, 0);
+ if (*(++arg) == ':')
+ *index = strtol(++arg, NULL, 0);
break;
default:
- fprintf(stderr, "Invalid metadata type %c.\n", *arg);
- ffmpeg_exit(1);
+ av_log(NULL, AV_LOG_FATAL, "Invalid metadata type %c.\n", *arg);
+ exit_program(1);
}
} else
*type = 'g';
}
-static int opt_map_metadata(const char *opt, const char *arg)
+static int opt_map_metadata(OptionsContext *o, const char *opt, const char *arg)
{
- AVMetaDataMap *m, *m1;
+ MetadataMap *m, *m1;
char *p;
- meta_data_maps = grow_array(meta_data_maps, sizeof(*meta_data_maps),
- &nb_meta_data_maps, nb_meta_data_maps + 1);
+ o->meta_data_maps = grow_array(o->meta_data_maps, sizeof(*o->meta_data_maps),
+ &o->nb_meta_data_maps, o->nb_meta_data_maps + 1);
- m = &meta_data_maps[nb_meta_data_maps - 1][0];
+ m = &o->meta_data_maps[o->nb_meta_data_maps - 1][1];
m->file = strtol(arg, &p, 0);
- parse_meta_type(p, &m->type, &m->index, &p);
- if (*p)
- p++;
+ parse_meta_type(*p ? p + 1 : p, &m->type, &m->index);
- m1 = &meta_data_maps[nb_meta_data_maps - 1][1];
- m1->file = strtol(p, &p, 0);
- parse_meta_type(p, &m1->type, &m1->index, &p);
+ m1 = &o->meta_data_maps[o->nb_meta_data_maps - 1][0];
+ if (p = strchr(opt, ':'))
+ parse_meta_type(p + 1, &m1->type, &m1->index);
+ else
+ m1->type = 'g';
if (m->type == 'g' || m1->type == 'g')
- metadata_global_autocopy = 0;
+ o->metadata_global_manual = 1;
if (m->type == 's' || m1->type == 's')
- metadata_streams_autocopy = 0;
+ o->metadata_streams_manual = 1;
if (m->type == 'c' || m1->type == 'c')
- metadata_chapters_autocopy = 0;
+ o->metadata_chapters_manual = 1;
return 0;
}
-static int opt_map_meta_data(const char *opt, const char *arg)
+static int opt_map_meta_data(OptionsContext *o, const char *opt, const char *arg)
{
- fprintf(stderr, "-map_meta_data is deprecated and will be removed soon. "
+ av_log(NULL, AV_LOG_WARNING, "-map_meta_data is deprecated and will be removed soon. "
"Use -map_metadata instead.\n");
- return opt_map_metadata(opt, arg);
+ return opt_map_metadata(o, opt, arg);
}
-static int opt_map_chapters(const char *opt, const char *arg)
+static int opt_recording_timestamp(OptionsContext *o, const char *opt, const char *arg)
{
- AVChapterMap *c;
- char *p;
-
- chapter_maps = grow_array(chapter_maps, sizeof(*chapter_maps), &nb_chapter_maps,
- nb_chapter_maps + 1);
- c = &chapter_maps[nb_chapter_maps - 1];
- c->out_file = strtol(arg, &p, 0);
- if (*p)
- p++;
-
- c->in_file = strtol(p, &p, 0);
- return 0;
-}
-
-static int opt_input_ts_scale(const char *opt, const char *arg)
-{
- unsigned int stream;
- double scale;
- char *p;
-
- stream = strtol(arg, &p, 0);
- if (*p)
- p++;
- scale= strtod(p, &p);
-
- if(stream >= MAX_STREAMS)
- ffmpeg_exit(1);
-
- input_files_ts_scale[nb_input_files] = grow_array(input_files_ts_scale[nb_input_files], sizeof(*input_files_ts_scale[nb_input_files]), &nb_input_files_ts_scale[nb_input_files], stream + 1);
- input_files_ts_scale[nb_input_files][stream]= scale;
- return 0;
-}
-
-static int opt_recording_time(const char *opt, const char *arg)
-{
- recording_time = parse_time_or_die(opt, arg, 1);
- return 0;
-}
-
-static int opt_start_time(const char *opt, const char *arg)
-{
- start_time = parse_time_or_die(opt, arg, 1);
- return 0;
-}
-
-static int opt_recording_timestamp(const char *opt, const char *arg)
-{
- recording_timestamp = parse_time_or_die(opt, arg, 0) / 1000000;
- return 0;
-}
-
-static int opt_input_ts_offset(const char *opt, const char *arg)
-{
- input_ts_offset = parse_time_or_die(opt, arg, 1);
+ char buf[128];
+ int64_t recording_timestamp = parse_time_or_die(opt, arg, 0) / 1E6;
+ struct tm time = *gmtime((time_t*)&recording_timestamp);
+ strftime(buf, sizeof(buf), "creation_time=%FT%T%z", &time);
+ parse_option(o, "metadata", buf, options);
+
+ av_log(NULL, AV_LOG_WARNING, "%s is deprecated, set the 'creation_time' metadata "
+ "tag instead.\n", opt);
return 0;
}
-static enum CodecID find_codec_or_die(const char *name, int type, int encoder, int strict)
+static enum CodecID find_codec_or_die(const char *name, enum AVMediaType type, int encoder)
{
const char *codec_string = encoder ? "encoder" : "decoder";
AVCodec *codec;
@@ -3132,43 +2951,135 @@ static enum CodecID find_codec_or_die(const char *name, int type, int encoder, i
avcodec_find_encoder_by_name(name) :
avcodec_find_decoder_by_name(name);
if(!codec) {
- fprintf(stderr, "Unknown %s '%s'\n", codec_string, name);
- ffmpeg_exit(1);
+ av_log(NULL, AV_LOG_FATAL, "Unknown %s '%s'\n", codec_string, name);
+ exit_program(1);
}
if(codec->type != type) {
- fprintf(stderr, "Invalid %s type '%s'\n", codec_string, name);
- ffmpeg_exit(1);
- }
- if(codec->capabilities & CODEC_CAP_EXPERIMENTAL &&
- strict > FF_COMPLIANCE_EXPERIMENTAL) {
- fprintf(stderr, "%s '%s' is experimental and might produce bad "
- "results.\nAdd '-strict experimental' if you want to use it.\n",
- codec_string, codec->name);
- codec = encoder ?
- avcodec_find_encoder(codec->id) :
- avcodec_find_decoder(codec->id);
- if (!(codec->capabilities & CODEC_CAP_EXPERIMENTAL))
- fprintf(stderr, "Or use the non experimental %s '%s'.\n",
- codec_string, codec->name);
- ffmpeg_exit(1);
+ av_log(NULL, AV_LOG_FATAL, "Invalid %s type '%s'\n", codec_string, name);
+ exit_program(1);
}
return codec->id;
}
-static int opt_input_file(const char *opt, const char *filename)
+static AVCodec *choose_codec(OptionsContext *o, AVFormatContext *s, AVStream *st, enum AVMediaType type)
+{
+ char *codec_name = NULL;
+
+ MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, st);
+
+ if (!codec_name) {
+ if (s->oformat) {
+ st->codec->codec_id = av_guess_codec(s->oformat, NULL, s->filename, NULL, type);
+ return avcodec_find_encoder(st->codec->codec_id);
+ }
+ } else if (!strcmp(codec_name, "copy"))
+ st->stream_copy = 1;
+ else {
+ st->codec->codec_id = find_codec_or_die(codec_name, type, s->iformat == NULL);
+ return s->oformat ? avcodec_find_encoder_by_name(codec_name) :
+ avcodec_find_decoder_by_name(codec_name);
+ }
+
+ return NULL;
+}
+
+/**
+ * Add all the streams from the given input file to the global
+ * list of input streams.
+ */
+static void add_input_streams(OptionsContext *o, AVFormatContext *ic)
+{
+ int i, rfps, rfps_base;
+ char *next, *codec_tag = NULL;
+
+ for (i = 0; i < ic->nb_streams; i++) {
+ AVStream *st = ic->streams[i];
+ AVCodecContext *dec = st->codec;
+ InputStream *ist;
+ double scale = 1.0;
+
+ input_streams = grow_array(input_streams, sizeof(*input_streams), &nb_input_streams, nb_input_streams + 1);
+ ist = &input_streams[nb_input_streams - 1];
+ ist->st = st;
+ ist->file_index = nb_input_files;
+ ist->discard = 1;
+ ist->opts = filter_codec_opts(codec_opts, ist->st->codec->codec_id, ic, st);
+
+ MATCH_PER_STREAM_OPT(ts_scale, dbl, scale, ic, st);
+ ist->ts_scale = scale;
+
+ MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, ic, st);
+ if (codec_tag) {
+ uint32_t tag = strtol(codec_tag, &next, 0);
+ if (*next)
+ tag = AV_RL32(codec_tag);
+ st->codec->codec_tag = tag;
+ }
+
+ ist->dec = choose_codec(o, ic, st, dec->codec_type);
+ if (!ist->dec)
+ ist->dec = avcodec_find_decoder(dec->codec_id);
+
+ switch (dec->codec_type) {
+ case AVMEDIA_TYPE_AUDIO:
+ if(!ist->dec)
+ ist->dec = avcodec_find_decoder(dec->codec_id);
+ if(o->audio_disable)
+ st->discard= AVDISCARD_ALL;
+ break;
+ case AVMEDIA_TYPE_VIDEO:
+ if(!ist->dec)
+ ist->dec = avcodec_find_decoder(dec->codec_id);
+ rfps = ic->streams[i]->r_frame_rate.num;
+ rfps_base = ic->streams[i]->r_frame_rate.den;
+ if (dec->lowres) {
+ dec->flags |= CODEC_FLAG_EMU_EDGE;
+ }
+
+ if (dec->time_base.den != rfps*dec->ticks_per_frame || dec->time_base.num != rfps_base) {
+
+ av_log(NULL, AV_LOG_INFO,"\nSeems stream %d codec frame rate differs from container frame rate: %2.2f (%d/%d) -> %2.2f (%d/%d)\n",
+ i, (float)dec->time_base.den / dec->time_base.num, dec->time_base.den, dec->time_base.num,
+ (float)rfps / rfps_base, rfps, rfps_base);
+ }
+
+ if (o->video_disable)
+ st->discard= AVDISCARD_ALL;
+ else if(video_discard)
+ st->discard= video_discard;
+ break;
+ case AVMEDIA_TYPE_DATA:
+ break;
+ case AVMEDIA_TYPE_SUBTITLE:
+ if(!ist->dec)
+ ist->dec = avcodec_find_decoder(dec->codec_id);
+ if(o->subtitle_disable)
+ st->discard = AVDISCARD_ALL;
+ break;
+ case AVMEDIA_TYPE_ATTACHMENT:
+ case AVMEDIA_TYPE_UNKNOWN:
+ break;
+ default:
+ abort();
+ }
+ }
+}
+
+static int opt_input_file(OptionsContext *o, const char *opt, const char *filename)
{
AVFormatContext *ic;
AVInputFormat *file_iformat = NULL;
- int err, i, ret, rfps, rfps_base;
+ int err, i, ret;
int64_t timestamp;
uint8_t buf[128];
+ AVDictionary **opts;
+ int orig_nb_streams; // number of streams before avformat_find_stream_info
- if (last_asked_format) {
- if (!(file_iformat = av_find_input_format(last_asked_format))) {
- fprintf(stderr, "Unknown input format: '%s'\n", last_asked_format);
- ffmpeg_exit(1);
+ if (o->format) {
+ if (!(file_iformat = av_find_input_format(o->format))) {
+ av_log(NULL, AV_LOG_FATAL, "Unknown input format: '%s'\n", o->format);
+ exit_program(1);
}
- last_asked_format = NULL;
}
if (!strcmp(filename, "-"))
@@ -3181,337 +3092,350 @@ static int opt_input_file(const char *opt, const char *filename)
ic = avformat_alloc_context();
if (!ic) {
print_error(filename, AVERROR(ENOMEM));
- ffmpeg_exit(1);
+ exit_program(1);
}
- if (audio_sample_rate) {
- snprintf(buf, sizeof(buf), "%d", audio_sample_rate);
+ if (o->nb_audio_sample_rate) {
+ snprintf(buf, sizeof(buf), "%d", o->audio_sample_rate[o->nb_audio_sample_rate - 1].u.i);
av_dict_set(&format_opts, "sample_rate", buf, 0);
}
- if (audio_channels) {
- snprintf(buf, sizeof(buf), "%d", audio_channels);
+ if (o->nb_audio_channels) {
+ snprintf(buf, sizeof(buf), "%d", o->audio_channels[o->nb_audio_channels - 1].u.i);
av_dict_set(&format_opts, "channels", buf, 0);
}
- if (frame_rate.num) {
- snprintf(buf, sizeof(buf), "%d/%d", frame_rate.num, frame_rate.den);
- av_dict_set(&format_opts, "framerate", buf, 0);
+ if (o->nb_frame_rates) {
+ av_dict_set(&format_opts, "framerate", o->frame_rates[o->nb_frame_rates - 1].u.str, 0);
}
- if (frame_width && frame_height) {
- snprintf(buf, sizeof(buf), "%dx%d", frame_width, frame_height);
- av_dict_set(&format_opts, "video_size", buf, 0);
+ if (o->nb_frame_sizes) {
+ av_dict_set(&format_opts, "video_size", o->frame_sizes[o->nb_frame_sizes - 1].u.str, 0);
}
- if (frame_pix_fmt != PIX_FMT_NONE)
- av_dict_set(&format_opts, "pixel_format", av_get_pix_fmt_name(frame_pix_fmt), 0);
+ if (o->nb_frame_pix_fmts)
+ av_dict_set(&format_opts, "pixel_format", o->frame_pix_fmts[o->nb_frame_pix_fmts - 1].u.str, 0);
ic->video_codec_id =
- find_codec_or_die(video_codec_name , AVMEDIA_TYPE_VIDEO , 0,
- avcodec_opts[AVMEDIA_TYPE_VIDEO ]->strict_std_compliance);
+ find_codec_or_die(video_codec_name , AVMEDIA_TYPE_VIDEO , 0);
ic->audio_codec_id =
- find_codec_or_die(audio_codec_name , AVMEDIA_TYPE_AUDIO , 0,
- avcodec_opts[AVMEDIA_TYPE_AUDIO ]->strict_std_compliance);
+ find_codec_or_die(audio_codec_name , AVMEDIA_TYPE_AUDIO , 0);
ic->subtitle_codec_id=
- find_codec_or_die(subtitle_codec_name, AVMEDIA_TYPE_SUBTITLE, 0,
- avcodec_opts[AVMEDIA_TYPE_SUBTITLE]->strict_std_compliance);
+ find_codec_or_die(subtitle_codec_name, AVMEDIA_TYPE_SUBTITLE, 0);
ic->flags |= AVFMT_FLAG_NONBLOCK;
+ if (loop_input) {
+ av_log(NULL, AV_LOG_WARNING, "-loop_input is deprecated, use -loop 1\n");
+ ic->loop_input = loop_input;
+ }
+
/* open the input file with generic libav function */
err = avformat_open_input(&ic, filename, file_iformat, &format_opts);
if (err < 0) {
print_error(filename, err);
- ffmpeg_exit(1);
+ exit_program(1);
}
assert_avoptions(format_opts);
- if(opt_programid) {
- int i, j;
- int found=0;
- for(i=0; i<ic->nb_streams; i++){
- ic->streams[i]->discard= AVDISCARD_ALL;
- }
- for(i=0; i<ic->nb_programs; i++){
- AVProgram *p= ic->programs[i];
- if(p->id != opt_programid){
- p->discard = AVDISCARD_ALL;
- }else{
- found=1;
- for(j=0; j<p->nb_stream_indexes; j++){
- ic->streams[p->stream_index[j]]->discard= AVDISCARD_DEFAULT;
- }
- }
- }
- if(!found){
- fprintf(stderr, "Specified program id not found\n");
- ffmpeg_exit(1);
- }
- opt_programid=0;
- }
+ /* apply forced codec ids */
+ for (i = 0; i < ic->nb_streams; i++)
+ choose_codec(o, ic, ic->streams[i], ic->streams[i]->codec->codec_type);
- ic->loop_input = loop_input;
-
- /* Set AVCodecContext options so they will be seen by av_find_stream_info() */
- for (i = 0; i < ic->nb_streams; i++) {
- AVCodecContext *dec = ic->streams[i]->codec;
- switch (dec->codec_type) {
- case AVMEDIA_TYPE_AUDIO:
- set_context_opts(dec, avcodec_opts[AVMEDIA_TYPE_AUDIO],
- AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_DECODING_PARAM,
- NULL);
- break;
- case AVMEDIA_TYPE_VIDEO:
- set_context_opts(dec, avcodec_opts[AVMEDIA_TYPE_VIDEO],
- AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM,
- NULL);
- break;
- }
- }
+ /* Set AVCodecContext options for avformat_find_stream_info */
+ opts = setup_find_stream_info_opts(ic, codec_opts);
+ orig_nb_streams = ic->nb_streams;
/* If not enough info to get the stream parameters, we decode the
first frames to get it. (used in mpeg case for example) */
- ret = av_find_stream_info(ic);
- if (ret < 0 && verbose >= 0) {
- fprintf(stderr, "%s: could not find codec parameters\n", filename);
+ ret = avformat_find_stream_info(ic, opts);
+ if (ret < 0) {
+ av_log(NULL, AV_LOG_FATAL, "%s: could not find codec parameters\n", filename);
av_close_input_file(ic);
- ffmpeg_exit(1);
+ exit_program(1);
}
- timestamp = start_time;
+ timestamp = o->start_time;
/* add the stream start time */
if (ic->start_time != AV_NOPTS_VALUE)
timestamp += ic->start_time;
/* if seeking requested, we execute it */
- if (start_time != 0) {
+ if (o->start_time != 0) {
ret = av_seek_frame(ic, -1, timestamp, AVSEEK_FLAG_BACKWARD);
if (ret < 0) {
- fprintf(stderr, "%s: could not seek to position %0.3f\n",
- filename, (double)timestamp / AV_TIME_BASE);
+ av_log(NULL, AV_LOG_WARNING, "%s: could not seek to position %0.3f\n",
+ filename, (double)timestamp / AV_TIME_BASE);
}
- /* reset seek info */
- start_time = 0;
}
/* update the current parameters so that they match the one of the input stream */
- for(i=0;i<ic->nb_streams;i++) {
- AVStream *st = ic->streams[i];
- AVCodecContext *dec = st->codec;
- AVInputStream *ist;
-
- dec->thread_count = thread_count;
- input_codecs = grow_array(input_codecs, sizeof(*input_codecs), &nb_input_codecs, nb_input_codecs + 1);
+ add_input_streams(o, ic);
- input_streams = grow_array(input_streams, sizeof(*input_streams), &nb_input_streams, nb_input_streams + 1);
- ist = &input_streams[nb_input_streams - 1];
- ist->st = st;
- ist->file_index = nb_input_files;
- ist->discard = 1;
-
- switch (dec->codec_type) {
- case AVMEDIA_TYPE_AUDIO:
- input_codecs[nb_input_codecs-1] = avcodec_find_decoder_by_name(audio_codec_name);
- set_context_opts(dec, avcodec_opts[AVMEDIA_TYPE_AUDIO], AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_DECODING_PARAM, input_codecs[nb_input_codecs-1]);
- channel_layout = dec->channel_layout;
- audio_sample_fmt = dec->sample_fmt;
- if(audio_disable)
- st->discard= AVDISCARD_ALL;
- break;
- case AVMEDIA_TYPE_VIDEO:
- input_codecs[nb_input_codecs-1] = avcodec_find_decoder_by_name(video_codec_name);
- set_context_opts(dec, avcodec_opts[AVMEDIA_TYPE_VIDEO], AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM, input_codecs[nb_input_codecs-1]);
- rfps = ic->streams[i]->r_frame_rate.num;
- rfps_base = ic->streams[i]->r_frame_rate.den;
- if (dec->lowres) {
- dec->flags |= CODEC_FLAG_EMU_EDGE;
- dec->height >>= dec->lowres;
- dec->width >>= dec->lowres;
- }
- if(me_threshold)
- dec->debug |= FF_DEBUG_MV;
-
- if (dec->time_base.den != rfps*dec->ticks_per_frame || dec->time_base.num != rfps_base) {
-
- if (verbose >= 0)
- fprintf(stderr,"\nSeems stream %d codec frame rate differs from container frame rate: %2.2f (%d/%d) -> %2.2f (%d/%d)\n",
- i, (float)dec->time_base.den / dec->time_base.num, dec->time_base.den, dec->time_base.num,
-
- (float)rfps / rfps_base, rfps, rfps_base);
- }
-
- if(video_disable)
- st->discard= AVDISCARD_ALL;
- else if(video_discard)
- st->discard= video_discard;
- break;
- case AVMEDIA_TYPE_DATA:
- break;
- case AVMEDIA_TYPE_SUBTITLE:
- input_codecs[nb_input_codecs-1] = avcodec_find_decoder_by_name(subtitle_codec_name);
- if(subtitle_disable)
- st->discard = AVDISCARD_ALL;
- break;
- case AVMEDIA_TYPE_ATTACHMENT:
- case AVMEDIA_TYPE_UNKNOWN:
- break;
- default:
- abort();
- }
- }
-
- input_files_ts_offset[nb_input_files] = input_ts_offset - (copy_ts ? 0 : timestamp);
/* dump the file content */
- if (verbose >= 0)
- av_dump_format(ic, nb_input_files, filename, 0);
+ av_dump_format(ic, nb_input_files, filename, 0);
input_files = grow_array(input_files, sizeof(*input_files), &nb_input_files, nb_input_files + 1);
input_files[nb_input_files - 1].ctx = ic;
input_files[nb_input_files - 1].ist_index = nb_input_streams - ic->nb_streams;
+ input_files[nb_input_files - 1].ts_offset = o->input_ts_offset - (copy_ts ? 0 : timestamp);
+ input_files[nb_input_files - 1].nb_streams = ic->nb_streams;
+ input_files[nb_input_files - 1].rate_emu = o->rate_emu;
- frame_rate = (AVRational){0, 0};
- frame_pix_fmt = PIX_FMT_NONE;
- frame_height = 0;
- frame_width = 0;
- audio_sample_rate = 0;
- audio_channels = 0;
+ for (i = 0; i < orig_nb_streams; i++)
+ av_dict_free(&opts[i]);
+ av_freep(&opts);
- av_freep(&video_codec_name);
- av_freep(&audio_codec_name);
- av_freep(&subtitle_codec_name);
- uninit_opts();
- init_opts();
+ reset_options(o, 1);
return 0;
}
-static void check_inputs(int *has_video_ptr,
- int *has_audio_ptr,
- int *has_subtitle_ptr,
- int *has_data_ptr)
+static void parse_forced_key_frames(char *kf, OutputStream *ost)
{
- int has_video, has_audio, has_subtitle, has_data, i, j;
- AVFormatContext *ic;
+ char *p;
+ int n = 1, i;
- has_video = 0;
- has_audio = 0;
- has_subtitle = 0;
- has_data = 0;
+ for (p = kf; *p; p++)
+ if (*p == ',')
+ n++;
+ ost->forced_kf_count = n;
+ ost->forced_kf_pts = av_malloc(sizeof(*ost->forced_kf_pts) * n);
+ if (!ost->forced_kf_pts) {
+ av_log(NULL, AV_LOG_FATAL, "Could not allocate forced key frames array.\n");
+ exit_program(1);
+ }
+ for (i = 0; i < n; i++) {
+ p = i ? strchr(p, ',') + 1 : kf;
+ ost->forced_kf_pts[i] = parse_time_or_die("force_key_frames", p, 1);
+ }
+}
- for(j=0;j<nb_input_files;j++) {
- ic = input_files[j].ctx;
- for(i=0;i<ic->nb_streams;i++) {
- AVCodecContext *enc = ic->streams[i]->codec;
- switch(enc->codec_type) {
- case AVMEDIA_TYPE_AUDIO:
- has_audio = 1;
- break;
- case AVMEDIA_TYPE_VIDEO:
- has_video = 1;
- break;
- case AVMEDIA_TYPE_SUBTITLE:
- has_subtitle = 1;
- break;
- case AVMEDIA_TYPE_DATA:
- case AVMEDIA_TYPE_ATTACHMENT:
- case AVMEDIA_TYPE_UNKNOWN:
- has_data = 1;
- break;
- default:
- abort();
- }
+static uint8_t *get_line(AVIOContext *s)
+{
+ AVIOContext *line;
+ uint8_t *buf;
+ char c;
+
+ if (avio_open_dyn_buf(&line) < 0) {
+ av_log(NULL, AV_LOG_FATAL, "Could not alloc buffer for reading preset.\n");
+ exit_program(1);
+ }
+
+ while ((c = avio_r8(s)) && c != '\n')
+ avio_w8(line, c);
+ avio_w8(line, 0);
+ avio_close_dyn_buf(line, &buf);
+
+ return buf;
+}
+
+static int get_preset_file_2(const char *preset_name, const char *codec_name, AVIOContext **s)
+{
+ int i, ret = 1;
+ char filename[1000];
+ const char *base[3] = { getenv("AVCONV_DATADIR"),
+ getenv("HOME"),
+ AVCONV_DATADIR,
+ };
+
+ for (i = 0; i < FF_ARRAY_ELEMS(base) && ret; i++) {
+ if (!base[i])
+ continue;
+ if (codec_name) {
+ snprintf(filename, sizeof(filename), "%s%s/%s-%s.avpreset", base[i],
+ i != 1 ? "" : "/.avconv", codec_name, preset_name);
+ ret = avio_open(s, filename, AVIO_FLAG_READ);
+ }
+ if (ret) {
+ snprintf(filename, sizeof(filename), "%s%s/%s.avpreset", base[i],
+ i != 1 ? "" : "/.avconv", preset_name);
+ ret = avio_open(s, filename, AVIO_FLAG_READ);
}
}
- *has_video_ptr = has_video;
- *has_audio_ptr = has_audio;
- *has_subtitle_ptr = has_subtitle;
- *has_data_ptr = has_data;
+ return ret;
}
-static void new_video_stream(AVFormatContext *oc, int file_idx)
+static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, enum AVMediaType type)
{
- AVStream *st;
- AVOutputStream *ost;
- AVCodecContext *video_enc;
- enum CodecID codec_id = CODEC_ID_NONE;
- AVCodec *codec= NULL;
+ OutputStream *ost;
+ AVStream *st = avformat_new_stream(oc, NULL);
+ int idx = oc->nb_streams - 1, ret = 0;
+ int64_t max_frames = INT64_MAX;
+ char *bsf = NULL, *next, *codec_tag = NULL;
+ AVBitStreamFilterContext *bsfc, *bsfc_prev = NULL;
+ double qscale = -1;
+ char *buf = NULL, *arg = NULL, *preset = NULL;
+ AVIOContext *s = NULL;
- st = av_new_stream(oc, oc->nb_streams < nb_streamid_map ? streamid_map[oc->nb_streams] : 0);
if (!st) {
- fprintf(stderr, "Could not alloc stream\n");
- ffmpeg_exit(1);
+ av_log(NULL, AV_LOG_FATAL, "Could not alloc stream.\n");
+ exit_program(1);
}
- ost = new_output_stream(oc, file_idx);
-
- if(!video_stream_copy){
- if (video_codec_name) {
- codec_id = find_codec_or_die(video_codec_name, AVMEDIA_TYPE_VIDEO, 1,
- avcodec_opts[AVMEDIA_TYPE_VIDEO]->strict_std_compliance);
- codec = avcodec_find_encoder_by_name(video_codec_name);
- ost->enc = codec;
- } else {
- codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, AVMEDIA_TYPE_VIDEO);
- codec = avcodec_find_encoder(codec_id);
+
+ if (oc->nb_streams - 1 < o->nb_streamid_map)
+ st->id = o->streamid_map[oc->nb_streams - 1];
+
+ output_streams = grow_array(output_streams, sizeof(*output_streams), &nb_output_streams,
+ nb_output_streams + 1);
+ ost = &output_streams[nb_output_streams - 1];
+ ost->file_index = nb_output_files;
+ ost->index = idx;
+ ost->st = st;
+ st->codec->codec_type = type;
+ ost->enc = choose_codec(o, oc, st, type);
+ if (ost->enc) {
+ ost->opts = filter_codec_opts(codec_opts, ost->enc->id, oc, st);
+ }
+
+ avcodec_get_context_defaults3(st->codec, ost->enc);
+ st->codec->codec_type = type; // XXX hack, avcodec_get_context_defaults2() sets type to unknown for stream copy
+
+ MATCH_PER_STREAM_OPT(presets, str, preset, oc, st);
+ if (preset && (!(ret = get_preset_file_2(preset, ost->enc->name, &s)))) {
+ do {
+ buf = get_line(s);
+ if (!buf[0] || buf[0] == '#') {
+ av_free(buf);
+ continue;
+ }
+ if (!(arg = strchr(buf, '='))) {
+ av_log(NULL, AV_LOG_FATAL, "Invalid line found in the preset file.\n");
+ exit_program(1);
+ }
+ *arg++ = 0;
+ av_dict_set(&ost->opts, buf, arg, AV_DICT_DONT_OVERWRITE);
+ av_free(buf);
+ } while (!s->eof_reached);
+ avio_close(s);
+ }
+ if (ret) {
+ av_log(NULL, AV_LOG_FATAL,
+ "Preset %s specified for stream %d:%d, but could not be opened.\n",
+ preset, ost->file_index, ost->index);
+ exit_program(1);
+ }
+
+ MATCH_PER_STREAM_OPT(max_frames, i64, max_frames, oc, st);
+ ost->max_frames = max_frames;
+
+ MATCH_PER_STREAM_OPT(bitstream_filters, str, bsf, oc, st);
+ while (bsf) {
+ if (next = strchr(bsf, ','))
+ *next++ = 0;
+ if (!(bsfc = av_bitstream_filter_init(bsf))) {
+ av_log(NULL, AV_LOG_FATAL, "Unknown bitstream filter %s\n", bsf);
+ exit_program(1);
}
+ if (bsfc_prev)
+ bsfc_prev->next = bsfc;
+ else
+ ost->bitstream_filters = bsfc;
- ost->frame_aspect_ratio = frame_aspect_ratio;
- frame_aspect_ratio = 0;
-#if CONFIG_AVFILTER
- ost->avfilter= vfilters;
- vfilters = NULL;
-#endif
+ bsfc_prev = bsfc;
+ bsf = next;
}
- avcodec_get_context_defaults3(st->codec, codec);
- ost->bitstream_filters = video_bitstream_filters;
- video_bitstream_filters= NULL;
+ MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, oc, st);
+ if (codec_tag) {
+ uint32_t tag = strtol(codec_tag, &next, 0);
+ if (*next)
+ tag = AV_RL32(codec_tag);
+ st->codec->codec_tag = tag;
+ }
- st->codec->thread_count= thread_count;
+ MATCH_PER_STREAM_OPT(qscale, dbl, qscale, oc, st);
+ if (qscale >= 0 || same_quant) {
+ st->codec->flags |= CODEC_FLAG_QSCALE;
+ st->codec->global_quality = FF_QP2LAMBDA * qscale;
+ }
- video_enc = st->codec;
+ if (oc->oformat->flags & AVFMT_GLOBALHEADER)
+ st->codec->flags |= CODEC_FLAG_GLOBAL_HEADER;
- if(video_codec_tag)
- video_enc->codec_tag= video_codec_tag;
+ av_opt_get_int(sws_opts, "sws_flags", 0, &ost->sws_flags);
+ return ost;
+}
- if(oc->oformat->flags & AVFMT_GLOBALHEADER) {
- video_enc->flags |= CODEC_FLAG_GLOBAL_HEADER;
- avcodec_opts[AVMEDIA_TYPE_VIDEO]->flags|= CODEC_FLAG_GLOBAL_HEADER;
+static void parse_matrix_coeffs(uint16_t *dest, const char *str)
+{
+ int i;
+ const char *p = str;
+ for(i = 0;; i++) {
+ dest[i] = atoi(p);
+ if(i == 63)
+ break;
+ p = strchr(p, ',');
+ if(!p) {
+ av_log(NULL, AV_LOG_FATAL, "Syntax error in matrix \"%s\" at coeff %d\n", str, i);
+ exit_program(1);
+ }
+ p++;
}
+}
- if (video_stream_copy) {
- st->stream_copy = 1;
- video_enc->codec_type = AVMEDIA_TYPE_VIDEO;
- video_enc->sample_aspect_ratio =
- st->sample_aspect_ratio = av_d2q(frame_aspect_ratio*frame_height/frame_width, 255);
- } else {
- const char *p;
- int i;
+static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc)
+{
+ AVStream *st;
+ OutputStream *ost;
+ AVCodecContext *video_enc;
- if (frame_rate.num)
- ost->frame_rate = frame_rate;
- video_enc->codec_id = codec_id;
- set_context_opts(video_enc, avcodec_opts[AVMEDIA_TYPE_VIDEO], AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM, codec);
+ ost = new_output_stream(o, oc, AVMEDIA_TYPE_VIDEO);
+ st = ost->st;
+ video_enc = st->codec;
+
+ if (!st->stream_copy) {
+ const char *p = NULL;
+ char *forced_key_frames = NULL, *frame_rate = NULL, *frame_size = NULL;
+ char *frame_aspect_ratio = NULL, *frame_pix_fmt = NULL;
+ char *intra_matrix = NULL, *inter_matrix = NULL, *filters = NULL;
+ int i, force_fps = 0, top_field_first = -1;
+
+ MATCH_PER_STREAM_OPT(frame_rates, str, frame_rate, oc, st);
+ if (frame_rate && av_parse_video_rate(&ost->frame_rate, frame_rate) < 0) {
+ av_log(NULL, AV_LOG_FATAL, "Invalid framerate value: %s\n", frame_rate);
+ exit_program(1);
+ }
+
+ MATCH_PER_STREAM_OPT(frame_sizes, str, frame_size, oc, st);
+ if (frame_size && av_parse_video_size(&video_enc->width, &video_enc->height, frame_size) < 0) {
+ av_log(NULL, AV_LOG_FATAL, "Invalid frame size: %s.\n", frame_size);
+ exit_program(1);
+ }
- video_enc->width = frame_width;
- video_enc->height = frame_height;
- video_enc->pix_fmt = frame_pix_fmt;
+ MATCH_PER_STREAM_OPT(frame_aspect_ratios, str, frame_aspect_ratio, oc, st);
+ if (frame_aspect_ratio)
+ ost->frame_aspect_ratio = parse_frame_aspect_ratio(frame_aspect_ratio);
+
+ video_enc->bits_per_raw_sample = frame_bits_per_raw_sample;
+ MATCH_PER_STREAM_OPT(frame_pix_fmts, str, frame_pix_fmt, oc, st);
+ if (frame_pix_fmt && (video_enc->pix_fmt = av_get_pix_fmt(frame_pix_fmt)) == PIX_FMT_NONE) {
+ av_log(NULL, AV_LOG_FATAL, "Unknown pixel format requested: %s.\n", frame_pix_fmt);
+ exit_program(1);
+ }
st->sample_aspect_ratio = video_enc->sample_aspect_ratio;
if (intra_only)
video_enc->gop_size = 0;
- if (video_qscale || same_quality) {
- video_enc->flags |= CODEC_FLAG_QSCALE;
- video_enc->global_quality=
- st->quality = FF_QP2LAMBDA * video_qscale;
+ MATCH_PER_STREAM_OPT(intra_matrices, str, intra_matrix, oc, st);
+ if (intra_matrix) {
+ if (!(video_enc->intra_matrix = av_mallocz(sizeof(*video_enc->intra_matrix) * 64))) {
+ av_log(NULL, AV_LOG_FATAL, "Could not allocate memory for intra matrix.\n");
+ exit_program(1);
+ }
+ parse_matrix_coeffs(video_enc->intra_matrix, intra_matrix);
+ }
+ MATCH_PER_STREAM_OPT(inter_matrices, str, inter_matrix, oc, st);
+ if (inter_matrix) {
+ if (!(video_enc->inter_matrix = av_mallocz(sizeof(*video_enc->inter_matrix) * 64))) {
+ av_log(NULL, AV_LOG_FATAL, "Could not allocate memory for inter matrix.\n");
+ exit_program(1);
+ }
+ parse_matrix_coeffs(video_enc->inter_matrix, inter_matrix);
}
- if(intra_matrix)
- video_enc->intra_matrix = intra_matrix;
- if(inter_matrix)
- video_enc->inter_matrix = inter_matrix;
-
- p= video_rc_override_string;
+ MATCH_PER_STREAM_OPT(rc_overrides, str, p, oc, st);
for(i=0; p; i++){
int start, end, q;
int e=sscanf(p, "%d,%d,%d", &start, &end, &q);
if(e!=3){
- fprintf(stderr, "error parsing rc_override\n");
- ffmpeg_exit(1);
+ av_log(NULL, AV_LOG_FATAL, "error parsing rc_override\n");
+ exit_program(1);
}
+ /* FIXME realloc failure */
video_enc->rc_override=
av_realloc(video_enc->rc_override,
sizeof(RcOverride)*(i+1));
@@ -3531,12 +3455,8 @@ static void new_video_stream(AVFormatContext *oc, int file_idx)
video_enc->rc_override_count=i;
if (!video_enc->rc_initial_buffer_occupancy)
video_enc->rc_initial_buffer_occupancy = video_enc->rc_buffer_size*3/4;
- video_enc->me_threshold= me_threshold;
video_enc->intra_dc_precision= intra_dc_precision - 8;
- if (do_psnr)
- video_enc->flags|= CODEC_FLAG_PSNR;
-
/* two pass mode */
if (do_pass) {
if (do_pass == 1) {
@@ -3546,209 +3466,95 @@ static void new_video_stream(AVFormatContext *oc, int file_idx)
}
}
+ MATCH_PER_STREAM_OPT(forced_key_frames, str, forced_key_frames, oc, st);
if (forced_key_frames)
- parse_forced_key_frames(forced_key_frames, ost, video_enc);
- }
- if (video_language) {
- av_dict_set(&st->metadata, "language", video_language, 0);
- av_freep(&video_language);
+ parse_forced_key_frames(forced_key_frames, ost);
+
+ MATCH_PER_STREAM_OPT(force_fps, i, force_fps, oc, st);
+ ost->force_fps = force_fps;
+
+ MATCH_PER_STREAM_OPT(top_field_first, i, top_field_first, oc, st);
+ ost->top_field_first = top_field_first;
+
+#if CONFIG_AVFILTER
+ MATCH_PER_STREAM_OPT(filters, str, filters, oc, st);
+ if (filters)
+ ost->avfilter = av_strdup(filters);
+#endif
}
- /* reset some key parameters */
- video_disable = 0;
- av_freep(&video_codec_name);
- av_freep(&forced_key_frames);
- video_stream_copy = 0;
- frame_pix_fmt = PIX_FMT_NONE;
+ return ost;
}
-static void new_audio_stream(AVFormatContext *oc, int file_idx)
+static OutputStream *new_audio_stream(OptionsContext *o, AVFormatContext *oc)
{
AVStream *st;
- AVOutputStream *ost;
- AVCodec *codec= NULL;
+ OutputStream *ost;
AVCodecContext *audio_enc;
- enum CodecID codec_id = CODEC_ID_NONE;
- st = av_new_stream(oc, oc->nb_streams < nb_streamid_map ? streamid_map[oc->nb_streams] : 0);
- if (!st) {
- fprintf(stderr, "Could not alloc stream\n");
- ffmpeg_exit(1);
- }
- ost = new_output_stream(oc, file_idx);
-
- if(!audio_stream_copy){
- if (audio_codec_name) {
- codec_id = find_codec_or_die(audio_codec_name, AVMEDIA_TYPE_AUDIO, 1,
- avcodec_opts[AVMEDIA_TYPE_AUDIO]->strict_std_compliance);
- codec = avcodec_find_encoder_by_name(audio_codec_name);
- ost->enc = codec;
- } else {
- codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, AVMEDIA_TYPE_AUDIO);
- codec = avcodec_find_encoder(codec_id);
- }
- }
-
- avcodec_get_context_defaults3(st->codec, codec);
-
- ost->bitstream_filters = audio_bitstream_filters;
- audio_bitstream_filters= NULL;
-
- st->codec->thread_count= thread_count;
+ ost = new_output_stream(o, oc, AVMEDIA_TYPE_AUDIO);
+ st = ost->st;
audio_enc = st->codec;
audio_enc->codec_type = AVMEDIA_TYPE_AUDIO;
- if(audio_codec_tag)
- audio_enc->codec_tag= audio_codec_tag;
+ if (!st->stream_copy) {
+ char *sample_fmt = NULL;
- if (oc->oformat->flags & AVFMT_GLOBALHEADER) {
- audio_enc->flags |= CODEC_FLAG_GLOBAL_HEADER;
- avcodec_opts[AVMEDIA_TYPE_AUDIO]->flags|= CODEC_FLAG_GLOBAL_HEADER;
- }
- if (audio_stream_copy) {
- st->stream_copy = 1;
- } else {
- audio_enc->codec_id = codec_id;
- set_context_opts(audio_enc, avcodec_opts[AVMEDIA_TYPE_AUDIO], AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM, codec);
+ MATCH_PER_STREAM_OPT(audio_channels, i, audio_enc->channels, oc, st);
- if (audio_qscale > QSCALE_NONE) {
- audio_enc->flags |= CODEC_FLAG_QSCALE;
- audio_enc->global_quality = st->quality = FF_QP2LAMBDA * audio_qscale;
+ MATCH_PER_STREAM_OPT(sample_fmts, str, sample_fmt, oc, st);
+ if (sample_fmt &&
+ (audio_enc->sample_fmt = av_get_sample_fmt(sample_fmt)) == AV_SAMPLE_FMT_NONE) {
+ av_log(NULL, AV_LOG_FATAL, "Invalid sample format '%s'\n", sample_fmt);
+ exit_program(1);
}
- if (audio_channels)
- audio_enc->channels = audio_channels;
- audio_enc->sample_fmt = audio_sample_fmt;
- if (audio_sample_rate)
- audio_enc->sample_rate = audio_sample_rate;
- audio_enc->channel_layout = channel_layout;
- choose_sample_fmt(st, codec);
- }
- if (audio_language) {
- av_dict_set(&st->metadata, "language", audio_language, 0);
- av_freep(&audio_language);
+
+ MATCH_PER_STREAM_OPT(audio_sample_rate, i, audio_enc->sample_rate, oc, st);
}
- /* reset some key parameters */
- audio_disable = 0;
- av_freep(&audio_codec_name);
- audio_stream_copy = 0;
+ return ost;
}
-static void new_data_stream(AVFormatContext *oc, int file_idx)
+static OutputStream *new_data_stream(OptionsContext *o, AVFormatContext *oc)
{
AVStream *st;
- AVCodec *codec=NULL;
- AVCodecContext *data_enc;
+ OutputStream *ost;
- st = av_new_stream(oc, oc->nb_streams < nb_streamid_map ? streamid_map[oc->nb_streams] : 0);
- if (!st) {
- fprintf(stderr, "Could not alloc stream\n");
- ffmpeg_exit(1);
- }
- new_output_stream(oc, file_idx);
- data_enc = st->codec;
- if (!data_stream_copy) {
- fprintf(stderr, "Data stream encoding not supported yet (only streamcopy)\n");
- ffmpeg_exit(1);
+ ost = new_output_stream(o, oc, AVMEDIA_TYPE_DATA);
+ st = ost->st;
+ if (!st->stream_copy) {
+ av_log(NULL, AV_LOG_FATAL, "Data stream encoding not supported yet (only streamcopy)\n");
+ exit_program(1);
}
- avcodec_get_context_defaults3(st->codec, codec);
-
- data_enc->codec_type = AVMEDIA_TYPE_DATA;
- if (data_codec_tag)
- data_enc->codec_tag= data_codec_tag;
-
- if (oc->oformat->flags & AVFMT_GLOBALHEADER) {
- data_enc->flags |= CODEC_FLAG_GLOBAL_HEADER;
- avcodec_opts[AVMEDIA_TYPE_DATA]->flags |= CODEC_FLAG_GLOBAL_HEADER;
- }
- if (data_stream_copy) {
- st->stream_copy = 1;
- }
+ return ost;
+}
- data_disable = 0;
- av_freep(&data_codec_name);
- data_stream_copy = 0;
+static OutputStream *new_attachment_stream(OptionsContext *o, AVFormatContext *oc)
+{
+ OutputStream *ost = new_output_stream(o, oc, AVMEDIA_TYPE_ATTACHMENT);
+ ost->st->stream_copy = 1;
+ return ost;
}
-static void new_subtitle_stream(AVFormatContext *oc, int file_idx)
+static OutputStream *new_subtitle_stream(OptionsContext *o, AVFormatContext *oc)
{
AVStream *st;
- AVOutputStream *ost;
- AVCodec *codec=NULL;
+ OutputStream *ost;
AVCodecContext *subtitle_enc;
- enum CodecID codec_id = CODEC_ID_NONE;
- st = av_new_stream(oc, oc->nb_streams < nb_streamid_map ? streamid_map[oc->nb_streams] : 0);
- if (!st) {
- fprintf(stderr, "Could not alloc stream\n");
- ffmpeg_exit(1);
- }
- ost = new_output_stream(oc, file_idx);
+ ost = new_output_stream(o, oc, AVMEDIA_TYPE_SUBTITLE);
+ st = ost->st;
subtitle_enc = st->codec;
- if(!subtitle_stream_copy){
- if (subtitle_codec_name) {
- codec_id = find_codec_or_die(subtitle_codec_name, AVMEDIA_TYPE_SUBTITLE, 1,
- avcodec_opts[AVMEDIA_TYPE_SUBTITLE]->strict_std_compliance);
- codec = avcodec_find_encoder_by_name(subtitle_codec_name);
- ost->enc = codec;
- } else {
- codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, AVMEDIA_TYPE_SUBTITLE);
- codec = avcodec_find_encoder(codec_id);
- }
- }
- avcodec_get_context_defaults3(st->codec, codec);
-
- ost->bitstream_filters = subtitle_bitstream_filters;
- subtitle_bitstream_filters= NULL;
subtitle_enc->codec_type = AVMEDIA_TYPE_SUBTITLE;
- if(subtitle_codec_tag)
- subtitle_enc->codec_tag= subtitle_codec_tag;
-
- if (oc->oformat->flags & AVFMT_GLOBALHEADER) {
- subtitle_enc->flags |= CODEC_FLAG_GLOBAL_HEADER;
- avcodec_opts[AVMEDIA_TYPE_SUBTITLE]->flags |= CODEC_FLAG_GLOBAL_HEADER;
- }
- if (subtitle_stream_copy) {
- st->stream_copy = 1;
- } else {
- subtitle_enc->codec_id = codec_id;
- set_context_opts(avcodec_opts[AVMEDIA_TYPE_SUBTITLE], subtitle_enc, AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_ENCODING_PARAM, codec);
- }
-
- if (subtitle_language) {
- av_dict_set(&st->metadata, "language", subtitle_language, 0);
- av_freep(&subtitle_language);
- }
-
- subtitle_disable = 0;
- av_freep(&subtitle_codec_name);
- subtitle_stream_copy = 0;
-}
-
-static int opt_new_stream(const char *opt, const char *arg)
-{
- AVFormatContext *oc;
- int file_idx = nb_output_files - 1;
- if (nb_output_files <= 0) {
- fprintf(stderr, "At least one output file must be specified\n");
- ffmpeg_exit(1);
- }
- oc = output_files[file_idx];
-
- if (!strcmp(opt, "newvideo" )) new_video_stream (oc, file_idx);
- else if (!strcmp(opt, "newaudio" )) new_audio_stream (oc, file_idx);
- else if (!strcmp(opt, "newsubtitle")) new_subtitle_stream(oc, file_idx);
- else if (!strcmp(opt, "newdata" )) new_data_stream (oc, file_idx);
- else av_assert0(0);
- return 0;
+ return ost;
}
/* arg format is "output-stream-index:streamid-value". */
-static int opt_streamid(const char *opt, const char *arg)
+static int opt_streamid(OptionsContext *o, const char *opt, const char *arg)
{
int idx;
char *p;
@@ -3757,111 +3563,214 @@ static int opt_streamid(const char *opt, const char *arg)
av_strlcpy(idx_str, arg, sizeof(idx_str));
p = strchr(idx_str, ':');
if (!p) {
- fprintf(stderr,
- "Invalid value '%s' for option '%s', required syntax is 'index:value'\n",
- arg, opt);
- ffmpeg_exit(1);
+ av_log(NULL, AV_LOG_FATAL,
+ "Invalid value '%s' for option '%s', required syntax is 'index:value'\n",
+ arg, opt);
+ exit_program(1);
}
*p++ = '\0';
idx = parse_number_or_die(opt, idx_str, OPT_INT, 0, MAX_STREAMS-1);
- streamid_map = grow_array(streamid_map, sizeof(*streamid_map), &nb_streamid_map, idx+1);
- streamid_map[idx] = parse_number_or_die(opt, p, OPT_INT, 0, INT_MAX);
+ o->streamid_map = grow_array(o->streamid_map, sizeof(*o->streamid_map), &o->nb_streamid_map, idx+1);
+ o->streamid_map[idx] = parse_number_or_die(opt, p, OPT_INT, 0, INT_MAX);
+ return 0;
+}
+
+static int copy_chapters(InputFile *ifile, OutputFile *ofile, int copy_metadata)
+{
+ AVFormatContext *is = ifile->ctx;
+ AVFormatContext *os = ofile->ctx;
+ int i;
+
+ for (i = 0; i < is->nb_chapters; i++) {
+ AVChapter *in_ch = is->chapters[i], *out_ch;
+ int64_t ts_off = av_rescale_q(ofile->start_time - ifile->ts_offset,
+ AV_TIME_BASE_Q, in_ch->time_base);
+ int64_t rt = (ofile->recording_time == INT64_MAX) ? INT64_MAX :
+ av_rescale_q(ofile->recording_time, AV_TIME_BASE_Q, in_ch->time_base);
+
+
+ if (in_ch->end < ts_off)
+ continue;
+ if (rt != INT64_MAX && in_ch->start > rt + ts_off)
+ break;
+
+ out_ch = av_mallocz(sizeof(AVChapter));
+ if (!out_ch)
+ return AVERROR(ENOMEM);
+
+ out_ch->id = in_ch->id;
+ out_ch->time_base = in_ch->time_base;
+ out_ch->start = FFMAX(0, in_ch->start - ts_off);
+ out_ch->end = FFMIN(rt, in_ch->end - ts_off);
+
+ if (copy_metadata)
+ av_dict_copy(&out_ch->metadata, in_ch->metadata, 0);
+
+ os->nb_chapters++;
+ os->chapters = av_realloc_f(os->chapters, os->nb_chapters, sizeof(AVChapter));
+ if (!os->chapters)
+ return AVERROR(ENOMEM);
+ os->chapters[os->nb_chapters - 1] = out_ch;
+ }
return 0;
}
-static void opt_output_file(const char *filename)
+static int read_ffserver_streams(OptionsContext *o, AVFormatContext *s, const char *filename)
{
+ int i, err;
+ AVFormatContext *ic = NULL;
+
+ err = avformat_open_input(&ic, filename, NULL, NULL);
+ if (err < 0)
+ return err;
+ /* copy stream format */
+ for(i=0;i<ic->nb_streams;i++) {
+ AVStream *st;
+ OutputStream *ost;
+ AVCodec *codec;
+
+ codec = avcodec_find_encoder(ic->streams[i]->codec->codec_id);
+ ost = new_output_stream(o, s, codec->type);
+ st = ost->st;
+
+ // FIXME: a more elegant solution is needed
+ memcpy(st, ic->streams[i], sizeof(AVStream));
+ st->info = av_malloc(sizeof(*st->info));
+ memcpy(st->info, ic->streams[i]->info, sizeof(*st->info));
+ avcodec_copy_context(st->codec, ic->streams[i]->codec);
+
+ if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && !st->stream_copy)
+ choose_sample_fmt(st, codec);
+ else if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO && !st->stream_copy)
+ choose_pixel_fmt(st, codec);
+ }
+
+ av_close_input_file(ic);
+ return 0;
+}
+
+static void opt_output_file(void *optctx, const char *filename)
+{
+ OptionsContext *o = optctx;
AVFormatContext *oc;
- int err, use_video, use_audio, use_subtitle, use_data;
- int input_has_video, input_has_audio, input_has_subtitle, input_has_data;
+ int i, err;
AVOutputFormat *file_oformat;
+ OutputStream *ost;
+ InputStream *ist;
if (!strcmp(filename, "-"))
filename = "pipe:";
- oc = avformat_alloc_context();
+ err = avformat_alloc_output_context2(&oc, NULL, o->format, filename);
if (!oc) {
- print_error(filename, AVERROR(ENOMEM));
- ffmpeg_exit(1);
- }
-
- if (last_asked_format) {
- file_oformat = av_guess_format(last_asked_format, NULL, NULL);
- if (!file_oformat) {
- fprintf(stderr, "Requested output format '%s' is not a suitable output format\n", last_asked_format);
- ffmpeg_exit(1);
- }
- last_asked_format = NULL;
- } else {
- file_oformat = av_guess_format(NULL, filename, NULL);
- if (!file_oformat) {
- fprintf(stderr, "Unable to find a suitable output format for '%s'\n",
- filename);
- ffmpeg_exit(1);
- }
+ print_error(filename, err);
+ exit_program(1);
}
-
- oc->oformat = file_oformat;
- av_strlcpy(oc->filename, filename, sizeof(oc->filename));
+ file_oformat= oc->oformat;
if (!strcmp(file_oformat->name, "ffm") &&
av_strstart(filename, "http:", NULL)) {
/* special case for files sent to ffserver: we get the stream
parameters from ffserver */
- int err = read_ffserver_streams(oc, filename);
+ int err = read_ffserver_streams(o, oc, filename);
if (err < 0) {
print_error(filename, err);
- ffmpeg_exit(1);
+ exit_program(1);
}
- } else {
- use_video = file_oformat->video_codec != CODEC_ID_NONE || video_stream_copy || video_codec_name;
- use_audio = file_oformat->audio_codec != CODEC_ID_NONE || audio_stream_copy || audio_codec_name;
- use_subtitle = file_oformat->subtitle_codec != CODEC_ID_NONE || subtitle_stream_copy || subtitle_codec_name;
- use_data = data_stream_copy || data_codec_name; /* XXX once generic data codec will be available add a ->data_codec reference and use it here */
-
- /* disable if no corresponding type found and at least one
- input file */
- if (nb_input_files > 0) {
- check_inputs(&input_has_video,
- &input_has_audio,
- &input_has_subtitle,
- &input_has_data);
-
- if (!input_has_video)
- use_video = 0;
- if (!input_has_audio)
- use_audio = 0;
- if (!input_has_subtitle)
- use_subtitle = 0;
- if (!input_has_data)
- use_data = 0;
+ } else if (!o->nb_stream_maps) {
+ /* pick the "best" stream of each type */
+#define NEW_STREAM(type, index)\
+ if (index >= 0) {\
+ ost = new_ ## type ## _stream(o, oc);\
+ ost->source_index = index;\
+ ost->sync_ist = &input_streams[index];\
+ input_streams[index].discard = 0;\
+ }
+
+ /* video: highest resolution */
+ if (!o->video_disable && oc->oformat->video_codec != CODEC_ID_NONE) {
+ int area = 0, idx = -1;
+ for (i = 0; i < nb_input_streams; i++) {
+ ist = &input_streams[i];
+ if (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO &&
+ ist->st->codec->width * ist->st->codec->height > area) {
+ area = ist->st->codec->width * ist->st->codec->height;
+ idx = i;
+ }
+ }
+ NEW_STREAM(video, idx);
}
- /* manual disable */
- if (audio_disable) use_audio = 0;
- if (video_disable) use_video = 0;
- if (subtitle_disable) use_subtitle = 0;
- if (data_disable) use_data = 0;
+ /* audio: most channels */
+ if (!o->audio_disable && oc->oformat->audio_codec != CODEC_ID_NONE) {
+ int channels = 0, idx = -1;
+ for (i = 0; i < nb_input_streams; i++) {
+ ist = &input_streams[i];
+ if (ist->st->codec->codec_type == AVMEDIA_TYPE_AUDIO &&
+ ist->st->codec->channels > channels) {
+ channels = ist->st->codec->channels;
+ idx = i;
+ }
+ }
+ NEW_STREAM(audio, idx);
+ }
- if (use_video) new_video_stream(oc, nb_output_files);
- if (use_audio) new_audio_stream(oc, nb_output_files);
- if (use_subtitle) new_subtitle_stream(oc, nb_output_files);
- if (use_data) new_data_stream(oc, nb_output_files);
+ /* subtitles: pick first */
+ if (!o->subtitle_disable && (oc->oformat->subtitle_codec != CODEC_ID_NONE || subtitle_codec_name)) {
+ for (i = 0; i < nb_input_streams; i++)
+ if (input_streams[i].st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) {
+ NEW_STREAM(subtitle, i);
+ break;
+ }
+ }
+ /* do something with data? */
+ } else {
+ for (i = 0; i < o->nb_stream_maps; i++) {
+ StreamMap *map = &o->stream_maps[i];
- oc->timestamp = recording_timestamp;
+ if (map->disabled)
+ continue;
- av_dict_copy(&oc->metadata, metadata, 0);
- av_dict_free(&metadata);
+ ist = &input_streams[input_files[map->file_index].ist_index + map->stream_index];
+ if(o->subtitle_disable && ist->st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE)
+ continue;
+ if(o-> audio_disable && ist->st->codec->codec_type == AVMEDIA_TYPE_AUDIO)
+ continue;
+ if(o-> video_disable && ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO)
+ continue;
+
+ switch (ist->st->codec->codec_type) {
+ case AVMEDIA_TYPE_VIDEO: ost = new_video_stream(o, oc); break;
+ case AVMEDIA_TYPE_AUDIO: ost = new_audio_stream(o, oc); break;
+ case AVMEDIA_TYPE_SUBTITLE: ost = new_subtitle_stream(o, oc); break;
+ case AVMEDIA_TYPE_DATA: ost = new_data_stream(o, oc); break;
+ case AVMEDIA_TYPE_ATTACHMENT: ost = new_attachment_stream(o, oc); break;
+ default:
+ av_log(NULL, AV_LOG_FATAL, "Cannot map stream #%d.%d - unsupported type.\n",
+ map->file_index, map->stream_index);
+ exit_program(1);
+ }
+
+ ost->source_index = input_files[map->file_index].ist_index + map->stream_index;
+ ost->sync_ist = &input_streams[input_files[map->sync_file_index].ist_index +
+ map->sync_stream_index];
+ ist->discard = 0;
+ }
}
- av_dict_copy(&output_opts[nb_output_files], format_opts, 0);
- output_files[nb_output_files++] = oc;
+ output_files = grow_array(output_files, sizeof(*output_files), &nb_output_files, nb_output_files + 1);
+ output_files[nb_output_files - 1].ctx = oc;
+ output_files[nb_output_files - 1].ost_index = nb_output_streams - oc->nb_streams;
+ output_files[nb_output_files - 1].recording_time = o->recording_time;
+ output_files[nb_output_files - 1].start_time = o->start_time;
+ output_files[nb_output_files - 1].limit_filesize = o->limit_filesize;
+ av_dict_copy(&output_files[nb_output_files - 1].opts, format_opts, 0);
/* check filename in case of an image number is expected */
if (oc->oformat->flags & AVFMT_NEEDNUMBER) {
if (!av_filename_number_test(oc->filename)) {
print_error(oc->filename, AVERROR(EINVAL));
- ffmpeg_exit(1);
+ exit_program(1);
}
}
@@ -3875,14 +3784,16 @@ static void opt_output_file(const char *filename)
if (!using_stdin) {
fprintf(stderr,"File '%s' already exists. Overwrite ? [y/N] ", filename);
fflush(stderr);
+ term_exit();
if (!read_yesno()) {
- fprintf(stderr, "Not overwriting - exiting\n");
- ffmpeg_exit(1);
+ av_log(0, AV_LOG_FATAL, "Not overwriting - exiting\n");
+ exit_program(1);
}
+ term_init();
}
else {
- fprintf(stderr,"File '%s' already exists. Exiting.\n", filename);
- ffmpeg_exit(1);
+ av_log(0, AV_LOG_FATAL,"File '%s' already exists. Exiting.\n", filename);
+ exit_program(1);
}
}
}
@@ -3890,24 +3801,139 @@ static void opt_output_file(const char *filename)
/* open the file */
if ((err = avio_open(&oc->pb, filename, AVIO_FLAG_WRITE)) < 0) {
print_error(filename, err);
- ffmpeg_exit(1);
+ exit_program(1);
}
}
- oc->preload= (int)(mux_preload*AV_TIME_BASE);
- oc->max_delay= (int)(mux_max_delay*AV_TIME_BASE);
- oc->loop_output = loop_output;
- oc->flags |= AVFMT_FLAG_NONBLOCK;
+ oc->preload = (int)(o->mux_preload * AV_TIME_BASE);
+ oc->max_delay = (int)(o->mux_max_delay * AV_TIME_BASE);
- frame_rate = (AVRational){0, 0};
- frame_width = 0;
- frame_height = 0;
- audio_sample_rate = 0;
- audio_channels = 0;
+ if (loop_output >= 0) {
+ av_log(NULL, AV_LOG_WARNING, "-loop_output is deprecated, use -loop\n");
+ oc->loop_output = loop_output;
+ }
- av_freep(&forced_key_frames);
- uninit_opts();
- init_opts();
+ /* copy chapters */
+ if (o->chapters_input_file >= nb_input_files) {
+ if (o->chapters_input_file == INT_MAX) {
+ /* copy chapters from the first input file that has them*/
+ o->chapters_input_file = -1;
+ for (i = 0; i < nb_input_files; i++)
+ if (input_files[i].ctx->nb_chapters) {
+ o->chapters_input_file = i;
+ break;
+ }
+ } else {
+ av_log(NULL, AV_LOG_FATAL, "Invalid input file index %d in chapter mapping.\n",
+ o->chapters_input_file);
+ exit_program(1);
+ }
+ }
+ if (o->chapters_input_file >= 0)
+ copy_chapters(&input_files[o->chapters_input_file], &output_files[nb_output_files - 1],
+ !o->metadata_chapters_manual);
+
+ /* copy metadata */
+ for (i = 0; i < o->nb_meta_data_maps; i++) {
+ AVFormatContext *files[2];
+ AVDictionary **meta[2];
+ int j;
+
+#define METADATA_CHECK_INDEX(index, nb_elems, desc)\
+ if ((index) < 0 || (index) >= (nb_elems)) {\
+ av_log(NULL, AV_LOG_FATAL, "Invalid %s index %d while processing metadata maps\n",\
+ (desc), (index));\
+ exit_program(1);\
+ }
+
+ int in_file_index = o->meta_data_maps[i][1].file;
+ if (in_file_index < 0)
+ continue;
+ METADATA_CHECK_INDEX(in_file_index, nb_input_files, "input file")
+
+ files[0] = oc;
+ files[1] = input_files[in_file_index].ctx;
+
+ for (j = 0; j < 2; j++) {
+ MetadataMap *map = &o->meta_data_maps[i][j];
+
+ switch (map->type) {
+ case 'g':
+ meta[j] = &files[j]->metadata;
+ break;
+ case 's':
+ METADATA_CHECK_INDEX(map->index, files[j]->nb_streams, "stream")
+ meta[j] = &files[j]->streams[map->index]->metadata;
+ break;
+ case 'c':
+ METADATA_CHECK_INDEX(map->index, files[j]->nb_chapters, "chapter")
+ meta[j] = &files[j]->chapters[map->index]->metadata;
+ break;
+ case 'p':
+ METADATA_CHECK_INDEX(map->index, files[j]->nb_programs, "program")
+ meta[j] = &files[j]->programs[map->index]->metadata;
+ break;
+ }
+ }
+
+ av_dict_copy(meta[0], *meta[1], AV_DICT_DONT_OVERWRITE);
+ }
+
+ /* copy global metadata by default */
+ if (!o->metadata_global_manual && nb_input_files){
+ av_dict_copy(&oc->metadata, input_files[0].ctx->metadata,
+ AV_DICT_DONT_OVERWRITE);
+ if(o->recording_time != INT64_MAX)
+ av_dict_set(&oc->metadata, "duration", NULL, 0);
+ }
+ if (!o->metadata_streams_manual)
+ for (i = output_files[nb_output_files - 1].ost_index; i < nb_output_streams; i++) {
+ InputStream *ist = &input_streams[output_streams[i].source_index];
+ av_dict_copy(&output_streams[i].st->metadata, ist->st->metadata, AV_DICT_DONT_OVERWRITE);
+ }
+
+ /* process manually set metadata */
+ for (i = 0; i < o->nb_metadata; i++) {
+ AVDictionary **m;
+ char type, *val;
+ int index = 0;
+
+ val = strchr(o->metadata[i].u.str, '=');
+ if (!val) {
+ av_log(NULL, AV_LOG_FATAL, "No '=' character in metadata string %s.\n",
+ o->metadata[i].u.str);
+ exit_program(1);
+ }
+ *val++ = 0;
+
+ parse_meta_type(o->metadata[i].specifier, &type, &index);
+ switch (type) {
+ case 'g':
+ m = &oc->metadata;
+ break;
+ case 's':
+ if (index < 0 || index >= oc->nb_streams) {
+ av_log(NULL, AV_LOG_FATAL, "Invalid stream index %d in metadata specifier.\n", index);
+ exit_program(1);
+ }
+ m = &oc->streams[index]->metadata;
+ break;
+ case 'c':
+ if (index < 0 || index >= oc->nb_chapters) {
+ av_log(NULL, AV_LOG_FATAL, "Invalid chapter index %d in metadata specifier.\n", index);
+ exit_program(1);
+ }
+ m = &oc->chapters[index]->metadata;
+ break;
+ default:
+ av_log(NULL, AV_LOG_FATAL, "Invalid metadata specifier %s.\n", o->metadata[i].specifier);
+ exit_program(1);
+ }
+
+ av_dict_set(m, o->metadata[i].u.str, *val ? val : NULL, 0);
+ }
+
+ reset_options(o, 0);
}
/* same option as mencoder */
@@ -3953,48 +3979,21 @@ static int64_t getmaxrss(void)
#endif
}
-static void parse_matrix_coeffs(uint16_t *dest, const char *str)
+static int opt_audio_qscale(OptionsContext *o, const char *opt, const char *arg)
{
- int i;
- const char *p = str;
- for(i = 0;; i++) {
- dest[i] = atoi(p);
- if(i == 63)
- break;
- p = strchr(p, ',');
- if(!p) {
- fprintf(stderr, "Syntax error in matrix \"%s\" at coeff %d\n", str, i);
- ffmpeg_exit(1);
- }
- p++;
- }
-}
-
-static void opt_inter_matrix(const char *arg)
-{
- inter_matrix = av_mallocz(sizeof(uint16_t) * 64);
- parse_matrix_coeffs(inter_matrix, arg);
-}
-
-static void opt_intra_matrix(const char *arg)
-{
- intra_matrix = av_mallocz(sizeof(uint16_t) * 64);
- parse_matrix_coeffs(intra_matrix, arg);
+ return parse_option(o, "q:a", arg, options);
}
static void show_usage(void)
{
printf("Hyper fast Audio and Video encoder\n");
- printf("usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...\n");
+ printf("usage: %s [options] [[infile options] -i infile]... {[outfile options] outfile}...\n", program_name);
printf("\n");
}
-static void show_help(void)
+static int opt_help(const char *opt, const char *arg)
{
- AVCodec *c;
- AVOutputFormat *oformat = NULL;
- AVInputFormat *iformat = NULL;
-
+ int flags = AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_ENCODING_PARAM;
av_log_set_callback(log_callback_help);
show_usage();
show_help_options(options, "Main options:\n",
@@ -4021,41 +4020,14 @@ static void show_help(void)
OPT_GRAB,
OPT_GRAB);
printf("\n");
- av_opt_show2(avcodec_opts[0], NULL, AV_OPT_FLAG_ENCODING_PARAM|AV_OPT_FLAG_DECODING_PARAM, 0);
- printf("\n");
+ show_help_children(avcodec_get_class(), flags);
+ show_help_children(avformat_get_class(), flags);
+ show_help_children(sws_get_class(), flags);
- /* individual codec options */
- c = NULL;
- while ((c = av_codec_next(c))) {
- if (c->priv_class) {
- av_opt_show2(&c->priv_class, NULL, AV_OPT_FLAG_ENCODING_PARAM|AV_OPT_FLAG_DECODING_PARAM, 0);
- printf("\n");
- }
- }
-
- av_opt_show2(avformat_opts, NULL, AV_OPT_FLAG_ENCODING_PARAM|AV_OPT_FLAG_DECODING_PARAM, 0);
- printf("\n");
-
- /* individual muxer options */
- while ((oformat = av_oformat_next(oformat))) {
- if (oformat->priv_class) {
- av_opt_show2(&oformat->priv_class, NULL, AV_OPT_FLAG_ENCODING_PARAM, 0);
- printf("\n");
- }
- }
-
- /* individual demuxer options */
- while ((iformat = av_iformat_next(iformat))) {
- if (iformat->priv_class) {
- av_opt_show2(&iformat->priv_class, NULL, AV_OPT_FLAG_DECODING_PARAM, 0);
- printf("\n");
- }
- }
-
- av_opt_show2(sws_opts, NULL, AV_OPT_FLAG_ENCODING_PARAM|AV_OPT_FLAG_DECODING_PARAM, 0);
+ return 0;
}
-static int opt_target(const char *opt, const char *arg)
+static int opt_target(OptionsContext *o, const char *opt, const char *arg)
{
enum { PAL, NTSC, FILM, UNKNOWN } norm = UNKNOWN;
static const char *const frame_rates[] = {"25", "30000/1001", "24000/1001"};
@@ -4070,54 +4042,45 @@ static int opt_target(const char *opt, const char *arg)
norm = FILM;
arg += 5;
} else {
- int fr;
- /* Calculate FR via float to avoid int overflow */
- fr = (int)(frame_rate.num * 1000.0 / frame_rate.den);
- if(fr == 25000) {
- norm = PAL;
- } else if((fr == 29970) || (fr == 23976)) {
- norm = NTSC;
- } else {
- /* Try to determine PAL/NTSC by peeking in the input files */
- if(nb_input_files) {
- int i, j;
- for (j = 0; j < nb_input_files; j++) {
- for (i = 0; i < input_files[j].ctx->nb_streams; i++) {
- AVCodecContext *c = input_files[j].ctx->streams[i]->codec;
- if(c->codec_type != AVMEDIA_TYPE_VIDEO)
- continue;
- fr = c->time_base.den * 1000 / c->time_base.num;
- if(fr == 25000) {
- norm = PAL;
- break;
- } else if((fr == 29970) || (fr == 23976)) {
- norm = NTSC;
- break;
- }
- }
- if(norm != UNKNOWN)
+ /* Try to determine PAL/NTSC by peeking in the input files */
+ if(nb_input_files) {
+ int i, j, fr;
+ for (j = 0; j < nb_input_files; j++) {
+ for (i = 0; i < input_files[j].nb_streams; i++) {
+ AVCodecContext *c = input_files[j].ctx->streams[i]->codec;
+ if(c->codec_type != AVMEDIA_TYPE_VIDEO)
+ continue;
+ fr = c->time_base.den * 1000 / c->time_base.num;
+ if(fr == 25000) {
+ norm = PAL;
break;
+ } else if((fr == 29970) || (fr == 23976)) {
+ norm = NTSC;
+ break;
+ }
}
+ if(norm != UNKNOWN)
+ break;
}
}
- if(verbose > 0 && norm != UNKNOWN)
- fprintf(stderr, "Assuming %s for target.\n", norm == PAL ? "PAL" : "NTSC");
+ if (norm != UNKNOWN)
+ av_log(NULL, AV_LOG_INFO, "Assuming %s for target.\n", norm == PAL ? "PAL" : "NTSC");
}
if(norm == UNKNOWN) {
- fprintf(stderr, "Could not determine norm (PAL/NTSC/NTSC-Film) for target.\n");
- fprintf(stderr, "Please prefix target with \"pal-\", \"ntsc-\" or \"film-\",\n");
- fprintf(stderr, "or set a framerate with \"-r xxx\".\n");
- ffmpeg_exit(1);
+ av_log(NULL, AV_LOG_FATAL, "Could not determine norm (PAL/NTSC/NTSC-Film) for target.\n");
+ av_log(NULL, AV_LOG_FATAL, "Please prefix target with \"pal-\", \"ntsc-\" or \"film-\",\n");
+ av_log(NULL, AV_LOG_FATAL, "or set a framerate with \"-r xxx\".\n");
+ exit_program(1);
}
if(!strcmp(arg, "vcd")) {
- opt_video_codec("vcodec", "mpeg1video");
- opt_audio_codec("vcodec", "mp2");
- opt_format("f", "vcd");
+ opt_video_codec(o, "c:v", "mpeg1video");
+ opt_audio_codec(o, "c:a", "mp2");
+ parse_option(o, "f", "vcd", options);
- opt_frame_size("s", norm == PAL ? "352x288" : "352x240");
- opt_frame_rate("r", frame_rates[norm]);
+ parse_option(o, "s", norm == PAL ? "352x288" : "352x240", options);
+ parse_option(o, "r", frame_rates[norm], options);
opt_default("g", norm == PAL ? "15" : "18");
opt_default("b", "1150000");
@@ -4125,9 +4088,9 @@ static int opt_target(const char *opt, const char *arg)
opt_default("minrate", "1150000");
opt_default("bufsize", "327680"); // 40*1024*8;
- opt_default("ab", "224000");
- audio_sample_rate = 44100;
- audio_channels = 2;
+ opt_default("b:a", "224000");
+ parse_option(o, "ar", "44100", options);
+ parse_option(o, "ac", "2", options);
opt_default("packetsize", "2324");
opt_default("muxrate", "1411200"); // 2352 * 75 * 8;
@@ -4137,15 +4100,16 @@ static int opt_target(const char *opt, const char *arg)
and the first pack from the other stream, respectively, may also have
been written before.
So the real data starts at SCR 36000+3*1200. */
- mux_preload= (36000+3*1200) / 90000.0; //0.44
+ o->mux_preload = (36000+3*1200) / 90000.0; //0.44
} else if(!strcmp(arg, "svcd")) {
- opt_video_codec("vcodec", "mpeg2video");
- opt_audio_codec("acodec", "mp2");
- opt_format("f", "svcd");
+ opt_video_codec(o, "c:v", "mpeg2video");
+ opt_audio_codec(o, "c:a", "mp2");
+ parse_option(o, "f", "svcd", options);
- opt_frame_size("s", norm == PAL ? "480x576" : "480x480");
- opt_frame_rate("r", frame_rates[norm]);
+ parse_option(o, "s", norm == PAL ? "480x576" : "480x480", options);
+ parse_option(o, "r", frame_rates[norm], options);
+ parse_option(o, "pix_fmt", "yuv420p", options);
opt_default("g", norm == PAL ? "15" : "18");
opt_default("b", "2040000");
@@ -4155,19 +4119,20 @@ static int opt_target(const char *opt, const char *arg)
opt_default("flags", "+scan_offset");
- opt_default("ab", "224000");
- audio_sample_rate = 44100;
+ opt_default("b:a", "224000");
+ parse_option(o, "ar", "44100", options);
opt_default("packetsize", "2324");
} else if(!strcmp(arg, "dvd")) {
- opt_video_codec("vcodec", "mpeg2video");
- opt_audio_codec("vcodec", "ac3");
- opt_format("f", "dvd");
+ opt_video_codec(o, "c:v", "mpeg2video");
+ opt_audio_codec(o, "c:a", "ac3");
+ parse_option(o, "f", "dvd", options);
- opt_frame_size("vcodec", norm == PAL ? "720x576" : "720x480");
- opt_frame_rate("r", frame_rates[norm]);
+ parse_option(o, "s", norm == PAL ? "720x576" : "720x480", options);
+ parse_option(o, "r", frame_rates[norm], options);
+ parse_option(o, "pix_fmt", "yuv420p", options);
opt_default("g", norm == PAL ? "15" : "18");
opt_default("b", "6000000");
@@ -4178,23 +4143,23 @@ static int opt_target(const char *opt, const char *arg)
opt_default("packetsize", "2048"); // from www.mpucoder.com: DVD sectors contain 2048 bytes of data, this is also the size of one pack.
opt_default("muxrate", "10080000"); // from mplex project: data_rate = 1260000. mux_rate = data_rate * 8
- opt_default("ab", "448000");
- audio_sample_rate = 48000;
+ opt_default("b:a", "448000");
+ parse_option(o, "ar", "48000", options);
} else if(!strncmp(arg, "dv", 2)) {
- opt_format("f", "dv");
+ parse_option(o, "f", "dv", options);
- opt_frame_size("s", norm == PAL ? "720x576" : "720x480");
- opt_frame_pix_fmt("pix_fmt", !strncmp(arg, "dv50", 4) ? "yuv422p" :
- norm == PAL ? "yuv420p" : "yuv411p");
- opt_frame_rate("r", frame_rates[norm]);
+ parse_option(o, "s", norm == PAL ? "720x576" : "720x480", options);
+ parse_option(o, "pix_fmt", !strncmp(arg, "dv50", 4) ? "yuv422p" :
+ norm == PAL ? "yuv420p" : "yuv411p", options);
+ parse_option(o, "r", frame_rates[norm], options);
- audio_sample_rate = 48000;
- audio_channels = 2;
+ parse_option(o, "ar", "48000", options);
+ parse_option(o, "ac", "2", options);
} else {
- fprintf(stderr, "Unknown target: %s\n", arg);
+ av_log(NULL, AV_LOG_ERROR, "Unknown target: %s\n", arg);
return AVERROR(EINVAL);
}
return 0;
@@ -4218,38 +4183,35 @@ static int opt_vstats(const char *opt, const char *arg)
return opt_vstats_file(opt, filename);
}
-static int opt_bsf(const char *opt, const char *arg)
+static int opt_video_frames(OptionsContext *o, const char *opt, const char *arg)
{
- AVBitStreamFilterContext *bsfc= av_bitstream_filter_init(arg); //FIXME split name and args for filter at '='
- AVBitStreamFilterContext **bsfp;
-
- if(!bsfc){
- fprintf(stderr, "Unknown bitstream filter %s\n", arg);
- ffmpeg_exit(1);
- }
-
- bsfp= *opt == 'v' ? &video_bitstream_filters :
- *opt == 'a' ? &audio_bitstream_filters :
- &subtitle_bitstream_filters;
- while(*bsfp)
- bsfp= &(*bsfp)->next;
+ return parse_option(o, "frames:v", arg, options);
+}
- *bsfp= bsfc;
+static int opt_audio_frames(OptionsContext *o, const char *opt, const char *arg)
+{
+ return parse_option(o, "frames:a", arg, options);
+}
- return 0;
+static int opt_data_frames(OptionsContext *o, const char *opt, const char *arg)
+{
+ return parse_option(o, "frames:d", arg, options);
}
-static int opt_preset(const char *opt, const char *arg)
+static int opt_preset(OptionsContext *o, const char *opt, const char *arg)
{
FILE *f=NULL;
char filename[1000], tmp[1000], tmp2[1000], line[1000];
- char *codec_name = *opt == 'v' ? video_codec_name :
- *opt == 'a' ? audio_codec_name :
- subtitle_codec_name;
+ const char *codec_name = *opt == 'v' ? video_codec_name :
+ *opt == 'a' ? audio_codec_name :
+ subtitle_codec_name;
if (!(f = get_preset_file(filename, sizeof(filename), arg, *opt == 'f', codec_name))) {
- fprintf(stderr, "File for preset '%s' not found\n", arg);
- ffmpeg_exit(1);
+ if(!strncmp(arg, "libx264-lossless", strlen("libx264-lossless"))){
+ av_log(0, AV_LOG_FATAL, "Please use -preset <speed> -qp 0\n");
+ }else
+ av_log(0, AV_LOG_FATAL, "File for preset '%s' not found\n", arg);
+ exit_program(1);
}
while(!feof(f)){
@@ -4258,20 +4220,20 @@ static int opt_preset(const char *opt, const char *arg)
continue;
e|= sscanf(line, "%999[^=]=%999[^\n]\n", tmp, tmp2) - 2;
if(e){
- fprintf(stderr, "%s: Invalid syntax: '%s'\n", filename, line);
- ffmpeg_exit(1);
+ av_log(0, AV_LOG_FATAL, "%s: Invalid syntax: '%s'\n", filename, line);
+ exit_program(1);
}
if(!strcmp(tmp, "acodec")){
- opt_audio_codec(tmp, tmp2);
+ opt_audio_codec(o, tmp, tmp2);
}else if(!strcmp(tmp, "vcodec")){
- opt_video_codec(tmp, tmp2);
+ opt_video_codec(o, tmp, tmp2);
}else if(!strcmp(tmp, "scodec")){
- opt_subtitle_codec(tmp, tmp2);
+ opt_subtitle_codec(o, tmp, tmp2);
}else if(!strcmp(tmp, "dcodec")){
- opt_data_codec(tmp, tmp2);
+ opt_data_codec(o, tmp, tmp2);
}else if(opt_default(tmp, tmp2) < 0){
- fprintf(stderr, "%s: Invalid option or argument: '%s', parsed as '%s' = '%s'\n", filename, line, tmp, tmp2);
- ffmpeg_exit(1);
+ av_log(0, AV_LOG_FATAL, "%s: Invalid option or argument: '%s', parsed as '%s' = '%s'\n", filename, line, tmp, tmp2);
+ exit_program(1);
}
}
@@ -4280,26 +4242,65 @@ static int opt_preset(const char *opt, const char *arg)
return 0;
}
+static void log_callback_null(void *ptr, int level, const char *fmt, va_list vl)
+{
+}
+
+static int opt_passlogfile(const char *opt, const char *arg)
+{
+ pass_logfilename_prefix = arg;
+#if CONFIG_LIBX264_ENCODER
+ return opt_default("passlogfile", arg);
+#else
+ return 0;
+#endif
+}
+
+static int opt_old2new(OptionsContext *o, const char *opt, const char *arg)
+{
+ char *s= av_malloc(strlen(opt)+2);
+ snprintf(s, strlen(opt)+2, "%s:%c", opt+1, *opt);
+ return parse_option(o, s, arg, options);
+}
+
+static int opt_bitrate(OptionsContext *o, const char *opt, const char *arg)
+{
+ if(!strcmp(opt, "b")){
+ av_log(0,AV_LOG_WARNING, "Please use -b:a or -b:v, -b is ambiguous\n");
+ return parse_option(o, av_strdup("b:v"), arg, options);
+ }
+ return opt_default(opt, arg);
+}
+
+static int opt_video_filters(OptionsContext *o, const char *opt, const char *arg)
+{
+ return parse_option(o, "filter:v", arg, options);
+}
+
+#define OFFSET(x) offsetof(OptionsContext, x)
static const OptionDef options[] = {
/* main options */
#include "cmdutils_common_opts.h"
- { "f", HAS_ARG, {(void*)opt_format}, "force format", "fmt" },
- { "i", HAS_ARG, {(void*)opt_input_file}, "input file name", "filename" },
+ { "f", HAS_ARG | OPT_STRING | OPT_OFFSET, {.off = OFFSET(format)}, "force format", "fmt" },
+ { "i", HAS_ARG | OPT_FUNC2, {(void*)opt_input_file}, "input file name", "filename" },
{ "y", OPT_BOOL, {(void*)&file_overwrite}, "overwrite output files" },
- { "map", HAS_ARG | OPT_EXPERT, {(void*)opt_map}, "set input stream mapping", "file.stream[:syncfile.syncstream]" },
- { "map_meta_data", HAS_ARG | OPT_EXPERT, {(void*)opt_map_meta_data}, "DEPRECATED set meta data information of outfile from infile",
+ { "c", HAS_ARG | OPT_STRING | OPT_SPEC, {.off = OFFSET(codec_names)}, "codec name", "codec" },
+ { "codec", HAS_ARG | OPT_STRING | OPT_SPEC, {.off = OFFSET(codec_names)}, "codec name", "codec" },
+ { "pre", HAS_ARG | OPT_STRING | OPT_SPEC, {.off = OFFSET(presets)}, "preset name", "preset" },
+ { "map", HAS_ARG | OPT_EXPERT | OPT_FUNC2, {(void*)opt_map}, "set input stream mapping", "file.stream[:syncfile.syncstream]" },
+ { "map_meta_data", HAS_ARG | OPT_EXPERT | OPT_FUNC2, {(void*)opt_map_meta_data}, "DEPRECATED set meta data information of outfile from infile",
"outfile[,metadata]:infile[,metadata]" },
- { "map_metadata", HAS_ARG | OPT_EXPERT, {(void*)opt_map_metadata}, "set metadata information of outfile from infile",
+ { "map_metadata", HAS_ARG | OPT_EXPERT | OPT_FUNC2, {(void*)opt_map_metadata}, "set metadata information of outfile from infile",
"outfile[,metadata]:infile[,metadata]" },
- { "map_chapters", HAS_ARG | OPT_EXPERT, {(void*)opt_map_chapters}, "set chapters mapping", "outfile:infile" },
- { "t", HAS_ARG, {(void*)opt_recording_time}, "record or transcode \"duration\" seconds of audio/video", "duration" },
- { "fs", HAS_ARG | OPT_INT64, {(void*)&limit_filesize}, "set the limit file size in bytes", "limit_size" }, //
- { "ss", HAS_ARG, {(void*)opt_start_time}, "set the start time offset", "time_off" },
- { "itsoffset", HAS_ARG, {(void*)opt_input_ts_offset}, "set the input ts offset", "time_off" },
- { "itsscale", HAS_ARG, {(void*)opt_input_ts_scale}, "set the input ts scale", "stream:scale" },
- { "timestamp", HAS_ARG, {(void*)opt_recording_timestamp}, "set the recording timestamp ('now' to set the current time)", "time" },
- { "metadata", HAS_ARG, {(void*)opt_metadata}, "add metadata", "string=string" },
- { "dframes", OPT_INT | HAS_ARG, {(void*)&max_frames[AVMEDIA_TYPE_DATA]}, "set the number of data frames to record", "number" },
+ { "map_chapters", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_OFFSET, {.off = OFFSET(chapters_input_file)}, "set chapters mapping", "input_file_index" },
+ { "t", HAS_ARG | OPT_TIME | OPT_OFFSET, {.off = OFFSET(recording_time)}, "record or transcode \"duration\" seconds of audio/video", "duration" },
+ { "fs", HAS_ARG | OPT_INT64 | OPT_OFFSET, {.off = OFFSET(limit_filesize)}, "set the limit file size in bytes", "limit_size" }, //
+ { "ss", HAS_ARG | OPT_TIME | OPT_OFFSET, {.off = OFFSET(start_time)}, "set the start time offset", "time_off" },
+ { "itsoffset", HAS_ARG | OPT_TIME | OPT_OFFSET, {.off = OFFSET(input_ts_offset)}, "set the input ts offset", "time_off" },
+ { "itsscale", HAS_ARG | OPT_DOUBLE | OPT_SPEC, {.off = OFFSET(ts_scale)}, "set the input ts scale", "scale" },
+ { "timestamp", HAS_ARG | OPT_FUNC2, {(void*)opt_recording_timestamp}, "set the recording timestamp ('now' to set the current time)", "time" },
+ { "metadata", HAS_ARG | OPT_STRING | OPT_SPEC, {.off = OFFSET(metadata)}, "add metadata", "string=string" },
+ { "dframes", HAS_ARG | OPT_FUNC2, {(void*)opt_data_frames}, "set the number of data frames to record", "number" },
{ "benchmark", OPT_BOOL | OPT_EXPERT, {(void*)&do_benchmark},
"add timings for benchmarking" },
{ "timelimit", HAS_ARG, {(void*)opt_timelimit}, "set max runtime in seconds", "limit" },
@@ -4307,12 +4308,10 @@ static const OptionDef options[] = {
"dump each input packet" },
{ "hex", OPT_BOOL | OPT_EXPERT, {(void*)&do_hex_dump},
"when dumping packets, also dump the payload" },
- { "re", OPT_BOOL | OPT_EXPERT, {(void*)&rate_emu}, "read input at native frame rate", "" },
- { "loop_input", OPT_BOOL | OPT_EXPERT, {(void*)&loop_input}, "loop (current only works with images)" },
- { "loop_output", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&loop_output}, "number of times to loop output in formats that support looping (0 loops forever)", "" },
- { "v", HAS_ARG, {(void*)opt_verbose}, "set ffmpeg verbosity level", "number" },
- { "target", HAS_ARG, {(void*)opt_target}, "specify target file type (\"vcd\", \"svcd\", \"dvd\", \"dv\", \"dv50\", \"pal-vcd\", \"ntsc-svcd\", ...)", "type" },
- { "threads", HAS_ARG | OPT_EXPERT, {(void*)opt_thread_count}, "thread count", "count" },
+ { "re", OPT_BOOL | OPT_EXPERT | OPT_OFFSET, {.off = OFFSET(rate_emu)}, "read input at native frame rate", "" },
+ { "loop_input", OPT_BOOL | OPT_EXPERT, {(void*)&loop_input}, "deprecated, use -loop" },
+ { "loop_output", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&loop_output}, "deprecated, use -loop", "" },
+ { "target", HAS_ARG | OPT_FUNC2, {(void*)opt_target}, "specify target file type (\"vcd\", \"svcd\", \"dvd\", \"dv\", \"dv50\", \"pal-vcd\", \"ntsc-svcd\", ...)", "type" },
{ "vsync", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&video_sync_method}, "video sync method", "" },
{ "async", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&audio_sync_method}, "audio sync method", "" },
{ "adrift_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, {(void*)&audio_drift_threshold}, "audio drift threshold", "threshold" },
@@ -4320,19 +4319,25 @@ static const OptionDef options[] = {
{ "copytb", OPT_BOOL | OPT_EXPERT, {(void*)&copy_tb}, "copy input stream time base when stream copying" },
{ "shortest", OPT_BOOL | OPT_EXPERT, {(void*)&opt_shortest}, "finish encoding within shortest input" }, //
{ "dts_delta_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, {(void*)&dts_delta_threshold}, "timestamp discontinuity delta threshold", "threshold" },
- { "programid", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&opt_programid}, "desired program number", "" },
{ "xerror", OPT_BOOL, {(void*)&exit_on_error}, "exit on error", "error" },
{ "copyinkf", OPT_BOOL | OPT_EXPERT, {(void*)&copy_initial_nonkeyframes}, "copy initial non-keyframes" },
+ { "frames", OPT_INT64 | HAS_ARG | OPT_SPEC, {.off = OFFSET(max_frames)}, "set the number of frames to record", "number" },
+ { "tag", OPT_STRING | HAS_ARG | OPT_SPEC, {.off = OFFSET(codec_tags)}, "force codec tag/fourcc", "fourcc/tag" },
+ { "q", HAS_ARG | OPT_EXPERT | OPT_DOUBLE | OPT_SPEC, {.off = OFFSET(qscale)}, "use fixed quality scale (VBR)", "q" },
+ { "qscale", HAS_ARG | OPT_EXPERT | OPT_DOUBLE | OPT_SPEC, {.off = OFFSET(qscale)}, "use fixed quality scale (VBR)", "q" },
+#if CONFIG_AVFILTER
+ { "filter", HAS_ARG | OPT_STRING | OPT_SPEC, {.off = OFFSET(filters)}, "set stream filterchain", "filter_list" },
+#endif
+ { "stats", OPT_BOOL, {&print_stats}, "print progress report during encoding", },
/* video options */
- { "b", HAS_ARG | OPT_VIDEO, {(void*)opt_bitrate}, "set bitrate (in bits/s)", "bitrate" },
- { "vb", HAS_ARG | OPT_VIDEO, {(void*)opt_bitrate}, "set bitrate (in bits/s)", "bitrate" },
- { "vframes", OPT_INT | HAS_ARG | OPT_VIDEO, {(void*)&max_frames[AVMEDIA_TYPE_VIDEO]}, "set the number of video frames to record", "number" },
- { "r", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_rate}, "set frame rate (Hz value, fraction or abbreviation)", "rate" },
- { "s", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_size}, "set frame size (WxH or abbreviation)", "size" },
- { "aspect", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_aspect_ratio}, "set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)", "aspect" },
- { "pix_fmt", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_frame_pix_fmt}, "set pixel format, 'list' as argument shows all the pixel formats supported", "format" },
- { "croptop", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_crop}, "Removed, use the crop filter instead", "size" },
+ { "vframes", HAS_ARG | OPT_VIDEO | OPT_FUNC2, {(void*)opt_video_frames}, "set the number of video frames to record", "number" },
+ { "r", HAS_ARG | OPT_VIDEO | OPT_STRING | OPT_SPEC, {.off = OFFSET(frame_rates)}, "set frame rate (Hz value, fraction or abbreviation)", "rate" },
+ { "s", HAS_ARG | OPT_VIDEO | OPT_STRING | OPT_SPEC, {.off = OFFSET(frame_sizes)}, "set frame size (WxH or abbreviation)", "size" },
+ { "aspect", HAS_ARG | OPT_VIDEO | OPT_STRING | OPT_SPEC, {.off = OFFSET(frame_aspect_ratios)}, "set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)", "aspect" },
+ { "pix_fmt", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_STRING | OPT_SPEC, {.off = OFFSET(frame_pix_fmts)}, "set pixel format", "format" },
+ { "bits_per_raw_sample", OPT_INT | HAS_ARG | OPT_VIDEO, {(void*)&frame_bits_per_raw_sample}, "set the number of bits per raw sample", "number" },
+ { "croptop", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_crop}, "Removed, use the crop filter instead", "size" },
{ "cropbottom", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_crop}, "Removed, use the crop filter instead", "size" },
{ "cropleft", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_crop}, "Removed, use the crop filter instead", "size" },
{ "cropright", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_crop}, "Removed, use the crop filter instead", "size" },
@@ -4342,56 +4347,48 @@ static const OptionDef options[] = {
{ "padright", HAS_ARG | OPT_VIDEO, {(void*)opt_pad}, "Removed, use the pad filter instead", "size" },
{ "padcolor", HAS_ARG | OPT_VIDEO, {(void*)opt_pad}, "Removed, use the pad filter instead", "color" },
{ "intra", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&intra_only}, "use only intra frames"},
- { "vn", OPT_BOOL | OPT_VIDEO, {(void*)&video_disable}, "disable video" },
+ { "vn", OPT_BOOL | OPT_VIDEO | OPT_OFFSET, {.off = OFFSET(video_disable)}, "disable video" },
{ "vdt", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)&video_discard}, "discard threshold", "n" },
- { "qscale", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_qscale}, "use fixed video quantizer scale (VBR)", "q" },
- { "rc_override", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_video_rc_override_string}, "rate control override for specific intervals", "override" },
- { "vcodec", HAS_ARG | OPT_VIDEO, {(void*)opt_video_codec}, "force video codec ('copy' to copy stream)", "codec" },
- { "me_threshold", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_me_threshold}, "motion estimaton threshold", "threshold" },
- { "sameq", OPT_BOOL | OPT_VIDEO, {(void*)&same_quality},
+ { "rc_override", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_STRING | OPT_SPEC, {.off = OFFSET(rc_overrides)}, "rate control override for specific intervals", "override" },
+ { "vcodec", HAS_ARG | OPT_VIDEO | OPT_FUNC2, {(void*)opt_video_codec}, "force video codec ('copy' to copy stream)", "codec" },
+ { "sameq", OPT_BOOL | OPT_VIDEO, {(void*)&same_quant}, "use same quantizer as source (implies VBR)" },
+ { "same_quant", OPT_BOOL | OPT_VIDEO, {(void*)&same_quant},
"use same quantizer as source (implies VBR)" },
{ "pass", HAS_ARG | OPT_VIDEO, {(void*)opt_pass}, "select the pass number (1 or 2)", "n" },
- { "passlogfile", HAS_ARG | OPT_STRING | OPT_VIDEO, {(void*)&pass_logfilename_prefix}, "select two pass log file name prefix", "prefix" },
+ { "passlogfile", HAS_ARG | OPT_VIDEO, {(void*)&opt_passlogfile}, "select two pass log file name prefix", "prefix" },
{ "deinterlace", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&do_deinterlace},
"deinterlace pictures" },
- { "psnr", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&do_psnr}, "calculate PSNR of compressed frames" },
{ "vstats", OPT_EXPERT | OPT_VIDEO, {(void*)&opt_vstats}, "dump video coding statistics to file" },
{ "vstats_file", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_vstats_file}, "dump video coding statistics to file", "file" },
#if CONFIG_AVFILTER
- { "vf", OPT_STRING | HAS_ARG, {(void*)&vfilters}, "video filters", "filter list" },
+ { "vf", HAS_ARG | OPT_VIDEO | OPT_FUNC2, {(void*)opt_video_filters}, "video filters", "filter list" },
#endif
- { "intra_matrix", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_intra_matrix}, "specify intra matrix coeffs", "matrix" },
- { "inter_matrix", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_inter_matrix}, "specify inter matrix coeffs", "matrix" },
- { "top", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_top_field_first}, "top=1/bottom=0/auto=-1 field first", "" },
+ { "intra_matrix", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_STRING | OPT_SPEC, {.off = OFFSET(intra_matrices)}, "specify intra matrix coeffs", "matrix" },
+ { "inter_matrix", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_STRING | OPT_SPEC, {.off = OFFSET(inter_matrices)}, "specify inter matrix coeffs", "matrix" },
+ { "top", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_INT| OPT_SPEC, {.off = OFFSET(top_field_first)}, "top=1/bottom=0/auto=-1 field first", "" },
{ "dc", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)&intra_dc_precision}, "intra_dc_precision", "precision" },
- { "vtag", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_codec_tag}, "force video tag/fourcc", "fourcc/tag" },
- { "newvideo", OPT_VIDEO, {(void*)opt_new_stream}, "add a new video stream to the current output stream" },
- { "vlang", HAS_ARG | OPT_STRING | OPT_VIDEO, {(void *)&video_language}, "set the ISO 639 language code (3 letters) of the current video stream" , "code" },
+ { "vtag", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_FUNC2, {(void*)opt_old2new}, "force video tag/fourcc", "fourcc/tag" },
{ "qphist", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, { (void *)&qp_hist }, "show QP histogram" },
- { "force_fps", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&force_fps}, "force the selected framerate, disable the best supported framerate selection" },
- { "streamid", HAS_ARG | OPT_EXPERT, {(void*)opt_streamid}, "set the value of an outfile streamid", "streamIndex:value" },
- { "force_key_frames", OPT_STRING | HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void *)&forced_key_frames}, "force key frames at specified timestamps", "timestamps" },
+ { "force_fps", OPT_BOOL | OPT_EXPERT | OPT_VIDEO | OPT_SPEC, {.off = OFFSET(force_fps)}, "force the selected framerate, disable the best supported framerate selection" },
+ { "streamid", HAS_ARG | OPT_EXPERT | OPT_FUNC2, {(void*)opt_streamid}, "set the value of an outfile streamid", "streamIndex:value" },
+ { "force_key_frames", OPT_STRING | HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_SPEC, {.off = OFFSET(forced_key_frames)}, "force key frames at specified timestamps", "timestamps" },
+ { "b", HAS_ARG | OPT_VIDEO | OPT_FUNC2, {(void*)opt_bitrate}, "video bitrate (please use -b:v)", "bitrate" },
/* audio options */
- { "ab", HAS_ARG | OPT_AUDIO, {(void*)opt_bitrate}, "set bitrate (in bits/s)", "bitrate" },
- { "aframes", OPT_INT | HAS_ARG | OPT_AUDIO, {(void*)&max_frames[AVMEDIA_TYPE_AUDIO]}, "set the number of audio frames to record", "number" },
- { "aq", OPT_FLOAT | HAS_ARG | OPT_AUDIO, {(void*)&audio_qscale}, "set audio quality (codec-specific)", "quality", },
- { "ar", HAS_ARG | OPT_AUDIO, {(void*)opt_audio_rate}, "set audio sampling rate (in Hz)", "rate" },
- { "ac", HAS_ARG | OPT_AUDIO, {(void*)opt_audio_channels}, "set number of audio channels", "channels" },
- { "an", OPT_BOOL | OPT_AUDIO, {(void*)&audio_disable}, "disable audio" },
- { "acodec", HAS_ARG | OPT_AUDIO, {(void*)opt_audio_codec}, "force audio codec ('copy' to copy stream)", "codec" },
- { "atag", HAS_ARG | OPT_EXPERT | OPT_AUDIO, {(void*)opt_codec_tag}, "force audio tag/fourcc", "fourcc/tag" },
+ { "aframes", HAS_ARG | OPT_AUDIO | OPT_FUNC2, {(void*)opt_audio_frames}, "set the number of audio frames to record", "number" },
+ { "aq", HAS_ARG | OPT_AUDIO | OPT_FUNC2, {(void*)opt_audio_qscale}, "set audio quality (codec-specific)", "quality", },
+ { "ar", HAS_ARG | OPT_AUDIO | OPT_INT | OPT_SPEC, {.off = OFFSET(audio_sample_rate)}, "set audio sampling rate (in Hz)", "rate" },
+ { "ac", HAS_ARG | OPT_AUDIO | OPT_INT | OPT_SPEC, {.off = OFFSET(audio_channels)}, "set number of audio channels", "channels" },
+ { "an", OPT_BOOL | OPT_AUDIO | OPT_OFFSET, {.off = OFFSET(audio_disable)}, "disable audio" },
+ { "acodec", HAS_ARG | OPT_AUDIO | OPT_FUNC2, {(void*)opt_audio_codec}, "force audio codec ('copy' to copy stream)", "codec" },
+ { "atag", HAS_ARG | OPT_EXPERT | OPT_AUDIO | OPT_FUNC2, {(void*)opt_old2new}, "force audio tag/fourcc", "fourcc/tag" },
{ "vol", OPT_INT | HAS_ARG | OPT_AUDIO, {(void*)&audio_volume}, "change audio volume (256=normal)" , "volume" }, //
- { "newaudio", OPT_AUDIO, {(void*)opt_new_stream}, "add a new audio stream to the current output stream" },
- { "alang", HAS_ARG | OPT_STRING | OPT_AUDIO, {(void *)&audio_language}, "set the ISO 639 language code (3 letters) of the current audio stream" , "code" },
- { "sample_fmt", HAS_ARG | OPT_EXPERT | OPT_AUDIO, {(void*)opt_audio_sample_fmt}, "set sample format, 'list' as argument shows all the sample formats supported", "format" },
+ { "sample_fmt", HAS_ARG | OPT_EXPERT | OPT_AUDIO | OPT_SPEC | OPT_STRING, {.off = OFFSET(sample_fmts)}, "set sample format", "format" },
/* subtitle options */
- { "sn", OPT_BOOL | OPT_SUBTITLE, {(void*)&subtitle_disable}, "disable subtitle" },
- { "scodec", HAS_ARG | OPT_SUBTITLE, {(void*)opt_subtitle_codec}, "force subtitle codec ('copy' to copy stream)", "codec" },
- { "newsubtitle", OPT_SUBTITLE, {(void*)opt_new_stream}, "add a new subtitle stream to the current output stream" },
- { "slang", HAS_ARG | OPT_STRING | OPT_SUBTITLE, {(void *)&subtitle_language}, "set the ISO 639 language code (3 letters) of the current subtitle stream" , "code" },
- { "stag", HAS_ARG | OPT_EXPERT | OPT_SUBTITLE, {(void*)opt_codec_tag}, "force subtitle tag/fourcc", "fourcc/tag" },
+ { "sn", OPT_BOOL | OPT_SUBTITLE | OPT_OFFSET, {.off = OFFSET(subtitle_disable)}, "disable subtitle" },
+ { "scodec", HAS_ARG | OPT_SUBTITLE | OPT_FUNC2, {(void*)opt_subtitle_codec}, "force subtitle codec ('copy' to copy stream)", "codec" },
+ { "stag", HAS_ARG | OPT_EXPERT | OPT_SUBTITLE | OPT_FUNC2, {(void*)opt_old2new}, "force subtitle tag/fourcc", "fourcc/tag" },
/* grab options */
{ "vc", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_GRAB, {(void*)opt_video_channel}, "deprecated, use -channel", "channel" },
@@ -4399,19 +4396,19 @@ static const OptionDef options[] = {
{ "isync", OPT_BOOL | OPT_EXPERT | OPT_GRAB, {(void*)&input_sync}, "sync read on input", "" },
/* muxer options */
- { "muxdelay", OPT_FLOAT | HAS_ARG | OPT_EXPERT, {(void*)&mux_max_delay}, "set the maximum demux-decode delay", "seconds" },
- { "muxpreload", OPT_FLOAT | HAS_ARG | OPT_EXPERT, {(void*)&mux_preload}, "set the initial demux-decode delay", "seconds" },
+ { "muxdelay", OPT_FLOAT | HAS_ARG | OPT_EXPERT | OPT_OFFSET, {.off = OFFSET(mux_max_delay)}, "set the maximum demux-decode delay", "seconds" },
+ { "muxpreload", OPT_FLOAT | HAS_ARG | OPT_EXPERT | OPT_OFFSET, {.off = OFFSET(mux_preload)}, "set the initial demux-decode delay", "seconds" },
- { "absf", HAS_ARG | OPT_AUDIO | OPT_EXPERT, {(void*)opt_bsf}, "", "bitstream_filter" },
- { "vbsf", HAS_ARG | OPT_VIDEO | OPT_EXPERT, {(void*)opt_bsf}, "", "bitstream_filter" },
- { "sbsf", HAS_ARG | OPT_SUBTITLE | OPT_EXPERT, {(void*)opt_bsf}, "", "bitstream_filter" },
+ { "bsf", HAS_ARG | OPT_STRING | OPT_SPEC, {.off = OFFSET(bitstream_filters)}, "A comma-separated list of bitstream filters", "bitstream_filters" },
+ { "absf", HAS_ARG | OPT_AUDIO | OPT_EXPERT| OPT_FUNC2, {(void*)opt_old2new}, "deprecated", "audio bitstream_filters" },
+ { "vbsf", HAS_ARG | OPT_VIDEO | OPT_EXPERT| OPT_FUNC2, {(void*)opt_old2new}, "deprecated", "video bitstream_filters" },
- { "apre", HAS_ARG | OPT_AUDIO | OPT_EXPERT, {(void*)opt_preset}, "set the audio options to the indicated preset", "preset" },
- { "vpre", HAS_ARG | OPT_VIDEO | OPT_EXPERT, {(void*)opt_preset}, "set the video options to the indicated preset", "preset" },
- { "spre", HAS_ARG | OPT_SUBTITLE | OPT_EXPERT, {(void*)opt_preset}, "set the subtitle options to the indicated preset", "preset" },
- { "fpre", HAS_ARG | OPT_EXPERT, {(void*)opt_preset}, "set options from indicated preset file", "filename" },
+ { "apre", HAS_ARG | OPT_AUDIO | OPT_EXPERT| OPT_FUNC2, {(void*)opt_preset}, "set the audio options to the indicated preset", "preset" },
+ { "vpre", HAS_ARG | OPT_VIDEO | OPT_EXPERT| OPT_FUNC2, {(void*)opt_preset}, "set the video options to the indicated preset", "preset" },
+ { "spre", HAS_ARG | OPT_SUBTITLE | OPT_EXPERT| OPT_FUNC2, {(void*)opt_preset}, "set the subtitle options to the indicated preset", "preset" },
+ { "fpre", HAS_ARG | OPT_EXPERT| OPT_FUNC2, {(void*)opt_preset}, "set options from indicated preset file", "filename" },
/* data codec support */
- { "dcodec", HAS_ARG | OPT_DATA, {(void*)opt_data_codec}, "force data codec ('copy' to copy stream)", "codec" },
+ { "dcodec", HAS_ARG | OPT_DATA | OPT_FUNC2, {(void*)opt_data_codec}, "force data codec ('copy' to copy stream)", "codec" },
{ "default", HAS_ARG | OPT_AUDIO | OPT_VIDEO | OPT_EXPERT, {(void*)opt_default}, "generic catch all option", "" },
{ NULL, },
@@ -4419,9 +4416,20 @@ static const OptionDef options[] = {
int main(int argc, char **argv)
{
+ OptionsContext o = { 0 };
int64_t ti;
+ reset_options(&o, 0);
+
av_log_set_flags(AV_LOG_SKIP_REPEATED);
+ parse_loglevel(argc, argv, options);
+
+ if(argc>1 && !strcmp(argv[1], "-d")){
+ run_as_daemon=1;
+ av_log_set_callback(log_callback_null);
+ argc--;
+ argv++;
+ }
avcodec_register_all();
#if CONFIG_AVDEVICE
@@ -4432,41 +4440,44 @@ int main(int argc, char **argv)
#endif
av_register_all();
- avio_set_interrupt_cb(decode_interrupt_cb);
-
- init_opts();
+#if HAVE_ISATTY
+ if(isatty(STDIN_FILENO))
+ avio_set_interrupt_cb(decode_interrupt_cb);
+#endif
show_banner();
+ term_init();
+
/* parse options */
- parse_options(argc, argv, options, opt_output_file);
+ parse_options(&o, argc, argv, options, opt_output_file);
if(nb_output_files <= 0 && nb_input_files == 0) {
show_usage();
- fprintf(stderr, "Use -h to get full help or, even better, run 'man ffmpeg'\n");
- ffmpeg_exit(1);
+ av_log(NULL, AV_LOG_WARNING, "Use -h to get full help or, even better, run 'man %s'\n", program_name);
+ exit_program(1);
}
/* file converter / grab */
if (nb_output_files <= 0) {
- fprintf(stderr, "At least one output file must be specified\n");
- ffmpeg_exit(1);
+ av_log(NULL, AV_LOG_FATAL, "At least one output file must be specified\n");
+ exit_program(1);
}
if (nb_input_files == 0) {
- fprintf(stderr, "At least one input file must be specified\n");
- ffmpeg_exit(1);
+ av_log(NULL, AV_LOG_FATAL, "At least one input file must be specified\n");
+ exit_program(1);
}
ti = getutime();
- if (transcode(output_files, nb_output_files, input_files, nb_input_files,
- stream_maps, nb_stream_maps) < 0)
- ffmpeg_exit(1);
+ if (transcode(output_files, nb_output_files, input_files, nb_input_files) < 0)
+ exit_program(1);
ti = getutime() - ti;
if (do_benchmark) {
int maxrss = getmaxrss() / 1024;
printf("bench: utime=%0.3fs maxrss=%ikB\n", ti / 1000000.0, maxrss);
}
- return ffmpeg_exit(0);
+ exit_program(0);
+ return 0;
}
diff --git a/ffplay.c b/ffplay.c
index 706ee25d65..b41820c51b 100644
--- a/ffplay.c
+++ b/ffplay.c
@@ -1,21 +1,21 @@
/*
- * ffplay : Simple Media Player based on the Libav libraries
+ * ffplay : Simple Media Player based on the FFmpeg libraries
* Copyright (c) 2003 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -31,26 +31,26 @@
#include "libavutil/dict.h"
#include "libavutil/parseutils.h"
#include "libavutil/samplefmt.h"
+#include "libavutil/avassert.h"
#include "libavformat/avformat.h"
#include "libavdevice/avdevice.h"
#include "libswscale/swscale.h"
#include "libavcodec/audioconvert.h"
#include "libavutil/opt.h"
#include "libavcodec/avfft.h"
+#include "libswresample/swresample.h"
#if CONFIG_AVFILTER
+# include "libavfilter/avcodec.h"
# include "libavfilter/avfilter.h"
# include "libavfilter/avfiltergraph.h"
+# include "libavfilter/buffersink.h"
#endif
-#include "cmdutils.h"
-
#include <SDL.h>
#include <SDL_thread.h>
-#ifdef __MINGW32__
-#undef main /* We don't want SDL to override our main() */
-#endif
+#include "cmdutils.h"
#include <unistd.h>
#include <assert.h>
@@ -71,8 +71,6 @@ const int program_birth_year = 2003;
/* no AV correction is done if too big error */
#define AV_NOSYNC_THRESHOLD 10.0
-#define FRAME_SKIP_FACTOR 0.05
-
/* maximum audio speed change to get correct sync */
#define SAMPLE_CORRECTION_PERCENT_MAX 10
@@ -98,8 +96,9 @@ typedef struct PacketQueue {
typedef struct VideoPicture {
double pts; ///<presentation time stamp for this picture
- double target_clock; ///<av_gettime() time at which this should be displayed ideally
+ double duration; ///<expected duration of the frame
int64_t pos; ///<byte position in file
+ int skip;
SDL_Overlay *bmp;
int width, height; /* source height & width */
int allocated;
@@ -122,7 +121,7 @@ enum {
};
typedef struct VideoState {
- SDL_Thread *parse_tid;
+ SDL_Thread *read_tid;
SDL_Thread *video_tid;
SDL_Thread *refresh_tid;
AVInputFormat *iformat;
@@ -136,7 +135,6 @@ typedef struct VideoState {
int64_t seek_rel;
int read_pause_return;
AVFormatContext *ic;
- int dtg_active_format;
int audio_stream;
@@ -153,18 +151,30 @@ typedef struct VideoState {
PacketQueue audioq;
int audio_hw_buf_size;
/* samples output by the codec. we reserve more space for avsync
- compensation */
- DECLARE_ALIGNED(16,uint8_t,audio_buf1)[(AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 2];
- DECLARE_ALIGNED(16,uint8_t,audio_buf2)[(AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 2];
+ compensation, resampling and format conversion */
+ DECLARE_ALIGNED(16,uint8_t,audio_buf1)[AVCODEC_MAX_AUDIO_FRAME_SIZE * 4];
+ DECLARE_ALIGNED(16,uint8_t,audio_buf2)[AVCODEC_MAX_AUDIO_FRAME_SIZE * 4];
uint8_t *audio_buf;
unsigned int audio_buf_size; /* in bytes */
int audio_buf_index; /* in bytes */
+ int audio_write_buf_size;
AVPacket audio_pkt_temp;
AVPacket audio_pkt;
enum AVSampleFormat audio_src_fmt;
- AVAudioConvert *reformat_ctx;
-
- int show_audio; /* if true, display audio samples */
+ enum AVSampleFormat audio_tgt_fmt;
+ int audio_src_channels;
+ int audio_tgt_channels;
+ int64_t audio_src_channel_layout;
+ int64_t audio_tgt_channel_layout;
+ int audio_src_freq;
+ int audio_tgt_freq;
+ struct SwrContext *swr_ctx;
+ double audio_current_pts;
+ double audio_current_pts_drift;
+
+ enum ShowMode {
+ SHOW_MODE_NONE = -1, SHOW_MODE_VIDEO = 0, SHOW_MODE_WAVES, SHOW_MODE_RDFT, SHOW_MODE_NB
+ } show_mode;
int16_t sample_array[SAMPLE_ARRAY_SIZE];
int sample_array_index;
int last_i_start;
@@ -185,7 +195,7 @@ typedef struct VideoState {
double frame_timer;
double frame_last_pts;
- double frame_last_delay;
+ double frame_last_duration;
double video_clock; ///<pts of last decoded frame / predicted pts of next decoded frame
int video_stream;
AVStream *video_st;
@@ -201,22 +211,18 @@ typedef struct VideoState {
struct SwsContext *img_convert_ctx;
#endif
- // QETimer *video_timer;
char filename[1024];
int width, height, xleft, ytop;
-
- PtsCorrectionContext pts_ctx;
+ int step;
#if CONFIG_AVFILTER
AVFilterContext *out_video_filter; ///<the last filter in the video chain
#endif
- float skip_frames;
- float skip_frames_index;
int refresh;
} VideoState;
-static void show_help(void);
+static int opt_help(const char *opt, const char *arg);
/* options specified by the user */
static AVInputFormat *file_iformat;
@@ -226,9 +232,6 @@ static int fs_screen_width;
static int fs_screen_height;
static int screen_width = 0;
static int screen_height = 0;
-static int frame_width = 0;
-static int frame_height = 0;
-static enum PixelFormat frame_pix_fmt = PIX_FMT_NONE;
static int audio_disable;
static int video_disable;
static int wanted_stream[AVMEDIA_TYPE_NB]={
@@ -242,10 +245,6 @@ static int show_status = 1;
static int av_sync_type = AV_SYNC_AUDIO_MASTER;
static int64_t start_time = AV_NOPTS_VALUE;
static int64_t duration = AV_NOPTS_VALUE;
-static int debug = 0;
-static int debug_mv = 0;
-static int step = 0;
-static int thread_count = 1;
static int workaround_bugs = 1;
static int fast = 0;
static int genpts = 0;
@@ -261,7 +260,11 @@ static int autoexit;
static int exit_on_keydown;
static int exit_on_mousedown;
static int loop=1;
-static int framedrop=1;
+static int framedrop=-1;
+static enum ShowMode show_mode = SHOW_MODE_NONE;
+static const char *audio_codec_name;
+static const char *subtitle_codec_name;
+static const char *video_codec_name;
static int rdftspeed=20;
#if CONFIG_AVFILTER
@@ -270,7 +273,6 @@ static char *vfilters = NULL;
/* current context */
static int is_full_screen;
-static VideoState *cur_stream;
static int64_t audio_callback_time;
static AVPacket flush_pkt;
@@ -281,39 +283,9 @@ static AVPacket flush_pkt;
static SDL_Surface *screen;
-static int packet_queue_put(PacketQueue *q, AVPacket *pkt);
-
-/* packet queue handling */
-static void packet_queue_init(PacketQueue *q)
+void exit_program(int ret)
{
- memset(q, 0, sizeof(PacketQueue));
- q->mutex = SDL_CreateMutex();
- q->cond = SDL_CreateCond();
- packet_queue_put(q, &flush_pkt);
-}
-
-static void packet_queue_flush(PacketQueue *q)
-{
- AVPacketList *pkt, *pkt1;
-
- SDL_LockMutex(q->mutex);
- for(pkt = q->first_pkt; pkt != NULL; pkt = pkt1) {
- pkt1 = pkt->next;
- av_free_packet(&pkt->pkt);
- av_freep(&pkt);
- }
- q->last_pkt = NULL;
- q->first_pkt = NULL;
- q->nb_packets = 0;
- q->size = 0;
- SDL_UnlockMutex(q->mutex);
-}
-
-static void packet_queue_end(PacketQueue *q)
-{
- packet_queue_flush(q);
- SDL_DestroyMutex(q->mutex);
- SDL_DestroyCond(q->cond);
+ exit(ret);
}
static int packet_queue_put(PacketQueue *q, AVPacket *pkt)
@@ -348,6 +320,39 @@ static int packet_queue_put(PacketQueue *q, AVPacket *pkt)
return 0;
}
+/* packet queue handling */
+static void packet_queue_init(PacketQueue *q)
+{
+ memset(q, 0, sizeof(PacketQueue));
+ q->mutex = SDL_CreateMutex();
+ q->cond = SDL_CreateCond();
+ packet_queue_put(q, &flush_pkt);
+}
+
+static void packet_queue_flush(PacketQueue *q)
+{
+ AVPacketList *pkt, *pkt1;
+
+ SDL_LockMutex(q->mutex);
+ for(pkt = q->first_pkt; pkt != NULL; pkt = pkt1) {
+ pkt1 = pkt->next;
+ av_free_packet(&pkt->pkt);
+ av_freep(&pkt);
+ }
+ q->last_pkt = NULL;
+ q->first_pkt = NULL;
+ q->nb_packets = 0;
+ q->size = 0;
+ SDL_UnlockMutex(q->mutex);
+}
+
+static void packet_queue_end(PacketQueue *q)
+{
+ packet_queue_flush(q);
+ SDL_DestroyMutex(q->mutex);
+ SDL_DestroyCond(q->cond);
+}
+
static void packet_queue_abort(PacketQueue *q)
{
SDL_LockMutex(q->mutex);
@@ -653,10 +658,10 @@ static void video_image_display(VideoState *is)
vp = &is->pictq[is->pictq_rindex];
if (vp->bmp) {
#if CONFIG_AVFILTER
- if (vp->picref->video->pixel_aspect.num == 0)
+ if (vp->picref->video->sample_aspect_ratio.num == 0)
aspect_ratio = 0;
else
- aspect_ratio = av_q2d(vp->picref->video->pixel_aspect);
+ aspect_ratio = av_q2d(vp->picref->video->sample_aspect_ratio);
#else
/* XXX: use variable in the frame */
@@ -671,14 +676,11 @@ static void video_image_display(VideoState *is)
aspect_ratio = 1.0;
aspect_ratio *= (float)vp->width / (float)vp->height;
- if (is->subtitle_st)
- {
- if (is->subpq_size > 0)
- {
+ if (is->subtitle_st) {
+ if (is->subpq_size > 0) {
sp = &is->subpq[is->subpq_rindex];
- if (vp->pts >= sp->pts + ((float) sp->sub.start_display_time / 1000))
- {
+ if (vp->pts >= sp->pts + ((float) sp->sub.start_display_time / 1000)) {
SDL_LockYUVOverlay (vp->bmp);
pict.data[0] = vp->bmp->pixels[0];
@@ -711,26 +713,15 @@ static void video_image_display(VideoState *is)
is->no_background = 0;
rect.x = is->xleft + x;
rect.y = is->ytop + y;
- rect.w = width;
- rect.h = height;
+ rect.w = FFMAX(width, 1);
+ rect.h = FFMAX(height, 1);
SDL_DisplayYUVOverlay(vp->bmp, &rect);
}
}
-/* get the current audio output buffer size, in samples. With SDL, we
- cannot have a precise information */
-static int audio_write_get_buf_size(VideoState *is)
-{
- return is->audio_buf_size - is->audio_buf_index;
-}
-
static inline int compute_mod(int a, int b)
{
- a = a % b;
- if (a >= 0)
- return a;
- else
- return a + b;
+ return a < 0 ? a%b + b : a%b;
}
static void video_audio_display(VideoState *s)
@@ -745,19 +736,19 @@ static void video_audio_display(VideoState *s)
nb_freq= 1<<(rdft_bits-1);
/* compute display index : center on currently output samples */
- channels = s->audio_st->codec->channels;
+ channels = s->audio_tgt_channels;
nb_display_channels = channels;
if (!s->paused) {
- int data_used= s->show_audio==1 ? s->width : (2*nb_freq);
+ int data_used= s->show_mode == SHOW_MODE_WAVES ? s->width : (2*nb_freq);
n = 2 * channels;
- delay = audio_write_get_buf_size(s);
+ delay = s->audio_write_buf_size;
delay /= n;
/* to be more precise, we take into account the time spent since
the last buffer computation */
if (audio_callback_time) {
time_diff = av_gettime() - audio_callback_time;
- delay -= (time_diff * s->audio_st->codec->sample_rate) / 1000000;
+ delay -= (time_diff * s->audio_tgt_freq) / 1000000;
}
delay += 2*data_used;
@@ -765,7 +756,7 @@ static void video_audio_display(VideoState *s)
delay = data_used;
i_start= x = compute_mod(s->sample_array_index - delay * channels, SAMPLE_ARRAY_SIZE);
- if(s->show_audio==1){
+ if (s->show_mode == SHOW_MODE_WAVES) {
h= INT_MIN;
for(i=0; i<1000; i+=channels){
int idx= (SAMPLE_ARRAY_SIZE + x - i) % SAMPLE_ARRAY_SIZE;
@@ -787,7 +778,7 @@ static void video_audio_display(VideoState *s)
}
bgcolor = SDL_MapRGB(screen->format, 0x00, 0x00, 0x00);
- if(s->show_audio==1){
+ if (s->show_mode == SHOW_MODE_WAVES) {
fill_rectangle(screen,
s->xleft, s->ytop, s->width, s->height,
bgcolor);
@@ -872,6 +863,57 @@ static void video_audio_display(VideoState *s)
}
}
+static void stream_close(VideoState *is)
+{
+ VideoPicture *vp;
+ int i;
+ /* XXX: use a special url_shutdown call to abort parse cleanly */
+ is->abort_request = 1;
+ SDL_WaitThread(is->read_tid, NULL);
+ SDL_WaitThread(is->refresh_tid, NULL);
+
+ /* free all pictures */
+ for(i=0;i<VIDEO_PICTURE_QUEUE_SIZE; i++) {
+ vp = &is->pictq[i];
+#if CONFIG_AVFILTER
+ if (vp->picref) {
+ avfilter_unref_buffer(vp->picref);
+ vp->picref = NULL;
+ }
+#endif
+ if (vp->bmp) {
+ SDL_FreeYUVOverlay(vp->bmp);
+ vp->bmp = NULL;
+ }
+ }
+ SDL_DestroyMutex(is->pictq_mutex);
+ SDL_DestroyCond(is->pictq_cond);
+ SDL_DestroyMutex(is->subpq_mutex);
+ SDL_DestroyCond(is->subpq_cond);
+#if !CONFIG_AVFILTER
+ if (is->img_convert_ctx)
+ sws_freeContext(is->img_convert_ctx);
+#endif
+ av_free(is);
+}
+
+static void do_exit(VideoState *is)
+{
+ if (is) {
+ stream_close(is);
+ }
+ av_lockmgr_register(NULL);
+ uninit_opts();
+#if CONFIG_AVFILTER
+ avfilter_uninit();
+#endif
+ if (show_status)
+ printf("\n");
+ SDL_Quit();
+ av_log(NULL, AV_LOG_QUIET, "%s", "");
+ exit(0);
+}
+
static int video_open(VideoState *is){
int flags = SDL_HWSURFACE|SDL_ASYNCBLIT|SDL_HWACCEL;
int w,h;
@@ -901,16 +943,10 @@ static int video_open(VideoState *is){
if(screen && is->width == screen->w && screen->w == w
&& is->height== screen->h && screen->h == h)
return 0;
-
-#ifndef __APPLE__
screen = SDL_SetVideoMode(w, h, 0, flags);
-#else
- /* setting bits_per_pixel = 0 or 32 causes blank video on OS X */
- screen = SDL_SetVideoMode(w, h, 24, flags);
-#endif
if (!screen) {
fprintf(stderr, "SDL: could not set video mode - exiting\n");
- return -1;
+ do_exit(is);
}
if (!window_title)
window_title = input_filename;
@@ -926,8 +962,8 @@ static int video_open(VideoState *is){
static void video_display(VideoState *is)
{
if(!screen)
- video_open(cur_stream);
- if (is->audio_st && is->show_audio)
+ video_open(is);
+ if (is->audio_st && is->show_mode != SHOW_MODE_VIDEO)
video_audio_display(is);
else if (is->video_st)
video_image_display(is);
@@ -944,7 +980,8 @@ static int refresh_thread(void *opaque)
is->refresh=1;
SDL_PushEvent(&event);
}
- usleep(is->audio_st && is->show_audio ? rdftspeed*1000 : 5000); //FIXME ideally we should wait the correct time but SDLs event passing is so slow it would be silly
+ //FIXME ideally we should wait the correct time but SDLs event passing is so slow it would be silly
+ usleep(is->audio_st && is->show_mode != SHOW_MODE_VIDEO ? rdftspeed*1000 : 5000);
}
return 0;
}
@@ -952,18 +989,11 @@ static int refresh_thread(void *opaque)
/* get the current audio clock value */
static double get_audio_clock(VideoState *is)
{
- double pts;
- int hw_buf_size, bytes_per_sec;
- pts = is->audio_clock;
- hw_buf_size = audio_write_get_buf_size(is);
- bytes_per_sec = 0;
- if (is->audio_st) {
- bytes_per_sec = is->audio_st->codec->sample_rate *
- 2 * is->audio_st->codec->channels;
+ if (is->paused) {
+ return is->audio_current_pts;
+ } else {
+ return is->audio_current_pts_drift + av_gettime() / 1000000.0;
}
- if (bytes_per_sec)
- pts -= (double)hw_buf_size / bytes_per_sec;
- return pts;
}
/* get the current video clock value */
@@ -1019,7 +1049,7 @@ static void stream_seek(VideoState *is, int64_t pos, int64_t rel, int seek_by_by
}
/* pause or resume the video */
-static void stream_pause(VideoState *is)
+static void stream_toggle_pause(VideoState *is)
{
if (is->paused) {
is->frame_timer += av_gettime() / 1000000.0 + is->video_current_pts_drift - is->video_current_pts;
@@ -1031,19 +1061,9 @@ static void stream_pause(VideoState *is)
is->paused = !is->paused;
}
-static double compute_target_time(double frame_current_pts, VideoState *is)
+static double compute_target_delay(double delay, VideoState *is)
{
- double delay, sync_threshold, diff;
-
- /* compute nominal delay */
- delay = frame_current_pts - is->frame_last_pts;
- if (delay <= 0 || delay >= 10.0) {
- /* if incorrect delay, use previous one */
- delay = is->frame_last_delay;
- } else {
- is->frame_last_delay = delay;
- }
- is->frame_last_pts = frame_current_pts;
+ double sync_threshold, diff;
/* update delay to follow master synchronisation source */
if (((is->av_sync_type == AV_SYNC_AUDIO_MASTER && is->audio_st) ||
@@ -1063,16 +1083,26 @@ static double compute_target_time(double frame_current_pts, VideoState *is)
delay = 2 * delay;
}
}
- is->frame_timer += delay;
- av_dlog(NULL, "video: delay=%0.3f pts=%0.3f A-V=%f\n",
- delay, frame_current_pts, -diff);
+ av_dlog(NULL, "video: delay=%0.3f A-V=%f\n",
+ delay, -diff);
- return is->frame_timer;
+ return delay;
+}
+
+static void pictq_next_picture(VideoState *is) {
+ /* update queue size and signal for next picture */
+ if (++is->pictq_rindex == VIDEO_PICTURE_QUEUE_SIZE)
+ is->pictq_rindex = 0;
+
+ SDL_LockMutex(is->pictq_mutex);
+ is->pictq_size--;
+ SDL_CondSignal(is->pictq_cond);
+ SDL_UnlockMutex(is->pictq_mutex);
}
/* called to display each frame */
-static void video_refresh_timer(void *opaque)
+static void video_refresh(void *opaque)
{
VideoState *is = opaque;
VideoPicture *vp;
@@ -1085,34 +1115,45 @@ retry:
//nothing to do, no picture to display in the que
} else {
double time= av_gettime()/1000000.0;
- double next_target;
+ double last_duration, duration, delay;
/* dequeue the picture */
vp = &is->pictq[is->pictq_rindex];
- if(time < vp->target_clock)
+ if (vp->skip) {
+ pictq_next_picture(is);
+ goto retry;
+ }
+
+ /* compute nominal last_duration */
+ last_duration = vp->pts - is->frame_last_pts;
+ if (last_duration > 0 && last_duration < 10.0) {
+ /* if duration of the last frame was sane, update last_duration in video state */
+ is->frame_last_duration = last_duration;
+ }
+ delay = compute_target_delay(is->frame_last_duration, is);
+
+ if(time < is->frame_timer + delay)
return;
+
+ is->frame_last_pts = vp->pts;
+ if (delay > 0)
+ is->frame_timer += delay * FFMAX(1, floor((time-is->frame_timer) / delay));
+
/* update current video pts */
is->video_current_pts = vp->pts;
is->video_current_pts_drift = is->video_current_pts - time;
is->video_current_pos = vp->pos;
- if(is->pictq_size > 1){
- VideoPicture *nextvp= &is->pictq[(is->pictq_rindex+1)%VIDEO_PICTURE_QUEUE_SIZE];
- assert(nextvp->target_clock >= vp->target_clock);
- next_target= nextvp->target_clock;
- }else{
- next_target= vp->target_clock + is->video_clock - vp->pts; //FIXME pass durations cleanly
+
+ if(is->pictq_size > 1) {
+ VideoPicture *nextvp= &is->pictq[(is->pictq_rindex+1)%VIDEO_PICTURE_QUEUE_SIZE];
+ duration = nextvp->pts - vp->pts; // More accurate this way, 1/time_base is often not reflecting FPS
+ } else {
+ duration = vp->duration;
}
- if(framedrop && time > next_target){
- is->skip_frames *= 1.0 + FRAME_SKIP_FACTOR;
- if(is->pictq_size > 1 || time > next_target + 0.5){
- /* update queue size and signal for next picture */
- if (++is->pictq_rindex == VIDEO_PICTURE_QUEUE_SIZE)
- is->pictq_rindex = 0;
-
- SDL_LockMutex(is->pictq_mutex);
- is->pictq_size--;
- SDL_CondSignal(is->pictq_cond);
- SDL_UnlockMutex(is->pictq_mutex);
+
+ if((framedrop>0 || (framedrop && is->audio_st)) && time > is->frame_timer + duration){
+ if(is->pictq_size > 1){
+ pictq_next_picture(is);
goto retry;
}
}
@@ -1165,14 +1206,7 @@ retry:
if (!display_disable)
video_display(is);
- /* update queue size and signal for next picture */
- if (++is->pictq_rindex == VIDEO_PICTURE_QUEUE_SIZE)
- is->pictq_rindex = 0;
-
- SDL_LockMutex(is->pictq_mutex);
- is->pictq_size--;
- SDL_CondSignal(is->pictq_cond);
- SDL_UnlockMutex(is->pictq_mutex);
+ pictq_next_picture(is);
}
} else if (is->audio_st) {
/* draw the next audio frame */
@@ -1204,65 +1238,20 @@ retry:
av_diff = 0;
if (is->audio_st && is->video_st)
av_diff = get_audio_clock(is) - get_video_clock(is);
- printf("%7.2f A-V:%7.3f s:%3.1f aq=%5dKB vq=%5dKB sq=%5dB f=%"PRId64"/%"PRId64" \r",
- get_master_clock(is), av_diff, FFMAX(is->skip_frames-1, 0), aqsize / 1024, vqsize / 1024, sqsize, is->pts_ctx.num_faulty_dts, is->pts_ctx.num_faulty_pts);
+ printf("%7.2f A-V:%7.3f aq=%5dKB vq=%5dKB sq=%5dB f=%"PRId64"/%"PRId64" \r",
+ get_master_clock(is),
+ av_diff,
+ aqsize / 1024,
+ vqsize / 1024,
+ sqsize,
+ is->video_st ? is->video_st->codec->pts_correction_num_faulty_dts : 0,
+ is->video_st ? is->video_st->codec->pts_correction_num_faulty_pts : 0);
fflush(stdout);
last_time = cur_time;
}
}
}
-static void stream_close(VideoState *is)
-{
- VideoPicture *vp;
- int i;
- /* XXX: use a special url_shutdown call to abort parse cleanly */
- is->abort_request = 1;
- SDL_WaitThread(is->parse_tid, NULL);
- SDL_WaitThread(is->refresh_tid, NULL);
-
- /* free all pictures */
- for(i=0;i<VIDEO_PICTURE_QUEUE_SIZE; i++) {
- vp = &is->pictq[i];
-#if CONFIG_AVFILTER
- if (vp->picref) {
- avfilter_unref_buffer(vp->picref);
- vp->picref = NULL;
- }
-#endif
- if (vp->bmp) {
- SDL_FreeYUVOverlay(vp->bmp);
- vp->bmp = NULL;
- }
- }
- SDL_DestroyMutex(is->pictq_mutex);
- SDL_DestroyCond(is->pictq_cond);
- SDL_DestroyMutex(is->subpq_mutex);
- SDL_DestroyCond(is->subpq_cond);
-#if !CONFIG_AVFILTER
- if (is->img_convert_ctx)
- sws_freeContext(is->img_convert_ctx);
-#endif
- av_free(is);
-}
-
-static void do_exit(void)
-{
- if (cur_stream) {
- stream_close(cur_stream);
- cur_stream = NULL;
- }
- uninit_opts();
-#if CONFIG_AVFILTER
- avfilter_uninit();
-#endif
- if (show_status)
- printf("\n");
- SDL_Quit();
- av_log(NULL, AV_LOG_QUIET, "");
- exit(0);
-}
-
/* allocate a picture (needs to do that in main thread to avoid
potential locking problems */
static void alloc_picture(void *opaque)
@@ -1298,7 +1287,7 @@ static void alloc_picture(void *opaque)
fprintf(stderr, "Error: the video system does not support an image\n"
"size of %dx%d pixels. Try using -lowres or -vf \"scale=w:h\"\n"
"to reduce the image size.\n", vp->width, vp->height );
- do_exit();
+ do_exit(is);
}
SDL_LockMutex(is->pictq_mutex);
@@ -1307,24 +1296,34 @@ static void alloc_picture(void *opaque)
SDL_UnlockMutex(is->pictq_mutex);
}
-/**
- *
- * @param pts the dts of the pkt / pts of the frame and guessed if not known
- */
-static int queue_picture(VideoState *is, AVFrame *src_frame, double pts, int64_t pos)
+static int queue_picture(VideoState *is, AVFrame *src_frame, double pts1, int64_t pos)
{
VideoPicture *vp;
-#if CONFIG_AVFILTER
- AVPicture pict_src;
-#else
- int dst_pix_fmt = PIX_FMT_YUV420P;
+ double frame_delay, pts = pts1;
+
+ /* compute the exact PTS for the picture if it is omitted in the stream
+ * pts1 is the dts of the pkt / pts of the frame */
+ if (pts != 0) {
+ /* update video clock with pts, if present */
+ is->video_clock = pts;
+ } else {
+ pts = is->video_clock;
+ }
+ /* update video clock for next frame */
+ frame_delay = av_q2d(is->video_st->codec->time_base);
+ /* for MPEG2, the frame can be repeated, so we update the
+ clock accordingly */
+ frame_delay += src_frame->repeat_pict * (frame_delay * 0.5);
+ is->video_clock += frame_delay;
+
+#if defined(DEBUG_SYNC) && 0
+ printf("frame_type=%c clock=%0.3f pts=%0.3f\n",
+ av_get_picture_type_char(src_frame->pict_type), pts, pts1);
#endif
+
/* wait until we have space to put a new picture */
SDL_LockMutex(is->pictq_mutex);
- if(is->pictq_size>=VIDEO_PICTURE_QUEUE_SIZE && !is->refresh)
- is->skip_frames= FFMAX(1.0 - FRAME_SKIP_FACTOR, is->skip_frames * (1.0-FRAME_SKIP_FACTOR));
-
while (is->pictq_size >= VIDEO_PICTURE_QUEUE_SIZE &&
!is->videoq.abort_request) {
SDL_CondWait(is->pictq_cond, is->pictq_mutex);
@@ -1336,6 +1335,8 @@ static int queue_picture(VideoState *is, AVFrame *src_frame, double pts, int64_t
vp = &is->pictq[is->pictq_windex];
+ vp->duration = frame_delay;
+
/* alloc or resize hardware picture buffer */
if (!vp->bmp ||
#if CONFIG_AVFILTER
@@ -1360,6 +1361,12 @@ static int queue_picture(VideoState *is, AVFrame *src_frame, double pts, int64_t
while (!vp->allocated && !is->videoq.abort_request) {
SDL_CondWait(is->pictq_cond, is->pictq_mutex);
}
+ /* if the queue is aborted, we have to pop the pending ALLOC event or wait for the allocation to complete */
+ if (is->videoq.abort_request && SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_EVENTMASK(FF_ALLOC_EVENT)) != 1) {
+ while (!vp->allocated) {
+ SDL_CondWait(is->pictq_cond, is->pictq_mutex);
+ }
+ }
SDL_UnlockMutex(is->pictq_mutex);
if (is->videoq.abort_request)
@@ -1388,22 +1395,14 @@ static int queue_picture(VideoState *is, AVFrame *src_frame, double pts, int64_t
pict.linesize[2] = vp->bmp->pitches[1];
#if CONFIG_AVFILTER
- pict_src.data[0] = src_frame->data[0];
- pict_src.data[1] = src_frame->data[1];
- pict_src.data[2] = src_frame->data[2];
-
- pict_src.linesize[0] = src_frame->linesize[0];
- pict_src.linesize[1] = src_frame->linesize[1];
- pict_src.linesize[2] = src_frame->linesize[2];
-
//FIXME use direct rendering
- av_picture_copy(&pict, &pict_src,
+ av_picture_copy(&pict, (AVPicture *)src_frame,
vp->pix_fmt, vp->width, vp->height);
#else
sws_flags = av_get_int(sws_opts, "sws_flags", NULL);
is->img_convert_ctx = sws_getCachedContext(is->img_convert_ctx,
vp->width, vp->height, vp->pix_fmt, vp->width, vp->height,
- dst_pix_fmt, sws_flags, NULL, NULL, NULL);
+ PIX_FMT_YUV420P, sws_flags, NULL, NULL, NULL);
if (is->img_convert_ctx == NULL) {
fprintf(stderr, "Cannot initialize the conversion context\n");
exit(1);
@@ -1416,48 +1415,21 @@ static int queue_picture(VideoState *is, AVFrame *src_frame, double pts, int64_t
vp->pts = pts;
vp->pos = pos;
+ vp->skip = 0;
/* now we can update the picture count */
if (++is->pictq_windex == VIDEO_PICTURE_QUEUE_SIZE)
is->pictq_windex = 0;
SDL_LockMutex(is->pictq_mutex);
- vp->target_clock= compute_target_time(vp->pts, is);
-
is->pictq_size++;
SDL_UnlockMutex(is->pictq_mutex);
}
return 0;
}
-/**
- * compute the exact PTS for the picture if it is omitted in the stream
- * @param pts1 the dts of the pkt / pts of the frame
- */
-static int output_picture2(VideoState *is, AVFrame *src_frame, double pts1, int64_t pos)
-{
- double frame_delay, pts;
-
- pts = pts1;
-
- if (pts != 0) {
- /* update video clock with pts, if present */
- is->video_clock = pts;
- } else {
- pts = is->video_clock;
- }
- /* update video clock for next frame */
- frame_delay = av_q2d(is->video_st->codec->time_base);
- /* for MPEG2, the frame can be repeated, so we update the
- clock accordingly */
- frame_delay += src_frame->repeat_pict * (frame_delay * 0.5);
- is->video_clock += frame_delay;
-
- return queue_picture(is, src_frame, pts, pos);
-}
-
static int get_video_frame(VideoState *is, AVFrame *frame, int64_t *pts, AVPacket *pkt)
{
- int len1, got_picture, i;
+ int got_picture, i;
if (packet_queue_get(&is->videoq, pkt, 1) < 0)
return -1;
@@ -1468,7 +1440,7 @@ static int get_video_frame(VideoState *is, AVFrame *frame, int64_t *pts, AVPacke
SDL_LockMutex(is->pictq_mutex);
//Make sure there are no long delay timers (ideally we should just flush the que but thats harder)
for (i = 0; i < VIDEO_PICTURE_QUEUE_SIZE; i++) {
- is->pictq[i].target_clock= 0;
+ is->pictq[i].skip = 1;
}
while (is->pictq_size && !is->videoq.abort_request) {
SDL_CondWait(is->pictq_cond, is->pictq_mutex);
@@ -1476,22 +1448,17 @@ static int get_video_frame(VideoState *is, AVFrame *frame, int64_t *pts, AVPacke
is->video_current_pos = -1;
SDL_UnlockMutex(is->pictq_mutex);
- init_pts_correction(&is->pts_ctx);
is->frame_last_pts = AV_NOPTS_VALUE;
- is->frame_last_delay = 0;
+ is->frame_last_duration = 0;
is->frame_timer = (double)av_gettime() / 1000000.0;
- is->skip_frames = 1;
- is->skip_frames_index = 0;
return 0;
}
- len1 = avcodec_decode_video2(is->video_st->codec,
- frame, &got_picture,
- pkt);
+ avcodec_decode_video2(is->video_st->codec, frame, &got_picture, pkt);
if (got_picture) {
if (decoder_reorder_pts == -1) {
- *pts = guess_correct_pts(&is->pts_ctx, frame->pkt_pts, frame->pkt_dts);
+ *pts = frame->best_effort_timestamp;
} else if (decoder_reorder_pts) {
*pts = frame->pkt_pts;
} else {
@@ -1502,11 +1469,7 @@ static int get_video_frame(VideoState *is, AVFrame *frame, int64_t *pts, AVPacke
*pts = 0;
}
- is->skip_frames_index += 1;
- if(is->skip_frames_index >= is->skip_frames){
- is->skip_frames_index -= FFMAX(is->skip_frames, 1.0);
- return 1;
- }
+ return 1;
}
return 0;
@@ -1528,6 +1491,8 @@ static int input_get_buffer(AVCodecContext *codec, AVFrame *pic)
unsigned edge;
int pixel_size;
+ av_assert0(codec->flags & CODEC_FLAG_EMU_EDGE);
+
if (codec->codec->capabilities & CODEC_CAP_NEG_LINESIZES)
perms |= AV_PERM_NEG_LINESIZES;
@@ -1540,6 +1505,10 @@ static int input_get_buffer(AVCodecContext *codec, AVFrame *pic)
w = codec->width;
h = codec->height;
+
+ if(av_image_check_size(w, h, 0, codec))
+ return -1;
+
avcodec_align_dimensions2(codec, &w, &h, stride);
edge = codec->flags & CODEC_FLAG_EMU_EDGE ? 0 : avcodec_get_edge_width();
w += edge << 1;
@@ -1606,7 +1575,9 @@ static int input_init(AVFilterContext *ctx, const char *args, void *opaque)
priv->is = opaque;
codec = priv->is->video_st->codec;
codec->opaque = ctx;
- if(codec->codec->capabilities & CODEC_CAP_DR1) {
+ if((codec->codec->capabilities & CODEC_CAP_DR1)
+ ) {
+ av_assert0(codec->flags & CODEC_FLAG_EMU_EDGE);
priv->use_dr1 = 1;
codec->get_buffer = input_get_buffer;
codec->release_buffer = input_release_buffer;
@@ -1638,7 +1609,7 @@ static int input_request_frame(AVFilterLink *link)
if (ret < 0)
return -1;
- if(priv->use_dr1) {
+ if(priv->use_dr1 && priv->frame->opaque) {
picref = avfilter_ref_buffer(priv->frame->opaque, ~0);
} else {
picref = avfilter_get_video_buffer(link, AV_PERM_WRITE, link->w, link->h);
@@ -1648,9 +1619,9 @@ static int input_request_frame(AVFilterLink *link)
}
av_free_packet(&pkt);
+ avfilter_copy_frame_props(picref, priv->frame);
picref->pts = pts;
- picref->pos = pkt.pos;
- picref->video->pixel_aspect = priv->is->video_st->codec->sample_aspect_ratio;
+
avfilter_start_frame(link, picref);
avfilter_draw_slice(link, 0, link->h, 1);
avfilter_end_frame(link);
@@ -1665,18 +1636,20 @@ static int input_query_formats(AVFilterContext *ctx)
priv->is->video_st->codec->pix_fmt, PIX_FMT_NONE
};
- avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts));
+ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts));
return 0;
}
static int input_config_props(AVFilterLink *link)
{
FilterPriv *priv = link->src->priv;
- AVCodecContext *c = priv->is->video_st->codec;
+ AVStream *s = priv->is->video_st;
- link->w = c->width;
- link->h = c->height;
- link->time_base = priv->is->video_st->time_base;
+ link->w = s->codec->width;
+ link->h = s->codec->height;
+ link->sample_aspect_ratio = s->sample_aspect_ratio.num ?
+ s->sample_aspect_ratio : s->codec->sample_aspect_ratio;
+ link->time_base = s->time_base;
return 0;
}
@@ -1704,21 +1677,30 @@ static int configure_video_filters(AVFilterGraph *graph, VideoState *is, const c
{
char sws_flags_str[128];
int ret;
- FFSinkContext ffsink_ctx = { .pix_fmt = PIX_FMT_YUV420P };
+ enum PixelFormat pix_fmts[] = { PIX_FMT_YUV420P, PIX_FMT_NONE };
+ AVBufferSinkParams *buffersink_params = av_buffersink_params_alloc();
AVFilterContext *filt_src = NULL, *filt_out = NULL;
snprintf(sws_flags_str, sizeof(sws_flags_str), "flags=%d", sws_flags);
graph->scale_sws_opts = av_strdup(sws_flags_str);
if ((ret = avfilter_graph_create_filter(&filt_src, &input_filter, "src",
NULL, is, graph)) < 0)
- goto the_end;
- if ((ret = avfilter_graph_create_filter(&filt_out, &ffsink, "out",
- NULL, &ffsink_ctx, graph)) < 0)
- goto the_end;
+ return ret;
+#if FF_API_OLD_VSINK_API
+ ret = avfilter_graph_create_filter(&filt_out, avfilter_get_by_name("buffersink"), "out",
+ NULL, pix_fmts, graph);
+#else
+ buffersink_params->pixel_fmts = pix_fmts;
+ ret = avfilter_graph_create_filter(&filt_out, avfilter_get_by_name("buffersink"), "out",
+ NULL, buffersink_params, graph);
+#endif
+ av_freep(&buffersink_params);
+ if (ret < 0)
+ return ret;
if(vfilters) {
- AVFilterInOut *outputs = av_malloc(sizeof(AVFilterInOut));
- AVFilterInOut *inputs = av_malloc(sizeof(AVFilterInOut));
+ AVFilterInOut *outputs = avfilter_inout_alloc();
+ AVFilterInOut *inputs = avfilter_inout_alloc();
outputs->name = av_strdup("in");
outputs->filter_ctx = filt_src;
@@ -1730,19 +1712,18 @@ static int configure_video_filters(AVFilterGraph *graph, VideoState *is, const c
inputs->pad_idx = 0;
inputs->next = NULL;
- if ((ret = avfilter_graph_parse(graph, vfilters, inputs, outputs, NULL)) < 0)
- goto the_end;
- av_freep(&vfilters);
+ if ((ret = avfilter_graph_parse(graph, vfilters, &inputs, &outputs, NULL)) < 0)
+ return ret;
} else {
if ((ret = avfilter_link(filt_src, 0, filt_out, 0)) < 0)
- goto the_end;
+ return ret;
}
if ((ret = avfilter_graph_config(graph, NULL)) < 0)
- goto the_end;
+ return ret;
is->out_video_filter = filt_out;
-the_end:
+
return ret;
}
@@ -1752,14 +1733,15 @@ static int video_thread(void *arg)
{
VideoState *is = arg;
AVFrame *frame= avcodec_alloc_frame();
- int64_t pts_int;
+ int64_t pts_int = AV_NOPTS_VALUE, pos = -1;
double pts;
int ret;
#if CONFIG_AVFILTER
AVFilterGraph *graph = avfilter_graph_alloc();
AVFilterContext *filt_out = NULL;
- int64_t pos;
+ int last_w = is->video_st->codec->width;
+ int last_h = is->video_st->codec->height;
if ((ret = configure_video_filters(graph, is, vfilters)) < 0)
goto the_end;
@@ -1771,13 +1753,26 @@ static int video_thread(void *arg)
AVPacket pkt;
#else
AVFilterBufferRef *picref;
- AVRational tb;
+ AVRational tb = filt_out->inputs[0]->time_base;
#endif
while (is->paused && !is->videoq.abort_request)
SDL_Delay(10);
#if CONFIG_AVFILTER
- ret = get_filtered_video_frame(filt_out, frame, &picref, &tb);
+ if ( last_w != is->video_st->codec->width
+ || last_h != is->video_st->codec->height) {
+ av_log(NULL, AV_LOG_INFO, "Frame changed from size:%dx%d to size:%dx%d\n",
+ last_w, last_h, is->video_st->codec->width, is->video_st->codec->height);
+ avfilter_graph_free(&graph);
+ graph = avfilter_graph_alloc();
+ if ((ret = configure_video_filters(graph, is, vfilters)) < 0)
+ goto the_end;
+ filt_out = is->out_video_filter;
+ last_w = is->video_st->codec->width;
+ last_h = is->video_st->codec->height;
+ }
+ ret = av_buffersink_get_buffer_ref(filt_out, &picref, 0);
if (picref) {
+ avfilter_fill_frame_from_video_buffer_ref(frame, picref);
pts_int = picref->pts;
pos = picref->pos;
frame->opaque = picref;
@@ -1793,27 +1788,26 @@ static int video_thread(void *arg)
}
#else
ret = get_video_frame(is, frame, &pts_int, &pkt);
+ pos = pkt.pos;
+ av_free_packet(&pkt);
#endif
if (ret < 0) goto the_end;
- if (!ret)
+#if CONFIG_AVFILTER
+ if (!picref)
continue;
+#endif
pts = pts_int*av_q2d(is->video_st->time_base);
-#if CONFIG_AVFILTER
- ret = output_picture2(is, frame, pts, pos);
-#else
- ret = output_picture2(is, frame, pts, pkt.pos);
- av_free_packet(&pkt);
-#endif
+ ret = queue_picture(is, frame, pts, pos);
+
if (ret < 0)
goto the_end;
- if (step)
- if (cur_stream)
- stream_pause(cur_stream);
+ if (is->step)
+ stream_toggle_pause(is);
}
the_end:
#if CONFIG_AVFILTER
@@ -1828,7 +1822,7 @@ static int subtitle_thread(void *arg)
VideoState *is = arg;
SubPicture *sp;
AVPacket pkt1, *pkt = &pkt1;
- int len1, got_subtitle;
+ int got_subtitle;
double pts;
int i, j;
int r, g, b, y, u, v, a;
@@ -1852,7 +1846,7 @@ static int subtitle_thread(void *arg)
SDL_UnlockMutex(is->subpq_mutex);
if (is->subtitleq.abort_request)
- goto the_end;
+ return 0;
sp = &is->subpq[is->subpq_windex];
@@ -1862,9 +1856,9 @@ static int subtitle_thread(void *arg)
if (pkt->pts != AV_NOPTS_VALUE)
pts = av_q2d(is->subtitle_st->time_base)*pkt->pts;
- len1 = avcodec_decode_subtitle2(is->subtitle_st->codec,
- &sp->sub, &got_subtitle,
- pkt);
+ avcodec_decode_subtitle2(is->subtitle_st->codec, &sp->sub,
+ &got_subtitle, pkt);
+
if (got_subtitle && sp->sub.format == 0) {
sp->pts = pts;
@@ -1889,7 +1883,6 @@ static int subtitle_thread(void *arg)
}
av_free_packet(pkt);
}
- the_end:
return 0;
}
@@ -1920,7 +1913,7 @@ static int synchronize_audio(VideoState *is, short *samples,
int n, samples_size;
double ref_clock;
- n = 2 * is->audio_st->codec->channels;
+ n = av_get_bytes_per_sample(is->audio_tgt_fmt) * is->audio_tgt_channels;
samples_size = samples_size1;
/* if not master, then we try to remove or add samples to correct the clock */
@@ -1942,15 +1935,15 @@ static int synchronize_audio(VideoState *is, short *samples,
avg_diff = is->audio_diff_cum * (1.0 - is->audio_diff_avg_coef);
if (fabs(avg_diff) >= is->audio_diff_threshold) {
- wanted_size = samples_size + ((int)(diff * is->audio_st->codec->sample_rate) * n);
+ wanted_size = samples_size + ((int)(diff * is->audio_tgt_freq) * n);
nb_samples = samples_size / n;
min_size = ((nb_samples * (100 - SAMPLE_CORRECTION_PERCENT_MAX)) / 100) * n;
max_size = ((nb_samples * (100 + SAMPLE_CORRECTION_PERCENT_MAX)) / 100) * n;
if (wanted_size < min_size)
wanted_size = min_size;
- else if (wanted_size > max_size)
- wanted_size = max_size;
+ else if (wanted_size > FFMIN3(max_size, sizeof(is->audio_buf1), sizeof(is->audio_buf2)))
+ wanted_size = FFMIN3(max_size, sizeof(is->audio_buf1), sizeof(is->audio_buf2));
/* add or remove samples to correction the synchro */
if (wanted_size < samples_size) {
@@ -1993,12 +1986,18 @@ static int audio_decode_frame(VideoState *is, double *pts_ptr)
AVPacket *pkt_temp = &is->audio_pkt_temp;
AVPacket *pkt = &is->audio_pkt;
AVCodecContext *dec= is->audio_st->codec;
- int n, len1, data_size;
+ int len1, len2, data_size, resampled_data_size;
+ int64_t dec_channel_layout;
double pts;
+ int new_packet = 0;
+ int flush_complete = 0;
for(;;) {
/* NOTE: the audio packet can contain several frames */
- while (pkt_temp->size > 0) {
+ while (pkt_temp->size > 0 || (!pkt_temp->data && new_packet)) {
+ if (flush_complete)
+ break;
+ new_packet = 0;
data_size = sizeof(is->audio_buf1);
len1 = avcodec_decode_audio3(dec,
(int16_t *)is->audio_buf1, &data_size,
@@ -2011,47 +2010,62 @@ static int audio_decode_frame(VideoState *is, double *pts_ptr)
pkt_temp->data += len1;
pkt_temp->size -= len1;
- if (data_size <= 0)
+
+ if (data_size <= 0) {
+ /* stop sending empty packets if the decoder is finished */
+ if (!pkt_temp->data && dec->codec->capabilities & CODEC_CAP_DELAY)
+ flush_complete = 1;
continue;
+ }
- if (dec->sample_fmt != is->audio_src_fmt) {
- if (is->reformat_ctx)
- av_audio_convert_free(is->reformat_ctx);
- is->reformat_ctx= av_audio_convert_alloc(AV_SAMPLE_FMT_S16, 1,
- dec->sample_fmt, 1, NULL, 0);
- if (!is->reformat_ctx) {
- fprintf(stderr, "Cannot convert %s sample format to %s sample format\n",
+ dec_channel_layout = (dec->channel_layout && dec->channels == av_get_channel_layout_nb_channels(dec->channel_layout)) ? dec->channel_layout : av_get_default_channel_layout(dec->channels);
+
+ if (dec->sample_fmt != is->audio_src_fmt || dec_channel_layout != is->audio_src_channel_layout || dec->sample_rate != is->audio_src_freq) {
+ if (is->swr_ctx)
+ swr_free(&is->swr_ctx);
+ is->swr_ctx = swr_alloc2(NULL, is->audio_tgt_channel_layout, is->audio_tgt_fmt, is->audio_tgt_freq,
+ dec_channel_layout, dec->sample_fmt, dec->sample_rate,
+ 0, NULL);
+ if (!is->swr_ctx || swr_init(is->swr_ctx) < 0) {
+ fprintf(stderr, "Cannot create sample rate converter for conversion of %d Hz %s %d channels to %d Hz %s %d channels!\n",
+ dec->sample_rate,
av_get_sample_fmt_name(dec->sample_fmt),
- av_get_sample_fmt_name(AV_SAMPLE_FMT_S16));
- break;
+ dec->channels,
+ is->audio_tgt_freq,
+ av_get_sample_fmt_name(is->audio_tgt_fmt),
+ is->audio_tgt_channels);
+ break;
}
- is->audio_src_fmt= dec->sample_fmt;
+ is->audio_src_channel_layout = dec_channel_layout;
+ is->audio_src_channels = dec->channels;
+ is->audio_src_freq = dec->sample_rate;
+ is->audio_src_fmt = dec->sample_fmt;
}
- if (is->reformat_ctx) {
- const void *ibuf[6]= {is->audio_buf1};
- void *obuf[6]= {is->audio_buf2};
- int istride[6]= {av_get_bytes_per_sample(dec->sample_fmt)};
- int ostride[6]= {2};
- int len= data_size/istride[0];
- if (av_audio_convert(is->reformat_ctx, obuf, ostride, ibuf, istride, len)<0) {
- printf("av_audio_convert() failed\n");
+ resampled_data_size = data_size;
+ if (is->swr_ctx) {
+ const uint8_t *in[] = {is->audio_buf1};
+ uint8_t *out[] = {is->audio_buf2};
+ len2 = swr_convert(is->swr_ctx, out, sizeof(is->audio_buf2) / is->audio_tgt_channels / av_get_bytes_per_sample(is->audio_tgt_fmt),
+ in, data_size / dec->channels / av_get_bytes_per_sample(dec->sample_fmt));
+ if (len2 < 0) {
+ fprintf(stderr, "audio_resample() failed\n");
break;
}
- is->audio_buf= is->audio_buf2;
- /* FIXME: existing code assume that data_size equals framesize*channels*2
- remove this legacy cruft */
- data_size= len*2;
- }else{
+ if (len2 == sizeof(is->audio_buf2) / is->audio_tgt_channels / av_get_bytes_per_sample(is->audio_tgt_fmt)) {
+ fprintf(stderr, "warning: audio buffer is probably too small\n");
+ swr_init(is->swr_ctx);
+ }
+ is->audio_buf = is->audio_buf2;
+ resampled_data_size = len2 * is->audio_tgt_channels * av_get_bytes_per_sample(is->audio_tgt_fmt);
+ } else {
is->audio_buf= is->audio_buf1;
}
/* if no pts, then compute it */
pts = is->audio_clock;
*pts_ptr = pts;
- n = 2 * dec->channels;
- is->audio_clock += (double)data_size /
- (double)(n * dec->sample_rate);
+ is->audio_clock += (double)data_size / (dec->channels * dec->sample_rate * av_get_bytes_per_sample(dec->sample_fmt));
#ifdef DEBUG
{
static double last_clock;
@@ -2061,7 +2075,7 @@ static int audio_decode_frame(VideoState *is, double *pts_ptr)
last_clock = is->audio_clock;
}
#endif
- return data_size;
+ return resampled_data_size;
}
/* free the current packet */
@@ -2073,12 +2087,11 @@ static int audio_decode_frame(VideoState *is, double *pts_ptr)
}
/* read next packet */
- if (packet_queue_get(&is->audioq, pkt, 1) < 0)
+ if ((new_packet = packet_queue_get(&is->audioq, pkt, 1)) < 0)
return -1;
- if(pkt->data == flush_pkt.data){
+
+ if (pkt->data == flush_pkt.data)
avcodec_flush_buffers(dec);
- continue;
- }
pkt_temp->data = pkt->data;
pkt_temp->size = pkt->size;
@@ -2095,6 +2108,7 @@ static void sdl_audio_callback(void *opaque, Uint8 *stream, int len)
{
VideoState *is = opaque;
int audio_size, len1;
+ int bytes_per_sec;
double pts;
audio_callback_time = av_gettime();
@@ -2105,10 +2119,10 @@ static void sdl_audio_callback(void *opaque, Uint8 *stream, int len)
if (audio_size < 0) {
/* if error, just output silence */
is->audio_buf = is->audio_buf1;
- is->audio_buf_size = 1024;
+ is->audio_buf_size = 256 * is->audio_tgt_channels * av_get_bytes_per_sample(is->audio_tgt_fmt);
memset(is->audio_buf, 0, is->audio_buf_size);
} else {
- if (is->show_audio)
+ if (is->show_mode != SHOW_MODE_VIDEO)
update_sample_display(is, (int16_t *)is->audio_buf, audio_size);
audio_size = synchronize_audio(is, (int16_t *)is->audio_buf, audio_size,
pts);
@@ -2124,6 +2138,11 @@ static void sdl_audio_callback(void *opaque, Uint8 *stream, int len)
stream += len1;
is->audio_buf_index += len1;
}
+ bytes_per_sec = is->audio_tgt_freq * is->audio_tgt_channels * av_get_bytes_per_sample(is->audio_tgt_fmt);
+ is->audio_write_buf_size = is->audio_buf_size - is->audio_buf_index;
+ /* Let's assume the audio driver that is used by SDL has two periods. */
+ is->audio_current_pts = is->audio_clock - (double)(2 * is->audio_hw_buf_size + is->audio_write_buf_size) / bytes_per_sec;
+ is->audio_current_pts_drift = is->audio_current_pts - audio_callback_time / 1000000.0;
}
/* open a given stream. Return 0 if OK */
@@ -2133,23 +2152,25 @@ static int stream_component_open(VideoState *is, int stream_index)
AVCodecContext *avctx;
AVCodec *codec;
SDL_AudioSpec wanted_spec, spec;
+ AVDictionary *opts;
+ AVDictionaryEntry *t = NULL;
+ int64_t wanted_channel_layout = 0;
if (stream_index < 0 || stream_index >= ic->nb_streams)
return -1;
avctx = ic->streams[stream_index]->codec;
- /* prepare audio output */
- if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) {
- if (avctx->channels > 0) {
- avctx->request_channels = FFMIN(2, avctx->channels);
- } else {
- avctx->request_channels = 2;
- }
- }
+ opts = filter_codec_opts(codec_opts, avctx->codec_id, ic, ic->streams[stream_index]);
codec = avcodec_find_decoder(avctx->codec_id);
- avctx->debug_mv = debug_mv;
- avctx->debug = debug;
+ switch(avctx->codec_type){
+ case AVMEDIA_TYPE_AUDIO : if(audio_codec_name ) codec= avcodec_find_decoder_by_name( audio_codec_name); break;
+ case AVMEDIA_TYPE_SUBTITLE: if(subtitle_codec_name) codec= avcodec_find_decoder_by_name(subtitle_codec_name); break;
+ case AVMEDIA_TYPE_VIDEO : if(video_codec_name ) codec= avcodec_find_decoder_by_name( video_codec_name); break;
+ }
+ if (!codec)
+ return -1;
+
avctx->workaround_bugs = workaround_bugs;
avctx->lowres = lowres;
if(lowres) avctx->flags |= CODEC_FLAG_EMU_EDGE;
@@ -2160,19 +2181,32 @@ static int stream_component_open(VideoState *is, int stream_index)
avctx->skip_loop_filter= skip_loop_filter;
avctx->error_recognition= error_recognition;
avctx->error_concealment= error_concealment;
- avctx->thread_count= thread_count;
- set_context_opts(avctx, avcodec_opts[avctx->codec_type], 0, codec);
+ if(codec->capabilities & CODEC_CAP_DR1)
+ avctx->flags |= CODEC_FLAG_EMU_EDGE;
+
+ if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) {
+ wanted_channel_layout = (avctx->channel_layout && avctx->channels == av_get_channel_layout_nb_channels(avctx->channels)) ? avctx->channel_layout : av_get_default_channel_layout(avctx->channels);
+ wanted_channel_layout &= ~AV_CH_LAYOUT_STEREO_DOWNMIX;
+ wanted_spec.channels = av_get_channel_layout_nb_channels(wanted_channel_layout);
+ wanted_spec.freq = avctx->sample_rate;
+ if (wanted_spec.freq <= 0 || wanted_spec.channels <= 0) {
+ fprintf(stderr, "Invalid sample rate or channel count!\n");
+ return -1;
+ }
+ }
if (!codec ||
- avcodec_open(avctx, codec) < 0)
+ avcodec_open2(avctx, codec, &opts) < 0)
return -1;
+ if ((t = av_dict_get(opts, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
+ av_log(NULL, AV_LOG_ERROR, "Option %s not found.\n", t->key);
+ return AVERROR_OPTION_NOT_FOUND;
+ }
/* prepare audio output */
if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) {
- wanted_spec.freq = avctx->sample_rate;
wanted_spec.format = AUDIO_S16SYS;
- wanted_spec.channels = avctx->channels;
wanted_spec.silence = 0;
wanted_spec.samples = SDL_AUDIO_BUFFER_SIZE;
wanted_spec.callback = sdl_audio_callback;
@@ -2182,7 +2216,21 @@ static int stream_component_open(VideoState *is, int stream_index)
return -1;
}
is->audio_hw_buf_size = spec.size;
- is->audio_src_fmt= AV_SAMPLE_FMT_S16;
+ if (spec.format != AUDIO_S16SYS) {
+ fprintf(stderr, "SDL advised audio format %d is not supported!\n", spec.format);
+ return -1;
+ }
+ if (spec.channels != wanted_spec.channels) {
+ wanted_channel_layout = av_get_default_channel_layout(spec.channels);
+ if (!wanted_channel_layout) {
+ fprintf(stderr, "SDL advised channel count %d is not supported!\n", spec.channels);
+ return -1;
+ }
+ }
+ is->audio_src_fmt = is->audio_tgt_fmt = AV_SAMPLE_FMT_S16;
+ is->audio_src_freq = is->audio_tgt_freq = spec.freq;
+ is->audio_src_channel_layout = is->audio_tgt_channel_layout = wanted_channel_layout;
+ is->audio_src_channels = is->audio_tgt_channels = spec.channels;
}
ic->streams[stream_index]->discard = AVDISCARD_DEFAULT;
@@ -2198,7 +2246,7 @@ static int stream_component_open(VideoState *is, int stream_index)
is->audio_diff_avg_count = 0;
/* since we do not have a precise anough audio fifo fullness,
we correct audio sync only if larger than this threshold */
- is->audio_diff_threshold = 2.0 * SDL_AUDIO_BUFFER_SIZE / avctx->sample_rate;
+ is->audio_diff_threshold = 2.0 * SDL_AUDIO_BUFFER_SIZE / wanted_spec.freq;
memset(&is->audio_pkt, 0, sizeof(is->audio_pkt));
packet_queue_init(&is->audioq);
@@ -2240,9 +2288,14 @@ static void stream_component_close(VideoState *is, int stream_index)
SDL_CloseAudio();
packet_queue_end(&is->audioq);
- if (is->reformat_ctx)
- av_audio_convert_free(is->reformat_ctx);
- is->reformat_ctx = NULL;
+ if (is->swr_ctx)
+ swr_free(&is->swr_ctx);
+ av_free_packet(&is->audio_pkt);
+
+ if (is->rdft) {
+ av_rdft_end(is->rdft);
+ av_freep(&is->rdft_data);
+ }
break;
case AVMEDIA_TYPE_VIDEO:
packet_queue_abort(&is->videoq);
@@ -2306,7 +2359,7 @@ static int decode_interrupt_cb(void)
}
/* this thread gets the stream from the disk or the network */
-static int decode_thread(void *arg)
+static int read_thread(void *arg)
{
VideoState *is = arg;
AVFormatContext *ic = NULL;
@@ -2316,6 +2369,8 @@ static int decode_thread(void *arg)
int eof=0;
int pkt_in_play_range = 0;
AVDictionaryEntry *t;
+ AVDictionary **opts;
+ int orig_nb_streams;
memset(st_index, -1, sizeof(st_index));
is->video_stream = -1;
@@ -2341,29 +2396,21 @@ static int decode_thread(void *arg)
if(genpts)
ic->flags |= AVFMT_FLAG_GENPTS;
- /* Set AVCodecContext options so they will be seen by av_find_stream_info() */
- for (i = 0; i < ic->nb_streams; i++) {
- AVCodecContext *dec = ic->streams[i]->codec;
- switch (dec->codec_type) {
- case AVMEDIA_TYPE_AUDIO:
- set_context_opts(dec, avcodec_opts[AVMEDIA_TYPE_AUDIO],
- AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_DECODING_PARAM,
- NULL);
- break;
- case AVMEDIA_TYPE_VIDEO:
- set_context_opts(dec, avcodec_opts[AVMEDIA_TYPE_VIDEO],
- AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM,
- NULL);
- break;
- }
- }
+ av_dict_set(&codec_opts, "request_channels", "2", 0);
+
+ opts = setup_find_stream_info_opts(ic, codec_opts);
+ orig_nb_streams = ic->nb_streams;
- err = av_find_stream_info(ic);
+ err = avformat_find_stream_info(ic, opts);
if (err < 0) {
fprintf(stderr, "%s: could not find codec parameters\n", is->filename);
ret = -1;
goto fail;
}
+ for (i = 0; i < orig_nb_streams; i++)
+ av_dict_free(&opts[i]);
+ av_freep(&opts);
+
if(ic->pb)
ic->pb->eof_reached= 0; //FIXME hack, ffplay maybe should not use url_feof() to test for the end
@@ -2409,6 +2456,8 @@ static int decode_thread(void *arg)
av_dump_format(ic, 0, is->filename, 0);
}
+ is->show_mode = show_mode;
+
/* open the streams */
if (st_index[AVMEDIA_TYPE_AUDIO] >= 0) {
stream_component_open(is, st_index[AVMEDIA_TYPE_AUDIO]);
@@ -2419,10 +2468,8 @@ static int decode_thread(void *arg)
ret= stream_component_open(is, st_index[AVMEDIA_TYPE_VIDEO]);
}
is->refresh_tid = SDL_CreateThread(refresh_thread, is);
- if(ret<0) {
- if (!display_disable)
- is->show_audio = 2;
- }
+ if (is->show_mode == SHOW_MODE_NONE)
+ is->show_mode = ret >= 0 ? SHOW_MODE_VIDEO : SHOW_MODE_RDFT;
if (st_index[AVMEDIA_TYPE_SUBTITLE] >= 0) {
stream_component_open(is, st_index[AVMEDIA_TYPE_SUBTITLE]);
@@ -2497,20 +2544,29 @@ static int decode_thread(void *arg)
pkt->stream_index= is->video_stream;
packet_queue_put(&is->videoq, pkt);
}
+ if (is->audio_stream >= 0 &&
+ is->audio_st->codec->codec->capabilities & CODEC_CAP_DELAY) {
+ av_init_packet(pkt);
+ pkt->data = NULL;
+ pkt->size = 0;
+ pkt->stream_index = is->audio_stream;
+ packet_queue_put(&is->audioq, pkt);
+ }
SDL_Delay(10);
if(is->audioq.size + is->videoq.size + is->subtitleq.size ==0){
if(loop!=1 && (!loop || --loop)){
- stream_seek(cur_stream, start_time != AV_NOPTS_VALUE ? start_time : 0, 0, 0);
+ stream_seek(is, start_time != AV_NOPTS_VALUE ? start_time : 0, 0, 0);
}else if(autoexit){
ret=AVERROR_EOF;
goto fail;
}
}
+ eof=0;
continue;
}
ret = av_read_frame(ic, pkt);
if (ret < 0) {
- if (ret == AVERROR_EOF || (ic->pb && ic->pb->eof_reached))
+ if (ret == AVERROR_EOF || url_feof(ic->pb))
eof=1;
if (ic->pb && ic->pb->error)
break;
@@ -2586,8 +2642,8 @@ static VideoState *stream_open(const char *filename, AVInputFormat *iformat)
is->subpq_cond = SDL_CreateCond();
is->av_sync_type = av_sync_type;
- is->parse_tid = SDL_CreateThread(decode_thread, is);
- if (!is->parse_tid) {
+ is->read_tid = SDL_CreateThread(read_thread, is);
+ if (!is->read_tid) {
av_free(is);
return NULL;
}
@@ -2644,43 +2700,38 @@ static void stream_cycle_channel(VideoState *is, int codec_type)
}
-static void toggle_full_screen(void)
+static void toggle_full_screen(VideoState *is)
{
is_full_screen = !is_full_screen;
- video_open(cur_stream);
+ video_open(is);
}
-static void toggle_pause(void)
+static void toggle_pause(VideoState *is)
{
- if (cur_stream)
- stream_pause(cur_stream);
- step = 0;
+ stream_toggle_pause(is);
+ is->step = 0;
}
-static void step_to_next_frame(void)
+static void step_to_next_frame(VideoState *is)
{
- if (cur_stream) {
- /* if the stream is paused unpause it, then step */
- if (cur_stream->paused)
- stream_pause(cur_stream);
- }
- step = 1;
+ /* if the stream is paused unpause it, then step */
+ if (is->paused)
+ stream_toggle_pause(is);
+ is->step = 1;
}
-static void toggle_audio_display(void)
+static void toggle_audio_display(VideoState *is)
{
- if (cur_stream) {
- int bgcolor = SDL_MapRGB(screen->format, 0x00, 0x00, 0x00);
- cur_stream->show_audio = (cur_stream->show_audio + 1) % 3;
- fill_rectangle(screen,
- cur_stream->xleft, cur_stream->ytop, cur_stream->width, cur_stream->height,
- bgcolor);
- SDL_UpdateRect(screen, cur_stream->xleft, cur_stream->ytop, cur_stream->width, cur_stream->height);
- }
+ int bgcolor = SDL_MapRGB(screen->format, 0x00, 0x00, 0x00);
+ is->show_mode = (is->show_mode + 1) % SHOW_MODE_NB;
+ fill_rectangle(screen,
+ is->xleft, is->ytop, is->width, is->height,
+ bgcolor);
+ SDL_UpdateRect(screen, is->xleft, is->ytop, is->width, is->height);
}
/* handle an event sent by the GUI */
-static void event_loop(void)
+static void event_loop(VideoState *cur_stream)
{
SDL_Event event;
double incr, pos, frac;
@@ -2691,38 +2742,35 @@ static void event_loop(void)
switch(event.type) {
case SDL_KEYDOWN:
if (exit_on_keydown) {
- do_exit();
+ do_exit(cur_stream);
break;
}
switch(event.key.keysym.sym) {
case SDLK_ESCAPE:
case SDLK_q:
- do_exit();
+ do_exit(cur_stream);
break;
case SDLK_f:
- toggle_full_screen();
+ toggle_full_screen(cur_stream);
break;
case SDLK_p:
case SDLK_SPACE:
- toggle_pause();
+ toggle_pause(cur_stream);
break;
case SDLK_s: //S: Step to next frame
- step_to_next_frame();
+ step_to_next_frame(cur_stream);
break;
case SDLK_a:
- if (cur_stream)
- stream_cycle_channel(cur_stream, AVMEDIA_TYPE_AUDIO);
+ stream_cycle_channel(cur_stream, AVMEDIA_TYPE_AUDIO);
break;
case SDLK_v:
- if (cur_stream)
- stream_cycle_channel(cur_stream, AVMEDIA_TYPE_VIDEO);
+ stream_cycle_channel(cur_stream, AVMEDIA_TYPE_VIDEO);
break;
case SDLK_t:
- if (cur_stream)
- stream_cycle_channel(cur_stream, AVMEDIA_TYPE_SUBTITLE);
+ stream_cycle_channel(cur_stream, AVMEDIA_TYPE_SUBTITLE);
break;
case SDLK_w:
- toggle_audio_display();
+ toggle_audio_display(cur_stream);
break;
case SDLK_LEFT:
incr = -10.0;
@@ -2736,25 +2784,23 @@ static void event_loop(void)
case SDLK_DOWN:
incr = -60.0;
do_seek:
- if (cur_stream) {
- if (seek_by_bytes) {
- if (cur_stream->video_stream >= 0 && cur_stream->video_current_pos>=0){
- pos= cur_stream->video_current_pos;
- }else if(cur_stream->audio_stream >= 0 && cur_stream->audio_pkt.pos>=0){
- pos= cur_stream->audio_pkt.pos;
- }else
- pos = avio_tell(cur_stream->ic->pb);
- if (cur_stream->ic->bit_rate)
- incr *= cur_stream->ic->bit_rate / 8.0;
- else
- incr *= 180000.0;
- pos += incr;
- stream_seek(cur_stream, pos, incr, 1);
- } else {
- pos = get_master_clock(cur_stream);
- pos += incr;
- stream_seek(cur_stream, (int64_t)(pos * AV_TIME_BASE), (int64_t)(incr * AV_TIME_BASE), 0);
- }
+ if (seek_by_bytes) {
+ if (cur_stream->video_stream >= 0 && cur_stream->video_current_pos>=0){
+ pos= cur_stream->video_current_pos;
+ }else if(cur_stream->audio_stream >= 0 && cur_stream->audio_pkt.pos>=0){
+ pos= cur_stream->audio_pkt.pos;
+ }else
+ pos = avio_tell(cur_stream->ic->pb);
+ if (cur_stream->ic->bit_rate)
+ incr *= cur_stream->ic->bit_rate / 8.0;
+ else
+ incr *= 180000.0;
+ pos += incr;
+ stream_seek(cur_stream, pos, incr, 1);
+ } else {
+ pos = get_master_clock(cur_stream);
+ pos += incr;
+ stream_seek(cur_stream, (int64_t)(pos * AV_TIME_BASE), (int64_t)(incr * AV_TIME_BASE), 0);
}
break;
default:
@@ -2763,7 +2809,7 @@ static void event_loop(void)
break;
case SDL_MOUSEBUTTONDOWN:
if (exit_on_mousedown) {
- do_exit();
+ do_exit(cur_stream);
break;
}
case SDL_MOUSEMOTION:
@@ -2774,50 +2820,46 @@ static void event_loop(void)
break;
x= event.motion.x;
}
- if (cur_stream) {
- if(seek_by_bytes || cur_stream->ic->duration<=0){
- uint64_t size= avio_size(cur_stream->ic->pb);
- stream_seek(cur_stream, size*x/cur_stream->width, 0, 1);
- }else{
- int64_t ts;
- int ns, hh, mm, ss;
- int tns, thh, tmm, tss;
- tns = cur_stream->ic->duration/1000000LL;
- thh = tns/3600;
- tmm = (tns%3600)/60;
- tss = (tns%60);
- frac = x/cur_stream->width;
- ns = frac*tns;
- hh = ns/3600;
- mm = (ns%3600)/60;
- ss = (ns%60);
- fprintf(stderr, "Seek to %2.0f%% (%2d:%02d:%02d) of total duration (%2d:%02d:%02d) \n", frac*100,
- hh, mm, ss, thh, tmm, tss);
- ts = frac*cur_stream->ic->duration;
- if (cur_stream->ic->start_time != AV_NOPTS_VALUE)
- ts += cur_stream->ic->start_time;
- stream_seek(cur_stream, ts, 0, 0);
- }
+ if(seek_by_bytes || cur_stream->ic->duration<=0){
+ uint64_t size= avio_size(cur_stream->ic->pb);
+ stream_seek(cur_stream, size*x/cur_stream->width, 0, 1);
+ }else{
+ int64_t ts;
+ int ns, hh, mm, ss;
+ int tns, thh, tmm, tss;
+ tns = cur_stream->ic->duration/1000000LL;
+ thh = tns/3600;
+ tmm = (tns%3600)/60;
+ tss = (tns%60);
+ frac = x/cur_stream->width;
+ ns = frac*tns;
+ hh = ns/3600;
+ mm = (ns%3600)/60;
+ ss = (ns%60);
+ fprintf(stderr, "Seek to %2.0f%% (%2d:%02d:%02d) of total duration (%2d:%02d:%02d) \n", frac*100,
+ hh, mm, ss, thh, tmm, tss);
+ ts = frac*cur_stream->ic->duration;
+ if (cur_stream->ic->start_time != AV_NOPTS_VALUE)
+ ts += cur_stream->ic->start_time;
+ stream_seek(cur_stream, ts, 0, 0);
}
break;
case SDL_VIDEORESIZE:
- if (cur_stream) {
- screen = SDL_SetVideoMode(event.resize.w, event.resize.h, 0,
- SDL_HWSURFACE|SDL_RESIZABLE|SDL_ASYNCBLIT|SDL_HWACCEL);
- screen_width = cur_stream->width = event.resize.w;
- screen_height= cur_stream->height= event.resize.h;
- }
+ screen = SDL_SetVideoMode(event.resize.w, event.resize.h, 0,
+ SDL_HWSURFACE|SDL_RESIZABLE|SDL_ASYNCBLIT|SDL_HWACCEL);
+ screen_width = cur_stream->width = event.resize.w;
+ screen_height= cur_stream->height= event.resize.h;
break;
case SDL_QUIT:
case FF_QUIT_EVENT:
- do_exit();
+ do_exit(cur_stream);
break;
case FF_ALLOC_EVENT:
video_open(event.user.data1);
alloc_picture(event.user.data1);
break;
case FF_REFRESH_EVENT:
- video_refresh_timer(event.user.data1);
+ video_refresh(event.user.data1);
cur_stream->refresh=0;
break;
default:
@@ -2828,15 +2870,8 @@ static void event_loop(void)
static int opt_frame_size(const char *opt, const char *arg)
{
- if (av_parse_video_size(&frame_width, &frame_height, arg) < 0) {
- fprintf(stderr, "Incorrect frame size\n");
- return AVERROR(EINVAL);
- }
- if ((frame_width % 2) != 0 || (frame_height % 2) != 0) {
- fprintf(stderr, "Frame size must be a multiple of 2\n");
- return AVERROR(EINVAL);
- }
- return 0;
+ av_log(NULL, AV_LOG_WARNING, "Option -s is deprecated, use -video_size.\n");
+ return opt_default("video_size", arg);
}
static int opt_width(const char *opt, const char *arg)
@@ -2863,8 +2898,8 @@ static int opt_format(const char *opt, const char *arg)
static int opt_frame_pix_fmt(const char *opt, const char *arg)
{
- frame_pix_fmt = av_get_pix_fmt(arg);
- return 0;
+ av_log(NULL, AV_LOG_WARNING, "Option -pix_fmt is deprecated, use -pixel_format.\n");
+ return opt_default("pixel_format", arg);
}
static int opt_sync(const char *opt, const char *arg)
@@ -2894,28 +2929,39 @@ static int opt_duration(const char *opt, const char *arg)
return 0;
}
-static int opt_debug(const char *opt, const char *arg)
+static int opt_show_mode(const char *opt, const char *arg)
{
- av_log_set_level(99);
- debug = parse_number_or_die(opt, arg, OPT_INT64, 0, INT_MAX);
+ show_mode = !strcmp(arg, "video") ? SHOW_MODE_VIDEO :
+ !strcmp(arg, "waves") ? SHOW_MODE_WAVES :
+ !strcmp(arg, "rdft" ) ? SHOW_MODE_RDFT :
+ parse_number_or_die(opt, arg, OPT_INT, 0, SHOW_MODE_NB-1);
return 0;
}
-static int opt_vismv(const char *opt, const char *arg)
+static void opt_input_file(void *optctx, const char *filename)
{
- debug_mv = parse_number_or_die(opt, arg, OPT_INT64, INT_MIN, INT_MAX);
- return 0;
+ if (input_filename) {
+ fprintf(stderr, "Argument '%s' provided as input filename, but '%s' was already specified.\n",
+ filename, input_filename);
+ exit_program(1);
+ }
+ if (!strcmp(filename, "-"))
+ filename = "pipe:";
+ input_filename = filename;
}
-static int opt_thread_count(const char *opt, const char *arg)
+static int opt_codec(void *o, const char *opt, const char *arg)
{
- thread_count= parse_number_or_die(opt, arg, OPT_INT64, 0, INT_MAX);
-#if !HAVE_THREADS
- fprintf(stderr, "Warning: not compiled with thread support, using thread emulation\n");
-#endif
+ switch(opt[strlen(opt)-1]){
+ case 'a' : audio_codec_name = arg; break;
+ case 's' : subtitle_codec_name = arg; break;
+ case 'v' : video_codec_name = arg; break;
+ }
return 0;
}
+static int dummy;
+
static const OptionDef options[] = {
#include "cmdutils_common_opts.h"
{ "x", HAS_ARG, {(void*)opt_width}, "force displayed width", "width" },
@@ -2934,9 +2980,7 @@ static const OptionDef options[] = {
{ "f", HAS_ARG, {(void*)opt_format}, "force format", "fmt" },
{ "pix_fmt", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_frame_pix_fmt}, "set pixel format", "format" },
{ "stats", OPT_BOOL | OPT_EXPERT, {(void*)&show_status}, "show status", "" },
- { "debug", HAS_ARG | OPT_EXPERT, {(void*)opt_debug}, "print specific debug info", "" },
{ "bug", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&workaround_bugs}, "workaround bugs", "" },
- { "vismv", HAS_ARG | OPT_EXPERT, {(void*)opt_vismv}, "visualize motion vectors", "" },
{ "fast", OPT_BOOL | OPT_EXPERT, {(void*)&fast}, "non spec compliant optimizations", "" },
{ "genpts", OPT_BOOL | OPT_EXPERT, {(void*)&genpts}, "generate pts", "" },
{ "drp", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&decoder_reorder_pts}, "let decoder reorder pts 0=off 1=on -1=auto", ""},
@@ -2948,7 +2992,6 @@ static const OptionDef options[] = {
{ "er", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&error_recognition}, "set error detection threshold (0-4)", "threshold" },
{ "ec", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&error_concealment}, "set error concealment options", "bit_mask" },
{ "sync", HAS_ARG | OPT_EXPERT, {(void*)opt_sync}, "set audio-video sync. type (type=audio/video/ext)", "type" },
- { "threads", HAS_ARG | OPT_EXPERT, {(void*)opt_thread_count}, "thread count", "count" },
{ "autoexit", OPT_BOOL | OPT_EXPERT, {(void*)&autoexit}, "exit at the end", "" },
{ "exitonkeydown", OPT_BOOL | OPT_EXPERT, {(void*)&exit_on_keydown}, "exit on key down", "" },
{ "exitonmousedown", OPT_BOOL | OPT_EXPERT, {(void*)&exit_on_mousedown}, "exit on mouse down", "" },
@@ -2959,19 +3002,21 @@ static const OptionDef options[] = {
{ "vf", OPT_STRING | HAS_ARG, {(void*)&vfilters}, "video filters", "filter list" },
#endif
{ "rdftspeed", OPT_INT | HAS_ARG| OPT_AUDIO | OPT_EXPERT, {(void*)&rdftspeed}, "rdft speed", "msecs" },
+ { "showmode", HAS_ARG, {(void*)opt_show_mode}, "select show mode (0 = video, 1 = waves, 2 = RDFT)", "mode" },
{ "default", HAS_ARG | OPT_AUDIO | OPT_VIDEO | OPT_EXPERT, {(void*)opt_default}, "generic catch all option", "" },
- { "i", 0, {NULL}, "ffmpeg compatibility dummy option", ""},
+ { "i", OPT_BOOL, {(void *)&dummy}, "read specified file", "input_file"},
+ { "codec", HAS_ARG | OPT_FUNC2, {(void*)opt_codec}, "force decoder", "decoder" },
{ NULL, },
};
static void show_usage(void)
{
printf("Simple media player\n");
- printf("usage: ffplay [options] input_file\n");
+ printf("usage: %s [options] input_file\n", program_name);
printf("\n");
}
-static void show_help(void)
+static int opt_help(const char *opt, const char *arg)
{
av_log_set_callback(log_callback_help);
show_usage();
@@ -2980,15 +3025,10 @@ static void show_help(void)
show_help_options(options, "\nAdvanced options:\n",
OPT_EXPERT, OPT_EXPERT);
printf("\n");
- av_opt_show2(avcodec_opts[0], NULL,
- AV_OPT_FLAG_DECODING_PARAM, 0);
- printf("\n");
- av_opt_show2(avformat_opts, NULL,
- AV_OPT_FLAG_DECODING_PARAM, 0);
+ show_help_children(avcodec_get_class(), AV_OPT_FLAG_DECODING_PARAM);
+ show_help_children(avformat_get_class(), AV_OPT_FLAG_DECODING_PARAM);
#if !CONFIG_AVFILTER
- printf("\n");
- av_opt_show2(sws_opts, NULL,
- AV_OPT_FLAG_ENCODING_PARAM, 0);
+ show_help_children(sws_get_class(), AV_OPT_FLAG_ENCODING_PARAM);
#endif
printf("\nWhile playing:\n"
"q, ESC quit\n"
@@ -3003,26 +3043,36 @@ static void show_help(void)
"down/up seek backward/forward 1 minute\n"
"mouse click seek to percentage in file corresponding to fraction of width\n"
);
+ return 0;
}
-static void opt_input_file(const char *filename)
+static int lockmgr(void **mtx, enum AVLockOp op)
{
- if (input_filename) {
- fprintf(stderr, "Argument '%s' provided as input filename, but '%s' was already specified.\n",
- filename, input_filename);
- exit(1);
- }
- if (!strcmp(filename, "-"))
- filename = "pipe:";
- input_filename = filename;
+ switch(op) {
+ case AV_LOCK_CREATE:
+ *mtx = SDL_CreateMutex();
+ if(!*mtx)
+ return 1;
+ return 0;
+ case AV_LOCK_OBTAIN:
+ return !!SDL_LockMutex(*mtx);
+ case AV_LOCK_RELEASE:
+ return !!SDL_UnlockMutex(*mtx);
+ case AV_LOCK_DESTROY:
+ SDL_DestroyMutex(*mtx);
+ return 0;
+ }
+ return 1;
}
/* Called from the main */
int main(int argc, char **argv)
{
int flags;
+ VideoState *is;
av_log_set_flags(AV_LOG_SKIP_REPEATED);
+ parse_loglevel(argc, argv, options);
/* register all codecs, demux and protocols */
avcodec_register_all();
@@ -3038,12 +3088,12 @@ int main(int argc, char **argv)
show_banner();
- parse_options(argc, argv, options, opt_input_file);
+ parse_options(NULL, argc, argv, options, opt_input_file);
if (!input_filename) {
show_usage();
fprintf(stderr, "An input file must be specified\n");
- fprintf(stderr, "Use -h to get full help or, even better, run 'man ffplay'\n");
+ fprintf(stderr, "Use -h to get full help or, even better, run 'man %s'\n", program_name);
exit(1);
}
@@ -3051,11 +3101,14 @@ int main(int argc, char **argv)
video_disable = 1;
}
flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER;
+ if (audio_disable)
+ flags &= ~SDL_INIT_AUDIO;
#if !defined(__MINGW32__) && !defined(__APPLE__)
flags |= SDL_INIT_EVENTTHREAD; /* Not supported on Windows or Mac OS X */
#endif
if (SDL_Init (flags)) {
fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError());
+ fprintf(stderr, "(Did you set the DISPLAY variable?)\n");
exit(1);
}
@@ -3071,12 +3124,21 @@ int main(int argc, char **argv)
SDL_EventState(SDL_SYSWMEVENT, SDL_IGNORE);
SDL_EventState(SDL_USEREVENT, SDL_IGNORE);
+ if (av_lockmgr_register(lockmgr)) {
+ fprintf(stderr, "Could not initialize lock manager!\n");
+ do_exit(NULL);
+ }
+
av_init_packet(&flush_pkt);
flush_pkt.data= "FLUSH";
- cur_stream = stream_open(input_filename, file_iformat);
+ is = stream_open(input_filename, file_iformat);
+ if (!is) {
+ fprintf(stderr, "Failed to initialize VideoState!\n");
+ do_exit(NULL);
+ }
- event_loop();
+ event_loop(is);
/* never returns */
diff --git a/ffpresets/libvpx-1080p.ffpreset b/ffpresets/libvpx-1080p.ffpreset
new file mode 100644
index 0000000000..47dd7624a7
--- /dev/null
+++ b/ffpresets/libvpx-1080p.ffpreset
@@ -0,0 +1,17 @@
+vcodec=libvpx
+g=120
+rc_lookahead=16
+quality=good
+speed=0
+profile=1
+qmax=51
+qmin=11
+slices=4
+vb=2M
+
+#ignored unless using -pass 2
+maxrate=24M
+minrate=100k
+arnr_max_frames=7
+arnr_strength=5
+arnr_type=3
diff --git a/ffpresets/libvpx-1080p50_60.ffpreset b/ffpresets/libvpx-1080p50_60.ffpreset
new file mode 100644
index 0000000000..8942a125a4
--- /dev/null
+++ b/ffpresets/libvpx-1080p50_60.ffpreset
@@ -0,0 +1,17 @@
+vcodec=libvpx
+g=120
+rc_lookahead=25
+quality=good
+speed=0
+profile=1
+qmax=51
+qmin=11
+slices=4
+vb=2M
+
+#ignored unless using -pass 2
+maxrate=24M
+minrate=100k
+arnr_max_frames=7
+arnr_strength=5
+arnr_type=3
diff --git a/ffpresets/libvpx-360p.ffpreset b/ffpresets/libvpx-360p.ffpreset
new file mode 100644
index 0000000000..0859fb7273
--- /dev/null
+++ b/ffpresets/libvpx-360p.ffpreset
@@ -0,0 +1,16 @@
+vcodec=libvpx
+g=120
+rc_lookahead=16
+quality=good
+speed=0
+profile=0
+qmax=63
+qmin=0
+vb=768k
+
+#ignored unless using -pass 2
+maxrate=1.5M
+minrate=40k
+arnr_max_frames=7
+arnr_strength=5
+arnr_type=3
diff --git a/ffpresets/libvpx-720p.ffpreset b/ffpresets/libvpx-720p.ffpreset
new file mode 100644
index 0000000000..84fe37d952
--- /dev/null
+++ b/ffpresets/libvpx-720p.ffpreset
@@ -0,0 +1,17 @@
+vcodec=libvpx
+g=120
+rc_lookahead=16
+quality=good
+speed=0
+profile=0
+qmax=51
+qmin=11
+slices=4
+vb=2M
+
+#ignored unless using -pass 2
+maxrate=24M
+minrate=100k
+arnr_max_frames=7
+arnr_strength=5
+arnr_type=3
diff --git a/ffpresets/libvpx-720p50_60.ffpreset b/ffpresets/libvpx-720p50_60.ffpreset
new file mode 100644
index 0000000000..848754a753
--- /dev/null
+++ b/ffpresets/libvpx-720p50_60.ffpreset
@@ -0,0 +1,17 @@
+vcodec=libvpx
+g=120
+rc_lookahead=25
+quality=good
+speed=0
+profile=0
+qmax=51
+qmin=11
+slices=4
+vb=2M
+
+#ignored unless using -pass 2
+maxrate=24M
+minrate=100k
+arnr_max_frames=7
+arnr_strength=5
+arnr_type=3
diff --git a/ffpresets/libx264-baseline.ffpreset b/ffpresets/libx264-baseline.ffpreset
deleted file mode 100644
index ee7654bdec..0000000000
--- a/ffpresets/libx264-baseline.ffpreset
+++ /dev/null
@@ -1,4 +0,0 @@
-coder=0
-bf=0
-flags2=-wpred-dct8x8
-wpredp=0
diff --git a/ffpresets/libx264-fast.ffpreset b/ffpresets/libx264-fast.ffpreset
deleted file mode 100644
index 65201331bd..0000000000
--- a/ffpresets/libx264-fast.ffpreset
+++ /dev/null
@@ -1,23 +0,0 @@
-coder=1
-flags=+loop+cgop
-cmp=+chroma
-partitions=+parti8x8+parti4x4+partp8x8+partb8x8
-me_method=hex
-subq=6
-me_range=16
-g=250
-keyint_min=25
-sc_threshold=40
-i_qfactor=0.71
-b_strategy=1
-qcomp=0.6
-qmin=0
-qmax=69
-qdiff=4
-bf=3
-refs=2
-directpred=1
-trellis=1
-flags2=+bpyramid+mixed_refs+wpred+dct8x8+fastpskip
-wpredp=2
-rc_lookahead=30
diff --git a/ffpresets/libx264-fast_firstpass.ffpreset b/ffpresets/libx264-fast_firstpass.ffpreset
deleted file mode 100644
index 6fdb4b9e55..0000000000
--- a/ffpresets/libx264-fast_firstpass.ffpreset
+++ /dev/null
@@ -1,23 +0,0 @@
-coder=1
-flags=+loop+cgop
-cmp=+chroma
-partitions=-parti8x8-parti4x4-partp8x8-partb8x8
-me_method=dia
-subq=2
-me_range=16
-g=250
-keyint_min=25
-sc_threshold=40
-i_qfactor=0.71
-b_strategy=1
-qcomp=0.6
-qmin=0
-qmax=69
-qdiff=4
-bf=3
-refs=1
-directpred=1
-trellis=0
-flags2=+bpyramid-mixed_refs+wpred-dct8x8+fastpskip
-wpredp=2
-rc_lookahead=30
diff --git a/ffpresets/libx264-faster.ffpreset b/ffpresets/libx264-faster.ffpreset
deleted file mode 100644
index 52efc1a325..0000000000
--- a/ffpresets/libx264-faster.ffpreset
+++ /dev/null
@@ -1,23 +0,0 @@
-coder=1
-flags=+loop+cgop
-cmp=+chroma
-partitions=+parti8x8+parti4x4+partp8x8+partb8x8
-me_method=hex
-subq=4
-me_range=16
-g=250
-keyint_min=25
-sc_threshold=40
-i_qfactor=0.71
-b_strategy=1
-qcomp=0.6
-qmin=0
-qmax=69
-qdiff=4
-bf=3
-refs=2
-directpred=1
-trellis=1
-flags2=+bpyramid-mixed_refs+wpred+dct8x8+fastpskip
-wpredp=1
-rc_lookahead=20
diff --git a/ffpresets/libx264-faster_firstpass.ffpreset b/ffpresets/libx264-faster_firstpass.ffpreset
deleted file mode 100644
index 41a87fb6b3..0000000000
--- a/ffpresets/libx264-faster_firstpass.ffpreset
+++ /dev/null
@@ -1,23 +0,0 @@
-coder=1
-flags=+loop+cgop
-cmp=+chroma
-partitions=-parti8x8-parti4x4-partp8x8-partb8x8
-me_method=dia
-subq=2
-me_range=16
-g=250
-keyint_min=25
-sc_threshold=40
-i_qfactor=0.71
-b_strategy=1
-qcomp=0.6
-qmin=0
-qmax=69
-qdiff=4
-bf=3
-refs=1
-directpred=1
-trellis=0
-flags2=+bpyramid-mixed_refs+wpred-dct8x8+fastpskip
-wpredp=1
-rc_lookahead=20
diff --git a/ffpresets/libx264-ipod320.ffpreset b/ffpresets/libx264-ipod320.ffpreset
deleted file mode 100644
index 943b521348..0000000000
--- a/ffpresets/libx264-ipod320.ffpreset
+++ /dev/null
@@ -1,7 +0,0 @@
-coder=0
-bf=0
-flags2=-wpred-dct8x8
-level=13
-maxrate=768000
-bufsize=3000000
-wpredp=0
diff --git a/ffpresets/libx264-ipod640.ffpreset b/ffpresets/libx264-ipod640.ffpreset
deleted file mode 100644
index 1ed3d9fb28..0000000000
--- a/ffpresets/libx264-ipod640.ffpreset
+++ /dev/null
@@ -1,8 +0,0 @@
-coder=0
-bf=0
-refs=1
-flags2=-wpred-dct8x8
-level=30
-maxrate=10000000
-bufsize=10000000
-wpredp=0
diff --git a/ffpresets/libx264-lossless_fast.ffpreset b/ffpresets/libx264-lossless_fast.ffpreset
deleted file mode 100644
index 49b9ed1add..0000000000
--- a/ffpresets/libx264-lossless_fast.ffpreset
+++ /dev/null
@@ -1,20 +0,0 @@
-coder=0
-flags=+loop+cgop
-cmp=+chroma
-partitions=-parti8x8+parti4x4+partp8x8-partp4x4-partb8x8
-me_method=hex
-subq=3
-me_range=16
-g=250
-keyint_min=25
-sc_threshold=40
-i_qfactor=0.71
-b_strategy=1
-qcomp=0.6
-qmin=0
-qmax=69
-qdiff=4
-directpred=1
-flags2=+fastpskip
-cqp=0
-wpredp=0
diff --git a/ffpresets/libx264-lossless_max.ffpreset b/ffpresets/libx264-lossless_max.ffpreset
deleted file mode 100644
index f32d7b40c6..0000000000
--- a/ffpresets/libx264-lossless_max.ffpreset
+++ /dev/null
@@ -1,21 +0,0 @@
-coder=1
-flags=+loop+cgop
-cmp=+chroma
-partitions=+parti8x8+parti4x4+partp8x8+partp4x4-partb8x8
-me_method=esa
-subq=8
-me_range=16
-g=250
-keyint_min=25
-sc_threshold=40
-i_qfactor=0.71
-b_strategy=1
-qcomp=0.6
-qmin=0
-qmax=69
-qdiff=4
-refs=16
-directpred=1
-flags2=+mixed_refs+dct8x8+fastpskip
-cqp=0
-wpredp=2
diff --git a/ffpresets/libx264-lossless_medium.ffpreset b/ffpresets/libx264-lossless_medium.ffpreset
deleted file mode 100644
index 0b84612fcb..0000000000
--- a/ffpresets/libx264-lossless_medium.ffpreset
+++ /dev/null
@@ -1,20 +0,0 @@
-coder=1
-flags=+loop+cgop
-cmp=+chroma
-partitions=-parti8x8+parti4x4+partp8x8+partp4x4-partb8x8
-me_method=hex
-subq=5
-me_range=16
-g=250
-keyint_min=25
-sc_threshold=40
-i_qfactor=0.71
-b_strategy=1
-qcomp=0.6
-qmin=0
-qmax=69
-qdiff=4
-directpred=1
-flags2=+fastpskip
-cqp=0
-wpredp=2
diff --git a/ffpresets/libx264-lossless_slow.ffpreset b/ffpresets/libx264-lossless_slow.ffpreset
deleted file mode 100644
index 857d3d1986..0000000000
--- a/ffpresets/libx264-lossless_slow.ffpreset
+++ /dev/null
@@ -1,21 +0,0 @@
-coder=1
-flags=+loop+cgop
-cmp=+chroma
-partitions=+parti8x8+parti4x4+partp8x8+partp4x4-partb8x8
-me_method=umh
-subq=6
-me_range=16
-g=250
-keyint_min=25
-sc_threshold=40
-i_qfactor=0.71
-b_strategy=1
-qcomp=0.6
-qmin=0
-qmax=69
-qdiff=4
-refs=2
-directpred=1
-flags2=+dct8x8+fastpskip
-cqp=0
-wpredp=2
diff --git a/ffpresets/libx264-lossless_slower.ffpreset b/ffpresets/libx264-lossless_slower.ffpreset
deleted file mode 100644
index ef0609f1b6..0000000000
--- a/ffpresets/libx264-lossless_slower.ffpreset
+++ /dev/null
@@ -1,21 +0,0 @@
-coder=1
-flags=+loop+cgop
-cmp=+chroma
-partitions=+parti8x8+parti4x4+partp8x8+partp4x4-partb8x8
-me_method=umh
-subq=8
-me_range=16
-g=250
-keyint_min=25
-sc_threshold=40
-i_qfactor=0.71
-b_strategy=1
-qcomp=0.6
-qmin=0
-qmax=69
-qdiff=4
-refs=4
-directpred=1
-flags2=+mixed_refs+dct8x8+fastpskip
-cqp=0
-wpredp=2
diff --git a/ffpresets/libx264-lossless_ultrafast.ffpreset b/ffpresets/libx264-lossless_ultrafast.ffpreset
deleted file mode 100644
index 4cc84f1b4f..0000000000
--- a/ffpresets/libx264-lossless_ultrafast.ffpreset
+++ /dev/null
@@ -1,19 +0,0 @@
-coder=0
-flags=+loop+cgop
-cmp=+chroma
-partitions=-parti8x8-parti4x4-partp8x8-partp4x4-partb8x8
-me_method=dia
-subq=0
-me_range=16
-g=250
-keyint_min=25
-sc_threshold=40
-i_qfactor=0.71
-b_strategy=1
-qcomp=0.6
-qmin=0
-qmax=69
-qdiff=4
-directpred=1
-flags2=+fastpskip
-cqp=0
diff --git a/ffpresets/libx264-main.ffpreset b/ffpresets/libx264-main.ffpreset
deleted file mode 100644
index d1dc7ddae9..0000000000
--- a/ffpresets/libx264-main.ffpreset
+++ /dev/null
@@ -1 +0,0 @@
-flags2=-dct8x8
diff --git a/ffpresets/libx264-medium.ffpreset b/ffpresets/libx264-medium.ffpreset
deleted file mode 100644
index 685995226d..0000000000
--- a/ffpresets/libx264-medium.ffpreset
+++ /dev/null
@@ -1,22 +0,0 @@
-coder=1
-flags=+loop+cgop
-cmp=+chroma
-partitions=+parti8x8+parti4x4+partp8x8+partb8x8
-me_method=hex
-subq=7
-me_range=16
-g=250
-keyint_min=25
-sc_threshold=40
-i_qfactor=0.71
-b_strategy=1
-qcomp=0.6
-qmin=0
-qmax=69
-qdiff=4
-bf=3
-refs=3
-directpred=1
-trellis=1
-flags2=+bpyramid+mixed_refs+wpred+dct8x8+fastpskip
-wpredp=2
diff --git a/ffpresets/libx264-medium_firstpass.ffpreset b/ffpresets/libx264-medium_firstpass.ffpreset
deleted file mode 100644
index ca304ee24d..0000000000
--- a/ffpresets/libx264-medium_firstpass.ffpreset
+++ /dev/null
@@ -1,22 +0,0 @@
-coder=1
-flags=+loop+cgop
-cmp=+chroma
-partitions=-parti8x8-parti4x4-partp8x8-partb8x8
-me_method=dia
-subq=2
-me_range=16
-g=250
-keyint_min=25
-sc_threshold=40
-i_qfactor=0.71
-b_strategy=1
-qcomp=0.6
-qmin=0
-qmax=69
-qdiff=4
-bf=3
-refs=1
-directpred=1
-trellis=0
-flags2=+bpyramid-mixed_refs+wpred-dct8x8+fastpskip
-wpredp=2
diff --git a/ffpresets/libx264-placebo.ffpreset b/ffpresets/libx264-placebo.ffpreset
deleted file mode 100644
index 7923a76c74..0000000000
--- a/ffpresets/libx264-placebo.ffpreset
+++ /dev/null
@@ -1,23 +0,0 @@
-coder=1
-flags=+loop+cgop
-cmp=+chroma
-partitions=+parti8x8+parti4x4+partp8x8+partp4x4+partb8x8
-me_method=tesa
-subq=10
-me_range=24
-g=250
-keyint_min=25
-sc_threshold=40
-i_qfactor=0.71
-b_strategy=2
-qcomp=0.6
-qmin=0
-qmax=69
-qdiff=4
-bf=16
-refs=16
-directpred=3
-trellis=2
-flags2=+bpyramid+mixed_refs+wpred+dct8x8-fastpskip
-wpredp=2
-rc_lookahead=60
diff --git a/ffpresets/libx264-placebo_firstpass.ffpreset b/ffpresets/libx264-placebo_firstpass.ffpreset
deleted file mode 100644
index 7923a76c74..0000000000
--- a/ffpresets/libx264-placebo_firstpass.ffpreset
+++ /dev/null
@@ -1,23 +0,0 @@
-coder=1
-flags=+loop+cgop
-cmp=+chroma
-partitions=+parti8x8+parti4x4+partp8x8+partp4x4+partb8x8
-me_method=tesa
-subq=10
-me_range=24
-g=250
-keyint_min=25
-sc_threshold=40
-i_qfactor=0.71
-b_strategy=2
-qcomp=0.6
-qmin=0
-qmax=69
-qdiff=4
-bf=16
-refs=16
-directpred=3
-trellis=2
-flags2=+bpyramid+mixed_refs+wpred+dct8x8-fastpskip
-wpredp=2
-rc_lookahead=60
diff --git a/ffpresets/libx264-slow.ffpreset b/ffpresets/libx264-slow.ffpreset
deleted file mode 100644
index fcbef4bcfc..0000000000
--- a/ffpresets/libx264-slow.ffpreset
+++ /dev/null
@@ -1,23 +0,0 @@
-coder=1
-flags=+loop+cgop
-cmp=+chroma
-partitions=+parti8x8+parti4x4+partp8x8+partb8x8
-me_method=umh
-subq=8
-me_range=16
-g=250
-keyint_min=25
-sc_threshold=40
-i_qfactor=0.71
-b_strategy=2
-qcomp=0.6
-qmin=0
-qmax=69
-qdiff=4
-bf=3
-refs=5
-directpred=3
-trellis=1
-flags2=+bpyramid+mixed_refs+wpred+dct8x8+fastpskip
-wpredp=2
-rc_lookahead=50
diff --git a/ffpresets/libx264-slow_firstpass.ffpreset b/ffpresets/libx264-slow_firstpass.ffpreset
deleted file mode 100644
index 74f87b0c2d..0000000000
--- a/ffpresets/libx264-slow_firstpass.ffpreset
+++ /dev/null
@@ -1,23 +0,0 @@
-coder=1
-flags=+loop+cgop
-cmp=+chroma
-partitions=-parti8x8-parti4x4-partp8x8-partb8x8
-me_method=dia
-subq=2
-me_range=16
-g=250
-keyint_min=25
-sc_threshold=40
-i_qfactor=0.71
-b_strategy=2
-qcomp=0.6
-qmin=0
-qmax=69
-qdiff=4
-bf=3
-refs=1
-directpred=3
-trellis=0
-flags2=+bpyramid-mixed_refs+wpred-dct8x8+fastpskip
-wpredp=2
-rc_lookahead=50
diff --git a/ffpresets/libx264-slower.ffpreset b/ffpresets/libx264-slower.ffpreset
deleted file mode 100644
index 741d21f920..0000000000
--- a/ffpresets/libx264-slower.ffpreset
+++ /dev/null
@@ -1,23 +0,0 @@
-coder=1
-flags=+loop+cgop
-cmp=+chroma
-partitions=+parti8x8+parti4x4+partp8x8+partp4x4+partb8x8
-me_method=umh
-subq=9
-me_range=16
-g=250
-keyint_min=25
-sc_threshold=40
-i_qfactor=0.71
-b_strategy=2
-qcomp=0.6
-qmin=0
-qmax=69
-qdiff=4
-bf=3
-refs=8
-directpred=3
-trellis=2
-flags2=+bpyramid+mixed_refs+wpred+dct8x8+fastpskip
-wpredp=2
-rc_lookahead=60
diff --git a/ffpresets/libx264-slower_firstpass.ffpreset b/ffpresets/libx264-slower_firstpass.ffpreset
deleted file mode 100644
index 0be886a156..0000000000
--- a/ffpresets/libx264-slower_firstpass.ffpreset
+++ /dev/null
@@ -1,23 +0,0 @@
-coder=1
-flags=+loop+cgop
-cmp=+chroma
-partitions=-parti8x8-parti4x4-partp8x8-partb8x8
-me_method=dia
-subq=2
-me_range=16
-g=250
-keyint_min=25
-sc_threshold=40
-i_qfactor=0.71
-b_strategy=2
-qcomp=0.6
-qmin=0
-qmax=69
-qdiff=4
-bf=3
-refs=1
-directpred=3
-trellis=0
-flags2=+bpyramid-mixed_refs+wpred-dct8x8+fastpskip
-wpredp=2
-rc_lookahead=60
diff --git a/ffpresets/libx264-superfast.ffpreset b/ffpresets/libx264-superfast.ffpreset
deleted file mode 100644
index 7f0f50b782..0000000000
--- a/ffpresets/libx264-superfast.ffpreset
+++ /dev/null
@@ -1,23 +0,0 @@
-coder=1
-flags=+loop+cgop
-cmp=+chroma
-partitions=+parti8x8+parti4x4-partp8x8-partb8x8
-me_method=dia
-subq=1
-me_range=16
-g=250
-keyint_min=25
-sc_threshold=40
-i_qfactor=0.71
-b_strategy=1
-qcomp=0.6
-qmin=0
-qmax=69
-qdiff=4
-bf=3
-refs=1
-directpred=1
-trellis=0
-flags2=+bpyramid-mixed_refs+wpred+dct8x8+fastpskip-mbtree
-wpredp=0
-rc_lookahead=0
diff --git a/ffpresets/libx264-superfast_firstpass.ffpreset b/ffpresets/libx264-superfast_firstpass.ffpreset
deleted file mode 100644
index 87b4f29012..0000000000
--- a/ffpresets/libx264-superfast_firstpass.ffpreset
+++ /dev/null
@@ -1,23 +0,0 @@
-coder=1
-flags=+loop+cgop
-cmp=+chroma
-partitions=-parti8x8-parti4x4-partp8x8-partb8x8
-me_method=dia
-subq=1
-me_range=16
-g=250
-keyint_min=25
-sc_threshold=40
-i_qfactor=0.71
-b_strategy=1
-qcomp=0.6
-qmin=0
-qmax=69
-qdiff=4
-bf=3
-refs=1
-directpred=1
-trellis=0
-flags2=+bpyramid-mixed_refs+wpred-dct8x8+fastpskip-mbtree
-wpredp=0
-rc_lookahead=0
diff --git a/ffpresets/libx264-ultrafast.ffpreset b/ffpresets/libx264-ultrafast.ffpreset
deleted file mode 100644
index 561191e399..0000000000
--- a/ffpresets/libx264-ultrafast.ffpreset
+++ /dev/null
@@ -1,24 +0,0 @@
-coder=0
-flags=-loop+cgop
-cmp=+chroma
-partitions=-parti8x8-parti4x4-partp8x8-partb8x8
-me_method=dia
-subq=0
-me_range=16
-g=250
-keyint_min=25
-sc_threshold=0
-i_qfactor=0.71
-b_strategy=0
-qcomp=0.6
-qmin=0
-qmax=69
-qdiff=4
-bf=0
-refs=1
-directpred=1
-trellis=0
-flags2=-bpyramid-mixed_refs-wpred-dct8x8+fastpskip-mbtree
-wpredp=0
-aq_mode=0
-rc_lookahead=0
diff --git a/ffpresets/libx264-ultrafast_firstpass.ffpreset b/ffpresets/libx264-ultrafast_firstpass.ffpreset
deleted file mode 100644
index 561191e399..0000000000
--- a/ffpresets/libx264-ultrafast_firstpass.ffpreset
+++ /dev/null
@@ -1,24 +0,0 @@
-coder=0
-flags=-loop+cgop
-cmp=+chroma
-partitions=-parti8x8-parti4x4-partp8x8-partb8x8
-me_method=dia
-subq=0
-me_range=16
-g=250
-keyint_min=25
-sc_threshold=0
-i_qfactor=0.71
-b_strategy=0
-qcomp=0.6
-qmin=0
-qmax=69
-qdiff=4
-bf=0
-refs=1
-directpred=1
-trellis=0
-flags2=-bpyramid-mixed_refs-wpred-dct8x8+fastpskip-mbtree
-wpredp=0
-aq_mode=0
-rc_lookahead=0
diff --git a/ffpresets/libx264-veryfast.ffpreset b/ffpresets/libx264-veryfast.ffpreset
deleted file mode 100644
index d8c7f7a371..0000000000
--- a/ffpresets/libx264-veryfast.ffpreset
+++ /dev/null
@@ -1,23 +0,0 @@
-coder=1
-flags=+loop+cgop
-cmp=+chroma
-partitions=+parti8x8+parti4x4+partp8x8+partb8x8
-me_method=hex
-subq=2
-me_range=16
-g=250
-keyint_min=25
-sc_threshold=40
-i_qfactor=0.71
-b_strategy=1
-qcomp=0.6
-qmin=0
-qmax=69
-qdiff=4
-bf=3
-refs=1
-directpred=1
-trellis=0
-flags2=+bpyramid-mixed_refs+wpred+dct8x8+fastpskip
-wpredp=0
-rc_lookahead=10
diff --git a/ffpresets/libx264-veryfast_firstpass.ffpreset b/ffpresets/libx264-veryfast_firstpass.ffpreset
deleted file mode 100644
index 7b2a1e93d2..0000000000
--- a/ffpresets/libx264-veryfast_firstpass.ffpreset
+++ /dev/null
@@ -1,23 +0,0 @@
-coder=1
-flags=+loop+cgop
-cmp=+chroma
-partitions=-parti8x8-parti4x4-partp8x8-partb8x8
-me_method=dia
-subq=2
-me_range=16
-g=250
-keyint_min=25
-sc_threshold=40
-i_qfactor=0.71
-b_strategy=1
-qcomp=0.6
-qmin=0
-qmax=69
-qdiff=4
-bf=3
-refs=1
-directpred=1
-trellis=0
-flags2=+bpyramid-mixed_refs+wpred-dct8x8+fastpskip
-wpredp=0
-rc_lookahead=10
diff --git a/ffpresets/libx264-veryslow.ffpreset b/ffpresets/libx264-veryslow.ffpreset
deleted file mode 100644
index 82333655f9..0000000000
--- a/ffpresets/libx264-veryslow.ffpreset
+++ /dev/null
@@ -1,23 +0,0 @@
-coder=1
-flags=+loop+cgop
-cmp=+chroma
-partitions=+parti8x8+parti4x4+partp8x8+partp4x4+partb8x8
-me_method=umh
-subq=10
-me_range=24
-g=250
-keyint_min=25
-sc_threshold=40
-i_qfactor=0.71
-b_strategy=2
-qcomp=0.6
-qmin=0
-qmax=69
-qdiff=4
-bf=8
-refs=16
-directpred=3
-trellis=2
-flags2=+bpyramid+mixed_refs+wpred+dct8x8+fastpskip
-wpredp=2
-rc_lookahead=60
diff --git a/ffpresets/libx264-veryslow_firstpass.ffpreset b/ffpresets/libx264-veryslow_firstpass.ffpreset
deleted file mode 100644
index 2bbf4731f4..0000000000
--- a/ffpresets/libx264-veryslow_firstpass.ffpreset
+++ /dev/null
@@ -1,23 +0,0 @@
-coder=1
-flags=+loop+cgop
-cmp=+chroma
-partitions=-parti8x8-parti4x4-partp8x8-partb8x8
-me_method=dia
-subq=2
-me_range=24
-g=250
-keyint_min=25
-sc_threshold=40
-i_qfactor=0.71
-b_strategy=2
-qcomp=0.6
-qmin=0
-qmax=69
-qdiff=4
-bf=8
-refs=1
-directpred=3
-trellis=0
-flags2=+bpyramid-mixed_refs+wpred-dct8x8+fastpskip
-wpredp=2
-rc_lookahead=60
diff --git a/ffprobe.c b/ffprobe.c
index edda454cde..470001c406 100644
--- a/ffprobe.c
+++ b/ffprobe.c
@@ -1,21 +1,21 @@
/*
- * ffprobe : Simple Media Prober based on the Libav libraries
+ * ffprobe : Simple Media Prober based on the FFmpeg libraries
* Copyright (c) 2007-2010 Stefano Sabatini
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -23,6 +23,7 @@
#include "libavformat/avformat.h"
#include "libavcodec/avcodec.h"
+#include "libavutil/avstring.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "libavutil/dict.h"
@@ -41,7 +42,8 @@ static int use_value_prefix = 0;
static int use_byte_value_binary_prefix = 0;
static int use_value_sexagesimal_format = 0;
-/* globals */
+static char *print_format;
+
static const OptionDef options[];
/* FFprobe context */
@@ -56,6 +58,11 @@ static const char *unit_hertz_str = "Hz" ;
static const char *unit_byte_str = "byte" ;
static const char *unit_bit_per_second_str = "bit/s";
+void exit_program(int ret)
+{
+ exit(ret);
+}
+
static char *value_string(char *buf, int buf_size, double val, const char *unit)
{
if (unit == unit_second_str && use_value_sexagesimal_format) {
@@ -83,9 +90,11 @@ static char *value_string(char *buf, int buf_size, double val, const char *unit)
prefix_string = decimal_unit_prefixes[index];
}
- snprintf(buf, buf_size, "%.3f %s%s", val, prefix_string, show_value_unit ? unit : "");
+ snprintf(buf, buf_size, "%.3f%s%s%s", val, prefix_string || show_value_unit ? " " : "",
+ prefix_string, show_value_unit ? unit : "");
} else {
- snprintf(buf, buf_size, "%f %s", val, show_value_unit ? unit : "");
+ snprintf(buf, buf_size, "%f%s%s", val, show_value_unit ? " " : "",
+ show_value_unit ? unit : "");
}
return buf;
@@ -113,150 +122,636 @@ static char *ts_value_string (char *buf, int buf_size, int64_t ts)
return buf;
}
-static const char *media_type_string(enum AVMediaType media_type)
+/* WRITERS API */
+
+typedef struct WriterContext WriterContext;
+
+typedef struct Writer {
+ int priv_size; ///< private size for the writer context
+ const char *name;
+
+ int (*init) (WriterContext *wctx, const char *args, void *opaque);
+ void (*uninit)(WriterContext *wctx);
+
+ void (*print_header)(WriterContext *ctx);
+ void (*print_footer)(WriterContext *ctx);
+
+ void (*print_chapter_header)(WriterContext *wctx, const char *);
+ void (*print_chapter_footer)(WriterContext *wctx, const char *);
+ void (*print_section_header)(WriterContext *wctx, const char *);
+ void (*print_section_footer)(WriterContext *wctx, const char *);
+ void (*print_integer) (WriterContext *wctx, const char *, int);
+ void (*print_string) (WriterContext *wctx, const char *, const char *);
+ void (*show_tags) (WriterContext *wctx, AVDictionary *dict);
+} Writer;
+
+struct WriterContext {
+ const AVClass *class; ///< class of the writer
+ const Writer *writer; ///< the Writer of which this is an instance
+ char *name; ///< name of this writer instance
+ void *priv; ///< private data for use by the filter
+ unsigned int nb_item; ///< number of the item printed in the given section, starting at 0
+ unsigned int nb_section; ///< number of the section printed in the given section sequence, starting at 0
+ unsigned int nb_chapter; ///< number of the chapter, starting at 0
+};
+
+static const char *writer_get_name(void *p)
+{
+ WriterContext *wctx = p;
+ return wctx->writer->name;
+}
+
+static const AVClass writer_class = {
+ "Writer",
+ writer_get_name,
+ NULL,
+ LIBAVUTIL_VERSION_INT,
+};
+
+static void writer_close(WriterContext **wctx)
+{
+ if (*wctx && (*wctx)->writer->uninit)
+ (*wctx)->writer->uninit(*wctx);
+
+ av_freep(&((*wctx)->priv));
+ av_freep(wctx);
+}
+
+static int writer_open(WriterContext **wctx, const Writer *writer,
+ const char *args, void *opaque)
+{
+ int ret = 0;
+
+ if (!(*wctx = av_malloc(sizeof(WriterContext)))) {
+ ret = AVERROR(ENOMEM);
+ goto fail;
+ }
+
+ if (!((*wctx)->priv = av_mallocz(writer->priv_size))) {
+ ret = AVERROR(ENOMEM);
+ goto fail;
+ }
+
+ (*wctx)->class = &writer_class;
+ (*wctx)->writer = writer;
+ if ((*wctx)->writer->init)
+ ret = (*wctx)->writer->init(*wctx, args, opaque);
+ if (ret < 0)
+ goto fail;
+
+ return 0;
+
+fail:
+ writer_close(wctx);
+ return ret;
+}
+
+static inline void writer_print_header(WriterContext *wctx)
+{
+ if (wctx->writer->print_header)
+ wctx->writer->print_header(wctx);
+ wctx->nb_chapter = 0;
+}
+
+static inline void writer_print_footer(WriterContext *wctx)
+{
+ if (wctx->writer->print_footer)
+ wctx->writer->print_footer(wctx);
+}
+
+static inline void writer_print_chapter_header(WriterContext *wctx,
+ const char *header)
+{
+ if (wctx->writer->print_chapter_header)
+ wctx->writer->print_chapter_header(wctx, header);
+ wctx->nb_section = 0;
+}
+
+static inline void writer_print_chapter_footer(WriterContext *wctx,
+ const char *footer)
+{
+ if (wctx->writer->print_chapter_footer)
+ wctx->writer->print_chapter_footer(wctx, footer);
+ wctx->nb_chapter++;
+}
+
+static inline void writer_print_section_header(WriterContext *wctx,
+ const char *header)
+{
+ if (wctx->writer->print_section_header)
+ wctx->writer->print_section_header(wctx, header);
+ wctx->nb_item = 0;
+}
+
+static inline void writer_print_section_footer(WriterContext *wctx,
+ const char *footer)
+{
+ if (wctx->writer->print_section_footer)
+ wctx->writer->print_section_footer(wctx, footer);
+ wctx->nb_section++;
+}
+
+static inline void writer_print_integer(WriterContext *wctx,
+ const char *key, int val)
+{
+ wctx->writer->print_integer(wctx, key, val);
+ wctx->nb_item++;
+}
+
+static inline void writer_print_string(WriterContext *wctx,
+ const char *key, const char *val)
+{
+ wctx->writer->print_string(wctx, key, val);
+ wctx->nb_item++;
+}
+
+static inline void writer_show_tags(WriterContext *wctx, AVDictionary *dict)
+{
+ wctx->writer->show_tags(wctx, dict);
+}
+
+#define MAX_REGISTERED_WRITERS_NB 64
+
+static Writer *registered_writers[MAX_REGISTERED_WRITERS_NB + 1];
+
+static int writer_register(Writer *writer)
+{
+ static int next_registered_writer_idx = 0;
+
+ if (next_registered_writer_idx == MAX_REGISTERED_WRITERS_NB)
+ return AVERROR(ENOMEM);
+
+ registered_writers[next_registered_writer_idx++] = writer;
+ return 0;
+}
+
+static Writer *writer_get_by_name(const char *name)
+{
+ int i;
+
+ for (i = 0; registered_writers[i]; i++)
+ if (!strcmp(registered_writers[i]->name, name))
+ return registered_writers[i];
+
+ return NULL;
+}
+
+/* Print helpers */
+
+struct print_buf {
+ char *s;
+ int len;
+};
+
+static char *fast_asprintf(struct print_buf *pbuf, const char *fmt, ...)
+{
+ va_list va;
+ int len;
+
+ va_start(va, fmt);
+ len = vsnprintf(NULL, 0, fmt, va);
+ va_end(va);
+ if (len < 0)
+ goto fail;
+
+ if (pbuf->len < len) {
+ char *p = av_realloc(pbuf->s, len + 1);
+ if (!p)
+ goto fail;
+ pbuf->s = p;
+ pbuf->len = len;
+ }
+
+ va_start(va, fmt);
+ len = vsnprintf(pbuf->s, len + 1, fmt, va);
+ va_end(va);
+ if (len < 0)
+ goto fail;
+ return pbuf->s;
+
+fail:
+ av_freep(&pbuf->s);
+ pbuf->len = 0;
+ return NULL;
+}
+
+#define ESCAPE_INIT_BUF_SIZE 256
+
+#define ESCAPE_CHECK_SIZE(src, size, max_size) \
+ if (size > max_size) { \
+ char buf[64]; \
+ snprintf(buf, sizeof(buf), "%s", src); \
+ av_log(log_ctx, AV_LOG_WARNING, \
+ "String '%s...' with is too big\n", buf); \
+ return "FFPROBE_TOO_BIG_STRING"; \
+ }
+
+#define ESCAPE_REALLOC_BUF(dst_size_p, dst_p, src, size) \
+ if (*dst_size_p < size) { \
+ char *q = av_realloc(*dst_p, size); \
+ if (!q) { \
+ char buf[64]; \
+ snprintf(buf, sizeof(buf), "%s", src); \
+ av_log(log_ctx, AV_LOG_WARNING, \
+ "String '%s...' could not be escaped\n", buf); \
+ return "FFPROBE_THIS_STRING_COULD_NOT_BE_ESCAPED"; \
+ } \
+ *dst_size_p = size; \
+ *dst = q; \
+ }
+
+/* WRITERS */
+
+/* Default output */
+
+static void default_print_footer(WriterContext *wctx)
+{
+ printf("\n");
+}
+
+static void default_print_chapter_header(WriterContext *wctx, const char *chapter)
+{
+ if (wctx->nb_chapter)
+ printf("\n");
+}
+
+/* lame uppercasing routine, assumes the string is lower case ASCII */
+static inline char *upcase_string(char *dst, size_t dst_size, const char *src)
+{
+ int i;
+ for (i = 0; src[i] && i < dst_size-1; i++)
+ dst[i] = src[i]-32;
+ dst[i] = 0;
+ return dst;
+}
+
+static void default_print_section_header(WriterContext *wctx, const char *section)
+{
+ char buf[32];
+
+ if (wctx->nb_section)
+ printf("\n");
+ printf("[%s]\n", upcase_string(buf, sizeof(buf), section));
+}
+
+static void default_print_section_footer(WriterContext *wctx, const char *section)
+{
+ char buf[32];
+
+ printf("[/%s]", upcase_string(buf, sizeof(buf), section));
+}
+
+static void default_print_str(WriterContext *wctx, const char *key, const char *value)
+{
+ printf("%s=%s\n", key, value);
+}
+
+static void default_print_int(WriterContext *wctx, const char *key, int value)
+{
+ printf("%s=%d\n", key, value);
+}
+
+static void default_show_tags(WriterContext *wctx, AVDictionary *dict)
+{
+ AVDictionaryEntry *tag = NULL;
+ while ((tag = av_dict_get(dict, "", tag, AV_DICT_IGNORE_SUFFIX))) {
+ printf("TAG:");
+ writer_print_string(wctx, tag->key, tag->value);
+ }
+}
+
+static Writer default_writer = {
+ .name = "default",
+ .print_footer = default_print_footer,
+ .print_chapter_header = default_print_chapter_header,
+ .print_section_header = default_print_section_header,
+ .print_section_footer = default_print_section_footer,
+ .print_integer = default_print_int,
+ .print_string = default_print_str,
+ .show_tags = default_show_tags
+};
+
+/* JSON output */
+
+typedef struct {
+ int multiple_entries; ///< tells if the given chapter requires multiple entries
+ char *buf;
+ size_t buf_size;
+} JSONContext;
+
+static av_cold int json_init(WriterContext *wctx, const char *args, void *opaque)
+{
+ JSONContext *json = wctx->priv;
+
+ json->buf_size = ESCAPE_INIT_BUF_SIZE;
+ if (!(json->buf = av_malloc(json->buf_size)))
+ return AVERROR(ENOMEM);
+
+ return 0;
+}
+
+static av_cold void json_uninit(WriterContext *wctx)
+{
+ JSONContext *json = wctx->priv;
+ av_freep(&json->buf);
+}
+
+static const char *json_escape_str(char **dst, size_t *dst_size, const char *src,
+ void *log_ctx)
+{
+ static const char json_escape[] = {'"', '\\', '\b', '\f', '\n', '\r', '\t', 0};
+ static const char json_subst[] = {'"', '\\', 'b', 'f', 'n', 'r', 't', 0};
+ const char *p;
+ char *q;
+ size_t size = 1;
+
+ // compute the length of the escaped string
+ for (p = src; *p; p++) {
+ ESCAPE_CHECK_SIZE(src, size, SIZE_MAX-6);
+ if (strchr(json_escape, *p)) size += 2; // simple escape
+ else if ((unsigned char)*p < 32) size += 6; // handle non-printable chars
+ else size += 1; // char copy
+ }
+ ESCAPE_REALLOC_BUF(dst_size, dst, src, size);
+
+ q = *dst;
+ for (p = src; *p; p++) {
+ char *s = strchr(json_escape, *p);
+ if (s) {
+ *q++ = '\\';
+ *q++ = json_subst[s - json_escape];
+ } else if ((unsigned char)*p < 32) {
+ snprintf(q, 7, "\\u00%02x", *p & 0xff);
+ q += 6;
+ } else {
+ *q++ = *p;
+ }
+ }
+ *q = 0;
+ return *dst;
+}
+
+static void json_print_header(WriterContext *wctx)
+{
+ printf("{");
+}
+
+static void json_print_footer(WriterContext *wctx)
+{
+ printf("\n}\n");
+}
+
+static void json_print_chapter_header(WriterContext *wctx, const char *chapter)
+{
+ JSONContext *json = wctx->priv;
+
+ if (wctx->nb_chapter)
+ printf(",");
+ json->multiple_entries = !strcmp(chapter, "packets") || !strcmp(chapter, "streams");
+ printf("\n \"%s\":%s", json_escape_str(&json->buf, &json->buf_size, chapter, wctx),
+ json->multiple_entries ? " [" : " ");
+}
+
+static void json_print_chapter_footer(WriterContext *wctx, const char *chapter)
+{
+ JSONContext *json = wctx->priv;
+
+ if (json->multiple_entries)
+ printf("]");
+}
+
+static void json_print_section_header(WriterContext *wctx, const char *section)
+{
+ if (wctx->nb_section) printf(",");
+ printf("{\n");
+}
+
+static void json_print_section_footer(WriterContext *wctx, const char *section)
+{
+ printf("\n }");
+}
+
+static inline void json_print_item_str(WriterContext *wctx,
+ const char *key, const char *value,
+ const char *indent)
{
- switch (media_type) {
- case AVMEDIA_TYPE_VIDEO: return "video";
- case AVMEDIA_TYPE_AUDIO: return "audio";
- case AVMEDIA_TYPE_DATA: return "data";
- case AVMEDIA_TYPE_SUBTITLE: return "subtitle";
- case AVMEDIA_TYPE_ATTACHMENT: return "attachment";
- default: return "unknown";
+ JSONContext *json = wctx->priv;
+
+ printf("%s\"%s\":", indent, json_escape_str(&json->buf, &json->buf_size, key, wctx));
+ printf(" \"%s\"", json_escape_str(&json->buf, &json->buf_size, value, wctx));
+}
+
+#define INDENT " "
+
+static void json_print_str(WriterContext *wctx, const char *key, const char *value)
+{
+ if (wctx->nb_item) printf(",\n");
+ json_print_item_str(wctx, key, value, INDENT);
+}
+
+static void json_print_int(WriterContext *wctx, const char *key, int value)
+{
+ JSONContext *json = wctx->priv;
+
+ if (wctx->nb_item) printf(",\n");
+ printf(INDENT "\"%s\": %d",
+ json_escape_str(&json->buf, &json->buf_size, key, wctx), value);
+}
+
+static void json_show_tags(WriterContext *wctx, AVDictionary *dict)
+{
+ AVDictionaryEntry *tag = NULL;
+ int is_first = 1;
+ if (!dict)
+ return;
+ printf(",\n" INDENT "\"tags\": {\n");
+ while ((tag = av_dict_get(dict, "", tag, AV_DICT_IGNORE_SUFFIX))) {
+ if (is_first) is_first = 0;
+ else printf(",\n");
+ json_print_item_str(wctx, tag->key, tag->value, INDENT INDENT);
}
+ printf("\n }");
}
-static void show_packet(AVFormatContext *fmt_ctx, AVPacket *pkt)
+static Writer json_writer = {
+ .name = "json",
+ .priv_size = sizeof(JSONContext),
+
+ .init = json_init,
+ .uninit = json_uninit,
+ .print_header = json_print_header,
+ .print_footer = json_print_footer,
+ .print_chapter_header = json_print_chapter_header,
+ .print_chapter_footer = json_print_chapter_footer,
+ .print_section_header = json_print_section_header,
+ .print_section_footer = json_print_section_footer,
+ .print_integer = json_print_int,
+ .print_string = json_print_str,
+ .show_tags = json_show_tags,
+};
+
+static void writer_register_all(void)
+{
+ static int initialized;
+
+ if (initialized)
+ return;
+ initialized = 1;
+
+ writer_register(&default_writer);
+ writer_register(&json_writer);
+}
+
+#define print_fmt(k, f, ...) do { \
+ if (fast_asprintf(&pbuf, f, __VA_ARGS__)) \
+ writer_print_string(w, k, pbuf.s); \
+} while (0)
+
+#define print_int(k, v) writer_print_integer(w, k, v)
+#define print_str(k, v) writer_print_string(w, k, v)
+#define print_section_header(s) writer_print_section_header(w, s)
+#define print_section_footer(s) writer_print_section_footer(w, s)
+#define show_tags(metadata) writer_show_tags(w, metadata)
+
+static void show_packet(WriterContext *w, AVFormatContext *fmt_ctx, AVPacket *pkt, int packet_idx)
{
char val_str[128];
AVStream *st = fmt_ctx->streams[pkt->stream_index];
-
- printf("[PACKET]\n");
- printf("codec_type=%s\n" , media_type_string(st->codec->codec_type));
- printf("stream_index=%d\n" , pkt->stream_index);
- printf("pts=%s\n" , ts_value_string (val_str, sizeof(val_str), pkt->pts));
- printf("pts_time=%s\n" , time_value_string(val_str, sizeof(val_str), pkt->pts, &st->time_base));
- printf("dts=%s\n" , ts_value_string (val_str, sizeof(val_str), pkt->dts));
- printf("dts_time=%s\n" , time_value_string(val_str, sizeof(val_str), pkt->dts, &st->time_base));
- printf("duration=%s\n" , ts_value_string (val_str, sizeof(val_str), pkt->duration));
- printf("duration_time=%s\n", time_value_string(val_str, sizeof(val_str), pkt->duration, &st->time_base));
- printf("size=%s\n" , value_string (val_str, sizeof(val_str), pkt->size, unit_byte_str));
- printf("pos=%"PRId64"\n" , pkt->pos);
- printf("flags=%c\n" , pkt->flags & AV_PKT_FLAG_KEY ? 'K' : '_');
- printf("[/PACKET]\n");
+ struct print_buf pbuf = {.s = NULL};
+
+ print_section_header("packet");
+ print_str("codec_type", av_x_if_null(av_get_media_type_string(st->codec->codec_type), "unknown"));
+ print_int("stream_index", pkt->stream_index);
+ print_str("pts", ts_value_string (val_str, sizeof(val_str), pkt->pts));
+ print_str("pts_time", time_value_string(val_str, sizeof(val_str), pkt->pts, &st->time_base));
+ print_str("dts", ts_value_string (val_str, sizeof(val_str), pkt->dts));
+ print_str("dts_time", time_value_string(val_str, sizeof(val_str), pkt->dts, &st->time_base));
+ print_str("duration", ts_value_string (val_str, sizeof(val_str), pkt->duration));
+ print_str("duration_time", time_value_string(val_str, sizeof(val_str), pkt->duration, &st->time_base));
+ print_str("size", value_string (val_str, sizeof(val_str), pkt->size, unit_byte_str));
+ print_fmt("pos", "%"PRId64, pkt->pos);
+ print_fmt("flags", "%c", pkt->flags & AV_PKT_FLAG_KEY ? 'K' : '_');
+ print_section_footer("packet");
+
+ av_free(pbuf.s);
+ fflush(stdout);
}
-static void show_packets(AVFormatContext *fmt_ctx)
+static void show_packets(WriterContext *w, AVFormatContext *fmt_ctx)
{
AVPacket pkt;
+ int i = 0;
av_init_packet(&pkt);
while (!av_read_frame(fmt_ctx, &pkt))
- show_packet(fmt_ctx, &pkt);
+ show_packet(w, fmt_ctx, &pkt, i++);
}
-static void show_stream(AVFormatContext *fmt_ctx, int stream_idx)
+static void show_stream(WriterContext *w, AVFormatContext *fmt_ctx, int stream_idx)
{
AVStream *stream = fmt_ctx->streams[stream_idx];
AVCodecContext *dec_ctx;
AVCodec *dec;
char val_str[128];
- AVDictionaryEntry *tag = NULL;
AVRational display_aspect_ratio;
+ struct print_buf pbuf = {.s = NULL};
- printf("[STREAM]\n");
+ print_section_header("stream");
- printf("index=%d\n", stream->index);
+ print_int("index", stream->index);
if ((dec_ctx = stream->codec)) {
if ((dec = dec_ctx->codec)) {
- printf("codec_name=%s\n", dec->name);
- printf("codec_long_name=%s\n", dec->long_name);
+ print_str("codec_name", dec->name);
+ print_str("codec_long_name", dec->long_name);
} else {
- printf("codec_name=unknown\n");
+ print_str("codec_name", "unknown");
}
- printf("codec_type=%s\n", media_type_string(dec_ctx->codec_type));
- printf("codec_time_base=%d/%d\n", dec_ctx->time_base.num, dec_ctx->time_base.den);
+ print_str("codec_type", av_x_if_null(av_get_media_type_string(dec_ctx->codec_type), "unknown"));
+ print_fmt("codec_time_base", "%d/%d", dec_ctx->time_base.num, dec_ctx->time_base.den);
/* print AVI/FourCC tag */
av_get_codec_tag_string(val_str, sizeof(val_str), dec_ctx->codec_tag);
- printf("codec_tag_string=%s\n", val_str);
- printf("codec_tag=0x%04x\n", dec_ctx->codec_tag);
+ print_str("codec_tag_string", val_str);
+ print_fmt("codec_tag", "0x%04x", dec_ctx->codec_tag);
switch (dec_ctx->codec_type) {
case AVMEDIA_TYPE_VIDEO:
- printf("width=%d\n", dec_ctx->width);
- printf("height=%d\n", dec_ctx->height);
- printf("has_b_frames=%d\n", dec_ctx->has_b_frames);
+ print_int("width", dec_ctx->width);
+ print_int("height", dec_ctx->height);
+ print_int("has_b_frames", dec_ctx->has_b_frames);
if (dec_ctx->sample_aspect_ratio.num) {
- printf("sample_aspect_ratio=%d:%d\n", dec_ctx->sample_aspect_ratio.num,
- dec_ctx->sample_aspect_ratio.den);
+ print_fmt("sample_aspect_ratio", "%d:%d",
+ dec_ctx->sample_aspect_ratio.num,
+ dec_ctx->sample_aspect_ratio.den);
av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
dec_ctx->width * dec_ctx->sample_aspect_ratio.num,
dec_ctx->height * dec_ctx->sample_aspect_ratio.den,
1024*1024);
- printf("display_aspect_ratio=%d:%d\n", display_aspect_ratio.num,
- display_aspect_ratio.den);
+ print_fmt("display_aspect_ratio", "%d:%d",
+ display_aspect_ratio.num,
+ display_aspect_ratio.den);
}
- printf("pix_fmt=%s\n", dec_ctx->pix_fmt != PIX_FMT_NONE ?
- av_pix_fmt_descriptors[dec_ctx->pix_fmt].name : "unknown");
+ print_str("pix_fmt", av_x_if_null(av_get_pix_fmt_name(dec_ctx->pix_fmt), "unknown"));
+ print_int("level", dec_ctx->level);
break;
case AVMEDIA_TYPE_AUDIO:
- printf("sample_rate=%s\n", value_string(val_str, sizeof(val_str),
- dec_ctx->sample_rate,
- unit_hertz_str));
- printf("channels=%d\n", dec_ctx->channels);
- printf("bits_per_sample=%d\n", av_get_bits_per_sample(dec_ctx->codec_id));
+ print_str("sample_fmt",
+ av_x_if_null(av_get_sample_fmt_name(dec_ctx->sample_fmt), "unknown"));
+ print_str("sample_rate", value_string(val_str, sizeof(val_str), dec_ctx->sample_rate, unit_hertz_str));
+ print_int("channels", dec_ctx->channels);
+ print_int("bits_per_sample", av_get_bits_per_sample(dec_ctx->codec_id));
break;
}
} else {
- printf("codec_type=unknown\n");
+ print_str("codec_type", "unknown");
}
if (fmt_ctx->iformat->flags & AVFMT_SHOW_IDS)
- printf("id=0x%x\n", stream->id);
- printf("r_frame_rate=%d/%d\n", stream->r_frame_rate.num, stream->r_frame_rate.den);
- printf("avg_frame_rate=%d/%d\n", stream->avg_frame_rate.num, stream->avg_frame_rate.den);
- printf("time_base=%d/%d\n", stream->time_base.num, stream->time_base.den);
- printf("start_time=%s\n", time_value_string(val_str, sizeof(val_str), stream->start_time,
- &stream->time_base));
- printf("duration=%s\n", time_value_string(val_str, sizeof(val_str), stream->duration,
- &stream->time_base));
+ print_fmt("id", "0x%x", stream->id);
+ print_fmt("r_frame_rate", "%d/%d", stream->r_frame_rate.num, stream->r_frame_rate.den);
+ print_fmt("avg_frame_rate", "%d/%d", stream->avg_frame_rate.num, stream->avg_frame_rate.den);
+ print_fmt("time_base", "%d/%d", stream->time_base.num, stream->time_base.den);
+ print_str("start_time", time_value_string(val_str, sizeof(val_str), stream->start_time, &stream->time_base));
+ print_str("duration", time_value_string(val_str, sizeof(val_str), stream->duration, &stream->time_base));
if (stream->nb_frames)
- printf("nb_frames=%"PRId64"\n", stream->nb_frames);
+ print_fmt("nb_frames", "%"PRId64, stream->nb_frames);
- while ((tag = av_dict_get(stream->metadata, "", tag, AV_DICT_IGNORE_SUFFIX)))
- printf("TAG:%s=%s\n", tag->key, tag->value);
+ show_tags(stream->metadata);
- printf("[/STREAM]\n");
+ print_section_footer("stream");
+ av_free(pbuf.s);
+ fflush(stdout);
}
-static void show_format(AVFormatContext *fmt_ctx)
+static void show_streams(WriterContext *w, AVFormatContext *fmt_ctx)
{
- AVDictionaryEntry *tag = NULL;
- char val_str[128];
-
- printf("[FORMAT]\n");
-
- printf("filename=%s\n", fmt_ctx->filename);
- printf("nb_streams=%d\n", fmt_ctx->nb_streams);
- printf("format_name=%s\n", fmt_ctx->iformat->name);
- printf("format_long_name=%s\n", fmt_ctx->iformat->long_name);
- printf("start_time=%s\n", time_value_string(val_str, sizeof(val_str), fmt_ctx->start_time,
- &AV_TIME_BASE_Q));
- printf("duration=%s\n", time_value_string(val_str, sizeof(val_str), fmt_ctx->duration,
- &AV_TIME_BASE_Q));
- printf("size=%s\n", value_string(val_str, sizeof(val_str), fmt_ctx->file_size,
- unit_byte_str));
- printf("bit_rate=%s\n", value_string(val_str, sizeof(val_str), fmt_ctx->bit_rate,
- unit_bit_per_second_str));
-
- while ((tag = av_dict_get(fmt_ctx->metadata, "", tag, AV_DICT_IGNORE_SUFFIX)))
- printf("TAG:%s=%s\n", tag->key, tag->value);
+ int i;
+ for (i = 0; i < fmt_ctx->nb_streams; i++)
+ show_stream(w, fmt_ctx, i);
+}
- printf("[/FORMAT]\n");
+static void show_format(WriterContext *w, AVFormatContext *fmt_ctx)
+{
+ char val_str[128];
+ struct print_buf pbuf = {.s = NULL};
+
+ print_section_header("format");
+ print_str("filename", fmt_ctx->filename);
+ print_int("nb_streams", fmt_ctx->nb_streams);
+ print_str("format_name", fmt_ctx->iformat->name);
+ print_str("format_long_name", fmt_ctx->iformat->long_name);
+ print_str("start_time", time_value_string(val_str, sizeof(val_str), fmt_ctx->start_time, &AV_TIME_BASE_Q));
+ print_str("duration", time_value_string(val_str, sizeof(val_str), fmt_ctx->duration, &AV_TIME_BASE_Q));
+ print_str("size", value_string(val_str, sizeof(val_str), fmt_ctx->file_size, unit_byte_str));
+ print_str("bit_rate", value_string(val_str, sizeof(val_str), fmt_ctx->bit_rate, unit_bit_per_second_str));
+ show_tags(fmt_ctx->metadata);
+ print_section_footer("format");
+ av_free(pbuf.s);
+ fflush(stdout);
}
static int open_input_file(AVFormatContext **fmt_ctx_ptr, const char *filename)
@@ -276,7 +771,7 @@ static int open_input_file(AVFormatContext **fmt_ctx_ptr, const char *filename)
/* fill the streams in the format context */
- if ((err = av_find_stream_info(fmt_ctx)) < 0) {
+ if ((err = avformat_find_stream_info(fmt_ctx, NULL)) < 0) {
print_error(filename, err);
return err;
}
@@ -291,7 +786,7 @@ static int open_input_file(AVFormatContext **fmt_ctx_ptr, const char *filename)
if (!(codec = avcodec_find_decoder(stream->codec->codec_id))) {
fprintf(stderr, "Unsupported codec with id %d for input stream %d\n",
stream->codec->codec_id, stream->index);
- } else if (avcodec_open(stream->codec, codec) < 0) {
+ } else if (avcodec_open2(stream->codec, codec, NULL) < 0) {
fprintf(stderr, "Error while opening codec for input stream %d\n",
stream->index);
}
@@ -301,32 +796,61 @@ static int open_input_file(AVFormatContext **fmt_ctx_ptr, const char *filename)
return 0;
}
+#define PRINT_CHAPTER(name) do { \
+ if (do_show_ ## name) { \
+ writer_print_chapter_header(wctx, #name); \
+ show_ ## name (wctx, fmt_ctx); \
+ writer_print_chapter_footer(wctx, #name); \
+ } \
+} while (0)
+
static int probe_file(const char *filename)
{
AVFormatContext *fmt_ctx;
- int ret, i;
+ int ret;
+ Writer *w;
+ char *buf;
+ char *w_name = NULL, *w_args = NULL;
+ WriterContext *wctx;
+
+ writer_register_all();
+
+ if (!print_format)
+ print_format = av_strdup("default");
+ w_name = av_strtok(print_format, "=", &buf);
+ w_args = buf;
+
+ w = writer_get_by_name(w_name);
+ if (!w) {
+ av_log(NULL, AV_LOG_ERROR, "Unknown output format with name '%s'\n", w_name);
+ ret = AVERROR(EINVAL);
+ goto end;
+ }
+ if ((ret = writer_open(&wctx, w, w_args, NULL)) < 0)
+ goto end;
if ((ret = open_input_file(&fmt_ctx, filename)))
- return ret;
+ goto end;
- if (do_show_packets)
- show_packets(fmt_ctx);
+ writer_print_header(wctx);
+ PRINT_CHAPTER(packets);
+ PRINT_CHAPTER(streams);
+ PRINT_CHAPTER(format);
+ writer_print_footer(wctx);
- if (do_show_streams)
- for (i = 0; i < fmt_ctx->nb_streams; i++)
- show_stream(fmt_ctx, i);
+ av_close_input_file(fmt_ctx);
+ writer_close(&wctx);
- if (do_show_format)
- show_format(fmt_ctx);
+end:
+ av_freep(&print_format);
- av_close_input_file(fmt_ctx);
- return 0;
+ return ret;
}
static void show_usage(void)
{
printf("Simple multimedia streams analyzer\n");
- printf("usage: ffprobe [OPTIONS] [INPUT_FILE]\n");
+ printf("usage: %s [OPTIONS] [INPUT_FILE]\n", program_name);
printf("\n");
}
@@ -340,7 +864,7 @@ static int opt_format(const char *opt, const char *arg)
return 0;
}
-static void opt_input_file(const char *arg)
+static void opt_input_file(void *optctx, const char *arg)
{
if (input_filename) {
fprintf(stderr, "Argument '%s' provided as input filename, but '%s' was already specified.\n",
@@ -352,22 +876,25 @@ static void opt_input_file(const char *arg)
input_filename = arg;
}
-static void show_help(void)
+static int opt_help(const char *opt, const char *arg)
{
av_log_set_callback(log_callback_help);
show_usage();
show_help_options(options, "Main options:\n", 0, 0);
printf("\n");
- av_opt_show2(avformat_opts, NULL,
- AV_OPT_FLAG_DECODING_PARAM, 0);
+
+ show_help_children(avformat_get_class(), AV_OPT_FLAG_DECODING_PARAM);
+
+ return 0;
}
-static void opt_pretty(void)
+static int opt_pretty(const char *opt, const char *arg)
{
show_value_unit = 1;
use_value_prefix = 1;
use_byte_value_binary_prefix = 1;
use_value_sexagesimal_format = 1;
+ return 0;
}
static const OptionDef options[] = {
@@ -381,10 +908,12 @@ static const OptionDef options[] = {
"use sexagesimal format HOURS:MM:SS.MICROSECONDS for time units" },
{ "pretty", 0, {(void*)&opt_pretty},
"prettify the format of displayed values, make it more human readable" },
+ { "print_format", OPT_STRING | HAS_ARG, {(void*)&print_format}, "set the output printing format (available formats are: default, json)", "format" },
{ "show_format", OPT_BOOL, {(void*)&do_show_format} , "show format/container info" },
{ "show_packets", OPT_BOOL, {(void*)&do_show_packets}, "show packets info" },
{ "show_streams", OPT_BOOL, {(void*)&do_show_streams}, "show streams info" },
{ "default", HAS_ARG | OPT_AUDIO | OPT_VIDEO | OPT_EXPERT, {(void*)opt_default}, "generic catch all option", "" },
+ { "i", HAS_ARG, {(void *)opt_input_file}, "read specified file", "input_file"},
{ NULL, },
};
@@ -392,27 +921,24 @@ int main(int argc, char **argv)
{
int ret;
+ parse_loglevel(argc, argv, options);
av_register_all();
init_opts();
#if CONFIG_AVDEVICE
avdevice_register_all();
#endif
- avformat_opts = avformat_alloc_context();
-
show_banner();
- parse_options(argc, argv, options, opt_input_file);
+ parse_options(NULL, argc, argv, options, opt_input_file);
if (!input_filename) {
show_usage();
fprintf(stderr, "You have to specify one input file.\n");
- fprintf(stderr, "Use -h to get full help or, even better, run 'man ffprobe'.\n");
+ fprintf(stderr, "Use -h to get full help or, even better, run 'man %s'.\n", program_name);
exit(1);
}
ret = probe_file(input_filename);
- av_free(avformat_opts);
-
return ret;
}
diff --git a/ffserver.c b/ffserver.c
index f80ad972e5..788755d613 100644
--- a/ffserver.c
+++ b/ffserver.c
@@ -2,20 +2,20 @@
* Multiple format streaming server
* Copyright (c) 2000, 2001, 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -321,6 +321,11 @@ static AVLFG random_state;
static FILE *logfile = NULL;
/* FIXME: make ffserver work with IPv6 */
+void exit_program(int ret)
+{
+ exit(ret);
+}
+
/* resolve host with also IP address parsing */
static int resolve_host(struct in_addr *sin_addr, const char *hostname)
{
@@ -517,6 +522,7 @@ static int socket_open_listen(struct sockaddr_in *my_addr)
tmp = 1;
setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR, &tmp, sizeof(tmp));
+ my_addr->sin_family = AF_INET;
if (bind (server_fd, (struct sockaddr *) my_addr, sizeof (*my_addr)) < 0) {
char bindmsg[32];
snprintf(bindmsg, sizeof(bindmsg), "bind(port %d)", ntohs(my_addr->sin_port));
@@ -2117,7 +2123,7 @@ static void open_parser(AVFormatContext *s, int i)
codec = avcodec_find_decoder(st->codec->codec_id);
if (codec && (codec->capabilities & CODEC_CAP_PARSE_ONLY)) {
st->codec->parse_only = 1;
- if (avcodec_open(st->codec, codec) < 0)
+ if (avcodec_open2(st->codec, codec, NULL) < 0)
st->codec->parse_only = 0;
}
}
@@ -2128,13 +2134,12 @@ static int open_input_stream(HTTPContext *c, const char *info)
char buf[128];
char input_filename[1024];
AVFormatContext *s = NULL;
- int buf_size, i, ret;
+ int i, ret;
int64_t stream_pos;
/* find file name */
if (c->stream->feed) {
strcpy(input_filename, c->stream->feed->feed_filename);
- buf_size = FFM_PACKET_SIZE;
/* compute position (absolute time) */
if (av_find_info_tag(buf, sizeof(buf), "date", info)) {
if ((ret = av_parse_time(&stream_pos, buf, 0)) < 0)
@@ -2146,7 +2151,6 @@ static int open_input_stream(HTTPContext *c, const char *info)
stream_pos = av_gettime() - c->stream->prebuffer * (int64_t)1000;
} else {
strcpy(input_filename, c->stream->feed_filename);
- buf_size = 0;
/* compute position (relative time) */
if (av_find_info_tag(buf, sizeof(buf), "date", info)) {
if ((ret = av_parse_time(&stream_pos, buf, 1)) < 0)
@@ -2164,7 +2168,7 @@ static int open_input_stream(HTTPContext *c, const char *info)
}
s->flags |= AVFMT_FLAG_GENPTS;
c->fmt_in = s;
- if (strcmp(s->iformat->name, "ffm") && av_find_stream_info(c->fmt_in) < 0) {
+ if (strcmp(s->iformat->name, "ffm") && avformat_find_stream_info(c->fmt_in, NULL) < 0) {
http_log("Could not find stream info '%s'\n", input_filename);
av_close_input_file(s);
return -1;
@@ -2262,7 +2266,7 @@ static int http_prepare_data(HTTPContext *c)
/*
* HACK to avoid mpeg ps muxer to spit many underflow errors
- * Default value from Libav
+ * Default value from FFmpeg
* Try to set it use configuration option
*/
c->fmt_ctx.preload = (int)(0.5*AV_TIME_BASE);
@@ -3165,8 +3169,8 @@ static void rtsp_cmd_setup(HTTPContext *c, const char *url,
switch(rtp_c->rtp_protocol) {
case RTSP_LOWER_TRANSPORT_UDP:
- rtp_port = rtp_get_local_rtp_port(rtp_c->rtp_handles[stream_index]);
- rtcp_port = rtp_get_local_rtcp_port(rtp_c->rtp_handles[stream_index]);
+ rtp_port = ff_rtp_get_local_rtp_port(rtp_c->rtp_handles[stream_index]);
+ rtcp_port = ff_rtp_get_local_rtcp_port(rtp_c->rtp_handles[stream_index]);
avio_printf(c->pb, "Transport: RTP/AVP/UDP;unicast;"
"client_port=%d-%d;server_port=%d-%d",
th->client_port_min, th->client_port_max,
@@ -3470,7 +3474,7 @@ static AVStream *add_av_stream1(FFStream *stream, AVCodecContext *codec, int cop
if (!fst)
return NULL;
if (copy) {
- fst->codec= avcodec_alloc_context();
+ fst->codec = avcodec_alloc_context3(NULL);
memcpy(fst->codec, codec, sizeof(AVCodecContext));
if (codec->extradata_size) {
fst->codec->extradata = av_malloc(codec->extradata_size);
@@ -3510,7 +3514,7 @@ static int add_av_stream(FFStream *feed, AVStream *st)
case AVMEDIA_TYPE_AUDIO:
if (av1->channels == av->channels &&
av1->sample_rate == av->sample_rate)
- goto found;
+ return i;
break;
case AVMEDIA_TYPE_VIDEO:
if (av1->width == av->width &&
@@ -3518,7 +3522,7 @@ static int add_av_stream(FFStream *feed, AVStream *st)
av1->time_base.den == av->time_base.den &&
av1->time_base.num == av->time_base.num &&
av1->gop_size == av->gop_size)
- goto found;
+ return i;
break;
default:
abort();
@@ -3530,8 +3534,6 @@ static int add_av_stream(FFStream *feed, AVStream *st)
if (!fst)
return -1;
return feed->nb_streams - 1;
- found:
- return i;
}
static void remove_stream(FFStream *stream)
@@ -3625,7 +3627,7 @@ static void build_file_streams(void)
} else {
/* find all the AVStreams inside and reference them in
'stream' */
- if (av_find_stream_info(infile) < 0) {
+ if (avformat_find_stream_info(infile, NULL) < 0) {
http_log("Could not find codec parameters from '%s'\n",
stream->feed_filename);
av_close_input_file(infile);
@@ -3652,21 +3654,13 @@ static void build_feed_streams(void)
for(stream = first_stream; stream != NULL; stream = stream->next) {
feed = stream->feed;
if (feed) {
- if (!stream->is_feed) {
- /* we handle a stream coming from a feed */
- for(i=0;i<stream->nb_streams;i++)
- stream->feed_streams[i] = add_av_stream(feed, stream->streams[i]);
- }
- }
- }
-
- /* gather all streams */
- for(stream = first_stream; stream != NULL; stream = stream->next) {
- feed = stream->feed;
- if (feed) {
if (stream->is_feed) {
for(i=0;i<stream->nb_streams;i++)
stream->feed_streams[i] = i;
+ } else {
+ /* we handle a stream coming from a feed */
+ for(i=0;i<stream->nb_streams;i++)
+ stream->feed_streams[i] = add_av_stream(feed, stream->streams[i]);
}
}
}
@@ -3887,7 +3881,7 @@ static void add_codec(FFStream *stream, AVCodecContext *av)
st = av_mallocz(sizeof(AVStream));
if (!st)
return;
- st->codec = avcodec_alloc_context();
+ st->codec = avcodec_alloc_context3(NULL);
stream->streams[stream->nb_streams++] = st;
memcpy(st->codec, av, sizeof(AVCodecContext));
}
@@ -3944,7 +3938,7 @@ static int ffserver_opt_default(const char *opt, const char *arg,
int ret = 0;
const AVOption *o = av_opt_find(avctx, opt, NULL, type, 0);
if(o)
- ret = av_set_string3(avctx, opt, arg, 1, NULL);
+ ret = av_opt_set(avctx, opt, arg, 0);
return ret;
}
@@ -4242,6 +4236,7 @@ static int parse_ffconfig(const char *filename)
stream->fmt = ffserver_guess_format(NULL, stream->filename, NULL);
avcodec_get_context_defaults2(&video_enc, AVMEDIA_TYPE_VIDEO);
avcodec_get_context_defaults2(&audio_enc, AVMEDIA_TYPE_AUDIO);
+
audio_id = CODEC_ID_NONE;
video_id = CODEC_ID_NONE;
if (stream->fmt) {
@@ -4655,12 +4650,13 @@ static void opt_debug(void)
logfilename[0] = '-';
}
-static void show_help(void)
+static int opt_help(const char *opt, const char *arg)
{
printf("usage: ffserver [options]\n"
"Hyper fast multi format Audio/Video streaming server\n");
printf("\n");
show_help_options(options, "Main options:\n", 0, 0);
+ return 0;
}
static const OptionDef options[] = {
@@ -4675,6 +4671,7 @@ int main(int argc, char **argv)
{
struct sigaction sigact;
+ parse_loglevel(argc, argv, options);
av_register_all();
show_banner();
@@ -4683,7 +4680,7 @@ int main(int argc, char **argv)
my_program_dir = getcwd(0, 0);
ffserver_daemon = 1;
- parse_options(argc, argv, options, NULL);
+ parse_options(NULL, argc, argv, options, NULL);
unsetenv("http_proxy"); /* Kill the http_proxy */
diff --git a/libavcodec/4xm.c b/libavcodec/4xm.c
index 176feb94c0..e6638c7b4b 100644
--- a/libavcodec/4xm.c
+++ b/libavcodec/4xm.c
@@ -2,20 +2,20 @@
* 4XM codec
* Copyright (c) 2003 Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -133,7 +133,9 @@ typedef struct FourXContext{
GetBitContext pre_gb; ///< ac/dc prefix
GetBitContext gb;
const uint8_t *bytestream;
+ const uint8_t *bytestream_end;
const uint16_t *wordstream;
+ const uint16_t *wordstream_end;
int mv[256];
VLC pre_vlc;
int last_dc;
@@ -277,7 +279,7 @@ static void init_mv(FourXContext *f){
}
#endif
-static inline void mcdc(uint16_t *dst, uint16_t *src, int log2w, int h, int stride, int scale, int dc){
+static inline void mcdc(uint16_t *dst, uint16_t *src, int log2w, int h, int stride, int scale, unsigned dc){
int i;
dc*= 0x10001;
@@ -328,6 +330,10 @@ static void decode_p_block(FourXContext *f, uint16_t *dst, uint16_t *src, int lo
assert(code>=0 && code<=6);
if(code == 0){
+ if (f->bytestream_end - f->bytestream < 1){
+ av_log(f->avctx, AV_LOG_ERROR, "bytestream overread\n");
+ return;
+ }
src += f->mv[ *f->bytestream++ ];
if(start > src || src > end){
av_log(f->avctx, AV_LOG_ERROR, "mv out of pic\n");
@@ -345,15 +351,31 @@ static void decode_p_block(FourXContext *f, uint16_t *dst, uint16_t *src, int lo
}else if(code == 3 && f->version<2){
mcdc(dst, src, log2w, h, stride, 1, 0);
}else if(code == 4){
+ if (f->bytestream_end - f->bytestream < 1){
+ av_log(f->avctx, AV_LOG_ERROR, "bytestream overread\n");
+ return;
+ }
src += f->mv[ *f->bytestream++ ];
if(start > src || src > end){
av_log(f->avctx, AV_LOG_ERROR, "mv out of pic\n");
return;
}
+ if (f->wordstream_end - f->wordstream < 1){
+ av_log(f->avctx, AV_LOG_ERROR, "wordstream overread\n");
+ return;
+ }
mcdc(dst, src, log2w, h, stride, 1, av_le2ne16(*f->wordstream++));
}else if(code == 5){
+ if (f->wordstream_end - f->wordstream < 1){
+ av_log(f->avctx, AV_LOG_ERROR, "wordstream overread\n");
+ return;
+ }
mcdc(dst, src, log2w, h, stride, 0, av_le2ne16(*f->wordstream++));
}else if(code == 6){
+ if (f->wordstream_end - f->wordstream < 2){
+ av_log(f->avctx, AV_LOG_ERROR, "wordstream overread\n");
+ return;
+ }
if(log2w){
dst[0] = av_le2ne16(*f->wordstream++);
dst[1] = av_le2ne16(*f->wordstream++);
@@ -375,6 +397,8 @@ static int decode_p_frame(FourXContext *f, const uint8_t *buf, int length){
if(f->version>1){
extra=20;
+ if (length < extra)
+ return -1;
bitstream_size= AV_RL32(buf+8);
wordstream_size= AV_RL32(buf+12);
bytestream_size= AV_RL32(buf+16);
@@ -385,11 +409,10 @@ static int decode_p_frame(FourXContext *f, const uint8_t *buf, int length){
bytestream_size= FFMAX(length - bitstream_size - wordstream_size, 0);
}
- if(bitstream_size+ bytestream_size+ wordstream_size + extra != length
- || bitstream_size > (1<<26)
- || bytestream_size > (1<<26)
- || wordstream_size > (1<<26)
- ){
+ if (bitstream_size > length ||
+ bytestream_size > length - bitstream_size ||
+ wordstream_size > length - bytestream_size - bitstream_size ||
+ extra > length - bytestream_size - bitstream_size - wordstream_size){
av_log(f->avctx, AV_LOG_ERROR, "lengths %d %d %d %d\n", bitstream_size, bytestream_size, wordstream_size,
bitstream_size+ bytestream_size+ wordstream_size - length);
return -1;
@@ -399,10 +422,13 @@ static int decode_p_frame(FourXContext *f, const uint8_t *buf, int length){
if (!f->bitstream_buffer)
return AVERROR(ENOMEM);
f->dsp.bswap_buf(f->bitstream_buffer, (const uint32_t*)(buf + extra), bitstream_size/4);
+ memset((uint8_t*)f->bitstream_buffer + bitstream_size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
init_get_bits(&f->gb, f->bitstream_buffer, 8*bitstream_size);
f->wordstream= (const uint16_t*)(buf + extra + bitstream_size);
+ f->wordstream_end= f->wordstream + wordstream_size/2;
f->bytestream= buf + extra + bitstream_size + wordstream_size;
+ f->bytestream_end = f->bytestream + bytestream_size;
init_mv(f);
@@ -531,7 +557,7 @@ static int decode_i_mb(FourXContext *f){
return 0;
}
-static const uint8_t *read_huffman_tables(FourXContext *f, const uint8_t * const buf){
+static const uint8_t *read_huffman_tables(FourXContext *f, const uint8_t * const buf, int buf_size){
int frequency[512];
uint8_t flag[512];
int up[512];
@@ -539,6 +565,7 @@ static const uint8_t *read_huffman_tables(FourXContext *f, const uint8_t * const
int bits_tab[257];
int start, end;
const uint8_t *ptr= buf;
+ const uint8_t *ptr_end = buf + buf_size;
int j;
memset(frequency, 0, sizeof(frequency));
@@ -549,6 +576,8 @@ static const uint8_t *read_huffman_tables(FourXContext *f, const uint8_t * const
for(;;){
int i;
+ if (start <= end && ptr_end - ptr < end - start + 1 + 1)
+ return NULL;
for(i=start; i<=end; i++){
frequency[i]= *ptr++;
}
@@ -601,9 +630,10 @@ static const uint8_t *read_huffman_tables(FourXContext *f, const uint8_t * const
len_tab[j]= len;
}
- init_vlc(&f->pre_vlc, ACDC_VLC_BITS, 257,
- len_tab , 1, 1,
- bits_tab, 4, 4, 0);
+ if (init_vlc(&f->pre_vlc, ACDC_VLC_BITS, 257,
+ len_tab , 1, 1,
+ bits_tab, 4, 4, 0))
+ return NULL;
return ptr;
}
@@ -621,10 +651,13 @@ static int decode_i2_frame(FourXContext *f, const uint8_t *buf, int length){
const int height= f->avctx->height;
uint16_t *dst= (uint16_t*)f->current_picture.data[0];
const int stride= f->current_picture.linesize[0]>>1;
+ const uint8_t *buf_end = buf + length;
for(y=0; y<height; y+=16){
for(x=0; x<width; x+=16){
unsigned int color[4], bits;
+ if (buf_end - buf < 8)
+ return -1;
memset(color, 0, sizeof(color));
//warning following is purely guessed ...
color[0]= bytestream_get_le16(&buf);
@@ -658,18 +691,23 @@ static int decode_i_frame(FourXContext *f, const uint8_t *buf, int length){
uint16_t *dst= (uint16_t*)f->current_picture.data[0];
const int stride= f->current_picture.linesize[0]>>1;
const unsigned int bitstream_size= AV_RL32(buf);
- const int token_count av_unused = AV_RL32(buf + bitstream_size + 8);
- unsigned int prestream_size= 4*AV_RL32(buf + bitstream_size + 4);
- const uint8_t *prestream= buf + bitstream_size + 12;
+ unsigned int prestream_size;
+ const uint8_t *prestream;
+
+ if (bitstream_size > (1<<26) || length < bitstream_size + 12)
+ return -1;
+ prestream_size = 4*AV_RL32(buf + bitstream_size + 4);
+ prestream = buf + bitstream_size + 12;
- if(prestream_size + bitstream_size + 12 != length
- || bitstream_size > (1<<26)
- || prestream_size > (1<<26)){
+ if (prestream_size > (1<<26) ||
+ prestream_size != length - (bitstream_size + 12)){
av_log(f->avctx, AV_LOG_ERROR, "size mismatch %d %d %d\n", prestream_size, bitstream_size, length);
return -1;
}
- prestream= read_huffman_tables(f, prestream);
+ prestream= read_huffman_tables(f, prestream, buf + length - prestream);
+ if (!prestream)
+ return -1;
init_get_bits(&f->gb, buf + 4, 8*bitstream_size);
@@ -679,6 +717,7 @@ static int decode_i_frame(FourXContext *f, const uint8_t *buf, int length){
if (!f->bitstream_buffer)
return AVERROR(ENOMEM);
f->dsp.bswap_buf(f->bitstream_buffer, (const uint32_t*)prestream, prestream_size/4);
+ memset((uint8_t*)f->bitstream_buffer + prestream_size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
init_get_bits(&f->pre_gb, f->bitstream_buffer, 8*prestream_size);
f->last_dc= 0*128*8*8;
@@ -710,6 +749,8 @@ static int decode_frame(AVCodecContext *avctx,
AVFrame *p, temp;
int i, frame_4cc, frame_size;
+ if (buf_size < 12)
+ return AVERROR_INVALIDDATA;
frame_4cc= AV_RL32(buf);
if(buf_size != AV_RL32(buf+4)+8 || buf_size < 20){
av_log(f->avctx, AV_LOG_ERROR, "size mismatch %d %d\n", buf_size, AV_RL32(buf+4));
@@ -722,6 +763,11 @@ static int decode_frame(AVCodecContext *avctx,
const int whole_size= AV_RL32(buf+16);
CFrameBuffer *cfrm;
+ if (data_size < 0 || whole_size < 0){
+ av_log(f->avctx, AV_LOG_ERROR, "sizes invalid\n");
+ return AVERROR_INVALIDDATA;
+ }
+
for(i=0; i<CFRAME_BUFFER_COUNT; i++){
if(f->cfrm[i].id && f->cfrm[i].id < avctx->frame_number)
av_log(f->avctx, AV_LOG_ERROR, "lost c frame %d\n", f->cfrm[i].id);
@@ -738,6 +784,8 @@ static int decode_frame(AVCodecContext *avctx,
}
cfrm= &f->cfrm[i];
+ if (data_size > UINT_MAX - cfrm->size - FF_INPUT_BUFFER_PADDING_SIZE)
+ return AVERROR_INVALIDDATA;
cfrm->data= av_fast_realloc(cfrm->data, &cfrm->allocated_size, cfrm->size + data_size + FF_INPUT_BUFFER_PADDING_SIZE);
if(!cfrm->data){ //explicit check needed as memcpy below might not catch a NULL
av_log(f->avctx, AV_LOG_ERROR, "realloc falure");
@@ -773,23 +821,24 @@ static int decode_frame(AVCodecContext *avctx,
avctx->flags |= CODEC_FLAG_EMU_EDGE; // alternatively we would have to use our own buffer management
- if(p->data[0])
- avctx->release_buffer(avctx, p);
-
p->reference= 1;
- if(avctx->get_buffer(avctx, p) < 0){
- av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
+ if (avctx->reget_buffer(avctx, p) < 0) {
+ av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
return -1;
}
if(frame_4cc == AV_RL32("ifr2")){
p->pict_type= AV_PICTURE_TYPE_I;
- if(decode_i2_frame(f, buf-4, frame_size) < 0)
+ if(decode_i2_frame(f, buf-4, frame_size+4) < 0){
+ av_log(f->avctx, AV_LOG_ERROR, "decode i2 frame failed\n");
return -1;
+ }
}else if(frame_4cc == AV_RL32("ifrm")){
p->pict_type= AV_PICTURE_TYPE_I;
- if(decode_i_frame(f, buf, frame_size) < 0)
+ if(decode_i_frame(f, buf, frame_size) < 0){
+ av_log(f->avctx, AV_LOG_ERROR, "decode i frame failed\n");
return -1;
+ }
}else if(frame_4cc == AV_RL32("pfrm") || frame_4cc == AV_RL32("pfr2")){
if(!f->last_picture.data[0]){
f->last_picture.reference= 1;
@@ -800,8 +849,10 @@ static int decode_frame(AVCodecContext *avctx,
}
p->pict_type= AV_PICTURE_TYPE_P;
- if(decode_p_frame(f, buf, frame_size) < 0)
+ if(decode_p_frame(f, buf, frame_size) < 0){
+ av_log(f->avctx, AV_LOG_ERROR, "decode p frame failed\n");
return -1;
+ }
}else if(frame_4cc == AV_RL32("snd_")){
av_log(avctx, AV_LOG_ERROR, "ignoring snd_ chunk length:%d\n", buf_size);
}else{
@@ -834,7 +885,13 @@ static av_cold int decode_init(AVCodecContext *avctx){
av_log(avctx, AV_LOG_ERROR, "extradata wrong or missing\n");
return 1;
}
+ if((avctx->width % 16) || (avctx->height % 16)) {
+ av_log(avctx, AV_LOG_ERROR, "unsupported width/height\n");
+ return AVERROR_INVALIDDATA;
+ }
+ avcodec_get_frame_defaults(&f->current_picture);
+ avcodec_get_frame_defaults(&f->last_picture);
f->version= AV_RL32(avctx->extradata)>>16;
common_init(avctx);
init_vlcs(f);
@@ -866,15 +923,14 @@ static av_cold int decode_end(AVCodecContext *avctx){
}
AVCodec ff_fourxm_decoder = {
- "4xm",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_4XM,
- sizeof(FourXContext),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- CODEC_CAP_DR1,
+ .name = "4xm",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_4XM,
+ .priv_data_size = sizeof(FourXContext),
+ .init = decode_init,
+ .close = decode_end,
+ .decode = decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("4X Movie"),
};
diff --git a/libavcodec/8bps.c b/libavcodec/8bps.c
index 055715fde5..8ae0185acb 100644
--- a/libavcodec/8bps.c
+++ b/libavcodec/8bps.c
@@ -2,20 +2,20 @@
* Quicktime Planar RGB (8BPS) Video Decoder
* Copyright (C) 2003 Roberto Togni
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -162,6 +162,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
c->avctx = avctx;
+ avcodec_get_frame_defaults(&c->pic);
c->pic.data[0] = NULL;
switch (avctx->bits_per_coded_sample) {
@@ -221,14 +222,13 @@ static av_cold int decode_end(AVCodecContext *avctx)
AVCodec ff_eightbps_decoder = {
- "8bps",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_8BPS,
- sizeof(EightBpsContext),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- CODEC_CAP_DR1,
- .long_name = NULL_IF_CONFIG_SMALL("QuickTime 8BPS video"),
+ .name = "8bps",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_8BPS,
+ .priv_data_size = sizeof(EightBpsContext),
+ .init = decode_init,
+ .close = decode_end,
+ .decode = decode_frame,
+ .capabilities = CODEC_CAP_DR1,
+ .long_name = NULL_IF_CONFIG_SMALL("QuickTime 8BPS video"),
};
diff --git a/libavcodec/8svx.c b/libavcodec/8svx.c
index 5fdea915ff..5c68d347e2 100644
--- a/libavcodec/8svx.c
+++ b/libavcodec/8svx.c
@@ -1,21 +1,21 @@
/*
- * 8SVX audio decoder
* Copyright (C) 2008 Jaikrishnan Menon
+ * Copyright (C) 2011 Stefano Sabatini
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -23,72 +23,177 @@
* @file
* 8svx audio decoder
* @author Jaikrishnan Menon
+ *
* supports: fibonacci delta encoding
* : exponential encoding
+ *
+ * For more information about the 8SVX format:
+ * http://netghost.narod.ru/gff/vendspec/iff/iff.txt
+ * http://sox.sourceforge.net/AudioFormats-11.html
+ * http://aminet.net/package/mus/misc/wavepak
+ * http://amigan.1emu.net/reg/8SVX.txt
+ *
+ * Samples can be found here:
+ * http://aminet.net/mods/smpl/
*/
#include "avcodec.h"
/** decoder context */
typedef struct EightSvxContext {
- int16_t fib_acc;
- const int16_t *table;
+ const int8_t *table;
+
+ /* buffer used to store the whole audio decoded/interleaved chunk,
+ * which is sent with the first packet */
+ uint8_t *samples;
+ size_t samples_size;
+ int samples_idx;
} EightSvxContext;
-static const int16_t fibonacci[16] = { -34<<8, -21<<8, -13<<8, -8<<8, -5<<8, -3<<8, -2<<8, -1<<8,
- 0, 1<<8, 2<<8, 3<<8, 5<<8, 8<<8, 13<<8, 21<<8 };
-static const int16_t exponential[16] = { -128<<8, -64<<8, -32<<8, -16<<8, -8<<8, -4<<8, -2<<8, -1<<8,
- 0, 1<<8, 2<<8, 4<<8, 8<<8, 16<<8, 32<<8, 64<<8 };
+static const int8_t fibonacci[16] = { -34, -21, -13, -8, -5, -3, -2, -1, 0, 1, 2, 3, 5, 8, 13, 21 };
+static const int8_t exponential[16] = { -128, -64, -32, -16, -8, -4, -2, -1, 0, 1, 2, 4, 8, 16, 32, 64 };
+
+#define MAX_FRAME_SIZE 2048
+
+/**
+ * Interleave samples in buffer containing all left channel samples
+ * at the beginning, and right channel samples at the end.
+ * Each sample is assumed to be in signed 8-bit format.
+ *
+ * @param size the size in bytes of the dst and src buffer
+ */
+static void interleave_stereo(uint8_t *dst, const uint8_t *src, int size)
+{
+ uint8_t *dst_end = dst + size;
+ size = size>>1;
+
+ while (dst < dst_end) {
+ *dst++ = *src;
+ *dst++ = *(src+size);
+ src++;
+ }
+}
+
+/**
+ * Delta decode the compressed values in src, and put the resulting
+ * decoded n samples in dst.
+ *
+ * @param val starting value assumed by the delta sequence
+ * @param table delta sequence table
+ * @return size in bytes of the decoded data, must be src_size*2
+ */
+static int delta_decode(int8_t *dst, const uint8_t *src, int src_size,
+ int8_t val, const int8_t *table)
+{
+ int n = src_size;
+ int8_t *dst0 = dst;
+
+ while (n--) {
+ uint8_t d = *src++;
+ val = av_clip(val + table[d & 0x0f], -127, 128);
+ *dst++ = val;
+ val = av_clip(val + table[d >> 4] , -127, 128);
+ *dst++ = val;
+ }
+
+ return dst-dst0;
+}
-/** decode a frame */
static int eightsvx_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
AVPacket *avpkt)
{
- const uint8_t *buf = avpkt->data;
- int buf_size = avpkt->size;
EightSvxContext *esc = avctx->priv_data;
- int16_t *out_data = data;
- int consumed = buf_size;
- const uint8_t *buf_end = buf + buf_size;
+ int out_data_size, n;
+ uint8_t *src, *dst;
- if((*data_size >> 2) < buf_size)
- return -1;
+ /* decode and interleave the first packet */
+ if (!esc->samples && avpkt) {
+ uint8_t *deinterleaved_samples;
- if(avctx->frame_number == 0) {
- esc->fib_acc = buf[1] << 8;
- buf_size -= 2;
- buf += 2;
- }
+ esc->samples_size = avctx->codec->id == CODEC_ID_8SVX_RAW ?
+ avpkt->size : avctx->channels + (avpkt->size-avctx->channels) * 2;
+ if (!(esc->samples = av_malloc(esc->samples_size)))
+ return AVERROR(ENOMEM);
+
+ /* decompress */
+ if (avctx->codec->id == CODEC_ID_8SVX_FIB || avctx->codec->id == CODEC_ID_8SVX_EXP) {
+ const uint8_t *buf = avpkt->data;
+ int buf_size = avpkt->size;
+ int n = esc->samples_size;
+
+ if (buf_size < 2) {
+ av_log(avctx, AV_LOG_ERROR, "packet size is too small\n");
+ return AVERROR(EINVAL);
+ }
+ if (!(deinterleaved_samples = av_mallocz(n)))
+ return AVERROR(ENOMEM);
- *data_size = buf_size << 2;
+ /* the uncompressed starting value is contained in the first byte */
+ if (avctx->channels == 2) {
+ delta_decode(deinterleaved_samples , buf+1, buf_size/2-1, buf[0], esc->table);
+ buf += buf_size/2;
+ delta_decode(deinterleaved_samples+n/2-1, buf+1, buf_size/2-1, buf[0], esc->table);
+ } else
+ delta_decode(deinterleaved_samples , buf+1, buf_size-1 , buf[0], esc->table);
+ } else {
+ deinterleaved_samples = avpkt->data;
+ }
- while(buf < buf_end) {
- uint8_t d = *buf++;
- esc->fib_acc += esc->table[d & 0x0f];
- *out_data++ = esc->fib_acc;
- esc->fib_acc += esc->table[d >> 4];
- *out_data++ = esc->fib_acc;
+ if (avctx->channels == 2)
+ interleave_stereo(esc->samples, deinterleaved_samples, esc->samples_size);
+ else
+ memcpy(esc->samples, deinterleaved_samples, esc->samples_size);
}
- return consumed;
+ /* return single packed with fixed size */
+ out_data_size = FFMIN(MAX_FRAME_SIZE, esc->samples_size - esc->samples_idx);
+ if (*data_size < out_data_size) {
+ av_log(avctx, AV_LOG_ERROR, "Provided buffer with size %d is too small.\n", *data_size);
+ return AVERROR(EINVAL);
+ }
+
+ *data_size = out_data_size;
+ dst = data;
+ src = esc->samples + esc->samples_idx;
+ for (n = out_data_size; n > 0; n--)
+ *dst++ = *src++ + 128;
+ esc->samples_idx += *data_size;
+
+ return avctx->codec->id == CODEC_ID_8SVX_FIB || avctx->codec->id == CODEC_ID_8SVX_EXP ?
+ (avctx->frame_number == 0)*2 + out_data_size / 2 :
+ out_data_size;
}
-/** initialize 8svx decoder */
static av_cold int eightsvx_decode_init(AVCodecContext *avctx)
{
EightSvxContext *esc = avctx->priv_data;
- switch(avctx->codec->id) {
- case CODEC_ID_8SVX_FIB:
- esc->table = fibonacci;
- break;
- case CODEC_ID_8SVX_EXP:
- esc->table = exponential;
- break;
- default:
- return -1;
+ if (avctx->channels > 2) {
+ av_log(avctx, AV_LOG_ERROR, "8SVX does not support more than 2 channels\n");
+ return AVERROR_INVALIDDATA;
}
- avctx->sample_fmt = AV_SAMPLE_FMT_S16;
+
+ switch (avctx->codec->id) {
+ case CODEC_ID_8SVX_FIB: esc->table = fibonacci; break;
+ case CODEC_ID_8SVX_EXP: esc->table = exponential; break;
+ case CODEC_ID_8SVX_RAW: esc->table = NULL; break;
+ default:
+ av_log(avctx, AV_LOG_ERROR, "Invalid codec id %d.\n", avctx->codec->id);
+ return AVERROR_INVALIDDATA;
+ }
+ avctx->sample_fmt = AV_SAMPLE_FMT_U8;
+
+ return 0;
+}
+
+static av_cold int eightsvx_decode_close(AVCodecContext *avctx)
+{
+ EightSvxContext *esc = avctx->priv_data;
+
+ av_freep(&esc->samples);
+ esc->samples_size = 0;
+ esc->samples_idx = 0;
+
return 0;
}
@@ -99,6 +204,7 @@ AVCodec ff_eightsvx_fib_decoder = {
.priv_data_size = sizeof (EightSvxContext),
.init = eightsvx_decode_init,
.decode = eightsvx_decode_frame,
+ .close = eightsvx_decode_close,
.long_name = NULL_IF_CONFIG_SMALL("8SVX fibonacci"),
};
@@ -109,5 +215,17 @@ AVCodec ff_eightsvx_exp_decoder = {
.priv_data_size = sizeof (EightSvxContext),
.init = eightsvx_decode_init,
.decode = eightsvx_decode_frame,
+ .close = eightsvx_decode_close,
.long_name = NULL_IF_CONFIG_SMALL("8SVX exponential"),
};
+
+AVCodec ff_eightsvx_raw_decoder = {
+ .name = "8svx_raw",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_8SVX_RAW,
+ .priv_data_size = sizeof(EightSvxContext),
+ .init = eightsvx_decode_init,
+ .decode = eightsvx_decode_frame,
+ .close = eightsvx_decode_close,
+ .long_name = NULL_IF_CONFIG_SMALL("8SVX rawaudio"),
+};
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index b781ed7ef3..147b37fa5f 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1,3 +1,5 @@
+include $(SUBDIR)../config.mak
+
NAME = avcodec
FFLIBS = avutil
@@ -16,6 +18,7 @@ OBJS = allcodecs.o \
options.o \
parser.o \
raw.o \
+ rawdec.o \
resample.o \
resample2.o \
simple_idct.o \
@@ -24,6 +27,7 @@ OBJS = allcodecs.o \
# parts needed for many different codecs
OBJS-$(CONFIG_AANDCT) += aandcttab.o
OBJS-$(CONFIG_AC3DSP) += ac3dsp.o
+OBJS-$(CONFIG_CRYSTALHD) += crystalhd.o
OBJS-$(CONFIG_ENCODERS) += faandct.o jfdctfst.o jfdctint.o
OBJS-$(CONFIG_DCT) += dct.o dct32_fixed.o dct32_float.o
OBJS-$(CONFIG_DWT) += dwt.o
@@ -76,7 +80,7 @@ OBJS-$(CONFIG_AMV_DECODER) += sp5xdec.o mjpegdec.o mjpeg.o
OBJS-$(CONFIG_ANM_DECODER) += anm.o
OBJS-$(CONFIG_ANSI_DECODER) += ansi.o cga_data.o
OBJS-$(CONFIG_APE_DECODER) += apedec.o
-OBJS-$(CONFIG_ASS_DECODER) += assdec.o ass.o
+OBJS-$(CONFIG_ASS_DECODER) += assdec.o ass.o ass_split.o
OBJS-$(CONFIG_ASS_ENCODER) += assenc.o ass.o
OBJS-$(CONFIG_ASV1_DECODER) += asv1.o mpeg12data.o
OBJS-$(CONFIG_ASV1_ENCODER) += asv1.o mpeg12data.o
@@ -89,9 +93,10 @@ OBJS-$(CONFIG_AURA2_DECODER) += aura.o
OBJS-$(CONFIG_AVS_DECODER) += avs.o
OBJS-$(CONFIG_BETHSOFTVID_DECODER) += bethsoftvideo.o
OBJS-$(CONFIG_BFI_DECODER) += bfi.o
-OBJS-$(CONFIG_BINK_DECODER) += bink.o binkidct.o
+OBJS-$(CONFIG_BINK_DECODER) += bink.o binkdsp.o
OBJS-$(CONFIG_BINKAUDIO_DCT_DECODER) += binkaudio.o wma.o
OBJS-$(CONFIG_BINKAUDIO_RDFT_DECODER) += binkaudio.o wma.o
+OBJS-$(CONFIG_BINTEXT_DECODER) += bintext.o cga_data.o
OBJS-$(CONFIG_BMP_DECODER) += bmp.o msrledec.o
OBJS-$(CONFIG_BMP_ENCODER) += bmpenc.o
OBJS-$(CONFIG_C93_DECODER) += c93.o
@@ -105,6 +110,7 @@ OBJS-$(CONFIG_COOK_DECODER) += cook.o
OBJS-$(CONFIG_CSCD_DECODER) += cscd.o
OBJS-$(CONFIG_CYUV_DECODER) += cyuv.o
OBJS-$(CONFIG_DCA_DECODER) += dca.o synth_filter.o dcadsp.o
+OBJS-$(CONFIG_DCA_ENCODER) += dcaenc.o
OBJS-$(CONFIG_DFA_DECODER) += dfa.o
OBJS-$(CONFIG_DNXHD_DECODER) += dnxhddec.o dnxhddata.o
OBJS-$(CONFIG_DNXHD_ENCODER) += dnxhdenc.o dnxhddata.o \
@@ -122,9 +128,9 @@ OBJS-$(CONFIG_DVDSUB_ENCODER) += dvdsubenc.o
OBJS-$(CONFIG_DVVIDEO_DECODER) += dv.o dvdata.o
OBJS-$(CONFIG_DVVIDEO_ENCODER) += dv.o dvdata.o
OBJS-$(CONFIG_DXA_DECODER) += dxa.o
-OBJS-$(CONFIG_EAC3_DECODER) += eac3dec.o eac3dec_data.o
+OBJS-$(CONFIG_EAC3_DECODER) += eac3dec.o eac3_data.o
OBJS-$(CONFIG_EAC3_ENCODER) += eac3enc.o ac3enc.o ac3enc_float.o \
- ac3tab.o ac3.o kbdwin.o
+ ac3tab.o ac3.o kbdwin.o eac3_data.o
OBJS-$(CONFIG_EACMV_DECODER) += eacmv.o
OBJS-$(CONFIG_EAMAD_DECODER) += eamad.o eaidct.o mpeg12.o \
mpeg12data.o mpegvideo.o \
@@ -137,19 +143,26 @@ OBJS-$(CONFIG_EATQI_DECODER) += eatqi.o eaidct.o mpeg12.o \
OBJS-$(CONFIG_EIGHTBPS_DECODER) += 8bps.o
OBJS-$(CONFIG_EIGHTSVX_EXP_DECODER) += 8svx.o
OBJS-$(CONFIG_EIGHTSVX_FIB_DECODER) += 8svx.o
+OBJS-$(CONFIG_EIGHTSVX_RAW_DECODER) += 8svx.o
OBJS-$(CONFIG_ESCAPE124_DECODER) += escape124.o
OBJS-$(CONFIG_FFV1_DECODER) += ffv1.o rangecoder.o
OBJS-$(CONFIG_FFV1_ENCODER) += ffv1.o rangecoder.o
OBJS-$(CONFIG_FFVHUFF_DECODER) += huffyuv.o
OBJS-$(CONFIG_FFVHUFF_ENCODER) += huffyuv.o
-OBJS-$(CONFIG_FLAC_DECODER) += flacdec.o flacdata.o flac.o
-OBJS-$(CONFIG_FLAC_ENCODER) += flacenc.o flacdata.o flac.o
+OBJS-$(CONFIG_FLAC_DECODER) += flacdec.o flacdata.o flac.o vorbis_data.o
+OBJS-$(CONFIG_FLAC_ENCODER) += flacenc.o flacdata.o flac.o vorbis_data.o
OBJS-$(CONFIG_FLASHSV_DECODER) += flashsv.o
OBJS-$(CONFIG_FLASHSV_ENCODER) += flashsvenc.o
+OBJS-$(CONFIG_FLASHSV2_ENCODER) += flashsv2enc.o
+OBJS-$(CONFIG_FLASHSV2_DECODER) += flashsv.o
OBJS-$(CONFIG_FLIC_DECODER) += flicvideo.o
OBJS-$(CONFIG_FOURXM_DECODER) += 4xm.o
OBJS-$(CONFIG_FRAPS_DECODER) += fraps.o
OBJS-$(CONFIG_FRWU_DECODER) += frwu.o
+OBJS-$(CONFIG_G723_1_DECODER) += g723_1.o acelp_vectors.o \
+ celp_filters.o celp_math.o
+OBJS-$(CONFIG_G723_1_ENCODER) += g723_1.o
+OBJS-$(CONFIG_G729_DECODER) += g729dec.o lsp.o celp_math.o acelp_filters.o acelp_pitch_delay.o acelp_vectors.o g729postfilter.o
OBJS-$(CONFIG_GIF_DECODER) += gifdec.o lzw.o
OBJS-$(CONFIG_GIF_ENCODER) += gif.o lzwenc.o
OBJS-$(CONFIG_GSM_DECODER) += gsmdec.o gsmdec_data.o msgsmdec.o
@@ -180,6 +193,7 @@ OBJS-$(CONFIG_H264_VAAPI_HWACCEL) += vaapi_h264.o
OBJS-$(CONFIG_HUFFYUV_DECODER) += huffyuv.o
OBJS-$(CONFIG_HUFFYUV_ENCODER) += huffyuv.o
OBJS-$(CONFIG_IDCIN_DECODER) += idcinvideo.o
+OBJS-$(CONFIG_IDF_DECODER) += bintext.o cga_data.o
OBJS-$(CONFIG_IFF_BYTERUN1_DECODER) += iff.o
OBJS-$(CONFIG_IFF_ILBM_DECODER) += iff.o
OBJS-$(CONFIG_IMC_DECODER) += imc.o
@@ -188,6 +202,8 @@ OBJS-$(CONFIG_INDEO3_DECODER) += indeo3.o
OBJS-$(CONFIG_INDEO5_DECODER) += indeo5.o ivi_common.o ivi_dsp.o
OBJS-$(CONFIG_INTERPLAY_DPCM_DECODER) += dpcm.o
OBJS-$(CONFIG_INTERPLAY_VIDEO_DECODER) += interplayvideo.o
+OBJS-$(CONFIG_JPEG2000_DECODER) += j2kdec.o mqcdec.o mqc.o j2k.o j2k_dwt.o
+OBJS-$(CONFIG_JPEG2000_ENCODER) += j2kenc.o mqcenc.o mqc.o j2k.o j2k_dwt.o
OBJS-$(CONFIG_JPEGLS_DECODER) += jpeglsdec.o jpegls.o \
mjpegdec.o mjpeg.o
OBJS-$(CONFIG_JPEGLS_ENCODER) += jpeglsenc.o jpegls.o
@@ -250,6 +266,7 @@ OBJS-$(CONFIG_MPEG_XVMC_DECODER) += mpegvideo_xvmc.o
OBJS-$(CONFIG_MPEG1VIDEO_DECODER) += mpeg12.o mpeg12data.o \
mpegvideo.o error_resilience.o
OBJS-$(CONFIG_MPEG1VIDEO_ENCODER) += mpeg12enc.o mpegvideo_enc.o \
+ timecode.o \
motion_est.o ratecontrol.o \
mpeg12.o mpeg12data.o \
mpegvideo.o error_resilience.o
@@ -258,6 +275,7 @@ OBJS-$(CONFIG_MPEG2_VAAPI_HWACCEL) += vaapi_mpeg2.o
OBJS-$(CONFIG_MPEG2VIDEO_DECODER) += mpeg12.o mpeg12data.o \
mpegvideo.o error_resilience.o
OBJS-$(CONFIG_MPEG2VIDEO_ENCODER) += mpeg12enc.o mpegvideo_enc.o \
+ timecode.o \
motion_est.o ratecontrol.o \
mpeg12.o mpeg12data.o \
mpegvideo.o error_resilience.o
@@ -273,6 +291,7 @@ OBJS-$(CONFIG_MSMPEG4V3_ENCODER) += msmpeg4.o msmpeg4data.o h263dec.o \
h263.o ituh263dec.o mpeg4videodec.o
OBJS-$(CONFIG_MSRLE_DECODER) += msrle.o msrledec.o
OBJS-$(CONFIG_MSVIDEO1_DECODER) += msvideo1.o
+OBJS-$(CONFIG_MSVIDEO1_ENCODER) += msvideo1enc.o elbg.o
OBJS-$(CONFIG_MSZH_DECODER) += lcldec.o
OBJS-$(CONFIG_MXPEG_DECODER) += mxpegdec.o mjpegdec.o mjpeg.o
OBJS-$(CONFIG_NELLYMOSER_DECODER) += nellymoserdec.o nellymoser.o
@@ -294,6 +313,8 @@ OBJS-$(CONFIG_PNG_DECODER) += png.o pngdec.o
OBJS-$(CONFIG_PNG_ENCODER) += png.o pngenc.o
OBJS-$(CONFIG_PPM_DECODER) += pnmdec.o pnm.o
OBJS-$(CONFIG_PPM_ENCODER) += pnmenc.o pnm.o
+OBJS-$(CONFIG_PRORES_DECODER) += proresdec2.o
+OBJS-$(CONFIG_PRORES_LGPL_DECODER) += proresdec_lgpl.o proresdsp.o
OBJS-$(CONFIG_PTX_DECODER) += ptx.o
OBJS-$(CONFIG_QCELP_DECODER) += qcelpdec.o celp_math.o \
celp_filters.o acelp_vectors.o \
@@ -322,9 +343,9 @@ OBJS-$(CONFIG_RV10_DECODER) += rv10.o
OBJS-$(CONFIG_RV10_ENCODER) += rv10enc.o
OBJS-$(CONFIG_RV20_DECODER) += rv10.o
OBJS-$(CONFIG_RV20_ENCODER) += rv20enc.o
-OBJS-$(CONFIG_RV30_DECODER) += rv30.o rv34.o rv30dsp.o \
+OBJS-$(CONFIG_RV30_DECODER) += rv30.o rv34.o rv30dsp.o rv34dsp.o \
mpegvideo.o error_resilience.o
-OBJS-$(CONFIG_RV40_DECODER) += rv40.o rv34.o rv40dsp.o \
+OBJS-$(CONFIG_RV40_DECODER) += rv40.o rv34.o rv34dsp.o rv40dsp.o \
mpegvideo.o error_resilience.o
OBJS-$(CONFIG_S302M_DECODER) += s302m.o
OBJS-$(CONFIG_SGI_DECODER) += sgidec.o
@@ -344,8 +365,12 @@ OBJS-$(CONFIG_SNOW_ENCODER) += snow.o rangecoder.o motion_est.o \
ituh263enc.o mpegvideo_enc.o \
mpeg12data.o
OBJS-$(CONFIG_SOL_DPCM_DECODER) += dpcm.o
+OBJS-$(CONFIG_SONIC_DECODER) += sonic.o
+OBJS-$(CONFIG_SONIC_ENCODER) += sonic.o
+OBJS-$(CONFIG_SONIC_LS_ENCODER) += sonic.o
OBJS-$(CONFIG_SP5X_DECODER) += sp5xdec.o mjpegdec.o mjpeg.o
OBJS-$(CONFIG_SRT_DECODER) += srtdec.o ass.o
+OBJS-$(CONFIG_SRT_ENCODER) += srtenc.o ass_split.o
OBJS-$(CONFIG_SUNRAST_DECODER) += sunrast.o
OBJS-$(CONFIG_SVQ1_DECODER) += svq1dec.o svq1.o h263.o \
mpegvideo.o error_resilience.o
@@ -376,6 +401,7 @@ OBJS-$(CONFIG_TTA_DECODER) += tta.o
OBJS-$(CONFIG_TWINVQ_DECODER) += twinvq.o celp_math.o
OBJS-$(CONFIG_TXD_DECODER) += txd.o s3tc.o
OBJS-$(CONFIG_ULTI_DECODER) += ulti.o
+OBJS-$(CONFIG_UTVIDEO_DECODER) += utvideo.o
OBJS-$(CONFIG_V210_DECODER) += v210dec.o
OBJS-$(CONFIG_V210_ENCODER) += v210enc.o
OBJS-$(CONFIG_V210X_DECODER) += v210x.o
@@ -422,6 +448,7 @@ OBJS-$(CONFIG_WS_SND1_DECODER) += ws-snd1.o
OBJS-$(CONFIG_XAN_DPCM_DECODER) += dpcm.o
OBJS-$(CONFIG_XAN_WC3_DECODER) += xan.o
OBJS-$(CONFIG_XAN_WC4_DECODER) += xxan.o
+OBJS-$(CONFIG_XBIN_DECODER) += bintext.o cga_data.o
OBJS-$(CONFIG_XL_DECODER) += xl.o
OBJS-$(CONFIG_XSUB_DECODER) += xsubdec.o
OBJS-$(CONFIG_XSUB_ENCODER) += xsubenc.o
@@ -482,10 +509,10 @@ OBJS-$(CONFIG_PCM_U32LE_ENCODER) += pcm.o
OBJS-$(CONFIG_PCM_ZORK_DECODER) += pcm.o
OBJS-$(CONFIG_PCM_ZORK_ENCODER) += pcm.o
-OBJS-$(CONFIG_ADPCM_4XM_DECODER) += adpcm.o
+OBJS-$(CONFIG_ADPCM_4XM_DECODER) += adpcm.o adpcm_data.o
OBJS-$(CONFIG_ADPCM_ADX_DECODER) += adxdec.o
OBJS-$(CONFIG_ADPCM_ADX_ENCODER) += adxenc.o
-OBJS-$(CONFIG_ADPCM_CT_DECODER) += adpcm.o
+OBJS-$(CONFIG_ADPCM_CT_DECODER) += adpcm.o adpcm_data.o
OBJS-$(CONFIG_ADPCM_EA_DECODER) += adpcm.o
OBJS-$(CONFIG_ADPCM_EA_MAXIS_XA_DECODER) += adpcm.o
OBJS-$(CONFIG_ADPCM_EA_R1_DECODER) += adpcm.o
@@ -496,62 +523,68 @@ OBJS-$(CONFIG_ADPCM_G722_DECODER) += g722.o
OBJS-$(CONFIG_ADPCM_G722_ENCODER) += g722.o
OBJS-$(CONFIG_ADPCM_G726_DECODER) += g726.o
OBJS-$(CONFIG_ADPCM_G726_ENCODER) += g726.o
-OBJS-$(CONFIG_ADPCM_IMA_AMV_DECODER) += adpcm.o
-OBJS-$(CONFIG_ADPCM_IMA_DK3_DECODER) += adpcm.o
-OBJS-$(CONFIG_ADPCM_IMA_DK4_DECODER) += adpcm.o
-OBJS-$(CONFIG_ADPCM_IMA_EA_EACS_DECODER) += adpcm.o
-OBJS-$(CONFIG_ADPCM_IMA_EA_SEAD_DECODER) += adpcm.o
-OBJS-$(CONFIG_ADPCM_IMA_ISS_DECODER) += adpcm.o
-OBJS-$(CONFIG_ADPCM_IMA_QT_DECODER) += adpcm.o
-OBJS-$(CONFIG_ADPCM_IMA_QT_ENCODER) += adpcm.o
-OBJS-$(CONFIG_ADPCM_IMA_SMJPEG_DECODER) += adpcm.o
-OBJS-$(CONFIG_ADPCM_IMA_WAV_DECODER) += adpcm.o
-OBJS-$(CONFIG_ADPCM_IMA_WAV_ENCODER) += adpcm.o
-OBJS-$(CONFIG_ADPCM_IMA_WS_DECODER) += adpcm.o
-OBJS-$(CONFIG_ADPCM_MS_DECODER) += adpcm.o
-OBJS-$(CONFIG_ADPCM_MS_ENCODER) += adpcm.o
+OBJS-$(CONFIG_ADPCM_IMA_AMV_DECODER) += adpcm.o adpcm_data.o
+OBJS-$(CONFIG_ADPCM_IMA_DK3_DECODER) += adpcm.o adpcm_data.o
+OBJS-$(CONFIG_ADPCM_IMA_DK4_DECODER) += adpcm.o adpcm_data.o
+OBJS-$(CONFIG_ADPCM_IMA_EA_EACS_DECODER) += adpcm.o adpcm_data.o
+OBJS-$(CONFIG_ADPCM_IMA_EA_SEAD_DECODER) += adpcm.o adpcm_data.o
+OBJS-$(CONFIG_ADPCM_IMA_ISS_DECODER) += adpcm.o adpcm_data.o
+OBJS-$(CONFIG_ADPCM_IMA_QT_DECODER) += adpcm.o adpcm_data.o
+OBJS-$(CONFIG_ADPCM_IMA_QT_ENCODER) += adpcmenc.o adpcm_data.o
+OBJS-$(CONFIG_ADPCM_IMA_SMJPEG_DECODER) += adpcm.o adpcm_data.o
+OBJS-$(CONFIG_ADPCM_IMA_WAV_DECODER) += adpcm.o adpcm_data.o
+OBJS-$(CONFIG_ADPCM_IMA_WAV_ENCODER) += adpcmenc.o adpcm_data.o
+OBJS-$(CONFIG_ADPCM_IMA_WS_DECODER) += adpcm.o adpcm_data.o
+OBJS-$(CONFIG_ADPCM_MS_DECODER) += adpcm.o adpcm_data.o
+OBJS-$(CONFIG_ADPCM_MS_ENCODER) += adpcmenc.o adpcm_data.o
OBJS-$(CONFIG_ADPCM_SBPRO_2_DECODER) += adpcm.o
OBJS-$(CONFIG_ADPCM_SBPRO_3_DECODER) += adpcm.o
OBJS-$(CONFIG_ADPCM_SBPRO_4_DECODER) += adpcm.o
-OBJS-$(CONFIG_ADPCM_SWF_DECODER) += adpcm.o
-OBJS-$(CONFIG_ADPCM_SWF_ENCODER) += adpcm.o
+OBJS-$(CONFIG_ADPCM_SWF_DECODER) += adpcm.o adpcm_data.o
+OBJS-$(CONFIG_ADPCM_SWF_ENCODER) += adpcmenc.o adpcm_data.o
OBJS-$(CONFIG_ADPCM_THP_DECODER) += adpcm.o
OBJS-$(CONFIG_ADPCM_XA_DECODER) += adpcm.o
-OBJS-$(CONFIG_ADPCM_YAMAHA_DECODER) += adpcm.o
-OBJS-$(CONFIG_ADPCM_YAMAHA_ENCODER) += adpcm.o
+OBJS-$(CONFIG_ADPCM_YAMAHA_DECODER) += adpcm.o adpcm_data.o
+OBJS-$(CONFIG_ADPCM_YAMAHA_ENCODER) += adpcmenc.o adpcm_data.o
# libavformat dependencies
OBJS-$(CONFIG_ADTS_MUXER) += mpeg4audio.o
OBJS-$(CONFIG_CAF_DEMUXER) += mpeg4audio.o mpegaudiodata.o
OBJS-$(CONFIG_DV_DEMUXER) += dvdata.o
-OBJS-$(CONFIG_DV_MUXER) += dvdata.o
-OBJS-$(CONFIG_FLAC_DEMUXER) += flacdec.o flacdata.o flac.o
-OBJS-$(CONFIG_FLAC_MUXER) += flacdec.o flacdata.o flac.o
+OBJS-$(CONFIG_DV_MUXER) += dvdata.o timecode.o
+OBJS-$(CONFIG_FLAC_DEMUXER) += flacdec.o flacdata.o flac.o vorbis_data.o
+OBJS-$(CONFIG_FLAC_MUXER) += flacdec.o flacdata.o flac.o vorbis_data.o
OBJS-$(CONFIG_FLV_DEMUXER) += mpeg4audio.o
OBJS-$(CONFIG_GXF_DEMUXER) += mpeg12data.o
OBJS-$(CONFIG_IFF_DEMUXER) += iff.o
-OBJS-$(CONFIG_MATROSKA_AUDIO_MUXER) += xiph.o mpeg4audio.o \
+OBJS-$(CONFIG_LATM_MUXER) += mpeg4audio.o
+OBJS-$(CONFIG_MATROSKA_AUDIO_MUXER) += xiph.o mpeg4audio.o vorbis_data.o \
flacdec.o flacdata.o flac.o
OBJS-$(CONFIG_MATROSKA_DEMUXER) += mpeg4audio.o mpegaudiodata.o
OBJS-$(CONFIG_MATROSKA_MUXER) += xiph.o mpeg4audio.o \
flacdec.o flacdata.o flac.o \
- mpegaudiodata.o
+ mpegaudiodata.o vorbis_data.o
+OBJS-$(CONFIG_MP3_MUXER) += mpegaudiodata.o mpegaudiodecheader.o
OBJS-$(CONFIG_MOV_DEMUXER) += mpeg4audio.o mpegaudiodata.o
OBJS-$(CONFIG_MOV_MUXER) += mpeg4audio.o mpegaudiodata.o
OBJS-$(CONFIG_MPEGTS_MUXER) += mpegvideo.o mpeg4audio.o
OBJS-$(CONFIG_MPEGTS_DEMUXER) += mpeg4audio.o mpegaudiodata.o
+OBJS-$(CONFIG_MXF_MUXER) += timecode.o
OBJS-$(CONFIG_NUT_MUXER) += mpegaudiodata.o
OBJS-$(CONFIG_OGG_DEMUXER) += flacdec.o flacdata.o flac.o \
- dirac.o mpeg12data.o
-OBJS-$(CONFIG_OGG_MUXER) += xiph.o flacdec.o flacdata.o flac.o
+ dirac.o mpeg12data.o vorbis_data.o
+OBJS-$(CONFIG_OGG_MUXER) += xiph.o flacdec.o flacdata.o flac.o \
+ vorbis_data.o
OBJS-$(CONFIG_RTP_MUXER) += mpeg4audio.o mpegvideo.o xiph.o
OBJS-$(CONFIG_SPDIF_DEMUXER) += aacadtsdec.o mpeg4audio.o
OBJS-$(CONFIG_WEBM_MUXER) += xiph.o mpeg4audio.o \
flacdec.o flacdata.o flac.o \
- mpegaudiodata.o
+ mpegaudiodata.o vorbis_data.o
OBJS-$(CONFIG_WTV_DEMUXER) += mpeg4audio.o mpegaudiodata.o
# external codec libraries
+OBJS-$(CONFIG_LIBAACPLUS_ENCODER) += libaacplus.o
+OBJS-$(CONFIG_LIBCELT_DECODER) += libcelt_dec.o
OBJS-$(CONFIG_LIBDIRAC_DECODER) += libdiracdec.o
OBJS-$(CONFIG_LIBDIRAC_ENCODER) += libdiracenc.o libdirac_libschro.o
OBJS-$(CONFIG_LIBFAAC_ENCODER) += libfaac.o
@@ -571,7 +604,10 @@ OBJS-$(CONFIG_LIBSCHROEDINGER_ENCODER) += libschroedingerenc.o \
libschroedinger.o \
libdirac_libschro.o
OBJS-$(CONFIG_LIBSPEEX_DECODER) += libspeexdec.o
+OBJS-$(CONFIG_LIBSPEEX_ENCODER) += libspeexenc.o
+OBJS-$(CONFIG_LIBSTAGEFRIGHT_H264_DECODER)+= libstagefright.o
OBJS-$(CONFIG_LIBTHEORA_ENCODER) += libtheoraenc.o
+OBJS-$(CONFIG_LIBUTVIDEO_DECODER) += libutvideo.o
OBJS-$(CONFIG_LIBVO_AACENC_ENCODER) += libvo-aacenc.o mpeg4audio.o
OBJS-$(CONFIG_LIBVO_AMRWBENC_ENCODER) += libvo-amrwbenc.o
OBJS-$(CONFIG_LIBVORBIS_ENCODER) += libvorbis.o vorbis_data.o
@@ -592,7 +628,8 @@ OBJS-$(CONFIG_DIRAC_PARSER) += dirac_parser.o
OBJS-$(CONFIG_DNXHD_PARSER) += dnxhd_parser.o
OBJS-$(CONFIG_DVBSUB_PARSER) += dvbsub_parser.o
OBJS-$(CONFIG_DVDSUB_PARSER) += dvdsub_parser.o
-OBJS-$(CONFIG_FLAC_PARSER) += flac_parser.o flacdata.o flac.o
+OBJS-$(CONFIG_FLAC_PARSER) += flac_parser.o flacdata.o flac.o \
+ vorbis_data.o
OBJS-$(CONFIG_H261_PARSER) += h261_parser.o
OBJS-$(CONFIG_H263_PARSER) += h263_parser.o
OBJS-$(CONFIG_H264_PARSER) += h264_parser.o h264.o \
@@ -614,6 +651,8 @@ OBJS-$(CONFIG_MPEGVIDEO_PARSER) += mpegvideo_parser.o \
mpeg12.o mpeg12data.o \
mpegvideo.o error_resilience.o
OBJS-$(CONFIG_PNM_PARSER) += pnm_parser.o pnm.o
+OBJS-$(CONFIG_RV30_PARSER) += rv34_parser.o
+OBJS-$(CONFIG_RV40_PARSER) += rv34_parser.o
OBJS-$(CONFIG_VC1_PARSER) += vc1_parser.o vc1.o vc1data.o \
msmpeg4.o msmpeg4data.o mpeg4video.o \
h263.o mpegvideo.o error_resilience.o
@@ -639,7 +678,7 @@ OBJS-$(CONFIG_TEXT2MOVSUB_BSF) += movsub_bsf.o
# thread libraries
OBJS-$(HAVE_PTHREADS) += pthread.o
-OBJS-$(HAVE_W32THREADS) += w32thread.o
+OBJS-$(HAVE_W32THREADS) += pthread.o
OBJS-$(CONFIG_MLIB) += mlib/dsputil_mlib.o \
@@ -663,8 +702,7 @@ SKIPHEADERS-$(CONFIG_LIBSCHROEDINGER) += libschroedinger.h
SKIPHEADERS-$(CONFIG_VAAPI) += vaapi_internal.h
SKIPHEADERS-$(CONFIG_VDPAU) += vdpau.h
SKIPHEADERS-$(CONFIG_XVMC) += xvmc.h
-
-EXAMPLES = api
+SKIPHEADERS-$(HAVE_W32THREADS) += w32pthreads.h
TESTPROGS = cabac dct fft fft-fixed h264 iirfilter rangecoder snow
TESTPROGS-$(HAVE_MMX) += motion
@@ -714,3 +752,9 @@ $(SUBDIR)motionpixels.o: $(SUBDIR)motionpixels_tables.h
$(SUBDIR)pcm.o: $(SUBDIR)pcm_tables.h
$(SUBDIR)qdm2.o: $(SUBDIR)qdm2_tables.h
endif
+
+CODEC_NAMES_SH := $(SRC_PATH)/$(SUBDIR)codec_names.sh
+AVCODEC_H := $(SRC_PATH)/$(SUBDIR)avcodec.h
+$(SUBDIR)codec_names.h: $(CODEC_NAMES_SH) config.h $(AVCODEC_H)
+ $(M)$(CODEC_NAMES_SH) config.h $(AVCODEC_H) $@
+$(SUBDIR)utils.o: $(SUBDIR)codec_names.h
diff --git a/libavcodec/a64colors.h b/libavcodec/a64colors.h
index d977426fc0..a9cdb6fa76 100644
--- a/libavcodec/a64colors.h
+++ b/libavcodec/a64colors.h
@@ -2,20 +2,20 @@
* a64 video encoder - c64 colors in rgb (Pepto)
* Copyright (c) 2009 Tobias Bindhammer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/a64enc.h b/libavcodec/a64enc.h
index b64b952fe4..fb559ba82b 100644
--- a/libavcodec/a64enc.h
+++ b/libavcodec/a64enc.h
@@ -2,20 +2,20 @@
* a64 video encoder - basic headers
* Copyright (c) 2009 Tobias Bindhammer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/a64multienc.c b/libavcodec/a64multienc.c
index 532f2a2824..5a665d0592 100644
--- a/libavcodec/a64multienc.c
+++ b/libavcodec/a64multienc.c
@@ -2,20 +2,20 @@
* a64 video encoder - multicolor modes
* Copyright (c) 2009 Tobias Bindhammer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/a64tables.h b/libavcodec/a64tables.h
index b95c5ce754..a955ef4caa 100644
--- a/libavcodec/a64tables.h
+++ b/libavcodec/a64tables.h
@@ -2,20 +2,20 @@
* a64 video encoder - tables used by a64 encoders
* Copyright (c) 2009 Tobias Bindhammer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/aac.h b/libavcodec/aac.h
index 4861ec0320..d01534de3f 100644
--- a/libavcodec/aac.h
+++ b/libavcodec/aac.h
@@ -3,20 +3,20 @@
* Copyright (c) 2005-2006 Oded Shimon ( ods15 ods15 dyndns org )
* Copyright (c) 2006-2007 Maxim Gavrilov ( maxim.gavrilov gmail com )
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -104,11 +104,11 @@ enum CouplingPoint {
* Output configuration status
*/
enum OCStatus {
- OC_NONE, //< Output unconfigured
- OC_TRIAL_PCE, //< Output configuration under trial specified by an inband PCE
- OC_TRIAL_FRAME, //< Output configuration under trial specified by a frame header
- OC_GLOBAL_HDR, //< Output configuration set in a global header but not yet locked
- OC_LOCKED, //< Output configuration locked in place
+ OC_NONE, ///< Output unconfigured
+ OC_TRIAL_PCE, ///< Output configuration under trial specified by an inband PCE
+ OC_TRIAL_FRAME, ///< Output configuration under trial specified by a frame header
+ OC_GLOBAL_HDR, ///< Output configuration set in a global header but not yet locked
+ OC_LOCKED, ///< Output configuration locked in place
};
/**
diff --git a/libavcodec/aac_ac3_parser.c b/libavcodec/aac_ac3_parser.c
index 58f30a4180..6f6ed895f0 100644
--- a/libavcodec/aac_ac3_parser.c
+++ b/libavcodec/aac_ac3_parser.c
@@ -3,20 +3,20 @@
* Copyright (c) 2003 Fabrice Bellard
* Copyright (c) 2003 Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/aac_ac3_parser.h b/libavcodec/aac_ac3_parser.h
index c4ed816d93..ccc387d3aa 100644
--- a/libavcodec/aac_ac3_parser.h
+++ b/libavcodec/aac_ac3_parser.h
@@ -3,20 +3,20 @@
* Copyright (c) 2003 Fabrice Bellard
* Copyright (c) 2003 Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/aac_adtstoasc_bsf.c b/libavcodec/aac_adtstoasc_bsf.c
index fbb86f8af7..3cb065ed5e 100644
--- a/libavcodec/aac_adtstoasc_bsf.c
+++ b/libavcodec/aac_adtstoasc_bsf.c
@@ -2,20 +2,20 @@
* MPEG-2/4 AAC ADTS to MPEG-4 Audio Specific Configuration bitstream filter
* Copyright (c) 2009 Alex Converse <alex.converse@gmail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -55,7 +55,7 @@ static int aac_adtstoasc_filter(AVBitStreamFilterContext *bsfc,
if (show_bits(&gb, 12) != 0xfff)
return 0;
- if (ff_aac_parse_header(&gb, &hdr) < 0) {
+ if (avpriv_aac_parse_header(&gb, &hdr) < 0) {
av_log(avctx, AV_LOG_ERROR, "Error parsing ADTS frame header!\n");
return -1;
}
@@ -72,13 +72,13 @@ static int aac_adtstoasc_filter(AVBitStreamFilterContext *bsfc,
int pce_size = 0;
uint8_t pce_data[MAX_PCE_SIZE];
if (!hdr.chan_config) {
- init_get_bits(&gb, buf, buf_size);
+ init_get_bits(&gb, buf, buf_size * 8);
if (get_bits(&gb, 3) != 5) {
av_log_missing_feature(avctx, "PCE based channel configuration, where the PCE is not the first syntax element is", 0);
return -1;
}
init_put_bits(&pb, pce_data, MAX_PCE_SIZE);
- pce_size = ff_copy_pce_data(&pb, &gb)/8;
+ pce_size = avpriv_copy_pce_data(&pb, &gb)/8;
flush_put_bits(&pb);
buf_size -= get_bits_count(&gb)/8;
buf += get_bits_count(&gb)/8;
diff --git a/libavcodec/aac_parser.c b/libavcodec/aac_parser.c
index 1c5546e7aa..3982ce6f91 100644
--- a/libavcodec/aac_parser.c
+++ b/libavcodec/aac_parser.c
@@ -3,20 +3,20 @@
* Copyright (c) 2003 Fabrice Bellard
* Copyright (c) 2003 Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -40,7 +40,7 @@ static int aac_sync(uint64_t state, AACAC3ParseContext *hdr_info,
tmp.u64 = av_be2ne64(state);
init_get_bits(&bits, tmp.u8+8-AAC_ADTS_HEADER_SIZE, AAC_ADTS_HEADER_SIZE * 8);
- if ((size = ff_aac_parse_header(&bits, &hdr)) < 0)
+ if ((size = avpriv_aac_parse_header(&bits, &hdr)) < 0)
return 0;
*need_next_header = 0;
*new_frame_start = 1;
diff --git a/libavcodec/aac_tablegen.c b/libavcodec/aac_tablegen.c
index b2c6c954e0..33a179f51e 100644
--- a/libavcodec/aac_tablegen.c
+++ b/libavcodec/aac_tablegen.c
@@ -3,20 +3,20 @@
*
* Copyright (c) 2010 Alex Converse <alex.converse@gmail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/aac_tablegen.h b/libavcodec/aac_tablegen.h
index 8773d9b975..7afa466139 100644
--- a/libavcodec/aac_tablegen.h
+++ b/libavcodec/aac_tablegen.h
@@ -3,20 +3,20 @@
*
* Copyright (c) 2010 Alex Converse <alex.converse@gmail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/aac_tablegen_decl.h b/libavcodec/aac_tablegen_decl.h
index 496ca0c677..0d86e80bc2 100644
--- a/libavcodec/aac_tablegen_decl.h
+++ b/libavcodec/aac_tablegen_decl.h
@@ -3,20 +3,20 @@
*
* Copyright (c) 2010 Alex Converse <alex.converse@gmail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/aacadtsdec.c b/libavcodec/aacadtsdec.c
index a9ff8ef63d..c9718c4599 100644
--- a/libavcodec/aacadtsdec.c
+++ b/libavcodec/aacadtsdec.c
@@ -4,20 +4,20 @@
* Copyright (c) 2003 Michael Niedermayer
* Copyright (c) 2009 Alex Converse
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -26,7 +26,7 @@
#include "get_bits.h"
#include "mpeg4audio.h"
-int ff_aac_parse_header(GetBitContext *gbc, AACADTSHeaderInfo *hdr)
+int avpriv_aac_parse_header(GetBitContext *gbc, AACADTSHeaderInfo *hdr)
{
int size, rdb, ch, sr;
int aot, crc_abs;
@@ -39,7 +39,7 @@ int ff_aac_parse_header(GetBitContext *gbc, AACADTSHeaderInfo *hdr)
crc_abs = get_bits1(gbc); /* protection_absent */
aot = get_bits(gbc, 2); /* profile_objecttype */
sr = get_bits(gbc, 4); /* sample_frequency_index */
- if(!ff_mpeg4audio_sample_rates[sr])
+ if(!avpriv_mpeg4audio_sample_rates[sr])
return AAC_AC3_PARSE_ERROR_SAMPLE_RATE;
skip_bits1(gbc); /* private_bit */
ch = get_bits(gbc, 3); /* channel_configuration */
@@ -62,7 +62,7 @@ int ff_aac_parse_header(GetBitContext *gbc, AACADTSHeaderInfo *hdr)
hdr->crc_absent = crc_abs;
hdr->num_aac_frames = rdb + 1;
hdr->sampling_index = sr;
- hdr->sample_rate = ff_mpeg4audio_sample_rates[sr];
+ hdr->sample_rate = avpriv_mpeg4audio_sample_rates[sr];
hdr->samples = (rdb + 1) * 1024;
hdr->bit_rate = size * 8 * hdr->sample_rate / hdr->samples;
diff --git a/libavcodec/aacadtsdec.h b/libavcodec/aacadtsdec.h
index 2fa1b4b2fc..fb2cbd9b35 100644
--- a/libavcodec/aacadtsdec.h
+++ b/libavcodec/aacadtsdec.h
@@ -3,20 +3,20 @@
* Copyright (c) 2003 Fabrice Bellard
* Copyright (c) 2003 Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -49,6 +49,6 @@ typedef struct {
* -2 if the version element is invalid, -3 if the sample rate
* element is invalid, or -4 if the bit rate element is invalid.
*/
-int ff_aac_parse_header(GetBitContext *gbc, AACADTSHeaderInfo *hdr);
+int avpriv_aac_parse_header(GetBitContext *gbc, AACADTSHeaderInfo *hdr);
#endif /* AVCODEC_AACADTSDEC_H */
diff --git a/libavcodec/aaccoder.c b/libavcodec/aaccoder.c
index b64bf9fa2d..b61af18056 100644
--- a/libavcodec/aaccoder.c
+++ b/libavcodec/aaccoder.c
@@ -2,20 +2,20 @@
* AAC coefficients encoder
* Copyright (C) 2008-2009 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -33,6 +33,7 @@
#include "libavutil/libm.h" // brought forward to work around cygwin header breakage
#include <float.h>
+#include <math.h>
#include "avcodec.h"
#include "put_bits.h"
#include "aac.h"
diff --git a/libavcodec/aacdec.c b/libavcodec/aacdec.c
index f26a4b74a7..97fddfc95c 100644
--- a/libavcodec/aacdec.c
+++ b/libavcodec/aacdec.c
@@ -7,20 +7,20 @@
* Copyright (c) 2008-2010 Paul Kendall <paul@kcbbs.gen.nz>
* Copyright (c) 2010 Janne Grunau <janne-ffmpeg@jannau.net>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -170,7 +170,7 @@ static ChannelElement *get_che(AACContext *ac, int type, int elem_id)
/**
* Check for the channel element in the current channel position configuration.
* If it exists, make sure the appropriate element is allocated and map the
- * channel order to match the internal Libav channel layout.
+ * channel order to match the internal FFmpeg channel layout.
*
* @param che_pos current channel position configuration
* @param type channel element type
@@ -251,8 +251,6 @@ static av_cold int output_configure(AACContext *ac,
}
memcpy(ac->tag_che_map, ac->che, 4 * MAX_ELEM_ID * sizeof(ac->che[0][0]));
-
- avctx->channel_layout = 0;
}
avctx->channels = channels;
@@ -315,6 +313,10 @@ static int decode_pce(AVCodecContext *avctx, MPEG4AudioConfig *m4ac,
if (get_bits1(gb))
skip_bits(gb, 3); // mixdown_coeff_index and pseudo_surround
+ if (get_bits_left(gb) < 4 * (num_front + num_side + num_back + num_lfe + num_assoc_data + num_cc)) {
+ av_log(avctx, AV_LOG_ERROR, overread_err);
+ return -1;
+ }
decode_channel_map(new_che_pos[TYPE_CPE], new_che_pos[TYPE_SCE], AAC_CHANNEL_FRONT, gb, num_front);
decode_channel_map(new_che_pos[TYPE_CPE], new_che_pos[TYPE_SCE], AAC_CHANNEL_SIDE, gb, num_side );
decode_channel_map(new_che_pos[TYPE_CPE], new_che_pos[TYPE_SCE], AAC_CHANNEL_BACK, gb, num_back );
@@ -458,7 +460,7 @@ static int decode_ga_specific_config(AACContext *ac, AVCodecContext *avctx,
static int decode_audio_specific_config(AACContext *ac,
AVCodecContext *avctx,
MPEG4AudioConfig *m4ac,
- const uint8_t *data, int data_size)
+ const uint8_t *data, int data_size, int asclen)
{
GetBitContext gb;
int i;
@@ -470,7 +472,7 @@ static int decode_audio_specific_config(AACContext *ac,
init_get_bits(&gb, data, data_size * 8);
- if ((i = ff_mpeg4audio_get_config(m4ac, data, data_size)) < 0)
+ if ((i = avpriv_mpeg4audio_get_config(m4ac, data, asclen/8)) < 0)
return -1;
if (m4ac->sampling_index > 12) {
av_log(avctx, AV_LOG_ERROR, "invalid sampling rate index %d\n", m4ac->sampling_index);
@@ -568,12 +570,9 @@ static av_cold int aac_decode_init(AVCodecContext *avctx)
ac->m4ac.sample_rate = avctx->sample_rate;
if (avctx->extradata_size > 0) {
- avctx->channels = 0;
- avctx->frame_size = 0;
- avctx->sample_rate = 0;
if (decode_audio_specific_config(ac, ac->avctx, &ac->m4ac,
avctx->extradata,
- avctx->extradata_size) < 0)
+ avctx->extradata_size, 8*avctx->extradata_size) < 0)
return -1;
} else {
int sr, i;
@@ -582,6 +581,8 @@ static av_cold int aac_decode_init(AVCodecContext *avctx)
sr = sample_rate_idx(avctx->sample_rate);
ac->m4ac.sampling_index = sr;
ac->m4ac.channels = avctx->channels;
+ ac->m4ac.sbr = -1;
+ ac->m4ac.ps = -1;
for (i = 0; i < FF_ARRAY_ELEMS(ff_mpeg4audio_channels); i++)
if (ff_mpeg4audio_channels[i] == avctx->channels)
@@ -592,8 +593,11 @@ static av_cold int aac_decode_init(AVCodecContext *avctx)
ac->m4ac.chan_config = i;
if (ac->m4ac.chan_config) {
- set_default_channel_config(avctx, new_che_pos, ac->m4ac.chan_config);
- output_configure(ac, ac->che_pos, new_che_pos, ac->m4ac.chan_config, OC_GLOBAL_HDR);
+ int ret = set_default_channel_config(avctx, new_che_pos, ac->m4ac.chan_config);
+ if (!ret)
+ output_configure(ac, ac->che_pos, new_che_pos, ac->m4ac.chan_config, OC_GLOBAL_HDR);
+ else if (avctx->error_recognition >= FF_ER_EXPLODE)
+ return AVERROR_INVALIDDATA;
}
}
@@ -1127,7 +1131,7 @@ static int decode_spectrum_and_dequant(AACContext *ac, float coef[1024],
GET_VLC(code, re, gb, vlc_tab, 8, 2);
cb_idx = cb_vector_idx[code];
nnz = cb_idx >> 8 & 15;
- bits = SHOW_UBITS(re, gb, nnz) << (32-nnz);
+ bits = nnz ? GET_CACHE(re, gb) : 0;
LAST_SKIP_BITS(re, gb, nnz);
cf = VMUL4S(cf, vq, cb_idx, bits, sf + idx);
} while (len -= 4);
@@ -1167,7 +1171,7 @@ static int decode_spectrum_and_dequant(AACContext *ac, float coef[1024],
GET_VLC(code, re, gb, vlc_tab, 8, 2);
cb_idx = cb_vector_idx[code];
nnz = cb_idx >> 8 & 15;
- sign = SHOW_UBITS(re, gb, nnz) << (cb_idx >> 12);
+ sign = nnz ? SHOW_UBITS(re, gb, nnz) << (cb_idx >> 12) : 0;
LAST_SKIP_BITS(re, gb, nnz);
cf = VMUL2S(cf, vq, cb_idx, sign, sf + idx);
} while (len -= 2);
@@ -1792,12 +1796,10 @@ static void windowing_and_mdct_ltp(AACContext *ac, float *out,
} else {
memset(in, 0, 448 * sizeof(float));
ac->dsp.vector_fmul(in + 448, in + 448, swindow_prev, 128);
- memcpy(in + 576, in + 576, 448 * sizeof(float));
}
if (ics->window_sequence[0] != LONG_START_SEQUENCE) {
ac->dsp.vector_fmul_reverse(in + 1024, in + 1024, lwindow, 1024);
} else {
- memcpy(in + 1024, in + 1024, 448 * sizeof(float));
ac->dsp.vector_fmul_reverse(in + 1024 + 448, in + 1024 + 448, swindow, 128);
memset(in + 1024 + 576, 0, 448 * sizeof(float));
}
@@ -2075,9 +2077,9 @@ static int parse_adts_frame_header(AACContext *ac, GetBitContext *gb)
int size;
AACADTSHeaderInfo hdr_info;
- size = ff_aac_parse_header(gb, &hdr_info);
+ size = avpriv_aac_parse_header(gb, &hdr_info);
if (size > 0) {
- if (ac->output_configured != OC_LOCKED && hdr_info.chan_config) {
+ if (hdr_info.chan_config) {
enum ChannelPosition new_che_pos[4][MAX_ELEM_ID];
memset(new_che_pos, 0, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0]));
ac->m4ac.chan_config = hdr_info.chan_config;
@@ -2092,10 +2094,10 @@ static int parse_adts_frame_header(AACContext *ac, GetBitContext *gb)
if (ac->output_configured != OC_LOCKED) {
ac->m4ac.sbr = -1;
ac->m4ac.ps = -1;
+ ac->m4ac.sample_rate = hdr_info.sample_rate;
+ ac->m4ac.sampling_index = hdr_info.sampling_index;
+ ac->m4ac.object_type = hdr_info.object_type;
}
- ac->m4ac.sample_rate = hdr_info.sample_rate;
- ac->m4ac.sampling_index = hdr_info.sampling_index;
- ac->m4ac.object_type = hdr_info.object_type;
if (!ac->avctx->sample_rate)
ac->avctx->sample_rate = hdr_info.sample_rate;
if (hdr_info.num_aac_frames == 1) {
@@ -2116,7 +2118,7 @@ static int aac_decode_frame_int(AVCodecContext *avctx, void *data,
ChannelElement *che = NULL, *che_prev = NULL;
enum RawDataBlockType elem_type, elem_type_prev = TYPE_END;
int err, elem_id, data_size_tmp;
- int samples = 0, multiplier;
+ int samples = 0, multiplier, audio_found = 0;
if (show_bits(gb, 12) == 0xfff) {
if (parse_adts_frame_header(ac, gb) < 0) {
@@ -2135,6 +2137,15 @@ static int aac_decode_frame_int(AVCodecContext *avctx, void *data,
elem_id = get_bits(gb, 4);
if (elem_type < TYPE_DSE) {
+ if (!ac->tags_mapped && elem_type == TYPE_CPE && ac->m4ac.chan_config==1) {
+ enum ChannelPosition new_che_pos[4][MAX_ELEM_ID]= {0};
+ ac->m4ac.chan_config=2;
+
+ if (set_default_channel_config(ac->avctx, new_che_pos, 2)<0)
+ return -1;
+ if (output_configure(ac, ac->che_pos, new_che_pos, 2, OC_TRIAL_FRAME)<0)
+ return -1;
+ }
if (!(che=get_che(ac, elem_type, elem_id))) {
av_log(ac->avctx, AV_LOG_ERROR, "channel element %d.%d is not allocated\n",
elem_type, elem_id);
@@ -2147,10 +2158,12 @@ static int aac_decode_frame_int(AVCodecContext *avctx, void *data,
case TYPE_SCE:
err = decode_ics(ac, &che->ch[0], gb, 0, 0);
+ audio_found = 1;
break;
case TYPE_CPE:
err = decode_cpe(ac, gb, che);
+ audio_found = 1;
break;
case TYPE_CCE:
@@ -2159,6 +2172,7 @@ static int aac_decode_frame_int(AVCodecContext *avctx, void *data,
case TYPE_LFE:
err = decode_ics(ac, &che->ch[0], gb, 0, 0);
+ audio_found = 1;
break;
case TYPE_DSE:
@@ -2235,7 +2249,7 @@ static int aac_decode_frame_int(AVCodecContext *avctx, void *data,
samples, avctx->channels);
}
- if (ac->output_configured)
+ if (ac->output_configured && audio_found)
ac->output_configured = OC_LOCKED;
return 0;
@@ -2304,10 +2318,11 @@ static inline uint32_t latm_get_value(GetBitContext *b)
}
static int latm_decode_audio_specific_config(struct LATMContext *latmctx,
- GetBitContext *gb)
+ GetBitContext *gb, int asclen)
{
AVCodecContext *avctx = latmctx->aac_ctx.avctx;
- MPEG4AudioConfig m4ac;
+ AACContext *ac= &latmctx->aac_ctx;
+ MPEG4AudioConfig m4ac=ac->m4ac;
int config_start_bit = get_bits_count(gb);
int bits_consumed, esize;
@@ -2317,12 +2332,14 @@ static int latm_decode_audio_specific_config(struct LATMContext *latmctx,
return AVERROR_INVALIDDATA;
} else {
bits_consumed =
- decode_audio_specific_config(NULL, avctx, &m4ac,
+ decode_audio_specific_config(ac, avctx, &m4ac,
gb->buffer + (config_start_bit / 8),
- get_bits_left(gb) / 8);
+ get_bits_left(gb) / 8, asclen);
if (bits_consumed < 0)
return AVERROR_INVALIDDATA;
+ if(ac->m4ac.sample_rate != m4ac.sample_rate || m4ac.chan_config != ac->m4ac.chan_config)
+ ac->m4ac= m4ac;
esize = (bits_consumed+7) / 8;
@@ -2377,11 +2394,11 @@ static int read_stream_mux_config(struct LATMContext *latmctx,
// for all but first stream: use_same_config = get_bits(gb, 1);
if (!audio_mux_version) {
- if ((ret = latm_decode_audio_specific_config(latmctx, gb)) < 0)
+ if ((ret = latm_decode_audio_specific_config(latmctx, gb, 0)) < 0)
return ret;
} else {
int ascLen = latm_get_value(gb);
- if ((ret = latm_decode_audio_specific_config(latmctx, gb)) < 0)
+ if ((ret = latm_decode_audio_specific_config(latmctx, gb, ascLen)) < 0)
return ret;
ascLen -= ret;
skip_bits_long(gb, ascLen);
@@ -2542,14 +2559,13 @@ av_cold static int latm_decode_init(AVCodecContext *avctx)
AVCodec ff_aac_decoder = {
- "aac",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_AAC,
- sizeof(AACContext),
- aac_decode_init,
- NULL,
- aac_decode_close,
- aac_decode_frame,
+ .name = "aac",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_AAC,
+ .priv_data_size = sizeof(AACContext),
+ .init = aac_decode_init,
+ .close = aac_decode_close,
+ .decode = aac_decode_frame,
.long_name = NULL_IF_CONFIG_SMALL("Advanced Audio Coding"),
.sample_fmts = (const enum AVSampleFormat[]) {
AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE
diff --git a/libavcodec/aacdectab.h b/libavcodec/aacdectab.h
index 23a7868ab2..22ae00ff32 100644
--- a/libavcodec/aacdectab.h
+++ b/libavcodec/aacdectab.h
@@ -3,20 +3,20 @@
* Copyright (c) 2005-2006 Oded Shimon ( ods15 ods15 dyndns org )
* Copyright (c) 2006-2007 Maxim Gavrilov ( maxim.gavrilov gmail com )
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c
index eae933235f..d0b24d8b96 100644
--- a/libavcodec/aacenc.c
+++ b/libavcodec/aacenc.c
@@ -2,20 +2,20 @@
* AAC encoder
* Copyright (C) 2008 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -135,6 +135,15 @@ static const uint8_t aac_chan_configs[6][5] = {
{4, TYPE_SCE, TYPE_CPE, TYPE_CPE, TYPE_LFE}, // 6 channels - front center + stereo + back stereo + LFE
};
+static const uint8_t channel_maps[][AAC_MAX_CHANNELS] = {
+ { 0 },
+ { 0, 1 },
+ { 2, 0, 1 },
+ { 2, 0, 1, 3 },
+ { 2, 0, 1, 3, 4 },
+ { 2, 0, 1, 4, 5, 3 },
+};
+
/**
* Make AAC audio config object.
* @see 1.6.2.1 "Syntax - AudioSpecificConfig"
@@ -165,12 +174,13 @@ static av_cold int aac_encode_init(AVCodecContext *avctx)
AACEncContext *s = avctx->priv_data;
int i;
const uint8_t *sizes[2];
+ uint8_t grouping[AAC_MAX_CHANNELS];
int lengths[2];
avctx->frame_size = 1024;
for (i = 0; i < 16; i++)
- if (avctx->sample_rate == ff_mpeg4audio_sample_rates[i])
+ if (avctx->sample_rate == avpriv_mpeg4audio_sample_rates[i])
break;
if (i == 16) {
av_log(avctx, AV_LOG_ERROR, "Unsupported sample rate %d\n", avctx->sample_rate);
@@ -210,7 +220,9 @@ static av_cold int aac_encode_init(AVCodecContext *avctx)
sizes[1] = swb_size_128[i];
lengths[0] = ff_aac_num_swb_1024[i];
lengths[1] = ff_aac_num_swb_128[i];
- ff_psy_init(&s->psy, avctx, 2, sizes, lengths, s->chan_map[0], &s->chan_map[1]);
+ for (i = 0; i < s->chan_map[0]; i++)
+ grouping[i] = s->chan_map[i + 1] == TYPE_CPE;
+ ff_psy_init(&s->psy, avctx, 2, sizes, lengths, s->chan_map[0], grouping);
s->psypp = ff_psy_preprocess_init(avctx);
s->coder = &ff_aac_coders[2];
@@ -479,7 +491,7 @@ static void put_bitstream_info(AVCodecContext *avctx, AACEncContext *s,
put_bits(&s->pb, 8, namelen - 16);
put_bits(&s->pb, 4, 0); //extension type - filler
padbits = 8 - (put_bits_count(&s->pb) & 7);
- align_put_bits(&s->pb);
+ avpriv_align_put_bits(&s->pb);
for (i = 0; i < namelen - 2; i++)
put_bits(&s->pb, 8, name[i]);
put_bits(&s->pb, 12 - padbits, 0);
@@ -499,15 +511,24 @@ static int aac_encode_frame(AVCodecContext *avctx,
return 0;
if (data) {
if (!s->psypp) {
- memcpy(s->samples + 1024 * avctx->channels, data,
- 1024 * avctx->channels * sizeof(s->samples[0]));
+ if (avctx->channels <= 2) {
+ memcpy(s->samples + 1024 * avctx->channels, data,
+ 1024 * avctx->channels * sizeof(s->samples[0]));
+ } else {
+ for (i = 0; i < 1024; i++)
+ for (ch = 0; ch < avctx->channels; ch++)
+ s->samples[(i + 1024) * avctx->channels + ch] =
+ ((int16_t*)data)[i * avctx->channels +
+ channel_maps[avctx->channels-1][ch]];
+ }
} else {
start_ch = 0;
samples2 = s->samples + 1024 * avctx->channels;
for (i = 0; i < s->chan_map[0]; i++) {
tag = s->chan_map[i+1];
chans = tag == TYPE_CPE ? 2 : 1;
- ff_psy_preprocess(s->psypp, (uint16_t*)data + start_ch,
+ ff_psy_preprocess(s->psypp,
+ (uint16_t*)data + channel_maps[avctx->channels-1][start_ch],
samples2 + start_ch, start_ch, chans);
start_ch += chans;
}
@@ -537,6 +558,12 @@ static int aac_encode_frame(AVCodecContext *avctx,
wi[ch].window_shape = 0;
wi[ch].num_windows = 1;
wi[ch].grouping[0] = 1;
+
+ /* Only the lowest 12 coefficients are used in a LFE channel.
+ * The expression below results in only the bottom 8 coefficients
+ * being used for 11.025kHz to 16kHz sample rates.
+ */
+ ics->num_swb = s->samplerate_index >= 8 ? 1 : 3;
} else {
wi[ch] = s->psy.model->window(&s->psy, samples2, la, cur_channel,
ics->window_sequence[0]);
@@ -547,7 +574,7 @@ static int aac_encode_frame(AVCodecContext *avctx,
ics->use_kb_window[0] = wi[ch].window_shape;
ics->num_windows = wi[ch].num_windows;
ics->swb_sizes = s->psy.bands [ics->num_windows == 8];
- ics->num_swb = tag == TYPE_LFE ? 12 : s->psy.num_bands[ics->num_windows == 8];
+ ics->num_swb = tag == TYPE_LFE ? ics->num_swb : s->psy.num_bands[ics->num_windows == 8];
for (w = 0; w < ics->num_windows; w++)
ics->group_len[w] = wi[ch].grouping[w];
@@ -659,10 +686,10 @@ static av_cold int aac_encode_end(AVCodecContext *avctx)
#define AACENC_FLAGS AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM
static const AVOption aacenc_options[] = {
- {"stereo_mode", "Stereo coding method", offsetof(AACEncContext, options.stereo_mode), FF_OPT_TYPE_INT, {.dbl = 0}, -1, 1, AACENC_FLAGS, "stereo_mode"},
- {"auto", "Selected by the Encoder", 0, FF_OPT_TYPE_CONST, {.dbl = -1 }, INT_MIN, INT_MAX, AACENC_FLAGS, "stereo_mode"},
- {"ms_off", "Disable Mid/Side coding", 0, FF_OPT_TYPE_CONST, {.dbl = 0 }, INT_MIN, INT_MAX, AACENC_FLAGS, "stereo_mode"},
- {"ms_force", "Force Mid/Side for the whole frame if possible", 0, FF_OPT_TYPE_CONST, {.dbl = 1 }, INT_MIN, INT_MAX, AACENC_FLAGS, "stereo_mode"},
+ {"stereo_mode", "Stereo coding method", offsetof(AACEncContext, options.stereo_mode), AV_OPT_TYPE_INT, {.dbl = 0}, -1, 1, AACENC_FLAGS, "stereo_mode"},
+ {"auto", "Selected by the Encoder", 0, AV_OPT_TYPE_CONST, {.dbl = -1 }, INT_MIN, INT_MAX, AACENC_FLAGS, "stereo_mode"},
+ {"ms_off", "Disable Mid/Side coding", 0, AV_OPT_TYPE_CONST, {.dbl = 0 }, INT_MIN, INT_MAX, AACENC_FLAGS, "stereo_mode"},
+ {"ms_force", "Force Mid/Side for the whole frame if possible", 0, AV_OPT_TYPE_CONST, {.dbl = 1 }, INT_MIN, INT_MAX, AACENC_FLAGS, "stereo_mode"},
{NULL}
};
@@ -674,13 +701,13 @@ static const AVClass aacenc_class = {
};
AVCodec ff_aac_encoder = {
- "aac",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_AAC,
- sizeof(AACEncContext),
- aac_encode_init,
- aac_encode_frame,
- aac_encode_end,
+ .name = "aac",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_AAC,
+ .priv_data_size = sizeof(AACEncContext),
+ .init = aac_encode_init,
+ .encode = aac_encode_frame,
+ .close = aac_encode_end,
.capabilities = CODEC_CAP_SMALL_LAST_FRAME | CODEC_CAP_DELAY | CODEC_CAP_EXPERIMENTAL,
.sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
.long_name = NULL_IF_CONFIG_SMALL("Advanced Audio Coding"),
diff --git a/libavcodec/aacenc.h b/libavcodec/aacenc.h
index acd185a809..150c651665 100644
--- a/libavcodec/aacenc.h
+++ b/libavcodec/aacenc.h
@@ -2,20 +2,20 @@
* AAC encoder
* Copyright (C) 2008 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/aacps.c b/libavcodec/aacps.c
index d818790a6f..6ef8347ee5 100644
--- a/libavcodec/aacps.c
+++ b/libavcodec/aacps.c
@@ -2,20 +2,20 @@
* MPEG-4 Parametric Stereo decoding functions
* Copyright (c) 2010 Alex Converse <alex.converse@gmail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -28,9 +28,9 @@
#include "aacps_tablegen.h"
#include "aacpsdata.c"
-#define PS_BASELINE 0 //< Operate in Baseline PS mode
- //< Baseline implies 10 or 20 stereo bands,
- //< mixing mode A, and no ipd/opd
+#define PS_BASELINE 0 ///< Operate in Baseline PS mode
+ ///< Baseline implies 10 or 20 stereo bands,
+ ///< mixing mode A, and no ipd/opd
#define numQMFSlots 32 //numTimeSlots * RATE
@@ -69,19 +69,19 @@ static const int huff_iid[] = {
static VLC vlc_ps[10];
-/**
- * Read Inter-channel Intensity Difference/Inter-Channel Coherence/
- * Inter-channel Phase Difference/Overall Phase Difference parameters from the
- * bitstream.
- *
- * @param avctx contains the current codec context
- * @param gb pointer to the input bitstream
- * @param ps pointer to the Parametric Stereo context
- * @param PAR pointer to the parameter to be read
- * @param e envelope to decode
- * @param dt 1: time delta-coded, 0: frequency delta-coded
- */
#define READ_PAR_DATA(PAR, OFFSET, MASK, ERR_CONDITION) \
+/** \
+ * Read Inter-channel Intensity Difference/Inter-Channel Coherence/ \
+ * Inter-channel Phase Difference/Overall Phase Difference parameters from the \
+ * bitstream. \
+ * \
+ * @param avctx contains the current codec context \
+ * @param gb pointer to the input bitstream \
+ * @param ps pointer to the Parametric Stereo context \
+ * @param PAR pointer to the parameter to be read \
+ * @param e envelope to decode \
+ * @param dt 1: time delta-coded, 0: frequency delta-coded \
+ */ \
static int read_ ## PAR ## _data(AVCodecContext *avctx, GetBitContext *gb, PSContext *ps, \
int8_t (*PAR)[PS_MAX_NR_IIDICC], int table_idx, int e, int dt) \
{ \
@@ -654,7 +654,7 @@ static void decorrelation(PSContext *ps, float (*out)[32][2], const float (*s)[3
const int8_t *k_to_i = is34 ? k_to_i_34 : k_to_i_20;
const float peak_decay_factor = 0.76592833836465f;
const float transient_impact = 1.5f;
- const float a_smooth = 0.25f; //< Smoothing coefficient
+ const float a_smooth = 0.25f; ///< Smoothing coefficient
int i, k, m, n;
int n0 = 0, nL = 32;
static const int link_delay[] = { 3, 4, 5 };
@@ -813,14 +813,17 @@ static void stereo_processing(PSContext *ps, float (*l)[32][2], float (*r)[32][2
const float (*H_LUT)[8][4] = (PS_BASELINE || ps->icc_mode < 3) ? HA : HB;
//Remapping
- memcpy(H11[0][0], H11[0][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H11[0][0][0]));
- memcpy(H11[1][0], H11[1][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H11[1][0][0]));
- memcpy(H12[0][0], H12[0][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H12[0][0][0]));
- memcpy(H12[1][0], H12[1][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H12[1][0][0]));
- memcpy(H21[0][0], H21[0][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H21[0][0][0]));
- memcpy(H21[1][0], H21[1][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H21[1][0][0]));
- memcpy(H22[0][0], H22[0][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H22[0][0][0]));
- memcpy(H22[1][0], H22[1][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H22[1][0][0]));
+ if (ps->num_env_old) {
+ memcpy(H11[0][0], H11[0][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H11[0][0][0]));
+ memcpy(H11[1][0], H11[1][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H11[1][0][0]));
+ memcpy(H12[0][0], H12[0][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H12[0][0][0]));
+ memcpy(H12[1][0], H12[1][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H12[1][0][0]));
+ memcpy(H21[0][0], H21[0][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H21[0][0][0]));
+ memcpy(H21[1][0], H21[1][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H21[1][0][0]));
+ memcpy(H22[0][0], H22[0][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H22[0][0][0]));
+ memcpy(H22[1][0], H22[1][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H22[1][0][0]));
+ }
+
if (is34) {
remap34(&iid_mapped, ps->iid_par, ps->nr_iid_par, ps->num_env, 1);
remap34(&icc_mapped, ps->icc_par, ps->nr_icc_par, ps->num_env, 1);
diff --git a/libavcodec/aacps.h b/libavcodec/aacps.h
index 59a9bff4bc..757a44366b 100644
--- a/libavcodec/aacps.h
+++ b/libavcodec/aacps.h
@@ -2,20 +2,20 @@
* MPEG-4 Parametric Stereo definitions and declarations
* Copyright (c) 2010 Alex Converse <alex.converse@gmail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -52,11 +52,11 @@ typedef struct {
int num_env;
int enable_ipdopd;
int border_position[PS_MAX_NUM_ENV+1];
- int8_t iid_par[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC]; //<Inter-channel Intensity Difference Parameters
- int8_t icc_par[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC]; //<Inter-Channel Coherence Parameters
+ int8_t iid_par[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC]; ///< Inter-channel Intensity Difference Parameters
+ int8_t icc_par[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC]; ///< Inter-Channel Coherence Parameters
/* ipd/opd is iid/icc sized so that the same functions can handle both */
- int8_t ipd_par[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC]; //<Inter-channel Phase Difference Parameters
- int8_t opd_par[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC]; //<Overall Phase Difference Parameters
+ int8_t ipd_par[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC]; ///< Inter-channel Phase Difference Parameters
+ int8_t opd_par[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC]; ///< Overall Phase Difference Parameters
int is34bands;
int is34bands_old;
diff --git a/libavcodec/aacps_tablegen.c b/libavcodec/aacps_tablegen.c
index 8650226d71..dc7797f6b8 100644
--- a/libavcodec/aacps_tablegen.c
+++ b/libavcodec/aacps_tablegen.c
@@ -3,20 +3,20 @@
*
* Copyright (c) 2010 Alex Converse <alex.converse@gmail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/aacps_tablegen.h b/libavcodec/aacps_tablegen.h
index 492cb0c56d..79ae644a87 100644
--- a/libavcodec/aacps_tablegen.h
+++ b/libavcodec/aacps_tablegen.h
@@ -3,20 +3,20 @@
*
* Copyright (c) 2010 Alex Converse <alex.converse@gmail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -139,7 +139,7 @@ static void ps_tableinit(void)
}
for (iid = 0; iid < 46; iid++) {
- float c = iid_par_dequant[iid]; //<Linear Inter-channel Intensity Difference
+ float c = iid_par_dequant[iid]; ///< Linear Inter-channel Intensity Difference
float c1 = (float)M_SQRT2 / sqrtf(1.0f + c*c);
float c2 = c * c1;
for (icc = 0; icc < 8; icc++) {
diff --git a/libavcodec/aacpsdata.c b/libavcodec/aacpsdata.c
index 675bd8e2b3..7431caebc6 100644
--- a/libavcodec/aacpsdata.c
+++ b/libavcodec/aacpsdata.c
@@ -2,20 +2,20 @@
* MPEG-4 Parametric Stereo data tables
* Copyright (c) 2010 Alex Converse <alex.converse@gmail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/aacpsy.c b/libavcodec/aacpsy.c
index 93ff934b2a..4152b70bbf 100644
--- a/libavcodec/aacpsy.c
+++ b/libavcodec/aacpsy.c
@@ -2,20 +2,20 @@
* AAC encoder psychoacoustic model
* Copyright (C) 2008 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/aacpsy.h b/libavcodec/aacpsy.h
index 5d1e14220c..05c93cddeb 100644
--- a/libavcodec/aacpsy.h
+++ b/libavcodec/aacpsy.h
@@ -2,20 +2,20 @@
* AAC encoder psychoacoustic model
* Copyright (C) 2008 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/aacsbr.c b/libavcodec/aacsbr.c
index 81b0b4c001..a213827132 100644
--- a/libavcodec/aacsbr.c
+++ b/libavcodec/aacsbr.c
@@ -3,20 +3,20 @@
* Copyright (c) 2008-2009 Robert Swain ( rob opendot cl )
* Copyright (c) 2009-2010 Alex Converse <alex.converse@gmail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -33,9 +33,11 @@
#include "fft.h"
#include "aacps.h"
#include "libavutil/libm.h"
+#include "libavutil/avassert.h"
#include <stdint.h>
#include <float.h>
+#include <math.h>
#define ENVELOPE_ADJUSTMENT_OFFSET 2
#define NOISE_FLOOR_OFFSET 6.0f
@@ -129,6 +131,8 @@ av_cold void ff_aac_sbr_init(void)
av_cold void ff_aac_sbr_ctx_init(AACContext *ac, SpectralBandReplication *sbr)
{
float mdct_scale;
+ if(sbr->mdct.mdct_bits)
+ return;
sbr->kx[0] = sbr->kx[1] = 32; //Typo in spec, kx' inits to 32
sbr->data[0].e_a[1] = sbr->data[1].e_a[1] = -1;
sbr->data[0].synthesis_filterbank_samples_offset = SBR_SYNTHESIS_BUF_SIZE - (1280 - 128);
@@ -1456,6 +1460,7 @@ static void sbr_mapping(AACContext *ac, SpectralBandReplication *sbr,
uint16_t *table = ch_data->bs_freq_res[e + 1] ? sbr->f_tablehigh : sbr->f_tablelow;
int k;
+ av_assert0(sbr->kx[1] <= table[0]);
for (i = 0; i < ilim; i++)
for (m = table[i]; m < table[i + 1]; m++)
sbr->e_origmapped[e][m - sbr->kx[1]] = ch_data->env_facs[e+1][i];
diff --git a/libavcodec/aacsbr.h b/libavcodec/aacsbr.h
index 153070d3f2..d0284981c3 100644
--- a/libavcodec/aacsbr.h
+++ b/libavcodec/aacsbr.h
@@ -3,20 +3,20 @@
* Copyright (c) 2008-2009 Robert Swain ( rob opendot cl )
* Copyright (c) 2010 Alex Converse <alex.converse@gmail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/aacsbrdata.h b/libavcodec/aacsbrdata.h
index 44d578f7fc..5d33a60888 100644
--- a/libavcodec/aacsbrdata.h
+++ b/libavcodec/aacsbrdata.h
@@ -2,20 +2,20 @@
* AAC Spectral Band Replication decoding data
* Copyright (c) 2008-2009 Robert Swain ( rob opendot cl )
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/aactab.c b/libavcodec/aactab.c
index 46886b12df..17102a66f5 100644
--- a/libavcodec/aactab.c
+++ b/libavcodec/aactab.c
@@ -3,20 +3,20 @@
* Copyright (c) 2005-2006 Oded Shimon ( ods15 ods15 dyndns org )
* Copyright (c) 2006-2007 Maxim Gavrilov ( maxim.gavrilov gmail com )
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/aactab.h b/libavcodec/aactab.h
index c76d65db95..c6213999b5 100644
--- a/libavcodec/aactab.h
+++ b/libavcodec/aactab.h
@@ -3,20 +3,20 @@
* Copyright (c) 2005-2006 Oded Shimon ( ods15 ods15 dyndns org )
* Copyright (c) 2006-2007 Maxim Gavrilov ( maxim.gavrilov gmail com )
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/aandcttab.c b/libavcodec/aandcttab.c
index 0c5b573412..87c50b37cf 100644
--- a/libavcodec/aandcttab.c
+++ b/libavcodec/aandcttab.c
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/aandcttab.h b/libavcodec/aandcttab.h
index daccb7bb0b..d774828a4d 100644
--- a/libavcodec/aandcttab.h
+++ b/libavcodec/aandcttab.h
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/aasc.c b/libavcodec/aasc.c
index e80e0945a1..f0407bc94b 100644
--- a/libavcodec/aasc.c
+++ b/libavcodec/aasc.c
@@ -2,20 +2,20 @@
* Autodesk RLE Decoder
* Copyright (C) 2005 the ffmpeg project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -50,8 +50,8 @@ static av_cold int aasc_decode_init(AVCodecContext *avctx)
AascContext *s = avctx->priv_data;
s->avctx = avctx;
-
avctx->pix_fmt = PIX_FMT_BGR24;
+ avcodec_get_frame_defaults(&s->frame);
return 0;
}
@@ -110,14 +110,13 @@ static av_cold int aasc_decode_end(AVCodecContext *avctx)
}
AVCodec ff_aasc_decoder = {
- "aasc",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_AASC,
- sizeof(AascContext),
- aasc_decode_init,
- NULL,
- aasc_decode_end,
- aasc_decode_frame,
- CODEC_CAP_DR1,
+ .name = "aasc",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_AASC,
+ .priv_data_size = sizeof(AascContext),
+ .init = aasc_decode_init,
+ .close = aasc_decode_end,
+ .decode = aasc_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Autodesk RLE"),
};
diff --git a/libavcodec/ac3.c b/libavcodec/ac3.c
index 99e5b50acb..29e132f5d1 100644
--- a/libavcodec/ac3.c
+++ b/libavcodec/ac3.c
@@ -2,20 +2,20 @@
* Common code between the AC-3 encoder and decoder
* Copyright (c) 2000 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/ac3.h b/libavcodec/ac3.h
index 9adad93db8..d53527844c 100644
--- a/libavcodec/ac3.h
+++ b/libavcodec/ac3.h
@@ -2,20 +2,20 @@
* Common code between the AC-3 encoder and decoder
* Copyright (c) 2000, 2001, 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -39,6 +39,8 @@
#define AC3_CRITICAL_BANDS 50
#define AC3_MAX_CPL_BANDS 18
+#include "libavutil/opt.h"
+#include "avcodec.h"
#include "ac3tab.h"
/* exponent encoding strategy */
diff --git a/libavcodec/ac3_parser.c b/libavcodec/ac3_parser.c
index 82eeda3e61..3d2fdb5ecf 100644
--- a/libavcodec/ac3_parser.c
+++ b/libavcodec/ac3_parser.c
@@ -3,20 +3,20 @@
* Copyright (c) 2003 Fabrice Bellard
* Copyright (c) 2003 Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -35,7 +35,7 @@ static const uint8_t eac3_blocks[4] = {
};
-int ff_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr)
+int avpriv_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr)
{
int frame_size_code;
@@ -141,7 +141,7 @@ static int ac3_sync(uint64_t state, AACAC3ParseContext *hdr_info,
GetBitContext gbc;
init_get_bits(&gbc, tmp.u8+8-AC3_HEADER_SIZE, 54);
- err = ff_ac3_parse_header(&gbc, &hdr);
+ err = avpriv_ac3_parse_header(&gbc, &hdr);
if(err < 0)
return 0;
diff --git a/libavcodec/ac3_parser.h b/libavcodec/ac3_parser.h
index d62490bc77..b5022de2d8 100644
--- a/libavcodec/ac3_parser.h
+++ b/libavcodec/ac3_parser.h
@@ -3,20 +3,20 @@
* Copyright (c) 2003 Fabrice Bellard
* Copyright (c) 2003 Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -36,6 +36,6 @@
* -2 if the bsid (version) element is invalid, -3 if the fscod (sample rate)
* element is invalid, or -4 if the frmsizecod (bit rate) element is invalid.
*/
-int ff_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr);
+int avpriv_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr);
#endif /* AVCODEC_AC3_PARSER_H */
diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c
index 42b62ef701..84a469193e 100644
--- a/libavcodec/ac3dec.c
+++ b/libavcodec/ac3dec.c
@@ -7,20 +7,20 @@
* Copyright (c) 2007-2008 Bartlomiej Wolowiec <bartek.wolowiec@gmail.com>
* Copyright (c) 2007 Justin Ruggles <justin.ruggles@gmail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -30,6 +30,7 @@
#include <string.h>
#include "libavutil/crc.h"
+#include "libavutil/opt.h"
#include "internal.h"
#include "aac_ac3_parser.h"
#include "ac3_parser.h"
@@ -37,9 +38,6 @@
#include "ac3dec_data.h"
#include "kbdwin.h"
-/** Large enough for maximum possible frame size when the specification limit is ignored */
-#define AC3_FRAME_BUFFER_SIZE 32768
-
/**
* table for ungrouping 3 values in 7 bits.
* used for exponents and bap=2 mantissas
@@ -178,6 +176,11 @@ static av_cold int ac3_decode_init(AVCodecContext *avctx)
AC3DecodeContext *s = avctx->priv_data;
s->avctx = avctx;
+#if FF_API_DRC_SCALE
+ if (avctx->drc_scale)
+ s->drc_scale = avctx->drc_scale;
+#endif
+
ff_ac3_common_init();
ac3_tables_init();
ff_mdct_init(&s->imdct_256, 8, 1, 1.0);
@@ -205,11 +208,6 @@ static av_cold int ac3_decode_init(AVCodecContext *avctx)
}
s->downmixed = 1;
- /* allocate context input buffer */
- s->input_buffer = av_mallocz(AC3_FRAME_BUFFER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);
- if (!s->input_buffer)
- return AVERROR(ENOMEM);
-
return 0;
}
@@ -263,7 +261,7 @@ static int parse_frame_header(AC3DecodeContext *s)
AC3HeaderInfo hdr;
int err;
- err = ff_ac3_parse_header(&s->gbc, &hdr);
+ err = avpriv_ac3_parse_header(&s->gbc, &hdr);
if(err)
return err;
@@ -507,9 +505,9 @@ static void ac3_decode_transform_coeffs_ch(AC3DecodeContext *s, int ch_index, ma
mantissa = b5_mantissas[get_bits(gbc, 4)];
break;
default: /* 6 to 15 */
- mantissa = get_bits(gbc, quantization_tab[bap]);
/* Shift mantissa and sign-extend it. */
- mantissa = (mantissa << (32-quantization_tab[bap]))>>8;
+ mantissa = get_sbits(gbc, quantization_tab[bap]);
+ mantissa <<= 24 - quantization_tab[bap];
break;
}
coeffs[freq] = mantissa >> exps[freq];
@@ -795,7 +793,7 @@ static int decode_audio_block(AC3DecodeContext *s, int blk)
do {
if(get_bits1(gbc)) {
s->dynamic_range[i] = ((dynamic_range_tab[get_bits(gbc, 8)]-1.0) *
- s->avctx->drc_scale)+1.0;
+ s->drc_scale)+1.0;
} else if(blk == 0) {
s->dynamic_range[i] = 1.0f;
}
@@ -1307,6 +1305,7 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data, int *data_size,
float *out_samples_flt = data;
int16_t *out_samples_s16 = data;
int blk, ch, err;
+ int data_size_orig, data_size_tmp;
const uint8_t *channel_map;
const float *output[AC3_MAX_CHANNELS];
@@ -1323,6 +1322,7 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data, int *data_size,
init_get_bits(&s->gbc, buf, buf_size * 8);
/* parse the syncinfo */
+ data_size_orig = *data_size;
*data_size = 0;
err = parse_frame_header(s);
@@ -1387,6 +1387,10 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data, int *data_size,
avctx->channels = s->out_channels;
avctx->channel_layout = s->channel_layout;
+ s->loro_center_mix_level = gain_levels[ center_levels[s-> center_mix_level]];
+ s->loro_surround_mix_level = gain_levels[surround_levels[s->surround_mix_level]];
+ s->ltrt_center_mix_level = LEVEL_MINUS_3DB;
+ s->ltrt_surround_mix_level = LEVEL_MINUS_3DB;
/* set downmixing coefficients if needed */
if(s->channels != s->out_channels && !((s->output_mode & AC3_OUTPUT_LFEON) &&
s->fbw_channels == s->out_channels)) {
@@ -1406,11 +1410,17 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data, int *data_size,
channel_map = ff_ac3_dec_channel_map[s->output_mode & ~AC3_OUTPUT_LFEON][s->lfe_on];
for (ch = 0; ch < s->out_channels; ch++)
output[ch] = s->output[channel_map[ch]];
+ data_size_tmp = s->num_blocks * 256 * avctx->channels;
+ data_size_tmp *= avctx->sample_fmt == AV_SAMPLE_FMT_FLT ? sizeof(*out_samples_flt) : sizeof(*out_samples_s16);
+ if (data_size_orig < data_size_tmp)
+ return -1;
+ *data_size = data_size_tmp;
for (blk = 0; blk < s->num_blocks; blk++) {
if (!err && decode_audio_block(s, blk)) {
av_log(avctx, AV_LOG_ERROR, "error decoding the audio block\n");
err = 1;
}
+
if (avctx->sample_fmt == AV_SAMPLE_FMT_FLT) {
s->fmt_conv.float_interleave(out_samples_flt, output, 256,
s->out_channels);
@@ -1435,11 +1445,30 @@ static av_cold int ac3_decode_end(AVCodecContext *avctx)
ff_mdct_end(&s->imdct_512);
ff_mdct_end(&s->imdct_256);
- av_freep(&s->input_buffer);
-
return 0;
}
+#define OFFSET(x) offsetof(AC3DecodeContext, x)
+#define PAR (AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM)
+static const AVOption options[] = {
+ { "drc_scale", "percentage of dynamic range compression to apply", OFFSET(drc_scale), AV_OPT_TYPE_FLOAT, {1.0}, 0.0, 1.0, PAR },
+
+{"dmix_mode", "Preferred Stereo Downmix Mode", OFFSET(preferred_stereo_downmix), AV_OPT_TYPE_INT, {.dbl = -1 }, -1, 2, 0, "dmix_mode"},
+{"ltrt_cmixlev", "Lt/Rt Center Mix Level", OFFSET(ltrt_center_mix_level), AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, 0},
+{"ltrt_surmixlev", "Lt/Rt Surround Mix Level", OFFSET(ltrt_surround_mix_level), AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, 0},
+{"loro_cmixlev", "Lo/Ro Center Mix Level", OFFSET(loro_center_mix_level), AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, 0},
+{"loro_surmixlev", "Lo/Ro Surround Mix Level", OFFSET(loro_surround_mix_level), AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, 0},
+
+ { NULL},
+};
+
+static const AVClass ac3_decoder_class = {
+ .class_name = "AC3 decoder",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
AVCodec ff_ac3_decoder = {
.name = "ac3",
.type = AVMEDIA_TYPE_AUDIO,
@@ -1452,9 +1481,16 @@ AVCodec ff_ac3_decoder = {
.sample_fmts = (const enum AVSampleFormat[]) {
AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE
},
+ .priv_class = &ac3_decoder_class,
};
#if CONFIG_EAC3_DECODER
+static const AVClass eac3_decoder_class = {
+ .class_name = "E-AC3 decoder",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
AVCodec ff_eac3_decoder = {
.name = "eac3",
.type = AVMEDIA_TYPE_AUDIO,
@@ -1467,5 +1503,6 @@ AVCodec ff_eac3_decoder = {
.sample_fmts = (const enum AVSampleFormat[]) {
AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE
},
+ .priv_class = &eac3_decoder_class,
};
#endif
diff --git a/libavcodec/ac3dec.h b/libavcodec/ac3dec.h
index aed87432f5..aa346cb020 100644
--- a/libavcodec/ac3dec.h
+++ b/libavcodec/ac3dec.h
@@ -2,20 +2,20 @@
* Common code between the AC-3 and E-AC-3 decoders
* Copyright (c) 2007 Bartlomiej Wolowiec <bartek.wolowiec@gmail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -62,10 +62,13 @@
#define SPX_MAX_BANDS 17
+/** Large enough for maximum possible frame size when the specification limit is ignored */
+#define AC3_FRAME_BUFFER_SIZE 32768
+
typedef struct {
+ AVClass *class; ///< class for AVOptions
AVCodecContext *avctx; ///< parent context
GetBitContext gbc; ///< bitstream reader
- uint8_t *input_buffer; ///< temp buffer to prevent overread
///@name Bit stream information
///@{
@@ -85,6 +88,12 @@ typedef struct {
int eac3; ///< indicates if current frame is E-AC-3
///@}
+ int preferred_stereo_downmix;
+ float ltrt_center_mix_level;
+ float ltrt_surround_mix_level;
+ float loro_center_mix_level;
+ float loro_surround_mix_level;
+
///@name Frame syntax parameters
int snr_offset_strategy; ///< SNR offset strategy (snroffststr)
int block_switch_syntax; ///< block switch syntax enabled (blkswe)
@@ -141,6 +150,7 @@ typedef struct {
///@name Dynamic range
float dynamic_range[2]; ///< dynamic range
+ float drc_scale; ///< percentage of dynamic range compression to be applied
///@}
///@name Bandwidth
@@ -200,6 +210,7 @@ typedef struct {
DECLARE_ALIGNED(32, float, window)[AC3_BLOCK_SIZE]; ///< window coefficients
DECLARE_ALIGNED(32, float, tmp_output)[AC3_BLOCK_SIZE]; ///< temporary storage for output before windowing
DECLARE_ALIGNED(32, float, output)[AC3_MAX_CHANNELS][AC3_BLOCK_SIZE]; ///< output after imdct transform and windowing
+ DECLARE_ALIGNED(32, uint8_t, input_buffer)[AC3_FRAME_BUFFER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE]; ///< temp buffer to prevent overread
///@}
} AC3DecodeContext;
diff --git a/libavcodec/ac3dec_data.c b/libavcodec/ac3dec_data.c
index 272a963f08..d0a9b1ec40 100644
--- a/libavcodec/ac3dec_data.c
+++ b/libavcodec/ac3dec_data.c
@@ -2,20 +2,20 @@
* AC-3 and E-AC-3 decoder tables
* Copyright (c) 2007 Bartlomiej Wolowiec <bartek.wolowiec@gmail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/ac3dec_data.h b/libavcodec/ac3dec_data.h
index c0a584e7b3..975b52ef2c 100644
--- a/libavcodec/ac3dec_data.h
+++ b/libavcodec/ac3dec_data.h
@@ -2,20 +2,20 @@
* AC-3 and E-AC-3 decoder tables
* Copyright (c) 2007 Bartlomiej Wolowiec <bartek.wolowiec@gmail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/ac3dsp.c b/libavcodec/ac3dsp.c
index 69beab64ca..a414db4107 100644
--- a/libavcodec/ac3dsp.c
+++ b/libavcodec/ac3dsp.c
@@ -2,20 +2,20 @@
* AC-3 DSP utils
* Copyright (c) 2011 Justin Ruggles
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/ac3dsp.h b/libavcodec/ac3dsp.h
index 621841e384..f0a6999ecb 100644
--- a/libavcodec/ac3dsp.h
+++ b/libavcodec/ac3dsp.h
@@ -2,20 +2,20 @@
* AC-3 DSP utils
* Copyright (c) 2011 Justin Ruggles
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index 668cebe400..48cafd2e81 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -4,20 +4,20 @@
* Copyright (c) 2006-2010 Justin Ruggles <justin.ruggles@gmail.com>
* Copyright (c) 2006-2010 Prakash Punnoor <prakash@punnoor.de>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -186,7 +186,7 @@ void ff_ac3_adjust_frame_size(AC3EncodeContext *s)
s->frame_size = s->frame_size_min +
2 * (s->bits_written * s->sample_rate < s->samples_written * s->bit_rate);
s->bits_written += s->frame_size * 8;
- s->samples_written += AC3_FRAME_SIZE;
+ s->samples_written += AC3_BLOCK_SIZE * s->num_blocks;
}
@@ -194,10 +194,11 @@ void ff_ac3_compute_coupling_strategy(AC3EncodeContext *s)
{
int blk, ch;
int got_cpl_snr;
+ int num_cpl_blocks;
/* set coupling use flags for each block/channel */
/* TODO: turn coupling on/off and adjust start band based on bit usage */
- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
+ for (blk = 0; blk < s->num_blocks; blk++) {
AC3Block *block = &s->blocks[blk];
for (ch = 1; ch <= s->fbw_channels; ch++)
block->channel_in_cpl[ch] = s->cpl_on;
@@ -206,12 +207,14 @@ void ff_ac3_compute_coupling_strategy(AC3EncodeContext *s)
/* enable coupling for each block if at least 2 channels have coupling
enabled for that block */
got_cpl_snr = 0;
- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
+ num_cpl_blocks = 0;
+ for (blk = 0; blk < s->num_blocks; blk++) {
AC3Block *block = &s->blocks[blk];
block->num_cpl_channels = 0;
for (ch = 1; ch <= s->fbw_channels; ch++)
block->num_cpl_channels += block->channel_in_cpl[ch];
block->cpl_in_use = block->num_cpl_channels > 1;
+ num_cpl_blocks += block->cpl_in_use;
if (!block->cpl_in_use) {
block->num_cpl_channels = 0;
for (ch = 1; ch <= s->fbw_channels; ch++)
@@ -237,9 +240,11 @@ void ff_ac3_compute_coupling_strategy(AC3EncodeContext *s)
block->new_snr_offsets = 0;
}
}
+ if (!num_cpl_blocks)
+ s->cpl_on = 0;
/* set bandwidth for each channel */
- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
+ for (blk = 0; blk < s->num_blocks; blk++) {
AC3Block *block = &s->blocks[blk];
for (ch = 1; ch <= s->fbw_channels; ch++) {
if (block->channel_in_cpl[ch])
@@ -264,7 +269,7 @@ void ff_ac3_apply_rematrixing(AC3EncodeContext *s)
if (!s->rematrixing_enabled)
return;
- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
+ for (blk = 0; blk < s->num_blocks; blk++) {
AC3Block *block = &s->blocks[blk];
if (block->new_rematrixing_strategy)
flags = block->rematrixing_flags;
@@ -301,6 +306,9 @@ static av_cold void exponent_init(AC3EncodeContext *s)
}
/* LFE */
exponent_group_tab[0][0][7] = 2;
+
+ if (CONFIG_EAC3_ENCODER && s->eac3)
+ ff_eac3_exponent_init();
}
@@ -310,7 +318,7 @@ static av_cold void exponent_init(AC3EncodeContext *s)
static void extract_exponents(AC3EncodeContext *s)
{
int ch = !s->cpl_on;
- int chan_size = AC3_MAX_COEFS * AC3_MAX_BLOCKS * (s->channels - ch + 1);
+ int chan_size = AC3_MAX_COEFS * s->num_blocks * (s->channels - ch + 1);
AC3Block *block = &s->blocks[0];
s->ac3dsp.extract_exponents(block->exp[ch], block->fixed_coef[ch], chan_size);
@@ -323,6 +331,15 @@ static void extract_exponents(AC3EncodeContext *s)
*/
#define EXP_DIFF_THRESHOLD 500
+/**
+ * Table used to select exponent strategy based on exponent reuse block interval.
+ */
+static const uint8_t exp_strategy_reuse_tab[4][6] = {
+ { EXP_D15, EXP_D15, EXP_D15, EXP_D15, EXP_D15, EXP_D15 },
+ { EXP_D15, EXP_D15, EXP_D15, EXP_D15, EXP_D15, EXP_D15 },
+ { EXP_D25, EXP_D25, EXP_D15, EXP_D15, EXP_D15, EXP_D15 },
+ { EXP_D45, EXP_D25, EXP_D25, EXP_D15, EXP_D15, EXP_D15 }
+};
/**
* Calculate exponent strategies for all channels.
@@ -341,9 +358,16 @@ static void compute_exp_strategy(AC3EncodeContext *s)
reused in the next frame */
exp_strategy[0] = EXP_NEW;
exp += AC3_MAX_COEFS;
- for (blk = 1; blk < AC3_MAX_BLOCKS; blk++, exp += AC3_MAX_COEFS) {
- if ((ch == CPL_CH && (!s->blocks[blk].cpl_in_use || !s->blocks[blk-1].cpl_in_use)) ||
- (ch > CPL_CH && (s->blocks[blk].channel_in_cpl[ch] != s->blocks[blk-1].channel_in_cpl[ch]))) {
+ for (blk = 1; blk < s->num_blocks; blk++, exp += AC3_MAX_COEFS) {
+ if (ch == CPL_CH) {
+ if (!s->blocks[blk-1].cpl_in_use) {
+ exp_strategy[blk] = EXP_NEW;
+ continue;
+ } else if (!s->blocks[blk].cpl_in_use) {
+ exp_strategy[blk] = EXP_REUSE;
+ continue;
+ }
+ } else if (s->blocks[blk].channel_in_cpl[ch] != s->blocks[blk-1].channel_in_cpl[ch]) {
exp_strategy[blk] = EXP_NEW;
continue;
}
@@ -358,25 +382,24 @@ static void compute_exp_strategy(AC3EncodeContext *s)
/* now select the encoding strategy type : if exponents are often
recoded, we use a coarse encoding */
blk = 0;
- while (blk < AC3_MAX_BLOCKS) {
+ while (blk < s->num_blocks) {
blk1 = blk + 1;
- while (blk1 < AC3_MAX_BLOCKS && exp_strategy[blk1] == EXP_REUSE)
+ while (blk1 < s->num_blocks && exp_strategy[blk1] == EXP_REUSE)
blk1++;
- switch (blk1 - blk) {
- case 1: exp_strategy[blk] = EXP_D45; break;
- case 2:
- case 3: exp_strategy[blk] = EXP_D25; break;
- default: exp_strategy[blk] = EXP_D15; break;
- }
+ exp_strategy[blk] = exp_strategy_reuse_tab[s->num_blks_code][blk1-blk-1];
blk = blk1;
}
}
if (s->lfe_on) {
ch = s->lfe_channel;
s->exp_strategy[ch][0] = EXP_D15;
- for (blk = 1; blk < AC3_MAX_BLOCKS; blk++)
+ for (blk = 1; blk < s->num_blocks; blk++)
s->exp_strategy[ch][blk] = EXP_REUSE;
}
+
+ /* for E-AC-3, determine frame exponent strategy */
+ if (CONFIG_EAC3_ENCODER && s->eac3)
+ ff_eac3_get_frame_exp_strategy(s);
}
@@ -468,7 +491,7 @@ static void encode_exponents(AC3EncodeContext *s)
cpl = (ch == CPL_CH);
blk = 0;
- while (blk < AC3_MAX_BLOCKS) {
+ while (blk < s->num_blocks) {
AC3Block *block = &s->blocks[blk];
if (cpl && !block->cpl_in_use) {
exp += AC3_MAX_COEFS;
@@ -481,7 +504,7 @@ static void encode_exponents(AC3EncodeContext *s)
/* count the number of EXP_REUSE blocks after the current block
and set exponent reference block numbers */
s->exp_ref_block[ch][blk] = blk;
- while (blk1 < AC3_MAX_BLOCKS && exp_strategy[blk1] == EXP_REUSE) {
+ while (blk1 < s->num_blocks && exp_strategy[blk1] == EXP_REUSE) {
s->exp_ref_block[ch][blk1] = blk;
blk1++;
}
@@ -504,20 +527,47 @@ static void encode_exponents(AC3EncodeContext *s)
/**
+ * Count exponent bits based on bandwidth, coupling, and exponent strategies.
+ */
+static int count_exponent_bits(AC3EncodeContext *s)
+{
+ int blk, ch;
+ int nb_groups, bit_count;
+
+ bit_count = 0;
+ for (blk = 0; blk < s->num_blocks; blk++) {
+ AC3Block *block = &s->blocks[blk];
+ for (ch = !block->cpl_in_use; ch <= s->channels; ch++) {
+ int exp_strategy = s->exp_strategy[ch][blk];
+ int cpl = (ch == CPL_CH);
+ int nb_coefs = block->end_freq[ch] - s->start_freq[ch];
+
+ if (exp_strategy == EXP_REUSE)
+ continue;
+
+ nb_groups = exponent_group_tab[cpl][exp_strategy-1][nb_coefs];
+ bit_count += 4 + (nb_groups * 7);
+ }
+ }
+
+ return bit_count;
+}
+
+
+/**
* Group exponents.
* 3 delta-encoded exponents are in each 7-bit group. The number of groups
* varies depending on exponent strategy and bandwidth.
*/
-static void group_exponents(AC3EncodeContext *s)
+void ff_ac3_group_exponents(AC3EncodeContext *s)
{
int blk, ch, i, cpl;
- int group_size, nb_groups, bit_count;
+ int group_size, nb_groups;
uint8_t *p;
int delta0, delta1, delta2;
int exp0, exp1;
- bit_count = 0;
- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
+ for (blk = 0; blk < s->num_blocks; blk++) {
AC3Block *block = &s->blocks[blk];
for (ch = !block->cpl_in_use; ch <= s->channels; ch++) {
int exp_strategy = s->exp_strategy[ch][blk];
@@ -526,7 +576,6 @@ static void group_exponents(AC3EncodeContext *s)
cpl = (ch == CPL_CH);
group_size = exp_strategy + (exp_strategy == EXP_D45);
nb_groups = exponent_group_tab[cpl][exp_strategy-1][block->end_freq[ch]-s->start_freq[ch]];
- bit_count += 4 + (nb_groups * 7);
p = block->exp[ch] + s->start_freq[ch] - cpl;
/* DC exponent */
@@ -558,8 +607,6 @@ static void group_exponents(AC3EncodeContext *s)
}
}
}
-
- s->exponent_bits = bit_count;
}
@@ -576,8 +623,6 @@ void ff_ac3_process_exponents(AC3EncodeContext *s)
encode_exponents(s);
- group_exponents(s);
-
emms_c();
}
@@ -606,26 +651,38 @@ static void count_frame_bits_fixed(AC3EncodeContext *s)
if (s->eac3) {
/* bitstream info header */
frame_bits += 35;
- frame_bits += 1 + 1 + 1;
+ frame_bits += 1 + 1;
+ if (s->num_blocks != 0x6)
+ frame_bits++;
+ frame_bits++;
/* audio frame header */
- frame_bits += 2;
+ if (s->num_blocks == 6)
+ frame_bits += 2;
frame_bits += 10;
/* exponent strategy */
- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++)
- frame_bits += 2 * s->fbw_channels + s->lfe_on;
+ if (s->use_frame_exp_strategy)
+ frame_bits += 5 * s->fbw_channels;
+ else
+ frame_bits += s->num_blocks * 2 * s->fbw_channels;
+ if (s->lfe_on)
+ frame_bits += s->num_blocks;
/* converter exponent strategy */
- frame_bits += s->fbw_channels * 5;
+ if (s->num_blks_code != 0x3)
+ frame_bits++;
+ else
+ frame_bits += s->fbw_channels * 5;
/* snr offsets */
frame_bits += 10;
/* block start info */
- frame_bits++;
+ if (s->num_blocks != 1)
+ frame_bits++;
} else {
frame_bits += 49;
frame_bits += frame_bits_inc[s->channel_mode];
}
/* audio blocks */
- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
+ for (blk = 0; blk < s->num_blocks; blk++) {
if (!s->eac3) {
/* block switch flags */
frame_bits += s->fbw_channels;
@@ -724,10 +781,34 @@ static void count_frame_bits(AC3EncodeContext *s)
/* header */
if (s->eac3) {
+ if (opt->eac3_mixing_metadata) {
+ if (s->channel_mode > AC3_CHMODE_STEREO)
+ frame_bits += 2;
+ if (s->has_center)
+ frame_bits += 6;
+ if (s->has_surround)
+ frame_bits += 6;
+ frame_bits += s->lfe_on;
+ frame_bits += 1 + 1 + 2;
+ if (s->channel_mode < AC3_CHMODE_STEREO)
+ frame_bits++;
+ frame_bits++;
+ }
+ if (opt->eac3_info_metadata) {
+ frame_bits += 3 + 1 + 1;
+ if (s->channel_mode == AC3_CHMODE_STEREO)
+ frame_bits += 2 + 2;
+ if (s->channel_mode >= AC3_CHMODE_2F2R)
+ frame_bits += 2;
+ frame_bits++;
+ if (opt->audio_production_info)
+ frame_bits += 5 + 2 + 1;
+ frame_bits++;
+ }
/* coupling */
if (s->channel_mode > AC3_CHMODE_MONO) {
frame_bits++;
- for (blk = 1; blk < AC3_MAX_BLOCKS; blk++) {
+ for (blk = 1; blk < s->num_blocks; blk++) {
AC3Block *block = &s->blocks[blk];
frame_bits++;
if (block->new_cpl_strategy)
@@ -735,8 +816,14 @@ static void count_frame_bits(AC3EncodeContext *s)
}
}
/* coupling exponent strategy */
- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++)
- frame_bits += 2 * s->blocks[blk].cpl_in_use;
+ if (s->cpl_on) {
+ if (s->use_frame_exp_strategy) {
+ frame_bits += 5 * s->cpl_on;
+ } else {
+ for (blk = 0; blk < s->num_blocks; blk++)
+ frame_bits += 2 * s->blocks[blk].cpl_in_use;
+ }
+ }
} else {
if (opt->audio_production_info)
frame_bits += 7;
@@ -749,7 +836,7 @@ static void count_frame_bits(AC3EncodeContext *s)
}
/* audio blocks */
- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
+ for (blk = 0; blk < s->num_blocks; blk++) {
AC3Block *block = &s->blocks[blk];
/* coupling strategy */
@@ -777,9 +864,9 @@ static void count_frame_bits(AC3EncodeContext *s)
if (block->cpl_in_use) {
for (ch = 1; ch <= s->fbw_channels; ch++) {
if (block->channel_in_cpl[ch]) {
- if (!s->eac3 || block->new_cpl_coords != 2)
+ if (!s->eac3 || block->new_cpl_coords[ch] != 2)
frame_bits++;
- if (block->new_cpl_coords) {
+ if (block->new_cpl_coords[ch]) {
frame_bits += 2;
frame_bits += (4 + 4) * s->num_cpl_bands;
}
@@ -836,7 +923,7 @@ static void bit_alloc_masking(AC3EncodeContext *s)
{
int blk, ch;
- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
+ for (blk = 0; blk < s->num_blocks; blk++) {
AC3Block *block = &s->blocks[blk];
for (ch = !block->cpl_in_use; ch <= s->channels; ch++) {
/* We only need psd and mask for calculating bap.
@@ -872,9 +959,9 @@ static void reset_block_bap(AC3EncodeContext *s)
ref_bap = s->bap_buffer;
for (ch = 0; ch <= s->channels; ch++) {
- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++)
+ for (blk = 0; blk < s->num_blocks; blk++)
s->ref_bap[ch][blk] = ref_bap + AC3_MAX_COEFS * s->exp_ref_block[ch][blk];
- ref_bap += AC3_MAX_COEFS * AC3_MAX_BLOCKS;
+ ref_bap += AC3_MAX_COEFS * s->num_blocks;
}
s->ref_bap_set = 1;
}
@@ -907,7 +994,7 @@ static void count_mantissa_bits_update_ch(AC3EncodeContext *s, int ch,
{
int blk;
- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
+ for (blk = 0; blk < s->num_blocks; blk++) {
AC3Block *block = &s->blocks[blk];
if (ch == CPL_CH && !block->cpl_in_use)
continue;
@@ -951,7 +1038,7 @@ static int bit_alloc(AC3EncodeContext *s, int snr_offset)
snr_offset = (snr_offset - 240) << 2;
reset_block_bap(s);
- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
+ for (blk = 0; blk < s->num_blocks; blk++) {
AC3Block *block = &s->blocks[blk];
for (ch = !block->cpl_in_use; ch <= s->channels; ch++) {
@@ -1030,6 +1117,8 @@ int ff_ac3_compute_bit_allocation(AC3EncodeContext *s)
{
count_frame_bits(s);
+ s->exponent_bits = count_exponent_bits(s);
+
bit_alloc_masking(s);
return cbr_bit_allocation(s);
@@ -1162,7 +1251,7 @@ void ff_ac3_quantize_mantissas(AC3EncodeContext *s)
{
int blk, ch, ch0=0, got_cpl;
- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
+ for (blk = 0; blk < s->num_blocks; blk++) {
AC3Block *block = &s->blocks[blk];
AC3Mant m = { 0 };
@@ -1302,9 +1391,9 @@ static void output_audio_block(AC3EncodeContext *s, int blk)
if (block->cpl_in_use) {
for (ch = 1; ch <= s->fbw_channels; ch++) {
if (block->channel_in_cpl[ch]) {
- if (!s->eac3 || block->new_cpl_coords != 2)
- put_bits(&s->pb, 1, block->new_cpl_coords);
- if (block->new_cpl_coords) {
+ if (!s->eac3 || block->new_cpl_coords[ch] != 2)
+ put_bits(&s->pb, 1, block->new_cpl_coords[ch]);
+ if (block->new_cpl_coords[ch]) {
put_bits(&s->pb, 2, block->cpl_master_exp[ch]);
for (bnd = 0; bnd < s->num_cpl_bands; bnd++) {
put_bits(&s->pb, 4, block->cpl_coord_exp [ch][bnd]);
@@ -1525,17 +1614,17 @@ void ff_ac3_output_frame(AC3EncodeContext *s, unsigned char *frame)
s->output_frame_header(s);
- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++)
+ for (blk = 0; blk < s->num_blocks; blk++)
output_audio_block(s, blk);
output_frame_end(s);
}
-static void dprint_options(AVCodecContext *avctx)
+static void dprint_options(AC3EncodeContext *s)
{
#ifdef DEBUG
- AC3EncodeContext *s = avctx->priv_data;
+ AVCodecContext *avctx = s->avctx;
AC3EncOptions *opt = &s->options;
char strbuf[32];
@@ -1553,6 +1642,7 @@ static void dprint_options(AVCodecContext *avctx)
av_dlog(avctx, "channel_layout: %s\n", strbuf);
av_dlog(avctx, "sample_rate: %d\n", s->sample_rate);
av_dlog(avctx, "bit_rate: %d\n", s->bit_rate);
+ av_dlog(avctx, "blocks/frame: %d (code=%d)\n", s->num_blocks, s->num_blks_code);
if (s->cutoff)
av_dlog(avctx, "cutoff: %d\n", s->cutoff);
@@ -1571,9 +1661,9 @@ static void dprint_options(AVCodecContext *avctx)
if (opt->audio_production_info) {
av_dlog(avctx, "mixing_level: %ddB\n", opt->mixing_level);
switch (opt->room_type) {
- case 0: av_strlcpy(strbuf, "notindicated", 32); break;
- case 1: av_strlcpy(strbuf, "large", 32); break;
- case 2: av_strlcpy(strbuf, "small", 32); break;
+ case AC3ENC_OPT_NOT_INDICATED: av_strlcpy(strbuf, "notindicated", 32); break;
+ case AC3ENC_OPT_LARGE_ROOM: av_strlcpy(strbuf, "large", 32); break;
+ case AC3ENC_OPT_SMALL_ROOM: av_strlcpy(strbuf, "small", 32); break;
default: snprintf(strbuf, 32, "ERROR (%d)", opt->room_type);
}
av_dlog(avctx, "room_type: %s\n", strbuf);
@@ -1585,9 +1675,9 @@ static void dprint_options(AVCodecContext *avctx)
av_dlog(avctx, "dialnorm: %ddB\n", opt->dialogue_level);
if (s->channel_mode == AC3_CHMODE_STEREO) {
switch (opt->dolby_surround_mode) {
- case 0: av_strlcpy(strbuf, "notindicated", 32); break;
- case 1: av_strlcpy(strbuf, "on", 32); break;
- case 2: av_strlcpy(strbuf, "off", 32); break;
+ case AC3ENC_OPT_NOT_INDICATED: av_strlcpy(strbuf, "notindicated", 32); break;
+ case AC3ENC_OPT_MODE_ON: av_strlcpy(strbuf, "on", 32); break;
+ case AC3ENC_OPT_MODE_OFF: av_strlcpy(strbuf, "off", 32); break;
default: snprintf(strbuf, 32, "ERROR (%d)", opt->dolby_surround_mode);
}
av_dlog(avctx, "dsur_mode: %s\n", strbuf);
@@ -1599,9 +1689,9 @@ static void dprint_options(AVCodecContext *avctx)
if (s->bitstream_id == 6) {
if (opt->extended_bsi_1) {
switch (opt->preferred_stereo_downmix) {
- case 0: av_strlcpy(strbuf, "notindicated", 32); break;
- case 1: av_strlcpy(strbuf, "ltrt", 32); break;
- case 2: av_strlcpy(strbuf, "loro", 32); break;
+ case AC3ENC_OPT_NOT_INDICATED: av_strlcpy(strbuf, "notindicated", 32); break;
+ case AC3ENC_OPT_DOWNMIX_LTRT: av_strlcpy(strbuf, "ltrt", 32); break;
+ case AC3ENC_OPT_DOWNMIX_LORO: av_strlcpy(strbuf, "loro", 32); break;
default: snprintf(strbuf, 32, "ERROR (%d)", opt->preferred_stereo_downmix);
}
av_dlog(avctx, "dmix_mode: %s\n", strbuf);
@@ -1618,23 +1708,23 @@ static void dprint_options(AVCodecContext *avctx)
}
if (opt->extended_bsi_2) {
switch (opt->dolby_surround_ex_mode) {
- case 0: av_strlcpy(strbuf, "notindicated", 32); break;
- case 1: av_strlcpy(strbuf, "on", 32); break;
- case 2: av_strlcpy(strbuf, "off", 32); break;
+ case AC3ENC_OPT_NOT_INDICATED: av_strlcpy(strbuf, "notindicated", 32); break;
+ case AC3ENC_OPT_MODE_ON: av_strlcpy(strbuf, "on", 32); break;
+ case AC3ENC_OPT_MODE_OFF: av_strlcpy(strbuf, "off", 32); break;
default: snprintf(strbuf, 32, "ERROR (%d)", opt->dolby_surround_ex_mode);
}
av_dlog(avctx, "dsurex_mode: %s\n", strbuf);
switch (opt->dolby_headphone_mode) {
- case 0: av_strlcpy(strbuf, "notindicated", 32); break;
- case 1: av_strlcpy(strbuf, "on", 32); break;
- case 2: av_strlcpy(strbuf, "off", 32); break;
+ case AC3ENC_OPT_NOT_INDICATED: av_strlcpy(strbuf, "notindicated", 32); break;
+ case AC3ENC_OPT_MODE_ON: av_strlcpy(strbuf, "on", 32); break;
+ case AC3ENC_OPT_MODE_OFF: av_strlcpy(strbuf, "off", 32); break;
default: snprintf(strbuf, 32, "ERROR (%d)", opt->dolby_headphone_mode);
}
av_dlog(avctx, "dheadphone_mode: %s\n", strbuf);
switch (opt->ad_converter_type) {
- case 0: av_strlcpy(strbuf, "standard", 32); break;
- case 1: av_strlcpy(strbuf, "hdcd", 32); break;
+ case AC3ENC_OPT_ADCONV_STANDARD: av_strlcpy(strbuf, "standard", 32); break;
+ case AC3ENC_OPT_ADCONV_HDCD: av_strlcpy(strbuf, "hdcd", 32); break;
default: snprintf(strbuf, 32, "ERROR (%d)", opt->ad_converter_type);
}
av_dlog(avctx, "ad_conv_type: %s\n", strbuf);
@@ -1686,26 +1776,152 @@ static void validate_mix_level(void *log_ctx, const char *opt_name,
* Validate metadata options as set by AVOption system.
* These values can optionally be changed per-frame.
*/
-int ff_ac3_validate_metadata(AVCodecContext *avctx)
+int ff_ac3_validate_metadata(AC3EncodeContext *s)
{
- AC3EncodeContext *s = avctx->priv_data;
+ AVCodecContext *avctx = s->avctx;
AC3EncOptions *opt = &s->options;
- /* validate mixing levels */
- if (s->has_center) {
- validate_mix_level(avctx, "center_mix_level", &opt->center_mix_level,
- cmixlev_options, CMIXLEV_NUM_OPTIONS, 1, 0,
- &s->center_mix_level);
+ opt->audio_production_info = 0;
+ opt->extended_bsi_1 = 0;
+ opt->extended_bsi_2 = 0;
+ opt->eac3_mixing_metadata = 0;
+ opt->eac3_info_metadata = 0;
+
+ /* determine mixing metadata / xbsi1 use */
+ if (s->channel_mode > AC3_CHMODE_STEREO && opt->preferred_stereo_downmix != AC3ENC_OPT_NONE) {
+ opt->extended_bsi_1 = 1;
+ opt->eac3_mixing_metadata = 1;
+ }
+ if (s->has_center &&
+ (opt->ltrt_center_mix_level >= 0 || opt->loro_center_mix_level >= 0)) {
+ opt->extended_bsi_1 = 1;
+ opt->eac3_mixing_metadata = 1;
+ }
+ if (s->has_surround &&
+ (opt->ltrt_surround_mix_level >= 0 || opt->loro_surround_mix_level >= 0)) {
+ opt->extended_bsi_1 = 1;
+ opt->eac3_mixing_metadata = 1;
+ }
+
+ if (s->eac3) {
+ /* determine info metadata use */
+ if (avctx->audio_service_type != AV_AUDIO_SERVICE_TYPE_MAIN)
+ opt->eac3_info_metadata = 1;
+ if (opt->copyright != AC3ENC_OPT_NONE || opt->original != AC3ENC_OPT_NONE)
+ opt->eac3_info_metadata = 1;
+ if (s->channel_mode == AC3_CHMODE_STEREO &&
+ (opt->dolby_headphone_mode != AC3ENC_OPT_NONE || opt->dolby_surround_mode != AC3ENC_OPT_NONE))
+ opt->eac3_info_metadata = 1;
+ if (s->channel_mode >= AC3_CHMODE_2F2R && opt->dolby_surround_ex_mode != AC3ENC_OPT_NONE)
+ opt->eac3_info_metadata = 1;
+ if (opt->mixing_level != AC3ENC_OPT_NONE || opt->room_type != AC3ENC_OPT_NONE ||
+ opt->ad_converter_type != AC3ENC_OPT_NONE) {
+ opt->audio_production_info = 1;
+ opt->eac3_info_metadata = 1;
+ }
+ } else {
+ /* determine audio production info use */
+ if (opt->mixing_level != AC3ENC_OPT_NONE || opt->room_type != AC3ENC_OPT_NONE)
+ opt->audio_production_info = 1;
+
+ /* determine xbsi2 use */
+ if (s->channel_mode >= AC3_CHMODE_2F2R && opt->dolby_surround_ex_mode != AC3ENC_OPT_NONE)
+ opt->extended_bsi_2 = 1;
+ if (s->channel_mode == AC3_CHMODE_STEREO && opt->dolby_headphone_mode != AC3ENC_OPT_NONE)
+ opt->extended_bsi_2 = 1;
+ if (opt->ad_converter_type != AC3ENC_OPT_NONE)
+ opt->extended_bsi_2 = 1;
+ }
+
+ /* validate AC-3 mixing levels */
+ if (!s->eac3) {
+ if (s->has_center) {
+ validate_mix_level(avctx, "center_mix_level", &opt->center_mix_level,
+ cmixlev_options, CMIXLEV_NUM_OPTIONS, 1, 0,
+ &s->center_mix_level);
+ }
+ if (s->has_surround) {
+ validate_mix_level(avctx, "surround_mix_level", &opt->surround_mix_level,
+ surmixlev_options, SURMIXLEV_NUM_OPTIONS, 1, 0,
+ &s->surround_mix_level);
+ }
+ }
+
+ /* validate extended bsi 1 / mixing metadata */
+ if (opt->extended_bsi_1 || opt->eac3_mixing_metadata) {
+ /* default preferred stereo downmix */
+ if (opt->preferred_stereo_downmix == AC3ENC_OPT_NONE)
+ opt->preferred_stereo_downmix = AC3ENC_OPT_NOT_INDICATED;
+ if (!s->eac3 || s->has_center) {
+ /* validate Lt/Rt center mix level */
+ validate_mix_level(avctx, "ltrt_center_mix_level",
+ &opt->ltrt_center_mix_level, extmixlev_options,
+ EXTMIXLEV_NUM_OPTIONS, 5, 0,
+ &s->ltrt_center_mix_level);
+ /* validate Lo/Ro center mix level */
+ validate_mix_level(avctx, "loro_center_mix_level",
+ &opt->loro_center_mix_level, extmixlev_options,
+ EXTMIXLEV_NUM_OPTIONS, 5, 0,
+ &s->loro_center_mix_level);
+ }
+ if (!s->eac3 || s->has_surround) {
+ /* validate Lt/Rt surround mix level */
+ validate_mix_level(avctx, "ltrt_surround_mix_level",
+ &opt->ltrt_surround_mix_level, extmixlev_options,
+ EXTMIXLEV_NUM_OPTIONS, 6, 3,
+ &s->ltrt_surround_mix_level);
+ /* validate Lo/Ro surround mix level */
+ validate_mix_level(avctx, "loro_surround_mix_level",
+ &opt->loro_surround_mix_level, extmixlev_options,
+ EXTMIXLEV_NUM_OPTIONS, 6, 3,
+ &s->loro_surround_mix_level);
+ }
+ }
+
+ /* validate audio service type / channels combination */
+ if ((avctx->audio_service_type == AV_AUDIO_SERVICE_TYPE_KARAOKE &&
+ avctx->channels == 1) ||
+ ((avctx->audio_service_type == AV_AUDIO_SERVICE_TYPE_COMMENTARY ||
+ avctx->audio_service_type == AV_AUDIO_SERVICE_TYPE_EMERGENCY ||
+ avctx->audio_service_type == AV_AUDIO_SERVICE_TYPE_VOICE_OVER)
+ && avctx->channels > 1)) {
+ av_log(avctx, AV_LOG_ERROR, "invalid audio service type for the "
+ "specified number of channels\n");
+ return AVERROR(EINVAL);
+ }
+
+ /* validate extended bsi 2 / info metadata */
+ if (opt->extended_bsi_2 || opt->eac3_info_metadata) {
+ /* default dolby headphone mode */
+ if (opt->dolby_headphone_mode == AC3ENC_OPT_NONE)
+ opt->dolby_headphone_mode = AC3ENC_OPT_NOT_INDICATED;
+ /* default dolby surround ex mode */
+ if (opt->dolby_surround_ex_mode == AC3ENC_OPT_NONE)
+ opt->dolby_surround_ex_mode = AC3ENC_OPT_NOT_INDICATED;
+ /* default A/D converter type */
+ if (opt->ad_converter_type == AC3ENC_OPT_NONE)
+ opt->ad_converter_type = AC3ENC_OPT_ADCONV_STANDARD;
}
- if (s->has_surround) {
- validate_mix_level(avctx, "surround_mix_level", &opt->surround_mix_level,
- surmixlev_options, SURMIXLEV_NUM_OPTIONS, 1, 0,
- &s->surround_mix_level);
+
+ /* copyright & original defaults */
+ if (!s->eac3 || opt->eac3_info_metadata) {
+ /* default copyright */
+ if (opt->copyright == AC3ENC_OPT_NONE)
+ opt->copyright = AC3ENC_OPT_OFF;
+ /* default original */
+ if (opt->original == AC3ENC_OPT_NONE)
+ opt->original = AC3ENC_OPT_ON;
}
- /* set audio production info flag */
- if (opt->mixing_level >= 0 || opt->room_type >= 0) {
- if (opt->mixing_level < 0) {
+ /* dolby surround mode default */
+ if (!s->eac3 || opt->eac3_info_metadata) {
+ if (opt->dolby_surround_mode == AC3ENC_OPT_NONE)
+ opt->dolby_surround_mode = AC3ENC_OPT_NOT_INDICATED;
+ }
+
+ /* validate audio production info */
+ if (opt->audio_production_info) {
+ if (opt->mixing_level == AC3ENC_OPT_NONE) {
av_log(avctx, AV_LOG_ERROR, "mixing_level must be set if "
"room_type is set\n");
return AVERROR(EINVAL);
@@ -1716,68 +1932,12 @@ int ff_ac3_validate_metadata(AVCodecContext *avctx)
return AVERROR(EINVAL);
}
/* default room type */
- if (opt->room_type < 0)
- opt->room_type = 0;
- opt->audio_production_info = 1;
- } else {
- opt->audio_production_info = 0;
- }
-
- /* set extended bsi 1 flag */
- if ((s->has_center || s->has_surround) &&
- (opt->preferred_stereo_downmix >= 0 ||
- opt->ltrt_center_mix_level >= 0 ||
- opt->ltrt_surround_mix_level >= 0 ||
- opt->loro_center_mix_level >= 0 ||
- opt->loro_surround_mix_level >= 0)) {
- /* default preferred stereo downmix */
- if (opt->preferred_stereo_downmix < 0)
- opt->preferred_stereo_downmix = 0;
- /* validate Lt/Rt center mix level */
- validate_mix_level(avctx, "ltrt_center_mix_level",
- &opt->ltrt_center_mix_level, extmixlev_options,
- EXTMIXLEV_NUM_OPTIONS, 5, 0,
- &s->ltrt_center_mix_level);
- /* validate Lt/Rt surround mix level */
- validate_mix_level(avctx, "ltrt_surround_mix_level",
- &opt->ltrt_surround_mix_level, extmixlev_options,
- EXTMIXLEV_NUM_OPTIONS, 6, 3,
- &s->ltrt_surround_mix_level);
- /* validate Lo/Ro center mix level */
- validate_mix_level(avctx, "loro_center_mix_level",
- &opt->loro_center_mix_level, extmixlev_options,
- EXTMIXLEV_NUM_OPTIONS, 5, 0,
- &s->loro_center_mix_level);
- /* validate Lo/Ro surround mix level */
- validate_mix_level(avctx, "loro_surround_mix_level",
- &opt->loro_surround_mix_level, extmixlev_options,
- EXTMIXLEV_NUM_OPTIONS, 6, 3,
- &s->loro_surround_mix_level);
- opt->extended_bsi_1 = 1;
- } else {
- opt->extended_bsi_1 = 0;
- }
-
- /* set extended bsi 2 flag */
- if (opt->dolby_surround_ex_mode >= 0 ||
- opt->dolby_headphone_mode >= 0 ||
- opt->ad_converter_type >= 0) {
- /* default dolby surround ex mode */
- if (opt->dolby_surround_ex_mode < 0)
- opt->dolby_surround_ex_mode = 0;
- /* default dolby headphone mode */
- if (opt->dolby_headphone_mode < 0)
- opt->dolby_headphone_mode = 0;
- /* default A/D converter type */
- if (opt->ad_converter_type < 0)
- opt->ad_converter_type = 0;
- opt->extended_bsi_2 = 1;
- } else {
- opt->extended_bsi_2 = 0;
+ if (opt->room_type == AC3ENC_OPT_NONE)
+ opt->room_type = AC3ENC_OPT_NOT_INDICATED;
}
/* set bitstream id for alternate bitstream syntax */
- if (opt->extended_bsi_1 || opt->extended_bsi_2) {
+ if (!s->eac3 && (opt->extended_bsi_1 || opt->extended_bsi_2)) {
if (s->bitstream_id > 8 && s->bitstream_id < 11) {
static int warn_once = 1;
if (warn_once) {
@@ -1817,7 +1977,9 @@ av_cold int ff_ac3_encode_close(AVCodecContext *avctx)
av_freep(&s->band_psd_buffer);
av_freep(&s->mask_buffer);
av_freep(&s->qmant_buffer);
- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
+ av_freep(&s->cpl_coord_exp_buffer);
+ av_freep(&s->cpl_coord_mant_buffer);
+ for (blk = 0; blk < s->num_blocks; blk++) {
AC3Block *block = &s->blocks[blk];
av_freep(&block->mdct_coef);
av_freep(&block->fixed_coef);
@@ -1827,10 +1989,11 @@ av_cold int ff_ac3_encode_close(AVCodecContext *avctx)
av_freep(&block->band_psd);
av_freep(&block->mask);
av_freep(&block->qmant);
+ av_freep(&block->cpl_coord_exp);
+ av_freep(&block->cpl_coord_mant);
}
- s->mdct_end(s->mdct);
- av_freep(&s->mdct);
+ s->mdct_end(s);
av_freep(&avctx->coded_frame);
return 0;
@@ -1885,8 +2048,9 @@ static av_cold int set_channel_info(AC3EncodeContext *s, int channels,
}
-static av_cold int validate_options(AVCodecContext *avctx, AC3EncodeContext *s)
+static av_cold int validate_options(AC3EncodeContext *s)
{
+ AVCodecContext *avctx = s->avctx;
int i, ret, max_sr;
/* validate channel layout */
@@ -1922,18 +2086,30 @@ static av_cold int validate_options(AVCodecContext *avctx, AC3EncodeContext *s)
/* validate bit rate */
if (s->eac3) {
int max_br, min_br, wpf, min_br_dist, min_br_code;
+ int num_blks_code, num_blocks, frame_samples;
/* calculate min/max bitrate */
- max_br = 2048 * s->sample_rate / AC3_FRAME_SIZE * 16;
- min_br = ((s->sample_rate + (AC3_FRAME_SIZE-1)) / AC3_FRAME_SIZE) * 16;
+ /* TODO: More testing with 3 and 2 blocks. All E-AC-3 samples I've
+ found use either 6 blocks or 1 block, even though 2 or 3 blocks
+ would work as far as the bit rate is concerned. */
+ for (num_blks_code = 3; num_blks_code >= 0; num_blks_code--) {
+ num_blocks = ((int[]){ 1, 2, 3, 6 })[num_blks_code];
+ frame_samples = AC3_BLOCK_SIZE * num_blocks;
+ max_br = 2048 * s->sample_rate / frame_samples * 16;
+ min_br = ((s->sample_rate + (frame_samples-1)) / frame_samples) * 16;
+ if (avctx->bit_rate <= max_br)
+ break;
+ }
if (avctx->bit_rate < min_br || avctx->bit_rate > max_br) {
av_log(avctx, AV_LOG_ERROR, "invalid bit rate. must be %d to %d "
"for this sample rate\n", min_br, max_br);
return AVERROR(EINVAL);
}
+ s->num_blks_code = num_blks_code;
+ s->num_blocks = num_blocks;
/* calculate words-per-frame for the selected bitrate */
- wpf = (avctx->bit_rate / 16) * AC3_FRAME_SIZE / s->sample_rate;
+ wpf = (avctx->bit_rate / 16) * frame_samples / s->sample_rate;
av_assert1(wpf > 0 && wpf <= 2048);
/* find the closest AC-3 bitrate code to the selected bitrate.
@@ -1965,6 +2141,8 @@ static av_cold int validate_options(AVCodecContext *avctx, AC3EncodeContext *s)
}
s->frame_size_code = i << 1;
s->frame_size_min = 2 * ff_ac3_frame_size_tab[s->frame_size_code][s->bit_alloc.sr_code];
+ s->num_blks_code = 0x3;
+ s->num_blocks = 6;
}
s->bit_rate = avctx->bit_rate;
s->frame_size = s->frame_size_min;
@@ -1978,29 +2156,15 @@ static av_cold int validate_options(AVCodecContext *avctx, AC3EncodeContext *s)
if (s->cutoff > (s->sample_rate >> 1))
s->cutoff = s->sample_rate >> 1;
- /* validate audio service type / channels combination */
- if ((avctx->audio_service_type == AV_AUDIO_SERVICE_TYPE_KARAOKE &&
- avctx->channels == 1) ||
- ((avctx->audio_service_type == AV_AUDIO_SERVICE_TYPE_COMMENTARY ||
- avctx->audio_service_type == AV_AUDIO_SERVICE_TYPE_EMERGENCY ||
- avctx->audio_service_type == AV_AUDIO_SERVICE_TYPE_VOICE_OVER)
- && avctx->channels > 1)) {
- av_log(avctx, AV_LOG_ERROR, "invalid audio service type for the "
- "specified number of channels\n");
- return AVERROR(EINVAL);
- }
-
- if (!s->eac3) {
- ret = ff_ac3_validate_metadata(avctx);
- if (ret)
- return ret;
- }
+ ret = ff_ac3_validate_metadata(s);
+ if (ret)
+ return ret;
s->rematrixing_enabled = s->options.stereo_rematrixing &&
(s->channel_mode == AC3_CHMODE_STEREO);
s->cpl_enabled = s->options.channel_coupling &&
- s->channel_mode >= AC3_CHMODE_STEREO && !s->fixed_point;
+ s->channel_mode >= AC3_CHMODE_STEREO;
return 0;
}
@@ -2029,24 +2193,28 @@ static av_cold void set_bandwidth(AC3EncodeContext *s)
/* set number of coefficients for each channel */
for (ch = 1; ch <= s->fbw_channels; ch++) {
s->start_freq[ch] = 0;
- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++)
+ for (blk = 0; blk < s->num_blocks; blk++)
s->blocks[blk].end_freq[ch] = s->bandwidth_code * 3 + 73;
}
/* LFE channel always has 7 coefs */
if (s->lfe_on) {
s->start_freq[s->lfe_channel] = 0;
- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++)
+ for (blk = 0; blk < s->num_blocks; blk++)
s->blocks[blk].end_freq[ch] = 7;
}
/* initialize coupling strategy */
if (s->cpl_enabled) {
- if (s->options.cpl_start >= 0) {
+ if (s->options.cpl_start != AC3ENC_OPT_AUTO) {
cpl_start = s->options.cpl_start;
} else {
cpl_start = ac3_coupling_start_tab[s->channel_mode-2][s->bit_alloc.sr_code][s->frame_size_code/2];
- if (cpl_start < 0)
- s->cpl_enabled = 0;
+ if (cpl_start < 0) {
+ if (s->options.channel_coupling == AC3ENC_OPT_AUTO)
+ s->cpl_enabled = 0;
+ else
+ cpl_start = 15;
+ }
}
}
if (s->cpl_enabled) {
@@ -2072,46 +2240,48 @@ static av_cold void set_bandwidth(AC3EncodeContext *s)
s->start_freq[CPL_CH] = cpl_start_band * 12 + 37;
s->cpl_end_freq = cpl_end_band * 12 + 37;
- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++)
+ for (blk = 0; blk < s->num_blocks; blk++)
s->blocks[blk].end_freq[CPL_CH] = s->cpl_end_freq;
}
}
-static av_cold int allocate_buffers(AVCodecContext *avctx)
+static av_cold int allocate_buffers(AC3EncodeContext *s)
{
+ AVCodecContext *avctx = s->avctx;
int blk, ch;
- AC3EncodeContext *s = avctx->priv_data;
int channels = s->channels + 1; /* includes coupling channel */
+ int channel_blocks = channels * s->num_blocks;
+ int total_coefs = AC3_MAX_COEFS * channel_blocks;
if (s->allocate_sample_buffers(s))
goto alloc_fail;
- FF_ALLOC_OR_GOTO(avctx, s->bap_buffer, AC3_MAX_BLOCKS * channels *
- AC3_MAX_COEFS * sizeof(*s->bap_buffer), alloc_fail);
- FF_ALLOC_OR_GOTO(avctx, s->bap1_buffer, AC3_MAX_BLOCKS * channels *
- AC3_MAX_COEFS * sizeof(*s->bap1_buffer), alloc_fail);
- FF_ALLOCZ_OR_GOTO(avctx, s->mdct_coef_buffer, AC3_MAX_BLOCKS * channels *
- AC3_MAX_COEFS * sizeof(*s->mdct_coef_buffer), alloc_fail);
- FF_ALLOC_OR_GOTO(avctx, s->exp_buffer, AC3_MAX_BLOCKS * channels *
- AC3_MAX_COEFS * sizeof(*s->exp_buffer), alloc_fail);
- FF_ALLOC_OR_GOTO(avctx, s->grouped_exp_buffer, AC3_MAX_BLOCKS * channels *
- 128 * sizeof(*s->grouped_exp_buffer), alloc_fail);
- FF_ALLOC_OR_GOTO(avctx, s->psd_buffer, AC3_MAX_BLOCKS * channels *
- AC3_MAX_COEFS * sizeof(*s->psd_buffer), alloc_fail);
- FF_ALLOC_OR_GOTO(avctx, s->band_psd_buffer, AC3_MAX_BLOCKS * channels *
- 64 * sizeof(*s->band_psd_buffer), alloc_fail);
- FF_ALLOC_OR_GOTO(avctx, s->mask_buffer, AC3_MAX_BLOCKS * channels *
- 64 * sizeof(*s->mask_buffer), alloc_fail);
- FF_ALLOC_OR_GOTO(avctx, s->qmant_buffer, AC3_MAX_BLOCKS * channels *
- AC3_MAX_COEFS * sizeof(*s->qmant_buffer), alloc_fail);
+ FF_ALLOC_OR_GOTO(avctx, s->bap_buffer, total_coefs *
+ sizeof(*s->bap_buffer), alloc_fail);
+ FF_ALLOC_OR_GOTO(avctx, s->bap1_buffer, total_coefs *
+ sizeof(*s->bap1_buffer), alloc_fail);
+ FF_ALLOCZ_OR_GOTO(avctx, s->mdct_coef_buffer, total_coefs *
+ sizeof(*s->mdct_coef_buffer), alloc_fail);
+ FF_ALLOC_OR_GOTO(avctx, s->exp_buffer, total_coefs *
+ sizeof(*s->exp_buffer), alloc_fail);
+ FF_ALLOC_OR_GOTO(avctx, s->grouped_exp_buffer, channel_blocks * 128 *
+ sizeof(*s->grouped_exp_buffer), alloc_fail);
+ FF_ALLOC_OR_GOTO(avctx, s->psd_buffer, total_coefs *
+ sizeof(*s->psd_buffer), alloc_fail);
+ FF_ALLOC_OR_GOTO(avctx, s->band_psd_buffer, channel_blocks * 64 *
+ sizeof(*s->band_psd_buffer), alloc_fail);
+ FF_ALLOC_OR_GOTO(avctx, s->mask_buffer, channel_blocks * 64 *
+ sizeof(*s->mask_buffer), alloc_fail);
+ FF_ALLOC_OR_GOTO(avctx, s->qmant_buffer, total_coefs *
+ sizeof(*s->qmant_buffer), alloc_fail);
if (s->cpl_enabled) {
- FF_ALLOC_OR_GOTO(avctx, s->cpl_coord_exp_buffer, AC3_MAX_BLOCKS * channels *
- 16 * sizeof(*s->cpl_coord_exp_buffer), alloc_fail);
- FF_ALLOC_OR_GOTO(avctx, s->cpl_coord_mant_buffer, AC3_MAX_BLOCKS * channels *
- 16 * sizeof(*s->cpl_coord_mant_buffer), alloc_fail);
+ FF_ALLOC_OR_GOTO(avctx, s->cpl_coord_exp_buffer, channel_blocks * 16 *
+ sizeof(*s->cpl_coord_exp_buffer), alloc_fail);
+ FF_ALLOC_OR_GOTO(avctx, s->cpl_coord_mant_buffer, channel_blocks * 16 *
+ sizeof(*s->cpl_coord_mant_buffer), alloc_fail);
}
- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
+ for (blk = 0; blk < s->num_blocks; blk++) {
AC3Block *block = &s->blocks[blk];
FF_ALLOCZ_OR_GOTO(avctx, block->mdct_coef, channels * sizeof(*block->mdct_coef),
alloc_fail);
@@ -2147,23 +2317,23 @@ static av_cold int allocate_buffers(AVCodecContext *avctx)
}
/* arrangement: channel, block, coeff */
- block->exp[ch] = &s->exp_buffer [AC3_MAX_COEFS * (AC3_MAX_BLOCKS * ch + blk)];
- block->mdct_coef[ch] = &s->mdct_coef_buffer [AC3_MAX_COEFS * (AC3_MAX_BLOCKS * ch + blk)];
+ block->exp[ch] = &s->exp_buffer [AC3_MAX_COEFS * (s->num_blocks * ch + blk)];
+ block->mdct_coef[ch] = &s->mdct_coef_buffer [AC3_MAX_COEFS * (s->num_blocks * ch + blk)];
}
}
if (!s->fixed_point) {
- FF_ALLOCZ_OR_GOTO(avctx, s->fixed_coef_buffer, AC3_MAX_BLOCKS * channels *
- AC3_MAX_COEFS * sizeof(*s->fixed_coef_buffer), alloc_fail);
- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
+ FF_ALLOCZ_OR_GOTO(avctx, s->fixed_coef_buffer, total_coefs *
+ sizeof(*s->fixed_coef_buffer), alloc_fail);
+ for (blk = 0; blk < s->num_blocks; blk++) {
AC3Block *block = &s->blocks[blk];
FF_ALLOCZ_OR_GOTO(avctx, block->fixed_coef, channels *
sizeof(*block->fixed_coef), alloc_fail);
for (ch = 0; ch < channels; ch++)
- block->fixed_coef[ch] = &s->fixed_coef_buffer[AC3_MAX_COEFS * (AC3_MAX_BLOCKS * ch + blk)];
+ block->fixed_coef[ch] = &s->fixed_coef_buffer[AC3_MAX_COEFS * (s->num_blocks * ch + blk)];
}
} else {
- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
+ for (blk = 0; blk < s->num_blocks; blk++) {
AC3Block *block = &s->blocks[blk];
FF_ALLOCZ_OR_GOTO(avctx, block->fixed_coef, channels *
sizeof(*block->fixed_coef), alloc_fail);
@@ -2190,14 +2360,14 @@ av_cold int ff_ac3_encode_init(AVCodecContext *avctx)
s->eac3 = avctx->codec_id == CODEC_ID_EAC3;
- avctx->frame_size = AC3_FRAME_SIZE;
-
ff_ac3_common_init();
- ret = validate_options(avctx, s);
+ ret = validate_options(s);
if (ret)
return ret;
+ avctx->frame_size = AC3_BLOCK_SIZE * s->num_blocks;
+
s->bitstream_mode = avctx->audio_service_type;
if (s->bitstream_mode == AV_AUDIO_SERVICE_TYPE_KARAOKE)
s->bitstream_mode = 0x7;
@@ -2234,12 +2404,11 @@ av_cold int ff_ac3_encode_init(AVCodecContext *avctx)
bit_alloc_init(s);
- FF_ALLOCZ_OR_GOTO(avctx, s->mdct, sizeof(AC3MDCTContext), init_fail);
- ret = s->mdct_init(avctx, s->mdct, 9);
+ ret = s->mdct_init(s);
if (ret)
goto init_fail;
- ret = allocate_buffers(avctx);
+ ret = allocate_buffers(s);
if (ret)
goto init_fail;
@@ -2248,7 +2417,7 @@ av_cold int ff_ac3_encode_init(AVCodecContext *avctx)
dsputil_init(&s->dsp, avctx);
ff_ac3dsp_init(&s->ac3dsp, avctx->flags & CODEC_FLAG_BITEXACT);
- dprint_options(avctx);
+ dprint_options(s);
return 0;
init_fail:
diff --git a/libavcodec/ac3enc.h b/libavcodec/ac3enc.h
index 54f427a523..4a017498f6 100644
--- a/libavcodec/ac3enc.h
+++ b/libavcodec/ac3enc.h
@@ -52,6 +52,7 @@
#define MAC_COEF(d,a,b) ((d)+=(a)*(b))
#define COEF_MIN (-16777215.0/16777216.0)
#define COEF_MAX ( 16777215.0/16777216.0)
+#define NEW_CPL_COORD_THRESHOLD 0.03
typedef float SampleType;
typedef float CoefType;
typedef float CoefSumType;
@@ -60,16 +61,29 @@ typedef float CoefSumType;
#define MAC_COEF(d,a,b) MAC64(d,a,b)
#define COEF_MIN -16777215
#define COEF_MAX 16777215
+#define NEW_CPL_COORD_THRESHOLD 503317
typedef int16_t SampleType;
typedef int32_t CoefType;
typedef int64_t CoefSumType;
#endif
+/* common option values */
+#define AC3ENC_OPT_NONE -1
+#define AC3ENC_OPT_AUTO -1
+#define AC3ENC_OPT_OFF 0
+#define AC3ENC_OPT_ON 1
+#define AC3ENC_OPT_NOT_INDICATED 0
+#define AC3ENC_OPT_MODE_ON 2
+#define AC3ENC_OPT_MODE_OFF 1
+
+/* specific option values */
+#define AC3ENC_OPT_LARGE_ROOM 1
+#define AC3ENC_OPT_SMALL_ROOM 2
+#define AC3ENC_OPT_DOWNMIX_LTRT 1
+#define AC3ENC_OPT_DOWNMIX_LORO 2
+#define AC3ENC_OPT_ADCONV_STANDARD 0
+#define AC3ENC_OPT_ADCONV_HDCD 1
-typedef struct AC3MDCTContext {
- const SampleType *window; ///< MDCT window function
- FFTContext fft; ///< FFT context for MDCT calculation
-} AC3MDCTContext;
/**
* Encoding Options used by AVOption.
@@ -96,6 +110,8 @@ typedef struct AC3EncOptions {
int dolby_surround_ex_mode;
int dolby_headphone_mode;
int ad_converter_type;
+ int eac3_mixing_metadata;
+ int eac3_info_metadata;
/* other encoding options */
int allow_per_frame_metadata;
@@ -126,7 +142,7 @@ typedef struct AC3Block {
int cpl_in_use; ///< coupling in use for this block (cplinu)
uint8_t channel_in_cpl[AC3_MAX_CHANNELS]; ///< channel in coupling (chincpl)
int num_cpl_channels; ///< number of channels in coupling
- uint8_t new_cpl_coords; ///< send new coupling coordinates (cplcoe)
+ uint8_t new_cpl_coords[AC3_MAX_CHANNELS]; ///< send new coupling coordinates (cplcoe)
uint8_t cpl_master_exp[AC3_MAX_CHANNELS]; ///< coupling coord master exponents (mstrcplco)
int new_snr_offsets; ///< send new SNR offsets
int new_cpl_leak; ///< send new coupling leak info
@@ -143,7 +159,8 @@ typedef struct AC3EncodeContext {
PutBitContext pb; ///< bitstream writer context
DSPContext dsp;
AC3DSPContext ac3dsp; ///< AC-3 optimized functions
- AC3MDCTContext *mdct; ///< MDCT context
+ FFTContext mdct; ///< FFT context for MDCT calculation
+ const SampleType *mdct_window; ///< MDCT window function array
AC3Block blocks[AC3_MAX_BLOCKS]; ///< per-block info
@@ -155,6 +172,8 @@ typedef struct AC3EncodeContext {
int bit_rate; ///< target bit rate, in bits-per-second
int sample_rate; ///< sampling frequency, in Hz
+ int num_blks_code; ///< number of blocks code (numblkscod)
+ int num_blocks; ///< number of blocks per frame
int frame_size_min; ///< minimum frame size in case rounding is necessary
int frame_size; ///< current frame size in bytes
int frame_size_code; ///< frame size code (frmsizecod)
@@ -221,13 +240,15 @@ typedef struct AC3EncodeContext {
uint8_t *cpl_coord_mant_buffer;
uint8_t exp_strategy[AC3_MAX_CHANNELS][AC3_MAX_BLOCKS]; ///< exponent strategies
+ uint8_t frame_exp_strategy[AC3_MAX_CHANNELS]; ///< frame exp strategy index
+ int use_frame_exp_strategy; ///< indicates use of frame exp strategy
uint8_t exp_ref_block[AC3_MAX_CHANNELS][AC3_MAX_BLOCKS]; ///< reference blocks for EXP_REUSE
uint8_t *ref_bap [AC3_MAX_CHANNELS][AC3_MAX_BLOCKS]; ///< bit allocation pointers (bap)
int ref_bap_set; ///< indicates if ref_bap pointers have been set
/* fixed vs. float function pointers */
- void (*mdct_end)(AC3MDCTContext *mdct);
- int (*mdct_init)(AVCodecContext *avctx, AC3MDCTContext *mdct, int nbits);
+ void (*mdct_end)(struct AC3EncodeContext *s);
+ int (*mdct_init)(struct AC3EncodeContext *s);
/* fixed vs. float templated function pointers */
int (*allocate_sample_buffers)(struct AC3EncodeContext *s);
@@ -243,7 +264,7 @@ int ff_ac3_encode_init(AVCodecContext *avctx);
int ff_ac3_encode_close(AVCodecContext *avctx);
-int ff_ac3_validate_metadata(AVCodecContext *avctx);
+int ff_ac3_validate_metadata(AC3EncodeContext *s);
void ff_ac3_adjust_frame_size(AC3EncodeContext *s);
@@ -255,6 +276,8 @@ void ff_ac3_process_exponents(AC3EncodeContext *s);
int ff_ac3_compute_bit_allocation(AC3EncodeContext *s);
+void ff_ac3_group_exponents(AC3EncodeContext *s);
+
void ff_ac3_quantize_mantissas(AC3EncodeContext *s);
void ff_ac3_output_frame(AC3EncodeContext *s, unsigned char *frame);
@@ -262,13 +285,11 @@ void ff_ac3_output_frame(AC3EncodeContext *s, unsigned char *frame);
/* prototypes for functions in ac3enc_fixed.c and ac3enc_float.c */
-void ff_ac3_fixed_mdct_end(AC3MDCTContext *mdct);
-void ff_ac3_float_mdct_end(AC3MDCTContext *mdct);
+void ff_ac3_fixed_mdct_end(AC3EncodeContext *s);
+void ff_ac3_float_mdct_end(AC3EncodeContext *s);
-int ff_ac3_fixed_mdct_init(AVCodecContext *avctx, AC3MDCTContext *mdct,
- int nbits);
-int ff_ac3_float_mdct_init(AVCodecContext *avctx, AC3MDCTContext *mdct,
- int nbits);
+int ff_ac3_fixed_mdct_init(AC3EncodeContext *s);
+int ff_ac3_float_mdct_init(AC3EncodeContext *s);
/* prototypes for functions in ac3enc_template.c */
diff --git a/libavcodec/ac3enc_fixed.c b/libavcodec/ac3enc_fixed.c
index b63f3d8df1..46d971ddf7 100644
--- a/libavcodec/ac3enc_fixed.c
+++ b/libavcodec/ac3enc_fixed.c
@@ -4,20 +4,20 @@
* Copyright (c) 2006-2010 Justin Ruggles <justin.ruggles@gmail.com>
* Copyright (c) 2006-2010 Prakash Punnoor <prakash@punnoor.de>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -29,11 +29,12 @@
#define CONFIG_FFT_FLOAT 0
#undef CONFIG_AC3ENC_FLOAT
#include "ac3enc.h"
+#include "eac3enc.h"
#define AC3ENC_TYPE AC3ENC_TYPE_AC3_FIXED
#include "ac3enc_opts_template.c"
-static AVClass ac3enc_class = { "Fixed-Point AC-3 Encoder", av_default_item_name,
- ac3fixed_options, LIBAVUTIL_VERSION_INT };
+static const AVClass ac3enc_class = { "Fixed-Point AC-3 Encoder", av_default_item_name,
+ ac3fixed_options, LIBAVUTIL_VERSION_INT };
#include "ac3enc_template.c"
@@ -41,9 +42,9 @@ static AVClass ac3enc_class = { "Fixed-Point AC-3 Encoder", av_default_item_name
/**
* Finalize MDCT and free allocated memory.
*/
-av_cold void AC3_NAME(mdct_end)(AC3MDCTContext *mdct)
+av_cold void AC3_NAME(mdct_end)(AC3EncodeContext *s)
{
- ff_mdct_end(&mdct->fft);
+ ff_mdct_end(&s->mdct);
}
@@ -51,11 +52,10 @@ av_cold void AC3_NAME(mdct_end)(AC3MDCTContext *mdct)
* Initialize MDCT tables.
* @param nbits log2(MDCT size)
*/
-av_cold int AC3_NAME(mdct_init)(AVCodecContext *avctx, AC3MDCTContext *mdct,
- int nbits)
+av_cold int AC3_NAME(mdct_init)(AC3EncodeContext *s)
{
- int ret = ff_mdct_init(&mdct->fft, nbits, 0, -1.0);
- mdct->window = ff_ac3_window;
+ int ret = ff_mdct_init(&s->mdct, 9, 0, -1.0);
+ s->mdct_window = ff_ac3_window;
return ret;
}
@@ -94,7 +94,7 @@ static void scale_coefficients(AC3EncodeContext *s)
{
int blk, ch;
- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
+ for (blk = 0; blk < s->num_blocks; blk++) {
AC3Block *block = &s->blocks[blk];
for (ch = 1; ch <= s->channels; ch++) {
s->ac3dsp.ac3_rshift_int32(block->mdct_coef[ch], AC3_MAX_COEFS,
@@ -119,6 +119,22 @@ static void clip_coefficients(DSPContext *dsp, int32_t *coef, unsigned int len)
}
+/**
+ * Calculate a single coupling coordinate.
+ */
+static CoefType calc_cpl_coord(CoefSumType energy_ch, CoefSumType energy_cpl)
+{
+ if (energy_cpl <= COEF_MAX) {
+ return 1048576;
+ } else {
+ uint64_t coord = energy_ch / (energy_cpl >> 24);
+ uint32_t coord32 = FFMIN(coord, 1073741824);
+ coord32 = ff_sqrt(coord32) << 9;
+ return FFMIN(coord32, COEF_MAX);
+ }
+}
+
+
static av_cold int ac3_fixed_encode_init(AVCodecContext *avctx)
{
AC3EncodeContext *s = avctx->priv_data;
@@ -128,14 +144,13 @@ static av_cold int ac3_fixed_encode_init(AVCodecContext *avctx)
AVCodec ff_ac3_fixed_encoder = {
- "ac3_fixed",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_AC3,
- sizeof(AC3EncodeContext),
- ac3_fixed_encode_init,
- ff_ac3_fixed_encode_frame,
- ff_ac3_encode_close,
- NULL,
+ .name = "ac3_fixed",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_AC3,
+ .priv_data_size = sizeof(AC3EncodeContext),
+ .init = ac3_fixed_encode_init,
+ .encode = ff_ac3_fixed_encode_frame,
+ .close = ff_ac3_encode_close,
.sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
.long_name = NULL_IF_CONFIG_SMALL("ATSC A/52A (AC-3)"),
.priv_class = &ac3enc_class,
diff --git a/libavcodec/ac3enc_float.c b/libavcodec/ac3enc_float.c
index 99a0775be2..c87ae40e86 100644
--- a/libavcodec/ac3enc_float.c
+++ b/libavcodec/ac3enc_float.c
@@ -4,20 +4,20 @@
* Copyright (c) 2006-2010 Justin Ruggles <justin.ruggles@gmail.com>
* Copyright (c) 2006-2010 Prakash Punnoor <prakash@punnoor.de>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -35,8 +35,8 @@
#if CONFIG_AC3_ENCODER
#define AC3ENC_TYPE AC3ENC_TYPE_AC3
#include "ac3enc_opts_template.c"
-static AVClass ac3enc_class = { "AC-3 Encoder", av_default_item_name,
- ac3_options, LIBAVUTIL_VERSION_INT };
+static const AVClass ac3enc_class = { "AC-3 Encoder", av_default_item_name,
+ ac3_options, LIBAVUTIL_VERSION_INT };
#endif
#include "ac3enc_template.c"
@@ -45,10 +45,10 @@ static AVClass ac3enc_class = { "AC-3 Encoder", av_default_item_name,
/**
* Finalize MDCT and free allocated memory.
*/
-av_cold void ff_ac3_float_mdct_end(AC3MDCTContext *mdct)
+av_cold void ff_ac3_float_mdct_end(AC3EncodeContext *s)
{
- ff_mdct_end(&mdct->fft);
- av_freep(&mdct->window);
+ ff_mdct_end(&s->mdct);
+ av_freep(&s->mdct_window);
}
@@ -56,26 +56,25 @@ av_cold void ff_ac3_float_mdct_end(AC3MDCTContext *mdct)
* Initialize MDCT tables.
* @param nbits log2(MDCT size)
*/
-av_cold int ff_ac3_float_mdct_init(AVCodecContext *avctx, AC3MDCTContext *mdct,
- int nbits)
+av_cold int ff_ac3_float_mdct_init(AC3EncodeContext *s)
{
float *window;
int i, n, n2;
- n = 1 << nbits;
+ n = 1 << 9;
n2 = n >> 1;
window = av_malloc(n * sizeof(*window));
if (!window) {
- av_log(avctx, AV_LOG_ERROR, "Cannot allocate memory.\n");
+ av_log(s->avctx, AV_LOG_ERROR, "Cannot allocate memory.\n");
return AVERROR(ENOMEM);
}
ff_kbd_window_init(window, 5.0, n2);
for (i = 0; i < n2; i++)
window[n-1-i] = window[i];
- mdct->window = window;
+ s->mdct_window = window;
- return ff_mdct_init(&mdct->fft, nbits, 0, -2.0 / n);
+ return ff_mdct_init(&s->mdct, 9, 0, -2.0 / n);
}
@@ -104,10 +103,11 @@ static int normalize_samples(AC3EncodeContext *s)
*/
static void scale_coefficients(AC3EncodeContext *s)
{
- int chan_size = AC3_MAX_COEFS * AC3_MAX_BLOCKS;
- s->ac3dsp.float_to_fixed24(s->fixed_coef_buffer + chan_size,
- s->mdct_coef_buffer + chan_size,
- chan_size * s->channels);
+ int chan_size = AC3_MAX_COEFS * s->num_blocks;
+ int cpl = s->cpl_on;
+ s->ac3dsp.float_to_fixed24(s->fixed_coef_buffer + (chan_size * !cpl),
+ s->mdct_coef_buffer + (chan_size * !cpl),
+ chan_size * (s->channels + cpl));
}
static void sum_square_butterfly(AC3EncodeContext *s, float sum[4],
@@ -126,16 +126,27 @@ static void clip_coefficients(DSPContext *dsp, float *coef, unsigned int len)
}
+/**
+ * Calculate a single coupling coordinate.
+ */
+static CoefType calc_cpl_coord(CoefSumType energy_ch, CoefSumType energy_cpl)
+{
+ float coord = 0.125;
+ if (energy_cpl > 0)
+ coord *= sqrtf(energy_ch / energy_cpl);
+ return FFMIN(coord, COEF_MAX);
+}
+
+
#if CONFIG_AC3_ENCODER
AVCodec ff_ac3_encoder = {
- "ac3",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_AC3,
- sizeof(AC3EncodeContext),
- ff_ac3_encode_init,
- ff_ac3_float_encode_frame,
- ff_ac3_encode_close,
- NULL,
+ .name = "ac3",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_AC3,
+ .priv_data_size = sizeof(AC3EncodeContext),
+ .init = ff_ac3_encode_init,
+ .encode = ff_ac3_float_encode_frame,
+ .close = ff_ac3_encode_close,
.sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_FLT,AV_SAMPLE_FMT_NONE},
.long_name = NULL_IF_CONFIG_SMALL("ATSC A/52A (AC-3)"),
.priv_class = &ac3enc_class,
diff --git a/libavcodec/ac3enc_opts_template.c b/libavcodec/ac3enc_opts_template.c
index 39138a1083..acb4ab477a 100644
--- a/libavcodec/ac3enc_opts_template.c
+++ b/libavcodec/ac3enc_opts_template.c
@@ -29,56 +29,52 @@ static const AVOption ac3_options[] = {
#else /* AC3ENC_TYPE_EAC3 */
static const AVOption eac3_options[] = {
#endif
-#if AC3ENC_TYPE != AC3ENC_TYPE_EAC3
/* Metadata Options */
-{"per_frame_metadata", "Allow Changing Metadata Per-Frame", OFFSET(allow_per_frame_metadata), FF_OPT_TYPE_INT, {.dbl = 0 }, 0, 1, AC3ENC_PARAM},
-/* downmix levels */
-{"center_mixlev", "Center Mix Level", OFFSET(center_mix_level), FF_OPT_TYPE_FLOAT, {.dbl = LEVEL_MINUS_4POINT5DB }, 0.0, 1.0, AC3ENC_PARAM},
-{"surround_mixlev", "Surround Mix Level", OFFSET(surround_mix_level), FF_OPT_TYPE_FLOAT, {.dbl = LEVEL_MINUS_6DB }, 0.0, 1.0, AC3ENC_PARAM},
+{"per_frame_metadata", "Allow Changing Metadata Per-Frame", OFFSET(allow_per_frame_metadata), AV_OPT_TYPE_INT, {.dbl = 0 }, 0, 1, AC3ENC_PARAM},
+#if AC3ENC_TYPE != AC3ENC_TYPE_EAC3
+/* AC-3 downmix levels */
+{"center_mixlev", "Center Mix Level", OFFSET(center_mix_level), AV_OPT_TYPE_FLOAT, {.dbl = LEVEL_MINUS_4POINT5DB }, 0.0, 1.0, AC3ENC_PARAM},
+{"surround_mixlev", "Surround Mix Level", OFFSET(surround_mix_level), AV_OPT_TYPE_FLOAT, {.dbl = LEVEL_MINUS_6DB }, 0.0, 1.0, AC3ENC_PARAM},
+#endif
/* audio production information */
-{"mixing_level", "Mixing Level", OFFSET(mixing_level), FF_OPT_TYPE_INT, {.dbl = -1 }, -1, 111, AC3ENC_PARAM},
-{"room_type", "Room Type", OFFSET(room_type), FF_OPT_TYPE_INT, {.dbl = -1 }, -1, 2, AC3ENC_PARAM, "room_type"},
- {"notindicated", "Not Indicated (default)", 0, FF_OPT_TYPE_CONST, {.dbl = 0 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "room_type"},
- {"large", "Large Room", 0, FF_OPT_TYPE_CONST, {.dbl = 1 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "room_type"},
- {"small", "Small Room", 0, FF_OPT_TYPE_CONST, {.dbl = 2 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "room_type"},
+{"mixing_level", "Mixing Level", OFFSET(mixing_level), AV_OPT_TYPE_INT, {.dbl = AC3ENC_OPT_NONE }, AC3ENC_OPT_NONE, 111, AC3ENC_PARAM},
+{"room_type", "Room Type", OFFSET(room_type), AV_OPT_TYPE_INT, {.dbl = AC3ENC_OPT_NONE }, AC3ENC_OPT_NONE, AC3ENC_OPT_SMALL_ROOM, AC3ENC_PARAM, "room_type"},
+ {"notindicated", "Not Indicated (default)", 0, AV_OPT_TYPE_CONST, {.dbl = AC3ENC_OPT_NOT_INDICATED }, INT_MIN, INT_MAX, AC3ENC_PARAM, "room_type"},
+ {"large", "Large Room", 0, AV_OPT_TYPE_CONST, {.dbl = AC3ENC_OPT_LARGE_ROOM }, INT_MIN, INT_MAX, AC3ENC_PARAM, "room_type"},
+ {"small", "Small Room", 0, AV_OPT_TYPE_CONST, {.dbl = AC3ENC_OPT_SMALL_ROOM }, INT_MIN, INT_MAX, AC3ENC_PARAM, "room_type"},
/* other metadata options */
-{"copyright", "Copyright Bit", OFFSET(copyright), FF_OPT_TYPE_INT, {.dbl = 0 }, 0, 1, AC3ENC_PARAM},
-#endif
-{"dialnorm", "Dialogue Level (dB)", OFFSET(dialogue_level), FF_OPT_TYPE_INT, {.dbl = -31 }, -31, -1, AC3ENC_PARAM},
-#if AC3ENC_TYPE != AC3ENC_TYPE_EAC3
-{"dsur_mode", "Dolby Surround Mode", OFFSET(dolby_surround_mode), FF_OPT_TYPE_INT, {.dbl = 0 }, 0, 2, AC3ENC_PARAM, "dsur_mode"},
- {"notindicated", "Not Indicated (default)", 0, FF_OPT_TYPE_CONST, {.dbl = 0 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dsur_mode"},
- {"on", "Dolby Surround Encoded", 0, FF_OPT_TYPE_CONST, {.dbl = 1 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dsur_mode"},
- {"off", "Not Dolby Surround Encoded", 0, FF_OPT_TYPE_CONST, {.dbl = 2 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dsur_mode"},
-{"original", "Original Bit Stream", OFFSET(original), FF_OPT_TYPE_INT, {.dbl = 1 }, 0, 1, AC3ENC_PARAM},
+{"copyright", "Copyright Bit", OFFSET(copyright), AV_OPT_TYPE_INT, {.dbl = AC3ENC_OPT_NONE }, AC3ENC_OPT_NONE, 1, AC3ENC_PARAM},
+{"dialnorm", "Dialogue Level (dB)", OFFSET(dialogue_level), AV_OPT_TYPE_INT, {.dbl = -31 }, -31, -1, AC3ENC_PARAM},
+{"dsur_mode", "Dolby Surround Mode", OFFSET(dolby_surround_mode), AV_OPT_TYPE_INT, {.dbl = AC3ENC_OPT_NONE }, AC3ENC_OPT_NONE, AC3ENC_OPT_MODE_OFF, AC3ENC_PARAM, "dsur_mode"},
+ {"notindicated", "Not Indicated (default)", 0, AV_OPT_TYPE_CONST, {.dbl = AC3ENC_OPT_NOT_INDICATED }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dsur_mode"},
+ {"on", "Dolby Surround Encoded", 0, AV_OPT_TYPE_CONST, {.dbl = AC3ENC_OPT_MODE_ON }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dsur_mode"},
+ {"off", "Not Dolby Surround Encoded", 0, AV_OPT_TYPE_CONST, {.dbl = AC3ENC_OPT_MODE_OFF }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dsur_mode"},
+{"original", "Original Bit Stream", OFFSET(original), AV_OPT_TYPE_INT, {.dbl = AC3ENC_OPT_NONE }, AC3ENC_OPT_NONE, 1, AC3ENC_PARAM},
/* extended bitstream information */
-{"dmix_mode", "Preferred Stereo Downmix Mode", OFFSET(preferred_stereo_downmix), FF_OPT_TYPE_INT, {.dbl = -1 }, -1, 2, AC3ENC_PARAM, "dmix_mode"},
- {"notindicated", "Not Indicated (default)", 0, FF_OPT_TYPE_CONST, {.dbl = 0 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dmix_mode"},
- {"ltrt", "Lt/Rt Downmix Preferred", 0, FF_OPT_TYPE_CONST, {.dbl = 1 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dmix_mode"},
- {"loro", "Lo/Ro Downmix Preferred", 0, FF_OPT_TYPE_CONST, {.dbl = 2 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dmix_mode"},
-{"ltrt_cmixlev", "Lt/Rt Center Mix Level", OFFSET(ltrt_center_mix_level), FF_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, AC3ENC_PARAM},
-{"ltrt_surmixlev", "Lt/Rt Surround Mix Level", OFFSET(ltrt_surround_mix_level), FF_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, AC3ENC_PARAM},
-{"loro_cmixlev", "Lo/Ro Center Mix Level", OFFSET(loro_center_mix_level), FF_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, AC3ENC_PARAM},
-{"loro_surmixlev", "Lo/Ro Surround Mix Level", OFFSET(loro_surround_mix_level), FF_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, AC3ENC_PARAM},
-{"dsurex_mode", "Dolby Surround EX Mode", OFFSET(dolby_surround_ex_mode), FF_OPT_TYPE_INT, {.dbl = -1 }, -1, 2, AC3ENC_PARAM, "dsurex_mode"},
- {"notindicated", "Not Indicated (default)", 0, FF_OPT_TYPE_CONST, {.dbl = 0 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dsurex_mode"},
- {"on", "Dolby Surround EX Encoded", 0, FF_OPT_TYPE_CONST, {.dbl = 1 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dsurex_mode"},
- {"off", "Not Dolby Surround EX Encoded", 0, FF_OPT_TYPE_CONST, {.dbl = 2 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dsurex_mode"},
-{"dheadphone_mode", "Dolby Headphone Mode", OFFSET(dolby_headphone_mode), FF_OPT_TYPE_INT, {.dbl = -1 }, -1, 2, AC3ENC_PARAM, "dheadphone_mode"},
- {"notindicated", "Not Indicated (default)", 0, FF_OPT_TYPE_CONST, {.dbl = 0 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dheadphone_mode"},
- {"on", "Dolby Headphone Encoded", 0, FF_OPT_TYPE_CONST, {.dbl = 1 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dheadphone_mode"},
- {"off", "Not Dolby Headphone Encoded", 0, FF_OPT_TYPE_CONST, {.dbl = 2 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dheadphone_mode"},
-{"ad_conv_type", "A/D Converter Type", OFFSET(ad_converter_type), FF_OPT_TYPE_INT, {.dbl = -1 }, -1, 1, AC3ENC_PARAM, "ad_conv_type"},
- {"standard", "Standard (default)", 0, FF_OPT_TYPE_CONST, {.dbl = 0 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "ad_conv_type"},
- {"hdcd", "HDCD", 0, FF_OPT_TYPE_CONST, {.dbl = 1 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "ad_conv_type"},
-#endif
+{"dmix_mode", "Preferred Stereo Downmix Mode", OFFSET(preferred_stereo_downmix), AV_OPT_TYPE_INT, {.dbl = AC3ENC_OPT_NONE }, AC3ENC_OPT_NONE, AC3ENC_OPT_DOWNMIX_LORO, AC3ENC_PARAM, "dmix_mode"},
+ {"notindicated", "Not Indicated (default)", 0, AV_OPT_TYPE_CONST, {.dbl = AC3ENC_OPT_NOT_INDICATED }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dmix_mode"},
+ {"ltrt", "Lt/Rt Downmix Preferred", 0, AV_OPT_TYPE_CONST, {.dbl = AC3ENC_OPT_DOWNMIX_LTRT }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dmix_mode"},
+ {"loro", "Lo/Ro Downmix Preferred", 0, AV_OPT_TYPE_CONST, {.dbl = AC3ENC_OPT_DOWNMIX_LORO }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dmix_mode"},
+{"ltrt_cmixlev", "Lt/Rt Center Mix Level", OFFSET(ltrt_center_mix_level), AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, AC3ENC_PARAM},
+{"ltrt_surmixlev", "Lt/Rt Surround Mix Level", OFFSET(ltrt_surround_mix_level), AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, AC3ENC_PARAM},
+{"loro_cmixlev", "Lo/Ro Center Mix Level", OFFSET(loro_center_mix_level), AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, AC3ENC_PARAM},
+{"loro_surmixlev", "Lo/Ro Surround Mix Level", OFFSET(loro_surround_mix_level), AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, AC3ENC_PARAM},
+{"dsurex_mode", "Dolby Surround EX Mode", OFFSET(dolby_surround_ex_mode), AV_OPT_TYPE_INT, {.dbl = AC3ENC_OPT_NONE }, AC3ENC_OPT_NONE, AC3ENC_OPT_MODE_OFF, AC3ENC_PARAM, "dsurex_mode"},
+ {"notindicated", "Not Indicated (default)", 0, AV_OPT_TYPE_CONST, {.dbl = AC3ENC_OPT_NOT_INDICATED }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dsurex_mode"},
+ {"on", "Dolby Surround EX Encoded", 0, AV_OPT_TYPE_CONST, {.dbl = AC3ENC_OPT_MODE_ON }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dsurex_mode"},
+ {"off", "Not Dolby Surround EX Encoded", 0, AV_OPT_TYPE_CONST, {.dbl = AC3ENC_OPT_MODE_OFF }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dsurex_mode"},
+{"dheadphone_mode", "Dolby Headphone Mode", OFFSET(dolby_headphone_mode), AV_OPT_TYPE_INT, {.dbl = AC3ENC_OPT_NONE }, AC3ENC_OPT_NONE, AC3ENC_OPT_MODE_OFF, AC3ENC_PARAM, "dheadphone_mode"},
+ {"notindicated", "Not Indicated (default)", 0, AV_OPT_TYPE_CONST, {.dbl = AC3ENC_OPT_NOT_INDICATED }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dheadphone_mode"},
+ {"on", "Dolby Headphone Encoded", 0, AV_OPT_TYPE_CONST, {.dbl = AC3ENC_OPT_MODE_ON }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dheadphone_mode"},
+ {"off", "Not Dolby Headphone Encoded", 0, AV_OPT_TYPE_CONST, {.dbl = AC3ENC_OPT_MODE_OFF }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dheadphone_mode"},
+{"ad_conv_type", "A/D Converter Type", OFFSET(ad_converter_type), AV_OPT_TYPE_INT, {.dbl = AC3ENC_OPT_NONE }, AC3ENC_OPT_NONE, AC3ENC_OPT_ADCONV_HDCD, AC3ENC_PARAM, "ad_conv_type"},
+ {"standard", "Standard (default)", 0, AV_OPT_TYPE_CONST, {.dbl = AC3ENC_OPT_ADCONV_STANDARD }, INT_MIN, INT_MAX, AC3ENC_PARAM, "ad_conv_type"},
+ {"hdcd", "HDCD", 0, AV_OPT_TYPE_CONST, {.dbl = AC3ENC_OPT_ADCONV_HDCD }, INT_MIN, INT_MAX, AC3ENC_PARAM, "ad_conv_type"},
/* Other Encoding Options */
-{"stereo_rematrixing", "Stereo Rematrixing", OFFSET(stereo_rematrixing), FF_OPT_TYPE_INT, {.dbl = 1 }, 0, 1, AC3ENC_PARAM},
-#if AC3ENC_TYPE != AC3ENC_TYPE_AC3_FIXED
-{"channel_coupling", "Channel Coupling", OFFSET(channel_coupling), FF_OPT_TYPE_INT, {.dbl = 1 }, 0, 1, AC3ENC_PARAM, "channel_coupling"},
- {"auto", "Selected by the Encoder", 0, FF_OPT_TYPE_CONST, {.dbl = -1 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "channel_coupling"},
-{"cpl_start_band", "Coupling Start Band", OFFSET(cpl_start), FF_OPT_TYPE_INT, {.dbl = -1 }, -1, 15, AC3ENC_PARAM, "cpl_start_band"},
- {"auto", "Selected by the Encoder", 0, FF_OPT_TYPE_CONST, {.dbl = -1 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "cpl_start_band"},
-#endif
+{"stereo_rematrixing", "Stereo Rematrixing", OFFSET(stereo_rematrixing), AV_OPT_TYPE_INT, {.dbl = AC3ENC_OPT_ON }, AC3ENC_OPT_OFF, AC3ENC_OPT_ON, AC3ENC_PARAM},
+{"channel_coupling", "Channel Coupling", OFFSET(channel_coupling), AV_OPT_TYPE_INT, {.dbl = AC3ENC_OPT_AUTO }, AC3ENC_OPT_AUTO, AC3ENC_OPT_ON, AC3ENC_PARAM, "channel_coupling"},
+ {"auto", "Selected by the Encoder", 0, AV_OPT_TYPE_CONST, {.dbl = AC3ENC_OPT_AUTO }, INT_MIN, INT_MAX, AC3ENC_PARAM, "channel_coupling"},
+{"cpl_start_band", "Coupling Start Band", OFFSET(cpl_start), AV_OPT_TYPE_INT, {.dbl = AC3ENC_OPT_AUTO }, AC3ENC_OPT_AUTO, 15, AC3ENC_PARAM, "cpl_start_band"},
+ {"auto", "Selected by the Encoder", 0, AV_OPT_TYPE_CONST, {.dbl = AC3ENC_OPT_AUTO }, INT_MIN, INT_MAX, AC3ENC_PARAM, "cpl_start_band"},
{NULL}
};
diff --git a/libavcodec/ac3enc_template.c b/libavcodec/ac3enc_template.c
index 1ee1b617db..85513b1cdd 100644
--- a/libavcodec/ac3enc_template.c
+++ b/libavcodec/ac3enc_template.c
@@ -28,8 +28,6 @@
#include <stdint.h>
-#include "ac3enc.h"
-
/* prototypes for static functions in ac3enc_fixed.c and ac3enc_float.c */
@@ -43,6 +41,8 @@ static int normalize_samples(AC3EncodeContext *s);
static void clip_coefficients(DSPContext *dsp, CoefType *coef, unsigned int len);
+static CoefType calc_cpl_coord(CoefSumType energy_ch, CoefSumType energy_cpl);
+
static void sum_square_butterfly(AC3EncodeContext *s, CoefSumType sum[4],
const CoefType *coef0, const CoefType *coef1,
int len);
@@ -82,13 +82,13 @@ static void deinterleave_input_samples(AC3EncodeContext *s,
int sinc;
/* copy last 256 samples of previous frame to the start of the current frame */
- memcpy(&s->planar_samples[ch][0], &s->planar_samples[ch][AC3_FRAME_SIZE],
+ memcpy(&s->planar_samples[ch][0], &s->planar_samples[ch][AC3_BLOCK_SIZE * s->num_blocks],
AC3_BLOCK_SIZE * sizeof(s->planar_samples[0][0]));
/* deinterleave */
sinc = s->channels;
sptr = samples + s->channel_map[ch];
- for (i = AC3_BLOCK_SIZE; i < AC3_FRAME_SIZE+AC3_BLOCK_SIZE; i++) {
+ for (i = AC3_BLOCK_SIZE; i < AC3_BLOCK_SIZE * (s->num_blocks + 1); i++) {
s->planar_samples[ch][i] = *sptr;
sptr += sinc;
}
@@ -106,54 +106,42 @@ static void apply_mdct(AC3EncodeContext *s)
int blk, ch;
for (ch = 0; ch < s->channels; ch++) {
- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
+ for (blk = 0; blk < s->num_blocks; blk++) {
AC3Block *block = &s->blocks[blk];
const SampleType *input_samples = &s->planar_samples[ch][blk * AC3_BLOCK_SIZE];
apply_window(&s->dsp, s->windowed_samples, input_samples,
- s->mdct->window, AC3_WINDOW_SIZE);
+ s->mdct_window, AC3_WINDOW_SIZE);
if (s->fixed_point)
block->coeff_shift[ch+1] = normalize_samples(s);
- s->mdct->fft.mdct_calcw(&s->mdct->fft, block->mdct_coef[ch+1],
- s->windowed_samples);
+ s->mdct.mdct_calcw(&s->mdct, block->mdct_coef[ch+1],
+ s->windowed_samples);
}
}
}
/**
- * Calculate a single coupling coordinate.
- */
-static inline float calc_cpl_coord(float energy_ch, float energy_cpl)
-{
- float coord = 0.125;
- if (energy_cpl > 0)
- coord *= sqrtf(energy_ch / energy_cpl);
- return coord;
-}
-
-
-/**
* Calculate coupling channel and coupling coordinates.
- * TODO: Currently this is only used for the floating-point encoder. I was
- * able to make it work for the fixed-point encoder, but quality was
- * generally lower in most cases than not using coupling. If a more
- * adaptive coupling strategy were to be implemented it might be useful
- * at that time to use coupling for the fixed-point encoder as well.
*/
static void apply_channel_coupling(AC3EncodeContext *s)
{
+ LOCAL_ALIGNED_16(CoefType, cpl_coords, [AC3_MAX_BLOCKS], [AC3_MAX_CHANNELS][16]);
#if CONFIG_AC3ENC_FLOAT
- LOCAL_ALIGNED_16(float, cpl_coords, [AC3_MAX_BLOCKS], [AC3_MAX_CHANNELS][16]);
LOCAL_ALIGNED_16(int32_t, fixed_cpl_coords, [AC3_MAX_BLOCKS], [AC3_MAX_CHANNELS][16]);
+#else
+ int32_t (*fixed_cpl_coords)[AC3_MAX_CHANNELS][16] = cpl_coords;
+#endif
int blk, ch, bnd, i, j;
CoefSumType energy[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][16] = {{{0}}};
int cpl_start, num_cpl_coefs;
memset(cpl_coords, 0, AC3_MAX_BLOCKS * sizeof(*cpl_coords));
- memset(fixed_cpl_coords, 0, AC3_MAX_BLOCKS * sizeof(*fixed_cpl_coords));
+#if CONFIG_AC3ENC_FLOAT
+ memset(fixed_cpl_coords, 0, AC3_MAX_BLOCKS * sizeof(*cpl_coords));
+#endif
/* align start to 16-byte boundary. align length to multiple of 32.
note: coupling start bin % 4 will always be 1 */
@@ -162,7 +150,7 @@ static void apply_channel_coupling(AC3EncodeContext *s)
cpl_start = FFMIN(256, cpl_start + num_cpl_coefs) - num_cpl_coefs;
/* calculate coupling channel from fbw channels */
- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
+ for (blk = 0; blk < s->num_blocks; blk++) {
AC3Block *block = &s->blocks[blk];
CoefType *cpl_coef = &block->mdct_coef[CPL_CH][cpl_start];
if (!block->cpl_in_use)
@@ -178,10 +166,6 @@ static void apply_channel_coupling(AC3EncodeContext *s)
/* coefficients must be clipped in order to be encoded */
clip_coefficients(&s->dsp, cpl_coef, num_cpl_coefs);
-
- /* scale coupling coefficients from float to 24-bit fixed-point */
- s->ac3dsp.float_to_fixed24(&block->fixed_coef[CPL_CH][cpl_start],
- cpl_coef, num_cpl_coefs);
}
/* calculate energy in each band in coupling channel and each fbw channel */
@@ -191,7 +175,7 @@ static void apply_channel_coupling(AC3EncodeContext *s)
while (i < s->cpl_end_freq) {
int band_size = s->cpl_band_sizes[bnd];
for (ch = CPL_CH; ch <= s->fbw_channels; ch++) {
- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
+ for (blk = 0; blk < s->num_blocks; blk++) {
AC3Block *block = &s->blocks[blk];
if (!block->cpl_in_use || (ch > CPL_CH && !block->channel_in_cpl[ch]))
continue;
@@ -205,68 +189,64 @@ static void apply_channel_coupling(AC3EncodeContext *s)
bnd++;
}
+ /* calculate coupling coordinates for all blocks for all channels */
+ for (blk = 0; blk < s->num_blocks; blk++) {
+ AC3Block *block = &s->blocks[blk];
+ if (!block->cpl_in_use)
+ continue;
+ for (ch = 1; ch <= s->fbw_channels; ch++) {
+ if (!block->channel_in_cpl[ch])
+ continue;
+ for (bnd = 0; bnd < s->num_cpl_bands; bnd++) {
+ cpl_coords[blk][ch][bnd] = calc_cpl_coord(energy[blk][ch][bnd],
+ energy[blk][CPL_CH][bnd]);
+ }
+ }
+ }
+
/* determine which blocks to send new coupling coordinates for */
- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
+ for (blk = 0; blk < s->num_blocks; blk++) {
AC3Block *block = &s->blocks[blk];
AC3Block *block0 = blk ? &s->blocks[blk-1] : NULL;
- int new_coords = 0;
- CoefSumType coord_diff[AC3_MAX_CHANNELS] = {0,};
-
- if (block->cpl_in_use) {
- /* calculate coupling coordinates for all blocks and calculate the
- average difference between coordinates in successive blocks */
- for (ch = 1; ch <= s->fbw_channels; ch++) {
- if (!block->channel_in_cpl[ch])
- continue;
- for (bnd = 0; bnd < s->num_cpl_bands; bnd++) {
- cpl_coords[blk][ch][bnd] = calc_cpl_coord(energy[blk][ch][bnd],
- energy[blk][CPL_CH][bnd]);
- if (blk > 0 && block0->cpl_in_use &&
- block0->channel_in_cpl[ch]) {
- coord_diff[ch] += fabs(cpl_coords[blk-1][ch][bnd] -
- cpl_coords[blk ][ch][bnd]);
- }
- }
- coord_diff[ch] /= s->num_cpl_bands;
- }
+ memset(block->new_cpl_coords, 0, sizeof(block->new_cpl_coords));
+ if (block->cpl_in_use) {
/* send new coordinates if this is the first block, if previous
* block did not use coupling but this block does, the channels
* using coupling has changed from the previous block, or the
* coordinate difference from the last block for any channel is
* greater than a threshold value. */
- if (blk == 0) {
- new_coords = 1;
- } else if (!block0->cpl_in_use) {
- new_coords = 1;
+ if (blk == 0 || !block0->cpl_in_use) {
+ for (ch = 1; ch <= s->fbw_channels; ch++)
+ block->new_cpl_coords[ch] = 1;
} else {
for (ch = 1; ch <= s->fbw_channels; ch++) {
- if (block->channel_in_cpl[ch] && !block0->channel_in_cpl[ch]) {
- new_coords = 1;
- break;
- }
- }
- if (!new_coords) {
- for (ch = 1; ch <= s->fbw_channels; ch++) {
- if (block->channel_in_cpl[ch] && coord_diff[ch] > 0.04) {
- new_coords = 1;
- break;
+ if (!block->channel_in_cpl[ch])
+ continue;
+ if (!block0->channel_in_cpl[ch]) {
+ block->new_cpl_coords[ch] = 1;
+ } else {
+ CoefSumType coord_diff = 0;
+ for (bnd = 0; bnd < s->num_cpl_bands; bnd++) {
+ coord_diff += FFABS(cpl_coords[blk-1][ch][bnd] -
+ cpl_coords[blk ][ch][bnd]);
}
+ coord_diff /= s->num_cpl_bands;
+ if (coord_diff > NEW_CPL_COORD_THRESHOLD)
+ block->new_cpl_coords[ch] = 1;
}
}
}
}
- block->new_cpl_coords = new_coords;
}
/* calculate final coupling coordinates, taking into account reusing of
coordinates in successive blocks */
for (bnd = 0; bnd < s->num_cpl_bands; bnd++) {
blk = 0;
- while (blk < AC3_MAX_BLOCKS) {
- int blk1;
- CoefSumType energy_cpl;
+ while (blk < s->num_blocks) {
+ int av_uninit(blk1);
AC3Block *block = &s->blocks[blk];
if (!block->cpl_in_use) {
@@ -274,23 +254,18 @@ static void apply_channel_coupling(AC3EncodeContext *s)
continue;
}
- energy_cpl = energy[blk][CPL_CH][bnd];
- blk1 = blk+1;
- while (!s->blocks[blk1].new_cpl_coords && blk1 < AC3_MAX_BLOCKS) {
- if (s->blocks[blk1].cpl_in_use)
- energy_cpl += energy[blk1][CPL_CH][bnd];
- blk1++;
- }
-
for (ch = 1; ch <= s->fbw_channels; ch++) {
- CoefType energy_ch;
+ CoefSumType energy_ch, energy_cpl;
if (!block->channel_in_cpl[ch])
continue;
+ energy_cpl = energy[blk][CPL_CH][bnd];
energy_ch = energy[blk][ch][bnd];
blk1 = blk+1;
- while (!s->blocks[blk1].new_cpl_coords && blk1 < AC3_MAX_BLOCKS) {
- if (s->blocks[blk1].cpl_in_use)
+ while (!s->blocks[blk1].new_cpl_coords[ch] && blk1 < s->num_blocks) {
+ if (s->blocks[blk1].cpl_in_use) {
+ energy_cpl += energy[blk1][CPL_CH][bnd];
energy_ch += energy[blk1][ch][bnd];
+ }
blk1++;
}
cpl_coords[blk][ch][bnd] = calc_cpl_coord(energy_ch, energy_cpl);
@@ -300,15 +275,16 @@ static void apply_channel_coupling(AC3EncodeContext *s)
}
/* calculate exponents/mantissas for coupling coordinates */
- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
+ for (blk = 0; blk < s->num_blocks; blk++) {
AC3Block *block = &s->blocks[blk];
- if (!block->cpl_in_use || !block->new_cpl_coords)
+ if (!block->cpl_in_use)
continue;
- clip_coefficients(&s->dsp, cpl_coords[blk][1], s->fbw_channels * 16);
+#if CONFIG_AC3ENC_FLOAT
s->ac3dsp.float_to_fixed24(fixed_cpl_coords[blk][1],
cpl_coords[blk][1],
s->fbw_channels * 16);
+#endif
s->ac3dsp.extract_exponents(block->cpl_coord_exp[1],
fixed_cpl_coords[blk][1],
s->fbw_channels * 16);
@@ -316,6 +292,9 @@ static void apply_channel_coupling(AC3EncodeContext *s)
for (ch = 1; ch <= s->fbw_channels; ch++) {
int bnd, min_exp, max_exp, master_exp;
+ if (!block->new_cpl_coords[ch])
+ continue;
+
/* determine master exponent */
min_exp = max_exp = block->cpl_coord_exp[ch][0];
for (bnd = 1; bnd < s->num_cpl_bands; bnd++) {
@@ -349,7 +328,6 @@ static void apply_channel_coupling(AC3EncodeContext *s)
if (CONFIG_EAC3_ENCODER && s->eac3)
ff_eac3_set_cpl_states(s);
-#endif /* CONFIG_AC3ENC_FLOAT */
}
@@ -365,15 +343,10 @@ static void compute_rematrixing_strategy(AC3EncodeContext *s)
if (s->channel_mode != AC3_CHMODE_STEREO)
return;
- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
+ for (blk = 0; blk < s->num_blocks; blk++) {
block = &s->blocks[blk];
block->new_rematrixing_strategy = !blk;
- if (!s->rematrixing_enabled) {
- block0 = block;
- continue;
- }
-
block->num_rematrixing_bands = 4;
if (block->cpl_in_use) {
block->num_rematrixing_bands -= (s->start_freq[CPL_CH] <= 61);
@@ -383,6 +356,11 @@ static void compute_rematrixing_strategy(AC3EncodeContext *s)
}
nb_coefs = FFMIN(block->end_freq[1], block->end_freq[2]);
+ if (!s->rematrixing_enabled) {
+ block0 = block;
+ continue;
+ }
+
for (bnd = 0; bnd < block->num_rematrixing_bands; bnd++) {
/* calculate calculate sum of squared coeffs for one band in one block */
int start = ff_ac3_rematrix_band_tab[bnd];
@@ -418,8 +396,8 @@ int AC3_NAME(encode_frame)(AVCodecContext *avctx, unsigned char *frame,
const SampleType *samples = data;
int ret;
- if (!s->eac3 && s->options.allow_per_frame_metadata) {
- ret = ff_ac3_validate_metadata(avctx);
+ if (s->options.allow_per_frame_metadata) {
+ ret = ff_ac3_validate_metadata(s);
if (ret)
return ret;
}
@@ -435,7 +413,7 @@ int AC3_NAME(encode_frame)(AVCodecContext *avctx, unsigned char *frame,
scale_coefficients(s);
clip_coefficients(&s->dsp, s->blocks[0].mdct_coef[1],
- AC3_MAX_COEFS * AC3_MAX_BLOCKS * s->channels);
+ AC3_MAX_COEFS * s->num_blocks * s->channels);
s->cpl_on = s->cpl_enabled;
ff_ac3_compute_coupling_strategy(s);
@@ -458,6 +436,8 @@ int AC3_NAME(encode_frame)(AVCodecContext *avctx, unsigned char *frame,
return ret;
}
+ ff_ac3_group_exponents(s);
+
ff_ac3_quantize_mantissas(s);
ff_ac3_output_frame(s, frame);
diff --git a/libavcodec/ac3tab.c b/libavcodec/ac3tab.c
index 7df3d828fb..3b3e715655 100644
--- a/libavcodec/ac3tab.c
+++ b/libavcodec/ac3tab.c
@@ -2,20 +2,20 @@
* AC-3 tables
* copyright (c) 2001 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/ac3tab.h b/libavcodec/ac3tab.h
index e5cd368bb7..aa13c8f6e5 100644
--- a/libavcodec/ac3tab.h
+++ b/libavcodec/ac3tab.h
@@ -2,20 +2,20 @@
* AC-3 tables
* Copyright (c) 2000, 2001, 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/acelp_filters.c b/libavcodec/acelp_filters.c
index 04f6d4a5f9..31f0e86f5b 100644
--- a/libavcodec/acelp_filters.c
+++ b/libavcodec/acelp_filters.c
@@ -3,20 +3,20 @@
*
* Copyright (c) 2008 Vladimir Voroshilov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/acelp_filters.h b/libavcodec/acelp_filters.h
index b8715d266f..0b1ccf4e71 100644
--- a/libavcodec/acelp_filters.h
+++ b/libavcodec/acelp_filters.h
@@ -3,20 +3,20 @@
*
* Copyright (c) 2008 Vladimir Voroshilov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/acelp_pitch_delay.c b/libavcodec/acelp_pitch_delay.c
index 2b791b5aa3..66d65a6903 100644
--- a/libavcodec/acelp_pitch_delay.c
+++ b/libavcodec/acelp_pitch_delay.c
@@ -3,20 +3,20 @@
*
* Copyright (c) 2008 Vladimir Voroshilov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/acelp_pitch_delay.h b/libavcodec/acelp_pitch_delay.h
index e5410bba7f..72977f1f49 100644
--- a/libavcodec/acelp_pitch_delay.h
+++ b/libavcodec/acelp_pitch_delay.h
@@ -3,20 +3,20 @@
*
* Copyright (c) 2008 Vladimir Voroshilov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/acelp_vectors.c b/libavcodec/acelp_vectors.c
index 25a6ff27df..a44ab8cfe6 100644
--- a/libavcodec/acelp_vectors.c
+++ b/libavcodec/acelp_vectors.c
@@ -3,20 +3,20 @@
*
* Copyright (c) 2008 Vladimir Voroshilov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/acelp_vectors.h b/libavcodec/acelp_vectors.h
index 07d1000d3f..f3bc781446 100644
--- a/libavcodec/acelp_vectors.h
+++ b/libavcodec/acelp_vectors.h
@@ -3,20 +3,20 @@
*
* Copyright (c) 2008 Vladimir Voroshilov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c
index 70a5360ce8..c88db5ca15 100644
--- a/libavcodec/adpcm.c
+++ b/libavcodec/adpcm.c
@@ -1,31 +1,32 @@
/*
- * ADPCM codecs
* Copyright (c) 2001-2003 The ffmpeg Project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avcodec.h"
#include "get_bits.h"
#include "put_bits.h"
#include "bytestream.h"
+#include "adpcm.h"
+#include "adpcm_data.h"
/**
* @file
- * ADPCM codecs.
+ * ADPCM decoders
* First version by Francois Revol (revol@free.fr)
* Fringe ADPCM codecs (e.g., DK3, DK4, Westwood)
* by Mike Melanson (melanson@pcisys.net)
@@ -41,73 +42,35 @@
* Features and limitations:
*
* Reference documents:
- * http://www.pcisys.net/~melanson/codecs/simpleaudio.html
- * http://www.geocities.com/SiliconValley/8682/aud3.txt
- * http://openquicktime.sourceforge.net/plugins.htm
- * XAnim sources (xa_codec.c) http://www.rasnaimaging.com/people/lapus/download.html
- * http://www.cs.ucla.edu/~leec/mediabench/applications.html
- * SoX source code http://home.sprynet.com/~cbagwell/sox.html
+ * http://wiki.multimedia.cx/index.php?title=Category:ADPCM_Audio_Codecs
+ * http://www.pcisys.net/~melanson/codecs/simpleaudio.html [dead]
+ * http://www.geocities.com/SiliconValley/8682/aud3.txt [dead]
+ * http://openquicktime.sourceforge.net/
+ * XAnim sources (xa_codec.c) http://xanim.polter.net/
+ * http://www.cs.ucla.edu/~leec/mediabench/applications.html [dead]
+ * SoX source code http://sox.sourceforge.net/
*
* CD-ROM XA:
- * http://ku-www.ss.titech.ac.jp/~yatsushi/xaadpcm.html
- * vagpack & depack http://homepages.compuserve.de/bITmASTER32/psx-index.html
+ * http://ku-www.ss.titech.ac.jp/~yatsushi/xaadpcm.html [dead]
+ * vagpack & depack http://homepages.compuserve.de/bITmASTER32/psx-index.html [dead]
* readstr http://www.geocities.co.jp/Playtown/2004/
*/
-#define BLKSIZE 1024
-
-/* step_table[] and index_table[] are from the ADPCM reference source */
-/* This is the index table: */
-static const int index_table[16] = {
- -1, -1, -1, -1, 2, 4, 6, 8,
- -1, -1, -1, -1, 2, 4, 6, 8,
-};
-
-/**
- * This is the step table. Note that many programs use slight deviations from
- * this table, but such deviations are negligible:
- */
-static const int step_table[89] = {
- 7, 8, 9, 10, 11, 12, 13, 14, 16, 17,
- 19, 21, 23, 25, 28, 31, 34, 37, 41, 45,
- 50, 55, 60, 66, 73, 80, 88, 97, 107, 118,
- 130, 143, 157, 173, 190, 209, 230, 253, 279, 307,
- 337, 371, 408, 449, 494, 544, 598, 658, 724, 796,
- 876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066,
- 2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358,
- 5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899,
- 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767
-};
-
-/* These are for MS-ADPCM */
-/* AdaptationTable[], AdaptCoeff1[], and AdaptCoeff2[] are from libsndfile */
-static const int AdaptationTable[] = {
- 230, 230, 230, 230, 307, 409, 512, 614,
- 768, 614, 512, 409, 307, 230, 230, 230
-};
-
-/** Divided by 4 to fit in 8-bit integers */
-static const uint8_t AdaptCoeff1[] = {
- 64, 128, 0, 48, 60, 115, 98
-};
-
-/** Divided by 4 to fit in 8-bit integers */
-static const int8_t AdaptCoeff2[] = {
- 0, -64, 0, 16, 0, -52, -58
-};
-
/* These are for CD-ROM XA ADPCM */
static const int xa_adpcm_table[5][2] = {
- { 0, 0 },
- { 60, 0 },
- { 115, -52 },
- { 98, -55 },
- { 122, -60 }
+ { 0, 0 },
+ { 60, 0 },
+ { 115, -52 },
+ { 98, -55 },
+ { 122, -60 }
};
static const int ea_adpcm_table[] = {
- 0, 240, 460, 392, 0, 0, -208, -220, 0, 1,
- 3, 4, 7, 8, 10, 11, 0, -1, -3, -4
+ 0, 240, 460, 392,
+ 0, 0, -208, -220,
+ 0, 1, 3, 4,
+ 7, 8, 10, 11,
+ 0, -1, -3, -4
};
// padded to zero where table size is less then 16
@@ -118,638 +81,22 @@ static const int swf_index_tables[4][16] = {
/*5*/ { -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 4, 6, 8, 10, 13, 16 }
};
-static const int yamaha_indexscale[] = {
- 230, 230, 230, 230, 307, 409, 512, 614,
- 230, 230, 230, 230, 307, 409, 512, 614
-};
-
-static const int yamaha_difflookup[] = {
- 1, 3, 5, 7, 9, 11, 13, 15,
- -1, -3, -5, -7, -9, -11, -13, -15
-};
-
/* end of tables */
-typedef struct ADPCMChannelStatus {
- int predictor;
- short int step_index;
- int step;
- /* for encoding */
- int prev_sample;
-
- /* MS version */
- short sample1;
- short sample2;
- int coeff1;
- int coeff2;
- int idelta;
-} ADPCMChannelStatus;
-
-typedef struct TrellisPath {
- int nibble;
- int prev;
-} TrellisPath;
-
-typedef struct TrellisNode {
- uint32_t ssd;
- int path;
- int sample1;
- int sample2;
- int step;
-} TrellisNode;
-
-typedef struct ADPCMContext {
+typedef struct ADPCMDecodeContext {
ADPCMChannelStatus status[6];
- TrellisPath *paths;
- TrellisNode *node_buf;
- TrellisNode **nodep_buf;
- uint8_t *trellis_hash;
-} ADPCMContext;
-
-#define FREEZE_INTERVAL 128
-
-/* XXX: implement encoding */
-
-#if CONFIG_ENCODERS
-static av_cold int adpcm_encode_init(AVCodecContext *avctx)
-{
- ADPCMContext *s = avctx->priv_data;
- uint8_t *extradata;
- int i;
- if (avctx->channels > 2)
- return -1; /* only stereo or mono =) */
-
- if(avctx->trellis && (unsigned)avctx->trellis > 16U){
- av_log(avctx, AV_LOG_ERROR, "invalid trellis size\n");
- return -1;
- }
-
- if (avctx->trellis) {
- int frontier = 1 << avctx->trellis;
- int max_paths = frontier * FREEZE_INTERVAL;
- FF_ALLOC_OR_GOTO(avctx, s->paths, max_paths * sizeof(*s->paths), error);
- FF_ALLOC_OR_GOTO(avctx, s->node_buf, 2 * frontier * sizeof(*s->node_buf), error);
- FF_ALLOC_OR_GOTO(avctx, s->nodep_buf, 2 * frontier * sizeof(*s->nodep_buf), error);
- FF_ALLOC_OR_GOTO(avctx, s->trellis_hash, 65536 * sizeof(*s->trellis_hash), error);
- }
-
- switch(avctx->codec->id) {
- case CODEC_ID_ADPCM_IMA_WAV:
- avctx->frame_size = (BLKSIZE - 4 * avctx->channels) * 8 / (4 * avctx->channels) + 1; /* each 16 bits sample gives one nibble */
- /* and we have 4 bytes per channel overhead */
- avctx->block_align = BLKSIZE;
- /* seems frame_size isn't taken into account... have to buffer the samples :-( */
- break;
- case CODEC_ID_ADPCM_IMA_QT:
- avctx->frame_size = 64;
- avctx->block_align = 34 * avctx->channels;
- break;
- case CODEC_ID_ADPCM_MS:
- avctx->frame_size = (BLKSIZE - 7 * avctx->channels) * 2 / avctx->channels + 2; /* each 16 bits sample gives one nibble */
- /* and we have 7 bytes per channel overhead */
- avctx->block_align = BLKSIZE;
- avctx->extradata_size = 32;
- extradata = avctx->extradata = av_malloc(avctx->extradata_size);
- if (!extradata)
- return AVERROR(ENOMEM);
- bytestream_put_le16(&extradata, avctx->frame_size);
- bytestream_put_le16(&extradata, 7); /* wNumCoef */
- for (i = 0; i < 7; i++) {
- bytestream_put_le16(&extradata, AdaptCoeff1[i] * 4);
- bytestream_put_le16(&extradata, AdaptCoeff2[i] * 4);
- }
- break;
- case CODEC_ID_ADPCM_YAMAHA:
- avctx->frame_size = BLKSIZE * avctx->channels;
- avctx->block_align = BLKSIZE;
- break;
- case CODEC_ID_ADPCM_SWF:
- if (avctx->sample_rate != 11025 &&
- avctx->sample_rate != 22050 &&
- avctx->sample_rate != 44100) {
- av_log(avctx, AV_LOG_ERROR, "Sample rate must be 11025, 22050 or 44100\n");
- goto error;
- }
- avctx->frame_size = 512 * (avctx->sample_rate / 11025);
- break;
- default:
- goto error;
- }
-
- avctx->coded_frame= avcodec_alloc_frame();
- avctx->coded_frame->key_frame= 1;
-
- return 0;
-error:
- av_freep(&s->paths);
- av_freep(&s->node_buf);
- av_freep(&s->nodep_buf);
- av_freep(&s->trellis_hash);
- return -1;
-}
-
-static av_cold int adpcm_encode_close(AVCodecContext *avctx)
-{
- ADPCMContext *s = avctx->priv_data;
- av_freep(&avctx->coded_frame);
- av_freep(&s->paths);
- av_freep(&s->node_buf);
- av_freep(&s->nodep_buf);
- av_freep(&s->trellis_hash);
-
- return 0;
-}
-
-
-static inline unsigned char adpcm_ima_compress_sample(ADPCMChannelStatus *c, short sample)
-{
- int delta = sample - c->prev_sample;
- int nibble = FFMIN(7, abs(delta)*4/step_table[c->step_index]) + (delta<0)*8;
- c->prev_sample += ((step_table[c->step_index] * yamaha_difflookup[nibble]) / 8);
- c->prev_sample = av_clip_int16(c->prev_sample);
- c->step_index = av_clip(c->step_index + index_table[nibble], 0, 88);
- return nibble;
-}
-
-static inline unsigned char adpcm_ms_compress_sample(ADPCMChannelStatus *c, short sample)
-{
- int predictor, nibble, bias;
-
- predictor = (((c->sample1) * (c->coeff1)) + ((c->sample2) * (c->coeff2))) / 64;
-
- nibble= sample - predictor;
- if(nibble>=0) bias= c->idelta/2;
- else bias=-c->idelta/2;
-
- nibble= (nibble + bias) / c->idelta;
- nibble= av_clip(nibble, -8, 7)&0x0F;
-
- predictor += (signed)((nibble & 0x08)?(nibble - 0x10):(nibble)) * c->idelta;
-
- c->sample2 = c->sample1;
- c->sample1 = av_clip_int16(predictor);
-
- c->idelta = (AdaptationTable[(int)nibble] * c->idelta) >> 8;
- if (c->idelta < 16) c->idelta = 16;
-
- return nibble;
-}
-
-static inline unsigned char adpcm_yamaha_compress_sample(ADPCMChannelStatus *c, short sample)
-{
- int nibble, delta;
-
- if(!c->step) {
- c->predictor = 0;
- c->step = 127;
- }
-
- delta = sample - c->predictor;
-
- nibble = FFMIN(7, abs(delta)*4/c->step) + (delta<0)*8;
-
- c->predictor += ((c->step * yamaha_difflookup[nibble]) / 8);
- c->predictor = av_clip_int16(c->predictor);
- c->step = (c->step * yamaha_indexscale[nibble]) >> 8;
- c->step = av_clip(c->step, 127, 24567);
-
- return nibble;
-}
-
-static void adpcm_compress_trellis(AVCodecContext *avctx, const short *samples,
- uint8_t *dst, ADPCMChannelStatus *c, int n)
-{
- //FIXME 6% faster if frontier is a compile-time constant
- ADPCMContext *s = avctx->priv_data;
- const int frontier = 1 << avctx->trellis;
- const int stride = avctx->channels;
- const int version = avctx->codec->id;
- TrellisPath *paths = s->paths, *p;
- TrellisNode *node_buf = s->node_buf;
- TrellisNode **nodep_buf = s->nodep_buf;
- TrellisNode **nodes = nodep_buf; // nodes[] is always sorted by .ssd
- TrellisNode **nodes_next = nodep_buf + frontier;
- int pathn = 0, froze = -1, i, j, k, generation = 0;
- uint8_t *hash = s->trellis_hash;
- memset(hash, 0xff, 65536 * sizeof(*hash));
-
- memset(nodep_buf, 0, 2 * frontier * sizeof(*nodep_buf));
- nodes[0] = node_buf + frontier;
- nodes[0]->ssd = 0;
- nodes[0]->path = 0;
- nodes[0]->step = c->step_index;
- nodes[0]->sample1 = c->sample1;
- nodes[0]->sample2 = c->sample2;
- if((version == CODEC_ID_ADPCM_IMA_WAV) || (version == CODEC_ID_ADPCM_IMA_QT) || (version == CODEC_ID_ADPCM_SWF))
- nodes[0]->sample1 = c->prev_sample;
- if(version == CODEC_ID_ADPCM_MS)
- nodes[0]->step = c->idelta;
- if(version == CODEC_ID_ADPCM_YAMAHA) {
- if(c->step == 0) {
- nodes[0]->step = 127;
- nodes[0]->sample1 = 0;
- } else {
- nodes[0]->step = c->step;
- nodes[0]->sample1 = c->predictor;
- }
- }
-
- for(i=0; i<n; i++) {
- TrellisNode *t = node_buf + frontier*(i&1);
- TrellisNode **u;
- int sample = samples[i*stride];
- int heap_pos = 0;
- memset(nodes_next, 0, frontier*sizeof(TrellisNode*));
- for(j=0; j<frontier && nodes[j]; j++) {
- // higher j have higher ssd already, so they're likely to yield a suboptimal next sample too
- const int range = (j < frontier/2) ? 1 : 0;
- const int step = nodes[j]->step;
- int nidx;
- if(version == CODEC_ID_ADPCM_MS) {
- const int predictor = ((nodes[j]->sample1 * c->coeff1) + (nodes[j]->sample2 * c->coeff2)) / 64;
- const int div = (sample - predictor) / step;
- const int nmin = av_clip(div-range, -8, 6);
- const int nmax = av_clip(div+range, -7, 7);
- for(nidx=nmin; nidx<=nmax; nidx++) {
- const int nibble = nidx & 0xf;
- int dec_sample = predictor + nidx * step;
-#define STORE_NODE(NAME, STEP_INDEX)\
- int d;\
- uint32_t ssd;\
- int pos;\
- TrellisNode *u;\
- uint8_t *h;\
- dec_sample = av_clip_int16(dec_sample);\
- d = sample - dec_sample;\
- ssd = nodes[j]->ssd + d*d;\
- /* Check for wraparound, skip such samples completely. \
- * Note, changing ssd to a 64 bit variable would be \
- * simpler, avoiding this check, but it's slower on \
- * x86 32 bit at the moment. */\
- if (ssd < nodes[j]->ssd)\
- goto next_##NAME;\
- /* Collapse any two states with the same previous sample value. \
- * One could also distinguish states by step and by 2nd to last
- * sample, but the effects of that are negligible.
- * Since nodes in the previous generation are iterated
- * through a heap, they're roughly ordered from better to
- * worse, but not strictly ordered. Therefore, an earlier
- * node with the same sample value is better in most cases
- * (and thus the current is skipped), but not strictly
- * in all cases. Only skipping samples where ssd >=
- * ssd of the earlier node with the same sample gives
- * slightly worse quality, though, for some reason. */ \
- h = &hash[(uint16_t) dec_sample];\
- if (*h == generation)\
- goto next_##NAME;\
- if (heap_pos < frontier) {\
- pos = heap_pos++;\
- } else {\
- /* Try to replace one of the leaf nodes with the new \
- * one, but try a different slot each time. */\
- pos = (frontier >> 1) + (heap_pos & ((frontier >> 1) - 1));\
- if (ssd > nodes_next[pos]->ssd)\
- goto next_##NAME;\
- heap_pos++;\
- }\
- *h = generation;\
- u = nodes_next[pos];\
- if(!u) {\
- assert(pathn < FREEZE_INTERVAL<<avctx->trellis);\
- u = t++;\
- nodes_next[pos] = u;\
- u->path = pathn++;\
- }\
- u->ssd = ssd;\
- u->step = STEP_INDEX;\
- u->sample2 = nodes[j]->sample1;\
- u->sample1 = dec_sample;\
- paths[u->path].nibble = nibble;\
- paths[u->path].prev = nodes[j]->path;\
- /* Sift the newly inserted node up in the heap to \
- * restore the heap property. */\
- while (pos > 0) {\
- int parent = (pos - 1) >> 1;\
- if (nodes_next[parent]->ssd <= ssd)\
- break;\
- FFSWAP(TrellisNode*, nodes_next[parent], nodes_next[pos]);\
- pos = parent;\
- }\
- next_##NAME:;
- STORE_NODE(ms, FFMAX(16, (AdaptationTable[nibble] * step) >> 8));
- }
- } else if((version == CODEC_ID_ADPCM_IMA_WAV)|| (version == CODEC_ID_ADPCM_IMA_QT)|| (version == CODEC_ID_ADPCM_SWF)) {
-#define LOOP_NODES(NAME, STEP_TABLE, STEP_INDEX)\
- const int predictor = nodes[j]->sample1;\
- const int div = (sample - predictor) * 4 / STEP_TABLE;\
- int nmin = av_clip(div-range, -7, 6);\
- int nmax = av_clip(div+range, -6, 7);\
- if(nmin<=0) nmin--; /* distinguish -0 from +0 */\
- if(nmax<0) nmax--;\
- for(nidx=nmin; nidx<=nmax; nidx++) {\
- const int nibble = nidx<0 ? 7-nidx : nidx;\
- int dec_sample = predictor + (STEP_TABLE * yamaha_difflookup[nibble]) / 8;\
- STORE_NODE(NAME, STEP_INDEX);\
- }
- LOOP_NODES(ima, step_table[step], av_clip(step + index_table[nibble], 0, 88));
- } else { //CODEC_ID_ADPCM_YAMAHA
- LOOP_NODES(yamaha, step, av_clip((step * yamaha_indexscale[nibble]) >> 8, 127, 24567));
-#undef LOOP_NODES
-#undef STORE_NODE
- }
- }
-
- u = nodes;
- nodes = nodes_next;
- nodes_next = u;
-
- generation++;
- if (generation == 255) {
- memset(hash, 0xff, 65536 * sizeof(*hash));
- generation = 0;
- }
-
- // prevent overflow
- if(nodes[0]->ssd > (1<<28)) {
- for(j=1; j<frontier && nodes[j]; j++)
- nodes[j]->ssd -= nodes[0]->ssd;
- nodes[0]->ssd = 0;
- }
-
- // merge old paths to save memory
- if(i == froze + FREEZE_INTERVAL) {
- p = &paths[nodes[0]->path];
- for(k=i; k>froze; k--) {
- dst[k] = p->nibble;
- p = &paths[p->prev];
- }
- froze = i;
- pathn = 0;
- // other nodes might use paths that don't coincide with the frozen one.
- // checking which nodes do so is too slow, so just kill them all.
- // this also slightly improves quality, but I don't know why.
- memset(nodes+1, 0, (frontier-1)*sizeof(TrellisNode*));
- }
- }
-
- p = &paths[nodes[0]->path];
- for(i=n-1; i>froze; i--) {
- dst[i] = p->nibble;
- p = &paths[p->prev];
- }
-
- c->predictor = nodes[0]->sample1;
- c->sample1 = nodes[0]->sample1;
- c->sample2 = nodes[0]->sample2;
- c->step_index = nodes[0]->step;
- c->step = nodes[0]->step;
- c->idelta = nodes[0]->step;
-}
-
-static int adpcm_encode_frame(AVCodecContext *avctx,
- unsigned char *frame, int buf_size, void *data)
-{
- int n, i, st;
- short *samples;
- unsigned char *dst;
- ADPCMContext *c = avctx->priv_data;
- uint8_t *buf;
-
- dst = frame;
- samples = (short *)data;
- st= avctx->channels == 2;
-/* n = (BLKSIZE - 4 * avctx->channels) / (2 * 8 * avctx->channels); */
-
- switch(avctx->codec->id) {
- case CODEC_ID_ADPCM_IMA_WAV:
- n = avctx->frame_size / 8;
- c->status[0].prev_sample = (signed short)samples[0]; /* XXX */
-/* c->status[0].step_index = 0; *//* XXX: not sure how to init the state machine */
- bytestream_put_le16(&dst, c->status[0].prev_sample);
- *dst++ = (unsigned char)c->status[0].step_index;
- *dst++ = 0; /* unknown */
- samples++;
- if (avctx->channels == 2) {
- c->status[1].prev_sample = (signed short)samples[0];
-/* c->status[1].step_index = 0; */
- bytestream_put_le16(&dst, c->status[1].prev_sample);
- *dst++ = (unsigned char)c->status[1].step_index;
- *dst++ = 0;
- samples++;
- }
-
- /* stereo: 4 bytes (8 samples) for left, 4 bytes for right, 4 bytes left, ... */
- if(avctx->trellis > 0) {
- FF_ALLOC_OR_GOTO(avctx, buf, 2*n*8, error);
- adpcm_compress_trellis(avctx, samples, buf, &c->status[0], n*8);
- if(avctx->channels == 2)
- adpcm_compress_trellis(avctx, samples+1, buf + n*8, &c->status[1], n*8);
- for(i=0; i<n; i++) {
- *dst++ = buf[8*i+0] | (buf[8*i+1] << 4);
- *dst++ = buf[8*i+2] | (buf[8*i+3] << 4);
- *dst++ = buf[8*i+4] | (buf[8*i+5] << 4);
- *dst++ = buf[8*i+6] | (buf[8*i+7] << 4);
- if (avctx->channels == 2) {
- uint8_t *buf1 = buf + n*8;
- *dst++ = buf1[8*i+0] | (buf1[8*i+1] << 4);
- *dst++ = buf1[8*i+2] | (buf1[8*i+3] << 4);
- *dst++ = buf1[8*i+4] | (buf1[8*i+5] << 4);
- *dst++ = buf1[8*i+6] | (buf1[8*i+7] << 4);
- }
- }
- av_free(buf);
- } else
- for (; n>0; n--) {
- *dst = adpcm_ima_compress_sample(&c->status[0], samples[0]);
- *dst |= adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels]) << 4;
- dst++;
- *dst = adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 2]);
- *dst |= adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 3]) << 4;
- dst++;
- *dst = adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 4]);
- *dst |= adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 5]) << 4;
- dst++;
- *dst = adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 6]);
- *dst |= adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 7]) << 4;
- dst++;
- /* right channel */
- if (avctx->channels == 2) {
- *dst = adpcm_ima_compress_sample(&c->status[1], samples[1]);
- *dst |= adpcm_ima_compress_sample(&c->status[1], samples[3]) << 4;
- dst++;
- *dst = adpcm_ima_compress_sample(&c->status[1], samples[5]);
- *dst |= adpcm_ima_compress_sample(&c->status[1], samples[7]) << 4;
- dst++;
- *dst = adpcm_ima_compress_sample(&c->status[1], samples[9]);
- *dst |= adpcm_ima_compress_sample(&c->status[1], samples[11]) << 4;
- dst++;
- *dst = adpcm_ima_compress_sample(&c->status[1], samples[13]);
- *dst |= adpcm_ima_compress_sample(&c->status[1], samples[15]) << 4;
- dst++;
- }
- samples += 8 * avctx->channels;
- }
- break;
- case CODEC_ID_ADPCM_IMA_QT:
- {
- int ch, i;
- PutBitContext pb;
- init_put_bits(&pb, dst, buf_size*8);
-
- for(ch=0; ch<avctx->channels; ch++){
- put_bits(&pb, 9, (c->status[ch].prev_sample + 0x10000) >> 7);
- put_bits(&pb, 7, c->status[ch].step_index);
- if(avctx->trellis > 0) {
- uint8_t buf[64];
- adpcm_compress_trellis(avctx, samples+ch, buf, &c->status[ch], 64);
- for(i=0; i<64; i++)
- put_bits(&pb, 4, buf[i^1]);
- c->status[ch].prev_sample = c->status[ch].predictor & ~0x7F;
- } else {
- for (i=0; i<64; i+=2){
- int t1, t2;
- t1 = adpcm_ima_compress_sample(&c->status[ch], samples[avctx->channels*(i+0)+ch]);
- t2 = adpcm_ima_compress_sample(&c->status[ch], samples[avctx->channels*(i+1)+ch]);
- put_bits(&pb, 4, t2);
- put_bits(&pb, 4, t1);
- }
- c->status[ch].prev_sample &= ~0x7F;
- }
- }
-
- flush_put_bits(&pb);
- dst += put_bits_count(&pb)>>3;
- break;
- }
- case CODEC_ID_ADPCM_SWF:
- {
- int i;
- PutBitContext pb;
- init_put_bits(&pb, dst, buf_size*8);
-
- n = avctx->frame_size-1;
-
- //Store AdpcmCodeSize
- put_bits(&pb, 2, 2); //Set 4bits flash adpcm format
-
- //Init the encoder state
- for(i=0; i<avctx->channels; i++){
- c->status[i].step_index = av_clip(c->status[i].step_index, 0, 63); // clip step so it fits 6 bits
- put_sbits(&pb, 16, samples[i]);
- put_bits(&pb, 6, c->status[i].step_index);
- c->status[i].prev_sample = (signed short)samples[i];
- }
-
- if(avctx->trellis > 0) {
- FF_ALLOC_OR_GOTO(avctx, buf, 2*n, error);
- adpcm_compress_trellis(avctx, samples+2, buf, &c->status[0], n);
- if (avctx->channels == 2)
- adpcm_compress_trellis(avctx, samples+3, buf+n, &c->status[1], n);
- for(i=0; i<n; i++) {
- put_bits(&pb, 4, buf[i]);
- if (avctx->channels == 2)
- put_bits(&pb, 4, buf[n+i]);
- }
- av_free(buf);
- } else {
- for (i=1; i<avctx->frame_size; i++) {
- put_bits(&pb, 4, adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels*i]));
- if (avctx->channels == 2)
- put_bits(&pb, 4, adpcm_ima_compress_sample(&c->status[1], samples[2*i+1]));
- }
- }
- flush_put_bits(&pb);
- dst += put_bits_count(&pb)>>3;
- break;
- }
- case CODEC_ID_ADPCM_MS:
- for(i=0; i<avctx->channels; i++){
- int predictor=0;
-
- *dst++ = predictor;
- c->status[i].coeff1 = AdaptCoeff1[predictor];
- c->status[i].coeff2 = AdaptCoeff2[predictor];
- }
- for(i=0; i<avctx->channels; i++){
- if (c->status[i].idelta < 16)
- c->status[i].idelta = 16;
-
- bytestream_put_le16(&dst, c->status[i].idelta);
- }
- for(i=0; i<avctx->channels; i++){
- c->status[i].sample2= *samples++;
- }
- for(i=0; i<avctx->channels; i++){
- c->status[i].sample1= *samples++;
-
- bytestream_put_le16(&dst, c->status[i].sample1);
- }
- for(i=0; i<avctx->channels; i++)
- bytestream_put_le16(&dst, c->status[i].sample2);
-
- if(avctx->trellis > 0) {
- int n = avctx->block_align - 7*avctx->channels;
- FF_ALLOC_OR_GOTO(avctx, buf, 2*n, error);
- if(avctx->channels == 1) {
- adpcm_compress_trellis(avctx, samples, buf, &c->status[0], n);
- for(i=0; i<n; i+=2)
- *dst++ = (buf[i] << 4) | buf[i+1];
- } else {
- adpcm_compress_trellis(avctx, samples, buf, &c->status[0], n);
- adpcm_compress_trellis(avctx, samples+1, buf+n, &c->status[1], n);
- for(i=0; i<n; i++)
- *dst++ = (buf[i] << 4) | buf[n+i];
- }
- av_free(buf);
- } else
- for(i=7*avctx->channels; i<avctx->block_align; i++) {
- int nibble;
- nibble = adpcm_ms_compress_sample(&c->status[ 0], *samples++)<<4;
- nibble|= adpcm_ms_compress_sample(&c->status[st], *samples++);
- *dst++ = nibble;
- }
- break;
- case CODEC_ID_ADPCM_YAMAHA:
- n = avctx->frame_size / 2;
- if(avctx->trellis > 0) {
- FF_ALLOC_OR_GOTO(avctx, buf, 2*n*2, error);
- n *= 2;
- if(avctx->channels == 1) {
- adpcm_compress_trellis(avctx, samples, buf, &c->status[0], n);
- for(i=0; i<n; i+=2)
- *dst++ = buf[i] | (buf[i+1] << 4);
- } else {
- adpcm_compress_trellis(avctx, samples, buf, &c->status[0], n);
- adpcm_compress_trellis(avctx, samples+1, buf+n, &c->status[1], n);
- for(i=0; i<n; i++)
- *dst++ = buf[i] | (buf[n+i] << 4);
- }
- av_free(buf);
- } else
- for (n *= avctx->channels; n>0; n--) {
- int nibble;
- nibble = adpcm_yamaha_compress_sample(&c->status[ 0], *samples++);
- nibble |= adpcm_yamaha_compress_sample(&c->status[st], *samples++) << 4;
- *dst++ = nibble;
- }
- break;
- default:
- error:
- return -1;
- }
- return dst - frame;
-}
-#endif //CONFIG_ENCODERS
+} ADPCMDecodeContext;
static av_cold int adpcm_decode_init(AVCodecContext * avctx)
{
- ADPCMContext *c = avctx->priv_data;
+ ADPCMDecodeContext *c = avctx->priv_data;
unsigned int max_channels = 2;
switch(avctx->codec->id) {
case CODEC_ID_ADPCM_EA_R1:
case CODEC_ID_ADPCM_EA_R2:
case CODEC_ID_ADPCM_EA_R3:
+ case CODEC_ID_ADPCM_EA_XAS:
max_channels = 6;
break;
}
@@ -786,8 +133,8 @@ static inline short adpcm_ima_expand_nibble(ADPCMChannelStatus *c, char nibble,
int predictor;
int sign, delta, diff, step;
- step = step_table[c->step_index];
- step_index = c->step_index + index_table[(unsigned)nibble];
+ step = ff_adpcm_step_table[c->step_index];
+ step_index = c->step_index + ff_adpcm_index_table[(unsigned)nibble];
if (step_index < 0) step_index = 0;
else if (step_index > 88) step_index = 88;
@@ -807,6 +154,32 @@ static inline short adpcm_ima_expand_nibble(ADPCMChannelStatus *c, char nibble,
return (short)c->predictor;
}
+static inline int adpcm_ima_qt_expand_nibble(ADPCMChannelStatus *c, int nibble, int shift)
+{
+ int step_index;
+ int predictor;
+ int diff, step;
+
+ step = ff_adpcm_step_table[c->step_index];
+ step_index = c->step_index + ff_adpcm_index_table[nibble];
+ step_index = av_clip(step_index, 0, 88);
+
+ diff = step >> 3;
+ if (nibble & 4) diff += step;
+ if (nibble & 2) diff += step >> 1;
+ if (nibble & 1) diff += step >> 2;
+
+ if (nibble & 8)
+ predictor = c->predictor - diff;
+ else
+ predictor = c->predictor + diff;
+
+ c->predictor = av_clip_int16(predictor);
+ c->step_index = step_index;
+
+ return c->predictor;
+}
+
static inline short adpcm_ms_expand_nibble(ADPCMChannelStatus *c, char nibble)
{
int predictor;
@@ -816,7 +189,7 @@ static inline short adpcm_ms_expand_nibble(ADPCMChannelStatus *c, char nibble)
c->sample2 = c->sample1;
c->sample1 = av_clip_int16(predictor);
- c->idelta = (AdaptationTable[(int)nibble] * c->idelta) >> 8;
+ c->idelta = (ff_adpcm_AdaptationTable[(int)nibble] * c->idelta) >> 8;
if (c->idelta < 16) c->idelta = 16;
return c->sample1;
@@ -837,7 +210,7 @@ static inline short adpcm_ct_expand_nibble(ADPCMChannelStatus *c, char nibble)
c->predictor = ((c->predictor * 254) >> 8) + (sign ? -diff : diff);
c->predictor = av_clip_int16(c->predictor);
/* calculate new step and clamp it to range 511..32767 */
- new_step = (AdaptationTable[nibble & 7] * c->step) >> 8;
+ new_step = (ff_adpcm_AdaptationTable[nibble & 7] * c->step) >> 8;
c->step = av_clip(new_step, 511, 32767);
return (short)c->predictor;
@@ -870,9 +243,9 @@ static inline short adpcm_yamaha_expand_nibble(ADPCMChannelStatus *c, unsigned c
c->step = 127;
}
- c->predictor += (c->step * yamaha_difflookup[nibble]) / 8;
+ c->predictor += (c->step * ff_adpcm_yamaha_difflookup[nibble]) / 8;
c->predictor = av_clip_int16(c->predictor);
- c->step = (c->step * yamaha_indexscale[nibble]) >> 8;
+ c->step = (c->step * ff_adpcm_yamaha_indexscale[nibble]) >> 8;
c->step = av_clip(c->step, 127, 24567);
return c->predictor;
}
@@ -942,6 +315,173 @@ static void xa_decode(short *out, const unsigned char *in,
}
}
+/**
+ * Get the number of samples that will be decoded from the packet.
+ * In one case, this is actually the maximum number of samples possible to
+ * decode with the given buf_size.
+ *
+ * @param[out] coded_samples set to the number of samples as coded in the
+ * packet, or 0 if the codec does not encode the
+ * number of samples in each frame.
+ */
+static int get_nb_samples(AVCodecContext *avctx, const uint8_t *buf,
+ int buf_size, int *coded_samples)
+{
+ ADPCMDecodeContext *s = avctx->priv_data;
+ int nb_samples = 0;
+ int ch = avctx->channels;
+ int has_coded_samples = 0;
+ int header_size;
+
+ *coded_samples = 0;
+
+ switch (avctx->codec->id) {
+ /* constant, only check buf_size */
+ case CODEC_ID_ADPCM_EA_XAS:
+ if (buf_size < 76 * ch)
+ return 0;
+ nb_samples = 128;
+ break;
+ case CODEC_ID_ADPCM_IMA_QT:
+ if (buf_size < 34 * ch)
+ return 0;
+ nb_samples = 64;
+ break;
+ /* simple 4-bit adpcm */
+ case CODEC_ID_ADPCM_CT:
+ case CODEC_ID_ADPCM_IMA_EA_SEAD:
+ case CODEC_ID_ADPCM_IMA_WS:
+ case CODEC_ID_ADPCM_YAMAHA:
+ nb_samples = buf_size * 2 / ch;
+ break;
+ }
+ if (nb_samples)
+ return nb_samples;
+
+ /* simple 4-bit adpcm, with header */
+ header_size = 0;
+ switch (avctx->codec->id) {
+ case CODEC_ID_ADPCM_4XM:
+ case CODEC_ID_ADPCM_IMA_ISS: header_size = 4 * ch; break;
+ case CODEC_ID_ADPCM_IMA_AMV: header_size = 8; break;
+ case CODEC_ID_ADPCM_IMA_SMJPEG: header_size = 4; break;
+ }
+ if (header_size > 0)
+ return (buf_size - header_size) * 2 / ch;
+
+ /* more complex formats */
+ switch (avctx->codec->id) {
+ case CODEC_ID_ADPCM_EA:
+ has_coded_samples = 1;
+ if (buf_size < 4)
+ return 0;
+ *coded_samples = AV_RL32(buf);
+ *coded_samples -= *coded_samples % 28;
+ nb_samples = (buf_size - 12) / 30 * 28;
+ break;
+ case CODEC_ID_ADPCM_IMA_EA_EACS:
+ has_coded_samples = 1;
+ if (buf_size < 4)
+ return 0;
+ *coded_samples = AV_RL32(buf);
+ nb_samples = (buf_size - (4 + 8 * ch)) * 2 / ch;
+ break;
+ case CODEC_ID_ADPCM_EA_MAXIS_XA:
+ nb_samples = ((buf_size - ch) / (2 * ch)) * 2 * ch;
+ break;
+ case CODEC_ID_ADPCM_EA_R1:
+ case CODEC_ID_ADPCM_EA_R2:
+ case CODEC_ID_ADPCM_EA_R3:
+ /* maximum number of samples */
+ /* has internal offsets and a per-frame switch to signal raw 16-bit */
+ has_coded_samples = 1;
+ if (buf_size < 4)
+ return 0;
+ switch (avctx->codec->id) {
+ case CODEC_ID_ADPCM_EA_R1:
+ header_size = 4 + 9 * ch;
+ *coded_samples = AV_RL32(buf);
+ break;
+ case CODEC_ID_ADPCM_EA_R2:
+ header_size = 4 + 5 * ch;
+ *coded_samples = AV_RL32(buf);
+ break;
+ case CODEC_ID_ADPCM_EA_R3:
+ header_size = 4 + 5 * ch;
+ *coded_samples = AV_RB32(buf);
+ break;
+ }
+ *coded_samples -= *coded_samples % 28;
+ nb_samples = (buf_size - header_size) * 2 / ch;
+ nb_samples -= nb_samples % 28;
+ break;
+ case CODEC_ID_ADPCM_IMA_DK3:
+ if (avctx->block_align > 0)
+ buf_size = FFMIN(buf_size, avctx->block_align);
+ nb_samples = ((buf_size - 16) * 8 / 3) / ch;
+ break;
+ case CODEC_ID_ADPCM_IMA_DK4:
+ nb_samples = 1 + (buf_size - 4 * ch) * 2 / ch;
+ break;
+ case CODEC_ID_ADPCM_IMA_WAV:
+ if (avctx->block_align > 0)
+ buf_size = FFMIN(buf_size, avctx->block_align);
+ nb_samples = 1 + (buf_size - 4 * ch) / (4 * ch) * 8;
+ break;
+ case CODEC_ID_ADPCM_MS:
+ if (avctx->block_align > 0)
+ buf_size = FFMIN(buf_size, avctx->block_align);
+ nb_samples = 2 + (buf_size - 7 * ch) * 2 / ch;
+ break;
+ case CODEC_ID_ADPCM_SBPRO_2:
+ case CODEC_ID_ADPCM_SBPRO_3:
+ case CODEC_ID_ADPCM_SBPRO_4:
+ {
+ int samples_per_byte;
+ switch (avctx->codec->id) {
+ case CODEC_ID_ADPCM_SBPRO_2: samples_per_byte = 4; break;
+ case CODEC_ID_ADPCM_SBPRO_3: samples_per_byte = 3; break;
+ case CODEC_ID_ADPCM_SBPRO_4: samples_per_byte = 2; break;
+ }
+ if (!s->status[0].step_index) {
+ nb_samples++;
+ buf_size -= ch;
+ }
+ nb_samples += buf_size * samples_per_byte / ch;
+ break;
+ }
+ case CODEC_ID_ADPCM_SWF:
+ {
+ int buf_bits = buf_size * 8 - 2;
+ int nbits = (buf[0] >> 6) + 2;
+ int block_hdr_size = 22 * ch;
+ int block_size = block_hdr_size + nbits * ch * 4095;
+ int nblocks = buf_bits / block_size;
+ int bits_left = buf_bits - nblocks * block_size;
+ nb_samples = nblocks * 4096;
+ if (bits_left >= block_hdr_size)
+ nb_samples += 1 + (bits_left - block_hdr_size) / (nbits * ch);
+ break;
+ }
+ case CODEC_ID_ADPCM_THP:
+ has_coded_samples = 1;
+ if (buf_size < 8)
+ return 0;
+ *coded_samples = AV_RB32(&buf[4]);
+ *coded_samples -= *coded_samples % 14;
+ nb_samples = (buf_size - 80) / (8 * ch) * 14;
+ break;
+ case CODEC_ID_ADPCM_XA:
+ nb_samples = (buf_size / 128) * 224 / ch;
+ break;
+ }
+
+ /* validate coded sample count */
+ if (has_coded_samples && (*coded_samples <= 0 || *coded_samples > nb_samples))
+ return AVERROR_INVALIDDATA;
+
+ return nb_samples;
+}
/* DK3 ADPCM support macro */
#define DK3_GET_NEXT_NIBBLE() \
@@ -952,8 +492,11 @@ static void xa_decode(short *out, const unsigned char *in,
} \
else \
{ \
+ if (end_of_packet) \
+ break; \
last_byte = *src++; \
- if (src >= buf + buf_size) break; \
+ if (src >= buf + buf_size) \
+ end_of_packet = 1; \
nibble = last_byte & 0x0F; \
decode_top_nibble_next = 1; \
}
@@ -964,93 +507,90 @@ static int adpcm_decode_frame(AVCodecContext *avctx,
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
- ADPCMContext *c = avctx->priv_data;
+ ADPCMDecodeContext *c = avctx->priv_data;
ADPCMChannelStatus *cs;
int n, m, channel, i;
- int block_predictor[2];
short *samples;
- short *samples_end;
const uint8_t *src;
int st; /* stereo */
-
- /* DK3 ADPCM accounting variables */
- unsigned char last_byte = 0;
- unsigned char nibble;
- int decode_top_nibble_next = 0;
- int diff_channel;
-
- /* EA ADPCM state variables */
- uint32_t samples_in_chunk;
- int32_t previous_left_sample, previous_right_sample;
- int32_t current_left_sample, current_right_sample;
- int32_t next_left_sample, next_right_sample;
- int32_t coeff1l, coeff2l, coeff1r, coeff2r;
- uint8_t shift_left, shift_right;
int count1, count2;
- int coeff[2][2], shift[2];//used in EA MAXIS ADPCM
+ int nb_samples, coded_samples, out_bps, out_size;
- if (!buf_size)
- return 0;
+ nb_samples = get_nb_samples(avctx, buf, buf_size, &coded_samples);
+ if (nb_samples <= 0) {
+ av_log(avctx, AV_LOG_ERROR, "invalid number of samples in packet\n");
+ return AVERROR_INVALIDDATA;
+ }
- //should protect all 4bit ADPCM variants
- //8 is needed for CODEC_ID_ADPCM_IMA_WAV with 2 channels
- //
- if(*data_size/4 < buf_size + 8)
- return -1;
+ out_bps = av_get_bytes_per_sample(avctx->sample_fmt);
+ out_size = nb_samples * avctx->channels * out_bps;
+ if (*data_size < out_size) {
+ av_log(avctx, AV_LOG_ERROR, "output buffer is too small\n");
+ return AVERROR(EINVAL);
+ }
+ /* use coded_samples when applicable */
+ /* it is always <= nb_samples, so the output buffer will be large enough */
+ if (coded_samples) {
+ if (coded_samples != nb_samples)
+ av_log(avctx, AV_LOG_WARNING, "mismatch in coded sample count\n");
+ nb_samples = coded_samples;
+ out_size = nb_samples * avctx->channels * out_bps;
+ }
samples = data;
- samples_end= samples + *data_size/2;
- *data_size= 0;
src = buf;
st = avctx->channels == 2 ? 1 : 0;
switch(avctx->codec->id) {
case CODEC_ID_ADPCM_IMA_QT:
- n = buf_size - 2*avctx->channels;
+ /* In QuickTime, IMA is encoded by chunks of 34 bytes (=64 samples).
+ Channel data is interleaved per-chunk. */
for (channel = 0; channel < avctx->channels; channel++) {
+ int16_t predictor;
+ int step_index;
cs = &(c->status[channel]);
/* (pppppp) (piiiiiii) */
/* Bits 15-7 are the _top_ 9 bits of the 16-bit initial predictor value */
- cs->predictor = (*src++) << 8;
- cs->predictor |= (*src & 0x80);
- cs->predictor &= 0xFF80;
-
- /* sign extension */
- if(cs->predictor & 0x8000)
- cs->predictor -= 0x10000;
-
- cs->predictor = av_clip_int16(cs->predictor);
-
- cs->step_index = (*src++) & 0x7F;
+ predictor = AV_RB16(src);
+ step_index = predictor & 0x7F;
+ predictor &= 0xFF80;
+
+ src += 2;
+
+ if (cs->step_index == step_index) {
+ int diff = (int)predictor - cs->predictor;
+ if (diff < 0)
+ diff = - diff;
+ if (diff > 0x7f)
+ goto update;
+ } else {
+ update:
+ cs->step_index = step_index;
+ cs->predictor = predictor;
+ }
if (cs->step_index > 88){
av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n", cs->step_index);
cs->step_index = 88;
}
- cs->step = step_table[cs->step_index];
-
samples = (short*)data + channel;
- for(m=32; n>0 && m>0; n--, m--) { /* in QuickTime, IMA is encoded by chuncks of 34 bytes (=64 samples) */
- *samples = adpcm_ima_expand_nibble(cs, src[0] & 0x0F, 3);
+ for (m = 0; m < 32; m++) {
+ *samples = adpcm_ima_qt_expand_nibble(cs, src[0] & 0x0F, 3);
samples += avctx->channels;
- *samples = adpcm_ima_expand_nibble(cs, src[0] >> 4 , 3);
+ *samples = adpcm_ima_qt_expand_nibble(cs, src[0] >> 4 , 3);
samples += avctx->channels;
src ++;
}
}
- if (st)
- samples--;
break;
case CODEC_ID_ADPCM_IMA_WAV:
if (avctx->block_align != 0 && buf_size > avctx->block_align)
buf_size = avctx->block_align;
-// samples_per_block= (block_align-4*chanels)*8 / (bits_per_sample * chanels) + 1;
-
for(i=0; i<avctx->channels; i++){
cs = &(c->status[i]);
cs->predictor = *samples++ = (int16_t)bytestream_get_le16(&src);
@@ -1063,61 +603,61 @@ static int adpcm_decode_frame(AVCodecContext *avctx,
if (*src++) av_log(avctx, AV_LOG_ERROR, "unused byte should be null but is %d!!\n", src[-1]); /* unused */
}
- while(src < buf + buf_size){
- for(m=0; m<4; m++){
- for(i=0; i<=st; i++)
- *samples++ = adpcm_ima_expand_nibble(&c->status[i], src[4*i] & 0x0F, 3);
- for(i=0; i<=st; i++)
- *samples++ = adpcm_ima_expand_nibble(&c->status[i], src[4*i] >> 4 , 3);
- src++;
+ for (n = (nb_samples - 1) / 8; n > 0; n--) {
+ for (i = 0; i < avctx->channels; i++) {
+ cs = &c->status[i];
+ for (m = 0; m < 4; m++) {
+ uint8_t v = *src++;
+ *samples = adpcm_ima_expand_nibble(cs, v & 0x0F, 3);
+ samples += avctx->channels;
+ *samples = adpcm_ima_expand_nibble(cs, v >> 4 , 3);
+ samples += avctx->channels;
+ }
+ samples -= 8 * avctx->channels - 1;
}
- src += 4*st;
+ samples += 7 * avctx->channels;
}
break;
case CODEC_ID_ADPCM_4XM:
- cs = &(c->status[0]);
- c->status[0].predictor= (int16_t)bytestream_get_le16(&src);
- if(st){
- c->status[1].predictor= (int16_t)bytestream_get_le16(&src);
- }
- c->status[0].step_index= (int16_t)bytestream_get_le16(&src);
- if(st){
- c->status[1].step_index= (int16_t)bytestream_get_le16(&src);
- }
- if (cs->step_index < 0) cs->step_index = 0;
- if (cs->step_index > 88) cs->step_index = 88;
+ for (i = 0; i < avctx->channels; i++)
+ c->status[i].predictor= (int16_t)bytestream_get_le16(&src);
- m= (buf_size - (src - buf))>>st;
- for(i=0; i<m; i++) {
- *samples++ = adpcm_ima_expand_nibble(&c->status[0], src[i] & 0x0F, 4);
- if (st)
- *samples++ = adpcm_ima_expand_nibble(&c->status[1], src[i+m] & 0x0F, 4);
- *samples++ = adpcm_ima_expand_nibble(&c->status[0], src[i] >> 4, 4);
- if (st)
- *samples++ = adpcm_ima_expand_nibble(&c->status[1], src[i+m] >> 4, 4);
+ for (i = 0; i < avctx->channels; i++) {
+ c->status[i].step_index= (int16_t)bytestream_get_le16(&src);
+ c->status[i].step_index = av_clip(c->status[i].step_index, 0, 88);
}
- src += m<<st;
-
+ for (i = 0; i < avctx->channels; i++) {
+ samples = (short*)data + i;
+ cs = &c->status[i];
+ for (n = nb_samples >> 1; n > 0; n--, src++) {
+ uint8_t v = *src;
+ *samples = adpcm_ima_expand_nibble(cs, v & 0x0F, 4);
+ samples += avctx->channels;
+ *samples = adpcm_ima_expand_nibble(cs, v >> 4 , 4);
+ samples += avctx->channels;
+ }
+ }
break;
case CODEC_ID_ADPCM_MS:
+ {
+ int block_predictor;
+
if (avctx->block_align != 0 && buf_size > avctx->block_align)
buf_size = avctx->block_align;
- n = buf_size - 7 * avctx->channels;
- if (n < 0)
- return -1;
- block_predictor[0] = av_clip(*src++, 0, 6);
- block_predictor[1] = 0;
- if (st)
- block_predictor[1] = av_clip(*src++, 0, 6);
+
+ block_predictor = av_clip(*src++, 0, 6);
+ c->status[0].coeff1 = ff_adpcm_AdaptCoeff1[block_predictor];
+ c->status[0].coeff2 = ff_adpcm_AdaptCoeff2[block_predictor];
+ if (st) {
+ block_predictor = av_clip(*src++, 0, 6);
+ c->status[1].coeff1 = ff_adpcm_AdaptCoeff1[block_predictor];
+ c->status[1].coeff2 = ff_adpcm_AdaptCoeff2[block_predictor];
+ }
c->status[0].idelta = (int16_t)bytestream_get_le16(&src);
if (st){
c->status[1].idelta = (int16_t)bytestream_get_le16(&src);
}
- c->status[0].coeff1 = AdaptCoeff1[block_predictor[0]];
- c->status[0].coeff2 = AdaptCoeff2[block_predictor[0]];
- c->status[1].coeff1 = AdaptCoeff1[block_predictor[1]];
- c->status[1].coeff2 = AdaptCoeff2[block_predictor[1]];
c->status[0].sample1 = bytestream_get_le16(&src);
if (st) c->status[1].sample1 = bytestream_get_le16(&src);
@@ -1128,51 +668,40 @@ static int adpcm_decode_frame(AVCodecContext *avctx,
if (st) *samples++ = c->status[1].sample2;
*samples++ = c->status[0].sample1;
if (st) *samples++ = c->status[1].sample1;
- for(;n>0;n--) {
+ for(n = (nb_samples - 2) >> (1 - st); n > 0; n--, src++) {
*samples++ = adpcm_ms_expand_nibble(&c->status[0 ], src[0] >> 4 );
*samples++ = adpcm_ms_expand_nibble(&c->status[st], src[0] & 0x0F);
- src ++;
}
break;
+ }
case CODEC_ID_ADPCM_IMA_DK4:
if (avctx->block_align != 0 && buf_size > avctx->block_align)
buf_size = avctx->block_align;
- c->status[0].predictor = (int16_t)bytestream_get_le16(&src);
- c->status[0].step_index = *src++;
- src++;
- *samples++ = c->status[0].predictor;
- if (st) {
- c->status[1].predictor = (int16_t)bytestream_get_le16(&src);
- c->status[1].step_index = *src++;
+ for (channel = 0; channel < avctx->channels; channel++) {
+ cs = &c->status[channel];
+ cs->predictor = (int16_t)bytestream_get_le16(&src);
+ cs->step_index = *src++;
src++;
- *samples++ = c->status[1].predictor;
+ *samples++ = cs->predictor;
}
- while (src < buf + buf_size) {
-
- /* take care of the top nibble (always left or mono channel) */
- *samples++ = adpcm_ima_expand_nibble(&c->status[0],
- src[0] >> 4, 3);
-
- /* take care of the bottom nibble, which is right sample for
- * stereo, or another mono sample */
- if (st)
- *samples++ = adpcm_ima_expand_nibble(&c->status[1],
- src[0] & 0x0F, 3);
- else
- *samples++ = adpcm_ima_expand_nibble(&c->status[0],
- src[0] & 0x0F, 3);
-
- src++;
+ for (n = nb_samples >> (1 - st); n > 0; n--, src++) {
+ uint8_t v = *src;
+ *samples++ = adpcm_ima_expand_nibble(&c->status[0 ], v >> 4 , 3);
+ *samples++ = adpcm_ima_expand_nibble(&c->status[st], v & 0x0F, 3);
}
break;
case CODEC_ID_ADPCM_IMA_DK3:
+ {
+ unsigned char last_byte = 0;
+ unsigned char nibble;
+ int decode_top_nibble_next = 0;
+ int end_of_packet = 0;
+ int diff_channel;
+
if (avctx->block_align != 0 && buf_size > avctx->block_align)
buf_size = avctx->block_align;
- if(buf_size + 16 > (samples_end - samples)*3/8)
- return -1;
-
c->status[0].predictor = (int16_t)AV_RL16(src + 10);
c->status[1].predictor = (int16_t)AV_RL16(src + 12);
c->status[0].step_index = src[14];
@@ -1211,50 +740,35 @@ static int adpcm_decode_frame(AVCodecContext *avctx,
*samples++ = c->status[0].predictor - c->status[1].predictor;
}
break;
+ }
case CODEC_ID_ADPCM_IMA_ISS:
- c->status[0].predictor = (int16_t)AV_RL16(src + 0);
- c->status[0].step_index = src[2];
- src += 4;
- if(st) {
- c->status[1].predictor = (int16_t)AV_RL16(src + 0);
- c->status[1].step_index = src[2];
- src += 4;
+ for (channel = 0; channel < avctx->channels; channel++) {
+ cs = &c->status[channel];
+ cs->predictor = (int16_t)bytestream_get_le16(&src);
+ cs->step_index = *src++;
+ src++;
}
- while (src < buf + buf_size) {
-
+ for (n = nb_samples >> (1 - st); n > 0; n--, src++) {
+ uint8_t v1, v2;
+ uint8_t v = *src;
+ /* nibbles are swapped for mono */
if (st) {
- *samples++ = adpcm_ima_expand_nibble(&c->status[0],
- src[0] >> 4 , 3);
- *samples++ = adpcm_ima_expand_nibble(&c->status[1],
- src[0] & 0x0F, 3);
+ v1 = v >> 4;
+ v2 = v & 0x0F;
} else {
- *samples++ = adpcm_ima_expand_nibble(&c->status[0],
- src[0] & 0x0F, 3);
- *samples++ = adpcm_ima_expand_nibble(&c->status[0],
- src[0] >> 4 , 3);
+ v2 = v >> 4;
+ v1 = v & 0x0F;
}
-
- src++;
+ *samples++ = adpcm_ima_expand_nibble(&c->status[0 ], v1, 3);
+ *samples++ = adpcm_ima_expand_nibble(&c->status[st], v2, 3);
}
break;
case CODEC_ID_ADPCM_IMA_WS:
- /* no per-block initialization; just start decoding the data */
while (src < buf + buf_size) {
-
- if (st) {
- *samples++ = adpcm_ima_expand_nibble(&c->status[0],
- src[0] >> 4 , 3);
- *samples++ = adpcm_ima_expand_nibble(&c->status[1],
- src[0] & 0x0F, 3);
- } else {
- *samples++ = adpcm_ima_expand_nibble(&c->status[0],
- src[0] >> 4 , 3);
- *samples++ = adpcm_ima_expand_nibble(&c->status[0],
- src[0] & 0x0F, 3);
- }
-
- src++;
+ uint8_t v = *src++;
+ *samples++ = adpcm_ima_expand_nibble(&c->status[0], v >> 4 , 3);
+ *samples++ = adpcm_ima_expand_nibble(&c->status[st], v & 0x0F, 3);
}
break;
case CODEC_ID_ADPCM_XA:
@@ -1267,42 +781,43 @@ static int adpcm_decode_frame(AVCodecContext *avctx,
}
break;
case CODEC_ID_ADPCM_IMA_EA_EACS:
- samples_in_chunk = bytestream_get_le32(&src) >> (1-st);
-
- if (samples_in_chunk > buf_size-4-(8<<st)) {
- src += buf_size - 4;
- break;
- }
+ src += 4; // skip sample count (already read)
for (i=0; i<=st; i++)
c->status[i].step_index = bytestream_get_le32(&src);
for (i=0; i<=st; i++)
c->status[i].predictor = bytestream_get_le32(&src);
- for (; samples_in_chunk; samples_in_chunk--, src++) {
+ for (n = nb_samples >> (1 - st); n > 0; n--, src++) {
*samples++ = adpcm_ima_expand_nibble(&c->status[0], *src>>4, 3);
*samples++ = adpcm_ima_expand_nibble(&c->status[st], *src&0x0F, 3);
}
break;
case CODEC_ID_ADPCM_IMA_EA_SEAD:
- for (; src < buf+buf_size; src++) {
+ for (n = nb_samples >> (1 - st); n > 0; n--, src++) {
*samples++ = adpcm_ima_expand_nibble(&c->status[0], src[0] >> 4, 6);
*samples++ = adpcm_ima_expand_nibble(&c->status[st],src[0]&0x0F, 6);
}
break;
case CODEC_ID_ADPCM_EA:
- if (buf_size < 4 || AV_RL32(src) >= ((buf_size - 12) * 2)) {
- src += buf_size;
- break;
- }
- samples_in_chunk = AV_RL32(src);
- src += 4;
+ {
+ int32_t previous_left_sample, previous_right_sample;
+ int32_t current_left_sample, current_right_sample;
+ int32_t next_left_sample, next_right_sample;
+ int32_t coeff1l, coeff2l, coeff1r, coeff2r;
+ uint8_t shift_left, shift_right;
+
+ /* Each EA ADPCM frame has a 12-byte header followed by 30-byte pieces,
+ each coding 28 stereo samples. */
+
+ src += 4; // skip sample count (already read)
+
current_left_sample = (int16_t)bytestream_get_le16(&src);
previous_left_sample = (int16_t)bytestream_get_le16(&src);
current_right_sample = (int16_t)bytestream_get_le16(&src);
previous_right_sample = (int16_t)bytestream_get_le16(&src);
- for (count1 = 0; count1 < samples_in_chunk/28;count1++) {
+ for (count1 = 0; count1 < nb_samples / 28; count1++) {
coeff1l = ea_adpcm_table[ *src >> 4 ];
coeff2l = ea_adpcm_table[(*src >> 4 ) + 4];
coeff1r = ea_adpcm_table[*src & 0x0F];
@@ -1338,14 +853,18 @@ static int adpcm_decode_frame(AVCodecContext *avctx,
src += 2; // Skip terminating 0x0000
break;
+ }
case CODEC_ID_ADPCM_EA_MAXIS_XA:
+ {
+ int coeff[2][2], shift[2];
+
for(channel = 0; channel < avctx->channels; channel++) {
for (i=0; i<2; i++)
coeff[channel][i] = ea_adpcm_table[(*src >> 4) + 4*i];
shift[channel] = (*src & 0x0F) + 8;
src++;
}
- for (count1 = 0; count1 < (buf_size - avctx->channels) / avctx->channels; count1++) {
+ for (count1 = 0; count1 < nb_samples / 2; count1++) {
for(i = 4; i >= 0; i-=4) { /* Pairwise samples LL RR (st) or LL LL (mono) */
for(channel = 0; channel < avctx->channels; channel++) {
int32_t sample = (int32_t)(((*(src+channel) >> i) & 0x0F) << 0x1C) >> shift[channel];
@@ -1359,7 +878,10 @@ static int adpcm_decode_frame(AVCodecContext *avctx,
}
src+=avctx->channels;
}
+ /* consume whole packet */
+ src = buf + buf_size;
break;
+ }
case CODEC_ID_ADPCM_EA_R1:
case CODEC_ID_ADPCM_EA_R2:
case CODEC_ID_ADPCM_EA_R3: {
@@ -1375,14 +897,9 @@ static int adpcm_decode_frame(AVCodecContext *avctx,
uint16_t *samplesC;
const uint8_t *srcC;
const uint8_t *src_end = buf + buf_size;
+ int count = 0;
- samples_in_chunk = (big_endian ? bytestream_get_be32(&src)
- : bytestream_get_le32(&src)) / 28;
- if (samples_in_chunk > UINT32_MAX/(28*avctx->channels) ||
- 28*samples_in_chunk*avctx->channels > samples_end-samples) {
- src += buf_size - 4;
- break;
- }
+ src += 4; // skip sample count (already read)
for (channel=0; channel<avctx->channels; channel++) {
int32_t offset = (big_endian ? bytestream_get_be32(&src)
@@ -1401,7 +918,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx,
previous_sample = c->status[channel].prev_sample;
}
- for (count1=0; count1<samples_in_chunk; count1++) {
+ for (count1 = 0; count1 < nb_samples / 28; count1++) {
if (*srcC == 0xEE) { /* only seen in R2 and R3 */
srcC++;
if (srcC > src_end - 30*2) break;
@@ -1435,6 +952,12 @@ static int adpcm_decode_frame(AVCodecContext *avctx,
}
}
}
+ if (!count) {
+ count = count1;
+ } else if (count != count1) {
+ av_log(avctx, AV_LOG_WARNING, "per-channel sample count mismatch\n");
+ count = FFMAX(count, count1);
+ }
if (avctx->codec->id != CODEC_ID_ADPCM_EA_R1) {
c->status[channel].predictor = current_sample;
@@ -1442,16 +965,11 @@ static int adpcm_decode_frame(AVCodecContext *avctx,
}
}
- src = src + buf_size - (4 + 4*avctx->channels);
- samples += 28 * samples_in_chunk * avctx->channels;
+ out_size = count * 28 * avctx->channels * out_bps;
+ src = src_end;
break;
}
case CODEC_ID_ADPCM_EA_XAS:
- if (samples_end-samples < 32*4*avctx->channels
- || buf_size < (4+15)*4*avctx->channels) {
- src += buf_size;
- break;
- }
for (channel=0; channel<avctx->channels; channel++) {
int coeff[2][4], shift[4];
short *s2, *s = &samples[channel];
@@ -1475,7 +993,6 @@ static int adpcm_decode_frame(AVCodecContext *avctx,
}
}
}
- samples += 32*4*avctx->channels;
break;
case CODEC_ID_ADPCM_IMA_AMV:
case CODEC_ID_ADPCM_IMA_SMJPEG:
@@ -1485,7 +1002,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx,
if (avctx->codec->id == CODEC_ID_ADPCM_IMA_AMV)
src+=4;
- while (src < buf + buf_size) {
+ for (n = nb_samples >> (1 - st); n > 0; n--, src++) {
char hi, lo;
lo = *src & 0x0F;
hi = *src >> 4;
@@ -1497,23 +1014,13 @@ static int adpcm_decode_frame(AVCodecContext *avctx,
lo, 3);
*samples++ = adpcm_ima_expand_nibble(&c->status[0],
hi, 3);
- src++;
}
break;
case CODEC_ID_ADPCM_CT:
- while (src < buf + buf_size) {
- if (st) {
- *samples++ = adpcm_ct_expand_nibble(&c->status[0],
- src[0] >> 4);
- *samples++ = adpcm_ct_expand_nibble(&c->status[1],
- src[0] & 0x0F);
- } else {
- *samples++ = adpcm_ct_expand_nibble(&c->status[0],
- src[0] >> 4);
- *samples++ = adpcm_ct_expand_nibble(&c->status[0],
- src[0] & 0x0F);
- }
- src++;
+ for (n = nb_samples >> (1 - st); n > 0; n--, src++) {
+ uint8_t v = *src;
+ *samples++ = adpcm_ct_expand_nibble(&c->status[0 ], v >> 4 );
+ *samples++ = adpcm_ct_expand_nibble(&c->status[st], v & 0x0F);
}
break;
case CODEC_ID_ADPCM_SBPRO_4:
@@ -1525,27 +1032,26 @@ static int adpcm_decode_frame(AVCodecContext *avctx,
if (st)
*samples++ = 128 * (*src++ - 0x80);
c->status[0].step_index = 1;
+ nb_samples--;
}
if (avctx->codec->id == CODEC_ID_ADPCM_SBPRO_4) {
- while (src < buf + buf_size) {
+ for (n = nb_samples >> (1 - st); n > 0; n--, src++) {
*samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
src[0] >> 4, 4, 0);
*samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
src[0] & 0x0F, 4, 0);
- src++;
}
} else if (avctx->codec->id == CODEC_ID_ADPCM_SBPRO_3) {
- while (src < buf + buf_size && samples + 2 < samples_end) {
+ for (n = nb_samples / 3; n > 0; n--, src++) {
*samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
src[0] >> 5 , 3, 0);
*samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
(src[0] >> 2) & 0x07, 3, 0);
*samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
src[0] & 0x03, 2, 0);
- src++;
}
} else {
- while (src < buf + buf_size && samples + 3 < samples_end) {
+ for (n = nb_samples >> (2 - st); n > 0; n--, src++) {
*samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
src[0] >> 6 , 2, 2);
*samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
@@ -1554,7 +1060,6 @@ static int adpcm_decode_frame(AVCodecContext *avctx,
(src[0] >> 2) & 0x03, 2, 2);
*samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
src[0] & 0x03, 2, 2);
- src++;
}
}
break;
@@ -1586,7 +1091,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx,
for (i = 0; i < avctx->channels; i++) {
// similar to IMA adpcm
int delta = get_bits(&gb, nb_bits);
- int step = step_table[c->status[i].step_index];
+ int step = ff_adpcm_step_table[c->status[i].step_index];
long vpdiff = 0; // vpdiff = (delta+0.5)*step/4
int k = k0;
@@ -1609,10 +1114,6 @@ static int adpcm_decode_frame(AVCodecContext *avctx,
c->status[i].predictor = av_clip_int16(c->status[i].predictor);
*samples++ = c->status[i].predictor;
- if (samples >= samples_end) {
- av_log(avctx, AV_LOG_ERROR, "allocated output buffer is too small\n");
- return -1;
- }
}
}
}
@@ -1620,35 +1121,20 @@ static int adpcm_decode_frame(AVCodecContext *avctx,
break;
}
case CODEC_ID_ADPCM_YAMAHA:
- while (src < buf + buf_size) {
- if (st) {
- *samples++ = adpcm_yamaha_expand_nibble(&c->status[0],
- src[0] & 0x0F);
- *samples++ = adpcm_yamaha_expand_nibble(&c->status[1],
- src[0] >> 4 );
- } else {
- *samples++ = adpcm_yamaha_expand_nibble(&c->status[0],
- src[0] & 0x0F);
- *samples++ = adpcm_yamaha_expand_nibble(&c->status[0],
- src[0] >> 4 );
- }
- src++;
+ for (n = nb_samples >> (1 - st); n > 0; n--, src++) {
+ uint8_t v = *src;
+ *samples++ = adpcm_yamaha_expand_nibble(&c->status[0 ], v & 0x0F);
+ *samples++ = adpcm_yamaha_expand_nibble(&c->status[st], v >> 4 );
}
break;
case CODEC_ID_ADPCM_THP:
{
int table[2][16];
- unsigned int samplecnt;
int prev[2][2];
int ch;
- if (buf_size < 80) {
- av_log(avctx, AV_LOG_ERROR, "frame too small\n");
- return -1;
- }
-
- src+=4;
- samplecnt = bytestream_get_be32(&src);
+ src += 4; // skip channel size
+ src += 4; // skip number of samples (already read)
for (i = 0; i < 32; i++)
table[0][i] = (int16_t)bytestream_get_be16(&src);
@@ -1657,16 +1143,11 @@ static int adpcm_decode_frame(AVCodecContext *avctx,
for (i = 0; i < 4; i++)
prev[0][i] = (int16_t)bytestream_get_be16(&src);
- if (samplecnt >= (samples_end - samples) / (st + 1)) {
- av_log(avctx, AV_LOG_ERROR, "allocated output buffer is too small\n");
- return -1;
- }
-
for (ch = 0; ch <= st; ch++) {
samples = (unsigned short *) data + ch;
/* Read in every sample for this channel. */
- for (i = 0; i < samplecnt / 14; i++) {
+ for (i = 0; i < nb_samples / 14; i++) {
int index = (*src >> 4) & 7;
unsigned int exp = 28 - (*src++ & 15);
int factor1 = table[ch][index * 2];
@@ -1690,59 +1171,27 @@ static int adpcm_decode_frame(AVCodecContext *avctx,
}
}
}
-
- /* In the previous loop, in case stereo is used, samples is
- increased exactly one time too often. */
- samples -= st;
break;
}
default:
return -1;
}
- *data_size = (uint8_t *)samples - (uint8_t *)data;
+ *data_size = out_size;
return src - buf;
}
-
-#if CONFIG_ENCODERS
-#define ADPCM_ENCODER(id,name,long_name_) \
-AVCodec ff_ ## name ## _encoder = { \
- #name, \
- AVMEDIA_TYPE_AUDIO, \
- id, \
- sizeof(ADPCMContext), \
- adpcm_encode_init, \
- adpcm_encode_frame, \
- adpcm_encode_close, \
- NULL, \
- .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, \
- .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
+#define ADPCM_DECODER(id_, name_, long_name_) \
+AVCodec ff_ ## name_ ## _decoder = { \
+ .name = #name_, \
+ .type = AVMEDIA_TYPE_AUDIO, \
+ .id = id_, \
+ .priv_data_size = sizeof(ADPCMDecodeContext), \
+ .init = adpcm_decode_init, \
+ .decode = adpcm_decode_frame, \
+ .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
}
-#else
-#define ADPCM_ENCODER(id,name,long_name_)
-#endif
-
-#if CONFIG_DECODERS
-#define ADPCM_DECODER(id,name,long_name_) \
-AVCodec ff_ ## name ## _decoder = { \
- #name, \
- AVMEDIA_TYPE_AUDIO, \
- id, \
- sizeof(ADPCMContext), \
- adpcm_decode_init, \
- NULL, \
- NULL, \
- adpcm_decode_frame, \
- .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
-}
-#else
-#define ADPCM_DECODER(id,name,long_name_)
-#endif
-
-#define ADPCM_CODEC(id,name,long_name_) \
- ADPCM_ENCODER(id,name,long_name_); ADPCM_DECODER(id,name,long_name_)
/* Note: Do not forget to add new entries to the Makefile as well. */
ADPCM_DECODER(CODEC_ID_ADPCM_4XM, adpcm_4xm, "ADPCM 4X Movie");
@@ -1759,15 +1208,15 @@ ADPCM_DECODER(CODEC_ID_ADPCM_IMA_DK4, adpcm_ima_dk4, "ADPCM IMA Duck DK4");
ADPCM_DECODER(CODEC_ID_ADPCM_IMA_EA_EACS, adpcm_ima_ea_eacs, "ADPCM IMA Electronic Arts EACS");
ADPCM_DECODER(CODEC_ID_ADPCM_IMA_EA_SEAD, adpcm_ima_ea_sead, "ADPCM IMA Electronic Arts SEAD");
ADPCM_DECODER(CODEC_ID_ADPCM_IMA_ISS, adpcm_ima_iss, "ADPCM IMA Funcom ISS");
-ADPCM_CODEC (CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt, "ADPCM IMA QuickTime");
+ADPCM_DECODER(CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt, "ADPCM IMA QuickTime");
ADPCM_DECODER(CODEC_ID_ADPCM_IMA_SMJPEG, adpcm_ima_smjpeg, "ADPCM IMA Loki SDL MJPEG");
-ADPCM_CODEC (CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav, "ADPCM IMA WAV");
+ADPCM_DECODER(CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav, "ADPCM IMA WAV");
ADPCM_DECODER(CODEC_ID_ADPCM_IMA_WS, adpcm_ima_ws, "ADPCM IMA Westwood");
-ADPCM_CODEC (CODEC_ID_ADPCM_MS, adpcm_ms, "ADPCM Microsoft");
+ADPCM_DECODER(CODEC_ID_ADPCM_MS, adpcm_ms, "ADPCM Microsoft");
ADPCM_DECODER(CODEC_ID_ADPCM_SBPRO_2, adpcm_sbpro_2, "ADPCM Sound Blaster Pro 2-bit");
ADPCM_DECODER(CODEC_ID_ADPCM_SBPRO_3, adpcm_sbpro_3, "ADPCM Sound Blaster Pro 2.6-bit");
ADPCM_DECODER(CODEC_ID_ADPCM_SBPRO_4, adpcm_sbpro_4, "ADPCM Sound Blaster Pro 4-bit");
-ADPCM_CODEC (CODEC_ID_ADPCM_SWF, adpcm_swf, "ADPCM Shockwave Flash");
+ADPCM_DECODER(CODEC_ID_ADPCM_SWF, adpcm_swf, "ADPCM Shockwave Flash");
ADPCM_DECODER(CODEC_ID_ADPCM_THP, adpcm_thp, "ADPCM Nintendo Gamecube THP");
ADPCM_DECODER(CODEC_ID_ADPCM_XA, adpcm_xa, "ADPCM CDROM XA");
-ADPCM_CODEC (CODEC_ID_ADPCM_YAMAHA, adpcm_yamaha, "ADPCM Yamaha");
+ADPCM_DECODER(CODEC_ID_ADPCM_YAMAHA, adpcm_yamaha, "ADPCM Yamaha");
diff --git a/libavcodec/adpcm.h b/libavcodec/adpcm.h
new file mode 100644
index 0000000000..475719adf5
--- /dev/null
+++ b/libavcodec/adpcm.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2001-2003 The ffmpeg Project
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * ADPCM encoder/decoder common header.
+ */
+
+#ifndef AVCODEC_ADPCM_H
+#define AVCODEC_ADPCM_H
+
+#define BLKSIZE 1024
+
+typedef struct ADPCMChannelStatus {
+ int predictor;
+ short int step_index;
+ int step;
+ /* for encoding */
+ int prev_sample;
+
+ /* MS version */
+ short sample1;
+ short sample2;
+ int coeff1;
+ int coeff2;
+ int idelta;
+} ADPCMChannelStatus;
+
+#endif /* AVCODEC_ADPCM_H */
diff --git a/libavcodec/adpcm_data.c b/libavcodec/adpcm_data.c
new file mode 100644
index 0000000000..f19d622d3b
--- /dev/null
+++ b/libavcodec/adpcm_data.c
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2001-2003 The ffmpeg Project
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * ADPCM tables
+ */
+
+#include <stdint.h>
+
+/* ff_adpcm_step_table[] and ff_adpcm_index_table[] are from the ADPCM
+ reference source */
+/* This is the index table: */
+const int8_t ff_adpcm_index_table[16] = {
+ -1, -1, -1, -1, 2, 4, 6, 8,
+ -1, -1, -1, -1, 2, 4, 6, 8,
+};
+
+/**
+ * This is the step table. Note that many programs use slight deviations from
+ * this table, but such deviations are negligible:
+ */
+const int16_t ff_adpcm_step_table[89] = {
+ 7, 8, 9, 10, 11, 12, 13, 14, 16, 17,
+ 19, 21, 23, 25, 28, 31, 34, 37, 41, 45,
+ 50, 55, 60, 66, 73, 80, 88, 97, 107, 118,
+ 130, 143, 157, 173, 190, 209, 230, 253, 279, 307,
+ 337, 371, 408, 449, 494, 544, 598, 658, 724, 796,
+ 876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066,
+ 2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358,
+ 5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899,
+ 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767
+};
+
+/* These are for MS-ADPCM */
+/* ff_adpcm_AdaptationTable[], ff_adpcm_AdaptCoeff1[], and
+ ff_adpcm_AdaptCoeff2[] are from libsndfile */
+const int16_t ff_adpcm_AdaptationTable[] = {
+ 230, 230, 230, 230, 307, 409, 512, 614,
+ 768, 614, 512, 409, 307, 230, 230, 230
+};
+
+/** Divided by 4 to fit in 8-bit integers */
+const uint8_t ff_adpcm_AdaptCoeff1[] = {
+ 64, 128, 0, 48, 60, 115, 98
+};
+
+/** Divided by 4 to fit in 8-bit integers */
+const int8_t ff_adpcm_AdaptCoeff2[] = {
+ 0, -64, 0, 16, 0, -52, -58
+};
+
+const int16_t ff_adpcm_yamaha_indexscale[] = {
+ 230, 230, 230, 230, 307, 409, 512, 614,
+ 230, 230, 230, 230, 307, 409, 512, 614
+};
+
+const int8_t ff_adpcm_yamaha_difflookup[] = {
+ 1, 3, 5, 7, 9, 11, 13, 15,
+ -1, -3, -5, -7, -9, -11, -13, -15
+};
diff --git a/libavcodec/adpcm_data.h b/libavcodec/adpcm_data.h
new file mode 100644
index 0000000000..97ab66c346
--- /dev/null
+++ b/libavcodec/adpcm_data.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2001-2003 The ffmpeg Project
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * ADPCM tables
+ */
+
+#ifndef AVCODEC_ADPCM_DATA_H
+#define AVCODEC_ADPCM_DATA_H
+
+#include <stdint.h>
+
+extern const int8_t ff_adpcm_index_table[16];
+extern const int16_t ff_adpcm_step_table[89];
+extern const int16_t ff_adpcm_AdaptationTable[];
+extern const uint8_t ff_adpcm_AdaptCoeff1[];
+extern const int8_t ff_adpcm_AdaptCoeff2[];
+extern const int16_t ff_adpcm_yamaha_indexscale[];
+extern const int8_t ff_adpcm_yamaha_difflookup[];
+
+#endif /* AVCODEC_ADPCM_DATA_H */
diff --git a/libavcodec/adpcmenc.c b/libavcodec/adpcmenc.c
new file mode 100644
index 0000000000..c193f5c7ef
--- /dev/null
+++ b/libavcodec/adpcmenc.c
@@ -0,0 +1,686 @@
+/*
+ * Copyright (c) 2001-2003 The ffmpeg Project
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "avcodec.h"
+#include "get_bits.h"
+#include "put_bits.h"
+#include "bytestream.h"
+#include "adpcm.h"
+#include "adpcm_data.h"
+
+/**
+ * @file
+ * ADPCM encoders
+ * First version by Francois Revol (revol@free.fr)
+ * Fringe ADPCM codecs (e.g., DK3, DK4, Westwood)
+ * by Mike Melanson (melanson@pcisys.net)
+ *
+ * See ADPCM decoder reference documents for codec information.
+ */
+
+typedef struct TrellisPath {
+ int nibble;
+ int prev;
+} TrellisPath;
+
+typedef struct TrellisNode {
+ uint32_t ssd;
+ int path;
+ int sample1;
+ int sample2;
+ int step;
+} TrellisNode;
+
+typedef struct ADPCMEncodeContext {
+ ADPCMChannelStatus status[6];
+ TrellisPath *paths;
+ TrellisNode *node_buf;
+ TrellisNode **nodep_buf;
+ uint8_t *trellis_hash;
+} ADPCMEncodeContext;
+
+#define FREEZE_INTERVAL 128
+
+static av_cold int adpcm_encode_init(AVCodecContext *avctx)
+{
+ ADPCMEncodeContext *s = avctx->priv_data;
+ uint8_t *extradata;
+ int i;
+ if (avctx->channels > 2)
+ return -1; /* only stereo or mono =) */
+
+ if(avctx->trellis && (unsigned)avctx->trellis > 16U){
+ av_log(avctx, AV_LOG_ERROR, "invalid trellis size\n");
+ return -1;
+ }
+
+ if (avctx->trellis) {
+ int frontier = 1 << avctx->trellis;
+ int max_paths = frontier * FREEZE_INTERVAL;
+ FF_ALLOC_OR_GOTO(avctx, s->paths, max_paths * sizeof(*s->paths), error);
+ FF_ALLOC_OR_GOTO(avctx, s->node_buf, 2 * frontier * sizeof(*s->node_buf), error);
+ FF_ALLOC_OR_GOTO(avctx, s->nodep_buf, 2 * frontier * sizeof(*s->nodep_buf), error);
+ FF_ALLOC_OR_GOTO(avctx, s->trellis_hash, 65536 * sizeof(*s->trellis_hash), error);
+ }
+
+ avctx->bits_per_coded_sample = av_get_bits_per_sample(avctx->codec->id);
+
+ switch(avctx->codec->id) {
+ case CODEC_ID_ADPCM_IMA_WAV:
+ avctx->frame_size = (BLKSIZE - 4 * avctx->channels) * 8 / (4 * avctx->channels) + 1; /* each 16 bits sample gives one nibble */
+ /* and we have 4 bytes per channel overhead */
+ avctx->block_align = BLKSIZE;
+ avctx->bits_per_coded_sample = 4;
+ /* seems frame_size isn't taken into account... have to buffer the samples :-( */
+ break;
+ case CODEC_ID_ADPCM_IMA_QT:
+ avctx->frame_size = 64;
+ avctx->block_align = 34 * avctx->channels;
+ break;
+ case CODEC_ID_ADPCM_MS:
+ avctx->frame_size = (BLKSIZE - 7 * avctx->channels) * 2 / avctx->channels + 2; /* each 16 bits sample gives one nibble */
+ /* and we have 7 bytes per channel overhead */
+ avctx->block_align = BLKSIZE;
+ avctx->bits_per_coded_sample = 4;
+ avctx->extradata_size = 32;
+ extradata = avctx->extradata = av_malloc(avctx->extradata_size);
+ if (!extradata)
+ return AVERROR(ENOMEM);
+ bytestream_put_le16(&extradata, avctx->frame_size);
+ bytestream_put_le16(&extradata, 7); /* wNumCoef */
+ for (i = 0; i < 7; i++) {
+ bytestream_put_le16(&extradata, ff_adpcm_AdaptCoeff1[i] * 4);
+ bytestream_put_le16(&extradata, ff_adpcm_AdaptCoeff2[i] * 4);
+ }
+ break;
+ case CODEC_ID_ADPCM_YAMAHA:
+ avctx->frame_size = BLKSIZE * avctx->channels;
+ avctx->block_align = BLKSIZE;
+ break;
+ case CODEC_ID_ADPCM_SWF:
+ if (avctx->sample_rate != 11025 &&
+ avctx->sample_rate != 22050 &&
+ avctx->sample_rate != 44100) {
+ av_log(avctx, AV_LOG_ERROR, "Sample rate must be 11025, 22050 or 44100\n");
+ goto error;
+ }
+ avctx->frame_size = 512 * (avctx->sample_rate / 11025);
+ break;
+ default:
+ goto error;
+ }
+
+ avctx->coded_frame= avcodec_alloc_frame();
+ avctx->coded_frame->key_frame= 1;
+
+ return 0;
+error:
+ av_freep(&s->paths);
+ av_freep(&s->node_buf);
+ av_freep(&s->nodep_buf);
+ av_freep(&s->trellis_hash);
+ return -1;
+}
+
+static av_cold int adpcm_encode_close(AVCodecContext *avctx)
+{
+ ADPCMEncodeContext *s = avctx->priv_data;
+ av_freep(&avctx->coded_frame);
+ av_freep(&s->paths);
+ av_freep(&s->node_buf);
+ av_freep(&s->nodep_buf);
+ av_freep(&s->trellis_hash);
+
+ return 0;
+}
+
+
+static inline unsigned char adpcm_ima_compress_sample(ADPCMChannelStatus *c, short sample)
+{
+ int delta = sample - c->prev_sample;
+ int nibble = FFMIN(7, abs(delta)*4/ff_adpcm_step_table[c->step_index]) + (delta<0)*8;
+ c->prev_sample += ((ff_adpcm_step_table[c->step_index] * ff_adpcm_yamaha_difflookup[nibble]) / 8);
+ c->prev_sample = av_clip_int16(c->prev_sample);
+ c->step_index = av_clip(c->step_index + ff_adpcm_index_table[nibble], 0, 88);
+ return nibble;
+}
+
+static inline unsigned char adpcm_ima_qt_compress_sample(ADPCMChannelStatus *c, short sample)
+{
+ int delta = sample - c->prev_sample;
+ int diff, step = ff_adpcm_step_table[c->step_index];
+ int nibble = 8*(delta < 0);
+
+ delta= abs(delta);
+ diff = delta + (step >> 3);
+
+ if (delta >= step) {
+ nibble |= 4;
+ delta -= step;
+ }
+ step >>= 1;
+ if (delta >= step) {
+ nibble |= 2;
+ delta -= step;
+ }
+ step >>= 1;
+ if (delta >= step) {
+ nibble |= 1;
+ delta -= step;
+ }
+ diff -= delta;
+
+ if (nibble & 8)
+ c->prev_sample -= diff;
+ else
+ c->prev_sample += diff;
+
+ c->prev_sample = av_clip_int16(c->prev_sample);
+ c->step_index = av_clip(c->step_index + ff_adpcm_index_table[nibble], 0, 88);
+
+ return nibble;
+}
+
+static inline unsigned char adpcm_ms_compress_sample(ADPCMChannelStatus *c, short sample)
+{
+ int predictor, nibble, bias;
+
+ predictor = (((c->sample1) * (c->coeff1)) + ((c->sample2) * (c->coeff2))) / 64;
+
+ nibble= sample - predictor;
+ if(nibble>=0) bias= c->idelta/2;
+ else bias=-c->idelta/2;
+
+ nibble= (nibble + bias) / c->idelta;
+ nibble= av_clip(nibble, -8, 7)&0x0F;
+
+ predictor += (signed)((nibble & 0x08)?(nibble - 0x10):(nibble)) * c->idelta;
+
+ c->sample2 = c->sample1;
+ c->sample1 = av_clip_int16(predictor);
+
+ c->idelta = (ff_adpcm_AdaptationTable[(int)nibble] * c->idelta) >> 8;
+ if (c->idelta < 16) c->idelta = 16;
+
+ return nibble;
+}
+
+static inline unsigned char adpcm_yamaha_compress_sample(ADPCMChannelStatus *c, short sample)
+{
+ int nibble, delta;
+
+ if(!c->step) {
+ c->predictor = 0;
+ c->step = 127;
+ }
+
+ delta = sample - c->predictor;
+
+ nibble = FFMIN(7, abs(delta)*4/c->step) + (delta<0)*8;
+
+ c->predictor += ((c->step * ff_adpcm_yamaha_difflookup[nibble]) / 8);
+ c->predictor = av_clip_int16(c->predictor);
+ c->step = (c->step * ff_adpcm_yamaha_indexscale[nibble]) >> 8;
+ c->step = av_clip(c->step, 127, 24567);
+
+ return nibble;
+}
+
+static void adpcm_compress_trellis(AVCodecContext *avctx, const short *samples,
+ uint8_t *dst, ADPCMChannelStatus *c, int n)
+{
+ //FIXME 6% faster if frontier is a compile-time constant
+ ADPCMEncodeContext *s = avctx->priv_data;
+ const int frontier = 1 << avctx->trellis;
+ const int stride = avctx->channels;
+ const int version = avctx->codec->id;
+ TrellisPath *paths = s->paths, *p;
+ TrellisNode *node_buf = s->node_buf;
+ TrellisNode **nodep_buf = s->nodep_buf;
+ TrellisNode **nodes = nodep_buf; // nodes[] is always sorted by .ssd
+ TrellisNode **nodes_next = nodep_buf + frontier;
+ int pathn = 0, froze = -1, i, j, k, generation = 0;
+ uint8_t *hash = s->trellis_hash;
+ memset(hash, 0xff, 65536 * sizeof(*hash));
+
+ memset(nodep_buf, 0, 2 * frontier * sizeof(*nodep_buf));
+ nodes[0] = node_buf + frontier;
+ nodes[0]->ssd = 0;
+ nodes[0]->path = 0;
+ nodes[0]->step = c->step_index;
+ nodes[0]->sample1 = c->sample1;
+ nodes[0]->sample2 = c->sample2;
+ if((version == CODEC_ID_ADPCM_IMA_WAV) || (version == CODEC_ID_ADPCM_IMA_QT) || (version == CODEC_ID_ADPCM_SWF))
+ nodes[0]->sample1 = c->prev_sample;
+ if(version == CODEC_ID_ADPCM_MS)
+ nodes[0]->step = c->idelta;
+ if(version == CODEC_ID_ADPCM_YAMAHA) {
+ if(c->step == 0) {
+ nodes[0]->step = 127;
+ nodes[0]->sample1 = 0;
+ } else {
+ nodes[0]->step = c->step;
+ nodes[0]->sample1 = c->predictor;
+ }
+ }
+
+ for(i=0; i<n; i++) {
+ TrellisNode *t = node_buf + frontier*(i&1);
+ TrellisNode **u;
+ int sample = samples[i*stride];
+ int heap_pos = 0;
+ memset(nodes_next, 0, frontier*sizeof(TrellisNode*));
+ for(j=0; j<frontier && nodes[j]; j++) {
+ // higher j have higher ssd already, so they're likely to yield a suboptimal next sample too
+ const int range = (j < frontier/2) ? 1 : 0;
+ const int step = nodes[j]->step;
+ int nidx;
+ if(version == CODEC_ID_ADPCM_MS) {
+ const int predictor = ((nodes[j]->sample1 * c->coeff1) + (nodes[j]->sample2 * c->coeff2)) / 64;
+ const int div = (sample - predictor) / step;
+ const int nmin = av_clip(div-range, -8, 6);
+ const int nmax = av_clip(div+range, -7, 7);
+ for(nidx=nmin; nidx<=nmax; nidx++) {
+ const int nibble = nidx & 0xf;
+ int dec_sample = predictor + nidx * step;
+#define STORE_NODE(NAME, STEP_INDEX)\
+ int d;\
+ uint32_t ssd;\
+ int pos;\
+ TrellisNode *u;\
+ uint8_t *h;\
+ dec_sample = av_clip_int16(dec_sample);\
+ d = sample - dec_sample;\
+ ssd = nodes[j]->ssd + d*d;\
+ /* Check for wraparound, skip such samples completely. \
+ * Note, changing ssd to a 64 bit variable would be \
+ * simpler, avoiding this check, but it's slower on \
+ * x86 32 bit at the moment. */\
+ if (ssd < nodes[j]->ssd)\
+ goto next_##NAME;\
+ /* Collapse any two states with the same previous sample value. \
+ * One could also distinguish states by step and by 2nd to last
+ * sample, but the effects of that are negligible.
+ * Since nodes in the previous generation are iterated
+ * through a heap, they're roughly ordered from better to
+ * worse, but not strictly ordered. Therefore, an earlier
+ * node with the same sample value is better in most cases
+ * (and thus the current is skipped), but not strictly
+ * in all cases. Only skipping samples where ssd >=
+ * ssd of the earlier node with the same sample gives
+ * slightly worse quality, though, for some reason. */ \
+ h = &hash[(uint16_t) dec_sample];\
+ if (*h == generation)\
+ goto next_##NAME;\
+ if (heap_pos < frontier) {\
+ pos = heap_pos++;\
+ } else {\
+ /* Try to replace one of the leaf nodes with the new \
+ * one, but try a different slot each time. */\
+ pos = (frontier >> 1) + (heap_pos & ((frontier >> 1) - 1));\
+ if (ssd > nodes_next[pos]->ssd)\
+ goto next_##NAME;\
+ heap_pos++;\
+ }\
+ *h = generation;\
+ u = nodes_next[pos];\
+ if(!u) {\
+ assert(pathn < FREEZE_INTERVAL<<avctx->trellis);\
+ u = t++;\
+ nodes_next[pos] = u;\
+ u->path = pathn++;\
+ }\
+ u->ssd = ssd;\
+ u->step = STEP_INDEX;\
+ u->sample2 = nodes[j]->sample1;\
+ u->sample1 = dec_sample;\
+ paths[u->path].nibble = nibble;\
+ paths[u->path].prev = nodes[j]->path;\
+ /* Sift the newly inserted node up in the heap to \
+ * restore the heap property. */\
+ while (pos > 0) {\
+ int parent = (pos - 1) >> 1;\
+ if (nodes_next[parent]->ssd <= ssd)\
+ break;\
+ FFSWAP(TrellisNode*, nodes_next[parent], nodes_next[pos]);\
+ pos = parent;\
+ }\
+ next_##NAME:;
+ STORE_NODE(ms, FFMAX(16, (ff_adpcm_AdaptationTable[nibble] * step) >> 8));
+ }
+ } else if((version == CODEC_ID_ADPCM_IMA_WAV)|| (version == CODEC_ID_ADPCM_IMA_QT)|| (version == CODEC_ID_ADPCM_SWF)) {
+#define LOOP_NODES(NAME, STEP_TABLE, STEP_INDEX)\
+ const int predictor = nodes[j]->sample1;\
+ const int div = (sample - predictor) * 4 / STEP_TABLE;\
+ int nmin = av_clip(div-range, -7, 6);\
+ int nmax = av_clip(div+range, -6, 7);\
+ if(nmin<=0) nmin--; /* distinguish -0 from +0 */\
+ if(nmax<0) nmax--;\
+ for(nidx=nmin; nidx<=nmax; nidx++) {\
+ const int nibble = nidx<0 ? 7-nidx : nidx;\
+ int dec_sample = predictor + (STEP_TABLE * ff_adpcm_yamaha_difflookup[nibble]) / 8;\
+ STORE_NODE(NAME, STEP_INDEX);\
+ }
+ LOOP_NODES(ima, ff_adpcm_step_table[step], av_clip(step + ff_adpcm_index_table[nibble], 0, 88));
+ } else { //CODEC_ID_ADPCM_YAMAHA
+ LOOP_NODES(yamaha, step, av_clip((step * ff_adpcm_yamaha_indexscale[nibble]) >> 8, 127, 24567));
+#undef LOOP_NODES
+#undef STORE_NODE
+ }
+ }
+
+ u = nodes;
+ nodes = nodes_next;
+ nodes_next = u;
+
+ generation++;
+ if (generation == 255) {
+ memset(hash, 0xff, 65536 * sizeof(*hash));
+ generation = 0;
+ }
+
+ // prevent overflow
+ if(nodes[0]->ssd > (1<<28)) {
+ for(j=1; j<frontier && nodes[j]; j++)
+ nodes[j]->ssd -= nodes[0]->ssd;
+ nodes[0]->ssd = 0;
+ }
+
+ // merge old paths to save memory
+ if(i == froze + FREEZE_INTERVAL) {
+ p = &paths[nodes[0]->path];
+ for(k=i; k>froze; k--) {
+ dst[k] = p->nibble;
+ p = &paths[p->prev];
+ }
+ froze = i;
+ pathn = 0;
+ // other nodes might use paths that don't coincide with the frozen one.
+ // checking which nodes do so is too slow, so just kill them all.
+ // this also slightly improves quality, but I don't know why.
+ memset(nodes+1, 0, (frontier-1)*sizeof(TrellisNode*));
+ }
+ }
+
+ p = &paths[nodes[0]->path];
+ for(i=n-1; i>froze; i--) {
+ dst[i] = p->nibble;
+ p = &paths[p->prev];
+ }
+
+ c->predictor = nodes[0]->sample1;
+ c->sample1 = nodes[0]->sample1;
+ c->sample2 = nodes[0]->sample2;
+ c->step_index = nodes[0]->step;
+ c->step = nodes[0]->step;
+ c->idelta = nodes[0]->step;
+}
+
+static int adpcm_encode_frame(AVCodecContext *avctx,
+ unsigned char *frame, int buf_size, void *data)
+{
+ int n, i, st;
+ short *samples;
+ unsigned char *dst;
+ ADPCMEncodeContext *c = avctx->priv_data;
+ uint8_t *buf;
+
+ dst = frame;
+ samples = (short *)data;
+ st= avctx->channels == 2;
+/* n = (BLKSIZE - 4 * avctx->channels) / (2 * 8 * avctx->channels); */
+
+ switch(avctx->codec->id) {
+ case CODEC_ID_ADPCM_IMA_WAV:
+ n = avctx->frame_size / 8;
+ c->status[0].prev_sample = (signed short)samples[0]; /* XXX */
+/* c->status[0].step_index = 0; *//* XXX: not sure how to init the state machine */
+ bytestream_put_le16(&dst, c->status[0].prev_sample);
+ *dst++ = (unsigned char)c->status[0].step_index;
+ *dst++ = 0; /* unknown */
+ samples++;
+ if (avctx->channels == 2) {
+ c->status[1].prev_sample = (signed short)samples[0];
+/* c->status[1].step_index = 0; */
+ bytestream_put_le16(&dst, c->status[1].prev_sample);
+ *dst++ = (unsigned char)c->status[1].step_index;
+ *dst++ = 0;
+ samples++;
+ }
+
+ /* stereo: 4 bytes (8 samples) for left, 4 bytes for right, 4 bytes left, ... */
+ if(avctx->trellis > 0) {
+ FF_ALLOC_OR_GOTO(avctx, buf, 2*n*8, error);
+ adpcm_compress_trellis(avctx, samples, buf, &c->status[0], n*8);
+ if(avctx->channels == 2)
+ adpcm_compress_trellis(avctx, samples+1, buf + n*8, &c->status[1], n*8);
+ for(i=0; i<n; i++) {
+ *dst++ = buf[8*i+0] | (buf[8*i+1] << 4);
+ *dst++ = buf[8*i+2] | (buf[8*i+3] << 4);
+ *dst++ = buf[8*i+4] | (buf[8*i+5] << 4);
+ *dst++ = buf[8*i+6] | (buf[8*i+7] << 4);
+ if (avctx->channels == 2) {
+ uint8_t *buf1 = buf + n*8;
+ *dst++ = buf1[8*i+0] | (buf1[8*i+1] << 4);
+ *dst++ = buf1[8*i+2] | (buf1[8*i+3] << 4);
+ *dst++ = buf1[8*i+4] | (buf1[8*i+5] << 4);
+ *dst++ = buf1[8*i+6] | (buf1[8*i+7] << 4);
+ }
+ }
+ av_free(buf);
+ } else
+ for (; n>0; n--) {
+ *dst = adpcm_ima_compress_sample(&c->status[0], samples[0]);
+ *dst |= adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels]) << 4;
+ dst++;
+ *dst = adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 2]);
+ *dst |= adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 3]) << 4;
+ dst++;
+ *dst = adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 4]);
+ *dst |= adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 5]) << 4;
+ dst++;
+ *dst = adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 6]);
+ *dst |= adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 7]) << 4;
+ dst++;
+ /* right channel */
+ if (avctx->channels == 2) {
+ *dst = adpcm_ima_compress_sample(&c->status[1], samples[1]);
+ *dst |= adpcm_ima_compress_sample(&c->status[1], samples[3]) << 4;
+ dst++;
+ *dst = adpcm_ima_compress_sample(&c->status[1], samples[5]);
+ *dst |= adpcm_ima_compress_sample(&c->status[1], samples[7]) << 4;
+ dst++;
+ *dst = adpcm_ima_compress_sample(&c->status[1], samples[9]);
+ *dst |= adpcm_ima_compress_sample(&c->status[1], samples[11]) << 4;
+ dst++;
+ *dst = adpcm_ima_compress_sample(&c->status[1], samples[13]);
+ *dst |= adpcm_ima_compress_sample(&c->status[1], samples[15]) << 4;
+ dst++;
+ }
+ samples += 8 * avctx->channels;
+ }
+ break;
+ case CODEC_ID_ADPCM_IMA_QT:
+ {
+ int ch, i;
+ PutBitContext pb;
+ init_put_bits(&pb, dst, buf_size*8);
+
+ for(ch=0; ch<avctx->channels; ch++){
+ put_bits(&pb, 9, (c->status[ch].prev_sample + 0x10000) >> 7);
+ put_bits(&pb, 7, c->status[ch].step_index);
+ if(avctx->trellis > 0) {
+ uint8_t buf[64];
+ adpcm_compress_trellis(avctx, samples+ch, buf, &c->status[ch], 64);
+ for(i=0; i<64; i++)
+ put_bits(&pb, 4, buf[i^1]);
+ } else {
+ for (i=0; i<64; i+=2){
+ int t1, t2;
+ t1 = adpcm_ima_qt_compress_sample(&c->status[ch], samples[avctx->channels*(i+0)+ch]);
+ t2 = adpcm_ima_qt_compress_sample(&c->status[ch], samples[avctx->channels*(i+1)+ch]);
+ put_bits(&pb, 4, t2);
+ put_bits(&pb, 4, t1);
+ }
+ }
+ }
+
+ flush_put_bits(&pb);
+ dst += put_bits_count(&pb)>>3;
+ break;
+ }
+ case CODEC_ID_ADPCM_SWF:
+ {
+ int i;
+ PutBitContext pb;
+ init_put_bits(&pb, dst, buf_size*8);
+
+ n = avctx->frame_size-1;
+
+ //Store AdpcmCodeSize
+ put_bits(&pb, 2, 2); //Set 4bits flash adpcm format
+
+ //Init the encoder state
+ for(i=0; i<avctx->channels; i++){
+ c->status[i].step_index = av_clip(c->status[i].step_index, 0, 63); // clip step so it fits 6 bits
+ put_sbits(&pb, 16, samples[i]);
+ put_bits(&pb, 6, c->status[i].step_index);
+ c->status[i].prev_sample = (signed short)samples[i];
+ }
+
+ if(avctx->trellis > 0) {
+ FF_ALLOC_OR_GOTO(avctx, buf, 2*n, error);
+ adpcm_compress_trellis(avctx, samples+2, buf, &c->status[0], n);
+ if (avctx->channels == 2)
+ adpcm_compress_trellis(avctx, samples+3, buf+n, &c->status[1], n);
+ for(i=0; i<n; i++) {
+ put_bits(&pb, 4, buf[i]);
+ if (avctx->channels == 2)
+ put_bits(&pb, 4, buf[n+i]);
+ }
+ av_free(buf);
+ } else {
+ for (i=1; i<avctx->frame_size; i++) {
+ put_bits(&pb, 4, adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels*i]));
+ if (avctx->channels == 2)
+ put_bits(&pb, 4, adpcm_ima_compress_sample(&c->status[1], samples[2*i+1]));
+ }
+ }
+ flush_put_bits(&pb);
+ dst += put_bits_count(&pb)>>3;
+ break;
+ }
+ case CODEC_ID_ADPCM_MS:
+ for(i=0; i<avctx->channels; i++){
+ int predictor=0;
+
+ *dst++ = predictor;
+ c->status[i].coeff1 = ff_adpcm_AdaptCoeff1[predictor];
+ c->status[i].coeff2 = ff_adpcm_AdaptCoeff2[predictor];
+ }
+ for(i=0; i<avctx->channels; i++){
+ if (c->status[i].idelta < 16)
+ c->status[i].idelta = 16;
+
+ bytestream_put_le16(&dst, c->status[i].idelta);
+ }
+ for(i=0; i<avctx->channels; i++){
+ c->status[i].sample2= *samples++;
+ }
+ for(i=0; i<avctx->channels; i++){
+ c->status[i].sample1= *samples++;
+
+ bytestream_put_le16(&dst, c->status[i].sample1);
+ }
+ for(i=0; i<avctx->channels; i++)
+ bytestream_put_le16(&dst, c->status[i].sample2);
+
+ if(avctx->trellis > 0) {
+ int n = avctx->block_align - 7*avctx->channels;
+ FF_ALLOC_OR_GOTO(avctx, buf, 2*n, error);
+ if(avctx->channels == 1) {
+ adpcm_compress_trellis(avctx, samples, buf, &c->status[0], n);
+ for(i=0; i<n; i+=2)
+ *dst++ = (buf[i] << 4) | buf[i+1];
+ } else {
+ adpcm_compress_trellis(avctx, samples, buf, &c->status[0], n);
+ adpcm_compress_trellis(avctx, samples+1, buf+n, &c->status[1], n);
+ for(i=0; i<n; i++)
+ *dst++ = (buf[i] << 4) | buf[n+i];
+ }
+ av_free(buf);
+ } else
+ for(i=7*avctx->channels; i<avctx->block_align; i++) {
+ int nibble;
+ nibble = adpcm_ms_compress_sample(&c->status[ 0], *samples++)<<4;
+ nibble|= adpcm_ms_compress_sample(&c->status[st], *samples++);
+ *dst++ = nibble;
+ }
+ break;
+ case CODEC_ID_ADPCM_YAMAHA:
+ n = avctx->frame_size / 2;
+ if(avctx->trellis > 0) {
+ FF_ALLOC_OR_GOTO(avctx, buf, 2*n*2, error);
+ n *= 2;
+ if(avctx->channels == 1) {
+ adpcm_compress_trellis(avctx, samples, buf, &c->status[0], n);
+ for(i=0; i<n; i+=2)
+ *dst++ = buf[i] | (buf[i+1] << 4);
+ } else {
+ adpcm_compress_trellis(avctx, samples, buf, &c->status[0], n);
+ adpcm_compress_trellis(avctx, samples+1, buf+n, &c->status[1], n);
+ for(i=0; i<n; i++)
+ *dst++ = buf[i] | (buf[n+i] << 4);
+ }
+ av_free(buf);
+ } else
+ for (n *= avctx->channels; n>0; n--) {
+ int nibble;
+ nibble = adpcm_yamaha_compress_sample(&c->status[ 0], *samples++);
+ nibble |= adpcm_yamaha_compress_sample(&c->status[st], *samples++) << 4;
+ *dst++ = nibble;
+ }
+ break;
+ default:
+ error:
+ return -1;
+ }
+ return dst - frame;
+}
+
+
+#define ADPCM_ENCODER(id_, name_, long_name_) \
+AVCodec ff_ ## name_ ## _encoder = { \
+ .name = #name_, \
+ .type = AVMEDIA_TYPE_AUDIO, \
+ .id = id_, \
+ .priv_data_size = sizeof(ADPCMEncodeContext), \
+ .init = adpcm_encode_init, \
+ .encode = adpcm_encode_frame, \
+ .close = adpcm_encode_close, \
+ .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, \
+ .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
+}
+
+ADPCM_ENCODER(CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt, "ADPCM IMA QuickTime");
+ADPCM_ENCODER(CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav, "ADPCM IMA WAV");
+ADPCM_ENCODER(CODEC_ID_ADPCM_MS, adpcm_ms, "ADPCM Microsoft");
+ADPCM_ENCODER(CODEC_ID_ADPCM_SWF, adpcm_swf, "ADPCM Shockwave Flash");
+ADPCM_ENCODER(CODEC_ID_ADPCM_YAMAHA, adpcm_yamaha, "ADPCM Yamaha");
diff --git a/libavcodec/adx.h b/libavcodec/adx.h
index c4206963d5..0fa1003ffc 100644
--- a/libavcodec/adx.h
+++ b/libavcodec/adx.h
@@ -2,20 +2,20 @@
* ADX ADPCM codecs
* Copyright (c) 2001,2003 BERO
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/adxdec.c b/libavcodec/adxdec.c
index 48acc659cc..df3e8dd355 100644
--- a/libavcodec/adxdec.c
+++ b/libavcodec/adxdec.c
@@ -2,20 +2,20 @@
* ADX ADPCM codecs
* Copyright (c) 2001,2003 BERO
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -167,14 +167,12 @@ static int adx_decode_frame(AVCodecContext *avctx,
}
AVCodec ff_adpcm_adx_decoder = {
- "adpcm_adx",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_ADPCM_ADX,
- sizeof(ADXContext),
- adx_decode_init,
- NULL,
- NULL,
- adx_decode_frame,
+ .name = "adpcm_adx",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_ADPCM_ADX,
+ .priv_data_size = sizeof(ADXContext),
+ .init = adx_decode_init,
+ .decode = adx_decode_frame,
.long_name = NULL_IF_CONFIG_SMALL("SEGA CRI ADX ADPCM"),
};
diff --git a/libavcodec/adxenc.c b/libavcodec/adxenc.c
index b0847f43ef..893afe0981 100644
--- a/libavcodec/adxenc.c
+++ b/libavcodec/adxenc.c
@@ -2,20 +2,20 @@
* ADX ADPCM codecs
* Copyright (c) 2001,2003 BERO
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -184,14 +184,13 @@ static int adx_encode_frame(AVCodecContext *avctx,
}
AVCodec ff_adpcm_adx_encoder = {
- "adpcm_adx",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_ADPCM_ADX,
- sizeof(ADXContext),
- adx_encode_init,
- adx_encode_frame,
- adx_encode_close,
- NULL,
+ .name = "adpcm_adx",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_ADPCM_ADX,
+ .priv_data_size = sizeof(ADXContext),
+ .init = adx_encode_init,
+ .encode = adx_encode_frame,
+ .close = adx_encode_close,
.sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
.long_name = NULL_IF_CONFIG_SMALL("SEGA CRI ADX ADPCM"),
};
diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index 4ea3f7ee84..06bf6f8c78 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -2,20 +2,20 @@
* ALAC (Apple Lossless Audio Codec) decoder
* Copyright (c) 2005 David Hammerton
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -23,9 +23,7 @@
* @file
* ALAC (Apple Lossless Audio Codec) decoder
* @author 2005 David Hammerton
- *
- * For more information on the ALAC format, visit:
- * http://crazney.net/programs/itunes/alac.html
+ * @see http://crazney.net/programs/itunes/alac.html
*
* Note: This decoder expects a 36- (0x24-)byte QuickTime atom to be
* passed through the extradata[_size] fields. This atom is tacked onto
@@ -286,20 +284,9 @@ static void predictor_decompress_fir_adapt(int32_t *error_buffer,
buffer_out[i+1] = val;
}
-#if 0
/* 4 and 8 are very common cases (the only ones i've seen). these
* should be unrolled and optimized
*/
- if (predictor_coef_num == 4) {
- /* FIXME: optimized general case */
- return;
- }
-
- if (predictor_coef_table == 8) {
- /* FIXME: optimized general case */
- return;
- }
-#endif
/* general case */
if (predictor_coef_num > 0) {
@@ -692,13 +679,12 @@ static av_cold int alac_decode_close(AVCodecContext *avctx)
}
AVCodec ff_alac_decoder = {
- "alac",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_ALAC,
- sizeof(ALACContext),
- alac_decode_init,
- NULL,
- alac_decode_close,
- alac_decode_frame,
+ .name = "alac",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_ALAC,
+ .priv_data_size = sizeof(ALACContext),
+ .init = alac_decode_init,
+ .close = alac_decode_close,
+ .decode = alac_decode_frame,
.long_name = NULL_IF_CONFIG_SMALL("ALAC (Apple Lossless Audio Codec)"),
};
diff --git a/libavcodec/alacenc.c b/libavcodec/alacenc.c
index acaa545915..c399471c1d 100644
--- a/libavcodec/alacenc.c
+++ b/libavcodec/alacenc.c
@@ -2,20 +2,20 @@
* ALAC audio encoder
* Copyright (c) 2008 Jaikrishnan Menon <realityman@gmx.net>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -389,6 +389,11 @@ static av_cold int alac_encode_init(AVCodecContext *avctx)
return -1;
}
+ if(avctx->channels > 2) {
+ av_log(avctx, AV_LOG_ERROR, "channels > 2 not supported\n");
+ return AVERROR_PATCHWELCOME;
+ }
+
// Set default compression level
if(avctx->compression_level == FF_COMPRESSION_DEFAULT)
s->compression_level = 2;
@@ -524,13 +529,13 @@ static av_cold int alac_encode_close(AVCodecContext *avctx)
}
AVCodec ff_alac_encoder = {
- "alac",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_ALAC,
- sizeof(AlacEncodeContext),
- alac_encode_init,
- alac_encode_frame,
- alac_encode_close,
+ .name = "alac",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_ALAC,
+ .priv_data_size = sizeof(AlacEncodeContext),
+ .init = alac_encode_init,
+ .encode = alac_encode_frame,
+ .close = alac_encode_close,
.capabilities = CODEC_CAP_SMALL_LAST_FRAME,
.sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE},
.long_name = NULL_IF_CONFIG_SMALL("ALAC (Apple Lossless Audio Codec)"),
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 71b6094089..fb630386d1 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -2,20 +2,20 @@
* Provide registration of all codecs, parsers and bitstream filters for libavcodec.
* Copyright (c) 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -57,8 +57,10 @@ void avcodec_register_all(void)
REGISTER_HWACCEL (H263_VAAPI, h263_vaapi);
REGISTER_HWACCEL (H264_DXVA2, h264_dxva2);
REGISTER_HWACCEL (H264_VAAPI, h264_vaapi);
+ REGISTER_HWACCEL (MPEG1_VDPAU, mpeg1_vdpau);
REGISTER_HWACCEL (MPEG2_DXVA2, mpeg2_dxva2);
REGISTER_HWACCEL (MPEG2_VAAPI, mpeg2_vaapi);
+ REGISTER_HWACCEL (MPEG2_VDPAU, mpeg2_vdpau);
REGISTER_HWACCEL (MPEG4_VAAPI, mpeg4_vaapi);
REGISTER_HWACCEL (VC1_DXVA2, vc1_dxva2);
REGISTER_HWACCEL (VC1_VAAPI, vc1_vaapi);
@@ -69,7 +71,7 @@ void avcodec_register_all(void)
REGISTER_ENCODER (A64MULTI, a64multi);
REGISTER_ENCODER (A64MULTI5, a64multi5);
REGISTER_DECODER (AASC, aasc);
- REGISTER_DECODER (AMV, amv);
+ REGISTER_ENCDEC (AMV, amv);
REGISTER_DECODER (ANM, anm);
REGISTER_DECODER (ANSI, ansi);
REGISTER_ENCDEC (ASV1, asv1);
@@ -102,10 +104,12 @@ void avcodec_register_all(void)
REGISTER_DECODER (EIGHTBPS, eightbps);
REGISTER_DECODER (EIGHTSVX_EXP, eightsvx_exp);
REGISTER_DECODER (EIGHTSVX_FIB, eightsvx_fib);
+ REGISTER_DECODER (EIGHTSVX_RAW, eightsvx_raw);
REGISTER_DECODER (ESCAPE124, escape124);
REGISTER_ENCDEC (FFV1, ffv1);
REGISTER_ENCDEC (FFVHUFF, ffvhuff);
REGISTER_ENCDEC (FLASHSV, flashsv);
+ REGISTER_ENCDEC (FLASHSV2, flashsv2);
REGISTER_DECODER (FLIC, flic);
REGISTER_ENCDEC (FLV, flv);
REGISTER_DECODER (FOURXM, fourxm);
@@ -117,6 +121,7 @@ void avcodec_register_all(void)
REGISTER_DECODER (H263I, h263i);
REGISTER_ENCODER (H263P, h263p);
REGISTER_DECODER (H264, h264);
+ REGISTER_DECODER (H264_CRYSTALHD, h264_crystalhd);
REGISTER_DECODER (H264_VDPAU, h264_vdpau);
REGISTER_ENCDEC (HUFFYUV, huffyuv);
REGISTER_DECODER (IDCIN, idcin);
@@ -126,6 +131,7 @@ void avcodec_register_all(void)
REGISTER_DECODER (INDEO3, indeo3);
REGISTER_DECODER (INDEO5, indeo5);
REGISTER_DECODER (INTERPLAY_VIDEO, interplay_video);
+ REGISTER_ENCDEC (JPEG2000, jpeg2000);
REGISTER_ENCDEC (JPEGLS, jpegls);
REGISTER_DECODER (JV, jv);
REGISTER_DECODER (KGV1, kgv1);
@@ -143,15 +149,18 @@ void avcodec_register_all(void)
REGISTER_ENCDEC (MPEG1VIDEO, mpeg1video);
REGISTER_ENCDEC (MPEG2VIDEO, mpeg2video);
REGISTER_ENCDEC (MPEG4, mpeg4);
+ REGISTER_DECODER (MPEG4_CRYSTALHD, mpeg4_crystalhd);
REGISTER_DECODER (MPEG4_VDPAU, mpeg4_vdpau);
REGISTER_DECODER (MPEGVIDEO, mpegvideo);
REGISTER_DECODER (MPEG_VDPAU, mpeg_vdpau);
REGISTER_DECODER (MPEG1_VDPAU, mpeg1_vdpau);
+ REGISTER_DECODER (MPEG2_CRYSTALHD, mpeg2_crystalhd);
+ REGISTER_DECODER (MSMPEG4_CRYSTALHD, msmpeg4_crystalhd);
REGISTER_DECODER (MSMPEG4V1, msmpeg4v1);
REGISTER_ENCDEC (MSMPEG4V2, msmpeg4v2);
REGISTER_ENCDEC (MSMPEG4V3, msmpeg4v3);
REGISTER_DECODER (MSRLE, msrle);
- REGISTER_DECODER (MSVIDEO1, msvideo1);
+ REGISTER_ENCDEC (MSVIDEO1, msvideo1);
REGISTER_DECODER (MSZH, mszh);
REGISTER_DECODER (MXPEG, mxpeg);
REGISTER_DECODER (NUV, nuv);
@@ -163,6 +172,8 @@ void avcodec_register_all(void)
REGISTER_DECODER (PICTOR, pictor);
REGISTER_ENCDEC (PNG, png);
REGISTER_ENCDEC (PPM, ppm);
+ REGISTER_DECODER (PRORES, prores);
+ REGISTER_DECODER (PRORES_LGPL, prores_lgpl);
REGISTER_DECODER (PTX, ptx);
REGISTER_DECODER (QDRAW, qdraw);
REGISTER_DECODER (QPEG, qpeg);
@@ -197,11 +208,14 @@ void avcodec_register_all(void)
REGISTER_DECODER (TSCC, tscc);
REGISTER_DECODER (TXD, txd);
REGISTER_DECODER (ULTI, ulti);
+ REGISTER_DECODER (UTVIDEO, utvideo);
REGISTER_ENCDEC (V210, v210);
REGISTER_DECODER (V210X, v210x);
REGISTER_DECODER (VB, vb);
REGISTER_DECODER (VC1, vc1);
+ REGISTER_DECODER (VC1_CRYSTALHD, vc1_crystalhd);
REGISTER_DECODER (VC1_VDPAU, vc1_vdpau);
+ REGISTER_DECODER (VC1IMAGE, vc1image);
REGISTER_DECODER (VCR1, vcr1);
REGISTER_DECODER (VMDVIDEO, vmdvideo);
REGISTER_DECODER (VMNC, vmnc);
@@ -215,7 +229,9 @@ void avcodec_register_all(void)
REGISTER_ENCDEC (WMV1, wmv1);
REGISTER_ENCDEC (WMV2, wmv2);
REGISTER_DECODER (WMV3, wmv3);
+ REGISTER_DECODER (WMV3_CRYSTALHD, wmv3_crystalhd);
REGISTER_DECODER (WMV3_VDPAU, wmv3_vdpau);
+ REGISTER_DECODER (WMV3IMAGE, wmv3image);
REGISTER_DECODER (WNV1, wnv1);
REGISTER_DECODER (XAN_WC3, xan_wc3);
REGISTER_DECODER (XAN_WC4, xan_wc4);
@@ -239,10 +255,12 @@ void avcodec_register_all(void)
REGISTER_DECODER (BINKAUDIO_DCT, binkaudio_dct);
REGISTER_DECODER (BINKAUDIO_RDFT, binkaudio_rdft);
REGISTER_DECODER (COOK, cook);
- REGISTER_DECODER (DCA, dca);
+ REGISTER_ENCDEC (DCA, dca);
REGISTER_DECODER (DSICINAUDIO, dsicinaudio);
REGISTER_ENCDEC (EAC3, eac3);
REGISTER_ENCDEC (FLAC, flac);
+ REGISTER_ENCDEC (G723_1, g723_1);
+ REGISTER_DECODER (G729, g729);
REGISTER_DECODER (GSM, gsm);
REGISTER_DECODER (GSM_MS, gsm_ms);
REGISTER_DECODER (IMC, imc);
@@ -269,6 +287,8 @@ void avcodec_register_all(void)
REGISTER_DECODER (SHORTEN, shorten);
REGISTER_DECODER (SIPR, sipr);
REGISTER_DECODER (SMACKAUD, smackaud);
+ REGISTER_ENCDEC (SONIC, sonic);
+ REGISTER_ENCODER (SONIC_LS, sonic_ls);
REGISTER_DECODER (TRUEHD, truehd);
REGISTER_DECODER (TRUESPEECH, truespeech);
REGISTER_DECODER (TTA, tta);
@@ -352,10 +372,12 @@ void avcodec_register_all(void)
REGISTER_ENCDEC (DVBSUB, dvbsub);
REGISTER_ENCDEC (DVDSUB, dvdsub);
REGISTER_DECODER (PGSSUB, pgssub);
- REGISTER_DECODER (SRT, srt);
+ REGISTER_ENCDEC (SRT, srt);
REGISTER_ENCDEC (XSUB, xsub);
/* external libraries */
+ REGISTER_ENCODER (LIBAACPLUS, libaacplus);
+ REGISTER_DECODER (LIBCELT, libcelt);
REGISTER_ENCDEC (LIBDIRAC, libdirac);
REGISTER_ENCODER (LIBFAAC, libfaac);
REGISTER_ENCDEC (LIBGSM, libgsm);
@@ -365,8 +387,10 @@ void avcodec_register_all(void)
REGISTER_DECODER (LIBOPENCORE_AMRWB, libopencore_amrwb);
REGISTER_DECODER (LIBOPENJPEG, libopenjpeg);
REGISTER_ENCDEC (LIBSCHROEDINGER, libschroedinger);
- REGISTER_DECODER (LIBSPEEX, libspeex);
+ REGISTER_ENCDEC (LIBSPEEX, libspeex);
+ REGISTER_DECODER (LIBSTAGEFRIGHT_H264, libstagefright_h264);
REGISTER_ENCODER (LIBTHEORA, libtheora);
+ REGISTER_DECODER (LIBUTVIDEO, libutvideo);
REGISTER_ENCODER (LIBVO_AACENC, libvo_aacenc);
REGISTER_ENCODER (LIBVO_AMRWBENC, libvo_amrwbenc);
REGISTER_ENCODER (LIBVORBIS, libvorbis);
@@ -375,6 +399,11 @@ void avcodec_register_all(void)
REGISTER_ENCODER (LIBXAVS, libxavs);
REGISTER_ENCODER (LIBXVID, libxvid);
+ /* text */
+ REGISTER_DECODER (BINTEXT, bintext);
+ REGISTER_DECODER (XBIN, xbin);
+ REGISTER_DECODER (IDF, idf);
+
/* parsers */
REGISTER_PARSER (AAC, aac);
REGISTER_PARSER (AAC_LATM, aac_latm);
@@ -395,6 +424,8 @@ void avcodec_register_all(void)
REGISTER_PARSER (MPEGAUDIO, mpegaudio);
REGISTER_PARSER (MPEGVIDEO, mpegvideo);
REGISTER_PARSER (PNM, pnm);
+ REGISTER_PARSER (RV30, rv30);
+ REGISTER_PARSER (RV40, rv40);
REGISTER_PARSER (VC1, vc1);
REGISTER_PARSER (VP3, vp3);
REGISTER_PARSER (VP8, vp8);
diff --git a/libavcodec/alpha/asm.h b/libavcodec/alpha/asm.h
index ab4cfccc87..827721e777 100644
--- a/libavcodec/alpha/asm.h
+++ b/libavcodec/alpha/asm.h
@@ -2,20 +2,20 @@
* Alpha optimized DSP utils
* Copyright (c) 2002 Falk Hueffner <falk@debian.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/alpha/dsputil_alpha.c b/libavcodec/alpha/dsputil_alpha.c
index 32bb0fc932..d8f999dfdc 100644
--- a/libavcodec/alpha/dsputil_alpha.c
+++ b/libavcodec/alpha/dsputil_alpha.c
@@ -2,20 +2,20 @@
* Alpha optimized DSP utils
* Copyright (c) 2002 Falk Hueffner <falk@debian.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -270,7 +270,7 @@ static void put_pixels16_axp_asm(uint8_t *block, const uint8_t *pixels,
void dsputil_init_alpha(DSPContext* c, AVCodecContext *avctx)
{
- const int high_bit_depth = avctx->codec_id == CODEC_ID_H264 && avctx->bits_per_raw_sample > 8;
+ const int high_bit_depth = avctx->bits_per_raw_sample > 8;
if (!high_bit_depth) {
c->put_pixels_tab[0][0] = put_pixels16_axp_asm;
@@ -321,7 +321,8 @@ void dsputil_init_alpha(DSPContext* c, AVCodecContext *avctx)
c->put_pixels_clamped = put_pixels_clamped_mvi_asm;
c->add_pixels_clamped = add_pixels_clamped_mvi_asm;
- c->get_pixels = get_pixels_mvi;
+ if (!high_bit_depth)
+ c->get_pixels = get_pixels_mvi;
c->diff_pixels = diff_pixels_mvi;
c->sad[0] = pix_abs16x16_mvi_asm;
c->sad[1] = pix_abs8x8_mvi;
@@ -335,7 +336,7 @@ void dsputil_init_alpha(DSPContext* c, AVCodecContext *avctx)
put_pixels_clamped_axp_p = c->put_pixels_clamped;
add_pixels_clamped_axp_p = c->add_pixels_clamped;
- if (!avctx->lowres &&
+ if (!avctx->lowres && avctx->bits_per_raw_sample <= 8 &&
(avctx->idct_algo == FF_IDCT_AUTO ||
avctx->idct_algo == FF_IDCT_SIMPLEALPHA)) {
c->idct_put = ff_simple_idct_put_axp;
diff --git a/libavcodec/alpha/dsputil_alpha.h b/libavcodec/alpha/dsputil_alpha.h
index 0dcacabb9d..a3fa3dd586 100644
--- a/libavcodec/alpha/dsputil_alpha.h
+++ b/libavcodec/alpha/dsputil_alpha.h
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/alpha/dsputil_alpha_asm.S b/libavcodec/alpha/dsputil_alpha_asm.S
index ca857ac152..32a8bc9562 100644
--- a/libavcodec/alpha/dsputil_alpha_asm.S
+++ b/libavcodec/alpha/dsputil_alpha_asm.S
@@ -2,20 +2,20 @@
* Alpha optimized DSP utils
* Copyright (c) 2002 Falk Hueffner <falk@debian.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/alpha/motion_est_alpha.c b/libavcodec/alpha/motion_est_alpha.c
index bb9ab134e9..863dd23da3 100644
--- a/libavcodec/alpha/motion_est_alpha.c
+++ b/libavcodec/alpha/motion_est_alpha.c
@@ -2,20 +2,20 @@
* Alpha optimized DSP utils
* Copyright (c) 2002 Falk Hueffner <falk@debian.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/alpha/motion_est_mvi_asm.S b/libavcodec/alpha/motion_est_mvi_asm.S
index 7fe4e168e0..2399085bcb 100644
--- a/libavcodec/alpha/motion_est_mvi_asm.S
+++ b/libavcodec/alpha/motion_est_mvi_asm.S
@@ -2,20 +2,20 @@
* Alpha optimized DSP utils
* Copyright (c) 2002 Falk Hueffner <falk@debian.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/alpha/mpegvideo_alpha.c b/libavcodec/alpha/mpegvideo_alpha.c
index add57364a3..de32545ade 100644
--- a/libavcodec/alpha/mpegvideo_alpha.c
+++ b/libavcodec/alpha/mpegvideo_alpha.c
@@ -2,20 +2,20 @@
* Alpha optimized DSP utils
* Copyright (c) 2002 Falk Hueffner <falk@debian.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/alpha/regdef.h b/libavcodec/alpha/regdef.h
index fa9ad98e5c..aa1959f46e 100644
--- a/libavcodec/alpha/regdef.h
+++ b/libavcodec/alpha/regdef.h
@@ -2,20 +2,20 @@
* Alpha optimized DSP utils
* copyright (c) 2002 Falk Hueffner <falk@debian.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/alpha/simple_idct_alpha.c b/libavcodec/alpha/simple_idct_alpha.c
index 61bc5f2084..522efd2b4d 100644
--- a/libavcodec/alpha/simple_idct_alpha.c
+++ b/libavcodec/alpha/simple_idct_alpha.c
@@ -9,20 +9,20 @@
* Alpha optimizations by Måns Rullgård <mans@mansr.com>
* and Falk Hueffner <falk@debian.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/alsdec.c b/libavcodec/alsdec.c
index 055bfd0d04..661f264cbf 100644
--- a/libavcodec/alsdec.c
+++ b/libavcodec/alsdec.c
@@ -2,20 +2,20 @@
* MPEG-4 ALS decoder
* Copyright (c) 2009 Thilo Borgmann <thilo.borgmann _at_ googlemail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -289,7 +289,7 @@ static av_cold int read_specific_config(ALSDecContext *ctx)
init_get_bits(&gb, avctx->extradata, avctx->extradata_size * 8);
- config_offset = ff_mpeg4audio_get_config(&m4ac, avctx->extradata,
+ config_offset = avpriv_mpeg4audio_get_config(&m4ac, avctx->extradata,
avctx->extradata_size);
if (config_offset < 0)
@@ -1739,14 +1739,13 @@ static av_cold void flush(AVCodecContext *avctx)
AVCodec ff_als_decoder = {
- "als",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_MP4ALS,
- sizeof(ALSDecContext),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
+ .name = "als",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_MP4ALS,
+ .priv_data_size = sizeof(ALSDecContext),
+ .init = decode_init,
+ .close = decode_end,
+ .decode = decode_frame,
.flush = flush,
.capabilities = CODEC_CAP_SUBFRAMES,
.long_name = NULL_IF_CONFIG_SMALL("MPEG-4 Audio Lossless Coding (ALS)"),
diff --git a/libavcodec/amr.h b/libavcodec/amr.h
index ae6e4d1490..7e5a4dce5b 100644
--- a/libavcodec/amr.h
+++ b/libavcodec/amr.h
@@ -3,20 +3,20 @@
*
* Copyright (c) 2010 Marcelo Galvao Povoa
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/amrnbdata.h b/libavcodec/amrnbdata.h
index d6d1f34562..2f21439896 100644
--- a/libavcodec/amrnbdata.h
+++ b/libavcodec/amrnbdata.h
@@ -3,20 +3,20 @@
* Copyright (c) 2006-2007 Robert Swain
* Copyright (c) 2009 Colin McQuillan
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/amrnbdec.c b/libavcodec/amrnbdec.c
index 1c90aadb12..b8d826e139 100644
--- a/libavcodec/amrnbdec.c
+++ b/libavcodec/amrnbdec.c
@@ -3,20 +3,20 @@
* Copyright (c) 2006-2007 Robert Swain
* Copyright (c) 2009 Colin McQuillan
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -936,7 +936,8 @@ static int amrnb_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
p->cur_frame_mode = unpack_bitstream(p, buf, buf_size);
if (p->cur_frame_mode == MODE_DTX) {
- av_log_missing_feature(avctx, "dtx mode", 1);
+ av_log_missing_feature(avctx, "dtx mode", 0);
+ av_log(avctx, AV_LOG_INFO, "Note: libopencore_amrnb supports dtx\n");
return -1;
}
diff --git a/libavcodec/amrwbdata.h b/libavcodec/amrwbdata.h
index 5421c23afb..1327b0237a 100644
--- a/libavcodec/amrwbdata.h
+++ b/libavcodec/amrwbdata.h
@@ -2,20 +2,20 @@
* AMR wideband data and definitions
* Copyright (c) 2010 Marcelo Galvao Povoa
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/amrwbdec.c b/libavcodec/amrwbdec.c
index d4bb7760ef..fa3f8dd050 100644
--- a/libavcodec/amrwbdec.c
+++ b/libavcodec/amrwbdec.c
@@ -2,20 +2,20 @@
* AMR wideband decoder
* Copyright (c) 2010 Marcelo Galvao Povoa
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/anm.c b/libavcodec/anm.c
index ef037f2468..188f8296f3 100644
--- a/libavcodec/anm.c
+++ b/libavcodec/anm.c
@@ -2,20 +2,20 @@
* Deluxe Paint Animation decoder
* Copyright (c) 2009 Peter Ross
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -29,6 +29,7 @@
typedef struct AnmContext {
AVFrame frame;
+ int palette[AVPALETTE_COUNT];
int x; ///< x coordinate position
} AnmContext;
@@ -43,15 +44,12 @@ static av_cold int decode_init(AVCodecContext *avctx)
if (avctx->extradata_size != 16*8 + 4*256)
return -1;
+ avcodec_get_frame_defaults(&s->frame);
s->frame.reference = 1;
- if (avctx->get_buffer(avctx, &s->frame) < 0) {
- av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
- return -1;
- }
buf = avctx->extradata + 16*8;
for (i = 0; i < 256; i++)
- ((uint32_t*)s->frame.data[1])[i] = bytestream_get_le32(&buf);
+ s->palette[i] = bytestream_get_le32(&buf);
return 0;
}
@@ -81,6 +79,8 @@ static inline int op(uint8_t **dst, const uint8_t *dst_end,
int striplen = FFMIN(count, remaining);
if (buf) {
striplen = FFMIN(striplen, buf_end - *buf);
+ if (*buf >= buf_end)
+ goto exhausted;
memcpy(*dst, *buf, striplen);
*buf += striplen;
} else if (pixel >= 0)
@@ -170,6 +170,8 @@ static int decode_frame(AVCodecContext *avctx,
}
} while (buf + 1 < buf_end);
+ memcpy(s->frame.data[1], s->palette, AVPALETTE_SIZE);
+
*data_size = sizeof(AVFrame);
*(AVFrame*)data = s->frame;
return buf_size;
@@ -184,14 +186,13 @@ static av_cold int decode_end(AVCodecContext *avctx)
}
AVCodec ff_anm_decoder = {
- "anm",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_ANM,
- sizeof(AnmContext),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- CODEC_CAP_DR1,
+ .name = "anm",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_ANM,
+ .priv_data_size = sizeof(AnmContext),
+ .init = decode_init,
+ .close = decode_end,
+ .decode = decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Deluxe Paint Animation"),
};
diff --git a/libavcodec/ansi.c b/libavcodec/ansi.c
index 32c7ce4ecd..ebcc288539 100644
--- a/libavcodec/ansi.c
+++ b/libavcodec/ansi.c
@@ -2,20 +2,20 @@
* ASCII/ANSI art decoder
* Copyright (c) 2010 Peter Ross <pross@xvid.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -81,6 +81,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
s->fg = DEFAULT_FG_COLOR;
s->bg = DEFAULT_BG_COLOR;
+ avcodec_get_frame_defaults(&s->frame);
if (!avctx->width || !avctx->height)
avcodec_set_dimensions(avctx, 80<<3, 25<<4);
diff --git a/libavcodec/apedec.c b/libavcodec/apedec.c
index f92b37527e..300a0097d8 100644
--- a/libavcodec/apedec.c
+++ b/libavcodec/apedec.c
@@ -3,20 +3,20 @@
* Copyright (c) 2007 Benjamin Zores <ben@geexbox.org>
* based upon libdemac from Dave Chapman.
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -885,14 +885,13 @@ static void ape_flush(AVCodecContext *avctx)
}
AVCodec ff_ape_decoder = {
- "ape",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_APE,
- sizeof(APEContext),
- ape_decode_init,
- NULL,
- ape_decode_close,
- ape_decode_frame,
+ .name = "ape",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_APE,
+ .priv_data_size = sizeof(APEContext),
+ .init = ape_decode_init,
+ .close = ape_decode_close,
+ .decode = ape_decode_frame,
.capabilities = CODEC_CAP_SUBFRAMES,
.flush = ape_flush,
.long_name = NULL_IF_CONFIG_SMALL("Monkey's Audio"),
diff --git a/libavcodec/arm/Makefile b/libavcodec/arm/Makefile
index 3374f0e2bd..cc5a2a7d39 100644
--- a/libavcodec/arm/Makefile
+++ b/libavcodec/arm/Makefile
@@ -11,7 +11,8 @@ ARMV6-OBJS-$(CONFIG_MPEGAUDIODSP) += arm/mpegaudiodsp_fixed_armv6.o
OBJS-$(CONFIG_VP5_DECODER) += arm/vp56dsp_init_arm.o
OBJS-$(CONFIG_VP6_DECODER) += arm/vp56dsp_init_arm.o
OBJS-$(CONFIG_VP8_DECODER) += arm/vp8dsp_init_arm.o
-ARMV6-OBJS-$(CONFIG_VP8_DECODER) += arm/vp8_armv6.o
+ARMV6-OBJS-$(CONFIG_VP8_DECODER) += arm/vp8_armv6.o \
+ arm/vp8dsp_armv6.o
OBJS-$(CONFIG_H264DSP) += arm/h264dsp_init_arm.o
OBJS-$(CONFIG_H264PRED) += arm/h264pred_init_arm.o
diff --git a/libavcodec/arm/aac.h b/libavcodec/arm/aac.h
index 83b5aef1b6..bd4d293f02 100644
--- a/libavcodec/arm/aac.h
+++ b/libavcodec/arm/aac.h
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2010 Mans Rullgard <mans@mansr.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/arm/ac3dsp_armv6.S b/libavcodec/arm/ac3dsp_armv6.S
index d3058ffcec..b6aee867b3 100644
--- a/libavcodec/arm/ac3dsp_armv6.S
+++ b/libavcodec/arm/ac3dsp_armv6.S
@@ -37,7 +37,7 @@ function ff_ac3_bit_alloc_calc_bap_armv6, export=1
ldrb r10, [r4], #1
1:
ldrsh r9, [r0], #2 @ mask[band]
- movw r8, #0x1fe0
+ mov r8, #0xff0
sub r9, r9, r12 @ - snr_offset
mov r11, r10
ldrb r10, [r4], #1 @ band_start_tab[band++]
@@ -45,7 +45,7 @@ function ff_ac3_bit_alloc_calc_bap_armv6, export=1
it lt
movlt r9, #0
cmp r10, r3 @ - end
- and r9, r9, r8 @ & 0x1fe0
+ and r9, r9, r8, lsl #1 @ & 0x1fe0
ite gt
subgt r8, r3, r11
suble r8, r10, r11
diff --git a/libavcodec/arm/ac3dsp_init_arm.c b/libavcodec/arm/ac3dsp_init_arm.c
index de29f27162..8ab685496d 100644
--- a/libavcodec/arm/ac3dsp_init_arm.c
+++ b/libavcodec/arm/ac3dsp_init_arm.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2011 Mans Rullgard <mans@mansr.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/arm/asm-offsets.h b/libavcodec/arm/asm-offsets.h
index 110d33dbb5..17a540031b 100644
--- a/libavcodec/arm/asm-offsets.h
+++ b/libavcodec/arm/asm-offsets.h
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2010 Mans Rullgard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -29,11 +29,11 @@
#endif
/* MpegEncContext */
-#define Y_DC_SCALE 0xb4
-#define C_DC_SCALE 0xb8
-#define AC_PRED 0xbc
-#define BLOCK_LAST_INDEX 0xc0
-#define H263_AIC 0xf0
-#define INTER_SCANTAB_RASTER_END 0x138
+#define Y_DC_SCALE 0xac
+#define C_DC_SCALE 0xb0
+#define AC_PRED 0xb4
+#define BLOCK_LAST_INDEX 0xb8
+#define H263_AIC 0xe8
+#define INTER_SCANTAB_RASTER_END 0x130
#endif /* AVCODEC_ARM_ASM_OFFSETS_H */
diff --git a/libavcodec/arm/asm.S b/libavcodec/arm/asm.S
index a7d3ace208..856d2e986f 100644
--- a/libavcodec/arm/asm.S
+++ b/libavcodec/arm/asm.S
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2008 Mans Rullgard <mans@mansr.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -97,6 +97,12 @@ T add \rn, \rn, \rm
T ldr \rt, [\rn]
.endm
+.macro ldr_dpren rt, rn, rm:vararg
+A ldr \rt, [\rn, -\rm]
+T sub \rt, \rn, \rm
+T ldr \rt, [\rt]
+.endm
+
.macro ldr_post rt, rn, rm:vararg
A ldr \rt, [\rn], \rm
T ldr \rt, [\rn]
@@ -133,6 +139,12 @@ T ldrh \rt, [\rn]
T add \rn, \rn, \rm
.endm
+.macro ldrb_post rt, rn, rm
+A ldrb \rt, [\rn], \rm
+T ldrb \rt, [\rn]
+T add \rn, \rn, \rm
+.endm
+
.macro str_post rt, rn, rm:vararg
A str \rt, [\rn], \rm
T str \rt, [\rn]
diff --git a/libavcodec/arm/dca.h b/libavcodec/arm/dca.h
new file mode 100644
index 0000000000..38c8d1f9cc
--- /dev/null
+++ b/libavcodec/arm/dca.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2011 Mans Rullgard <mans@mansr.com>
+ *
+ * This file is part of Libav.
+ *
+ * Libav 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.
+ *
+ * Libav 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_ARM_DCA_H
+#define AVCODEC_ARM_DCA_H
+
+#include <stdint.h>
+#include "config.h"
+
+#if HAVE_NEON && HAVE_INLINE_ASM && HAVE_ASM_MOD_Y
+
+#define int8x8_fmul_int32 int8x8_fmul_int32
+static inline void int8x8_fmul_int32(float *dst, const int8_t *src, int scale)
+{
+ __asm__ ("vcvt.f32.s32 %2, %2, #4 \n"
+ "vld1.8 {d0}, [%1,:64] \n"
+ "vmovl.s8 q0, d0 \n"
+ "vmovl.s16 q1, d1 \n"
+ "vmovl.s16 q0, d0 \n"
+ "vcvt.f32.s32 q0, q0 \n"
+ "vcvt.f32.s32 q1, q1 \n"
+ "vmul.f32 q0, q0, %y2 \n"
+ "vmul.f32 q1, q1, %y2 \n"
+ "vst1.32 {q0-q1}, [%m0,:128] \n"
+ : "=Um"(*(float (*)[8])dst)
+ : "r"(src), "x"(scale)
+ : "d0", "d1", "d2", "d3");
+}
+
+#endif
+
+#endif /* AVCODEC_ARM_DCA_H */
diff --git a/libavcodec/arm/dcadsp_init_arm.c b/libavcodec/arm/dcadsp_init_arm.c
index b5ac2068d5..5663cd7fc2 100644
--- a/libavcodec/arm/dcadsp_init_arm.c
+++ b/libavcodec/arm/dcadsp_init_arm.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2010 Mans Rullgard <mans@mansr.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/arm/dcadsp_neon.S b/libavcodec/arm/dcadsp_neon.S
index 71f5dd843b..852527a59e 100644
--- a/libavcodec/arm/dcadsp_neon.S
+++ b/libavcodec/arm/dcadsp_neon.S
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2010 Mans Rullgard <mans@mansr.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/arm/dsputil_arm.S b/libavcodec/arm/dsputil_arm.S
index 136551f4c9..1247b0fa84 100644
--- a/libavcodec/arm/dsputil_arm.S
+++ b/libavcodec/arm/dsputil_arm.S
@@ -2,20 +2,20 @@
@ ARMv4 optimized DSP utils
@ Copyright (c) 2004 AGAWA Koji <i (AT) atty (DOT) jp>
@
-@ This file is part of Libav.
+@ This file is part of FFmpeg.
@
-@ Libav is free software; you can redistribute it and/or
+@ FFmpeg 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.
@
-@ Libav is distributed in the hope that it will be useful,
+@ FFmpeg 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
@ Lesser General Public License for more details.
@
@ You should have received a copy of the GNU Lesser General Public
-@ License along with Libav; if not, write to the Free Software
+@ License along with FFmpeg; if not, write to the Free Software
@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
@
diff --git a/libavcodec/arm/dsputil_arm.h b/libavcodec/arm/dsputil_arm.h
index 6d7e6a6d16..b333c70226 100644
--- a/libavcodec/arm/dsputil_arm.h
+++ b/libavcodec/arm/dsputil_arm.h
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2009 Mans Rullgard <mans@mansr.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/arm/dsputil_armv6.S b/libavcodec/arm/dsputil_armv6.S
index b8461059d9..a2c8588fad 100644
--- a/libavcodec/arm/dsputil_armv6.S
+++ b/libavcodec/arm/dsputil_armv6.S
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2009 Mans Rullgard <mans@mansr.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/arm/dsputil_init_arm.c b/libavcodec/arm/dsputil_init_arm.c
index 777a2f954e..ccbe1ed296 100644
--- a/libavcodec/arm/dsputil_init_arm.c
+++ b/libavcodec/arm/dsputil_init_arm.c
@@ -2,20 +2,20 @@
* ARM optimized DSP utils
* Copyright (c) 2001 Lionel Ulmer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -75,12 +75,12 @@ static void simple_idct_arm_add(uint8_t *dest, int line_size, DCTELEM *block)
void dsputil_init_arm(DSPContext* c, AVCodecContext *avctx)
{
- const int high_bit_depth = avctx->codec_id == CODEC_ID_H264 && avctx->bits_per_raw_sample > 8;
+ const int high_bit_depth = avctx->bits_per_raw_sample > 8;
ff_put_pixels_clamped = c->put_pixels_clamped;
ff_add_pixels_clamped = c->add_pixels_clamped;
- if (!avctx->lowres) {
+ if (!avctx->lowres && avctx->bits_per_raw_sample <= 8) {
if(avctx->idct_algo == FF_IDCT_AUTO ||
avctx->idct_algo == FF_IDCT_ARM){
c->idct_put = j_rev_dct_arm_put;
diff --git a/libavcodec/arm/dsputil_init_armv5te.c b/libavcodec/arm/dsputil_init_armv5te.c
index 572e06cf36..2390aabb62 100644
--- a/libavcodec/arm/dsputil_init_armv5te.c
+++ b/libavcodec/arm/dsputil_init_armv5te.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2009 Mans Rullgard <mans@mansr.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -29,8 +29,9 @@ void ff_prefetch_arm(void *mem, int stride, int h);
void av_cold ff_dsputil_init_armv5te(DSPContext* c, AVCodecContext *avctx)
{
- if (!avctx->lowres && (avctx->idct_algo == FF_IDCT_AUTO ||
- avctx->idct_algo == FF_IDCT_SIMPLEARMV5TE)) {
+ if (!avctx->lowres && avctx->bits_per_raw_sample <= 8 &&
+ (avctx->idct_algo == FF_IDCT_AUTO ||
+ avctx->idct_algo == FF_IDCT_SIMPLEARMV5TE)) {
c->idct_put = ff_simple_idct_put_armv5te;
c->idct_add = ff_simple_idct_add_armv5te;
c->idct = ff_simple_idct_armv5te;
diff --git a/libavcodec/arm/dsputil_init_armv6.c b/libavcodec/arm/dsputil_init_armv6.c
index 7584aeefc6..fb0d00973e 100644
--- a/libavcodec/arm/dsputil_init_armv6.c
+++ b/libavcodec/arm/dsputil_init_armv6.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2009 Mans Rullgard <mans@mansr.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -72,10 +72,11 @@ int ff_pix_sum_armv6(uint8_t *pix, int line_size);
void av_cold ff_dsputil_init_armv6(DSPContext* c, AVCodecContext *avctx)
{
- const int high_bit_depth = avctx->codec_id == CODEC_ID_H264 && avctx->bits_per_raw_sample > 8;
+ const int high_bit_depth = avctx->bits_per_raw_sample > 8;
- if (!avctx->lowres && (avctx->idct_algo == FF_IDCT_AUTO ||
- avctx->idct_algo == FF_IDCT_SIMPLEARMV6)) {
+ if (!avctx->lowres && avctx->bits_per_raw_sample <= 8 &&
+ (avctx->idct_algo == FF_IDCT_AUTO ||
+ avctx->idct_algo == FF_IDCT_SIMPLEARMV6)) {
c->idct_put = ff_simple_idct_put_armv6;
c->idct_add = ff_simple_idct_add_armv6;
c->idct = ff_simple_idct_armv6;
@@ -105,8 +106,9 @@ void av_cold ff_dsputil_init_armv6(DSPContext* c, AVCodecContext *avctx)
c->avg_pixels_tab[1][0] = ff_avg_pixels8_armv6;
}
+ if (!high_bit_depth)
+ c->get_pixels = ff_get_pixels_armv6;
c->add_pixels_clamped = ff_add_pixels_clamped_armv6;
- c->get_pixels = ff_get_pixels_armv6;
c->diff_pixels = ff_diff_pixels_armv6;
c->pix_abs[0][0] = ff_pix_abs16_armv6;
diff --git a/libavcodec/arm/dsputil_init_neon.c b/libavcodec/arm/dsputil_init_neon.c
index 3f58dea9cd..ddc9d640f8 100644
--- a/libavcodec/arm/dsputil_init_neon.c
+++ b/libavcodec/arm/dsputil_init_neon.c
@@ -2,20 +2,20 @@
* ARM NEON optimised DSP functions
* Copyright (c) 2008 Mans Rullgard <mans@mansr.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -143,14 +143,8 @@ void ff_vector_fmul_window_neon(float *dst, const float *src0,
const float *src1, const float *win, int len);
void ff_vector_fmul_scalar_neon(float *dst, const float *src, float mul,
int len);
-void ff_vector_fmul_sv_scalar_2_neon(float *dst, const float *src,
- const float **vp, float mul, int len);
-void ff_vector_fmul_sv_scalar_4_neon(float *dst, const float *src,
- const float **vp, float mul, int len);
-void ff_sv_fmul_scalar_2_neon(float *dst, const float **vp, float mul,
- int len);
-void ff_sv_fmul_scalar_4_neon(float *dst, const float **vp, float mul,
- int len);
+void ff_vector_fmac_scalar_neon(float *dst, const float *src, float mul,
+ int len);
void ff_butterflies_float_neon(float *v1, float *v2, int len);
float ff_scalarproduct_float_neon(const float *v1, const float *v2, int len);
void ff_vector_fmul_reverse_neon(float *dst, const float *src0,
@@ -175,9 +169,9 @@ void ff_apply_window_int16_neon(int16_t *dst, const int16_t *src,
void ff_dsputil_init_neon(DSPContext *c, AVCodecContext *avctx)
{
- const int high_bit_depth = avctx->codec_id == CODEC_ID_H264 && avctx->bits_per_raw_sample > 8;
+ const int high_bit_depth = avctx->bits_per_raw_sample > 8;
- if (!avctx->lowres) {
+ if (!avctx->lowres && avctx->bits_per_raw_sample <= 8) {
if (avctx->idct_algo == FF_IDCT_AUTO ||
avctx->idct_algo == FF_IDCT_SIMPLENEON) {
c->idct_put = ff_simple_idct_put_neon;
@@ -313,6 +307,7 @@ void ff_dsputil_init_neon(DSPContext *c, AVCodecContext *avctx)
c->vector_fmul = ff_vector_fmul_neon;
c->vector_fmul_window = ff_vector_fmul_window_neon;
c->vector_fmul_scalar = ff_vector_fmul_scalar_neon;
+ c->vector_fmac_scalar = ff_vector_fmac_scalar_neon;
c->butterflies_float = ff_butterflies_float_neon;
c->scalarproduct_float = ff_scalarproduct_float_neon;
c->vector_fmul_reverse = ff_vector_fmul_reverse_neon;
@@ -320,12 +315,6 @@ void ff_dsputil_init_neon(DSPContext *c, AVCodecContext *avctx)
c->vector_clipf = ff_vector_clipf_neon;
c->vector_clip_int32 = ff_vector_clip_int32_neon;
- c->vector_fmul_sv_scalar[0] = ff_vector_fmul_sv_scalar_2_neon;
- c->vector_fmul_sv_scalar[1] = ff_vector_fmul_sv_scalar_4_neon;
-
- c->sv_fmul_scalar[0] = ff_sv_fmul_scalar_2_neon;
- c->sv_fmul_scalar[1] = ff_sv_fmul_scalar_4_neon;
-
if (CONFIG_VORBIS_DECODER)
c->vorbis_inverse_coupling = ff_vorbis_inverse_coupling_neon;
diff --git a/libavcodec/arm/dsputil_init_vfp.c b/libavcodec/arm/dsputil_init_vfp.c
index 9cda890411..ee092dca10 100644
--- a/libavcodec/arm/dsputil_init_vfp.c
+++ b/libavcodec/arm/dsputil_init_vfp.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2008 Siarhei Siamashka <ssvb@users.sourceforge.net>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/arm/dsputil_iwmmxt.c b/libavcodec/arm/dsputil_iwmmxt.c
index 86f8fddfcf..2837af119f 100644
--- a/libavcodec/arm/dsputil_iwmmxt.c
+++ b/libavcodec/arm/dsputil_iwmmxt.c
@@ -2,20 +2,20 @@
* iWMMXt optimized DSP utils
* Copyright (c) 2004 AGAWA Koji
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -155,7 +155,7 @@ static void nop(uint8_t *block, const uint8_t *pixels, int line_size, int h)
void ff_dsputil_init_iwmmxt(DSPContext* c, AVCodecContext *avctx)
{
int mm_flags = AV_CPU_FLAG_IWMMXT; /* multimedia extension flags */
- const int high_bit_depth = avctx->codec_id == CODEC_ID_H264 && avctx->bits_per_raw_sample > 8;
+ const int high_bit_depth = avctx->bits_per_raw_sample > 8;
if (avctx->dsp_mask) {
if (avctx->dsp_mask & AV_CPU_FLAG_FORCE)
diff --git a/libavcodec/arm/dsputil_iwmmxt_rnd_template.c b/libavcodec/arm/dsputil_iwmmxt_rnd_template.c
index df0ead6d80..35a5a9b8b4 100644
--- a/libavcodec/arm/dsputil_iwmmxt_rnd_template.c
+++ b/libavcodec/arm/dsputil_iwmmxt_rnd_template.c
@@ -2,20 +2,20 @@
* iWMMXt optimized DSP utils
* copyright (c) 2004 AGAWA Koji
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/arm/dsputil_neon.S b/libavcodec/arm/dsputil_neon.S
index 3b9b542a68..1574ad6496 100644
--- a/libavcodec/arm/dsputil_neon.S
+++ b/libavcodec/arm/dsputil_neon.S
@@ -2,20 +2,20 @@
* ARM NEON optimised DSP functions
* Copyright (c) 2008 Mans Rullgard <mans@mansr.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -587,106 +587,50 @@ NOVFP vdup.32 q8, r2
.unreq len
endfunc
-function ff_vector_fmul_sv_scalar_2_neon, export=1
-VFP vdup.32 d16, d0[0]
-NOVFP vdup.32 d16, r3
-NOVFP ldr r3, [sp]
- vld1.32 {d0},[r1,:64]!
- vld1.32 {d1},[r1,:64]!
-1: subs r3, r3, #4
- vmul.f32 d4, d0, d16
- vmul.f32 d5, d1, d16
- ldr r12, [r2], #4
- vld1.32 {d2},[r12,:64]
- ldr r12, [r2], #4
- vld1.32 {d3},[r12,:64]
- vmul.f32 d4, d4, d2
- vmul.f32 d5, d5, d3
- beq 2f
- vld1.32 {d0},[r1,:64]!
- vld1.32 {d1},[r1,:64]!
- vst1.32 {d4},[r0,:64]!
- vst1.32 {d5},[r0,:64]!
- b 1b
-2: vst1.32 {d4},[r0,:64]!
- vst1.32 {d5},[r0,:64]!
- bx lr
-endfunc
-
-function ff_vector_fmul_sv_scalar_4_neon, export=1
-VFP vdup.32 q10, d0[0]
-NOVFP vdup.32 q10, r3
-NOVFP ldr r3, [sp]
- push {lr}
- bics lr, r3, #7
- beq 3f
- vld1.32 {q0},[r1,:128]!
- vld1.32 {q2},[r1,:128]!
-1: ldr r12, [r2], #4
- vld1.32 {q1},[r12,:128]
- ldr r12, [r2], #4
- vld1.32 {q3},[r12,:128]
- vmul.f32 q8, q0, q10
- vmul.f32 q8, q8, q1
- vmul.f32 q9, q2, q10
- vmul.f32 q9, q9, q3
- subs lr, lr, #8
- beq 2f
- vld1.32 {q0},[r1,:128]!
- vld1.32 {q2},[r1,:128]!
- vst1.32 {q8},[r0,:128]!
- vst1.32 {q9},[r0,:128]!
- b 1b
-2: vst1.32 {q8},[r0,:128]!
- vst1.32 {q9},[r0,:128]!
- ands r3, r3, #7
- it eq
- popeq {pc}
-3: vld1.32 {q0},[r1,:128]!
- ldr r12, [r2], #4
- vld1.32 {q1},[r12,:128]
- vmul.f32 q0, q0, q10
- vmul.f32 q0, q0, q1
- vst1.32 {q0},[r0,:128]!
- subs r3, r3, #4
- bgt 3b
- pop {pc}
-endfunc
-
-function ff_sv_fmul_scalar_2_neon, export=1
+function ff_vector_fmac_scalar_neon, export=1
VFP len .req r2
+VFP acc .req r3
NOVFP len .req r3
-VFP vdup.32 q8, d0[0]
-NOVFP vdup.32 q8, r2
- ldr r12, [r1], #4
- vld1.32 {d0},[r12,:64]
- ldr r12, [r1], #4
- vld1.32 {d1},[r12,:64]
-1: vmul.f32 q1, q0, q8
- subs len, len, #4
+NOVFP acc .req r2
+VFP vdup.32 q15, d0[0]
+NOVFP vdup.32 q15, r2
+ bics r12, len, #15
+ mov acc, r0
+ beq 3f
+ vld1.32 {q0}, [r1,:128]!
+ vld1.32 {q8}, [acc,:128]!
+ vld1.32 {q1}, [r1,:128]!
+ vld1.32 {q9}, [acc,:128]!
+1: vmla.f32 q8, q0, q15
+ vld1.32 {q2}, [r1,:128]!
+ vld1.32 {q10}, [acc,:128]!
+ vmla.f32 q9, q1, q15
+ vld1.32 {q3}, [r1,:128]!
+ vld1.32 {q11}, [acc,:128]!
+ vmla.f32 q10, q2, q15
+ vst1.32 {q8}, [r0,:128]!
+ vmla.f32 q11, q3, q15
+ vst1.32 {q9}, [r0,:128]!
+ subs r12, r12, #16
beq 2f
- ldr r12, [r1], #4
- vld1.32 {d0},[r12,:64]
- ldr r12, [r1], #4
- vld1.32 {d1},[r12,:64]
- vst1.32 {q1},[r0,:128]!
+ vld1.32 {q0}, [r1,:128]!
+ vld1.32 {q8}, [acc,:128]!
+ vst1.32 {q10}, [r0,:128]!
+ vld1.32 {q1}, [r1,:128]!
+ vld1.32 {q9}, [acc,:128]!
+ vst1.32 {q11}, [r0,:128]!
b 1b
-2: vst1.32 {q1},[r0,:128]!
- bx lr
- .unreq len
-endfunc
-
-function ff_sv_fmul_scalar_4_neon, export=1
-VFP len .req r2
-NOVFP len .req r3
-VFP vdup.32 q8, d0[0]
-NOVFP vdup.32 q8, r2
-1: ldr r12, [r1], #4
- vld1.32 {q0},[r12,:128]
- vmul.f32 q0, q0, q8
- vst1.32 {q0},[r0,:128]!
+2: vst1.32 {q10}, [r0,:128]!
+ vst1.32 {q11}, [r0,:128]!
+ ands len, len, #15
+ it eq
+ bxeq lr
+3: vld1.32 {q0}, [r1,:128]!
+ vld1.32 {q8}, [acc,:128]!
+ vmla.f32 q8, q0, q15
+ vst1.32 {q8}, [r0,:128]!
subs len, len, #4
- bgt 1b
+ bgt 3b
bx lr
.unreq len
endfunc
diff --git a/libavcodec/arm/dsputil_vfp.S b/libavcodec/arm/dsputil_vfp.S
index cbc4bd6c70..108208174d 100644
--- a/libavcodec/arm/dsputil_vfp.S
+++ b/libavcodec/arm/dsputil_vfp.S
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2008 Siarhei Siamashka <ssvb@users.sourceforge.net>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/arm/fft_fixed_init_arm.c b/libavcodec/arm/fft_fixed_init_arm.c
index be412cde05..df71e7fe09 100644
--- a/libavcodec/arm/fft_fixed_init_arm.c
+++ b/libavcodec/arm/fft_fixed_init_arm.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2009 Mans Rullgard <mans@mansr.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFMpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/arm/fft_fixed_neon.S b/libavcodec/arm/fft_fixed_neon.S
index 0508088590..0316b80bce 100644
--- a/libavcodec/arm/fft_fixed_neon.S
+++ b/libavcodec/arm/fft_fixed_neon.S
@@ -122,7 +122,7 @@ endfunc
function fft_pass_neon
push {r4,lr}
- movrel lr, coefs + 24
+ movrel lr, coefs+24
vld1.16 {d30}, [lr,:64]
lsl r12, r2, #3
vmov d31, d30
diff --git a/libavcodec/arm/fft_init_arm.c b/libavcodec/arm/fft_init_arm.c
index 4ee4909682..3e0e41ec3b 100644
--- a/libavcodec/arm/fft_init_arm.c
+++ b/libavcodec/arm/fft_init_arm.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2009 Mans Rullgard <mans@mansr.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/arm/fft_neon.S b/libavcodec/arm/fft_neon.S
index 887621834e..fd76edcd15 100644
--- a/libavcodec/arm/fft_neon.S
+++ b/libavcodec/arm/fft_neon.S
@@ -7,20 +7,20 @@
* This algorithm (though not any of the implementation details) is
* based on libdjbfft by D. J. Bernstein.
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -349,9 +349,7 @@ function ff_fft_permute_neon, export=1
pop {r4,pc}
endfunc
- .section .rodata
- .align 4
-fft_tab_neon:
+const fft_tab_neon
.word fft4_neon
.word fft8_neon
.word fft16_neon
@@ -367,8 +365,12 @@ fft_tab_neon:
.word fft16384_neon
.word fft32768_neon
.word fft65536_neon
-ELF .size fft_tab_neon, . - fft_tab_neon
+endconst
- .align 4
-pmmp: .float +1.0, -1.0, -1.0, +1.0
-mppm: .float -M_SQRT1_2, M_SQRT1_2, M_SQRT1_2, -M_SQRT1_2
+const pmmp, align=4
+ .float +1.0, -1.0, -1.0, +1.0
+endconst
+
+const mppm, align=4
+ .float -M_SQRT1_2, M_SQRT1_2, M_SQRT1_2, -M_SQRT1_2
+endconst
diff --git a/libavcodec/arm/fmtconvert_init_arm.c b/libavcodec/arm/fmtconvert_init_arm.c
index 92e07f17a0..4b6e3939f5 100644
--- a/libavcodec/arm/fmtconvert_init_arm.c
+++ b/libavcodec/arm/fmtconvert_init_arm.c
@@ -1,20 +1,20 @@
/*
* ARM optimized Format Conversion Utils
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/arm/fmtconvert_neon.S b/libavcodec/arm/fmtconvert_neon.S
index 45cc84b7ec..d1ad32ed27 100644
--- a/libavcodec/arm/fmtconvert_neon.S
+++ b/libavcodec/arm/fmtconvert_neon.S
@@ -2,20 +2,20 @@
* ARM NEON optimised Format Conversion Utils
* Copyright (c) 2008 Mans Rullgard <mans@mansr.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/arm/fmtconvert_vfp.S b/libavcodec/arm/fmtconvert_vfp.S
index f7b0e3dcb5..7e2eb83620 100644
--- a/libavcodec/arm/fmtconvert_vfp.S
+++ b/libavcodec/arm/fmtconvert_vfp.S
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2008 Siarhei Siamashka <ssvb@users.sourceforge.net>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/arm/h264dsp_init_arm.c b/libavcodec/arm/h264dsp_init_arm.c
index c2399e50ff..cc4c688c8b 100644
--- a/libavcodec/arm/h264dsp_init_arm.c
+++ b/libavcodec/arm/h264dsp_init_arm.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2010 Mans Rullgard <mans@mansr.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -32,47 +32,22 @@ void ff_h264_v_loop_filter_chroma_neon(uint8_t *pix, int stride, int alpha,
void ff_h264_h_loop_filter_chroma_neon(uint8_t *pix, int stride, int alpha,
int beta, int8_t *tc0);
-void ff_weight_h264_pixels_16x16_neon(uint8_t *ds, int stride, int log2_den,
- int weight, int offset);
-void ff_weight_h264_pixels_16x8_neon(uint8_t *ds, int stride, int log2_den,
- int weight, int offset);
-void ff_weight_h264_pixels_8x16_neon(uint8_t *ds, int stride, int log2_den,
- int weight, int offset);
-void ff_weight_h264_pixels_8x8_neon(uint8_t *ds, int stride, int log2_den,
- int weight, int offset);
-void ff_weight_h264_pixels_8x4_neon(uint8_t *ds, int stride, int log2_den,
- int weight, int offset);
-void ff_weight_h264_pixels_4x8_neon(uint8_t *ds, int stride, int log2_den,
- int weight, int offset);
-void ff_weight_h264_pixels_4x4_neon(uint8_t *ds, int stride, int log2_den,
- int weight, int offset);
-void ff_weight_h264_pixels_4x2_neon(uint8_t *ds, int stride, int log2_den,
- int weight, int offset);
+void ff_weight_h264_pixels_16_neon(uint8_t *dst, int stride, int height,
+ int log2_den, int weight, int offset);
+void ff_weight_h264_pixels_8_neon(uint8_t *dst, int stride, int height,
+ int log2_den, int weight, int offset);
+void ff_weight_h264_pixels_4_neon(uint8_t *dst, int stride, int height,
+ int log2_den, int weight, int offset);
-void ff_biweight_h264_pixels_16x16_neon(uint8_t *dst, uint8_t *src, int stride,
- int log2_den, int weightd, int weights,
- int offset);
-void ff_biweight_h264_pixels_16x8_neon(uint8_t *dst, uint8_t *src, int stride,
- int log2_den, int weightd, int weights,
- int offset);
-void ff_biweight_h264_pixels_8x16_neon(uint8_t *dst, uint8_t *src, int stride,
- int log2_den, int weightd, int weights,
- int offset);
-void ff_biweight_h264_pixels_8x8_neon(uint8_t *dst, uint8_t *src, int stride,
- int log2_den, int weightd, int weights,
- int offset);
-void ff_biweight_h264_pixels_8x4_neon(uint8_t *dst, uint8_t *src, int stride,
- int log2_den, int weightd, int weights,
- int offset);
-void ff_biweight_h264_pixels_4x8_neon(uint8_t *dst, uint8_t *src, int stride,
- int log2_den, int weightd, int weights,
- int offset);
-void ff_biweight_h264_pixels_4x4_neon(uint8_t *dst, uint8_t *src, int stride,
- int log2_den, int weightd, int weights,
- int offset);
-void ff_biweight_h264_pixels_4x2_neon(uint8_t *dst, uint8_t *src, int stride,
- int log2_den, int weightd, int weights,
- int offset);
+void ff_biweight_h264_pixels_16_neon(uint8_t *dst, uint8_t *src, int stride,
+ int height, int log2_den, int weightd,
+ int weights, int offset);
+void ff_biweight_h264_pixels_8_neon(uint8_t *dst, uint8_t *src, int stride,
+ int height, int log2_den, int weightd,
+ int weights, int offset);
+void ff_biweight_h264_pixels_4_neon(uint8_t *dst, uint8_t *src, int stride,
+ int height, int log2_den, int weightd,
+ int weights, int offset);
void ff_h264_idct_add_neon(uint8_t *dst, DCTELEM *block, int stride);
void ff_h264_idct_dc_add_neon(uint8_t *dst, DCTELEM *block, int stride);
@@ -92,44 +67,37 @@ void ff_h264_idct8_add4_neon(uint8_t *dst, const int *block_offset,
DCTELEM *block, int stride,
const uint8_t nnzc[6*8]);
-static void ff_h264dsp_init_neon(H264DSPContext *c, const int bit_depth)
+static void ff_h264dsp_init_neon(H264DSPContext *c, const int bit_depth, const int chroma_format_idc)
{
if (bit_depth == 8) {
c->h264_v_loop_filter_luma = ff_h264_v_loop_filter_luma_neon;
c->h264_h_loop_filter_luma = ff_h264_h_loop_filter_luma_neon;
+ if(chroma_format_idc == 1){
c->h264_v_loop_filter_chroma = ff_h264_v_loop_filter_chroma_neon;
c->h264_h_loop_filter_chroma = ff_h264_h_loop_filter_chroma_neon;
+ }
- c->weight_h264_pixels_tab[0] = ff_weight_h264_pixels_16x16_neon;
- c->weight_h264_pixels_tab[1] = ff_weight_h264_pixels_16x8_neon;
- c->weight_h264_pixels_tab[2] = ff_weight_h264_pixels_8x16_neon;
- c->weight_h264_pixels_tab[3] = ff_weight_h264_pixels_8x8_neon;
- c->weight_h264_pixels_tab[4] = ff_weight_h264_pixels_8x4_neon;
- c->weight_h264_pixels_tab[5] = ff_weight_h264_pixels_4x8_neon;
- c->weight_h264_pixels_tab[6] = ff_weight_h264_pixels_4x4_neon;
- c->weight_h264_pixels_tab[7] = ff_weight_h264_pixels_4x2_neon;
+ c->weight_h264_pixels_tab[0] = ff_weight_h264_pixels_16_neon;
+ c->weight_h264_pixels_tab[1] = ff_weight_h264_pixels_8_neon;
+ c->weight_h264_pixels_tab[2] = ff_weight_h264_pixels_4_neon;
- c->biweight_h264_pixels_tab[0] = ff_biweight_h264_pixels_16x16_neon;
- c->biweight_h264_pixels_tab[1] = ff_biweight_h264_pixels_16x8_neon;
- c->biweight_h264_pixels_tab[2] = ff_biweight_h264_pixels_8x16_neon;
- c->biweight_h264_pixels_tab[3] = ff_biweight_h264_pixels_8x8_neon;
- c->biweight_h264_pixels_tab[4] = ff_biweight_h264_pixels_8x4_neon;
- c->biweight_h264_pixels_tab[5] = ff_biweight_h264_pixels_4x8_neon;
- c->biweight_h264_pixels_tab[6] = ff_biweight_h264_pixels_4x4_neon;
- c->biweight_h264_pixels_tab[7] = ff_biweight_h264_pixels_4x2_neon;
+ c->biweight_h264_pixels_tab[0] = ff_biweight_h264_pixels_16_neon;
+ c->biweight_h264_pixels_tab[1] = ff_biweight_h264_pixels_8_neon;
+ c->biweight_h264_pixels_tab[2] = ff_biweight_h264_pixels_4_neon;
c->h264_idct_add = ff_h264_idct_add_neon;
c->h264_idct_dc_add = ff_h264_idct_dc_add_neon;
c->h264_idct_add16 = ff_h264_idct_add16_neon;
c->h264_idct_add16intra = ff_h264_idct_add16intra_neon;
- c->h264_idct_add8 = ff_h264_idct_add8_neon;
+ if (chroma_format_idc == 1)
+ c->h264_idct_add8 = ff_h264_idct_add8_neon;
c->h264_idct8_add = ff_h264_idct8_add_neon;
c->h264_idct8_dc_add = ff_h264_idct8_dc_add_neon;
c->h264_idct8_add4 = ff_h264_idct8_add4_neon;
}
}
-void ff_h264dsp_init_arm(H264DSPContext *c, const int bit_depth)
+void ff_h264dsp_init_arm(H264DSPContext *c, const int bit_depth, const int chroma_format_idc)
{
- if (HAVE_NEON) ff_h264dsp_init_neon(c, bit_depth);
+ if (HAVE_NEON) ff_h264dsp_init_neon(c, bit_depth, chroma_format_idc);
}
diff --git a/libavcodec/arm/h264dsp_neon.S b/libavcodec/arm/h264dsp_neon.S
index 0fa4a6b0a5..6426f46637 100644
--- a/libavcodec/arm/h264dsp_neon.S
+++ b/libavcodec/arm/h264dsp_neon.S
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2008 Mans Rullgard <mans@mansr.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -1592,7 +1592,7 @@ endfunc
vdup.8 d1, r5
vmov q2, q8
vmov q3, q8
-1: subs ip, ip, #2
+1: subs r3, r3, #2
vld1.8 {d20-d21},[r0,:128], r2
\macd q2, d0, d20
pld [r0]
@@ -1632,7 +1632,7 @@ endfunc
vdup.8 d1, r5
vmov q1, q8
vmov q10, q8
-1: subs ip, ip, #2
+1: subs r3, r3, #2
vld1.8 {d4},[r0,:64], r2
\macd q1, d0, d4
pld [r0]
@@ -1662,7 +1662,7 @@ endfunc
vdup.8 d1, r5
vmov q1, q8
vmov q10, q8
-1: subs ip, ip, #4
+1: subs r3, r3, #4
vld1.32 {d4[0]},[r0,:32], r2
vld1.32 {d4[1]},[r0,:32], r2
\macd q1, d0, d4
@@ -1700,16 +1700,17 @@ endfunc
.endm
.macro biweight_func w
-function biweight_h264_pixels_\w\()_neon
+function ff_biweight_h264_pixels_\w\()_neon, export=1
push {r4-r6, lr}
- add r4, sp, #16
+ ldr r12, [sp, #16]
+ add r4, sp, #20
ldm r4, {r4-r6}
lsr lr, r4, #31
add r6, r6, #1
eors lr, lr, r5, lsr #30
orr r6, r6, #1
- vdup.16 q9, r3
- lsl r6, r6, r3
+ vdup.16 q9, r12
+ lsl r6, r6, r12
vmvn q9, q9
vdup.16 q8, r6
mov r6, r0
@@ -1730,34 +1731,15 @@ function biweight_h264_pixels_\w\()_neon
endfunc
.endm
- .macro biweight_entry w, h, b=1
-function ff_biweight_h264_pixels_\w\()x\h\()_neon, export=1
- mov ip, #\h
-.if \b
- b biweight_h264_pixels_\w\()_neon
-.endif
-endfunc
- .endm
-
- biweight_entry 16, 8
- biweight_entry 16, 16, b=0
biweight_func 16
-
- biweight_entry 8, 16
- biweight_entry 8, 4
- biweight_entry 8, 8, b=0
biweight_func 8
-
- biweight_entry 4, 8
- biweight_entry 4, 2
- biweight_entry 4, 4, b=0
biweight_func 4
@ Weighted prediction
.macro weight_16 add
- vdup.8 d0, r3
-1: subs ip, ip, #2
+ vdup.8 d0, r12
+1: subs r2, r2, #2
vld1.8 {d20-d21},[r0,:128], r1
vmull.u8 q2, d0, d20
pld [r0]
@@ -1785,8 +1767,8 @@ endfunc
.endm
.macro weight_8 add
- vdup.8 d0, r3
-1: subs ip, ip, #2
+ vdup.8 d0, r12
+1: subs r2, r2, #2
vld1.8 {d4},[r0,:64], r1
vmull.u8 q1, d0, d4
pld [r0]
@@ -1806,10 +1788,10 @@ endfunc
.endm
.macro weight_4 add
- vdup.8 d0, r3
+ vdup.8 d0, r12
vmov q1, q8
vmov q10, q8
-1: subs ip, ip, #4
+1: subs r2, r2, #4
vld1.32 {d4[0]},[r0,:32], r1
vld1.32 {d4[1]},[r0,:32], r1
vmull.u8 q1, d0, d4
@@ -1842,50 +1824,32 @@ endfunc
.endm
.macro weight_func w
-function weight_h264_pixels_\w\()_neon
+function ff_weight_h264_pixels_\w\()_neon, export=1
push {r4, lr}
- ldr r4, [sp, #8]
- cmp r2, #1
- lsl r4, r4, r2
+ ldr r12, [sp, #8]
+ ldr r4, [sp, #12]
+ cmp r3, #1
+ lsl r4, r4, r3
vdup.16 q8, r4
mov r4, r0
ble 20f
- rsb lr, r2, #1
+ rsb lr, r3, #1
vdup.16 q9, lr
- cmp r3, #0
+ cmp r12, #0
blt 10f
weight_\w vhadd.s16
-10: rsb r3, r3, #0
+10: rsb r12, r12, #0
weight_\w vhsub.s16
-20: rsb lr, r2, #0
+20: rsb lr, r3, #0
vdup.16 q9, lr
- cmp r3, #0
+ cmp r12, #0
blt 10f
weight_\w vadd.s16
-10: rsb r3, r3, #0
+10: rsb r12, r12, #0
weight_\w vsub.s16
endfunc
.endm
- .macro weight_entry w, h, b=1
-function ff_weight_h264_pixels_\w\()x\h\()_neon, export=1
- mov ip, #\h
-.if \b
- b weight_h264_pixels_\w\()_neon
-.endif
-endfunc
- .endm
-
- weight_entry 16, 8
- weight_entry 16, 16, b=0
weight_func 16
-
- weight_entry 8, 16
- weight_entry 8, 4
- weight_entry 8, 8, b=0
weight_func 8
-
- weight_entry 4, 8
- weight_entry 4, 2
- weight_entry 4, 4, b=0
weight_func 4
diff --git a/libavcodec/arm/h264idct_neon.S b/libavcodec/arm/h264idct_neon.S
index eadf2e711d..8cf9bd8b66 100644
--- a/libavcodec/arm/h264idct_neon.S
+++ b/libavcodec/arm/h264idct_neon.S
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2008 Mans Rullgard <mans@mansr.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -383,8 +383,8 @@ function ff_h264_idct8_add4_neon, export=1
pop {r4-r8,pc}
endfunc
- .section .rodata
-scan8: .byte 4+ 1*8, 5+ 1*8, 4+ 2*8, 5+ 2*8
+const scan8
+ .byte 4+ 1*8, 5+ 1*8, 4+ 2*8, 5+ 2*8
.byte 6+ 1*8, 7+ 1*8, 6+ 2*8, 7+ 2*8
.byte 4+ 3*8, 5+ 3*8, 4+ 4*8, 5+ 4*8
.byte 6+ 3*8, 7+ 3*8, 6+ 4*8, 7+ 4*8
@@ -396,3 +396,4 @@ scan8: .byte 4+ 1*8, 5+ 1*8, 4+ 2*8, 5+ 2*8
.byte 6+11*8, 7+11*8, 6+12*8, 7+12*8
.byte 4+13*8, 5+13*8, 4+14*8, 5+14*8
.byte 6+13*8, 7+13*8, 6+14*8, 7+14*8
+endconst
diff --git a/libavcodec/arm/h264pred_init_arm.c b/libavcodec/arm/h264pred_init_arm.c
index e96f339a55..75653ff7a5 100644
--- a/libavcodec/arm/h264pred_init_arm.c
+++ b/libavcodec/arm/h264pred_init_arm.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2009 Mans Rullgard <mans@mansr.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -42,13 +42,13 @@ void ff_pred8x8_0lt_dc_neon(uint8_t *src, int stride);
void ff_pred8x8_l00_dc_neon(uint8_t *src, int stride);
void ff_pred8x8_0l0_dc_neon(uint8_t *src, int stride);
-static void ff_h264_pred_init_neon(H264PredContext *h, int codec_id, const int bit_depth)
+static void ff_h264_pred_init_neon(H264PredContext *h, int codec_id, const int bit_depth, const int chroma_format_idc)
{
const int high_depth = bit_depth > 8;
if (high_depth)
return;
-
+ if(chroma_format_idc == 1){
h->pred8x8[VERT_PRED8x8 ] = ff_pred8x8_vert_neon;
h->pred8x8[HOR_PRED8x8 ] = ff_pred8x8_hor_neon;
if (codec_id != CODEC_ID_VP8)
@@ -63,6 +63,7 @@ static void ff_h264_pred_init_neon(H264PredContext *h, int codec_id, const int b
h->pred8x8[ALZHEIMER_DC_L00_PRED8x8] = ff_pred8x8_l00_dc_neon;
h->pred8x8[ALZHEIMER_DC_0L0_PRED8x8] = ff_pred8x8_0l0_dc_neon;
}
+ }
h->pred16x16[DC_PRED8x8 ] = ff_pred16x16_dc_neon;
h->pred16x16[VERT_PRED8x8 ] = ff_pred16x16_vert_neon;
@@ -74,7 +75,7 @@ static void ff_h264_pred_init_neon(H264PredContext *h, int codec_id, const int b
h->pred16x16[PLANE_PRED8x8 ] = ff_pred16x16_plane_neon;
}
-void ff_h264_pred_init_arm(H264PredContext *h, int codec_id, int bit_depth)
+void ff_h264_pred_init_arm(H264PredContext *h, int codec_id, int bit_depth, const int chroma_format_idc)
{
- if (HAVE_NEON) ff_h264_pred_init_neon(h, codec_id, bit_depth);
+ if (HAVE_NEON) ff_h264_pred_init_neon(h, codec_id, bit_depth, chroma_format_idc);
}
diff --git a/libavcodec/arm/h264pred_neon.S b/libavcodec/arm/h264pred_neon.S
index fe8a369a90..0dac20b4a0 100644
--- a/libavcodec/arm/h264pred_neon.S
+++ b/libavcodec/arm/h264pred_neon.S
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2009 Mans Rullgard <mans@mansr.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -166,12 +166,9 @@ function ff_pred16x16_plane_neon, export=1
bx lr
endfunc
- .section .rodata
- .align 4
-p16weight:
+const p16weight, align=4
.short 1,2,3,4,5,6,7,8
-
- .text
+endconst
function ff_pred8x8_hor_neon, export=1
sub r2, r0, #1
diff --git a/libavcodec/arm/int_neon.S b/libavcodec/arm/int_neon.S
index 5a149912f4..e8023e0686 100644
--- a/libavcodec/arm/int_neon.S
+++ b/libavcodec/arm/int_neon.S
@@ -2,20 +2,20 @@
* ARM NEON optimised integer operations
* Copyright (c) 2009 Kostya Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/arm/mathops.h b/libavcodec/arm/mathops.h
index 3803fcde8c..d67714c496 100644
--- a/libavcodec/arm/mathops.h
+++ b/libavcodec/arm/mathops.h
@@ -2,20 +2,20 @@
* simple math operations
* Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at> et al
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/arm/mdct_neon.S b/libavcodec/arm/mdct_neon.S
index 1ba3067c4e..2def704497 100644
--- a/libavcodec/arm/mdct_neon.S
+++ b/libavcodec/arm/mdct_neon.S
@@ -2,20 +2,20 @@
* ARM NEON optimised MDCT
* Copyright (c) 2009 Mans Rullgard <mans@mansr.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/arm/mpegvideo_arm.c b/libavcodec/arm/mpegvideo_arm.c
index b1d1312943..6cb1bc8582 100644
--- a/libavcodec/arm/mpegvideo_arm.c
+++ b/libavcodec/arm/mpegvideo_arm.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2002 Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/arm/mpegvideo_arm.h b/libavcodec/arm/mpegvideo_arm.h
index a36da6112b..3549bb244b 100644
--- a/libavcodec/arm/mpegvideo_arm.h
+++ b/libavcodec/arm/mpegvideo_arm.h
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/arm/mpegvideo_armv5te.c b/libavcodec/arm/mpegvideo_armv5te.c
index 30197d8bc1..1d383cae1e 100644
--- a/libavcodec/arm/mpegvideo_armv5te.c
+++ b/libavcodec/arm/mpegvideo_armv5te.c
@@ -2,20 +2,20 @@
* Optimization of some functions from mpegvideo.c for armv5te
* Copyright (c) 2007 Siarhei Siamashka <ssvb@users.sourceforge.net>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/arm/mpegvideo_armv5te_s.S b/libavcodec/arm/mpegvideo_armv5te_s.S
index 952c8d74cb..3db9c734e9 100644
--- a/libavcodec/arm/mpegvideo_armv5te_s.S
+++ b/libavcodec/arm/mpegvideo_armv5te_s.S
@@ -2,20 +2,20 @@
* Optimization of some functions from mpegvideo.c for armv5te
* Copyright (c) 2007 Siarhei Siamashka <ssvb@users.sourceforge.net>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/arm/mpegvideo_iwmmxt.c b/libavcodec/arm/mpegvideo_iwmmxt.c
index 4d5edd8050..bb47c0d321 100644
--- a/libavcodec/arm/mpegvideo_iwmmxt.c
+++ b/libavcodec/arm/mpegvideo_iwmmxt.c
@@ -1,20 +1,20 @@
/*
* copyright (c) 2004 AGAWA Koji
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -93,29 +93,9 @@ static void dct_unquantize_h263_intra_iwmmxt(MpegEncContext *s,
block_orig[0] = level;
}
-#if 0
-static void dct_unquantize_h263_inter_iwmmxt(MpegEncContext *s,
- DCTELEM *block, int n, int qscale)
-{
- int nCoeffs;
-
- assert(s->block_last_index[n]>=0);
-
- if(s->ac_pred)
- nCoeffs=63;
- else
- nCoeffs= s->inter_scantable.raster_end[ s->block_last_index[n] ];
-
- ippiQuantInvInter_Compact_H263_16s_I(block, nCoeffs+1, qscale);
-}
-#endif
-
void MPV_common_init_iwmmxt(MpegEncContext *s)
{
if (!(mm_flags & AV_CPU_FLAG_IWMMXT)) return;
s->dct_unquantize_h263_intra = dct_unquantize_h263_intra_iwmmxt;
-#if 0
- s->dct_unquantize_h263_inter = dct_unquantize_h263_inter_iwmmxt;
-#endif
}
diff --git a/libavcodec/arm/mpegvideo_neon.S b/libavcodec/arm/mpegvideo_neon.S
index 206a71a14d..849047e13c 100644
--- a/libavcodec/arm/mpegvideo_neon.S
+++ b/libavcodec/arm/mpegvideo_neon.S
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2010 Mans Rullgard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/arm/rdft_neon.S b/libavcodec/arm/rdft_neon.S
index fba275eb8c..19886e6d0b 100644
--- a/libavcodec/arm/rdft_neon.S
+++ b/libavcodec/arm/rdft_neon.S
@@ -2,20 +2,20 @@
* ARM NEON optimised RDFT
* Copyright (c) 2009 Mans Rullgard <mans@mansr.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/arm/simple_idct_arm.S b/libavcodec/arm/simple_idct_arm.S
index 717b12c64b..990dde6ff7 100644
--- a/libavcodec/arm/simple_idct_arm.S
+++ b/libavcodec/arm/simple_idct_arm.S
@@ -5,22 +5,22 @@
* Author: Frederic Boulay <dilb@handhelds.org>
*
* The function defined in this file is derived from the simple_idct function
- * from the libavcodec library part of the Libav project.
+ * from the libavcodec library part of the FFmpeg project.
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/arm/simple_idct_armv5te.S b/libavcodec/arm/simple_idct_armv5te.S
index 24641e47b6..71727ceccc 100644
--- a/libavcodec/arm/simple_idct_armv5te.S
+++ b/libavcodec/arm/simple_idct_armv5te.S
@@ -4,20 +4,20 @@
* Copyright (c) 2001 Michael Niedermayer <michaelni@gmx.at>
* Copyright (c) 2006 Mans Rullgard <mans@mansr.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/arm/simple_idct_armv6.S b/libavcodec/arm/simple_idct_armv6.S
index 284eb1f941..a176b3a7b4 100644
--- a/libavcodec/arm/simple_idct_armv6.S
+++ b/libavcodec/arm/simple_idct_armv6.S
@@ -4,20 +4,20 @@
* Copyright (c) 2001 Michael Niedermayer <michaelni@gmx.at>
* Copyright (c) 2007 Mans Rullgard <mans@mansr.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/arm/simple_idct_neon.S b/libavcodec/arm/simple_idct_neon.S
index cbed9eefe4..5df8f6e4fc 100644
--- a/libavcodec/arm/simple_idct_neon.S
+++ b/libavcodec/arm/simple_idct_neon.S
@@ -6,20 +6,20 @@
* Based on Simple IDCT
* Copyright (c) 2001 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -243,10 +243,9 @@ function idct_col4_st8_neon
bx lr
endfunc
- .section .rodata
- .align 4
-idct_coeff_neon:
+const idct_coeff_neon, align=4
.short W1, W2, W3, W4, W5, W6, W7, W4c
+endconst
.macro idct_start data
push {r4-r7, lr}
diff --git a/libavcodec/arm/synth_filter_neon.S b/libavcodec/arm/synth_filter_neon.S
index 1d6e5b2b86..3f91d67506 100644
--- a/libavcodec/arm/synth_filter_neon.S
+++ b/libavcodec/arm/synth_filter_neon.S
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2010 Mans Rullgard <mans@mansr.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/arm/vp3dsp_neon.S b/libavcodec/arm/vp3dsp_neon.S
index c1a55cad2f..ae3e40201a 100644
--- a/libavcodec/arm/vp3dsp_neon.S
+++ b/libavcodec/arm/vp3dsp_neon.S
@@ -1,30 +1,28 @@
/*
* Copyright (c) 2009 David Conrad
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "asm.S"
-.section .rodata
-.align 4
-
-vp3_idct_constants:
+const vp3_idct_constants, align=4
.short 64277, 60547, 54491, 46341, 36410, 25080, 12785
+endconst
#define xC1S7 d0[0]
#define xC2S6 d0[1]
@@ -34,8 +32,6 @@ vp3_idct_constants:
#define xC6S2 d1[1]
#define xC7S1 d1[2]
-.text
-
.macro vp3_loop_filter
vsubl.u8 q3, d18, d17
vsubl.u8 q2, d16, d19
diff --git a/libavcodec/arm/vp56_arith.h b/libavcodec/arm/vp56_arith.h
index ef30ffe897..ece9ac2a6c 100644
--- a/libavcodec/arm/vp56_arith.h
+++ b/libavcodec/arm/vp56_arith.h
@@ -1,20 +1,20 @@
/*
* Copyright (C) 2010 Mans Rullgard <mans@mansr.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/arm/vp56dsp_init_arm.c b/libavcodec/arm/vp56dsp_init_arm.c
index 598960251a..ceab9a87d2 100644
--- a/libavcodec/arm/vp56dsp_init_arm.c
+++ b/libavcodec/arm/vp56dsp_init_arm.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2010 Mans Rullgard <mans@mansr.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/arm/vp56dsp_neon.S b/libavcodec/arm/vp56dsp_neon.S
index b95d8ab28b..0353661009 100644
--- a/libavcodec/arm/vp56dsp_neon.S
+++ b/libavcodec/arm/vp56dsp_neon.S
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2010 Mans Rullgard <mans@mansr.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/arm/vp8.h b/libavcodec/arm/vp8.h
index 76a0397a8d..55193394c5 100644
--- a/libavcodec/arm/vp8.h
+++ b/libavcodec/arm/vp8.h
@@ -1,18 +1,18 @@
/**
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/arm/vp8_armv6.S b/libavcodec/arm/vp8_armv6.S
index 1d89c68909..8a3beb9fbb 100644
--- a/libavcodec/arm/vp8_armv6.S
+++ b/libavcodec/arm/vp8_armv6.S
@@ -1,20 +1,20 @@
/**
* Copyright (C) 2010 Mans Rullgard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -240,9 +240,9 @@ A orrcs r8, r8, r10, lsl r6
b 5b
endfunc
- .section .rodata
-zigzag_scan:
+const zigzag_scan
.byte 0, 2, 8, 16
.byte 10, 4, 6, 12
.byte 18, 24, 26, 20
.byte 14, 22, 28, 30
+endconst
diff --git a/libavcodec/arm/vp8dsp_armv6.S b/libavcodec/arm/vp8dsp_armv6.S
new file mode 100644
index 0000000000..4e7b78361e
--- /dev/null
+++ b/libavcodec/arm/vp8dsp_armv6.S
@@ -0,0 +1,2328 @@
+/**
+ * VP8 ARMv6 optimisations
+ *
+ * Copyright (c) 2011 The WebM project authors. All Rights Reserved.
+ * Copyright (c) 2010 Rob Clark <rob@ti.com>
+ * Copyright (c) 2011 Mans Rullgard <mans@mansr.com>
+ *
+ * This file is part of Libav.
+ *
+ * Libav 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.
+ *
+ * Libav 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * This code was partially ported from libvpx, which uses this license:
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ *
+ * (Note that the "LICENSE", "AUTHORS" and "PATENTS" files can be
+ * found in the libvpx source tree.)
+ */
+
+#include "asm.S"
+
+@ idct
+
+@ void vp8_luma_dc_wht(DCTELEM block[4][4][16], DCTELEM dc[16])
+function ff_vp8_luma_dc_wht_armv6, export=1
+ push {r4 - r10, lr}
+
+ @ load dc[] and zero memory
+ mov r12, #0
+ ldr r2, [r1] @ dc0[0,1]
+ ldr r3, [r1, #4] @ dc0[2,3]
+ ldr r4, [r1, #8] @ dc1[0,1]
+ ldr r5, [r1, #12] @ dc1[2,3]
+ ldr r6, [r1, #16] @ dc2[0,1]
+ ldr r7, [r1, #20] @ dc2[2,3]
+ ldr r8, [r1, #24] @ dc3[0,1]
+ ldr r9, [r1, #28] @ dc3[2,3]
+ str r12,[r1]
+ str r12,[r1, #4]
+ str r12,[r1, #8]
+ str r12,[r1, #12]
+ str r12,[r1, #16]
+ str r12,[r1, #20]
+ str r12,[r1, #24]
+ str r12,[r1, #28]
+
+ @ loop1
+ uadd16 r12, r2, r8 @ t0[0,1]
+ uadd16 r14, r3, r9 @ t0[2,3]
+ usub16 r2, r2, r8 @ t3[0,1]
+ usub16 r3, r3, r9 @ t3[2,3]
+ uadd16 r8, r4, r6 @ t1[0,1]
+ uadd16 r9, r5, r7 @ t1[2,3]
+ usub16 r4, r4, r6 @ t2[0,1]
+ usub16 r5, r5, r7 @ t2[2,3]
+
+ uadd16 r6, r12, r8 @ dc0[0,1]
+ uadd16 r7, r14, r9 @ dc0[2,3]
+ usub16 r12, r12, r8 @ dc2[0,1]
+ usub16 r14, r14, r9 @ dc2[2,3]
+ uadd16 r8, r2, r4 @ dc1[0,1]
+ uadd16 r9, r3, r5 @ dc1[2,3]
+ usub16 r2, r2, r4 @ dc3[0,1]
+ usub16 r3, r3, r5 @ dc3[2,3]
+
+ mov r1, #3
+ orr r1, r1, #0x30000 @ 3 | 3 (round)
+
+ @ "transpose"
+ pkhbt r4, r6, r8, lsl #16 @ dc{0,1}[0]
+ pkhtb r6, r8, r6, asr #16 @ dc{0,1}[1]
+ pkhbt r5, r12, r2, lsl #16 @ dc{2,3}[0]
+ pkhtb r12, r2, r12, asr #16 @ dc{2,3}[1]
+ pkhbt r8, r7, r9, lsl #16 @ dc{0,1}[2]
+ uadd16 r4, r4, r1
+ uadd16 r5, r5, r1
+ pkhtb r7, r9, r7, asr #16 @ dc{0,1}[3]
+ pkhbt r2, r14, r3, lsl #16 @ dc{2,3}[2]
+ pkhtb r14, r3, r14, asr #16 @ dc{2,3}[3]
+
+ @ loop2
+ uadd16 r9, r4, r7 @ t0[0,1]
+ uadd16 r3, r5, r14 @ t0[2,3]
+ usub16 r4, r4, r7 @ t3[0,1]
+ usub16 r5, r5, r14 @ t3[2,3]
+ uadd16 r7, r6, r8 @ t1[0,1]
+ uadd16 r14, r12, r2 @ t1[2,3]
+ usub16 r6, r6, r8 @ t2[0,1]
+ usub16 r12, r12, r2 @ t2[2,3]
+
+ uadd16 r8, r9, r7 @ block[0,1][0]
+ uadd16 r2, r3, r14 @ block[2,3][0]
+ usub16 r9, r9, r7 @ block[0,1][2]
+ usub16 r3, r3, r14 @ block[2,3][2]
+ uadd16 r7, r4, r6 @ block[0,1][1]
+ uadd16 r14, r5, r12 @ block[2,3][1]
+ usub16 r4, r4, r6 @ block[0,1][3]
+ usub16 r5, r5, r12 @ block[2,3][3]
+
+ @ store
+ mov r6, r8, asr #19 @ block[1][0]
+ mov r12, r7, asr #19 @ block[1][1]
+ mov r1, r9, asr #19 @ block[1][2]
+ mov r10, r4, asr #19 @ block[1][3]
+ sxth r8, r8
+ sxth r7, r7
+ sxth r9, r9
+ sxth r4, r4
+ asr r8, #3 @ block[0][0]
+ asr r7, #3 @ block[0][1]
+ asr r9, #3 @ block[0][2]
+ asr r4, #3 @ block[0][3]
+
+ strh r8, [r0], #32
+ strh r7, [r0], #32
+ strh r9, [r0], #32
+ strh r4, [r0], #32
+ strh r6, [r0], #32
+ strh r12,[r0], #32
+ strh r1, [r0], #32
+ strh r10,[r0], #32
+
+ mov r6, r2, asr #19 @ block[3][0]
+ mov r12, r14, asr #19 @ block[3][1]
+ mov r1, r3, asr #19 @ block[3][2]
+ mov r10, r5, asr #19 @ block[3][3]
+ sxth r2, r2
+ sxth r14, r14
+ sxth r3, r3
+ sxth r5, r5
+ asr r2, #3 @ block[2][0]
+ asr r14, #3 @ block[2][1]
+ asr r3, #3 @ block[2][2]
+ asr r5, #3 @ block[2][3]
+
+ strh r2, [r0], #32
+ strh r14,[r0], #32
+ strh r3, [r0], #32
+ strh r5, [r0], #32
+ strh r6, [r0], #32
+ strh r12,[r0], #32
+ strh r1, [r0], #32
+ strh r10,[r0], #32
+
+ pop {r4 - r10, pc}
+endfunc
+
+@ void vp8_luma_dc_wht_dc(DCTELEM block[4][4][16], DCTELEM dc[16])
+function ff_vp8_luma_dc_wht_dc_armv6, export=1
+ ldrsh r2, [r1]
+ mov r3, #0
+ add r2, r2, #3
+ strh r3, [r1]
+ asr r2, r2, #3
+ .rept 16
+ strh r2, [r0], #32
+ .endr
+ bx lr
+endfunc
+
+@ void vp8_idct_add(uint8_t *dst, DCTELEM block[16], int stride)
+function ff_vp8_idct_add_armv6, export=1
+ push {r4 - r11, lr}
+ sub sp, sp, #32
+
+ mov r3, #0x00004E00 @ cos
+ orr r3, r3, #0x0000007B @ cospi8sqrt2minus1 = 20091
+ mov r4, #0x00008A00 @ sin
+ orr r4, r4, #0x0000008C @ sinpi8sqrt2 = 35468
+ mov r5, #0x2 @ i=2
+1:
+ ldr r6, [r1, #8] @ i5 | i4 = block1[1] | block1[0]
+ ldr r12,[r1, #24] @ i13 | i12 = block3[1] | block3[0]
+ ldr r14,[r1, #16] @ i9 | i8 = block2[1] | block2[0]
+
+ smulwt r9, r3, r6 @ (ip[5] * cospi8sqrt2minus1) >> 16
+ smulwb r7, r3, r6 @ (ip[4] * cospi8sqrt2minus1) >> 16
+ smulwt r10, r4, r6 @ (ip[5] * sinpi8sqrt2) >> 16
+ smulwb r8, r4, r6 @ (ip[4] * sinpi8sqrt2) >> 16
+ pkhbt r7, r7, r9, lsl #16 @ 5c | 4c
+ smulwt r11, r3, r12 @ (ip[13] * cospi8sqrt2minus1) >> 16
+ pkhbt r8, r8, r10, lsl #16 @ 5s | 4s = t2 first half
+ uadd16 r6, r6, r7 @ 5c+5 | 4c+4 = t3 first half
+ smulwt r7, r4, r12 @ (ip[13] * sinpi8sqrt2) >> 16
+ smulwb r9, r3, r12 @ (ip[12] * cospi8sqrt2minus1) >> 16
+ smulwb r10, r4, r12 @ (ip[12] * sinpi8sqrt2) >> 16
+
+ subs r5, r5, #1 @ i--
+ pkhbt r9, r9, r11, lsl #16 @ 13c | 12c
+ ldr r11,[r1] @ i1 | i0
+ pkhbt r10, r10, r7, lsl #16 @ 13s | 12s = t3 second half
+ uadd16 r7, r12, r9 @ 13c+13 | 12c+12 = t2 second half
+ usub16 r7, r8, r7 @ c = t2
+ uadd16 r6, r6, r10 @ d = t3
+ uadd16 r10, r11, r14 @ a = t0
+ usub16 r8, r11, r14 @ b = t1
+ uadd16 r9, r10, r6 @ a+d = tmp{0,1}[0]
+ usub16 r10, r10, r6 @ a-d = tmp{0,1}[3]
+ uadd16 r6, r8, r7 @ b+c = tmp{0,1}[1]
+ usub16 r7, r8, r7 @ b-c = tmp{0,1}[2]
+ mov r8, #0
+ str r6, [sp, #8] @ o5 | o4
+ str r7, [sp, #16] @ o9 | o8
+ str r10,[sp, #24] @ o13 | o12
+ str r9, [sp], #4 @ o1 | o0
+ str r8, [r1, #24]
+ str r8, [r1, #16]
+ str r8, [r1, #8]
+ str r8, [r1], #4
+ bne 1b
+
+ mov r5, #0x2 @ i=2
+ sub sp, sp, #8
+2:
+ ldr r6, [sp, #8] @ i5 | i4 = tmp{0,1}[1]
+ ldr r14,[sp, #4] @ i3 | i2 = tmp{2,3}[0]
+ ldr r12,[sp, #12] @ i7 | i6 = tmp{2,3}[1]
+ ldr r1, [sp], #16 @ i1 | i0 = tmp{0,1}[0]
+ smulwt r9, r3, r6 @ (ip[5] * cospi8sqrt2minus1) >> 16
+ smulwt r7, r3, r1 @ (ip[1] * cospi8sqrt2minus1) >> 16
+ smulwt r10, r4, r6 @ (ip[5] * sinpi8sqrt2) >> 16
+ smulwt r8, r4, r1 @ (ip[1] * sinpi8sqrt2) >> 16
+ pkhbt r11, r1, r6, lsl #16 @ i4 | i0 = t0/t1 first half
+ pkhbt r7, r7, r9, lsl #16 @ 5c | 1c
+ pkhbt r8, r8, r10, lsl #16 @ 5s | 1s = temp1 = t2 first half
+ pkhtb r1, r6, r1, asr #16 @ i5 | i1
+ uadd16 r1, r7, r1 @ 5c+5 | 1c+1 = temp2 (d) = t3 first half
+ pkhbt r9, r14, r12, lsl #16 @ i6 | i2 = t0/t1 second half
+ uadd16 r10, r11, r9 @ a = t0
+ usub16 r9, r11, r9 @ b = t1
+ pkhtb r6, r12, r14, asr #16 @ i7 | i3
+ subs r5, r5, #0x1 @ i--
+ smulwt r7, r3, r6 @ (ip[7] * cospi8sqrt2minus1) >> 16
+ smulwt r11, r4, r6 @ (ip[7] * sinpi8sqrt2) >> 16
+ smulwb r12, r3, r6 @ (ip[3] * cospi8sqrt2minus1) >> 16
+ smulwb r14, r4, r6 @ (ip[3] * sinpi8sqrt2) >> 16
+
+ pkhbt r7, r12, r7, lsl #16 @ 7c | 3c
+ pkhbt r11, r14, r11, lsl #16 @ 7s | 3s = temp1 (d) = t3 second half
+ mov r14, #0x4 @ set up 4's
+ orr r14, r14, #0x40000 @ 4|4
+ uadd16 r6, r7, r6 @ 7c+7 | 3c+3 = temp2 (c) = t2 second half
+ usub16 r12, r8, r6 @ c (o5 | o1) = t2
+ uadd16 r6, r11, r1 @ d (o7 | o3) = t3
+ uadd16 r10, r10, r14 @ t0 + 4
+ uadd16 r9, r9, r14 @ t1 + 4
+ uadd16 r7, r10, r6 @ a+d = dst{0,1}[0]
+ usub16 r6, r10, r6 @ a-d = dst{0,1}[3]
+ uadd16 r10, r9, r12 @ b+c = dst{0,1}[1]
+ usub16 r1, r9, r12 @ b-c = dst{0,1}[2]
+
+ mov r9, r6, asr #3 @ o[1][3]
+ mov r12, r1, asr #3 @ o[1][2]
+ pkhtb r8, r12, r7, asr #19 @ o[1][0,2]
+ pkhtb r11, r9, r10, asr #19 @ o[1][1,3]
+ ldr r12,[r0]
+ ldr r9, [r0, r2]
+ sxth r7, r7
+ sxth r6, r6
+ sxth r10, r10
+ sxth r1, r1
+ asr r7, #3 @ o[0][0]
+ asr r10, #3 @ o[0][1]
+ pkhbt r7, r7, r1, lsl #13 @ o[0][0,2]
+ pkhbt r10, r10, r6, lsl #13 @ o[0][1,3]
+
+ uxtab16 r7, r7, r12
+ uxtab16 r10, r10, r12, ror #8
+ uxtab16 r8, r8, r9
+ uxtab16 r11, r11, r9, ror #8
+ usat16 r7, #8, r7
+ usat16 r10, #8, r10
+ usat16 r8, #8, r8
+ usat16 r11, #8, r11
+ orr r7, r7, r10, lsl #8
+ orr r8, r8, r11, lsl #8
+ str r8, [r0, r2]
+ str_post r7, r0, r2, lsl #1
+
+ bne 2b
+
+ pop {r4 - r11, pc}
+endfunc
+
+@ void vp8_idct_dc_add(uint8_t *dst, DCTELEM block[16], int stride)
+function ff_vp8_idct_dc_add_armv6, export=1
+ push {r4 - r5, lr}
+ ldrsh r3, [r1]
+ mov r4, #0
+ add r3, r3, #4
+ asr r3, #3
+ strh r4, [r1], #32
+ ldr r4, [r0, r2]
+ ldr_post r5, r0, r2, lsl #1
+ pkhbt r3, r3, r3, lsl #16
+
+ uxtab16 lr, r3, r5 @ a1+2 | a1+0
+ uxtab16 r5, r3, r5, ror #8 @ a1+3 | a1+1
+ uxtab16 r12, r3, r4
+ uxtab16 r4, r3, r4, ror #8
+ usat16 lr, #8, lr
+ usat16 r5, #8, r5
+ usat16 r12, #8, r12
+ usat16 r4, #8, r4
+ orr lr, lr, r5, lsl #8
+ orr r12, r12, r4, lsl #8
+ ldr r5, [r0]
+ ldr r4, [r0, r2]
+ sub r0, r0, r2, lsl #1
+ str r12,[r0, r2]
+ str_post lr, r0, r2, lsl #1
+
+ uxtab16 lr, r3, r5
+ uxtab16 r5, r3, r5, ror #8
+ uxtab16 r12, r3, r4
+ uxtab16 r4, r3, r4, ror #8
+ usat16 lr, #8, lr
+ usat16 r5, #8, r5
+ usat16 r12, #8, r12
+ usat16 r4, #8, r4
+ orr lr, lr, r5, lsl #8
+ orr r12, r12, r4, lsl #8
+
+ str r12,[r0, r2]
+ str_post lr, r0, r2, lsl #1
+
+ pop {r4 - r5, pc}
+endfunc
+
+@ void vp8_idct_dc_add4uv(uint8_t *dst, DCTELEM block[4][16], int stride)
+function ff_vp8_idct_dc_add4uv_armv6, export=1
+ push {lr}
+
+ bl ff_vp8_idct_dc_add_armv6
+ sub r0, r0, r2, lsl #2
+ add r0, r0, #4
+ bl ff_vp8_idct_dc_add_armv6
+ sub r0, r0, #4
+ bl ff_vp8_idct_dc_add_armv6
+ sub r0, r0, r2, lsl #2
+ add r0, r0, #4
+ bl ff_vp8_idct_dc_add_armv6
+
+ pop {pc}
+endfunc
+
+@ void vp8_idct_dc_add4y(uint8_t *dst, DCTELEM block[4][16], int stride)
+function ff_vp8_idct_dc_add4y_armv6, export=1
+ push {lr}
+
+ bl ff_vp8_idct_dc_add_armv6
+ sub r0, r0, r2, lsl #2
+ add r0, r0, #4
+ bl ff_vp8_idct_dc_add_armv6
+ sub r0, r0, r2, lsl #2
+ add r0, r0, #4
+ bl ff_vp8_idct_dc_add_armv6
+ sub r0, r0, r2, lsl #2
+ add r0, r0, #4
+ bl ff_vp8_idct_dc_add_armv6
+
+ pop {pc}
+endfunc
+
+@ loopfilter
+
+@ void vp8_v_loop_filter16_simple(uint8_t *dst, int stride, int flim)
+function ff_vp8_v_loop_filter16_simple_armv6, export=1
+ push {r4 - r11, lr}
+
+ ldr_dpren r3, r0, r1, lsl #1 @ p1
+ ldr_dpren r4, r0, r1 @ p0
+ ldr r5, [r0] @ q0
+ ldr r6, [r0, r1] @ q1
+ orr r2, r2, r2, lsl #16
+ mov r9, #4 @ count
+ mov lr, #0 @ need 0 in a couple places
+ orr r12, r2, r2, lsl #8 @ splat int -> byte
+ ldr r2, c0x80808080
+
+1:
+ @ vp8_simple_filter_mask()
+ uqsub8 r7, r3, r6 @ p1 - q1
+ uqsub8 r8, r6, r3 @ q1 - p1
+ uqsub8 r10, r4, r5 @ p0 - q0
+ uqsub8 r11, r5, r4 @ q0 - p0
+ orr r8, r8, r7 @ abs(p1 - q1)
+ orr r10, r10, r11 @ abs(p0 - q0)
+ uqadd8 r10, r10, r10 @ abs(p0 - q0) * 2
+ uhadd8 r8, r8, lr @ abs(p1 - q2) >> 1
+ uqadd8 r10, r10, r8 @ abs(p0 - q0)*2 + abs(p1 - q1)/2
+ mvn r8, #0
+ usub8 r10, r12, r10 @ compare to flimit. usub8 sets GE flags
+ sel r10, r8, lr @ filter mask: F or 0
+ cmp r10, #0
+ beq 2f @ skip filtering if all masks are 0x00
+
+ @ vp8_simple_filter()
+ eor r3, r3, r2 @ p1 offset to convert to a signed value
+ eor r6, r6, r2 @ q1 offset to convert to a signed value
+ eor r4, r4, r2 @ p0 offset to convert to a signed value
+ eor r5, r5, r2 @ q0 offset to convert to a signed value
+
+ qsub8 r3, r3, r6 @ vp8_filter = p1 - q1
+ qsub8 r6, r5, r4 @ q0 - p0
+ qadd8 r3, r3, r6 @ += q0 - p0
+ ldr r7, c0x04040404
+ qadd8 r3, r3, r6 @ += q0 - p0
+ ldr r8, c0x03030303
+ qadd8 r3, r3, r6 @ vp8_filter = p1-q1 + 3*(q0-p0))
+ @STALL
+ and r3, r3, r10 @ vp8_filter &= mask
+
+ qadd8 r7, r3, r7 @ Filter1 = vp8_filter + 4
+ qadd8 r8, r3, r8 @ Filter2 = vp8_filter + 3
+
+ shadd8 r7, r7, lr
+ shadd8 r8, r8, lr
+ shadd8 r7, r7, lr
+ shadd8 r8, r8, lr
+ shadd8 r7, r7, lr @ Filter1 >>= 3
+ shadd8 r8, r8, lr @ Filter2 >>= 3
+
+ qsub8 r5, r5, r7 @ u = q0 - Filter1
+ qadd8 r4, r4, r8 @ u = p0 + Filter2
+ eor r5, r5, r2 @ *oq0 = u^0x80
+ eor r4, r4, r2 @ *op0 = u^0x80
+T sub r7, r0, r1
+ str r5, [r0] @ store oq0 result
+A str r4, [r0, -r1] @ store op0 result
+T str r4, [r7]
+
+2:
+ subs r9, r9, #1 @ counter--
+ add r0, r0, #4 @ next row
+T itttt ne
+A ldrne r3, [r0, -r1, lsl #1] @ p1
+T subne r3, r0, r1, lsl #1
+T ldrne r3, [r3] @ p1
+A ldrne r4, [r0, -r1] @ p0
+T subne r4, r0, r1
+T ldrne r4, [r4] @ p0
+T itt ne
+ ldrne r5, [r0] @ q0
+ ldrne r6, [r0, r1] @ q1
+
+ bne 1b
+
+ pop {r4 - r11, pc}
+endfunc
+
+c0x01010101: .long 0x01010101
+c0x03030303: .long 0x03030303
+c0x04040404: .long 0x04040404
+c0x7F7F7F7F: .long 0x7F7F7F7F
+c0x80808080: .long 0x80808080
+
+@ void vp8_v_loop_filter16_inner(uint8_t *dst, int stride,
+@ int fE, int fI, int hev_thresh)
+@ and
+@ void vp8_v_loop_filter8uv_inner(uint8_t *dstU, uint8_t *dstV, int stride,
+@ int fE, int fI, int hev_thresh)
+@ call:
+@ void vp8_v_loop_filter_inner(uint8_t *dst, int stride,
+@ int fE, int fI, int hev_thresh, int count)
+function ff_vp8_v_loop_filter_inner_armv6, export=1
+ push {r4 - r11, lr}
+
+ sub r0, r0, r1, lsl #2 @ move r0 pointer down by 4 lines
+ ldr r5, [sp, #40] @ counter
+ ldr r6, [sp, #36] @ load thresh address
+ sub sp, sp, #16 @ create temp buffer
+
+ ldr r10,[r0, r1] @ p2
+ ldr_post r9, r0, r1, lsl #1 @ p3
+ ldr r12,[r0, r1] @ p0
+ ldr_post r11, r0, r1, lsl #1 @ p1
+
+ orr r2, r2, r2, lsl #16
+ orr r3, r3, r3, lsl #16
+ orr r6, r6, r6, lsl #16
+ orr r4, r2, r2, lsl #8 @ flimE splat int -> byte
+ orr r2, r3, r3, lsl #8 @ flimI splat int -> byte
+ orr r3, r6, r6, lsl #8 @ thresh splat int -> byte
+
+1:
+ @ vp8_filter_mask() function
+ @ calculate breakout conditions
+ uqsub8 r6, r9, r10 @ p3 - p2
+ uqsub8 r7, r10, r9 @ p2 - p3
+ uqsub8 r8, r10, r11 @ p2 - p1
+ uqsub8 r10, r11, r10 @ p1 - p2
+
+ orr r6, r6, r7 @ abs (p3-p2)
+ orr r8, r8, r10 @ abs (p2-p1)
+ uqsub8 lr, r6, r2 @ compare to limit. lr: vp8_filter_mask
+ uqsub8 r8, r8, r2 @ compare to limit
+ uqsub8 r6, r11, r12 @ p1 - p0
+ orr lr, lr, r8
+ uqsub8 r7, r12, r11 @ p0 - p1
+ ldr r10,[r0, r1] @ q1
+ ldr_post r9, r0, r1, lsl #1 @ q0
+ orr r6, r6, r7 @ abs (p1-p0)
+ uqsub8 r7, r6, r2 @ compare to limit
+ uqsub8 r8, r6, r3 @ compare to thresh -- save r8 for later
+ orr lr, lr, r7
+
+ uqsub8 r6, r11, r10 @ p1 - q1
+ uqsub8 r7, r10, r11 @ q1 - p1
+ uqsub8 r11, r12, r9 @ p0 - q0
+ uqsub8 r12, r9, r12 @ q0 - p0
+ orr r6, r6, r7 @ abs (p1-q1)
+ ldr r7, c0x7F7F7F7F
+ orr r12, r11, r12 @ abs (p0-q0)
+ ldr_post r11, r0, r1 @ q2
+ uqadd8 r12, r12, r12 @ abs (p0-q0) * 2
+ and r6, r7, r6, lsr #1 @ abs (p1-q1) / 2
+ uqsub8 r7, r9, r10 @ q0 - q1
+ uqadd8 r12, r12, r6 @ abs (p0-q0)*2 + abs (p1-q1)/2
+ uqsub8 r6, r10, r9 @ q1 - q0
+ uqsub8 r12, r12, r4 @ compare to flimit
+ uqsub8 r9, r11, r10 @ q2 - q1
+
+ orr lr, lr, r12
+
+ ldr_post r12, r0, r1 @ q3
+ uqsub8 r10, r10, r11 @ q1 - q2
+ orr r6, r7, r6 @ abs (q1-q0)
+ orr r10, r9, r10 @ abs (q2-q1)
+ uqsub8 r7, r6, r2 @ compare to limit
+ uqsub8 r10, r10, r2 @ compare to limit
+ uqsub8 r6, r6, r3 @ compare to thresh -- save r6 for later
+ orr lr, lr, r7
+ orr lr, lr, r10
+
+ uqsub8 r10, r12, r11 @ q3 - q2
+ uqsub8 r9, r11, r12 @ q2 - q3
+
+ mvn r11, #0 @ r11 == -1
+
+ orr r10, r10, r9 @ abs (q3-q2)
+ uqsub8 r10, r10, r2 @ compare to limit
+
+ mov r12, #0
+ orr lr, lr, r10
+ sub r0, r0, r1, lsl #2
+
+ usub8 lr, r12, lr @ use usub8 instead of ssub8
+ sel lr, r11, r12 @ filter mask: lr
+
+ cmp lr, #0
+ beq 2f @ skip filtering
+
+ sub r0, r0, r1, lsl #1 @ move r0 pointer down by 6 lines
+
+ @vp8_hevmask() function
+ @calculate high edge variance
+ orr r10, r6, r8 @ calculate vp8_hevmask
+
+ usub8 r10, r12, r10 @ use usub8 instead of ssub8
+ sel r6, r12, r11 @ obtain vp8_hevmask: r6
+
+ @vp8_filter() function
+ ldr r8, [r0, r1] @ p0
+ ldr_post r7, r0, r1, lsl #1 @ p1
+ ldr r12, c0x80808080
+ ldr r10,[r0, r1] @ q1
+ ldr_post r9, r0, r1, lsl #1 @ q0
+
+ eor r7, r7, r12 @ p1 offset to convert to a signed value
+ eor r8, r8, r12 @ p0 offset to convert to a signed value
+ eor r9, r9, r12 @ q0 offset to convert to a signed value
+ eor r10, r10, r12 @ q1 offset to convert to a signed value
+
+ str r9, [sp] @ store qs0 temporarily
+ str r8, [sp, #4] @ store ps0 temporarily
+ str r10,[sp, #8] @ store qs1 temporarily
+ str r7, [sp, #12] @ store ps1 temporarily
+
+ qsub8 r7, r7, r10 @ vp8_signed_char_clamp(ps1-qs1)
+ qsub8 r8, r9, r8 @ vp8_signed_char_clamp(vp8_filter + 3 * ( qs0 - ps0))
+
+ and r7, r7, r6 @ vp8_filter (r7) &= hev
+
+ qadd8 r7, r7, r8
+ ldr r9, c0x03030303 @ r9 = 3 --modified for vp8
+
+ qadd8 r7, r7, r8
+ ldr r10, c0x04040404
+
+ qadd8 r7, r7, r8
+ and r7, r7, lr @ vp8_filter &= mask@
+
+ qadd8 r8, r7, r9 @ Filter2 (r8) = vp8_signed_char_clamp(vp8_filter+3)
+ qadd8 r7, r7, r10 @ vp8_filter = vp8_signed_char_clamp(vp8_filter+4)
+
+ mov r9, #0
+ shadd8 r8, r8, r9 @ Filter2 >>= 3
+ shadd8 r7, r7, r9 @ vp8_filter >>= 3
+ shadd8 r8, r8, r9
+ shadd8 r7, r7, r9
+ shadd8 lr, r8, r9 @ lr: Filter2
+ shadd8 r7, r7, r9 @ r7: filter
+
+ @calculate output
+
+ ldr r8, [sp] @ load qs0
+ ldr r9, [sp, #4] @ load ps0
+
+ ldr r10, c0x01010101
+
+ qsub8 r8, r8, r7 @ u = vp8_signed_char_clamp(qs0 - vp8_filter)
+ qadd8 r9, r9, lr @ u = vp8_signed_char_clamp(ps0 + Filter2)
+
+ mov lr, #0
+ sadd8 r7, r7, r10 @ vp8_filter += 1
+ shadd8 r7, r7, lr @ vp8_filter >>= 1
+
+ ldr r11,[sp, #12] @ load ps1
+ ldr r10,[sp, #8] @ load qs1
+
+ bic r7, r7, r6 @ vp8_filter &= ~hev
+ sub r0, r0, r1, lsl #2
+
+ qadd8 r11, r11, r7 @ u = vp8_signed_char_clamp(ps1 + vp8_filter)
+ qsub8 r10, r10, r7 @ u = vp8_signed_char_clamp(qs1 - vp8_filter)
+
+ eor r11, r11, r12 @ *op1 = u^0x80
+ eor r9, r9, r12 @ *op0 = u^0x80
+ eor r8, r8, r12 @ *oq0 = u^0x80
+ eor r10, r10, r12 @ *oq1 = u^0x80
+ str r9, [r0, r1] @ store op0 result
+ str_post r11, r0, r1, lsl #1 @ store op1
+ str r10,[r0, r1] @ store oq1
+ str_post r8, r0, r1, lsl #1 @ store oq0 result
+
+ sub r0, r0, r1, lsl #1
+
+2:
+ add r0, r0, #4
+ sub r0, r0, r1, lsl #2
+
+ subs r5, r5, #1
+T ittt ne
+ ldrne r10,[r0, r1] @ p2
+A ldrne r9, [r0], r1, lsl #1 @ p3
+T ldrne r9, [r0] @ p3
+T addne r0, r0, r1, lsl #1
+T ittt ne
+ ldrne r12,[r0, r1] @ p0
+A ldrne r11,[r0], r1, lsl #1 @ p1
+T ldrne r11,[r0] @ p3
+T addne r0, r0, r1, lsl #1
+
+ bne 1b
+
+ add sp, sp, #16
+ pop {r4 - r11, pc}
+endfunc
+
+@ void vp8_v_loop_filter16(uint8_t *dst, int stride,
+@ int fE, int fI, int hev_thresh)
+@ and
+@ void vp8_v_loop_filter8uv(uint8_t *dstU, uint8_t *dstV, int stride,
+@ int fE, int fI, int hev_thresh)
+@ call:
+@ void vp8_v_loop_filter(uint8_t *dst, int stride,
+@ int fE, int fI, int hev_thresh, int count)
+function ff_vp8_v_loop_filter_armv6, export=1
+ push {r4 - r11, lr}
+
+ sub r0, r0, r1, lsl #2 @ move r0 pointer down by 4 lines
+ ldr r5, [sp, #40] @ counter
+ ldr r6, [sp, #36] @ load thresh address
+ sub sp, sp, #16 @ create temp buffer
+
+ ldr r10,[r0, r1] @ p2
+ ldr_post r9, r0, r1, lsl #1 @ p3
+ ldr r12,[r0, r1] @ p0
+ ldr_post r11, r0, r1, lsl #1 @ p1
+
+ orr r2, r2, r2, lsl #16
+ orr r3, r3, r3, lsl #16
+ orr r6, r6, r6, lsl #16
+ orr r4, r2, r2, lsl #8 @ flimE splat int -> byte
+ orr r2, r3, r3, lsl #8 @ flimI splat int -> byte
+ orr r3, r6, r6, lsl #8 @ thresh splat int -> byte
+
+1:
+ @ vp8_filter_mask() function
+ @ calculate breakout conditions
+ uqsub8 r6, r9, r10 @ p3 - p2
+ uqsub8 r7, r10, r9 @ p2 - p3
+ uqsub8 r8, r10, r11 @ p2 - p1
+ uqsub8 r10, r11, r10 @ p1 - p2
+
+ orr r6, r6, r7 @ abs (p3-p2)
+ orr r8, r8, r10 @ abs (p2-p1)
+ uqsub8 lr, r6, r2 @ compare to limit. lr: vp8_filter_mask
+ uqsub8 r8, r8, r2 @ compare to limit
+
+ uqsub8 r6, r11, r12 @ p1 - p0
+ orr lr, lr, r8
+ uqsub8 r7, r12, r11 @ p0 - p1
+ ldr r10,[r0, r1] @ q1
+ ldr_post r9, r0, r1, lsl #1 @ q0
+ orr r6, r6, r7 @ abs (p1-p0)
+ uqsub8 r7, r6, r2 @ compare to limit
+ uqsub8 r8, r6, r3 @ compare to thresh -- save r8 for later
+ orr lr, lr, r7
+
+ uqsub8 r6, r11, r10 @ p1 - q1
+ uqsub8 r7, r10, r11 @ q1 - p1
+ uqsub8 r11, r12, r9 @ p0 - q0
+ uqsub8 r12, r9, r12 @ q0 - p0
+ orr r6, r6, r7 @ abs (p1-q1)
+ ldr r7, c0x7F7F7F7F
+ orr r12, r11, r12 @ abs (p0-q0)
+ ldr_post r11, r0, r1 @ q2
+ uqadd8 r12, r12, r12 @ abs (p0-q0) * 2
+ and r6, r7, r6, lsr #1 @ abs (p1-q1) / 2
+ uqsub8 r7, r9, r10 @ q0 - q1
+ uqadd8 r12, r12, r6 @ abs (p0-q0)*2 + abs (p1-q1)/2
+ uqsub8 r6, r10, r9 @ q1 - q0
+ uqsub8 r12, r12, r4 @ compare to flimit
+ uqsub8 r9, r11, r10 @ q2 - q1
+
+ orr lr, lr, r12
+
+ ldr_post r12, r0, r1 @ q3
+
+ uqsub8 r10, r10, r11 @ q1 - q2
+ orr r6, r7, r6 @ abs (q1-q0)
+ orr r10, r9, r10 @ abs (q2-q1)
+ uqsub8 r7, r6, r2 @ compare to limit
+ uqsub8 r10, r10, r2 @ compare to limit
+ uqsub8 r6, r6, r3 @ compare to thresh -- save r6 for later
+ orr lr, lr, r7
+ orr lr, lr, r10
+
+ uqsub8 r10, r12, r11 @ q3 - q2
+ uqsub8 r9, r11, r12 @ q2 - q3
+
+ mvn r11, #0 @ r11 == -1
+
+ orr r10, r10, r9 @ abs (q3-q2)
+ uqsub8 r10, r10, r2 @ compare to limit
+
+ mov r12, #0
+
+ orr lr, lr, r10
+
+ usub8 lr, r12, lr @ use usub8 instead of ssub8
+ sel lr, r11, r12 @ filter mask: lr
+
+ cmp lr, #0
+ beq 2f @ skip filtering
+
+ @vp8_hevmask() function
+ @calculate high edge variance
+ sub r0, r0, r1, lsl #2 @ move r0 pointer down by 6 lines
+ sub r0, r0, r1, lsl #1
+
+ orr r10, r6, r8
+
+ usub8 r10, r12, r10
+ sel r6, r12, r11 @ hev mask: r6
+
+ @vp8_mbfilter() function
+ @p2, q2 are only needed at the end. Do not need to load them in now.
+ ldr r8, [r0, r1] @ p0
+ ldr_post r7, r0, r1, lsl #1 @ p1
+ ldr r12, c0x80808080
+ ldr_post r9, r0, r1 @ q0
+ ldr r10,[r0] @ q1
+
+ eor r7, r7, r12 @ ps1
+ eor r8, r8, r12 @ ps0
+ eor r9, r9, r12 @ qs0
+ eor r10, r10, r12 @ qs1
+
+ qsub8 r12, r9, r8 @ vp8_signed_char_clamp(vp8_filter + 3 * ( qs0 - ps0))
+ str r7, [sp, #12] @ store ps1 temporarily
+ qsub8 r7, r7, r10 @ vp8_signed_char_clamp(ps1-qs1)
+ str r10,[sp, #8] @ store qs1 temporarily
+ qadd8 r7, r7, r12
+ str r9, [sp] @ store qs0 temporarily
+ qadd8 r7, r7, r12
+ str r8, [sp, #4] @ store ps0 temporarily
+ qadd8 r7, r7, r12 @ vp8_filter: r7
+
+ ldr r10, c0x03030303 @ r10 = 3 --modified for vp8
+ ldr r9, c0x04040404
+
+ and r7, r7, lr @ vp8_filter &= mask (lr is free)
+
+ mov r12, r7 @ Filter2: r12
+ and r12, r12, r6 @ Filter2 &= hev
+
+ @save bottom 3 bits so that we round one side +4 and the other +3
+ qadd8 r8, r12, r9 @ Filter1 (r8) = vp8_signed_char_clamp(Filter2+4)
+ qadd8 r12, r12, r10 @ Filter2 (r12) = vp8_signed_char_clamp(Filter2+3)
+
+ mov r10, #0
+ shadd8 r8, r8, r10 @ Filter1 >>= 3
+ shadd8 r12, r12, r10 @ Filter2 >>= 3
+ shadd8 r8, r8, r10
+ shadd8 r12, r12, r10
+ shadd8 r8, r8, r10 @ r8: Filter1
+ shadd8 r12, r12, r10 @ r12: Filter2
+
+ ldr r9, [sp] @ load qs0
+ ldr r11,[sp, #4] @ load ps0
+
+ qsub8 r9, r9, r8 @ qs0 = vp8_signed_char_clamp(qs0 - Filter1)
+ qadd8 r11, r11, r12 @ ps0 = vp8_signed_char_clamp(ps0 + Filter2)
+
+ bic r12, r7, r6 @ vp8_filter &= ~hev ( r6 is free)
+
+ @roughly 3/7th difference across boundary
+ mov lr, #0x1b @ 27
+ mov r7, #0x3f @ 63
+
+ sxtb16 r6, r12
+ sxtb16 r10, r12, ror #8
+ smlabb r8, r6, lr, r7
+ smlatb r6, r6, lr, r7
+ smlabb r7, r10, lr, r7
+ smultb r10, r10, lr
+ ssat r8, #8, r8, asr #7
+ ssat r6, #8, r6, asr #7
+ add r10, r10, #63
+ ssat r7, #8, r7, asr #7
+ ssat r10, #8, r10, asr #7
+
+ ldr lr, c0x80808080
+
+ pkhbt r6, r8, r6, lsl #16
+ pkhbt r10, r7, r10, lsl #16
+ uxtb16 r6, r6
+ uxtb16 r10, r10
+
+ sub r0, r0, r1
+
+ orr r10, r6, r10, lsl #8 @ u = vp8_signed_char_clamp((63 + Filter2 * 27)>>7)
+
+ qsub8 r8, r9, r10 @ s = vp8_signed_char_clamp(qs0 - u)
+ qadd8 r10, r11, r10 @ s = vp8_signed_char_clamp(ps0 + u)
+ eor r8, r8, lr @ *oq0 = s^0x80
+ str r8, [r0] @ store *oq0
+ sub r0, r0, r1
+ eor r10, r10, lr @ *op0 = s^0x80
+ str r10,[r0] @ store *op0
+
+ @roughly 2/7th difference across boundary
+ mov lr, #0x12 @ 18
+ mov r7, #0x3f @ 63
+
+ sxtb16 r6, r12
+ sxtb16 r10, r12, ror #8
+ smlabb r8, r6, lr, r7
+ smlatb r6, r6, lr, r7
+ smlabb r9, r10, lr, r7
+ smlatb r10, r10, lr, r7
+ ssat r8, #8, r8, asr #7
+ ssat r6, #8, r6, asr #7
+ ssat r9, #8, r9, asr #7
+ ssat r10, #8, r10, asr #7
+
+ ldr lr, c0x80808080
+
+ pkhbt r6, r8, r6, lsl #16
+ pkhbt r10, r9, r10, lsl #16
+
+ ldr r9, [sp, #8] @ load qs1
+ ldr r11, [sp, #12] @ load ps1
+
+ uxtb16 r6, r6
+ uxtb16 r10, r10
+
+ sub r0, r0, r1
+
+ orr r10, r6, r10, lsl #8 @ u = vp8_signed_char_clamp((63 + Filter2 * 18)>>7)
+
+ qadd8 r11, r11, r10 @ s = vp8_signed_char_clamp(ps1 + u)
+ qsub8 r8, r9, r10 @ s = vp8_signed_char_clamp(qs1 - u)
+ eor r11, r11, lr @ *op1 = s^0x80
+ str_post r11, r0, r1 @ store *op1
+ eor r8, r8, lr @ *oq1 = s^0x80
+ add r0, r0, r1, lsl #1
+
+ mov r7, #0x3f @ 63
+
+ str_post r8, r0, r1 @ store *oq1
+
+ @roughly 1/7th difference across boundary
+ mov lr, #0x9 @ 9
+ ldr r9, [r0] @ load q2
+
+ sxtb16 r6, r12
+ sxtb16 r10, r12, ror #8
+ smlabb r8, r6, lr, r7
+ smlatb r6, r6, lr, r7
+ smlabb r12, r10, lr, r7
+ smlatb r10, r10, lr, r7
+ ssat r8, #8, r8, asr #7
+ ssat r6, #8, r6, asr #7
+ ssat r12, #8, r12, asr #7
+ ssat r10, #8, r10, asr #7
+
+ sub r0, r0, r1, lsl #2
+
+ pkhbt r6, r8, r6, lsl #16
+ pkhbt r10, r12, r10, lsl #16
+
+ sub r0, r0, r1
+ ldr lr, c0x80808080
+
+ ldr r11, [r0] @ load p2
+
+ uxtb16 r6, r6
+ uxtb16 r10, r10
+
+ eor r9, r9, lr
+ eor r11, r11, lr
+
+ orr r10, r6, r10, lsl #8 @ u = vp8_signed_char_clamp((63 + Filter2 * 9)>>7)
+
+ qadd8 r8, r11, r10 @ s = vp8_signed_char_clamp(ps2 + u)
+ qsub8 r10, r9, r10 @ s = vp8_signed_char_clamp(qs2 - u)
+ eor r8, r8, lr @ *op2 = s^0x80
+ str_post r8, r0, r1, lsl #2 @ store *op2
+ add r0, r0, r1
+ eor r10, r10, lr @ *oq2 = s^0x80
+ str_post r10, r0, r1, lsl #1 @ store *oq2
+
+2:
+ add r0, r0, #4
+ sub r0, r0, r1, lsl #3
+ subs r5, r5, #1
+
+T ittt ne
+ ldrne r10,[r0, r1] @ p2
+A ldrne r9, [r0], r1, lsl #1 @ p3
+T ldrne r9, [r0] @ p3
+T addne r0, r0, r1, lsl #1
+T ittt ne
+ ldrne r12,[r0, r1] @ p0
+A ldrne r11,[r0], r1, lsl #1 @ p1
+T ldrne r11,[r0] @ p3
+T addne r0, r0, r1, lsl #1
+
+ bne 1b
+
+ add sp, sp, #16
+ pop {r4 - r11, pc}
+endfunc
+
+.macro TRANSPOSE_MATRIX i0, i1, i2, i3, o3, o2, o1, o0
+ @ input: $0, $1, $2, $3
+ @ output: $4, $5, $6, $7
+ @ i0: 03 02 01 00
+ @ i1: 13 12 11 10
+ @ i2: 23 22 21 20
+ @ i3: 33 32 31 30
+ @ o3 o2 o1 o0
+
+ uxtb16 \o1, \i1 @ xx 12 xx 10
+ uxtb16 \o0, \i0 @ xx 02 xx 00
+ uxtb16 \o3, \i3 @ xx 32 xx 30
+ uxtb16 \o2, \i2 @ xx 22 xx 20
+ orr \o1, \o0, \o1, lsl #8 @ 12 02 10 00
+ orr \o3, \o2, \o3, lsl #8 @ 32 22 30 20
+
+ uxtb16 \i1, \i1, ror #8 @ xx 13 xx 11
+ uxtb16 \i3, \i3, ror #8 @ xx 33 xx 31
+ uxtb16 \i0, \i0, ror #8 @ xx 03 xx 01
+ uxtb16 \i2, \i2, ror #8 @ xx 23 xx 21
+ orr \i0, \i0, \i1, lsl #8 @ 13 03 11 01
+ orr \i2, \i2, \i3, lsl #8 @ 33 23 31 21
+
+ pkhtb \o2, \o3, \o1, asr #16 @ 32 22 12 02 -- p1
+ pkhbt \o0, \o1, \o3, lsl #16 @ 30 20 10 00 -- p3
+
+ pkhtb \o3, \i2, \i0, asr #16 @ 33 23 13 03 -- p0
+ pkhbt \o1, \i0, \i2, lsl #16 @ 31 21 11 01 -- p2
+.endm
+
+@ void vp8_h_loop_filter16_simple(uint8_t *dst, int stride, int flim)
+function ff_vp8_h_loop_filter16_simple_armv6, export=1
+ push {r4 - r11, lr}
+ orr r12, r2, r2, lsl #16
+ ldr r2, c0x80808080
+ orr r12, r12, r12, lsl #8
+
+ @ load soure data to r7, r8, r9, r10
+ sub r0, r0, #2
+ ldr r8, [r0, r1]
+ ldr_post r7, r0, r1, lsl #1
+ ldr r10,[r0, r1]
+ ldr_post r9, r0, r1, lsl #1
+ add r0, r0, #2
+
+ mov r11, #4 @ count (r11) for 4-in-parallel
+1:
+ @transpose r7, r8, r9, r10 to r3, r4, r5, r6
+ TRANSPOSE_MATRIX r7, r8, r9, r10, r6, r5, r4, r3
+
+ @ vp8_simple_filter_mask() function
+ uqsub8 r7, r3, r6 @ p1 - q1
+ uqsub8 r8, r6, r3 @ q1 - p1
+ uqsub8 r9, r4, r5 @ p0 - q0
+ uqsub8 r10, r5, r4 @ q0 - p0
+ orr r7, r7, r8 @ abs(p1 - q1)
+ orr r9, r9, r10 @ abs(p0 - q0)
+ mov r8, #0
+ uqadd8 r9, r9, r9 @ abs(p0 - q0) * 2
+ uhadd8 r7, r7, r8 @ abs(p1 - q1) / 2
+ uqadd8 r7, r7, r9 @ abs(p0 - q0)*2 + abs(p1 - q1)/2
+ mvn r10, #0 @ r10 == -1
+
+ usub8 r7, r12, r7 @ compare to flimit
+ sel lr, r10, r8 @ filter mask
+
+ cmp lr, #0
+ beq 2f @ skip filtering
+
+ @vp8_simple_filter() function
+ eor r3, r3, r2 @ p1 offset to convert to a signed value
+ eor r6, r6, r2 @ q1 offset to convert to a signed value
+ eor r4, r4, r2 @ p0 offset to convert to a signed value
+ eor r5, r5, r2 @ q0 offset to convert to a signed value
+
+ qsub8 r3, r3, r6 @ vp8_filter = p1 - q1
+ qsub8 r6, r5, r4 @ q0 - p0
+
+ qadd8 r3, r3, r6 @ vp8_filter += q0 - p0
+ ldr r9, c0x03030303 @ r9 = 3
+
+ qadd8 r3, r3, r6 @ vp8_filter += q0 - p0
+ ldr r7, c0x04040404
+
+ qadd8 r3, r3, r6 @ vp8_filter = p1-q1 + 3*(q0-p0))
+ @STALL
+ and r3, r3, lr @ vp8_filter &= mask
+
+ qadd8 r9, r3, r9 @ Filter2 = vp8_filter + 3
+ qadd8 r3, r3, r7 @ Filter1 = vp8_filter + 4
+
+ shadd8 r9, r9, r8
+ shadd8 r3, r3, r8
+ shadd8 r9, r9, r8
+ shadd8 r3, r3, r8
+ shadd8 r9, r9, r8 @ Filter2 >>= 3
+ shadd8 r3, r3, r8 @ Filter1 >>= 3
+
+ @calculate output
+ sub r0, r0, r1, lsl #2
+
+ qadd8 r4, r4, r9 @ u = p0 + Filter2
+ qsub8 r5, r5, r3 @ u = q0 - Filter1
+ eor r4, r4, r2 @ *op0 = u^0x80
+ eor r5, r5, r2 @ *oq0 = u^0x80
+
+ strb r4, [r0, #-1] @ store the result
+ mov r4, r4, lsr #8
+ strb_post r5, r0, r1
+ mov r5, r5, lsr #8
+
+ strb r4, [r0, #-1]
+ mov r4, r4, lsr #8
+ strb_post r5, r0, r1
+ mov r5, r5, lsr #8
+
+ strb r4, [r0, #-1]
+ mov r4, r4, lsr #8
+ strb_post r5, r0, r1
+ mov r5, r5, lsr #8
+
+ strb r4, [r0, #-1]
+ strb_post r5, r0, r1
+
+2:
+ subs r11, r11, #1
+
+ @ load soure data to r7, r8, r9, r10
+ sub r0, r0, #2
+T ittt ne
+ ldrne r8, [r0, r1]
+A ldrne r7, [r0], r1, lsl #1
+T ldrne r7, [r0]
+T addne r0, r0, r1, lsl #1
+T ittt ne
+ ldrne r10,[r0, r1]
+A ldrne r9, [r0], r1, lsl #1
+T ldrne r9, [r0]
+T addne r0, r0, r1, lsl #1
+ add r0, r0, #2
+
+ bne 1b
+
+ pop {r4 - r11, pc}
+endfunc
+
+@ void vp8_h_loop_filter16_inner(uint8_t *dst, int stride,
+@ int fE, int fI, int hev_thresh)
+@ and
+@ void vp8_h_loop_filter8uv_inner(uint8_t *dstU, uint8_t *dstV, int stride,
+@ int fE, int fI, int hev_thresh)
+@ call:
+@ void vp8_h_loop_filter_inner(uint8_t *dst, int stride,
+@ int fE, int fI, int hev_thresh, int count)
+function ff_vp8_h_loop_filter_inner_armv6, export=1
+ push {r4 - r11, lr}
+
+ sub r0, r0, #4 @ move r0 pointer down by 4
+ ldr r5, [sp, #40] @ counter
+ ldr r9, [sp, #36] @ load thresh address
+ sub sp, sp, #16 @ create temp buffer
+
+ ldr r7, [r0, r1] @ transpose will make it into p3-p0
+ ldr_post r6, r0, r1, lsl #1 @ load source data
+ ldr lr, [r0, r1]
+ ldr_post r8, r0, r1, lsl #1
+
+ orr r2, r2, r2, lsl #16
+ orr r3, r3, r3, lsl #16
+ orr r9, r9, r9, lsl #16
+ orr r4, r2, r2, lsl #8 @ flimE splat int -> byte
+ orr r2, r3, r3, lsl #8 @ flimI splat int -> byte
+ orr r3, r9, r9, lsl #8 @ thresh splat int -> byte
+
+1:
+ @ vp8_filter_mask() function
+ @ calculate breakout conditions
+ @ transpose the source data for 4-in-parallel operation
+ TRANSPOSE_MATRIX r6, r7, r8, lr, r12, r11, r10, r9
+
+ uqsub8 r7, r9, r10 @ p3 - p2
+ uqsub8 r8, r10, r9 @ p2 - p3
+ uqsub8 r9, r10, r11 @ p2 - p1
+ uqsub8 r10, r11, r10 @ p1 - p2
+ orr r7, r7, r8 @ abs (p3-p2)
+ orr r10, r9, r10 @ abs (p2-p1)
+ uqsub8 lr, r7, r2 @ compare to limit. lr: vp8_filter_mask
+ uqsub8 r10, r10, r2 @ compare to limit
+
+ sub r0, r0, r1, lsl #2 @ move r0 pointer down by 4 lines
+
+ orr lr, lr, r10
+
+ uqsub8 r6, r11, r12 @ p1 - p0
+ uqsub8 r7, r12, r11 @ p0 - p1
+ add r0, r0, #4 @ move r0 pointer up by 4
+ orr r6, r6, r7 @ abs (p1-p0)
+ str r11,[sp, #12] @ save p1
+ uqsub8 r10, r6, r2 @ compare to limit
+ uqsub8 r11, r6, r3 @ compare to thresh
+ orr lr, lr, r10
+
+ @ transpose uses 8 regs(r6 - r12 and lr). Need to save reg value now
+ @ transpose the source data for 4-in-parallel operation
+ str r11,[sp] @ push r11 to stack
+ ldr r7, [r0, r1]
+ ldr_post r6, r0, r1, lsl #1 @ load source data
+ str r12,[sp, #4] @ save current reg before load q0 - q3 data
+ str lr, [sp, #8]
+ ldr lr, [r0, r1]
+ ldr_post r8, r0, r1, lsl #1
+
+ TRANSPOSE_MATRIX r6, r7, r8, lr, r12, r11, r10, r9
+
+ ldr lr, [sp, #8] @ load back (f)limit accumulator
+
+ uqsub8 r6, r12, r11 @ q3 - q2
+ uqsub8 r7, r11, r12 @ q2 - q3
+ uqsub8 r12, r11, r10 @ q2 - q1
+ uqsub8 r11, r10, r11 @ q1 - q2
+ orr r6, r6, r7 @ abs (q3-q2)
+ orr r7, r12, r11 @ abs (q2-q1)
+ uqsub8 r6, r6, r2 @ compare to limit
+ uqsub8 r7, r7, r2 @ compare to limit
+ ldr r11,[sp, #4] @ load back p0
+ ldr r12,[sp, #12] @ load back p1
+ orr lr, lr, r6
+ orr lr, lr, r7
+
+ uqsub8 r6, r11, r9 @ p0 - q0
+ uqsub8 r7, r9, r11 @ q0 - p0
+ uqsub8 r8, r12, r10 @ p1 - q1
+ uqsub8 r11, r10, r12 @ q1 - p1
+ orr r6, r6, r7 @ abs (p0-q0)
+ ldr r7, c0x7F7F7F7F
+ orr r8, r8, r11 @ abs (p1-q1)
+ uqadd8 r6, r6, r6 @ abs (p0-q0) * 2
+ and r8, r7, r8, lsr #1 @ abs (p1-q1) / 2
+ uqsub8 r11, r10, r9 @ q1 - q0
+ uqadd8 r6, r8, r6 @ abs (p0-q0)*2 + abs (p1-q1)/2
+ uqsub8 r12, r9, r10 @ q0 - q1
+ uqsub8 r6, r6, r4 @ compare to flimit
+
+ orr r9, r11, r12 @ abs (q1-q0)
+ uqsub8 r8, r9, r2 @ compare to limit
+ uqsub8 r10, r9, r3 @ compare to thresh
+ orr lr, lr, r6
+ orr lr, lr, r8
+
+ mvn r11, #0 @ r11 == -1
+ mov r12, #0
+
+ usub8 lr, r12, lr
+ ldr r9, [sp] @ load the compared result
+ sel lr, r11, r12 @ filter mask: lr
+
+ cmp lr, #0
+ beq 2f @ skip filtering
+
+ @vp8_hevmask() function
+ @calculate high edge variance
+ sub r0, r0, r1, lsl #2 @ move r0 pointer down by 4 lines
+
+ orr r9, r9, r10
+
+ ldrh r7, [r0, #-2]
+ ldrh_post r8, r0, r1
+
+ usub8 r9, r12, r9
+ sel r6, r12, r11 @ hev mask: r6
+
+ @vp8_filter() function
+ @ load soure data to r6, r11, r12, lr
+ ldrh r9, [r0, #-2]
+ ldrh_post r10, r0, r1
+
+ pkhbt r12, r7, r8, lsl #16
+
+ ldrh r7, [r0, #-2]
+ ldrh_post r8, r0, r1
+
+ pkhbt r11, r9, r10, lsl #16
+
+ ldrh r9, [r0, #-2]
+ ldrh_post r10, r0, r1
+
+ @ Transpose needs 8 regs(r6 - r12, and lr). Save r6 and lr first
+ str r6, [sp]
+ str lr, [sp, #4]
+
+ pkhbt r6, r7, r8, lsl #16
+ pkhbt lr, r9, r10, lsl #16
+
+ @transpose r12, r11, r6, lr to r7, r8, r9, r10
+ TRANSPOSE_MATRIX r12, r11, r6, lr, r10, r9, r8, r7
+
+ @load back hev_mask r6 and filter_mask lr
+ ldr r12, c0x80808080
+ ldr r6, [sp]
+ ldr lr, [sp, #4]
+
+ eor r7, r7, r12 @ p1 offset to convert to a signed value
+ eor r8, r8, r12 @ p0 offset to convert to a signed value
+ eor r9, r9, r12 @ q0 offset to convert to a signed value
+ eor r10, r10, r12 @ q1 offset to convert to a signed value
+
+ str r9, [sp] @ store qs0 temporarily
+ str r8, [sp, #4] @ store ps0 temporarily
+ str r10,[sp, #8] @ store qs1 temporarily
+ str r7, [sp, #12] @ store ps1 temporarily
+
+ qsub8 r7, r7, r10 @ vp8_signed_char_clamp(ps1-qs1)
+ qsub8 r8, r9, r8 @ vp8_signed_char_clamp(vp8_filter + 3 * ( qs0 - ps0))
+
+ and r7, r7, r6 @ vp8_filter (r7) &= hev (r7 : filter)
+
+ qadd8 r7, r7, r8
+ ldr r9, c0x03030303 @ r9 = 3 --modified for vp8
+
+ qadd8 r7, r7, r8
+ ldr r10, c0x04040404
+
+ qadd8 r7, r7, r8
+
+ and r7, r7, lr @ vp8_filter &= mask
+
+ qadd8 r8, r7, r9 @ Filter2 (r8) = vp8_signed_char_clamp(vp8_filter+3)
+ qadd8 r7, r7, r10 @ vp8_filter = vp8_signed_char_clamp(vp8_filter+4)
+
+ mov r9, #0
+ shadd8 r8, r8, r9 @ Filter2 >>= 3
+ shadd8 r7, r7, r9 @ vp8_filter >>= 3
+ shadd8 r8, r8, r9
+ shadd8 r7, r7, r9
+ shadd8 lr, r8, r9 @ lr: filter2
+ shadd8 r7, r7, r9 @ r7: filter
+
+ @calculate output
+ ldr r8, [sp] @ load qs0
+ ldr r9, [sp, #4] @ load ps0
+
+ ldr r10, c0x01010101
+
+ qsub8 r8, r8, r7 @ u = vp8_signed_char_clamp(qs0 - vp8_filter)
+ qadd8 r9, r9, lr @ u = vp8_signed_char_clamp(ps0 + Filter2)
+
+ eor r8, r8, r12
+ eor r9, r9, r12
+
+ mov lr, #0
+
+ sadd8 r7, r7, r10
+ shadd8 r7, r7, lr
+
+ ldr r10,[sp, #8] @ load qs1
+ ldr r11,[sp, #12] @ load ps1
+
+ bic r7, r7, r6 @ r7: vp8_filter
+
+ qsub8 r10, r10, r7 @ u = vp8_signed_char_clamp(qs1 - vp8_filter)
+ qadd8 r11, r11, r7 @ u = vp8_signed_char_clamp(ps1 + vp8_filter)
+ eor r10, r10, r12
+ eor r11, r11, r12
+
+ sub r0, r0, r1, lsl #2
+
+ @we can use TRANSPOSE_MATRIX macro to transpose output - input: q1, q0, p0, p1
+ TRANSPOSE_MATRIX r11, r9, r8, r10, lr, r12, r7, r6
+
+ strh r6, [r0, #-2] @ store the result
+ mov r6, r6, lsr #16
+ strh_post r6, r0, r1
+
+ strh r7, [r0, #-2]
+ mov r7, r7, lsr #16
+ strh_post r7, r0, r1
+
+ strh r12, [r0, #-2]
+ mov r12, r12, lsr #16
+ strh_post r12, r0, r1
+
+ strh lr, [r0, #-2]
+ mov lr, lr, lsr #16
+ strh_post lr, r0, r1
+
+2:
+ sub r0, r0, #4
+ subs r5, r5, #1
+
+T ittt ne
+ ldrne r7, [r0, r1]
+A ldrne r6, [r0], r1, lsl #1 @ load source data
+T ldrne r6, [r0] @ load source data
+T addne r0, r0, r1, lsl #1
+T ittt ne
+ ldrne lr, [r0, r1]
+A ldrne r8, [r0], r1, lsl #1
+T ldrne r8, [r0]
+T addne r0, r0, r1, lsl #1
+
+ bne 1b
+
+ add sp, sp, #16
+ pop {r4 - r11, pc}
+endfunc
+
+@ void vp8_h_loop_filter16(uint8_t *dst, int stride,
+@ int fE, int fI, int hev_thresh)
+@ and
+@ void vp8_h_loop_filter8uv(uint8_t *dstU, uint8_t *dstV, int stride,
+@ int fE, int fI, int hev_thresh)
+@ call:
+@ void vp8_h_loop_filter(uint8_t *dst, int stride,
+@ int fE, int fI, int hev_thresh, int count)
+function ff_vp8_h_loop_filter_armv6, export=1
+ push {r4 - r11, lr}
+
+ sub r0, r0, #4 @ move r0 pointer down by 4
+ ldr r5, [sp, #40] @ counter
+ ldr r9, [sp, #36] @ load thresh address
+ sub sp, sp, #16 @ create temp buffer
+
+ ldr r7, [r0, r1] @ transpose will make it into p3-p0
+ ldr_post r6, r0, r1, lsl #1 @ load source data
+ ldr lr, [r0, r1]
+ ldr_post r8, r0, r1, lsl #1
+
+ orr r2, r2, r2, lsl #16
+ orr r3, r3, r3, lsl #16
+ orr r9, r9, r9, lsl #16
+ orr r4, r2, r2, lsl #8 @ flimE splat int -> byte
+ orr r2, r3, r3, lsl #8 @ flimI splat int -> byte
+ orr r3, r9, r9, lsl #8 @ thresh splat int -> byte
+
+1:
+ @ vp8_filter_mask() function
+ @ calculate breakout conditions
+ @ transpose the source data for 4-in-parallel operation
+ TRANSPOSE_MATRIX r6, r7, r8, lr, r12, r11, r10, r9
+
+ uqsub8 r7, r9, r10 @ p3 - p2
+ uqsub8 r8, r10, r9 @ p2 - p3
+ uqsub8 r9, r10, r11 @ p2 - p1
+ uqsub8 r10, r11, r10 @ p1 - p2
+ orr r7, r7, r8 @ abs (p3-p2)
+ orr r10, r9, r10 @ abs (p2-p1)
+ uqsub8 lr, r7, r2 @ compare to limit. lr: vp8_filter_mask
+ uqsub8 r10, r10, r2 @ compare to limit
+
+ sub r0, r0, r1, lsl #2 @ move r0 pointer down by 4 lines
+
+ orr lr, lr, r10
+
+ uqsub8 r6, r11, r12 @ p1 - p0
+ uqsub8 r7, r12, r11 @ p0 - p1
+ add r0, r0, #4 @ move r0 pointer up by 4
+ orr r6, r6, r7 @ abs (p1-p0)
+ str r11,[sp, #12] @ save p1
+ uqsub8 r10, r6, r2 @ compare to limit
+ uqsub8 r11, r6, r3 @ compare to thresh
+ orr lr, lr, r10
+
+ @ transpose uses 8 regs(r6 - r12 and lr). Need to save reg value now
+ @ transpose the source data for 4-in-parallel operation
+ str r11,[sp] @ push r11 to stack
+ ldr r7, [r0, r1]
+ ldr_post r6, r0, r1, lsl #1 @ load source data
+ str r12,[sp, #4] @ save current reg before load q0 - q3 data
+ str lr, [sp, #8]
+ ldr lr, [r0, r1]
+ ldr_post r8, r0, r1, lsl #1
+
+ TRANSPOSE_MATRIX r6, r7, r8, lr, r12, r11, r10, r9
+
+ ldr lr, [sp, #8] @ load back (f)limit accumulator
+
+ uqsub8 r6, r12, r11 @ q3 - q2
+ uqsub8 r7, r11, r12 @ q2 - q3
+ uqsub8 r12, r11, r10 @ q2 - q1
+ uqsub8 r11, r10, r11 @ q1 - q2
+ orr r6, r6, r7 @ abs (q3-q2)
+ orr r7, r12, r11 @ abs (q2-q1)
+ uqsub8 r6, r6, r2 @ compare to limit
+ uqsub8 r7, r7, r2 @ compare to limit
+ ldr r11,[sp, #4] @ load back p0
+ ldr r12,[sp, #12] @ load back p1
+ orr lr, lr, r6
+ orr lr, lr, r7
+
+ uqsub8 r6, r11, r9 @ p0 - q0
+ uqsub8 r7, r9, r11 @ q0 - p0
+ uqsub8 r8, r12, r10 @ p1 - q1
+ uqsub8 r11, r10, r12 @ q1 - p1
+ orr r6, r6, r7 @ abs (p0-q0)
+ ldr r7, c0x7F7F7F7F
+ orr r8, r8, r11 @ abs (p1-q1)
+ uqadd8 r6, r6, r6 @ abs (p0-q0) * 2
+ and r8, r7, r8, lsr #1 @ abs (p1-q1) / 2
+ uqsub8 r11, r10, r9 @ q1 - q0
+ uqadd8 r6, r8, r6 @ abs (p0-q0)*2 + abs (p1-q1)/2
+ uqsub8 r12, r9, r10 @ q0 - q1
+ uqsub8 r6, r6, r4 @ compare to flimit
+
+ orr r9, r11, r12 @ abs (q1-q0)
+ uqsub8 r8, r9, r2 @ compare to limit
+ uqsub8 r10, r9, r3 @ compare to thresh
+ orr lr, lr, r6
+ orr lr, lr, r8
+
+ mvn r11, #0 @ r11 == -1
+ mov r12, #0
+
+ usub8 lr, r12, lr
+ ldr r9, [sp] @ load the compared result
+ sel lr, r11, r12 @ filter mask: lr
+
+ cmp lr, #0
+ beq 2f @ skip filtering
+
+
+ @vp8_hevmask() function
+ @calculate high edge variance
+ sub r0, r0, r1, lsl #2 @ move r0 pointer down by 4 lines
+
+ orr r9, r9, r10
+
+ ldrh r7, [r0, #-2]
+ ldrh_post r8, r0, r1
+
+ usub8 r9, r12, r9
+ sel r6, r12, r11 @ hev mask: r6
+
+
+ @ vp8_mbfilter() function
+ @ p2, q2 are only needed at the end. do not need to load them in now.
+ @ Transpose needs 8 regs(r6 - r12, and lr). Save r6 and lr first
+ @ load soure data to r6, r11, r12, lr
+ ldrh r9, [r0, #-2]
+ ldrh_post r10, r0, r1
+
+ pkhbt r12, r7, r8, lsl #16
+
+ ldrh r7, [r0, #-2]
+ ldrh_post r8, r0, r1
+
+ pkhbt r11, r9, r10, lsl #16
+
+ ldrh r9, [r0, #-2]
+ ldrh_post r10, r0, r1
+
+ str r6, [sp] @ save r6
+ str lr, [sp, #4] @ save lr
+
+ pkhbt r6, r7, r8, lsl #16
+ pkhbt lr, r9, r10, lsl #16
+
+ @transpose r12, r11, r6, lr to p1, p0, q0, q1
+ TRANSPOSE_MATRIX r12, r11, r6, lr, r10, r9, r8, r7
+
+ @load back hev_mask r6 and filter_mask lr
+ ldr r12, c0x80808080
+ ldr r6, [sp]
+ ldr lr, [sp, #4]
+
+ eor r7, r7, r12 @ ps1
+ eor r8, r8, r12 @ ps0
+ eor r9, r9, r12 @ qs0
+ eor r10, r10, r12 @ qs1
+
+ qsub8 r12, r9, r8 @ vp8_signed_char_clamp(vp8_filter + 3 * ( qs0 - ps0))
+ str r7, [sp, #12] @ store ps1 temporarily
+ qsub8 r7, r7, r10 @ vp8_signed_char_clamp(ps1-qs1)
+ str r10,[sp, #8] @ store qs1 temporarily
+ qadd8 r7, r7, r12
+ str r9, [sp] @ store qs0 temporarily
+ qadd8 r7, r7, r12
+ str r8, [sp, #4] @ store ps0 temporarily
+ qadd8 r7, r7, r12 @ vp8_filter: r7
+
+ ldr r10, c0x03030303 @ r10 = 3 --modified for vp8
+ ldr r9, c0x04040404
+
+ and r7, r7, lr @ vp8_filter &= mask (lr is free)
+
+ mov r12, r7 @ Filter2: r12
+ and r12, r12, r6 @ Filter2 &= hev
+
+ @save bottom 3 bits so that we round one side +4 and the other +3
+ qadd8 r8, r12, r9 @ Filter1 (r8) = vp8_signed_char_clamp(Filter2+4)
+ qadd8 r12, r12, r10 @ Filter2 (r12) = vp8_signed_char_clamp(Filter2+3)
+
+ mov r10, #0
+ shadd8 r8, r8, r10 @ Filter1 >>= 3
+ shadd8 r12, r12, r10 @ Filter2 >>= 3
+ shadd8 r8, r8, r10
+ shadd8 r12, r12, r10
+ shadd8 r8, r8, r10 @ r8: Filter1
+ shadd8 r12, r12, r10 @ r12: Filter2
+
+ ldr r9, [sp] @ load qs0
+ ldr r11,[sp, #4] @ load ps0
+
+ qsub8 r9, r9, r8 @ qs0 = vp8_signed_char_clamp(qs0 - Filter1)
+ qadd8 r11, r11, r12 @ ps0 = vp8_signed_char_clamp(ps0 + Filter2)
+
+ bic r12, r7, r6 @vp8_filter &= ~hev ( r6 is free)
+
+ @roughly 3/7th difference across boundary
+ mov lr, #0x1b @ 27
+ mov r7, #0x3f @ 63
+
+ sxtb16 r6, r12
+ sxtb16 r10, r12, ror #8
+ smlabb r8, r6, lr, r7
+ smlatb r6, r6, lr, r7
+ smlabb r7, r10, lr, r7
+ smultb r10, r10, lr
+ ssat r8, #8, r8, asr #7
+ ssat r6, #8, r6, asr #7
+ add r10, r10, #63
+ ssat r7, #8, r7, asr #7
+ ssat r10, #8, r10, asr #7
+
+ ldr lr, c0x80808080
+
+ pkhbt r6, r8, r6, lsl #16
+ pkhbt r10, r7, r10, lsl #16
+ uxtb16 r6, r6
+ uxtb16 r10, r10
+
+ sub r0, r0, r1, lsl #2 @ move r0 pointer down by 4 lines
+
+ orr r10, r6, r10, lsl #8 @ u = vp8_signed_char_clamp((63 + Filter2 * 27)>>7)
+
+ qsub8 r8, r9, r10 @ s = vp8_signed_char_clamp(qs0 - u)
+ qadd8 r10, r11, r10 @ s = vp8_signed_char_clamp(ps0 + u)
+ eor r8, r8, lr @ *oq0 = s^0x80
+ eor r10, r10, lr @ *op0 = s^0x80
+
+ strb r10,[r0, #-1] @ store op0 result
+ strb_post r8, r0, r1 @ store oq0 result
+ mov r10, r10, lsr #8
+ mov r8, r8, lsr #8
+ strb r10,[r0, #-1]
+ strb_post r8, r0, r1
+ mov r10, r10, lsr #8
+ mov r8, r8, lsr #8
+ strb r10,[r0, #-1]
+ strb_post r8, r0, r1
+ mov r10, r10, lsr #8
+ mov r8, r8, lsr #8
+ strb r10,[r0, #-1]
+ strb_post r8, r0, r1
+
+ @roughly 2/7th difference across boundary
+ mov lr, #0x12 @ 18
+ mov r7, #0x3f @ 63
+
+ sxtb16 r6, r12
+ sxtb16 r10, r12, ror #8
+ smlabb r8, r6, lr, r7
+ smlatb r6, r6, lr, r7
+ smlabb r9, r10, lr, r7
+ smlatb r10, r10, lr, r7
+ ssat r8, #8, r8, asr #7
+ ssat r6, #8, r6, asr #7
+ ssat r9, #8, r9, asr #7
+ ssat r10, #8, r10, asr #7
+
+ sub r0, r0, r1, lsl #2 @ move r0 pointer down by 4 lines
+
+ pkhbt r6, r8, r6, lsl #16
+ pkhbt r10, r9, r10, lsl #16
+
+ ldr r9, [sp, #8] @ load qs1
+ ldr r11,[sp, #12] @ load ps1
+ ldr lr, c0x80808080
+
+ uxtb16 r6, r6
+ uxtb16 r10, r10
+
+ add r0, r0, #2
+
+ orr r10, r6, r10, lsl #8 @ u = vp8_signed_char_clamp((63 + Filter2 * 18)>>7)
+
+ qsub8 r8, r9, r10 @ s = vp8_signed_char_clamp(qs1 - u)
+ qadd8 r10, r11, r10 @ s = vp8_signed_char_clamp(ps1 + u)
+ eor r8, r8, lr @ *oq1 = s^0x80
+ eor r10, r10, lr @ *op1 = s^0x80
+
+ ldrb r11,[r0, #-5] @ load p2 for 1/7th difference across boundary
+ strb r10,[r0, #-4] @ store op1
+ strb r8, [r0, #-1] @ store oq1
+ ldrb_post r9, r0, r1 @ load q2 for 1/7th difference across boundary
+
+ mov r10, r10, lsr #8
+ mov r8, r8, lsr #8
+
+ ldrb r6, [r0, #-5]
+ strb r10,[r0, #-4]
+ strb r8, [r0, #-1]
+ ldrb_post r7, r0, r1
+
+ mov r10, r10, lsr #8
+ mov r8, r8, lsr #8
+ orr r11, r11, r6, lsl #8
+ orr r9, r9, r7, lsl #8
+
+ ldrb r6, [r0, #-5]
+ strb r10,[r0, #-4]
+ strb r8, [r0, #-1]
+ ldrb_post r7, r0, r1
+
+ mov r10, r10, lsr #8
+ mov r8, r8, lsr #8
+ orr r11, r11, r6, lsl #16
+ orr r9, r9, r7, lsl #16
+
+ ldrb r6, [r0, #-5]
+ strb r10,[r0, #-4]
+ strb r8, [r0, #-1]
+ ldrb_post r7, r0, r1
+ orr r11, r11, r6, lsl #24
+ orr r9, r9, r7, lsl #24
+
+ @roughly 1/7th difference across boundary
+ eor r9, r9, lr
+ eor r11, r11, lr
+
+ mov lr, #0x9 @ 9
+ mov r7, #0x3f @ 63
+
+ sxtb16 r6, r12
+ sxtb16 r10, r12, ror #8
+ smlabb r8, r6, lr, r7
+ smlatb r6, r6, lr, r7
+ smlabb r12, r10, lr, r7
+ smlatb r10, r10, lr, r7
+ ssat r8, #8, r8, asr #7
+ ssat r6, #8, r6, asr #7
+ ssat r12, #8, r12, asr #7
+ ssat r10, #8, r10, asr #7
+
+ sub r0, r0, r1, lsl #2
+
+ pkhbt r6, r8, r6, lsl #16
+ pkhbt r10, r12, r10, lsl #16
+
+ uxtb16 r6, r6
+ uxtb16 r10, r10
+
+ ldr lr, c0x80808080
+
+ orr r10, r6, r10, lsl #8 @ u = vp8_signed_char_clamp((63 + Filter2 * 9)>>7)
+
+ qadd8 r8, r11, r10 @ s = vp8_signed_char_clamp(ps2 + u)
+ qsub8 r10, r9, r10 @ s = vp8_signed_char_clamp(qs2 - u)
+ eor r8, r8, lr @ *op2 = s^0x80
+ eor r10, r10, lr @ *oq2 = s^0x80
+
+ strb r8, [r0, #-5] @ store *op2
+ strb_post r10, r0, r1 @ store *oq2
+ mov r8, r8, lsr #8
+ mov r10, r10, lsr #8
+ strb r8, [r0, #-5]
+ strb_post r10, r0, r1
+ mov r8, r8, lsr #8
+ mov r10, r10, lsr #8
+ strb r8, [r0, #-5]
+ strb_post r10, r0, r1
+ mov r8, r8, lsr #8
+ mov r10, r10, lsr #8
+ strb r8, [r0, #-5]
+ strb_post r10, r0, r1
+
+ @adjust r0 pointer for next loop
+ sub r0, r0, #2
+
+2:
+ sub r0, r0, #4
+ subs r5, r5, #1
+
+T ittt ne
+ ldrne r7, [r0, r1]
+A ldrne r6, [r0], r1, lsl #1 @ load source data
+T ldrne r6, [r0]
+T addne r0, r0, r1, lsl #1
+T ittt ne
+ ldrne lr, [r0, r1]
+A ldrne r8, [r0], r1, lsl #1
+T ldrne r8, [r0]
+T addne r0, r0, r1, lsl #1
+
+ bne 1b
+
+ add sp, sp, #16
+ pop {r4 - r11, pc}
+endfunc
+
+@ MC
+
+@ void put_vp8_pixels16(uint8_t *dst, int dststride, uint8_t *src,
+@ int srcstride, int h, int mx, int my)
+function ff_put_vp8_pixels16_armv6, export=1
+ push {r4 - r11}
+ ldr r12,[sp, #32] @ h
+1:
+ subs r12, r12, #2
+ ldr r5, [r2, #4]
+ ldr r6, [r2, #8]
+ ldr r7, [r2, #12]
+ ldr_post r4, r2, r3
+ ldr r9, [r2, #4]
+ ldr r10,[r2, #8]
+ ldr r11,[r2, #12]
+ ldr_post r8, r2, r3
+ strd r6, r7, [r0, #8]
+ strd_post r4, r5, r0, r1
+ strd r10, r11,[r0, #8]
+ strd_post r8, r9, r0, r1
+ bgt 1b
+ pop {r4 - r11}
+ bx lr
+endfunc
+
+@ void put_vp8_pixels8(uint8_t *dst, int dststride, uint8_t *src,
+@ int srcstride, int h, int mx, int my)
+function ff_put_vp8_pixels8_armv6, export=1
+ push {r4 - r11}
+ ldr r12,[sp, #32] @ h
+1:
+ subs r12, r12, #4
+ ldr r5, [r2, #4]
+ ldr_post r4, r2, r3
+ ldr r7, [r2, #4]
+ ldr_post r6, r2, r3
+ ldr r9, [r2, #4]
+ ldr_post r8, r2, r3
+ ldr r11,[r2, #4]
+ ldr_post r10, r2, r3
+ strd_post r4, r5, r0, r1
+ strd_post r6, r7, r0, r1
+ strd_post r8, r9, r0, r1
+ strd_post r10, r11, r0, r1
+ bgt 1b
+ pop {r4 - r11}
+ bx lr
+endfunc
+
+@ void put_vp8_pixels4(uint8_t *dst, int dststride, uint8_t *src,
+@ int srcstride, int h, int mx, int my)
+function ff_put_vp8_pixels4_armv6, export=1
+ ldr r12, [sp, #0] @ h
+ push {r4 - r6, lr}
+1:
+ subs r12, r12, #4
+ ldr r5, [r2, r3]
+ ldr_post r4, r2, r3, lsl #1
+ ldr lr, [r2, r3]
+ ldr_post r6, r2, r3, lsl #1
+ str r5, [r0, r1]
+ str_post r4, r0, r1, lsl #1
+ str lr, [r0, r1]
+ str_post r6, r0, r1, lsl #1
+ bgt 1b
+ pop {r4 - r6, pc}
+endfunc
+
+@ note: worst case sum of all 6-tap filter values * 255 is 0x7f80 so 16 bit
+@ arithmatic can be used to apply filters
+const sixtap_filters_13245600, align=4
+ .short 2, 108, -11, 36, -8, 1, 0, 0
+ .short 3, 77, -16, 77, -16, 3, 0, 0
+ .short 1, 36, -8, 108, -11, 2, 0, 0
+endconst
+const fourtap_filters_1324, align=4
+ .short -6, 12, 123, -1
+ .short -9, 50, 93, -6
+ .short -6, 93, 50, -9
+ .short -1, 123, 12, -6
+endconst
+
+@ void put_vp8_epel_h6(uint8_t *dst, int dststride, uint8_t *src,
+@ int srcstride, int w, int h, int mx)
+function ff_put_vp8_epel_h6_armv6, export=1
+ push {r4 - r11, lr}
+
+ sub r2, r2, #2
+ movrel lr, sixtap_filters_13245600 - 16
+ ldr r12,[sp, #44] @ vp8_filter index
+ ldr r4, [sp, #36] @ width
+ add lr, lr, r12, lsl #3
+ sub r3, r3, r4 @ src_stride - block_width
+ sub r1, r1, r4 @ dst_stride - block_width
+ lsr r4, #2
+
+ str r4, [sp, #36] @ "4-in-parallel" loop counter @40
+ str r3, [sp, #44] @ src_stride - block_width @48
+ push {r1} @ dst_stride - block_width @0
+ @ height @44
+
+ ldr r1, [lr], #4 @ coefficients
+ ldr r3, [lr], #4
+ ldr lr, [lr]
+1:
+ @ 3 loads, 10 shuffles and then mul/acc/add/shr
+ @ o0: i0/i1/i2/i3/i4/i5 -> i0/i2 (ld1) | i1/i3 (ld1) | i4/i5 (ld2)
+ @ o1: i1/i2/i3/i4/i5/i6 -> i1/i3 (ld1) | i2/i4 (ld2) | i5/i6 (ld2/3)
+ @ o2: i2/i3/i4/i5/i6/i7 -> i2/i4 (ld2) | i3/i5 (ld2) | i6/i7 (ld3)
+ @ o3: i3/i4/i5/i6/i7/i8 -> i3/i5 (ld2) | i4/i6 (ld2/3) | i7/i8 (ld3)
+ ldr r7, [r2, #5] @ ld3 -> src[5-8]
+ ldr r6, [r2, #2] @ ld2 -> src[2-5]
+ ldr r5, [r2], #4 @ ld1 -> src[0-3]
+
+ pkhtb r7, r7, r7, asr #8 @ src[8,7,7,6]
+ uxtb16 r9, r6, ror #8 @ src[5] | src[3]
+ uxtb16 r6, r6 @ src[4] | src[2]
+ uxtb16 r8, r5, ror #8 @ src[3] | src[1]
+ uxtb16 r11, r7, ror #8 @ src[8] | src[7]
+ uxtb16 r7, r7 @ src[7] | src[6]
+ pkhtb r10, r9, r6, asr #16 @ src[5] | src[4]
+ uxtb16 r5, r5 @ src[2] | src[0]
+
+ smuad r11, r11, lr @ filter[3][2] -> r11
+ subs r4, r4, #1
+ pkhbt r12, r10, r7, lsl #16 @ src[6] | src[4]
+ smuad r7, r7, lr @ filter[2][2] -> r7
+ smuad r5, r5, r1 @ filter[0][0] -> r5
+ smlad r11, r9, r1, r11 @ filter[3][0] -> r11
+ smlad r7, r9, r3, r7 @ filter[2][1] -> r7
+ smuad r9, r8, r1 @ filter[1][0] -> r9
+ smlad r5, r8, r3, r5 @ filter[0][1] -> r5
+ pkhtb r8, r12, r10, asr #16 @ src[6] | src[5]
+ smlad r11, r12, r3, r11 @ filter[3][1] -> r11
+ smlad r9, r6, r3, r9 @ filter[1][1] -> r9
+ smlad r5, r10, lr, r5 @ filter[0][2] -> r5
+ smlad r7, r6, r1, r7 @ filter[2][0] -> r7
+ smlad r9, r8, lr, r9 @ filter[1][2] -> r9
+
+ add r5, r5, #0x40 @ round_shift_and_clamp[0]
+ add r9, r9, #0x40 @ round_shift_and_clamp[1]
+ add r7, r7, #0x40 @ round_shift_and_clamp[2]
+ add r11, r11, #0x40 @ round_shift_and_clamp[3]
+
+ usat r5, #8, r5, asr #7
+ usat r9, #8, r9, asr #7
+ usat r7, #8, r7, asr #7
+ usat r11, #8, r11, asr #7
+
+ strb r5, [r0], #1 @ store res[0]
+ strb r9, [r0], #1 @ store res[1]
+ strb r7, [r0], #1 @ store res[2]
+ strb r11,[r0], #1 @ store res[3]
+
+ bne 1b
+
+ ldr r12,[sp, #44] @ height = outer-loop counter
+ subs r12, r12, #1
+T itttt ne
+ ldrne r4, [sp, #40] @ 4-in-parallel loop counter
+ ldrne r5, [sp, #48]
+ ldrne r6, [sp]
+ strne r12,[sp, #44]
+ add r2, r2, r5 @ move to next input/output lines
+ add r0, r0, r6
+
+ bne 1b
+
+ add sp, sp, #4 @ restore stack after push{r1} above
+ pop {r4 - r11, pc}
+endfunc
+
+@ void put_vp8_epel_v6(uint8_t *dst, int dststride, uint8_t *src,
+@ int srcstride, int w, int h, int my)
+function ff_put_vp8_epel_v6_armv6, export=1
+ push {r4 - r11, lr}
+
+ movrel lr, sixtap_filters_13245600 - 16
+ ldr r12,[sp, #44] @ vp8_filter index
+ ldr r4, [sp, #36] @ width
+ add lr, lr, r12, lsl #3
+ sub r1, r1, r4 @ dst_stride - block_width
+ lsr r4, #2
+
+ str r4, [sp, #36] @ "4-in-parallel" loop counter @40
+ str r3, [sp, #44] @ src_stride - block_width @48
+ push {r1} @ dst_stride - block_width @0
+ @ height @44
+1:
+ add r1, r3, r3, lsl #1 @ stride * 3
+ ldr_dpren r5, r2, r3 @ src[0,1,2,3 + stride * 1]
+ ldr r6, [r2, r3] @ src[0,1,2,3 + stride * 3]
+ ldr r7, [r2, r3, lsl #1] @ src[0,1,2,3 + stride * 4]
+ ldr r8, [r2, r1] @ src[0,1,2,3 + stride * 5]
+
+ @ byte -> word and "transpose"
+ uxtb16 r9, r5, ror #8 @ src[3 + stride*1] | src[1 + stride*1]
+ uxtb16 r10, r6, ror #8 @ src[3 + stride*3] | src[1 + stride*3]
+ uxtb16 r11, r7, ror #8 @ src[3 + stride*4] | src[1 + stride*4]
+ uxtb16 r12, r8, ror #8 @ src[3 + stride*5] | src[1 + stride*5]
+ uxtb16 r5, r5 @ src[2 + stride*1] | src[0 + stride*1]
+ uxtb16 r6, r6 @ src[2 + stride*3] | src[0 + stride*3]
+ uxtb16 r7, r7 @ src[2 + stride*4] | src[0 + stride*4]
+ uxtb16 r8, r8 @ src[2 + stride*5] | src[0 + stride*5]
+ pkhbt r1, r9, r10, lsl #16 @ src[1 + stride*3] | src[1 + stride*1]
+ pkhtb r9, r10, r9, asr #16 @ src[3 + stride*3] | src[3 + stride*1]
+ pkhbt r10, r11, r12, lsl #16 @ src[1 + stride*5] | src[1 + stride*4]
+ pkhtb r11, r12, r11, asr #16 @ src[3 + stride*5] | src[3 + stride*4]
+ pkhbt r12, r5, r6, lsl #16 @ src[0 + stride*3] | src[0 + stride*1]
+ pkhtb r5, r6, r5, asr #16 @ src[2 + stride*3] | src[2 + stride*1]
+ pkhbt r6, r7, r8, lsl #16 @ src[0 + stride*5] | src[0 + stride*4]
+ pkhtb r7, r8, r7, asr #16 @ src[2 + stride*5] | src[2 + stride*4]
+
+ ldr r8, [lr, #4] @ stall - if only I had more registers...
+ smuad r12, r12, r8 @ filter[0][1]
+ smuad r1, r1, r8 @ filter[1][1]
+ smuad r5, r5, r8 @ filter[2][1]
+ smuad r9, r9, r8 @ filter[3][1]
+ ldr r8, [lr, #8] @ stall - if only I had more registers...
+ smlad r12, r6, r8, r12 @ filter[0][2]
+ smlad r1, r10, r8, r1 @ filter[1][2]
+ ldr_dpren r6, r2, r3, lsl #1 @ src[0,1,2,3 + stride * 0]
+ ldr r10,[r2], #4 @ src[0,1,2,3 + stride * 2]
+ smlad r5, r7, r8, r5 @ filter[2][2]
+ smlad r9, r11, r8, r9 @ filter[3][2]
+
+ uxtb16 r7, r6, ror #8 @ src[3 + stride*0] | src[1 + stride*0]
+ uxtb16 r11, r10, ror #8 @ src[3 + stride*2] | src[1 + stride*2]
+ uxtb16 r6, r6 @ src[2 + stride*0] | src[0 + stride*0]
+ uxtb16 r10, r10 @ src[2 + stride*2] | src[0 + stride*2]
+
+ pkhbt r8, r7, r11, lsl #16 @ src[1 + stride*2] | src[1 + stride*0]
+ pkhtb r7, r11, r7, asr #16 @ src[3 + stride*2] | src[3 + stride*0]
+ pkhbt r11, r6, r10, lsl #16 @ src[0 + stride*2] | src[0 + stride*0]
+ pkhtb r6, r10, r6, asr #16 @ src[2 + stride*2] | src[2 + stride*0]
+
+ ldr r10,[lr] @ stall - if only I had more registers...
+ subs r4, r4, #1 @ counter--
+ smlad r12, r11, r10, r12 @ filter[0][0]
+ smlad r1, r8, r10, r1 @ filter[1][0]
+ smlad r5, r6, r10, r5 @ filter[2][0]
+ smlad r9, r7, r10, r9 @ filter[3][0]
+
+ add r12, r12, #0x40 @ round_shift_and_clamp[0]
+ add r1, r1, #0x40 @ round_shift_and_clamp[1]
+ add r5, r5, #0x40 @ round_shift_and_clamp[2]
+ add r9, r9, #0x40 @ round_shift_and_clamp[3]
+
+ usat r12, #8, r12, asr #7
+ usat r1, #8, r1, asr #7
+ usat r5, #8, r5, asr #7
+ usat r9, #8, r9, asr #7
+
+ strb r12,[r0], #1 @ store res[0]
+ strb r1, [r0], #1 @ store res[1]
+ strb r5, [r0], #1 @ store res[2]
+ strb r9, [r0], #1 @ store res[3]
+
+ bne 1b
+
+ ldr r12,[sp, #44] @ height = outer-loop counter
+ subs r12, r12, #1
+T itttt ne
+ ldrne r4, [sp, #40] @ 4-in-parallel loop counter
+ ldrne r6, [sp, #0]
+ subne r2, r2, r4, lsl #2
+ strne r12,[sp, #44]
+ add r0, r0, r6
+ add r2, r2, r3 @ move to next input/output lines
+
+ bne 1b
+
+ add sp, sp, #4 @ restore stack after push{r1} above
+ pop {r4 - r11, pc}
+endfunc
+
+@ void put_vp8_epel_h4(uint8_t *dst, int dststride, uint8_t *src,
+@ int srcstride, int w, int h, int mx)
+function ff_put_vp8_epel_h4_armv6, export=1
+ push {r4 - r11, lr}
+
+ subs r2, r2, #1
+ movrel lr, fourtap_filters_1324 - 4
+ ldr r4, [sp, #36] @ width
+ ldr r12,[sp, #44] @ vp8_filter index
+ add lr, lr, r12, lsl #2
+ sub r3, r3, r4 @ src_stride - block_width
+ sub r1, r1, r4 @ dst_stride - block_width
+ ldr r5, [lr]
+ ldr r6, [lr, #4]
+ asr r4, #2
+
+ ldr lr, [sp, #40] @ height = outer-loop counter
+ str r4, [sp, #36] @ "4-in-parallel" inner loop counter
+1:
+ @ 3 loads, 5 uxtb16s and then mul/acc/add/shr
+ @ o0: i0/i1/i2/i3 -> i0/i2(ld1) + i1/i3(ld1)
+ @ o1: i1/i2/i3/i4 -> i1/i3(ld1) + i2/i4(ld2)
+ @ o2: i2/i3/i4/i5 -> i2/i4(ld2) + i3/i5(ld2)
+ @ o3: i3/i4/i5/i6 -> i3/i5(ld2) + i4/i6(ld3)
+ ldr r9, [r2, #3] @ load source data
+ ldr r8, [r2, #2]
+ ldr r7, [r2], #4
+
+ uxtb16 r9, r9, ror #8 @ src[6] | src[4]
+ uxtb16 r10, r8, ror #8 @ src[5] | src[3]
+ uxtb16 r8, r8 @ src[4] | src[2]
+ uxtb16 r11, r7, ror #8 @ src[3] | src[1]
+ uxtb16 r7, r7 @ src[2] | src[0]
+
+ smuad r9, r9, r6 @ filter[3][1] -> r9
+ smuad r12, r10, r6 @ filter[2][1] -> r12
+ smuad r7, r7, r5 @ filter[0][0] -> r7
+ smlad r9, r10, r5, r9 @ filter[3][0] -> r9
+ smuad r10, r11, r5 @ filter[1][0] -> r10
+ smlad r12, r8, r5, r12 @ filter[2][0] -> r12
+ smlad r7, r11, r6, r7 @ filter[0][1] -> r7
+ smlad r10, r8, r6, r10 @ filter[1][1] -> r10
+
+ subs r4, r4, #1 @ counter--
+
+ add r7, r7, #0x40 @ round_shift_and_clamp[0]
+ add r10, r10, #0x40 @ round_shift_and_clamp[1]
+ add r12, r12, #0x40 @ round_shift_and_clamp[2]
+ add r9, r9, #0x40 @ round_shift_and_clamp[3]
+
+ usat r7, #8, r7, asr #7
+ usat r10, #8, r10, asr #7
+ usat r12, #8, r12, asr #7
+ usat r9, #8, r9, asr #7
+
+ strb r7, [r0], #1 @ store res[0]
+ strb r10,[r0], #1 @ store res[1]
+ strb r12,[r0], #1 @ store res[2]
+ strb r9, [r0], #1 @ store res[3]
+
+ bne 1b
+
+ subs lr, lr, #1
+T it ne
+ ldrne r4, [sp, #36] @ 4-in-parallel loop counter
+ add r2, r2, r3 @ move to next input/output lines
+ add r0, r0, r1
+
+ bne 1b
+
+ pop {r4 - r11, pc}
+endfunc
+
+@ void put_vp8_epel_v4(uint8_t *dst, int dststride, uint8_t *src,
+@ int srcstride, int w, int h, int my)
+function ff_put_vp8_epel_v4_armv6, export=1
+ push {r4 - r11, lr}
+
+ movrel lr, fourtap_filters_1324 - 4
+ ldr r12,[sp, #44] @ vp8_filter index
+ ldr r4, [sp, #36] @ width
+ add lr, lr, r12, lsl #2
+ sub r1, r1, r4 @ dst_stride - block_width
+ asr r4, #2
+ ldr r5, [lr]
+ ldr r6, [lr, #4]
+
+ str r4, [sp, #36] @ "4-in-parallel" loop counter @40
+ str r3, [sp, #44] @ src_stride @48
+ push {r1} @ dst_stride - block_width @36
+ @ height @44
+1:
+ ldr lr, [r2, r3, lsl #1] @ load source pixels
+ ldr r12,[r2, r3]
+ ldr_dpren r7, r2, r3
+ ldr r11,[r2], #4
+
+ @ byte -> word and "transpose"
+ uxtb16 r8, lr, ror #8 @ src[3 + stride*3] | src[1 + stride*3]
+ uxtb16 r9, r12, ror #8 @ src[3 + stride*2] | src[1 + stride*2]
+ uxtb16 r3, r7, ror #8 @ src[3 + stride*0] | src[1 + stride*0]
+ uxtb16 r1, r11, ror #8 @ src[3 + stride*1] | src[1 + stride*1]
+ uxtb16 lr, lr @ src[2 + stride*3] | src[0 + stride*3]
+ uxtb16 r12, r12 @ src[2 + stride*2] | src[0 + stride*2]
+ uxtb16 r7, r7 @ src[2 + stride*0] | src[0 + stride*0]
+ uxtb16 r11, r11 @ src[2 + stride*1] | src[0 + stride*1]
+ pkhbt r10, r1, r8, lsl #16 @ src[1 + stride*3] | src[1 + stride*1]
+ pkhtb r1, r8, r1, asr #16 @ src[3 + stride*3] | src[3 + stride*1]
+ pkhbt r8, r3, r9, lsl #16 @ src[1 + stride*2] | src[1 + stride*0]
+ pkhtb r3, r9, r3, asr #16 @ src[3 + stride*2] | src[3 + stride*0]
+ pkhbt r9, r11, lr, lsl #16 @ src[0 + stride*3] | src[0 + stride*1]
+ pkhtb r11, lr, r11, asr #16 @ src[2 + stride*3] | src[2 + stride*1]
+ pkhbt lr, r7, r12, lsl #16 @ src[0 + stride*2] | src[0 + stride*0]
+ pkhtb r7, r12, r7, asr #16 @ src[2 + stride*2] | src[2 + stride*0]
+
+ smuad r9, r9, r6 @ filter[0][1]
+ smuad r10, r10, r6 @ filter[1][1]
+ smuad r11, r11, r6 @ filter[2][1]
+ smuad r1, r1, r6 @ filter[3][1]
+ smlad r9, lr, r5, r9 @ filter[0][0]
+ smlad r10, r8, r5, r10 @ filter[1][0]
+ smlad r11, r7, r5, r11 @ filter[2][0]
+ smlad r1, r3, r5, r1 @ filter[3][0]
+
+ subs r4, r4, #1 @ counter--
+ ldr r3, [sp, #48] @ FIXME prevent clobber of r3 above?
+
+ add r9, r9, #0x40 @ round_shift_and_clamp[0]
+ add r10, r10, #0x40 @ round_shift_and_clamp[1]
+ add r11, r11, #0x40 @ round_shift_and_clamp[2]
+ add r1, r1, #0x40 @ round_shift_and_clamp[3]
+
+ usat r9, #8, r9, asr #7
+ usat r10, #8, r10, asr #7
+ usat r11, #8, r11, asr #7
+ usat r1, #8, r1, asr #7
+
+ strb r9, [r0], #1 @ store result
+ strb r10,[r0], #1
+ strb r11,[r0], #1
+ strb r1, [r0], #1
+
+ bne 1b
+
+ ldr r12,[sp, #44] @ height = outer-loop counter
+ subs r12, r12, #1
+T ittt ne
+ ldrne r4, [sp, #40] @ 4-in-parallel loop counter
+ ldrne r9, [sp, #0]
+ strne r12,[sp, #44]
+ sub r2, r2, r4, lsl #2
+ add r0, r0, r9
+ add r2, r2, r3 @ move to next input/output lines
+
+ bne 1b
+
+ add sp, sp, #4 @ restore stack after push{r1} above
+ pop {r4 - r11, pc}
+endfunc
+
+@ void put_vp8_bilin_h(uint8_t *dst, int dststride, uint8_t *src,
+@ int srcstride, int w, int h, int mx)
+function ff_put_vp8_bilin_h_armv6, export=1
+ push {r4 - r9, lr}
+
+ ldr r8, [sp, #36] @ vp8_filter index
+ ldr r12,[sp, #32] @ height = outer-loop counter
+ ldr r4, [sp, #28] @ width
+ lsl r5, r8, #16 @ mx << 16
+ sub r3, r3, r4 @ src_stride - block_width
+ sub r1, r1, r4 @ dst_stride - block_width
+ asr r4, #2
+ sub r5, r5, r8 @ (mx << 16) | (-mx)
+ str r4, [sp, #28] @ "4-in-parallel" loop counter
+ add r5, r5, #8 @ (8 - mx) | (mx << 16) = filter coefficients
+1:
+ ldrb r6, [r2], #1 @ load source data
+ ldrb r7, [r2], #1
+ ldrb r8, [r2], #1
+ ldrb r9, [r2], #1
+ ldrb lr, [r2]
+
+ pkhbt r6, r6, r7, lsl #16 @ src[1] | src[0]
+ pkhbt r7, r7, r8, lsl #16 @ src[2] | src[1]
+ pkhbt r8, r8, r9, lsl #16 @ src[3] | src[2]
+ pkhbt r9, r9, lr, lsl #16 @ src[4] | src[3]
+
+ smuad r6, r6, r5 @ apply the filter
+ smuad r7, r7, r5
+ smuad r8, r8, r5
+ smuad r9, r9, r5
+
+ subs r4, r4, #1 @ counter--
+
+ add r6, r6, #0x4 @ round_shift_and_clamp
+ add r7, r7, #0x4
+ add r8, r8, #0x4
+ add r9, r9, #0x4
+
+ asr r6, #3
+ asr r7, #3
+ pkhbt r6, r6, r8, lsl #13
+ pkhbt r7, r7, r9, lsl #13
+ orr r6, r6, r7, lsl #8
+ str r6, [r0], #4 @ store result
+
+ bne 1b
+
+ ldr r4, [sp, #28] @ 4-in-parallel loop counter
+ subs r12, r12, #1
+
+ add r2, r2, r3 @ move to next input/output lines
+ add r0, r0, r1
+
+ bne 1b
+
+ pop {r4 - r9, pc}
+endfunc
+
+@ void put_vp8_bilin_v(uint8_t *dst, int dststride, uint8_t *src,
+@ int srcstride, int w, int h, int my)
+function ff_put_vp8_bilin_v_armv6, export=1
+ push {r4 - r11, lr}
+
+ ldr r11,[sp, #44] @ vp8_filter index
+ ldr r4, [sp, #36] @ width
+ mov r5, r11, lsl #16 @ mx << 16
+ ldr r12,[sp, #40] @ height = outer-loop counter
+ sub r1, r1, r4
+ sub r5, r5, r11 @ (mx << 16) | (-mx)
+ asr r4, #2
+ add r5, r5, #8 @ (8 - mx) | (mx << 16) = filter coefficients
+ str r4, [sp, #36] @ "4-in-parallel" loop counter
+1:
+ ldrb r10,[r2, r3] @ load the data
+ ldrb r6, [r2], #1
+ ldrb r11,[r2, r3]
+ ldrb r7, [r2], #1
+ ldrb lr, [r2, r3]
+ ldrb r8, [r2], #1
+ ldrb r9, [r2, r3]
+ pkhbt r6, r6, r10, lsl #16
+ ldrb r10,[r2], #1
+ pkhbt r7, r7, r11, lsl #16
+ pkhbt r8, r8, lr, lsl #16
+ pkhbt r9, r10, r9, lsl #16
+
+ smuad r6, r6, r5 @ apply the filter
+ smuad r7, r7, r5
+ smuad r8, r8, r5
+ smuad r9, r9, r5
+
+ subs r4, r4, #1 @ counter--
+
+ add r6, r6, #0x4 @ round_shift_and_clamp
+ add r7, r7, #0x4
+ add r8, r8, #0x4
+ add r9, r9, #0x4
+
+ asr r6, #3
+ asr r7, #3
+ pkhbt r6, r6, r8, lsl #13
+ pkhbt r7, r7, r9, lsl #13
+ orr r6, r6, r7, lsl #8
+ str r6, [r0], #4 @ store result
+
+ bne 1b
+
+ ldr r4, [sp, #36] @ 4-in-parallel loop counter
+ subs r12, r12, #1
+
+ add r2, r2, r3 @ move to next input/output lines
+ add r0, r0, r1
+ sub r2, r2, r4, lsl #2
+
+ bne 1b
+ pop {r4 - r11, pc}
+endfunc
diff --git a/libavcodec/arm/vp8dsp_init_arm.c b/libavcodec/arm/vp8dsp_init_arm.c
index 269c6e3f72..b56e6f42e0 100644
--- a/libavcodec/arm/vp8dsp_init_arm.c
+++ b/libavcodec/arm/vp8dsp_init_arm.c
@@ -1,31 +1,35 @@
/**
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdint.h>
#include "libavcodec/vp8dsp.h"
-void ff_vp8_luma_dc_wht_neon(DCTELEM block[4][4][16], DCTELEM dc[16]);
-void ff_vp8_luma_dc_wht_dc_neon(DCTELEM block[4][4][16], DCTELEM dc[16]);
+void ff_vp8_luma_dc_wht_dc_armv6(DCTELEM block[4][4][16], DCTELEM dc[16]);
-void ff_vp8_idct_add_neon(uint8_t *dst, DCTELEM block[16], int stride);
-void ff_vp8_idct_dc_add_neon(uint8_t *dst, DCTELEM block[16], int stride);
-void ff_vp8_idct_dc_add4y_neon(uint8_t *dst, DCTELEM block[4][16], int stride);
-void ff_vp8_idct_dc_add4uv_neon(uint8_t *dst, DCTELEM block[4][16], int stride);
+#define idct_funcs(opt) \
+void ff_vp8_luma_dc_wht_ ## opt(DCTELEM block[4][4][16], DCTELEM dc[16]); \
+void ff_vp8_idct_add_ ## opt(uint8_t *dst, DCTELEM block[16], int stride); \
+void ff_vp8_idct_dc_add_ ## opt(uint8_t *dst, DCTELEM block[16], int stride); \
+void ff_vp8_idct_dc_add4y_ ## opt(uint8_t *dst, DCTELEM block[4][16], int stride); \
+void ff_vp8_idct_dc_add4uv_ ## opt(uint8_t *dst, DCTELEM block[4][16], int stride)
+
+idct_funcs(neon);
+idct_funcs(armv6);
void ff_vp8_v_loop_filter16_neon(uint8_t *dst, int stride,
int flim_E, int flim_I, int hev_thresh);
@@ -47,29 +51,106 @@ void ff_vp8_h_loop_filter8uv_inner_neon(uint8_t *dstU, uint8_t *dstV,
int stride, int flim_E, int flim_I,
int hev_thresh);
-void ff_vp8_v_loop_filter16_simple_neon(uint8_t *dst, int stride, int flim);
-void ff_vp8_h_loop_filter16_simple_neon(uint8_t *dst, int stride, int flim);
+void ff_vp8_v_loop_filter_inner_armv6(uint8_t *dst, int stride,
+ int flim_E, int flim_I,
+ int hev_thresh, int count);
+void ff_vp8_h_loop_filter_inner_armv6(uint8_t *dst, int stride,
+ int flim_E, int flim_I,
+ int hev_thresh, int count);
+void ff_vp8_v_loop_filter_armv6(uint8_t *dst, int stride,
+ int flim_E, int flim_I,
+ int hev_thresh, int count);
+void ff_vp8_h_loop_filter_armv6(uint8_t *dst, int stride,
+ int flim_E, int flim_I,
+ int hev_thresh, int count);
+static void ff_vp8_v_loop_filter16_armv6(uint8_t *dst, int stride,
+ int flim_E, int flim_I, int hev_thresh)
+{
+ ff_vp8_v_loop_filter_armv6(dst, stride, flim_E, flim_I, hev_thresh, 4);
+}
+
+static void ff_vp8_h_loop_filter16_armv6(uint8_t *dst, int stride,
+ int flim_E, int flim_I, int hev_thresh)
+{
+ ff_vp8_h_loop_filter_armv6(dst, stride, flim_E, flim_I, hev_thresh, 4);
+}
-#define VP8_MC(n) \
- void ff_put_vp8_##n##_neon(uint8_t *dst, int dststride, \
- uint8_t *src, int srcstride, \
- int h, int x, int y)
+static void ff_vp8_v_loop_filter8uv_armv6(uint8_t *dstU, uint8_t *dstV, int stride,
+ int flim_E, int flim_I, int hev_thresh)
+{
+ ff_vp8_v_loop_filter_armv6(dstU, stride, flim_E, flim_I, hev_thresh, 2);
+ ff_vp8_v_loop_filter_armv6(dstV, stride, flim_E, flim_I, hev_thresh, 2);
+}
+
+static void ff_vp8_h_loop_filter8uv_armv6(uint8_t *dstU, uint8_t *dstV, int stride,
+ int flim_E, int flim_I, int hev_thresh)
+{
+ ff_vp8_h_loop_filter_armv6(dstU, stride, flim_E, flim_I, hev_thresh, 2);
+ ff_vp8_h_loop_filter_armv6(dstV, stride, flim_E, flim_I, hev_thresh, 2);
+}
+
+static void ff_vp8_v_loop_filter16_inner_armv6(uint8_t *dst, int stride,
+ int flim_E, int flim_I, int hev_thresh)
+{
+ ff_vp8_v_loop_filter_inner_armv6(dst, stride, flim_E, flim_I, hev_thresh, 4);
+}
+
+static void ff_vp8_h_loop_filter16_inner_armv6(uint8_t *dst, int stride,
+ int flim_E, int flim_I, int hev_thresh)
+{
+ ff_vp8_h_loop_filter_inner_armv6(dst, stride, flim_E, flim_I, hev_thresh, 4);
+}
+
+static void ff_vp8_v_loop_filter8uv_inner_armv6(uint8_t *dstU, uint8_t *dstV,
+ int stride, int flim_E, int flim_I,
+ int hev_thresh)
+{
+ ff_vp8_v_loop_filter_inner_armv6(dstU, stride, flim_E, flim_I, hev_thresh, 2);
+ ff_vp8_v_loop_filter_inner_armv6(dstV, stride, flim_E, flim_I, hev_thresh, 2);
+}
+
+static void ff_vp8_h_loop_filter8uv_inner_armv6(uint8_t *dstU, uint8_t *dstV,
+ int stride, int flim_E, int flim_I,
+ int hev_thresh)
+{
+ ff_vp8_h_loop_filter_inner_armv6(dstU, stride, flim_E, flim_I, hev_thresh, 2);
+ ff_vp8_h_loop_filter_inner_armv6(dstV, stride, flim_E, flim_I, hev_thresh, 2);
+}
+
+#define simple_lf_funcs(opt) \
+void ff_vp8_v_loop_filter16_simple_ ## opt(uint8_t *dst, int stride, int flim); \
+void ff_vp8_h_loop_filter16_simple_ ## opt(uint8_t *dst, int stride, int flim)
+
+simple_lf_funcs(neon);
+simple_lf_funcs(armv6);
+
+#define VP8_MC_OPT(n, opt) \
+ void ff_put_vp8_##n##_##opt(uint8_t *dst, int dststride, \
+ uint8_t *src, int srcstride, \
+ int h, int x, int y)
+
+#define VP8_MC(n) \
+ VP8_MC_OPT(n, neon)
#define VP8_EPEL(w) \
- VP8_MC(pixels ## w); \
VP8_MC(epel ## w ## _h4); \
VP8_MC(epel ## w ## _h6); \
- VP8_MC(epel ## w ## _v4); \
VP8_MC(epel ## w ## _h4v4); \
VP8_MC(epel ## w ## _h6v4); \
+ VP8_MC(epel ## w ## _v4); \
VP8_MC(epel ## w ## _v6); \
VP8_MC(epel ## w ## _h4v6); \
VP8_MC(epel ## w ## _h6v6)
VP8_EPEL(16);
+VP8_MC(pixels16);
+VP8_MC_OPT(pixels16, armv6);
VP8_EPEL(8);
+VP8_MC(pixels8);
+VP8_MC_OPT(pixels8, armv6);
VP8_EPEL(4);
+VP8_MC_OPT(pixels4, armv6);
VP8_MC(bilin16_h);
VP8_MC(bilin16_v);
@@ -81,83 +162,148 @@ VP8_MC(bilin4_h);
VP8_MC(bilin4_v);
VP8_MC(bilin4_hv);
+#define VP8_V6_MC(n) \
+void ff_put_vp8_##n##_armv6(uint8_t *dst, int dststride, uint8_t *src, \
+ int srcstride, int w, int h, int mxy)
+
+VP8_V6_MC(epel_v6);
+VP8_V6_MC(epel_h6);
+VP8_V6_MC(epel_v4);
+VP8_V6_MC(epel_h4);
+VP8_V6_MC(bilin_v);
+VP8_V6_MC(bilin_h);
+
+#define VP8_EPEL_HV(SIZE, TAPNUMX, TAPNUMY, NAME, HNAME, VNAME, MAXHEIGHT) \
+static void ff_put_vp8_##NAME##SIZE##_##HNAME##VNAME##_armv6( \
+ uint8_t *dst, int dststride, uint8_t *src, \
+ int srcstride, int h, int mx, int my) \
+{ \
+ DECLARE_ALIGNED(4, uint8_t, tmp)[SIZE * (MAXHEIGHT + TAPNUMY - 1)]; \
+ uint8_t *tmpptr = tmp + SIZE * (TAPNUMY / 2 - 1); \
+ src -= srcstride * (TAPNUMY / 2 - 1); \
+ ff_put_vp8_ ## NAME ## _ ## HNAME ## _armv6(tmp, SIZE, src, srcstride, \
+ SIZE, h + TAPNUMY - 1, mx); \
+ ff_put_vp8_ ## NAME ## _ ## VNAME ## _armv6(dst, dststride, tmpptr, SIZE, \
+ SIZE, h, my); \
+}
+
+VP8_EPEL_HV(16, 6, 6, epel, h6, v6, 16);
+VP8_EPEL_HV(16, 2, 2, bilin, h, v, 16);
+VP8_EPEL_HV(8, 6, 6, epel, h6, v6, 16);
+VP8_EPEL_HV(8, 4, 6, epel, h4, v6, 16);
+VP8_EPEL_HV(8, 6, 4, epel, h6, v4, 16);
+VP8_EPEL_HV(8, 4, 4, epel, h4, v4, 16);
+VP8_EPEL_HV(8, 2, 2, bilin, h, v, 16);
+VP8_EPEL_HV(4, 6, 6, epel, h6, v6, 8);
+VP8_EPEL_HV(4, 4, 6, epel, h4, v6, 8);
+VP8_EPEL_HV(4, 6, 4, epel, h6, v4, 8);
+VP8_EPEL_HV(4, 4, 4, epel, h4, v4, 8);
+VP8_EPEL_HV(4, 2, 2, bilin, h, v, 8);
+
+extern void put_vp8_epel4_v6_c(uint8_t *dst, int d, uint8_t *src, int s, int h, int mx, int my);
+#undef printf
+#define VP8_EPEL_H_OR_V(SIZE, NAME, HV) \
+static void ff_put_vp8_##NAME##SIZE##_##HV##_armv6( \
+ uint8_t *dst, int dststride, uint8_t *src, \
+ int srcstride, int h, int mx, int my) \
+{ \
+ ff_put_vp8_## NAME ## _ ## HV ## _armv6(dst, dststride, src, srcstride, \
+ SIZE, h, mx | my); \
+}
+
+VP8_EPEL_H_OR_V(4, epel, h6);
+VP8_EPEL_H_OR_V(4, epel, h4);
+VP8_EPEL_H_OR_V(4, epel, v6);
+VP8_EPEL_H_OR_V(4, epel, v4);
+VP8_EPEL_H_OR_V(4, bilin, v);
+VP8_EPEL_H_OR_V(4, bilin, h);
+VP8_EPEL_H_OR_V(8, epel, h6);
+VP8_EPEL_H_OR_V(8, epel, h4);
+VP8_EPEL_H_OR_V(8, epel, v6);
+VP8_EPEL_H_OR_V(8, epel, v4);
+VP8_EPEL_H_OR_V(8, bilin, v);
+VP8_EPEL_H_OR_V(8, bilin, h);
+VP8_EPEL_H_OR_V(16, epel, h6);
+VP8_EPEL_H_OR_V(16, epel, v6);
+VP8_EPEL_H_OR_V(16, bilin, v);
+VP8_EPEL_H_OR_V(16, bilin, h);
+
av_cold void ff_vp8dsp_init_arm(VP8DSPContext *dsp)
{
+#define set_func_ptrs(opt) \
+ dsp->vp8_luma_dc_wht = ff_vp8_luma_dc_wht_##opt; \
+ dsp->vp8_luma_dc_wht_dc = ff_vp8_luma_dc_wht_dc_armv6; \
+ \
+ dsp->vp8_idct_add = ff_vp8_idct_add_##opt; \
+ dsp->vp8_idct_dc_add = ff_vp8_idct_dc_add_##opt; \
+ dsp->vp8_idct_dc_add4y = ff_vp8_idct_dc_add4y_##opt; \
+ dsp->vp8_idct_dc_add4uv = ff_vp8_idct_dc_add4uv_##opt; \
+ \
+ dsp->vp8_v_loop_filter16y = ff_vp8_v_loop_filter16_##opt; \
+ dsp->vp8_h_loop_filter16y = ff_vp8_h_loop_filter16_##opt; \
+ dsp->vp8_v_loop_filter8uv = ff_vp8_v_loop_filter8uv_##opt; \
+ dsp->vp8_h_loop_filter8uv = ff_vp8_h_loop_filter8uv_##opt; \
+ \
+ dsp->vp8_v_loop_filter16y_inner = ff_vp8_v_loop_filter16_inner_##opt; \
+ dsp->vp8_h_loop_filter16y_inner = ff_vp8_h_loop_filter16_inner_##opt; \
+ dsp->vp8_v_loop_filter8uv_inner = ff_vp8_v_loop_filter8uv_inner_##opt; \
+ dsp->vp8_h_loop_filter8uv_inner = ff_vp8_h_loop_filter8uv_inner_##opt; \
+ \
+ dsp->vp8_v_loop_filter_simple = ff_vp8_v_loop_filter16_simple_##opt; \
+ dsp->vp8_h_loop_filter_simple = ff_vp8_h_loop_filter16_simple_##opt; \
+ \
+ dsp->put_vp8_epel_pixels_tab[0][0][0] = ff_put_vp8_pixels16_##opt; \
+ dsp->put_vp8_epel_pixels_tab[0][0][2] = ff_put_vp8_epel16_h6_##opt; \
+ dsp->put_vp8_epel_pixels_tab[0][2][0] = ff_put_vp8_epel16_v6_##opt; \
+ dsp->put_vp8_epel_pixels_tab[0][2][2] = ff_put_vp8_epel16_h6v6_##opt; \
+ \
+ dsp->put_vp8_epel_pixels_tab[1][0][0] = ff_put_vp8_pixels8_##opt; \
+ dsp->put_vp8_epel_pixels_tab[1][0][1] = ff_put_vp8_epel8_h4_##opt; \
+ dsp->put_vp8_epel_pixels_tab[1][0][2] = ff_put_vp8_epel8_h6_##opt; \
+ dsp->put_vp8_epel_pixels_tab[1][1][0] = ff_put_vp8_epel8_v4_##opt; \
+ dsp->put_vp8_epel_pixels_tab[1][1][1] = ff_put_vp8_epel8_h4v4_##opt; \
+ dsp->put_vp8_epel_pixels_tab[1][1][2] = ff_put_vp8_epel8_h6v4_##opt; \
+ dsp->put_vp8_epel_pixels_tab[1][2][0] = ff_put_vp8_epel8_v6_##opt; \
+ dsp->put_vp8_epel_pixels_tab[1][2][1] = ff_put_vp8_epel8_h4v6_##opt; \
+ dsp->put_vp8_epel_pixels_tab[1][2][2] = ff_put_vp8_epel8_h6v6_##opt; \
+ \
+ dsp->put_vp8_epel_pixels_tab[2][0][0] = ff_put_vp8_pixels4_armv6; \
+ dsp->put_vp8_epel_pixels_tab[2][0][1] = ff_put_vp8_epel4_h4_##opt; \
+ dsp->put_vp8_epel_pixels_tab[2][0][2] = ff_put_vp8_epel4_h6_##opt; \
+ dsp->put_vp8_epel_pixels_tab[2][1][0] = ff_put_vp8_epel4_v4_##opt; \
+ dsp->put_vp8_epel_pixels_tab[2][1][1] = ff_put_vp8_epel4_h4v4_##opt; \
+ dsp->put_vp8_epel_pixels_tab[2][1][2] = ff_put_vp8_epel4_h6v4_##opt; \
+ dsp->put_vp8_epel_pixels_tab[2][2][0] = ff_put_vp8_epel4_v6_##opt; \
+ dsp->put_vp8_epel_pixels_tab[2][2][1] = ff_put_vp8_epel4_h4v6_##opt; \
+ dsp->put_vp8_epel_pixels_tab[2][2][2] = ff_put_vp8_epel4_h6v6_##opt; \
+ \
+ dsp->put_vp8_bilinear_pixels_tab[0][0][0] = ff_put_vp8_pixels16_##opt; \
+ dsp->put_vp8_bilinear_pixels_tab[0][0][2] = ff_put_vp8_bilin16_h_##opt; \
+ dsp->put_vp8_bilinear_pixels_tab[0][2][0] = ff_put_vp8_bilin16_v_##opt; \
+ dsp->put_vp8_bilinear_pixels_tab[0][2][2] = ff_put_vp8_bilin16_hv_##opt; \
+ \
+ dsp->put_vp8_bilinear_pixels_tab[1][0][0] = ff_put_vp8_pixels8_##opt; \
+ dsp->put_vp8_bilinear_pixels_tab[1][0][1] = ff_put_vp8_bilin8_h_##opt; \
+ dsp->put_vp8_bilinear_pixels_tab[1][0][2] = ff_put_vp8_bilin8_h_##opt; \
+ dsp->put_vp8_bilinear_pixels_tab[1][1][0] = ff_put_vp8_bilin8_v_##opt; \
+ dsp->put_vp8_bilinear_pixels_tab[1][1][1] = ff_put_vp8_bilin8_hv_##opt; \
+ dsp->put_vp8_bilinear_pixels_tab[1][1][2] = ff_put_vp8_bilin8_hv_##opt; \
+ dsp->put_vp8_bilinear_pixels_tab[1][2][0] = ff_put_vp8_bilin8_v_##opt; \
+ dsp->put_vp8_bilinear_pixels_tab[1][2][1] = ff_put_vp8_bilin8_hv_##opt; \
+ dsp->put_vp8_bilinear_pixels_tab[1][2][2] = ff_put_vp8_bilin8_hv_##opt; \
+ \
+ dsp->put_vp8_bilinear_pixels_tab[2][0][0] = ff_put_vp8_pixels4_armv6; \
+ dsp->put_vp8_bilinear_pixels_tab[2][0][1] = ff_put_vp8_bilin4_h_##opt; \
+ dsp->put_vp8_bilinear_pixels_tab[2][0][2] = ff_put_vp8_bilin4_h_##opt; \
+ dsp->put_vp8_bilinear_pixels_tab[2][1][0] = ff_put_vp8_bilin4_v_##opt; \
+ dsp->put_vp8_bilinear_pixels_tab[2][1][1] = ff_put_vp8_bilin4_hv_##opt; \
+ dsp->put_vp8_bilinear_pixels_tab[2][1][2] = ff_put_vp8_bilin4_hv_##opt; \
+ dsp->put_vp8_bilinear_pixels_tab[2][2][0] = ff_put_vp8_bilin4_v_##opt; \
+ dsp->put_vp8_bilinear_pixels_tab[2][2][1] = ff_put_vp8_bilin4_hv_##opt; \
+ dsp->put_vp8_bilinear_pixels_tab[2][2][2] = ff_put_vp8_bilin4_hv_##opt
if (HAVE_NEON) {
- dsp->vp8_luma_dc_wht = ff_vp8_luma_dc_wht_neon;
- dsp->vp8_luma_dc_wht_dc = ff_vp8_luma_dc_wht_dc_neon;
-
- dsp->vp8_idct_add = ff_vp8_idct_add_neon;
- dsp->vp8_idct_dc_add = ff_vp8_idct_dc_add_neon;
- dsp->vp8_idct_dc_add4y = ff_vp8_idct_dc_add4y_neon;
- dsp->vp8_idct_dc_add4uv = ff_vp8_idct_dc_add4uv_neon;
-
- dsp->vp8_v_loop_filter16y = ff_vp8_v_loop_filter16_neon;
- dsp->vp8_h_loop_filter16y = ff_vp8_h_loop_filter16_neon;
- dsp->vp8_v_loop_filter8uv = ff_vp8_v_loop_filter8uv_neon;
- dsp->vp8_h_loop_filter8uv = ff_vp8_h_loop_filter8uv_neon;
-
- dsp->vp8_v_loop_filter16y_inner = ff_vp8_v_loop_filter16_inner_neon;
- dsp->vp8_h_loop_filter16y_inner = ff_vp8_h_loop_filter16_inner_neon;
- dsp->vp8_v_loop_filter8uv_inner = ff_vp8_v_loop_filter8uv_inner_neon;
- dsp->vp8_h_loop_filter8uv_inner = ff_vp8_h_loop_filter8uv_inner_neon;
-
- dsp->vp8_v_loop_filter_simple = ff_vp8_v_loop_filter16_simple_neon;
- dsp->vp8_h_loop_filter_simple = ff_vp8_h_loop_filter16_simple_neon;
-
- dsp->put_vp8_epel_pixels_tab[0][0][0] = ff_put_vp8_pixels16_neon;
- dsp->put_vp8_epel_pixels_tab[0][0][2] = ff_put_vp8_epel16_h6_neon;
- dsp->put_vp8_epel_pixels_tab[0][2][0] = ff_put_vp8_epel16_v6_neon;
- dsp->put_vp8_epel_pixels_tab[0][2][2] = ff_put_vp8_epel16_h6v6_neon;
-
- dsp->put_vp8_epel_pixels_tab[1][0][0] = ff_put_vp8_pixels8_neon;
- dsp->put_vp8_epel_pixels_tab[1][0][1] = ff_put_vp8_epel8_h4_neon;
- dsp->put_vp8_epel_pixels_tab[1][0][2] = ff_put_vp8_epel8_h6_neon;
- dsp->put_vp8_epel_pixels_tab[1][1][0] = ff_put_vp8_epel8_v4_neon;
- dsp->put_vp8_epel_pixels_tab[1][1][1] = ff_put_vp8_epel8_h4v4_neon;
- dsp->put_vp8_epel_pixels_tab[1][1][2] = ff_put_vp8_epel8_h6v4_neon;
- dsp->put_vp8_epel_pixels_tab[1][2][0] = ff_put_vp8_epel8_v6_neon;
- dsp->put_vp8_epel_pixels_tab[1][2][1] = ff_put_vp8_epel8_h4v6_neon;
- dsp->put_vp8_epel_pixels_tab[1][2][2] = ff_put_vp8_epel8_h6v6_neon;
-
- dsp->put_vp8_epel_pixels_tab[2][0][0] = ff_put_vp8_pixels4_neon;
- dsp->put_vp8_epel_pixels_tab[2][0][1] = ff_put_vp8_epel4_h4_neon;
- dsp->put_vp8_epel_pixels_tab[2][0][2] = ff_put_vp8_epel4_h6_neon;
- dsp->put_vp8_epel_pixels_tab[2][1][0] = ff_put_vp8_epel4_v4_neon;
- dsp->put_vp8_epel_pixels_tab[2][1][1] = ff_put_vp8_epel4_h4v4_neon;
- dsp->put_vp8_epel_pixels_tab[2][1][2] = ff_put_vp8_epel4_h6v4_neon;
- dsp->put_vp8_epel_pixels_tab[2][2][0] = ff_put_vp8_epel4_v6_neon;
- dsp->put_vp8_epel_pixels_tab[2][2][1] = ff_put_vp8_epel4_h4v6_neon;
- dsp->put_vp8_epel_pixels_tab[2][2][2] = ff_put_vp8_epel4_h6v6_neon;
-
- dsp->put_vp8_bilinear_pixels_tab[0][0][0] = ff_put_vp8_pixels16_neon;
- dsp->put_vp8_bilinear_pixels_tab[0][0][1] = ff_put_vp8_bilin16_h_neon;
- dsp->put_vp8_bilinear_pixels_tab[0][0][2] = ff_put_vp8_bilin16_h_neon;
- dsp->put_vp8_bilinear_pixels_tab[0][1][0] = ff_put_vp8_bilin16_v_neon;
- dsp->put_vp8_bilinear_pixels_tab[0][1][1] = ff_put_vp8_bilin16_hv_neon;
- dsp->put_vp8_bilinear_pixels_tab[0][1][2] = ff_put_vp8_bilin16_hv_neon;
- dsp->put_vp8_bilinear_pixels_tab[0][2][0] = ff_put_vp8_bilin16_v_neon;
- dsp->put_vp8_bilinear_pixels_tab[0][2][1] = ff_put_vp8_bilin16_hv_neon;
- dsp->put_vp8_bilinear_pixels_tab[0][2][2] = ff_put_vp8_bilin16_hv_neon;
-
- dsp->put_vp8_bilinear_pixels_tab[1][0][0] = ff_put_vp8_pixels8_neon;
- dsp->put_vp8_bilinear_pixels_tab[1][0][1] = ff_put_vp8_bilin8_h_neon;
- dsp->put_vp8_bilinear_pixels_tab[1][0][2] = ff_put_vp8_bilin8_h_neon;
- dsp->put_vp8_bilinear_pixels_tab[1][1][0] = ff_put_vp8_bilin8_v_neon;
- dsp->put_vp8_bilinear_pixels_tab[1][1][1] = ff_put_vp8_bilin8_hv_neon;
- dsp->put_vp8_bilinear_pixels_tab[1][1][2] = ff_put_vp8_bilin8_hv_neon;
- dsp->put_vp8_bilinear_pixels_tab[1][2][0] = ff_put_vp8_bilin8_v_neon;
- dsp->put_vp8_bilinear_pixels_tab[1][2][1] = ff_put_vp8_bilin8_hv_neon;
- dsp->put_vp8_bilinear_pixels_tab[1][2][2] = ff_put_vp8_bilin8_hv_neon;
-
- dsp->put_vp8_bilinear_pixels_tab[2][0][0] = ff_put_vp8_pixels4_neon;
- dsp->put_vp8_bilinear_pixels_tab[2][0][1] = ff_put_vp8_bilin4_h_neon;
- dsp->put_vp8_bilinear_pixels_tab[2][0][2] = ff_put_vp8_bilin4_h_neon;
- dsp->put_vp8_bilinear_pixels_tab[2][1][0] = ff_put_vp8_bilin4_v_neon;
- dsp->put_vp8_bilinear_pixels_tab[2][1][1] = ff_put_vp8_bilin4_hv_neon;
- dsp->put_vp8_bilinear_pixels_tab[2][1][2] = ff_put_vp8_bilin4_hv_neon;
- dsp->put_vp8_bilinear_pixels_tab[2][2][0] = ff_put_vp8_bilin4_v_neon;
- dsp->put_vp8_bilinear_pixels_tab[2][2][1] = ff_put_vp8_bilin4_hv_neon;
- dsp->put_vp8_bilinear_pixels_tab[2][2][2] = ff_put_vp8_bilin4_hv_neon;
+ set_func_ptrs(neon);
+ } else if (HAVE_ARMV6) {
+ set_func_ptrs(armv6);
}
}
diff --git a/libavcodec/arm/vp8dsp_neon.S b/libavcodec/arm/vp8dsp_neon.S
index 1b9f24eef2..1fb3753aab 100644
--- a/libavcodec/arm/vp8dsp_neon.S
+++ b/libavcodec/arm/vp8dsp_neon.S
@@ -4,20 +4,20 @@
* Copyright (c) 2010 Rob Clark <rob@ti.com>
* Copyright (c) 2011 Mans Rullgard <mans@mansr.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -76,18 +76,6 @@ function ff_vp8_luma_dc_wht_neon, export=1
bx lr
endfunc
-function ff_vp8_luma_dc_wht_dc_neon, export=1
- ldrsh r2, [r1]
- mov r3, #0
- add r2, r2, #3
- strh r3, [r1]
- asr r2, r2, #3
- .rept 16
- strh r2, [r0], #32
- .endr
- bx lr
-endfunc
-
function ff_vp8_idct_add_neon, export=1
vld1.16 {q0-q1}, [r1,:128]
movw r3, #20091
@@ -741,23 +729,6 @@ function ff_put_vp8_pixels8_neon, export=1
bx lr
endfunc
-function ff_put_vp8_pixels4_neon, export=1
- ldr r12, [sp, #0] @ h
- push {r4-r6,lr}
-1:
- subs r12, r12, #4
- ldr_post r4, r2, r3
- ldr_post r5, r2, r3
- ldr_post r6, r2, r3
- ldr_post lr, r2, r3
- str_post r4, r0, r1
- str_post r5, r0, r1
- str_post r6, r0, r1
- str_post lr, r0, r1
- bgt 1b
- pop {r4-r6,pc}
-endfunc
-
/* 4/6-tap 8th-pel MC */
.macro vp8_epel8_h6 d, a, b
diff --git a/libavcodec/ass.c b/libavcodec/ass.c
index 327a77bb45..cb0babf2c8 100644
--- a/libavcodec/ass.c
+++ b/libavcodec/ass.c
@@ -2,20 +2,20 @@
* SSA/ASS common funtions
* Copyright (c) 2010 Aurelien Jacobs <aurel@gnuage.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -23,26 +23,11 @@
#include "ass.h"
#include "libavutil/avstring.h"
-/**
- * Generate a suitable AVCodecContext.subtitle_header for SUBTITLE_ASS.
- *
- * @param avctx pointer to the AVCodecContext
- * @param font name of the default font face to use
- * @param font_size default font size to use
- * @param color default text color to use (ABGR)
- * @param back_color default background color to use (ABGR)
- * @param bold 1 for bold text, 0 for normal text
- * @param italic 1 for italic text, 0 for normal text
- * @param underline 1 for underline text, 0 for normal text
- * @param alignment position of the text (left, center, top...), defined after
- * the layout of the numpad (1-3 sub, 4-6 mid, 7-9 top)
- * @return >= 0 on success otherwise an error code <0
- */
-static int ff_ass_subtitle_header(AVCodecContext *avctx,
- const char *font, int font_size,
- int color, int back_color,
- int bold, int italic, int underline,
- int alignment)
+int ff_ass_subtitle_header(AVCodecContext *avctx,
+ const char *font, int font_size,
+ int color, int back_color,
+ int bold, int italic, int underline,
+ int alignment)
{
char header[512];
@@ -78,11 +63,6 @@ int ff_ass_subtitle_header_default(AVCodecContext *avctx)
ASS_DEFAULT_ALIGNMENT);
}
-void ff_ass_init(AVSubtitle *sub)
-{
- memset(sub, 0, sizeof(*sub));
-}
-
static int ts_to_string(char *str, int strlen, int ts)
{
int h, m, s;
diff --git a/libavcodec/ass.h b/libavcodec/ass.h
index 594b5f3ac6..efff44d6ed 100644
--- a/libavcodec/ass.h
+++ b/libavcodec/ass.h
@@ -2,20 +2,20 @@
* SSA/ASS common funtions
* Copyright (c) 2010 Aurelien Jacobs <aurel@gnuage.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -39,20 +39,34 @@
/** @} */
/**
- * Generate a suitable AVCodecContext.subtitle_header for SUBTITLE_ASS
- * with default style.
+ * Generate a suitable AVCodecContext.subtitle_header for SUBTITLE_ASS.
*
* @param avctx pointer to the AVCodecContext
+ * @param font name of the default font face to use
+ * @param font_size default font size to use
+ * @param color default text color to use (ABGR)
+ * @param back_color default background color to use (ABGR)
+ * @param bold 1 for bold text, 0 for normal text
+ * @param italic 1 for italic text, 0 for normal text
+ * @param underline 1 for underline text, 0 for normal text
+ * @param alignment position of the text (left, center, top...), defined after
+ * the layout of the numpad (1-3 sub, 4-6 mid, 7-9 top)
* @return >= 0 on success otherwise an error code <0
*/
-int ff_ass_subtitle_header_default(AVCodecContext *avctx);
+int ff_ass_subtitle_header(AVCodecContext *avctx,
+ const char *font, int font_size,
+ int color, int back_color,
+ int bold, int italic, int underline,
+ int alignment);
/**
- * Initialize an AVSubtitle structure for use with ff_ass_add_rect().
+ * Generate a suitable AVCodecContext.subtitle_header for SUBTITLE_ASS
+ * with default style.
*
- * @param sub pointer to the AVSubtitle
+ * @param avctx pointer to the AVCodecContext
+ * @return >= 0 on success otherwise an error code <0
*/
-void ff_ass_init(AVSubtitle *sub);
+int ff_ass_subtitle_header_default(AVCodecContext *avctx);
/**
* Add an ASS dialog line to an AVSubtitle as a new AVSubtitleRect.
diff --git a/libavcodec/ass_split.c b/libavcodec/ass_split.c
new file mode 100644
index 0000000000..2a3b76445e
--- /dev/null
+++ b/libavcodec/ass_split.c
@@ -0,0 +1,468 @@
+/*
+ * SSA/ASS spliting functions
+ * Copyright (c) 2010 Aurelien Jacobs <aurel@gnuage.org>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "avcodec.h"
+#include "ass_split.h"
+
+typedef enum {
+ ASS_STR,
+ ASS_INT,
+ ASS_FLT,
+ ASS_COLOR,
+ ASS_TIMESTAMP,
+ ASS_ALGN,
+} ASSFieldType;
+
+typedef struct {
+ const char *name;
+ int type;
+ int offset;
+} ASSFields;
+
+typedef struct {
+ const char *section;
+ const char *format_header;
+ const char *fields_header;
+ int size;
+ int offset;
+ int offset_count;
+ ASSFields fields[10];
+} ASSSection;
+
+static const ASSSection ass_sections[] = {
+ { .section = "Script Info",
+ .offset = offsetof(ASS, script_info),
+ .fields = {{"ScriptType", ASS_STR, offsetof(ASSScriptInfo, script_type)},
+ {"Collisions", ASS_STR, offsetof(ASSScriptInfo, collisions) },
+ {"PlayResX", ASS_INT, offsetof(ASSScriptInfo, play_res_x) },
+ {"PlayResY", ASS_INT, offsetof(ASSScriptInfo, play_res_y) },
+ {"Timer", ASS_FLT, offsetof(ASSScriptInfo, timer) },
+ {0},
+ }
+ },
+ { .section = "V4+ Styles",
+ .format_header = "Format",
+ .fields_header = "Style",
+ .size = sizeof(ASSStyle),
+ .offset = offsetof(ASS, styles),
+ .offset_count = offsetof(ASS, styles_count),
+ .fields = {{"Name", ASS_STR, offsetof(ASSStyle, name) },
+ {"Fontname", ASS_STR, offsetof(ASSStyle, font_name) },
+ {"Fontsize", ASS_INT, offsetof(ASSStyle, font_size) },
+ {"PrimaryColour",ASS_COLOR,offsetof(ASSStyle, primary_color)},
+ {"BackColour", ASS_COLOR,offsetof(ASSStyle, back_color) },
+ {"Bold", ASS_INT, offsetof(ASSStyle, bold) },
+ {"Italic", ASS_INT, offsetof(ASSStyle, italic) },
+ {"Underline", ASS_INT, offsetof(ASSStyle, underline) },
+ {"Alignment", ASS_INT, offsetof(ASSStyle, alignment) },
+ {0},
+ }
+ },
+ { .section = "V4 Styles",
+ .format_header = "Format",
+ .fields_header = "Style",
+ .size = sizeof(ASSStyle),
+ .offset = offsetof(ASS, styles),
+ .offset_count = offsetof(ASS, styles_count),
+ .fields = {{"Name", ASS_STR, offsetof(ASSStyle, name) },
+ {"Fontname", ASS_STR, offsetof(ASSStyle, font_name) },
+ {"Fontsize", ASS_INT, offsetof(ASSStyle, font_size) },
+ {"PrimaryColour",ASS_COLOR,offsetof(ASSStyle, primary_color)},
+ {"BackColour", ASS_COLOR,offsetof(ASSStyle, back_color) },
+ {"Bold", ASS_INT, offsetof(ASSStyle, bold) },
+ {"Italic", ASS_INT, offsetof(ASSStyle, italic) },
+ {"Alignment", ASS_ALGN, offsetof(ASSStyle, alignment) },
+ {0},
+ }
+ },
+ { .section = "Events",
+ .format_header = "Format",
+ .fields_header = "Dialogue",
+ .size = sizeof(ASSDialog),
+ .offset = offsetof(ASS, dialogs),
+ .offset_count = offsetof(ASS, dialogs_count),
+ .fields = {{"Layer", ASS_INT, offsetof(ASSDialog, layer) },
+ {"Start", ASS_TIMESTAMP, offsetof(ASSDialog, start) },
+ {"End", ASS_TIMESTAMP, offsetof(ASSDialog, end) },
+ {"Style", ASS_STR, offsetof(ASSDialog, style) },
+ {"Text", ASS_STR, offsetof(ASSDialog, text) },
+ {0},
+ }
+ },
+};
+
+
+typedef int (*ASSConvertFunc)(void *dest, const char *buf, int len);
+
+static int convert_str(void *dest, const char *buf, int len)
+{
+ char *str = av_malloc(len + 1);
+ if (str) {
+ memcpy(str, buf, len);
+ str[len] = 0;
+ if (*(void **)dest)
+ av_free(*(void **)dest);
+ *(char **)dest = str;
+ }
+ return !str;
+}
+static int convert_int(void *dest, const char *buf, int len)
+{
+ return sscanf(buf, "%d", (int *)dest) == 1;
+}
+static int convert_flt(void *dest, const char *buf, int len)
+{
+ return sscanf(buf, "%f", (float *)dest) == 1;
+}
+static int convert_color(void *dest, const char *buf, int len)
+{
+ return sscanf(buf, "&H%8x", (int *)dest) == 1 ||
+ sscanf(buf, "%d", (int *)dest) == 1;
+}
+static int convert_timestamp(void *dest, const char *buf, int len)
+{
+ int c, h, m, s, cs;
+ if ((c = sscanf(buf, "%d:%02d:%02d.%02d", &h, &m, &s, &cs)) == 4)
+ *(int *)dest = 360000*h + 6000*m + 100*s + cs;
+ return c == 4;
+}
+static int convert_alignment(void *dest, const char *buf, int len)
+{
+ int a;
+ if (sscanf(buf, "%d", &a) == 1) {
+ /* convert V4 Style alignment to V4+ Style */
+ *(int *)dest = a + ((a&4) >> 1) - 5*!!(a&8);
+ return 1;
+ }
+ return 0;
+}
+
+static const ASSConvertFunc convert_func[] = {
+ [ASS_STR] = convert_str,
+ [ASS_INT] = convert_int,
+ [ASS_FLT] = convert_flt,
+ [ASS_COLOR] = convert_color,
+ [ASS_TIMESTAMP] = convert_timestamp,
+ [ASS_ALGN] = convert_alignment,
+};
+
+
+struct ASSSplitContext {
+ ASS ass;
+ int current_section;
+ int field_number[FF_ARRAY_ELEMS(ass_sections)];
+ int *field_order[FF_ARRAY_ELEMS(ass_sections)];
+};
+
+
+static uint8_t *realloc_section_array(ASSSplitContext *ctx)
+{
+ const ASSSection *section = &ass_sections[ctx->current_section];
+ int *count = (int *)((uint8_t *)&ctx->ass + section->offset_count);
+ void **section_ptr = (void **)((uint8_t *)&ctx->ass + section->offset);
+ uint8_t *tmp = av_realloc(*section_ptr, (*count+1)*section->size);
+ if (!tmp)
+ return NULL;
+ *section_ptr = tmp;
+ tmp += *count * section->size;
+ memset(tmp, 0, section->size);
+ (*count)++;
+ return tmp;
+}
+
+static inline int is_eol(char buf)
+{
+ return buf == '\r' || buf == '\n' || buf == 0;
+}
+
+static inline const char *skip_space(const char *buf)
+{
+ while (*buf == ' ')
+ buf++;
+ return buf;
+}
+
+static const char *ass_split_section(ASSSplitContext *ctx, const char *buf)
+{
+ const ASSSection *section = &ass_sections[ctx->current_section];
+ int *number = &ctx->field_number[ctx->current_section];
+ int *order = ctx->field_order[ctx->current_section];
+ int *tmp, i, len;
+
+ while (buf && *buf) {
+ if (buf[0] == '[') {
+ ctx->current_section = -1;
+ break;
+ }
+ if (buf[0] == ';' || (buf[0] == '!' && buf[1] == ':')) {
+ /* skip comments */
+ } else if (section->format_header && !order) {
+ len = strlen(section->format_header);
+ if (strncmp(buf, section->format_header, len) || buf[len] != ':')
+ return NULL;
+ buf += len + 1;
+ while (!is_eol(*buf)) {
+ buf = skip_space(buf);
+ len = strcspn(buf, ", \r\n");
+ if (!(tmp = av_realloc(order, (*number + 1) * sizeof(*order))))
+ return NULL;
+ order = tmp;
+ order[*number] = -1;
+ for (i=0; section->fields[i].name; i++)
+ if (!strncmp(buf, section->fields[i].name, len)) {
+ order[*number] = i;
+ break;
+ }
+ (*number)++;
+ buf = skip_space(buf + len + 1);
+ }
+ ctx->field_order[ctx->current_section] = order;
+ } else if (section->fields_header) {
+ len = strlen(section->fields_header);
+ if (!strncmp(buf, section->fields_header, len) && buf[len] == ':') {
+ uint8_t *ptr, *struct_ptr = realloc_section_array(ctx);
+ if (!struct_ptr) return NULL;
+ buf += len + 1;
+ for (i=0; !is_eol(*buf) && i < *number; i++) {
+ int last = i == *number - 1;
+ buf = skip_space(buf);
+ len = strcspn(buf, last ? "\r\n" : ",\r\n");
+ if (order[i] >= 0) {
+ ASSFieldType type = section->fields[order[i]].type;
+ ptr = struct_ptr + section->fields[order[i]].offset;
+ convert_func[type](ptr, buf, len);
+ }
+ buf = skip_space(buf + len + !last);
+ }
+ }
+ } else {
+ len = strcspn(buf, ":\r\n");
+ if (buf[len] == ':') {
+ for (i=0; section->fields[i].name; i++)
+ if (!strncmp(buf, section->fields[i].name, len)) {
+ ASSFieldType type = section->fields[i].type;
+ uint8_t *ptr = (uint8_t *)&ctx->ass + section->offset;
+ ptr += section->fields[i].offset;
+ buf = skip_space(buf + len + 1);
+ convert_func[type](ptr, buf, strcspn(buf, "\r\n"));
+ break;
+ }
+ }
+ }
+ buf += strcspn(buf, "\n") + 1;
+ }
+ return buf;
+}
+
+static int ass_split(ASSSplitContext *ctx, const char *buf)
+{
+ char c, section[16];
+ int i;
+
+ if (ctx->current_section >= 0)
+ buf = ass_split_section(ctx, buf);
+
+ while (buf && *buf) {
+ if (sscanf(buf, "[%15[0-9A-Za-z+ ]]%c", section, &c) == 2) {
+ buf += strcspn(buf, "\n") + 1;
+ for (i=0; i<FF_ARRAY_ELEMS(ass_sections); i++)
+ if (!strcmp(section, ass_sections[i].section)) {
+ ctx->current_section = i;
+ buf = ass_split_section(ctx, buf);
+ }
+ } else
+ buf += strcspn(buf, "\n") + 1;
+ }
+ return buf ? 0 : AVERROR_INVALIDDATA;
+}
+
+ASSSplitContext *ff_ass_split(const char *buf)
+{
+ ASSSplitContext *ctx = av_mallocz(sizeof(*ctx));
+ ctx->current_section = -1;
+ if (ass_split(ctx, buf) < 0) {
+ ff_ass_split_free(ctx);
+ return NULL;
+ }
+ return ctx;
+}
+
+static void free_section(ASSSplitContext *ctx, const ASSSection *section)
+{
+ uint8_t *ptr = (uint8_t *)&ctx->ass + section->offset;
+ int i, j, *count, c = 1;
+
+ if (section->format_header) {
+ ptr = *(void **)ptr;
+ count = (int *)((uint8_t *)&ctx->ass + section->offset_count);
+ } else
+ count = &c;
+
+ if (ptr)
+ for (i=0; i<*count; i++, ptr += section->size)
+ for (j=0; section->fields[j].name; j++) {
+ const ASSFields *field = &section->fields[j];
+ if (field->type == ASS_STR)
+ av_freep(ptr + field->offset);
+ }
+ *count = 0;
+
+ if (section->format_header)
+ av_freep((uint8_t *)&ctx->ass + section->offset);
+}
+
+ASSDialog *ff_ass_split_dialog(ASSSplitContext *ctx, const char *buf,
+ int cache, int *number)
+{
+ ASSDialog *dialog = NULL;
+ int i, count;
+ if (!cache)
+ for (i=0; i<FF_ARRAY_ELEMS(ass_sections); i++)
+ if (!strcmp(ass_sections[i].section, "Events")) {
+ free_section(ctx, &ass_sections[i]);
+ break;
+ }
+ count = ctx->ass.dialogs_count;
+ if (ass_split(ctx, buf) == 0)
+ dialog = ctx->ass.dialogs + count;
+ if (number)
+ *number = ctx->ass.dialogs_count - count;
+ return dialog;
+}
+
+void ff_ass_split_free(ASSSplitContext *ctx)
+{
+ if (ctx) {
+ int i;
+ for (i=0; i<FF_ARRAY_ELEMS(ass_sections); i++)
+ free_section(ctx, &ass_sections[i]);
+ av_free(ctx);
+ }
+}
+
+
+int ff_ass_split_override_codes(const ASSCodesCallbacks *callbacks, void *priv,
+ const char *buf)
+{
+ const char *text = NULL;
+ char new_line[2];
+ int text_len = 0;
+
+ while (*buf) {
+ if (text && callbacks->text &&
+ (sscanf(buf, "\\%1[nN]", new_line) == 1 ||
+ !strncmp(buf, "{\\", 2))) {
+ callbacks->text(priv, text, text_len);
+ text = NULL;
+ }
+ if (sscanf(buf, "\\%1[nN]", new_line) == 1) {
+ if (callbacks->new_line)
+ callbacks->new_line(priv, new_line[0] == 'N');
+ buf += 2;
+ } else if (!strncmp(buf, "{\\", 2)) {
+ buf++;
+ while (*buf == '\\') {
+ char style[2], c[2], sep[2], c_num[2] = "0", tmp[128] = {0};
+ unsigned int color = 0xFFFFFFFF;
+ int len, size = -1, an = -1, alpha = -1;
+ int x1, y1, x2, y2, t1 = -1, t2 = -1;
+ if (sscanf(buf, "\\%1[bisu]%1[01\\}]%n", style, c, &len) > 1) {
+ int close = c[0] == '0' ? 1 : c[0] == '1' ? 0 : -1;
+ len += close != -1;
+ if (callbacks->style)
+ callbacks->style(priv, style[0], close);
+ } else if (sscanf(buf, "\\c%1[\\}]%n", sep, &len) > 0 ||
+ sscanf(buf, "\\c&H%X&%1[\\}]%n", &color, sep, &len) > 1 ||
+ sscanf(buf, "\\%1[1234]c%1[\\}]%n", c_num, sep, &len) > 1 ||
+ sscanf(buf, "\\%1[1234]c&H%X&%1[\\}]%n", c_num, &color, sep, &len) > 2) {
+ if (callbacks->color)
+ callbacks->color(priv, color, c_num[0] - '0');
+ } else if (sscanf(buf, "\\alpha%1[\\}]%n", sep, &len) > 0 ||
+ sscanf(buf, "\\alpha&H%2X&%1[\\}]%n", &alpha, sep, &len) > 1 ||
+ sscanf(buf, "\\%1[1234]a%1[\\}]%n", c_num, sep, &len) > 1 ||
+ sscanf(buf, "\\%1[1234]a&H%2X&%1[\\}]%n", c_num, &alpha, sep, &len) > 2) {
+ if (callbacks->alpha)
+ callbacks->alpha(priv, alpha, c_num[0] - '0');
+ } else if (sscanf(buf, "\\fn%1[\\}]%n", sep, &len) > 0 ||
+ sscanf(buf, "\\fn%127[^\\}]%1[\\}]%n", tmp, sep, &len) > 1) {
+ if (callbacks->font_name)
+ callbacks->font_name(priv, tmp[0] ? tmp : NULL);
+ } else if (sscanf(buf, "\\fs%1[\\}]%n", sep, &len) > 0 ||
+ sscanf(buf, "\\fs%u%1[\\}]%n", &size, sep, &len) > 1) {
+ if (callbacks->font_size)
+ callbacks->font_size(priv, size);
+ } else if (sscanf(buf, "\\a%1[\\}]%n", sep, &len) > 0 ||
+ sscanf(buf, "\\a%2u%1[\\}]%n", &an, sep, &len) > 1 ||
+ sscanf(buf, "\\an%1[\\}]%n", sep, &len) > 0 ||
+ sscanf(buf, "\\an%1u%1[\\}]%n", &an, sep, &len) > 1) {
+ if (an != -1 && buf[2] != 'n')
+ an = (an&3) + (an&4 ? 6 : an&8 ? 3 : 0);
+ if (callbacks->alignment)
+ callbacks->alignment(priv, an);
+ } else if (sscanf(buf, "\\r%1[\\}]%n", sep, &len) > 0 ||
+ sscanf(buf, "\\r%127[^\\}]%1[\\}]%n", tmp, sep, &len) > 1) {
+ if (callbacks->cancel_overrides)
+ callbacks->cancel_overrides(priv, tmp);
+ } else if (sscanf(buf, "\\move(%d,%d,%d,%d)%1[\\}]%n", &x1, &y1, &x2, &y2, sep, &len) > 4 ||
+ sscanf(buf, "\\move(%d,%d,%d,%d,%d,%d)%1[\\}]%n", &x1, &y1, &x2, &y2, &t1, &t2, sep, &len) > 6) {
+ if (callbacks->move)
+ callbacks->move(priv, x1, y1, x2, y2, t1, t2);
+ } else if (sscanf(buf, "\\pos(%d,%d)%1[\\}]%n", &x1, &y1, sep, &len) > 2) {
+ if (callbacks->move)
+ callbacks->move(priv, x1, y1, x1, y1, -1, -1);
+ } else if (sscanf(buf, "\\org(%d,%d)%1[\\}]%n", &x1, &y1, sep, &len) > 2) {
+ if (callbacks->origin)
+ callbacks->origin(priv, x1, y1);
+ } else {
+ len = strcspn(buf+1, "\\}") + 2; /* skip unknown code */
+ }
+ buf += len - 1;
+ }
+ if (*buf++ != '}')
+ return AVERROR_INVALIDDATA;
+ } else {
+ if (!text) {
+ text = buf;
+ text_len = 1;
+ } else
+ text_len++;
+ buf++;
+ }
+ }
+ if (text && callbacks->text)
+ callbacks->text(priv, text, text_len);
+ if (callbacks->end)
+ callbacks->end(priv);
+ return 0;
+}
+
+ASSStyle *ass_style_get(ASSSplitContext *ctx, const char *style)
+{
+ ASS *ass = &ctx->ass;
+ int i;
+
+ if (!style || !*style)
+ style = "Default";
+ for (i=0; i<ass->styles_count; i++)
+ if (!strcmp(ass->styles[i].name, style))
+ return ass->styles + i;
+ return NULL;
+}
diff --git a/libavcodec/ass_split.h b/libavcodec/ass_split.h
new file mode 100644
index 0000000000..2ce4eb5d9c
--- /dev/null
+++ b/libavcodec/ass_split.h
@@ -0,0 +1,172 @@
+/*
+ * SSA/ASS spliting functions
+ * Copyright (c) 2010 Aurelien Jacobs <aurel@gnuage.org>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_ASS_SPLIT_H
+#define AVCODEC_ASS_SPLIT_H
+
+/**
+ * fields extracted from the [Script Info] section
+ */
+typedef struct {
+ char *script_type; /**< SSA script format version (eg. v4.00) */
+ char *collisions; /**< how subtitles are moved to prevent collisions */
+ int play_res_x; /**< video width that ASS coords are referring to */
+ int play_res_y; /**< video height that ASS coords are referring to */
+ float timer; /**< time multiplier to apply to SSA clock (in %) */
+} ASSScriptInfo;
+
+/**
+ * fields extracted from the [V4(+) Styles] section
+ */
+typedef struct {
+ char *name; /**< name of the tyle (case sensitive) */
+ char *font_name; /**< font face (case sensitive) */
+ int font_size; /**< font height */
+ int primary_color; /**< color that a subtitle will normally appear in */
+ int back_color; /**< color of the subtitle outline or shadow */
+ int bold; /**< whether text is bold (1) or not (0) */
+ int italic; /**< whether text is italic (1) or not (0) */
+ int underline; /**< whether text is underlined (1) or not (0) */
+ int alignment; /**< position of the text (left, center, top...),
+ defined after the layout of the numpad
+ (1-3 sub, 4-6 mid, 7-9 top) */
+} ASSStyle;
+
+/**
+ * fields extracted from the [Events] section
+ */
+typedef struct {
+ int layer; /**< higher numbered layers are drawn over lower numbered */
+ int start; /**< start time of the dialog in centiseconds */
+ int end; /**< end time of the dialog in centiseconds */
+ char *style; /**< name of the ASSStyle to use with this dialog */
+ char *text; /**< actual text which will be displayed as a subtitle,
+ can include style override control codes (see
+ ff_ass_split_override_codes()) */
+} ASSDialog;
+
+/**
+ * structure containing the whole split ASS data
+ */
+typedef struct {
+ ASSScriptInfo script_info; /**< general information about the SSA script*/
+ ASSStyle *styles; /**< array of split out styles */
+ int styles_count; /**< number of ASSStyle in the styles array */
+ ASSDialog *dialogs; /**< array of split out dialogs */
+ int dialogs_count; /**< number of ASSDialog in the dialogs array*/
+} ASS;
+
+/**
+ * This struct can be casted to ASS to access to the split data.
+ */
+typedef struct ASSSplitContext ASSSplitContext;
+
+/**
+ * Split a full ASS file or a ASS header from a string buffer and store
+ * the split structure in a newly allocated context.
+ *
+ * @param buf String containing the ASS formated data.
+ * @return Newly allocated struct containing split data.
+ */
+ASSSplitContext *ff_ass_split(const char *buf);
+
+/**
+ * Split one or several ASS "Dialogue" lines from a string buffer and store
+ * them in a already initialized context.
+ *
+ * @param ctx Context previously initialized by ff_ass_split().
+ * @param buf String containing the ASS "Dialogue" lines.
+ * @param cache Set to 1 to keep all the previously split ASSDialog in
+ * the context, or set to 0 to free all the previously split
+ * ASSDialog.
+ * @param number If not NULL, the pointed integer will be set to the number
+ * of split ASSDialog.
+ * @return Pointer to the first split ASSDialog.
+ */
+ASSDialog *ff_ass_split_dialog(ASSSplitContext *ctx, const char *buf,
+ int cache, int *number);
+
+/**
+ * Free all the memory allocated for an ASSSplitContext.
+ *
+ * @param ctx Context previously initialized by ff_ass_split().
+ */
+void ff_ass_split_free(ASSSplitContext *ctx);
+
+
+/**
+ * Set of callback functions corresponding to each override codes that can
+ * be encountered in a "Dialogue" Text field.
+ */
+typedef struct {
+ /**
+ * @defgroup ass_styles ASS styles
+ * @{
+ */
+ void (*text)(void *priv, const char *text, int len);
+ void (*new_line)(void *priv, int forced);
+ void (*style)(void *priv, char style, int close);
+ void (*color)(void *priv, unsigned int color, unsigned int color_id);
+ void (*alpha)(void *priv, int alpha, int alpha_id);
+ void (*font_name)(void *priv, const char *name);
+ void (*font_size)(void *priv, int size);
+ void (*alignment)(void *priv, int alignment);
+ void (*cancel_overrides)(void *priv, const char *style);
+ /** @} */
+
+ /**
+ * @defgroup ass_functions ASS functions
+ * @{
+ */
+ void (*move)(void *priv, int x1, int y1, int x2, int y2, int t1, int t2);
+ void (*origin)(void *priv, int x, int y);
+ /** @} */
+
+ /**
+ * @defgroup ass_end end of Dialogue Event
+ * @{
+ */
+ void (*end)(void *priv);
+ /** @} */
+} ASSCodesCallbacks;
+
+/**
+ * Split override codes out of a ASS "Dialogue" Text field.
+ *
+ * @param callbacks Set of callback functions called for each override code
+ * encountered.
+ * @param priv Opaque pointer passed to the callback functions.
+ * @param buf The ASS "Dialogue" Text field to split.
+ * @return >= 0 on success otherwise an error code <0
+ */
+int ff_ass_split_override_codes(const ASSCodesCallbacks *callbacks, void *priv,
+ const char *buf);
+
+/**
+ * Find an ASSStyle structure by its name.
+ *
+ * @param ctx Context previously initialized by ff_ass_split().
+ * @param style name of the style to search for.
+ * @return the ASSStyle corresponding to style, or NULL if style can't be found
+ */
+ASSStyle *ass_style_get(ASSSplitContext *ctx, const char *style);
+
+#endif /* AVCODEC_ASS_SPLIT_H */
diff --git a/libavcodec/assdec.c b/libavcodec/assdec.c
index 98f7be36a2..087a0c839b 100644
--- a/libavcodec/assdec.c
+++ b/libavcodec/assdec.c
@@ -2,25 +2,26 @@
* SSA/ASS decoder
* Copyright (c) 2010 Aurelien Jacobs <aurel@gnuage.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avcodec.h"
#include "ass.h"
+#include "ass_split.h"
static av_cold int ass_decode_init(AVCodecContext *avctx)
{
@@ -29,6 +30,7 @@ static av_cold int ass_decode_init(AVCodecContext *avctx)
return AVERROR(ENOMEM);
memcpy(avctx->subtitle_header, avctx->extradata, avctx->extradata_size);
avctx->subtitle_header_size = avctx->extradata_size;
+ avctx->priv_data = ff_ass_split(avctx->extradata);
return 0;
}
@@ -38,10 +40,10 @@ static int ass_decode_frame(AVCodecContext *avctx, void *data, int *got_sub_ptr,
const char *ptr = avpkt->data;
int len, size = avpkt->size;
- ff_ass_init(data);
-
while (size > 0) {
- len = ff_ass_add_rect(data, ptr, 0, 0/* FIXME: duration */, 1);
+ ASSDialog *dialog = ff_ass_split_dialog(avctx->priv_data, ptr, 0, NULL);
+ int duration = dialog->end - dialog->start;
+ len = ff_ass_add_rect(data, ptr, 0, duration, 1);
if (len < 0)
return len;
ptr += len;
@@ -52,6 +54,13 @@ static int ass_decode_frame(AVCodecContext *avctx, void *data, int *got_sub_ptr,
return avpkt->size;
}
+static int ass_decode_close(AVCodecContext *avctx)
+{
+ ff_ass_split_free(avctx->priv_data);
+ avctx->priv_data = NULL;
+ return 0;
+}
+
AVCodec ff_ass_decoder = {
.name = "ass",
.long_name = NULL_IF_CONFIG_SMALL("Advanced SubStation Alpha subtitle"),
@@ -59,4 +68,5 @@ AVCodec ff_ass_decoder = {
.id = CODEC_ID_SSA,
.init = ass_decode_init,
.decode = ass_decode_frame,
+ .close = ass_decode_close,
};
diff --git a/libavcodec/assenc.c b/libavcodec/assenc.c
index b7836ff29f..103f2ff276 100644
--- a/libavcodec/assenc.c
+++ b/libavcodec/assenc.c
@@ -2,20 +2,20 @@
* SSA/ASS encoder
* Copyright (c) 2010 Aurelien Jacobs <aurel@gnuage.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/asv1.c b/libavcodec/asv1.c
index e8ab07b4cb..ab5ac8d68e 100644
--- a/libavcodec/asv1.c
+++ b/libavcodec/asv1.c
@@ -2,20 +2,20 @@
* ASUS V1/V2 codec
* Copyright (c) 2003 Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -497,7 +497,7 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size,
}
emms_c();
- align_put_bits(&a->pb);
+ avpriv_align_put_bits(&a->pb);
while(put_bits_count(&a->pb)&31)
put_bits(&a->pb, 8, 0);
@@ -603,39 +603,37 @@ static av_cold int decode_end(AVCodecContext *avctx){
}
AVCodec ff_asv1_decoder = {
- "asv1",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_ASV1,
- sizeof(ASV1Context),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- CODEC_CAP_DR1,
+ .name = "asv1",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_ASV1,
+ .priv_data_size = sizeof(ASV1Context),
+ .init = decode_init,
+ .close = decode_end,
+ .decode = decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name= NULL_IF_CONFIG_SMALL("ASUS V1"),
};
AVCodec ff_asv2_decoder = {
- "asv2",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_ASV2,
- sizeof(ASV1Context),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- CODEC_CAP_DR1,
+ .name = "asv2",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_ASV2,
+ .priv_data_size = sizeof(ASV1Context),
+ .init = decode_init,
+ .close = decode_end,
+ .decode = decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name= NULL_IF_CONFIG_SMALL("ASUS V2"),
};
#if CONFIG_ASV1_ENCODER
AVCodec ff_asv1_encoder = {
- "asv1",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_ASV1,
- sizeof(ASV1Context),
- encode_init,
- encode_frame,
+ .name = "asv1",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_ASV1,
+ .priv_data_size = sizeof(ASV1Context),
+ .init = encode_init,
+ .encode = encode_frame,
//encode_end,
.pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
.long_name= NULL_IF_CONFIG_SMALL("ASUS V1"),
@@ -644,12 +642,12 @@ AVCodec ff_asv1_encoder = {
#if CONFIG_ASV2_ENCODER
AVCodec ff_asv2_encoder = {
- "asv2",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_ASV2,
- sizeof(ASV1Context),
- encode_init,
- encode_frame,
+ .name = "asv2",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_ASV2,
+ .priv_data_size = sizeof(ASV1Context),
+ .init = encode_init,
+ .encode = encode_frame,
//encode_end,
.pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
.long_name= NULL_IF_CONFIG_SMALL("ASUS V2"),
diff --git a/libavcodec/atrac.c b/libavcodec/atrac.c
index 2c39aade22..6c1b1f19ce 100644
--- a/libavcodec/atrac.c
+++ b/libavcodec/atrac.c
@@ -3,20 +3,20 @@
* Copyright (c) 2006-2008 Maxim Poliakovski
* Copyright (c) 2006-2008 Benjamin Larsson
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/atrac.h b/libavcodec/atrac.h
index 2223a5e620..e126935e12 100644
--- a/libavcodec/atrac.h
+++ b/libavcodec/atrac.h
@@ -3,20 +3,20 @@
* Copyright (c) 2009 Maxim Poliakovski
* Copyright (c) 2009 Benjamin Larsson
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/atrac1.c b/libavcodec/atrac1.c
index 0ba2cf6bdd..2ad99bf473 100644
--- a/libavcodec/atrac1.c
+++ b/libavcodec/atrac1.c
@@ -3,20 +3,20 @@
* Copyright (c) 2009 Maxim Poliakovski
* Copyright (c) 2009 Benjamin Larsson
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -282,7 +282,7 @@ static int atrac1_decode_frame(AVCodecContext *avctx, void *data,
if (buf_size < 212 * q->channels) {
- av_log(q,AV_LOG_ERROR,"Not enought data to decode!\n");
+ av_log(avctx, AV_LOG_ERROR,"Not enought data to decode!\n");
return -1;
}
diff --git a/libavcodec/atrac1data.h b/libavcodec/atrac1data.h
index 7d5dbebc7f..ebebe4b105 100644
--- a/libavcodec/atrac1data.h
+++ b/libavcodec/atrac1data.h
@@ -3,20 +3,20 @@
* Copyright (c) 2009 Maxim Poliakovski
* Copyright (c) 2009 Benjamin Larsson
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/atrac3.c b/libavcodec/atrac3.c
index accaae3d65..20ab75dfd7 100644
--- a/libavcodec/atrac3.c
+++ b/libavcodec/atrac3.c
@@ -3,20 +3,20 @@
* Copyright (c) 2006-2008 Maxim Poliakovski
* Copyright (c) 2006-2008 Benjamin Larsson
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/atrac3data.h b/libavcodec/atrac3data.h
index 9076d3ae8d..b5aa71f8ca 100644
--- a/libavcodec/atrac3data.h
+++ b/libavcodec/atrac3data.h
@@ -3,20 +3,20 @@
* Copyright (c) 2006-2007 Maxim Poliakovski
* Copyright (c) 2006-2007 Benjamin Larsson
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/audioconvert.c b/libavcodec/audioconvert.c
index 4bea30848f..e101095e40 100644
--- a/libavcodec/audioconvert.c
+++ b/libavcodec/audioconvert.c
@@ -2,20 +2,20 @@
* audio conversion
* Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/audioconvert.h b/libavcodec/audioconvert.h
index e9a78fe495..5f38cca513 100644
--- a/libavcodec/audioconvert.h
+++ b/libavcodec/audioconvert.h
@@ -3,20 +3,20 @@
* Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
* Copyright (c) 2008 Peter Ross
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/aura.c b/libavcodec/aura.c
index e85e8225fd..e2c90b45f7 100644
--- a/libavcodec/aura.c
+++ b/libavcodec/aura.c
@@ -1,20 +1,20 @@
/*
* Aura 2 decoder
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -39,6 +39,7 @@ static av_cold int aura_decode_init(AVCodecContext *avctx)
if (avctx->width & 0x3)
return -1;
avctx->pix_fmt = PIX_FMT_YUV422P;
+ avcodec_get_frame_defaults(&s->frame);
return 0;
}
@@ -123,16 +124,14 @@ static av_cold int aura_decode_end(AVCodecContext *avctx)
}
AVCodec ff_aura2_decoder = {
- "aura2",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_AURA2,
- sizeof(AuraDecodeContext),
- aura_decode_init,
- NULL,
- aura_decode_end,
- aura_decode_frame,
- CODEC_CAP_DR1,
- NULL,
+ .name = "aura2",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_AURA2,
+ .priv_data_size = sizeof(AuraDecodeContext),
+ .init = aura_decode_init,
+ .close = aura_decode_end,
+ .decode = aura_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Auravision Aura 2"),
};
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index b26bac7bef..c2b9096d87 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -1,20 +1,20 @@
/*
* copyright (c) 2001 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -30,6 +30,7 @@
#include "libavutil/samplefmt.h"
#include "libavutil/avutil.h"
#include "libavutil/cpu.h"
+#include "libavutil/dict.h"
#include "libavutil/log.h"
#include "libavutil/pixfmt.h"
#include "libavutil/rational.h"
@@ -207,8 +208,17 @@ enum CodecID {
CODEC_ID_PRORES,
CODEC_ID_JV,
CODEC_ID_DFA,
+ CODEC_ID_WMV3IMAGE,
+ CODEC_ID_VC1IMAGE,
+#if LIBAVCODEC_VERSION_MAJOR == 53
+ CODEC_ID_8SVX_RAW,
+ CODEC_ID_G2M,
+#endif
+ CODEC_ID_UTVIDEO_DEPRECATED,
+ CODEC_ID_UTVIDEO = 0x800,
/* various PCM "codecs" */
+ CODEC_ID_FIRST_AUDIO = 0x10000, ///< A dummy id pointing at the start of audio codecs
CODEC_ID_PCM_S16LE= 0x10000,
CODEC_ID_PCM_S16BE,
CODEC_ID_PCM_U16LE,
@@ -337,8 +347,12 @@ enum CodecID {
CODEC_ID_BINKAUDIO_DCT,
CODEC_ID_AAC_LATM,
CODEC_ID_QDMC,
+ CODEC_ID_CELT,
+ CODEC_ID_G729 = 0x15800,
+ CODEC_ID_G723_1= 0x15801,
/* subtitle codecs */
+ CODEC_ID_FIRST_SUBTITLE = 0x17000, ///< A dummy ID pointing at the start of subtitle codecs.
CODEC_ID_DVD_SUBTITLE= 0x17000,
CODEC_ID_DVB_SUBTITLE,
CODEC_ID_TEXT, ///< raw UTF-8 text
@@ -348,9 +362,14 @@ enum CodecID {
CODEC_ID_HDMV_PGS_SUBTITLE,
CODEC_ID_DVB_TELETEXT,
CODEC_ID_SRT,
+ CODEC_ID_MICRODVD,
/* other specific kind of codecs (generally used for attachments) */
+ CODEC_ID_FIRST_UNKNOWN = 0x18000, ///< A dummy ID pointing at the start of various fake codecs.
CODEC_ID_TTF= 0x18000,
+ CODEC_ID_BINTEXT,
+ CODEC_ID_XBIN,
+ CODEC_ID_IDF,
CODEC_ID_PROBE= 0x19000, ///< codec_id is not known (like CODEC_ID_NONE) but lavf should attempt to identify it
@@ -429,7 +448,7 @@ enum CodecID {
* Note: If the first 23 bits of the additional bytes are not 0, then damaged
* MPEG bitstreams could cause overread and segfault.
*/
-#define FF_INPUT_BUFFER_PADDING_SIZE 8
+#define FF_INPUT_BUFFER_PADDING_SIZE 16
/**
* minimum encoding buffer size
@@ -564,7 +583,6 @@ typedef struct RcOverride{
#define CODEC_FLAG_QPEL 0x0010 ///< Use qpel MC.
#define CODEC_FLAG_GMC 0x0020 ///< Use GMC.
#define CODEC_FLAG_MV0 0x0040 ///< Always try a MB with MV=<0,0>.
-#define CODEC_FLAG_PART 0x0080 ///< Use data partitioning.
/**
* The parent program guarantees that the input for B-frames containing
* streams is not written to for at least s->max_b_frames+1 frames, if
@@ -573,7 +591,6 @@ typedef struct RcOverride{
#define CODEC_FLAG_INPUT_PRESERVED 0x0100
#define CODEC_FLAG_PASS1 0x0200 ///< Use internal 2pass ratecontrol in first pass mode.
#define CODEC_FLAG_PASS2 0x0400 ///< Use internal 2pass ratecontrol in second pass mode.
-#define CODEC_FLAG_EXTERN_HUFF 0x1000 ///< Use external Huffman table (for MJPEG).
#define CODEC_FLAG_GRAY 0x2000 ///< Only decode/encode grayscale.
#define CODEC_FLAG_EMU_EDGE 0x4000 ///< Don't draw edges.
#define CODEC_FLAG_PSNR 0x8000 ///< error[?] variables will be set during encoding.
@@ -582,25 +599,43 @@ typedef struct RcOverride{
#define CODEC_FLAG_NORMALIZE_AQP 0x00020000 ///< Normalize adaptive quantization.
#define CODEC_FLAG_INTERLACED_DCT 0x00040000 ///< Use interlaced DCT.
#define CODEC_FLAG_LOW_DELAY 0x00080000 ///< Force low delay.
-#define CODEC_FLAG_ALT_SCAN 0x00100000 ///< Use alternate scan.
#define CODEC_FLAG_GLOBAL_HEADER 0x00400000 ///< Place global headers in extradata instead of every keyframe.
#define CODEC_FLAG_BITEXACT 0x00800000 ///< Use only bitexact stuff (except (I)DCT).
/* Fx : Flag for h263+ extra options */
#define CODEC_FLAG_AC_PRED 0x01000000 ///< H.263 advanced intra coding / MPEG-4 AC prediction
-#define CODEC_FLAG_H263P_UMV 0x02000000 ///< unlimited motion vector
#define CODEC_FLAG_CBP_RD 0x04000000 ///< Use rate distortion optimization for cbp.
#define CODEC_FLAG_QP_RD 0x08000000 ///< Use rate distortion optimization for qp selectioon.
-#define CODEC_FLAG_H263P_AIV 0x00000008 ///< H.263 alternative inter VLC
-#define CODEC_FLAG_OBMC 0x00000001 ///< OBMC
#define CODEC_FLAG_LOOP_FILTER 0x00000800 ///< loop filter
-#define CODEC_FLAG_H263P_SLICE_STRUCT 0x10000000
#define CODEC_FLAG_INTERLACED_ME 0x20000000 ///< interlaced motion estimation
-#define CODEC_FLAG_SVCD_SCAN_OFFSET 0x40000000 ///< Will reserve space for SVCD scan offset user data.
#define CODEC_FLAG_CLOSED_GOP 0x80000000
#define CODEC_FLAG2_FAST 0x00000001 ///< Allow non spec compliant speedup tricks.
#define CODEC_FLAG2_STRICT_GOP 0x00000002 ///< Strictly enforce GOP size.
#define CODEC_FLAG2_NO_OUTPUT 0x00000004 ///< Skip bitstream encoding.
#define CODEC_FLAG2_LOCAL_HEADER 0x00000008 ///< Place global headers at every keyframe instead of in extradata.
+#define CODEC_FLAG2_SKIP_RD 0x00004000 ///< RD optimal MB level residual skipping
+#define CODEC_FLAG2_CHUNKS 0x00008000 ///< Input bitstream might be truncated at a packet boundaries instead of only at frame boundaries.
+#define CODEC_FLAG2_SHOW_ALL 0x00400000 ///< Show all frames before the first keyframe
+/**
+ * @defgroup deprecated_flags Deprecated codec flags
+ * Use corresponding private codec options instead.
+ * @{
+ */
+#if FF_API_MPEGVIDEO_GLOBAL_OPTS
+#define CODEC_FLAG_OBMC 0x00000001 ///< OBMC
+#define CODEC_FLAG_H263P_AIV 0x00000008 ///< H.263 alternative inter VLC
+#define CODEC_FLAG_PART 0x0080 ///< Use data partitioning.
+#define CODEC_FLAG_ALT_SCAN 0x00100000 ///< Use alternate scan.
+#define CODEC_FLAG_H263P_UMV 0x02000000 ///< unlimited motion vector
+#define CODEC_FLAG_H263P_SLICE_STRUCT 0x10000000
+#define CODEC_FLAG_SVCD_SCAN_OFFSET 0x40000000 ///< Will reserve space for SVCD scan offset user data.
+#define CODEC_FLAG2_INTRA_VLC 0x00000800 ///< Use MPEG-2 intra VLC table.
+#define CODEC_FLAG2_DROP_FRAME_TIMECODE 0x00002000 ///< timecode is in drop frame format.
+#define CODEC_FLAG2_NON_LINEAR_QUANT 0x00010000 ///< Use MPEG-2 nonlinear quantizer.
+#endif
+#if FF_API_MJPEG_GLOBAL_OPTS
+#define CODEC_FLAG_EXTERN_HUFF 0x1000 ///< Use external Huffman table (for MJPEG).
+#endif
+#if FF_API_X264_GLOBAL_OPTS
#define CODEC_FLAG2_BPYRAMID 0x00000010 ///< H.264 allow B-frames to be used as references.
#define CODEC_FLAG2_WPRED 0x00000020 ///< H.264 weighted biprediction for B-frames
#define CODEC_FLAG2_MIXED_REFS 0x00000040 ///< H.264 one reference per partition, as opposed to one reference per macroblock
@@ -608,17 +643,20 @@ typedef struct RcOverride{
#define CODEC_FLAG2_FASTPSKIP 0x00000100 ///< H.264 fast pskip
#define CODEC_FLAG2_AUD 0x00000200 ///< H.264 access unit delimiters
#define CODEC_FLAG2_BRDO 0x00000400 ///< B-frame rate-distortion optimization
-#define CODEC_FLAG2_INTRA_VLC 0x00000800 ///< Use MPEG-2 intra VLC table.
-#define CODEC_FLAG2_MEMC_ONLY 0x00001000 ///< Only do ME/MC (I frames -> ref, P frame -> ME+MC).
-#define CODEC_FLAG2_DROP_FRAME_TIMECODE 0x00002000 ///< timecode is in drop frame format.
-#define CODEC_FLAG2_SKIP_RD 0x00004000 ///< RD optimal MB level residual skipping
-#define CODEC_FLAG2_CHUNKS 0x00008000 ///< Input bitstream might be truncated at a packet boundaries instead of only at frame boundaries.
-#define CODEC_FLAG2_NON_LINEAR_QUANT 0x00010000 ///< Use MPEG-2 nonlinear quantizer.
-#define CODEC_FLAG2_BIT_RESERVOIR 0x00020000 ///< Use a bit reservoir when encoding if possible
#define CODEC_FLAG2_MBTREE 0x00040000 ///< Use macroblock tree ratecontrol (x264 only)
#define CODEC_FLAG2_PSY 0x00080000 ///< Use psycho visual optimizations.
#define CODEC_FLAG2_SSIM 0x00100000 ///< Compute SSIM during encoding, error[] values are undefined.
#define CODEC_FLAG2_INTRA_REFRESH 0x00200000 ///< Use periodic insertion of intra blocks instead of keyframes.
+#endif
+#if FF_API_SNOW_GLOBAL_OPTS
+#define CODEC_FLAG2_MEMC_ONLY 0x00001000 ///< Only do ME/MC (I frames -> ref, P frame -> ME+MC).
+#endif
+#if FF_API_LAME_GLOBAL_OPTS
+#define CODEC_FLAG2_BIT_RESERVOIR 0x00020000 ///< Use a bit reservoir when encoding if possible
+#endif
+/**
+ * @}
+ */
/* Unsupported options :
* Syntax Arithmetic coding (SAC)
@@ -640,8 +678,10 @@ typedef struct RcOverride{
/* Codec can export data for HW decoding (XvMC). */
#define CODEC_CAP_HWACCEL 0x0010
/**
- * Codec has a nonzero delay and needs to be fed with NULL at the end to get the delayed data.
- * If this is not set, the codec is guaranteed to never be fed with NULL data.
+ * Codec has a nonzero delay and needs to be fed with avpkt->data=NULL,
+ * avpkt->size=0 at the end to get the delayed data until the decoder no longer
+ * returns frames. If this is not set, the codec is guaranteed to never be fed
+ * with NULL data.
*/
#define CODEC_CAP_DELAY 0x0020
/**
@@ -674,10 +714,12 @@ typedef struct RcOverride{
* Codec should fill in channel configuration and samplerate instead of container
*/
#define CODEC_CAP_CHANNEL_CONF 0x0400
+
/**
* Codec is able to deal with negative linesizes
*/
#define CODEC_CAP_NEG_LINESIZES 0x0800
+
/**
* Codec supports frame-level multithreading.
*/
@@ -686,6 +728,10 @@ typedef struct RcOverride{
* Codec supports slice-based (or partition-based) multithreading.
*/
#define CODEC_CAP_SLICE_THREADS 0x2000
+/**
+ * Codec is lossless.
+ */
+#define CODEC_CAP_LOSSLESS 0x80000000
//The following defines may change, don't expect compatibility if you use them.
#define MB_TYPE_INTRA4x4 0x0001
@@ -740,266 +786,6 @@ typedef struct AVPanScan{
int16_t position[3][2];
}AVPanScan;
-#define FF_COMMON_FRAME \
- /**\
- * pointer to the picture planes.\
- * This might be different from the first allocated byte\
- * - encoding: \
- * - decoding: \
- */\
- uint8_t *data[4];\
- int linesize[4];\
- /**\
- * pointer to the first allocated byte of the picture. Can be used in get_buffer/release_buffer.\
- * This isn't used by libavcodec unless the default get/release_buffer() is used.\
- * - encoding: \
- * - decoding: \
- */\
- uint8_t *base[4];\
- /**\
- * 1 -> keyframe, 0-> not\
- * - encoding: Set by libavcodec.\
- * - decoding: Set by libavcodec.\
- */\
- int key_frame;\
-\
- /**\
- * Picture type of the frame, see ?_TYPE below.\
- * - encoding: Set by libavcodec. for coded_picture (and set by user for input).\
- * - decoding: Set by libavcodec.\
- */\
- enum AVPictureType pict_type;\
-\
- /**\
- * presentation timestamp in time_base units (time when frame should be shown to user)\
- * If AV_NOPTS_VALUE then frame_rate = 1/time_base will be assumed.\
- * - encoding: MUST be set by user.\
- * - decoding: Set by libavcodec.\
- */\
- int64_t pts;\
-\
- /**\
- * picture number in bitstream order\
- * - encoding: set by\
- * - decoding: Set by libavcodec.\
- */\
- int coded_picture_number;\
- /**\
- * picture number in display order\
- * - encoding: set by\
- * - decoding: Set by libavcodec.\
- */\
- int display_picture_number;\
-\
- /**\
- * quality (between 1 (good) and FF_LAMBDA_MAX (bad)) \
- * - encoding: Set by libavcodec. for coded_picture (and set by user for input).\
- * - decoding: Set by libavcodec.\
- */\
- int quality; \
-\
- /**\
- * buffer age (1->was last buffer and dint change, 2->..., ...).\
- * Set to INT_MAX if the buffer has not been used yet.\
- * - encoding: unused\
- * - decoding: MUST be set by get_buffer().\
- */\
- int age;\
-\
- /**\
- * is this picture used as reference\
- * The values for this are the same as the MpegEncContext.picture_structure\
- * variable, that is 1->top field, 2->bottom field, 3->frame/both fields.\
- * Set to 4 for delayed, non-reference frames.\
- * - encoding: unused\
- * - decoding: Set by libavcodec. (before get_buffer() call)).\
- */\
- int reference;\
-\
- /**\
- * QP table\
- * - encoding: unused\
- * - decoding: Set by libavcodec.\
- */\
- int8_t *qscale_table;\
- /**\
- * QP store stride\
- * - encoding: unused\
- * - decoding: Set by libavcodec.\
- */\
- int qstride;\
-\
- /**\
- * mbskip_table[mb]>=1 if MB didn't change\
- * stride= mb_width = (width+15)>>4\
- * - encoding: unused\
- * - decoding: Set by libavcodec.\
- */\
- uint8_t *mbskip_table;\
-\
- /**\
- * motion vector table\
- * @code\
- * example:\
- * int mv_sample_log2= 4 - motion_subsample_log2;\
- * int mb_width= (width+15)>>4;\
- * int mv_stride= (mb_width << mv_sample_log2) + 1;\
- * motion_val[direction][x + y*mv_stride][0->mv_x, 1->mv_y];\
- * @endcode\
- * - encoding: Set by user.\
- * - decoding: Set by libavcodec.\
- */\
- int16_t (*motion_val[2])[2];\
-\
- /**\
- * macroblock type table\
- * mb_type_base + mb_width + 2\
- * - encoding: Set by user.\
- * - decoding: Set by libavcodec.\
- */\
- uint32_t *mb_type;\
-\
- /**\
- * log2 of the size of the block which a single vector in motion_val represents: \
- * (4->16x16, 3->8x8, 2-> 4x4, 1-> 2x2)\
- * - encoding: unused\
- * - decoding: Set by libavcodec.\
- */\
- uint8_t motion_subsample_log2;\
-\
- /**\
- * for some private data of the user\
- * - encoding: unused\
- * - decoding: Set by user.\
- */\
- void *opaque;\
-\
- /**\
- * error\
- * - encoding: Set by libavcodec. if flags&CODEC_FLAG_PSNR.\
- * - decoding: unused\
- */\
- uint64_t error[4];\
-\
- /**\
- * type of the buffer (to keep track of who has to deallocate data[*])\
- * - encoding: Set by the one who allocates it.\
- * - decoding: Set by the one who allocates it.\
- * Note: User allocated (direct rendering) & internal buffers cannot coexist currently.\
- */\
- int type;\
- \
- /**\
- * When decoding, this signals how much the picture must be delayed.\
- * extra_delay = repeat_pict / (2*fps)\
- * - encoding: unused\
- * - decoding: Set by libavcodec.\
- */\
- int repeat_pict;\
- \
- /**\
- * \
- */\
- int qscale_type;\
- \
- /**\
- * The content of the picture is interlaced.\
- * - encoding: Set by user.\
- * - decoding: Set by libavcodec. (default 0)\
- */\
- int interlaced_frame;\
- \
- /**\
- * If the content is interlaced, is top field displayed first.\
- * - encoding: Set by user.\
- * - decoding: Set by libavcodec.\
- */\
- int top_field_first;\
- \
- /**\
- * Pan scan.\
- * - encoding: Set by user.\
- * - decoding: Set by libavcodec.\
- */\
- AVPanScan *pan_scan;\
- \
- /**\
- * Tell user application that palette has changed from previous frame.\
- * - encoding: ??? (no palette-enabled encoder yet)\
- * - decoding: Set by libavcodec. (default 0).\
- */\
- int palette_has_changed;\
- \
- /**\
- * codec suggestion on buffer type if != 0\
- * - encoding: unused\
- * - decoding: Set by libavcodec. (before get_buffer() call)).\
- */\
- int buffer_hints;\
-\
- /**\
- * DCT coefficients\
- * - encoding: unused\
- * - decoding: Set by libavcodec.\
- */\
- short *dct_coeff;\
-\
- /**\
- * motion reference frame index\
- * the order in which these are stored can depend on the codec.\
- * - encoding: Set by user.\
- * - decoding: Set by libavcodec.\
- */\
- int8_t *ref_index[2];\
-\
- /**\
- * reordered opaque 64bit (generally an integer or a double precision float\
- * PTS but can be anything). \
- * The user sets AVCodecContext.reordered_opaque to represent the input at\
- * that time,\
- * the decoder reorders values as needed and sets AVFrame.reordered_opaque\
- * to exactly one of the values provided by the user through AVCodecContext.reordered_opaque \
- * @deprecated in favor of pkt_pts\
- * - encoding: unused\
- * - decoding: Read by user.\
- */\
- int64_t reordered_opaque;\
-\
- /**\
- * hardware accelerator private data (Libav-allocated)\
- * - encoding: unused\
- * - decoding: Set by libavcodec\
- */\
- void *hwaccel_picture_private;\
-\
- /**\
- * reordered pts from the last AVPacket that has been input into the decoder\
- * - encoding: unused\
- * - decoding: Read by user.\
- */\
- int64_t pkt_pts;\
-\
- /**\
- * dts from the last AVPacket that has been input into the decoder\
- * - encoding: unused\
- * - decoding: Read by user.\
- */\
- int64_t pkt_dts;\
-\
- /**\
- * the AVCodecContext which ff_thread_get_buffer() was last called on\
- * - encoding: Set by libavcodec.\
- * - decoding: Set by libavcodec.\
- */\
- struct AVCodecContext *owner;\
-\
- /**\
- * used by multithreading to store frame-specific info\
- * - encoding: Set by libavcodec.\
- * - decoding: Set by libavcodec.\
- */\
- void *thread_opaque;\
-
#define FF_QSCALE_TYPE_MPEG1 0
#define FF_QSCALE_TYPE_MPEG2 1
#define FF_QSCALE_TYPE_H264 2
@@ -1050,6 +836,9 @@ typedef struct AVPacket {
uint8_t *data;
int size;
int stream_index;
+ /**
+ * A combination of AV_PKT_FLAG values
+ */
int flags;
/**
* Additional packet data that can be provided by the container.
@@ -1090,19 +879,313 @@ typedef struct AVPacket {
*/
int64_t convergence_duration;
} AVPacket;
-#define AV_PKT_FLAG_KEY 0x0001
+#define AV_PKT_FLAG_KEY 0x0001 ///< The packet contains a keyframe
+#define AV_PKT_FLAG_CORRUPT 0x0002 ///< The packet content is corrupted
/**
* Audio Video Frame.
- * New fields can be added to the end of FF_COMMON_FRAME with minor version
- * bumps.
- * Removal, reordering and changes to existing fields require a major
- * version bump. No fields should be added into AVFrame before or after
- * FF_COMMON_FRAME!
+ * New fields can be added to the end of AVFRAME with minor version
+ * bumps. Removal, reordering and changes to existing fields require
+ * a major version bump.
* sizeof(AVFrame) must not be used outside libav*.
*/
typedef struct AVFrame {
- FF_COMMON_FRAME
+ /**
+ * pointer to the picture planes.
+ * This might be different from the first allocated byte
+ * - encoding:
+ * - decoding:
+ */
+ uint8_t *data[4];
+ int linesize[4];
+ /**
+ * pointer to the first allocated byte of the picture. Can be used in get_buffer/release_buffer.
+ * This isn't used by libavcodec unless the default get/release_buffer() is used.
+ * - encoding:
+ * - decoding:
+ */
+ uint8_t *base[4];
+ /**
+ * 1 -> keyframe, 0-> not
+ * - encoding: Set by libavcodec.
+ * - decoding: Set by libavcodec.
+ */
+ int key_frame;
+
+ /**
+ * Picture type of the frame, see ?_TYPE below.
+ * - encoding: Set by libavcodec. for coded_picture (and set by user for input).
+ * - decoding: Set by libavcodec.
+ */
+ enum AVPictureType pict_type;
+
+ /**
+ * presentation timestamp in time_base units (time when frame should be shown to user)
+ * If AV_NOPTS_VALUE then frame_rate = 1/time_base will be assumed.
+ * - encoding: MUST be set by user.
+ * - decoding: Set by libavcodec.
+ */
+ int64_t pts;
+
+ /**
+ * picture number in bitstream order
+ * - encoding: set by
+ * - decoding: Set by libavcodec.
+ */
+ int coded_picture_number;
+ /**
+ * picture number in display order
+ * - encoding: set by
+ * - decoding: Set by libavcodec.
+ */
+ int display_picture_number;
+
+ /**
+ * quality (between 1 (good) and FF_LAMBDA_MAX (bad))
+ * - encoding: Set by libavcodec. for coded_picture (and set by user for input).
+ * - decoding: Set by libavcodec.
+ */
+ int quality;
+
+ /**
+ * buffer age (1->was last buffer and dint change, 2->..., ...).
+ * Set to INT_MAX if the buffer has not been used yet.
+ * - encoding: unused
+ * - decoding: MUST be set by get_buffer().
+ */
+ int age;
+
+ /**
+ * is this picture used as reference
+ * The values for this are the same as the MpegEncContext.picture_structure
+ * variable, that is 1->top field, 2->bottom field, 3->frame/both fields.
+ * Set to 4 for delayed, non-reference frames.
+ * - encoding: unused
+ * - decoding: Set by libavcodec. (before get_buffer() call)).
+ */
+ int reference;
+
+ /**
+ * QP table
+ * - encoding: unused
+ * - decoding: Set by libavcodec.
+ */
+ int8_t *qscale_table;
+ /**
+ * QP store stride
+ * - encoding: unused
+ * - decoding: Set by libavcodec.
+ */
+ int qstride;
+
+ /**
+ * mbskip_table[mb]>=1 if MB didn't change
+ * stride= mb_width = (width+15)>>4
+ * - encoding: unused
+ * - decoding: Set by libavcodec.
+ */
+ uint8_t *mbskip_table;
+
+ /**
+ * motion vector table
+ * @code
+ * example:
+ * int mv_sample_log2= 4 - motion_subsample_log2;
+ * int mb_width= (width+15)>>4;
+ * int mv_stride= (mb_width << mv_sample_log2) + 1;
+ * motion_val[direction][x + y*mv_stride][0->mv_x, 1->mv_y];
+ * @endcode
+ * - encoding: Set by user.
+ * - decoding: Set by libavcodec.
+ */
+ int16_t (*motion_val[2])[2];
+
+ /**
+ * macroblock type table
+ * mb_type_base + mb_width + 2
+ * - encoding: Set by user.
+ * - decoding: Set by libavcodec.
+ */
+ uint32_t *mb_type;
+
+ /**
+ * log2 of the size of the block which a single vector in motion_val represents:
+ * (4->16x16, 3->8x8, 2-> 4x4, 1-> 2x2)
+ * - encoding: unused
+ * - decoding: Set by libavcodec.
+ */
+ uint8_t motion_subsample_log2;
+
+ /**
+ * for some private data of the user
+ * - encoding: unused
+ * - decoding: Set by user.
+ */
+ void *opaque;
+
+ /**
+ * error
+ * - encoding: Set by libavcodec. if flags&CODEC_FLAG_PSNR.
+ * - decoding: unused
+ */
+ uint64_t error[4];
+
+ /**
+ * type of the buffer (to keep track of who has to deallocate data[*])
+ * - encoding: Set by the one who allocates it.
+ * - decoding: Set by the one who allocates it.
+ * Note: User allocated (direct rendering) & internal buffers cannot coexist currently.
+ */
+ int type;
+
+ /**
+ * When decoding, this signals how much the picture must be delayed.
+ * extra_delay = repeat_pict / (2*fps)
+ * - encoding: unused
+ * - decoding: Set by libavcodec.
+ */
+ int repeat_pict;
+
+ /**
+ *
+ */
+ int qscale_type;
+
+ /**
+ * The content of the picture is interlaced.
+ * - encoding: Set by user.
+ * - decoding: Set by libavcodec. (default 0)
+ */
+ int interlaced_frame;
+
+ /**
+ * If the content is interlaced, is top field displayed first.
+ * - encoding: Set by user.
+ * - decoding: Set by libavcodec.
+ */
+ int top_field_first;
+
+ /**
+ * Pan scan.
+ * - encoding: Set by user.
+ * - decoding: Set by libavcodec.
+ */
+ AVPanScan *pan_scan;
+
+ /**
+ * Tell user application that palette has changed from previous frame.
+ * - encoding: ??? (no palette-enabled encoder yet)
+ * - decoding: Set by libavcodec. (default 0).
+ */
+ int palette_has_changed;
+
+ /**
+ * codec suggestion on buffer type if != 0
+ * - encoding: unused
+ * - decoding: Set by libavcodec. (before get_buffer() call)).
+ */
+ int buffer_hints;
+
+ /**
+ * DCT coefficients
+ * - encoding: unused
+ * - decoding: Set by libavcodec.
+ */
+ short *dct_coeff;
+
+ /**
+ * motion reference frame index
+ * the order in which these are stored can depend on the codec.
+ * - encoding: Set by user.
+ * - decoding: Set by libavcodec.
+ */
+ int8_t *ref_index[2];
+
+ /**
+ * reordered opaque 64bit (generally an integer or a double precision float
+ * PTS but can be anything).
+ * The user sets AVCodecContext.reordered_opaque to represent the input at
+ * that time,
+ * the decoder reorders values as needed and sets AVFrame.reordered_opaque
+ * to exactly one of the values provided by the user through AVCodecContext.reordered_opaque
+ * @deprecated in favor of pkt_pts
+ * - encoding: unused
+ * - decoding: Read by user.
+ */
+ int64_t reordered_opaque;
+
+ /**
+ * hardware accelerator private data (FFmpeg-allocated)
+ * - encoding: unused
+ * - decoding: Set by libavcodec
+ */
+ void *hwaccel_picture_private;
+
+ /**
+ * reordered pts from the last AVPacket that has been input into the decoder
+ * - encoding: unused
+ * - decoding: Read by user.
+ */
+ int64_t pkt_pts;
+
+ /**
+ * dts from the last AVPacket that has been input into the decoder
+ * - encoding: unused
+ * - decoding: Read by user.
+ */
+ int64_t pkt_dts;
+
+ /**
+ * the AVCodecContext which ff_thread_get_buffer() was last called on
+ * - encoding: Set by libavcodec.
+ * - decoding: Set by libavcodec.
+ */
+ struct AVCodecContext *owner;
+
+ /**
+ * used by multithreading to store frame-specific info
+ * - encoding: Set by libavcodec.
+ * - decoding: Set by libavcodec.
+ */
+ void *thread_opaque;
+
+ /**
+ * frame timestamp estimated using various heuristics, in stream time base
+ * - encoding: unused
+ * - decoding: set by libavcodec, read by user.
+ */
+ int64_t best_effort_timestamp;
+
+ /**
+ * reordered pos from the last AVPacket that has been input into the decoder
+ * - encoding: unused
+ * - decoding: Read by user.
+ */
+ int64_t pkt_pos;
+
+ /**
+ * reordered sample aspect ratio for the video frame, 0/1 if unknown\unspecified
+ * - encoding: unused
+ * - decoding: Read by user.
+ */
+ AVRational sample_aspect_ratio;
+
+ /**
+ * width and height of the video frame
+ * - encoding: unused
+ * - decoding: Read by user.
+ */
+ int width, height;
+
+ /**
+ * format of the frame, -1 if unknown or unset
+ * It should be cast to the corresponding enum (enum PixelFormat
+ * for video, enum AVSampleFormat for audio)
+ * - encoding: unused
+ * - decoding: Read by user.
+ */
+ int format;
+
} AVFrame;
/**
@@ -1110,6 +1193,8 @@ typedef struct AVFrame {
* New fields can be added to the end with minor version bumps.
* Removal, reordering and changes to existing fields require a major
* version bump.
+ * Please use AVOptions (av_opt* / av_set/get*()) to access these fields from user
+ * applications.
* sizeof(AVCodecContext) must not be used outside libav*.
*/
typedef struct AVCodecContext {
@@ -1439,17 +1524,20 @@ typedef struct AVCodecContext {
*/
float b_quant_offset;
+#if FF_API_ER
/**
- * Error recognization; higher values will detect more errors but may
+ * Error recognition; higher values will detect more errors but may
* misdetect some more or less valid parts as errors.
* - encoding: unused
* - decoding: Set by user.
*/
- int error_recognition;
+ attribute_deprecated int error_recognition;
#define FF_ER_CAREFUL 1
#define FF_ER_COMPLIANT 2
#define FF_ER_AGGRESSIVE 3
#define FF_ER_VERY_AGGRESSIVE 4
+#define FF_ER_EXPLODE 5
+#endif /* FF_API_ER */
/**
* Called at the beginning of each frame to get a buffer for it.
@@ -2235,6 +2323,23 @@ typedef struct AVCodecContext {
#define FF_PROFILE_VC1_COMPLEX 2
#define FF_PROFILE_VC1_ADVANCED 3
+#define FF_PROFILE_MPEG4_SIMPLE 0
+#define FF_PROFILE_MPEG4_SIMPLE_SCALABLE 1
+#define FF_PROFILE_MPEG4_CORE 2
+#define FF_PROFILE_MPEG4_MAIN 3
+#define FF_PROFILE_MPEG4_N_BIT 4
+#define FF_PROFILE_MPEG4_SCALABLE_TEXTURE 5
+#define FF_PROFILE_MPEG4_SIMPLE_FACE_ANIMATION 6
+#define FF_PROFILE_MPEG4_BASIC_ANIMATED_TEXTURE 7
+#define FF_PROFILE_MPEG4_HYBRID 8
+#define FF_PROFILE_MPEG4_ADVANCED_REAL_TIME 9
+#define FF_PROFILE_MPEG4_CORE_SCALABLE 10
+#define FF_PROFILE_MPEG4_ADVANCED_CODING 11
+#define FF_PROFILE_MPEG4_ADVANCED_CORE 12
+#define FF_PROFILE_MPEG4_ADVANCED_SCALABLE_TEXTURE 13
+#define FF_PROFILE_MPEG4_SIMPLE_STUDIO 14
+#define FF_PROFILE_MPEG4_ADVANCED_SIMPLE 15
+
/**
* level
* - encoding: Set by user.
@@ -2251,8 +2356,7 @@ typedef struct AVCodecContext {
int lowres;
/**
- * Bitstream width / height, may be different from width/height if lowres
- * or other things are used.
+ * Bitstream width / height, may be different from width/height if lowres enabled.
* - encoding: unused
* - decoding: Set by user before init if known. Codec should override / dynamically change if needed.
*/
@@ -2350,19 +2454,23 @@ typedef struct AVCodecContext {
*/
int brd_scale;
+#if FF_API_X264_GLOBAL_OPTS
/**
* constant rate factor - quality-based VBR - values ~correspond to qps
* - encoding: Set by user.
* - decoding: unused
+ * @deprecated use 'crf' libx264 private option
*/
- float crf;
+ attribute_deprecated float crf;
/**
* constant quantization parameter rate control method
* - encoding: Set by user.
* - decoding: unused
+ * @deprecated use 'cqp' libx264 private option
*/
- int cqp;
+ attribute_deprecated int cqp;
+#endif
/**
* minimum GOP size
@@ -2385,12 +2493,14 @@ typedef struct AVCodecContext {
*/
int chromaoffset;
+#if FF_API_X264_GLOBAL_OPTS
/**
* Influences how often B-frames are used.
* - encoding: Set by user.
* - decoding: unused
*/
- int bframebias;
+ attribute_deprecated int bframebias;
+#endif
/**
* trellis RD quantization
@@ -2399,12 +2509,13 @@ typedef struct AVCodecContext {
*/
int trellis;
+#if FF_API_X264_GLOBAL_OPTS
/**
* Reduce fluctuations in qp (before curve compression).
* - encoding: Set by user.
* - decoding: unused
*/
- float complexityblur;
+ attribute_deprecated float complexityblur;
/**
* in-loop deblocking filter alphac0 parameter
@@ -2412,7 +2523,7 @@ typedef struct AVCodecContext {
* - encoding: Set by user.
* - decoding: unused
*/
- int deblockalpha;
+ attribute_deprecated int deblockalpha;
/**
* in-loop deblocking filter beta parameter
@@ -2420,14 +2531,14 @@ typedef struct AVCodecContext {
* - encoding: Set by user.
* - decoding: unused
*/
- int deblockbeta;
+ attribute_deprecated int deblockbeta;
/**
* macroblock subpartition sizes to consider - p8x8, p4x4, b8x8, i8x8, i4x4
* - encoding: Set by user.
* - decoding: unused
*/
- int partitions;
+ attribute_deprecated int partitions;
#define X264_PART_I4X4 0x001 /* Analyze i4x4 */
#define X264_PART_I8X8 0x002 /* Analyze i8x8 (requires 8x8 transform) */
#define X264_PART_P8X8 0x010 /* Analyze p16x8, p8x16 and p8x8 */
@@ -2439,7 +2550,8 @@ typedef struct AVCodecContext {
* - encoding: Set by user.
* - decoding: unused
*/
- int directpred;
+ attribute_deprecated int directpred;
+#endif
/**
* Audio cutoff bandwidth (0 means "automatic")
@@ -2543,13 +2655,16 @@ typedef struct AVCodecContext {
int request_channels;
#endif
+#if FF_API_DRC_SCALE
/**
* Percentage of dynamic range compression to be applied by the decoder.
* The default value is 1.0, corresponding to full compression.
* - encoding: unused
* - decoding: Set by user.
+ * @deprecated use AC3 decoder private option instead.
*/
- float drc_scale;
+ attribute_deprecated float drc_scale;
+#endif
/**
* opaque 64bit number (generally a PTS) that will be reordered and
@@ -2562,7 +2677,6 @@ typedef struct AVCodecContext {
/**
* Bits per sample/pixel of internal libavcodec pixel/sample format.
- * This field is applicable only when sample_fmt is AV_SAMPLE_FMT_S32.
* - encoding: set by user.
* - decoding: set by libavcodec.
*/
@@ -2571,7 +2685,7 @@ typedef struct AVCodecContext {
/**
* Audio channel layout.
* - encoding: set by user.
- * - decoding: set by libavcodec.
+ * - decoding: set by user, may be overwritten by libavcodec.
*/
int64_t channel_layout;
@@ -2616,8 +2730,8 @@ typedef struct AVCodecContext {
* Hardware accelerator context.
* For some hardware accelerators, a global context needs to be
* provided by the user. In that case, this holds display-dependent
- * data Libav cannot instantiate itself. Please refer to the
- * Libav HW accelerator documentation to know how to fill this
+ * data FFmpeg cannot instantiate itself. Please refer to the
+ * FFmpeg HW accelerator documentation to know how to fill this
* is. e.g. for VA API, this is a struct vaapi_context.
* - encoding: unused
* - decoding: Set by user
@@ -2679,6 +2793,7 @@ typedef struct AVCodecContext {
*/
int (*execute2)(struct AVCodecContext *c, int (*func)(struct AVCodecContext *c2, void *arg, int jobnr, int threadnr), void *arg2, int *ret, int count);
+#if FF_API_X264_GLOBAL_OPTS
/**
* explicit P-frame weighted prediction analysis method
* 0: off
@@ -2687,7 +2802,7 @@ typedef struct AVCodecContext {
* - encoding: Set by user.
* - decoding: unused
*/
- int weighted_p_pred;
+ attribute_deprecated int weighted_p_pred;
/**
* AQ mode
@@ -2697,7 +2812,7 @@ typedef struct AVCodecContext {
* - encoding: Set by user
* - decoding: unused
*/
- int aq_mode;
+ attribute_deprecated int aq_mode;
/**
* AQ strength
@@ -2705,7 +2820,7 @@ typedef struct AVCodecContext {
* - encoding: Set by user
* - decoding: unused
*/
- float aq_strength;
+ attribute_deprecated float aq_strength;
/**
* PSY RD
@@ -2713,7 +2828,7 @@ typedef struct AVCodecContext {
* - encoding: Set by user
* - decoding: unused
*/
- float psy_rd;
+ attribute_deprecated float psy_rd;
/**
* PSY trellis
@@ -2721,7 +2836,7 @@ typedef struct AVCodecContext {
* - encoding: Set by user
* - decoding: unused
*/
- float psy_trellis;
+ attribute_deprecated float psy_trellis;
/**
* RC lookahead
@@ -2729,7 +2844,7 @@ typedef struct AVCodecContext {
* - encoding: Set by user
* - decoding: unused
*/
- int rc_lookahead;
+ attribute_deprecated int rc_lookahead;
/**
* Constant rate factor maximum
@@ -2738,7 +2853,8 @@ typedef struct AVCodecContext {
* - encoding: Set by user.
* - decoding: unused
*/
- float crf_max;
+ attribute_deprecated float crf_max;
+#endif
int log_level_offset;
@@ -2805,8 +2921,8 @@ typedef struct AVCodecContext {
* - decoding: Set by user, otherwise the default is used.
*/
int thread_type;
-#define FF_THREAD_FRAME 1 //< Decode more than one frame at once
-#define FF_THREAD_SLICE 2 //< Decode more than one part of a single frame at once
+#define FF_THREAD_FRAME 1 ///< Decode more than one frame at once
+#define FF_THREAD_SLICE 2 ///< Decode more than one part of a single frame at once
/**
* Which multithreading methods are in use by the codec.
@@ -2841,11 +2957,34 @@ typedef struct AVCodecContext {
enum AVAudioServiceType audio_service_type;
/**
- * Used to request a sample format from the decoder.
- * - encoding: unused.
+ * desired sample format
+ * - encoding: Not used.
* - decoding: Set by user.
+ * Decoder will decode to this format if it can.
*/
enum AVSampleFormat request_sample_fmt;
+
+ /**
+ * Error recognition; may misdetect some more or less valid parts as errors.
+ * - encoding: unused
+ * - decoding: Set by user.
+ */
+ int err_recognition;
+#define AV_EF_CRCCHECK (1<<0)
+#define AV_EF_BITSTREAM (1<<1)
+#define AV_EF_BUFFER (1<<2)
+#define AV_EF_EXPLODE (1<<3)
+
+ /**
+ * Current statistics for PTS correction.
+ * - decoding: maintained and used by libavcodec, not intended to be used by user apps
+ * - encoding: unused
+ */
+ int64_t pts_correction_num_faulty_pts; /// Number of incorrect PTS values so far
+ int64_t pts_correction_num_faulty_dts; /// Number of incorrect DTS values so far
+ int64_t pts_correction_last_pts; /// PTS of the last frame
+ int64_t pts_correction_last_dts; /// DTS of the last frame
+
} AVCodecContext;
/**
@@ -2856,6 +2995,8 @@ typedef struct AVProfile {
const char *name; ///< short name for the profile
} AVProfile;
+typedef struct AVCodecDefault AVCodecDefault;
+
/**
* AVCodec.
*/
@@ -2918,6 +3059,16 @@ typedef struct AVCodec {
*/
int (*update_thread_context)(AVCodecContext *dst, const AVCodecContext *src);
/** @} */
+
+ /**
+ * Private codec-specific defaults.
+ */
+ const AVCodecDefault *defaults;
+
+ /**
+ * Initialize codec static data, called from avcodec_register().
+ */
+ void (*init_static_data)(struct AVCodec *codec);
} AVCodec;
/**
@@ -3019,6 +3170,8 @@ typedef struct AVPicture {
int linesize[4]; ///< number of bytes per line
} AVPicture;
+#define AVPALETTE_SIZE 1024
+#define AVPALETTE_COUNT 256
#if FF_API_PALETTE_CONTROL
/**
* AVPaletteControl
@@ -3028,8 +3181,6 @@ typedef struct AVPicture {
* @deprecated Use AVPacket to send palette changes instead.
* This is totally broken.
*/
-#define AVPALETTE_SIZE 1024
-#define AVPALETTE_COUNT 256
typedef struct AVPaletteControl {
/* Demuxer sets this to 1 to indicate the palette has changed;
@@ -3176,6 +3327,11 @@ uint8_t* av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
uint8_t* av_packet_get_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
int *size);
+int av_packet_merge_side_data(AVPacket *pkt);
+
+int av_packet_split_side_data(AVPacket *pkt);
+
+
/* resample.c */
struct ReSampleContext;
@@ -3333,8 +3489,17 @@ int avpicture_layout(const AVPicture* src, enum PixelFormat pix_fmt, int width,
int avpicture_get_size(enum PixelFormat pix_fmt, int width, int height);
void avcodec_get_chroma_sub_sample(enum PixelFormat pix_fmt, int *h_shift, int *v_shift);
+/**
+ * Get the name of a codec.
+ * @return a static string identifying the codec; never NULL
+ */
+const char *avcodec_get_name(enum CodecID id);
+
#if FF_API_GET_PIX_FMT_NAME
/**
+ * Return the short name for a pixel format.
+ *
+ * \see av_get_pix_fmt(), av_get_pix_fmt_string().
* @deprecated Deprecated in favor of av_get_pix_fmt_name().
*/
attribute_deprecated
@@ -3381,7 +3546,8 @@ size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_ta
* @param[in] dst_pix_fmt destination pixel format
* @param[in] src_pix_fmt source pixel format
* @param[in] has_alpha Whether the source pixel format alpha channel is used.
- * @return Combination of flags informing you what kind of losses will occur.
+ * @return Combination of flags informing you what kind of losses will occur
+ * (maximum loss for an invalid dst_pix_fmt).
*/
int avcodec_get_pix_fmt_loss(enum PixelFormat dst_pix_fmt, enum PixelFormat src_pix_fmt,
int has_alpha);
@@ -3396,9 +3562,11 @@ int avcodec_get_pix_fmt_loss(enum PixelFormat dst_pix_fmt, enum PixelFormat src_
* The pixel formats from which it chooses one, are determined by the
* pix_fmt_mask parameter.
*
+ * Note, only the first 64 pixel formats will fit in pix_fmt_mask.
+ *
* @code
* src_pix_fmt = PIX_FMT_YUV420P;
- * pix_fmt_mask = (1 << PIX_FMT_YUV422P) || (1 << PIX_FMT_RGB24);
+ * pix_fmt_mask = (1 << PIX_FMT_YUV422P) | (1 << PIX_FMT_RGB24);
* dst_pix_fmt = avcodec_find_best_pix_fmt(pix_fmt_mask, src_pix_fmt, alpha, &loss);
* @endcode
*
@@ -3411,6 +3579,40 @@ int avcodec_get_pix_fmt_loss(enum PixelFormat dst_pix_fmt, enum PixelFormat src_
enum PixelFormat avcodec_find_best_pix_fmt(int64_t pix_fmt_mask, enum PixelFormat src_pix_fmt,
int has_alpha, int *loss_ptr);
+/**
+ * Find the best pixel format to convert to given a certain source pixel
+ * format and a selection of two destination pixel formats. When converting from
+ * one pixel format to another, information loss may occur. For example, when converting
+ * from RGB24 to GRAY, the color information will be lost. Similarly, other losses occur when
+ * converting from some formats to other formats. avcodec_find_best_pix_fmt2() selects which of
+ * the given pixel formats should be used to suffer the least amount of loss.
+ *
+ * If one of the destination formats is PIX_FMT_NONE the other pixel format (if valid) will be
+ * returned.
+ *
+ * @code
+ * src_pix_fmt = PIX_FMT_YUV420P;
+ * dst_pix_fmt1= PIX_FMT_RGB24;
+ * dst_pix_fmt2= PIX_FMT_GRAY8;
+ * dst_pix_fmt3= PIX_FMT_RGB8;
+ * loss= FF_LOSS_CHROMA; // don't care about chroma loss, so chroma loss will be ignored.
+ * dst_pix_fmt = avcodec_find_best_pix_fmt2(dst_pix_fmt1, dst_pix_fmt2, src_pix_fmt, alpha, &loss);
+ * dst_pix_fmt = avcodec_find_best_pix_fmt2(dst_pix_fmt, dst_pix_fmt3, src_pix_fmt, alpha, &loss);
+ * @endcode
+ *
+ * @param[in] dst_pix_fmt1 One of the two destination pixel formats to choose from
+ * @param[in] dst_pix_fmt2 The other of the two destination pixel formats to choose from
+ * @param[in] src_pix_fmt Source pixel format
+ * @param[in] has_alpha Whether the source pixel format alpha channel is used.
+ * @param[in, out] loss_ptr Combination of loss flags. In: selects which of the losses to ignore, i.e.
+ * NULL or value of zero means we care about all losses. Out: the loss
+ * that occurs when converting from src to selected dst pixel format.
+ * @return The best pixel format to convert to or -1 if none was found.
+ */
+enum PixelFormat avcodec_find_best_pix_fmt2(enum PixelFormat dst_pix_fmt1, enum PixelFormat dst_pix_fmt2,
+ enum PixelFormat src_pix_fmt, int has_alpha, int *loss_ptr);
+
+#if FF_API_GET_ALPHA_INFO
#define FF_ALPHA_TRANSP 0x0001 /* image has some totally transparent pixels */
#define FF_ALPHA_SEMI_TRANSP 0x0002 /* image has some transparent pixels */
@@ -3418,8 +3620,10 @@ enum PixelFormat avcodec_find_best_pix_fmt(int64_t pix_fmt_mask, enum PixelForma
* Tell if an image really has transparent alpha values.
* @return ored mask of FF_ALPHA_xxx constants
*/
+attribute_deprecated
int img_get_alpha_info(const AVPicture *src,
enum PixelFormat pix_fmt, int width, int height);
+#endif
/* deinterlace a picture */
/* deinterlace - if not supported return -1 */
@@ -3450,21 +3654,22 @@ const char *avcodec_configuration(void);
*/
const char *avcodec_license(void);
+#if FF_API_AVCODEC_INIT
/**
- * Initialize libavcodec.
- * If called more than once, does nothing.
- *
- * @warning This function must be called before any other libavcodec
- * function.
- *
- * @warning This function is not thread-safe.
+ * @deprecated this function is called automatically from avcodec_register()
+ * and avcodec_register_all(), there is no need to call it manually
*/
+attribute_deprecated
void avcodec_init(void);
+#endif
/**
* Register the codec codec and initialize libavcodec.
*
- * @see avcodec_init(), avcodec_register_all()
+ * @warning either this function or avcodec_register_all() must be called
+ * before any other libavcodec functions.
+ *
+ * @see avcodec_register_all()
*/
void avcodec_register(AVCodec *codec);
@@ -3510,36 +3715,63 @@ void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode);
*/
const char *av_get_profile_name(const AVCodec *codec, int profile);
+#if FF_API_ALLOC_CONTEXT
/**
* Set the fields of the given AVCodecContext to default values.
*
* @param s The AVCodecContext of which the fields should be set to default values.
+ * @deprecated use avcodec_get_context_defaults3
*/
+attribute_deprecated
void avcodec_get_context_defaults(AVCodecContext *s);
/** THIS FUNCTION IS NOT YET PART OF THE PUBLIC API!
* we WILL change its arguments and name a few times! */
+attribute_deprecated
void avcodec_get_context_defaults2(AVCodecContext *s, enum AVMediaType);
+#endif
-/** THIS FUNCTION IS NOT YET PART OF THE PUBLIC API!
- * we WILL change its arguments and name a few times! */
+/**
+ * Set the fields of the given AVCodecContext to default values corresponding
+ * to the given codec (defaults may be codec-dependent).
+ *
+ * Do not call this function if a non-NULL codec has been passed
+ * to avcodec_alloc_context3() that allocated this AVCodecContext.
+ * If codec is non-NULL, it is illegal to call avcodec_open2() with a
+ * different codec on this AVCodecContext.
+ */
int avcodec_get_context_defaults3(AVCodecContext *s, AVCodec *codec);
+#if FF_API_ALLOC_CONTEXT
/**
* Allocate an AVCodecContext and set its fields to default values. The
* resulting struct can be deallocated by simply calling av_free().
*
* @return An AVCodecContext filled with default values or NULL on failure.
* @see avcodec_get_context_defaults
+ *
+ * @deprecated use avcodec_alloc_context3()
*/
+attribute_deprecated
AVCodecContext *avcodec_alloc_context(void);
/** THIS FUNCTION IS NOT YET PART OF THE PUBLIC API!
* we WILL change its arguments and name a few times! */
+attribute_deprecated
AVCodecContext *avcodec_alloc_context2(enum AVMediaType);
+#endif
-/** THIS FUNCTION IS NOT YET PART OF THE PUBLIC API!
- * we WILL change its arguments and name a few times! */
+/**
+ * Allocate an AVCodecContext and set its fields to default values. The
+ * resulting struct can be deallocated by simply calling av_free().
+ *
+ * @param codec if non-NULL, allocate private data and initialize defaults
+ * for the given codec. It is illegal to then call avcodec_open()
+ * with a different codec.
+ *
+ * @return An AVCodecContext filled with default values or NULL on failure.
+ * @see avcodec_get_context_defaults
+ */
AVCodecContext *avcodec_alloc_context3(AVCodec *codec);
/**
@@ -3549,7 +3781,7 @@ AVCodecContext *avcodec_alloc_context3(AVCodec *codec);
* can use this AVCodecContext to decode/encode video/audio data.
*
* @param dest target codec context, should be initialized with
- * avcodec_alloc_context(), but otherwise uninitialized
+ * avcodec_alloc_context3(), but otherwise uninitialized
* @param src source codec context
* @return AVERROR() on error (e.g. memory allocation error), 0 on success
*/
@@ -3619,6 +3851,7 @@ int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, v
int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int, int),void *arg, int *ret, int count);
//FIXME func typedef
+#if FF_API_AVCODEC_OPEN
/**
* Initialize the AVCodecContext to use the given AVCodec. Prior to using this
* function the context has to be allocated.
@@ -3635,7 +3868,7 @@ int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2,
* if (!codec)
* exit(1);
*
- * context = avcodec_alloc_context();
+ * context = avcodec_alloc_context3(codec);
*
* if (avcodec_open(context, codec) < 0)
* exit(1);
@@ -3644,9 +3877,46 @@ int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2,
* @param avctx The context which will be set up to use the given codec.
* @param codec The codec to use within the context.
* @return zero on success, a negative value on error
- * @see avcodec_alloc_context, avcodec_find_decoder, avcodec_find_encoder, avcodec_close
+ * @see avcodec_alloc_context3, avcodec_find_decoder, avcodec_find_encoder, avcodec_close
+ *
+ * @deprecated use avcodec_open2
*/
+attribute_deprecated
int avcodec_open(AVCodecContext *avctx, AVCodec *codec);
+#endif
+
+/**
+ * Initialize the AVCodecContext to use the given AVCodec. Prior to using this
+ * function the context has to be allocated with avcodec_alloc_context().
+ *
+ * The functions avcodec_find_decoder_by_name(), avcodec_find_encoder_by_name(),
+ * avcodec_find_decoder() and avcodec_find_encoder() provide an easy way for
+ * retrieving a codec.
+ *
+ * @warning This function is not thread safe!
+ *
+ * @code
+ * avcodec_register_all();
+ * av_dict_set(&opts, "b", "2.5M", 0);
+ * codec = avcodec_find_decoder(CODEC_ID_H264);
+ * if (!codec)
+ * exit(1);
+ *
+ * context = avcodec_alloc_context();
+ *
+ * if (avcodec_open(context, codec, opts) < 0)
+ * exit(1);
+ * @endcode
+ *
+ * @param avctx The context to initialize.
+ * @param options A dictionary filled with AVCodecContext and codec-private options.
+ * On return this object will be filled with options that were not found.
+ *
+ * @return zero on success, a negative value on error
+ * @see avcodec_alloc_context3(), avcodec_find_decoder(), avcodec_find_encoder(),
+ * av_dict_set(), av_opt_find().
+ */
+int avcodec_open2(AVCodecContext *avctx, AVCodec *codec, AVDictionary **options);
/**
* Decode the audio frame of size avpkt->size from avpkt->data into samples.
@@ -3677,6 +3947,10 @@ int avcodec_open(AVCodecContext *avctx, AVCodec *codec);
* samples should be 16 byte aligned unless the CPU doesn't need it
* (AltiVec and SSE do).
*
+ * @note Codecs which have the CODEC_CAP_DELAY capability set have a delay
+ * between input and output, these need to be fed with avpkt->data=NULL,
+ * avpkt->size=0 at the end to return the remaining frames.
+ *
* @param avctx the codec context
* @param[out] samples the output buffer, sample type in avctx->sample_fmt
* @param[in,out] frame_size_ptr the output buffer size in bytes
@@ -3710,8 +3984,9 @@ int avcodec_decode_audio3(AVCodecContext *avctx, int16_t *samples,
*
* In practice, avpkt->data should have 4 byte alignment at minimum.
*
- * @note Some codecs have a delay between input and output, these need to be
- * fed with avpkt->data=NULL, avpkt->size=0 at the end to return the remaining frames.
+ * @note Codecs which have the CODEC_CAP_DELAY capability set have a delay
+ * between input and output, these need to be fed with avpkt->data=NULL,
+ * avpkt->size=0 at the end to return the remaining frames.
*
* @param avctx the codec context
* @param[out] picture The AVFrame in which the decoded video frame will be stored.
@@ -4126,7 +4401,7 @@ unsigned int av_xiphlacing(unsigned char *s, unsigned int v);
/**
* Logs a generic warning message about a missing feature. This function is
- * intended to be used internally by Libav (libavcodec, libavformat, etc.)
+ * intended to be used internally by FFmpeg (libavcodec, libavformat, etc.)
* only, and would normally not be used by applications.
* @param[in] avc a pointer to an arbitrary struct of which the first field is
* a pointer to an AVClass struct
@@ -4140,7 +4415,7 @@ void av_log_missing_feature(void *avc, const char *feature, int want_sample);
/**
* Log a generic warning message asking for a sample. This function is
- * intended to be used internally by Libav (libavcodec, libavformat, etc.)
+ * intended to be used internally by FFmpeg (libavcodec, libavformat, etc.)
* only, and would normally not be used by applications.
* @param[in] avc a pointer to an arbitrary struct of which the first field is
* a pointer to an AVClass struct
@@ -4177,7 +4452,7 @@ enum AVLockOp {
* lockmgr should store/get a pointer to a user allocated mutex. It's
* NULL upon AV_LOCK_CREATE and != NULL for all other ops.
*
- * @param cb User defined callback. Note: Libav may invoke calls to this
+ * @param cb User defined callback. Note: FFmpeg may invoke calls to this
* callback during the call to av_lockmgr_register().
* Thus, the application must be prepared to handle that.
* If cb is set to NULL the lockmgr will be unregistered.
@@ -4186,4 +4461,17 @@ enum AVLockOp {
*/
int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op));
+/**
+ * Get the type of the given codec.
+ */
+enum AVMediaType avcodec_get_type(enum CodecID codec_id);
+
+/**
+ * Get the AVClass for AVCodecContext. It can be used in combination with
+ * AV_OPT_SEARCH_FAKE_OBJ for examining options.
+ *
+ * @see av_opt_find().
+ */
+const AVClass *avcodec_get_class(void);
+
#endif /* AVCODEC_AVCODEC_H */
diff --git a/libavcodec/avfft.c b/libavcodec/avfft.c
index 9ed06fbeb5..9e0ddaa627 100644
--- a/libavcodec/avfft.c
+++ b/libavcodec/avfft.c
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/avfft.h b/libavcodec/avfft.h
index 91fe2f4297..be2d9c7e10 100644
--- a/libavcodec/avfft.h
+++ b/libavcodec/avfft.h
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index e0e4df46f2..ff34285b48 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -2,26 +2,26 @@
* AVPacket functions for libavcodec
* Copyright (c) 2000, 2001, 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avcodec.h"
#include "libavutil/avassert.h"
-
+#include "bytestream.h"
void av_destruct_packet_nofree(AVPacket *pkt)
{
@@ -196,3 +196,82 @@ uint8_t* av_packet_get_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
}
return NULL;
}
+
+#define FF_MERGE_MARKER 0x8c4d9d108e25e9feULL
+
+int av_packet_merge_side_data(AVPacket *pkt){
+ if(pkt->side_data_elems){
+ int i;
+ uint8_t *p;
+ uint64_t size= pkt->size + 8LL + FF_INPUT_BUFFER_PADDING_SIZE;
+ AVPacket old= *pkt;
+ for (i=0; i<old.side_data_elems; i++) {
+ size += old.side_data[i].size + 5LL;
+ }
+ if (size > INT_MAX)
+ return AVERROR(EINVAL);
+ p = av_malloc(size);
+ if (!p)
+ return AVERROR(ENOMEM);
+ pkt->data = p;
+ pkt->destruct = av_destruct_packet;
+ pkt->size = size - FF_INPUT_BUFFER_PADDING_SIZE;
+ bytestream_put_buffer(&p, old.data, old.size);
+ for (i=old.side_data_elems-1; i>=0; i--) {
+ bytestream_put_buffer(&p, old.side_data[i].data, old.side_data[i].size);
+ bytestream_put_be32(&p, old.side_data[i].size);
+ *p++ = old.side_data[i].type | ((i==old.side_data_elems-1)*128);
+ }
+ bytestream_put_be64(&p, FF_MERGE_MARKER);
+ av_assert0(p-pkt->data == pkt->size);
+ memset(p, 0, FF_INPUT_BUFFER_PADDING_SIZE);
+ av_free_packet(&old);
+ pkt->side_data_elems = 0;
+ pkt->side_data = NULL;
+ return 1;
+ }
+ return 0;
+}
+
+int av_packet_split_side_data(AVPacket *pkt){
+ if (!pkt->side_data_elems && pkt->size >12 && AV_RB64(pkt->data + pkt->size - 8) == FF_MERGE_MARKER){
+ int i;
+ unsigned int size;
+ uint8_t *p= pkt->data + pkt->size - 8 - 5;
+
+ av_dup_packet(pkt);
+
+ for (i=1; ; i++){
+ size = AV_RB32(p);
+ if (size>INT_MAX || p - pkt->data <= size)
+ return 0;
+ if (p[4]&128)
+ break;
+ p-= size+5;
+ }
+
+ pkt->side_data = av_malloc(i * sizeof(*pkt->side_data));
+ if (!pkt->side_data)
+ return AVERROR(ENOMEM);
+
+ p= pkt->data + pkt->size - 8 - 5;
+ for (i=0; ; i++){
+ size= AV_RB32(p);
+ av_assert0(size<=INT_MAX && p - pkt->data > size);
+ pkt->side_data[i].data = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);
+ pkt->side_data[i].size = size;
+ pkt->side_data[i].type = p[4]&127;
+ if (!pkt->side_data[i].data)
+ return AVERROR(ENOMEM);
+ memcpy(pkt->side_data[i].data, p-size, size);
+ pkt->size -= size + 5;
+ if(p[4]&128)
+ break;
+ p-= size+5;
+ }
+ pkt->size -= 8;
+ pkt->side_data_elems = i+1;
+ return 1;
+ }
+ return 0;
+}
diff --git a/libavcodec/avr32/mathops.h b/libavcodec/avr32/mathops.h
index 528b7adb33..85f42b594d 100644
--- a/libavcodec/avr32/mathops.h
+++ b/libavcodec/avr32/mathops.h
@@ -2,20 +2,20 @@
* Simple math operations
* Copyright (c) 2009 Mans Rullgard <mans@mansr.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/avs.c b/libavcodec/avs.c
index 1c2682b338..9e73695f5e 100644
--- a/libavcodec/avs.c
+++ b/libavcodec/avs.c
@@ -2,20 +2,20 @@
* AVS video decoder.
* Copyright (c) 2006 Aurelien Jacobs <aurel@gnuage.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -47,6 +47,7 @@ avs_decode_frame(AVCodecContext * avctx,
void *data, int *data_size, AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
+ const uint8_t *buf_end = avpkt->data + avpkt->size;
int buf_size = avpkt->size;
AvsContext *const avs = avctx->priv_data;
AVFrame *picture = data;
@@ -69,6 +70,8 @@ avs_decode_frame(AVCodecContext * avctx,
out = avs->picture.data[0];
stride = avs->picture.linesize[0];
+ if (buf_end - buf < 4)
+ return AVERROR_INVALIDDATA;
sub_type = buf[0];
type = buf[1];
buf += 4;
@@ -79,6 +82,8 @@ avs_decode_frame(AVCodecContext * avctx,
first = AV_RL16(buf);
last = first + AV_RL16(buf + 2);
+ if (first >= 256 || last > 256 || buf_end - buf < 4 + 4 + 3 * (last - first))
+ return AVERROR_INVALIDDATA;
buf += 4;
for (i=first; i<last; i++, buf+=3)
pal[i] = (buf[0] << 18) | (buf[1] << 10) | (buf[2] << 2);
@@ -114,16 +119,22 @@ avs_decode_frame(AVCodecContext * avctx,
return -1;
}
+ if (buf_end - buf < 256 * vect_w * vect_h)
+ return AVERROR_INVALIDDATA;
table = buf + (256 * vect_w * vect_h);
if (sub_type != AVS_I_FRAME) {
int map_size = ((318 / vect_w + 7) / 8) * (198 / vect_h);
- init_get_bits(&change_map, table, map_size);
+ if (buf_end - table < map_size)
+ return AVERROR_INVALIDDATA;
+ init_get_bits(&change_map, table, map_size * 8);
table += map_size;
}
for (y=0; y<198; y+=vect_h) {
for (x=0; x<318; x+=vect_w) {
if (sub_type == AVS_I_FRAME || get_bits1(&change_map)) {
+ if (buf_end - table < 1)
+ return AVERROR_INVALIDDATA;
vect = &buf[*table++ * (vect_w * vect_h)];
for (j=0; j<vect_w; j++) {
out[(y + 0) * stride + x + j] = vect[(0 * vect_w) + j];
@@ -146,19 +157,19 @@ avs_decode_frame(AVCodecContext * avctx,
static av_cold int avs_decode_init(AVCodecContext * avctx)
{
+ AvsContext *const avs = avctx->priv_data;
avctx->pix_fmt = PIX_FMT_PAL8;
+ avcodec_get_frame_defaults(&avs->picture);
return 0;
}
AVCodec ff_avs_decoder = {
- "avs",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_AVS,
- sizeof(AvsContext),
- avs_decode_init,
- NULL,
- NULL,
- avs_decode_frame,
- CODEC_CAP_DR1,
+ .name = "avs",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_AVS,
+ .priv_data_size = sizeof(AvsContext),
+ .init = avs_decode_init,
+ .decode = avs_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("AVS (Audio Video Standard) video"),
};
diff --git a/libavcodec/bethsoftvideo.c b/libavcodec/bethsoftvideo.c
index d294bbfe74..fa2db05765 100644
--- a/libavcodec/bethsoftvideo.c
+++ b/libavcodec/bethsoftvideo.c
@@ -2,20 +2,20 @@
* Bethesda VID video decoder
* Copyright (C) 2007 Nicholas Tung
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -23,8 +23,8 @@
* @file
* @brief Bethesda Softworks VID Video Decoder
* @author Nicholas Tung [ntung (at. ntung com] (2007-03)
- * @sa http://wiki.multimedia.cx/index.php?title=Bethsoft_VID
- * @sa http://www.svatopluk.com/andux/docs/dfvid.html
+ * @see http://wiki.multimedia.cx/index.php?title=Bethsoft_VID
+ * @see http://www.svatopluk.com/andux/docs/dfvid.html
*/
#include "libavutil/common.h"
@@ -39,6 +39,7 @@ typedef struct BethsoftvidContext {
static av_cold int bethsoftvid_decode_init(AVCodecContext *avctx)
{
BethsoftvidContext *vid = avctx->priv_data;
+ avcodec_get_frame_defaults(&vid->frame);
vid->frame.reference = 1;
vid->frame.buffer_hints = FF_BUFFER_HINTS_VALID |
FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
diff --git a/libavcodec/bethsoftvideo.h b/libavcodec/bethsoftvideo.h
index 5cbbdfdff0..d5b5d0a525 100644
--- a/libavcodec/bethsoftvideo.h
+++ b/libavcodec/bethsoftvideo.h
@@ -2,20 +2,20 @@
* Bethesda VID video decoder
* Copyright (C) 2007 Nicholas Tung
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/bfi.c b/libavcodec/bfi.c
index c97dfe2dc0..1f31d7fb61 100644
--- a/libavcodec/bfi.c
+++ b/libavcodec/bfi.c
@@ -2,20 +2,20 @@
* Brute Force & Ignorance (BFI) video decoder
* Copyright (c) 2008 Sisir Koppaka
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -23,7 +23,7 @@
* @file
* @brief Brute Force & Ignorance (.bfi) video decoder
* @author Sisir Koppaka ( sisir.koppaka at gmail dot com )
- * @sa http://wiki.multimedia.cx/index.php?title=BFI
+ * @see http://wiki.multimedia.cx/index.php?title=BFI
*/
#include "libavutil/common.h"
@@ -34,12 +34,14 @@ typedef struct BFIContext {
AVCodecContext *avctx;
AVFrame frame;
uint8_t *dst;
+ uint32_t pal[256];
} BFIContext;
static av_cold int bfi_decode_init(AVCodecContext * avctx)
{
BFIContext *bfi = avctx->priv_data;
avctx->pix_fmt = PIX_FMT_PAL8;
+ avcodec_get_frame_defaults(&bfi->frame);
bfi->dst = av_mallocz(avctx->width * avctx->height);
return 0;
}
@@ -85,10 +87,13 @@ static int bfi_decode_frame(AVCodecContext * avctx, void *data,
(avctx->extradata[i * 3 + j] >> 4)) << shift;
pal++;
}
+ memcpy(bfi->pal, bfi->frame.data[1], sizeof(bfi->pal));
bfi->frame.palette_has_changed = 1;
} else {
bfi->frame.pict_type = AV_PICTURE_TYPE_P;
bfi->frame.key_frame = 0;
+ bfi->frame.palette_has_changed = 0;
+ memcpy(bfi->frame.data[1], bfi->pal, sizeof(bfi->pal));
}
buf += 4; //Unpacked size, not required.
diff --git a/libavcodec/bfin/config_bfin.h b/libavcodec/bfin/config_bfin.h
index 0fee494cc7..f3a2c6ebc6 100644
--- a/libavcodec/bfin/config_bfin.h
+++ b/libavcodec/bfin/config_bfin.h
@@ -1,20 +1,20 @@
/*
* Copyright (C) 2007 Marc Hoffman <marc.hoffman@analog.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
diff --git a/libavcodec/bfin/dsputil_bfin.c b/libavcodec/bfin/dsputil_bfin.c
index 0db2d8baf8..bfcc337388 100644
--- a/libavcodec/bfin/dsputil_bfin.c
+++ b/libavcodec/bfin/dsputil_bfin.c
@@ -4,20 +4,20 @@
* Copyright (C) 2007 Marc Hoffman <marc.hoffman@analog.com>
* Copyright (c) 2006 Michael Benjamin <michael.benjamin@analog.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -197,14 +197,14 @@ static int bfin_pix_abs8_xy2 (void *c, uint8_t *blk1, uint8_t *blk2, int line_si
void dsputil_init_bfin( DSPContext* c, AVCodecContext *avctx )
{
- const int high_bit_depth = avctx->codec_id == CODEC_ID_H264 && avctx->bits_per_raw_sample > 8;
+ const int high_bit_depth = avctx->bits_per_raw_sample > 8;
- c->get_pixels = ff_bfin_get_pixels;
c->diff_pixels = ff_bfin_diff_pixels;
c->put_pixels_clamped = ff_bfin_put_pixels_clamped;
c->add_pixels_clamped = ff_bfin_add_pixels_clamped;
if (!high_bit_depth)
+ c->get_pixels = ff_bfin_get_pixels;
c->clear_blocks = bfin_clear_blocks;
c->pix_sum = ff_bfin_pix_sum;
c->pix_norm1 = ff_bfin_pix_norm1;
@@ -253,19 +253,21 @@ void dsputil_init_bfin( DSPContext* c, AVCodecContext *avctx )
/* c->put_no_rnd_pixels_tab[0][3] = ff_bfin_put_pixels16_xy2_nornd; */
}
- if (avctx->dct_algo == FF_DCT_AUTO)
- c->fdct = ff_bfin_fdct;
-
- if (avctx->idct_algo==FF_IDCT_VP3) {
- c->idct_permutation_type = FF_NO_IDCT_PERM;
- c->idct = ff_bfin_vp3_idct;
- c->idct_add = ff_bfin_vp3_idct_add;
- c->idct_put = ff_bfin_vp3_idct_put;
- } else if (avctx->idct_algo == FF_IDCT_AUTO) {
- c->idct_permutation_type = FF_NO_IDCT_PERM;
- c->idct = ff_bfin_idct;
- c->idct_add = bfin_idct_add;
- c->idct_put = bfin_idct_put;
+ if (avctx->bits_per_raw_sample <= 8) {
+ if (avctx->dct_algo == FF_DCT_AUTO)
+ c->fdct = ff_bfin_fdct;
+
+ if (avctx->idct_algo == FF_IDCT_VP3) {
+ c->idct_permutation_type = FF_NO_IDCT_PERM;
+ c->idct = ff_bfin_vp3_idct;
+ c->idct_add = ff_bfin_vp3_idct_add;
+ c->idct_put = ff_bfin_vp3_idct_put;
+ } else if (avctx->idct_algo == FF_IDCT_AUTO) {
+ c->idct_permutation_type = FF_NO_IDCT_PERM;
+ c->idct = ff_bfin_idct;
+ c->idct_add = bfin_idct_add;
+ c->idct_put = bfin_idct_put;
+ }
}
}
diff --git a/libavcodec/bfin/dsputil_bfin.h b/libavcodec/bfin/dsputil_bfin.h
index f1a9b32d64..7edcf97b6b 100644
--- a/libavcodec/bfin/dsputil_bfin.h
+++ b/libavcodec/bfin/dsputil_bfin.h
@@ -3,20 +3,20 @@
*
* Copyright (C) 2007 Marc Hoffman <mmh@pleasantst.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/bfin/fdct_bfin.S b/libavcodec/bfin/fdct_bfin.S
index 4c32436e01..0eac7a3042 100644
--- a/libavcodec/bfin/fdct_bfin.S
+++ b/libavcodec/bfin/fdct_bfin.S
@@ -3,20 +3,20 @@
*
* Copyright (C) 2007 Marc Hoffman <marc.hoffman@analog.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
diff --git a/libavcodec/bfin/idct_bfin.S b/libavcodec/bfin/idct_bfin.S
index b3dedd3410..04f9159d8d 100644
--- a/libavcodec/bfin/idct_bfin.S
+++ b/libavcodec/bfin/idct_bfin.S
@@ -3,20 +3,20 @@
*
* Copyright (C) 2007 Marc Hoffman <marc.hoffman@analog.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
diff --git a/libavcodec/bfin/mathops.h b/libavcodec/bfin/mathops.h
index bbee49380e..50c03160ed 100644
--- a/libavcodec/bfin/mathops.h
+++ b/libavcodec/bfin/mathops.h
@@ -3,20 +3,20 @@
*
* Copyright (C) 2007 Marc Hoffman <mmhoffm@gmail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVCODEC_BFIN_MATHOPS_H
diff --git a/libavcodec/bfin/mpegvideo_bfin.c b/libavcodec/bfin/mpegvideo_bfin.c
index ad68876149..996290a52d 100644
--- a/libavcodec/bfin/mpegvideo_bfin.c
+++ b/libavcodec/bfin/mpegvideo_bfin.c
@@ -3,20 +3,20 @@
*
* Copyright (C) 2007 Marc Hoffman <mmh@pleasantst.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -61,8 +61,13 @@ static int dct_quantize_bfin (MpegEncContext *s,
dc = block[0] = (block[0] + (q >> 1)) / q;
start_i = 1;
last_non_zero = 0;
- bias = s->q_intra_matrix16[qscale][1];
- qmat = s->q_intra_matrix16[qscale][0];
+ if(n<4){
+ bias = s->q_intra_matrix16[qscale][1];
+ qmat = s->q_intra_matrix16[qscale][0];
+ }else{
+ bias = s->q_chroma_intra_matrix16[qscale][1];
+ qmat = s->q_chroma_intra_matrix16[qscale][0];
+ }
} else {
start_i = 0;
diff --git a/libavcodec/bfin/pixels_bfin.S b/libavcodec/bfin/pixels_bfin.S
index 085ff46147..69b493b647 100644
--- a/libavcodec/bfin/pixels_bfin.S
+++ b/libavcodec/bfin/pixels_bfin.S
@@ -2,20 +2,20 @@
* Blackfin Pixel Operations
* Copyright (C) 2007 Marc Hoffman <marc.hoffman@analog.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "config_bfin.h"
diff --git a/libavcodec/bfin/vp3_bfin.c b/libavcodec/bfin/vp3_bfin.c
index 4b08042ff3..dfe34c5b3e 100644
--- a/libavcodec/bfin/vp3_bfin.c
+++ b/libavcodec/bfin/vp3_bfin.c
@@ -1,20 +1,20 @@
/*
* Copyright (C) 2007 Marc Hoffman <marc.hoffman@analog.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/bfin/vp3_idct_bfin.S b/libavcodec/bfin/vp3_idct_bfin.S
index 4c678f1bc6..21f732c58d 100644
--- a/libavcodec/bfin/vp3_idct_bfin.S
+++ b/libavcodec/bfin/vp3_idct_bfin.S
@@ -3,20 +3,20 @@
*
* Copyright (C) 2007 Marc Hoffman <marc.hoffman@analog.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
diff --git a/libavcodec/bgmc.c b/libavcodec/bgmc.c
index b8aaa8d14a..b9041d080e 100644
--- a/libavcodec/bgmc.c
+++ b/libavcodec/bgmc.c
@@ -2,20 +2,20 @@
* Block Gilbert-Moore decoder
* Copyright (c) 2010 Thilo Borgmann <thilo.borgmann _at_ googlemail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/bgmc.h b/libavcodec/bgmc.h
index 3d5b49034d..9e386fdbdd 100644
--- a/libavcodec/bgmc.h
+++ b/libavcodec/bgmc.h
@@ -2,20 +2,20 @@
* Block Gilbert-Moore decoder
* Copyright (c) 2010 Thilo Borgmann <thilo.borgmann _at_ googlemail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/bink.c b/libavcodec/bink.c
index e085aa54e2..253a874937 100644
--- a/libavcodec/bink.c
+++ b/libavcodec/bink.c
@@ -3,20 +3,20 @@
* Copyright (c) 2009 Konstantin Shishkov
* Copyright (C) 2011 Peter Ross <pross@xvid.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -24,6 +24,7 @@
#include "avcodec.h"
#include "dsputil.h"
#include "binkdata.h"
+#include "binkdsp.h"
#include "mathops.h"
#define ALT_BITSTREAM_READER_LE
@@ -60,8 +61,8 @@ static const int binkb_bundle_signed[BINKB_NB_SRC] = {
0, 0, 0, 1, 1, 0, 1, 0, 0, 0
};
-static uint32_t binkb_intra_quant[16][64];
-static uint32_t binkb_inter_quant[16][64];
+static int32_t binkb_intra_quant[16][64];
+static int32_t binkb_inter_quant[16][64];
/**
* IDs for different data types used in Bink video codec
@@ -109,11 +110,11 @@ typedef struct Bundle {
typedef struct BinkContext {
AVCodecContext *avctx;
DSPContext dsp;
+ BinkDSPContext bdsp;
AVFrame pic, last;
int version; ///< internal Bink file version
int has_alpha;
int swap_planes;
- ScanTable scantable; ///< permutated scantable for DCT coeffs decoding
Bundle bundle[BINKB_NB_SRC]; ///< bundles for decoding all data types
Tree col_high[16]; ///< trees for decoding high nibble in "colours" data type
@@ -246,7 +247,7 @@ static void read_tree(GetBitContext *gb, Tree *tree)
tree->syms[i] = get_bits(gb, 4);
tmp1[tree->syms[i]] = 1;
}
- for (i = 0; i < 16; i++)
+ for (i = 0; i < 16 && len < 16 - 1; i++)
if (!tmp1[i])
tree->syms[++len] = i;
} else {
@@ -343,14 +344,14 @@ static int read_motion_values(AVCodecContext *avctx, GetBitContext *gb, Bundle *
memset(b->cur_dec, v, t);
b->cur_dec += t;
} else {
- do {
+ while (b->cur_dec < dec_end) {
v = GET_HUFF(gb, b->tree);
if (v) {
sign = -get_bits1(gb);
v = (v ^ sign) - sign;
}
*b->cur_dec++ = v;
- } while (b->cur_dec < dec_end);
+ }
}
return 0;
}
@@ -374,7 +375,7 @@ static int read_block_types(AVCodecContext *avctx, GetBitContext *gb, Bundle *b)
memset(b->cur_dec, v, t);
b->cur_dec += t;
} else {
- do {
+ while (b->cur_dec < dec_end) {
v = GET_HUFF(gb, b->tree);
if (v < 12) {
last = v;
@@ -382,10 +383,12 @@ static int read_block_types(AVCodecContext *avctx, GetBitContext *gb, Bundle *b)
} else {
int run = bink_rlelens[v - 12];
+ if (dec_end - b->cur_dec < run)
+ return -1;
memset(b->cur_dec, last, run);
b->cur_dec += run;
}
- } while (b->cur_dec < dec_end);
+ }
}
return 0;
}
@@ -455,7 +458,8 @@ static int read_dcs(AVCodecContext *avctx, GetBitContext *gb, Bundle *b,
int start_bits, int has_sign)
{
int i, j, len, len2, bsize, sign, v, v2;
- int16_t *dst = (int16_t*)b->cur_dec;
+ int16_t *dst = (int16_t*)b->cur_dec;
+ int16_t *dst_end = (int16_t*)b->data_end;
CHECK_READ_VAL(gb, b, len);
v = get_bits(gb, start_bits - has_sign);
@@ -463,10 +467,14 @@ static int read_dcs(AVCodecContext *avctx, GetBitContext *gb, Bundle *b,
sign = -get_bits1(gb);
v = (v ^ sign) - sign;
}
+ if (dst_end - dst < 1)
+ return -1;
*dst++ = v;
len--;
for (i = 0; i < len; i += 8) {
len2 = FFMIN(len - i, 8);
+ if (dst_end - dst < len2)
+ return -1;
bsize = get_bits(gb, 4);
if (bsize) {
for (j = 0; j < len2; j++) {
@@ -534,6 +542,8 @@ static int binkb_read_bundle(BinkContext *c, GetBitContext *gb, int bundle_num)
int i, len;
CHECK_READ_VAL(gb, b, len);
+ if (b->data_end - b->cur_dec < len * (1 + (bits > 8)))
+ return -1;
if (bits <= 8) {
if (!issigned) {
for (i = 0; i < len; i++)
@@ -580,8 +590,8 @@ static inline int binkb_get_value(BinkContext *c, int bundle_num)
* @param quant_matrices quantization matrices
* @return 0 for success, negative value in other cases
*/
-static int read_dct_coeffs(GetBitContext *gb, DCTELEM block[64], const uint8_t *scan,
- const uint32_t quant_matrices[16][64], int q)
+static int read_dct_coeffs(GetBitContext *gb, int32_t block[64], const uint8_t *scan,
+ const int32_t quant_matrices[16][64], int q)
{
int coef_list[128];
int mode_list[128];
@@ -590,7 +600,7 @@ static int read_dct_coeffs(GetBitContext *gb, DCTELEM block[64], const uint8_t *
int coef_count = 0;
int coef_idx[64];
int quant_idx;
- const uint32_t *quant;
+ const int32_t *quant;
coef_list[list_end] = 4; mode_list[list_end++] = 0;
coef_list[list_end] = 24; mode_list[list_end++] = 0;
@@ -623,7 +633,6 @@ static int read_dct_coeffs(GetBitContext *gb, DCTELEM block[64], const uint8_t *
coef_list[--list_start] = ccoef;
mode_list[ list_start] = 3;
} else {
- int t;
if (!bits) {
t = 1 - (get_bits1(gb) << 1);
} else {
@@ -791,6 +800,7 @@ static int binkb_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx,
const uint8_t *scan;
int xoff, yoff;
LOCAL_ALIGNED_16(DCTELEM, block, [64]);
+ LOCAL_ALIGNED_16(int32_t, dctblock, [64]);
int coordmap[64];
int ybias = is_key ? -15 : 0;
int qp;
@@ -845,11 +855,11 @@ static int binkb_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx,
dst[coordmap[*scan++]] = binkb_get_value(c, BINKB_SRC_COLORS);
break;
case 2:
- c->dsp.clear_block(block);
- block[0] = binkb_get_value(c, BINKB_SRC_INTRA_DC);
+ memset(dctblock, 0, sizeof(*dctblock) * 64);
+ dctblock[0] = binkb_get_value(c, BINKB_SRC_INTRA_DC);
qp = binkb_get_value(c, BINKB_SRC_INTRA_Q);
- read_dct_coeffs(gb, block, c->scantable.permutated, binkb_intra_quant, qp);
- c->dsp.idct_put(dst, stride, block);
+ read_dct_coeffs(gb, dctblock, bink_scan, binkb_intra_quant, qp);
+ c->bdsp.idct_put(dst, stride, dctblock);
break;
case 3:
xoff = binkb_get_value(c, BINKB_SRC_X_OFF);
@@ -878,11 +888,11 @@ static int binkb_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx,
} else {
put_pixels8x8_overlapped(dst, ref, stride);
}
- c->dsp.clear_block(block);
- block[0] = binkb_get_value(c, BINKB_SRC_INTER_DC);
+ memset(dctblock, 0, sizeof(*dctblock) * 64);
+ dctblock[0] = binkb_get_value(c, BINKB_SRC_INTER_DC);
qp = binkb_get_value(c, BINKB_SRC_INTER_Q);
- read_dct_coeffs(gb, block, c->scantable.permutated, binkb_inter_quant, qp);
- c->dsp.idct_add(dst, stride, block);
+ read_dct_coeffs(gb, dctblock, bink_scan, binkb_inter_quant, qp);
+ c->bdsp.idct_add(dst, stride, dctblock);
break;
case 5:
v = binkb_get_value(c, BINKB_SRC_COLORS);
@@ -937,6 +947,7 @@ static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx,
int xoff, yoff;
LOCAL_ALIGNED_16(DCTELEM, block, [64]);
LOCAL_ALIGNED_16(uint8_t, ublock, [64]);
+ LOCAL_ALIGNED_16(int32_t, dctblock, [64]);
int coordmap[64];
const int stride = c->pic.linesize[plane_idx];
@@ -948,8 +959,9 @@ static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx,
for (i = 0; i < BINK_NB_SRC; i++)
read_bundle(gb, c, i);
- ref_start = c->last.data[plane_idx];
- ref_end = c->last.data[plane_idx]
+ ref_start = c->last.data[plane_idx] ? c->last.data[plane_idx]
+ : c->pic.data[plane_idx];
+ ref_end = ref_start
+ (bw - 1 + c->last.linesize[plane_idx] * (bh - 1)) * 8;
for (i = 0; i < 64; i++)
@@ -978,7 +990,8 @@ static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx,
if (by == bh)
break;
dst = c->pic.data[plane_idx] + 8*by*stride;
- prev = c->last.data[plane_idx] + 8*by*stride;
+ prev = (c->last.data[plane_idx] ? c->last.data[plane_idx]
+ : c->pic.data[plane_idx]) + 8*by*stride;
for (bx = 0; bx < bw; bx++, dst += 8, prev += 8) {
blk = get_value(c, BINK_SRC_BLOCK_TYPES);
// 16x16 block type on odd line means part of the already decoded block, so skip it
@@ -1019,11 +1032,10 @@ static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx,
ublock[*scan++] = get_value(c, BINK_SRC_COLORS);
break;
case INTRA_BLOCK:
- c->dsp.clear_block(block);
- block[0] = get_value(c, BINK_SRC_INTRA_DC);
- read_dct_coeffs(gb, block, c->scantable.permutated, bink_intra_quant, -1);
- c->dsp.idct(block);
- c->dsp.put_pixels_nonclamped(block, ublock, 8);
+ memset(dctblock, 0, sizeof(*dctblock) * 64);
+ dctblock[0] = get_value(c, BINK_SRC_INTRA_DC);
+ read_dct_coeffs(gb, dctblock, bink_scan, bink_intra_quant, -1);
+ c->bdsp.idct_put(ublock, 8, dctblock);
break;
case FILL_BLOCK:
v = get_value(c, BINK_SRC_COLORS);
@@ -1048,7 +1060,7 @@ static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx,
return -1;
}
if (blk != FILL_BLOCK)
- c->dsp.scale_block(ublock, dst, stride);
+ c->bdsp.scale_block(ublock, dst, stride);
bx++;
dst += 8;
prev += 8;
@@ -1103,10 +1115,10 @@ static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx,
c->dsp.add_pixels8(dst, block, stride);
break;
case INTRA_BLOCK:
- c->dsp.clear_block(block);
- block[0] = get_value(c, BINK_SRC_INTRA_DC);
- read_dct_coeffs(gb, block, c->scantable.permutated, bink_intra_quant, -1);
- c->dsp.idct_put(dst, stride, block);
+ memset(dctblock, 0, sizeof(*dctblock) * 64);
+ dctblock[0] = get_value(c, BINK_SRC_INTRA_DC);
+ read_dct_coeffs(gb, dctblock, bink_scan, bink_intra_quant, -1);
+ c->bdsp.idct_put(dst, stride, dctblock);
break;
case FILL_BLOCK:
v = get_value(c, BINK_SRC_COLORS);
@@ -1117,10 +1129,10 @@ static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx,
yoff = get_value(c, BINK_SRC_Y_OFF);
ref = prev + xoff + yoff * stride;
c->dsp.put_pixels_tab[1][0](dst, ref, stride, 8);
- c->dsp.clear_block(block);
- block[0] = get_value(c, BINK_SRC_INTER_DC);
- read_dct_coeffs(gb, block, c->scantable.permutated, bink_inter_quant, -1);
- c->dsp.idct_add(dst, stride, block);
+ memset(dctblock, 0, sizeof(*dctblock) * 64);
+ dctblock[0] = get_value(c, BINK_SRC_INTER_DC);
+ read_dct_coeffs(gb, dctblock, bink_scan, bink_inter_quant, -1);
+ c->bdsp.idct_add(dst, stride, dctblock);
break;
case PATTERN_BLOCK:
for (i = 0; i < 2; i++)
@@ -1288,7 +1300,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
avctx->idct_algo = FF_IDCT_BINK;
dsputil_init(&c->dsp, avctx);
- ff_init_scantable(c->dsp.idct_permutation, &c->scantable, bink_scan);
+ ff_binkdsp_init(&c->bdsp);
init_bundles(c);
@@ -1316,13 +1328,12 @@ static av_cold int decode_end(AVCodecContext *avctx)
}
AVCodec ff_bink_decoder = {
- "binkvideo",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_BINKVIDEO,
- sizeof(BinkContext),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
+ .name = "binkvideo",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_BINKVIDEO,
+ .priv_data_size = sizeof(BinkContext),
+ .init = decode_init,
+ .close = decode_end,
+ .decode = decode_frame,
.long_name = NULL_IF_CONFIG_SMALL("Bink video"),
};
diff --git a/libavcodec/binkaudio.c b/libavcodec/binkaudio.c
index a05b0b56b2..2d06aaa9e9 100644
--- a/libavcodec/binkaudio.c
+++ b/libavcodec/binkaudio.c
@@ -3,20 +3,20 @@
* Copyright (c) 2007-2011 Peter Ross (pross@xvid.org)
* Copyright (c) 2009 Daniel Verkamp (daniel@drv.nu)
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -90,7 +90,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
return -1;
}
- s->version_b = avctx->codec_tag == MKTAG('B','I','K','b');
+ s->version_b = avctx->extradata && avctx->extradata[3] == 'b';
if (avctx->codec->id == CODEC_ID_BINKAUDIO_RDFT) {
// audio is already interleaved for the RDFT format variant
@@ -292,25 +292,23 @@ static int decode_frame(AVCodecContext *avctx,
}
AVCodec ff_binkaudio_rdft_decoder = {
- "binkaudio_rdft",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_BINKAUDIO_RDFT,
- sizeof(BinkAudioContext),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
+ .name = "binkaudio_rdft",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_BINKAUDIO_RDFT,
+ .priv_data_size = sizeof(BinkAudioContext),
+ .init = decode_init,
+ .close = decode_end,
+ .decode = decode_frame,
.long_name = NULL_IF_CONFIG_SMALL("Bink Audio (RDFT)")
};
AVCodec ff_binkaudio_dct_decoder = {
- "binkaudio_dct",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_BINKAUDIO_DCT,
- sizeof(BinkAudioContext),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
+ .name = "binkaudio_dct",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_BINKAUDIO_DCT,
+ .priv_data_size = sizeof(BinkAudioContext),
+ .init = decode_init,
+ .close = decode_end,
+ .decode = decode_frame,
.long_name = NULL_IF_CONFIG_SMALL("Bink Audio (DCT)")
};
diff --git a/libavcodec/binkdata.h b/libavcodec/binkdata.h
index db289ad3a1..b9dc1f2639 100644
--- a/libavcodec/binkdata.h
+++ b/libavcodec/binkdata.h
@@ -2,20 +2,20 @@
* Bink video decoder
* Copyright (C) 2009 Kostya Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -285,7 +285,7 @@ static const uint8_t bink_patterns[16][64] = {
}
};
-static const uint32_t bink_intra_quant[16][64] = {
+static const int32_t bink_intra_quant[16][64] = {
{
0x010000, 0x016315, 0x01E83D, 0x02A535, 0x014E7B, 0x016577, 0x02F1E6, 0x02724C,
0x010000, 0x00EEDA, 0x024102, 0x017F9B, 0x00BE80, 0x00611E, 0x01083C, 0x00A552,
@@ -448,7 +448,7 @@ static const uint32_t bink_intra_quant[16][64] = {
},
};
-static const uint32_t bink_inter_quant[16][64] = {
+static const int32_t bink_inter_quant[16][64] = {
{
0x010000, 0x017946, 0x01A5A9, 0x0248DC, 0x016363, 0x0152A7, 0x0243EC, 0x0209EA,
0x012000, 0x00E248, 0x01BBDA, 0x015CBC, 0x00A486, 0x0053E0, 0x00F036, 0x008095,
diff --git a/libavcodec/binkidct.c b/libavcodec/binkdsp.c
index 2326a616d5..c751743aa8 100644
--- a/libavcodec/binkidct.c
+++ b/libavcodec/binkdsp.c
@@ -1,30 +1,31 @@
/*
- * Bink IDCT algorithm
+ * Bink DSP routines
* Copyright (c) 2009 Kostya Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
- * Bink IDCT algorithm
+ * Bink DSP routines
*/
#include "dsputil.h"
+#include "binkdsp.h"
#define A1 2896 /* (1/sqrt(2))<<12 */
#define A2 2217
@@ -62,7 +63,7 @@
#define MUNGE_ROW(x) (((x) + 0x7F)>>8)
#define IDCT_ROW(dest,src) IDCT_TRANSFORM(dest,0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7,MUNGE_ROW,src)
-static inline void bink_idct_col(int *dest, const DCTELEM *src)
+static inline void bink_idct_col(int *dest, const int32_t *src)
{
if ((src[8]|src[16]|src[24]|src[32]|src[40]|src[48]|src[56])==0) {
dest[0] =
@@ -78,7 +79,7 @@ static inline void bink_idct_col(int *dest, const DCTELEM *src)
}
}
-void ff_bink_idct_c(DCTELEM *block)
+static void bink_idct_c(int32_t *block)
{
int i;
int temp[64];
@@ -90,17 +91,17 @@ void ff_bink_idct_c(DCTELEM *block)
}
}
-void ff_bink_idct_add_c(uint8_t *dest, int linesize, DCTELEM *block)
+static void bink_idct_add_c(uint8_t *dest, int linesize, int32_t *block)
{
int i, j;
- ff_bink_idct_c(block);
+ bink_idct_c(block);
for (i = 0; i < 8; i++, dest += linesize, block += 8)
for (j = 0; j < 8; j++)
dest[j] += block[j];
}
-void ff_bink_idct_put_c(uint8_t *dest, int linesize, DCTELEM *block)
+static void bink_idct_put_c(uint8_t *dest, int linesize, int32_t *block)
{
int i;
int temp[64];
@@ -110,3 +111,26 @@ void ff_bink_idct_put_c(uint8_t *dest, int linesize, DCTELEM *block)
IDCT_ROW( (&dest[i*linesize]), (&temp[8*i]) );
}
}
+
+static void scale_block_c(const uint8_t src[64]/*align 8*/, uint8_t *dst/*align 8*/, int linesize)
+{
+ int i, j;
+ uint16_t *dst1 = (uint16_t *) dst;
+ uint16_t *dst2 = (uint16_t *)(dst + linesize);
+
+ for (j = 0; j < 8; j++) {
+ for (i = 0; i < 8; i++) {
+ dst1[i] = dst2[i] = src[i] * 0x0101;
+ }
+ src += 8;
+ dst1 += linesize;
+ dst2 += linesize;
+ }
+}
+
+void ff_binkdsp_init(BinkDSPContext *c)
+{
+ c->idct_add = bink_idct_add_c;
+ c->idct_put = bink_idct_put_c;
+ c->scale_block = scale_block_c;
+}
diff --git a/libavcodec/binkdsp.h b/libavcodec/binkdsp.h
new file mode 100644
index 0000000000..d105f717e9
--- /dev/null
+++ b/libavcodec/binkdsp.h
@@ -0,0 +1,40 @@
+/*
+ * Bink DSP routines
+ * Copyright (c) 2009 Kostya Shishkov
+ *
+ * This file is part of Libav.
+ *
+ * Libav 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.
+ *
+ * Libav 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * Bink DSP routines
+ */
+
+#ifndef AVCODEC_BINKDSP_H
+#define AVCODEC_BINKDSP_H
+
+#include "dsputil.h"
+
+typedef struct BinkDSPContext {
+ void (*idct_put)(uint8_t *dest/*align 8*/, int line_size, int32_t *block/*align 16*/);
+ void (*idct_add)(uint8_t *dest/*align 8*/, int line_size, int32_t *block/*align 16*/);
+ void (*scale_block)(const uint8_t src[64]/*align 8*/, uint8_t *dst/*align 8*/, int linesize);
+} BinkDSPContext;
+
+void ff_binkdsp_init(BinkDSPContext *c);
+
+#endif /* AVCODEC_BINKDSP_H */
diff --git a/libavcodec/bintext.c b/libavcodec/bintext.c
new file mode 100644
index 0000000000..947be396b8
--- /dev/null
+++ b/libavcodec/bintext.c
@@ -0,0 +1,250 @@
+/*
+ * Binary text decoder
+ * eXtended BINary text (XBIN) decoder
+ * iCEDraw File decoder
+ * Copyright (c) 2010 Peter Ross (pross@xvid.org)
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * Binary text decoder
+ * eXtended BINary text (XBIN) decoder
+ * iCEDraw File decoder
+ */
+
+#include "libavutil/intreadwrite.h"
+#include "avcodec.h"
+#include "cga_data.h"
+#include "bintext.h"
+
+typedef struct XbinContext {
+ AVFrame frame;
+ int palette[16];
+ int flags;
+ int font_height;
+ const uint8_t *font;
+ int x, y;
+} XbinContext;
+
+static av_cold int decode_init(AVCodecContext *avctx)
+{
+ XbinContext *s = avctx->priv_data;
+ uint8_t *p;
+ int i;
+
+ avctx->pix_fmt = PIX_FMT_PAL8;
+ p = avctx->extradata;
+ if (p) {
+ s->font_height = p[0];
+ s->flags = p[1];
+ p += 2;
+ } else {
+ s->font_height = 8;
+ s->flags = 0;
+ }
+
+ if ((s->flags & BINTEXT_PALETTE)) {
+ for (i = 0; i < 16; i++) {
+ s->palette[i] = 0xFF000000 | (AV_RB24(p) << 2);
+ p += 3;
+ }
+ } else {
+ for (i = 0; i < 16; i++)
+ s->palette[i] = 0xFF000000 | ff_cga_palette[i];
+ }
+
+ if ((s->flags & BINTEXT_FONT)) {
+ s->font = p;
+ } else {
+ switch(s->font_height) {
+ default:
+ av_log(avctx, AV_LOG_WARNING, "font height %i not supported\n", s->font_height);
+ s->font_height = 8;
+ case 8:
+ s->font = ff_cga_font;
+ break;
+ case 16:
+ s->font = ff_vga16_font;
+ break;
+ }
+ }
+
+ return 0;
+}
+
+#define DEFAULT_BG_COLOR 0
+static void hscroll(AVCodecContext *avctx)
+{
+ XbinContext *s = avctx->priv_data;
+ if (s->y < avctx->height - s->font_height) {
+ s->y += s->font_height;
+ } else {
+ memmove(s->frame.data[0], s->frame.data[0] + s->font_height*s->frame.linesize[0],
+ (avctx->height - s->font_height)*s->frame.linesize[0]);
+ memset(s->frame.data[0] + (avctx->height - s->font_height)*s->frame.linesize[0],
+ DEFAULT_BG_COLOR, s->font_height * s->frame.linesize[0]);
+ }
+}
+
+#define FONT_WIDTH 8
+
+/**
+ * Draw character to screen
+ */
+static void draw_char(AVCodecContext *avctx, int c, int a)
+{
+ XbinContext *s = avctx->priv_data;
+ if (s->y > avctx->height - s->font_height)
+ return;
+ ff_draw_pc_font(s->frame.data[0] + s->y * s->frame.linesize[0] + s->x,
+ s->frame.linesize[0], s->font, s->font_height, c,
+ a & 0x0F, a >> 4);
+ s->x += FONT_WIDTH;
+ if (s->x > avctx->width - FONT_WIDTH) {
+ s->x = 0;
+ s->y += s->font_height;
+ }
+}
+
+static int decode_frame(AVCodecContext *avctx,
+ void *data, int *data_size,
+ AVPacket *avpkt)
+{
+ XbinContext *s = avctx->priv_data;
+ const uint8_t *buf = avpkt->data;
+ int buf_size = avpkt->size;
+ const uint8_t *buf_end = buf+buf_size;
+
+ s->x = s->y = 0;
+ s->frame.buffer_hints = FF_BUFFER_HINTS_VALID |
+ FF_BUFFER_HINTS_PRESERVE |
+ FF_BUFFER_HINTS_REUSABLE;
+ if (avctx->reget_buffer(avctx, &s->frame)) {
+ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
+ return -1;
+ }
+ s->frame.pict_type = FF_I_TYPE;
+ s->frame.palette_has_changed = 1;
+ memcpy(s->frame.data[1], s->palette, 16 * 4);
+
+ if (avctx->codec_id == CODEC_ID_XBIN) {
+ while (buf + 2 < buf_end) {
+ int i,c,a;
+ int type = *buf >> 6;
+ int count = (*buf & 0x3F) + 1;
+ buf++;
+ switch (type) {
+ case 0: //no compression
+ for (i = 0; i < count && buf + 1 < buf_end; i++) {
+ draw_char(avctx, buf[0], buf[1]);
+ buf += 2;
+ }
+ break;
+ case 1: //character compression
+ c = *buf++;
+ for (i = 0; i < count && buf < buf_end; i++)
+ draw_char(avctx, c, *buf++);
+ break;
+ case 2: //attribute compression
+ a = *buf++;
+ for (i = 0; i < count && buf < buf_end; i++)
+ draw_char(avctx, *buf++, a);
+ break;
+ case 3: //character/attribute compression
+ c = *buf++;
+ a = *buf++;
+ for (i = 0; i < count && buf < buf_end; i++)
+ draw_char(avctx, c, a);
+ break;
+ }
+ }
+ } else if (avctx->codec_id == CODEC_ID_IDF) {
+ while (buf + 2 < buf_end) {
+ if (AV_RL16(buf) == 1) {
+ int i;
+ if (buf + 6 > buf_end)
+ break;
+ for (i = 0; i < buf[2]; i++)
+ draw_char(avctx, buf[4], buf[5]);
+ buf += 6;
+ } else {
+ draw_char(avctx, buf[0], buf[1]);
+ buf += 2;
+ }
+ }
+ } else {
+ while (buf + 1 < buf_end) {
+ draw_char(avctx, buf[0], buf[1]);
+ buf += 2;
+ }
+ }
+
+ *data_size = sizeof(AVFrame);
+ *(AVFrame*)data = s->frame;
+ return buf_size;
+}
+
+static av_cold int decode_end(AVCodecContext *avctx)
+{
+ XbinContext *s = avctx->priv_data;
+
+ if (s->frame.data[0])
+ avctx->release_buffer(avctx, &s->frame);
+
+ return 0;
+}
+
+AVCodec ff_bintext_decoder = {
+ "bintext",
+ AVMEDIA_TYPE_VIDEO,
+ CODEC_ID_BINTEXT,
+ sizeof(XbinContext),
+ decode_init,
+ NULL,
+ decode_end,
+ decode_frame,
+ CODEC_CAP_DR1,
+ .long_name = NULL_IF_CONFIG_SMALL("Binary text"),
+};
+
+AVCodec ff_xbin_decoder = {
+ "xbin",
+ AVMEDIA_TYPE_VIDEO,
+ CODEC_ID_XBIN,
+ sizeof(XbinContext),
+ decode_init,
+ NULL,
+ decode_end,
+ decode_frame,
+ CODEC_CAP_DR1,
+ .long_name = NULL_IF_CONFIG_SMALL("eXtended BINary text"),
+};
+
+AVCodec ff_idf_decoder = {
+ "idf",
+ AVMEDIA_TYPE_VIDEO,
+ CODEC_ID_IDF,
+ sizeof(XbinContext),
+ decode_init,
+ NULL,
+ decode_end,
+ decode_frame,
+ CODEC_CAP_DR1,
+ .long_name = NULL_IF_CONFIG_SMALL("iCEDraw text"),
+};
diff --git a/libavcodec/bintext.h b/libavcodec/bintext.h
new file mode 100644
index 0000000000..ea834a00e3
--- /dev/null
+++ b/libavcodec/bintext.h
@@ -0,0 +1,37 @@
+/*
+ * Binary text decoder
+ * Copyright (c) 2010 Peter Ross (pross@xvid.org)
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * Binary text decoder
+ */
+
+#ifndef AVCODEC_BINTEXT_H
+#define AVCODEC_BINTEXT_H
+
+/* flag values passed between avformat and avcodec;
+ * while these are identical to the XBIN flags, they are are also used
+ * for the BINTEXT and IDF decoders.
+ */
+#define BINTEXT_PALETTE 0x1
+#define BINTEXT_FONT 0x2
+
+#endif /* AVCODEC_BINTEXT_H */
diff --git a/libavcodec/bit_depth_template.c b/libavcodec/bit_depth_template.c
index c0a6eafe89..9071ec2a35 100644
--- a/libavcodec/bit_depth_template.c
+++ b/libavcodec/bit_depth_template.c
@@ -43,15 +43,6 @@
# undef PIXEL_SPLAT_X4
#else
# define AVCODEC_H264_HIGH_DEPTH_H
-# define CLIP_PIXEL(depth)\
- static inline uint16_t av_clip_pixel_ ## depth (int p)\
- {\
- const int pixel_max = (1 << depth)-1;\
- return (p & ~pixel_max) ? (-p)>>31 & pixel_max : p;\
- }
-
-CLIP_PIXEL( 9)
-CLIP_PIXEL(10)
#endif
#if BIT_DEPTH > 8
@@ -70,6 +61,9 @@ CLIP_PIXEL(10)
# define AV_WN4P AV_WN64
# define AV_WN4PA AV_WN64A
# define PIXEL_SPLAT_X4(x) ((x)*0x0001000100010001ULL)
+
+# define av_clip_pixel(a) av_clip_uintp2(a, BIT_DEPTH)
+# define CLIP(a) av_clip_uintp2(a, BIT_DEPTH)
#else
# define pixel uint8_t
# define pixel2 uint16_t
@@ -86,21 +80,12 @@ CLIP_PIXEL(10)
# define AV_WN4P AV_WN32
# define AV_WN4PA AV_WN32A
# define PIXEL_SPLAT_X4(x) ((x)*0x01010101U)
-#endif
-#if BIT_DEPTH == 8
# define av_clip_pixel(a) av_clip_uint8(a)
# define CLIP(a) cm[a]
-# define FUNC(a) a ## _8
-# define FUNCC(a) a ## _8_c
-#elif BIT_DEPTH == 9
-# define av_clip_pixel(a) av_clip_pixel_9(a)
-# define CLIP(a) av_clip_pixel_9(a)
-# define FUNC(a) a ## _9
-# define FUNCC(a) a ## _9_c
-#elif BIT_DEPTH == 10
-# define av_clip_pixel(a) av_clip_pixel_10(a)
-# define CLIP(a) av_clip_pixel_10(a)
-# define FUNC(a) a ## _10
-# define FUNCC(a) a ## _10_c
#endif
+
+#define FUNC3(a, b, c) a ## _ ## b ## c
+#define FUNC2(a, b, c) FUNC3(a, b, c)
+#define FUNC(a) FUNC2(a, BIT_DEPTH,)
+#define FUNCC(a) FUNC2(a, BIT_DEPTH, _c)
diff --git a/libavcodec/bitstream.c b/libavcodec/bitstream.c
index 70717883c1..d4d7623bc3 100644
--- a/libavcodec/bitstream.c
+++ b/libavcodec/bitstream.c
@@ -6,20 +6,20 @@
*
* alternative bitstream reader & writer by Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -41,7 +41,7 @@ const uint8_t ff_log2_run[41]={
24,
};
-void align_put_bits(PutBitContext *s)
+void avpriv_align_put_bits(PutBitContext *s)
{
put_bits(s,s->bit_left & 7,0);
}
@@ -56,7 +56,7 @@ void ff_put_string(PutBitContext *pb, const char *string, int terminate_string)
put_bits(pb, 8, 0);
}
-void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length)
+void avpriv_copy_bits(PutBitContext *pb, const uint8_t *src, int length)
{
int words= length>>4;
int bits= length&15;
@@ -105,8 +105,8 @@ static int alloc_table(VLC *vlc, int size, int use_static)
if(use_static)
abort(); //cant do anything, init_vlc() is used with too little memory
vlc->table_allocated += (1 << vlc->bits);
- vlc->table = av_realloc(vlc->table,
- sizeof(VLC_TYPE) * 2 * vlc->table_allocated);
+ vlc->table = av_realloc_f(vlc->table,
+ vlc->table_allocated, sizeof(VLC_TYPE) * 2);
if (!vlc->table)
return -1;
}
diff --git a/libavcodec/bitstream_filter.c b/libavcodec/bitstream_filter.c
index b803ca4ef9..1a6ba396d2 100644
--- a/libavcodec/bitstream_filter.c
+++ b/libavcodec/bitstream_filter.c
@@ -1,20 +1,20 @@
/*
* copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/bmp.c b/libavcodec/bmp.c
index b7fee130bc..0b387249e6 100644
--- a/libavcodec/bmp.c
+++ b/libavcodec/bmp.c
@@ -2,20 +2,20 @@
* BMP image format decoder
* Copyright (c) 2005 Mans Rullgard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -245,7 +245,7 @@ static int bmp_decode_frame(AVCodecContext *avctx,
buf = buf0 + 14 + ihsize; //palette location
if((hsize-ihsize-14) < (colors << 2)){ // OS/2 bitmap, 3 bytes per palette entry
for(i = 0; i < colors; i++)
- ((uint32_t*)p->data[1])[i] = bytestream_get_le24(&buf);
+ ((uint32_t*)p->data[1])[i] = (0xff<<24) | bytestream_get_le24(&buf);
}else{
for(i = 0; i < colors; i++)
((uint32_t*)p->data[1])[i] = bytestream_get_le32(&buf);
@@ -336,14 +336,13 @@ static av_cold int bmp_decode_end(AVCodecContext *avctx)
}
AVCodec ff_bmp_decoder = {
- "bmp",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_BMP,
- sizeof(BMPContext),
- bmp_decode_init,
- NULL,
- bmp_decode_end,
- bmp_decode_frame,
- CODEC_CAP_DR1,
+ .name = "bmp",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_BMP,
+ .priv_data_size = sizeof(BMPContext),
+ .init = bmp_decode_init,
+ .close = bmp_decode_end,
+ .decode = bmp_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("BMP image"),
};
diff --git a/libavcodec/bmp.h b/libavcodec/bmp.h
index ab11523379..b24a1faf00 100644
--- a/libavcodec/bmp.h
+++ b/libavcodec/bmp.h
@@ -2,20 +2,20 @@
* internals for BMP codecs
* Copyright (c) 2005 Mans Rullgard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/bmpenc.c b/libavcodec/bmpenc.c
index b3630f094c..63c3b729a9 100644
--- a/libavcodec/bmpenc.c
+++ b/libavcodec/bmpenc.c
@@ -3,20 +3,20 @@
* Copyright (c) 2006, 2007 Michel Bardiaux
* Copyright (c) 2009 Daniel Verkamp <daniel at drv.nu>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -150,13 +150,12 @@ static int bmp_encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_s
}
AVCodec ff_bmp_encoder = {
- "bmp",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_BMP,
- sizeof(BMPContext),
- bmp_encode_init,
- bmp_encode_frame,
- NULL, //encode_end,
+ .name = "bmp",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_BMP,
+ .priv_data_size = sizeof(BMPContext),
+ .init = bmp_encode_init,
+ .encode = bmp_encode_frame,
.pix_fmts = (const enum PixelFormat[]){
PIX_FMT_BGR24,
PIX_FMT_RGB555, PIX_FMT_RGB565,
diff --git a/libavcodec/bytestream.h b/libavcodec/bytestream.h
index 98f00879be..b56f6ce743 100644
--- a/libavcodec/bytestream.h
+++ b/libavcodec/bytestream.h
@@ -2,20 +2,20 @@
* Bytestream functions
* copyright (c) 2006 Baptiste Coudurier <baptiste.coudurier@free.fr>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/c93.c b/libavcodec/c93.c
index 0b6eb02614..1f4ed1fdf0 100644
--- a/libavcodec/c93.c
+++ b/libavcodec/c93.c
@@ -2,20 +2,20 @@
* Interplay C93 video decoder
* Copyright (c) 2007 Anssi Hannula <anssi.hannula@gmail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -47,6 +47,10 @@ typedef enum {
static av_cold int decode_init(AVCodecContext *avctx)
{
+ C93DecoderContext * const c93 = avctx->priv_data;
+
+ avcodec_get_frame_defaults(&c93->pictures[0]);
+ avcodec_get_frame_defaults(&c93->pictures[1]);
avctx->pix_fmt = PIX_FMT_PAL8;
return 0;
}
@@ -243,14 +247,13 @@ static int decode_frame(AVCodecContext *avctx, void *data,
}
AVCodec ff_c93_decoder = {
- "c93",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_C93,
- sizeof(C93DecoderContext),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- CODEC_CAP_DR1,
+ .name = "c93",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_C93,
+ .priv_data_size = sizeof(C93DecoderContext),
+ .init = decode_init,
+ .close = decode_end,
+ .decode = decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Interplay C93"),
};
diff --git a/libavcodec/cabac.c b/libavcodec/cabac.c
index 691beb0ae3..e03043f91f 100644
--- a/libavcodec/cabac.c
+++ b/libavcodec/cabac.c
@@ -2,20 +2,20 @@
* H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder
* Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -75,18 +75,7 @@ static const uint8_t lps_state[64]= {
33,33,34,34,35,35,35,36,
36,36,37,37,37,38,38,63,
};
-#if 0
-const uint8_t ff_h264_norm_shift_old[128]= {
- 7,6,5,5,4,4,4,4,3,3,3,3,3,3,3,3,
- 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
- 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
- 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-};
-#endif
+
const uint8_t ff_h264_norm_shift[512]= {
9,8,7,7,6,6,6,6,5,5,5,5,5,5,5,5,
4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
@@ -161,10 +150,14 @@ void ff_init_cabac_states(CABACContext *c){
ff_h264_mps_state[2*i+1]= 2*mps_state[i]+1;
if( i ){
+ ff_h264_lps_state[2*i+0]=
ff_h264_mlps_state[128-2*i-1]= 2*lps_state[i]+0;
+ ff_h264_lps_state[2*i+1]=
ff_h264_mlps_state[128-2*i-2]= 2*lps_state[i]+1;
}else{
+ ff_h264_lps_state[2*i+0]=
ff_h264_mlps_state[128-2*i-1]= 1;
+ ff_h264_lps_state[2*i+1]=
ff_h264_mlps_state[128-2*i-2]= 0;
}
}
@@ -177,6 +170,140 @@ void ff_init_cabac_states(CABACContext *c){
#include "avcodec.h"
#include "cabac.h"
+static void put_cabac(CABACContext *c, uint8_t * const state, int bit){
+ int RangeLPS= ff_h264_lps_range[2*(c->range&0xC0) + *state];
+
+ if(bit == ((*state)&1)){
+ c->range -= RangeLPS;
+ *state= ff_h264_mps_state[*state];
+ }else{
+ c->low += c->range - RangeLPS;
+ c->range = RangeLPS;
+ *state= ff_h264_lps_state[*state];
+ }
+
+ renorm_cabac_encoder(c);
+
+#ifdef STRICT_LIMITS
+ c->symCount++;
+#endif
+}
+
+/**
+ * @param bit 0 -> write zero bit, !=0 write one bit
+ */
+static void put_cabac_bypass(CABACContext *c, int bit){
+ c->low += c->low;
+
+ if(bit){
+ c->low += c->range;
+ }
+//FIXME optimize
+ if(c->low<0x200){
+ put_cabac_bit(c, 0);
+ }else if(c->low<0x400){
+ c->outstanding_count++;
+ c->low -= 0x200;
+ }else{
+ put_cabac_bit(c, 1);
+ c->low -= 0x400;
+ }
+
+#ifdef STRICT_LIMITS
+ c->symCount++;
+#endif
+}
+
+/**
+ *
+ * @return the number of bytes written
+ */
+static int put_cabac_terminate(CABACContext *c, int bit){
+ c->range -= 2;
+
+ if(!bit){
+ renorm_cabac_encoder(c);
+ }else{
+ c->low += c->range;
+ c->range= 2;
+
+ renorm_cabac_encoder(c);
+
+ assert(c->low <= 0x1FF);
+ put_cabac_bit(c, c->low>>9);
+ put_bits(&c->pb, 2, ((c->low>>7)&3)|1);
+
+ flush_put_bits(&c->pb); //FIXME FIXME FIXME XXX wrong
+ }
+
+#ifdef STRICT_LIMITS
+ c->symCount++;
+#endif
+
+ return (put_bits_count(&c->pb)+7)>>3;
+}
+
+/**
+ * put (truncated) unary binarization.
+ */
+static void put_cabac_u(CABACContext *c, uint8_t * state, int v, int max, int max_index, int truncated){
+ int i;
+
+ assert(v <= max);
+
+ for(i=0; i<v; i++){
+ put_cabac(c, state, 1);
+ if(i < max_index) state++;
+ }
+ if(truncated==0 || v<max)
+ put_cabac(c, state, 0);
+}
+
+/**
+ * put unary exp golomb k-th order binarization.
+ */
+static void put_cabac_ueg(CABACContext *c, uint8_t * state, int v, int max, int is_signed, int k, int max_index){
+ int i;
+
+ if(v==0)
+ put_cabac(c, state, 0);
+ else{
+ const int sign= v < 0;
+
+ if(is_signed) v= FFABS(v);
+
+ if(v<max){
+ for(i=0; i<v; i++){
+ put_cabac(c, state, 1);
+ if(i < max_index) state++;
+ }
+
+ put_cabac(c, state, 0);
+ }else{
+ int m= 1<<k;
+
+ for(i=0; i<max; i++){
+ put_cabac(c, state, 1);
+ if(i < max_index) state++;
+ }
+
+ v -= max;
+ while(v >= m){ //FIXME optimize
+ put_cabac_bypass(c, 1);
+ v-= m;
+ m+= m;
+ }
+ put_cabac_bypass(c, 0);
+ while(m>>=1){
+ put_cabac_bypass(c, v&m);
+ }
+ }
+
+ if(is_signed)
+ put_cabac_bypass(c, sign);
+ }
+}
+
int main(void){
CABACContext c;
uint8_t b[9*SIZE];
@@ -190,7 +317,8 @@ int main(void){
ff_init_cabac_states(&c);
for(i=0; i<SIZE; i++){
- r[i] = av_lfg_get(&prng) % 7;
+ if(2*i<SIZE) r[i] = av_lfg_get(&prng) % 7;
+ else r[i] = (i>>8)&1;
}
for(i=0; i<SIZE; i++){
@@ -205,6 +333,7 @@ START_TIMER
STOP_TIMER("put_cabac")
}
+#if 0
for(i=0; i<SIZE; i++){
START_TIMER
put_cabac_u(&c, state, r[i], 6, 3, i&1);
@@ -216,7 +345,7 @@ START_TIMER
put_cabac_ueg(&c, state, r[i], 3, 0, 1, 2);
STOP_TIMER("put_cabac_ueg")
}
-
+#endif
put_cabac_terminate(&c, 1);
ff_init_cabac_decoder(&c, b, SIZE);
diff --git a/libavcodec/cabac.h b/libavcodec/cabac.h
index 57d1d70d29..ed156e6fca 100644
--- a/libavcodec/cabac.h
+++ b/libavcodec/cabac.h
@@ -2,20 +2,20 @@
* H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder
* Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -90,178 +90,6 @@ static inline void renorm_cabac_encoder(CABACContext *c){
}
}
-#ifdef TEST
-static void put_cabac(CABACContext *c, uint8_t * const state, int bit){
- int RangeLPS= ff_h264_lps_range[2*(c->range&0xC0) + *state];
-
- if(bit == ((*state)&1)){
- c->range -= RangeLPS;
- *state= ff_h264_mps_state[*state];
- }else{
- c->low += c->range - RangeLPS;
- c->range = RangeLPS;
- *state= ff_h264_lps_state[*state];
- }
-
- renorm_cabac_encoder(c);
-
-#ifdef STRICT_LIMITS
- c->symCount++;
-#endif
-}
-
-static void put_cabac_static(CABACContext *c, int RangeLPS, int bit){
- assert(c->range > RangeLPS);
-
- if(!bit){
- c->range -= RangeLPS;
- }else{
- c->low += c->range - RangeLPS;
- c->range = RangeLPS;
- }
-
- renorm_cabac_encoder(c);
-
-#ifdef STRICT_LIMITS
- c->symCount++;
-#endif
-}
-
-/**
- * @param bit 0 -> write zero bit, !=0 write one bit
- */
-static void put_cabac_bypass(CABACContext *c, int bit){
- c->low += c->low;
-
- if(bit){
- c->low += c->range;
- }
-//FIXME optimize
- if(c->low<0x200){
- put_cabac_bit(c, 0);
- }else if(c->low<0x400){
- c->outstanding_count++;
- c->low -= 0x200;
- }else{
- put_cabac_bit(c, 1);
- c->low -= 0x400;
- }
-
-#ifdef STRICT_LIMITS
- c->symCount++;
-#endif
-}
-
-/**
- *
- * @return the number of bytes written
- */
-static int put_cabac_terminate(CABACContext *c, int bit){
- c->range -= 2;
-
- if(!bit){
- renorm_cabac_encoder(c);
- }else{
- c->low += c->range;
- c->range= 2;
-
- renorm_cabac_encoder(c);
-
- assert(c->low <= 0x1FF);
- put_cabac_bit(c, c->low>>9);
- put_bits(&c->pb, 2, ((c->low>>7)&3)|1);
-
- flush_put_bits(&c->pb); //FIXME FIXME FIXME XXX wrong
- }
-
-#ifdef STRICT_LIMITS
- c->symCount++;
-#endif
-
- return (put_bits_count(&c->pb)+7)>>3;
-}
-
-/**
- * put (truncated) unary binarization.
- */
-static void put_cabac_u(CABACContext *c, uint8_t * state, int v, int max, int max_index, int truncated){
- int i;
-
- assert(v <= max);
-
-#if 1
- for(i=0; i<v; i++){
- put_cabac(c, state, 1);
- if(i < max_index) state++;
- }
- if(truncated==0 || v<max)
- put_cabac(c, state, 0);
-#else
- if(v <= max_index){
- for(i=0; i<v; i++){
- put_cabac(c, state+i, 1);
- }
- if(truncated==0 || v<max)
- put_cabac(c, state+i, 0);
- }else{
- for(i=0; i<=max_index; i++){
- put_cabac(c, state+i, 1);
- }
- for(; i<v; i++){
- put_cabac(c, state+max_index, 1);
- }
- if(truncated==0 || v<max)
- put_cabac(c, state+max_index, 0);
- }
-#endif
-}
-
-/**
- * put unary exp golomb k-th order binarization.
- */
-static void put_cabac_ueg(CABACContext *c, uint8_t * state, int v, int max, int is_signed, int k, int max_index){
- int i;
-
- if(v==0)
- put_cabac(c, state, 0);
- else{
- const int sign= v < 0;
-
- if(is_signed) v= FFABS(v);
-
- if(v<max){
- for(i=0; i<v; i++){
- put_cabac(c, state, 1);
- if(i < max_index) state++;
- }
-
- put_cabac(c, state, 0);
- }else{
- int m= 1<<k;
-
- for(i=0; i<max; i++){
- put_cabac(c, state, 1);
- if(i < max_index) state++;
- }
-
- v -= max;
- while(v >= m){ //FIXME optimize
- put_cabac_bypass(c, 1);
- v-= m;
- m+= m;
- }
- put_cabac_bypass(c, 0);
- while(m>>=1){
- put_cabac_bypass(c, v&m);
- }
- }
-
- if(is_signed)
- put_cabac_bypass(c, sign);
- }
-}
-#endif /* TEST */
-
static void refill(CABACContext *c){
#if CABAC_BITS == 16
c->low+= (c->bytestream[0]<<9) + (c->bytestream[1]<<1);
diff --git a/libavcodec/cavs.c b/libavcodec/cavs.c
index 9a73e2a54b..47fc5a5da8 100644
--- a/libavcodec/cavs.c
+++ b/libavcodec/cavs.c
@@ -2,20 +2,20 @@
* Chinese AVS video (AVS1-P2, JiZhun profile) decoder.
* Copyright (c) 2006 Stefan Gehrer <stefan.gehrer@gmx.de>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -333,9 +333,9 @@ static inline void mc_dir_part(AVSContext *h,Picture *pic,int square,
const int mx= mv->x + src_x_offset*8;
const int my= mv->y + src_y_offset*8;
const int luma_xy= (mx&3) + ((my&3)<<2);
- uint8_t * src_y = pic->data[0] + (mx>>2) + (my>>2)*h->l_stride;
- uint8_t * src_cb= pic->data[1] + (mx>>3) + (my>>3)*h->c_stride;
- uint8_t * src_cr= pic->data[2] + (mx>>3) + (my>>3)*h->c_stride;
+ uint8_t * src_y = pic->f.data[0] + (mx >> 2) + (my >> 2) * h->l_stride;
+ uint8_t * src_cb = pic->f.data[1] + (mx >> 3) + (my >> 3) * h->c_stride;
+ uint8_t * src_cr = pic->f.data[2] + (mx >> 3) + (my >> 3) * h->c_stride;
int extra_width= 0; //(s->flags&CODEC_FLAG_EMU_EDGE) ? 0 : 16;
int extra_height= extra_width;
int emu=0;
@@ -344,7 +344,7 @@ static inline void mc_dir_part(AVSContext *h,Picture *pic,int square,
const int pic_width = 16*h->mb_width;
const int pic_height = 16*h->mb_height;
- if(!pic->data[0])
+ if(!pic->f.data[0])
return;
if(mx&7) extra_width -= 3;
if(my&7) extra_height -= 3;
@@ -602,9 +602,9 @@ int ff_cavs_next_mb(AVSContext *h) {
h->mbx = 0;
h->mby++;
/* re-calculate sample pointers */
- h->cy = h->picture.data[0] + h->mby*16*h->l_stride;
- h->cu = h->picture.data[1] + h->mby*8*h->c_stride;
- h->cv = h->picture.data[2] + h->mby*8*h->c_stride;
+ h->cy = h->picture.f.data[0] + h->mby * 16 * h->l_stride;
+ h->cu = h->picture.f.data[1] + h->mby * 8 * h->c_stride;
+ h->cv = h->picture.f.data[2] + h->mby * 8 * h->c_stride;
if(h->mby == h->mb_height) { //frame end
return 0;
}
@@ -629,11 +629,11 @@ void ff_cavs_init_pic(AVSContext *h) {
h->mv[MV_FWD_X0] = ff_cavs_dir_mv;
set_mvs(&h->mv[MV_FWD_X0], BLK_16X16);
h->pred_mode_Y[3] = h->pred_mode_Y[6] = NOT_AVAIL;
- h->cy = h->picture.data[0];
- h->cu = h->picture.data[1];
- h->cv = h->picture.data[2];
- h->l_stride = h->picture.linesize[0];
- h->c_stride = h->picture.linesize[1];
+ h->cy = h->picture.f.data[0];
+ h->cu = h->picture.f.data[1];
+ h->cv = h->picture.f.data[2];
+ h->l_stride = h->picture.f.linesize[0];
+ h->c_stride = h->picture.f.linesize[1];
h->luma_scan[2] = 8*h->l_stride;
h->luma_scan[3] = 8*h->l_stride+8;
h->mbx = h->mby = h->mbidx = 0;
diff --git a/libavcodec/cavs.h b/libavcodec/cavs.h
index eda76a8d8e..cb4ab2630b 100644
--- a/libavcodec/cavs.h
+++ b/libavcodec/cavs.h
@@ -2,20 +2,20 @@
* Chinese AVS video (AVS1-P2, JiZhun profile) decoder.
* Copyright (c) 2006 Stefan Gehrer <stefan.gehrer@gmx.de>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/cavs_parser.c b/libavcodec/cavs_parser.c
index 2cc65665b8..be32345af8 100644
--- a/libavcodec/cavs_parser.c
+++ b/libavcodec/cavs_parser.c
@@ -2,20 +2,20 @@
* Chinese AVS video (AVS1-P2, JiZhun profile) parser.
* Copyright (c) 2006 Stefan Gehrer <stefan.gehrer@gmx.de>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/cavsdata.h b/libavcodec/cavsdata.h
index 210169f844..a93405d380 100644
--- a/libavcodec/cavsdata.h
+++ b/libavcodec/cavsdata.h
@@ -2,20 +2,20 @@
* Chinese AVS video (AVS1-P2, JiZhun profile) decoder.
* Copyright (c) 2006 Stefan Gehrer <stefan.gehrer@gmx.de>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/cavsdec.c b/libavcodec/cavsdec.c
index a9e4d37c2a..2bf968ba22 100644
--- a/libavcodec/cavsdec.c
+++ b/libavcodec/cavsdec.c
@@ -2,20 +2,20 @@
* Chinese AVS video (AVS1-P2, JiZhun profile) decoder.
* Copyright (c) 2006 Stefan Gehrer <stefan.gehrer@gmx.de>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -115,7 +115,8 @@ static inline int get_ue_code(GetBitContext *gb, int order) {
static int decode_residual_block(AVSContext *h, GetBitContext *gb,
const struct dec_2dvlc *r, int esc_golomb_order,
int qp, uint8_t *dst, int stride) {
- int i, level_code, esc_code, level, run, mask;
+ int i, esc_code, level, mask;
+ unsigned int level_code, run;
DCTELEM level_buf[65];
uint8_t run_buf[65];
DCTELEM *block = h->block;
@@ -124,6 +125,8 @@ static int decode_residual_block(AVSContext *h, GetBitContext *gb,
level_code = get_ue_code(gb,r->golomb_order);
if(level_code >= ESCAPE_CODE) {
run = ((level_code - ESCAPE_CODE) >> 1) + 1;
+ if(run > 64)
+ return -1;
esc_code = get_ue_code(gb,esc_golomb_order);
level = esc_code + (run > r->max_run ? 1 : r->level_add[run]);
while(level > r->inc_limit)
@@ -163,7 +166,7 @@ static inline int decode_residual_inter(AVSContext *h) {
/* get coded block pattern */
int cbp= get_ue_golomb(&h->s.gb);
- if(cbp > 63){
+ if(cbp > 63U){
av_log(h->s.avctx, AV_LOG_ERROR, "illegal inter cbp\n");
return -1;
}
@@ -189,7 +192,8 @@ static inline int decode_residual_inter(AVSContext *h) {
static int decode_mb_i(AVSContext *h, int cbp_code) {
GetBitContext *gb = &h->s.gb;
- int block, pred_mode_uv;
+ unsigned pred_mode_uv;
+ int block;
uint8_t top[18];
uint8_t *left = NULL;
uint8_t *d;
@@ -222,7 +226,7 @@ static int decode_mb_i(AVSContext *h, int cbp_code) {
/* get coded block pattern */
if(h->pic_type == AV_PICTURE_TYPE_I)
cbp_code = get_ue_golomb(gb);
- if(cbp_code > 63){
+ if(cbp_code > 63U){
av_log(h->s.avctx, AV_LOG_ERROR, "illegal intra cbp\n");
return -1;
}
@@ -445,6 +449,8 @@ static inline int check_for_slice(AVSContext *h) {
if((show_bits_long(gb,24+align) & 0xFFFFFF) == 0x000001) {
skip_bits_long(gb,24+align);
h->stc = get_bits(gb,8);
+ if (h->stc >= h->mb_height)
+ return 0;
decode_slice_header(h,gb);
return 1;
}
@@ -476,8 +482,8 @@ static int decode_pic(AVSContext *h) {
return -1;
}
/* make sure we have the reference frames we need */
- if(!h->DPB[0].data[0] ||
- (!h->DPB[1].data[0] && h->pic_type == AV_PICTURE_TYPE_B))
+ if(!h->DPB[0].f.data[0] ||
+ (!h->DPB[1].f.data[0] && h->pic_type == AV_PICTURE_TYPE_B))
return -1;
} else {
h->pic_type = AV_PICTURE_TYPE_I;
@@ -494,7 +500,7 @@ static int decode_pic(AVSContext *h) {
skip_bits(&s->gb,1); //marker_bit
}
/* release last B frame */
- if(h->picture.data[0])
+ if(h->picture.f.data[0])
s->avctx->release_buffer(s->avctx, (AVFrame *)&h->picture);
s->avctx->get_buffer(s->avctx, (AVFrame *)&h->picture);
@@ -585,7 +591,7 @@ static int decode_pic(AVSContext *h) {
} while(ff_cavs_next_mb(h));
}
if(h->pic_type != AV_PICTURE_TYPE_B) {
- if(h->DPB[1].data[0])
+ if(h->DPB[1].f.data[0])
s->avctx->release_buffer(s->avctx, (AVFrame *)&h->DPB[1]);
h->DPB[1] = h->DPB[0];
h->DPB[0] = h->picture;
@@ -619,8 +625,8 @@ static int decode_seq_header(AVSContext *h) {
s->low_delay = get_bits1(&s->gb);
h->mb_width = (s->width + 15) >> 4;
h->mb_height = (s->height + 15) >> 4;
- h->s.avctx->time_base.den = ff_frame_rate_tab[frame_rate_code].num;
- h->s.avctx->time_base.num = ff_frame_rate_tab[frame_rate_code].den;
+ h->s.avctx->time_base.den = avpriv_frame_rate_tab[frame_rate_code].num;
+ h->s.avctx->time_base.num = avpriv_frame_rate_tab[frame_rate_code].den;
h->s.avctx->width = s->width;
h->s.avctx->height = s->height;
if(!h->top_qp)
@@ -648,7 +654,7 @@ static int cavs_decode_frame(AVCodecContext * avctx,void *data, int *data_size,
s->avctx = avctx;
if (buf_size == 0) {
- if(!s->low_delay && h->DPB[0].data[0]) {
+ if (!s->low_delay && h->DPB[0].f.data[0]) {
*data_size = sizeof(AVPicture);
*picture = *(AVFrame *) &h->DPB[0];
}
@@ -658,8 +664,8 @@ static int cavs_decode_frame(AVCodecContext * avctx,void *data, int *data_size,
buf_ptr = buf;
buf_end = buf + buf_size;
for(;;) {
- buf_ptr = ff_find_start_code(buf_ptr,buf_end, &stc);
- if(stc & 0xFFFFFE00)
+ buf_ptr = avpriv_mpv_find_start_code(buf_ptr,buf_end, &stc);
+ if((stc & 0xFFFFFE00) || buf_ptr == buf_end)
return FFMAX(0, buf_ptr - buf - s->parse_context.last_index);
input_size = (buf_end - buf_ptr)*8;
switch(stc) {
@@ -669,9 +675,9 @@ static int cavs_decode_frame(AVCodecContext * avctx,void *data, int *data_size,
break;
case PIC_I_START_CODE:
if(!h->got_keyframe) {
- if(h->DPB[0].data[0])
+ if(h->DPB[0].f.data[0])
avctx->release_buffer(avctx, (AVFrame *)&h->DPB[0]);
- if(h->DPB[1].data[0])
+ if(h->DPB[1].f.data[0])
avctx->release_buffer(avctx, (AVFrame *)&h->DPB[1]);
h->got_keyframe = 1;
}
@@ -685,7 +691,7 @@ static int cavs_decode_frame(AVCodecContext * avctx,void *data, int *data_size,
break;
*data_size = sizeof(AVPicture);
if(h->pic_type != AV_PICTURE_TYPE_B) {
- if(h->DPB[1].data[0]) {
+ if(h->DPB[1].f.data[0]) {
*picture = *(AVFrame *) &h->DPB[1];
} else {
*data_size = 0;
@@ -710,15 +716,14 @@ static int cavs_decode_frame(AVCodecContext * avctx,void *data, int *data_size,
}
AVCodec ff_cavs_decoder = {
- "cavs",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_CAVS,
- sizeof(AVSContext),
- ff_cavs_init,
- NULL,
- ff_cavs_end,
- cavs_decode_frame,
- CODEC_CAP_DR1 | CODEC_CAP_DELAY,
+ .name = "cavs",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_CAVS,
+ .priv_data_size = sizeof(AVSContext),
+ .init = ff_cavs_init,
+ .close = ff_cavs_end,
+ .decode = cavs_decode_frame,
+ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY,
.flush= cavs_flush,
.long_name= NULL_IF_CONFIG_SMALL("Chinese AVS video (AVS1-P2, JiZhun profile)"),
};
diff --git a/libavcodec/cavsdsp.c b/libavcodec/cavsdsp.c
index 04e521be75..192e0f976d 100644
--- a/libavcodec/cavsdsp.c
+++ b/libavcodec/cavsdsp.c
@@ -5,20 +5,20 @@
*
* Copyright (c) 2006 Stefan Gehrer <stefan.gehrer@gmx.de>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/cavsdsp.h b/libavcodec/cavsdsp.h
index b1133b7264..b41ad21bca 100644
--- a/libavcodec/cavsdsp.h
+++ b/libavcodec/cavsdsp.h
@@ -2,20 +2,20 @@
* Chinese AVS video (AVS1-P2, JiZhun profile) decoder.
* Copyright (c) 2006 Stefan Gehrer <stefan.gehrer@gmx.de>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/cbrt_tablegen.c b/libavcodec/cbrt_tablegen.c
index e92c0f1db1..e0a8e63a8b 100644
--- a/libavcodec/cbrt_tablegen.c
+++ b/libavcodec/cbrt_tablegen.c
@@ -3,20 +3,20 @@
*
* Copyright (c) 2010 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/cbrt_tablegen.h b/libavcodec/cbrt_tablegen.h
index 01963a3f9d..a9d34dc75d 100644
--- a/libavcodec/cbrt_tablegen.h
+++ b/libavcodec/cbrt_tablegen.h
@@ -3,20 +3,20 @@
*
* Copyright (c) 2010 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/cdgraphics.c b/libavcodec/cdgraphics.c
index 2f8e98ca3d..f7d9e5f7e3 100644
--- a/libavcodec/cdgraphics.c
+++ b/libavcodec/cdgraphics.c
@@ -2,20 +2,20 @@
* CD Graphics Video Decoder
* Copyright (c) 2009 Michael Tison
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -26,8 +26,8 @@
* @file
* @brief CD Graphics Video Decoder
* @author Michael Tison
- * @sa http://wiki.multimedia.cx/index.php?title=CD_Graphics
- * @sa http://www.ccs.neu.edu/home/bchafy/cdb/info/cdg
+ * @see http://wiki.multimedia.cx/index.php?title=CD_Graphics
+ * @see http://www.ccs.neu.edu/home/bchafy/cdb/info/cdg
*/
/// default screen sizes
@@ -368,15 +368,13 @@ static av_cold int cdg_decode_end(AVCodecContext *avctx)
}
AVCodec ff_cdgraphics_decoder = {
- "cdgraphics",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_CDGRAPHICS,
- sizeof(CDGraphicsContext),
- cdg_decode_init,
- NULL,
- cdg_decode_end,
- cdg_decode_frame,
- CODEC_CAP_DR1,
- .max_lowres = 5,
+ .name = "cdgraphics",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_CDGRAPHICS,
+ .priv_data_size = sizeof(CDGraphicsContext),
+ .init = cdg_decode_init,
+ .close = cdg_decode_end,
+ .decode = cdg_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("CD Graphics video"),
};
diff --git a/libavcodec/celp_filters.c b/libavcodec/celp_filters.c
index 25a6744b04..1535060c9d 100644
--- a/libavcodec/celp_filters.c
+++ b/libavcodec/celp_filters.c
@@ -3,20 +3,20 @@
*
* Copyright (c) 2008 Vladimir Voroshilov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -58,7 +58,7 @@ void ff_celp_circ_addf(float *out, const float *in,
int ff_celp_lp_synthesis_filter(int16_t *out, const int16_t *filter_coeffs,
const int16_t *in, int buffer_length,
int filter_length, int stop_on_overflow,
- int rounder)
+ int shift, int rounder)
{
int i,n;
@@ -67,7 +67,7 @@ int ff_celp_lp_synthesis_filter(int16_t *out, const int16_t *filter_coeffs,
for (i = 1; i <= filter_length; i++)
sum -= filter_coeffs[i-1] * out[n-i];
- sum = (sum >> 12) + in[n];
+ sum = ((sum >> 12) + in[n]) >> shift;
if (sum + 0x8000 > 0xFFFFU) {
if (stop_on_overflow)
diff --git a/libavcodec/celp_filters.h b/libavcodec/celp_filters.h
index cfd08fd440..f7e8fbddd3 100644
--- a/libavcodec/celp_filters.h
+++ b/libavcodec/celp_filters.h
@@ -3,20 +3,20 @@
*
* Copyright (c) 2008 Vladimir Voroshilov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -63,6 +63,7 @@ void ff_celp_circ_addf(float *out, const float *in,
* @param filter_length filter length (10 for 10th order LP filter)
* @param stop_on_overflow 1 - return immediately if overflow occurs
* 0 - ignore overflows
+ * @param shift the result is shifted right by this value
* @param rounder the amount to add for rounding (usually 0x800 or 0xfff)
*
* @return 1 if overflow occurred, 0 - otherwise
@@ -75,7 +76,7 @@ void ff_celp_circ_addf(float *out, const float *in,
int ff_celp_lp_synthesis_filter(int16_t *out, const int16_t *filter_coeffs,
const int16_t *in, int buffer_length,
int filter_length, int stop_on_overflow,
- int rounder);
+ int shift, int rounder);
/**
* LP synthesis filter.
diff --git a/libavcodec/celp_math.c b/libavcodec/celp_math.c
index 4ab20ad29f..d85277f209 100644
--- a/libavcodec/celp_math.c
+++ b/libavcodec/celp_math.c
@@ -3,20 +3,20 @@
*
* Copyright (c) 2008 Vladimir Voroshilov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -25,6 +25,7 @@
#include <assert.h>
#include "avcodec.h"
+#include "mathops.h"
#include "celp_math.h"
#ifdef G729_BITEXACT
@@ -196,6 +197,17 @@ int ff_log2(uint32_t value)
return (power_int << 15) + value;
}
+int64_t ff_dot_product(const int16_t *a, const int16_t *b, int length)
+{
+ int i;
+ int64_t sum = 0;
+
+ for (i = 0; i < length; i++)
+ sum += MUL16(a[i], b[i]);
+
+ return sum;
+}
+
float ff_dot_productf(const float* a, const float* b, int length)
{
float sum = 0;
diff --git a/libavcodec/celp_math.h b/libavcodec/celp_math.h
index 9cd9ae238d..4803245478 100644
--- a/libavcodec/celp_math.h
+++ b/libavcodec/celp_math.h
@@ -3,20 +3,20 @@
*
* Copyright (c) 2008 Vladimir Voroshilov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -64,6 +64,16 @@ static inline int bidir_sal(int value, int offset)
}
/**
+ * returns the dot product of 2 int16_t vectors.
+ * @param a input data array
+ * @param b input data array
+ * @param length number of elements
+ *
+ * @return dot product = sum of elementwise products
+ */
+int64_t ff_dot_product(const int16_t *a, const int16_t *b, int length);
+
+/**
* returns the dot product.
* @param a input data array
* @param b input data array
diff --git a/libavcodec/cga_data.c b/libavcodec/cga_data.c
index 2c63ff2001..160d77cde2 100644
--- a/libavcodec/cga_data.c
+++ b/libavcodec/cga_data.c
@@ -1,20 +1,20 @@
/*
* CGA/EGA/VGA ROM data
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/cga_data.h b/libavcodec/cga_data.h
index 2149cfd2f1..998dccaefb 100644
--- a/libavcodec/cga_data.h
+++ b/libavcodec/cga_data.h
@@ -1,20 +1,20 @@
/*
* CGA/EGA/VGA ROM data
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/chomp_bsf.c b/libavcodec/chomp_bsf.c
index 9ed7496930..eaefaaa539 100644
--- a/libavcodec/chomp_bsf.c
+++ b/libavcodec/chomp_bsf.c
@@ -2,20 +2,20 @@
* Chomp bitstream filter
* Copyright (c) 2010 Alex Converse <alex.converse@gmail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/cinepak.c b/libavcodec/cinepak.c
index 4bda2a74eb..a0ec7b89d0 100644
--- a/libavcodec/cinepak.c
+++ b/libavcodec/cinepak.c
@@ -2,20 +2,20 @@
* Cinepak Video Decoder
* Copyright (C) 2003 the ffmpeg project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -336,7 +336,8 @@ static int cinepak_decode (CinepakContext *s)
* If the frame header is followed by the bytes FE 00 00 06 00 00 then
* this is probably one of the two known files that have 6 extra bytes
* after the frame header. Else, assume 2 extra bytes. */
- if ((s->data[10] == 0xFE) &&
+ if (s->size >= 16 &&
+ (s->data[10] == 0xFE) &&
(s->data[11] == 0x00) &&
(s->data[12] == 0x00) &&
(s->data[13] == 0x06) &&
@@ -354,6 +355,8 @@ static int cinepak_decode (CinepakContext *s)
if (num_strips > MAX_STRIPS)
num_strips = MAX_STRIPS;
+ s->frame.key_frame = 0;
+
for (i=0; i < num_strips; i++) {
if ((s->data + 12) > eod)
return -1;
@@ -364,6 +367,9 @@ static int cinepak_decode (CinepakContext *s)
s->strips[i].y2 = y0 + AV_RB16 (&s->data[8]);
s->strips[i].x2 = s->avctx->width;
+ if (s->strips[i].id == 0x10)
+ s->frame.key_frame = 1;
+
strip_size = AV_RB24 (&s->data[1]) - 12;
s->data += 12;
strip_size = ((s->data + strip_size) > eod) ? (eod - s->data) : strip_size;
@@ -404,6 +410,7 @@ static av_cold int cinepak_decode_init(AVCodecContext *avctx)
avctx->pix_fmt = PIX_FMT_PAL8;
}
+ avcodec_get_frame_defaults(&s->frame);
s->frame.data[0] = NULL;
return 0;
@@ -459,14 +466,13 @@ static av_cold int cinepak_decode_end(AVCodecContext *avctx)
}
AVCodec ff_cinepak_decoder = {
- "cinepak",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_CINEPAK,
- sizeof(CinepakContext),
- cinepak_decode_init,
- NULL,
- cinepak_decode_end,
- cinepak_decode_frame,
- CODEC_CAP_DR1,
+ .name = "cinepak",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_CINEPAK,
+ .priv_data_size = sizeof(CinepakContext),
+ .init = cinepak_decode_init,
+ .close = cinepak_decode_end,
+ .decode = cinepak_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Cinepak"),
};
diff --git a/libavcodec/cljr.c b/libavcodec/cljr.c
index e2b01e2a6a..6e352b8e61 100644
--- a/libavcodec/cljr.c
+++ b/libavcodec/cljr.c
@@ -2,20 +2,20 @@
* Cirrus Logic AccuPak (CLJR) codec
* Copyright (c) 2003 Alex Beregszaszi
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -67,7 +67,7 @@ static int decode_frame(AVCodecContext *avctx,
p->pict_type= AV_PICTURE_TYPE_I;
p->key_frame= 1;
- init_get_bits(&a->gb, buf, buf_size);
+ init_get_bits(&a->gb, buf, buf_size * 8);
for(y=0; y<avctx->height; y++){
uint8_t *luma= &a->picture.data[0][ y*a->picture.linesize[0] ];
@@ -105,7 +105,7 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size,
emms_c();
- align_put_bits(&a->pb);
+ avpriv_align_put_bits(&a->pb);
while(get_bit_count(&a->pb)&31)
put_bits(&a->pb, 8, 0);
@@ -118,6 +118,7 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size,
static av_cold void common_init(AVCodecContext *avctx){
CLJRContext * const a = avctx->priv_data;
+ avcodec_get_frame_defaults(&a->picture);
avctx->coded_frame= (AVFrame*)&a->picture;
a->avctx= avctx;
}
@@ -141,27 +142,24 @@ static av_cold int encode_init(AVCodecContext *avctx){
#endif
AVCodec ff_cljr_decoder = {
- "cljr",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_CLJR,
- sizeof(CLJRContext),
- decode_init,
- NULL,
- NULL,
- decode_frame,
- CODEC_CAP_DR1,
+ .name = "cljr",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_CLJR,
+ .priv_data_size = sizeof(CLJRContext),
+ .init = decode_init,
+ .decode = decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Cirrus Logic AccuPak"),
};
#if CONFIG_CLJR_ENCODER
AVCodec ff_cljr_encoder = {
- "cljr",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_CLJR,
- sizeof(CLJRContext),
- encode_init,
- encode_frame,
- //encode_end,
+ .name = "cljr",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_CLJR,
+ .priv_data_size = sizeof(CLJRContext),
+ .init = encode_init,
+ .encode = encode_frame,
.long_name = NULL_IF_CONFIG_SMALL("Cirrus Logic AccuPak"),
};
#endif
diff --git a/libavcodec/codec_names.sh b/libavcodec/codec_names.sh
new file mode 100755
index 0000000000..167d29771e
--- /dev/null
+++ b/libavcodec/codec_names.sh
@@ -0,0 +1,85 @@
+#!/bin/sh
+
+# Copyright (c) 2011 Nicolas George
+#
+# This file is part of FFmpeg.
+#
+# FFmpeg 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.
+#
+# FFmpeg 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with FFmpeg; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+set -e
+
+config="$1"
+codecs="$2"
+out="$3"
+test -n "$out"
+
+outval=""
+
+add_line () {
+ outval="$outval$*
+"
+}
+
+parse_config_h () {
+ while read define var value; do
+ case "$define $var $value" in
+ "#define CONFIG_"*_*" 1") eval "$var=1";;
+ esac
+ done
+}
+
+define_codecid () {
+ id="$1"
+ n=${1#CODEC_ID_}
+ add_line "case ${id}:"
+ eval "c=\${CONFIG_${n}_DECODER}:\${CONFIG_${n}_ENCODER}"
+ case "$c" in
+ 1:*) s="decoder";;
+ *:1) s="encoder";;
+ *) s="";;
+ esac
+ case "$s" in
+ "") add_line " return \"$n\";" ;;
+ *)
+ add_line " { extern AVCodec ff_${n}_${s};"
+ add_line " return ff_${n}_${s}.name; }"
+ ;;
+ esac
+}
+
+parse_enum_codecid () {
+ while read line; do
+ case "$line" in
+ "};") break;;
+ *CODEC_ID_FIRST*///*dummy*) ;;
+ CODEC_ID_*) define_codecid ${line%%[=,]*};;
+ esac
+ done
+}
+
+parse_avcodec_h () {
+ while read line; do
+ case "$line" in
+ "enum CodecID {") parse_enum_codecid; break;;
+ esac
+ done
+}
+
+parse_config_h < "$config"
+parse_avcodec_h < "$codecs"
+sed -e '/case.*:/!y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/' \
+ -e 's/extern avcodec /extern AVCodec /' > "$out" <<EOF
+$outval
+EOF
diff --git a/libavcodec/cook.c b/libavcodec/cook.c
index b5492db27b..0d09bb83fb 100644
--- a/libavcodec/cook.c
+++ b/libavcodec/cook.c
@@ -3,20 +3,20 @@
* Copyright (c) 2003 Sascha Sommer
* Copyright (c) 2005 Benjamin Larsson
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -1174,8 +1174,9 @@ static av_cold int cook_decode_init(AVCodecContext *avctx)
return -1;
}
- if ((q->subpacket[s].js_vlc_bits > 6) || (q->subpacket[s].js_vlc_bits < 0)) {
- av_log(avctx,AV_LOG_ERROR,"js_vlc_bits = %d, only >= 0 and <= 6 allowed!\n",q->subpacket[s].js_vlc_bits);
+ if ((q->subpacket[s].js_vlc_bits > 6) || (q->subpacket[s].js_vlc_bits < 2*q->subpacket[s].joint_stereo)) {
+ av_log(avctx,AV_LOG_ERROR,"js_vlc_bits = %d, only >= %d and <= 6 allowed!\n",
+ q->subpacket[s].js_vlc_bits, 2*q->subpacket[s].joint_stereo);
return -1;
}
diff --git a/libavcodec/cookdata.h b/libavcodec/cookdata.h
index e8d6ebfcb3..15e8e9519f 100644
--- a/libavcodec/cookdata.h
+++ b/libavcodec/cookdata.h
@@ -3,20 +3,20 @@
* Copyright (c) 2003 Sascha Sommer
* Copyright (c) 2005 Benjamin Larsson
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/cos_tablegen.c b/libavcodec/cos_tablegen.c
index 5e52c482c6..1577166a46 100644
--- a/libavcodec/cos_tablegen.c
+++ b/libavcodec/cos_tablegen.c
@@ -3,20 +3,20 @@
*
* Copyright (c) 2009 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/crystalhd.c b/libavcodec/crystalhd.c
new file mode 100644
index 0000000000..833b8d97fa
--- /dev/null
+++ b/libavcodec/crystalhd.c
@@ -0,0 +1,1141 @@
+/*
+ * - CrystalHD decoder module -
+ *
+ * Copyright(C) 2010,2011 Philip Langdale <ffmpeg.philipl@overt.org>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/*
+ * - Principles of Operation -
+ *
+ * The CrystalHD decoder operates at the bitstream level - which is an even
+ * higher level than the decoding hardware you typically see in modern GPUs.
+ * This means it has a very simple interface, in principle. You feed demuxed
+ * packets in one end and get decoded picture (fields/frames) out the other.
+ *
+ * Of course, nothing is ever that simple. Due, at the very least, to b-frame
+ * dependencies in the supported formats, the hardware has a delay between
+ * when a packet goes in, and when a picture comes out. Furthermore, this delay
+ * is not just a function of time, but also one of the dependency on additional
+ * frames being fed into the decoder to satisfy the b-frame dependencies.
+ *
+ * As such, a pipeline will build up that is roughly equivalent to the required
+ * DPB for the file being played. If that was all it took, things would still
+ * be simple - so, of course, it isn't.
+ *
+ * The hardware has a way of indicating that a picture is ready to be copied out,
+ * but this is unreliable - and sometimes the attempt will still fail so, based
+ * on testing, the code will wait until 3 pictures are ready before starting
+ * to copy out - and this has the effect of extending the pipeline.
+ *
+ * Finally, while it is tempting to say that once the decoder starts outputing
+ * frames, the software should never fail to return a frame from a decode(),
+ * this is a hard assertion to make, because the stream may switch between
+ * differently encoded content (number of b-frames, interlacing, etc) which
+ * might require a longer pipeline than before. If that happened, you could
+ * deadlock trying to retrieve a frame that can't be decoded without feeding
+ * in additional packets.
+ *
+ * As such, the code will return in the event that a picture cannot be copied
+ * out, leading to an increase in the length of the pipeline. This in turn,
+ * means we have to be sensitive to the time it takes to decode a picture;
+ * We do not want to give up just because the hardware needed a little more
+ * time to prepare the picture! For this reason, there are delays included
+ * in the decode() path that ensure that, under normal conditions, the hardware
+ * will only fail to return a frame if it really needs additional packets to
+ * complete the decoding.
+ *
+ * Finally, to be explicit, we do not want the pipeline to grow without bound
+ * for two reasons: 1) The hardware can only buffer a finite number of packets,
+ * and 2) The client application may not be able to cope with arbitrarily long
+ * delays in the video path relative to the audio path. For example. MPlayer
+ * can only handle a 20 picture delay (although this is arbitrary, and needs
+ * to be extended to fully support the CrystalHD where the delay could be up
+ * to 32 pictures - consider PAFF H.264 content with 16 b-frames).
+ */
+
+/*****************************************************************************
+ * Includes
+ ****************************************************************************/
+
+#define _XOPEN_SOURCE 600
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <libcrystalhd/bc_dts_types.h>
+#include <libcrystalhd/bc_dts_defs.h>
+#include <libcrystalhd/libcrystalhd_if.h>
+
+#include "avcodec.h"
+#include "h264.h"
+#include "libavutil/imgutils.h"
+#include "libavutil/intreadwrite.h"
+#include "libavutil/opt.h"
+
+/** Timeout parameter passed to DtsProcOutput() in us */
+#define OUTPUT_PROC_TIMEOUT 50
+/** Step between fake timestamps passed to hardware in units of 100ns */
+#define TIMESTAMP_UNIT 100000
+/** Initial value in us of the wait in decode() */
+#define BASE_WAIT 10000
+/** Increment in us to adjust wait in decode() */
+#define WAIT_UNIT 1000
+
+
+/*****************************************************************************
+ * Module private data
+ ****************************************************************************/
+
+typedef enum {
+ RET_ERROR = -1,
+ RET_OK = 0,
+ RET_COPY_AGAIN = 1,
+ RET_SKIP_NEXT_COPY = 2,
+ RET_COPY_NEXT_FIELD = 3,
+} CopyRet;
+
+typedef struct OpaqueList {
+ struct OpaqueList *next;
+ uint64_t fake_timestamp;
+ uint64_t reordered_opaque;
+ uint8_t pic_type;
+} OpaqueList;
+
+typedef struct {
+ AVClass *av_class;
+ AVCodecContext *avctx;
+ AVFrame pic;
+ HANDLE dev;
+
+ AVBitStreamFilterContext *bsfc;
+ AVCodecParserContext *parser;
+
+ uint8_t is_70012;
+ uint8_t *sps_pps_buf;
+ uint32_t sps_pps_size;
+ uint8_t is_nal;
+ uint8_t output_ready;
+ uint8_t need_second_field;
+ uint8_t skip_next_output;
+ uint64_t decode_wait;
+
+ uint64_t last_picture;
+
+ OpaqueList *head;
+ OpaqueList *tail;
+
+ /* Options */
+ uint32_t sWidth;
+ uint8_t bframe_bug;
+} CHDContext;
+
+static const AVOption options[] = {
+ { "crystalhd_downscale_width",
+ "Turn on downscaling to the specified width",
+ offsetof(CHDContext, sWidth),
+ AV_OPT_TYPE_INT, 0, 0, UINT32_MAX,
+ AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM, },
+ { NULL, },
+};
+
+
+/*****************************************************************************
+ * Helper functions
+ ****************************************************************************/
+
+static inline BC_MEDIA_SUBTYPE id2subtype(CHDContext *priv, enum CodecID id)
+{
+ switch (id) {
+ case CODEC_ID_MPEG4:
+ return BC_MSUBTYPE_DIVX;
+ case CODEC_ID_MSMPEG4V3:
+ return BC_MSUBTYPE_DIVX311;
+ case CODEC_ID_MPEG2VIDEO:
+ return BC_MSUBTYPE_MPEG2VIDEO;
+ case CODEC_ID_VC1:
+ return BC_MSUBTYPE_VC1;
+ case CODEC_ID_WMV3:
+ return BC_MSUBTYPE_WMV3;
+ case CODEC_ID_H264:
+ return priv->is_nal ? BC_MSUBTYPE_AVC1 : BC_MSUBTYPE_H264;
+ default:
+ return BC_MSUBTYPE_INVALID;
+ }
+}
+
+static inline void print_frame_info(CHDContext *priv, BC_DTS_PROC_OUT *output)
+{
+ av_log(priv->avctx, AV_LOG_VERBOSE, "\tYBuffSz: %u\n", output->YbuffSz);
+ av_log(priv->avctx, AV_LOG_VERBOSE, "\tYBuffDoneSz: %u\n",
+ output->YBuffDoneSz);
+ av_log(priv->avctx, AV_LOG_VERBOSE, "\tUVBuffDoneSz: %u\n",
+ output->UVBuffDoneSz);
+ av_log(priv->avctx, AV_LOG_VERBOSE, "\tTimestamp: %"PRIu64"\n",
+ output->PicInfo.timeStamp);
+ av_log(priv->avctx, AV_LOG_VERBOSE, "\tPicture Number: %u\n",
+ output->PicInfo.picture_number);
+ av_log(priv->avctx, AV_LOG_VERBOSE, "\tWidth: %u\n",
+ output->PicInfo.width);
+ av_log(priv->avctx, AV_LOG_VERBOSE, "\tHeight: %u\n",
+ output->PicInfo.height);
+ av_log(priv->avctx, AV_LOG_VERBOSE, "\tChroma: 0x%03x\n",
+ output->PicInfo.chroma_format);
+ av_log(priv->avctx, AV_LOG_VERBOSE, "\tPulldown: %u\n",
+ output->PicInfo.pulldown);
+ av_log(priv->avctx, AV_LOG_VERBOSE, "\tFlags: 0x%08x\n",
+ output->PicInfo.flags);
+ av_log(priv->avctx, AV_LOG_VERBOSE, "\tFrame Rate/Res: %u\n",
+ output->PicInfo.frame_rate);
+ av_log(priv->avctx, AV_LOG_VERBOSE, "\tAspect Ratio: %u\n",
+ output->PicInfo.aspect_ratio);
+ av_log(priv->avctx, AV_LOG_VERBOSE, "\tColor Primaries: %u\n",
+ output->PicInfo.colour_primaries);
+ av_log(priv->avctx, AV_LOG_VERBOSE, "\tMetaData: %u\n",
+ output->PicInfo.picture_meta_payload);
+ av_log(priv->avctx, AV_LOG_VERBOSE, "\tSession Number: %u\n",
+ output->PicInfo.sess_num);
+ av_log(priv->avctx, AV_LOG_VERBOSE, "\tycom: %u\n",
+ output->PicInfo.ycom);
+ av_log(priv->avctx, AV_LOG_VERBOSE, "\tCustom Aspect: %u\n",
+ output->PicInfo.custom_aspect_ratio_width_height);
+ av_log(priv->avctx, AV_LOG_VERBOSE, "\tFrames to Drop: %u\n",
+ output->PicInfo.n_drop);
+ av_log(priv->avctx, AV_LOG_VERBOSE, "\tH264 Valid Fields: 0x%08x\n",
+ output->PicInfo.other.h264.valid);
+}
+
+
+/*****************************************************************************
+ * OpaqueList functions
+ ****************************************************************************/
+
+static uint64_t opaque_list_push(CHDContext *priv, uint64_t reordered_opaque,
+ uint8_t pic_type)
+{
+ OpaqueList *newNode = av_mallocz(sizeof (OpaqueList));
+ if (!newNode) {
+ av_log(priv->avctx, AV_LOG_ERROR,
+ "Unable to allocate new node in OpaqueList.\n");
+ return 0;
+ }
+ if (!priv->head) {
+ newNode->fake_timestamp = TIMESTAMP_UNIT;
+ priv->head = newNode;
+ } else {
+ newNode->fake_timestamp = priv->tail->fake_timestamp + TIMESTAMP_UNIT;
+ priv->tail->next = newNode;
+ }
+ priv->tail = newNode;
+ newNode->reordered_opaque = reordered_opaque;
+ newNode->pic_type = pic_type;
+
+ return newNode->fake_timestamp;
+}
+
+/*
+ * The OpaqueList is built in decode order, while elements will be removed
+ * in presentation order. If frames are reordered, this means we must be
+ * able to remove elements that are not the first element.
+ *
+ * Returned node must be freed by caller.
+ */
+static OpaqueList *opaque_list_pop(CHDContext *priv, uint64_t fake_timestamp)
+{
+ OpaqueList *node = priv->head;
+
+ if (!priv->head) {
+ av_log(priv->avctx, AV_LOG_ERROR,
+ "CrystalHD: Attempted to query non-existent timestamps.\n");
+ return NULL;
+ }
+
+ /*
+ * The first element is special-cased because we have to manipulate
+ * the head pointer rather than the previous element in the list.
+ */
+ if (priv->head->fake_timestamp == fake_timestamp) {
+ priv->head = node->next;
+
+ if (!priv->head->next)
+ priv->tail = priv->head;
+
+ node->next = NULL;
+ return node;
+ }
+
+ /*
+ * The list is processed at arm's length so that we have the
+ * previous element available to rewrite its next pointer.
+ */
+ while (node->next) {
+ OpaqueList *current = node->next;
+ if (current->fake_timestamp == fake_timestamp) {
+ node->next = current->next;
+
+ if (!node->next)
+ priv->tail = node;
+
+ current->next = NULL;
+ return current;
+ } else {
+ node = current;
+ }
+ }
+
+ av_log(priv->avctx, AV_LOG_VERBOSE,
+ "CrystalHD: Couldn't match fake_timestamp.\n");
+ return NULL;
+}
+
+
+/*****************************************************************************
+ * Video decoder API function definitions
+ ****************************************************************************/
+
+static void flush(AVCodecContext *avctx)
+{
+ CHDContext *priv = avctx->priv_data;
+
+ avctx->has_b_frames = 0;
+ priv->last_picture = -1;
+ priv->output_ready = 0;
+ priv->need_second_field = 0;
+ priv->skip_next_output = 0;
+ priv->decode_wait = BASE_WAIT;
+
+ if (priv->pic.data[0])
+ avctx->release_buffer(avctx, &priv->pic);
+
+ /* Flush mode 4 flushes all software and hardware buffers. */
+ DtsFlushInput(priv->dev, 4);
+}
+
+
+static av_cold int uninit(AVCodecContext *avctx)
+{
+ CHDContext *priv = avctx->priv_data;
+ HANDLE device;
+
+ device = priv->dev;
+ DtsStopDecoder(device);
+ DtsCloseDecoder(device);
+ DtsDeviceClose(device);
+
+ av_parser_close(priv->parser);
+ if (priv->bsfc) {
+ av_bitstream_filter_close(priv->bsfc);
+ }
+
+ av_free(priv->sps_pps_buf);
+
+ if (priv->pic.data[0])
+ avctx->release_buffer(avctx, &priv->pic);
+
+ if (priv->head) {
+ OpaqueList *node = priv->head;
+ while (node) {
+ OpaqueList *next = node->next;
+ av_free(node);
+ node = next;
+ }
+ }
+
+ return 0;
+}
+
+
+static av_cold int init(AVCodecContext *avctx)
+{
+ CHDContext* priv;
+ BC_STATUS ret;
+ BC_INFO_CRYSTAL version;
+ BC_INPUT_FORMAT format = {
+ .FGTEnable = FALSE,
+ .Progressive = TRUE,
+ .OptFlags = 0x80000000 | vdecFrameRate59_94 | 0x40,
+ .width = avctx->width,
+ .height = avctx->height,
+ };
+
+ BC_MEDIA_SUBTYPE subtype;
+
+ uint32_t mode = DTS_PLAYBACK_MODE |
+ DTS_LOAD_FILE_PLAY_FW |
+ DTS_SKIP_TX_CHK_CPB |
+ DTS_PLAYBACK_DROP_RPT_MODE |
+ DTS_SINGLE_THREADED_MODE |
+ DTS_DFLT_RESOLUTION(vdecRESOLUTION_1080p23_976);
+
+ av_log(avctx, AV_LOG_VERBOSE, "CrystalHD Init for %s\n",
+ avctx->codec->name);
+
+ avctx->pix_fmt = PIX_FMT_YUYV422;
+
+ /* Initialize the library */
+ priv = avctx->priv_data;
+ priv->avctx = avctx;
+ priv->is_nal = avctx->extradata_size > 0 && *(avctx->extradata) == 1;
+ priv->last_picture = -1;
+ priv->decode_wait = BASE_WAIT;
+
+ subtype = id2subtype(priv, avctx->codec->id);
+ switch (subtype) {
+ case BC_MSUBTYPE_AVC1:
+ {
+ uint8_t *dummy_p;
+ int dummy_int;
+
+ priv->bsfc = av_bitstream_filter_init("h264_mp4toannexb");
+ if (!priv->bsfc) {
+ av_log(avctx, AV_LOG_ERROR,
+ "Cannot open the h264_mp4toannexb BSF!\n");
+ return AVERROR_BSF_NOT_FOUND;
+ }
+ av_bitstream_filter_filter(priv->bsfc, avctx, NULL, &dummy_p,
+ &dummy_int, NULL, 0, 0);
+ }
+ subtype = BC_MSUBTYPE_H264;
+ // Fall-through
+ case BC_MSUBTYPE_H264:
+ format.startCodeSz = 4;
+ // Fall-through
+ case BC_MSUBTYPE_VC1:
+ case BC_MSUBTYPE_WVC1:
+ case BC_MSUBTYPE_WMV3:
+ case BC_MSUBTYPE_WMVA:
+ case BC_MSUBTYPE_MPEG2VIDEO:
+ case BC_MSUBTYPE_DIVX:
+ case BC_MSUBTYPE_DIVX311:
+ format.pMetaData = avctx->extradata;
+ format.metaDataSz = avctx->extradata_size;
+ break;
+ default:
+ av_log(avctx, AV_LOG_ERROR, "CrystalHD: Unknown codec name\n");
+ return AVERROR(EINVAL);
+ }
+ format.mSubtype = subtype;
+
+ if (priv->sWidth) {
+ format.bEnableScaling = 1;
+ format.ScalingParams.sWidth = priv->sWidth;
+ }
+
+ /* Get a decoder instance */
+ av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: starting up\n");
+ // Initialize the Link and Decoder devices
+ ret = DtsDeviceOpen(&priv->dev, mode);
+ if (ret != BC_STS_SUCCESS) {
+ av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: DtsDeviceOpen failed\n");
+ goto fail;
+ }
+
+ ret = DtsCrystalHDVersion(priv->dev, &version);
+ if (ret != BC_STS_SUCCESS) {
+ av_log(avctx, AV_LOG_VERBOSE,
+ "CrystalHD: DtsCrystalHDVersion failed\n");
+ goto fail;
+ }
+ priv->is_70012 = version.device == 0;
+
+ if (priv->is_70012 &&
+ (subtype == BC_MSUBTYPE_DIVX || subtype == BC_MSUBTYPE_DIVX311)) {
+ av_log(avctx, AV_LOG_VERBOSE,
+ "CrystalHD: BCM70012 doesn't support MPEG4-ASP/DivX/Xvid\n");
+ goto fail;
+ }
+
+ ret = DtsSetInputFormat(priv->dev, &format);
+ if (ret != BC_STS_SUCCESS) {
+ av_log(avctx, AV_LOG_ERROR, "CrystalHD: SetInputFormat failed\n");
+ goto fail;
+ }
+
+ ret = DtsOpenDecoder(priv->dev, BC_STREAM_TYPE_ES);
+ if (ret != BC_STS_SUCCESS) {
+ av_log(avctx, AV_LOG_ERROR, "CrystalHD: DtsOpenDecoder failed\n");
+ goto fail;
+ }
+
+ ret = DtsSetColorSpace(priv->dev, OUTPUT_MODE422_YUY2);
+ if (ret != BC_STS_SUCCESS) {
+ av_log(avctx, AV_LOG_ERROR, "CrystalHD: DtsSetColorSpace failed\n");
+ goto fail;
+ }
+ ret = DtsStartDecoder(priv->dev);
+ if (ret != BC_STS_SUCCESS) {
+ av_log(avctx, AV_LOG_ERROR, "CrystalHD: DtsStartDecoder failed\n");
+ goto fail;
+ }
+ ret = DtsStartCapture(priv->dev);
+ if (ret != BC_STS_SUCCESS) {
+ av_log(avctx, AV_LOG_ERROR, "CrystalHD: DtsStartCapture failed\n");
+ goto fail;
+ }
+
+ if (avctx->codec->id == CODEC_ID_H264) {
+ priv->parser = av_parser_init(avctx->codec->id);
+ if (!priv->parser)
+ av_log(avctx, AV_LOG_WARNING,
+ "Cannot open the h.264 parser! Interlaced h.264 content "
+ "will not be detected reliably.\n");
+ priv->parser->flags = PARSER_FLAG_COMPLETE_FRAMES;
+ }
+ av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: Init complete.\n");
+
+ return 0;
+
+ fail:
+ uninit(avctx);
+ return -1;
+}
+
+
+static inline CopyRet copy_frame(AVCodecContext *avctx,
+ BC_DTS_PROC_OUT *output,
+ void *data, int *data_size)
+{
+ BC_STATUS ret;
+ BC_DTS_STATUS decoder_status;
+ uint8_t trust_interlaced;
+ uint8_t interlaced;
+
+ CHDContext *priv = avctx->priv_data;
+ int64_t pkt_pts = AV_NOPTS_VALUE;
+ uint8_t pic_type = 0;
+
+ uint8_t bottom_field = (output->PicInfo.flags & VDEC_FLAG_BOTTOMFIELD) ==
+ VDEC_FLAG_BOTTOMFIELD;
+ uint8_t bottom_first = !!(output->PicInfo.flags & VDEC_FLAG_BOTTOM_FIRST);
+
+ int width = output->PicInfo.width;
+ int height = output->PicInfo.height;
+ int bwidth;
+ uint8_t *src = output->Ybuff;
+ int sStride;
+ uint8_t *dst;
+ int dStride;
+
+ if (output->PicInfo.timeStamp != 0) {
+ OpaqueList *node = opaque_list_pop(priv, output->PicInfo.timeStamp);
+ if (node) {
+ pkt_pts = node->reordered_opaque;
+ pic_type = node->pic_type;
+ av_free(node);
+ } else {
+ /*
+ * We will encounter a situation where a timestamp cannot be
+ * popped if a second field is being returned. In this case,
+ * each field has the same timestamp and the first one will
+ * cause it to be popped. To keep subsequent calculations
+ * simple, pic_type should be set a FIELD value - doesn't
+ * matter which, but I chose BOTTOM.
+ */
+ pic_type = PICT_BOTTOM_FIELD;
+ }
+ av_log(avctx, AV_LOG_VERBOSE, "output \"pts\": %"PRIu64"\n",
+ output->PicInfo.timeStamp);
+ av_log(avctx, AV_LOG_VERBOSE, "output picture type %d\n",
+ pic_type);
+ }
+
+ ret = DtsGetDriverStatus(priv->dev, &decoder_status);
+ if (ret != BC_STS_SUCCESS) {
+ av_log(avctx, AV_LOG_ERROR,
+ "CrystalHD: GetDriverStatus failed: %u\n", ret);
+ return RET_ERROR;
+ }
+
+ /*
+ * For most content, we can trust the interlaced flag returned
+ * by the hardware, but sometimes we can't. These are the
+ * conditions under which we can trust the flag:
+ *
+ * 1) It's not h.264 content
+ * 2) The UNKNOWN_SRC flag is not set
+ * 3) We know we're expecting a second field
+ * 4) The hardware reports this picture and the next picture
+ * have the same picture number.
+ *
+ * Note that there can still be interlaced content that will
+ * fail this check, if the hardware hasn't decoded the next
+ * picture or if there is a corruption in the stream. (In either
+ * case a 0 will be returned for the next picture number)
+ */
+ trust_interlaced = avctx->codec->id != CODEC_ID_H264 ||
+ !(output->PicInfo.flags & VDEC_FLAG_UNKNOWN_SRC) ||
+ priv->need_second_field ||
+ (decoder_status.picNumFlags & ~0x40000000) ==
+ output->PicInfo.picture_number;
+
+ /*
+ * If we got a false negative for trust_interlaced on the first field,
+ * we will realise our mistake here when we see that the picture number is that
+ * of the previous picture. We cannot recover the frame and should discard the
+ * second field to keep the correct number of output frames.
+ */
+ if (output->PicInfo.picture_number == priv->last_picture && !priv->need_second_field) {
+ av_log(avctx, AV_LOG_WARNING,
+ "Incorrectly guessed progressive frame. Discarding second field\n");
+ /* Returning without providing a picture. */
+ return RET_OK;
+ }
+
+ interlaced = (output->PicInfo.flags & VDEC_FLAG_INTERLACED_SRC) &&
+ trust_interlaced;
+
+ if (!trust_interlaced && (decoder_status.picNumFlags & ~0x40000000) == 0) {
+ av_log(avctx, AV_LOG_VERBOSE,
+ "Next picture number unknown. Assuming progressive frame.\n");
+ }
+
+ av_log(avctx, AV_LOG_VERBOSE, "Interlaced state: %d | trust_interlaced %d\n",
+ interlaced, trust_interlaced);
+
+ if (priv->pic.data[0] && !priv->need_second_field)
+ avctx->release_buffer(avctx, &priv->pic);
+
+ priv->need_second_field = interlaced && !priv->need_second_field;
+
+ priv->pic.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE |
+ FF_BUFFER_HINTS_REUSABLE;
+ if (!priv->pic.data[0]) {
+ if (avctx->get_buffer(avctx, &priv->pic) < 0) {
+ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
+ return RET_ERROR;
+ }
+ }
+
+ bwidth = av_image_get_linesize(avctx->pix_fmt, width, 0);
+ if (priv->is_70012) {
+ int pStride;
+
+ if (width <= 720)
+ pStride = 720;
+ else if (width <= 1280)
+ pStride = 1280;
+ else if (width <= 1080)
+ pStride = 1080;
+ sStride = av_image_get_linesize(avctx->pix_fmt, pStride, 0);
+ } else {
+ sStride = bwidth;
+ }
+
+ dStride = priv->pic.linesize[0];
+ dst = priv->pic.data[0];
+
+ av_log(priv->avctx, AV_LOG_VERBOSE, "CrystalHD: Copying out frame\n");
+
+ if (interlaced) {
+ int dY = 0;
+ int sY = 0;
+
+ height /= 2;
+ if (bottom_field) {
+ av_log(priv->avctx, AV_LOG_VERBOSE, "Interlaced: bottom field\n");
+ dY = 1;
+ } else {
+ av_log(priv->avctx, AV_LOG_VERBOSE, "Interlaced: top field\n");
+ dY = 0;
+ }
+
+ for (sY = 0; sY < height; dY++, sY++) {
+ memcpy(&(dst[dY * dStride]), &(src[sY * sStride]), bwidth);
+ dY++;
+ }
+ } else {
+ av_image_copy_plane(dst, dStride, src, sStride, bwidth, height);
+ }
+
+ priv->pic.interlaced_frame = interlaced;
+ if (interlaced)
+ priv->pic.top_field_first = !bottom_first;
+
+ priv->pic.pkt_pts = pkt_pts;
+
+ if (!priv->need_second_field) {
+ *data_size = sizeof(AVFrame);
+ *(AVFrame *)data = priv->pic;
+ }
+
+ /*
+ * Two types of PAFF content have been observed. One form causes the
+ * hardware to return a field pair and the other individual fields,
+ * even though the input is always individual fields. We must skip
+ * copying on the next decode() call to maintain pipeline length in
+ * the first case.
+ */
+ if (!interlaced && (output->PicInfo.flags & VDEC_FLAG_UNKNOWN_SRC) &&
+ (pic_type == PICT_TOP_FIELD || pic_type == PICT_BOTTOM_FIELD)) {
+ av_log(priv->avctx, AV_LOG_VERBOSE, "Fieldpair from two packets.\n");
+ return RET_SKIP_NEXT_COPY;
+ }
+
+ /*
+ * Testing has shown that in all cases where we don't want to return the
+ * full frame immediately, VDEC_FLAG_UNKNOWN_SRC is set.
+ */
+ return priv->need_second_field &&
+ !(output->PicInfo.flags & VDEC_FLAG_UNKNOWN_SRC) ?
+ RET_COPY_NEXT_FIELD : RET_OK;
+}
+
+
+static inline CopyRet receive_frame(AVCodecContext *avctx,
+ void *data, int *data_size)
+{
+ BC_STATUS ret;
+ BC_DTS_PROC_OUT output = {
+ .PicInfo.width = avctx->width,
+ .PicInfo.height = avctx->height,
+ };
+ CHDContext *priv = avctx->priv_data;
+ HANDLE dev = priv->dev;
+
+ *data_size = 0;
+
+ // Request decoded data from the driver
+ ret = DtsProcOutputNoCopy(dev, OUTPUT_PROC_TIMEOUT, &output);
+ if (ret == BC_STS_FMT_CHANGE) {
+ av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: Initial format change\n");
+ avctx->width = output.PicInfo.width;
+ avctx->height = output.PicInfo.height;
+ return RET_COPY_AGAIN;
+ } else if (ret == BC_STS_SUCCESS) {
+ int copy_ret = -1;
+ if (output.PoutFlags & BC_POUT_FLAGS_PIB_VALID) {
+ if (priv->last_picture == -1) {
+ /*
+ * Init to one less, so that the incrementing code doesn't
+ * need to be special-cased.
+ */
+ priv->last_picture = output.PicInfo.picture_number - 1;
+ }
+
+ if (avctx->codec->id == CODEC_ID_MPEG4 &&
+ output.PicInfo.timeStamp == 0 && priv->bframe_bug) {
+ av_log(avctx, AV_LOG_VERBOSE,
+ "CrystalHD: Not returning packed frame twice.\n");
+ priv->last_picture++;
+ DtsReleaseOutputBuffs(dev, NULL, FALSE);
+ return RET_COPY_AGAIN;
+ }
+
+ print_frame_info(priv, &output);
+
+ if (priv->last_picture + 1 < output.PicInfo.picture_number) {
+ av_log(avctx, AV_LOG_WARNING,
+ "CrystalHD: Picture Number discontinuity\n");
+ /*
+ * Have we lost frames? If so, we need to shrink the
+ * pipeline length appropriately.
+ *
+ * XXX: I have no idea what the semantics of this situation
+ * are so I don't even know if we've lost frames or which
+ * ones.
+ *
+ * In any case, only warn the first time.
+ */
+ priv->last_picture = output.PicInfo.picture_number - 1;
+ }
+
+ copy_ret = copy_frame(avctx, &output, data, data_size);
+ if (*data_size > 0) {
+ avctx->has_b_frames--;
+ priv->last_picture++;
+ av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: Pipeline length: %u\n",
+ avctx->has_b_frames);
+ }
+ } else {
+ /*
+ * An invalid frame has been consumed.
+ */
+ av_log(avctx, AV_LOG_ERROR, "CrystalHD: ProcOutput succeeded with "
+ "invalid PIB\n");
+ avctx->has_b_frames--;
+ copy_ret = RET_OK;
+ }
+ DtsReleaseOutputBuffs(dev, NULL, FALSE);
+
+ return copy_ret;
+ } else if (ret == BC_STS_BUSY) {
+ return RET_COPY_AGAIN;
+ } else {
+ av_log(avctx, AV_LOG_ERROR, "CrystalHD: ProcOutput failed %d\n", ret);
+ return RET_ERROR;
+ }
+}
+
+
+static int decode(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)
+{
+ BC_STATUS ret;
+ BC_DTS_STATUS decoder_status;
+ CopyRet rec_ret;
+ CHDContext *priv = avctx->priv_data;
+ HANDLE dev = priv->dev;
+ uint8_t *in_data = avpkt->data;
+ int len = avpkt->size;
+ int free_data = 0;
+ uint8_t pic_type = 0;
+
+ av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: decode_frame\n");
+
+ if (avpkt->size == 7 && !priv->bframe_bug) {
+ /*
+ * The use of a drop frame triggers the bug
+ */
+ av_log(avctx, AV_LOG_INFO,
+ "CrystalHD: Enabling work-around for packed b-frame bug\n");
+ priv->bframe_bug = 1;
+ } else if (avpkt->size == 8 && priv->bframe_bug) {
+ /*
+ * Delay frames don't trigger the bug
+ */
+ av_log(avctx, AV_LOG_INFO,
+ "CrystalHD: Disabling work-around for packed b-frame bug\n");
+ priv->bframe_bug = 0;
+ }
+
+ if (len) {
+ int32_t tx_free = (int32_t)DtsTxFreeSize(dev);
+
+ if (priv->parser) {
+ int ret = 0;
+
+ if (priv->bsfc) {
+ ret = av_bitstream_filter_filter(priv->bsfc, avctx, NULL,
+ &in_data, &len,
+ avpkt->data, len, 0);
+ }
+ free_data = ret > 0;
+
+ if (ret >= 0) {
+ uint8_t *pout;
+ int psize;
+ int index;
+ H264Context *h = priv->parser->priv_data;
+
+ index = av_parser_parse2(priv->parser, avctx, &pout, &psize,
+ in_data, len, avctx->pkt->pts,
+ avctx->pkt->dts, 0);
+ if (index < 0) {
+ av_log(avctx, AV_LOG_WARNING,
+ "CrystalHD: Failed to parse h.264 packet to "
+ "detect interlacing.\n");
+ } else if (index != len) {
+ av_log(avctx, AV_LOG_WARNING,
+ "CrystalHD: Failed to parse h.264 packet "
+ "completely. Interlaced frames may be "
+ "incorrectly detected\n.");
+ } else {
+ av_log(avctx, AV_LOG_VERBOSE,
+ "CrystalHD: parser picture type %d\n",
+ h->s.picture_structure);
+ pic_type = h->s.picture_structure;
+ }
+ } else {
+ av_log(avctx, AV_LOG_WARNING,
+ "CrystalHD: mp4toannexb filter failed to filter "
+ "packet. Interlaced frames may be incorrectly "
+ "detected.\n");
+ }
+ }
+
+ if (len < tx_free - 1024) {
+ /*
+ * Despite being notionally opaque, either libcrystalhd or
+ * the hardware itself will mangle pts values that are too
+ * small or too large. The docs claim it should be in units
+ * of 100ns. Given that we're nominally dealing with a black
+ * box on both sides, any transform we do has no guarantee of
+ * avoiding mangling so we need to build a mapping to values
+ * we know will not be mangled.
+ */
+ uint64_t pts = opaque_list_push(priv, avctx->pkt->pts, pic_type);
+ if (!pts) {
+ if (free_data) {
+ av_freep(&in_data);
+ }
+ return AVERROR(ENOMEM);
+ }
+ av_log(priv->avctx, AV_LOG_VERBOSE,
+ "input \"pts\": %"PRIu64"\n", pts);
+ ret = DtsProcInput(dev, in_data, len, pts, 0);
+ if (free_data) {
+ av_freep(&in_data);
+ }
+ if (ret == BC_STS_BUSY) {
+ av_log(avctx, AV_LOG_WARNING,
+ "CrystalHD: ProcInput returned busy\n");
+ usleep(BASE_WAIT);
+ return AVERROR(EBUSY);
+ } else if (ret != BC_STS_SUCCESS) {
+ av_log(avctx, AV_LOG_ERROR,
+ "CrystalHD: ProcInput failed: %u\n", ret);
+ return -1;
+ }
+ avctx->has_b_frames++;
+ } else {
+ av_log(avctx, AV_LOG_WARNING, "CrystalHD: Input buffer full\n");
+ len = 0; // We didn't consume any bytes.
+ }
+ } else {
+ av_log(avctx, AV_LOG_INFO, "CrystalHD: No more input data\n");
+ }
+
+ if (priv->skip_next_output) {
+ av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: Skipping next output.\n");
+ priv->skip_next_output = 0;
+ avctx->has_b_frames--;
+ return len;
+ }
+
+ ret = DtsGetDriverStatus(dev, &decoder_status);
+ if (ret != BC_STS_SUCCESS) {
+ av_log(avctx, AV_LOG_ERROR, "CrystalHD: GetDriverStatus failed\n");
+ return -1;
+ }
+
+ /*
+ * No frames ready. Don't try to extract.
+ *
+ * Empirical testing shows that ReadyListCount can be a damn lie,
+ * and ProcOut still fails when count > 0. The same testing showed
+ * that two more iterations were needed before ProcOutput would
+ * succeed.
+ */
+ if (priv->output_ready < 2) {
+ if (decoder_status.ReadyListCount != 0)
+ priv->output_ready++;
+ usleep(BASE_WAIT);
+ av_log(avctx, AV_LOG_INFO, "CrystalHD: Filling pipeline.\n");
+ return len;
+ } else if (decoder_status.ReadyListCount == 0) {
+ /*
+ * After the pipeline is established, if we encounter a lack of frames
+ * that probably means we're not giving the hardware enough time to
+ * decode them, so start increasing the wait time at the end of a
+ * decode call.
+ */
+ usleep(BASE_WAIT);
+ priv->decode_wait += WAIT_UNIT;
+ av_log(avctx, AV_LOG_INFO, "CrystalHD: No frames ready. Returning\n");
+ return len;
+ }
+
+ do {
+ rec_ret = receive_frame(avctx, data, data_size);
+ if (rec_ret == RET_OK && *data_size == 0) {
+ /*
+ * This case is for when the encoded fields are stored
+ * separately and we get a separate avpkt for each one. To keep
+ * the pipeline stable, we should return nothing and wait for
+ * the next time round to grab the second field.
+ * H.264 PAFF is an example of this.
+ */
+ av_log(avctx, AV_LOG_VERBOSE, "Returning after first field.\n");
+ avctx->has_b_frames--;
+ } else if (rec_ret == RET_COPY_NEXT_FIELD) {
+ /*
+ * This case is for when the encoded fields are stored in a
+ * single avpkt but the hardware returns then separately. Unless
+ * we grab the second field before returning, we'll slip another
+ * frame in the pipeline and if that happens a lot, we're sunk.
+ * So we have to get that second field now.
+ * Interlaced mpeg2 and vc1 are examples of this.
+ */
+ av_log(avctx, AV_LOG_VERBOSE, "Trying to get second field.\n");
+ while (1) {
+ usleep(priv->decode_wait);
+ ret = DtsGetDriverStatus(dev, &decoder_status);
+ if (ret == BC_STS_SUCCESS &&
+ decoder_status.ReadyListCount > 0) {
+ rec_ret = receive_frame(avctx, data, data_size);
+ if ((rec_ret == RET_OK && *data_size > 0) ||
+ rec_ret == RET_ERROR)
+ break;
+ }
+ }
+ av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: Got second field.\n");
+ } else if (rec_ret == RET_SKIP_NEXT_COPY) {
+ /*
+ * Two input packets got turned into a field pair. Gawd.
+ */
+ av_log(avctx, AV_LOG_VERBOSE,
+ "Don't output on next decode call.\n");
+ priv->skip_next_output = 1;
+ }
+ /*
+ * If rec_ret == RET_COPY_AGAIN, that means that either we just handled
+ * a FMT_CHANGE event and need to go around again for the actual frame,
+ * we got a busy status and need to try again, or we're dealing with
+ * packed b-frames, where the hardware strangely returns the packed
+ * p-frame twice. We choose to keep the second copy as it carries the
+ * valid pts.
+ */
+ } while (rec_ret == RET_COPY_AGAIN);
+ usleep(priv->decode_wait);
+ return len;
+}
+
+
+#if CONFIG_H264_CRYSTALHD_DECODER
+static AVClass h264_class = {
+ "h264_crystalhd",
+ av_default_item_name,
+ options,
+ LIBAVUTIL_VERSION_INT,
+};
+
+AVCodec ff_h264_crystalhd_decoder = {
+ .name = "h264_crystalhd",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_H264,
+ .priv_data_size = sizeof(CHDContext),
+ .init = init,
+ .close = uninit,
+ .decode = decode,
+ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY | CODEC_CAP_EXPERIMENTAL,
+ .flush = flush,
+ .long_name = NULL_IF_CONFIG_SMALL("H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (CrystalHD acceleration)"),
+ .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUYV422, PIX_FMT_NONE},
+ .priv_class = &h264_class,
+};
+#endif
+
+#if CONFIG_MPEG2_CRYSTALHD_DECODER
+static AVClass mpeg2_class = {
+ "mpeg2_crystalhd",
+ av_default_item_name,
+ options,
+ LIBAVUTIL_VERSION_INT,
+};
+
+AVCodec ff_mpeg2_crystalhd_decoder = {
+ .name = "mpeg2_crystalhd",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_MPEG2VIDEO,
+ .priv_data_size = sizeof(CHDContext),
+ .init = init,
+ .close = uninit,
+ .decode = decode,
+ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY | CODEC_CAP_EXPERIMENTAL,
+ .flush = flush,
+ .long_name = NULL_IF_CONFIG_SMALL("MPEG-2 Video (CrystalHD acceleration)"),
+ .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUYV422, PIX_FMT_NONE},
+ .priv_class = &mpeg2_class,
+};
+#endif
+
+#if CONFIG_MPEG4_CRYSTALHD_DECODER
+static AVClass mpeg4_class = {
+ "mpeg4_crystalhd",
+ av_default_item_name,
+ options,
+ LIBAVUTIL_VERSION_INT,
+};
+
+AVCodec ff_mpeg4_crystalhd_decoder = {
+ .name = "mpeg4_crystalhd",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_MPEG4,
+ .priv_data_size = sizeof(CHDContext),
+ .init = init,
+ .close = uninit,
+ .decode = decode,
+ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY | CODEC_CAP_EXPERIMENTAL,
+ .flush = flush,
+ .long_name = NULL_IF_CONFIG_SMALL("MPEG-4 Part 2 (CrystalHD acceleration)"),
+ .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUYV422, PIX_FMT_NONE},
+ .priv_class = &mpeg4_class,
+};
+#endif
+
+#if CONFIG_MSMPEG4_CRYSTALHD_DECODER
+static AVClass msmpeg4_class = {
+ "msmpeg4_crystalhd",
+ av_default_item_name,
+ options,
+ LIBAVUTIL_VERSION_INT,
+};
+
+AVCodec ff_msmpeg4_crystalhd_decoder = {
+ .name = "msmpeg4_crystalhd",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_MSMPEG4V3,
+ .priv_data_size = sizeof(CHDContext),
+ .init = init,
+ .close = uninit,
+ .decode = decode,
+ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY | CODEC_CAP_EXPERIMENTAL,
+ .flush = flush,
+ .long_name = NULL_IF_CONFIG_SMALL("MPEG-4 Part 2 Microsoft variant version 3 (CrystalHD acceleration)"),
+ .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUYV422, PIX_FMT_NONE},
+ .priv_class = &msmpeg4_class,
+};
+#endif
+
+#if CONFIG_VC1_CRYSTALHD_DECODER
+static AVClass vc1_class = {
+ "vc1_crystalhd",
+ av_default_item_name,
+ options,
+ LIBAVUTIL_VERSION_INT,
+};
+
+AVCodec ff_vc1_crystalhd_decoder = {
+ .name = "vc1_crystalhd",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_VC1,
+ .priv_data_size = sizeof(CHDContext),
+ .init = init,
+ .close = uninit,
+ .decode = decode,
+ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY | CODEC_CAP_EXPERIMENTAL,
+ .flush = flush,
+ .long_name = NULL_IF_CONFIG_SMALL("SMPTE VC-1 (CrystalHD acceleration)"),
+ .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUYV422, PIX_FMT_NONE},
+ .priv_class = &vc1_class,
+};
+#endif
+
+#if CONFIG_WMV3_CRYSTALHD_DECODER
+static AVClass wmv3_class = {
+ "wmv3_crystalhd",
+ av_default_item_name,
+ options,
+ LIBAVUTIL_VERSION_INT,
+};
+
+AVCodec ff_wmv3_crystalhd_decoder = {
+ .name = "wmv3_crystalhd",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_WMV3,
+ .priv_data_size = sizeof(CHDContext),
+ .init = init,
+ .close = uninit,
+ .decode = decode,
+ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY | CODEC_CAP_EXPERIMENTAL,
+ .flush = flush,
+ .long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 9 (CrystalHD acceleration)"),
+ .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUYV422, PIX_FMT_NONE},
+ .priv_class = &wmv3_class,
+};
+#endif
diff --git a/libavcodec/cscd.c b/libavcodec/cscd.c
index 3518929c18..8f7f132271 100644
--- a/libavcodec/cscd.c
+++ b/libavcodec/cscd.c
@@ -2,20 +2,20 @@
* CamStudio decoder
* Copyright (c) 2006 Reimar Doeffinger
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
@@ -231,6 +231,7 @@ static av_cold int decode_init(AVCodecContext *avctx) {
return 1;
}
c->bpp = avctx->bits_per_coded_sample;
+ avcodec_get_frame_defaults(&c->pic);
c->pic.data[0] = NULL;
c->linelen = avctx->width * avctx->bits_per_coded_sample / 8;
c->height = avctx->height;
@@ -255,15 +256,14 @@ static av_cold int decode_end(AVCodecContext *avctx) {
}
AVCodec ff_cscd_decoder = {
- "camstudio",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_CSCD,
- sizeof(CamStudioContext),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- CODEC_CAP_DR1,
+ .name = "camstudio",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_CSCD,
+ .priv_data_size = sizeof(CamStudioContext),
+ .init = decode_init,
+ .close = decode_end,
+ .decode = decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("CamStudio"),
};
diff --git a/libavcodec/cyuv.c b/libavcodec/cyuv.c
index ecdec17439..2df6087ae0 100644
--- a/libavcodec/cyuv.c
+++ b/libavcodec/cyuv.c
@@ -6,20 +6,20 @@
*
* Copyright (C) 2003 the ffmpeg project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -53,6 +53,7 @@ static av_cold int cyuv_decode_init(AVCodecContext *avctx)
return -1;
s->height = avctx->height;
avctx->pix_fmt = PIX_FMT_YUV411P;
+ avcodec_get_frame_defaults(&s->frame);
return 0;
}
@@ -179,32 +180,28 @@ static av_cold int cyuv_decode_end(AVCodecContext *avctx)
#if CONFIG_AURA_DECODER
AVCodec ff_aura_decoder = {
- "aura",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_AURA,
- sizeof(CyuvDecodeContext),
- cyuv_decode_init,
- NULL,
- cyuv_decode_end,
- cyuv_decode_frame,
- CODEC_CAP_DR1,
- NULL,
+ .name = "aura",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_AURA,
+ .priv_data_size = sizeof(CyuvDecodeContext),
+ .init = cyuv_decode_init,
+ .close = cyuv_decode_end,
+ .decode = cyuv_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Auravision AURA"),
};
#endif
#if CONFIG_CYUV_DECODER
AVCodec ff_cyuv_decoder = {
- "cyuv",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_CYUV,
- sizeof(CyuvDecodeContext),
- cyuv_decode_init,
- NULL,
- cyuv_decode_end,
- cyuv_decode_frame,
- CODEC_CAP_DR1,
- NULL,
+ .name = "cyuv",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_CYUV,
+ .priv_data_size = sizeof(CyuvDecodeContext),
+ .init = cyuv_decode_init,
+ .close = cyuv_decode_end,
+ .decode = cyuv_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Creative YUV (CYUV)"),
};
#endif
diff --git a/libavcodec/dca.c b/libavcodec/dca.c
index 58f3420586..d900d883bd 100644
--- a/libavcodec/dca.c
+++ b/libavcodec/dca.c
@@ -5,20 +5,20 @@
* Copyright (C) 2006 Benjamin Larsson
* Copyright (C) 2007 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -42,6 +42,10 @@
#include "dcadsp.h"
#include "fmtconvert.h"
+#if ARCH_ARM
+# include "arm/dca.h"
+#endif
+
//#define TRACE
#define DCA_PRIM_CHANNELS_MAX (7)
@@ -320,7 +324,7 @@ typedef struct {
int lfe_scale_factor;
/* Subband samples history (for ADPCM) */
- float subband_samples_hist[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][4];
+ DECLARE_ALIGNED(16, float, subband_samples_hist)[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][4];
DECLARE_ALIGNED(32, float, subband_fir_hist)[DCA_PRIM_CHANNELS_MAX][512];
DECLARE_ALIGNED(32, float, subband_fir_noidea)[DCA_PRIM_CHANNELS_MAX][32];
int hist_index[DCA_PRIM_CHANNELS_MAX];
@@ -898,15 +902,17 @@ static void qmf_32_subbands(DCAContext * s, int chans,
else /* Perfect reconstruction */
prCoeff = fir_32bands_perfect;
+ for (i = sb_act; i < 32; i++)
+ s->raXin[i] = 0.0;
+
/* Reconstructed channel sample index */
for (subindex = 0; subindex < 8; subindex++) {
/* Load in one sample from each subband and clear inactive subbands */
for (i = 0; i < sb_act; i++){
- uint32_t v = AV_RN32A(&samples_in[i][subindex]) ^ ((i-1)&2)<<30;
+ unsigned sign = (i - 1) & 2;
+ uint32_t v = AV_RN32A(&samples_in[i][subindex]) ^ sign << 30;
AV_WN32A(&s->raXin[i], v);
}
- for (; i < 32; i++)
- s->raXin[i] = 0.0;
s->synth.synth_filter_float(&s->imdct,
s->subband_fir_hist[chans], &s->hist_index[chans],
@@ -1056,6 +1062,16 @@ static int decode_blockcode(int code, int levels, int *values)
static const uint8_t abits_sizes[7] = { 7, 10, 12, 13, 15, 17, 19 };
static const uint8_t abits_levels[7] = { 3, 5, 7, 9, 13, 17, 25 };
+#ifndef int8x8_fmul_int32
+static inline void int8x8_fmul_int32(float *dst, const int8_t *src, int scale)
+{
+ float fscale = scale / 16.0;
+ int i;
+ for (i = 0; i < 8; i++)
+ dst[i] = src[i] * fscale;
+}
+#endif
+
static int dca_subsubframe(DCAContext * s, int base_channel, int block_index)
{
int k, l;
@@ -1160,19 +1176,16 @@ static int dca_subsubframe(DCAContext * s, int base_channel, int block_index)
for (l = s->vq_start_subband[k]; l < s->subband_activity[k]; l++) {
/* 1 vector -> 32 samples but we only need the 8 samples
* for this subsubframe. */
- int m;
+ int hfvq = s->high_freq_vq[k][l];
if (!s->debug_flag & 0x01) {
av_log(s->avctx, AV_LOG_DEBUG, "Stream with high frequencies VQ coding\n");
s->debug_flag |= 0x01;
}
- for (m = 0; m < 8; m++) {
- subband_samples[k][l][m] =
- high_freq_vq[s->high_freq_vq[k][l]][subsubframe * 8 +
- m]
- * (float) s->scale_factor[k][l][0] / 16.0;
- }
+ int8x8_fmul_int32(subband_samples[k][l],
+ &high_freq_vq[hfvq][subsubframe * 8],
+ s->scale_factor[k][l][0]);
}
}
@@ -1792,6 +1805,10 @@ static int dca_decode_frame(AVCodecContext * avctx,
s->output = DCA_STEREO;
avctx->channel_layout = AV_CH_LAYOUT_STEREO;
}
+ else if (avctx->request_channel_layout & AV_CH_LAYOUT_NATIVE) {
+ static const int8_t dca_channel_order_native[9] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
+ s->channel_order_tab = dca_channel_order_native;
+ }
} else {
av_log(avctx, AV_LOG_ERROR, "Non standard configuration %d !\n",s->amode);
return -1;
@@ -1799,7 +1816,7 @@ static int dca_decode_frame(AVCodecContext * avctx,
/* There is nothing that prevents a dts frame to change channel configuration
- but Libav doesn't support that so only set the channels if it is previously
+ but FFmpeg doesn't support that so only set the channels if it is previously
unset. Ideally during the first probe for channels the crc should be checked
and only set avctx->channels when the crc is ok. Right now the decoder could
set the channels based on a broken first frame.*/
@@ -1829,11 +1846,8 @@ static int dca_decode_frame(AVCodecContext * avctx,
float* back_chan = s->samples + s->channel_order_tab[s->xch_base_channel] * 256;
float* lt_chan = s->samples + s->channel_order_tab[s->xch_base_channel - 2] * 256;
float* rt_chan = s->samples + s->channel_order_tab[s->xch_base_channel - 1] * 256;
- int j;
- for(j = 0; j < 256; ++j) {
- lt_chan[j] -= back_chan[j] * M_SQRT1_2;
- rt_chan[j] -= back_chan[j] * M_SQRT1_2;
- }
+ s->dsp.vector_fmac_scalar(lt_chan, back_chan, -M_SQRT1_2, 256);
+ s->dsp.vector_fmac_scalar(rt_chan, back_chan, -M_SQRT1_2, 256);
}
if (avctx->sample_fmt == AV_SAMPLE_FMT_FLT) {
diff --git a/libavcodec/dca.h b/libavcodec/dca.h
index 8ea6049e0d..02c0a51ea8 100644
--- a/libavcodec/dca.h
+++ b/libavcodec/dca.h
@@ -5,20 +5,20 @@
* Copyright (C) 2006 Benjamin Larsson
* Copyright (C) 2007 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/dca_parser.c b/libavcodec/dca_parser.c
index 70a3e989ba..a956e7506b 100644
--- a/libavcodec/dca_parser.c
+++ b/libavcodec/dca_parser.c
@@ -5,20 +5,20 @@
* Copyright (C) 2006 Benjamin Larsson
* Copyright (C) 2007 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/dcadata.h b/libavcodec/dcadata.h
index ed3ec4ee52..02dbb0fe54 100644
--- a/libavcodec/dcadata.h
+++ b/libavcodec/dcadata.h
@@ -3,20 +3,20 @@
* Copyright (C) 2004 Gildas Bazin
* Copyright (c) 2006 Benjamin Larsson
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -4224,7 +4224,7 @@ static const float lossless_quant_d[32] = {
/* Vector quantization tables */
-static const int8_t high_freq_vq[1024][32] =
+DECLARE_ALIGNED(8, static const int8_t, high_freq_vq)[1024][32] =
{
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
diff --git a/libavcodec/dcadsp.c b/libavcodec/dcadsp.c
index 14932e6786..dd4994d276 100644
--- a/libavcodec/dcadsp.c
+++ b/libavcodec/dcadsp.c
@@ -2,20 +2,20 @@
* Copyright (c) 2004 Gildas Bazin
* Copyright (c) 2010 Mans Rullgard <mans@mansr.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/dcadsp.h b/libavcodec/dcadsp.h
index 3c6f1f9a9f..bb157f7650 100644
--- a/libavcodec/dcadsp.h
+++ b/libavcodec/dcadsp.h
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/dcaenc.c b/libavcodec/dcaenc.c
new file mode 100644
index 0000000000..eccff08c03
--- /dev/null
+++ b/libavcodec/dcaenc.c
@@ -0,0 +1,586 @@
+/*
+ * DCA encoder
+ * Copyright (C) 2008 Alexander E. Patrakov
+ * 2010 Benjamin Larsson
+ * 2011 Xiang Wang
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/common.h"
+#include "libavutil/avassert.h"
+#include "libavutil/audioconvert.h"
+#include "avcodec.h"
+#include "get_bits.h"
+#include "put_bits.h"
+#include "dcaenc.h"
+#include "dcadata.h"
+
+#undef NDEBUG
+
+#define MAX_CHANNELS 6
+#define DCA_SUBBANDS_32 32
+#define DCA_MAX_FRAME_SIZE 16383
+#define DCA_HEADER_SIZE 13
+
+#define DCA_SUBBANDS 32 ///< Subband activity count
+#define QUANTIZER_BITS 16
+#define SUBFRAMES 1
+#define SUBSUBFRAMES 4
+#define PCM_SAMPLES (SUBFRAMES*SUBSUBFRAMES*8)
+#define LFE_BITS 8
+#define LFE_INTERPOLATION 64
+#define LFE_PRESENT 2
+#define LFE_MISSING 0
+
+static const int8_t dca_lfe_index[] = {
+ 1,2,2,2,2,3,2,3,2,3,2,3,1,3,2,3
+};
+
+static const int8_t dca_channel_reorder_lfe[][9] = {
+ { 0, -1, -1, -1, -1, -1, -1, -1, -1 },
+ { 0, 1, -1, -1, -1, -1, -1, -1, -1 },
+ { 0, 1, -1, -1, -1, -1, -1, -1, -1 },
+ { 0, 1, -1, -1, -1, -1, -1, -1, -1 },
+ { 0, 1, -1, -1, -1, -1, -1, -1, -1 },
+ { 1, 2, 0, -1, -1, -1, -1, -1, -1 },
+ { 0, 1, -1, 2, -1, -1, -1, -1, -1 },
+ { 1, 2, 0, -1, 3, -1, -1, -1, -1 },
+ { 0, 1, -1, 2, 3, -1, -1, -1, -1 },
+ { 1, 2, 0, -1, 3, 4, -1, -1, -1 },
+ { 2, 3, -1, 0, 1, 4, 5, -1, -1 },
+ { 1, 2, 0, -1, 3, 4, 5, -1, -1 },
+ { 0, -1, 4, 5, 2, 3, 1, -1, -1 },
+ { 3, 4, 1, -1, 0, 2, 5, 6, -1 },
+ { 2, 3, -1, 5, 7, 0, 1, 4, 6 },
+ { 3, 4, 1, -1, 0, 2, 5, 7, 6 },
+};
+
+static const int8_t dca_channel_reorder_nolfe[][9] = {
+ { 0, -1, -1, -1, -1, -1, -1, -1, -1 },
+ { 0, 1, -1, -1, -1, -1, -1, -1, -1 },
+ { 0, 1, -1, -1, -1, -1, -1, -1, -1 },
+ { 0, 1, -1, -1, -1, -1, -1, -1, -1 },
+ { 0, 1, -1, -1, -1, -1, -1, -1, -1 },
+ { 1, 2, 0, -1, -1, -1, -1, -1, -1 },
+ { 0, 1, 2, -1, -1, -1, -1, -1, -1 },
+ { 1, 2, 0, 3, -1, -1, -1, -1, -1 },
+ { 0, 1, 2, 3, -1, -1, -1, -1, -1 },
+ { 1, 2, 0, 3, 4, -1, -1, -1, -1 },
+ { 2, 3, 0, 1, 4, 5, -1, -1, -1 },
+ { 1, 2, 0, 3, 4, 5, -1, -1, -1 },
+ { 0, 4, 5, 2, 3, 1, -1, -1, -1 },
+ { 3, 4, 1, 0, 2, 5, 6, -1, -1 },
+ { 2, 3, 5, 7, 0, 1, 4, 6, -1 },
+ { 3, 4, 1, 0, 2, 5, 7, 6, -1 },
+};
+
+typedef struct {
+ PutBitContext pb;
+ int32_t history[MAX_CHANNELS][512]; /* This is a circular buffer */
+ int start[MAX_CHANNELS];
+ int frame_size;
+ int prim_channels;
+ int lfe_channel;
+ int sample_rate_code;
+ int scale_factor[MAX_CHANNELS][DCA_SUBBANDS_32];
+ int lfe_scale_factor;
+ int lfe_data[SUBFRAMES*SUBSUBFRAMES*4];
+
+ int a_mode; ///< audio channels arrangement
+ int num_channel;
+ int lfe_state;
+ int lfe_offset;
+ const int8_t *channel_order_tab; ///< channel reordering table, lfe and non lfe
+
+ int32_t pcm[FFMAX(LFE_INTERPOLATION, DCA_SUBBANDS_32)];
+ int32_t subband[PCM_SAMPLES][MAX_CHANNELS][DCA_SUBBANDS_32]; /* [sample][channel][subband] */
+} DCAContext;
+
+static int32_t cos_table[128];
+
+static inline int32_t mul32(int32_t a, int32_t b)
+{
+ int64_t r = (int64_t) a * b;
+ /* round the result before truncating - improves accuracy */
+ return (r + 0x80000000) >> 32;
+}
+
+/* Integer version of the cosine modulated Pseudo QMF */
+
+static void qmf_init(void)
+{
+ int i;
+ int32_t c[17], s[17];
+ s[0] = 0; /* sin(index * PI / 64) * 0x7fffffff */
+ c[0] = 0x7fffffff; /* cos(index * PI / 64) * 0x7fffffff */
+
+ for (i = 1; i <= 16; i++) {
+ s[i] = 2 * (mul32(c[i - 1], 105372028) + mul32(s[i - 1], 2144896908));
+ c[i] = 2 * (mul32(c[i - 1], 2144896908) - mul32(s[i - 1], 105372028));
+ }
+
+ for (i = 0; i < 16; i++) {
+ cos_table[i ] = c[i] >> 3; /* avoid output overflow */
+ cos_table[i + 16] = s[16 - i] >> 3;
+ cos_table[i + 32] = -s[i] >> 3;
+ cos_table[i + 48] = -c[16 - i] >> 3;
+ cos_table[i + 64] = -c[i] >> 3;
+ cos_table[i + 80] = -s[16 - i] >> 3;
+ cos_table[i + 96] = s[i] >> 3;
+ cos_table[i + 112] = c[16 - i] >> 3;
+ }
+}
+
+static int32_t band_delta_factor(int band, int sample_num)
+{
+ int index = band * (2 * sample_num + 1);
+ if (band == 0)
+ return 0x07ffffff;
+ else
+ return cos_table[index & 127];
+}
+
+static void add_new_samples(DCAContext *c, const int32_t *in,
+ int count, int channel)
+{
+ int i;
+
+ /* Place new samples into the history buffer */
+ for (i = 0; i < count; i++) {
+ c->history[channel][c->start[channel] + i] = in[i];
+ av_assert0(c->start[channel] + i < 512);
+ }
+ c->start[channel] += count;
+ if (c->start[channel] == 512)
+ c->start[channel] = 0;
+ av_assert0(c->start[channel] < 512);
+}
+
+static void qmf_decompose(DCAContext *c, int32_t in[32], int32_t out[32],
+ int channel)
+{
+ int band, i, j, k;
+ int32_t resp;
+ int32_t accum[DCA_SUBBANDS_32] = {0};
+
+ add_new_samples(c, in, DCA_SUBBANDS_32, channel);
+
+ /* Calculate the dot product of the signal with the (possibly inverted)
+ reference decoder's response to this vector:
+ (0.0, 0.0, ..., 0.0, -1.0, 1.0, 0.0, ..., 0.0)
+ so that -1.0 cancels 1.0 from the previous step */
+
+ for (k = 48, j = 0, i = c->start[channel]; i < 512; k++, j++, i++)
+ accum[(k & 32) ? (31 - (k & 31)) : (k & 31)] += mul32(c->history[channel][i], UnQMF[j]);
+ for (i = 0; i < c->start[channel]; k++, j++, i++)
+ accum[(k & 32) ? (31 - (k & 31)) : (k & 31)] += mul32(c->history[channel][i], UnQMF[j]);
+
+ resp = 0;
+ /* TODO: implement FFT instead of this naive calculation */
+ for (band = 0; band < DCA_SUBBANDS_32; band++) {
+ for (j = 0; j < 32; j++)
+ resp += mul32(accum[j], band_delta_factor(band, j));
+
+ out[band] = (band & 2) ? (-resp) : resp;
+ }
+}
+
+static int32_t lfe_fir_64i[512];
+static int lfe_downsample(DCAContext *c, int32_t in[LFE_INTERPOLATION])
+{
+ int i, j;
+ int channel = c->prim_channels;
+ int32_t accum = 0;
+
+ add_new_samples(c, in, LFE_INTERPOLATION, channel);
+ for (i = c->start[channel], j = 0; i < 512; i++, j++)
+ accum += mul32(c->history[channel][i], lfe_fir_64i[j]);
+ for (i = 0; i < c->start[channel]; i++, j++)
+ accum += mul32(c->history[channel][i], lfe_fir_64i[j]);
+ return accum;
+}
+
+static void init_lfe_fir(void)
+{
+ static int initialized = 0;
+ int i;
+ if (initialized)
+ return;
+
+ for (i = 0; i < 512; i++)
+ lfe_fir_64i[i] = lfe_fir_64[i] * (1 << 25); //float -> int32_t
+ initialized = 1;
+}
+
+static void put_frame_header(DCAContext *c)
+{
+ /* SYNC */
+ put_bits(&c->pb, 16, 0x7ffe);
+ put_bits(&c->pb, 16, 0x8001);
+
+ /* Frame type: normal */
+ put_bits(&c->pb, 1, 1);
+
+ /* Deficit sample count: none */
+ put_bits(&c->pb, 5, 31);
+
+ /* CRC is not present */
+ put_bits(&c->pb, 1, 0);
+
+ /* Number of PCM sample blocks */
+ put_bits(&c->pb, 7, PCM_SAMPLES-1);
+
+ /* Primary frame byte size */
+ put_bits(&c->pb, 14, c->frame_size-1);
+
+ /* Audio channel arrangement: L + R (stereo) */
+ put_bits(&c->pb, 6, c->num_channel);
+
+ /* Core audio sampling frequency */
+ put_bits(&c->pb, 4, c->sample_rate_code);
+
+ /* Transmission bit rate: 1411.2 kbps */
+ put_bits(&c->pb, 5, 0x16); /* FIXME: magic number */
+
+ /* Embedded down mix: disabled */
+ put_bits(&c->pb, 1, 0);
+
+ /* Embedded dynamic range flag: not present */
+ put_bits(&c->pb, 1, 0);
+
+ /* Embedded time stamp flag: not present */
+ put_bits(&c->pb, 1, 0);
+
+ /* Auxiliary data flag: not present */
+ put_bits(&c->pb, 1, 0);
+
+ /* HDCD source: no */
+ put_bits(&c->pb, 1, 0);
+
+ /* Extension audio ID: N/A */
+ put_bits(&c->pb, 3, 0);
+
+ /* Extended audio data: not present */
+ put_bits(&c->pb, 1, 0);
+
+ /* Audio sync word insertion flag: after each sub-frame */
+ put_bits(&c->pb, 1, 0);
+
+ /* Low frequency effects flag: not present or interpolation factor=64 */
+ put_bits(&c->pb, 2, c->lfe_state);
+
+ /* Predictor history switch flag: on */
+ put_bits(&c->pb, 1, 1);
+
+ /* No CRC */
+ /* Multirate interpolator switch: non-perfect reconstruction */
+ put_bits(&c->pb, 1, 0);
+
+ /* Encoder software revision: 7 */
+ put_bits(&c->pb, 4, 7);
+
+ /* Copy history: 0 */
+ put_bits(&c->pb, 2, 0);
+
+ /* Source PCM resolution: 16 bits, not DTS ES */
+ put_bits(&c->pb, 3, 0);
+
+ /* Front sum/difference coding: no */
+ put_bits(&c->pb, 1, 0);
+
+ /* Surrounds sum/difference coding: no */
+ put_bits(&c->pb, 1, 0);
+
+ /* Dialog normalization: 0 dB */
+ put_bits(&c->pb, 4, 0);
+}
+
+static void put_primary_audio_header(DCAContext *c)
+{
+ static const int bitlen[11] = { 0, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3 };
+ static const int thr[11] = { 0, 1, 3, 3, 3, 3, 7, 7, 7, 7, 7 };
+
+ int ch, i;
+ /* Number of subframes */
+ put_bits(&c->pb, 4, SUBFRAMES - 1);
+
+ /* Number of primary audio channels */
+ put_bits(&c->pb, 3, c->prim_channels - 1);
+
+ /* Subband activity count */
+ for (ch = 0; ch < c->prim_channels; ch++)
+ put_bits(&c->pb, 5, DCA_SUBBANDS - 2);
+
+ /* High frequency VQ start subband */
+ for (ch = 0; ch < c->prim_channels; ch++)
+ put_bits(&c->pb, 5, DCA_SUBBANDS - 1);
+
+ /* Joint intensity coding index: 0, 0 */
+ for (ch = 0; ch < c->prim_channels; ch++)
+ put_bits(&c->pb, 3, 0);
+
+ /* Transient mode codebook: A4, A4 (arbitrary) */
+ for (ch = 0; ch < c->prim_channels; ch++)
+ put_bits(&c->pb, 2, 0);
+
+ /* Scale factor code book: 7 bit linear, 7-bit sqrt table (for each channel) */
+ for (ch = 0; ch < c->prim_channels; ch++)
+ put_bits(&c->pb, 3, 6);
+
+ /* Bit allocation quantizer select: linear 5-bit */
+ for (ch = 0; ch < c->prim_channels; ch++)
+ put_bits(&c->pb, 3, 6);
+
+ /* Quantization index codebook select: dummy data
+ to avoid transmission of scale factor adjustment */
+
+ for (i = 1; i < 11; i++)
+ for (ch = 0; ch < c->prim_channels; ch++)
+ put_bits(&c->pb, bitlen[i], thr[i]);
+
+ /* Scale factor adjustment index: not transmitted */
+}
+
+/**
+ * 8-23 bits quantization
+ * @param sample
+ * @param bits
+ */
+static inline uint32_t quantize(int32_t sample, int bits)
+{
+ av_assert0(sample < 1 << (bits - 1));
+ av_assert0(sample >= -(1 << (bits - 1)));
+ return sample & ((1 << bits) - 1);
+}
+
+static inline int find_scale_factor7(int64_t max_value, int bits)
+{
+ int i = 0, j = 128, q;
+ max_value = ((max_value << 15) / lossy_quant[bits + 3]) >> (bits - 1);
+ while (i < j) {
+ q = (i + j) >> 1;
+ if (max_value < scale_factor_quant7[q])
+ j = q;
+ else
+ i = q + 1;
+ }
+ av_assert1(i < 128);
+ return i;
+}
+
+static inline void put_sample7(DCAContext *c, int64_t sample, int bits,
+ int scale_factor)
+{
+ sample = (sample << 15) / ((int64_t) lossy_quant[bits + 3] * scale_factor_quant7[scale_factor]);
+ put_bits(&c->pb, bits, quantize((int) sample, bits));
+}
+
+static void put_subframe(DCAContext *c,
+ int32_t subband_data[8 * SUBSUBFRAMES][MAX_CHANNELS][32],
+ int subframe)
+{
+ int i, sub, ss, ch, max_value;
+ int32_t *lfe_data = c->lfe_data + 4 * SUBSUBFRAMES * subframe;
+
+ /* Subsubframes count */
+ put_bits(&c->pb, 2, SUBSUBFRAMES -1);
+
+ /* Partial subsubframe sample count: dummy */
+ put_bits(&c->pb, 3, 0);
+
+ /* Prediction mode: no ADPCM, in each channel and subband */
+ for (ch = 0; ch < c->prim_channels; ch++)
+ for (sub = 0; sub < DCA_SUBBANDS; sub++)
+ put_bits(&c->pb, 1, 0);
+
+ /* Prediction VQ addres: not transmitted */
+ /* Bit allocation index */
+ for (ch = 0; ch < c->prim_channels; ch++)
+ for (sub = 0; sub < DCA_SUBBANDS; sub++)
+ put_bits(&c->pb, 5, QUANTIZER_BITS+3);
+
+ if (SUBSUBFRAMES > 1) {
+ /* Transition mode: none for each channel and subband */
+ for (ch = 0; ch < c->prim_channels; ch++)
+ for (sub = 0; sub < DCA_SUBBANDS; sub++)
+ put_bits(&c->pb, 1, 0); /* codebook A4 */
+ }
+
+ /* Determine scale_factor */
+ for (ch = 0; ch < c->prim_channels; ch++)
+ for (sub = 0; sub < DCA_SUBBANDS; sub++) {
+ max_value = 0;
+ for (i = 0; i < 8 * SUBSUBFRAMES; i++)
+ max_value = FFMAX(max_value, FFABS(subband_data[i][ch][sub]));
+ c->scale_factor[ch][sub] = find_scale_factor7(max_value, QUANTIZER_BITS);
+ }
+
+ if (c->lfe_channel) {
+ max_value = 0;
+ for (i = 0; i < 4 * SUBSUBFRAMES; i++)
+ max_value = FFMAX(max_value, FFABS(lfe_data[i]));
+ c->lfe_scale_factor = find_scale_factor7(max_value, LFE_BITS);
+ }
+
+ /* Scale factors: the same for each channel and subband,
+ encoded according to Table D.1.2 */
+ for (ch = 0; ch < c->prim_channels; ch++)
+ for (sub = 0; sub < DCA_SUBBANDS; sub++)
+ put_bits(&c->pb, 7, c->scale_factor[ch][sub]);
+
+ /* Joint subband scale factor codebook select: not transmitted */
+ /* Scale factors for joint subband coding: not transmitted */
+ /* Stereo down-mix coefficients: not transmitted */
+ /* Dynamic range coefficient: not transmitted */
+ /* Stde information CRC check word: not transmitted */
+ /* VQ encoded high frequency subbands: not transmitted */
+
+ /* LFE data */
+ if (c->lfe_channel) {
+ for (i = 0; i < 4 * SUBSUBFRAMES; i++)
+ put_sample7(c, lfe_data[i], LFE_BITS, c->lfe_scale_factor);
+ put_bits(&c->pb, 8, c->lfe_scale_factor);
+ }
+
+ /* Audio data (subsubframes) */
+
+ for (ss = 0; ss < SUBSUBFRAMES ; ss++)
+ for (ch = 0; ch < c->prim_channels; ch++)
+ for (sub = 0; sub < DCA_SUBBANDS; sub++)
+ for (i = 0; i < 8; i++)
+ put_sample7(c, subband_data[ss * 8 + i][ch][sub], QUANTIZER_BITS, c->scale_factor[ch][sub]);
+
+ /* DSYNC */
+ put_bits(&c->pb, 16, 0xffff);
+}
+
+static void put_frame(DCAContext *c,
+ int32_t subband_data[PCM_SAMPLES][MAX_CHANNELS][32],
+ uint8_t *frame)
+{
+ int i;
+ init_put_bits(&c->pb, frame + DCA_HEADER_SIZE, DCA_MAX_FRAME_SIZE-DCA_HEADER_SIZE);
+
+ put_primary_audio_header(c);
+ for (i = 0; i < SUBFRAMES; i++)
+ put_subframe(c, &subband_data[SUBSUBFRAMES * 8 * i], i);
+
+ flush_put_bits(&c->pb);
+ c->frame_size = (put_bits_count(&c->pb) >> 3) + DCA_HEADER_SIZE;
+
+ init_put_bits(&c->pb, frame, DCA_HEADER_SIZE);
+ put_frame_header(c);
+ flush_put_bits(&c->pb);
+}
+
+static int encode_frame(AVCodecContext *avctx, uint8_t *frame,
+ int buf_size, void *data)
+{
+ int i, k, channel;
+ DCAContext *c = avctx->priv_data;
+ int16_t *samples = data;
+ int real_channel = 0;
+
+ for (i = 0; i < PCM_SAMPLES; i ++) { /* i is the decimated sample number */
+ for (channel = 0; channel < c->prim_channels + 1; channel++) {
+ /* Get 32 PCM samples */
+ for (k = 0; k < 32; k++) { /* k is the sample number in a 32-sample block */
+ c->pcm[k] = samples[avctx->channels * (32 * i + k) + channel] << 16;
+ }
+ /* Put subband samples into the proper place */
+ real_channel = c->channel_order_tab[channel];
+ if (real_channel >= 0) {
+ qmf_decompose(c, c->pcm, &c->subband[i][real_channel][0], real_channel);
+ }
+ }
+ }
+
+ if (c->lfe_channel) {
+ for (i = 0; i < PCM_SAMPLES / 2; i++) {
+ for (k = 0; k < LFE_INTERPOLATION; k++) /* k is the sample number in a 32-sample block */
+ c->pcm[k] = samples[avctx->channels * (LFE_INTERPOLATION*i+k) + c->lfe_offset] << 16;
+ c->lfe_data[i] = lfe_downsample(c, c->pcm);
+ }
+ }
+
+ put_frame(c, c->subband, frame);
+
+ return c->frame_size;
+}
+
+static int encode_init(AVCodecContext *avctx)
+{
+ DCAContext *c = avctx->priv_data;
+ int i;
+
+ c->prim_channels = avctx->channels;
+ c->lfe_channel = (avctx->channels == 3 || avctx->channels == 6);
+
+ switch (avctx->channel_layout) {
+ case AV_CH_LAYOUT_STEREO: c->a_mode = 2; c->num_channel = 2; break;
+ case AV_CH_LAYOUT_5POINT0: c->a_mode = 9; c->num_channel = 9; break;
+ case AV_CH_LAYOUT_5POINT1: c->a_mode = 9; c->num_channel = 9; break;
+ case AV_CH_LAYOUT_5POINT0_BACK: c->a_mode = 9; c->num_channel = 9; break;
+ case AV_CH_LAYOUT_5POINT1_BACK: c->a_mode = 9; c->num_channel = 9; break;
+ default:
+ av_log(avctx, AV_LOG_ERROR,
+ "Only stereo, 5.0, 5.1 channel layouts supported at the moment!\n");
+ return AVERROR_PATCHWELCOME;
+ }
+
+ if (c->lfe_channel) {
+ init_lfe_fir();
+ c->prim_channels--;
+ c->channel_order_tab = dca_channel_reorder_lfe[c->a_mode];
+ c->lfe_state = LFE_PRESENT;
+ c->lfe_offset = dca_lfe_index[c->a_mode];
+ } else {
+ c->channel_order_tab = dca_channel_reorder_nolfe[c->a_mode];
+ c->lfe_state = LFE_MISSING;
+ }
+
+ for (i = 0; i < 16; i++) {
+ if (dca_sample_rates[i] && (dca_sample_rates[i] == avctx->sample_rate))
+ break;
+ }
+ if (i == 16) {
+ av_log(avctx, AV_LOG_ERROR, "Sample rate %iHz not supported, only ", avctx->sample_rate);
+ for (i = 0; i < 16; i++)
+ av_log(avctx, AV_LOG_ERROR, "%d, ", dca_sample_rates[i]);
+ av_log(avctx, AV_LOG_ERROR, "supported.\n");
+ return -1;
+ }
+ c->sample_rate_code = i;
+
+ avctx->frame_size = 32 * PCM_SAMPLES;
+
+ if (!cos_table[127])
+ qmf_init();
+ return 0;
+}
+
+AVCodec ff_dca_encoder = {
+ .name = "dca",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_DTS,
+ .priv_data_size = sizeof(DCAContext),
+ .init = encode_init,
+ .encode = encode_frame,
+ .capabilities = CODEC_CAP_EXPERIMENTAL,
+ .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
+};
diff --git a/libavcodec/dcaenc.h b/libavcodec/dcaenc.h
new file mode 100644
index 0000000000..63d03dc449
--- /dev/null
+++ b/libavcodec/dcaenc.h
@@ -0,0 +1,544 @@
+/*
+ * DCA encoder tables
+ * Copyright (C) 2008 Alexander E. Patrakov
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_DCAENC_H
+#define AVCODEC_DCAENC_H
+
+/* This is a scaled version of the response of the reference decoder to
+ this vector of subband samples: ( 1.0 0.0 0.0 ... 0.0 )
+ */
+
+static const int32_t UnQMF[512] = {
+ 7,
+ 4,
+ -961,
+ -2844,
+ -8024,
+ -18978,
+ -32081,
+ -15635,
+ -16582,
+ -18359,
+ -17180,
+ -14868,
+ -11664,
+ -8051,
+ -4477,
+ -1327,
+ -1670,
+ -6019,
+ -11590,
+ -18030,
+ -24762,
+ -30965,
+ -35947,
+ -36145,
+ -37223,
+ -86311,
+ -57024,
+ -27215,
+ -11274,
+ -4684,
+ 42,
+ 108,
+ 188,
+ 250,
+ -1007,
+ -596,
+ -2289,
+ -12218,
+ -27191,
+ -124367,
+ -184256,
+ -250538,
+ -323499,
+ -397784,
+ -468855,
+ -532072,
+ -583000,
+ -618041,
+ -777916,
+ -783868,
+ -765968,
+ -724740,
+ -662468,
+ -583058,
+ -490548,
+ -401623,
+ -296090,
+ -73154,
+ -36711,
+ -7766,
+ -2363,
+ -4905,
+ 2388,
+ 2681,
+ 5651,
+ 4086,
+ 71110,
+ 139742,
+ 188067,
+ 151237,
+ 101355,
+ 309917,
+ 343690,
+ 358839,
+ 357555,
+ 334606,
+ 289625,
+ 224152,
+ 142063,
+ 48725,
+ 74996,
+ 238425,
+ 411666,
+ 584160,
+ 744276,
+ 880730,
+ 983272,
+ 1041933,
+ 1054396,
+ 789531,
+ 851022,
+ 864032,
+ 675431,
+ 418134,
+ 35762,
+ 66911,
+ 103502,
+ 136403,
+ -55147,
+ -245269,
+ -499595,
+ -808470,
+ -1136858,
+ -2010912,
+ -2581654,
+ -3151901,
+ -3696328,
+ -4196599,
+ -4633761,
+ -4993229,
+ -5262495,
+ -5436311,
+ -477650,
+ -901314,
+ -1308090,
+ -1677468,
+ -1985525,
+ -2212848,
+ -2341196,
+ -2373915,
+ -2269552,
+ -2620489,
+ -2173858,
+ -1629954,
+ -946595,
+ -193499,
+ 1119459,
+ 1138657,
+ 1335311,
+ 1126544,
+ 2765033,
+ 3139603,
+ 3414913,
+ 3599213,
+ 3676363,
+ 3448981,
+ 3328726,
+ 3111551,
+ 2810887,
+ 2428657,
+ 1973684,
+ 1457278,
+ 893848,
+ 300995,
+ -292521,
+ -867621,
+ -1404936,
+ -1871278,
+ -2229831,
+ -2440932,
+ -2462684,
+ -2255006,
+ -1768898,
+ -1079574,
+ 82115,
+ 1660302,
+ 3660715,
+ 6123610,
+ 8329598,
+ 11888744,
+ 15722147,
+ 19737089,
+ 25647773,
+ 31039399,
+ 36868007,
+ 43124253,
+ 49737161,
+ 56495958,
+ 63668945,
+ 71039511,
+ 78540240,
+ 86089058,
+ 93600041,
+ 100981151,
+ 108136061,
+ 114970055,
+ 121718321,
+ 127566038,
+ 132774642,
+ 137247294,
+ 140894737,
+ 143635018,
+ 145395599,
+ 146114032,
+ 145742999,
+ 144211606,
+ 141594341,
+ 137808404,
+ 132914122,
+ 126912246,
+ 120243281,
+ 112155281,
+ 103338368,
+ 93904953,
+ 83439152,
+ 72921548,
+ 62192990,
+ 51434918,
+ 40894003,
+ 30786726,
+ 21384955,
+ 12939112,
+ 5718193,
+ -5790,
+ -3959261,
+ -5870978,
+ -5475538,
+ -2517061,
+ 3247310,
+ 12042937,
+ 24076729,
+ 39531397,
+ 58562863,
+ 81297002,
+ 107826748,
+ 138209187,
+ 172464115,
+ 210569037,
+ 252468018,
+ 298045453,
+ 347168648,
+ 399634888,
+ 455137189,
+ 513586535,
+ 574537650,
+ 637645129,
+ 702597163,
+ 768856566,
+ 836022040,
+ 903618096,
+ 971159680,
+ 1038137214,
+ 1103987353,
+ 1168195035,
+ 1230223053,
+ 1289539180,
+ 1345620373,
+ 1397957958,
+ 1446063657,
+ 1489474689,
+ 1527740502,
+ 1560502307,
+ 1587383079,
+ 1608071145,
+ 1622301248,
+ 1629859340,
+ 1630584888,
+ 1624373875,
+ 1611178348,
+ 1591018893,
+ 1563948667,
+ 1530105004,
+ 1489673227,
+ 1442904075,
+ 1390107674,
+ 1331590427,
+ 1267779478,
+ 1199115126,
+ 1126053392,
+ 1049146257,
+ 968928307,
+ 885965976,
+ 800851610,
+ 714186243,
+ 626590147,
+ 538672486,
+ 451042824,
+ 364299927,
+ 279026812,
+ 195785029,
+ 115109565,
+ 37503924,
+ -36564551,
+ -106668063,
+ -172421668,
+ -233487283,
+ -289575706,
+ -340448569,
+ -385919511,
+ -425854915,
+ -460174578,
+ -488840702,
+ -511893328,
+ -529405118,
+ -541489888,
+ -548312207,
+ -550036471,
+ -547005316,
+ -539436808,
+ -527630488,
+ -512084785,
+ -492941605,
+ -470665204,
+ -445668379,
+ -418328829,
+ -389072810,
+ -358293846,
+ -326396227,
+ -293769619,
+ -260792276,
+ -227825056,
+ -195208961,
+ -163262121,
+ -132280748,
+ -102533727,
+ -74230062,
+ -47600637,
+ -22817785,
+ -25786,
+ 20662895,
+ 39167253,
+ 55438413,
+ 69453741,
+ 81242430,
+ 90795329,
+ 98213465,
+ 103540643,
+ 106917392,
+ 108861938,
+ 108539682,
+ 106780704,
+ 103722568,
+ 99043289,
+ 93608686,
+ 87266209,
+ 80212203,
+ 72590022,
+ 64603428,
+ 56362402,
+ 48032218,
+ 39749162,
+ 31638971,
+ 23814664,
+ 16376190,
+ 9409836,
+ 2988017,
+ -2822356,
+ -7976595,
+ -12454837,
+ -16241147,
+ -19331944,
+ -21735011,
+ -23468284,
+ -24559822,
+ -25042936,
+ -25035583,
+ -24429587,
+ -23346408,
+ -21860411,
+ -20015718,
+ -17025330,
+ -14968728,
+ -12487138,
+ -9656319,
+ -7846681,
+ -5197816,
+ -2621904,
+ -144953,
+ 2144746,
+ 3990570,
+ 5845884,
+ 7454650,
+ 8820394,
+ 9929891,
+ 10784445,
+ 11390921,
+ 11762056,
+ 11916017,
+ 12261189,
+ 12117604,
+ 11815303,
+ 11374622,
+ 10815301,
+ 10157241,
+ 9418799,
+ 8629399,
+ 7780776,
+ 7303680,
+ 6353499,
+ 5392738,
+ 4457895,
+ 3543062,
+ 1305978,
+ 1402521,
+ 1084092,
+ 965652,
+ -151008,
+ -666667,
+ -1032157,
+ -1231475,
+ -1319043,
+ -1006023,
+ -915720,
+ -773426,
+ -612377,
+ -445864,
+ -291068,
+ -161337,
+ -66484,
+ -11725,
+ 133453,
+ 388184,
+ 615856,
+ 804033,
+ 942377,
+ 1022911,
+ 1041247,
+ 995854,
+ 891376,
+ 572246,
+ 457992,
+ 316365,
+ 172738,
+ 43037,
+ -117662,
+ -98542,
+ -70279,
+ -41458,
+ -535790,
+ -959038,
+ -1364456,
+ -1502265,
+ -1568530,
+ -2378681,
+ -2701111,
+ -2976407,
+ -3182552,
+ -3314415,
+ -3366600,
+ -3337701,
+ -3232252,
+ -3054999,
+ 1984841,
+ 1925903,
+ 1817377,
+ 1669153,
+ 1490069,
+ 1292040,
+ 1086223,
+ 890983,
+ 699163,
+ 201358,
+ 266971,
+ 296990,
+ 198419,
+ 91119,
+ 4737,
+ 5936,
+ 2553,
+ 2060,
+ -3828,
+ -1664,
+ -4917,
+ -20796,
+ -36822,
+ -131247,
+ -154923,
+ -162055,
+ -161354,
+ -148762,
+ -125754,
+ -94473,
+ -57821,
+ -19096,
+ 15172,
+ 43004,
+ 65624,
+ 81354,
+ 89325,
+ 89524,
+ 82766,
+ 71075,
+ 55128,
+ 13686,
+ 6921,
+ 1449,
+ 420,
+ 785,
+ -215,
+ -179,
+ -113,
+ -49,
+ 6002,
+ 16007,
+ 42978,
+ 100662,
+ 171472,
+ 83975,
+ 93702,
+ 108813,
+ 111893,
+ 110272,
+ 103914,
+ 93973,
+ 81606,
+ 68041,
+ -54058,
+ -60695,
+ -65277,
+ -67224,
+ -66213,
+ -62082,
+ -55574,
+ -42988,
+ -35272,
+ -63735,
+ -33501,
+ -12671,
+ -4038,
+ -1232,
+ 5,
+ 7
+};
+
+#endif /* AVCODEC_DCAENC_H */
diff --git a/libavcodec/dcahuff.h b/libavcodec/dcahuff.h
index 254fc76a91..cbc8429e59 100644
--- a/libavcodec/dcahuff.h
+++ b/libavcodec/dcahuff.h
@@ -3,20 +3,20 @@
* Copyright (C) 2004 Gildas Bazin
* Copyright (C) 2007 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/dct-test.c b/libavcodec/dct-test.c
index 689aef8fa9..c7cd9ee5e2 100644
--- a/libavcodec/dct-test.c
+++ b/libavcodec/dct-test.c
@@ -2,20 +2,20 @@
* (c) 2001 Fabrice Bellard
* 2007 Marc Hoffman <marc.hoffman@analog.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -71,7 +71,7 @@ struct algo {
const char *name;
void (*func)(DCTELEM *block);
enum formattag { NO_PERM, MMX_PERM, MMX_SIMPLE_PERM, SCALE_PERM,
- SSE2_PERM, PARTTRANS_PERM } format;
+ SSE2_PERM, PARTTRANS_PERM, TRANSPOSE_PERM } format;
int mm_support;
int nonspec;
};
@@ -88,7 +88,7 @@ static const struct algo fdct_tab[] = {
{ "REF-DBL", ff_ref_fdct, NO_PERM },
{ "FAAN", ff_faandct, FAAN_SCALE },
{ "IJG-AAN-INT", fdct_ifast, SCALE_PERM },
- { "IJG-LLM-INT", ff_jpeg_fdct_islow, NO_PERM },
+ { "IJG-LLM-INT", ff_jpeg_fdct_islow_8, NO_PERM },
#if HAVE_MMX
{ "MMX", ff_fdct_mmx, NO_PERM, AV_CPU_FLAG_MMX },
@@ -107,11 +107,27 @@ static const struct algo fdct_tab[] = {
{ 0 }
};
+#if HAVE_MMX
+void ff_prores_idct_put_10_sse2(uint16_t *dst, int linesize,
+ DCTELEM *block, int16_t *qmat);
+
+static void ff_prores_idct_put_10_sse2_wrap(uint16_t *dst){
+ int16_t qmat[64]; int i;
+ int16_t tmp[64];
+
+ for(i=0; i<64; i++){
+ qmat[i]=4;
+ tmp[i]= dst[i];
+ }
+ ff_prores_idct_put_10_sse2(dst, 16, tmp, qmat);
+}
+#endif
+
static const struct algo idct_tab[] = {
{ "FAANI", ff_faanidct, NO_PERM },
{ "REF-DBL", ff_ref_idct, NO_PERM },
{ "INT", j_rev_dct, MMX_PERM },
- { "SIMPLE-C", ff_simple_idct, NO_PERM },
+ { "SIMPLE-C", ff_simple_idct_8, NO_PERM },
#if HAVE_MMX
#if CONFIG_GPL
@@ -122,6 +138,7 @@ static const struct algo idct_tab[] = {
{ "XVID-MMX", ff_idct_xvid_mmx, NO_PERM, AV_CPU_FLAG_MMX, 1 },
{ "XVID-MMX2", ff_idct_xvid_mmx2, NO_PERM, AV_CPU_FLAG_MMX2, 1 },
{ "XVID-SSE2", ff_idct_xvid_sse2, SSE2_PERM, AV_CPU_FLAG_SSE2, 1 },
+ { "PR-SSE2", ff_prores_idct_put_10_sse2_wrap, TRANSPOSE_PERM, AV_CPU_FLAG_SSE2, 1 },
#endif
#if ARCH_BFIN
@@ -190,7 +207,6 @@ static void idct_mmx_init(void)
DECLARE_ALIGNED(16, static DCTELEM, block)[64];
DECLARE_ALIGNED(8, static DCTELEM, block1)[64];
-DECLARE_ALIGNED(8, static DCTELEM, block_org)[64];
static inline void mmx_emms(void)
{
@@ -200,7 +216,60 @@ static inline void mmx_emms(void)
#endif
}
-static int dct_error(const struct algo *dct, int test, int is_idct, int speed)
+static void init_block(DCTELEM block[64], int test, int is_idct, AVLFG *prng, int vals)
+{
+ int i, j;
+
+ memset(block, 0, 64 * sizeof(*block));
+
+ switch (test) {
+ case 0:
+ for (i = 0; i < 64; i++)
+ block[i] = (av_lfg_get(prng) % (2*vals)) -vals;
+ if (is_idct) {
+ ff_ref_fdct(block);
+ for (i = 0; i < 64; i++)
+ block[i] >>= 3;
+ }
+ break;
+ case 1:
+ j = av_lfg_get(prng) % 10 + 1;
+ for (i = 0; i < j; i++)
+ block[av_lfg_get(prng) % 64] = av_lfg_get(prng) % (2*vals) -vals;
+ break;
+ case 2:
+ block[ 0] = av_lfg_get(prng) % (16*vals) - (8*vals);
+ block[63] = (block[0] & 1) ^ 1;
+ break;
+ }
+}
+
+static void permute(DCTELEM dst[64], const DCTELEM src[64], int perm)
+{
+ int i;
+
+ if (perm == MMX_PERM) {
+ for (i = 0; i < 64; i++)
+ dst[idct_mmx_perm[i]] = src[i];
+ } else if (perm == MMX_SIMPLE_PERM) {
+ for (i = 0; i < 64; i++)
+ dst[idct_simple_mmx_perm[i]] = src[i];
+ } else if (perm == SSE2_PERM) {
+ for (i = 0; i < 64; i++)
+ dst[(i & 0x38) | idct_sse2_row_perm[i & 7]] = src[i];
+ } else if (perm == PARTTRANS_PERM) {
+ for (i = 0; i < 64; i++)
+ dst[(i & 0x24) | ((i & 3) << 3) | ((i >> 3) & 3)] = src[i];
+ } else if (perm == TRANSPOSE_PERM) {
+ for (i = 0; i < 64; i++)
+ dst[(i>>3) | ((i<<3)&0x38)] = src[i];
+ } else {
+ for (i = 0; i < 64; i++)
+ dst[i] = src[i];
+ }
+}
+
+static int dct_error(const struct algo *dct, int test, int is_idct, int speed, const int bits)
{
void (*ref)(DCTELEM *block) = is_idct ? ff_ref_idct : ff_ref_fdct;
int it, i, scale;
@@ -210,6 +279,7 @@ static int dct_error(const struct algo *dct, int test, int is_idct, int speed)
int maxout = 0;
int blockSumErrMax = 0, blockSumErr;
AVLFG prng;
+ const int vals=1<<bits;
double omse, ome;
int spec_err;
@@ -220,50 +290,8 @@ static int dct_error(const struct algo *dct, int test, int is_idct, int speed)
for (i = 0; i < 64; i++)
sysErr[i] = 0;
for (it = 0; it < NB_ITS; it++) {
- for (i = 0; i < 64; i++)
- block1[i] = 0;
- switch (test) {
- case 0:
- for (i = 0; i < 64; i++)
- block1[i] = (av_lfg_get(&prng) % 512) - 256;
- if (is_idct) {
- ff_ref_fdct(block1);
- for (i = 0; i < 64; i++)
- block1[i] >>= 3;
- }
- break;
- case 1: {
- int num = av_lfg_get(&prng) % 10 + 1;
- for (i = 0; i < num; i++)
- block1[av_lfg_get(&prng) % 64] =
- av_lfg_get(&prng) % 512 - 256;
- }
- break;
- case 2:
- block1[0] = av_lfg_get(&prng) % 4096 - 2048;
- block1[63] = (block1[0] & 1) ^ 1;
- break;
- }
-
- for (i = 0; i < 64; i++)
- block_org[i] = block1[i];
-
- if (dct->format == MMX_PERM) {
- for (i = 0; i < 64; i++)
- block[idct_mmx_perm[i]] = block1[i];
- } else if (dct->format == MMX_SIMPLE_PERM) {
- for (i = 0; i < 64; i++)
- block[idct_simple_mmx_perm[i]] = block1[i];
- } else if (dct->format == SSE2_PERM) {
- for (i = 0; i < 64; i++)
- block[(i & 0x38) | idct_sse2_row_perm[i & 7]] = block1[i];
- } else if (dct->format == PARTTRANS_PERM) {
- for (i = 0; i < 64; i++)
- block[(i & 0x24) | ((i & 3) << 3) | ((i >> 3) & 3)] = block1[i];
- } else {
- for (i = 0; i < 64; i++)
- block[i] = block1[i];
- }
+ init_block(block1, test, is_idct, &prng, vals);
+ permute(block, block1, dct->format);
dct->func(block);
mmx_emms();
@@ -308,7 +336,7 @@ static int dct_error(const struct algo *dct, int test, int is_idct, int speed)
spec_err = is_idct && (err_inf > 1 || omse > 0.02 || fabs(ome) > 0.0015);
- printf("%s %s: ppe=%d omse=%0.8f ome=%0.8f syserr=%0.8f maxout=%d blockSumErr=%d\n",
+ printf("%s %s: max_err=%d omse=%0.8f ome=%0.8f syserr=%0.8f maxout=%d blockSumErr=%d\n",
is_idct ? "IDCT" : "DCT", dct->name, err_inf,
omse, ome, (double) sysErrMax / NB_ITS,
maxout, blockSumErrMax);
@@ -320,45 +348,15 @@ static int dct_error(const struct algo *dct, int test, int is_idct, int speed)
return 0;
/* speed test */
- for (i = 0; i < 64; i++)
- block1[i] = 0;
-
- switch (test) {
- case 0:
- for (i = 0; i < 64; i++)
- block1[i] = av_lfg_get(&prng) % 512 - 256;
- if (is_idct) {
- ff_ref_fdct(block1);
- for (i = 0; i < 64; i++)
- block1[i] >>= 3;
- }
- break;
- case 1:
- case 2:
- block1[0] = av_lfg_get(&prng) % 512 - 256;
- block1[1] = av_lfg_get(&prng) % 512 - 256;
- block1[2] = av_lfg_get(&prng) % 512 - 256;
- block1[3] = av_lfg_get(&prng) % 512 - 256;
- break;
- }
- if (dct->format == MMX_PERM) {
- for (i = 0; i < 64; i++)
- block[idct_mmx_perm[i]] = block1[i];
- } else if (dct->format == MMX_SIMPLE_PERM) {
- for (i = 0; i < 64; i++)
- block[idct_simple_mmx_perm[i]] = block1[i];
- } else {
- for (i = 0; i < 64; i++)
- block[i] = block1[i];
- }
+ init_block(block, test, is_idct, &prng, vals);
+ permute(block1, block, dct->format);
ti = gettime();
it1 = 0;
do {
for (it = 0; it < NB_ITS_SPEED; it++) {
- for (i = 0; i < 64; i++)
- block[i] = block1[i];
+ memcpy(block, block1, sizeof(block));
dct->func(block);
}
it1 += NB_ITS_SPEED;
@@ -489,6 +487,25 @@ static void idct248_error(const char *name,
if (v > err_max)
err_max = v;
}
+#if 0
+ printf("ref=\n");
+ for(i=0;i<8;i++) {
+ int j;
+ for(j=0;j<8;j++) {
+ printf(" %3d", img_dest1[i*8+j]);
+ }
+ printf("\n");
+ }
+
+ printf("out=\n");
+ for(i=0;i<8;i++) {
+ int j;
+ for(j=0;j<8;j++) {
+ printf(" %3d", img_dest[i*8+j]);
+ }
+ printf("\n");
+ }
+#endif
}
printf("%s %s: err_inf=%d\n", 1 ? "IDCT248" : "DCT248", name, err_max);
@@ -514,10 +531,11 @@ static void idct248_error(const char *name,
static void help(void)
{
- printf("dct-test [-i] [<test-number>]\n"
+ printf("dct-test [-i] [<test-number>] [<bits>]\n"
"test-number 0 -> test with random matrixes\n"
" 1 -> test with random sparse matrixes\n"
" 2 -> do 3. test from mpeg4 std\n"
+ "bits Number of time domain bits to use, 8 is default\n"
"-i test IDCT implementations\n"
"-4 test IDCT248 implementations\n"
"-t speed test\n");
@@ -530,6 +548,7 @@ int main(int argc, char **argv)
int test = 1;
int speed = 0;
int err = 0;
+ int bits=8;
cpu_flags = av_get_cpu_flags();
@@ -566,6 +585,7 @@ int main(int argc, char **argv)
if (optind < argc)
test = atoi(argv[optind]);
+ if(optind+1 < argc) bits= atoi(argv[optind+1]);
printf("ffmpeg DCT/IDCT test\n");
@@ -575,7 +595,7 @@ int main(int argc, char **argv)
const struct algo *algos = test_idct ? idct_tab : fdct_tab;
for (i = 0; algos[i].name; i++)
if (!(~cpu_flags & algos[i].mm_support)) {
- err |= dct_error(&algos[i], test, test_idct, speed);
+ err |= dct_error(&algos[i], test, test_idct, speed, bits);
}
}
diff --git a/libavcodec/dct.c b/libavcodec/dct.c
index 5c63af30a1..c30cff664e 100644
--- a/libavcodec/dct.c
+++ b/libavcodec/dct.c
@@ -4,20 +4,20 @@
* Copyright (c) 2010 Alex Converse <alex.converse@gmail.com>
* Copyright (c) 2010 Vitor Sessak
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/dct.h b/libavcodec/dct.h
index c898856279..bb17d75d0c 100644
--- a/libavcodec/dct.h
+++ b/libavcodec/dct.h
@@ -4,20 +4,20 @@
* Copyright (c) 2010 Alex Converse <alex.converse@gmail.com>
* Copyright (c) 2010 Vitor Sessak
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/dct32.c b/libavcodec/dct32.c
index 272e0dbf95..fb53d53ab1 100644
--- a/libavcodec/dct32.c
+++ b/libavcodec/dct32.c
@@ -2,20 +2,20 @@
* Template for the Discrete Cosine Transform for 32 samples
* Copyright (c) 2001, 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/dctref.c b/libavcodec/dctref.c
index ae3dec51cd..851014b664 100644
--- a/libavcodec/dctref.c
+++ b/libavcodec/dctref.c
@@ -2,20 +2,20 @@
* reference discrete cosine transform (double precision)
* Copyright (C) 2009 Dylan Yudaken
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/dctref.h b/libavcodec/dctref.h
index ba89abd752..f6fde8863a 100644
--- a/libavcodec/dctref.h
+++ b/libavcodec/dctref.h
@@ -2,30 +2,28 @@
* reference discrete cosine transform (double precision)
* Copyright (C) 2009 Dylan Yudaken
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVCODEC_DCTREF_H
#define AVCODEC_DCTREF_H
-#include "dsputil.h"
-
-void ff_ref_fdct(DCTELEM *block);
-void ff_ref_idct(DCTELEM *block);
+void ff_ref_fdct(short *block);
+void ff_ref_idct(short *block);
void ff_ref_dct_init(void);
#endif /* AVCODEC_DCTREF_H */
diff --git a/libavcodec/dfa.c b/libavcodec/dfa.c
index 919375baf0..f222a59459 100644
--- a/libavcodec/dfa.c
+++ b/libavcodec/dfa.c
@@ -3,20 +3,20 @@
* Copyright (c) 2011 Konstantin Shishkov
* based on work by Vladimir "VAG" Gneushev
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -384,14 +384,13 @@ static av_cold int dfa_decode_end(AVCodecContext *avctx)
}
AVCodec ff_dfa_decoder = {
- "dfa",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_DFA,
- sizeof(DfaContext),
- dfa_decode_init,
- NULL,
- dfa_decode_end,
- dfa_decode_frame,
- CODEC_CAP_DR1,
+ .name = "dfa",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_DFA,
+ .priv_data_size = sizeof(DfaContext),
+ .init = dfa_decode_init,
+ .close = dfa_decode_end,
+ .decode = dfa_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Chronomaster DFA"),
};
diff --git a/libavcodec/dirac.c b/libavcodec/dirac.c
index 09da1cbd56..e637c4951f 100644
--- a/libavcodec/dirac.c
+++ b/libavcodec/dirac.c
@@ -2,20 +2,20 @@
* Copyright (C) 2007 Marco Gerards <marco@gnu.org>
* Copyright (C) 2009 David Conrad
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -120,7 +120,7 @@ static int parse_source_parameters(AVCodecContext *avctx, GetBitContext *gb,
// chroma subsampling
if (get_bits1(gb))
source->chroma_format = svq3_get_ue_golomb(gb);
- if (source->chroma_format > 2) {
+ if (source->chroma_format > 2U) {
av_log(avctx, AV_LOG_ERROR, "Unknown chroma format %d\n",
source->chroma_format);
return -1;
@@ -128,14 +128,14 @@ static int parse_source_parameters(AVCodecContext *avctx, GetBitContext *gb,
if (get_bits1(gb))
source->interlaced = svq3_get_ue_golomb(gb);
- if (source->interlaced > 1)
+ if (source->interlaced > 1U)
return -1;
// frame rate
if (get_bits1(gb)) {
source->frame_rate_index = svq3_get_ue_golomb(gb);
- if (source->frame_rate_index > 10)
+ if (source->frame_rate_index > 10U)
return -1;
if (!source->frame_rate_index) {
@@ -145,7 +145,7 @@ static int parse_source_parameters(AVCodecContext *avctx, GetBitContext *gb,
}
if (source->frame_rate_index > 0) {
if (source->frame_rate_index <= 8)
- frame_rate = ff_frame_rate_tab[source->frame_rate_index];
+ frame_rate = avpriv_frame_rate_tab[source->frame_rate_index];
else
frame_rate = dirac_frame_rate[source->frame_rate_index-9];
}
@@ -156,7 +156,7 @@ static int parse_source_parameters(AVCodecContext *avctx, GetBitContext *gb,
if (get_bits1(gb)) {
source->aspect_ratio_index = svq3_get_ue_golomb(gb);
- if (source->aspect_ratio_index > 6)
+ if (source->aspect_ratio_index > 6U)
return -1;
if (!source->aspect_ratio_index) {
@@ -179,7 +179,7 @@ static int parse_source_parameters(AVCodecContext *avctx, GetBitContext *gb,
if (get_bits1(gb)) {
source->pixel_range_index = svq3_get_ue_golomb(gb);
- if (source->pixel_range_index > 4)
+ if (source->pixel_range_index > 4U)
return -1;
// This assumes either fullrange or MPEG levels only
@@ -207,7 +207,7 @@ static int parse_source_parameters(AVCodecContext *avctx, GetBitContext *gb,
if (get_bits1(gb)) {
idx = source->color_spec_index = svq3_get_ue_golomb(gb);
- if (source->color_spec_index > 4)
+ if (source->color_spec_index > 4U)
return -1;
avctx->color_primaries = dirac_color_presets[idx].color_primaries;
@@ -217,7 +217,7 @@ static int parse_source_parameters(AVCodecContext *avctx, GetBitContext *gb,
if (!source->color_spec_index) {
if (get_bits1(gb)) {
idx = svq3_get_ue_golomb(gb);
- if (idx < 3)
+ if (idx < 3U)
avctx->color_primaries = dirac_primaries[idx];
}
@@ -242,7 +242,7 @@ static int parse_source_parameters(AVCodecContext *avctx, GetBitContext *gb,
return 0;
}
-int ff_dirac_parse_sequence_header(AVCodecContext *avctx, GetBitContext *gb,
+int avpriv_dirac_parse_sequence_header(AVCodecContext *avctx, GetBitContext *gb,
dirac_source_params *source)
{
unsigned version_major;
@@ -259,7 +259,7 @@ int ff_dirac_parse_sequence_header(AVCodecContext *avctx, GetBitContext *gb,
else if (version_major > 2)
av_log(avctx, AV_LOG_WARNING, "Stream may have unhandled features\n");
- if (video_format > 20)
+ if (video_format > 20U)
return -1;
// Fill in defaults for the source parameters.
diff --git a/libavcodec/dirac.h b/libavcodec/dirac.h
index 0be66c2d91..6d41be740a 100644
--- a/libavcodec/dirac.h
+++ b/libavcodec/dirac.h
@@ -2,20 +2,20 @@
* Copyright (C) 2007 Marco Gerards <marco@gnu.org>
* Copyright (C) 2009 David Conrad
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -51,7 +51,7 @@ typedef struct {
uint8_t color_spec_index; ///< index into dirac_color_spec_presets[]
} dirac_source_params;
-int ff_dirac_parse_sequence_header(AVCodecContext *avctx, GetBitContext *gb,
- dirac_source_params *source);
+int avpriv_dirac_parse_sequence_header(AVCodecContext *avctx, GetBitContext *gb,
+ dirac_source_params *source);
#endif /* AVCODEC_DIRAC_H */
diff --git a/libavcodec/dirac_parser.c b/libavcodec/dirac_parser.c
index 87c3a04b91..b407168b41 100644
--- a/libavcodec/dirac_parser.c
+++ b/libavcodec/dirac_parser.c
@@ -4,20 +4,20 @@
* Copyright (c) 2007-2008 Marco Gerards <marco@gnu.org>
* Copyright (c) 2008 BBC, Anuradha Suraparaju <asuraparaju@gmail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/dnxhd_parser.c b/libavcodec/dnxhd_parser.c
index 44ea8f06f5..e5a5aa09f5 100644
--- a/libavcodec/dnxhd_parser.c
+++ b/libavcodec/dnxhd_parser.c
@@ -2,20 +2,20 @@
* DNxHD/VC-3 parser
* Copyright (c) 2008 Baptiste Coudurier <baptiste.coudurier@free.fr>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/dnxhddata.c b/libavcodec/dnxhddata.c
index 82d083c1e2..536636df94 100644
--- a/libavcodec/dnxhddata.c
+++ b/libavcodec/dnxhddata.c
@@ -2,26 +2,48 @@
* VC3/DNxHD data.
* Copyright (c) 2007 SmartJog S.A., Baptiste Coudurier <baptiste dot coudurier at smartjog dot com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avcodec.h"
#include "dnxhddata.h"
+static const uint8_t dnxhd_1235_luma_weight[] = {
+ 0, 32, 32, 32, 33, 35, 38, 39,
+ 32, 33, 32, 33, 36, 36, 39, 42,
+ 32, 32, 33, 36, 35, 37, 41, 43,
+ 31, 33, 34, 36, 36, 40, 42, 48,
+ 32, 34, 36, 37, 39, 42, 46, 51,
+ 36, 37, 37, 39, 41, 46, 51, 55,
+ 37, 39, 41, 41, 47, 50, 55, 56,
+ 41, 42, 41, 44, 50, 53, 60, 60
+};
+
+static const uint8_t dnxhd_1235_chroma_weight[] = {
+ 0, 32, 33, 34, 39, 41, 54, 59,
+ 33, 34, 35, 38, 43, 49, 58, 84,
+ 34, 37, 39, 44, 46, 55, 74, 87,
+ 40, 42, 47, 48, 58, 70, 87, 86,
+ 43, 50, 56, 63, 72, 94, 91, 82,
+ 55, 63, 65, 75, 93, 89, 85, 73,
+ 61, 67, 82, 81, 83, 90, 79, 73,
+ 74, 84, 75, 78, 90, 85, 73, 73
+};
+
static const uint8_t dnxhd_1237_luma_weight[] = {
0, 32, 33, 34, 34, 36, 37, 36,
36, 37, 38, 38, 38, 39, 41, 44,
@@ -108,7 +130,7 @@ static const uint8_t dnxhd_1242_chroma_weight[] = {
48, 49, 51, 51, 52, 52, 54, 54,
49, 49, 52, 53, 54, 54, 53, 53,
55, 59, 63, 62, 60, 60, 60, 60,
- };
+};
static const uint8_t dnxhd_1243_luma_weight[] = {
0, 32, 32, 33, 33, 35, 35, 35,
@@ -132,6 +154,28 @@ static const uint8_t dnxhd_1243_chroma_weight[] = {
46, 45, 46, 47, 47, 48, 47, 47,
};
+static const uint8_t dnxhd_1250_luma_weight[] = {
+ 0, 32, 35, 35, 36, 36, 41, 43,
+ 32, 34, 35, 36, 37, 39, 43, 47,
+ 33, 34, 36, 38, 38, 42, 42, 50,
+ 34, 36, 38, 38, 41, 40, 47, 54,
+ 35, 38, 39, 40, 39, 45, 49, 58,
+ 38, 39, 40, 39, 46, 47, 54, 60,
+ 38, 39, 41, 46, 46, 48, 57, 62,
+ 40, 41, 44, 45, 49, 54, 63, 63
+};
+
+static const uint8_t dnxhd_1250_chroma_weight[] = {
+ 0, 32, 35, 36, 40, 42, 51, 51,
+ 35, 36, 39, 39, 43, 51, 52, 55,
+ 36, 41, 41, 43, 51, 53, 54, 56,
+ 43, 44, 45, 50, 54, 54, 55, 57,
+ 45, 48, 50, 51, 55, 58, 59, 58,
+ 49, 52, 49, 57, 58, 62, 58, 60,
+ 51, 51, 56, 58, 62, 61, 59, 62,
+ 52, 52, 60, 61, 59, 59, 63, 63
+};
+
static const uint8_t dnxhd_1251_luma_weight[] = {
0, 32, 32, 34, 34, 34, 34, 35,
35, 35, 36, 37, 36, 36, 35, 36,
@@ -184,35 +228,144 @@ static const uint8_t dnxhd_1237_dc_bits[12] = {
};
static const uint16_t dnxhd_1237_ac_codes[257] = {
- 0, 1, 4, 5, 12, 26, 27, 56, 57, 58, 59, 120, 121, 244, 245, 246, 247, 248, 498, 499, 500, 501, 502, 1006, 1007, 1008, 1009, 1010, 1011, 2024, 2025, 2026, 2027, 2028, 2029, 2030, 2031, 4064, 4065, 4066, 4067, 4068, 4069, 4070, 4071, 4072, 4073, 8148, 8149, 8150, 8151, 8152, 8153, 8154, 8155, 8156, 8157, 8158, 16318, 16319, 16320, 16321, 16322, 16323, 16324, 16325, 16326, 16327, 16328, 16329, 16330, 16331, 16332, 16333, 32668, 32669, 32670, 32671, 32672, 32673, 32674, 32675, 32676, 32677, 32678, 32679, 32680, 32681, 32682, 32683, 32684, 65370, 65371, 65372, 65373, 65374, 65375, 65376, 65377, 65378, 65379, 65380, 65381, 65382, 65383, 65384, 65385, 65386, 65387, 65388, 65389, 65390, 65391, 65392, 65393, 65394, 65395, 65396, 65397, 65398, 65399, 65400, 65401, 65402, 65403, 65404, 65405, 65406, 65407, 65408, 65409, 65410, 65411, 65412, 65413, 65414, 65415, 65416, 65417, 65418, 65419, 65420, 65421, 65422, 65423, 65424, 65425, 65426, 65427, 65428, 65429, 65430, 65431, 65432, 65433, 65434, 65435, 65436, 65437, 65438, 65439, 65440, 65441, 65442, 65443, 65444, 65445, 65446, 65447, 65448, 65449, 65450, 65451, 65452, 65453, 65454, 65455, 65456, 65457, 65458, 65459, 65460, 65461, 65462, 65463, 65464, 65465, 65466, 65467, 65468, 65469, 65470, 65471, 65472, 65473, 65474, 65475, 65476, 65477, 65478, 65479, 65480, 65481, 65482, 65483, 65484, 65485, 65486, 65487, 65488, 65489, 65490, 65491, 65492, 65493, 65494, 65495, 65496, 65497, 65498, 65499, 65500, 65501, 65502, 65503, 65504, 65505, 65506, 65507, 65508, 65509, 65510, 65511, 65512, 65513, 65514, 65515, 65516, 65517, 65518, 65519, 65520, 65521, 65522, 65523, 65524, 65525, 65526, 65527, 65528, 65529, 65530, 65531, 65532, 65533, 65534, 65535,
+ 0, 1, 4, 5, 12, 26, 27, 56,
+ 57, 58, 59, 120, 121, 244, 245, 246,
+ 247, 248, 498, 499, 500, 501, 502, 1006,
+ 1007, 1008, 1009, 1010, 1011, 2024, 2025, 2026,
+ 2027, 2028, 2029, 2030, 2031, 4064, 4065, 4066,
+ 4067, 4068, 4069, 4070, 4071, 4072, 4073, 8148,
+ 8149, 8150, 8151, 8152, 8153, 8154, 8155, 8156,
+ 8157, 8158, 16318, 16319, 16320, 16321, 16322, 16323,
+ 16324, 16325, 16326, 16327, 16328, 16329, 16330, 16331,
+ 16332, 16333, 32668, 32669, 32670, 32671, 32672, 32673,
+ 32674, 32675, 32676, 32677, 32678, 32679, 32680, 32681,
+ 32682, 32683, 32684, 65370, 65371, 65372, 65373, 65374,
+ 65375, 65376, 65377, 65378, 65379, 65380, 65381, 65382,
+ 65383, 65384, 65385, 65386, 65387, 65388, 65389, 65390,
+ 65391, 65392, 65393, 65394, 65395, 65396, 65397, 65398,
+ 65399, 65400, 65401, 65402, 65403, 65404, 65405, 65406,
+ 65407, 65408, 65409, 65410, 65411, 65412, 65413, 65414,
+ 65415, 65416, 65417, 65418, 65419, 65420, 65421, 65422,
+ 65423, 65424, 65425, 65426, 65427, 65428, 65429, 65430,
+ 65431, 65432, 65433, 65434, 65435, 65436, 65437, 65438,
+ 65439, 65440, 65441, 65442, 65443, 65444, 65445, 65446,
+ 65447, 65448, 65449, 65450, 65451, 65452, 65453, 65454,
+ 65455, 65456, 65457, 65458, 65459, 65460, 65461, 65462,
+ 65463, 65464, 65465, 65466, 65467, 65468, 65469, 65470,
+ 65471, 65472, 65473, 65474, 65475, 65476, 65477, 65478,
+ 65479, 65480, 65481, 65482, 65483, 65484, 65485, 65486,
+ 65487, 65488, 65489, 65490, 65491, 65492, 65493, 65494,
+ 65495, 65496, 65497, 65498, 65499, 65500, 65501, 65502,
+ 65503, 65504, 65505, 65506, 65507, 65508, 65509, 65510,
+ 65511, 65512, 65513, 65514, 65515, 65516, 65517, 65518,
+ 65519, 65520, 65521, 65522, 65523, 65524, 65525, 65526,
+ 65527, 65528, 65529, 65530, 65531, 65532, 65533, 65534,
+ 65535,
};
static const uint8_t dnxhd_1237_ac_bits[257] = {
- 2, 2, 3, 3, 4, 5, 5, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 2, 2, 3, 3, 4, 5, 5, 6, 6, 6, 6, 7, 7, 8, 8, 8,
+ 8, 8, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 11, 11, 11,
+ 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13,
+ 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14,
+ 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16,
};
static const uint8_t dnxhd_1237_ac_level[257] = {
- 1, 1, 2, 0, 3, 4, 2, 5, 6, 7, 3, 8, 9, 10, 11, 12, 4, 5, 13, 14, 15, 16, 6, 17, 18, 19, 20, 21, 7, 22, 23, 24, 25, 26, 27, 8, 9, 28, 29, 30, 31, 32, 33, 34, 10, 11, 12, 35, 36, 37, 38, 39, 40, 41, 13, 14, 15, 16, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 17, 18, 19, 20, 21, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 1, 22, 23, 24, 25, 26, 27, 62, 63, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64,
+ 1, 1, 2, 0, 3, 4, 2, 5, 6, 7, 3, 8, 9, 10, 11, 12,
+ 4, 5, 13, 14, 15, 16, 6, 17, 18, 19, 20, 21, 7, 22, 23, 24,
+ 25, 26, 27, 8, 9, 28, 29, 30, 31, 32, 33, 34, 10, 11, 12, 35,
+ 36, 37, 38, 39, 40, 41, 13, 14, 15, 16, 42, 43, 44, 45, 46, 47,
+ 48, 49, 50, 51, 52, 17, 18, 19, 20, 21, 53, 54, 55, 56, 57, 58,
+ 59, 60, 61, 64, 1, 22, 23, 24, 25, 26, 27, 62, 63, 2, 3, 4,
+ 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
+ 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
+ 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
+ 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 28, 29, 30, 31,
+ 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+ 64, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+ 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+ 64,
};
static const uint8_t dnxhd_1237_ac_run_flag[257] = {
- 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0,
+ 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0,
+ 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0,
+ 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1,
};
static const uint8_t dnxhd_1237_ac_index_flag[257] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1,
};
static const uint16_t dnxhd_1237_run_codes[62] = {
- 0, 4, 10, 11, 24, 25, 26, 54, 55, 56, 57, 58, 118, 119, 240, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 990, 991, 992, 993, 994, 995, 996, 997, 998, 999, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017, 1018, 1019, 1020, 1021, 1022, 1023,
+ 0, 4, 10, 11, 24, 25, 26, 54,
+ 55, 56, 57, 58, 118, 119, 240, 482,
+ 483, 484, 485, 486, 487, 488, 489, 490,
+ 491, 492, 493, 494, 990, 991, 992, 993,
+ 994, 995, 996, 997, 998, 999, 1000, 1001,
+ 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009,
+ 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017,
+ 1018, 1019, 1020, 1021, 1022, 1023,
};
static const uint8_t dnxhd_1237_run_bits[62] = {
- 1, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
+ 1, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7, 8, 9,
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10,
+ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
+ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
};
static const uint8_t dnxhd_1237_run[62] = {
- 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 53, 57, 58, 59, 60, 61, 62, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 54, 55, 56,
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+ 17, 18, 19, 20, 21, 53, 57, 58, 59, 60, 61, 62, 22, 23, 24, 25,
+ 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41,
+ 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 54, 55, 56,
};
static const uint8_t dnxhd_1238_dc_codes[12] = {
@@ -224,122 +377,698 @@ static const uint8_t dnxhd_1238_dc_bits[12] = {
};
static const uint16_t dnxhd_1238_ac_codes[257] = {
- 0, 1, 4, 10, 11, 24, 25, 26, 54, 55, 56, 57, 116, 117, 118, 119, 240, 241, 242, 243, 244, 245, 492, 493, 494, 495, 496, 497, 498, 499, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025, 2026, 2027, 4056, 4057, 4058, 4059, 4060, 4061, 4062, 4063, 4064, 4065, 4066, 4067, 4068, 4069, 8140, 8141, 8142, 8143, 8144, 8145, 8146, 8147, 8148, 8149, 8150, 8151, 8152, 8153, 8154, 8155, 8156, 16314, 16315, 16316, 16317, 16318, 16319, 16320, 16321, 16322, 16323, 16324, 16325, 16326, 16327, 16328, 16329, 16330, 16331, 16332, 16333, 16334, 16335, 16336, 16337, 16338, 32678, 32679, 32680, 32681, 32682, 32683, 32684, 32685, 32686, 32687, 32688, 32689, 32690, 32691, 32692, 32693, 32694, 32695, 32696, 32697, 32698, 32699, 32700, 32701, 32702, 32703, 32704, 32705, 65412, 65413, 65414, 65415, 65416, 65417, 65418, 65419, 65420, 65421, 65422, 65423, 65424, 65425, 65426, 65427, 65428, 65429, 65430, 65431, 65432, 65433, 65434, 65435, 65436, 65437, 65438, 65439, 65440, 65441, 65442, 65443, 65444, 65445, 65446, 65447, 65448, 65449, 65450, 65451, 65452, 65453, 65454, 65455, 65456, 65457, 65458, 65459, 65460, 65461, 65462, 65463, 65464, 65465, 65466, 65467, 65468, 65469, 65470, 65471, 65472, 65473, 65474, 65475, 65476, 65477, 65478, 65479, 65480, 65481, 65482, 65483, 65484, 65485, 65486, 65487, 65488, 65489, 65490, 65491, 65492, 65493, 65494, 65495, 65496, 65497, 65498, 65499, 65500, 65501, 65502, 65503, 65504, 65505, 65506, 65507, 65508, 65509, 65510, 65511, 65512, 65513, 65514, 65515, 65516, 65517, 65518, 65519, 65520, 65521, 65522, 65523, 65524, 65525, 65526, 65527, 65528, 65529, 65530, 65531, 65532, 65533, 65534, 65535,
+ 0, 1, 4, 10, 11, 24, 25, 26,
+ 54, 55, 56, 57, 116, 117, 118, 119,
+ 240, 241, 242, 243, 244, 245, 492, 493,
+ 494, 495, 496, 497, 498, 499, 1000, 1001,
+ 1002, 1003, 1004, 1005, 1006, 1007, 1008, 2018,
+ 2019, 2020, 2021, 2022, 2023, 2024, 2025, 2026,
+ 2027, 4056, 4057, 4058, 4059, 4060, 4061, 4062,
+ 4063, 4064, 4065, 4066, 4067, 4068, 4069, 8140,
+ 8141, 8142, 8143, 8144, 8145, 8146, 8147, 8148,
+ 8149, 8150, 8151, 8152, 8153, 8154, 8155, 8156,
+ 16314, 16315, 16316, 16317, 16318, 16319, 16320, 16321,
+ 16322, 16323, 16324, 16325, 16326, 16327, 16328, 16329,
+ 16330, 16331, 16332, 16333, 16334, 16335, 16336, 16337,
+ 16338, 32678, 32679, 32680, 32681, 32682, 32683, 32684,
+ 32685, 32686, 32687, 32688, 32689, 32690, 32691, 32692,
+ 32693, 32694, 32695, 32696, 32697, 32698, 32699, 32700,
+ 32701, 32702, 32703, 32704, 32705, 65412, 65413, 65414,
+ 65415, 65416, 65417, 65418, 65419, 65420, 65421, 65422,
+ 65423, 65424, 65425, 65426, 65427, 65428, 65429, 65430,
+ 65431, 65432, 65433, 65434, 65435, 65436, 65437, 65438,
+ 65439, 65440, 65441, 65442, 65443, 65444, 65445, 65446,
+ 65447, 65448, 65449, 65450, 65451, 65452, 65453, 65454,
+ 65455, 65456, 65457, 65458, 65459, 65460, 65461, 65462,
+ 65463, 65464, 65465, 65466, 65467, 65468, 65469, 65470,
+ 65471, 65472, 65473, 65474, 65475, 65476, 65477, 65478,
+ 65479, 65480, 65481, 65482, 65483, 65484, 65485, 65486,
+ 65487, 65488, 65489, 65490, 65491, 65492, 65493, 65494,
+ 65495, 65496, 65497, 65498, 65499, 65500, 65501, 65502,
+ 65503, 65504, 65505, 65506, 65507, 65508, 65509, 65510,
+ 65511, 65512, 65513, 65514, 65515, 65516, 65517, 65518,
+ 65519, 65520, 65521, 65522, 65523, 65524, 65525, 65526,
+ 65527, 65528, 65529, 65530, 65531, 65532, 65533, 65534,
+ 65535,
};
static const uint8_t dnxhd_1238_ac_bits[257] = {
- 2, 2, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 2, 2, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7,
+ 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10,
+ 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11,
+ 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13,
+ 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
+ 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
+ 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16,
};
static const uint8_t dnxhd_1238_ac_level[257] = {
- 1, 1, 2, 3, 0, 4, 5, 2, 6, 7, 8, 3, 9, 10, 11, 4, 12, 13, 14, 15, 16, 5, 17, 18, 19, 20, 21, 22, 6, 7, 23, 24, 25, 26, 27, 28, 29, 8, 9, 30, 31, 32, 33, 34, 35, 36, 37, 10, 11, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 12, 13, 14, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 15, 16, 17, 18, 62, 63, 64, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 19, 20, 21, 22, 23, 24, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 40, 25, 26, 27, 28, 29, 30, 38, 39, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64,
+ 1, 1, 2, 3, 0, 4, 5, 2, 6, 7, 8, 3, 9, 10, 11, 4,
+ 12, 13, 14, 15, 16, 5, 17, 18, 19, 20, 21, 22, 6, 7, 23, 24,
+ 25, 26, 27, 28, 29, 8, 9, 30, 31, 32, 33, 34, 35, 36, 37, 10,
+ 11, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 12, 13, 14, 49,
+ 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 15, 16, 17, 18,
+ 62, 63, 64, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
+ 14, 15, 16, 19, 20, 21, 22, 23, 24, 17, 18, 19, 20, 21, 22, 23,
+ 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 40, 25,
+ 26, 27, 28, 29, 30, 38, 39, 41, 42, 43, 44, 45, 46, 47, 48, 49,
+ 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 31,
+ 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+ 64, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+ 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+ 64,
}; /* 0 is EOB */
static const uint8_t dnxhd_1238_ac_run_flag[257] = {
- 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1,
+ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0,
+ 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1,
+ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
+ 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1,
};
static const uint8_t dnxhd_1238_ac_index_flag[257] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
+ 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1,
};
-static const uint16_t dnxhd_1238_run_codes[62] = {
- 0, 4, 10, 11, 24, 25, 26, 27, 56, 57, 58, 59, 120, 242, 486, 487, 488, 489, 980, 981, 982, 983, 984, 985, 986, 987, 988, 989, 990, 991, 992, 993, 994, 995, 996, 997, 998, 999, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017, 1018, 1019, 1020, 1021, 1022, 1023,
+static const uint16_t dnxhd_1235_1238_1241_run_codes[62] = {
+ 0, 4, 10, 11, 24, 25, 26, 27,
+ 56, 57, 58, 59, 120, 242, 486, 487,
+ 488, 489, 980, 981, 982, 983, 984, 985,
+ 986, 987, 988, 989, 990, 991, 992, 993,
+ 994, 995, 996, 997, 998, 999, 1000, 1001,
+ 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009,
+ 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017,
+ 1018, 1019, 1020, 1021, 1022, 1023,
};
-static const uint8_t dnxhd_1238_run_bits[62] = {
- 1, 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 8, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
+static const uint8_t dnxhd_1235_1238_1241_run_bits[62] = {
+ 1, 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 8, 9, 9,
+ 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
+ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
+ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
};
static const uint8_t dnxhd_1238_run[62] = {
- 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 20, 21, 17, 18, 19, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62,
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+ 20, 21, 17, 18, 19, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
+ 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
+ 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62,
};
-static const uint8_t dnxhd_1241_dc_codes[14] = {
+static const uint8_t dnxhd_1235_1241_dc_codes[14] = {
10, 62, 11, 12, 13, 0, 1, 2, 3, 4, 14, 30, 126, 127,
};
-static const uint8_t dnxhd_1241_dc_bits[14] = {
+static const uint8_t dnxhd_1235_1241_dc_bits[14] = {
4, 6, 4, 4, 4, 3, 3, 3, 3, 3, 4, 5, 7, 7,
};
-static const uint16_t dnxhd_1241_ac_codes[257] = {
- 0, 1, 4, 10, 11, 24, 25, 26, 54, 55, 56, 57, 116, 117, 118, 119, 240, 241, 242, 243, 244, 245, 492, 493, 494, 495, 496, 497, 498, 998, 999, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025, 2026, 4054, 4055, 4056, 4057, 4058, 4059, 4060, 4061, 4062, 4063, 4064, 4065, 4066, 4067, 4068, 4069, 8140, 8141, 8142, 8143, 8144, 8145, 8146, 8147, 8148, 8149, 8150, 8151, 8152, 8153, 8154, 8155, 8156, 8157, 16316, 16317, 16318, 16319, 16320, 16321, 16322, 16323, 16324, 16325, 16326, 16327, 16328, 16329, 16330, 16331, 16332, 16333, 16334, 16335, 16336, 16337, 32676, 32677, 32678, 32679, 32680, 32681, 32682, 32683, 32684, 32685, 32686, 32687, 32688, 32689, 32690, 32691, 32692, 32693, 32694, 32695, 32696, 32697, 32698, 32699, 32700, 32701, 32702, 32703, 32704, 32705, 32706, 32707, 32708, 65418, 65419, 65420, 65421, 65422, 65423, 65424, 65425, 65426, 65427, 65428, 65429, 65430, 65431, 65432, 65433, 65434, 65435, 65436, 65437, 65438, 65439, 65440, 65441, 65442, 65443, 65444, 65445, 65446, 65447, 65448, 65449, 65450, 65451, 65452, 65453, 65454, 65455, 65456, 65457, 65458, 65459, 65460, 65461, 65462, 65463, 65464, 65465, 65466, 65467, 65468, 65469, 65470, 65471, 65472, 65473, 65474, 65475, 65476, 65477, 65478, 65479, 65480, 65481, 65482, 65483, 65484, 65485, 65486, 65487, 65488, 65489, 65490, 65491, 65492, 65493, 65494, 65495, 65496, 65497, 65498, 65499, 65500, 65501, 65502, 65503, 65504, 65505, 65506, 65507, 65508, 65509, 65510, 65511, 65512, 65513, 65514, 65515, 65516, 65517, 65518, 65519, 65520, 65521, 65522, 65523, 65524, 65525, 65526, 65527, 65528, 65529, 65530, 65531, 65532, 65533, 65534, 65535,
+
+static const uint16_t dnxhd_1235_1241_ac_codes[257] = {
+ 0, 1, 4, 10, 11, 24, 25, 26,
+ 54, 55, 56, 57, 116, 117, 118, 119,
+ 240, 241, 242, 243, 244, 245, 492, 493,
+ 494, 495, 496, 497, 498, 998, 999, 1000,
+ 1001, 1002, 1003, 1004, 1005, 1006, 1007, 2016,
+ 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024,
+ 2025, 2026, 4054, 4055, 4056, 4057, 4058, 4059,
+ 4060, 4061, 4062, 4063, 4064, 4065, 4066, 4067,
+ 4068, 4069, 8140, 8141, 8142, 8143, 8144, 8145,
+ 8146, 8147, 8148, 8149, 8150, 8151, 8152, 8153,
+ 8154, 8155, 8156, 8157, 16316, 16317, 16318, 16319,
+ 16320, 16321, 16322, 16323, 16324, 16325, 16326, 16327,
+ 16328, 16329, 16330, 16331, 16332, 16333, 16334, 16335,
+ 16336, 16337, 32676, 32677, 32678, 32679, 32680, 32681,
+ 32682, 32683, 32684, 32685, 32686, 32687, 32688, 32689,
+ 32690, 32691, 32692, 32693, 32694, 32695, 32696, 32697,
+ 32698, 32699, 32700, 32701, 32702, 32703, 32704, 32705,
+ 32706, 32707, 32708, 65418, 65419, 65420, 65421, 65422,
+ 65423, 65424, 65425, 65426, 65427, 65428, 65429, 65430,
+ 65431, 65432, 65433, 65434, 65435, 65436, 65437, 65438,
+ 65439, 65440, 65441, 65442, 65443, 65444, 65445, 65446,
+ 65447, 65448, 65449, 65450, 65451, 65452, 65453, 65454,
+ 65455, 65456, 65457, 65458, 65459, 65460, 65461, 65462,
+ 65463, 65464, 65465, 65466, 65467, 65468, 65469, 65470,
+ 65471, 65472, 65473, 65474, 65475, 65476, 65477, 65478,
+ 65479, 65480, 65481, 65482, 65483, 65484, 65485, 65486,
+ 65487, 65488, 65489, 65490, 65491, 65492, 65493, 65494,
+ 65495, 65496, 65497, 65498, 65499, 65500, 65501, 65502,
+ 65503, 65504, 65505, 65506, 65507, 65508, 65509, 65510,
+ 65511, 65512, 65513, 65514, 65515, 65516, 65517, 65518,
+ 65519, 65520, 65521, 65522, 65523, 65524, 65525, 65526,
+ 65527, 65528, 65529, 65530, 65531, 65532, 65533, 65534,
+ 65535,
+};
+
+static const uint8_t dnxhd_1235_1241_ac_bits[257] = {
+ 2, 2, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7,
+ 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10,
+ 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11,
+ 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
+ 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
+ 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
+ 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16,
};
-static const uint8_t dnxhd_1241_ac_bits[257] = {
- 2, 2, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+static const uint8_t dnxhd_1235_1241_ac_level[257] = {
+ 1, 1, 2, 3, 0, 4, 5, 2, 6, 7, 8, 3, 9, 10, 11, 4,
+ 12, 13, 14, 15, 16, 5, 17, 18, 19, 20, 21, 6, 7, 22, 23, 24,
+ 25, 26, 27, 28, 29, 8, 9, 30, 31, 32, 33, 34, 35, 36, 37, 38,
+ 10, 11, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 12, 13,
+ 14, 15, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 1,
+ 16, 17, 18, 19, 64, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
+ 13, 14, 15, 16, 17, 20, 21, 22, 23, 24, 18, 19, 20, 21, 22, 23,
+ 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
+ 40, 41, 42, 25, 26, 27, 28, 29, 30, 31, 32, 43, 44, 45, 46, 47,
+ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+ 64, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+ 64, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+ 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+ 64,
};
-static const uint8_t dnxhd_1241_ac_level[257] = {
- 1, 1, 2, 3, 0, 4, 5, 2, 6, 7, 8, 3, 9, 10, 11, 4, 12, 13, 14, 15, 16, 5, 17, 18, 19, 20, 21, 6, 7, 22, 23, 24, 25, 26, 27, 28, 29, 8, 9, 30, 31, 32, 33, 34, 35, 36, 37, 38, 10, 11, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 12, 13, 14, 15, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 1, 16, 17, 18, 19, 64, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 20, 21, 22, 23, 24, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 25, 26, 27, 28, 29, 30, 31, 32, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64,
+static const uint8_t dnxhd_1235_1241_ac_run_flag[257] = {
+ 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1,
+ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0,
+ 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1,
+ 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1,
};
-static const uint8_t dnxhd_1241_ac_run_flag[257] = {
- 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+static const uint8_t dnxhd_1235_1241_ac_index_flag[257] = {
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
+ 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1,
};
-static const uint8_t dnxhd_1241_ac_index_flag[257] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+static const uint8_t dnxhd_1235_1241_run[62] = {
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+ 18, 20, 17, 19, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
+ 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
+ 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62,
};
-static const uint8_t dnxhd_1241_run[62] = {
- 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 18, 20, 17, 19, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62,
+static const uint8_t dnxhd_1250_dc_codes[14] = {
+ 10, 62, 11, 12, 13, 0, 1, 2, 3, 4, 14, 30, 126, 127
+};
+static const uint8_t dnxhd_1250_dc_bits[14] = {
+ 4, 6, 4, 4, 4, 3, 3, 3, 3, 3, 4, 5, 7, 7
+};
+static const uint16_t dnxhd_1250_ac_codes[257] = {
+ 0, 1, 4, 10, 11, 24, 25, 26,
+ 54, 55, 56, 57, 116, 117, 118, 119,
+ 240, 241, 242, 243, 244, 245, 492, 493,
+ 494, 495, 496, 497, 498, 998, 999, 1000,
+ 1001, 1002, 1003, 1004, 1005, 1006, 2014, 2015,
+ 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023,
+ 2024, 2025, 4052, 4053, 4054, 4055, 4056, 4057,
+ 4058, 4059, 4060, 4061, 4062, 4063, 4064, 4065,
+ 4066, 4067, 8136, 8137, 8138, 8139, 8140, 8141,
+ 8142, 8143, 8144, 8145, 8146, 8147, 8148, 8149,
+ 8150, 8151, 8152, 8153, 8154, 8155, 8156, 16314,
+ 16315, 16316, 16317, 16318, 16319, 16320, 16321, 16322,
+ 16323, 16324, 16325, 16326, 16327, 16328, 16329, 16330,
+ 16331, 16332, 16333, 16334, 16335, 16336, 16337, 16338,
+ 32678, 32679, 32680, 32681, 32682, 32683, 32684, 32685,
+ 32686, 32687, 32688, 32689, 32690, 32691, 32692, 32693,
+ 32694, 32695, 32696, 32697, 32698, 32699, 32700, 32701,
+ 32702, 32703, 32704, 32705, 32706, 32707, 32708, 32709,
+ 32710, 32711, 32712, 65426, 65427, 65428, 65429, 65430,
+ 65431, 65432, 65433, 65434, 65435, 65436, 65437, 65438,
+ 65439, 65440, 65441, 65442, 65443, 65444, 65445, 65446,
+ 65447, 65448, 65449, 65450, 65451, 65452, 65453, 65454,
+ 65455, 65456, 65457, 65458, 65459, 65460, 65461, 65462,
+ 65463, 65464, 65465, 65466, 65467, 65468, 65469, 65470,
+ 65471, 65472, 65473, 65474, 65475, 65476, 65477, 65478,
+ 65479, 65480, 65481, 65482, 65483, 65484, 65485, 65486,
+ 65487, 65488, 65489, 65490, 65491, 65492, 65493, 65494,
+ 65495, 65496, 65497, 65498, 65499, 65500, 65501, 65502,
+ 65503, 65504, 65505, 65506, 65507, 65508, 65509, 65510,
+ 65511, 65512, 65513, 65514, 65515, 65516, 65517, 65518,
+ 65519, 65520, 65521, 65522, 65523, 65524, 65525, 65526,
+ 65527, 65528, 65529, 65530, 65531, 65532, 65533, 65534,
+ 65535
+};
+static const uint8_t dnxhd_1250_ac_bits[257] = {
+ 2, 2, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7,
+ 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10,
+ 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
+ 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
+ 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
+ 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14,
+ 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16
+};
+static const uint8_t dnxhd_1250_ac_level[257] = {
+ 1, 1, 2, 3, 0, 4, 5, 2, 6, 7, 8, 3, 9, 10, 11, 4,
+ 12, 13, 14, 15, 16, 5, 17, 18, 19, 20, 21, 22, 6, 23, 24, 25,
+ 26, 27, 28, 29, 7, 8, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
+ 9, 10, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 11,
+ 12, 13, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 1, 2,
+ 3, 4, 5, 14, 15, 16, 17, 6, 7, 8, 9, 10, 11, 12, 13, 14,
+ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 18, 19, 20, 21,
+ 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
+ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 55, 56, 22, 23, 24,
+ 25, 26, 27, 54, 57, 58, 59, 60, 61, 62, 63, 64, 28, 29, 30, 31,
+ 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+ 64, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+ 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+ 64
+};
+static const uint8_t dnxhd_1250_ac_run_flag[257] = {
+ 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1,
+ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,
+ 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
+ 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1,
+ 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1
+};
+static const uint8_t dnxhd_1250_ac_index_flag[257] = {
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1,
+ 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0,
+ 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1
+};
+static const uint16_t dnxhd_1250_run_codes[62] = {
+ 0, 4, 5, 12, 26, 27, 28, 58,
+ 118, 119, 120, 242, 486, 487, 976, 977,
+ 978, 979, 980, 981, 982, 983, 984, 985,
+ 986, 987, 988, 989, 990, 991, 992, 993,
+ 994, 995, 996, 997, 998, 999, 1000, 1001,
+ 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009,
+ 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017,
+ 1018, 1019, 1020, 1021, 1022, 1023
+};
+static const uint8_t dnxhd_1250_run_bits[62] = {
+ 1, 3, 3, 4, 5, 5, 5, 6, 7, 7, 7, 8, 9, 9, 10, 10,
+ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
+ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
+ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10
+};
+static const uint8_t dnxhd_1250_run[62] = {
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+ 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
+ 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
+ 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62
};
static const uint8_t dnxhd_1251_dc_codes[12] = {
0, 12, 13, 1, 2, 3, 4, 5, 14, 30, 62, 63,
};
+
static const uint8_t dnxhd_1251_dc_bits[12] = {
3, 4, 4, 3, 3, 3, 3, 3, 4, 5, 6, 6,
};
+
static const uint16_t dnxhd_1251_ac_codes[257] = {
- 0, 1, 4, 10, 11, 24, 25, 26, 54, 55, 56, 57, 116, 117, 118, 119, 240, 241, 242, 243, 244, 245, 492, 493, 494, 495, 496, 497, 996, 997, 998, 999, 1000, 1001, 1002, 1003, 1004, 1005, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025, 4052, 4053, 4054, 4055, 4056, 4057, 4058, 4059, 4060, 4061, 4062, 4063, 4064, 4065, 4066, 8134, 8135, 8136, 8137, 8138, 8139, 8140, 8141, 8142, 8143, 8144, 8145, 8146, 8147, 8148, 8149, 8150, 8151, 8152, 8153, 8154, 8155, 8156, 16314, 16315, 16316, 16317, 16318, 16319, 16320, 16321, 16322, 16323, 16324, 16325, 16326, 16327, 16328, 16329, 16330, 16331, 16332, 16333, 16334, 16335, 16336, 16337, 16338, 16339, 32680, 32681, 32682, 32683, 32684, 32685, 32686, 32687, 32688, 32689, 32690, 32691, 32692, 32693, 32694, 32695, 32696, 32697, 32698, 32699, 32700, 32701, 32702, 32703, 32704, 32705, 32706, 32707, 32708, 32709, 32710, 32711, 32712, 32713, 32714, 65430, 65431, 65432, 65433, 65434, 65435, 65436, 65437, 65438, 65439, 65440, 65441, 65442, 65443, 65444, 65445, 65446, 65447, 65448, 65449, 65450, 65451, 65452, 65453, 65454, 65455, 65456, 65457, 65458, 65459, 65460, 65461, 65462, 65463, 65464, 65465, 65466, 65467, 65468, 65469, 65470, 65471, 65472, 65473, 65474, 65475, 65476, 65477, 65478, 65479, 65480, 65481, 65482, 65483, 65484, 65485, 65486, 65487, 65488, 65489, 65490, 65491, 65492, 65493, 65494, 65495, 65496, 65497, 65498, 65499, 65500, 65501, 65502, 65503, 65504, 65505, 65506, 65507, 65508, 65509, 65510, 65511, 65512, 65513, 65514, 65515, 65516, 65517, 65518, 65519, 65520, 65521, 65522, 65523, 65524, 65525, 65526, 65527, 65528, 65529, 65530, 65531, 65532, 65533, 65534, 65535,
+ 0, 1, 4, 10, 11, 24, 25, 26,
+ 54, 55, 56, 57, 116, 117, 118, 119,
+ 240, 241, 242, 243, 244, 245, 492, 493,
+ 494, 495, 496, 497, 996, 997, 998, 999,
+ 1000, 1001, 1002, 1003, 1004, 1005, 2012, 2013,
+ 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021,
+ 2022, 2023, 2024, 2025, 4052, 4053, 4054, 4055,
+ 4056, 4057, 4058, 4059, 4060, 4061, 4062, 4063,
+ 4064, 4065, 4066, 8134, 8135, 8136, 8137, 8138,
+ 8139, 8140, 8141, 8142, 8143, 8144, 8145, 8146,
+ 8147, 8148, 8149, 8150, 8151, 8152, 8153, 8154,
+ 8155, 8156, 16314, 16315, 16316, 16317, 16318, 16319,
+ 16320, 16321, 16322, 16323, 16324, 16325, 16326, 16327,
+ 16328, 16329, 16330, 16331, 16332, 16333, 16334, 16335,
+ 16336, 16337, 16338, 16339, 32680, 32681, 32682, 32683,
+ 32684, 32685, 32686, 32687, 32688, 32689, 32690, 32691,
+ 32692, 32693, 32694, 32695, 32696, 32697, 32698, 32699,
+ 32700, 32701, 32702, 32703, 32704, 32705, 32706, 32707,
+ 32708, 32709, 32710, 32711, 32712, 32713, 32714, 65430,
+ 65431, 65432, 65433, 65434, 65435, 65436, 65437, 65438,
+ 65439, 65440, 65441, 65442, 65443, 65444, 65445, 65446,
+ 65447, 65448, 65449, 65450, 65451, 65452, 65453, 65454,
+ 65455, 65456, 65457, 65458, 65459, 65460, 65461, 65462,
+ 65463, 65464, 65465, 65466, 65467, 65468, 65469, 65470,
+ 65471, 65472, 65473, 65474, 65475, 65476, 65477, 65478,
+ 65479, 65480, 65481, 65482, 65483, 65484, 65485, 65486,
+ 65487, 65488, 65489, 65490, 65491, 65492, 65493, 65494,
+ 65495, 65496, 65497, 65498, 65499, 65500, 65501, 65502,
+ 65503, 65504, 65505, 65506, 65507, 65508, 65509, 65510,
+ 65511, 65512, 65513, 65514, 65515, 65516, 65517, 65518,
+ 65519, 65520, 65521, 65522, 65523, 65524, 65525, 65526,
+ 65527, 65528, 65529, 65530, 65531, 65532, 65533, 65534,
+ 65535,
};
+
static const uint8_t dnxhd_1251_ac_bits[257] = {
- 2, 2, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 2, 2, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7,
+ 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10,
+ 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
+ 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
+ 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
+ 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14,
+ 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
+ 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16,
};
+
static const uint8_t dnxhd_1251_ac_level[257] = {
- 1, 1, 2, 3, 0, 4, 5, 2, 6, 7, 8, 3, 9, 10, 11, 4, 12, 13, 14, 15, 16, 5, 17, 18, 19, 20, 21, 6, 22, 23, 24, 25, 26, 27, 28, 29, 7, 8, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 9, 10, 11, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 12, 13, 14, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 1, 2, 3, 4, 5, 6, 7, 8, 15, 16, 17, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 18, 19, 20, 21, 22, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 23, 24, 25, 26, 27, 28, 59, 60, 61, 62, 63, 64, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64,
+ 1, 1, 2, 3, 0, 4, 5, 2, 6, 7, 8, 3, 9, 10, 11, 4,
+ 12, 13, 14, 15, 16, 5, 17, 18, 19, 20, 21, 6, 22, 23, 24, 25,
+ 26, 27, 28, 29, 7, 8, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
+ 40, 9, 10, 11, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
+ 12, 13, 14, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 1,
+ 2, 3, 4, 5, 6, 7, 8, 15, 16, 17, 9, 10, 11, 12, 13, 14,
+ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 18,
+ 19, 20, 21, 22, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41,
+ 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
+ 58, 23, 24, 25, 26, 27, 28, 59, 60, 61, 62, 63, 64, 29, 30, 31,
+ 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+ 64, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+ 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+ 64,
};
+
static const uint8_t dnxhd_1251_ac_run_flag[257] = {
- 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1,
+ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
+ 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
+ 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1,
};
+
static const uint8_t dnxhd_1251_ac_index_flag[257] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
+ 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
+ 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1,
};
+
static const uint16_t dnxhd_1251_run_codes[62] = {
- 0, 4, 5, 12, 26, 27, 28, 58, 118, 119, 120, 242, 486, 487, 976, 977, 978, 979, 980, 981, 982, 983, 984, 985, 986, 987, 988, 989, 990, 991, 992, 993, 994, 995, 996, 997, 998, 999, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017, 1018, 1019, 1020, 1021, 1022, 1023,
+ 0, 4, 5, 12, 26, 27, 28, 58,
+ 118, 119, 120, 242, 486, 487, 976, 977,
+ 978, 979, 980, 981, 982, 983, 984, 985,
+ 986, 987, 988, 989, 990, 991, 992, 993,
+ 994, 995, 996, 997, 998, 999, 1000, 1001,
+ 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009,
+ 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017,
+ 1018, 1019, 1020, 1021, 1022, 1023,
};
+
static const uint8_t dnxhd_1251_run_bits[62] = {
- 1, 3, 3, 4, 5, 5, 5, 6, 7, 7, 7, 8, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
+ 1, 3, 3, 4, 5, 5, 5, 6, 7, 7, 7, 8, 9, 9, 10, 10,
+ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
+ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
+ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
};
+
static const uint8_t dnxhd_1251_run[62] = {
- 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62,
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+ 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
+ 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
+ 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62,
};
static const uint8_t dnxhd_1252_dc_codes[12] = {
0, 12, 13, 1, 2, 3, 4, 5, 14, 30, 62, 63,
};
+
static const uint8_t dnxhd_1252_dc_bits[12] = {
3, 4, 4, 3, 3, 3, 3, 3, 4, 5, 6, 6,
};
+
static const uint16_t dnxhd_1252_ac_codes[257] = {
- 0, 1, 4, 10, 11, 12, 26, 27, 56, 57, 58, 118, 119, 120, 242, 243, 244, 245, 246, 247, 496, 497, 498, 499, 500, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 2020, 2021, 2022, 2023, 2024, 2025, 2026, 2027, 2028, 2029, 4060, 4061, 4062, 4063, 4064, 4065, 4066, 4067, 4068, 4069, 4070, 4071, 8144, 8145, 8146, 8147, 8148, 8149, 8150, 8151, 8152, 8153, 8154, 8155, 8156, 8157, 8158, 16318, 16319, 16320, 16321, 16322, 16323, 16324, 16325, 16326, 16327, 16328, 16329, 16330, 16331, 16332, 16333, 16334, 16335, 32672, 32673, 32674, 32675, 32676, 32677, 32678, 32679, 32680, 32681, 32682, 32683, 32684, 32685, 32686, 32687, 32688, 32689, 32690, 32691, 32692, 32693, 32694, 65390, 65391, 65392, 65393, 65394, 65395, 65396, 65397, 65398, 65399, 65400, 65401, 65402, 65403, 65404, 65405, 65406, 65407, 65408, 65409, 65410, 65411, 65412, 65413, 65414, 65415, 65416, 65417, 65418, 65419, 65420, 65421, 65422, 65423, 65424, 65425, 65426, 65427, 65428, 65429, 65430, 65431, 65432, 65433, 65434, 65435, 65436, 65437, 65438, 65439, 65440, 65441, 65442, 65443, 65444, 65445, 65446, 65447, 65448, 65449, 65450, 65451, 65452, 65453, 65454, 65455, 65456, 65457, 65458, 65459, 65460, 65461, 65462, 65463, 65464, 65465, 65466, 65467, 65468, 65469, 65470, 65471, 65472, 65473, 65474, 65475, 65476, 65477, 65478, 65479, 65480, 65481, 65482, 65483, 65484, 65485, 65486, 65487, 65488, 65489, 65490, 65491, 65492, 65493, 65494, 65495, 65496, 65497, 65498, 65499, 65500, 65501, 65502, 65503, 65504, 65505, 65506, 65507, 65508, 65509, 65510, 65511, 65512, 65513, 65514, 65515, 65516, 65517, 65518, 65519, 65520, 65521, 65522, 65523, 65524, 65525, 65526, 65527, 65528, 65529, 65530, 65531, 65532, 65533, 65534, 65535,
+ 0, 1, 4, 10, 11, 12, 26, 27,
+ 56, 57, 58, 118, 119, 120, 242, 243,
+ 244, 245, 246, 247, 496, 497, 498, 499,
+ 500, 1002, 1003, 1004, 1005, 1006, 1007, 1008,
+ 1009, 2020, 2021, 2022, 2023, 2024, 2025, 2026,
+ 2027, 2028, 2029, 4060, 4061, 4062, 4063, 4064,
+ 4065, 4066, 4067, 4068, 4069, 4070, 4071, 8144,
+ 8145, 8146, 8147, 8148, 8149, 8150, 8151, 8152,
+ 8153, 8154, 8155, 8156, 8157, 8158, 16318, 16319,
+ 16320, 16321, 16322, 16323, 16324, 16325, 16326, 16327,
+ 16328, 16329, 16330, 16331, 16332, 16333, 16334, 16335,
+ 32672, 32673, 32674, 32675, 32676, 32677, 32678, 32679,
+ 32680, 32681, 32682, 32683, 32684, 32685, 32686, 32687,
+ 32688, 32689, 32690, 32691, 32692, 32693, 32694, 65390,
+ 65391, 65392, 65393, 65394, 65395, 65396, 65397, 65398,
+ 65399, 65400, 65401, 65402, 65403, 65404, 65405, 65406,
+ 65407, 65408, 65409, 65410, 65411, 65412, 65413, 65414,
+ 65415, 65416, 65417, 65418, 65419, 65420, 65421, 65422,
+ 65423, 65424, 65425, 65426, 65427, 65428, 65429, 65430,
+ 65431, 65432, 65433, 65434, 65435, 65436, 65437, 65438,
+ 65439, 65440, 65441, 65442, 65443, 65444, 65445, 65446,
+ 65447, 65448, 65449, 65450, 65451, 65452, 65453, 65454,
+ 65455, 65456, 65457, 65458, 65459, 65460, 65461, 65462,
+ 65463, 65464, 65465, 65466, 65467, 65468, 65469, 65470,
+ 65471, 65472, 65473, 65474, 65475, 65476, 65477, 65478,
+ 65479, 65480, 65481, 65482, 65483, 65484, 65485, 65486,
+ 65487, 65488, 65489, 65490, 65491, 65492, 65493, 65494,
+ 65495, 65496, 65497, 65498, 65499, 65500, 65501, 65502,
+ 65503, 65504, 65505, 65506, 65507, 65508, 65509, 65510,
+ 65511, 65512, 65513, 65514, 65515, 65516, 65517, 65518,
+ 65519, 65520, 65521, 65522, 65523, 65524, 65525, 65526,
+ 65527, 65528, 65529, 65530, 65531, 65532, 65533, 65534,
+ 65535,
};
+
static const uint8_t dnxhd_1252_ac_bits[257] = {
- 2, 2, 3, 4, 4, 4, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 2, 2, 3, 4, 4, 4, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8,
+ 8, 8, 8, 8, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10,
+ 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12,
+ 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13,
+ 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
+ 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16,
};
+
static const uint8_t dnxhd_1252_ac_level[257] = {
- 1, 1, 2, 3, 2, 0, 4, 5, 6, 7, 3, 8, 9, 10, 11, 12, 13, 14, 4, 5, 15, 16, 17, 18, 6, 19, 20, 21, 22, 23, 24, 7, 8, 25, 26, 27, 28, 29, 30, 31, 32, 9, 10, 33, 34, 35, 36, 37, 38, 39, 40, 41, 11, 12, 13, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 14, 15, 16, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 1, 2, 3, 17, 18, 19, 20, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 21, 22, 23, 24, 25, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64,
+ 1, 1, 2, 3, 2, 0, 4, 5, 6, 7, 3, 8, 9, 10, 11, 12,
+ 13, 14, 4, 5, 15, 16, 17, 18, 6, 19, 20, 21, 22, 23, 24, 7,
+ 8, 25, 26, 27, 28, 29, 30, 31, 32, 9, 10, 33, 34, 35, 36, 37,
+ 38, 39, 40, 41, 11, 12, 13, 42, 43, 44, 45, 46, 47, 48, 49, 50,
+ 51, 52, 53, 14, 15, 16, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+ 64, 1, 2, 3, 17, 18, 19, 20, 4, 5, 6, 7, 8, 9, 10, 11,
+ 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 21, 22, 23, 24, 25, 22,
+ 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
+ 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
+ 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 26, 27, 28, 29, 30, 31,
+ 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+ 64, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+ 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+ 64,
};
+
static const uint8_t dnxhd_1252_ac_run_flag[257] = {
- 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
+ 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1,
+ 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1,
};
+
static const uint8_t dnxhd_1252_ac_index_flag[257] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1,
};
const CIDEntry ff_dnxhd_cid_table[] = {
+ { 1235, 1920, 1080, 0, 917504, 917504, 6, 10,
+ dnxhd_1235_luma_weight, dnxhd_1235_chroma_weight,
+ dnxhd_1235_1241_dc_codes, dnxhd_1235_1241_dc_bits,
+ dnxhd_1235_1241_ac_codes, dnxhd_1235_1241_ac_bits, dnxhd_1235_1241_ac_level,
+ dnxhd_1235_1241_ac_run_flag, dnxhd_1235_1241_ac_index_flag,
+ dnxhd_1235_1238_1241_run_codes, dnxhd_1235_1238_1241_run_bits, dnxhd_1235_1241_run,
+ { 175, 185, 365, 440 } },
{ 1237, 1920, 1080, 0, 606208, 606208, 4, 8,
dnxhd_1237_luma_weight, dnxhd_1237_chroma_weight,
dnxhd_1237_dc_codes, dnxhd_1237_dc_bits,
@@ -352,14 +1081,14 @@ const CIDEntry ff_dnxhd_cid_table[] = {
dnxhd_1238_dc_codes, dnxhd_1238_dc_bits,
dnxhd_1238_ac_codes, dnxhd_1238_ac_bits, dnxhd_1238_ac_level,
dnxhd_1238_ac_run_flag, dnxhd_1238_ac_index_flag,
- dnxhd_1238_run_codes, dnxhd_1238_run_bits, dnxhd_1238_run,
+ dnxhd_1235_1238_1241_run_codes, dnxhd_1235_1238_1241_run_bits, dnxhd_1238_run,
{ 175, 185, 220, 365, 440 } },
{ 1241, 1920, 1080, 1, 917504, 458752, 6, 10,
dnxhd_1241_luma_weight, dnxhd_1241_chroma_weight,
- dnxhd_1241_dc_codes, dnxhd_1241_dc_bits,
- dnxhd_1241_ac_codes, dnxhd_1241_ac_bits, dnxhd_1241_ac_level,
- dnxhd_1241_ac_run_flag, dnxhd_1241_ac_index_flag,
- dnxhd_1238_run_codes, dnxhd_1238_run_bits, dnxhd_1241_run,
+ dnxhd_1235_1241_dc_codes, dnxhd_1235_1241_dc_bits,
+ dnxhd_1235_1241_ac_codes, dnxhd_1235_1241_ac_bits, dnxhd_1235_1241_ac_level,
+ dnxhd_1235_1241_ac_run_flag, dnxhd_1235_1241_ac_index_flag,
+ dnxhd_1235_1238_1241_run_codes, dnxhd_1235_1238_1241_run_bits, dnxhd_1235_1241_run,
{ 185, 220 } },
{ 1242, 1920, 1080, 1, 606208, 303104, 4, 8,
dnxhd_1242_luma_weight, dnxhd_1242_chroma_weight,
@@ -373,8 +1102,15 @@ const CIDEntry ff_dnxhd_cid_table[] = {
dnxhd_1238_dc_codes, dnxhd_1238_dc_bits,
dnxhd_1238_ac_codes, dnxhd_1238_ac_bits, dnxhd_1238_ac_level,
dnxhd_1238_ac_run_flag, dnxhd_1238_ac_index_flag,
- dnxhd_1238_run_codes, dnxhd_1238_run_bits, dnxhd_1238_run,
+ dnxhd_1235_1238_1241_run_codes, dnxhd_1235_1238_1241_run_bits, dnxhd_1238_run,
{ 185, 220 } },
+ { 1250, 1280, 720, 0, 458752, 458752, 6, 10,
+ dnxhd_1250_luma_weight, dnxhd_1250_chroma_weight,
+ dnxhd_1250_dc_codes, dnxhd_1250_dc_bits,
+ dnxhd_1250_ac_codes, dnxhd_1250_ac_bits, dnxhd_1250_ac_level,
+ dnxhd_1250_ac_run_flag, dnxhd_1250_ac_index_flag,
+ dnxhd_1250_run_codes, dnxhd_1250_run_bits, dnxhd_1250_run,
+ { 90, 180, 220 } },
{ 1251, 1280, 720, 0, 458752, 458752, 4, 8,
dnxhd_1251_luma_weight, dnxhd_1251_chroma_weight,
dnxhd_1251_dc_codes, dnxhd_1251_dc_bits,
@@ -407,7 +1143,7 @@ int ff_dnxhd_get_cid_table(int cid)
return -1;
}
-int ff_dnxhd_find_cid(AVCodecContext *avctx)
+int ff_dnxhd_find_cid(AVCodecContext *avctx, int bit_depth)
{
int i, j;
int mbs = avctx->bit_rate/1000000;
@@ -417,7 +1153,7 @@ int ff_dnxhd_find_cid(AVCodecContext *avctx)
const CIDEntry *cid = &ff_dnxhd_cid_table[i];
if (cid->width == avctx->width && cid->height == avctx->height &&
cid->interlaced == !!(avctx->flags & CODEC_FLAG_INTERLACED_DCT) &&
- cid->bit_depth == 8) { // until 10 bit is supported
+ cid->bit_depth == bit_depth) {
for (j = 0; j < sizeof(cid->bit_rates); j++) {
if (cid->bit_rates[j] == mbs)
return cid->cid;
diff --git a/libavcodec/dnxhddata.h b/libavcodec/dnxhddata.h
index df841872fc..4d03a600f4 100644
--- a/libavcodec/dnxhddata.h
+++ b/libavcodec/dnxhddata.h
@@ -2,20 +2,20 @@
* VC3/DNxHD decoder.
* Copyright (c) 2007 SmartJog S.A., Baptiste Coudurier <baptiste dot coudurier at smartjog dot com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -46,6 +46,6 @@ typedef struct {
extern const CIDEntry ff_dnxhd_cid_table[];
int ff_dnxhd_get_cid_table(int cid);
-int ff_dnxhd_find_cid(AVCodecContext *avctx);
+int ff_dnxhd_find_cid(AVCodecContext *avctx, int bit_depth);
#endif /* AVCODEC_DNXHDDATA_H */
diff --git a/libavcodec/dnxhddec.c b/libavcodec/dnxhddec.c
index 6928b32263..ad56aabd0e 100644
--- a/libavcodec/dnxhddec.c
+++ b/libavcodec/dnxhddec.c
@@ -1,21 +1,24 @@
/*
* VC3/DNxHD decoder.
* Copyright (c) 2007 SmartJog S.A., Baptiste Coudurier <baptiste dot coudurier at smartjog dot com>
+ * Copyright (c) 2011 MirriAd Ltd
*
- * This file is part of Libav.
+ * 10 bit support added by MirriAd Ltd, Joseph Artsimovich <joseph@mirriad.com>
*
- * Libav is free software; you can redistribute it and/or
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -28,7 +31,7 @@
#include "dnxhddata.h"
#include "dsputil.h"
-typedef struct {
+typedef struct DNXHDContext {
AVCodecContext *avctx;
AVFrame picture;
GetBitContext gb;
@@ -43,18 +46,24 @@ typedef struct {
DECLARE_ALIGNED(16, DCTELEM, blocks)[8][64];
ScanTable scantable;
const CIDEntry *cid_table;
+ int bit_depth; // 8, 10 or 0 if not initialized at all.
+ void (*decode_dct_block)(struct DNXHDContext *ctx, DCTELEM *block,
+ int n, int qscale);
} DNXHDContext;
#define DNXHD_VLC_BITS 9
#define DNXHD_DC_VLC_BITS 7
+static void dnxhd_decode_dct_block_8(DNXHDContext *ctx, DCTELEM *block, int n, int qscale);
+static void dnxhd_decode_dct_block_10(DNXHDContext *ctx, DCTELEM *block, int n, int qscale);
+
static av_cold int dnxhd_decode_init(AVCodecContext *avctx)
{
DNXHDContext *ctx = avctx->priv_data;
ctx->avctx = avctx;
- dsputil_init(&ctx->dsp, avctx);
avctx->coded_frame = &ctx->picture;
+ avcodec_get_frame_defaults(&ctx->picture);
ctx->picture.type = AV_PICTURE_TYPE_I;
ctx->picture.key_frame = 1;
return 0;
@@ -62,7 +71,7 @@ static av_cold int dnxhd_decode_init(AVCodecContext *avctx)
static int dnxhd_init_vlc(DNXHDContext *ctx, int cid)
{
- if (!ctx->cid_table) {
+ if (cid != ctx->cid) {
int index;
if ((index = ff_dnxhd_get_cid_table(cid)) < 0) {
@@ -70,10 +79,15 @@ static int dnxhd_init_vlc(DNXHDContext *ctx, int cid)
return -1;
}
ctx->cid_table = &ff_dnxhd_cid_table[index];
+
+ free_vlc(&ctx->ac_vlc);
+ free_vlc(&ctx->dc_vlc);
+ free_vlc(&ctx->run_vlc);
+
init_vlc(&ctx->ac_vlc, DNXHD_VLC_BITS, 257,
ctx->cid_table->ac_bits, 1, 1,
ctx->cid_table->ac_codes, 2, 2, 0);
- init_vlc(&ctx->dc_vlc, DNXHD_DC_VLC_BITS, ctx->cid_table->bit_depth+4,
+ init_vlc(&ctx->dc_vlc, DNXHD_DC_VLC_BITS, ctx->bit_depth + 4,
ctx->cid_table->dc_bits, 1, 1,
ctx->cid_table->dc_codes, 1, 1, 0);
init_vlc(&ctx->run_vlc, DNXHD_VLC_BITS, 62,
@@ -81,6 +95,7 @@ static int dnxhd_init_vlc(DNXHDContext *ctx, int cid)
ctx->cid_table->run_codes, 2, 2, 0);
ff_init_scantable(ctx->dsp.idct_permutation, &ctx->scantable, ff_zigzag_direct);
+ ctx->cid = cid;
}
return 0;
}
@@ -88,7 +103,7 @@ static int dnxhd_init_vlc(DNXHDContext *ctx, int cid)
static int dnxhd_decode_header(DNXHDContext *ctx, const uint8_t *buf, int buf_size, int first_field)
{
static const uint8_t header_prefix[] = { 0x00, 0x00, 0x02, 0x80, 0x01 };
- int i;
+ int i, cid;
if (buf_size < 0x280)
return -1;
@@ -107,17 +122,30 @@ static int dnxhd_decode_header(DNXHDContext *ctx, const uint8_t *buf, int buf_si
ctx->height = AV_RB16(buf + 0x18);
ctx->width = AV_RB16(buf + 0x1a);
- av_dlog(ctx->avctx, "width %d, heigth %d\n", ctx->width, ctx->height);
+ av_dlog(ctx->avctx, "width %d, height %d\n", ctx->width, ctx->height);
if (buf[0x21] & 0x40) {
- av_log(ctx->avctx, AV_LOG_ERROR, "10 bit per component\n");
- return -1;
+ ctx->avctx->pix_fmt = PIX_FMT_YUV422P10;
+ ctx->avctx->bits_per_raw_sample = 10;
+ if (ctx->bit_depth != 10) {
+ dsputil_init(&ctx->dsp, ctx->avctx);
+ ctx->bit_depth = 10;
+ ctx->decode_dct_block = dnxhd_decode_dct_block_10;
+ }
+ } else {
+ ctx->avctx->pix_fmt = PIX_FMT_YUV422P;
+ ctx->avctx->bits_per_raw_sample = 8;
+ if (ctx->bit_depth != 8) {
+ dsputil_init(&ctx->dsp, ctx->avctx);
+ ctx->bit_depth = 8;
+ ctx->decode_dct_block = dnxhd_decode_dct_block_8;
+ }
}
- ctx->cid = AV_RB32(buf + 0x28);
- av_dlog(ctx->avctx, "compression id %d\n", ctx->cid);
+ cid = AV_RB32(buf + 0x28);
+ av_dlog(ctx->avctx, "compression id %d\n", cid);
- if (dnxhd_init_vlc(ctx, ctx->cid) < 0)
+ if (dnxhd_init_vlc(ctx, cid) < 0)
return -1;
if (buf_size < ctx->cid_table->coding_unit_size) {
@@ -151,79 +179,103 @@ static int dnxhd_decode_header(DNXHDContext *ctx, const uint8_t *buf, int buf_si
return 0;
}
-static int dnxhd_decode_dc(DNXHDContext *ctx)
-{
- int len;
-
- len = get_vlc2(&ctx->gb, ctx->dc_vlc.table, DNXHD_DC_VLC_BITS, 1);
- return len ? get_xbits(&ctx->gb, len) : 0;
-}
-
-static void dnxhd_decode_dct_block(DNXHDContext *ctx, DCTELEM *block, int n, int qscale)
+static av_always_inline void dnxhd_decode_dct_block(DNXHDContext *ctx,
+ DCTELEM *block, int n,
+ int qscale,
+ int index_bits,
+ int level_bias,
+ int level_shift)
{
- int i, j, index, index2;
+ int i, j, index1, index2, len;
int level, component, sign;
- const uint8_t *weigth_matrix;
+ const uint8_t *weight_matrix;
+ OPEN_READER(bs, &ctx->gb);
if (n&2) {
component = 1 + (n&1);
- weigth_matrix = ctx->cid_table->chroma_weight;
+ weight_matrix = ctx->cid_table->chroma_weight;
} else {
component = 0;
- weigth_matrix = ctx->cid_table->luma_weight;
+ weight_matrix = ctx->cid_table->luma_weight;
}
- ctx->last_dc[component] += dnxhd_decode_dc(ctx);
+ UPDATE_CACHE(bs, &ctx->gb);
+ GET_VLC(len, bs, &ctx->gb, ctx->dc_vlc.table, DNXHD_DC_VLC_BITS, 1);
+ if (len) {
+ level = GET_CACHE(bs, &ctx->gb);
+ LAST_SKIP_BITS(bs, &ctx->gb, len);
+ sign = ~level >> 31;
+ level = (NEG_USR32(sign ^ level, len) ^ sign) - sign;
+ ctx->last_dc[component] += level;
+ }
block[0] = ctx->last_dc[component];
//av_log(ctx->avctx, AV_LOG_DEBUG, "dc %d\n", block[0]);
+
for (i = 1; ; i++) {
- index = get_vlc2(&ctx->gb, ctx->ac_vlc.table, DNXHD_VLC_BITS, 2);
- //av_log(ctx->avctx, AV_LOG_DEBUG, "index %d\n", index);
- level = ctx->cid_table->ac_level[index];
+ UPDATE_CACHE(bs, &ctx->gb);
+ GET_VLC(index1, bs, &ctx->gb, ctx->ac_vlc.table,
+ DNXHD_VLC_BITS, 2);
+ //av_log(ctx->avctx, AV_LOG_DEBUG, "index %d\n", index1);
+ level = ctx->cid_table->ac_level[index1];
if (!level) { /* EOB */
//av_log(ctx->avctx, AV_LOG_DEBUG, "EOB\n");
- return;
+ break;
}
- sign = get_sbits(&ctx->gb, 1);
- if (ctx->cid_table->ac_index_flag[index]) {
- level += get_bits(&ctx->gb, ctx->cid_table->index_bits)<<6;
+ sign = SHOW_SBITS(bs, &ctx->gb, 1);
+ SKIP_BITS(bs, &ctx->gb, 1);
+
+ if (ctx->cid_table->ac_index_flag[index1]) {
+ level += SHOW_UBITS(bs, &ctx->gb, index_bits) << 6;
+ SKIP_BITS(bs, &ctx->gb, index_bits);
}
- if (ctx->cid_table->ac_run_flag[index]) {
- index2 = get_vlc2(&ctx->gb, ctx->run_vlc.table, DNXHD_VLC_BITS, 2);
+ if (ctx->cid_table->ac_run_flag[index1]) {
+ UPDATE_CACHE(bs, &ctx->gb);
+ GET_VLC(index2, bs, &ctx->gb, ctx->run_vlc.table,
+ DNXHD_VLC_BITS, 2);
i += ctx->cid_table->run[index2];
}
if (i > 63) {
av_log(ctx->avctx, AV_LOG_ERROR, "ac tex damaged %d, %d\n", n, i);
- return;
+ break;
}
j = ctx->scantable.permutated[i];
//av_log(ctx->avctx, AV_LOG_DEBUG, "j %d\n", j);
- //av_log(ctx->avctx, AV_LOG_DEBUG, "level %d, weigth %d\n", level, weigth_matrix[i]);
- level = (2*level+1) * qscale * weigth_matrix[i];
- if (ctx->cid_table->bit_depth == 10) {
- if (weigth_matrix[i] != 8)
- level += 8;
- level >>= 4;
- } else {
- if (weigth_matrix[i] != 32)
- level += 32;
- level >>= 6;
- }
+ //av_log(ctx->avctx, AV_LOG_DEBUG, "level %d, weight %d\n", level, weight_matrix[i]);
+ level = (2*level+1) * qscale * weight_matrix[i];
+ if (level_bias < 32 || weight_matrix[i] != level_bias)
+ level += level_bias;
+ level >>= level_shift;
+
//av_log(NULL, AV_LOG_DEBUG, "i %d, j %d, end level %d\n", i, j, level);
block[j] = (level^sign) - sign;
}
+
+ CLOSE_READER(bs, &ctx->gb);
+}
+
+static void dnxhd_decode_dct_block_8(DNXHDContext *ctx, DCTELEM *block,
+ int n, int qscale)
+{
+ dnxhd_decode_dct_block(ctx, block, n, qscale, 4, 32, 6);
+}
+
+static void dnxhd_decode_dct_block_10(DNXHDContext *ctx, DCTELEM *block,
+ int n, int qscale)
+{
+ dnxhd_decode_dct_block(ctx, block, n, qscale, 6, 8, 4);
}
static int dnxhd_decode_macroblock(DNXHDContext *ctx, int x, int y)
{
+ int shift1 = ctx->bit_depth == 10;
int dct_linesize_luma = ctx->picture.linesize[0];
int dct_linesize_chroma = ctx->picture.linesize[1];
uint8_t *dest_y, *dest_u, *dest_v;
- int dct_offset;
+ int dct_y_offset, dct_x_offset;
int qscale, i;
qscale = get_bits(&ctx->gb, 11);
@@ -232,7 +284,7 @@ static int dnxhd_decode_macroblock(DNXHDContext *ctx, int x, int y)
for (i = 0; i < 8; i++) {
ctx->dsp.clear_block(ctx->blocks[i]);
- dnxhd_decode_dct_block(ctx, ctx->blocks[i], i, qscale);
+ ctx->decode_dct_block(ctx, ctx->blocks[i], i, qscale);
}
if (ctx->picture.interlaced_frame) {
@@ -240,9 +292,9 @@ static int dnxhd_decode_macroblock(DNXHDContext *ctx, int x, int y)
dct_linesize_chroma <<= 1;
}
- dest_y = ctx->picture.data[0] + ((y * dct_linesize_luma) << 4) + (x << 4);
- dest_u = ctx->picture.data[1] + ((y * dct_linesize_chroma) << 4) + (x << 3);
- dest_v = ctx->picture.data[2] + ((y * dct_linesize_chroma) << 4) + (x << 3);
+ dest_y = ctx->picture.data[0] + ((y * dct_linesize_luma) << 4) + (x << (4 + shift1));
+ dest_u = ctx->picture.data[1] + ((y * dct_linesize_chroma) << 4) + (x << (3 + shift1));
+ dest_v = ctx->picture.data[2] + ((y * dct_linesize_chroma) << 4) + (x << (3 + shift1));
if (ctx->cur_field) {
dest_y += ctx->picture.linesize[0];
@@ -250,18 +302,19 @@ static int dnxhd_decode_macroblock(DNXHDContext *ctx, int x, int y)
dest_v += ctx->picture.linesize[2];
}
- dct_offset = dct_linesize_luma << 3;
- ctx->dsp.idct_put(dest_y, dct_linesize_luma, ctx->blocks[0]);
- ctx->dsp.idct_put(dest_y + 8, dct_linesize_luma, ctx->blocks[1]);
- ctx->dsp.idct_put(dest_y + dct_offset, dct_linesize_luma, ctx->blocks[4]);
- ctx->dsp.idct_put(dest_y + dct_offset + 8, dct_linesize_luma, ctx->blocks[5]);
+ dct_y_offset = dct_linesize_luma << 3;
+ dct_x_offset = 8 << shift1;
+ ctx->dsp.idct_put(dest_y, dct_linesize_luma, ctx->blocks[0]);
+ ctx->dsp.idct_put(dest_y + dct_x_offset, dct_linesize_luma, ctx->blocks[1]);
+ ctx->dsp.idct_put(dest_y + dct_y_offset, dct_linesize_luma, ctx->blocks[4]);
+ ctx->dsp.idct_put(dest_y + dct_y_offset + dct_x_offset, dct_linesize_luma, ctx->blocks[5]);
if (!(ctx->avctx->flags & CODEC_FLAG_GRAY)) {
- dct_offset = dct_linesize_chroma << 3;
- ctx->dsp.idct_put(dest_u, dct_linesize_chroma, ctx->blocks[2]);
- ctx->dsp.idct_put(dest_v, dct_linesize_chroma, ctx->blocks[3]);
- ctx->dsp.idct_put(dest_u + dct_offset, dct_linesize_chroma, ctx->blocks[6]);
- ctx->dsp.idct_put(dest_v + dct_offset, dct_linesize_chroma, ctx->blocks[7]);
+ dct_y_offset = dct_linesize_chroma << 3;
+ ctx->dsp.idct_put(dest_u, dct_linesize_chroma, ctx->blocks[2]);
+ ctx->dsp.idct_put(dest_v, dct_linesize_chroma, ctx->blocks[3]);
+ ctx->dsp.idct_put(dest_u + dct_y_offset, dct_linesize_chroma, ctx->blocks[6]);
+ ctx->dsp.idct_put(dest_v + dct_y_offset, dct_linesize_chroma, ctx->blocks[7]);
}
return 0;
@@ -273,7 +326,7 @@ static int dnxhd_decode_macroblocks(DNXHDContext *ctx, const uint8_t *buf, int b
for (y = 0; y < ctx->mb_height; y++) {
ctx->last_dc[0] =
ctx->last_dc[1] =
- ctx->last_dc[2] = 1<<(ctx->cid_table->bit_depth+2); // for levels +2^(bitdepth-1)
+ ctx->last_dc[2] = 1 << (ctx->bit_depth + 2); // for levels +2^(bitdepth-1)
init_get_bits(&ctx->gb, buf + ctx->mb_scan_index[y], (buf_size - ctx->mb_scan_index[y]) << 3);
for (x = 0; x < ctx->mb_width; x++) {
//START_TIMER;
@@ -306,7 +359,6 @@ static int dnxhd_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
first_field = 1;
}
- avctx->pix_fmt = PIX_FMT_YUV422P;
if (av_image_check_size(ctx->width, ctx->height, 0, avctx))
return -1;
avcodec_set_dimensions(avctx, ctx->width, ctx->height);
@@ -347,14 +399,13 @@ static av_cold int dnxhd_decode_close(AVCodecContext *avctx)
}
AVCodec ff_dnxhd_decoder = {
- "dnxhd",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_DNXHD,
- sizeof(DNXHDContext),
- dnxhd_decode_init,
- NULL,
- dnxhd_decode_close,
- dnxhd_decode_frame,
- CODEC_CAP_DR1,
+ .name = "dnxhd",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_DNXHD,
+ .priv_data_size = sizeof(DNXHDContext),
+ .init = dnxhd_decode_init,
+ .close = dnxhd_decode_close,
+ .decode = dnxhd_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("VC3/DNxHD"),
};
diff --git a/libavcodec/dnxhdenc.c b/libavcodec/dnxhdenc.c
index 78da1c15e2..cd1261af3c 100644
--- a/libavcodec/dnxhdenc.c
+++ b/libavcodec/dnxhdenc.c
@@ -1,23 +1,25 @@
/*
* VC3/DNxHD encoder
* Copyright (c) 2007 Baptiste Coudurier <baptiste dot coudurier at smartjog dot com>
+ * Copyright (c) 2011 MirriAd Ltd
*
* VC-3 encoder funded by the British Broadcasting Corporation
+ * 10 bit support added by MirriAd Ltd, Joseph Artsimovich <joseph@mirriad.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -28,21 +30,21 @@
#include "avcodec.h"
#include "dsputil.h"
#include "mpegvideo.h"
+#include "mpegvideo_common.h"
#include "dnxhdenc.h"
#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
+#define DNX10BIT_QMAT_SHIFT 18 // The largest value that will not lead to overflow for 10bit samples.
static const AVOption options[]={
- {"nitris_compat", "encode with Avid Nitris compatibility", offsetof(DNXHDEncContext, nitris_compat), FF_OPT_TYPE_INT, {.dbl = 0}, 0, 1, VE},
+ {"nitris_compat", "encode with Avid Nitris compatibility", offsetof(DNXHDEncContext, nitris_compat), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 1, VE},
{NULL}
};
static const AVClass class = { "dnxhd", av_default_item_name, options, LIBAVUTIL_VERSION_INT };
-int dct_quantize_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow);
-
#define LAMBDA_FRAC_BITS 10
-static av_always_inline void dnxhd_get_pixels_8x4(DCTELEM *restrict block, const uint8_t *pixels, int line_size)
+static void dnxhd_8bit_get_pixels_8x4_sym(DCTELEM *restrict block, const uint8_t *pixels, int line_size)
{
int i;
for (i = 0; i < 4; i++) {
@@ -53,10 +55,48 @@ static av_always_inline void dnxhd_get_pixels_8x4(DCTELEM *restrict block, const
pixels += line_size;
block += 8;
}
- memcpy(block , block- 8, sizeof(*block)*8);
- memcpy(block+ 8, block-16, sizeof(*block)*8);
- memcpy(block+16, block-24, sizeof(*block)*8);
- memcpy(block+24, block-32, sizeof(*block)*8);
+ memcpy(block, block - 8, sizeof(*block) * 8);
+ memcpy(block + 8, block - 16, sizeof(*block) * 8);
+ memcpy(block + 16, block - 24, sizeof(*block) * 8);
+ memcpy(block + 24, block - 32, sizeof(*block) * 8);
+}
+
+static av_always_inline void dnxhd_10bit_get_pixels_8x4_sym(DCTELEM *restrict block, const uint8_t *pixels, int line_size)
+{
+ int i;
+
+ block += 32;
+
+ for (i = 0; i < 4; i++) {
+ memcpy(block + i * 8, pixels + i * line_size, 8 * sizeof(*block));
+ memcpy(block - (i+1) * 8, pixels + i * line_size, 8 * sizeof(*block));
+ }
+}
+
+static int dnxhd_10bit_dct_quantize(MpegEncContext *ctx, DCTELEM *block,
+ int n, int qscale, int *overflow)
+{
+ const uint8_t *scantable= ctx->intra_scantable.scantable;
+ const int *qmat = n<4 ? ctx->q_intra_matrix[qscale] : ctx->q_chroma_intra_matrix[qscale];
+ int last_non_zero = 0;
+ int i;
+
+ ctx->dsp.fdct(block);
+
+ // Divide by 4 with rounding, to compensate scaling of DCT coefficients
+ block[0] = (block[0] + 2) >> 2;
+
+ for (i = 1; i < 64; ++i) {
+ int j = scantable[i];
+ int sign = block[j] >> 31;
+ int level = (block[j] ^ sign) - sign;
+ level = level * qmat[j] >> DNX10BIT_QMAT_SHIFT;
+ block[j] = (level ^ sign) - sign;
+ if (level)
+ last_non_zero = i;
+ }
+
+ return last_non_zero;
}
static int dnxhd_init_vlc(DNXHDEncContext *ctx)
@@ -65,9 +105,9 @@ static int dnxhd_init_vlc(DNXHDEncContext *ctx)
int max_level = 1<<(ctx->cid_table->bit_depth+2);
FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->vlc_codes, max_level*4*sizeof(*ctx->vlc_codes), fail);
- FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->vlc_bits , max_level*4*sizeof(*ctx->vlc_bits ), fail);
- FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->run_codes, 63*2 , fail);
- FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->run_bits , 63 , fail);
+ FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->vlc_bits, max_level*4*sizeof(*ctx->vlc_bits) , fail);
+ FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->run_codes, 63*2, fail);
+ FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->run_bits, 63, fail);
ctx->vlc_codes += max_level*2;
ctx->vlc_bits += max_level*2;
@@ -119,31 +159,60 @@ static int dnxhd_init_qmat(DNXHDEncContext *ctx, int lbias, int cbias)
// init first elem to 1 to avoid div by 0 in convert_matrix
uint16_t weight_matrix[64] = {1,}; // convert_matrix needs uint16_t*
int qscale, i;
+ const uint8_t *luma_weight_table = ctx->cid_table->luma_weight;
+ const uint8_t *chroma_weight_table = ctx->cid_table->chroma_weight;
- FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->qmatrix_l, (ctx->m.avctx->qmax+1) * 64 * sizeof(int) , fail);
- FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->qmatrix_c, (ctx->m.avctx->qmax+1) * 64 * sizeof(int) , fail);
+ FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->qmatrix_l, (ctx->m.avctx->qmax+1) * 64 * sizeof(int), fail);
+ FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->qmatrix_c, (ctx->m.avctx->qmax+1) * 64 * sizeof(int), fail);
FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->qmatrix_l16, (ctx->m.avctx->qmax+1) * 64 * 2 * sizeof(uint16_t), fail);
FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->qmatrix_c16, (ctx->m.avctx->qmax+1) * 64 * 2 * sizeof(uint16_t), fail);
- for (i = 1; i < 64; i++) {
- int j = ctx->m.dsp.idct_permutation[ff_zigzag_direct[i]];
- weight_matrix[j] = ctx->cid_table->luma_weight[i];
- }
- ff_convert_matrix(&ctx->m.dsp, ctx->qmatrix_l, ctx->qmatrix_l16, weight_matrix,
- ctx->m.intra_quant_bias, 1, ctx->m.avctx->qmax, 1);
- for (i = 1; i < 64; i++) {
- int j = ctx->m.dsp.idct_permutation[ff_zigzag_direct[i]];
- weight_matrix[j] = ctx->cid_table->chroma_weight[i];
- }
- ff_convert_matrix(&ctx->m.dsp, ctx->qmatrix_c, ctx->qmatrix_c16, weight_matrix,
- ctx->m.intra_quant_bias, 1, ctx->m.avctx->qmax, 1);
- for (qscale = 1; qscale <= ctx->m.avctx->qmax; qscale++) {
- for (i = 0; i < 64; i++) {
- ctx->qmatrix_l [qscale] [i] <<= 2; ctx->qmatrix_c [qscale] [i] <<= 2;
- ctx->qmatrix_l16[qscale][0][i] <<= 2; ctx->qmatrix_l16[qscale][1][i] <<= 2;
- ctx->qmatrix_c16[qscale][0][i] <<= 2; ctx->qmatrix_c16[qscale][1][i] <<= 2;
+ if (ctx->cid_table->bit_depth == 8) {
+ for (i = 1; i < 64; i++) {
+ int j = ctx->m.dsp.idct_permutation[ff_zigzag_direct[i]];
+ weight_matrix[j] = ctx->cid_table->luma_weight[i];
+ }
+ ff_convert_matrix(&ctx->m.dsp, ctx->qmatrix_l, ctx->qmatrix_l16, weight_matrix,
+ ctx->m.intra_quant_bias, 1, ctx->m.avctx->qmax, 1);
+ for (i = 1; i < 64; i++) {
+ int j = ctx->m.dsp.idct_permutation[ff_zigzag_direct[i]];
+ weight_matrix[j] = ctx->cid_table->chroma_weight[i];
+ }
+ ff_convert_matrix(&ctx->m.dsp, ctx->qmatrix_c, ctx->qmatrix_c16, weight_matrix,
+ ctx->m.intra_quant_bias, 1, ctx->m.avctx->qmax, 1);
+
+ for (qscale = 1; qscale <= ctx->m.avctx->qmax; qscale++) {
+ for (i = 0; i < 64; i++) {
+ ctx->qmatrix_l [qscale] [i] <<= 2; ctx->qmatrix_c [qscale] [i] <<= 2;
+ ctx->qmatrix_l16[qscale][0][i] <<= 2; ctx->qmatrix_l16[qscale][1][i] <<= 2;
+ ctx->qmatrix_c16[qscale][0][i] <<= 2; ctx->qmatrix_c16[qscale][1][i] <<= 2;
+ }
+ }
+ } else {
+ // 10-bit
+ for (qscale = 1; qscale <= ctx->m.avctx->qmax; qscale++) {
+ for (i = 1; i < 64; i++) {
+ int j = ctx->m.dsp.idct_permutation[ff_zigzag_direct[i]];
+
+ // The quantization formula from the VC-3 standard is:
+ // quantized = sign(block[i]) * floor(abs(block[i]/s) * p / (qscale * weight_table[i]))
+ // Where p is 32 for 8-bit samples and 8 for 10-bit ones.
+ // The s factor compensates scaling of DCT coefficients done by the DCT routines,
+ // and therefore is not present in standard. It's 8 for 8-bit samples and 4 for 10-bit ones.
+ // We want values of ctx->qtmatrix_l and ctx->qtmatrix_r to be:
+ // ((1 << DNX10BIT_QMAT_SHIFT) * (p / s)) / (qscale * weight_table[i])
+ // For 10-bit samples, p / s == 2
+ ctx->qmatrix_l[qscale][j] = (1 << (DNX10BIT_QMAT_SHIFT + 1)) / (qscale * luma_weight_table[i]);
+ ctx->qmatrix_c[qscale][j] = (1 << (DNX10BIT_QMAT_SHIFT + 1)) / (qscale * chroma_weight_table[i]);
+ }
}
}
+
+ ctx->m.q_chroma_intra_matrix16 = ctx->qmatrix_c16;
+ ctx->m.q_chroma_intra_matrix = ctx->qmatrix_c;
+ ctx->m.q_intra_matrix16 = ctx->qmatrix_l16;
+ ctx->m.q_intra_matrix = ctx->qmatrix_l;
+
return 0;
fail:
return -1;
@@ -166,10 +235,22 @@ static int dnxhd_init_rc(DNXHDEncContext *ctx)
static int dnxhd_encode_init(AVCodecContext *avctx)
{
DNXHDEncContext *ctx = avctx->priv_data;
- int i, index;
+ int i, index, bit_depth;
+
+ switch (avctx->pix_fmt) {
+ case PIX_FMT_YUV422P:
+ bit_depth = 8;
+ break;
+ case PIX_FMT_YUV422P10:
+ bit_depth = 10;
+ break;
+ default:
+ av_log(avctx, AV_LOG_ERROR, "pixel format is incompatible with DNxHD\n");
+ return -1;
+ }
- ctx->cid = ff_dnxhd_find_cid(avctx);
- if (!ctx->cid || avctx->pix_fmt != PIX_FMT_YUV422P) {
+ ctx->cid = ff_dnxhd_find_cid(avctx, bit_depth);
+ if (!ctx->cid) {
av_log(avctx, AV_LOG_ERROR, "video parameters incompatible with DNxHD\n");
return -1;
}
@@ -182,15 +263,25 @@ static int dnxhd_encode_init(AVCodecContext *avctx)
ctx->m.mb_intra = 1;
ctx->m.h263_aic = 1;
- ctx->get_pixels_8x4_sym = dnxhd_get_pixels_8x4;
+ avctx->bits_per_raw_sample = ctx->cid_table->bit_depth;
dsputil_init(&ctx->m.dsp, avctx);
ff_dct_common_init(&ctx->m);
+ if (!ctx->m.dct_quantize)
+ ctx->m.dct_quantize = dct_quantize_c;
+
+ if (ctx->cid_table->bit_depth == 10) {
+ ctx->m.dct_quantize = dnxhd_10bit_dct_quantize;
+ ctx->get_pixels_8x4_sym = dnxhd_10bit_get_pixels_8x4_sym;
+ ctx->block_width_l2 = 4;
+ } else {
+ ctx->get_pixels_8x4_sym = dnxhd_8bit_get_pixels_8x4_sym;
+ ctx->block_width_l2 = 3;
+ }
+
#if HAVE_MMX
ff_dnxhd_init_mmx(ctx);
#endif
- if (!ctx->m.dct_quantize)
- ctx->m.dct_quantize = dct_quantize_c;
ctx->m.mb_height = (avctx->height + 15) / 16;
ctx->m.mb_width = (avctx->width + 15) / 16;
@@ -219,7 +310,7 @@ static int dnxhd_encode_init(AVCodecContext *avctx)
FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->slice_size, ctx->m.mb_height*sizeof(uint32_t), fail);
FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->slice_offs, ctx->m.mb_height*sizeof(uint32_t), fail);
FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->mb_bits, ctx->m.mb_num *sizeof(uint16_t), fail);
- FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->mb_qscale, ctx->m.mb_num *sizeof(uint8_t) , fail);
+ FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->mb_qscale, ctx->m.mb_num *sizeof(uint8_t), fail);
ctx->frame.key_frame = 1;
ctx->frame.pict_type = AV_PICTURE_TYPE_I;
@@ -256,7 +347,7 @@ static int dnxhd_write_header(AVCodecContext *avctx, uint8_t *buf)
AV_WB16(buf + 0x1a, avctx->width); // SPL
AV_WB16(buf + 0x1d, avctx->height>>ctx->interlaced); // NAL
- buf[0x21] = 0x38; // FIXME 8 bit per comp
+ buf[0x21] = ctx->cid_table->bit_depth == 10 ? 0x58 : 0x38;
buf[0x22] = 0x88 + (ctx->interlaced<<2);
AV_WB32(buf + 0x28, ctx->cid); // CID
buf[0x2c] = ctx->interlaced ? 0 : 0x80;
@@ -322,15 +413,27 @@ static av_always_inline void dnxhd_unquantize_c(DNXHDEncContext *ctx, DCTELEM *b
if (level) {
if (level < 0) {
level = (1-2*level) * qscale * weight_matrix[i];
- if (weight_matrix[i] != 32)
- level += 32;
- level >>= 6;
+ if (ctx->cid_table->bit_depth == 10) {
+ if (weight_matrix[i] != 8)
+ level += 8;
+ level >>= 4;
+ } else {
+ if (weight_matrix[i] != 32)
+ level += 32;
+ level >>= 6;
+ }
level = -level;
} else {
level = (2*level+1) * qscale * weight_matrix[i];
- if (weight_matrix[i] != 32)
- level += 32;
- level >>= 6;
+ if (ctx->cid_table->bit_depth == 10) {
+ if (weight_matrix[i] != 8)
+ level += 8;
+ level >>= 4;
+ } else {
+ if (weight_matrix[i] != 32)
+ level += 32;
+ level >>= 6;
+ }
}
block[j] = level;
}
@@ -342,7 +445,7 @@ static av_always_inline int dnxhd_ssd_block(DCTELEM *qblock, DCTELEM *block)
int score = 0;
int i;
for (i = 0; i < 64; i++)
- score += (block[i]-qblock[i])*(block[i]-qblock[i]);
+ score += (block[i] - qblock[i]) * (block[i] - qblock[i]);
return score;
}
@@ -365,45 +468,42 @@ static av_always_inline int dnxhd_calc_ac_bits(DNXHDEncContext *ctx, DCTELEM *bl
static av_always_inline void dnxhd_get_blocks(DNXHDEncContext *ctx, int mb_x, int mb_y)
{
- const uint8_t *ptr_y = ctx->thread[0]->src[0] + ((mb_y << 4) * ctx->m.linesize) + (mb_x << 4);
- const uint8_t *ptr_u = ctx->thread[0]->src[1] + ((mb_y << 4) * ctx->m.uvlinesize) + (mb_x << 3);
- const uint8_t *ptr_v = ctx->thread[0]->src[2] + ((mb_y << 4) * ctx->m.uvlinesize) + (mb_x << 3);
+ const int bs = ctx->block_width_l2;
+ const int bw = 1 << bs;
+ const uint8_t *ptr_y = ctx->thread[0]->src[0] + ((mb_y << 4) * ctx->m.linesize) + (mb_x << bs+1);
+ const uint8_t *ptr_u = ctx->thread[0]->src[1] + ((mb_y << 4) * ctx->m.uvlinesize) + (mb_x << bs);
+ const uint8_t *ptr_v = ctx->thread[0]->src[2] + ((mb_y << 4) * ctx->m.uvlinesize) + (mb_x << bs);
DSPContext *dsp = &ctx->m.dsp;
- dsp->get_pixels(ctx->blocks[0], ptr_y , ctx->m.linesize);
- dsp->get_pixels(ctx->blocks[1], ptr_y + 8, ctx->m.linesize);
- dsp->get_pixels(ctx->blocks[2], ptr_u , ctx->m.uvlinesize);
- dsp->get_pixels(ctx->blocks[3], ptr_v , ctx->m.uvlinesize);
+ dsp->get_pixels(ctx->blocks[0], ptr_y, ctx->m.linesize);
+ dsp->get_pixels(ctx->blocks[1], ptr_y + bw, ctx->m.linesize);
+ dsp->get_pixels(ctx->blocks[2], ptr_u, ctx->m.uvlinesize);
+ dsp->get_pixels(ctx->blocks[3], ptr_v, ctx->m.uvlinesize);
if (mb_y+1 == ctx->m.mb_height && ctx->m.avctx->height == 1080) {
if (ctx->interlaced) {
- ctx->get_pixels_8x4_sym(ctx->blocks[4], ptr_y + ctx->dct_y_offset , ctx->m.linesize);
- ctx->get_pixels_8x4_sym(ctx->blocks[5], ptr_y + ctx->dct_y_offset + 8, ctx->m.linesize);
- ctx->get_pixels_8x4_sym(ctx->blocks[6], ptr_u + ctx->dct_uv_offset , ctx->m.uvlinesize);
- ctx->get_pixels_8x4_sym(ctx->blocks[7], ptr_v + ctx->dct_uv_offset , ctx->m.uvlinesize);
+ ctx->get_pixels_8x4_sym(ctx->blocks[4], ptr_y + ctx->dct_y_offset, ctx->m.linesize);
+ ctx->get_pixels_8x4_sym(ctx->blocks[5], ptr_y + ctx->dct_y_offset + bw, ctx->m.linesize);
+ ctx->get_pixels_8x4_sym(ctx->blocks[6], ptr_u + ctx->dct_uv_offset, ctx->m.uvlinesize);
+ ctx->get_pixels_8x4_sym(ctx->blocks[7], ptr_v + ctx->dct_uv_offset, ctx->m.uvlinesize);
} else {
- dsp->clear_block(ctx->blocks[4]); dsp->clear_block(ctx->blocks[5]);
- dsp->clear_block(ctx->blocks[6]); dsp->clear_block(ctx->blocks[7]);
+ dsp->clear_block(ctx->blocks[4]);
+ dsp->clear_block(ctx->blocks[5]);
+ dsp->clear_block(ctx->blocks[6]);
+ dsp->clear_block(ctx->blocks[7]);
}
} else {
- dsp->get_pixels(ctx->blocks[4], ptr_y + ctx->dct_y_offset , ctx->m.linesize);
- dsp->get_pixels(ctx->blocks[5], ptr_y + ctx->dct_y_offset + 8, ctx->m.linesize);
- dsp->get_pixels(ctx->blocks[6], ptr_u + ctx->dct_uv_offset , ctx->m.uvlinesize);
- dsp->get_pixels(ctx->blocks[7], ptr_v + ctx->dct_uv_offset , ctx->m.uvlinesize);
+ dsp->get_pixels(ctx->blocks[4], ptr_y + ctx->dct_y_offset, ctx->m.linesize);
+ dsp->get_pixels(ctx->blocks[5], ptr_y + ctx->dct_y_offset + bw, ctx->m.linesize);
+ dsp->get_pixels(ctx->blocks[6], ptr_u + ctx->dct_uv_offset, ctx->m.uvlinesize);
+ dsp->get_pixels(ctx->blocks[7], ptr_v + ctx->dct_uv_offset, ctx->m.uvlinesize);
}
}
static av_always_inline int dnxhd_switch_matrix(DNXHDEncContext *ctx, int i)
{
- if (i&2) {
- ctx->m.q_intra_matrix16 = ctx->qmatrix_c16;
- ctx->m.q_intra_matrix = ctx->qmatrix_c;
- return 1 + (i&1);
- } else {
- ctx->m.q_intra_matrix16 = ctx->qmatrix_l16;
- ctx->m.q_intra_matrix = ctx->qmatrix_l;
- return 0;
- }
+ const static uint8_t component[8]={0,0,1,2,0,0,1,2};
+ return component[i];
}
static int dnxhd_calc_bits_thread(AVCodecContext *avctx, void *arg, int jobnr, int threadnr)
@@ -416,7 +516,7 @@ static int dnxhd_calc_bits_thread(AVCodecContext *avctx, void *arg, int jobnr, i
ctx->m.last_dc[0] =
ctx->m.last_dc[1] =
- ctx->m.last_dc[2] = 1024;
+ ctx->m.last_dc[2] = 1 << (ctx->cid_table->bit_depth + 2);
for (mb_x = 0; mb_x < ctx->m.mb_width; mb_x++) {
unsigned mb = mb_y * ctx->m.mb_width + mb_x;
@@ -433,12 +533,14 @@ static int dnxhd_calc_bits_thread(AVCodecContext *avctx, void *arg, int jobnr, i
int n = dnxhd_switch_matrix(ctx, i);
memcpy(block, src_block, 64*sizeof(*block));
- last_index = ctx->m.dct_quantize(&ctx->m, block, i, qscale, &overflow);
+ last_index = ctx->m.dct_quantize(&ctx->m, block, 4&(2*i), qscale, &overflow);
ac_bits += dnxhd_calc_ac_bits(ctx, block, last_index);
diff = block[0] - ctx->m.last_dc[n];
if (diff < 0) nbits = av_log2_16bit(-2*diff);
else nbits = av_log2_16bit( 2*diff);
+
+ assert(nbits < ctx->cid_table->bit_depth + 4);
dc_bits += ctx->cid_table->dc_bits[nbits] + nbits;
ctx->m.last_dc[n] = block[0];
@@ -464,7 +566,7 @@ static int dnxhd_encode_thread(AVCodecContext *avctx, void *arg, int jobnr, int
ctx->m.last_dc[0] =
ctx->m.last_dc[1] =
- ctx->m.last_dc[2] = 1024;
+ ctx->m.last_dc[2] = 1 << (ctx->cid_table->bit_depth + 2);
for (mb_x = 0; mb_x < ctx->m.mb_width; mb_x++) {
unsigned mb = mb_y * ctx->m.mb_width + mb_x;
int qscale = ctx->mb_qscale[mb];
@@ -478,7 +580,7 @@ static int dnxhd_encode_thread(AVCodecContext *avctx, void *arg, int jobnr, int
DCTELEM *block = ctx->blocks[i];
int last_index, overflow;
int n = dnxhd_switch_matrix(ctx, i);
- last_index = ctx->m.dct_quantize(&ctx->m, block, i, qscale, &overflow);
+ last_index = ctx->m.dct_quantize(&ctx->m, block, 4&(2*i), qscale, &overflow);
//START_TIMER;
dnxhd_encode_block(ctx, block, last_index, n);
//STOP_TIMER("encode_block");
@@ -497,14 +599,14 @@ static void dnxhd_setup_threads_slices(DNXHDEncContext *ctx)
for (mb_y = 0; mb_y < ctx->m.mb_height; mb_y++) {
int thread_size;
ctx->slice_offs[mb_y] = offset;
- ctx->slice_size[mb_y] = 0;
- for (mb_x = 0; mb_x < ctx->m.mb_width; mb_x++) {
- unsigned mb = mb_y * ctx->m.mb_width + mb_x;
- ctx->slice_size[mb_y] += ctx->mb_bits[mb];
- }
- ctx->slice_size[mb_y] = (ctx->slice_size[mb_y]+31)&~31;
- ctx->slice_size[mb_y] >>= 3;
- thread_size = ctx->slice_size[mb_y];
+ ctx->slice_size[mb_y] = 0;
+ for (mb_x = 0; mb_x < ctx->m.mb_width; mb_x++) {
+ unsigned mb = mb_y * ctx->m.mb_width + mb_x;
+ ctx->slice_size[mb_y] += ctx->mb_bits[mb];
+ }
+ ctx->slice_size[mb_y] = (ctx->slice_size[mb_y]+31)&~31;
+ ctx->slice_size[mb_y] >>= 3;
+ thread_size = ctx->slice_size[mb_y];
offset += thread_size;
}
}
@@ -514,13 +616,40 @@ static int dnxhd_mb_var_thread(AVCodecContext *avctx, void *arg, int jobnr, int
DNXHDEncContext *ctx = avctx->priv_data;
int mb_y = jobnr, mb_x;
ctx = ctx->thread[threadnr];
- for (mb_x = 0; mb_x < ctx->m.mb_width; mb_x++) {
- unsigned mb = mb_y * ctx->m.mb_width + mb_x;
- uint8_t *pix = ctx->thread[0]->src[0] + ((mb_y<<4) * ctx->m.linesize) + (mb_x<<4);
- int sum = ctx->m.dsp.pix_sum(pix, ctx->m.linesize);
- int varc = (ctx->m.dsp.pix_norm1(pix, ctx->m.linesize) - (((unsigned)(sum*sum))>>8)+128)>>8;
- ctx->mb_cmp[mb].value = varc;
- ctx->mb_cmp[mb].mb = mb;
+ if (ctx->cid_table->bit_depth == 8) {
+ uint8_t *pix = ctx->thread[0]->src[0] + ((mb_y<<4) * ctx->m.linesize);
+ for (mb_x = 0; mb_x < ctx->m.mb_width; ++mb_x, pix += 16) {
+ unsigned mb = mb_y * ctx->m.mb_width + mb_x;
+ int sum = ctx->m.dsp.pix_sum(pix, ctx->m.linesize);
+ int varc = (ctx->m.dsp.pix_norm1(pix, ctx->m.linesize) - (((unsigned)sum*sum)>>8)+128)>>8;
+ ctx->mb_cmp[mb].value = varc;
+ ctx->mb_cmp[mb].mb = mb;
+ }
+ } else { // 10-bit
+ int const linesize = ctx->m.linesize >> 1;
+ for (mb_x = 0; mb_x < ctx->m.mb_width; ++mb_x) {
+ uint16_t *pix = (uint16_t*)ctx->thread[0]->src[0] + ((mb_y << 4) * linesize) + (mb_x << 4);
+ unsigned mb = mb_y * ctx->m.mb_width + mb_x;
+ int sum = 0;
+ int sqsum = 0;
+ int mean, sqmean;
+ int i, j;
+ // Macroblocks are 16x16 pixels, unlike DCT blocks which are 8x8.
+ for (i = 0; i < 16; ++i) {
+ for (j = 0; j < 16; ++j) {
+ // Turn 16-bit pixels into 10-bit ones.
+ int const sample = (unsigned)pix[j] >> 6;
+ sum += sample;
+ sqsum += sample * sample;
+ // 2^10 * 2^10 * 16 * 16 = 2^28, which is less than INT_MAX
+ }
+ pix += linesize;
+ }
+ mean = sum >> 8; // 16*16 == 2^8
+ sqmean = sqsum >> 8;
+ ctx->mb_cmp[mb].value = sqmean - mean * mean;
+ ctx->mb_cmp[mb].mb = mb;
+ }
}
return 0;
}
@@ -862,15 +991,15 @@ static int dnxhd_encode_end(AVCodecContext *avctx)
}
AVCodec ff_dnxhd_encoder = {
- "dnxhd",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_DNXHD,
- sizeof(DNXHDEncContext),
- dnxhd_encode_init,
- dnxhd_encode_picture,
- dnxhd_encode_end,
+ .name = "dnxhd",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_DNXHD,
+ .priv_data_size = sizeof(DNXHDEncContext),
+ .init = dnxhd_encode_init,
+ .encode = dnxhd_encode_picture,
+ .close = dnxhd_encode_end,
.capabilities = CODEC_CAP_SLICE_THREADS,
- .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUV422P, PIX_FMT_NONE},
+ .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUV422P, PIX_FMT_YUV422P10, PIX_FMT_NONE},
.long_name = NULL_IF_CONFIG_SMALL("VC3/DNxHD"),
.priv_class = &class,
};
diff --git a/libavcodec/dnxhdenc.h b/libavcodec/dnxhdenc.h
index bb24540a9f..80b6f85c89 100644
--- a/libavcodec/dnxhdenc.h
+++ b/libavcodec/dnxhdenc.h
@@ -4,20 +4,20 @@
*
* VC-3 encoder funded by the British Broadcasting Corporation
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -52,8 +52,12 @@ typedef struct DNXHDEncContext {
struct DNXHDEncContext *thread[MAX_THREADS];
+ // Because our samples are either 8 or 16 bits for 8-bit and 10-bit
+ // encoding respectively, these refer either to bytes or to two-byte words.
unsigned dct_y_offset;
unsigned dct_uv_offset;
+ unsigned block_width_l2;
+
int interlaced;
int cur_field;
diff --git a/libavcodec/dpcm.c b/libavcodec/dpcm.c
index af5bf8abea..8f6cd8e115 100644
--- a/libavcodec/dpcm.c
+++ b/libavcodec/dpcm.c
@@ -2,20 +2,20 @@
* Assorted DPCM codecs
* Copyright (c) 2003 The ffmpeg Project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -39,17 +39,16 @@
#include "libavutil/intreadwrite.h"
#include "avcodec.h"
+#include "bytestream.h"
typedef struct DPCMContext {
int channels;
- short roq_square_array[256];
- long sample[2];//for SOL_DPCM
- const int *sol_table;//for SOL_DPCM
+ int16_t roq_square_array[256];
+ int sample[2]; ///< previous sample (for SOL_DPCM)
+ const int8_t *sol_table; ///< delta table for SOL_DPCM
} DPCMContext;
-#define SE_16BIT(x) if (x & 0x8000) x -= 0x10000;
-
-static const int interplay_delta_table[] = {
+static const int16_t interplay_delta_table[] = {
0, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23,
@@ -85,15 +84,17 @@ static const int interplay_delta_table[] = {
};
-static const int sol_table_old[16] =
- { 0x0, 0x1, 0x2 , 0x3, 0x6, 0xA, 0xF, 0x15,
- -0x15, -0xF, -0xA, -0x6, -0x3, -0x2, -0x1, 0x0};
+static const int8_t sol_table_old[16] = {
+ 0x0, 0x1, 0x2, 0x3, 0x6, 0xA, 0xF, 0x15,
+ -0x15, -0xF, -0xA, -0x6, -0x3, -0x2, -0x1, 0x0
+};
-static const int sol_table_new[16] =
- { 0x0, 0x1, 0x2, 0x3, 0x6, 0xA, 0xF, 0x15,
- 0x0, -0x1, -0x2, -0x3, -0x6, -0xA, -0xF, -0x15};
+static const int8_t sol_table_new[16] = {
+ 0x0, 0x1, 0x2, 0x3, 0x6, 0xA, 0xF, 0x15,
+ 0x0, -0x1, -0x2, -0x3, -0x6, -0xA, -0xF, -0x15
+};
-static const int sol_table_16[128] = {
+static const int16_t sol_table_16[128] = {
0x000, 0x008, 0x010, 0x020, 0x030, 0x040, 0x050, 0x060, 0x070, 0x080,
0x090, 0x0A0, 0x0B0, 0x0C0, 0x0D0, 0x0E0, 0x0F0, 0x100, 0x110, 0x120,
0x130, 0x140, 0x150, 0x160, 0x170, 0x180, 0x190, 0x1A0, 0x1B0, 0x1C0,
@@ -110,12 +111,15 @@ static const int sol_table_16[128] = {
};
-
static av_cold int dpcm_decode_init(AVCodecContext *avctx)
{
DPCMContext *s = avctx->priv_data;
int i;
- short square;
+
+ if (avctx->channels < 1 || avctx->channels > 2) {
+ av_log(avctx, AV_LOG_INFO, "invalid number of channels\n");
+ return AVERROR(EINVAL);
+ }
s->channels = avctx->channels;
s->sample[0] = s->sample[1] = 0;
@@ -125,25 +129,23 @@ static av_cold int dpcm_decode_init(AVCodecContext *avctx)
case CODEC_ID_ROQ_DPCM:
/* initialize square table */
for (i = 0; i < 128; i++) {
- square = i * i;
- s->roq_square_array[i] = square;
+ int16_t square = i * i;
+ s->roq_square_array[i ] = square;
s->roq_square_array[i + 128] = -square;
}
break;
-
case CODEC_ID_SOL_DPCM:
switch(avctx->codec_tag){
case 1:
- s->sol_table=sol_table_old;
+ s->sol_table = sol_table_old;
s->sample[0] = s->sample[1] = 0x80;
break;
case 2:
- s->sol_table=sol_table_new;
+ s->sol_table = sol_table_new;
s->sample[0] = s->sample[1] = 0x80;
break;
case 3:
- s->sol_table=sol_table_16;
break;
default:
av_log(avctx, AV_LOG_ERROR, "Unknown SOL subcodec\n");
@@ -155,163 +157,175 @@ static av_cold int dpcm_decode_init(AVCodecContext *avctx)
break;
}
- avctx->sample_fmt = AV_SAMPLE_FMT_S16;
+ if (avctx->codec->id == CODEC_ID_SOL_DPCM && avctx->codec_tag != 3)
+ avctx->sample_fmt = AV_SAMPLE_FMT_U8;
+ else
+ avctx->sample_fmt = AV_SAMPLE_FMT_S16;
+
return 0;
}
-static int dpcm_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
+
+static int dpcm_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
+ const uint8_t *buf_end = buf + buf_size;
DPCMContext *s = avctx->priv_data;
- int in, out = 0;
+ int out = 0;
int predictor[2];
- int channel_number = 0;
- short *output_samples = data;
- int shift[2];
- unsigned char byte;
- short diff;
+ int ch = 0;
+ int stereo = s->channels - 1;
+ int16_t *output_samples = data;
if (!buf_size)
return 0;
- // almost every DPCM variant expands one byte of data into two
- if(*data_size/2 < buf_size)
- return -1;
+ /* calculate output size */
+ switch(avctx->codec->id) {
+ case CODEC_ID_ROQ_DPCM:
+ out = buf_size - 8;
+ break;
+ case CODEC_ID_INTERPLAY_DPCM:
+ out = buf_size - 6 - s->channels;
+ break;
+ case CODEC_ID_XAN_DPCM:
+ out = buf_size - 2 * s->channels;
+ break;
+ case CODEC_ID_SOL_DPCM:
+ if (avctx->codec_tag != 3)
+ out = buf_size * 2;
+ else
+ out = buf_size;
+ break;
+ }
+ out *= av_get_bytes_per_sample(avctx->sample_fmt);
+ if (out < 0) {
+ av_log(avctx, AV_LOG_ERROR, "packet is too small\n");
+ return AVERROR(EINVAL);
+ }
+ if (*data_size < out) {
+ av_log(avctx, AV_LOG_ERROR, "output buffer is too small\n");
+ return AVERROR(EINVAL);
+ }
switch(avctx->codec->id) {
case CODEC_ID_ROQ_DPCM:
- if (s->channels == 1)
- predictor[0] = AV_RL16(&buf[6]);
- else {
- predictor[0] = buf[7] << 8;
- predictor[1] = buf[6] << 8;
+ buf += 6;
+
+ if (stereo) {
+ predictor[1] = (int16_t)(bytestream_get_byte(&buf) << 8);
+ predictor[0] = (int16_t)(bytestream_get_byte(&buf) << 8);
+ } else {
+ predictor[0] = (int16_t)bytestream_get_le16(&buf);
}
- SE_16BIT(predictor[0]);
- SE_16BIT(predictor[1]);
/* decode the samples */
- for (in = 8, out = 0; in < buf_size; in++, out++) {
- predictor[channel_number] += s->roq_square_array[buf[in]];
- predictor[channel_number] = av_clip_int16(predictor[channel_number]);
- output_samples[out] = predictor[channel_number];
+ while (buf < buf_end) {
+ predictor[ch] += s->roq_square_array[*buf++];
+ predictor[ch] = av_clip_int16(predictor[ch]);
+ *output_samples++ = predictor[ch];
/* toggle channel */
- channel_number ^= s->channels - 1;
+ ch ^= stereo;
}
break;
case CODEC_ID_INTERPLAY_DPCM:
- in = 6; /* skip over the stream mask and stream length */
- predictor[0] = AV_RL16(&buf[in]);
- in += 2;
- SE_16BIT(predictor[0])
- output_samples[out++] = predictor[0];
- if (s->channels == 2) {
- predictor[1] = AV_RL16(&buf[in]);
- in += 2;
- SE_16BIT(predictor[1])
- output_samples[out++] = predictor[1];
+ buf += 6; /* skip over the stream mask and stream length */
+
+ for (ch = 0; ch < s->channels; ch++) {
+ predictor[ch] = (int16_t)bytestream_get_le16(&buf);
+ *output_samples++ = predictor[ch];
}
- while (in < buf_size) {
- predictor[channel_number] += interplay_delta_table[buf[in++]];
- predictor[channel_number] = av_clip_int16(predictor[channel_number]);
- output_samples[out++] = predictor[channel_number];
+ ch = 0;
+ while (buf < buf_end) {
+ predictor[ch] += interplay_delta_table[*buf++];
+ predictor[ch] = av_clip_int16(predictor[ch]);
+ *output_samples++ = predictor[ch];
/* toggle channel */
- channel_number ^= s->channels - 1;
+ ch ^= stereo;
}
-
break;
case CODEC_ID_XAN_DPCM:
- in = 0;
- shift[0] = shift[1] = 4;
- predictor[0] = AV_RL16(&buf[in]);
- in += 2;
- SE_16BIT(predictor[0]);
- if (s->channels == 2) {
- predictor[1] = AV_RL16(&buf[in]);
- in += 2;
- SE_16BIT(predictor[1]);
- }
-
- while (in < buf_size) {
- byte = buf[in++];
- diff = (byte & 0xFC) << 8;
- if ((byte & 0x03) == 3)
- shift[channel_number]++;
+ {
+ int shift[2] = { 4, 4 };
+
+ for (ch = 0; ch < s->channels; ch++)
+ predictor[ch] = (int16_t)bytestream_get_le16(&buf);
+
+ ch = 0;
+ while (buf < buf_end) {
+ uint8_t n = *buf++;
+ int16_t diff = (n & 0xFC) << 8;
+ if ((n & 0x03) == 3)
+ shift[ch]++;
else
- shift[channel_number] -= (2 * (byte & 3));
+ shift[ch] -= (2 * (n & 3));
/* saturate the shifter to a lower limit of 0 */
- if (shift[channel_number] < 0)
- shift[channel_number] = 0;
+ if (shift[ch] < 0)
+ shift[ch] = 0;
- diff >>= shift[channel_number];
- predictor[channel_number] += diff;
+ diff >>= shift[ch];
+ predictor[ch] += diff;
- predictor[channel_number] = av_clip_int16(predictor[channel_number]);
- output_samples[out++] = predictor[channel_number];
+ predictor[ch] = av_clip_int16(predictor[ch]);
+ *output_samples++ = predictor[ch];
/* toggle channel */
- channel_number ^= s->channels - 1;
+ ch ^= stereo;
}
break;
+ }
case CODEC_ID_SOL_DPCM:
- in = 0;
if (avctx->codec_tag != 3) {
- if(*data_size/4 < buf_size)
- return -1;
- while (in < buf_size) {
- int n1, n2;
- n1 = (buf[in] >> 4) & 0xF;
- n2 = buf[in++] & 0xF;
- s->sample[0] += s->sol_table[n1];
- if (s->sample[0] < 0) s->sample[0] = 0;
- if (s->sample[0] > 255) s->sample[0] = 255;
- output_samples[out++] = (s->sample[0] - 128) << 8;
- s->sample[s->channels - 1] += s->sol_table[n2];
- if (s->sample[s->channels - 1] < 0) s->sample[s->channels - 1] = 0;
- if (s->sample[s->channels - 1] > 255) s->sample[s->channels - 1] = 255;
- output_samples[out++] = (s->sample[s->channels - 1] - 128) << 8;
+ uint8_t *output_samples_u8 = data;
+ while (buf < buf_end) {
+ uint8_t n = *buf++;
+
+ s->sample[0] += s->sol_table[n >> 4];
+ s->sample[0] = av_clip_uint8(s->sample[0]);
+ *output_samples_u8++ = s->sample[0];
+
+ s->sample[stereo] += s->sol_table[n & 0x0F];
+ s->sample[stereo] = av_clip_uint8(s->sample[stereo]);
+ *output_samples_u8++ = s->sample[stereo];
}
} else {
- while (in < buf_size) {
- int n;
- n = buf[in++];
- if (n & 0x80) s->sample[channel_number] -= s->sol_table[n & 0x7F];
- else s->sample[channel_number] += s->sol_table[n & 0x7F];
- s->sample[channel_number] = av_clip_int16(s->sample[channel_number]);
- output_samples[out++] = s->sample[channel_number];
+ while (buf < buf_end) {
+ uint8_t n = *buf++;
+ if (n & 0x80) s->sample[ch] -= sol_table_16[n & 0x7F];
+ else s->sample[ch] += sol_table_16[n & 0x7F];
+ s->sample[ch] = av_clip_int16(s->sample[ch]);
+ *output_samples++ = s->sample[ch];
/* toggle channel */
- channel_number ^= s->channels - 1;
+ ch ^= stereo;
}
}
break;
}
- *data_size = out * sizeof(short);
+ *data_size = out;
return buf_size;
}
-#define DPCM_DECODER(id, name, long_name_) \
-AVCodec ff_ ## name ## _decoder = { \
- #name, \
- AVMEDIA_TYPE_AUDIO, \
- id, \
- sizeof(DPCMContext), \
- dpcm_decode_init, \
- NULL, \
- NULL, \
- dpcm_decode_frame, \
- .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
+#define DPCM_DECODER(id_, name_, long_name_) \
+AVCodec ff_ ## name_ ## _decoder = { \
+ .name = #name_, \
+ .type = AVMEDIA_TYPE_AUDIO, \
+ .id = id_, \
+ .priv_data_size = sizeof(DPCMContext), \
+ .init = dpcm_decode_init, \
+ .decode = dpcm_decode_frame, \
+ .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
}
DPCM_DECODER(CODEC_ID_INTERPLAY_DPCM, interplay_dpcm, "DPCM Interplay");
-DPCM_DECODER(CODEC_ID_ROQ_DPCM, roq_dpcm, "DPCM id RoQ");
-DPCM_DECODER(CODEC_ID_SOL_DPCM, sol_dpcm, "DPCM Sol");
-DPCM_DECODER(CODEC_ID_XAN_DPCM, xan_dpcm, "DPCM Xan");
+DPCM_DECODER(CODEC_ID_ROQ_DPCM, roq_dpcm, "DPCM id RoQ");
+DPCM_DECODER(CODEC_ID_SOL_DPCM, sol_dpcm, "DPCM Sol");
+DPCM_DECODER(CODEC_ID_XAN_DPCM, xan_dpcm, "DPCM Xan");
diff --git a/libavcodec/dpx.c b/libavcodec/dpx.c
index 0722dd07ef..e8dae300e5 100644
--- a/libavcodec/dpx.c
+++ b/libavcodec/dpx.c
@@ -2,20 +2,20 @@
* DPX (.dpx) image decoder
* Copyright (c) 2009 Jimmy Christensen
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -234,15 +234,12 @@ static av_cold int decode_end(AVCodecContext *avctx)
}
AVCodec ff_dpx_decoder = {
- "dpx",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_DPX,
- sizeof(DPXContext),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- 0,
- NULL,
+ .name = "dpx",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_DPX,
+ .priv_data_size = sizeof(DPXContext),
+ .init = decode_init,
+ .close = decode_end,
+ .decode = decode_frame,
.long_name = NULL_IF_CONFIG_SMALL("DPX image"),
};
diff --git a/libavcodec/dpxenc.c b/libavcodec/dpxenc.c
index 7ae929238d..f69cfdc94e 100644
--- a/libavcodec/dpxenc.c
+++ b/libavcodec/dpxenc.c
@@ -2,20 +2,20 @@
* DPX (.dpx) image encoder
* Copyright (c) 2011 Peter Ross <pross@xvid.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -35,7 +35,7 @@ static av_cold int encode_init(AVCodecContext *avctx)
DPXContext *s = avctx->priv_data;
avctx->coded_frame = &s->picture;
- avctx->coded_frame->pict_type = FF_I_TYPE;
+ avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
avctx->coded_frame->key_frame = 1;
s->big_endian = 1;
@@ -73,8 +73,7 @@ do { \
else AV_WL32(p, value); \
} while(0)
-static void encode_rgb48_10bit(AVCodecContext *avctx, const AVPicture *pic,
- uint8_t *dst)
+static void encode_rgb48_10bit(AVCodecContext *avctx, const AVPicture *pic, uint8_t *dst)
{
DPXContext *s = avctx->priv_data;
const uint8_t *src = pic->data[0];
@@ -99,8 +98,7 @@ static void encode_rgb48_10bit(AVCodecContext *avctx, const AVPicture *pic,
}
}
-static int encode_frame(AVCodecContext *avctx, unsigned char *buf,
- int buf_size, void *data)
+static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data)
{
DPXContext *s = avctx->priv_data;
int size;
@@ -135,7 +133,7 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf,
write32(buf + 1628, avctx->sample_aspect_ratio.num);
write32(buf + 1632, avctx->sample_aspect_ratio.den);
- switch (s->bits_per_component) {
+ switch(s->bits_per_component) {
case 8:
case 16:
size = avpicture_layout(data, avctx->pix_fmt,
diff --git a/libavcodec/dsicinav.c b/libavcodec/dsicinav.c
index 643aed946b..05d9e4cc14 100644
--- a/libavcodec/dsicinav.c
+++ b/libavcodec/dsicinav.c
@@ -2,20 +2,20 @@
* Delphine Software International CIN Audio/Video Decoders
* Copyright (c) 2006 Gregory Montoir (cyx@users.sourceforge.net)
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -94,6 +94,7 @@ static av_cold int cinvideo_decode_init(AVCodecContext *avctx)
cin->avctx = avctx;
avctx->pix_fmt = PIX_FMT_PAL8;
+ avcodec_get_frame_defaults(&cin->frame);
cin->frame.data[0] = NULL;
cin->bitmap_size = avctx->width * avctx->height;
@@ -216,7 +217,11 @@ static int cinvideo_decode_frame(AVCodecContext *avctx,
bitmap_frame_size = buf_size - 4;
/* handle palette */
+ if (bitmap_frame_size < palette_colors_count * (3 + (palette_type != 0)))
+ return AVERROR_INVALIDDATA;
if (palette_type == 0) {
+ if (palette_colors_count > 256)
+ return AVERROR_INVALIDDATA;
for (i = 0; i < palette_colors_count; ++i) {
cin->palette[i] = bytestream_get_le24(&buf);
bitmap_frame_size -= 3;
@@ -344,26 +349,23 @@ static int cinaudio_decode_frame(AVCodecContext *avctx,
AVCodec ff_dsicinvideo_decoder = {
- "dsicinvideo",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_DSICINVIDEO,
- sizeof(CinVideoContext),
- cinvideo_decode_init,
- NULL,
- cinvideo_decode_end,
- cinvideo_decode_frame,
- CODEC_CAP_DR1,
+ .name = "dsicinvideo",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_DSICINVIDEO,
+ .priv_data_size = sizeof(CinVideoContext),
+ .init = cinvideo_decode_init,
+ .close = cinvideo_decode_end,
+ .decode = cinvideo_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Delphine Software International CIN video"),
};
AVCodec ff_dsicinaudio_decoder = {
- "dsicinaudio",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_DSICINAUDIO,
- sizeof(CinAudioContext),
- cinaudio_decode_init,
- NULL,
- NULL,
- cinaudio_decode_frame,
+ .name = "dsicinaudio",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_DSICINAUDIO,
+ .priv_data_size = sizeof(CinAudioContext),
+ .init = cinaudio_decode_init,
+ .decode = cinaudio_decode_frame,
.long_name = NULL_IF_CONFIG_SMALL("Delphine Software International CIN audio"),
};
diff --git a/libavcodec/dsputil.c b/libavcodec/dsputil.c
index 4f17b435d1..c451c97155 100644
--- a/libavcodec/dsputil.c
+++ b/libavcodec/dsputil.c
@@ -5,20 +5,20 @@
*
* gmc & q-pel & 32/64 bit based MC by Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -38,7 +38,6 @@
#include "config.h"
#include "ac3dec.h"
#include "vorbis.h"
-#include "png.h"
uint8_t ff_cropTbl[256 + 2 * MAX_NEG_CROP] = {0, };
uint32_t ff_squareTbl[512] = {0, };
@@ -145,6 +144,41 @@ void ff_init_scantable(uint8_t *permutation, ScanTable *st, const uint8_t *src_s
}
}
+void ff_init_scantable_permutation(uint8_t *idct_permutation,
+ int idct_permutation_type)
+{
+ int i;
+
+ switch(idct_permutation_type){
+ case FF_NO_IDCT_PERM:
+ for(i=0; i<64; i++)
+ idct_permutation[i]= i;
+ break;
+ case FF_LIBMPEG2_IDCT_PERM:
+ for(i=0; i<64; i++)
+ idct_permutation[i]= (i & 0x38) | ((i & 6) >> 1) | ((i & 1) << 2);
+ break;
+ case FF_SIMPLE_IDCT_PERM:
+ for(i=0; i<64; i++)
+ idct_permutation[i]= simple_mmx_permutation[i];
+ break;
+ case FF_TRANSPOSE_IDCT_PERM:
+ for(i=0; i<64; i++)
+ idct_permutation[i]= ((i&7)<<3) | (i>>3);
+ break;
+ case FF_PARTTRANS_IDCT_PERM:
+ for(i=0; i<64; i++)
+ idct_permutation[i]= (i&0x24) | ((i&3)<<3) | ((i>>3)&3);
+ break;
+ case FF_SSE2_IDCT_PERM:
+ for(i=0; i<64; i++)
+ idct_permutation[i]= (i&0x38) | idct_sse2_row_perm[i&7];
+ break;
+ default:
+ av_log(NULL, AV_LOG_ERROR, "Internal error, IDCT permutation not set\n");
+ }
+}
+
static int pix_sum_c(uint8_t * pix, int line_size)
{
int s, i, j;
@@ -185,7 +219,7 @@ static int pix_norm1_c(uint8_t * pix, int line_size)
s += sq[pix[6]];
s += sq[pix[7]];
#else
-#if LONG_MAX > 2147483647
+#if HAVE_FAST_64BIT
register uint64_t x=*(uint64_t*)pix;
s += sq[x&0xff];
s += sq[(x>>8)&0xff];
@@ -307,25 +341,6 @@ static int sse16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
return s;
}
-static void get_pixels_c(DCTELEM *restrict block, const uint8_t *pixels, int line_size)
-{
- int i;
-
- /* read the pixels */
- for(i=0;i<8;i++) {
- block[0] = pixels[0];
- block[1] = pixels[1];
- block[2] = pixels[2];
- block[3] = pixels[3];
- block[4] = pixels[4];
- block[5] = pixels[5];
- block[6] = pixels[6];
- block[7] = pixels[7];
- pixels += line_size;
- block += 8;
- }
-}
-
static void diff_pixels_c(DCTELEM *restrict block, const uint8_t *s1,
const uint8_t *s2, int stride){
int i;
@@ -424,27 +439,6 @@ void ff_put_signed_pixels_clamped_c(const DCTELEM *block,
}
}
-static void put_pixels_nonclamped_c(const DCTELEM *block, uint8_t *restrict pixels,
- int line_size)
-{
- int i;
-
- /* read the pixels */
- for(i=0;i<8;i++) {
- pixels[0] = block[0];
- pixels[1] = block[1];
- pixels[2] = block[2];
- pixels[3] = block[3];
- pixels[4] = block[4];
- pixels[5] = block[5];
- pixels[6] = block[6];
- pixels[7] = block[7];
-
- pixels += line_size;
- block += 8;
- }
-}
-
void ff_add_pixels_clamped_c(const DCTELEM *block, uint8_t *restrict pixels,
int line_size)
{
@@ -526,22 +520,6 @@ static void fill_block8_c(uint8_t *block, uint8_t value, int line_size, int h)
}
}
-static void scale_block_c(const uint8_t src[64]/*align 8*/, uint8_t *dst/*align 8*/, int linesize)
-{
- int i, j;
- uint16_t *dst1 = (uint16_t *) dst;
- uint16_t *dst2 = (uint16_t *)(dst + linesize);
-
- for (j = 0; j < 8; j++) {
- for (i = 0; i < 8; i++) {
- dst1[i] = dst2[i] = src[i] * 0x0101;
- }
- src += 8;
- dst1 += linesize;
- dst2 += linesize;
- }
-}
-
#define avg2(a,b) ((a+b+1)>>1)
#define avg4(a,b,c,d) ((a+b+c+d+2)>>2)
@@ -819,27 +797,6 @@ static inline void avg_tpel_pixels_mc22_c(uint8_t *dst, const uint8_t *src, int
dst += stride;
}
}
-#if 0
-#define TPEL_WIDTH(width)\
-static void put_tpel_pixels ## width ## _mc00_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
- void put_tpel_pixels_mc00_c(dst, src, stride, width, height);}\
-static void put_tpel_pixels ## width ## _mc10_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
- void put_tpel_pixels_mc10_c(dst, src, stride, width, height);}\
-static void put_tpel_pixels ## width ## _mc20_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
- void put_tpel_pixels_mc20_c(dst, src, stride, width, height);}\
-static void put_tpel_pixels ## width ## _mc01_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
- void put_tpel_pixels_mc01_c(dst, src, stride, width, height);}\
-static void put_tpel_pixels ## width ## _mc11_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
- void put_tpel_pixels_mc11_c(dst, src, stride, width, height);}\
-static void put_tpel_pixels ## width ## _mc21_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
- void put_tpel_pixels_mc21_c(dst, src, stride, width, height);}\
-static void put_tpel_pixels ## width ## _mc02_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
- void put_tpel_pixels_mc02_c(dst, src, stride, width, height);}\
-static void put_tpel_pixels ## width ## _mc12_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
- void put_tpel_pixels_mc12_c(dst, src, stride, width, height);}\
-static void put_tpel_pixels ## width ## _mc22_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
- void put_tpel_pixels_mc22_c(dst, src, stride, width, height);}
-#endif
#define QPEL_MC(r, OPNAME, RND, OP) \
static void OPNAME ## mpeg4_qpel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
@@ -1357,16 +1314,16 @@ static void wmv2_mspel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int
}
#if CONFIG_RV40_DECODER
-static void put_rv40_qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride){
+void ff_put_rv40_qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride){
put_pixels16_xy2_8_c(dst, src, stride, 16);
}
-static void avg_rv40_qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride){
+void ff_avg_rv40_qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride){
avg_pixels16_xy2_8_c(dst, src, stride, 16);
}
-static void put_rv40_qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride){
+void ff_put_rv40_qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride){
put_pixels8_xy2_8_c(dst, src, stride, 8);
}
-static void avg_rv40_qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride){
+void ff_avg_rv40_qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride){
avg_pixels8_xy2_8_c(dst, src, stride, 8);
}
#endif /* CONFIG_RV40_DECODER */
@@ -1924,17 +1881,6 @@ static void add_bytes_c(uint8_t *dst, uint8_t *src, int w){
dst[i+0] += src[i+0];
}
-static void add_bytes_l2_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){
- long i;
- for(i=0; i<=w-sizeof(long); i+=sizeof(long)){
- long a = *(long*)(src1+i);
- long b = *(long*)(src2+i);
- *(long*)(dst+i) = ((a&pb_7f) + (b&pb_7f)) ^ ((a^b)&pb_80);
- }
- for(; i<w; i++)
- dst[i] = src1[i]+src2[i];
-}
-
static void diff_bytes_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){
long i;
#if !HAVE_FAST_UNALIGNED
@@ -2258,7 +2204,7 @@ static int quant_psnr8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *s
s->block_last_index[0/*FIXME*/]= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
s->dct_unquantize_inter(s, temp, 0, s->qscale);
- ff_simple_idct(temp); //FIXME
+ ff_simple_idct_8(temp); //FIXME
for(i=0; i<64; i++)
sum+= (temp[i]-bak[i])*(temp[i]-bak[i]);
@@ -2532,48 +2478,12 @@ static void vector_fmul_scalar_c(float *dst, const float *src, float mul,
dst[i] = src[i] * mul;
}
-static void vector_fmul_sv_scalar_2_c(float *dst, const float *src,
- const float **sv, float mul, int len)
-{
- int i;
- for (i = 0; i < len; i += 2, sv++) {
- dst[i ] = src[i ] * sv[0][0] * mul;
- dst[i+1] = src[i+1] * sv[0][1] * mul;
- }
-}
-
-static void vector_fmul_sv_scalar_4_c(float *dst, const float *src,
- const float **sv, float mul, int len)
-{
- int i;
- for (i = 0; i < len; i += 4, sv++) {
- dst[i ] = src[i ] * sv[0][0] * mul;
- dst[i+1] = src[i+1] * sv[0][1] * mul;
- dst[i+2] = src[i+2] * sv[0][2] * mul;
- dst[i+3] = src[i+3] * sv[0][3] * mul;
- }
-}
-
-static void sv_fmul_scalar_2_c(float *dst, const float **sv, float mul,
- int len)
-{
- int i;
- for (i = 0; i < len; i += 2, sv++) {
- dst[i ] = sv[0][0] * mul;
- dst[i+1] = sv[0][1] * mul;
- }
-}
-
-static void sv_fmul_scalar_4_c(float *dst, const float **sv, float mul,
- int len)
+static void vector_fmac_scalar_c(float *dst, const float *src, float mul,
+ int len)
{
int i;
- for (i = 0; i < len; i += 4, sv++) {
- dst[i ] = sv[0][0] * mul;
- dst[i+1] = sv[0][1] * mul;
- dst[i+2] = sv[0][2] * mul;
- dst[i+3] = sv[0][3] * mul;
- }
+ for (i = 0; i < len; i++)
+ dst[i] += src[i] * mul;
}
static void butterflies_float_c(float *restrict v1, float *restrict v2,
@@ -2844,16 +2754,16 @@ av_cold void dsputil_static_init(void)
int ff_check_alignment(void){
static int did_fail=0;
- DECLARE_ALIGNED(16, int, aligned);
+ LOCAL_ALIGNED_16(int, aligned, [4]);
- if((intptr_t)&aligned & 15){
+ if((intptr_t)aligned & 15){
if(!did_fail){
#if HAVE_MMX || HAVE_ALTIVEC
av_log(NULL, AV_LOG_ERROR,
"Compiler did not align stack variables. Libavcodec has been miscompiled\n"
"and may be very slow or crash. This is not a bug in libavcodec,\n"
"but in the compiler. You may try recompiling using gcc >= 4.2.\n"
- "Do not report crashes to Libav developers.\n");
+ "Do not report crashes to FFmpeg developers.\n");
#endif
did_fail=1;
}
@@ -2869,44 +2779,28 @@ av_cold void dsputil_init(DSPContext* c, AVCodecContext *avctx)
ff_check_alignment();
#if CONFIG_ENCODERS
- if(avctx->dct_algo==FF_DCT_FASTINT) {
- c->fdct = fdct_ifast;
- c->fdct248 = fdct_ifast248;
- }
- else if(avctx->dct_algo==FF_DCT_FAAN) {
- c->fdct = ff_faandct;
- c->fdct248 = ff_faandct248;
- }
- else {
- c->fdct = ff_jpeg_fdct_islow; //slow/accurate/default
- c->fdct248 = ff_fdct248_islow;
+ if (avctx->bits_per_raw_sample == 10) {
+ c->fdct = ff_jpeg_fdct_islow_10;
+ c->fdct248 = ff_fdct248_islow_10;
+ } else {
+ if(avctx->dct_algo==FF_DCT_FASTINT) {
+ c->fdct = fdct_ifast;
+ c->fdct248 = fdct_ifast248;
+ }
+ else if(avctx->dct_algo==FF_DCT_FAAN) {
+ c->fdct = ff_faandct;
+ c->fdct248 = ff_faandct248;
+ }
+ else {
+ c->fdct = ff_jpeg_fdct_islow_8; //slow/accurate/default
+ c->fdct248 = ff_fdct248_islow_8;
+ }
}
#endif //CONFIG_ENCODERS
if(avctx->lowres==1){
- if(avctx->idct_algo==FF_IDCT_INT || avctx->idct_algo==FF_IDCT_AUTO || !CONFIG_H264_DECODER){
- c->idct_put= ff_jref_idct4_put;
- c->idct_add= ff_jref_idct4_add;
- }else{
- if (avctx->codec_id != CODEC_ID_H264) {
- c->idct_put= ff_h264_lowres_idct_put_8_c;
- c->idct_add= ff_h264_lowres_idct_add_8_c;
- } else {
- switch (avctx->bits_per_raw_sample) {
- case 9:
- c->idct_put= ff_h264_lowres_idct_put_9_c;
- c->idct_add= ff_h264_lowres_idct_add_9_c;
- break;
- case 10:
- c->idct_put= ff_h264_lowres_idct_put_10_c;
- c->idct_add= ff_h264_lowres_idct_add_10_c;
- break;
- default:
- c->idct_put= ff_h264_lowres_idct_put_8_c;
- c->idct_add= ff_h264_lowres_idct_add_8_c;
- }
- }
- }
+ c->idct_put= ff_jref_idct4_put;
+ c->idct_add= ff_jref_idct4_add;
c->idct = j_rev_dct4;
c->idct_permutation_type= FF_NO_IDCT_PERM;
}else if(avctx->lowres==2){
@@ -2920,6 +2814,12 @@ av_cold void dsputil_init(DSPContext* c, AVCodecContext *avctx)
c->idct = j_rev_dct1;
c->idct_permutation_type= FF_NO_IDCT_PERM;
}else{
+ if (avctx->bits_per_raw_sample == 10) {
+ c->idct_put = ff_simple_idct_put_10;
+ c->idct_add = ff_simple_idct_add_10;
+ c->idct = ff_simple_idct_10;
+ c->idct_permutation_type = FF_NO_IDCT_PERM;
+ } else {
if(avctx->idct_algo==FF_IDCT_INT){
c->idct_put= ff_jref_idct_put;
c->idct_add= ff_jref_idct_add;
@@ -2944,24 +2844,18 @@ av_cold void dsputil_init(DSPContext* c, AVCodecContext *avctx)
}else if(CONFIG_EATGQ_DECODER && avctx->idct_algo==FF_IDCT_EA) {
c->idct_put= ff_ea_idct_put_c;
c->idct_permutation_type= FF_NO_IDCT_PERM;
- }else if(CONFIG_BINK_DECODER && avctx->idct_algo==FF_IDCT_BINK) {
- c->idct = ff_bink_idct_c;
- c->idct_add = ff_bink_idct_add_c;
- c->idct_put = ff_bink_idct_put_c;
- c->idct_permutation_type = FF_NO_IDCT_PERM;
}else{ //accurate/default
- c->idct_put= ff_simple_idct_put;
- c->idct_add= ff_simple_idct_add;
- c->idct = ff_simple_idct;
+ c->idct_put = ff_simple_idct_put_8;
+ c->idct_add = ff_simple_idct_add_8;
+ c->idct = ff_simple_idct_8;
c->idct_permutation_type= FF_NO_IDCT_PERM;
}
+ }
}
- c->get_pixels = get_pixels_c;
c->diff_pixels = diff_pixels_c;
c->put_pixels_clamped = ff_put_pixels_clamped_c;
c->put_signed_pixels_clamped = ff_put_signed_pixels_clamped_c;
- c->put_pixels_nonclamped = put_pixels_nonclamped_c;
c->add_pixels_clamped = ff_add_pixels_clamped_c;
c->sum_abs_dctelem = sum_abs_dctelem_c;
c->gmc1 = gmc1_c;
@@ -2971,7 +2865,6 @@ av_cold void dsputil_init(DSPContext* c, AVCodecContext *avctx)
c->fill_block_tab[0] = fill_block16_c;
c->fill_block_tab[1] = fill_block8_c;
- c->scale_block = scale_block_c;
/* TODO [0] 16 [1] 8 */
c->pix_abs[0][0] = pix_abs16_c;
@@ -3041,16 +2934,6 @@ av_cold void dsputil_init(DSPContext* c, AVCodecContext *avctx)
#if CONFIG_WMV2_DECODER || CONFIG_VC1_DECODER
ff_intrax8dsp_init(c,avctx);
#endif
-#if CONFIG_RV30_DECODER
- ff_rv30dsp_init(c,avctx);
-#endif
-#if CONFIG_RV40_DECODER
- ff_rv40dsp_init(c,avctx);
- c->put_rv40_qpel_pixels_tab[0][15] = put_rv40_qpel16_mc33_c;
- c->avg_rv40_qpel_pixels_tab[0][15] = avg_rv40_qpel16_mc33_c;
- c->put_rv40_qpel_pixels_tab[1][15] = put_rv40_qpel8_mc33_c;
- c->avg_rv40_qpel_pixels_tab[1][15] = avg_rv40_qpel8_mc33_c;
-#endif
c->put_mspel_pixels_tab[0]= ff_put_pixels8x8_c;
c->put_mspel_pixels_tab[1]= put_mspel8_mc10_c;
@@ -3096,7 +2979,6 @@ av_cold void dsputil_init(DSPContext* c, AVCodecContext *avctx)
c->ssd_int8_vs_int16 = ssd_int8_vs_int16_c;
c->add_bytes= add_bytes_c;
- c->add_bytes_l2= add_bytes_l2_c;
c->diff_bytes= diff_bytes_c;
c->add_hfyu_median_prediction= add_hfyu_median_prediction_c;
c->sub_hfyu_median_prediction= sub_hfyu_median_prediction_c;
@@ -3104,9 +2986,6 @@ av_cold void dsputil_init(DSPContext* c, AVCodecContext *avctx)
c->add_hfyu_left_prediction_bgr32 = add_hfyu_left_prediction_bgr32_c;
c->bswap_buf= bswap_buf;
c->bswap16_buf = bswap16_buf;
-#if CONFIG_PNG_DECODER
- c->add_png_paeth_prediction= ff_add_png_paeth_prediction;
-#endif
if (CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
c->h263_h_loop_filter= h263_h_loop_filter_c;
@@ -3142,12 +3021,7 @@ av_cold void dsputil_init(DSPContext* c, AVCodecContext *avctx)
c->scalarproduct_float = scalarproduct_float_c;
c->butterflies_float = butterflies_float_c;
c->vector_fmul_scalar = vector_fmul_scalar_c;
-
- c->vector_fmul_sv_scalar[0] = vector_fmul_sv_scalar_2_c;
- c->vector_fmul_sv_scalar[1] = vector_fmul_sv_scalar_4_c;
-
- c->sv_fmul_scalar[0] = sv_fmul_scalar_2_c;
- c->sv_fmul_scalar[1] = sv_fmul_scalar_4_c;
+ c->vector_fmac_scalar = vector_fmac_scalar_c;
c->shrink[0]= av_image_copy_plane;
c->shrink[1]= ff_shrink22;
@@ -3189,13 +3063,14 @@ av_cold void dsputil_init(DSPContext* c, AVCodecContext *avctx)
c->PFX ## _pixels_tab[IDX][15] = FUNCC(PFX ## NUM ## _mc33, depth)
-#define BIT_DEPTH_FUNCS(depth)\
+#define BIT_DEPTH_FUNCS(depth, dct)\
+ c->get_pixels = FUNCC(get_pixels ## dct , depth);\
c->draw_edges = FUNCC(draw_edges , depth);\
c->emulated_edge_mc = FUNC (ff_emulated_edge_mc , depth);\
- c->clear_block = FUNCC(clear_block , depth);\
- c->clear_blocks = FUNCC(clear_blocks , depth);\
- c->add_pixels8 = FUNCC(add_pixels8 , depth);\
- c->add_pixels4 = FUNCC(add_pixels4 , depth);\
+ c->clear_block = FUNCC(clear_block ## dct , depth);\
+ c->clear_blocks = FUNCC(clear_blocks ## dct , depth);\
+ c->add_pixels8 = FUNCC(add_pixels8 ## dct , depth);\
+ c->add_pixels4 = FUNCC(add_pixels4 ## dct , depth);\
c->put_no_rnd_pixels_l2[0] = FUNCC(put_no_rnd_pixels16_l2, depth);\
c->put_no_rnd_pixels_l2[1] = FUNCC(put_no_rnd_pixels8_l2 , depth);\
\
@@ -3227,21 +3102,26 @@ av_cold void dsputil_init(DSPContext* c, AVCodecContext *avctx)
dspfunc2(avg_h264_qpel, 1, 8, depth);\
dspfunc2(avg_h264_qpel, 2, 4, depth);
- if (avctx->codec_id != CODEC_ID_H264 || avctx->bits_per_raw_sample == 8) {
- BIT_DEPTH_FUNCS(8)
- } else {
- switch (avctx->bits_per_raw_sample) {
- case 9:
- BIT_DEPTH_FUNCS(9)
- break;
- case 10:
- BIT_DEPTH_FUNCS(10)
- break;
- default:
- av_log(avctx, AV_LOG_DEBUG, "Unsupported bit depth: %d\n", avctx->bits_per_raw_sample);
- BIT_DEPTH_FUNCS(8)
- break;
+ switch (avctx->bits_per_raw_sample) {
+ case 9:
+ if (c->dct_bits == 32) {
+ BIT_DEPTH_FUNCS(9, _32);
+ } else {
+ BIT_DEPTH_FUNCS(9, _16);
}
+ break;
+ case 10:
+ if (c->dct_bits == 32) {
+ BIT_DEPTH_FUNCS(10, _32);
+ } else {
+ BIT_DEPTH_FUNCS(10, _16);
+ }
+ break;
+ default:
+ av_log(avctx, AV_LOG_DEBUG, "Unsupported bit depth: %d\n", avctx->bits_per_raw_sample);
+ case 8:
+ BIT_DEPTH_FUNCS(8, _16);
+ break;
}
@@ -3262,43 +3142,6 @@ av_cold void dsputil_init(DSPContext* c, AVCodecContext *avctx)
c->avg_2tap_qpel_pixels_tab[0][i]= c->avg_h264_qpel_pixels_tab[0][i];
}
- c->put_rv30_tpel_pixels_tab[0][0] = c->put_h264_qpel_pixels_tab[0][0];
- c->put_rv30_tpel_pixels_tab[1][0] = c->put_h264_qpel_pixels_tab[1][0];
- c->avg_rv30_tpel_pixels_tab[0][0] = c->avg_h264_qpel_pixels_tab[0][0];
- c->avg_rv30_tpel_pixels_tab[1][0] = c->avg_h264_qpel_pixels_tab[1][0];
-
- c->put_rv40_qpel_pixels_tab[0][0] = c->put_h264_qpel_pixels_tab[0][0];
- c->put_rv40_qpel_pixels_tab[1][0] = c->put_h264_qpel_pixels_tab[1][0];
- c->avg_rv40_qpel_pixels_tab[0][0] = c->avg_h264_qpel_pixels_tab[0][0];
- c->avg_rv40_qpel_pixels_tab[1][0] = c->avg_h264_qpel_pixels_tab[1][0];
-
- switch(c->idct_permutation_type){
- case FF_NO_IDCT_PERM:
- for(i=0; i<64; i++)
- c->idct_permutation[i]= i;
- break;
- case FF_LIBMPEG2_IDCT_PERM:
- for(i=0; i<64; i++)
- c->idct_permutation[i]= (i & 0x38) | ((i & 6) >> 1) | ((i & 1) << 2);
- break;
- case FF_SIMPLE_IDCT_PERM:
- for(i=0; i<64; i++)
- c->idct_permutation[i]= simple_mmx_permutation[i];
- break;
- case FF_TRANSPOSE_IDCT_PERM:
- for(i=0; i<64; i++)
- c->idct_permutation[i]= ((i&7)<<3) | (i>>3);
- break;
- case FF_PARTTRANS_IDCT_PERM:
- for(i=0; i<64; i++)
- c->idct_permutation[i]= (i&0x24) | ((i&3)<<3) | ((i>>3)&3);
- break;
- case FF_SSE2_IDCT_PERM:
- for(i=0; i<64; i++)
- c->idct_permutation[i]= (i&0x38) | idct_sse2_row_perm[i&7];
- break;
- default:
- av_log(avctx, AV_LOG_ERROR, "Internal error, IDCT permutation not set\n");
- }
+ ff_init_scantable_permutation(c->idct_permutation,
+ c->idct_permutation_type);
}
-
diff --git a/libavcodec/dsputil.h b/libavcodec/dsputil.h
index ef2956eecb..22c51a0962 100644
--- a/libavcodec/dsputil.h
+++ b/libavcodec/dsputil.h
@@ -3,20 +3,20 @@
* Copyright (c) 2000, 2001, 2002 Fabrice Bellard
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -40,8 +40,10 @@ typedef short DCTELEM;
void fdct_ifast (DCTELEM *data);
void fdct_ifast248 (DCTELEM *data);
-void ff_jpeg_fdct_islow (DCTELEM *data);
-void ff_fdct248_islow (DCTELEM *data);
+void ff_jpeg_fdct_islow_8(DCTELEM *data);
+void ff_jpeg_fdct_islow_10(DCTELEM *data);
+void ff_fdct248_islow_8(DCTELEM *data);
+void ff_fdct248_islow_10(DCTELEM *data);
void j_rev_dct (DCTELEM *data);
void j_rev_dct4 (DCTELEM *data);
@@ -58,13 +60,13 @@ void ff_h264_idct8_add_ ## depth ## _c(uint8_t *dst, DCTELEM *block, int stride)
void ff_h264_idct_add_ ## depth ## _c(uint8_t *dst, DCTELEM *block, int stride);\
void ff_h264_idct8_dc_add_ ## depth ## _c(uint8_t *dst, DCTELEM *block, int stride);\
void ff_h264_idct_dc_add_ ## depth ## _c(uint8_t *dst, DCTELEM *block, int stride);\
-void ff_h264_lowres_idct_add_ ## depth ## _c(uint8_t *dst, int stride, DCTELEM *block);\
-void ff_h264_lowres_idct_put_ ## depth ## _c(uint8_t *dst, int stride, DCTELEM *block);\
void ff_h264_idct_add16_ ## depth ## _c(uint8_t *dst, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]);\
void ff_h264_idct_add16intra_ ## depth ## _c(uint8_t *dst, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]);\
void ff_h264_idct8_add4_ ## depth ## _c(uint8_t *dst, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]);\
+void ff_h264_idct_add8_422_ ## depth ## _c(uint8_t **dest, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]);\
void ff_h264_idct_add8_ ## depth ## _c(uint8_t **dest, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]);\
void ff_h264_luma_dc_dequant_idct_ ## depth ## _c(DCTELEM *output, DCTELEM *input, int qmul);\
+void ff_h264_chroma422_dc_dequant_idct_ ## depth ## _c(DCTELEM *block, int qmul);\
void ff_h264_chroma_dc_dequant_idct_ ## depth ## _c(DCTELEM *block, int qmul);
H264_IDCT( 8)
@@ -111,14 +113,15 @@ void ff_vp3_idct_dc_add_c(uint8_t *dest/*align 8*/, int line_size, const DCTELEM
void ff_vp3_v_loop_filter_c(uint8_t *src, int stride, int *bounding_values);
void ff_vp3_h_loop_filter_c(uint8_t *src, int stride, int *bounding_values);
-/* Bink functions */
-void ff_bink_idct_c (DCTELEM *block);
-void ff_bink_idct_add_c(uint8_t *dest, int linesize, DCTELEM *block);
-void ff_bink_idct_put_c(uint8_t *dest, int linesize, DCTELEM *block);
-
/* EA functions */
void ff_ea_idct_put_c(uint8_t *dest, int linesize, DCTELEM *block);
+/* RV40 functions */
+void ff_put_rv40_qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride);
+void ff_avg_rv40_qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride);
+void ff_put_rv40_qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride);
+void ff_avg_rv40_qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride);
+
/* 1/2^n downscaling functions from imgconvert.c */
void ff_shrink22(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
void ff_shrink44(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
@@ -130,7 +133,7 @@ void ff_gmc_c(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy,
/* minimum alignment rules ;)
If you notice errors in the align stuff, need more alignment for some ASM code
for some CPU or need to use a function with less aligned data then send a mail
-to the libav-devel mailing list, ...
+to the ffmpeg-devel mailing list, ...
!warning These alignments might not match reality, (missing attribute((align))
stuff somewhere possible).
@@ -201,6 +204,8 @@ typedef struct ScanTable{
} ScanTable;
void ff_init_scantable(uint8_t *, ScanTable *st, const uint8_t *src_scantable);
+void ff_init_scantable_permutation(uint8_t *idct_permutation,
+ int idct_permutation_type);
#define EMULATED_EDGE(depth) \
void ff_emulated_edge_mc_ ## depth (uint8_t *buf, const uint8_t *src, int linesize,\
@@ -211,8 +216,6 @@ EMULATED_EDGE(8)
EMULATED_EDGE(9)
EMULATED_EDGE(10)
-#define ff_emulated_edge_mc ff_emulated_edge_mc_8
-
void ff_add_pixels_clamped_c(const DCTELEM *block, uint8_t *dest, int linesize);
void ff_put_pixels_clamped_c(const DCTELEM *block, uint8_t *dest, int linesize);
void ff_put_signed_pixels_clamped_c(const DCTELEM *block, uint8_t *dest, int linesize);
@@ -221,12 +224,16 @@ void ff_put_signed_pixels_clamped_c(const DCTELEM *block, uint8_t *dest, int lin
* DSPContext.
*/
typedef struct DSPContext {
+ /**
+ * Size of DCT coefficients.
+ */
+ int dct_bits;
+
/* pixel ops : interface with DCT */
void (*get_pixels)(DCTELEM *block/*align 16*/, const uint8_t *pixels/*align 8*/, int line_size);
void (*diff_pixels)(DCTELEM *block/*align 16*/, const uint8_t *s1/*align 8*/, const uint8_t *s2/*align 8*/, int stride);
void (*put_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size);
void (*put_signed_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size);
- void (*put_pixels_nonclamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size);
void (*add_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size);
void (*add_pixels8)(uint8_t *pixels, DCTELEM *block, int line_size);
void (*add_pixels4)(uint8_t *pixels, DCTELEM *block, int line_size);
@@ -371,7 +378,6 @@ typedef struct DSPContext {
/* huffyuv specific */
void (*add_bytes)(uint8_t *dst/*align 16*/, uint8_t *src/*align 16*/, int w);
- void (*add_bytes_l2)(uint8_t *dst/*align 16*/, uint8_t *src1/*align 16*/, uint8_t *src2/*align 16*/, int w);
void (*diff_bytes)(uint8_t *dst/*align 16*/, uint8_t *src1/*align 16*/, uint8_t *src2/*align 1*/,int w);
/**
* subtract huffyuv's variant of median prediction
@@ -382,7 +388,6 @@ typedef struct DSPContext {
int (*add_hfyu_left_prediction)(uint8_t *dst, const uint8_t *src, int w, int left);
void (*add_hfyu_left_prediction_bgr32)(uint8_t *dst, const uint8_t *src, int w, int *red, int *green, int *blue, int *alpha);
/* this might write to dst[w] */
- void (*add_png_paeth_prediction)(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp);
void (*bswap_buf)(uint32_t *dst, const uint32_t *src, int w);
void (*bswap16_buf)(uint16_t *dst, const uint16_t *src, int len);
@@ -421,31 +426,16 @@ typedef struct DSPContext {
void (*vector_fmul_scalar)(float *dst, const float *src, float mul,
int len);
/**
- * Multiply a vector of floats by concatenated short vectors of
- * floats and by a scalar float. Source and destination vectors
- * must overlap exactly or not at all.
- * [0]: short vectors of length 2, 8-byte aligned
- * [1]: short vectors of length 4, 16-byte aligned
- * @param dst output vector, 16-byte aligned
+ * Multiply a vector of floats by a scalar float and add to
+ * destination vector. Source and destination vectors must
+ * overlap exactly or not at all.
+ * @param dst result vector, 16-byte aligned
* @param src input vector, 16-byte aligned
- * @param sv array of pointers to short vectors
- * @param mul scalar value
- * @param len number of elements in src and dst, multiple of 4
- */
- void (*vector_fmul_sv_scalar[2])(float *dst, const float *src,
- const float **sv, float mul, int len);
- /**
- * Multiply short vectors of floats by a scalar float, store
- * concatenated result.
- * [0]: short vectors of length 2, 8-byte aligned
- * [1]: short vectors of length 4, 16-byte aligned
- * @param dst output vector, 16-byte aligned
- * @param sv array of pointers to short vectors
* @param mul scalar value
- * @param len number of output elements, multiple of 4
+ * @param len length of vector, multiple of 4
*/
- void (*sv_fmul_scalar[2])(float *dst, const float **sv,
- float mul, int len);
+ void (*vector_fmac_scalar)(float *dst, const float *src, float mul,
+ int len);
/**
* Calculate the scalar product of two vectors of floats.
* @param v1 first vector, 16-byte aligned
@@ -571,19 +561,7 @@ typedef struct DSPContext {
void (*vector_clip_int32)(int32_t *dst, const int32_t *src, int32_t min,
int32_t max, unsigned int len);
- /* rv30 functions */
- qpel_mc_func put_rv30_tpel_pixels_tab[4][16];
- qpel_mc_func avg_rv30_tpel_pixels_tab[4][16];
-
- /* rv40 functions */
- qpel_mc_func put_rv40_qpel_pixels_tab[4][16];
- qpel_mc_func avg_rv40_qpel_pixels_tab[4][16];
- h264_chroma_mc_func put_rv40_chroma_pixels_tab[3];
- h264_chroma_mc_func avg_rv40_chroma_pixels_tab[3];
-
- /* bink functions */
op_fill_func fill_block_tab[2];
- void (*scale_block)(const uint8_t src[64]/*align 8*/, uint8_t *dst/*align 8*/, int linesize);
} DSPContext;
void dsputil_static_init(void);
@@ -657,14 +635,14 @@ void dsputil_init_sh4(DSPContext* c, AVCodecContext *avctx);
void dsputil_init_vis(DSPContext* c, AVCodecContext *avctx);
void ff_dsputil_init_dwt(DSPContext *c);
-void ff_rv30dsp_init(DSPContext* c, AVCodecContext *avctx);
-void ff_rv40dsp_init(DSPContext* c, AVCodecContext *avctx);
void ff_intrax8dsp_init(DSPContext* c, AVCodecContext *avctx);
void ff_mlp_init(DSPContext* c, AVCodecContext *avctx);
void ff_mlp_init_x86(DSPContext* c, AVCodecContext *avctx);
+
#if ARCH_ARM
+
#if HAVE_NEON
# define STRIDE_ALIGN 16
#endif
diff --git a/libavcodec/dsputil_template.c b/libavcodec/dsputil_template.c
index 645a881a19..85d4fec7dc 100644
--- a/libavcodec/dsputil_template.c
+++ b/libavcodec/dsputil_template.c
@@ -5,20 +5,20 @@
*
* gmc & q-pel & 32/64 bit based MC by Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -79,10 +79,10 @@ static inline void FUNC(copy_block16)(uint8_t *dst, const uint8_t *src, int dstS
/* draw the edges of width 'w' of an image of size width, height */
//FIXME check that this is ok for mpeg4 interlaced
-static void FUNCC(draw_edges)(uint8_t *_buf, int _wrap, int width, int height, int w, int h, int sides)
+static void FUNCC(draw_edges)(uint8_t *p_buf, int p_wrap, int width, int height, int w, int h, int sides)
{
- pixel *buf = (pixel*)_buf;
- int wrap = _wrap / sizeof(pixel);
+ pixel *buf = (pixel*)p_buf;
+ int wrap = p_wrap / sizeof(pixel);
pixel *ptr, *last_line;
int i;
@@ -192,187 +192,89 @@ void FUNC(ff_emulated_edge_mc)(uint8_t *buf, const uint8_t *src, int linesize, i
}
}
-static void FUNCC(add_pixels8)(uint8_t *restrict _pixels, DCTELEM *_block, int line_size)
-{
- int i;
- pixel *restrict pixels = (pixel *restrict)_pixels;
- dctcoef *block = (dctcoef*)_block;
- line_size /= sizeof(pixel);
-
- for(i=0;i<8;i++) {
- pixels[0] += block[0];
- pixels[1] += block[1];
- pixels[2] += block[2];
- pixels[3] += block[3];
- pixels[4] += block[4];
- pixels[5] += block[5];
- pixels[6] += block[6];
- pixels[7] += block[7];
- pixels += line_size;
- block += 8;
- }
+#define DCTELEM_FUNCS(dctcoef, suffix) \
+static void FUNCC(get_pixels ## suffix)(DCTELEM *restrict _block, \
+ const uint8_t *_pixels, \
+ int line_size) \
+{ \
+ const pixel *pixels = (const pixel *) _pixels; \
+ dctcoef *restrict block = (dctcoef *) _block; \
+ int i; \
+ \
+ /* read the pixels */ \
+ for(i=0;i<8;i++) { \
+ block[0] = pixels[0]; \
+ block[1] = pixels[1]; \
+ block[2] = pixels[2]; \
+ block[3] = pixels[3]; \
+ block[4] = pixels[4]; \
+ block[5] = pixels[5]; \
+ block[6] = pixels[6]; \
+ block[7] = pixels[7]; \
+ pixels += line_size / sizeof(pixel); \
+ block += 8; \
+ } \
+} \
+ \
+static void FUNCC(add_pixels8 ## suffix)(uint8_t *restrict _pixels, \
+ DCTELEM *_block, \
+ int line_size) \
+{ \
+ int i; \
+ pixel *restrict pixels = (pixel *restrict)_pixels; \
+ dctcoef *block = (dctcoef*)_block; \
+ line_size /= sizeof(pixel); \
+ \
+ for(i=0;i<8;i++) { \
+ pixels[0] += block[0]; \
+ pixels[1] += block[1]; \
+ pixels[2] += block[2]; \
+ pixels[3] += block[3]; \
+ pixels[4] += block[4]; \
+ pixels[5] += block[5]; \
+ pixels[6] += block[6]; \
+ pixels[7] += block[7]; \
+ pixels += line_size; \
+ block += 8; \
+ } \
+} \
+ \
+static void FUNCC(add_pixels4 ## suffix)(uint8_t *restrict _pixels, \
+ DCTELEM *_block, \
+ int line_size) \
+{ \
+ int i; \
+ pixel *restrict pixels = (pixel *restrict)_pixels; \
+ dctcoef *block = (dctcoef*)_block; \
+ line_size /= sizeof(pixel); \
+ \
+ for(i=0;i<4;i++) { \
+ pixels[0] += block[0]; \
+ pixels[1] += block[1]; \
+ pixels[2] += block[2]; \
+ pixels[3] += block[3]; \
+ pixels += line_size; \
+ block += 4; \
+ } \
+} \
+ \
+static void FUNCC(clear_block ## suffix)(DCTELEM *block) \
+{ \
+ memset(block, 0, sizeof(dctcoef)*64); \
+} \
+ \
+/** \
+ * memset(blocks, 0, sizeof(DCTELEM)*6*64) \
+ */ \
+static void FUNCC(clear_blocks ## suffix)(DCTELEM *blocks) \
+{ \
+ memset(blocks, 0, sizeof(dctcoef)*6*64); \
}
-static void FUNCC(add_pixels4)(uint8_t *restrict _pixels, DCTELEM *_block, int line_size)
-{
- int i;
- pixel *restrict pixels = (pixel *restrict)_pixels;
- dctcoef *block = (dctcoef*)_block;
- line_size /= sizeof(pixel);
-
- for(i=0;i<4;i++) {
- pixels[0] += block[0];
- pixels[1] += block[1];
- pixels[2] += block[2];
- pixels[3] += block[3];
- pixels += line_size;
- block += 4;
- }
-}
-
-#if 0
-
-#define PIXOP2(OPNAME, OP) \
-static void OPNAME ## _pixels(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
-{\
- int i;\
- for(i=0; i<h; i++){\
- OP(*((uint64_t*)block), AV_RN64(pixels));\
- pixels+=line_size;\
- block +=line_size;\
- }\
-}\
-\
-static void OPNAME ## _no_rnd_pixels_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
-{\
- int i;\
- for(i=0; i<h; i++){\
- const uint64_t a= AV_RN64(pixels );\
- const uint64_t b= AV_RN64(pixels+1);\
- OP(*((uint64_t*)block), (a&b) + (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
- pixels+=line_size;\
- block +=line_size;\
- }\
-}\
-\
-static void OPNAME ## _pixels_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
-{\
- int i;\
- for(i=0; i<h; i++){\
- const uint64_t a= AV_RN64(pixels );\
- const uint64_t b= AV_RN64(pixels+1);\
- OP(*((uint64_t*)block), (a|b) - (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
- pixels+=line_size;\
- block +=line_size;\
- }\
-}\
-\
-static void OPNAME ## _no_rnd_pixels_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
-{\
- int i;\
- for(i=0; i<h; i++){\
- const uint64_t a= AV_RN64(pixels );\
- const uint64_t b= AV_RN64(pixels+line_size);\
- OP(*((uint64_t*)block), (a&b) + (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
- pixels+=line_size;\
- block +=line_size;\
- }\
-}\
-\
-static void OPNAME ## _pixels_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
-{\
- int i;\
- for(i=0; i<h; i++){\
- const uint64_t a= AV_RN64(pixels );\
- const uint64_t b= AV_RN64(pixels+line_size);\
- OP(*((uint64_t*)block), (a|b) - (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
- pixels+=line_size;\
- block +=line_size;\
- }\
-}\
-\
-static void OPNAME ## _pixels_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
-{\
- int i;\
- const uint64_t a= AV_RN64(pixels );\
- const uint64_t b= AV_RN64(pixels+1);\
- uint64_t l0= (a&0x0303030303030303ULL)\
- + (b&0x0303030303030303ULL)\
- + 0x0202020202020202ULL;\
- uint64_t h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
- + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
- uint64_t l1,h1;\
-\
- pixels+=line_size;\
- for(i=0; i<h; i+=2){\
- uint64_t a= AV_RN64(pixels );\
- uint64_t b= AV_RN64(pixels+1);\
- l1= (a&0x0303030303030303ULL)\
- + (b&0x0303030303030303ULL);\
- h1= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
- + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
- OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
- pixels+=line_size;\
- block +=line_size;\
- a= AV_RN64(pixels );\
- b= AV_RN64(pixels+1);\
- l0= (a&0x0303030303030303ULL)\
- + (b&0x0303030303030303ULL)\
- + 0x0202020202020202ULL;\
- h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
- + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
- OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
- pixels+=line_size;\
- block +=line_size;\
- }\
-}\
-\
-static void OPNAME ## _no_rnd_pixels_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
-{\
- int i;\
- const uint64_t a= AV_RN64(pixels );\
- const uint64_t b= AV_RN64(pixels+1);\
- uint64_t l0= (a&0x0303030303030303ULL)\
- + (b&0x0303030303030303ULL)\
- + 0x0101010101010101ULL;\
- uint64_t h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
- + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
- uint64_t l1,h1;\
-\
- pixels+=line_size;\
- for(i=0; i<h; i+=2){\
- uint64_t a= AV_RN64(pixels );\
- uint64_t b= AV_RN64(pixels+1);\
- l1= (a&0x0303030303030303ULL)\
- + (b&0x0303030303030303ULL);\
- h1= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
- + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
- OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
- pixels+=line_size;\
- block +=line_size;\
- a= AV_RN64(pixels );\
- b= AV_RN64(pixels+1);\
- l0= (a&0x0303030303030303ULL)\
- + (b&0x0303030303030303ULL)\
- + 0x0101010101010101ULL;\
- h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
- + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
- OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
- pixels+=line_size;\
- block +=line_size;\
- }\
-}\
-\
-CALL_2X_PIXELS(OPNAME ## _pixels16_c , OPNAME ## _pixels_c , 8*sizeof(pixel))\
-CALL_2X_PIXELS(OPNAME ## _pixels16_x2_c , OPNAME ## _pixels_x2_c , 8*sizeof(pixel))\
-CALL_2X_PIXELS(OPNAME ## _pixels16_y2_c , OPNAME ## _pixels_y2_c , 8*sizeof(pixel))\
-CALL_2X_PIXELS(OPNAME ## _pixels16_xy2_c, OPNAME ## _pixels_xy2_c, 8*sizeof(pixel))\
-CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_x2_c , OPNAME ## _no_rnd_pixels_x2_c , 8*sizeof(pixel))\
-CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_y2_c , OPNAME ## _no_rnd_pixels_y2_c , 8*sizeof(pixel))\
-CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_xy2_c, OPNAME ## _no_rnd_pixels_xy2_c, 8*sizeof(pixel))
-
-#define op_avg(a, b) a = ( ((a)|(b)) - ((((a)^(b))&0xFEFEFEFEFEFEFEFEULL)>>1) )
-#else // 64 bit variant
+DCTELEM_FUNCS(DCTELEM, _16)
+#if BIT_DEPTH > 8
+DCTELEM_FUNCS(dctcoef, _32)
+#endif
#define PIXOP2(OPNAME, OP) \
static void FUNCC(OPNAME ## _pixels2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
@@ -582,12 +484,12 @@ static inline void FUNC(OPNAME ## _no_rnd_pixels16_l4)(uint8_t *dst, const uint8
FUNC(OPNAME ## _no_rnd_pixels8_l4)(dst+8*sizeof(pixel), src1+8*sizeof(pixel), src2+8*sizeof(pixel), src3+8*sizeof(pixel), src4+8*sizeof(pixel), dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
}\
\
-static inline void FUNCC(OPNAME ## _pixels2_xy2)(uint8_t *_block, const uint8_t *_pixels, int line_size, int h)\
+static inline void FUNCC(OPNAME ## _pixels2_xy2)(uint8_t *p_block, const uint8_t *p_pixels, int line_size, int h)\
{\
int i, a0, b0, a1, b1;\
- pixel *block = (pixel*)_block;\
- const pixel *pixels = (const pixel*)_pixels;\
- line_size /= sizeof(pixel);\
+ pixel *block = (pixel*)p_block;\
+ const pixel *pixels = (const pixel*)p_pixels;\
+ line_size >>= sizeof(pixel)-1;\
a0= pixels[0];\
b0= pixels[1] + 2;\
a0 += b0;\
@@ -749,7 +651,6 @@ CALL_2X_PIXELS(FUNCC(OPNAME ## _no_rnd_pixels16_y2) , FUNCC(OPNAME ## _no_rnd_pi
CALL_2X_PIXELS(FUNCC(OPNAME ## _no_rnd_pixels16_xy2), FUNCC(OPNAME ## _no_rnd_pixels8_xy2), 8*sizeof(pixel))\
#define op_avg(a, b) a = rnd_avg_pixel4(a, b)
-#endif
#define op_put(a, b) a = b
PIXOP2(avg, op_avg)
@@ -769,15 +670,15 @@ static void FUNCC(put_no_rnd_pixels8_l2)(uint8_t *dst, const uint8_t *a, const u
}
#define H264_CHROMA_MC(OPNAME, OP)\
-static void FUNCC(OPNAME ## h264_chroma_mc2)(uint8_t *_dst/*align 8*/, uint8_t *_src/*align 1*/, int stride, int h, int x, int y){\
- pixel *dst = (pixel*)_dst;\
- pixel *src = (pixel*)_src;\
+static void FUNCC(OPNAME ## h264_chroma_mc2)(uint8_t *p_dst/*align 8*/, uint8_t *p_src/*align 1*/, int stride, int h, int x, int y){\
+ pixel *dst = (pixel*)p_dst;\
+ pixel *src = (pixel*)p_src;\
const int A=(8-x)*(8-y);\
const int B=( x)*(8-y);\
const int C=(8-x)*( y);\
const int D=( x)*( y);\
int i;\
- stride /= sizeof(pixel);\
+ stride >>= sizeof(pixel)-1;\
\
assert(x<8 && y<8 && x>=0 && y>=0);\
\
@@ -800,15 +701,15 @@ static void FUNCC(OPNAME ## h264_chroma_mc2)(uint8_t *_dst/*align 8*/, uint8_t *
}\
}\
\
-static void FUNCC(OPNAME ## h264_chroma_mc4)(uint8_t *_dst/*align 8*/, uint8_t *_src/*align 1*/, int stride, int h, int x, int y){\
- pixel *dst = (pixel*)_dst;\
- pixel *src = (pixel*)_src;\
+static void FUNCC(OPNAME ## h264_chroma_mc4)(uint8_t *p_dst/*align 8*/, uint8_t *p_src/*align 1*/, int stride, int h, int x, int y){\
+ pixel *dst = (pixel*)p_dst;\
+ pixel *src = (pixel*)p_src;\
const int A=(8-x)*(8-y);\
const int B=( x)*(8-y);\
const int C=(8-x)*( y);\
const int D=( x)*( y);\
int i;\
- stride /= sizeof(pixel);\
+ stride >>= sizeof(pixel)-1;\
\
assert(x<8 && y<8 && x>=0 && y>=0);\
\
@@ -835,15 +736,15 @@ static void FUNCC(OPNAME ## h264_chroma_mc4)(uint8_t *_dst/*align 8*/, uint8_t *
}\
}\
\
-static void FUNCC(OPNAME ## h264_chroma_mc8)(uint8_t *_dst/*align 8*/, uint8_t *_src/*align 1*/, int stride, int h, int x, int y){\
- pixel *dst = (pixel*)_dst;\
- pixel *src = (pixel*)_src;\
+static void FUNCC(OPNAME ## h264_chroma_mc8)(uint8_t *p_dst/*align 8*/, uint8_t *p_src/*align 1*/, int stride, int h, int x, int y){\
+ pixel *dst = (pixel*)p_dst;\
+ pixel *src = (pixel*)p_src;\
const int A=(8-x)*(8-y);\
const int B=( x)*(8-y);\
const int C=(8-x)*( y);\
const int D=( x)*( y);\
int i;\
- stride /= sizeof(pixel);\
+ stride >>= sizeof(pixel)-1;\
\
assert(x<8 && y<8 && x>=0 && y>=0);\
\
@@ -887,14 +788,14 @@ H264_CHROMA_MC(avg_ , op_avg)
#undef op_put
#define H264_LOWPASS(OPNAME, OP, OP2) \
-static av_unused void FUNC(OPNAME ## h264_qpel2_h_lowpass)(uint8_t *_dst, uint8_t *_src, int dstStride, int srcStride){\
+static av_unused void FUNC(OPNAME ## h264_qpel2_h_lowpass)(uint8_t *p_dst, uint8_t *p_src, int dstStride, int srcStride){\
const int h=2;\
INIT_CLIP\
int i;\
- pixel *dst = (pixel*)_dst;\
- pixel *src = (pixel*)_src;\
- dstStride /= sizeof(pixel);\
- srcStride /= sizeof(pixel);\
+ pixel *dst = (pixel*)p_dst;\
+ pixel *src = (pixel*)p_src;\
+ dstStride >>= sizeof(pixel)-1;\
+ srcStride >>= sizeof(pixel)-1;\
for(i=0; i<h; i++)\
{\
OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]));\
@@ -904,14 +805,14 @@ static av_unused void FUNC(OPNAME ## h264_qpel2_h_lowpass)(uint8_t *_dst, uint8_
}\
}\
\
-static av_unused void FUNC(OPNAME ## h264_qpel2_v_lowpass)(uint8_t *_dst, uint8_t *_src, int dstStride, int srcStride){\
+static av_unused void FUNC(OPNAME ## h264_qpel2_v_lowpass)(uint8_t *p_dst, uint8_t *p_src, int dstStride, int srcStride){\
const int w=2;\
INIT_CLIP\
int i;\
- pixel *dst = (pixel*)_dst;\
- pixel *src = (pixel*)_src;\
- dstStride /= sizeof(pixel);\
- srcStride /= sizeof(pixel);\
+ pixel *dst = (pixel*)p_dst;\
+ pixel *src = (pixel*)p_src;\
+ dstStride >>= sizeof(pixel)-1;\
+ srcStride >>= sizeof(pixel)-1;\
for(i=0; i<w; i++)\
{\
const int srcB= src[-2*srcStride];\
@@ -928,16 +829,16 @@ static av_unused void FUNC(OPNAME ## h264_qpel2_v_lowpass)(uint8_t *_dst, uint8_
}\
}\
\
-static av_unused void FUNC(OPNAME ## h264_qpel2_hv_lowpass)(uint8_t *_dst, int16_t *tmp, uint8_t *_src, int dstStride, int tmpStride, int srcStride){\
+static av_unused void FUNC(OPNAME ## h264_qpel2_hv_lowpass)(uint8_t *p_dst, int16_t *tmp, uint8_t *p_src, int dstStride, int tmpStride, int srcStride){\
const int h=2;\
const int w=2;\
const int pad = (BIT_DEPTH > 9) ? (-10 * ((1<<BIT_DEPTH)-1)) : 0;\
INIT_CLIP\
int i;\
- pixel *dst = (pixel*)_dst;\
- pixel *src = (pixel*)_src;\
- dstStride /= sizeof(pixel);\
- srcStride /= sizeof(pixel);\
+ pixel *dst = (pixel*)p_dst;\
+ pixel *src = (pixel*)p_src;\
+ dstStride >>= sizeof(pixel)-1;\
+ srcStride >>= sizeof(pixel)-1;\
src -= 2*srcStride;\
for(i=0; i<h+5; i++)\
{\
@@ -962,14 +863,14 @@ static av_unused void FUNC(OPNAME ## h264_qpel2_hv_lowpass)(uint8_t *_dst, int16
tmp++;\
}\
}\
-static void FUNC(OPNAME ## h264_qpel4_h_lowpass)(uint8_t *_dst, uint8_t *_src, int dstStride, int srcStride){\
+static void FUNC(OPNAME ## h264_qpel4_h_lowpass)(uint8_t *p_dst, uint8_t *p_src, int dstStride, int srcStride){\
const int h=4;\
INIT_CLIP\
int i;\
- pixel *dst = (pixel*)_dst;\
- pixel *src = (pixel*)_src;\
- dstStride /= sizeof(pixel);\
- srcStride /= sizeof(pixel);\
+ pixel *dst = (pixel*)p_dst;\
+ pixel *src = (pixel*)p_src;\
+ dstStride >>= sizeof(pixel)-1;\
+ srcStride >>= sizeof(pixel)-1;\
for(i=0; i<h; i++)\
{\
OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]));\
@@ -981,14 +882,14 @@ static void FUNC(OPNAME ## h264_qpel4_h_lowpass)(uint8_t *_dst, uint8_t *_src, i
}\
}\
\
-static void FUNC(OPNAME ## h264_qpel4_v_lowpass)(uint8_t *_dst, uint8_t *_src, int dstStride, int srcStride){\
+static void FUNC(OPNAME ## h264_qpel4_v_lowpass)(uint8_t *p_dst, uint8_t *p_src, int dstStride, int srcStride){\
const int w=4;\
INIT_CLIP\
int i;\
- pixel *dst = (pixel*)_dst;\
- pixel *src = (pixel*)_src;\
- dstStride /= sizeof(pixel);\
- srcStride /= sizeof(pixel);\
+ pixel *dst = (pixel*)p_dst;\
+ pixel *src = (pixel*)p_src;\
+ dstStride >>= sizeof(pixel)-1;\
+ srcStride >>= sizeof(pixel)-1;\
for(i=0; i<w; i++)\
{\
const int srcB= src[-2*srcStride];\
@@ -1009,16 +910,16 @@ static void FUNC(OPNAME ## h264_qpel4_v_lowpass)(uint8_t *_dst, uint8_t *_src, i
}\
}\
\
-static void FUNC(OPNAME ## h264_qpel4_hv_lowpass)(uint8_t *_dst, int16_t *tmp, uint8_t *_src, int dstStride, int tmpStride, int srcStride){\
+static void FUNC(OPNAME ## h264_qpel4_hv_lowpass)(uint8_t *p_dst, int16_t *tmp, uint8_t *p_src, int dstStride, int tmpStride, int srcStride){\
const int h=4;\
const int w=4;\
const int pad = (BIT_DEPTH > 9) ? (-10 * ((1<<BIT_DEPTH)-1)) : 0;\
INIT_CLIP\
int i;\
- pixel *dst = (pixel*)_dst;\
- pixel *src = (pixel*)_src;\
- dstStride /= sizeof(pixel);\
- srcStride /= sizeof(pixel);\
+ pixel *dst = (pixel*)p_dst;\
+ pixel *src = (pixel*)p_src;\
+ dstStride >>= sizeof(pixel)-1;\
+ srcStride >>= sizeof(pixel)-1;\
src -= 2*srcStride;\
for(i=0; i<h+5; i++)\
{\
@@ -1050,14 +951,14 @@ static void FUNC(OPNAME ## h264_qpel4_hv_lowpass)(uint8_t *_dst, int16_t *tmp, u
}\
}\
\
-static void FUNC(OPNAME ## h264_qpel8_h_lowpass)(uint8_t *_dst, uint8_t *_src, int dstStride, int srcStride){\
+static void FUNC(OPNAME ## h264_qpel8_h_lowpass)(uint8_t *p_dst, uint8_t *p_src, int dstStride, int srcStride){\
const int h=8;\
INIT_CLIP\
int i;\
- pixel *dst = (pixel*)_dst;\
- pixel *src = (pixel*)_src;\
- dstStride /= sizeof(pixel);\
- srcStride /= sizeof(pixel);\
+ pixel *dst = (pixel*)p_dst;\
+ pixel *src = (pixel*)p_src;\
+ dstStride >>= sizeof(pixel)-1;\
+ srcStride >>= sizeof(pixel)-1;\
for(i=0; i<h; i++)\
{\
OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3 ]));\
@@ -1073,14 +974,14 @@ static void FUNC(OPNAME ## h264_qpel8_h_lowpass)(uint8_t *_dst, uint8_t *_src, i
}\
}\
\
-static void FUNC(OPNAME ## h264_qpel8_v_lowpass)(uint8_t *_dst, uint8_t *_src, int dstStride, int srcStride){\
+static void FUNC(OPNAME ## h264_qpel8_v_lowpass)(uint8_t *p_dst, uint8_t *p_src, int dstStride, int srcStride){\
const int w=8;\
INIT_CLIP\
int i;\
- pixel *dst = (pixel*)_dst;\
- pixel *src = (pixel*)_src;\
- dstStride /= sizeof(pixel);\
- srcStride /= sizeof(pixel);\
+ pixel *dst = (pixel*)p_dst;\
+ pixel *src = (pixel*)p_src;\
+ dstStride >>= sizeof(pixel)-1;\
+ srcStride >>= sizeof(pixel)-1;\
for(i=0; i<w; i++)\
{\
const int srcB= src[-2*srcStride];\
@@ -1109,16 +1010,16 @@ static void FUNC(OPNAME ## h264_qpel8_v_lowpass)(uint8_t *_dst, uint8_t *_src, i
}\
}\
\
-static void FUNC(OPNAME ## h264_qpel8_hv_lowpass)(uint8_t *_dst, int16_t *tmp, uint8_t *_src, int dstStride, int tmpStride, int srcStride){\
+static void FUNC(OPNAME ## h264_qpel8_hv_lowpass)(uint8_t *p_dst, int16_t *tmp, uint8_t *p_src, int dstStride, int tmpStride, int srcStride){\
const int h=8;\
const int w=8;\
const int pad = (BIT_DEPTH > 9) ? (-10 * ((1<<BIT_DEPTH)-1)) : 0;\
INIT_CLIP\
int i;\
- pixel *dst = (pixel*)_dst;\
- pixel *src = (pixel*)_src;\
- dstStride /= sizeof(pixel);\
- srcStride /= sizeof(pixel);\
+ pixel *dst = (pixel*)p_dst;\
+ pixel *src = (pixel*)p_src;\
+ dstStride >>= sizeof(pixel)-1;\
+ srcStride >>= sizeof(pixel)-1;\
src -= 2*srcStride;\
for(i=0; i<h+5; i++)\
{\
@@ -1377,15 +1278,3 @@ void FUNCC(ff_avg_pixels16x16)(uint8_t *dst, uint8_t *src, int stride) {
FUNCC(avg_pixels16)(dst, src, stride, 16);
}
-static void FUNCC(clear_block)(DCTELEM *block)
-{
- memset(block, 0, sizeof(dctcoef)*64);
-}
-
-/**
- * memset(blocks, 0, sizeof(DCTELEM)*6*64)
- */
-static void FUNCC(clear_blocks)(DCTELEM *blocks)
-{
- memset(blocks, 0, sizeof(dctcoef)*6*64);
-}
diff --git a/libavcodec/dump_extradata_bsf.c b/libavcodec/dump_extradata_bsf.c
index ba77b15c6b..9499d6d8d8 100644
--- a/libavcodec/dump_extradata_bsf.c
+++ b/libavcodec/dump_extradata_bsf.c
@@ -1,20 +1,20 @@
/*
* copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/dv.c b/libavcodec/dv.c
index a35bb2f2ed..462cbbed45 100644
--- a/libavcodec/dv.c
+++ b/libavcodec/dv.c
@@ -16,20 +16,20 @@
* Many thanks to Dan Dennedy <dan@dennedy.org> for providing wealth
* of DV technical info.
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -349,7 +349,7 @@ static av_cold int dvvideo_init(AVCodecContext *avctx)
static av_cold int dvvideo_init_encoder(AVCodecContext *avctx)
{
- if (!ff_dv_codec_profile(avctx)) {
+ if (!avpriv_dv_codec_profile(avctx)) {
av_log(avctx, AV_LOG_ERROR, "Found no DV profile for %ix%i %s video\n",
avctx->width, avctx->height, av_get_pix_fmt_name(avctx->pix_fmt));
return -1;
@@ -775,7 +775,7 @@ static av_always_inline int dv_init_enc_block(EncBlockInfo* bi, uint8_t *data, i
method suggested in SMPTE 314M Table 22, and an improved
method. The SMPTE method is very conservative; it assigns class
3 (i.e. severe quantization) to any block where the largest AC
- component is greater than 36. Libav's DV encoder tracks AC bit
+ component is greater than 36. FFmpeg's DV encoder tracks AC bit
consumption precisely, so there is no need to bias most blocks
towards strongly lossy compression. Instead, we assign class 2
to most blocks, and use class 3 only when strictly necessary
@@ -783,7 +783,7 @@ static av_always_inline int dv_init_enc_block(EncBlockInfo* bi, uint8_t *data, i
#if 0 /* SMPTE spec method */
static const int classes[] = {12, 24, 36, 0xffff};
-#else /* improved Libav method */
+#else /* improved FFmpeg method */
static const int classes[] = {-1, -1, 255, 0xffff};
#endif
int max = classes[0];
@@ -1072,7 +1072,7 @@ static int dvvideo_decode_frame(AVCodecContext *avctx,
const uint8_t* vsc_pack;
int apt, is16_9;
- s->sys = ff_dv_frame_profile(s->sys, buf, buf_size);
+ s->sys = avpriv_dv_frame_profile2(avctx, s->sys, buf, buf_size);
if (!s->sys || buf_size < s->sys->frame_size || dv_init_dynamic_tables(s->sys)) {
av_log(avctx, AV_LOG_ERROR, "could not find dv frame profile\n");
return -1; /* NOTE: we only accept several full frames */
@@ -1081,6 +1081,7 @@ static int dvvideo_decode_frame(AVCodecContext *avctx,
if (s->picture.data[0])
avctx->release_buffer(avctx, &s->picture);
+ avcodec_get_frame_defaults(&s->picture);
s->picture.reference = 0;
s->picture.key_frame = 1;
s->picture.pict_type = AV_PICTURE_TYPE_I;
@@ -1108,7 +1109,7 @@ static int dvvideo_decode_frame(AVCodecContext *avctx,
vsc_pack = buf + 80*5 + 48 + 5;
if ( *vsc_pack == dv_video_control ) {
apt = buf[4] & 0x07;
- is16_9 = (vsc_pack && ((vsc_pack[2] & 0x07) == 0x02 || (!apt && (vsc_pack[2] & 0x07) == 0x07)));
+ is16_9 = (vsc_pack[2] & 0x07) == 0x02 || (!apt && (vsc_pack[2] & 0x07) == 0x07);
avctx->sample_aspect_ratio = s->sys->sar[is16_9];
}
@@ -1245,7 +1246,7 @@ static int dvvideo_encode_frame(AVCodecContext *c, uint8_t *buf, int buf_size,
{
DVVideoContext *s = c->priv_data;
- s->sys = ff_dv_codec_profile(c);
+ s->sys = avpriv_dv_codec_profile(c);
if (!s->sys || buf_size < s->sys->frame_size || dv_init_dynamic_tables(s->sys))
return -1;
@@ -1279,12 +1280,12 @@ static int dvvideo_close(AVCodecContext *c)
#if CONFIG_DVVIDEO_ENCODER
AVCodec ff_dvvideo_encoder = {
- "dvvideo",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_DVVIDEO,
- sizeof(DVVideoContext),
- dvvideo_init_encoder,
- dvvideo_encode_frame,
+ .name = "dvvideo",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_DVVIDEO,
+ .priv_data_size = sizeof(DVVideoContext),
+ .init = dvvideo_init_encoder,
+ .encode = dvvideo_encode_frame,
.capabilities = CODEC_CAP_SLICE_THREADS,
.pix_fmts = (const enum PixelFormat[]) {PIX_FMT_YUV411P, PIX_FMT_YUV422P, PIX_FMT_YUV420P, PIX_FMT_NONE},
.long_name = NULL_IF_CONFIG_SMALL("DV (Digital Video)"),
@@ -1293,16 +1294,14 @@ AVCodec ff_dvvideo_encoder = {
#if CONFIG_DVVIDEO_DECODER
AVCodec ff_dvvideo_decoder = {
- "dvvideo",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_DVVIDEO,
- sizeof(DVVideoContext),
- dvvideo_init,
- NULL,
- dvvideo_close,
- dvvideo_decode_frame,
- CODEC_CAP_DR1 | CODEC_CAP_SLICE_THREADS,
- NULL,
+ .name = "dvvideo",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_DVVIDEO,
+ .priv_data_size = sizeof(DVVideoContext),
+ .init = dvvideo_init,
+ .close = dvvideo_close,
+ .decode = dvvideo_decode_frame,
+ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_SLICE_THREADS,
.max_lowres = 3,
.long_name = NULL_IF_CONFIG_SMALL("DV (Digital Video)"),
};
diff --git a/libavcodec/dv_tablegen.c b/libavcodec/dv_tablegen.c
index f463550365..5d3793e11d 100644
--- a/libavcodec/dv_tablegen.c
+++ b/libavcodec/dv_tablegen.c
@@ -3,20 +3,20 @@
*
* Copyright (c) 2010 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/dv_tablegen.h b/libavcodec/dv_tablegen.h
index 4fa8d91374..678be73940 100644
--- a/libavcodec/dv_tablegen.h
+++ b/libavcodec/dv_tablegen.h
@@ -3,20 +3,20 @@
*
* Copyright (c) 2010 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/dv_vlc_data.h b/libavcodec/dv_vlc_data.h
index b5c1ddecb4..c23c564613 100644
--- a/libavcodec/dv_vlc_data.h
+++ b/libavcodec/dv_vlc_data.h
@@ -2,20 +2,20 @@
* VLC constants for DV codec
* Copyright (c) 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/dvbsub.c b/libavcodec/dvbsub.c
index 206e50e1d2..58b7f970f8 100644
--- a/libavcodec/dvbsub.c
+++ b/libavcodec/dvbsub.c
@@ -2,20 +2,20 @@
* DVB subtitle encoding for ffmpeg
* Copyright (c) 2005 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avcodec.h"
@@ -194,6 +194,61 @@ static void dvb_encode_rle4(uint8_t **pq,
*pq = q;
}
+static void dvb_encode_rle8(uint8_t **pq,
+ const uint8_t *bitmap, int linesize,
+ int w, int h)
+{
+ uint8_t *q;
+ int x, y, len, x1, f, color;
+
+ q = *pq;
+
+ for (y = 0; y < h; y++) {
+ *q++ = 0x12;
+
+ x = 0;
+ f = 0;
+ while (x < w) {
+ x1 = x;
+ color = bitmap[x1++];
+ while (x1 < w && bitmap[x1] == color)
+ x1++;
+ len = x1 - x;
+ if (len == 1 && color) {
+ // 00000001 to 11111111 1 pixel in colour x
+ *q++ = color;
+ } else {
+ if (color == 0x00) {
+ // 00000000 0LLLLLLL L pixels (1-127) in colour 0 (L > 0)
+ len = FFMIN(len, 127);
+ *q++ = 0x00;
+ *q++ = len;
+ } else if (len > 2) {
+ // 00000000 1LLLLLLL CCCCCCCC L pixels (3-127) in colour C (L > 2)
+ len = FFMIN(len, 127);
+ *q++ = 0x00;
+ *q++ = 0x80+len;
+ *q++ = color;
+ }
+ else if (len == 2) {
+ *q++ = color;
+ *q++ = color;
+ } else {
+ *q++ = color;
+ len = 1;
+ }
+ }
+ x += len;
+ }
+ /* end of line */
+ // 00000000 00000000 end of 8-bit/pixel_code_string
+ *q++ = 0x00;
+ *q++ = 0x00;
+ bitmap += linesize;
+ }
+ *pq = q;
+}
+
static int encode_dvb_subtitles(DVBSubtitleContext *s,
uint8_t *outbuf, AVSubtitle *h)
{
@@ -245,10 +300,15 @@ static int encode_dvb_subtitles(DVBSubtitleContext *s,
} else if (h->rects[clut_id]->nb_colors <= 16) {
/* 4 bpp, standard encoding */
bpp_index = 1;
+ } else if (h->rects[clut_id]->nb_colors <= 256) {
+ /* 8 bpp, standard encoding */
+ bpp_index = 2;
} else {
return -1;
}
+
+ /* CLUT segment */
*q++ = 0x0f; /* sync byte */
*q++ = 0x12; /* CLUT definition segment */
bytestream_put_be16(&q, page_id);
@@ -321,18 +381,25 @@ static int encode_dvb_subtitles(DVBSubtitleContext *s,
if (!s->hide_state) {
for (object_id = 0; object_id < h->num_rects; object_id++) {
- /* Object Data segment */
+ void (*dvb_encode_rle)(uint8_t **pq,
+ const uint8_t *bitmap, int linesize,
+ int w, int h);
+ /* bpp_index maths */
if (h->rects[object_id]->nb_colors <= 4) {
/* 2 bpp, some decoders do not support it correctly */
- bpp_index = 0;
+ dvb_encode_rle = dvb_encode_rle2;
} else if (h->rects[object_id]->nb_colors <= 16) {
/* 4 bpp, standard encoding */
- bpp_index = 1;
+ dvb_encode_rle = dvb_encode_rle4;
+ } else if (h->rects[object_id]->nb_colors <= 256) {
+ /* 8 bpp, standard encoding */
+ dvb_encode_rle = dvb_encode_rle8;
} else {
return -1;
}
+ /* Object Data segment */
*q++ = 0x0f; /* sync byte */
*q++ = 0x13;
bytestream_put_be16(&q, page_id);
@@ -345,19 +412,12 @@ static int encode_dvb_subtitles(DVBSubtitleContext *s,
non_modifying_color_flag */
{
uint8_t *ptop_field_len, *pbottom_field_len, *top_ptr, *bottom_ptr;
- void (*dvb_encode_rle)(uint8_t **pq,
- const uint8_t *bitmap, int linesize,
- int w, int h);
+
ptop_field_len = q;
q += 2;
pbottom_field_len = q;
q += 2;
- if (bpp_index == 0)
- dvb_encode_rle = dvb_encode_rle2;
- else
- dvb_encode_rle = dvb_encode_rle4;
-
top_ptr = q;
dvb_encode_rle(&q, h->rects[object_id]->pict.data[0], h->rects[object_id]->w * 2,
h->rects[object_id]->w, h->rects[object_id]->h >> 1);
@@ -403,11 +463,10 @@ static int dvbsub_encode(AVCodecContext *avctx,
}
AVCodec ff_dvbsub_encoder = {
- "dvbsub",
- AVMEDIA_TYPE_SUBTITLE,
- CODEC_ID_DVB_SUBTITLE,
- sizeof(DVBSubtitleContext),
- NULL,
- dvbsub_encode,
+ .name = "dvbsub",
+ .type = AVMEDIA_TYPE_SUBTITLE,
+ .id = CODEC_ID_DVB_SUBTITLE,
+ .priv_data_size = sizeof(DVBSubtitleContext),
+ .encode = dvbsub_encode,
.long_name = NULL_IF_CONFIG_SMALL("DVB subtitles"),
};
diff --git a/libavcodec/dvbsub_parser.c b/libavcodec/dvbsub_parser.c
index 8f3b0653d4..59d03d1d46 100644
--- a/libavcodec/dvbsub_parser.c
+++ b/libavcodec/dvbsub_parser.c
@@ -1,21 +1,21 @@
/*
- * DVB subtitle parser for Libav
+ * DVB subtitle parser for FFmpeg
* Copyright (c) 2005 Ian Caulfield
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avcodec.h"
diff --git a/libavcodec/dvbsubdec.c b/libavcodec/dvbsubdec.c
index 3f39a960cb..8ba84da225 100644
--- a/libavcodec/dvbsubdec.c
+++ b/libavcodec/dvbsubdec.c
@@ -2,20 +2,20 @@
* DVB subtitle decoding for ffmpeg
* Copyright (c) 2005 Ian Caulfield
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avcodec.h"
@@ -154,6 +154,7 @@ static void png_save2(const char *filename, uint32_t *bitmap, int w, int h)
typedef struct DVBSubCLUT {
int id;
+ int version;
uint32_t clut4[4];
uint32_t clut16[16];
@@ -180,6 +181,7 @@ typedef struct DVBSubObjectDisplay {
typedef struct DVBSubObject {
int id;
+ int version;
int type;
@@ -199,6 +201,7 @@ typedef struct DVBSubRegionDisplay {
typedef struct DVBSubRegion {
int id;
+ int version;
int width;
int height;
@@ -209,6 +212,7 @@ typedef struct DVBSubRegion {
uint8_t *pbuf;
int buf_size;
+ int dirty;
DVBSubObjectDisplay *display_list;
@@ -228,6 +232,7 @@ typedef struct DVBSubContext {
int composition_id;
int ancillary_id;
+ int version;
int time_out;
DVBSubRegion *region_list;
DVBSubCLUT *clut_list;
@@ -318,21 +323,10 @@ static void delete_region_display_list(DVBSubContext *ctx, DVBSubRegion *region)
}
-static void delete_state(DVBSubContext *ctx)
+static void delete_cluts(DVBSubContext *ctx)
{
- DVBSubRegion *region;
DVBSubCLUT *clut;
- while (ctx->region_list) {
- region = ctx->region_list;
-
- ctx->region_list = region->next;
-
- delete_region_display_list(ctx, region);
- av_free(region->pbuf);
- av_free(region);
- }
-
while (ctx->clut_list) {
clut = ctx->clut_list;
@@ -340,12 +334,35 @@ static void delete_state(DVBSubContext *ctx)
av_free(clut);
}
+}
- av_freep(&ctx->display_definition);
+static void delete_objects(DVBSubContext *ctx)
+{
+ DVBSubObject *object;
+
+ while (ctx->object_list) {
+ object = ctx->object_list;
+
+ ctx->object_list = object->next;
+
+ av_free(object);
+ }
+}
+
+static void delete_regions(DVBSubContext *ctx)
+{
+ DVBSubRegion *region;
- /* Should already be null */
- if (ctx->object_list)
- av_log(0, AV_LOG_ERROR, "Memory deallocation error!\n");
+ while (ctx->region_list) {
+ region = ctx->region_list;
+
+ ctx->region_list = region->next;
+
+ delete_region_display_list(ctx, region);
+
+ av_free(region->pbuf);
+ av_free(region);
+ }
}
static av_cold int dvbsub_init_decoder(AVCodecContext *avctx)
@@ -362,6 +379,8 @@ static av_cold int dvbsub_init_decoder(AVCodecContext *avctx)
ctx->ancillary_id = AV_RB16(avctx->extradata + 2);
}
+ ctx->version = -1;
+
default_clut.id = -1;
default_clut.next = NULL;
@@ -430,7 +449,13 @@ static av_cold int dvbsub_close_decoder(AVCodecContext *avctx)
DVBSubContext *ctx = avctx->priv_data;
DVBSubRegionDisplay *display;
- delete_state(ctx);
+ delete_regions(ctx);
+
+ delete_objects(ctx);
+
+ delete_cluts(ctx);
+
+ av_freep(&ctx->display_definition);
while (ctx->display_list) {
display = ctx->display_list;
@@ -444,16 +469,18 @@ static av_cold int dvbsub_close_decoder(AVCodecContext *avctx)
static int dvbsub_read_2bit_string(uint8_t *destbuf, int dbuf_len,
const uint8_t **srcbuf, int buf_size,
- int non_mod, uint8_t *map_table)
+ int non_mod, uint8_t *map_table, int x_pos)
{
GetBitContext gb;
int bits;
int run_length;
- int pixels_read = 0;
+ int pixels_read = x_pos;
init_get_bits(&gb, *srcbuf, buf_size << 3);
+ destbuf += x_pos;
+
while (get_bits_count(&gb) < buf_size << 3 && pixels_read < dbuf_len) {
bits = get_bits(&gb, 2);
@@ -514,14 +541,14 @@ static int dvbsub_read_2bit_string(uint8_t *destbuf, int dbuf_len,
}
}
} else if (bits == 1) {
- pixels_read += 2;
if (map_table)
bits = map_table[0];
else
bits = 0;
- if (pixels_read <= dbuf_len) {
- *destbuf++ = bits;
+ run_length = 2;
+ while (run_length-- > 0 && pixels_read < dbuf_len) {
*destbuf++ = bits;
+ pixels_read++;
}
} else {
(*srcbuf) += (get_bits_count(&gb) + 7) >> 3;
@@ -549,16 +576,18 @@ static int dvbsub_read_2bit_string(uint8_t *destbuf, int dbuf_len,
static int dvbsub_read_4bit_string(uint8_t *destbuf, int dbuf_len,
const uint8_t **srcbuf, int buf_size,
- int non_mod, uint8_t *map_table)
+ int non_mod, uint8_t *map_table, int x_pos)
{
GetBitContext gb;
int bits;
int run_length;
- int pixels_read = 0;
+ int pixels_read = x_pos;
init_get_bits(&gb, *srcbuf, buf_size << 3);
+ destbuf += x_pos;
+
while (get_bits_count(&gb) < buf_size << 3 && pixels_read < dbuf_len) {
bits = get_bits(&gb, 4);
@@ -638,14 +667,14 @@ static int dvbsub_read_4bit_string(uint8_t *destbuf, int dbuf_len,
}
}
} else if (bits == 1) {
- pixels_read += 2;
if (map_table)
bits = map_table[0];
else
bits = 0;
- if (pixels_read <= dbuf_len) {
- *destbuf++ = bits;
+ run_length = 2;
+ while (run_length-- > 0 && pixels_read < dbuf_len) {
*destbuf++ = bits;
+ pixels_read++;
}
} else {
if (map_table)
@@ -670,12 +699,14 @@ static int dvbsub_read_4bit_string(uint8_t *destbuf, int dbuf_len,
static int dvbsub_read_8bit_string(uint8_t *destbuf, int dbuf_len,
const uint8_t **srcbuf, int buf_size,
- int non_mod, uint8_t *map_table)
+ int non_mod, uint8_t *map_table, int x_pos)
{
const uint8_t *sbuf_end = (*srcbuf) + buf_size;
int bits;
int run_length;
- int pixels_read = 0;
+ int pixels_read = x_pos;
+
+ destbuf += x_pos;
while (*srcbuf < sbuf_end && pixels_read < dbuf_len) {
bits = *(*srcbuf)++;
@@ -744,6 +775,7 @@ static void dvbsub_parse_pixel_data_block(AVCodecContext *avctx, DVBSubObjectDis
0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff};
uint8_t *map_table;
+#if 0
av_dlog(avctx, "DVB pixel block size %d, %s field:\n", buf_size,
top_bottom ? "bottom" : "top");
@@ -758,21 +790,22 @@ static void dvbsub_parse_pixel_data_block(AVCodecContext *avctx, DVBSubObjectDis
if (i % 16)
av_dlog(avctx, "\n");
+#endif
if (region == 0)
return;
pbuf = region->pbuf;
+ region->dirty = 1;
x_pos = display->x_pos;
y_pos = display->y_pos;
- if ((y_pos & 1) != top_bottom)
- y_pos++;
+ y_pos += top_bottom;
while (buf < buf_end) {
- if (x_pos > region->width || y_pos > region->height) {
- av_log(avctx, AV_LOG_ERROR, "Invalid object location!\n");
+ if ((*buf!=0xf0 && x_pos >= region->width) || y_pos >= region->height) {
+ av_log(avctx, AV_LOG_ERROR, "Invalid object location! %d-%d %d-%d %02x\n", x_pos, region->width, y_pos, region->height, *buf);
return;
}
@@ -785,9 +818,9 @@ static void dvbsub_parse_pixel_data_block(AVCodecContext *avctx, DVBSubObjectDis
else
map_table = NULL;
- x_pos += dvbsub_read_2bit_string(pbuf + (y_pos * region->width) + x_pos,
- region->width - x_pos, &buf, buf_end - buf,
- non_mod, map_table);
+ x_pos = dvbsub_read_2bit_string(pbuf + (y_pos * region->width),
+ region->width, &buf, buf_end - buf,
+ non_mod, map_table, x_pos);
break;
case 0x11:
if (region->depth < 4) {
@@ -800,9 +833,9 @@ static void dvbsub_parse_pixel_data_block(AVCodecContext *avctx, DVBSubObjectDis
else
map_table = NULL;
- x_pos += dvbsub_read_4bit_string(pbuf + (y_pos * region->width) + x_pos,
- region->width - x_pos, &buf, buf_end - buf,
- non_mod, map_table);
+ x_pos = dvbsub_read_4bit_string(pbuf + (y_pos * region->width),
+ region->width, &buf, buf_end - buf,
+ non_mod, map_table, x_pos);
break;
case 0x12:
if (region->depth < 8) {
@@ -810,9 +843,9 @@ static void dvbsub_parse_pixel_data_block(AVCodecContext *avctx, DVBSubObjectDis
return;
}
- x_pos += dvbsub_read_8bit_string(pbuf + (y_pos * region->width) + x_pos,
- region->width - x_pos, &buf, buf_end - buf,
- non_mod, NULL);
+ x_pos = dvbsub_read_8bit_string(pbuf + (y_pos * region->width),
+ region->width, &buf, buf_end - buf,
+ non_mod, NULL, x_pos);
break;
case 0x20:
@@ -847,7 +880,6 @@ static void dvbsub_parse_object_segment(AVCodecContext *avctx,
DVBSubContext *ctx = avctx->priv_data;
const uint8_t *buf_end = buf + buf_size;
- const uint8_t *block;
int object_id;
DVBSubObject *object;
DVBSubObjectDisplay *display;
@@ -878,7 +910,8 @@ static void dvbsub_parse_object_segment(AVCodecContext *avctx,
}
for (display = object->display_list; display; display = display->object_list_next) {
- block = buf;
+ const uint8_t *block = buf;
+ int bfl = bottom_field_len;
dvbsub_parse_pixel_data_block(avctx, display, block, top_field_len, 0,
non_modifying_color);
@@ -886,9 +919,9 @@ static void dvbsub_parse_object_segment(AVCodecContext *avctx,
if (bottom_field_len > 0)
block = buf + top_field_len;
else
- bottom_field_len = top_field_len;
+ bfl = top_field_len;
- dvbsub_parse_pixel_data_block(avctx, display, block, bottom_field_len, 1,
+ dvbsub_parse_pixel_data_block(avctx, display, block, bfl, 1,
non_modifying_color);
}
@@ -907,6 +940,7 @@ static void dvbsub_parse_clut_segment(AVCodecContext *avctx,
const uint8_t *buf_end = buf + buf_size;
int i, clut_id;
+ int version;
DVBSubCLUT *clut;
int entry_id, depth , full_range;
int y, cr, cb, alpha;
@@ -924,6 +958,7 @@ static void dvbsub_parse_clut_segment(AVCodecContext *avctx,
av_dlog(avctx, "\n");
clut_id = *buf++;
+ version = ((*buf)>>4)&15;
buf += 1;
clut = get_clut(ctx, clut_id);
@@ -934,11 +969,16 @@ static void dvbsub_parse_clut_segment(AVCodecContext *avctx,
memcpy(clut, &default_clut, sizeof(DVBSubCLUT));
clut->id = clut_id;
+ clut->version = -1;
clut->next = ctx->clut_list;
ctx->clut_list = clut;
}
+ if (clut->version != version) {
+
+ clut->version = version;
+
while (buf + 4 < buf_end) {
entry_id = *buf++;
@@ -980,6 +1020,7 @@ static void dvbsub_parse_clut_segment(AVCodecContext *avctx,
if (depth & 0x20)
clut->clut256[entry_id] = RGBA(r,g,b,255 - alpha);
}
+ }
}
@@ -990,6 +1031,7 @@ static void dvbsub_parse_region_segment(AVCodecContext *avctx,
const uint8_t *buf_end = buf + buf_size;
int region_id, object_id;
+ int version;
DVBSubRegion *region;
DVBSubObject *object;
DVBSubObjectDisplay *display;
@@ -1006,11 +1048,13 @@ static void dvbsub_parse_region_segment(AVCodecContext *avctx,
region = av_mallocz(sizeof(DVBSubRegion));
region->id = region_id;
+ region->version = -1;
region->next = ctx->region_list;
ctx->region_list = region;
}
+ version = ((*buf)>>4) & 15;
fill = ((*buf++) >> 3) & 1;
region->width = AV_RB16(buf);
@@ -1026,6 +1070,7 @@ static void dvbsub_parse_region_segment(AVCodecContext *avctx,
region->pbuf = av_malloc(region->buf_size);
fill = 1;
+ region->dirty = 0;
}
region->depth = 1 << (((*buf++) >> 2) & 7);
@@ -1035,9 +1080,10 @@ static void dvbsub_parse_region_segment(AVCodecContext *avctx,
}
region->clut = *buf++;
- if (region->depth == 8)
+ if (region->depth == 8) {
region->bgcolor = *buf++;
- else {
+ buf += 1;
+ } else {
buf += 1;
if (region->depth == 4)
@@ -1104,17 +1150,27 @@ static void dvbsub_parse_page_segment(AVCodecContext *avctx,
const uint8_t *buf_end = buf + buf_size;
int region_id;
int page_state;
+ int timeout;
+ int version;
if (buf_size < 1)
return;
- ctx->time_out = *buf++;
+ timeout = *buf++;
+ version = ((*buf)>>4) & 15;
page_state = ((*buf++) >> 2) & 3;
+ if (ctx->version != version) {
+
+ ctx->time_out = timeout;
+ ctx->version = version;
+
av_dlog(avctx, "Page time out %ds, state %d\n", ctx->time_out, page_state);
- if (page_state == 2) {
- delete_state(ctx);
+ if (page_state == 1 || page_state == 2) {
+ delete_regions(ctx);
+ delete_objects(ctx);
+ delete_cluts(ctx);
}
tmp_display_list = ctx->display_list;
@@ -1159,6 +1215,7 @@ static void dvbsub_parse_page_segment(AVCodecContext *avctx,
av_free(display);
}
+ }
}
@@ -1312,10 +1369,7 @@ static int dvbsub_display_end_segment(AVCodecContext *avctx, const uint8_t *buf,
int i;
int offset_x=0, offset_y=0;
- sub->rects = NULL;
- sub->start_display_time = 0;
sub->end_display_time = ctx->time_out * 1000;
- sub->format = 0;
if (display_def) {
offset_x = display_def->x;
@@ -1328,22 +1382,24 @@ static int dvbsub_display_end_segment(AVCodecContext *avctx, const uint8_t *buf,
sub->rects = av_mallocz(sizeof(*sub->rects) * sub->num_rects);
for(i=0; i<sub->num_rects; i++)
sub->rects[i] = av_mallocz(sizeof(*sub->rects[i]));
- }
i = 0;
for (display = ctx->display_list; display; display = display->next) {
region = get_region(ctx, display->region_id);
- rect = sub->rects[i];
if (!region)
continue;
+ if (!region->dirty)
+ continue;
+
+ rect = sub->rects[i];
rect->x = display->x_pos + offset_x;
rect->y = display->y_pos + offset_y;
rect->w = region->width;
rect->h = region->height;
- rect->nb_colors = 16;
+ rect->nb_colors = (1 << region->depth);
rect->type = SUBTITLE_BITMAP;
rect->pict.linesize[0] = region->width;
@@ -1375,7 +1431,7 @@ static int dvbsub_display_end_segment(AVCodecContext *avctx, const uint8_t *buf,
}
sub->num_rects = i;
-
+ }
#ifdef DEBUG
save_display_set(ctx);
#endif
@@ -1446,6 +1502,7 @@ static int dvbsub_decode(AVCodecContext *avctx,
break;
case DVBSUB_DISPLAYDEFINITION_SEGMENT:
dvbsub_parse_display_definition_segment(avctx, p, segment_length);
+ break;
case DVBSUB_DISPLAY_SEGMENT:
*data_size = dvbsub_display_end_segment(avctx, p, segment_length, sub);
break;
@@ -1464,13 +1521,12 @@ static int dvbsub_decode(AVCodecContext *avctx,
AVCodec ff_dvbsub_decoder = {
- "dvbsub",
- AVMEDIA_TYPE_SUBTITLE,
- CODEC_ID_DVB_SUBTITLE,
- sizeof(DVBSubContext),
- dvbsub_init_decoder,
- NULL,
- dvbsub_close_decoder,
- dvbsub_decode,
+ .name = "dvbsub",
+ .type = AVMEDIA_TYPE_SUBTITLE,
+ .id = CODEC_ID_DVB_SUBTITLE,
+ .priv_data_size = sizeof(DVBSubContext),
+ .init = dvbsub_init_decoder,
+ .close = dvbsub_close_decoder,
+ .decode = dvbsub_decode,
.long_name = NULL_IF_CONFIG_SMALL("DVB subtitles"),
};
diff --git a/libavcodec/dvdata.c b/libavcodec/dvdata.c
index a80d2da803..b29f5ce53f 100644
--- a/libavcodec/dvdata.c
+++ b/libavcodec/dvdata.c
@@ -2,20 +2,20 @@
* Constants for DV codec
* Copyright (c) 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -25,6 +25,7 @@
*/
#include "libavutil/rational.h"
+#include "libavutil/intreadwrite.h"
#include "avcodec.h"
#include "dvdata.h"
@@ -245,20 +246,25 @@ static const DVprofile dv_profiles[] = {
}
};
-const DVprofile* ff_dv_frame_profile(const DVprofile *sys,
+const DVprofile* avpriv_dv_frame_profile2(AVCodecContext* codec, const DVprofile *sys,
const uint8_t* frame, unsigned buf_size)
{
- int i;
+ int i, dsf, stype;
- int dsf = (frame[3] & 0x80) >> 7;
+ if(buf_size < DV_PROFILE_BYTES)
+ return NULL;
- int stype = frame[80*5 + 48 + 3] & 0x1f;
+ dsf = (frame[3] & 0x80) >> 7;
+ stype = frame[80*5 + 48 + 3] & 0x1f;
/* 576i50 25Mbps 4:1:1 is a special case */
if (dsf == 1 && stype == 0 && frame[4] & 0x07 /* the APT field */) {
return &dv_profiles[2];
}
+ if(codec && codec->codec_tag==AV_RL32("dvsd") && codec->width==720 && codec->height==576)
+ return &dv_profiles[1];
+
for (i=0; i<FF_ARRAY_ELEMS(dv_profiles); i++)
if (dsf == dv_profiles[i].dsf && stype == dv_profiles[i].video_stype)
return &dv_profiles[i];
@@ -270,7 +276,13 @@ const DVprofile* ff_dv_frame_profile(const DVprofile *sys,
return NULL;
}
-const DVprofile* ff_dv_codec_profile(AVCodecContext* codec)
+const DVprofile* avpriv_dv_frame_profile(const DVprofile *sys,
+ const uint8_t* frame, unsigned buf_size)
+{
+ return avpriv_dv_frame_profile2(NULL, sys, frame, buf_size);
+}
+
+const DVprofile* avpriv_dv_codec_profile(AVCodecContext* codec)
{
int i;
diff --git a/libavcodec/dvdata.h b/libavcodec/dvdata.h
index 817b50639f..557e744b8e 100644
--- a/libavcodec/dvdata.h
+++ b/libavcodec/dvdata.h
@@ -2,20 +2,20 @@
* Constants for DV codec
* Copyright (c) 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -274,9 +274,11 @@ enum dv_pack_type {
*/
#define DV_MAX_BPM 8
-const DVprofile* ff_dv_frame_profile(const DVprofile *sys,
+const DVprofile* avpriv_dv_frame_profile(const DVprofile *sys,
const uint8_t* frame, unsigned buf_size);
-const DVprofile* ff_dv_codec_profile(AVCodecContext* codec);
+const DVprofile* avpriv_dv_frame_profile2(AVCodecContext* codec, const DVprofile *sys,
+ const uint8_t* frame, unsigned buf_size);
+const DVprofile* avpriv_dv_codec_profile(AVCodecContext* codec);
static inline int dv_write_dif_id(enum dv_section_type t, uint8_t chan_num,
uint8_t seq_num, uint8_t dif_num,
diff --git a/libavcodec/dvdsub_parser.c b/libavcodec/dvdsub_parser.c
index 5b07de60df..3bbf0dcb8b 100644
--- a/libavcodec/dvdsub_parser.c
+++ b/libavcodec/dvdsub_parser.c
@@ -2,20 +2,20 @@
* DVD subtitle decoding for ffmpeg
* Copyright (c) 2005 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/dvdsubdec.c b/libavcodec/dvdsubdec.c
index 8f3ba63229..021d30dfe7 100644
--- a/libavcodec/dvdsubdec.c
+++ b/libavcodec/dvdsubdec.c
@@ -2,20 +2,20 @@
* DVD subtitle decoding for ffmpeg
* Copyright (c) 2005 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avcodec.h"
@@ -25,6 +25,14 @@
//#define DEBUG
+typedef struct DVDSubContext
+{
+ uint32_t palette[16];
+ int has_palette;
+ uint8_t colormap[4];
+ uint8_t alpha[256];
+} DVDSubContext;
+
static void yuv_a_to_rgba(const uint8_t *ycbcr, const uint8_t *alpha, uint32_t *rgba, int num_values)
{
uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
@@ -116,12 +124,27 @@ static int decode_rle(uint8_t *bitmap, int linesize, int w, int h,
}
static void guess_palette(uint32_t *rgba_palette,
- uint8_t *colormap,
- uint8_t *alpha,
+ DVDSubContext* ctx,
uint32_t subtitle_color)
{
+ static const uint8_t level_map[4][4] = {
+ // this configuration (full range, lowest to highest) in tests
+ // seemed most common, so assume this
+ {0xff},
+ {0x00, 0xff},
+ {0x00, 0x80, 0xff},
+ {0x00, 0x55, 0xaa, 0xff},
+ };
uint8_t color_used[16];
int nb_opaque_colors, i, level, j, r, g, b;
+ uint8_t *colormap = ctx->colormap, *alpha = ctx->alpha;
+
+ if(ctx->has_palette) {
+ for(i = 0; i < 4; i++)
+ rgba_palette[i] = (ctx->palette[colormap[i]] & 0x00ffffff)
+ | ((alpha[i] * 17) << 24);
+ return;
+ }
for(i = 0; i < 4; i++)
rgba_palette[i] = 0;
@@ -138,18 +161,18 @@ static void guess_palette(uint32_t *rgba_palette,
if (nb_opaque_colors == 0)
return;
- j = nb_opaque_colors;
+ j = 0;
memset(color_used, 0, 16);
for(i = 0; i < 4; i++) {
if (alpha[i] != 0) {
if (!color_used[colormap[i]]) {
- level = (0xff * j) / nb_opaque_colors;
+ level = level_map[nb_opaque_colors][j];
r = (((subtitle_color >> 16) & 0xff) * level) >> 8;
g = (((subtitle_color >> 8) & 0xff) * level) >> 8;
b = (((subtitle_color >> 0) & 0xff) * level) >> 8;
rgba_palette[i] = b | (g << 8) | (r << 16) | ((alpha[i] * 17) << 24);
color_used[colormap[i]] = (i + 1);
- j--;
+ j++;
} else {
rgba_palette[i] = (rgba_palette[color_used[colormap[i]] - 1] & 0x00ffffff) |
((alpha[i] * 17) << 24);
@@ -160,20 +183,19 @@ static void guess_palette(uint32_t *rgba_palette,
#define READ_OFFSET(a) (big_offsets ? AV_RB32(a) : AV_RB16(a))
-static int decode_dvd_subtitles(AVSubtitle *sub_header,
+static int decode_dvd_subtitles(DVDSubContext *ctx, AVSubtitle *sub_header,
const uint8_t *buf, int buf_size)
{
int cmd_pos, pos, cmd, x1, y1, x2, y2, offset1, offset2, next_cmd_pos;
int big_offsets, offset_size, is_8bit = 0;
const uint8_t *yuv_palette = 0;
- uint8_t colormap[4], alpha[256];
+ uint8_t *colormap = ctx->colormap, *alpha = ctx->alpha;
int date;
int i;
int is_menu = 0;
if (buf_size < 10)
return -1;
- memset(sub_header, 0, sizeof(*sub_header));
if (AV_RB16(buf) == 0) { /* HD subpicture with 4-byte offsets */
big_offsets = 1;
@@ -326,8 +348,8 @@ static int decode_dvd_subtitles(AVSubtitle *sub_header,
yuv_a_to_rgba(yuv_palette, alpha, (uint32_t*)sub_header->rects[0]->pict.data[1], 256);
} else {
sub_header->rects[0]->nb_colors = 4;
- guess_palette((uint32_t*)sub_header->rects[0]->pict.data[1],
- colormap, alpha, 0xffff00);
+ guess_palette((uint32_t*)sub_header->rects[0]->pict.data[1], ctx,
+ 0xffff00);
}
sub_header->rects[0]->x = x1;
sub_header->rects[0]->y = y1;
@@ -337,6 +359,10 @@ static int decode_dvd_subtitles(AVSubtitle *sub_header,
sub_header->rects[0]->pict.linesize[0] = w;
}
}
+ if (next_cmd_pos < cmd_pos) {
+ av_log(NULL, AV_LOG_ERROR, "Invalid command offset\n");
+ break;
+ }
if (next_cmd_pos == cmd_pos)
break;
cmd_pos = next_cmd_pos;
@@ -458,12 +484,13 @@ static int dvdsub_decode(AVCodecContext *avctx,
void *data, int *data_size,
AVPacket *avpkt)
{
+ DVDSubContext *ctx = (DVDSubContext*) avctx->priv_data;
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
AVSubtitle *sub = data;
int is_menu;
- is_menu = decode_dvd_subtitles(sub, buf, buf_size);
+ is_menu = decode_dvd_subtitles(ctx, sub, buf, buf_size);
if (is_menu < 0) {
no_subtitle:
@@ -486,14 +513,58 @@ static int dvdsub_decode(AVCodecContext *avctx,
return buf_size;
}
+static int dvdsub_init(AVCodecContext *avctx)
+{
+ DVDSubContext *ctx = (DVDSubContext*) avctx->priv_data;
+ char *dataorig, *data;
+
+ if (!avctx->extradata || !avctx->extradata_size)
+ return 1;
+
+ dataorig = data = av_malloc(avctx->extradata_size+1);
+ if (!data)
+ return AVERROR(ENOMEM);
+ memcpy(data, avctx->extradata, avctx->extradata_size);
+ data[avctx->extradata_size] = '\0';
+
+ for(;;) {
+ int pos = strcspn(data, "\n\r");
+ if (pos==0 && *data==0)
+ break;
+
+ if (strncmp("palette:", data, 8) == 0) {
+ int i;
+ char *p = data+8;
+ ctx->has_palette = 1;
+ for(i=0;i<16;i++) {
+ ctx->palette[i] = strtoul(p, &p, 16);
+ while(*p == ',' || isspace(*p))
+ p++;
+ }
+ }
+
+ data += pos;
+ data += strspn(data, "\n\r");
+ }
+
+ if (ctx->has_palette) {
+ int i;
+ av_log(avctx, AV_LOG_DEBUG, "palette:");
+ for(i=0;i<16;i++)
+ av_log(avctx, AV_LOG_DEBUG, " 0x%06x", ctx->palette[i]);
+ av_log(avctx, AV_LOG_DEBUG, "\n");
+ }
+
+ av_free(dataorig);
+ return 1;
+}
+
AVCodec ff_dvdsub_decoder = {
- "dvdsub",
- AVMEDIA_TYPE_SUBTITLE,
- CODEC_ID_DVD_SUBTITLE,
- 0,
- NULL,
- NULL,
- NULL,
- dvdsub_decode,
+ .name = "dvdsub",
+ .type = AVMEDIA_TYPE_SUBTITLE,
+ .id = CODEC_ID_DVD_SUBTITLE,
+ .priv_data_size = sizeof(DVDSubContext),
+ .init = dvdsub_init,
+ .decode = dvdsub_decode,
.long_name = NULL_IF_CONFIG_SMALL("DVD subtitles"),
};
diff --git a/libavcodec/dvdsubenc.c b/libavcodec/dvdsubenc.c
index 71c5e792d0..1aa6ce7b78 100644
--- a/libavcodec/dvdsubenc.c
+++ b/libavcodec/dvdsubenc.c
@@ -2,20 +2,20 @@
* DVD subtitle encoding for ffmpeg
* Copyright (c) 2005 Wolfram Gloger
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avcodec.h"
@@ -216,11 +216,9 @@ static int dvdsub_encode(AVCodecContext *avctx,
}
AVCodec ff_dvdsub_encoder = {
- "dvdsub",
- AVMEDIA_TYPE_SUBTITLE,
- CODEC_ID_DVD_SUBTITLE,
- 0,
- NULL,
- dvdsub_encode,
+ .name = "dvdsub",
+ .type = AVMEDIA_TYPE_SUBTITLE,
+ .id = CODEC_ID_DVD_SUBTITLE,
+ .encode = dvdsub_encode,
.long_name = NULL_IF_CONFIG_SMALL("DVD subtitles"),
};
diff --git a/libavcodec/dwt.c b/libavcodec/dwt.c
index 2c5b56ca48..d9d58de8b2 100644
--- a/libavcodec/dwt.c
+++ b/libavcodec/dwt.c
@@ -1,20 +1,20 @@
/*
* Copyright (C) 2004-2010 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/dwt.h b/libavcodec/dwt.h
index fc73fe7e8e..b10e4f5596 100644
--- a/libavcodec/dwt.h
+++ b/libavcodec/dwt.h
@@ -1,20 +1,20 @@
/*
* Copyright (C) 2004-2010 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/dxa.c b/libavcodec/dxa.c
index 75f3212232..b3bdae5c55 100644
--- a/libavcodec/dxa.c
+++ b/libavcodec/dxa.c
@@ -2,20 +2,20 @@
* Feeble Files/ScummVM DXA decoder
* Copyright (c) 2007 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -295,6 +295,9 @@ static av_cold int decode_init(AVCodecContext *avctx)
c->avctx = avctx;
avctx->pix_fmt = PIX_FMT_PAL8;
+ avcodec_get_frame_defaults(&c->pic);
+ avcodec_get_frame_defaults(&c->prev);
+
c->dsize = avctx->width * avctx->height * 2;
if((c->decomp_buf = av_malloc(c->dsize)) == NULL) {
av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n");
@@ -318,15 +321,14 @@ static av_cold int decode_end(AVCodecContext *avctx)
}
AVCodec ff_dxa_decoder = {
- "dxa",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_DXA,
- sizeof(DxaDecContext),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- CODEC_CAP_DR1,
+ .name = "dxa",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_DXA,
+ .priv_data_size = sizeof(DxaDecContext),
+ .init = decode_init,
+ .close = decode_end,
+ .decode = decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Feeble Files/ScummVM DXA"),
};
diff --git a/libavcodec/dxva2.c b/libavcodec/dxva2.c
index 25b021ae11..b6f8aea429 100644
--- a/libavcodec/dxva2.c
+++ b/libavcodec/dxva2.c
@@ -3,20 +3,20 @@
*
* copyright (c) 2010 Laurent Aimar
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -24,7 +24,7 @@
void *ff_dxva2_get_surface(const Picture *picture)
{
- return picture->data[3];
+ return picture->f.data[3];
}
unsigned ff_dxva2_get_surface_index(const struct dxva_context *ctx,
diff --git a/libavcodec/dxva2.h b/libavcodec/dxva2.h
index 5db5d0bc9f..6eb494b9fe 100644
--- a/libavcodec/dxva2.h
+++ b/libavcodec/dxva2.h
@@ -3,20 +3,20 @@
*
* copyright (c) 2009 Laurent Aimar
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -27,9 +27,11 @@
#include <dxva2api.h>
+#define FF_DXVA2_WORKAROUND_SCALING_LIST_ZIGZAG 1 ///< Work around for DXVA2 and old UVD/UVD+ ATI video cards
+
/**
* This structure is used to provides the necessary configurations and data
- * to the DXVA2 Libav HWAccel implementation.
+ * to the DXVA2 FFmpeg HWAccel implementation.
*
* The application must make it available as AVCodecContext.hwaccel_context.
*/
@@ -60,7 +62,7 @@ struct dxva_context {
uint64_t workaround;
/**
- * Private to the Libav AVHWAccel implementation
+ * Private to the FFmpeg AVHWAccel implementation
*/
unsigned report_id;
};
diff --git a/libavcodec/dxva2_h264.c b/libavcodec/dxva2_h264.c
index 8de4c51082..a707e63a54 100644
--- a/libavcodec/dxva2_h264.c
+++ b/libavcodec/dxva2_h264.c
@@ -3,20 +3,20 @@
*
* copyright (c) 2009 Laurent Aimar
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -70,15 +70,15 @@ static void fill_picture_parameters(struct dxva_context *ctx, const H264Context
ff_dxva2_get_surface_index(ctx, r),
r->long_ref != 0);
- if ((r->reference & PICT_TOP_FIELD) && r->field_poc[0] != INT_MAX)
+ if ((r->f.reference & PICT_TOP_FIELD) && r->field_poc[0] != INT_MAX)
pp->FieldOrderCntList[i][0] = r->field_poc[0];
- if ((r->reference & PICT_BOTTOM_FIELD) && r->field_poc[1] != INT_MAX)
+ if ((r->f.reference & PICT_BOTTOM_FIELD) && r->field_poc[1] != INT_MAX)
pp->FieldOrderCntList[i][1] = r->field_poc[1];
pp->FrameNumList[i] = r->long_ref ? r->pic_id : r->frame_num;
- if (r->reference & PICT_TOP_FIELD)
+ if (r->f.reference & PICT_TOP_FIELD)
pp->UsedForReferenceFlags |= 1 << (2*i + 0);
- if (r->reference & PICT_BOTTOM_FIELD)
+ if (r->f.reference & PICT_BOTTOM_FIELD)
pp->UsedForReferenceFlags |= 1 << (2*i + 1);
} else {
pp->RefFrameList[i].bPicEntry = 0xff;
@@ -95,7 +95,7 @@ static void fill_picture_parameters(struct dxva_context *ctx, const H264Context
pp->wBitFields = ((s->picture_structure != PICT_FRAME) << 0) |
(h->sps.mb_aff << 1) |
(h->sps.residual_color_transform_flag << 2) |
- /* sp_for_switch_flag (not implemented by Libav) */
+ /* sp_for_switch_flag (not implemented by FFmpeg) */
(0 << 3) |
(h->sps.chroma_format_idc << 4) |
((h->nal_ref_idc != 0) << 6) |
@@ -113,7 +113,10 @@ static void fill_picture_parameters(struct dxva_context *ctx, const H264Context
pp->bit_depth_luma_minus8 = h->sps.bit_depth_luma - 8;
pp->bit_depth_chroma_minus8 = h->sps.bit_depth_chroma - 8;
- pp->Reserved16Bits = 3; /* FIXME is there a way to detect the right mode ? */
+ if (ctx->workaround & FF_DXVA2_WORKAROUND_SCALING_LIST_ZIGZAG)
+ pp->Reserved16Bits = 0;
+ else
+ pp->Reserved16Bits = 3; /* FIXME is there a way to detect the right mode ? */
pp->StatusReportFeedbackNumber = 1 + ctx->report_id++;
pp->CurrFieldOrderCnt[0] = 0;
if ((s->picture_structure & PICT_TOP_FIELD) &&
@@ -146,21 +149,33 @@ static void fill_picture_parameters(struct dxva_context *ctx, const H264Context
pp->deblocking_filter_control_present_flag = h->pps.deblocking_filter_parameters_present;
pp->redundant_pic_cnt_present_flag= h->pps.redundant_pic_cnt_present;
pp->Reserved8BitsB = 0;
- pp->slice_group_change_rate_minus1= 0; /* XXX not implemented by Libav */
- //pp->SliceGroupMap[810]; /* XXX not implemented by Libav */
+ pp->slice_group_change_rate_minus1= 0; /* XXX not implemented by FFmpeg */
+ //pp->SliceGroupMap[810]; /* XXX not implemented by FFmpeg */
}
-static void fill_scaling_lists(const H264Context *h, DXVA_Qmatrix_H264 *qm)
+static void fill_scaling_lists(struct dxva_context *ctx, const H264Context *h, DXVA_Qmatrix_H264 *qm)
{
unsigned i, j;
memset(qm, 0, sizeof(*qm));
- for (i = 0; i < 6; i++)
- for (j = 0; j < 16; j++)
- qm->bScalingLists4x4[i][j] = h->pps.scaling_matrix4[i][zigzag_scan[j]];
+ if (ctx->workaround & FF_DXVA2_WORKAROUND_SCALING_LIST_ZIGZAG) {
+ for (i = 0; i < 6; i++)
+ for (j = 0; j < 16; j++)
+ qm->bScalingLists4x4[i][j] = h->pps.scaling_matrix4[i][j];
+
+ for (i = 0; i < 64; i++) {
+ qm->bScalingLists8x8[0][i] = h->pps.scaling_matrix8[0][i];
+ qm->bScalingLists8x8[1][i] = h->pps.scaling_matrix8[3][i];
+ }
+ } else {
+ for (i = 0; i < 6; i++)
+ for (j = 0; j < 16; j++)
+ qm->bScalingLists4x4[i][j] = h->pps.scaling_matrix4[i][zigzag_scan[j]];
- for (i = 0; i < 2; i++)
- for (j = 0; j < 64; j++)
- qm->bScalingLists8x8[i][j] = h->pps.scaling_matrix8[i][ff_zigzag_direct[j]];
+ for (i = 0; i < 64; i++) {
+ qm->bScalingLists8x8[0][i] = h->pps.scaling_matrix8[0][ff_zigzag_direct[i]];
+ qm->bScalingLists8x8[1][i] = h->pps.scaling_matrix8[3][ff_zigzag_direct[i]];
+ }
+ }
}
static int is_slice_short(struct dxva_context *ctx)
@@ -216,7 +231,7 @@ static void fill_slice_long(AVCodecContext *avctx, DXVA_Slice_H264_Long *slice,
unsigned plane;
fill_picture_entry(&slice->RefPicList[list][i],
ff_dxva2_get_surface_index(ctx, r),
- r->reference == PICT_BOTTOM_FIELD);
+ r->f.reference == PICT_BOTTOM_FIELD);
for (plane = 0; plane < 3; plane++) {
int w, o;
if (plane == 0 && h->luma_weight_flag[list]) {
@@ -243,7 +258,7 @@ static void fill_slice_long(AVCodecContext *avctx, DXVA_Slice_H264_Long *slice,
}
}
}
- slice->slice_qs_delta = 0; /* XXX not implemented by Libav */
+ slice->slice_qs_delta = 0; /* XXX not implemented by FFmpeg */
slice->slice_qp_delta = s->qscale - h->pps.init_qp;
slice->redundant_pic_cnt = h->redundant_pic_count;
if (h->slice_type == AV_PICTURE_TYPE_B)
@@ -265,7 +280,7 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx,
const unsigned mb_count = s->mb_width * s->mb_height;
struct dxva_context *ctx = avctx->hwaccel_context;
const Picture *current_picture = h->s.current_picture_ptr;
- struct dxva2_picture_context *ctx_pic = current_picture->hwaccel_picture_private;
+ struct dxva2_picture_context *ctx_pic = current_picture->f.hwaccel_picture_private;
DXVA_Slice_H264_Short *slice = NULL;
uint8_t *dxva_data, *current, *end;
unsigned dxva_size;
@@ -360,7 +375,7 @@ static int start_frame(AVCodecContext *avctx,
{
const H264Context *h = avctx->priv_data;
struct dxva_context *ctx = avctx->hwaccel_context;
- struct dxva2_picture_context *ctx_pic = h->s.current_picture_ptr->hwaccel_picture_private;
+ struct dxva2_picture_context *ctx_pic = h->s.current_picture_ptr->f.hwaccel_picture_private;
if (!ctx->decoder || !ctx->cfg || ctx->surface_count <= 0)
return -1;
@@ -370,7 +385,7 @@ static int start_frame(AVCodecContext *avctx,
fill_picture_parameters(ctx, h, &ctx_pic->pp);
/* Fill up DXVA_Qmatrix_H264 */
- fill_scaling_lists(h, &ctx_pic->qm);
+ fill_scaling_lists(ctx, h, &ctx_pic->qm);
ctx_pic->slice_count = 0;
ctx_pic->bitstream_size = 0;
@@ -384,7 +399,7 @@ static int decode_slice(AVCodecContext *avctx,
const H264Context *h = avctx->priv_data;
struct dxva_context *ctx = avctx->hwaccel_context;
const Picture *current_picture = h->s.current_picture_ptr;
- struct dxva2_picture_context *ctx_pic = current_picture->hwaccel_picture_private;
+ struct dxva2_picture_context *ctx_pic = current_picture->f.hwaccel_picture_private;
unsigned position;
if (ctx_pic->slice_count >= MAX_SLICES)
@@ -413,7 +428,7 @@ static int end_frame(AVCodecContext *avctx)
H264Context *h = avctx->priv_data;
MpegEncContext *s = &h->s;
struct dxva2_picture_context *ctx_pic =
- h->s.current_picture_ptr->hwaccel_picture_private;
+ h->s.current_picture_ptr->f.hwaccel_picture_private;
if (ctx_pic->slice_count <= 0 || ctx_pic->bitstream_size <= 0)
return -1;
diff --git a/libavcodec/dxva2_internal.h b/libavcodec/dxva2_internal.h
index 57fc7bd6f9..23d4d87522 100644
--- a/libavcodec/dxva2_internal.h
+++ b/libavcodec/dxva2_internal.h
@@ -3,20 +3,20 @@
*
* copyright (c) 2010 Laurent Aimar
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/dxva2_mpeg2.c b/libavcodec/dxva2_mpeg2.c
index f14aabd540..02065744ce 100644
--- a/libavcodec/dxva2_mpeg2.c
+++ b/libavcodec/dxva2_mpeg2.c
@@ -3,20 +3,20 @@
*
* copyright (c) 2010 Laurent Aimar
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -151,7 +151,7 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx,
const struct MpegEncContext *s = avctx->priv_data;
struct dxva_context *ctx = avctx->hwaccel_context;
struct dxva2_picture_context *ctx_pic =
- s->current_picture_ptr->hwaccel_picture_private;
+ s->current_picture_ptr->f.hwaccel_picture_private;
const int is_field = s->picture_structure != PICT_FRAME;
const unsigned mb_count = s->mb_width * (s->mb_height >> is_field);
uint8_t *dxva_data, *current, *end;
@@ -210,7 +210,7 @@ static int start_frame(AVCodecContext *avctx,
const struct MpegEncContext *s = avctx->priv_data;
struct dxva_context *ctx = avctx->hwaccel_context;
struct dxva2_picture_context *ctx_pic =
- s->current_picture_ptr->hwaccel_picture_private;
+ s->current_picture_ptr->f.hwaccel_picture_private;
if (!ctx->decoder || !ctx->cfg || ctx->surface_count <= 0)
return -1;
@@ -230,7 +230,7 @@ static int decode_slice(AVCodecContext *avctx,
{
const struct MpegEncContext *s = avctx->priv_data;
struct dxva2_picture_context *ctx_pic =
- s->current_picture_ptr->hwaccel_picture_private;
+ s->current_picture_ptr->f.hwaccel_picture_private;
unsigned position;
if (ctx_pic->slice_count >= MAX_SLICES)
@@ -250,7 +250,7 @@ static int end_frame(AVCodecContext *avctx)
{
struct MpegEncContext *s = avctx->priv_data;
struct dxva2_picture_context *ctx_pic =
- s->current_picture_ptr->hwaccel_picture_private;
+ s->current_picture_ptr->f.hwaccel_picture_private;
if (ctx_pic->slice_count <= 0 || ctx_pic->bitstream_size <= 0)
return -1;
diff --git a/libavcodec/dxva2_vc1.c b/libavcodec/dxva2_vc1.c
index 112d7df785..2bdd0cc6c7 100644
--- a/libavcodec/dxva2_vc1.c
+++ b/libavcodec/dxva2_vc1.c
@@ -3,20 +3,20 @@
*
* copyright (c) 2010 Laurent Aimar
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -161,7 +161,7 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx,
const VC1Context *v = avctx->priv_data;
struct dxva_context *ctx = avctx->hwaccel_context;
const MpegEncContext *s = &v->s;
- struct dxva2_picture_context *ctx_pic = s->current_picture_ptr->hwaccel_picture_private;
+ struct dxva2_picture_context *ctx_pic = s->current_picture_ptr->f.hwaccel_picture_private;
DXVA_SliceInfo *slice = &ctx_pic->si;
@@ -213,7 +213,7 @@ static int start_frame(AVCodecContext *avctx,
{
const VC1Context *v = avctx->priv_data;
struct dxva_context *ctx = avctx->hwaccel_context;
- struct dxva2_picture_context *ctx_pic = v->s.current_picture_ptr->hwaccel_picture_private;
+ struct dxva2_picture_context *ctx_pic = v->s.current_picture_ptr->f.hwaccel_picture_private;
if (!ctx->decoder || !ctx->cfg || ctx->surface_count <= 0)
return -1;
@@ -231,7 +231,7 @@ static int decode_slice(AVCodecContext *avctx,
{
const VC1Context *v = avctx->priv_data;
const Picture *current_picture = v->s.current_picture_ptr;
- struct dxva2_picture_context *ctx_pic = current_picture->hwaccel_picture_private;
+ struct dxva2_picture_context *ctx_pic = current_picture->f.hwaccel_picture_private;
if (ctx_pic->bitstream_size > 0)
return -1;
@@ -252,7 +252,7 @@ static int decode_slice(AVCodecContext *avctx,
static int end_frame(AVCodecContext *avctx)
{
VC1Context *v = avctx->priv_data;
- struct dxva2_picture_context *ctx_pic = v->s.current_picture_ptr->hwaccel_picture_private;
+ struct dxva2_picture_context *ctx_pic = v->s.current_picture_ptr->f.hwaccel_picture_private;
if (ctx_pic->bitstream_size <= 0)
return -1;
diff --git a/libavcodec/eac3dec_data.c b/libavcodec/eac3_data.c
index 4cea26fcb3..b159e1682f 100644
--- a/libavcodec/eac3dec_data.c
+++ b/libavcodec/eac3_data.c
@@ -1,21 +1,21 @@
/*
- * E-AC-3 decoder tables
+ * E-AC-3 tables
* Copyright (c) 2007 Bartlomiej Wolowiec <bartek.wolowiec@gmail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -24,7 +24,7 @@
* Tables taken directly from the E-AC-3 spec.
*/
-#include "eac3dec_data.h"
+#include "eac3_data.h"
#include "ac3.h"
const uint8_t ff_eac3_bits_vs_hebap[20] = {
diff --git a/libavcodec/eac3dec_data.h b/libavcodec/eac3_data.h
index 91892a30d6..10a67f16d2 100644
--- a/libavcodec/eac3dec_data.h
+++ b/libavcodec/eac3_data.h
@@ -1,26 +1,26 @@
/*
- * E-AC-3 decoder tables
+ * E-AC-3 tables
* Copyright (c) 2007 Bartlomiej Wolowiec <bartek.wolowiec@gmail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef AVCODEC_EAC3DEC_DATA_H
-#define AVCODEC_EAC3DEC_DATA_H
+#ifndef AVCODEC_EAC3_DATA_H
+#define AVCODEC_EAC3_DATA_H
#include <stdint.h>
@@ -33,4 +33,4 @@ extern const int16_t (* const ff_eac3_mantissa_vq[8])[6];
extern const uint8_t ff_eac3_frm_expstr[32][6];
extern const float ff_eac3_spx_atten_tab[32][3];
-#endif /* AVCODEC_EAC3DEC_DATA_H */
+#endif /* AVCODEC_EAC3_DATA_H */
diff --git a/libavcodec/eac3dec.c b/libavcodec/eac3dec.c
index 54007686dd..ad240e4341 100644
--- a/libavcodec/eac3dec.c
+++ b/libavcodec/eac3dec.c
@@ -3,20 +3,20 @@
* Copyright (c) 2007 Bartlomiej Wolowiec <bartek.wolowiec@gmail.com>
* Copyright (c) 2008 Justin Ruggles
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -51,7 +51,7 @@
#include "ac3_parser.h"
#include "ac3dec.h"
#include "ac3dec_data.h"
-#include "eac3dec_data.h"
+#include "eac3_data.h"
/** gain adaptive quantization mode */
typedef enum {
diff --git a/libavcodec/eac3enc.c b/libavcodec/eac3enc.c
index f39b9f1925..f3b4418896 100644
--- a/libavcodec/eac3enc.c
+++ b/libavcodec/eac3enc.c
@@ -27,12 +27,63 @@
#define CONFIG_AC3ENC_FLOAT 1
#include "ac3enc.h"
#include "eac3enc.h"
+#include "eac3_data.h"
#define AC3ENC_TYPE AC3ENC_TYPE_EAC3
#include "ac3enc_opts_template.c"
-static AVClass eac3enc_class = { "E-AC-3 Encoder", av_default_item_name,
- eac3_options, LIBAVUTIL_VERSION_INT };
+static const AVClass eac3enc_class = { "E-AC-3 Encoder", av_default_item_name,
+ eac3_options, LIBAVUTIL_VERSION_INT };
+
+
+/**
+ * LUT for finding a matching frame exponent strategy index from a set of
+ * exponent strategies for a single channel across all 6 blocks.
+ */
+static int8_t eac3_frame_expstr_index_tab[3][4][4][4][4][4];
+
+
+void ff_eac3_exponent_init(void)
+{
+ int i;
+
+ memset(eac3_frame_expstr_index_tab, -1, sizeof(eac3_frame_expstr_index_tab));
+ for (i = 0; i < 32; i++) {
+ eac3_frame_expstr_index_tab[ff_eac3_frm_expstr[i][0]-1]
+ [ff_eac3_frm_expstr[i][1]]
+ [ff_eac3_frm_expstr[i][2]]
+ [ff_eac3_frm_expstr[i][3]]
+ [ff_eac3_frm_expstr[i][4]]
+ [ff_eac3_frm_expstr[i][5]] = i;
+ }
+}
+
+
+void ff_eac3_get_frame_exp_strategy(AC3EncodeContext *s)
+{
+ int ch;
+
+ if (s->num_blocks < 6) {
+ s->use_frame_exp_strategy = 0;
+ return;
+ }
+
+ s->use_frame_exp_strategy = 1;
+ for (ch = !s->cpl_on; ch <= s->fbw_channels; ch++) {
+ int expstr = eac3_frame_expstr_index_tab[s->exp_strategy[ch][0]-1]
+ [s->exp_strategy[ch][1]]
+ [s->exp_strategy[ch][2]]
+ [s->exp_strategy[ch][3]]
+ [s->exp_strategy[ch][4]]
+ [s->exp_strategy[ch][5]];
+ if (expstr < 0) {
+ s->use_frame_exp_strategy = 0;
+ break;
+ }
+ s->frame_exp_strategy[ch] = expstr;
+ }
+}
+
void ff_eac3_set_cpl_states(AC3EncodeContext *s)
@@ -43,12 +94,12 @@ void ff_eac3_set_cpl_states(AC3EncodeContext *s)
/* set first cpl coords */
for (ch = 1; ch <= s->fbw_channels; ch++)
first_cpl_coords[ch] = 1;
- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
+ for (blk = 0; blk < s->num_blocks; blk++) {
AC3Block *block = &s->blocks[blk];
for (ch = 1; ch <= s->fbw_channels; ch++) {
if (block->channel_in_cpl[ch]) {
if (first_cpl_coords[ch]) {
- block->new_cpl_coords = 2;
+ block->new_cpl_coords[ch] = 2;
first_cpl_coords[ch] = 0;
}
} else {
@@ -58,7 +109,7 @@ void ff_eac3_set_cpl_states(AC3EncodeContext *s)
}
/* set first cpl leak */
- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
+ for (blk = 0; blk < s->num_blocks; blk++) {
AC3Block *block = &s->blocks[blk];
if (block->cpl_in_use) {
block->new_cpl_leak = 2;
@@ -84,22 +135,64 @@ void ff_eac3_output_frame_header(AC3EncodeContext *s)
put_bits(&s->pb, 2, s->bit_alloc.sr_code); /* sample rate code */
} else {
put_bits(&s->pb, 2, s->bit_alloc.sr_code); /* sample rate code */
- put_bits(&s->pb, 2, 0x3); /* number of blocks = 6 */
+ put_bits(&s->pb, 2, s->num_blks_code); /* number of blocks */
}
put_bits(&s->pb, 3, s->channel_mode); /* audio coding mode */
put_bits(&s->pb, 1, s->lfe_on); /* LFE channel indicator */
put_bits(&s->pb, 5, s->bitstream_id); /* bitstream id (EAC3=16) */
put_bits(&s->pb, 5, -opt->dialogue_level); /* dialogue normalization level */
put_bits(&s->pb, 1, 0); /* no compression gain */
- put_bits(&s->pb, 1, 0); /* no mixing metadata */
- /* TODO: mixing metadata */
- put_bits(&s->pb, 1, 0); /* no info metadata */
- /* TODO: info metadata */
+ /* mixing metadata*/
+ put_bits(&s->pb, 1, opt->eac3_mixing_metadata);
+ if (opt->eac3_mixing_metadata) {
+ if (s->channel_mode > AC3_CHMODE_STEREO)
+ put_bits(&s->pb, 2, opt->preferred_stereo_downmix);
+ if (s->has_center) {
+ put_bits(&s->pb, 3, s->ltrt_center_mix_level);
+ put_bits(&s->pb, 3, s->loro_center_mix_level);
+ }
+ if (s->has_surround) {
+ put_bits(&s->pb, 3, s->ltrt_surround_mix_level);
+ put_bits(&s->pb, 3, s->loro_surround_mix_level);
+ }
+ if (s->lfe_on)
+ put_bits(&s->pb, 1, 0);
+ put_bits(&s->pb, 1, 0); /* no program scale */
+ put_bits(&s->pb, 1, 0); /* no ext program scale */
+ put_bits(&s->pb, 2, 0); /* no mixing parameters */
+ if (s->channel_mode < AC3_CHMODE_STEREO)
+ put_bits(&s->pb, 1, 0); /* no pan info */
+ put_bits(&s->pb, 1, 0); /* no frame mix config info */
+ }
+ /* info metadata*/
+ put_bits(&s->pb, 1, opt->eac3_info_metadata);
+ if (opt->eac3_info_metadata) {
+ put_bits(&s->pb, 3, s->bitstream_mode);
+ put_bits(&s->pb, 1, opt->copyright);
+ put_bits(&s->pb, 1, opt->original);
+ if (s->channel_mode == AC3_CHMODE_STEREO) {
+ put_bits(&s->pb, 2, opt->dolby_surround_mode);
+ put_bits(&s->pb, 2, opt->dolby_headphone_mode);
+ }
+ if (s->channel_mode >= AC3_CHMODE_2F2R)
+ put_bits(&s->pb, 2, opt->dolby_surround_ex_mode);
+ put_bits(&s->pb, 1, opt->audio_production_info);
+ if (opt->audio_production_info) {
+ put_bits(&s->pb, 5, opt->mixing_level - 80);
+ put_bits(&s->pb, 2, opt->room_type);
+ put_bits(&s->pb, 1, opt->ad_converter_type);
+ }
+ put_bits(&s->pb, 1, 0);
+ }
+ if (s->num_blocks != 6)
+ put_bits(&s->pb, 1, !(s->avctx->frame_number % 6)); /* converter sync flag */
put_bits(&s->pb, 1, 0); /* no additional bit stream info */
/* frame header */
- put_bits(&s->pb, 1, 1); /* exponent strategy syntax = each block */
+ if (s->num_blocks == 6) {
+ put_bits(&s->pb, 1, !s->use_frame_exp_strategy);/* exponent strategy syntax */
put_bits(&s->pb, 1, 0); /* aht enabled = no */
+ }
put_bits(&s->pb, 2, 0); /* snr offset strategy = 1 */
put_bits(&s->pb, 1, 0); /* transient pre-noise processing enabled = no */
put_bits(&s->pb, 1, 0); /* block switch syntax enabled = no */
@@ -112,7 +205,7 @@ void ff_eac3_output_frame_header(AC3EncodeContext *s)
/* coupling strategy use flags */
if (s->channel_mode > AC3_CHMODE_MONO) {
put_bits(&s->pb, 1, s->blocks[0].cpl_in_use);
- for (blk = 1; blk < AC3_MAX_BLOCKS; blk++) {
+ for (blk = 1; blk < s->num_blocks; blk++) {
AC3Block *block = &s->blocks[blk];
put_bits(&s->pb, 1, block->new_cpl_strategy);
if (block->new_cpl_strategy)
@@ -120,21 +213,35 @@ void ff_eac3_output_frame_header(AC3EncodeContext *s)
}
}
/* exponent strategy */
- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++)
- for (ch = !s->blocks[blk].cpl_in_use; ch <= s->fbw_channels; ch++)
- put_bits(&s->pb, 2, s->exp_strategy[ch][blk]);
+ if (s->use_frame_exp_strategy) {
+ for (ch = !s->cpl_on; ch <= s->fbw_channels; ch++)
+ put_bits(&s->pb, 5, s->frame_exp_strategy[ch]);
+ } else {
+ for (blk = 0; blk < s->num_blocks; blk++)
+ for (ch = !s->blocks[blk].cpl_in_use; ch <= s->fbw_channels; ch++)
+ put_bits(&s->pb, 2, s->exp_strategy[ch][blk]);
+ }
if (s->lfe_on) {
- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++)
+ for (blk = 0; blk < s->num_blocks; blk++)
put_bits(&s->pb, 1, s->exp_strategy[s->lfe_channel][blk]);
}
- /* E-AC-3 to AC-3 converter exponent strategy (unfortunately not optional...) */
- for (ch = 1; ch <= s->fbw_channels; ch++)
- put_bits(&s->pb, 5, 0);
+ /* E-AC-3 to AC-3 converter exponent strategy (not optional when num blocks == 6) */
+ if (s->num_blocks != 6) {
+ put_bits(&s->pb, 1, 0);
+ } else {
+ for (ch = 1; ch <= s->fbw_channels; ch++) {
+ if (s->use_frame_exp_strategy)
+ put_bits(&s->pb, 5, s->frame_exp_strategy[ch]);
+ else
+ put_bits(&s->pb, 5, 0);
+ }
+ }
/* snr offsets */
put_bits(&s->pb, 6, s->coarse_snr_offset);
put_bits(&s->pb, 4, s->fine_snr_offset[1]);
/* block start info */
- put_bits(&s->pb, 1, 0);
+ if (s->num_blocks > 1)
+ put_bits(&s->pb, 1, 0);
}
diff --git a/libavcodec/eac3enc.h b/libavcodec/eac3enc.h
index eacb8cf164..a92a24c2fa 100644
--- a/libavcodec/eac3enc.h
+++ b/libavcodec/eac3enc.h
@@ -30,6 +30,16 @@
#include "ac3enc.h"
/**
+ * Initialize E-AC-3 exponent tables.
+ */
+void ff_eac3_exponent_init(void);
+
+/**
+ * Determine frame exponent strategy use and indices.
+ */
+void ff_eac3_get_frame_exp_strategy(AC3EncodeContext *s);
+
+/**
* Set coupling states.
* This determines whether certain flags must be written to the bitstream or
* whether they will be implicitly already known by the decoder.
diff --git a/libavcodec/eacmv.c b/libavcodec/eacmv.c
index c968a3d403..20ec0a2265 100644
--- a/libavcodec/eacmv.c
+++ b/libavcodec/eacmv.c
@@ -2,20 +2,20 @@
* Electronic Arts CMV Video Decoder
* Copyright (c) 2007-2008 Peter Ross
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -43,6 +43,10 @@ typedef struct CmvContext {
static av_cold int cmv_decode_init(AVCodecContext *avctx){
CmvContext *s = avctx->priv_data;
+ avcodec_get_frame_defaults(&s->frame);
+ avcodec_get_frame_defaults(&s->last_frame);
+ avcodec_get_frame_defaults(&s->last2_frame);
+
s->avctx = avctx;
avctx->pix_fmt = PIX_FMT_PAL8;
return 0;
@@ -52,7 +56,7 @@ static void cmv_decode_intra(CmvContext * s, const uint8_t *buf, const uint8_t *
unsigned char *dst = s->frame.data[0];
int i;
- for (i=0; i < s->avctx->height && buf+s->avctx->width<=buf_end; i++) {
+ for (i=0; i < s->avctx->height && buf_end - buf >= s->avctx->width; i++) {
memcpy(dst, buf, s->avctx->width);
dst += s->frame.linesize[0];
buf += s->avctx->width;
@@ -84,7 +88,7 @@ static void cmv_decode_inter(CmvContext * s, const uint8_t *buf, const uint8_t *
i = 0;
for(y=0; y<s->avctx->height/4; y++)
- for(x=0; x<s->avctx->width/4 && buf+i<buf_end; x++) {
+ for(x=0; x<s->avctx->width/4 && buf_end - buf > i; x++) {
if (buf[i]==0xFF) {
unsigned char *dst = s->frame.data[0] + (y*4)*s->frame.linesize[0] + x*4;
if (raw+16<buf_end && *raw==0xFF) { /* intra */
@@ -106,9 +110,10 @@ static void cmv_decode_inter(CmvContext * s, const uint8_t *buf, const uint8_t *
}else{ /* inter using last frame as reference */
int xoffset = (buf[i] & 0xF) - 7;
int yoffset = ((buf[i] >> 4)) - 7;
- cmv_motcomp(s->frame.data[0], s->frame.linesize[0],
- s->last_frame.data[0], s->last_frame.linesize[0],
- x*4, y*4, xoffset, yoffset, s->avctx->width, s->avctx->height);
+ if (s->last_frame.data[0])
+ cmv_motcomp(s->frame.data[0], s->frame.linesize[0],
+ s->last_frame.data[0], s->last_frame.linesize[0],
+ x*4, y*4, xoffset, yoffset, s->avctx->width, s->avctx->height);
}
i++;
}
@@ -118,7 +123,7 @@ static void cmv_process_header(CmvContext *s, const uint8_t *buf, const uint8_t
{
int pal_start, pal_count, i;
- if(buf+16>=buf_end) {
+ if(buf_end - buf < 16) {
av_log(s->avctx, AV_LOG_WARNING, "truncated header\n");
return;
}
@@ -135,7 +140,7 @@ static void cmv_process_header(CmvContext *s, const uint8_t *buf, const uint8_t
pal_count = AV_RL16(&buf[14]);
buf += 16;
- for (i=pal_start; i<pal_start+pal_count && i<AVPALETTE_COUNT && buf+2<buf_end; i++) {
+ for (i=pal_start; i<pal_start+pal_count && i<AVPALETTE_COUNT && buf_end - buf >= 3; i++) {
s->palette[i] = AV_RB24(buf);
buf += 3;
}
@@ -153,6 +158,9 @@ static int cmv_decode_frame(AVCodecContext *avctx,
CmvContext *s = avctx->priv_data;
const uint8_t *buf_end = buf + buf_size;
+ if (buf_end - buf < EA_PREAMBLE_SIZE)
+ return AVERROR_INVALIDDATA;
+
if (AV_RL32(buf)==MVIh_TAG||AV_RB32(buf)==MVIh_TAG) {
cmv_process_header(s, buf+EA_PREAMBLE_SIZE, buf_end);
return buf_size;
@@ -206,14 +214,13 @@ static av_cold int cmv_decode_end(AVCodecContext *avctx){
}
AVCodec ff_eacmv_decoder = {
- "eacmv",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_CMV,
- sizeof(CmvContext),
- cmv_decode_init,
- NULL,
- cmv_decode_end,
- cmv_decode_frame,
- CODEC_CAP_DR1,
+ .name = "eacmv",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_CMV,
+ .priv_data_size = sizeof(CmvContext),
+ .init = cmv_decode_init,
+ .close = cmv_decode_end,
+ .decode = cmv_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Electronic Arts CMV video"),
};
diff --git a/libavcodec/eaidct.c b/libavcodec/eaidct.c
index 9d829c4161..9972e422ed 100644
--- a/libavcodec/eaidct.c
+++ b/libavcodec/eaidct.c
@@ -2,20 +2,20 @@
* Electronic Arts TGQ/TQI/MAD IDCT algorithm
* Copyright (c) 2007-2008 Peter Ross <pross@xvid.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/eamad.c b/libavcodec/eamad.c
index db22781588..b0c42f0222 100644
--- a/libavcodec/eamad.c
+++ b/libavcodec/eamad.c
@@ -2,20 +2,20 @@
* Electronic Arts Madcow Video Decoder
* Copyright (c) 2007-2009 Peter Ross
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -85,15 +85,21 @@ static inline void comp_block(MadContext *t, int mb_x, int mb_y,
{
MpegEncContext *s = &t->s;
if (j < 4) {
+ unsigned offset = (mb_y*16 + ((j&2)<<2) + mv_y)*t->last_frame.linesize[0] + mb_x*16 + ((j&1)<<3) + mv_x;
+ if (offset >= (s->height - 7) * t->last_frame.linesize[0] - 7)
+ return;
comp(t->frame.data[0] + (mb_y*16 + ((j&2)<<2))*t->frame.linesize[0] + mb_x*16 + ((j&1)<<3),
t->frame.linesize[0],
- t->last_frame.data[0] + (mb_y*16 + ((j&2)<<2) + mv_y)*t->last_frame.linesize[0] + mb_x*16 + ((j&1)<<3) + mv_x,
+ t->last_frame.data[0] + offset,
t->last_frame.linesize[0], add);
} else if (!(s->avctx->flags & CODEC_FLAG_GRAY)) {
int index = j - 3;
+ unsigned offset = (mb_y * 8 + (mv_y/2))*t->last_frame.linesize[index] + mb_x * 8 + (mv_x/2);
+ if (offset >= (s->height/2 - 7) * t->last_frame.linesize[index] - 7)
+ return;
comp(t->frame.data[index] + (mb_y*8)*t->frame.linesize[index] + mb_x * 8,
t->frame.linesize[index],
- t->last_frame.data[index] + (mb_y * 8 + (mv_y/2))*t->last_frame.linesize[index] + mb_x * 8 + (mv_x/2),
+ t->last_frame.data[index] + offset,
t->last_frame.linesize[index], add);
}
}
@@ -205,7 +211,8 @@ static void decode_mb(MadContext *t, int inter)
for (j=0; j<6; j++) {
if (mv_map & (1<<j)) { // mv_x and mv_y are guarded by mv_map
int add = 2*decode_motion(&s->gb);
- comp_block(t, s->mb_x, s->mb_y, j, mv_x, mv_y, add);
+ if (t->last_frame.data[0])
+ comp_block(t, s->mb_x, s->mb_y, j, mv_x, mv_y, add);
} else {
s->dsp.clear_block(t->block);
decode_block_intra(t, t->block);
@@ -266,6 +273,8 @@ static int decode_frame(AVCodecContext *avctx,
avcodec_set_dimensions(avctx, s->width, s->height);
if (t->frame.data[0])
avctx->release_buffer(avctx, &t->frame);
+ if (t->last_frame.data[0])
+ avctx->release_buffer(avctx, &t->last_frame);
}
t->frame.reference = 1;
@@ -280,6 +289,7 @@ static int decode_frame(AVCodecContext *avctx,
if (!t->bitstream_buf)
return AVERROR(ENOMEM);
bswap16_buf(t->bitstream_buf, (const uint16_t*)buf, (buf_end-buf)/2);
+ memset((uint8_t*)t->bitstream_buf + (buf_end-buf), 0, FF_INPUT_BUFFER_PADDING_SIZE);
init_get_bits(&s->gb, t->bitstream_buf, 8*(buf_end-buf));
for (s->mb_y=0; s->mb_y < (avctx->height+15)/16; s->mb_y++)
@@ -307,14 +317,13 @@ static av_cold int decode_end(AVCodecContext *avctx)
}
AVCodec ff_eamad_decoder = {
- "eamad",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_MAD,
- sizeof(MadContext),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- CODEC_CAP_DR1,
+ .name = "eamad",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_MAD,
+ .priv_data_size = sizeof(MadContext),
+ .init = decode_init,
+ .close = decode_end,
+ .decode = decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Electronic Arts Madcow Video")
};
diff --git a/libavcodec/eatgq.c b/libavcodec/eatgq.c
index d4f8b8fb5f..95692a471b 100644
--- a/libavcodec/eatgq.c
+++ b/libavcodec/eatgq.c
@@ -2,20 +2,20 @@
* Electronic Arts TGQ Video Decoder
* Copyright (c) 2007-2008 Peter Ross <pross@xvid.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -244,14 +244,13 @@ static av_cold int tgq_decode_end(AVCodecContext *avctx){
}
AVCodec ff_eatgq_decoder = {
- "eatgq",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_TGQ,
- sizeof(TgqContext),
- tgq_decode_init,
- NULL,
- tgq_decode_end,
- tgq_decode_frame,
- CODEC_CAP_DR1,
+ .name = "eatgq",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_TGQ,
+ .priv_data_size = sizeof(TgqContext),
+ .init = tgq_decode_init,
+ .close = tgq_decode_end,
+ .decode = tgq_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Electronic Arts TGQ video"),
};
diff --git a/libavcodec/eatgv.c b/libavcodec/eatgv.c
index ee5c094169..26bf524339 100644
--- a/libavcodec/eatgv.c
+++ b/libavcodec/eatgv.c
@@ -2,20 +2,20 @@
* Electronic Arts TGV Video Decoder
* Copyright (c) 2007-2008 Peter Ross
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -55,6 +55,8 @@ static av_cold int tgv_decode_init(AVCodecContext *avctx){
s->avctx = avctx;
avctx->time_base = (AVRational){1, 15};
avctx->pix_fmt = PIX_FMT_PAL8;
+ avcodec_get_frame_defaults(&s->frame);
+ avcodec_get_frame_defaults(&s->last_frame);
return 0;
}
@@ -72,7 +74,7 @@ static int unpack(const uint8_t *src, const uint8_t *src_end, unsigned char *dst
else
src += 2;
- if (src+3>src_end)
+ if (src_end - src < 3)
return -1;
size = AV_RB24(src);
src += 3;
@@ -136,7 +138,7 @@ static int unpack(const uint8_t *src, const uint8_t *src_end, unsigned char *dst
* @return 0 on success, -1 on critical buffer underflow
*/
static int tgv_decode_inter(TgvContext * s, const uint8_t *buf, const uint8_t *buf_end){
- unsigned char *frame0_end = s->last_frame.data[0] + s->avctx->width*s->last_frame.linesize[0];
+ unsigned last_frame_size = s->avctx->height*s->last_frame.linesize[0];
int num_mvs;
int num_blocks_raw;
int num_blocks_packed;
@@ -146,7 +148,7 @@ static int tgv_decode_inter(TgvContext * s, const uint8_t *buf, const uint8_t *b
int mvbits;
const unsigned char *blocks_raw;
- if(buf+12>buf_end)
+ if(buf_end - buf < 12)
return -1;
num_mvs = AV_RL16(&buf[0]);
@@ -169,7 +171,7 @@ static int tgv_decode_inter(TgvContext * s, const uint8_t *buf, const uint8_t *b
/* read motion vectors */
mvbits = (num_mvs*2*10+31) & ~31;
- if (buf+(mvbits>>3)+16*num_blocks_raw+8*num_blocks_packed>buf_end)
+ if (buf_end - buf < (mvbits>>3)+16*num_blocks_raw+8*num_blocks_packed)
return -1;
init_get_bits(&gb, buf, mvbits);
@@ -205,12 +207,14 @@ static int tgv_decode_inter(TgvContext * s, const uint8_t *buf, const uint8_t *b
int src_stride;
if (vector < num_mvs) {
- src = s->last_frame.data[0] +
- (y*4 + s->mv_codebook[vector][1])*s->last_frame.linesize[0] +
- x*4 + s->mv_codebook[vector][0];
+ unsigned offset =
+ (y*4 + s->mv_codebook[vector][1])*s->last_frame.linesize[0] +
+ x*4 + s->mv_codebook[vector][0];
+
src_stride = s->last_frame.linesize[0];
- if (src+3*src_stride+3>=frame0_end)
+ if (offset >= last_frame_size - (3*src_stride+3))
continue;
+ src = s->last_frame.data[0] + offset;
}else{
int offset = vector - num_mvs;
if (offset<num_blocks_raw)
@@ -250,12 +254,15 @@ static int tgv_decode_frame(AVCodecContext *avctx,
const uint8_t *buf_end = buf + buf_size;
int chunk_type;
+ if (buf_end - buf < EA_PREAMBLE_SIZE)
+ return AVERROR_INVALIDDATA;
+
chunk_type = AV_RL32(&buf[0]);
buf += EA_PREAMBLE_SIZE;
if (chunk_type==kVGT_TAG) {
int pal_count, i;
- if(buf+12>buf_end) {
+ if(buf_end - buf < 12) {
av_log(avctx, AV_LOG_WARNING, "truncated header\n");
return -1;
}
@@ -270,7 +277,7 @@ static int tgv_decode_frame(AVCodecContext *avctx,
pal_count = AV_RL16(&buf[6]);
buf += 12;
- for(i=0; i<pal_count && i<AVPALETTE_COUNT && buf+2<buf_end; i++) {
+ for(i=0; i<pal_count && i<AVPALETTE_COUNT && buf_end - buf >= 3; i++) {
s->palette[i] = AV_RB24(buf);
buf += 3;
}
@@ -335,13 +342,12 @@ static av_cold int tgv_decode_end(AVCodecContext *avctx)
}
AVCodec ff_eatgv_decoder = {
- "eatgv",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_TGV,
- sizeof(TgvContext),
- tgv_decode_init,
- NULL,
- tgv_decode_end,
- tgv_decode_frame,
+ .name = "eatgv",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_TGV,
+ .priv_data_size = sizeof(TgvContext),
+ .init = tgv_decode_init,
+ .close = tgv_decode_end,
+ .decode = tgv_decode_frame,
.long_name = NULL_IF_CONFIG_SMALL("Electronic Arts TGV video"),
};
diff --git a/libavcodec/eatqi.c b/libavcodec/eatqi.c
index aa96437013..a1ad8147dc 100644
--- a/libavcodec/eatqi.c
+++ b/libavcodec/eatqi.c
@@ -2,30 +2,28 @@
* Electronic Arts TQI Video Decoder
* Copyright (c) 2007-2009 Peter Ross <pross@xvid.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* Electronic Arts TQI Video Decoder
- * by Peter Ross <pross@xvid.org>
- *
- * Technical details here:
- * http://wiki.multimedia.cx/index.php?title=Electronic_Arts_TQI
+ * @author Peter Ross <pross@xvid.org>
+ * @see http://wiki.multimedia.cx/index.php?title=Electronic_Arts_TQI
*/
#include "avcodec.h"
@@ -155,14 +153,13 @@ static av_cold int tqi_decode_end(AVCodecContext *avctx)
}
AVCodec ff_eatqi_decoder = {
- "eatqi",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_TQI,
- sizeof(TqiContext),
- tqi_decode_init,
- NULL,
- tqi_decode_end,
- tqi_decode_frame,
- CODEC_CAP_DR1,
+ .name = "eatqi",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_TQI,
+ .priv_data_size = sizeof(TqiContext),
+ .init = tqi_decode_init,
+ .close = tqi_decode_end,
+ .decode = tqi_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Electronic Arts TQI Video"),
};
diff --git a/libavcodec/elbg.c b/libavcodec/elbg.c
index 030c3a68c4..ede863e9be 100644
--- a/libavcodec/elbg.c
+++ b/libavcodec/elbg.c
@@ -1,20 +1,20 @@
/*
* Copyright (C) 2007 Vitor Sessak <vitor1001@gmail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/elbg.h b/libavcodec/elbg.h
index b8ea489b24..e6f577e3e5 100644
--- a/libavcodec/elbg.h
+++ b/libavcodec/elbg.h
@@ -1,20 +1,20 @@
/*
* Copyright (C) 2007 Vitor Sessak <vitor1001@gmail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/error_resilience.c b/libavcodec/error_resilience.c
index 8906b49c80..cf967bf215 100644
--- a/libavcodec/error_resilience.c
+++ b/libavcodec/error_resilience.c
@@ -3,20 +3,20 @@
*
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -41,9 +41,9 @@
#undef mb_intra
static void decode_mb(MpegEncContext *s, int ref){
- s->dest[0] = s->current_picture.data[0] + (s->mb_y * 16* s->linesize ) + s->mb_x * 16;
- s->dest[1] = s->current_picture.data[1] + (s->mb_y * (16>>s->chroma_y_shift) * s->uvlinesize) + s->mb_x * (16>>s->chroma_x_shift);
- s->dest[2] = s->current_picture.data[2] + (s->mb_y * (16>>s->chroma_y_shift) * s->uvlinesize) + s->mb_x * (16>>s->chroma_x_shift);
+ s->dest[0] = s->current_picture.f.data[0] + (s->mb_y * 16 * s->linesize) + s->mb_x * 16;
+ s->dest[1] = s->current_picture.f.data[1] + (s->mb_y * (16 >> s->chroma_y_shift) * s->uvlinesize) + s->mb_x * (16 >> s->chroma_x_shift);
+ s->dest[2] = s->current_picture.f.data[2] + (s->mb_y * (16 >> s->chroma_y_shift) * s->uvlinesize) + s->mb_x * (16 >> s->chroma_x_shift);
if(CONFIG_H264_DECODER && s->codec_id == CODEC_ID_H264){
H264Context *h= (void*)s;
@@ -52,7 +52,7 @@ static void decode_mb(MpegEncContext *s, int ref){
assert(ref>=0);
if(ref >= h->ref_count[0]) //FIXME it is posible albeit uncommon that slice references differ between slices, we take the easy approuch and ignore it for now. If this turns out to have any relevance in practice then correct remapping should be added
ref=0;
- fill_rectangle(&s->current_picture.ref_index[0][4*h->mb_xy], 2, 2, 2, ref, 1);
+ fill_rectangle(&s->current_picture.f.ref_index[0][4*h->mb_xy], 2, 2, 2, ref, 1);
fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, ref, 1);
fill_rectangle(h->mv_cache[0][ scan8[0] ], 4, 4, 8, pack16to32(s->mv[0][0][0],s->mv[0][0][1]), 4);
assert(!FRAME_MBAFF);
@@ -166,14 +166,14 @@ static void guess_dc(MpegEncContext *s, int16_t *dc, int w, int h, int stride, i
error= s->error_status_table[mb_index];
- if(IS_INTER(s->current_picture.mb_type[mb_index])) continue; //inter
+ if(IS_INTER(s->current_picture.f.mb_type[mb_index])) continue; //inter
if(!(error&DC_ERROR)) continue; //dc-ok
/* right block */
for(j=b_x+1; j<w; j++){
int mb_index_j= (j>>is_luma) + (b_y>>is_luma)*s->mb_stride;
int error_j= s->error_status_table[mb_index_j];
- int intra_j= IS_INTRA(s->current_picture.mb_type[mb_index_j]);
+ int intra_j = IS_INTRA(s->current_picture.f.mb_type[mb_index_j]);
if(intra_j==0 || !(error_j&DC_ERROR)){
color[0]= dc[j + b_y*stride];
distance[0]= j-b_x;
@@ -185,7 +185,7 @@ static void guess_dc(MpegEncContext *s, int16_t *dc, int w, int h, int stride, i
for(j=b_x-1; j>=0; j--){
int mb_index_j= (j>>is_luma) + (b_y>>is_luma)*s->mb_stride;
int error_j= s->error_status_table[mb_index_j];
- int intra_j= IS_INTRA(s->current_picture.mb_type[mb_index_j]);
+ int intra_j = IS_INTRA(s->current_picture.f.mb_type[mb_index_j]);
if(intra_j==0 || !(error_j&DC_ERROR)){
color[1]= dc[j + b_y*stride];
distance[1]= b_x-j;
@@ -197,7 +197,7 @@ static void guess_dc(MpegEncContext *s, int16_t *dc, int w, int h, int stride, i
for(j=b_y+1; j<h; j++){
int mb_index_j= (b_x>>is_luma) + (j>>is_luma)*s->mb_stride;
int error_j= s->error_status_table[mb_index_j];
- int intra_j= IS_INTRA(s->current_picture.mb_type[mb_index_j]);
+ int intra_j = IS_INTRA(s->current_picture.f.mb_type[mb_index_j]);
if(intra_j==0 || !(error_j&DC_ERROR)){
color[2]= dc[b_x + j*stride];
distance[2]= j-b_y;
@@ -209,7 +209,7 @@ static void guess_dc(MpegEncContext *s, int16_t *dc, int w, int h, int stride, i
for(j=b_y-1; j>=0; j--){
int mb_index_j= (b_x>>is_luma) + (j>>is_luma)*s->mb_stride;
int error_j= s->error_status_table[mb_index_j];
- int intra_j= IS_INTRA(s->current_picture.mb_type[mb_index_j]);
+ int intra_j = IS_INTRA(s->current_picture.f.mb_type[mb_index_j]);
if(intra_j==0 || !(error_j&DC_ERROR)){
color[3]= dc[b_x + j*stride];
distance[3]= b_y-j;
@@ -248,13 +248,13 @@ static void h_block_filter(MpegEncContext *s, uint8_t *dst, int w, int h, int st
int y;
int left_status = s->error_status_table[( b_x >>is_luma) + (b_y>>is_luma)*s->mb_stride];
int right_status= s->error_status_table[((b_x+1)>>is_luma) + (b_y>>is_luma)*s->mb_stride];
- int left_intra= IS_INTRA(s->current_picture.mb_type [( b_x >>is_luma) + (b_y>>is_luma)*s->mb_stride]);
- int right_intra= IS_INTRA(s->current_picture.mb_type [((b_x+1)>>is_luma) + (b_y>>is_luma)*s->mb_stride]);
+ int left_intra = IS_INTRA(s->current_picture.f.mb_type[( b_x >> is_luma) + (b_y >> is_luma) * s->mb_stride]);
+ int right_intra = IS_INTRA(s->current_picture.f.mb_type[((b_x + 1) >> is_luma) + (b_y >> is_luma) * s->mb_stride]);
int left_damage = left_status&(DC_ERROR|AC_ERROR|MV_ERROR);
int right_damage= right_status&(DC_ERROR|AC_ERROR|MV_ERROR);
int offset= b_x*8 + b_y*stride*8;
- int16_t *left_mv= s->current_picture.motion_val[0][mvy_stride*b_y + mvx_stride* b_x ];
- int16_t *right_mv= s->current_picture.motion_val[0][mvy_stride*b_y + mvx_stride*(b_x+1)];
+ int16_t *left_mv= s->current_picture.f.motion_val[0][mvy_stride*b_y + mvx_stride* b_x ];
+ int16_t *right_mv= s->current_picture.f.motion_val[0][mvy_stride*b_y + mvx_stride*(b_x+1)];
if(!(left_damage||right_damage)) continue; // both undamaged
@@ -311,13 +311,13 @@ static void v_block_filter(MpegEncContext *s, uint8_t *dst, int w, int h, int st
int x;
int top_status = s->error_status_table[(b_x>>is_luma) + ( b_y >>is_luma)*s->mb_stride];
int bottom_status= s->error_status_table[(b_x>>is_luma) + ((b_y+1)>>is_luma)*s->mb_stride];
- int top_intra= IS_INTRA(s->current_picture.mb_type [(b_x>>is_luma) + ( b_y >>is_luma)*s->mb_stride]);
- int bottom_intra= IS_INTRA(s->current_picture.mb_type [(b_x>>is_luma) + ((b_y+1)>>is_luma)*s->mb_stride]);
+ int top_intra = IS_INTRA(s->current_picture.f.mb_type[(b_x >> is_luma) + ( b_y >> is_luma) * s->mb_stride]);
+ int bottom_intra = IS_INTRA(s->current_picture.f.mb_type[(b_x >> is_luma) + ((b_y + 1) >> is_luma) * s->mb_stride]);
int top_damage = top_status&(DC_ERROR|AC_ERROR|MV_ERROR);
int bottom_damage= bottom_status&(DC_ERROR|AC_ERROR|MV_ERROR);
int offset= b_x*8 + b_y*stride*8;
- int16_t *top_mv= s->current_picture.motion_val[0][mvy_stride* b_y + mvx_stride*b_x];
- int16_t *bottom_mv= s->current_picture.motion_val[0][mvy_stride*(b_y+1) + mvx_stride*b_x];
+ int16_t *top_mv = s->current_picture.f.motion_val[0][mvy_stride * b_y + mvx_stride * b_x];
+ int16_t *bottom_mv = s->current_picture.f.motion_val[0][mvy_stride * (b_y + 1) + mvx_stride * b_x];
if(!(top_damage||bottom_damage)) continue; // both undamaged
@@ -376,12 +376,20 @@ static void guess_mv(MpegEncContext *s){
int f=0;
int error= s->error_status_table[mb_xy];
- if(IS_INTRA(s->current_picture.mb_type[mb_xy])) f=MV_FROZEN; //intra //FIXME check
+ if(IS_INTRA(s->current_picture.f.mb_type[mb_xy])) f=MV_FROZEN; //intra //FIXME check
if(!(error&MV_ERROR)) f=MV_FROZEN; //inter with undamaged MV
fixed[mb_xy]= f;
if(f==MV_FROZEN)
num_avail++;
+ else if(s->last_picture.f.data[0] && s->last_picture.f.motion_val[0]){
+ const int mb_y= mb_xy / s->mb_stride;
+ const int mb_x= mb_xy % s->mb_stride;
+ const int mot_index= (mb_x + mb_y*mot_stride) * mot_step;
+ s->current_picture.f.motion_val[0][mot_index][0]= s->last_picture.f.motion_val[0][mot_index][0];
+ s->current_picture.f.motion_val[0][mot_index][1]= s->last_picture.f.motion_val[0][mot_index][1];
+ s->current_picture.f.ref_index[0][4*mb_xy] = s->last_picture.f.ref_index[0][4*mb_xy];
+ }
}
if((!(s->avctx->error_concealment&FF_EC_GUESS_MVS)) || num_avail <= mb_width/2){
@@ -389,10 +397,10 @@ static void guess_mv(MpegEncContext *s){
for(mb_x=0; mb_x<s->mb_width; mb_x++){
const int mb_xy= mb_x + mb_y*s->mb_stride;
- if(IS_INTRA(s->current_picture.mb_type[mb_xy])) continue;
+ if(IS_INTRA(s->current_picture.f.mb_type[mb_xy])) continue;
if(!(s->error_status_table[mb_xy]&MV_ERROR)) continue;
- s->mv_dir = s->last_picture.data[0] ? MV_DIR_FORWARD : MV_DIR_BACKWARD;
+ s->mv_dir = s->last_picture.f.data[0] ? MV_DIR_FORWARD : MV_DIR_BACKWARD;
s->mb_intra=0;
s->mv_type = MV_TYPE_16X16;
s->mb_skipped=0;
@@ -434,8 +442,8 @@ int score_sum=0;
if((mb_x^mb_y^pass)&1) continue;
if(fixed[mb_xy]==MV_FROZEN) continue;
- assert(!IS_INTRA(s->current_picture.mb_type[mb_xy]));
- assert(s->last_picture_ptr && s->last_picture_ptr->data[0]);
+ assert(!IS_INTRA(s->current_picture.f.mb_type[mb_xy]));
+ assert(s->last_picture_ptr && s->last_picture_ptr->f.data[0]);
j=0;
if(mb_x>0 && fixed[mb_xy-1 ]==MV_FROZEN) j=1;
@@ -454,27 +462,27 @@ int score_sum=0;
none_left=0;
if(mb_x>0 && fixed[mb_xy-1]){
- mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index - mot_step][0];
- mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index - mot_step][1];
- ref [pred_count] = s->current_picture.ref_index[0][4*(mb_xy-1)];
+ mv_predictor[pred_count][0]= s->current_picture.f.motion_val[0][mot_index - mot_step][0];
+ mv_predictor[pred_count][1]= s->current_picture.f.motion_val[0][mot_index - mot_step][1];
+ ref [pred_count] = s->current_picture.f.ref_index[0][4*(mb_xy-1)];
pred_count++;
}
if(mb_x+1<mb_width && fixed[mb_xy+1]){
- mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index + mot_step][0];
- mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index + mot_step][1];
- ref [pred_count] = s->current_picture.ref_index[0][4*(mb_xy+1)];
+ mv_predictor[pred_count][0]= s->current_picture.f.motion_val[0][mot_index + mot_step][0];
+ mv_predictor[pred_count][1]= s->current_picture.f.motion_val[0][mot_index + mot_step][1];
+ ref [pred_count] = s->current_picture.f.ref_index[0][4*(mb_xy+1)];
pred_count++;
}
if(mb_y>0 && fixed[mb_xy-mb_stride]){
- mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index - mot_stride*mot_step][0];
- mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index - mot_stride*mot_step][1];
- ref [pred_count] = s->current_picture.ref_index[0][4*(mb_xy-s->mb_stride)];
+ mv_predictor[pred_count][0]= s->current_picture.f.motion_val[0][mot_index - mot_stride*mot_step][0];
+ mv_predictor[pred_count][1]= s->current_picture.f.motion_val[0][mot_index - mot_stride*mot_step][1];
+ ref [pred_count] = s->current_picture.f.ref_index[0][4*(mb_xy-s->mb_stride)];
pred_count++;
}
if(mb_y+1<mb_height && fixed[mb_xy+mb_stride]){
- mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index + mot_stride*mot_step][0];
- mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index + mot_stride*mot_step][1];
- ref [pred_count] = s->current_picture.ref_index[0][4*(mb_xy+s->mb_stride)];
+ mv_predictor[pred_count][0]= s->current_picture.f.motion_val[0][mot_index + mot_stride*mot_step][0];
+ mv_predictor[pred_count][1]= s->current_picture.f.motion_val[0][mot_index + mot_stride*mot_step][1];
+ ref [pred_count] = s->current_picture.f.ref_index[0][4*(mb_xy+s->mb_stride)];
pred_count++;
}
if(pred_count==0) continue;
@@ -527,23 +535,23 @@ skip_mean_and_median:
/* zero MV */
pred_count++;
- if (!fixed[mb_xy]) {
+ if (!fixed[mb_xy] && 0) {
if (s->avctx->codec_id == CODEC_ID_H264) {
// FIXME
} else {
ff_thread_await_progress((AVFrame *) s->last_picture_ptr,
mb_y, 0);
}
- if (!s->last_picture.motion_val[0] ||
- !s->last_picture.ref_index[0])
+ if (!s->last_picture.f.motion_val[0] ||
+ !s->last_picture.f.ref_index[0])
goto skip_last_mv;
- prev_x = s->last_picture.motion_val[0][mot_index][0];
- prev_y = s->last_picture.motion_val[0][mot_index][1];
- prev_ref = s->last_picture.ref_index[0][4*mb_xy];
+ prev_x = s->last_picture.f.motion_val[0][mot_index][0];
+ prev_y = s->last_picture.f.motion_val[0][mot_index][1];
+ prev_ref = s->last_picture.f.ref_index[0][4*mb_xy];
} else {
- prev_x = s->current_picture.motion_val[0][mot_index][0];
- prev_y = s->current_picture.motion_val[0][mot_index][1];
- prev_ref = s->current_picture.ref_index[0][4*mb_xy];
+ prev_x = s->current_picture.f.motion_val[0][mot_index][0];
+ prev_y = s->current_picture.f.motion_val[0][mot_index][1];
+ prev_ref = s->current_picture.f.ref_index[0][4*mb_xy];
}
/* last MV */
@@ -565,10 +573,10 @@ skip_mean_and_median:
for(j=0; j<pred_count; j++){
int score=0;
- uint8_t *src= s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize;
+ uint8_t *src = s->current_picture.f.data[0] + mb_x*16 + mb_y*16*s->linesize;
- s->current_picture.motion_val[0][mot_index][0]= s->mv[0][0][0]= mv_predictor[j][0];
- s->current_picture.motion_val[0][mot_index][1]= s->mv[0][0][1]= mv_predictor[j][1];
+ s->current_picture.f.motion_val[0][mot_index][0] = s->mv[0][0][0] = mv_predictor[j][0];
+ s->current_picture.f.motion_val[0][mot_index][1] = s->mv[0][0][1] = mv_predictor[j][1];
if(ref[j]<0) //predictor intra or otherwise not available
continue;
@@ -607,8 +615,8 @@ score_sum+= best_score;
for(i=0; i<mot_step; i++)
for(j=0; j<mot_step; j++){
- s->current_picture.motion_val[0][mot_index+i+j*mot_stride][0]= s->mv[0][0][0];
- s->current_picture.motion_val[0][mot_index+i+j*mot_stride][1]= s->mv[0][0][1];
+ s->current_picture.f.motion_val[0][mot_index + i + j * mot_stride][0] = s->mv[0][0][0];
+ s->current_picture.f.motion_val[0][mot_index + i + j * mot_stride][1] = s->mv[0][0][1];
}
decode_mb(s, ref[best_pred]);
@@ -640,7 +648,7 @@ score_sum+= best_score;
static int is_intra_more_likely(MpegEncContext *s){
int is_intra_likely, i, j, undamaged_count, skip_amount, mb_x, mb_y;
- if(!s->last_picture_ptr || !s->last_picture_ptr->data[0]) return 1; //no previous frame available -> use spatial prediction
+ if (!s->last_picture_ptr || !s->last_picture_ptr->f.data[0]) return 1; //no previous frame available -> use spatial prediction
undamaged_count=0;
for(i=0; i<s->mb_num; i++){
@@ -652,7 +660,7 @@ static int is_intra_more_likely(MpegEncContext *s){
if(s->codec_id == CODEC_ID_H264){
H264Context *h= (void*)s;
- if(h->ref_count[0] <= 0 || !h->ref_list[0][0].data[0])
+ if (h->list_count <= 0 || h->ref_count[0] <= 0 || !h->ref_list[0][0].f.data[0])
return 1;
}
@@ -679,8 +687,8 @@ static int is_intra_more_likely(MpegEncContext *s){
if((j%skip_amount) != 0) continue; //skip a few to speed things up
if(s->pict_type==AV_PICTURE_TYPE_I){
- uint8_t *mb_ptr = s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize;
- uint8_t *last_mb_ptr= s->last_picture.data [0] + mb_x*16 + mb_y*16*s->linesize;
+ uint8_t *mb_ptr = s->current_picture.f.data[0] + mb_x*16 + mb_y*16*s->linesize;
+ uint8_t *last_mb_ptr= s->last_picture.f.data [0] + mb_x*16 + mb_y*16*s->linesize;
if (s->avctx->codec_id == CODEC_ID_H264) {
// FIXME
@@ -689,9 +697,10 @@ static int is_intra_more_likely(MpegEncContext *s){
mb_y, 0);
}
is_intra_likely += s->dsp.sad[0](NULL, last_mb_ptr, mb_ptr , s->linesize, 16);
+ // FIXME need await_progress() here
is_intra_likely -= s->dsp.sad[0](NULL, last_mb_ptr, last_mb_ptr+s->linesize*16, s->linesize, 16);
}else{
- if(IS_INTRA(s->current_picture.mb_type[mb_xy]))
+ if (IS_INTRA(s->current_picture.f.mb_type[mb_xy]))
is_intra_likely++;
else
is_intra_likely--;
@@ -793,15 +802,15 @@ void ff_er_frame_end(MpegEncContext *s){
s->picture_structure != PICT_FRAME || // we dont support ER of field pictures yet, though it should not crash if enabled
s->error_count==3*s->mb_width*(s->avctx->skip_top + s->avctx->skip_bottom)) return;
- if(s->current_picture.motion_val[0] == NULL){
+ if (s->current_picture.f.motion_val[0] == NULL) {
av_log(s->avctx, AV_LOG_ERROR, "Warning MVs not available\n");
for(i=0; i<2; i++){
- pic->ref_index[i]= av_mallocz(s->mb_stride * s->mb_height * 4 * sizeof(uint8_t));
+ pic->f.ref_index[i] = av_mallocz(s->mb_stride * s->mb_height * 4 * sizeof(uint8_t));
pic->motion_val_base[i]= av_mallocz((size+4) * 2 * sizeof(uint16_t));
- pic->motion_val[i]= pic->motion_val_base[i]+4;
+ pic->f.motion_val[i] = pic->motion_val_base[i] + 4;
}
- pic->motion_subsample_log2= 3;
+ pic->f.motion_subsample_log2 = 3;
s->current_picture= *s->current_picture_ptr;
}
@@ -816,6 +825,7 @@ void ff_er_frame_end(MpegEncContext *s){
}
}
+#if 1
/* handle overlapping slices */
for(error_type=1; error_type<=3; error_type++){
int end_ok=0;
@@ -836,7 +846,8 @@ void ff_er_frame_end(MpegEncContext *s){
end_ok=0;
}
}
-
+#endif
+#if 1
/* handle slices with partitions of different length */
if(s->partitioned_frame){
int end_ok=0;
@@ -857,7 +868,7 @@ void ff_er_frame_end(MpegEncContext *s){
end_ok=0;
}
}
-
+#endif
/* handle missing slices */
if(s->error_recognition>=4){
int end_ok=1;
@@ -881,6 +892,7 @@ void ff_er_frame_end(MpegEncContext *s){
}
}
+#if 1
/* backward mark errors */
distance=9999999;
for(error_type=1; error_type<=3; error_type++){
@@ -905,6 +917,7 @@ void ff_er_frame_end(MpegEncContext *s){
distance= 9999999;
}
}
+#endif
/* forward mark errors */
error=0;
@@ -919,7 +932,7 @@ void ff_er_frame_end(MpegEncContext *s){
s->error_status_table[mb_xy]|= error;
}
}
-
+#if 1
/* handle not partitioned case */
if(!s->partitioned_frame){
for(i=0; i<s->mb_num; i++){
@@ -930,6 +943,7 @@ void ff_er_frame_end(MpegEncContext *s){
s->error_status_table[mb_xy]= error;
}
}
+#endif
dc_error= ac_error= mv_error=0;
for(i=0; i<s->mb_num; i++){
@@ -951,25 +965,25 @@ void ff_er_frame_end(MpegEncContext *s){
continue;
if(is_intra_likely)
- s->current_picture.mb_type[mb_xy]= MB_TYPE_INTRA4x4;
+ s->current_picture.f.mb_type[mb_xy] = MB_TYPE_INTRA4x4;
else
- s->current_picture.mb_type[mb_xy]= MB_TYPE_16x16 | MB_TYPE_L0;
+ s->current_picture.f.mb_type[mb_xy] = MB_TYPE_16x16 | MB_TYPE_L0;
}
// change inter to intra blocks if no reference frames are available
- if (!s->last_picture.data[0] && !s->next_picture.data[0])
+ if (!s->last_picture.f.data[0] && !s->next_picture.f.data[0])
for(i=0; i<s->mb_num; i++){
const int mb_xy= s->mb_index2xy[i];
- if(!IS_INTRA(s->current_picture.mb_type[mb_xy]))
- s->current_picture.mb_type[mb_xy]= MB_TYPE_INTRA4x4;
+ if (!IS_INTRA(s->current_picture.f.mb_type[mb_xy]))
+ s->current_picture.f.mb_type[mb_xy] = MB_TYPE_INTRA4x4;
}
/* handle inter blocks with damaged AC */
for(mb_y=0; mb_y<s->mb_height; mb_y++){
for(mb_x=0; mb_x<s->mb_width; mb_x++){
const int mb_xy= mb_x + mb_y * s->mb_stride;
- const int mb_type= s->current_picture.mb_type[mb_xy];
- int dir = !s->last_picture.data[0];
+ const int mb_type= s->current_picture.f.mb_type[mb_xy];
+ int dir = !s->last_picture.f.data[0];
error= s->error_status_table[mb_xy];
if(IS_INTRA(mb_type)) continue; //intra
@@ -984,13 +998,13 @@ void ff_er_frame_end(MpegEncContext *s){
int j;
s->mv_type = MV_TYPE_8X8;
for(j=0; j<4; j++){
- s->mv[0][j][0] = s->current_picture.motion_val[dir][ mb_index + (j&1) + (j>>1)*s->b8_stride ][0];
- s->mv[0][j][1] = s->current_picture.motion_val[dir][ mb_index + (j&1) + (j>>1)*s->b8_stride ][1];
+ s->mv[0][j][0] = s->current_picture.f.motion_val[dir][mb_index + (j & 1) + (j >> 1) * s->b8_stride][0];
+ s->mv[0][j][1] = s->current_picture.f.motion_val[dir][mb_index + (j & 1) + (j >> 1) * s->b8_stride][1];
}
}else{
s->mv_type = MV_TYPE_16X16;
- s->mv[0][0][0] = s->current_picture.motion_val[dir][ mb_x*2 + mb_y*2*s->b8_stride ][0];
- s->mv[0][0][1] = s->current_picture.motion_val[dir][ mb_x*2 + mb_y*2*s->b8_stride ][1];
+ s->mv[0][0][0] = s->current_picture.f.motion_val[dir][ mb_x*2 + mb_y*2*s->b8_stride ][0];
+ s->mv[0][0][1] = s->current_picture.f.motion_val[dir][ mb_x*2 + mb_y*2*s->b8_stride ][1];
}
s->dsp.clear_blocks(s->block[0]);
@@ -1007,7 +1021,7 @@ void ff_er_frame_end(MpegEncContext *s){
for(mb_x=0; mb_x<s->mb_width; mb_x++){
int xy= mb_x*2 + mb_y*2*s->b8_stride;
const int mb_xy= mb_x + mb_y * s->mb_stride;
- const int mb_type= s->current_picture.mb_type[mb_xy];
+ const int mb_type= s->current_picture.f.mb_type[mb_xy];
error= s->error_status_table[mb_xy];
if(IS_INTRA(mb_type)) continue;
@@ -1015,8 +1029,8 @@ void ff_er_frame_end(MpegEncContext *s){
if(!(error&AC_ERROR)) continue; //undamaged inter
s->mv_dir = MV_DIR_FORWARD|MV_DIR_BACKWARD;
- if(!s->last_picture.data[0]) s->mv_dir &= ~MV_DIR_FORWARD;
- if(!s->next_picture.data[0]) s->mv_dir &= ~MV_DIR_BACKWARD;
+ if(!s->last_picture.f.data[0]) s->mv_dir &= ~MV_DIR_FORWARD;
+ if(!s->next_picture.f.data[0]) s->mv_dir &= ~MV_DIR_BACKWARD;
s->mb_intra=0;
s->mv_type = MV_TYPE_16X16;
s->mb_skipped=0;
@@ -1031,10 +1045,10 @@ void ff_er_frame_end(MpegEncContext *s){
ff_thread_await_progress((AVFrame *) s->next_picture_ptr,
mb_y, 0);
}
- s->mv[0][0][0] = s->next_picture.motion_val[0][xy][0]*time_pb/time_pp;
- s->mv[0][0][1] = s->next_picture.motion_val[0][xy][1]*time_pb/time_pp;
- s->mv[1][0][0] = s->next_picture.motion_val[0][xy][0]*(time_pb - time_pp)/time_pp;
- s->mv[1][0][1] = s->next_picture.motion_val[0][xy][1]*(time_pb - time_pp)/time_pp;
+ s->mv[0][0][0] = s->next_picture.f.motion_val[0][xy][0] * time_pb / time_pp;
+ s->mv[0][0][1] = s->next_picture.f.motion_val[0][xy][1] * time_pb / time_pp;
+ s->mv[1][0][0] = s->next_picture.f.motion_val[0][xy][0] * (time_pb - time_pp) / time_pp;
+ s->mv[1][0][1] = s->next_picture.f.motion_val[0][xy][1] * (time_pb - time_pp) / time_pp;
}else{
s->mv[0][0][0]= 0;
s->mv[0][0][1]= 0;
@@ -1061,16 +1075,16 @@ void ff_er_frame_end(MpegEncContext *s){
int16_t *dc_ptr;
uint8_t *dest_y, *dest_cb, *dest_cr;
const int mb_xy= mb_x + mb_y * s->mb_stride;
- const int mb_type= s->current_picture.mb_type[mb_xy];
+ const int mb_type = s->current_picture.f.mb_type[mb_xy];
error= s->error_status_table[mb_xy];
if(IS_INTRA(mb_type) && s->partitioned_frame) continue;
// if(error&MV_ERROR) continue; //inter data damaged FIXME is this good?
- dest_y = s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize;
- dest_cb= s->current_picture.data[1] + mb_x*8 + mb_y*8 *s->uvlinesize;
- dest_cr= s->current_picture.data[2] + mb_x*8 + mb_y*8 *s->uvlinesize;
+ dest_y = s->current_picture.f.data[0] + mb_x * 16 + mb_y * 16 * s->linesize;
+ dest_cb = s->current_picture.f.data[1] + mb_x * 8 + mb_y * 8 * s->uvlinesize;
+ dest_cr = s->current_picture.f.data[2] + mb_x * 8 + mb_y * 8 * s->uvlinesize;
dc_ptr= &s->dc_val[0][mb_x*2 + mb_y*2*s->b8_stride];
for(n=0; n<4; n++){
@@ -1096,45 +1110,47 @@ void ff_er_frame_end(MpegEncContext *s){
s->dc_val[2][mb_x + mb_y*s->mb_stride]= (dcv+4)>>3;
}
}
-
+#if 1
/* guess DC for damaged blocks */
guess_dc(s, s->dc_val[0], s->mb_width*2, s->mb_height*2, s->b8_stride, 1);
guess_dc(s, s->dc_val[1], s->mb_width , s->mb_height , s->mb_stride, 0);
guess_dc(s, s->dc_val[2], s->mb_width , s->mb_height , s->mb_stride, 0);
-
+#endif
/* filter luma DC */
filter181(s->dc_val[0], s->mb_width*2, s->mb_height*2, s->b8_stride);
+#if 1
/* render DC only intra */
for(mb_y=0; mb_y<s->mb_height; mb_y++){
for(mb_x=0; mb_x<s->mb_width; mb_x++){
uint8_t *dest_y, *dest_cb, *dest_cr;
const int mb_xy= mb_x + mb_y * s->mb_stride;
- const int mb_type= s->current_picture.mb_type[mb_xy];
+ const int mb_type = s->current_picture.f.mb_type[mb_xy];
error= s->error_status_table[mb_xy];
if(IS_INTER(mb_type)) continue;
if(!(error&AC_ERROR)) continue; //undamaged
- dest_y = s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize;
- dest_cb= s->current_picture.data[1] + mb_x*8 + mb_y*8 *s->uvlinesize;
- dest_cr= s->current_picture.data[2] + mb_x*8 + mb_y*8 *s->uvlinesize;
+ dest_y = s->current_picture.f.data[0] + mb_x * 16 + mb_y * 16 * s->linesize;
+ dest_cb = s->current_picture.f.data[1] + mb_x * 8 + mb_y * 8 * s->uvlinesize;
+ dest_cr = s->current_picture.f.data[2] + mb_x * 8 + mb_y * 8 * s->uvlinesize;
put_dc(s, dest_y, dest_cb, dest_cr, mb_x, mb_y);
}
}
+#endif
if(s->avctx->error_concealment&FF_EC_DEBLOCK){
/* filter horizontal block boundaries */
- h_block_filter(s, s->current_picture.data[0], s->mb_width*2, s->mb_height*2, s->linesize , 1);
- h_block_filter(s, s->current_picture.data[1], s->mb_width , s->mb_height , s->uvlinesize, 0);
- h_block_filter(s, s->current_picture.data[2], s->mb_width , s->mb_height , s->uvlinesize, 0);
+ h_block_filter(s, s->current_picture.f.data[0], s->mb_width*2, s->mb_height*2, s->linesize , 1);
+ h_block_filter(s, s->current_picture.f.data[1], s->mb_width , s->mb_height , s->uvlinesize, 0);
+ h_block_filter(s, s->current_picture.f.data[2], s->mb_width , s->mb_height , s->uvlinesize, 0);
/* filter vertical block boundaries */
- v_block_filter(s, s->current_picture.data[0], s->mb_width*2, s->mb_height*2, s->linesize , 1);
- v_block_filter(s, s->current_picture.data[1], s->mb_width , s->mb_height , s->uvlinesize, 0);
- v_block_filter(s, s->current_picture.data[2], s->mb_width , s->mb_height , s->uvlinesize, 0);
+ v_block_filter(s, s->current_picture.f.data[0], s->mb_width*2, s->mb_height*2, s->linesize , 1);
+ v_block_filter(s, s->current_picture.f.data[1], s->mb_width , s->mb_height , s->uvlinesize, 0);
+ v_block_filter(s, s->current_picture.f.data[2], s->mb_width , s->mb_height , s->uvlinesize, 0);
}
ec_clean:
diff --git a/libavcodec/escape124.c b/libavcodec/escape124.c
index 9d216a4c95..2c86d5f34f 100644
--- a/libavcodec/escape124.c
+++ b/libavcodec/escape124.c
@@ -2,20 +2,20 @@
* Escape 124 Video Decoder
* Copyright (C) 2008 Eli Friedman (eli.friedman@gmail.com)
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -61,6 +61,7 @@ static av_cold int escape124_decode_init(AVCodecContext *avctx)
{
Escape124Context *s = avctx->priv_data;
+ avcodec_get_frame_defaults(&s->frame);
avctx->pix_fmt = PIX_FMT_RGB555;
s->num_superblocks = ((unsigned)avctx->width / 8) *
@@ -214,7 +215,8 @@ static int escape124_decode_frame(AVCodecContext *avctx,
uint16_t* old_frame_data, *new_frame_data;
unsigned old_stride, new_stride;
- AVFrame new_frame = { { 0 } };
+ AVFrame new_frame;
+ avcodec_get_frame_defaults(&new_frame);
init_get_bits(&gb, buf, buf_size * 8);
@@ -364,15 +366,14 @@ static int escape124_decode_frame(AVCodecContext *avctx,
AVCodec ff_escape124_decoder = {
- "escape124",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_ESCAPE124,
- sizeof(Escape124Context),
- escape124_decode_init,
- NULL,
- escape124_decode_close,
- escape124_decode_frame,
- CODEC_CAP_DR1,
+ .name = "escape124",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_ESCAPE124,
+ .priv_data_size = sizeof(Escape124Context),
+ .init = escape124_decode_init,
+ .close = escape124_decode_close,
+ .decode = escape124_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Escape 124"),
};
diff --git a/libavcodec/faandct.h b/libavcodec/faandct.h
index da8c0e42d9..f43b62f168 100644
--- a/libavcodec/faandct.h
+++ b/libavcodec/faandct.h
@@ -2,20 +2,20 @@
* Floating point AAN DCT
* Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/faanidct.c b/libavcodec/faanidct.c
index 0b9b458284..dc3d8fbb81 100644
--- a/libavcodec/faanidct.c
+++ b/libavcodec/faanidct.c
@@ -2,20 +2,20 @@
* Floating point AAN IDCT
* Copyright (c) 2008 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "faanidct.h"
diff --git a/libavcodec/faanidct.h b/libavcodec/faanidct.h
index f3896f7a48..4cf1189286 100644
--- a/libavcodec/faanidct.h
+++ b/libavcodec/faanidct.h
@@ -2,20 +2,20 @@
* Floating point AAN IDCT
* Copyright (c) 2008 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/faxcompr.c b/libavcodec/faxcompr.c
index 79e8d757af..c157b984d3 100644
--- a/libavcodec/faxcompr.c
+++ b/libavcodec/faxcompr.c
@@ -2,26 +2,26 @@
* CCITT Fax Group 3 and 4 decompression
* Copyright (c) 2008 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
- * CCITT Fax Group 3 and 4 decompression
* @file
+ * CCITT Fax Group 3 and 4 decompression
* @author Konstantin Shishkov
*/
#include "avcodec.h"
diff --git a/libavcodec/faxcompr.h b/libavcodec/faxcompr.h
index 4742d15e59..53d11681b2 100644
--- a/libavcodec/faxcompr.h
+++ b/libavcodec/faxcompr.h
@@ -2,26 +2,26 @@
* CCITT Fax Group 3 and 4 decompression
* Copyright (c) 2008 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
- * CCITT Fax Group 3 and 4 decompression
* @file
+ * CCITT Fax Group 3 and 4 decompression
* @author Konstantin Shishkov
*/
#ifndef AVCODEC_FAXCOMPR_H
diff --git a/libavcodec/fft-fixed-test.c b/libavcodec/fft-fixed-test.c
index 63cd194576..fa750b6326 100644
--- a/libavcodec/fft-fixed-test.c
+++ b/libavcodec/fft-fixed-test.c
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFMpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFMpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/fft-internal.h b/libavcodec/fft-internal.h
index d30571b733..61066bb18b 100644
--- a/libavcodec/fft-internal.h
+++ b/libavcodec/fft-internal.h
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/fft-test.c b/libavcodec/fft-test.c
index 59a53ddeb6..be105fe834 100644
--- a/libavcodec/fft-test.c
+++ b/libavcodec/fft-test.c
@@ -1,20 +1,20 @@
/*
* (c) 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/fft.c b/libavcodec/fft.c
index aa34b34152..4eb46f14c8 100644
--- a/libavcodec/fft.c
+++ b/libavcodec/fft.c
@@ -4,20 +4,20 @@
* Copyright (c) 2002 Fabrice Bellard
* Partly based on libdjbfft by D. J. Bernstein
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/fft.h b/libavcodec/fft.h
index 706f94b574..0e19e947b1 100644
--- a/libavcodec/fft.h
+++ b/libavcodec/fft.h
@@ -2,20 +2,20 @@
* Copyright (c) 2000, 2001, 2002 Fabrice Bellard
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/fft_fixed.c b/libavcodec/fft_fixed.c
index b28091d35c..3955efea05 100644
--- a/libavcodec/fft_fixed.c
+++ b/libavcodec/fft_fixed.c
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/fft_float.c b/libavcodec/fft_float.c
index 24c9fdb366..214964631b 100644
--- a/libavcodec/fft_float.c
+++ b/libavcodec/fft_float.c
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c
index 1f1d4d1c62..2b7a928ca0 100644
--- a/libavcodec/ffv1.c
+++ b/libavcodec/ffv1.c
@@ -3,20 +3,20 @@
*
* Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -180,6 +180,7 @@ typedef struct FFV1Context{
int colorspace;
int16_t *sample_buffer;
int gob_count;
+ int packed_at_lsb;
int quant_table_count;
@@ -543,8 +544,14 @@ static void encode_plane(FFV1Context *s, uint8_t *src, int w, int h, int stride,
}
encode_line(s, w, sample, plane_index, 8);
}else{
- for(x=0; x<w; x++){
- sample[0][x]= ((uint16_t*)(src + stride*y))[x] >> (16 - s->avctx->bits_per_raw_sample);
+ if(s->packed_at_lsb){
+ for(x=0; x<w; x++){
+ sample[0][x]= ((uint16_t*)(src + stride*y))[x];
+ }
+ }else{
+ for(x=0; x<w; x++){
+ sample[0][x]= ((uint16_t*)(src + stride*y))[x] >> (16 - s->avctx->bits_per_raw_sample);
+ }
}
encode_line(s, w, sample, plane_index, s->avctx->bits_per_raw_sample);
}
@@ -659,6 +666,8 @@ static av_cold int common_init(AVCodecContext *avctx){
s->avctx= avctx;
s->flags= avctx->flags;
+ avcodec_get_frame_defaults(&s->picture);
+
dsputil_init(&s->dsp, avctx);
s->width = avctx->width;
@@ -898,6 +907,10 @@ static av_cold int encode_init(AVCodecContext *avctx)
avctx->coded_frame= &s->picture;
switch(avctx->pix_fmt){
+ case PIX_FMT_YUV420P9:
+ case PIX_FMT_YUV420P10:
+ case PIX_FMT_YUV422P10:
+ s->packed_at_lsb = 1;
case PIX_FMT_YUV444P16:
case PIX_FMT_YUV422P16:
case PIX_FMT_YUV420P16:
@@ -1061,6 +1074,7 @@ static int encode_slice(AVCodecContext *c, void *arg){
int x= fs->slice_x;
int y= fs->slice_y;
AVFrame * const p= &f->picture;
+ const int ps= (c->bits_per_raw_sample>8)+1;
if(f->colorspace==0){
const int chroma_width = -((-width )>>f->chroma_h_shift);
@@ -1068,12 +1082,12 @@ static int encode_slice(AVCodecContext *c, void *arg){
const int cx= x>>f->chroma_h_shift;
const int cy= y>>f->chroma_v_shift;
- encode_plane(fs, p->data[0] + x + y*p->linesize[0], width, height, p->linesize[0], 0);
+ encode_plane(fs, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0);
- encode_plane(fs, p->data[1] + cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1);
- encode_plane(fs, p->data[2] + cx+cy*p->linesize[2], chroma_width, chroma_height, p->linesize[2], 1);
+ encode_plane(fs, p->data[1] + ps*cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1);
+ encode_plane(fs, p->data[2] + ps*cx+cy*p->linesize[2], chroma_width, chroma_height, p->linesize[2], 1);
}else{
- encode_rgb_frame(fs, (uint32_t*)(p->data[0]) + x + y*(p->linesize[0]/4), width, height, p->linesize[0]/4);
+ encode_rgb_frame(fs, (uint32_t*)(p->data[0]) + ps*x + y*(p->linesize[0]/4), width, height, p->linesize[0]/4);
}
emms_c();
@@ -1327,8 +1341,14 @@ static void decode_plane(FFV1Context *s, uint8_t *src, int w, int h, int stride,
}
}else{
decode_line(s, w, sample, plane_index, s->avctx->bits_per_raw_sample);
- for(x=0; x<w; x++){
- ((uint16_t*)(src + stride*y))[x]= sample[1][x] << (16 - s->avctx->bits_per_raw_sample);
+ if(s->packed_at_lsb){
+ for(x=0; x<w; x++){
+ ((uint16_t*)(src + stride*y))[x]= sample[1][x];
+ }
+ }else{
+ for(x=0; x<w; x++){
+ ((uint16_t*)(src + stride*y))[x]= sample[1][x] << (16 - s->avctx->bits_per_raw_sample);
+ }
}
}
//STOP_TIMER("decode-line")}
@@ -1384,6 +1404,7 @@ static int decode_slice(AVCodecContext *c, void *arg){
int height= fs->slice_height;
int x= fs->slice_x;
int y= fs->slice_y;
+ const int ps= (c->bits_per_raw_sample>8)+1;
AVFrame * const p= &f->picture;
av_assert1(width && height);
@@ -1392,12 +1413,12 @@ static int decode_slice(AVCodecContext *c, void *arg){
const int chroma_height= -((-height)>>f->chroma_v_shift);
const int cx= x>>f->chroma_h_shift;
const int cy= y>>f->chroma_v_shift;
- decode_plane(fs, p->data[0] + x + y*p->linesize[0], width, height, p->linesize[0], 0);
+ decode_plane(fs, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0);
- decode_plane(fs, p->data[1] + cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1);
- decode_plane(fs, p->data[2] + cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[2], 1);
+ decode_plane(fs, p->data[1] + ps*cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1);
+ decode_plane(fs, p->data[2] + ps*cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[2], 1);
}else{
- decode_rgb_frame(fs, (uint32_t*)p->data[0] + x + y*(p->linesize[0]/4), width, height, p->linesize[0]/4);
+ decode_rgb_frame(fs, (uint32_t*)p->data[0] + ps*x + y*(p->linesize[0]/4), width, height, p->linesize[0]/4);
}
emms_c();
@@ -1543,7 +1564,25 @@ static int read_header(FFV1Context *f){
av_log(f->avctx, AV_LOG_ERROR, "format not supported\n");
return -1;
}
- }else{
+ }else if(f->avctx->bits_per_raw_sample==9) {
+ switch(16*f->chroma_h_shift + f->chroma_v_shift){
+ case 0x00: f->avctx->pix_fmt= PIX_FMT_YUV444P16; break;
+ case 0x10: f->avctx->pix_fmt= PIX_FMT_YUV422P16; break;
+ case 0x11: f->avctx->pix_fmt= PIX_FMT_YUV420P9 ; f->packed_at_lsb=1; break;
+ default:
+ av_log(f->avctx, AV_LOG_ERROR, "format not supported\n");
+ return -1;
+ }
+ }else if(f->avctx->bits_per_raw_sample==10) {
+ switch(16*f->chroma_h_shift + f->chroma_v_shift){
+ case 0x00: f->avctx->pix_fmt= PIX_FMT_YUV444P16; break;
+ case 0x10: f->avctx->pix_fmt= PIX_FMT_YUV422P10; f->packed_at_lsb=1; break;
+ case 0x11: f->avctx->pix_fmt= PIX_FMT_YUV420P10; f->packed_at_lsb=1; break;
+ default:
+ av_log(f->avctx, AV_LOG_ERROR, "format not supported\n");
+ return -1;
+ }
+ }else {
switch(16*f->chroma_h_shift + f->chroma_v_shift){
case 0x00: f->avctx->pix_fmt= PIX_FMT_YUV444P16; break;
case 0x10: f->avctx->pix_fmt= PIX_FMT_YUV422P16; break;
@@ -1580,6 +1619,7 @@ static int read_header(FFV1Context *f){
for(j=0; j<f->slice_count; j++){
FFV1Context *fs= f->slice_context[j];
fs->ac= f->ac;
+ fs->packed_at_lsb= f->packed_at_lsb;
if(f->version >= 2){
fs->slice_x = get_symbol(c, state, 0) *f->width ;
@@ -1693,7 +1733,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac
bytes_read = c->bytestream - c->bytestream_start - 1;
if(bytes_read ==0) av_log(avctx, AV_LOG_ERROR, "error at end of AC stream\n"); //FIXME
//printf("pos=%d\n", bytes_read);
- init_get_bits(&f->slice_context[0]->gb, buf + bytes_read, buf_size - bytes_read);
+ init_get_bits(&f->slice_context[0]->gb, buf + bytes_read, (buf_size - bytes_read) * 8);
} else {
bytes_read = 0; /* avoid warning */
}
@@ -1710,7 +1750,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac
if(fs->ac){
ff_init_range_decoder(&fs->c, buf_p, v);
}else{
- init_get_bits(&fs->gb, buf_p, v);
+ init_get_bits(&fs->gb, buf_p, v * 8);
}
}
@@ -1724,30 +1764,28 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac
}
AVCodec ff_ffv1_decoder = {
- "ffv1",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_FFV1,
- sizeof(FFV1Context),
- decode_init,
- NULL,
- common_end,
- decode_frame,
- CODEC_CAP_DR1 /*| CODEC_CAP_DRAW_HORIZ_BAND*/ | CODEC_CAP_SLICE_THREADS,
- NULL,
+ .name = "ffv1",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_FFV1,
+ .priv_data_size = sizeof(FFV1Context),
+ .init = decode_init,
+ .close = common_end,
+ .decode = decode_frame,
+ .capabilities = CODEC_CAP_DR1 /*| CODEC_CAP_DRAW_HORIZ_BAND*/ | CODEC_CAP_SLICE_THREADS,
.long_name= NULL_IF_CONFIG_SMALL("FFmpeg video codec #1"),
};
#if CONFIG_FFV1_ENCODER
AVCodec ff_ffv1_encoder = {
- "ffv1",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_FFV1,
- sizeof(FFV1Context),
- encode_init,
- encode_frame,
- common_end,
+ .name = "ffv1",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_FFV1,
+ .priv_data_size = sizeof(FFV1Context),
+ .init = encode_init,
+ .encode = encode_frame,
+ .close = common_end,
.capabilities = CODEC_CAP_SLICE_THREADS,
- .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_YUV444P, PIX_FMT_YUV422P, PIX_FMT_YUV411P, PIX_FMT_YUV410P, PIX_FMT_RGB32, PIX_FMT_YUV420P16, PIX_FMT_YUV422P16, PIX_FMT_YUV444P16, PIX_FMT_NONE},
+ .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_YUV444P, PIX_FMT_YUV422P, PIX_FMT_YUV411P, PIX_FMT_YUV410P, PIX_FMT_RGB32, PIX_FMT_YUV420P16, PIX_FMT_YUV422P16, PIX_FMT_YUV444P16, PIX_FMT_YUV420P9, PIX_FMT_YUV420P10, PIX_FMT_YUV422P10, PIX_FMT_NONE},
.long_name= NULL_IF_CONFIG_SMALL("FFmpeg video codec #1"),
};
#endif
diff --git a/libavcodec/flac.c b/libavcodec/flac.c
index e6a427af11..5ed3ef7fc3 100644
--- a/libavcodec/flac.c
+++ b/libavcodec/flac.c
@@ -2,26 +2,27 @@
* FLAC common code
* Copyright (c) 2009 Justin Ruggles
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/crc.h"
#include "flac.h"
#include "flacdata.h"
+#include "vorbis.h"
static const int8_t sample_size_table[] = { 0, 8, 12, 0, 16, 20, 24, 0 };
@@ -54,9 +55,12 @@ int ff_flac_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb,
fi->ch_mode = get_bits(gb, 4);
if (fi->ch_mode < FLAC_MAX_CHANNELS) {
fi->channels = fi->ch_mode + 1;
+ if (fi->ch_mode <= 5)
+ avctx->channel_layout = ff_vorbis_channel_layouts[fi->ch_mode];
fi->ch_mode = FLAC_CHMODE_INDEPENDENT;
} else if (fi->ch_mode <= FLAC_CHMODE_MID_SIDE) {
fi->channels = 2;
+ avctx->channel_layout = AV_CH_LAYOUT_STEREO;
} else {
av_log(avctx, AV_LOG_ERROR + log_level_offset,
"invalid channel mode: %d\n", fi->ch_mode);
diff --git a/libavcodec/flac.h b/libavcodec/flac.h
index 6ec8a3752d..65965af6ad 100644
--- a/libavcodec/flac.h
+++ b/libavcodec/flac.h
@@ -2,20 +2,20 @@
* FLAC (Free Lossless Audio Codec) decoder/demuxer common functions
* Copyright (c) 2008 Justin Ruggles
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -95,8 +95,8 @@ typedef struct FLACFrameInfo {
* @param[out] s where parsed information is stored
* @param[in] buffer pointer to start of 34-byte streaminfo data
*/
-void ff_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s,
- const uint8_t *buffer);
+void avpriv_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s,
+ const uint8_t *buffer);
/**
* Validate the FLAC extradata.
@@ -105,9 +105,9 @@ void ff_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s,
* @param[out] streaminfo_start pointer to start of 34-byte STREAMINFO data.
* @return 1 if valid, 0 if not valid.
*/
-int ff_flac_is_extradata_valid(AVCodecContext *avctx,
- enum FLACExtradataFormat *format,
- uint8_t **streaminfo_start);
+int avpriv_flac_is_extradata_valid(AVCodecContext *avctx,
+ enum FLACExtradataFormat *format,
+ uint8_t **streaminfo_start);
/**
* Parse the metadata block parameters from the header.
@@ -116,8 +116,8 @@ int ff_flac_is_extradata_valid(AVCodecContext *avctx,
* @param[out] type metadata block type
* @param[out] size metadata block size
*/
-void ff_flac_parse_block_header(const uint8_t *block_header,
- int *last, int *type, int *size);
+void avpriv_flac_parse_block_header(const uint8_t *block_header,
+ int *last, int *type, int *size);
/**
* Calculate an estimate for the maximum frame size based on verbatim mode.
diff --git a/libavcodec/flac_parser.c b/libavcodec/flac_parser.c
index 947a5b6e15..50ad72b7c0 100644
--- a/libavcodec/flac_parser.c
+++ b/libavcodec/flac_parser.c
@@ -2,20 +2,20 @@
* FLAC parser
* Copyright (c) 2010 Michael Chinen
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/flacdata.c b/libavcodec/flacdata.c
index 820c3aa492..6fcbe3955a 100644
--- a/libavcodec/flacdata.c
+++ b/libavcodec/flacdata.c
@@ -2,20 +2,20 @@
* FLAC data
* Copyright (c) 2003 Alex Beregszaszi
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/flacdata.h b/libavcodec/flacdata.h
index f56637773c..96a50b9183 100644
--- a/libavcodec/flacdata.h
+++ b/libavcodec/flacdata.h
@@ -2,20 +2,20 @@
* FLAC data header
* Copyright (c) 2003 Alex Beregszaszi
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/flacdec.c b/libavcodec/flacdec.c
index 1ce8559de6..cebe3e3e62 100644
--- a/libavcodec/flacdec.c
+++ b/libavcodec/flacdec.c
@@ -2,20 +2,20 @@
* FLAC (Free Lossless Audio Codec) decoder
* Copyright (c) 2003 Alex Beregszaszi
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -23,9 +23,7 @@
* @file
* FLAC (Free Lossless Audio Codec) decoder
* @author Alex Beregszaszi
- *
- * For more information on the FLAC format, visit:
- * http://flac.sourceforge.net/
+ * @see http://flac.sourceforge.net/
*
* This decoder can be used in 1 of 2 ways: Either raw FLAC data can be fed
* through, starting from the initial 'fLaC' signature; or by passing the
@@ -65,7 +63,7 @@ typedef struct FLACContext {
static void allocate_buffers(FLACContext *s);
-int ff_flac_is_extradata_valid(AVCodecContext *avctx,
+int avpriv_flac_is_extradata_valid(AVCodecContext *avctx,
enum FLACExtradataFormat *format,
uint8_t **streaminfo_start)
{
@@ -106,11 +104,11 @@ static av_cold int flac_decode_init(AVCodecContext *avctx)
if (!avctx->extradata)
return 0;
- if (!ff_flac_is_extradata_valid(avctx, &format, &streaminfo))
+ if (!avpriv_flac_is_extradata_valid(avctx, &format, &streaminfo))
return -1;
/* initialize based on the demuxer-supplied streamdata header */
- ff_flac_parse_streaminfo(avctx, (FLACStreaminfo *)s, streaminfo);
+ avpriv_flac_parse_streaminfo(avctx, (FLACStreaminfo *)s, streaminfo);
if (s->bps > 16)
avctx->sample_fmt = AV_SAMPLE_FMT_S32;
else
@@ -142,7 +140,7 @@ static void allocate_buffers(FLACContext *s)
}
}
-void ff_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s,
+void avpriv_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s,
const uint8_t *buffer)
{
GetBitContext gb;
@@ -176,7 +174,7 @@ void ff_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s,
dump_headers(avctx, s);
}
-void ff_flac_parse_block_header(const uint8_t *block_header,
+void avpriv_flac_parse_block_header(const uint8_t *block_header,
int *last, int *type, int *size)
{
int tmp = bytestream_get_byte(&block_header);
@@ -203,12 +201,12 @@ static int parse_streaminfo(FLACContext *s, const uint8_t *buf, int buf_size)
/* need more data */
return 0;
}
- ff_flac_parse_block_header(&buf[4], NULL, &metadata_type, &metadata_size);
+ avpriv_flac_parse_block_header(&buf[4], NULL, &metadata_type, &metadata_size);
if (metadata_type != FLAC_METADATA_TYPE_STREAMINFO ||
metadata_size != FLAC_STREAMINFO_SIZE) {
return AVERROR_INVALIDDATA;
}
- ff_flac_parse_streaminfo(s->avctx, (FLACStreaminfo *)s, &buf[8]);
+ avpriv_flac_parse_streaminfo(s->avctx, (FLACStreaminfo *)s, &buf[8]);
allocate_buffers(s);
s->got_streaminfo = 1;
@@ -228,9 +226,11 @@ static int get_metadata_size(const uint8_t *buf, int buf_size)
buf += 4;
do {
- ff_flac_parse_block_header(buf, &metadata_last, NULL, &metadata_size);
+ if (buf_end - buf < 4)
+ return 0;
+ avpriv_flac_parse_block_header(buf, &metadata_last, NULL, &metadata_size);
buf += 4;
- if (buf + metadata_size > buf_end) {
+ if (buf_end - buf < metadata_size) {
/* need more data in order to read the complete header */
return 0;
}
@@ -654,13 +654,12 @@ static av_cold int flac_decode_close(AVCodecContext *avctx)
}
AVCodec ff_flac_decoder = {
- "flac",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_FLAC,
- sizeof(FLACContext),
- flac_decode_init,
- NULL,
- flac_decode_close,
- flac_decode_frame,
+ .name = "flac",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_FLAC,
+ .priv_data_size = sizeof(FLACContext),
+ .init = flac_decode_init,
+ .close = flac_decode_close,
+ .decode = flac_decode_frame,
.long_name= NULL_IF_CONFIG_SMALL("FLAC (Free Lossless Audio Codec)"),
};
diff --git a/libavcodec/flacenc.c b/libavcodec/flacenc.c
index be775cabd3..7345a7eef0 100644
--- a/libavcodec/flacenc.c
+++ b/libavcodec/flacenc.c
@@ -2,20 +2,20 @@
* FLAC audio encoder
* Copyright (c) 2006 Justin Ruggles <justin.ruggles@gmail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -439,6 +439,28 @@ static av_cold int flac_encode_init(AVCodecContext *avctx)
if (!avctx->coded_frame)
return AVERROR(ENOMEM);
+ if (channels == 3 &&
+ avctx->channel_layout != (AV_CH_LAYOUT_STEREO|AV_CH_FRONT_CENTER) ||
+ channels == 4 &&
+ avctx->channel_layout != AV_CH_LAYOUT_2_2 &&
+ avctx->channel_layout != AV_CH_LAYOUT_QUAD ||
+ channels == 5 &&
+ avctx->channel_layout != AV_CH_LAYOUT_5POINT0 &&
+ avctx->channel_layout != AV_CH_LAYOUT_5POINT0_BACK ||
+ channels == 6 &&
+ avctx->channel_layout != AV_CH_LAYOUT_5POINT1 &&
+ avctx->channel_layout != AV_CH_LAYOUT_5POINT1_BACK) {
+ if (avctx->channel_layout) {
+ av_log(avctx, AV_LOG_ERROR, "Channel layout not supported by Flac, "
+ "output stream will have incorrect "
+ "channel layout.\n");
+ } else {
+ av_log(avctx, AV_LOG_WARNING, "No channel layout specified. The encoder "
+ "will use Flac channel layout for "
+ "%d channels.\n", channels);
+ }
+ }
+
ret = ff_lpc_init(&s->lpc_ctx, avctx->frame_size,
s->options.max_prediction_order, FF_LPC_TYPE_LEVINSON);
@@ -1330,22 +1352,22 @@ static av_cold int flac_encode_close(AVCodecContext *avctx)
#define FLAGS AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM
static const AVOption options[] = {
-{ "lpc_coeff_precision", "LPC coefficient precision", offsetof(FlacEncodeContext, options.lpc_coeff_precision), FF_OPT_TYPE_INT, {.dbl = 15 }, 0, MAX_LPC_PRECISION, FLAGS },
-{ "lpc_type", "LPC algorithm", offsetof(FlacEncodeContext, options.lpc_type), FF_OPT_TYPE_INT, {.dbl = FF_LPC_TYPE_DEFAULT }, FF_LPC_TYPE_DEFAULT, FF_LPC_TYPE_NB-1, FLAGS, "lpc_type" },
-{ "none", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_LPC_TYPE_NONE }, INT_MIN, INT_MAX, FLAGS, "lpc_type" },
-{ "fixed", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_LPC_TYPE_FIXED }, INT_MIN, INT_MAX, FLAGS, "lpc_type" },
-{ "levinson", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_LPC_TYPE_LEVINSON }, INT_MIN, INT_MAX, FLAGS, "lpc_type" },
-{ "cholesky", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_LPC_TYPE_CHOLESKY }, INT_MIN, INT_MAX, FLAGS, "lpc_type" },
-{ "lpc_passes", "Number of passes to use for Cholesky factorization during LPC analysis", offsetof(FlacEncodeContext, options.lpc_passes), FF_OPT_TYPE_INT, {.dbl = -1 }, INT_MIN, INT_MAX, FLAGS },
-{ "min_partition_order", NULL, offsetof(FlacEncodeContext, options.min_partition_order), FF_OPT_TYPE_INT, {.dbl = -1 }, -1, MAX_PARTITION_ORDER, FLAGS },
-{ "max_partition_order", NULL, offsetof(FlacEncodeContext, options.max_partition_order), FF_OPT_TYPE_INT, {.dbl = -1 }, -1, MAX_PARTITION_ORDER, FLAGS },
-{ "prediction_order_method", "Search method for selecting prediction order", offsetof(FlacEncodeContext, options.prediction_order_method), FF_OPT_TYPE_INT, {.dbl = -1 }, -1, ORDER_METHOD_LOG, FLAGS, "predm" },
-{ "estimation", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = ORDER_METHOD_EST }, INT_MIN, INT_MAX, FLAGS, "predm" },
-{ "2level", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = ORDER_METHOD_2LEVEL }, INT_MIN, INT_MAX, FLAGS, "predm" },
-{ "4level", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = ORDER_METHOD_4LEVEL }, INT_MIN, INT_MAX, FLAGS, "predm" },
-{ "8level", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = ORDER_METHOD_8LEVEL }, INT_MIN, INT_MAX, FLAGS, "predm" },
-{ "search", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = ORDER_METHOD_SEARCH }, INT_MIN, INT_MAX, FLAGS, "predm" },
-{ "log", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = ORDER_METHOD_LOG }, INT_MIN, INT_MAX, FLAGS, "predm" },
+{ "lpc_coeff_precision", "LPC coefficient precision", offsetof(FlacEncodeContext, options.lpc_coeff_precision), AV_OPT_TYPE_INT, {.dbl = 15 }, 0, MAX_LPC_PRECISION, FLAGS },
+{ "lpc_type", "LPC algorithm", offsetof(FlacEncodeContext, options.lpc_type), AV_OPT_TYPE_INT, {.dbl = FF_LPC_TYPE_DEFAULT }, FF_LPC_TYPE_DEFAULT, FF_LPC_TYPE_NB-1, FLAGS, "lpc_type" },
+{ "none", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_LPC_TYPE_NONE }, INT_MIN, INT_MAX, FLAGS, "lpc_type" },
+{ "fixed", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_LPC_TYPE_FIXED }, INT_MIN, INT_MAX, FLAGS, "lpc_type" },
+{ "levinson", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_LPC_TYPE_LEVINSON }, INT_MIN, INT_MAX, FLAGS, "lpc_type" },
+{ "cholesky", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_LPC_TYPE_CHOLESKY }, INT_MIN, INT_MAX, FLAGS, "lpc_type" },
+{ "lpc_passes", "Number of passes to use for Cholesky factorization during LPC analysis", offsetof(FlacEncodeContext, options.lpc_passes), AV_OPT_TYPE_INT, {.dbl = -1 }, INT_MIN, INT_MAX, FLAGS },
+{ "min_partition_order", NULL, offsetof(FlacEncodeContext, options.min_partition_order), AV_OPT_TYPE_INT, {.dbl = -1 }, -1, MAX_PARTITION_ORDER, FLAGS },
+{ "max_partition_order", NULL, offsetof(FlacEncodeContext, options.max_partition_order), AV_OPT_TYPE_INT, {.dbl = -1 }, -1, MAX_PARTITION_ORDER, FLAGS },
+{ "prediction_order_method", "Search method for selecting prediction order", offsetof(FlacEncodeContext, options.prediction_order_method), AV_OPT_TYPE_INT, {.dbl = -1 }, -1, ORDER_METHOD_LOG, FLAGS, "predm" },
+{ "estimation", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = ORDER_METHOD_EST }, INT_MIN, INT_MAX, FLAGS, "predm" },
+{ "2level", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = ORDER_METHOD_2LEVEL }, INT_MIN, INT_MAX, FLAGS, "predm" },
+{ "4level", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = ORDER_METHOD_4LEVEL }, INT_MIN, INT_MAX, FLAGS, "predm" },
+{ "8level", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = ORDER_METHOD_8LEVEL }, INT_MIN, INT_MAX, FLAGS, "predm" },
+{ "search", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = ORDER_METHOD_SEARCH }, INT_MIN, INT_MAX, FLAGS, "predm" },
+{ "log", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = ORDER_METHOD_LOG }, INT_MIN, INT_MAX, FLAGS, "predm" },
{ NULL },
};
@@ -1357,15 +1379,14 @@ static const AVClass flac_encoder_class = {
};
AVCodec ff_flac_encoder = {
- "flac",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_FLAC,
- sizeof(FlacEncodeContext),
- flac_encode_init,
- flac_encode_frame,
- flac_encode_close,
- NULL,
- .capabilities = CODEC_CAP_SMALL_LAST_FRAME | CODEC_CAP_DELAY,
+ .name = "flac",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_FLAC,
+ .priv_data_size = sizeof(FlacEncodeContext),
+ .init = flac_encode_init,
+ .encode = flac_encode_frame,
+ .close = flac_encode_close,
+ .capabilities = CODEC_CAP_SMALL_LAST_FRAME | CODEC_CAP_DELAY | CODEC_CAP_LOSSLESS,
.sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
.long_name = NULL_IF_CONFIG_SMALL("FLAC (Free Lossless Audio Codec)"),
.priv_class = &flac_encoder_class,
diff --git a/libavcodec/flashsv.c b/libavcodec/flashsv.c
index a958bdaa53..3861344cb7 100644
--- a/libavcodec/flashsv.c
+++ b/libavcodec/flashsv.c
@@ -3,20 +3,20 @@
* Copyright (C) 2004 Alex Beregszaszi
* Copyright (C) 2006 Benjamin Larsson
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -25,35 +25,29 @@
* Flash Screen Video decoder
* @author Alex Beregszaszi
* @author Benjamin Larsson
- */
-
-/* Bitstream description
- * The picture is divided into blocks that are zlib compressed.
- *
- * The decoder is fed complete frames, the frameheader contains:
- * 4bits of block width
- * 12bits of frame width
- * 4bits of block height
- * 12bits of frame height
+ * @author Daniel Verkamp
+ * @author Konstantin Shishkov
*
- * Directly after the header are the compressed blocks. The blocks
- * have their compressed size represented with 16bits in the beginnig.
- * If the size = 0 then the block is unchanged from the previous frame.
- * All blocks are decompressed until the buffer is consumed.
- *
- * Encoding ideas, a basic encoder would just use a fixed block size.
- * Block sizes can be multipels of 16, from 16 to 256. The blocks don't
- * have to be quadratic. A brute force search with a set of diffrent
- * block sizes should give a better result then to just use a fixed size.
+ * A description of the bitstream format for Flash Screen Video version 1/2
+ * is part of the SWF File Format Specification (version 10), which can be
+ * downloaded from http://www.adobe.com/devnet/swf.html.
*/
#include <stdio.h>
#include <stdlib.h>
#include <zlib.h>
+#include "libavutil/intreadwrite.h"
#include "avcodec.h"
+#include "bytestream.h"
#include "get_bits.h"
+typedef struct BlockInfo {
+ uint8_t *pos;
+ int size;
+ int unp_size;
+} BlockInfo;
+
typedef struct FlashSVContext {
AVCodecContext *avctx;
AVFrame frame;
@@ -62,21 +56,50 @@ typedef struct FlashSVContext {
uint8_t *tmpblock;
int block_size;
z_stream zstream;
+ int ver;
+ const uint32_t *pal;
+ int is_keyframe;
+ uint8_t *keyframedata;
+ uint8_t *keyframe;
+ BlockInfo *blocks;
+ uint8_t *deflate_block;
+ int deflate_block_size;
+ int color_depth;
+ int zlibprime_curr, zlibprime_prev;
+ int diff_start, diff_height;
} FlashSVContext;
-static void copy_region(uint8_t *sptr, uint8_t *dptr,
- int dx, int dy, int h, int w, int stride)
+static int decode_hybrid(const uint8_t *sptr, uint8_t *dptr, int dx, int dy,
+ int h, int w, int stride, const uint32_t *pal)
{
- int i;
-
- for (i = dx + h; i > dx; i--) {
- memcpy(dptr + (i * stride) + dy * 3, sptr, w * 3);
- sptr += w * 3;
+ int x, y;
+ const uint8_t *orig_src = sptr;
+
+ for (y = dx+h; y > dx; y--) {
+ uint8_t *dst = dptr + (y * stride) + dy * 3;
+ for (x = 0; x < w; x++) {
+ if (*sptr & 0x80) {
+ /* 15-bit color */
+ unsigned c = AV_RB16(sptr) & ~0x8000;
+ unsigned b = c & 0x1F;
+ unsigned g = (c >> 5) & 0x1F;
+ unsigned r = c >> 10;
+ /* 000aaabb -> aaabbaaa */
+ *dst++ = (b << 3) | (b >> 2);
+ *dst++ = (g << 3) | (g >> 2);
+ *dst++ = (r << 3) | (r >> 2);
+ sptr += 2;
+ } else {
+ /* palette index */
+ uint32_t c = pal[*sptr++];
+ bytestream_put_le24(&dst, c);
+ }
+ }
}
+ return sptr - orig_src;
}
-
static av_cold int flashsv_decode_init(AVCodecContext *avctx)
{
FlashSVContext *s = avctx->priv_data;
@@ -86,22 +109,127 @@ static av_cold int flashsv_decode_init(AVCodecContext *avctx)
s->zstream.zalloc = Z_NULL;
s->zstream.zfree = Z_NULL;
s->zstream.opaque = Z_NULL;
- zret = inflateInit(&(s->zstream));
+ zret = inflateInit(&s->zstream);
if (zret != Z_OK) {
av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret);
return 1;
}
avctx->pix_fmt = PIX_FMT_BGR24;
+ avcodec_get_frame_defaults(&s->frame);
s->frame.data[0] = NULL;
return 0;
}
+static void flashsv2_prime(FlashSVContext *s, uint8_t *src,
+ int size, int unp_size)
+{
+ z_stream zs;
+
+ zs.zalloc = NULL;
+ zs.zfree = NULL;
+ zs.opaque = NULL;
+
+ s->zstream.next_in = src;
+ s->zstream.avail_in = size;
+ s->zstream.next_out = s->tmpblock;
+ s->zstream.avail_out = s->block_size * 3;
+ inflate(&s->zstream, Z_SYNC_FLUSH);
+
+ deflateInit(&zs, 0);
+ zs.next_in = s->tmpblock;
+ zs.avail_in = s->block_size * 3 - s->zstream.avail_out;
+ zs.next_out = s->deflate_block;
+ zs.avail_out = s->deflate_block_size;
+ deflate(&zs, Z_SYNC_FLUSH);
+ deflateEnd(&zs);
+
+ inflateReset(&s->zstream);
+
+ s->zstream.next_in = s->deflate_block;
+ s->zstream.avail_in = s->deflate_block_size - zs.avail_out;
+ s->zstream.next_out = s->tmpblock;
+ s->zstream.avail_out = s->block_size * 3;
+ inflate(&s->zstream, Z_SYNC_FLUSH);
+}
+
+static int flashsv_decode_block(AVCodecContext *avctx, AVPacket *avpkt,
+ GetBitContext *gb, int block_size,
+ int width, int height, int x_pos, int y_pos,
+ int blk_idx)
+{
+ struct FlashSVContext *s = avctx->priv_data;
+ uint8_t *line = s->tmpblock;
+ int k;
+ int ret = inflateReset(&s->zstream);
+ if (ret != Z_OK) {
+ //return -1;
+ }
+ if (s->zlibprime_curr || s->zlibprime_prev) {
+ flashsv2_prime(s, s->blocks[blk_idx].pos, s->blocks[blk_idx].size,
+ s->blocks[blk_idx].unp_size);
+ }
+ s->zstream.next_in = avpkt->data + get_bits_count(gb) / 8;
+ s->zstream.avail_in = block_size;
+ s->zstream.next_out = s->tmpblock;
+ s->zstream.avail_out = s->block_size * 3;
+ ret = inflate(&s->zstream, Z_FINISH);
+ if (ret == Z_DATA_ERROR) {
+ av_log(avctx, AV_LOG_ERROR, "Zlib resync occurred\n");
+ inflateSync(&s->zstream);
+ ret = inflate(&s->zstream, Z_FINISH);
+ }
+
+ if (ret != Z_OK && ret != Z_STREAM_END) {
+ //return -1;
+ }
+
+ if (s->is_keyframe) {
+ s->blocks[blk_idx].pos = s->keyframedata + (get_bits_count(gb) / 8);
+ s->blocks[blk_idx].size = block_size;
+ s->blocks[blk_idx].unp_size = s->block_size * 3 - s->zstream.avail_out;
+ }
+ if (!s->color_depth) {
+ /* Flash Screen Video stores the image upside down, so copy
+ * lines to destination in reverse order. */
+ for (k = 1; k <= s->diff_height; k++) {
+ memcpy(s->frame.data[0] + x_pos * 3 +
+ (s->image_height - y_pos - s->diff_start - k) * s->frame.linesize[0],
+ line, width * 3);
+ /* advance source pointer to next line */
+ line += width * 3;
+ }
+ } else {
+ /* hybrid 15-bit/palette mode */
+ decode_hybrid(s->tmpblock, s->frame.data[0],
+ s->image_height - (y_pos + 1 + s->diff_start + s->diff_height),
+ x_pos, s->diff_height, width,
+ s->frame.linesize[0], s->pal);
+ }
+ skip_bits_long(gb, 8 * block_size); /* skip the consumed bits */
+ return 0;
+}
+
+static int calc_deflate_block_size(int tmpblock_size)
+{
+ z_stream zstream;
+ int size;
+
+ zstream.zalloc = Z_NULL;
+ zstream.zfree = Z_NULL;
+ zstream.opaque = Z_NULL;
+ if (deflateInit(&zstream, 0) != Z_OK)
+ return -1;
+ size = deflateBound(&zstream, tmpblock_size);
+ deflateEnd(&zstream);
+
+ return size;
+}
+
static int flashsv_decode_frame(AVCodecContext *avctx, void *data,
int *data_size, AVPacket *avpkt)
{
- const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
FlashSVContext *s = avctx->priv_data;
int h_blocks, v_blocks, h_part, v_part, i, j;
@@ -113,7 +241,7 @@ static int flashsv_decode_frame(AVCodecContext *avctx, void *data,
if (buf_size < 4)
return -1;
- init_get_bits(&gb, buf, buf_size * 8);
+ init_get_bits(&gb, avpkt->data, buf_size * 8);
/* start to parse the bitstream */
s->block_width = 16 * (get_bits(&gb, 4) + 1);
@@ -121,7 +249,19 @@ static int flashsv_decode_frame(AVCodecContext *avctx, void *data,
s->block_height = 16 * (get_bits(&gb, 4) + 1);
s->image_height = get_bits(&gb, 12);
- /* calculate amount of blocks and the size of the border blocks */
+ if (s->ver == 2) {
+ skip_bits(&gb, 6);
+ if (get_bits1(&gb)) {
+ av_log_missing_feature(avctx, "iframe", 1);
+ return AVERROR_PATCHWELCOME;
+ }
+ if (get_bits1(&gb)) {
+ av_log_missing_feature(avctx, "custom palette", 1);
+ return AVERROR_PATCHWELCOME;
+ }
+ }
+
+ /* calculate number of blocks and size of border (partial) blocks */
h_blocks = s->image_width / s->block_width;
h_part = s->image_width % s->block_width;
v_blocks = s->image_height / s->block_height;
@@ -130,34 +270,61 @@ static int flashsv_decode_frame(AVCodecContext *avctx, void *data,
/* the block size could change between frames, make sure the buffer
* is large enough, if not, get a larger one */
if (s->block_size < s->block_width * s->block_height) {
- av_free(s->tmpblock);
- if ((s->tmpblock = av_malloc(3 * s->block_width * s->block_height)) == NULL) {
+ int tmpblock_size = 3 * s->block_width * s->block_height;
+
+ s->tmpblock = av_realloc(s->tmpblock, tmpblock_size);
+ if (!s->tmpblock) {
av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n");
return AVERROR(ENOMEM);
}
+ if (s->ver == 2) {
+ s->deflate_block_size = calc_deflate_block_size(tmpblock_size);
+ if (s->deflate_block_size <= 0) {
+ av_log(avctx, AV_LOG_ERROR, "Can't determine deflate buffer size.\n");
+ return -1;
+ }
+ s->deflate_block = av_realloc(s->deflate_block, s->deflate_block_size);
+ if (!s->deflate_block) {
+ av_log(avctx, AV_LOG_ERROR, "Can't allocate deflate buffer.\n");
+ return AVERROR(ENOMEM);
+ }
+ }
}
s->block_size = s->block_width * s->block_height;
- /* init the image size once */
- if ((avctx->width == 0) && (avctx->height == 0)) {
+ /* initialize the image size once */
+ if (avctx->width == 0 && avctx->height == 0) {
avctx->width = s->image_width;
avctx->height = s->image_height;
}
/* check for changes of image width and image height */
- if ((avctx->width != s->image_width) || (avctx->height != s->image_height)) {
- av_log(avctx, AV_LOG_ERROR, "Frame width or height differs from first frames!\n");
- av_log(avctx, AV_LOG_ERROR, "fh = %d, fv %d vs ch = %d, cv = %d\n", avctx->height,
- avctx->width, s->image_height, s->image_width);
- return -1;
+ if (avctx->width != s->image_width || avctx->height != s->image_height) {
+ av_log(avctx, AV_LOG_ERROR,
+ "Frame width or height differs from first frame!\n");
+ av_log(avctx, AV_LOG_ERROR, "fh = %d, fv %d vs ch = %d, cv = %d\n",
+ avctx->height, avctx->width, s->image_height, s->image_width);
+ return AVERROR_INVALIDDATA;
}
- av_log(avctx, AV_LOG_DEBUG, "image: %dx%d block: %dx%d num: %dx%d part: %dx%d\n",
- s->image_width, s->image_height, s->block_width, s->block_height,
- h_blocks, v_blocks, h_part, v_part);
+ /* we care for keyframes only in Screen Video v2 */
+ s->is_keyframe = (avpkt->flags & AV_PKT_FLAG_KEY) && (s->ver == 2);
+ if (s->is_keyframe) {
+ s->keyframedata = av_realloc(s->keyframedata, avpkt->size);
+ memcpy(s->keyframedata, avpkt->data, avpkt->size);
+ s->blocks = av_realloc(s->blocks,
+ (v_blocks + !!v_part) * (h_blocks + !!h_part)
+ * sizeof(s->blocks[0]));
+ }
- s->frame.reference = 1;
- s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
+ av_dlog(avctx, "image: %dx%d block: %dx%d num: %dx%d part: %dx%d\n",
+ s->image_width, s->image_height, s->block_width, s->block_height,
+ h_blocks, v_blocks, h_part, v_part);
+
+ s->frame.reference = 3;
+ s->frame.buffer_hints = FF_BUFFER_HINTS_VALID |
+ FF_BUFFER_HINTS_PRESERVE |
+ FF_BUFFER_HINTS_REUSABLE;
if (avctx->reget_buffer(avctx, &s->frame) < 0) {
av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
return -1;
@@ -166,53 +333,97 @@ static int flashsv_decode_frame(AVCodecContext *avctx, void *data,
/* loop over all block columns */
for (j = 0; j < v_blocks + (v_part ? 1 : 0); j++) {
- int hp = j * s->block_height; // horiz position in frame
- int hs = (j < v_blocks) ? s->block_height : v_part; // size of block
-
+ int y_pos = j * s->block_height; // vertical position in frame
+ int cur_blk_height = (j < v_blocks) ? s->block_height : v_part;
/* loop over all block rows */
for (i = 0; i < h_blocks + (h_part ? 1 : 0); i++) {
- int wp = i * s->block_width; // vert position in frame
- int ws = (i < h_blocks) ? s->block_width : h_part; // size of block
+ int x_pos = i * s->block_width; // horizontal position in frame
+ int cur_blk_width = (i < h_blocks) ? s->block_width : h_part;
+ int has_diff = 0;
/* get the size of the compressed zlib chunk */
int size = get_bits(&gb, 16);
+
+ s->color_depth = 0;
+ s->zlibprime_curr = 0;
+ s->zlibprime_prev = 0;
+ s->diff_start = 0;
+ s->diff_height = cur_blk_height;
+
if (8 * size > get_bits_left(&gb)) {
avctx->release_buffer(avctx, &s->frame);
s->frame.data[0] = NULL;
- return -1;
+ return AVERROR_INVALIDDATA;
}
- if (size == 0) {
- /* no change, don't do anything */
- } else {
- /* decompress block */
- int ret = inflateReset(&(s->zstream));
- if (ret != Z_OK) {
- av_log(avctx, AV_LOG_ERROR, "error in decompression (reset) of block %dx%d\n", i, j);
- /* return -1; */
+ if (s->ver == 2 && size) {
+ skip_bits(&gb, 3);
+ s->color_depth = get_bits(&gb, 2);
+ has_diff = get_bits1(&gb);
+ s->zlibprime_curr = get_bits1(&gb);
+ s->zlibprime_prev = get_bits1(&gb);
+
+ if (s->color_depth != 0 && s->color_depth != 2) {
+ av_log(avctx, AV_LOG_ERROR,
+ "%dx%d invalid color depth %d\n", i, j, s->color_depth);
+ return AVERROR_INVALIDDATA;
}
- s->zstream.next_in = buf + (get_bits_count(&gb) / 8);
- s->zstream.avail_in = size;
- s->zstream.next_out = s->tmpblock;
- s->zstream.avail_out = s->block_size * 3;
- ret = inflate(&(s->zstream), Z_FINISH);
- if (ret == Z_DATA_ERROR) {
- av_log(avctx, AV_LOG_ERROR, "Zlib resync occurred\n");
- inflateSync(&(s->zstream));
- ret = inflate(&(s->zstream), Z_FINISH);
+
+ if (has_diff) {
+ s->diff_start = get_bits(&gb, 8);
+ s->diff_height = get_bits(&gb, 8);
+ av_log(avctx, AV_LOG_DEBUG,
+ "%dx%d diff start %d height %d\n",
+ i, j, s->diff_start, s->diff_height);
+ size -= 2;
}
- if ((ret != Z_OK) && (ret != Z_STREAM_END)) {
- av_log(avctx, AV_LOG_ERROR, "error in decompression of block %dx%d: %d\n", i, j, ret);
- /* return -1; */
+ if (s->zlibprime_prev)
+ av_log(avctx, AV_LOG_DEBUG, "%dx%d zlibprime_prev\n", i, j);
+
+ if (s->zlibprime_curr) {
+ int col = get_bits(&gb, 8);
+ int row = get_bits(&gb, 8);
+ av_log(avctx, AV_LOG_DEBUG, "%dx%d zlibprime_curr %dx%d\n", i, j, col, row);
+ size -= 2;
+ av_log_missing_feature(avctx, "zlibprime_curr", 1);
+ return AVERROR_PATCHWELCOME;
}
- copy_region(s->tmpblock, s->frame.data[0], s->image_height - (hp + hs + 1),
- wp, hs, ws, s->frame.linesize[0]);
- skip_bits_long(&gb, 8 * size); /* skip the consumed bits */
+ size--; // account for flags byte
+ }
+
+ if (has_diff) {
+ int k;
+ int off = (s->image_height - y_pos - 1) * s->frame.linesize[0];
+
+ for (k = 0; k < cur_blk_height; k++)
+ memcpy(s->frame.data[0] + off - k*s->frame.linesize[0] + x_pos*3,
+ s->keyframe + off - k*s->frame.linesize[0] + x_pos*3,
+ cur_blk_width * 3);
+ }
+
+ /* skip unchanged blocks, which have size 0 */
+ if (size) {
+ if (flashsv_decode_block(avctx, avpkt, &gb, size,
+ cur_blk_width, cur_blk_height,
+ x_pos, y_pos,
+ i + j * (h_blocks + !!h_part)))
+ av_log(avctx, AV_LOG_ERROR,
+ "error in decompression of block %dx%d\n", i, j);
}
}
}
+ if (s->is_keyframe && s->ver == 2) {
+ if (!s->keyframe) {
+ s->keyframe = av_malloc(s->frame.linesize[0] * avctx->height);
+ if (!s->keyframe) {
+ av_log(avctx, AV_LOG_ERROR, "Cannot allocate image data\n");
+ return AVERROR(ENOMEM);
+ }
+ }
+ memcpy(s->keyframe, s->frame.data[0], s->frame.linesize[0] * avctx->height);
+ }
*data_size = sizeof(AVFrame);
*(AVFrame*)data = s->frame;
@@ -229,7 +440,7 @@ static int flashsv_decode_frame(AVCodecContext *avctx, void *data,
static av_cold int flashsv_decode_end(AVCodecContext *avctx)
{
FlashSVContext *s = avctx->priv_data;
- inflateEnd(&(s->zstream));
+ inflateEnd(&s->zstream);
/* release the frame if needed */
if (s->frame.data[0])
avctx->release_buffer(avctx, &s->frame);
@@ -241,6 +452,7 @@ static av_cold int flashsv_decode_end(AVCodecContext *avctx)
}
+#if CONFIG_FLASHSV_DECODER
AVCodec ff_flashsv_decoder = {
.name = "flashsv",
.type = AVMEDIA_TYPE_VIDEO,
@@ -253,3 +465,67 @@ AVCodec ff_flashsv_decoder = {
.pix_fmts = (const enum PixelFormat[]){PIX_FMT_BGR24, PIX_FMT_NONE},
.long_name = NULL_IF_CONFIG_SMALL("Flash Screen Video v1"),
};
+#endif /* CONFIG_FLASHSV_DECODER */
+
+#if CONFIG_FLASHSV2_DECODER
+static const uint32_t ff_flashsv2_default_palette[128] = {
+ 0x000000, 0x333333, 0x666666, 0x999999, 0xCCCCCC, 0xFFFFFF,
+ 0x330000, 0x660000, 0x990000, 0xCC0000, 0xFF0000, 0x003300,
+ 0x006600, 0x009900, 0x00CC00, 0x00FF00, 0x000033, 0x000066,
+ 0x000099, 0x0000CC, 0x0000FF, 0x333300, 0x666600, 0x999900,
+ 0xCCCC00, 0xFFFF00, 0x003333, 0x006666, 0x009999, 0x00CCCC,
+ 0x00FFFF, 0x330033, 0x660066, 0x990099, 0xCC00CC, 0xFF00FF,
+ 0xFFFF33, 0xFFFF66, 0xFFFF99, 0xFFFFCC, 0xFF33FF, 0xFF66FF,
+ 0xFF99FF, 0xFFCCFF, 0x33FFFF, 0x66FFFF, 0x99FFFF, 0xCCFFFF,
+ 0xCCCC33, 0xCCCC66, 0xCCCC99, 0xCCCCFF, 0xCC33CC, 0xCC66CC,
+ 0xCC99CC, 0xCCFFCC, 0x33CCCC, 0x66CCCC, 0x99CCCC, 0xFFCCCC,
+ 0x999933, 0x999966, 0x9999CC, 0x9999FF, 0x993399, 0x996699,
+ 0x99CC99, 0x99FF99, 0x339999, 0x669999, 0xCC9999, 0xFF9999,
+ 0x666633, 0x666699, 0x6666CC, 0x6666FF, 0x663366, 0x669966,
+ 0x66CC66, 0x66FF66, 0x336666, 0x996666, 0xCC6666, 0xFF6666,
+ 0x333366, 0x333399, 0x3333CC, 0x3333FF, 0x336633, 0x339933,
+ 0x33CC33, 0x33FF33, 0x663333, 0x993333, 0xCC3333, 0xFF3333,
+ 0x003366, 0x336600, 0x660033, 0x006633, 0x330066, 0x663300,
+ 0x336699, 0x669933, 0x993366, 0x339966, 0x663399, 0x996633,
+ 0x6699CC, 0x99CC66, 0xCC6699, 0x66CC99, 0x9966CC, 0xCC9966,
+ 0x99CCFF, 0xCCFF99, 0xFF99CC, 0x99FFCC, 0xCC99FF, 0xFFCC99,
+ 0x111111, 0x222222, 0x444444, 0x555555, 0xAAAAAA, 0xBBBBBB,
+ 0xDDDDDD, 0xEEEEEE
+};
+
+static av_cold int flashsv2_decode_init(AVCodecContext *avctx)
+{
+ FlashSVContext *s = avctx->priv_data;
+ flashsv_decode_init(avctx);
+ s->pal = ff_flashsv2_default_palette;
+ s->ver = 2;
+
+ return 0;
+}
+
+static av_cold int flashsv2_decode_end(AVCodecContext *avctx)
+{
+ FlashSVContext *s = avctx->priv_data;
+
+ av_freep(&s->keyframedata);
+ av_freep(&s->blocks);
+ av_freep(&s->keyframe);
+ av_freep(&s->deflate_block);
+ flashsv_decode_end(avctx);
+
+ return 0;
+}
+
+AVCodec ff_flashsv2_decoder = {
+ .name = "flashsv2",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_FLASHSV2,
+ .priv_data_size = sizeof(FlashSVContext),
+ .init = flashsv2_decode_init,
+ .close = flashsv2_decode_end,
+ .decode = flashsv_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
+ .pix_fmts = (const enum PixelFormat[]){PIX_FMT_BGR24, PIX_FMT_NONE},
+ .long_name = NULL_IF_CONFIG_SMALL("Flash Screen Video v2"),
+};
+#endif /* CONFIG_FLASHSV2_DECODER */
diff --git a/libavcodec/flashsv2enc.c b/libavcodec/flashsv2enc.c
new file mode 100644
index 0000000000..27bd87816b
--- /dev/null
+++ b/libavcodec/flashsv2enc.c
@@ -0,0 +1,907 @@
+/*
+ * Flash Screen Video Version 2 encoder
+ * Copyright (C) 2009 Joshua Warner
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * Flash Screen Video Version 2 encoder
+ * @author Joshua Warner
+ */
+
+/* Differences from version 1 stream:
+ * NOTE: Currently, the only player that supports version 2 streams is Adobe Flash Player itself.
+ * * Supports sending only a range of scanlines in a block,
+ * indicating a difference from the corresponding block in the last keyframe.
+ * * Supports initializing the zlib dictionary with data from the corresponding
+ * block in the last keyframe, to improve compression.
+ * * Supports a hybrid 15-bit rgb / 7-bit palette color space.
+ */
+
+/* TODO:
+ * Don't keep Block structures for both current frame and keyframe.
+ * Make better heuristics for deciding stream parameters (optimum_* functions). Currently these return constants.
+ * Figure out how to encode palette information in the stream, choose an optimum palette at each keyframe.
+ * Figure out how the zlibPrimeCompressCurrent flag works, implement support.
+ * Find other sample files (that weren't generated here), develop a decoder.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <zlib.h>
+
+#include "libavutil/imgutils.h"
+#include "avcodec.h"
+#include "put_bits.h"
+#include "bytestream.h"
+
+#define HAS_IFRAME_IMAGE 0x02
+#define HAS_PALLET_INFO 0x01
+
+#define COLORSPACE_BGR 0x00
+#define COLORSPACE_15_7 0x10
+#define HAS_DIFF_BLOCKS 0x04
+#define ZLIB_PRIME_COMPRESS_CURRENT 0x02
+#define ZLIB_PRIME_COMPRESS_PREVIOUS 0x01
+
+// Disables experimental "smart" parameter-choosing code, as well as the statistics that it depends on.
+// At the moment, the "smart" code is a great example of how the parameters *shouldn't* be chosen.
+#define FLASHSV2_DUMB
+
+typedef struct Block {
+ uint8_t *enc;
+ uint8_t *sl_begin, *sl_end;
+ int enc_size;
+ uint8_t *data;
+ unsigned long data_size;
+
+ uint8_t start, len;
+ uint8_t dirty;
+ uint8_t col, row, width, height;
+ uint8_t flags;
+} Block;
+
+typedef struct Palette {
+ unsigned colors[128];
+ uint8_t index[1 << 15];
+} Palette;
+
+typedef struct FlashSV2Context {
+ AVCodecContext *avctx;
+ uint8_t *current_frame;
+ uint8_t *key_frame;
+ AVFrame frame;
+ uint8_t *encbuffer;
+ uint8_t *keybuffer;
+ uint8_t *databuffer;
+
+ Block *frame_blocks;
+ Block *key_blocks;
+ int frame_size;
+ int blocks_size;
+
+ int use15_7, dist, comp;
+
+ int rows, cols;
+
+ int last_key_frame;
+
+ int image_width, image_height;
+ int block_width, block_height;
+ uint8_t flags;
+ uint8_t use_custom_palette;
+ uint8_t palette_type; ///< 0=>default, 1=>custom - changed when palette regenerated.
+ Palette palette;
+#ifndef FLASHSV2_DUMB
+ double tot_blocks; ///< blocks encoded since last keyframe
+ double diff_blocks; ///< blocks that were different since last keyframe
+ double tot_lines; ///< total scanlines in image since last keyframe
+ double diff_lines; ///< scanlines that were different since last keyframe
+ double raw_size; ///< size of raw frames since last keyframe
+ double comp_size; ///< size of compressed data since last keyframe
+ double uncomp_size; ///< size of uncompressed data since last keyframe
+
+ double total_bits; ///< total bits written to stream so far
+#endif
+} FlashSV2Context;
+
+static av_cold void cleanup(FlashSV2Context * s)
+{
+ av_freep(&s->encbuffer);
+ av_freep(&s->keybuffer);
+ av_freep(&s->databuffer);
+ av_freep(&s->current_frame);
+ av_freep(&s->key_frame);
+
+ av_freep(&s->frame_blocks);
+ av_freep(&s->key_blocks);
+}
+
+static void init_blocks(FlashSV2Context * s, Block * blocks,
+ uint8_t * encbuf, uint8_t * databuf)
+{
+ int row, col;
+ Block *b;
+ for (col = 0; col < s->cols; col++) {
+ for (row = 0; row < s->rows; row++) {
+ b = blocks + (col + row * s->cols);
+ b->width = (col < s->cols - 1) ?
+ s->block_width :
+ s->image_width - col * s->block_width;
+
+ b->height = (row < s->rows - 1) ?
+ s->block_height :
+ s->image_height - row * s->block_height;
+
+ b->row = row;
+ b->col = col;
+ b->enc = encbuf;
+ b->data = databuf;
+ encbuf += b->width * b->height * 3;
+ databuf += !databuf ? 0 : b->width * b->height * 6;
+ }
+ }
+}
+
+static void reset_stats(FlashSV2Context * s)
+{
+#ifndef FLASHSV2_DUMB
+ s->diff_blocks = 0.1;
+ s->tot_blocks = 1;
+ s->diff_lines = 0.1;
+ s->tot_lines = 1;
+ s->raw_size = s->comp_size = s->uncomp_size = 10;
+#endif
+}
+
+static av_cold int flashsv2_encode_init(AVCodecContext * avctx)
+{
+ FlashSV2Context *s = avctx->priv_data;
+
+ s->avctx = avctx;
+
+ s->comp = avctx->compression_level;
+ if (s->comp == -1)
+ s->comp = 9;
+ if (s->comp < 0 || s->comp > 9) {
+ av_log(avctx, AV_LOG_ERROR,
+ "Compression level should be 0-9, not %d\n", s->comp);
+ return -1;
+ }
+
+
+ if ((avctx->width > 4095) || (avctx->height > 4095)) {
+ av_log(avctx, AV_LOG_ERROR,
+ "Input dimensions too large, input must be max 4096x4096 !\n");
+ return -1;
+ }
+
+ if (av_image_check_size(avctx->width, avctx->height, 0, avctx) < 0)
+ return -1;
+
+
+ s->last_key_frame = 0;
+
+ s->image_width = avctx->width;
+ s->image_height = avctx->height;
+
+ s->block_width = (s->image_width / 12) & ~15;
+ s->block_height = (s->image_height / 12) & ~15;
+
+ s->rows = (s->image_height + s->block_height - 1) / s->block_height;
+ s->cols = (s->image_width + s->block_width - 1) / s->block_width;
+
+ s->frame_size = s->image_width * s->image_height * 3;
+ s->blocks_size = s->rows * s->cols * sizeof(Block);
+
+ s->encbuffer = av_mallocz(s->frame_size);
+ s->keybuffer = av_mallocz(s->frame_size);
+ s->databuffer = av_mallocz(s->frame_size * 6);
+ s->current_frame = av_mallocz(s->frame_size);
+ s->key_frame = av_mallocz(s->frame_size);
+ s->frame_blocks = av_mallocz(s->blocks_size);
+ s->key_blocks = av_mallocz(s->blocks_size);
+
+ init_blocks(s, s->frame_blocks, s->encbuffer, s->databuffer);
+ init_blocks(s, s->key_blocks, s->keybuffer, 0);
+ reset_stats(s);
+#ifndef FLASHSV2_DUMB
+ s->total_bits = 1;
+#endif
+
+ s->use_custom_palette = 0;
+ s->palette_type = -1; // so that the palette will be generated in reconfigure_at_keyframe
+
+ if (!s->encbuffer || !s->keybuffer || !s->databuffer
+ || !s->current_frame || !s->key_frame || !s->key_blocks
+ || !s->frame_blocks) {
+ av_log(avctx, AV_LOG_ERROR, "Memory allocation failed.\n");
+ cleanup(s);
+ return -1;
+ }
+
+ return 0;
+}
+
+static int new_key_frame(FlashSV2Context * s)
+{
+ int i;
+ memcpy(s->key_blocks, s->frame_blocks, s->blocks_size);
+ memcpy(s->key_frame, s->current_frame, s->frame_size);
+
+ for (i = 0; i < s->rows * s->cols; i++) {
+ s->key_blocks[i].enc += (s->keybuffer - s->encbuffer);
+ s->key_blocks[i].sl_begin = 0;
+ s->key_blocks[i].sl_end = 0;
+ s->key_blocks[i].data = 0;
+ }
+ FFSWAP(uint8_t * , s->keybuffer, s->encbuffer);
+
+ return 0;
+}
+
+static int write_palette(FlashSV2Context * s, uint8_t * buf, int buf_size)
+{
+ //this isn't implemented yet! Default palette only!
+ return -1;
+}
+
+static int write_header(FlashSV2Context * s, uint8_t * buf, int buf_size)
+{
+ PutBitContext pb;
+ int buf_pos, len;
+
+ if (buf_size < 5)
+ return -1;
+
+ init_put_bits(&pb, buf, buf_size * 8);
+
+ put_bits(&pb, 4, (s->block_width >> 4) - 1);
+ put_bits(&pb, 12, s->image_width);
+ put_bits(&pb, 4, (s->block_height >> 4) - 1);
+ put_bits(&pb, 12, s->image_height);
+
+ flush_put_bits(&pb);
+ buf_pos = 4;
+
+ buf[buf_pos++] = s->flags;
+
+ if (s->flags & HAS_PALLET_INFO) {
+ len = write_palette(s, buf + buf_pos, buf_size - buf_pos);
+ if (len < 0)
+ return -1;
+ buf_pos += len;
+ }
+
+ return buf_pos;
+}
+
+static int write_block(Block * b, uint8_t * buf, int buf_size)
+{
+ int buf_pos = 0;
+ unsigned block_size = b->data_size;
+
+ if (b->flags & HAS_DIFF_BLOCKS)
+ block_size += 2;
+ if (b->flags & ZLIB_PRIME_COMPRESS_CURRENT)
+ block_size += 2;
+ if (block_size > 0)
+ block_size += 1;
+ if (buf_size < block_size + 2)
+ return -1;
+
+ buf[buf_pos++] = block_size >> 8;
+ buf[buf_pos++] = block_size;
+
+ if (block_size == 0)
+ return buf_pos;
+
+ buf[buf_pos++] = b->flags;
+
+ if (b->flags & HAS_DIFF_BLOCKS) {
+ buf[buf_pos++] = (b->start);
+ buf[buf_pos++] = (b->len);
+ }
+
+ if (b->flags & ZLIB_PRIME_COMPRESS_CURRENT) {
+ //This feature of the format is poorly understood, and as of now, unused.
+ buf[buf_pos++] = (b->col);
+ buf[buf_pos++] = (b->row);
+ }
+
+ memcpy(buf + buf_pos, b->data, b->data_size);
+
+ buf_pos += b->data_size;
+
+ return buf_pos;
+}
+
+static int encode_zlib(Block * b, uint8_t * buf, unsigned long *buf_size, int comp)
+{
+ int res = compress2(buf, buf_size, b->sl_begin, b->sl_end - b->sl_begin, comp);
+ return res == Z_OK ? 0 : -1;
+}
+
+static int encode_zlibprime(Block * b, Block * prime, uint8_t * buf,
+ int *buf_size, int comp)
+{
+ z_stream s;
+ int res;
+ s.zalloc = NULL;
+ s.zfree = NULL;
+ s.opaque = NULL;
+ res = deflateInit(&s, comp);
+ if (res < 0)
+ return -1;
+
+ s.next_in = prime->enc;
+ s.avail_in = prime->enc_size;
+ while (s.avail_in > 0) {
+ s.next_out = buf;
+ s.avail_out = *buf_size;
+ res = deflate(&s, Z_SYNC_FLUSH);
+ if (res < 0)
+ return -1;
+ }
+
+ s.next_in = b->sl_begin;
+ s.avail_in = b->sl_end - b->sl_begin;
+ s.next_out = buf;
+ s.avail_out = *buf_size;
+ res = deflate(&s, Z_FINISH);
+ deflateEnd(&s);
+ *buf_size -= s.avail_out;
+ if (res != Z_STREAM_END)
+ return -1;
+ return 0;
+}
+
+static int encode_bgr(Block * b, const uint8_t * src, int stride)
+{
+ int i;
+ uint8_t *ptr = b->enc;
+ for (i = 0; i < b->start; i++)
+ memcpy(ptr + i * b->width * 3, src + i * stride, b->width * 3);
+ b->sl_begin = ptr + i * b->width * 3;
+ for (; i < b->start + b->len; i++)
+ memcpy(ptr + i * b->width * 3, src + i * stride, b->width * 3);
+ b->sl_end = ptr + i * b->width * 3;
+ for (; i < b->height; i++)
+ memcpy(ptr + i * b->width * 3, src + i * stride, b->width * 3);
+ b->enc_size = ptr + i * b->width * 3 - b->enc;
+ return b->enc_size;
+}
+
+static inline unsigned pixel_color15(const uint8_t * src)
+{
+ return (src[0] >> 3) | ((src[1] & 0xf8) << 2) | ((src[2] & 0xf8) << 7);
+}
+
+static inline unsigned int chroma_diff(unsigned int c1, unsigned int c2)
+{
+ unsigned int t1 = (c1 & 0x000000ff) + ((c1 & 0x0000ff00) >> 8) + ((c1 & 0x00ff0000) >> 16);
+ unsigned int t2 = (c2 & 0x000000ff) + ((c2 & 0x0000ff00) >> 8) + ((c2 & 0x00ff0000) >> 16);
+
+ return abs(t1 - t2) + abs((c1 & 0x000000ff) - (c2 & 0x000000ff)) +
+ abs(((c1 & 0x0000ff00) >> 8) - ((c2 & 0x0000ff00) >> 8)) +
+ abs(((c1 & 0x00ff0000) >> 16) - ((c2 & 0x00ff0000) >> 16));
+}
+
+static inline int pixel_color7_fast(Palette * palette, unsigned c15)
+{
+ return palette->index[c15];
+}
+
+static int pixel_color7_slow(Palette * palette, unsigned color)
+{
+ int i, min = 0x7fffffff;
+ int minc = -1;
+ for (i = 0; i < 128; i++) {
+ int c1 = palette->colors[i];
+ int diff = chroma_diff(c1, color);
+ if (diff < min) {
+ min = diff;
+ minc = i;
+ }
+ }
+ return minc;
+}
+
+static inline unsigned pixel_bgr(const uint8_t * src)
+{
+ return (src[0]) | (src[1] << 8) | (src[2] << 16);
+}
+
+static int write_pixel_15_7(Palette * palette, uint8_t * dest, const uint8_t * src,
+ int dist)
+{
+ unsigned c15 = pixel_color15(src);
+ unsigned color = pixel_bgr(src);
+ int d15 = chroma_diff(color, color & 0x00f8f8f8);
+ int c7 = pixel_color7_fast(palette, c15);
+ int d7 = chroma_diff(color, palette->colors[c7]);
+ if (dist + d15 >= d7) {
+ dest[0] = c7;
+ return 1;
+ } else {
+ dest[0] = 0x80 | (c15 >> 8);
+ dest[1] = c15 & 0xff;
+ return 2;
+ }
+}
+
+static int update_palette_index(Palette * palette)
+{
+ int r, g, b;
+ unsigned int bgr, c15, index;
+ for (r = 4; r < 256; r += 8) {
+ for (g = 4; g < 256; g += 8) {
+ for (b = 4; b < 256; b += 8) {
+ bgr = b | (g << 8) | (r << 16);
+ c15 = (b >> 3) | ((g & 0xf8) << 2) | ((r & 0xf8) << 7);
+ index = pixel_color7_slow(palette, bgr);
+
+ palette->index[c15] = index;
+ }
+ }
+ }
+ return 0;
+}
+
+static const unsigned int default_screen_video_v2_palette[128] = {
+ 0x00000000, 0x00333333, 0x00666666, 0x00999999, 0x00CCCCCC, 0x00FFFFFF,
+ 0x00330000, 0x00660000, 0x00990000, 0x00CC0000, 0x00FF0000, 0x00003300,
+ 0x00006600, 0x00009900, 0x0000CC00, 0x0000FF00, 0x00000033, 0x00000066,
+ 0x00000099, 0x000000CC, 0x000000FF, 0x00333300, 0x00666600, 0x00999900,
+ 0x00CCCC00, 0x00FFFF00, 0x00003333, 0x00006666, 0x00009999, 0x0000CCCC,
+ 0x0000FFFF, 0x00330033, 0x00660066, 0x00990099, 0x00CC00CC, 0x00FF00FF,
+ 0x00FFFF33, 0x00FFFF66, 0x00FFFF99, 0x00FFFFCC, 0x00FF33FF, 0x00FF66FF,
+ 0x00FF99FF, 0x00FFCCFF, 0x0033FFFF, 0x0066FFFF, 0x0099FFFF, 0x00CCFFFF,
+ 0x00CCCC33, 0x00CCCC66, 0x00CCCC99, 0x00CCCCFF, 0x00CC33CC, 0x00CC66CC,
+ 0x00CC99CC, 0x00CCFFCC, 0x0033CCCC, 0x0066CCCC, 0x0099CCCC, 0x00FFCCCC,
+ 0x00999933, 0x00999966, 0x009999CC, 0x009999FF, 0x00993399, 0x00996699,
+ 0x0099CC99, 0x0099FF99, 0x00339999, 0x00669999, 0x00CC9999, 0x00FF9999,
+ 0x00666633, 0x00666699, 0x006666CC, 0x006666FF, 0x00663366, 0x00669966,
+ 0x0066CC66, 0x0066FF66, 0x00336666, 0x00996666, 0x00CC6666, 0x00FF6666,
+ 0x00333366, 0x00333399, 0x003333CC, 0x003333FF, 0x00336633, 0x00339933,
+ 0x0033CC33, 0x0033FF33, 0x00663333, 0x00993333, 0x00CC3333, 0x00FF3333,
+ 0x00003366, 0x00336600, 0x00660033, 0x00006633, 0x00330066, 0x00663300,
+ 0x00336699, 0x00669933, 0x00993366, 0x00339966, 0x00663399, 0x00996633,
+ 0x006699CC, 0x0099CC66, 0x00CC6699, 0x0066CC99, 0x009966CC, 0x00CC9966,
+ 0x0099CCFF, 0x00CCFF99, 0x00FF99CC, 0x0099FFCC, 0x00CC99FF, 0x00FFCC99,
+ 0x00111111, 0x00222222, 0x00444444, 0x00555555, 0x00AAAAAA, 0x00BBBBBB,
+ 0x00DDDDDD, 0x00EEEEEE
+};
+
+static int generate_default_palette(Palette * palette)
+{
+ memcpy(palette->colors, default_screen_video_v2_palette,
+ sizeof(default_screen_video_v2_palette));
+
+ return update_palette_index(palette);
+}
+
+static int generate_optimum_palette(Palette * palette, const uint8_t * image,
+ int width, int height, int stride)
+{
+ //this isn't implemented yet! Default palette only!
+ return -1;
+}
+
+static inline int encode_15_7_sl(Palette * palette, uint8_t * dest,
+ const uint8_t * src, int width, int dist)
+{
+ int len = 0, x;
+ for (x = 0; x < width; x++) {
+ len += write_pixel_15_7(palette, dest + len, src + 3 * x, dist);
+ }
+ return len;
+}
+
+static int encode_15_7(Palette * palette, Block * b, const uint8_t * src,
+ int stride, int dist)
+{
+ int i;
+ uint8_t *ptr = b->enc;
+ for (i = 0; i < b->start; i++)
+ ptr += encode_15_7_sl(palette, ptr, src + i * stride, b->width, dist);
+ b->sl_begin = ptr;
+ for (; i < b->start + b->len; i++)
+ ptr += encode_15_7_sl(palette, ptr, src + i * stride, b->width, dist);
+ b->sl_end = ptr;
+ for (; i < b->height; i++)
+ ptr += encode_15_7_sl(palette, ptr, src + i * stride, b->width, dist);
+ b->enc_size = ptr - b->enc;
+ return b->enc_size;
+}
+
+static int encode_block(Palette * palette, Block * b, Block * prev,
+ const uint8_t * src, int stride, int comp, int dist,
+ int keyframe)
+{
+ unsigned buf_size = b->width * b->height * 6;
+ uint8_t buf[buf_size];
+ int res;
+ if (b->flags & COLORSPACE_15_7) {
+ encode_15_7(palette, b, src, stride, dist);
+ } else {
+ encode_bgr(b, src, stride);
+ }
+
+ if (b->len > 0) {
+ b->data_size = buf_size;
+ res = encode_zlib(b, b->data, &b->data_size, comp);
+ if (res)
+ return res;
+
+ if (!keyframe) {
+ res = encode_zlibprime(b, prev, buf, &buf_size, comp);
+ if (res)
+ return res;
+
+ if (buf_size < b->data_size) {
+ b->data_size = buf_size;
+ memcpy(b->data, buf, buf_size);
+ b->flags |= ZLIB_PRIME_COMPRESS_PREVIOUS;
+ }
+ }
+ } else {
+ b->data_size = 0;
+ }
+ return 0;
+}
+
+static int compare_sl(FlashSV2Context * s, Block * b, const uint8_t * src,
+ uint8_t * frame, uint8_t * key, int y, int keyframe)
+{
+ if (memcmp(src, frame, b->width * 3) != 0) {
+ b->dirty = 1;
+ memcpy(frame, src, b->width * 3);
+#ifndef FLASHSV2_DUMB
+ s->diff_lines++;
+#endif
+ }
+ if (memcmp(src, key, b->width * 3) != 0) {
+ if (b->len == 0)
+ b->start = y;
+ b->len = y + 1 - b->start;
+ }
+ return 0;
+}
+
+static int mark_all_blocks(FlashSV2Context * s, const uint8_t * src, int stride,
+ int keyframe)
+{
+ int sl, rsl, col, pos, possl;
+ Block *b;
+ for (sl = s->image_height - 1; sl >= 0; sl--) {
+ for (col = 0; col < s->cols; col++) {
+ rsl = s->image_height - sl - 1;
+ b = s->frame_blocks + col + rsl / s->block_height * s->cols;
+ possl = stride * sl + col * s->block_width * 3;
+ pos = s->image_width * rsl * 3 + col * s->block_width * 3;
+ compare_sl(s, b, src + possl, s->current_frame + pos,
+ s->key_frame + pos, rsl % s->block_height, keyframe);
+ }
+ }
+#ifndef FLASHSV2_DUMB
+ s->tot_lines += s->image_height * s->cols;
+#endif
+ return 0;
+}
+
+static int encode_all_blocks(FlashSV2Context * s, int keyframe)
+{
+ int row, col, res;
+ uint8_t *data;
+ Block *b, *prev;
+ for (row = 0; row < s->rows; row++) {
+ for (col = 0; col < s->cols; col++) {
+ b = s->frame_blocks + (row * s->cols + col);
+ prev = s->key_blocks + (row * s->cols + col);
+ if (keyframe) {
+ b->start = 0;
+ b->len = b->height;
+ b->flags = s->use15_7 ? COLORSPACE_15_7 : 0;
+ } else if (!b->dirty) {
+ b->start = 0;
+ b->len = 0;
+ b->data_size = 0;
+ b->flags = s->use15_7 ? COLORSPACE_15_7 : 0;
+ continue;
+ } else {
+ b->flags = s->use15_7 ? COLORSPACE_15_7 | HAS_DIFF_BLOCKS : HAS_DIFF_BLOCKS;
+ }
+ data = s->current_frame + s->image_width * 3 * s->block_height * row + s->block_width * col * 3;
+ res = encode_block(&s->palette, b, prev, data, s->image_width * 3, s->comp, s->dist, keyframe);
+#ifndef FLASHSV2_DUMB
+ if (b->dirty)
+ s->diff_blocks++;
+ s->comp_size += b->data_size;
+ s->uncomp_size += b->enc_size;
+#endif
+ if (res)
+ return res;
+ }
+ }
+#ifndef FLASHSV2_DUMB
+ s->raw_size += s->image_width * s->image_height * 3;
+ s->tot_blocks += s->rows * s->cols;
+#endif
+ return 0;
+}
+
+static int write_all_blocks(FlashSV2Context * s, uint8_t * buf,
+ int buf_size)
+{
+ int row, col, buf_pos = 0, len;
+ Block *b;
+ for (row = 0; row < s->rows; row++) {
+ for (col = 0; col < s->cols; col++) {
+ b = s->frame_blocks + row * s->cols + col;
+ len = write_block(b, buf + buf_pos, buf_size - buf_pos);
+ b->start = b->len = b->dirty = 0;
+ if (len < 0)
+ return len;
+ buf_pos += len;
+ }
+ }
+ return buf_pos;
+}
+
+static int write_bitstream(FlashSV2Context * s, const uint8_t * src, int stride,
+ uint8_t * buf, int buf_size, int keyframe)
+{
+ int buf_pos, res;
+
+ res = mark_all_blocks(s, src, stride, keyframe);
+ if (res)
+ return res;
+ res = encode_all_blocks(s, keyframe);
+ if (res)
+ return res;
+
+ res = write_header(s, buf, buf_size);
+ if (res < 0) {
+ return res;
+ } else {
+ buf_pos = res;
+ }
+ res = write_all_blocks(s, buf + buf_pos, buf_size - buf_pos);
+ if (res < 0)
+ return res;
+ buf_pos += res;
+#ifndef FLASHSV2_DUMB
+ s->total_bits += ((double) buf_pos) * 8.0;
+#endif
+
+ return buf_pos;
+}
+
+static void recommend_keyframe(FlashSV2Context * s, int *keyframe)
+{
+#ifndef FLASHSV2_DUMB
+ double block_ratio, line_ratio, enc_ratio, comp_ratio, data_ratio;
+ if (s->avctx->gop_size > 0) {
+ block_ratio = s->diff_blocks / s->tot_blocks;
+ line_ratio = s->diff_lines / s->tot_lines;
+ enc_ratio = s->uncomp_size / s->raw_size;
+ comp_ratio = s->comp_size / s->uncomp_size;
+ data_ratio = s->comp_size / s->raw_size;
+
+ if ((block_ratio >= 0.5 && line_ratio / block_ratio <= 0.5) || line_ratio >= 0.95) {
+ *keyframe = 1;
+ return;
+ }
+ }
+#else
+ return;
+#endif
+}
+
+static const double block_size_fraction = 1.0 / 300;
+static int optimum_block_width(FlashSV2Context * s)
+{
+#ifndef FLASHSV2_DUMB
+ double save = (1-pow(s->diff_lines/s->diff_blocks/s->block_height, 0.5)) * s->comp_size/s->tot_blocks;
+ double width = block_size_fraction * sqrt(0.5 * save * s->rows * s->cols) * s->image_width;
+ int pwidth = ((int) width);
+ return FFCLIP(pwidth & ~15, 256, 16);
+#else
+ return 64;
+#endif
+}
+
+static int optimum_block_height(FlashSV2Context * s)
+{
+#ifndef FLASHSV2_DUMB
+ double save = (1-pow(s->diff_lines/s->diff_blocks/s->block_height, 0.5)) * s->comp_size/s->tot_blocks;
+ double height = block_size_fraction * sqrt(0.5 * save * s->rows * s->cols) * s->image_height;
+ int pheight = ((int) height);
+ return FFCLIP(pheight & ~15, 256, 16);
+#else
+ return 64;
+#endif
+}
+
+static const double use15_7_threshold = 8192;
+
+static int optimum_use15_7(FlashSV2Context * s)
+{
+#ifndef FLASHSV2_DUMB
+ double ideal = ((double)(s->avctx->bit_rate * s->avctx->time_base.den * s->avctx->ticks_per_frame)) /
+ ((double) s->avctx->time_base.num) * s->avctx->frame_number;
+ if (ideal + use15_7_threshold < s->total_bits) {
+ return 1;
+ } else {
+ return 0;
+ }
+#else
+ return s->avctx->global_quality == 0;
+#endif
+}
+
+static const double color15_7_factor = 100;
+
+static int optimum_dist(FlashSV2Context * s)
+{
+#ifndef FLASHSV2_DUMB
+ double ideal =
+ s->avctx->bit_rate * s->avctx->time_base.den *
+ s->avctx->ticks_per_frame;
+ int dist = pow((s->total_bits / ideal) * color15_7_factor, 3);
+ av_log(s->avctx, AV_LOG_DEBUG, "dist: %d\n", dist);
+ return dist;
+#else
+ return 15;
+#endif
+}
+
+
+static int reconfigure_at_keyframe(FlashSV2Context * s, const uint8_t * image,
+ int stride)
+{
+ int update_palette = 0;
+ int res;
+ s->block_width = optimum_block_width(s);
+ s->block_height = optimum_block_height(s);
+
+ s->rows = (s->image_height + s->block_height - 1) / s->block_height;
+ s->cols = (s->image_width + s->block_width - 1) / s->block_width;
+
+ if (s->rows * s->cols != s->blocks_size / sizeof(Block)) {
+ if (s->rows * s->cols > s->blocks_size / sizeof(Block)) {
+ s->frame_blocks = av_realloc(s->frame_blocks, s->rows * s->cols * sizeof(Block));
+ s->key_blocks = av_realloc(s->key_blocks, s->cols * s->rows * sizeof(Block));
+ if (!s->frame_blocks || !s->key_blocks) {
+ av_log(s->avctx, AV_LOG_ERROR, "Memory allocation failed.\n");
+ return -1;
+ }
+ s->blocks_size = s->rows * s->cols * sizeof(Block);
+ }
+ init_blocks(s, s->frame_blocks, s->encbuffer, s->databuffer);
+ init_blocks(s, s->key_blocks, s->keybuffer, 0);
+
+ }
+
+ s->use15_7 = optimum_use15_7(s);
+ if (s->use15_7) {
+ if ((s->use_custom_palette && s->palette_type != 1) || update_palette) {
+ res = generate_optimum_palette(&s->palette, image, s->image_width, s->image_height, stride);
+ if (res)
+ return res;
+ s->palette_type = 1;
+ av_log(s->avctx, AV_LOG_DEBUG, "Generated optimum palette\n");
+ } else if (!s->use_custom_palette && s->palette_type != 0) {
+ res = generate_default_palette(&s->palette);
+ if (res)
+ return res;
+ s->palette_type = 0;
+ av_log(s->avctx, AV_LOG_DEBUG, "Generated default palette\n");
+ }
+ }
+
+
+ reset_stats(s);
+
+ return 0;
+}
+
+static int flashsv2_encode_frame(AVCodecContext * avctx, uint8_t * buf,
+ int buf_size, void *data)
+{
+ FlashSV2Context *const s = avctx->priv_data;
+ AVFrame *pict = data;
+ AVFrame *const p = &s->frame;
+ int res;
+ int keyframe = 0;
+
+ *p = *pict;
+
+ /* First frame needs to be a keyframe */
+ if (avctx->frame_number == 0)
+ keyframe = 1;
+
+ /* Check the placement of keyframes */
+ if (avctx->gop_size > 0) {
+ if (avctx->frame_number >= s->last_key_frame + avctx->gop_size)
+ keyframe = 1;
+ }
+
+ if (buf_size < s->frame_size) {
+ //Conservative upper bound check for compressed data
+ av_log(avctx, AV_LOG_ERROR, "buf_size %d < %d\n", buf_size, s->frame_size);
+ return -1;
+ }
+
+ if (!keyframe
+ && avctx->frame_number > s->last_key_frame + avctx->keyint_min) {
+ recommend_keyframe(s, &keyframe);
+ if (keyframe)
+ av_log(avctx, AV_LOG_DEBUG, "Recommending key frame at frame %d\n", avctx->frame_number);
+ }
+
+ if (keyframe) {
+ res = reconfigure_at_keyframe(s, p->data[0], p->linesize[0]);
+ if (res)
+ return res;
+ }
+
+ if (s->use15_7)
+ s->dist = optimum_dist(s);
+
+ res = write_bitstream(s, p->data[0], p->linesize[0], buf, buf_size, keyframe);
+
+ if (keyframe) {
+ new_key_frame(s);
+ p->pict_type = FF_I_TYPE;
+ p->key_frame = 1;
+ s->last_key_frame = avctx->frame_number;
+ av_log(avctx, AV_LOG_DEBUG, "Inserting key frame at frame %d\n", avctx->frame_number);
+ } else {
+ p->pict_type = FF_P_TYPE;
+ p->key_frame = 0;
+ }
+
+ avctx->coded_frame = p;
+
+ return res;
+}
+
+static av_cold int flashsv2_encode_end(AVCodecContext * avctx)
+{
+ FlashSV2Context *s = avctx->priv_data;
+
+ cleanup(s);
+
+ return 0;
+}
+
+AVCodec ff_flashsv2_encoder = {
+ "flashsv2",
+ AVMEDIA_TYPE_VIDEO,
+ CODEC_ID_FLASHSV2,
+ sizeof(FlashSV2Context),
+ flashsv2_encode_init,
+ flashsv2_encode_frame,
+ flashsv2_encode_end,
+ .pix_fmts = (enum PixelFormat[]) {PIX_FMT_BGR24, PIX_FMT_NONE},
+ .long_name = NULL_IF_CONFIG_SMALL("Flash Screen Video Version 2"),
+ .capabilities = CODEC_CAP_EXPERIMENTAL,
+};
diff --git a/libavcodec/flashsvenc.c b/libavcodec/flashsvenc.c
index ad14104112..7e21e7d534 100644
--- a/libavcodec/flashsvenc.c
+++ b/libavcodec/flashsvenc.c
@@ -3,20 +3,20 @@
* Copyright (C) 2004 Alex Beregszaszi
* Copyright (C) 2006 Benjamin Larsson
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -27,31 +27,21 @@
* Flash Screen Video encoder
* @author Alex Beregszaszi
* @author Benjamin Larsson
+ *
+ * A description of the bitstream format for Flash Screen Video version 1/2
+ * is part of the SWF File Format Specification (version 10), which can be
+ * downloaded from http://www.adobe.com/devnet/swf.html.
*/
-/* Bitstream description
- * The picture is divided into blocks that are zlib-compressed.
- *
- * The decoder is fed complete frames, the frameheader contains:
- * 4bits of block width
- * 12bits of frame width
- * 4bits of block height
- * 12bits of frame height
- *
- * Directly after the header are the compressed blocks. The blocks
- * have their compressed size represented with 16bits in the beginig.
- * If the size = 0 then the block is unchanged from the previous frame.
- * All blocks are decompressed until the buffer is consumed.
- *
- * Encoding ideas, a basic encoder would just use a fixed block size.
- * Block sizes can be multipels of 16, from 16 to 256. The blocks don't
+/*
+ * Encoding ideas: A basic encoder would just use a fixed block size.
+ * Block sizes can be multiples of 16, from 16 to 256. The blocks don't
* have to be quadratic. A brute force search with a set of different
* block sizes should give a better result than to just use a fixed size.
- */
-
-/* TODO:
- * Don't reencode the frame in brute force mode if the frame is a dupe. Speed up.
- * Make the difference check faster.
+ *
+ * TODO:
+ * Don't reencode the frame in brute force mode if the frame is a dupe.
+ * Speed up. Make the difference check faster.
*/
#include <stdio.h>
@@ -85,8 +75,8 @@ static int copy_region_enc(uint8_t *sptr, uint8_t *dptr, int dx, int dy,
int diff = 0;
for (i = dx + h; i > dx; i--) {
- nsptr = sptr + (i * stride) + dy * 3;
- npfptr = pfptr + (i * stride) + dy * 3;
+ nsptr = sptr + i * stride + dy * 3;
+ npfptr = pfptr + i * stride + dy * 3;
for (j = 0; j < w * 3; j++) {
diff |= npfptr[j] ^ nsptr[j];
dptr[j] = nsptr[j];
@@ -104,13 +94,14 @@ static av_cold int flashsv_encode_init(AVCodecContext *avctx)
s->avctx = avctx;
- if ((avctx->width > 4095) || (avctx->height > 4095)) {
- av_log(avctx, AV_LOG_ERROR, "Input dimensions too large, input must be max 4096x4096 !\n");
+ if (avctx->width > 4095 || avctx->height > 4095) {
+ av_log(avctx, AV_LOG_ERROR,
+ "Input dimensions too large, input must be max 4096x4096 !\n");
return AVERROR_INVALIDDATA;
}
// Needed if zlib unused or init aborted before deflateInit
- memset(&(s->zstream), 0, sizeof(z_stream));
+ memset(&s->zstream, 0, sizeof(z_stream));
s->last_key_frame = 0;
@@ -141,9 +132,9 @@ static int encode_bitstream(FlashSVContext *s, AVFrame *p, uint8_t *buf,
init_put_bits(&pb, buf, buf_size * 8);
- put_bits(&pb, 4, (block_width / 16) - 1);
+ put_bits(&pb, 4, block_width / 16 - 1);
put_bits(&pb, 12, s->image_width);
- put_bits(&pb, 4, (block_height / 16) - 1);
+ put_bits(&pb, 4, block_height / 16 - 1);
put_bits(&pb, 12, s->image_height);
flush_put_bits(&pb);
buf_pos = 4;
@@ -156,37 +147,36 @@ static int encode_bitstream(FlashSVContext *s, AVFrame *p, uint8_t *buf,
/* loop over all block columns */
for (j = 0; j < v_blocks + (v_part ? 1 : 0); j++) {
- int hp = j * block_height; // horiz position in frame
- int hs = (j < v_blocks) ? block_height : v_part; // size of block
+ int y_pos = j * block_height; // vertical position in frame
+ int cur_blk_height = (j < v_blocks) ? block_height : v_part;
/* loop over all block rows */
for (i = 0; i < h_blocks + (h_part ? 1 : 0); i++) {
- int wp = i * block_width; // vert position in frame
- int ws = (i < h_blocks) ? block_width : h_part; // size of block
+ int x_pos = i * block_width; // horizontal position in frame
+ int cur_blk_width = (i < h_blocks) ? block_width : h_part;
int ret = Z_OK;
- uint8_t *ptr;
-
- ptr = buf + buf_pos;
+ uint8_t *ptr = buf + buf_pos;
/* copy the block to the temp buffer before compression
* (if it differs from the previous frame's block) */
res = copy_region_enc(p->data[0], s->tmpblock,
- s->image_height - (hp + hs + 1),
- wp, hs, ws, p->linesize[0], previous_frame);
+ s->image_height - (y_pos + cur_blk_height + 1),
+ x_pos, cur_blk_height, cur_blk_width,
+ p->linesize[0], previous_frame);
if (res || *I_frame) {
- unsigned long zsize;
- zsize = 3 * block_width * block_height;
- ret = compress2(ptr + 2, &zsize, s->tmpblock, 3 * ws * hs, 9);
-
+ unsigned long zsize = 3 * block_width * block_height;
+ ret = compress2(ptr + 2, &zsize, s->tmpblock,
+ 3 * cur_blk_width * cur_blk_height, 9);
- //ret = deflateReset(&(s->zstream));
+ //ret = deflateReset(&s->zstream);
if (ret != Z_OK)
- av_log(s->avctx, AV_LOG_ERROR, "error while compressing block %dx%d\n", i, j);
+ av_log(s->avctx, AV_LOG_ERROR,
+ "error while compressing block %dx%d\n", i, j);
- bytestream_put_be16(&ptr, (unsigned int) zsize);
+ bytestream_put_be16(&ptr, zsize);
buf_pos += zsize + 2;
- //av_log(avctx, AV_LOG_ERROR, "buf_pos = %d\n", buf_pos);
+ av_dlog(s->avctx, "buf_pos = %d\n", buf_pos);
} else {
pred_blocks++;
bytestream_put_be16(&ptr, 0);
@@ -213,7 +203,7 @@ static int flashsv_encode_frame(AVCodecContext *avctx, uint8_t *buf,
uint8_t *pfptr;
int res;
int I_frame = 0;
- int opt_w, opt_h;
+ int opt_w = 4, opt_h = 4;
*p = *pict;
@@ -228,42 +218,40 @@ static int flashsv_encode_frame(AVCodecContext *avctx, uint8_t *buf,
}
if (p->linesize[0] < 0)
- pfptr = s->previous_frame - ((s->image_height - 1) * p->linesize[0]);
+ pfptr = s->previous_frame - (s->image_height - 1) * p->linesize[0];
else
pfptr = s->previous_frame;
/* Check the placement of keyframes */
- if (avctx->gop_size > 0) {
- if (avctx->frame_number >= s->last_key_frame + avctx->gop_size) {
- I_frame = 1;
- }
+ if (avctx->gop_size > 0 &&
+ avctx->frame_number >= s->last_key_frame + avctx->gop_size) {
+ I_frame = 1;
}
- opt_w = 4;
- opt_h = 4;
-
- if (buf_size < s->image_width*s->image_height*3) {
+ if (buf_size < s->image_width * s->image_height * 3) {
//Conservative upper bound check for compressed data
av_log(avctx, AV_LOG_ERROR, "buf_size %d < %d\n",
buf_size, s->image_width * s->image_height * 3);
return -1;
}
- res = encode_bitstream(s, p, buf, buf_size, opt_w * 16, opt_h * 16, pfptr, &I_frame);
+ res = encode_bitstream(s, p, buf, buf_size, opt_w * 16, opt_h * 16,
+ pfptr, &I_frame);
//save the current frame
if (p->linesize[0] > 0)
memcpy(s->previous_frame, p->data[0], s->image_height * p->linesize[0]);
else
- memcpy(s->previous_frame, p->data[0] + p->linesize[0] * (s->image_height - 1),
+ memcpy(s->previous_frame,
+ p->data[0] + p->linesize[0] * (s->image_height - 1),
s->image_height * FFABS(p->linesize[0]));
//mark the frame type so the muxer can mux it correctly
if (I_frame) {
- p->pict_type = AV_PICTURE_TYPE_I;
- p->key_frame = 1;
+ p->pict_type = AV_PICTURE_TYPE_I;
+ p->key_frame = 1;
s->last_key_frame = avctx->frame_number;
- av_log(avctx, AV_LOG_DEBUG, "Inserting key frame at frame %d\n", avctx->frame_number);
+ av_dlog(avctx, "Inserting keyframe at frame %d\n", avctx->frame_number);
} else {
p->pict_type = AV_PICTURE_TYPE_P;
p->key_frame = 0;
@@ -278,7 +266,7 @@ static av_cold int flashsv_encode_end(AVCodecContext *avctx)
{
FlashSVContext *s = avctx->priv_data;
- deflateEnd(&(s->zstream));
+ deflateEnd(&s->zstream);
av_free(s->encbuffer);
av_free(s->previous_frame);
diff --git a/libavcodec/flicvideo.c b/libavcodec/flicvideo.c
index e8c0e14386..fa925983a9 100644
--- a/libavcodec/flicvideo.c
+++ b/libavcodec/flicvideo.c
@@ -2,20 +2,20 @@
* FLI/FLC Animation Video Decoder
* Copyright (C) 2003, 2004 the ffmpeg project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -61,9 +61,9 @@
#define CHECK_PIXEL_PTR(n) \
if (pixel_ptr + n > pixel_limit) { \
- av_log (s->avctx, AV_LOG_INFO, "Problem: pixel_ptr >= pixel_limit (%d >= %d)\n", \
+ av_log (s->avctx, AV_LOG_ERROR, "Invalid pixel_ptr = %d > pixel_limit = %d\n", \
pixel_ptr + n, pixel_limit); \
- return -1; \
+ return AVERROR_INVALIDDATA; \
} \
typedef struct FlicDecodeContext {
@@ -117,6 +117,7 @@ static av_cold int flic_decode_init(AVCodecContext *avctx)
return -1;
}
+ avcodec_get_frame_defaults(&s->frame);
s->frame.data[0] = NULL;
s->new_palette = 0;
@@ -130,7 +131,6 @@ static int flic_decode_frame_8BPP(AVCodecContext *avctx,
FlicDecodeContext *s = avctx->priv_data;
int stream_ptr = 0;
- int stream_ptr_after_color_chunk;
int pixel_ptr;
int palette_ptr;
unsigned char palette_idx1;
@@ -170,7 +170,11 @@ static int flic_decode_frame_8BPP(AVCodecContext *avctx,
pixels = s->frame.data[0];
pixel_limit = s->avctx->height * s->frame.linesize[0];
+ if (buf_size < 16 || buf_size > INT_MAX - (3 * 256 + FF_INPUT_BUFFER_PADDING_SIZE))
+ return AVERROR_INVALIDDATA;
frame_size = AV_RL32(&buf[stream_ptr]);
+ if (frame_size > buf_size)
+ frame_size = buf_size;
stream_ptr += 6; /* skip the magic number */
num_chunks = AV_RL16(&buf[stream_ptr]);
stream_ptr += 10; /* skip padding */
@@ -178,8 +182,16 @@ static int flic_decode_frame_8BPP(AVCodecContext *avctx,
frame_size -= 16;
/* iterate through the chunks */
- while ((frame_size > 0) && (num_chunks > 0)) {
+ while ((frame_size >= 6) && (num_chunks > 0)) {
+ int stream_ptr_after_chunk;
chunk_size = AV_RL32(&buf[stream_ptr]);
+ if (chunk_size > frame_size) {
+ av_log(avctx, AV_LOG_WARNING,
+ "Invalid chunk_size = %u > frame_size = %u\n", chunk_size, frame_size);
+ chunk_size = frame_size;
+ }
+ stream_ptr_after_chunk = stream_ptr + chunk_size;
+
stream_ptr += 4;
chunk_type = AV_RL16(&buf[stream_ptr]);
stream_ptr += 2;
@@ -187,8 +199,6 @@ static int flic_decode_frame_8BPP(AVCodecContext *avctx,
switch (chunk_type) {
case FLI_256_COLOR:
case FLI_COLOR:
- stream_ptr_after_color_chunk = stream_ptr + chunk_size - 6;
-
/* check special case: If this file is from the Magic Carpet
* game and uses 6-bit colors even though it reports 256-color
* chunks in a 0xAF12-type file (fli_type is set to 0xAF13 during
@@ -212,6 +222,9 @@ static int flic_decode_frame_8BPP(AVCodecContext *avctx,
if (color_changes == 0)
color_changes = 256;
+ if (stream_ptr + color_changes * 3 > stream_ptr_after_chunk)
+ break;
+
for (j = 0; j < color_changes; j++) {
unsigned int entry;
@@ -228,13 +241,6 @@ static int flic_decode_frame_8BPP(AVCodecContext *avctx,
s->palette[palette_ptr++] = entry;
}
}
-
- /* color chunks sometimes have weird 16-bit alignment issues;
- * therefore, take the hardline approach and set the stream_ptr
- * to the value calculated w.r.t. the size specified by the color
- * chunk header */
- stream_ptr = stream_ptr_after_color_chunk;
-
break;
case FLI_DELTA:
@@ -242,6 +248,8 @@ static int flic_decode_frame_8BPP(AVCodecContext *avctx,
compressed_lines = AV_RL16(&buf[stream_ptr]);
stream_ptr += 2;
while (compressed_lines > 0) {
+ if (stream_ptr + 2 > stream_ptr_after_chunk)
+ break;
line_packets = AV_RL16(&buf[stream_ptr]);
stream_ptr += 2;
if ((line_packets & 0xC000) == 0xC000) {
@@ -261,6 +269,8 @@ static int flic_decode_frame_8BPP(AVCodecContext *avctx,
CHECK_PIXEL_PTR(0);
pixel_countdown = s->avctx->width;
for (i = 0; i < line_packets; i++) {
+ if (stream_ptr + 2 > stream_ptr_after_chunk)
+ break;
/* account for the skip bytes */
pixel_skip = buf[stream_ptr++];
pixel_ptr += pixel_skip;
@@ -277,6 +287,8 @@ static int flic_decode_frame_8BPP(AVCodecContext *avctx,
}
} else {
CHECK_PIXEL_PTR(byte_run * 2);
+ if (stream_ptr + byte_run * 2 > stream_ptr_after_chunk)
+ break;
for (j = 0; j < byte_run * 2; j++, pixel_countdown--) {
palette_idx1 = buf[stream_ptr++];
pixels[pixel_ptr++] = palette_idx1;
@@ -303,6 +315,8 @@ static int flic_decode_frame_8BPP(AVCodecContext *avctx,
CHECK_PIXEL_PTR(0);
pixel_countdown = s->avctx->width;
line_packets = buf[stream_ptr++];
+ if (stream_ptr + 2 * line_packets > stream_ptr_after_chunk)
+ break;
if (line_packets > 0) {
for (i = 0; i < line_packets; i++) {
/* account for the skip bytes */
@@ -312,6 +326,8 @@ static int flic_decode_frame_8BPP(AVCodecContext *avctx,
byte_run = (signed char)(buf[stream_ptr++]);
if (byte_run > 0) {
CHECK_PIXEL_PTR(byte_run);
+ if (stream_ptr + byte_run > stream_ptr_after_chunk)
+ break;
for (j = 0; j < byte_run; j++, pixel_countdown--) {
palette_idx1 = buf[stream_ptr++];
pixels[pixel_ptr++] = palette_idx1;
@@ -349,6 +365,8 @@ static int flic_decode_frame_8BPP(AVCodecContext *avctx,
stream_ptr++;
pixel_countdown = s->avctx->width;
while (pixel_countdown > 0) {
+ if (stream_ptr + 1 > stream_ptr_after_chunk)
+ break;
byte_run = (signed char)(buf[stream_ptr++]);
if (byte_run > 0) {
palette_idx1 = buf[stream_ptr++];
@@ -363,6 +381,8 @@ static int flic_decode_frame_8BPP(AVCodecContext *avctx,
} else { /* copy bytes if byte_run < 0 */
byte_run = -byte_run;
CHECK_PIXEL_PTR(byte_run);
+ if (stream_ptr + byte_run > stream_ptr_after_chunk)
+ break;
for (j = 0; j < byte_run; j++) {
palette_idx1 = buf[stream_ptr++];
pixels[pixel_ptr++] = palette_idx1;
@@ -380,10 +400,9 @@ static int flic_decode_frame_8BPP(AVCodecContext *avctx,
case FLI_COPY:
/* copy the chunk (uncompressed frame) */
- if (chunk_size - 6 > s->avctx->width * s->avctx->height) {
+ if (chunk_size - 6 != s->avctx->width * s->avctx->height) {
av_log(avctx, AV_LOG_ERROR, "In chunk FLI_COPY : source data (%d bytes) " \
- "bigger than image, skipping chunk\n", chunk_size - 6);
- stream_ptr += chunk_size - 6;
+ "has incorrect size, skipping chunk\n", chunk_size - 6);
} else {
for (y_ptr = 0; y_ptr < s->frame.linesize[0] * s->avctx->height;
y_ptr += s->frame.linesize[0]) {
@@ -396,7 +415,6 @@ static int flic_decode_frame_8BPP(AVCodecContext *avctx,
case FLI_MINI:
/* some sort of a thumbnail? disregard this chunk... */
- stream_ptr += chunk_size - 6;
break;
default:
@@ -404,6 +422,8 @@ static int flic_decode_frame_8BPP(AVCodecContext *avctx,
break;
}
+ stream_ptr = stream_ptr_after_chunk;
+
frame_size -= chunk_size;
num_chunks--;
}
@@ -742,18 +762,13 @@ static av_cold int flic_decode_end(AVCodecContext *avctx)
}
AVCodec ff_flic_decoder = {
- "flic",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_FLIC,
- sizeof(FlicDecodeContext),
- flic_decode_init,
- NULL,
- flic_decode_end,
- flic_decode_frame,
- CODEC_CAP_DR1,
- NULL,
- NULL,
- NULL,
- NULL,
+ .name = "flic",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_FLIC,
+ .priv_data_size = sizeof(FlicDecodeContext),
+ .init = flic_decode_init,
+ .close = flic_decode_end,
+ .decode = flic_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Autodesk Animator Flic video"),
};
diff --git a/libavcodec/flv.h b/libavcodec/flv.h
index 3d9a2d5232..16bc88b663 100644
--- a/libavcodec/flv.h
+++ b/libavcodec/flv.h
@@ -1,19 +1,19 @@
/*
* FLV specific private header.
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/flvdec.c b/libavcodec/flvdec.c
index 9546c1c2ce..7337107469 100644
--- a/libavcodec/flvdec.c
+++ b/libavcodec/flvdec.c
@@ -1,19 +1,19 @@
/*
* FLV decoding.
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -119,15 +119,14 @@ int ff_flv_decode_picture_header(MpegEncContext *s)
}
AVCodec ff_flv_decoder = {
- "flv",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_FLV1,
- sizeof(MpegEncContext),
- ff_h263_decode_init,
- NULL,
- ff_h263_decode_end,
- ff_h263_decode_frame,
- CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
+ .name = "flv",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_FLV1,
+ .priv_data_size = sizeof(MpegEncContext),
+ .init = ff_h263_decode_init,
+ .close = ff_h263_decode_end,
+ .decode = ff_h263_decode_frame,
+ .capabilities = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
.max_lowres= 3,
.long_name= NULL_IF_CONFIG_SMALL("Flash Video (FLV) / Sorenson Spark / Sorenson H.263"),
.pix_fmts= ff_pixfmt_list_420,
diff --git a/libavcodec/flvenc.c b/libavcodec/flvenc.c
index 28bca2ea6a..ee373d0975 100644
--- a/libavcodec/flvenc.c
+++ b/libavcodec/flvenc.c
@@ -1,19 +1,19 @@
/*
* FLV Encoding specific code.
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -25,7 +25,7 @@ void ff_flv_encode_picture_header(MpegEncContext * s, int picture_number)
{
int format;
- align_put_bits(&s->pb);
+ avpriv_align_put_bits(&s->pb);
put_bits(&s->pb, 17, 1);
put_bits(&s->pb, 5, (s->h263_flv-1)); /* 0: h263 escape codes 1: 11-bit escape codes */
@@ -85,13 +85,13 @@ void ff_flv2_encode_ac_esc(PutBitContext *pb, int slevel, int level, int run, in
}
AVCodec ff_flv_encoder = {
- "flv",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_FLV1,
- sizeof(MpegEncContext),
- MPV_encode_init,
- MPV_encode_picture,
- MPV_encode_end,
+ .name = "flv",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_FLV1,
+ .priv_data_size = sizeof(MpegEncContext),
+ .init = MPV_encode_init,
+ .encode = MPV_encode_picture,
+ .close = MPV_encode_end,
.pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
.long_name= NULL_IF_CONFIG_SMALL("Flash Video (FLV) / Sorenson Spark / Sorenson H.263"),
};
diff --git a/libavcodec/fmtconvert.c b/libavcodec/fmtconvert.c
index 58fece70b2..c03117c2cd 100644
--- a/libavcodec/fmtconvert.c
+++ b/libavcodec/fmtconvert.c
@@ -3,20 +3,20 @@
* Copyright (c) 2000, 2001 Fabrice Bellard
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -86,3 +86,34 @@ av_cold void ff_fmt_convert_init(FmtConvertContext *c, AVCodecContext *avctx)
if (HAVE_ALTIVEC) ff_fmt_convert_init_altivec(c, avctx);
if (HAVE_MMX) ff_fmt_convert_init_x86(c, avctx);
}
+
+/* ffdshow custom code */
+void float_interleave(float *dst, const float **src, long len, int channels)
+{
+ int i,j,c;
+ if(channels==2){
+ for(i=0; i<len; i++){
+ dst[2*i] = src[0][i] / 32768.0f;
+ dst[2*i+1] = src[1][i] / 32768.0f;
+ }
+ }else{
+ for(c=0; c<channels; c++)
+ for(i=0, j=c; i<len; i++, j+=channels)
+ dst[j] = src[c][i] / 32768.0f;
+ }
+}
+
+void float_interleave_noscale(float *dst, const float **src, long len, int channels)
+{
+ int i,j,c;
+ if(channels==2){
+ for(i=0; i<len; i++){
+ dst[2*i] = src[0][i];
+ dst[2*i+1] = src[1][i];
+ }
+ }else{
+ for(c=0; c<channels; c++)
+ for(i=0, j=c; i<len; i++, j+=channels)
+ dst[j] = src[c][i];
+ }
+}
diff --git a/libavcodec/fmtconvert.h b/libavcodec/fmtconvert.h
index d7741135b7..c0584753cd 100644
--- a/libavcodec/fmtconvert.h
+++ b/libavcodec/fmtconvert.h
@@ -3,20 +3,20 @@
* Copyright (c) 2000, 2001 Fabrice Bellard
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -70,7 +70,15 @@ typedef struct FmtConvertContext {
long len, int channels);
/**
- * Convert an array of interleaved float to multiple arrays of float.
+ * Convert multiple arrays of float to an array of interleaved float.
+ *
+ * @param dst destination array of interleaved float.
+ * constraints: 16-byte aligned
+ * @param src source array of float arrays, one for each channel.
+ * constraints: 16-byte aligned
+ * @param len number of elements to convert.
+ * constraints: multiple of 8
+ * @param channels number of channels
*/
void (*float_interleave)(float *dst, const float **src, unsigned int len,
int channels);
@@ -85,4 +93,8 @@ void ff_fmt_convert_init_arm(FmtConvertContext *c, AVCodecContext *avctx);
void ff_fmt_convert_init_altivec(FmtConvertContext *c, AVCodecContext *avctx);
void ff_fmt_convert_init_x86(FmtConvertContext *c, AVCodecContext *avctx);
+/* ffdshow custom code */
+void float_interleave(float *dst, const float **src, long len, int channels);
+void float_interleave_noscale(float *dst, const float **src, long len, int channels);
+
#endif /* AVCODEC_FMTCONVERT_H */
diff --git a/libavcodec/fraps.c b/libavcodec/fraps.c
index 2bbc7b9f01..aad8731028 100644
--- a/libavcodec/fraps.c
+++ b/libavcodec/fraps.c
@@ -3,20 +3,20 @@
* Copyright (c) 2005 Roine Gustafsson
* Copyright (c) 2006 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -46,6 +46,7 @@ typedef struct FrapsContext{
AVCodecContext *avctx;
AVFrame frame;
uint8_t *tmpbuf;
+ int tmpbuf_size;
DSPContext dsp;
} FrapsContext;
@@ -59,8 +60,8 @@ static av_cold int decode_init(AVCodecContext *avctx)
{
FrapsContext * const s = avctx->priv_data;
+ avcodec_get_frame_defaults(&s->frame);
avctx->coded_frame = (AVFrame*)&s->frame;
- avctx->pix_fmt= PIX_FMT_NONE; /* set in decode_frame */
s->avctx = avctx;
s->tmpbuf = NULL;
@@ -272,7 +273,9 @@ static int decode_frame(AVCodecContext *avctx,
offs[planes] = buf_size;
for(i = 0; i < planes; i++){
is_chroma = !!i;
- s->tmpbuf = av_realloc(s->tmpbuf, offs[i + 1] - offs[i] - 1024 + FF_INPUT_BUFFER_PADDING_SIZE);
+ av_fast_malloc(&s->tmpbuf, &s->tmpbuf_size, offs[i + 1] - offs[i] - 1024 + FF_INPUT_BUFFER_PADDING_SIZE);
+ if (!s->tmpbuf)
+ return AVERROR(ENOMEM);
if(fraps2_decode_plane(s, f->data[i], f->linesize[i], avctx->width >> is_chroma,
avctx->height >> is_chroma, buf + offs[i], offs[i + 1] - offs[i], is_chroma, 1) < 0) {
av_log(avctx, AV_LOG_ERROR, "Error decoding plane %i\n", i);
@@ -314,7 +317,9 @@ static int decode_frame(AVCodecContext *avctx,
}
offs[planes] = buf_size;
for(i = 0; i < planes; i++){
- s->tmpbuf = av_realloc(s->tmpbuf, offs[i + 1] - offs[i] - 1024 + FF_INPUT_BUFFER_PADDING_SIZE);
+ av_fast_malloc(&s->tmpbuf, &s->tmpbuf_size, offs[i + 1] - offs[i] - 1024 + FF_INPUT_BUFFER_PADDING_SIZE);
+ if (!s->tmpbuf)
+ return AVERROR(ENOMEM);
if(fraps2_decode_plane(s, f->data[0] + i + (f->linesize[0] * (avctx->height - 1)), -f->linesize[0],
avctx->width, avctx->height, buf + offs[i], offs[i + 1] - offs[i], 0, 3) < 0) {
av_log(avctx, AV_LOG_ERROR, "Error decoding plane %i\n", i);
@@ -356,14 +361,13 @@ static av_cold int decode_end(AVCodecContext *avctx)
AVCodec ff_fraps_decoder = {
- "fraps",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_FRAPS,
- sizeof(FrapsContext),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- CODEC_CAP_DR1,
+ .name = "fraps",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_FRAPS,
+ .priv_data_size = sizeof(FrapsContext),
+ .init = decode_init,
+ .close = decode_end,
+ .decode = decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Fraps"),
};
diff --git a/libavcodec/frwu.c b/libavcodec/frwu.c
index ee3d2e47a0..2a2146d601 100644
--- a/libavcodec/frwu.c
+++ b/libavcodec/frwu.c
@@ -3,20 +3,20 @@
*
* Copyright (c) 2009 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -27,7 +27,7 @@
static av_cold int decode_init(AVCodecContext *avctx)
{
if (avctx->width & 1) {
- av_log(avctx, AV_LOG_ERROR, "FRWU needs even width\n");
+ av_log(avctx, AV_LOG_ERROR, "frwu needs even width\n");
return -1;
}
avctx->pix_fmt = PIX_FMT_UYVY422;
@@ -110,14 +110,12 @@ static av_cold int decode_close(AVCodecContext *avctx)
}
AVCodec ff_frwu_decoder = {
- "FRWU",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_FRWU,
- 0,
- decode_init,
- NULL,
- decode_close,
- decode_frame,
- CODEC_CAP_DR1,
+ .name = "FRWU",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_FRWU,
+ .init = decode_init,
+ .close = decode_close,
+ .decode = decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Forward Uncompressed"),
};
diff --git a/libavcodec/g722.c b/libavcodec/g722.c
index 257292de7f..30c6f5313c 100644
--- a/libavcodec/g722.c
+++ b/libavcodec/g722.c
@@ -7,26 +7,25 @@
* Copyright (c) 2009 Kenan Gillet
* Copyright (c) 2010 Martin Storsjo
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
- *
* G.722 ADPCM audio codec
*
* This G.722 decoder is a bit-exact implementation of the ITU G.722
diff --git a/libavcodec/g723_1.c b/libavcodec/g723_1.c
new file mode 100644
index 0000000000..e1dc431d0e
--- /dev/null
+++ b/libavcodec/g723_1.c
@@ -0,0 +1,2216 @@
+/*
+ * G.723.1 compatible decoder
+ * Copyright (c) 2006 Benjamin Larsson
+ * Copyright (c) 2010 Mohamed Naufal Basheer
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * G.723.1 compatible decoder
+ */
+
+#include "avcodec.h"
+#define ALT_BITSTREAM_READER_LE
+#include "get_bits.h"
+#include "acelp_vectors.h"
+#include "celp_filters.h"
+#include "celp_math.h"
+#include "lsp.h"
+#include "libavutil/lzo.h"
+#include "g723_1_data.h"
+
+typedef struct g723_1_context {
+ G723_1_Subframe subframe[4];
+ FrameType cur_frame_type;
+ FrameType past_frame_type;
+ Rate cur_rate;
+ uint8_t lsp_index[LSP_BANDS];
+ int pitch_lag[2];
+ int erased_frames;
+
+ int16_t prev_lsp[LPC_ORDER];
+ int16_t prev_excitation[PITCH_MAX];
+ int16_t excitation[PITCH_MAX + FRAME_LEN];
+ int16_t synth_mem[LPC_ORDER];
+ int16_t fir_mem[LPC_ORDER];
+ int iir_mem[LPC_ORDER];
+
+ int random_seed;
+ int interp_index;
+ int interp_gain;
+ int sid_gain;
+ int cur_gain;
+ int reflection_coef;
+ int pf_gain; ///< formant postfilter
+ ///< gain scaling unit memory
+
+ int16_t prev_data[HALF_FRAME_LEN];
+ int16_t prev_weight_sig[PITCH_MAX];
+
+
+ int16_t hpf_fir_mem; ///< highpass filter fir
+ int hpf_iir_mem; ///< and iir memories
+ int16_t perf_fir_mem[LPC_ORDER]; ///< perceptual filter fir
+ int16_t perf_iir_mem[LPC_ORDER]; ///< and iir memories
+
+ int16_t harmonic_mem[PITCH_MAX];
+} G723_1_Context;
+
+static av_cold int g723_1_decode_init(AVCodecContext *avctx)
+{
+ G723_1_Context *p = avctx->priv_data;
+
+ avctx->sample_fmt = SAMPLE_FMT_S16;
+ p->pf_gain = 1 << 12;
+ memcpy(p->prev_lsp, dc_lsp, LPC_ORDER * sizeof(int16_t));
+
+ return 0;
+}
+
+/**
+ * Unpack the frame into parameters.
+ *
+ * @param p the context
+ * @param buf pointer to the input buffer
+ * @param buf_size size of the input buffer
+ */
+static int unpack_bitstream(G723_1_Context *p, const uint8_t *buf,
+ int buf_size)
+{
+ GetBitContext gb;
+ int ad_cb_len;
+ int temp, info_bits, i;
+
+ init_get_bits(&gb, buf, buf_size * 8);
+
+ /* Extract frame type and rate info */
+ info_bits = get_bits(&gb, 2);
+
+ if (info_bits == 3) {
+ p->cur_frame_type = UntransmittedFrame;
+ return 0;
+ }
+
+ /* Extract 24 bit lsp indices, 8 bit for each band */
+ p->lsp_index[2] = get_bits(&gb, 8);
+ p->lsp_index[1] = get_bits(&gb, 8);
+ p->lsp_index[0] = get_bits(&gb, 8);
+
+ if (info_bits == 2) {
+ p->cur_frame_type = SIDFrame;
+ p->subframe[0].amp_index = get_bits(&gb, 6);
+ return 0;
+ }
+
+ /* Extract the info common to both rates */
+ p->cur_rate = info_bits ? Rate5k3 : Rate6k3;
+ p->cur_frame_type = ActiveFrame;
+
+ p->pitch_lag[0] = get_bits(&gb, 7);
+ if (p->pitch_lag[0] > 123) /* test if forbidden code */
+ return -1;
+ p->pitch_lag[0] += PITCH_MIN;
+ p->subframe[1].ad_cb_lag = get_bits(&gb, 2);
+
+ p->pitch_lag[1] = get_bits(&gb, 7);
+ if (p->pitch_lag[1] > 123)
+ return -1;
+ p->pitch_lag[1] += PITCH_MIN;
+ p->subframe[3].ad_cb_lag = get_bits(&gb, 2);
+ p->subframe[0].ad_cb_lag = 1;
+ p->subframe[2].ad_cb_lag = 1;
+
+ for (i = 0; i < SUBFRAMES; i++) {
+ /* Extract combined gain */
+ temp = get_bits(&gb, 12);
+ ad_cb_len = 170;
+ p->subframe[i].dirac_train = 0;
+ if (p->cur_rate == Rate6k3 && p->pitch_lag[i >> 1] < SUBFRAME_LEN - 2) {
+ p->subframe[i].dirac_train = temp >> 11;
+ temp &= 0x7ff;
+ ad_cb_len = 85;
+ }
+ p->subframe[i].ad_cb_gain = FASTDIV(temp, GAIN_LEVELS);
+ if (p->subframe[i].ad_cb_gain < ad_cb_len) {
+ p->subframe[i].amp_index = temp - p->subframe[i].ad_cb_gain *
+ GAIN_LEVELS;
+ } else {
+ return -1;
+ }
+ }
+
+ p->subframe[0].grid_index = get_bits1(&gb);
+ p->subframe[1].grid_index = get_bits1(&gb);
+ p->subframe[2].grid_index = get_bits1(&gb);
+ p->subframe[3].grid_index = get_bits1(&gb);
+
+ if (p->cur_rate == Rate6k3) {
+ skip_bits1(&gb); /* skip reserved bit */
+
+ /* Compute pulse_pos index using the 13-bit combined position index */
+ temp = get_bits(&gb, 13);
+ p->subframe[0].pulse_pos = temp / 810;
+
+ temp -= p->subframe[0].pulse_pos * 810;
+ p->subframe[1].pulse_pos = FASTDIV(temp, 90);
+
+ temp -= p->subframe[1].pulse_pos * 90;
+ p->subframe[2].pulse_pos = FASTDIV(temp, 9);
+ p->subframe[3].pulse_pos = temp - p->subframe[2].pulse_pos * 9;
+
+ p->subframe[0].pulse_pos = (p->subframe[0].pulse_pos << 16) +
+ get_bits(&gb, 16);
+ p->subframe[1].pulse_pos = (p->subframe[1].pulse_pos << 14) +
+ get_bits(&gb, 14);
+ p->subframe[2].pulse_pos = (p->subframe[2].pulse_pos << 16) +
+ get_bits(&gb, 16);
+ p->subframe[3].pulse_pos = (p->subframe[3].pulse_pos << 14) +
+ get_bits(&gb, 14);
+
+ p->subframe[0].pulse_sign = get_bits(&gb, 6);
+ p->subframe[1].pulse_sign = get_bits(&gb, 5);
+ p->subframe[2].pulse_sign = get_bits(&gb, 6);
+ p->subframe[3].pulse_sign = get_bits(&gb, 5);
+ } else { /* Rate5k3 */
+ p->subframe[0].pulse_pos = get_bits(&gb, 12);
+ p->subframe[1].pulse_pos = get_bits(&gb, 12);
+ p->subframe[2].pulse_pos = get_bits(&gb, 12);
+ p->subframe[3].pulse_pos = get_bits(&gb, 12);
+
+ p->subframe[0].pulse_sign = get_bits(&gb, 4);
+ p->subframe[1].pulse_sign = get_bits(&gb, 4);
+ p->subframe[2].pulse_sign = get_bits(&gb, 4);
+ p->subframe[3].pulse_sign = get_bits(&gb, 4);
+ }
+
+ return 0;
+}
+
+/**
+ * Bitexact implementation of sqrt(val/2).
+ */
+static int16_t square_root(int val)
+{
+ return (ff_sqrt(val << 1) >> 1) & (~1);
+}
+
+/**
+ * Calculate the number of left-shifts required for normalizing the input.
+ *
+ * @param num input number
+ * @param width width of the input, 16 bits(0) / 32 bits(1)
+ */
+static int normalize_bits(int num, int width)
+{
+ int i = 0;
+ int bits = (width) ? 31 : 15;
+
+ if (num) {
+ if (num == -1)
+ return bits;
+ if (num < 0)
+ num = ~num;
+ i= bits - av_log2(num) - 1;
+ i= FFMAX(i, 0);
+ }
+ return i;
+}
+
+#define normalize_bits_int16(num) normalize_bits(num, 0)
+#define normalize_bits_int32(num) normalize_bits(num, 1)
+#define dot_product(a,b,c,d) (ff_dot_product(a,b,c)<<(d))
+
+/**
+ * Scale vector contents based on the largest of their absolutes.
+ */
+static int scale_vector(int16_t *vector, int length)
+{
+ int bits, scale, max = 0;
+ int i;
+
+ const int16_t shift_table[16] = {
+ 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
+ 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x7fff
+ };
+
+ for (i = 0; i < length; i++)
+ max = FFMAX(max, FFABS(vector[i]));
+
+ bits = normalize_bits(max, 0);
+ scale = shift_table[bits];
+
+ for (i = 0; i < length; i++)
+ vector[i] = (vector[i] * scale) >> 3;
+
+ return bits - 3;
+}
+
+/**
+ * Perform inverse quantization of LSP frequencies.
+ *
+ * @param cur_lsp the current LSP vector
+ * @param prev_lsp the previous LSP vector
+ * @param lsp_index VQ indices
+ * @param bad_frame bad frame flag
+ */
+static void inverse_quant(int16_t *cur_lsp, int16_t *prev_lsp,
+ uint8_t *lsp_index, int bad_frame)
+{
+ int min_dist, pred;
+ int i, j, temp, stable;
+
+ /* Check for frame erasure */
+ if (!bad_frame) {
+ min_dist = 0x100;
+ pred = 12288;
+ } else {
+ min_dist = 0x200;
+ pred = 23552;
+ lsp_index[0] = lsp_index[1] = lsp_index[2] = 0;
+ }
+
+ /* Get the VQ table entry corresponding to the transmitted index */
+ cur_lsp[0] = lsp_band0[lsp_index[0]][0];
+ cur_lsp[1] = lsp_band0[lsp_index[0]][1];
+ cur_lsp[2] = lsp_band0[lsp_index[0]][2];
+ cur_lsp[3] = lsp_band1[lsp_index[1]][0];
+ cur_lsp[4] = lsp_band1[lsp_index[1]][1];
+ cur_lsp[5] = lsp_band1[lsp_index[1]][2];
+ cur_lsp[6] = lsp_band2[lsp_index[2]][0];
+ cur_lsp[7] = lsp_band2[lsp_index[2]][1];
+ cur_lsp[8] = lsp_band2[lsp_index[2]][2];
+ cur_lsp[9] = lsp_band2[lsp_index[2]][3];
+
+ /* Add predicted vector & DC component to the previously quantized vector */
+ for (i = 0; i < LPC_ORDER; i++) {
+ temp = ((prev_lsp[i] - dc_lsp[i]) * pred + (1 << 14)) >> 15;
+ cur_lsp[i] += dc_lsp[i] + temp;
+ }
+
+ for (i = 0; i < LPC_ORDER; i++) {
+ cur_lsp[0] = FFMAX(cur_lsp[0], 0x180);
+ cur_lsp[LPC_ORDER - 1] = FFMIN(cur_lsp[LPC_ORDER - 1], 0x7e00);
+
+ /* Stability check */
+ for (j = 1; j < LPC_ORDER; j++) {
+ temp = min_dist + cur_lsp[j - 1] - cur_lsp[j];
+ if (temp > 0) {
+ temp >>= 1;
+ cur_lsp[j - 1] -= temp;
+ cur_lsp[j] += temp;
+ }
+ }
+ stable = 1;
+ for (j = 1; j < LPC_ORDER; j++) {
+ temp = cur_lsp[j - 1] + min_dist - cur_lsp[j] - 4;
+ if (temp > 0) {
+ stable = 0;
+ break;
+ }
+ }
+ if (stable)
+ break;
+ }
+ if (!stable)
+ memcpy(cur_lsp, prev_lsp, LPC_ORDER * sizeof(int16_t));
+}
+
+/**
+ * Bitexact implementation of 2ab scaled by 1/2^16.
+ *
+ * @param a 32 bit multiplicand
+ * @param b 16 bit multiplier
+ */
+#define MULL2(a, b) \
+ MULL(a,b,15)
+
+/**
+ * Convert LSP frequencies to LPC coefficients.
+ *
+ * @param lpc buffer for LPC coefficients
+ */
+static void lsp2lpc(int16_t *lpc)
+{
+ int f1[LPC_ORDER / 2 + 1];
+ int f2[LPC_ORDER / 2 + 1];
+ int i, j;
+
+ /* Calculate negative cosine */
+ for (j = 0; j < LPC_ORDER; j++) {
+ int index = lpc[j] >> 7;
+ int offset = lpc[j] & 0x7f;
+ int64_t temp1 = cos_tab[index] << 16;
+ int temp2 = (cos_tab[index + 1] - cos_tab[index]) *
+ ((offset << 8) + 0x80) << 1;
+
+ lpc[j] = -(av_clipl_int32(((temp1 + temp2) << 1) + (1 << 15)) >> 16);
+ }
+
+ /*
+ * Compute sum and difference polynomial coefficients
+ * (bitexact alternative to lsp2poly() in lsp.c)
+ */
+ /* Initialize with values in Q28 */
+ f1[0] = 1 << 28;
+ f1[1] = (lpc[0] << 14) + (lpc[2] << 14);
+ f1[2] = lpc[0] * lpc[2] + (2 << 28);
+
+ f2[0] = 1 << 28;
+ f2[1] = (lpc[1] << 14) + (lpc[3] << 14);
+ f2[2] = lpc[1] * lpc[3] + (2 << 28);
+
+ /*
+ * Calculate and scale the coefficients by 1/2 in
+ * each iteration for a final scaling factor of Q25
+ */
+ for (i = 2; i < LPC_ORDER / 2; i++) {
+ f1[i + 1] = f1[i - 1] + MULL2(f1[i], lpc[2 * i]);
+ f2[i + 1] = f2[i - 1] + MULL2(f2[i], lpc[2 * i + 1]);
+
+ for (j = i; j >= 2; j--) {
+ f1[j] = MULL2(f1[j - 1], lpc[2 * i]) +
+ (f1[j] >> 1) + (f1[j - 2] >> 1);
+ f2[j] = MULL2(f2[j - 1], lpc[2 * i + 1]) +
+ (f2[j] >> 1) + (f2[j - 2] >> 1);
+ }
+
+ f1[0] >>= 1;
+ f2[0] >>= 1;
+ f1[1] = ((lpc[2 * i] << 16 >> i) + f1[1]) >> 1;
+ f2[1] = ((lpc[2 * i + 1] << 16 >> i) + f2[1]) >> 1;
+ }
+
+ /* Convert polynomial coefficients to LPC coefficients */
+ for (i = 0; i < LPC_ORDER / 2; i++) {
+ int64_t ff1 = f1[i + 1] + f1[i];
+ int64_t ff2 = f2[i + 1] - f2[i];
+
+ lpc[i] = av_clipl_int32(((ff1 + ff2) << 3) + (1 << 15)) >> 16;
+ lpc[LPC_ORDER - i - 1] = av_clipl_int32(((ff1 - ff2) << 3) +
+ (1 << 15)) >> 16;
+ }
+}
+
+/**
+ * Quantize LSP frequencies by interpolation and convert them to
+ * the corresponding LPC coefficients.
+ *
+ * @param lpc buffer for LPC coefficients
+ * @param cur_lsp the current LSP vector
+ * @param prev_lsp the previous LSP vector
+ */
+static void lsp_interpolate(int16_t *lpc, int16_t *cur_lsp, int16_t *prev_lsp)
+{
+ int i;
+ int16_t *lpc_ptr = lpc;
+
+ /* cur_lsp * 0.25 + prev_lsp * 0.75 */
+ ff_acelp_weighted_vector_sum(lpc, cur_lsp, prev_lsp,
+ 4096, 12288, 1 << 13, 14, LPC_ORDER);
+ ff_acelp_weighted_vector_sum(lpc + LPC_ORDER, cur_lsp, prev_lsp,
+ 8192, 8192, 1 << 13, 14, LPC_ORDER);
+ ff_acelp_weighted_vector_sum(lpc + 2 * LPC_ORDER, cur_lsp, prev_lsp,
+ 12288, 4096, 1 << 13, 14, LPC_ORDER);
+ memcpy(lpc + 3 * LPC_ORDER, cur_lsp, LPC_ORDER * sizeof(int16_t));
+
+ for (i = 0; i < SUBFRAMES; i++) {
+ lsp2lpc(lpc_ptr);
+ lpc_ptr += LPC_ORDER;
+ }
+}
+
+/**
+ * Generate a train of dirac functions with period as pitch lag.
+ */
+static void gen_dirac_train(int16_t *buf, int pitch_lag)
+{
+ int16_t vector[SUBFRAME_LEN];
+ int i, j;
+
+ memcpy(vector, buf, SUBFRAME_LEN * sizeof(int16_t));
+ for (i = pitch_lag; i < SUBFRAME_LEN; i += pitch_lag) {
+ for (j = 0; j < SUBFRAME_LEN - i; j++)
+ buf[i + j] += vector[j];
+ }
+}
+
+/**
+ * Generate fixed codebook excitation vector.
+ *
+ * @param vector decoded excitation vector
+ * @param subfrm current subframe
+ * @param cur_rate current bitrate
+ * @param pitch_lag closed loop pitch lag
+ * @param index current subframe index
+ */
+static void gen_fcb_excitation(int16_t *vector, G723_1_Subframe subfrm,
+ Rate cur_rate, int pitch_lag, int index)
+{
+ int temp, i, j;
+
+ memset(vector, 0, SUBFRAME_LEN * sizeof(int16_t));
+
+ if (cur_rate == Rate6k3) {
+ if (subfrm.pulse_pos >= max_pos[index])
+ return;
+
+ /* Decode amplitudes and positions */
+ j = PULSE_MAX - pulses[index];
+ temp = subfrm.pulse_pos;
+ for (i = 0; i < SUBFRAME_LEN / GRID_SIZE; i++) {
+ temp -= combinatorial_table[j][i];
+ if (temp >= 0)
+ continue;
+ temp += combinatorial_table[j++][i];
+ if (subfrm.pulse_sign & (1 << (PULSE_MAX - j))) {
+ vector[subfrm.grid_index + GRID_SIZE * i] =
+ -fixed_cb_gain[subfrm.amp_index];
+ } else {
+ vector[subfrm.grid_index + GRID_SIZE * i] =
+ fixed_cb_gain[subfrm.amp_index];
+ }
+ if (j == PULSE_MAX)
+ break;
+ }
+ if (subfrm.dirac_train == 1)
+ gen_dirac_train(vector, pitch_lag);
+ } else { /* Rate5k3 */
+ int cb_gain = fixed_cb_gain[subfrm.amp_index];
+ int cb_shift = subfrm.grid_index;
+ int cb_sign = subfrm.pulse_sign;
+ int cb_pos = subfrm.pulse_pos;
+ int offset, beta, lag;
+
+ for (i = 0; i < 8; i += 2) {
+ offset = ((cb_pos & 7) << 3) + cb_shift + i;
+ vector[offset] = (cb_sign & 1) ? cb_gain : -cb_gain;
+ cb_pos >>= 3;
+ cb_sign >>= 1;
+ }
+
+ /* Enhance harmonic components */
+ lag = pitch_contrib[subfrm.ad_cb_gain << 1] + pitch_lag +
+ subfrm.ad_cb_lag - 1;
+ beta = pitch_contrib[(subfrm.ad_cb_gain << 1) + 1];
+
+ if (lag < SUBFRAME_LEN - 2) {
+ for (i = lag; i < SUBFRAME_LEN; i++)
+ vector[i] += beta * vector[i - lag] >> 15;
+ }
+ }
+}
+
+/**
+ * Get delayed contribution from the previous excitation vector.
+ */
+static void get_residual(int16_t *residual, int16_t *prev_excitation, int lag)
+{
+ int offset = PITCH_MAX - PITCH_ORDER / 2 - lag;
+ int i;
+
+ residual[0] = prev_excitation[offset];
+ residual[1] = prev_excitation[offset + 1];
+
+ offset += 2;
+ for (i = 2; i < SUBFRAME_LEN + PITCH_ORDER - 1; i++)
+ residual[i] = prev_excitation[offset + (i - 2) % lag];
+}
+
+/**
+ * Generate adaptive codebook excitation.
+ */
+static void gen_acb_excitation(int16_t *vector, int16_t *prev_excitation,
+ int pitch_lag, G723_1_Subframe subfrm,
+ Rate cur_rate)
+{
+ int16_t residual[SUBFRAME_LEN + PITCH_ORDER - 1];
+ const int16_t *cb_ptr;
+ int lag = pitch_lag + subfrm.ad_cb_lag - 1;
+
+ int i;
+ int64_t sum;
+
+ get_residual(residual, prev_excitation, lag);
+
+ /* Select quantization table */
+ if (cur_rate == Rate6k3 && pitch_lag < SUBFRAME_LEN - 2) {
+ cb_ptr = adaptive_cb_gain85;
+ } else
+ cb_ptr = adaptive_cb_gain170;
+
+ /* Calculate adaptive vector */
+ cb_ptr += subfrm.ad_cb_gain * 20;
+ for (i = 0; i < SUBFRAME_LEN; i++) {
+ sum = ff_dot_product(residual + i, cb_ptr, PITCH_ORDER);
+ vector[i] = av_clipl_int32((sum << 2) + (1 << 15)) >> 16;
+ }
+}
+
+/**
+ * Estimate maximum auto-correlation around pitch lag.
+ *
+ * @param p the context
+ * @param offset offset of the excitation vector
+ * @param ccr_max pointer to the maximum auto-correlation
+ * @param pitch_lag decoded pitch lag
+ * @param length length of autocorrelation
+ * @param dir forward lag(1) / backward lag(-1)
+ */
+static int autocorr_max(G723_1_Context *p, int offset, int *ccr_max,
+ int pitch_lag, int length, int dir)
+{
+ int limit, ccr, lag = 0;
+ int16_t *buf = p->excitation + offset;
+ int i;
+
+ pitch_lag = FFMIN(PITCH_MAX - 3, pitch_lag);
+ limit = FFMIN(FRAME_LEN + PITCH_MAX - offset - length, pitch_lag + 3);
+
+ for (i = pitch_lag - 3; i <= limit; i++) {
+ ccr = ff_dot_product(buf, buf + dir * i, length)<<1;
+
+ if (ccr > *ccr_max) {
+ *ccr_max = ccr;
+ lag = i;
+ }
+ }
+ return lag;
+}
+
+/**
+ * Calculate pitch postfilter optimal and scaling gains.
+ *
+ * @param lag pitch postfilter forward/backward lag
+ * @param ppf pitch postfilter parameters
+ * @param cur_rate current bitrate
+ * @param tgt_eng target energy
+ * @param ccr cross-correlation
+ * @param res_eng residual energy
+ */
+static void comp_ppf_gains(int lag, PPFParam *ppf, Rate cur_rate,
+ int tgt_eng, int ccr, int res_eng)
+{
+ int pf_residual; /* square of postfiltered residual */
+ int64_t temp1, temp2;
+
+ ppf->index = lag;
+
+ temp1 = tgt_eng * res_eng >> 1;
+ temp2 = ccr * ccr << 1;
+
+ if (temp2 > temp1) {
+ if (ccr >= res_eng) {
+ ppf->opt_gain = ppf_gain_weight[cur_rate];
+ } else {
+ ppf->opt_gain = (ccr << 15) / res_eng *
+ ppf_gain_weight[cur_rate] >> 15;
+ }
+ /* pf_res^2 = tgt_eng + 2*ccr*gain + res_eng*gain^2 */
+ temp1 = (tgt_eng << 15) + (ccr * ppf->opt_gain << 1);
+ temp2 = (ppf->opt_gain * ppf->opt_gain >> 15) * res_eng;
+ pf_residual = av_clipl_int32(temp1 + temp2 + (1 << 15)) >> 16;
+
+ if (tgt_eng >= pf_residual << 1) {
+ temp1 = 0x7fff;
+ } else {
+ temp1 = (tgt_eng << 14) / pf_residual;
+ }
+
+ /* scaling_gain = sqrt(tgt_eng/pf_res^2) */
+ ppf->sc_gain = square_root(temp1 << 16);
+ } else {
+ ppf->opt_gain = 0;
+ ppf->sc_gain = 0x7fff;
+ }
+
+ ppf->opt_gain = av_clip_int16(ppf->opt_gain * ppf->sc_gain >> 15);
+}
+
+/**
+ * Calculate pitch postfilter parameters.
+ *
+ * @param p the context
+ * @param offset offset of the excitation vector
+ * @param pitch_lag decoded pitch lag
+ * @param ppf pitch postfilter parameters
+ * @param cur_rate current bitrate
+ */
+static void comp_ppf_coeff(G723_1_Context *p, int offset, int pitch_lag,
+ PPFParam *ppf, Rate cur_rate)
+{
+
+ int16_t scale;
+ int i;
+ int64_t temp1, temp2;
+
+ /*
+ * 0 - target energy
+ * 1 - forward cross-correlation
+ * 2 - forward residual energy
+ * 3 - backward cross-correlation
+ * 4 - backward residual energy
+ */
+ int energy[5] = {0, 0, 0, 0, 0};
+ int16_t *buf = p->excitation + offset;
+ int fwd_lag = autocorr_max(p, offset, &energy[1], pitch_lag,
+ SUBFRAME_LEN, 1);
+ int back_lag = autocorr_max(p, offset, &energy[3], pitch_lag,
+ SUBFRAME_LEN, -1);
+
+ ppf->index = 0;
+ ppf->opt_gain = 0;
+ ppf->sc_gain = 0x7fff;
+
+ /* Case 0, Section 3.6 */
+ if (!back_lag && !fwd_lag)
+ return;
+
+ /* Compute target energy */
+ energy[0] = ff_dot_product(buf, buf, SUBFRAME_LEN)<<1;
+
+ /* Compute forward residual energy */
+ if (fwd_lag)
+ energy[2] = ff_dot_product(buf + fwd_lag, buf + fwd_lag,
+ SUBFRAME_LEN)<<1;
+
+ /* Compute backward residual energy */
+ if (back_lag)
+ energy[4] = ff_dot_product(buf - back_lag, buf - back_lag,
+ SUBFRAME_LEN)<<1;
+
+ /* Normalize and shorten */
+ temp1 = 0;
+ for (i = 0; i < 5; i++)
+ temp1 = FFMAX(energy[i], temp1);
+
+ scale = normalize_bits(temp1, 1);
+ for (i = 0; i < 5; i++)
+ energy[i] = av_clipl_int32(energy[i] << scale) >> 16;
+
+ if (fwd_lag && !back_lag) { /* Case 1 */
+ comp_ppf_gains(fwd_lag, ppf, cur_rate, energy[0], energy[1],
+ energy[2]);
+ } else if (!fwd_lag) { /* Case 2 */
+ comp_ppf_gains(-back_lag, ppf, cur_rate, energy[0], energy[3],
+ energy[4]);
+ } else { /* Case 3 */
+
+ /*
+ * Select the largest of energy[1]^2/energy[2]
+ * and energy[3]^2/energy[4]
+ */
+ temp1 = energy[4] * ((energy[1] * energy[1] + (1 << 14)) >> 15);
+ temp2 = energy[2] * ((energy[3] * energy[3] + (1 << 14)) >> 15);
+ if (temp1 >= temp2) {
+ comp_ppf_gains(fwd_lag, ppf, cur_rate, energy[0], energy[1],
+ energy[2]);
+ } else {
+ comp_ppf_gains(-back_lag, ppf, cur_rate, energy[0], energy[3],
+ energy[4]);
+ }
+ }
+}
+
+/**
+ * Classify frames as voiced/unvoiced.
+ *
+ * @param p the context
+ * @param pitch_lag decoded pitch_lag
+ * @param exc_eng excitation energy estimation
+ * @param scale scaling factor of exc_eng
+ *
+ * @return residual interpolation index if voiced, 0 otherwise
+ */
+static int comp_interp_index(G723_1_Context *p, int pitch_lag,
+ int *exc_eng, int *scale)
+{
+ int offset = PITCH_MAX + 2 * SUBFRAME_LEN;
+ int16_t *buf = p->excitation + offset;
+
+ int index, ccr, tgt_eng, best_eng, temp;
+
+ *scale = scale_vector(p->excitation, FRAME_LEN + PITCH_MAX);
+
+ /* Compute maximum backward cross-correlation */
+ ccr = 0;
+ index = autocorr_max(p, offset, &ccr, pitch_lag, SUBFRAME_LEN * 2, -1);
+ ccr = av_clipl_int32((int64_t)ccr + (1 << 15)) >> 16;
+
+ /* Compute target energy */
+ tgt_eng = ff_dot_product(buf, buf, SUBFRAME_LEN * 2)<<1;
+ *exc_eng = av_clipl_int32(tgt_eng + (1 << 15)) >> 16;
+
+ if (ccr <= 0)
+ return 0;
+
+ /* Compute best energy */
+ best_eng = ff_dot_product(buf - index, buf - index,
+ SUBFRAME_LEN * 2)<<1;
+ best_eng = av_clipl_int32((int64_t)best_eng + (1 << 15)) >> 16;
+
+ temp = best_eng * *exc_eng >> 3;
+
+ if (temp < ccr * ccr) {
+ return index;
+ } else
+ return 0;
+}
+
+/**
+ * Peform residual interpolation based on frame classification.
+ *
+ * @param buf decoded excitation vector
+ * @param out output vector
+ * @param lag decoded pitch lag
+ * @param gain interpolated gain
+ * @param rseed seed for random number generator
+ */
+static void residual_interp(int16_t *buf, int16_t *out, int lag,
+ int gain, int *rseed)
+{
+ int i;
+ if (lag) { /* Voiced */
+ int16_t *vector_ptr = buf + PITCH_MAX;
+ /* Attenuate */
+ for (i = 0; i < lag; i++)
+ vector_ptr[i - lag] = vector_ptr[i - lag] * 3 >> 2;
+ av_memcpy_backptr((uint8_t*)vector_ptr, lag * sizeof(int16_t),
+ FRAME_LEN * sizeof(int16_t));
+ memcpy(out, vector_ptr, FRAME_LEN * sizeof(int16_t));
+ } else { /* Unvoiced */
+ for (i = 0; i < FRAME_LEN; i++) {
+ *rseed = *rseed * 521 + 259;
+ out[i] = gain * *rseed >> 15;
+ }
+ memset(buf, 0, (FRAME_LEN + PITCH_MAX) * sizeof(int16_t));
+ }
+}
+
+/**
+ * Perform IIR filtering.
+ *
+ * @param fir_coef FIR coefficients
+ * @param iir_coef IIR coefficients
+ * @param src source vector
+ * @param dest destination vector
+ * @param width width of the output, 16 bits(0) / 32 bits(1)
+ */
+#define iir_filter(fir_coef, iir_coef, src, dest, width)\
+{\
+ int m, n;\
+ int res_shift = 16 & ~-(width);\
+ int in_shift = 16 - res_shift;\
+\
+ for (m = 0; m < SUBFRAME_LEN; m++) {\
+ int64_t filter = 0;\
+ for (n = 1; n <= LPC_ORDER; n++) {\
+ filter -= (fir_coef)[n - 1] * (src)[m - n] -\
+ (iir_coef)[n - 1] * ((dest)[m - n] >> in_shift);\
+ }\
+\
+ (dest)[m] = av_clipl_int32(((src)[m] << 16) + (filter << 3) +\
+ (1 << 15)) >> res_shift;\
+ }\
+}
+
+/**
+ * Adjust gain of postfiltered signal.
+ *
+ * @param p the context
+ * @param buf postfiltered output vector
+ * @param energy input energy coefficient
+ */
+static void gain_scale(G723_1_Context *p, int16_t * buf, int energy)
+{
+ int num, denom, gain, bits1, bits2;
+ int i;
+
+ num = energy;
+ denom = 0;
+ for (i = 0; i < SUBFRAME_LEN; i++) {
+ int64_t temp = buf[i] >> 2;
+ temp = av_clipl_int32(MUL64(temp, temp) << 1);
+ denom = av_clipl_int32(denom + temp);
+ }
+
+ if (num && denom) {
+ bits1 = normalize_bits(num, 1);
+ bits2 = normalize_bits(denom, 1);
+ num = num << bits1 >> 1;
+ denom <<= bits2;
+
+ bits2 = 5 + bits1 - bits2;
+ bits2 = FFMAX(0, bits2);
+
+ gain = (num >> 1) / (denom >> 16);
+ gain = square_root(gain << 16 >> bits2);
+ } else {
+ gain = 1 << 12;
+ }
+
+ for (i = 0; i < SUBFRAME_LEN; i++) {
+ p->pf_gain = ((p->pf_gain << 4) - p->pf_gain + gain + (1 << 3)) >> 4;
+ buf[i] = av_clip_int16((buf[i] * (p->pf_gain + (p->pf_gain >> 4)) +
+ (1 << 10)) >> 11);
+ }
+}
+
+/**
+ * Perform formant filtering.
+ *
+ * @param p the context
+ * @param lpc quantized lpc coefficients
+ * @param buf output buffer
+ */
+static void formant_postfilter(G723_1_Context *p, int16_t *lpc, int16_t *buf)
+{
+ int16_t filter_coef[2][LPC_ORDER], *buf_ptr;
+ int filter_signal[LPC_ORDER + FRAME_LEN], *signal_ptr;
+ int i, j, k;
+
+ memcpy(buf, p->fir_mem, LPC_ORDER * sizeof(int16_t));
+ memcpy(filter_signal, p->iir_mem, LPC_ORDER * sizeof(int));
+
+ for (i = LPC_ORDER, j = 0; j < SUBFRAMES; i += SUBFRAME_LEN, j++) {
+ for (k = 0; k < LPC_ORDER; k++) {
+ filter_coef[0][k] = (-lpc[k] * postfilter_tbl[0][k] +
+ (1 << 14)) >> 15;
+ filter_coef[1][k] = (-lpc[k] * postfilter_tbl[1][k] +
+ (1 << 14)) >> 15;
+ }
+ iir_filter(filter_coef[0], filter_coef[1], buf + i,
+ filter_signal + i, 1);
+ }
+
+ memcpy(p->fir_mem, buf + FRAME_LEN, LPC_ORDER * sizeof(int16_t));
+ memcpy(p->iir_mem, filter_signal + FRAME_LEN, LPC_ORDER * sizeof(int));
+
+ buf_ptr = buf + LPC_ORDER;
+ signal_ptr = filter_signal + LPC_ORDER;
+ for (i = 0; i < SUBFRAMES; i++) {
+ int16_t temp_vector[SUBFRAME_LEN];
+ int16_t temp;
+ int auto_corr[2];
+ int scale, energy;
+
+ /* Normalize */
+ memcpy(temp_vector, buf_ptr, SUBFRAME_LEN * sizeof(int16_t));
+ scale = scale_vector(temp_vector, SUBFRAME_LEN);
+
+ /* Compute auto correlation coefficients */
+ auto_corr[0] = ff_dot_product(temp_vector, temp_vector + 1,
+ SUBFRAME_LEN - 1)<<1;
+ auto_corr[1] = ff_dot_product(temp_vector, temp_vector,
+ SUBFRAME_LEN)<<1;
+
+ /* Compute reflection coefficient */
+ temp = auto_corr[1] >> 16;
+ if (temp) {
+ temp = (auto_corr[0] >> 2) / temp;
+ }
+ p->reflection_coef = ((p->reflection_coef << 2) - p->reflection_coef +
+ temp + 2) >> 2;
+ temp = (p->reflection_coef * 0xffffc >> 3) & 0xfffc;
+
+ /* Compensation filter */
+ for (j = 0; j < SUBFRAME_LEN; j++) {
+ buf_ptr[j] = av_clipl_int32(signal_ptr[j] +
+ ((signal_ptr[j - 1] >> 16) *
+ temp << 1)) >> 16;
+ }
+
+ /* Compute normalized signal energy */
+ temp = 2 * scale + 4;
+ if (temp < 0) {
+ energy = av_clipl_int32((int64_t)auto_corr[1] << -temp);
+ } else
+ energy = auto_corr[1] >> temp;
+
+ gain_scale(p, buf_ptr, energy);
+
+ buf_ptr += SUBFRAME_LEN;
+ signal_ptr += SUBFRAME_LEN;
+ }
+}
+
+static int g723_1_decode_frame(AVCodecContext *avctx, void *data,
+ int *data_size, AVPacket *avpkt)
+{
+ G723_1_Context *p = avctx->priv_data;
+ const uint8_t *buf = avpkt->data;
+ int buf_size = avpkt->size;
+ int16_t *out = data;
+ int dec_mode = buf[0] & 3;
+
+ PPFParam ppf[SUBFRAMES];
+ int16_t cur_lsp[LPC_ORDER];
+ int16_t lpc[SUBFRAMES * LPC_ORDER];
+ int16_t acb_vector[SUBFRAME_LEN];
+ int16_t *vector_ptr;
+ int bad_frame = 0, i, j;
+
+ if (!buf_size || buf_size < frame_size[dec_mode]) {
+ *data_size = 0;
+ return buf_size;
+ }
+
+ if (unpack_bitstream(p, buf, buf_size) < 0) {
+ bad_frame = 1;
+ p->cur_frame_type = p->past_frame_type == ActiveFrame ?
+ ActiveFrame : UntransmittedFrame;
+ }
+
+ *data_size = FRAME_LEN * sizeof(int16_t);
+ if(p->cur_frame_type == ActiveFrame) {
+ if (!bad_frame) {
+ p->erased_frames = 0;
+ } else if(p->erased_frames != 3)
+ p->erased_frames++;
+
+ inverse_quant(cur_lsp, p->prev_lsp, p->lsp_index, bad_frame);
+ lsp_interpolate(lpc, cur_lsp, p->prev_lsp);
+
+ /* Save the lsp_vector for the next frame */
+ memcpy(p->prev_lsp, cur_lsp, LPC_ORDER * sizeof(int16_t));
+
+ /* Generate the excitation for the frame */
+ memcpy(p->excitation, p->prev_excitation, PITCH_MAX * sizeof(int16_t));
+ vector_ptr = p->excitation + PITCH_MAX;
+ if (!p->erased_frames) {
+ /* Update interpolation gain memory */
+ p->interp_gain = fixed_cb_gain[(p->subframe[2].amp_index +
+ p->subframe[3].amp_index) >> 1];
+ for (i = 0; i < SUBFRAMES; i++) {
+ gen_fcb_excitation(vector_ptr, p->subframe[i], p->cur_rate,
+ p->pitch_lag[i >> 1], i);
+ gen_acb_excitation(acb_vector, &p->excitation[SUBFRAME_LEN * i],
+ p->pitch_lag[i >> 1], p->subframe[i],
+ p->cur_rate);
+ /* Get the total excitation */
+ for (j = 0; j < SUBFRAME_LEN; j++) {
+ vector_ptr[j] = av_clip_int16(vector_ptr[j] << 1);
+ vector_ptr[j] = av_clip_int16(vector_ptr[j] +
+ acb_vector[j]);
+ }
+ vector_ptr += SUBFRAME_LEN;
+ }
+
+ vector_ptr = p->excitation + PITCH_MAX;
+
+ /* Save the excitation */
+ memcpy(out, vector_ptr, FRAME_LEN * sizeof(int16_t));
+
+ p->interp_index = comp_interp_index(p, p->pitch_lag[1],
+ &p->sid_gain, &p->cur_gain);
+
+ for (i = PITCH_MAX, j = 0; j < SUBFRAMES; i += SUBFRAME_LEN, j++)
+ comp_ppf_coeff(p, i, p->pitch_lag[j >> 1],
+ ppf + j, p->cur_rate);
+
+ /* Restore the original excitation */
+ memcpy(p->excitation, p->prev_excitation,
+ PITCH_MAX * sizeof(int16_t));
+ memcpy(vector_ptr, out, FRAME_LEN * sizeof(int16_t));
+
+ /* Peform pitch postfiltering */
+ for (i = 0, j = 0; j < SUBFRAMES; i += SUBFRAME_LEN, j++)
+ ff_acelp_weighted_vector_sum(out + LPC_ORDER + i, vector_ptr + i,
+ vector_ptr + i + ppf[j].index,
+ ppf[j].sc_gain, ppf[j].opt_gain,
+ 1 << 14, 15, SUBFRAME_LEN);
+ } else {
+ p->interp_gain = (p->interp_gain * 3 + 2) >> 2;
+ if (p->erased_frames == 3) {
+ /* Mute output */
+ memset(p->excitation, 0,
+ (FRAME_LEN + PITCH_MAX) * sizeof(int16_t));
+ memset(out, 0, (FRAME_LEN + LPC_ORDER) * sizeof(int16_t));
+ } else {
+ /* Regenerate frame */
+ residual_interp(p->excitation, out + LPC_ORDER, p->interp_index,
+ p->interp_gain, &p->random_seed);
+ }
+ }
+ /* Save the excitation for the next frame */
+ memcpy(p->prev_excitation, p->excitation + FRAME_LEN,
+ PITCH_MAX * sizeof(int16_t));
+ } else {
+ memset(out, 0, *data_size);
+ av_log(avctx, AV_LOG_WARNING,
+ "G.723.1: Comfort noise generation not supported yet\n");
+ return frame_size[dec_mode];
+ }
+
+ p->past_frame_type = p->cur_frame_type;
+
+ memcpy(out, p->synth_mem, LPC_ORDER * sizeof(int16_t));
+ for (i = LPC_ORDER, j = 0; j < SUBFRAMES; i += SUBFRAME_LEN, j++)
+ ff_celp_lp_synthesis_filter(out + i, &lpc[j * LPC_ORDER],
+ out + i, SUBFRAME_LEN, LPC_ORDER,
+ 0, 1, 1 << 12);
+ memcpy(p->synth_mem, out + FRAME_LEN, LPC_ORDER * sizeof(int16_t));
+
+ formant_postfilter(p, lpc, out);
+
+ memmove(out, out + LPC_ORDER, *data_size);
+
+ return frame_size[dec_mode];
+}
+
+AVCodec ff_g723_1_decoder = {
+ .name = "g723_1",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_G723_1,
+ .priv_data_size = sizeof(G723_1_Context),
+ .init = g723_1_decode_init,
+ .decode = g723_1_decode_frame,
+ .long_name = NULL_IF_CONFIG_SMALL("G.723.1"),
+ .capabilities = CODEC_CAP_SUBFRAMES,
+};
+
+#if CONFIG_G723_1_ENCODER
+#define BITSTREAM_WRITER_LE
+#include "put_bits.h"
+
+static av_cold int g723_1_encode_init(AVCodecContext *avctx)
+{
+ G723_1_Context *p = avctx->priv_data;
+
+ if (avctx->sample_rate != 8000) {
+ av_log(avctx, AV_LOG_ERROR, "Only 8000Hz sample rate supported\n");
+ return -1;
+ }
+
+ if (avctx->channels != 1) {
+ av_log(avctx, AV_LOG_ERROR, "Only mono supported\n");
+ return AVERROR(EINVAL);
+ }
+
+ if (avctx->bit_rate == 6300) {
+ p->cur_rate = Rate6k3;
+ } else if (avctx->bit_rate == 5300) {
+ av_log(avctx, AV_LOG_ERROR, "Bitrate not supported yet, use 6.3k\n");
+ return AVERROR_PATCHWELCOME;
+ } else {
+ av_log(avctx, AV_LOG_ERROR,
+ "Bitrate not supported, use 6.3k\n");
+ return AVERROR(EINVAL);
+ }
+ avctx->frame_size = 240;
+ memcpy(p->prev_lsp, dc_lsp, LPC_ORDER * sizeof(int16_t));
+
+ return 0;
+}
+
+/**
+ * Remove DC component from the input signal.
+ *
+ * @param buf input signal
+ * @param fir zero memory
+ * @param iir pole memory
+ */
+static void highpass_filter(int16_t *buf, int16_t *fir, int *iir)
+{
+ int i;
+ for (i = 0; i < FRAME_LEN; i++) {
+ *iir = (buf[i] << 15) + ((-*fir) << 15) + MULL2(*iir, 0x7f00);
+ *fir = buf[i];
+ buf[i] = av_clipl_int32((int64_t)*iir + (1 << 15)) >> 16;
+ }
+}
+
+/**
+ * Estimate autocorrelation of the input vector.
+ *
+ * @param buf input buffer
+ * @param autocorr autocorrelation coefficients vector
+ */
+static void comp_autocorr(int16_t *buf, int16_t *autocorr)
+{
+ int i, scale, temp;
+ int16_t vector[LPC_FRAME];
+
+ memcpy(vector, buf, LPC_FRAME * sizeof(int16_t));
+ scale_vector(vector, LPC_FRAME);
+
+ /* Apply the Hamming window */
+ for (i = 0; i < LPC_FRAME; i++)
+ vector[i] = (vector[i] * hamming_window[i] + (1 << 14)) >> 15;
+
+ /* Compute the first autocorrelation coefficient */
+ temp = dot_product(vector, vector, LPC_FRAME, 0);
+
+ /* Apply a white noise correlation factor of (1025/1024) */
+ temp += temp >> 10;
+
+ /* Normalize */
+ scale = normalize_bits_int32(temp);
+ autocorr[0] = av_clipl_int32((int64_t)(temp << scale) +
+ (1 << 15)) >> 16;
+
+ /* Compute the remaining coefficients */
+ if (!autocorr[0]) {
+ memset(autocorr + 1, 0, LPC_ORDER * sizeof(int16_t));
+ } else {
+ for (i = 1; i <= LPC_ORDER; i++) {
+ temp = dot_product(vector, vector + i, LPC_FRAME - i, 0);
+ temp = MULL2((temp << scale), binomial_window[i - 1]);
+ autocorr[i] = av_clipl_int32((int64_t)temp + (1 << 15)) >> 16;
+ }
+ }
+}
+
+/**
+ * Use Levinson-Durbin recursion to compute LPC coefficients from
+ * autocorrelation values.
+ *
+ * @param lpc LPC coefficients vector
+ * @param autocorr autocorrelation coefficients vector
+ * @param error prediction error
+ */
+static void levinson_durbin(int16_t *lpc, int16_t *autocorr, int16_t error)
+{
+ int16_t vector[LPC_ORDER];
+ int16_t partial_corr;
+ int i, j, temp;
+
+ memset(lpc, 0, LPC_ORDER * sizeof(int16_t));
+
+ for (i = 0; i < LPC_ORDER; i++) {
+ /* Compute the partial correlation coefficient */
+ temp = 0;
+ for (j = 0; j < i; j++)
+ temp -= lpc[j] * autocorr[i - j - 1];
+ temp = ((autocorr[i] << 13) + temp) << 3;
+
+ if (FFABS(temp) >= (error << 16))
+ break;
+
+ partial_corr = temp / (error << 1);
+
+ lpc[i] = av_clipl_int32((int64_t)(partial_corr << 14) +
+ (1 << 15)) >> 16;
+
+ /* Update the prediction error */
+ temp = MULL2(temp, partial_corr);
+ error = av_clipl_int32((int64_t)(error << 16) - temp +
+ (1 << 15)) >> 16;
+
+ memcpy(vector, lpc, i * sizeof(int16_t));
+ for (j = 0; j < i; j++) {
+ temp = partial_corr * vector[i - j - 1] << 1;
+ lpc[j] = av_clipl_int32((int64_t)(lpc[j] << 16) - temp +
+ (1 << 15)) >> 16;
+ }
+ }
+}
+
+/**
+ * Calculate LPC coefficients for the current frame.
+ *
+ * @param buf current frame
+ * @param prev_data 2 trailing subframes of the previous frame
+ * @param lpc LPC coefficients vector
+ */
+static void comp_lpc_coeff(int16_t *buf, int16_t *lpc)
+{
+ int16_t autocorr[(LPC_ORDER + 1) * SUBFRAMES];
+ int16_t *autocorr_ptr = autocorr;
+ int16_t *lpc_ptr = lpc;
+ int i, j;
+
+ for (i = 0, j = 0; j < SUBFRAMES; i += SUBFRAME_LEN, j++) {
+ comp_autocorr(buf + i, autocorr_ptr);
+ levinson_durbin(lpc_ptr, autocorr_ptr + 1, autocorr_ptr[0]);
+
+ lpc_ptr += LPC_ORDER;
+ autocorr_ptr += LPC_ORDER + 1;
+ }
+}
+
+static void lpc2lsp(int16_t *lpc, int16_t *prev_lsp, int16_t *lsp)
+{
+ int f[LPC_ORDER + 2]; ///< coefficients of the sum and difference
+ ///< polynomials (F1, F2) ordered as
+ ///< f1[0], f2[0], ...., f1[5], f2[5]
+
+ int max, shift, cur_val, prev_val, count, p;
+ int i, j;
+ int64_t temp;
+
+ /* Initialize f1[0] and f2[0] to 1 in Q25 */
+ for (i = 0; i < LPC_ORDER; i++)
+ lsp[i] = (lpc[i] * bandwidth_expand[i] + (1 << 14)) >> 15;
+
+ /* Apply bandwidth expansion on the LPC coefficients */
+ f[0] = f[1] = 1 << 25;
+
+ /* Compute the remaining coefficients */
+ for (i = 0; i < LPC_ORDER / 2; i++) {
+ /* f1 */
+ f[2 * i + 2] = -f[2 * i] - ((lsp[i] + lsp[LPC_ORDER - 1 - i]) << 12);
+ /* f2 */
+ f[2 * i + 3] = f[2 * i + 1] - ((lsp[i] - lsp[LPC_ORDER - 1 - i]) << 12);
+ }
+
+ /* Divide f1[5] and f2[5] by 2 for use in polynomial evaluation */
+ f[LPC_ORDER] >>= 1;
+ f[LPC_ORDER + 1] >>= 1;
+
+ /* Normalize and shorten */
+ max = FFABS(f[0]);
+ for (i = 1; i < LPC_ORDER + 2; i++)
+ max = FFMAX(max, FFABS(f[i]));
+
+ shift = normalize_bits_int32(max);
+
+ for (i = 0; i < LPC_ORDER + 2; i++)
+ f[i] = av_clipl_int32((int64_t)(f[i] << shift) + (1 << 15)) >> 16;
+
+ /**
+ * Evaluate F1 and F2 at uniform intervals of pi/256 along the
+ * unit circle and check for zero crossings.
+ */
+ p = 0;
+ temp = 0;
+ for (i = 0; i <= LPC_ORDER / 2; i++)
+ temp += f[2 * i] * cos_tab[0];
+ prev_val = av_clipl_int32(temp << 1);
+ count = 0;
+ for ( i = 1; i < COS_TBL_SIZE / 2; i++) {
+ /* Evaluate */
+ temp = 0;
+ for (j = 0; j <= LPC_ORDER / 2; j++)
+ temp += f[LPC_ORDER - 2 * j + p] * cos_tab[i * j % COS_TBL_SIZE];
+ cur_val = av_clipl_int32(temp << 1);
+
+ /* Check for sign change, indicating a zero crossing */
+ if ((cur_val ^ prev_val) < 0) {
+ int abs_cur = FFABS(cur_val);
+ int abs_prev = FFABS(prev_val);
+ int sum = abs_cur + abs_prev;
+
+ shift = normalize_bits_int32(sum);
+ sum <<= shift;
+ abs_prev = abs_prev << shift >> 8;
+ lsp[count++] = ((i - 1) << 7) + (abs_prev >> 1) / (sum >> 16);
+
+ if (count == LPC_ORDER)
+ break;
+
+ /* Switch between sum and difference polynomials */
+ p ^= 1;
+
+ /* Evaluate */
+ temp = 0;
+ for (j = 0; j <= LPC_ORDER / 2; j++){
+ temp += f[LPC_ORDER - 2 * j + p] *
+ cos_tab[i * j % COS_TBL_SIZE];
+ }
+ cur_val = av_clipl_int32(temp<<1);
+ }
+ prev_val = cur_val;
+ }
+
+ if (count != LPC_ORDER)
+ memcpy(lsp, prev_lsp, LPC_ORDER * sizeof(int16_t));
+}
+
+/**
+ * Quantize the current LSP subvector.
+ *
+ * @param num band number
+ * @param offset offset of the current subvector in an LPC_ORDER vector
+ * @param size size of the current subvector
+ */
+#define get_index(num, offset, size) \
+{\
+ int error, max = -1;\
+ int16_t temp[4];\
+ int i, j;\
+ for (i = 0; i < LSP_CB_SIZE; i++) {\
+ for (j = 0; j < size; j++){\
+ temp[j] = (weight[j + (offset)] * lsp_band##num[i][j] +\
+ (1 << 14)) >> 15;\
+ }\
+ error = dot_product(lsp + (offset), temp, size, 1) << 1;\
+ error -= dot_product(lsp_band##num[i], temp, size, 1);\
+ if (error > max) {\
+ max = error;\
+ lsp_index[num] = i;\
+ }\
+ }\
+}
+
+/**
+ * Vector quantize the LSP frequencies.
+ *
+ * @param lsp the current lsp vector
+ * @param prev_lsp the previous lsp vector
+ */
+static void lsp_quantize(uint8_t *lsp_index, int16_t *lsp, int16_t *prev_lsp)
+{
+ int16_t weight[LPC_ORDER];
+ int16_t min, max;
+ int shift, i;
+
+ /* Calculate the VQ weighting vector */
+ weight[0] = (1 << 20) / (lsp[1] - lsp[0]);
+ weight[LPC_ORDER - 1] = (1 << 20) /
+ (lsp[LPC_ORDER - 1] - lsp[LPC_ORDER - 2]);
+
+ for (i = 1; i < LPC_ORDER - 1; i++) {
+ min = FFMIN(lsp[i] - lsp[i - 1], lsp[i + 1] - lsp[i]);
+ if (min > 0x20)
+ weight[i] = (1 << 20) / min;
+ else
+ weight[i] = INT16_MAX;
+ }
+
+ /* Normalize */
+ max = 0;
+ for (i = 0; i < LPC_ORDER; i++)
+ max = FFMAX(weight[i], max);
+
+ shift = normalize_bits_int16(max);
+ for (i = 0; i < LPC_ORDER; i++) {
+ weight[i] <<= shift;
+ }
+
+ /* Compute the VQ target vector */
+ for (i = 0; i < LPC_ORDER; i++) {
+ lsp[i] -= dc_lsp[i] +
+ (((prev_lsp[i] - dc_lsp[i]) * 12288 + (1 << 14)) >> 15);
+ }
+
+ get_index(0, 0, 3);
+ get_index(1, 3, 3);
+ get_index(2, 6, 4);
+}
+
+/**
+ * Apply the formant perceptual weighting filter.
+ *
+ * @param flt_coef filter coefficients
+ * @param unq_lpc unquantized lpc vector
+ */
+static void perceptual_filter(G723_1_Context *p, int16_t *flt_coef,
+ int16_t *unq_lpc, int16_t *buf)
+{
+ int16_t vector[FRAME_LEN + LPC_ORDER];
+ int i, j, k, l = 0;
+
+ memcpy(buf, p->iir_mem, sizeof(int16_t) * LPC_ORDER);
+ memcpy(vector, p->fir_mem, sizeof(int16_t) * LPC_ORDER);
+ memcpy(vector + LPC_ORDER, buf + LPC_ORDER, sizeof(int16_t) * FRAME_LEN);
+
+ for (i = LPC_ORDER, j = 0; j < SUBFRAMES; i += SUBFRAME_LEN, j++) {
+ for (k = 0; k < LPC_ORDER; k++) {
+ flt_coef[k + 2 * l] = (unq_lpc[k + l] * percept_flt_tbl[0][k] +
+ (1 << 14)) >> 15;
+ flt_coef[k + 2 * l + LPC_ORDER] = (unq_lpc[k + l] *
+ percept_flt_tbl[1][k] +
+ (1 << 14)) >> 15;
+ }
+ iir_filter(flt_coef + 2 * l, flt_coef + 2 * l + LPC_ORDER, vector + i,
+ buf + i, 0);
+ l += LPC_ORDER;
+ }
+ memcpy(p->iir_mem, buf + FRAME_LEN, sizeof(int16_t) * LPC_ORDER);
+ memcpy(p->fir_mem, vector + FRAME_LEN, sizeof(int16_t) * LPC_ORDER);
+}
+
+/**
+ * Estimate the open loop pitch period.
+ *
+ * @param buf perceptually weighted speech
+ * @param start estimation is carried out from this position
+ */
+static int estimate_pitch(int16_t *buf, int start)
+{
+ int max_exp = 32;
+ int max_ccr = 0x4000;
+ int max_eng = 0x7fff;
+ int index = PITCH_MIN;
+ int offset = start - PITCH_MIN + 1;
+
+ int ccr, eng, orig_eng, ccr_eng, exp;
+ int diff, temp;
+
+ int i;
+
+ orig_eng = dot_product(buf + offset, buf + offset, HALF_FRAME_LEN, 0);
+
+ for (i = PITCH_MIN; i <= PITCH_MAX - 3; i++) {
+ offset--;
+
+ /* Update energy and compute correlation */
+ orig_eng += buf[offset] * buf[offset] -
+ buf[offset + HALF_FRAME_LEN] * buf[offset + HALF_FRAME_LEN];
+ ccr = dot_product(buf + start, buf + offset, HALF_FRAME_LEN, 0);
+ if (ccr <= 0)
+ continue;
+
+ /* Split into mantissa and exponent to maintain precision */
+ exp = normalize_bits_int32(ccr);
+ ccr = av_clipl_int32((int64_t)(ccr << exp) + (1 << 15)) >> 16;
+ exp <<= 1;
+ ccr *= ccr;
+ temp = normalize_bits_int32(ccr);
+ ccr = ccr << temp >> 16;
+ exp += temp;
+
+ temp = normalize_bits_int32(orig_eng);
+ eng = av_clipl_int32((int64_t)(orig_eng << temp) + (1 << 15)) >> 16;
+ exp -= temp;
+
+ if (ccr >= eng) {
+ exp--;
+ ccr >>= 1;
+ }
+ if (exp > max_exp)
+ continue;
+
+ if (exp + 1 < max_exp)
+ goto update;
+
+ /* Equalize exponents before comparison */
+ if (exp + 1 == max_exp)
+ temp = max_ccr >> 1;
+ else
+ temp = max_ccr;
+ ccr_eng = ccr * max_eng;
+ diff = ccr_eng - eng * temp;
+ if (diff > 0 && (i - index < PITCH_MIN || diff > ccr_eng >> 2)) {
+update:
+ index = i;
+ max_exp = exp;
+ max_ccr = ccr;
+ max_eng = eng;
+ }
+ }
+ return index;
+}
+
+/**
+ * Compute harmonic noise filter parameters.
+ *
+ * @param buf perceptually weighted speech
+ * @param pitch_lag open loop pitch period
+ * @param hf harmonic filter parameters
+ */
+static void comp_harmonic_coeff(int16_t *buf, int16_t pitch_lag, HFParam *hf)
+{
+ int ccr, eng, max_ccr, max_eng;
+ int exp, max, diff;
+ int energy[15];
+ int i, j;
+
+ for (i = 0, j = pitch_lag - 3; j <= pitch_lag + 3; i++, j++) {
+ /* Compute residual energy */
+ energy[i << 1] = dot_product(buf - j, buf - j, SUBFRAME_LEN, 0);
+ /* Compute correlation */
+ energy[(i << 1) + 1] = dot_product(buf, buf - j, SUBFRAME_LEN, 0);
+ }
+
+ /* Compute target energy */
+ energy[14] = dot_product(buf, buf, SUBFRAME_LEN, 0);
+
+ /* Normalize */
+ max = 0;
+ for (i = 0; i < 15; i++)
+ max = FFMAX(max, FFABS(energy[i]));
+
+ exp = normalize_bits_int32(max);
+ for (i = 0; i < 15; i++) {
+ energy[i] = av_clipl_int32((int64_t)(energy[i] << exp) +
+ (1 << 15)) >> 16;
+ }
+
+ hf->index = -1;
+ hf->gain = 0;
+ max_ccr = 1;
+ max_eng = 0x7fff;
+
+ for (i = 0; i <= 6; i++) {
+ eng = energy[i << 1];
+ ccr = energy[(i << 1) + 1];
+
+ if (ccr <= 0)
+ continue;
+
+ ccr = (ccr * ccr + (1 << 14)) >> 15;
+ diff = ccr * max_eng - eng * max_ccr;
+ if (diff > 0) {
+ max_ccr = ccr;
+ max_eng = eng;
+ hf->index = i;
+ }
+ }
+
+ if (hf->index == -1) {
+ hf->index = pitch_lag;
+ return;
+ }
+
+ eng = energy[14] * max_eng;
+ eng = (eng >> 2) + (eng >> 3);
+ ccr = energy[(hf->index << 1) + 1] * energy[(hf->index << 1) + 1];
+ if (eng < ccr) {
+ eng = energy[(hf->index << 1) + 1];
+
+ if (eng >= max_eng)
+ hf->gain = 0x2800;
+ else
+ hf->gain = ((eng << 15) / max_eng * 0x2800 + (1 << 14)) >> 15;
+ }
+ hf->index += pitch_lag - 3;
+}
+
+/**
+ * Apply the harmonic noise shaping filter.
+ *
+ * @param hf filter parameters
+ */
+static void harmonic_filter(HFParam *hf, int16_t *src, int16_t *dest)
+{
+ int i;
+
+ for (i = 0; i < SUBFRAME_LEN; i++) {
+ int64_t temp = hf->gain * src[i - hf->index] << 1;
+ dest[i] = av_clipl_int32((src[i] << 16) - temp + (1 << 15)) >> 16;
+ }
+}
+
+static void harmonic_noise_sub(HFParam *hf, int16_t *src, int16_t *dest)
+{
+ int i;
+ for (i = 0; i < SUBFRAME_LEN; i++) {
+ int64_t temp = hf->gain * src[i - hf->index] << 1;
+ dest[i] = av_clipl_int32(((dest[i] - src[i]) << 16) + temp +
+ (1 << 15)) >> 16;
+
+ }
+}
+
+/**
+ * Combined synthesis and formant perceptual weighting filer.
+ *
+ * @param qnt_lpc quantized lpc coefficients
+ * @param perf_lpc perceptual filter coefficients
+ * @param perf_fir perceptual filter fir memory
+ * @param perf_iir perceptual filter iir memory
+ * @param scale the filter output will be scaled by 2^scale
+ */
+static void synth_percept_filter(int16_t *qnt_lpc, int16_t *perf_lpc,
+ int16_t *perf_fir, int16_t *perf_iir,
+ int16_t *src, int16_t *dest, int scale)
+{
+ int i, j;
+ int16_t buf_16[SUBFRAME_LEN + LPC_ORDER];
+ int64_t buf[SUBFRAME_LEN];
+
+ int16_t *bptr_16 = buf_16 + LPC_ORDER;
+
+ memcpy(buf_16, perf_fir, sizeof(int16_t) * LPC_ORDER);
+ memcpy(dest - LPC_ORDER, perf_iir, sizeof(int16_t) * LPC_ORDER);
+
+ for (i = 0; i < SUBFRAME_LEN; i++) {
+ int64_t temp = 0;
+ for (j = 1; j <= LPC_ORDER; j++)
+ temp -= qnt_lpc[j - 1] * bptr_16[i - j];
+
+ buf[i] = (src[i] << 15) + (temp << 3);
+ bptr_16[i] = av_clipl_int32(buf[i] + (1 << 15)) >> 16;
+ }
+
+ for (i = 0; i < SUBFRAME_LEN; i++) {
+ int64_t fir = 0, iir = 0;
+ for (j = 1; j <= LPC_ORDER; j++) {
+ fir -= perf_lpc[j - 1] * bptr_16[i - j];
+ iir += perf_lpc[j + LPC_ORDER - 1] * dest[i - j];
+ }
+ dest[i] = av_clipl_int32(((buf[i] + (fir << 3)) << scale) + (iir << 3) +
+ (1 << 15)) >> 16;
+ }
+ memcpy(perf_fir, buf_16 + SUBFRAME_LEN, sizeof(int16_t) * LPC_ORDER);
+ memcpy(perf_iir, dest + SUBFRAME_LEN - LPC_ORDER,
+ sizeof(int16_t) * LPC_ORDER);
+}
+
+/**
+ * Compute the adaptive codebook contribution.
+ *
+ * @param buf input signal
+ * @param index the current subframe index
+ */
+static void acb_search(G723_1_Context *p, int16_t *residual,
+ int16_t *impulse_resp, int16_t *buf,
+ int index)
+{
+
+ int16_t flt_buf[PITCH_ORDER][SUBFRAME_LEN];
+
+ const int16_t *cb_tbl = adaptive_cb_gain85;
+
+ int ccr_buf[PITCH_ORDER * SUBFRAMES << 2];
+
+ int pitch_lag = p->pitch_lag[index >> 1];
+ int acb_lag = 1;
+ int acb_gain = 0;
+ int odd_frame = index & 1;
+ int iter = 3 + odd_frame;
+ int count = 0;
+ int tbl_size = 85;
+
+ int i, j, k, l, max;
+ int64_t temp;
+
+ if (!odd_frame) {
+ if (pitch_lag == PITCH_MIN)
+ pitch_lag++;
+ else
+ pitch_lag = FFMIN(pitch_lag, PITCH_MAX - 5);
+ }
+
+ for (i = 0; i < iter; i++) {
+ get_residual(residual, p->prev_excitation, pitch_lag + i - 1);
+
+ for (j = 0; j < SUBFRAME_LEN; j++) {
+ temp = 0;
+ for (k = 0; k <= j; k++)
+ temp += residual[PITCH_ORDER - 1 + k] * impulse_resp[j - k];
+ flt_buf[PITCH_ORDER - 1][j] = av_clipl_int32((temp << 1) +
+ (1 << 15)) >> 16;
+ }
+
+ for (j = PITCH_ORDER - 2; j >= 0; j--) {
+ flt_buf[j][0] = ((residual[j] << 13) + (1 << 14)) >> 15;
+ for (k = 1; k < SUBFRAME_LEN; k++) {
+ temp = (flt_buf[j + 1][k - 1] << 15) +
+ residual[j] * impulse_resp[k];
+ flt_buf[j][k] = av_clipl_int32((temp << 1) + (1 << 15)) >> 16;
+ }
+ }
+
+ /* Compute crosscorrelation with the signal */
+ for (j = 0; j < PITCH_ORDER; j++) {
+ temp = dot_product(buf, flt_buf[j], SUBFRAME_LEN, 0);
+ ccr_buf[count++] = av_clipl_int32(temp << 1);
+ }
+
+ /* Compute energies */
+ for (j = 0; j < PITCH_ORDER; j++) {
+ ccr_buf[count++] = dot_product(flt_buf[j], flt_buf[j],
+ SUBFRAME_LEN, 1);
+ }
+
+ for (j = 1; j < PITCH_ORDER; j++) {
+ for (k = 0; k < j; k++) {
+ temp = dot_product(flt_buf[j], flt_buf[k], SUBFRAME_LEN, 0);
+ ccr_buf[count++] = av_clipl_int32(temp<<2);
+ }
+ }
+ }
+
+ /* Normalize and shorten */
+ max = 0;
+ for (i = 0; i < 20 * iter; i++)
+ max = FFMAX(max, FFABS(ccr_buf[i]));
+
+ temp = normalize_bits_int32(max);
+
+ for (i = 0; i < 20 * iter; i++){
+ ccr_buf[i] = av_clipl_int32((int64_t)(ccr_buf[i] << temp) +
+ (1 << 15)) >> 16;
+ }
+
+ max = 0;
+ for (i = 0; i < iter; i++) {
+ /* Select quantization table */
+ if (!odd_frame && pitch_lag + i - 1 >= SUBFRAME_LEN - 2 ||
+ odd_frame && pitch_lag >= SUBFRAME_LEN - 2) {
+ cb_tbl = adaptive_cb_gain170;
+ tbl_size = 170;
+ }
+
+ for (j = 0, k = 0; j < tbl_size; j++, k += 20) {
+ temp = 0;
+ for (l = 0; l < 20; l++)
+ temp += ccr_buf[20 * i + l] * cb_tbl[k + l];
+ temp = av_clipl_int32(temp);
+
+ if (temp > max) {
+ max = temp;
+ acb_gain = j;
+ acb_lag = i;
+ }
+ }
+ }
+
+ if (!odd_frame) {
+ pitch_lag += acb_lag - 1;
+ acb_lag = 1;
+ }
+
+ p->pitch_lag[index >> 1] = pitch_lag;
+ p->subframe[index].ad_cb_lag = acb_lag;
+ p->subframe[index].ad_cb_gain = acb_gain;
+}
+
+/**
+ * Subtract the adaptive codebook contribution from the input
+ * to obtain the residual.
+ *
+ * @param buf target vector
+ */
+static void sub_acb_contrib(int16_t *residual, int16_t *impulse_resp,
+ int16_t *buf)
+{
+ int i, j;
+ /* Subtract adaptive CB contribution to obtain the residual */
+ for (i = 0; i < SUBFRAME_LEN; i++) {
+ int64_t temp = buf[i] << 14;
+ for (j = 0; j <= i; j++)
+ temp -= residual[j] * impulse_resp[i - j];
+
+ buf[i] = av_clipl_int32((temp << 2) + (1 << 15)) >> 16;
+ }
+}
+
+/**
+ * Quantize the residual signal using the fixed codebook (MP-MLQ).
+ *
+ * @param optim optimized fixed codebook parameters
+ * @param buf excitation vector
+ */
+static void get_fcb_param(FCBParam *optim, int16_t *impulse_resp,
+ int16_t *buf, int pulse_cnt, int pitch_lag)
+{
+ FCBParam param;
+ int16_t impulse_r[SUBFRAME_LEN];
+ int16_t temp_corr[SUBFRAME_LEN];
+ int16_t impulse_corr[SUBFRAME_LEN];
+
+ int ccr1[SUBFRAME_LEN];
+ int ccr2[SUBFRAME_LEN];
+ int amp, err, max, max_amp_index, min, scale, i, j, k, l;
+
+ int64_t temp;
+
+ /* Update impulse response */
+ memcpy(impulse_r, impulse_resp, sizeof(int16_t) * SUBFRAME_LEN);
+ param.dirac_train = 0;
+ if (pitch_lag < SUBFRAME_LEN - 2) {
+ param.dirac_train = 1;
+ gen_dirac_train(impulse_r, pitch_lag);
+ }
+
+ for (i = 0; i < SUBFRAME_LEN; i++)
+ temp_corr[i] = impulse_r[i] >> 1;
+
+ /* Compute impulse response autocorrelation */
+ temp = dot_product(temp_corr, temp_corr, SUBFRAME_LEN, 1);
+
+ scale = normalize_bits_int32(temp);
+ impulse_corr[0] = av_clipl_int32((temp << scale) + (1 << 15)) >> 16;
+
+ for (i = 1; i < SUBFRAME_LEN; i++) {
+ temp = dot_product(temp_corr + i, temp_corr, SUBFRAME_LEN - i, 1);
+ impulse_corr[i] = av_clipl_int32((temp << scale) + (1 << 15)) >> 16;
+ }
+
+ /* Compute crosscorrelation of impulse response with residual signal */
+ scale -= 4;
+ for (i = 0; i < SUBFRAME_LEN; i++){
+ temp = dot_product(buf + i, impulse_r, SUBFRAME_LEN - i, 1);
+ if (scale < 0)
+ ccr1[i] = temp >> -scale;
+ else
+ ccr1[i] = av_clipl_int32(temp << scale);
+ }
+
+ /* Search loop */
+ for (i = 0; i < GRID_SIZE; i++) {
+ /* Maximize the crosscorrelation */
+ max = 0;
+ for (j = i; j < SUBFRAME_LEN; j += GRID_SIZE) {
+ temp = FFABS(ccr1[j]);
+ if (temp >= max) {
+ max = temp;
+ param.pulse_pos[0] = j;
+ }
+ }
+
+ /* Quantize the gain (max crosscorrelation/impulse_corr[0]) */
+ amp = max;
+ min = 1 << 30;
+ max_amp_index = GAIN_LEVELS - 2;
+ for (j = max_amp_index; j >= 2; j--) {
+ temp = av_clipl_int32((int64_t)fixed_cb_gain[j] *
+ impulse_corr[0] << 1);
+ temp = FFABS(temp - amp);
+ if (temp < min) {
+ min = temp;
+ max_amp_index = j;
+ }
+ }
+
+ max_amp_index--;
+ /* Select additional gain values */
+ for (j = 1; j < 5; j++) {
+ for (k = i; k < SUBFRAME_LEN; k += GRID_SIZE) {
+ temp_corr[k] = 0;
+ ccr2[k] = ccr1[k];
+ }
+ param.amp_index = max_amp_index + j - 2;
+ amp = fixed_cb_gain[param.amp_index];
+
+ param.pulse_sign[0] = (ccr2[param.pulse_pos[0]] < 0) ? -amp : amp;
+ temp_corr[param.pulse_pos[0]] = 1;
+
+ for (k = 1; k < pulse_cnt; k++) {
+ max = -1 << 30;
+ for (l = i; l < SUBFRAME_LEN; l += GRID_SIZE) {
+ if (temp_corr[l])
+ continue;
+ temp = impulse_corr[FFABS(l - param.pulse_pos[k - 1])];
+ temp = av_clipl_int32((int64_t)temp *
+ param.pulse_sign[k - 1] << 1);
+ ccr2[l] -= temp;
+ temp = FFABS(ccr2[l]);
+ if (temp > max) {
+ max = temp;
+ param.pulse_pos[k] = l;
+ }
+ }
+
+ param.pulse_sign[k] = (ccr2[param.pulse_pos[k]] < 0) ?
+ -amp : amp;
+ temp_corr[param.pulse_pos[k]] = 1;
+ }
+
+ /* Create the error vector */
+ memset(temp_corr, 0, sizeof(int16_t) * SUBFRAME_LEN);
+
+ for (k = 0; k < pulse_cnt; k++)
+ temp_corr[param.pulse_pos[k]] = param.pulse_sign[k];
+
+ for (k = SUBFRAME_LEN - 1; k >= 0; k--) {
+ temp = 0;
+ for (l = 0; l <= k; l++) {
+ int prod = av_clipl_int32((int64_t)temp_corr[l] *
+ impulse_r[k - l] << 1);
+ temp = av_clipl_int32(temp + prod);
+ }
+ temp_corr[k] = temp << 2 >> 16;
+ }
+
+ /* Compute square of error */
+ err = 0;
+ for (k = 0; k < SUBFRAME_LEN; k++) {
+ int64_t prod;
+ prod = av_clipl_int32((int64_t)buf[k] * temp_corr[k] << 1);
+ err = av_clipl_int32(err - prod);
+ prod = av_clipl_int32((int64_t)temp_corr[k] * temp_corr[k]);
+ err = av_clipl_int32(err + prod);
+ }
+
+ /* Minimize */
+ if (err < optim->min_err) {
+ optim->min_err = err;
+ optim->grid_index = i;
+ optim->amp_index = param.amp_index;
+ optim->dirac_train = param.dirac_train;
+
+ for (k = 0; k < pulse_cnt; k++) {
+ optim->pulse_sign[k] = param.pulse_sign[k];
+ optim->pulse_pos[k] = param.pulse_pos[k];
+ }
+ }
+ }
+ }
+}
+
+/**
+ * Encode the pulse position and gain of the current subframe.
+ *
+ * @param optim optimized fixed CB parameters
+ * @param buf excitation vector
+ */
+static void pack_fcb_param(G723_1_Subframe *subfrm, FCBParam *optim,
+ int16_t *buf, int pulse_cnt)
+{
+ int i, j;
+
+ j = PULSE_MAX - pulse_cnt;
+
+ subfrm->pulse_sign = 0;
+ subfrm->pulse_pos = 0;
+
+ for (i = 0; i < SUBFRAME_LEN >> 1; i++) {
+ int val = buf[optim->grid_index + (i << 1)];
+ if (!val) {
+ subfrm->pulse_pos += combinatorial_table[j][i];
+ } else {
+ subfrm->pulse_sign <<= 1;
+ if (val < 0) subfrm->pulse_sign++;
+ j++;
+
+ if (j == PULSE_MAX) break;
+ }
+ }
+ subfrm->amp_index = optim->amp_index;
+ subfrm->grid_index = optim->grid_index;
+ subfrm->dirac_train = optim->dirac_train;
+}
+
+/**
+ * Compute the fixed codebook excitation.
+ *
+ * @param buf target vector
+ * @param impulse_resp impulse response of the combined filter
+ */
+static void fcb_search(G723_1_Context *p, int16_t *impulse_resp,
+ int16_t *buf, int index)
+{
+ FCBParam optim;
+ int pulse_cnt = pulses[index];
+ int i;
+
+ optim.min_err = 1 << 30;
+ get_fcb_param(&optim, impulse_resp, buf, pulse_cnt, SUBFRAME_LEN);
+
+ if (p->pitch_lag[index >> 1] < SUBFRAME_LEN - 2) {
+ get_fcb_param(&optim, impulse_resp, buf, pulse_cnt,
+ p->pitch_lag[index >> 1]);
+ }
+
+ /* Reconstruct the excitation */
+ memset(buf, 0, sizeof(int16_t) * SUBFRAME_LEN);
+ for (i = 0; i < pulse_cnt; i++)
+ buf[optim.pulse_pos[i]] = optim.pulse_sign[i];
+
+ pack_fcb_param(&p->subframe[index], &optim, buf, pulse_cnt);
+
+ if (optim.dirac_train)
+ gen_dirac_train(buf, p->pitch_lag[index >> 1]);
+}
+
+/**
+ * Pack the frame parameters into output bitstream.
+ *
+ * @param frame output buffer
+ * @param size size of the buffer
+ */
+static int pack_bitstream(G723_1_Context *p, unsigned char *frame, int size)
+{
+ PutBitContext pb;
+ int info_bits, i, temp;
+
+ init_put_bits(&pb, frame, size);
+
+ if (p->cur_rate == Rate6k3) {
+ info_bits = 0;
+ put_bits(&pb, 2, info_bits);
+ }
+
+ put_bits(&pb, 8, p->lsp_index[2]);
+ put_bits(&pb, 8, p->lsp_index[1]);
+ put_bits(&pb, 8, p->lsp_index[0]);
+
+ put_bits(&pb, 7, p->pitch_lag[0] - PITCH_MIN);
+ put_bits(&pb, 2, p->subframe[1].ad_cb_lag);
+ put_bits(&pb, 7, p->pitch_lag[1] - PITCH_MIN);
+ put_bits(&pb, 2, p->subframe[3].ad_cb_lag);
+
+ /* Write 12 bit combined gain */
+ for (i = 0; i < SUBFRAMES; i++) {
+ temp = p->subframe[i].ad_cb_gain * GAIN_LEVELS +
+ p->subframe[i].amp_index;
+ if (p->cur_rate == Rate6k3)
+ temp += p->subframe[i].dirac_train << 11;
+ put_bits(&pb, 12, temp);
+ }
+
+ put_bits(&pb, 1, p->subframe[0].grid_index);
+ put_bits(&pb, 1, p->subframe[1].grid_index);
+ put_bits(&pb, 1, p->subframe[2].grid_index);
+ put_bits(&pb, 1, p->subframe[3].grid_index);
+
+ if (p->cur_rate == Rate6k3) {
+ skip_put_bits(&pb, 1); /* reserved bit */
+
+ /* Write 13 bit combined position index */
+ temp = (p->subframe[0].pulse_pos >> 16) * 810 +
+ (p->subframe[1].pulse_pos >> 14) * 90 +
+ (p->subframe[2].pulse_pos >> 16) * 9 +
+ (p->subframe[3].pulse_pos >> 14);
+ put_bits(&pb, 13, temp);
+
+ put_bits(&pb, 16, p->subframe[0].pulse_pos & 0xffff);
+ put_bits(&pb, 14, p->subframe[1].pulse_pos & 0x3fff);
+ put_bits(&pb, 16, p->subframe[2].pulse_pos & 0xffff);
+ put_bits(&pb, 14, p->subframe[3].pulse_pos & 0x3fff);
+
+ put_bits(&pb, 6, p->subframe[0].pulse_sign);
+ put_bits(&pb, 5, p->subframe[1].pulse_sign);
+ put_bits(&pb, 6, p->subframe[2].pulse_sign);
+ put_bits(&pb, 5, p->subframe[3].pulse_sign);
+ }
+
+ flush_put_bits(&pb);
+ return frame_size[info_bits];
+}
+
+static int g723_1_encode_frame(AVCodecContext *avctx, unsigned char *buf,
+ int buf_size, void *data)
+{
+ G723_1_Context *p = avctx->priv_data;
+ int16_t unq_lpc[LPC_ORDER * SUBFRAMES];
+ int16_t qnt_lpc[LPC_ORDER * SUBFRAMES];
+ int16_t cur_lsp[LPC_ORDER];
+ int16_t weighted_lpc[LPC_ORDER * SUBFRAMES << 1];
+ int16_t vector[FRAME_LEN + PITCH_MAX];
+ int offset;
+ int16_t *in = data;
+
+ HFParam hf[4];
+ int i, j;
+
+ highpass_filter(in, &p->hpf_fir_mem, &p->hpf_iir_mem);
+
+ memcpy(vector, p->prev_data, HALF_FRAME_LEN * sizeof(int16_t));
+ memcpy(vector + HALF_FRAME_LEN, in, FRAME_LEN * sizeof(int16_t));
+
+ comp_lpc_coeff(vector, unq_lpc);
+ lpc2lsp(&unq_lpc[LPC_ORDER * 3], p->prev_lsp, cur_lsp);
+ lsp_quantize(p->lsp_index, cur_lsp, p->prev_lsp);
+
+ /* Update memory */
+ memcpy(vector + LPC_ORDER, p->prev_data + SUBFRAME_LEN,
+ sizeof(int16_t) * SUBFRAME_LEN);
+ memcpy(vector + LPC_ORDER + SUBFRAME_LEN, in,
+ sizeof(int16_t) * (HALF_FRAME_LEN + SUBFRAME_LEN));
+ memcpy(p->prev_data, in + HALF_FRAME_LEN,
+ sizeof(int16_t) * HALF_FRAME_LEN);
+ memcpy(in, vector + LPC_ORDER, sizeof(int16_t) * FRAME_LEN);
+
+ perceptual_filter(p, weighted_lpc, unq_lpc, vector);
+
+ memcpy(in, vector + LPC_ORDER, sizeof(int16_t) * FRAME_LEN);
+ memcpy(vector, p->prev_weight_sig, sizeof(int16_t) * PITCH_MAX);
+ memcpy(vector + PITCH_MAX, in, sizeof(int16_t) * FRAME_LEN);
+
+ scale_vector(vector, FRAME_LEN + PITCH_MAX);
+
+ p->pitch_lag[0] = estimate_pitch(vector, PITCH_MAX);
+ p->pitch_lag[1] = estimate_pitch(vector, PITCH_MAX + HALF_FRAME_LEN);
+
+ for (i = PITCH_MAX, j = 0; j < SUBFRAMES; i += SUBFRAME_LEN, j++)
+ comp_harmonic_coeff(vector + i, p->pitch_lag[j >> 1], hf + j);
+
+ memcpy(vector, p->prev_weight_sig, sizeof(int16_t) * PITCH_MAX);
+ memcpy(vector + PITCH_MAX, in, sizeof(int16_t) * FRAME_LEN);
+ memcpy(p->prev_weight_sig, vector + FRAME_LEN, sizeof(int16_t) * PITCH_MAX);
+
+ for (i = 0, j = 0; j < SUBFRAMES; i += SUBFRAME_LEN, j++)
+ harmonic_filter(hf + j, vector + PITCH_MAX + i, in + i);
+
+ inverse_quant(cur_lsp, p->prev_lsp, p->lsp_index, 0);
+ lsp_interpolate(qnt_lpc, cur_lsp, p->prev_lsp);
+
+ memcpy(p->prev_lsp, cur_lsp, sizeof(int16_t) * LPC_ORDER);
+
+ offset = 0;
+ for (i = 0; i < SUBFRAMES; i++) {
+ int16_t impulse_resp[SUBFRAME_LEN];
+ int16_t residual[SUBFRAME_LEN + PITCH_ORDER - 1];
+ int16_t flt_in[SUBFRAME_LEN];
+ int16_t zero[LPC_ORDER], fir[LPC_ORDER], iir[LPC_ORDER];
+
+ /**
+ * Compute the combined impulse response of the synthesis filter,
+ * formant perceptual weighting filter and harmonic noise shaping filter
+ */
+ memset(zero, 0, sizeof(int16_t) * LPC_ORDER);
+ memset(vector, 0, sizeof(int16_t) * PITCH_MAX);
+ memset(flt_in, 0, sizeof(int16_t) * SUBFRAME_LEN);
+
+ flt_in[0] = 1 << 13; /* Unit impulse */
+ synth_percept_filter(qnt_lpc + offset, weighted_lpc + (offset << 1),
+ zero, zero, flt_in, vector + PITCH_MAX, 1);
+ harmonic_filter(hf + i, vector + PITCH_MAX, impulse_resp);
+
+ /* Compute the combined zero input response */
+ flt_in[0] = 0;
+ memcpy(fir, p->perf_fir_mem, sizeof(int16_t) * LPC_ORDER);
+ memcpy(iir, p->perf_iir_mem, sizeof(int16_t) * LPC_ORDER);
+
+ synth_percept_filter(qnt_lpc + offset, weighted_lpc + (offset << 1),
+ fir, iir, flt_in, vector + PITCH_MAX, 0);
+ memcpy(vector, p->harmonic_mem, sizeof(int16_t) * PITCH_MAX);
+ harmonic_noise_sub(hf + i, vector + PITCH_MAX, in);
+
+ acb_search(p, residual, impulse_resp, in, i);
+ gen_acb_excitation(residual, p->prev_excitation,p->pitch_lag[i >> 1],
+ p->subframe[i], p->cur_rate);
+ sub_acb_contrib(residual, impulse_resp, in);
+
+ fcb_search(p, impulse_resp, in, i);
+
+ /* Reconstruct the excitation */
+ gen_acb_excitation(impulse_resp, p->prev_excitation, p->pitch_lag[i >> 1],
+ p->subframe[i], Rate6k3);
+
+ memmove(p->prev_excitation, p->prev_excitation + SUBFRAME_LEN,
+ sizeof(int16_t) * (PITCH_MAX - SUBFRAME_LEN));
+ for (j = 0; j < SUBFRAME_LEN; j++)
+ in[j] = av_clip_int16((in[j] << 1) + impulse_resp[j]);
+ memcpy(p->prev_excitation + PITCH_MAX - SUBFRAME_LEN, in,
+ sizeof(int16_t) * SUBFRAME_LEN);
+
+ /* Update filter memories */
+ synth_percept_filter(qnt_lpc + offset, weighted_lpc + (offset << 1),
+ p->perf_fir_mem, p->perf_iir_mem,
+ in, vector + PITCH_MAX, 0);
+ memmove(p->harmonic_mem, p->harmonic_mem + SUBFRAME_LEN,
+ sizeof(int16_t) * (PITCH_MAX - SUBFRAME_LEN));
+ memcpy(p->harmonic_mem + PITCH_MAX - SUBFRAME_LEN, vector + PITCH_MAX,
+ sizeof(int16_t) * SUBFRAME_LEN);
+
+ in += SUBFRAME_LEN;
+ offset += LPC_ORDER;
+ }
+
+ return pack_bitstream(p, buf, buf_size);
+}
+
+AVCodec ff_g723_1_encoder = {
+ .name = "g723_1",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_G723_1,
+ .priv_data_size = sizeof(G723_1_Context),
+ .init = g723_1_encode_init,
+ .encode = g723_1_encode_frame,
+ .long_name = NULL_IF_CONFIG_SMALL("G.723.1"),
+ .sample_fmts = (const enum SampleFormat[]){SAMPLE_FMT_S16,
+ SAMPLE_FMT_NONE},
+};
+#endif
diff --git a/libavcodec/g723_1_data.h b/libavcodec/g723_1_data.h
new file mode 100644
index 0000000000..bd1abe9f0d
--- /dev/null
+++ b/libavcodec/g723_1_data.h
@@ -0,0 +1,1315 @@
+/*
+ * G723.1 compatible decoder data tables.
+ * Copyright (c) 2006 Benjamin Larsson
+ * Copyright (c) 2010 Mohamed Naufal Basheer
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * G723.1 compatible decoder data tables
+ */
+
+#define SUBFRAMES 4
+#define SUBFRAME_LEN 60
+#define FRAME_LEN (SUBFRAME_LEN << 2)
+#define HALF_FRAME_LEN (FRAME_LEN / 2)
+#define LPC_FRAME (HALF_FRAME_LEN + SUBFRAME_LEN)
+#define LPC_ORDER 10
+#define LSP_BANDS 3
+#define LSP_CB_SIZE 256
+#define PITCH_MIN 18
+#define PITCH_MAX (PITCH_MIN + 127)
+#define PITCH_ORDER 5
+#define GRID_SIZE 2
+#define PULSE_MAX 6
+#define GAIN_LEVELS 24
+#define COS_TBL_SIZE 512
+
+/**
+ * G723.1 frame types
+ */
+typedef enum {
+ ActiveFrame, ///< Active speech
+ SIDFrame, ///< Silence Insertion Descriptor frame
+ UntransmittedFrame
+} FrameType;
+
+static const uint8_t frame_size[4] = {24, 20, 4, 1};
+
+typedef enum {
+ Rate6k3,
+ Rate5k3
+} Rate;
+
+/**
+ * G723.1 unpacked data subframe
+ */
+typedef struct {
+ int ad_cb_lag; ///< adaptive codebook lag
+ int ad_cb_gain;
+ int dirac_train;
+ int pulse_sign;
+ int grid_index;
+ int amp_index;
+ int pulse_pos;
+} G723_1_Subframe;
+
+/**
+ * Pitch postfilter parameters
+ */
+typedef struct {
+ int index; ///< postfilter backward/forward lag
+ int16_t opt_gain; ///< optimal gain
+ int16_t sc_gain; ///< scaling gain
+} PPFParam;
+
+/**
+ * Harmonic filter parameters
+ */
+typedef struct {
+ int index;
+ int gain;
+} HFParam;
+
+/**
+ * Optimized fixed codebook excitation parameters
+ */
+typedef struct {
+ int min_err;
+ int amp_index;
+ int grid_index;
+ int dirac_train;
+ int pulse_pos[PULSE_MAX];
+ int pulse_sign[PULSE_MAX];
+} FCBParam;
+
+/**
+ * Postfilter gain weighting factors scaled by 2^15
+ */
+static const int16_t ppf_gain_weight[2] = {0x1800, 0x2000};
+
+/**
+ * LSP DC component
+ */
+static const int16_t dc_lsp[LPC_ORDER] = {
+ 0x0c3b,
+ 0x1271,
+ 0x1e0a,
+ 0x2a36,
+ 0x3630,
+ 0x406f,
+ 0x4d28,
+ 0x56f4,
+ 0x638c,
+ 0x6c46
+};
+
+/**
+ * Cosine table scaled by 2^14
+ */
+static const int16_t cos_tab[COS_TBL_SIZE] = {
+ 16384, 16383, 16379, 16373, 16364, 16353, 16340, 16324,
+ 16305, 16284, 16261, 16235, 16207, 16176, 16143, 16107,
+ 16069, 16029, 15986, 15941, 15893, 15843, 15791, 15736,
+ 15679, 15619, 15557, 15493, 15426, 15357, 15286, 15213,
+ 15137, 15059, 14978, 14896, 14811, 14724, 14635, 14543,
+ 14449, 14354, 14256, 14155, 14053, 13949, 13842, 13733,
+ 13623, 13510, 13395, 13279, 13160, 13039, 12916, 12792,
+ 12665, 12537, 12406, 12274, 12140, 12004, 11866, 11727,
+ 11585, 11442, 11297, 11151, 11003, 10853, 10702, 10549,
+ 10394, 10238, 10080, 9921, 9760, 9598, 9434, 9269,
+ 9102, 8935, 8765, 8595, 8423, 8250, 8076, 7900,
+ 7723, 7545, 7366, 7186, 7005, 6823, 6639, 6455,
+ 6270, 6084, 5897, 5708, 5520, 5330, 5139, 4948,
+ 4756, 4563, 4370, 4176, 3981, 3786, 3590, 3393,
+ 3196, 2999, 2801, 2603, 2404, 2205, 2006, 1806,
+ 1606, 1406, 1205, 1005, 804, 603, 402, 201,
+ 0, -201, -402, -603, -804, -1005, -1205, -1406,
+ -1606, -1806, -2006, -2205, -2404, -2603, -2801, -2999,
+ -3196, -3393, -3590, -3786, -3981, -4176, -4370, -4563,
+ -4756, -4948, -5139, -5330, -5520, -5708, -5897, -6084,
+ -6270, -6455, -6639, -6823, -7005, -7186, -7366, -7545,
+ -7723, -7900, -8076, -8250, -8423, -8595, -8765, -8935,
+ -9102, -9269, -9434, -9598, -9760, -9921, -10080, -10238,
+ -10394, -10549, -10702, -10853, -11003, -11151, -11297, -11442,
+ -11585, -11727, -11866, -12004, -12140, -12274, -12406, -12537,
+ -12665, -12792, -12916, -13039, -13160, -13279, -13395, -13510,
+ -13623, -13733, -13842, -13949, -14053, -14155, -14256, -14354,
+ -14449, -14543, -14635, -14724, -14811, -14896, -14978, -15059,
+ -15137, -15213, -15286, -15357, -15426, -15493, -15557, -15619,
+ -15679, -15736, -15791, -15843, -15893, -15941, -15986, -16029,
+ -16069, -16107, -16143, -16176, -16207, -16235, -16261, -16284,
+ -16305, -16324, -16340, -16353, -16364, -16373, -16379, -16383,
+ -16384, -16383, -16379, -16373, -16364, -16353, -16340, -16324,
+ -16305, -16284, -16261, -16235, -16207, -16176, -16143, -16107,
+ -16069, -16029, -15986, -15941, -15893, -15843, -15791, -15736,
+ -15679, -15619, -15557, -15493, -15426, -15357, -15286, -15213,
+ -15137, -15059, -14978, -14896, -14811, -14724, -14635, -14543,
+ -14449, -14354, -14256, -14155, -14053, -13949, -13842, -13733,
+ -13623, -13510, -13395, -13279, -13160, -13039, -12916, -12792,
+ -12665, -12537, -12406, -12274, -12140, -12004, -11866, -11727,
+ -11585, -11442, -11297, -11151, -11003, -10853, -10702, -10549,
+ -10394, -10238, -10080, -9921, -9760, -9598, -9434, -9269,
+ -9102, -8935, -8765, -8595, -8423, -8250, -8076, -7900,
+ -7723, -7545, -7366, -7186, -7005, -6823, -6639, -6455,
+ -6270, -6084, -5897, -5708, -5520, -5330, -5139, -4948,
+ -4756, -4563, -4370, -4176, -3981, -3786, -3590, -3393,
+ -3196, -2999, -2801, -2603, -2404, -2205, -2006, -1806,
+ -1606, -1406, -1205, -1005, -804, -603, -402, -201,
+ 0, 201, 402, 603, 804, 1005, 1205, 1406,
+ 1606, 1806, 2006, 2205, 2404, 2603, 2801, 2999,
+ 3196, 3393, 3590, 3786, 3981, 4176, 4370, 4563,
+ 4756, 4948, 5139, 5330, 5520, 5708, 5897, 6084,
+ 6270, 6455, 6639, 6823, 7005, 7186, 7366, 7545,
+ 7723, 7900, 8076, 8250, 8423, 8595, 8765, 8935,
+ 9102, 9269, 9434, 9598, 9760, 9921, 10080, 10238,
+ 10394, 10549, 10702, 10853, 11003, 11151, 11297, 11442,
+ 11585, 11727, 11866, 12004, 12140, 12274, 12406, 12537,
+ 12665, 12792, 12916, 13039, 13160, 13279, 13395, 13510,
+ 13623, 13733, 13842, 13949, 14053, 14155, 14256, 14354,
+ 14449, 14543, 14635, 14724, 14811, 14896, 14978, 15059,
+ 15137, 15213, 15286, 15357, 15426, 15493, 15557, 15619,
+ 15679, 15736, 15791, 15843, 15893, 15941, 15986, 16029,
+ 16069, 16107, 16143, 16176, 16207, 16235, 16261, 16284,
+ 16305, 16324, 16340, 16353, 16364, 16373, 16379, 16383,
+};
+
+/**
+ * LSP VQ tables
+ */
+static const int16_t lsp_band0[LSP_CB_SIZE][3] = {
+ { 0, 0, 0}, { -270, -1372, -1032}, { -541, -1650, -1382},
+ { -723, -2011, -2213}, { -941, -1122, -1942}, { -780, -1145, -2454},
+ { -884, -1309, -1373}, {-1051, -1523, -1766}, {-1083, -1622, -2300},
+ { -777, -1377, -2147}, { -935, -1467, -2763}, { -802, -1327, -3471},
+ { -935, -1959, -3999}, { -240, -89, 222}, { -661, -257, -160},
+ { -994, -466, -419}, { -188, -164, -278}, { -342, -512, -415},
+ { -607, -511, -797}, { 16, 19, -716}, { 374, 425, -972},
+ { -346, 245, -282}, { -265, 506, -754}, { -620, -147, 1955},
+ { -742, -860, 2597}, { -150, -352, 2704}, { 305, 880, 1954},
+ { 123, 731, 2766}, { -348, 765, 3327}, { 618, 221, 3258},
+ { -178, -47, 4219}, { 393, 1304, 3842}, { 698, 1702, 4801},
+ { 63, -584, 1229}, { -215, -732, 1704}, { 172, -335, 1909},
+ { -2, 216, 1797}, { 353, 127, 2205}, {-1208, 188, 11},
+ { -513, -75, -683}, { -973, 222, -646}, { -616, -843, -388},
+ { -950, -1113, -359}, {-1431, -623, -705}, {-1398, -1063, -178},
+ { -45, -461, 35}, { -9, -657, -216}, { 127, -1078, 95},
+ { -950, -1156, 584}, {-1480, -1494, 449}, { -120, -705, 516},
+ { -368, -961, 727}, { -378, -526, 973}, { -793, -614, 676},
+ { -801, -755, 1287}, {-1476, -340, 1636}, { -505, -1254, 1543},
+ {-1243, -1622, 1532}, { -776, -1477, -655}, {-1151, -1296, -823},
+ {-1153, -1672, -1124}, {-1291, -2003, -1702}, { -622, -1283, 57},
+ { -471, -1611, 509}, {-1060, -1570, -139}, { -873, -2156, -536},
+ {-1716, -2021, -364}, {-2150, -3218, -1291}, {-1248, -1945, -2904},
+ {-1215, -2633, -2855}, { 167, -244, 84}, { 349, -412, -217},
+ { -40, -352, 632}, { 227, -529, 405}, { 68, -383, -443},
+ { 167, -558, -706}, { -275, -854, -14}, { -351, -1089, -449},
+ { 341, -72, -289}, { 603, -106, -474}, { 322, -219, -649},
+ { 179, -317, -998}, { 450, -291, -996}, { 555, 195, -525},
+ { 784, 272, -831}, { -148, -384, -849}, { 82, -536, -1357},
+ { 238, -172, -1354}, { 422, -268, -1841}, { 297, -737, -2079},
+ { -111, -801, -598}, { 1, -668, -984}, { -131, -818, -1299},
+ { -329, -521, -1310}, { -151, -778, -1834}, { -93, -352, -1746},
+ { -568, -640, -1821}, { -509, -941, -2183}, { 464, -815, -1250},
+ { 79, -1133, -1597}, { -184, -1353, -2123}, { -196, -410, -2427},
+ { -192, -833, -2810}, { -259, -1382, -3045}, { -217, 4, -1166},
+ { -800, -325, -1219}, { -363, -830, -898}, { -661, -1134, -960},
+ { -386, -980, -1501}, { -627, -1159, -1722}, { -903, -829, -855},
+ { -685, -829, -1313}, {-1065, -959, -1405}, { 441, 25, -847},
+ { 655, -27, -1181}, { 1159, -110, -705}, { 856, 253, -1671},
+ { 415, 404, -1}, { 322, 903, -398}, { 670, 499, -292},
+ { 803, 591, -610}, { 1144, 591, -814}, { 717, 183, 393},
+ { 857, 381, 106}, { 609, 62, -27}, { 792, 198, -325},
+ { 735, 805, 88}, { 1142, 812, 78}, { 1028, 366, -292},
+ { 1309, 743, -237}, { 1615, 589, -79}, { 1010, 639, -243},
+ { 999, 964, -311}, { 1500, 1137, -615}, { 988, 357, 646},
+ { 1227, 667, 683}, { 1164, 1565, 894}, { 1392, 2015, 477},
+ { 1138, 533, 250}, { 1437, 896, 391}, { 1765, 1118, 99},
+ { 1112, 1090, 802}, { 1596, 846, 1134}, { 937, 1161, 279},
+ { 1719, 1254, 683}, { 1338, 1086, 35}, { 1419, 1324, 428},
+ { 1428, 1524, 40}, { 2108, 1594, 89}, { 1015, 544, 1222},
+ { 1121, 925, 1263}, { 1030, 1318, 1485}, { 1295, 789, 1817},
+ { 1323, 1272, 1909}, { 1724, 1237, 1803}, { 1797, 1689, 858},
+ { 2149, 1367, 1301}, { 2302, 1867, 761}, { 2863, 2351, 1053},
+ { 52, 163, -76}, { 230, 309, -492}, { -71, 619, 39},
+ { -218, 856, 499}, { -654, 736, -207}, { -535, 1259, 155},
+ { -480, 1476, 643}, { 262, 1081, 102}, { 309, 1592, -182},
+ { 627, 1629, 534}, { 337, 643, 456}, { 758, 670, 713},
+ { 202, 1126, 658}, { 612, 1131, 666}, { 686, 1223, 1136},
+ { -131, 377, 525}, { 42, 708, 907}, { 87, 1488, 1035},
+ { 432, 2117, 904}, { 137, 981, 1332}, { -447, 1014, 1136},
+ { -839, 1793, 1246}, { -559, 297, 198}, { -850, 685, 446},
+ {-1273, 632, 826}, { -401, -544, 173}, { -753, -793, 144},
+ { -436, -9, 772}, { -115, -243, 1310}, { -670, -269, 374},
+ {-1027, -13, 639}, { -887, -81, 1137}, {-1277, -455, 158},
+ {-1411, -720, 736}, { 172, 88, 403}, { 386, 255, 756},
+ { -500, 522, 910}, { -958, 659, 1388}, { -395, 301, 1344},
+ { -356, 768, 1813}, { -613, 841, 2419}, { 445, -122, 252},
+ { 629, -87, 723}, { 283, -253, 870}, { 456, -116, 1381},
+ { 757, 180, 1059}, { 532, 408, 1509}, { 947, 288, 1806},
+ { 1325, 994, 2524}, { 892, 1219, 3023}, { 1397, 1596, 3406},
+ { 1143, 1552, 2546}, { 1850, 1433, 2710}, { -10, 134, 1002},
+ { 154, 499, 1323}, { 508, 792, 1117}, { 509, 1340, 1616},
+ { 762, 862, 1608}, { 787, 740, 2320}, { 794, 1727, 1283},
+ { 465, 2108, 1660}, { -120, 1451, 1613}, { -386, 2016, 2169},
+ { 891, 1225, 2050}, { 456, 1480, 2185}, { 1493, 1283, 1209},
+ { 1397, 1636, 1518}, { 1776, 1738, 1552}, { 1572, 1698, 2141},
+ { 1389, 2126, 1271}, { 1959, 2413, 1119}, { 1365, 2892, 1505},
+ { 2206, 1971, 1623}, { 2076, 1950, 2280}, { 1717, 2291, 1867},
+ { 2366, 2515, 1953}, { 2865, 2838, 2522}, { 2535, 3465, 2011},
+ { 3381, 4127, 2638}, { 836, 2667, 2289}, { 1761, 2773, 2337},
+ { 1415, 3325, 2911}, { 2354, 3138, 3126}, { 2659, 4192, 4010},
+ { 1048, 1786, 1818}, { 1242, 2111, 2240}, { 1512, 2079, 2780},
+ { 1573, 2491, 3138}, { 2230, 2377, 2782}, { 416, 1773, 2704},
+ { 725, 2336, 3297}, { 1252, 2373, 3978}, { 2094, 2268, 3568},
+ { 2011, 2712, 4528}, { 1341, 3507, 3876}, { 1216, 3919, 4922},
+ { 1693, 4793, 6012}
+};
+
+static const int16_t lsp_band1[LSP_CB_SIZE][3] = {
+ { 0, 0, 0}, {-2114, -1302, 76}, {-2652, -1278, -1368},
+ {-2847, -828, -349}, {-3812, -2190, -349}, {-3946, -364, -449},
+ {-2725, -4492, -3607}, {-3495, -4764, -1744}, { -51, -756, 84},
+ { -153, -1191, 504}, { 108, -1418, 1167}, { -835, -896, 390},
+ { -569, -1702, 87}, {-1151, -1818, 933}, {-1826, -2547, 411},
+ {-1842, -1818, 1451}, {-2438, -1611, 781}, {-2747, -2477, 1311},
+ { -940, 1252, 477}, {-1629, 1688, 602}, {-1202, 617, 280},
+ {-1737, 393, 580}, {-1528, 1077, 1199}, {-2165, -161, 1408},
+ {-2504, -1087, 2371}, {-3458, -175, 1395}, {-1397, -98, -843},
+ {-2252, -177, -1149}, {-1489, -726, -1283}, {-1558, -265, -1744},
+ {-1867, -821, -1897}, {-2062, -1516, -2340}, {-2595, -1142, -2861},
+ { 170, 46, -819}, { -193, -204, -1151}, { 326, -196, -1532},
+ { 780, 329, -816}, { 201, 369, -1243}, { 650, -209, -1060},
+ { 1144, -15, -1216}, { 1203, -259, -1867}, { -890, -564, -1430},
+ { -638, -852, -1921}, { 177, -739, -1358}, { -261, -526, -1666},
+ { 206, -407, -2255}, { 338, -526, -822}, { 421, -1095, -1009},
+ { 765, -607, -1408}, { 825, -1295, -2004}, { 357, -905, -1815},
+ { -58, -1248, -1588}, { -596, -1436, -2046}, { -73, -1159, -2116},
+ { -115, -1382, -2581}, { -160, -1723, -1952}, { -6, -2196, -2954},
+ { -649, -1705, -2603}, { -617, -1453, -3282}, { -949, -2019, -3102},
+ { -812, 1544, 1937}, {-1854, 574, 2000}, {-1463, 1140, 2649},
+ {-2683, 1748, 1452}, {-2486, 2241, 2523}, { 783, 1910, 1435},
+ { 581, 2682, 1376}, { 236, 2197, 1885}, { -453, 2943, 2057},
+ { -682, 2178, 2565}, {-1342, 3201, 3328}, { -288, -184, 262},
+ { 121, -149, -183}, { 758, -412, 206}, { 1038, -204, 853},
+ { 1577, -457, 700}, { 937, -640, -567}, { 1508, -528, -1024},
+ { -225, -527, -427}, { -564, -1095, -332}, { -742, -353, -186},
+ {-1288, -459, 84}, {-1853, -484, -274}, {-1554, -731, 825},
+ {-2425, -234, 382}, {-1722, 293, -271}, {-2515, 425, -564},
+ {-2599, 818, 464}, { -358, 118, -375}, { -613, 198, -874},
+ { -690, 683, -324}, {-1352, 1155, -168}, {-1093, 129, -324},
+ {-1184, 611, -858}, { 433, 386, -372}, { -120, 486, -634},
+ { 234, 851, -631}, { 602, 128, 46}, { 1099, 410, 159},
+ { 715, -145, -424}, { 1198, -85, -593}, { 1390, 367, -358},
+ { 1683, 362, -964}, { 1711, 622, 45}, { 2033, 833, -383},
+ { 2890, 549, -506}, { 7, 401, 52}, { 72, 811, 415},
+ { 566, 668, 41}, { 467, 1218, 130}, { 68, 957, -187},
+ { -25, 1649, -103}, { -661, 260, 214}, { -925, -94, 612},
+ { -321, -422, 965}, { -788, -672, 1783}, { 400, -673, 779},
+ { 741, -595, 1635}, { -161, 307, 657}, { -382, 836, 871},
+ { -814, 400, 1223}, { 364, 606, 1247}, { 57, 75, 1571},
+ { 151, 471, 2287}, { -81, 1021, 1502}, { 227, 1470, 1097},
+ { 658, 1275, 1653}, { 664, 1478, 2377}, { 263, -127, 444},
+ { 264, 89, 969}, { 794, 171, 576}, { 821, 186, 1226},
+ { 404, 462, 517}, { 339, 918, 794}, { 1280, 1423, 196},
+ { 1453, 2019, 365}, { 1615, 1481, 672}, { 2394, 1708, 508},
+ { 806, 1238, 573}, { 713, 1158, 1078}, { 1285, 1436, 1232},
+ { 1790, 1188, 1141}, { 765, 643, 864}, { 1032, 797, 1279},
+ { 900, 563, 1827}, { 1514, 673, 2312}, { 1544, 1129, 3240},
+ { 1469, 1050, 1594}, { 1945, 1318, 1988}, { 2397, 2026, 2060},
+ { 3538, 2057, 2620}, { 1249, -118, 74}, { 1727, 194, 421},
+ { 2078, -50, -463}, { 970, 688, -432}, { 1149, 952, -110},
+ { 1254, 1275, -651}, { 1386, 929, 401}, { 1960, 1167, 232},
+ { 407, -752, -243}, { 859, -1118, 172}, { -227, -860, -992},
+ { -796, -1175, -1380}, { 8, -1282, -388}, { 353, -1781, -1037},
+ { -732, -397, -807}, { -853, -28, -1342}, {-1229, -1207, -1959},
+ {-1015, -1125, -2543}, {-1452, -1791, -2725}, {-1891, -2416, -3269},
+ { -918, -1629, -783}, { -580, -2155, -698}, {-1097, -2364, -96},
+ {-1387, -1513, 7}, {-1588, -2076, -664}, {-1473, -2740, -784},
+ {-2378, -3149, -56}, {-2856, -2092, -169}, {-3391, -3708, 316},
+ {-1176, -890, -614}, {-1944, -1061, -800}, { -299, -1517, -1000},
+ { -640, -1850, -1526}, {-1454, -1536, -1233}, {-1890, -1955, -1756},
+ {-1086, -1921, -2122}, { -750, -2325, -2260}, {-1325, -2413, -2673},
+ {-1114, -2542, -3459}, {-1341, -2901, -3963}, {-1160, -2226, -1393},
+ {-1001, -2772, -1573}, {-1594, -2641, -1978}, {-1534, -3046, -2624},
+ {-2224, -2196, -675}, {-2807, -3054, -1102}, {-2008, -2840, -1186},
+ {-1980, -3332, -1695}, {-1715, -3562, -505}, {-2527, -4000, -1887},
+ {-2333, -2734, -2296}, {-3440, -2401, -3211}, {-2008, -3528, -3337},
+ {-2247, -3291, -4510}, { -475, 949, 155}, { -149, 1365, 545},
+ { -757, 1644, 1083}, { -217, 2053, 1353}, {-1433, 2301, 1462},
+ { 495, 1661, 529}, { 10, 2037, 740}, { 2082, 1898, 978},
+ { 2831, 2294, 911}, { 842, 793, 420}, { 1223, 1023, 863},
+ { 1237, 451, 780}, { 1744, 708, 822}, { 1533, 284, 1384},
+ { 2135, 609, 1538}, { 2305, 626, 540}, { 2368, 1187, 955},
+ { 2586, 1255, -7}, { 3116, 1131, 726}, { 3431, 1730, 428},
+ { 2734, 1648, 1307}, { 2988, 1231, 2010}, { 3523, 2024, 1488},
+ { 1034, 1657, 871}, { 1206, 2163, 1036}, { 1807, 2372, 1233},
+ { 1808, 1769, 1493}, { 1573, 2332, 1779}, { 1216, 1609, 1866},
+ { 1480, 1898, 2513}, { 465, 2708, 2776}, { 771, 3638, 3338},
+ { 1869, 2599, 2623}, { 2825, 2745, 2468}, { 2638, 2439, 1585},
+ { 2094, 2970, 1308}, { 2022, 3057, 1999}, { 3428, 2912, 1816},
+ { 4536, 2974, 2129}, { 1046, 2563, 2086}, { 1363, 3562, 2318},
+ { 2511, 1891, 2984}, { 1866, 2306, 3986}, { 3272, 2924, 3682},
+ { 3146, 3564, 2272}, { 3592, 3968, 2822}, { 2431, 3369, 3069},
+ { 1931, 4709, 3090}, { 2629, 4220, 3986}, { 4639, 4056, 3664},
+ { 4035, 5334, 4912}
+};
+
+static const int16_t lsp_band2[LSP_CB_SIZE][4] = {
+ { 0, 0, 0, 0}, { 601, 512, -542, 334},
+ { 428, 1087, -484, -132}, { 652, 622, -391, -572},
+ { 378, 799, 141, -860}, { 1040, 409, 112, -554},
+ { 1123, 670, -75, -847}, { 1421, 494, -315, -1095},
+ { 787, 1001, 114, -460}, { 988, 1672, 216, -681},
+ { 1007, 1241, -132, -1247}, { 1073, 399, 186, -5},
+ { 1262, 193, -694, -129}, { 325, 196, 51, -641},
+ { 861, -59, 350, -458}, { 1261, 567, 586, -346},
+ { 1532, 885, 210, -517}, { 2027, 937, 113, -792},
+ { 1383, 1064, 334, 38}, { 1964, 1468, 459, 133},
+ { 2062, 1186, -98, -121}, { 2577, 1445, 506, -373},
+ { 2310, 1682, -2, -960}, { 2876, 1939, 765, 138},
+ { 3581, 2360, 649, -414}, { 219, 176, -398, -309},
+ { 434, -78, -435, -880}, { -344, 301, 265, -552},
+ { -915, 470, 657, -380}, { 419, -432, -163, -453},
+ { 351, -953, 8, -562}, { 789, -43, 20, -958},
+ { 302, -594, -352, -1159}, { 1040, 108, -668, -924},
+ { 1333, 210, -1217, -1663}, { 483, 589, -350, -1140},
+ { 1003, 824, -802, -1184}, { 745, 58, -589, -1443},
+ { 346, 247, -915, -1683}, { 270, 796, -720, -2043},
+ { 1208, 722, -222, -193}, { 1486, 1180, -412, -672},
+ { 1722, 179, -69, -521}, { 2047, 860, -666, -1410},
+ { -146, 222, -281, -805}, { -189, 90, -114, -1307},
+ { -152, 1086, -241, -764}, { -439, 733, -601, -1302},
+ { -833, -167, -351, -601}, { -856, -422, -411, -1059},
+ { -747, -355, -582, -1644}, { -837, 210, -916, -1144},
+ {-1800, 32, -878, -1687}, { -48, -23, -1146, 52},
+ { -350, -409, -1656, -364}, { 265, -728, -858, -577},
+ { 458, -247, -1141, -997}, { 691, -407, -1988, -1161},
+ { -66, -104, -705, -1249}, { -431, -93, -1191, -1844},
+ { 203, -732, -1000, -1693}, { 10, -832, -1846, -1819},
+ { 493, -128, -1436, -1768}, { 488, -311, -1730, -2540},
+ { -653, -532, -1150, -1172}, {-1086, -289, -1706, -1533},
+ { -699, -1205, -1216, -1766}, {-1032, -1481, -2074, -1523},
+ { -721, -1220, -2277, -2600}, { 12, -539, -1484, -1131},
+ { -40, -911, -2106, -441}, { -471, -484, -2267, -1549},
+ { -141, -988, -3006, -1721}, {-1545, -2102, -583, 342},
+ {-1383, -2772, -386, -13}, {-2118, -2589, -1205, 72},
+ {-2147, -3231, -965, 390}, {-2949, -3300, -621, 637},
+ {-3907, -4138, -865, 803}, {-1287, -845, -375, -548},
+ {-1416, -1169, -487, -1277}, {-1400, -1690, -1027, -418},
+ {-2018, -1909, -1188, -1260}, {-1418, -2222, -2029, -128},
+ {-2067, -2998, -2693, -310}, { -950, -1028, -1538, 185},
+ {-1616, -915, -2205, -549}, { 19, -821, -1145, 352},
+ { 184, -1175, -1356, -627}, { -547, -1088, -1661, -911},
+ { -216, -1502, -2197, -948}, { -795, -1306, -2374, -451},
+ { -924, -1889, -2796, -680}, { -600, -1614, -3609, -885},
+ {-2392, -2528, 319, 303}, {-2908, -2095, -310, 573},
+ {-3460, -2141, 49, -113}, {-2231, -448, 675, -146},
+ {-2805, -532, 1231, 479}, {-2684, -486, -200, 611},
+ {-3525, -971, -198, 704}, {-3707, 173, 349, 254},
+ {-4734, -1447, -34, 880}, { 777, -512, 114, -10},
+ { 1250, -66, 442, -5}, { 604, 613, 452, -352},
+ { 1224, 777, 675, -1014}, {-1372, -79, -1208, -238},
+ {-2389, -17, -1157, -818}, {-1504, -673, -1133, -1060},
+ {-1984, -799, -2005, -1973}, {-2037, -798, -1068, -105},
+ {-3190, -899, -1817, -194}, { -156, -886, 394, -318},
+ { -258, -1283, 551, 202}, { -536, -1729, 910, 331},
+ { -847, -1109, 795, -163}, {-1171, -1128, 715, 519},
+ {-1080, -1319, 1685, 668}, {-1000, -1921, 96, 211},
+ {-1487, -2148, 831, 174}, {-1139, -374, 414, -4},
+ {-1517, -1383, 396, -352}, {-1012, 439, -59, -967},
+ {-1812, 706, -440, -1030}, {-1971, -329, -34, -827},
+ {-2472, -1588, -151, -606}, {-2161, 374, -281, 76},
+ {-3012, 231, -15, -690}, { 1104, 566, 721, 209},
+ { 1685, 564, 383, 98}, { 1898, 750, 792, -97},
+ { 556, -64, 561, -93}, { 876, 162, 913, -22},
+ { 961, 675, 1296, 140}, { 756, -396, 851, 544},
+ { 360, -303, 1341, 396}, { 878, -22, 1464, 863},
+ { -309, -273, 642, -129}, { -686, -82, 842, 454},
+ { -5, -47, 1069, 998}, { -94, 967, 1277, 298},
+ { -489, 385, 1473, 746}, { -369, -717, 1333, 242},
+ { 281, -993, 1726, 924}, { 464, 601, 1575, 1376},
+ { -250, 206, 2339, 1175}, { -438, 377, -597, -285},
+ {-1020, 787, -790, -287}, { -458, -410, 215, 295},
+ { -589, -860, -121, 797}, {-1175, 122, -437, 466},
+ {-1480, -121, 367, 924}, { 234, 323, 770, -555},
+ { 145, 30, 996, 26}, { 66, 849, 93, -145},
+ { -117, 1261, 474, -399}, {-1495, 1051, 218, -506},
+ {-1390, 694, 994, 88}, { 616, 7, 78, 304},
+ { 1060, 52, -62, 835}, { 833, 454, 649, 1359},
+ { -770, 464, 47, 93}, { -574, 1199, -39, 379},
+ { 114, -98, 488, 485}, { 727, 244, 606, 696},
+ { -76, 455, 671, 546}, { -565, -13, 145, 819},
+ { -376, 569, 448, 1128}, { 218, 122, 265, 1167},
+ { 230, 738, 932, 1003}, { 138, 477, 36, 450},
+ { 404, 787, -73, 1000}, { 497, 1259, 387, 1231},
+ { 17, 207, 195, -79}, { 562, 358, 53, -158},
+ { 493, 387, 478, 189}, { 678, 831, 640, 558},
+ { -197, 523, 613, 57}, { 429, 894, 769, 111},
+ { 67, 1174, 568, 511}, { 1242, 824, 251, 840},
+ { 1419, 1074, 864, 481}, { 924, 1474, 669, 724},
+ { 1539, 1879, 654, 1590}, { 445, 337, 1111, 541},
+ { 472, 1421, 1264, 1094}, { 794, 735, 1103, 668},
+ { 1055, 863, 1192, 1020}, { 778, 1105, 806, 1798},
+ { 1052, 1527, 1587, 2151}, { 881, 1552, 1265, 391},
+ { 726, 872, 1812, 601}, { 1469, 280, 1008, 616},
+ { 1403, 577, 1803, 1244}, { 1650, 1314, 1148, 1072},
+ { 1297, 1669, 1911, 1026}, { 2093, 1044, 2115, 1189},
+ { 1644, 1961, 2587, 1512}, { 25, -315, -9, -106},
+ { 290, -339, 428, -444}, { -68, -783, 735, 772},
+ { 245, -555, 468, 47}, { 334, -895, 814, 146},
+ { 235, 368, -964, -959}, { -203, 315, -1566, -1217},
+ { 801, 17, -276, -354}, { 894, -495, -789, -635},
+ { 716, 291, -1189, -357}, { 560, -260, -733, -2},
+ { 679, -508, -1429, 211}, { -51, -62, -428, 557},
+ { 322, -638, -211, 614}, { -878, -1057, -84, -71},
+ { -388, -1415, -167, -318}, { -754, -1574, 214, -539},
+ {-1419, -2004, -92, -787}, { -47, -856, -347, -255},
+ { 23, -1211, -173, 320}, { -658, -487, -893, 353},
+ { -783, -1587, -584, 507}, {-1420, -859, -378, 441},
+ {-2095, -1491, -137, 439}, { -321, -1450, -1288, -12},
+ { -359, -2113, -553, -8}, { -831, -1918, -1561, 32},
+ {-1014, -2487, -1359, -939}, { -475, -311, -169, -236},
+ { -907, -426, 276, -611}, { -96, -400, 50, -710},
+ { -426, -1022, -10, -985}, { -197, -258, -744, -575},
+ { -611, -930, -771, -394}, { -267, -776, -612, -939},
+ { -256, -1346, -802, -1122}, { -796, -1570, -825, -754},
+ { 712, 876, 141, 227}, { 981, 1509, 85, 124},
+ { 1462, 1228, 979, -39}, { 1734, 999, 1481, 440},
+ { 2293, 1116, 769, 440}, { 2504, 1480, 1241, 356},
+ { 2474, 1909, 1558, 810}, { 917, 1134, 607, -134},
+ { 509, 1809, 781, -123}, { 1712, 1506, 559, -423},
+ { 2037, 2317, 726, -155}, { 3031, 2676, 1203, 331},
+ { 3664, 3274, 1768, 531}, { 1610, 1839, 867, 183},
+ { 1774, 1972, 1538, 97}, { 1822, 2158, 1282, 659},
+ { 2222, 2758, 1818, 900}, { 3251, 2124, 1723, 996},
+ { 3633, 2336, 2408, 1453}, { 2923, 3517, 2567, 1318},
+};
+
+/**
+ * Used for the coding/decoding of the pulses positions
+ * for the MP-MLQ codebook
+ */
+static const int32_t combinatorial_table[PULSE_MAX][SUBFRAME_LEN/GRID_SIZE] = {
+ {118755, 98280, 80730, 65780, 53130,
+ 42504, 33649, 26334, 20349, 15504,
+ 11628, 8568, 6188, 4368, 3003,
+ 2002, 1287, 792, 462, 252,
+ 126, 56, 21, 6, 1,
+ 0, 0, 0, 0, 0},
+
+ { 23751, 20475, 17550, 14950, 12650,
+ 10626, 8855, 7315, 5985, 4845,
+ 3876, 3060, 2380, 1820, 1365,
+ 1001, 715, 495, 330, 210,
+ 126, 70, 35, 15, 5,
+ 1, 0, 0, 0, 0},
+
+ { 3654, 3276, 2925, 2600, 2300,
+ 2024, 1771, 1540, 1330, 1140,
+ 969, 816, 680, 560, 455,
+ 364, 286, 220, 165, 120,
+ 84, 56, 35, 20, 10,
+ 4, 1, 0, 0, 0},
+
+ { 406, 378, 351, 325, 300,
+ 276, 253, 231, 210, 190,
+ 171, 153, 136, 120, 105,
+ 91, 78, 66, 55, 45,
+ 36, 28, 21, 15, 10,
+ 6, 3, 1, 0, 0},
+
+ { 29, 28, 27, 26, 25,
+ 24, 23, 22, 21, 20,
+ 19, 18, 17, 16, 15,
+ 14, 13, 12, 11, 10,
+ 9, 8, 7, 6, 5,
+ 4, 3, 2, 1, 0},
+
+ { 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1},
+};
+
+static const int16_t pitch_contrib[340] = {
+ 60, 0, 0, 2489, 60, 0, 0, 5217,
+ 1, 6171, 0, 3953, 0, 10364, 1, 9357,
+ -1, 8843, 1, 9396, 0, 5794, -1, 10816,
+ 2, 11606, -2, 12072, 0, 8616, 1, 12170,
+ 0, 14440, 0, 7787, -1, 13721, 0, 18205,
+ 0, 14471, 0, 15807, 1, 15275, 0, 13480,
+ -1, 18375, -1, 0, 1, 11194, -1, 13010,
+ 1, 18836, -2, 20354, 1, 16233, -1, 0,
+ 60, 0, 0, 12130, 0, 13385, 1, 17834,
+ 1, 20875, 0, 21996, 1, 0, 1, 18277,
+ -1, 21321, 1, 13738, -1, 19094, -1, 20387,
+ -1, 0, 0, 21008, 60, 0, -2, 22807,
+ 0, 15900, 1, 0, 0, 17989, -1, 22259,
+ 1, 24395, 1, 23138, 0, 23948, 1, 22997,
+ 2, 22604, -1, 25942, 0, 26246, 1, 25321,
+ 0, 26423, 0, 24061, 0, 27247, 60, 0,
+ -1, 25572, 1, 23918, 1, 25930, 2, 26408,
+ -1, 19049, 1, 27357, -1, 24538, 60, 0,
+ -1, 25093, 0, 28549, 1, 0, 0, 22793,
+ -1, 25659, 0, 29377, 0, 30276, 0, 26198,
+ 1, 22521, -1, 28919, 0, 27384, 1, 30162,
+ -1, 0, 0, 24237, -1, 30062, 0, 21763,
+ 1, 30917, 60, 0, 0, 31284, 0, 29433,
+ 1, 26821, 1, 28655, 0, 31327, 2, 30799,
+ 1, 31389, 0, 32322, 1, 31760, -2, 31830,
+ 0, 26936, -1, 31180, 1, 30875, 0, 27873,
+ -1, 30429, 1, 31050, 0, 0, 0, 31912,
+ 1, 31611, 0, 31565, 0, 25557, 0, 31357,
+ 60, 0, 1, 29536, 1, 28985, -1, 26984,
+ -1, 31587, 2, 30836, -2, 31133, 0, 30243,
+ -1, 30742, -1, 32090, 60, 0, 2, 30902,
+ 60, 0, 0, 30027, 0, 29042, 60, 0,
+ 0, 31756, 0, 24553, 0, 25636, -2, 30501,
+ 60, 0, -1, 29617, 0, 30649, 60, 0,
+ 0, 29274, 2, 30415, 0, 27480, 0, 31213,
+ -1, 28147, 0, 30600, 1, 31652, 2, 29068,
+ 60, 0, 1, 28571, 1, 28730, 1, 31422,
+ 0, 28257, 0, 24797, 60, 0, 0, 0,
+ 60, 0, 0, 22105, 0, 27852, 60, 0,
+ 60, 0, -1, 24214, 0, 24642, 0, 23305,
+ 60, 0, 60, 0, 1, 22883, 0, 21601,
+ 60, 0, 2, 25650, 60, 0, -2, 31253,
+ -2, 25144, 0, 17998
+};
+
+/**
+ * Number of non-zero pulses in the MP-MLQ excitation
+ */
+static const int8_t pulses[4] = {6, 5, 6, 5};
+
+/**
+ * Size of the MP-MLQ fixed excitation codebooks
+ */
+static const int32_t max_pos[4] = {593775, 142506, 593775, 142506};
+
+static const int16_t fixed_cb_gain[GAIN_LEVELS] = {
+ 1, 2, 3, 4, 6, 9, 13, 18,
+ 26, 38, 55, 80, 115, 166, 240, 348,
+ 502, 726, 1050, 1517, 2193, 3170, 4582, 6623,
+};
+
+static const int16_t adaptive_cb_gain85[85 * 20] = {
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 800, 1496, 167, -256,
+ -338, -39, -136, -1, -4, -6, -73, -8,
+ -15, 12, 23, 2, 16, 30, 3, -5,
+ -462, -686, 493, 2575, 311, -13, -28, -14,
+ -404, -5, -19, 13, 20, 72, 107, -77,
+ 8, 13, -9, -48, 1483, 144, 784, 928,
+ 1243, -134, -1, -37, -52, -94, -13, -71,
+ -6, -84, -8, -44, -112, -10, -59, -70,
+ -77, 275, 3522, 1056, -1254, 0, -4, -757,
+ -68, -95, 1, 16, -59, 4, -17, -227,
+ -5, 21, 269, 80, -125, -40, -264, 381,
+ 5027, 0, 0, -4, -8, -1542, 0, -2,
+ 0, 2, 0, 6, 38, 12, 81, -117,
+ 138, 332, 2215, 2574, 1339, -1, -6, -299,
+ -404, -109, -2, -18, -44, -21, -52, -348,
+ -11, -27, -181, -210, 3685, 2883, -887, 866,
+ -1639, -828, -507, -48, -45, -164, -648, 199,
+ 156, -194, -152, 46, 368, 288, -88, 86,
+ 1396, 2146, 2235, 345, 942, -118, -281, -305,
+ -7, -54, -182, -190, -292, -29, -45, -47,
+ -80, -123, -128, -19, 13, 4475, 3549, -804,
+ -655, 0, -1222, -768, -39, -26, -3, -2,
+ -969, 0, 219, 174, 0, 179, 141, -32,
+ -724, 254, 242, 6049, 2462, -32, -3, -3,
+ -2233, -370, 11, 10, -3, 267, -94, -89,
+ 108, -38, -36, -909, 626, -1713, 6121, 4561,
+ -1061, -23, -179, -2287, -1270, -68, 65, -233,
+ 640, -174, 477, -1704, 40, -111, 396, 295,
+ -350, 1391, 7985, 511, -405, -7, -118, -3892,
+ -15, -10, 29, 170, -678, 10, -43, -249,
+ -8, 34, 197, 12, 3144, -529, 608, 2530,
+ 3878, -603, -17, -22, -390, -918, 101, -116,
+ 19, -485, 81, -93, -744, 125, -144, -599,
+ 2589, -689, 3045, 5603, -404, -409, -29, -566,
+ -1916, -10, 108, -481, 128, -885, 235, -1041,
+ 63, -17, 75, 138, 3107, 513, 1374, -3594,
+ -4922, -589, -16, -115, -788, -1478, -97, -260,
+ -43, 681, 112, 301, 933, 154, 413, -1079,
+ 2468, 6010, 1107, -390, 1961, -372, -2204, -74,
+ -9, -234, -905, -166, -406, 58, 143, 26,
+ -295, -719, -132, 46, 4773, 2766, 2368, 4862,
+ -4044, -1390, -467, -342, -1443, -998, -806, -690,
+ -399, -1416, -821, -702, 1178, 682, 584, 1200,
+ 1665, -1879, 1443, 1701, 8562, -169, -215, -127,
+ -176, -4475, 190, -146, 165, -172, 195, -149,
+ -870, 982, -754, -889, 2716, 9011, -1007, 755,
+ -1785, -450, -4956, -61, -34, -194, -1493, 167,
+ 554, -125, -415, 46, 296, 982, -109, 82,
+ -2727, 7548, 1285, 938, 3420, -453, -3478, -100,
+ -53, -714, 1256, 213, -592, 156, -432, -73,
+ 569, -1576, -268, -196, 3677, 882, 4050, 1202,
+ 2323, -825, -47, -1001, -88, -329, -198, -909,
+ -218, -269, -64, -297, -521, -125, -574, -170,
+ 2046, -753, 122, 10102, 603, -255, -34, 0,
+ -6229, -22, 94, -15, 5, -1261, 464, -75,
+ -75, 27, -4, -372, 449, -1815, 10690, 3870,
+ -527, -12, -201, -6976, -914, -16, 49, -293,
+ 1184, -106, 428, -2525, 14, -58, 344, 124,
+ -941, 2352, 5049, 3650, 2637, -54, -337, -1556,
+ -813, -424, 135, 290, -725, 209, -524, -1125,
+ 151, -378, -812, -587, -1879, 796, 3117, 9569,
+ -404, -215, -38, -593, -5589, -9, 91, 357,
+ -151, 1097, -464, -1821, -46, 19, 76, 236,
+ -1715, 2043, -2096, 9946, 4001, -179, -254, -268,
+ -6038, -977, 213, -219, 261, 1041, -1240, 1272,
+ 418, -498, 511, -2429, -5772, -618, -3921, 284,
+ -3155, -2033, -23, -938, -4, -607, -218, -1381,
+ -148, 100, 10, 68, -1111, -119, -755, 54,
+ 382, 4748, 8003, -2064, 2198, -8, -1376, -3909,
+ -260, -294, -110, -186, -2319, 48, 598, 1008,
+ -51, -637, -1073, 277, -867, 3015, 11926, -1675,
+ 947, -45, -555, -8681, -171, -54, 159, 631,
+ -2195, -88, 308, 1219, 50, -174, -690, 96,
+ -4933, -432, 6757, 3771, 1352, -1485, -11, -2786,
+ -867, -111, -130, 2034, 178, 1135, 99, -1555,
+ 407, 35, -557, -311, 152, 9726, 4231, -1928,
+ 1490, -1, -5774, -1092, -226, -135, -90, -39,
+ -2511, 17, 1144, 498, -13, -884, -384, 175,
+ 2512, 193, 9033, 5361, -3148, -385, -2, -4980,
+ -1754, -605, -29, -1385, -106, -822, -63, -2956,
+ 482, 37, 1735, 1030, 8464, 2844, 12, 549,
+ 2132, -4373, -493, 0, -18, -277, -1469, -6,
+ -2, -284, -95, 0, -1101, -370, -1, -71,
+ 2141, -2602, 7166, 9046, -1350, -279, -413, -3134,
+ -4994, -111, 340, -936, 1138, -1182, 1436, -3957,
+ 176, -214, 590, 745, -244, 278, 13307, 1227,
+ -161, -3, -4, -10808, -91, -1, 4, 198,
+ -226, 18, -20, -997, -2, 2, 131, 12,
+ -1947, 8217, 6269, 917, -2559, -231, -4121, -2399,
+ -51, -399, 976, 745, -3144, 108, -460, -350,
+ -304, 1283, 979, 143, -1810, 2061, -2781, 6056,
+ 10058, -200, -259, -472, -2238, -6174, 227, -307,
+ 349, 669, -761, 1028, 1111, -1265, 1707, -3717,
+ 7827, 9161, -3409, 2473, -1510, -3739, -5122, -709,
+ -373, -139, -4376, 1628, 1906, -1181, -1382, 514,
+ 721, 844, -314, 228, -1430, 8313, 9541, -2955,
+ 1626, -124, -4218, -5556, -533, -161, 725, 832,
+ -4841, -257, 1499, 1721, 142, -825, -947, 293,
+ 2819, -4247, 5391, 8673, 2756, -485, -1101, -1774,
+ -4591, -463, 730, -927, 1397, -1492, 2248, -2854,
+ -474, 714, -907, -1459, 141, 14552, 690, 257,
+ -112, -1, -12926, -29, -4, 0, -125, -5,
+ -613, -2, -228, -10, 0, 99, 4, 1,
+ 11938, -1859, 1806, -962, -884, -8699, -211, -199,
+ -56, -47, 1355, -1316, 205, 701, -109, 106,
+ 644, -100, 97, -51, 3728, 1982, 2264, 4584,
+ 3131, -848, -239, -312, -1282, -598, -451, -515,
+ -273, -1043, -554, -633, -712, -378, -432, -876,
+ -1181, 766, 720, 14303, -216, -85, -35, -31,
+ -12486, -2, 55, 51, -33, 1031, -668, -628,
+ -15, 10, 9, 189, -4385, 4826, 10112, 1569,
+ 3388, -1173, -1421, -6242, -150, -700, 1291, 2706,
+ -2979, 420, -462, -969, 906, -998, -2091, -324,
+ -448, 1932, 15591, -1842, 657, -12, -227, -14837,
+ -207, -26, 52, 427, -1838, -50, 217, 1753,
+ 18, -77, -626, 74, -4141, 1844, 3962, 5517,
+ 6220, -1046, -207, -958, -1858, -2361, 466, 1001,
+ -446, 1394, -621, -1334, 1572, -700, -1504, -2094,
+ 729, -2299, 14755, 3657, -952, -32, -322, -13288,
+ -816, -55, 102, -656, 2071, -162, 513, -3294,
+ 42, -133, 857, 212, -1385, 5801, 13339, -3137,
+ 1344, -117, -2054, -10861, -600, -110, 490, 1127,
+ -4723, -265, 1111, 2554, 113, -476, -1094, 257,
+ 4710, 9661, 1073, -2467, 3274, -1354, -5697, -70,
+ -371, -654, -2777, -308, -633, 709, 1455, 161,
+ -941, -1930, -214, 493, 1843, -3624, 12422, 6898,
+ -1559, -207, -802, -9419, -2904, -148, 407, -1397,
+ 2748, -775, 1526, -5230, 175, -344, 1182, 656,
+ 1433, 2394, 2507, 1380, 8780, -125, -349, -383,
+ -116, -4705, -209, -219, -366, -120, -201, -211,
+ -768, -1283, -1343, -740, -1712, 12915, 5883, -2197,
+ 991, -179, -10181, -2112, -294, -60, 1350, 615,
+ -4638, -229, 1732, 789, 103, -781, -356, 133,
+ 15072, 2158, -1245, 910, -496, -13865, -284, -94,
+ -50, -15, -1986, 1145, 164, -837, -119, 69,
+ 456, 65, -37, 27, 4655, 7319, 4916, 586,
+ -3381, -1322, -3270, -1475, -20, -697, -2079, -1396,
+ -2196, -166, -261, -175, 960, 1510, 1014, 120,
+ 1191, -2140, 5120, 13498, -1418, -86, -279, -1600,
+ -11121, -122, 155, -372, 669, -981, 1763, -4218,
+ 103, -185, 443, 1168, -1530, -817, 8191, 9632,
+ -1452, -143, -40, -4095, -5663, -128, -76, 765,
+ 408, 900, 480, -4815, -135, -72, 726, 854,
+ -3236, 607, 1696, -2106, 11485, -639, -22, -175,
+ -270, -8051, 119, 335, -62, -416, 78, 218,
+ 2268, -425, -1189, 1476, 3203, -1903, -837, 9679,
+ 7057, -626, -221, -42, -5718, -3039, 372, 163,
+ -97, -1892, 1124, 494, -1380, 819, 360, -4169,
+ 213, -655, 17015, 620, -384, -2, -26, -17671,
+ -23, -9, 8, -221, 681, -8, 24, -644,
+ 5, -15, 399, 14, 5088, 35, -3339, 3726,
+ 8488, -1580, 0, -680, -847, -4397, -10, 1037,
+ 7, -1157, -8, 759, -2636, -18, 1730, -1930,
+ -988, 1454, -2688, 15039, 2682, -59, -129, -441,
+ -13805, -439, 87, -162, 238, 907, -1335, 2467,
+ 161, -238, 440, -2462, -4865, -2842, -53, 5495,
+ 6523, -1445, -493, 0, -1843, -2597, -844, -16,
+ -9, 1632, 953, 18, 1937, 1131, 21, -2188,
+ 3076, 15069, -2914, 1810, -971, -577, -13860, -518,
+ -200, -57, -2829, 547, 2680, -339, -1665, 322,
+ 182, 893, -172, 107, 1311, 5355, 11054, 2299,
+ -3654, -105, -1750, -7458, -322, -814, -428, -885,
+ -3613, -184, -751, -1551, 292, 1194, 2465, 512,
+ 4035, 5619, 4618, 1815, 1912, -994, -1927, -1301,
+ -201, -223, -1384, -1137, -1583, -447, -622, -511,
+ -471, -656, -539, -211, -2131, 2754, -4501, 12879,
+ 7432, -277, -463, -1236, -10124, -3371, 358, -585,
+ 756, 1675, -2165, 3538, 967, -1249, 2042, -5842,
+ 5618, -515, 3219, -4149, 4857, -1926, -16, -632,
+ -1050, -1440, 176, -1104, 101, 1422, -130, 815,
+ -1666, 152, -954, 1230, 1838, -1709, 1139, 16867,
+ 716, -206, -178, -79, -17366, -31, 191, -127,
+ 118, -1892, 1759, -1173, -80, 74, -49, -737,
+ 1978, -3845, 10050, 11854, -2492, -238, -902, -6164,
+ -8576, -379, 464, -1213, 2358, -1431, 2782, -7271,
+ 301, -585, 1529, 1803, -2600, 11246, 11289, -3647,
+ 1463, -412, -7720, -7778, -812, -130, 1784, 1791,
+ -7749, -578, 2504, 2513, 232, -1004, -1008, 325,
+ 3442, 907, 2725, 8970, 3638, -723, -50, -453,
+ -4911, -808, -190, -572, -150, -1884, -496, -1492,
+ -764, -201, -605, -1992, -126, 17498, 3481, -2003,
+ 1090, 0, -18689, -739, -244, -72, 135, 26,
+ -3717, -15, 2139, 425, 8, -1165, -231, 133,
+ -1814, 1048, -2164, 4070, 16272, -200, -67, -285,
+ -1011, -16160, 116, -239, 138, 450, -260, 537,
+ 1801, -1041, 2149, -4042, 9354, 12580, -1883, 962,
+ -617, -5341, -9660, -216, -56, -23, -7183, 1075,
+ 1446, -549, -738, 110, 352, 474, -71, 36,
+ 1708, 4199, 7387, 6335, 1003, -178, -1076, -3330,
+ -2449, -61, -437, -770, -1893, -660, -1623, -2856,
+ -104, -257, -452, -388, -2624, 5623, 17310, -2353,
+ 592, -420, -1930, -18288, -338, -21, 900, 2772,
+ -5941, -376, 807, 2486, 94, -203, -625, 85,
+ 1211, -850, 1193, -1926, 15992, -89, -44, -86,
+ -226, -15609, 62, -88, 61, 142, -100, 140,
+ -1182, 830, -1165, 1880, 3983, -2054, 11506, -19,
+ 3622, -968, -257, -8080, 0, -801, 499, -2797,
+ 1442, 4, -2, 13, -880, 454, -2544, 4,
+ -786, -1354, 16092, 7246, -1665, -37, -111, -15805,
+ -3205, -169, -65, 772, 1330, 348, 599, -7117,
+ -80, -137, 1636, 736, -4316, -511, 6674, 11665,
+ 4633, -1137, -15, -2719, -8305, -1310, -134, 1758,
+ 208, 3073, 364, -4752, 1220, 144, -1887, -3299,
+ 7912, 4557, 1937, 1885, 7037, -3821, -1267, -229,
+ -216, -3022, -2200, -935, -538, -910, -524, -222,
+ -3398, -1957, -832, -809, 3434, 2967, 5867, 8196,
+ 8766, -720, -537, -2101, -4100, -4690, -622, -1230,
+ -1062, -1718, -1484, -2935, -1837, -1588, -3139, -4385,
+ 5881, 9176, 8119, 3934, 3355, -2111, -5139, -4023,
+ -944, -687, -3294, -2914, -4547, -1412, -2203, -1949,
+ -1204, -1879, -1662, -805
+};
+
+static const int16_t adaptive_cb_gain170[170 * 20] = {
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 776, 212, 715, 670,
+ 809, -36, -2, -31, -27, -39, -10, -33,
+ -9, -31, -8, -29, -38, -10, -35, -33,
+ 1296, 1316, -168, -320, -815, -102, -105, -1,
+ -6, -40, -104, 13, 13, 25, 25, -3,
+ 64, 65, -8, -15, -589, 680, 2478, 308,
+ -596, -21, -28, -375, -5, -21, 24, 89,
+ -102, 11, -12, -46, -21, 24, 90, 11,
+ -735, -487, -5, 2948, 468, -33, -14, 0,
+ -530, -13, -21, 0, 0, 132, 87, 0,
+ 21, 13, 0, -84, 1042, 1730, 1068, 333,
+ 626, -66, -182, -69, -6, -23, -110, -67,
+ -112, -21, -35, -21, -39, -66, -40, -12,
+ 486, -769, 4074, 2825, -1107, -14, -36, -1013,
+ -487, -74, 22, -120, 191, -83, 132, -702,
+ 32, -52, 275, 191, 1521, -767, -124, 4320,
+ 1026, -141, -35, 0, -1139, -64, 71, 11,
+ -5, -401, 202, 32, -95, 48, 7, -270,
+ 2425, 1267, 3439, -91, -1166, -359, -98, -722,
+ 0, -83, -187, -509, -266, 13, 7, 19,
+ 172, 90, 244, -6, -1251, 975, 173, 4039,
+ 2005, -95, -58, -1, -996, -245, 74, 13,
+ -10, 308, -240, -42, 153, -119, -21, -494,
+ 1820, 632, 1322, 2062, 1031, -202, -24, -106,
+ -259, -64, -70, -146, -51, -229, -79, -166,
+ -114, -39, -83, -129, -447, 4904, 244, -315,
+ -2038, -12, -1467, -3, -6, -253, 134, 6,
+ -73, -8, 94, 4, -55, 610, 30, -39,
+ -208, -1102, 463, -448, 5653, -2, -74, -13,
+ -12, -1950, -14, 5, 31, -5, -30, 12,
+ 71, 380, -159, 154, 4739, 2600, -1864, 856,
+ -1554, -1371, -412, -212, -44, -147, -752, 539,
+ 295, -247, -135, 97, 449, 246, -176, 81,
+ 1894, 3533, 35, -26, 2145, -219, -762, 0,
+ 0, -280, -408, -4, -7, 3, 5, 0,
+ -248, -462, -4, 3, -2699, 1841, 4072, 2443,
+ 1582, -444, -207, -1012, -364, -152, 303, 670,
+ -457, 402, -274, -607, 260, -177, -393, -236,
+ -844, 3358, 6106, -1059, -537, -43, -688, -2275,
+ -68, -17, 173, 314, -1251, -54, 217, 395,
+ -27, 110, 200, -34, 1251, 1016, 3020, 2210,
+ 1445, -95, -63, -556, -298, -127, -77, -230,
+ -187, -168, -137, -407, -110, -89, -266, -194,
+ 2099, 2277, 4038, 3533, -2870, -269, -316, -995,
+ -762, -503, -291, -517, -561, -452, -491, -871,
+ 367, 399, 707, 619, 400, -1114, 8516, 2422,
+ -1117, -9, -75, -4426, -358, -76, 27, -208,
+ 579, -59, 164, -1259, 27, -75, 580, 165,
+ -4398, -2011, 3912, -2407, 2258, -1180, -247, -934,
+ -353, -311, -540, 1050, 480, -646, -295, 575,
+ 606, 277, -539, 331, 1767, -1447, 4240, 6160,
+ -757, -190, -127, -1097, -2316, -35, 156, -457,
+ 374, -664, 544, -1594, 81, -66, 195, 284,
+ 1594, -1463, 1035, 6938, 1920, -155, -130, -65,
+ -2938, -225, 142, -100, 92, -675, 619, -438,
+ -186, 171, -121, -813, -562, 4716, 4085, -591,
+ 2421, -19, -1357, -1018, -21, -357, 162, 140,
+ -1175, -20, 170, 147, 83, -696, -603, 87,
+ 1552, 8778, -935, 354, -1424, -147, -4703, -53,
+ -7, -123, -831, 88, 501, -33, -189, 20,
+ 134, 763, -81, 30, 4831, -4431, 41, -1479,
+ -2976, -1424, -1198, 0, -133, -540, 1306, -12,
+ 11, 436, -400, 3, 877, -804, 7, -268,
+ 2090, 1192, 1006, 1645, 4853, -266, -86, -61,
+ -165, -1437, -152, -128, -73, -210, -119, -101,
+ -619, -353, -298, -487, 2386, 5712, 1426, -94,
+ 1350, -347, -1991, -124, 0, -111, -832, -207,
+ -497, 13, 32, 8, -196, -470, -117, 7,
+ -1349, 1091, 1659, 8891, 313, -111, -72, -168,
+ -4825, -5, 89, 136, -110, 732, -592, -900,
+ 25, -20, -31, -170, 9980, 916, -381, -808,
+ 88, -6080, -51, -8, -39, 0, -558, 232,
+ 21, 492, 45, -18, -53, -4, 2, 4,
+ 2338, -1031, -248, 3928, 6484, -333, -64, -3,
+ -942, -2566, 147, 35, -15, -560, 247, 59,
+ -925, 408, 98, -1555, 6166, -1240, -337, 3672,
+ -1277, -2320, -93, -6, -823, -99, 466, 126,
+ -25, -1382, 278, 75, 480, -96, -26, 286,
+ 4377, -132, -2588, 1701, 4865, -1169, -1, -409,
+ -176, -1444, 35, 691, -20, -454, 13, 268,
+ -1299, 39, 768, -505, 2594, 3295, 3944, 1481,
+ 682, -410, -662, -949, -133, -28, -521, -624,
+ -793, -234, -297, -356, -108, -137, -164, -61,
+ 4151, 624, 815, 4485, 2229, -1052, -23, -40,
+ -1228, -303, -158, -206, -31, -1136, -170, -223,
+ -565, -84, -111, -610, -3575, -361, 4924, 2791,
+ 4698, -780, -7, -1480, -475, -1347, -78, 1074,
+ 108, 609, 61, -839, 1025, 103, -1412, -800,
+ -2518, 3791, 8623, 315, 2465, -387, -877, -4538,
+ -6, -370, 582, 1325, -1995, 48, -73, -166,
+ 378, -570, -1297, -47, -691, 2989, 9957, -421,
+ -1142, -29, -545, -6051, -10, -79, 126, 420,
+ -1817, -17, 76, 256, -48, 208, 694, -29,
+ -1918, 104, -3190, -3410, -4440, -224, 0, -621,
+ -709, -1203, 12, -373, 20, -399, 21, -664,
+ -519, 28, -864, -924, -3359, -1668, 1854, 6939,
+ 1430, -688, -169, -209, -2939, -124, -341, 380,
+ 188, 1422, 706, -785, 293, 145, -161, -606,
+ 42, 9706, 3164, -952, 907, 0, -5750, -611,
+ -55, -50, -25, -8, -1874, 2, 564, 183,
+ -2, -537, -175, 52, 1607, 785, 2862, 4327,
+ 3307, -157, -37, -500, -1143, -667, -77, -280,
+ -137, -424, -207, -756, -324, -158, -577, -873,
+ 6801, 3416, 2227, 1682, -3217, -2823, -712, -302,
+ -172, -631, -1418, -924, -464, -698, -350, -228,
+ 1335, 670, 437, 330, 3459, 3898, 364, 7841,
+ -2640, -730, -927, -8, -3753, -425, -823, -76,
+ -86, -1655, -1865, -174, 557, 628, 58, 1263,
+ -5902, -3458, -2465, -1886, 4334, -2126, -730, -371,
+ -217, -1146, -1245, -888, -520, -679, -398, -283,
+ 1561, 915, 652, 499, -3710, 1133, 7849, 3443,
+ -215, -840, -78, -3760, -723, -2, 256, 1777,
+ -543, 779, -238, -1649, -48, 14, 103, 45,
+ 4132, 2828, 2, -4212, -4116, -1042, -488, 0,
+ -1083, -1034, -713, 0, 0, 1062, 727, 0,
+ 1038, 710, 0, -1058, 5875, 8496, -1796, 1376,
+ -1786, -2107, -4406, -197, -115, -194, -3047, 644,
+ 931, -493, -713, 150, 640, 926, -195, 150,
+ 3143, 3483, 3546, -793, 4489, -603, -740, -767,
+ -38, -1230, -668, -680, -754, 152, 168, 171,
+ -861, -954, -971, 217, 2845, 7965, 3695, -5432,
+ 3978, -494, -3873, -833, -1801, -966, -1383, -641,
+ -1796, 943, 2641, 1225, -691, -1934, -897, 1319,
+ 1538, 150, 7139, 2049, 3097, -144, -1, -3110,
+ -256, -585, -14, -670, -65, -192, -18, -892,
+ -290, -28, -1349, -387, 618, 7520, 4729, -238,
+ -3373, -23, -3452, -1365, -3, -694, -283, -178,
+ -2170, 8, 109, 68, 127, 1548, 973, -49,
+ 2965, -3013, 7912, 7076, -1997, -536, -554, -3821,
+ -3056, -243, 545, -1431, 1455, -1280, 1301, -3417,
+ 361, -367, 964, 862, 2443, -929, -1113, 9677,
+ 4138, -364, -52, -75, -5716, -1045, 138, 166,
+ -63, -1443, 549, 657, -617, 234, 281, -2444,
+ 1966, 3309, 10085, -3399, 2105, -236, -668, -6207,
+ -705, -270, -397, -1210, -2037, 408, 686, 2092,
+ -252, -425, -1295, 436, -112, -1368, 8868, 4822,
+ 2048, 0, -114, -4800, -1419, -256, -9, 61,
+ 740, 33, 402, -2610, 14, 171, -1108, -602,
+ -2597, 438, -1839, 6229, 7266, -411, -11, -206,
+ -2368, -3223, 69, -291, 49, 987, -166, 699,
+ 1152, -194, 816, -2763, 3454, 553, 9127, 4946,
+ -5596, -728, -18, -5084, -1493, -1911, -116, -1924,
+ -308, -1042, -166, -2755, 1179, 188, 3117, 1689,
+ -532, -663, 12262, 2495, -1004, -17, -26, -9177,
+ -380, -61, -21, 398, 496, 81, 101, -1867,
+ -32, -40, 751, 152, -2100, 1317, -1509, 11425,
+ 2997, -269, -105, -139, -7967, -548, 168, -193,
+ 121, 1464, -918, 1052, 384, -240, 276, -2090,
+ 1193, -2697, 11259, 5373, -763, -86, -444, -7737,
+ -1762, -35, 196, -819, 1853, -391, 884, -3692,
+ 55, -125, 525, 250, 2405, -471, 11079, 203,
+ 782, -353, -13, -7491, -2, -37, 69, -1626,
+ 318, -29, 5, -137, -114, 22, -529, -9,
+ -1871, 5685, 11290, -2662, 1353, -213, -1972, -7780,
+ -432, -111, 649, 1289, -3917, -304, 923, 1834,
+ 154, -469, -932, 220, -3768, 5927, -3093, 5041,
+ 5212, -866, -2144, -584, -1551, -1658, 1363, -711,
+ 1119, 1159, -1824, 951, 1198, -1885, 984, -1603,
+ -2546, 9502, 5969, -2440, 1928, -395, -5511, -2175,
+ -363, -226, 1477, 927, -3462, -379, 1415, 889,
+ 299, -1118, -702, 287, -4963, 3568, 4592, 5508,
+ 3451, -1503, -777, -1287, -1851, -727, 1080, 1391,
+ -1000, 1668, -1199, -1543, 1045, -751, -967, -1160,
+ 1745, -2586, 3983, 10899, -1551, -186, -408, -968,
+ -7250, -146, 275, -424, 628, -1161, 1720, -2649,
+ 165, -244, 377, 1032, 867, -456, -727, 3369,
+ 11822, -45, -12, -32, -692, -8531, 24, 38,
+ -20, -178, 93, 149, -625, 329, 525, -2431,
+ 7535, 2422, 1926, 1405, 1599, -3466, -358, -226,
+ -120, -156, -1114, -886, -284, -646, -207, -165,
+ -735, -236, -188, -137, 1041, -735, -142, 13209,
+ 1515, -66, -33, -1, -10649, -140, 46, 9,
+ -6, -839, 593, 114, -96, 68, 13, -1222,
+ 7950, 6745, -1444, -1008, 2721, -3857, -2777, -127,
+ -62, -452, -3273, 700, 594, 489, 415, -88,
+ -1320, -1120, 239, 167, -4754, -1379, 4522, -578,
+ -5733, -1379, -116, -1248, -20, -2006, -400, 1312,
+ 380, -167, -48, 159, -1663, -482, 1582, -202,
+ 3220, 5978, 5923, 2430, -2689, -633, -2181, -2141,
+ -360, -441, -1175, -1164, -2161, -477, -886, -878,
+ 528, 981, 972, 398, 377, 1312, 13978, -1470,
+ 677, -8, -105, -11925, -132, -28, -30, -321,
+ -1119, 33, 117, 1254, -15, -54, -577, 60,
+ -3435, 6770, 314, -885, 5686, -720, -2797, -6,
+ -47, -1973, 1419, 65, -129, -185, 366, 16,
+ 1192, -2349, -109, 307, 3171, 8774, -2260, 2679,
+ 3069, -613, -4699, -312, -438, -575, -1698, 437,
+ 1210, -518, -1435, 369, -594, -1643, 423, -501,
+ 5557, 1509, 5407, -125, -7386, -1884, -139, -1784,
+ 0, -3330, -511, -1834, -498, 42, 11, 41,
+ 2505, 680, 2438, -56, -2838, 2595, 13228, 271,
+ 1793, -491, -411, -10680, -4, -196, 449, 2291,
+ -2095, 47, -42, -219, 310, -284, -1447, -29,
+ 664, -278, 14966, 951, -711, -26, -4, -13672,
+ -55, -30, 11, -606, 253, -38, 16, -869,
+ 28, -12, 650, 41, 808, 1770, 8658, 5863,
+ -1486, -39, -191, -4576, -2098, -134, -87, -427,
+ -935, -289, -633, -3098, 73, 160, 785, 531,
+ 3063, 1539, 2000, -542, 9576, -572, -144, -244,
+ -17, -5597, -287, -374, -188, 101, 51, 66,
+ -1790, -900, -1169, 317, 514, 14083, -323, 896,
+ -891, -16, -12106, -6, -49, -48, -442, 10,
+ 277, -28, -770, 17, 27, 766, -17, 48,
+ 892, 158, 5237, 11057, -1603, -48, -1, -1674,
+ -7462, -156, -8, -285, -50, -602, -106, -3534,
+ 87, 15, 512, 1082, -1612, 2564, -4296, 12526,
+ 5710, -158, -401, -1126, -9576, -1990, 252, -422,
+ 672, 1232, -1960, 3284, 561, -893, 1497, -4365,
+ 4889, -6878, 612, 6109, 4753, -1459, -2887, -22,
+ -2277, -1379, 2052, -182, 257, -1823, 2564, -228,
+ -1418, 1995, -177, -1772, 3053, -506, 2403, 9625,
+ 1322, -569, -15, -352, -5655, -106, 94, -448,
+ 74, -1794, 297, -1412, -246, 40, -194, -777,
+ -754, 12904, 4480, -2113, 1471, -34, -10163, -1225,
+ -272, -132, 594, 206, -3529, -97, 1664, 577,
+ 67, -1159, -402, 189, 4255, 1476, 5055, 2393,
+ 2912, -1105, -132, -1559, -349, -517, -383, -1313,
+ -455, -621, -215, -738, -756, -262, -898, -425,
+ -1371, 535, 1417, 14604, -997, -114, -17, -122,
+ -13017, -60, 44, 118, -46, 1222, -477, -1263,
+ -83, 32, 86, 888, 5368, -1744, 4083, -1236,
+ 3753, -1758, -185, -1017, -93, -860, 571, -1338,
+ 434, 405, -131, 308, -1229, 399, -935, 283,
+ 1588, -3097, 14415, 3699, -1171, -154, -585, -12683,
+ -835, -83, 300, -1397, 2725, -358, 699, -3255,
+ 113, -221, 1030, 264, 212, 7989, 9471, -3344,
+ 2009, -2, -3895, -5475, -682, -246, -103, -123,
+ -4618, 43, 1630, 1933, -26, -979, -1161, 410,
+ 856, 2294, -627, 6930, 6929, -44, -321, -24,
+ -2931, -2930, -119, 32, 87, -362, -970, 265,
+ -362, -970, 265, -2931, 2357, -4187, 7162, 7683,
+ 3371, -339, -1070, -3131, -3603, -693, 602, -1030,
+ 1830, -1105, 1963, -3359, -485, 861, -1474, -1581,
+ 350, 4585, 14053, -3819, 1218, -7, -1283, -12054,
+ -890, -90, -97, -300, -3933, 81, 1068, 3275,
+ -26, -341, -1045, 284, -3248, 3531, 475, 2137,
+ 11711, -644, -761, -13, -278, -8372, 700, 94,
+ -102, 423, -460, -62, 2322, -2524, -340, -1528,
+ -3017, 3852, 1725, 8440, 5257, -555, -905, -181,
+ -4348, -1686, 709, 317, -405, 1554, -1984, -889,
+ 968, -1236, -553, -2708, -909, 3196, 15512, -2528,
+ 1066, -50, -623, -14686, -390, -69, 177, 861,
+ -3026, -140, 493, 2393, 59, -208, -1009, 164,
+ 959, -3370, 9617, 9545, -1761, -56, -693, -5645,
+ -5561, -189, 197, -563, 1978, -558, 1963, -5603,
+ 103, -362, 1034, 1026, 7575, 11796, -4845, 3252,
+ -1703, -3502, -8493, -1433, -645, -177, -5454, 2240,
+ 3488, -1503, -2341, 961, 787, 1226, -503, 338,
+ 6409, 1722, 1764, -4191, 6015, -2507, -181, -189,
+ -1072, -2208, -673, -690, -185, 1639, 440, 451,
+ -2353, -632, -647, 1538, -2420, 12161, 5038, 1286,
+ -2098, -357, -9027, -1549, -100, -268, 1796, 744,
+ -3740, 190, -954, -395, -310, 1557, 645, 164,
+ -2232, -1341, 7246, 9470, -1977, -304, -109, -3204,
+ -5474, -238, -182, 987, 593, 1290, 775, -4188,
+ -269, -161, 874, 1143, 1030, 7034, 4231, 1551,
+ 3077, -64, -3019, -1093, -146, -577, -442, -266,
+ -1816, -97, -666, -400, -193, -1321, -794, -291,
+ 5121, 11835, -477, -1749, 2298, -1601, -8549, -13,
+ -186, -322, -3699, 149, 344, 546, 1264, -50,
+ -718, -1660, 66, 245, -3328, 3827, 5921, 9976,
+ -1045, -676, -894, -2140, -6075, -66, 777, 1203,
+ -1383, 2027, -2330, -3605, -212, 244, 377, 636,
+ 3813, 5718, -4666, -3412, 5674, -887, -1995, -1329,
+ -710, -1965, -1331, 1086, 1628, 794, 1191, -972,
+ -1320, -1980, 1616, 1181, 1348, -3672, 13154, 6938,
+ -1690, -110, -823, -10561, -2938, -174, 302, -1082,
+ 2948, -570, 1555, -5570, 139, -379, 1357, 716,
+ 2151, -3586, 6949, 12131, -1224, -282, -785, -2947,
+ -8982, -91, 470, -912, 1521, -1592, 2655, -5145,
+ 160, -268, 519, 906, -2889, 9647, 10276, -2728,
+ 995, -509, -5680, -6445, -454, -60, 1701, 1812,
+ -6051, -481, 1606, 1711, 175, -586, -624, 165,
+ 6177, 2184, 555, 1985, 6589, -2329, -291, -18,
+ -240, -2650, -823, -209, -74, -748, -264, -67,
+ -2484, -878, -223, -798, -492, 391, 17166, -681,
+ 240, -14, -9, -17987, -28, -3, 11, 515,
+ -410, -20, 16, 713, 7, -5, -252, 10,
+ 12628, 5448, -2630, 3011, -2695, -9733, -1811, -422,
+ -553, -443, -4199, 2027, 874, -2321, -1001, 483,
+ 2077, 896, -432, 495, -3628, -534, 3447, 7002,
+ 6751, -803, -17, -725, -2992, -2782, -118, 763,
+ 112, 1550, 228, -1473, 1495, 220, -1420, -2885,
+ -5239, 5901, 8107, 3650, 4846, -1675, -2125, -4012,
+ -813, -1433, 1887, 2592, -2920, 1167, -1315, -1806,
+ 1550, -1745, -2398, -1080, 6157, 6678, 4099, -1074,
+ 2348, -2314, -2722, -1025, -70, -336, -2509, -1540,
+ -1670, 403, 437, 268, -882, -957, -587, 153,
+ 1079, 16099, 242, -881, 1690, -71, -15820, -3,
+ -47, -174, -1060, -16, -238, 58, 865, 13,
+ -111, -1661, -25, 90, -278, 227, -1039, 1636,
+ 16945, -4, -3, -65, -163, -17526, 3, -17,
+ 14, 27, -22, 103, 287, -234, 1074, -1693,
+ 15778, -1454, 574, -603, -107, -15195, -129, -20,
+ -22, 0, 1400, -553, 51, 581, -53, 21,
+ 103, -9, 3, -3, 2406, -836, 13224, 7993,
+ -4266, -353, -42, -10673, -3899, -1111, 122, -1942,
+ 674, -1174, 407, -6451, 626, -217, 3443, 2081,
+ 3184, 14368, -3336, 2255, -1801, -619, -12600, -679,
+ -310, -198, -2793, 648, 2926, -438, -1977, 459,
+ 350, 1580, -366, 247, -1698, 17076, 2504, -539,
+ -646, -176, -17798, -382, -17, -25, 1770, 259,
+ -2610, -55, 561, 82, -67, 673, 98, -21,
+ 2375, -797, -2696, 14483, 5383, -344, -38, -443,
+ -12803, -1769, 115, 391, -131, -2100, 705, 2384,
+ -780, 262, 886, -4759, -2691, 2554, -4520, 9573,
+ 10655, -442, -398, -1247, -5594, -6930, 419, -742,
+ 704, 1572, -1492, 2641, 1750, -1661, 2939, -6226,
+ -4332, -4399, -1657, 4880, 7375, -1145, -1181, -167,
+ -1453, -3319, -1163, -438, -444, 1290, 1310, 493,
+ 1950, 1980, 745, -2196, -3498, 7405, 9955, 2693,
+ -2971, -746, -3347, -6049, -442, -538, 1581, 2125,
+ -4499, 575, -1217, -1636, -634, 1342, 1805, 488,
+ 6717, -3792, 7739, 2798, 3489, -2754, -877, -3655,
+ -477, -743, 1554, -3173, 1791, -1147, 647, -1321,
+ -1430, 807, -1648, -595, 5263, 9770, 3463, 1069,
+ -3971, -1690, -5826, -732, -69, -962, -3138, -1112,
+ -2065, -343, -637, -226, 1275, 2368, 839, 259,
+ 1243, -2634, 16772, 1871, 332, -94, -423, -17169,
+ -213, -6, 199, -1273, 2696, -142, 300, -1915,
+ -25, 53, -339, -37, 2691, 2836, 3105, 5711,
+ 4817, -442, -491, -588, -1991, -1416, -465, -510,
+ -537, -938, -988, -1082, -791, -834, -913, -1679,
+ 4366, 2944, 7210, 3627, 1161, -1163, -529, -3172,
+ -803, -82, -784, -1921, -1295, -966, -651, -1596,
+ -309, -208, -511, -257, 13888, 3951, -671, -2305,
+ 3354, -11773, -953, -27, -324, -686, -3349, 569,
+ 161, 1954, 556, -94, -2843, -809, 137, 472,
+ 7053, 5847, 2929, 8378, -4794, -3036, -2086, -523,
+ -4284, -1403, -2517, -1261, -1045, -3607, -2990, -1498,
+ 2064, 1711, 857, 2451, -2191, 12838, 9182, -3915,
+ 1617, -293, -10059, -5146, -935, -159, 1717, 1228,
+ -7195, -523, 3068, 2194, 216, -1267, -906, 386,
+ -4881, 13114, 5767, -435, 4155, -1454, -10498, -2030,
+ -11, -1054, 3907, 1718, -4616, -129, 348, 153,
+ 1238, -3326, -1462, 110, 7843, -1250, 210, 7106,
+ -5203, -3754, -95, -2, -3082, -1652, 598, -100,
+ 16, -3402, 542, -91, 2491, -397, 66, 2257,
+ -2463, 8168, 14551, -3908, 1828, -370, -4072, -12923,
+ -932, -204, 1228, 2188, -7254, -587, 1948, 3471,
+ 274, -911, -1623, 436, -1579, 347, -272, -2735,
+ 16031, -152, -7, -4, -456, -15686, 33, -26,
+ 5, -263, 58, -45, 1545, -340, 266, 2676,
+ -6327, 1328, 5093, -5079, 7617, -2443, -107, -1583,
+ -1574, -3541, 513, 1967, -413, -1961, 411, 1578,
+ 2941, -617, -2367, 2361, 3286, -4509, 11306, 11025,
+ -2623, -659, -1241, -7802, -7419, -420, 904, -2267,
+ 3112, -2211, 3034, -7608, 526, -722, 1810, 1765,
+ 5567, 17853, -3754, 1166, -519, -1892, -19455, -860,
+ -83, -16, -6067, 1275, 4090, -396, -1271, 267,
+ 176, 566, -119, 37, -2136, -424, 15292, 5108,
+ -1648, -278, -10, -14273, -1593, -165, -55, 1993,
+ 396, 666, 132, -4768, -214, -42, 1538, 514,
+ 2267, -3297, 2549, 16563, -791, -313, -663, -396,
+ -16745, -38, 456, -352, 513, -2291, 3333, -2576,
+ 109, -159, 123, 799, 3655, 1899, -3364, 6279,
+ 12510, -815, -220, -690, -2406, -9552, -423, 750,
+ 390, -1400, -728, 1289, -2791, -1450, 2568, -4794,
+ 8052, 2285, -6193, 5138, 6003, -3957, -318, -2341,
+ -1611, -2199, -1123, 3044, 864, -2525, -716, 1942,
+ -2950, -837, 2269, -1882, -386, -2291, 7679, 15387,
+ -2723, -9, -320, -3599, -14452, -452, -54, 181,
+ 1074, 362, 2152, -7212, -64, -380, 1276, 2557,
+ 2777, -1173, 3984, 13079, 2508, -470, -84, -969,
+ -10440, -384, 198, -675, 285, -2217, 936, -3180,
+ -425, 179, -610, -2002, -1879, 1771, -2684, 16705,
+ 1833, -215, -191, -439, -17032, -205, 203, -308,
+ 290, 1916, -1805, 2736, 210, -198, 300, -1869,
+ 1052, 4495, 15519, 1467, -4032, -67, -1233, -14700,
+ -131, -992, -288, -997, -4257, -94, -402, -1389,
+ 259, 1106, 3819, 361, 3010, 2544, 6969, 7559,
+ 1996, -553, -395, -2964, -3487, -243, -467, -1280,
+ -1082, -1388, -1174, -3215, -366, -310, -849, -921,
+ -5209, -1867, 8713, 10351, 1549, -1656, -212, -4634,
+ -6540, -146, -593, 2770, 993, 3291, 1180, -5505,
+ 492, 176, -824, -979, -4314, 8513, 913, 7547,
+ -2723, -1135, -4423, -50, -3476, -452, 2241, 240,
+ -474, 1987, -3921, -420, -717, 1415, 151, 1254,
+ 12929, -1219, 2448, 1757, 6303, -10204, -90, -365,
+ -188, -2425, 962, -1932, 182, -1386, 130, -262,
+ -4974, 469, -941, -676, 6465, 4132, 3167, 3160,
+ 5697, -2551, -1042, -612, -609, -1981, -1630, -1249,
+ -798, -1247, -797, -611, -2248, -1437, -1101, -1099,
+ -3636, 4859, 18914, -1335, 810, -807, -1441, -21836,
+ -108, -40, 1078, 4198, -5609, -296, 396, 1541,
+ 179, -240, -936, 66, 8844, 7864, 654, -4063,
+ -5680, -4774, -3774, -26, -1007, -1969, -4245, -353,
+ -314, 2193, 1950, 162, 3066, 2726, 226, -1408,
+ 1859, 2634, 9228, 996, 9464, -211, -423, -5197,
+ -60, -5467, -299, -1047, -1483, -113, -160, -561,
+ -1074, -1521, -5330, -575, 2949, 12260, 10290, -497,
+ -3943, -530, -9174, -6463, -15, -949, -2206, -1852,
+ -7700, 89, 372, 312, 709, 2950, 2476, -119,
+ -2903, 1552, 14867, 9970, -496, -514, -147, -13491,
+ -6068, -15, 275, 2634, -1408, 1766, -944, -9047,
+ -87, 47, 450, 302, 3243, 8234, 7586, 3373,
+ 2151, -642, -4138, -3512, -694, -282, -1630, -1501,
+ -3812, -667, -1695, -1561, -425, -1081, -996, -442,
+ -9631, 60, 3501, 5359, 10150, -5662, 0, -748,
+ -1752, -6288, 35, 2058, -12, 3150, -19, -1145,
+ 5967, -37, -2169, -3320, -6874, -2553, -5446, -2195,
+ -7841, -2884, -397, -1810, -294, -3753, -1071, -2285,
+ -848, -921, -342, -729, -3290, -1221, -2606, -1050,
+ -3413, -1141, 4630, 13612, 7897, -711, -79, -1308,
+ -11310, -3806, -237, 964, 322, 2836, 948, -3847,
+ 1645, 550, -2231, -6561, 4410, -5678, 8006, -3992,
+ 3811, -1187, -1968, -3912, -973, -886, 1528, -2155,
+ 2775, 1074, -1383, 1951, -1025, 1321, -1862, 928,
+ 5659, 11535, 2203, -452, 7169, -1954, -8121, -296,
+ -12, -3137, -3984, -761, -1551, 156, 318, 60,
+ -2476, -5048, -964, 197, 2914, -2914, 3485, -3965,
+ 13675, -518, -518, -741, -959, -11414, 518, -620,
+ 620, 705, -705, 843, -2433, 2432, -2909, 3310,
+ 7843, 1907, 1022, 8882, 7972, -3755, -222, -63,
+ -4815, -3879, -913, -489, -119, -4252, -1034, -554,
+ -3816, -928, -497, -4322, 13807, 9531, 1436, 1612,
+ 1779, -11636, -5544, -125, -158, -193, -8032, -1210,
+ -835, -1358, -938, -141, -1499, -1035, -156, -175,
+ 13620, -5337, 5450, -2263, 1723, -11322, -1738, -1813,
+ -312, -181, 4436, -4531, 1775, 1881, -737, 752,
+ -1432, 561, -573, 238, 5297, 8374, 8872, 7694,
+ 6538, -1712, -4280, -4804, -3613, -2609, -2707, -2868,
+ -4534, -2487, -3932, -4166, -2113, -3341, -3540, -3070
+};
+
+/**
+ * 0.65^i (Zero part) and 0.75^i (Pole part) scaled by 2^15
+ */
+static const int16_t postfilter_tbl[2][LPC_ORDER] = {
+ /* Zero */
+ {21299, 13844, 8999, 5849, 3802, 2471, 1606, 1044, 679, 441},
+ /* Pole */
+ {24576, 18432, 13824, 10368, 7776, 5832, 4374, 3281, 2460, 1845}
+};
+
+/**
+ * Hamming window coefficients scaled by 2^15
+ */
+static const int16_t hamming_window[LPC_FRAME] = {
+ 2621, 2631, 2659, 2705, 2770, 2853, 2955, 3074, 3212, 3367,
+ 3541, 3731, 3939, 4164, 4405, 4663, 4937, 5226, 5531, 5851,
+ 6186, 6534, 6897, 7273, 7661, 8062, 8475, 8899, 9334, 9780,
+ 10235, 10699, 11172, 11653, 12141, 12636, 13138, 13645, 14157, 14673,
+ 15193, 15716, 16242, 16769, 17298, 17827, 18356, 18884, 19411, 19935,
+ 20457, 20975, 21489, 21999, 22503, 23002, 23494, 23978, 24455, 24924,
+ 25384, 25834, 26274, 26704, 27122, 27529, 27924, 28306, 28675, 29031,
+ 29373, 29700, 30012, 30310, 30592, 30857, 31107, 31340, 31557, 31756,
+ 31938, 32102, 32249, 32377, 32488, 32580, 32654, 32710, 32747, 32766,
+ 32766, 32747, 32710, 32654, 32580, 32488, 32377, 32249, 32102, 31938,
+ 31756, 31557, 31340, 31107, 30857, 30592, 30310, 30012, 29700, 29373,
+ 29031, 28675, 28306, 27924, 27529, 27122, 26704, 26274, 25834, 25384,
+ 24924, 24455, 23978, 23494, 23002, 22503, 21999, 21489, 20975, 20457,
+ 19935, 19411, 18884, 18356, 17827, 17298, 16769, 16242, 15716, 15193,
+ 14673, 14157, 13645, 13138, 12636, 12141, 11653, 11172, 10699, 10235,
+ 9780, 9334, 8899, 8475, 8062, 7661, 7273, 6897, 6534, 6186,
+ 5851, 5531, 5226, 4937, 4663, 4405, 4164, 3939, 3731, 3541,
+ 3367, 3212, 3074, 2955, 2853, 2770, 2705, 2659, 2631, 2621
+};
+
+/**
+ * Binomial window coefficients scaled by 2^15
+ */
+static const int16_t binomial_window[LPC_ORDER] = {
+ 32749, 32695, 32604, 32477, 32315, 32118, 31887, 31622, 31324, 30995
+};
+
+/**
+ * 0.994^i scaled by 2^15
+ */
+static const int16_t bandwidth_expand[LPC_ORDER] = {
+ 32571, 32376, 32182, 31989, 31797, 31606, 31416, 31228, 31040, 30854
+};
+
+/**
+ * 0.5^i scaled by 2^15
+ */
+static const int16_t percept_flt_tbl[2][LPC_ORDER] = {
+ /* Zero part */
+ {29491, 26542, 23888, 21499, 19349, 17414, 15673, 14106, 12695, 11425},
+ /* Pole part */
+ {16384, 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32}
+};
diff --git a/libavcodec/g726.c b/libavcodec/g726.c
index 09df727c0f..2ce113b24b 100644
--- a/libavcodec/g726.c
+++ b/libavcodec/g726.c
@@ -5,20 +5,20 @@
* This is a very straightforward rendition of the G.726
* Section 4 "Computational Details".
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <limits.h>
@@ -392,14 +392,13 @@ static int g726_decode_frame(AVCodecContext *avctx,
#if CONFIG_ADPCM_G726_ENCODER
AVCodec ff_adpcm_g726_encoder = {
- "g726",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_ADPCM_G726,
- sizeof(G726Context),
- g726_init,
- g726_encode_frame,
- g726_close,
- NULL,
+ .name = "g726",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_ADPCM_G726,
+ .priv_data_size = sizeof(G726Context),
+ .init = g726_init,
+ .encode = g726_encode_frame,
+ .close = g726_close,
.capabilities = CODEC_CAP_SMALL_LAST_FRAME,
.sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
.long_name = NULL_IF_CONFIG_SMALL("G.726 ADPCM"),
@@ -407,13 +406,12 @@ AVCodec ff_adpcm_g726_encoder = {
#endif
AVCodec ff_adpcm_g726_decoder = {
- "g726",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_ADPCM_G726,
- sizeof(G726Context),
- g726_init,
- NULL,
- g726_close,
- g726_decode_frame,
+ .name = "g726",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_ADPCM_G726,
+ .priv_data_size = sizeof(G726Context),
+ .init = g726_init,
+ .close = g726_close,
+ .decode = g726_decode_frame,
.long_name = NULL_IF_CONFIG_SMALL("G.726 ADPCM"),
};
diff --git a/libavcodec/g729.h b/libavcodec/g729.h
new file mode 100644
index 0000000000..61683130a9
--- /dev/null
+++ b/libavcodec/g729.h
@@ -0,0 +1,29 @@
+/*
+ * G.729, G729 Annex D decoders
+ * Copyright (c) 2008 Vladimir Voroshilov
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#ifndef AVCODEC_G729_H
+#define AVCODEC_G729_H
+
+/**
+ * subframe size
+ */
+#define SUBFRAME_SIZE 40
+
+#endif // AVCODEC_G729_H
diff --git a/libavcodec/g729data.h b/libavcodec/g729data.h
index 48010a7683..365ca47ec6 100644
--- a/libavcodec/g729data.h
+++ b/libavcodec/g729data.h
@@ -1,21 +1,21 @@
/*
- * data for G.729 decoder
+ * data for G.729, G729 Annex D decoders
* Copyright (c) 2007 Vladimir Voroshilov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -246,7 +246,56 @@ static const int16_t cb_gain_2nd_8k[1<<GC_2ND_IDX_BITS_8K][2] = { /*(1.14) (1.13
};
/**
+ * gain codebook (first stage), 6.4k mode (D.3.9.2 of G.729)
+ */
+static const int16_t cb_gain_1st_6k4[1<<GC_1ST_IDX_BITS_6K4][2] =
+{ /*(0.14) (1.14)*/
+ { 5849, 0 },
+ { 3171, 9280 },
+ { 3617, 6747 },
+ { 4987, 22294 },
+ { 2929, 1078 },
+ { 6068, 6093 },
+ { 9425, 2731 },
+ { 3915, 12872 },
+};
+
+/**
+ * gain codebook (second stage), 6.4k mode (D.3.9.2 of G.729)
+ */
+static const int16_t cb_gain_2nd_6k4[1<<GC_2ND_IDX_BITS_6K4][2] =
+{ /*(1.14) (1.14)*/
+ { 0, 4175 },
+ {10828, 27602 },
+ {16423, 15724 },
+ { 4478, 7324 },
+ { 3988, 0 },
+ {10291, 11385 },
+ {11956, 10735 },
+ { 7876, 7821 },
+};
+
+/**
* 4th order Moving Average (MA) Predictor codebook (3.2.4 of G.729)
+ *
+ * float cb_ma_predictor_float[2][MA_NP][10] = {
+ * {
+ * {0.2570, 0.2780, 0.2800, 0.2736, 0.2757, 0.2764, 0.2675, 0.2678, 0.2779, 0.2647},
+ * {0.2142, 0.2194, 0.2331, 0.2230, 0.2272, 0.2252, 0.2148, 0.2123, 0.2115, 0.2096},
+ * {0.1670, 0.1523, 0.1567, 0.1580, 0.1601, 0.1569, 0.1589, 0.1555, 0.1474, 0.1571},
+ * {0.1238, 0.0925, 0.0798, 0.0923, 0.0890, 0.0828, 0.1010, 0.0988, 0.0872, 0.1060},
+ * },
+ * {
+ * {0.2360, 0.2405, 0.2499, 0.2495, 0.2517, 0.2591, 0.2636, 0.2625, 0.2551, 0.2310},
+ * {0.1285, 0.0925, 0.0779, 0.1060, 0.1183, 0.1176, 0.1277, 0.1268, 0.1193, 0.1211},
+ * {0.0981, 0.0589, 0.0401, 0.0654, 0.0761, 0.0728, 0.0841, 0.0826, 0.0776, 0.0891},
+ * {0.0923, 0.0486, 0.0287, 0.0498, 0.0526, 0.0482, 0.0621, 0.0636, 0.0584, 0.0794},
+ * },
+ * };
+ * 15
+ * cb_ma_predictor[j][k][i] = floor( 2 * cb_ma_predictor_float[j][k][i] )
+ *
+ * j=0..1, i=0..9, k=0..MA_NP-1
*/
static const int16_t cb_ma_predictor[2][MA_NP][10] = { /* (0.15) */
{
@@ -263,16 +312,71 @@ static const int16_t cb_ma_predictor[2][MA_NP][10] = { /* (0.15) */
}
};
+/**
+ * 15 3
+ * cb_ma_predictor_sum[j][i] = floor( 2 * (1.0 - sum ( cb_ma_predictor_float[j][k][i] ) ) )
+ * k=0
+ * j=0..1, i=0..9
+ */
static const int16_t cb_ma_predictor_sum[2][10] = { /* (0.15) */
{ 7798, 8447, 8205, 8293, 8126, 8477, 8447, 8703, 9043, 8604},
{14585, 18333, 19772, 17344, 16426, 16459, 15155, 15220, 16043, 15708}
};
/**
+ * 12
+ * 2
+ * cb_ma_predictor_sum_inv[j][i] = floor(---------------------------------------------)
+ * 3
+ * 1.0 - sum ( cb_ma_predictor_float[j][k][i] )
+ * k=0
+ * j=0..1, i=0..9
+ */
+static const int16_t cb_ma_predictor_sum_inv[2][10] = { /* (3.12) */
+ {17210, 15888, 16357, 16183, 16516, 15833, 15888, 15421, 14840, 15597},
+ { 9202, 7320, 6788, 7738, 8170, 8154, 8856, 8818, 8366, 8544}
+};
+
+/**
+ * MA prediction coefficients (3.9.1 of G.729, near Equation 69)
+ */
+static const uint16_t ma_prediction_coeff[4] = { /* (0.13) */
+ 5571, 4751, 2785, 1556
+};
+
+/**
* initial LSP coefficients belongs to virtual frame preceding the
* first frame of the stream
*/
static const int16_t lsp_init[10]= { /* (0.15) */
30000, 26000, 21000, 15000, 8000, 0, -8000,-15000,-21000,-26000
};
+
+/**
+ * additional "phase" post-processing filter impulse response (D.6.2 of G.729)
+ *
+ * Table contains three impulse responses, correspond to
+ * different amounts of spreading.
+ */
+static const int16_t phase_filter[3][40] =
+{
+ { // maximum spreading (for noise-like segments)
+ 14690, 11518, 1268, -2762, -5672, 7514, -36, -2808, -3041, 4823,
+ 2952, -8425, 3785, 1455, 2179, -8638, 8051, -2104, -1455, 777,
+ 1108, -2386, 2254, -364, -675, -2104, 6046, -5682, 1072, 3123,
+ -5059, 5312, -2330, -3729, 6924, -3890, 675, -1776, 29, 10145,
+ },
+ { // medium spreading
+ 30274, 3831, -4037, 2972, -1049, -1003, 2477, -3044, 2815, -2232,
+ 1753, -1612, 1714, -1776, 1543, -1009, 429, -170, 472, -1265,
+ 2176, -2707, 2523, -1622, 344, 826, -1530, 1724, -1658, 1701,
+ -2064, 2644, -3061, 2897, -1979, 557, 780, -1370, 842, 655,
+ },
+ { // no spreading (for voiced speech)
+ 32767, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ }
+};
#endif /* AVCODEC_G729DATA_H */
diff --git a/libavcodec/g729dec.c b/libavcodec/g729dec.c
index 71e7c5d4c8..d76567974f 100644
--- a/libavcodec/g729dec.c
+++ b/libavcodec/g729dec.c
@@ -1,41 +1,41 @@
/*
- * G.729 decoder
+ * G.729, G729 Annex D decoders
* Copyright (c) 2008 Vladimir Voroshilov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include <stdlib.h>
+
#include <inttypes.h>
-#include <limits.h>
-#include <stdio.h>
#include <string.h>
-#include <math.h>
-#include <assert.h>
#include "avcodec.h"
#include "libavutil/avutil.h"
#include "get_bits.h"
+#include "dsputil.h"
+#include "g729.h"
#include "lsp.h"
#include "celp_math.h"
+#include "celp_filters.h"
#include "acelp_filters.h"
#include "acelp_pitch_delay.h"
#include "acelp_vectors.h"
#include "g729data.h"
+#include "g729postfilter.h"
/**
* minimum quantized LSF value (3.2.4)
@@ -55,6 +55,9 @@
*/
#define LSFQ_DIFF_MIN 321
+/// interpolation filter length
+#define INTERPOL_LEN 11
+
/**
* minimum gain pitch value (3.8, Equation 47)
* 0.2 in (1.14)
@@ -71,10 +74,19 @@
#define SHARP_MAX 13017
/**
- * subframe size
+ * MR_ENERGY (mean removed energy) = mean_energy + 10 * log10(2^26 * subframe_size) in (7.13)
*/
-#define SUBFRAME_SIZE 40
+#define MR_ENERGY 1018156
+
+#define DECISION_NOISE 0
+#define DECISION_INTERMEDIATE 1
+#define DECISION_VOICE 2
+typedef enum {
+ FORMAT_G729_8K = 0,
+ FORMAT_G729D_6K4,
+ FORMAT_COUNT,
+} G729Formats;
typedef struct {
uint8_t ac_index_bits[2]; ///< adaptive codebook index for second subframe (size in bits)
@@ -86,6 +98,12 @@ typedef struct {
} G729FormatDescription;
typedef struct {
+ DSPContext dsp;
+
+ /// past excitation signal buffer
+ int16_t exc_base[2*SUBFRAME_SIZE+PITCH_DELAY_MAX+INTERPOL_LEN];
+
+ int16_t* exc; ///< start of past excitation data in buffer
int pitch_delay_int_prev; ///< integer part of previous subframe's pitch delay (4.1.3)
/// (2.13) LSP quantizer outputs
@@ -95,6 +113,43 @@ typedef struct {
int16_t lsfq[10]; ///< (2.13) quantized LSF coefficients from previous frame
int16_t lsp_buf[2][10]; ///< (0.15) LSP coefficients (previous and current frames) (3.2.5)
int16_t *lsp[2]; ///< pointers to lsp_buf
+
+ int16_t quant_energy[4]; ///< (5.10) past quantized energy
+
+ /// previous speech data for LP synthesis filter
+ int16_t syn_filter_data[10];
+
+
+ /// residual signal buffer (used in long-term postfilter)
+ int16_t residual[SUBFRAME_SIZE + RES_PREV_DATA_SIZE];
+
+ /// previous speech data for residual calculation filter
+ int16_t res_filter_data[SUBFRAME_SIZE+10];
+
+ /// previous speech data for short-term postfilter
+ int16_t pos_filter_data[SUBFRAME_SIZE+10];
+
+ /// (1.14) pitch gain of current and five previous subframes
+ int16_t past_gain_pitch[6];
+
+ /// (14.1) gain code from current and previous subframe
+ int16_t past_gain_code[2];
+
+ /// voice decision on previous subframe (0-noise, 1-intermediate, 2-voice), G.729D
+ int16_t voice_decision;
+
+ int16_t onset; ///< detected onset level (0-2)
+ int16_t was_periodic; ///< whether previous frame was declared as periodic or not (4.4)
+ int16_t ht_prev_data; ///< previous data for 4.2.3, equation 86
+ int gain_coeff; ///< (1.14) gain coefficient (4.2.4)
+ uint16_t rand_value; ///< random number generator value (4.4.4)
+ int ma_predictor_prev; ///< switched MA predictor of LSP quantizer from last good frame
+
+ /// (14.14) high-pass filter data (past input)
+ int hpf_f[2];
+
+ /// high-pass filter data (past output)
+ int16_t hpf_z[2];
} G729Context;
static const G729FormatDescription format_g729_8k = {
@@ -131,6 +186,15 @@ static inline int get_parity(uint8_t value)
return (0x6996966996696996ULL >> (value >> 2)) & 1;
}
+/*
+ * Decodes LSF (Line Spectral Frequencies) from L0-L3 (3.2.4).
+ * @param lsfq [out] (2.13) quantized LSF coefficients
+ * @param past_quantizer_outputs [in/out] (2.13) quantizer outputs from previous frames
+ * @param ma_predictor switched MA predictor of LSP quantizer
+ * @param vq_1st first stage vector of quantizer
+ * @param vq_2nd_low second stage lower vector of LSP quantizer
+ * @param vq_2nd_high second stage higher vector of LSP quantizer
+ */
static void lsf_decode(int16_t* lsfq, int16_t* past_quantizer_outputs[MA_NP + 1],
int16_t ma_predictor,
int16_t vq_1st, int16_t vq_2nd_low, int16_t vq_2nd_high)
@@ -162,13 +226,122 @@ static void lsf_decode(int16_t* lsfq, int16_t* past_quantizer_outputs[MA_NP + 1]
lsfq[i] = sum >> 15;
}
- /* Rotate past_quantizer_outputs. */
- memmove(past_quantizer_outputs + 1, past_quantizer_outputs, MA_NP * sizeof(int16_t*));
- past_quantizer_outputs[0] = quantizer_output;
-
ff_acelp_reorder_lsf(lsfq, LSFQ_DIFF_MIN, LSFQ_MIN, LSFQ_MAX, 10);
}
+/**
+ * Restores past LSP quantizer output using LSF from previous frame
+ * @param lsfq [in/out] (2.13) quantized LSF coefficients
+ * @param past_quantizer_outputs [in/out] (2.13) quantizer outputs from previous frames
+ * @param ma_predictor_prev MA predictor from previous frame
+ * @param lsfq_prev (2.13) quantized LSF coefficients from previous frame
+ */
+static void lsf_restore_from_previous(int16_t* lsfq,
+ int16_t* past_quantizer_outputs[MA_NP + 1],
+ int ma_predictor_prev)
+{
+ int16_t* quantizer_output = past_quantizer_outputs[MA_NP];
+ int i,k;
+
+ for (i = 0; i < 10; i++) {
+ int tmp = lsfq[i] << 15;
+
+ for (k = 0; k < MA_NP; k++)
+ tmp -= past_quantizer_outputs[k][i] * cb_ma_predictor[ma_predictor_prev][k][i];
+
+ quantizer_output[i] = ((tmp >> 15) * cb_ma_predictor_sum_inv[ma_predictor_prev][i]) >> 12;
+ }
+}
+
+/**
+ * Constructs new excitation signal and applies phase filter to it
+ * @param out[out] constructed speech signal
+ * @param in original excitation signal
+ * @param fc_cur (2.13) original fixed-codebook vector
+ * @param gain_code (14.1) gain code
+ * @param subframe_size length of the subframe
+ */
+static void g729d_get_new_exc(
+ int16_t* out,
+ const int16_t* in,
+ const int16_t* fc_cur,
+ int dstate,
+ int gain_code,
+ int subframe_size)
+{
+ int i;
+ int16_t fc_new[SUBFRAME_SIZE];
+
+ ff_celp_convolve_circ(fc_new, fc_cur, phase_filter[dstate], subframe_size);
+
+ for(i=0; i<subframe_size; i++)
+ {
+ out[i] = in[i];
+ out[i] -= (gain_code * fc_cur[i] + 0x2000) >> 14;
+ out[i] += (gain_code * fc_new[i] + 0x2000) >> 14;
+ }
+}
+
+/**
+ * Makes decision about onset in current subframe
+ * @param past_onset decision result of previous subframe
+ * @param past_gain_code gain code of current and previous subframe
+ *
+ * @return onset decision result for current subframe
+ */
+static int g729d_onset_decision(int past_onset, const int16_t* past_gain_code)
+{
+ if((past_gain_code[0] >> 1) > past_gain_code[1])
+ return 2;
+ else
+ return FFMAX(past_onset-1, 0);
+}
+
+/**
+ * Makes decision about voice presence in current subframe
+ * @param onset onset level
+ * @param prev_voice_decision voice decision result from previous subframe
+ * @param past_gain_pitch pitch gain of current and previous subframes
+ *
+ * @return voice decision result for current subframe
+ */
+static int16_t g729d_voice_decision(int onset, int prev_voice_decision, const int16_t* past_gain_pitch)
+{
+ int i, low_gain_pitch_cnt, voice_decision;
+
+ if(past_gain_pitch[0] >= 14745) // 0.9
+ voice_decision = DECISION_VOICE;
+ else if (past_gain_pitch[0] <= 9830) // 0.6
+ voice_decision = DECISION_NOISE;
+ else
+ voice_decision = DECISION_INTERMEDIATE;
+
+ for(i=0, low_gain_pitch_cnt=0; i<6; i++)
+ if(past_gain_pitch[i] < 9830)
+ low_gain_pitch_cnt++;
+
+ if(low_gain_pitch_cnt > 2 && !onset)
+ voice_decision = DECISION_NOISE;
+
+ if(!onset && voice_decision > prev_voice_decision + 1)
+ voice_decision--;
+
+ if(onset && voice_decision < DECISION_VOICE)
+ voice_decision++;
+
+ return voice_decision;
+}
+
+static int32_t scalarproduct_int16_c(const int16_t * v1, const int16_t * v2, int order, int shift)
+{
+ int res = 0;
+
+ while (order--)
+ res += (*v1++ * *v2++) >> shift;
+
+ return res;
+}
+
static av_cold int decoder_init(AVCodecContext * avctx)
{
G729Context* ctx = avctx->priv_data;
@@ -178,10 +351,13 @@ static av_cold int decoder_init(AVCodecContext * avctx)
av_log(avctx, AV_LOG_ERROR, "Only mono sound is supported (requested channels: %d).\n", avctx->channels);
return AVERROR(EINVAL);
}
+ avctx->sample_fmt = AV_SAMPLE_FMT_S16;
/* Both 8kbit/s and 6.4kbit/s modes uses two subframes per frame. */
avctx->frame_size = SUBFRAME_SIZE << 1;
+ ctx->gain_coeff = 16384; // 1.0 in (1.14)
+
for (k = 0; k < MA_NP + 1; k++) {
ctx->past_quantizer_outputs[k] = ctx->past_quantizer_output_buf[k];
for (i = 1; i < 11; i++)
@@ -192,6 +368,18 @@ static av_cold int decoder_init(AVCodecContext * avctx)
ctx->lsp[1] = ctx->lsp_buf[1];
memcpy(ctx->lsp[0], lsp_init, 10 * sizeof(int16_t));
+ ctx->exc = &ctx->exc_base[PITCH_DELAY_MAX+INTERPOL_LEN];
+
+ /* random seed initialization */
+ ctx->rand_value = 21845;
+
+ /* quantized prediction error */
+ for(i=0; i<4; i++)
+ ctx->quant_energy[i] = -14336; // -14 in (5.10)
+
+ dsputil_init(&ctx->dsp, avctx);
+ ctx->dsp.scalarproduct_int16 = scalarproduct_int16_c;
+
return 0;
}
@@ -202,10 +390,12 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
int buf_size = avpkt->size;
int16_t *out_frame = data;
GetBitContext gb;
- G729FormatDescription format;
+ const G729FormatDescription *format;
int frame_erasure = 0; ///< frame erasure detected during decoding
int bad_pitch = 0; ///< parity check failed
int i;
+ int16_t *tmp;
+ G729Formats packet_type;
G729Context *ctx = avctx->priv_data;
int16_t lp[2][11]; // (3.12)
uint8_t ma_predictor; ///< switched MA predictor of LSP quantizer
@@ -213,8 +403,13 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
uint8_t quantizer_2nd_lo; ///< second stage lower vector of quantizer (size in bits)
uint8_t quantizer_2nd_hi; ///< second stage higher vector of quantizer (size in bits)
- int pitch_delay_int; // pitch delay, integer part
+ int pitch_delay_int[2]; // pitch delay, integer part
int pitch_delay_3x; // pitch delay, multiplied by 3
+ int16_t fc[SUBFRAME_SIZE]; // fixed-codebook vector
+ int16_t synth[SUBFRAME_SIZE+10]; // fixed-codebook vector
+ int j;
+ int gain_before, gain_after;
+ int is_periodic = 0; // whether one of the subframes is declared as periodic or not
if (*data_size < SUBFRAME_SIZE << 2) {
av_log(avctx, AV_LOG_ERROR, "Error processing packet: output buffer too small\n");
@@ -222,10 +417,15 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
}
if (buf_size == 10) {
- format = format_g729_8k;
+ packet_type = FORMAT_G729_8K;
+ format = &format_g729_8k;
+ //Reset voice decision
+ ctx->onset = 0;
+ ctx->voice_decision = DECISION_VOICE;
av_log(avctx, AV_LOG_DEBUG, "Packet type: %s\n", "G.729 @ 8kbit/s");
} else if (buf_size == 8) {
- format = format_g729d_6k4;
+ packet_type = FORMAT_G729D_6K4;
+ format = &format_g729d_6k4;
av_log(avctx, AV_LOG_DEBUG, "Packet type: %s\n", "G.729D @ 6.4kbit/s");
} else {
av_log(avctx, AV_LOG_ERROR, "Packet size %d is unknown.\n", buf_size);
@@ -236,16 +436,27 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
frame_erasure |= buf[i];
frame_erasure = !frame_erasure;
- init_get_bits(&gb, buf, buf_size);
+ init_get_bits(&gb, buf, 8*buf_size);
ma_predictor = get_bits(&gb, 1);
quantizer_1st = get_bits(&gb, VQ_1ST_BITS);
quantizer_2nd_lo = get_bits(&gb, VQ_2ND_BITS);
quantizer_2nd_hi = get_bits(&gb, VQ_2ND_BITS);
- lsf_decode(ctx->lsfq, ctx->past_quantizer_outputs,
- ma_predictor,
- quantizer_1st, quantizer_2nd_lo, quantizer_2nd_hi);
+ if(frame_erasure)
+ lsf_restore_from_previous(ctx->lsfq, ctx->past_quantizer_outputs,
+ ctx->ma_predictor_prev);
+ else {
+ lsf_decode(ctx->lsfq, ctx->past_quantizer_outputs,
+ ma_predictor,
+ quantizer_1st, quantizer_2nd_lo, quantizer_2nd_hi);
+ ctx->ma_predictor_prev = ma_predictor;
+ }
+
+ tmp = ctx->past_quantizer_outputs[MA_NP];
+ memmove(ctx->past_quantizer_outputs + 1, ctx->past_quantizer_outputs,
+ MA_NP * sizeof(int16_t*));
+ ctx->past_quantizer_outputs[0] = tmp;
ff_acelp_lsf2lsp(ctx->lsp[1], ctx->lsfq, 10);
@@ -254,21 +465,25 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
FFSWAP(int16_t*, ctx->lsp[1], ctx->lsp[0]);
for (i = 0; i < 2; i++) {
+ int gain_corr_factor;
+
uint8_t ac_index; ///< adaptive codebook index
uint8_t pulses_signs; ///< fixed-codebook vector pulse signs
int fc_indexes; ///< fixed-codebook indexes
uint8_t gc_1st_index; ///< gain codebook (first stage) index
uint8_t gc_2nd_index; ///< gain codebook (second stage) index
- ac_index = get_bits(&gb, format.ac_index_bits[i]);
- if(!i && format.parity_bit)
+ ac_index = get_bits(&gb, format->ac_index_bits[i]);
+ if(!i && format->parity_bit)
bad_pitch = get_parity(ac_index) == get_bits1(&gb);
- fc_indexes = get_bits(&gb, format.fc_indexes_bits);
- pulses_signs = get_bits(&gb, format.fc_signs_bits);
- gc_1st_index = get_bits(&gb, format.gc_1st_index_bits);
- gc_2nd_index = get_bits(&gb, format.gc_2nd_index_bits);
-
- if(!i) {
+ fc_indexes = get_bits(&gb, format->fc_indexes_bits);
+ pulses_signs = get_bits(&gb, format->fc_signs_bits);
+ gc_1st_index = get_bits(&gb, format->gc_1st_index_bits);
+ gc_2nd_index = get_bits(&gb, format->gc_2nd_index_bits);
+
+ if (frame_erasure)
+ pitch_delay_3x = 3 * ctx->pitch_delay_int_prev;
+ else if(!i) {
if (bad_pitch)
pitch_delay_3x = 3 * ctx->pitch_delay_int_prev;
else
@@ -284,35 +499,208 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
}
/* Round pitch delay to nearest (used everywhere except ff_acelp_interpolate). */
- pitch_delay_int = (pitch_delay_3x + 1) / 3;
+ pitch_delay_int[i] = (pitch_delay_3x + 1) / 3;
+
+ if (frame_erasure) {
+ ctx->rand_value = g729_prng(ctx->rand_value);
+ fc_indexes = ctx->rand_value & ((1 << format->fc_indexes_bits) - 1);
+
+ ctx->rand_value = g729_prng(ctx->rand_value);
+ pulses_signs = ctx->rand_value;
+ }
+
+
+ memset(fc, 0, sizeof(int16_t) * SUBFRAME_SIZE);
+ switch (packet_type) {
+ case FORMAT_G729_8K:
+ ff_acelp_fc_pulse_per_track(fc, ff_fc_4pulses_8bits_tracks_13,
+ ff_fc_4pulses_8bits_track_4,
+ fc_indexes, pulses_signs, 3, 3);
+ break;
+ case FORMAT_G729D_6K4:
+ ff_acelp_fc_pulse_per_track(fc, ff_fc_2pulses_9bits_track1_gray,
+ ff_fc_2pulses_9bits_track2_gray,
+ fc_indexes, pulses_signs, 1, 4);
+ break;
+ }
- ff_acelp_weighted_vector_sum(fc + pitch_delay_int,
- fc + pitch_delay_int,
+ /*
+ This filter enhances harmonic components of the fixed-codebook vector to
+ improve the quality of the reconstructed speech.
+
+ / fc_v[i], i < pitch_delay
+ fc_v[i] = <
+ \ fc_v[i] + gain_pitch * fc_v[i-pitch_delay], i >= pitch_delay
+ */
+ ff_acelp_weighted_vector_sum(fc + pitch_delay_int[i],
+ fc + pitch_delay_int[i],
fc, 1 << 14,
- av_clip(ctx->gain_pitch, SHARP_MIN, SHARP_MAX),
+ av_clip(ctx->past_gain_pitch[0], SHARP_MIN, SHARP_MAX),
0, 14,
- SUBFRAME_SIZE - pitch_delay_int);
+ SUBFRAME_SIZE - pitch_delay_int[i]);
+
+ memmove(ctx->past_gain_pitch+1, ctx->past_gain_pitch, 5 * sizeof(int16_t));
+ ctx->past_gain_code[1] = ctx->past_gain_code[0];
if (frame_erasure) {
- ctx->gain_pitch = (29491 * ctx->gain_pitch) >> 15; // 0.90 (0.15)
- ctx->gain_code = ( 2007 * ctx->gain_code ) >> 11; // 0.98 (0.11)
+ ctx->past_gain_pitch[0] = (29491 * ctx->past_gain_pitch[0]) >> 15; // 0.90 (0.15)
+ ctx->past_gain_code[0] = ( 2007 * ctx->past_gain_code[0] ) >> 11; // 0.98 (0.11)
gain_corr_factor = 0;
} else {
- ctx->gain_pitch = cb_gain_1st_8k[gc_1st_index][0] +
- cb_gain_2nd_8k[gc_2nd_index][0];
- gain_corr_factor = cb_gain_1st_8k[gc_1st_index][1] +
- cb_gain_2nd_8k[gc_2nd_index][1];
+ if (packet_type == FORMAT_G729D_6K4) {
+ ctx->past_gain_pitch[0] = cb_gain_1st_6k4[gc_1st_index][0] +
+ cb_gain_2nd_6k4[gc_2nd_index][0];
+ gain_corr_factor = cb_gain_1st_6k4[gc_1st_index][1] +
+ cb_gain_2nd_6k4[gc_2nd_index][1];
+
+ /* Without check below overflow can occure in ff_acelp_update_past_gain.
+ It is not issue for G.729, because gain_corr_factor in it's case is always
+ greater than 1024, while in G.729D it can be even zero. */
+ gain_corr_factor = FFMAX(gain_corr_factor, 1024);
+#ifndef G729_BITEXACT
+ gain_corr_factor >>= 1;
+#endif
+ } else {
+ ctx->past_gain_pitch[0] = cb_gain_1st_8k[gc_1st_index][0] +
+ cb_gain_2nd_8k[gc_2nd_index][0];
+ gain_corr_factor = cb_gain_1st_8k[gc_1st_index][1] +
+ cb_gain_2nd_8k[gc_2nd_index][1];
+ }
+
+ /* Decode the fixed-codebook gain. */
+ ctx->past_gain_code[0] = ff_acelp_decode_gain_code(&ctx->dsp, gain_corr_factor,
+ fc, MR_ENERGY,
+ ctx->quant_energy,
+ ma_prediction_coeff,
+ SUBFRAME_SIZE, 4);
+#ifdef G729_BITEXACT
+ /*
+ This correction required to get bit-exact result with
+ reference code, because gain_corr_factor in G.729D is
+ two times larger than in original G.729.
+
+ If bit-exact result is not issue then gain_corr_factor
+ can be simpler devided by 2 before call to g729_get_gain_code
+ instead of using correction below.
+ */
+ if (packet_type == FORMAT_G729D_6K4) {
+ gain_corr_factor >>= 1;
+ ctx->past_gain_code[0] >>= 1;
+ }
+#endif
+ }
+ ff_acelp_update_past_gain(ctx->quant_energy, gain_corr_factor, 2, frame_erasure);
+
+ /* Routine requires rounding to lowest. */
+ ff_acelp_interpolate(ctx->exc + i * SUBFRAME_SIZE,
+ ctx->exc + i * SUBFRAME_SIZE - pitch_delay_3x / 3,
+ ff_acelp_interp_filter, 6,
+ (pitch_delay_3x % 3) << 1,
+ 10, SUBFRAME_SIZE);
ff_acelp_weighted_vector_sum(ctx->exc + i * SUBFRAME_SIZE,
ctx->exc + i * SUBFRAME_SIZE, fc,
- (!voicing && frame_erasure) ? 0 : ctx->gain_pitch,
- ( voicing && frame_erasure) ? 0 : ctx->gain_code,
+ (!ctx->was_periodic && frame_erasure) ? 0 : ctx->past_gain_pitch[0],
+ ( ctx->was_periodic && frame_erasure) ? 0 : ctx->past_gain_code[0],
1 << 13, 14, SUBFRAME_SIZE);
- ctx->pitch_delay_int_prev = pitch_delay_int;
+ memcpy(synth, ctx->syn_filter_data, 10 * sizeof(int16_t));
+
+ if (ff_celp_lp_synthesis_filter(
+ synth+10,
+ &lp[i][1],
+ ctx->exc + i * SUBFRAME_SIZE,
+ SUBFRAME_SIZE,
+ 10,
+ 1,
+ 0,
+ 0x800))
+ /* Overflow occured, downscale excitation signal... */
+ for (j = 0; j < 2 * SUBFRAME_SIZE + PITCH_DELAY_MAX + INTERPOL_LEN; j++)
+ ctx->exc_base[j] >>= 2;
+
+ /* ... and make synthesis again. */
+ if (packet_type == FORMAT_G729D_6K4) {
+ int16_t exc_new[SUBFRAME_SIZE];
+
+ ctx->onset = g729d_onset_decision(ctx->onset, ctx->past_gain_code);
+ ctx->voice_decision = g729d_voice_decision(ctx->onset, ctx->voice_decision, ctx->past_gain_pitch);
+
+ g729d_get_new_exc(exc_new, ctx->exc + i * SUBFRAME_SIZE, fc, ctx->voice_decision, ctx->past_gain_code[0], SUBFRAME_SIZE);
+
+ ff_celp_lp_synthesis_filter(
+ synth+10,
+ &lp[i][1],
+ exc_new,
+ SUBFRAME_SIZE,
+ 10,
+ 0,
+ 0,
+ 0x800);
+ } else {
+ ff_celp_lp_synthesis_filter(
+ synth+10,
+ &lp[i][1],
+ ctx->exc + i * SUBFRAME_SIZE,
+ SUBFRAME_SIZE,
+ 10,
+ 0,
+ 0,
+ 0x800);
+ }
+ /* Save data (without postfilter) for use in next subframe. */
+ memcpy(ctx->syn_filter_data, synth+SUBFRAME_SIZE, 10 * sizeof(int16_t));
+
+ /* Calculate gain of unfiltered signal for use in AGC. */
+ gain_before = 0;
+ for (j = 0; j < SUBFRAME_SIZE; j++)
+ gain_before += FFABS(synth[j+10]);
+
+ /* Call postfilter and also update voicing decision for use in next frame. */
+ ff_g729_postfilter(
+ &ctx->dsp,
+ &ctx->ht_prev_data,
+ &is_periodic,
+ &lp[i][0],
+ pitch_delay_int[0],
+ ctx->residual,
+ ctx->res_filter_data,
+ ctx->pos_filter_data,
+ synth+10,
+ SUBFRAME_SIZE);
+
+ /* Calculate gain of filtered signal for use in AGC. */
+ gain_after = 0;
+ for(j=0; j<SUBFRAME_SIZE; j++)
+ gain_after += FFABS(synth[j+10]);
+
+ ctx->gain_coeff = ff_g729_adaptive_gain_control(
+ gain_before,
+ gain_after,
+ synth+10,
+ SUBFRAME_SIZE,
+ ctx->gain_coeff);
+
+ if (frame_erasure)
+ ctx->pitch_delay_int_prev = FFMIN(ctx->pitch_delay_int_prev + 1, PITCH_DELAY_MAX);
+ else
+ ctx->pitch_delay_int_prev = pitch_delay_int[i];
+
+ memcpy(synth+8, ctx->hpf_z, 2*sizeof(int16_t));
+ ff_acelp_high_pass_filter(
+ out_frame + i*SUBFRAME_SIZE,
+ ctx->hpf_f,
+ synth+10,
+ SUBFRAME_SIZE);
+ memcpy(ctx->hpf_z, synth+8+SUBFRAME_SIZE, 2*sizeof(int16_t));
}
+ ctx->was_periodic = is_periodic;
+
+ /* Save signal for use in next frame. */
+ memmove(ctx->exc_base, ctx->exc_base + 2 * SUBFRAME_SIZE, (PITCH_DELAY_MAX+INTERPOL_LEN)*sizeof(int16_t));
+
*data_size = SUBFRAME_SIZE << 2;
return buf_size;
}
diff --git a/libavcodec/g729postfilter.c b/libavcodec/g729postfilter.c
new file mode 100644
index 0000000000..87472f694c
--- /dev/null
+++ b/libavcodec/g729postfilter.c
@@ -0,0 +1,610 @@
+/*
+ * G.729, G729 Annex D postfilter
+ * Copyright (c) 2008 Vladimir Voroshilov
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#include <inttypes.h>
+#include <limits.h>
+
+#include "avcodec.h"
+#include "g729.h"
+#include "acelp_pitch_delay.h"
+#include "g729postfilter.h"
+#include "celp_math.h"
+#include "acelp_filters.h"
+#include "acelp_vectors.h"
+#include "celp_filters.h"
+
+#define FRAC_BITS 15
+#include "mathops.h"
+
+/**
+ * short interpolation filter (of length 33, according to spec)
+ * for computing signal with non-integer delay
+ */
+static const int16_t ff_g729_interp_filt_short[(ANALYZED_FRAC_DELAYS+1)*SHORT_INT_FILT_LEN] = {
+ 0, 31650, 28469, 23705, 18050, 12266, 7041, 2873,
+ 0, -1597, -2147, -1992, -1492, -933, -484, -188,
+};
+
+/**
+ * long interpolation filter (of length 129, according to spec)
+ * for computing signal with non-integer delay
+ */
+static const int16_t ff_g729_interp_filt_long[(ANALYZED_FRAC_DELAYS+1)*LONG_INT_FILT_LEN] = {
+ 0, 31915, 29436, 25569, 20676, 15206, 9639, 4439,
+ 0, -3390, -5579, -6549, -6414, -5392, -3773, -1874,
+ 0, 1595, 2727, 3303, 3319, 2850, 2030, 1023,
+ 0, -887, -1527, -1860, -1876, -1614, -1150, -579,
+ 0, 501, 859, 1041, 1044, 892, 631, 315,
+ 0, -266, -453, -543, -538, -455, -317, -156,
+ 0, 130, 218, 258, 253, 212, 147, 72,
+ 0, -59, -101, -122, -123, -106, -77, -40,
+};
+
+/**
+ * formant_pp_factor_num_pow[i] = FORMANT_PP_FACTOR_NUM^(i+1)
+ */
+static const int16_t formant_pp_factor_num_pow[10]= {
+ /* (0.15) */
+ 18022, 9912, 5451, 2998, 1649, 907, 499, 274, 151, 83
+};
+
+/**
+ * formant_pp_factor_den_pow[i] = FORMANT_PP_FACTOR_DEN^(i+1)
+ */
+static const int16_t formant_pp_factor_den_pow[10] = {
+ /* (0.15) */
+ 22938, 16057, 11240, 7868, 5508, 3856, 2699, 1889, 1322, 925
+};
+
+/**
+ * \brief Residual signal calculation (4.2.1 if G.729)
+ * \param out [out] output data filtered through A(z/FORMANT_PP_FACTOR_NUM)
+ * \param filter_coeffs (3.12) A(z/FORMANT_PP_FACTOR_NUM) filter coefficients
+ * \param in input speech data to process
+ * \param subframe_size size of one subframe
+ *
+ * \note in buffer must contain 10 items of previous speech data before top of the buffer
+ * \remark It is safe to pass the same buffer for input and output.
+ */
+static void residual_filter(int16_t* out, const int16_t* filter_coeffs, const int16_t* in,
+ int subframe_size)
+{
+ int i, n;
+
+ for (n = subframe_size - 1; n >= 0; n--) {
+ int sum = 0x800;
+ for (i = 0; i < 10; i++)
+ sum += filter_coeffs[i] * in[n - i - 1];
+
+ out[n] = in[n] + (sum >> 12);
+ }
+}
+
+/**
+ * \brief long-term postfilter (4.2.1)
+ * \param dsp initialized DSP context
+ * \param pitch_delay_int integer part of the pitch delay in the first subframe
+ * \param residual filtering input data
+ * \param residual_filt [out] speech signal with applied A(z/FORMANT_PP_FACTOR_NUM) filter
+ * \param subframe_size size of subframe
+ *
+ * \return 0 if long-term prediction gain is less than 3dB, 1 - otherwise
+ */
+static int16_t long_term_filter(DSPContext *dsp, int pitch_delay_int,
+ const int16_t* residual, int16_t *residual_filt,
+ int subframe_size)
+{
+ int i, k, tmp, tmp2;
+ int sum;
+ int L_temp0;
+ int L_temp1;
+ int64_t L64_temp0;
+ int64_t L64_temp1;
+ int16_t shift;
+ int corr_int_num, corr_int_den;
+
+ int ener;
+ int16_t sh_ener;
+
+ int16_t gain_num,gain_den; //selected signal's gain numerator and denominator
+ int16_t sh_gain_num, sh_gain_den;
+ int gain_num_square;
+
+ int16_t gain_long_num,gain_long_den; //filtered through long interpolation filter signal's gain numerator and denominator
+ int16_t sh_gain_long_num, sh_gain_long_den;
+
+ int16_t best_delay_int, best_delay_frac;
+
+ int16_t delayed_signal_offset;
+ int lt_filt_factor_a, lt_filt_factor_b;
+
+ int16_t * selected_signal;
+ const int16_t * selected_signal_const; //Necessary to avoid compiler warning
+
+ int16_t sig_scaled[SUBFRAME_SIZE + RES_PREV_DATA_SIZE];
+ int16_t delayed_signal[ANALYZED_FRAC_DELAYS][SUBFRAME_SIZE+1];
+ int corr_den[ANALYZED_FRAC_DELAYS][2];
+
+ tmp = 0;
+ for(i=0; i<subframe_size + RES_PREV_DATA_SIZE; i++)
+ tmp |= FFABS(residual[i]);
+
+ if(!tmp)
+ shift = 3;
+ else
+ shift = av_log2(tmp) - 11;
+
+ if (shift > 0)
+ for (i = 0; i < subframe_size + RES_PREV_DATA_SIZE; i++)
+ sig_scaled[i] = residual[i] >> shift;
+ else
+ for (i = 0; i < subframe_size + RES_PREV_DATA_SIZE; i++)
+ sig_scaled[i] = residual[i] << -shift;
+
+ /* Start of best delay searching code */
+ gain_num = 0;
+
+ ener = dsp->scalarproduct_int16(sig_scaled + RES_PREV_DATA_SIZE,
+ sig_scaled + RES_PREV_DATA_SIZE,
+ subframe_size, 0);
+ if (ener) {
+ sh_ener = FFMAX(av_log2(ener) - 14, 0);
+ ener >>= sh_ener;
+ /* Search for best pitch delay.
+
+ sum{ r(n) * r(k,n) ] }^2
+ R'(k)^2 := -------------------------
+ sum{ r(k,n) * r(k,n) }
+
+
+ R(T) := sum{ r(n) * r(n-T) ] }
+
+
+ where
+ r(n-T) is integer delayed signal with delay T
+ r(k,n) is non-integer delayed signal with integer delay best_delay
+ and fractional delay k */
+
+ /* Find integer delay best_delay which maximizes correlation R(T).
+
+ This is also equals to numerator of R'(0),
+ since the fine search (second step) is done with 1/8
+ precision around best_delay. */
+ corr_int_num = 0;
+ best_delay_int = pitch_delay_int - 1;
+ for (i = pitch_delay_int - 1; i <= pitch_delay_int + 1; i++) {
+ sum = dsp->scalarproduct_int16(sig_scaled + RES_PREV_DATA_SIZE,
+ sig_scaled + RES_PREV_DATA_SIZE - i,
+ subframe_size, 0);
+ if (sum > corr_int_num) {
+ corr_int_num = sum;
+ best_delay_int = i;
+ }
+ }
+ if (corr_int_num) {
+ /* Compute denominator of pseudo-normalized correlation R'(0). */
+ corr_int_den = dsp->scalarproduct_int16(sig_scaled - best_delay_int + RES_PREV_DATA_SIZE,
+ sig_scaled - best_delay_int + RES_PREV_DATA_SIZE,
+ subframe_size, 0);
+
+ /* Compute signals with non-integer delay k (with 1/8 precision),
+ where k is in [0;6] range.
+ Entire delay is qual to best_delay+(k+1)/8
+ This is archieved by applying an interpolation filter of
+ legth 33 to source signal. */
+ for (k = 0; k < ANALYZED_FRAC_DELAYS; k++) {
+ ff_acelp_interpolate(&delayed_signal[k][0],
+ &sig_scaled[RES_PREV_DATA_SIZE - best_delay_int],
+ ff_g729_interp_filt_short,
+ ANALYZED_FRAC_DELAYS+1,
+ 8 - k - 1,
+ SHORT_INT_FILT_LEN,
+ subframe_size + 1);
+ }
+
+ /* Compute denominator of pseudo-normalized correlation R'(k).
+
+ corr_den[k][0] is square root of R'(k) denominator, for int(T) == int(T0)
+ corr_den[k][1] is square root of R'(k) denominator, for int(T) == int(T0)+1
+
+ Also compute maximum value of above denominators over all k. */
+ tmp = corr_int_den;
+ for (k = 0; k < ANALYZED_FRAC_DELAYS; k++) {
+ sum = dsp->scalarproduct_int16(&delayed_signal[k][1],
+ &delayed_signal[k][1],
+ subframe_size - 1, 0);
+ corr_den[k][0] = sum + delayed_signal[k][0 ] * delayed_signal[k][0 ];
+ corr_den[k][1] = sum + delayed_signal[k][subframe_size] * delayed_signal[k][subframe_size];
+
+ tmp = FFMAX3(tmp, corr_den[k][0], corr_den[k][1]);
+ }
+
+ sh_gain_den = av_log2(tmp) - 14;
+ if (sh_gain_den >= 0) {
+
+ sh_gain_num = FFMAX(sh_gain_den, sh_ener);
+ /* Loop through all k and find delay that maximizes
+ R'(k) correlation.
+ Search is done in [int(T0)-1; intT(0)+1] range
+ with 1/8 precision. */
+ delayed_signal_offset = 1;
+ best_delay_frac = 0;
+ gain_den = corr_int_den >> sh_gain_den;
+ gain_num = corr_int_num >> sh_gain_num;
+ gain_num_square = gain_num * gain_num;
+ for (k = 0; k < ANALYZED_FRAC_DELAYS; k++) {
+ for (i = 0; i < 2; i++) {
+ int16_t gain_num_short, gain_den_short;
+ int gain_num_short_square;
+ /* Compute numerator of pseudo-normalized
+ correlation R'(k). */
+ sum = dsp->scalarproduct_int16(&delayed_signal[k][i],
+ sig_scaled + RES_PREV_DATA_SIZE,
+ subframe_size, 0);
+ gain_num_short = FFMAX(sum >> sh_gain_num, 0);
+
+ /*
+ gain_num_short_square gain_num_square
+ R'(T)^2 = -----------------------, max R'(T)^2= --------------
+ den gain_den
+ */
+ gain_num_short_square = gain_num_short * gain_num_short;
+ gain_den_short = corr_den[k][i] >> sh_gain_den;
+
+ tmp = MULL(gain_num_short_square, gain_den, FRAC_BITS);
+ tmp2 = MULL(gain_num_square, gain_den_short, FRAC_BITS);
+
+ // R'(T)^2 > max R'(T)^2
+ if (tmp > tmp2) {
+ gain_num = gain_num_short;
+ gain_den = gain_den_short;
+ gain_num_square = gain_num_short_square;
+ delayed_signal_offset = i;
+ best_delay_frac = k + 1;
+ }
+ }
+ }
+
+ /*
+ R'(T)^2
+ 2 * --------- < 1
+ R(0)
+ */
+ L64_temp0 = (int64_t)gain_num_square << ((sh_gain_num << 1) + 1);
+ L64_temp1 = ((int64_t)gain_den * ener) << (sh_gain_den + sh_ener);
+ if (L64_temp0 < L64_temp1)
+ gain_num = 0;
+ } // if(sh_gain_den >= 0)
+ } // if(corr_int_num)
+ } // if(ener)
+ /* End of best delay searching code */
+
+ if (!gain_num) {
+ memcpy(residual_filt, residual + RES_PREV_DATA_SIZE, subframe_size * sizeof(int16_t));
+
+ /* Long-term prediction gain is less than 3dB. Long-term postfilter is disabled. */
+ return 0;
+ }
+ if (best_delay_frac) {
+ /* Recompute delayed signal with an interpolation filter of length 129. */
+ ff_acelp_interpolate(residual_filt,
+ &sig_scaled[RES_PREV_DATA_SIZE - best_delay_int + delayed_signal_offset],
+ ff_g729_interp_filt_long,
+ ANALYZED_FRAC_DELAYS + 1,
+ 8 - best_delay_frac,
+ LONG_INT_FILT_LEN,
+ subframe_size + 1);
+ /* Compute R'(k) correlation's numerator. */
+ sum = dsp->scalarproduct_int16(residual_filt,
+ sig_scaled + RES_PREV_DATA_SIZE,
+ subframe_size, 0);
+
+ if (sum < 0) {
+ gain_long_num = 0;
+ sh_gain_long_num = 0;
+ } else {
+ tmp = FFMAX(av_log2(sum) - 14, 0);
+ sum >>= tmp;
+ gain_long_num = sum;
+ sh_gain_long_num = tmp;
+ }
+
+ /* Compute R'(k) correlation's denominator. */
+ sum = dsp->scalarproduct_int16(residual_filt, residual_filt, subframe_size, 0);
+
+ tmp = FFMAX(av_log2(sum) - 14, 0);
+ sum >>= tmp;
+ gain_long_den = sum;
+ sh_gain_long_den = tmp;
+
+ /* Select between original and delayed signal.
+ Delayed signal will be selected if it increases R'(k)
+ correlation. */
+ L_temp0 = gain_num * gain_num;
+ L_temp0 = MULL(L_temp0, gain_long_den, FRAC_BITS);
+
+ L_temp1 = gain_long_num * gain_long_num;
+ L_temp1 = MULL(L_temp1, gain_den, FRAC_BITS);
+
+ tmp = ((sh_gain_long_num - sh_gain_num) << 1) - (sh_gain_long_den - sh_gain_den);
+ if (tmp > 0)
+ L_temp0 >>= tmp;
+ else
+ L_temp1 >>= -tmp;
+
+ /* Check if longer filter increases the values of R'(k). */
+ if (L_temp1 > L_temp0) {
+ /* Select long filter. */
+ selected_signal = residual_filt;
+ gain_num = gain_long_num;
+ gain_den = gain_long_den;
+ sh_gain_num = sh_gain_long_num;
+ sh_gain_den = sh_gain_long_den;
+ } else
+ /* Select short filter. */
+ selected_signal = &delayed_signal[best_delay_frac-1][delayed_signal_offset];
+
+ /* Rescale selected signal to original value. */
+ if (shift > 0)
+ for (i = 0; i < subframe_size; i++)
+ selected_signal[i] <<= shift;
+ else
+ for (i = 0; i < subframe_size; i++)
+ selected_signal[i] >>= -shift;
+
+ /* necessary to avoid compiler warning */
+ selected_signal_const = selected_signal;
+ } // if(best_delay_frac)
+ else
+ selected_signal_const = residual + RES_PREV_DATA_SIZE - (best_delay_int + 1 - delayed_signal_offset);
+#ifdef G729_BITEXACT
+ tmp = sh_gain_num - sh_gain_den;
+ if (tmp > 0)
+ gain_den >>= tmp;
+ else
+ gain_num >>= -tmp;
+
+ if (gain_num > gain_den)
+ lt_filt_factor_a = MIN_LT_FILT_FACTOR_A;
+ else {
+ gain_num >>= 2;
+ gain_den >>= 1;
+ lt_filt_factor_a = (gain_den << 15) / (gain_den + gain_num);
+ }
+#else
+ L64_temp0 = ((int64_t)gain_num) << (sh_gain_num - 1);
+ L64_temp1 = ((int64_t)gain_den) << sh_gain_den;
+ lt_filt_factor_a = FFMAX((L64_temp1 << 15) / (L64_temp1 + L64_temp0), MIN_LT_FILT_FACTOR_A);
+#endif
+
+ /* Filter through selected filter. */
+ lt_filt_factor_b = 32767 - lt_filt_factor_a + 1;
+
+ ff_acelp_weighted_vector_sum(residual_filt, residual + RES_PREV_DATA_SIZE,
+ selected_signal_const,
+ lt_filt_factor_a, lt_filt_factor_b,
+ 1<<14, 15, subframe_size);
+
+ // Long-term prediction gain is larger than 3dB.
+ return 1;
+}
+
+/**
+ * \brief Calculate reflection coefficient for tilt compensation filter (4.2.3).
+ * \param dsp initialized DSP context
+ * \param lp_gn (3.12) coefficients of A(z/FORMANT_PP_FACTOR_NUM) filter
+ * \param lp_gd (3.12) coefficients of A(z/FORMANT_PP_FACTOR_DEN) filter
+ * \param speech speech to update
+ * \param subframe_size size of subframe
+ *
+ * \return (3.12) reflection coefficient
+ *
+ * \remark The routine also calculates the gain term for the short-term
+ * filter (gf) and multiplies the speech data by 1/gf.
+ *
+ * \note All members of lp_gn, except 10-19 must be equal to zero.
+ */
+static int16_t get_tilt_comp(DSPContext *dsp, int16_t *lp_gn,
+ const int16_t *lp_gd, int16_t* speech,
+ int subframe_size)
+{
+ int rh1,rh0; // (3.12)
+ int temp;
+ int i;
+ int gain_term;
+
+ lp_gn[10] = 4096; //1.0 in (3.12)
+
+ /* Apply 1/A(z/FORMANT_PP_FACTOR_DEN) filter to hf. */
+ ff_celp_lp_synthesis_filter(lp_gn + 11, lp_gd + 1, lp_gn + 11, 22, 10, 0, 0, 0x800);
+ /* Now lp_gn (starting with 10) contains impulse response
+ of A(z/FORMANT_PP_FACTOR_NUM)/A(z/FORMANT_PP_FACTOR_DEN) filter. */
+
+ rh0 = dsp->scalarproduct_int16(lp_gn + 10, lp_gn + 10, 20, 0);
+ rh1 = dsp->scalarproduct_int16(lp_gn + 10, lp_gn + 11, 20, 0);
+
+ /* downscale to avoid overflow */
+ temp = av_log2(rh0) - 14;
+ if (temp > 0) {
+ rh0 >>= temp;
+ rh1 >>= temp;
+ }
+
+ if (FFABS(rh1) > rh0 || !rh0)
+ return 0;
+
+ gain_term = 0;
+ for (i = 0; i < 20; i++)
+ gain_term += FFABS(lp_gn[i + 10]);
+ gain_term >>= 2; // (3.12) -> (5.10)
+
+ if (gain_term > 0x400) { // 1.0 in (5.10)
+ temp = 0x2000000 / gain_term; // 1.0/gain_term in (0.15)
+ for (i = 0; i < subframe_size; i++)
+ speech[i] = (speech[i] * temp + 0x4000) >> 15;
+ }
+
+ return -(rh1 << 15) / rh0;
+}
+
+/**
+ * \brief Apply tilt compensation filter (4.2.3).
+ * \param res_pst [in/out] residual signal (partially filtered)
+ * \param k1 (3.12) reflection coefficient
+ * \param subframe_size size of subframe
+ * \param ht_prev_data previous data for 4.2.3, equation 86
+ *
+ * \return new value for ht_prev_data
+*/
+static int16_t apply_tilt_comp(int16_t* out, int16_t* res_pst, int refl_coeff,
+ int subframe_size, int16_t ht_prev_data)
+{
+ int tmp, tmp2;
+ int i;
+ int gt, ga;
+ int fact, sh_fact;
+
+ if (refl_coeff > 0) {
+ gt = (refl_coeff * G729_TILT_FACTOR_PLUS + 0x4000) >> 15;
+ fact = 0x4000; // 0.5 in (0.15)
+ sh_fact = 15;
+ } else {
+ gt = (refl_coeff * G729_TILT_FACTOR_MINUS + 0x4000) >> 15;
+ fact = 0x800; // 0.5 in (3.12)
+ sh_fact = 12;
+ }
+ ga = (fact << 15) / av_clip_int16(32768 - FFABS(gt));
+ gt >>= 1;
+
+ /* Apply tilt compensation filter to signal. */
+ tmp = res_pst[subframe_size - 1];
+
+ for (i = subframe_size - 1; i >= 1; i--) {
+ tmp2 = (res_pst[i] << 15) + ((gt * res_pst[i-1]) << 1);
+ tmp2 = (tmp2 + 0x4000) >> 15;
+
+ tmp2 = (tmp2 * ga * 2 + fact) >> sh_fact;
+ out[i] = tmp2;
+ }
+ tmp2 = (res_pst[0] << 15) + ((gt * ht_prev_data) << 1);
+ tmp2 = (tmp2 + 0x4000) >> 15;
+ tmp2 = (tmp2 * ga * 2 + fact) >> sh_fact;
+ out[0] = tmp2;
+
+ return tmp;
+}
+
+void ff_g729_postfilter(DSPContext *dsp, int16_t* ht_prev_data, int* voicing,
+ const int16_t *lp_filter_coeffs, int pitch_delay_int,
+ int16_t* residual, int16_t* res_filter_data,
+ int16_t* pos_filter_data, int16_t *speech, int subframe_size)
+{
+ int16_t residual_filt_buf[SUBFRAME_SIZE+11];
+ int16_t lp_gn[33]; // (3.12)
+ int16_t lp_gd[11]; // (3.12)
+ int tilt_comp_coeff;
+ int i;
+
+ /* Zero-filling is necessary for tilt-compensation filter. */
+ memset(lp_gn, 0, 33 * sizeof(int16_t));
+
+ /* Calculate A(z/FORMANT_PP_FACTOR_NUM) filter coefficients. */
+ for (i = 0; i < 10; i++)
+ lp_gn[i + 11] = (lp_filter_coeffs[i + 1] * formant_pp_factor_num_pow[i] + 0x4000) >> 15;
+
+ /* Calculate A(z/FORMANT_PP_FACTOR_DEN) filter coefficients. */
+ for (i = 0; i < 10; i++)
+ lp_gd[i + 1] = (lp_filter_coeffs[i + 1] * formant_pp_factor_den_pow[i] + 0x4000) >> 15;
+
+ /* residual signal calculation (one-half of short-term postfilter) */
+ memcpy(speech - 10, res_filter_data, 10 * sizeof(int16_t));
+ residual_filter(residual + RES_PREV_DATA_SIZE, lp_gn + 11, speech, subframe_size);
+ /* Save data to use it in the next subframe. */
+ memcpy(res_filter_data, speech + subframe_size - 10, 10 * sizeof(int16_t));
+
+ /* long-term filter. If long-term prediction gain is larger than 3dB (returned value is
+ nonzero) then declare current subframe as periodic. */
+ *voicing = FFMAX(*voicing, long_term_filter(dsp, pitch_delay_int,
+ residual, residual_filt_buf + 10,
+ subframe_size));
+
+ /* shift residual for using in next subframe */
+ memmove(residual, residual + subframe_size, RES_PREV_DATA_SIZE * sizeof(int16_t));
+
+ /* short-term filter tilt compensation */
+ tilt_comp_coeff = get_tilt_comp(dsp, lp_gn, lp_gd, residual_filt_buf + 10, subframe_size);
+
+ /* Apply second half of short-term postfilter: 1/A(z/FORMANT_PP_FACTOR_DEN) */
+ ff_celp_lp_synthesis_filter(pos_filter_data + 10, lp_gd + 1,
+ residual_filt_buf + 10,
+ subframe_size, 10, 0, 0, 0x800);
+ memcpy(pos_filter_data, pos_filter_data + subframe_size, 10 * sizeof(int16_t));
+
+ *ht_prev_data = apply_tilt_comp(speech, pos_filter_data + 10, tilt_comp_coeff,
+ subframe_size, *ht_prev_data);
+}
+
+/**
+ * \brief Adaptive gain control (4.2.4)
+ * \param gain_before gain of speech before applying postfilters
+ * \param gain_after gain of speech after applying postfilters
+ * \param speech [in/out] signal buffer
+ * \param subframe_size length of subframe
+ * \param gain_prev (3.12) previous value of gain coefficient
+ *
+ * \return (3.12) last value of gain coefficient
+ */
+int16_t ff_g729_adaptive_gain_control(int gain_before, int gain_after, int16_t *speech,
+ int subframe_size, int16_t gain_prev)
+{
+ int gain; // (3.12)
+ int n;
+ int exp_before, exp_after;
+
+ if(!gain_after && gain_before)
+ return 0;
+
+ if (gain_before) {
+
+ exp_before = 14 - av_log2(gain_before);
+ gain_before = bidir_sal(gain_before, exp_before);
+
+ exp_after = 14 - av_log2(gain_after);
+ gain_after = bidir_sal(gain_after, exp_after);
+
+ if (gain_before < gain_after) {
+ gain = (gain_before << 15) / gain_after;
+ gain = bidir_sal(gain, exp_after - exp_before - 1);
+ } else {
+ gain = ((gain_before - gain_after) << 14) / gain_after + 0x4000;
+ gain = bidir_sal(gain, exp_after - exp_before);
+ }
+ gain = (gain * G729_AGC_FAC1 + 0x4000) >> 15; // gain * (1-0.9875)
+ } else
+ gain = 0;
+
+ for (n = 0; n < subframe_size; n++) {
+ // gain_prev = gain + 0.9875 * gain_prev
+ gain_prev = (G729_AGC_FACTOR * gain_prev + 0x4000) >> 15;
+ gain_prev = av_clip_int16(gain + gain_prev);
+ speech[n] = av_clip_int16((speech[n] * gain_prev + 0x2000) >> 14);
+ }
+ return gain_prev;
+}
diff --git a/libavcodec/g729postfilter.h b/libavcodec/g729postfilter.h
new file mode 100644
index 0000000000..0ccecb2b92
--- /dev/null
+++ b/libavcodec/g729postfilter.h
@@ -0,0 +1,115 @@
+/*
+ * G.729, G729 Annex D postfilter
+ * Copyright (c) 2008 Vladimir Voroshilov
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#ifndef FFMPEG_G729POSTFILTER_H
+#define FFMPEG_G729POSTFILTER_H
+
+#include <stdint.h>
+
+/**
+ * tilt compensation factor (G.729, k1>0)
+ * 0.2 in Q15
+ */
+#define G729_TILT_FACTOR_PLUS 6554
+
+/**
+ * tilt compensation factor (G.729, k1<0)
+ * 0.9 in Q15
+ */
+#define G729_TILT_FACTOR_MINUS 29491
+
+/* 4.2.2 */
+#define FORMANT_PP_FACTOR_NUM 18022 //0.55 in Q15
+#define FORMANT_PP_FACTOR_DEN 22938 //0.70 in Q15
+
+/**
+ * gain adjustment factor (G.729, 4.2.4)
+ * 0.9875 in Q15
+ */
+#define G729_AGC_FACTOR 32358
+#define G729_AGC_FAC1 (32768-G729_AGC_FACTOR)
+
+/**
+ * 1.0 / (1.0 + 0.5) in Q15
+ * where 0.5 is the minimum value of
+ * weight factor, controlling amount of long-term postfiltering
+ */
+#define MIN_LT_FILT_FACTOR_A 21845
+
+/**
+ * Short interpolation filter length
+ */
+#define SHORT_INT_FILT_LEN 2
+
+/**
+ * Long interpolation filter length
+ */
+#define LONG_INT_FILT_LEN 8
+
+/**
+ * Number of analyzed fractional pitch delays in second stage of long-term
+ * postfilter
+ */
+#define ANALYZED_FRAC_DELAYS 7
+
+/**
+ * Amount of past residual signal data stored in buffer
+ */
+#define RES_PREV_DATA_SIZE (PITCH_DELAY_MAX + LONG_INT_FILT_LEN + 1)
+
+/**
+ * \brief Signal postfiltering (4.2)
+ * \param dsp initialized DSP context
+ * \param ht_prev_data [in/out] (Q12) pointer to variable receiving tilt
+ * compensation filter data from previous subframe
+ * \param voicing [in/out] (Q0) pointer to variable receiving voicing decision
+ * \param lp_filter_coeffs (Q12) LP filter coefficients
+ * \param pitch_delay_int integer part of the pitch delay
+ * \param residual [in/out] (Q0) residual signal buffer (used in long-term postfilter)
+ * \param res_filter_data [in/out] (Q0) speech data of previous subframe
+ * \param pos_filter_data [in/out] (Q0) previous speech data for short-term postfilter
+ * \param speech [in/out] (Q0) signal buffer
+ * \param subframe_size size of subframe
+ *
+ * Filtering has the following stages:
+ * Long-term postfilter (4.2.1)
+ * Short-term postfilter (4.2.2).
+ * Tilt-compensation (4.2.3)
+ */
+void ff_g729_postfilter(DSPContext *dsp, int16_t* ht_prev_data, int* voicing,
+ const int16_t *lp_filter_coeffs, int pitch_delay_int,
+ int16_t* residual, int16_t* res_filter_data,
+ int16_t* pos_filter_data, int16_t *speech,
+ int subframe_size);
+
+/**
+ * \brief Adaptive gain control (4.2.4)
+ * \param gain_before (Q0) gain of speech before applying postfilters
+ * \param gain_after (Q0) gain of speech after applying postfilters
+ * \param speech [in/out] (Q0) signal buffer
+ * \param subframe_size length of subframe
+ * \param gain_prev (Q12) previous value of gain coefficient
+ *
+ * \return (Q12) last value of gain coefficient
+ */
+int16_t ff_g729_adaptive_gain_control(int gain_before, int gain_after, int16_t *speech,
+ int subframe_size, int16_t gain_prev);
+
+#endif // FFMPEG_G729POSTFILTER_H
diff --git a/libavcodec/get_bits.h b/libavcodec/get_bits.h
index d2ae345315..3b09dfd285 100644
--- a/libavcodec/get_bits.h
+++ b/libavcodec/get_bits.h
@@ -1,20 +1,20 @@
/*
* copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -127,7 +127,7 @@ for examples see get_bits, show_bits, skip_bits, get_vlc
# define OPEN_READER(name, gb) \
unsigned int name##_index = (gb)->index; \
- unsigned int av_unused name##_cache = 0
+ av_unused unsigned int name##_cache
# define CLOSE_READER(name, gb) (gb)->index = name##_index
@@ -201,11 +201,19 @@ static inline void skip_bits_long(GetBitContext *s, int n){
} \
} while (0)
+#if ARCH_X86
+# define SKIP_CACHE(name, gb, num) \
+ __asm__("shldl %2, %1, %0 \n\t" \
+ "shll %2, %1 \n\t" \
+ : "+r" (name##_cache0), "+r" (name##_cache1) \
+ : "Ic" ((uint8_t)(num)))
+#else
# define SKIP_CACHE(name, gb, num) do { \
name##_cache0 <<= (num); \
name##_cache0 |= NEG_USR32(name##_cache1,num); \
name##_cache1 <<= (num); \
} while (0)
+#endif
# define SKIP_COUNTER(name, gb, num) name##_bit_count += (num)
diff --git a/libavcodec/gif.c b/libavcodec/gif.c
index a34d710a10..8736f0f46c 100644
--- a/libavcodec/gif.c
+++ b/libavcodec/gif.c
@@ -4,20 +4,20 @@
* Copyright (c) 2002 Francois Revol
* Copyright (c) 2006 Baptiste Coudurier
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -167,13 +167,13 @@ static int gif_encode_close(AVCodecContext *avctx)
}
AVCodec ff_gif_encoder = {
- "gif",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_GIF,
- sizeof(GIFContext),
- gif_encode_init,
- gif_encode_frame,
- gif_encode_close,
+ .name = "gif",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_GIF,
+ .priv_data_size = sizeof(GIFContext),
+ .init = gif_encode_init,
+ .encode = gif_encode_frame,
+ .close = gif_encode_close,
.pix_fmts= (const enum PixelFormat[]){PIX_FMT_RGB8, PIX_FMT_BGR8, PIX_FMT_RGB4_BYTE, PIX_FMT_BGR4_BYTE, PIX_FMT_GRAY8, PIX_FMT_PAL8, PIX_FMT_NONE},
.long_name= NULL_IF_CONFIG_SMALL("GIF (Graphics Interchange Format)"),
};
diff --git a/libavcodec/gifdec.c b/libavcodec/gifdec.c
index 934c944a5b..7a22fa702f 100644
--- a/libavcodec/gifdec.c
+++ b/libavcodec/gifdec.c
@@ -3,20 +3,20 @@
* Copyright (c) 2003 Fabrice Bellard
* Copyright (c) 2006 Baptiste Coudurier
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -326,14 +326,13 @@ static av_cold int gif_decode_close(AVCodecContext *avctx)
}
AVCodec ff_gif_decoder = {
- "gif",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_GIF,
- sizeof(GifState),
- gif_decode_init,
- NULL,
- gif_decode_close,
- gif_decode_frame,
- CODEC_CAP_DR1,
+ .name = "gif",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_GIF,
+ .priv_data_size = sizeof(GifState),
+ .init = gif_decode_init,
+ .close = gif_decode_close,
+ .decode = gif_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("GIF (Graphics Interchange Format)"),
};
diff --git a/libavcodec/golomb.c b/libavcodec/golomb.c
index 550c41ebfe..937ac22ce1 100644
--- a/libavcodec/golomb.c
+++ b/libavcodec/golomb.c
@@ -2,20 +2,20 @@
* exp golomb vlc stuff
* Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/golomb.h b/libavcodec/golomb.h
index 83d277f963..8dff0322a7 100644
--- a/libavcodec/golomb.h
+++ b/libavcodec/golomb.h
@@ -3,20 +3,20 @@
* Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
* Copyright (c) 2004 Alex Beregszaszi
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -75,6 +75,20 @@ static inline int get_ue_golomb(GetBitContext *gb){
}
}
+/**
+ * Read an unsigned Exp-Golomb code in the range 0 to UINT32_MAX-1.
+ */
+static inline unsigned get_ue_golomb_long(GetBitContext *gb)
+{
+ unsigned buf, log;
+
+ buf = show_bits_long(gb, 32);
+ log = 31 - av_log2(buf);
+ skip_bits_long(gb, log);
+
+ return get_bits_long(gb, log + 1) - 1;
+}
+
/**
* read unsigned exp golomb code, constraint to a max of 31.
* the return value is undefined if the stored value exceeds 31.
diff --git a/libavcodec/gsmdec.c b/libavcodec/gsmdec.c
index 693febd673..a3f67d3b52 100644
--- a/libavcodec/gsmdec.c
+++ b/libavcodec/gsmdec.c
@@ -2,20 +2,20 @@
* gsm 06.10 decoder
* Copyright (c) 2010 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -85,25 +85,21 @@ static int gsm_decode_frame(AVCodecContext *avctx, void *data,
}
AVCodec ff_gsm_decoder = {
- "gsm",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_GSM,
- sizeof(GSMContext),
- gsm_init,
- NULL,
- NULL,
- gsm_decode_frame,
+ .name = "gsm",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_GSM,
+ .priv_data_size = sizeof(GSMContext),
+ .init = gsm_init,
+ .decode = gsm_decode_frame,
.long_name = NULL_IF_CONFIG_SMALL("GSM"),
};
AVCodec ff_gsm_ms_decoder = {
- "gsm_ms",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_GSM_MS,
- sizeof(GSMContext),
- gsm_init,
- NULL,
- NULL,
- gsm_decode_frame,
+ .name = "gsm_ms",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_GSM_MS,
+ .priv_data_size = sizeof(GSMContext),
+ .init = gsm_init,
+ .decode = gsm_decode_frame,
.long_name = NULL_IF_CONFIG_SMALL("GSM Microsoft variant"),
};
diff --git a/libavcodec/gsmdec_data.c b/libavcodec/gsmdec_data.c
index 8b75bb6a67..4324ea28a9 100644
--- a/libavcodec/gsmdec_data.c
+++ b/libavcodec/gsmdec_data.c
@@ -2,20 +2,20 @@
* gsm 06.10 decoder data
* Copyright (c) 2010 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/gsmdec_data.h b/libavcodec/gsmdec_data.h
index b78daa7335..bb4f159c60 100644
--- a/libavcodec/gsmdec_data.h
+++ b/libavcodec/gsmdec_data.h
@@ -2,20 +2,20 @@
* gsm 06.10 decoder data
* Copyright (c) 2010 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/gsmdec_template.c b/libavcodec/gsmdec_template.c
index 7e57c7183f..b63ec9ed27 100644
--- a/libavcodec/gsmdec_template.c
+++ b/libavcodec/gsmdec_template.c
@@ -2,20 +2,20 @@
* gsm 06.10 decoder
* Copyright (c) 2010 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/h261.c b/libavcodec/h261.c
index eab36402ee..562a151e90 100644
--- a/libavcodec/h261.c
+++ b/libavcodec/h261.c
@@ -3,20 +3,20 @@
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
* Copyright (c) 2004 Maarten Daniels
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/h261.h b/libavcodec/h261.h
index 6461329343..5b60dd65a3 100644
--- a/libavcodec/h261.h
+++ b/libavcodec/h261.h
@@ -3,20 +3,20 @@
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
* Copyright (c) 2004 Maarten Daniels
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/h261_parser.c b/libavcodec/h261_parser.c
index 20c2862549..3fb86db125 100644
--- a/libavcodec/h261_parser.c
+++ b/libavcodec/h261_parser.c
@@ -3,20 +3,20 @@
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
* Copyright (c) 2004 Maarten Daniels
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -70,11 +70,15 @@ static int h261_parse(AVCodecParserContext *s,
ParseContext *pc = s->priv_data;
int next;
- next= h261_find_frame_end(pc,avctx, buf, buf_size);
- if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) {
- *poutbuf = NULL;
- *poutbuf_size = 0;
- return buf_size;
+ if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) {
+ next = buf_size;
+ } else {
+ next= h261_find_frame_end(pc,avctx, buf, buf_size);
+ if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) {
+ *poutbuf = NULL;
+ *poutbuf_size = 0;
+ return buf_size;
+ }
}
*poutbuf = buf;
*poutbuf_size = buf_size;
diff --git a/libavcodec/h261data.h b/libavcodec/h261data.h
index 2c610151c7..82bae163df 100644
--- a/libavcodec/h261data.h
+++ b/libavcodec/h261data.h
@@ -2,20 +2,20 @@
* copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
* copyright (c) 2004 Maarten Daniels
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/h261dec.c b/libavcodec/h261dec.c
index a335d68ff1..96ebb24027 100644
--- a/libavcodec/h261dec.c
+++ b/libavcodec/h261dec.c
@@ -3,20 +3,20 @@
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
* Copyright (c) 2004 Maarten Daniels
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -215,7 +215,7 @@ static int h261_decode_mb_skipped(H261Context *h, int mba1, int mba2 )
s->mv_dir = MV_DIR_FORWARD;
s->mv_type = MV_TYPE_16X16;
- s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
+ s->current_picture.f.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
s->mv[0][0][0] = 0;
s->mv[0][0][1] = 0;
s->mb_skipped = 1;
@@ -323,14 +323,14 @@ static int h261_decode_mb(H261Context *h){
}
if(s->mb_intra){
- s->current_picture.mb_type[xy]= MB_TYPE_INTRA;
+ s->current_picture.f.mb_type[xy] = MB_TYPE_INTRA;
goto intra;
}
//set motion vectors
s->mv_dir = MV_DIR_FORWARD;
s->mv_type = MV_TYPE_16X16;
- s->current_picture.mb_type[xy]= MB_TYPE_16x16 | MB_TYPE_L0;
+ s->current_picture.f.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_L0;
s->mv[0][0][0] = h->current_mv_x * 2;//gets divided by 2 in motion compensation
s->mv[0][0][1] = h->current_mv_y * 2;
@@ -464,7 +464,7 @@ static int h261_decode_picture_header(H261Context *h){
s->picture_number = (s->picture_number&~31) + i;
s->avctx->time_base= (AVRational){1001, 30000};
- s->current_picture.pts= s->picture_number;
+ s->current_picture.f.pts = s->picture_number;
/* PTYPE starts here */
@@ -570,7 +570,7 @@ retry:
}
//we need to set current_picture_ptr before reading the header, otherwise we cannot store anyting im there
- if(s->current_picture_ptr==NULL || s->current_picture_ptr->data[0]){
+ if (s->current_picture_ptr == NULL || s->current_picture_ptr->f.data[0]) {
int i= ff_find_unused_picture(s, 0);
s->current_picture_ptr= &s->picture[i];
}
@@ -596,8 +596,8 @@ retry:
}
// for skipping the frame
- s->current_picture.pict_type= s->pict_type;
- s->current_picture.key_frame= s->pict_type == AV_PICTURE_TYPE_I;
+ s->current_picture.f.pict_type = s->pict_type;
+ s->current_picture.f.key_frame = s->pict_type == AV_PICTURE_TYPE_I;
if( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type==AV_PICTURE_TYPE_B)
||(avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=AV_PICTURE_TYPE_I)
@@ -620,8 +620,8 @@ retry:
}
MPV_frame_end(s);
-assert(s->current_picture.pict_type == s->current_picture_ptr->pict_type);
-assert(s->current_picture.pict_type == s->pict_type);
+assert(s->current_picture.f.pict_type == s->current_picture_ptr->f.pict_type);
+assert(s->current_picture.f.pict_type == s->pict_type);
*pict= *(AVFrame*)s->current_picture_ptr;
ff_print_debug_info(s, pict);
@@ -640,15 +640,14 @@ static av_cold int h261_decode_end(AVCodecContext *avctx)
}
AVCodec ff_h261_decoder = {
- "h261",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_H261,
- sizeof(H261Context),
- h261_decode_init,
- NULL,
- h261_decode_end,
- h261_decode_frame,
- CODEC_CAP_DR1,
+ .name = "h261",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_H261,
+ .priv_data_size = sizeof(H261Context),
+ .init = h261_decode_init,
+ .close = h261_decode_end,
+ .decode = h261_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.max_lowres = 3,
.long_name = NULL_IF_CONFIG_SMALL("H.261"),
};
diff --git a/libavcodec/h261enc.c b/libavcodec/h261enc.c
index 27746d5d8c..a275bfda4a 100644
--- a/libavcodec/h261enc.c
+++ b/libavcodec/h261enc.c
@@ -3,20 +3,20 @@
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
* Copyright (c) 2004 Maarten Daniels
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -53,7 +53,7 @@ void ff_h261_encode_picture_header(MpegEncContext * s, int picture_number){
H261Context * h = (H261Context *) s;
int format, temp_ref;
- align_put_bits(&s->pb);
+ avpriv_align_put_bits(&s->pb);
/* Update the pointer to last GOB */
s->ptr_lastgob = put_bits_ptr(&s->pb);
@@ -322,13 +322,13 @@ static void h261_encode_block(H261Context * h, DCTELEM * block, int n){
}
AVCodec ff_h261_encoder = {
- "h261",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_H261,
- sizeof(H261Context),
- MPV_encode_init,
- MPV_encode_picture,
- MPV_encode_end,
+ .name = "h261",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_H261,
+ .priv_data_size = sizeof(H261Context),
+ .init = MPV_encode_init,
+ .encode = MPV_encode_picture,
+ .close = MPV_encode_end,
.pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
.long_name= NULL_IF_CONFIG_SMALL("H.261"),
};
diff --git a/libavcodec/h263.c b/libavcodec/h263.c
index 5c25df2272..53f06bb2e6 100644
--- a/libavcodec/h263.c
+++ b/libavcodec/h263.c
@@ -5,20 +5,20 @@
* Copyright (c) 2001 Juan J. Sierralta P
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -52,7 +52,7 @@ void ff_h263_update_motion_val(MpegEncContext * s){
const int wrap = s->b8_stride;
const int xy = s->block_index[0];
- s->current_picture.mbskip_table[mb_xy]= s->mb_skipped;
+ s->current_picture.f.mbskip_table[mb_xy] = s->mb_skipped;
if(s->mv_type != MV_TYPE_8X8){
int motion_x, motion_y;
@@ -71,30 +71,30 @@ void ff_h263_update_motion_val(MpegEncContext * s){
s->p_field_mv_table[i][0][mb_xy][0]= s->mv[0][i][0];
s->p_field_mv_table[i][0][mb_xy][1]= s->mv[0][i][1];
}
- s->current_picture.ref_index[0][4*mb_xy ]=
- s->current_picture.ref_index[0][4*mb_xy + 1]= s->field_select[0][0];
- s->current_picture.ref_index[0][4*mb_xy + 2]=
- s->current_picture.ref_index[0][4*mb_xy + 3]= s->field_select[0][1];
+ s->current_picture.f.ref_index[0][4*mb_xy ] =
+ s->current_picture.f.ref_index[0][4*mb_xy + 1] = s->field_select[0][0];
+ s->current_picture.f.ref_index[0][4*mb_xy + 2] =
+ s->current_picture.f.ref_index[0][4*mb_xy + 3] = s->field_select[0][1];
}
/* no update if 8X8 because it has been done during parsing */
- s->current_picture.motion_val[0][xy][0] = motion_x;
- s->current_picture.motion_val[0][xy][1] = motion_y;
- s->current_picture.motion_val[0][xy + 1][0] = motion_x;
- s->current_picture.motion_val[0][xy + 1][1] = motion_y;
- s->current_picture.motion_val[0][xy + wrap][0] = motion_x;
- s->current_picture.motion_val[0][xy + wrap][1] = motion_y;
- s->current_picture.motion_val[0][xy + 1 + wrap][0] = motion_x;
- s->current_picture.motion_val[0][xy + 1 + wrap][1] = motion_y;
+ s->current_picture.f.motion_val[0][xy][0] = motion_x;
+ s->current_picture.f.motion_val[0][xy][1] = motion_y;
+ s->current_picture.f.motion_val[0][xy + 1][0] = motion_x;
+ s->current_picture.f.motion_val[0][xy + 1][1] = motion_y;
+ s->current_picture.f.motion_val[0][xy + wrap][0] = motion_x;
+ s->current_picture.f.motion_val[0][xy + wrap][1] = motion_y;
+ s->current_picture.f.motion_val[0][xy + 1 + wrap][0] = motion_x;
+ s->current_picture.f.motion_val[0][xy + 1 + wrap][1] = motion_y;
}
if(s->encoding){ //FIXME encoding MUST be cleaned up
if (s->mv_type == MV_TYPE_8X8)
- s->current_picture.mb_type[mb_xy]= MB_TYPE_L0 | MB_TYPE_8x8;
+ s->current_picture.f.mb_type[mb_xy] = MB_TYPE_L0 | MB_TYPE_8x8;
else if(s->mb_intra)
- s->current_picture.mb_type[mb_xy]= MB_TYPE_INTRA;
+ s->current_picture.f.mb_type[mb_xy] = MB_TYPE_INTRA;
else
- s->current_picture.mb_type[mb_xy]= MB_TYPE_L0 | MB_TYPE_16x16;
+ s->current_picture.f.mb_type[mb_xy] = MB_TYPE_L0 | MB_TYPE_16x16;
}
}
@@ -154,7 +154,7 @@ void ff_h263_loop_filter(MpegEncContext * s){
Diag Top
Left Center
*/
- if(!IS_SKIP(s->current_picture.mb_type[xy])){
+ if (!IS_SKIP(s->current_picture.f.mb_type[xy])) {
qp_c= s->qscale;
s->dsp.h263_v_loop_filter(dest_y+8*linesize , linesize, qp_c);
s->dsp.h263_v_loop_filter(dest_y+8*linesize+8, linesize, qp_c);
@@ -164,10 +164,10 @@ void ff_h263_loop_filter(MpegEncContext * s){
if(s->mb_y){
int qp_dt, qp_tt, qp_tc;
- if(IS_SKIP(s->current_picture.mb_type[xy-s->mb_stride]))
+ if (IS_SKIP(s->current_picture.f.mb_type[xy - s->mb_stride]))
qp_tt=0;
else
- qp_tt= s->current_picture.qscale_table[xy-s->mb_stride];
+ qp_tt = s->current_picture.f.qscale_table[xy - s->mb_stride];
if(qp_c)
qp_tc= qp_c;
@@ -187,10 +187,10 @@ void ff_h263_loop_filter(MpegEncContext * s){
s->dsp.h263_h_loop_filter(dest_y-8*linesize+8 , linesize, qp_tt);
if(s->mb_x){
- if(qp_tt || IS_SKIP(s->current_picture.mb_type[xy-1-s->mb_stride]))
+ if (qp_tt || IS_SKIP(s->current_picture.f.mb_type[xy - 1 - s->mb_stride]))
qp_dt= qp_tt;
else
- qp_dt= s->current_picture.qscale_table[xy-1-s->mb_stride];
+ qp_dt = s->current_picture.f.qscale_table[xy - 1 - s->mb_stride];
if(qp_dt){
const int chroma_qp= s->chroma_qscale_table[qp_dt];
@@ -209,10 +209,10 @@ void ff_h263_loop_filter(MpegEncContext * s){
if(s->mb_x){
int qp_lc;
- if(qp_c || IS_SKIP(s->current_picture.mb_type[xy-1]))
+ if (qp_c || IS_SKIP(s->current_picture.f.mb_type[xy - 1]))
qp_lc= qp_c;
else
- qp_lc= s->current_picture.qscale_table[xy-1];
+ qp_lc = s->current_picture.f.qscale_table[xy - 1];
if(qp_lc){
s->dsp.h263_h_loop_filter(dest_y, linesize, qp_lc);
@@ -321,7 +321,7 @@ int16_t *h263_pred_motion(MpegEncContext * s, int block, int dir,
static const int off[4]= {2, 1, 1, -1};
wrap = s->b8_stride;
- mot_val = s->current_picture.motion_val[dir] + s->block_index[block];
+ mot_val = s->current_picture.f.motion_val[dir] + s->block_index[block];
A = mot_val[ - 1];
/* special case for first (slice) line */
diff --git a/libavcodec/h263.h b/libavcodec/h263.h
index 1dc300709e..b2b6613536 100644
--- a/libavcodec/h263.h
+++ b/libavcodec/h263.h
@@ -1,20 +1,20 @@
/*
* H263 internal header
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVCODEC_H263_H
diff --git a/libavcodec/h263_parser.c b/libavcodec/h263_parser.c
index 4b9fc110f2..a3d24ea433 100644
--- a/libavcodec/h263_parser.c
+++ b/libavcodec/h263_parser.c
@@ -2,20 +2,20 @@
* H.263 parser
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -70,12 +70,16 @@ static int h263_parse(AVCodecParserContext *s,
ParseContext *pc = s->priv_data;
int next;
- next= ff_h263_find_frame_end(pc, buf, buf_size);
+ if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) {
+ next = buf_size;
+ } else {
+ next= ff_h263_find_frame_end(pc, buf, buf_size);
- if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) {
- *poutbuf = NULL;
- *poutbuf_size = 0;
- return buf_size;
+ if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) {
+ *poutbuf = NULL;
+ *poutbuf_size = 0;
+ return buf_size;
+ }
}
*poutbuf = buf;
diff --git a/libavcodec/h263_parser.h b/libavcodec/h263_parser.h
index 5bd715f49d..565a222bc1 100644
--- a/libavcodec/h263_parser.h
+++ b/libavcodec/h263_parser.h
@@ -2,20 +2,20 @@
* H.263 parser
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/h263data.h b/libavcodec/h263data.h
index 966da56110..81e3ddd2e0 100644
--- a/libavcodec/h263data.h
+++ b/libavcodec/h263data.h
@@ -4,20 +4,20 @@
* copyright (c) 2001 Juan J. Sierralta P
* copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
index bc6d613be4..2887805a0e 100644
--- a/libavcodec/h263dec.c
+++ b/libavcodec/h263dec.c
@@ -3,20 +3,20 @@
* Copyright (c) 2001 Fabrice Bellard
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -91,6 +91,8 @@ av_cold int ff_h263_decode_init(AVCodecContext *avctx)
break;
case CODEC_ID_VC1:
case CODEC_ID_WMV3:
+ case CODEC_ID_VC1IMAGE:
+ case CODEC_ID_WMV3IMAGE:
s->h263_pred = 1;
s->msmpeg4_version=6;
avctx->chroma_sample_location = AVCHROMA_LOC_LEFT;
@@ -269,7 +271,7 @@ static int decode_slice(MpegEncContext *s){
if( s->codec_id==CODEC_ID_MPEG4
&& (s->workaround_bugs&FF_BUG_AUTODETECT)
&& get_bits_left(&s->gb) >=0
- && get_bits_left(&s->gb) < 48
+ && get_bits_left(&s->gb) < 137
// && !s->resync_marker
&& !s->data_partitioning){
@@ -380,6 +382,18 @@ uint64_t time= rdtsc();
retry:
+ if(s->divx_packed && s->bitstream_buffer_size){
+ int i;
+ for(i=0; i<buf_size-3; i++){
+ if(buf[i]==0 && buf[i+1]==0 && buf[i+2]==1){
+ if(buf[i+3]==0xB0){
+ av_log(s->avctx, AV_LOG_WARNING, "Discarding excessive bitstream in packed xvid\n");
+ s->bitstream_buffer_size=0;
+ }
+ break;
+ }
+ }
+ }
if(s->bitstream_buffer_size && (s->divx_packed || buf_size<20)){ //divx 5.01+/xvid frame reorder
init_get_bits(&s->gb, s->bitstream_buffer, s->bitstream_buffer_size*8);
@@ -394,7 +408,7 @@ retry:
/* We need to set current_picture_ptr before reading the header,
* otherwise we cannot store anyting in there */
- if(s->current_picture_ptr==NULL || s->current_picture_ptr->data[0]){
+ if (s->current_picture_ptr == NULL || s->current_picture_ptr->f.data[0]) {
int i= ff_find_unused_picture(s, 0);
s->current_picture_ptr= &s->picture[i];
}
@@ -581,8 +595,8 @@ retry:
s->gob_index = ff_h263_get_gob_height(s);
// for skipping the frame
- s->current_picture.pict_type= s->pict_type;
- s->current_picture.key_frame= s->pict_type == AV_PICTURE_TYPE_I;
+ s->current_picture.f.pict_type = s->pict_type;
+ s->current_picture.f.key_frame = s->pict_type == AV_PICTURE_TYPE_I;
/* skip B-frames if we don't have reference frames */
if(s->last_picture_ptr==NULL && (s->pict_type==AV_PICTURE_TYPE_B || s->dropable)) return get_consumed_bytes(s, buf_size);
@@ -638,7 +652,7 @@ retry:
s->mb_x=0;
s->mb_y=0;
- decode_slice(s);
+ ret = decode_slice(s);
while(s->mb_y<s->mb_height){
if(s->msmpeg4_version){
if(s->slice_height==0 || s->mb_x!=0 || (s->mb_y%s->slice_height)!=0 || get_bits_count(&s->gb) > s->gb.size_in_bits)
@@ -654,7 +668,7 @@ retry:
if(s->msmpeg4_version<4 && s->h263_pred)
ff_mpeg4_clean_buffers(s);
- decode_slice(s);
+ if (decode_slice(s) < 0) ret = AVERROR_INVALIDDATA;
}
if (s->msmpeg4_version && s->msmpeg4_version<4 && s->pict_type==AV_PICTURE_TYPE_I)
@@ -666,22 +680,18 @@ retry:
frame_end:
/* divx 5.01+ bistream reorder stuff */
if(s->codec_id==CODEC_ID_MPEG4 && s->divx_packed){
- int current_pos= get_bits_count(&s->gb)>>3;
+ int current_pos= s->gb.buffer == s->bitstream_buffer ? 0 : (get_bits_count(&s->gb)>>3);
int startcode_found=0;
- if(buf_size - current_pos > 5){
+ if(buf_size - current_pos > 7){
int i;
- for(i=current_pos; i<buf_size-3; i++){
+ for(i=current_pos; i<buf_size-4; i++){
if(buf[i]==0 && buf[i+1]==0 && buf[i+2]==1 && buf[i+3]==0xB6){
- startcode_found=1;
+ startcode_found=!(buf[i+4]&0x40);
break;
}
}
}
- if(s->gb.buffer == s->bitstream_buffer && buf_size>7 && s->xvid_build>=0){ //xvid style
- startcode_found=1;
- current_pos=0;
- }
if(startcode_found){
av_fast_malloc(
@@ -705,8 +715,8 @@ intrax8_decoded:
MPV_frame_end(s);
-assert(s->current_picture.pict_type == s->current_picture_ptr->pict_type);
-assert(s->current_picture.pict_type == s->pict_type);
+ assert(s->current_picture.f.pict_type == s->current_picture_ptr->f.pict_type);
+ assert(s->current_picture.f.pict_type == s->pict_type);
if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {
*pict= *(AVFrame*)s->current_picture_ptr;
} else if (s->last_picture_ptr != NULL) {
@@ -722,19 +732,18 @@ assert(s->current_picture.pict_type == s->pict_type);
av_log(avctx, AV_LOG_DEBUG, "%"PRId64"\n", rdtsc()-time);
#endif
- return get_consumed_bytes(s, buf_size);
+ return (ret && avctx->error_recognition >= FF_ER_EXPLODE)?ret:get_consumed_bytes(s, buf_size);
}
AVCodec ff_h263_decoder = {
- "h263",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_H263,
- sizeof(MpegEncContext),
- ff_h263_decode_init,
- NULL,
- ff_h263_decode_end,
- ff_h263_decode_frame,
- CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY,
+ .name = "h263",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_H263,
+ .priv_data_size = sizeof(MpegEncContext),
+ .init = ff_h263_decode_init,
+ .close = ff_h263_decode_end,
+ .decode = ff_h263_decode_frame,
+ .capabilities = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY,
.flush= ff_mpeg_flush,
.max_lowres= 3,
.long_name= NULL_IF_CONFIG_SMALL("H.263 / H.263-1996, H.263+ / H.263-1998 / H.263 version 2"),
diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index dbac4fda95..4906f92ea8 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -2,20 +2,20 @@
* H.26L/H.264/AVC/JVT/14496-10/... decoder
* Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -97,12 +97,9 @@ int ff_h264_check_intra4x4_pred_mode(H264Context *h){
}
return 0;
-} //FIXME cleanup like ff_h264_check_intra_pred_mode
+} //FIXME cleanup like check_intra_pred_mode
-/**
- * checks if the top & left blocks are available if needed & changes the dc mode so it only uses the available blocks.
- */
-int ff_h264_check_intra_pred_mode(H264Context *h, int mode){
+static int check_intra_pred_mode(H264Context *h, int mode, int is_chroma){
MpegEncContext * const s = &h->s;
static const int8_t top [7]= {LEFT_DC_PRED8x8, 1,-1,-1};
static const int8_t left[7]= { TOP_DC_PRED8x8,-1, 2,-1,DC_128_PRED8x8};
@@ -122,7 +119,7 @@ int ff_h264_check_intra_pred_mode(H264Context *h, int mode){
if((h->left_samples_available&0x8080) != 0x8080){
mode= left[ mode ];
- if(h->left_samples_available&0x8080){ //mad cow disease mode, aka MBAFF + constrained_intra_pred
+ if(is_chroma && (h->left_samples_available&0x8080)){ //mad cow disease mode, aka MBAFF + constrained_intra_pred
mode= ALZHEIMER_DC_L0T_PRED8x8 + (!(h->left_samples_available&0x8000)) + 2*(mode == DC_128_PRED8x8);
}
if(mode<0){
@@ -134,6 +131,23 @@ int ff_h264_check_intra_pred_mode(H264Context *h, int mode){
return mode;
}
+/**
+ * checks if the top & left blocks are available if needed & changes the dc mode so it only uses the available blocks.
+ */
+int ff_h264_check_intra16x16_pred_mode(H264Context *h, int mode)
+{
+ return check_intra_pred_mode(h, mode, 0);
+}
+
+/**
+ * checks if the top & left blocks are available if needed & changes the dc mode so it only uses the available blocks.
+ */
+int ff_h264_check_intra_chroma_pred_mode(H264Context *h, int mode)
+{
+ return check_intra_pred_mode(h, mode, 1);
+}
+
+
const uint8_t *ff_h264_decode_nal(H264Context *h, const uint8_t *src, int *dst_length, int *consumed, int length){
int i, si, di;
uint8_t *dst;
@@ -174,20 +188,28 @@ const uint8_t *ff_h264_decode_nal(H264Context *h, const uint8_t *src, int *dst_l
i-= RS;
}
- if(i>=length-1){ //no escaped 0
- *dst_length= length;
- *consumed= length+1; //+1 for the header
- return src;
- }
-
bufidx = h->nal_unit_type == NAL_DPC ? 1 : 0; // use second escape buffer for inter data
- av_fast_malloc(&h->rbsp_buffer[bufidx], &h->rbsp_buffer_size[bufidx], length+FF_INPUT_BUFFER_PADDING_SIZE);
+ si=h->rbsp_buffer_size[bufidx];
+ av_fast_malloc(&h->rbsp_buffer[bufidx], &h->rbsp_buffer_size[bufidx], length+FF_INPUT_BUFFER_PADDING_SIZE+MAX_MBPAIR_SIZE);
dst= h->rbsp_buffer[bufidx];
+ if(si != h->rbsp_buffer_size[bufidx])
+ memset(dst + length, 0, FF_INPUT_BUFFER_PADDING_SIZE+MAX_MBPAIR_SIZE);
if (dst == NULL){
return NULL;
}
+ if(i>=length-1){ //no escaped 0
+ *dst_length= length;
+ *consumed= length+1; //+1 for the header
+ if(h->s.avctx->flags2 & CODEC_FLAG2_FAST){
+ return src;
+ }else{
+ memcpy(dst, src, length);
+ return dst;
+ }
+ }
+
//printf("decoding esc\n");
memcpy(dst, src, i);
si=di=i;
@@ -261,8 +283,8 @@ static inline void get_lowest_part_y(H264Context *h, int refs[2][48], int n, int
// Error resilience puts the current picture in the ref list.
// Don't try to wait on these as it will cause a deadlock.
// Fields can wait on each other, though.
- if(ref->thread_opaque != s->current_picture.thread_opaque ||
- (ref->reference&3) != s->picture_structure) {
+ if (ref->f.thread_opaque != s->current_picture.f.thread_opaque ||
+ (ref->f.reference & 3) != s->picture_structure) {
my = get_lowest_part_list_y(h, ref, n, height, y_offset, 0);
if (refs[0][ref_n] < 0) nrefs[0] += 1;
refs[0][ref_n] = FFMAX(refs[0][ref_n], my);
@@ -273,8 +295,8 @@ static inline void get_lowest_part_y(H264Context *h, int refs[2][48], int n, int
int ref_n = h->ref_cache[1][ scan8[n] ];
Picture *ref= &h->ref_list[1][ref_n];
- if(ref->thread_opaque != s->current_picture.thread_opaque ||
- (ref->reference&3) != s->picture_structure) {
+ if (ref->f.thread_opaque != s->current_picture.f.thread_opaque ||
+ (ref->f.reference & 3) != s->picture_structure) {
my = get_lowest_part_list_y(h, ref, n, height, y_offset, 1);
if (refs[1][ref_n] < 0) nrefs[1] += 1;
refs[1][ref_n] = FFMAX(refs[1][ref_n], my);
@@ -290,7 +312,7 @@ static inline void get_lowest_part_y(H264Context *h, int refs[2][48], int n, int
static void await_references(H264Context *h){
MpegEncContext * const s = &h->s;
const int mb_xy= h->mb_xy;
- const int mb_type= s->current_picture.mb_type[mb_xy];
+ const int mb_type = s->current_picture.f.mb_type[mb_xy];
int refs[2][48];
int nrefs[2] = {0};
int ref, list;
@@ -350,7 +372,7 @@ static void await_references(H264Context *h){
int row = refs[list][ref];
if(row >= 0){
Picture *ref_pic = &h->ref_list[list][ref];
- int ref_field = ref_pic->reference - 1;
+ int ref_field = ref_pic->f.reference - 1;
int ref_field_picture = ref_pic->field_picture;
int pic_height = 16*s->mb_height >> ref_field_picture;
@@ -438,17 +460,20 @@ static void chroma_dc_dct_c(DCTELEM *block){
}
#endif
-static inline void mc_dir_part(H264Context *h, Picture *pic, int n, int square, int chroma_height, int delta, int list,
- uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
- int src_x_offset, int src_y_offset,
- qpel_mc_func *qpix_op, h264_chroma_mc_func chroma_op,
- int pixel_shift, int chroma444){
+static av_always_inline void
+mc_dir_part(H264Context *h, Picture *pic, int n, int square,
+ int height, int delta, int list,
+ uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
+ int src_x_offset, int src_y_offset,
+ qpel_mc_func *qpix_op, h264_chroma_mc_func chroma_op,
+ int pixel_shift, int chroma_idc)
+{
MpegEncContext * const s = &h->s;
const int mx= h->mv_cache[list][ scan8[n] ][0] + src_x_offset*8;
int my= h->mv_cache[list][ scan8[n] ][1] + src_y_offset*8;
const int luma_xy= (mx&3) + ((my&3)<<2);
int offset = ((mx>>2) << pixel_shift) + (my>>2)*h->mb_linesize;
- uint8_t * src_y = pic->data[0] + offset;
+ uint8_t * src_y = pic->f.data[0] + offset;
uint8_t * src_cb, * src_cr;
int extra_width= h->emu_edge_width;
int extra_height= h->emu_edge_height;
@@ -457,6 +482,7 @@ static inline void mc_dir_part(H264Context *h, Picture *pic, int n, int square,
const int full_my= my>>2;
const int pic_width = 16*s->mb_width;
const int pic_height = 16*s->mb_height >> MB_FIELD;
+ int ysh;
if(mx&7) extra_width -= 3;
if(my&7) extra_height -= 3;
@@ -465,7 +491,8 @@ static inline void mc_dir_part(H264Context *h, Picture *pic, int n, int square,
|| full_my < 0-extra_height
|| full_mx + 16/*FIXME*/ > pic_width + extra_width
|| full_my + 16/*FIXME*/ > pic_height + extra_height){
- s->dsp.emulated_edge_mc(s->edge_emu_buffer, src_y - (2 << pixel_shift) - 2*h->mb_linesize, h->mb_linesize, 16+5, 16+5/*FIXME*/, full_mx-2, full_my-2, pic_width, pic_height);
+ s->dsp.emulated_edge_mc(s->edge_emu_buffer, src_y - (2 << pixel_shift) - 2*h->mb_linesize, h->mb_linesize,
+ 16+5, 16+5/*FIXME*/, full_mx-2, full_my-2, pic_width, pic_height);
src_y= s->edge_emu_buffer + (2 << pixel_shift) + 2*h->mb_linesize;
emu=1;
}
@@ -477,8 +504,8 @@ static inline void mc_dir_part(H264Context *h, Picture *pic, int n, int square,
if(CONFIG_GRAY && s->flags&CODEC_FLAG_GRAY) return;
- if(chroma444){
- src_cb = pic->data[1] + offset;
+ if(chroma_idc == 3 /* yuv444 */){
+ src_cb = pic->f.data[1] + offset;
if(emu){
s->dsp.emulated_edge_mc(s->edge_emu_buffer, src_cb - (2 << pixel_shift) - 2*h->mb_linesize, h->mb_linesize,
16+5, 16+5/*FIXME*/, full_mx-2, full_my-2, pic_width, pic_height);
@@ -489,7 +516,7 @@ static inline void mc_dir_part(H264Context *h, Picture *pic, int n, int square,
qpix_op[luma_xy](dest_cb + delta, src_cb + delta, h->mb_linesize);
}
- src_cr = pic->data[2] + offset;
+ src_cr = pic->f.data[2] + offset;
if(emu){
s->dsp.emulated_edge_mc(s->edge_emu_buffer, src_cr - (2 << pixel_shift) - 2*h->mb_linesize, h->mb_linesize,
16+5, 16+5/*FIXME*/, full_mx-2, full_my-2, pic_width, pic_height);
@@ -502,42 +529,55 @@ static inline void mc_dir_part(H264Context *h, Picture *pic, int n, int square,
return;
}
- if(MB_FIELD){
+ ysh = 3 - (chroma_idc == 2 /* yuv422 */);
+ if(chroma_idc == 1 /* yuv420 */ && MB_FIELD){
// chroma offset when predicting from a field of opposite parity
- my += 2 * ((s->mb_y & 1) - (pic->reference - 1));
+ my += 2 * ((s->mb_y & 1) - (pic->f.reference - 1));
emu |= (my>>3) < 0 || (my>>3) + 8 >= (pic_height>>1);
}
- src_cb= pic->data[1] + ((mx>>3) << pixel_shift) + (my>>3)*h->mb_uvlinesize;
- src_cr= pic->data[2] + ((mx>>3) << pixel_shift) + (my>>3)*h->mb_uvlinesize;
+
+ src_cb = pic->f.data[1] + ((mx >> 3) << pixel_shift) + (my >> ysh) * h->mb_uvlinesize;
+ src_cr = pic->f.data[2] + ((mx >> 3) << pixel_shift) + (my >> ysh) * h->mb_uvlinesize;
if(emu){
- s->dsp.emulated_edge_mc(s->edge_emu_buffer, src_cb, h->mb_uvlinesize, 9, 9/*FIXME*/, (mx>>3), (my>>3), pic_width>>1, pic_height>>1);
+ s->dsp.emulated_edge_mc(s->edge_emu_buffer, src_cb, h->mb_uvlinesize,
+ 9, 8 * chroma_idc + 1, (mx >> 3), (my >> ysh),
+ pic_width >> 1, pic_height >> (chroma_idc == 1 /* yuv420 */));
src_cb= s->edge_emu_buffer;
}
- chroma_op(dest_cb, src_cb, h->mb_uvlinesize, chroma_height, mx&7, my&7);
+ chroma_op(dest_cb, src_cb, h->mb_uvlinesize, height >> (chroma_idc == 1 /* yuv420 */),
+ mx&7, (my << (chroma_idc == 2 /* yuv422 */)) &7);
if(emu){
- s->dsp.emulated_edge_mc(s->edge_emu_buffer, src_cr, h->mb_uvlinesize, 9, 9/*FIXME*/, (mx>>3), (my>>3), pic_width>>1, pic_height>>1);
+ s->dsp.emulated_edge_mc(s->edge_emu_buffer, src_cr, h->mb_uvlinesize,
+ 9, 8 * chroma_idc + 1, (mx >> 3), (my >> ysh),
+ pic_width >> 1, pic_height >> (chroma_idc == 1 /* yuv420 */));
src_cr= s->edge_emu_buffer;
}
- chroma_op(dest_cr, src_cr, h->mb_uvlinesize, chroma_height, mx&7, my&7);
+ chroma_op(dest_cr, src_cr, h->mb_uvlinesize, height >> (chroma_idc == 1 /* yuv420 */),
+ mx&7, (my << (chroma_idc == 2 /* yuv422 */)) &7);
}
-static inline void mc_part_std(H264Context *h, int n, int square, int chroma_height, int delta,
- uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
- int x_offset, int y_offset,
- qpel_mc_func *qpix_put, h264_chroma_mc_func chroma_put,
- qpel_mc_func *qpix_avg, h264_chroma_mc_func chroma_avg,
- int list0, int list1, int pixel_shift, int chroma444){
+static av_always_inline void
+mc_part_std(H264Context *h, int n, int square, int height, int delta,
+ uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
+ int x_offset, int y_offset,
+ qpel_mc_func *qpix_put, h264_chroma_mc_func chroma_put,
+ qpel_mc_func *qpix_avg, h264_chroma_mc_func chroma_avg,
+ int list0, int list1, int pixel_shift, int chroma_idc)
+{
MpegEncContext * const s = &h->s;
qpel_mc_func *qpix_op= qpix_put;
h264_chroma_mc_func chroma_op= chroma_put;
dest_y += (2*x_offset << pixel_shift) + 2*y_offset*h->mb_linesize;
- if(chroma444){
+ if (chroma_idc == 3 /* yuv444 */) {
dest_cb += (2*x_offset << pixel_shift) + 2*y_offset*h->mb_linesize;
dest_cr += (2*x_offset << pixel_shift) + 2*y_offset*h->mb_linesize;
- }else{
+ } else if (chroma_idc == 2 /* yuv422 */) {
+ dest_cb += ( x_offset << pixel_shift) + 2*y_offset*h->mb_uvlinesize;
+ dest_cr += ( x_offset << pixel_shift) + 2*y_offset*h->mb_uvlinesize;
+ } else /* yuv420 */ {
dest_cb += ( x_offset << pixel_shift) + y_offset*h->mb_uvlinesize;
dest_cr += ( x_offset << pixel_shift) + y_offset*h->mb_uvlinesize;
}
@@ -546,9 +586,9 @@ static inline void mc_part_std(H264Context *h, int n, int square, int chroma_hei
if(list0){
Picture *ref= &h->ref_list[0][ h->ref_cache[0][ scan8[n] ] ];
- mc_dir_part(h, ref, n, square, chroma_height, delta, 0,
+ mc_dir_part(h, ref, n, square, height, delta, 0,
dest_y, dest_cb, dest_cr, x_offset, y_offset,
- qpix_op, chroma_op, pixel_shift, chroma444);
+ qpix_op, chroma_op, pixel_shift, chroma_idc);
qpix_op= qpix_avg;
chroma_op= chroma_avg;
@@ -556,28 +596,36 @@ static inline void mc_part_std(H264Context *h, int n, int square, int chroma_hei
if(list1){
Picture *ref= &h->ref_list[1][ h->ref_cache[1][ scan8[n] ] ];
- mc_dir_part(h, ref, n, square, chroma_height, delta, 1,
+ mc_dir_part(h, ref, n, square, height, delta, 1,
dest_y, dest_cb, dest_cr, x_offset, y_offset,
- qpix_op, chroma_op, pixel_shift, chroma444);
+ qpix_op, chroma_op, pixel_shift, chroma_idc);
}
}
-static inline void mc_part_weighted(H264Context *h, int n, int square, int chroma_height, int delta,
- uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
- int x_offset, int y_offset,
- qpel_mc_func *qpix_put, h264_chroma_mc_func chroma_put,
- h264_weight_func luma_weight_op, h264_weight_func chroma_weight_op,
- h264_biweight_func luma_weight_avg, h264_biweight_func chroma_weight_avg,
- int list0, int list1, int pixel_shift, int chroma444){
+static av_always_inline void
+mc_part_weighted(H264Context *h, int n, int square, int height, int delta,
+ uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
+ int x_offset, int y_offset,
+ qpel_mc_func *qpix_put, h264_chroma_mc_func chroma_put,
+ h264_weight_func luma_weight_op, h264_weight_func chroma_weight_op,
+ h264_biweight_func luma_weight_avg, h264_biweight_func chroma_weight_avg,
+ int list0, int list1, int pixel_shift, int chroma_idc){
MpegEncContext * const s = &h->s;
+ int chroma_height;
dest_y += (2*x_offset << pixel_shift) + 2*y_offset*h->mb_linesize;
- if(chroma444){
+ if (chroma_idc == 3 /* yuv444 */) {
+ chroma_height = height;
chroma_weight_avg = luma_weight_avg;
chroma_weight_op = luma_weight_op;
dest_cb += (2*x_offset << pixel_shift) + 2*y_offset*h->mb_linesize;
dest_cr += (2*x_offset << pixel_shift) + 2*y_offset*h->mb_linesize;
- }else{
+ } else if (chroma_idc == 2 /* yuv422 */) {
+ chroma_height = height;
+ dest_cb += ( x_offset << pixel_shift) + 2*y_offset*h->mb_uvlinesize;
+ dest_cr += ( x_offset << pixel_shift) + 2*y_offset*h->mb_uvlinesize;
+ } else /* yuv420 */ {
+ chroma_height = height >> 1;
dest_cb += ( x_offset << pixel_shift) + y_offset*h->mb_uvlinesize;
dest_cr += ( x_offset << pixel_shift) + y_offset*h->mb_uvlinesize;
}
@@ -593,27 +641,32 @@ static inline void mc_part_weighted(H264Context *h, int n, int square, int chrom
int refn0 = h->ref_cache[0][ scan8[n] ];
int refn1 = h->ref_cache[1][ scan8[n] ];
- mc_dir_part(h, &h->ref_list[0][refn0], n, square, chroma_height, delta, 0,
+ mc_dir_part(h, &h->ref_list[0][refn0], n, square, height, delta, 0,
dest_y, dest_cb, dest_cr,
- x_offset, y_offset, qpix_put, chroma_put, pixel_shift, chroma444);
- mc_dir_part(h, &h->ref_list[1][refn1], n, square, chroma_height, delta, 1,
+ x_offset, y_offset, qpix_put, chroma_put,
+ pixel_shift, chroma_idc);
+ mc_dir_part(h, &h->ref_list[1][refn1], n, square, height, delta, 1,
tmp_y, tmp_cb, tmp_cr,
- x_offset, y_offset, qpix_put, chroma_put, pixel_shift, chroma444);
+ x_offset, y_offset, qpix_put, chroma_put,
+ pixel_shift, chroma_idc);
if(h->use_weight == 2){
int weight0 = h->implicit_weight[refn0][refn1][s->mb_y&1];
int weight1 = 64 - weight0;
- luma_weight_avg( dest_y, tmp_y, h-> mb_linesize, 5, weight0, weight1, 0);
- chroma_weight_avg(dest_cb, tmp_cb, h->mb_uvlinesize, 5, weight0, weight1, 0);
- chroma_weight_avg(dest_cr, tmp_cr, h->mb_uvlinesize, 5, weight0, weight1, 0);
+ luma_weight_avg( dest_y, tmp_y, h-> mb_linesize,
+ height, 5, weight0, weight1, 0);
+ chroma_weight_avg(dest_cb, tmp_cb, h->mb_uvlinesize,
+ chroma_height, 5, weight0, weight1, 0);
+ chroma_weight_avg(dest_cr, tmp_cr, h->mb_uvlinesize,
+ chroma_height, 5, weight0, weight1, 0);
}else{
- luma_weight_avg(dest_y, tmp_y, h->mb_linesize, h->luma_log2_weight_denom,
+ luma_weight_avg(dest_y, tmp_y, h->mb_linesize, height, h->luma_log2_weight_denom,
h->luma_weight[refn0][0][0] , h->luma_weight[refn1][1][0],
h->luma_weight[refn0][0][1] + h->luma_weight[refn1][1][1]);
- chroma_weight_avg(dest_cb, tmp_cb, h->mb_uvlinesize, h->chroma_log2_weight_denom,
+ chroma_weight_avg(dest_cb, tmp_cb, h->mb_uvlinesize, chroma_height, h->chroma_log2_weight_denom,
h->chroma_weight[refn0][0][0][0] , h->chroma_weight[refn1][1][0][0],
h->chroma_weight[refn0][0][0][1] + h->chroma_weight[refn1][1][0][1]);
- chroma_weight_avg(dest_cr, tmp_cr, h->mb_uvlinesize, h->chroma_log2_weight_denom,
+ chroma_weight_avg(dest_cr, tmp_cr, h->mb_uvlinesize, chroma_height, h->chroma_log2_weight_denom,
h->chroma_weight[refn0][0][1][0] , h->chroma_weight[refn1][1][1][0],
h->chroma_weight[refn0][0][1][1] + h->chroma_weight[refn1][1][1][1]);
}
@@ -621,42 +674,46 @@ static inline void mc_part_weighted(H264Context *h, int n, int square, int chrom
int list = list1 ? 1 : 0;
int refn = h->ref_cache[list][ scan8[n] ];
Picture *ref= &h->ref_list[list][refn];
- mc_dir_part(h, ref, n, square, chroma_height, delta, list,
+ mc_dir_part(h, ref, n, square, height, delta, list,
dest_y, dest_cb, dest_cr, x_offset, y_offset,
- qpix_put, chroma_put, pixel_shift, chroma444);
+ qpix_put, chroma_put, pixel_shift, chroma_idc);
- luma_weight_op(dest_y, h->mb_linesize, h->luma_log2_weight_denom,
+ luma_weight_op(dest_y, h->mb_linesize, height, h->luma_log2_weight_denom,
h->luma_weight[refn][list][0], h->luma_weight[refn][list][1]);
if(h->use_weight_chroma){
- chroma_weight_op(dest_cb, h->mb_uvlinesize, h->chroma_log2_weight_denom,
+ chroma_weight_op(dest_cb, h->mb_uvlinesize, chroma_height, h->chroma_log2_weight_denom,
h->chroma_weight[refn][list][0][0], h->chroma_weight[refn][list][0][1]);
- chroma_weight_op(dest_cr, h->mb_uvlinesize, h->chroma_log2_weight_denom,
+ chroma_weight_op(dest_cr, h->mb_uvlinesize, chroma_height, h->chroma_log2_weight_denom,
h->chroma_weight[refn][list][1][0], h->chroma_weight[refn][list][1][1]);
}
}
}
-static inline void mc_part(H264Context *h, int n, int square, int chroma_height, int delta,
- uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
- int x_offset, int y_offset,
- qpel_mc_func *qpix_put, h264_chroma_mc_func chroma_put,
- qpel_mc_func *qpix_avg, h264_chroma_mc_func chroma_avg,
- h264_weight_func *weight_op, h264_biweight_func *weight_avg,
- int list0, int list1, int pixel_shift, int chroma444){
+static av_always_inline void
+mc_part(H264Context *h, int n, int square, int height, int delta,
+ uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
+ int x_offset, int y_offset,
+ qpel_mc_func *qpix_put, h264_chroma_mc_func chroma_put,
+ qpel_mc_func *qpix_avg, h264_chroma_mc_func chroma_avg,
+ h264_weight_func *weight_op, h264_biweight_func *weight_avg,
+ int list0, int list1, int pixel_shift, int chroma_idc)
+{
if((h->use_weight==2 && list0 && list1
&& (h->implicit_weight[ h->ref_cache[0][scan8[n]] ][ h->ref_cache[1][scan8[n]] ][h->s.mb_y&1] != 32))
|| h->use_weight==1)
- mc_part_weighted(h, n, square, chroma_height, delta, dest_y, dest_cb, dest_cr,
+ mc_part_weighted(h, n, square, height, delta, dest_y, dest_cb, dest_cr,
x_offset, y_offset, qpix_put, chroma_put,
- weight_op[0], weight_op[3], weight_avg[0],
- weight_avg[3], list0, list1, pixel_shift, chroma444);
+ weight_op[0], weight_op[1], weight_avg[0],
+ weight_avg[1], list0, list1, pixel_shift, chroma_idc);
else
- mc_part_std(h, n, square, chroma_height, delta, dest_y, dest_cb, dest_cr,
+ mc_part_std(h, n, square, height, delta, dest_y, dest_cb, dest_cr,
x_offset, y_offset, qpix_put, chroma_put, qpix_avg,
- chroma_avg, list0, list1, pixel_shift, chroma444);
+ chroma_avg, list0, list1, pixel_shift, chroma_idc);
}
-static inline void prefetch_motion(H264Context *h, int list, int pixel_shift, int chroma444){
+static av_always_inline void
+prefetch_motion(H264Context *h, int list, int pixel_shift, int chroma_idc)
+{
/* fetch pixels for estimated mv 4 macroblocks ahead
* optimized for 64byte cache lines */
MpegEncContext * const s = &h->s;
@@ -664,14 +721,14 @@ static inline void prefetch_motion(H264Context *h, int list, int pixel_shift, in
if(refn >= 0){
const int mx= (h->mv_cache[list][scan8[0]][0]>>2) + 16*s->mb_x + 8;
const int my= (h->mv_cache[list][scan8[0]][1]>>2) + 16*s->mb_y;
- uint8_t **src= h->ref_list[list][refn].data;
+ uint8_t **src = h->ref_list[list][refn].f.data;
int off= (mx << pixel_shift) + (my + (s->mb_x&3)*4)*h->mb_linesize + (64 << pixel_shift);
s->dsp.prefetch(src[0]+off, s->linesize, 4);
- if(chroma444){
+ if (chroma_idc == 3 /* yuv444 */) {
s->dsp.prefetch(src[1]+off, s->linesize, 4);
s->dsp.prefetch(src[2]+off, s->linesize, 4);
}else{
- off= ((mx>>1) << pixel_shift) + ((my>>1) + (s->mb_x&7))*s->uvlinesize + (64 << pixel_shift);
+ off= (((mx>>1)+64)<<pixel_shift) + ((my>>1) + (s->mb_x&7))*s->uvlinesize;
s->dsp.prefetch(src[1]+off, src[2]-src[1], 2);
}
}
@@ -681,45 +738,46 @@ static av_always_inline void hl_motion(H264Context *h, uint8_t *dest_y, uint8_t
qpel_mc_func (*qpix_put)[16], h264_chroma_mc_func (*chroma_put),
qpel_mc_func (*qpix_avg)[16], h264_chroma_mc_func (*chroma_avg),
h264_weight_func *weight_op, h264_biweight_func *weight_avg,
- int pixel_shift, int chroma444){
+ int pixel_shift, int chroma_idc)
+{
MpegEncContext * const s = &h->s;
const int mb_xy= h->mb_xy;
- const int mb_type= s->current_picture.mb_type[mb_xy];
+ const int mb_type = s->current_picture.f.mb_type[mb_xy];
assert(IS_INTER(mb_type));
- if(HAVE_PTHREADS && (s->avctx->active_thread_type & FF_THREAD_FRAME))
+ if(HAVE_THREADS && (s->avctx->active_thread_type & FF_THREAD_FRAME))
await_references(h);
- prefetch_motion(h, 0, pixel_shift, chroma444);
+ prefetch_motion(h, 0, pixel_shift, chroma_idc);
if(IS_16X16(mb_type)){
- mc_part(h, 0, 1, 8, 0, dest_y, dest_cb, dest_cr, 0, 0,
+ mc_part(h, 0, 1, 16, 0, dest_y, dest_cb, dest_cr, 0, 0,
qpix_put[0], chroma_put[0], qpix_avg[0], chroma_avg[0],
weight_op, weight_avg,
IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1),
- pixel_shift, chroma444);
+ pixel_shift, chroma_idc);
}else if(IS_16X8(mb_type)){
- mc_part(h, 0, 0, 4, 8 << pixel_shift, dest_y, dest_cb, dest_cr, 0, 0,
+ mc_part(h, 0, 0, 8, 8 << pixel_shift, dest_y, dest_cb, dest_cr, 0, 0,
qpix_put[1], chroma_put[0], qpix_avg[1], chroma_avg[0],
- &weight_op[1], &weight_avg[1],
+ weight_op, weight_avg,
IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1),
- pixel_shift, chroma444);
- mc_part(h, 8, 0, 4, 8 << pixel_shift, dest_y, dest_cb, dest_cr, 0, 4,
+ pixel_shift, chroma_idc);
+ mc_part(h, 8, 0, 8, 8 << pixel_shift, dest_y, dest_cb, dest_cr, 0, 4,
qpix_put[1], chroma_put[0], qpix_avg[1], chroma_avg[0],
- &weight_op[1], &weight_avg[1],
+ weight_op, weight_avg,
IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1),
- pixel_shift, chroma444);
+ pixel_shift, chroma_idc);
}else if(IS_8X16(mb_type)){
- mc_part(h, 0, 0, 8, 8*h->mb_linesize, dest_y, dest_cb, dest_cr, 0, 0,
+ mc_part(h, 0, 0, 16, 8*h->mb_linesize, dest_y, dest_cb, dest_cr, 0, 0,
qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1],
- &weight_op[2], &weight_avg[2],
+ &weight_op[1], &weight_avg[1],
IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1),
- pixel_shift, chroma444);
- mc_part(h, 4, 0, 8, 8*h->mb_linesize, dest_y, dest_cb, dest_cr, 4, 0,
+ pixel_shift, chroma_idc);
+ mc_part(h, 4, 0, 16, 8*h->mb_linesize, dest_y, dest_cb, dest_cr, 4, 0,
qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1],
- &weight_op[2], &weight_avg[2],
+ &weight_op[1], &weight_avg[1],
IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1),
- pixel_shift, chroma444);
+ pixel_shift, chroma_idc);
}else{
int i;
@@ -732,69 +790,73 @@ static av_always_inline void hl_motion(H264Context *h, uint8_t *dest_y, uint8_t
int y_offset= (i&2)<<1;
if(IS_SUB_8X8(sub_mb_type)){
- mc_part(h, n, 1, 4, 0, dest_y, dest_cb, dest_cr, x_offset, y_offset,
+ mc_part(h, n, 1, 8, 0, dest_y, dest_cb, dest_cr, x_offset, y_offset,
qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1],
- &weight_op[3], &weight_avg[3],
+ &weight_op[1], &weight_avg[1],
IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1),
- pixel_shift, chroma444);
+ pixel_shift, chroma_idc);
}else if(IS_SUB_8X4(sub_mb_type)){
- mc_part(h, n , 0, 2, 4 << pixel_shift, dest_y, dest_cb, dest_cr, x_offset, y_offset,
+ mc_part(h, n , 0, 4, 4 << pixel_shift, dest_y, dest_cb, dest_cr, x_offset, y_offset,
qpix_put[2], chroma_put[1], qpix_avg[2], chroma_avg[1],
- &weight_op[4], &weight_avg[4],
+ &weight_op[1], &weight_avg[1],
IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1),
- pixel_shift, chroma444);
- mc_part(h, n+2, 0, 2, 4 << pixel_shift, dest_y, dest_cb, dest_cr, x_offset, y_offset+2,
+ pixel_shift, chroma_idc);
+ mc_part(h, n+2, 0, 4, 4 << pixel_shift, dest_y, dest_cb, dest_cr, x_offset, y_offset+2,
qpix_put[2], chroma_put[1], qpix_avg[2], chroma_avg[1],
- &weight_op[4], &weight_avg[4],
+ &weight_op[1], &weight_avg[1],
IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1),
- pixel_shift, chroma444);
+ pixel_shift, chroma_idc);
}else if(IS_SUB_4X8(sub_mb_type)){
- mc_part(h, n , 0, 4, 4*h->mb_linesize, dest_y, dest_cb, dest_cr, x_offset, y_offset,
+ mc_part(h, n , 0, 8, 4*h->mb_linesize, dest_y, dest_cb, dest_cr, x_offset, y_offset,
qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2],
- &weight_op[5], &weight_avg[5],
+ &weight_op[2], &weight_avg[2],
IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1),
- pixel_shift, chroma444);
- mc_part(h, n+1, 0, 4, 4*h->mb_linesize, dest_y, dest_cb, dest_cr, x_offset+2, y_offset,
+ pixel_shift, chroma_idc);
+ mc_part(h, n+1, 0, 8, 4*h->mb_linesize, dest_y, dest_cb, dest_cr, x_offset+2, y_offset,
qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2],
- &weight_op[5], &weight_avg[5],
+ &weight_op[2], &weight_avg[2],
IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1),
- pixel_shift, chroma444);
+ pixel_shift, chroma_idc);
}else{
int j;
assert(IS_SUB_4X4(sub_mb_type));
for(j=0; j<4; j++){
int sub_x_offset= x_offset + 2*(j&1);
int sub_y_offset= y_offset + (j&2);
- mc_part(h, n+j, 1, 2, 0, dest_y, dest_cb, dest_cr, sub_x_offset, sub_y_offset,
+ mc_part(h, n+j, 1, 4, 0, dest_y, dest_cb, dest_cr, sub_x_offset, sub_y_offset,
qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2],
- &weight_op[6], &weight_avg[6],
+ &weight_op[2], &weight_avg[2],
IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1),
- pixel_shift, chroma444);
+ pixel_shift, chroma_idc);
}
}
}
}
- prefetch_motion(h, 1, pixel_shift, chroma444);
+ prefetch_motion(h, 1, pixel_shift, chroma_idc);
}
-#define hl_motion_fn(sh, bits) \
-static av_always_inline void hl_motion_ ## bits(H264Context *h, \
- uint8_t *dest_y, \
- uint8_t *dest_cb, uint8_t *dest_cr, \
- qpel_mc_func (*qpix_put)[16], \
- h264_chroma_mc_func (*chroma_put), \
- qpel_mc_func (*qpix_avg)[16], \
- h264_chroma_mc_func (*chroma_avg), \
- h264_weight_func *weight_op, \
- h264_biweight_func *weight_avg, \
- int chroma444) \
-{ \
- hl_motion(h, dest_y, dest_cb, dest_cr, qpix_put, chroma_put, \
- qpix_avg, chroma_avg, weight_op, weight_avg, sh, chroma444); \
+static av_always_inline void
+hl_motion_420(H264Context *h, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
+ qpel_mc_func (*qpix_put)[16], h264_chroma_mc_func (*chroma_put),
+ qpel_mc_func (*qpix_avg)[16], h264_chroma_mc_func (*chroma_avg),
+ h264_weight_func *weight_op, h264_biweight_func *weight_avg,
+ int pixel_shift)
+{
+ hl_motion(h, dest_y, dest_cb, dest_cr, qpix_put, chroma_put,
+ qpix_avg, chroma_avg, weight_op, weight_avg, pixel_shift, 1);
+}
+
+static av_always_inline void
+hl_motion_422(H264Context *h, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
+ qpel_mc_func (*qpix_put)[16], h264_chroma_mc_func (*chroma_put),
+ qpel_mc_func (*qpix_avg)[16], h264_chroma_mc_func (*chroma_avg),
+ h264_weight_func *weight_op, h264_biweight_func *weight_avg,
+ int pixel_shift)
+{
+ hl_motion(h, dest_y, dest_cb, dest_cr, qpix_put, chroma_put,
+ qpix_avg, chroma_avg, weight_op, weight_avg, pixel_shift, 2);
}
-hl_motion_fn(0, 8);
-hl_motion_fn(1, 16);
static void free_tables(H264Context *h, int free_rbsp){
int i;
@@ -960,7 +1022,7 @@ static void clone_tables(H264Context *dst, H264Context *src, int i){
dst->list_counts = src->list_counts;
dst->s.obmc_scratchpad = NULL;
- ff_h264_pred_init(&dst->hpc, src->s.codec_id, src->sps.bit_depth_luma);
+ ff_h264_pred_init(&dst->hpc, src->s.codec_id, src->sps.bit_depth_luma, src->sps.chroma_format_idc);
}
/**
@@ -988,30 +1050,39 @@ static av_cold void common_init(H264Context *h){
s->height = s->avctx->height;
s->codec_id= s->avctx->codec->id;
- ff_h264dsp_init(&h->h264dsp, 8);
- ff_h264_pred_init(&h->hpc, s->codec_id, 8);
+ s->avctx->bits_per_raw_sample = 8;
+ h->cur_chroma_format_idc = 1;
+
+ ff_h264dsp_init(&h->h264dsp,
+ s->avctx->bits_per_raw_sample, h->cur_chroma_format_idc);
+ ff_h264_pred_init(&h->hpc, s->codec_id,
+ s->avctx->bits_per_raw_sample, h->cur_chroma_format_idc);
h->dequant_coeff_pps= -1;
s->unrestricted_mv=1;
s->decode=1; //FIXME
+ s->dsp.dct_bits = 16;
dsputil_init(&s->dsp, s->avctx); // needed so that idct permutation is known early
memset(h->pps.scaling_matrix4, 16, 6*16*sizeof(uint8_t));
memset(h->pps.scaling_matrix8, 16, 2*64*sizeof(uint8_t));
}
-int ff_h264_decode_extradata(H264Context *h)
+int ff_h264_decode_extradata(H264Context *h, const uint8_t *buf, int size)
{
AVCodecContext *avctx = h->s.avctx;
- if(avctx->extradata[0] == 1){
+ if(!buf || size <= 0)
+ return -1;
+
+ if(buf[0] == 1){
int i, cnt, nalsize;
- unsigned char *p = avctx->extradata;
+ const unsigned char *p = buf;
h->is_avc = 1;
- if(avctx->extradata_size < 7) {
+ if(size < 7) {
av_log(avctx, AV_LOG_ERROR, "avcC too short\n");
return -1;
}
@@ -1023,6 +1094,8 @@ int ff_h264_decode_extradata(H264Context *h)
p += 6;
for (i = 0; i < cnt; i++) {
nalsize = AV_RB16(p) + 2;
+ if(nalsize > size - (p-buf))
+ return -1;
if(decode_nal_units(h, p, nalsize) < 0) {
av_log(avctx, AV_LOG_ERROR, "Decoding sps %d from avcC failed\n", i);
return -1;
@@ -1033,6 +1106,8 @@ int ff_h264_decode_extradata(H264Context *h)
cnt = *(p++); // Number of pps
for (i = 0; i < cnt; i++) {
nalsize = AV_RB16(p) + 2;
+ if(nalsize > size - (p-buf))
+ return -1;
if (decode_nal_units(h, p, nalsize) < 0) {
av_log(avctx, AV_LOG_ERROR, "Decoding pps %d from avcC failed\n", i);
return -1;
@@ -1040,10 +1115,10 @@ int ff_h264_decode_extradata(H264Context *h)
p += nalsize;
}
// Now store right nal length size, that will be use to parse all other nals
- h->nal_length_size = (avctx->extradata[4] & 0x03) + 1;
+ h->nal_length_size = (buf[4] & 0x03) + 1;
} else {
h->is_avc = 0;
- if(decode_nal_units(h, avctx->extradata, avctx->extradata_size) < 0)
+ if(decode_nal_units(h, buf, size) < 0)
return -1;
}
return 0;
@@ -1087,7 +1162,7 @@ av_cold int ff_h264_decode_init(AVCodecContext *avctx){
}
if(avctx->extradata_size > 0 && avctx->extradata &&
- ff_h264_decode_extradata(h))
+ ff_h264_decode_extradata(h, avctx->extradata, avctx->extradata_size))
return -1;
if(h->sps.bitstream_restriction_flag && s->avctx->has_b_frames < h->sps.num_reorder_frames){
@@ -1156,7 +1231,10 @@ static int decode_update_thread_context(AVCodecContext *dst, const AVCodecContex
memcpy(&h->s + 1, &h1->s + 1, sizeof(H264Context) - sizeof(MpegEncContext)); //copy all fields after MpegEnc
memset(h->sps_buffers, 0, sizeof(h->sps_buffers));
memset(h->pps_buffers, 0, sizeof(h->pps_buffers));
- ff_h264_alloc_tables(h);
+ if (ff_h264_alloc_tables(h) < 0) {
+ av_log(dst, AV_LOG_ERROR, "Could not allocate memory for h264\n");
+ return AVERROR(ENOMEM);
+ }
context_init(h);
for(i=0; i<2; i++){
@@ -1208,11 +1286,12 @@ static int decode_update_thread_context(AVCodecContext *dst, const AVCodecContex
copy_picture_range(h->delayed_pic, h1->delayed_pic, MAX_DELAYED_PIC_COUNT+2, s, s1);
h->last_slice_type = h1->last_slice_type;
+ h->sync = h1->sync;
if(!s->current_picture_ptr) return 0;
if(!s->dropable) {
- ff_h264_execute_ref_pic_marking(h, h->mmco, h->mmco_index);
+ err = ff_h264_execute_ref_pic_marking(h, h->mmco, h->mmco_index);
h->prev_poc_msb = h->poc_msb;
h->prev_poc_lsb = h->poc_lsb;
}
@@ -1220,7 +1299,7 @@ static int decode_update_thread_context(AVCodecContext *dst, const AVCodecContex
h->prev_frame_num = h->frame_num;
h->outputed_poc = h->next_outputed_poc;
- return 0;
+ return err;
}
int ff_h264_frame_start(H264Context *h){
@@ -1238,7 +1317,7 @@ int ff_h264_frame_start(H264Context *h){
* Zero here; IDR markings per slice in frame or fields are ORed in later.
* See decode_nal_units().
*/
- s->current_picture_ptr->key_frame= 0;
+ s->current_picture_ptr->f.key_frame = 0;
s->current_picture_ptr->mmco_reset= 0;
assert(s->linesize && s->uvlinesize);
@@ -1263,7 +1342,7 @@ int ff_h264_frame_start(H264Context *h){
/* some macroblocks can be accessed before they're available in case of lost slices, mbaff or threading*/
memset(h->slice_table, -1, (s->mb_height*s->mb_stride-1) * sizeof(*h->slice_table));
-// s->decode= (s->flags&CODEC_FLAG_PSNR) || !s->encoding || s->current_picture.reference /*|| h->contains_intra*/ || 1;
+// s->decode = (s->flags & CODEC_FLAG_PSNR) || !s->encoding || s->current_picture.f.reference /*|| h->contains_intra*/ || 1;
// We mark the current picture as non-reference after allocating it, so
// that if we break out due to an error it can be released automatically
@@ -1272,7 +1351,7 @@ int ff_h264_frame_start(H264Context *h){
// get released even with set reference, besides SVQ3 and others do not
// mark frames as reference later "naturally".
if(s->codec_id != CODEC_ID_SVQ3)
- s->current_picture_ptr->reference= 0;
+ s->current_picture_ptr->f.reference = 0;
s->current_picture_ptr->field_poc[0]=
s->current_picture_ptr->field_poc[1]= INT_MAX;
@@ -1298,8 +1377,8 @@ static void decode_postinit(H264Context *h, int setup_finished){
Picture *cur = s->current_picture_ptr;
int i, pics, out_of_order, out_idx;
- s->current_picture_ptr->qscale_type= FF_QSCALE_TYPE_H264;
- s->current_picture_ptr->pict_type= s->pict_type;
+ s->current_picture_ptr->f.qscale_type = FF_QSCALE_TYPE_H264;
+ s->current_picture_ptr->f.pict_type = s->pict_type;
if (h->next_output_pic) return;
@@ -1312,8 +1391,8 @@ static void decode_postinit(H264Context *h, int setup_finished){
return;
}
- cur->interlaced_frame = 0;
- cur->repeat_pict = 0;
+ cur->f.interlaced_frame = 0;
+ cur->f.repeat_pict = 0;
/* Signal interlacing information externally. */
/* Prioritize picture timing SEI information over used decoding process if it exists. */
@@ -1325,53 +1404,53 @@ static void decode_postinit(H264Context *h, int setup_finished){
break;
case SEI_PIC_STRUCT_TOP_FIELD:
case SEI_PIC_STRUCT_BOTTOM_FIELD:
- cur->interlaced_frame = 1;
+ cur->f.interlaced_frame = 1;
break;
case SEI_PIC_STRUCT_TOP_BOTTOM:
case SEI_PIC_STRUCT_BOTTOM_TOP:
if (FIELD_OR_MBAFF_PICTURE)
- cur->interlaced_frame = 1;
+ cur->f.interlaced_frame = 1;
else
// try to flag soft telecine progressive
- cur->interlaced_frame = h->prev_interlaced_frame;
+ cur->f.interlaced_frame = h->prev_interlaced_frame;
break;
case SEI_PIC_STRUCT_TOP_BOTTOM_TOP:
case SEI_PIC_STRUCT_BOTTOM_TOP_BOTTOM:
// Signal the possibility of telecined film externally (pic_struct 5,6)
// From these hints, let the applications decide if they apply deinterlacing.
- cur->repeat_pict = 1;
+ cur->f.repeat_pict = 1;
break;
case SEI_PIC_STRUCT_FRAME_DOUBLING:
// Force progressive here, as doubling interlaced frame is a bad idea.
- cur->repeat_pict = 2;
+ cur->f.repeat_pict = 2;
break;
case SEI_PIC_STRUCT_FRAME_TRIPLING:
- cur->repeat_pict = 4;
+ cur->f.repeat_pict = 4;
break;
}
if ((h->sei_ct_type & 3) && h->sei_pic_struct <= SEI_PIC_STRUCT_BOTTOM_TOP)
- cur->interlaced_frame = (h->sei_ct_type & (1<<1)) != 0;
+ cur->f.interlaced_frame = (h->sei_ct_type & (1 << 1)) != 0;
}else{
/* Derive interlacing flag from used decoding process. */
- cur->interlaced_frame = FIELD_OR_MBAFF_PICTURE;
+ cur->f.interlaced_frame = FIELD_OR_MBAFF_PICTURE;
}
- h->prev_interlaced_frame = cur->interlaced_frame;
+ h->prev_interlaced_frame = cur->f.interlaced_frame;
if (cur->field_poc[0] != cur->field_poc[1]){
/* Derive top_field_first from field pocs. */
- cur->top_field_first = cur->field_poc[0] < cur->field_poc[1];
+ cur->f.top_field_first = cur->field_poc[0] < cur->field_poc[1];
}else{
- if(cur->interlaced_frame || h->sps.pic_struct_present_flag){
+ if (cur->f.interlaced_frame || h->sps.pic_struct_present_flag) {
/* Use picture timing SEI information. Even if it is a information of a past frame, better than nothing. */
if(h->sei_pic_struct == SEI_PIC_STRUCT_TOP_BOTTOM
|| h->sei_pic_struct == SEI_PIC_STRUCT_TOP_BOTTOM_TOP)
- cur->top_field_first = 1;
+ cur->f.top_field_first = 1;
else
- cur->top_field_first = 0;
+ cur->f.top_field_first = 0;
}else{
/* Most likely progressive */
- cur->top_field_first = 0;
+ cur->f.top_field_first = 0;
}
}
@@ -1394,20 +1473,20 @@ static void decode_postinit(H264Context *h, int setup_finished){
pics = 0;
while(h->delayed_pic[pics]) pics++;
- assert(pics <= MAX_DELAYED_PIC_COUNT);
+ av_assert0(pics <= MAX_DELAYED_PIC_COUNT);
h->delayed_pic[pics++] = cur;
- if(cur->reference == 0)
- cur->reference = DELAYED_PIC_REF;
+ if (cur->f.reference == 0)
+ cur->f.reference = DELAYED_PIC_REF;
out = h->delayed_pic[0];
out_idx = 0;
- for(i=1; h->delayed_pic[i] && !h->delayed_pic[i]->key_frame && !h->delayed_pic[i]->mmco_reset; i++)
+ for (i = 1; h->delayed_pic[i] && !h->delayed_pic[i]->f.key_frame && !h->delayed_pic[i]->mmco_reset; i++)
if(h->delayed_pic[i]->poc < out->poc){
out = h->delayed_pic[i];
out_idx = i;
}
- if(s->avctx->has_b_frames == 0 && (h->delayed_pic[0]->key_frame || h->delayed_pic[0]->mmco_reset))
+ if (s->avctx->has_b_frames == 0 && (h->delayed_pic[0]->f.key_frame || h->delayed_pic[0]->mmco_reset))
h->next_outputed_poc= INT_MIN;
out_of_order = out->poc < h->next_outputed_poc;
@@ -1416,14 +1495,14 @@ static void decode_postinit(H264Context *h, int setup_finished){
else if((out_of_order && pics-1 == s->avctx->has_b_frames && s->avctx->has_b_frames < MAX_DELAYED_PIC_COUNT)
|| (s->low_delay &&
((h->next_outputed_poc != INT_MIN && out->poc > h->next_outputed_poc + 2)
- || cur->pict_type == AV_PICTURE_TYPE_B)))
+ || cur->f.pict_type == AV_PICTURE_TYPE_B)))
{
s->low_delay = 0;
s->avctx->has_b_frames++;
}
if(out_of_order || pics > s->avctx->has_b_frames){
- out->reference &= ~DELAYED_PIC_REF;
+ out->f.reference &= ~DELAYED_PIC_REF;
out->owner2 = s; // for frame threading, the owner must be the second field's thread
// or else the first thread can release the picture and reuse it unsafely
for(i=out_idx; h->delayed_pic[i]; i++)
@@ -1431,7 +1510,7 @@ static void decode_postinit(H264Context *h, int setup_finished){
}
if(!out_of_order && pics > s->avctx->has_b_frames){
h->next_output_pic = out;
- if(out_idx==0 && h->delayed_pic[0] && (h->delayed_pic[0]->key_frame || h->delayed_pic[0]->mmco_reset)) {
+ if (out_idx == 0 && h->delayed_pic[0] && (h->delayed_pic[0]->f.key_frame || h->delayed_pic[0]->mmco_reset)) {
h->next_outputed_poc = INT_MIN;
} else
h->next_outputed_poc = out->poc;
@@ -1439,15 +1518,24 @@ static void decode_postinit(H264Context *h, int setup_finished){
av_log(s->avctx, AV_LOG_DEBUG, "no picture\n");
}
+ if (h->next_output_pic && h->next_output_pic->sync) {
+ h->sync |= 2;
+ }
+
if (setup_finished)
ff_thread_finish_setup(s->avctx);
}
-static inline void backup_mb_border(H264Context *h, uint8_t *src_y, uint8_t *src_cb, uint8_t *src_cr, int linesize, int uvlinesize, int chroma444, int simple){
+static av_always_inline void backup_mb_border(H264Context *h, uint8_t *src_y,
+ uint8_t *src_cb, uint8_t *src_cr,
+ int linesize, int uvlinesize, int simple)
+{
MpegEncContext * const s = &h->s;
uint8_t *top_border;
int top_idx = 1;
const int pixel_shift = h->pixel_shift;
+ int chroma444 = CHROMA444;
+ int chroma422 = CHROMA422;
src_y -= linesize;
src_cb -= uvlinesize;
@@ -1471,6 +1559,14 @@ static inline void backup_mb_border(H264Context *h, uint8_t *src_y, uint8_t *src
AV_COPY128(top_border+16, src_cb + 15*uvlinesize);
AV_COPY128(top_border+32, src_cr + 15*uvlinesize);
}
+ } else if(chroma422){
+ if (pixel_shift) {
+ AV_COPY128(top_border+32, src_cb + 15*uvlinesize);
+ AV_COPY128(top_border+48, src_cr + 15*uvlinesize);
+ } else {
+ AV_COPY64(top_border+16, src_cb + 15*uvlinesize);
+ AV_COPY64(top_border+24, src_cr + 15*uvlinesize);
+ }
} else {
if (pixel_shift) {
AV_COPY128(top_border+32, src_cb+7*uvlinesize);
@@ -1506,6 +1602,14 @@ static inline void backup_mb_border(H264Context *h, uint8_t *src_y, uint8_t *src
AV_COPY128(top_border+16, src_cb + 16*linesize);
AV_COPY128(top_border+32, src_cr + 16*linesize);
}
+ } else if(chroma422) {
+ if (pixel_shift) {
+ AV_COPY128(top_border+32, src_cb+16*uvlinesize);
+ AV_COPY128(top_border+48, src_cr+16*uvlinesize);
+ } else {
+ AV_COPY64(top_border+16, src_cb+16*uvlinesize);
+ AV_COPY64(top_border+24, src_cr+16*uvlinesize);
+ }
} else {
if (pixel_shift) {
AV_COPY128(top_border+32, src_cb+8*uvlinesize);
@@ -1518,7 +1622,7 @@ static inline void backup_mb_border(H264Context *h, uint8_t *src_y, uint8_t *src
}
}
-static inline void xchg_mb_border(H264Context *h, uint8_t *src_y,
+static av_always_inline void xchg_mb_border(H264Context *h, uint8_t *src_y,
uint8_t *src_cb, uint8_t *src_cr,
int linesize, int uvlinesize,
int xchg, int chroma444,
@@ -1679,7 +1783,7 @@ static av_always_inline void hl_decode_mb_predict_luma(H264Context *h, int mb_ty
tr_high= ((uint16_t*)ptr)[3 - linesize/2]*0x0001000100010001ULL;
topright= (uint8_t*) &tr_high;
} else {
- tr= ptr[3 - linesize]*0x01010101;
+ tr= ptr[3 - linesize]*0x01010101u;
topright= (uint8_t*) &tr;
}
}else
@@ -1770,12 +1874,13 @@ static av_always_inline void hl_decode_mb_idct_luma(H264Context *h, int mb_type,
}
}
-static av_always_inline void hl_decode_mb_internal(H264Context *h, int simple, int pixel_shift){
+static av_always_inline void hl_decode_mb_internal(H264Context *h, int simple, int pixel_shift)
+{
MpegEncContext * const s = &h->s;
const int mb_x= s->mb_x;
const int mb_y= s->mb_y;
const int mb_xy= h->mb_xy;
- const int mb_type= s->current_picture.mb_type[mb_xy];
+ const int mb_type = s->current_picture.f.mb_type[mb_xy];
uint8_t *dest_y, *dest_cb, *dest_cr;
int linesize, uvlinesize /*dct_offset*/;
int i, j;
@@ -1784,10 +1889,12 @@ static av_always_inline void hl_decode_mb_internal(H264Context *h, int simple, i
/* is_h264 should always be true if SVQ3 is disabled. */
const int is_h264 = !CONFIG_SVQ3_DECODER || simple || s->codec_id == CODEC_ID_H264;
void (*idct_add)(uint8_t *dst, DCTELEM *block, int stride);
+ const int block_h = 16 >> s->chroma_y_shift;
+ const int chroma422 = CHROMA422;
- dest_y = s->current_picture.data[0] + ((mb_x << pixel_shift) + mb_y * s->linesize ) * 16;
- dest_cb = s->current_picture.data[1] + ((mb_x << pixel_shift) + mb_y * s->uvlinesize) * 8;
- dest_cr = s->current_picture.data[2] + ((mb_x << pixel_shift) + mb_y * s->uvlinesize) * 8;
+ dest_y = s->current_picture.f.data[0] + ((mb_x << pixel_shift) + mb_y * s->linesize ) * 16;
+ dest_cb = s->current_picture.f.data[1] + (mb_x << pixel_shift)*8 + mb_y * s->uvlinesize * block_h;
+ dest_cr = s->current_picture.f.data[2] + (mb_x << pixel_shift)*8 + mb_y * s->uvlinesize * block_h;
s->dsp.prefetch(dest_y + (s->mb_x&3)*4*s->linesize + (64 << pixel_shift), s->linesize, 4);
s->dsp.prefetch(dest_cb + (s->mb_x&7)*s->uvlinesize + (64 << pixel_shift), dest_cr - dest_cb, 2);
@@ -1800,8 +1907,8 @@ static av_always_inline void hl_decode_mb_internal(H264Context *h, int simple, i
block_offset = &h->block_offset[48];
if(mb_y&1){ //FIXME move out of this function?
dest_y -= s->linesize*15;
- dest_cb-= s->uvlinesize*7;
- dest_cr-= s->uvlinesize*7;
+ dest_cb-= s->uvlinesize * (block_h - 1);
+ dest_cr-= s->uvlinesize * (block_h - 1);
}
if(FRAME_MBAFF) {
int list;
@@ -1827,8 +1934,8 @@ static av_always_inline void hl_decode_mb_internal(H264Context *h, int simple, i
}
if (!simple && IS_INTRA_PCM(mb_type)) {
+ const int bit_depth = h->sps.bit_depth_luma;
if (pixel_shift) {
- const int bit_depth = h->sps.bit_depth_luma;
int j;
GetBitContext gb;
init_get_bits(&gb, (uint8_t*)h->mb, 384*bit_depth);
@@ -1839,15 +1946,25 @@ static av_always_inline void hl_decode_mb_internal(H264Context *h, int simple, i
tmp_y[j] = get_bits(&gb, bit_depth);
}
if(simple || !CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
- for (i = 0; i < 8; i++) {
- uint16_t *tmp_cb = (uint16_t*)(dest_cb + i*uvlinesize);
- for (j = 0; j < 8; j++)
- tmp_cb[j] = get_bits(&gb, bit_depth);
- }
- for (i = 0; i < 8; i++) {
- uint16_t *tmp_cr = (uint16_t*)(dest_cr + i*uvlinesize);
- for (j = 0; j < 8; j++)
- tmp_cr[j] = get_bits(&gb, bit_depth);
+ if (!h->sps.chroma_format_idc) {
+ for (i = 0; i < block_h; i++) {
+ uint16_t *tmp_cb = (uint16_t*)(dest_cb + i*uvlinesize);
+ uint16_t *tmp_cr = (uint16_t*)(dest_cr + i*uvlinesize);
+ for (j = 0; j < 8; j++) {
+ tmp_cb[j] = tmp_cr[j] = 1 << (bit_depth - 1);
+ }
+ }
+ } else {
+ for (i = 0; i < block_h; i++) {
+ uint16_t *tmp_cb = (uint16_t*)(dest_cb + i*uvlinesize);
+ for (j = 0; j < 8; j++)
+ tmp_cb[j] = get_bits(&gb, bit_depth);
+ }
+ for (i = 0; i < block_h; i++) {
+ uint16_t *tmp_cr = (uint16_t*)(dest_cr + i*uvlinesize);
+ for (j = 0; j < 8; j++)
+ tmp_cr[j] = get_bits(&gb, bit_depth);
+ }
}
}
} else {
@@ -1855,9 +1972,16 @@ static av_always_inline void hl_decode_mb_internal(H264Context *h, int simple, i
memcpy(dest_y + i* linesize, h->mb + i*8, 16);
}
if(simple || !CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
- for (i=0; i<8; i++) {
- memcpy(dest_cb+ i*uvlinesize, h->mb + 128 + i*4, 8);
- memcpy(dest_cr+ i*uvlinesize, h->mb + 160 + i*4, 8);
+ if (!h->sps.chroma_format_idc) {
+ for (i=0; i<8; i++) {
+ memset(dest_cb + i*uvlinesize, 1 << (bit_depth - 1), 8);
+ memset(dest_cr + i*uvlinesize, 1 << (bit_depth - 1), 8);
+ }
+ } else {
+ for (i=0; i<block_h; i++) {
+ memcpy(dest_cb + i*uvlinesize, h->mb + 128 + i*4, 8);
+ memcpy(dest_cr + i*uvlinesize, h->mb + 160 + i*4, 8);
+ }
}
}
}
@@ -1876,18 +2000,21 @@ static av_always_inline void hl_decode_mb_internal(H264Context *h, int simple, i
if(h->deblocking_filter)
xchg_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize, 0, 0, simple, pixel_shift);
}else if(is_h264){
- if (pixel_shift) {
- hl_motion_16(h, dest_y, dest_cb, dest_cr,
- s->me.qpel_put, s->dsp.put_h264_chroma_pixels_tab,
- s->me.qpel_avg, s->dsp.avg_h264_chroma_pixels_tab,
- h->h264dsp.weight_h264_pixels_tab,
- h->h264dsp.biweight_h264_pixels_tab, 0);
- } else
- hl_motion_8(h, dest_y, dest_cb, dest_cr,
- s->me.qpel_put, s->dsp.put_h264_chroma_pixels_tab,
- s->me.qpel_avg, s->dsp.avg_h264_chroma_pixels_tab,
- h->h264dsp.weight_h264_pixels_tab,
- h->h264dsp.biweight_h264_pixels_tab, 0);
+ if (chroma422) {
+ hl_motion_422(h, dest_y, dest_cb, dest_cr,
+ s->me.qpel_put, s->dsp.put_h264_chroma_pixels_tab,
+ s->me.qpel_avg, s->dsp.avg_h264_chroma_pixels_tab,
+ h->h264dsp.weight_h264_pixels_tab,
+ h->h264dsp.biweight_h264_pixels_tab,
+ pixel_shift);
+ } else {
+ hl_motion_420(h, dest_y, dest_cb, dest_cr,
+ s->me.qpel_put, s->dsp.put_h264_chroma_pixels_tab,
+ s->me.qpel_avg, s->dsp.avg_h264_chroma_pixels_tab,
+ h->h264dsp.weight_h264_pixels_tab,
+ h->h264dsp.biweight_h264_pixels_tab,
+ pixel_shift);
+ }
}
hl_decode_mb_idct_luma(h, mb_type, is_h264, simple, transform_bypass, pixel_shift, block_offset, linesize, dest_y, 0);
@@ -1905,18 +2032,34 @@ static av_always_inline void hl_decode_mb_internal(H264Context *h, int simple, i
if(h->non_zero_count_cache[ scan8[i] ] || dctcoef_get(h->mb, pixel_shift, i*16))
idct_add (dest[j-1] + block_offset[i], h->mb + (i*16 << pixel_shift), uvlinesize);
}
+ if (chroma422) {
+ for(i=j*16+4; i<j*16+8; i++){
+ if(h->non_zero_count_cache[ scan8[i] ] || dctcoef_get(h->mb, pixel_shift, i*16))
+ idct_add (dest[j-1] + block_offset[i+4], h->mb + (i*16 << pixel_shift), uvlinesize);
+ }
+ }
}
}
}else{
if(is_h264){
+ int qp[2];
+ if (chroma422) {
+ qp[0] = h->chroma_qp[0] + 3;
+ qp[1] = h->chroma_qp[1] + 3;
+ } else {
+ qp[0] = h->chroma_qp[0];
+ qp[1] = h->chroma_qp[1];
+ }
if(h->non_zero_count_cache[ scan8[CHROMA_DC_BLOCK_INDEX+0] ])
- h->h264dsp.h264_chroma_dc_dequant_idct(h->mb + (16*16*1 << pixel_shift), h->dequant4_coeff[IS_INTRA(mb_type) ? 1:4][h->chroma_qp[0]][0]);
+ h->h264dsp.h264_chroma_dc_dequant_idct(h->mb + (16*16*1 << pixel_shift), h->dequant4_coeff[IS_INTRA(mb_type) ? 1:4][qp[0]][0]);
if(h->non_zero_count_cache[ scan8[CHROMA_DC_BLOCK_INDEX+1] ])
- h->h264dsp.h264_chroma_dc_dequant_idct(h->mb + (16*16*2 << pixel_shift), h->dequant4_coeff[IS_INTRA(mb_type) ? 2:5][h->chroma_qp[1]][0]);
+ h->h264dsp.h264_chroma_dc_dequant_idct(h->mb + (16*16*2 << pixel_shift), h->dequant4_coeff[IS_INTRA(mb_type) ? 2:5][qp[1]][0]);
h->h264dsp.h264_idct_add8(dest, block_offset,
h->mb, uvlinesize,
h->non_zero_count_cache);
- }else{
+ }
+#if CONFIG_SVQ3_DECODER
+ else{
h->h264dsp.h264_chroma_dc_dequant_idct(h->mb + 16*16*1, h->dequant4_coeff[IS_INTRA(mb_type) ? 1:4][h->chroma_qp[0]][0]);
h->h264dsp.h264_chroma_dc_dequant_idct(h->mb + 16*16*2, h->dequant4_coeff[IS_INTRA(mb_type) ? 2:5][h->chroma_qp[1]][0]);
for(j=1; j<3; j++){
@@ -1928,6 +2071,7 @@ static av_always_inline void hl_decode_mb_internal(H264Context *h, int simple, i
}
}
}
+#endif
}
}
}
@@ -1943,7 +2087,7 @@ static av_always_inline void hl_decode_mb_444_internal(H264Context *h, int simpl
const int mb_x= s->mb_x;
const int mb_y= s->mb_y;
const int mb_xy= h->mb_xy;
- const int mb_type= s->current_picture.mb_type[mb_xy];
+ const int mb_type = s->current_picture.f.mb_type[mb_xy];
uint8_t *dest[3];
int linesize;
int i, j, p;
@@ -1953,7 +2097,7 @@ static av_always_inline void hl_decode_mb_444_internal(H264Context *h, int simpl
for (p = 0; p < plane_count; p++)
{
- dest[p] = s->current_picture.data[p] + ((mb_x << pixel_shift) + mb_y * s->linesize) * 16;
+ dest[p] = s->current_picture.f.data[p] + ((mb_x << pixel_shift) + mb_y * s->linesize) * 16;
s->dsp.prefetch(dest[p] + (s->mb_x&3)*4*s->linesize + (64 << pixel_shift), s->linesize, 4);
}
@@ -2017,18 +2161,11 @@ static av_always_inline void hl_decode_mb_444_internal(H264Context *h, int simpl
if(h->deblocking_filter)
xchg_mb_border(h, dest[0], dest[1], dest[2], linesize, linesize, 0, 1, simple, pixel_shift);
}else{
- if (pixel_shift) {
- hl_motion_16(h, dest[0], dest[1], dest[2],
- s->me.qpel_put, s->dsp.put_h264_chroma_pixels_tab,
- s->me.qpel_avg, s->dsp.avg_h264_chroma_pixels_tab,
- h->h264dsp.weight_h264_pixels_tab,
- h->h264dsp.biweight_h264_pixels_tab, 1);
- } else
- hl_motion_8(h, dest[0], dest[1], dest[2],
- s->me.qpel_put, s->dsp.put_h264_chroma_pixels_tab,
- s->me.qpel_avg, s->dsp.avg_h264_chroma_pixels_tab,
- h->h264dsp.weight_h264_pixels_tab,
- h->h264dsp.biweight_h264_pixels_tab, 1);
+ hl_motion(h, dest[0], dest[1], dest[2],
+ s->me.qpel_put, s->dsp.put_h264_chroma_pixels_tab,
+ s->me.qpel_avg, s->dsp.avg_h264_chroma_pixels_tab,
+ h->h264dsp.weight_h264_pixels_tab,
+ h->h264dsp.biweight_h264_pixels_tab, pixel_shift, 3);
}
for (p = 0; p < plane_count; p++)
@@ -2069,7 +2206,7 @@ static void av_noinline hl_decode_mb_444_simple(H264Context *h){
void ff_h264_hl_decode_mb(H264Context *h){
MpegEncContext * const s = &h->s;
const int mb_xy= h->mb_xy;
- const int mb_type= s->current_picture.mb_type[mb_xy];
+ const int mb_type = s->current_picture.f.mb_type[mb_xy];
int is_complex = CONFIG_SMALL || h->is_complex || IS_INTRA_PCM(mb_type) || s->qscale == 0;
if (CHROMA444) {
@@ -2161,7 +2298,11 @@ static void implicit_weight_table(H264Context *h, int field){
}
if(field < 0){
- cur_poc = s->current_picture_ptr->poc;
+ if (s->picture_structure == PICT_FRAME) {
+ cur_poc = s->current_picture_ptr->poc;
+ } else {
+ cur_poc = s->current_picture_ptr->field_poc[s->picture_structure - 1];
+ }
if( h->ref_count[0] == 1 && h->ref_count[1] == 1 && !FRAME_MBAFF
&& h->ref_list[0][0].poc + h->ref_list[1][0].poc == 2*cur_poc){
h->use_weight= 0;
@@ -2186,15 +2327,17 @@ static void implicit_weight_table(H264Context *h, int field){
for(ref0=ref_start; ref0 < ref_count0; ref0++){
int poc0 = h->ref_list[0][ref0].poc;
for(ref1=ref_start; ref1 < ref_count1; ref1++){
- int poc1 = h->ref_list[1][ref1].poc;
- int td = av_clip(poc1 - poc0, -128, 127);
- int w= 32;
- if(td){
- int tb = av_clip(cur_poc - poc0, -128, 127);
- int tx = (16384 + (FFABS(td) >> 1)) / td;
- int dist_scale_factor = (tb*tx + 32) >> 8;
- if(dist_scale_factor >= -64 && dist_scale_factor <= 128)
- w = 64 - dist_scale_factor;
+ int w = 32;
+ if (!h->ref_list[0][ref0].long_ref && !h->ref_list[1][ref1].long_ref) {
+ int poc1 = h->ref_list[1][ref1].poc;
+ int td = av_clip(poc1 - poc0, -128, 127);
+ if(td){
+ int tb = av_clip(cur_poc - poc0, -128, 127);
+ int tx = (16384 + (FFABS(td) >> 1)) / td;
+ int dist_scale_factor = (tb*tx + 32) >> 8;
+ if(dist_scale_factor >= -64 && dist_scale_factor <= 128)
+ w = 64 - dist_scale_factor;
+ }
}
if(field<0){
h->implicit_weight[ref0][ref1][0]=
@@ -2221,19 +2364,21 @@ static void idr(H264Context *h){
static void flush_dpb(AVCodecContext *avctx){
H264Context *h= avctx->priv_data;
int i;
- for(i=0; i<MAX_DELAYED_PIC_COUNT; i++) {
+ for(i=0; i<=MAX_DELAYED_PIC_COUNT; i++) {
if(h->delayed_pic[i])
- h->delayed_pic[i]->reference= 0;
+ h->delayed_pic[i]->f.reference = 0;
h->delayed_pic[i]= NULL;
}
h->outputed_poc=h->next_outputed_poc= INT_MIN;
h->prev_interlaced_frame = 1;
idr(h);
if(h->s.current_picture_ptr)
- h->s.current_picture_ptr->reference= 0;
+ h->s.current_picture_ptr->f.reference = 0;
h->s.first_field= 0;
ff_h264_reset_sei(h);
ff_mpeg_flush(avctx);
+ h->recovery_frame= -1;
+ h->sync= 0;
}
static int init_poc(H264Context *h){
@@ -2350,9 +2495,10 @@ static void init_scan_tables(H264Context *h){
}
}
-static void field_end(H264Context *h, int in_setup){
+static int field_end(H264Context *h, int in_setup){
MpegEncContext * const s = &h->s;
AVCodecContext * const avctx= s->avctx;
+ int err = 0;
s->mb_y= 0;
if (!in_setup && !s->dropable)
@@ -2364,7 +2510,7 @@ static void field_end(H264Context *h, int in_setup){
if(in_setup || !(avctx->active_thread_type&FF_THREAD_FRAME)){
if(!s->dropable) {
- ff_h264_execute_ref_pic_marking(h, h->mmco, h->mmco_index);
+ err = ff_h264_execute_ref_pic_marking(h, h->mmco, h->mmco_index);
h->prev_poc_msb= h->poc_msb;
h->prev_poc_lsb= h->poc_lsb;
}
@@ -2399,6 +2545,8 @@ static void field_end(H264Context *h, int in_setup){
MPV_frame_end(s);
h->current_slice=0;
+
+ return err;
}
/**
@@ -2549,22 +2697,27 @@ static int decode_slice_header(H264Context *h, H264Context *h0){
h->b_stride= s->mb_width*4;
+ s->chroma_y_shift = h->sps.chroma_format_idc <= 1; // 400 uses yuv420p
+
s->width = 16*s->mb_width - (2>>CHROMA444)*FFMIN(h->sps.crop_right, (8<<CHROMA444)-1);
if(h->sps.frame_mbs_only_flag)
- s->height= 16*s->mb_height - (2>>CHROMA444)*FFMIN(h->sps.crop_bottom, (8<<CHROMA444)-1);
+ s->height= 16*s->mb_height - (1<<s->chroma_y_shift)*FFMIN(h->sps.crop_bottom, (16>>s->chroma_y_shift)-1);
else
- s->height= 16*s->mb_height - (4>>CHROMA444)*FFMIN(h->sps.crop_bottom, (8<<CHROMA444)-1);
+ s->height= 16*s->mb_height - (2<<s->chroma_y_shift)*FFMIN(h->sps.crop_bottom, (16>>s->chroma_y_shift)-1);
if (s->context_initialized
&& ( s->width != s->avctx->width || s->height != s->avctx->height
+ || s->avctx->bits_per_raw_sample != h->sps.bit_depth_luma
+ || h->cur_chroma_format_idc != h->sps.chroma_format_idc
|| av_cmp_q(h->sps.sar, s->avctx->sample_aspect_ratio))) {
if(h != h0) {
- av_log_missing_feature(s->avctx, "Width/height changing with threads is", 0);
+ av_log_missing_feature(s->avctx, "Width/height/bit depth/chroma idc changing with threads is", 0);
return -1; // width / height changed during parallelized decoding
}
free_tables(h, 0);
flush_dpb(s->avctx);
MPV_common_end(s);
+ h->list_count = 0;
}
if (!s->context_initialized) {
if (h != h0) {
@@ -2576,11 +2729,27 @@ static int decode_slice_header(H264Context *h, H264Context *h0){
s->avctx->sample_aspect_ratio= h->sps.sar;
av_assert0(s->avctx->sample_aspect_ratio.den);
- h->s.avctx->coded_width = 16*s->mb_width;
- h->s.avctx->coded_height = 16*s->mb_height;
+ if (s->avctx->bits_per_raw_sample != h->sps.bit_depth_luma ||
+ h->cur_chroma_format_idc != h->sps.chroma_format_idc) {
+ if (h->sps.bit_depth_luma >= 8 && h->sps.bit_depth_luma <= 10 &&
+ (h->sps.bit_depth_luma != 9 || !CHROMA422)) {
+ s->avctx->bits_per_raw_sample = h->sps.bit_depth_luma;
+ h->cur_chroma_format_idc = h->sps.chroma_format_idc;
+ h->pixel_shift = h->sps.bit_depth_luma > 8;
+
+ ff_h264dsp_init(&h->h264dsp, h->sps.bit_depth_luma, h->sps.chroma_format_idc);
+ ff_h264_pred_init(&h->hpc, s->codec_id, h->sps.bit_depth_luma, h->sps.chroma_format_idc);
+ s->dsp.dct_bits = h->sps.bit_depth_luma > 8 ? 32 : 16;
+ dsputil_init(&s->dsp, s->avctx);
+ } else {
+ av_log(s->avctx, AV_LOG_DEBUG, "Unsupported bit depth: %d chroma_idc: %d\n",
+ h->sps.bit_depth_luma, h->sps.chroma_format_idc);
+ return -1;
+ }
+ }
if(h->sps.video_signal_type_present_flag){
- s->avctx->color_range = h->sps.full_range ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG;
+ s->avctx->color_range = h->sps.full_range>0 ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG;
if(h->sps.colour_description_present_flag){
s->avctx->color_primaries = h->sps.color_primaries;
s->avctx->color_trc = h->sps.color_trc;
@@ -2598,14 +2767,30 @@ static int decode_slice_header(H264Context *h, H264Context *h0){
switch (h->sps.bit_depth_luma) {
case 9 :
- s->avctx->pix_fmt = CHROMA444 ? PIX_FMT_YUV444P9 : PIX_FMT_YUV420P9;
+ if (CHROMA444)
+ s->avctx->pix_fmt = PIX_FMT_YUV444P9;
+ else if (CHROMA422)
+ s->avctx->pix_fmt = PIX_FMT_YUV422P9;
+ else
+ s->avctx->pix_fmt = PIX_FMT_YUV420P9;
break;
case 10 :
- s->avctx->pix_fmt = CHROMA444 ? PIX_FMT_YUV444P10 : PIX_FMT_YUV420P10;
+ if (CHROMA444)
+ s->avctx->pix_fmt = PIX_FMT_YUV444P10;
+ else if (CHROMA422)
+ s->avctx->pix_fmt = PIX_FMT_YUV422P10;
+ else
+ s->avctx->pix_fmt = PIX_FMT_YUV420P10;
break;
default:
if (CHROMA444){
s->avctx->pix_fmt = s->avctx->color_range == AVCOL_RANGE_JPEG ? PIX_FMT_YUVJ444P : PIX_FMT_YUV444P;
+ if (s->avctx->colorspace == AVCOL_SPC_RGB) {
+ s->avctx->pix_fmt = PIX_FMT_GBR24P;
+ av_log(h->s.avctx, AV_LOG_DEBUG, "Detected GBR colorspace.\n");
+ }
+ } else if (CHROMA422) {
+ s->avctx->pix_fmt = s->avctx->color_range == AVCOL_RANGE_JPEG ? PIX_FMT_YUVJ422P : PIX_FMT_YUV422P;
}else{
s->avctx->pix_fmt = s->avctx->get_format(s->avctx,
s->avctx->codec->pix_fmts ?
@@ -2626,7 +2811,10 @@ static int decode_slice_header(H264Context *h, H264Context *h0){
h->prev_interlaced_frame = 1;
init_scan_tables(h);
- ff_h264_alloc_tables(h);
+ if (ff_h264_alloc_tables(h) < 0) {
+ av_log(h->s.avctx, AV_LOG_ERROR, "Could not allocate memory for h264\n");
+ return AVERROR(ENOMEM);
+ }
if (!HAVE_THREADS || !(s->avctx->active_thread_type&FF_THREAD_SLICE)) {
if (context_init(h) < 0) {
@@ -2663,6 +2851,10 @@ static int decode_slice_header(H264Context *h, H264Context *h0){
if(h->sps.frame_mbs_only_flag){
s->picture_structure= PICT_FRAME;
}else{
+ if(!h->sps.direct_8x8_inference_flag && slice_type == AV_PICTURE_TYPE_B){
+ av_log(h->s.avctx, AV_LOG_ERROR, "This stream was generated by a broken encoder, invalid 8x8 inference\n");
+ return -1;
+ }
if(get_bits1(&s->gb)) { //field_pic_flag
s->picture_structure= PICT_TOP_FIELD + get_bits1(&s->gb); //bottom_field_flag
} else {
@@ -2700,7 +2892,9 @@ static int decode_slice_header(H264Context *h, H264Context *h0){
ff_thread_report_progress((AVFrame*)s->current_picture_ptr, INT_MAX, 0);
ff_thread_report_progress((AVFrame*)s->current_picture_ptr, INT_MAX, 1);
ff_generate_sliding_window_mmcos(h);
- ff_h264_execute_ref_pic_marking(h, h->mmco, h->mmco_index);
+ if (ff_h264_execute_ref_pic_marking(h, h->mmco, h->mmco_index) < 0 &&
+ s->avctx->error_recognition >= FF_ER_EXPLODE)
+ return AVERROR_INVALIDDATA;
/* Error concealment: if a ref is missing, copy the previous ref in its place.
* FIXME: avoiding a memcpy would be nice, but ref handling makes many assumptions
* about there being no actual duplicates.
@@ -2709,8 +2903,8 @@ static int decode_slice_header(H264Context *h, H264Context *h0){
* be fixed. */
if (h->short_ref_count) {
if (prev) {
- av_image_copy(h->short_ref[0]->data, h->short_ref[0]->linesize,
- (const uint8_t**)prev->data, prev->linesize,
+ av_image_copy(h->short_ref[0]->f.data, h->short_ref[0]->f.linesize,
+ (const uint8_t**)prev->f.data, prev->f.linesize,
s->avctx->pix_fmt, s->mb_width*16, s->mb_height*16);
h->short_ref[0]->poc = prev->poc+2;
}
@@ -2721,8 +2915,8 @@ static int decode_slice_header(H264Context *h, H264Context *h0){
/* See if we have a decoded first field looking for a pair... */
if (s0->first_field) {
assert(s0->current_picture_ptr);
- assert(s0->current_picture_ptr->data[0]);
- assert(s0->current_picture_ptr->reference != DELAYED_PIC_REF);
+ assert(s0->current_picture_ptr->f.data[0]);
+ assert(s0->current_picture_ptr->f.reference != DELAYED_PIC_REF);
/* figure out if we have a complementary field pair */
if (!FIELD_PICTURE || s->picture_structure == last_pic_structure) {
@@ -2735,7 +2929,7 @@ static int decode_slice_header(H264Context *h, H264Context *h0){
} else {
if (h->nal_ref_idc &&
- s0->current_picture_ptr->reference &&
+ s0->current_picture_ptr->f.reference &&
s0->current_picture_ptr->frame_num != h->frame_num) {
/*
* This and previous field were reference, but had
@@ -2822,6 +3016,7 @@ static int decode_slice_header(H264Context *h, H264Context *h0){
h->ref_count[1]= h->pps.ref_count[1];
if(h->slice_type_nos != AV_PICTURE_TYPE_I){
+ unsigned max= (16<<(s->picture_structure != PICT_FRAME))-1;
if(h->slice_type_nos == AV_PICTURE_TYPE_B){
h->direct_spatial_mv_pred= get_bits1(&s->gb);
}
@@ -2832,25 +3027,27 @@ static int decode_slice_header(H264Context *h, H264Context *h0){
if(h->slice_type_nos==AV_PICTURE_TYPE_B)
h->ref_count[1]= get_ue_golomb(&s->gb) + 1;
- if(h->ref_count[0]-1 > 32-1 || h->ref_count[1]-1 > 32-1){
- av_log(h->s.avctx, AV_LOG_ERROR, "reference overflow\n");
- h->ref_count[0]= h->ref_count[1]= 1;
- return -1;
- }
+ }
+ if(h->ref_count[0]-1 > max || h->ref_count[1]-1 > max){
+ av_log(h->s.avctx, AV_LOG_ERROR, "reference overflow\n");
+ h->ref_count[0]= h->ref_count[1]= 1;
+ return -1;
}
if(h->slice_type_nos == AV_PICTURE_TYPE_B)
h->list_count= 2;
else
h->list_count= 1;
}else
- h->list_count= 0;
+ h->ref_count[1]= h->ref_count[0]= h->list_count= 0;
if(!default_ref_list_done){
ff_h264_fill_default_ref_list(h);
}
- if(h->slice_type_nos!=AV_PICTURE_TYPE_I && ff_h264_decode_ref_pic_list_reordering(h) < 0)
+ if(h->slice_type_nos!=AV_PICTURE_TYPE_I && ff_h264_decode_ref_pic_list_reordering(h) < 0) {
+ h->ref_count[1]= h->ref_count[0]= 0;
return -1;
+ }
if(h->slice_type_nos!=AV_PICTURE_TYPE_I){
s->last_picture_ptr= &h->ref_list[0][0];
@@ -2874,8 +3071,9 @@ static int decode_slice_header(H264Context *h, H264Context *h0){
}
}
- if(h->nal_ref_idc)
- ff_h264_decode_ref_pic_marking(h0, &s->gb);
+ if(h->nal_ref_idc && ff_h264_decode_ref_pic_marking(h0, &s->gb) < 0 &&
+ s->avctx->error_recognition >= FF_ER_EXPLODE)
+ return AVERROR_INVALIDDATA;
if(FRAME_MBAFF){
ff_h264_fill_mbaff_ref_list(h);
@@ -2963,7 +3161,9 @@ static int decode_slice_header(H264Context *h, H264Context *h0){
}
}
}
- h->qp_thresh= 15 + 52 - FFMIN(h->slice_alpha_c0_offset, h->slice_beta_offset) - FFMAX3(0, h->pps.chroma_qp_index_offset[0], h->pps.chroma_qp_index_offset[1]);
+ h->qp_thresh = 15 + 52 - FFMIN(h->slice_alpha_c0_offset, h->slice_beta_offset)
+ - FFMAX3(0, h->pps.chroma_qp_index_offset[0], h->pps.chroma_qp_index_offset[1])
+ + 6 * (h->sps.bit_depth_luma - 8);
#if 0 //FMO
if( h->pps.num_slice_groups > 1 && h->pps.mb_slice_group_map_type >= 3 && h->pps.mb_slice_group_map_type <= 5)
@@ -2972,8 +3172,14 @@ static int decode_slice_header(H264Context *h, H264Context *h0){
h0->last_slice_type = slice_type;
h->slice_num = ++h0->current_slice;
- if(h->slice_num >= MAX_SLICES){
- av_log(s->avctx, AV_LOG_ERROR, "Too many slices, increase MAX_SLICES and recompile\n");
+
+ if(h->slice_num)
+ h0->slice_row[(h->slice_num-1)&(MAX_SLICES-1)]= s->resync_mb_y;
+ if ( h0->slice_row[h->slice_num&(MAX_SLICES-1)] + 3 >= s->resync_mb_y
+ && h0->slice_row[h->slice_num&(MAX_SLICES-1)] <= s->resync_mb_y
+ && h->slice_num >= MAX_SLICES) {
+ //in case of ASO this check needs to be updated depending on how we decide to assign slice numbers in this case
+ av_log(s->avctx, AV_LOG_WARNING, "Possibly too many slices (%d >= %d), increase MAX_SLICES and recompile if there are artifacts\n", h->slice_num, MAX_SLICES);
}
for(j=0; j<2; j++){
@@ -2981,16 +3187,16 @@ static int decode_slice_header(H264Context *h, H264Context *h0){
int *ref2frm= h->ref2frm[h->slice_num&(MAX_SLICES-1)][j];
for(i=0; i<16; i++){
id_list[i]= 60;
- if(h->ref_list[j][i].data[0]){
+ if (h->ref_list[j][i].f.data[0]) {
int k;
- uint8_t *base= h->ref_list[j][i].base[0];
+ uint8_t *base = h->ref_list[j][i].f.base[0];
for(k=0; k<h->short_ref_count; k++)
- if(h->short_ref[k]->base[0] == base){
+ if (h->short_ref[k]->f.base[0] == base) {
id_list[i]= k;
break;
}
for(k=0; k<h->long_ref_count; k++)
- if(h->long_ref[k] && h->long_ref[k]->base[0] == base){
+ if (h->long_ref[k] && h->long_ref[k]->f.base[0] == base) {
id_list[i]= h->short_ref_count + k;
break;
}
@@ -3001,12 +3207,12 @@ static int decode_slice_header(H264Context *h, H264Context *h0){
ref2frm[1]= -1;
for(i=0; i<16; i++)
ref2frm[i+2]= 4*id_list[i]
- +(h->ref_list[j][i].reference&3);
+ + (h->ref_list[j][i].f.reference & 3);
ref2frm[18+0]=
ref2frm[18+1]= -1;
for(i=16; i<48; i++)
ref2frm[i+4]= 4*id_list[(i-16)>>1]
- +(h->ref_list[j][i].reference&3);
+ + (h->ref_list[j][i].f.reference & 3);
}
//FIXME: fix draw_edges+PAFF+frame threads
@@ -3056,11 +3262,11 @@ static av_always_inline void fill_filter_caches_inter(H264Context *h, MpegEncCon
const int b_xy= h->mb2b_xy[top_xy] + 3*b_stride;
const int b8_xy= 4*top_xy + 2;
int (*ref2frm)[64] = h->ref2frm[ h->slice_table[top_xy]&(MAX_SLICES-1) ][0] + (MB_MBAFF ? 20 : 2);
- AV_COPY128(mv_dst - 1*8, s->current_picture.motion_val[list][b_xy + 0]);
+ AV_COPY128(mv_dst - 1*8, s->current_picture.f.motion_val[list][b_xy + 0]);
ref_cache[0 - 1*8]=
- ref_cache[1 - 1*8]= ref2frm[list][s->current_picture.ref_index[list][b8_xy + 0]];
+ ref_cache[1 - 1*8]= ref2frm[list][s->current_picture.f.ref_index[list][b8_xy + 0]];
ref_cache[2 - 1*8]=
- ref_cache[3 - 1*8]= ref2frm[list][s->current_picture.ref_index[list][b8_xy + 1]];
+ ref_cache[3 - 1*8]= ref2frm[list][s->current_picture.f.ref_index[list][b8_xy + 1]];
}else{
AV_ZERO128(mv_dst - 1*8);
AV_WN32A(&ref_cache[0 - 1*8], ((LIST_NOT_USED)&0xFF)*0x01010101u);
@@ -3071,14 +3277,14 @@ static av_always_inline void fill_filter_caches_inter(H264Context *h, MpegEncCon
const int b_xy= h->mb2b_xy[left_xy[LTOP]] + 3;
const int b8_xy= 4*left_xy[LTOP] + 1;
int (*ref2frm)[64] = h->ref2frm[ h->slice_table[left_xy[LTOP]]&(MAX_SLICES-1) ][0] + (MB_MBAFF ? 20 : 2);
- AV_COPY32(mv_dst - 1 + 0, s->current_picture.motion_val[list][b_xy + b_stride*0]);
- AV_COPY32(mv_dst - 1 + 8, s->current_picture.motion_val[list][b_xy + b_stride*1]);
- AV_COPY32(mv_dst - 1 +16, s->current_picture.motion_val[list][b_xy + b_stride*2]);
- AV_COPY32(mv_dst - 1 +24, s->current_picture.motion_val[list][b_xy + b_stride*3]);
+ AV_COPY32(mv_dst - 1 + 0, s->current_picture.f.motion_val[list][b_xy + b_stride*0]);
+ AV_COPY32(mv_dst - 1 + 8, s->current_picture.f.motion_val[list][b_xy + b_stride*1]);
+ AV_COPY32(mv_dst - 1 + 16, s->current_picture.f.motion_val[list][b_xy + b_stride*2]);
+ AV_COPY32(mv_dst - 1 + 24, s->current_picture.f.motion_val[list][b_xy + b_stride*3]);
ref_cache[-1 + 0]=
- ref_cache[-1 + 8]= ref2frm[list][s->current_picture.ref_index[list][b8_xy + 2*0]];
+ ref_cache[-1 + 8]= ref2frm[list][s->current_picture.f.ref_index[list][b8_xy + 2*0]];
ref_cache[-1 + 16]=
- ref_cache[-1 + 24]= ref2frm[list][s->current_picture.ref_index[list][b8_xy + 2*1]];
+ ref_cache[-1 + 24]= ref2frm[list][s->current_picture.f.ref_index[list][b8_xy + 2*1]];
}else{
AV_ZERO32(mv_dst - 1 + 0);
AV_ZERO32(mv_dst - 1 + 8);
@@ -3102,7 +3308,7 @@ static av_always_inline void fill_filter_caches_inter(H264Context *h, MpegEncCon
}
{
- int8_t *ref = &s->current_picture.ref_index[list][4*mb_xy];
+ int8_t *ref = &s->current_picture.f.ref_index[list][4*mb_xy];
int (*ref2frm)[64] = h->ref2frm[ h->slice_num&(MAX_SLICES-1) ][0] + (MB_MBAFF ? 20 : 2);
uint32_t ref01 = (pack16to32(ref2frm[list][ref[0]],ref2frm[list][ref[1]])&0x00FF00FF)*0x0101;
uint32_t ref23 = (pack16to32(ref2frm[list][ref[2]],ref2frm[list][ref[3]])&0x00FF00FF)*0x0101;
@@ -3113,7 +3319,7 @@ static av_always_inline void fill_filter_caches_inter(H264Context *h, MpegEncCon
}
{
- int16_t (*mv_src)[2] = &s->current_picture.motion_val[list][4*s->mb_x + 4*s->mb_y*b_stride];
+ int16_t (*mv_src)[2] = &s->current_picture.f.motion_val[list][4*s->mb_x + 4*s->mb_y*b_stride];
AV_COPY128(mv_dst + 8*0, mv_src + 0*b_stride);
AV_COPY128(mv_dst + 8*1, mv_src + 1*b_stride);
AV_COPY128(mv_dst + 8*2, mv_src + 2*b_stride);
@@ -3140,7 +3346,7 @@ static int fill_filter_caches(H264Context *h, int mb_type){
left_xy[LBOT] = left_xy[LTOP] = mb_xy-1;
if(FRAME_MBAFF){
- const int left_mb_field_flag = IS_INTERLACED(s->current_picture.mb_type[mb_xy-1]);
+ const int left_mb_field_flag = IS_INTERLACED(s->current_picture.f.mb_type[mb_xy - 1]);
const int curr_mb_field_flag = IS_INTERLACED(mb_type);
if(s->mb_y&1){
if (left_mb_field_flag != curr_mb_field_flag) {
@@ -3148,7 +3354,7 @@ static int fill_filter_caches(H264Context *h, int mb_type){
}
}else{
if(curr_mb_field_flag){
- top_xy += s->mb_stride & (((s->current_picture.mb_type[top_xy ]>>7)&1)-1);
+ top_xy += s->mb_stride & (((s->current_picture.f.mb_type[top_xy] >> 7) & 1) - 1);
}
if (left_mb_field_flag != curr_mb_field_flag) {
left_xy[LBOT] += s->mb_stride;
@@ -3163,21 +3369,21 @@ static int fill_filter_caches(H264Context *h, int mb_type){
//for sufficiently low qp, filtering wouldn't do anything
//this is a conservative estimate: could also check beta_offset and more accurate chroma_qp
int qp_thresh = h->qp_thresh; //FIXME strictly we should store qp_thresh for each mb of a slice
- int qp = s->current_picture.qscale_table[mb_xy];
+ int qp = s->current_picture.f.qscale_table[mb_xy];
if(qp <= qp_thresh
- && (left_xy[LTOP]<0 || ((qp + s->current_picture.qscale_table[left_xy[LTOP]] + 1)>>1) <= qp_thresh)
- && (top_xy <0 || ((qp + s->current_picture.qscale_table[top_xy ] + 1)>>1) <= qp_thresh)){
+ && (left_xy[LTOP] < 0 || ((qp + s->current_picture.f.qscale_table[left_xy[LTOP]] + 1) >> 1) <= qp_thresh)
+ && (top_xy < 0 || ((qp + s->current_picture.f.qscale_table[top_xy ] + 1) >> 1) <= qp_thresh)) {
if(!FRAME_MBAFF)
return 1;
- if( (left_xy[LTOP]< 0 || ((qp + s->current_picture.qscale_table[left_xy[LBOT] ] + 1)>>1) <= qp_thresh)
- && (top_xy < s->mb_stride || ((qp + s->current_picture.qscale_table[top_xy -s->mb_stride] + 1)>>1) <= qp_thresh))
+ if ((left_xy[LTOP] < 0 || ((qp + s->current_picture.f.qscale_table[left_xy[LBOT] ] + 1) >> 1) <= qp_thresh) &&
+ (top_xy < s->mb_stride || ((qp + s->current_picture.f.qscale_table[top_xy - s->mb_stride] + 1) >> 1) <= qp_thresh))
return 1;
}
}
- top_type = s->current_picture.mb_type[top_xy];
- left_type[LTOP] = s->current_picture.mb_type[left_xy[LTOP]];
- left_type[LBOT] = s->current_picture.mb_type[left_xy[LBOT]];
+ top_type = s->current_picture.f.mb_type[top_xy];
+ left_type[LTOP] = s->current_picture.f.mb_type[left_xy[LTOP]];
+ left_type[LBOT] = s->current_picture.f.mb_type[left_xy[LBOT]];
if(h->deblocking_filter == 2){
if(h->slice_table[top_xy ] != h->slice_num) top_type= 0;
if(h->slice_table[left_xy[LBOT]] != h->slice_num) left_type[LTOP]= left_type[LBOT]= 0;
@@ -3259,6 +3465,7 @@ static void loop_filter(H264Context *h, int start_x, int end_x){
const int end_mb_y= s->mb_y + FRAME_MBAFF;
const int old_slice_type= h->slice_type;
const int pixel_shift = h->pixel_shift;
+ const int block_h = 16 >> s->chroma_y_shift;
if(h->deblocking_filter) {
for(mb_x= start_x; mb_x<end_x; mb_x++){
@@ -3266,7 +3473,7 @@ static void loop_filter(H264Context *h, int start_x, int end_x){
int mb_xy, mb_type;
mb_xy = h->mb_xy = mb_x + mb_y*s->mb_stride;
h->slice_num= h->slice_table[mb_xy];
- mb_type= s->current_picture.mb_type[mb_xy];
+ mb_type = s->current_picture.f.mb_type[mb_xy];
h->list_count= h->list_counts[mb_xy];
if(FRAME_MBAFF)
@@ -3274,9 +3481,9 @@ static void loop_filter(H264Context *h, int start_x, int end_x){
s->mb_x= mb_x;
s->mb_y= mb_y;
- dest_y = s->current_picture.data[0] + ((mb_x << pixel_shift) + mb_y * s->linesize ) * 16;
- dest_cb = s->current_picture.data[1] + ((mb_x << pixel_shift) + mb_y * s->uvlinesize) * (8 << CHROMA444);
- dest_cr = s->current_picture.data[2] + ((mb_x << pixel_shift) + mb_y * s->uvlinesize) * (8 << CHROMA444);
+ dest_y = s->current_picture.f.data[0] + ((mb_x << pixel_shift) + mb_y * s->linesize ) * 16;
+ dest_cb = s->current_picture.f.data[1] + (mb_x << pixel_shift) * (8 << CHROMA444) + mb_y * s->uvlinesize * block_h;
+ dest_cr = s->current_picture.f.data[2] + (mb_x << pixel_shift) * (8 << CHROMA444) + mb_y * s->uvlinesize * block_h;
//FIXME simplify above
if (MB_FIELD) {
@@ -3284,18 +3491,18 @@ static void loop_filter(H264Context *h, int start_x, int end_x){
uvlinesize = h->mb_uvlinesize = s->uvlinesize * 2;
if(mb_y&1){ //FIXME move out of this function?
dest_y -= s->linesize*15;
- dest_cb-= s->uvlinesize*((8 << CHROMA444)-1);
- dest_cr-= s->uvlinesize*((8 << CHROMA444)-1);
+ dest_cb-= s->uvlinesize * (block_h - 1);
+ dest_cr-= s->uvlinesize * (block_h - 1);
}
} else {
linesize = h->mb_linesize = s->linesize;
uvlinesize = h->mb_uvlinesize = s->uvlinesize;
}
- backup_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize, CHROMA444, 0);
+ backup_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize, 0);
if(fill_filter_caches(h, mb_type))
continue;
- h->chroma_qp[0] = get_chroma_qp(h, 0, s->current_picture.qscale_table[mb_xy]);
- h->chroma_qp[1] = get_chroma_qp(h, 1, s->current_picture.qscale_table[mb_xy]);
+ h->chroma_qp[0] = get_chroma_qp(h, 0, s->current_picture.f.qscale_table[mb_xy]);
+ h->chroma_qp[1] = get_chroma_qp(h, 1, s->current_picture.f.qscale_table[mb_xy]);
if (FRAME_MBAFF) {
ff_h264_filter_mb (h, mb_x, mb_y, dest_y, dest_cb, dest_cr, linesize, uvlinesize);
@@ -3316,9 +3523,9 @@ static void predict_field_decoding_flag(H264Context *h){
MpegEncContext * const s = &h->s;
const int mb_xy= s->mb_x + s->mb_y*s->mb_stride;
int mb_type = (h->slice_table[mb_xy-1] == h->slice_num)
- ? s->current_picture.mb_type[mb_xy-1]
+ ? s->current_picture.f.mb_type[mb_xy - 1]
: (h->slice_table[mb_xy-s->mb_stride] == h->slice_num)
- ? s->current_picture.mb_type[mb_xy-s->mb_stride]
+ ? s->current_picture.f.mb_type[mb_xy - s->mb_stride]
: 0;
h->mb_mbaff = h->mb_field_decoding_flag = IS_INTERLACED(mb_type) ? 1 : 0;
}
@@ -3462,7 +3669,8 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg){
if(s->mb_y >= s->mb_height){
tprintf(s->avctx, "slice end %d %d\n", get_bits_count(&s->gb), s->gb.size_in_bits);
- if(get_bits_count(&s->gb) == s->gb.size_in_bits ) {
+ if( get_bits_count(&s->gb) == s->gb.size_in_bits
+ || get_bits_count(&s->gb) < s->gb.size_in_bits && s->avctx->error_recognition < FF_ER_AGGRESSIVE) {
ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);
return 0;
@@ -3489,52 +3697,6 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg){
}
}
}
-
-#if 0
- for(;s->mb_y < s->mb_height; s->mb_y++){
- for(;s->mb_x < s->mb_width; s->mb_x++){
- int ret= decode_mb(h);
-
- ff_h264_hl_decode_mb(h);
-
- if(ret<0){
- av_log(s->avctx, AV_LOG_ERROR, "error while decoding MB %d %d\n", s->mb_x, s->mb_y);
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask);
-
- return -1;
- }
-
- if(++s->mb_x >= s->mb_width){
- s->mb_x=0;
- if(++s->mb_y >= s->mb_height){
- if(get_bits_count(s->gb) == s->gb.size_in_bits){
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);
-
- return 0;
- }else{
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);
-
- return -1;
- }
- }
- }
-
- if(get_bits_count(s->?gb) >= s->gb?.size_in_bits){
- if(get_bits_count(s->gb) == s->gb.size_in_bits){
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);
-
- return 0;
- }else{
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask);
-
- return -1;
- }
- }
- }
- s->mb_x=0;
- ff_draw_horiz_band(s, 16*s->mb_y, 16);
- }
-#endif
}
/**
@@ -3543,23 +3705,22 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg){
* @param h h264 master context
* @param context_count number of contexts to execute
*/
-static void execute_decode_slices(H264Context *h, int context_count){
+static int execute_decode_slices(H264Context *h, int context_count){
MpegEncContext * const s = &h->s;
AVCodecContext * const avctx= s->avctx;
H264Context *hx;
int i;
- if (s->avctx->hwaccel)
- return;
- if(s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU)
- return;
+ if (s->avctx->hwaccel || s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU)
+ return 0;
if(context_count == 1) {
- decode_slice(avctx, &h);
+ return decode_slice(avctx, &h);
} else {
for(i = 1; i < context_count; i++) {
hx = h->thread_context[i];
hx->s.error_recognition = avctx->error_recognition;
hx->s.error_count = 0;
+ hx->x264_build= h->x264_build;
}
avctx->execute(avctx, (void *)decode_slice,
@@ -3574,6 +3735,8 @@ static void execute_decode_slices(H264Context *h, int context_count){
for(i = 1; i < context_count; i++)
h->s.error_count += h->thread_context[i]->s.error_count;
}
+
+ return 0;
}
@@ -3645,13 +3808,13 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size){
s->workaround_bugs |= FF_BUG_TRUNCATED;
if(!(s->workaround_bugs & FF_BUG_TRUNCATED)){
- while(ptr[dst_length - 1] == 0 && dst_length > 0)
+ while(dst_length > 0 && ptr[dst_length - 1] == 0)
dst_length--;
}
bit_length= !dst_length ? 0 : (8*dst_length - ff_h264_decode_rbsp_trailing(h, ptr + dst_length - 1));
if(s->avctx->debug&FF_DEBUG_STARTCODE){
- av_log(h->s.avctx, AV_LOG_DEBUG, "NAL %d at %d/%d length %d\n", hx->nal_unit_type, buf_index, buf_size, dst_length);
+ av_log(h->s.avctx, AV_LOG_DEBUG, "NAL %d/%d at %d/%d length %d\n", hx->nal_unit_type, hx->nal_ref_idc, buf_index, buf_size, dst_length);
}
if (h->is_avc && (nalsize != consumed) && nalsize){
@@ -3668,9 +3831,13 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size){
switch (hx->nal_unit_type) {
case NAL_SPS:
case NAL_PPS:
+ nals_needed = nal_index;
+ break;
case NAL_IDR_SLICE:
case NAL_SLICE:
- nals_needed = nal_index;
+ init_get_bits(&hx->s.gb, ptr, bit_length);
+ if (!get_ue_golomb(&hx->s.gb))
+ nals_needed = nal_index;
}
continue;
}
@@ -3697,9 +3864,22 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size){
if((err = decode_slice_header(hx, h)))
break;
- s->current_picture_ptr->key_frame |=
- (hx->nal_unit_type == NAL_IDR_SLICE) ||
- (h->sei_recovery_frame_cnt >= 0);
+ if (h->sei_recovery_frame_cnt >= 0 && h->recovery_frame < 0) {
+ h->recovery_frame = (h->frame_num + h->sei_recovery_frame_cnt) %
+ (1 << h->sps.log2_max_frame_num);
+ }
+
+ s->current_picture_ptr->f.key_frame |=
+ (hx->nal_unit_type == NAL_IDR_SLICE);
+
+ if (h->recovery_frame == h->frame_num) {
+ h->sync |= 1;
+ h->recovery_frame = -1;
+ }
+
+ h->sync |= !!s->current_picture_ptr->f.key_frame;
+ h->sync |= 3*!!(s->flags2 & CODEC_FLAG2_SHOW_ALL);
+ s->current_picture_ptr->sync = h->sync;
if (h->current_slice == 1) {
if(!(s->flags2 & CODEC_FLAG2_CHUNKS)) {
@@ -3762,7 +3942,11 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size){
break;
case NAL_SPS:
init_get_bits(&s->gb, ptr, bit_length);
- ff_h264_decode_seq_parameter_set(h);
+ if(ff_h264_decode_seq_parameter_set(h) < 0 && h->is_avc && (nalsize != consumed) && nalsize){
+ av_log(h->s.avctx, AV_LOG_DEBUG, "SPS decoding failure, trying alternative mode\n");
+ init_get_bits(&s->gb, &buf[buf_index + 1 - consumed], 8*nalsize);
+ ff_h264_decode_seq_parameter_set(h);
+ }
if (s->flags& CODEC_FLAG_LOW_DELAY ||
(h->sps.bitstream_restriction_flag && !h->sps.num_reorder_frames))
@@ -3770,20 +3954,6 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size){
if(avctx->has_b_frames < 2)
avctx->has_b_frames= !s->low_delay;
-
- if (avctx->bits_per_raw_sample != h->sps.bit_depth_luma) {
- if (h->sps.bit_depth_luma >= 8 && h->sps.bit_depth_luma <= 10) {
- avctx->bits_per_raw_sample = h->sps.bit_depth_luma;
- h->pixel_shift = h->sps.bit_depth_luma > 8;
-
- ff_h264dsp_init(&h->h264dsp, h->sps.bit_depth_luma);
- ff_h264_pred_init(&h->hpc, s->codec_id, h->sps.bit_depth_luma);
- dsputil_init(&s->dsp, s->avctx);
- } else {
- av_log(avctx, AV_LOG_DEBUG, "Unsupported bit depth: %d\n", h->sps.bit_depth_luma);
- return -1;
- }
- }
break;
case NAL_PPS:
init_get_bits(&s->gb, ptr, bit_length);
@@ -3861,7 +4031,7 @@ static int decode_frame(AVCodecContext *avctx,
//FIXME factorize this with the output code below
out = h->delayed_pic[0];
out_idx = 0;
- for(i=1; h->delayed_pic[i] && !h->delayed_pic[i]->key_frame && !h->delayed_pic[i]->mmco_reset; i++)
+ for (i = 1; h->delayed_pic[i] && !h->delayed_pic[i]->f.key_frame && !h->delayed_pic[i]->mmco_reset; i++)
if(h->delayed_pic[i]->poc < out->poc){
out = h->delayed_pic[i];
out_idx = i;
@@ -3877,6 +4047,8 @@ static int decode_frame(AVCodecContext *avctx,
return 0;
}
+ if(h->is_avc && buf_size >= 9 && AV_RB32(buf)==0x0164001F && buf[5] && buf[8]==0x67)
+ return ff_h264_decode_extradata(h, buf, buf_size);
buf_index=decode_nal_units(h, buf, buf_size);
if(buf_index < 0)
@@ -3900,13 +4072,12 @@ static int decode_frame(AVCodecContext *avctx,
field_end(h, 0);
- if (!h->next_output_pic) {
- /* Wait for second field. */
- *data_size = 0;
-
- } else {
- *data_size = sizeof(AVFrame);
- *pict = *(AVFrame*)h->next_output_pic;
+ *data_size = 0; /* Wait for second field. */
+ if (h->next_output_pic && h->next_output_pic->sync) {
+ if(h->sync>1 || h->next_output_pic->f.pict_type != AV_PICTURE_TYPE_B){
+ *data_size = sizeof(AVFrame);
+ *pict = *(AVFrame*)h->next_output_pic;
+ }
}
}
@@ -3941,6 +4112,7 @@ static inline void fill_mb_avail(H264Context *h){
#undef random
#define COUNT 8000
#define SIZE (COUNT*40)
+extern AVCodec ff_h264_decoder;
int main(void){
int i;
uint8_t temp[SIZE];
@@ -3950,6 +4122,8 @@ int main(void){
DSPContext dsp;
AVCodecContext avctx;
+ avcodec_get_context_defaults3(&avctx, &ff_h264_decoder);
+
dsputil_init(&dsp, &avctx);
init_put_bits(&pb, temp, SIZE);
@@ -4001,109 +4175,6 @@ int main(void){
STOP_TIMER("get_se_golomb");
}
-#if 0
- printf("testing 4x4 (I)DCT\n");
-
- DCTELEM block[16];
- uint8_t src[16], ref[16];
- uint64_t error= 0, max_error=0;
-
- for(i=0; i<COUNT; i++){
- int j;
-// printf("%d %d %d\n", r1, r2, (r2-r1)*16);
- for(j=0; j<16; j++){
- ref[j]= random()%255;
- src[j]= random()%255;
- }
-
- h264_diff_dct_c(block, src, ref, 4);
-
- //normalize
- for(j=0; j<16; j++){
-// printf("%d ", block[j]);
- block[j]= block[j]*4;
- if(j&1) block[j]= (block[j]*4 + 2)/5;
- if(j&4) block[j]= (block[j]*4 + 2)/5;
- }
-// printf("\n");
-
- h->h264dsp.h264_idct_add(ref, block, 4);
-/* for(j=0; j<16; j++){
- printf("%d ", ref[j]);
- }
- printf("\n");*/
-
- for(j=0; j<16; j++){
- int diff= FFABS(src[j] - ref[j]);
-
- error+= diff*diff;
- max_error= FFMAX(max_error, diff);
- }
- }
- printf("error=%f max_error=%d\n", ((float)error)/COUNT/16, (int)max_error );
- printf("testing quantizer\n");
- for(qp=0; qp<52; qp++){
- for(i=0; i<16; i++)
- src1_block[i]= src2_block[i]= random()%255;
-
- }
- printf("Testing NAL layer\n");
-
- uint8_t bitstream[COUNT];
- uint8_t nal[COUNT*2];
- H264Context h;
- memset(&h, 0, sizeof(H264Context));
-
- for(i=0; i<COUNT; i++){
- int zeros= i;
- int nal_length;
- int consumed;
- int out_length;
- uint8_t *out;
- int j;
-
- for(j=0; j<COUNT; j++){
- bitstream[j]= (random() % 255) + 1;
- }
-
- for(j=0; j<zeros; j++){
- int pos= random() % COUNT;
- while(bitstream[pos] == 0){
- pos++;
- pos %= COUNT;
- }
- bitstream[pos]=0;
- }
-
- START_TIMER
-
- nal_length= encode_nal(&h, nal, bitstream, COUNT, COUNT*2);
- if(nal_length<0){
- printf("encoding failed\n");
- return -1;
- }
-
- out= ff_h264_decode_nal(&h, nal, &out_length, &consumed, nal_length);
-
- STOP_TIMER("NAL")
-
- if(out_length != COUNT){
- printf("incorrect length %d %d\n", out_length, COUNT);
- return -1;
- }
-
- if(consumed != nal_length){
- printf("incorrect consumed length %d %d\n", nal_length, consumed);
- return -1;
- }
-
- if(memcmp(bitstream, out, COUNT)){
- printf("mismatch\n");
- return -1;
- }
- }
-#endif
-
printf("Testing RBSP\n");
@@ -4157,16 +4228,15 @@ static const AVProfile profiles[] = {
};
AVCodec ff_h264_decoder = {
- "h264",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_H264,
- sizeof(H264Context),
- ff_h264_decode_init,
- NULL,
- ff_h264_decode_end,
- decode_frame,
- /*CODEC_CAP_DRAW_HORIZ_BAND |*/ CODEC_CAP_DR1 | CODEC_CAP_DELAY |
- CODEC_CAP_SLICE_THREADS | CODEC_CAP_FRAME_THREADS,
+ .name = "h264",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_H264,
+ .priv_data_size = sizeof(H264Context),
+ .init = ff_h264_decode_init,
+ .close = ff_h264_decode_end,
+ .decode = decode_frame,
+ .capabilities = /*CODEC_CAP_DRAW_HORIZ_BAND |*/ CODEC_CAP_DR1 | CODEC_CAP_DELAY |
+ CODEC_CAP_SLICE_THREADS | CODEC_CAP_FRAME_THREADS,
.flush= flush_dpb,
.long_name = NULL_IF_CONFIG_SMALL("H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"),
.init_thread_copy = ONLY_IF_THREADS_ENABLED(decode_init_thread_copy),
@@ -4176,15 +4246,14 @@ AVCodec ff_h264_decoder = {
#if CONFIG_H264_VDPAU_DECODER
AVCodec ff_h264_vdpau_decoder = {
- "h264_vdpau",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_H264,
- sizeof(H264Context),
- ff_h264_decode_init,
- NULL,
- ff_h264_decode_end,
- decode_frame,
- CODEC_CAP_DR1 | CODEC_CAP_DELAY | CODEC_CAP_HWACCEL_VDPAU,
+ .name = "h264_vdpau",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_H264,
+ .priv_data_size = sizeof(H264Context),
+ .init = ff_h264_decode_init,
+ .close = ff_h264_decode_end,
+ .decode = decode_frame,
+ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY | CODEC_CAP_HWACCEL_VDPAU,
.flush= flush_dpb,
.long_name = NULL_IF_CONFIG_SMALL("H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (VDPAU acceleration)"),
.pix_fmts = (const enum PixelFormat[]){PIX_FMT_VDPAU_H264, PIX_FMT_NONE},
diff --git a/libavcodec/h264.h b/libavcodec/h264.h
index dad06e2007..f4a463310e 100644
--- a/libavcodec/h264.h
+++ b/libavcodec/h264.h
@@ -2,20 +2,20 @@
* H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder
* Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -39,13 +39,6 @@
#define interlaced_dct interlaced_dct_is_a_bad_name
#define mb_intra mb_intra_is_not_initialized_see_mb_type
-#define CHROMA_DC_COEFF_TOKEN_VLC_BITS 8
-#define COEFF_TOKEN_VLC_BITS 8
-#define TOTAL_ZEROS_VLC_BITS 9
-#define CHROMA_DC_TOTAL_ZEROS_VLC_BITS 3
-#define RUN_VLC_BITS 3
-#define RUN7_VLC_BITS 6
-
#define MAX_SPS_COUNT 32
#define MAX_PPS_COUNT 256
@@ -53,6 +46,8 @@
#define MAX_DELAYED_PIC_COUNT 16
+#define MAX_MBPAIR_SIZE (256*1024) // a tighter bound could be calculated if someone cares about a few bytes
+
/* Compiling in interlaced support reduces the speed
* of progressive decoding by about 2%. */
#define ALLOW_INTERLACE
@@ -92,6 +87,7 @@
#define CABAC h->pps.cabac
#endif
+#define CHROMA422 (h->sps.chroma_format_idc == 2)
#define CHROMA444 (h->sps.chroma_format_idc == 3)
#define EXTENDED_SAR 255
@@ -107,7 +103,7 @@
*/
#define DELAYED_PIC_REF 4
-#define QP_MAX_NUM (51 + 2*6) // The maximum supported qp
+#define QP_MAX_NUM (51 + 4*6) // The maximum supported qp
/* NAL unit types */
enum {
@@ -233,7 +229,7 @@ typedef struct PPS{
int transform_8x8_mode; ///< transform_8x8_mode_flag
uint8_t scaling_matrix4[6][16];
uint8_t scaling_matrix8[6][64];
- uint8_t chroma_qp_table[2][64]; ///< pre-scaled (with chroma_qp_index_offset) version of qp_table
+ uint8_t chroma_qp_table[2][QP_MAX_NUM+1]; ///< pre-scaled (with chroma_qp_index_offset) version of qp_table
int chroma_qp_diff;
}PPS;
@@ -382,9 +378,9 @@ typedef struct H264Context{
/**
* num_ref_idx_l0/1_active_minus1 + 1
*/
+ uint8_t *list_counts; ///< Array of list_count per MB specifying the slice type
unsigned int ref_count[2]; ///< counts frames or fields, depending on current mb mode
unsigned int list_count;
- uint8_t *list_counts; ///< Array of list_count per MB specifying the slice type
Picture ref_list[2][48]; /**< 0..15: frame refs, 16..47: mbaff field refs.
Reordered version of default_ref_list
according to picture reordering in slice header */
@@ -575,6 +571,13 @@ typedef struct H264Context{
* frames.
*/
int sei_recovery_frame_cnt;
+ /**
+ * recovery_frame is the frame_num at which the next frame should
+ * be fully constructed.
+ *
+ * Set to -1 when not expecting a recovery point.
+ */
+ int recovery_frame;
int luma_weight_flag[2]; ///< 7.4.3.2 luma_weight_lX_flag
int chroma_weight_flag[2]; ///< 7.4.3.2 chroma_weight_lX_flag
@@ -582,10 +585,16 @@ typedef struct H264Context{
// Timestamp stuff
int sei_buffering_period_present; ///< Buffering period SEI flag
int initial_cpb_removal_delay[32]; ///< Initial timestamps for CPBs
+
+ int cur_chroma_format_idc;
+
+ int16_t slice_row[MAX_SLICES]; ///< to detect when MAX_SLICES is too low
+
+ int sync; ///< did we had a keyframe or recovery point
}H264Context;
-extern const uint8_t ff_h264_chroma_qp[3][QP_MAX_NUM+1]; ///< One chroma qp table for each supported bit depth (8, 9, 10).
+extern const uint8_t ff_h264_chroma_qp[5][QP_MAX_NUM+1]; ///< One chroma qp table for each possible bit depth (8-12).
/**
* Decode SEI
@@ -659,11 +668,16 @@ int ff_h264_check_intra4x4_pred_mode(H264Context *h);
/**
* Check if the top & left blocks are available if needed & change the dc mode so it only uses the available blocks.
*/
-int ff_h264_check_intra_pred_mode(H264Context *h, int mode);
+int ff_h264_check_intra16x16_pred_mode(H264Context *h, int mode);
+
+/**
+ * Check if the top & left blocks are available if needed & change the dc mode so it only uses the available blocks.
+ */
+int ff_h264_check_intra_chroma_pred_mode(H264Context *h, int mode);
void ff_h264_hl_decode_mb(H264Context *h);
int ff_h264_frame_start(H264Context *h);
-int ff_h264_decode_extradata(H264Context *h);
+int ff_h264_decode_extradata(H264Context *h, const uint8_t *buf, int size);
av_cold int ff_h264_decode_init(AVCodecContext *avctx);
av_cold int ff_h264_decode_end(AVCodecContext *avctx);
av_cold void ff_h264_decode_init_vlc(void);
@@ -766,430 +780,10 @@ static av_always_inline uint16_t pack8to16(int a, int b){
/**
* gets the chroma qp.
*/
-static inline int get_chroma_qp(H264Context *h, int t, int qscale){
+static av_always_inline int get_chroma_qp(H264Context *h, int t, int qscale){
return h->pps.chroma_qp_table[t][qscale];
}
-static inline void pred_pskip_motion(H264Context * const h, int * const mx, int * const my);
-
-static void fill_decode_neighbors(H264Context *h, int mb_type){
- MpegEncContext * const s = &h->s;
- const int mb_xy= h->mb_xy;
- int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS];
- static const uint8_t left_block_options[4][32]={
- {0,1,2,3,7,10,8,11,3+0*4, 3+1*4, 3+2*4, 3+3*4, 1+4*4, 1+8*4, 1+5*4, 1+9*4},
- {2,2,3,3,8,11,8,11,3+2*4, 3+2*4, 3+3*4, 3+3*4, 1+5*4, 1+9*4, 1+5*4, 1+9*4},
- {0,0,1,1,7,10,7,10,3+0*4, 3+0*4, 3+1*4, 3+1*4, 1+4*4, 1+8*4, 1+4*4, 1+8*4},
- {0,2,0,2,7,10,7,10,3+0*4, 3+2*4, 3+0*4, 3+2*4, 1+4*4, 1+8*4, 1+4*4, 1+8*4}
- };
-
- h->topleft_partition= -1;
-
- top_xy = mb_xy - (s->mb_stride << MB_FIELD);
-
- /* Wow, what a mess, why didn't they simplify the interlacing & intra
- * stuff, I can't imagine that these complex rules are worth it. */
-
- topleft_xy = top_xy - 1;
- topright_xy= top_xy + 1;
- left_xy[LBOT] = left_xy[LTOP] = mb_xy-1;
- h->left_block = left_block_options[0];
- if(FRAME_MBAFF){
- const int left_mb_field_flag = IS_INTERLACED(s->current_picture.mb_type[mb_xy-1]);
- const int curr_mb_field_flag = IS_INTERLACED(mb_type);
- if(s->mb_y&1){
- if (left_mb_field_flag != curr_mb_field_flag) {
- left_xy[LBOT] = left_xy[LTOP] = mb_xy - s->mb_stride - 1;
- if (curr_mb_field_flag) {
- left_xy[LBOT] += s->mb_stride;
- h->left_block = left_block_options[3];
- } else {
- topleft_xy += s->mb_stride;
- // take top left mv from the middle of the mb, as opposed to all other modes which use the bottom right partition
- h->topleft_partition = 0;
- h->left_block = left_block_options[1];
- }
- }
- }else{
- if(curr_mb_field_flag){
- topleft_xy += s->mb_stride & (((s->current_picture.mb_type[top_xy - 1]>>7)&1)-1);
- topright_xy += s->mb_stride & (((s->current_picture.mb_type[top_xy + 1]>>7)&1)-1);
- top_xy += s->mb_stride & (((s->current_picture.mb_type[top_xy ]>>7)&1)-1);
- }
- if (left_mb_field_flag != curr_mb_field_flag) {
- if (curr_mb_field_flag) {
- left_xy[LBOT] += s->mb_stride;
- h->left_block = left_block_options[3];
- } else {
- h->left_block = left_block_options[2];
- }
- }
- }
- }
-
- h->topleft_mb_xy = topleft_xy;
- h->top_mb_xy = top_xy;
- h->topright_mb_xy= topright_xy;
- h->left_mb_xy[LTOP] = left_xy[LTOP];
- h->left_mb_xy[LBOT] = left_xy[LBOT];
- //FIXME do we need all in the context?
-
- h->topleft_type = s->current_picture.mb_type[topleft_xy] ;
- h->top_type = s->current_picture.mb_type[top_xy] ;
- h->topright_type= s->current_picture.mb_type[topright_xy];
- h->left_type[LTOP] = s->current_picture.mb_type[left_xy[LTOP]] ;
- h->left_type[LBOT] = s->current_picture.mb_type[left_xy[LBOT]] ;
-
- if(FMO){
- if(h->slice_table[topleft_xy ] != h->slice_num) h->topleft_type = 0;
- if(h->slice_table[top_xy ] != h->slice_num) h->top_type = 0;
- if(h->slice_table[left_xy[LTOP] ] != h->slice_num) h->left_type[LTOP] = h->left_type[LBOT] = 0;
- }else{
- if(h->slice_table[topleft_xy ] != h->slice_num){
- h->topleft_type = 0;
- if(h->slice_table[top_xy ] != h->slice_num) h->top_type = 0;
- if(h->slice_table[left_xy[LTOP] ] != h->slice_num) h->left_type[LTOP] = h->left_type[LBOT] = 0;
- }
- }
- if(h->slice_table[topright_xy] != h->slice_num) h->topright_type= 0;
-}
-
-static void fill_decode_caches(H264Context *h, int mb_type){
- MpegEncContext * const s = &h->s;
- int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS];
- int topleft_type, top_type, topright_type, left_type[LEFT_MBS];
- const uint8_t * left_block= h->left_block;
- int i;
- uint8_t *nnz;
- uint8_t *nnz_cache;
-
- topleft_xy = h->topleft_mb_xy;
- top_xy = h->top_mb_xy;
- topright_xy = h->topright_mb_xy;
- left_xy[LTOP] = h->left_mb_xy[LTOP];
- left_xy[LBOT] = h->left_mb_xy[LBOT];
- topleft_type = h->topleft_type;
- top_type = h->top_type;
- topright_type = h->topright_type;
- left_type[LTOP]= h->left_type[LTOP];
- left_type[LBOT]= h->left_type[LBOT];
-
- if(!IS_SKIP(mb_type)){
- if(IS_INTRA(mb_type)){
- int type_mask= h->pps.constrained_intra_pred ? IS_INTRA(-1) : -1;
- h->topleft_samples_available=
- h->top_samples_available=
- h->left_samples_available= 0xFFFF;
- h->topright_samples_available= 0xEEEA;
-
- if(!(top_type & type_mask)){
- h->topleft_samples_available= 0xB3FF;
- h->top_samples_available= 0x33FF;
- h->topright_samples_available= 0x26EA;
- }
- if(IS_INTERLACED(mb_type) != IS_INTERLACED(left_type[LTOP])){
- if(IS_INTERLACED(mb_type)){
- if(!(left_type[LTOP] & type_mask)){
- h->topleft_samples_available&= 0xDFFF;
- h->left_samples_available&= 0x5FFF;
- }
- if(!(left_type[LBOT] & type_mask)){
- h->topleft_samples_available&= 0xFF5F;
- h->left_samples_available&= 0xFF5F;
- }
- }else{
- int left_typei = s->current_picture.mb_type[left_xy[LTOP] + s->mb_stride];
-
- assert(left_xy[LTOP] == left_xy[LBOT]);
- if(!((left_typei & type_mask) && (left_type[LTOP] & type_mask))){
- h->topleft_samples_available&= 0xDF5F;
- h->left_samples_available&= 0x5F5F;
- }
- }
- }else{
- if(!(left_type[LTOP] & type_mask)){
- h->topleft_samples_available&= 0xDF5F;
- h->left_samples_available&= 0x5F5F;
- }
- }
-
- if(!(topleft_type & type_mask))
- h->topleft_samples_available&= 0x7FFF;
-
- if(!(topright_type & type_mask))
- h->topright_samples_available&= 0xFBFF;
-
- if(IS_INTRA4x4(mb_type)){
- if(IS_INTRA4x4(top_type)){
- AV_COPY32(h->intra4x4_pred_mode_cache+4+8*0, h->intra4x4_pred_mode + h->mb2br_xy[top_xy]);
- }else{
- h->intra4x4_pred_mode_cache[4+8*0]=
- h->intra4x4_pred_mode_cache[5+8*0]=
- h->intra4x4_pred_mode_cache[6+8*0]=
- h->intra4x4_pred_mode_cache[7+8*0]= 2 - 3*!(top_type & type_mask);
- }
- for(i=0; i<2; i++){
- if(IS_INTRA4x4(left_type[LEFT(i)])){
- int8_t *mode= h->intra4x4_pred_mode + h->mb2br_xy[left_xy[LEFT(i)]];
- h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]= mode[6-left_block[0+2*i]];
- h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= mode[6-left_block[1+2*i]];
- }else{
- h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]=
- h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= 2 - 3*!(left_type[LEFT(i)] & type_mask);
- }
- }
- }
- }
-
-
-/*
-0 . T T. T T T T
-1 L . .L . . . .
-2 L . .L . . . .
-3 . T TL . . . .
-4 L . .L . . . .
-5 L . .. . . . .
-*/
-//FIXME constraint_intra_pred & partitioning & nnz (let us hope this is just a typo in the spec)
- nnz_cache = h->non_zero_count_cache;
- if(top_type){
- nnz = h->non_zero_count[top_xy];
- AV_COPY32(&nnz_cache[4+8* 0], &nnz[4*3]);
- if(CHROMA444){
- AV_COPY32(&nnz_cache[4+8* 5], &nnz[4* 7]);
- AV_COPY32(&nnz_cache[4+8*10], &nnz[4*11]);
- }else{
- AV_COPY32(&nnz_cache[4+8* 5], &nnz[4* 5]);
- AV_COPY32(&nnz_cache[4+8*10], &nnz[4* 9]);
- }
- }else{
- uint32_t top_empty = CABAC && !IS_INTRA(mb_type) ? 0 : 0x40404040;
- AV_WN32A(&nnz_cache[4+8* 0], top_empty);
- AV_WN32A(&nnz_cache[4+8* 5], top_empty);
- AV_WN32A(&nnz_cache[4+8*10], top_empty);
- }
-
- for (i=0; i<2; i++) {
- if(left_type[LEFT(i)]){
- nnz = h->non_zero_count[left_xy[LEFT(i)]];
- nnz_cache[3+8* 1 + 2*8*i]= nnz[left_block[8+0+2*i]];
- nnz_cache[3+8* 2 + 2*8*i]= nnz[left_block[8+1+2*i]];
- if(CHROMA444){
- nnz_cache[3+8* 6 + 2*8*i]= nnz[left_block[8+0+2*i]+4*4];
- nnz_cache[3+8* 7 + 2*8*i]= nnz[left_block[8+1+2*i]+4*4];
- nnz_cache[3+8*11 + 2*8*i]= nnz[left_block[8+0+2*i]+8*4];
- nnz_cache[3+8*12 + 2*8*i]= nnz[left_block[8+1+2*i]+8*4];
- }else{
- nnz_cache[3+8* 6 + 8*i]= nnz[left_block[8+4+2*i]];
- nnz_cache[3+8*11 + 8*i]= nnz[left_block[8+5+2*i]];
- }
- }else{
- nnz_cache[3+8* 1 + 2*8*i]=
- nnz_cache[3+8* 2 + 2*8*i]=
- nnz_cache[3+8* 6 + 2*8*i]=
- nnz_cache[3+8* 7 + 2*8*i]=
- nnz_cache[3+8*11 + 2*8*i]=
- nnz_cache[3+8*12 + 2*8*i]= CABAC && !IS_INTRA(mb_type) ? 0 : 64;
- }
- }
-
- if( CABAC ) {
- // top_cbp
- if(top_type) {
- h->top_cbp = h->cbp_table[top_xy];
- } else {
- h->top_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F;
- }
- // left_cbp
- if (left_type[LTOP]) {
- h->left_cbp = (h->cbp_table[left_xy[LTOP]] & 0x7F0)
- | ((h->cbp_table[left_xy[LTOP]]>>(left_block[0]&(~1)))&2)
- | (((h->cbp_table[left_xy[LBOT]]>>(left_block[2]&(~1)))&2) << 2);
- } else {
- h->left_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F;
- }
- }
- }
-
- if(IS_INTER(mb_type) || (IS_DIRECT(mb_type) && h->direct_spatial_mv_pred)){
- int list;
- int b_stride = h->b_stride;
- for(list=0; list<h->list_count; list++){
- int8_t *ref_cache = &h->ref_cache[list][scan8[0]];
- int8_t *ref = s->current_picture.ref_index[list];
- int16_t (*mv_cache)[2] = &h->mv_cache[list][scan8[0]];
- int16_t (*mv)[2] = s->current_picture.motion_val[list];
- if(!USES_LIST(mb_type, list)){
- continue;
- }
- assert(!(IS_DIRECT(mb_type) && !h->direct_spatial_mv_pred));
-
- if(USES_LIST(top_type, list)){
- const int b_xy= h->mb2b_xy[top_xy] + 3*b_stride;
- AV_COPY128(mv_cache[0 - 1*8], mv[b_xy + 0]);
- ref_cache[0 - 1*8]=
- ref_cache[1 - 1*8]= ref[4*top_xy + 2];
- ref_cache[2 - 1*8]=
- ref_cache[3 - 1*8]= ref[4*top_xy + 3];
- }else{
- AV_ZERO128(mv_cache[0 - 1*8]);
- AV_WN32A(&ref_cache[0 - 1*8], ((top_type ? LIST_NOT_USED : PART_NOT_AVAILABLE)&0xFF)*0x01010101);
- }
-
- if(mb_type & (MB_TYPE_16x8|MB_TYPE_8x8)){
- for(i=0; i<2; i++){
- int cache_idx = -1 + i*2*8;
- if(USES_LIST(left_type[LEFT(i)], list)){
- const int b_xy= h->mb2b_xy[left_xy[LEFT(i)]] + 3;
- const int b8_xy= 4*left_xy[LEFT(i)] + 1;
- AV_COPY32(mv_cache[cache_idx ], mv[b_xy + b_stride*left_block[0+i*2]]);
- AV_COPY32(mv_cache[cache_idx+8], mv[b_xy + b_stride*left_block[1+i*2]]);
- ref_cache[cache_idx ]= ref[b8_xy + (left_block[0+i*2]&~1)];
- ref_cache[cache_idx+8]= ref[b8_xy + (left_block[1+i*2]&~1)];
- }else{
- AV_ZERO32(mv_cache[cache_idx ]);
- AV_ZERO32(mv_cache[cache_idx+8]);
- ref_cache[cache_idx ]=
- ref_cache[cache_idx+8]= (left_type[LEFT(i)]) ? LIST_NOT_USED : PART_NOT_AVAILABLE;
- }
- }
- }else{
- if(USES_LIST(left_type[LTOP], list)){
- const int b_xy= h->mb2b_xy[left_xy[LTOP]] + 3;
- const int b8_xy= 4*left_xy[LTOP] + 1;
- AV_COPY32(mv_cache[-1], mv[b_xy + b_stride*left_block[0]]);
- ref_cache[-1]= ref[b8_xy + (left_block[0]&~1)];
- }else{
- AV_ZERO32(mv_cache[-1]);
- ref_cache[-1]= left_type[LTOP] ? LIST_NOT_USED : PART_NOT_AVAILABLE;
- }
- }
-
- if(USES_LIST(topright_type, list)){
- const int b_xy= h->mb2b_xy[topright_xy] + 3*b_stride;
- AV_COPY32(mv_cache[4 - 1*8], mv[b_xy]);
- ref_cache[4 - 1*8]= ref[4*topright_xy + 2];
- }else{
- AV_ZERO32(mv_cache[4 - 1*8]);
- ref_cache[4 - 1*8]= topright_type ? LIST_NOT_USED : PART_NOT_AVAILABLE;
- }
- if(ref_cache[4 - 1*8] < 0){
- if(USES_LIST(topleft_type, list)){
- const int b_xy = h->mb2b_xy[topleft_xy] + 3 + b_stride + (h->topleft_partition & 2*b_stride);
- const int b8_xy= 4*topleft_xy + 1 + (h->topleft_partition & 2);
- AV_COPY32(mv_cache[-1 - 1*8], mv[b_xy]);
- ref_cache[-1 - 1*8]= ref[b8_xy];
- }else{
- AV_ZERO32(mv_cache[-1 - 1*8]);
- ref_cache[-1 - 1*8]= topleft_type ? LIST_NOT_USED : PART_NOT_AVAILABLE;
- }
- }
-
- if((mb_type&(MB_TYPE_SKIP|MB_TYPE_DIRECT2)) && !FRAME_MBAFF)
- continue;
-
- if(!(mb_type&(MB_TYPE_SKIP|MB_TYPE_DIRECT2))){
- uint8_t (*mvd_cache)[2] = &h->mvd_cache[list][scan8[0]];
- uint8_t (*mvd)[2] = h->mvd_table[list];
- ref_cache[2+8*0] =
- ref_cache[2+8*2] = PART_NOT_AVAILABLE;
- AV_ZERO32(mv_cache[2+8*0]);
- AV_ZERO32(mv_cache[2+8*2]);
-
- if( CABAC ) {
- if(USES_LIST(top_type, list)){
- const int b_xy= h->mb2br_xy[top_xy];
- AV_COPY64(mvd_cache[0 - 1*8], mvd[b_xy + 0]);
- }else{
- AV_ZERO64(mvd_cache[0 - 1*8]);
- }
- if(USES_LIST(left_type[LTOP], list)){
- const int b_xy= h->mb2br_xy[left_xy[LTOP]] + 6;
- AV_COPY16(mvd_cache[-1 + 0*8], mvd[b_xy - left_block[0]]);
- AV_COPY16(mvd_cache[-1 + 1*8], mvd[b_xy - left_block[1]]);
- }else{
- AV_ZERO16(mvd_cache[-1 + 0*8]);
- AV_ZERO16(mvd_cache[-1 + 1*8]);
- }
- if(USES_LIST(left_type[LBOT], list)){
- const int b_xy= h->mb2br_xy[left_xy[LBOT]] + 6;
- AV_COPY16(mvd_cache[-1 + 2*8], mvd[b_xy - left_block[2]]);
- AV_COPY16(mvd_cache[-1 + 3*8], mvd[b_xy - left_block[3]]);
- }else{
- AV_ZERO16(mvd_cache[-1 + 2*8]);
- AV_ZERO16(mvd_cache[-1 + 3*8]);
- }
- AV_ZERO16(mvd_cache[2+8*0]);
- AV_ZERO16(mvd_cache[2+8*2]);
- if(h->slice_type_nos == AV_PICTURE_TYPE_B){
- uint8_t *direct_cache = &h->direct_cache[scan8[0]];
- uint8_t *direct_table = h->direct_table;
- fill_rectangle(direct_cache, 4, 4, 8, MB_TYPE_16x16>>1, 1);
-
- if(IS_DIRECT(top_type)){
- AV_WN32A(&direct_cache[-1*8], 0x01010101u*(MB_TYPE_DIRECT2>>1));
- }else if(IS_8X8(top_type)){
- int b8_xy = 4*top_xy;
- direct_cache[0 - 1*8]= direct_table[b8_xy + 2];
- direct_cache[2 - 1*8]= direct_table[b8_xy + 3];
- }else{
- AV_WN32A(&direct_cache[-1*8], 0x01010101*(MB_TYPE_16x16>>1));
- }
-
- if(IS_DIRECT(left_type[LTOP]))
- direct_cache[-1 + 0*8]= MB_TYPE_DIRECT2>>1;
- else if(IS_8X8(left_type[LTOP]))
- direct_cache[-1 + 0*8]= direct_table[4*left_xy[LTOP] + 1 + (left_block[0]&~1)];
- else
- direct_cache[-1 + 0*8]= MB_TYPE_16x16>>1;
-
- if(IS_DIRECT(left_type[LBOT]))
- direct_cache[-1 + 2*8]= MB_TYPE_DIRECT2>>1;
- else if(IS_8X8(left_type[LBOT]))
- direct_cache[-1 + 2*8]= direct_table[4*left_xy[LBOT] + 1 + (left_block[2]&~1)];
- else
- direct_cache[-1 + 2*8]= MB_TYPE_16x16>>1;
- }
- }
- }
- if(FRAME_MBAFF){
-#define MAP_MVS\
- MAP_F2F(scan8[0] - 1 - 1*8, topleft_type)\
- MAP_F2F(scan8[0] + 0 - 1*8, top_type)\
- MAP_F2F(scan8[0] + 1 - 1*8, top_type)\
- MAP_F2F(scan8[0] + 2 - 1*8, top_type)\
- MAP_F2F(scan8[0] + 3 - 1*8, top_type)\
- MAP_F2F(scan8[0] + 4 - 1*8, topright_type)\
- MAP_F2F(scan8[0] - 1 + 0*8, left_type[LTOP])\
- MAP_F2F(scan8[0] - 1 + 1*8, left_type[LTOP])\
- MAP_F2F(scan8[0] - 1 + 2*8, left_type[LBOT])\
- MAP_F2F(scan8[0] - 1 + 3*8, left_type[LBOT])
- if(MB_FIELD){
-#define MAP_F2F(idx, mb_type)\
- if(!IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0){\
- h->ref_cache[list][idx] <<= 1;\
- h->mv_cache[list][idx][1] /= 2;\
- h->mvd_cache[list][idx][1] >>=1;\
- }
- MAP_MVS
-#undef MAP_F2F
- }else{
-#define MAP_F2F(idx, mb_type)\
- if(IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0){\
- h->ref_cache[list][idx] >>= 1;\
- h->mv_cache[list][idx][1] <<= 1;\
- h->mvd_cache[list][idx][1] <<= 1;\
- }
- MAP_MVS
-#undef MAP_F2F
- }
- }
- }
- }
-
- h->neighbor_transform_size= !!IS_8x8DCT(top_type) + !!IS_8x8DCT(left_type[LTOP]);
-}
-
/**
* gets the predicted intra4x4 prediction mode.
*/
@@ -1229,7 +823,7 @@ static av_always_inline void write_back_non_zero_count(H264Context *h){
AV_COPY32(&nnz[32], &nnz_cache[4+8*11]);
AV_COPY32(&nnz[36], &nnz_cache[4+8*12]);
- if(CHROMA444){
+ if(!h->s.chroma_y_shift){
AV_COPY32(&nnz[24], &nnz_cache[4+8* 8]);
AV_COPY32(&nnz[28], &nnz_cache[4+8* 9]);
AV_COPY32(&nnz[40], &nnz_cache[4+8*13]);
@@ -1240,7 +834,7 @@ static av_always_inline void write_back_non_zero_count(H264Context *h){
static av_always_inline void write_back_motion_list(H264Context *h, MpegEncContext * const s, int b_stride,
int b_xy, int b8_xy, int mb_type, int list )
{
- int16_t (*mv_dst)[2] = &s->current_picture.motion_val[list][b_xy];
+ int16_t (*mv_dst)[2] = &s->current_picture.f.motion_val[list][b_xy];
int16_t (*mv_src)[2] = &h->mv_cache[list][scan8[0]];
AV_COPY128(mv_dst + 0*b_stride, mv_src + 8*0);
AV_COPY128(mv_dst + 1*b_stride, mv_src + 8*1);
@@ -1260,7 +854,7 @@ static av_always_inline void write_back_motion_list(H264Context *h, MpegEncConte
}
{
- int8_t *ref_index = &s->current_picture.ref_index[list][b8_xy];
+ int8_t *ref_index = &s->current_picture.f.ref_index[list][b8_xy];
int8_t *ref_cache = h->ref_cache[list];
ref_index[0+0*2]= ref_cache[scan8[0]];
ref_index[1+0*2]= ref_cache[scan8[4]];
@@ -1278,7 +872,8 @@ static av_always_inline void write_back_motion(H264Context *h, int mb_type){
if(USES_LIST(mb_type, 0)){
write_back_motion_list(h, s, b_stride, b_xy, b8_xy, mb_type, 0);
}else{
- fill_rectangle(&s->current_picture.ref_index[0][b8_xy], 2, 2, 2, (uint8_t)LIST_NOT_USED, 1);
+ fill_rectangle(&s->current_picture.f.ref_index[0][b8_xy],
+ 2, 2, 2, (uint8_t)LIST_NOT_USED, 1);
}
if(USES_LIST(mb_type, 1)){
write_back_motion_list(h, s, b_stride, b_xy, b8_xy, mb_type, 1);
@@ -1301,49 +896,4 @@ static av_always_inline int get_dct8x8_allowed(H264Context *h){
return !(AV_RN64A(h->sub_mb_type) & ((MB_TYPE_16x8|MB_TYPE_8x16|MB_TYPE_8x8|MB_TYPE_DIRECT2)*0x0001000100010001ULL));
}
-/**
- * decodes a P_SKIP or B_SKIP macroblock
- */
-static void av_unused decode_mb_skip(H264Context *h){
- MpegEncContext * const s = &h->s;
- const int mb_xy= h->mb_xy;
- int mb_type=0;
-
- memset(h->non_zero_count[mb_xy], 0, 48);
-
- if(MB_FIELD)
- mb_type|= MB_TYPE_INTERLACED;
-
- if( h->slice_type_nos == AV_PICTURE_TYPE_B )
- {
- // just for fill_caches. pred_direct_motion will set the real mb_type
- mb_type|= MB_TYPE_L0L1|MB_TYPE_DIRECT2|MB_TYPE_SKIP;
- if(h->direct_spatial_mv_pred){
- fill_decode_neighbors(h, mb_type);
- fill_decode_caches(h, mb_type); //FIXME check what is needed and what not ...
- }
- ff_h264_pred_direct_motion(h, &mb_type);
- mb_type|= MB_TYPE_SKIP;
- }
- else
- {
- int mx, my;
- mb_type|= MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P1L0|MB_TYPE_SKIP;
-
- fill_decode_neighbors(h, mb_type);
- fill_decode_caches(h, mb_type); //FIXME check what is needed and what not ...
- pred_pskip_motion(h, &mx, &my);
- fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, 0, 1);
- fill_rectangle( h->mv_cache[0][scan8[0]], 4, 4, 8, pack16to32(mx,my), 4);
- }
-
- write_back_motion(h, mb_type);
- s->current_picture.mb_type[mb_xy]= mb_type;
- s->current_picture.qscale_table[mb_xy]= s->qscale;
- h->slice_table[ mb_xy ]= h->slice_num;
- h->prev_mb_skipped= 1;
-}
-
-#include "h264_mvpred.h" //For pred_pskip_motion()
-
#endif /* AVCODEC_H264_H */
diff --git a/libavcodec/h264_cabac.c b/libavcodec/h264_cabac.c
index 6dacf7a336..31c2658a6b 100644
--- a/libavcodec/h264_cabac.c
+++ b/libavcodec/h264_cabac.c
@@ -2,20 +2,20 @@
* H.26L/H.264/AVC/JVT/14496-10/... cabac decoding
* Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -1284,8 +1284,8 @@ static int decode_cabac_field_decoding_flag(H264Context *h) {
unsigned long ctx = 0;
- ctx += h->mb_field_decoding_flag & !!s->mb_x; //for FMO:(s->current_picture.mb_type[mba_xy]>>7)&(h->slice_table[mba_xy] == h->slice_num);
- ctx += (s->current_picture.mb_type[mbb_xy]>>7)&(h->slice_table[mbb_xy] == h->slice_num);
+ ctx += h->mb_field_decoding_flag & !!s->mb_x; //for FMO:(s->current_picture.f.mb_type[mba_xy] >> 7) & (h->slice_table[mba_xy] == h->slice_num);
+ ctx += (s->current_picture.f.mb_type[mbb_xy] >> 7) & (h->slice_table[mbb_xy] == h->slice_num);
return get_cabac_noinline( &h->cabac, &(h->cabac_state+70)[ctx] );
}
@@ -1330,13 +1330,13 @@ static int decode_cabac_mb_skip( H264Context *h, int mb_x, int mb_y ) {
mba_xy = mb_xy - 1;
if( (mb_y&1)
&& h->slice_table[mba_xy] == h->slice_num
- && MB_FIELD == !!IS_INTERLACED( s->current_picture.mb_type[mba_xy] ) )
+ && MB_FIELD == !!IS_INTERLACED( s->current_picture.f.mb_type[mba_xy] ) )
mba_xy += s->mb_stride;
if( MB_FIELD ){
mbb_xy = mb_xy - s->mb_stride;
if( !(mb_y&1)
&& h->slice_table[mbb_xy] == h->slice_num
- && IS_INTERLACED( s->current_picture.mb_type[mbb_xy] ) )
+ && IS_INTERLACED( s->current_picture.f.mb_type[mbb_xy] ) )
mbb_xy -= s->mb_stride;
}else
mbb_xy = mb_x + (mb_y-1)*s->mb_stride;
@@ -1346,9 +1346,9 @@ static int decode_cabac_mb_skip( H264Context *h, int mb_x, int mb_y ) {
mbb_xy = mb_xy - (s->mb_stride << FIELD_PICTURE);
}
- if( h->slice_table[mba_xy] == h->slice_num && !IS_SKIP( s->current_picture.mb_type[mba_xy] ))
+ if( h->slice_table[mba_xy] == h->slice_num && !IS_SKIP( s->current_picture.f.mb_type[mba_xy] ))
ctx++;
- if( h->slice_table[mbb_xy] == h->slice_num && !IS_SKIP( s->current_picture.mb_type[mbb_xy] ))
+ if( h->slice_table[mbb_xy] == h->slice_num && !IS_SKIP( s->current_picture.f.mb_type[mbb_xy] ))
ctx++;
if( h->slice_type_nos == AV_PICTURE_TYPE_B )
@@ -1565,7 +1565,12 @@ DECLARE_ASM_CONST(1, uint8_t, last_coeff_flag_offset_8x8)[63] = {
5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8
};
-static av_always_inline void decode_cabac_residual_internal( H264Context *h, DCTELEM *block, int cat, int n, const uint8_t *scantable, const uint32_t *qmul, int max_coeff, int is_dc ) {
+static av_always_inline void
+decode_cabac_residual_internal(H264Context *h, DCTELEM *block,
+ int cat, int n, const uint8_t *scantable,
+ const uint32_t *qmul, int max_coeff,
+ int is_dc, int chroma422)
+{
static const int significant_coeff_flag_offset[2][14] = {
{ 105+0, 105+15, 105+29, 105+44, 105+47, 402, 484+0, 484+15, 484+29, 660, 528+0, 528+15, 528+29, 718 },
{ 277+0, 277+15, 277+29, 277+44, 277+47, 436, 776+0, 776+15, 776+29, 675, 820+0, 820+15, 820+29, 733 }
@@ -1587,12 +1592,16 @@ static av_always_inline void decode_cabac_residual_internal( H264Context *h, DCT
9, 9,10,10, 8,11,12,11, 9, 9,10,10, 8,13,13, 9,
9,10,10, 8,13,13, 9, 9,10,10,14,14,14,14,14 }
};
+ static const uint8_t sig_coeff_offset_dc[7] = { 0, 0, 1, 1, 2, 2, 2 };
/* node ctx: 0..3: abslevel1 (with abslevelgt1 == 0).
* 4..7: abslevelgt1 + 3 (and abslevel1 doesn't matter).
* map node ctx => cabac ctx for level=1 */
static const uint8_t coeff_abs_level1_ctx[8] = { 1, 2, 3, 4, 0, 0, 0, 0 };
/* map node ctx => cabac ctx for level>1 */
- static const uint8_t coeff_abs_levelgt1_ctx[8] = { 5, 5, 5, 5, 6, 7, 8, 9 };
+ static const uint8_t coeff_abs_levelgt1_ctx[2][8] = {
+ { 5, 5, 5, 5, 6, 7, 8, 9 },
+ { 5, 5, 5, 5, 6, 7, 8, 8 }, // 422/dc case
+ };
static const uint8_t coeff_abs_level_transition[2][8] = {
/* update node ctx after decoding a level=1 */
{ 1, 2, 3, 3, 4, 5, 6, 7 },
@@ -1649,14 +1658,22 @@ static av_always_inline void decode_cabac_residual_internal( H264Context *h, DCT
const uint8_t *sig_off = significant_coeff_flag_offset_8x8[MB_FIELD];
#if ARCH_X86 && HAVE_7REGS && HAVE_EBX_AVAILABLE && !defined(BROKEN_RELOCATIONS)
coeff_count= decode_significance_8x8_x86(CC, significant_coeff_ctx_base, index,
- last_coeff_ctx_base-significant_coeff_ctx_base, sig_off);
+ last_coeff_ctx_base, sig_off);
} else {
- coeff_count= decode_significance_x86(CC, max_coeff, significant_coeff_ctx_base, index,
- last_coeff_ctx_base-significant_coeff_ctx_base);
+ if (is_dc && chroma422) { // dc 422
+ DECODE_SIGNIFICANCE(7, sig_coeff_offset_dc[last], sig_coeff_offset_dc[last]);
+ } else {
+ coeff_count= decode_significance_x86(CC, max_coeff, significant_coeff_ctx_base, index,
+ last_coeff_ctx_base-significant_coeff_ctx_base);
+ }
#else
DECODE_SIGNIFICANCE( 63, sig_off[last], last_coeff_flag_offset_8x8[last] );
} else {
- DECODE_SIGNIFICANCE( max_coeff - 1, last, last );
+ if (is_dc && chroma422) { // dc 422
+ DECODE_SIGNIFICANCE(7, sig_coeff_offset_dc[last], sig_coeff_offset_dc[last]);
+ } else {
+ DECODE_SIGNIFICANCE(max_coeff - 1, last, last);
+ }
#endif
}
assert(coeff_count > 0);
@@ -1676,6 +1693,7 @@ static av_always_inline void decode_cabac_residual_internal( H264Context *h, DCT
}
}
+
#define STORE_BLOCK(type) \
do { \
uint8_t *ctx = coeff_abs_level1_ctx[node_ctx] + abs_level_m1_ctx_base; \
@@ -1691,7 +1709,7 @@ static av_always_inline void decode_cabac_residual_internal( H264Context *h, DCT
} \
} else { \
int coeff_abs = 2; \
- ctx = coeff_abs_levelgt1_ctx[node_ctx] + abs_level_m1_ctx_base; \
+ ctx = coeff_abs_levelgt1_ctx[is_dc && chroma422][node_ctx] + abs_level_m1_ctx_base; \
node_ctx = coeff_abs_level_transition[1][node_ctx]; \
\
while( coeff_abs < 15 && get_cabac( CC, ctx ) ) { \
@@ -1719,11 +1737,11 @@ static av_always_inline void decode_cabac_residual_internal( H264Context *h, DCT
} \
} while ( coeff_count );
- if (h->pixel_shift) {
- STORE_BLOCK(int32_t)
- } else {
- STORE_BLOCK(int16_t)
- }
+ if (h->pixel_shift) {
+ STORE_BLOCK(int32_t)
+ } else {
+ STORE_BLOCK(int16_t)
+ }
#ifdef CABAC_ON_STACK
h->cabac.range = cc.range ;
h->cabac.low = cc.low ;
@@ -1733,11 +1751,18 @@ static av_always_inline void decode_cabac_residual_internal( H264Context *h, DCT
}
static void decode_cabac_residual_dc_internal( H264Context *h, DCTELEM *block, int cat, int n, const uint8_t *scantable, int max_coeff ) {
- decode_cabac_residual_internal(h, block, cat, n, scantable, NULL, max_coeff, 1);
+ decode_cabac_residual_internal(h, block, cat, n, scantable, NULL, max_coeff, 1, 0);
+}
+
+static void decode_cabac_residual_dc_internal_422(H264Context *h, DCTELEM *block,
+ int cat, int n, const uint8_t *scantable,
+ int max_coeff)
+{
+ decode_cabac_residual_internal(h, block, cat, n, scantable, NULL, max_coeff, 1, 1);
}
static void decode_cabac_residual_nondc_internal( H264Context *h, DCTELEM *block, int cat, int n, const uint8_t *scantable, const uint32_t *qmul, int max_coeff ) {
- decode_cabac_residual_internal(h, block, cat, n, scantable, qmul, max_coeff, 0);
+ decode_cabac_residual_internal(h, block, cat, n, scantable, qmul, max_coeff, 0, 0);
}
/* cat: 0-> DC 16x16 n = 0
@@ -1761,6 +1786,19 @@ static av_always_inline void decode_cabac_residual_dc( H264Context *h, DCTELEM *
decode_cabac_residual_dc_internal( h, block, cat, n, scantable, max_coeff );
}
+static av_always_inline void
+decode_cabac_residual_dc_422(H264Context *h, DCTELEM *block,
+ int cat, int n, const uint8_t *scantable,
+ int max_coeff)
+{
+ /* read coded block flag */
+ if (get_cabac(&h->cabac, &h->cabac_state[get_cabac_cbf_ctx(h, cat, n, max_coeff, 1)]) == 0) {
+ h->non_zero_count_cache[scan8[n]] = 0;
+ return;
+ }
+ decode_cabac_residual_dc_internal_422(h, block, cat, n, scantable, max_coeff);
+}
+
static av_always_inline void decode_cabac_residual_nondc( H264Context *h, DCTELEM *block, int cat, int n, const uint8_t *scantable, const uint32_t *qmul, int max_coeff ) {
/* read coded block flag */
if( (cat != 5 || CHROMA444) && get_cabac( &h->cabac, &h->cabac_state[get_cabac_cbf_ctx( h, cat, n, max_coeff, 0 ) ] ) == 0 ) {
@@ -1818,8 +1856,7 @@ static av_always_inline void decode_cabac_luma_residual( H264Context *h, const u
}
}
} else {
- uint8_t * const nnz= &h->non_zero_count_cache[ scan8[4*i8x8+16*p] ];
- nnz[0] = nnz[1] = nnz[8] = nnz[9] = 0;
+ fill_rectangle(&h->non_zero_count_cache[scan8[4*i8x8+16*p]], 2, 2, 8, 0, 1);
}
}
}
@@ -1850,7 +1887,7 @@ int ff_h264_decode_mb_cabac(H264Context *h) {
/* read skip flags */
if( skip ) {
if( FRAME_MBAFF && (s->mb_y&1)==0 ){
- s->current_picture.mb_type[mb_xy] = MB_TYPE_SKIP;
+ s->current_picture.f.mb_type[mb_xy] = MB_TYPE_SKIP;
h->next_mb_skipped = decode_cabac_mb_skip( h, s->mb_x, s->mb_y+1 );
if(!h->next_mb_skipped)
h->mb_mbaff = h->mb_field_decoding_flag = decode_cabac_field_decoding_flag(h);
@@ -1966,10 +2003,10 @@ decode_intra_mb:
h->cbp_table[mb_xy] = 0xf7ef;
h->chroma_pred_mode_table[mb_xy] = 0;
// In deblocking, the quantizer is 0
- s->current_picture.qscale_table[mb_xy]= 0;
+ s->current_picture.f.qscale_table[mb_xy] = 0;
// All coeffs are present
memset(h->non_zero_count[mb_xy], 16, 48);
- s->current_picture.mb_type[mb_xy]= mb_type;
+ s->current_picture.f.mb_type[mb_xy] = mb_type;
h->last_qscale_diff = 0;
return 0;
}
@@ -2002,14 +2039,14 @@ decode_intra_mb:
write_back_intra_pred_mode(h);
if( ff_h264_check_intra4x4_pred_mode(h) < 0 ) return -1;
} else {
- h->intra16x16_pred_mode= ff_h264_check_intra_pred_mode( h, h->intra16x16_pred_mode );
+ h->intra16x16_pred_mode= ff_h264_check_intra16x16_pred_mode( h, h->intra16x16_pred_mode );
if( h->intra16x16_pred_mode < 0 ) return -1;
}
if(decode_chroma){
h->chroma_pred_mode_table[mb_xy] =
pred_mode = decode_cabac_mb_chroma_pre_mode( h );
- pred_mode= ff_h264_check_intra_pred_mode( h, pred_mode );
+ pred_mode= ff_h264_check_intra_chroma_pred_mode( h, pred_mode );
if( pred_mode < 0 ) return -1;
h->chroma_pred_mode= pred_mode;
} else {
@@ -2266,7 +2303,7 @@ decode_intra_mb:
AV_WN32A(&nnz_cache[4+8*10], top_empty);
}
}
- s->current_picture.mb_type[mb_xy]= mb_type;
+ s->current_picture.f.mb_type[mb_xy] = mb_type;
if( cbp || IS_INTRA16x16( mb_type ) ) {
const uint8_t *scan, *scan8x8;
@@ -2314,7 +2351,36 @@ decode_intra_mb:
if(CHROMA444){
decode_cabac_luma_residual(h, scan, scan8x8, pixel_shift, mb_type, cbp, 1);
decode_cabac_luma_residual(h, scan, scan8x8, pixel_shift, mb_type, cbp, 2);
- } else {
+ } else if (CHROMA422) {
+ if( cbp&0x30 ){
+ int c;
+ for( c = 0; c < 2; c++ ) {
+ //av_log( s->avctx, AV_LOG_ERROR, "INTRA C%d-DC\n",c );
+ decode_cabac_residual_dc_422(h, h->mb + ((256 + 16*16*c) << pixel_shift), 3,
+ CHROMA_DC_BLOCK_INDEX + c,
+ chroma422_dc_scan, 8);
+ }
+ }
+
+ if( cbp&0x20 ) {
+ int c, i, i8x8;
+ for( c = 0; c < 2; c++ ) {
+ DCTELEM *mb = h->mb + (16*(16 + 16*c) << pixel_shift);
+ qmul = h->dequant4_coeff[c+1+(IS_INTRA( mb_type ) ? 0:3)][h->chroma_qp[c]];
+ for (i8x8 = 0; i8x8 < 2; i8x8++) {
+ for (i = 0; i < 4; i++) {
+ const int index = 16 + 16 * c + 8*i8x8 + i;
+ //av_log(s->avctx, AV_LOG_ERROR, "INTRA C%d-AC %d\n",c, index - 16);
+ decode_cabac_residual_nondc(h, mb, 4, index, scan + 1, qmul, 15);
+ mb += 16<<pixel_shift;
+ }
+ }
+ }
+ } else {
+ fill_rectangle(&h->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1);
+ fill_rectangle(&h->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1);
+ }
+ } else /* yuv420 */ {
if( cbp&0x30 ){
int c;
for( c = 0; c < 2; c++ ) {
@@ -2345,7 +2411,7 @@ decode_intra_mb:
h->last_qscale_diff = 0;
}
- s->current_picture.qscale_table[mb_xy]= s->qscale;
+ s->current_picture.f.qscale_table[mb_xy] = s->qscale;
write_back_non_zero_count(h);
if(MB_MBAFF){
diff --git a/libavcodec/h264_cavlc.c b/libavcodec/h264_cavlc.c
index 90c411002e..b0dc999132 100644
--- a/libavcodec/h264_cavlc.c
+++ b/libavcodec/h264_cavlc.c
@@ -2,20 +2,20 @@
* H.26L/H.264/AVC/JVT/14496-10/... cavlc bitstream decoding
* Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -62,6 +62,30 @@ static const uint8_t chroma_dc_coeff_token_bits[4*5]={
2, 3, 2, 0,
};
+static const uint8_t chroma422_dc_coeff_token_len[4*9]={
+ 1, 0, 0, 0,
+ 7, 2, 0, 0,
+ 7, 7, 3, 0,
+ 9, 7, 7, 5,
+ 9, 9, 7, 6,
+ 10, 10, 9, 7,
+ 11, 11, 10, 7,
+ 12, 12, 11, 10,
+ 13, 12, 12, 11,
+};
+
+static const uint8_t chroma422_dc_coeff_token_bits[4*9]={
+ 1, 0, 0, 0,
+ 15, 1, 0, 0,
+ 14, 13, 1, 0,
+ 7, 12, 11, 1,
+ 6, 5, 10, 1,
+ 7, 6, 4, 9,
+ 7, 6, 5, 8,
+ 7, 6, 5, 4,
+ 7, 5, 4, 4,
+};
+
static const uint8_t coeff_token_len[4][4*17]={
{
1, 0, 0, 0,
@@ -172,6 +196,26 @@ static const uint8_t chroma_dc_total_zeros_bits[3][4]= {
{ 1, 0, 0, 0,},
};
+static const uint8_t chroma422_dc_total_zeros_len[7][8]= {
+ { 1, 3, 3, 4, 4, 4, 5, 5 },
+ { 3, 2, 3, 3, 3, 3, 3 },
+ { 3, 3, 2, 2, 3, 3 },
+ { 3, 2, 2, 2, 3 },
+ { 2, 2, 2, 2 },
+ { 2, 2, 1 },
+ { 1, 1 },
+};
+
+static const uint8_t chroma422_dc_total_zeros_bits[7][8]= {
+ { 1, 2, 3, 2, 3, 1, 1, 0 },
+ { 0, 1, 1, 4, 5, 6, 7 },
+ { 0, 1, 1, 2, 6, 7 },
+ { 6, 0, 1, 2, 7 },
+ { 0, 1, 2, 3 },
+ { 0, 1, 1 },
+ { 0, 1 },
+};
+
static const uint8_t run_len[7][16]={
{1,1},
{1,2,2},
@@ -200,6 +244,10 @@ static VLC chroma_dc_coeff_token_vlc;
static VLC_TYPE chroma_dc_coeff_token_vlc_table[256][2];
static const int chroma_dc_coeff_token_vlc_table_size = 256;
+static VLC chroma422_dc_coeff_token_vlc;
+static VLC_TYPE chroma422_dc_coeff_token_vlc_table[8192][2];
+static const int chroma422_dc_coeff_token_vlc_table_size = 8192;
+
static VLC total_zeros_vlc[15];
static VLC_TYPE total_zeros_vlc_tables[15][512][2];
static const int total_zeros_vlc_tables_size = 512;
@@ -208,6 +256,10 @@ static VLC chroma_dc_total_zeros_vlc[3];
static VLC_TYPE chroma_dc_total_zeros_vlc_tables[3][8][2];
static const int chroma_dc_total_zeros_vlc_tables_size = 8;
+static VLC chroma422_dc_total_zeros_vlc[7];
+static VLC_TYPE chroma422_dc_total_zeros_vlc_tables[7][32][2];
+static const int chroma422_dc_total_zeros_vlc_tables_size = 32;
+
static VLC run_vlc[6];
static VLC_TYPE run_vlc_tables[6][8][2];
static const int run_vlc_tables_size = 8;
@@ -219,6 +271,14 @@ static const int run7_vlc_table_size = 96;
#define LEVEL_TAB_BITS 8
static int8_t cavlc_level_tab[7][1<<LEVEL_TAB_BITS][2];
+#define CHROMA_DC_COEFF_TOKEN_VLC_BITS 8
+#define CHROMA422_DC_COEFF_TOKEN_VLC_BITS 13
+#define COEFF_TOKEN_VLC_BITS 8
+#define TOTAL_ZEROS_VLC_BITS 9
+#define CHROMA_DC_TOTAL_ZEROS_VLC_BITS 3
+#define CHROMA422_DC_TOTAL_ZEROS_VLC_BITS 5
+#define RUN_VLC_BITS 3
+#define RUN7_VLC_BITS 6
/**
* gets the predicted number of non-zero coefficients.
@@ -238,17 +298,18 @@ static inline int pred_non_zero_count(H264Context *h, int n){
}
static av_cold void init_cavlc_level_tab(void){
- int suffix_length, mask;
+ int suffix_length;
unsigned int i;
for(suffix_length=0; suffix_length<7; suffix_length++){
for(i=0; i<(1<<LEVEL_TAB_BITS); i++){
int prefix= LEVEL_TAB_BITS - av_log2(2*i);
- int level_code= (prefix<<suffix_length) + (i>>(LEVEL_TAB_BITS-prefix-1-suffix_length)) - (1<<suffix_length);
- mask= -(level_code&1);
- level_code= (((2+level_code)>>1) ^ mask) - mask;
if(prefix + 1 + suffix_length <= LEVEL_TAB_BITS){
+ int level_code = (prefix << suffix_length) +
+ (i >> (av_log2(i) - suffix_length)) - (1 << suffix_length);
+ int mask = -(level_code&1);
+ level_code = (((2 + level_code) >> 1) ^ mask) - mask;
cavlc_level_tab[suffix_length][i][0]= level_code;
cavlc_level_tab[suffix_length][i][1]= prefix + 1 + suffix_length;
}else if(prefix + 1 <= LEVEL_TAB_BITS){
@@ -277,6 +338,13 @@ av_cold void ff_h264_decode_init_vlc(void){
&chroma_dc_coeff_token_bits[0], 1, 1,
INIT_VLC_USE_NEW_STATIC);
+ chroma422_dc_coeff_token_vlc.table = chroma422_dc_coeff_token_vlc_table;
+ chroma422_dc_coeff_token_vlc.table_allocated = chroma422_dc_coeff_token_vlc_table_size;
+ init_vlc(&chroma422_dc_coeff_token_vlc, CHROMA422_DC_COEFF_TOKEN_VLC_BITS, 4*9,
+ &chroma422_dc_coeff_token_len [0], 1, 1,
+ &chroma422_dc_coeff_token_bits[0], 1, 1,
+ INIT_VLC_USE_NEW_STATIC);
+
offset = 0;
for(i=0; i<4; i++){
coeff_token_vlc[i].table = coeff_token_vlc_tables+offset;
@@ -303,6 +371,17 @@ av_cold void ff_h264_decode_init_vlc(void){
&chroma_dc_total_zeros_bits[i][0], 1, 1,
INIT_VLC_USE_NEW_STATIC);
}
+
+ for(i=0; i<7; i++){
+ chroma422_dc_total_zeros_vlc[i].table = chroma422_dc_total_zeros_vlc_tables[i];
+ chroma422_dc_total_zeros_vlc[i].table_allocated = chroma422_dc_total_zeros_vlc_tables_size;
+ init_vlc(&chroma422_dc_total_zeros_vlc[i],
+ CHROMA422_DC_TOTAL_ZEROS_VLC_BITS, 8,
+ &chroma422_dc_total_zeros_len [i][0], 1, 1,
+ &chroma422_dc_total_zeros_bits[i][0], 1, 1,
+ INIT_VLC_USE_NEW_STATIC);
+ }
+
for(i=0; i<15; i++){
total_zeros_vlc[i].table = total_zeros_vlc_tables[i];
total_zeros_vlc[i].table_allocated = total_zeros_vlc_tables_size;
@@ -372,7 +451,10 @@ static int decode_residual(H264Context *h, GetBitContext *gb, DCTELEM *block, in
//FIXME put trailing_onex into the context
if(max_coeff <= 8){
- coeff_token= get_vlc2(gb, chroma_dc_coeff_token_vlc.table, CHROMA_DC_COEFF_TOKEN_VLC_BITS, 1);
+ if (max_coeff == 4)
+ coeff_token = get_vlc2(gb, chroma_dc_coeff_token_vlc.table, CHROMA_DC_COEFF_TOKEN_VLC_BITS, 1);
+ else
+ coeff_token = get_vlc2(gb, chroma422_dc_coeff_token_vlc.table, CHROMA422_DC_COEFF_TOKEN_VLC_BITS, 1);
total_coeff= coeff_token>>2;
}else{
if(n >= LUMA_DC_BLOCK_INDEX){
@@ -482,11 +564,16 @@ static int decode_residual(H264Context *h, GetBitContext *gb, DCTELEM *block, in
if(total_coeff == max_coeff)
zeros_left=0;
else{
- /* FIXME: we don't actually support 4:2:2 yet. */
- if(max_coeff <= 8)
- zeros_left= get_vlc2(gb, (chroma_dc_total_zeros_vlc-1)[ total_coeff ].table, CHROMA_DC_TOTAL_ZEROS_VLC_BITS, 1);
- else
+ if (max_coeff <= 8) {
+ if (max_coeff == 4)
+ zeros_left = get_vlc2(gb, (chroma_dc_total_zeros_vlc-1)[total_coeff].table,
+ CHROMA_DC_TOTAL_ZEROS_VLC_BITS, 1);
+ else
+ zeros_left = get_vlc2(gb, (chroma422_dc_total_zeros_vlc-1)[total_coeff].table,
+ CHROMA422_DC_TOTAL_ZEROS_VLC_BITS, 1);
+ } else {
zeros_left= get_vlc2(gb, (total_zeros_vlc-1)[ total_coeff ].table, TOTAL_ZEROS_VLC_BITS, 1);
+ }
}
#define STORE_BLOCK(type) \
@@ -689,11 +776,11 @@ decode_intra_mb:
}
// In deblocking, the quantizer is 0
- s->current_picture.qscale_table[mb_xy]= 0;
+ s->current_picture.f.qscale_table[mb_xy] = 0;
// All coeffs are present
memset(h->non_zero_count[mb_xy], 16, 48);
- s->current_picture.mb_type[mb_xy]= mb_type;
+ s->current_picture.f.mb_type[mb_xy] = mb_type;
return 0;
}
@@ -735,12 +822,12 @@ decode_intra_mb:
if( ff_h264_check_intra4x4_pred_mode(h) < 0)
return -1;
}else{
- h->intra16x16_pred_mode= ff_h264_check_intra_pred_mode(h, h->intra16x16_pred_mode);
+ h->intra16x16_pred_mode= ff_h264_check_intra16x16_pred_mode(h, h->intra16x16_pred_mode);
if(h->intra16x16_pred_mode < 0)
return -1;
}
if(decode_chroma){
- pred_mode= ff_h264_check_intra_pred_mode(h, get_ue_golomb_31(&s->gb));
+ pred_mode= ff_h264_check_intra_chroma_pred_mode(h, get_ue_golomb_31(&s->gb));
if(pred_mode < 0)
return -1;
h->chroma_pred_mode= pred_mode;
@@ -990,10 +1077,10 @@ decode_intra_mb:
}
h->cbp=
h->cbp_table[mb_xy]= cbp;
- s->current_picture.mb_type[mb_xy]= mb_type;
+ s->current_picture.f.mb_type[mb_xy] = mb_type;
if(cbp || IS_INTRA16x16(mb_type)){
- int i4x4, chroma_idx;
+ int i4x4, i8x8, chroma_idx;
int dquant;
int ret;
GetBitContext *gb= IS_INTRA(mb_type) ? h->intra_gb_ptr : h->inter_gb_ptr;
@@ -1036,9 +1123,14 @@ decode_intra_mb:
return -1;
}
} else {
+ const int num_c8x8 = h->sps.chroma_format_idc;
+
if(cbp&0x30){
for(chroma_idx=0; chroma_idx<2; chroma_idx++)
- if( decode_residual(h, gb, h->mb + ((256 + 16*16*chroma_idx) << pixel_shift), CHROMA_DC_BLOCK_INDEX+chroma_idx, chroma_dc_scan, NULL, 4) < 0){
+ if (decode_residual(h, gb, h->mb + ((256 + 16*16*chroma_idx) << pixel_shift),
+ CHROMA_DC_BLOCK_INDEX+chroma_idx,
+ CHROMA422 ? chroma422_dc_scan : chroma_dc_scan,
+ NULL, 4*num_c8x8) < 0) {
return -1;
}
}
@@ -1046,10 +1138,13 @@ decode_intra_mb:
if(cbp&0x20){
for(chroma_idx=0; chroma_idx<2; chroma_idx++){
const uint32_t *qmul = h->dequant4_coeff[chroma_idx+1+(IS_INTRA( mb_type ) ? 0:3)][h->chroma_qp[chroma_idx]];
- for(i4x4=0; i4x4<4; i4x4++){
- const int index= 16 + 16*chroma_idx + i4x4;
- if( decode_residual(h, gb, h->mb + (16*index << pixel_shift), index, scan + 1, qmul, 15) < 0){
- return -1;
+ DCTELEM *mb = h->mb + (16*(16 + 16*chroma_idx) << pixel_shift);
+ for (i8x8=0; i8x8<num_c8x8; i8x8++) {
+ for (i4x4=0; i4x4<4; i4x4++) {
+ const int index= 16 + 16*chroma_idx + 8*i8x8 + i4x4;
+ if (decode_residual(h, gb, mb, index, scan + 1, qmul, 15) < 0)
+ return -1;
+ mb += 16<<pixel_shift;
}
}
}
@@ -1063,7 +1158,7 @@ decode_intra_mb:
fill_rectangle(&h->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1);
fill_rectangle(&h->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1);
}
- s->current_picture.qscale_table[mb_xy]= s->qscale;
+ s->current_picture.f.qscale_table[mb_xy] = s->qscale;
write_back_non_zero_count(h);
if(MB_MBAFF){
diff --git a/libavcodec/h264_direct.c b/libavcodec/h264_direct.c
index a7e6853b5c..453199d540 100644
--- a/libavcodec/h264_direct.c
+++ b/libavcodec/h264_direct.c
@@ -2,20 +2,20 @@
* H.26L/H.264/AVC/JVT/14496-10/... direct mb/block decoding
* Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -87,9 +87,10 @@ static void fill_colmap(H264Context *h, int map[2][16+32], int list, int field,
poc= (poc&~3) + rfield + 1;
for(j=start; j<end; j++){
- if(4*h->ref_list[0][j].frame_num + (h->ref_list[0][j].reference&3) == poc){
+ if (4 * h->ref_list[0][j].frame_num + (h->ref_list[0][j].f.reference & 3) == poc) {
int cur_ref= mbafi ? (j-16)^field : j;
- map[list][2*old_ref + (rfield^field) + 16] = cur_ref;
+ if(ref1->mbaff)
+ map[list][2*old_ref + (rfield^field) + 16] = cur_ref;
if(rfield == field || !interl)
map[list][old_ref] = cur_ref;
break;
@@ -105,12 +106,12 @@ void ff_h264_direct_ref_list_init(H264Context * const h){
Picture * const cur = s->current_picture_ptr;
int list, j, field;
int sidx= (s->picture_structure&1)^1;
- int ref1sidx= (ref1->reference&1)^1;
+ int ref1sidx = (ref1->f.reference&1)^1;
for(list=0; list<2; list++){
cur->ref_count[sidx][list] = h->ref_count[list];
for(j=0; j<h->ref_count[list]; j++)
- cur->ref_poc[sidx][list][j] = 4*h->ref_list[list][j].frame_num + (h->ref_list[list][j].reference&3);
+ cur->ref_poc[sidx][list][j] = 4 * h->ref_list[list][j].frame_num + (h->ref_list[list][j].f.reference & 3);
}
if(s->picture_structure == PICT_FRAME){
@@ -126,11 +127,11 @@ void ff_h264_direct_ref_list_init(H264Context * const h){
int *col_poc = h->ref_list[1]->field_poc;
h->col_parity= (FFABS(col_poc[0] - cur_poc) >= FFABS(col_poc[1] - cur_poc));
ref1sidx=sidx= h->col_parity;
- }else if(!(s->picture_structure & h->ref_list[1][0].reference) && !h->ref_list[1][0].mbaff){ // FL -> FL & differ parity
- h->col_fieldoff= 2*(h->ref_list[1][0].reference) - 3;
+ } else if (!(s->picture_structure & h->ref_list[1][0].f.reference) && !h->ref_list[1][0].mbaff) { // FL -> FL & differ parity
+ h->col_fieldoff = 2 * h->ref_list[1][0].f.reference - 3;
}
- if(cur->pict_type != AV_PICTURE_TYPE_B || h->direct_spatial_mv_pred)
+ if (cur->f.pict_type != AV_PICTURE_TYPE_B || h->direct_spatial_mv_pred)
return;
for(list=0; list<2; list++){
@@ -143,11 +144,11 @@ void ff_h264_direct_ref_list_init(H264Context * const h){
static void await_reference_mb_row(H264Context * const h, Picture *ref, int mb_y)
{
- int ref_field = ref->reference - 1;
+ int ref_field = ref->f.reference - 1;
int ref_field_picture = ref->field_picture;
int ref_height = 16*h->s.mb_height >> ref_field_picture;
- if(!HAVE_PTHREADS || !(h->s.avctx->active_thread_type&FF_THREAD_FRAME))
+ if(!HAVE_THREADS || !(h->s.avctx->active_thread_type&FF_THREAD_FRAME))
return;
//FIXME it can be safe to access mb stuff
@@ -172,7 +173,7 @@ static void pred_spatial_direct_motion(H264Context * const h, int *mb_type){
int mv[2];
int list;
- assert(h->ref_list[1][0].reference&3);
+ assert(h->ref_list[1][0].f.reference & 3);
await_reference_mb_row(h, &h->ref_list[1][0], s->mb_y + !!IS_INTERLACED(*mb_type));
@@ -234,8 +235,8 @@ static void pred_spatial_direct_motion(H264Context * const h, int *mb_type){
return;
}
- if(IS_INTERLACED(h->ref_list[1][0].mb_type[mb_xy])){ // AFL/AFR/FR/FL -> AFL/FL
- if(!IS_INTERLACED(*mb_type)){ // AFR/FR -> AFL/FL
+ if (IS_INTERLACED(h->ref_list[1][0].f.mb_type[mb_xy])) { // AFL/AFR/FR/FL -> AFL/FL
+ if (!IS_INTERLACED(*mb_type)) { // AFR/FR -> AFL/FL
mb_y = (s->mb_y&~1) + h->col_parity;
mb_xy= s->mb_x + ((s->mb_y&~1) + h->col_parity)*s->mb_stride;
b8_stride = 0;
@@ -248,8 +249,8 @@ static void pred_spatial_direct_motion(H264Context * const h, int *mb_type){
if(IS_INTERLACED(*mb_type)){ // AFL /FL -> AFR/FR
mb_y = s->mb_y&~1;
mb_xy= s->mb_x + (s->mb_y&~1)*s->mb_stride;
- mb_type_col[0] = h->ref_list[1][0].mb_type[mb_xy];
- mb_type_col[1] = h->ref_list[1][0].mb_type[mb_xy + s->mb_stride];
+ mb_type_col[0] = h->ref_list[1][0].f.mb_type[mb_xy];
+ mb_type_col[1] = h->ref_list[1][0].f.mb_type[mb_xy + s->mb_stride];
b8_stride = 2+4*s->mb_stride;
b4_stride *= 6;
@@ -264,7 +265,7 @@ static void pred_spatial_direct_motion(H264Context * const h, int *mb_type){
}else{ // AFR/FR -> AFR/FR
single_col:
mb_type_col[0] =
- mb_type_col[1] = h->ref_list[1][0].mb_type[mb_xy];
+ mb_type_col[1] = h->ref_list[1][0].f.mb_type[mb_xy];
sub_mb_type |= MB_TYPE_16x16|MB_TYPE_DIRECT2; /* B_SUB_8x8 */
if(!is_b8x8 && (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA)){
@@ -284,10 +285,10 @@ single_col:
await_reference_mb_row(h, &h->ref_list[1][0], mb_y);
- l1mv0 = &h->ref_list[1][0].motion_val[0][h->mb2b_xy [mb_xy]];
- l1mv1 = &h->ref_list[1][0].motion_val[1][h->mb2b_xy [mb_xy]];
- l1ref0 = &h->ref_list[1][0].ref_index [0][4*mb_xy];
- l1ref1 = &h->ref_list[1][0].ref_index [1][4*mb_xy];
+ l1mv0 = &h->ref_list[1][0].f.motion_val[0][h->mb2b_xy [mb_xy]];
+ l1mv1 = &h->ref_list[1][0].f.motion_val[1][h->mb2b_xy [mb_xy]];
+ l1ref0 = &h->ref_list[1][0].f.ref_index [0][4 * mb_xy];
+ l1ref1 = &h->ref_list[1][0].f.ref_index [1][4 * mb_xy];
if(!b8_stride){
if(s->mb_y&1){
l1ref0 += 2;
@@ -416,12 +417,12 @@ static void pred_temp_direct_motion(H264Context * const h, int *mb_type){
unsigned int sub_mb_type;
int i8, i4;
- assert(h->ref_list[1][0].reference&3);
+ assert(h->ref_list[1][0].f.reference & 3);
await_reference_mb_row(h, &h->ref_list[1][0], s->mb_y + !!IS_INTERLACED(*mb_type));
- if(IS_INTERLACED(h->ref_list[1][0].mb_type[mb_xy])){ // AFL/AFR/FR/FL -> AFL/FL
- if(!IS_INTERLACED(*mb_type)){ // AFR/FR -> AFL/FL
+ if (IS_INTERLACED(h->ref_list[1][0].f.mb_type[mb_xy])) { // AFL/AFR/FR/FL -> AFL/FL
+ if (!IS_INTERLACED(*mb_type)) { // AFR/FR -> AFL/FL
mb_y = (s->mb_y&~1) + h->col_parity;
mb_xy= s->mb_x + ((s->mb_y&~1) + h->col_parity)*s->mb_stride;
b8_stride = 0;
@@ -434,8 +435,8 @@ static void pred_temp_direct_motion(H264Context * const h, int *mb_type){
if(IS_INTERLACED(*mb_type)){ // AFL /FL -> AFR/FR
mb_y = s->mb_y&~1;
mb_xy= s->mb_x + (s->mb_y&~1)*s->mb_stride;
- mb_type_col[0] = h->ref_list[1][0].mb_type[mb_xy];
- mb_type_col[1] = h->ref_list[1][0].mb_type[mb_xy + s->mb_stride];
+ mb_type_col[0] = h->ref_list[1][0].f.mb_type[mb_xy];
+ mb_type_col[1] = h->ref_list[1][0].f.mb_type[mb_xy + s->mb_stride];
b8_stride = 2+4*s->mb_stride;
b4_stride *= 6;
@@ -451,7 +452,7 @@ static void pred_temp_direct_motion(H264Context * const h, int *mb_type){
}else{ // AFR/FR -> AFR/FR
single_col:
mb_type_col[0] =
- mb_type_col[1] = h->ref_list[1][0].mb_type[mb_xy];
+ mb_type_col[1] = h->ref_list[1][0].f.mb_type[mb_xy];
sub_mb_type = MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_SUB_8x8 */
if(!is_b8x8 && (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA)){
@@ -471,10 +472,10 @@ single_col:
await_reference_mb_row(h, &h->ref_list[1][0], mb_y);
- l1mv0 = &h->ref_list[1][0].motion_val[0][h->mb2b_xy [mb_xy]];
- l1mv1 = &h->ref_list[1][0].motion_val[1][h->mb2b_xy [mb_xy]];
- l1ref0 = &h->ref_list[1][0].ref_index [0][4*mb_xy];
- l1ref1 = &h->ref_list[1][0].ref_index [1][4*mb_xy];
+ l1mv0 = &h->ref_list[1][0].f.motion_val[0][h->mb2b_xy [mb_xy]];
+ l1mv1 = &h->ref_list[1][0].f.motion_val[1][h->mb2b_xy [mb_xy]];
+ l1ref0 = &h->ref_list[1][0].f.ref_index [0][4 * mb_xy];
+ l1ref1 = &h->ref_list[1][0].f.ref_index [1][4 * mb_xy];
if(!b8_stride){
if(s->mb_y&1){
l1ref0 += 2;
diff --git a/libavcodec/h264_loopfilter.c b/libavcodec/h264_loopfilter.c
index e6b6141f13..67399395a1 100644
--- a/libavcodec/h264_loopfilter.c
+++ b/libavcodec/h264_loopfilter.c
@@ -2,20 +2,20 @@
* H.26L/H.264/AVC/JVT/14496-10/... loop filter
* Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -100,14 +100,14 @@ static const uint8_t tc0_table[52*3][4] = {
{-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 },
};
-static void av_always_inline filter_mb_edgev( uint8_t *pix, int stride, int16_t bS[4], unsigned int qp, H264Context *h) {
- const int qp_bd_offset = 6 * (h->sps.bit_depth_luma - 8);
- const unsigned int index_a = qp - qp_bd_offset + h->slice_alpha_c0_offset;
+/* intra: 0 if this loopfilter call is guaranteed to be inter (bS < 4), 1 if it might be intra (bS == 4) */
+static void av_always_inline filter_mb_edgev( uint8_t *pix, int stride, const int16_t bS[4], unsigned int qp, int a, int b, H264Context *h, int intra ) {
+ const unsigned int index_a = qp + a;
const int alpha = alpha_table[index_a];
- const int beta = beta_table[qp - qp_bd_offset + h->slice_beta_offset];
+ const int beta = beta_table[qp + b];
if (alpha ==0 || beta == 0) return;
- if( bS[0] < 4 ) {
+ if( bS[0] < 4 || !intra ) {
int8_t tc[4];
tc[0] = tc0_table[index_a][bS[0]];
tc[1] = tc0_table[index_a][bS[1]];
@@ -118,14 +118,13 @@ static void av_always_inline filter_mb_edgev( uint8_t *pix, int stride, int16_t
h->h264dsp.h264_h_loop_filter_luma_intra(pix, stride, alpha, beta);
}
}
-static void av_always_inline filter_mb_edgecv( uint8_t *pix, int stride, int16_t bS[4], unsigned int qp, H264Context *h ) {
- const int qp_bd_offset = 6 * (h->sps.bit_depth_luma - 8);
- const unsigned int index_a = qp - qp_bd_offset + h->slice_alpha_c0_offset;
+static void av_always_inline filter_mb_edgecv( uint8_t *pix, int stride, const int16_t bS[4], unsigned int qp, int a, int b, H264Context *h, int intra ) {
+ const unsigned int index_a = qp + a;
const int alpha = alpha_table[index_a];
- const int beta = beta_table[qp - qp_bd_offset + h->slice_beta_offset];
+ const int beta = beta_table[qp + b];
if (alpha ==0 || beta == 0) return;
- if( bS[0] < 4 ) {
+ if( bS[0] < 4 || !intra ) {
int8_t tc[4];
tc[0] = tc0_table[index_a][bS[0]]+1;
tc[1] = tc0_table[index_a][bS[1]]+1;
@@ -137,14 +136,13 @@ static void av_always_inline filter_mb_edgecv( uint8_t *pix, int stride, int16_t
}
}
-static void filter_mb_mbaff_edgev( H264Context *h, uint8_t *pix, int stride, int16_t bS[7], int bsi, int qp ) {
- const int qp_bd_offset = 6 * (h->sps.bit_depth_luma - 8);
- int index_a = qp - qp_bd_offset + h->slice_alpha_c0_offset;
- int alpha = alpha_table[index_a];
- int beta = beta_table[qp - qp_bd_offset + h->slice_beta_offset];
+static void av_always_inline filter_mb_mbaff_edgev( H264Context *h, uint8_t *pix, int stride, const int16_t bS[7], int bsi, int qp, int a, int b, int intra ) {
+ const unsigned int index_a = qp + a;
+ const int alpha = alpha_table[index_a];
+ const int beta = beta_table[qp + b];
if (alpha ==0 || beta == 0) return;
- if( bS[0] < 4 ) {
+ if( bS[0] < 4 || !intra ) {
int8_t tc[4];
tc[0] = tc0_table[index_a][bS[0*bsi]];
tc[1] = tc0_table[index_a][bS[1*bsi]];
@@ -155,14 +153,13 @@ static void filter_mb_mbaff_edgev( H264Context *h, uint8_t *pix, int stride, int
h->h264dsp.h264_h_loop_filter_luma_mbaff_intra(pix, stride, alpha, beta);
}
}
-static void filter_mb_mbaff_edgecv( H264Context *h, uint8_t *pix, int stride, int16_t bS[7], int bsi, int qp ) {
- const int qp_bd_offset = 6 * (h->sps.bit_depth_luma - 8);
- int index_a = qp - qp_bd_offset + h->slice_alpha_c0_offset;
- int alpha = alpha_table[index_a];
- int beta = beta_table[qp - qp_bd_offset + h->slice_beta_offset];
+static void av_always_inline filter_mb_mbaff_edgecv( H264Context *h, uint8_t *pix, int stride, const int16_t bS[7], int bsi, int qp, int a, int b, int intra ) {
+ const unsigned int index_a = qp + a;
+ const int alpha = alpha_table[index_a];
+ const int beta = beta_table[qp + b];
if (alpha ==0 || beta == 0) return;
- if( bS[0] < 4 ) {
+ if( bS[0] < 4 || !intra ) {
int8_t tc[4];
tc[0] = tc0_table[index_a][bS[0*bsi]] + 1;
tc[1] = tc0_table[index_a][bS[1*bsi]] + 1;
@@ -174,14 +171,13 @@ static void filter_mb_mbaff_edgecv( H264Context *h, uint8_t *pix, int stride, in
}
}
-static void av_always_inline filter_mb_edgeh( uint8_t *pix, int stride, int16_t bS[4], unsigned int qp, H264Context *h ) {
- const int qp_bd_offset = 6 * (h->sps.bit_depth_luma - 8);
- const unsigned int index_a = qp - qp_bd_offset + h->slice_alpha_c0_offset;
+static void av_always_inline filter_mb_edgeh( uint8_t *pix, int stride, const int16_t bS[4], unsigned int qp, int a, int b, H264Context *h, int intra ) {
+ const unsigned int index_a = qp + a;
const int alpha = alpha_table[index_a];
- const int beta = beta_table[qp - qp_bd_offset + h->slice_beta_offset];
+ const int beta = beta_table[qp + b];
if (alpha ==0 || beta == 0) return;
- if( bS[0] < 4 ) {
+ if( bS[0] < 4 || !intra ) {
int8_t tc[4];
tc[0] = tc0_table[index_a][bS[0]];
tc[1] = tc0_table[index_a][bS[1]];
@@ -193,14 +189,13 @@ static void av_always_inline filter_mb_edgeh( uint8_t *pix, int stride, int16_t
}
}
-static void av_always_inline filter_mb_edgech( uint8_t *pix, int stride, int16_t bS[4], unsigned int qp, H264Context *h ) {
- const int qp_bd_offset = 6 * (h->sps.bit_depth_luma - 8);
- const unsigned int index_a = qp - qp_bd_offset + h->slice_alpha_c0_offset;
+static void av_always_inline filter_mb_edgech( uint8_t *pix, int stride, const int16_t bS[4], unsigned int qp, int a, int b, H264Context *h, int intra ) {
+ const unsigned int index_a = qp + a;
const int alpha = alpha_table[index_a];
- const int beta = beta_table[qp - qp_bd_offset + h->slice_beta_offset];
+ const int beta = beta_table[qp + b];
if (alpha ==0 || beta == 0) return;
- if( bS[0] < 4 ) {
+ if( bS[0] < 4 || !intra ) {
int8_t tc[4];
tc[0] = tc0_table[index_a][bS[0]]+1;
tc[1] = tc0_table[index_a][bS[1]]+1;
@@ -212,116 +207,126 @@ static void av_always_inline filter_mb_edgech( uint8_t *pix, int stride, int16_t
}
}
-void ff_h264_filter_mb_fast( H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr, unsigned int linesize, unsigned int uvlinesize) {
+static void av_always_inline h264_filter_mb_fast_internal( H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr,
+ unsigned int linesize, unsigned int uvlinesize, int pixel_shift) {
MpegEncContext * const s = &h->s;
- int mb_xy;
- int mb_type, left_type, top_type;
- int qp, qp0, qp1, qpc, qpc0, qpc1, qp_thresh;
int chroma = !(CONFIG_GRAY && (s->flags&CODEC_FLAG_GRAY));
int chroma444 = CHROMA444;
-
- mb_xy = h->mb_xy;
-
- if(!h->h264dsp.h264_loop_filter_strength || h->pps.chroma_qp_diff) {
- ff_h264_filter_mb(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize);
- return;
- }
- assert(!FRAME_MBAFF);
- left_type= h->left_type[LTOP];
- top_type= h->top_type;
-
- mb_type = s->current_picture.mb_type[mb_xy];
- qp = s->current_picture.qscale_table[mb_xy];
- qp0 = s->current_picture.qscale_table[mb_xy-1];
- qp1 = s->current_picture.qscale_table[h->top_mb_xy];
- qpc = get_chroma_qp( h, 0, qp );
- qpc0 = get_chroma_qp( h, 0, qp0 );
- qpc1 = get_chroma_qp( h, 0, qp1 );
+ int chroma422 = CHROMA422;
+
+ int mb_xy = h->mb_xy;
+ int left_type= h->left_type[LTOP];
+ int top_type= h->top_type;
+
+ int qp_bd_offset = 6 * (h->sps.bit_depth_luma - 8);
+ int a = h->slice_alpha_c0_offset - qp_bd_offset;
+ int b = h->slice_beta_offset - qp_bd_offset;
+
+ int mb_type = s->current_picture.f.mb_type[mb_xy];
+ int qp = s->current_picture.f.qscale_table[mb_xy];
+ int qp0 = s->current_picture.f.qscale_table[mb_xy - 1];
+ int qp1 = s->current_picture.f.qscale_table[h->top_mb_xy];
+ int qpc = get_chroma_qp( h, 0, qp );
+ int qpc0 = get_chroma_qp( h, 0, qp0 );
+ int qpc1 = get_chroma_qp( h, 0, qp1 );
qp0 = (qp + qp0 + 1) >> 1;
qp1 = (qp + qp1 + 1) >> 1;
qpc0 = (qpc + qpc0 + 1) >> 1;
qpc1 = (qpc + qpc1 + 1) >> 1;
- qp_thresh = 15+52 - h->slice_alpha_c0_offset;
- if(qp <= qp_thresh && qp0 <= qp_thresh && qp1 <= qp_thresh &&
- qpc <= qp_thresh && qpc0 <= qp_thresh && qpc1 <= qp_thresh)
- return;
if( IS_INTRA(mb_type) ) {
- int16_t bS4[4] = {4,4,4,4};
- int16_t bS3[4] = {3,3,3,3};
- int16_t *bSH = FIELD_PICTURE ? bS3 : bS4;
+ static const int16_t bS4[4] = {4,4,4,4};
+ static const int16_t bS3[4] = {3,3,3,3};
+ const int16_t *bSH = FIELD_PICTURE ? bS3 : bS4;
if(left_type)
- filter_mb_edgev( &img_y[4*0], linesize, bS4, qp0, h);
+ filter_mb_edgev( &img_y[4*0<<pixel_shift], linesize, bS4, qp0, a, b, h, 1);
if( IS_8x8DCT(mb_type) ) {
- filter_mb_edgev( &img_y[4*2], linesize, bS3, qp, h);
+ filter_mb_edgev( &img_y[4*2<<pixel_shift], linesize, bS3, qp, a, b, h, 0);
if(top_type){
- filter_mb_edgeh( &img_y[4*0*linesize], linesize, bSH, qp1, h);
+ filter_mb_edgeh( &img_y[4*0*linesize], linesize, bSH, qp1, a, b, h, 1);
}
- filter_mb_edgeh( &img_y[4*2*linesize], linesize, bS3, qp, h);
+ filter_mb_edgeh( &img_y[4*2*linesize], linesize, bS3, qp, a, b, h, 0);
} else {
- filter_mb_edgev( &img_y[4*1], linesize, bS3, qp, h);
- filter_mb_edgev( &img_y[4*2], linesize, bS3, qp, h);
- filter_mb_edgev( &img_y[4*3], linesize, bS3, qp, h);
+ filter_mb_edgev( &img_y[4*1<<pixel_shift], linesize, bS3, qp, a, b, h, 0);
+ filter_mb_edgev( &img_y[4*2<<pixel_shift], linesize, bS3, qp, a, b, h, 0);
+ filter_mb_edgev( &img_y[4*3<<pixel_shift], linesize, bS3, qp, a, b, h, 0);
if(top_type){
- filter_mb_edgeh( &img_y[4*0*linesize], linesize, bSH, qp1, h);
+ filter_mb_edgeh( &img_y[4*0*linesize], linesize, bSH, qp1, a, b, h, 1);
}
- filter_mb_edgeh( &img_y[4*1*linesize], linesize, bS3, qp, h);
- filter_mb_edgeh( &img_y[4*2*linesize], linesize, bS3, qp, h);
- filter_mb_edgeh( &img_y[4*3*linesize], linesize, bS3, qp, h);
+ filter_mb_edgeh( &img_y[4*1*linesize], linesize, bS3, qp, a, b, h, 0);
+ filter_mb_edgeh( &img_y[4*2*linesize], linesize, bS3, qp, a, b, h, 0);
+ filter_mb_edgeh( &img_y[4*3*linesize], linesize, bS3, qp, a, b, h, 0);
}
if(chroma){
if(chroma444){
if(left_type){
- filter_mb_edgev( &img_cb[4*0], linesize, bS4, qpc0, h);
- filter_mb_edgev( &img_cr[4*0], linesize, bS4, qpc0, h);
+ filter_mb_edgev( &img_cb[4*0<<pixel_shift], linesize, bS4, qpc0, a, b, h, 1);
+ filter_mb_edgev( &img_cr[4*0<<pixel_shift], linesize, bS4, qpc0, a, b, h, 1);
}
if( IS_8x8DCT(mb_type) ) {
- filter_mb_edgev( &img_cb[4*2], linesize, bS3, qpc, h);
- filter_mb_edgev( &img_cr[4*2], linesize, bS3, qpc, h);
+ filter_mb_edgev( &img_cb[4*2<<pixel_shift], linesize, bS3, qpc, a, b, h, 0);
+ filter_mb_edgev( &img_cr[4*2<<pixel_shift], linesize, bS3, qpc, a, b, h, 0);
if(top_type){
- filter_mb_edgeh( &img_cb[4*0*linesize], linesize, bSH, qpc1, h);
- filter_mb_edgeh( &img_cr[4*0*linesize], linesize, bSH, qpc1, h);
+ filter_mb_edgeh( &img_cb[4*0*linesize], linesize, bSH, qpc1, a, b, h, 1 );
+ filter_mb_edgeh( &img_cr[4*0*linesize], linesize, bSH, qpc1, a, b, h, 1 );
}
- filter_mb_edgeh( &img_cb[4*2*linesize], linesize, bS3, qpc, h);
- filter_mb_edgeh( &img_cr[4*2*linesize], linesize, bS3, qpc, h);
+ filter_mb_edgeh( &img_cb[4*2*linesize], linesize, bS3, qpc, a, b, h, 0);
+ filter_mb_edgeh( &img_cr[4*2*linesize], linesize, bS3, qpc, a, b, h, 0);
} else {
- filter_mb_edgev( &img_cb[4*1], linesize, bS3, qpc, h);
- filter_mb_edgev( &img_cr[4*1], linesize, bS3, qpc, h);
- filter_mb_edgev( &img_cb[4*2], linesize, bS3, qpc, h);
- filter_mb_edgev( &img_cr[4*2], linesize, bS3, qpc, h);
- filter_mb_edgev( &img_cb[4*3], linesize, bS3, qpc, h);
- filter_mb_edgev( &img_cr[4*3], linesize, bS3, qpc, h);
+ filter_mb_edgev( &img_cb[4*1<<pixel_shift], linesize, bS3, qpc, a, b, h, 0);
+ filter_mb_edgev( &img_cr[4*1<<pixel_shift], linesize, bS3, qpc, a, b, h, 0);
+ filter_mb_edgev( &img_cb[4*2<<pixel_shift], linesize, bS3, qpc, a, b, h, 0);
+ filter_mb_edgev( &img_cr[4*2<<pixel_shift], linesize, bS3, qpc, a, b, h, 0);
+ filter_mb_edgev( &img_cb[4*3<<pixel_shift], linesize, bS3, qpc, a, b, h, 0);
+ filter_mb_edgev( &img_cr[4*3<<pixel_shift], linesize, bS3, qpc, a, b, h, 0);
if(top_type){
- filter_mb_edgeh( &img_cb[4*0*linesize], linesize, bSH, qpc1, h);
- filter_mb_edgeh( &img_cr[4*0*linesize], linesize, bSH, qpc1, h);
+ filter_mb_edgeh( &img_cb[4*0*linesize], linesize, bSH, qpc1, a, b, h, 1);
+ filter_mb_edgeh( &img_cr[4*0*linesize], linesize, bSH, qpc1, a, b, h, 1);
}
- filter_mb_edgeh( &img_cb[4*1*linesize], linesize, bS3, qpc, h);
- filter_mb_edgeh( &img_cr[4*1*linesize], linesize, bS3, qpc, h);
- filter_mb_edgeh( &img_cb[4*2*linesize], linesize, bS3, qpc, h);
- filter_mb_edgeh( &img_cr[4*2*linesize], linesize, bS3, qpc, h);
- filter_mb_edgeh( &img_cb[4*3*linesize], linesize, bS3, qpc, h);
- filter_mb_edgeh( &img_cr[4*3*linesize], linesize, bS3, qpc, h);
+ filter_mb_edgeh( &img_cb[4*1*linesize], linesize, bS3, qpc, a, b, h, 0);
+ filter_mb_edgeh( &img_cr[4*1*linesize], linesize, bS3, qpc, a, b, h, 0);
+ filter_mb_edgeh( &img_cb[4*2*linesize], linesize, bS3, qpc, a, b, h, 0);
+ filter_mb_edgeh( &img_cr[4*2*linesize], linesize, bS3, qpc, a, b, h, 0);
+ filter_mb_edgeh( &img_cb[4*3*linesize], linesize, bS3, qpc, a, b, h, 0);
+ filter_mb_edgeh( &img_cr[4*3*linesize], linesize, bS3, qpc, a, b, h, 0);
+ }
+ }else if(chroma422){
+ if(left_type){
+ filter_mb_edgecv(&img_cb[2*0<<pixel_shift], uvlinesize, bS4, qpc0, a, b, h, 1);
+ filter_mb_edgecv(&img_cr[2*0<<pixel_shift], uvlinesize, bS4, qpc0, a, b, h, 1);
+ }
+ filter_mb_edgecv(&img_cb[2*2<<pixel_shift], uvlinesize, bS3, qpc, a, b, h, 0);
+ filter_mb_edgecv(&img_cr[2*2<<pixel_shift], uvlinesize, bS3, qpc, a, b, h, 0);
+ if(top_type){
+ filter_mb_edgech(&img_cb[4*0*uvlinesize], uvlinesize, bSH, qpc1, a, b, h, 1);
+ filter_mb_edgech(&img_cr[4*0*uvlinesize], uvlinesize, bSH, qpc1, a, b, h, 1);
}
+ filter_mb_edgech(&img_cb[4*1*uvlinesize], uvlinesize, bS3, qpc, a, b, h, 0);
+ filter_mb_edgech(&img_cr[4*1*uvlinesize], uvlinesize, bS3, qpc, a, b, h, 0);
+ filter_mb_edgech(&img_cb[4*2*uvlinesize], uvlinesize, bS3, qpc, a, b, h, 0);
+ filter_mb_edgech(&img_cr[4*2*uvlinesize], uvlinesize, bS3, qpc, a, b, h, 0);
+ filter_mb_edgech(&img_cb[4*3*uvlinesize], uvlinesize, bS3, qpc, a, b, h, 0);
+ filter_mb_edgech(&img_cr[4*3*uvlinesize], uvlinesize, bS3, qpc, a, b, h, 0);
}else{
if(left_type){
- filter_mb_edgecv( &img_cb[2*0], uvlinesize, bS4, qpc0, h);
- filter_mb_edgecv( &img_cr[2*0], uvlinesize, bS4, qpc0, h);
+ filter_mb_edgecv( &img_cb[2*0<<pixel_shift], uvlinesize, bS4, qpc0, a, b, h, 1);
+ filter_mb_edgecv( &img_cr[2*0<<pixel_shift], uvlinesize, bS4, qpc0, a, b, h, 1);
}
- filter_mb_edgecv( &img_cb[2*2], uvlinesize, bS3, qpc, h);
- filter_mb_edgecv( &img_cr[2*2], uvlinesize, bS3, qpc, h);
+ filter_mb_edgecv( &img_cb[2*2<<pixel_shift], uvlinesize, bS3, qpc, a, b, h, 0);
+ filter_mb_edgecv( &img_cr[2*2<<pixel_shift], uvlinesize, bS3, qpc, a, b, h, 0);
if(top_type){
- filter_mb_edgech( &img_cb[2*0*uvlinesize], uvlinesize, bSH, qpc1, h);
- filter_mb_edgech( &img_cr[2*0*uvlinesize], uvlinesize, bSH, qpc1, h);
+ filter_mb_edgech( &img_cb[2*0*uvlinesize], uvlinesize, bSH, qpc1, a, b, h, 1);
+ filter_mb_edgech( &img_cr[2*0*uvlinesize], uvlinesize, bSH, qpc1, a, b, h, 1);
}
- filter_mb_edgech( &img_cb[2*2*uvlinesize], uvlinesize, bS3, qpc, h);
- filter_mb_edgech( &img_cr[2*2*uvlinesize], uvlinesize, bS3, qpc, h);
+ filter_mb_edgech( &img_cb[2*2*uvlinesize], uvlinesize, bS3, qpc, a, b, h, 0);
+ filter_mb_edgech( &img_cr[2*2*uvlinesize], uvlinesize, bS3, qpc, a, b, h, 0);
}
}
return;
} else {
LOCAL_ALIGNED_8(int16_t, bS, [2], [4][4]);
int edges;
- if( IS_8x8DCT(mb_type) && (h->cbp&7) == 7 ) {
+ if( IS_8x8DCT(mb_type) && (h->cbp&7) == 7 && !chroma444 ) {
edges = 4;
AV_WN64A(bS[0][0], 0x0002000200020002ULL);
AV_WN64A(bS[0][2], 0x0002000200020002ULL);
@@ -340,43 +345,61 @@ void ff_h264_filter_mb_fast( H264Context *h, int mb_x, int mb_y, uint8_t *img_y,
if( IS_INTRA(top_type) )
AV_WN64A(bS[1][0], FIELD_PICTURE ? 0x0003000300030003ULL : 0x0004000400040004ULL);
-#define FILTER(hv,dir,edge)\
+#define FILTER(hv,dir,edge,intra)\
if(AV_RN64A(bS[dir][edge])) { \
- filter_mb_edge##hv( &img_y[4*edge*(dir?linesize:1)], linesize, bS[dir][edge], edge ? qp : qp##dir, h );\
+ filter_mb_edge##hv( &img_y[4*edge*(dir?linesize:1<<pixel_shift)], linesize, bS[dir][edge], edge ? qp : qp##dir, a, b, h, intra );\
if(chroma){\
if(chroma444){\
- filter_mb_edge##hv( &img_cb[4*edge*(dir?linesize:1)], linesize, bS[dir][edge], edge ? qpc : qpc##dir, h );\
- filter_mb_edge##hv( &img_cr[4*edge*(dir?linesize:1)], linesize, bS[dir][edge], edge ? qpc : qpc##dir, h );\
+ filter_mb_edge##hv( &img_cb[4*edge*(dir?linesize:1<<pixel_shift)], linesize, bS[dir][edge], edge ? qpc : qpc##dir, a, b, h, intra );\
+ filter_mb_edge##hv( &img_cr[4*edge*(dir?linesize:1<<pixel_shift)], linesize, bS[dir][edge], edge ? qpc : qpc##dir, a, b, h, intra );\
} else if(!(edge&1)) {\
- filter_mb_edgec##hv( &img_cb[2*edge*(dir?uvlinesize:1)], uvlinesize, bS[dir][edge], edge ? qpc : qpc##dir, h );\
- filter_mb_edgec##hv( &img_cr[2*edge*(dir?uvlinesize:1)], uvlinesize, bS[dir][edge], edge ? qpc : qpc##dir, h );\
+ filter_mb_edgec##hv( &img_cb[2*edge*(dir?uvlinesize:1<<pixel_shift)], uvlinesize, bS[dir][edge], edge ? qpc : qpc##dir, a, b, h, intra );\
+ filter_mb_edgec##hv( &img_cr[2*edge*(dir?uvlinesize:1<<pixel_shift)], uvlinesize, bS[dir][edge], edge ? qpc : qpc##dir, a, b, h, intra );\
}\
}\
}
if(left_type)
- FILTER(v,0,0);
+ FILTER(v,0,0,1);
if( edges == 1 ) {
if(top_type)
- FILTER(h,1,0);
+ FILTER(h,1,0,1);
} else if( IS_8x8DCT(mb_type) ) {
- FILTER(v,0,2);
+ FILTER(v,0,2,0);
if(top_type)
- FILTER(h,1,0);
- FILTER(h,1,2);
+ FILTER(h,1,0,1);
+ FILTER(h,1,2,0);
} else {
- FILTER(v,0,1);
- FILTER(v,0,2);
- FILTER(v,0,3);
+ FILTER(v,0,1,0);
+ FILTER(v,0,2,0);
+ FILTER(v,0,3,0);
if(top_type)
- FILTER(h,1,0);
- FILTER(h,1,1);
- FILTER(h,1,2);
- FILTER(h,1,3);
+ FILTER(h,1,0,1);
+ FILTER(h,1,1,0);
+ FILTER(h,1,2,0);
+ FILTER(h,1,3,0);
}
#undef FILTER
}
}
+void ff_h264_filter_mb_fast( H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr, unsigned int linesize, unsigned int uvlinesize) {
+ assert(!FRAME_MBAFF);
+ if(!h->h264dsp.h264_loop_filter_strength || h->pps.chroma_qp_diff) {
+ ff_h264_filter_mb(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize);
+ return;
+ }
+
+#if CONFIG_SMALL
+ h264_filter_mb_fast_internal(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, h->pixel_shift);
+#else
+ if(h->pixel_shift){
+ h264_filter_mb_fast_internal(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, 1);
+ }else{
+ h264_filter_mb_fast_internal(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, 0);
+ }
+#endif
+}
+
static int check_mv(H264Context *h, long b_idx, long bn_idx, int mvy_limit){
int v;
@@ -406,10 +429,12 @@ static int check_mv(H264Context *h, long b_idx, long bn_idx, int mvy_limit){
return v;
}
-static av_always_inline void filter_mb_dir(H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr, unsigned int linesize, unsigned int uvlinesize, int mb_xy, int mb_type, int mvy_limit, int first_vertical_edge_done, int chroma, int chroma444, int dir) {
+static av_always_inline void filter_mb_dir(H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr, unsigned int linesize, unsigned int uvlinesize, int mb_xy, int mb_type, int mvy_limit, int first_vertical_edge_done, int a, int b, int chroma, int dir) {
MpegEncContext * const s = &h->s;
int edge;
int chroma_qp_avg[2];
+ int chroma444 = CHROMA444;
+ int chroma422 = CHROMA422;
const int mbm_xy = dir == 0 ? mb_xy -1 : h->top_mb_xy;
const int mbm_type = dir == 0 ? h->left_type[LTOP] : h->top_type;
@@ -439,10 +464,10 @@ static av_always_inline void filter_mb_dir(H264Context *h, int mb_x, int mb_y, u
for(j=0; j<2; j++, mbn_xy += s->mb_stride){
DECLARE_ALIGNED(8, int16_t, bS)[4];
int qp;
- if( IS_INTRA(mb_type|s->current_picture.mb_type[mbn_xy]) ) {
+ if (IS_INTRA(mb_type | s->current_picture.f.mb_type[mbn_xy])) {
AV_WN64A(bS, 0x0003000300030003ULL);
} else {
- if(!CABAC && IS_8x8DCT(s->current_picture.mb_type[mbn_xy])){
+ if (!CABAC && IS_8x8DCT(s->current_picture.f.mb_type[mbn_xy])) {
bS[0]= 1+((h->cbp_table[mbn_xy] & 0x4000)||h->non_zero_count_cache[scan8[0]+0]);
bS[1]= 1+((h->cbp_table[mbn_xy] & 0x4000)||h->non_zero_count_cache[scan8[0]+1]);
bS[2]= 1+((h->cbp_table[mbn_xy] & 0x8000)||h->non_zero_count_cache[scan8[0]+2]);
@@ -457,19 +482,19 @@ static av_always_inline void filter_mb_dir(H264Context *h, int mb_x, int mb_y, u
}
// Do not use s->qscale as luma quantizer because it has not the same
// value in IPCM macroblocks.
- qp = ( s->current_picture.qscale_table[mb_xy] + s->current_picture.qscale_table[mbn_xy] + 1 ) >> 1;
+ qp = (s->current_picture.f.qscale_table[mb_xy] + s->current_picture.f.qscale_table[mbn_xy] + 1) >> 1;
tprintf(s->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, tmp_linesize, tmp_uvlinesize);
{ int i; for (i = 0; i < 4; i++) tprintf(s->avctx, " bS[%d]:%d", i, bS[i]); tprintf(s->avctx, "\n"); }
- filter_mb_edgeh( &img_y[j*linesize], tmp_linesize, bS, qp, h );
- chroma_qp_avg[0] = (h->chroma_qp[0] + get_chroma_qp( h, 0, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1;
- chroma_qp_avg[1] = (h->chroma_qp[1] + get_chroma_qp( h, 1, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1;
+ filter_mb_edgeh( &img_y[j*linesize], tmp_linesize, bS, qp, a, b, h, 0 );
+ chroma_qp_avg[0] = (h->chroma_qp[0] + get_chroma_qp(h, 0, s->current_picture.f.qscale_table[mbn_xy]) + 1) >> 1;
+ chroma_qp_avg[1] = (h->chroma_qp[1] + get_chroma_qp(h, 1, s->current_picture.f.qscale_table[mbn_xy]) + 1) >> 1;
if (chroma) {
if (chroma444) {
- filter_mb_edgeh (&img_cb[j*uvlinesize], tmp_uvlinesize, bS, chroma_qp_avg[0], h);
- filter_mb_edgeh (&img_cr[j*uvlinesize], tmp_uvlinesize, bS, chroma_qp_avg[1], h);
+ filter_mb_edgeh (&img_cb[j*uvlinesize], tmp_uvlinesize, bS, chroma_qp_avg[0], a, b, h, 0);
+ filter_mb_edgeh (&img_cr[j*uvlinesize], tmp_uvlinesize, bS, chroma_qp_avg[1], a, b, h, 0);
} else {
- filter_mb_edgech(&img_cb[j*uvlinesize], tmp_uvlinesize, bS, chroma_qp_avg[0], h);
- filter_mb_edgech(&img_cr[j*uvlinesize], tmp_uvlinesize, bS, chroma_qp_avg[1], h);
+ filter_mb_edgech(&img_cb[j*uvlinesize], tmp_uvlinesize, bS, chroma_qp_avg[0], a, b, h, 0);
+ filter_mb_edgech(&img_cr[j*uvlinesize], tmp_uvlinesize, bS, chroma_qp_avg[1], a, b, h, 0);
}
}
}
@@ -522,32 +547,32 @@ static av_always_inline void filter_mb_dir(H264Context *h, int mb_x, int mb_y, u
// Do not use s->qscale as luma quantizer because it has not the same
// value in IPCM macroblocks.
if(bS[0]+bS[1]+bS[2]+bS[3]){
- qp = ( s->current_picture.qscale_table[mb_xy] + s->current_picture.qscale_table[mbm_xy] + 1 ) >> 1;
+ qp = (s->current_picture.f.qscale_table[mb_xy] + s->current_picture.f.qscale_table[mbm_xy] + 1) >> 1;
//tprintf(s->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d, QPc:%d, QPcn:%d\n", mb_x, mb_y, dir, edge, qp, h->chroma_qp[0], s->current_picture.qscale_table[mbn_xy]);
tprintf(s->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, linesize, uvlinesize);
//{ int i; for (i = 0; i < 4; i++) tprintf(s->avctx, " bS[%d]:%d", i, bS[i]); tprintf(s->avctx, "\n"); }
- chroma_qp_avg[0] = (h->chroma_qp[0] + get_chroma_qp( h, 0, s->current_picture.qscale_table[mbm_xy] ) + 1 ) >> 1;
- chroma_qp_avg[1] = (h->chroma_qp[1] + get_chroma_qp( h, 1, s->current_picture.qscale_table[mbm_xy] ) + 1 ) >> 1;
+ chroma_qp_avg[0] = (h->chroma_qp[0] + get_chroma_qp(h, 0, s->current_picture.f.qscale_table[mbm_xy]) + 1) >> 1;
+ chroma_qp_avg[1] = (h->chroma_qp[1] + get_chroma_qp(h, 1, s->current_picture.f.qscale_table[mbm_xy]) + 1) >> 1;
if( dir == 0 ) {
- filter_mb_edgev( &img_y[0], linesize, bS, qp, h );
+ filter_mb_edgev( &img_y[0], linesize, bS, qp, a, b, h, 1 );
if (chroma) {
if (chroma444) {
- filter_mb_edgev ( &img_cb[0], uvlinesize, bS, chroma_qp_avg[0], h);
- filter_mb_edgev ( &img_cr[0], uvlinesize, bS, chroma_qp_avg[1], h);
+ filter_mb_edgev ( &img_cb[0], uvlinesize, bS, chroma_qp_avg[0], a, b, h, 1);
+ filter_mb_edgev ( &img_cr[0], uvlinesize, bS, chroma_qp_avg[1], a, b, h, 1);
} else {
- filter_mb_edgecv( &img_cb[0], uvlinesize, bS, chroma_qp_avg[0], h);
- filter_mb_edgecv( &img_cr[0], uvlinesize, bS, chroma_qp_avg[1], h);
+ filter_mb_edgecv( &img_cb[0], uvlinesize, bS, chroma_qp_avg[0], a, b, h, 1);
+ filter_mb_edgecv( &img_cr[0], uvlinesize, bS, chroma_qp_avg[1], a, b, h, 1);
}
}
} else {
- filter_mb_edgeh( &img_y[0], linesize, bS, qp, h );
+ filter_mb_edgeh( &img_y[0], linesize, bS, qp, a, b, h, 1 );
if (chroma) {
if (chroma444) {
- filter_mb_edgeh ( &img_cb[0], uvlinesize, bS, chroma_qp_avg[0], h);
- filter_mb_edgeh ( &img_cr[0], uvlinesize, bS, chroma_qp_avg[1], h);
+ filter_mb_edgeh ( &img_cb[0], uvlinesize, bS, chroma_qp_avg[0], a, b, h, 1);
+ filter_mb_edgeh ( &img_cr[0], uvlinesize, bS, chroma_qp_avg[1], a, b, h, 1);
} else {
- filter_mb_edgech( &img_cb[0], uvlinesize, bS, chroma_qp_avg[0], h);
- filter_mb_edgech( &img_cr[0], uvlinesize, bS, chroma_qp_avg[1], h);
+ filter_mb_edgech( &img_cb[0], uvlinesize, bS, chroma_qp_avg[0], a, b, h, 1);
+ filter_mb_edgech( &img_cr[0], uvlinesize, bS, chroma_qp_avg[1], a, b, h, 1);
}
}
}
@@ -559,8 +584,9 @@ static av_always_inline void filter_mb_dir(H264Context *h, int mb_x, int mb_y, u
for( edge = 1; edge < edges; edge++ ) {
DECLARE_ALIGNED(8, int16_t, bS)[4];
int qp;
+ const int deblock_edge = !IS_8x8DCT(mb_type & (edge<<24)); // (edge&1) && IS_8x8DCT(mb_type)
- if( IS_8x8DCT(mb_type & (edge<<24)) ) // (edge&1) && IS_8x8DCT(mb_type)
+ if (!deblock_edge && (!chroma422 || dir == 0))
continue;
if( IS_INTRA(mb_type)) {
@@ -606,30 +632,39 @@ static av_always_inline void filter_mb_dir(H264Context *h, int mb_x, int mb_y, u
/* Filter edge */
// Do not use s->qscale as luma quantizer because it has not the same
// value in IPCM macroblocks.
- qp = s->current_picture.qscale_table[mb_xy];
+ qp = s->current_picture.f.qscale_table[mb_xy];
//tprintf(s->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d, QPc:%d, QPcn:%d\n", mb_x, mb_y, dir, edge, qp, h->chroma_qp[0], s->current_picture.qscale_table[mbn_xy]);
tprintf(s->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, linesize, uvlinesize);
//{ int i; for (i = 0; i < 4; i++) tprintf(s->avctx, " bS[%d]:%d", i, bS[i]); tprintf(s->avctx, "\n"); }
if( dir == 0 ) {
- filter_mb_edgev( &img_y[4*edge << h->pixel_shift], linesize, bS, qp, h );
+ filter_mb_edgev( &img_y[4*edge << h->pixel_shift], linesize, bS, qp, a, b, h, 0 );
if (chroma) {
if (chroma444) {
- filter_mb_edgev ( &img_cb[4*edge << h->pixel_shift], uvlinesize, bS, h->chroma_qp[0], h);
- filter_mb_edgev ( &img_cr[4*edge << h->pixel_shift], uvlinesize, bS, h->chroma_qp[1], h);
+ filter_mb_edgev ( &img_cb[4*edge << h->pixel_shift], uvlinesize, bS, h->chroma_qp[0], a, b, h, 0);
+ filter_mb_edgev ( &img_cr[4*edge << h->pixel_shift], uvlinesize, bS, h->chroma_qp[1], a, b, h, 0);
} else if( (edge&1) == 0 ) {
- filter_mb_edgecv( &img_cb[2*edge << h->pixel_shift], uvlinesize, bS, h->chroma_qp[0], h);
- filter_mb_edgecv( &img_cr[2*edge << h->pixel_shift], uvlinesize, bS, h->chroma_qp[1], h);
+ filter_mb_edgecv( &img_cb[2*edge << h->pixel_shift], uvlinesize, bS, h->chroma_qp[0], a, b, h, 0);
+ filter_mb_edgecv( &img_cr[2*edge << h->pixel_shift], uvlinesize, bS, h->chroma_qp[1], a, b, h, 0);
}
}
} else {
- filter_mb_edgeh( &img_y[4*edge*linesize], linesize, bS, qp, h );
- if (chroma) {
- if (chroma444) {
- filter_mb_edgeh ( &img_cb[4*edge*uvlinesize], uvlinesize, bS, h->chroma_qp[0], h);
- filter_mb_edgeh ( &img_cr[4*edge*uvlinesize], uvlinesize, bS, h->chroma_qp[1], h);
- } else if( (edge&1) == 0 ) {
- filter_mb_edgech( &img_cb[2*edge*uvlinesize], uvlinesize, bS, h->chroma_qp[0], h);
- filter_mb_edgech( &img_cr[2*edge*uvlinesize], uvlinesize, bS, h->chroma_qp[1], h);
+ if (chroma422) {
+ if (deblock_edge)
+ filter_mb_edgeh(&img_y[4*edge*linesize], linesize, bS, qp, a, b, h, 0);
+ if (chroma) {
+ filter_mb_edgech(&img_cb[4*edge*uvlinesize], uvlinesize, bS, h->chroma_qp[0], a, b, h, 0);
+ filter_mb_edgech(&img_cr[4*edge*uvlinesize], uvlinesize, bS, h->chroma_qp[1], a, b, h, 0);
+ }
+ } else {
+ filter_mb_edgeh(&img_y[4*edge*linesize], linesize, bS, qp, a, b, h, 0);
+ if (chroma) {
+ if (chroma444) {
+ filter_mb_edgeh (&img_cb[4*edge*uvlinesize], uvlinesize, bS, h->chroma_qp[0], a, b, h, 0);
+ filter_mb_edgeh (&img_cr[4*edge*uvlinesize], uvlinesize, bS, h->chroma_qp[1], a, b, h, 0);
+ } else if ((edge&1) == 0) {
+ filter_mb_edgech(&img_cb[2*edge*uvlinesize], uvlinesize, bS, h->chroma_qp[0], a, b, h, 0);
+ filter_mb_edgech(&img_cr[2*edge*uvlinesize], uvlinesize, bS, h->chroma_qp[1], a, b, h, 0);
+ }
}
}
}
@@ -639,11 +674,14 @@ static av_always_inline void filter_mb_dir(H264Context *h, int mb_x, int mb_y, u
void ff_h264_filter_mb( H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr, unsigned int linesize, unsigned int uvlinesize) {
MpegEncContext * const s = &h->s;
const int mb_xy= mb_x + mb_y*s->mb_stride;
- const int mb_type = s->current_picture.mb_type[mb_xy];
+ const int mb_type = s->current_picture.f.mb_type[mb_xy];
const int mvy_limit = IS_INTERLACED(mb_type) ? 2 : 4;
int first_vertical_edge_done = 0;
av_unused int dir;
int chroma = !(CONFIG_GRAY && (s->flags&CODEC_FLAG_GRAY));
+ int qp_bd_offset = 6 * (h->sps.bit_depth_luma - 8);
+ int a = h->slice_alpha_c0_offset - qp_bd_offset;
+ int b = h->slice_beta_offset - qp_bd_offset;
if (FRAME_MBAFF
// and current and left pair do not have the same interlaced type
@@ -692,9 +730,9 @@ void ff_h264_filter_mb( H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint
}
}
- mb_qp = s->current_picture.qscale_table[mb_xy];
- mbn0_qp = s->current_picture.qscale_table[h->left_mb_xy[0]];
- mbn1_qp = s->current_picture.qscale_table[h->left_mb_xy[1]];
+ mb_qp = s->current_picture.f.qscale_table[mb_xy];
+ mbn0_qp = s->current_picture.f.qscale_table[h->left_mb_xy[0]];
+ mbn1_qp = s->current_picture.f.qscale_table[h->left_mb_xy[1]];
qp[0] = ( mb_qp + mbn0_qp + 1 ) >> 1;
bqp[0] = ( get_chroma_qp( h, 0, mb_qp ) +
get_chroma_qp( h, 0, mbn0_qp ) + 1 ) >> 1;
@@ -710,35 +748,40 @@ void ff_h264_filter_mb( H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint
tprintf(s->avctx, "filter mb:%d/%d MBAFF, QPy:%d/%d, QPb:%d/%d QPr:%d/%d ls:%d uvls:%d", mb_x, mb_y, qp[0], qp[1], bqp[0], bqp[1], rqp[0], rqp[1], linesize, uvlinesize);
{ int i; for (i = 0; i < 8; i++) tprintf(s->avctx, " bS[%d]:%d", i, bS[i]); tprintf(s->avctx, "\n"); }
if(MB_FIELD){
- filter_mb_mbaff_edgev ( h, img_y , linesize, bS , 1, qp [0] );
- filter_mb_mbaff_edgev ( h, img_y + 8* linesize, linesize, bS+4, 1, qp [1] );
+ filter_mb_mbaff_edgev ( h, img_y , linesize, bS , 1, qp [0], a, b, 1 );
+ filter_mb_mbaff_edgev ( h, img_y + 8* linesize, linesize, bS+4, 1, qp [1], a, b, 1 );
if (chroma){
if (CHROMA444) {
- filter_mb_mbaff_edgev ( h, img_cb, uvlinesize, bS , 1, bqp[0] );
- filter_mb_mbaff_edgev ( h, img_cb + 8*uvlinesize, uvlinesize, bS+4, 1, bqp[1] );
- filter_mb_mbaff_edgev ( h, img_cr, uvlinesize, bS , 1, rqp[0] );
- filter_mb_mbaff_edgev ( h, img_cr + 8*uvlinesize, uvlinesize, bS+4, 1, rqp[1] );
+ filter_mb_mbaff_edgev ( h, img_cb, uvlinesize, bS , 1, bqp[0], a, b, 1 );
+ filter_mb_mbaff_edgev ( h, img_cb + 8*uvlinesize, uvlinesize, bS+4, 1, bqp[1], a, b, 1 );
+ filter_mb_mbaff_edgev ( h, img_cr, uvlinesize, bS , 1, rqp[0], a, b, 1 );
+ filter_mb_mbaff_edgev ( h, img_cr + 8*uvlinesize, uvlinesize, bS+4, 1, rqp[1], a, b, 1 );
+ } else if (CHROMA422) {
+ filter_mb_mbaff_edgecv(h, img_cb, uvlinesize, bS , 1, bqp[0], a, b, 1);
+ filter_mb_mbaff_edgecv(h, img_cb + 8*uvlinesize, uvlinesize, bS+4, 1, bqp[1], a, b, 1);
+ filter_mb_mbaff_edgecv(h, img_cr, uvlinesize, bS , 1, rqp[0], a, b, 1);
+ filter_mb_mbaff_edgecv(h, img_cr + 8*uvlinesize, uvlinesize, bS+4, 1, rqp[1], a, b, 1);
}else{
- filter_mb_mbaff_edgecv( h, img_cb, uvlinesize, bS , 1, bqp[0] );
- filter_mb_mbaff_edgecv( h, img_cb + 4*uvlinesize, uvlinesize, bS+4, 1, bqp[1] );
- filter_mb_mbaff_edgecv( h, img_cr, uvlinesize, bS , 1, rqp[0] );
- filter_mb_mbaff_edgecv( h, img_cr + 4*uvlinesize, uvlinesize, bS+4, 1, rqp[1] );
+ filter_mb_mbaff_edgecv( h, img_cb, uvlinesize, bS , 1, bqp[0], a, b, 1 );
+ filter_mb_mbaff_edgecv( h, img_cb + 4*uvlinesize, uvlinesize, bS+4, 1, bqp[1], a, b, 1 );
+ filter_mb_mbaff_edgecv( h, img_cr, uvlinesize, bS , 1, rqp[0], a, b, 1 );
+ filter_mb_mbaff_edgecv( h, img_cr + 4*uvlinesize, uvlinesize, bS+4, 1, rqp[1], a, b, 1 );
}
}
}else{
- filter_mb_mbaff_edgev ( h, img_y , 2* linesize, bS , 2, qp [0] );
- filter_mb_mbaff_edgev ( h, img_y + linesize, 2* linesize, bS+1, 2, qp [1] );
+ filter_mb_mbaff_edgev ( h, img_y , 2* linesize, bS , 2, qp [0], a, b, 1 );
+ filter_mb_mbaff_edgev ( h, img_y + linesize, 2* linesize, bS+1, 2, qp [1], a, b, 1 );
if (chroma){
if (CHROMA444) {
- filter_mb_mbaff_edgev ( h, img_cb, 2*uvlinesize, bS , 2, bqp[0] );
- filter_mb_mbaff_edgev ( h, img_cb + uvlinesize, 2*uvlinesize, bS+1, 2, bqp[1] );
- filter_mb_mbaff_edgev ( h, img_cr, 2*uvlinesize, bS , 2, rqp[0] );
- filter_mb_mbaff_edgev ( h, img_cr + uvlinesize, 2*uvlinesize, bS+1, 2, rqp[1] );
+ filter_mb_mbaff_edgev ( h, img_cb, 2*uvlinesize, bS , 2, bqp[0], a, b, 1 );
+ filter_mb_mbaff_edgev ( h, img_cb + uvlinesize, 2*uvlinesize, bS+1, 2, bqp[1], a, b, 1 );
+ filter_mb_mbaff_edgev ( h, img_cr, 2*uvlinesize, bS , 2, rqp[0], a, b, 1 );
+ filter_mb_mbaff_edgev ( h, img_cr + uvlinesize, 2*uvlinesize, bS+1, 2, rqp[1], a, b, 1 );
}else{
- filter_mb_mbaff_edgecv( h, img_cb, 2*uvlinesize, bS , 2, bqp[0] );
- filter_mb_mbaff_edgecv( h, img_cb + uvlinesize, 2*uvlinesize, bS+1, 2, bqp[1] );
- filter_mb_mbaff_edgecv( h, img_cr, 2*uvlinesize, bS , 2, rqp[0] );
- filter_mb_mbaff_edgecv( h, img_cr + uvlinesize, 2*uvlinesize, bS+1, 2, rqp[1] );
+ filter_mb_mbaff_edgecv( h, img_cb, 2*uvlinesize, bS , 2, bqp[0], a, b, 1 );
+ filter_mb_mbaff_edgecv( h, img_cb + uvlinesize, 2*uvlinesize, bS+1, 2, bqp[1], a, b, 1 );
+ filter_mb_mbaff_edgecv( h, img_cr, 2*uvlinesize, bS , 2, rqp[0], a, b, 1 );
+ filter_mb_mbaff_edgecv( h, img_cr + uvlinesize, 2*uvlinesize, bS+1, 2, rqp[1], a, b, 1 );
}
}
}
@@ -746,9 +789,9 @@ void ff_h264_filter_mb( H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint
#if CONFIG_SMALL
for( dir = 0; dir < 2; dir++ )
- filter_mb_dir(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, mb_xy, mb_type, mvy_limit, dir ? 0 : first_vertical_edge_done, chroma, CHROMA444, dir);
+ filter_mb_dir(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, mb_xy, mb_type, mvy_limit, dir ? 0 : first_vertical_edge_done, a, b, chroma, dir);
#else
- filter_mb_dir(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, mb_xy, mb_type, mvy_limit, first_vertical_edge_done, chroma, CHROMA444, 0);
- filter_mb_dir(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, mb_xy, mb_type, mvy_limit, 0, chroma, CHROMA444, 1);
+ filter_mb_dir(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, mb_xy, mb_type, mvy_limit, first_vertical_edge_done, a, b, chroma, 0);
+ filter_mb_dir(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, mb_xy, mb_type, mvy_limit, 0, a, b, chroma, 1);
#endif
}
diff --git a/libavcodec/h264_mp4toannexb_bsf.c b/libavcodec/h264_mp4toannexb_bsf.c
index bc49b146ab..e85bdb6712 100644
--- a/libavcodec/h264_mp4toannexb_bsf.c
+++ b/libavcodec/h264_mp4toannexb_bsf.c
@@ -2,20 +2,20 @@
* H.264 MP4 to Annex B byte stream format filter
* Copyright (c) 2007 Benoit Fouet <benoit.fouet@free.fr>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -87,11 +87,7 @@ static int h264_mp4toannexb_filter(AVBitStreamFilterContext *bsfc,
/* retrieve sps and pps unit(s) */
unit_nb = *extradata++ & 0x1f; /* number of sps unit(s) */
if (!unit_nb) {
- unit_nb = *extradata++; /* number of pps unit(s) */
- sps_done++;
-
- if (unit_nb)
- pps_seen = 1;
+ goto pps;
} else {
sps_seen = 1;
}
@@ -115,7 +111,7 @@ static int h264_mp4toannexb_filter(AVBitStreamFilterContext *bsfc,
memcpy(out+total_size-unit_size-4, nalu_header, 4);
memcpy(out+total_size-unit_size, extradata+2, unit_size);
extradata += 2+unit_size;
-
+pps:
if (!unit_nb && !sps_done++) {
unit_nb = *extradata++; /* number of pps unit(s) */
if (unit_nb)
diff --git a/libavcodec/h264_mvpred.h b/libavcodec/h264_mvpred.h
index f603e7ff38..4cf79ea161 100644
--- a/libavcodec/h264_mvpred.h
+++ b/libavcodec/h264_mvpred.h
@@ -2,20 +2,20 @@
* H.26L/H.264/AVC/JVT/14496-10/... motion vector predicion
* Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -35,7 +35,7 @@
//#undef NDEBUG
#include <assert.h>
-static inline int fetch_diagonal_mv(H264Context *h, const int16_t **C, int i, int list, int part_width){
+static av_always_inline int fetch_diagonal_mv(H264Context *h, const int16_t **C, int i, int list, int part_width){
const int topright_ref= h->ref_cache[list][ i - 8 + part_width ];
MpegEncContext *s = &h->s;
@@ -48,15 +48,15 @@ static inline int fetch_diagonal_mv(H264Context *h, const int16_t **C, int i, in
const int mb_type = mb_types[xy+(y4>>2)*s->mb_stride];\
if(!USES_LIST(mb_type,list))\
return LIST_NOT_USED;\
- mv = s->current_picture_ptr->motion_val[list][h->mb2b_xy[xy]+3 + y4*h->b_stride];\
+ mv = s->current_picture_ptr->f.motion_val[list][h->mb2b_xy[xy] + 3 + y4*h->b_stride];\
h->mv_cache[list][scan8[0]-2][0] = mv[0];\
h->mv_cache[list][scan8[0]-2][1] = mv[1] MV_OP;\
- return s->current_picture_ptr->ref_index[list][4*xy+1 + (y4&~1)] REF_OP;
+ return s->current_picture_ptr->f.ref_index[list][4*xy + 1 + (y4 & ~1)] REF_OP;
if(topright_ref == PART_NOT_AVAILABLE
&& i >= scan8[0]+8 && (i&7)==4
&& h->ref_cache[list][scan8[0]-1] != PART_NOT_AVAILABLE){
- const uint32_t *mb_types = s->current_picture_ptr->mb_type;
+ const uint32_t *mb_types = s->current_picture_ptr->f.mb_type;
const int16_t *mv;
AV_ZERO32(h->mv_cache[list][scan8[0]-2]);
*C = h->mv_cache[list][scan8[0]-2];
@@ -92,7 +92,7 @@ static inline int fetch_diagonal_mv(H264Context *h, const int16_t **C, int i, in
* @param mx the x component of the predicted motion vector
* @param my the y component of the predicted motion vector
*/
-static inline void pred_motion(H264Context * const h, int n, int part_width, int list, int ref, int * const mx, int * const my){
+static av_always_inline void pred_motion(H264Context * const h, int n, int part_width, int list, int ref, int * const mx, int * const my){
const int index8= scan8[n];
const int top_ref= h->ref_cache[list][ index8 - 8 ];
const int left_ref= h->ref_cache[list][ index8 - 1 ];
@@ -147,7 +147,7 @@ static inline void pred_motion(H264Context * const h, int n, int part_width, int
* @param mx the x component of the predicted motion vector
* @param my the y component of the predicted motion vector
*/
-static inline void pred_16x8_motion(H264Context * const h, int n, int list, int ref, int * const mx, int * const my){
+static av_always_inline void pred_16x8_motion(H264Context * const h, int n, int list, int ref, int * const mx, int * const my){
if(n==0){
const int top_ref= h->ref_cache[list][ scan8[0] - 8 ];
const int16_t * const B= h->mv_cache[list][ scan8[0] - 8 ];
@@ -182,7 +182,7 @@ static inline void pred_16x8_motion(H264Context * const h, int n, int list, int
* @param mx the x component of the predicted motion vector
* @param my the y component of the predicted motion vector
*/
-static inline void pred_8x16_motion(H264Context * const h, int n, int list, int ref, int * const mx, int * const my){
+static av_always_inline void pred_8x16_motion(H264Context * const h, int n, int list, int ref, int * const mx, int * const my){
if(n==0){
const int left_ref= h->ref_cache[list][ scan8[0] - 1 ];
const int16_t * const A= h->mv_cache[list][ scan8[0] - 1 ];
@@ -213,23 +213,580 @@ static inline void pred_8x16_motion(H264Context * const h, int n, int list, int
pred_motion(h, n, 2, list, ref, mx, my);
}
-static inline void pred_pskip_motion(H264Context * const h, int * const mx, int * const my){
- const int top_ref = h->ref_cache[0][ scan8[0] - 8 ];
- const int left_ref= h->ref_cache[0][ scan8[0] - 1 ];
+#define FIX_MV_MBAFF(type, refn, mvn, idx)\
+ if(FRAME_MBAFF){\
+ if(MB_FIELD){\
+ if(!IS_INTERLACED(type)){\
+ refn <<= 1;\
+ AV_COPY32(mvbuf[idx], mvn);\
+ mvbuf[idx][1] /= 2;\
+ mvn = mvbuf[idx];\
+ }\
+ }else{\
+ if(IS_INTERLACED(type)){\
+ refn >>= 1;\
+ AV_COPY32(mvbuf[idx], mvn);\
+ mvbuf[idx][1] <<= 1;\
+ mvn = mvbuf[idx];\
+ }\
+ }\
+ }
- tprintf(h->s.avctx, "pred_pskip: (%d) (%d) at %2d %2d\n", top_ref, left_ref, h->s.mb_x, h->s.mb_y);
+static av_always_inline void pred_pskip_motion(H264Context * const h){
+ DECLARE_ALIGNED(4, static const int16_t, zeromv)[2] = {0};
+ DECLARE_ALIGNED(4, int16_t, mvbuf)[3][2];
+ MpegEncContext * const s = &h->s;
+ int8_t *ref = s->current_picture.f.ref_index[0];
+ int16_t (*mv)[2] = s->current_picture.f.motion_val[0];
+ int top_ref, left_ref, diagonal_ref, match_count, mx, my;
+ const int16_t *A, *B, *C;
+ int b_stride = h->b_stride;
+
+ fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, 0, 1);
+
+ /* To avoid doing an entire fill_decode_caches, we inline the relevant parts here.
+ * FIXME: this is a partial duplicate of the logic in fill_decode_caches, but it's
+ * faster this way. Is there a way to avoid this duplication?
+ */
+ if(USES_LIST(h->left_type[LTOP], 0)){
+ left_ref = ref[4*h->left_mb_xy[LTOP] + 1 + (h->left_block[0]&~1)];
+ A = mv[h->mb2b_xy[h->left_mb_xy[LTOP]] + 3 + b_stride*h->left_block[0]];
+ FIX_MV_MBAFF(h->left_type[LTOP], left_ref, A, 0);
+ if(!(left_ref | AV_RN32A(A))){
+ goto zeromv;
+ }
+ }else if(h->left_type[LTOP]){
+ left_ref = LIST_NOT_USED;
+ A = zeromv;
+ }else{
+ goto zeromv;
+ }
- if(top_ref == PART_NOT_AVAILABLE || left_ref == PART_NOT_AVAILABLE
- || !( top_ref | AV_RN32A(h->mv_cache[0][ scan8[0] - 8 ]))
- || !(left_ref | AV_RN32A(h->mv_cache[0][ scan8[0] - 1 ]))){
+ if(USES_LIST(h->top_type, 0)){
+ top_ref = ref[4*h->top_mb_xy + 2];
+ B = mv[h->mb2b_xy[h->top_mb_xy] + 3*b_stride];
+ FIX_MV_MBAFF(h->top_type, top_ref, B, 1);
+ if(!(top_ref | AV_RN32A(B))){
+ goto zeromv;
+ }
+ }else if(h->top_type){
+ top_ref = LIST_NOT_USED;
+ B = zeromv;
+ }else{
+ goto zeromv;
+ }
- *mx = *my = 0;
- return;
+ tprintf(h->s.avctx, "pred_pskip: (%d) (%d) at %2d %2d\n", top_ref, left_ref, h->s.mb_x, h->s.mb_y);
+
+ if(USES_LIST(h->topright_type, 0)){
+ diagonal_ref = ref[4*h->topright_mb_xy + 2];
+ C = mv[h->mb2b_xy[h->topright_mb_xy] + 3*b_stride];
+ FIX_MV_MBAFF(h->topright_type, diagonal_ref, C, 2);
+ }else if(h->topright_type){
+ diagonal_ref = LIST_NOT_USED;
+ C = zeromv;
+ }else{
+ if(USES_LIST(h->topleft_type, 0)){
+ diagonal_ref = ref[4*h->topleft_mb_xy + 1 + (h->topleft_partition & 2)];
+ C = mv[h->mb2b_xy[h->topleft_mb_xy] + 3 + b_stride + (h->topleft_partition & 2*b_stride)];
+ FIX_MV_MBAFF(h->topleft_type, diagonal_ref, C, 2);
+ }else if(h->topleft_type){
+ diagonal_ref = LIST_NOT_USED;
+ C = zeromv;
+ }else{
+ diagonal_ref = PART_NOT_AVAILABLE;
+ C = zeromv;
+ }
}
- pred_motion(h, 0, 4, 0, 0, mx, my);
+ match_count= !diagonal_ref + !top_ref + !left_ref;
+ tprintf(h->s.avctx, "pred_pskip_motion match_count=%d\n", match_count);
+ if(match_count > 1){
+ mx = mid_pred(A[0], B[0], C[0]);
+ my = mid_pred(A[1], B[1], C[1]);
+ }else if(match_count==1){
+ if(!left_ref){
+ mx = A[0];
+ my = A[1];
+ }else if(!top_ref){
+ mx = B[0];
+ my = B[1];
+ }else{
+ mx = C[0];
+ my = C[1];
+ }
+ }else{
+ mx = mid_pred(A[0], B[0], C[0]);
+ my = mid_pred(A[1], B[1], C[1]);
+ }
+ fill_rectangle( h->mv_cache[0][scan8[0]], 4, 4, 8, pack16to32(mx,my), 4);
+ return;
+zeromv:
+ fill_rectangle( h->mv_cache[0][scan8[0]], 4, 4, 8, 0, 4);
return;
}
+static void fill_decode_neighbors(H264Context *h, int mb_type){
+ MpegEncContext * const s = &h->s;
+ const int mb_xy= h->mb_xy;
+ int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS];
+ static const uint8_t left_block_options[4][32]={
+ {0,1,2,3,7,10,8,11,3+0*4, 3+1*4, 3+2*4, 3+3*4, 1+4*4, 1+8*4, 1+5*4, 1+9*4},
+ {2,2,3,3,8,11,8,11,3+2*4, 3+2*4, 3+3*4, 3+3*4, 1+5*4, 1+9*4, 1+5*4, 1+9*4},
+ {0,0,1,1,7,10,7,10,3+0*4, 3+0*4, 3+1*4, 3+1*4, 1+4*4, 1+8*4, 1+4*4, 1+8*4},
+ {0,2,0,2,7,10,7,10,3+0*4, 3+2*4, 3+0*4, 3+2*4, 1+4*4, 1+8*4, 1+4*4, 1+8*4}
+ };
+
+ h->topleft_partition= -1;
+
+ top_xy = mb_xy - (s->mb_stride << MB_FIELD);
+
+ /* Wow, what a mess, why didn't they simplify the interlacing & intra
+ * stuff, I can't imagine that these complex rules are worth it. */
+
+ topleft_xy = top_xy - 1;
+ topright_xy= top_xy + 1;
+ left_xy[LBOT] = left_xy[LTOP] = mb_xy-1;
+ h->left_block = left_block_options[0];
+ if(FRAME_MBAFF){
+ const int left_mb_field_flag = IS_INTERLACED(s->current_picture.f.mb_type[mb_xy - 1]);
+ const int curr_mb_field_flag = IS_INTERLACED(mb_type);
+ if(s->mb_y&1){
+ if (left_mb_field_flag != curr_mb_field_flag) {
+ left_xy[LBOT] = left_xy[LTOP] = mb_xy - s->mb_stride - 1;
+ if (curr_mb_field_flag) {
+ left_xy[LBOT] += s->mb_stride;
+ h->left_block = left_block_options[3];
+ } else {
+ topleft_xy += s->mb_stride;
+ // take top left mv from the middle of the mb, as opposed to all other modes which use the bottom right partition
+ h->topleft_partition = 0;
+ h->left_block = left_block_options[1];
+ }
+ }
+ }else{
+ if(curr_mb_field_flag){
+ topleft_xy += s->mb_stride & (((s->current_picture.f.mb_type[top_xy - 1] >> 7) & 1) - 1);
+ topright_xy += s->mb_stride & (((s->current_picture.f.mb_type[top_xy + 1] >> 7) & 1) - 1);
+ top_xy += s->mb_stride & (((s->current_picture.f.mb_type[top_xy ] >> 7) & 1) - 1);
+ }
+ if (left_mb_field_flag != curr_mb_field_flag) {
+ if (curr_mb_field_flag) {
+ left_xy[LBOT] += s->mb_stride;
+ h->left_block = left_block_options[3];
+ } else {
+ h->left_block = left_block_options[2];
+ }
+ }
+ }
+ }
+
+ h->topleft_mb_xy = topleft_xy;
+ h->top_mb_xy = top_xy;
+ h->topright_mb_xy= topright_xy;
+ h->left_mb_xy[LTOP] = left_xy[LTOP];
+ h->left_mb_xy[LBOT] = left_xy[LBOT];
+ //FIXME do we need all in the context?
+
+ h->topleft_type = s->current_picture.f.mb_type[topleft_xy];
+ h->top_type = s->current_picture.f.mb_type[top_xy];
+ h->topright_type = s->current_picture.f.mb_type[topright_xy];
+ h->left_type[LTOP] = s->current_picture.f.mb_type[left_xy[LTOP]];
+ h->left_type[LBOT] = s->current_picture.f.mb_type[left_xy[LBOT]];
+
+ if(FMO){
+ if(h->slice_table[topleft_xy ] != h->slice_num) h->topleft_type = 0;
+ if(h->slice_table[top_xy ] != h->slice_num) h->top_type = 0;
+ if(h->slice_table[left_xy[LTOP] ] != h->slice_num) h->left_type[LTOP] = h->left_type[LBOT] = 0;
+ }else{
+ if(h->slice_table[topleft_xy ] != h->slice_num){
+ h->topleft_type = 0;
+ if(h->slice_table[top_xy ] != h->slice_num) h->top_type = 0;
+ if(h->slice_table[left_xy[LTOP] ] != h->slice_num) h->left_type[LTOP] = h->left_type[LBOT] = 0;
+ }
+ }
+ if(h->slice_table[topright_xy] != h->slice_num) h->topright_type= 0;
+}
+
+static void fill_decode_caches(H264Context *h, int mb_type){
+ MpegEncContext * const s = &h->s;
+ int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS];
+ int topleft_type, top_type, topright_type, left_type[LEFT_MBS];
+ const uint8_t * left_block= h->left_block;
+ int i;
+ uint8_t *nnz;
+ uint8_t *nnz_cache;
+
+ topleft_xy = h->topleft_mb_xy;
+ top_xy = h->top_mb_xy;
+ topright_xy = h->topright_mb_xy;
+ left_xy[LTOP] = h->left_mb_xy[LTOP];
+ left_xy[LBOT] = h->left_mb_xy[LBOT];
+ topleft_type = h->topleft_type;
+ top_type = h->top_type;
+ topright_type = h->topright_type;
+ left_type[LTOP]= h->left_type[LTOP];
+ left_type[LBOT]= h->left_type[LBOT];
+
+ if(!IS_SKIP(mb_type)){
+ if(IS_INTRA(mb_type)){
+ int type_mask= h->pps.constrained_intra_pred ? IS_INTRA(-1) : -1;
+ h->topleft_samples_available=
+ h->top_samples_available=
+ h->left_samples_available= 0xFFFF;
+ h->topright_samples_available= 0xEEEA;
+
+ if(!(top_type & type_mask)){
+ h->topleft_samples_available= 0xB3FF;
+ h->top_samples_available= 0x33FF;
+ h->topright_samples_available= 0x26EA;
+ }
+ if(IS_INTERLACED(mb_type) != IS_INTERLACED(left_type[LTOP])){
+ if(IS_INTERLACED(mb_type)){
+ if(!(left_type[LTOP] & type_mask)){
+ h->topleft_samples_available&= 0xDFFF;
+ h->left_samples_available&= 0x5FFF;
+ }
+ if(!(left_type[LBOT] & type_mask)){
+ h->topleft_samples_available&= 0xFF5F;
+ h->left_samples_available&= 0xFF5F;
+ }
+ }else{
+ int left_typei = s->current_picture.f.mb_type[left_xy[LTOP] + s->mb_stride];
+
+ assert(left_xy[LTOP] == left_xy[LBOT]);
+ if(!((left_typei & type_mask) && (left_type[LTOP] & type_mask))){
+ h->topleft_samples_available&= 0xDF5F;
+ h->left_samples_available&= 0x5F5F;
+ }
+ }
+ }else{
+ if(!(left_type[LTOP] & type_mask)){
+ h->topleft_samples_available&= 0xDF5F;
+ h->left_samples_available&= 0x5F5F;
+ }
+ }
+
+ if(!(topleft_type & type_mask))
+ h->topleft_samples_available&= 0x7FFF;
+
+ if(!(topright_type & type_mask))
+ h->topright_samples_available&= 0xFBFF;
+
+ if(IS_INTRA4x4(mb_type)){
+ if(IS_INTRA4x4(top_type)){
+ AV_COPY32(h->intra4x4_pred_mode_cache+4+8*0, h->intra4x4_pred_mode + h->mb2br_xy[top_xy]);
+ }else{
+ h->intra4x4_pred_mode_cache[4+8*0]=
+ h->intra4x4_pred_mode_cache[5+8*0]=
+ h->intra4x4_pred_mode_cache[6+8*0]=
+ h->intra4x4_pred_mode_cache[7+8*0]= 2 - 3*!(top_type & type_mask);
+ }
+ for(i=0; i<2; i++){
+ if(IS_INTRA4x4(left_type[LEFT(i)])){
+ int8_t *mode= h->intra4x4_pred_mode + h->mb2br_xy[left_xy[LEFT(i)]];
+ h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]= mode[6-left_block[0+2*i]];
+ h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= mode[6-left_block[1+2*i]];
+ }else{
+ h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]=
+ h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= 2 - 3*!(left_type[LEFT(i)] & type_mask);
+ }
+ }
+ }
+ }
+
+
+/*
+0 . T T. T T T T
+1 L . .L . . . .
+2 L . .L . . . .
+3 . T TL . . . .
+4 L . .L . . . .
+5 L . .. . . . .
+*/
+//FIXME constraint_intra_pred & partitioning & nnz (let us hope this is just a typo in the spec)
+ nnz_cache = h->non_zero_count_cache;
+ if(top_type){
+ nnz = h->non_zero_count[top_xy];
+ AV_COPY32(&nnz_cache[4+8* 0], &nnz[4*3]);
+ if(!s->chroma_y_shift){
+ AV_COPY32(&nnz_cache[4+8* 5], &nnz[4* 7]);
+ AV_COPY32(&nnz_cache[4+8*10], &nnz[4*11]);
+ }else{
+ AV_COPY32(&nnz_cache[4+8* 5], &nnz[4* 5]);
+ AV_COPY32(&nnz_cache[4+8*10], &nnz[4* 9]);
+ }
+ }else{
+ uint32_t top_empty = CABAC && !IS_INTRA(mb_type) ? 0 : 0x40404040;
+ AV_WN32A(&nnz_cache[4+8* 0], top_empty);
+ AV_WN32A(&nnz_cache[4+8* 5], top_empty);
+ AV_WN32A(&nnz_cache[4+8*10], top_empty);
+ }
+
+ for (i=0; i<2; i++) {
+ if(left_type[LEFT(i)]){
+ nnz = h->non_zero_count[left_xy[LEFT(i)]];
+ nnz_cache[3+8* 1 + 2*8*i]= nnz[left_block[8+0+2*i]];
+ nnz_cache[3+8* 2 + 2*8*i]= nnz[left_block[8+1+2*i]];
+ if(CHROMA444){
+ nnz_cache[3+8* 6 + 2*8*i]= nnz[left_block[8+0+2*i]+4*4];
+ nnz_cache[3+8* 7 + 2*8*i]= nnz[left_block[8+1+2*i]+4*4];
+ nnz_cache[3+8*11 + 2*8*i]= nnz[left_block[8+0+2*i]+8*4];
+ nnz_cache[3+8*12 + 2*8*i]= nnz[left_block[8+1+2*i]+8*4];
+ }else if(CHROMA422) {
+ nnz_cache[3+8* 6 + 2*8*i]= nnz[left_block[8+0+2*i]-2+4*4];
+ nnz_cache[3+8* 7 + 2*8*i]= nnz[left_block[8+1+2*i]-2+4*4];
+ nnz_cache[3+8*11 + 2*8*i]= nnz[left_block[8+0+2*i]-2+8*4];
+ nnz_cache[3+8*12 + 2*8*i]= nnz[left_block[8+1+2*i]-2+8*4];
+ }else{
+ nnz_cache[3+8* 6 + 8*i]= nnz[left_block[8+4+2*i]];
+ nnz_cache[3+8*11 + 8*i]= nnz[left_block[8+5+2*i]];
+ }
+ }else{
+ nnz_cache[3+8* 1 + 2*8*i]=
+ nnz_cache[3+8* 2 + 2*8*i]=
+ nnz_cache[3+8* 6 + 2*8*i]=
+ nnz_cache[3+8* 7 + 2*8*i]=
+ nnz_cache[3+8*11 + 2*8*i]=
+ nnz_cache[3+8*12 + 2*8*i]= CABAC && !IS_INTRA(mb_type) ? 0 : 64;
+ }
+ }
+
+ if( CABAC ) {
+ // top_cbp
+ if(top_type) {
+ h->top_cbp = h->cbp_table[top_xy];
+ } else {
+ h->top_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F;
+ }
+ // left_cbp
+ if (left_type[LTOP]) {
+ h->left_cbp = (h->cbp_table[left_xy[LTOP]] & 0x7F0)
+ | ((h->cbp_table[left_xy[LTOP]]>>(left_block[0]&(~1)))&2)
+ | (((h->cbp_table[left_xy[LBOT]]>>(left_block[2]&(~1)))&2) << 2);
+ } else {
+ h->left_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F;
+ }
+ }
+ }
+
+ if(IS_INTER(mb_type) || (IS_DIRECT(mb_type) && h->direct_spatial_mv_pred)){
+ int list;
+ int b_stride = h->b_stride;
+ for(list=0; list<h->list_count; list++){
+ int8_t *ref_cache = &h->ref_cache[list][scan8[0]];
+ int8_t *ref = s->current_picture.f.ref_index[list];
+ int16_t (*mv_cache)[2] = &h->mv_cache[list][scan8[0]];
+ int16_t (*mv)[2] = s->current_picture.f.motion_val[list];
+ if(!USES_LIST(mb_type, list)){
+ continue;
+ }
+ assert(!(IS_DIRECT(mb_type) && !h->direct_spatial_mv_pred));
+
+ if(USES_LIST(top_type, list)){
+ const int b_xy= h->mb2b_xy[top_xy] + 3*b_stride;
+ AV_COPY128(mv_cache[0 - 1*8], mv[b_xy + 0]);
+ ref_cache[0 - 1*8]=
+ ref_cache[1 - 1*8]= ref[4*top_xy + 2];
+ ref_cache[2 - 1*8]=
+ ref_cache[3 - 1*8]= ref[4*top_xy + 3];
+ }else{
+ AV_ZERO128(mv_cache[0 - 1*8]);
+ AV_WN32A(&ref_cache[0 - 1*8], ((top_type ? LIST_NOT_USED : PART_NOT_AVAILABLE)&0xFF)*0x01010101u);
+ }
+
+ if(mb_type & (MB_TYPE_16x8|MB_TYPE_8x8)){
+ for(i=0; i<2; i++){
+ int cache_idx = -1 + i*2*8;
+ if(USES_LIST(left_type[LEFT(i)], list)){
+ const int b_xy= h->mb2b_xy[left_xy[LEFT(i)]] + 3;
+ const int b8_xy= 4*left_xy[LEFT(i)] + 1;
+ AV_COPY32(mv_cache[cache_idx ], mv[b_xy + b_stride*left_block[0+i*2]]);
+ AV_COPY32(mv_cache[cache_idx+8], mv[b_xy + b_stride*left_block[1+i*2]]);
+ ref_cache[cache_idx ]= ref[b8_xy + (left_block[0+i*2]&~1)];
+ ref_cache[cache_idx+8]= ref[b8_xy + (left_block[1+i*2]&~1)];
+ }else{
+ AV_ZERO32(mv_cache[cache_idx ]);
+ AV_ZERO32(mv_cache[cache_idx+8]);
+ ref_cache[cache_idx ]=
+ ref_cache[cache_idx+8]= (left_type[LEFT(i)]) ? LIST_NOT_USED : PART_NOT_AVAILABLE;
+ }
+ }
+ }else{
+ if(USES_LIST(left_type[LTOP], list)){
+ const int b_xy= h->mb2b_xy[left_xy[LTOP]] + 3;
+ const int b8_xy= 4*left_xy[LTOP] + 1;
+ AV_COPY32(mv_cache[-1], mv[b_xy + b_stride*left_block[0]]);
+ ref_cache[-1]= ref[b8_xy + (left_block[0]&~1)];
+ }else{
+ AV_ZERO32(mv_cache[-1]);
+ ref_cache[-1]= left_type[LTOP] ? LIST_NOT_USED : PART_NOT_AVAILABLE;
+ }
+ }
+
+ if(USES_LIST(topright_type, list)){
+ const int b_xy= h->mb2b_xy[topright_xy] + 3*b_stride;
+ AV_COPY32(mv_cache[4 - 1*8], mv[b_xy]);
+ ref_cache[4 - 1*8]= ref[4*topright_xy + 2];
+ }else{
+ AV_ZERO32(mv_cache[4 - 1*8]);
+ ref_cache[4 - 1*8]= topright_type ? LIST_NOT_USED : PART_NOT_AVAILABLE;
+ }
+ if(ref_cache[4 - 1*8] < 0){
+ if(USES_LIST(topleft_type, list)){
+ const int b_xy = h->mb2b_xy[topleft_xy] + 3 + b_stride + (h->topleft_partition & 2*b_stride);
+ const int b8_xy= 4*topleft_xy + 1 + (h->topleft_partition & 2);
+ AV_COPY32(mv_cache[-1 - 1*8], mv[b_xy]);
+ ref_cache[-1 - 1*8]= ref[b8_xy];
+ }else{
+ AV_ZERO32(mv_cache[-1 - 1*8]);
+ ref_cache[-1 - 1*8]= topleft_type ? LIST_NOT_USED : PART_NOT_AVAILABLE;
+ }
+ }
+
+ if((mb_type&(MB_TYPE_SKIP|MB_TYPE_DIRECT2)) && !FRAME_MBAFF)
+ continue;
+
+ if(!(mb_type&(MB_TYPE_SKIP|MB_TYPE_DIRECT2))){
+ uint8_t (*mvd_cache)[2] = &h->mvd_cache[list][scan8[0]];
+ uint8_t (*mvd)[2] = h->mvd_table[list];
+ ref_cache[2+8*0] =
+ ref_cache[2+8*2] = PART_NOT_AVAILABLE;
+ AV_ZERO32(mv_cache[2+8*0]);
+ AV_ZERO32(mv_cache[2+8*2]);
+
+ if( CABAC ) {
+ if(USES_LIST(top_type, list)){
+ const int b_xy= h->mb2br_xy[top_xy];
+ AV_COPY64(mvd_cache[0 - 1*8], mvd[b_xy + 0]);
+ }else{
+ AV_ZERO64(mvd_cache[0 - 1*8]);
+ }
+ if(USES_LIST(left_type[LTOP], list)){
+ const int b_xy= h->mb2br_xy[left_xy[LTOP]] + 6;
+ AV_COPY16(mvd_cache[-1 + 0*8], mvd[b_xy - left_block[0]]);
+ AV_COPY16(mvd_cache[-1 + 1*8], mvd[b_xy - left_block[1]]);
+ }else{
+ AV_ZERO16(mvd_cache[-1 + 0*8]);
+ AV_ZERO16(mvd_cache[-1 + 1*8]);
+ }
+ if(USES_LIST(left_type[LBOT], list)){
+ const int b_xy= h->mb2br_xy[left_xy[LBOT]] + 6;
+ AV_COPY16(mvd_cache[-1 + 2*8], mvd[b_xy - left_block[2]]);
+ AV_COPY16(mvd_cache[-1 + 3*8], mvd[b_xy - left_block[3]]);
+ }else{
+ AV_ZERO16(mvd_cache[-1 + 2*8]);
+ AV_ZERO16(mvd_cache[-1 + 3*8]);
+ }
+ AV_ZERO16(mvd_cache[2+8*0]);
+ AV_ZERO16(mvd_cache[2+8*2]);
+ if(h->slice_type_nos == AV_PICTURE_TYPE_B){
+ uint8_t *direct_cache = &h->direct_cache[scan8[0]];
+ uint8_t *direct_table = h->direct_table;
+ fill_rectangle(direct_cache, 4, 4, 8, MB_TYPE_16x16>>1, 1);
+
+ if(IS_DIRECT(top_type)){
+ AV_WN32A(&direct_cache[-1*8], 0x01010101u*(MB_TYPE_DIRECT2>>1));
+ }else if(IS_8X8(top_type)){
+ int b8_xy = 4*top_xy;
+ direct_cache[0 - 1*8]= direct_table[b8_xy + 2];
+ direct_cache[2 - 1*8]= direct_table[b8_xy + 3];
+ }else{
+ AV_WN32A(&direct_cache[-1*8], 0x01010101*(MB_TYPE_16x16>>1));
+ }
+
+ if(IS_DIRECT(left_type[LTOP]))
+ direct_cache[-1 + 0*8]= MB_TYPE_DIRECT2>>1;
+ else if(IS_8X8(left_type[LTOP]))
+ direct_cache[-1 + 0*8]= direct_table[4*left_xy[LTOP] + 1 + (left_block[0]&~1)];
+ else
+ direct_cache[-1 + 0*8]= MB_TYPE_16x16>>1;
+
+ if(IS_DIRECT(left_type[LBOT]))
+ direct_cache[-1 + 2*8]= MB_TYPE_DIRECT2>>1;
+ else if(IS_8X8(left_type[LBOT]))
+ direct_cache[-1 + 2*8]= direct_table[4*left_xy[LBOT] + 1 + (left_block[2]&~1)];
+ else
+ direct_cache[-1 + 2*8]= MB_TYPE_16x16>>1;
+ }
+ }
+ }
+ if(FRAME_MBAFF){
+#define MAP_MVS\
+ MAP_F2F(scan8[0] - 1 - 1*8, topleft_type)\
+ MAP_F2F(scan8[0] + 0 - 1*8, top_type)\
+ MAP_F2F(scan8[0] + 1 - 1*8, top_type)\
+ MAP_F2F(scan8[0] + 2 - 1*8, top_type)\
+ MAP_F2F(scan8[0] + 3 - 1*8, top_type)\
+ MAP_F2F(scan8[0] + 4 - 1*8, topright_type)\
+ MAP_F2F(scan8[0] - 1 + 0*8, left_type[LTOP])\
+ MAP_F2F(scan8[0] - 1 + 1*8, left_type[LTOP])\
+ MAP_F2F(scan8[0] - 1 + 2*8, left_type[LBOT])\
+ MAP_F2F(scan8[0] - 1 + 3*8, left_type[LBOT])
+ if(MB_FIELD){
+#define MAP_F2F(idx, mb_type)\
+ if(!IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0){\
+ h->ref_cache[list][idx] <<= 1;\
+ h->mv_cache[list][idx][1] /= 2;\
+ h->mvd_cache[list][idx][1] >>=1;\
+ }
+ MAP_MVS
+#undef MAP_F2F
+ }else{
+#define MAP_F2F(idx, mb_type)\
+ if(IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0){\
+ h->ref_cache[list][idx] >>= 1;\
+ h->mv_cache[list][idx][1] <<= 1;\
+ h->mvd_cache[list][idx][1] <<= 1;\
+ }
+ MAP_MVS
+#undef MAP_F2F
+ }
+ }
+ }
+ }
+
+ h->neighbor_transform_size= !!IS_8x8DCT(top_type) + !!IS_8x8DCT(left_type[LTOP]);
+}
+
+/**
+ * decodes a P_SKIP or B_SKIP macroblock
+ */
+static void av_unused decode_mb_skip(H264Context *h){
+ MpegEncContext * const s = &h->s;
+ const int mb_xy= h->mb_xy;
+ int mb_type=0;
+
+ memset(h->non_zero_count[mb_xy], 0, 48);
+
+ if(MB_FIELD)
+ mb_type|= MB_TYPE_INTERLACED;
+
+ if( h->slice_type_nos == AV_PICTURE_TYPE_B )
+ {
+ // just for fill_caches. pred_direct_motion will set the real mb_type
+ mb_type|= MB_TYPE_L0L1|MB_TYPE_DIRECT2|MB_TYPE_SKIP;
+ if(h->direct_spatial_mv_pred){
+ fill_decode_neighbors(h, mb_type);
+ fill_decode_caches(h, mb_type); //FIXME check what is needed and what not ...
+ }
+ ff_h264_pred_direct_motion(h, &mb_type);
+ mb_type|= MB_TYPE_SKIP;
+ }
+ else
+ {
+ mb_type|= MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P1L0|MB_TYPE_SKIP;
+
+ fill_decode_neighbors(h, mb_type);
+ pred_pskip_motion(h);
+ }
+
+ write_back_motion(h, mb_type);
+ s->current_picture.f.mb_type[mb_xy] = mb_type;
+ s->current_picture.f.qscale_table[mb_xy] = s->qscale;
+ h->slice_table[ mb_xy ]= h->slice_num;
+ h->prev_mb_skipped= 1;
+}
+
#endif /* AVCODEC_H264_MVPRED_H */
diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c
index 56102691a8..614dad35eb 100644
--- a/libavcodec/h264_parser.c
+++ b/libavcodec/h264_parser.c
@@ -2,20 +2,20 @@
* H.26L/H.264/AVC/JVT/14496-10/... parser
* Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -34,30 +34,48 @@
static int ff_h264_find_frame_end(H264Context *h, const uint8_t *buf, int buf_size)
{
- int i;
+ int i, j;
uint32_t state;
ParseContext *pc = &(h->s.parse_context);
+ int next_avc= h->is_avc ? 0 : buf_size;
+
//printf("first %02X%02X%02X%02X\n", buf[0], buf[1],buf[2],buf[3]);
// mb_addr= pc->mb_addr - 1;
state= pc->state;
if(state>13)
state= 7;
+ if(h->is_avc && !h->nal_length_size)
+ av_log(h->s.avctx, AV_LOG_ERROR, "AVC-parser: nal length size invalid\n");
+
for(i=0; i<buf_size; i++){
+ if(i >= next_avc) {
+ int nalsize = 0;
+ i = next_avc;
+ for(j = 0; j < h->nal_length_size; j++)
+ nalsize = (nalsize << 8) | buf[i++];
+ if(nalsize <= 0 || nalsize > buf_size - i){
+ av_log(h->s.avctx, AV_LOG_ERROR, "AVC-parser: nal size %d remaining %d\n", nalsize, buf_size - i);
+ return buf_size;
+ }
+ next_avc= i + nalsize;
+ state= 5;
+ }
+
if(state==7){
#if HAVE_FAST_UNALIGNED
/* we check i<buf_size instead of i+3/7 because its simpler
* and there should be FF_INPUT_BUFFER_PADDING_SIZE bytes at the end
*/
# if HAVE_FAST_64BIT
- while(i<buf_size && !((~*(const uint64_t*)(buf+i) & (*(const uint64_t*)(buf+i) - 0x0101010101010101ULL)) & 0x8080808080808080ULL))
+ while(i<next_avc && !((~*(const uint64_t*)(buf+i) & (*(const uint64_t*)(buf+i) - 0x0101010101010101ULL)) & 0x8080808080808080ULL))
i+=8;
# else
- while(i<buf_size && !((~*(const uint32_t*)(buf+i) & (*(const uint32_t*)(buf+i) - 0x01010101U)) & 0x80808080U))
+ while(i<next_avc && !((~*(const uint32_t*)(buf+i) & (*(const uint32_t*)(buf+i) - 0x01010101U)) & 0x80808080U))
i+=4;
# endif
#endif
- for(; i<buf_size; i++){
+ for(; i<next_avc; i++){
if(!buf[i]){
state=2;
break;
@@ -89,11 +107,15 @@ static int ff_h264_find_frame_end(H264Context *h, const uint8_t *buf, int buf_si
}
}
pc->state= state;
+ if(h->is_avc)
+ return next_avc;
return END_NOT_FOUND;
found:
pc->state=7;
pc->frame_start_found= 0;
+ if(h->is_avc)
+ return next_avc;
return i-(state&5);
}
@@ -131,7 +153,7 @@ static inline int parse_nal_units(AVCodecParserContext *s,
for(;;) {
int src_length, dst_length, consumed;
- buf = ff_find_start_code(buf, buf_end, &state);
+ buf = avpriv_mpv_find_start_code(buf, buf_end, &state);
if(buf >= buf_end)
break;
--buf;
@@ -234,7 +256,7 @@ static inline int parse_nal_units(AVCodecParserContext *s,
buf += consumed;
}
/* didn't find a picture! */
- av_log(h->s.avctx, AV_LOG_ERROR, "missing picture in access unit\n");
+ av_log(h->s.avctx, AV_LOG_ERROR, "missing picture in access unit with size %d\n", buf_size);
return -1;
}
@@ -251,7 +273,13 @@ static int h264_parse(AVCodecParserContext *s,
h->got_first = 1;
if (avctx->extradata_size) {
h->s.avctx = avctx;
- ff_h264_decode_extradata(h);
+ // must be done like in decoder, otherwise opening the parser,
+ // letting it create extradata and then closing and opening again
+ // will cause has_b_frames to be always set.
+ // Note that estimate_timings_from_pts does exactly this.
+ if (!avctx->has_b_frames)
+ h->s.low_delay = 1;
+ ff_h264_decode_extradata(h, avctx->extradata, avctx->extradata_size);
}
}
@@ -272,6 +300,7 @@ static int h264_parse(AVCodecParserContext *s,
}
}
+ if(!h->is_avc){
parse_nal_units(s, avctx, buf, buf_size);
if (h->sei_cpb_removal_delay >= 0) {
@@ -287,6 +316,7 @@ static int h264_parse(AVCodecParserContext *s,
if (s->flags & PARSER_FLAG_ONCE) {
s->flags &= PARSER_FLAG_COMPLETE_FRAMES;
}
+ }
*poutbuf = buf;
*poutbuf_size = buf_size;
diff --git a/libavcodec/h264_ps.c b/libavcodec/h264_ps.c
index 7491807460..a7de122c53 100644
--- a/libavcodec/h264_ps.c
+++ b/libavcodec/h264_ps.c
@@ -2,20 +2,20 @@
* H.26L/H.264/AVC/JVT/14496-10/... parameter set decoding
* Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -70,7 +70,7 @@ static const AVRational pixel_aspect[17]={
QP(37,d), QP(37,d), QP(37,d), QP(38,d), QP(38,d), QP(38,d),\
QP(39,d), QP(39,d), QP(39,d), QP(39,d)
-const uint8_t ff_h264_chroma_qp[3][QP_MAX_NUM+1] = {
+const uint8_t ff_h264_chroma_qp[5][QP_MAX_NUM+1] = {
{
CHROMA_QP_TABLE_END(8)
},
@@ -83,6 +83,19 @@ const uint8_t ff_h264_chroma_qp[3][QP_MAX_NUM+1] = {
6, 7, 8, 9, 10, 11,
CHROMA_QP_TABLE_END(10)
},
+ {
+ 0, 1, 2, 3, 4, 5,
+ 6, 7, 8, 9, 10, 11,
+ 12,13,14,15, 16, 17,
+ CHROMA_QP_TABLE_END(11)
+ },
+ {
+ 0, 1, 2, 3, 4, 5,
+ 6, 7, 8, 9, 10, 11,
+ 12,13,14,15, 16, 17,
+ 18,19,20,21, 22, 23,
+ CHROMA_QP_TABLE_END(12)
+ },
};
static const uint8_t default_scaling4[2][16]={
@@ -130,8 +143,8 @@ static inline int decode_hrd_parameters(H264Context *h, SPS *sps){
get_bits(&s->gb, 4); /* bit_rate_scale */
get_bits(&s->gb, 4); /* cpb_size_scale */
for(i=0; i<cpb_count; i++){
- get_ue_golomb(&s->gb); /* bit_rate_value_minus1 */
- get_ue_golomb(&s->gb); /* cpb_size_value_minus1 */
+ get_ue_golomb_long(&s->gb); /* bit_rate_value_minus1 */
+ get_ue_golomb_long(&s->gb); /* cpb_size_value_minus1 */
get_bits1(&s->gb); /* cbr_flag */
}
sps->initial_cpb_removal_delay_length = get_bits(&s->gb, 5) + 1;
@@ -228,7 +241,6 @@ static inline int decode_vui_parameters(H264Context *h, SPS *sps){
get_ue_golomb(&s->gb); /*max_dec_frame_buffering*/
if(s->gb.size_in_bits < get_bits_count(&s->gb)){
- av_log(h->s.avctx, AV_LOG_ERROR, "Overread VUI by %d bits\n", get_bits_count(&s->gb) - s->gb.size_in_bits);
sps->num_reorder_frames=0;
sps->bitstream_restriction_flag= 0;
}
@@ -238,6 +250,10 @@ static inline int decode_vui_parameters(H264Context *h, SPS *sps){
return -1;
}
}
+ if(s->gb.size_in_bits < get_bits_count(&s->gb)){
+ av_log(h->s.avctx, AV_LOG_ERROR, "Overread VUI by %d bits\n", get_bits_count(&s->gb) - s->gb.size_in_bits);
+ return -1;
+ }
return 0;
}
@@ -322,10 +338,12 @@ int ff_h264_decode_seq_parameter_set(H264Context *h){
sps->profile_idc= profile_idc;
sps->constraint_set_flags = constraint_set_flags;
sps->level_idc= level_idc;
+ sps->full_range = -1;
memset(sps->scaling_matrix4, 16, sizeof(sps->scaling_matrix4));
memset(sps->scaling_matrix8, 16, sizeof(sps->scaling_matrix8));
sps->scaling_matrix_present = 0;
+ sps->colorspace = 2; //AVCOL_SPC_UNSPECIFIED
if(sps->profile_idc >= 100){ //high profile
sps->chroma_format_idc= get_ue_golomb_31(&s->gb);
@@ -333,6 +351,11 @@ int ff_h264_decode_seq_parameter_set(H264Context *h){
sps->residual_color_transform_flag = get_bits1(&s->gb);
sps->bit_depth_luma = get_ue_golomb(&s->gb) + 8;
sps->bit_depth_chroma = get_ue_golomb(&s->gb) + 8;
+ if (sps->bit_depth_luma > 12U || sps->bit_depth_chroma > 12U) {
+ av_log(h->s.avctx, AV_LOG_ERROR, "illegal bit depth value (%d, %d)\n",
+ sps->bit_depth_luma, sps->bit_depth_chroma);
+ goto fail;
+ }
sps->transform_bypass = get_bits1(&s->gb);
decode_scaling_matrices(h, sps, NULL, 1, sps->scaling_matrix4, sps->scaling_matrix8);
}else{
@@ -365,7 +388,7 @@ int ff_h264_decode_seq_parameter_set(H264Context *h){
}
sps->ref_frame_count= get_ue_golomb_31(&s->gb);
- if(sps->ref_frame_count > MAX_PICTURE_COUNT-2 || sps->ref_frame_count >= 32U){
+ if(sps->ref_frame_count > MAX_PICTURE_COUNT-2 || sps->ref_frame_count > 16U){
av_log(h->s.avctx, AV_LOG_ERROR, "too many reference frames\n");
goto fail;
}
@@ -385,10 +408,6 @@ int ff_h264_decode_seq_parameter_set(H264Context *h){
sps->mb_aff= 0;
sps->direct_8x8_inference_flag= get_bits1(&s->gb);
- if(!sps->frame_mbs_only_flag && !sps->direct_8x8_inference_flag){
- av_log(h->s.avctx, AV_LOG_ERROR, "This stream was generated by a broken encoder, invalid 8x8 inference\n");
- goto fail;
- }
#ifndef ALLOW_INTERLACE
if(sps->mb_aff)
@@ -396,16 +415,24 @@ int ff_h264_decode_seq_parameter_set(H264Context *h){
#endif
sps->crop= get_bits1(&s->gb);
if(sps->crop){
- int crop_limit = sps->chroma_format_idc == 3 ? 16 : 8;
+ int crop_vertical_limit = sps->chroma_format_idc & 2 ? 16 : 8;
+ int crop_horizontal_limit = sps->chroma_format_idc == 3 ? 16 : 8;
sps->crop_left = get_ue_golomb(&s->gb);
sps->crop_right = get_ue_golomb(&s->gb);
sps->crop_top = get_ue_golomb(&s->gb);
sps->crop_bottom= get_ue_golomb(&s->gb);
if(sps->crop_left || sps->crop_top){
- av_log(h->s.avctx, AV_LOG_ERROR, "insane cropping not completely supported, this could look slightly wrong ...\n");
+ av_log(h->s.avctx, AV_LOG_ERROR, "insane cropping not completely supported, this could look slightly wrong ... (left: %d, top: %d)\n", sps->crop_left, sps->crop_top);
}
- if(sps->crop_right >= crop_limit || sps->crop_bottom >= crop_limit){
- av_log(h->s.avctx, AV_LOG_ERROR, "brainfart cropping not supported, this could look slightly wrong ...\n");
+ if(sps->crop_right >= crop_horizontal_limit || sps->crop_bottom >= crop_vertical_limit){
+ av_log(h->s.avctx, AV_LOG_ERROR, "brainfart cropping not supported, cropping disabled (right: %d, bottom: %d)\n", sps->crop_right, sps->crop_bottom);
+ /* It is very unlikely that partial cropping will make anybody happy.
+ * Not cropping at all fixes for example playback of Sisvel 3D streams
+ * in applications supporting Sisvel 3D. */
+ sps->crop_left =
+ sps->crop_right =
+ sps->crop_top =
+ sps->crop_bottom= 0;
}
}else{
sps->crop_left =
@@ -423,7 +450,7 @@ int ff_h264_decode_seq_parameter_set(H264Context *h){
sps->sar.den= 1;
if(s->avctx->debug&FF_DEBUG_PICT_INFO){
- av_log(h->s.avctx, AV_LOG_DEBUG, "sps:%u profile:%d/%d poc:%d ref:%d %dx%d %s %s crop:%d/%d/%d/%d %s %s %d/%d\n",
+ av_log(h->s.avctx, AV_LOG_DEBUG, "sps:%u profile:%d/%d poc:%d ref:%d %dx%d %s %s crop:%d/%d/%d/%d %s %s %d/%d b%d\n",
sps_id, sps->profile_idc, sps->level_idc,
sps->poc_type,
sps->ref_frame_count,
@@ -435,7 +462,8 @@ int ff_h264_decode_seq_parameter_set(H264Context *h){
sps->vui_parameters_present_flag ? "VUI" : "",
((const char*[]){"Gray","420","422","444"})[sps->chroma_format_idc],
sps->timing_info_present_flag ? sps->num_units_in_tick : 0,
- sps->timing_info_present_flag ? sps->time_scale : 0
+ sps->timing_info_present_flag ? sps->time_scale : 0,
+ sps->bit_depth_luma
);
}
@@ -462,6 +490,7 @@ int ff_h264_decode_picture_parameter_set(H264Context *h, int bit_length){
unsigned int pps_id= get_ue_golomb(&s->gb);
PPS *pps;
const int qp_bd_offset = 6*(h->sps.bit_depth_luma-8);
+ int bits_left;
if(pps_id >= MAX_PPS_COUNT) {
av_log(h->s.avctx, AV_LOG_ERROR, "pps_id (%d) out of range\n", pps_id);
@@ -538,6 +567,7 @@ int ff_h264_decode_picture_parameter_set(H264Context *h, int bit_length){
memcpy(pps->scaling_matrix4, h->sps_buffers[pps->sps_id]->scaling_matrix4, sizeof(pps->scaling_matrix4));
memcpy(pps->scaling_matrix8, h->sps_buffers[pps->sps_id]->scaling_matrix8, sizeof(pps->scaling_matrix8));
+ bits_left = bit_length - get_bits_count(&s->gb);
if(get_bits_count(&s->gb) < bit_length){
pps->transform_8x8_mode= get_bits1(&s->gb);
decode_scaling_matrices(h, h->sps_buffers[pps->sps_id], pps, 0, pps->scaling_matrix4, pps->scaling_matrix8);
diff --git a/libavcodec/h264_refs.c b/libavcodec/h264_refs.c
index a025f7d352..0e00c4f94b 100644
--- a/libavcodec/h264_refs.c
+++ b/libavcodec/h264_refs.c
@@ -2,20 +2,20 @@
* H.26L/H.264/AVC/JVT/14496-10/... reference picture handling
* Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -25,6 +25,7 @@
* @author Michael Niedermayer <michaelni@gmx.at>
*/
+#include "libavutil/avassert.h"
#include "internal.h"
#include "dsputil.h"
#include "avcodec.h"
@@ -39,16 +40,16 @@ static void pic_as_field(Picture *pic, const int parity){
int i;
for (i = 0; i < 4; ++i) {
if (parity == PICT_BOTTOM_FIELD)
- pic->data[i] += pic->linesize[i];
- pic->reference = parity;
- pic->linesize[i] *= 2;
+ pic->f.data[i] += pic->f.linesize[i];
+ pic->f.reference = parity;
+ pic->f.linesize[i] *= 2;
}
pic->poc= pic->field_poc[parity == PICT_BOTTOM_FIELD];
}
static int split_field_copy(Picture *dest, Picture *src,
int parity, int id_add){
- int match = !!(src->reference & parity);
+ int match = !!(src->f.reference & parity);
if (match) {
*dest = *src;
@@ -67,9 +68,9 @@ static int build_def_list(Picture *def, Picture **in, int len, int is_long, int
int index=0;
while(i[0]<len || i[1]<len){
- while(i[0]<len && !(in[ i[0] ] && (in[ i[0] ]->reference & sel)))
+ while (i[0] < len && !(in[ i[0] ] && (in[ i[0] ]->f.reference & sel)))
i[0]++;
- while(i[1]<len && !(in[ i[1] ] && (in[ i[1] ]->reference & (sel^3))))
+ while (i[1] < len && !(in[ i[1] ] && (in[ i[1] ]->f.reference & (sel^3))))
i[1]++;
if(i[0] < len){
in[ i[0] ]->pic_id= is_long ? i[0] : in[ i[0] ]->frame_num;
@@ -133,7 +134,7 @@ int ff_h264_fill_default_ref_list(H264Context *h){
}
if(lens[0] == lens[1] && lens[1] > 1){
- for(i=0; h->default_ref_list[0][i].data[0] == h->default_ref_list[1][i].data[0] && i<lens[0]; i++);
+ for (i = 0; h->default_ref_list[0][i].f.data[0] == h->default_ref_list[1][i].f.data[0] && i < lens[0]; i++);
if(i == lens[0])
FFSWAP(Picture, h->default_ref_list[1][0], h->default_ref_list[1][1]);
}
@@ -229,11 +230,11 @@ int ff_h264_decode_ref_pic_list_reordering(H264Context *h){
for(i= h->short_ref_count-1; i>=0; i--){
ref = h->short_ref[i];
- assert(ref->reference);
+ assert(ref->f.reference);
assert(!ref->long_ref);
if(
ref->frame_num == frame_num &&
- (ref->reference & pic_structure)
+ (ref->f.reference & pic_structure)
)
break;
}
@@ -250,8 +251,8 @@ int ff_h264_decode_ref_pic_list_reordering(H264Context *h){
return -1;
}
ref = h->long_ref[long_idx];
- assert(!(ref && !ref->reference));
- if(ref && (ref->reference & pic_structure)){
+ assert(!(ref && !ref->f.reference));
+ if (ref && (ref->f.reference & pic_structure)) {
ref->pic_id= pic_id;
assert(ref->long_ref);
i=0;
@@ -285,9 +286,9 @@ int ff_h264_decode_ref_pic_list_reordering(H264Context *h){
}
for(list=0; list<h->list_count; list++){
for(index= 0; index < h->ref_count[list]; index++){
- if(!h->ref_list[list][index].data[0]){
+ if (!h->ref_list[list][index].f.data[0]) {
av_log(h->s.avctx, AV_LOG_ERROR, "Missing reference picture\n");
- if(h->default_ref_list[list][0].data[0])
+ if (h->default_ref_list[list][0].f.data[0])
h->ref_list[list][index]= h->default_ref_list[list][0];
else
return -1;
@@ -300,19 +301,19 @@ int ff_h264_decode_ref_pic_list_reordering(H264Context *h){
void ff_h264_fill_mbaff_ref_list(H264Context *h){
int list, i, j;
- for(list=0; list<2; list++){ //FIXME try list_count
+ for(list=0; list<h->list_count; list++){
for(i=0; i<h->ref_count[list]; i++){
Picture *frame = &h->ref_list[list][i];
Picture *field = &h->ref_list[list][16+2*i];
field[0] = *frame;
for(j=0; j<3; j++)
- field[0].linesize[j] <<= 1;
- field[0].reference = PICT_TOP_FIELD;
+ field[0].f.linesize[j] <<= 1;
+ field[0].f.reference = PICT_TOP_FIELD;
field[0].poc= field[0].field_poc[0];
field[1] = field[0];
for(j=0; j<3; j++)
- field[1].data[j] += frame->linesize[j];
- field[1].reference = PICT_BOTTOM_FIELD;
+ field[1].f.data[j] += frame->f.linesize[j];
+ field[1].f.reference = PICT_BOTTOM_FIELD;
field[1].poc= field[1].field_poc[1];
h->luma_weight[16+2*i][list][0] = h->luma_weight[16+2*i+1][list][0] = h->luma_weight[i][list][0];
@@ -338,12 +339,12 @@ void ff_h264_fill_mbaff_ref_list(H264Context *h){
*/
static inline int unreference_pic(H264Context *h, Picture *pic, int refmask){
int i;
- if (pic->reference &= refmask) {
+ if (pic->f.reference &= refmask) {
return 0;
} else {
for(i = 0; h->delayed_pic[i]; i++)
if(pic == h->delayed_pic[i]){
- pic->reference=DELAYED_PIC_REF;
+ pic->f.reference = DELAYED_PIC_REF;
break;
}
return 1;
@@ -453,7 +454,8 @@ static void print_short_term(H264Context *h) {
av_log(h->s.avctx, AV_LOG_DEBUG, "short term list:\n");
for(i=0; i<h->short_ref_count; i++){
Picture *pic= h->short_ref[i];
- av_log(h->s.avctx, AV_LOG_DEBUG, "%d fn:%d poc:%d %p\n", i, pic->frame_num, pic->poc, pic->data[0]);
+ av_log(h->s.avctx, AV_LOG_DEBUG, "%d fn:%d poc:%d %p\n",
+ i, pic->frame_num, pic->poc, pic->f.data[0]);
}
}
}
@@ -468,7 +470,8 @@ static void print_long_term(H264Context *h) {
for(i = 0; i < 16; i++){
Picture *pic= h->long_ref[i];
if (pic) {
- av_log(h->s.avctx, AV_LOG_DEBUG, "%d fn:%d poc:%d %p\n", i, pic->frame_num, pic->poc, pic->data[0]);
+ av_log(h->s.avctx, AV_LOG_DEBUG, "%d fn:%d poc:%d %p\n",
+ i, pic->frame_num, pic->poc, pic->f.data[0]);
}
}
}
@@ -476,11 +479,10 @@ static void print_long_term(H264Context *h) {
void ff_generate_sliding_window_mmcos(H264Context *h) {
MpegEncContext * const s = &h->s;
- assert(h->long_ref_count + h->short_ref_count <= h->sps.ref_frame_count);
h->mmco_index= 0;
- if(h->short_ref_count && h->long_ref_count + h->short_ref_count == h->sps.ref_frame_count &&
- !(FIELD_PICTURE && !s->first_field && s->current_picture_ptr->reference)) {
+ if(h->short_ref_count && h->long_ref_count + h->short_ref_count >= h->sps.ref_frame_count &&
+ !(FIELD_PICTURE && !s->first_field && s->current_picture_ptr->f.reference)) {
h->mmco[0].opcode= MMCO_SHORT2UNUSED;
h->mmco[0].short_pic_num= h->short_ref[ h->short_ref_count - 1 ]->frame_num;
h->mmco_index= 1;
@@ -496,7 +498,7 @@ void ff_generate_sliding_window_mmcos(H264Context *h) {
int ff_h264_execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count){
MpegEncContext * const s = &h->s;
int i, av_uninit(j);
- int current_ref_assigned=0;
+ int current_ref_assigned=0, err=0;
Picture *av_uninit(pic);
if((s->avctx->debug&FF_DEBUG_MMCO) && mmco_count==0)
@@ -513,8 +515,10 @@ int ff_h264_execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count){
pic = find_short(h, frame_num, &j);
if(!pic){
if(mmco[i].opcode != MMCO_SHORT2LONG || !h->long_ref[mmco[i].long_arg]
- || h->long_ref[mmco[i].long_arg]->frame_num != frame_num)
- av_log(h->s.avctx, AV_LOG_ERROR, "mmco: unref short failure\n");
+ || h->long_ref[mmco[i].long_arg]->frame_num != frame_num) {
+ av_log(h->s.avctx, AV_LOG_ERROR, "mmco: unref short failure\n");
+ err = AVERROR_INVALIDDATA;
+ }
continue;
}
}
@@ -561,7 +565,7 @@ int ff_h264_execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count){
h->long_ref_count++;
}
- s->current_picture_ptr->reference |= s->picture_structure;
+ s->current_picture_ptr->f.reference |= s->picture_structure;
current_ref_assigned=1;
break;
case MMCO_SET_MAX_LONG:
@@ -600,16 +604,18 @@ int ff_h264_execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count){
*/
if (h->short_ref_count && h->short_ref[0] == s->current_picture_ptr) {
/* Just mark the second field valid */
- s->current_picture_ptr->reference = PICT_FRAME;
+ s->current_picture_ptr->f.reference = PICT_FRAME;
} else if (s->current_picture_ptr->long_ref) {
av_log(h->s.avctx, AV_LOG_ERROR, "illegal short term reference "
"assignment for second field "
"in complementary field pair "
"(first field is long term)\n");
+ err = AVERROR_INVALIDDATA;
} else {
pic= remove_short(h, s->current_picture_ptr->frame_num, 0);
if(pic){
av_log(h->s.avctx, AV_LOG_ERROR, "illegal short term buffer state detected\n");
+ err = AVERROR_INVALIDDATA;
}
if(h->short_ref_count)
@@ -617,12 +623,11 @@ int ff_h264_execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count){
h->short_ref[0]= s->current_picture_ptr;
h->short_ref_count++;
- s->current_picture_ptr->reference |= s->picture_structure;
+ s->current_picture_ptr->f.reference |= s->picture_structure;
}
}
- if (h->long_ref_count + h->short_ref_count -
- (h->short_ref[0] == s->current_picture_ptr) > h->sps.ref_frame_count){
+ if (h->long_ref_count + h->short_ref_count > FFMAX(h->sps.ref_frame_count, 1)){
/* We have too many reference frames, probably due to corrupted
* stream. Need to discard one frame. Prevents overrun of the
@@ -632,6 +637,7 @@ int ff_h264_execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count){
"number of reference frames (%d+%d) exceeds max (%d; probably "
"corrupt input), discarding one\n",
h->long_ref_count, h->short_ref_count, h->sps.ref_frame_count);
+ err = AVERROR_INVALIDDATA;
if (h->long_ref_count && !h->short_ref_count) {
for (i = 0; i < 16; ++i)
@@ -648,7 +654,7 @@ int ff_h264_execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count){
print_short_term(h);
print_long_term(h);
- return 0;
+ return h->s.avctx->error_recognition >= FF_ER_EXPLODE ? err : 0;
}
int ff_h264_decode_ref_pic_marking(H264Context *h, GetBitContext *gb){
@@ -678,7 +684,7 @@ int ff_h264_decode_ref_pic_marking(H264Context *h, GetBitContext *gb){
}
if(opcode==MMCO_SHORT2LONG || opcode==MMCO_LONG2UNUSED || opcode==MMCO_LONG || opcode==MMCO_SET_MAX_LONG){
unsigned int long_arg= get_ue_golomb_31(gb);
- if(long_arg >= 32 || (long_arg >= 16 && !(opcode == MMCO_LONG2UNUSED && FIELD_PICTURE))){
+ if(long_arg >= 32 || (long_arg >= 16 && !(opcode == MMCO_SET_MAX_LONG && long_arg == 16) && !(opcode == MMCO_LONG2UNUSED && FIELD_PICTURE))){
av_log(h->s.avctx, AV_LOG_ERROR, "illegal long ref in memory management control operation %d\n", opcode);
return -1;
}
diff --git a/libavcodec/h264_sei.c b/libavcodec/h264_sei.c
index 4f52bbe969..374e53dfcf 100644
--- a/libavcodec/h264_sei.c
+++ b/libavcodec/h264_sei.c
@@ -2,20 +2,20 @@
* H.26L/H.264/AVC/JVT/14496-10/... sei decoding
* Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -177,6 +177,9 @@ int ff_h264_decode_sei(H264Context *h){
size+= show_bits(&s->gb, 8);
}while(get_bits(&s->gb, 8) == 255);
+ if(s->avctx->debug&FF_DEBUG_STARTCODE)
+ av_log(h->s.avctx, AV_LOG_DEBUG, "SEI %d len:%d\n", type, size);
+
switch(type){
case SEI_TYPE_PIC_TIMING: // Picture timing SEI
if(decode_picture_timing(h) < 0)
diff --git a/libavcodec/h264data.h b/libavcodec/h264data.h
index 1851169dd3..a5ed069e94 100644
--- a/libavcodec/h264data.h
+++ b/libavcodec/h264data.h
@@ -2,20 +2,20 @@
* H26L/H264/AVC/JVT/14496-10/... encoder/decoder
* Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -80,7 +80,14 @@ static const uint8_t luma_dc_field_scan[16]={
static const uint8_t chroma_dc_scan[4]={
(0+0*2)*16, (1+0*2)*16,
- (0+1*2)*16, (1+1*2)*16, //FIXME
+ (0+1*2)*16, (1+1*2)*16,
+};
+
+static const uint8_t chroma422_dc_scan[8]={
+ (0+0*2)*16, (0+1*2)*16,
+ (1+0*2)*16, (0+2*2)*16,
+ (0+3*2)*16, (1+1*2)*16,
+ (1+2*2)*16, (1+3*2)*16,
};
// zigzag_scan8x8_cavlc[i] = zigzag_scan8x8[(i/4) + 16*(i%4)]
diff --git a/libavcodec/h264dsp.c b/libavcodec/h264dsp.c
index 64f4856189..bd35aa3065 100644
--- a/libavcodec/h264dsp.c
+++ b/libavcodec/h264dsp.c
@@ -2,20 +2,20 @@
* H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder
* Copyright (c) 2003-2010 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -41,7 +41,7 @@
#include "h264dsp_template.c"
#undef BIT_DEPTH
-void ff_h264dsp_init(H264DSPContext *c, const int bit_depth)
+void ff_h264dsp_init(H264DSPContext *c, const int bit_depth, const int chroma_format_idc)
{
#undef FUNC
#define FUNC(a, depth) a ## _ ## depth ## _c
@@ -53,31 +53,25 @@ void ff_h264dsp_init(H264DSPContext *c, const int bit_depth)
c->h264_idct8_dc_add= FUNC(ff_h264_idct8_dc_add, depth);\
c->h264_idct_add16 = FUNC(ff_h264_idct_add16, depth);\
c->h264_idct8_add4 = FUNC(ff_h264_idct8_add4, depth);\
- c->h264_idct_add8 = FUNC(ff_h264_idct_add8, depth);\
+ if (chroma_format_idc == 1)\
+ c->h264_idct_add8 = FUNC(ff_h264_idct_add8, depth);\
+ else\
+ c->h264_idct_add8 = FUNC(ff_h264_idct_add8_422, depth);\
c->h264_idct_add16intra= FUNC(ff_h264_idct_add16intra, depth);\
c->h264_luma_dc_dequant_idct= FUNC(ff_h264_luma_dc_dequant_idct, depth);\
- c->h264_chroma_dc_dequant_idct= FUNC(ff_h264_chroma_dc_dequant_idct, depth);\
+ if (chroma_format_idc == 1)\
+ c->h264_chroma_dc_dequant_idct= FUNC(ff_h264_chroma_dc_dequant_idct, depth);\
+ else\
+ c->h264_chroma_dc_dequant_idct= FUNC(ff_h264_chroma422_dc_dequant_idct, depth);\
\
- c->weight_h264_pixels_tab[0]= FUNC(weight_h264_pixels16x16, depth);\
- c->weight_h264_pixels_tab[1]= FUNC(weight_h264_pixels16x8, depth);\
- c->weight_h264_pixels_tab[2]= FUNC(weight_h264_pixels8x16, depth);\
- c->weight_h264_pixels_tab[3]= FUNC(weight_h264_pixels8x8, depth);\
- c->weight_h264_pixels_tab[4]= FUNC(weight_h264_pixels8x4, depth);\
- c->weight_h264_pixels_tab[5]= FUNC(weight_h264_pixels4x8, depth);\
- c->weight_h264_pixels_tab[6]= FUNC(weight_h264_pixels4x4, depth);\
- c->weight_h264_pixels_tab[7]= FUNC(weight_h264_pixels4x2, depth);\
- c->weight_h264_pixels_tab[8]= FUNC(weight_h264_pixels2x4, depth);\
- c->weight_h264_pixels_tab[9]= FUNC(weight_h264_pixels2x2, depth);\
- c->biweight_h264_pixels_tab[0]= FUNC(biweight_h264_pixels16x16, depth);\
- c->biweight_h264_pixels_tab[1]= FUNC(biweight_h264_pixels16x8, depth);\
- c->biweight_h264_pixels_tab[2]= FUNC(biweight_h264_pixels8x16, depth);\
- c->biweight_h264_pixels_tab[3]= FUNC(biweight_h264_pixels8x8, depth);\
- c->biweight_h264_pixels_tab[4]= FUNC(biweight_h264_pixels8x4, depth);\
- c->biweight_h264_pixels_tab[5]= FUNC(biweight_h264_pixels4x8, depth);\
- c->biweight_h264_pixels_tab[6]= FUNC(biweight_h264_pixels4x4, depth);\
- c->biweight_h264_pixels_tab[7]= FUNC(biweight_h264_pixels4x2, depth);\
- c->biweight_h264_pixels_tab[8]= FUNC(biweight_h264_pixels2x4, depth);\
- c->biweight_h264_pixels_tab[9]= FUNC(biweight_h264_pixels2x2, depth);\
+ c->weight_h264_pixels_tab[0]= FUNC(weight_h264_pixels16, depth);\
+ c->weight_h264_pixels_tab[1]= FUNC(weight_h264_pixels8, depth);\
+ c->weight_h264_pixels_tab[2]= FUNC(weight_h264_pixels4, depth);\
+ c->weight_h264_pixels_tab[3]= FUNC(weight_h264_pixels2, depth);\
+ c->biweight_h264_pixels_tab[0]= FUNC(biweight_h264_pixels16, depth);\
+ c->biweight_h264_pixels_tab[1]= FUNC(biweight_h264_pixels8, depth);\
+ c->biweight_h264_pixels_tab[2]= FUNC(biweight_h264_pixels4, depth);\
+ c->biweight_h264_pixels_tab[3]= FUNC(biweight_h264_pixels2, depth);\
\
c->h264_v_loop_filter_luma= FUNC(h264_v_loop_filter_luma, depth);\
c->h264_h_loop_filter_luma= FUNC(h264_h_loop_filter_luma, depth);\
@@ -86,11 +80,23 @@ void ff_h264dsp_init(H264DSPContext *c, const int bit_depth)
c->h264_h_loop_filter_luma_intra= FUNC(h264_h_loop_filter_luma_intra, depth);\
c->h264_h_loop_filter_luma_mbaff_intra= FUNC(h264_h_loop_filter_luma_mbaff_intra, depth);\
c->h264_v_loop_filter_chroma= FUNC(h264_v_loop_filter_chroma, depth);\
- c->h264_h_loop_filter_chroma= FUNC(h264_h_loop_filter_chroma, depth);\
- c->h264_h_loop_filter_chroma_mbaff= FUNC(h264_h_loop_filter_chroma_mbaff, depth);\
+ if (chroma_format_idc == 1)\
+ c->h264_h_loop_filter_chroma= FUNC(h264_h_loop_filter_chroma, depth);\
+ else\
+ c->h264_h_loop_filter_chroma= FUNC(h264_h_loop_filter_chroma422, depth);\
+ if (chroma_format_idc == 1)\
+ c->h264_h_loop_filter_chroma_mbaff= FUNC(h264_h_loop_filter_chroma_mbaff, depth);\
+ else\
+ c->h264_h_loop_filter_chroma_mbaff= FUNC(h264_h_loop_filter_chroma422_mbaff, depth);\
c->h264_v_loop_filter_chroma_intra= FUNC(h264_v_loop_filter_chroma_intra, depth);\
- c->h264_h_loop_filter_chroma_intra= FUNC(h264_h_loop_filter_chroma_intra, depth);\
- c->h264_h_loop_filter_chroma_mbaff_intra= FUNC(h264_h_loop_filter_chroma_mbaff_intra, depth);\
+ if (chroma_format_idc == 1)\
+ c->h264_h_loop_filter_chroma_intra= FUNC(h264_h_loop_filter_chroma_intra, depth);\
+ else\
+ c->h264_h_loop_filter_chroma_intra= FUNC(h264_h_loop_filter_chroma422_intra, depth);\
+ if (chroma_format_idc == 1)\
+ c->h264_h_loop_filter_chroma_mbaff_intra= FUNC(h264_h_loop_filter_chroma_mbaff_intra, depth);\
+ else\
+ c->h264_h_loop_filter_chroma_mbaff_intra= FUNC(h264_h_loop_filter_chroma422_mbaff_intra, depth);\
c->h264_loop_filter_strength= NULL;
switch (bit_depth) {
@@ -105,7 +111,7 @@ void ff_h264dsp_init(H264DSPContext *c, const int bit_depth)
break;
}
- if (ARCH_ARM) ff_h264dsp_init_arm(c, bit_depth);
- if (HAVE_ALTIVEC) ff_h264dsp_init_ppc(c, bit_depth);
- if (HAVE_MMX) ff_h264dsp_init_x86(c, bit_depth);
+ if (ARCH_ARM) ff_h264dsp_init_arm(c, bit_depth, chroma_format_idc);
+ if (HAVE_ALTIVEC) ff_h264dsp_init_ppc(c, bit_depth, chroma_format_idc);
+ if (HAVE_MMX) ff_h264dsp_init_x86(c, bit_depth, chroma_format_idc);
}
diff --git a/libavcodec/h264dsp.h b/libavcodec/h264dsp.h
index 6972725781..490a936310 100644
--- a/libavcodec/h264dsp.h
+++ b/libavcodec/h264dsp.h
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2003-2010 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -31,16 +31,18 @@
#include "dsputil.h"
//typedef void (*h264_chroma_mc_func)(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int srcStride, int h, int x, int y);
-typedef void (*h264_weight_func)(uint8_t *block, int stride, int log2_denom, int weight, int offset);
-typedef void (*h264_biweight_func)(uint8_t *dst, uint8_t *src, int stride, int log2_denom, int weightd, int weights, int offset);
+typedef void (*h264_weight_func)(uint8_t *block, int stride, int height,
+ int log2_denom, int weight, int offset);
+typedef void (*h264_biweight_func)(uint8_t *dst, uint8_t *src, int stride, int height,
+ int log2_denom, int weightd, int weights, int offset);
/**
* Context for storing H.264 DSP functions
*/
typedef struct H264DSPContext{
/* weighted MC */
- h264_weight_func weight_h264_pixels_tab[10];
- h264_biweight_func biweight_h264_pixels_tab[10];
+ h264_weight_func weight_h264_pixels_tab[4];
+ h264_biweight_func biweight_h264_pixels_tab[4];
/* loop filter */
void (*h264_v_loop_filter_luma)(uint8_t *pix/*align 16*/, int stride, int alpha, int beta, int8_t *tc0);
@@ -74,9 +76,9 @@ typedef struct H264DSPContext{
void (*h264_chroma_dc_dequant_idct)(DCTELEM *block, int qmul);
}H264DSPContext;
-void ff_h264dsp_init(H264DSPContext *c, const int bit_depth);
-void ff_h264dsp_init_arm(H264DSPContext *c, const int bit_depth);
-void ff_h264dsp_init_ppc(H264DSPContext *c, const int bit_depth);
-void ff_h264dsp_init_x86(H264DSPContext *c, const int bit_depth);
+void ff_h264dsp_init(H264DSPContext *c, const int bit_depth, const int chroma_format_idc);
+void ff_h264dsp_init_arm(H264DSPContext *c, const int bit_depth, const int chroma_format_idc);
+void ff_h264dsp_init_ppc(H264DSPContext *c, const int bit_depth, const int chroma_format_idc);
+void ff_h264dsp_init_x86(H264DSPContext *c, const int bit_depth, const int chroma_format_idc);
#endif /* AVCODEC_H264DSP_H */
diff --git a/libavcodec/h264dsp_template.c b/libavcodec/h264dsp_template.c
index d11eff0919..4d5faf01c0 100644
--- a/libavcodec/h264dsp_template.c
+++ b/libavcodec/h264dsp_template.c
@@ -1,21 +1,21 @@
/*
* H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder
- * Copyright (c) 2003-2010 Michael Niedermayer <michaelni@gmx.at>
+ * Copyright (c) 2003-2011 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -29,14 +29,16 @@
#define op_scale1(x) block[x] = av_clip_pixel( (block[x]*weight + offset) >> log2_denom )
#define op_scale2(x) dst[x] = av_clip_pixel( (src[x]*weights + dst[x]*weightd + offset) >> (log2_denom+1))
-#define H264_WEIGHT(W,H) \
-static void FUNCC(weight_h264_pixels ## W ## x ## H)(uint8_t *_block, int stride, int log2_denom, int weight, int offset){ \
+#define H264_WEIGHT(W) \
+static void FUNCC(weight_h264_pixels ## W)(uint8_t *_block, int stride, int height, \
+ int log2_denom, int weight, int offset) \
+{ \
int y; \
pixel *block = (pixel*)_block; \
- stride /= sizeof(pixel); \
+ stride >>= sizeof(pixel)-1; \
offset <<= (log2_denom + (BIT_DEPTH-8)); \
if(log2_denom) offset += 1<<(log2_denom-1); \
- for(y=0; y<H; y++, block += stride){ \
+ for (y = 0; y < height; y++, block += stride) { \
op_scale1(0); \
op_scale1(1); \
if(W==2) continue; \
@@ -58,14 +60,16 @@ static void FUNCC(weight_h264_pixels ## W ## x ## H)(uint8_t *_block, int stride
op_scale1(15); \
} \
} \
-static void FUNCC(biweight_h264_pixels ## W ## x ## H)(uint8_t *_dst, uint8_t *_src, int stride, int log2_denom, int weightd, int weights, int offset){ \
+static void FUNCC(biweight_h264_pixels ## W)(uint8_t *_dst, uint8_t *_src, int stride, int height, \
+ int log2_denom, int weightd, int weights, int offset) \
+{ \
int y; \
pixel *dst = (pixel*)_dst; \
pixel *src = (pixel*)_src; \
- stride /= sizeof(pixel); \
+ stride >>= sizeof(pixel)-1; \
offset <<= (BIT_DEPTH-8); \
offset = ((offset + 1) | 1) << log2_denom; \
- for(y=0; y<H; y++, dst += stride, src += stride){ \
+ for (y = 0; y < height; y++, dst += stride, src += stride) { \
op_scale2(0); \
op_scale2(1); \
if(W==2) continue; \
@@ -88,27 +92,21 @@ static void FUNCC(biweight_h264_pixels ## W ## x ## H)(uint8_t *_dst, uint8_t *_
} \
}
-H264_WEIGHT(16,16)
-H264_WEIGHT(16,8)
-H264_WEIGHT(8,16)
-H264_WEIGHT(8,8)
-H264_WEIGHT(8,4)
-H264_WEIGHT(4,8)
-H264_WEIGHT(4,4)
-H264_WEIGHT(4,2)
-H264_WEIGHT(2,4)
-H264_WEIGHT(2,2)
+H264_WEIGHT(16)
+H264_WEIGHT(8)
+H264_WEIGHT(4)
+H264_WEIGHT(2)
#undef op_scale1
#undef op_scale2
#undef H264_WEIGHT
-static av_always_inline av_flatten void FUNCC(h264_loop_filter_luma)(uint8_t *_pix, int xstride, int ystride, int inner_iters, int alpha, int beta, int8_t *tc0)
+static av_always_inline av_flatten void FUNCC(h264_loop_filter_luma)(uint8_t *p_pix, int xstride, int ystride, int inner_iters, int alpha, int beta, int8_t *tc0)
{
- pixel *pix = (pixel*)_pix;
+ pixel *pix = (pixel*)p_pix;
int i, d;
- xstride /= sizeof(pixel);
- ystride /= sizeof(pixel);
+ xstride >>= sizeof(pixel)-1;
+ ystride >>= sizeof(pixel)-1;
alpha <<= BIT_DEPTH - 8;
beta <<= BIT_DEPTH - 8;
for( i = 0; i < 4; i++ ) {
@@ -164,12 +162,12 @@ static void FUNCC(h264_h_loop_filter_luma_mbaff)(uint8_t *pix, int stride, int a
FUNCC(h264_loop_filter_luma)(pix, sizeof(pixel), stride, 2, alpha, beta, tc0);
}
-static av_always_inline av_flatten void FUNCC(h264_loop_filter_luma_intra)(uint8_t *_pix, int xstride, int ystride, int inner_iters, int alpha, int beta)
+static av_always_inline av_flatten void FUNCC(h264_loop_filter_luma_intra)(uint8_t *p_pix, int xstride, int ystride, int inner_iters, int alpha, int beta)
{
- pixel *pix = (pixel*)_pix;
+ pixel *pix = (pixel*)p_pix;
int d;
- xstride /= sizeof(pixel);
- ystride /= sizeof(pixel);
+ xstride >>= sizeof(pixel)-1;
+ ystride >>= sizeof(pixel)-1;
alpha <<= BIT_DEPTH - 8;
beta <<= BIT_DEPTH - 8;
for( d = 0; d < 4 * inner_iters; d++ ) {
@@ -230,14 +228,14 @@ static void FUNCC(h264_h_loop_filter_luma_mbaff_intra)(uint8_t *pix, int stride,
FUNCC(h264_loop_filter_luma_intra)(pix, sizeof(pixel), stride, 2, alpha, beta);
}
-static av_always_inline av_flatten void FUNCC(h264_loop_filter_chroma)(uint8_t *_pix, int xstride, int ystride, int inner_iters, int alpha, int beta, int8_t *tc0)
+static av_always_inline av_flatten void FUNCC(h264_loop_filter_chroma)(uint8_t *p_pix, int xstride, int ystride, int inner_iters, int alpha, int beta, int8_t *tc0)
{
- pixel *pix = (pixel*)_pix;
+ pixel *pix = (pixel*)p_pix;
int i, d;
- xstride /= sizeof(pixel);
- ystride /= sizeof(pixel);
alpha <<= BIT_DEPTH - 8;
beta <<= BIT_DEPTH - 8;
+ xstride >>= sizeof(pixel)-1;
+ ystride >>= sizeof(pixel)-1;
for( i = 0; i < 4; i++ ) {
const int tc = ((tc0[i] - 1) << (BIT_DEPTH - 8)) + 1;
if( tc <= 0 ) {
@@ -275,13 +273,21 @@ static void FUNCC(h264_h_loop_filter_chroma_mbaff)(uint8_t *pix, int stride, int
{
FUNCC(h264_loop_filter_chroma)(pix, sizeof(pixel), stride, 1, alpha, beta, tc0);
}
+static void FUNCC(h264_h_loop_filter_chroma422)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
+{
+ FUNCC(h264_loop_filter_chroma)(pix, sizeof(pixel), stride, 4, alpha, beta, tc0);
+}
+static void FUNCC(h264_h_loop_filter_chroma422_mbaff)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
+{
+ FUNCC(h264_loop_filter_chroma)(pix, sizeof(pixel), stride, 2, alpha, beta, tc0);
+}
-static av_always_inline av_flatten void FUNCC(h264_loop_filter_chroma_intra)(uint8_t *_pix, int xstride, int ystride, int inner_iters, int alpha, int beta)
+static av_always_inline av_flatten void FUNCC(h264_loop_filter_chroma_intra)(uint8_t *p_pix, int xstride, int ystride, int inner_iters, int alpha, int beta)
{
- pixel *pix = (pixel*)_pix;
+ pixel *pix = (pixel*)p_pix;
int d;
- xstride /= sizeof(pixel);
- ystride /= sizeof(pixel);
+ xstride >>= sizeof(pixel)-1;
+ ystride >>= sizeof(pixel)-1;
alpha <<= BIT_DEPTH - 8;
beta <<= BIT_DEPTH - 8;
for( d = 0; d < 4 * inner_iters; d++ ) {
@@ -312,3 +318,11 @@ static void FUNCC(h264_h_loop_filter_chroma_mbaff_intra)(uint8_t *pix, int strid
{
FUNCC(h264_loop_filter_chroma_intra)(pix, sizeof(pixel), stride, 1, alpha, beta);
}
+static void FUNCC(h264_h_loop_filter_chroma422_intra)(uint8_t *pix, int stride, int alpha, int beta)
+{
+ FUNCC(h264_loop_filter_chroma_intra)(pix, sizeof(pixel), stride, 4, alpha, beta);
+}
+static void FUNCC(h264_h_loop_filter_chroma422_mbaff_intra)(uint8_t *pix, int stride, int alpha, int beta)
+{
+ FUNCC(h264_loop_filter_chroma_intra)(pix, sizeof(pixel), stride, 2, alpha, beta);
+}
diff --git a/libavcodec/h264idct.c b/libavcodec/h264idct.c
index 1634a00835..7d1ee007bc 100644
--- a/libavcodec/h264idct.c
+++ b/libavcodec/h264idct.c
@@ -2,20 +2,20 @@
* H.264 IDCT
* Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/h264idct_template.c b/libavcodec/h264idct_template.c
index 55c1d3a4d8..c59976a1d9 100644
--- a/libavcodec/h264idct_template.c
+++ b/libavcodec/h264idct_template.c
@@ -2,20 +2,20 @@
* H.264 IDCT
* Copyright (c) 2004-2011 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -46,58 +46,47 @@ static const uint8_t scan8[16*3]={
};
#endif
-static av_always_inline void FUNCC(idct_internal)(uint8_t *_dst, DCTELEM *_block, int stride, int block_stride, int shift, int add){
+void FUNCC(ff_h264_idct_add)(uint8_t *_dst, DCTELEM *_block, int stride)
+{
int i;
INIT_CLIP
pixel *dst = (pixel*)_dst;
dctcoef *block = (dctcoef*)_block;
- stride /= sizeof(pixel);
+ stride >>= sizeof(pixel)-1;
- block[0] += 1<<(shift-1);
+ block[0] += 1 << 5;
for(i=0; i<4; i++){
- const int z0= block[i + block_stride*0] + block[i + block_stride*2];
- const int z1= block[i + block_stride*0] - block[i + block_stride*2];
- const int z2= (block[i + block_stride*1]>>1) - block[i + block_stride*3];
- const int z3= block[i + block_stride*1] + (block[i + block_stride*3]>>1);
-
- block[i + block_stride*0]= z0 + z3;
- block[i + block_stride*1]= z1 + z2;
- block[i + block_stride*2]= z1 - z2;
- block[i + block_stride*3]= z0 - z3;
+ const int z0= block[i + 4*0] + block[i + 4*2];
+ const int z1= block[i + 4*0] - block[i + 4*2];
+ const int z2= (block[i + 4*1]>>1) - block[i + 4*3];
+ const int z3= block[i + 4*1] + (block[i + 4*3]>>1);
+
+ block[i + 4*0]= z0 + z3;
+ block[i + 4*1]= z1 + z2;
+ block[i + 4*2]= z1 - z2;
+ block[i + 4*3]= z0 - z3;
}
for(i=0; i<4; i++){
- const int z0= block[0 + block_stride*i] + block[2 + block_stride*i];
- const int z1= block[0 + block_stride*i] - block[2 + block_stride*i];
- const int z2= (block[1 + block_stride*i]>>1) - block[3 + block_stride*i];
- const int z3= block[1 + block_stride*i] + (block[3 + block_stride*i]>>1);
-
- dst[i + 0*stride]= CLIP(add*dst[i + 0*stride] + ((z0 + z3) >> shift));
- dst[i + 1*stride]= CLIP(add*dst[i + 1*stride] + ((z1 + z2) >> shift));
- dst[i + 2*stride]= CLIP(add*dst[i + 2*stride] + ((z1 - z2) >> shift));
- dst[i + 3*stride]= CLIP(add*dst[i + 3*stride] + ((z0 - z3) >> shift));
+ const int z0= block[0 + 4*i] + block[2 + 4*i];
+ const int z1= block[0 + 4*i] - block[2 + 4*i];
+ const int z2= (block[1 + 4*i]>>1) - block[3 + 4*i];
+ const int z3= block[1 + 4*i] + (block[3 + 4*i]>>1);
+
+ dst[i + 0*stride]= CLIP(dst[i + 0*stride] + ((z0 + z3) >> 6));
+ dst[i + 1*stride]= CLIP(dst[i + 1*stride] + ((z1 + z2) >> 6));
+ dst[i + 2*stride]= CLIP(dst[i + 2*stride] + ((z1 - z2) >> 6));
+ dst[i + 3*stride]= CLIP(dst[i + 3*stride] + ((z0 - z3) >> 6));
}
}
-void FUNCC(ff_h264_idct_add)(uint8_t *dst, DCTELEM *block, int stride){
- FUNCC(idct_internal)(dst, block, stride, 4, 6, 1);
-}
-
-void FUNCC(ff_h264_lowres_idct_add)(uint8_t *dst, int stride, DCTELEM *block){
- FUNCC(idct_internal)(dst, block, stride, 8, 3, 1);
-}
-
-void FUNCC(ff_h264_lowres_idct_put)(uint8_t *dst, int stride, DCTELEM *block){
- FUNCC(idct_internal)(dst, block, stride, 8, 3, 0);
-}
-
void FUNCC(ff_h264_idct8_add)(uint8_t *_dst, DCTELEM *_block, int stride){
int i;
INIT_CLIP
pixel *dst = (pixel*)_dst;
dctcoef *block = (dctcoef*)_block;
- stride /= sizeof(pixel);
+ stride >>= sizeof(pixel)-1;
block[0] += 32;
@@ -166,12 +155,12 @@ void FUNCC(ff_h264_idct8_add)(uint8_t *_dst, DCTELEM *_block, int stride){
}
// assumes all AC coefs are 0
-void FUNCC(ff_h264_idct_dc_add)(uint8_t *_dst, DCTELEM *block, int stride){
+void FUNCC(ff_h264_idct_dc_add)(uint8_t *p_dst, DCTELEM *block, int stride){
int i, j;
int dc = (((dctcoef*)block)[0] + 32) >> 6;
INIT_CLIP
- pixel *dst = (pixel*)_dst;
- stride /= sizeof(pixel);
+ pixel *dst = (pixel*)p_dst;
+ stride >>= sizeof(pixel)-1;
for( j = 0; j < 4; j++ )
{
for( i = 0; i < 4; i++ )
@@ -180,12 +169,12 @@ void FUNCC(ff_h264_idct_dc_add)(uint8_t *_dst, DCTELEM *block, int stride){
}
}
-void FUNCC(ff_h264_idct8_dc_add)(uint8_t *_dst, DCTELEM *block, int stride){
+void FUNCC(ff_h264_idct8_dc_add)(uint8_t *p_dst, DCTELEM *block, int stride){
int i, j;
int dc = (((dctcoef*)block)[0] + 32) >> 6;
INIT_CLIP
- pixel *dst = (pixel*)_dst;
- stride /= sizeof(pixel);
+ pixel *dst = (pixel*)p_dst;
+ stride >>= sizeof(pixel)-1;
for( j = 0; j < 8; j++ )
{
for( i = 0; i < 8; i++ )
@@ -200,7 +189,7 @@ void FUNCC(ff_h264_idct_add16)(uint8_t *dst, const int *block_offset, DCTELEM *b
int nnz = nnzc[ scan8[i] ];
if(nnz){
if(nnz==1 && ((dctcoef*)block)[i*16]) FUNCC(ff_h264_idct_dc_add)(dst + block_offset[i], block + i*16*sizeof(pixel), stride);
- else FUNCC(idct_internal )(dst + block_offset[i], block + i*16*sizeof(pixel), stride, 4, 6, 1);
+ else FUNCC(ff_h264_idct_add )(dst + block_offset[i], block + i*16*sizeof(pixel), stride);
}
}
}
@@ -208,7 +197,7 @@ void FUNCC(ff_h264_idct_add16)(uint8_t *dst, const int *block_offset, DCTELEM *b
void FUNCC(ff_h264_idct_add16intra)(uint8_t *dst, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[15*8]){
int i;
for(i=0; i<16; i++){
- if(nnzc[ scan8[i] ]) FUNCC(idct_internal )(dst + block_offset[i], block + i*16*sizeof(pixel), stride, 4, 6, 1);
+ if(nnzc[ scan8[i] ]) FUNCC(ff_h264_idct_add )(dst + block_offset[i], block + i*16*sizeof(pixel), stride);
else if(((dctcoef*)block)[i*16]) FUNCC(ff_h264_idct_dc_add)(dst + block_offset[i], block + i*16*sizeof(pixel), stride);
}
}
@@ -235,17 +224,40 @@ void FUNCC(ff_h264_idct_add8)(uint8_t **dest, const int *block_offset, DCTELEM *
}
}
}
+
+void FUNCC(ff_h264_idct_add8_422)(uint8_t **dest, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[15*8]){
+ int i, j;
+
+ for(j=1; j<3; j++){
+ for(i=j*16; i<j*16+4; i++){
+ if(nnzc[ scan8[i] ])
+ FUNCC(ff_h264_idct_add )(dest[j-1] + block_offset[i], block + i*16*sizeof(pixel), stride);
+ else if(((dctcoef*)block)[i*16])
+ FUNCC(ff_h264_idct_dc_add)(dest[j-1] + block_offset[i], block + i*16*sizeof(pixel), stride);
+ }
+ }
+
+ for(j=1; j<3; j++){
+ for(i=j*16+4; i<j*16+8; i++){
+ if(nnzc[ scan8[i+4] ])
+ FUNCC(ff_h264_idct_add )(dest[j-1] + block_offset[i+4], block + i*16*sizeof(pixel), stride);
+ else if(((dctcoef*)block)[i*16])
+ FUNCC(ff_h264_idct_dc_add)(dest[j-1] + block_offset[i+4], block + i*16*sizeof(pixel), stride);
+ }
+ }
+}
+
/**
* IDCT transforms the 16 dc values and dequantizes them.
* @param qmul quantization parameter
*/
-void FUNCC(ff_h264_luma_dc_dequant_idct)(DCTELEM *_output, DCTELEM *_input, int qmul){
+void FUNCC(ff_h264_luma_dc_dequant_idct)(DCTELEM *p_output, DCTELEM *p_input, int qmul){
#define stride 16
int i;
int temp[16];
static const uint8_t x_offset[4]={0, 2*stride, 8*stride, 10*stride};
- dctcoef *input = (dctcoef*)_input;
- dctcoef *output = (dctcoef*)_output;
+ dctcoef *input = (dctcoef*)p_input;
+ dctcoef *output = (dctcoef*)p_output;
for(i=0; i<4; i++){
const int z0= input[4*i+0] + input[4*i+1];
@@ -274,6 +286,33 @@ void FUNCC(ff_h264_luma_dc_dequant_idct)(DCTELEM *_output, DCTELEM *_input, int
#undef stride
}
+void FUNCC(ff_h264_chroma422_dc_dequant_idct)(DCTELEM *_block, int qmul){
+ const int stride= 16*2;
+ const int xStride= 16;
+ int i;
+ int temp[8];
+ static const uint8_t x_offset[2]={0, 16};
+ dctcoef *block = (dctcoef*)_block;
+
+ for(i=0; i<4; i++){
+ temp[2*i+0] = block[stride*i + xStride*0] + block[stride*i + xStride*1];
+ temp[2*i+1] = block[stride*i + xStride*0] - block[stride*i + xStride*1];
+ }
+
+ for(i=0; i<2; i++){
+ const int offset= x_offset[i];
+ const int z0= temp[2*0+i] + temp[2*2+i];
+ const int z1= temp[2*0+i] - temp[2*2+i];
+ const int z2= temp[2*1+i] - temp[2*3+i];
+ const int z3= temp[2*1+i] + temp[2*3+i];
+
+ block[stride*0+offset]= ((z0 + z3)*qmul + 128) >> 8;
+ block[stride*1+offset]= ((z1 + z2)*qmul + 128) >> 8;
+ block[stride*2+offset]= ((z1 - z2)*qmul + 128) >> 8;
+ block[stride*3+offset]= ((z0 - z3)*qmul + 128) >> 8;
+ }
+}
+
void FUNCC(ff_h264_chroma_dc_dequant_idct)(DCTELEM *_block, int qmul){
const int stride= 16*2;
const int xStride= 16;
diff --git a/libavcodec/h264pred.c b/libavcodec/h264pred.c
index b3701ef3b8..a174b4ca3c 100644
--- a/libavcodec/h264pred.c
+++ b/libavcodec/h264pred.c
@@ -2,20 +2,20 @@
* H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder
* Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -40,7 +40,7 @@
#undef BIT_DEPTH
static void pred4x4_vertical_vp8_c(uint8_t *src, const uint8_t *topright, int stride){
- const int lt= src[-1-1*stride];
+ const unsigned lt = src[-1-1*stride];
LOAD_TOP_EDGE
LOAD_TOP_RIGHT_EDGE
uint32_t v = PACK_4U8((lt + 2*t0 + t1 + 2) >> 2,
@@ -55,7 +55,7 @@ static void pred4x4_vertical_vp8_c(uint8_t *src, const uint8_t *topright, int st
}
static void pred4x4_horizontal_vp8_c(uint8_t *src, const uint8_t *topright, int stride){
- const int lt= src[-1-1*stride];
+ const unsigned lt = src[-1-1*stride];
LOAD_LEFT_EDGE
AV_WN32A(src+0*stride, ((lt + 2*l0 + l1 + 2) >> 2)*0x01010101);
@@ -67,8 +67,6 @@ static void pred4x4_horizontal_vp8_c(uint8_t *src, const uint8_t *topright, int
static void pred4x4_down_left_svq3_c(uint8_t *src, const uint8_t *topright, int stride){
LOAD_TOP_EDGE
LOAD_LEFT_EDGE
- const av_unused int unu0= t0;
- const av_unused int unu1= l0;
src[0+0*stride]=(l1 + t1)>>1;
src[1+0*stride]=
@@ -292,7 +290,7 @@ static void pred16x16_tm_vp8_c(uint8_t *src, int stride){
static void pred8x8_left_dc_rv40_c(uint8_t *src, int stride){
int i;
- int dc0;
+ unsigned dc0;
dc0=0;
for(i=0;i<8; i++)
@@ -307,7 +305,7 @@ static void pred8x8_left_dc_rv40_c(uint8_t *src, int stride){
static void pred8x8_top_dc_rv40_c(uint8_t *src, int stride){
int i;
- int dc0;
+ unsigned dc0;
dc0=0;
for(i=0;i<8; i++)
@@ -322,7 +320,7 @@ static void pred8x8_top_dc_rv40_c(uint8_t *src, int stride){
static void pred8x8_dc_rv40_c(uint8_t *src, int stride){
int i;
- int dc0=0;
+ unsigned dc0 = 0;
for(i=0;i<4; i++){
dc0+= src[-1+i*stride] + src[i-stride];
@@ -363,7 +361,7 @@ static void pred8x8_tm_vp8_c(uint8_t *src, int stride){
/**
* Set the intra prediction function pointers.
*/
-void ff_h264_pred_init(H264PredContext *h, int codec_id, const int bit_depth){
+void ff_h264_pred_init(H264PredContext *h, int codec_id, const int bit_depth, const int chroma_format_idc){
// MpegEncContext * const s = &h->s;
#undef FUNC
@@ -436,20 +434,39 @@ void ff_h264_pred_init(H264PredContext *h, int codec_id, const int bit_depth){
h->pred8x8l[TOP_DC_PRED ]= FUNCC(pred8x8l_top_dc , depth);\
h->pred8x8l[DC_128_PRED ]= FUNCC(pred8x8l_128_dc , depth);\
\
- h->pred8x8[VERT_PRED8x8 ]= FUNCC(pred8x8_vertical , depth);\
- h->pred8x8[HOR_PRED8x8 ]= FUNCC(pred8x8_horizontal , depth);\
+ if (chroma_format_idc == 1) {\
+ h->pred8x8[VERT_PRED8x8 ]= FUNCC(pred8x8_vertical , depth);\
+ h->pred8x8[HOR_PRED8x8 ]= FUNCC(pred8x8_horizontal , depth);\
+ } else {\
+ h->pred8x8[VERT_PRED8x8 ]= FUNCC(pred8x16_vertical , depth);\
+ h->pred8x8[HOR_PRED8x8 ]= FUNCC(pred8x16_horizontal , depth);\
+ }\
if (codec_id != CODEC_ID_VP8) {\
- h->pred8x8[PLANE_PRED8x8]= FUNCC(pred8x8_plane , depth);\
+ if (chroma_format_idc == 1) {\
+ h->pred8x8[PLANE_PRED8x8]= FUNCC(pred8x8_plane , depth);\
+ } else {\
+ h->pred8x8[PLANE_PRED8x8]= FUNCC(pred8x16_plane , depth);\
+ }\
} else\
h->pred8x8[PLANE_PRED8x8]= FUNCD(pred8x8_tm_vp8);\
if(codec_id != CODEC_ID_RV40 && codec_id != CODEC_ID_VP8){\
- h->pred8x8[DC_PRED8x8 ]= FUNCC(pred8x8_dc , depth);\
- h->pred8x8[LEFT_DC_PRED8x8]= FUNCC(pred8x8_left_dc , depth);\
- h->pred8x8[TOP_DC_PRED8x8 ]= FUNCC(pred8x8_top_dc , depth);\
- h->pred8x8[ALZHEIMER_DC_L0T_PRED8x8 ]= FUNC(pred8x8_mad_cow_dc_l0t, depth);\
- h->pred8x8[ALZHEIMER_DC_0LT_PRED8x8 ]= FUNC(pred8x8_mad_cow_dc_0lt, depth);\
- h->pred8x8[ALZHEIMER_DC_L00_PRED8x8 ]= FUNC(pred8x8_mad_cow_dc_l00, depth);\
- h->pred8x8[ALZHEIMER_DC_0L0_PRED8x8 ]= FUNC(pred8x8_mad_cow_dc_0l0, depth);\
+ if (chroma_format_idc == 1) {\
+ h->pred8x8[DC_PRED8x8 ]= FUNCC(pred8x8_dc , depth);\
+ h->pred8x8[LEFT_DC_PRED8x8]= FUNCC(pred8x8_left_dc , depth);\
+ h->pred8x8[TOP_DC_PRED8x8 ]= FUNCC(pred8x8_top_dc , depth);\
+ h->pred8x8[ALZHEIMER_DC_L0T_PRED8x8 ]= FUNC(pred8x8_mad_cow_dc_l0t, depth);\
+ h->pred8x8[ALZHEIMER_DC_0LT_PRED8x8 ]= FUNC(pred8x8_mad_cow_dc_0lt, depth);\
+ h->pred8x8[ALZHEIMER_DC_L00_PRED8x8 ]= FUNC(pred8x8_mad_cow_dc_l00, depth);\
+ h->pred8x8[ALZHEIMER_DC_0L0_PRED8x8 ]= FUNC(pred8x8_mad_cow_dc_0l0, depth);\
+ } else {\
+ h->pred8x8[DC_PRED8x8 ]= FUNCC(pred8x16_dc , depth);\
+ h->pred8x8[LEFT_DC_PRED8x8]= FUNCC(pred8x16_left_dc , depth);\
+ h->pred8x8[TOP_DC_PRED8x8 ]= FUNCC(pred8x16_top_dc , depth);\
+ h->pred8x8[ALZHEIMER_DC_L0T_PRED8x8 ]= FUNC(pred8x16_mad_cow_dc_l0t, depth);\
+ h->pred8x8[ALZHEIMER_DC_0LT_PRED8x8 ]= FUNC(pred8x16_mad_cow_dc_0lt, depth);\
+ h->pred8x8[ALZHEIMER_DC_L00_PRED8x8 ]= FUNC(pred8x16_mad_cow_dc_l00, depth);\
+ h->pred8x8[ALZHEIMER_DC_0L0_PRED8x8 ]= FUNC(pred8x16_mad_cow_dc_0l0, depth);\
+ }\
}else{\
h->pred8x8[DC_PRED8x8 ]= FUNCD(pred8x8_dc_rv40);\
h->pred8x8[LEFT_DC_PRED8x8]= FUNCD(pred8x8_left_dc_rv40);\
@@ -459,7 +476,11 @@ void ff_h264_pred_init(H264PredContext *h, int codec_id, const int bit_depth){
h->pred8x8[DC_129_PRED8x8]= FUNCC(pred8x8_129_dc , depth);\
}\
}\
- h->pred8x8[DC_128_PRED8x8 ]= FUNCC(pred8x8_128_dc , depth);\
+ if (chroma_format_idc == 1) {\
+ h->pred8x8[DC_128_PRED8x8 ]= FUNCC(pred8x8_128_dc , depth);\
+ } else {\
+ h->pred8x8[DC_128_PRED8x8 ]= FUNCC(pred8x16_128_dc , depth);\
+ }\
\
h->pred16x16[DC_PRED8x8 ]= FUNCC(pred16x16_dc , depth);\
h->pred16x16[VERT_PRED8x8 ]= FUNCC(pred16x16_vertical , depth);\
@@ -489,8 +510,13 @@ void ff_h264_pred_init(H264PredContext *h, int codec_id, const int bit_depth){
h->pred4x4_add [ HOR_PRED ]= FUNCC(pred4x4_horizontal_add , depth);\
h->pred8x8l_add [VERT_PRED ]= FUNCC(pred8x8l_vertical_add , depth);\
h->pred8x8l_add [ HOR_PRED ]= FUNCC(pred8x8l_horizontal_add , depth);\
+ if (chroma_format_idc == 1) {\
h->pred8x8_add [VERT_PRED8x8]= FUNCC(pred8x8_vertical_add , depth);\
h->pred8x8_add [ HOR_PRED8x8]= FUNCC(pred8x8_horizontal_add , depth);\
+ } else {\
+ h->pred8x8_add [VERT_PRED8x8]= FUNCC(pred8x16_vertical_add , depth);\
+ h->pred8x8_add [ HOR_PRED8x8]= FUNCC(pred8x16_horizontal_add , depth);\
+ }\
h->pred16x16_add[VERT_PRED8x8]= FUNCC(pred16x16_vertical_add , depth);\
h->pred16x16_add[ HOR_PRED8x8]= FUNCC(pred16x16_horizontal_add , depth);\
@@ -506,6 +532,6 @@ void ff_h264_pred_init(H264PredContext *h, int codec_id, const int bit_depth){
break;
}
- if (ARCH_ARM) ff_h264_pred_init_arm(h, codec_id, bit_depth);
- if (HAVE_MMX) ff_h264_pred_init_x86(h, codec_id, bit_depth);
+ if (ARCH_ARM) ff_h264_pred_init_arm(h, codec_id, bit_depth, chroma_format_idc);
+ if (HAVE_MMX) ff_h264_pred_init_x86(h, codec_id, bit_depth, chroma_format_idc);
}
diff --git a/libavcodec/h264pred.h b/libavcodec/h264pred.h
index 34b1e90bbc..599cdb228b 100644
--- a/libavcodec/h264pred.h
+++ b/libavcodec/h264pred.h
@@ -2,20 +2,20 @@
* H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder
* Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -101,8 +101,8 @@ typedef struct H264PredContext{
void (*pred16x16_add[3])(uint8_t *pix/*align 16*/, const int *block_offset, const DCTELEM *block/*align 16*/, int stride);
}H264PredContext;
-void ff_h264_pred_init(H264PredContext *h, int codec_id, const int bit_depth);
-void ff_h264_pred_init_arm(H264PredContext *h, int codec_id, const int bit_depth);
-void ff_h264_pred_init_x86(H264PredContext *h, int codec_id, const int bit_depth);
+void ff_h264_pred_init(H264PredContext *h, int codec_id, const int bit_depth, const int chroma_format_idc);
+void ff_h264_pred_init_arm(H264PredContext *h, int codec_id, const int bit_depth, const int chroma_format_idc);
+void ff_h264_pred_init_x86(H264PredContext *h, int codec_id, const int bit_depth, const int chroma_format_idc);
#endif /* AVCODEC_H264PRED_H */
diff --git a/libavcodec/h264pred_template.c b/libavcodec/h264pred_template.c
index e5d91555b8..074fad50ca 100644
--- a/libavcodec/h264pred_template.c
+++ b/libavcodec/h264pred_template.c
@@ -2,20 +2,20 @@
* H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder
* Copyright (c) 2003-2011 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -31,7 +31,7 @@
static void FUNCC(pred4x4_vertical)(uint8_t *_src, const uint8_t *topright, int _stride){
pixel *src = (pixel*)_src;
- int stride = _stride/sizeof(pixel);
+ int stride = _stride>>(sizeof(pixel)-1);
const pixel4 a= AV_RN4PA(src-stride);
AV_WN4PA(src+0*stride, a);
@@ -42,7 +42,7 @@ static void FUNCC(pred4x4_vertical)(uint8_t *_src, const uint8_t *topright, int
static void FUNCC(pred4x4_horizontal)(uint8_t *_src, const uint8_t *topright, int _stride){
pixel *src = (pixel*)_src;
- int stride = _stride/sizeof(pixel);
+ int stride = _stride>>(sizeof(pixel)-1);
AV_WN4PA(src+0*stride, PIXEL_SPLAT_X4(src[-1+0*stride]));
AV_WN4PA(src+1*stride, PIXEL_SPLAT_X4(src[-1+1*stride]));
AV_WN4PA(src+2*stride, PIXEL_SPLAT_X4(src[-1+2*stride]));
@@ -51,7 +51,7 @@ static void FUNCC(pred4x4_horizontal)(uint8_t *_src, const uint8_t *topright, in
static void FUNCC(pred4x4_dc)(uint8_t *_src, const uint8_t *topright, int _stride){
pixel *src = (pixel*)_src;
- int stride = _stride/sizeof(pixel);
+ int stride = _stride>>(sizeof(pixel)-1);
const int dc= ( src[-stride] + src[1-stride] + src[2-stride] + src[3-stride]
+ src[-1+0*stride] + src[-1+1*stride] + src[-1+2*stride] + src[-1+3*stride] + 4) >>3;
const pixel4 a = PIXEL_SPLAT_X4(dc);
@@ -64,7 +64,7 @@ static void FUNCC(pred4x4_dc)(uint8_t *_src, const uint8_t *topright, int _strid
static void FUNCC(pred4x4_left_dc)(uint8_t *_src, const uint8_t *topright, int _stride){
pixel *src = (pixel*)_src;
- int stride = _stride/sizeof(pixel);
+ int stride = _stride>>(sizeof(pixel)-1);
const int dc= ( src[-1+0*stride] + src[-1+1*stride] + src[-1+2*stride] + src[-1+3*stride] + 2) >>2;
const pixel4 a = PIXEL_SPLAT_X4(dc);
@@ -76,7 +76,7 @@ static void FUNCC(pred4x4_left_dc)(uint8_t *_src, const uint8_t *topright, int _
static void FUNCC(pred4x4_top_dc)(uint8_t *_src, const uint8_t *topright, int _stride){
pixel *src = (pixel*)_src;
- int stride = _stride/sizeof(pixel);
+ int stride = _stride>>(sizeof(pixel)-1);
const int dc= ( src[-stride] + src[1-stride] + src[2-stride] + src[3-stride] + 2) >>2;
const pixel4 a = PIXEL_SPLAT_X4(dc);
@@ -88,7 +88,7 @@ static void FUNCC(pred4x4_top_dc)(uint8_t *_src, const uint8_t *topright, int _s
static void FUNCC(pred4x4_128_dc)(uint8_t *_src, const uint8_t *topright, int _stride){
pixel *src = (pixel*)_src;
- int stride = _stride/sizeof(pixel);
+ int stride = _stride>>(sizeof(pixel)-1);
const pixel4 a = PIXEL_SPLAT_X4(1<<(BIT_DEPTH-1));
AV_WN4PA(src+0*stride, a);
@@ -99,7 +99,7 @@ static void FUNCC(pred4x4_128_dc)(uint8_t *_src, const uint8_t *topright, int _s
static void FUNCC(pred4x4_127_dc)(uint8_t *_src, const uint8_t *topright, int _stride){
pixel *src = (pixel*)_src;
- int stride = _stride/sizeof(pixel);
+ int stride = _stride>>(sizeof(pixel)-1);
const pixel4 a = PIXEL_SPLAT_X4((1<<(BIT_DEPTH-1))-1);
AV_WN4PA(src+0*stride, a);
@@ -110,7 +110,7 @@ static void FUNCC(pred4x4_127_dc)(uint8_t *_src, const uint8_t *topright, int _s
static void FUNCC(pred4x4_129_dc)(uint8_t *_src, const uint8_t *topright, int _stride){
pixel *src = (pixel*)_src;
- int stride = _stride/sizeof(pixel);
+ int stride = _stride>>(sizeof(pixel)-1);
const pixel4 a = PIXEL_SPLAT_X4((1<<(BIT_DEPTH-1))+1);
AV_WN4PA(src+0*stride, a);
@@ -121,32 +121,32 @@ static void FUNCC(pred4x4_129_dc)(uint8_t *_src, const uint8_t *topright, int _s
#define LOAD_TOP_RIGHT_EDGE\
- const int av_unused t4= topright[0];\
- const int av_unused t5= topright[1];\
- const int av_unused t6= topright[2];\
- const int av_unused t7= topright[3];\
+ const unsigned av_unused t4 = topright[0];\
+ const unsigned av_unused t5 = topright[1];\
+ const unsigned av_unused t6 = topright[2];\
+ const unsigned av_unused t7 = topright[3];\
#define LOAD_DOWN_LEFT_EDGE\
- const int av_unused l4= src[-1+4*stride];\
- const int av_unused l5= src[-1+5*stride];\
- const int av_unused l6= src[-1+6*stride];\
- const int av_unused l7= src[-1+7*stride];\
+ const unsigned av_unused l4 = src[-1+4*stride];\
+ const unsigned av_unused l5 = src[-1+5*stride];\
+ const unsigned av_unused l6 = src[-1+6*stride];\
+ const unsigned av_unused l7 = src[-1+7*stride];\
#define LOAD_LEFT_EDGE\
- const int av_unused l0= src[-1+0*stride];\
- const int av_unused l1= src[-1+1*stride];\
- const int av_unused l2= src[-1+2*stride];\
- const int av_unused l3= src[-1+3*stride];\
+ const unsigned av_unused l0 = src[-1+0*stride];\
+ const unsigned av_unused l1 = src[-1+1*stride];\
+ const unsigned av_unused l2 = src[-1+2*stride];\
+ const unsigned av_unused l3 = src[-1+3*stride];\
#define LOAD_TOP_EDGE\
- const int av_unused t0= src[ 0-1*stride];\
- const int av_unused t1= src[ 1-1*stride];\
- const int av_unused t2= src[ 2-1*stride];\
- const int av_unused t3= src[ 3-1*stride];\
+ const unsigned av_unused t0 = src[ 0-1*stride];\
+ const unsigned av_unused t1 = src[ 1-1*stride];\
+ const unsigned av_unused t2 = src[ 2-1*stride];\
+ const unsigned av_unused t3 = src[ 3-1*stride];\
static void FUNCC(pred4x4_down_right)(uint8_t *_src, const uint8_t *topright, int _stride){
pixel *src = (pixel*)_src;
- int stride = _stride/sizeof(pixel);
+ int stride = _stride>>(sizeof(pixel)-1);
const int lt= src[-1-1*stride];
LOAD_TOP_EDGE
LOAD_LEFT_EDGE
@@ -172,7 +172,7 @@ static void FUNCC(pred4x4_down_right)(uint8_t *_src, const uint8_t *topright, in
static void FUNCC(pred4x4_down_left)(uint8_t *_src, const uint8_t *_topright, int _stride){
pixel *src = (pixel*)_src;
const pixel *topright = (const pixel*)_topright;
- int stride = _stride/sizeof(pixel);
+ int stride = _stride>>(sizeof(pixel)-1);
LOAD_TOP_EDGE
LOAD_TOP_RIGHT_EDGE
// LOAD_LEFT_EDGE
@@ -197,7 +197,7 @@ static void FUNCC(pred4x4_down_left)(uint8_t *_src, const uint8_t *_topright, in
static void FUNCC(pred4x4_vertical_right)(uint8_t *_src, const uint8_t *topright, int _stride){
pixel *src = (pixel*)_src;
- int stride = _stride/sizeof(pixel);
+ int stride = _stride>>(sizeof(pixel)-1);
const int lt= src[-1-1*stride];
LOAD_TOP_EDGE
LOAD_LEFT_EDGE
@@ -223,7 +223,7 @@ static void FUNCC(pred4x4_vertical_right)(uint8_t *_src, const uint8_t *topright
static void FUNCC(pred4x4_vertical_left)(uint8_t *_src, const uint8_t *_topright, int _stride){
pixel *src = (pixel*)_src;
const pixel *topright = (const pixel*)_topright;
- int stride = _stride/sizeof(pixel);
+ int stride = _stride>>(sizeof(pixel)-1);
LOAD_TOP_EDGE
LOAD_TOP_RIGHT_EDGE
@@ -247,7 +247,7 @@ static void FUNCC(pred4x4_vertical_left)(uint8_t *_src, const uint8_t *_topright
static void FUNCC(pred4x4_horizontal_up)(uint8_t *_src, const uint8_t *topright, int _stride){
pixel *src = (pixel*)_src;
- int stride = _stride/sizeof(pixel);
+ int stride = _stride>>(sizeof(pixel)-1);
LOAD_LEFT_EDGE
src[0+0*stride]=(l0 + l1 + 1)>>1;
@@ -270,7 +270,7 @@ static void FUNCC(pred4x4_horizontal_up)(uint8_t *_src, const uint8_t *topright,
static void FUNCC(pred4x4_horizontal_down)(uint8_t *_src, const uint8_t *topright, int _stride){
pixel *src = (pixel*)_src;
- int stride = _stride/sizeof(pixel);
+ int stride = _stride>>(sizeof(pixel)-1);
const int lt= src[-1-1*stride];
LOAD_TOP_EDGE
LOAD_LEFT_EDGE
@@ -296,7 +296,7 @@ static void FUNCC(pred4x4_horizontal_down)(uint8_t *_src, const uint8_t *toprigh
static void FUNCC(pred16x16_vertical)(uint8_t *_src, int _stride){
int i;
pixel *src = (pixel*)_src;
- int stride = _stride/sizeof(pixel);
+ int stride = _stride>>(sizeof(pixel)-1);
const pixel4 a = AV_RN4PA(((pixel4*)(src-stride))+0);
const pixel4 b = AV_RN4PA(((pixel4*)(src-stride))+1);
const pixel4 c = AV_RN4PA(((pixel4*)(src-stride))+2);
@@ -313,7 +313,7 @@ static void FUNCC(pred16x16_vertical)(uint8_t *_src, int _stride){
static void FUNCC(pred16x16_horizontal)(uint8_t *_src, int stride){
int i;
pixel *src = (pixel*)_src;
- stride /= sizeof(pixel);
+ stride >>= sizeof(pixel)-1;
for(i=0; i<16; i++){
const pixel4 a = PIXEL_SPLAT_X4(src[-1+i*stride]);
@@ -338,7 +338,7 @@ static void FUNCC(pred16x16_dc)(uint8_t *_src, int stride){
int i, dc=0;
pixel *src = (pixel*)_src;
pixel4 dcsplat;
- stride /= sizeof(pixel);
+ stride >>= sizeof(pixel)-1;
for(i=0;i<16; i++){
dc+= src[-1+i*stride];
@@ -356,7 +356,7 @@ static void FUNCC(pred16x16_left_dc)(uint8_t *_src, int stride){
int i, dc=0;
pixel *src = (pixel*)_src;
pixel4 dcsplat;
- stride /= sizeof(pixel);
+ stride >>= sizeof(pixel)-1;
for(i=0;i<16; i++){
dc+= src[-1+i*stride];
@@ -370,7 +370,7 @@ static void FUNCC(pred16x16_top_dc)(uint8_t *_src, int stride){
int i, dc=0;
pixel *src = (pixel*)_src;
pixel4 dcsplat;
- stride /= sizeof(pixel);
+ stride >>= sizeof(pixel)-1;
for(i=0;i<16; i++){
dc+= src[i-stride];
@@ -384,7 +384,7 @@ static void FUNCC(pred16x16_top_dc)(uint8_t *_src, int stride){
static void FUNCC(pred16x16_##n##_dc)(uint8_t *_src, int stride){\
int i;\
pixel *src = (pixel*)_src;\
- stride /= sizeof(pixel);\
+ stride >>= sizeof(pixel)-1;\
PREDICT_16x16_DC(PIXEL_SPLAT_X4(v));\
}
@@ -392,12 +392,12 @@ PRED16x16_X(127, (1<<(BIT_DEPTH-1))-1);
PRED16x16_X(128, (1<<(BIT_DEPTH-1))+0);
PRED16x16_X(129, (1<<(BIT_DEPTH-1))+1);
-static inline void FUNCC(pred16x16_plane_compat)(uint8_t *_src, int _stride, const int svq3, const int rv40){
+static inline void FUNCC(pred16x16_plane_compat)(uint8_t *p_src, int p_stride, const int svq3, const int rv40){
int i, j, k;
int a;
INIT_CLIP
- pixel *src = (pixel*)_src;
- int stride = _stride/sizeof(pixel);
+ pixel *src = (pixel*)p_src;
+ int stride = p_stride>>(sizeof(pixel)-1);
const pixel * const src0 = src +7-stride;
const pixel * src1 = src +8*stride-1;
const pixel * src2 = src1-2*stride; // == src+6*stride-1;
@@ -444,7 +444,7 @@ static void FUNCC(pred16x16_plane)(uint8_t *src, int stride){
static void FUNCC(pred8x8_vertical)(uint8_t *_src, int _stride){
int i;
pixel *src = (pixel*)_src;
- int stride = _stride/sizeof(pixel);
+ int stride = _stride>>(sizeof(pixel)-1);
const pixel4 a= AV_RN4PA(((pixel4*)(src-stride))+0);
const pixel4 b= AV_RN4PA(((pixel4*)(src-stride))+1);
@@ -454,10 +454,23 @@ static void FUNCC(pred8x8_vertical)(uint8_t *_src, int _stride){
}
}
+static void FUNCC(pred8x16_vertical)(uint8_t *_src, int _stride){
+ int i;
+ pixel *src = (pixel*)_src;
+ int stride = _stride>>(sizeof(pixel)-1);
+ const pixel4 a= AV_RN4PA(((pixel4*)(src-stride))+0);
+ const pixel4 b= AV_RN4PA(((pixel4*)(src-stride))+1);
+
+ for(i=0; i<16; i++){
+ AV_WN4PA(((pixel4*)(src+i*stride))+0, a);
+ AV_WN4PA(((pixel4*)(src+i*stride))+1, b);
+ }
+}
+
static void FUNCC(pred8x8_horizontal)(uint8_t *_src, int stride){
int i;
pixel *src = (pixel*)_src;
- stride /= sizeof(pixel);
+ stride >>= sizeof(pixel)-1;
for(i=0; i<8; i++){
const pixel4 a = PIXEL_SPLAT_X4(src[-1+i*stride]);
@@ -466,12 +479,23 @@ static void FUNCC(pred8x8_horizontal)(uint8_t *_src, int stride){
}
}
+static void FUNCC(pred8x16_horizontal)(uint8_t *_src, int stride){
+ int i;
+ pixel *src = (pixel*)_src;
+ stride >>= sizeof(pixel)-1;
+ for(i=0; i<16; i++){
+ const pixel4 a = PIXEL_SPLAT_X4(src[-1+i*stride]);
+ AV_WN4PA(((pixel4*)(src+i*stride))+0, a);
+ AV_WN4PA(((pixel4*)(src+i*stride))+1, a);
+ }
+}
+
#define PRED8x8_X(n, v)\
static void FUNCC(pred8x8_##n##_dc)(uint8_t *_src, int stride){\
int i;\
const pixel4 a = PIXEL_SPLAT_X4(v);\
pixel *src = (pixel*)_src;\
- stride /= sizeof(pixel);\
+ stride >>= sizeof(pixel)-1;\
for(i=0; i<8; i++){\
AV_WN4PA(((pixel4*)(src+i*stride))+0, a);\
AV_WN4PA(((pixel4*)(src+i*stride))+1, a);\
@@ -482,12 +506,17 @@ PRED8x8_X(127, (1<<(BIT_DEPTH-1))-1);
PRED8x8_X(128, (1<<(BIT_DEPTH-1))+0);
PRED8x8_X(129, (1<<(BIT_DEPTH-1))+1);
+static void FUNCC(pred8x16_128_dc)(uint8_t *_src, int stride){
+ FUNCC(pred8x8_128_dc)(_src, stride);
+ FUNCC(pred8x8_128_dc)(_src+8*stride, stride);
+}
+
static void FUNCC(pred8x8_left_dc)(uint8_t *_src, int stride){
int i;
int dc0, dc2;
pixel4 dc0splat, dc2splat;
pixel *src = (pixel*)_src;
- stride /= sizeof(pixel);
+ stride >>= sizeof(pixel)-1;
dc0=dc2=0;
for(i=0;i<4; i++){
@@ -507,12 +536,17 @@ static void FUNCC(pred8x8_left_dc)(uint8_t *_src, int stride){
}
}
+static void FUNCC(pred8x16_left_dc)(uint8_t *_src, int stride){
+ FUNCC(pred8x8_left_dc)(_src, stride);
+ FUNCC(pred8x8_left_dc)(_src+8*stride, stride);
+}
+
static void FUNCC(pred8x8_top_dc)(uint8_t *_src, int stride){
int i;
int dc0, dc1;
pixel4 dc0splat, dc1splat;
pixel *src = (pixel*)_src;
- stride /= sizeof(pixel);
+ stride >>= sizeof(pixel)-1;
dc0=dc1=0;
for(i=0;i<4; i++){
@@ -532,12 +566,33 @@ static void FUNCC(pred8x8_top_dc)(uint8_t *_src, int stride){
}
}
+static void FUNCC(pred8x16_top_dc)(uint8_t *_src, int stride){
+ int i;
+ int dc0, dc1;
+ pixel4 dc0splat, dc1splat;
+ pixel *src = (pixel*)_src;
+ stride >>= sizeof(pixel)-1;
+
+ dc0=dc1=0;
+ for(i=0;i<4; i++){
+ dc0+= src[i-stride];
+ dc1+= src[4+i-stride];
+ }
+ dc0splat = PIXEL_SPLAT_X4((dc0 + 2)>>2);
+ dc1splat = PIXEL_SPLAT_X4((dc1 + 2)>>2);
+
+ for(i=0; i<16; i++){
+ AV_WN4PA(((pixel4*)(src+i*stride))+0, dc0splat);
+ AV_WN4PA(((pixel4*)(src+i*stride))+1, dc1splat);
+ }
+}
+
static void FUNCC(pred8x8_dc)(uint8_t *_src, int stride){
int i;
int dc0, dc1, dc2;
pixel4 dc0splat, dc1splat, dc2splat, dc3splat;
pixel *src = (pixel*)_src;
- stride /= sizeof(pixel);
+ stride >>= sizeof(pixel)-1;
dc0=dc1=dc2=0;
for(i=0;i<4; i++){
@@ -560,35 +615,99 @@ static void FUNCC(pred8x8_dc)(uint8_t *_src, int stride){
}
}
+static void FUNCC(pred8x16_dc)(uint8_t *_src, int stride){
+ int i;
+ int dc0, dc1, dc2, dc3, dc4;
+ pixel4 dc0splat, dc1splat, dc2splat, dc3splat, dc4splat, dc5splat, dc6splat, dc7splat;
+ pixel *src = (pixel*)_src;
+ stride >>= sizeof(pixel)-1;
+
+ dc0=dc1=dc2=dc3=dc4=0;
+ for(i=0;i<4; i++){
+ dc0+= src[-1+i*stride] + src[i-stride];
+ dc1+= src[4+i-stride];
+ dc2+= src[-1+(i+4)*stride];
+ dc3+= src[-1+(i+8)*stride];
+ dc4+= src[-1+(i+12)*stride];
+ }
+ dc0splat = PIXEL_SPLAT_X4((dc0 + 4)>>3);
+ dc1splat = PIXEL_SPLAT_X4((dc1 + 2)>>2);
+ dc2splat = PIXEL_SPLAT_X4((dc2 + 2)>>2);
+ dc3splat = PIXEL_SPLAT_X4((dc1 + dc2 + 4)>>3);
+ dc4splat = PIXEL_SPLAT_X4((dc3 + 2)>>2);
+ dc5splat = PIXEL_SPLAT_X4((dc1 + dc3 + 4)>>3);
+ dc6splat = PIXEL_SPLAT_X4((dc4 + 2)>>2);
+ dc7splat = PIXEL_SPLAT_X4((dc1 + dc4 + 4)>>3);
+
+ for(i=0; i<4; i++){
+ AV_WN4PA(((pixel4*)(src+i*stride))+0, dc0splat);
+ AV_WN4PA(((pixel4*)(src+i*stride))+1, dc1splat);
+ }
+ for(i=4; i<8; i++){
+ AV_WN4PA(((pixel4*)(src+i*stride))+0, dc2splat);
+ AV_WN4PA(((pixel4*)(src+i*stride))+1, dc3splat);
+ }
+ for(i=8; i<12; i++){
+ AV_WN4PA(((pixel4*)(src+i*stride))+0, dc4splat);
+ AV_WN4PA(((pixel4*)(src+i*stride))+1, dc5splat);
+ }
+ for(i=12; i<16; i++){
+ AV_WN4PA(((pixel4*)(src+i*stride))+0, dc6splat);
+ AV_WN4PA(((pixel4*)(src+i*stride))+1, dc7splat);
+ }
+}
+
//the following 4 function should not be optimized!
static void FUNC(pred8x8_mad_cow_dc_l0t)(uint8_t *src, int stride){
FUNCC(pred8x8_top_dc)(src, stride);
FUNCC(pred4x4_dc)(src, NULL, stride);
}
+static void FUNC(pred8x16_mad_cow_dc_l0t)(uint8_t *src, int stride){
+ FUNCC(pred8x16_top_dc)(src, stride);
+ FUNCC(pred4x4_dc)(src, NULL, stride);
+}
+
static void FUNC(pred8x8_mad_cow_dc_0lt)(uint8_t *src, int stride){
FUNCC(pred8x8_dc)(src, stride);
FUNCC(pred4x4_top_dc)(src, NULL, stride);
}
+static void FUNC(pred8x16_mad_cow_dc_0lt)(uint8_t *src, int stride){
+ FUNCC(pred8x16_dc)(src, stride);
+ FUNCC(pred4x4_top_dc)(src, NULL, stride);
+}
+
static void FUNC(pred8x8_mad_cow_dc_l00)(uint8_t *src, int stride){
FUNCC(pred8x8_left_dc)(src, stride);
FUNCC(pred4x4_128_dc)(src + 4*stride , NULL, stride);
FUNCC(pred4x4_128_dc)(src + 4*stride + 4*sizeof(pixel), NULL, stride);
}
+static void FUNC(pred8x16_mad_cow_dc_l00)(uint8_t *src, int stride){
+ FUNCC(pred8x16_left_dc)(src, stride);
+ FUNCC(pred4x4_128_dc)(src + 4*stride , NULL, stride);
+ FUNCC(pred4x4_128_dc)(src + 4*stride + 4*sizeof(pixel), NULL, stride);
+}
+
static void FUNC(pred8x8_mad_cow_dc_0l0)(uint8_t *src, int stride){
FUNCC(pred8x8_left_dc)(src, stride);
FUNCC(pred4x4_128_dc)(src , NULL, stride);
FUNCC(pred4x4_128_dc)(src + 4*sizeof(pixel), NULL, stride);
}
+static void FUNC(pred8x16_mad_cow_dc_0l0)(uint8_t *src, int stride){
+ FUNCC(pred8x16_left_dc)(src, stride);
+ FUNCC(pred4x4_128_dc)(src , NULL, stride);
+ FUNCC(pred4x4_128_dc)(src + 4*sizeof(pixel), NULL, stride);
+}
+
static void FUNCC(pred8x8_plane)(uint8_t *_src, int _stride){
int j, k;
int a;
INIT_CLIP
pixel *src = (pixel*)_src;
- int stride = _stride/sizeof(pixel);
+ int stride = _stride>>(sizeof(pixel)-1);
const pixel * const src0 = src +3-stride;
const pixel * src1 = src +4*stride-1;
const pixel * src2 = src1-2*stride; // == src+2*stride-1;
@@ -618,6 +737,47 @@ static void FUNCC(pred8x8_plane)(uint8_t *_src, int _stride){
}
}
+static void FUNCC(pred8x16_plane)(uint8_t *_src, int _stride){
+ int j, k;
+ int a;
+ INIT_CLIP
+ pixel *src = (pixel*)_src;
+ int stride = _stride>>(sizeof(pixel)-1);
+ const pixel * const src0 = src +3-stride;
+ const pixel * src1 = src +8*stride-1;
+ const pixel * src2 = src1-2*stride; // == src+6*stride-1;
+ int H = src0[1] - src0[-1];
+ int V = src1[0] - src2[ 0];
+
+ for (k = 2; k <= 4; ++k) {
+ src1 += stride; src2 -= stride;
+ H += k*(src0[k] - src0[-k]);
+ V += k*(src1[0] - src2[ 0]);
+ }
+ for (; k <= 8; ++k) {
+ src1 += stride; src2 -= stride;
+ V += k*(src1[0] - src2[0]);
+ }
+
+ H = (17*H+16) >> 5;
+ V = (5*V+32) >> 6;
+
+ a = 16*(src1[0] + src2[8] + 1) - 7*V - 3*H;
+ for(j=16; j>0; --j) {
+ int b = a;
+ a += V;
+ src[0] = CLIP((b ) >> 5);
+ src[1] = CLIP((b+ H) >> 5);
+ src[2] = CLIP((b+2*H) >> 5);
+ src[3] = CLIP((b+3*H) >> 5);
+ src[4] = CLIP((b+4*H) >> 5);
+ src[5] = CLIP((b+5*H) >> 5);
+ src[6] = CLIP((b+6*H) >> 5);
+ src[7] = CLIP((b+7*H) >> 5);
+ src += stride;
+ }
+}
+
#define SRC(x,y) src[(x)+(y)*stride]
#define PL(y) \
const int l##y = (SRC(-1,y-1) + 2*SRC(-1,y) + SRC(-1,y+1) + 2) >> 2;
@@ -659,32 +819,32 @@ static void FUNCC(pred8x8_plane)(uint8_t *_src, int _stride){
static void FUNCC(pred8x8l_128_dc)(uint8_t *_src, int has_topleft, int has_topright, int _stride)
{
pixel *src = (pixel*)_src;
- int stride = _stride/sizeof(pixel);
+ int stride = _stride>>(sizeof(pixel)-1);
PREDICT_8x8_DC(PIXEL_SPLAT_X4(1<<(BIT_DEPTH-1)));
}
static void FUNCC(pred8x8l_left_dc)(uint8_t *_src, int has_topleft, int has_topright, int _stride)
{
pixel *src = (pixel*)_src;
- int stride = _stride/sizeof(pixel);
+ int stride = _stride>>(sizeof(pixel)-1);
PREDICT_8x8_LOAD_LEFT;
const pixel4 dc = PIXEL_SPLAT_X4((l0+l1+l2+l3+l4+l5+l6+l7+4) >> 3);
PREDICT_8x8_DC(dc);
}
-static void FUNCC(pred8x8l_top_dc)(uint8_t *_src, int has_topleft, int has_topright, int _stride)
+static void FUNCC(pred8x8l_top_dc)(uint8_t *p_src, int has_topleft, int has_topright, int p_stride)
{
- pixel *src = (pixel*)_src;
- int stride = _stride/sizeof(pixel);
+ pixel *src = (pixel*)p_src;
+ int stride = p_stride>>(sizeof(pixel)-1);
PREDICT_8x8_LOAD_TOP;
const pixel4 dc = PIXEL_SPLAT_X4((t0+t1+t2+t3+t4+t5+t6+t7+4) >> 3);
PREDICT_8x8_DC(dc);
}
-static void FUNCC(pred8x8l_dc)(uint8_t *_src, int has_topleft, int has_topright, int _stride)
+static void FUNCC(pred8x8l_dc)(uint8_t *p_src, int has_topleft, int has_topright, int p_stride)
{
- pixel *src = (pixel*)_src;
- int stride = _stride/sizeof(pixel);
+ pixel *src = (pixel*)p_src;
+ int stride = p_stride>>(sizeof(pixel)-1);
PREDICT_8x8_LOAD_LEFT;
PREDICT_8x8_LOAD_TOP;
@@ -692,10 +852,10 @@ static void FUNCC(pred8x8l_dc)(uint8_t *_src, int has_topleft, int has_topright,
+t0+t1+t2+t3+t4+t5+t6+t7+8) >> 4);
PREDICT_8x8_DC(dc);
}
-static void FUNCC(pred8x8l_horizontal)(uint8_t *_src, int has_topleft, int has_topright, int _stride)
+static void FUNCC(pred8x8l_horizontal)(uint8_t *p_src, int has_topleft, int has_topright, int p_stride)
{
- pixel *src = (pixel*)_src;
- int stride = _stride/sizeof(pixel);
+ pixel *src = (pixel*)p_src;
+ int stride = p_stride>>(sizeof(pixel)-1);
pixel4 a;
PREDICT_8x8_LOAD_LEFT;
@@ -709,7 +869,7 @@ static void FUNCC(pred8x8l_vertical)(uint8_t *_src, int has_topleft, int has_top
{
int y;
pixel *src = (pixel*)_src;
- int stride = _stride/sizeof(pixel);
+ int stride = _stride>>(sizeof(pixel)-1);
pixel4 a, b;
PREDICT_8x8_LOAD_TOP;
@@ -728,10 +888,10 @@ static void FUNCC(pred8x8l_vertical)(uint8_t *_src, int has_topleft, int has_top
AV_WN4PA(((pixel4*)(src+y*stride))+1, b);
}
}
-static void FUNCC(pred8x8l_down_left)(uint8_t *_src, int has_topleft, int has_topright, int _stride)
+static void FUNCC(pred8x8l_down_left)(uint8_t *p_src, int has_topleft, int has_topright, int p_stride)
{
- pixel *src = (pixel*)_src;
- int stride = _stride/sizeof(pixel);
+ pixel *src = (pixel*)p_src;
+ int stride = p_stride>>(sizeof(pixel)-1);
PREDICT_8x8_LOAD_TOP;
PREDICT_8x8_LOAD_TOPRIGHT;
SRC(0,0)= (t0 + 2*t1 + t2 + 2) >> 2;
@@ -750,10 +910,10 @@ static void FUNCC(pred8x8l_down_left)(uint8_t *_src, int has_topleft, int has_to
SRC(6,7)=SRC(7,6)= (t13 + 2*t14 + t15 + 2) >> 2;
SRC(7,7)= (t14 + 3*t15 + 2) >> 2;
}
-static void FUNCC(pred8x8l_down_right)(uint8_t *_src, int has_topleft, int has_topright, int _stride)
+static void FUNCC(pred8x8l_down_right)(uint8_t *p_src, int has_topleft, int has_topright, int p_stride)
{
- pixel *src = (pixel*)_src;
- int stride = _stride/sizeof(pixel);
+ pixel *src = (pixel*)p_src;
+ int stride = p_stride>>(sizeof(pixel)-1);
PREDICT_8x8_LOAD_TOP;
PREDICT_8x8_LOAD_LEFT;
PREDICT_8x8_LOAD_TOPLEFT;
@@ -773,10 +933,10 @@ static void FUNCC(pred8x8l_down_right)(uint8_t *_src, int has_topleft, int has_t
SRC(6,0)=SRC(7,1)= (t4 + 2*t5 + t6 + 2) >> 2;
SRC(7,0)= (t5 + 2*t6 + t7 + 2) >> 2;
}
-static void FUNCC(pred8x8l_vertical_right)(uint8_t *_src, int has_topleft, int has_topright, int _stride)
+static void FUNCC(pred8x8l_vertical_right)(uint8_t *p_src, int has_topleft, int has_topright, int p_stride)
{
- pixel *src = (pixel*)_src;
- int stride = _stride/sizeof(pixel);
+ pixel *src = (pixel*)p_src;
+ int stride = p_stride>>(sizeof(pixel)-1);
PREDICT_8x8_LOAD_TOP;
PREDICT_8x8_LOAD_LEFT;
PREDICT_8x8_LOAD_TOPLEFT;
@@ -803,10 +963,10 @@ static void FUNCC(pred8x8l_vertical_right)(uint8_t *_src, int has_topleft, int h
SRC(7,1)= (t5 + 2*t6 + t7 + 2) >> 2;
SRC(7,0)= (t6 + t7 + 1) >> 1;
}
-static void FUNCC(pred8x8l_horizontal_down)(uint8_t *_src, int has_topleft, int has_topright, int _stride)
+static void FUNCC(pred8x8l_horizontal_down)(uint8_t *p_src, int has_topleft, int has_topright, int p_stride)
{
- pixel *src = (pixel*)_src;
- int stride = _stride/sizeof(pixel);
+ pixel *src = (pixel*)p_src;
+ int stride = p_stride>>(sizeof(pixel)-1);
PREDICT_8x8_LOAD_TOP;
PREDICT_8x8_LOAD_LEFT;
PREDICT_8x8_LOAD_TOPLEFT;
@@ -833,10 +993,10 @@ static void FUNCC(pred8x8l_horizontal_down)(uint8_t *_src, int has_topleft, int
SRC(6,0)= (t5 + 2*t4 + t3 + 2) >> 2;
SRC(7,0)= (t6 + 2*t5 + t4 + 2) >> 2;
}
-static void FUNCC(pred8x8l_vertical_left)(uint8_t *_src, int has_topleft, int has_topright, int _stride)
+static void FUNCC(pred8x8l_vertical_left)(uint8_t *p_src, int has_topleft, int has_topright, int p_stride)
{
- pixel *src = (pixel*)_src;
- int stride = _stride/sizeof(pixel);
+ pixel *src = (pixel*)p_src;
+ int stride = p_stride>>(sizeof(pixel)-1);
PREDICT_8x8_LOAD_TOP;
PREDICT_8x8_LOAD_TOPRIGHT;
SRC(0,0)= (t0 + t1 + 1) >> 1;
@@ -862,10 +1022,10 @@ static void FUNCC(pred8x8l_vertical_left)(uint8_t *_src, int has_topleft, int ha
SRC(7,6)= (t10 + t11 + 1) >> 1;
SRC(7,7)= (t10 + 2*t11 + t12 + 2) >> 2;
}
-static void FUNCC(pred8x8l_horizontal_up)(uint8_t *_src, int has_topleft, int has_topright, int _stride)
+static void FUNCC(pred8x8l_horizontal_up)(uint8_t *p_src, int has_topleft, int has_topright, int p_stride)
{
- pixel *src = (pixel*)_src;
- int stride = _stride/sizeof(pixel);
+ pixel *src = (pixel*)p_src;
+ int stride = p_stride>>(sizeof(pixel)-1);
PREDICT_8x8_LOAD_LEFT;
SRC(0,0)= (l0 + l1 + 1) >> 1;
SRC(1,0)= (l0 + 2*l1 + l2 + 2) >> 2;
@@ -896,11 +1056,11 @@ static void FUNCC(pred8x8l_horizontal_up)(uint8_t *_src, int has_topleft, int ha
#undef PL
#undef SRC
-static void FUNCC(pred4x4_vertical_add)(uint8_t *_pix, const DCTELEM *_block, int stride){
+static void FUNCC(pred4x4_vertical_add)(uint8_t *p_pix, const DCTELEM *p_block, int stride){
int i;
- pixel *pix = (pixel*)_pix;
- const dctcoef *block = (const dctcoef*)_block;
- stride /= sizeof(pixel);
+ pixel *pix = (pixel*)p_pix;
+ const dctcoef *block = (const dctcoef*)p_block;
+ stride >>= sizeof(pixel)-1;
pix -= stride;
for(i=0; i<4; i++){
pixel v = pix[0];
@@ -913,11 +1073,11 @@ static void FUNCC(pred4x4_vertical_add)(uint8_t *_pix, const DCTELEM *_block, in
}
}
-static void FUNCC(pred4x4_horizontal_add)(uint8_t *_pix, const DCTELEM *_block, int stride){
+static void FUNCC(pred4x4_horizontal_add)(uint8_t *p_pix, const DCTELEM *p_block, int stride){
int i;
- pixel *pix = (pixel*)_pix;
- const dctcoef *block = (const dctcoef*)_block;
- stride /= sizeof(pixel);
+ pixel *pix = (pixel*)p_pix;
+ const dctcoef *block = (const dctcoef*)p_block;
+ stride >>= sizeof(pixel)-1;
for(i=0; i<4; i++){
pixel v = pix[-1];
pix[0]= v += block[0];
@@ -929,11 +1089,11 @@ static void FUNCC(pred4x4_horizontal_add)(uint8_t *_pix, const DCTELEM *_block,
}
}
-static void FUNCC(pred8x8l_vertical_add)(uint8_t *_pix, const DCTELEM *_block, int stride){
+static void FUNCC(pred8x8l_vertical_add)(uint8_t *p_pix, const DCTELEM *p_block, int stride){
int i;
- pixel *pix = (pixel*)_pix;
- const dctcoef *block = (const dctcoef*)_block;
- stride /= sizeof(pixel);
+ pixel *pix = (pixel*)p_pix;
+ const dctcoef *block = (const dctcoef*)p_block;
+ stride >>= sizeof(pixel)-1;
pix -= stride;
for(i=0; i<8; i++){
pixel v = pix[0];
@@ -950,11 +1110,11 @@ static void FUNCC(pred8x8l_vertical_add)(uint8_t *_pix, const DCTELEM *_block, i
}
}
-static void FUNCC(pred8x8l_horizontal_add)(uint8_t *_pix, const DCTELEM *_block, int stride){
+static void FUNCC(pred8x8l_horizontal_add)(uint8_t *p_pix, const DCTELEM *p_block, int stride){
int i;
- pixel *pix = (pixel*)_pix;
- const dctcoef *block = (const dctcoef*)_block;
- stride /= sizeof(pixel);
+ pixel *pix = (pixel*)p_pix;
+ const dctcoef *block = (const dctcoef*)p_block;
+ stride >>= sizeof(pixel)-1;
for(i=0; i<8; i++){
pixel v = pix[-1];
pix[0]= v += block[0];
@@ -988,8 +1148,24 @@ static void FUNCC(pred8x8_vertical_add)(uint8_t *pix, const int *block_offset, c
FUNCC(pred4x4_vertical_add)(pix + block_offset[i], block + i*16*sizeof(pixel), stride);
}
+static void FUNCC(pred8x16_vertical_add)(uint8_t *pix, const int *block_offset, const DCTELEM *block, int stride){
+ int i;
+ for(i=0; i<4; i++)
+ FUNCC(pred4x4_vertical_add)(pix + block_offset[i], block + i*16*sizeof(pixel), stride);
+ for(i=4; i<8; i++)
+ FUNCC(pred4x4_vertical_add)(pix + block_offset[i+4], block + i*16*sizeof(pixel), stride);
+}
+
static void FUNCC(pred8x8_horizontal_add)(uint8_t *pix, const int *block_offset, const DCTELEM *block, int stride){
int i;
for(i=0; i<4; i++)
FUNCC(pred4x4_horizontal_add)(pix + block_offset[i], block + i*16*sizeof(pixel), stride);
}
+
+static void FUNCC(pred8x16_horizontal_add)(uint8_t *pix, const int *block_offset, const DCTELEM *block, int stride){
+ int i;
+ for(i=0; i<4; i++)
+ FUNCC(pred4x4_horizontal_add)(pix + block_offset[i], block + i*16*sizeof(pixel), stride);
+ for(i=4; i<8; i++)
+ FUNCC(pred4x4_horizontal_add)(pix + block_offset[i+4], block + i*16*sizeof(pixel), stride);
+}
diff --git a/libavcodec/huffman.c b/libavcodec/huffman.c
index 211ea63750..7b33bdd7f3 100644
--- a/libavcodec/huffman.c
+++ b/libavcodec/huffman.c
@@ -1,25 +1,28 @@
-/**
- * @file
- * huffman tree builder and VLC generator
+/*
* Copyright (c) 2006 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+/**
+ * @file
+ * huffman tree builder and VLC generator
+ */
+
#include "avcodec.h"
#include "get_bits.h"
#include "huffman.h"
diff --git a/libavcodec/huffman.h b/libavcodec/huffman.h
index 4a60187b3c..5e0787a5e8 100644
--- a/libavcodec/huffman.h
+++ b/libavcodec/huffman.h
@@ -1,25 +1,28 @@
-/**
- * @file
- * huffman tree builder and VLC generator
+/*
* Copyright (C) 2007 Aurelien Jacobs <aurel@gnuage.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+/**
+ * @file
+ * huffman tree builder and VLC generator
+ */
+
#ifndef AVCODEC_HUFFMAN_H
#define AVCODEC_HUFFMAN_H
diff --git a/libavcodec/huffyuv.c b/libavcodec/huffyuv.c
index a399142d59..b7a79a857b 100644
--- a/libavcodec/huffyuv.c
+++ b/libavcodec/huffyuv.c
@@ -6,20 +6,20 @@
* see http://www.pcisys.net/~melanson/codecs/huffyuv.txt for a description of
* the algorithm used
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -433,6 +433,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
memset(s->vlc, 0, 3*sizeof(VLC));
avctx->coded_frame= &s->picture;
+ avcodec_get_frame_defaults(&s->picture);
s->interlaced= s->height > 288;
s->bgr32=1;
@@ -1435,16 +1436,14 @@ static av_cold int encode_end(AVCodecContext *avctx)
#if CONFIG_HUFFYUV_DECODER
AVCodec ff_huffyuv_decoder = {
- "huffyuv",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_HUFFYUV,
- sizeof(HYuvContext),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- CODEC_CAP_DR1 | CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_FRAME_THREADS,
- NULL,
+ .name = "huffyuv",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_HUFFYUV,
+ .priv_data_size = sizeof(HYuvContext),
+ .init = decode_init,
+ .close = decode_end,
+ .decode = decode_frame,
+ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_FRAME_THREADS,
.init_thread_copy = ONLY_IF_THREADS_ENABLED(decode_init_thread_copy),
.long_name = NULL_IF_CONFIG_SMALL("Huffyuv / HuffYUV"),
};
@@ -1452,16 +1451,14 @@ AVCodec ff_huffyuv_decoder = {
#if CONFIG_FFVHUFF_DECODER
AVCodec ff_ffvhuff_decoder = {
- "ffvhuff",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_FFVHUFF,
- sizeof(HYuvContext),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- CODEC_CAP_DR1 | CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_FRAME_THREADS,
- NULL,
+ .name = "ffvhuff",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_FFVHUFF,
+ .priv_data_size = sizeof(HYuvContext),
+ .init = decode_init,
+ .close = decode_end,
+ .decode = decode_frame,
+ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_FRAME_THREADS,
.init_thread_copy = ONLY_IF_THREADS_ENABLED(decode_init_thread_copy),
.long_name = NULL_IF_CONFIG_SMALL("Huffyuv FFmpeg variant"),
};
@@ -1469,13 +1466,13 @@ AVCodec ff_ffvhuff_decoder = {
#if CONFIG_HUFFYUV_ENCODER
AVCodec ff_huffyuv_encoder = {
- "huffyuv",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_HUFFYUV,
- sizeof(HYuvContext),
- encode_init,
- encode_frame,
- encode_end,
+ .name = "huffyuv",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_HUFFYUV,
+ .priv_data_size = sizeof(HYuvContext),
+ .init = encode_init,
+ .encode = encode_frame,
+ .close = encode_end,
.pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV422P, PIX_FMT_RGB32, PIX_FMT_NONE},
.long_name = NULL_IF_CONFIG_SMALL("Huffyuv / HuffYUV"),
};
@@ -1483,13 +1480,13 @@ AVCodec ff_huffyuv_encoder = {
#if CONFIG_FFVHUFF_ENCODER
AVCodec ff_ffvhuff_encoder = {
- "ffvhuff",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_FFVHUFF,
- sizeof(HYuvContext),
- encode_init,
- encode_frame,
- encode_end,
+ .name = "ffvhuff",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_FFVHUFF,
+ .priv_data_size = sizeof(HYuvContext),
+ .init = encode_init,
+ .encode = encode_frame,
+ .close = encode_end,
.pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_YUV422P, PIX_FMT_RGB32, PIX_FMT_NONE},
.long_name = NULL_IF_CONFIG_SMALL("Huffyuv FFmpeg variant"),
};
diff --git a/libavcodec/idcinvideo.c b/libavcodec/idcinvideo.c
index ac56e19442..c47dc303bf 100644
--- a/libavcodec/idcinvideo.c
+++ b/libavcodec/idcinvideo.c
@@ -2,20 +2,20 @@
* id Quake II CIN Video Decoder
* Copyright (C) 2003 the ffmpeg project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -166,6 +166,7 @@ static av_cold int idcin_decode_init(AVCodecContext *avctx)
huff_build_tree(s, i);
}
+ avcodec_get_frame_defaults(&s->frame);
s->frame.data[0] = NULL;
return 0;
@@ -254,15 +255,14 @@ static av_cold int idcin_decode_end(AVCodecContext *avctx)
}
AVCodec ff_idcin_decoder = {
- "idcinvideo",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_IDCIN,
- sizeof(IdcinContext),
- idcin_decode_init,
- NULL,
- idcin_decode_end,
- idcin_decode_frame,
- CODEC_CAP_DR1,
+ .name = "idcinvideo",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_IDCIN,
+ .priv_data_size = sizeof(IdcinContext),
+ .init = idcin_decode_init,
+ .close = idcin_decode_end,
+ .decode = idcin_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("id Quake II CIN video"),
};
diff --git a/libavcodec/iff.c b/libavcodec/iff.c
index 63e1f31a4e..31aa6f0947 100644
--- a/libavcodec/iff.c
+++ b/libavcodec/iff.c
@@ -3,20 +3,20 @@
* Copyright (c) 2010 Peter Ross <pross@xvid.org>
* Copyright (c) 2010 Sebastian Vater <cdgs.basty@googlemail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -30,10 +30,26 @@
#include "avcodec.h"
#include "get_bits.h"
+// TODO: masking bits
+typedef enum {
+ MASK_NONE,
+ MASK_HAS_MASK,
+ MASK_HAS_TRANSPARENT_COLOR,
+ MASK_LASSO
+} mask_type;
+
typedef struct {
AVFrame frame;
int planesize;
uint8_t * planebuf;
+ uint8_t * ham_buf; ///< temporary buffer for planar to chunky conversation
+ uint32_t *ham_palbuf; ///< HAM decode table
+ unsigned compression; ///< delta compression method used
+ unsigned bpp; ///< bits per plane to decode (differs from bits_per_coded_sample if HAM)
+ unsigned ham; ///< 0 if non-HAM or number of hold bits (6 for bpp > 6, 4 otherwise)
+ unsigned flags; ///< 1 for EHB, 0 is no extra half darkening
+ unsigned transparency; ///< TODO: transparency color index in palette
+ unsigned masking; ///< TODO: masking method used
int init; // 1 if buffer and palette data already initialized, 0 otherwise
} IffContext;
@@ -122,6 +138,8 @@ static av_always_inline uint32_t gray2rgb(const uint32_t x) {
static int ff_cmap_read_palette(AVCodecContext *avctx, uint32_t *pal)
{
int count, i;
+ const uint8_t *const palette = avctx->extradata + AV_RB16(avctx->extradata);
+ int palette_size = avctx->extradata_size - AV_RB16(avctx->extradata);
if (avctx->bits_per_coded_sample > 8) {
av_log(avctx, AV_LOG_ERROR, "bit_per_coded_sample > 8 not supported\n");
@@ -130,10 +148,10 @@ static int ff_cmap_read_palette(AVCodecContext *avctx, uint32_t *pal)
count = 1 << avctx->bits_per_coded_sample;
// If extradata is smaller than actually needed, fill the remaining with black.
- count = FFMIN(avctx->extradata_size / 3, count);
+ count = FFMIN(palette_size / 3, count);
if (count) {
for (i=0; i < count; i++) {
- pal[i] = 0xFF000000 | AV_RB24( avctx->extradata + i*3 );
+ pal[i] = 0xFF000000 | AV_RB24(palette + i*3);
}
} else { // Create gray-scale color palette for bps < 8
count = 1 << avctx->bits_per_coded_sample;
@@ -145,15 +163,127 @@ static int ff_cmap_read_palette(AVCodecContext *avctx, uint32_t *pal)
return 0;
}
+/**
+ * Extracts the IFF extra context and updates internal
+ * decoder structures.
+ *
+ * @param avctx the AVCodecContext where to extract extra context to
+ * @param avpkt the AVPacket to extract extra context from or NULL to use avctx
+ * @return 0 in case of success, a negative error code otherwise
+ */
+static int extract_header(AVCodecContext *const avctx,
+ const AVPacket *const avpkt) {
+ const uint8_t *buf;
+ unsigned buf_size;
+ IffContext *s = avctx->priv_data;
+ int palette_size = avctx->extradata_size - AV_RB16(avctx->extradata);
+
+ if (avpkt) {
+ int image_size;
+ if (avpkt->size < 2)
+ return AVERROR_INVALIDDATA;
+ image_size = avpkt->size - AV_RB16(avpkt->data);
+ buf = avpkt->data;
+ buf_size = bytestream_get_be16(&buf);
+ if (buf_size <= 1 || image_size <= 1) {
+ av_log(avctx, AV_LOG_ERROR,
+ "Invalid image size received: %u -> image data offset: %d\n",
+ buf_size, image_size);
+ return AVERROR_INVALIDDATA;
+ }
+ } else {
+ if (avctx->extradata_size < 2)
+ return AVERROR_INVALIDDATA;
+ buf = avctx->extradata;
+ buf_size = bytestream_get_be16(&buf);
+ if (buf_size <= 1 || palette_size < 0) {
+ av_log(avctx, AV_LOG_ERROR,
+ "Invalid palette size received: %u -> palette data offset: %d\n",
+ buf_size, palette_size);
+ return AVERROR_INVALIDDATA;
+ }
+ }
+
+ if (buf_size > 8) {
+ s->compression = bytestream_get_byte(&buf);
+ s->bpp = bytestream_get_byte(&buf);
+ s->ham = bytestream_get_byte(&buf);
+ s->flags = bytestream_get_byte(&buf);
+ s->transparency = bytestream_get_be16(&buf);
+ s->masking = bytestream_get_byte(&buf);
+ if (s->masking == MASK_HAS_TRANSPARENT_COLOR) {
+ av_log(avctx, AV_LOG_ERROR, "Transparency not supported\n");
+ return AVERROR_PATCHWELCOME;
+ } else if (s->masking != MASK_NONE) {
+ av_log(avctx, AV_LOG_ERROR, "Masking not supported\n");
+ return AVERROR_PATCHWELCOME;
+ }
+ if (!s->bpp || s->bpp > 32) {
+ av_log(avctx, AV_LOG_ERROR, "Invalid number of bitplanes: %u\n", s->bpp);
+ return AVERROR_INVALIDDATA;
+ } else if (s->ham >= 8) {
+ av_log(avctx, AV_LOG_ERROR, "Invalid number of hold bits for HAM: %u\n", s->ham);
+ return AVERROR_INVALIDDATA;
+ }
+
+ av_freep(&s->ham_buf);
+ av_freep(&s->ham_palbuf);
+
+ if (s->ham) {
+ int i, count = FFMIN(palette_size / 3, 1 << s->ham);
+ const uint8_t *const palette = avctx->extradata + AV_RB16(avctx->extradata);
+ s->ham_buf = av_malloc((s->planesize * 8) + FF_INPUT_BUFFER_PADDING_SIZE);
+ if (!s->ham_buf)
+ return AVERROR(ENOMEM);
+
+ s->ham_palbuf = av_malloc((8 * (1 << s->ham) * sizeof (uint32_t)) + FF_INPUT_BUFFER_PADDING_SIZE);
+ if (!s->ham_palbuf) {
+ av_freep(&s->ham_buf);
+ return AVERROR(ENOMEM);
+ }
+
+ if (count) { // HAM with color palette attached
+ // prefill with black and palette and set HAM take direct value mask to zero
+ memset(s->ham_palbuf, 0, (1 << s->ham) * 2 * sizeof (uint32_t));
+ for (i=0; i < count; i++) {
+ s->ham_palbuf[i*2+1] = AV_RL24(palette + i*3);
+ }
+ count = 1 << s->ham;
+ } else { // HAM with grayscale color palette
+ count = 1 << s->ham;
+ for (i=0; i < count; i++) {
+ s->ham_palbuf[i*2] = 0; // take direct color value from palette
+ s->ham_palbuf[i*2+1] = av_le2ne32(gray2rgb((i * 255) >> s->ham));
+ }
+ }
+ for (i=0; i < count; i++) {
+ uint32_t tmp = i << (8 - s->ham);
+ tmp |= tmp >> s->ham;
+ s->ham_palbuf[(i+count)*2] = 0x00FFFF; // just modify blue color component
+ s->ham_palbuf[(i+count*2)*2] = 0xFFFF00; // just modify red color component
+ s->ham_palbuf[(i+count*3)*2] = 0xFF00FF; // just modify green color component
+ s->ham_palbuf[(i+count)*2+1] = tmp << 16;
+ s->ham_palbuf[(i+count*2)*2+1] = tmp;
+ s->ham_palbuf[(i+count*3)*2+1] = tmp << 8;
+ }
+ } else if (s->flags & 1) { // EHB (ExtraHalfBrite) color palette
+ av_log(avctx, AV_LOG_ERROR, "ExtraHalfBrite (EHB) mode not supported\n");
+ return AVERROR_PATCHWELCOME;
+ }
+ }
+
+ return 0;
+}
+
static av_cold int decode_init(AVCodecContext *avctx)
{
IffContext *s = avctx->priv_data;
int err;
if (avctx->bits_per_coded_sample <= 8) {
- avctx->pix_fmt = (avctx->bits_per_coded_sample < 8 ||
- avctx->extradata_size) ? PIX_FMT_PAL8
- : PIX_FMT_GRAY8;
+ int palette_size = avctx->extradata_size - AV_RB16(avctx->extradata);
+ avctx->pix_fmt = (avctx->bits_per_coded_sample < 8) ||
+ (avctx->extradata_size >= 2 && palette_size) ? PIX_FMT_PAL8 : PIX_FMT_GRAY8;
} else if (avctx->bits_per_coded_sample <= 32) {
avctx->pix_fmt = PIX_FMT_BGR32;
} else {
@@ -167,6 +297,11 @@ static av_cold int decode_init(AVCodecContext *avctx)
if (!s->planebuf)
return AVERROR(ENOMEM);
+ s->bpp = avctx->bits_per_coded_sample;
+ avcodec_get_frame_defaults(&s->frame);
+
+ if ((err = extract_header(avctx, NULL)) < 0)
+ return err;
s->frame.reference = 1;
return 0;
@@ -214,6 +349,39 @@ static void decodeplane32(uint32_t *dst, const uint8_t *buf, int buf_size, int p
} while (--buf_size);
}
+#define DECODE_HAM_PLANE32(x) \
+ first = buf[x] << 1; \
+ second = buf[(x)+1] << 1; \
+ delta &= pal[first++]; \
+ delta |= pal[first]; \
+ dst[x] = delta; \
+ delta &= pal[second++]; \
+ delta |= pal[second]; \
+ dst[(x)+1] = delta
+
+/**
+ * Converts one line of HAM6/8-encoded chunky buffer to 24bpp.
+ *
+ * @param dst the destination 24bpp buffer
+ * @param buf the source 8bpp chunky buffer
+ * @param pal the HAM decode table
+ * @param buf_size the plane size in bytes
+ */
+static void decode_ham_plane32(uint32_t *dst, const uint8_t *buf,
+ const uint32_t *const pal, unsigned buf_size)
+{
+ uint32_t delta = 0;
+ do {
+ uint32_t first, second;
+ DECODE_HAM_PLANE32(0);
+ DECODE_HAM_PLANE32(2);
+ DECODE_HAM_PLANE32(4);
+ DECODE_HAM_PLANE32(6);
+ buf += 8;
+ dst += 8;
+ } while (--buf_size);
+}
+
/**
* Decode one complete byterun1 encoded line.
*
@@ -250,11 +418,14 @@ static int decode_frame_ilbm(AVCodecContext *avctx,
AVPacket *avpkt)
{
IffContext *s = avctx->priv_data;
- const uint8_t *buf = avpkt->data;
- int buf_size = avpkt->size;
+ const uint8_t *buf = avpkt->size >= 2 ? avpkt->data + AV_RB16(avpkt->data) : NULL;
+ const int buf_size = avpkt->size >= 2 ? avpkt->size - AV_RB16(avpkt->data) : 0;
const uint8_t *buf_end = buf+buf_size;
int y, plane, res;
+ if ((res = extract_header(avctx, avpkt)) < 0)
+ return res;
+
if (s->init) {
if ((res = avctx->reget_buffer(avctx, &s->frame)) < 0) {
av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
@@ -274,16 +445,26 @@ static int decode_frame_ilbm(AVCodecContext *avctx,
for(y = 0; y < avctx->height; y++ ) {
uint8_t *row = &s->frame.data[0][ y*s->frame.linesize[0] ];
memset(row, 0, avctx->width);
- for (plane = 0; plane < avctx->bits_per_coded_sample && buf < buf_end; plane++) {
+ for (plane = 0; plane < s->bpp && buf < buf_end; plane++) {
decodeplane8(row, buf, FFMIN(s->planesize, buf_end - buf), plane);
buf += s->planesize;
}
}
+ } else if (s->ham) { // HAM to PIX_FMT_BGR32
+ for (y = 0; y < avctx->height; y++) {
+ uint8_t *row = &s->frame.data[0][ y*s->frame.linesize[0] ];
+ memset(s->ham_buf, 0, avctx->width);
+ for (plane = 0; plane < s->bpp && buf < buf_end; plane++) {
+ decodeplane8(s->ham_buf, buf, FFMIN(s->planesize, buf_end - buf), plane);
+ buf += s->planesize;
+ }
+ decode_ham_plane32((uint32_t *) row, s->ham_buf, s->ham_palbuf, s->planesize);
+ }
} else { // PIX_FMT_BGR32
for(y = 0; y < avctx->height; y++ ) {
uint8_t *row = &s->frame.data[0][y*s->frame.linesize[0]];
memset(row, 0, avctx->width << 2);
- for (plane = 0; plane < avctx->bits_per_coded_sample && buf < buf_end; plane++) {
+ for (plane = 0; plane < s->bpp && buf < buf_end; plane++) {
decodeplane32((uint32_t *) row, buf, FFMIN(s->planesize, buf_end - buf), plane);
buf += s->planesize;
}
@@ -295,6 +476,13 @@ static int decode_frame_ilbm(AVCodecContext *avctx,
memcpy(row, buf, FFMIN(avctx->width, buf_end - buf));
buf += avctx->width + (avctx->width % 2); // padding if odd
}
+ } else { // IFF-PBM: HAM to PIX_FMT_BGR32
+ for (y = 0; y < avctx->height; y++) {
+ uint8_t *row = &s->frame.data[0][ y*s->frame.linesize[0] ];
+ memcpy(s->ham_buf, buf, FFMIN(avctx->width, buf_end - buf));
+ buf += avctx->width + (avctx->width & 1); // padding if odd
+ decode_ham_plane32((uint32_t *) row, s->ham_buf, s->ham_palbuf, avctx->width);
+ }
}
*data_size = sizeof(AVFrame);
@@ -307,11 +495,13 @@ static int decode_frame_byterun1(AVCodecContext *avctx,
AVPacket *avpkt)
{
IffContext *s = avctx->priv_data;
- const uint8_t *buf = avpkt->data;
- int buf_size = avpkt->size;
+ const uint8_t *buf = avpkt->size >= 2 ? avpkt->data + AV_RB16(avpkt->data) : NULL;
+ const int buf_size = avpkt->size >= 2 ? avpkt->size - AV_RB16(avpkt->data) : 0;
const uint8_t *buf_end = buf+buf_size;
int y, plane, res;
+ if ((res = extract_header(avctx, avpkt)) < 0)
+ return res;
if (s->init) {
if ((res = avctx->reget_buffer(avctx, &s->frame)) < 0) {
av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
@@ -331,26 +521,42 @@ static int decode_frame_byterun1(AVCodecContext *avctx,
for(y = 0; y < avctx->height ; y++ ) {
uint8_t *row = &s->frame.data[0][ y*s->frame.linesize[0] ];
memset(row, 0, avctx->width);
- for (plane = 0; plane < avctx->bits_per_coded_sample; plane++) {
+ for (plane = 0; plane < s->bpp; plane++) {
buf += decode_byterun(s->planebuf, s->planesize, buf, buf_end);
decodeplane8(row, s->planebuf, s->planesize, plane);
}
}
+ } else if (s->ham) { // HAM to PIX_FMT_BGR32
+ for (y = 0; y < avctx->height ; y++) {
+ uint8_t *row = &s->frame.data[0][y*s->frame.linesize[0]];
+ memset(s->ham_buf, 0, avctx->width);
+ for (plane = 0; plane < s->bpp; plane++) {
+ buf += decode_byterun(s->planebuf, s->planesize, buf, buf_end);
+ decodeplane8(s->ham_buf, s->planebuf, s->planesize, plane);
+ }
+ decode_ham_plane32((uint32_t *) row, s->ham_buf, s->ham_palbuf, s->planesize);
+ }
} else { //PIX_FMT_BGR32
for(y = 0; y < avctx->height ; y++ ) {
uint8_t *row = &s->frame.data[0][y*s->frame.linesize[0]];
memset(row, 0, avctx->width << 2);
- for (plane = 0; plane < avctx->bits_per_coded_sample; plane++) {
+ for (plane = 0; plane < s->bpp; plane++) {
buf += decode_byterun(s->planebuf, s->planesize, buf, buf_end);
decodeplane32((uint32_t *) row, s->planebuf, s->planesize, plane);
}
}
}
- } else {
+ } else if (avctx->pix_fmt == PIX_FMT_PAL8 || avctx->pix_fmt == PIX_FMT_GRAY8) { // IFF-PBM
for(y = 0; y < avctx->height ; y++ ) {
uint8_t *row = &s->frame.data[0][y*s->frame.linesize[0]];
buf += decode_byterun(row, avctx->width, buf, buf_end);
}
+ } else { // IFF-PBM: HAM to PIX_FMT_BGR32
+ for (y = 0; y < avctx->height ; y++) {
+ uint8_t *row = &s->frame.data[0][y*s->frame.linesize[0]];
+ buf += decode_byterun(s->ham_buf, avctx->width, buf, buf_end);
+ decode_ham_plane32((uint32_t *) row, s->ham_buf, s->ham_palbuf, avctx->width);
+ }
}
*data_size = sizeof(AVFrame);
@@ -364,31 +570,31 @@ static av_cold int decode_end(AVCodecContext *avctx)
if (s->frame.data[0])
avctx->release_buffer(avctx, &s->frame);
av_freep(&s->planebuf);
+ av_freep(&s->ham_buf);
+ av_freep(&s->ham_palbuf);
return 0;
}
AVCodec ff_iff_ilbm_decoder = {
- "iff_ilbm",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_IFF_ILBM,
- sizeof(IffContext),
- decode_init,
- NULL,
- decode_end,
- decode_frame_ilbm,
- CODEC_CAP_DR1,
+ .name = "iff_ilbm",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_IFF_ILBM,
+ .priv_data_size = sizeof(IffContext),
+ .init = decode_init,
+ .close = decode_end,
+ .decode = decode_frame_ilbm,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("IFF ILBM"),
};
AVCodec ff_iff_byterun1_decoder = {
- "iff_byterun1",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_IFF_BYTERUN1,
- sizeof(IffContext),
- decode_init,
- NULL,
- decode_end,
- decode_frame_byterun1,
- CODEC_CAP_DR1,
+ .name = "iff_byterun1",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_IFF_BYTERUN1,
+ .priv_data_size = sizeof(IffContext),
+ .init = decode_init,
+ .close = decode_end,
+ .decode = decode_frame_byterun1,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("IFF ByteRun1"),
};
diff --git a/libavcodec/iirfilter.c b/libavcodec/iirfilter.c
index 34d3962807..4785a7c7c2 100644
--- a/libavcodec/iirfilter.c
+++ b/libavcodec/iirfilter.c
@@ -2,20 +2,20 @@
* IIR filter
* Copyright (c) 2008 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/iirfilter.h b/libavcodec/iirfilter.h
index bc65a96b59..b29e035811 100644
--- a/libavcodec/iirfilter.h
+++ b/libavcodec/iirfilter.h
@@ -2,20 +2,20 @@
* IIR filter
* Copyright (c) 2008 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/imc.c b/libavcodec/imc.c
index 07d6cadcfd..f08efe46ec 100644
--- a/libavcodec/imc.c
+++ b/libavcodec/imc.c
@@ -4,20 +4,20 @@
* Copyright (c) 2006 Benjamin Larsson
* Copyright (c) 2006 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/imcdata.h b/libavcodec/imcdata.h
index 8e99391d61..64e7c7185e 100644
--- a/libavcodec/imcdata.h
+++ b/libavcodec/imcdata.h
@@ -4,20 +4,20 @@
* Copyright (c) 2006 Benjamin Larsson
* Copyright (c) 2006 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/imgconvert.c b/libavcodec/imgconvert.c
index 351ed7ada7..2279875db2 100644
--- a/libavcodec/imgconvert.c
+++ b/libavcodec/imgconvert.c
@@ -2,20 +2,20 @@
* Misc image conversion routines
* Copyright (c) 2001, 2002, 2003 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -42,18 +42,11 @@
#include "x86/dsputil_mmx.h"
#endif
-#define xglue(x, y) x ## y
-#define glue(x, y) xglue(x, y)
-
#define FF_COLOR_RGB 0 /**< RGB color space */
#define FF_COLOR_GRAY 1 /**< gray color space */
#define FF_COLOR_YUV 2 /**< YUV color space. 16 <= Y <= 235, 16 <= U, V <= 240 */
#define FF_COLOR_YUV_JPEG 3 /**< YUV color space. 0 <= Y <= 255, 0 <= U, V <= 255 */
-#define FF_PIXEL_PLANAR 0 /**< each channel has one component in AVPicture */
-#define FF_PIXEL_PACKED 1 /**< only one components containing all the channels */
-#define FF_PIXEL_PALETTE 2 /**< one components containing indexes for a palette */
-
#if HAVE_MMX && HAVE_YASM
#define deinterlace_line_inplace ff_deinterlace_line_inplace_mmx
#define deinterlace_line ff_deinterlace_line_mmx
@@ -63,351 +56,225 @@
#endif
typedef struct PixFmtInfo {
- uint8_t nb_channels; /**< number of channels (including alpha) */
uint8_t color_type; /**< color type (see FF_COLOR_xxx constants) */
- uint8_t pixel_type; /**< pixel storage type (see FF_PIXEL_xxx constants) */
uint8_t is_alpha : 1; /**< true if alpha can be specified */
- uint8_t depth; /**< bit depth of the color components */
+ uint8_t padded_size; /**< padded size in bits if different from the non-padded size */
} PixFmtInfo;
/* this table gives more information about formats */
static const PixFmtInfo pix_fmt_info[PIX_FMT_NB] = {
/* YUV formats */
[PIX_FMT_YUV420P] = {
- .nb_channels = 3,
.color_type = FF_COLOR_YUV,
- .pixel_type = FF_PIXEL_PLANAR,
- .depth = 8,
},
[PIX_FMT_YUV422P] = {
- .nb_channels = 3,
.color_type = FF_COLOR_YUV,
- .pixel_type = FF_PIXEL_PLANAR,
- .depth = 8,
},
[PIX_FMT_YUV444P] = {
- .nb_channels = 3,
.color_type = FF_COLOR_YUV,
- .pixel_type = FF_PIXEL_PLANAR,
- .depth = 8,
},
[PIX_FMT_YUYV422] = {
- .nb_channels = 1,
.color_type = FF_COLOR_YUV,
- .pixel_type = FF_PIXEL_PACKED,
- .depth = 8,
},
[PIX_FMT_UYVY422] = {
- .nb_channels = 1,
.color_type = FF_COLOR_YUV,
- .pixel_type = FF_PIXEL_PACKED,
- .depth = 8,
},
[PIX_FMT_YUV410P] = {
- .nb_channels = 3,
.color_type = FF_COLOR_YUV,
- .pixel_type = FF_PIXEL_PLANAR,
- .depth = 8,
},
[PIX_FMT_YUV411P] = {
- .nb_channels = 3,
.color_type = FF_COLOR_YUV,
- .pixel_type = FF_PIXEL_PLANAR,
- .depth = 8,
},
[PIX_FMT_YUV440P] = {
- .nb_channels = 3,
.color_type = FF_COLOR_YUV,
- .pixel_type = FF_PIXEL_PLANAR,
- .depth = 8,
},
[PIX_FMT_YUV420P16LE] = {
- .nb_channels = 3,
.color_type = FF_COLOR_YUV,
- .pixel_type = FF_PIXEL_PLANAR,
- .depth = 16,
},
[PIX_FMT_YUV422P16LE] = {
- .nb_channels = 3,
.color_type = FF_COLOR_YUV,
- .pixel_type = FF_PIXEL_PLANAR,
- .depth = 16,
},
[PIX_FMT_YUV444P16LE] = {
- .nb_channels = 3,
.color_type = FF_COLOR_YUV,
- .pixel_type = FF_PIXEL_PLANAR,
- .depth = 16,
},
[PIX_FMT_YUV420P16BE] = {
- .nb_channels = 3,
.color_type = FF_COLOR_YUV,
- .pixel_type = FF_PIXEL_PLANAR,
- .depth = 16,
},
[PIX_FMT_YUV422P16BE] = {
- .nb_channels = 3,
.color_type = FF_COLOR_YUV,
- .pixel_type = FF_PIXEL_PLANAR,
- .depth = 16,
},
[PIX_FMT_YUV444P16BE] = {
- .nb_channels = 3,
.color_type = FF_COLOR_YUV,
- .pixel_type = FF_PIXEL_PLANAR,
- .depth = 16,
},
-
/* YUV formats with alpha plane */
[PIX_FMT_YUVA420P] = {
- .nb_channels = 4,
.color_type = FF_COLOR_YUV,
- .pixel_type = FF_PIXEL_PLANAR,
- .depth = 8,
},
/* JPEG YUV */
[PIX_FMT_YUVJ420P] = {
- .nb_channels = 3,
.color_type = FF_COLOR_YUV_JPEG,
- .pixel_type = FF_PIXEL_PLANAR,
- .depth = 8,
},
[PIX_FMT_YUVJ422P] = {
- .nb_channels = 3,
.color_type = FF_COLOR_YUV_JPEG,
- .pixel_type = FF_PIXEL_PLANAR,
- .depth = 8,
},
[PIX_FMT_YUVJ444P] = {
- .nb_channels = 3,
.color_type = FF_COLOR_YUV_JPEG,
- .pixel_type = FF_PIXEL_PLANAR,
- .depth = 8,
},
[PIX_FMT_YUVJ440P] = {
- .nb_channels = 3,
.color_type = FF_COLOR_YUV_JPEG,
- .pixel_type = FF_PIXEL_PLANAR,
- .depth = 8,
},
/* RGB formats */
[PIX_FMT_RGB24] = {
- .nb_channels = 3,
.color_type = FF_COLOR_RGB,
- .pixel_type = FF_PIXEL_PACKED,
- .depth = 8,
},
[PIX_FMT_BGR24] = {
- .nb_channels = 3,
.color_type = FF_COLOR_RGB,
- .pixel_type = FF_PIXEL_PACKED,
- .depth = 8,
},
[PIX_FMT_ARGB] = {
- .nb_channels = 4, .is_alpha = 1,
+ .is_alpha = 1,
.color_type = FF_COLOR_RGB,
- .pixel_type = FF_PIXEL_PACKED,
- .depth = 8,
},
[PIX_FMT_RGB48BE] = {
- .nb_channels = 3,
.color_type = FF_COLOR_RGB,
- .pixel_type = FF_PIXEL_PACKED,
- .depth = 16,
},
[PIX_FMT_RGB48LE] = {
- .nb_channels = 3,
.color_type = FF_COLOR_RGB,
- .pixel_type = FF_PIXEL_PACKED,
- .depth = 16,
+ },
+ [PIX_FMT_RGBA64BE] = {
+ .is_alpha = 1,
+ .color_type = FF_COLOR_RGB,
+ },
+ [PIX_FMT_RGBA64LE] = {
+ .is_alpha = 1,
+ .color_type = FF_COLOR_RGB,
},
[PIX_FMT_RGB565BE] = {
- .nb_channels = 3,
.color_type = FF_COLOR_RGB,
- .pixel_type = FF_PIXEL_PACKED,
- .depth = 5,
},
[PIX_FMT_RGB565LE] = {
- .nb_channels = 3,
.color_type = FF_COLOR_RGB,
- .pixel_type = FF_PIXEL_PACKED,
- .depth = 5,
},
[PIX_FMT_RGB555BE] = {
- .nb_channels = 3,
.color_type = FF_COLOR_RGB,
- .pixel_type = FF_PIXEL_PACKED,
- .depth = 5,
+ .padded_size = 16,
},
[PIX_FMT_RGB555LE] = {
- .nb_channels = 3,
.color_type = FF_COLOR_RGB,
- .pixel_type = FF_PIXEL_PACKED,
- .depth = 5,
+ .padded_size = 16,
},
[PIX_FMT_RGB444BE] = {
- .nb_channels = 3,
.color_type = FF_COLOR_RGB,
- .pixel_type = FF_PIXEL_PACKED,
- .depth = 4,
+ .padded_size = 16,
},
[PIX_FMT_RGB444LE] = {
- .nb_channels = 3,
.color_type = FF_COLOR_RGB,
- .pixel_type = FF_PIXEL_PACKED,
- .depth = 4,
+ .padded_size = 16,
},
/* gray / mono formats */
[PIX_FMT_GRAY16BE] = {
- .nb_channels = 1,
.color_type = FF_COLOR_GRAY,
- .pixel_type = FF_PIXEL_PLANAR,
- .depth = 16,
},
[PIX_FMT_GRAY16LE] = {
- .nb_channels = 1,
.color_type = FF_COLOR_GRAY,
- .pixel_type = FF_PIXEL_PLANAR,
- .depth = 16,
},
[PIX_FMT_GRAY8] = {
- .nb_channels = 1,
.color_type = FF_COLOR_GRAY,
- .pixel_type = FF_PIXEL_PLANAR,
- .depth = 8,
},
[PIX_FMT_MONOWHITE] = {
- .nb_channels = 1,
.color_type = FF_COLOR_GRAY,
- .pixel_type = FF_PIXEL_PLANAR,
- .depth = 1,
},
[PIX_FMT_MONOBLACK] = {
- .nb_channels = 1,
.color_type = FF_COLOR_GRAY,
- .pixel_type = FF_PIXEL_PLANAR,
- .depth = 1,
},
/* paletted formats */
[PIX_FMT_PAL8] = {
- .nb_channels = 4, .is_alpha = 1,
+ .is_alpha = 1,
.color_type = FF_COLOR_RGB,
- .pixel_type = FF_PIXEL_PALETTE,
- .depth = 8,
},
[PIX_FMT_UYYVYY411] = {
- .nb_channels = 1,
.color_type = FF_COLOR_YUV,
- .pixel_type = FF_PIXEL_PACKED,
- .depth = 8,
},
[PIX_FMT_ABGR] = {
- .nb_channels = 4, .is_alpha = 1,
+ .is_alpha = 1,
+ .color_type = FF_COLOR_RGB,
+ },
+ [PIX_FMT_BGR48BE] = {
+ .color_type = FF_COLOR_RGB,
+ },
+ [PIX_FMT_BGR48LE] = {
+ .color_type = FF_COLOR_RGB,
+ },
+ [PIX_FMT_BGRA64BE] = {
+ .is_alpha = 1,
+ .color_type = FF_COLOR_RGB,
+ },
+ [PIX_FMT_BGRA64LE] = {
+ .is_alpha = 1,
.color_type = FF_COLOR_RGB,
- .pixel_type = FF_PIXEL_PACKED,
- .depth = 8,
},
[PIX_FMT_BGR565BE] = {
- .nb_channels = 3,
.color_type = FF_COLOR_RGB,
- .pixel_type = FF_PIXEL_PACKED,
- .depth = 5,
+ .padded_size = 16,
},
[PIX_FMT_BGR565LE] = {
- .nb_channels = 3,
.color_type = FF_COLOR_RGB,
- .pixel_type = FF_PIXEL_PACKED,
- .depth = 5,
+ .padded_size = 16,
},
[PIX_FMT_BGR555BE] = {
- .nb_channels = 3,
.color_type = FF_COLOR_RGB,
- .pixel_type = FF_PIXEL_PACKED,
- .depth = 5,
+ .padded_size = 16,
},
[PIX_FMT_BGR555LE] = {
- .nb_channels = 3,
.color_type = FF_COLOR_RGB,
- .pixel_type = FF_PIXEL_PACKED,
- .depth = 5,
+ .padded_size = 16,
},
[PIX_FMT_BGR444BE] = {
- .nb_channels = 3,
.color_type = FF_COLOR_RGB,
- .pixel_type = FF_PIXEL_PACKED,
- .depth = 4,
+ .padded_size = 16,
},
[PIX_FMT_BGR444LE] = {
- .nb_channels = 3,
.color_type = FF_COLOR_RGB,
- .pixel_type = FF_PIXEL_PACKED,
- .depth = 4,
+ .padded_size = 16,
},
[PIX_FMT_RGB8] = {
- .nb_channels = 1,
.color_type = FF_COLOR_RGB,
- .pixel_type = FF_PIXEL_PACKED,
- .depth = 8,
},
[PIX_FMT_RGB4] = {
- .nb_channels = 1,
.color_type = FF_COLOR_RGB,
- .pixel_type = FF_PIXEL_PACKED,
- .depth = 4,
},
[PIX_FMT_RGB4_BYTE] = {
- .nb_channels = 1,
.color_type = FF_COLOR_RGB,
- .pixel_type = FF_PIXEL_PACKED,
- .depth = 8,
+ .padded_size = 8,
},
[PIX_FMT_BGR8] = {
- .nb_channels = 1,
.color_type = FF_COLOR_RGB,
- .pixel_type = FF_PIXEL_PACKED,
- .depth = 8,
},
[PIX_FMT_BGR4] = {
- .nb_channels = 1,
.color_type = FF_COLOR_RGB,
- .pixel_type = FF_PIXEL_PACKED,
- .depth = 4,
},
[PIX_FMT_BGR4_BYTE] = {
- .nb_channels = 1,
.color_type = FF_COLOR_RGB,
- .pixel_type = FF_PIXEL_PACKED,
- .depth = 8,
+ .padded_size = 8,
},
[PIX_FMT_NV12] = {
- .nb_channels = 2,
.color_type = FF_COLOR_YUV,
- .pixel_type = FF_PIXEL_PLANAR,
- .depth = 8,
},
[PIX_FMT_NV21] = {
- .nb_channels = 2,
.color_type = FF_COLOR_YUV,
- .pixel_type = FF_PIXEL_PLANAR,
- .depth = 8,
},
[PIX_FMT_BGRA] = {
- .nb_channels = 4, .is_alpha = 1,
+ .is_alpha = 1,
.color_type = FF_COLOR_RGB,
- .pixel_type = FF_PIXEL_PACKED,
- .depth = 8,
},
[PIX_FMT_RGBA] = {
- .nb_channels = 4, .is_alpha = 1,
+ .is_alpha = 1,
.color_type = FF_COLOR_RGB,
- .pixel_type = FF_PIXEL_PACKED,
- .depth = 8,
},
};
@@ -470,6 +337,16 @@ int avpicture_layout(const AVPicture* src, enum PixelFormat pix_fmt, int width,
}
}
+ switch (pix_fmt) {
+ case PIX_FMT_RGB8:
+ case PIX_FMT_BGR8:
+ case PIX_FMT_RGB4_BYTE:
+ case PIX_FMT_BGR4_BYTE:
+ case PIX_FMT_GRAY8:
+ // do not include palette for these pseudo-paletted formats
+ return size;
+ }
+
if (desc->flags & PIX_FMT_PAL)
memcpy((unsigned char *)(((size_t)dest + 3) & ~3), src->data[1], 256 * 4);
@@ -493,28 +370,55 @@ int avpicture_get_size(enum PixelFormat pix_fmt, int width, int height)
return avpicture_fill(&dummy_pict, NULL, pix_fmt, width, height);
}
+static int get_pix_fmt_depth(int *min, int *max, enum PixelFormat pix_fmt)
+{
+ const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt];
+ int i;
+
+ if (!desc->nb_components) {
+ *min = *max = 0;
+ return AVERROR(EINVAL);
+ }
+
+ *min = INT_MAX, *max = -INT_MAX;
+ for (i = 0; i < desc->nb_components; i++) {
+ *min = FFMIN(desc->comp[i].depth_minus1+1, *min);
+ *max = FFMAX(desc->comp[i].depth_minus1+1, *max);
+ }
+ return 0;
+}
+
int avcodec_get_pix_fmt_loss(enum PixelFormat dst_pix_fmt, enum PixelFormat src_pix_fmt,
int has_alpha)
{
const PixFmtInfo *pf, *ps;
- const AVPixFmtDescriptor *src_desc = &av_pix_fmt_descriptors[src_pix_fmt];
- const AVPixFmtDescriptor *dst_desc = &av_pix_fmt_descriptors[dst_pix_fmt];
- int loss;
+ const AVPixFmtDescriptor *src_desc;
+ const AVPixFmtDescriptor *dst_desc;
+ int src_min_depth, src_max_depth, dst_min_depth, dst_max_depth;
+ int ret, loss;
+
+ if (dst_pix_fmt >= PIX_FMT_NB || dst_pix_fmt <= PIX_FMT_NONE)
+ return ~0;
+ src_desc = &av_pix_fmt_descriptors[src_pix_fmt];
+ dst_desc = &av_pix_fmt_descriptors[dst_pix_fmt];
ps = &pix_fmt_info[src_pix_fmt];
/* compute loss */
loss = 0;
- pf = &pix_fmt_info[dst_pix_fmt];
- if (pf->depth < ps->depth ||
- ((dst_pix_fmt == PIX_FMT_RGB555BE || dst_pix_fmt == PIX_FMT_RGB555LE ||
- dst_pix_fmt == PIX_FMT_BGR555BE || dst_pix_fmt == PIX_FMT_BGR555LE) &&
- (src_pix_fmt == PIX_FMT_RGB565BE || src_pix_fmt == PIX_FMT_RGB565LE ||
- src_pix_fmt == PIX_FMT_BGR565BE || src_pix_fmt == PIX_FMT_BGR565LE)))
+
+ if ((ret = get_pix_fmt_depth(&src_min_depth, &src_max_depth, src_pix_fmt)) < 0)
+ return ret;
+ if ((ret = get_pix_fmt_depth(&dst_min_depth, &dst_max_depth, dst_pix_fmt)) < 0)
+ return ret;
+ if (dst_min_depth < src_min_depth ||
+ dst_max_depth < src_max_depth)
loss |= FF_LOSS_DEPTH;
if (dst_desc->log2_chroma_w > src_desc->log2_chroma_w ||
dst_desc->log2_chroma_h > src_desc->log2_chroma_h)
loss |= FF_LOSS_RESOLUTION;
+
+ pf = &pix_fmt_info[dst_pix_fmt];
switch(pf->color_type) {
case FF_COLOR_RGB:
if (ps->color_type != FF_COLOR_RGB &&
@@ -546,95 +450,43 @@ int avcodec_get_pix_fmt_loss(enum PixelFormat dst_pix_fmt, enum PixelFormat src_
loss |= FF_LOSS_CHROMA;
if (!pf->is_alpha && (ps->is_alpha && has_alpha))
loss |= FF_LOSS_ALPHA;
- if (pf->pixel_type == FF_PIXEL_PALETTE &&
- (ps->pixel_type != FF_PIXEL_PALETTE && ps->color_type != FF_COLOR_GRAY))
+ if (dst_pix_fmt == PIX_FMT_PAL8 &&
+ (src_pix_fmt != PIX_FMT_PAL8 && ps->color_type != FF_COLOR_GRAY))
loss |= FF_LOSS_COLORQUANT;
return loss;
}
static int avg_bits_per_pixel(enum PixelFormat pix_fmt)
{
- int bits;
- const PixFmtInfo *pf;
+ const PixFmtInfo *info = &pix_fmt_info[pix_fmt];
const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt];
- pf = &pix_fmt_info[pix_fmt];
- switch(pf->pixel_type) {
- case FF_PIXEL_PACKED:
- switch(pix_fmt) {
- case PIX_FMT_YUYV422:
- case PIX_FMT_UYVY422:
- case PIX_FMT_RGB565BE:
- case PIX_FMT_RGB565LE:
- case PIX_FMT_RGB555BE:
- case PIX_FMT_RGB555LE:
- case PIX_FMT_RGB444BE:
- case PIX_FMT_RGB444LE:
- case PIX_FMT_BGR565BE:
- case PIX_FMT_BGR565LE:
- case PIX_FMT_BGR555BE:
- case PIX_FMT_BGR555LE:
- case PIX_FMT_BGR444BE:
- case PIX_FMT_BGR444LE:
- bits = 16;
- break;
- case PIX_FMT_UYYVYY411:
- bits = 12;
- break;
- default:
- bits = pf->depth * pf->nb_channels;
- break;
- }
- break;
- case FF_PIXEL_PLANAR:
- if (desc->log2_chroma_w == 0 && desc->log2_chroma_h == 0) {
- bits = pf->depth * pf->nb_channels;
- } else {
- bits = pf->depth + ((2 * pf->depth) >>
- (desc->log2_chroma_w + desc->log2_chroma_h));
- }
- break;
- case FF_PIXEL_PALETTE:
- bits = 8;
- break;
- default:
- bits = -1;
- break;
- }
- return bits;
+ return info->padded_size ?
+ info->padded_size : av_get_bits_per_pixel(desc);
}
-static enum PixelFormat avcodec_find_best_pix_fmt1(int64_t pix_fmt_mask,
- enum PixelFormat src_pix_fmt,
- int has_alpha,
- int loss_mask)
+enum PixelFormat avcodec_find_best_pix_fmt(int64_t pix_fmt_mask, enum PixelFormat src_pix_fmt,
+ int has_alpha, int *loss_ptr)
{
- int dist, i, loss, min_dist;
enum PixelFormat dst_pix_fmt;
+ int i;
- /* find exact color match with smallest size */
- dst_pix_fmt = PIX_FMT_NONE;
- min_dist = 0x7fffffff;
- for(i = 0;i < PIX_FMT_NB; i++) {
- if (pix_fmt_mask & (1ULL << i)) {
- loss = avcodec_get_pix_fmt_loss(i, src_pix_fmt, has_alpha) & loss_mask;
- if (loss == 0) {
- dist = avg_bits_per_pixel(i);
- if (dist < min_dist) {
- min_dist = dist;
- dst_pix_fmt = i;
- }
- }
- }
+ if (loss_ptr) /* all losses count (for backward compatibility) */
+ *loss_ptr = 0;
+
+ dst_pix_fmt = PIX_FMT_NONE; /* so first iteration doesn't have to be treated special */
+ for(i = 0; i< FFMIN(PIX_FMT_NB, 64); i++){
+ if (pix_fmt_mask & (1ULL << i))
+ dst_pix_fmt = avcodec_find_best_pix_fmt2(dst_pix_fmt, i, src_pix_fmt, has_alpha, loss_ptr);
}
return dst_pix_fmt;
}
-enum PixelFormat avcodec_find_best_pix_fmt(int64_t pix_fmt_mask, enum PixelFormat src_pix_fmt,
- int has_alpha, int *loss_ptr)
+enum PixelFormat avcodec_find_best_pix_fmt2(enum PixelFormat dst_pix_fmt1, enum PixelFormat dst_pix_fmt2,
+ enum PixelFormat src_pix_fmt, int has_alpha, int *loss_ptr)
{
enum PixelFormat dst_pix_fmt;
- int loss_mask, i;
+ int loss1, loss2, loss_order1, loss_order2, i, loss_mask;
static const int loss_mask_order[] = {
~0, /* no loss first */
~FF_LOSS_ALPHA,
@@ -642,22 +494,29 @@ enum PixelFormat avcodec_find_best_pix_fmt(int64_t pix_fmt_mask, enum PixelForma
~(FF_LOSS_COLORSPACE | FF_LOSS_RESOLUTION),
~FF_LOSS_COLORQUANT,
~FF_LOSS_DEPTH,
+ ~(FF_LOSS_RESOLUTION | FF_LOSS_DEPTH | FF_LOSS_COLORSPACE | FF_LOSS_ALPHA |
+ FF_LOSS_COLORQUANT | FF_LOSS_CHROMA),
+ 0x80000, //non zero entry that combines all loss variants including future additions
0,
};
+ loss_mask= loss_ptr?~*loss_ptr:~0; /* use loss mask if provided */
+ dst_pix_fmt = PIX_FMT_NONE;
+ loss1 = avcodec_get_pix_fmt_loss(dst_pix_fmt1, src_pix_fmt, has_alpha) & loss_mask;
+ loss2 = avcodec_get_pix_fmt_loss(dst_pix_fmt2, src_pix_fmt, has_alpha) & loss_mask;
+
/* try with successive loss */
- i = 0;
- for(;;) {
- loss_mask = loss_mask_order[i++];
- dst_pix_fmt = avcodec_find_best_pix_fmt1(pix_fmt_mask, src_pix_fmt,
- has_alpha, loss_mask);
- if (dst_pix_fmt >= 0)
- goto found;
- if (loss_mask == 0)
- break;
+ for(i = 0;loss_mask_order[i] != 0 && dst_pix_fmt == PIX_FMT_NONE;i++) {
+ loss_order1 = loss1 & loss_mask_order[i];
+ loss_order2 = loss2 & loss_mask_order[i];
+
+ if (loss_order1 == 0 && loss_order2 == 0){ /* use format with smallest depth */
+ dst_pix_fmt = avg_bits_per_pixel(dst_pix_fmt2) < avg_bits_per_pixel(dst_pix_fmt1) ? dst_pix_fmt2 : dst_pix_fmt1;
+ } else if (loss_order1 == 0 || loss_order2 == 0) { /* use format with no loss */
+ dst_pix_fmt = loss_order2 ? dst_pix_fmt1 : dst_pix_fmt2;
+ }
}
- return PIX_FMT_NONE;
- found:
+
if (loss_ptr)
*loss_ptr = avcodec_get_pix_fmt_loss(dst_pix_fmt, src_pix_fmt, has_alpha);
return dst_pix_fmt;
@@ -776,11 +635,26 @@ void avpicture_free(AVPicture *picture)
}
/* return true if yuv planar */
-static inline int is_yuv_planar(const PixFmtInfo *ps)
+static inline int is_yuv_planar(enum PixelFormat fmt)
{
- return (ps->color_type == FF_COLOR_YUV ||
- ps->color_type == FF_COLOR_YUV_JPEG) &&
- ps->pixel_type == FF_PIXEL_PLANAR;
+ const PixFmtInfo *info = &pix_fmt_info[fmt];
+ const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[fmt];
+ int i;
+ int planes[4] = { 0 };
+
+ if (info->color_type != FF_COLOR_YUV &&
+ info->color_type != FF_COLOR_YUV_JPEG)
+ return 0;
+
+ /* set the used planes */
+ for (i = 0; i < desc->nb_components; i++)
+ planes[desc->comp[i].plane] = 1;
+
+ /* if there is an unused plane, the format is not planar */
+ for (i = 0; i < desc->nb_components; i++)
+ if (!planes[i])
+ return 0;
+ return 1;
}
int av_picture_crop(AVPicture *dst, const AVPicture *src,
@@ -789,15 +663,23 @@ int av_picture_crop(AVPicture *dst, const AVPicture *src,
int y_shift;
int x_shift;
- if (pix_fmt < 0 || pix_fmt >= PIX_FMT_NB || !is_yuv_planar(&pix_fmt_info[pix_fmt]))
+ if (pix_fmt < 0 || pix_fmt >= PIX_FMT_NB)
return -1;
y_shift = av_pix_fmt_descriptors[pix_fmt].log2_chroma_h;
x_shift = av_pix_fmt_descriptors[pix_fmt].log2_chroma_w;
+ if (is_yuv_planar(pix_fmt)) {
dst->data[0] = src->data[0] + (top_band * src->linesize[0]) + left_band;
dst->data[1] = src->data[1] + ((top_band >> y_shift) * src->linesize[1]) + (left_band >> x_shift);
dst->data[2] = src->data[2] + ((top_band >> y_shift) * src->linesize[2]) + (left_band >> x_shift);
+ } else{
+ if(top_band % (1<<y_shift) || left_band % (1<<x_shift))
+ return -1;
+ if(left_band) //FIXME add support for this too
+ return -1;
+ dst->data[0] = src->data[0] + (top_band * src->linesize[0]) + left_band;
+ }
dst->linesize[0] = src->linesize[0];
dst->linesize[1] = src->linesize[1];
@@ -816,7 +698,7 @@ int av_picture_pad(AVPicture *dst, const AVPicture *src, int height, int width,
int i, y;
if (pix_fmt < 0 || pix_fmt >= PIX_FMT_NB ||
- !is_yuv_planar(&pix_fmt_info[pix_fmt])) return -1;
+ !is_yuv_planar(pix_fmt)) return -1;
for (i = 0; i < 3; i++) {
x_shift = i ? av_pix_fmt_descriptors[pix_fmt].log2_chroma_w : 0;
@@ -865,6 +747,7 @@ int av_picture_pad(AVPicture *dst, const AVPicture *src, int height, int width,
return 0;
}
+#if FF_API_GET_ALPHA_INFO
/* NOTE: we scan all the pixels to have an exact information */
static int get_alpha_info_pal8(const AVPicture *src, int width, int height)
{
@@ -911,6 +794,7 @@ int img_get_alpha_info(const AVPicture *src,
}
return ret;
}
+#endif
#if !(HAVE_MMX && HAVE_YASM)
/* filter parameters: [-1 4 2 4 -1] // 8 */
diff --git a/libavcodec/imgconvert.h b/libavcodec/imgconvert.h
index c99e587906..64da317d27 100644
--- a/libavcodec/imgconvert.h
+++ b/libavcodec/imgconvert.h
@@ -4,20 +4,20 @@
*
* Copyright (c) 2008 Vitor Sessak
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/imx_dump_header_bsf.c b/libavcodec/imx_dump_header_bsf.c
index 3724daf008..8119809faa 100644
--- a/libavcodec/imx_dump_header_bsf.c
+++ b/libavcodec/imx_dump_header_bsf.c
@@ -2,20 +2,20 @@
* imx dump header bitstream filter
* Copyright (c) 2007 Baptiste Coudurier
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/indeo2.c b/libavcodec/indeo2.c
index 0e588c3966..f7798e307d 100644
--- a/libavcodec/indeo2.c
+++ b/libavcodec/indeo2.c
@@ -2,20 +2,20 @@
* Intel Indeo 2 codec
* Copyright (c) 2005 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -146,9 +146,6 @@ static int ir2_decode_frame(AVCodecContext *avctx,
AVFrame * const p= (AVFrame*)&s->picture;
int start;
- if(p->data[0])
- avctx->release_buffer(avctx, p);
-
p->reference = 1;
p->buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
if (avctx->reget_buffer(avctx, p)) {
@@ -156,6 +153,13 @@ static int ir2_decode_frame(AVCodecContext *avctx,
return -1;
}
+ start = 48; /* hardcoded for now */
+
+ if (start >= buf_size) {
+ av_log(s->avctx, AV_LOG_ERROR, "input buffer size too small (%d)\n", buf_size);
+ return AVERROR_INVALIDDATA;
+ }
+
s->decode_delta = buf[18];
/* decide whether frame uses deltas or not */
@@ -163,9 +167,8 @@ static int ir2_decode_frame(AVCodecContext *avctx,
for (i = 0; i < buf_size; i++)
buf[i] = av_reverse[buf[i]];
#endif
- start = 48; /* hardcoded for now */
- init_get_bits(&s->gb, buf + start, buf_size - start);
+ init_get_bits(&s->gb, buf + start, (buf_size - start) * 8);
if (s->decode_delta) { /* intraframe */
ir2_decode_plane(s, avctx->width, avctx->height,
@@ -195,6 +198,7 @@ static av_cold int ir2_decode_init(AVCodecContext *avctx){
Ir2Context * const ic = avctx->priv_data;
static VLC_TYPE vlc_tables[1 << CODE_VLC_BITS][2];
+ avcodec_get_frame_defaults(&ic->picture);
ic->avctx = avctx;
avctx->pix_fmt= PIX_FMT_YUV410P;
@@ -225,14 +229,13 @@ static av_cold int ir2_decode_end(AVCodecContext *avctx){
}
AVCodec ff_indeo2_decoder = {
- "indeo2",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_INDEO2,
- sizeof(Ir2Context),
- ir2_decode_init,
- NULL,
- ir2_decode_end,
- ir2_decode_frame,
- CODEC_CAP_DR1,
+ .name = "indeo2",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_INDEO2,
+ .priv_data_size = sizeof(Ir2Context),
+ .init = ir2_decode_init,
+ .close = ir2_decode_end,
+ .decode = ir2_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Intel Indeo 2"),
};
diff --git a/libavcodec/indeo2data.h b/libavcodec/indeo2data.h
index ef85e32d87..b2e0b8a509 100644
--- a/libavcodec/indeo2data.h
+++ b/libavcodec/indeo2data.h
@@ -2,20 +2,20 @@
* Intel Indeo 2 codec
* copyright (c) 2005 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/indeo3.c b/libavcodec/indeo3.c
index 30b70850f8..fbbffe230a 100644
--- a/libavcodec/indeo3.c
+++ b/libavcodec/indeo3.c
@@ -1,27 +1,29 @@
/*
- * Intel Indeo 3 (IV31, IV32, etc.) video decoder for ffmpeg
- * written, produced, and directed by Alan Smithee
- *
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+/**
+ * @file
+ * Intel Indeo 3 (IV31, IV32, etc.) video decoder for FFmpeg
+ * written, produced, and directed by Alan Smithee
+ *
+ * For some documentation see:
+ * http://wiki.multimedia.cx/index.php?title=Indeo_3
+ */
#include "libavutil/imgutils.h"
#include "avcodec.h"
@@ -211,6 +213,7 @@ static void iv_Decode_Chunk(Indeo3DecodeContext *s,
int *width_tbl, width_tbl_arr[10];
const signed char *ref_vectors;
uint8_t *cur_frm_pos, *ref_frm_pos, *cp, *cp2;
+ uint8_t *cur_end = cur + width*height + width;
uint32_t *cur_lp, *ref_lp;
const uint32_t *correction_lp[2], *correctionloworder_lp[2], *correctionhighorder_lp[2];
uint8_t *correction_type_sp[2];
@@ -357,6 +360,8 @@ static void iv_Decode_Chunk(Indeo3DecodeContext *s,
k = *buf1++;
cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2];
ref_lp = ((uint32_t *)ref_frm_pos) + width_tbl[lp2];
+ if ((uint8_t *)cur_lp >= cur_end-3)
+ break;
switch(correction_type_sp[0][k]) {
case 0:
@@ -967,6 +972,7 @@ static av_cold int indeo3_decode_init(AVCodecContext *avctx)
s->width = avctx->width;
s->height = avctx->height;
avctx->pix_fmt = PIX_FMT_YUV410P;
+ avcodec_get_frame_defaults(&s->frame);
if (!(ret = build_modpred(s)))
ret = iv_alloc_frames(s);
@@ -1134,19 +1140,20 @@ static av_cold int indeo3_decode_end(AVCodecContext *avctx)
iv_free_func(s);
+ if (s->frame.data[0])
+ avctx->release_buffer(avctx, &s->frame);
+
return 0;
}
AVCodec ff_indeo3_decoder = {
- "indeo3",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_INDEO3,
- sizeof(Indeo3DecodeContext),
- indeo3_decode_init,
- NULL,
- indeo3_decode_end,
- indeo3_decode_frame,
- CODEC_CAP_DR1,
- NULL,
+ .name = "indeo3",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_INDEO3,
+ .priv_data_size = sizeof(Indeo3DecodeContext),
+ .init = indeo3_decode_init,
+ .close = indeo3_decode_end,
+ .decode = indeo3_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Intel Indeo 3"),
};
diff --git a/libavcodec/indeo3data.h b/libavcodec/indeo3data.h
index 334c3e0c97..bbc4c952ff 100644
--- a/libavcodec/indeo3data.h
+++ b/libavcodec/indeo3data.h
@@ -2,20 +2,20 @@
* Intel Indeo 3 (IV31, IV32, etc.) video decoder for ffmpeg
* written, produced, and directed by Alan Smithee
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/indeo5.c b/libavcodec/indeo5.c
index ba1bc18eff..4c6bfd66d1 100644
--- a/libavcodec/indeo5.c
+++ b/libavcodec/indeo5.c
@@ -2,20 +2,20 @@
* Indeo Video Interactive v5 compatible decoder
* Copyright (c) 2009 Maxim Poliakovski
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -713,6 +713,8 @@ static av_cold int decode_init(AVCodecContext *avctx)
ctx->pic_conf.tile_height = avctx->height;
ctx->pic_conf.luma_bands = ctx->pic_conf.chroma_bands = 1;
+ avcodec_get_frame_defaults(&ctx->frame);
+
result = ff_ivi_init_planes(ctx->planes, &ctx->pic_conf);
if (result) {
av_log(avctx, AV_LOG_ERROR, "Couldn't allocate color planes!\n");
diff --git a/libavcodec/indeo5data.h b/libavcodec/indeo5data.h
index f4252b59f6..a6217d0bf8 100644
--- a/libavcodec/indeo5data.h
+++ b/libavcodec/indeo5data.h
@@ -2,20 +2,20 @@
* Indeo Video Interactive 5 compatible decoder
* Copyright (c) 2009 Maxim Poliakovski
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/intelh263dec.c b/libavcodec/intelh263dec.c
index 83049bcc6f..836e98ee88 100644
--- a/libavcodec/intelh263dec.c
+++ b/libavcodec/intelh263dec.c
@@ -1,20 +1,20 @@
/*
* H.263i decoder
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -125,15 +125,14 @@ int ff_intel_h263_decode_picture_header(MpegEncContext *s)
}
AVCodec ff_h263i_decoder = {
- "h263i",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_H263I,
- sizeof(MpegEncContext),
- ff_h263_decode_init,
- NULL,
- ff_h263_decode_end,
- ff_h263_decode_frame,
- CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
+ .name = "h263i",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_H263I,
+ .priv_data_size = sizeof(MpegEncContext),
+ .init = ff_h263_decode_init,
+ .close = ff_h263_decode_end,
+ .decode = ff_h263_decode_frame,
+ .capabilities = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Intel H.263"),
.pix_fmts= ff_pixfmt_list_420,
};
diff --git a/libavcodec/internal.h b/libavcodec/internal.h
index fe853ab87e..d431a85bf9 100644
--- a/libavcodec/internal.h
+++ b/libavcodec/internal.h
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -27,6 +27,11 @@
#include <stdint.h>
#include "avcodec.h"
+struct AVCodecDefault {
+ const uint8_t *key;
+ const uint8_t *value;
+};
+
/**
* Determine whether pix_fmt is a hardware accelerated format.
*/
@@ -48,6 +53,11 @@ AVHWAccel *ff_find_hwaccel(enum CodecID codec_id, enum PixelFormat pix_fmt);
*/
int ff_match_2uint16(const uint16_t (*tab)[2], int size, int a, int b);
-unsigned int ff_toupper4(unsigned int x);
+unsigned int avpriv_toupper4(unsigned int x);
+
+/**
+ * does needed setup of pkt_pts/pos and such for (re)get_buffer();
+ */
+void ff_init_buffer_info(AVCodecContext *s, AVFrame *pic);
#endif /* AVCODEC_INTERNAL_H */
diff --git a/libavcodec/interplayvideo.c b/libavcodec/interplayvideo.c
index 3bbb464aff..c8aa8bf65b 100644
--- a/libavcodec/interplayvideo.c
+++ b/libavcodec/interplayvideo.c
@@ -2,20 +2,20 @@
* Interplay MVE Video Decoder
* Copyright (C) 2003 the ffmpeg project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -1022,6 +1022,9 @@ static av_cold int ipvideo_decode_init(AVCodecContext *avctx)
/* decoding map contains 4 bits of information per 8x8 block */
s->decoding_map_size = avctx->width * avctx->height / (8 * 8 * 2);
+ avcodec_get_frame_defaults(&s->second_last_frame);
+ avcodec_get_frame_defaults(&s->last_frame);
+ avcodec_get_frame_defaults(&s->current_frame);
s->current_frame.data[0] = s->last_frame.data[0] =
s->second_last_frame.data[0] = NULL;
@@ -1089,14 +1092,13 @@ static av_cold int ipvideo_decode_end(AVCodecContext *avctx)
}
AVCodec ff_interplay_video_decoder = {
- "interplayvideo",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_INTERPLAY_VIDEO,
- sizeof(IpvideoContext),
- ipvideo_decode_init,
- NULL,
- ipvideo_decode_end,
- ipvideo_decode_frame,
- CODEC_CAP_DR1,
+ .name = "interplayvideo",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_INTERPLAY_VIDEO,
+ .priv_data_size = sizeof(IpvideoContext),
+ .init = ipvideo_decode_init,
+ .close = ipvideo_decode_end,
+ .decode = ipvideo_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Interplay MVE video"),
};
diff --git a/libavcodec/intrax8.c b/libavcodec/intrax8.c
index 69f940a162..4b0886280b 100644
--- a/libavcodec/intrax8.c
+++ b/libavcodec/intrax8.c
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -304,7 +304,7 @@ static int x8_setup_spatial_predictor(IntraX8Context * const w, const int chroma
int quant;
s->dsp.x8_setup_spatial_compensation(s->dest[chroma], s->edge_emu_buffer,
- s->current_picture.linesize[chroma>0],
+ s->current_picture.f.linesize[chroma>0],
&range, &sum, w->edges);
if(chroma){
w->orient=w->chroma_orient;
@@ -613,7 +613,7 @@ static int x8_decode_intra_mb(IntraX8Context* const w, const int chroma){
dc_level+= (w->predicted_dc*divide_quant + (1<<12) )>>13;
dsp_x8_put_solidcolor( av_clip_uint8((dc_level*dc_quant+4)>>3),
- s->dest[chroma], s->current_picture.linesize[!!chroma]);
+ s->dest[chroma], s->current_picture.f.linesize[!!chroma]);
goto block_placed;
}
@@ -637,15 +637,15 @@ static int x8_decode_intra_mb(IntraX8Context* const w, const int chroma){
}
if(w->flat_dc){
- dsp_x8_put_solidcolor(w->predicted_dc, s->dest[chroma], s->current_picture.linesize[!!chroma]);
+ dsp_x8_put_solidcolor(w->predicted_dc, s->dest[chroma], s->current_picture.f.linesize[!!chroma]);
}else{
s->dsp.x8_spatial_compensation[w->orient]( s->edge_emu_buffer,
s->dest[chroma],
- s->current_picture.linesize[!!chroma] );
+ s->current_picture.f.linesize[!!chroma] );
}
if(!zeros_only)
s->dsp.idct_add ( s->dest[chroma],
- s->current_picture.linesize[!!chroma],
+ s->current_picture.f.linesize[!!chroma],
s->block[0] );
block_placed:
@@ -656,7 +656,7 @@ block_placed:
if(s->loop_filter){
uint8_t* ptr = s->dest[chroma];
- int linesize = s->current_picture.linesize[!!chroma];
+ int linesize = s->current_picture.f.linesize[!!chroma];
if(!( (w->edges&2) || ( zeros_only && (w->orient|4)==4 ) )){
s->dsp.x8_h_loop_filter(ptr, linesize, w->quant);
@@ -671,12 +671,12 @@ block_placed:
static void x8_init_block_index(MpegEncContext *s){ //FIXME maybe merge with ff_*
//not s->linesize as this would be wrong for field pics
//not that IntraX8 has interlacing support ;)
- const int linesize = s->current_picture.linesize[0];
- const int uvlinesize= s->current_picture.linesize[1];
+ const int linesize = s->current_picture.f.linesize[0];
+ const int uvlinesize = s->current_picture.f.linesize[1];
- s->dest[0] = s->current_picture.data[0];
- s->dest[1] = s->current_picture.data[1];
- s->dest[2] = s->current_picture.data[2];
+ s->dest[0] = s->current_picture.f.data[0];
+ s->dest[1] = s->current_picture.f.data[1];
+ s->dest[2] = s->current_picture.f.data[2];
s->dest[0] += s->mb_y * linesize << 3;
s->dest[1] += ( s->mb_y&(~1) ) * uvlinesize << 2;//chroma blocks are on add rows
@@ -771,7 +771,7 @@ int ff_intrax8_decode_picture(IntraX8Context * const w, int dquant, int quant_of
/*emulate MB info in the relevant tables*/
s->mbskip_table [mb_xy]=0;
s->mbintra_table[mb_xy]=1;
- s->current_picture.qscale_table[mb_xy]=w->quant;
+ s->current_picture.f.qscale_table[mb_xy] = w->quant;
mb_xy++;
}
s->dest[0]+= 8;
diff --git a/libavcodec/intrax8.h b/libavcodec/intrax8.h
index 3a58938cc3..8ce4f8d098 100644
--- a/libavcodec/intrax8.h
+++ b/libavcodec/intrax8.h
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/intrax8dsp.c b/libavcodec/intrax8dsp.c
index 1a62fcde77..692e1b102f 100644
--- a/libavcodec/intrax8dsp.c
+++ b/libavcodec/intrax8dsp.c
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/intrax8huf.h b/libavcodec/intrax8huf.h
index 6bf01f388a..375906bab2 100644
--- a/libavcodec/intrax8huf.h
+++ b/libavcodec/intrax8huf.h
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/ituh263dec.c b/libavcodec/ituh263dec.c
index 7071b845fc..69e7ab9c99 100644
--- a/libavcodec/ituh263dec.c
+++ b/libavcodec/ituh263dec.c
@@ -5,20 +5,20 @@
* Copyright (c) 2001 Juan J. Sierralta P
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -271,7 +271,7 @@ int ff_h263_resync(MpegEncContext *s){
int h263_decode_motion(MpegEncContext * s, int pred, int f_code)
{
- int code, val, sign, shift, l;
+ int code, val, sign, shift;
code = get_vlc2(&s->gb, mv_vlc.table, MV_VLC_BITS, 2);
if (code == 0)
@@ -293,8 +293,7 @@ int h263_decode_motion(MpegEncContext * s, int pred, int f_code)
/* modulo decoding */
if (!s->h263_long_vectors) {
- l = INT_BIT - 5 - f_code;
- val = (val<<l)>>l;
+ val = sign_extend(val, 5 + f_code);
} else {
/* horrible h263 long vector mode */
if (pred < -31 && val < -63)
@@ -353,20 +352,20 @@ static void preview_obmc(MpegEncContext *s){
do{
if (get_bits1(&s->gb)) {
/* skip mb */
- mot_val = s->current_picture.motion_val[0][ s->block_index[0] ];
+ mot_val = s->current_picture.f.motion_val[0][s->block_index[0]];
mot_val[0 ]= mot_val[2 ]=
mot_val[0+stride]= mot_val[2+stride]= 0;
mot_val[1 ]= mot_val[3 ]=
mot_val[1+stride]= mot_val[3+stride]= 0;
- s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
+ s->current_picture.f.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
goto end;
}
cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2);
}while(cbpc == 20);
if(cbpc & 4){
- s->current_picture.mb_type[xy]= MB_TYPE_INTRA;
+ s->current_picture.f.mb_type[xy] = MB_TYPE_INTRA;
}else{
get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
if (cbpc & 8) {
@@ -378,7 +377,7 @@ static void preview_obmc(MpegEncContext *s){
}
if ((cbpc & 16) == 0) {
- s->current_picture.mb_type[xy]= MB_TYPE_16x16 | MB_TYPE_L0;
+ s->current_picture.f.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_L0;
/* 16x16 motion prediction */
mot_val= h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
if (s->umvplus)
@@ -396,7 +395,7 @@ static void preview_obmc(MpegEncContext *s){
mot_val[1 ]= mot_val[3 ]=
mot_val[1+stride]= mot_val[3+stride]= my;
} else {
- s->current_picture.mb_type[xy]= MB_TYPE_8x8 | MB_TYPE_L0;
+ s->current_picture.f.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_L0;
for(i=0;i<4;i++) {
mot_val = h263_pred_motion(s, i, 0, &pred_x, &pred_y);
if (s->umvplus)
@@ -618,7 +617,7 @@ int ff_h263_decode_mb(MpegEncContext *s,
s->block_last_index[i] = -1;
s->mv_dir = MV_DIR_FORWARD;
s->mv_type = MV_TYPE_16X16;
- s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
+ s->current_picture.f.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
s->mv[0][0][0] = 0;
s->mv[0][0][1] = 0;
s->mb_skipped = !(s->obmc | s->loop_filter);
@@ -651,7 +650,7 @@ int ff_h263_decode_mb(MpegEncContext *s,
s->mv_dir = MV_DIR_FORWARD;
if ((cbpc & 16) == 0) {
- s->current_picture.mb_type[xy]= MB_TYPE_16x16 | MB_TYPE_L0;
+ s->current_picture.f.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_L0;
/* 16x16 motion prediction */
s->mv_type = MV_TYPE_16X16;
h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
@@ -676,7 +675,7 @@ int ff_h263_decode_mb(MpegEncContext *s,
if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */
} else {
- s->current_picture.mb_type[xy]= MB_TYPE_8x8 | MB_TYPE_L0;
+ s->current_picture.f.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_L0;
s->mv_type = MV_TYPE_8X8;
for(i=0;i<4;i++) {
mot_val = h263_pred_motion(s, i, 0, &pred_x, &pred_y);
@@ -704,8 +703,8 @@ int ff_h263_decode_mb(MpegEncContext *s,
} else if(s->pict_type==AV_PICTURE_TYPE_B) {
int mb_type;
const int stride= s->b8_stride;
- int16_t *mot_val0 = s->current_picture.motion_val[0][ 2*(s->mb_x + s->mb_y*stride) ];
- int16_t *mot_val1 = s->current_picture.motion_val[1][ 2*(s->mb_x + s->mb_y*stride) ];
+ int16_t *mot_val0 = s->current_picture.f.motion_val[0][2 * (s->mb_x + s->mb_y * stride)];
+ int16_t *mot_val1 = s->current_picture.f.motion_val[1][2 * (s->mb_x + s->mb_y * stride)];
// const int mv_xy= s->mb_x + 1 + s->mb_y * s->mb_stride;
//FIXME ugly
@@ -788,7 +787,7 @@ int ff_h263_decode_mb(MpegEncContext *s,
}
}
- s->current_picture.mb_type[xy]= mb_type;
+ s->current_picture.f.mb_type[xy] = mb_type;
} else { /* I-Frame */
do{
cbpc = get_vlc2(&s->gb, ff_h263_intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 2);
@@ -803,11 +802,11 @@ int ff_h263_decode_mb(MpegEncContext *s,
dquant = cbpc & 4;
s->mb_intra = 1;
intra:
- s->current_picture.mb_type[xy]= MB_TYPE_INTRA;
+ s->current_picture.f.mb_type[xy] = MB_TYPE_INTRA;
if (s->h263_aic) {
s->ac_pred = get_bits1(&s->gb);
if(s->ac_pred){
- s->current_picture.mb_type[xy]= MB_TYPE_INTRA | MB_TYPE_ACPRED;
+ s->current_picture.f.mb_type[xy] = MB_TYPE_INTRA | MB_TYPE_ACPRED;
s->h263_aic_dir = get_bits1(&s->gb);
}
@@ -889,7 +888,7 @@ int h263_decode_picture_header(MpegEncContext *s)
i = get_bits(&s->gb, 8); /* picture timestamp */
if( (s->picture_number&~0xFF)+i < s->picture_number)
i+= 256;
- s->current_picture_ptr->pts=
+ s->current_picture_ptr->f.pts =
s->picture_number= (s->picture_number&~0xFF) + i;
/* PTYPE starts here */
diff --git a/libavcodec/ituh263enc.c b/libavcodec/ituh263enc.c
index cadf389866..01c603e26d 100644
--- a/libavcodec/ituh263enc.c
+++ b/libavcodec/ituh263enc.c
@@ -5,20 +5,20 @@
* Copyright (c) 2001 Juan J. Sierralta P
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -126,7 +126,7 @@ void h263_encode_picture_header(MpegEncContext * s, int picture_number)
coded_frame_rate= 1800000;
coded_frame_rate_base= (1000+best_clock_code)*best_divisor;
- align_put_bits(&s->pb);
+ avpriv_align_put_bits(&s->pb);
/* Update the pointer to last GOB */
s->ptr_lastgob = put_bits_ptr(&s->pb);
@@ -275,7 +275,7 @@ void h263_encode_gob_header(MpegEncContext * s, int mb_line)
*/
void ff_clean_h263_qscales(MpegEncContext *s){
int i;
- int8_t * const qscale_table= s->current_picture.qscale_table;
+ int8_t * const qscale_table = s->current_picture.f.qscale_table;
ff_init_qscale_tab(s);
@@ -529,8 +529,8 @@ void h263_encode_mb(MpegEncContext * s,
/* motion vectors: 8x8 mode*/
h263_pred_motion(s, i, 0, &pred_x, &pred_y);
- motion_x= s->current_picture.motion_val[0][ s->block_index[i] ][0];
- motion_y= s->current_picture.motion_val[0][ s->block_index[i] ][1];
+ motion_x = s->current_picture.f.motion_val[0][s->block_index[i]][0];
+ motion_y = s->current_picture.f.motion_val[0][s->block_index[i]][1];
if (!s->umvplus) {
ff_h263_encode_motion_vector(s, motion_x - pred_x,
motion_y - pred_y, 1);
@@ -657,7 +657,7 @@ void h263_encode_mb(MpegEncContext * s,
void ff_h263_encode_motion(MpegEncContext * s, int val, int f_code)
{
- int range, l, bit_size, sign, code, bits;
+ int range, bit_size, sign, code, bits;
if (val == 0) {
/* zero vector */
@@ -667,8 +667,7 @@ void ff_h263_encode_motion(MpegEncContext * s, int val, int f_code)
bit_size = f_code - 1;
range = 1 << bit_size;
/* modulo encoding */
- l= INT_BIT - 6 - bit_size;
- val = (val<<l)>>l;
+ val = sign_extend(val, 6 + bit_size);
sign = val>>31;
val= (val^sign)-sign;
sign&=1;
diff --git a/libavcodec/ivi_common.c b/libavcodec/ivi_common.c
index bd3d4e6fd4..7f14a89f33 100644
--- a/libavcodec/ivi_common.c
+++ b/libavcodec/ivi_common.c
@@ -3,20 +3,20 @@
*
* Copyright (c) 2009 Maxim Poliakovski
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/ivi_common.h b/libavcodec/ivi_common.h
index fd3d82515a..10cca26045 100644
--- a/libavcodec/ivi_common.h
+++ b/libavcodec/ivi_common.h
@@ -3,20 +3,20 @@
*
* Copyright (c) 2009 Maxim Poliakovski
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -219,7 +219,7 @@ static inline int ivi_scale_mv(int mv, int mv_scale)
/**
* Generate a huffman codebook from the given descriptor
- * and convert it into the Libav VLC table.
+ * and convert it into the FFmpeg VLC table.
*
* @param[in] cb pointer to codebook descriptor
* @param[out] vlc where to place the generated VLC table
diff --git a/libavcodec/ivi_dsp.c b/libavcodec/ivi_dsp.c
index 6b62dc8fdb..913fdc31b2 100644
--- a/libavcodec/ivi_dsp.c
+++ b/libavcodec/ivi_dsp.c
@@ -3,20 +3,20 @@
*
* Copyright (c) 2009 Maxim Poliakovski
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/ivi_dsp.h b/libavcodec/ivi_dsp.h
index 9632966a9a..4fb2f80035 100644
--- a/libavcodec/ivi_dsp.h
+++ b/libavcodec/ivi_dsp.h
@@ -3,20 +3,20 @@
*
* Copyright (c) 2009 Maxim Poliakovski
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/j2k.c b/libavcodec/j2k.c
new file mode 100644
index 0000000000..33a7e3100b
--- /dev/null
+++ b/libavcodec/j2k.c
@@ -0,0 +1,392 @@
+/*
+ * JPEG2000 encoder and decoder common functions
+ * Copyright (c) 2007 Kamil Nowosad
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * JPEG2000 image encoder and decoder common functions
+ * @file
+ * @author Kamil Nowosad
+ */
+
+
+#include "avcodec.h"
+#include "j2k.h"
+
+#define SHL(a, n) ((n)>=0 ? (a) << (n) : (a) >> -(n))
+
+#if 0
+void ff_j2k_printv(int *tab, int l)
+{
+ int i;
+ for (i = 0; i < l; i++)
+ printf("%.3d ", tab[i]);
+ printf("\n");
+}
+
+void ff_j2k_printu(uint8_t *tab, int l)
+{
+ int i;
+ for (i = 0; i < l; i++)
+ printf("%.3hd ", tab[i]);
+ printf("\n");
+}
+#endif
+
+/* tag tree routines */
+
+/** allocate the memory for tag tree */
+
+static int tag_tree_size(int w, int h)
+{
+ int res = 0;
+ while (w > 1 || h > 1){
+ res += w * h;
+ w = (w+1) >> 1;
+ h = (h+1) >> 1;
+ }
+ return res + 1;
+}
+
+J2kTgtNode *ff_j2k_tag_tree_init(int w, int h)
+{
+ int pw = w, ph = h;
+ J2kTgtNode *res, *t, *t2;
+
+ t = res = av_mallocz(tag_tree_size(w, h)*sizeof(J2kTgtNode));
+
+ if (res == NULL)
+ return NULL;
+
+ while (w > 1 || h > 1){
+ int i, j;
+ pw = w;
+ ph = h;
+
+ w = (w+1) >> 1;
+ h = (h+1) >> 1;
+ t2 = t + pw*ph;
+
+ for (i = 0; i < ph; i++)
+ for (j = 0; j < pw; j++){
+ t[i*pw + j].parent = &t2[(i>>1)*w + (j>>1)];
+ }
+ t = t2;
+ }
+ t[0].parent = NULL;
+ return res;
+}
+
+static void tag_tree_zero(J2kTgtNode *t, int w, int h)
+{
+ int i, siz = tag_tree_size(w, h);
+
+ for (i = 0; i < siz; i++){
+ t[i].val = 0;
+ t[i].vis = 0;
+ }
+}
+
+uint8_t ff_j2k_nbctxno_lut[256][4];
+
+static int getnbctxno(int flag, int bandno, int vert_causal_ctx_csty_symbol)
+{
+ int h, v, d;
+
+ h = ((flag & J2K_T1_SIG_E) ? 1:0)+
+ ((flag & J2K_T1_SIG_W) ? 1:0);
+ v = ((flag & J2K_T1_SIG_N) ? 1:0);
+ if (!vert_causal_ctx_csty_symbol)
+ v = v + ((flag & J2K_T1_SIG_S) ? 1:0);
+ d = ((flag & J2K_T1_SIG_NE) ? 1:0)+
+ ((flag & J2K_T1_SIG_NW) ? 1:0);
+ if (!vert_causal_ctx_csty_symbol)
+ d = d + ((flag & J2K_T1_SIG_SE) ? 1:0)+
+ ((flag & J2K_T1_SIG_SW) ? 1:0);
+ if (bandno < 3){
+ if (bandno == 1)
+ FFSWAP(int, h, v);
+ if (h == 2) return 8;
+ if (h == 1){
+ if (v >= 1) return 7;
+ if (d >= 1) return 6;
+ return 5;
+ }
+ if (v == 2) return 4;
+ if (v == 1) return 3;
+ if (d >= 2) return 2;
+ if (d == 1) return 1;
+ return 0;
+ } else{
+ if (d >= 3) return 8;
+ if (d == 2){
+ if (h+v >= 1) return 7;
+ return 6;
+ }
+ if (d == 1){
+ if (h+v >= 2) return 5;
+ if (h+v == 1) return 4;
+ return 3;
+ }
+ if (h+v >= 2) return 2;
+ if (h+v == 1) return 1;
+ return 0;
+ }
+ assert(0);
+}
+
+uint8_t ff_j2k_sgnctxno_lut[16][16], ff_j2k_xorbit_lut[16][16];
+
+static int getsgnctxno(int flag, uint8_t *xorbit)
+{
+ int vcontrib, hcontrib;
+ static const int contribtab[3][3] = {{0, -1, 1}, {-1, -1, 0}, {1, 0, 1}};
+ static const int ctxlbltab[3][3] = {{13, 12, 11}, {10, 9, 10}, {11, 12, 13}};
+ static const int xorbittab[3][3] = {{1, 1, 1,}, {1, 0, 0}, {0, 0, 0}};
+
+ hcontrib = contribtab[flag & J2K_T1_SIG_E ? flag & J2K_T1_SGN_E ? 1:2:0]
+ [flag & J2K_T1_SIG_W ? flag & J2K_T1_SGN_W ? 1:2:0]+1;
+ vcontrib = contribtab[flag & J2K_T1_SIG_S ? flag & J2K_T1_SGN_S ? 1:2:0]
+ [flag & J2K_T1_SIG_N ? flag & J2K_T1_SGN_N ? 1:2:0]+1;
+ *xorbit = xorbittab[hcontrib][vcontrib];
+ return ctxlbltab[hcontrib][vcontrib];
+}
+
+void ff_j2k_init_tier1_luts(void)
+{
+ int i, j;
+ for (i = 0; i < 256; i++)
+ for (j = 0; j < 4; j++)
+ ff_j2k_nbctxno_lut[i][j] = getnbctxno(i, j, 0);
+ for (i = 0; i < 16; i++)
+ for (j = 0; j < 16; j++)
+ ff_j2k_sgnctxno_lut[i][j] = getsgnctxno(i + (j << 8), &ff_j2k_xorbit_lut[i][j]);
+}
+
+void ff_j2k_set_significant(J2kT1Context *t1, int x, int y, int negative)
+{
+ x++; y++;
+ t1->flags[y][x] |= J2K_T1_SIG;
+ if (negative){
+ t1->flags[y][x+1] |= J2K_T1_SIG_W | J2K_T1_SGN_W;
+ t1->flags[y][x-1] |= J2K_T1_SIG_E | J2K_T1_SGN_E;
+ t1->flags[y+1][x] |= J2K_T1_SIG_N | J2K_T1_SGN_N;
+ t1->flags[y-1][x] |= J2K_T1_SIG_S | J2K_T1_SGN_S;
+ } else{
+ t1->flags[y][x+1] |= J2K_T1_SIG_W;
+ t1->flags[y][x-1] |= J2K_T1_SIG_E;
+ t1->flags[y+1][x] |= J2K_T1_SIG_N;
+ t1->flags[y-1][x] |= J2K_T1_SIG_S;
+ }
+ t1->flags[y+1][x+1] |= J2K_T1_SIG_NW;
+ t1->flags[y+1][x-1] |= J2K_T1_SIG_NE;
+ t1->flags[y-1][x+1] |= J2K_T1_SIG_SW;
+ t1->flags[y-1][x-1] |= J2K_T1_SIG_SE;
+}
+
+int ff_j2k_init_component(J2kComponent *comp, J2kCodingStyle *codsty, J2kQuantStyle *qntsty, int cbps, int dx, int dy)
+{
+ int reslevelno, bandno, gbandno = 0, ret, i, j, csize = 1;
+
+ if (ret=ff_j2k_dwt_init(&comp->dwt, comp->coord, codsty->nreslevels-1, codsty->transform))
+ return ret;
+ for (i = 0; i < 2; i++)
+ csize *= comp->coord[i][1] - comp->coord[i][0];
+
+ comp->data = av_malloc(csize * sizeof(int));
+ if (!comp->data)
+ return AVERROR(ENOMEM);
+ comp->reslevel = av_malloc(codsty->nreslevels * sizeof(J2kResLevel));
+
+ if (!comp->reslevel)
+ return AVERROR(ENOMEM);
+ for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++){
+ int declvl = codsty->nreslevels - reslevelno;
+ J2kResLevel *reslevel = comp->reslevel + reslevelno;
+
+ for (i = 0; i < 2; i++)
+ for (j = 0; j < 2; j++)
+ reslevel->coord[i][j] =
+ ff_j2k_ceildivpow2(comp->coord[i][j], declvl - 1);
+
+ if (reslevelno == 0)
+ reslevel->nbands = 1;
+ else
+ reslevel->nbands = 3;
+
+ if (reslevel->coord[0][1] == reslevel->coord[0][0])
+ reslevel->num_precincts_x = 0;
+ else
+ reslevel->num_precincts_x = ff_j2k_ceildivpow2(reslevel->coord[0][1], codsty->log2_prec_width)
+ - (reslevel->coord[0][0] >> codsty->log2_prec_width);
+
+ if (reslevel->coord[1][1] == reslevel->coord[1][0])
+ reslevel->num_precincts_y = 0;
+ else
+ reslevel->num_precincts_y = ff_j2k_ceildivpow2(reslevel->coord[1][1], codsty->log2_prec_height)
+ - (reslevel->coord[1][0] >> codsty->log2_prec_height);
+
+ reslevel->band = av_malloc(reslevel->nbands * sizeof(J2kBand));
+ if (!reslevel->band)
+ return AVERROR(ENOMEM);
+ for (bandno = 0; bandno < reslevel->nbands; bandno++, gbandno++){
+ J2kBand *band = reslevel->band + bandno;
+ int cblkno, precx, precy, precno;
+ int x0, y0, x1, y1;
+ int xi0, yi0, xi1, yi1;
+ int cblkperprecw, cblkperprech;
+
+ if (qntsty->quantsty != J2K_QSTY_NONE){
+ const static uint8_t lut_gain[2][4] = {{0, 0, 0, 0}, {0, 1, 1, 2}};
+ int numbps;
+
+ numbps = cbps + lut_gain[codsty->transform][bandno + reslevelno>0];
+ band->stepsize = SHL(2048 + qntsty->mant[gbandno], 2 + numbps - qntsty->expn[gbandno]);
+ } else
+ band->stepsize = 1 << 13;
+
+ if (reslevelno == 0){ // the same everywhere
+ band->codeblock_width = 1 << FFMIN(codsty->log2_cblk_width, codsty->log2_prec_width-1);
+ band->codeblock_height = 1 << FFMIN(codsty->log2_cblk_height, codsty->log2_prec_height-1);
+ for (i = 0; i < 2; i++)
+ for (j = 0; j < 2; j++)
+ band->coord[i][j] = ff_j2k_ceildivpow2(comp->coord[i][j], declvl-1);
+ } else{
+ band->codeblock_width = 1 << FFMIN(codsty->log2_cblk_width, codsty->log2_prec_width);
+ band->codeblock_height = 1 << FFMIN(codsty->log2_cblk_height, codsty->log2_prec_height);
+
+ for (i = 0; i < 2; i++)
+ for (j = 0; j < 2; j++)
+ band->coord[i][j] = ff_j2k_ceildivpow2(comp->coord[i][j] - (((bandno+1>>i)&1) << declvl-1), declvl);
+ }
+ band->cblknx = ff_j2k_ceildiv(band->coord[0][1], band->codeblock_width) - band->coord[0][0] / band->codeblock_width;
+ band->cblkny = ff_j2k_ceildiv(band->coord[1][1], band->codeblock_height) - band->coord[1][0] / band->codeblock_height;
+
+ for (j = 0; j < 2; j++)
+ band->coord[0][j] = ff_j2k_ceildiv(band->coord[0][j], dx);
+ for (j = 0; j < 2; j++)
+ band->coord[1][j] = ff_j2k_ceildiv(band->coord[1][j], dy);
+
+ band->cblknx = ff_j2k_ceildiv(band->cblknx, dx);
+ band->cblkny = ff_j2k_ceildiv(band->cblkny, dy);
+
+ band->cblk = av_malloc(band->cblknx * band->cblkny * sizeof(J2kCblk));
+ if (!band->cblk)
+ return AVERROR(ENOMEM);
+ band->prec = av_malloc(reslevel->num_precincts_x * reslevel->num_precincts_y * sizeof(J2kPrec));
+ if (!band->prec)
+ return AVERROR(ENOMEM);
+
+ for (cblkno = 0; cblkno < band->cblknx * band->cblkny; cblkno++){
+ J2kCblk *cblk = band->cblk + cblkno;
+ cblk->zero = 0;
+ cblk->lblock = 3;
+ cblk->length = 0;
+ cblk->lengthinc = 0;
+ cblk->npasses = 0;
+ }
+
+ y0 = band->coord[1][0];
+ y1 = ((band->coord[1][0] + (1<<codsty->log2_prec_height)) & ~((1<<codsty->log2_prec_height)-1)) - y0;
+ yi0 = 0;
+ yi1 = ff_j2k_ceildivpow2(y1 - y0, codsty->log2_cblk_height) << codsty->log2_cblk_height;
+ yi1 = FFMIN(yi1, band->cblkny);
+ cblkperprech = 1<<(codsty->log2_prec_height - codsty->log2_cblk_height);
+ for (precy = 0, precno = 0; precy < reslevel->num_precincts_y; precy++){
+ for (precx = 0; precx < reslevel->num_precincts_x; precx++, precno++){
+ band->prec[precno].yi0 = yi0;
+ band->prec[precno].yi1 = yi1;
+ }
+ yi1 += cblkperprech;
+ yi0 = yi1 - cblkperprech;
+ yi1 = FFMIN(yi1, band->cblkny);
+ }
+ x0 = band->coord[0][0];
+ x1 = ((band->coord[0][0] + (1<<codsty->log2_prec_width)) & ~((1<<codsty->log2_prec_width)-1)) - x0;
+ xi0 = 0;
+ xi1 = ff_j2k_ceildivpow2(x1 - x0, codsty->log2_cblk_width) << codsty->log2_cblk_width;
+ xi1 = FFMIN(xi1, band->cblknx);
+
+ cblkperprecw = 1<<(codsty->log2_prec_width - codsty->log2_cblk_width);
+ for (precx = 0, precno = 0; precx < reslevel->num_precincts_x; precx++){
+ for (precy = 0; precy < reslevel->num_precincts_y; precy++, precno = 0){
+ J2kPrec *prec = band->prec + precno;
+ prec->xi0 = xi0;
+ prec->xi1 = xi1;
+ prec->cblkincl = ff_j2k_tag_tree_init(prec->xi1 - prec->xi0,
+ prec->yi1 - prec->yi0);
+ prec->zerobits = ff_j2k_tag_tree_init(prec->xi1 - prec->xi0,
+ prec->yi1 - prec->yi0);
+ if (!prec->cblkincl || !prec->zerobits)
+ return AVERROR(ENOMEM);
+
+ }
+ xi1 += cblkperprecw;
+ xi0 = xi1 - cblkperprecw;
+ xi1 = FFMIN(xi1, band->cblknx);
+ }
+ }
+ }
+ return 0;
+}
+
+void ff_j2k_reinit(J2kComponent *comp, J2kCodingStyle *codsty)
+{
+ int reslevelno, bandno, cblkno, precno;
+ for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++){
+ J2kResLevel *rlevel = comp->reslevel + reslevelno;
+ for (bandno = 0; bandno < rlevel->nbands; bandno++){
+ J2kBand *band = rlevel->band + bandno;
+ for(precno = 0; precno < rlevel->num_precincts_x * rlevel->num_precincts_y; precno++){
+ J2kPrec *prec = band->prec + precno;
+ tag_tree_zero(prec->zerobits, prec->xi1 - prec->xi0, prec->yi1 - prec->yi0);
+ tag_tree_zero(prec->cblkincl, prec->xi1 - prec->xi0, prec->yi1 - prec->yi0);
+ }
+ for (cblkno = 0; cblkno < band->cblknx * band->cblkny; cblkno++){
+ J2kCblk *cblk = band->cblk + cblkno;
+ cblk->length = 0;
+ cblk->lblock = 3;
+ }
+ }
+ }
+}
+
+void ff_j2k_cleanup(J2kComponent *comp, J2kCodingStyle *codsty)
+{
+ int reslevelno, bandno, precno;
+ for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++){
+ J2kResLevel *reslevel = comp->reslevel + reslevelno;
+
+ for (bandno = 0; bandno < reslevel->nbands ; bandno++){
+ J2kBand *band = reslevel->band + bandno;
+ for (precno = 0; precno < reslevel->num_precincts_x * reslevel->num_precincts_y; precno++){
+ J2kPrec *prec = band->prec + precno;
+ av_freep(&prec->zerobits);
+ av_freep(&prec->cblkincl);
+ }
+ av_freep(&band->cblk);
+ av_freep(&band->prec);
+ }
+ av_freep(&reslevel->band);
+ }
+
+ ff_j2k_dwt_destroy(&comp->dwt);
+ av_freep(&comp->reslevel);
+ av_freep(&comp->data);
+}
diff --git a/libavcodec/j2k.h b/libavcodec/j2k.h
new file mode 100644
index 0000000000..85d5cd079c
--- /dev/null
+++ b/libavcodec/j2k.h
@@ -0,0 +1,234 @@
+/*
+ * JPEG2000 tables
+ * Copyright (c) 2007 Kamil Nowosad
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_J2K_H
+#define AVCODEC_J2K_H
+
+/**
+ * JPEG2000 tables
+ * @file
+ * @author Kamil Nowosad
+ */
+
+#include "mqc.h"
+#include "j2k_dwt.h"
+
+enum J2kMarkers{
+ J2K_SOC = 0xff4f, ///< start of codestream
+ J2K_SIZ = 0xff51, ///< image and tile size
+ J2K_COD, ///< coding style default
+ J2K_COC, ///< coding style component
+ J2K_TLM = 0xff55, ///< packed packet headers, tile-part header
+ J2K_PLM = 0xff57, ///< tile-part lengths
+ J2K_PLT, ///< packet length, main header
+ J2K_QCD = 0xff5c, ///< quantization default
+ J2K_QCC, ///< quantization component
+ J2K_RGN, ///< region of interest
+ J2K_POC, ///< progression order change
+ J2K_PPM, ///< packet length, tile-part header
+ J2K_PPT, ///< packed packet headers, main header
+ J2K_CRG = 0xff63, ///< component registration
+ J2K_COM, ///< comment
+ J2K_SOT = 0xff90, ///< start of tile-part
+ J2K_SOP, ///< start of packet
+ J2K_EPH, ///< end of packet header
+ J2K_SOD, ///< start of data
+ J2K_EOC = 0xffd9, ///< end of codestream
+};
+
+enum J2kQuantsty{ ///< quantization style
+ J2K_QSTY_NONE, ///< no quantization
+ J2K_QSTY_SI, ///< scalar derived
+ J2K_QSTY_SE ///< scalar expoounded
+};
+
+#define J2K_MAX_CBLKW 64
+#define J2K_MAX_CBLKH 64
+
+// T1 flags
+// flags determining significance of neighbour coefficients
+#define J2K_T1_SIG_N 0x0001
+#define J2K_T1_SIG_E 0x0002
+#define J2K_T1_SIG_W 0x0004
+#define J2K_T1_SIG_S 0x0008
+#define J2K_T1_SIG_NE 0x0010
+#define J2K_T1_SIG_NW 0x0020
+#define J2K_T1_SIG_SE 0x0040
+#define J2K_T1_SIG_SW 0x0080
+#define J2K_T1_SIG_NB (J2K_T1_SIG_N | J2K_T1_SIG_E | J2K_T1_SIG_S | J2K_T1_SIG_W \
+ |J2K_T1_SIG_NE | J2K_T1_SIG_NW | J2K_T1_SIG_SE | J2K_T1_SIG_SW)
+// flags determining sign bit of neighbour coefficients
+#define J2K_T1_SGN_N 0x0100
+#define J2K_T1_SGN_S 0x0200
+#define J2K_T1_SGN_W 0x0400
+#define J2K_T1_SGN_E 0x0800
+
+#define J2K_T1_VIS 0x1000
+#define J2K_T1_SIG 0x2000
+#define J2K_T1_REF 0x4000
+
+#define J2K_T1_SGN 0x8000
+
+// Codeblock coding styles
+#define J2K_CBLK_BYPASS 0x01 // Selective arithmetic coding bypass
+#define J2K_CBLK_RESET 0x02 // Reset context probabilities
+#define J2K_CBLK_TERMALL 0x04 // Terminate after each coding pass
+#define J2K_CBLK_VSC 0x08 // Vertical stripe causal context formation
+#define J2K_CBLK_PREDTERM 0x10 // Predictable termination
+#define J2K_CBLK_SEGSYM 0x20 // Segmentation symbols present
+
+// Coding styles
+#define J2K_CSTY_PREC 0x01 // Precincts defined in coding style
+#define J2K_CSTY_SOP 0x02 // SOP marker present
+#define J2K_CSTY_EPH 0x04 // EPH marker present
+
+typedef struct {
+ int data[J2K_MAX_CBLKW][J2K_MAX_CBLKH];
+ int flags[J2K_MAX_CBLKW+2][J2K_MAX_CBLKH+2];
+ MqcState mqc;
+} J2kT1Context;
+
+typedef struct J2kTgtNode {
+ uint8_t val;
+ uint8_t vis;
+ struct J2kTgtNode *parent;
+} J2kTgtNode;
+
+typedef struct {
+ uint8_t nreslevels; ///< number of resolution levels
+ uint8_t log2_cblk_width,
+ log2_cblk_height; ///< exponent of codeblock size
+ uint8_t transform; ///< DWT type
+ uint8_t csty; ///< coding style
+ uint8_t log2_prec_width,
+ log2_prec_height; ///< precinct size
+ uint8_t nlayers; ///< number of layers
+ uint8_t mct; ///< multiple component transformation
+ uint8_t cblk_style; ///< codeblock coding style
+} J2kCodingStyle;
+
+typedef struct {
+ uint8_t expn[32 * 3]; ///< quantization exponent
+ uint16_t mant[32 * 3]; ///< quantization mantissa
+ uint8_t quantsty; ///< quantization style
+ uint8_t nguardbits; ///< number of guard bits
+} J2kQuantStyle;
+
+typedef struct {
+ uint16_t rate;
+ int64_t disto;
+} J2kPass;
+
+typedef struct {
+ uint8_t npasses;
+ uint8_t ninclpasses; ///< number coding of passes included in codestream
+ uint8_t nonzerobits;
+ uint16_t length;
+ uint16_t lengthinc;
+ uint8_t lblock;
+ uint8_t zero;
+ uint8_t data[8192];
+ J2kPass passes[100];
+} J2kCblk; ///< code block
+
+typedef struct {
+ uint16_t xi0, xi1, yi0, yi1; ///< codeblock indexes ([xi0, xi1))
+ J2kTgtNode *zerobits;
+ J2kTgtNode *cblkincl;
+} J2kPrec; ///< precinct
+
+typedef struct {
+ uint16_t coord[2][2]; ///< border coordinates {{x0, x1}, {y0, y1}}
+ uint16_t codeblock_width, codeblock_height;
+ uint16_t cblknx, cblkny;
+ uint32_t stepsize; ///< quantization stepsize (* 2^13)
+ J2kPrec *prec;
+ J2kCblk *cblk;
+} J2kBand; ///< subband
+
+typedef struct {
+ uint8_t nbands;
+ uint16_t coord[2][2]; ///< border coordinates {{x0, x1}, {y0, y1}}
+ uint16_t num_precincts_x, num_precincts_y; ///< number of precincts in x/y direction
+ uint8_t log2_prec_width, log2_prec_height; ///< exponent of precinct size
+ J2kBand *band;
+} J2kResLevel; ///< resolution level
+
+typedef struct {
+ J2kResLevel *reslevel;
+ DWTContext dwt;
+ int *data;
+ uint16_t coord[2][2]; ///< border coordinates {{x0, x1}, {y0, y1}}
+} J2kComponent;
+
+/* debug routines */
+#if 0
+#undef fprintf
+#undef printf
+void ff_j2k_printv(int *tab, int l);
+void ff_j2k_printu(uint8_t *tab, int l);
+#endif
+
+/* misc tools */
+static inline int ff_j2k_ceildivpow2(int a, int b)
+{
+ return (a + (1 << b) - 1)>> b;
+}
+
+static inline int ff_j2k_ceildiv(int a, int b)
+{
+ return (a + b - 1) / b;
+}
+
+/* tag tree routines */
+J2kTgtNode *ff_j2k_tag_tree_init(int w, int h);
+
+/* TIER-1 routines */
+void ff_j2k_init_tier1_luts(void);
+
+void ff_j2k_set_significant(J2kT1Context *t1, int x, int y, int negative);
+
+extern uint8_t ff_j2k_nbctxno_lut[256][4];
+
+static inline int ff_j2k_getnbctxno(int flag, int bandno, int vert_causal_ctx_csty_symbol)
+{
+ return ff_j2k_nbctxno_lut[flag&255][bandno];
+}
+
+static inline int ff_j2k_getrefctxno(int flag)
+{
+ static const uint8_t refctxno_lut[2][2] = {{14, 15}, {16, 16}};
+ return refctxno_lut[(flag>>14)&1][(flag & 255) != 0];
+}
+
+extern uint8_t ff_j2k_sgnctxno_lut[16][16], ff_j2k_xorbit_lut[16][16];
+
+static inline int ff_j2k_getsgnctxno(int flag, int *xorbit)
+{
+ *xorbit = ff_j2k_xorbit_lut[flag&15][(flag>>8)&15];
+ return ff_j2k_sgnctxno_lut[flag&15][(flag>>8)&15];
+}
+
+int ff_j2k_init_component(J2kComponent *comp, J2kCodingStyle *codsty, J2kQuantStyle *qntsty, int cbps, int dx, int dy);
+void ff_j2k_reinit(J2kComponent *comp, J2kCodingStyle *codsty);
+void ff_j2k_cleanup(J2kComponent *comp, J2kCodingStyle *codsty);
+
+#endif /* AVCODEC_J2K_H */
diff --git a/libavcodec/j2k_dwt.c b/libavcodec/j2k_dwt.c
new file mode 100644
index 0000000000..ab7a1ab757
--- /dev/null
+++ b/libavcodec/j2k_dwt.c
@@ -0,0 +1,386 @@
+/*
+ * Discrete wavelet transform
+ * Copyright (c) 2007 Kamil Nowosad
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * Discrete wavelet transform
+ * @file
+ * @author Kamil Nowosad
+ */
+
+#include "j2k_dwt.h"
+
+const static float scale97[] = {1.625786, 1.230174};
+
+static inline void extend53(int *p, int i0, int i1)
+{
+ p[i0 - 1] = p[i0 + 1];
+ p[i1 ] = p[i1 - 2];
+ p[i0 - 2] = p[i0 + 2];
+ p[i1 + 1] = p[i1 - 3];
+}
+
+static inline void extend97(float *p, int i0, int i1)
+{
+ int i;
+
+ for (i = 1; i <= 4; i++){
+ p[i0 - i] = p[i0 + i];
+ p[i1 + i - 1] = p[i1 - i - 1];
+ }
+}
+
+static void sd_1d53(int *p, int i0, int i1)
+{
+ int i;
+
+ if (i1 == i0 + 1)
+ return;
+
+ extend53(p, i0, i1);
+
+ for (i = (i0+1)/2 - 1; i < (i1+1)/2; i++)
+ p[2*i+1] -= (p[2*i] + p[2*i+2]) >> 1;
+ for (i = (i0+1)/2; i < (i1+1)/2; i++)
+ p[2*i] += (p[2*i-1] + p[2*i+1] + 2) >> 2;
+}
+
+static void dwt_encode53(DWTContext *s, int *t)
+{
+ int lev,
+ w = s->linelen[s->ndeclevels-1][0];
+ int *line = s->linebuf;
+ line += 3;
+
+ for (lev = s->ndeclevels-1; lev >= 0; lev--){
+ int lh = s->linelen[lev][0],
+ lv = s->linelen[lev][1],
+ mh = s->mod[lev][0],
+ mv = s->mod[lev][1],
+ lp;
+ int *l;
+
+ // HOR_SD
+ l = line + mh;
+ for (lp = 0; lp < lv; lp++){
+ int i, j = 0;
+
+ for (i = 0; i < lh; i++)
+ l[i] = t[w*lp + i];
+
+ sd_1d53(line, mh, mh + lh);
+
+ // copy back and deinterleave
+ for (i = mh; i < lh; i+=2, j++)
+ t[w*lp + j] = l[i];
+ for (i = 1-mh; i < lh; i+=2, j++)
+ t[w*lp + j] = l[i];
+ }
+
+ // VER_SD
+ l = line + mv;
+ for (lp = 0; lp < lh; lp++) {
+ int i, j = 0;
+
+ for (i = 0; i < lv; i++)
+ l[i] = t[w*i + lp];
+
+ sd_1d53(line, mv, mv + lv);
+
+ // copy back and deinterleave
+ for (i = mv; i < lv; i+=2, j++)
+ t[w*j + lp] = l[i];
+ for (i = 1-mv; i < lv; i+=2, j++)
+ t[w*j + lp] = l[i];
+ }
+ }
+}
+
+static void sd_1d97(float *p, int i0, int i1)
+{
+ int i;
+
+ if (i1 == i0 + 1)
+ return;
+
+ extend97(p, i0, i1);
+ i0++; i1++;
+
+ for (i = i0/2 - 2; i < i1/2 + 1; i++)
+ p[2*i+1] -= 1.586134 * (p[2*i] + p[2*i+2]);
+ for (i = i0/2 - 1; i < i1/2 + 1; i++)
+ p[2*i] -= 0.052980 * (p[2*i-1] + p[2*i+1]);
+ for (i = i0/2 - 1; i < i1/2; i++)
+ p[2*i+1] += 0.882911 * (p[2*i] + p[2*i+2]);
+ for (i = i0/2; i < i1/2; i++)
+ p[2*i] += 0.443506 * (p[2*i-1] + p[2*i+1]);
+}
+
+static void dwt_encode97(DWTContext *s, int *t)
+{
+ int lev,
+ w = s->linelen[s->ndeclevels-1][0];
+ float *line = s->linebuf;
+ line += 5;
+
+ for (lev = s->ndeclevels-1; lev >= 0; lev--){
+ int lh = s->linelen[lev][0],
+ lv = s->linelen[lev][1],
+ mh = s->mod[lev][0],
+ mv = s->mod[lev][1],
+ lp;
+ float *l;
+
+ // HOR_SD
+ l = line + mh;
+ for (lp = 0; lp < lv; lp++){
+ int i, j = 0;
+
+ for (i = 0; i < lh; i++)
+ l[i] = t[w*lp + i];
+
+ sd_1d97(line, mh, mh + lh);
+
+ // copy back and deinterleave
+ for (i = mh; i < lh; i+=2, j++)
+ t[w*lp + j] = scale97[mh] * l[i] / 2;
+ for (i = 1-mh; i < lh; i+=2, j++)
+ t[w*lp + j] = scale97[mh] * l[i] / 2;
+ }
+
+ // VER_SD
+ l = line + mv;
+ for (lp = 0; lp < lh; lp++) {
+ int i, j = 0;
+
+ for (i = 0; i < lv; i++)
+ l[i] = t[w*i + lp];
+
+ sd_1d97(line, mv, mv + lv);
+
+ // copy back and deinterleave
+ for (i = mv; i < lv; i+=2, j++)
+ t[w*j + lp] = scale97[mv] * l[i] / 2;
+ for (i = 1-mv; i < lv; i+=2, j++)
+ t[w*j + lp] = scale97[mv] * l[i] / 2;
+ }
+ }
+}
+
+static void sr_1d53(int *p, int i0, int i1)
+{
+ int i;
+
+ if (i1 == i0 + 1)
+ return;
+
+ extend53(p, i0, i1);
+
+ for (i = i0/2; i < i1/2 + 1; i++)
+ p[2*i] -= (p[2*i-1] + p[2*i+1] + 2) >> 2;
+ for (i = i0/2; i < i1/2; i++)
+ p[2*i+1] += (p[2*i] + p[2*i+2]) >> 1;
+}
+
+static void dwt_decode53(DWTContext *s, int *t)
+{
+ int lev,
+ w = s->linelen[s->ndeclevels-1][0];
+ int *line = s->linebuf;
+ line += 3;
+
+ for (lev = 0; lev < s->ndeclevels; lev++){
+ int lh = s->linelen[lev][0],
+ lv = s->linelen[lev][1],
+ mh = s->mod[lev][0],
+ mv = s->mod[lev][1],
+ lp;
+ int *l;
+
+ // HOR_SD
+ l = line + mh;
+ for (lp = 0; lp < lv; lp++){
+ int i, j = 0;
+ // copy with interleaving
+ for (i = mh; i < lh; i+=2, j++)
+ l[i] = t[w*lp + j];
+ for (i = 1-mh; i < lh; i+=2, j++)
+ l[i] = t[w*lp + j];
+
+ sr_1d53(line, mh, mh + lh);
+
+ for (i = 0; i < lh; i++)
+ t[w*lp + i] = l[i];
+ }
+
+ // VER_SD
+ l = line + mv;
+ for (lp = 0; lp < lh; lp++){
+ int i, j = 0;
+ // copy with interleaving
+ for (i = mv; i < lv; i+=2, j++)
+ l[i] = t[w*j + lp];
+ for (i = 1-mv; i < lv; i+=2, j++)
+ l[i] = t[w*j + lp];
+
+ sr_1d53(line, mv, mv + lv);
+
+ for (i = 0; i < lv; i++)
+ t[w*i + lp] = l[i];
+ }
+ }
+}
+
+static void sr_1d97(float *p, int i0, int i1)
+{
+ int i;
+
+ if (i1 == i0 + 1)
+ return;
+
+ extend97(p, i0, i1);
+
+ for (i = i0/2 - 1; i < i1/2 + 2; i++)
+ p[2*i] -= 0.443506 * (p[2*i-1] + p[2*i+1]);
+ for (i = i0/2 - 1; i < i1/2 + 1; i++)
+ p[2*i+1] -= 0.882911 * (p[2*i] + p[2*i+2]);
+ for (i = i0/2; i < i1/2 + 1; i++)
+ p[2*i] += 0.052980 * (p[2*i-1] + p[2*i+1]);
+ for (i = i0/2; i < i1/2; i++)
+ p[2*i+1] += 1.586134 * (p[2*i] + p[2*i+2]);
+}
+
+static void dwt_decode97(DWTContext *s, int *t)
+{
+ int lev,
+ w = s->linelen[s->ndeclevels-1][0];
+ float *line = s->linebuf;
+ line += 5;
+
+ for (lev = 0; lev < s->ndeclevels; lev++){
+ int lh = s->linelen[lev][0],
+ lv = s->linelen[lev][1],
+ mh = s->mod[lev][0],
+ mv = s->mod[lev][1],
+ lp;
+ float *l;
+
+ // HOR_SD
+ l = line + mh;
+ for (lp = 0; lp < lv; lp++){
+ int i, j = 0;
+ // copy with interleaving
+ for (i = mh; i < lh; i+=2, j++)
+ l[i] = scale97[1-mh] * t[w*lp + j];
+ for (i = 1-mh; i < lh; i+=2, j++)
+ l[i] = scale97[1-mh] * t[w*lp + j];
+
+ sr_1d97(line, mh, mh + lh);
+
+ for (i = 0; i < lh; i++)
+ t[w*lp + i] = l[i];
+ }
+
+ // VER_SD
+ l = line + mv;
+ for (lp = 0; lp < lh; lp++){
+ int i, j = 0;
+ // copy with interleaving
+ for (i = mv; i < lv; i+=2, j++)
+ l[i] = scale97[1-mv] * t[w*j + lp];
+ for (i = 1-mv; i < lv; i+=2, j++)
+ l[i] = scale97[1-mv] * t[w*j + lp];
+
+ sr_1d97(line, mv, mv + lv);
+
+ for (i = 0; i < lv; i++)
+ t[w*i + lp] = l[i];
+ }
+ }
+}
+
+int ff_j2k_dwt_init(DWTContext *s, uint16_t border[2][2], int decomp_levels, int type)
+{
+ int i, j, lev = decomp_levels, maxlen,
+ b[2][2];
+
+ if (decomp_levels >= FF_DWT_MAX_DECLVLS)
+ return AVERROR_INVALIDDATA;
+ s->ndeclevels = decomp_levels;
+ s->type = type;
+
+ for (i = 0; i < 2; i++)
+ for(j = 0; j < 2; j++)
+ b[i][j] = border[i][j];
+
+ maxlen = FFMAX(b[0][1] - b[0][0],
+ b[1][1] - b[1][0]);
+
+ while(--lev >= 0){
+ for (i = 0; i < 2; i++){
+ s->linelen[lev][i] = b[i][1] - b[i][0];
+ s->mod[lev][i] = b[i][0] & 1;
+ for (j = 0; j < 2; j++)
+ b[i][j] = (b[i][j] + 1) >> 1;
+ }
+ }
+ if (type == FF_DWT97)
+ s->linebuf = av_malloc((maxlen + 12) * sizeof(float));
+ else if (type == FF_DWT53)
+ s->linebuf = av_malloc((maxlen + 6) * sizeof(int));
+ else
+ return -1;
+
+ if (!s->linebuf)
+ return AVERROR(ENOMEM);
+
+ return 0;
+}
+
+int ff_j2k_dwt_encode(DWTContext *s, int *t)
+{
+ switch(s->type){
+ case FF_DWT97:
+ dwt_encode97(s, t); break;
+ case FF_DWT53:
+ dwt_encode53(s, t); break;
+ default:
+ return -1;
+ }
+ return 0;
+}
+
+int ff_j2k_dwt_decode(DWTContext *s, int *t)
+{
+ switch(s->type){
+ case FF_DWT97:
+ dwt_decode97(s, t); break;
+ case FF_DWT53:
+ dwt_decode53(s, t); break;
+ default:
+ return -1;
+ }
+ return 0;
+}
+
+void ff_j2k_dwt_destroy(DWTContext *s)
+{
+ av_freep(&s->linebuf);
+}
diff --git a/libavcodec/j2k_dwt.h b/libavcodec/j2k_dwt.h
new file mode 100644
index 0000000000..a2a25a6891
--- /dev/null
+++ b/libavcodec/j2k_dwt.h
@@ -0,0 +1,63 @@
+/*
+ * Discrete wavelet transform
+ * Copyright (c) 2007 Kamil Nowosad
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_DWT_H
+#define AVCODEC_DWT_H
+
+/**
+ * Discrete wavelet transform
+ * @file
+ * @author Kamil Nowosad
+ */
+
+#include "avcodec.h"
+
+#define FF_DWT_MAX_DECLVLS 32 ///< max number of decomposition levels
+
+enum DWTType{
+ FF_DWT97,
+ FF_DWT53
+};
+
+typedef struct {
+ ///line lengths {horizontal, vertical} in consecutive decomposition levels
+ uint16_t linelen[FF_DWT_MAX_DECLVLS][2];
+ uint8_t mod[FF_DWT_MAX_DECLVLS][2]; ///< coordinates (x0, y0) of decomp. levels mod 2
+ uint8_t ndeclevels; ///< number of decomposition levels
+ uint8_t type; ///< 0 for 9/7; 1 for 5/3
+ void *linebuf; ///< buffer used by transform (int or float)
+} DWTContext;
+
+/**
+ * initialize DWT
+ * @param s DWT context
+ * @param border coordinates of transformed region {{x0, x1}, {y0, y1}}
+ * @param decomp_levels number of decomposition levels
+ * @param type 0 for DWT 9/7; 1 for DWT 5/3
+ */
+int ff_j2k_dwt_init(DWTContext *s, uint16_t border[2][2], int decomp_levels, int type);
+
+int ff_j2k_dwt_encode(DWTContext *s, int *t);
+int ff_j2k_dwt_decode(DWTContext *s, int *t);
+
+void ff_j2k_dwt_destroy(DWTContext *s);
+
+#endif /* AVCODEC_DWT_H */
diff --git a/libavcodec/j2kdec.c b/libavcodec/j2kdec.c
new file mode 100644
index 0000000000..01a1e2e399
--- /dev/null
+++ b/libavcodec/j2kdec.c
@@ -0,0 +1,1071 @@
+/*
+ * JPEG2000 image decoder
+ * Copyright (c) 2007 Kamil Nowosad
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * JPEG2000 image decoder
+ * @file
+ * @author Kamil Nowosad
+ */
+
+#include "avcodec.h"
+#include "bytestream.h"
+#include "j2k.h"
+#include "libavutil/common.h"
+
+#define JP2_SIG_TYPE 0x6A502020
+#define JP2_SIG_VALUE 0x0D0A870A
+#define JP2_CODESTREAM 0x6A703263
+
+#define HAD_COC 0x01
+#define HAD_QCC 0x02
+
+typedef struct {
+ J2kComponent *comp;
+ uint8_t properties[4];
+ J2kCodingStyle codsty[4];
+ J2kQuantStyle qntsty[4];
+} J2kTile;
+
+typedef struct {
+ AVCodecContext *avctx;
+ AVFrame picture;
+
+ int width, height; ///< image width and height
+ int image_offset_x, image_offset_y;
+ int tile_offset_x, tile_offset_y;
+ uint8_t cbps[4]; ///< bits per sample in particular components
+ uint8_t sgnd[4]; ///< if a component is signed
+ uint8_t properties[4];
+ int cdx[4], cdy[4];
+ int precision;
+ int ncomponents;
+ int tile_width, tile_height; ///< tile size
+ int numXtiles, numYtiles;
+ int maxtilelen;
+
+ J2kCodingStyle codsty[4];
+ J2kQuantStyle qntsty[4];
+
+ uint8_t *buf_start;
+ uint8_t *buf;
+ uint8_t *buf_end;
+ int bit_index;
+
+ int16_t curtileno;
+
+ J2kTile *tile;
+} J2kDecoderContext;
+
+static int get_bits(J2kDecoderContext *s, int n)
+{
+ int res = 0;
+ if (s->buf_end - s->buf < ((n - s->bit_index) >> 8))
+ return AVERROR(EINVAL);
+ while (--n >= 0){
+ res <<= 1;
+ if (s->bit_index == 0){
+ s->bit_index = 7 + (*s->buf != 0xff);
+ s->buf++;
+ }
+ s->bit_index--;
+ res |= (*s->buf >> s->bit_index) & 1;
+ }
+ return res;
+}
+
+static void j2k_flush(J2kDecoderContext *s)
+{
+ if (*s->buf == 0xff)
+ s->buf++;
+ s->bit_index = 8;
+ s->buf++;
+}
+#if 0
+void printcomp(J2kComponent *comp)
+{
+ int i;
+ for (i = 0; i < comp->y1 - comp->y0; i++)
+ ff_j2k_printv(comp->data + i * (comp->x1 - comp->x0), comp->x1 - comp->x0);
+}
+
+static void nspaces(FILE *fd, int n)
+{
+ while(n--) putc(' ', fd);
+}
+
+static void dump(J2kDecoderContext *s, FILE *fd)
+{
+ int tileno, compno, reslevelno, bandno, precno;
+ fprintf(fd, "XSiz = %d, YSiz = %d, tile_width = %d, tile_height = %d\n"
+ "numXtiles = %d, numYtiles = %d, ncomponents = %d\n"
+ "tiles:\n",
+ s->width, s->height, s->tile_width, s->tile_height,
+ s->numXtiles, s->numYtiles, s->ncomponents);
+ for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++){
+ J2kTile *tile = s->tile + tileno;
+ nspaces(fd, 2);
+ fprintf(fd, "tile %d:\n", tileno);
+ for(compno = 0; compno < s->ncomponents; compno++){
+ J2kComponent *comp = tile->comp + compno;
+ nspaces(fd, 4);
+ fprintf(fd, "component %d:\n", compno);
+ nspaces(fd, 4);
+ fprintf(fd, "x0 = %d, x1 = %d, y0 = %d, y1 = %d\n",
+ comp->x0, comp->x1, comp->y0, comp->y1);
+ for(reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++){
+ J2kResLevel *reslevel = comp->reslevel + reslevelno;
+ nspaces(fd, 6);
+ fprintf(fd, "reslevel %d:\n", reslevelno);
+ nspaces(fd, 6);
+ fprintf(fd, "x0 = %d, x1 = %d, y0 = %d, y1 = %d, nbands = %d\n",
+ reslevel->x0, reslevel->x1, reslevel->y0,
+ reslevel->y1, reslevel->nbands);
+ for(bandno = 0; bandno < reslevel->nbands; bandno++){
+ J2kBand *band = reslevel->band + bandno;
+ nspaces(fd, 8);
+ fprintf(fd, "band %d:\n", bandno);
+ nspaces(fd, 8);
+ fprintf(fd, "x0 = %d, x1 = %d, y0 = %d, y1 = %d,"
+ "codeblock_width = %d, codeblock_height = %d cblknx = %d cblkny = %d\n",
+ band->x0, band->x1,
+ band->y0, band->y1,
+ band->codeblock_width, band->codeblock_height,
+ band->cblknx, band->cblkny);
+ for (precno = 0; precno < reslevel->num_precincts_x * reslevel->num_precincts_y; precno++){
+ J2kPrec *prec = band->prec + precno;
+ nspaces(fd, 10);
+ fprintf(fd, "prec %d:\n", precno);
+ nspaces(fd, 10);
+ fprintf(fd, "xi0 = %d, xi1 = %d, yi0 = %d, yi1 = %d\n",
+ prec->xi0, prec->xi1, prec->yi0, prec->yi1);
+ }
+ }
+ }
+ }
+ }
+}
+#endif
+
+/** decode the value stored in node */
+static int tag_tree_decode(J2kDecoderContext *s, J2kTgtNode *node, int threshold)
+{
+ J2kTgtNode *stack[30];
+ int sp = -1, curval = 0;
+
+ while(node && !node->vis){
+ stack[++sp] = node;
+ node = node->parent;
+ }
+
+ if (node)
+ curval = node->val;
+ else
+ curval = stack[sp]->val;
+
+ while(curval < threshold && sp >= 0){
+ if (curval < stack[sp]->val)
+ curval = stack[sp]->val;
+ while (curval < threshold){
+ int ret;
+ if ((ret = get_bits(s, 1)) > 0){
+ stack[sp]->vis++;
+ break;
+ } else if (!ret)
+ curval++;
+ else
+ return ret;
+ }
+ stack[sp]->val = curval;
+ sp--;
+ }
+ return curval;
+}
+
+/* marker segments */
+/** get sizes and offsets of image, tiles; number of components */
+static int get_siz(J2kDecoderContext *s)
+{
+ int i, ret;
+
+ if (s->buf_end - s->buf < 36)
+ return AVERROR(EINVAL);
+
+ bytestream_get_be16(&s->buf); // Rsiz (skipped)
+ s->width = bytestream_get_be32(&s->buf); // width
+ s->height = bytestream_get_be32(&s->buf); // height
+ s->image_offset_x = bytestream_get_be32(&s->buf); // X0Siz
+ s->image_offset_y = bytestream_get_be32(&s->buf); // Y0Siz
+
+ s->tile_width = bytestream_get_be32(&s->buf); // XTSiz
+ s->tile_height = bytestream_get_be32(&s->buf); // YTSiz
+ s->tile_offset_x = bytestream_get_be32(&s->buf); // XT0Siz
+ s->tile_offset_y = bytestream_get_be32(&s->buf); // YT0Siz
+ s->ncomponents = bytestream_get_be16(&s->buf); // CSiz
+
+ if (s->buf_end - s->buf < 2 * s->ncomponents)
+ return AVERROR(EINVAL);
+
+ for (i = 0; i < s->ncomponents; i++){ // Ssiz_i XRsiz_i, YRsiz_i
+ uint8_t x = bytestream_get_byte(&s->buf);
+ s->cbps[i] = (x & 0x7f) + 1;
+ s->precision = FFMAX(s->cbps[i], s->precision);
+ s->sgnd[i] = (x & 0x80) == 1;
+ s->cdx[i] = bytestream_get_byte(&s->buf);
+ s->cdy[i] = bytestream_get_byte(&s->buf);
+ }
+
+ s->numXtiles = ff_j2k_ceildiv(s->width - s->tile_offset_x, s->tile_width);
+ s->numYtiles = ff_j2k_ceildiv(s->height - s->tile_offset_y, s->tile_height);
+
+ s->tile = av_mallocz(s->numXtiles * s->numYtiles * sizeof(J2kTile));
+ if (!s->tile)
+ return AVERROR(ENOMEM);
+
+ for (i = 0; i < s->numXtiles * s->numYtiles; i++){
+ J2kTile *tile = s->tile + i;
+
+ tile->comp = av_mallocz(s->ncomponents * sizeof(J2kComponent));
+ if (!tile->comp)
+ return AVERROR(ENOMEM);
+ }
+
+ s->avctx->width = s->width - s->image_offset_x;
+ s->avctx->height = s->height - s->image_offset_y;
+
+ switch(s->ncomponents){
+ case 1: if (s->precision > 8) {
+ s->avctx->pix_fmt = PIX_FMT_GRAY16;
+ } else s->avctx->pix_fmt = PIX_FMT_GRAY8;
+ break;
+ case 3: if (s->precision > 8) {
+ s->avctx->pix_fmt = PIX_FMT_RGB48;
+ } else s->avctx->pix_fmt = PIX_FMT_RGB24;
+ break;
+ case 4: s->avctx->pix_fmt = PIX_FMT_BGRA; break;
+ }
+
+ if (s->picture.data[0])
+ s->avctx->release_buffer(s->avctx, &s->picture);
+
+ if ((ret = s->avctx->get_buffer(s->avctx, &s->picture)) < 0)
+ return ret;
+
+ s->picture.pict_type = FF_I_TYPE;
+ s->picture.key_frame = 1;
+
+ return 0;
+}
+
+/** get common part for COD and COC segments */
+static int get_cox(J2kDecoderContext *s, J2kCodingStyle *c)
+{
+ if (s->buf_end - s->buf < 5)
+ return AVERROR(EINVAL);
+ c->nreslevels = bytestream_get_byte(&s->buf) + 1; // num of resolution levels - 1
+ c->log2_cblk_width = bytestream_get_byte(&s->buf) + 2; // cblk width
+ c->log2_cblk_height = bytestream_get_byte(&s->buf) + 2; // cblk height
+
+ c->cblk_style = bytestream_get_byte(&s->buf);
+ if (c->cblk_style != 0){ // cblk style
+ av_log(s->avctx, AV_LOG_WARNING, "extra cblk styles %X\n", c->cblk_style);
+ }
+ c->transform = bytestream_get_byte(&s->buf); // transformation
+ if (c->csty & J2K_CSTY_PREC) {
+ int i;
+ for (i = 0; i < c->nreslevels; i++)
+ bytestream_get_byte(&s->buf);
+ }
+ return 0;
+}
+
+/** get coding parameters for a particular tile or whole image*/
+static int get_cod(J2kDecoderContext *s, J2kCodingStyle *c, uint8_t *properties)
+{
+ J2kCodingStyle tmp;
+ int compno;
+
+ if (s->buf_end - s->buf < 5)
+ return AVERROR(EINVAL);
+
+ tmp.log2_prec_width =
+ tmp.log2_prec_height = 15;
+
+ tmp.csty = bytestream_get_byte(&s->buf);
+
+ if (bytestream_get_byte(&s->buf)){ // progression level
+ av_log(s->avctx, AV_LOG_ERROR, "only LRCP progression supported\n");
+ return -1;
+ }
+
+ tmp.nlayers = bytestream_get_be16(&s->buf);
+ tmp.mct = bytestream_get_byte(&s->buf); // multiple component transformation
+
+ get_cox(s, &tmp);
+ for (compno = 0; compno < s->ncomponents; compno++){
+ if (!(properties[compno] & HAD_COC))
+ memcpy(c + compno, &tmp, sizeof(J2kCodingStyle));
+ }
+ return 0;
+}
+
+/** get coding parameters for a component in the whole image on a particular tile */
+static int get_coc(J2kDecoderContext *s, J2kCodingStyle *c, uint8_t *properties)
+{
+ int compno;
+
+ if (s->buf_end - s->buf < 2)
+ return AVERROR(EINVAL);
+
+ compno = bytestream_get_byte(&s->buf);
+
+ c += compno;
+ c->csty = bytestream_get_byte(&s->buf);
+ get_cox(s, c);
+
+ properties[compno] |= HAD_COC;
+ return 0;
+}
+
+/** get common part for QCD and QCC segments */
+static int get_qcx(J2kDecoderContext *s, int n, J2kQuantStyle *q)
+{
+ int i, x;
+
+ if (s->buf_end - s->buf < 1)
+ return AVERROR(EINVAL);
+
+ x = bytestream_get_byte(&s->buf); // Sqcd
+
+ q->nguardbits = x >> 5;
+ q->quantsty = x & 0x1f;
+
+ if (q->quantsty == J2K_QSTY_NONE){
+ n -= 3;
+ if (s->buf_end - s->buf < n)
+ return AVERROR(EINVAL);
+ for (i = 0; i < n; i++)
+ q->expn[i] = bytestream_get_byte(&s->buf) >> 3;
+ } else if (q->quantsty == J2K_QSTY_SI){
+ if (s->buf_end - s->buf < 2)
+ return AVERROR(EINVAL);
+ x = bytestream_get_be16(&s->buf);
+ q->expn[0] = x >> 11;
+ q->mant[0] = x & 0x7ff;
+ for (i = 1; i < 32 * 3; i++){
+ int curexpn = FFMAX(0, q->expn[0] - (i-1)/3);
+ q->expn[i] = curexpn;
+ q->mant[i] = q->mant[0];
+ }
+ } else{
+ n = (n - 3) >> 1;
+ if (s->buf_end - s->buf < n)
+ return AVERROR(EINVAL);
+ for (i = 0; i < n; i++){
+ x = bytestream_get_be16(&s->buf);
+ q->expn[i] = x >> 11;
+ q->mant[i] = x & 0x7ff;
+ }
+ }
+ return 0;
+}
+
+/** get quantization parameters for a particular tile or a whole image */
+static int get_qcd(J2kDecoderContext *s, int n, J2kQuantStyle *q, uint8_t *properties)
+{
+ J2kQuantStyle tmp;
+ int compno;
+
+ if (get_qcx(s, n, &tmp))
+ return -1;
+ for (compno = 0; compno < s->ncomponents; compno++)
+ if (!(properties[compno] & HAD_QCC))
+ memcpy(q + compno, &tmp, sizeof(J2kQuantStyle));
+ return 0;
+}
+
+/** get quantization parameters for a component in the whole image on in a particular tile */
+static int get_qcc(J2kDecoderContext *s, int n, J2kQuantStyle *q, uint8_t *properties)
+{
+ int compno;
+
+ if (s->buf_end - s->buf < 1)
+ return AVERROR(EINVAL);
+
+ compno = bytestream_get_byte(&s->buf);
+ properties[compno] |= HAD_QCC;
+ return get_qcx(s, n-1, q+compno);
+}
+
+/** get start of tile segment */
+static uint8_t get_sot(J2kDecoderContext *s)
+{
+ if (s->buf_end - s->buf < 4)
+ return AVERROR(EINVAL);
+
+ s->curtileno = bytestream_get_be16(&s->buf); ///< Isot
+
+ s->buf += 4; ///< Psot (ignored)
+
+ if (!bytestream_get_byte(&s->buf)){ ///< TPsot
+ J2kTile *tile = s->tile + s->curtileno;
+
+ /* copy defaults */
+ memcpy(tile->codsty, s->codsty, s->ncomponents * sizeof(J2kCodingStyle));
+ memcpy(tile->qntsty, s->qntsty, s->ncomponents * sizeof(J2kQuantStyle));
+ }
+ bytestream_get_byte(&s->buf); ///< TNsot
+
+ return 0;
+}
+
+static int init_tile(J2kDecoderContext *s, int tileno)
+{
+ int compno,
+ tilex = tileno % s->numXtiles,
+ tiley = tileno / s->numXtiles;
+ J2kTile *tile = s->tile + tileno;
+
+ if (!tile->comp)
+ return AVERROR(ENOMEM);
+ for (compno = 0; compno < s->ncomponents; compno++){
+ J2kComponent *comp = tile->comp + compno;
+ J2kCodingStyle *codsty = tile->codsty + compno;
+ J2kQuantStyle *qntsty = tile->qntsty + compno;
+ int ret; // global bandno
+
+ comp->coord[0][0] = FFMAX(tilex * s->tile_width + s->tile_offset_x, s->image_offset_x);
+ comp->coord[0][1] = FFMIN((tilex+1)*s->tile_width + s->tile_offset_x, s->width);
+ comp->coord[1][0] = FFMAX(tiley * s->tile_height + s->tile_offset_y, s->image_offset_y);
+ comp->coord[1][1] = FFMIN((tiley+1)*s->tile_height + s->tile_offset_y, s->height);
+
+ if (ret = ff_j2k_init_component(comp, codsty, qntsty, s->cbps[compno], s->cdx[compno], s->cdy[compno]))
+ return ret;
+ }
+ return 0;
+}
+
+/** read the number of coding passes */
+static int getnpasses(J2kDecoderContext *s)
+{
+ int num;
+ if (!get_bits(s, 1))
+ return 1;
+ if (!get_bits(s, 1))
+ return 2;
+ if ((num = get_bits(s, 2)) != 3)
+ return num < 0 ? num : 3 + num;
+ if ((num = get_bits(s, 5)) != 31)
+ return num < 0 ? num : 6 + num;
+ num = get_bits(s, 7);
+ return num < 0 ? num : 37 + num;
+}
+
+static int getlblockinc(J2kDecoderContext *s)
+{
+ int res = 0, ret;
+ while (ret = get_bits(s, 1)){
+ if (ret < 0)
+ return ret;
+ res++;
+ }
+ return res;
+}
+
+static int decode_packet(J2kDecoderContext *s, J2kCodingStyle *codsty, J2kResLevel *rlevel, int precno,
+ int layno, uint8_t *expn, int numgbits)
+{
+ int bandno, cblkny, cblknx, cblkno, ret;
+
+ if (!(ret = get_bits(s, 1))){
+ j2k_flush(s);
+ return 0;
+ } else if (ret < 0)
+ return ret;
+
+ for (bandno = 0; bandno < rlevel->nbands; bandno++){
+ J2kBand *band = rlevel->band + bandno;
+ J2kPrec *prec = band->prec + precno;
+ int pos = 0;
+
+ if (band->coord[0][0] == band->coord[0][1]
+ || band->coord[1][0] == band->coord[1][1])
+ continue;
+
+ for (cblkny = prec->yi0; cblkny < prec->yi1; cblkny++)
+ for(cblknx = prec->xi0, cblkno = cblkny * band->cblknx + cblknx; cblknx < prec->xi1; cblknx++, cblkno++, pos++){
+ J2kCblk *cblk = band->cblk + cblkno;
+ int incl, newpasses, llen;
+
+ if (cblk->npasses)
+ incl = get_bits(s, 1);
+ else
+ incl = tag_tree_decode(s, prec->cblkincl + pos, layno+1) == layno;
+ if (!incl)
+ continue;
+ else if (incl < 0)
+ return incl;
+
+ if (!cblk->npasses)
+ cblk->nonzerobits = expn[bandno] + numgbits - 1 - tag_tree_decode(s, prec->zerobits + pos, 100);
+ if ((newpasses = getnpasses(s)) < 0)
+ return newpasses;
+ if ((llen = getlblockinc(s)) < 0)
+ return llen;
+ cblk->lblock += llen;
+ if ((ret = get_bits(s, av_log2(newpasses) + cblk->lblock)) < 0)
+ return ret;
+ cblk->lengthinc = ret;
+ cblk->npasses += newpasses;
+ }
+ }
+ j2k_flush(s);
+
+ if (codsty->csty & J2K_CSTY_EPH) {
+ if (AV_RB16(s->buf) == J2K_EPH) {
+ s->buf += 2;
+ } else {
+ av_log(s->avctx, AV_LOG_ERROR, "EPH marker not found.\n");
+ }
+ }
+
+ for (bandno = 0; bandno < rlevel->nbands; bandno++){
+ J2kBand *band = rlevel->band + bandno;
+ int yi, cblknw = band->prec[precno].xi1 - band->prec[precno].xi0;
+ for (yi = band->prec[precno].yi0; yi < band->prec[precno].yi1; yi++){
+ int xi;
+ for (xi = band->prec[precno].xi0; xi < band->prec[precno].xi1; xi++){
+ J2kCblk *cblk = band->cblk + yi * cblknw + xi;
+ if (s->buf_end - s->buf < cblk->lengthinc)
+ return AVERROR(EINVAL);
+ bytestream_get_buffer(&s->buf, cblk->data, cblk->lengthinc);
+ cblk->length += cblk->lengthinc;
+ cblk->lengthinc = 0;
+ }
+ }
+ }
+ return 0;
+}
+
+static int decode_packets(J2kDecoderContext *s, J2kTile *tile)
+{
+ int layno, reslevelno, compno, precno, ok_reslevel;
+ s->bit_index = 8;
+ for (layno = 0; layno < tile->codsty[0].nlayers; layno++){
+ ok_reslevel = 1;
+ for (reslevelno = 0; ok_reslevel; reslevelno++){
+ ok_reslevel = 0;
+ for (compno = 0; compno < s->ncomponents; compno++){
+ J2kCodingStyle *codsty = tile->codsty + compno;
+ J2kQuantStyle *qntsty = tile->qntsty + compno;
+ if (reslevelno < codsty->nreslevels){
+ J2kResLevel *rlevel = tile->comp[compno].reslevel + reslevelno;
+ ok_reslevel = 1;
+ for (precno = 0; precno < rlevel->num_precincts_x * rlevel->num_precincts_y; precno++){
+ if (decode_packet(s, codsty, rlevel, precno, layno, qntsty->expn +
+ (reslevelno ? 3*(reslevelno-1)+1 : 0), qntsty->nguardbits))
+ return -1;
+ }
+ }
+ }
+ }
+ }
+ return 0;
+}
+
+/* TIER-1 routines */
+static void decode_sigpass(J2kT1Context *t1, int width, int height, int bpno, int bandno, int bpass_csty_symbol,
+ int vert_causal_ctx_csty_symbol)
+{
+ int mask = 3 << (bpno - 1), y0, x, y;
+
+ for (y0 = 0; y0 < height; y0 += 4)
+ for (x = 0; x < width; x++)
+ for (y = y0; y < height && y < y0+4; y++){
+ if ((t1->flags[y+1][x+1] & J2K_T1_SIG_NB)
+ && !(t1->flags[y+1][x+1] & (J2K_T1_SIG | J2K_T1_VIS))){
+ int vert_causal_ctx_csty_loc_symbol = vert_causal_ctx_csty_symbol && (x == 3 && y == 3);
+ if (ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + ff_j2k_getnbctxno(t1->flags[y+1][x+1], bandno,
+ vert_causal_ctx_csty_loc_symbol))){
+ int xorbit, ctxno = ff_j2k_getsgnctxno(t1->flags[y+1][x+1], &xorbit);
+ if (bpass_csty_symbol)
+ t1->data[y][x] = ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + ctxno) ? -mask : mask;
+ else
+ t1->data[y][x] = (ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + ctxno) ^ xorbit) ?
+ -mask : mask;
+
+ ff_j2k_set_significant(t1, x, y, t1->data[y][x] < 0);
+ }
+ t1->flags[y+1][x+1] |= J2K_T1_VIS;
+ }
+ }
+}
+
+static void decode_refpass(J2kT1Context *t1, int width, int height, int bpno)
+{
+ int phalf, nhalf;
+ int y0, x, y;
+
+ phalf = 1 << (bpno - 1);
+ nhalf = -phalf;
+
+ for (y0 = 0; y0 < height; y0 += 4)
+ for (x = 0; x < width; x++)
+ for (y = y0; y < height && y < y0+4; y++){
+ if ((t1->flags[y+1][x+1] & (J2K_T1_SIG | J2K_T1_VIS)) == J2K_T1_SIG){
+ int ctxno = ff_j2k_getrefctxno(t1->flags[y+1][x+1]);
+ int r = ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + ctxno) ? phalf : nhalf;
+ t1->data[y][x] += t1->data[y][x] < 0 ? -r : r;
+ t1->flags[y+1][x+1] |= J2K_T1_REF;
+ }
+ }
+}
+
+static void decode_clnpass(J2kDecoderContext *s, J2kT1Context *t1, int width, int height,
+ int bpno, int bandno, int seg_symbols)
+{
+ int mask = 3 << (bpno - 1), y0, x, y, runlen, dec;
+
+ for (y0 = 0; y0 < height; y0 += 4) {
+ for (x = 0; x < width; x++){
+ if (y0 + 3 < height && !(
+ (t1->flags[y0+1][x+1] & (J2K_T1_SIG_NB | J2K_T1_VIS | J2K_T1_SIG)) ||
+ (t1->flags[y0+2][x+1] & (J2K_T1_SIG_NB | J2K_T1_VIS | J2K_T1_SIG)) ||
+ (t1->flags[y0+3][x+1] & (J2K_T1_SIG_NB | J2K_T1_VIS | J2K_T1_SIG)) ||
+ (t1->flags[y0+4][x+1] & (J2K_T1_SIG_NB | J2K_T1_VIS | J2K_T1_SIG)))){
+ if (!ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + MQC_CX_RL))
+ continue;
+ runlen = ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + MQC_CX_UNI);
+ runlen = (runlen << 1) | ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + MQC_CX_UNI);
+ dec = 1;
+ } else{
+ runlen = 0;
+ dec = 0;
+ }
+
+ for (y = y0 + runlen; y < y0 + 4 && y < height; y++){
+ if (!dec){
+ if (!(t1->flags[y+1][x+1] & (J2K_T1_SIG | J2K_T1_VIS)))
+ dec = ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + ff_j2k_getnbctxno(t1->flags[y+1][x+1],
+ bandno, 0));
+ }
+ if (dec){
+ int xorbit, ctxno = ff_j2k_getsgnctxno(t1->flags[y+1][x+1], &xorbit);
+ t1->data[y][x] = (ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + ctxno) ^ xorbit) ? -mask : mask;
+ ff_j2k_set_significant(t1, x, y, t1->data[y][x] < 0);
+ }
+ dec = 0;
+ t1->flags[y+1][x+1] &= ~J2K_T1_VIS;
+ }
+ }
+ }
+ if (seg_symbols) {
+ int val;
+ val = ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + MQC_CX_UNI);
+ val = (val << 1) + ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + MQC_CX_UNI);
+ val = (val << 1) + ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + MQC_CX_UNI);
+ val = (val << 1) + ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + MQC_CX_UNI);
+ if (val != 0xa) {
+ av_log(s->avctx, AV_LOG_ERROR,"Segmentation symbol value incorrect\n");
+ }
+ }
+}
+
+static int decode_cblk(J2kDecoderContext *s, J2kCodingStyle *codsty, J2kT1Context *t1, J2kCblk *cblk,
+ int width, int height, int bandpos)
+{
+ int passno = cblk->npasses, pass_t = 2, bpno = cblk->nonzerobits - 1, y, clnpass_cnt = 0;
+ int bpass_csty_symbol = J2K_CBLK_BYPASS & codsty->cblk_style;
+ int vert_causal_ctx_csty_symbol = J2K_CBLK_VSC & codsty->cblk_style;
+
+ for (y = 0; y < height+2; y++)
+ memset(t1->flags[y], 0, (width+2)*sizeof(int));
+
+ for (y = 0; y < height; y++)
+ memset(t1->data[y], 0, width*sizeof(int));
+
+ cblk->data[cblk->length] = 0xff;
+ cblk->data[cblk->length+1] = 0xff;
+ ff_mqc_initdec(&t1->mqc, cblk->data);
+
+ while(passno--){
+ switch(pass_t){
+ case 0: decode_sigpass(t1, width, height, bpno+1, bandpos,
+ bpass_csty_symbol && (clnpass_cnt >= 4), vert_causal_ctx_csty_symbol);
+ break;
+ case 1: decode_refpass(t1, width, height, bpno+1);
+ if (bpass_csty_symbol && clnpass_cnt >= 4)
+ ff_mqc_initdec(&t1->mqc, cblk->data);
+ break;
+ case 2: decode_clnpass(s, t1, width, height, bpno+1, bandpos,
+ codsty->cblk_style & J2K_CBLK_SEGSYM);
+ clnpass_cnt = clnpass_cnt + 1;
+ if (bpass_csty_symbol && clnpass_cnt >= 4)
+ ff_mqc_initdec(&t1->mqc, cblk->data);
+ break;
+ }
+
+ pass_t++;
+ if (pass_t == 3){
+ bpno--;
+ pass_t = 0;
+ }
+ }
+ return 0;
+}
+
+static void mct_decode(J2kDecoderContext *s, J2kTile *tile)
+{
+ int i, *src[3], i0, i1, i2, csize = 1;
+
+ for (i = 0; i < 3; i++)
+ src[i] = tile->comp[i].data;
+
+ for (i = 0; i < 2; i++)
+ csize *= tile->comp[0].coord[i][1] - tile->comp[0].coord[i][0];
+
+ if (tile->codsty[0].transform == FF_DWT97){
+ for (i = 0; i < csize; i++){
+ i0 = *src[0] + (*src[2] * 46802 >> 16);
+ i1 = *src[0] - (*src[1] * 22553 + *src[2] * 46802 >> 16);
+ i2 = *src[0] + (116130 * *src[1] >> 16);
+ *src[0]++ = i0;
+ *src[1]++ = i1;
+ *src[2]++ = i2;
+ }
+ } else{
+ for (i = 0; i < csize; i++){
+ i1 = *src[0] - (*src[2] + *src[1] >> 2);
+ i0 = i1 + *src[2];
+ i2 = i1 + *src[1];
+ *src[0]++ = i0;
+ *src[1]++ = i1;
+ *src[2]++ = i2;
+ }
+ }
+}
+
+static int decode_tile(J2kDecoderContext *s, J2kTile *tile)
+{
+ int compno, reslevelno, bandno;
+ int x, y, *src[4];
+ uint8_t *line;
+ J2kT1Context t1;
+
+ for (compno = 0; compno < s->ncomponents; compno++){
+ J2kComponent *comp = tile->comp + compno;
+ J2kCodingStyle *codsty = tile->codsty + compno;
+
+ for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++){
+ J2kResLevel *rlevel = comp->reslevel + reslevelno;
+ for (bandno = 0; bandno < rlevel->nbands; bandno++){
+ J2kBand *band = rlevel->band + bandno;
+ int cblkx, cblky, cblkno=0, xx0, x0, xx1, y0, yy0, yy1, bandpos;
+
+ bandpos = bandno + (reslevelno > 0);
+
+ yy0 = bandno == 0 ? 0 : comp->reslevel[reslevelno-1].coord[1][1] - comp->reslevel[reslevelno-1].coord[1][0];
+ y0 = yy0;
+ yy1 = FFMIN(ff_j2k_ceildiv(band->coord[1][0] + 1, band->codeblock_height) * band->codeblock_height,
+ band->coord[1][1]) - band->coord[1][0] + yy0;
+
+ if (band->coord[0][0] == band->coord[0][1] || band->coord[1][0] == band->coord[1][1])
+ continue;
+
+ for (cblky = 0; cblky < band->cblkny; cblky++){
+ if (reslevelno == 0 || bandno == 1)
+ xx0 = 0;
+ else
+ xx0 = comp->reslevel[reslevelno-1].coord[0][1] - comp->reslevel[reslevelno-1].coord[0][0];
+ x0 = xx0;
+ xx1 = FFMIN(ff_j2k_ceildiv(band->coord[0][0] + 1, band->codeblock_width) * band->codeblock_width,
+ band->coord[0][1]) - band->coord[0][0] + xx0;
+
+ for (cblkx = 0; cblkx < band->cblknx; cblkx++, cblkno++){
+ int y, x;
+ decode_cblk(s, codsty, &t1, band->cblk + cblkno, xx1 - xx0, yy1 - yy0, bandpos);
+ if (codsty->transform == FF_DWT53){
+ for (y = yy0; y < yy1; y+=s->cdy[compno]){
+ int *ptr = t1.data[y-yy0];
+ for (x = xx0; x < xx1; x+=s->cdx[compno]){
+ comp->data[(comp->coord[0][1] - comp->coord[0][0]) * y + x] = *ptr++ >> 1;
+ }
+ }
+ } else{
+ for (y = yy0; y < yy1; y+=s->cdy[compno]){
+ int *ptr = t1.data[y-yy0];
+ for (x = xx0; x < xx1; x+=s->cdx[compno]){
+ int tmp = ((int64_t)*ptr++) * ((int64_t)band->stepsize) >> 13, tmp2;
+ tmp2 = FFABS(tmp>>1) + FFABS(tmp&1);
+ comp->data[(comp->coord[0][1] - comp->coord[0][0]) * y + x] = tmp < 0 ? -tmp2 : tmp2;
+ }
+ }
+ }
+ xx0 = xx1;
+ xx1 = FFMIN(xx1 + band->codeblock_width, band->coord[0][1] - band->coord[0][0] + x0);
+ }
+ yy0 = yy1;
+ yy1 = FFMIN(yy1 + band->codeblock_height, band->coord[1][1] - band->coord[1][0] + y0);
+ }
+ }
+ }
+ ff_j2k_dwt_decode(&comp->dwt, comp->data);
+ src[compno] = comp->data;
+ }
+ if (tile->codsty[0].mct)
+ mct_decode(s, tile);
+
+ if (s->avctx->pix_fmt == PIX_FMT_BGRA) // RGBA -> BGRA
+ FFSWAP(int *, src[0], src[2]);
+
+ if (s->precision <= 8) {
+ for (compno = 0; compno < s->ncomponents; compno++){
+ y = tile->comp[compno].coord[1][0] - s->image_offset_y;
+ line = s->picture.data[0] + y * s->picture.linesize[0];
+ for (; y < tile->comp[compno].coord[1][1] - s->image_offset_y; y += s->cdy[compno]){
+ uint8_t *dst;
+
+ x = tile->comp[compno].coord[0][0] - s->image_offset_x;
+ dst = line + x * s->ncomponents + compno;
+
+ for (; x < tile->comp[compno].coord[0][1] - s->image_offset_x; x += s->cdx[compno]) {
+ *src[compno] += 1 << (s->cbps[compno]-1);
+ if (*src[compno] < 0)
+ *src[compno] = 0;
+ else if (*src[compno] >= (1 << s->cbps[compno]))
+ *src[compno] = (1 << s->cbps[compno]) - 1;
+ *dst = *src[compno]++;
+ dst += s->ncomponents;
+ }
+ line += s->picture.linesize[0];
+ }
+ }
+ } else {
+ for (compno = 0; compno < s->ncomponents; compno++) {
+ y = tile->comp[compno].coord[1][0] - s->image_offset_y;
+ line = s->picture.data[0] + y * s->picture.linesize[0];
+ for (; y < tile->comp[compno].coord[1][1] - s->image_offset_y; y += s->cdy[compno]) {
+ uint16_t *dst;
+ x = tile->comp[compno].coord[0][0] - s->image_offset_x;
+ dst = line + (x * s->ncomponents + compno) * 2;
+ for (; x < tile->comp[compno].coord[0][1] - s->image_offset_x; x += s-> cdx[compno]) {
+ int32_t val;
+ val = *src[compno]++ << (16 - s->cbps[compno]);
+ val += 1 << 15;
+ val = av_clip(val, 0, (1 << 16) - 1);
+ *dst = val;
+ dst += s->ncomponents;
+ }
+ line += s->picture.linesize[0];
+ }
+ }
+ }
+ return 0;
+}
+
+static void cleanup(J2kDecoderContext *s)
+{
+ int tileno, compno;
+ for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++){
+ for (compno = 0; compno < s->ncomponents; compno++){
+ J2kComponent *comp = s->tile[tileno].comp + compno;
+ J2kCodingStyle *codsty = s->tile[tileno].codsty + compno;
+
+ ff_j2k_cleanup(comp, codsty);
+ }
+ av_freep(&s->tile[tileno].comp);
+ }
+ av_freep(&s->tile);
+}
+
+static int decode_codestream(J2kDecoderContext *s)
+{
+ J2kCodingStyle *codsty = s->codsty;
+ J2kQuantStyle *qntsty = s->qntsty;
+ uint8_t *properties = s->properties;
+
+ for (;;){
+ int marker, len, ret = 0;
+ uint8_t *oldbuf;
+ if (s->buf_end - s->buf < 2){
+ av_log(s->avctx, AV_LOG_ERROR, "Missing EOC\n");
+ break;
+ }
+
+ marker = bytestream_get_be16(&s->buf);
+ oldbuf = s->buf;
+
+ if (marker == J2K_SOD){
+ J2kTile *tile = s->tile + s->curtileno;
+ if (ret = init_tile(s, s->curtileno))
+ return ret;
+ if (ret = decode_packets(s, tile))
+ return ret;
+ continue;
+ }
+ if (marker == J2K_EOC)
+ break;
+
+ if (s->buf_end - s->buf < 2)
+ return AVERROR(EINVAL);
+ len = bytestream_get_be16(&s->buf);
+ switch(marker){
+ case J2K_SIZ:
+ ret = get_siz(s); break;
+ case J2K_COC:
+ ret = get_coc(s, codsty, properties); break;
+ case J2K_COD:
+ ret = get_cod(s, codsty, properties); break;
+ case J2K_QCC:
+ ret = get_qcc(s, len, qntsty, properties); break;
+ case J2K_QCD:
+ ret = get_qcd(s, len, qntsty, properties); break;
+ case J2K_SOT:
+ if (!(ret = get_sot(s))){
+ codsty = s->tile[s->curtileno].codsty;
+ qntsty = s->tile[s->curtileno].qntsty;
+ properties = s->tile[s->curtileno].properties;
+ }
+ break;
+ case J2K_COM:
+ // the comment is ignored
+ s->buf += len - 2; break;
+ default:
+ av_log(s->avctx, AV_LOG_ERROR, "unsupported marker 0x%.4X at pos 0x%tx\n", marker, s->buf - s->buf_start - 4);
+ s->buf += len - 2; break;
+ }
+ if (s->buf - oldbuf != len || ret){
+ av_log(s->avctx, AV_LOG_ERROR, "error during processing marker segment %.4x\n", marker);
+ return ret ? ret : -1;
+ }
+ }
+ return 0;
+}
+
+static int jp2_find_codestream(J2kDecoderContext *s)
+{
+ uint32_t atom_size;
+ int found_codestream = 0, search_range = 10;
+
+ // skip jpeg2k signature atom
+ s->buf += 12;
+
+ while(!found_codestream && search_range && s->buf_end - s->buf >= 8) {
+ atom_size = AV_RB32(s->buf);
+ if(AV_RB32(s->buf + 4) == JP2_CODESTREAM) {
+ found_codestream = 1;
+ s->buf += 8;
+ } else {
+ if (s->buf_end - s->buf < atom_size)
+ return 0;
+ s->buf += atom_size;
+ search_range--;
+ }
+ }
+
+ if(found_codestream)
+ return 1;
+ return 0;
+}
+
+static int decode_frame(AVCodecContext *avctx,
+ void *data, int *data_size,
+ AVPacket *avpkt)
+{
+ J2kDecoderContext *s = avctx->priv_data;
+ AVFrame *picture = data;
+ int tileno, ret;
+
+ s->avctx = avctx;
+ av_log(s->avctx, AV_LOG_DEBUG, "start\n");
+
+ // init
+ s->buf = s->buf_start = avpkt->data;
+ s->buf_end = s->buf_start + avpkt->size;
+ s->curtileno = -1;
+
+ ff_j2k_init_tier1_luts();
+
+ if (s->buf_end - s->buf < 2)
+ return AVERROR(EINVAL);
+
+ // check if the image is in jp2 format
+ if(s->buf_end - s->buf >= 12 &&
+ (AV_RB32(s->buf) == 12) && (AV_RB32(s->buf + 4) == JP2_SIG_TYPE) &&
+ (AV_RB32(s->buf + 8) == JP2_SIG_VALUE)) {
+ if(!jp2_find_codestream(s)) {
+ av_log(avctx, AV_LOG_ERROR, "couldn't find jpeg2k codestream atom\n");
+ return -1;
+ }
+ }
+
+ if (bytestream_get_be16(&s->buf) != J2K_SOC){
+ av_log(avctx, AV_LOG_ERROR, "SOC marker not present\n");
+ return -1;
+ }
+ if (ret = decode_codestream(s))
+ return ret;
+
+ for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++)
+ if (ret = decode_tile(s, s->tile + tileno))
+ return ret;
+
+ cleanup(s);
+ av_log(s->avctx, AV_LOG_DEBUG, "end\n");
+
+ *data_size = sizeof(AVPicture);
+ *picture = s->picture;
+
+ return s->buf - s->buf_start;
+}
+
+static av_cold int j2kdec_init(AVCodecContext *avctx)
+{
+ J2kDecoderContext *s = avctx->priv_data;
+
+ avcodec_get_frame_defaults((AVFrame*)&s->picture);
+ avctx->coded_frame = (AVFrame*)&s->picture;
+ return 0;
+}
+
+static av_cold int decode_end(AVCodecContext *avctx)
+{
+ J2kDecoderContext *s = avctx->priv_data;
+
+ if (s->picture.data[0])
+ avctx->release_buffer(avctx, &s->picture);
+
+ return 0;
+}
+
+AVCodec ff_jpeg2000_decoder = {
+ "j2k",
+ AVMEDIA_TYPE_VIDEO,
+ CODEC_ID_JPEG2000,
+ sizeof(J2kDecoderContext),
+ j2kdec_init,
+ NULL,
+ decode_end,
+ decode_frame,
+ .capabilities = CODEC_CAP_EXPERIMENTAL,
+ .long_name = NULL_IF_CONFIG_SMALL("JPEG 2000"),
+ .pix_fmts =
+ (enum PixelFormat[]) {PIX_FMT_GRAY8, PIX_FMT_RGB24, -1}
+};
diff --git a/libavcodec/j2kenc.c b/libavcodec/j2kenc.c
new file mode 100644
index 0000000000..50b2b2137a
--- /dev/null
+++ b/libavcodec/j2kenc.c
@@ -0,0 +1,1053 @@
+/*
+ * JPEG2000 image encoder
+ * Copyright (c) 2007 Kamil Nowosad
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * JPEG2000 image encoder
+ * @file
+ * @author Kamil Nowosad
+ */
+
+#include <float.h>
+#include "avcodec.h"
+#include "bytestream.h"
+#include "j2k.h"
+#include "libavutil/common.h"
+
+#define NMSEDEC_BITS 7
+#define NMSEDEC_FRACBITS (NMSEDEC_BITS-1)
+#define WMSEDEC_SHIFT 13 ///< must be >= 13
+#define LAMBDA_SCALE (100000000LL << (WMSEDEC_SHIFT - 13))
+
+static int lut_nmsedec_ref [1<<NMSEDEC_BITS],
+ lut_nmsedec_ref0[1<<NMSEDEC_BITS],
+ lut_nmsedec_sig [1<<NMSEDEC_BITS],
+ lut_nmsedec_sig0[1<<NMSEDEC_BITS];
+
+static const int dwt_norms[2][4][10] = { // [dwt_type][band][rlevel] (multiplied by 10000)
+ {{10000, 19650, 41770, 84030, 169000, 338400, 676900, 1353000, 2706000, 5409000},
+ {20220, 39890, 83550, 170400, 342700, 686300, 1373000, 2746000, 5490000},
+ {20220, 39890, 83550, 170400, 342700, 686300, 1373000, 2746000, 5490000},
+ {20800, 38650, 83070, 171800, 347100, 695900, 1393000, 2786000, 5572000}},
+
+ {{10000, 15000, 27500, 53750, 106800, 213400, 426700, 853300, 1707000, 3413000},
+ {10380, 15920, 29190, 57030, 113300, 226400, 452500, 904800, 1809000},
+ {10380, 15920, 29190, 57030, 113300, 226400, 452500, 904800, 1809000},
+ { 7186, 9218, 15860, 30430, 60190, 120100, 240000, 479700, 959300}}
+};
+
+typedef struct {
+ J2kComponent *comp;
+} J2kTile;
+
+typedef struct {
+ AVCodecContext *avctx;
+ AVFrame picture;
+
+ int width, height; ///< image width and height
+ uint8_t cbps[4]; ///< bits per sample in particular components
+ int chroma_shift[2];
+ uint8_t planar;
+ int ncomponents;
+ int tile_width, tile_height; ///< tile size
+ int numXtiles, numYtiles;
+
+ uint8_t *buf_start;
+ uint8_t *buf;
+ uint8_t *buf_end;
+ int bit_index;
+
+ int64_t lambda;
+
+ J2kCodingStyle codsty;
+ J2kQuantStyle qntsty;
+
+ J2kTile *tile;
+} J2kEncoderContext;
+
+
+/* debug */
+#if 0
+#undef ifprintf
+#undef printf
+
+static void nspaces(FILE *fd, int n)
+{
+ while(n--) putc(' ', fd);
+}
+
+static void printv(int *tab, int l)
+{
+ int i;
+ for (i = 0; i < l; i++)
+ printf("%.3d ", tab[i]);
+ printf("\n");
+}
+
+static void printu(uint8_t *tab, int l)
+{
+ int i;
+ for (i = 0; i < l; i++)
+ printf("%.3hd ", tab[i]);
+ printf("\n");
+}
+
+static void printcomp(J2kComponent *comp)
+{
+ int i;
+ for (i = 0; i < comp->y1 - comp->y0; i++)
+ printv(comp->data + i * (comp->x1 - comp->x0), comp->x1 - comp->x0);
+}
+
+static void dump(J2kEncoderContext *s, FILE *fd)
+{
+ int tileno, compno, reslevelno, bandno, precno;
+ fprintf(fd, "XSiz = %d, YSiz = %d, tile_width = %d, tile_height = %d\n"
+ "numXtiles = %d, numYtiles = %d, ncomponents = %d\n"
+ "tiles:\n",
+ s->width, s->height, s->tile_width, s->tile_height,
+ s->numXtiles, s->numYtiles, s->ncomponents);
+ for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++){
+ J2kTile *tile = s->tile + tileno;
+ nspaces(fd, 2);
+ fprintf(fd, "tile %d:\n", tileno);
+ for(compno = 0; compno < s->ncomponents; compno++){
+ J2kComponent *comp = tile->comp + compno;
+ nspaces(fd, 4);
+ fprintf(fd, "component %d:\n", compno);
+ nspaces(fd, 4);
+ fprintf(fd, "x0 = %d, x1 = %d, y0 = %d, y1 = %d\n",
+ comp->x0, comp->x1, comp->y0, comp->y1);
+ for(reslevelno = 0; reslevelno < s->nreslevels; reslevelno++){
+ J2kResLevel *reslevel = comp->reslevel + reslevelno;
+ nspaces(fd, 6);
+ fprintf(fd, "reslevel %d:\n", reslevelno);
+ nspaces(fd, 6);
+ fprintf(fd, "x0 = %d, x1 = %d, y0 = %d, y1 = %d, nbands = %d\n",
+ reslevel->x0, reslevel->x1, reslevel->y0,
+ reslevel->y1, reslevel->nbands);
+ for(bandno = 0; bandno < reslevel->nbands; bandno++){
+ J2kBand *band = reslevel->band + bandno;
+ nspaces(fd, 8);
+ fprintf(fd, "band %d:\n", bandno);
+ nspaces(fd, 8);
+ fprintf(fd, "x0 = %d, x1 = %d, y0 = %d, y1 = %d,"
+ "codeblock_width = %d, codeblock_height = %d cblknx = %d cblkny = %d\n",
+ band->x0, band->x1,
+ band->y0, band->y1,
+ band->codeblock_width, band->codeblock_height,
+ band->cblknx, band->cblkny);
+ for (precno = 0; precno < reslevel->num_precincts_x * reslevel->num_precincts_y; precno++){
+ J2kPrec *prec = band->prec + precno;
+ nspaces(fd, 10);
+ fprintf(fd, "prec %d:\n", precno);
+ nspaces(fd, 10);
+ fprintf(fd, "xi0 = %d, xi1 = %d, yi0 = %d, yi1 = %d\n",
+ prec->xi0, prec->xi1, prec->yi0, prec->yi1);
+ }
+ }
+ }
+ }
+ }
+}
+#endif
+
+/* bitstream routines */
+
+/** put n times val bit */
+static void put_bits(J2kEncoderContext *s, int val, int n) // TODO: optimize
+{
+ while (n-- > 0){
+ if (s->bit_index == 8)
+ {
+ s->bit_index = *s->buf == 0xff;
+ *(++s->buf) = 0;
+ }
+ *s->buf |= val << (7 - s->bit_index++);
+ }
+}
+
+/** put n least significant bits of a number num */
+static void put_num(J2kEncoderContext *s, int num, int n)
+{
+ while(--n >= 0)
+ put_bits(s, (num >> n) & 1, 1);
+}
+
+/** flush the bitstream */
+static void j2k_flush(J2kEncoderContext *s)
+{
+ if (s->bit_index){
+ s->bit_index = 0;
+ s->buf++;
+ }
+}
+
+/* tag tree routines */
+
+/** code the value stored in node */
+static void tag_tree_code(J2kEncoderContext *s, J2kTgtNode *node, int threshold)
+{
+ J2kTgtNode *stack[30];
+ int sp = 1, curval = 0;
+ stack[0] = node;
+
+ node = node->parent;
+ while(node){
+ if (node->vis){
+ curval = node->val;
+ break;
+ }
+ node->vis++;
+ stack[sp++] = node;
+ node = node->parent;
+ }
+ while(--sp >= 0){
+ if (stack[sp]->val >= threshold){
+ put_bits(s, 0, threshold - curval);
+ break;
+ }
+ put_bits(s, 0, stack[sp]->val - curval);
+ put_bits(s, 1, 1);
+ curval = stack[sp]->val;
+ }
+}
+
+/** update the value in node */
+static void tag_tree_update(J2kTgtNode *node)
+{
+ int lev = 0;
+ while (node->parent){
+ if (node->parent->val <= node->val)
+ break;
+ node->parent->val = node->val;
+ node = node->parent;
+ lev++;
+ }
+}
+
+static int put_siz(J2kEncoderContext *s)
+{
+ int i;
+
+ if (s->buf_end - s->buf < 40 + 3 * s->ncomponents)
+ return -1;
+
+ bytestream_put_be16(&s->buf, J2K_SIZ);
+ bytestream_put_be16(&s->buf, 38 + 3 * s->ncomponents); // Lsiz
+ bytestream_put_be16(&s->buf, 0); // Rsiz
+ bytestream_put_be32(&s->buf, s->width); // width
+ bytestream_put_be32(&s->buf, s->height); // height
+ bytestream_put_be32(&s->buf, 0); // X0Siz
+ bytestream_put_be32(&s->buf, 0); // Y0Siz
+
+ bytestream_put_be32(&s->buf, s->tile_width); // XTSiz
+ bytestream_put_be32(&s->buf, s->tile_height); // YTSiz
+ bytestream_put_be32(&s->buf, 0); // XT0Siz
+ bytestream_put_be32(&s->buf, 0); // YT0Siz
+ bytestream_put_be16(&s->buf, s->ncomponents); // CSiz
+
+ for (i = 0; i < s->ncomponents; i++){ // Ssiz_i XRsiz_i, YRsiz_i
+ bytestream_put_byte(&s->buf, 7);
+ bytestream_put_byte(&s->buf, i?1<<s->chroma_shift[0]:1);
+ bytestream_put_byte(&s->buf, i?1<<s->chroma_shift[1]:1);
+ }
+ return 0;
+}
+
+static int put_cod(J2kEncoderContext *s)
+{
+ J2kCodingStyle *codsty = &s->codsty;
+
+ if (s->buf_end - s->buf < 14)
+ return -1;
+
+ bytestream_put_be16(&s->buf, J2K_COD);
+ bytestream_put_be16(&s->buf, 12); // Lcod
+ bytestream_put_byte(&s->buf, 0); // Scod
+ // SGcod
+ bytestream_put_byte(&s->buf, 0); // progression level
+ bytestream_put_be16(&s->buf, 1); // num of layers
+ if(s->avctx->pix_fmt == PIX_FMT_YUV444P){
+ bytestream_put_byte(&s->buf, 2); // ICT
+ }else{
+ bytestream_put_byte(&s->buf, 0); // unspecified
+ }
+ // SPcod
+ bytestream_put_byte(&s->buf, codsty->nreslevels - 1); // num of decomp. levels
+ bytestream_put_byte(&s->buf, codsty->log2_cblk_width-2); // cblk width
+ bytestream_put_byte(&s->buf, codsty->log2_cblk_height-2); // cblk height
+ bytestream_put_byte(&s->buf, 0); // cblk style
+ bytestream_put_byte(&s->buf, codsty->transform); // transformation
+ return 0;
+}
+
+static int put_qcd(J2kEncoderContext *s, int compno)
+{
+ int i, size;
+ J2kCodingStyle *codsty = &s->codsty;
+ J2kQuantStyle *qntsty = &s->qntsty;
+
+ if (qntsty->quantsty == J2K_QSTY_NONE)
+ size = 4 + 3 * (codsty->nreslevels-1);
+ else // QSTY_SE
+ size = 5 + 6 * (codsty->nreslevels-1);
+
+ if (s->buf_end - s->buf < size + 2)
+ return -1;
+
+ bytestream_put_be16(&s->buf, J2K_QCD);
+ bytestream_put_be16(&s->buf, size); // LQcd
+ bytestream_put_byte(&s->buf, (qntsty->nguardbits << 5) | qntsty->quantsty); // Sqcd
+ if (qntsty->quantsty == J2K_QSTY_NONE)
+ for (i = 0; i < codsty->nreslevels * 3 - 2; i++)
+ bytestream_put_byte(&s->buf, qntsty->expn[i] << 3);
+ else // QSTY_SE
+ for (i = 0; i < codsty->nreslevels * 3 - 2; i++)
+ bytestream_put_be16(&s->buf, (qntsty->expn[i] << 11) | qntsty->mant[i]);
+ return 0;
+}
+
+static uint8_t *put_sot(J2kEncoderContext *s, int tileno)
+{
+ uint8_t *psotptr;
+
+ if (s->buf_end - s->buf < 12)
+ return NULL;
+
+ bytestream_put_be16(&s->buf, J2K_SOT);
+ bytestream_put_be16(&s->buf, 10); // Lsot
+ bytestream_put_be16(&s->buf, tileno); // Isot
+
+ psotptr = s->buf;
+ bytestream_put_be32(&s->buf, 0); // Psot (filled in later)
+
+ bytestream_put_byte(&s->buf, 0); // TPsot
+ bytestream_put_byte(&s->buf, 1); // TNsot
+ return psotptr;
+}
+
+/**
+ * compute the sizes of tiles, resolution levels, bands, etc.
+ * allocate memory for them
+ * divide the input image into tile-components
+ */
+static int init_tiles(J2kEncoderContext *s)
+{
+ int tileno, tilex, tiley, compno;
+ J2kCodingStyle *codsty = &s->codsty;
+ J2kQuantStyle *qntsty = &s->qntsty;
+
+ s->numXtiles = ff_j2k_ceildiv(s->width, s->tile_width);
+ s->numYtiles = ff_j2k_ceildiv(s->height, s->tile_height);
+
+ s->tile = av_malloc(s->numXtiles * s->numYtiles * sizeof(J2kTile));
+ if (!s->tile)
+ return AVERROR(ENOMEM);
+ for (tileno = 0, tiley = 0; tiley < s->numYtiles; tiley++)
+ for (tilex = 0; tilex < s->numXtiles; tilex++, tileno++){
+ J2kTile *tile = s->tile + tileno;
+
+ tile->comp = av_malloc(s->ncomponents * sizeof(J2kComponent));
+ if (!tile->comp)
+ return AVERROR(ENOMEM);
+ for (compno = 0; compno < s->ncomponents; compno++){
+ J2kComponent *comp = tile->comp + compno;
+ int ret, i, j;
+
+ comp->coord[0][0] = tilex * s->tile_width;
+ comp->coord[0][1] = FFMIN((tilex+1)*s->tile_width, s->width);
+ comp->coord[1][0] = tiley * s->tile_height;
+ comp->coord[1][1] = FFMIN((tiley+1)*s->tile_height, s->height);
+ if (compno > 0)
+ for (i = 0; i < 2; i++)
+ for (j = 0; j < 2; j++)
+ comp->coord[i][j] = ff_j2k_ceildivpow2(comp->coord[i][j], s->chroma_shift[i]);
+
+ if (ret = ff_j2k_init_component(comp, codsty, qntsty, s->cbps[compno], compno?1<<s->chroma_shift[0]:1, compno?1<<s->chroma_shift[1]:1))
+ return ret;
+ }
+ }
+ return 0;
+}
+
+static void copy_frame(J2kEncoderContext *s)
+{
+ int tileno, compno, i, y, x;
+ uint8_t *line;
+ for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++){
+ J2kTile *tile = s->tile + tileno;
+ if (s->planar){
+ for (compno = 0; compno < s->ncomponents; compno++){
+ J2kComponent *comp = tile->comp + compno;
+ int *dst = comp->data;
+ line = s->picture.data[compno]
+ + comp->coord[1][0] * s->picture.linesize[compno]
+ + comp->coord[0][0];
+ for (y = comp->coord[1][0]; y < comp->coord[1][1]; y++){
+ uint8_t *ptr = line;
+ for (x = comp->coord[0][0]; x < comp->coord[0][1]; x++)
+ *dst++ = *ptr++ - (1 << 7);
+ line += s->picture.linesize[compno];
+ }
+ }
+ } else{
+ line = s->picture.data[0] + tile->comp[0].coord[1][0] * s->picture.linesize[0]
+ + tile->comp[0].coord[0][0] * s->ncomponents;
+
+ i = 0;
+ for (y = tile->comp[0].coord[1][0]; y < tile->comp[0].coord[1][1]; y++){
+ uint8_t *ptr = line;
+ for (x = tile->comp[0].coord[0][0]; x < tile->comp[0].coord[0][1]; x++, i++){
+ for (compno = 0; compno < s->ncomponents; compno++){
+ tile->comp[compno].data[i] = *ptr++ - (1 << 7);
+ }
+ }
+ line += s->picture.linesize[0];
+ }
+ }
+ }
+}
+
+static void init_quantization(J2kEncoderContext *s)
+{
+ int compno, reslevelno, bandno;
+ J2kQuantStyle *qntsty = &s->qntsty;
+ J2kCodingStyle *codsty = &s->codsty;
+
+ for (compno = 0; compno < s->ncomponents; compno++){
+ int gbandno = 0;
+ for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++){
+ int nbands, lev = codsty->nreslevels - reslevelno - 1;
+ nbands = reslevelno ? 3 : 1;
+ for (bandno = 0; bandno < nbands; bandno++, gbandno++){
+ int expn, mant;
+
+ if (codsty->transform == FF_DWT97){
+ int bandpos = bandno + (reslevelno>0),
+ ss = 81920000 / dwt_norms[0][bandpos][lev],
+ log = av_log2(ss);
+ mant = (11 - log < 0 ? ss >> log - 11 : ss << 11 - log) & 0x7ff;
+ expn = s->cbps[compno] - log + 13;
+ } else
+ expn = ((bandno&2)>>1) + (reslevelno>0) + s->cbps[compno];
+
+ qntsty->expn[gbandno] = expn;
+ qntsty->mant[gbandno] = mant;
+ }
+ }
+ }
+}
+
+static void init_luts()
+{
+ int i, a,
+ mask = ~((1<<NMSEDEC_FRACBITS)-1);
+
+ for (i = 0; i < (1 << NMSEDEC_BITS); i++){
+ lut_nmsedec_sig[i] = FFMAX(6*i - (9<<NMSEDEC_FRACBITS-1) << 12-NMSEDEC_FRACBITS, 0);
+ lut_nmsedec_sig0[i] = FFMAX((i*i + (1<<NMSEDEC_FRACBITS-1) & mask) << 1, 0);
+
+ a = (i >> (NMSEDEC_BITS-2)&2) + 1;
+ lut_nmsedec_ref[i] = FFMAX((-2*i + (1<<NMSEDEC_FRACBITS) + a*i - (a*a<<NMSEDEC_FRACBITS-2))
+ << 13-NMSEDEC_FRACBITS, 0);
+ lut_nmsedec_ref0[i] = FFMAX(((i*i + (1-4*i << NMSEDEC_FRACBITS-1) + (1<<2*NMSEDEC_FRACBITS)) & mask)
+ << 1, 0);
+ }
+}
+
+/* tier-1 routines */
+static int getnmsedec_sig(int x, int bpno)
+{
+ if (bpno > NMSEDEC_FRACBITS)
+ return lut_nmsedec_sig[(x >> (bpno - NMSEDEC_FRACBITS)) & ((1 << NMSEDEC_BITS) - 1)];
+ return lut_nmsedec_sig0[x & ((1 << NMSEDEC_BITS) - 1)];
+}
+
+static int getnmsedec_ref(int x, int bpno)
+{
+ if (bpno > NMSEDEC_FRACBITS)
+ return lut_nmsedec_ref[(x >> (bpno - NMSEDEC_FRACBITS)) & ((1 << NMSEDEC_BITS) - 1)];
+ return lut_nmsedec_ref0[x & ((1 << NMSEDEC_BITS) - 1)];
+}
+
+static void encode_sigpass(J2kT1Context *t1, int width, int height, int bandno, int *nmsedec, int bpno)
+{
+ int y0, x, y, mask = 1 << (bpno + NMSEDEC_FRACBITS);
+ int vert_causal_ctx_csty_loc_symbol;
+ for (y0 = 0; y0 < height; y0 += 4)
+ for (x = 0; x < width; x++)
+ for (y = y0; y < height && y < y0+4; y++){
+ if (!(t1->flags[y+1][x+1] & J2K_T1_SIG) && (t1->flags[y+1][x+1] & J2K_T1_SIG_NB)){
+ int ctxno = ff_j2k_getnbctxno(t1->flags[y+1][x+1], bandno, vert_causal_ctx_csty_loc_symbol),
+ bit = t1->data[y][x] & mask ? 1 : 0;
+ ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + ctxno, bit);
+ if (bit){
+ int xorbit;
+ int ctxno = ff_j2k_getsgnctxno(t1->flags[y+1][x+1], &xorbit);
+ ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + ctxno, (t1->flags[y+1][x+1] >> 15) ^ xorbit);
+ *nmsedec += getnmsedec_sig(t1->data[y][x], bpno + NMSEDEC_FRACBITS);
+ ff_j2k_set_significant(t1, x, y, t1->flags[y+1][x+1] >> 15);
+ }
+ t1->flags[y+1][x+1] |= J2K_T1_VIS;
+ }
+ }
+}
+
+static void encode_refpass(J2kT1Context *t1, int width, int height, int *nmsedec, int bpno)
+{
+ int y0, x, y, mask = 1 << (bpno + NMSEDEC_FRACBITS);
+ for (y0 = 0; y0 < height; y0 += 4)
+ for (x = 0; x < width; x++)
+ for (y = y0; y < height && y < y0+4; y++)
+ if ((t1->flags[y+1][x+1] & (J2K_T1_SIG | J2K_T1_VIS)) == J2K_T1_SIG){
+ int ctxno = ff_j2k_getrefctxno(t1->flags[y+1][x+1]);
+ *nmsedec += getnmsedec_ref(t1->data[y][x], bpno + NMSEDEC_FRACBITS);
+ ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + ctxno, t1->data[y][x] & mask ? 1:0);
+ t1->flags[y+1][x+1] |= J2K_T1_REF;
+ }
+}
+
+static void encode_clnpass(J2kT1Context *t1, int width, int height, int bandno, int *nmsedec, int bpno)
+{
+ int y0, x, y, mask = 1 << (bpno + NMSEDEC_FRACBITS);
+ int vert_causal_ctx_csty_loc_symbol;
+ for (y0 = 0; y0 < height; y0 += 4)
+ for (x = 0; x < width; x++){
+ if (y0 + 3 < height && !(
+ (t1->flags[y0+1][x+1] & (J2K_T1_SIG_NB | J2K_T1_VIS | J2K_T1_SIG)) ||
+ (t1->flags[y0+2][x+1] & (J2K_T1_SIG_NB | J2K_T1_VIS | J2K_T1_SIG)) ||
+ (t1->flags[y0+3][x+1] & (J2K_T1_SIG_NB | J2K_T1_VIS | J2K_T1_SIG)) ||
+ (t1->flags[y0+4][x+1] & (J2K_T1_SIG_NB | J2K_T1_VIS | J2K_T1_SIG))))
+ {
+ // aggregation mode
+ int rlen;
+ for (rlen = 0; rlen < 4; rlen++)
+ if (t1->data[y0+rlen][x] & mask)
+ break;
+ ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + MQC_CX_RL, rlen != 4);
+ if (rlen == 4)
+ continue;
+ ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + MQC_CX_UNI, rlen >> 1);
+ ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + MQC_CX_UNI, rlen & 1);
+ for (y = y0 + rlen; y < y0 + 4; y++){
+ if (!(t1->flags[y+1][x+1] & (J2K_T1_SIG | J2K_T1_VIS))){
+ int ctxno = ff_j2k_getnbctxno(t1->flags[y+1][x+1], bandno, vert_causal_ctx_csty_loc_symbol);
+ if (y > y0 + rlen)
+ ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + ctxno, t1->data[y][x] & mask ? 1:0);
+ if (t1->data[y][x] & mask){ // newly significant
+ int xorbit;
+ int ctxno = ff_j2k_getsgnctxno(t1->flags[y+1][x+1], &xorbit);
+ *nmsedec += getnmsedec_sig(t1->data[y][x], bpno + NMSEDEC_FRACBITS);
+ ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + ctxno, (t1->flags[y+1][x+1] >> 15) ^ xorbit);
+ ff_j2k_set_significant(t1, x, y, t1->flags[y+1][x+1] >> 15);
+ }
+ }
+ t1->flags[y+1][x+1] &= ~J2K_T1_VIS;
+ }
+ } else{
+ for (y = y0; y < y0 + 4 && y < height; y++){
+ if (!(t1->flags[y+1][x+1] & (J2K_T1_SIG | J2K_T1_VIS))){
+ int ctxno = ff_j2k_getnbctxno(t1->flags[y+1][x+1], bandno, vert_causal_ctx_csty_loc_symbol);
+ ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + ctxno, t1->data[y][x] & mask ? 1:0);
+ if (t1->data[y][x] & mask){ // newly significant
+ int xorbit;
+ int ctxno = ff_j2k_getsgnctxno(t1->flags[y+1][x+1], &xorbit);
+ *nmsedec += getnmsedec_sig(t1->data[y][x], bpno + NMSEDEC_FRACBITS);
+ ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + ctxno, (t1->flags[y+1][x+1] >> 15) ^ xorbit);
+ ff_j2k_set_significant(t1, x, y, t1->flags[y+1][x+1] >> 15);
+ }
+ }
+ t1->flags[y+1][x+1] &= ~J2K_T1_VIS;
+ }
+ }
+ }
+}
+
+static void encode_cblk(J2kEncoderContext *s, J2kT1Context *t1, J2kCblk *cblk, J2kTile *tile,
+ int width, int height, int bandpos, int lev)
+{
+ int pass_t = 2, passno, x, y, max=0, nmsedec, bpno;
+ int64_t wmsedec = 0;
+
+ for (y = 0; y < height+2; y++)
+ memset(t1->flags[y], 0, (width+2)*sizeof(int));
+
+ for (y = 0; y < height; y++){
+ for (x = 0; x < width; x++){
+ if (t1->data[y][x] < 0){
+ t1->flags[y+1][x+1] |= J2K_T1_SGN;
+ t1->data[y][x] = -t1->data[y][x];
+ }
+ max = FFMAX(max, t1->data[y][x]);
+ }
+ }
+
+ if (max == 0){
+ cblk->nonzerobits = 0;
+ bpno = 0;
+ } else{
+ cblk->nonzerobits = av_log2(max) + 1 - NMSEDEC_FRACBITS;
+ bpno = cblk->nonzerobits - 1;
+ }
+
+ ff_mqc_initenc(&t1->mqc, cblk->data);
+
+ for (passno = 0; bpno >= 0; passno++){
+ nmsedec=0;
+
+ switch(pass_t){
+ case 0: encode_sigpass(t1, width, height, bandpos, &nmsedec, bpno);
+ break;
+ case 1: encode_refpass(t1, width, height, &nmsedec, bpno);
+ break;
+ case 2: encode_clnpass(t1, width, height, bandpos, &nmsedec, bpno);
+ break;
+ }
+
+ cblk->passes[passno].rate = 3 + ff_mqc_length(&t1->mqc);
+ wmsedec += (int64_t)nmsedec << (2*bpno);
+ cblk->passes[passno].disto = wmsedec;
+
+ if (++pass_t == 3){
+ pass_t = 0;
+ bpno--;
+ }
+ }
+ cblk->npasses = passno;
+ cblk->ninclpasses = passno;
+
+ // TODO: optional flush on each pass
+ cblk->passes[passno-1].rate = ff_mqc_flush(&t1->mqc);
+}
+
+/* tier-2 routines: */
+
+static void putnumpasses(J2kEncoderContext *s, int n)
+{
+ if (n == 1)
+ put_num(s, 0, 1);
+ else if (n == 2)
+ put_num(s, 2, 2);
+ else if (n <= 5)
+ put_num(s, 0xc | (n-3), 4);
+ else if (n <= 36)
+ put_num(s, 0x1e0 | (n-6), 9);
+ else
+ put_num(s, 0xff80 | (n-37), 16);
+}
+
+
+static int encode_packet(J2kEncoderContext *s, J2kResLevel *rlevel, int precno,
+ uint8_t *expn, int numgbits)
+{
+ int bandno, empty = 1;
+
+ // init bitstream
+ *s->buf = 0;
+ s->bit_index = 0;
+
+ // header
+
+ // is the packet empty?
+ for (bandno = 0; bandno < rlevel->nbands; bandno++){
+ if (rlevel->band[bandno].coord[0][0] < rlevel->band[bandno].coord[0][1]
+ && rlevel->band[bandno].coord[1][0] < rlevel->band[bandno].coord[1][1]){
+ empty = 0;
+ break;
+ }
+ }
+
+ put_bits(s, !empty, 1);
+ if (empty){
+ j2k_flush(s);
+ return 0;
+ }
+
+ for (bandno = 0; bandno < rlevel->nbands; bandno++){
+ J2kBand *band = rlevel->band + bandno;
+ J2kPrec *prec = band->prec + precno;
+ int yi, xi, pos;
+ int cblknw = prec->xi1 - prec->xi0;
+
+ if (band->coord[0][0] == band->coord[0][1]
+ || band->coord[1][0] == band->coord[1][1])
+ continue;
+
+ for (pos=0, yi = prec->yi0; yi < prec->yi1; yi++){
+ for (xi = prec->xi0; xi < prec->xi1; xi++, pos++){
+ prec->cblkincl[pos].val = band->cblk[yi * cblknw + xi].ninclpasses == 0;
+ tag_tree_update(prec->cblkincl + pos);
+ prec->zerobits[pos].val = expn[bandno] + numgbits - 1 - band->cblk[yi * cblknw + xi].nonzerobits;
+ tag_tree_update(prec->zerobits + pos);
+ }
+ }
+
+ for (pos=0, yi = prec->yi0; yi < prec->yi1; yi++){
+ for (xi = prec->xi0; xi < prec->xi1; xi++, pos++){
+ int pad = 0, llen, length;
+ J2kCblk *cblk = band->cblk + yi * cblknw + xi;
+
+ if (s->buf_end - s->buf < 20) // approximately
+ return -1;
+
+ // inclusion information
+ tag_tree_code(s, prec->cblkincl + pos, 1);
+ if (!cblk->ninclpasses)
+ continue;
+ // zerobits information
+ tag_tree_code(s, prec->zerobits + pos, 100);
+ // number of passes
+ putnumpasses(s, cblk->ninclpasses);
+
+ length = cblk->passes[cblk->ninclpasses-1].rate;
+ llen = av_log2(length) - av_log2(cblk->ninclpasses) - 2;
+ if (llen < 0){
+ pad = -llen;
+ llen = 0;
+ }
+ // length of code block
+ put_bits(s, 1, llen);
+ put_bits(s, 0, 1);
+ put_num(s, length, av_log2(length)+1+pad);
+ }
+ }
+ }
+ j2k_flush(s);
+ for (bandno = 0; bandno < rlevel->nbands; bandno++){
+ J2kBand *band = rlevel->band + bandno;
+ J2kPrec *prec = band->prec + precno;
+ int yi, cblknw = prec->xi1 - prec->xi0;
+ for (yi = prec->yi0; yi < prec->yi1; yi++){
+ int xi;
+ for (xi = prec->xi0; xi < prec->xi1; xi++){
+ J2kCblk *cblk = band->cblk + yi * cblknw + xi;
+ if (cblk->ninclpasses){
+ if (s->buf_end - s->buf < cblk->passes[cblk->ninclpasses-1].rate)
+ return -1;
+ bytestream_put_buffer(&s->buf, cblk->data, cblk->passes[cblk->ninclpasses-1].rate);
+ }
+ }
+ }
+ }
+ return 0;
+}
+
+static int encode_packets(J2kEncoderContext *s, J2kTile *tile, int tileno)
+{
+ int compno, reslevelno, ret;
+ J2kCodingStyle *codsty = &s->codsty;
+ J2kQuantStyle *qntsty = &s->qntsty;
+
+ av_log(s->avctx, AV_LOG_DEBUG, "tier2\n");
+ // lay-rlevel-comp-pos progression
+ for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++){
+ for (compno = 0; compno < s->ncomponents; compno++){
+ int precno;
+ J2kResLevel *reslevel = s->tile[tileno].comp[compno].reslevel + reslevelno;
+ for (precno = 0; precno < reslevel->num_precincts_x * reslevel->num_precincts_y; precno++){
+ if (ret = encode_packet(s, reslevel, precno, qntsty->expn + (reslevelno ? 3*reslevelno-2 : 0),
+ qntsty->nguardbits))
+ return ret;
+ }
+ }
+ }
+ av_log(s->avctx, AV_LOG_DEBUG, "after tier2\n");
+ return 0;
+}
+
+static int getcut(J2kCblk *cblk, int64_t lambda, int dwt_norm)
+{
+ int passno, res = 0;
+ for (passno = 0; passno < cblk->npasses; passno++){
+ int dr;
+ int64_t dd;
+
+ dr = cblk->passes[passno].rate
+ - (res ? cblk->passes[res-1].rate:0);
+ dd = cblk->passes[passno].disto
+ - (res ? cblk->passes[res-1].disto:0);
+
+ if (((dd * dwt_norm) >> WMSEDEC_SHIFT) * dwt_norm >= dr * lambda)
+ res = passno+1;
+ }
+ return res;
+}
+
+static void truncpasses(J2kEncoderContext *s, J2kTile *tile)
+{
+ int compno, reslevelno, bandno, cblkno, lev;
+ J2kCodingStyle *codsty = &s->codsty;
+
+ for (compno = 0; compno < s->ncomponents; compno++){
+ J2kComponent *comp = tile->comp + compno;
+
+ for (reslevelno = 0, lev = codsty->nreslevels-1; reslevelno < codsty->nreslevels; reslevelno++, lev--){
+ J2kResLevel *reslevel = comp->reslevel + reslevelno;
+
+ for (bandno = 0; bandno < reslevel->nbands ; bandno++){
+ int bandpos = bandno + (reslevelno > 0);
+ J2kBand *band = reslevel->band + bandno;
+
+ for (cblkno = 0; cblkno < band->cblknx * band->cblkny; cblkno++){
+ J2kCblk *cblk = band->cblk + cblkno;
+
+ cblk->ninclpasses = getcut(cblk, s->lambda,
+ (int64_t)dwt_norms[codsty->transform][bandpos][lev] * (int64_t)band->stepsize >> 13);
+ }
+ }
+ }
+ }
+}
+
+static int encode_tile(J2kEncoderContext *s, J2kTile *tile, int tileno)
+{
+ int compno, reslevelno, bandno, ret;
+ J2kT1Context t1;
+ J2kCodingStyle *codsty = &s->codsty;
+ for (compno = 0; compno < s->ncomponents; compno++){
+ J2kComponent *comp = s->tile[tileno].comp + compno;
+
+ av_log(s->avctx, AV_LOG_DEBUG,"dwt\n");
+ if (ret = ff_j2k_dwt_encode(&comp->dwt, comp->data))
+ return ret;
+ av_log(s->avctx, AV_LOG_DEBUG,"after dwt -> tier1\n");
+
+ for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++){
+ J2kResLevel *reslevel = comp->reslevel + reslevelno;
+
+ for (bandno = 0; bandno < reslevel->nbands ; bandno++){
+ J2kBand *band = reslevel->band + bandno;
+ int cblkx, cblky, cblkno=0, xx0, x0, xx1, y0, yy0, yy1, bandpos;
+ yy0 = bandno == 0 ? 0 : comp->reslevel[reslevelno-1].coord[1][1] - comp->reslevel[reslevelno-1].coord[1][0];
+ y0 = yy0;
+ yy1 = FFMIN(ff_j2k_ceildiv(band->coord[1][0] + 1, band->codeblock_height) * band->codeblock_height,
+ band->coord[1][1]) - band->coord[1][0] + yy0;
+
+ if (band->coord[0][0] == band->coord[0][1] || band->coord[1][0] == band->coord[1][1])
+ continue;
+
+ bandpos = bandno + (reslevelno > 0);
+
+ for (cblky = 0; cblky < band->cblkny; cblky++){
+ if (reslevelno == 0 || bandno == 1)
+ xx0 = 0;
+ else
+ xx0 = comp->reslevel[reslevelno-1].coord[0][1] - comp->reslevel[reslevelno-1].coord[0][0];
+ x0 = xx0;
+ xx1 = FFMIN(ff_j2k_ceildiv(band->coord[0][0] + 1, band->codeblock_width) * band->codeblock_width,
+ band->coord[0][1]) - band->coord[0][0] + xx0;
+
+ for (cblkx = 0; cblkx < band->cblknx; cblkx++, cblkno++){
+ int y, x;
+ if (codsty->transform == FF_DWT53){
+ for (y = yy0; y < yy1; y++){
+ int *ptr = t1.data[y-yy0];
+ for (x = xx0; x < xx1; x++){
+ *ptr++ = comp->data[(comp->coord[0][1] - comp->coord[0][0]) * y + x] << NMSEDEC_FRACBITS;
+ }
+ }
+ } else{
+ for (y = yy0; y < yy1; y++){
+ int *ptr = t1.data[y-yy0];
+ for (x = xx0; x < xx1; x++){
+ *ptr = (comp->data[(comp->coord[0][1] - comp->coord[0][0]) * y + x]);
+ *ptr++ = (int64_t)*ptr * (int64_t)(8192 * 8192 / band->stepsize) >> 13 - NMSEDEC_FRACBITS;
+ }
+ }
+ }
+ encode_cblk(s, &t1, band->cblk + cblkno, tile, xx1 - xx0, yy1 - yy0,
+ bandpos, codsty->nreslevels - reslevelno - 1);
+ xx0 = xx1;
+ xx1 = FFMIN(xx1 + band->codeblock_width, band->coord[0][1] - band->coord[0][0] + x0);
+ }
+ yy0 = yy1;
+ yy1 = FFMIN(yy1 + band->codeblock_height, band->coord[1][1] - band->coord[1][0] + y0);
+ }
+ }
+ }
+ av_log(s->avctx, AV_LOG_DEBUG, "after tier1\n");
+ }
+
+ av_log(s->avctx, AV_LOG_DEBUG, "rate control\n");
+ truncpasses(s, tile);
+ if (ret = encode_packets(s, tile, tileno))
+ return ret;
+ av_log(s->avctx, AV_LOG_DEBUG, "after rate control\n");
+ return 0;
+}
+
+static void cleanup(J2kEncoderContext *s)
+{
+ int tileno, compno;
+ J2kCodingStyle *codsty = &s->codsty;
+
+ for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++){
+ for (compno = 0; compno < s->ncomponents; compno++){
+ J2kComponent *comp = s->tile[tileno].comp + compno;
+ ff_j2k_cleanup(comp, codsty);
+ }
+ av_freep(&s->tile[tileno].comp);
+ }
+ av_freep(&s->tile);
+}
+
+static void reinit(J2kEncoderContext *s)
+{
+ int tileno, compno;
+ for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++){
+ J2kTile *tile = s->tile + tileno;
+ for (compno = 0; compno < s->ncomponents; compno++)
+ ff_j2k_reinit(tile->comp + compno, &s->codsty);
+ }
+}
+
+static int encode_frame(AVCodecContext *avctx,
+ uint8_t *buf, int buf_size,
+ void *data)
+{
+ int tileno, ret;
+ J2kEncoderContext *s = avctx->priv_data;
+
+ // init:
+ s->buf = s->buf_start = buf;
+ s->buf_end = buf + buf_size;
+
+ s->picture = *(AVFrame*)data;
+ avctx->coded_frame= &s->picture;
+
+ s->lambda = s->picture.quality * LAMBDA_SCALE;
+
+ copy_frame(s);
+ reinit(s);
+
+ if (s->buf_end - s->buf < 2)
+ return -1;
+ bytestream_put_be16(&s->buf, J2K_SOC);
+ if (ret = put_siz(s))
+ return ret;
+ if (ret = put_cod(s))
+ return ret;
+ if (ret = put_qcd(s, 0))
+ return ret;
+
+ for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++){
+ uint8_t *psotptr;
+ if (!(psotptr = put_sot(s, tileno)))
+ return -1;
+ if (s->buf_end - s->buf < 2)
+ return -1;
+ bytestream_put_be16(&s->buf, J2K_SOD);
+ if (ret = encode_tile(s, s->tile + tileno, tileno))
+ return ret;
+ bytestream_put_be32(&psotptr, s->buf - psotptr + 6);
+ }
+ if (s->buf_end - s->buf < 2)
+ return -1;
+ bytestream_put_be16(&s->buf, J2K_EOC);
+
+ av_log(s->avctx, AV_LOG_DEBUG, "end\n");
+ return s->buf - s->buf_start;
+}
+
+static av_cold int j2kenc_init(AVCodecContext *avctx)
+{
+ int i, ret;
+ J2kEncoderContext *s = avctx->priv_data;
+ J2kCodingStyle *codsty = &s->codsty;
+ J2kQuantStyle *qntsty = &s->qntsty;
+
+ s->avctx = avctx;
+ av_log(s->avctx, AV_LOG_DEBUG, "init\n");
+
+ // defaults:
+ // TODO: implement setting non-standard precinct size
+ codsty->log2_prec_width = 15;
+ codsty->log2_prec_height = 15;
+ codsty->nreslevels = 7;
+ codsty->log2_cblk_width = 4;
+ codsty->log2_cblk_height = 4;
+ codsty->transform = 1;
+
+ qntsty->nguardbits = 1;
+
+ s->tile_width = 256;
+ s->tile_height = 256;
+
+ if (codsty->transform == FF_DWT53)
+ qntsty->quantsty = J2K_QSTY_NONE;
+ else
+ qntsty->quantsty = J2K_QSTY_SE;
+
+ s->width = avctx->width;
+ s->height = avctx->height;
+
+ for (i = 0; i < 3; i++)
+ s->cbps[i] = 8;
+
+ if (avctx->pix_fmt == PIX_FMT_RGB24){
+ s->ncomponents = 3;
+ } else if (avctx->pix_fmt == PIX_FMT_GRAY8){
+ s->ncomponents = 1;
+ } else{ // planar YUV
+ s->planar = 1;
+ s->ncomponents = 3;
+ avcodec_get_chroma_sub_sample(avctx->pix_fmt,
+ s->chroma_shift, s->chroma_shift + 1);
+ }
+
+ ff_j2k_init_tier1_luts();
+
+ init_luts();
+
+ init_quantization(s);
+ if (ret=init_tiles(s))
+ return ret;
+
+ av_log(s->avctx, AV_LOG_DEBUG, "after init\n");
+
+ return 0;
+}
+
+static int j2kenc_destroy(AVCodecContext *avctx)
+{
+ J2kEncoderContext *s = avctx->priv_data;
+
+ cleanup(s);
+ return 0;
+}
+
+AVCodec ff_jpeg2000_encoder = {
+ "j2k",
+ AVMEDIA_TYPE_VIDEO,
+ CODEC_ID_JPEG2000,
+ sizeof(J2kEncoderContext),
+ j2kenc_init,
+ encode_frame,
+ j2kenc_destroy,
+ .capabilities= CODEC_CAP_EXPERIMENTAL,
+ .long_name = NULL_IF_CONFIG_SMALL("JPEG 2000"),
+ .pix_fmts =
+ (enum PixelFormat[]) {PIX_FMT_RGB24, PIX_FMT_YUV444P, PIX_FMT_GRAY8,
+/* PIX_FMT_YUV420P,
+ PIX_FMT_YUV422P, PIX_FMT_YUV444P,
+ PIX_FMT_YUV410P, PIX_FMT_YUV411P,*/
+ -1}
+};
diff --git a/libavcodec/jfdctint.c b/libavcodec/jfdctint.c
index 072c7440b5..0482bc5643 100644
--- a/libavcodec/jfdctint.c
+++ b/libavcodec/jfdctint.c
@@ -1,402 +1,25 @@
-/*
- * jfdctint.c
- *
- * This file is part of the Independent JPEG Group's software.
- *
- * The authors make NO WARRANTY or representation, either express or implied,
- * with respect to this software, its quality, accuracy, merchantability, or
- * fitness for a particular purpose. This software is provided "AS IS", and
- * you, its user, assume the entire risk as to its quality and accuracy.
- *
- * This software is copyright (C) 1991-1996, Thomas G. Lane.
- * All Rights Reserved except as specified below.
- *
- * Permission is hereby granted to use, copy, modify, and distribute this
- * software (or portions thereof) for any purpose, without fee, subject to
- * these conditions:
- * (1) If any part of the source code for this software is distributed, then
- * this README file must be included, with this copyright and no-warranty
- * notice unaltered; and any additions, deletions, or changes to the original
- * files must be clearly indicated in accompanying documentation.
- * (2) If only executable code is distributed, then the accompanying
- * documentation must state that "this software is based in part on the work
- * of the Independent JPEG Group".
- * (3) Permission for use of this software is granted only if the user accepts
- * full responsibility for any undesirable consequences; the authors accept
- * NO LIABILITY for damages of any kind.
- *
- * These conditions apply to any software derived from or based on the IJG
- * code, not just to the unmodified library. If you use our work, you ought
- * to acknowledge us.
- *
- * Permission is NOT granted for the use of any IJG author's name or company
- * name in advertising or publicity relating to this software or products
- * derived from it. This software may be referred to only as "the Independent
- * JPEG Group's software".
- *
- * We specifically permit and encourage the use of this software as the basis
- * of commercial products, provided that all warranty or liability claims are
- * assumed by the product vendor.
- *
- * This file contains a slow-but-accurate integer implementation of the
- * forward DCT (Discrete Cosine Transform).
- *
- * A 2-D DCT can be done by 1-D DCT on each row followed by 1-D DCT
- * on each column. Direct algorithms are also available, but they are
- * much more complex and seem not to be any faster when reduced to code.
- *
- * This implementation is based on an algorithm described in
- * C. Loeffler, A. Ligtenberg and G. Moschytz, "Practical Fast 1-D DCT
- * Algorithms with 11 Multiplications", Proc. Int'l. Conf. on Acoustics,
- * Speech, and Signal Processing 1989 (ICASSP '89), pp. 988-991.
- * The primary algorithm described there uses 11 multiplies and 29 adds.
- * We use their alternate method with 12 multiplies and 32 adds.
- * The advantage of this method is that no data path contains more than one
- * multiplication; this allows a very simple and accurate implementation in
- * scaled fixed-point arithmetic, with a minimal number of shifts.
- */
-
/**
- * @file
- * Independent JPEG Group's slow & accurate dct.
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include "libavutil/common.h"
-#include "dsputil.h"
-
-#define DCTSIZE 8
-#define BITS_IN_JSAMPLE 8
-#define GLOBAL(x) x
-#define RIGHT_SHIFT(x, n) ((x) >> (n))
-#define MULTIPLY16C16(var,const) ((var)*(const))
-
-#if 1 //def USE_ACCURATE_ROUNDING
-#define DESCALE(x,n) RIGHT_SHIFT((x) + (1 << ((n) - 1)), n)
-#else
-#define DESCALE(x,n) RIGHT_SHIFT(x, n)
-#endif
-
-
-/*
- * This module is specialized to the case DCTSIZE = 8.
- */
-
-#if DCTSIZE != 8
- Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
-#endif
-
-
-/*
- * The poop on this scaling stuff is as follows:
- *
- * Each 1-D DCT step produces outputs which are a factor of sqrt(N)
- * larger than the true DCT outputs. The final outputs are therefore
- * a factor of N larger than desired; since N=8 this can be cured by
- * a simple right shift at the end of the algorithm. The advantage of
- * this arrangement is that we save two multiplications per 1-D DCT,
- * because the y0 and y4 outputs need not be divided by sqrt(N).
- * In the IJG code, this factor of 8 is removed by the quantization step
- * (in jcdctmgr.c), NOT in this module.
+ * This file is part of Libav.
*
- * We have to do addition and subtraction of the integer inputs, which
- * is no problem, and multiplication by fractional constants, which is
- * a problem to do in integer arithmetic. We multiply all the constants
- * by CONST_SCALE and convert them to integer constants (thus retaining
- * CONST_BITS bits of precision in the constants). After doing a
- * multiplication we have to divide the product by CONST_SCALE, with proper
- * rounding, to produce the correct output. This division can be done
- * cheaply as a right shift of CONST_BITS bits. We postpone shifting
- * as long as possible so that partial sums can be added together with
- * full fractional precision.
+ * Libav 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.
*
- * The outputs of the first pass are scaled up by PASS1_BITS bits so that
- * they are represented to better-than-integral precision. These outputs
- * require BITS_IN_JSAMPLE + PASS1_BITS + 3 bits; this fits in a 16-bit word
- * with the recommended scaling. (For 12-bit sample data, the intermediate
- * array is int32_t anyway.)
+ * Libav 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
+ * Lesser General Public License for more details.
*
- * To avoid overflow of the 32-bit intermediate results in pass 2, we must
- * have BITS_IN_JSAMPLE + CONST_BITS + PASS1_BITS <= 26. Error analysis
- * shows that the values given below are the most effective.
- */
-
-#if BITS_IN_JSAMPLE == 8
-#define CONST_BITS 13
-#define PASS1_BITS 4 /* set this to 2 if 16x16 multiplies are faster */
-#else
-#define CONST_BITS 13
-#define PASS1_BITS 1 /* lose a little precision to avoid overflow */
-#endif
-
-/* Some C compilers fail to reduce "FIX(constant)" at compile time, thus
- * causing a lot of useless floating-point operations at run time.
- * To get around this we use the following pre-calculated constants.
- * If you change CONST_BITS you may want to add appropriate values.
- * (With a reasonable C compiler, you can just rely on the FIX() macro...)
- */
-
-#if CONST_BITS == 13
-#define FIX_0_298631336 ((int32_t) 2446) /* FIX(0.298631336) */
-#define FIX_0_390180644 ((int32_t) 3196) /* FIX(0.390180644) */
-#define FIX_0_541196100 ((int32_t) 4433) /* FIX(0.541196100) */
-#define FIX_0_765366865 ((int32_t) 6270) /* FIX(0.765366865) */
-#define FIX_0_899976223 ((int32_t) 7373) /* FIX(0.899976223) */
-#define FIX_1_175875602 ((int32_t) 9633) /* FIX(1.175875602) */
-#define FIX_1_501321110 ((int32_t) 12299) /* FIX(1.501321110) */
-#define FIX_1_847759065 ((int32_t) 15137) /* FIX(1.847759065) */
-#define FIX_1_961570560 ((int32_t) 16069) /* FIX(1.961570560) */
-#define FIX_2_053119869 ((int32_t) 16819) /* FIX(2.053119869) */
-#define FIX_2_562915447 ((int32_t) 20995) /* FIX(2.562915447) */
-#define FIX_3_072711026 ((int32_t) 25172) /* FIX(3.072711026) */
-#else
-#define FIX_0_298631336 FIX(0.298631336)
-#define FIX_0_390180644 FIX(0.390180644)
-#define FIX_0_541196100 FIX(0.541196100)
-#define FIX_0_765366865 FIX(0.765366865)
-#define FIX_0_899976223 FIX(0.899976223)
-#define FIX_1_175875602 FIX(1.175875602)
-#define FIX_1_501321110 FIX(1.501321110)
-#define FIX_1_847759065 FIX(1.847759065)
-#define FIX_1_961570560 FIX(1.961570560)
-#define FIX_2_053119869 FIX(2.053119869)
-#define FIX_2_562915447 FIX(2.562915447)
-#define FIX_3_072711026 FIX(3.072711026)
-#endif
-
-
-/* Multiply an int32_t variable by an int32_t constant to yield an int32_t result.
- * For 8-bit samples with the recommended scaling, all the variable
- * and constant values involved are no more than 16 bits wide, so a
- * 16x16->32 bit multiply can be used instead of a full 32x32 multiply.
- * For 12-bit samples, a full 32-bit multiplication will be needed.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#if BITS_IN_JSAMPLE == 8 && CONST_BITS<=13 && PASS1_BITS<=2
-#define MULTIPLY(var,const) MULTIPLY16C16(var,const)
-#else
-#define MULTIPLY(var,const) ((var) * (const))
-#endif
-
-
-static av_always_inline void row_fdct(DCTELEM * data){
- int tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
- int tmp10, tmp11, tmp12, tmp13;
- int z1, z2, z3, z4, z5;
- DCTELEM *dataptr;
- int ctr;
-
- /* Pass 1: process rows. */
- /* Note results are scaled up by sqrt(8) compared to a true DCT; */
- /* furthermore, we scale the results by 2**PASS1_BITS. */
-
- dataptr = data;
- for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
- tmp0 = dataptr[0] + dataptr[7];
- tmp7 = dataptr[0] - dataptr[7];
- tmp1 = dataptr[1] + dataptr[6];
- tmp6 = dataptr[1] - dataptr[6];
- tmp2 = dataptr[2] + dataptr[5];
- tmp5 = dataptr[2] - dataptr[5];
- tmp3 = dataptr[3] + dataptr[4];
- tmp4 = dataptr[3] - dataptr[4];
-
- /* Even part per LL&M figure 1 --- note that published figure is faulty;
- * rotator "sqrt(2)*c1" should be "sqrt(2)*c6".
- */
-
- tmp10 = tmp0 + tmp3;
- tmp13 = tmp0 - tmp3;
- tmp11 = tmp1 + tmp2;
- tmp12 = tmp1 - tmp2;
-
- dataptr[0] = (DCTELEM) ((tmp10 + tmp11) << PASS1_BITS);
- dataptr[4] = (DCTELEM) ((tmp10 - tmp11) << PASS1_BITS);
-
- z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
- dataptr[2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
- CONST_BITS-PASS1_BITS);
- dataptr[6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
- CONST_BITS-PASS1_BITS);
-
- /* Odd part per figure 8 --- note paper omits factor of sqrt(2).
- * cK represents cos(K*pi/16).
- * i0..i3 in the paper are tmp4..tmp7 here.
- */
-
- z1 = tmp4 + tmp7;
- z2 = tmp5 + tmp6;
- z3 = tmp4 + tmp6;
- z4 = tmp5 + tmp7;
- z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
-
- tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
- tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
- tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
- tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
- z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
- z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
- z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
- z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
-
- z3 += z5;
- z4 += z5;
-
- dataptr[7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, CONST_BITS-PASS1_BITS);
- dataptr[5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, CONST_BITS-PASS1_BITS);
- dataptr[3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, CONST_BITS-PASS1_BITS);
- dataptr[1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, CONST_BITS-PASS1_BITS);
-
- dataptr += DCTSIZE; /* advance pointer to next row */
- }
-}
-
-/*
- * Perform the forward DCT on one block of samples.
- */
-
-GLOBAL(void)
-ff_jpeg_fdct_islow (DCTELEM * data)
-{
- int tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
- int tmp10, tmp11, tmp12, tmp13;
- int z1, z2, z3, z4, z5;
- DCTELEM *dataptr;
- int ctr;
-
- row_fdct(data);
-
- /* Pass 2: process columns.
- * We remove the PASS1_BITS scaling, but leave the results scaled up
- * by an overall factor of 8.
- */
-
- dataptr = data;
- for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
- tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
- tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
- tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
- tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
- tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
- tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
- tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
- tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
-
- /* Even part per LL&M figure 1 --- note that published figure is faulty;
- * rotator "sqrt(2)*c1" should be "sqrt(2)*c6".
- */
-
- tmp10 = tmp0 + tmp3;
- tmp13 = tmp0 - tmp3;
- tmp11 = tmp1 + tmp2;
- tmp12 = tmp1 - tmp2;
-
- dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS);
- dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS);
-
- z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
- dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
- CONST_BITS+PASS1_BITS);
- dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
- CONST_BITS+PASS1_BITS);
-
- /* Odd part per figure 8 --- note paper omits factor of sqrt(2).
- * cK represents cos(K*pi/16).
- * i0..i3 in the paper are tmp4..tmp7 here.
- */
-
- z1 = tmp4 + tmp7;
- z2 = tmp5 + tmp6;
- z3 = tmp4 + tmp6;
- z4 = tmp5 + tmp7;
- z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
-
- tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
- tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
- tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
- tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
- z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
- z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
- z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
- z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
-
- z3 += z5;
- z4 += z5;
-
- dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp4 + z1 + z3,
- CONST_BITS+PASS1_BITS);
- dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp5 + z2 + z4,
- CONST_BITS+PASS1_BITS);
- dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp6 + z2 + z3,
- CONST_BITS+PASS1_BITS);
- dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp7 + z1 + z4,
- CONST_BITS+PASS1_BITS);
-
- dataptr++; /* advance pointer to next column */
- }
-}
-
-/*
- * The secret of DCT2-4-8 is really simple -- you do the usual 1-DCT
- * on the rows and then, instead of doing even and odd, part on the colums
- * you do even part two times.
- */
-GLOBAL(void)
-ff_fdct248_islow (DCTELEM * data)
-{
- int tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
- int tmp10, tmp11, tmp12, tmp13;
- int z1;
- DCTELEM *dataptr;
- int ctr;
-
- row_fdct(data);
-
- /* Pass 2: process columns.
- * We remove the PASS1_BITS scaling, but leave the results scaled up
- * by an overall factor of 8.
- */
-
- dataptr = data;
- for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
- tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*1];
- tmp1 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*3];
- tmp2 = dataptr[DCTSIZE*4] + dataptr[DCTSIZE*5];
- tmp3 = dataptr[DCTSIZE*6] + dataptr[DCTSIZE*7];
- tmp4 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*1];
- tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*3];
- tmp6 = dataptr[DCTSIZE*4] - dataptr[DCTSIZE*5];
- tmp7 = dataptr[DCTSIZE*6] - dataptr[DCTSIZE*7];
-
- tmp10 = tmp0 + tmp3;
- tmp11 = tmp1 + tmp2;
- tmp12 = tmp1 - tmp2;
- tmp13 = tmp0 - tmp3;
-
- dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS);
- dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS);
-
- z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
- dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
- CONST_BITS+PASS1_BITS);
- dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
- CONST_BITS+PASS1_BITS);
-
- tmp10 = tmp4 + tmp7;
- tmp11 = tmp5 + tmp6;
- tmp12 = tmp5 - tmp6;
- tmp13 = tmp4 - tmp7;
-
- dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS);
- dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS);
-
- z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
- dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
- CONST_BITS+PASS1_BITS);
- dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
- CONST_BITS+PASS1_BITS);
+#define BIT_DEPTH 8
+#include "jfdctint_template.c"
+#undef BIT_DEPTH
- dataptr++; /* advance pointer to next column */
- }
-}
+#define BIT_DEPTH 10
+#include "jfdctint_template.c"
+#undef BIT_DEPTH
diff --git a/libavcodec/jfdctint_template.c b/libavcodec/jfdctint_template.c
new file mode 100644
index 0000000000..e60e72a412
--- /dev/null
+++ b/libavcodec/jfdctint_template.c
@@ -0,0 +1,405 @@
+/*
+ * jfdctint.c
+ *
+ * This file is part of the Independent JPEG Group's software.
+ *
+ * The authors make NO WARRANTY or representation, either express or implied,
+ * with respect to this software, its quality, accuracy, merchantability, or
+ * fitness for a particular purpose. This software is provided "AS IS", and
+ * you, its user, assume the entire risk as to its quality and accuracy.
+ *
+ * This software is copyright (C) 1991-1996, Thomas G. Lane.
+ * All Rights Reserved except as specified below.
+ *
+ * Permission is hereby granted to use, copy, modify, and distribute this
+ * software (or portions thereof) for any purpose, without fee, subject to
+ * these conditions:
+ * (1) If any part of the source code for this software is distributed, then
+ * this README file must be included, with this copyright and no-warranty
+ * notice unaltered; and any additions, deletions, or changes to the original
+ * files must be clearly indicated in accompanying documentation.
+ * (2) If only executable code is distributed, then the accompanying
+ * documentation must state that "this software is based in part on the work
+ * of the Independent JPEG Group".
+ * (3) Permission for use of this software is granted only if the user accepts
+ * full responsibility for any undesirable consequences; the authors accept
+ * NO LIABILITY for damages of any kind.
+ *
+ * These conditions apply to any software derived from or based on the IJG
+ * code, not just to the unmodified library. If you use our work, you ought
+ * to acknowledge us.
+ *
+ * Permission is NOT granted for the use of any IJG author's name or company
+ * name in advertising or publicity relating to this software or products
+ * derived from it. This software may be referred to only as "the Independent
+ * JPEG Group's software".
+ *
+ * We specifically permit and encourage the use of this software as the basis
+ * of commercial products, provided that all warranty or liability claims are
+ * assumed by the product vendor.
+ *
+ * This file contains a slow-but-accurate integer implementation of the
+ * forward DCT (Discrete Cosine Transform).
+ *
+ * A 2-D DCT can be done by 1-D DCT on each row followed by 1-D DCT
+ * on each column. Direct algorithms are also available, but they are
+ * much more complex and seem not to be any faster when reduced to code.
+ *
+ * This implementation is based on an algorithm described in
+ * C. Loeffler, A. Ligtenberg and G. Moschytz, "Practical Fast 1-D DCT
+ * Algorithms with 11 Multiplications", Proc. Int'l. Conf. on Acoustics,
+ * Speech, and Signal Processing 1989 (ICASSP '89), pp. 988-991.
+ * The primary algorithm described there uses 11 multiplies and 29 adds.
+ * We use their alternate method with 12 multiplies and 32 adds.
+ * The advantage of this method is that no data path contains more than one
+ * multiplication; this allows a very simple and accurate implementation in
+ * scaled fixed-point arithmetic, with a minimal number of shifts.
+ */
+
+/**
+ * @file
+ * Independent JPEG Group's slow & accurate dct.
+ */
+
+#include "libavutil/common.h"
+#include "dsputil.h"
+
+#include "bit_depth_template.c"
+
+#define DCTSIZE 8
+#define BITS_IN_JSAMPLE BIT_DEPTH
+#define GLOBAL(x) x
+#define RIGHT_SHIFT(x, n) ((x) >> (n))
+#define MULTIPLY16C16(var,const) ((var)*(const))
+
+#if 1 //def USE_ACCURATE_ROUNDING
+#define DESCALE(x,n) RIGHT_SHIFT((x) + (1 << ((n) - 1)), n)
+#else
+#define DESCALE(x,n) RIGHT_SHIFT(x, n)
+#endif
+
+
+/*
+ * This module is specialized to the case DCTSIZE = 8.
+ */
+
+#if DCTSIZE != 8
+#error "Sorry, this code only copes with 8x8 DCTs."
+#endif
+
+
+/*
+ * The poop on this scaling stuff is as follows:
+ *
+ * Each 1-D DCT step produces outputs which are a factor of sqrt(N)
+ * larger than the true DCT outputs. The final outputs are therefore
+ * a factor of N larger than desired; since N=8 this can be cured by
+ * a simple right shift at the end of the algorithm. The advantage of
+ * this arrangement is that we save two multiplications per 1-D DCT,
+ * because the y0 and y4 outputs need not be divided by sqrt(N).
+ * In the IJG code, this factor of 8 is removed by the quantization step
+ * (in jcdctmgr.c), NOT in this module.
+ *
+ * We have to do addition and subtraction of the integer inputs, which
+ * is no problem, and multiplication by fractional constants, which is
+ * a problem to do in integer arithmetic. We multiply all the constants
+ * by CONST_SCALE and convert them to integer constants (thus retaining
+ * CONST_BITS bits of precision in the constants). After doing a
+ * multiplication we have to divide the product by CONST_SCALE, with proper
+ * rounding, to produce the correct output. This division can be done
+ * cheaply as a right shift of CONST_BITS bits. We postpone shifting
+ * as long as possible so that partial sums can be added together with
+ * full fractional precision.
+ *
+ * The outputs of the first pass are scaled up by PASS1_BITS bits so that
+ * they are represented to better-than-integral precision. These outputs
+ * require BITS_IN_JSAMPLE + PASS1_BITS + 3 bits; this fits in a 16-bit word
+ * with the recommended scaling. (For 12-bit sample data, the intermediate
+ * array is int32_t anyway.)
+ *
+ * To avoid overflow of the 32-bit intermediate results in pass 2, we must
+ * have BITS_IN_JSAMPLE + CONST_BITS + PASS1_BITS <= 26. Error analysis
+ * shows that the values given below are the most effective.
+ */
+
+#undef CONST_BITS
+#undef PASS1_BITS
+#undef OUT_SHIFT
+
+#if BITS_IN_JSAMPLE == 8
+#define CONST_BITS 13
+#define PASS1_BITS 4 /* set this to 2 if 16x16 multiplies are faster */
+#define OUT_SHIFT PASS1_BITS
+#else
+#define CONST_BITS 13
+#define PASS1_BITS 1 /* lose a little precision to avoid overflow */
+#define OUT_SHIFT (PASS1_BITS + 1)
+#endif
+
+/* Some C compilers fail to reduce "FIX(constant)" at compile time, thus
+ * causing a lot of useless floating-point operations at run time.
+ * To get around this we use the following pre-calculated constants.
+ * If you change CONST_BITS you may want to add appropriate values.
+ * (With a reasonable C compiler, you can just rely on the FIX() macro...)
+ */
+
+#if CONST_BITS == 13
+#define FIX_0_298631336 ((int32_t) 2446) /* FIX(0.298631336) */
+#define FIX_0_390180644 ((int32_t) 3196) /* FIX(0.390180644) */
+#define FIX_0_541196100 ((int32_t) 4433) /* FIX(0.541196100) */
+#define FIX_0_765366865 ((int32_t) 6270) /* FIX(0.765366865) */
+#define FIX_0_899976223 ((int32_t) 7373) /* FIX(0.899976223) */
+#define FIX_1_175875602 ((int32_t) 9633) /* FIX(1.175875602) */
+#define FIX_1_501321110 ((int32_t) 12299) /* FIX(1.501321110) */
+#define FIX_1_847759065 ((int32_t) 15137) /* FIX(1.847759065) */
+#define FIX_1_961570560 ((int32_t) 16069) /* FIX(1.961570560) */
+#define FIX_2_053119869 ((int32_t) 16819) /* FIX(2.053119869) */
+#define FIX_2_562915447 ((int32_t) 20995) /* FIX(2.562915447) */
+#define FIX_3_072711026 ((int32_t) 25172) /* FIX(3.072711026) */
+#else
+#define FIX_0_298631336 FIX(0.298631336)
+#define FIX_0_390180644 FIX(0.390180644)
+#define FIX_0_541196100 FIX(0.541196100)
+#define FIX_0_765366865 FIX(0.765366865)
+#define FIX_0_899976223 FIX(0.899976223)
+#define FIX_1_175875602 FIX(1.175875602)
+#define FIX_1_501321110 FIX(1.501321110)
+#define FIX_1_847759065 FIX(1.847759065)
+#define FIX_1_961570560 FIX(1.961570560)
+#define FIX_2_053119869 FIX(2.053119869)
+#define FIX_2_562915447 FIX(2.562915447)
+#define FIX_3_072711026 FIX(3.072711026)
+#endif
+
+
+/* Multiply an int32_t variable by an int32_t constant to yield an int32_t result.
+ * For 8-bit samples with the recommended scaling, all the variable
+ * and constant values involved are no more than 16 bits wide, so a
+ * 16x16->32 bit multiply can be used instead of a full 32x32 multiply.
+ * For 12-bit samples, a full 32-bit multiplication will be needed.
+ */
+
+#if BITS_IN_JSAMPLE == 8 && CONST_BITS<=13 && PASS1_BITS<=2
+#define MULTIPLY(var,const) MULTIPLY16C16(var,const)
+#else
+#define MULTIPLY(var,const) ((var) * (const))
+#endif
+
+
+static av_always_inline void FUNC(row_fdct)(DCTELEM *data)
+{
+ int tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
+ int tmp10, tmp11, tmp12, tmp13;
+ int z1, z2, z3, z4, z5;
+ DCTELEM *dataptr;
+ int ctr;
+
+ /* Pass 1: process rows. */
+ /* Note results are scaled up by sqrt(8) compared to a true DCT; */
+ /* furthermore, we scale the results by 2**PASS1_BITS. */
+
+ dataptr = data;
+ for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
+ tmp0 = dataptr[0] + dataptr[7];
+ tmp7 = dataptr[0] - dataptr[7];
+ tmp1 = dataptr[1] + dataptr[6];
+ tmp6 = dataptr[1] - dataptr[6];
+ tmp2 = dataptr[2] + dataptr[5];
+ tmp5 = dataptr[2] - dataptr[5];
+ tmp3 = dataptr[3] + dataptr[4];
+ tmp4 = dataptr[3] - dataptr[4];
+
+ /* Even part per LL&M figure 1 --- note that published figure is faulty;
+ * rotator "sqrt(2)*c1" should be "sqrt(2)*c6".
+ */
+
+ tmp10 = tmp0 + tmp3;
+ tmp13 = tmp0 - tmp3;
+ tmp11 = tmp1 + tmp2;
+ tmp12 = tmp1 - tmp2;
+
+ dataptr[0] = (DCTELEM) ((tmp10 + tmp11) << PASS1_BITS);
+ dataptr[4] = (DCTELEM) ((tmp10 - tmp11) << PASS1_BITS);
+
+ z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
+ dataptr[2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
+ CONST_BITS-PASS1_BITS);
+ dataptr[6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
+ CONST_BITS-PASS1_BITS);
+
+ /* Odd part per figure 8 --- note paper omits factor of sqrt(2).
+ * cK represents cos(K*pi/16).
+ * i0..i3 in the paper are tmp4..tmp7 here.
+ */
+
+ z1 = tmp4 + tmp7;
+ z2 = tmp5 + tmp6;
+ z3 = tmp4 + tmp6;
+ z4 = tmp5 + tmp7;
+ z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
+
+ tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
+ tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
+ tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
+ tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
+ z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
+ z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
+ z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
+ z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
+
+ z3 += z5;
+ z4 += z5;
+
+ dataptr[7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, CONST_BITS-PASS1_BITS);
+ dataptr[5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, CONST_BITS-PASS1_BITS);
+ dataptr[3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, CONST_BITS-PASS1_BITS);
+ dataptr[1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, CONST_BITS-PASS1_BITS);
+
+ dataptr += DCTSIZE; /* advance pointer to next row */
+ }
+}
+
+/*
+ * Perform the forward DCT on one block of samples.
+ */
+
+GLOBAL(void)
+FUNC(ff_jpeg_fdct_islow)(DCTELEM *data)
+{
+ int tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
+ int tmp10, tmp11, tmp12, tmp13;
+ int z1, z2, z3, z4, z5;
+ DCTELEM *dataptr;
+ int ctr;
+
+ FUNC(row_fdct)(data);
+
+ /* Pass 2: process columns.
+ * We remove the PASS1_BITS scaling, but leave the results scaled up
+ * by an overall factor of 8.
+ */
+
+ dataptr = data;
+ for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
+ tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
+ tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
+ tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
+ tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
+ tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
+ tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
+ tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
+ tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
+
+ /* Even part per LL&M figure 1 --- note that published figure is faulty;
+ * rotator "sqrt(2)*c1" should be "sqrt(2)*c6".
+ */
+
+ tmp10 = tmp0 + tmp3;
+ tmp13 = tmp0 - tmp3;
+ tmp11 = tmp1 + tmp2;
+ tmp12 = tmp1 - tmp2;
+
+ dataptr[DCTSIZE*0] = DESCALE(tmp10 + tmp11, OUT_SHIFT);
+ dataptr[DCTSIZE*4] = DESCALE(tmp10 - tmp11, OUT_SHIFT);
+
+ z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
+ dataptr[DCTSIZE*2] = DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
+ CONST_BITS + OUT_SHIFT);
+ dataptr[DCTSIZE*6] = DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
+ CONST_BITS + OUT_SHIFT);
+
+ /* Odd part per figure 8 --- note paper omits factor of sqrt(2).
+ * cK represents cos(K*pi/16).
+ * i0..i3 in the paper are tmp4..tmp7 here.
+ */
+
+ z1 = tmp4 + tmp7;
+ z2 = tmp5 + tmp6;
+ z3 = tmp4 + tmp6;
+ z4 = tmp5 + tmp7;
+ z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
+
+ tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
+ tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
+ tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
+ tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
+ z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
+ z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
+ z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
+ z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
+
+ z3 += z5;
+ z4 += z5;
+
+ dataptr[DCTSIZE*7] = DESCALE(tmp4 + z1 + z3, CONST_BITS + OUT_SHIFT);
+ dataptr[DCTSIZE*5] = DESCALE(tmp5 + z2 + z4, CONST_BITS + OUT_SHIFT);
+ dataptr[DCTSIZE*3] = DESCALE(tmp6 + z2 + z3, CONST_BITS + OUT_SHIFT);
+ dataptr[DCTSIZE*1] = DESCALE(tmp7 + z1 + z4, CONST_BITS + OUT_SHIFT);
+
+ dataptr++; /* advance pointer to next column */
+ }
+}
+
+/*
+ * The secret of DCT2-4-8 is really simple -- you do the usual 1-DCT
+ * on the rows and then, instead of doing even and odd, part on the colums
+ * you do even part two times.
+ */
+GLOBAL(void)
+FUNC(ff_fdct248_islow)(DCTELEM *data)
+{
+ int tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
+ int tmp10, tmp11, tmp12, tmp13;
+ int z1;
+ DCTELEM *dataptr;
+ int ctr;
+
+ FUNC(row_fdct)(data);
+
+ /* Pass 2: process columns.
+ * We remove the PASS1_BITS scaling, but leave the results scaled up
+ * by an overall factor of 8.
+ */
+
+ dataptr = data;
+ for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
+ tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*1];
+ tmp1 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*3];
+ tmp2 = dataptr[DCTSIZE*4] + dataptr[DCTSIZE*5];
+ tmp3 = dataptr[DCTSIZE*6] + dataptr[DCTSIZE*7];
+ tmp4 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*1];
+ tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*3];
+ tmp6 = dataptr[DCTSIZE*4] - dataptr[DCTSIZE*5];
+ tmp7 = dataptr[DCTSIZE*6] - dataptr[DCTSIZE*7];
+
+ tmp10 = tmp0 + tmp3;
+ tmp11 = tmp1 + tmp2;
+ tmp12 = tmp1 - tmp2;
+ tmp13 = tmp0 - tmp3;
+
+ dataptr[DCTSIZE*0] = DESCALE(tmp10 + tmp11, OUT_SHIFT);
+ dataptr[DCTSIZE*4] = DESCALE(tmp10 - tmp11, OUT_SHIFT);
+
+ z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
+ dataptr[DCTSIZE*2] = DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
+ CONST_BITS+OUT_SHIFT);
+ dataptr[DCTSIZE*6] = DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
+ CONST_BITS+OUT_SHIFT);
+
+ tmp10 = tmp4 + tmp7;
+ tmp11 = tmp5 + tmp6;
+ tmp12 = tmp5 - tmp6;
+ tmp13 = tmp4 - tmp7;
+
+ dataptr[DCTSIZE*1] = DESCALE(tmp10 + tmp11, OUT_SHIFT);
+ dataptr[DCTSIZE*5] = DESCALE(tmp10 - tmp11, OUT_SHIFT);
+
+ z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
+ dataptr[DCTSIZE*3] = DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
+ CONST_BITS + OUT_SHIFT);
+ dataptr[DCTSIZE*7] = DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
+ CONST_BITS + OUT_SHIFT);
+
+ dataptr++; /* advance pointer to next column */
+ }
+}
diff --git a/libavcodec/jpegls.c b/libavcodec/jpegls.c
index ebe6b85e98..c40b929e95 100644
--- a/libavcodec/jpegls.c
+++ b/libavcodec/jpegls.c
@@ -3,20 +3,20 @@
* Copyright (c) 2003 Michael Niedermayer
* Copyright (c) 2006 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/jpegls.h b/libavcodec/jpegls.h
index 1c1817e833..2c21f774e8 100644
--- a/libavcodec/jpegls.h
+++ b/libavcodec/jpegls.h
@@ -3,20 +3,20 @@
* Copyright (c) 2003 Michael Niedermayer
* Copyright (c) 2006 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -86,6 +86,8 @@ static inline void ff_jpegls_downscale_state(JLSState *state, int Q){
}
static inline int ff_jpegls_update_state_regular(JLSState *state, int Q, int err){
+ if(FFABS(err) > 0xFFFF)
+ return -0x10000;
state->A[Q] += FFABS(err);
err *= state->twonear;
state->B[Q] += err;
diff --git a/libavcodec/jpeglsdec.c b/libavcodec/jpeglsdec.c
index 69cc1d3266..5e98b64644 100644
--- a/libavcodec/jpeglsdec.c
+++ b/libavcodec/jpeglsdec.c
@@ -3,20 +3,20 @@
* Copyright (c) 2003 Michael Niedermayer
* Copyright (c) 2006 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -40,7 +40,7 @@
* (or test broken JPEG-LS decoder) and slow down ordinary decoding a bit.
*
* There is no Golomb code with length >= 32 bits possible, so check and
-* avoid situation of 32 zeros, Libav Golomb decoder is painfully slow
+* avoid situation of 32 zeros, FFmpeg Golomb decoder is painfully slow
* on this errors.
*/
//#define JLS_BROKEN
@@ -262,9 +262,9 @@ int ff_jpegls_decode_picture(MJpegDecodeContext *s, int near, int point_transfor
JLSState *state;
int off = 0, stride = 1, width, shift;
- zero = av_mallocz(s->picture_ptr->linesize[0]);
+ zero = av_mallocz(s->picture.linesize[0]);
last = zero;
- cur = s->picture_ptr->data[0];
+ cur = s->picture.data[0];
state = av_mallocz(sizeof(JLSState));
/* initialize JPEG-LS state from JPEG parameters */
@@ -286,8 +286,8 @@ int ff_jpegls_decode_picture(MJpegDecodeContext *s, int near, int point_transfor
// av_log(s->avctx, AV_LOG_DEBUG, "JPEG-LS params: %ix%i NEAR=%i MV=%i T(%i,%i,%i) RESET=%i, LIMIT=%i, qbpp=%i, RANGE=%i\n",s->width,s->height,state->near,state->maxval,state->T1,state->T2,state->T3,state->reset,state->limit,state->qbpp, state->range);
// av_log(s->avctx, AV_LOG_DEBUG, "JPEG params: ILV=%i Pt=%i BPP=%i, scan = %i\n", ilv, point_transform, s->bits, s->cur_scan);
if(ilv == 0) { /* separate planes */
- off = s->cur_scan - 1;
stride = (s->nb_components > 1) ? 3 : 1;
+ off = av_clip(s->cur_scan - 1, 0, stride);
width = s->width * stride;
cur += off;
for(i = 0; i < s->height; i++) {
@@ -299,7 +299,7 @@ int ff_jpegls_decode_picture(MJpegDecodeContext *s, int near, int point_transfor
t = *((uint16_t*)last);
}
last = cur;
- cur += s->picture_ptr->linesize[0];
+ cur += s->picture.linesize[0];
if (s->restart_interval && !--s->restart_count) {
align_get_bits(&s->gb);
@@ -309,7 +309,7 @@ int ff_jpegls_decode_picture(MJpegDecodeContext *s, int near, int point_transfor
} else if(ilv == 1) { /* line interleaving */
int j;
int Rc[3] = {0, 0, 0};
- memset(cur, 0, s->picture_ptr->linesize[0]);
+ memset(cur, 0, s->picture.linesize[0]);
width = s->width * 3;
for(i = 0; i < s->height; i++) {
for(j = 0; j < 3; j++) {
@@ -322,7 +322,7 @@ int ff_jpegls_decode_picture(MJpegDecodeContext *s, int near, int point_transfor
}
}
last = cur;
- cur += s->picture_ptr->linesize[0];
+ cur += s->picture.linesize[0];
}
} else if(ilv == 2) { /* sample interleaving */
av_log(s->avctx, AV_LOG_ERROR, "Sample interleaved images are not supported.\n");
@@ -337,22 +337,22 @@ int ff_jpegls_decode_picture(MJpegDecodeContext *s, int near, int point_transfor
w = s->width * s->nb_components;
if(s->bits <= 8){
- uint8_t *src = s->picture_ptr->data[0];
+ uint8_t *src = s->picture.data[0];
for(i = 0; i < s->height; i++){
for(x = off; x < w; x+= stride){
src[x] <<= shift;
}
- src += s->picture_ptr->linesize[0];
+ src += s->picture.linesize[0];
}
}else{
- uint16_t *src = (uint16_t*) s->picture_ptr->data[0];
+ uint16_t *src = (uint16_t*) s->picture.data[0];
for(i = 0; i < s->height; i++){
for(x = 0; x < w; x++){
src[x] <<= shift;
}
- src += s->picture_ptr->linesize[0]/2;
+ src += s->picture.linesize[0]/2;
}
}
}
@@ -364,14 +364,13 @@ int ff_jpegls_decode_picture(MJpegDecodeContext *s, int near, int point_transfor
AVCodec ff_jpegls_decoder = {
- "jpegls",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_JPEGLS,
- sizeof(MJpegDecodeContext),
- ff_mjpeg_decode_init,
- NULL,
- ff_mjpeg_decode_end,
- ff_mjpeg_decode_frame,
- CODEC_CAP_DR1,
+ .name = "jpegls",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_JPEGLS,
+ .priv_data_size = sizeof(MJpegDecodeContext),
+ .init = ff_mjpeg_decode_init,
+ .close = ff_mjpeg_decode_end,
+ .decode = ff_mjpeg_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("JPEG-LS"),
};
diff --git a/libavcodec/jpeglsdec.h b/libavcodec/jpeglsdec.h
index 473282207d..5204ecb205 100644
--- a/libavcodec/jpeglsdec.h
+++ b/libavcodec/jpeglsdec.h
@@ -3,20 +3,20 @@
* Copyright (c) 2003 Michael Niedermayer
* Copyright (c) 2006 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/jpeglsenc.c b/libavcodec/jpeglsenc.c
index a825cf9d6b..d72287b296 100644
--- a/libavcodec/jpeglsenc.c
+++ b/libavcodec/jpeglsenc.c
@@ -3,20 +3,20 @@
* Copyright (c) 2003 Michael Niedermayer
* Copyright (c) 2006 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -357,7 +357,7 @@ static int encode_picture_ls(AVCodecContext *avctx, unsigned char *buf, int buf_
put_bits(&pb, 8, v);
}
}
- align_put_bits(&pb);
+ avpriv_align_put_bits(&pb);
av_free(buf2);
/* End of image */
@@ -383,13 +383,12 @@ static av_cold int encode_init_ls(AVCodecContext *ctx) {
}
AVCodec ff_jpegls_encoder = { //FIXME avoid MPV_* lossless JPEG should not need them
- "jpegls",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_JPEGLS,
- sizeof(JpeglsContext),
- encode_init_ls,
- encode_picture_ls,
- NULL,
- .pix_fmts= (const enum PixelFormat[]){PIX_FMT_BGR24, PIX_FMT_RGB24, PIX_FMT_GRAY8, PIX_FMT_GRAY16, PIX_FMT_NONE},
- .long_name= NULL_IF_CONFIG_SMALL("JPEG-LS"),
+ .name = "jpegls",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_JPEGLS,
+ .priv_data_size = sizeof(JpeglsContext),
+ .init = encode_init_ls,
+ .encode = encode_picture_ls,
+ .pix_fmts = (const enum PixelFormat[]){PIX_FMT_BGR24, PIX_FMT_RGB24, PIX_FMT_GRAY8, PIX_FMT_GRAY16, PIX_FMT_NONE},
+ .long_name = NULL_IF_CONFIG_SMALL("JPEG-LS"),
};
diff --git a/libavcodec/jvdec.c b/libavcodec/jvdec.c
index 0c346486f5..f1fdee5d43 100644
--- a/libavcodec/jvdec.c
+++ b/libavcodec/jvdec.c
@@ -2,20 +2,20 @@
* Bitmap Brothers JV video decoder
* Copyright (c) 2011 Peter Ross <pross@xvid.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -150,7 +150,7 @@ static int decode_frame(AVCodecContext *avctx,
if (video_type == 0 || video_type == 1) {
GetBitContext gb;
- init_get_bits(&gb, buf, FFMIN(video_size, buf_end - buf));
+ init_get_bits(&gb, buf, FFMIN(video_size, (buf_end - buf) * 8));
for (j = 0; j < avctx->height; j += 8)
for (i = 0; i < avctx->width; i += 8)
diff --git a/libavcodec/kbdwin.c b/libavcodec/kbdwin.c
index c2c1c59040..8b33861f71 100644
--- a/libavcodec/kbdwin.c
+++ b/libavcodec/kbdwin.c
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/kbdwin.h b/libavcodec/kbdwin.h
index 89b569aa7c..4b939756c1 100644
--- a/libavcodec/kbdwin.h
+++ b/libavcodec/kbdwin.h
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/kgv1dec.c b/libavcodec/kgv1dec.c
index 57684340af..398b8af0d5 100644
--- a/libavcodec/kgv1dec.c
+++ b/libavcodec/kgv1dec.c
@@ -2,20 +2,20 @@
* Kega Game Video (KGV1) decoder
* Copyright (c) 2010 Daniel Verkamp
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -150,6 +150,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
c->avctx = avctx;
avctx->pix_fmt = PIX_FMT_RGB555;
+ avcodec_get_frame_defaults(&c->pic);
return 0;
}
@@ -165,14 +166,12 @@ static av_cold int decode_end(AVCodecContext *avctx)
}
AVCodec ff_kgv1_decoder = {
- "kgv1",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_KGV1,
- sizeof(KgvContext),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- .max_lowres = 1,
+ .name = "kgv1",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_KGV1,
+ .priv_data_size = sizeof(KgvContext),
+ .init = decode_init,
+ .close = decode_end,
+ .decode = decode_frame,
.long_name = NULL_IF_CONFIG_SMALL("Kega Game Video"),
};
diff --git a/libavcodec/kmvc.c b/libavcodec/kmvc.c
index 718cdfd932..7ac4c01fba 100644
--- a/libavcodec/kmvc.c
+++ b/libavcodec/kmvc.c
@@ -2,20 +2,20 @@
* KMVC decoder
* Copyright (c) 2006 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -375,6 +375,7 @@ static av_cold int decode_init(AVCodecContext * avctx)
c->setpal = 1;
}
+ avcodec_get_frame_defaults(&c->pic);
avctx->pix_fmt = PIX_FMT_PAL8;
return 0;
@@ -398,14 +399,13 @@ static av_cold int decode_end(AVCodecContext * avctx)
}
AVCodec ff_kmvc_decoder = {
- "kmvc",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_KMVC,
- sizeof(KmvcContext),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- CODEC_CAP_DR1,
+ .name = "kmvc",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_KMVC,
+ .priv_data_size = sizeof(KmvcContext),
+ .init = decode_init,
+ .close = decode_end,
+ .decode = decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Karl Morton's video codec"),
};
diff --git a/libavcodec/lagarith.c b/libavcodec/lagarith.c
index 1c18b967e4..a632e52b0d 100644
--- a/libavcodec/lagarith.c
+++ b/libavcodec/lagarith.c
@@ -2,20 +2,20 @@
* Lagarith lossless decoder
* Copyright (c) 2009 Nathan Caldwell <saintdev (at) gmail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -509,14 +509,13 @@ static av_cold int lag_decode_end(AVCodecContext *avctx)
}
AVCodec ff_lagarith_decoder = {
- "lagarith",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_LAGARITH,
- sizeof(LagarithContext),
- lag_decode_init,
- NULL,
- lag_decode_end,
- lag_decode_frame,
- CODEC_CAP_DR1,
+ .name = "lagarith",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_LAGARITH,
+ .priv_data_size = sizeof(LagarithContext),
+ .init = lag_decode_init,
+ .close = lag_decode_end,
+ .decode = lag_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Lagarith lossless"),
};
diff --git a/libavcodec/lagarithrac.c b/libavcodec/lagarithrac.c
index ab7a60011d..56c1d0bcc0 100644
--- a/libavcodec/lagarithrac.c
+++ b/libavcodec/lagarithrac.c
@@ -3,20 +3,20 @@
* Copyright (c) 2009 Nathan Caldwell <saintdev (at) gmail.com>
* Copyright (c) 2009 David Conrad
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/lagarithrac.h b/libavcodec/lagarithrac.h
index b9421993a4..8c78538f21 100644
--- a/libavcodec/lagarithrac.h
+++ b/libavcodec/lagarithrac.h
@@ -3,20 +3,20 @@
* Copyright (c) 2009 Nathan Caldwell <saintdev (at) gmail.com>
* Copyright (c) 2009 David Conrad
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/latm_parser.c b/libavcodec/latm_parser.c
index fe39de8e09..8e42c6ace9 100644
--- a/libavcodec/latm_parser.c
+++ b/libavcodec/latm_parser.c
@@ -1,20 +1,20 @@
/*
* copyright (c) 2008 Paul Kendall <paul@kcbbs.gen.nz>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/lcl.h b/libavcodec/lcl.h
index 4e7e170138..b60c0e901a 100644
--- a/libavcodec/lcl.h
+++ b/libavcodec/lcl.h
@@ -2,20 +2,20 @@
* LCL (LossLess Codec Library) Codec
* Copyright (c) 2002-2004 Roberto Togni
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/lcldec.c b/libavcodec/lcldec.c
index f41a88934b..e288fc3f63 100644
--- a/libavcodec/lcldec.c
+++ b/libavcodec/lcldec.c
@@ -2,20 +2,20 @@
* LCL (LossLess Codec Library) Codec
* Copyright (c) 2002-2004 Roberto Togni
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -453,6 +453,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
unsigned int max_basesize = FFALIGN(avctx->width, 4) * FFALIGN(avctx->height, 4) + AV_LZO_OUTPUT_PADDING;
unsigned int max_decomp_size;
+ avcodec_get_frame_defaults(&c->pic);
if (avctx->extradata_size < 8) {
av_log(avctx, AV_LOG_ERROR, "Extradata size too small.\n");
return 1;
@@ -610,30 +611,28 @@ static av_cold int decode_end(AVCodecContext *avctx)
#if CONFIG_MSZH_DECODER
AVCodec ff_mszh_decoder = {
- "mszh",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_MSZH,
- sizeof(LclDecContext),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- CODEC_CAP_DR1,
+ .name = "mszh",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_MSZH,
+ .priv_data_size = sizeof(LclDecContext),
+ .init = decode_init,
+ .close = decode_end,
+ .decode = decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("LCL (LossLess Codec Library) MSZH"),
};
#endif
#if CONFIG_ZLIB_DECODER
AVCodec ff_zlib_decoder = {
- "zlib",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_ZLIB,
- sizeof(LclDecContext),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- CODEC_CAP_DR1,
+ .name = "zlib",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_ZLIB,
+ .priv_data_size = sizeof(LclDecContext),
+ .init = decode_init,
+ .close = decode_end,
+ .decode = decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("LCL (LossLess Codec Library) ZLIB"),
};
#endif
diff --git a/libavcodec/lclenc.c b/libavcodec/lclenc.c
index 3285d1afba..9f66960910 100644
--- a/libavcodec/lclenc.c
+++ b/libavcodec/lclenc.c
@@ -2,20 +2,20 @@
* LCL (LossLess Codec Library) Codec
* Copyright (c) 2002-2004 Roberto Togni
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -171,13 +171,13 @@ static av_cold int encode_end(AVCodecContext *avctx)
}
AVCodec ff_zlib_encoder = {
- "zlib",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_ZLIB,
- sizeof(LclEncContext),
- encode_init,
- encode_frame,
- encode_end,
+ .name = "zlib",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_ZLIB,
+ .priv_data_size = sizeof(LclEncContext),
+ .init = encode_init,
+ .encode = encode_frame,
+ .close = encode_end,
.pix_fmts = (const enum PixelFormat[]) { PIX_FMT_BGR24, PIX_FMT_NONE },
.long_name = NULL_IF_CONFIG_SMALL("LCL (LossLess Codec Library) ZLIB"),
};
diff --git a/libavcodec/libaacplus.c b/libavcodec/libaacplus.c
new file mode 100644
index 0000000000..c8c87be549
--- /dev/null
+++ b/libavcodec/libaacplus.c
@@ -0,0 +1,136 @@
+/*
+ * Interface to libaacplus for aac+ (sbr+ps) encoding
+ * Copyright (c) 2010 tipok <piratfm@gmail.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * Interface to libaacplus for aac+ (sbr+ps) encoding.
+ */
+
+#include "avcodec.h"
+#include <aacplus.h>
+
+typedef struct aacPlusAudioContext {
+ aacplusEncHandle aacplus_handle;
+} aacPlusAudioContext;
+
+static av_cold int aacPlus_encode_init(AVCodecContext *avctx)
+{
+ aacPlusAudioContext *s = avctx->priv_data;
+ aacplusEncConfiguration *aacplus_cfg;
+ unsigned long samples_input, max_bytes_output;
+
+ /* number of channels */
+ if (avctx->channels < 1 || avctx->channels > 2) {
+ av_log(avctx, AV_LOG_ERROR, "encoding %d channel(s) is not allowed\n", avctx->channels);
+ return -1;
+ }
+
+ s->aacplus_handle = aacplusEncOpen(avctx->sample_rate,
+ avctx->channels,
+ &samples_input, &max_bytes_output);
+ if(!s->aacplus_handle) {
+ av_log(avctx, AV_LOG_ERROR, "can't open encoder\n");
+ return -1;
+ }
+
+ /* check aacplus version */
+ aacplus_cfg = aacplusEncGetCurrentConfiguration(s->aacplus_handle);
+
+ /* put the options in the configuration struct */
+ if(avctx->profile != FF_PROFILE_AAC_LOW && avctx->profile != FF_PROFILE_UNKNOWN) {
+ av_log(avctx, AV_LOG_ERROR, "invalid AAC profile: %d, only LC supported\n", avctx->profile);
+ aacplusEncClose(s->aacplus_handle);
+ return -1;
+ }
+
+ aacplus_cfg->bitRate = avctx->bit_rate;
+ aacplus_cfg->bandWidth = avctx->cutoff;
+ if (avctx->flags & CODEC_FLAG_GLOBAL_HEADER) {
+ aacplus_cfg->outputFormat = 0; //raw aac
+ }
+ aacplus_cfg->inputFormat = AACPLUS_INPUT_16BIT;
+ if (!aacplusEncSetConfiguration(s->aacplus_handle, aacplus_cfg)) {
+ av_log(avctx, AV_LOG_ERROR, "libaacplus doesn't support this output format!\n");
+ return -1;
+ }
+
+ avctx->frame_size = samples_input / avctx->channels;
+
+ avctx->coded_frame= avcodec_alloc_frame();
+ avctx->coded_frame->key_frame= 1;
+
+ /* Set decoder specific info */
+ avctx->extradata_size = 0;
+ if (avctx->flags & CODEC_FLAG_GLOBAL_HEADER) {
+
+ unsigned char *buffer = NULL;
+ unsigned long decoder_specific_info_size;
+
+ if (aacplusEncGetDecoderSpecificInfo(s->aacplus_handle, &buffer,
+ &decoder_specific_info_size) == 1) {
+ avctx->extradata = av_malloc(decoder_specific_info_size + FF_INPUT_BUFFER_PADDING_SIZE);
+ avctx->extradata_size = decoder_specific_info_size;
+ memcpy(avctx->extradata, buffer, avctx->extradata_size);
+ }
+#undef free
+ free(buffer);
+#define free please_use_av_free
+ }
+ return 0;
+}
+
+static int aacPlus_encode_frame(AVCodecContext *avctx,
+ unsigned char *frame, int buf_size, void *data)
+{
+ aacPlusAudioContext *s = avctx->priv_data;
+ int bytes_written;
+
+ bytes_written = aacplusEncEncode(s->aacplus_handle,
+ data,
+ avctx->frame_size * avctx->channels,
+ frame,
+ buf_size);
+
+ return bytes_written;
+}
+
+static av_cold int aacPlus_encode_close(AVCodecContext *avctx)
+{
+ aacPlusAudioContext *s = avctx->priv_data;
+
+ av_freep(&avctx->coded_frame);
+ av_freep(&avctx->extradata);
+
+ aacplusEncClose(s->aacplus_handle);
+ return 0;
+}
+
+AVCodec ff_libaacplus_encoder = {
+ "libaacplus",
+ AVMEDIA_TYPE_AUDIO,
+ CODEC_ID_AAC,
+ sizeof(aacPlusAudioContext),
+ aacPlus_encode_init,
+ aacPlus_encode_frame,
+ aacPlus_encode_close,
+ .sample_fmts = (const enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE},
+ .long_name = NULL_IF_CONFIG_SMALL("libaacplus AAC+ (Advanced Audio Codec with SBR+PS)"),
+};
diff --git a/libavcodec/libavcodec.v b/libavcodec/libavcodec.v
index 65699038ab..9f6b01d103 100644
--- a/libavcodec/libavcodec.v
+++ b/libavcodec/libavcodec.v
@@ -1,9 +1,29 @@
LIBAVCODEC_$MAJOR {
- global: *;
- local:
- ff_*_bsf;
- ff_*_decoder;
- ff_*_encoder;
- ff_*_hwaccel;
- ff_*_parser;
+ global: av*;
+ audio_resample;
+ audio_resample_close;
+ #deprecated, remove after next bump
+ img_get_alpha_info;
+ dsputil_init;
+ ff_find_pix_fmt;
+ ff_framenum_to_drop_timecode;
+ ff_framenum_to_smtpe_timecode;
+ ff_raw_pix_fmt_tags;
+ ff_init_smtpe_timecode;
+ ff_fft*;
+ ff_mdct*;
+ ff_dct*;
+ ff_rdft*;
+ ff_prores_idct_put_10_sse2;
+ ff_simple_idct*;
+ ff_aanscales;
+ ff_faan*;
+ ff_mmx_idct;
+ ff_fdct*;
+ fdct_ifast;
+ j_rev_dct;
+ ff_mmxext_idct;
+ ff_idct_xvid*;
+ ff_jpeg_fdct*;
+ local: *;
};
diff --git a/libavcodec/libcelt_dec.c b/libavcodec/libcelt_dec.c
new file mode 100644
index 0000000000..6f3965401c
--- /dev/null
+++ b/libavcodec/libcelt_dec.c
@@ -0,0 +1,136 @@
+/*
+ * Xiph CELT / Opus decoder using libcelt
+ * Copyright (c) 2011 Nicolas George
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <celt/celt.h>
+#include <celt/celt_header.h>
+#include "avcodec.h"
+#include "libavutil/intreadwrite.h"
+
+struct libcelt_context {
+ CELTMode *mode;
+ CELTDecoder *dec;
+ int frame_bytes;
+ int discard;
+};
+
+static int ff_celt_error_to_averror(int err)
+{
+ switch(err) {
+ case CELT_BAD_ARG: return AVERROR(EINVAL);
+#ifdef CELT_BUFFER_TOO_SMALL
+ case CELT_BUFFER_TOO_SMALL: return AVERROR(ENOBUFS);
+#endif
+ case CELT_INTERNAL_ERROR: return AVERROR(EFAULT);
+ case CELT_CORRUPTED_DATA: return AVERROR_INVALIDDATA;
+ case CELT_UNIMPLEMENTED: return AVERROR(ENOTSUP);
+#ifdef ENOTRECOVERABLE
+ case CELT_INVALID_STATE: return AVERROR(ENOTRECOVERABLE);
+#endif
+ case CELT_ALLOC_FAIL: return AVERROR(ENOMEM);
+ default: return AVERROR(EINVAL);
+ }
+}
+
+static int ff_celt_bitstream_version_hack(CELTMode *mode)
+{
+ CELTHeader header = { .version_id = 0 };
+ celt_header_init(&header, mode, 960, 2);
+ return header.version_id;
+}
+
+static av_cold int libcelt_dec_init(AVCodecContext *c)
+{
+ struct libcelt_context *celt = c->priv_data;
+ int err;
+
+ if (!c->channels || !c->frame_size ||
+ c->frame_size > INT_MAX / sizeof(int16_t) / c->channels)
+ return AVERROR(EINVAL);
+ celt->frame_bytes = c->frame_size * c->channels * sizeof(int16_t);
+ celt->mode = celt_mode_create(c->sample_rate, c->frame_size, &err);
+ if (!celt->mode)
+ return ff_celt_error_to_averror(err);
+ celt->dec = celt_decoder_create_custom(celt->mode, c->channels, &err);
+ if (!celt->dec) {
+ celt_mode_destroy(celt->mode);
+ return ff_celt_error_to_averror(err);
+ }
+ if (c->extradata_size >= 4) {
+ celt->discard = AV_RL32(c->extradata);
+ if (celt->discard < 0 || celt->discard >= c->frame_size) {
+ av_log(c, AV_LOG_WARNING,
+ "Invalid overlap (%d), ignored.\n", celt->discard);
+ celt->discard = 0;
+ }
+ celt->discard *= c->channels * sizeof(int16_t);
+ }
+ if(c->extradata_size >= 8) {
+ unsigned version = AV_RL32(c->extradata + 4);
+ unsigned lib_version = ff_celt_bitstream_version_hack(celt->mode);
+ if (version != lib_version)
+ av_log(c, AV_LOG_WARNING,
+ "CELT bitstream version 0x%x may be "
+ "improperly decoded by libcelt for version 0x%x.\n",
+ version, lib_version);
+ }
+ return 0;
+}
+
+static av_cold int libcelt_dec_close(AVCodecContext *c)
+{
+ struct libcelt_context *celt = c->priv_data;
+
+ celt_decoder_destroy(celt->dec);
+ celt_mode_destroy(celt->mode);
+ return 0;
+}
+
+static int libcelt_dec_decode(AVCodecContext *c, void *pcm, int *pcm_size,
+ AVPacket *pkt)
+{
+ struct libcelt_context *celt = c->priv_data;
+ int err;
+
+ if (*pcm_size < celt->frame_bytes)
+ return AVERROR(ENOBUFS);
+ err = celt_decode(celt->dec, pkt->data, pkt->size, pcm, c->frame_size);
+ if (err < 0)
+ return ff_celt_error_to_averror(err);
+ *pcm_size = celt->frame_bytes;
+ if (celt->discard) {
+ *pcm_size = celt->frame_bytes - celt->discard;
+ memmove(pcm, (char *)pcm + celt->discard, *pcm_size);
+ celt->discard = 0;
+ }
+ return pkt->size;
+}
+
+AVCodec ff_libcelt_decoder = {
+ .name = "libcelt",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_CELT,
+ .priv_data_size = sizeof(struct libcelt_context),
+ .init = libcelt_dec_init,
+ .close = libcelt_dec_close,
+ .decode = libcelt_dec_decode,
+ .capabilities = 0,
+ .long_name = NULL_IF_CONFIG_SMALL("Xiph CELT/Opus decoder using libcelt"),
+};
diff --git a/libavcodec/libdirac.h b/libavcodec/libdirac.h
index 7f7912238d..0dc19ca338 100644
--- a/libavcodec/libdirac.h
+++ b/libavcodec/libdirac.h
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2008 BBC, Anuradha Suraparaju <asuraparaju at gmail dot com >
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -30,7 +30,7 @@
#include <libdirac_common/dirac_types.h>
/**
-* Table providing a Dirac chroma format to Libav pixel format mapping.
+* Table providing a Dirac chroma format to FFmpeg pixel format mapping.
*/
static const struct {
enum PixelFormat ff_pix_fmt;
diff --git a/libavcodec/libdirac_libschro.c b/libavcodec/libdirac_libschro.c
index 525d8663bc..aee185885e 100644
--- a/libavcodec/libdirac_libschro.c
+++ b/libavcodec/libdirac_libschro.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2008 BBC, Anuradha Suraparaju <asuraparaju at gmail dot com >
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/libdirac_libschro.h b/libavcodec/libdirac_libschro.h
index 9c2e9e7bb7..3d63f977cf 100644
--- a/libavcodec/libdirac_libschro.h
+++ b/libavcodec/libdirac_libschro.h
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2008 BBC, Anuradha Suraparaju <asuraparaju at gmail dot com >
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/libdiracdec.c b/libavcodec/libdiracdec.c
index 08fec3dfec..24a4a06929 100644
--- a/libavcodec/libdiracdec.c
+++ b/libavcodec/libdiracdec.c
@@ -3,20 +3,20 @@
* Copyright (c) 2005 BBC, Andrew Kennedy <dirac at rd dot bbc dot co dot uk>
* Copyright (c) 2006-2008 BBC, Anuradha Suraparaju <asuraparaju at gmail dot com >
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -47,7 +47,7 @@ typedef struct FfmpegDiracDecoderParams {
/**
-* returns Libav chroma format
+* returns FFmpeg chroma format
*/
static enum PixelFormat GetFfmpegChromaFormat(dirac_chroma_t dirac_pix_fmt)
{
@@ -103,7 +103,7 @@ static int libdirac_decode_frame(AVCodecContext *avccontext,
case STATE_SEQUENCE:
{
- /* tell Libav about sequence details */
+ /* tell FFmpeg about sequence details */
dirac_sourceparams_t *src_params = &p_dirac_params->p_decoder->src_params;
if (av_image_check_size(src_params->width, src_params->height,
@@ -195,15 +195,14 @@ static void libdirac_flush(AVCodecContext *avccontext)
AVCodec ff_libdirac_decoder = {
- "libdirac",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_DIRAC,
- sizeof(FfmpegDiracDecoderParams),
- libdirac_decode_init,
- NULL,
- libdirac_decode_close,
- libdirac_decode_frame,
- CODEC_CAP_DELAY,
+ .name = "libdirac",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_DIRAC,
+ .priv_data_size = sizeof(FfmpegDiracDecoderParams),
+ .init = libdirac_decode_init,
+ .close = libdirac_decode_close,
+ .decode = libdirac_decode_frame,
+ .capabilities = CODEC_CAP_DELAY,
.flush = libdirac_flush,
.long_name = NULL_IF_CONFIG_SMALL("libdirac Dirac 2.2"),
};
diff --git a/libavcodec/libdiracenc.c b/libavcodec/libdiracenc.c
index ff4b92f3c0..8bf0da4948 100644
--- a/libavcodec/libdiracenc.c
+++ b/libavcodec/libdiracenc.c
@@ -3,20 +3,20 @@
* Copyright (c) 2005 BBC, Andrew Kennedy <dirac at rd dot bbc dot co dot uk>
* Copyright (c) 2006-2008 BBC, Anuradha Suraparaju <asuraparaju at gmail dot com >
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -392,13 +392,13 @@ static av_cold int libdirac_encode_close(AVCodecContext *avccontext)
AVCodec ff_libdirac_encoder = {
- "libdirac",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_DIRAC,
- sizeof(FfmpegDiracEncoderParams),
- libdirac_encode_init,
- libdirac_encode_frame,
- libdirac_encode_close,
+ .name = "libdirac",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_DIRAC,
+ .priv_data_size = sizeof(FfmpegDiracEncoderParams),
+ .init = libdirac_encode_init,
+ .encode = libdirac_encode_frame,
+ .close = libdirac_encode_close,
.capabilities = CODEC_CAP_DELAY,
.pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_YUV422P, PIX_FMT_YUV444P, PIX_FMT_NONE},
.long_name = NULL_IF_CONFIG_SMALL("libdirac Dirac 2.2"),
diff --git a/libavcodec/libfaac.c b/libavcodec/libfaac.c
index 51d965e87a..31dc1a41ed 100644
--- a/libavcodec/libfaac.c
+++ b/libavcodec/libfaac.c
@@ -2,20 +2,20 @@
* Interface to libfaac for aac encoding
* Copyright (c) 2002 Gildas Bazin <gbazin@netcourrier.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -31,6 +31,13 @@ typedef struct FaacAudioContext {
faacEncHandle faac_handle;
} FaacAudioContext;
+static const int channel_maps[][6] = {
+ { 2, 0, 1 }, //< C L R
+ { 2, 0, 1, 3 }, //< C L R Cs
+ { 2, 0, 1, 3, 4 }, //< C L R Ls Rs
+ { 2, 0, 1, 4, 5, 3 }, //< C L R Ls Rs LFE
+};
+
static av_cold int Faac_encode_init(AVCodecContext *avctx)
{
FaacAudioContext *s = avctx->priv_data;
@@ -86,6 +93,9 @@ static av_cold int Faac_encode_init(AVCodecContext *avctx)
}
faac_cfg->outputFormat = 1;
faac_cfg->inputFormat = FAAC_INPUT_16BIT;
+ if (avctx->channels > 2)
+ memcpy(faac_cfg->channel_map, channel_maps[avctx->channels-3],
+ avctx->channels * sizeof(int));
avctx->frame_size = samples_input / avctx->channels;
@@ -155,13 +165,13 @@ static const AVProfile profiles[] = {
};
AVCodec ff_libfaac_encoder = {
- "libfaac",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_AAC,
- sizeof(FaacAudioContext),
- Faac_encode_init,
- Faac_encode_frame,
- Faac_encode_close,
+ .name = "libfaac",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_AAC,
+ .priv_data_size = sizeof(FaacAudioContext),
+ .init = Faac_encode_init,
+ .encode = Faac_encode_frame,
+ .close = Faac_encode_close,
.capabilities = CODEC_CAP_SMALL_LAST_FRAME | CODEC_CAP_DELAY,
.sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
.long_name = NULL_IF_CONFIG_SMALL("libfaac AAC (Advanced Audio Codec)"),
diff --git a/libavcodec/libgsm.c b/libavcodec/libgsm.c
index 34f29573db..1541b3b29e 100644
--- a/libavcodec/libgsm.c
+++ b/libavcodec/libgsm.c
@@ -3,20 +3,20 @@
* Copyright (c) 2005 Alban Bedel <albeu@free.fr>
* Copyright (c) 2006, 2007 Michel Bardiaux <mbardiaux@mediaxim.be>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -35,36 +35,26 @@
#define GSM_MS_BLOCK_SIZE 65
#define GSM_FRAME_SIZE 160
-static av_cold int libgsm_init(AVCodecContext *avctx) {
+static av_cold int libgsm_encode_init(AVCodecContext *avctx) {
if (avctx->channels > 1) {
av_log(avctx, AV_LOG_ERROR, "Mono required for GSM, got %d channels\n",
avctx->channels);
return -1;
}
- if(avctx->codec->decode){
- if(!avctx->channels)
- avctx->channels= 1;
-
- if(!avctx->sample_rate)
- avctx->sample_rate= 8000;
-
- avctx->sample_fmt = AV_SAMPLE_FMT_S16;
- }else{
- if (avctx->sample_rate != 8000) {
- av_log(avctx, AV_LOG_ERROR, "Sample rate 8000Hz required for GSM, got %dHz\n",
- avctx->sample_rate);
- if(avctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL)
- return -1;
- }
- if (avctx->bit_rate != 13000 /* Official */ &&
- avctx->bit_rate != 13200 /* Very common */ &&
- avctx->bit_rate != 0 /* Unknown; a.o. mov does not set bitrate when decoding */ ) {
- av_log(avctx, AV_LOG_ERROR, "Bitrate 13000bps required for GSM, got %dbps\n",
- avctx->bit_rate);
- if(avctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL)
- return -1;
- }
+ if (avctx->sample_rate != 8000) {
+ av_log(avctx, AV_LOG_ERROR, "Sample rate 8000Hz required for GSM, got %dHz\n",
+ avctx->sample_rate);
+ if (avctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL)
+ return -1;
+ }
+ if (avctx->bit_rate != 13000 /* Official */ &&
+ avctx->bit_rate != 13200 /* Very common */ &&
+ avctx->bit_rate != 0 /* Unknown; a.o. mov does not set bitrate when decoding */ ) {
+ av_log(avctx, AV_LOG_ERROR, "Bitrate 13000bps required for GSM, got %dbps\n",
+ avctx->bit_rate);
+ if (avctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL)
+ return -1;
}
avctx->priv_data = gsm_create();
@@ -88,7 +78,7 @@ static av_cold int libgsm_init(AVCodecContext *avctx) {
return 0;
}
-static av_cold int libgsm_close(AVCodecContext *avctx) {
+static av_cold int libgsm_encode_close(AVCodecContext *avctx) {
av_freep(&avctx->coded_frame);
gsm_destroy(avctx->priv_data);
avctx->priv_data = NULL;
@@ -113,33 +103,70 @@ static int libgsm_encode_frame(AVCodecContext *avctx,
AVCodec ff_libgsm_encoder = {
- "libgsm",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_GSM,
- 0,
- libgsm_init,
- libgsm_encode_frame,
- libgsm_close,
+ .name = "libgsm",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_GSM,
+ .init = libgsm_encode_init,
+ .encode = libgsm_encode_frame,
+ .close = libgsm_encode_close,
.sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
.long_name = NULL_IF_CONFIG_SMALL("libgsm GSM"),
};
AVCodec ff_libgsm_ms_encoder = {
- "libgsm_ms",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_GSM_MS,
- 0,
- libgsm_init,
- libgsm_encode_frame,
- libgsm_close,
+ .name = "libgsm_ms",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_GSM_MS,
+ .init = libgsm_encode_init,
+ .encode = libgsm_encode_frame,
+ .close = libgsm_encode_close,
.sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
.long_name = NULL_IF_CONFIG_SMALL("libgsm GSM Microsoft variant"),
};
+static av_cold int libgsm_decode_init(AVCodecContext *avctx) {
+ if (avctx->channels > 1) {
+ av_log(avctx, AV_LOG_ERROR, "Mono required for GSM, got %d channels\n",
+ avctx->channels);
+ return -1;
+ }
+
+ if (!avctx->channels)
+ avctx->channels = 1;
+
+ if (!avctx->sample_rate)
+ avctx->sample_rate = 8000;
+
+ avctx->sample_fmt = AV_SAMPLE_FMT_S16;
+
+ avctx->priv_data = gsm_create();
+
+ switch(avctx->codec_id) {
+ case CODEC_ID_GSM:
+ avctx->frame_size = GSM_FRAME_SIZE;
+ avctx->block_align = GSM_BLOCK_SIZE;
+ break;
+ case CODEC_ID_GSM_MS: {
+ int one = 1;
+ gsm_option(avctx->priv_data, GSM_OPT_WAV49, &one);
+ avctx->frame_size = 2 * GSM_FRAME_SIZE;
+ avctx->block_align = GSM_MS_BLOCK_SIZE;
+ }
+ }
+
+ return 0;
+}
+
+static av_cold int libgsm_decode_close(AVCodecContext *avctx) {
+ gsm_destroy(avctx->priv_data);
+ avctx->priv_data = NULL;
+ return 0;
+}
+
static int libgsm_decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
AVPacket *avpkt) {
- const uint8_t *buf = avpkt->data;
+ uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
*data_size = 0; /* In case of error */
if(buf_size < avctx->block_align) return -1;
@@ -157,25 +184,21 @@ static int libgsm_decode_frame(AVCodecContext *avctx,
}
AVCodec ff_libgsm_decoder = {
- "libgsm",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_GSM,
- 0,
- libgsm_init,
- NULL,
- libgsm_close,
- libgsm_decode_frame,
+ .name = "libgsm",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_GSM,
+ .init = libgsm_decode_init,
+ .close = libgsm_decode_close,
+ .decode = libgsm_decode_frame,
.long_name = NULL_IF_CONFIG_SMALL("libgsm GSM"),
};
AVCodec ff_libgsm_ms_decoder = {
- "libgsm_ms",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_GSM_MS,
- 0,
- libgsm_init,
- NULL,
- libgsm_close,
- libgsm_decode_frame,
+ .name = "libgsm_ms",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_GSM_MS,
+ .init = libgsm_decode_init,
+ .close = libgsm_decode_close,
+ .decode = libgsm_decode_frame,
.long_name = NULL_IF_CONFIG_SMALL("libgsm GSM Microsoft variant"),
};
diff --git a/libavcodec/libmp3lame.c b/libavcodec/libmp3lame.c
index 68f1bc9e2b..fcefa2915e 100644
--- a/libavcodec/libmp3lame.c
+++ b/libavcodec/libmp3lame.c
@@ -2,20 +2,20 @@
* Interface to libmp3lame for mp3 encoding
* Copyright (c) 2002 Lennert Buytenhek <buytenh@gnu.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -25,16 +25,24 @@
*/
#include "libavutil/intreadwrite.h"
+#include "libavutil/log.h"
+#include "libavutil/opt.h"
#include "avcodec.h"
#include "mpegaudio.h"
#include <lame/lame.h>
#define BUFFER_SIZE (7200 + 2*MPA_FRAME_SIZE + MPA_FRAME_SIZE/4)
typedef struct Mp3AudioContext {
+ AVClass *class;
lame_global_flags *gfp;
int stereo;
uint8_t buffer[BUFFER_SIZE];
int buffer_index;
+ struct {
+ int *left;
+ int *right;
+ } s32_data;
+ int reservoir;
} Mp3AudioContext;
static av_cold int MP3lame_encode_init(AVCodecContext *avctx)
@@ -64,15 +72,35 @@ static av_cold int MP3lame_encode_init(AVCodecContext *avctx)
lame_set_VBR_quality(s->gfp, avctx->global_quality/(float)FF_QP2LAMBDA);
}
lame_set_bWriteVbrTag(s->gfp,0);
- lame_set_disable_reservoir(s->gfp, avctx->flags2 & CODEC_FLAG2_BIT_RESERVOIR ? 0 : 1);
+#if FF_API_LAME_GLOBAL_OPTS
+ s->reservoir = avctx->flags2 & CODEC_FLAG2_BIT_RESERVOIR;
+#endif
+ lame_set_disable_reservoir(s->gfp, !s->reservoir);
if (lame_init_params(s->gfp) < 0)
goto err_close;
avctx->frame_size = lame_get_framesize(s->gfp);
- avctx->coded_frame= avcodec_alloc_frame();
+ if(!(avctx->coded_frame= avcodec_alloc_frame())) {
+ lame_close(s->gfp);
+
+ return AVERROR(ENOMEM);
+ }
avctx->coded_frame->key_frame= 1;
+ if(AV_SAMPLE_FMT_S32 == avctx->sample_fmt && s->stereo) {
+ int nelem = 2 * avctx->frame_size;
+
+ if(! (s->s32_data.left = av_malloc(nelem * sizeof(int)))) {
+ av_freep(&avctx->coded_frame);
+ lame_close(s->gfp);
+
+ return AVERROR(ENOMEM);
+ }
+
+ s->s32_data.right = s->s32_data.left + avctx->frame_size;
+ }
+
return 0;
err_close:
@@ -147,17 +175,35 @@ static int MP3lame_encode_frame(AVCodecContext *avctx,
/* lame 3.91 dies on '1-channel interleaved' data */
- if(data){
+ if(!data){
+ lame_result= lame_encode_flush(
+ s->gfp,
+ s->buffer + s->buffer_index,
+ BUFFER_SIZE - s->buffer_index
+ );
+#if 2147483647 == INT_MAX
+ }else if(AV_SAMPLE_FMT_S32 == avctx->sample_fmt){
if (s->stereo) {
- lame_result = lame_encode_buffer_interleaved(
+ int32_t *rp = data;
+ int32_t *mp = rp + 2*avctx->frame_size;
+ int *wpl = s->s32_data.left;
+ int *wpr = s->s32_data.right;
+
+ while (rp < mp) {
+ *wpl++ = *rp++;
+ *wpr++ = *rp++;
+ }
+
+ lame_result = lame_encode_buffer_int(
s->gfp,
- data,
+ s->s32_data.left,
+ s->s32_data.right,
avctx->frame_size,
s->buffer + s->buffer_index,
BUFFER_SIZE - s->buffer_index
);
} else {
- lame_result = lame_encode_buffer(
+ lame_result = lame_encode_buffer_int(
s->gfp,
data,
data,
@@ -166,12 +212,26 @@ static int MP3lame_encode_frame(AVCodecContext *avctx,
BUFFER_SIZE - s->buffer_index
);
}
+#endif
}else{
- lame_result= lame_encode_flush(
+ if (s->stereo) {
+ lame_result = lame_encode_buffer_interleaved(
+ s->gfp,
+ data,
+ avctx->frame_size,
+ s->buffer + s->buffer_index,
+ BUFFER_SIZE - s->buffer_index
+ );
+ } else {
+ lame_result = lame_encode_buffer(
s->gfp,
+ data,
+ data,
+ avctx->frame_size,
s->buffer + s->buffer_index,
BUFFER_SIZE - s->buffer_index
);
+ }
}
if(lame_result < 0){
@@ -207,23 +267,42 @@ static av_cold int MP3lame_encode_close(AVCodecContext *avctx)
{
Mp3AudioContext *s = avctx->priv_data;
+ av_freep(&s->s32_data.left);
av_freep(&avctx->coded_frame);
lame_close(s->gfp);
return 0;
}
+#define OFFSET(x) offsetof(Mp3AudioContext, x)
+#define AE AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
+static const AVOption options[] = {
+ { "reservoir", "Use bit reservoir.", OFFSET(reservoir), AV_OPT_TYPE_INT, { 1 }, 0, 1, AE },
+ { NULL },
+};
+
+static const AVClass libmp3lame_class = {
+ .class_name = "libmp3lame encoder",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
AVCodec ff_libmp3lame_encoder = {
- "libmp3lame",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_MP3,
- sizeof(Mp3AudioContext),
- MP3lame_encode_init,
- MP3lame_encode_frame,
- MP3lame_encode_close,
+ .name = "libmp3lame",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_MP3,
+ .priv_data_size = sizeof(Mp3AudioContext),
+ .init = MP3lame_encode_init,
+ .encode = MP3lame_encode_frame,
+ .close = MP3lame_encode_close,
.capabilities= CODEC_CAP_DELAY,
- .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
+ .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,
+#if 2147483647 == INT_MAX
+ AV_SAMPLE_FMT_S32,
+#endif
+ AV_SAMPLE_FMT_NONE},
.supported_samplerates= sSampleRates,
.long_name= NULL_IF_CONFIG_SMALL("libmp3lame MP3 (MPEG audio layer 3)"),
+ .priv_class = &libmp3lame_class,
};
diff --git a/libavcodec/libopencore-amr.c b/libavcodec/libopencore-amr.c
index cf8bdbbcb8..7af773f581 100644
--- a/libavcodec/libopencore-amr.c
+++ b/libavcodec/libopencore-amr.c
@@ -2,20 +2,20 @@
* AMR Audio decoder stub
* Copyright (c) 2003 the ffmpeg project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -88,7 +88,7 @@ typedef struct AMRContext {
} AMRContext;
static const AVOption options[] = {
- { "dtx", "Allow DTX (generate comfort noise)", offsetof(AMRContext, enc_dtx), FF_OPT_TYPE_INT, 0, 0, 1, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
+ { "dtx", "Allow DTX (generate comfort noise)", offsetof(AMRContext, enc_dtx), AV_OPT_TYPE_INT, { 0 }, 0, 1, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
{ NULL }
};
@@ -158,14 +158,13 @@ static int amr_nb_decode_frame(AVCodecContext *avctx, void *data,
}
AVCodec ff_libopencore_amrnb_decoder = {
- "libopencore_amrnb",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_AMR_NB,
- sizeof(AMRContext),
- amr_nb_decode_init,
- NULL,
- amr_nb_decode_close,
- amr_nb_decode_frame,
+ .name = "libopencore_amrnb",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_AMR_NB,
+ .priv_data_size = sizeof(AMRContext),
+ .init = amr_nb_decode_init,
+ .close = amr_nb_decode_close,
+ .decode = amr_nb_decode_frame,
.long_name = NULL_IF_CONFIG_SMALL("OpenCORE Adaptive Multi-Rate (AMR) Narrow-Band"),
};
@@ -230,14 +229,13 @@ static int amr_nb_encode_frame(AVCodecContext *avctx,
}
AVCodec ff_libopencore_amrnb_encoder = {
- "libopencore_amrnb",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_AMR_NB,
- sizeof(AMRContext),
- amr_nb_encode_init,
- amr_nb_encode_frame,
- amr_nb_encode_close,
- NULL,
+ .name = "libopencore_amrnb",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_AMR_NB,
+ .priv_data_size = sizeof(AMRContext),
+ .init = amr_nb_encode_init,
+ .encode = amr_nb_encode_frame,
+ .close = amr_nb_encode_close,
.sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
.long_name = NULL_IF_CONFIG_SMALL("OpenCORE Adaptive Multi-Rate (AMR) Narrow-Band"),
.priv_class = &class,
@@ -308,14 +306,13 @@ static int amr_wb_decode_close(AVCodecContext *avctx)
}
AVCodec ff_libopencore_amrwb_decoder = {
- "libopencore_amrwb",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_AMR_WB,
- sizeof(AMRWBContext),
- amr_wb_decode_init,
- NULL,
- amr_wb_decode_close,
- amr_wb_decode_frame,
+ .name = "libopencore_amrwb",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_AMR_WB,
+ .priv_data_size = sizeof(AMRWBContext),
+ .init = amr_wb_decode_init,
+ .close = amr_wb_decode_close,
+ .decode = amr_wb_decode_frame,
.long_name = NULL_IF_CONFIG_SMALL("OpenCORE Adaptive Multi-Rate (AMR) Wide-Band"),
};
diff --git a/libavcodec/libopenjpeg.c b/libavcodec/libopenjpeg.c
index 342dcd98ac..42c71e361c 100644
--- a/libavcodec/libopenjpeg.c
+++ b/libavcodec/libopenjpeg.c
@@ -2,20 +2,20 @@
* JPEG 2000 decoding support via OpenJPEG
* Copyright (c) 2009 Jaikrishnan Menon <realityman@gmx.net>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -27,6 +27,7 @@
#include "libavutil/imgutils.h"
#include "avcodec.h"
#include "libavutil/intreadwrite.h"
+#include "thread.h"
#define OPJ_STATIC
#include <openjpeg.h>
@@ -53,6 +54,15 @@ static av_cold int libopenjpeg_decode_init(AVCodecContext *avctx)
LibOpenJPEGContext *ctx = avctx->priv_data;
opj_set_default_decoder_parameters(&ctx->dec_params);
+ avcodec_get_frame_defaults(&ctx->image);
+ avctx->coded_frame = &ctx->image;
+ return 0;
+}
+
+static av_cold int libopenjpeg_decode_init_thread_copy(AVCodecContext *avctx)
+{
+ LibOpenJPEGContext *ctx = avctx->priv_data;
+
avctx->coded_frame = &ctx->image;
return 0;
}
@@ -61,7 +71,7 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
AVPacket *avpkt)
{
- const uint8_t *buf = avpkt->data;
+ uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
LibOpenJPEGContext *ctx = avctx->priv_data;
AVFrame *picture = &ctx->image, *output = data;
@@ -94,7 +104,7 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx,
}
opj_set_event_mgr((opj_common_ptr)dec, NULL, NULL);
- ctx->dec_params.cp_reduce = avctx->lowres;
+ ctx->dec_params.cp_limit_decoding = LIMIT_TO_MAIN_HEADER;
// Tie decoder with decoding parameters
opj_setup_decoder(dec, &ctx->dec_params);
stream = opj_cio_open((opj_common_ptr)dec, buf, buf_size);
@@ -104,7 +114,7 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx,
return -1;
}
- // Decode the codestream
+ // Decode the header only
image = opj_decode_with_info(dec, stream, NULL);
opj_cio_close(stream);
if(!image) {
@@ -112,8 +122,8 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx,
opj_destroy_decompress(dec);
return -1;
}
- width = image->comps[0].w << avctx->lowres;
- height = image->comps[0].h << avctx->lowres;
+ width = image->x1 - image->x0;
+ height = image->y1 - image->y0;
if(av_image_check_size(width, height, 0, avctx) < 0) {
av_log(avctx, AV_LOG_ERROR, "%dx%d dimension invalid.\n", width, height);
goto done;
@@ -139,13 +149,30 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx,
}
if(picture->data[0])
- avctx->release_buffer(avctx, picture);
+ ff_thread_release_buffer(avctx, picture);
+
+ if(ff_thread_get_buffer(avctx, picture) < 0){
+ av_log(avctx, AV_LOG_ERROR, "ff_thread_get_buffer() failed\n");
+ return -1;
+ }
- if(avctx->get_buffer(avctx, picture) < 0) {
- av_log(avctx, AV_LOG_ERROR, "Couldn't allocate image buffer.\n");
+ ff_thread_finish_setup(avctx);
+
+ ctx->dec_params.cp_limit_decoding = NO_LIMITATION;
+ ctx->dec_params.cp_reduce = avctx->lowres;
+ // Tie decoder with decoding parameters
+ opj_setup_decoder(dec, &ctx->dec_params);
+ stream = opj_cio_open((opj_common_ptr)dec, buf, buf_size);
+ if(!stream) {
+ av_log(avctx, AV_LOG_ERROR, "Codestream could not be opened for reading.\n");
+ opj_destroy_decompress(dec);
return -1;
}
+ // Decode the codestream
+ image = opj_decode_with_info(dec, stream, NULL);
+ opj_cio_close(stream);
+
for(x = 0; x < image->numcomps; x++) {
adjust[x] = FFMAX(image->comps[x].prec - 8, 0);
}
@@ -179,21 +206,21 @@ static av_cold int libopenjpeg_decode_close(AVCodecContext *avctx)
LibOpenJPEGContext *ctx = avctx->priv_data;
if(ctx->image.data[0])
- avctx->release_buffer(avctx, &ctx->image);
+ ff_thread_release_buffer(avctx, &ctx->image);
return 0 ;
}
AVCodec ff_libopenjpeg_decoder = {
- "libopenjpeg",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_JPEG2000,
- sizeof(LibOpenJPEGContext),
- libopenjpeg_decode_init,
- NULL,
- libopenjpeg_decode_close,
- libopenjpeg_decode_frame,
- CODEC_CAP_DR1,
- .max_lowres = 5,
- .long_name = NULL_IF_CONFIG_SMALL("OpenJPEG based JPEG 2000 decoder"),
-} ;
+ .name = "libopenjpeg",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_JPEG2000,
+ .priv_data_size = sizeof(LibOpenJPEGContext),
+ .init = libopenjpeg_decode_init,
+ .close = libopenjpeg_decode_close,
+ .decode = libopenjpeg_decode_frame,
+ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_FRAME_THREADS,
+ .max_lowres = 5,
+ .long_name = NULL_IF_CONFIG_SMALL("OpenJPEG based JPEG 2000 decoder"),
+ .init_thread_copy = ONLY_IF_THREADS_ENABLED(libopenjpeg_decode_init_thread_copy)
+};
diff --git a/libavcodec/libschroedinger.c b/libavcodec/libschroedinger.c
index 804d652ff7..04c15a2a01 100644
--- a/libavcodec/libschroedinger.c
+++ b/libavcodec/libschroedinger.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2008 BBC, Anuradha Suraparaju <asuraparaju at gmail dot com >
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/libschroedinger.h b/libavcodec/libschroedinger.h
index c9e2a5ecb0..65a41e642a 100644
--- a/libavcodec/libschroedinger.h
+++ b/libavcodec/libschroedinger.h
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2008 BBC, Anuradha Suraparaju <asuraparaju at gmail dot com >
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/libschroedingerdec.c b/libavcodec/libschroedingerdec.c
index ee29704d92..2c019b2fa6 100644
--- a/libavcodec/libschroedingerdec.c
+++ b/libavcodec/libschroedingerdec.c
@@ -2,20 +2,20 @@
* Dirac decoder support via Schroedinger libraries
* Copyright (c) 2008 BBC, Anuradha Suraparaju <asuraparaju at gmail dot com >
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -118,7 +118,7 @@ static SchroBuffer* FfmpegFindNextSchroParseUnit(FfmpegSchroParseUnitContext *pa
}
/**
-* Returns Libav chroma format.
+* Returns FFmpeg chroma format.
*/
static enum PixelFormat GetFfmpegChromaFormat(SchroChromaFormat schro_pix_fmt)
{
@@ -169,7 +169,7 @@ static void libschroedinger_handle_first_access_unit(AVCodecContext *avccontext)
p_schro_params->format = schro_decoder_get_video_format(decoder);
- /* Tell Libav about sequence details. */
+ /* Tell FFmpeg about sequence details. */
if (av_image_check_size(p_schro_params->format->width, p_schro_params->format->height,
0, avccontext) < 0) {
av_log(avccontext, AV_LOG_ERROR, "invalid dimensions (%dx%d)\n",
@@ -208,7 +208,6 @@ static int libschroedinger_decode_frame(AVCodecContext *avccontext,
FfmpegSchroDecoderParams *p_schro_params = avccontext->priv_data;
SchroDecoder *decoder = p_schro_params->decoder;
- SchroVideoFormat *format;
AVPicture *picture = data;
SchroBuffer *enc_buf;
SchroFrame* frame;
@@ -240,7 +239,6 @@ static int libschroedinger_decode_frame(AVCodecContext *avccontext,
go = 1;
} else
outer = 0;
- format = p_schro_params->format;
while (go) {
/* Parse data and process result. */
@@ -347,15 +345,14 @@ static void libschroedinger_flush(AVCodecContext *avccontext)
}
AVCodec ff_libschroedinger_decoder = {
- "libschroedinger",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_DIRAC,
- sizeof(FfmpegSchroDecoderParams),
- libschroedinger_decode_init,
- NULL,
- libschroedinger_decode_close,
- libschroedinger_decode_frame,
- CODEC_CAP_DELAY,
+ .name = "libschroedinger",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_DIRAC,
+ .priv_data_size = sizeof(FfmpegSchroDecoderParams),
+ .init = libschroedinger_decode_init,
+ .close = libschroedinger_decode_close,
+ .decode = libschroedinger_decode_frame,
+ .capabilities = CODEC_CAP_DELAY,
.flush = libschroedinger_flush,
.long_name = NULL_IF_CONFIG_SMALL("libschroedinger Dirac 2.2"),
};
diff --git a/libavcodec/libschroedingerenc.c b/libavcodec/libschroedingerenc.c
index d7190d06a4..f36b90e4eb 100644
--- a/libavcodec/libschroedingerenc.c
+++ b/libavcodec/libschroedingerenc.c
@@ -2,20 +2,20 @@
* Dirac encoder support via Schroedinger libraries
* Copyright (c) 2008 BBC, Anuradha Suraparaju <asuraparaju at gmail dot com >
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -423,13 +423,13 @@ static int libschroedinger_encode_close(AVCodecContext *avccontext)
AVCodec ff_libschroedinger_encoder = {
- "libschroedinger",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_DIRAC,
- sizeof(FfmpegSchroEncoderParams),
- libschroedinger_encode_init,
- libschroedinger_encode_frame,
- libschroedinger_encode_close,
+ .name = "libschroedinger",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_DIRAC,
+ .priv_data_size = sizeof(FfmpegSchroEncoderParams),
+ .init = libschroedinger_encode_init,
+ .encode = libschroedinger_encode_frame,
+ .close = libschroedinger_encode_close,
.capabilities = CODEC_CAP_DELAY,
.pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_YUV422P, PIX_FMT_YUV444P, PIX_FMT_NONE},
.long_name = NULL_IF_CONFIG_SMALL("libschroedinger Dirac 2.2"),
diff --git a/libavcodec/libspeexdec.c b/libavcodec/libspeexdec.c
index e6626dc88b..91f190525d 100644
--- a/libavcodec/libspeexdec.c
+++ b/libavcodec/libspeexdec.c
@@ -1,28 +1,28 @@
/*
* Copyright (C) 2008 David Conrad
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include "avcodec.h"
#include <speex/speex.h>
#include <speex/speex_header.h>
#include <speex/speex_stereo.h>
#include <speex/speex_callbacks.h>
+#include "avcodec.h"
typedef struct {
SpeexBits bits;
@@ -60,14 +60,14 @@ static av_cold int libspeex_decode_init(AVCodecContext *avctx)
mode = speex_lib_get_mode(s->header->mode);
if (!mode) {
av_log(avctx, AV_LOG_ERROR, "Unknown Speex mode %d", s->header->mode);
- return -1;
+ return AVERROR_INVALIDDATA;
}
} else
av_log(avctx, AV_LOG_INFO, "Missing Speex header, assuming defaults.\n");
if (avctx->channels > 2) {
av_log(avctx, AV_LOG_ERROR, "Only stereo and mono are supported.\n");
- return -1;
+ return AVERROR(EINVAL);
}
speex_bits_init(&s->bits);
@@ -96,35 +96,45 @@ static int libspeex_decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
AVPacket *avpkt)
{
- const uint8_t *buf = avpkt->data;
+ uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
LibSpeexContext *s = avctx->priv_data;
- int16_t *output = data, *end;
- int i, num_samples;
-
- num_samples = s->frame_size * avctx->channels;
- end = output + *data_size / sizeof(*output);
-
- speex_bits_read_from(&s->bits, buf, buf_size);
-
- for (i = 0; speex_bits_remaining(&s->bits) && output + num_samples < end; i++) {
- int ret = speex_decode_int(s->dec_state, &s->bits, output);
- if (ret <= -2) {
- av_log(avctx, AV_LOG_ERROR, "Error decoding Speex frame.\n");
- return -1;
- } else if (ret == -1)
- // end of stream
- break;
+ int16_t *output = data;
+ int out_size, ret, consumed = 0;
+
+ /* check output buffer size */
+ out_size = s->frame_size * avctx->channels *
+ av_get_bytes_per_sample(avctx->sample_fmt);
+ if (*data_size < out_size) {
+ av_log(avctx, AV_LOG_ERROR, "Output buffer is too small\n");
+ return AVERROR(EINVAL);
+ }
- if (avctx->channels == 2)
- speex_decode_stereo_int(output, s->frame_size, &s->stereo);
+ /* if there is not enough data left for the smallest possible frame,
+ reset the libspeex buffer using the current packet, otherwise ignore
+ the current packet and keep decoding frames from the libspeex buffer. */
+ if (speex_bits_remaining(&s->bits) < 43) {
+ /* check for flush packet */
+ if (!buf || !buf_size) {
+ *data_size = 0;
+ return buf_size;
+ }
+ /* set new buffer */
+ speex_bits_read_from(&s->bits, buf, buf_size);
+ consumed = buf_size;
+ }
- output += num_samples;
+ /* decode a single frame */
+ ret = speex_decode_int(s->dec_state, &s->bits, output);
+ if (ret <= -2) {
+ av_log(avctx, AV_LOG_ERROR, "Error decoding Speex frame.\n");
+ return AVERROR_INVALIDDATA;
}
+ if (avctx->channels == 2)
+ speex_decode_stereo_int(output, s->frame_size, &s->stereo);
- avctx->frame_size = s->frame_size * i;
- *data_size = avctx->channels * avctx->frame_size * sizeof(*output);
- return buf_size;
+ *data_size = out_size;
+ return consumed;
}
static av_cold int libspeex_decode_close(AVCodecContext *avctx)
@@ -138,14 +148,21 @@ static av_cold int libspeex_decode_close(AVCodecContext *avctx)
return 0;
}
+static av_cold void libspeex_decode_flush(AVCodecContext *avctx)
+{
+ LibSpeexContext *s = avctx->priv_data;
+ speex_bits_reset(&s->bits);
+}
+
AVCodec ff_libspeex_decoder = {
- "libspeex",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_SPEEX,
- sizeof(LibSpeexContext),
- libspeex_decode_init,
- NULL,
- libspeex_decode_close,
- libspeex_decode_frame,
+ .name = "libspeex",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_SPEEX,
+ .priv_data_size = sizeof(LibSpeexContext),
+ .init = libspeex_decode_init,
+ .close = libspeex_decode_close,
+ .decode = libspeex_decode_frame,
+ .flush = libspeex_decode_flush,
+ .capabilities = CODEC_CAP_SUBFRAMES | CODEC_CAP_DELAY,
.long_name = NULL_IF_CONFIG_SMALL("libspeex Speex"),
};
diff --git a/libavcodec/libspeexenc.c b/libavcodec/libspeexenc.c
new file mode 100644
index 0000000000..a3176d1388
--- /dev/null
+++ b/libavcodec/libspeexenc.c
@@ -0,0 +1,324 @@
+/*
+ * Copyright (C) 2009 Justin Ruggles
+ * Copyright (c) 2009 Xuggle Incorporated
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * libspeex Speex audio encoder
+ *
+ * Usage Guide
+ * This explains the values that need to be set prior to initialization in
+ * order to control various encoding parameters.
+ *
+ * Channels
+ * Speex only supports mono or stereo, so avctx->channels must be set to
+ * 1 or 2.
+ *
+ * Sample Rate / Encoding Mode
+ * Speex has 3 modes, each of which uses a specific sample rate.
+ * narrowband : 8 kHz
+ * wideband : 16 kHz
+ * ultra-wideband : 32 kHz
+ * avctx->sample_rate must be set to one of these 3 values. This will be
+ * used to set the encoding mode.
+ *
+ * Rate Control
+ * VBR mode is turned on by setting CODEC_FLAG_QSCALE in avctx->flags.
+ * avctx->global_quality is used to set the encoding quality.
+ * For CBR mode, avctx->bit_rate can be used to set the constant bitrate.
+ * Alternatively, the 'cbr_quality' option can be set from 0 to 10 to set
+ * a constant bitrate based on quality.
+ * For ABR mode, set avctx->bit_rate and set the 'abr' option to 1.
+ * Approx. Bitrate Range:
+ * narrowband : 2400 - 25600 bps
+ * wideband : 4000 - 43200 bps
+ * ultra-wideband : 4400 - 45200 bps
+ *
+ * Complexity
+ * Encoding complexity is controlled by setting avctx->compression_level.
+ * The valid range is 0 to 10. A higher setting gives generally better
+ * quality at the expense of encoding speed. This does not affect the
+ * bit rate.
+ *
+ * Frames-per-Packet
+ * The encoder defaults to using 1 frame-per-packet. However, it is
+ * sometimes desirable to use multiple frames-per-packet to reduce the
+ * amount of container overhead. This can be done by setting the
+ * 'frames_per_packet' option to a value 1 to 8.
+ */
+
+#include <speex/speex.h>
+#include <speex/speex_header.h>
+#include <speex/speex_stereo.h>
+#include "libavutil/mathematics.h"
+#include "libavutil/opt.h"
+#include "avcodec.h"
+#include "internal.h"
+
+typedef struct {
+ AVClass *class; ///< AVClass for private options
+ SpeexBits bits; ///< libspeex bitwriter context
+ SpeexHeader header; ///< libspeex header struct
+ void *enc_state; ///< libspeex encoder state
+ int frames_per_packet; ///< number of frames to encode in each packet
+ float vbr_quality; ///< VBR quality 0.0 to 10.0
+ int cbr_quality; ///< CBR quality 0 to 10
+ int abr; ///< flag to enable ABR
+ int pkt_frame_count; ///< frame count for the current packet
+ int lookahead; ///< encoder delay
+ int sample_count; ///< total sample count (used for pts)
+} LibSpeexEncContext;
+
+static av_cold void print_enc_params(AVCodecContext *avctx,
+ LibSpeexEncContext *s)
+{
+ const char *mode_str = "unknown";
+
+ av_log(avctx, AV_LOG_DEBUG, "channels: %d\n", avctx->channels);
+ switch (s->header.mode) {
+ case SPEEX_MODEID_NB: mode_str = "narrowband"; break;
+ case SPEEX_MODEID_WB: mode_str = "wideband"; break;
+ case SPEEX_MODEID_UWB: mode_str = "ultra-wideband"; break;
+ }
+ av_log(avctx, AV_LOG_DEBUG, "mode: %s\n", mode_str);
+ if (s->header.vbr) {
+ av_log(avctx, AV_LOG_DEBUG, "rate control: VBR\n");
+ av_log(avctx, AV_LOG_DEBUG, " quality: %f\n", s->vbr_quality);
+ } else if (s->abr) {
+ av_log(avctx, AV_LOG_DEBUG, "rate control: ABR\n");
+ av_log(avctx, AV_LOG_DEBUG, " bitrate: %d bps\n", avctx->bit_rate);
+ } else {
+ av_log(avctx, AV_LOG_DEBUG, "rate control: CBR\n");
+ av_log(avctx, AV_LOG_DEBUG, " bitrate: %d bps\n", avctx->bit_rate);
+ }
+ av_log(avctx, AV_LOG_DEBUG, "complexity: %d\n",
+ avctx->compression_level);
+ av_log(avctx, AV_LOG_DEBUG, "frame size: %d samples\n",
+ avctx->frame_size);
+ av_log(avctx, AV_LOG_DEBUG, "frames per packet: %d\n",
+ s->frames_per_packet);
+ av_log(avctx, AV_LOG_DEBUG, "packet size: %d\n",
+ avctx->frame_size * s->frames_per_packet);
+}
+
+static av_cold int encode_init(AVCodecContext *avctx)
+{
+ LibSpeexEncContext *s = avctx->priv_data;
+ const SpeexMode *mode;
+ uint8_t *header_data;
+ int header_size;
+ int32_t complexity;
+
+ /* channels */
+ if (avctx->channels < 1 || avctx->channels > 2) {
+ av_log(avctx, AV_LOG_ERROR, "Invalid channels (%d). Only stereo and "
+ "mono are supported\n", avctx->channels);
+ return AVERROR(EINVAL);
+ }
+
+ /* sample rate and encoding mode */
+ switch (avctx->sample_rate) {
+ case 8000: mode = &speex_nb_mode; break;
+ case 16000: mode = &speex_wb_mode; break;
+ case 32000: mode = &speex_uwb_mode; break;
+ default:
+ av_log(avctx, AV_LOG_ERROR, "Sample rate of %d Hz is not supported. "
+ "Resample to 8, 16, or 32 kHz.\n", avctx->sample_rate);
+ return AVERROR(EINVAL);
+ }
+
+ /* initialize libspeex */
+ s->enc_state = speex_encoder_init(mode);
+ if (!s->enc_state) {
+ av_log(avctx, AV_LOG_ERROR, "Error initializing libspeex\n");
+ return -1;
+ }
+ speex_init_header(&s->header, avctx->sample_rate, avctx->channels, mode);
+
+ /* rate control method and parameters */
+ if (avctx->flags & CODEC_FLAG_QSCALE) {
+ /* VBR */
+ s->header.vbr = 1;
+ speex_encoder_ctl(s->enc_state, SPEEX_SET_VBR, &s->header.vbr);
+ s->vbr_quality = av_clipf(avctx->global_quality / (float)FF_QP2LAMBDA,
+ 0.0f, 10.0f);
+ speex_encoder_ctl(s->enc_state, SPEEX_SET_VBR_QUALITY, &s->vbr_quality);
+ } else {
+ s->header.bitrate = avctx->bit_rate;
+ if (avctx->bit_rate > 0) {
+ /* CBR or ABR by bitrate */
+ if (s->abr) {
+ speex_encoder_ctl(s->enc_state, SPEEX_SET_ABR,
+ &s->header.bitrate);
+ speex_encoder_ctl(s->enc_state, SPEEX_GET_ABR,
+ &s->header.bitrate);
+ } else {
+ speex_encoder_ctl(s->enc_state, SPEEX_SET_BITRATE,
+ &s->header.bitrate);
+ speex_encoder_ctl(s->enc_state, SPEEX_GET_BITRATE,
+ &s->header.bitrate);
+ }
+ } else {
+ /* CBR by quality */
+ speex_encoder_ctl(s->enc_state, SPEEX_SET_QUALITY,
+ &s->cbr_quality);
+ speex_encoder_ctl(s->enc_state, SPEEX_GET_BITRATE,
+ &s->header.bitrate);
+ }
+ /* stereo side information adds about 800 bps to the base bitrate */
+ /* TODO: this should be calculated exactly */
+ avctx->bit_rate = s->header.bitrate + (avctx->channels == 2 ? 800 : 0);
+ }
+
+ /* set encoding complexity */
+ if (avctx->compression_level > FF_COMPRESSION_DEFAULT) {
+ complexity = av_clip(avctx->compression_level, 0, 10);
+ speex_encoder_ctl(s->enc_state, SPEEX_SET_COMPLEXITY, &complexity);
+ }
+ speex_encoder_ctl(s->enc_state, SPEEX_GET_COMPLEXITY, &complexity);
+ avctx->compression_level = complexity;
+
+ /* set packet size */
+ avctx->frame_size = s->header.frame_size;
+ s->header.frames_per_packet = s->frames_per_packet;
+
+ /* set encoding delay */
+ speex_encoder_ctl(s->enc_state, SPEEX_GET_LOOKAHEAD, &s->lookahead);
+ s->sample_count = -s->lookahead;
+
+ /* create header packet bytes from header struct */
+ /* note: libspeex allocates the memory for header_data, which is freed
+ below with speex_header_free() */
+ header_data = speex_header_to_packet(&s->header, &header_size);
+
+ /* allocate extradata and coded_frame */
+ avctx->extradata = av_malloc(header_size + FF_INPUT_BUFFER_PADDING_SIZE);
+ avctx->coded_frame = avcodec_alloc_frame();
+ if (!avctx->extradata || !avctx->coded_frame) {
+ speex_header_free(header_data);
+ speex_encoder_destroy(s->enc_state);
+ av_log(avctx, AV_LOG_ERROR, "memory allocation error\n");
+ return AVERROR(ENOMEM);
+ }
+
+ /* copy header packet to extradata */
+ memcpy(avctx->extradata, header_data, header_size);
+ avctx->extradata_size = header_size;
+ speex_header_free(header_data);
+
+ /* init libspeex bitwriter */
+ speex_bits_init(&s->bits);
+
+ print_enc_params(avctx, s);
+ return 0;
+}
+
+static int encode_frame(AVCodecContext *avctx, uint8_t *frame, int buf_size,
+ void *data)
+{
+ LibSpeexEncContext *s = avctx->priv_data;
+ int16_t *samples = data;
+ int sample_count = s->sample_count;
+
+ if (data) {
+ /* encode Speex frame */
+ if (avctx->channels == 2)
+ speex_encode_stereo_int(samples, s->header.frame_size, &s->bits);
+ speex_encode_int(s->enc_state, samples, &s->bits);
+ s->pkt_frame_count++;
+ s->sample_count += avctx->frame_size;
+ } else {
+ /* handle end-of-stream */
+ if (!s->pkt_frame_count)
+ return 0;
+ /* add extra terminator codes for unused frames in last packet */
+ while (s->pkt_frame_count < s->frames_per_packet) {
+ speex_bits_pack(&s->bits, 15, 5);
+ s->pkt_frame_count++;
+ }
+ }
+
+ /* write output if all frames for the packet have been encoded */
+ if (s->pkt_frame_count == s->frames_per_packet) {
+ s->pkt_frame_count = 0;
+ avctx->coded_frame->pts =
+ av_rescale_q(sample_count, (AVRational){ 1, avctx->sample_rate },
+ avctx->time_base);
+ if (buf_size > speex_bits_nbytes(&s->bits)) {
+ int ret = speex_bits_write(&s->bits, frame, buf_size);
+ speex_bits_reset(&s->bits);
+ return ret;
+ } else {
+ av_log(avctx, AV_LOG_ERROR, "output buffer too small");
+ return AVERROR(EINVAL);
+ }
+ }
+ return 0;
+}
+
+static av_cold int encode_close(AVCodecContext *avctx)
+{
+ LibSpeexEncContext *s = avctx->priv_data;
+
+ speex_bits_destroy(&s->bits);
+ speex_encoder_destroy(s->enc_state);
+
+ av_freep(&avctx->coded_frame);
+ av_freep(&avctx->extradata);
+
+ return 0;
+}
+
+#define OFFSET(x) offsetof(LibSpeexEncContext, x)
+#define AE AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
+static const AVOption options[] = {
+ { "abr", "Use average bit rate", OFFSET(abr), AV_OPT_TYPE_INT, { 0 }, 0, 1, AE },
+ { "cbr_quality", "Set quality value (0 to 10) for CBR", OFFSET(cbr_quality), AV_OPT_TYPE_INT, { 8 }, 0, 10, AE },
+ { "frames_per_packet", "Number of frames to encode in each packet", OFFSET(frames_per_packet), AV_OPT_TYPE_INT, { 1 }, 1, 8, AE },
+ { NULL },
+};
+
+static const AVClass class = {
+ .class_name = "libspeex",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
+static const AVCodecDefault defaults[] = {
+ { "b", "0" },
+ { "compression_level", "3" },
+ { NULL },
+};
+
+AVCodec ff_libspeex_encoder = {
+ .name = "libspeex",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_SPEEX,
+ .priv_data_size = sizeof(LibSpeexEncContext),
+ .init = encode_init,
+ .encode = encode_frame,
+ .close = encode_close,
+ .capabilities = CODEC_CAP_DELAY,
+ .sample_fmts = (const enum SampleFormat[]){ AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE },
+ .long_name = NULL_IF_CONFIG_SMALL("libspeex Speex"),
+ .priv_class = &class,
+ .defaults = defaults,
+};
diff --git a/libavcodec/libstagefright.cpp b/libavcodec/libstagefright.cpp
new file mode 100644
index 0000000000..e29a377311
--- /dev/null
+++ b/libavcodec/libstagefright.cpp
@@ -0,0 +1,552 @@
+/*
+ * Interface to the Android Stagefright library for
+ * H/W accelerated H.264 decoding
+ *
+ * Copyright (C) 2011 Mohamed Naufal
+ * Copyright (C) 2011 Martin Storsjö
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <binder/ProcessState.h>
+#include <media/stagefright/MetaData.h>
+#include <media/stagefright/MediaBufferGroup.h>
+#include <media/stagefright/MediaDebug.h>
+#include <media/stagefright/MediaDefs.h>
+#include <media/stagefright/OMXClient.h>
+#include <media/stagefright/OMXCodec.h>
+#include <utils/List.h>
+#include <new>
+
+extern "C" {
+#include "avcodec.h"
+#include "libavutil/imgutils.h"
+}
+
+#define OMX_QCOM_COLOR_FormatYVU420SemiPlanar 0x7FA30C00
+
+using namespace android;
+
+struct Frame {
+ status_t status;
+ size_t size;
+ int64_t time;
+ int key;
+ uint8_t *buffer;
+ MediaBuffer* mbuffer;
+ int32_t w, h;
+};
+
+class CustomSource;
+
+struct StagefrightContext {
+ AVCodecContext *avctx;
+ AVBitStreamFilterContext *bsfc;
+ uint8_t* orig_extradata;
+ int orig_extradata_size;
+ sp<MediaSource> *source;
+ List<Frame*> *in_queue, *out_queue;
+ pthread_mutex_t in_mutex, out_mutex;
+ pthread_cond_t condition;
+ pthread_t decode_thread_id;
+
+ Frame *end_frame;
+ bool source_done;
+ volatile sig_atomic_t thread_started, thread_exited, stop_decode;
+
+ AVFrame ret_frame;
+
+ uint8_t *dummy_buf;
+ int dummy_bufsize;
+
+ OMXClient *client;
+ sp<MediaSource> *decoder;
+ const char *decoder_component;
+};
+
+class CustomSource : public MediaSource {
+public:
+ CustomSource(AVCodecContext *avctx, sp<MetaData> meta) {
+ s = (StagefrightContext*)avctx->priv_data;
+ source_meta = meta;
+ frame_size = (avctx->width * avctx->height * 3) / 2;
+ buf_group.add_buffer(new MediaBuffer(frame_size));
+ }
+
+ virtual sp<MetaData> getFormat() {
+ return source_meta;
+ }
+
+ virtual status_t start(MetaData *params) {
+ return OK;
+ }
+
+ virtual status_t stop() {
+ return OK;
+ }
+
+ virtual status_t read(MediaBuffer **buffer,
+ const MediaSource::ReadOptions *options) {
+ Frame *frame;
+ status_t ret;
+
+ if (s->thread_exited)
+ return ERROR_END_OF_STREAM;
+ pthread_mutex_lock(&s->in_mutex);
+
+ while (s->in_queue->empty())
+ pthread_cond_wait(&s->condition, &s->in_mutex);
+
+ frame = *s->in_queue->begin();
+ ret = frame->status;
+
+ if (ret == OK) {
+ ret = buf_group.acquire_buffer(buffer);
+ if (ret == OK) {
+ memcpy((*buffer)->data(), frame->buffer, frame->size);
+ (*buffer)->set_range(0, frame->size);
+ (*buffer)->meta_data()->clear();
+ (*buffer)->meta_data()->setInt32(kKeyIsSyncFrame,frame->key);
+ (*buffer)->meta_data()->setInt64(kKeyTime, frame->time);
+ } else {
+ av_log(s->avctx, AV_LOG_ERROR, "Failed to acquire MediaBuffer\n");
+ }
+ av_freep(&frame->buffer);
+ }
+
+ s->in_queue->erase(s->in_queue->begin());
+ pthread_mutex_unlock(&s->in_mutex);
+
+ av_freep(&frame);
+ return ret;
+ }
+
+private:
+ MediaBufferGroup buf_group;
+ sp<MetaData> source_meta;
+ StagefrightContext *s;
+ int frame_size;
+};
+
+void* decode_thread(void *arg)
+{
+ AVCodecContext *avctx = (AVCodecContext*)arg;
+ StagefrightContext *s = (StagefrightContext*)avctx->priv_data;
+ Frame* frame;
+ MediaBuffer *buffer;
+ int decode_done = 0;
+ do {
+ buffer = NULL;
+ frame = (Frame*)av_mallocz(sizeof(Frame));
+ if (!frame) {
+ frame = s->end_frame;
+ frame->status = AVERROR(ENOMEM);
+ decode_done = 1;
+ s->end_frame = NULL;
+ } else {
+ frame->status = (*s->decoder)->read(&buffer);
+ if (frame->status == OK) {
+ sp<MetaData> outFormat = (*s->decoder)->getFormat();
+ outFormat->findInt32(kKeyWidth , &frame->w);
+ outFormat->findInt32(kKeyHeight, &frame->h);
+ frame->size = buffer->range_length();
+ frame->mbuffer = buffer;
+ } else if (frame->status == INFO_FORMAT_CHANGED) {
+ if (buffer)
+ buffer->release();
+ av_free(frame);
+ continue;
+ } else {
+ decode_done = 1;
+ }
+ }
+ while (true) {
+ pthread_mutex_lock(&s->out_mutex);
+ if (s->out_queue->size() >= 10) {
+ pthread_mutex_unlock(&s->out_mutex);
+ usleep(10000);
+ continue;
+ }
+ break;
+ }
+ s->out_queue->push_back(frame);
+ pthread_mutex_unlock(&s->out_mutex);
+ } while (!decode_done && !s->stop_decode);
+
+ s->thread_exited = true;
+
+ return 0;
+}
+
+static av_cold int Stagefright_init(AVCodecContext *avctx)
+{
+ StagefrightContext *s = (StagefrightContext*)avctx->priv_data;
+ sp<MetaData> meta, outFormat;
+ int32_t colorFormat = 0;
+ int ret;
+
+ if (!avctx->extradata || !avctx->extradata_size || avctx->extradata[0] != 1)
+ return -1;
+
+ s->avctx = avctx;
+ s->bsfc = av_bitstream_filter_init("h264_mp4toannexb");
+ if (!s->bsfc) {
+ av_log(avctx, AV_LOG_ERROR, "Cannot open the h264_mp4toannexb BSF!\n");
+ return -1;
+ }
+
+ s->orig_extradata_size = avctx->extradata_size;
+ s->orig_extradata = (uint8_t*) av_mallocz(avctx->extradata_size +
+ FF_INPUT_BUFFER_PADDING_SIZE);
+ if (!s->orig_extradata) {
+ ret = AVERROR(ENOMEM);
+ goto fail;
+ }
+ memcpy(s->orig_extradata, avctx->extradata, avctx->extradata_size);
+
+ meta = new MetaData;
+ if (meta == NULL) {
+ ret = AVERROR(ENOMEM);
+ goto fail;
+ }
+ meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_AVC);
+ meta->setInt32(kKeyWidth, avctx->width);
+ meta->setInt32(kKeyHeight, avctx->height);
+ meta->setData(kKeyAVCC, kTypeAVCC, avctx->extradata, avctx->extradata_size);
+
+ android::ProcessState::self()->startThreadPool();
+
+ s->source = new sp<MediaSource>();
+ *s->source = new CustomSource(avctx, meta);
+ s->in_queue = new List<Frame*>;
+ s->out_queue = new List<Frame*>;
+ s->client = new OMXClient;
+ s->end_frame = (Frame*)av_mallocz(sizeof(Frame));
+ if (s->source == NULL || !s->in_queue || !s->out_queue || !s->client ||
+ !s->end_frame) {
+ ret = AVERROR(ENOMEM);
+ goto fail;
+ }
+
+ if (s->client->connect() != OK) {
+ av_log(avctx, AV_LOG_ERROR, "Cannot connect OMX client\n");
+ ret = -1;
+ goto fail;
+ }
+
+ s->decoder = new sp<MediaSource>();
+ *s->decoder = OMXCodec::Create(s->client->interface(), meta,
+ false, *s->source, NULL,
+ OMXCodec::kClientNeedsFramebuffer);
+ if ((*s->decoder)->start() != OK) {
+ av_log(avctx, AV_LOG_ERROR, "Cannot start decoder\n");
+ ret = -1;
+ s->client->disconnect();
+ goto fail;
+ }
+
+ outFormat = (*s->decoder)->getFormat();
+ outFormat->findInt32(kKeyColorFormat, &colorFormat);
+ if (colorFormat == OMX_QCOM_COLOR_FormatYVU420SemiPlanar ||
+ colorFormat == OMX_COLOR_FormatYUV420SemiPlanar)
+ avctx->pix_fmt = PIX_FMT_NV21;
+ else
+ avctx->pix_fmt = PIX_FMT_YUV420P;
+
+ outFormat->findCString(kKeyDecoderComponent, &s->decoder_component);
+ if (s->decoder_component)
+ s->decoder_component = av_strdup(s->decoder_component);
+
+ pthread_mutex_init(&s->in_mutex, NULL);
+ pthread_mutex_init(&s->out_mutex, NULL);
+ pthread_cond_init(&s->condition, NULL);
+ return 0;
+
+fail:
+ av_bitstream_filter_close(s->bsfc);
+ av_freep(&s->orig_extradata);
+ av_freep(&s->end_frame);
+ delete s->in_queue;
+ delete s->out_queue;
+ delete s->client;
+ return ret;
+}
+
+static int Stagefright_decode_frame(AVCodecContext *avctx, void *data,
+ int *data_size, AVPacket *avpkt)
+{
+ StagefrightContext *s = (StagefrightContext*)avctx->priv_data;
+ Frame *frame;
+ MediaBuffer *mbuffer;
+ status_t status;
+ size_t size;
+ uint8_t *buf;
+ const uint8_t *src_data[3];
+ int w, h;
+ int src_linesize[3];
+ int orig_size = avpkt->size;
+ AVPacket pkt = *avpkt;
+ int ret;
+
+ if (!s->thread_started) {
+ pthread_create(&s->decode_thread_id, NULL, &decode_thread, avctx);
+ s->thread_started = true;
+ }
+
+ if (avpkt && avpkt->data) {
+ av_bitstream_filter_filter(s->bsfc, avctx, NULL, &pkt.data, &pkt.size,
+ avpkt->data, avpkt->size, avpkt->flags & AV_PKT_FLAG_KEY);
+ avpkt = &pkt;
+ }
+
+ if (!s->source_done) {
+ if(!s->dummy_buf) {
+ s->dummy_buf = (uint8_t*)av_malloc(avpkt->size);
+ if (!s->dummy_buf)
+ return AVERROR(ENOMEM);
+ s->dummy_bufsize = avpkt->size;
+ memcpy(s->dummy_buf, avpkt->data, avpkt->size);
+ }
+
+ frame = (Frame*)av_mallocz(sizeof(Frame));
+ if (avpkt->data) {
+ frame->status = OK;
+ frame->size = avpkt->size;
+ // Stagefright can't handle negative timestamps -
+ // if needed, work around this by offsetting them manually?
+ if (avpkt->pts >= 0)
+ frame->time = avpkt->pts;
+ frame->key = avpkt->flags & AV_PKT_FLAG_KEY ? 1 : 0;
+ frame->buffer = (uint8_t*)av_malloc(avpkt->size);
+ if (!frame->buffer) {
+ av_freep(&frame);
+ return AVERROR(ENOMEM);
+ }
+ uint8_t *ptr = avpkt->data;
+ // The OMX.SEC decoder fails without this.
+ if (avpkt->size == orig_size + avctx->extradata_size) {
+ ptr += avctx->extradata_size;
+ frame->size = orig_size;
+ }
+ memcpy(frame->buffer, ptr, orig_size);
+ } else {
+ frame->status = ERROR_END_OF_STREAM;
+ s->source_done = true;
+ }
+
+ while (true) {
+ if (s->thread_exited) {
+ s->source_done = true;
+ break;
+ }
+ pthread_mutex_lock(&s->in_mutex);
+ if (s->in_queue->size() >= 10) {
+ pthread_mutex_unlock(&s->in_mutex);
+ usleep(10000);
+ continue;
+ }
+ s->in_queue->push_back(frame);
+ pthread_cond_signal(&s->condition);
+ pthread_mutex_unlock(&s->in_mutex);
+ break;
+ }
+ }
+ while (true) {
+ pthread_mutex_lock(&s->out_mutex);
+ if (!s->out_queue->empty()) break;
+ pthread_mutex_unlock(&s->out_mutex);
+ if (s->source_done) {
+ usleep(10000);
+ continue;
+ } else {
+ return orig_size;
+ }
+ }
+
+ frame = *s->out_queue->begin();
+ s->out_queue->erase(s->out_queue->begin());
+ pthread_mutex_unlock(&s->out_mutex);
+
+ mbuffer = frame->mbuffer;
+ status = frame->status;
+ size = frame->size;
+ w = frame->w;
+ h = frame->h;
+ av_freep(&frame);
+
+ if (status == ERROR_END_OF_STREAM)
+ return 0;
+ if (status != OK) {
+ if (status == AVERROR(ENOMEM))
+ return status;
+ av_log(avctx, AV_LOG_ERROR, "Decode failed: %x\n", status);
+ return -1;
+ }
+
+ // The OMX.SEC decoder doesn't signal the modified width/height
+ if (s->decoder_component && !strncmp(s->decoder_component, "OMX.SEC", 7) &&
+ (w & 15 || h & 15)) {
+ if (((w + 15)&~15) * ((h + 15)&~15) * 3/2 == size) {
+ w = (w + 15)&~15;
+ h = (h + 15)&~15;
+ }
+ }
+
+ if (!avctx->width || !avctx->height || avctx->width > w || avctx->height > h) {
+ avctx->width = w;
+ avctx->height = h;
+ }
+
+ ret = avctx->reget_buffer(avctx, &s->ret_frame);
+ if (ret < 0) {
+ av_log(avctx, AV_LOG_ERROR, "reget buffer() failed\n");
+ goto end;
+ }
+
+ src_linesize[0] = w;
+ if (avctx->pix_fmt == PIX_FMT_YUV420P)
+ src_linesize[1] = src_linesize[2] = w/2;
+ else if (avctx->pix_fmt == PIX_FMT_NV21)
+ src_linesize[1] = w;
+
+ buf = (uint8_t*)mbuffer->data();
+ src_data[0] = buf;
+ src_data[1] = buf + src_linesize[0] * h;
+ src_data[2] = src_data[1] + src_linesize[1] * h/2;
+ av_image_copy(s->ret_frame.data, s->ret_frame.linesize,
+ src_data, src_linesize,
+ avctx->pix_fmt, avctx->width, avctx->height);
+
+ *data_size = sizeof(AVFrame);
+ *(AVFrame*)data = s->ret_frame;
+ ret = orig_size;
+end:
+ mbuffer->release();
+ return ret;
+}
+
+static av_cold int Stagefright_close(AVCodecContext *avctx)
+{
+ StagefrightContext *s = (StagefrightContext*)avctx->priv_data;
+ Frame *frame;
+
+ if (s->thread_started) {
+ if (!s->thread_exited) {
+ s->stop_decode = 1;
+
+ // Make sure decode_thread() doesn't get stuck
+ pthread_mutex_lock(&s->out_mutex);
+ while (!s->out_queue->empty()) {
+ frame = *s->out_queue->begin();
+ s->out_queue->erase(s->out_queue->begin());
+ if (frame->size)
+ frame->mbuffer->release();
+ av_freep(&frame);
+ }
+ pthread_mutex_unlock(&s->out_mutex);
+
+ // Feed a dummy frame prior to signalling EOF.
+ // This is required to terminate the decoder(OMX.SEC)
+ // when only one frame is read during stream info detection.
+ if (s->dummy_buf && (frame = (Frame*)av_mallocz(sizeof(Frame)))) {
+ frame->status = OK;
+ frame->size = s->dummy_bufsize;
+ frame->key = 1;
+ frame->buffer = s->dummy_buf;
+ pthread_mutex_lock(&s->in_mutex);
+ s->in_queue->push_back(frame);
+ pthread_cond_signal(&s->condition);
+ pthread_mutex_unlock(&s->in_mutex);
+ s->dummy_buf = NULL;
+ }
+
+ pthread_mutex_lock(&s->in_mutex);
+ s->end_frame->status = ERROR_END_OF_STREAM;
+ s->in_queue->push_back(s->end_frame);
+ pthread_cond_signal(&s->condition);
+ pthread_mutex_unlock(&s->in_mutex);
+ s->end_frame = NULL;
+ }
+
+ pthread_join(s->decode_thread_id, NULL);
+
+ if (s->ret_frame.data[0])
+ avctx->release_buffer(avctx, &s->ret_frame);
+
+ s->thread_started = false;
+ }
+
+ while (!s->in_queue->empty()) {
+ frame = *s->in_queue->begin();
+ s->in_queue->erase(s->in_queue->begin());
+ if (frame->size)
+ av_freep(&frame->buffer);
+ av_freep(&frame);
+ }
+
+ while (!s->out_queue->empty()) {
+ frame = *s->out_queue->begin();
+ s->out_queue->erase(s->out_queue->begin());
+ if (frame->size)
+ frame->mbuffer->release();
+ av_freep(&frame);
+ }
+
+ (*s->decoder)->stop();
+ s->client->disconnect();
+
+ if (s->decoder_component)
+ av_freep(&s->decoder_component);
+ av_freep(&s->dummy_buf);
+ av_freep(&s->end_frame);
+
+ // Reset the extradata back to the original mp4 format, so that
+ // the next invocation (both when decoding and when called from
+ // av_find_stream_info) get the original mp4 format extradata.
+ av_freep(&avctx->extradata);
+ avctx->extradata = s->orig_extradata;
+ avctx->extradata_size = s->orig_extradata_size;
+
+ delete s->in_queue;
+ delete s->out_queue;
+ delete s->client;
+ delete s->decoder;
+ delete s->source;
+
+ pthread_mutex_destroy(&s->in_mutex);
+ pthread_mutex_destroy(&s->out_mutex);
+ pthread_cond_destroy(&s->condition);
+ av_bitstream_filter_close(s->bsfc);
+ return 0;
+}
+
+AVCodec ff_libstagefright_h264_decoder = {
+ "libstagefright_h264",
+ AVMEDIA_TYPE_VIDEO,
+ CODEC_ID_H264,
+ sizeof(StagefrightContext),
+ Stagefright_init,
+ NULL, //encode
+ Stagefright_close,
+ Stagefright_decode_frame,
+ CODEC_CAP_DELAY,
+ NULL, //next
+ NULL, //flush
+ NULL, //supported_framerates
+ NULL, //pixel_formats
+ NULL_IF_CONFIG_SMALL("libstagefright H.264"),
+};
diff --git a/libavcodec/libtheoraenc.c b/libavcodec/libtheoraenc.c
index 86cc09ffa6..87793adc72 100644
--- a/libavcodec/libtheoraenc.c
+++ b/libavcodec/libtheoraenc.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2006 Paul Richards <paul.richards@gmail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -30,7 +30,7 @@
* and o_ prefixes on variables which are libogg types.
*/
-/* Libav includes */
+/* FFmpeg includes */
#include "libavutil/intreadwrite.h"
#include "libavutil/log.h"
#include "libavutil/base64.h"
diff --git a/libavcodec/libutvideo.cpp b/libavcodec/libutvideo.cpp
new file mode 100644
index 0000000000..27f22e8570
--- /dev/null
+++ b/libavcodec/libutvideo.cpp
@@ -0,0 +1,230 @@
+/*
+ * Copyright (c) 2011 Derek Buitenhuis
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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;
+ * version 2 of the License.
+ *
+ * FFmpeg 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 FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * Known FOURCCs:
+ * 'ULY0' (YCbCr 4:2:0), 'ULY2' (YCbCr 4:2:2), 'ULRG' (RGB), 'ULRA' (RGBA)
+ */
+
+extern "C" {
+#include "avcodec.h"
+}
+
+#include <stdlib.h>
+#include <utvideo/utvideo.h>
+#include <utvideo/Codec.h>
+
+#include "get_bits.h"
+
+typedef struct {
+ uint32_t version;
+ uint32_t original_format;
+ uint32_t stripes;
+ uint32_t flags;
+} UtVideoExtra;
+
+typedef struct {
+ CCodec *codec;
+ unsigned int buf_size;
+ uint8_t *output;
+} UtVideoContext;
+
+static av_cold int utvideo_decode_init(AVCodecContext *avctx)
+{
+ UtVideoContext *utv = (UtVideoContext *)avctx->priv_data;
+ UtVideoExtra info;
+ int defined_fourcc = 0;
+
+ if(avctx->extradata_size != 4*4)
+ {
+ av_log(avctx, AV_LOG_ERROR, "Extradata size mismatch.\n");
+ return -1;
+ }
+
+ /* Read extradata */
+ info.version = AV_RL32(avctx->extradata);
+ info.original_format = AV_RL32(avctx->extradata + 4);
+ info.stripes = AV_RL32(avctx->extradata + 8);
+ info.flags = AV_RL32(avctx->extradata + 12);
+
+ /* Try to output the original format */
+ switch(UNFCC(info.original_format))
+ {
+ case UTVF_YV12:
+ avctx->pix_fmt = PIX_FMT_YUV420P;
+ break;
+ case UTVF_YUY2:
+ case UTVF_YUYV:
+ case UTVF_YUNV:
+ avctx->pix_fmt = PIX_FMT_YUYV422;
+ break;
+ case UTVF_UYVY:
+ case UTVF_UYNV:
+ avctx->pix_fmt = PIX_FMT_UYVY422;
+ break;
+ case UTVF_RGB24_WIN:
+ avctx->pix_fmt = PIX_FMT_BGR24;
+ break;
+ case UTVF_RGB32_WIN:
+ avctx->pix_fmt = PIX_FMT_RGB32;
+ break;
+ case UTVF_ARGB32_WIN:
+ avctx->pix_fmt = PIX_FMT_ARGB;
+ break;
+ case 0:
+ /* Fall back on FOURCC */
+ switch(UNFCC(avctx->codec_tag))
+ {
+ case UTVF_ULY0:
+ avctx->pix_fmt = PIX_FMT_YUV420P;
+ defined_fourcc = UTVF_YV12;
+ break;
+ case UTVF_ULY2:
+ avctx->pix_fmt = PIX_FMT_YUYV422;
+ defined_fourcc = UTVF_YUY2;
+ break;
+ case UTVF_ULRG:
+ avctx->pix_fmt = PIX_FMT_BGR24;
+ defined_fourcc = UTVF_RGB24_WIN;
+ break;
+ case UTVF_ULRA:
+ avctx->pix_fmt = PIX_FMT_RGB32;
+ defined_fourcc = UTVF_RGB32_WIN;
+ break;
+ }
+ break;
+ default:
+ av_log(avctx, AV_LOG_ERROR,
+ "Codec ExtraData is Corrupt or Invalid: %X\n", info.original_format);
+ return -1;
+ }
+
+ /* Only allocate the buffer once */
+ utv->buf_size = avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height);
+ utv->output = (uint8_t *)av_malloc(utv->buf_size * sizeof(uint8_t));
+
+ if(utv->output == NULL)
+ {
+ av_log(avctx, AV_LOG_ERROR, "Unable to allocate output buffer.\n");
+ return -1;
+ }
+
+ /* Allocate the output frame */
+ avctx->coded_frame = avcodec_alloc_frame();
+
+ /* Ut Video only supports 8-bit */
+ avctx->bits_per_raw_sample = 8;
+
+ /* Is it interlaced? */
+ avctx->coded_frame->interlaced_frame = info.flags & 0x800 ? 1 : 0;
+
+ /* Apparently Ut Video doesn't store this info... */
+ avctx->coded_frame->top_field_first = 1;
+
+ /*
+ * Create a Ut Video instance. Since the function wants
+ * an "interface name" string, pass it the name of the lib.
+ */
+ utv->codec = CCodec::CreateInstance(UNFCC(avctx->codec_tag), "libavcodec");
+
+ /* Initialize Decoding */
+ utv->codec->DecodeBegin(defined_fourcc ? defined_fourcc : UNFCC(info.original_format),
+ avctx->width, avctx->height, CBGROSSWIDTH_WINDOWS, &info,
+ sizeof(UtVideoExtra));
+
+ return 0;
+}
+
+static int utvideo_decode_frame(AVCodecContext *avctx, void *data,
+ int *data_size, AVPacket *avpkt)
+{
+ UtVideoContext *utv = (UtVideoContext *)avctx->priv_data;
+ AVFrame *pic = avctx->coded_frame;
+ unsigned int w = avctx->width, h = avctx->height;
+
+ /* Set flags */
+ pic->reference = 0;
+ pic->pict_type = AV_PICTURE_TYPE_I;
+ pic->key_frame = 1;
+
+ /* Decode the frame */
+ utv->codec->DecodeFrame(utv->output, avpkt->data, true);
+
+ /* Set the output data depending on the colorspace */
+ switch(avctx->pix_fmt)
+ {
+ case PIX_FMT_YUV420P:
+ pic->linesize[0] = w;
+ pic->linesize[1] = pic->linesize[2] = w / 2;
+ pic->data[0] = utv->output;
+ pic->data[2] = utv->output + (w * h);
+ pic->data[1] = pic->data[2] + (w * h / 4);
+ break;
+ case PIX_FMT_YUYV422:
+ case PIX_FMT_UYVY422:
+ pic->linesize[0] = w * 2;
+ pic->data[0] = utv->output;
+ break;
+ case PIX_FMT_BGR24:
+ case PIX_FMT_RGB32:
+ /* Make the linesize negative, since Ut Video uses bottom-up BGR */
+ pic->linesize[0] = -1 * w * (avctx->pix_fmt == PIX_FMT_BGR24 ? 3 : 4);
+ pic->data[0] = utv->output + utv->buf_size + pic->linesize[0];
+ break;
+ }
+
+ *data_size = sizeof(AVFrame);
+ *(AVFrame *)data = *pic;
+
+ return avpkt->size;
+}
+
+static av_cold int utvideo_decode_close(AVCodecContext *avctx)
+{
+ UtVideoContext *utv = (UtVideoContext *)avctx->priv_data;
+
+ /* Free output */
+ av_freep(&avctx->coded_frame);
+ av_freep(&utv->output);
+
+ /* Finish decoding and clean up the instance */
+ utv->codec->DecodeEnd();
+ CCodec::DeleteInstance(utv->codec);
+
+ return 0;
+}
+
+AVCodec ff_libutvideo_decoder = {
+ "utvideo",
+ AVMEDIA_TYPE_VIDEO,
+ CODEC_ID_UTVIDEO,
+ sizeof(UtVideoContext),
+ utvideo_decode_init,
+ NULL,
+ utvideo_decode_close,
+ utvideo_decode_frame,
+ CODEC_CAP_LOSSLESS,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL_IF_CONFIG_SMALL("Ut Video"),
+};
diff --git a/libavcodec/libvo-aacenc.c b/libavcodec/libvo-aacenc.c
index 5a75bcbbb4..dcec664347 100644
--- a/libavcodec/libvo-aacenc.c
+++ b/libavcodec/libvo-aacenc.c
@@ -2,20 +2,20 @@
* AAC encoder wrapper
* Copyright (c) 2010 Martin Storsjo
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -63,7 +63,7 @@ static av_cold int aac_encode_init(AVCodecContext *avctx)
}
for (index = 0; index < 16; index++)
- if (avctx->sample_rate == ff_mpeg4audio_sample_rates[index])
+ if (avctx->sample_rate == avpriv_mpeg4audio_sample_rates[index])
break;
if (index == 16) {
av_log(avctx, AV_LOG_ERROR, "Unsupported sample rate %d\n",
@@ -116,14 +116,13 @@ static int aac_encode_frame(AVCodecContext *avctx,
}
AVCodec ff_libvo_aacenc_encoder = {
- "libvo_aacenc",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_AAC,
- sizeof(AACContext),
- aac_encode_init,
- aac_encode_frame,
- aac_encode_close,
- NULL,
+ .name = "libvo_aacenc",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_AAC,
+ .priv_data_size = sizeof(AACContext),
+ .init = aac_encode_init,
+ .encode = aac_encode_frame,
+ .close = aac_encode_close,
.sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
.long_name = NULL_IF_CONFIG_SMALL("Android VisualOn AAC"),
};
diff --git a/libavcodec/libvo-amrwbenc.c b/libavcodec/libvo-amrwbenc.c
index b3615ede42..b32fe4e1df 100644
--- a/libavcodec/libvo-amrwbenc.c
+++ b/libavcodec/libvo-amrwbenc.c
@@ -2,20 +2,20 @@
* AMR Audio encoder stub
* Copyright (c) 2003 the ffmpeg project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -34,7 +34,7 @@ typedef struct AMRWBContext {
} AMRWBContext;
static const AVOption options[] = {
- { "dtx", "Allow DTX (generate comfort noise)", offsetof(AMRWBContext, allow_dtx), FF_OPT_TYPE_INT, 0, 0, 1, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
+ { "dtx", "Allow DTX (generate comfort noise)", offsetof(AMRWBContext, allow_dtx), AV_OPT_TYPE_INT, { 0 }, 0, 1, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
{ NULL }
};
@@ -118,14 +118,13 @@ static int amr_wb_encode_frame(AVCodecContext *avctx,
}
AVCodec ff_libvo_amrwbenc_encoder = {
- "libvo_amrwbenc",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_AMR_WB,
- sizeof(AMRWBContext),
- amr_wb_encode_init,
- amr_wb_encode_frame,
- amr_wb_encode_close,
- NULL,
+ .name = "libvo_amrwbenc",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_AMR_WB,
+ .priv_data_size = sizeof(AMRWBContext),
+ .init = amr_wb_encode_init,
+ .encode = amr_wb_encode_frame,
+ .close = amr_wb_encode_close,
.sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
.long_name = NULL_IF_CONFIG_SMALL("Android VisualOn Adaptive Multi-Rate "
"(AMR) Wide-Band"),
diff --git a/libavcodec/libvorbis.c b/libavcodec/libvorbis.c
index 85cb9c5989..53993e3719 100644
--- a/libavcodec/libvorbis.c
+++ b/libavcodec/libvorbis.c
@@ -1,20 +1,20 @@
/*
* copyright (c) 2002 Mark Hills <mark@pogo.org.uk>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -56,7 +56,7 @@ typedef struct OggVorbisContext {
} OggVorbisContext ;
static const AVOption options[]={
-{"iblock", "Sets the impulse block bias", offsetof(OggVorbisContext, iblock), FF_OPT_TYPE_DOUBLE, {.dbl = 0}, -15, 0, AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_ENCODING_PARAM},
+{"iblock", "Sets the impulse block bias", offsetof(OggVorbisContext, iblock), AV_OPT_TYPE_DOUBLE, {.dbl = 0}, -15, 0, AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_ENCODING_PARAM},
{NULL}
};
static const AVClass class = { "libvorbis", av_default_item_name, options, LIBAVUTIL_VERSION_INT };
@@ -97,6 +97,35 @@ static av_cold int oggvorbis_init_encoder(vorbis_info *vi, AVCodecContext *avcco
vorbis_encode_ctl(vi, OV_ECTL_IBLOCK_SET, &context->iblock);
}
+ if (avccontext->channels == 3 &&
+ avccontext->channel_layout != (AV_CH_LAYOUT_STEREO|AV_CH_FRONT_CENTER) ||
+ avccontext->channels == 4 &&
+ avccontext->channel_layout != AV_CH_LAYOUT_2_2 &&
+ avccontext->channel_layout != AV_CH_LAYOUT_QUAD ||
+ avccontext->channels == 5 &&
+ avccontext->channel_layout != AV_CH_LAYOUT_5POINT0 &&
+ avccontext->channel_layout != AV_CH_LAYOUT_5POINT0_BACK ||
+ avccontext->channels == 6 &&
+ avccontext->channel_layout != AV_CH_LAYOUT_5POINT1 &&
+ avccontext->channel_layout != AV_CH_LAYOUT_5POINT1_BACK ||
+ avccontext->channels == 7 &&
+ avccontext->channel_layout != (AV_CH_LAYOUT_5POINT1|AV_CH_BACK_CENTER) ||
+ avccontext->channels == 8 &&
+ avccontext->channel_layout != AV_CH_LAYOUT_7POINT1) {
+ if (avccontext->channel_layout) {
+ char name[32];
+ av_get_channel_layout_string(name, sizeof(name), avccontext->channels,
+ avccontext->channel_layout);
+ av_log(avccontext, AV_LOG_ERROR, "%s not supported by Vorbis: "
+ "output stream will have incorrect "
+ "channel layout.\n", name);
+ } else {
+ av_log(avccontext, AV_LOG_WARNING, "No channel layout specified. The encoder "
+ "will use Vorbis channel layout for "
+ "%d channels.\n", avccontext->channels);
+ }
+ }
+
return vorbis_encode_setup_init(vi);
}
@@ -245,15 +274,15 @@ static av_cold int oggvorbis_encode_close(AVCodecContext *avccontext) {
AVCodec ff_libvorbis_encoder = {
- "libvorbis",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_VORBIS,
- sizeof(OggVorbisContext),
- oggvorbis_encode_init,
- oggvorbis_encode_frame,
- oggvorbis_encode_close,
- .capabilities= CODEC_CAP_DELAY,
- .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
- .long_name= NULL_IF_CONFIG_SMALL("libvorbis Vorbis"),
- .priv_class= &class,
-} ;
+ .name = "libvorbis",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_VORBIS,
+ .priv_data_size = sizeof(OggVorbisContext),
+ .init = oggvorbis_encode_init,
+ .encode = oggvorbis_encode_frame,
+ .close = oggvorbis_encode_close,
+ .capabilities = CODEC_CAP_DELAY,
+ .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
+ .long_name = NULL_IF_CONFIG_SMALL("libvorbis Vorbis"),
+ .priv_class = &class,
+};
diff --git a/libavcodec/libvpxdec.c b/libavcodec/libvpxdec.c
index 2aa077c07a..15329f3f31 100644
--- a/libavcodec/libvpxdec.c
+++ b/libavcodec/libvpxdec.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2010, Google, Inc.
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -112,14 +112,12 @@ static av_cold int vp8_free(AVCodecContext *avctx)
}
AVCodec ff_libvpx_decoder = {
- "libvpx",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_VP8,
- sizeof(VP8Context),
- vp8_init,
- NULL, /* encode */
- vp8_free,
- vp8_decode,
- 0, /* capabilities */
+ .name = "libvpx",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_VP8,
+ .priv_data_size = sizeof(VP8Context),
+ .init = vp8_init,
+ .close = vp8_free,
+ .decode = vp8_decode,
.long_name = NULL_IF_CONFIG_SMALL("libvpx VP8"),
};
diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index ca2e6157d5..1a922837e1 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2010, Google, Inc.
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -29,8 +29,10 @@
#include <vpx/vp8cx.h>
#include "avcodec.h"
+#include "internal.h"
#include "libavutil/base64.h"
#include "libavutil/mathematics.h"
+#include "libavutil/opt.h"
/**
* Portion of struct vpx_codec_cx_pkt from vpx_encoder.h.
@@ -48,11 +50,23 @@ struct FrameListData {
};
typedef struct VP8EncoderContext {
+ AVClass *class;
struct vpx_codec_ctx encoder;
struct vpx_image rawimg;
struct vpx_fixed_buf twopass_stats;
- unsigned long deadline; //i.e., RT/GOOD/BEST
+ int deadline; //i.e., RT/GOOD/BEST
struct FrameListData *coded_frame_list;
+
+ int cpu_used;
+ int auto_alt_ref;
+
+ int arnr_max_frames;
+ int arnr_strength;
+ int arnr_type;
+
+ int lag_in_frames;
+ int error_resilient;
+ int crf;
} VP8Context;
/** String mappings for enum vp8e_enc_control_id */
@@ -73,6 +87,7 @@ static const char *ctlidstr[] = {
[VP8E_SET_ARNR_MAXFRAMES] = "VP8E_SET_ARNR_MAXFRAMES",
[VP8E_SET_ARNR_STRENGTH] = "VP8E_SET_ARNR_STRENGTH",
[VP8E_SET_ARNR_TYPE] = "VP8E_SET_ARNR_TYPE",
+ [VP8E_SET_CQ_LEVEL] = "VP8E_SET_CQ_LEVEL",
};
static av_cold void log_encoder_error(AVCodecContext *avctx, const char *desc)
@@ -205,7 +220,6 @@ static av_cold int vp8_init(AVCodecContext *avctx)
{
VP8Context *ctx = avctx->priv_data;
const struct vpx_codec_iface *iface = &vpx_codec_vp8_cx_algo;
- int cpuused = 3;
struct vpx_codec_enc_cfg enccfg;
int res;
@@ -224,6 +238,13 @@ static av_cold int vp8_init(AVCodecContext *avctx)
enccfg.g_timebase.num = avctx->time_base.num;
enccfg.g_timebase.den = avctx->time_base.den;
enccfg.g_threads = avctx->thread_count;
+#if FF_API_X264_GLOBAL_OPTS
+ enccfg.g_lag_in_frames= FFMIN(avctx->rc_lookahead, 25); //0-25, avoids init failure
+ if (ctx->lag_in_frames >= 0)
+ enccfg.g_lag_in_frames = ctx->lag_in_frames;
+#else
+ enccfg.g_lag_in_frames= ctx->lag_in_frames;
+#endif
if (avctx->flags & CODEC_FLAG_PASS1)
enccfg.g_pass = VPX_RC_FIRST_PASS;
@@ -235,11 +256,18 @@ static av_cold int vp8_init(AVCodecContext *avctx)
if (avctx->rc_min_rate == avctx->rc_max_rate &&
avctx->rc_min_rate == avctx->bit_rate)
enccfg.rc_end_usage = VPX_CBR;
+#if FF_API_X264_GLOBAL_OPTS
+ else if (avctx->crf || ctx->crf > 0)
+#else
+ else if (ctx->crf)
+#endif
+ enccfg.rc_end_usage = VPX_CQ;
enccfg.rc_target_bitrate = av_rescale_rnd(avctx->bit_rate, 1, 1000,
AV_ROUND_NEAR_INF);
-
- enccfg.rc_min_quantizer = avctx->qmin;
- enccfg.rc_max_quantizer = avctx->qmax;
+ if (avctx->qmin > 0)
+ enccfg.rc_min_quantizer = avctx->qmin;
+ if (avctx->qmax > 0)
+ enccfg.rc_max_quantizer = avctx->qmax;
enccfg.rc_dropframe_thresh = avctx->frame_skip_threshold;
//0-100 (0 => CBR, 100 => VBR)
@@ -257,11 +285,13 @@ static av_cold int vp8_init(AVCodecContext *avctx)
enccfg.rc_buf_initial_sz =
avctx->rc_initial_buffer_occupancy * 1000LL / avctx->bit_rate;
enccfg.rc_buf_optimal_sz = enccfg.rc_buf_sz * 5 / 6;
+ enccfg.rc_undershoot_pct = round(avctx->rc_buffer_aggressivity * 100);
//_enc_init() will balk if kf_min_dist differs from max w/VPX_KF_AUTO
- if (avctx->keyint_min == avctx->gop_size)
+ if (avctx->keyint_min >= 0 && avctx->keyint_min == avctx->gop_size)
enccfg.kf_min_dist = avctx->keyint_min;
- enccfg.kf_max_dist = avctx->gop_size;
+ if (avctx->gop_size >= 0)
+ enccfg.kf_max_dist = avctx->gop_size;
if (enccfg.g_pass == VPX_RC_FIRST_PASS)
enccfg.g_lag_in_frames = 0;
@@ -292,13 +322,14 @@ static av_cold int vp8_init(AVCodecContext *avctx)
enccfg.rc_twopass_stats_in = ctx->twopass_stats;
}
- ctx->deadline = VPX_DL_GOOD_QUALITY;
/* 0-3: For non-zero values the encoder increasingly optimizes for reduced
complexity playback on low powered devices at the expense of encode
quality. */
if (avctx->profile != FF_PROFILE_UNKNOWN)
enccfg.g_profile = avctx->profile;
+ enccfg.g_error_resilient = ctx->error_resilient;
+
dump_enc_cfg(avctx, &enccfg);
/* Construct Encoder Context */
res = vpx_codec_enc_init(&ctx->encoder, iface, &enccfg, 0);
@@ -309,10 +340,28 @@ static av_cold int vp8_init(AVCodecContext *avctx)
//codec control failures are currently treated only as warnings
av_log(avctx, AV_LOG_DEBUG, "vpx_codec_control\n");
- codecctl_int(avctx, VP8E_SET_CPUUSED, cpuused);
+ if (ctx->cpu_used != INT_MIN)
+ codecctl_int(avctx, VP8E_SET_CPUUSED, ctx->cpu_used);
+ if (ctx->auto_alt_ref >= 0)
+ codecctl_int(avctx, VP8E_SET_ENABLEAUTOALTREF, ctx->auto_alt_ref);
+ if (ctx->arnr_max_frames >= 0)
+ codecctl_int(avctx, VP8E_SET_ARNR_MAXFRAMES, ctx->arnr_max_frames);
+ if (ctx->arnr_strength >= 0)
+ codecctl_int(avctx, VP8E_SET_ARNR_STRENGTH, ctx->arnr_strength);
+ if (ctx->arnr_type >= 0)
+ codecctl_int(avctx, VP8E_SET_ARNR_TYPE, ctx->arnr_type);
codecctl_int(avctx, VP8E_SET_NOISE_SENSITIVITY, avctx->noise_reduction);
codecctl_int(avctx, VP8E_SET_TOKEN_PARTITIONS, av_log2(avctx->slices));
codecctl_int(avctx, VP8E_SET_STATIC_THRESHOLD, avctx->mb_threshold);
+#if FF_API_X264_GLOBAL_OPTS
+ codecctl_int(avctx, VP8E_SET_CQ_LEVEL, (int)avctx->crf);
+ if (ctx->crf >= 0)
+ codecctl_int(avctx, VP8E_SET_CQ_LEVEL, ctx->crf);
+#else
+ codecctl_int(avctx, VP8E_SET_CQ_LEVEL, ctx->crf);
+#endif
+
+ av_log(avctx, AV_LOG_DEBUG, "Using deadline: %d\n", ctx->deadline);
//provide dummy value to initialize wrapper, values will be updated each _encode()
vpx_img_wrap(&ctx->rawimg, VPX_IMG_FMT_I420, avctx->width, avctx->height, 1,
@@ -432,8 +481,8 @@ static int queue_frames(AVCodecContext *avctx, uint8_t *buf, int buf_size,
break;
case VPX_CODEC_STATS_PKT: {
struct vpx_fixed_buf *stats = &ctx->twopass_stats;
- stats->buf = av_realloc(stats->buf,
- stats->sz + pkt->data.twopass_stats.sz);
+ stats->buf = av_realloc_f(stats->buf, 1,
+ stats->sz + pkt->data.twopass_stats.sz);
if (!stats->buf) {
av_log(avctx, AV_LOG_ERROR, "Stat buffer realloc failed\n");
return AVERROR(ENOMEM);
@@ -496,16 +545,76 @@ static int vp8_encode(AVCodecContext *avctx, uint8_t *buf, int buf_size,
return coded_size;
}
+#define OFFSET(x) offsetof(VP8Context, x)
+#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
+static const AVOption options[] = {
+ { "cpu-used", "Quality/Speed ratio modifier", OFFSET(cpu_used), AV_OPT_TYPE_INT, {INT_MIN}, INT_MIN, INT_MAX, VE},
+ { "auto-alt-ref", "Enable use of alternate reference "
+ "frames (2-pass only)", OFFSET(auto_alt_ref), AV_OPT_TYPE_INT, {-1}, -1, 1, VE},
+ { "lag-in-frames", "Number of frames to look ahead for "
+ "alternate reference frame selection", OFFSET(lag_in_frames), AV_OPT_TYPE_INT, {-1}, -1, INT_MAX, VE},
+ { "arnr-maxframes", "altref noise reduction max frame count", OFFSET(arnr_max_frames), AV_OPT_TYPE_INT, {-1}, -1, INT_MAX, VE},
+ { "arnr-strength", "altref noise reduction filter strength", OFFSET(arnr_strength), AV_OPT_TYPE_INT, {-1}, -1, INT_MAX, VE},
+ { "arnr-type", "altref noise reduction filter type", OFFSET(arnr_type), AV_OPT_TYPE_INT, {-1}, -1, INT_MAX, VE, "arnr_type"},
+ { "backward", NULL, 0, AV_OPT_TYPE_CONST, {1}, 0, 0, VE, "arnr_type" },
+ { "forward", NULL, 0, AV_OPT_TYPE_CONST, {2}, 0, 0, VE, "arnr_type" },
+ { "centered", NULL, 0, AV_OPT_TYPE_CONST, {3}, 0, 0, VE, "arnr_type" },
+ { "deadline", "Time to spend encoding, in microseconds.", OFFSET(deadline), AV_OPT_TYPE_INT, {VPX_DL_GOOD_QUALITY}, INT_MIN, INT_MAX, VE, "quality"},
+ { "best", NULL, 0, AV_OPT_TYPE_CONST, {VPX_DL_BEST_QUALITY}, 0, 0, VE, "quality"},
+ { "good", NULL, 0, AV_OPT_TYPE_CONST, {VPX_DL_GOOD_QUALITY}, 0, 0, VE, "quality"},
+ { "realtime", NULL, 0, AV_OPT_TYPE_CONST, {VPX_DL_REALTIME}, 0, 0, VE, "quality"},
+ { "error-resilient", "Error resilience configuration", OFFSET(error_resilient), AV_OPT_TYPE_FLAGS, {0}, INT_MIN, INT_MAX, VE, "er"},
+#ifdef VPX_ERROR_RESILIENT_DEFAULT
+ { "default", "Improve resiliency against losses of whole frames", 0, AV_OPT_TYPE_CONST, {VPX_ERROR_RESILIENT_DEFAULT}, 0, 0, VE, "er"},
+ { "partitions", "The frame partitions are independently decodable "
+ "by the bool decoder, meaning that partitions can be decoded even "
+ "though earlier partitions have been lost. Note that intra predicition"
+ " is still done over the partition boundary.", 0, AV_OPT_TYPE_CONST, {VPX_ERROR_RESILIENT_PARTITIONS}, 0, 0, VE, "er"},
+#endif
+{"speed", "", offsetof(VP8Context, cpu_used), AV_OPT_TYPE_INT, {.dbl = 3}, -16, 16, VE},
+{"quality", "", offsetof(VP8Context, deadline), AV_OPT_TYPE_INT, {.dbl = VPX_DL_GOOD_QUALITY}, INT_MIN, INT_MAX, VE, "quality"},
+{"best", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = VPX_DL_BEST_QUALITY}, INT_MIN, INT_MAX, VE, "quality"},
+{"good", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = VPX_DL_GOOD_QUALITY}, INT_MIN, INT_MAX, VE, "quality"},
+{"realtime", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = VPX_DL_REALTIME}, INT_MIN, INT_MAX, VE, "quality"},
+{"arnr_max_frames", "altref noise reduction max frame count", offsetof(VP8Context, arnr_max_frames), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 15, VE},
+{"arnr_strength", "altref noise reduction filter strength", offsetof(VP8Context, arnr_strength), AV_OPT_TYPE_INT, {.dbl = 3}, 0, 6, VE},
+{"arnr_type", "altref noise reduction filter type", offsetof(VP8Context, arnr_type), AV_OPT_TYPE_INT, {.dbl = 3}, 1, 3, VE},
+#if FF_API_X264_GLOBAL_OPTS
+{"rc_lookahead", "Number of frames to look ahead for alternate reference frame selection", offsetof(VP8Context, lag_in_frames), AV_OPT_TYPE_INT, {.dbl = -1}, -1, 25, VE},
+{"crf", "Select the quality for constant quality mode", offsetof(VP8Context, crf), AV_OPT_TYPE_INT, {.dbl = -1}, -1, 63, VE},
+#else
+{"rc_lookahead", "Number of frames to look ahead for alternate reference frame selection", offsetof(VP8Context, lag_in_frames), AV_OPT_TYPE_INT, {.dbl = 25}, 0, 25, VE},
+{"crf", "Select the quality for constant quality mode", offsetof(VP8Context, crf), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 63, VE},
+#endif
+{NULL}
+};
+
+static const AVClass class = {
+ .class_name = "libvpx encoder",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
+static const AVCodecDefault defaults[] = {
+ { "qmin", "-1" },
+ { "qmax", "-1" },
+ { "g", "-1" },
+ { "keyint_min", "-1" },
+ { NULL },
+};
+
AVCodec ff_libvpx_encoder = {
- "libvpx",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_VP8,
- sizeof(VP8Context),
- vp8_init,
- vp8_encode,
- vp8_free,
- NULL,
- CODEC_CAP_DELAY,
+ .name = "libvpx",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_VP8,
+ .priv_data_size = sizeof(VP8Context),
+ .init = vp8_init,
+ .encode = vp8_encode,
+ .close = vp8_free,
+ .capabilities = CODEC_CAP_DELAY,
.pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
.long_name = NULL_IF_CONFIG_SMALL("libvpx VP8"),
+ .priv_class = &class,
+ .defaults = defaults,
};
diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index e5fac00469..7410112172 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -2,37 +2,74 @@
* H.264 encoding using the x264 library
* Copyright (C) 2005 Mans Rullgard <mans@mansr.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include "libavutil/opt.h"
+#include "libavutil/pixdesc.h"
#include "avcodec.h"
+#include "internal.h"
#include <x264.h>
+#include <float.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct X264Context {
+ AVClass *class;
x264_param_t params;
x264_t *enc;
x264_picture_t pic;
uint8_t *sei;
int sei_size;
AVFrame out_pic;
+ char *preset;
+ char *tune;
+ char *profile;
+ char *level;
+ int fastfirstpass;
+ char *stats;
+ char *wpredp;
+ char *x264opts;
+ float crf;
+ float crf_max;
+ int cqp;
+ int aq_mode;
+ float aq_strength;
+ char *psy_rd;
+ int psy;
+ int rc_lookahead;
+ int weightp;
+ int weightb;
+ int ssim;
+ int intra_refresh;
+ int b_bias;
+ int b_pyramid;
+ int mixed_refs;
+ int dct8x8;
+ int fast_pskip;
+ int aud;
+ int mbtree;
+ char *deblock;
+ float cplxblur;
+ char *partitions;
+ int direct_pred;
+ int slice_max_size;
} X264Context;
static void X264_log(void *p, int level, const char *fmt, va_list args)
@@ -60,9 +97,14 @@ static int encode_nals(AVCodecContext *ctx, uint8_t *buf, int size,
/* Write the SEI as part of the first frame. */
if (x4->sei_size > 0 && nnal > 0) {
+ if (x4->sei_size > size) {
+ av_log(ctx, AV_LOG_ERROR, "Error: nal buffer is too small\n");
+ return -1;
+ }
memcpy(p, x4->sei, x4->sei_size);
p += x4->sei_size;
x4->sei_size = 0;
+ av_freep(&x4->sei);
}
for (i = 0; i < nnal; i++){
@@ -73,6 +115,11 @@ static int encode_nals(AVCodecContext *ctx, uint8_t *buf, int size,
memcpy(x4->sei, nals[i].p_payload, nals[i].i_payload);
continue;
}
+ if (nals[i].i_payload > (size - (p - buf))) {
+ // return only complete nals which fit in buf
+ av_log(ctx, AV_LOG_ERROR, "Error: nal buffer is too small\n");
+ break;
+ }
memcpy(p, nals[i].p_payload, nals[i].i_payload);
p += nals[i].i_payload;
}
@@ -80,21 +127,43 @@ static int encode_nals(AVCodecContext *ctx, uint8_t *buf, int size,
return p - buf;
}
+static int avfmt2_num_planes(int avfmt)
+{
+ switch (avfmt) {
+ case PIX_FMT_YUV420P:
+ case PIX_FMT_YUVJ420P:
+ case PIX_FMT_YUV420P9:
+ case PIX_FMT_YUV420P10:
+ case PIX_FMT_YUV444P:
+ return 3;
+
+ case PIX_FMT_BGR24:
+ case PIX_FMT_RGB24:
+ return 1;
+
+ default:
+ return 3;
+ }
+}
+
static int X264_frame(AVCodecContext *ctx, uint8_t *buf,
- int bufsize, void *data)
+ int orig_bufsize, void *data)
{
X264Context *x4 = ctx->priv_data;
AVFrame *frame = data;
x264_nal_t *nal;
int nnal, i;
x264_picture_t pic_out;
+ int bufsize;
x264_picture_init( &x4->pic );
- x4->pic.img.i_csp = X264_CSP_I420;
- x4->pic.img.i_plane = 3;
+ x4->pic.img.i_csp = x4->params.i_csp;
+ if (x264_bit_depth > 8)
+ x4->pic.img.i_csp |= X264_CSP_HIGH_DEPTH;
+ x4->pic.img.i_plane = avfmt2_num_planes(ctx->pix_fmt);
if (frame) {
- for (i = 0; i < 3; i++) {
+ for (i = 0; i < x4->pic.img.i_plane; i++) {
x4->pic.img.plane[i] = frame->data[i];
x4->pic.img.i_stride[i] = frame->linesize[i];
}
@@ -109,9 +178,16 @@ static int X264_frame(AVCodecContext *ctx, uint8_t *buf,
x4->params.b_tff = frame->top_field_first;
x264_encoder_reconfig(x4->enc, &x4->params);
}
+ if (x4->params.vui.i_sar_height != ctx->sample_aspect_ratio.den
+ || x4->params.vui.i_sar_width != ctx->sample_aspect_ratio.num) {
+ x4->params.vui.i_sar_height = ctx->sample_aspect_ratio.den;
+ x4->params.vui.i_sar_width = ctx->sample_aspect_ratio.num;
+ x264_encoder_reconfig(x4->enc, &x4->params);
+ }
}
do {
+ bufsize = orig_bufsize;
if (x264_encoder_encode(x4->enc, &nal, &nnal, frame? &x4->pic: NULL, &pic_out) < 0)
return -1;
@@ -138,7 +214,8 @@ static int X264_frame(AVCodecContext *ctx, uint8_t *buf,
}
x4->out_pic.key_frame = pic_out.b_keyframe;
- x4->out_pic.quality = (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA;
+ if (bufsize)
+ x4->out_pic.quality = (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA;
return bufsize;
}
@@ -156,25 +233,87 @@ static av_cold int X264_close(AVCodecContext *avctx)
return 0;
}
+#define OPT_STR(opt, param) \
+ do { \
+ int ret; \
+ if (param && (ret = x264_param_parse(&x4->params, opt, param)) < 0) { \
+ if(ret == X264_PARAM_BAD_NAME) \
+ av_log(avctx, AV_LOG_ERROR, \
+ "bad option '%s': '%s'\n", opt, param); \
+ else \
+ av_log(avctx, AV_LOG_ERROR, \
+ "bad value for '%s': '%s'\n", opt, param); \
+ return -1; \
+ } \
+ } while (0);
+
+static int convert_pix_fmt(enum PixelFormat pix_fmt)
+{
+ switch (pix_fmt) {
+ case PIX_FMT_YUV420P:
+ case PIX_FMT_YUVJ420P:
+ case PIX_FMT_YUV420P9:
+ case PIX_FMT_YUV420P10: return X264_CSP_I420;
+ case PIX_FMT_YUV422P:
+ case PIX_FMT_YUV422P10: return X264_CSP_I422;
+ case PIX_FMT_YUV444P:
+ case PIX_FMT_YUV444P9:
+ case PIX_FMT_YUV444P10: return X264_CSP_I444;
+#ifdef X264_CSP_BGR
+ case PIX_FMT_BGR24:
+ return X264_CSP_BGR;
+
+ case PIX_FMT_RGB24:
+ return X264_CSP_RGB;
+#endif
+ };
+ return 0;
+}
+
+#define PARSE_X264_OPT(name, var)\
+ if (x4->var && x264_param_parse(&x4->params, name, x4->var) < 0) {\
+ av_log(avctx, AV_LOG_ERROR, "Error parsing option '%s' with value '%s'.\n", name, x4->var);\
+ return AVERROR(EINVAL);\
+ }
+
static av_cold int X264_init(AVCodecContext *avctx)
{
X264Context *x4 = avctx->priv_data;
- x4->sei_size = 0;
x264_param_default(&x4->params);
+ x4->params.b_deblocking_filter = avctx->flags & CODEC_FLAG_LOOP_FILTER;
+
+ x4->params.rc.f_ip_factor = 1 / fabs(avctx->i_quant_factor);
+ x4->params.rc.f_pb_factor = avctx->b_quant_factor;
+ x4->params.analyse.i_chroma_qp_offset = avctx->chromaoffset;
+ if (x4->preset || x4->tune)
+ if (x264_param_default_preset(&x4->params, x4->preset, x4->tune) < 0) {
+ av_log(avctx, AV_LOG_ERROR, "Error setting preset/tune %s/%s.\n", x4->preset, x4->tune);
+ return AVERROR(EINVAL);
+ }
+
+ if (avctx->level > 0)
+ x4->params.i_level_idc = avctx->level;
+
x4->params.pf_log = X264_log;
x4->params.p_log_private = avctx;
+ x4->params.i_log_level = X264_LOG_DEBUG;
+ x4->params.i_csp = convert_pix_fmt(avctx->pix_fmt);
+
+ OPT_STR("weightp", x4->wpredp);
- x4->params.i_keyint_max = avctx->gop_size;
- x4->params.b_intra_refresh = avctx->flags2 & CODEC_FLAG2_INTRA_REFRESH;
- x4->params.rc.i_bitrate = avctx->bit_rate / 1000;
+ if (avctx->bit_rate) {
+ x4->params.rc.i_bitrate = avctx->bit_rate / 1000;
+ x4->params.rc.i_rc_method = X264_RC_ABR;
+ }
x4->params.rc.i_vbv_buffer_size = avctx->rc_buffer_size / 1000;
x4->params.rc.i_vbv_max_bitrate = avctx->rc_max_rate / 1000;
x4->params.rc.b_stat_write = avctx->flags & CODEC_FLAG_PASS1;
if (avctx->flags & CODEC_FLAG_PASS2) {
x4->params.rc.b_stat_read = 1;
} else {
+#if FF_API_X264_GLOBAL_OPTS
if (avctx->crf) {
x4->params.rc.i_rc_method = X264_RC_CRF;
x4->params.rc.f_rf_constant = avctx->crf;
@@ -183,48 +322,64 @@ static av_cold int X264_init(AVCodecContext *avctx)
x4->params.rc.i_rc_method = X264_RC_CQP;
x4->params.rc.i_qp_constant = avctx->cqp;
}
- }
-
- // if neither crf nor cqp modes are selected we have to enable the RC
- // we do it this way because we cannot check if the bitrate has been set
- if (!(avctx->crf || (avctx->cqp > -1)))
- x4->params.rc.i_rc_method = X264_RC_ABR;
-
- x4->params.i_bframe = avctx->max_b_frames;
- x4->params.b_cabac = avctx->coder_type == FF_CODER_TYPE_AC;
- x4->params.i_bframe_adaptive = avctx->b_frame_strategy;
- x4->params.i_bframe_bias = avctx->bframebias;
- x4->params.i_bframe_pyramid = avctx->flags2 & CODEC_FLAG2_BPYRAMID ? X264_B_PYRAMID_NORMAL : X264_B_PYRAMID_NONE;
- avctx->has_b_frames = avctx->flags2 & CODEC_FLAG2_BPYRAMID ? 2 : !!avctx->max_b_frames;
+#endif
- x4->params.i_keyint_min = avctx->keyint_min;
- if (x4->params.i_keyint_min > x4->params.i_keyint_max)
- x4->params.i_keyint_min = x4->params.i_keyint_max;
-
- x4->params.i_scenecut_threshold = avctx->scenechange_threshold;
+ if (x4->crf >= 0) {
+ x4->params.rc.i_rc_method = X264_RC_CRF;
+ x4->params.rc.f_rf_constant = x4->crf;
+ } else if (x4->cqp >= 0) {
+ x4->params.rc.i_rc_method = X264_RC_CQP;
+ x4->params.rc.i_qp_constant = x4->cqp;
+ }
- x4->params.b_deblocking_filter = avctx->flags & CODEC_FLAG_LOOP_FILTER;
- x4->params.i_deblocking_filter_alphac0 = avctx->deblockalpha;
- x4->params.i_deblocking_filter_beta = avctx->deblockbeta;
+ if (x4->crf_max >= 0)
+ x4->params.rc.f_rf_constant_max = x4->crf_max;
+ }
- x4->params.rc.i_qp_min = avctx->qmin;
- x4->params.rc.i_qp_max = avctx->qmax;
- x4->params.rc.i_qp_step = avctx->max_qdiff;
+ OPT_STR("stats", x4->stats);
- x4->params.rc.f_qcompress = avctx->qcompress; /* 0.0 => cbr, 1.0 => constant qp */
- x4->params.rc.f_qblur = avctx->qblur; /* temporally blur quants */
- x4->params.rc.f_complexity_blur = avctx->complexityblur;
+ if (avctx->rc_buffer_size && avctx->rc_initial_buffer_occupancy &&
+ (avctx->rc_initial_buffer_occupancy <= avctx->rc_buffer_size)) {
+ x4->params.rc.f_vbv_buffer_init =
+ (float)avctx->rc_initial_buffer_occupancy / avctx->rc_buffer_size;
+ }
- x4->params.i_frame_reference = avctx->refs;
+ OPT_STR("level", x4->level);
- x4->params.i_width = avctx->width;
- x4->params.i_height = avctx->height;
- x4->params.vui.i_sar_width = avctx->sample_aspect_ratio.num;
- x4->params.vui.i_sar_height = avctx->sample_aspect_ratio.den;
- x4->params.i_fps_num = x4->params.i_timebase_den = avctx->time_base.den;
- x4->params.i_fps_den = x4->params.i_timebase_num = avctx->time_base.num;
+ if(x4->x264opts){
+ const char *p= x4->x264opts;
+ while(p){
+ char param[256]={0}, val[256]={0};
+ sscanf(p, "%255[^:=]=%255[^:]", param, val);
+ OPT_STR(param, val);
+ p= strchr(p, ':');
+ p+=!!p;
+ }
+ }
- x4->params.analyse.inter = 0;
+#if FF_API_X264_GLOBAL_OPTS
+ if (avctx->aq_mode >= 0)
+ x4->params.rc.i_aq_mode = avctx->aq_mode;
+ if (avctx->aq_strength >= 0)
+ x4->params.rc.f_aq_strength = avctx->aq_strength;
+ if (avctx->psy_rd >= 0)
+ x4->params.analyse.f_psy_rd = avctx->psy_rd;
+ if (avctx->psy_trellis >= 0)
+ x4->params.analyse.f_psy_trellis = avctx->psy_trellis;
+ if (avctx->rc_lookahead >= 0)
+ x4->params.rc.i_lookahead = avctx->rc_lookahead;
+ if (avctx->weighted_p_pred >= 0)
+ x4->params.analyse.i_weighted_pred = avctx->weighted_p_pred;
+ if (avctx->bframebias)
+ x4->params.i_bframe_bias = avctx->bframebias;
+ if (avctx->deblockalpha)
+ x4->params.i_deblocking_filter_alphac0 = avctx->deblockalpha;
+ if (avctx->deblockbeta)
+ x4->params.i_deblocking_filter_beta = avctx->deblockbeta;
+ if (avctx->complexityblur >= 0)
+ x4->params.rc.f_complexity_blur = avctx->complexityblur;
+ if (avctx->directpred >= 0)
+ x4->params.analyse.i_direct_mv_pred = avctx->directpred;
if (avctx->partitions) {
if (avctx->partitions & X264_PART_I4X4)
x4->params.analyse.inter |= X264_ANALYSE_I4x4;
@@ -237,11 +392,19 @@ static av_cold int X264_init(AVCodecContext *avctx)
if (avctx->partitions & X264_PART_B8X8)
x4->params.analyse.inter |= X264_ANALYSE_BSUB16x16;
}
-
- x4->params.analyse.i_direct_mv_pred = avctx->directpred;
-
- x4->params.analyse.b_weighted_bipred = avctx->flags2 & CODEC_FLAG2_WPRED;
- x4->params.analyse.i_weighted_pred = avctx->weighted_p_pred;
+ if (avctx->flags2) {
+ x4->params.analyse.b_ssim = avctx->flags2 & CODEC_FLAG2_SSIM;
+ x4->params.b_intra_refresh = avctx->flags2 & CODEC_FLAG2_INTRA_REFRESH;
+ x4->params.i_bframe_pyramid = avctx->flags2 & CODEC_FLAG2_BPYRAMID ? X264_B_PYRAMID_NORMAL : X264_B_PYRAMID_NONE;
+ x4->params.analyse.b_weighted_bipred = avctx->flags2 & CODEC_FLAG2_WPRED;
+ x4->params.analyse.b_mixed_references = avctx->flags2 & CODEC_FLAG2_MIXED_REFS;
+ x4->params.analyse.b_transform_8x8 = avctx->flags2 & CODEC_FLAG2_8X8DCT;
+ x4->params.analyse.b_fast_pskip = avctx->flags2 & CODEC_FLAG2_FASTPSKIP;
+ x4->params.b_aud = avctx->flags2 & CODEC_FLAG2_AUD;
+ x4->params.analyse.b_psy = avctx->flags2 & CODEC_FLAG2_PSY;
+ x4->params.rc.b_mb_tree = !!(avctx->flags2 & CODEC_FLAG2_MBTREE);
+ }
+#endif
if (avctx->me_method == ME_EPZS)
x4->params.analyse.i_me_method = X264_ME_DIA;
@@ -253,52 +416,107 @@ static av_cold int X264_init(AVCodecContext *avctx)
x4->params.analyse.i_me_method = X264_ME_ESA;
else if (avctx->me_method == ME_TESA)
x4->params.analyse.i_me_method = X264_ME_TESA;
- else x4->params.analyse.i_me_method = X264_ME_HEX;
-
- x4->params.rc.i_aq_mode = avctx->aq_mode;
- x4->params.rc.f_aq_strength = avctx->aq_strength;
- x4->params.rc.i_lookahead = avctx->rc_lookahead;
-
- x4->params.analyse.b_psy = avctx->flags2 & CODEC_FLAG2_PSY;
- x4->params.analyse.f_psy_rd = avctx->psy_rd;
- x4->params.analyse.f_psy_trellis = avctx->psy_trellis;
-
- x4->params.analyse.i_me_range = avctx->me_range;
- x4->params.analyse.i_subpel_refine = avctx->me_subpel_quality;
- x4->params.analyse.b_mixed_references = avctx->flags2 & CODEC_FLAG2_MIXED_REFS;
- x4->params.analyse.b_chroma_me = avctx->me_cmp & FF_CMP_CHROMA;
- x4->params.analyse.b_transform_8x8 = avctx->flags2 & CODEC_FLAG2_8X8DCT;
- x4->params.analyse.b_fast_pskip = avctx->flags2 & CODEC_FLAG2_FASTPSKIP;
-
- x4->params.analyse.i_trellis = avctx->trellis;
- x4->params.analyse.i_noise_reduction = avctx->noise_reduction;
-
- if (avctx->level > 0)
- x4->params.i_level_idc = avctx->level;
-
- if (avctx->rc_buffer_size && avctx->rc_initial_buffer_occupancy &&
- (avctx->rc_initial_buffer_occupancy <= avctx->rc_buffer_size)) {
- x4->params.rc.f_vbv_buffer_init =
- (float)avctx->rc_initial_buffer_occupancy / avctx->rc_buffer_size;
- }
+ if (avctx->gop_size >= 0)
+ x4->params.i_keyint_max = avctx->gop_size;
+ if (avctx->max_b_frames >= 0)
+ x4->params.i_bframe = avctx->max_b_frames;
+ if (avctx->scenechange_threshold >= 0)
+ x4->params.i_scenecut_threshold = avctx->scenechange_threshold;
+ if (avctx->qmin >= 0)
+ x4->params.rc.i_qp_min = avctx->qmin;
+ if (avctx->qmax >= 0)
+ x4->params.rc.i_qp_max = avctx->qmax;
+ if (avctx->max_qdiff >= 0)
+ x4->params.rc.i_qp_step = avctx->max_qdiff;
+ if (avctx->qblur >= 0)
+ x4->params.rc.f_qblur = avctx->qblur; /* temporally blur quants */
+ if (avctx->qcompress >= 0)
+ x4->params.rc.f_qcompress = avctx->qcompress; /* 0.0 => cbr, 1.0 => constant qp */
+ if (avctx->refs >= 0)
+ x4->params.i_frame_reference = avctx->refs;
+ if (avctx->trellis >= 0)
+ x4->params.analyse.i_trellis = avctx->trellis;
+ if (avctx->me_range >= 0)
+ x4->params.analyse.i_me_range = avctx->me_range;
+ if (avctx->noise_reduction >= 0)
+ x4->params.analyse.i_noise_reduction = avctx->noise_reduction;
+ if (avctx->me_subpel_quality >= 0)
+ x4->params.analyse.i_subpel_refine = avctx->me_subpel_quality;
+ if (avctx->b_frame_strategy >= 0)
+ x4->params.i_bframe_adaptive = avctx->b_frame_strategy;
+ if (avctx->keyint_min >= 0)
+ x4->params.i_keyint_min = avctx->keyint_min;
+ if (avctx->coder_type >= 0)
+ x4->params.b_cabac = avctx->coder_type == FF_CODER_TYPE_AC;
+ if (avctx->me_cmp >= 0)
+ x4->params.analyse.b_chroma_me = avctx->me_cmp & FF_CMP_CHROMA;
+
+ if (x4->aq_mode >= 0)
+ x4->params.rc.i_aq_mode = x4->aq_mode;
+ if (x4->aq_strength >= 0)
+ x4->params.rc.f_aq_strength = x4->aq_strength;
+ PARSE_X264_OPT("psy-rd", psy_rd);
+ PARSE_X264_OPT("deblock", deblock);
+ PARSE_X264_OPT("partitions", partitions);
+ if (x4->psy >= 0)
+ x4->params.analyse.b_psy = x4->psy;
+ if (x4->rc_lookahead >= 0)
+ x4->params.rc.i_lookahead = x4->rc_lookahead;
+ if (x4->weightp >= 0)
+ x4->params.analyse.i_weighted_pred = x4->weightp;
+ if (x4->weightb >= 0)
+ x4->params.analyse.b_weighted_bipred = x4->weightb;
+ if (x4->cplxblur >= 0)
+ x4->params.rc.f_complexity_blur = x4->cplxblur;
+
+ if (x4->ssim >= 0)
+ x4->params.analyse.b_ssim = x4->ssim;
+ if (x4->intra_refresh >= 0)
+ x4->params.b_intra_refresh = x4->intra_refresh;
+ if (x4->b_bias != INT_MIN)
+ x4->params.i_bframe_bias = x4->b_bias;
+ if (x4->b_pyramid >= 0)
+ x4->params.i_bframe_pyramid = x4->b_pyramid;
+ if (x4->mixed_refs >= 0)
+ x4->params.analyse.b_mixed_references = x4->mixed_refs;
+ if (x4->dct8x8 >= 0)
+ x4->params.analyse.b_transform_8x8 = x4->dct8x8;
+ if (x4->fast_pskip >= 0)
+ x4->params.analyse.b_fast_pskip = x4->fast_pskip;
+ if (x4->aud >= 0)
+ x4->params.b_aud = x4->aud;
+ if (x4->mbtree >= 0)
+ x4->params.rc.b_mb_tree = x4->mbtree;
+ if (x4->direct_pred >= 0)
+ x4->params.analyse.i_direct_mv_pred = x4->direct_pred;
+
+ if (x4->slice_max_size >= 0)
+ x4->params.i_slice_max_size = x4->slice_max_size;
+
+ if (x4->fastfirstpass)
+ x264_param_apply_fastfirstpass(&x4->params);
+
+ if (x4->profile)
+ if (x264_param_apply_profile(&x4->params, x4->profile) < 0) {
+ av_log(avctx, AV_LOG_ERROR, "Error setting profile %s.\n", x4->profile);
+ return AVERROR(EINVAL);
+ }
- x4->params.rc.b_mb_tree = !!(avctx->flags2 & CODEC_FLAG2_MBTREE);
- x4->params.rc.f_ip_factor = 1 / fabs(avctx->i_quant_factor);
- x4->params.rc.f_pb_factor = avctx->b_quant_factor;
- x4->params.analyse.i_chroma_qp_offset = avctx->chromaoffset;
+ x4->params.i_width = avctx->width;
+ x4->params.i_height = avctx->height;
+ x4->params.vui.i_sar_width = avctx->sample_aspect_ratio.num;
+ x4->params.vui.i_sar_height = avctx->sample_aspect_ratio.den;
+ x4->params.i_fps_num = x4->params.i_timebase_den = avctx->time_base.den;
+ x4->params.i_fps_den = x4->params.i_timebase_num = avctx->time_base.num;
x4->params.analyse.b_psnr = avctx->flags & CODEC_FLAG_PSNR;
- x4->params.analyse.b_ssim = avctx->flags2 & CODEC_FLAG2_SSIM;
- x4->params.i_log_level = X264_LOG_DEBUG;
-
- x4->params.b_aud = avctx->flags2 & CODEC_FLAG2_AUD;
x4->params.i_threads = avctx->thread_count;
x4->params.b_interlaced = avctx->flags & CODEC_FLAG_INTERLACED_DCT;
- x4->params.b_open_gop = !(avctx->flags & CODEC_FLAG_CLOSED_GOP);
+// x4->params.b_open_gop = !(avctx->flags & CODEC_FLAG_CLOSED_GOP);
x4->params.i_slice_count = avctx->slices;
@@ -307,6 +525,14 @@ static av_cold int X264_init(AVCodecContext *avctx)
if (avctx->flags & CODEC_FLAG_GLOBAL_HEADER)
x4->params.b_repeat_headers = 0;
+ // update AVCodecContext with x264 parameters
+ avctx->has_b_frames = x4->params.i_bframe ?
+ x4->params.i_bframe_pyramid ? 2 : 1 : 0;
+ avctx->bit_rate = x4->params.rc.i_bitrate*1000;
+#if FF_API_X264_GLOBAL_OPTS
+ avctx->crf = x4->params.rc.f_rf_constant;
+#endif
+
x4->enc = x264_encoder_open(&x4->params);
if (!x4->enc)
return -1;
@@ -330,6 +556,124 @@ static av_cold int X264_init(AVCodecContext *avctx)
return 0;
}
+static const enum PixelFormat pix_fmts_8bit[] = {
+ PIX_FMT_YUV420P,
+ PIX_FMT_YUVJ420P,
+ PIX_FMT_YUV422P,
+ PIX_FMT_YUV444P,
+#ifdef X264_CSP_BGR
+ PIX_FMT_BGR24,
+ PIX_FMT_RGB24,
+#endif
+ PIX_FMT_NONE
+};
+static const enum PixelFormat pix_fmts_9bit[] = {
+ PIX_FMT_YUV420P9,
+ PIX_FMT_YUV444P9,
+ PIX_FMT_NONE
+};
+static const enum PixelFormat pix_fmts_10bit[] = {
+ PIX_FMT_YUV420P10,
+ PIX_FMT_YUV422P10,
+ PIX_FMT_YUV444P10,
+ PIX_FMT_NONE
+};
+
+static av_cold void X264_init_static(AVCodec *codec)
+{
+ if (x264_bit_depth == 8)
+ codec->pix_fmts = pix_fmts_8bit;
+ else if (x264_bit_depth == 9)
+ codec->pix_fmts = pix_fmts_9bit;
+ else if (x264_bit_depth == 10)
+ codec->pix_fmts = pix_fmts_10bit;
+}
+
+#define OFFSET(x) offsetof(X264Context, x)
+#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
+static const AVOption options[] = {
+ { "preset", "Set the encoding preset (cf. x264 --fullhelp)", OFFSET(preset), AV_OPT_TYPE_STRING, { .str = "medium" }, 0, 0, VE},
+ { "tune", "Tune the encoding params (cf. x264 --fullhelp)", OFFSET(tune), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE},
+ { "profile", "Set profile restrictions (cf. x264 --fullhelp) ", OFFSET(profile), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE},
+ { "fastfirstpass", "Use fast settings when encoding first pass", OFFSET(fastfirstpass), AV_OPT_TYPE_INT, { 1 }, 0, 1, VE},
+ {"level", "Specify level (as defined by Annex A)", OFFSET(level), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, VE},
+ {"passlogfile", "Filename for 2 pass stats", OFFSET(stats), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, VE},
+ {"wpredp", "Weighted prediction for P-frames", OFFSET(wpredp), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, VE},
+ {"x264opts", "x264 options", OFFSET(x264opts), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, VE},
+ { "crf", "Select the quality for constant quality mode", OFFSET(crf), AV_OPT_TYPE_FLOAT, {-1 }, -1, FLT_MAX, VE },
+ { "crf_max", "In CRF mode, prevents VBV from lowering quality beyond this point.",OFFSET(crf_max), AV_OPT_TYPE_FLOAT, {-1 }, -1, FLT_MAX, VE },
+ { "qp", "Constant quantization parameter rate control method",OFFSET(cqp), AV_OPT_TYPE_INT, {-1 }, -1, INT_MAX, VE },
+ { "aq-mode", "AQ method", OFFSET(aq_mode), AV_OPT_TYPE_INT, {-1 }, -1, INT_MAX, VE, "aq_mode"},
+ { "none", NULL, 0, AV_OPT_TYPE_CONST, {X264_AQ_NONE}, INT_MIN, INT_MAX, VE, "aq_mode" },
+ { "variance", "Variance AQ (complexity mask)", 0, AV_OPT_TYPE_CONST, {X264_AQ_VARIANCE}, INT_MIN, INT_MAX, VE, "aq_mode" },
+ { "autovariance", "Auto-variance AQ (experimental)", 0, AV_OPT_TYPE_CONST, {X264_AQ_AUTOVARIANCE}, INT_MIN, INT_MAX, VE, "aq_mode" },
+ { "aq-strength", "AQ strength. Reduces blocking and blurring in flat and textured areas.", OFFSET(aq_strength), AV_OPT_TYPE_FLOAT, {-1}, -1, FLT_MAX, VE},
+ { "psy", "Use psychovisual optimizations.", OFFSET(psy), AV_OPT_TYPE_INT, {-1 }, -1, 1, VE },
+ { "psy-rd", "Strength of psychovisual optimization, in <psy-rd>:<psy-trellis> format.", OFFSET(psy_rd), AV_OPT_TYPE_STRING, {0 }, 0, 0, VE},
+ { "rc-lookahead", "Number of frames to look ahead for frametype and ratecontrol", OFFSET(rc_lookahead), AV_OPT_TYPE_INT, {-1 }, -1, INT_MAX, VE },
+ { "weightb", "Weighted prediction for B-frames.", OFFSET(weightb), AV_OPT_TYPE_INT, {-1 }, -1, 1, VE },
+ { "weightp", "Weighted prediction analysis method.", OFFSET(weightp), AV_OPT_TYPE_INT, {-1 }, -1, INT_MAX, VE, "weightp" },
+ { "none", NULL, 0, AV_OPT_TYPE_CONST, {X264_WEIGHTP_NONE}, INT_MIN, INT_MAX, VE, "weightp" },
+ { "simple", NULL, 0, AV_OPT_TYPE_CONST, {X264_WEIGHTP_SIMPLE}, INT_MIN, INT_MAX, VE, "weightp" },
+ { "smart", NULL, 0, AV_OPT_TYPE_CONST, {X264_WEIGHTP_SMART}, INT_MIN, INT_MAX, VE, "weightp" },
+ { "ssim", "Calculate and print SSIM stats.", OFFSET(ssim), AV_OPT_TYPE_INT, {-1 }, -1, 1, VE },
+ { "intra-refresh", "Use Periodic Intra Refresh instead of IDR frames.",OFFSET(intra_refresh),AV_OPT_TYPE_INT, {-1 }, -1, 1, VE },
+ { "b-bias", "Influences how often B-frames are used", OFFSET(b_bias), AV_OPT_TYPE_INT, {INT_MIN}, INT_MIN, INT_MAX, VE },
+ { "b-pyramid", "Keep some B-frames as references.", OFFSET(b_pyramid), AV_OPT_TYPE_INT, {-1 }, -1, INT_MAX, VE, "b_pyramid" },
+ { "none", NULL, 0, AV_OPT_TYPE_CONST, {X264_B_PYRAMID_NONE}, INT_MIN, INT_MAX, VE, "b_pyramid" },
+ { "strict", "Strictly hierarchical pyramid", 0, AV_OPT_TYPE_CONST, {X264_B_PYRAMID_STRICT}, INT_MIN, INT_MAX, VE, "b_pyramid" },
+ { "normal", "Non-strict (not Blu-ray compatible)", 0, AV_OPT_TYPE_CONST, {X264_B_PYRAMID_NORMAL}, INT_MIN, INT_MAX, VE, "b_pyramid" },
+ { "mixed-refs", "One reference per partition, as opposed to one reference per macroblock", OFFSET(mixed_refs), AV_OPT_TYPE_INT, {-1}, -1, 1, VE },
+ { "8x8dct", "High profile 8x8 transform.", OFFSET(dct8x8), AV_OPT_TYPE_INT, {-1 }, -1, 1, VE},
+ { "fast-pskip", NULL, OFFSET(fast_pskip), AV_OPT_TYPE_INT, {-1 }, -1, 1, VE},
+ { "aud", "Use access unit delimiters.", OFFSET(aud), AV_OPT_TYPE_INT, {-1 }, -1, 1, VE},
+ { "mbtree", "Use macroblock tree ratecontrol.", OFFSET(mbtree), AV_OPT_TYPE_INT, {-1 }, -1, 1, VE},
+ { "deblock", "Loop filter parameters, in <alpha:beta> form.", OFFSET(deblock), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE},
+ { "cplxblur", "Reduce fluctuations in QP (before curve compression)", OFFSET(cplxblur), AV_OPT_TYPE_FLOAT, {-1 }, -1, FLT_MAX, VE},
+ { "partitions", "A comma-separated list of partitions to consider. "
+ "Possible values: p8x8, p4x4, b8x8, i8x8, i4x4, none, all", OFFSET(partitions), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE},
+ { "direct-pred", "Direct MV prediction mode", OFFSET(direct_pred), AV_OPT_TYPE_INT, {-1 }, -1, INT_MAX, VE, "direct-pred" },
+ { "none", NULL, 0, AV_OPT_TYPE_CONST, { X264_DIRECT_PRED_NONE }, 0, 0, VE, "direct-pred" },
+ { "spatial", NULL, 0, AV_OPT_TYPE_CONST, { X264_DIRECT_PRED_SPATIAL }, 0, 0, VE, "direct-pred" },
+ { "temporal", NULL, 0, AV_OPT_TYPE_CONST, { X264_DIRECT_PRED_TEMPORAL }, 0, 0, VE, "direct-pred" },
+ { "auto", NULL, 0, AV_OPT_TYPE_CONST, { X264_DIRECT_PRED_AUTO }, 0, 0, VE, "direct-pred" },
+ { "slice-max-size","Constant quantization parameter rate control method",OFFSET(slice_max_size), AV_OPT_TYPE_INT, {-1 }, -1, INT_MAX, VE },
+ { NULL },
+};
+
+static const AVClass class = {
+ .class_name = "libx264",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
+static const AVCodecDefault x264_defaults[] = {
+ { "b", "0" },
+ { "bf", "-1" },
+ { "flags2", "0" },
+ { "g", "-1" },
+ { "qmin", "-1" },
+ { "qmax", "-1" },
+ { "qdiff", "-1" },
+ { "qblur", "-1" },
+ { "qcomp", "-1" },
+ { "rc_lookahead", "-1" },
+ { "refs", "-1" },
+ { "sc_threshold", "-1" },
+ { "trellis", "-1" },
+ { "nr", "-1" },
+ { "me_range", "-1" },
+ { "me_method", "-1" },
+ { "subq", "-1" },
+ { "b_strategy", "-1" },
+ { "keyint_min", "-1" },
+ { "coder", "-1" },
+ { "cmp", "-1" },
+ { "threads", AV_STRINGIFY(X264_THREADS_AUTO) },
+ { NULL },
+};
+
AVCodec ff_libx264_encoder = {
.name = "libx264",
.type = AVMEDIA_TYPE_VIDEO,
@@ -339,6 +683,8 @@ AVCodec ff_libx264_encoder = {
.encode = X264_frame,
.close = X264_close,
.capabilities = CODEC_CAP_DELAY,
- .pix_fmts = (const enum PixelFormat[]) { PIX_FMT_YUV420P, PIX_FMT_YUVJ420P, PIX_FMT_NONE },
.long_name = NULL_IF_CONFIG_SMALL("libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"),
+ .priv_class = &class,
+ .defaults = x264_defaults,
+ .init_static_data = X264_init_static,
};
diff --git a/libavcodec/libxavs.c b/libavcodec/libxavs.c
index d11c4248e1..4d9bec03e6 100644
--- a/libavcodec/libxavs.c
+++ b/libavcodec/libxavs.c
@@ -2,20 +2,20 @@
* AVS encoding using the xavs library
* Copyright (C) 2010 Amanda, Y.N. Wu <amanda11192003@gmail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -24,8 +24,11 @@
#include <string.h>
#include <math.h>
#include <stdint.h>
+#include <float.h>
#include <xavs.h>
#include "avcodec.h"
+#include "internal.h"
+#include "libavutil/opt.h"
#define END_OF_STREAM 0x001
@@ -41,6 +44,15 @@ typedef struct XavsContext {
int sei_size;
AVFrame out_pic;
int end_of_stream;
+ float crf;
+ int cqp;
+ int b_bias;
+ float cplxblur;
+ int direct_pred;
+ int aud;
+ int fast_pskip;
+ int mbtree;
+ int mixed_refs;
} XavsContext;
static void XAVS_log(void *p, int level, const char *fmt, va_list args)
@@ -181,13 +193,17 @@ static av_cold int XAVS_init(AVCodecContext *avctx)
x4->params.pf_log = XAVS_log;
x4->params.p_log_private = avctx;
x4->params.i_keyint_max = avctx->gop_size;
- x4->params.rc.i_bitrate = avctx->bit_rate / 1000;
+ if (avctx->bit_rate) {
+ x4->params.rc.i_bitrate = avctx->bit_rate / 1000;
+ x4->params.rc.i_rc_method = XAVS_RC_ABR;
+ }
x4->params.rc.i_vbv_buffer_size = avctx->rc_buffer_size / 1000;
x4->params.rc.i_vbv_max_bitrate = avctx->rc_max_rate / 1000;
x4->params.rc.b_stat_write = avctx->flags & CODEC_FLAG_PASS1;
if (avctx->flags & CODEC_FLAG_PASS2) {
x4->params.rc.b_stat_read = 1;
} else {
+#if FF_API_X264_GLOBAL_OPTS
if (avctx->crf) {
x4->params.rc.i_rc_method = XAVS_RC_CRF;
x4->params.rc.f_rf_constant = avctx->crf;
@@ -195,19 +211,63 @@ static av_cold int XAVS_init(AVCodecContext *avctx)
x4->params.rc.i_rc_method = XAVS_RC_CQP;
x4->params.rc.i_qp_constant = avctx->cqp;
}
+#endif
+
+ if (x4->crf >= 0) {
+ x4->params.rc.i_rc_method = XAVS_RC_CRF;
+ x4->params.rc.f_rf_constant = x4->crf;
+ } else if (x4->cqp >= 0) {
+ x4->params.rc.i_rc_method = XAVS_RC_CQP;
+ x4->params.rc.i_qp_constant = x4->cqp;
+ }
}
- /* if neither crf nor cqp modes are selected we have to enable the RC */
- /* we do it this way because we cannot check if the bitrate has been set */
- if (!(avctx->crf || (avctx->cqp > -1)))
- x4->params.rc.i_rc_method = XAVS_RC_ABR;
+#if FF_API_X264_GLOBAL_OPTS
+ if (avctx->bframebias)
+ x4->params.i_bframe_bias = avctx->bframebias;
+ if (avctx->deblockalpha)
+ x4->params.i_deblocking_filter_alphac0 = avctx->deblockalpha;
+ if (avctx->deblockbeta)
+ x4->params.i_deblocking_filter_beta = avctx->deblockbeta;
+ if (avctx->complexityblur >= 0)
+ x4->params.rc.f_complexity_blur = avctx->complexityblur;
+ if (avctx->directpred >= 0)
+ x4->params.analyse.i_direct_mv_pred = avctx->directpred;
+ if (avctx->partitions) {
+ if (avctx->partitions & XAVS_PART_I8X8)
+ x4->params.analyse.inter |= XAVS_ANALYSE_I8x8;
+ if (avctx->partitions & XAVS_PART_P8X8)
+ x4->params.analyse.inter |= XAVS_ANALYSE_PSUB16x16;
+ if (avctx->partitions & XAVS_PART_B8X8)
+ x4->params.analyse.inter |= XAVS_ANALYSE_BSUB16x16;
+ }
+ x4->params.rc.b_mb_tree = !!(avctx->flags2 & CODEC_FLAG2_MBTREE);
+ x4->params.b_aud = avctx->flags2 & CODEC_FLAG2_AUD;
+ x4->params.analyse.b_mixed_references = avctx->flags2 & CODEC_FLAG2_MIXED_REFS;
+ x4->params.analyse.b_fast_pskip = avctx->flags2 & CODEC_FLAG2_FASTPSKIP;
+ x4->params.analyse.b_weighted_bipred = avctx->flags2 & CODEC_FLAG2_WPRED;
+#endif
+
+ if (x4->aud >= 0)
+ x4->params.b_aud = x4->aud;
+ if (x4->mbtree >= 0)
+ x4->params.rc.b_mb_tree = x4->mbtree;
+ if (x4->direct_pred >= 0)
+ x4->params.analyse.i_direct_mv_pred = x4->direct_pred;
+ if (x4->fast_pskip >= 0)
+ x4->params.analyse.b_fast_pskip = x4->fast_pskip;
+ if (x4->mixed_refs >= 0)
+ x4->params.analyse.b_mixed_references = x4->mixed_refs;
+ if (x4->b_bias != INT_MIN)
+ x4->params.i_bframe_bias = x4->b_bias;
+ if (x4->cplxblur >= 0)
+ x4->params.rc.f_complexity_blur = x4->cplxblur;
x4->params.i_bframe = avctx->max_b_frames;
/* cabac is not included in AVS JiZhun Profile */
x4->params.b_cabac = 0;
x4->params.i_bframe_adaptive = avctx->b_frame_strategy;
- x4->params.i_bframe_bias = avctx->bframebias;
avctx->has_b_frames = !!avctx->max_b_frames;
@@ -220,8 +280,6 @@ static av_cold int XAVS_init(AVCodecContext *avctx)
x4->params.i_scenecut_threshold = avctx->scenechange_threshold;
// x4->params.b_deblocking_filter = avctx->flags & CODEC_FLAG_LOOP_FILTER;
- x4->params.i_deblocking_filter_alphac0 = avctx->deblockalpha;
- x4->params.i_deblocking_filter_beta = avctx->deblockbeta;
x4->params.rc.i_qp_min = avctx->qmin;
x4->params.rc.i_qp_max = avctx->qmax;
@@ -229,7 +287,6 @@ static av_cold int XAVS_init(AVCodecContext *avctx)
x4->params.rc.f_qcompress = avctx->qcompress; /* 0.0 => cbr, 1.0 => constant qp */
x4->params.rc.f_qblur = avctx->qblur; /* temporally blur quants */
- x4->params.rc.f_complexity_blur = avctx->complexityblur;
x4->params.i_frame_reference = avctx->refs;
@@ -241,20 +298,6 @@ static av_cold int XAVS_init(AVCodecContext *avctx)
x4->params.i_fps_num = avctx->time_base.den;
x4->params.i_fps_den = avctx->time_base.num;
x4->params.analyse.inter = XAVS_ANALYSE_I8x8 |XAVS_ANALYSE_PSUB16x16| XAVS_ANALYSE_BSUB16x16;
- if (avctx->partitions) {
- if (avctx->partitions & XAVS_PART_I8X8)
- x4->params.analyse.inter |= XAVS_ANALYSE_I8x8;
-
- if (avctx->partitions & XAVS_PART_P8X8)
- x4->params.analyse.inter |= XAVS_ANALYSE_PSUB16x16;
-
- if (avctx->partitions & XAVS_PART_B8X8)
- x4->params.analyse.inter |= XAVS_ANALYSE_BSUB16x16;
- }
-
- x4->params.analyse.i_direct_mv_pred = avctx->directpred;
-
- x4->params.analyse.b_weighted_bipred = avctx->flags2 & CODEC_FLAG2_WPRED;
switch (avctx->me_method) {
case ME_EPZS:
@@ -279,11 +322,9 @@ static av_cold int XAVS_init(AVCodecContext *avctx)
x4->params.analyse.i_me_range = avctx->me_range;
x4->params.analyse.i_subpel_refine = avctx->me_subpel_quality;
- x4->params.analyse.b_mixed_references = avctx->flags2 & CODEC_FLAG2_MIXED_REFS;
x4->params.analyse.b_chroma_me = avctx->me_cmp & FF_CMP_CHROMA;
/* AVS P2 only enables 8x8 transform */
x4->params.analyse.b_transform_8x8 = 1; //avctx->flags2 & CODEC_FLAG2_8X8DCT;
- x4->params.analyse.b_fast_pskip = avctx->flags2 & CODEC_FLAG2_FASTPSKIP;
x4->params.analyse.i_trellis = avctx->trellis;
x4->params.analyse.i_noise_reduction = avctx->noise_reduction;
@@ -303,14 +344,12 @@ static av_cold int XAVS_init(AVCodecContext *avctx)
/* TAG:do we have MB tree RC method */
/* what is the RC method we are now using? Default NO */
- x4->params.rc.b_mb_tree = !!(avctx->flags2 & CODEC_FLAG2_MBTREE);
x4->params.rc.f_ip_factor = 1 / fabs(avctx->i_quant_factor);
x4->params.rc.f_pb_factor = avctx->b_quant_factor;
x4->params.analyse.i_chroma_qp_offset = avctx->chromaoffset;
x4->params.analyse.b_psnr = avctx->flags & CODEC_FLAG_PSNR;
x4->params.i_log_level = XAVS_LOG_DEBUG;
- x4->params.b_aud = avctx->flags2 & CODEC_FLAG2_AUD;
x4->params.i_threads = avctx->thread_count;
x4->params.b_interlaced = avctx->flags & CODEC_FLAG_INTERLACED_DCT;
@@ -336,6 +375,37 @@ static av_cold int XAVS_init(AVCodecContext *avctx)
return 0;
}
+#define OFFSET(x) offsetof(XavsContext, x)
+#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
+static const AVOption options[] = {
+ { "crf", "Select the quality for constant quality mode", OFFSET(crf), AV_OPT_TYPE_FLOAT, {-1 }, -1, FLT_MAX, VE },
+ { "qp", "Constant quantization parameter rate control method",OFFSET(cqp), AV_OPT_TYPE_INT, {-1 }, -1, INT_MAX, VE },
+ { "b-bias", "Influences how often B-frames are used", OFFSET(b_bias), AV_OPT_TYPE_INT, {INT_MIN}, INT_MIN, INT_MAX, VE },
+ { "cplxblur", "Reduce fluctuations in QP (before curve compression)", OFFSET(cplxblur), AV_OPT_TYPE_FLOAT, {-1 }, -1, FLT_MAX, VE},
+ { "direct-pred", "Direct MV prediction mode", OFFSET(direct_pred), AV_OPT_TYPE_INT, {-1 }, -1, INT_MAX, VE, "direct-pred" },
+ { "none", NULL, 0, AV_OPT_TYPE_CONST, { XAVS_DIRECT_PRED_NONE }, 0, 0, VE, "direct-pred" },
+ { "spatial", NULL, 0, AV_OPT_TYPE_CONST, { XAVS_DIRECT_PRED_SPATIAL }, 0, 0, VE, "direct-pred" },
+ { "temporal", NULL, 0, AV_OPT_TYPE_CONST, { XAVS_DIRECT_PRED_TEMPORAL }, 0, 0, VE, "direct-pred" },
+ { "auto", NULL, 0, AV_OPT_TYPE_CONST, { XAVS_DIRECT_PRED_AUTO }, 0, 0, VE, "direct-pred" },
+ { "aud", "Use access unit delimiters.", OFFSET(aud), AV_OPT_TYPE_INT, {-1 }, -1, 1, VE},
+ { "mbtree", "Use macroblock tree ratecontrol.", OFFSET(mbtree), AV_OPT_TYPE_INT, {-1 }, -1, 1, VE},
+ { "mixed-refs", "One reference per partition, as opposed to one reference per macroblock", OFFSET(mixed_refs), AV_OPT_TYPE_INT, {-1}, -1, 1, VE },
+ { "fast-pskip", NULL, OFFSET(fast_pskip), AV_OPT_TYPE_INT, {-1 }, -1, 1, VE},
+ { NULL },
+};
+
+static const AVClass class = {
+ .class_name = "libxavs",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
+static const AVCodecDefault xavs_defaults[] = {
+ { "b", "0" },
+ { NULL },
+};
+
AVCodec ff_libxavs_encoder = {
.name = "libxavs",
.type = AVMEDIA_TYPE_VIDEO,
@@ -347,5 +417,7 @@ AVCodec ff_libxavs_encoder = {
.capabilities = CODEC_CAP_DELAY,
.pix_fmts = (const enum PixelFormat[]) { PIX_FMT_YUV420P, PIX_FMT_NONE },
.long_name = NULL_IF_CONFIG_SMALL("libxavs - the Chinese Audio Video Standard Encoder"),
+ .priv_class = &class,
+ .defaults = xavs_defaults,
};
diff --git a/libavcodec/libxvid_internal.h b/libavcodec/libxvid_internal.h
index a2dc6ef50c..6517f62174 100644
--- a/libavcodec/libxvid_internal.h
+++ b/libavcodec/libxvid_internal.h
@@ -1,20 +1,20 @@
/*
* copyright (C) 2006 Corey Hickey
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/libxvid_rc.c b/libavcodec/libxvid_rc.c
index b4bc715aea..8a2b487122 100644
--- a/libavcodec/libxvid_rc.c
+++ b/libavcodec/libxvid_rc.c
@@ -3,25 +3,26 @@
*
* Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <xvid.h>
#include <unistd.h>
+#include "libavutil/file.h"
#include "avcodec.h"
#include "libxvid_internal.h"
//#include "dsputil.h"
@@ -40,7 +41,7 @@ int ff_xvid_rate_control_init(MpegEncContext *s){
//xvid_debug=-1;
- fd=ff_tempfile("xvidrc.", &tmp_name);
+ fd=av_tempfile("xvidrc.", &tmp_name, 0, s->avctx);
if (fd == -1) {
av_log(NULL, AV_LOG_ERROR, "Can't create temporary pass2 file.\n");
return -1;
diff --git a/libavcodec/libxvidff.c b/libavcodec/libxvidff.c
index fd0aea58fa..f7aa7fd44e 100644
--- a/libavcodec/libxvidff.c
+++ b/libavcodec/libxvidff.c
@@ -2,20 +2,20 @@
* Interface to xvidcore for mpeg4 encoding
* Copyright (c) 2004 Adam Thayer <krevnik@comcast.net>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -28,13 +28,11 @@
#include <xvid.h>
#include <unistd.h>
#include "avcodec.h"
+#include "libavutil/file.h"
#include "libavutil/cpu.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mathematics.h"
#include "libxvid_internal.h"
-#if !HAVE_MKSTEMP
-#include <fcntl.h>
-#endif
/**
* Buffer management macros.
@@ -77,42 +75,6 @@ int xvid_strip_vol_header(AVCodecContext *avctx, unsigned char *frame, unsigned
int xvid_ff_2pass(void *ref, int opt, void *p1, void *p2);
void xvid_correct_framerate(AVCodecContext *avctx);
-/* Wrapper to work around the lack of mkstemp() on mingw.
- * Also, tries to create file in /tmp first, if possible.
- * *prefix can be a character constant; *filename will be allocated internally.
- * @return file descriptor of opened file (or -1 on error)
- * and opened file name in **filename. */
-int ff_tempfile(const char *prefix, char **filename) {
- int fd=-1;
-#if !HAVE_MKSTEMP
- *filename = tempnam(".", prefix);
-#else
- size_t len = strlen(prefix) + 12; /* room for "/tmp/" and "XXXXXX\0" */
- *filename = av_malloc(len);
-#endif
- /* -----common section-----*/
- if (*filename == NULL) {
- av_log(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot allocate file name\n");
- return -1;
- }
-#if !HAVE_MKSTEMP
- fd = open(*filename, O_RDWR | O_BINARY | O_CREAT, 0444);
-#else
- snprintf(*filename, len, "/tmp/%sXXXXXX", prefix);
- fd = mkstemp(*filename);
- if (fd < 0) {
- snprintf(*filename, len, "./%sXXXXXX", prefix);
- fd = mkstemp(*filename);
- }
-#endif
- /* -----common section-----*/
- if (fd < 0) {
- av_log(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot open temporary file %s\n", *filename);
- return -1;
- }
- return fd; /* success */
-}
-
#if CONFIG_LIBXVID_ENCODER
/**
@@ -270,7 +232,7 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx) {
rc2pass2.version = XVID_VERSION;
rc2pass2.bitrate = avctx->bit_rate;
- fd = ff_tempfile("xvidff.", &(x->twopassfile));
+ fd = av_tempfile("xvidff.", &(x->twopassfile), 0, avctx);
if( fd == -1 ) {
av_log(avctx, AV_LOG_ERROR,
"Xvid: Cannot write 2-pass pipe\n");
@@ -454,8 +416,8 @@ static int xvid_encode_frame(AVCodecContext *avctx,
XVID_TYPE_AUTO;
/* Pixel aspect ratio setting */
- if (avctx->sample_aspect_ratio.num < 1 || avctx->sample_aspect_ratio.num > 255 ||
- avctx->sample_aspect_ratio.den < 1 || avctx->sample_aspect_ratio.den > 255) {
+ if (avctx->sample_aspect_ratio.num < 0 || avctx->sample_aspect_ratio.num > 255 ||
+ avctx->sample_aspect_ratio.den < 0 || avctx->sample_aspect_ratio.den > 255) {
av_log(avctx, AV_LOG_ERROR, "Invalid pixel aspect ratio %i/%i\n",
avctx->sample_aspect_ratio.num, avctx->sample_aspect_ratio.den);
return -1;
@@ -529,6 +491,7 @@ static av_cold int xvid_encode_close(AVCodecContext *avctx) {
if( x->twopassbuffer != NULL ) {
av_free(x->twopassbuffer);
av_free(x->old_twopassbuffer);
+ avctx->stats_out = NULL;
}
av_free(x->twopassfile);
av_free(x->intra_matrix);
@@ -749,7 +712,7 @@ static int xvid_ff_2pass_before(struct xvid_context *ref,
static int xvid_ff_2pass_after(struct xvid_context *ref,
xvid_plg_data_t *param) {
char *log = ref->twopassbuffer;
- char *frame_types = " ipbs";
+ const char *frame_types = " ipbs";
char frame_type;
/* Quick bounds check */
@@ -809,13 +772,13 @@ int xvid_ff_2pass(void *ref, int cmd, void *p1, void *p2) {
* Xvid codec definition for libavcodec.
*/
AVCodec ff_libxvid_encoder = {
- "libxvid",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_MPEG4,
- sizeof(struct xvid_context),
- xvid_encode_init,
- xvid_encode_frame,
- xvid_encode_close,
+ .name = "libxvid",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_MPEG4,
+ .priv_data_size = sizeof(struct xvid_context),
+ .init = xvid_encode_init,
+ .encode = xvid_encode_frame,
+ .close = xvid_encode_close,
.pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
.long_name= NULL_IF_CONFIG_SMALL("libxvidcore MPEG-4 part 2"),
};
diff --git a/libavcodec/ljpegenc.c b/libavcodec/ljpegenc.c
index 56a60c913e..f8178d5adb 100644
--- a/libavcodec/ljpegenc.c
+++ b/libavcodec/ljpegenc.c
@@ -8,20 +8,20 @@
* aspecting, new decode_frame mechanism and apple mjpeg-b support
* by Alex Beregszaszi
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -187,12 +187,12 @@ static int encode_picture_lossless(AVCodecContext *avctx, unsigned char *buf, in
AVCodec ff_ljpeg_encoder = { //FIXME avoid MPV_* lossless JPEG should not need them
- "ljpeg",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_LJPEG,
- sizeof(MpegEncContext),
- MPV_encode_init,
- encode_picture_lossless,
- MPV_encode_end,
- .long_name = NULL_IF_CONFIG_SMALL("Lossless JPEG"),
+ .name = "ljpeg",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_LJPEG,
+ .priv_data_size = sizeof(MpegEncContext),
+ .init = MPV_encode_init,
+ .encode = encode_picture_lossless,
+ .close = MPV_encode_end,
+ .long_name = NULL_IF_CONFIG_SMALL("Lossless JPEG"),
};
diff --git a/libavcodec/loco.c b/libavcodec/loco.c
index 32b1bfc9b1..505f566ba6 100644
--- a/libavcodec/loco.c
+++ b/libavcodec/loco.c
@@ -2,20 +2,20 @@
* LOCO codec
* Copyright (c) 2005 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -272,6 +272,8 @@ static av_cold int decode_init(AVCodecContext *avctx){
if(avctx->debug & FF_DEBUG_PICT_INFO)
av_log(avctx, AV_LOG_INFO, "lossy:%i, version:%i, mode: %i\n", l->lossy, version, l->mode);
+ avcodec_get_frame_defaults(&l->pic);
+
return 0;
}
@@ -286,14 +288,13 @@ static av_cold int decode_end(AVCodecContext *avctx){
}
AVCodec ff_loco_decoder = {
- "loco",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_LOCO,
- sizeof(LOCOContext),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- CODEC_CAP_DR1,
+ .name = "loco",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_LOCO,
+ .priv_data_size = sizeof(LOCOContext),
+ .init = decode_init,
+ .close = decode_end,
+ .decode = decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("LOCO"),
};
diff --git a/libavcodec/lpc.c b/libavcodec/lpc.c
index 31fa324216..c27208823d 100644
--- a/libavcodec/lpc.c
+++ b/libavcodec/lpc.c
@@ -2,20 +2,20 @@
* LPC utility code
* Copyright (c) 2006 Justin Ruggles <justin.ruggles@gmail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -149,10 +149,8 @@ static int estimate_best_order(double *ref, int min_order, int max_order)
/**
* Calculate LPC coefficients for multiple orders
*
- * @param lpc_type LPC method for determining coefficients
- * 0 = LPC with fixed pre-defined coeffs
- * 1 = LPC with coeffs determined by Levinson-Durbin recursion
- * 2+ = LPC with coeffs determined by Cholesky factorization using (use_lpc-1) passes.
+ * @param lpc_type LPC method for determining coefficients,
+ * see #FFLPCType for details
*/
int ff_lpc_calc_coefs(LPCContext *s,
const int32_t *samples, int blocksize, int min_order,
diff --git a/libavcodec/lpc.h b/libavcodec/lpc.h
index 8cc2362e5b..9db5dbac30 100644
--- a/libavcodec/lpc.h
+++ b/libavcodec/lpc.h
@@ -2,20 +2,20 @@
* LPC utility code
* Copyright (c) 2006 Justin Ruggles <justin.ruggles@gmail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/lsp.c b/libavcodec/lsp.c
index 26b35843b6..374539a029 100644
--- a/libavcodec/lsp.c
+++ b/libavcodec/lsp.c
@@ -4,20 +4,20 @@
* Copyright (c) 2007 Reynaldo H. Verdejo Pinochet (QCELP decoder)
* Copyright (c) 2008 Vladimir Voroshilov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -120,8 +120,8 @@ void ff_acelp_lsp2lpc(int16_t* lp, const int16_t* lsp, int lp_half_order)
void ff_amrwb_lsp2lpc(const double *lsp, float *lp, int lp_order)
{
int lp_half_order = lp_order >> 1;
- double buf[lp_half_order + 1];
- double pa[lp_half_order + 1];
+ double buf[MAX_LP_HALF_ORDER + 1];
+ double pa[MAX_LP_HALF_ORDER + 1];
double *qa = buf + 1;
int i,j;
diff --git a/libavcodec/lsp.h b/libavcodec/lsp.h
index 3648ec74e5..46a2d47beb 100644
--- a/libavcodec/lsp.h
+++ b/libavcodec/lsp.h
@@ -3,20 +3,20 @@
*
* Copyright (c) 2008 Vladimir Voroshilov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -91,7 +91,7 @@ void ff_amrwb_lsp2lpc(const double *lsp, float *lp, int lp_order);
void ff_acelp_lp_decode(int16_t* lp_1st, int16_t* lp_2nd, const int16_t* lsp_2nd, const int16_t* lsp_prev, int lp_order);
-#define MAX_LP_HALF_ORDER 8
+#define MAX_LP_HALF_ORDER 10
#define MAX_LP_ORDER (2*MAX_LP_HALF_ORDER)
/**
diff --git a/libavcodec/lzw.c b/libavcodec/lzw.c
index 6129429053..185a05d6ab 100644
--- a/libavcodec/lzw.c
+++ b/libavcodec/lzw.c
@@ -3,20 +3,20 @@
* Copyright (c) 2003 Fabrice Bellard
* Copyright (c) 2006 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -24,7 +24,7 @@
* @file
* @brief LZW decoding routines
* @author Fabrice Bellard
- * Modified for use in TIFF by Konstantin Shishkov
+ * @author modified for use in TIFF by Konstantin Shishkov
*/
#include "avcodec.h"
diff --git a/libavcodec/lzw.h b/libavcodec/lzw.h
index d1efdaf131..115ca4edb4 100644
--- a/libavcodec/lzw.h
+++ b/libavcodec/lzw.h
@@ -3,20 +3,20 @@
* Copyright (c) 2003 Fabrice Bellard
* Copyright (c) 2006 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -24,7 +24,7 @@
* @file
* @brief LZW decoding routines
* @author Fabrice Bellard
- * Modified for use in TIFF by Konstantin Shishkov
+ * @author modified for use in TIFF by Konstantin Shishkov
*/
#ifndef AVCODEC_LZW_H
diff --git a/libavcodec/lzwenc.c b/libavcodec/lzwenc.c
index df38116c0d..0757d02ab4 100644
--- a/libavcodec/lzwenc.c
+++ b/libavcodec/lzwenc.c
@@ -2,26 +2,26 @@
* LZW encoder
* Copyright (c) 2007 Bartlomiej Wolowiec
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
- * LZW encoder
* @file
+ * LZW encoder
* @author Bartlomiej Wolowiec
*/
diff --git a/libavcodec/mace.c b/libavcodec/mace.c
index 53ec0560dd..9f8749110e 100644
--- a/libavcodec/mace.c
+++ b/libavcodec/mace.c
@@ -2,20 +2,20 @@
* MACE decoder
* Copyright (c) 2002 Laszlo Torok <torokl@alpha.dfmk.hu>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -280,26 +280,22 @@ static int mace_decode_frame(AVCodecContext *avctx,
}
AVCodec ff_mace3_decoder = {
- "mace3",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_MACE3,
- sizeof(MACEContext),
- mace_decode_init,
- NULL,
- NULL,
- mace_decode_frame,
+ .name = "mace3",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_MACE3,
+ .priv_data_size = sizeof(MACEContext),
+ .init = mace_decode_init,
+ .decode = mace_decode_frame,
.long_name = NULL_IF_CONFIG_SMALL("MACE (Macintosh Audio Compression/Expansion) 3:1"),
};
AVCodec ff_mace6_decoder = {
- "mace6",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_MACE6,
- sizeof(MACEContext),
- mace_decode_init,
- NULL,
- NULL,
- mace_decode_frame,
+ .name = "mace6",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_MACE6,
+ .priv_data_size = sizeof(MACEContext),
+ .init = mace_decode_init,
+ .decode = mace_decode_frame,
.long_name = NULL_IF_CONFIG_SMALL("MACE (Macintosh Audio Compression/Expansion) 6:1"),
};
diff --git a/libavcodec/mathops.h b/libavcodec/mathops.h
index ec76eaae29..1126ba6043 100644
--- a/libavcodec/mathops.h
+++ b/libavcodec/mathops.h
@@ -3,20 +3,20 @@
* Copyright (c) 2001, 2002 Fabrice Bellard
* Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at> et al
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVCODEC_MATHOPS_H
@@ -116,7 +116,9 @@ static inline av_const int mid_pred(int a, int b, int c)
#ifndef sign_extend
static inline av_const int sign_extend(int val, unsigned bits)
{
- return (val << ((8 * sizeof(int)) - bits)) >> ((8 * sizeof(int)) - bits);
+ unsigned shift = 8 * sizeof(int) - bits;
+ union { unsigned u; int s; } v = { (unsigned) val << shift };
+ return v.s >> shift;
}
#endif
diff --git a/libavcodec/mdct.c b/libavcodec/mdct.c
index 6f64534273..22320240de 100644
--- a/libavcodec/mdct.c
+++ b/libavcodec/mdct.c
@@ -2,20 +2,20 @@
* MDCT/IMDCT transforms
* Copyright (c) 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/mdct_fixed.c b/libavcodec/mdct_fixed.c
index 94527f9e85..794a3e0bc2 100644
--- a/libavcodec/mdct_fixed.c
+++ b/libavcodec/mdct_fixed.c
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/mdct_float.c b/libavcodec/mdct_float.c
index e4f5549cb7..ec4f486f19 100644
--- a/libavcodec/mdct_float.c
+++ b/libavcodec/mdct_float.c
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/mdec.c b/libavcodec/mdec.c
index 02b69d045a..cf606935a6 100644
--- a/libavcodec/mdec.c
+++ b/libavcodec/mdec.c
@@ -4,20 +4,20 @@
*
* based upon code from Sebastian Jedruszkiewicz <elf@frogger.rules.pl>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -219,6 +219,7 @@ static av_cold void mdec_common_init(AVCodecContext *avctx){
a->mb_width = (avctx->coded_width + 15) / 16;
a->mb_height = (avctx->coded_height + 15) / 16;
+ avcodec_get_frame_defaults(&a->picture);
avctx->coded_frame= &a->picture;
a->avctx= avctx;
}
@@ -244,14 +245,15 @@ static av_cold int decode_init_thread_copy(AVCodecContext *avctx){
MDECContext * const a = avctx->priv_data;
AVFrame *p = (AVFrame*)&a->picture;
- avctx->coded_frame = p;
+ avctx->coded_frame= p;
a->avctx= avctx;
- p->qscale_table = av_mallocz( a->mb_width);
+ p->qscale_table= av_mallocz(a->mb_width);
return 0;
}
+
static av_cold int decode_end(AVCodecContext *avctx){
MDECContext * const a = avctx->priv_data;
@@ -265,15 +267,14 @@ static av_cold int decode_end(AVCodecContext *avctx){
}
AVCodec ff_mdec_decoder = {
- "mdec",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_MDEC,
- sizeof(MDECContext),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- CODEC_CAP_DR1 | CODEC_CAP_FRAME_THREADS,
+ .name = "mdec",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_MDEC,
+ .priv_data_size = sizeof(MDECContext),
+ .init = decode_init,
+ .close = decode_end,
+ .decode = decode_frame,
+ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_FRAME_THREADS,
.long_name= NULL_IF_CONFIG_SMALL("Sony PlayStation MDEC (Motion DECoder)"),
.init_thread_copy= ONLY_IF_THREADS_ENABLED(decode_init_thread_copy)
};
diff --git a/libavcodec/mimic.c b/libavcodec/mimic.c
index 46497ec76c..1deed0b87f 100644
--- a/libavcodec/mimic.c
+++ b/libavcodec/mimic.c
@@ -2,20 +2,20 @@
* Copyright (C) 2005 Ole André Vadla Ravnås <oleavr@gmail.com>
* Copyright (C) 2008 Ramiro Polla
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -209,7 +209,7 @@ static int vlc_decode_block(MimicContext *ctx, int num_coeffs, int qscale)
value = get_bits(&ctx->gb, num_bits);
- /* Libav's IDCT behaves somewhat different from the original code, so
+ /* FFmpeg's IDCT behaves somewhat different from the original code, so
* a factor of 4 was added to the input */
coeff = vlcdec_lookup[num_bits][value];
@@ -416,15 +416,14 @@ static av_cold int mimic_decode_end(AVCodecContext *avctx)
}
AVCodec ff_mimic_decoder = {
- "mimic",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_MIMIC,
- sizeof(MimicContext),
- mimic_decode_init,
- NULL,
- mimic_decode_end,
- mimic_decode_frame,
- CODEC_CAP_DR1 | CODEC_CAP_FRAME_THREADS,
+ .name = "mimic",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_MIMIC,
+ .priv_data_size = sizeof(MimicContext),
+ .init = mimic_decode_init,
+ .close = mimic_decode_end,
+ .decode = mimic_decode_frame,
+ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_FRAME_THREADS,
.long_name = NULL_IF_CONFIG_SMALL("Mimic"),
.update_thread_context = ONLY_IF_THREADS_ENABLED(mimic_decode_update_thread_context)
};
diff --git a/libavcodec/mips/mathops.h b/libavcodec/mips/mathops.h
index 573745b291..b58361f74d 100644
--- a/libavcodec/mips/mathops.h
+++ b/libavcodec/mips/mathops.h
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2009 Mans Rullgard <mans@mansr.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/mjpeg.c b/libavcodec/mjpeg.c
index 9f2d50fa05..6eba27da0b 100644
--- a/libavcodec/mjpeg.c
+++ b/libavcodec/mjpeg.c
@@ -8,20 +8,20 @@
* aspecting, new decode_frame mechanism and apple mjpeg-b support
* by Alex Beregszaszi
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/mjpeg.h b/libavcodec/mjpeg.h
index c3fde4432c..3c88471bab 100644
--- a/libavcodec/mjpeg.h
+++ b/libavcodec/mjpeg.h
@@ -8,20 +8,20 @@
* aspecting, new decode_frame mechanism and apple mjpeg-b support
* by Alex Beregszaszi
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/mjpeg2jpeg_bsf.c b/libavcodec/mjpeg2jpeg_bsf.c
index 335a73bf54..855f24add3 100644
--- a/libavcodec/mjpeg2jpeg_bsf.c
+++ b/libavcodec/mjpeg2jpeg_bsf.c
@@ -2,20 +2,20 @@
* MJPEG/AVI1 to JPEG/JFIF bitstream format filter
* Copyright (c) 2010 Adrian Daerr and Nicolas George
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/mjpeg_parser.c b/libavcodec/mjpeg_parser.c
index b5282f17c4..0cc355db5c 100644
--- a/libavcodec/mjpeg_parser.c
+++ b/libavcodec/mjpeg_parser.c
@@ -4,20 +4,20 @@
* Copyright (c) 2003 Alex Beregszaszi
* Copyright (c) 2003-2004 Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/mjpega_dump_header_bsf.c b/libavcodec/mjpega_dump_header_bsf.c
index 2a181fc386..2e86fd4ef3 100644
--- a/libavcodec/mjpega_dump_header_bsf.c
+++ b/libavcodec/mjpega_dump_header_bsf.c
@@ -2,20 +2,20 @@
* MJPEG A dump header bitstream filter
* Copyright (c) 2006 Baptiste Coudurier
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/mjpegbdec.c b/libavcodec/mjpegbdec.c
index 837304ea74..ff39f71fd7 100644
--- a/libavcodec/mjpegbdec.c
+++ b/libavcodec/mjpegbdec.c
@@ -2,20 +2,20 @@
* Apple MJPEG-B decoder
* Copyright (c) 2002 Alex Beregszaszi
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -81,7 +81,9 @@ read_header:
{
init_get_bits(&s->gb, buf_ptr+dqt_offs, (buf_end - (buf_ptr+dqt_offs))*8);
s->start_code = DQT;
- ff_mjpeg_decode_dqt(s);
+ if (ff_mjpeg_decode_dqt(s) < 0 &&
+ avctx->error_recognition >= FF_ER_EXPLODE)
+ return AVERROR_INVALIDDATA;
}
dht_offs = read_offs(avctx, &hgb, buf_end - buf_ptr, "dht is %d and size is %d\n");
@@ -113,7 +115,9 @@ read_header:
init_get_bits(&s->gb, buf_ptr+sos_offs, field_size*8);
s->mjpb_skiptosod = (sod_offs - sos_offs - show_bits(&s->gb, 16));
s->start_code = SOS;
- ff_mjpeg_decode_sos(s, NULL, NULL);
+ if (ff_mjpeg_decode_sos(s, NULL, NULL) < 0 &&
+ avctx->error_recognition >= FF_ER_EXPLODE)
+ return AVERROR_INVALIDDATA;
}
if (s->interlaced) {
@@ -146,16 +150,14 @@ read_header:
}
AVCodec ff_mjpegb_decoder = {
- "mjpegb",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_MJPEGB,
- sizeof(MJpegDecodeContext),
- ff_mjpeg_decode_init,
- NULL,
- ff_mjpeg_decode_end,
- mjpegb_decode_frame,
- CODEC_CAP_DR1,
- NULL,
+ .name = "mjpegb",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_MJPEGB,
+ .priv_data_size = sizeof(MJpegDecodeContext),
+ .init = ff_mjpeg_decode_init,
+ .close = ff_mjpeg_decode_end,
+ .decode = mjpegb_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.max_lowres = 3,
.long_name = NULL_IF_CONFIG_SMALL("Apple MJPEG-B"),
};
diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
index 4684190e08..944b2eb975 100644
--- a/libavcodec/mjpegdec.c
+++ b/libavcodec/mjpegdec.c
@@ -8,20 +8,20 @@
* aspecting, new decode_frame mechanism and apple mjpeg-b support
* by Alex Beregszaszi
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -34,6 +34,8 @@
#include <assert.h>
#include "libavutil/imgutils.h"
+#include "libavutil/avassert.h"
+#include "libavutil/opt.h"
#include "avcodec.h"
#include "dsputil.h"
#include "mjpeg.h"
@@ -83,6 +85,7 @@ av_cold int ff_mjpeg_decode_init(AVCodecContext *avctx)
if (!s->picture_ptr)
s->picture_ptr = &s->picture;
+ avcodec_get_frame_defaults(&s->picture);
s->avctx = avctx;
dsputil_init(&s->dsp, avctx);
@@ -96,7 +99,11 @@ av_cold int ff_mjpeg_decode_init(AVCodecContext *avctx)
build_basic_mjpeg_vlc(s);
+#if FF_API_MJPEG_GLOBAL_OPTS
if (avctx->flags & CODEC_FLAG_EXTERN_HUFF)
+ s->extern_huff = 1;
+#endif
+ if (s->extern_huff)
{
av_log(avctx, AV_LOG_INFO, "mjpeg: using external huffman table\n");
init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size*8);
@@ -212,6 +219,8 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s)
{
int len, nb_components, i, width, height, pix_fmt_id;
+ s->cur_scan = 0;
+
/* XXX: verify len field validity */
len = get_bits(&s->gb, 16);
s->bits= get_bits(&s->gb, 8);
@@ -316,8 +325,10 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s)
case 0x11111100:
if(s->rgb){
s->avctx->pix_fmt = PIX_FMT_BGRA;
- }else
+ }else{
s->avctx->pix_fmt = s->cs_itu601 ? PIX_FMT_YUV444P : PIX_FMT_YUVJ444P;
+ s->avctx->color_range = s->cs_itu601 ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG;
+ }
assert(s->nb_components==3);
break;
case 0x11000000:
@@ -325,12 +336,15 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s)
break;
case 0x12111100:
s->avctx->pix_fmt = s->cs_itu601 ? PIX_FMT_YUV440P : PIX_FMT_YUVJ440P;
+ s->avctx->color_range = s->cs_itu601 ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG;
break;
case 0x21111100:
s->avctx->pix_fmt = s->cs_itu601 ? PIX_FMT_YUV422P : PIX_FMT_YUVJ422P;
+ s->avctx->color_range = s->cs_itu601 ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG;
break;
case 0x22111100:
s->avctx->pix_fmt = s->cs_itu601 ? PIX_FMT_YUV420P : PIX_FMT_YUVJ420P;
+ s->avctx->color_range = s->cs_itu601 ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG;
break;
default:
av_log(s->avctx, AV_LOG_ERROR, "Unhandled pixel format 0x%x\n", pix_fmt_id);
@@ -637,7 +651,7 @@ static int ljpeg_decode_rgb_scan(MJpegDecodeContext *s, int predictor, int point
}
for(mb_y = 0; mb_y < s->mb_height; mb_y++) {
const int modified_predictor= mb_y ? predictor : 1;
- uint8_t *ptr = s->picture_ptr->data[0] + (linesize * mb_y);
+ uint8_t *ptr = s->picture.data[0] + (linesize * mb_y);
if (s->interlaced && s->bottom_field)
ptr += linesize >> 1;
@@ -714,7 +728,7 @@ static int ljpeg_decode_yuv_scan(MJpegDecodeContext *s, int predictor, int point
for(j=0; j<n; j++) {
int pred;
- ptr = s->picture_ptr->data[c] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap
+ ptr = s->picture.data[c] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap
if(y==0 && mb_y==0){
if(x==0 && mb_x==0){
pred= 128 << point_transform;
@@ -754,7 +768,7 @@ static int ljpeg_decode_yuv_scan(MJpegDecodeContext *s, int predictor, int point
for(j=0; j<n; j++) {
int pred;
- ptr = s->picture_ptr->data[c] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap
+ ptr = s->picture.data[c] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap
PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor);
*ptr= pred + (mjpeg_decode_dc(s, s->dc_index[i]) << point_transform);
if (++x == h) {
@@ -879,54 +893,48 @@ static int mjpeg_decode_scan(MJpegDecodeContext *s, int nb_components, int Ah, i
}
}
- if (s->restart_interval && !--s->restart_count) {
+ if (s->restart_interval) --s->restart_count;
+ i= 8+((-get_bits_count(&s->gb))&7);
+ if (s->restart_interval && show_bits(&s->gb, i) == (1<<i)-1){ /* skip RSTn */
+ int pos= get_bits_count(&s->gb);
align_get_bits(&s->gb);
- skip_bits(&s->gb, 16); /* skip RSTn */
- for (i=0; i<nb_components; i++) /* reset dc */
- s->last_dc[i] = 1024;
+ while(get_bits_count(&s->gb) < s->gb.size_in_bits && show_bits(&s->gb, 8) == 0xFF)
+ skip_bits(&s->gb, 8);
+ if(get_bits_count(&s->gb) < s->gb.size_in_bits && (get_bits(&s->gb, 8)&0xF8) == 0xD0){
+ for (i=0; i<nb_components; i++) /* reset dc */
+ s->last_dc[i] = 1024;
+ }else{
+ skip_bits_long(&s->gb, pos - get_bits_count(&s->gb));
+ }
}
}
}
return 0;
}
-static int mjpeg_decode_scan_progressive_ac(MJpegDecodeContext *s, int ss, int se, int Ah, int Al,
- const uint8_t *mb_bitmask, const AVFrame *reference){
+static int mjpeg_decode_scan_progressive_ac(MJpegDecodeContext *s, int ss, int se, int Ah, int Al){
int mb_x, mb_y;
int EOBRUN = 0;
int c = s->comp_index[0];
- uint8_t* data = s->picture_ptr->data[c];
- const uint8_t *reference_data = reference ? reference->data[c] : NULL;
+ uint8_t* data = s->picture.data[c];
int linesize = s->linesize[c];
int last_scan = 0;
int16_t *quant_matrix = s->quant_matrixes[ s->quant_index[c] ];
- GetBitContext mb_bitmask_gb;
-
- if (mb_bitmask) {
- init_get_bits(&mb_bitmask_gb, mb_bitmask, s->mb_width*s->mb_height);
- }
if(!Al) {
s->coefs_finished[c] |= (1LL<<(se+1))-(1LL<<ss);
last_scan = !~s->coefs_finished[c];
}
- if(s->interlaced && s->bottom_field) {
- int offset = linesize >> 1;
- data += offset;
- reference_data += offset;
- }
+ if(s->interlaced && s->bottom_field)
+ data += linesize >> 1;
for(mb_y = 0; mb_y < s->mb_height; mb_y++) {
- int block_offset = (mb_y*linesize*8 >> s->avctx->lowres);
- uint8_t *ptr = data + block_offset;
+ uint8_t *ptr = data + (mb_y*linesize*8 >> s->avctx->lowres);
int block_idx = mb_y * s->block_stride[c];
DCTELEM (*block)[64] = &s->blocks[c][block_idx];
uint8_t *last_nnz = &s->last_nnz[c][block_idx];
for(mb_x = 0; mb_x < s->mb_width; mb_x++, block++, last_nnz++) {
- const int copy_mb = mb_bitmask && !get_bits1(&mb_bitmask_gb);
-
- if (!copy_mb) {
int ret;
if(Ah)
ret = decode_block_refinement(s, *block, last_nnz, s->ac_index[0],
@@ -938,15 +946,9 @@ static int mjpeg_decode_scan_progressive_ac(MJpegDecodeContext *s, int ss, int s
av_log(s->avctx, AV_LOG_ERROR, "error y=%d x=%d\n", mb_y, mb_x);
return -1;
}
- }
-
if(last_scan) {
- if (copy_mb) {
- mjpeg_copy_block(ptr, reference_data + block_offset, linesize, s->avctx->lowres);
- } else {
s->dsp.idct_put(ptr, linesize, *block);
ptr += 8 >> s->avctx->lowres;
- }
}
}
}
@@ -1008,8 +1010,11 @@ int ff_mjpeg_decode_sos(MJpegDecodeContext *s,
predictor= get_bits(&s->gb, 8); /* JPEG Ss / lossless JPEG predictor /JPEG-LS NEAR */
ilv= get_bits(&s->gb, 8); /* JPEG Se / JPEG-LS ILV */
- prev_shift = get_bits(&s->gb, 4); /* Ah */
- point_transform= get_bits(&s->gb, 4); /* Al */
+ if(s->avctx->codec_tag != AV_RL32("CJPG")){
+ prev_shift = get_bits(&s->gb, 4); /* Ah */
+ point_transform= get_bits(&s->gb, 4); /* Al */
+ }else
+ prev_shift= point_transform= 0;
for(i=0;i<nb_components;i++)
s->last_dc[i] = 1024;
@@ -1029,9 +1034,9 @@ int ff_mjpeg_decode_sos(MJpegDecodeContext *s,
}
if(s->avctx->debug & FF_DEBUG_PICT_INFO)
- av_log(s->avctx, AV_LOG_DEBUG, "%s %s p:%d >>:%d ilv:%d bits:%d %s\n", s->lossless ? "lossless" : "sequential DCT", s->rgb ? "RGB" : "",
- predictor, point_transform, ilv, s->bits,
- s->pegasus_rct ? "PRCT" : (s->rct ? "RCT" : ""));
+ av_log(s->avctx, AV_LOG_DEBUG, "%s %s p:%d >>:%d ilv:%d bits:%d skip:%d %s comp:%d\n", s->lossless ? "lossless" : "sequential DCT", s->rgb ? "RGB" : "",
+ predictor, point_transform, ilv, s->bits, s->mjpb_skiptosod,
+ s->pegasus_rct ? "PRCT" : (s->rct ? "RCT" : ""), nb_components);
/* mjpeg-b can have padding bytes between sos and image data, skip them */
@@ -1039,6 +1044,7 @@ int ff_mjpeg_decode_sos(MJpegDecodeContext *s,
skip_bits(&s->gb, 8);
if(s->lossless){
+ av_assert0(s->picture_ptr == &s->picture);
if(CONFIG_JPEGLS_DECODER && s->ls){
// for(){
// reset_ls_coding_parameters(s, 0);
@@ -1056,8 +1062,8 @@ int ff_mjpeg_decode_sos(MJpegDecodeContext *s,
}
}else{
if(s->progressive && predictor) {
- if(mjpeg_decode_scan_progressive_ac(s, predictor, ilv, prev_shift, point_transform,
- mb_bitmask, reference) < 0)
+ av_assert0(s->picture_ptr == &s->picture);
+ if(mjpeg_decode_scan_progressive_ac(s, predictor, ilv, prev_shift, point_transform) < 0)
return -1;
} else {
if(mjpeg_decode_scan(s, nb_components, prev_shift, point_transform,
@@ -1116,9 +1122,8 @@ static int mjpeg_decode_app(MJpegDecodeContext *s)
s->buggy_avid = 1;
// if (s->first_picture)
// printf("mjpeg: workarounding buggy AVID\n");
- i = get_bits(&s->gb, 8);
- if (i==2) s->bottom_field= 1;
- else if(i==1) s->bottom_field= 0;
+ i = get_bits(&s->gb, 8); len--;
+ av_log(s->avctx, AV_LOG_DEBUG, "polarity %d\n", i);
#if 0
skip_bits(&s->gb, 8);
skip_bits(&s->gb, 32);
@@ -1269,29 +1274,6 @@ static int mjpeg_decode_com(MJpegDecodeContext *s)
return 0;
}
-#if 0
-static int valid_marker_list[] =
-{
- /* 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f */
-/* 0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-/* 1 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-/* 2 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-/* 3 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-/* 4 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-/* 5 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-/* 6 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-/* 7 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-/* 8 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-/* 9 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-/* a */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-/* b */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-/* c */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-/* d */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-/* e */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-/* f */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
-}
-#endif
-
/* return the 8 bit start code value and update the search
state. Return -1 if no start code found */
static int find_marker(const uint8_t **pbuf_ptr, const uint8_t *buf_end)
@@ -1299,9 +1281,7 @@ static int find_marker(const uint8_t **pbuf_ptr, const uint8_t *buf_end)
const uint8_t *buf_ptr;
unsigned int v, v2;
int val;
-#ifdef DEBUG
int skipped=0;
-#endif
buf_ptr = *pbuf_ptr;
while (buf_ptr < buf_end) {
@@ -1311,9 +1291,7 @@ static int find_marker(const uint8_t **pbuf_ptr, const uint8_t *buf_end)
val = *buf_ptr++;
goto found;
}
-#ifdef DEBUG
skipped++;
-#endif
}
val = -1;
found:
@@ -1512,10 +1490,8 @@ int ff_mjpeg_decode_frame(AVCodecContext *avctx,
return -1;
break;
case EOI:
- s->cur_scan = 0;
- if ((s->buggy_avid && !s->interlaced) || s->restart_interval)
- break;
eoi_parser:
+ s->cur_scan = 0;
if (!s->got_picture) {
av_log(avctx, AV_LOG_WARNING, "Found EOI before any SOF, ignoring\n");
break;
@@ -1524,7 +1500,7 @@ eoi_parser:
s->bottom_field ^= 1;
/* if not bottom field, do not output image yet */
if (s->bottom_field == !s->interlace_polarity)
- goto not_the_end;
+ break;
}
*picture = *s->picture_ptr;
*data_size = sizeof(AVFrame);
@@ -1545,11 +1521,9 @@ eoi_parser:
av_log(avctx, AV_LOG_WARNING, "Can not process SOS before SOF, skipping\n");
break;
}
- ff_mjpeg_decode_sos(s, NULL, NULL);
- /* buggy avid puts EOI every 10-20th frame */
- /* if restart period is over process EOI */
- if ((s->buggy_avid && !s->interlaced) || s->restart_interval)
- goto eoi_parser;
+ if (ff_mjpeg_decode_sos(s, NULL, NULL) < 0 &&
+ avctx->error_recognition >= FF_ER_EXPLODE)
+ return AVERROR_INVALIDDATA;
break;
case DRI:
mjpeg_decode_dri(s);
@@ -1571,7 +1545,6 @@ eoi_parser:
// break;
}
-not_the_end:
/* eof process start code */
buf_ptr += (get_bits_count(&s->gb)+7)/8;
av_log(avctx, AV_LOG_DEBUG, "marker parser used %d bytes (%d bits)\n",
@@ -1615,32 +1588,43 @@ av_cold int ff_mjpeg_decode_end(AVCodecContext *avctx)
return 0;
}
+#define OFFSET(x) offsetof(MJpegDecodeContext, x)
+#define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
+static const AVOption options[] = {
+ { "extern_huff", "Use external huffman table.", OFFSET(extern_huff), AV_OPT_TYPE_INT, { 0 }, 0, 1, VD },
+ { NULL },
+};
+
+static const AVClass mjpegdec_class = {
+ .class_name = "MJPEG decoder",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
AVCodec ff_mjpeg_decoder = {
- "mjpeg",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_MJPEG,
- sizeof(MJpegDecodeContext),
- ff_mjpeg_decode_init,
- NULL,
- ff_mjpeg_decode_end,
- ff_mjpeg_decode_frame,
- CODEC_CAP_DR1,
- NULL,
+ .name = "mjpeg",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_MJPEG,
+ .priv_data_size = sizeof(MJpegDecodeContext),
+ .init = ff_mjpeg_decode_init,
+ .close = ff_mjpeg_decode_end,
+ .decode = ff_mjpeg_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.max_lowres = 3,
.long_name = NULL_IF_CONFIG_SMALL("MJPEG (Motion JPEG)"),
+ .priv_class = &mjpegdec_class,
};
AVCodec ff_thp_decoder = {
- "thp",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_THP,
- sizeof(MJpegDecodeContext),
- ff_mjpeg_decode_init,
- NULL,
- ff_mjpeg_decode_end,
- ff_mjpeg_decode_frame,
- CODEC_CAP_DR1,
- NULL,
+ .name = "thp",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_THP,
+ .priv_data_size = sizeof(MJpegDecodeContext),
+ .init = ff_mjpeg_decode_init,
+ .close = ff_mjpeg_decode_end,
+ .decode = ff_mjpeg_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.max_lowres = 3,
.long_name = NULL_IF_CONFIG_SMALL("Nintendo Gamecube THP video"),
};
diff --git a/libavcodec/mjpegdec.h b/libavcodec/mjpegdec.h
index 52c256ee2f..d88ba7b544 100644
--- a/libavcodec/mjpegdec.h
+++ b/libavcodec/mjpegdec.h
@@ -4,20 +4,20 @@
* Copyright (c) 2003 Alex Beregszaszi
* Copyright (c) 2003-2004 Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -29,6 +29,8 @@
#ifndef AVCODEC_MJPEGDEC_H
#define AVCODEC_MJPEGDEC_H
+#include "libavutil/log.h"
+
#include "avcodec.h"
#include "get_bits.h"
#include "dsputil.h"
@@ -36,6 +38,7 @@
#define MAX_COMPONENTS 4
typedef struct MJpegDecodeContext {
+ AVClass *class;
AVCodecContext *avctx;
GetBitContext gb;
@@ -106,6 +109,8 @@ typedef struct MJpegDecodeContext {
uint16_t (*ljpeg_buffer)[4];
unsigned int ljpeg_buffer_size;
+
+ int extern_huff;
} MJpegDecodeContext;
int ff_mjpeg_decode_init(AVCodecContext *avctx);
diff --git a/libavcodec/mjpegenc.c b/libavcodec/mjpegenc.c
index 169d19e17a..228b616f65 100644
--- a/libavcodec/mjpegenc.c
+++ b/libavcodec/mjpegenc.c
@@ -8,20 +8,20 @@
* aspecting, new decode_frame mechanism and apple mjpeg-b support
* by Alex Beregszaszi
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -156,13 +156,13 @@ static void jpeg_put_comments(MpegEncContext *s)
int size;
uint8_t *ptr;
- if (s->aspect_ratio_info /* && !lossless */)
+ if (s->avctx->sample_aspect_ratio.num /* && !lossless */)
{
/* JFIF header */
put_marker(p, APP0);
put_bits(p, 16, 16);
ff_put_string(p, "JFIF", 1); /* this puts the trailing zero-byte too */
- put_bits(p, 16, 0x0201); /* v 1.02 */
+ put_bits(p, 16, 0x0102); /* v 1.02 */
put_bits(p, 8, 0); /* units type: 0 - aspect ratio */
put_bits(p, 16, s->avctx->sample_aspect_ratio.num);
put_bits(p, 16, s->avctx->sample_aspect_ratio.den);
@@ -200,6 +200,9 @@ void ff_mjpeg_encode_picture_header(MpegEncContext *s)
put_marker(&s->pb, SOI);
+ // hack for AMV mjpeg format
+ if(s->avctx->codec_id == CODEC_ID_AMV) return;
+
jpeg_put_comments(s);
jpeg_table_header(s);
@@ -445,14 +448,47 @@ void ff_mjpeg_encode_mb(MpegEncContext *s, DCTELEM block[6][64])
s->i_tex_bits += get_bits_diff(s);
}
+// maximum over s->mjpeg_vsample[i]
+#define V_MAX 2
+static int amv_encode_picture(AVCodecContext *avctx,
+ unsigned char *buf, int buf_size, void *data)
+{
+
+ AVFrame* pic=data;
+ MpegEncContext *s = avctx->priv_data;
+ int i;
+
+ //CODEC_FLAG_EMU_EDGE have to be cleared
+ if(s->avctx->flags & CODEC_FLAG_EMU_EDGE)
+ return -1;
+
+ //picture should be flipped upside-down
+ for(i=0; i < 3; i++) {
+ pic->data[i] += (pic->linesize[i] * (s->mjpeg_vsample[i] * (8 * s->mb_height -((s->height/V_MAX)&7)) - 1 ));
+ pic->linesize[i] *= -1;
+ }
+ return MPV_encode_picture(avctx,buf, buf_size, pic);
+}
+
AVCodec ff_mjpeg_encoder = {
- "mjpeg",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_MJPEG,
- sizeof(MpegEncContext),
- MPV_encode_init,
- MPV_encode_picture,
- MPV_encode_end,
+ .name = "mjpeg",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_MJPEG,
+ .priv_data_size = sizeof(MpegEncContext),
+ .init = MPV_encode_init,
+ .encode = MPV_encode_picture,
+ .close = MPV_encode_end,
.pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUVJ420P, PIX_FMT_YUVJ422P, PIX_FMT_NONE},
.long_name= NULL_IF_CONFIG_SMALL("MJPEG (Motion JPEG)"),
};
+
+AVCodec ff_amv_encoder = {
+ .name = "amv",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_AMV,
+ .priv_data_size = sizeof(MpegEncContext),
+ .init = MPV_encode_init,
+ .encode = amv_encode_picture,
+ .close = MPV_encode_end,
+ .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUVJ420P, PIX_FMT_YUVJ422P, -1},
+};
diff --git a/libavcodec/mjpegenc.h b/libavcodec/mjpegenc.h
index 12ff54055e..49627a3d55 100644
--- a/libavcodec/mjpegenc.h
+++ b/libavcodec/mjpegenc.h
@@ -8,20 +8,20 @@
* aspecting, new decode_frame mechanism and apple mjpeg-b support
* by Alex Beregszaszi
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/mlib/dsputil_mlib.c b/libavcodec/mlib/dsputil_mlib.c
index c0f2c036c6..b5594a9a03 100644
--- a/libavcodec/mlib/dsputil_mlib.c
+++ b/libavcodec/mlib/dsputil_mlib.c
@@ -2,20 +2,20 @@
* Sun mediaLib optimized DSP utils
* Copyright (c) 2001 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -421,13 +421,14 @@ static void ff_fdct_mlib(DCTELEM *data)
void dsputil_init_mlib(DSPContext* c, AVCodecContext *avctx)
{
- const int high_bit_depth = avctx->codec_id == CODEC_ID_H264 && avctx->bits_per_raw_sample > 8;
+ const int high_bit_depth = avctx->bits_per_raw_sample > 8;
- c->get_pixels = get_pixels_mlib;
c->diff_pixels = diff_pixels_mlib;
c->add_pixels_clamped = add_pixels_clamped_mlib;
if (!high_bit_depth) {
+ c->get_pixels = get_pixels_mlib;
+
c->put_pixels_tab[0][0] = put_pixels16_mlib;
c->put_pixels_tab[0][1] = put_pixels16_x2_mlib;
c->put_pixels_tab[0][2] = put_pixels16_y2_mlib;
diff --git a/libavcodec/mlp.c b/libavcodec/mlp.c
index 9615b66ee1..87f7c77139 100644
--- a/libavcodec/mlp.c
+++ b/libavcodec/mlp.c
@@ -2,20 +2,20 @@
* MLP codec common code
* Copyright (c) 2007-2008 Ian Caulfield
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/mlp.h b/libavcodec/mlp.h
index b001ad270d..628b58d318 100644
--- a/libavcodec/mlp.h
+++ b/libavcodec/mlp.h
@@ -2,20 +2,20 @@
* MLP codec common header file
* Copyright (c) 2007-2008 Ian Caulfield
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/mlp_parser.c b/libavcodec/mlp_parser.c
index e85eb72c38..abd3ffa8e7 100644
--- a/libavcodec/mlp_parser.c
+++ b/libavcodec/mlp_parser.c
@@ -2,20 +2,20 @@
* MLP parser
* Copyright (c) 2007 Ian Caulfield
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -43,28 +43,28 @@ static const uint8_t mlp_channels[32] = {
5, 6, 5, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
-static const uint64_t mlp_layout[32] = {
+const uint64_t ff_mlp_layout[32] = {
AV_CH_LAYOUT_MONO,
AV_CH_LAYOUT_STEREO,
AV_CH_LAYOUT_2_1,
- AV_CH_LAYOUT_2_2,
+ AV_CH_LAYOUT_QUAD,
AV_CH_LAYOUT_STEREO|AV_CH_LOW_FREQUENCY,
AV_CH_LAYOUT_2_1|AV_CH_LOW_FREQUENCY,
- AV_CH_LAYOUT_2_2|AV_CH_LOW_FREQUENCY,
+ AV_CH_LAYOUT_QUAD|AV_CH_LOW_FREQUENCY,
AV_CH_LAYOUT_SURROUND,
AV_CH_LAYOUT_4POINT0,
- AV_CH_LAYOUT_5POINT0,
+ AV_CH_LAYOUT_5POINT0_BACK,
AV_CH_LAYOUT_SURROUND|AV_CH_LOW_FREQUENCY,
AV_CH_LAYOUT_4POINT0|AV_CH_LOW_FREQUENCY,
- AV_CH_LAYOUT_5POINT1,
+ AV_CH_LAYOUT_5POINT1_BACK,
AV_CH_LAYOUT_4POINT0,
- AV_CH_LAYOUT_5POINT0,
+ AV_CH_LAYOUT_5POINT0_BACK,
AV_CH_LAYOUT_SURROUND|AV_CH_LOW_FREQUENCY,
AV_CH_LAYOUT_4POINT0|AV_CH_LOW_FREQUENCY,
- AV_CH_LAYOUT_5POINT1,
- AV_CH_LAYOUT_2_2|AV_CH_LOW_FREQUENCY,
- AV_CH_LAYOUT_5POINT0,
- AV_CH_LAYOUT_5POINT1,
+ AV_CH_LAYOUT_5POINT1_BACK,
+ AV_CH_LAYOUT_QUAD|AV_CH_LOW_FREQUENCY,
+ AV_CH_LAYOUT_5POINT0_BACK,
+ AV_CH_LAYOUT_5POINT1_BACK,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
@@ -107,7 +107,7 @@ static int truehd_channels(int chanmap)
return channels;
}
-static int64_t truehd_layout(int chanmap)
+int64_t ff_truehd_layout(int chanmap)
{
int layout = 0, i;
@@ -138,11 +138,11 @@ int ff_mlp_read_major_sync(void *log, MLPHeaderInfo *mh, GetBitContext *gb)
checksum = ff_mlp_checksum16(gb->buffer, 26);
if (checksum != AV_RL16(gb->buffer+26)) {
av_log(log, AV_LOG_ERROR, "major sync info header checksum error\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
if (get_bits_long(gb, 24) != 0xf8726f) /* Sync words */
- return -1;
+ return AVERROR_INVALIDDATA;
mh->stream_type = get_bits(gb, 8);
@@ -173,7 +173,7 @@ int ff_mlp_read_major_sync(void *log, MLPHeaderInfo *mh, GetBitContext *gb)
mh->channels_thd_stream2 = get_bits(gb, 13);
} else
- return -1;
+ return AVERROR_INVALIDDATA;
mh->access_unit_size = 40 << (ratebits & 7);
mh->access_unit_size_pow2 = 64 << (ratebits & 7);
@@ -316,15 +316,15 @@ static int mlp_parse(AVCodecParserContext *s,
if (mh.stream_type == 0xbb) {
/* MLP stream */
avctx->channels = mlp_channels[mh.channels_mlp];
- avctx->channel_layout = mlp_layout[mh.channels_mlp];
+ avctx->channel_layout = ff_mlp_layout[mh.channels_mlp];
} else { /* mh.stream_type == 0xba */
/* TrueHD stream */
if (mh.channels_thd_stream2) {
avctx->channels = truehd_channels(mh.channels_thd_stream2);
- avctx->channel_layout = truehd_layout(mh.channels_thd_stream2);
+ avctx->channel_layout = ff_truehd_layout(mh.channels_thd_stream2);
} else {
avctx->channels = truehd_channels(mh.channels_thd_stream1);
- avctx->channel_layout = truehd_layout(mh.channels_thd_stream1);
+ avctx->channel_layout = ff_truehd_layout(mh.channels_thd_stream1);
}
}
diff --git a/libavcodec/mlp_parser.h b/libavcodec/mlp_parser.h
index 940ba838f3..6e43bc38dc 100644
--- a/libavcodec/mlp_parser.h
+++ b/libavcodec/mlp_parser.h
@@ -2,20 +2,20 @@
* MLP parser prototypes
* Copyright (c) 2007 Ian Caulfield
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -54,6 +54,9 @@ typedef struct MLPHeaderInfo
int ff_mlp_read_major_sync(void *log, MLPHeaderInfo *mh, GetBitContext *gb);
+int64_t ff_truehd_layout(int chanmap);
+
+extern const uint64_t ff_mlp_layout[32];
#endif /* AVCODEC_MLP_PARSER_H */
diff --git a/libavcodec/mlpdec.c b/libavcodec/mlpdec.c
index 5e50eba75e..0396423b92 100644
--- a/libavcodec/mlpdec.c
+++ b/libavcodec/mlpdec.c
@@ -2,20 +2,20 @@
* MLP decoder
* Copyright (c) 2007-2008 Ian Caulfield
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -41,7 +41,7 @@
static const char* sample_message =
"Please file a bug report following the instructions at "
- "http://libav.org/bugreports.html and include "
+ "http://ffmpeg.org/bugreports.html and include "
"a sample of this file.";
typedef struct SubStream {
@@ -133,6 +133,9 @@ typedef struct MLPDecodeContext {
//! Index of the last substream to decode - further substreams are skipped.
uint8_t max_decoded_substream;
+ //! Stream needs channel reordering to comply with FFmpeg's channel order
+ uint8_t needs_reordering;
+
//! number of PCM samples contained in each frame
int access_unit_size;
//! next power of two above the number of samples in each frame
@@ -214,7 +217,7 @@ static inline int read_huff_channels(MLPDecodeContext *m, GetBitContext *gbp,
VLC_BITS, (9 + VLC_BITS - 1) / VLC_BITS);
if (result < 0)
- return -1;
+ return AVERROR_INVALIDDATA;
if (lsb_bits > 0)
result = (result << lsb_bits) + get_bits(gbp, lsb_bits);
@@ -250,61 +253,61 @@ static av_cold int mlp_decode_init(AVCodecContext *avctx)
static int read_major_sync(MLPDecodeContext *m, GetBitContext *gb)
{
MLPHeaderInfo mh;
- int substr;
+ int substr, ret;
- if (ff_mlp_read_major_sync(m->avctx, &mh, gb) != 0)
- return -1;
+ if ((ret = ff_mlp_read_major_sync(m->avctx, &mh, gb)) != 0)
+ return ret;
if (mh.group1_bits == 0) {
av_log(m->avctx, AV_LOG_ERROR, "invalid/unknown bits per sample\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
if (mh.group2_bits > mh.group1_bits) {
av_log(m->avctx, AV_LOG_ERROR,
"Channel group 2 cannot have more bits per sample than group 1.\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
if (mh.group2_samplerate && mh.group2_samplerate != mh.group1_samplerate) {
av_log(m->avctx, AV_LOG_ERROR,
"Channel groups with differing sample rates are not currently supported.\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
if (mh.group1_samplerate == 0) {
av_log(m->avctx, AV_LOG_ERROR, "invalid/unknown sampling rate\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
if (mh.group1_samplerate > MAX_SAMPLERATE) {
av_log(m->avctx, AV_LOG_ERROR,
"Sampling rate %d is greater than the supported maximum (%d).\n",
mh.group1_samplerate, MAX_SAMPLERATE);
- return -1;
+ return AVERROR_INVALIDDATA;
}
if (mh.access_unit_size > MAX_BLOCKSIZE) {
av_log(m->avctx, AV_LOG_ERROR,
"Block size %d is greater than the supported maximum (%d).\n",
mh.access_unit_size, MAX_BLOCKSIZE);
- return -1;
+ return AVERROR_INVALIDDATA;
}
if (mh.access_unit_size_pow2 > MAX_BLOCKSIZE_POW2) {
av_log(m->avctx, AV_LOG_ERROR,
"Block size pow2 %d is greater than the supported maximum (%d).\n",
mh.access_unit_size_pow2, MAX_BLOCKSIZE_POW2);
- return -1;
+ return AVERROR_INVALIDDATA;
}
if (mh.num_substreams == 0)
- return -1;
+ return AVERROR_INVALIDDATA;
if (m->avctx->codec_id == CODEC_ID_MLP && mh.num_substreams > 2) {
av_log(m->avctx, AV_LOG_ERROR, "MLP only supports up to 2 substreams.\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
if (mh.num_substreams > MAX_SUBSTREAMS) {
av_log(m->avctx, AV_LOG_ERROR,
"Number of substreams %d is larger than the maximum supported "
"by the decoder. %s\n", mh.num_substreams, sample_message);
- return -1;
+ return AVERROR_INVALIDDATA;
}
m->access_unit_size = mh.access_unit_size;
@@ -326,6 +329,26 @@ static int read_major_sync(MLPDecodeContext *m, GetBitContext *gb)
for (substr = 0; substr < MAX_SUBSTREAMS; substr++)
m->substream[substr].restart_seen = 0;
+ if (mh.stream_type == 0xbb) {
+ /* MLP stream */
+ m->avctx->channel_layout = ff_mlp_layout[mh.channels_mlp];
+ } else { /* mh.stream_type == 0xba */
+ /* TrueHD stream */
+ if (mh.channels_thd_stream2) {
+ m->avctx->channel_layout = ff_truehd_layout(mh.channels_thd_stream2);
+ } else {
+ m->avctx->channel_layout = ff_truehd_layout(mh.channels_thd_stream1);
+ }
+ if (m->avctx->channels &&
+ !m->avctx->request_channels && !m->avctx->request_channel_layout &&
+ av_get_channel_layout_nb_channels(m->avctx->channel_layout) != m->avctx->channels) {
+ m->avctx->channel_layout = 0;
+ av_log_ask_for_sample(m->avctx, "Unknown channel layout.");
+ }
+ }
+
+ m->needs_reordering = mh.channels_mlp >= 18 && mh.channels_mlp <= 20;
+
return 0;
}
@@ -351,14 +374,14 @@ static int read_restart_header(MLPDecodeContext *m, GetBitContext *gbp,
if (sync_word != 0x31ea >> 1) {
av_log(m->avctx, AV_LOG_ERROR,
"restart header sync incorrect (got 0x%04x)\n", sync_word);
- return -1;
+ return AVERROR_INVALIDDATA;
}
s->noise_type = get_bits1(gbp);
if (m->avctx->codec_id == CODEC_ID_MLP && s->noise_type) {
av_log(m->avctx, AV_LOG_ERROR, "MLP must have 0x31ea sync word.\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
skip_bits(gbp, 16); /* Output timestamp */
@@ -371,13 +394,13 @@ static int read_restart_header(MLPDecodeContext *m, GetBitContext *gbp,
av_log(m->avctx, AV_LOG_ERROR,
"Max matrix channel cannot be greater than %d.\n",
max_matrix_channel);
- return -1;
+ return AVERROR_INVALIDDATA;
}
if (s->max_channel != s->max_matrix_channel) {
av_log(m->avctx, AV_LOG_ERROR,
"Max channel must be equal max matrix channel.\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
/* This should happen for TrueHD streams with >6 channels and MLP's noise
@@ -386,13 +409,13 @@ static int read_restart_header(MLPDecodeContext *m, GetBitContext *gbp,
av_log(m->avctx, AV_LOG_ERROR,
"Number of channels %d is larger than the maximum supported "
"by the decoder. %s\n", s->max_channel+2, sample_message);
- return -1;
+ return AVERROR_INVALIDDATA;
}
if (s->min_channel > s->max_channel) {
av_log(m->avctx, AV_LOG_ERROR,
"Substream min channel cannot be greater than max channel.\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
if (m->avctx->request_channels > 0
@@ -431,11 +454,29 @@ static int read_restart_header(MLPDecodeContext *m, GetBitContext *gbp,
av_log(m->avctx, AV_LOG_ERROR,
"Assignment of matrix channel %d to invalid output channel %d. %s\n",
ch, ch_assign, sample_message);
- return -1;
+ return AVERROR_INVALIDDATA;
}
s->ch_assign[ch_assign] = ch;
}
+ if (m->avctx->codec_id == CODEC_ID_MLP && m->needs_reordering) {
+ if (m->avctx->channel_layout == (AV_CH_LAYOUT_QUAD|AV_CH_LOW_FREQUENCY) ||
+ m->avctx->channel_layout == AV_CH_LAYOUT_5POINT0_BACK) {
+ int i = s->ch_assign[4];
+ s->ch_assign[4] = s->ch_assign[3];
+ s->ch_assign[3] = s->ch_assign[2];
+ s->ch_assign[2] = i;
+ } else if (m->avctx->channel_layout == AV_CH_LAYOUT_5POINT1_BACK) {
+ FFSWAP(int, s->ch_assign[2], s->ch_assign[4]);
+ FFSWAP(int, s->ch_assign[3], s->ch_assign[5]);
+ }
+ }
+ if (m->avctx->codec_id == CODEC_ID_TRUEHD &&
+ m->avctx->channel_layout == AV_CH_LAYOUT_7POINT1) {
+ FFSWAP(int, s->ch_assign[4], s->ch_assign[6]);
+ FFSWAP(int, s->ch_assign[5], s->ch_assign[7]);
+ }
+
checksum = ff_mlp_restart_checksum(buf, get_bits_count(gbp) - start_count);
if (checksum != get_bits(gbp, 8))
@@ -487,7 +528,7 @@ static int read_filter_params(MLPDecodeContext *m, GetBitContext *gbp,
if (m->filter_changed[channel][filter]++ > 1) {
av_log(m->avctx, AV_LOG_ERROR, "Filters may change only once per access unit.\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
order = get_bits(gbp, 4);
@@ -495,7 +536,7 @@ static int read_filter_params(MLPDecodeContext *m, GetBitContext *gbp,
av_log(m->avctx, AV_LOG_ERROR,
"%cIR filter order %d is greater than maximum %d.\n",
fchar, order, max_order);
- return -1;
+ return AVERROR_INVALIDDATA;
}
fp->order = order;
@@ -511,13 +552,13 @@ static int read_filter_params(MLPDecodeContext *m, GetBitContext *gbp,
av_log(m->avctx, AV_LOG_ERROR,
"%cIR filter coeff_bits must be between 1 and 16.\n",
fchar);
- return -1;
+ return AVERROR_INVALIDDATA;
}
if (coeff_bits + coeff_shift > 16) {
av_log(m->avctx, AV_LOG_ERROR,
"Sum of coeff_bits and coeff_shift for %cIR filter must be 16 or less.\n",
fchar);
- return -1;
+ return AVERROR_INVALIDDATA;
}
for (i = 0; i < order; i++)
@@ -529,7 +570,7 @@ static int read_filter_params(MLPDecodeContext *m, GetBitContext *gbp,
if (filter == FIR) {
av_log(m->avctx, AV_LOG_ERROR,
"FIR filter has state data specified.\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
state_bits = get_bits(gbp, 4);
@@ -557,7 +598,7 @@ static int read_matrix_params(MLPDecodeContext *m, unsigned int substr, GetBitCo
if (m->matrix_changed++ > 1) {
av_log(m->avctx, AV_LOG_ERROR, "Matrices may change only once per access unit.\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
s->num_primitive_matrices = get_bits(gbp, 4);
@@ -566,7 +607,7 @@ static int read_matrix_params(MLPDecodeContext *m, unsigned int substr, GetBitCo
av_log(m->avctx, AV_LOG_ERROR,
"Number of primitive matrices cannot be greater than %d.\n",
max_primitive_matrices);
- return -1;
+ return AVERROR_INVALIDDATA;
}
for (mat = 0; mat < s->num_primitive_matrices; mat++) {
@@ -579,12 +620,12 @@ static int read_matrix_params(MLPDecodeContext *m, unsigned int substr, GetBitCo
av_log(m->avctx, AV_LOG_ERROR,
"Invalid channel %d specified as output from matrix.\n",
s->matrix_out_ch[mat]);
- return -1;
+ return AVERROR_INVALIDDATA;
}
if (frac_bits > 14) {
av_log(m->avctx, AV_LOG_ERROR,
"Too many fractional bits specified.\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
max_chan = s->max_matrix_channel;
@@ -617,27 +658,28 @@ static int read_channel_params(MLPDecodeContext *m, unsigned int substr,
ChannelParams *cp = &s->channel_params[ch];
FilterParams *fir = &cp->filter_params[FIR];
FilterParams *iir = &cp->filter_params[IIR];
+ int ret;
if (s->param_presence_flags & PARAM_FIR)
if (get_bits1(gbp))
- if (read_filter_params(m, gbp, substr, ch, FIR) < 0)
- return -1;
+ if ((ret = read_filter_params(m, gbp, substr, ch, FIR)) < 0)
+ return ret;
if (s->param_presence_flags & PARAM_IIR)
if (get_bits1(gbp))
- if (read_filter_params(m, gbp, substr, ch, IIR) < 0)
- return -1;
+ if ((ret = read_filter_params(m, gbp, substr, ch, IIR)) < 0)
+ return ret;
if (fir->order + iir->order > 8) {
av_log(m->avctx, AV_LOG_ERROR, "Total filter orders too high.\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
if (fir->order && iir->order &&
fir->shift != iir->shift) {
av_log(m->avctx, AV_LOG_ERROR,
"FIR and IIR filters must use the same precision.\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
/* The FIR and IIR filters must have the same precision.
* To simplify the filtering code, only the precision of the
@@ -656,7 +698,7 @@ static int read_channel_params(MLPDecodeContext *m, unsigned int substr,
if (cp->huff_lsbs > 24) {
av_log(m->avctx, AV_LOG_ERROR, "Invalid huff_lsbs.\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
cp->sign_huff_offset = calculate_sign_huff(m, substr, ch);
@@ -672,6 +714,7 @@ static int read_decoding_params(MLPDecodeContext *m, GetBitContext *gbp,
{
SubStream *s = &m->substream[substr];
unsigned int ch;
+ int ret;
if (s->param_presence_flags & PARAM_PRESENCE)
if (get_bits1(gbp))
@@ -683,14 +726,14 @@ static int read_decoding_params(MLPDecodeContext *m, GetBitContext *gbp,
if (s->blocksize < 8 || s->blocksize > m->access_unit_size) {
av_log(m->avctx, AV_LOG_ERROR, "Invalid blocksize.");
s->blocksize = 0;
- return -1;
+ return AVERROR_INVALIDDATA;
}
}
if (s->param_presence_flags & PARAM_MATRIX)
if (get_bits1(gbp))
- if (read_matrix_params(m, substr, gbp) < 0)
- return -1;
+ if ((ret = read_matrix_params(m, substr, gbp)) < 0)
+ return ret;
if (s->param_presence_flags & PARAM_OUTSHIFT)
if (get_bits1(gbp))
@@ -709,8 +752,8 @@ static int read_decoding_params(MLPDecodeContext *m, GetBitContext *gbp,
for (ch = s->min_channel; ch <= s->max_channel; ch++)
if (get_bits1(gbp))
- if (read_channel_params(m, substr, gbp, ch) < 0)
- return -1;
+ if ((ret = read_channel_params(m, substr, gbp, ch)) < 0)
+ return ret;
return 0;
}
@@ -752,6 +795,7 @@ static int read_block_data(MLPDecodeContext *m, GetBitContext *gbp,
{
SubStream *s = &m->substream[substr];
unsigned int i, ch, expected_stream_pos = 0;
+ int ret;
if (s->data_check_present) {
expected_stream_pos = get_bits_count(gbp);
@@ -762,15 +806,15 @@ static int read_block_data(MLPDecodeContext *m, GetBitContext *gbp,
if (s->blockpos + s->blocksize > m->access_unit_size) {
av_log(m->avctx, AV_LOG_ERROR, "too many audio samples in frame\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
memset(&m->bypassed_lsbs[s->blockpos][0], 0,
s->blocksize * sizeof(m->bypassed_lsbs[0]));
for (i = 0; i < s->blocksize; i++)
- if (read_huff_channels(m, gbp, substr, i) < 0)
- return -1;
+ if ((ret = read_huff_channels(m, gbp, substr, i)) < 0)
+ return ret;
for (ch = s->min_channel; ch <= s->max_channel; ch++)
filter_channel(m, substr, ch);
@@ -901,16 +945,26 @@ static void rematrix_channels(MLPDecodeContext *m, unsigned int substr)
/** Write the audio data into the output buffer. */
-static int output_data_internal(MLPDecodeContext *m, unsigned int substr,
- uint8_t *data, unsigned int *data_size, int is32)
+static int output_data(MLPDecodeContext *m, unsigned int substr,
+ uint8_t *data, unsigned int *data_size)
{
SubStream *s = &m->substream[substr];
unsigned int i, out_ch = 0;
+ int out_size;
int32_t *data_32 = (int32_t*) data;
int16_t *data_16 = (int16_t*) data;
+ int is32 = (m->avctx->sample_fmt == AV_SAMPLE_FMT_S32);
+
+ if (m->avctx->channels != s->max_matrix_channel + 1) {
+ av_log(m->avctx, AV_LOG_ERROR, "channel count mismatch\n");
+ return AVERROR_INVALIDDATA;
+ }
- if (*data_size < (s->max_channel + 1) * s->blockpos * (is32 ? 4 : 2))
- return -1;
+ out_size = s->blockpos * m->avctx->channels *
+ av_get_bytes_per_sample(m->avctx->sample_fmt);
+
+ if (*data_size < out_size)
+ return AVERROR(EINVAL);
for (i = 0; i < s->blockpos; i++) {
for (out_ch = 0; out_ch <= s->max_matrix_channel; out_ch++) {
@@ -923,21 +977,11 @@ static int output_data_internal(MLPDecodeContext *m, unsigned int substr,
}
}
- *data_size = i * out_ch * (is32 ? 4 : 2);
+ *data_size = out_size;
return 0;
}
-static int output_data(MLPDecodeContext *m, unsigned int substr,
- uint8_t *data, unsigned int *data_size)
-{
- if (m->avctx->sample_fmt == AV_SAMPLE_FMT_S32)
- return output_data_internal(m, substr, data, data_size, 1);
- else
- return output_data_internal(m, substr, data, data_size, 0);
-}
-
-
/** Read an access unit from the stream.
* @return negative on error, 0 if not enough data is present in the input stream,
* otherwise the number of bytes consumed. */
@@ -956,6 +1000,7 @@ static int read_access_unit(AVCodecContext *avctx, void* data, int *data_size,
uint8_t substream_parity_present[MAX_SUBSTREAMS];
uint16_t substream_data_len[MAX_SUBSTREAMS];
uint8_t parity_bits;
+ int ret;
if (buf_size < 4)
return 0;
@@ -963,7 +1008,7 @@ static int read_access_unit(AVCodecContext *avctx, void* data, int *data_size,
length = (AV_RB16(buf) & 0xfff) * 2;
if (length < 4 || length > buf_size)
- return -1;
+ return AVERROR_INVALIDDATA;
init_get_bits(&gb, (buf + 4), (length - 4) * 8);
@@ -1069,8 +1114,8 @@ static int read_access_unit(AVCodecContext *avctx, void* data, int *data_size,
if (!s->restart_seen)
goto next_substr;
- if (read_block_data(m, &gb, substr) < 0)
- return -1;
+ if ((ret = read_block_data(m, &gb, substr)) < 0)
+ return ret;
if (get_bits_count(&gb) >= substream_data_len[substr] * 8)
goto substream_length_mismatch;
@@ -1083,13 +1128,13 @@ static int read_access_unit(AVCodecContext *avctx, void* data, int *data_size,
int shorten_by;
if (get_bits(&gb, 16) != 0xD234)
- return -1;
+ return AVERROR_INVALIDDATA;
shorten_by = get_bits(&gb, 16);
if (m->avctx->codec_id == CODEC_ID_TRUEHD && shorten_by & 0x2000)
s->blockpos -= FFMIN(shorten_by & 0x1FFF, s->blockpos);
else if (m->avctx->codec_id == CODEC_ID_MLP && shorten_by != 0xD234)
- return -1;
+ return AVERROR_INVALIDDATA;
if (substr == m->max_decoded_substream)
av_log(m->avctx, AV_LOG_INFO, "End of stream indicated.\n");
@@ -1123,42 +1168,38 @@ next_substr:
rematrix_channels(m, m->max_decoded_substream);
- if (output_data(m, m->max_decoded_substream, data, data_size) < 0)
- return -1;
+ if ((ret = output_data(m, m->max_decoded_substream, data, data_size)) < 0)
+ return ret;
return length;
substream_length_mismatch:
av_log(m->avctx, AV_LOG_ERROR, "substream %d length mismatch\n", substr);
- return -1;
+ return AVERROR_INVALIDDATA;
error:
m->params_valid = 0;
- return -1;
+ return AVERROR_INVALIDDATA;
}
AVCodec ff_mlp_decoder = {
- "mlp",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_MLP,
- sizeof(MLPDecodeContext),
- mlp_decode_init,
- NULL,
- NULL,
- read_access_unit,
+ .name = "mlp",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_MLP,
+ .priv_data_size = sizeof(MLPDecodeContext),
+ .init = mlp_decode_init,
+ .decode = read_access_unit,
.long_name = NULL_IF_CONFIG_SMALL("MLP (Meridian Lossless Packing)"),
};
#if CONFIG_TRUEHD_DECODER
AVCodec ff_truehd_decoder = {
- "truehd",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_TRUEHD,
- sizeof(MLPDecodeContext),
- mlp_decode_init,
- NULL,
- NULL,
- read_access_unit,
+ .name = "truehd",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_TRUEHD,
+ .priv_data_size = sizeof(MLPDecodeContext),
+ .init = mlp_decode_init,
+ .decode = read_access_unit,
.long_name = NULL_IF_CONFIG_SMALL("TrueHD"),
};
#endif /* CONFIG_TRUEHD_DECODER */
diff --git a/libavcodec/mlpdsp.c b/libavcodec/mlpdsp.c
index 7d01c7586d..7ec8dd24e6 100644
--- a/libavcodec/mlpdsp.c
+++ b/libavcodec/mlpdsp.c
@@ -2,20 +2,20 @@
* Copyright (c) 2007-2008 Ian Caulfield
* 2009 Ramiro Polla
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/mmvideo.c b/libavcodec/mmvideo.c
index b65335e6cb..0f30e9d35e 100644
--- a/libavcodec/mmvideo.c
+++ b/libavcodec/mmvideo.c
@@ -2,20 +2,20 @@
* American Laser Games MM Video Decoder
* Copyright (c) 2006,2008 Peter Ross
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -58,6 +58,7 @@ static av_cold int mm_decode_init(AVCodecContext *avctx)
avctx->pix_fmt = PIX_FMT_PAL8;
+ avcodec_get_frame_defaults(&s->frame);
s->frame.reference = 1;
return 0;
@@ -214,14 +215,13 @@ static av_cold int mm_decode_end(AVCodecContext *avctx)
}
AVCodec ff_mmvideo_decoder = {
- "mmvideo",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_MMVIDEO,
- sizeof(MmContext),
- mm_decode_init,
- NULL,
- mm_decode_end,
- mm_decode_frame,
- CODEC_CAP_DR1,
+ .name = "mmvideo",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_MMVIDEO,
+ .priv_data_size = sizeof(MmContext),
+ .init = mm_decode_init,
+ .close = mm_decode_end,
+ .decode = mm_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("American Laser Games MM Video"),
};
diff --git a/libavcodec/motion-test.c b/libavcodec/motion-test.c
index b88917c988..85ea1045b4 100644
--- a/libavcodec/motion-test.c
+++ b/libavcodec/motion-test.c
@@ -1,20 +1,20 @@
/*
* (c) 2001 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -144,7 +144,7 @@ int main(int argc, char **argv)
printf("ffmpeg motion test\n");
- ctx = avcodec_alloc_context();
+ ctx = avcodec_alloc_context3(NULL);
ctx->dsp_mask = AV_CPU_FLAG_FORCE;
dsputil_init(&cctx, ctx);
for (c = 0; c < flags_size; c++) {
diff --git a/libavcodec/motion_est.c b/libavcodec/motion_est.c
index 48e8ea9ffa..319aaf97ca 100644
--- a/libavcodec/motion_est.c
+++ b/libavcodec/motion_est.c
@@ -5,20 +5,20 @@
*
* new motion estimation (X1/EPZS) by Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -52,7 +52,7 @@ static inline int sad_hpel_motion_search(MpegEncContext * s,
int src_index, int ref_index,
int size, int h);
-static inline int update_map_generation(MotionEstContext *c)
+static inline unsigned update_map_generation(MotionEstContext *c)
{
c->map_generation+= 1<<(ME_MAP_MV_BITS*2);
if(c->map_generation==0){
@@ -374,30 +374,6 @@ int ff_init_me(MpegEncContext *s){
return 0;
}
-#if 0
-static int pix_dev(uint8_t * pix, int line_size, int mean)
-{
- int s, i, j;
-
- s = 0;
- for (i = 0; i < 16; i++) {
- for (j = 0; j < 16; j += 8) {
- s += FFABS(pix[0]-mean);
- s += FFABS(pix[1]-mean);
- s += FFABS(pix[2]-mean);
- s += FFABS(pix[3]-mean);
- s += FFABS(pix[4]-mean);
- s += FFABS(pix[5]-mean);
- s += FFABS(pix[6]-mean);
- s += FFABS(pix[7]-mean);
- pix += 8;
- }
- pix += line_size - 16;
- }
- return s;
-}
-#endif
-
static inline void no_motion_search(MpegEncContext * s,
int *mx_ptr, int *my_ptr)
{
@@ -533,16 +509,16 @@ static inline void set_p_mv_tables(MpegEncContext * s, int mx, int my, int mv4)
if(mv4){
int mot_xy= s->block_index[0];
- s->current_picture.motion_val[0][mot_xy ][0]= mx;
- s->current_picture.motion_val[0][mot_xy ][1]= my;
- s->current_picture.motion_val[0][mot_xy+1][0]= mx;
- s->current_picture.motion_val[0][mot_xy+1][1]= my;
+ s->current_picture.f.motion_val[0][mot_xy ][0] = mx;
+ s->current_picture.f.motion_val[0][mot_xy ][1] = my;
+ s->current_picture.f.motion_val[0][mot_xy + 1][0] = mx;
+ s->current_picture.f.motion_val[0][mot_xy + 1][1] = my;
mot_xy += s->b8_stride;
- s->current_picture.motion_val[0][mot_xy ][0]= mx;
- s->current_picture.motion_val[0][mot_xy ][1]= my;
- s->current_picture.motion_val[0][mot_xy+1][0]= mx;
- s->current_picture.motion_val[0][mot_xy+1][1]= my;
+ s->current_picture.f.motion_val[0][mot_xy ][0] = mx;
+ s->current_picture.f.motion_val[0][mot_xy ][1] = my;
+ s->current_picture.f.motion_val[0][mot_xy + 1][0] = mx;
+ s->current_picture.f.motion_val[0][mot_xy + 1][1] = my;
}
}
@@ -615,8 +591,8 @@ static inline int h263_mv4_search(MpegEncContext *s, int mx, int my, int shift)
const int mot_stride = s->b8_stride;
const int mot_xy = s->block_index[block];
- P_LEFT[0] = s->current_picture.motion_val[0][mot_xy - 1][0];
- P_LEFT[1] = s->current_picture.motion_val[0][mot_xy - 1][1];
+ P_LEFT[0] = s->current_picture.f.motion_val[0][mot_xy - 1][0];
+ P_LEFT[1] = s->current_picture.f.motion_val[0][mot_xy - 1][1];
if(P_LEFT[0] > (c->xmax<<shift)) P_LEFT[0] = (c->xmax<<shift);
@@ -625,10 +601,10 @@ static inline int h263_mv4_search(MpegEncContext *s, int mx, int my, int shift)
c->pred_x= pred_x4= P_LEFT[0];
c->pred_y= pred_y4= P_LEFT[1];
} else {
- P_TOP[0] = s->current_picture.motion_val[0][mot_xy - mot_stride ][0];
- P_TOP[1] = s->current_picture.motion_val[0][mot_xy - mot_stride ][1];
- P_TOPRIGHT[0] = s->current_picture.motion_val[0][mot_xy - mot_stride + off[block]][0];
- P_TOPRIGHT[1] = s->current_picture.motion_val[0][mot_xy - mot_stride + off[block]][1];
+ P_TOP[0] = s->current_picture.f.motion_val[0][mot_xy - mot_stride ][0];
+ P_TOP[1] = s->current_picture.f.motion_val[0][mot_xy - mot_stride ][1];
+ P_TOPRIGHT[0] = s->current_picture.f.motion_val[0][mot_xy - mot_stride + off[block]][0];
+ P_TOPRIGHT[1] = s->current_picture.f.motion_val[0][mot_xy - mot_stride + off[block]][1];
if(P_TOP[1] > (c->ymax<<shift)) P_TOP[1] = (c->ymax<<shift);
if(P_TOPRIGHT[0] < (c->xmin<<shift)) P_TOPRIGHT[0]= (c->xmin<<shift);
if(P_TOPRIGHT[0] > (c->xmax<<shift)) P_TOPRIGHT[0]= (c->xmax<<shift);
@@ -680,8 +656,8 @@ static inline int h263_mv4_search(MpegEncContext *s, int mx, int my, int shift)
my4_sum+= my4;
}
- s->current_picture.motion_val[0][ s->block_index[block] ][0]= mx4;
- s->current_picture.motion_val[0][ s->block_index[block] ][1]= my4;
+ s->current_picture.f.motion_val[0][s->block_index[block]][0] = mx4;
+ s->current_picture.f.motion_val[0][s->block_index[block]][1] = my4;
if(mx4 != mx || my4 != my) same=0;
}
@@ -690,7 +666,7 @@ static inline int h263_mv4_search(MpegEncContext *s, int mx, int my, int shift)
return INT_MAX;
if(s->dsp.me_sub_cmp[0] != s->dsp.mb_cmp[0]){
- dmin_sum += s->dsp.mb_cmp[0](s, s->new_picture.data[0] + s->mb_x*16 + s->mb_y*16*stride, c->scratchpad, stride, 16);
+ dmin_sum += s->dsp.mb_cmp[0](s, s->new_picture.f.data[0] + s->mb_x*16 + s->mb_y*16*stride, c->scratchpad, stride, 16);
}
if(c->avctx->mb_cmp&FF_CMP_CHROMA){
@@ -705,15 +681,15 @@ static inline int h263_mv4_search(MpegEncContext *s, int mx, int my, int shift)
offset= (s->mb_x*8 + (mx>>1)) + (s->mb_y*8 + (my>>1))*s->uvlinesize;
if(s->no_rounding){
- s->dsp.put_no_rnd_pixels_tab[1][dxy](c->scratchpad , s->last_picture.data[1] + offset, s->uvlinesize, 8);
- s->dsp.put_no_rnd_pixels_tab[1][dxy](c->scratchpad+8 , s->last_picture.data[2] + offset, s->uvlinesize, 8);
+ s->dsp.put_no_rnd_pixels_tab[1][dxy](c->scratchpad , s->last_picture.f.data[1] + offset, s->uvlinesize, 8);
+ s->dsp.put_no_rnd_pixels_tab[1][dxy](c->scratchpad + 8, s->last_picture.f.data[2] + offset, s->uvlinesize, 8);
}else{
- s->dsp.put_pixels_tab [1][dxy](c->scratchpad , s->last_picture.data[1] + offset, s->uvlinesize, 8);
- s->dsp.put_pixels_tab [1][dxy](c->scratchpad+8 , s->last_picture.data[2] + offset, s->uvlinesize, 8);
+ s->dsp.put_pixels_tab [1][dxy](c->scratchpad , s->last_picture.f.data[1] + offset, s->uvlinesize, 8);
+ s->dsp.put_pixels_tab [1][dxy](c->scratchpad + 8, s->last_picture.f.data[2] + offset, s->uvlinesize, 8);
}
- dmin_sum += s->dsp.mb_cmp[1](s, s->new_picture.data[1] + s->mb_x*8 + s->mb_y*8*s->uvlinesize, c->scratchpad , s->uvlinesize, 8);
- dmin_sum += s->dsp.mb_cmp[1](s, s->new_picture.data[2] + s->mb_x*8 + s->mb_y*8*s->uvlinesize, c->scratchpad+8, s->uvlinesize, 8);
+ dmin_sum += s->dsp.mb_cmp[1](s, s->new_picture.f.data[1] + s->mb_x*8 + s->mb_y*8*s->uvlinesize, c->scratchpad , s->uvlinesize, 8);
+ dmin_sum += s->dsp.mb_cmp[1](s, s->new_picture.f.data[2] + s->mb_x*8 + s->mb_y*8*s->uvlinesize, c->scratchpad+8, s->uvlinesize, 8);
}
c->pred_x= mx;
@@ -879,7 +855,7 @@ static inline int check_input_motion(MpegEncContext * s, int mb_x, int mb_y, int
Picture *p= s->current_picture_ptr;
int mb_xy= mb_x + mb_y*s->mb_stride;
int xy= 2*mb_x + 2*mb_y*s->b8_stride;
- int mb_type= s->current_picture.mb_type[mb_xy];
+ int mb_type= s->current_picture.f.mb_type[mb_xy];
int flags= c->flags;
int shift= (flags&FLAG_QPEL) + 1;
int mask= (1<<shift)-1;
@@ -896,8 +872,8 @@ static inline int check_input_motion(MpegEncContext * s, int mb_x, int mb_y, int
for(i=0; i<4; i++){
int xy= s->block_index[i];
- clip_input_mv(s, p->motion_val[0][xy], !!IS_INTERLACED(mb_type));
- clip_input_mv(s, p->motion_val[1][xy], !!IS_INTERLACED(mb_type));
+ clip_input_mv(s, p->f.motion_val[0][xy], !!IS_INTERLACED(mb_type));
+ clip_input_mv(s, p->f.motion_val[1][xy], !!IS_INTERLACED(mb_type));
}
if(IS_INTERLACED(mb_type)){
@@ -912,8 +888,8 @@ static inline int check_input_motion(MpegEncContext * s, int mb_x, int mb_y, int
}
if(USES_LIST(mb_type, 0)){
- int field_select0= p->ref_index[0][4*mb_xy ];
- int field_select1= p->ref_index[0][4*mb_xy+2];
+ int field_select0= p->f.ref_index[0][4*mb_xy ];
+ int field_select1= p->f.ref_index[0][4*mb_xy+2];
assert(field_select0==0 ||field_select0==1);
assert(field_select1==0 ||field_select1==1);
init_interlaced_ref(s, 0);
@@ -921,46 +897,46 @@ static inline int check_input_motion(MpegEncContext * s, int mb_x, int mb_y, int
if(p_type){
s->p_field_select_table[0][mb_xy]= field_select0;
s->p_field_select_table[1][mb_xy]= field_select1;
- *(uint32_t*)s->p_field_mv_table[0][field_select0][mb_xy]= *(uint32_t*)p->motion_val[0][xy ];
- *(uint32_t*)s->p_field_mv_table[1][field_select1][mb_xy]= *(uint32_t*)p->motion_val[0][xy2];
+ *(uint32_t*)s->p_field_mv_table[0][field_select0][mb_xy] = *(uint32_t*)p->f.motion_val[0][xy ];
+ *(uint32_t*)s->p_field_mv_table[1][field_select1][mb_xy] = *(uint32_t*)p->f.motion_val[0][xy2];
s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_INTER_I;
}else{
s->b_field_select_table[0][0][mb_xy]= field_select0;
s->b_field_select_table[0][1][mb_xy]= field_select1;
- *(uint32_t*)s->b_field_mv_table[0][0][field_select0][mb_xy]= *(uint32_t*)p->motion_val[0][xy ];
- *(uint32_t*)s->b_field_mv_table[0][1][field_select1][mb_xy]= *(uint32_t*)p->motion_val[0][xy2];
+ *(uint32_t*)s->b_field_mv_table[0][0][field_select0][mb_xy] = *(uint32_t*)p->f.motion_val[0][xy ];
+ *(uint32_t*)s->b_field_mv_table[0][1][field_select1][mb_xy] = *(uint32_t*)p->f.motion_val[0][xy2];
s->mb_type[mb_xy]= CANDIDATE_MB_TYPE_FORWARD_I;
}
- x= p->motion_val[0][xy ][0];
- y= p->motion_val[0][xy ][1];
+ x = p->f.motion_val[0][xy ][0];
+ y = p->f.motion_val[0][xy ][1];
d = cmp(s, x>>shift, y>>shift, x&mask, y&mask, 0, 8, field_select0, 0, cmpf, chroma_cmpf, flags);
- x= p->motion_val[0][xy2][0];
- y= p->motion_val[0][xy2][1];
+ x = p->f.motion_val[0][xy2][0];
+ y = p->f.motion_val[0][xy2][1];
d+= cmp(s, x>>shift, y>>shift, x&mask, y&mask, 0, 8, field_select1, 1, cmpf, chroma_cmpf, flags);
}
if(USES_LIST(mb_type, 1)){
- int field_select0= p->ref_index[1][4*mb_xy ];
- int field_select1= p->ref_index[1][4*mb_xy+2];
+ int field_select0 = p->f.ref_index[1][4 * mb_xy ];
+ int field_select1 = p->f.ref_index[1][4 * mb_xy + 2];
assert(field_select0==0 ||field_select0==1);
assert(field_select1==0 ||field_select1==1);
init_interlaced_ref(s, 2);
s->b_field_select_table[1][0][mb_xy]= field_select0;
s->b_field_select_table[1][1][mb_xy]= field_select1;
- *(uint32_t*)s->b_field_mv_table[1][0][field_select0][mb_xy]= *(uint32_t*)p->motion_val[1][xy ];
- *(uint32_t*)s->b_field_mv_table[1][1][field_select1][mb_xy]= *(uint32_t*)p->motion_val[1][xy2];
+ *(uint32_t*)s->b_field_mv_table[1][0][field_select0][mb_xy] = *(uint32_t*)p->f.motion_val[1][xy ];
+ *(uint32_t*)s->b_field_mv_table[1][1][field_select1][mb_xy] = *(uint32_t*)p->f.motion_val[1][xy2];
if(USES_LIST(mb_type, 0)){
s->mb_type[mb_xy]= CANDIDATE_MB_TYPE_BIDIR_I;
}else{
s->mb_type[mb_xy]= CANDIDATE_MB_TYPE_BACKWARD_I;
}
- x= p->motion_val[1][xy ][0];
- y= p->motion_val[1][xy ][1];
+ x = p->f.motion_val[1][xy ][0];
+ y = p->f.motion_val[1][xy ][1];
d = cmp(s, x>>shift, y>>shift, x&mask, y&mask, 0, 8, field_select0+2, 0, cmpf, chroma_cmpf, flags);
- x= p->motion_val[1][xy2][0];
- y= p->motion_val[1][xy2][1];
+ x = p->f.motion_val[1][xy2][0];
+ y = p->f.motion_val[1][xy2][1];
d+= cmp(s, x>>shift, y>>shift, x&mask, y&mask, 0, 8, field_select1+2, 1, cmpf, chroma_cmpf, flags);
//FIXME bidir scores
}
@@ -976,33 +952,33 @@ static inline int check_input_motion(MpegEncContext * s, int mb_x, int mb_y, int
init_mv4_ref(c);
for(i=0; i<4; i++){
xy= s->block_index[i];
- x= p->motion_val[0][xy][0];
- y= p->motion_val[0][xy][1];
+ x= p->f.motion_val[0][xy][0];
+ y= p->f.motion_val[0][xy][1];
d+= cmp(s, x>>shift, y>>shift, x&mask, y&mask, 1, 8, i, i, cmpf, chroma_cmpf, flags);
}
s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_INTER4V;
}else{
if(USES_LIST(mb_type, 0)){
if(p_type){
- *(uint32_t*)s->p_mv_table[mb_xy]= *(uint32_t*)p->motion_val[0][xy];
+ *(uint32_t*)s->p_mv_table[mb_xy] = *(uint32_t*)p->f.motion_val[0][xy];
s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_INTER;
}else if(USES_LIST(mb_type, 1)){
- *(uint32_t*)s->b_bidir_forw_mv_table[mb_xy]= *(uint32_t*)p->motion_val[0][xy];
- *(uint32_t*)s->b_bidir_back_mv_table[mb_xy]= *(uint32_t*)p->motion_val[1][xy];
+ *(uint32_t*)s->b_bidir_forw_mv_table[mb_xy] = *(uint32_t*)p->f.motion_val[0][xy];
+ *(uint32_t*)s->b_bidir_back_mv_table[mb_xy] = *(uint32_t*)p->f.motion_val[1][xy];
s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_BIDIR;
}else{
- *(uint32_t*)s->b_forw_mv_table[mb_xy]= *(uint32_t*)p->motion_val[0][xy];
+ *(uint32_t*)s->b_forw_mv_table[mb_xy] = *(uint32_t*)p->f.motion_val[0][xy];
s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_FORWARD;
}
- x= p->motion_val[0][xy][0];
- y= p->motion_val[0][xy][1];
+ x = p->f.motion_val[0][xy][0];
+ y = p->f.motion_val[0][xy][1];
d = cmp(s, x>>shift, y>>shift, x&mask, y&mask, 0, 16, 0, 0, cmpf, chroma_cmpf, flags);
}else if(USES_LIST(mb_type, 1)){
- *(uint32_t*)s->b_back_mv_table[mb_xy]= *(uint32_t*)p->motion_val[1][xy];
+ *(uint32_t*)s->b_back_mv_table[mb_xy] = *(uint32_t*)p->f.motion_val[1][xy];
s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_BACKWARD;
- x= p->motion_val[1][xy][0];
- y= p->motion_val[1][xy][1];
+ x = p->f.motion_val[1][xy][0];
+ y = p->f.motion_val[1][xy][1];
d = cmp(s, x>>shift, y>>shift, x&mask, y&mask, 0, 16, 2, 0, cmpf, chroma_cmpf, flags);
}else
s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_INTRA;
@@ -1023,7 +999,7 @@ void ff_estimate_p_frame_motion(MpegEncContext * s,
int mb_type=0;
Picture * const pic= &s->current_picture;
- init_ref(c, s->new_picture.data, s->last_picture.data, NULL, 16*mb_x, 16*mb_y, 0);
+ init_ref(c, s->new_picture.f.data, s->last_picture.f.data, NULL, 16*mb_x, 16*mb_y, 0);
assert(s->quarter_sample==0 || s->quarter_sample==1);
assert(s->linesize == c->stride);
@@ -1040,7 +1016,7 @@ void ff_estimate_p_frame_motion(MpegEncContext * s,
/* intra / predictive decision */
pix = c->src[0][0];
sum = s->dsp.pix_sum(pix, s->linesize);
- varc = s->dsp.pix_norm1(pix, s->linesize) - (((unsigned)(sum*sum))>>8) + 500;
+ varc = s->dsp.pix_norm1(pix, s->linesize) - (((unsigned)sum*sum)>>8) + 500;
pic->mb_mean[s->mb_stride * mb_y + mb_x] = (sum+128)>>8;
pic->mb_var [s->mb_stride * mb_y + mb_x] = (varc+128)>>8;
@@ -1075,16 +1051,16 @@ void ff_estimate_p_frame_motion(MpegEncContext * s,
const int mot_stride = s->b8_stride;
const int mot_xy = s->block_index[0];
- P_LEFT[0] = s->current_picture.motion_val[0][mot_xy - 1][0];
- P_LEFT[1] = s->current_picture.motion_val[0][mot_xy - 1][1];
+ P_LEFT[0] = s->current_picture.f.motion_val[0][mot_xy - 1][0];
+ P_LEFT[1] = s->current_picture.f.motion_val[0][mot_xy - 1][1];
if(P_LEFT[0] > (c->xmax<<shift)) P_LEFT[0] = (c->xmax<<shift);
if(!s->first_slice_line) {
- P_TOP[0] = s->current_picture.motion_val[0][mot_xy - mot_stride ][0];
- P_TOP[1] = s->current_picture.motion_val[0][mot_xy - mot_stride ][1];
- P_TOPRIGHT[0] = s->current_picture.motion_val[0][mot_xy - mot_stride + 2][0];
- P_TOPRIGHT[1] = s->current_picture.motion_val[0][mot_xy - mot_stride + 2][1];
+ P_TOP[0] = s->current_picture.f.motion_val[0][mot_xy - mot_stride ][0];
+ P_TOP[1] = s->current_picture.f.motion_val[0][mot_xy - mot_stride ][1];
+ P_TOPRIGHT[0] = s->current_picture.f.motion_val[0][mot_xy - mot_stride + 2][0];
+ P_TOPRIGHT[1] = s->current_picture.f.motion_val[0][mot_xy - mot_stride + 2][1];
if(P_TOP[1] > (c->ymax<<shift)) P_TOP[1] = (c->ymax<<shift);
if(P_TOPRIGHT[0] < (c->xmin<<shift)) P_TOPRIGHT[0]= (c->xmin<<shift);
if(P_TOPRIGHT[1] > (c->ymax<<shift)) P_TOPRIGHT[1]= (c->ymax<<shift);
@@ -1202,7 +1178,7 @@ void ff_estimate_p_frame_motion(MpegEncContext * s,
if((c->avctx->mb_cmp&0xFF)==FF_CMP_SSE){
intra_score= varc - 500;
}else{
- int mean= (sum+128)>>8;
+ unsigned mean = (sum+128)>>8;
mean*= 0x01010101;
for(i=0; i<16; i++){
@@ -1214,37 +1190,13 @@ void ff_estimate_p_frame_motion(MpegEncContext * s,
intra_score= s->dsp.mb_cmp[0](s, c->scratchpad, pix, s->linesize, 16);
}
-#if 0 //FIXME
- /* get chroma score */
- if(c->avctx->mb_cmp&FF_CMP_CHROMA){
- for(i=1; i<3; i++){
- uint8_t *dest_c;
- int mean;
-
- if(s->out_format == FMT_H263){
- mean= (s->dc_val[i][mb_x + mb_y*s->b8_stride] + 4)>>3; //FIXME not exact but simple ;)
- }else{
- mean= (s->last_dc[i] + 4)>>3;
- }
- dest_c = s->new_picture.data[i] + (mb_y * 8 * (s->uvlinesize)) + mb_x * 8;
-
- mean*= 0x01010101;
- for(i=0; i<8; i++){
- *(uint32_t*)(&c->scratchpad[i*s->uvlinesize+ 0]) = mean;
- *(uint32_t*)(&c->scratchpad[i*s->uvlinesize+ 4]) = mean;
- }
-
- intra_score+= s->dsp.mb_cmp[1](s, c->scratchpad, dest_c, s->uvlinesize);
- }
- }
-#endif
intra_score += c->mb_penalty_factor*16;
if(intra_score < dmin){
mb_type= CANDIDATE_MB_TYPE_INTRA;
- s->current_picture.mb_type[mb_y*s->mb_stride + mb_x]= CANDIDATE_MB_TYPE_INTRA; //FIXME cleanup
+ s->current_picture.f.mb_type[mb_y*s->mb_stride + mb_x] = CANDIDATE_MB_TYPE_INTRA; //FIXME cleanup
}else
- s->current_picture.mb_type[mb_y*s->mb_stride + mb_x]= 0;
+ s->current_picture.f.mb_type[mb_y*s->mb_stride + mb_x] = 0;
{
int p_score= FFMIN(vard, varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*100);
@@ -1264,7 +1216,7 @@ int ff_pre_estimate_p_frame_motion(MpegEncContext * s,
int P[10][2];
const int shift= 1+s->quarter_sample;
const int xy= mb_x + mb_y*s->mb_stride;
- init_ref(c, s->new_picture.data, s->last_picture.data, NULL, 16*mb_x, 16*mb_y, 0);
+ init_ref(c, s->new_picture.f.data, s->last_picture.f.data, NULL, 16*mb_x, 16*mb_y, 0);
assert(s->quarter_sample==0 || s->quarter_sample==1);
@@ -1615,7 +1567,7 @@ static inline int direct_search(MpegEncContext * s, int mb_x, int mb_y)
ymin= xmin=(-32)>>shift;
ymax= xmax= 31>>shift;
- if(IS_8X8(s->next_picture.mb_type[mot_xy])){
+ if (IS_8X8(s->next_picture.f.mb_type[mot_xy])) {
s->mv_type= MV_TYPE_8X8;
}else{
s->mv_type= MV_TYPE_16X16;
@@ -1625,8 +1577,8 @@ static inline int direct_search(MpegEncContext * s, int mb_x, int mb_y)
int index= s->block_index[i];
int min, max;
- c->co_located_mv[i][0]= s->next_picture.motion_val[0][index][0];
- c->co_located_mv[i][1]= s->next_picture.motion_val[0][index][1];
+ c->co_located_mv[i][0] = s->next_picture.f.motion_val[0][index][0];
+ c->co_located_mv[i][1] = s->next_picture.f.motion_val[0][index][1];
c->direct_basis_mv[i][0]= c->co_located_mv[i][0]*time_pb/time_pp + ((i& 1)<<(shift+3));
c->direct_basis_mv[i][1]= c->co_located_mv[i][1]*time_pb/time_pp + ((i>>1)<<(shift+3));
// c->direct_basis_mv[1][i][0]= c->co_located_mv[i][0]*(time_pb - time_pp)/time_pp + ((i &1)<<(shift+3);
@@ -1708,13 +1660,14 @@ void ff_estimate_b_frame_motion(MpegEncContext * s,
int fmin, bmin, dmin, fbmin, bimin, fimin;
int type=0;
const int xy = mb_y*s->mb_stride + mb_x;
- init_ref(c, s->new_picture.data, s->last_picture.data, s->next_picture.data, 16*mb_x, 16*mb_y, 2);
+ init_ref(c, s->new_picture.f.data, s->last_picture.f.data,
+ s->next_picture.f.data, 16 * mb_x, 16 * mb_y, 2);
get_limits(s, 16*mb_x, 16*mb_y);
c->skip=0;
- if(s->codec_id == CODEC_ID_MPEG4 && s->next_picture.mbskip_table[xy]){
+ if (s->codec_id == CODEC_ID_MPEG4 && s->next_picture.f.mbskip_table[xy]) {
int score= direct_search(s, mb_x, mb_y); //FIXME just check 0,0
score= ((unsigned)(score*score + 128*256))>>16;
@@ -1849,10 +1802,6 @@ void ff_estimate_b_frame_motion(MpegEncContext * s,
if(dmin>256*256*16) type&= ~CANDIDATE_MB_TYPE_DIRECT; //do not try direct mode if it is invalid for this MB
if(s->codec_id == CODEC_ID_MPEG4 && type&CANDIDATE_MB_TYPE_DIRECT && s->flags&CODEC_FLAG_MV0 && *(uint32_t*)s->b_direct_mv_table[xy])
type |= CANDIDATE_MB_TYPE_DIRECT0;
-#if 0
- if(s->out_format == FMT_MPEG1)
- type |= CANDIDATE_MB_TYPE_INTRA;
-#endif
}
s->mb_type[mb_y*s->mb_stride + mb_x]= type;
@@ -1947,14 +1896,14 @@ void ff_fix_long_p_mvs(MpegEncContext * s)
int block;
for(block=0; block<4; block++){
int off= (block& 1) + (block>>1)*wrap;
- int mx= s->current_picture.motion_val[0][ xy + off ][0];
- int my= s->current_picture.motion_val[0][ xy + off ][1];
+ int mx = s->current_picture.f.motion_val[0][ xy + off ][0];
+ int my = s->current_picture.f.motion_val[0][ xy + off ][1];
if( mx >=range || mx <-range
|| my >=range || my <-range){
s->mb_type[i] &= ~CANDIDATE_MB_TYPE_INTER4V;
s->mb_type[i] |= CANDIDATE_MB_TYPE_INTRA;
- s->current_picture.mb_type[i]= CANDIDATE_MB_TYPE_INTRA;
+ s->current_picture.f.mb_type[i] = CANDIDATE_MB_TYPE_INTRA;
}
}
}
diff --git a/libavcodec/motion_est_template.c b/libavcodec/motion_est_template.c
index 576bb3da43..b7b7b6d521 100644
--- a/libavcodec/motion_est_template.c
+++ b/libavcodec/motion_est_template.c
@@ -2,20 +2,20 @@
* Motion estimation
* Copyright (c) 2002-2004 Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -44,75 +44,6 @@
COPY3_IF_LT(dmin, d, bx, hx, by, hy)\
}
-#if 0
-static int hpel_motion_search)(MpegEncContext * s,
- int *mx_ptr, int *my_ptr, int dmin,
- uint8_t *ref_data[3],
- int size)
-{
- const int xx = 16 * s->mb_x + 8*(n&1);
- const int yy = 16 * s->mb_y + 8*(n>>1);
- const int mx = *mx_ptr;
- const int my = *my_ptr;
- const int penalty_factor= c->sub_penalty_factor;
-
- LOAD_COMMON
-
- // INIT;
- //FIXME factorize
- me_cmp_func cmp, chroma_cmp, cmp_sub, chroma_cmp_sub;
-
- if(s->no_rounding /*FIXME b_type*/){
- hpel_put= &s->dsp.put_no_rnd_pixels_tab[size];
- chroma_hpel_put= &s->dsp.put_no_rnd_pixels_tab[size+1];
- }else{
- hpel_put=& s->dsp.put_pixels_tab[size];
- chroma_hpel_put= &s->dsp.put_pixels_tab[size+1];
- }
- cmpf= s->dsp.me_cmp[size];
- chroma_cmpf= s->dsp.me_cmp[size+1];
- cmp_sub= s->dsp.me_sub_cmp[size];
- chroma_cmp_sub= s->dsp.me_sub_cmp[size+1];
-
- if(c->skip){ //FIXME somehow move up (benchmark)
- *mx_ptr = 0;
- *my_ptr = 0;
- return dmin;
- }
-
- if(c->avctx->me_cmp != c->avctx->me_sub_cmp){
- CMP_HPEL(dmin, 0, 0, mx, my, size);
- if(mx || my)
- dmin += (mv_penalty[2*mx - pred_x] + mv_penalty[2*my - pred_y])*penalty_factor;
- }
-
- if (mx > xmin && mx < xmax &&
- my > ymin && my < ymax) {
- int bx=2*mx, by=2*my;
- int d= dmin;
-
- CHECK_HALF_MV(1, 1, mx-1, my-1)
- CHECK_HALF_MV(0, 1, mx , my-1)
- CHECK_HALF_MV(1, 1, mx , my-1)
- CHECK_HALF_MV(1, 0, mx-1, my )
- CHECK_HALF_MV(1, 0, mx , my )
- CHECK_HALF_MV(1, 1, mx-1, my )
- CHECK_HALF_MV(0, 1, mx , my )
- CHECK_HALF_MV(1, 1, mx , my )
-
- assert(bx >= xmin*2 || bx <= xmax*2 || by >= ymin*2 || by <= ymax*2);
-
- *mx_ptr = bx;
- *my_ptr = by;
- }else{
- *mx_ptr =2*mx;
- *my_ptr =2*my;
- }
-
- return dmin;
-}
-
-#else
static int hpel_motion_search(MpegEncContext * s,
int *mx_ptr, int *my_ptr, int dmin,
int src_index, int ref_index,
@@ -158,8 +89,9 @@ static int hpel_motion_search(MpegEncContext * s,
const int b= score_map[(index+(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)]
+ (mv_penalty[bx - pred_x] + mv_penalty[by+2 - pred_y])*c->penalty_factor;
- int key;
- int map_generation= c->map_generation;
+#if 1
+ unsigned key;
+ unsigned map_generation= c->map_generation;
#ifndef NDEBUG
uint32_t *map= c->map;
#endif
@@ -171,6 +103,7 @@ static int hpel_motion_search(MpegEncContext * s,
assert(map[(index+1)&(ME_MAP_SIZE-1)] == key);
key= ((my)<<ME_MAP_MV_BITS) + (mx-1) + map_generation;
assert(map[(index-1)&(ME_MAP_SIZE-1)] == key);
+#endif
if(t<=b){
CHECK_HALF_MV(0, 1, mx ,my-1)
if(l<=r){
@@ -218,7 +151,6 @@ static int hpel_motion_search(MpegEncContext * s,
return dmin;
}
-#endif
static int no_sub_motion_search(MpegEncContext * s,
int *mx_ptr, int *my_ptr, int dmin,
@@ -278,7 +210,7 @@ static int qpel_motion_search(MpegEncContext * s,
const int mx = *mx_ptr;
const int my = *my_ptr;
const int penalty_factor= c->sub_penalty_factor;
- const int map_generation= c->map_generation;
+ const unsigned map_generation = c->map_generation;
const int subpel_quality= c->avctx->me_subpel_quality;
uint32_t *map= c->map;
me_cmp_func cmpf, chroma_cmpf;
@@ -321,7 +253,6 @@ static int qpel_motion_search(MpegEncContext * s,
int best_pos[8][2];
memset(best, 64, sizeof(int)*8);
-#if 1
if(s->me.dia_size>=2){
const int tl= score_map[(index-(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)];
const int bl= score_map[(index+(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)];
@@ -410,76 +341,6 @@ static int qpel_motion_search(MpegEncContext * s,
CHECK_QUARTER_MV(nx&3, ny&3, nx>>2, ny>>2)
}
-#if 0
- const int tl= score_map[(index-(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)];
- const int bl= score_map[(index+(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)];
- const int tr= score_map[(index-(1<<ME_MAP_SHIFT)+1)&(ME_MAP_SIZE-1)];
- const int br= score_map[(index+(1<<ME_MAP_SHIFT)+1)&(ME_MAP_SIZE-1)];
-// if(l < r && l < t && l < b && l < tl && l < bl && l < tr && l < br && bl < tl){
- if(tl<br){
-
-// nx= FFMAX(4*mx - bx, bx - 4*mx);
-// ny= FFMAX(4*my - by, by - 4*my);
-
- static int stats[7][7], count;
- count++;
- stats[4*mx - bx + 3][4*my - by + 3]++;
- if(256*256*256*64 % count ==0){
- for(i=0; i<49; i++){
- if((i%7)==0) printf("\n");
- printf("%6d ", stats[0][i]);
- }
- printf("\n");
- }
- }
-#endif
-#else
-
- CHECK_QUARTER_MV(2, 2, mx-1, my-1)
- CHECK_QUARTER_MV(0, 2, mx , my-1)
- CHECK_QUARTER_MV(2, 2, mx , my-1)
- CHECK_QUARTER_MV(2, 0, mx , my )
- CHECK_QUARTER_MV(2, 2, mx , my )
- CHECK_QUARTER_MV(0, 2, mx , my )
- CHECK_QUARTER_MV(2, 2, mx-1, my )
- CHECK_QUARTER_MV(2, 0, mx-1, my )
-
- nx= bx;
- ny= by;
-
- for(i=0; i<8; i++){
- int ox[8]= {0, 1, 1, 1, 0,-1,-1,-1};
- int oy[8]= {1, 1, 0,-1,-1,-1, 0, 1};
- CHECK_QUARTER_MV((nx + ox[i])&3, (ny + oy[i])&3, (nx + ox[i])>>2, (ny + oy[i])>>2)
- }
-#endif
-#if 0
- //outer ring
- CHECK_QUARTER_MV(1, 3, mx-1, my-1)
- CHECK_QUARTER_MV(1, 2, mx-1, my-1)
- CHECK_QUARTER_MV(1, 1, mx-1, my-1)
- CHECK_QUARTER_MV(2, 1, mx-1, my-1)
- CHECK_QUARTER_MV(3, 1, mx-1, my-1)
- CHECK_QUARTER_MV(0, 1, mx , my-1)
- CHECK_QUARTER_MV(1, 1, mx , my-1)
- CHECK_QUARTER_MV(2, 1, mx , my-1)
- CHECK_QUARTER_MV(3, 1, mx , my-1)
- CHECK_QUARTER_MV(3, 2, mx , my-1)
- CHECK_QUARTER_MV(3, 3, mx , my-1)
- CHECK_QUARTER_MV(3, 0, mx , my )
- CHECK_QUARTER_MV(3, 1, mx , my )
- CHECK_QUARTER_MV(3, 2, mx , my )
- CHECK_QUARTER_MV(3, 3, mx , my )
- CHECK_QUARTER_MV(2, 3, mx , my )
- CHECK_QUARTER_MV(1, 3, mx , my )
- CHECK_QUARTER_MV(0, 3, mx , my )
- CHECK_QUARTER_MV(3, 3, mx-1, my )
- CHECK_QUARTER_MV(2, 3, mx-1, my )
- CHECK_QUARTER_MV(1, 3, mx-1, my )
- CHECK_QUARTER_MV(1, 2, mx-1, my )
- CHECK_QUARTER_MV(1, 1, mx-1, my )
- CHECK_QUARTER_MV(1, 0, mx-1, my )
-#endif
assert(bx >= xmin*4 && bx <= xmax*4 && by >= ymin*4 && by <= ymax*4);
*mx_ptr = bx;
@@ -495,7 +356,7 @@ static int qpel_motion_search(MpegEncContext * s,
#define CHECK_MV(x,y)\
{\
- const int key= ((y)<<ME_MAP_MV_BITS) + (x) + map_generation;\
+ const unsigned key = ((y)<<ME_MAP_MV_BITS) + (x) + map_generation;\
const int index= (((y)<<ME_MAP_SHIFT) + (x))&(ME_MAP_SIZE-1);\
assert((x) >= xmin);\
assert((x) <= xmax);\
@@ -523,7 +384,7 @@ static int qpel_motion_search(MpegEncContext * s,
#define CHECK_MV_DIR(x,y,new_dir)\
{\
- const int key= ((y)<<ME_MAP_MV_BITS) + (x) + map_generation;\
+ const unsigned key = ((y)<<ME_MAP_MV_BITS) + (x) + map_generation;\
const int index= (((y)<<ME_MAP_SHIFT) + (x))&(ME_MAP_SIZE-1);\
/*printf("check_mv_dir %d %d %d\n", x, y, new_dir);*/\
if(map[index]!=key){\
@@ -561,13 +422,13 @@ static av_always_inline int small_diamond_search(MpegEncContext * s, int *best,
int next_dir=-1;
LOAD_COMMON
LOAD_COMMON2
- int map_generation= c->map_generation;
+ unsigned map_generation = c->map_generation;
cmpf= s->dsp.me_cmp[size];
chroma_cmpf= s->dsp.me_cmp[size+1];
{ /* ensure that the best point is in the MAP as h/qpel refinement needs it */
- const int key= (best[1]<<ME_MAP_MV_BITS) + best[0] + map_generation;
+ const unsigned key = (best[1]<<ME_MAP_MV_BITS) + best[0] + map_generation;
const int index= ((best[1]<<ME_MAP_SHIFT) + best[0])&(ME_MAP_SIZE-1);
if(map[index]!=key){ //this will be executed only very rarey
score_map[index]= cmp(s, best[0], best[1], 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);
@@ -603,7 +464,7 @@ static int funny_diamond_search(MpegEncContext * s, int *best, int dmin,
int dia_size;
LOAD_COMMON
LOAD_COMMON2
- int map_generation= c->map_generation;
+ unsigned map_generation = c->map_generation;
cmpf= s->dsp.me_cmp[size];
chroma_cmpf= s->dsp.me_cmp[size+1];
@@ -644,7 +505,7 @@ static int hex_search(MpegEncContext * s, int *best, int dmin,
me_cmp_func cmpf, chroma_cmpf;
LOAD_COMMON
LOAD_COMMON2
- int map_generation= c->map_generation;
+ unsigned map_generation = c->map_generation;
int x,y,d;
const int dec= dia_size & (dia_size-1);
@@ -678,7 +539,7 @@ static int l2s_dia_search(MpegEncContext * s, int *best, int dmin,
me_cmp_func cmpf, chroma_cmpf;
LOAD_COMMON
LOAD_COMMON2
- int map_generation= c->map_generation;
+ unsigned map_generation = c->map_generation;
int x,y,i,d;
int dia_size= c->dia_size&0xFF;
const int dec= dia_size & (dia_size-1);
@@ -716,7 +577,7 @@ static int umh_search(MpegEncContext * s, int *best, int dmin,
me_cmp_func cmpf, chroma_cmpf;
LOAD_COMMON
LOAD_COMMON2
- int map_generation= c->map_generation;
+ unsigned map_generation = c->map_generation;
int x,y,x2,y2, i, j, d;
const int dia_size= c->dia_size&0xFE;
static const int hex[16][2]={{-4,-2}, {-4,-1}, {-4, 0}, {-4, 1}, {-4, 2},
@@ -763,7 +624,7 @@ static int full_search(MpegEncContext * s, int *best, int dmin,
me_cmp_func cmpf, chroma_cmpf;
LOAD_COMMON
LOAD_COMMON2
- int map_generation= c->map_generation;
+ unsigned map_generation = c->map_generation;
int x,y, d;
const int dia_size= c->dia_size&0xFF;
@@ -792,7 +653,7 @@ static int full_search(MpegEncContext * s, int *best, int dmin,
#define SAB_CHECK_MV(ax,ay)\
{\
- const int key= ((ay)<<ME_MAP_MV_BITS) + (ax) + map_generation;\
+ const unsigned key = ((ay)<<ME_MAP_MV_BITS) + (ax) + map_generation;\
const int index= (((ay)<<ME_MAP_SHIFT) + (ax))&(ME_MAP_SIZE-1);\
/*printf("sab check %d %d\n", ax, ay);*/\
if(map[index]!=key){\
@@ -831,7 +692,7 @@ static int sab_diamond_search(MpegEncContext * s, int *best, int dmin,
int i, j;
LOAD_COMMON
LOAD_COMMON2
- int map_generation= c->map_generation;
+ unsigned map_generation = c->map_generation;
cmpf= s->dsp.me_cmp[size];
chroma_cmpf= s->dsp.me_cmp[size+1];
@@ -916,7 +777,7 @@ static int var_diamond_search(MpegEncContext * s, int *best, int dmin,
int dia_size;
LOAD_COMMON
LOAD_COMMON2
- int map_generation= c->map_generation;
+ unsigned map_generation = c->map_generation;
cmpf= s->dsp.me_cmp[size];
chroma_cmpf= s->dsp.me_cmp[size+1];
@@ -1008,7 +869,7 @@ static av_always_inline int epzs_motion_search_internal(MpegEncContext * s, int
int d; ///< the score (cmp + penalty) of any given mv
int dmin; /**< the best value of d, i.e. the score
corresponding to the mv stored in best[]. */
- int map_generation;
+ unsigned map_generation;
int penalty_factor;
const int ref_mv_stride= s->mb_stride; //pass as arg FIXME
const int ref_mv_xy= s->mb_x + s->mb_y*ref_mv_stride; //add to last_mv beforepassing FIXME
@@ -1136,7 +997,7 @@ static int epzs_motion_search4(MpegEncContext * s,
MotionEstContext * const c= &s->me;
int best[2]={0, 0};
int d, dmin;
- int map_generation;
+ unsigned map_generation;
const int penalty_factor= c->penalty_factor;
const int size=1;
const int h=8;
@@ -1196,7 +1057,7 @@ static int epzs_motion_search2(MpegEncContext * s,
MotionEstContext * const c= &s->me;
int best[2]={0, 0};
int d, dmin;
- int map_generation;
+ unsigned map_generation;
const int penalty_factor= c->penalty_factor;
const int size=0; //FIXME pass as arg
const int h=8;
diff --git a/libavcodec/motionpixels.c b/libavcodec/motionpixels.c
index ebc4b31201..ff1152822f 100644
--- a/libavcodec/motionpixels.c
+++ b/libavcodec/motionpixels.c
@@ -2,20 +2,20 @@
* Motion Pixels Video Decoder
* Copyright (c) 2008 Gregory Montoir (cyx@users.sourceforge.net)
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -52,15 +52,18 @@ typedef struct MotionPixelsContext {
static av_cold int mp_decode_init(AVCodecContext *avctx)
{
MotionPixelsContext *mp = avctx->priv_data;
+ int w4 = (avctx->width + 3) & ~3;
+ int h4 = (avctx->height + 3) & ~3;
motionpixels_tableinit();
mp->avctx = avctx;
dsputil_init(&mp->dsp, avctx);
- mp->changes_map = av_mallocz(avctx->width * avctx->height);
+ mp->changes_map = av_mallocz(avctx->width * h4);
mp->offset_bits_len = av_log2(avctx->width * avctx->height) + 1;
mp->vpt = av_mallocz(avctx->height * sizeof(YuvPixel));
- mp->hpt = av_mallocz(avctx->height * avctx->width / 16 * sizeof(YuvPixel));
+ mp->hpt = av_mallocz(h4 * w4 / 16 * sizeof(YuvPixel));
avctx->pix_fmt = PIX_FMT_RGB555;
+ avcodec_get_frame_defaults(&mp->frame);
return 0;
}
@@ -252,6 +255,7 @@ static int mp_decode_frame(AVCodecContext *avctx,
mp->dsp.bswap_buf((uint32_t *)mp->bswapbuf, (const uint32_t *)buf, buf_size / 4);
if (buf_size & 3)
memcpy(mp->bswapbuf + (buf_size & ~3), buf + (buf_size & ~3), buf_size & 3);
+ memset(mp->bswapbuf + buf_size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
init_get_bits(&gb, mp->bswapbuf, buf_size * 8);
memset(mp->changes_map, 0, avctx->width * avctx->height);
@@ -278,7 +282,10 @@ static int mp_decode_frame(AVCodecContext *avctx,
if (sz == 0)
goto end;
- init_vlc(&mp->vlc, mp->max_codes_bits, mp->codes_count, &mp->codes[0].size, sizeof(HuffCode), 1, &mp->codes[0].code, sizeof(HuffCode), 4, 0);
+ if (mp->max_codes_bits <= 0)
+ goto end;
+ if (init_vlc(&mp->vlc, mp->max_codes_bits, mp->codes_count, &mp->codes[0].size, sizeof(HuffCode), 1, &mp->codes[0].code, sizeof(HuffCode), 4, 0))
+ goto end;
mp_decode_frame_helper(mp, &gb);
free_vlc(&mp->vlc);
@@ -303,14 +310,13 @@ static av_cold int mp_decode_end(AVCodecContext *avctx)
}
AVCodec ff_motionpixels_decoder = {
- "motionpixels",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_MOTIONPIXELS,
- sizeof(MotionPixelsContext),
- mp_decode_init,
- NULL,
- mp_decode_end,
- mp_decode_frame,
- CODEC_CAP_DR1,
+ .name = "motionpixels",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_MOTIONPIXELS,
+ .priv_data_size = sizeof(MotionPixelsContext),
+ .init = mp_decode_init,
+ .close = mp_decode_end,
+ .decode = mp_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Motion Pixels video"),
};
diff --git a/libavcodec/motionpixels_tablegen.c b/libavcodec/motionpixels_tablegen.c
index ad8e0d9161..31e5cdf710 100644
--- a/libavcodec/motionpixels_tablegen.c
+++ b/libavcodec/motionpixels_tablegen.c
@@ -3,20 +3,20 @@
*
* Copyright (c) 2009 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/motionpixels_tablegen.h b/libavcodec/motionpixels_tablegen.h
index cbf56c8694..b9802e589d 100644
--- a/libavcodec/motionpixels_tablegen.h
+++ b/libavcodec/motionpixels_tablegen.h
@@ -3,20 +3,20 @@
*
* Copyright (c) 2009 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -30,7 +30,7 @@ typedef struct YuvPixel {
} YuvPixel;
static int mp_yuv_to_rgb(int y, int v, int u, int clip_rgb) {
- static const uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
+ const uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
int r, g, b;
r = (1000 * y + 701 * v) / 1000;
diff --git a/libavcodec/movsub_bsf.c b/libavcodec/movsub_bsf.c
index 423ebebcc6..088c774001 100644
--- a/libavcodec/movsub_bsf.c
+++ b/libavcodec/movsub_bsf.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2008 Reimar Döffinger
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/mp3_header_compress_bsf.c b/libavcodec/mp3_header_compress_bsf.c
index bc3659ef3e..417a2940d5 100644
--- a/libavcodec/mp3_header_compress_bsf.c
+++ b/libavcodec/mp3_header_compress_bsf.c
@@ -1,20 +1,20 @@
/*
* copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/mp3_header_decompress_bsf.c b/libavcodec/mp3_header_decompress_bsf.c
index 3f3074286a..c08aa1fa05 100644
--- a/libavcodec/mp3_header_decompress_bsf.c
+++ b/libavcodec/mp3_header_decompress_bsf.c
@@ -1,20 +1,20 @@
/*
* copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -50,10 +50,10 @@ static int mp3_header_decompress(AVBitStreamFilterContext *bsfc, AVCodecContext
lsf = sample_rate < (24000+32000)/2;
mpeg25 = sample_rate < (12000+16000)/2;
sample_rate_index= (header>>10)&3;
- sample_rate= ff_mpa_freq_tab[sample_rate_index] >> (lsf + mpeg25); //in case sample rate is a little off
+ sample_rate= avpriv_mpa_freq_tab[sample_rate_index] >> (lsf + mpeg25); //in case sample rate is a little off
for(bitrate_index=2; bitrate_index<30; bitrate_index++){
- frame_size = ff_mpa_bitrate_tab[lsf][2][bitrate_index>>1];
+ frame_size = avpriv_mpa_bitrate_tab[lsf][2][bitrate_index>>1];
frame_size = (frame_size * 144000) / (sample_rate << lsf) + (bitrate_index&1);
if(frame_size == buf_size + 4)
break;
diff --git a/libavcodec/mpc.c b/libavcodec/mpc.c
index 4573860525..c2975ec732 100644
--- a/libavcodec/mpc.c
+++ b/libavcodec/mpc.c
@@ -2,20 +2,20 @@
* Musepack decoder core
* Copyright (c) 2006 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/mpc.h b/libavcodec/mpc.h
index 6d0f7b45bb..cd5769234c 100644
--- a/libavcodec/mpc.h
+++ b/libavcodec/mpc.h
@@ -2,20 +2,20 @@
* Musepack decoder
* Copyright (c) 2006 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/mpc7.c b/libavcodec/mpc7.c
index dbfa3c8636..272e1b28ba 100644
--- a/libavcodec/mpc7.c
+++ b/libavcodec/mpc7.c
@@ -2,20 +2,20 @@
* Musepack SV7 decoder
* Copyright (c) 2006 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -197,12 +197,19 @@ static int mpc7_decode_frame(AVCodecContext * avctx,
int i, ch;
int mb = -1;
Band *bands = c->bands;
- int off;
+ int off, out_size;
int bits_used, bits_avail;
memset(bands, 0, sizeof(bands));
if(buf_size <= 4){
av_log(avctx, AV_LOG_ERROR, "Too small buffer passed (%i bytes)\n", buf_size);
+ return AVERROR(EINVAL);
+ }
+
+ out_size = (buf[1] ? c->lastframelen : MPC_FRAME_SIZE) * 4;
+ if (*data_size < out_size) {
+ av_log(avctx, AV_LOG_ERROR, "Output buffer is too small\n");
+ return AVERROR(EINVAL);
}
bits = av_malloc(((buf_size - 1) & ~3) + FF_INPUT_BUFFER_PADDING_SIZE);
@@ -277,7 +284,7 @@ static int mpc7_decode_frame(AVCodecContext * avctx,
*data_size = 0;
return buf_size;
}
- *data_size = (buf[1] ? c->lastframelen : MPC_FRAME_SIZE) * 4;
+ *data_size = out_size;
return buf_size;
}
@@ -291,14 +298,12 @@ static void mpc7_decode_flush(AVCodecContext *avctx)
}
AVCodec ff_mpc7_decoder = {
- "mpc7",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_MUSEPACK7,
- sizeof(MPCContext),
- mpc7_decode_init,
- NULL,
- NULL,
- mpc7_decode_frame,
+ .name = "mpc7",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_MUSEPACK7,
+ .priv_data_size = sizeof(MPCContext),
+ .init = mpc7_decode_init,
+ .decode = mpc7_decode_frame,
.flush = mpc7_decode_flush,
.long_name = NULL_IF_CONFIG_SMALL("Musepack SV7"),
};
diff --git a/libavcodec/mpc7data.h b/libavcodec/mpc7data.h
index f205ffe97f..5609e8fbf3 100644
--- a/libavcodec/mpc7data.h
+++ b/libavcodec/mpc7data.h
@@ -2,20 +2,20 @@
* Musepack decoder
* Copyright (c) 2006 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/mpc8.c b/libavcodec/mpc8.c
index 3177faf1c4..2f6bde3231 100644
--- a/libavcodec/mpc8.c
+++ b/libavcodec/mpc8.c
@@ -2,20 +2,20 @@
* Musepack SV8 decoder
* Copyright (c) 2007 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -127,6 +127,8 @@ static av_cold int mpc8_decode_init(AVCodecContext * avctx)
skip_bits(&gb, 3);//sample rate
c->maxbands = get_bits(&gb, 5) + 1;
+ if (c->maxbands >= BANDS)
+ return AVERROR_INVALIDDATA;
channels = get_bits(&gb, 4) + 1;
if (channels > 2) {
av_log_missing_feature(avctx, "Multichannel MPC SV8", 1);
@@ -241,10 +243,16 @@ static int mpc8_decode_frame(AVCodecContext * avctx,
GetBitContext gb2, *gb = &gb2;
int i, j, k, ch, cnt, res, t;
Band *bands = c->bands;
- int off;
+ int off, out_size;
int maxband, keyframe;
int last[2];
+ out_size = MPC_FRAME_SIZE * 2 * avctx->channels;
+ if (*data_size < out_size) {
+ av_log(avctx, AV_LOG_ERROR, "Output buffer is too small\n");
+ return AVERROR(EINVAL);
+ }
+
keyframe = c->cur_frame == 0;
if(keyframe){
@@ -260,6 +268,8 @@ static int mpc8_decode_frame(AVCodecContext * avctx,
maxband = c->last_max_band + get_vlc2(gb, band_vlc.table, MPC8_BANDS_BITS, 2);
if(maxband > 32) maxband -= 33;
}
+ if(maxband > c->maxbands)
+ return AVERROR_INVALIDDATA;
c->last_max_band = maxband;
/* read subband indexes */
@@ -400,19 +410,17 @@ static int mpc8_decode_frame(AVCodecContext * avctx,
c->last_bits_used = get_bits_count(gb);
if(c->cur_frame >= c->frames)
c->cur_frame = 0;
- *data_size = MPC_FRAME_SIZE * 2 * avctx->channels;
+ *data_size = out_size;
return c->cur_frame ? c->last_bits_used >> 3 : buf_size;
}
AVCodec ff_mpc8_decoder = {
- "mpc8",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_MUSEPACK8,
- sizeof(MPCContext),
- mpc8_decode_init,
- NULL,
- NULL,
- mpc8_decode_frame,
+ .name = "mpc8",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_MUSEPACK8,
+ .priv_data_size = sizeof(MPCContext),
+ .init = mpc8_decode_init,
+ .decode = mpc8_decode_frame,
.long_name = NULL_IF_CONFIG_SMALL("Musepack SV8"),
};
diff --git a/libavcodec/mpc8data.h b/libavcodec/mpc8data.h
index 2940b30733..22c2be43bf 100644
--- a/libavcodec/mpc8data.h
+++ b/libavcodec/mpc8data.h
@@ -2,20 +2,20 @@
* Musepack SV8 decoder
* Copyright (c) 2007 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/mpc8huff.h b/libavcodec/mpc8huff.h
index 6005e214e8..8491037aa4 100644
--- a/libavcodec/mpc8huff.h
+++ b/libavcodec/mpc8huff.h
@@ -2,20 +2,20 @@
* Musepack SV8 decoder
* Copyright (c) 2007 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/mpcdata.h b/libavcodec/mpcdata.h
index 397dad59d8..03df3da3b5 100644
--- a/libavcodec/mpcdata.h
+++ b/libavcodec/mpcdata.h
@@ -2,20 +2,20 @@
* Musepack decoder
* Copyright (c) 2006 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c
index 986cad5fd2..9663db2f61 100644
--- a/libavcodec/mpeg12.c
+++ b/libavcodec/mpeg12.c
@@ -1,22 +1,22 @@
/*
* MPEG-1/2 decoder
- * Copyright (c) 2000,2001 Fabrice Bellard
+ * Copyright (c) 2000, 2001 Fabrice Bellard
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -30,6 +30,7 @@
#include "avcodec.h"
#include "dsputil.h"
#include "mpegvideo.h"
+#include "libavutil/avassert.h"
#include "mpeg12.h"
#include "mpeg12data.h"
@@ -49,543 +50,12 @@
#define MB_PTYPE_VLC_BITS 6
#define MB_BTYPE_VLC_BITS 6
-static inline int mpeg1_decode_block_intra(MpegEncContext *s,
- DCTELEM *block,
- int n);
-static inline int mpeg1_decode_block_inter(MpegEncContext *s,
- DCTELEM *block,
- int n);
-static inline int mpeg1_fast_decode_block_inter(MpegEncContext *s, DCTELEM *block, int n);
-static inline int mpeg2_decode_block_non_intra(MpegEncContext *s,
- DCTELEM *block,
- int n);
-static inline int mpeg2_decode_block_intra(MpegEncContext *s,
- DCTELEM *block,
- int n);
-static inline int mpeg2_fast_decode_block_non_intra(MpegEncContext *s, DCTELEM *block, int n);
-static inline int mpeg2_fast_decode_block_intra(MpegEncContext *s, DCTELEM *block, int n);
-static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred);
-static void exchange_uv(MpegEncContext *s);
-
-static const enum PixelFormat pixfmt_xvmc_mpg2_420[] = {
- PIX_FMT_XVMC_MPEG2_IDCT,
- PIX_FMT_XVMC_MPEG2_MC,
- PIX_FMT_NONE};
-
-uint8_t ff_mpeg12_static_rl_table_store[2][2][2*MAX_RUN + MAX_LEVEL + 3];
-
-
-#define INIT_2D_VLC_RL(rl, static_size)\
-{\
- static RL_VLC_ELEM rl_vlc_table[static_size];\
- INIT_VLC_STATIC(&rl.vlc, TEX_VLC_BITS, rl.n + 2,\
- &rl.table_vlc[0][1], 4, 2,\
- &rl.table_vlc[0][0], 4, 2, static_size);\
-\
- rl.rl_vlc[0]= rl_vlc_table;\
- init_2d_vlc_rl(&rl);\
-}
-
-static void init_2d_vlc_rl(RLTable *rl)
-{
- int i;
-
- for(i=0; i<rl->vlc.table_size; i++){
- int code= rl->vlc.table[i][0];
- int len = rl->vlc.table[i][1];
- int level, run;
-
- if(len==0){ // illegal code
- run= 65;
- level= MAX_LEVEL;
- }else if(len<0){ //more bits needed
- run= 0;
- level= code;
- }else{
- if(code==rl->n){ //esc
- run= 65;
- level= 0;
- }else if(code==rl->n+1){ //eob
- run= 0;
- level= 127;
- }else{
- run= rl->table_run [code] + 1;
- level= rl->table_level[code];
- }
- }
- rl->rl_vlc[0][i].len= len;
- rl->rl_vlc[0][i].level= level;
- rl->rl_vlc[0][i].run= run;
- }
-}
-
-void ff_mpeg12_common_init(MpegEncContext *s)
-{
-
- s->y_dc_scale_table=
- s->c_dc_scale_table= ff_mpeg2_dc_scale_table[s->intra_dc_precision];
-
-}
-
-void ff_mpeg1_clean_buffers(MpegEncContext *s){
- s->last_dc[0] = 1 << (7 + s->intra_dc_precision);
- s->last_dc[1] = s->last_dc[0];
- s->last_dc[2] = s->last_dc[0];
- memset(s->last_mv, 0, sizeof(s->last_mv));
-}
-
-
-/******************************************/
-/* decoding */
-
-VLC ff_dc_lum_vlc;
-VLC ff_dc_chroma_vlc;
-
static VLC mv_vlc;
-static VLC mbincr_vlc;
-static VLC mb_ptype_vlc;
-static VLC mb_btype_vlc;
-static VLC mb_pat_vlc;
-
-av_cold void ff_mpeg12_init_vlcs(void)
-{
- static int done = 0;
-
- if (!done) {
- done = 1;
-
- INIT_VLC_STATIC(&ff_dc_lum_vlc, DC_VLC_BITS, 12,
- ff_mpeg12_vlc_dc_lum_bits, 1, 1,
- ff_mpeg12_vlc_dc_lum_code, 2, 2, 512);
- INIT_VLC_STATIC(&ff_dc_chroma_vlc, DC_VLC_BITS, 12,
- ff_mpeg12_vlc_dc_chroma_bits, 1, 1,
- ff_mpeg12_vlc_dc_chroma_code, 2, 2, 514);
- INIT_VLC_STATIC(&mv_vlc, MV_VLC_BITS, 17,
- &ff_mpeg12_mbMotionVectorTable[0][1], 2, 1,
- &ff_mpeg12_mbMotionVectorTable[0][0], 2, 1, 518);
- INIT_VLC_STATIC(&mbincr_vlc, MBINCR_VLC_BITS, 36,
- &ff_mpeg12_mbAddrIncrTable[0][1], 2, 1,
- &ff_mpeg12_mbAddrIncrTable[0][0], 2, 1, 538);
- INIT_VLC_STATIC(&mb_pat_vlc, MB_PAT_VLC_BITS, 64,
- &ff_mpeg12_mbPatTable[0][1], 2, 1,
- &ff_mpeg12_mbPatTable[0][0], 2, 1, 512);
-
- INIT_VLC_STATIC(&mb_ptype_vlc, MB_PTYPE_VLC_BITS, 7,
- &table_mb_ptype[0][1], 2, 1,
- &table_mb_ptype[0][0], 2, 1, 64);
- INIT_VLC_STATIC(&mb_btype_vlc, MB_BTYPE_VLC_BITS, 11,
- &table_mb_btype[0][1], 2, 1,
- &table_mb_btype[0][0], 2, 1, 64);
- init_rl(&ff_rl_mpeg1, ff_mpeg12_static_rl_table_store[0]);
- init_rl(&ff_rl_mpeg2, ff_mpeg12_static_rl_table_store[1]);
-
- INIT_2D_VLC_RL(ff_rl_mpeg1, 680);
- INIT_2D_VLC_RL(ff_rl_mpeg2, 674);
- }
-}
-
-static inline int get_dmv(MpegEncContext *s)
-{
- if(get_bits1(&s->gb))
- return 1 - (get_bits1(&s->gb) << 1);
- else
- return 0;
-}
-
-static inline int get_qscale(MpegEncContext *s)
-{
- int qscale = get_bits(&s->gb, 5);
- if (s->q_scale_type) {
- return non_linear_qscale[qscale];
- } else {
- return qscale << 1;
- }
-}
-
-/* motion type (for MPEG-2) */
-#define MT_FIELD 1
-#define MT_FRAME 2
-#define MT_16X8 2
-#define MT_DMV 3
-
-static int mpeg_decode_mb(MpegEncContext *s,
- DCTELEM block[12][64])
-{
- int i, j, k, cbp, val, mb_type, motion_type;
- const int mb_block_count = 4 + (1<< s->chroma_format);
-
- av_dlog(s->avctx, "decode_mb: x=%d y=%d\n", s->mb_x, s->mb_y);
-
- assert(s->mb_skipped==0);
-
- if (s->mb_skip_run-- != 0) {
- if (s->pict_type == AV_PICTURE_TYPE_P) {
- s->mb_skipped = 1;
- s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride ]= MB_TYPE_SKIP | MB_TYPE_L0 | MB_TYPE_16x16;
- } else {
- int mb_type;
-
- if(s->mb_x)
- mb_type= s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride - 1];
- else
- mb_type= s->current_picture.mb_type[ s->mb_width + (s->mb_y-1)*s->mb_stride - 1]; // FIXME not sure if this is allowed in MPEG at all
- if(IS_INTRA(mb_type))
- return -1;
-
- s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride ]=
- mb_type | MB_TYPE_SKIP;
-// assert(s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride - 1]&(MB_TYPE_16x16|MB_TYPE_16x8));
-
- if((s->mv[0][0][0]|s->mv[0][0][1]|s->mv[1][0][0]|s->mv[1][0][1])==0)
- s->mb_skipped = 1;
- }
-
- return 0;
- }
-
- switch(s->pict_type) {
- default:
- case AV_PICTURE_TYPE_I:
- if (get_bits1(&s->gb) == 0) {
- if (get_bits1(&s->gb) == 0){
- av_log(s->avctx, AV_LOG_ERROR, "invalid mb type in I Frame at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
- mb_type = MB_TYPE_QUANT | MB_TYPE_INTRA;
- } else {
- mb_type = MB_TYPE_INTRA;
- }
- break;
- case AV_PICTURE_TYPE_P:
- mb_type = get_vlc2(&s->gb, mb_ptype_vlc.table, MB_PTYPE_VLC_BITS, 1);
- if (mb_type < 0){
- av_log(s->avctx, AV_LOG_ERROR, "invalid mb type in P Frame at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
- mb_type = ptype2mb_type[ mb_type ];
- break;
- case AV_PICTURE_TYPE_B:
- mb_type = get_vlc2(&s->gb, mb_btype_vlc.table, MB_BTYPE_VLC_BITS, 1);
- if (mb_type < 0){
- av_log(s->avctx, AV_LOG_ERROR, "invalid mb type in B Frame at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
- mb_type = btype2mb_type[ mb_type ];
- break;
- }
- av_dlog(s->avctx, "mb_type=%x\n", mb_type);
-// motion_type = 0; /* avoid warning */
- if (IS_INTRA(mb_type)) {
- s->dsp.clear_blocks(s->block[0]);
-
- if(!s->chroma_y_shift){
- s->dsp.clear_blocks(s->block[6]);
- }
-
- /* compute DCT type */
- if (s->picture_structure == PICT_FRAME && //FIXME add an interlaced_dct coded var?
- !s->frame_pred_frame_dct) {
- s->interlaced_dct = get_bits1(&s->gb);
- }
-
- if (IS_QUANT(mb_type))
- s->qscale = get_qscale(s);
-
- if (s->concealment_motion_vectors) {
- /* just parse them */
- if (s->picture_structure != PICT_FRAME)
- skip_bits1(&s->gb); /* field select */
-
- s->mv[0][0][0]= s->last_mv[0][0][0]= s->last_mv[0][1][0] =
- mpeg_decode_motion(s, s->mpeg_f_code[0][0], s->last_mv[0][0][0]);
- s->mv[0][0][1]= s->last_mv[0][0][1]= s->last_mv[0][1][1] =
- mpeg_decode_motion(s, s->mpeg_f_code[0][1], s->last_mv[0][0][1]);
-
- skip_bits1(&s->gb); /* marker */
- }else
- memset(s->last_mv, 0, sizeof(s->last_mv)); /* reset mv prediction */
- s->mb_intra = 1;
- //if 1, we memcpy blocks in xvmcvideo
- if(CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration > 1){
- ff_xvmc_pack_pblocks(s,-1);//inter are always full blocks
- if(s->swap_uv){
- exchange_uv(s);
- }
- }
-
- if (s->codec_id == CODEC_ID_MPEG2VIDEO) {
- if(s->flags2 & CODEC_FLAG2_FAST){
- for(i=0;i<6;i++) {
- mpeg2_fast_decode_block_intra(s, *s->pblocks[i], i);
- }
- }else{
- for(i=0;i<mb_block_count;i++) {
- if (mpeg2_decode_block_intra(s, *s->pblocks[i], i) < 0)
- return -1;
- }
- }
- } else {
- for(i=0;i<6;i++) {
- if (mpeg1_decode_block_intra(s, *s->pblocks[i], i) < 0)
- return -1;
- }
- }
- } else {
- if (mb_type & MB_TYPE_ZERO_MV){
- assert(mb_type & MB_TYPE_CBP);
-
- s->mv_dir = MV_DIR_FORWARD;
- if(s->picture_structure == PICT_FRAME){
- if(!s->frame_pred_frame_dct)
- s->interlaced_dct = get_bits1(&s->gb);
- s->mv_type = MV_TYPE_16X16;
- }else{
- s->mv_type = MV_TYPE_FIELD;
- mb_type |= MB_TYPE_INTERLACED;
- s->field_select[0][0]= s->picture_structure - 1;
- }
-
- if (IS_QUANT(mb_type))
- s->qscale = get_qscale(s);
-
- s->last_mv[0][0][0] = 0;
- s->last_mv[0][0][1] = 0;
- s->last_mv[0][1][0] = 0;
- s->last_mv[0][1][1] = 0;
- s->mv[0][0][0] = 0;
- s->mv[0][0][1] = 0;
- }else{
- assert(mb_type & MB_TYPE_L0L1);
-//FIXME decide if MBs in field pictures are MB_TYPE_INTERLACED
- /* get additional motion vector type */
- if (s->frame_pred_frame_dct)
- motion_type = MT_FRAME;
- else{
- motion_type = get_bits(&s->gb, 2);
- if (s->picture_structure == PICT_FRAME && HAS_CBP(mb_type))
- s->interlaced_dct = get_bits1(&s->gb);
- }
-
- if (IS_QUANT(mb_type))
- s->qscale = get_qscale(s);
-
- /* motion vectors */
- s->mv_dir= (mb_type>>13)&3;
- av_dlog(s->avctx, "motion_type=%d\n", motion_type);
- switch(motion_type) {
- case MT_FRAME: /* or MT_16X8 */
- if (s->picture_structure == PICT_FRAME) {
- mb_type |= MB_TYPE_16x16;
- s->mv_type = MV_TYPE_16X16;
- for(i=0;i<2;i++) {
- if (USES_LIST(mb_type, i)) {
- /* MT_FRAME */
- s->mv[i][0][0]= s->last_mv[i][0][0]= s->last_mv[i][1][0] =
- mpeg_decode_motion(s, s->mpeg_f_code[i][0], s->last_mv[i][0][0]);
- s->mv[i][0][1]= s->last_mv[i][0][1]= s->last_mv[i][1][1] =
- mpeg_decode_motion(s, s->mpeg_f_code[i][1], s->last_mv[i][0][1]);
- /* full_pel: only for MPEG-1 */
- if (s->full_pel[i]){
- s->mv[i][0][0] <<= 1;
- s->mv[i][0][1] <<= 1;
- }
- }
- }
- } else {
- mb_type |= MB_TYPE_16x8 | MB_TYPE_INTERLACED;
- s->mv_type = MV_TYPE_16X8;
- for(i=0;i<2;i++) {
- if (USES_LIST(mb_type, i)) {
- /* MT_16X8 */
- for(j=0;j<2;j++) {
- s->field_select[i][j] = get_bits1(&s->gb);
- for(k=0;k<2;k++) {
- val = mpeg_decode_motion(s, s->mpeg_f_code[i][k],
- s->last_mv[i][j][k]);
- s->last_mv[i][j][k] = val;
- s->mv[i][j][k] = val;
- }
- }
- }
- }
- }
- break;
- case MT_FIELD:
- s->mv_type = MV_TYPE_FIELD;
- if (s->picture_structure == PICT_FRAME) {
- mb_type |= MB_TYPE_16x8 | MB_TYPE_INTERLACED;
- for(i=0;i<2;i++) {
- if (USES_LIST(mb_type, i)) {
- for(j=0;j<2;j++) {
- s->field_select[i][j] = get_bits1(&s->gb);
- val = mpeg_decode_motion(s, s->mpeg_f_code[i][0],
- s->last_mv[i][j][0]);
- s->last_mv[i][j][0] = val;
- s->mv[i][j][0] = val;
- av_dlog(s->avctx, "fmx=%d\n", val);
- val = mpeg_decode_motion(s, s->mpeg_f_code[i][1],
- s->last_mv[i][j][1] >> 1);
- s->last_mv[i][j][1] = val << 1;
- s->mv[i][j][1] = val;
- av_dlog(s->avctx, "fmy=%d\n", val);
- }
- }
- }
- } else {
- mb_type |= MB_TYPE_16x16 | MB_TYPE_INTERLACED;
- for(i=0;i<2;i++) {
- if (USES_LIST(mb_type, i)) {
- s->field_select[i][0] = get_bits1(&s->gb);
- for(k=0;k<2;k++) {
- val = mpeg_decode_motion(s, s->mpeg_f_code[i][k],
- s->last_mv[i][0][k]);
- s->last_mv[i][0][k] = val;
- s->last_mv[i][1][k] = val;
- s->mv[i][0][k] = val;
- }
- }
- }
- }
- break;
- case MT_DMV:
- s->mv_type = MV_TYPE_DMV;
- for(i=0;i<2;i++) {
- if (USES_LIST(mb_type, i)) {
- int dmx, dmy, mx, my, m;
- const int my_shift= s->picture_structure == PICT_FRAME;
-
- mx = mpeg_decode_motion(s, s->mpeg_f_code[i][0],
- s->last_mv[i][0][0]);
- s->last_mv[i][0][0] = mx;
- s->last_mv[i][1][0] = mx;
- dmx = get_dmv(s);
- my = mpeg_decode_motion(s, s->mpeg_f_code[i][1],
- s->last_mv[i][0][1] >> my_shift);
- dmy = get_dmv(s);
-
-
- s->last_mv[i][0][1] = my<<my_shift;
- s->last_mv[i][1][1] = my<<my_shift;
-
- s->mv[i][0][0] = mx;
- s->mv[i][0][1] = my;
- s->mv[i][1][0] = mx;//not used
- s->mv[i][1][1] = my;//not used
-
- if (s->picture_structure == PICT_FRAME) {
- mb_type |= MB_TYPE_16x16 | MB_TYPE_INTERLACED;
-
- //m = 1 + 2 * s->top_field_first;
- m = s->top_field_first ? 1 : 3;
-
- /* top -> top pred */
- s->mv[i][2][0] = ((mx * m + (mx > 0)) >> 1) + dmx;
- s->mv[i][2][1] = ((my * m + (my > 0)) >> 1) + dmy - 1;
- m = 4 - m;
- s->mv[i][3][0] = ((mx * m + (mx > 0)) >> 1) + dmx;
- s->mv[i][3][1] = ((my * m + (my > 0)) >> 1) + dmy + 1;
- } else {
- mb_type |= MB_TYPE_16x16;
-
- s->mv[i][2][0] = ((mx + (mx > 0)) >> 1) + dmx;
- s->mv[i][2][1] = ((my + (my > 0)) >> 1) + dmy;
- if(s->picture_structure == PICT_TOP_FIELD)
- s->mv[i][2][1]--;
- else
- s->mv[i][2][1]++;
- }
- }
- }
- break;
- default:
- av_log(s->avctx, AV_LOG_ERROR, "00 motion_type at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
- }
-
- s->mb_intra = 0;
- if (HAS_CBP(mb_type)) {
- s->dsp.clear_blocks(s->block[0]);
-
- cbp = get_vlc2(&s->gb, mb_pat_vlc.table, MB_PAT_VLC_BITS, 1);
- if(mb_block_count > 6){
- cbp<<= mb_block_count-6;
- cbp |= get_bits(&s->gb, mb_block_count-6);
- s->dsp.clear_blocks(s->block[6]);
- }
- if (cbp <= 0){
- av_log(s->avctx, AV_LOG_ERROR, "invalid cbp at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
-
- //if 1, we memcpy blocks in xvmcvideo
- if(CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration > 1){
- ff_xvmc_pack_pblocks(s,cbp);
- if(s->swap_uv){
- exchange_uv(s);
- }
- }
-
- if (s->codec_id == CODEC_ID_MPEG2VIDEO) {
- if(s->flags2 & CODEC_FLAG2_FAST){
- for(i=0;i<6;i++) {
- if(cbp & 32) {
- mpeg2_fast_decode_block_non_intra(s, *s->pblocks[i], i);
- } else {
- s->block_last_index[i] = -1;
- }
- cbp+=cbp;
- }
- }else{
- cbp<<= 12-mb_block_count;
-
- for(i=0;i<mb_block_count;i++) {
- if ( cbp & (1<<11) ) {
- if (mpeg2_decode_block_non_intra(s, *s->pblocks[i], i) < 0)
- return -1;
- } else {
- s->block_last_index[i] = -1;
- }
- cbp+=cbp;
- }
- }
- } else {
- if(s->flags2 & CODEC_FLAG2_FAST){
- for(i=0;i<6;i++) {
- if (cbp & 32) {
- mpeg1_fast_decode_block_inter(s, *s->pblocks[i], i);
- } else {
- s->block_last_index[i] = -1;
- }
- cbp+=cbp;
- }
- }else{
- for(i=0;i<6;i++) {
- if (cbp & 32) {
- if (mpeg1_decode_block_inter(s, *s->pblocks[i], i) < 0)
- return -1;
- } else {
- s->block_last_index[i] = -1;
- }
- cbp+=cbp;
- }
- }
- }
- }else{
- for(i=0;i<12;i++)
- s->block_last_index[i] = -1;
- }
- }
-
- s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride ]= mb_type;
-
- return 0;
-}
/* as H.263, but only 17 codes */
static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred)
{
- int code, sign, val, l, shift;
+ int code, sign, val, shift;
code = get_vlc2(&s->gb, mv_vlc.table, MV_VLC_BITS, 2);
if (code == 0) {
@@ -595,11 +65,11 @@ static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred)
return 0xffff;
}
- sign = get_bits1(&s->gb);
+ sign = get_bits1(&s->gb);
shift = fcode - 1;
- val = code;
+ val = code;
if (shift) {
- val = (val - 1) << shift;
+ val = (val - 1) << shift;
val |= get_bits(&s->gb, shift);
val++;
}
@@ -608,52 +78,48 @@ static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred)
val += pred;
/* modulo decoding */
- l= INT_BIT - 5 - shift;
- val = (val<<l)>>l;
- return val;
+ return sign_extend(val, 5 + shift);
}
-static inline int mpeg1_decode_block_intra(MpegEncContext *s,
- DCTELEM *block,
- int n)
+static inline int mpeg1_decode_block_intra(MpegEncContext *s, DCTELEM *block, int n)
{
int level, dc, diff, i, j, run;
int component;
RLTable *rl = &ff_rl_mpeg1;
- uint8_t * const scantable= s->intra_scantable.permutated;
- const uint16_t *quant_matrix= s->intra_matrix;
- const int qscale= s->qscale;
+ uint8_t * const scantable = s->intra_scantable.permutated;
+ const uint16_t *quant_matrix = s->intra_matrix;
+ const int qscale = s->qscale;
/* DC coefficient */
component = (n <= 3 ? 0 : n - 4 + 1);
diff = decode_dc(&s->gb, component);
if (diff >= 0xffff)
return -1;
- dc = s->last_dc[component];
+ dc = s->last_dc[component];
dc += diff;
s->last_dc[component] = dc;
- block[0] = dc*quant_matrix[0];
+ block[0] = dc * quant_matrix[0];
av_dlog(s->avctx, "dc=%d diff=%d\n", dc, diff);
i = 0;
{
OPEN_READER(re, &s->gb);
/* now quantify & encode AC coefficients */
- for(;;) {
+ for (;;) {
UPDATE_CACHE(re, &s->gb);
GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
- if(level == 127){
+ if (level == 127) {
break;
- } else if(level != 0) {
+ } else if (level != 0) {
i += run;
j = scantable[i];
- level= (level*qscale*quant_matrix[j])>>4;
- level= (level-1)|1;
+ level = (level * qscale * quant_matrix[j]) >> 4;
+ level = (level - 1) | 1;
level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
LAST_SKIP_BITS(re, &s->gb, 1);
} else {
/* escape */
- run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6);
+ run = SHOW_UBITS(re, &s->gb, 6) + 1; LAST_SKIP_BITS(re, &s->gb, 6);
UPDATE_CACHE(re, &s->gb);
level = SHOW_SBITS(re, &s->gb, 8); SKIP_BITS(re, &s->gb, 8);
if (level == -128) {
@@ -663,17 +129,17 @@ static inline int mpeg1_decode_block_intra(MpegEncContext *s,
}
i += run;
j = scantable[i];
- if(level<0){
- level= -level;
- level= (level*qscale*quant_matrix[j])>>4;
- level= (level-1)|1;
- level= -level;
- }else{
- level= (level*qscale*quant_matrix[j])>>4;
- level= (level-1)|1;
+ if (level < 0) {
+ level = -level;
+ level = (level * qscale * quant_matrix[j]) >> 4;
+ level = (level - 1) | 1;
+ level = -level;
+ } else {
+ level = (level * qscale * quant_matrix[j]) >> 4;
+ level = (level - 1) | 1;
}
}
- if (i > 63){
+ if (i > 63) {
av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
return -1;
}
@@ -686,22 +152,18 @@ static inline int mpeg1_decode_block_intra(MpegEncContext *s,
return 0;
}
-int ff_mpeg1_decode_block_intra(MpegEncContext *s,
- DCTELEM *block,
- int n)
+int ff_mpeg1_decode_block_intra(MpegEncContext *s, DCTELEM *block, int n)
{
return mpeg1_decode_block_intra(s, block, n);
}
-static inline int mpeg1_decode_block_inter(MpegEncContext *s,
- DCTELEM *block,
- int n)
+static inline int mpeg1_decode_block_inter(MpegEncContext *s, DCTELEM *block, int n)
{
int level, i, j, run;
RLTable *rl = &ff_rl_mpeg1;
- uint8_t * const scantable= s->intra_scantable.permutated;
- const uint16_t *quant_matrix= s->inter_matrix;
- const int qscale= s->qscale;
+ uint8_t * const scantable = s->intra_scantable.permutated;
+ const uint16_t *quant_matrix = s->inter_matrix;
+ const int qscale = s->qscale;
{
OPEN_READER(re, &s->gb);
@@ -709,30 +171,30 @@ static inline int mpeg1_decode_block_inter(MpegEncContext *s,
// special case for first coefficient, no need to add second VLC table
UPDATE_CACHE(re, &s->gb);
if (((int32_t)GET_CACHE(re, &s->gb)) < 0) {
- level= (3*qscale*quant_matrix[0])>>5;
- level= (level-1)|1;
- if(GET_CACHE(re, &s->gb)&0x40000000)
- level= -level;
+ level = (3 * qscale * quant_matrix[0]) >> 5;
+ level = (level - 1) | 1;
+ if (GET_CACHE(re, &s->gb) & 0x40000000)
+ level = -level;
block[0] = level;
i++;
SKIP_BITS(re, &s->gb, 2);
- if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
+ if (((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
goto end;
}
/* now quantify & encode AC coefficients */
- for(;;) {
+ for (;;) {
GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
- if(level != 0) {
+ if (level != 0) {
i += run;
j = scantable[i];
- level= ((level*2+1)*qscale*quant_matrix[j])>>5;
- level= (level-1)|1;
+ level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
+ level = (level - 1) | 1;
level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
SKIP_BITS(re, &s->gb, 1);
} else {
/* escape */
- run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6);
+ run = SHOW_UBITS(re, &s->gb, 6) + 1; LAST_SKIP_BITS(re, &s->gb, 6);
UPDATE_CACHE(re, &s->gb);
level = SHOW_SBITS(re, &s->gb, 8); SKIP_BITS(re, &s->gb, 8);
if (level == -128) {
@@ -742,23 +204,23 @@ static inline int mpeg1_decode_block_inter(MpegEncContext *s,
}
i += run;
j = scantable[i];
- if(level<0){
- level= -level;
- level= ((level*2+1)*qscale*quant_matrix[j])>>5;
- level= (level-1)|1;
- level= -level;
- }else{
- level= ((level*2+1)*qscale*quant_matrix[j])>>5;
- level= (level-1)|1;
+ if (level < 0) {
+ level = -level;
+ level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
+ level = (level - 1) | 1;
+ level = -level;
+ } else {
+ level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
+ level = (level - 1) | 1;
}
}
- if (i > 63){
+ if (i > 63) {
av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
return -1;
}
block[j] = level;
- if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
+ if (((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
break;
UPDATE_CACHE(re, &s->gb);
}
@@ -774,8 +236,8 @@ static inline int mpeg1_fast_decode_block_inter(MpegEncContext *s, DCTELEM *bloc
{
int level, i, j, run;
RLTable *rl = &ff_rl_mpeg1;
- uint8_t * const scantable= s->intra_scantable.permutated;
- const int qscale= s->qscale;
+ uint8_t * const scantable = s->intra_scantable.permutated;
+ const int qscale = s->qscale;
{
OPEN_READER(re, &s->gb);
@@ -783,26 +245,26 @@ static inline int mpeg1_fast_decode_block_inter(MpegEncContext *s, DCTELEM *bloc
// special case for first coefficient, no need to add second VLC table
UPDATE_CACHE(re, &s->gb);
if (((int32_t)GET_CACHE(re, &s->gb)) < 0) {
- level= (3*qscale)>>1;
- level= (level-1)|1;
- if(GET_CACHE(re, &s->gb)&0x40000000)
- level= -level;
+ level = (3 * qscale) >> 1;
+ level = (level - 1) | 1;
+ if (GET_CACHE(re, &s->gb) & 0x40000000)
+ level = -level;
block[0] = level;
i++;
SKIP_BITS(re, &s->gb, 2);
- if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
+ if (((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
goto end;
}
/* now quantify & encode AC coefficients */
- for(;;) {
+ for (;;) {
GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
- if(level != 0) {
+ if (level != 0) {
i += run;
j = scantable[i];
- level= ((level*2+1)*qscale)>>1;
- level= (level-1)|1;
+ level = ((level * 2 + 1) * qscale) >> 1;
+ level = (level - 1) | 1;
level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
SKIP_BITS(re, &s->gb, 1);
} else {
@@ -817,19 +279,19 @@ static inline int mpeg1_fast_decode_block_inter(MpegEncContext *s, DCTELEM *bloc
}
i += run;
j = scantable[i];
- if(level<0){
- level= -level;
- level= ((level*2+1)*qscale)>>1;
- level= (level-1)|1;
- level= -level;
- }else{
- level= ((level*2+1)*qscale)>>1;
- level= (level-1)|1;
+ if (level < 0) {
+ level = -level;
+ level = ((level * 2 + 1) * qscale) >> 1;
+ level = (level - 1) | 1;
+ level = -level;
+ } else {
+ level = ((level * 2 + 1) * qscale) >> 1;
+ level = (level - 1) | 1;
}
}
block[j] = level;
- if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
+ if (((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
break;
UPDATE_CACHE(re, &s->gb);
}
@@ -842,15 +304,13 @@ end:
}
-static inline int mpeg2_decode_block_non_intra(MpegEncContext *s,
- DCTELEM *block,
- int n)
+static inline int mpeg2_decode_block_non_intra(MpegEncContext *s, DCTELEM *block, int n)
{
int level, i, j, run;
RLTable *rl = &ff_rl_mpeg1;
- uint8_t * const scantable= s->intra_scantable.permutated;
+ uint8_t * const scantable = s->intra_scantable.permutated;
const uint16_t *quant_matrix;
- const int qscale= s->qscale;
+ const int qscale = s->qscale;
int mismatch;
mismatch = 1;
@@ -866,50 +326,50 @@ static inline int mpeg2_decode_block_non_intra(MpegEncContext *s,
// special case for first coefficient, no need to add second VLC table
UPDATE_CACHE(re, &s->gb);
if (((int32_t)GET_CACHE(re, &s->gb)) < 0) {
- level= (3*qscale*quant_matrix[0])>>5;
- if(GET_CACHE(re, &s->gb)&0x40000000)
- level= -level;
- block[0] = level;
+ level= (3 * qscale * quant_matrix[0]) >> 5;
+ if (GET_CACHE(re, &s->gb) & 0x40000000)
+ level = -level;
+ block[0] = level;
mismatch ^= level;
i++;
SKIP_BITS(re, &s->gb, 2);
- if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
+ if (((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
goto end;
}
/* now quantify & encode AC coefficients */
- for(;;) {
+ for (;;) {
GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
- if(level != 0) {
+ if (level != 0) {
i += run;
j = scantable[i];
- level= ((level*2+1)*qscale*quant_matrix[j])>>5;
+ level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
SKIP_BITS(re, &s->gb, 1);
} else {
/* escape */
- run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6);
+ run = SHOW_UBITS(re, &s->gb, 6) + 1; LAST_SKIP_BITS(re, &s->gb, 6);
UPDATE_CACHE(re, &s->gb);
level = SHOW_SBITS(re, &s->gb, 12); SKIP_BITS(re, &s->gb, 12);
i += run;
j = scantable[i];
- if(level<0){
- level= ((-level*2+1)*qscale*quant_matrix[j])>>5;
- level= -level;
- }else{
- level= ((level*2+1)*qscale*quant_matrix[j])>>5;
+ if (level < 0) {
+ level = ((-level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
+ level = -level;
+ } else {
+ level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
}
}
- if (i > 63){
+ if (i > 63) {
av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
return -1;
}
mismatch ^= level;
- block[j] = level;
- if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
+ block[j] = level;
+ if (((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
break;
UPDATE_CACHE(re, &s->gb);
}
@@ -924,57 +384,56 @@ end:
}
static inline int mpeg2_fast_decode_block_non_intra(MpegEncContext *s,
- DCTELEM *block,
- int n)
+ DCTELEM *block, int n)
{
int level, i, j, run;
RLTable *rl = &ff_rl_mpeg1;
- uint8_t * const scantable= s->intra_scantable.permutated;
- const int qscale= s->qscale;
+ uint8_t * const scantable = s->intra_scantable.permutated;
+ const int qscale = s->qscale;
OPEN_READER(re, &s->gb);
i = -1;
// special case for first coefficient, no need to add second VLC table
UPDATE_CACHE(re, &s->gb);
if (((int32_t)GET_CACHE(re, &s->gb)) < 0) {
- level= (3*qscale)>>1;
- if(GET_CACHE(re, &s->gb)&0x40000000)
- level= -level;
+ level = (3 * qscale) >> 1;
+ if (GET_CACHE(re, &s->gb) & 0x40000000)
+ level = -level;
block[0] = level;
i++;
SKIP_BITS(re, &s->gb, 2);
- if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
+ if (((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
goto end;
}
/* now quantify & encode AC coefficients */
- for(;;) {
+ for (;;) {
GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
- if(level != 0) {
+ if (level != 0) {
i += run;
- j = scantable[i];
- level= ((level*2+1)*qscale)>>1;
+ j = scantable[i];
+ level = ((level * 2 + 1) * qscale) >> 1;
level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
SKIP_BITS(re, &s->gb, 1);
} else {
/* escape */
- run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6);
+ run = SHOW_UBITS(re, &s->gb, 6) + 1; LAST_SKIP_BITS(re, &s->gb, 6);
UPDATE_CACHE(re, &s->gb);
level = SHOW_SBITS(re, &s->gb, 12); SKIP_BITS(re, &s->gb, 12);
i += run;
- j = scantable[i];
- if(level<0){
- level= ((-level*2+1)*qscale)>>1;
- level= -level;
- }else{
- level= ((level*2+1)*qscale)>>1;
+ j = scantable[i];
+ if (level < 0) {
+ level = ((-level * 2 + 1) * qscale) >> 1;
+ level = -level;
+ } else {
+ level = ((level * 2 + 1) * qscale) >> 1;
}
}
block[j] = level;
- if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
+ if (((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
break;
UPDATE_CACHE(re, &s->gb);
}
@@ -986,30 +445,28 @@ end:
}
-static inline int mpeg2_decode_block_intra(MpegEncContext *s,
- DCTELEM *block,
- int n)
+static inline int mpeg2_decode_block_intra(MpegEncContext *s, DCTELEM *block, int n)
{
int level, dc, diff, i, j, run;
int component;
RLTable *rl;
- uint8_t * const scantable= s->intra_scantable.permutated;
+ uint8_t * const scantable = s->intra_scantable.permutated;
const uint16_t *quant_matrix;
- const int qscale= s->qscale;
+ const int qscale = s->qscale;
int mismatch;
/* DC coefficient */
- if (n < 4){
+ if (n < 4) {
quant_matrix = s->intra_matrix;
component = 0;
- }else{
+ } else {
quant_matrix = s->chroma_intra_matrix;
- component = (n&1) + 1;
+ component = (n & 1) + 1;
}
diff = decode_dc(&s->gb, component);
if (diff >= 0xffff)
return -1;
- dc = s->last_dc[component];
+ dc = s->last_dc[component];
dc += diff;
s->last_dc[component] = dc;
block[0] = dc << (3 - s->intra_dc_precision);
@@ -1024,66 +481,64 @@ static inline int mpeg2_decode_block_intra(MpegEncContext *s,
{
OPEN_READER(re, &s->gb);
/* now quantify & encode AC coefficients */
- for(;;) {
+ for (;;) {
UPDATE_CACHE(re, &s->gb);
GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
- if(level == 127){
+ if (level == 127) {
break;
- } else if(level != 0) {
+ } else if (level != 0) {
i += run;
- j = scantable[i];
- level= (level*qscale*quant_matrix[j])>>4;
+ j = scantable[i];
+ level = (level * qscale * quant_matrix[j]) >> 4;
level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
LAST_SKIP_BITS(re, &s->gb, 1);
} else {
/* escape */
- run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6);
+ run = SHOW_UBITS(re, &s->gb, 6) + 1; LAST_SKIP_BITS(re, &s->gb, 6);
UPDATE_CACHE(re, &s->gb);
level = SHOW_SBITS(re, &s->gb, 12); SKIP_BITS(re, &s->gb, 12);
i += run;
- j = scantable[i];
- if(level<0){
- level= (-level*qscale*quant_matrix[j])>>4;
- level= -level;
- }else{
- level= (level*qscale*quant_matrix[j])>>4;
+ j = scantable[i];
+ if (level < 0) {
+ level = (-level * qscale * quant_matrix[j]) >> 4;
+ level = -level;
+ } else {
+ level = (level * qscale * quant_matrix[j]) >> 4;
}
}
- if (i > 63){
+ if (i > 63) {
av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
return -1;
}
- mismatch^= level;
- block[j] = level;
+ mismatch ^= level;
+ block[j] = level;
}
CLOSE_READER(re, &s->gb);
}
- block[63]^= mismatch&1;
+ block[63] ^= mismatch & 1;
s->block_last_index[n] = i;
return 0;
}
-static inline int mpeg2_fast_decode_block_intra(MpegEncContext *s,
- DCTELEM *block,
- int n)
+static inline int mpeg2_fast_decode_block_intra(MpegEncContext *s, DCTELEM *block, int n)
{
int level, dc, diff, j, run;
int component;
RLTable *rl;
- uint8_t * scantable= s->intra_scantable.permutated;
+ uint8_t * scantable = s->intra_scantable.permutated;
const uint16_t *quant_matrix;
- const int qscale= s->qscale;
+ const int qscale = s->qscale;
/* DC coefficient */
- if (n < 4){
+ if (n < 4) {
quant_matrix = s->intra_matrix;
component = 0;
- }else{
+ } else {
quant_matrix = s->chroma_intra_matrix;
- component = (n&1) + 1;
+ component = (n & 1) + 1;
}
diff = decode_dc(&s->gb, component);
if (diff >= 0xffff)
@@ -1100,30 +555,30 @@ static inline int mpeg2_fast_decode_block_intra(MpegEncContext *s,
{
OPEN_READER(re, &s->gb);
/* now quantify & encode AC coefficients */
- for(;;) {
+ for (;;) {
UPDATE_CACHE(re, &s->gb);
GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
- if(level == 127){
+ if (level == 127) {
break;
- } else if(level != 0) {
+ } else if (level != 0) {
scantable += run;
j = *scantable;
- level= (level*qscale*quant_matrix[j])>>4;
+ level = (level * qscale * quant_matrix[j]) >> 4;
level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
LAST_SKIP_BITS(re, &s->gb, 1);
} else {
/* escape */
- run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6);
+ run = SHOW_UBITS(re, &s->gb, 6) + 1; LAST_SKIP_BITS(re, &s->gb, 6);
UPDATE_CACHE(re, &s->gb);
level = SHOW_SBITS(re, &s->gb, 12); SKIP_BITS(re, &s->gb, 12);
scantable += run;
j = *scantable;
- if(level<0){
- level= (-level*qscale*quant_matrix[j])>>4;
- level= -level;
- }else{
- level= (level*qscale*quant_matrix[j])>>4;
+ if (level < 0) {
+ level = (-level * qscale * quant_matrix[j]) >> 4;
+ level = -level;
+ } else {
+ level = (level * qscale * quant_matrix[j]) >> 4;
}
}
@@ -1136,6 +591,527 @@ static inline int mpeg2_fast_decode_block_intra(MpegEncContext *s,
return 0;
}
+uint8_t ff_mpeg12_static_rl_table_store[2][2][2*MAX_RUN + MAX_LEVEL + 3];
+
+#define INIT_2D_VLC_RL(rl, static_size)\
+{\
+ static RL_VLC_ELEM rl_vlc_table[static_size];\
+ INIT_VLC_STATIC(&rl.vlc, TEX_VLC_BITS, rl.n + 2,\
+ &rl.table_vlc[0][1], 4, 2,\
+ &rl.table_vlc[0][0], 4, 2, static_size);\
+\
+ rl.rl_vlc[0] = rl_vlc_table;\
+ init_2d_vlc_rl(&rl);\
+}
+
+static void init_2d_vlc_rl(RLTable *rl)
+{
+ int i;
+
+ for (i = 0; i < rl->vlc.table_size; i++) {
+ int code = rl->vlc.table[i][0];
+ int len = rl->vlc.table[i][1];
+ int level, run;
+
+ if (len == 0) { // illegal code
+ run = 65;
+ level = MAX_LEVEL;
+ } else if (len<0) { //more bits needed
+ run = 0;
+ level = code;
+ } else {
+ if (code == rl->n) { //esc
+ run = 65;
+ level = 0;
+ } else if (code == rl->n+1) { //eob
+ run = 0;
+ level = 127;
+ } else {
+ run = rl->table_run [code] + 1;
+ level = rl->table_level[code];
+ }
+ }
+ rl->rl_vlc[0][i].len = len;
+ rl->rl_vlc[0][i].level = level;
+ rl->rl_vlc[0][i].run = run;
+ }
+}
+
+void ff_mpeg12_common_init(MpegEncContext *s)
+{
+
+ s->y_dc_scale_table =
+ s->c_dc_scale_table = ff_mpeg2_dc_scale_table[s->intra_dc_precision];
+
+}
+
+void ff_mpeg1_clean_buffers(MpegEncContext *s)
+{
+ s->last_dc[0] = 1 << (7 + s->intra_dc_precision);
+ s->last_dc[1] = s->last_dc[0];
+ s->last_dc[2] = s->last_dc[0];
+ memset(s->last_mv, 0, sizeof(s->last_mv));
+}
+
+
+/******************************************/
+/* decoding */
+
+VLC ff_dc_lum_vlc;
+VLC ff_dc_chroma_vlc;
+
+static VLC mbincr_vlc;
+static VLC mb_ptype_vlc;
+static VLC mb_btype_vlc;
+static VLC mb_pat_vlc;
+
+av_cold void ff_mpeg12_init_vlcs(void)
+{
+ static int done = 0;
+
+ if (!done) {
+ done = 1;
+
+ INIT_VLC_STATIC(&ff_dc_lum_vlc, DC_VLC_BITS, 12,
+ ff_mpeg12_vlc_dc_lum_bits, 1, 1,
+ ff_mpeg12_vlc_dc_lum_code, 2, 2, 512);
+ INIT_VLC_STATIC(&ff_dc_chroma_vlc, DC_VLC_BITS, 12,
+ ff_mpeg12_vlc_dc_chroma_bits, 1, 1,
+ ff_mpeg12_vlc_dc_chroma_code, 2, 2, 514);
+ INIT_VLC_STATIC(&mv_vlc, MV_VLC_BITS, 17,
+ &ff_mpeg12_mbMotionVectorTable[0][1], 2, 1,
+ &ff_mpeg12_mbMotionVectorTable[0][0], 2, 1, 518);
+ INIT_VLC_STATIC(&mbincr_vlc, MBINCR_VLC_BITS, 36,
+ &ff_mpeg12_mbAddrIncrTable[0][1], 2, 1,
+ &ff_mpeg12_mbAddrIncrTable[0][0], 2, 1, 538);
+ INIT_VLC_STATIC(&mb_pat_vlc, MB_PAT_VLC_BITS, 64,
+ &ff_mpeg12_mbPatTable[0][1], 2, 1,
+ &ff_mpeg12_mbPatTable[0][0], 2, 1, 512);
+
+ INIT_VLC_STATIC(&mb_ptype_vlc, MB_PTYPE_VLC_BITS, 7,
+ &table_mb_ptype[0][1], 2, 1,
+ &table_mb_ptype[0][0], 2, 1, 64);
+ INIT_VLC_STATIC(&mb_btype_vlc, MB_BTYPE_VLC_BITS, 11,
+ &table_mb_btype[0][1], 2, 1,
+ &table_mb_btype[0][0], 2, 1, 64);
+ init_rl(&ff_rl_mpeg1, ff_mpeg12_static_rl_table_store[0]);
+ init_rl(&ff_rl_mpeg2, ff_mpeg12_static_rl_table_store[1]);
+
+ INIT_2D_VLC_RL(ff_rl_mpeg1, 680);
+ INIT_2D_VLC_RL(ff_rl_mpeg2, 674);
+ }
+}
+
+static inline int get_dmv(MpegEncContext *s)
+{
+ if (get_bits1(&s->gb))
+ return 1 - (get_bits1(&s->gb) << 1);
+ else
+ return 0;
+}
+
+static inline int get_qscale(MpegEncContext *s)
+{
+ int qscale = get_bits(&s->gb, 5);
+ if (s->q_scale_type) {
+ return non_linear_qscale[qscale];
+ } else {
+ return qscale << 1;
+ }
+}
+
+static void exchange_uv(MpegEncContext *s)
+{
+ DCTELEM (*tmp)[64];
+
+ tmp = s->pblocks[4];
+ s->pblocks[4] = s->pblocks[5];
+ s->pblocks[5] = tmp;
+}
+
+/* motion type (for MPEG-2) */
+#define MT_FIELD 1
+#define MT_FRAME 2
+#define MT_16X8 2
+#define MT_DMV 3
+
+static int mpeg_decode_mb(MpegEncContext *s, DCTELEM block[12][64])
+{
+ int i, j, k, cbp, val, mb_type, motion_type;
+ const int mb_block_count = 4 + (1 << s->chroma_format);
+
+ av_dlog(s->avctx, "decode_mb: x=%d y=%d\n", s->mb_x, s->mb_y);
+
+ assert(s->mb_skipped == 0);
+
+ if (s->mb_skip_run-- != 0) {
+ if (s->pict_type == AV_PICTURE_TYPE_P) {
+ s->mb_skipped = 1;
+ s->current_picture.f.mb_type[s->mb_x + s->mb_y * s->mb_stride] = MB_TYPE_SKIP | MB_TYPE_L0 | MB_TYPE_16x16;
+ } else {
+ int mb_type;
+
+ if (s->mb_x)
+ mb_type = s->current_picture.f.mb_type[s->mb_x + s->mb_y * s->mb_stride - 1];
+ else
+ mb_type = s->current_picture.f.mb_type[s->mb_width + (s->mb_y - 1) * s->mb_stride - 1]; // FIXME not sure if this is allowed in MPEG at all
+ if (IS_INTRA(mb_type))
+ return -1;
+ s->current_picture.f.mb_type[s->mb_x + s->mb_y*s->mb_stride] =
+ mb_type | MB_TYPE_SKIP;
+// assert(s->current_picture.f.mb_type[s->mb_x + s->mb_y * s->mb_stride - 1] & (MB_TYPE_16x16 | MB_TYPE_16x8));
+
+ if ((s->mv[0][0][0] | s->mv[0][0][1] | s->mv[1][0][0] | s->mv[1][0][1]) == 0)
+ s->mb_skipped = 1;
+ }
+
+ return 0;
+ }
+
+ switch (s->pict_type) {
+ default:
+ case AV_PICTURE_TYPE_I:
+ if (get_bits1(&s->gb) == 0) {
+ if (get_bits1(&s->gb) == 0) {
+ av_log(s->avctx, AV_LOG_ERROR, "invalid mb type in I Frame at %d %d\n", s->mb_x, s->mb_y);
+ return -1;
+ }
+ mb_type = MB_TYPE_QUANT | MB_TYPE_INTRA;
+ } else {
+ mb_type = MB_TYPE_INTRA;
+ }
+ break;
+ case AV_PICTURE_TYPE_P:
+ mb_type = get_vlc2(&s->gb, mb_ptype_vlc.table, MB_PTYPE_VLC_BITS, 1);
+ if (mb_type < 0) {
+ av_log(s->avctx, AV_LOG_ERROR, "invalid mb type in P Frame at %d %d\n", s->mb_x, s->mb_y);
+ return -1;
+ }
+ mb_type = ptype2mb_type[mb_type];
+ break;
+ case AV_PICTURE_TYPE_B:
+ mb_type = get_vlc2(&s->gb, mb_btype_vlc.table, MB_BTYPE_VLC_BITS, 1);
+ if (mb_type < 0) {
+ av_log(s->avctx, AV_LOG_ERROR, "invalid mb type in B Frame at %d %d\n", s->mb_x, s->mb_y);
+ return -1;
+ }
+ mb_type = btype2mb_type[mb_type];
+ break;
+ }
+ av_dlog(s->avctx, "mb_type=%x\n", mb_type);
+// motion_type = 0; /* avoid warning */
+ if (IS_INTRA(mb_type)) {
+ s->dsp.clear_blocks(s->block[0]);
+
+ if (!s->chroma_y_shift) {
+ s->dsp.clear_blocks(s->block[6]);
+ }
+
+ /* compute DCT type */
+ if (s->picture_structure == PICT_FRAME && // FIXME add an interlaced_dct coded var?
+ !s->frame_pred_frame_dct) {
+ s->interlaced_dct = get_bits1(&s->gb);
+ }
+
+ if (IS_QUANT(mb_type))
+ s->qscale = get_qscale(s);
+
+ if (s->concealment_motion_vectors) {
+ /* just parse them */
+ if (s->picture_structure != PICT_FRAME)
+ skip_bits1(&s->gb); /* field select */
+
+ s->mv[0][0][0]= s->last_mv[0][0][0]= s->last_mv[0][1][0] =
+ mpeg_decode_motion(s, s->mpeg_f_code[0][0], s->last_mv[0][0][0]);
+ s->mv[0][0][1]= s->last_mv[0][0][1]= s->last_mv[0][1][1] =
+ mpeg_decode_motion(s, s->mpeg_f_code[0][1], s->last_mv[0][0][1]);
+
+ skip_bits1(&s->gb); /* marker */
+ } else
+ memset(s->last_mv, 0, sizeof(s->last_mv)); /* reset mv prediction */
+ s->mb_intra = 1;
+ // if 1, we memcpy blocks in xvmcvideo
+ if (CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration > 1) {
+ ff_xvmc_pack_pblocks(s, -1); // inter are always full blocks
+ if (s->swap_uv) {
+ exchange_uv(s);
+ }
+ }
+
+ if (s->codec_id == CODEC_ID_MPEG2VIDEO) {
+ if (s->flags2 & CODEC_FLAG2_FAST) {
+ for (i = 0; i < 6; i++) {
+ mpeg2_fast_decode_block_intra(s, *s->pblocks[i], i);
+ }
+ } else {
+ for (i = 0; i < mb_block_count; i++) {
+ if (mpeg2_decode_block_intra(s, *s->pblocks[i], i) < 0)
+ return -1;
+ }
+ }
+ } else {
+ for (i = 0; i < 6; i++) {
+ if (mpeg1_decode_block_intra(s, *s->pblocks[i], i) < 0)
+ return -1;
+ }
+ }
+ } else {
+ if (mb_type & MB_TYPE_ZERO_MV) {
+ assert(mb_type & MB_TYPE_CBP);
+
+ s->mv_dir = MV_DIR_FORWARD;
+ if (s->picture_structure == PICT_FRAME) {
+ if (!s->frame_pred_frame_dct)
+ s->interlaced_dct = get_bits1(&s->gb);
+ s->mv_type = MV_TYPE_16X16;
+ } else {
+ s->mv_type = MV_TYPE_FIELD;
+ mb_type |= MB_TYPE_INTERLACED;
+ s->field_select[0][0] = s->picture_structure - 1;
+ }
+
+ if (IS_QUANT(mb_type))
+ s->qscale = get_qscale(s);
+
+ s->last_mv[0][0][0] = 0;
+ s->last_mv[0][0][1] = 0;
+ s->last_mv[0][1][0] = 0;
+ s->last_mv[0][1][1] = 0;
+ s->mv[0][0][0] = 0;
+ s->mv[0][0][1] = 0;
+ } else {
+ assert(mb_type & MB_TYPE_L0L1);
+ // FIXME decide if MBs in field pictures are MB_TYPE_INTERLACED
+ /* get additional motion vector type */
+ if (s->frame_pred_frame_dct)
+ motion_type = MT_FRAME;
+ else {
+ motion_type = get_bits(&s->gb, 2);
+ if (s->picture_structure == PICT_FRAME && HAS_CBP(mb_type))
+ s->interlaced_dct = get_bits1(&s->gb);
+ }
+
+ if (IS_QUANT(mb_type))
+ s->qscale = get_qscale(s);
+
+ /* motion vectors */
+ s->mv_dir = (mb_type >> 13) & 3;
+ av_dlog(s->avctx, "motion_type=%d\n", motion_type);
+ switch (motion_type) {
+ case MT_FRAME: /* or MT_16X8 */
+ if (s->picture_structure == PICT_FRAME) {
+ mb_type |= MB_TYPE_16x16;
+ s->mv_type = MV_TYPE_16X16;
+ for (i = 0; i < 2; i++) {
+ if (USES_LIST(mb_type, i)) {
+ /* MT_FRAME */
+ s->mv[i][0][0]= s->last_mv[i][0][0]= s->last_mv[i][1][0] =
+ mpeg_decode_motion(s, s->mpeg_f_code[i][0], s->last_mv[i][0][0]);
+ s->mv[i][0][1]= s->last_mv[i][0][1]= s->last_mv[i][1][1] =
+ mpeg_decode_motion(s, s->mpeg_f_code[i][1], s->last_mv[i][0][1]);
+ /* full_pel: only for MPEG-1 */
+ if (s->full_pel[i]) {
+ s->mv[i][0][0] <<= 1;
+ s->mv[i][0][1] <<= 1;
+ }
+ }
+ }
+ } else {
+ mb_type |= MB_TYPE_16x8 | MB_TYPE_INTERLACED;
+ s->mv_type = MV_TYPE_16X8;
+ for (i = 0; i < 2; i++) {
+ if (USES_LIST(mb_type, i)) {
+ /* MT_16X8 */
+ for (j = 0; j < 2; j++) {
+ s->field_select[i][j] = get_bits1(&s->gb);
+ for (k = 0; k < 2; k++) {
+ val = mpeg_decode_motion(s, s->mpeg_f_code[i][k],
+ s->last_mv[i][j][k]);
+ s->last_mv[i][j][k] = val;
+ s->mv[i][j][k] = val;
+ }
+ }
+ }
+ }
+ }
+ break;
+ case MT_FIELD:
+ s->mv_type = MV_TYPE_FIELD;
+ if (s->picture_structure == PICT_FRAME) {
+ mb_type |= MB_TYPE_16x8 | MB_TYPE_INTERLACED;
+ for (i = 0; i < 2; i++) {
+ if (USES_LIST(mb_type, i)) {
+ for (j = 0; j < 2; j++) {
+ s->field_select[i][j] = get_bits1(&s->gb);
+ val = mpeg_decode_motion(s, s->mpeg_f_code[i][0],
+ s->last_mv[i][j][0]);
+ s->last_mv[i][j][0] = val;
+ s->mv[i][j][0] = val;
+ av_dlog(s->avctx, "fmx=%d\n", val);
+ val = mpeg_decode_motion(s, s->mpeg_f_code[i][1],
+ s->last_mv[i][j][1] >> 1);
+ s->last_mv[i][j][1] = val << 1;
+ s->mv[i][j][1] = val;
+ av_dlog(s->avctx, "fmy=%d\n", val);
+ }
+ }
+ }
+ } else {
+ av_assert0(!s->progressive_sequence);
+ mb_type |= MB_TYPE_16x16 | MB_TYPE_INTERLACED;
+ for (i = 0; i < 2; i++) {
+ if (USES_LIST(mb_type, i)) {
+ s->field_select[i][0] = get_bits1(&s->gb);
+ for (k = 0; k < 2; k++) {
+ val = mpeg_decode_motion(s, s->mpeg_f_code[i][k],
+ s->last_mv[i][0][k]);
+ s->last_mv[i][0][k] = val;
+ s->last_mv[i][1][k] = val;
+ s->mv[i][0][k] = val;
+ }
+ }
+ }
+ }
+ break;
+ case MT_DMV:
+ if(s->progressive_sequence){
+ av_log(s->avctx, AV_LOG_ERROR, "MT_DMV in progressive_sequence\n");
+ return -1;
+ }
+ s->mv_type = MV_TYPE_DMV;
+ for (i = 0; i < 2; i++) {
+ if (USES_LIST(mb_type, i)) {
+ int dmx, dmy, mx, my, m;
+ const int my_shift = s->picture_structure == PICT_FRAME;
+
+ mx = mpeg_decode_motion(s, s->mpeg_f_code[i][0],
+ s->last_mv[i][0][0]);
+ s->last_mv[i][0][0] = mx;
+ s->last_mv[i][1][0] = mx;
+ dmx = get_dmv(s);
+ my = mpeg_decode_motion(s, s->mpeg_f_code[i][1],
+ s->last_mv[i][0][1] >> my_shift);
+ dmy = get_dmv(s);
+
+
+ s->last_mv[i][0][1] = my << my_shift;
+ s->last_mv[i][1][1] = my << my_shift;
+
+ s->mv[i][0][0] = mx;
+ s->mv[i][0][1] = my;
+ s->mv[i][1][0] = mx; // not used
+ s->mv[i][1][1] = my; // not used
+
+ if (s->picture_structure == PICT_FRAME) {
+ mb_type |= MB_TYPE_16x16 | MB_TYPE_INTERLACED;
+
+ // m = 1 + 2 * s->top_field_first;
+ m = s->top_field_first ? 1 : 3;
+
+ /* top -> top pred */
+ s->mv[i][2][0] = ((mx * m + (mx > 0)) >> 1) + dmx;
+ s->mv[i][2][1] = ((my * m + (my > 0)) >> 1) + dmy - 1;
+ m = 4 - m;
+ s->mv[i][3][0] = ((mx * m + (mx > 0)) >> 1) + dmx;
+ s->mv[i][3][1] = ((my * m + (my > 0)) >> 1) + dmy + 1;
+ } else {
+ mb_type |= MB_TYPE_16x16;
+
+ s->mv[i][2][0] = ((mx + (mx > 0)) >> 1) + dmx;
+ s->mv[i][2][1] = ((my + (my > 0)) >> 1) + dmy;
+ if (s->picture_structure == PICT_TOP_FIELD)
+ s->mv[i][2][1]--;
+ else
+ s->mv[i][2][1]++;
+ }
+ }
+ }
+ break;
+ default:
+ av_log(s->avctx, AV_LOG_ERROR, "00 motion_type at %d %d\n", s->mb_x, s->mb_y);
+ return -1;
+ }
+ }
+
+ s->mb_intra = 0;
+ if (HAS_CBP(mb_type)) {
+ s->dsp.clear_blocks(s->block[0]);
+
+ cbp = get_vlc2(&s->gb, mb_pat_vlc.table, MB_PAT_VLC_BITS, 1);
+ if (mb_block_count > 6) {
+ cbp <<= mb_block_count - 6;
+ cbp |= get_bits(&s->gb, mb_block_count - 6);
+ s->dsp.clear_blocks(s->block[6]);
+ }
+ if (cbp <= 0) {
+ av_log(s->avctx, AV_LOG_ERROR, "invalid cbp at %d %d\n", s->mb_x, s->mb_y);
+ return -1;
+ }
+
+ //if 1, we memcpy blocks in xvmcvideo
+ if (CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration > 1) {
+ ff_xvmc_pack_pblocks(s, cbp);
+ if (s->swap_uv) {
+ exchange_uv(s);
+ }
+ }
+
+ if (s->codec_id == CODEC_ID_MPEG2VIDEO) {
+ if (s->flags2 & CODEC_FLAG2_FAST) {
+ for (i = 0; i < 6; i++) {
+ if (cbp & 32) {
+ mpeg2_fast_decode_block_non_intra(s, *s->pblocks[i], i);
+ } else {
+ s->block_last_index[i] = -1;
+ }
+ cbp += cbp;
+ }
+ } else {
+ cbp <<= 12-mb_block_count;
+
+ for (i = 0; i < mb_block_count; i++) {
+ if (cbp & (1 << 11)) {
+ if (mpeg2_decode_block_non_intra(s, *s->pblocks[i], i) < 0)
+ return -1;
+ } else {
+ s->block_last_index[i] = -1;
+ }
+ cbp += cbp;
+ }
+ }
+ } else {
+ if (s->flags2 & CODEC_FLAG2_FAST) {
+ for (i = 0; i < 6; i++) {
+ if (cbp & 32) {
+ mpeg1_fast_decode_block_inter(s, *s->pblocks[i], i);
+ } else {
+ s->block_last_index[i] = -1;
+ }
+ cbp += cbp;
+ }
+ } else {
+ for (i = 0; i < 6; i++) {
+ if (cbp & 32) {
+ if (mpeg1_decode_block_inter(s, *s->pblocks[i], i) < 0)
+ return -1;
+ } else {
+ s->block_last_index[i] = -1;
+ }
+ cbp += cbp;
+ }
+ }
+ }
+ } else {
+ for (i = 0; i < 12; i++)
+ s->block_last_index[i] = -1;
+ }
+ }
+
+ s->current_picture.f.mb_type[s->mb_x + s->mb_y * s->mb_stride] = mb_type;
+
+ return 0;
+}
+
typedef struct Mpeg1Context {
MpegEncContext mpeg_enc_ctx;
int mpeg_enc_ctx_allocated; /* true if decoding context allocated */
@@ -1147,6 +1123,7 @@ typedef struct Mpeg1Context {
int save_width, save_height, save_progressive_seq;
AVRational frame_rate_ext; ///< MPEG-2 specific framerate modificator
int sync; ///< Did we reach a sync point like a GOP/SEQ/KEYFrame?
+ int tmpgexs;
} Mpeg1Context;
static av_cold int mpeg_decode_init(AVCodecContext *avctx)
@@ -1157,22 +1134,22 @@ static av_cold int mpeg_decode_init(AVCodecContext *avctx)
/* we need some permutation to store matrices,
* until MPV_common_init() sets the real permutation. */
- for(i=0;i<64;i++)
+ for (i = 0; i < 64; i++)
s2->dsp.idct_permutation[i]=i;
MPV_decode_defaults(s2);
- s->mpeg_enc_ctx.avctx= avctx;
- s->mpeg_enc_ctx.flags= avctx->flags;
- s->mpeg_enc_ctx.flags2= avctx->flags2;
+ s->mpeg_enc_ctx.avctx = avctx;
+ s->mpeg_enc_ctx.flags = avctx->flags;
+ s->mpeg_enc_ctx.flags2 = avctx->flags2;
ff_mpeg12_common_init(&s->mpeg_enc_ctx);
ff_mpeg12_init_vlcs();
- s->mpeg_enc_ctx_allocated = 0;
+ s->mpeg_enc_ctx_allocated = 0;
s->mpeg_enc_ctx.picture_number = 0;
- s->repeat_field = 0;
- s->mpeg_enc_ctx.codec_id= avctx->codec->id;
- avctx->color_range= AVCOL_RANGE_MPEG;
+ s->repeat_field = 0;
+ s->mpeg_enc_ctx.codec_id = avctx->codec->id;
+ avctx->color_range = AVCOL_RANGE_MPEG;
if (avctx->codec->id == CODEC_ID_MPEG1VIDEO)
avctx->chroma_sample_location = AVCHROMA_LOC_CENTER;
else
@@ -1186,168 +1163,197 @@ static int mpeg_decode_update_thread_context(AVCodecContext *avctx, const AVCode
MpegEncContext *s = &ctx->mpeg_enc_ctx, *s1 = &ctx_from->mpeg_enc_ctx;
int err;
- if(avctx == avctx_from || !ctx_from->mpeg_enc_ctx_allocated || !s1->context_initialized)
+ if (avctx == avctx_from || !ctx_from->mpeg_enc_ctx_allocated || !s1->context_initialized)
return 0;
err = ff_mpeg_update_thread_context(avctx, avctx_from);
- if(err) return err;
+ if (err) return err;
- if(!ctx->mpeg_enc_ctx_allocated)
+ if (!ctx->mpeg_enc_ctx_allocated)
memcpy(s + 1, s1 + 1, sizeof(Mpeg1Context) - sizeof(MpegEncContext));
- if(!(s->pict_type == FF_B_TYPE || s->low_delay))
+ if (!(s->pict_type == AV_PICTURE_TYPE_B || s->low_delay))
s->picture_number++;
return 0;
}
static void quant_matrix_rebuild(uint16_t *matrix, const uint8_t *old_perm,
- const uint8_t *new_perm){
+ const uint8_t *new_perm)
+{
uint16_t temp_matrix[64];
int i;
- memcpy(temp_matrix,matrix,64*sizeof(uint16_t));
+ memcpy(temp_matrix, matrix, 64 * sizeof(uint16_t));
- for(i=0;i<64;i++){
+ for (i = 0; i < 64; i++) {
matrix[new_perm[i]] = temp_matrix[old_perm[i]];
}
}
-static enum PixelFormat mpeg_get_pixelformat(AVCodecContext *avctx){
+static const enum PixelFormat mpeg1_hwaccel_pixfmt_list_420[] = {
+#if CONFIG_MPEG_XVMC_DECODER
+ PIX_FMT_XVMC_MPEG2_IDCT,
+ PIX_FMT_XVMC_MPEG2_MC,
+#endif
+#if CONFIG_MPEG1_VDPAU_HWACCEL
+ PIX_FMT_VDPAU_MPEG1,
+#endif
+ PIX_FMT_YUV420P,
+ PIX_FMT_NONE
+};
+
+static const enum PixelFormat mpeg2_hwaccel_pixfmt_list_420[] = {
+#if CONFIG_MPEG_XVMC_DECODER
+ PIX_FMT_XVMC_MPEG2_IDCT,
+ PIX_FMT_XVMC_MPEG2_MC,
+#endif
+#if CONFIG_MPEG2_VDPAU_HWACCEL
+ PIX_FMT_VDPAU_MPEG2,
+#endif
+#if CONFIG_MPEG2_DXVA2_HWACCEL
+ PIX_FMT_DXVA2_VLD,
+#endif
+#if CONFIG_MPEG2_VAAPI_HWACCEL
+ PIX_FMT_VAAPI_VLD,
+#endif
+ PIX_FMT_YUV420P,
+ PIX_FMT_NONE
+};
+
+static inline int uses_vdpau(AVCodecContext *avctx) {
+ return avctx->pix_fmt == PIX_FMT_VDPAU_MPEG1 || avctx->pix_fmt == PIX_FMT_VDPAU_MPEG2;
+}
+
+static enum PixelFormat mpeg_get_pixelformat(AVCodecContext *avctx)
+{
Mpeg1Context *s1 = avctx->priv_data;
MpegEncContext *s = &s1->mpeg_enc_ctx;
- if(avctx->xvmc_acceleration)
- return avctx->get_format(avctx,pixfmt_xvmc_mpg2_420);
- else if(avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU){
- if(avctx->codec_id == CODEC_ID_MPEG1VIDEO)
- return PIX_FMT_VDPAU_MPEG1;
- else
- return PIX_FMT_VDPAU_MPEG2;
- }else{
- if(s->chroma_format < 2)
- return avctx->get_format(avctx,ff_hwaccel_pixfmt_list_420);
- else if(s->chroma_format == 2)
- return PIX_FMT_YUV422P;
- else
- return PIX_FMT_YUV444P;
- }
+ if(s->chroma_format < 2) {
+ enum PixelFormat res;
+ res = avctx->get_format(avctx,
+ avctx->codec_id == CODEC_ID_MPEG1VIDEO ?
+ mpeg1_hwaccel_pixfmt_list_420 :
+ mpeg2_hwaccel_pixfmt_list_420);
+ if (res != PIX_FMT_XVMC_MPEG2_IDCT && res != PIX_FMT_XVMC_MPEG2_MC) {
+ avctx->xvmc_acceleration = 0;
+ } else if (!avctx->xvmc_acceleration) {
+ avctx->xvmc_acceleration = 2;
+ }
+ return res;
+ } else if(s->chroma_format == 2)
+ return PIX_FMT_YUV422P;
+ else
+ return PIX_FMT_YUV444P;
}
/* Call this function when we know all parameters.
* It may be called in different places for MPEG-1 and MPEG-2. */
-static int mpeg_decode_postinit(AVCodecContext *avctx){
+static int mpeg_decode_postinit(AVCodecContext *avctx)
+{
Mpeg1Context *s1 = avctx->priv_data;
MpegEncContext *s = &s1->mpeg_enc_ctx;
uint8_t old_permutation[64];
- if (
- (s1->mpeg_enc_ctx_allocated == 0)||
- avctx->coded_width != s->width ||
- avctx->coded_height != s->height||
- s1->save_width != s->width ||
- s1->save_height != s->height ||
- s1->save_aspect_info != s->aspect_ratio_info||
+ if ((s1->mpeg_enc_ctx_allocated == 0) ||
+ avctx->coded_width != s->width ||
+ avctx->coded_height != s->height ||
+ s1->save_width != s->width ||
+ s1->save_height != s->height ||
+ s1->save_aspect_info != s->aspect_ratio_info ||
s1->save_progressive_seq != s->progressive_sequence ||
0)
{
if (s1->mpeg_enc_ctx_allocated) {
- ParseContext pc= s->parse_context;
- s->parse_context.buffer=0;
+ ParseContext pc = s->parse_context;
+ s->parse_context.buffer = 0;
MPV_common_end(s);
- s->parse_context= pc;
+ s->parse_context = pc;
}
- if( (s->width == 0 )||(s->height == 0))
+ if ((s->width == 0) || (s->height == 0))
return -2;
avcodec_set_dimensions(avctx, s->width, s->height);
- avctx->bit_rate = s->bit_rate;
- s1->save_aspect_info = s->aspect_ratio_info;
- s1->save_width = s->width;
- s1->save_height = s->height;
+ avctx->bit_rate = s->bit_rate;
+ s1->save_aspect_info = s->aspect_ratio_info;
+ s1->save_width = s->width;
+ s1->save_height = s->height;
s1->save_progressive_seq = s->progressive_sequence;
/* low_delay may be forced, in this case we will have B-frames
* that behave like P-frames. */
avctx->has_b_frames = !(s->low_delay);
- assert((avctx->sub_id==1) == (avctx->codec_id==CODEC_ID_MPEG1VIDEO));
- if(avctx->codec_id==CODEC_ID_MPEG1VIDEO){
+ assert((avctx->sub_id == 1) == (avctx->codec_id == CODEC_ID_MPEG1VIDEO));
+ if (avctx->codec_id == CODEC_ID_MPEG1VIDEO) {
//MPEG-1 fps
- avctx->time_base.den= ff_frame_rate_tab[s->frame_rate_index].num;
- avctx->time_base.num= ff_frame_rate_tab[s->frame_rate_index].den;
+ avctx->time_base.den = avpriv_frame_rate_tab[s->frame_rate_index].num;
+ avctx->time_base.num = avpriv_frame_rate_tab[s->frame_rate_index].den;
//MPEG-1 aspect
- avctx->sample_aspect_ratio= av_d2q(
- 1.0/ff_mpeg1_aspect[s->aspect_ratio_info], 255);
+ avctx->sample_aspect_ratio = av_d2q(1.0/ff_mpeg1_aspect[s->aspect_ratio_info], 255);
avctx->ticks_per_frame=1;
- }else{//MPEG-2
+ } else {//MPEG-2
//MPEG-2 fps
- av_reduce(
- &s->avctx->time_base.den,
- &s->avctx->time_base.num,
- ff_frame_rate_tab[s->frame_rate_index].num * s1->frame_rate_ext.num*2,
- ff_frame_rate_tab[s->frame_rate_index].den * s1->frame_rate_ext.den,
- 1<<30);
- avctx->ticks_per_frame=2;
- //MPEG-2 aspect
- if(s->aspect_ratio_info > 1){
+ av_reduce(&s->avctx->time_base.den,
+ &s->avctx->time_base.num,
+ avpriv_frame_rate_tab[s->frame_rate_index].num * s1->frame_rate_ext.num*2,
+ avpriv_frame_rate_tab[s->frame_rate_index].den * s1->frame_rate_ext.den,
+ 1 << 30);
+ avctx->ticks_per_frame = 2;
+ //MPEG-2 aspect
+ if (s->aspect_ratio_info > 1) {
AVRational dar =
- av_mul_q(
- av_div_q(ff_mpeg2_aspect[s->aspect_ratio_info],
- (AVRational){s1->pan_scan.width, s1->pan_scan.height}),
- (AVRational){s->width, s->height});
+ av_mul_q(av_div_q(ff_mpeg2_aspect[s->aspect_ratio_info],
+ (AVRational) {s1->pan_scan.width, s1->pan_scan.height}),
+ (AVRational) {s->width, s->height});
// we ignore the spec here and guess a bit as reality does not match the spec, see for example
// res_change_ffmpeg_aspect.ts and sequence-display-aspect.mpg
// issue1613, 621, 562
- if((s1->pan_scan.width == 0 ) || (s1->pan_scan.height == 0) ||
- (av_cmp_q(dar,(AVRational){4,3}) && av_cmp_q(dar,(AVRational){16,9}))) {
- s->avctx->sample_aspect_ratio=
- av_div_q(
- ff_mpeg2_aspect[s->aspect_ratio_info],
- (AVRational){s->width, s->height}
- );
- }else{
- s->avctx->sample_aspect_ratio=
- av_div_q(
- ff_mpeg2_aspect[s->aspect_ratio_info],
- (AVRational){s1->pan_scan.width, s1->pan_scan.height}
- );
+ if ((s1->pan_scan.width == 0) || (s1->pan_scan.height == 0) ||
+ (av_cmp_q(dar, (AVRational) {4, 3}) && av_cmp_q(dar, (AVRational) {16, 9}))) {
+ s->avctx->sample_aspect_ratio =
+ av_div_q(ff_mpeg2_aspect[s->aspect_ratio_info],
+ (AVRational) {s->width, s->height});
+ } else {
+ s->avctx->sample_aspect_ratio =
+ av_div_q(ff_mpeg2_aspect[s->aspect_ratio_info],
+ (AVRational) {s1->pan_scan.width, s1->pan_scan.height});
//issue1613 4/3 16/9 -> 16/9
//res_change_ffmpeg_aspect.ts 4/3 225/44 ->4/3
//widescreen-issue562.mpg 4/3 16/9 -> 16/9
-// s->avctx->sample_aspect_ratio= av_mul_q(s->avctx->sample_aspect_ratio, (AVRational){s->width, s->height});
-//av_log(NULL, AV_LOG_ERROR, "A %d/%d\n",ff_mpeg2_aspect[s->aspect_ratio_info].num, ff_mpeg2_aspect[s->aspect_ratio_info].den);
-//av_log(NULL, AV_LOG_ERROR, "B %d/%d\n",s->avctx->sample_aspect_ratio.num, s->avctx->sample_aspect_ratio.den);
+// s->avctx->sample_aspect_ratio = av_mul_q(s->avctx->sample_aspect_ratio, (AVRational) {s->width, s->height});
+//av_log(NULL, AV_LOG_ERROR, "A %d/%d\n", ff_mpeg2_aspect[s->aspect_ratio_info].num, ff_mpeg2_aspect[s->aspect_ratio_info].den);
+//av_log(NULL, AV_LOG_ERROR, "B %d/%d\n", s->avctx->sample_aspect_ratio.num, s->avctx->sample_aspect_ratio.den);
}
- }else{
- s->avctx->sample_aspect_ratio=
+ } else {
+ s->avctx->sample_aspect_ratio =
ff_mpeg2_aspect[s->aspect_ratio_info];
}
- }//MPEG-2
+ } // MPEG-2
avctx->pix_fmt = mpeg_get_pixelformat(avctx);
avctx->hwaccel = ff_find_hwaccel(avctx->codec->id, avctx->pix_fmt);
- //until then pix_fmt may be changed right after codec init
- if( avctx->pix_fmt == PIX_FMT_XVMC_MPEG2_IDCT ||
- avctx->hwaccel ||
- s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU )
- if( avctx->idct_algo == FF_IDCT_AUTO )
+ // until then pix_fmt may be changed right after codec init
+ if (avctx->pix_fmt == PIX_FMT_XVMC_MPEG2_IDCT ||
+ avctx->hwaccel )
+ if (avctx->idct_algo == FF_IDCT_AUTO)
avctx->idct_algo = FF_IDCT_SIMPLE;
/* Quantization matrices may need reordering
* if DCT permutation is changed. */
- memcpy(old_permutation,s->dsp.idct_permutation,64*sizeof(uint8_t));
+ memcpy(old_permutation, s->dsp.idct_permutation, 64 * sizeof(uint8_t));
if (MPV_common_init(s) < 0)
return -2;
- quant_matrix_rebuild(s->intra_matrix, old_permutation,s->dsp.idct_permutation);
- quant_matrix_rebuild(s->inter_matrix, old_permutation,s->dsp.idct_permutation);
- quant_matrix_rebuild(s->chroma_intra_matrix,old_permutation,s->dsp.idct_permutation);
- quant_matrix_rebuild(s->chroma_inter_matrix,old_permutation,s->dsp.idct_permutation);
+ quant_matrix_rebuild(s->intra_matrix, old_permutation, s->dsp.idct_permutation);
+ quant_matrix_rebuild(s->inter_matrix, old_permutation, s->dsp.idct_permutation);
+ quant_matrix_rebuild(s->chroma_intra_matrix, old_permutation, s->dsp.idct_permutation);
+ quant_matrix_rebuild(s->chroma_inter_matrix, old_permutation, s->dsp.idct_permutation);
s1->mpeg_enc_ctx_allocated = 1;
}
@@ -1365,10 +1371,10 @@ static int mpeg1_decode_picture(AVCodecContext *avctx,
ref = get_bits(&s->gb, 10); /* temporal ref */
s->pict_type = get_bits(&s->gb, 3);
- if(s->pict_type == 0 || s->pict_type > 3)
+ if (s->pict_type == 0 || s->pict_type > 3)
return -1;
- vbv_delay= get_bits(&s->gb, 16);
+ vbv_delay = get_bits(&s->gb, 16);
if (s->pict_type == AV_PICTURE_TYPE_P || s->pict_type == AV_PICTURE_TYPE_B) {
s->full_pel[0] = get_bits1(&s->gb);
f_code = get_bits(&s->gb, 3);
@@ -1385,10 +1391,10 @@ static int mpeg1_decode_picture(AVCodecContext *avctx,
s->mpeg_f_code[1][0] = f_code;
s->mpeg_f_code[1][1] = f_code;
}
- s->current_picture.pict_type= s->pict_type;
- s->current_picture.key_frame= s->pict_type == AV_PICTURE_TYPE_I;
+ s->current_picture.f.pict_type = s->pict_type;
+ s->current_picture.f.key_frame = s->pict_type == AV_PICTURE_TYPE_I;
- if(avctx->debug & FF_DEBUG_PICT_INFO)
+ if (avctx->debug & FF_DEBUG_PICT_INFO)
av_log(avctx, AV_LOG_DEBUG, "vbv_delay %d, ref %d type:%d\n", vbv_delay, ref, s->pict_type);
s->y_dc_scale = 8;
@@ -1403,30 +1409,31 @@ static void mpeg_decode_sequence_extension(Mpeg1Context *s1)
int bit_rate_ext;
skip_bits(&s->gb, 1); /* profile and level esc*/
- s->avctx->profile= get_bits(&s->gb, 3);
- s->avctx->level= get_bits(&s->gb, 4);
+ s->avctx->profile = get_bits(&s->gb, 3);
+ s->avctx->level = get_bits(&s->gb, 4);
s->progressive_sequence = get_bits1(&s->gb); /* progressive_sequence */
- s->chroma_format = get_bits(&s->gb, 2); /* chroma_format 1=420, 2=422, 3=444 */
- horiz_size_ext = get_bits(&s->gb, 2);
- vert_size_ext = get_bits(&s->gb, 2);
- s->width |= (horiz_size_ext << 12);
- s->height |= (vert_size_ext << 12);
+ s->chroma_format = get_bits(&s->gb, 2); /* chroma_format 1=420, 2=422, 3=444 */
+ horiz_size_ext = get_bits(&s->gb, 2);
+ vert_size_ext = get_bits(&s->gb, 2);
+ s->width |= (horiz_size_ext << 12);
+ s->height |= (vert_size_ext << 12);
bit_rate_ext = get_bits(&s->gb, 12); /* XXX: handle it */
s->bit_rate += (bit_rate_ext << 18) * 400;
skip_bits1(&s->gb); /* marker */
- s->avctx->rc_buffer_size += get_bits(&s->gb, 8)*1024*16<<10;
+ s->avctx->rc_buffer_size += get_bits(&s->gb, 8) * 1024 * 16 << 10;
s->low_delay = get_bits1(&s->gb);
- if(s->flags & CODEC_FLAG_LOW_DELAY) s->low_delay=1;
+ if (s->flags & CODEC_FLAG_LOW_DELAY)
+ s->low_delay = 1;
- s1->frame_rate_ext.num = get_bits(&s->gb, 2)+1;
- s1->frame_rate_ext.den = get_bits(&s->gb, 5)+1;
+ s1->frame_rate_ext.num = get_bits(&s->gb, 2) + 1;
+ s1->frame_rate_ext.den = get_bits(&s->gb, 5) + 1;
av_dlog(s->avctx, "sequence extension\n");
- s->codec_id= s->avctx->codec_id= CODEC_ID_MPEG2VIDEO;
+ s->codec_id = s->avctx->codec_id = CODEC_ID_MPEG2VIDEO;
s->avctx->sub_id = 2; /* indicates MPEG-2 found */
- if(s->avctx->debug & FF_DEBUG_PICT_INFO)
+ if (s->avctx->debug & FF_DEBUG_PICT_INFO)
av_log(s->avctx, AV_LOG_DEBUG, "profile: %d, level: %d vbv buffer: %d, bitrate:%d\n",
s->avctx->profile, s->avctx->level, s->avctx->rc_buffer_size, s->bit_rate);
@@ -1434,78 +1441,78 @@ static void mpeg_decode_sequence_extension(Mpeg1Context *s1)
static void mpeg_decode_sequence_display_extension(Mpeg1Context *s1)
{
- MpegEncContext *s= &s1->mpeg_enc_ctx;
+ MpegEncContext *s = &s1->mpeg_enc_ctx;
int color_description, w, h;
skip_bits(&s->gb, 3); /* video format */
- color_description= get_bits1(&s->gb);
- if(color_description){
- s->avctx->color_primaries= get_bits(&s->gb, 8);
- s->avctx->color_trc = get_bits(&s->gb, 8);
- s->avctx->colorspace = get_bits(&s->gb, 8);
+ color_description = get_bits1(&s->gb);
+ if (color_description) {
+ s->avctx->color_primaries = get_bits(&s->gb, 8);
+ s->avctx->color_trc = get_bits(&s->gb, 8);
+ s->avctx->colorspace = get_bits(&s->gb, 8);
}
- w= get_bits(&s->gb, 14);
+ w = get_bits(&s->gb, 14);
skip_bits(&s->gb, 1); //marker
- h= get_bits(&s->gb, 14);
+ h = get_bits(&s->gb, 14);
// remaining 3 bits are zero padding
- s1->pan_scan.width= 16*w;
- s1->pan_scan.height=16*h;
+ s1->pan_scan.width = 16 * w;
+ s1->pan_scan.height = 16 * h;
- if(s->avctx->debug & FF_DEBUG_PICT_INFO)
+ if (s->avctx->debug & FF_DEBUG_PICT_INFO)
av_log(s->avctx, AV_LOG_DEBUG, "sde w:%d, h:%d\n", w, h);
}
static void mpeg_decode_picture_display_extension(Mpeg1Context *s1)
{
- MpegEncContext *s= &s1->mpeg_enc_ctx;
- int i,nofco;
+ MpegEncContext *s = &s1->mpeg_enc_ctx;
+ int i, nofco;
nofco = 1;
- if(s->progressive_sequence){
- if(s->repeat_first_field){
+ if (s->progressive_sequence) {
+ if (s->repeat_first_field) {
nofco++;
- if(s->top_field_first)
+ if (s->top_field_first)
nofco++;
}
- }else{
- if(s->picture_structure == PICT_FRAME){
+ } else {
+ if (s->picture_structure == PICT_FRAME) {
nofco++;
- if(s->repeat_first_field)
+ if (s->repeat_first_field)
nofco++;
}
}
- for(i=0; i<nofco; i++){
- s1->pan_scan.position[i][0]= get_sbits(&s->gb, 16);
- skip_bits(&s->gb, 1); //marker
- s1->pan_scan.position[i][1]= get_sbits(&s->gb, 16);
- skip_bits(&s->gb, 1); //marker
+ for (i = 0; i < nofco; i++) {
+ s1->pan_scan.position[i][0] = get_sbits(&s->gb, 16);
+ skip_bits(&s->gb, 1); // marker
+ s1->pan_scan.position[i][1] = get_sbits(&s->gb, 16);
+ skip_bits(&s->gb, 1); // marker
}
- if(s->avctx->debug & FF_DEBUG_PICT_INFO)
+ if (s->avctx->debug & FF_DEBUG_PICT_INFO)
av_log(s->avctx, AV_LOG_DEBUG, "pde (%d,%d) (%d,%d) (%d,%d)\n",
- s1->pan_scan.position[0][0], s1->pan_scan.position[0][1],
- s1->pan_scan.position[1][0], s1->pan_scan.position[1][1],
- s1->pan_scan.position[2][0], s1->pan_scan.position[2][1]
- );
+ s1->pan_scan.position[0][0], s1->pan_scan.position[0][1],
+ s1->pan_scan.position[1][0], s1->pan_scan.position[1][1],
+ s1->pan_scan.position[2][0], s1->pan_scan.position[2][1]);
}
-static int load_matrix(MpegEncContext *s, uint16_t matrix0[64], uint16_t matrix1[64], int intra){
+static int load_matrix(MpegEncContext *s, uint16_t matrix0[64], uint16_t matrix1[64], int intra)
+{
int i;
- for(i=0; i<64; i++) {
- int j = s->dsp.idct_permutation[ ff_zigzag_direct[i] ];
+ for (i = 0; i < 64; i++) {
+ int j = s->dsp.idct_permutation[ff_zigzag_direct[i]];
int v = get_bits(&s->gb, 8);
- if(v==0){
+ if (v == 0) {
av_log(s->avctx, AV_LOG_ERROR, "matrix damaged\n");
return -1;
}
- if(intra && i==0 && v!=8){
+ if (intra && i == 0 && v != 8) {
av_log(s->avctx, AV_LOG_ERROR, "intra matrix invalid, ignoring\n");
- v= 8; // needed by pink.mpg / issue1046
+ v = 8; // needed by pink.mpg / issue1046
}
matrix0[j] = v;
- if(matrix1)
+ if (matrix1)
matrix1[j] = v;
}
return 0;
@@ -1515,75 +1522,74 @@ static void mpeg_decode_quant_matrix_extension(MpegEncContext *s)
{
av_dlog(s->avctx, "matrix extension\n");
- if(get_bits1(&s->gb)) load_matrix(s, s->chroma_intra_matrix, s->intra_matrix, 1);
- if(get_bits1(&s->gb)) load_matrix(s, s->chroma_inter_matrix, s->inter_matrix, 0);
- if(get_bits1(&s->gb)) load_matrix(s, s->chroma_intra_matrix, NULL , 1);
- if(get_bits1(&s->gb)) load_matrix(s, s->chroma_inter_matrix, NULL , 0);
+ if (get_bits1(&s->gb)) load_matrix(s, s->chroma_intra_matrix, s->intra_matrix, 1);
+ if (get_bits1(&s->gb)) load_matrix(s, s->chroma_inter_matrix, s->inter_matrix, 0);
+ if (get_bits1(&s->gb)) load_matrix(s, s->chroma_intra_matrix, NULL , 1);
+ if (get_bits1(&s->gb)) load_matrix(s, s->chroma_inter_matrix, NULL , 0);
}
static void mpeg_decode_picture_coding_extension(Mpeg1Context *s1)
{
- MpegEncContext *s= &s1->mpeg_enc_ctx;
+ MpegEncContext *s = &s1->mpeg_enc_ctx;
s->full_pel[0] = s->full_pel[1] = 0;
s->mpeg_f_code[0][0] = get_bits(&s->gb, 4);
s->mpeg_f_code[0][1] = get_bits(&s->gb, 4);
s->mpeg_f_code[1][0] = get_bits(&s->gb, 4);
s->mpeg_f_code[1][1] = get_bits(&s->gb, 4);
- if(!s->pict_type && s1->mpeg_enc_ctx_allocated){
+ if (!s->pict_type && s1->mpeg_enc_ctx_allocated) {
av_log(s->avctx, AV_LOG_ERROR, "Missing picture start code, guessing missing values\n");
- if(s->mpeg_f_code[1][0] == 15 && s->mpeg_f_code[1][1]==15){
- if(s->mpeg_f_code[0][0] == 15 && s->mpeg_f_code[0][1] == 15)
- s->pict_type= AV_PICTURE_TYPE_I;
+ if (s->mpeg_f_code[1][0] == 15 && s->mpeg_f_code[1][1] == 15) {
+ if (s->mpeg_f_code[0][0] == 15 && s->mpeg_f_code[0][1] == 15)
+ s->pict_type = AV_PICTURE_TYPE_I;
else
- s->pict_type= AV_PICTURE_TYPE_P;
- }else
- s->pict_type= AV_PICTURE_TYPE_B;
- s->current_picture.pict_type= s->pict_type;
- s->current_picture.key_frame= s->pict_type == AV_PICTURE_TYPE_I;
+ s->pict_type = AV_PICTURE_TYPE_P;
+ } else
+ s->pict_type = AV_PICTURE_TYPE_B;
+ s->current_picture.f.pict_type = s->pict_type;
+ s->current_picture.f.key_frame = s->pict_type == AV_PICTURE_TYPE_I;
}
- s->intra_dc_precision = get_bits(&s->gb, 2);
- s->picture_structure = get_bits(&s->gb, 2);
- s->top_field_first = get_bits1(&s->gb);
- s->frame_pred_frame_dct = get_bits1(&s->gb);
+ s->intra_dc_precision = get_bits(&s->gb, 2);
+ s->picture_structure = get_bits(&s->gb, 2);
+ s->top_field_first = get_bits1(&s->gb);
+ s->frame_pred_frame_dct = get_bits1(&s->gb);
s->concealment_motion_vectors = get_bits1(&s->gb);
- s->q_scale_type = get_bits1(&s->gb);
- s->intra_vlc_format = get_bits1(&s->gb);
- s->alternate_scan = get_bits1(&s->gb);
- s->repeat_first_field = get_bits1(&s->gb);
- s->chroma_420_type = get_bits1(&s->gb);
- s->progressive_frame = get_bits1(&s->gb);
-
- if(s->progressive_sequence && !s->progressive_frame){
- s->progressive_frame= 1;
+ s->q_scale_type = get_bits1(&s->gb);
+ s->intra_vlc_format = get_bits1(&s->gb);
+ s->alternate_scan = get_bits1(&s->gb);
+ s->repeat_first_field = get_bits1(&s->gb);
+ s->chroma_420_type = get_bits1(&s->gb);
+ s->progressive_frame = get_bits1(&s->gb);
+
+ if (s->progressive_sequence && !s->progressive_frame) {
+ s->progressive_frame = 1;
av_log(s->avctx, AV_LOG_ERROR, "interlaced frame in progressive sequence, ignoring\n");
}
- if(s->picture_structure==0 || (s->progressive_frame && s->picture_structure!=PICT_FRAME)){
+ if (s->picture_structure == 0 || (s->progressive_frame && s->picture_structure != PICT_FRAME)) {
av_log(s->avctx, AV_LOG_ERROR, "picture_structure %d invalid, ignoring\n", s->picture_structure);
- s->picture_structure= PICT_FRAME;
+ s->picture_structure = PICT_FRAME;
}
- if(s->progressive_sequence && !s->frame_pred_frame_dct){
+ if (s->progressive_sequence && !s->frame_pred_frame_dct) {
av_log(s->avctx, AV_LOG_ERROR, "invalid frame_pred_frame_dct\n");
- s->frame_pred_frame_dct= 1;
}
- if(s->picture_structure == PICT_FRAME){
- s->first_field=0;
- s->v_edge_pos= 16*s->mb_height;
- }else{
+ if (s->picture_structure == PICT_FRAME) {
+ s->first_field = 0;
+ s->v_edge_pos = 16 * s->mb_height;
+ } else {
s->first_field ^= 1;
- s->v_edge_pos= 8*s->mb_height;
- memset(s->mbskip_table, 0, s->mb_stride*s->mb_height);
+ s->v_edge_pos = 8 * s->mb_height;
+ memset(s->mbskip_table, 0, s->mb_stride * s->mb_height);
}
- if(s->alternate_scan){
- ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable , ff_alternate_vertical_scan);
- ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable , ff_alternate_vertical_scan);
- }else{
- ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable , ff_zigzag_direct);
- ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable , ff_zigzag_direct);
+ if (s->alternate_scan) {
+ ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable, ff_alternate_vertical_scan);
+ ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable, ff_alternate_vertical_scan);
+ } else {
+ ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable, ff_zigzag_direct);
+ ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable, ff_zigzag_direct);
}
/* composite display not parsed */
@@ -1598,56 +1604,49 @@ static void mpeg_decode_picture_coding_extension(Mpeg1Context *s1)
av_dlog(s->avctx, "progressive_frame=%d\n", s->progressive_frame);
}
-static void exchange_uv(MpegEncContext *s){
- DCTELEM (*tmp)[64];
-
- tmp = s->pblocks[4];
- s->pblocks[4] = s->pblocks[5];
- s->pblocks[5] = tmp;
-}
-
-static int mpeg_field_start(MpegEncContext *s, const uint8_t *buf, int buf_size){
- AVCodecContext *avctx= s->avctx;
+static int mpeg_field_start(MpegEncContext *s, const uint8_t *buf, int buf_size)
+{
+ AVCodecContext *avctx = s->avctx;
Mpeg1Context *s1 = (Mpeg1Context*)s;
/* start frame decoding */
- if(s->first_field || s->picture_structure==PICT_FRAME){
- if(MPV_frame_start(s, avctx) < 0)
+ if (s->first_field || s->picture_structure == PICT_FRAME) {
+ if (MPV_frame_start(s, avctx) < 0)
return -1;
ff_er_frame_start(s);
/* first check if we must repeat the frame */
- s->current_picture_ptr->repeat_pict = 0;
+ s->current_picture_ptr->f.repeat_pict = 0;
if (s->repeat_first_field) {
if (s->progressive_sequence) {
if (s->top_field_first)
- s->current_picture_ptr->repeat_pict = 4;
+ s->current_picture_ptr->f.repeat_pict = 4;
else
- s->current_picture_ptr->repeat_pict = 2;
+ s->current_picture_ptr->f.repeat_pict = 2;
} else if (s->progressive_frame) {
- s->current_picture_ptr->repeat_pict = 1;
+ s->current_picture_ptr->f.repeat_pict = 1;
}
}
- *s->current_picture_ptr->pan_scan= s1->pan_scan;
+ *s->current_picture_ptr->f.pan_scan = s1->pan_scan;
- if (HAVE_PTHREADS && (avctx->active_thread_type & FF_THREAD_FRAME))
+ if (HAVE_THREADS && (avctx->active_thread_type & FF_THREAD_FRAME))
ff_thread_finish_setup(avctx);
- }else{ //second field
- int i;
+ } else { // second field
+ int i;
- if(!s->current_picture_ptr){
- av_log(s->avctx, AV_LOG_ERROR, "first field missing\n");
- return -1;
- }
+ if (!s->current_picture_ptr) {
+ av_log(s->avctx, AV_LOG_ERROR, "first field missing\n");
+ return -1;
+ }
- for(i=0; i<4; i++){
- s->current_picture.data[i] = s->current_picture_ptr->data[i];
- if(s->picture_structure == PICT_BOTTOM_FIELD){
- s->current_picture.data[i] += s->current_picture_ptr->linesize[i];
- }
+ for (i = 0; i < 4; i++) {
+ s->current_picture.f.data[i] = s->current_picture_ptr->f.data[i];
+ if (s->picture_structure == PICT_BOTTOM_FIELD) {
+ s->current_picture.f.data[i] += s->current_picture_ptr->f.linesize[i];
}
+ }
}
if (avctx->hwaccel) {
@@ -1657,15 +1656,15 @@ static int mpeg_field_start(MpegEncContext *s, const uint8_t *buf, int buf_size)
// MPV_frame_start will call this function too,
// but we need to call it on every field
- if(CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration)
- if(ff_xvmc_field_start(s,avctx) < 0)
+ if (CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration)
+ if (ff_xvmc_field_start(s, avctx) < 0)
return -1;
return 0;
}
#define DECODE_SLICE_ERROR -1
-#define DECODE_SLICE_OK 0
+#define DECODE_SLICE_OK 0
/**
* decodes a slice. MpegEncContext.mb_y must be set to the MB row from the startcode
@@ -1675,24 +1674,24 @@ static int mpeg_field_start(MpegEncContext *s, const uint8_t *buf, int buf_size)
static int mpeg_decode_slice(Mpeg1Context *s1, int mb_y,
const uint8_t **buf, int buf_size)
{
- MpegEncContext *s = &s1->mpeg_enc_ctx;
- AVCodecContext *avctx= s->avctx;
- const int field_pic= s->picture_structure != PICT_FRAME;
- const int lowres= s->avctx->lowres;
+ MpegEncContext *s = &s1->mpeg_enc_ctx;
+ AVCodecContext *avctx = s->avctx;
+ const int lowres = s->avctx->lowres;
+ const int field_pic = s->picture_structure != PICT_FRAME;
- s->resync_mb_x=
- s->resync_mb_y= -1;
+ s->resync_mb_x =
+ s->resync_mb_y = -1;
assert(mb_y < s->mb_height);
- init_get_bits(&s->gb, *buf, buf_size*8);
+ init_get_bits(&s->gb, *buf, buf_size * 8);
ff_mpeg1_clean_buffers(s);
s->interlaced_dct = 0;
s->qscale = get_qscale(s);
- if(s->qscale == 0){
+ if (s->qscale == 0) {
av_log(s->avctx, AV_LOG_ERROR, "qscale == 0\n");
return -1;
}
@@ -1702,14 +1701,14 @@ static int mpeg_decode_slice(Mpeg1Context *s1, int mb_y,
skip_bits(&s->gb, 8);
}
- s->mb_x=0;
+ s->mb_x = 0;
- if(mb_y==0 && s->codec_tag == AV_RL32("SLIF")){
+ if (mb_y == 0 && s->codec_tag == AV_RL32("SLIF")) {
skip_bits1(&s->gb);
- }else{
- for(;;) {
+ } else {
+ for (;;) {
int code = get_vlc2(&s->gb, mbincr_vlc.table, MBINCR_VLC_BITS, 2);
- if (code < 0){
+ if (code < 0) {
av_log(s->avctx, AV_LOG_ERROR, "first mb_incr damaged\n");
return -1;
}
@@ -1725,7 +1724,7 @@ static int mpeg_decode_slice(Mpeg1Context *s1, int mb_y,
}
}
- if(s->mb_x >= (unsigned)s->mb_width){
+ if (s->mb_x >= (unsigned)s->mb_width) {
av_log(s->avctx, AV_LOG_ERROR, "initial skip overflow\n");
return -1;
}
@@ -1733,7 +1732,7 @@ static int mpeg_decode_slice(Mpeg1Context *s1, int mb_y,
if (avctx->hwaccel) {
const uint8_t *buf_end, *buf_start = *buf - 4; /* include start_code */
int start_code = -1;
- buf_end = ff_find_start_code(buf_start + 2, *buf + buf_size, &start_code);
+ buf_end = avpriv_mpv_find_start_code(buf_start + 2, *buf + buf_size, &start_code);
if (buf_end < *buf + buf_size)
buf_end -= 4;
s->mb_y = mb_y;
@@ -1743,41 +1742,41 @@ static int mpeg_decode_slice(Mpeg1Context *s1, int mb_y,
return DECODE_SLICE_OK;
}
- s->resync_mb_x= s->mb_x;
- s->resync_mb_y= s->mb_y= mb_y;
- s->mb_skip_run= 0;
+ s->resync_mb_x = s->mb_x;
+ s->resync_mb_y = s->mb_y = mb_y;
+ s->mb_skip_run = 0;
ff_init_block_index(s);
- if (s->mb_y==0 && s->mb_x==0 && (s->first_field || s->picture_structure==PICT_FRAME)) {
- if(s->avctx->debug&FF_DEBUG_PICT_INFO){
+ if (s->mb_y == 0 && s->mb_x == 0 && (s->first_field || s->picture_structure == PICT_FRAME)) {
+ if (s->avctx->debug & FF_DEBUG_PICT_INFO) {
av_log(s->avctx, AV_LOG_DEBUG, "qp:%d fc:%2d%2d%2d%2d %s %s %s %s %s dc:%d pstruct:%d fdct:%d cmv:%d qtype:%d ivlc:%d rff:%d %s\n",
- s->qscale, s->mpeg_f_code[0][0],s->mpeg_f_code[0][1],s->mpeg_f_code[1][0],s->mpeg_f_code[1][1],
- s->pict_type == AV_PICTURE_TYPE_I ? "I" : (s->pict_type == AV_PICTURE_TYPE_P ? "P" : (s->pict_type == AV_PICTURE_TYPE_B ? "B" : "S")),
- s->progressive_sequence ? "ps" :"", s->progressive_frame ? "pf" : "", s->alternate_scan ? "alt" :"", s->top_field_first ? "top" :"",
- s->intra_dc_precision, s->picture_structure, s->frame_pred_frame_dct, s->concealment_motion_vectors,
- s->q_scale_type, s->intra_vlc_format, s->repeat_first_field, s->chroma_420_type ? "420" :"");
+ s->qscale, s->mpeg_f_code[0][0], s->mpeg_f_code[0][1], s->mpeg_f_code[1][0], s->mpeg_f_code[1][1],
+ s->pict_type == AV_PICTURE_TYPE_I ? "I" : (s->pict_type == AV_PICTURE_TYPE_P ? "P" : (s->pict_type == AV_PICTURE_TYPE_B ? "B" : "S")),
+ s->progressive_sequence ? "ps" :"", s->progressive_frame ? "pf" : "", s->alternate_scan ? "alt" :"", s->top_field_first ? "top" :"",
+ s->intra_dc_precision, s->picture_structure, s->frame_pred_frame_dct, s->concealment_motion_vectors,
+ s->q_scale_type, s->intra_vlc_format, s->repeat_first_field, s->chroma_420_type ? "420" :"");
}
}
- for(;;) {
- //If 1, we memcpy blocks in xvmcvideo.
- if(CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration > 1)
- ff_xvmc_init_block(s);//set s->block
+ for (;;) {
+ // If 1, we memcpy blocks in xvmcvideo.
+ if (CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration > 1)
+ ff_xvmc_init_block(s); // set s->block
- if(mpeg_decode_mb(s, s->block) < 0)
+ if (mpeg_decode_mb(s, s->block) < 0)
return -1;
- if(s->current_picture.motion_val[0] && !s->encoding){ //note motion_val is normally NULL unless we want to extract the MVs
+ if (s->current_picture.f.motion_val[0] && !s->encoding) { // note motion_val is normally NULL unless we want to extract the MVs
const int wrap = s->b8_stride;
- int xy = s->mb_x*2 + s->mb_y*2*wrap;
- int b8_xy= 4*(s->mb_x + s->mb_y*s->mb_stride);
+ int xy = s->mb_x * 2 + s->mb_y * 2 * wrap;
+ int b8_xy = 4 * (s->mb_x + s->mb_y * s->mb_stride);
int motion_x, motion_y, dir, i;
- for(i=0; i<2; i++){
- for(dir=0; dir<2; dir++){
- if (s->mb_intra || (dir==1 && s->pict_type != AV_PICTURE_TYPE_B)) {
+ for (i = 0; i < 2; i++) {
+ for (dir = 0; dir < 2; dir++) {
+ if (s->mb_intra || (dir == 1 && s->pict_type != AV_PICTURE_TYPE_B)) {
motion_x = motion_y = 0;
- }else if (s->mv_type == MV_TYPE_16X16 || (s->mv_type == MV_TYPE_FIELD && field_pic)){
+ } else if (s->mv_type == MV_TYPE_16X16 || (s->mv_type == MV_TYPE_FIELD && field_pic)) {
motion_x = s->mv[dir][0][0];
motion_y = s->mv[dir][0][1];
} else /*if ((s->mv_type == MV_TYPE_FIELD) || (s->mv_type == MV_TYPE_16X8))*/ {
@@ -1785,13 +1784,13 @@ static int mpeg_decode_slice(Mpeg1Context *s1, int mb_y,
motion_y = s->mv[dir][i][1];
}
- s->current_picture.motion_val[dir][xy ][0] = motion_x;
- s->current_picture.motion_val[dir][xy ][1] = motion_y;
- s->current_picture.motion_val[dir][xy + 1][0] = motion_x;
- s->current_picture.motion_val[dir][xy + 1][1] = motion_y;
- s->current_picture.ref_index [dir][b8_xy ]=
- s->current_picture.ref_index [dir][b8_xy + 1]= s->field_select[dir][i];
- assert(s->field_select[dir][i]==0 || s->field_select[dir][i]==1);
+ s->current_picture.f.motion_val[dir][xy ][0] = motion_x;
+ s->current_picture.f.motion_val[dir][xy ][1] = motion_y;
+ s->current_picture.f.motion_val[dir][xy + 1][0] = motion_x;
+ s->current_picture.f.motion_val[dir][xy + 1][1] = motion_y;
+ s->current_picture.f.ref_index [dir][b8_xy ] =
+ s->current_picture.f.ref_index [dir][b8_xy + 1] = s->field_select[dir][i];
+ assert(s->field_select[dir][i] == 0 || s->field_select[dir][i] == 1);
}
xy += wrap;
b8_xy +=2;
@@ -1805,25 +1804,25 @@ static int mpeg_decode_slice(Mpeg1Context *s1, int mb_y,
MPV_decode_mb(s, s->block);
if (++s->mb_x >= s->mb_width) {
- const int mb_size= 16>>s->avctx->lowres;
+ const int mb_size = 16 >> s->avctx->lowres;
- ff_draw_horiz_band(s, mb_size*(s->mb_y>>field_pic), mb_size);
+ ff_draw_horiz_band(s, mb_size*(s->mb_y >> field_pic), mb_size);
MPV_report_decode_progress(s);
s->mb_x = 0;
- s->mb_y += 1<<field_pic;
+ s->mb_y += 1 << field_pic;
- if(s->mb_y >= s->mb_height){
- int left= get_bits_left(&s->gb);
- int is_d10= s->chroma_format==2 && s->pict_type==AV_PICTURE_TYPE_I && avctx->profile==0 && avctx->level==5
- && s->intra_dc_precision == 2 && s->q_scale_type == 1 && s->alternate_scan == 0
- && s->progressive_frame == 0 /* vbv_delay == 0xBBB || 0xE10*/;
+ if (s->mb_y >= s->mb_height) {
+ int left = get_bits_left(&s->gb);
+ int is_d10 = s->chroma_format == 2 && s->pict_type == AV_PICTURE_TYPE_I && avctx->profile == 0 && avctx->level == 5
+ && s->intra_dc_precision == 2 && s->q_scale_type == 1 && s->alternate_scan == 0
+ && s->progressive_frame == 0 /* vbv_delay == 0xBBB || 0xE10*/;
- if(left < 0 || (left && show_bits(&s->gb, FFMIN(left, 23)) && !is_d10)
- || (avctx->error_recognition >= FF_ER_AGGRESSIVE && left>8)){
+ if (left < 0 || (left && show_bits(&s->gb, FFMIN(left, 23)) && !is_d10)
+ || (avctx->error_recognition >= FF_ER_AGGRESSIVE && left > 8)) {
av_log(avctx, AV_LOG_ERROR, "end mismatch left=%d %0X\n", left, show_bits(&s->gb, FFMIN(left, 23)));
return -1;
- }else
+ } else
goto eos;
}
@@ -1834,17 +1833,17 @@ static int mpeg_decode_slice(Mpeg1Context *s1, int mb_y,
if (s->mb_skip_run == -1) {
/* read increment again */
s->mb_skip_run = 0;
- for(;;) {
+ for (;;) {
int code = get_vlc2(&s->gb, mbincr_vlc.table, MBINCR_VLC_BITS, 2);
- if (code < 0){
+ if (code < 0) {
av_log(s->avctx, AV_LOG_ERROR, "mb incr damaged\n");
return -1;
}
if (code >= 33) {
if (code == 33) {
s->mb_skip_run += 33;
- }else if(code == 35){
- if(s->mb_skip_run != 0 || show_bits(&s->gb, 15) != 0){
+ } else if (code == 35) {
+ if (s->mb_skip_run != 0 || show_bits(&s->gb, 15) != 0) {
av_log(s->avctx, AV_LOG_ERROR, "slice mismatch\n");
return -1;
}
@@ -1856,28 +1855,28 @@ static int mpeg_decode_slice(Mpeg1Context *s1, int mb_y,
break;
}
}
- if(s->mb_skip_run){
+ if (s->mb_skip_run) {
int i;
- if(s->pict_type == AV_PICTURE_TYPE_I){
+ if (s->pict_type == AV_PICTURE_TYPE_I) {
av_log(s->avctx, AV_LOG_ERROR, "skipped MB in I frame at %d %d\n", s->mb_x, s->mb_y);
return -1;
}
/* skip mb */
s->mb_intra = 0;
- for(i=0;i<12;i++)
+ for (i = 0; i < 12; i++)
s->block_last_index[i] = -1;
- if(s->picture_structure == PICT_FRAME)
+ if (s->picture_structure == PICT_FRAME)
s->mv_type = MV_TYPE_16X16;
else
s->mv_type = MV_TYPE_FIELD;
if (s->pict_type == AV_PICTURE_TYPE_P) {
/* if P type, zero motion vector is implied */
- s->mv_dir = MV_DIR_FORWARD;
- s->mv[0][0][0] = s->mv[0][0][1] = 0;
- s->last_mv[0][0][0] = s->last_mv[0][0][1] = 0;
- s->last_mv[0][1][0] = s->last_mv[0][1][1] = 0;
- s->field_select[0][0]= (s->picture_structure - 1) & 1;
+ s->mv_dir = MV_DIR_FORWARD;
+ s->mv[0][0][0] = s->mv[0][0][1] = 0;
+ s->last_mv[0][0][0] = s->last_mv[0][0][1] = 0;
+ s->last_mv[0][1][0] = s->last_mv[0][1][1] = 0;
+ s->field_select[0][0] = (s->picture_structure - 1) & 1;
} else {
/* if B type, reuse previous vectors and directions */
s->mv[0][0][0] = s->last_mv[0][0][0];
@@ -1894,38 +1893,41 @@ eos: // end of slice
return 0;
}
-static int slice_decode_thread(AVCodecContext *c, void *arg){
- MpegEncContext *s= *(void**)arg;
- const uint8_t *buf= s->gb.buffer;
- int mb_y= s->start_mb_y;
- const int field_pic= s->picture_structure != PICT_FRAME;
+static int slice_decode_thread(AVCodecContext *c, void *arg)
+{
+ MpegEncContext *s = *(void**)arg;
+ const uint8_t *buf = s->gb.buffer;
+ int mb_y = s->start_mb_y;
+ const int field_pic = s->picture_structure != PICT_FRAME;
- s->error_count= (3*(s->end_mb_y - s->start_mb_y)*s->mb_width) >> field_pic;
+ s->error_count = (3 * (s->end_mb_y - s->start_mb_y) * s->mb_width) >> field_pic;
- for(;;){
+ for (;;) {
uint32_t start_code;
int ret;
- ret= mpeg_decode_slice((Mpeg1Context*)s, mb_y, &buf, s->gb.buffer_end - buf);
+ ret = mpeg_decode_slice((Mpeg1Context*)s, mb_y, &buf, s->gb.buffer_end - buf);
emms_c();
//av_log(c, AV_LOG_DEBUG, "ret:%d resync:%d/%d mb:%d/%d ts:%d/%d ec:%d\n",
//ret, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, s->start_mb_y, s->end_mb_y, s->error_count);
- if(ret < 0){
- if(s->resync_mb_x>=0 && s->resync_mb_y>=0)
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, AC_ERROR|DC_ERROR|MV_ERROR);
- }else{
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, AC_END|DC_END|MV_END);
+ if (ret < 0) {
+ if (c->error_recognition >= FF_ER_EXPLODE)
+ return ret;
+ if (s->resync_mb_x >= 0 && s->resync_mb_y >= 0)
+ ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, AC_ERROR | DC_ERROR | MV_ERROR);
+ } else {
+ ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, AC_END | DC_END | MV_END);
}
- if(s->mb_y == s->end_mb_y)
+ if (s->mb_y == s->end_mb_y)
return 0;
- start_code= -1;
- buf = ff_find_start_code(buf, s->gb.buffer_end, &start_code);
+ start_code = -1;
+ buf = avpriv_mpv_find_start_code(buf, s->gb.buffer_end, &start_code);
mb_y= (start_code - SLICE_MIN_START_CODE) << field_pic;
if (s->picture_structure == PICT_BOTTOM_FIELD)
mb_y++;
- if(mb_y < 0 || mb_y >= s->end_mb_y)
+ if (mb_y < 0 || mb_y >= s->end_mb_y)
return -1;
}
}
@@ -1947,21 +1949,21 @@ static int slice_end(AVCodecContext *avctx, AVFrame *pict)
av_log(avctx, AV_LOG_ERROR, "hardware accelerator failed to decode picture\n");
}
- if(CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration)
+ if (CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration)
ff_xvmc_field_end(s);
/* end of slice reached */
- if (/*s->mb_y<<field_pic == s->mb_height &&*/ !s->first_field) {
+ if (/*s->mb_y << field_pic == s->mb_height &&*/ !s->first_field && !s->first_slice) {
/* end of image */
- s->current_picture_ptr->qscale_type= FF_QSCALE_TYPE_MPEG2;
+ s->current_picture_ptr->f.qscale_type = FF_QSCALE_TYPE_MPEG2;
ff_er_frame_end(s);
MPV_frame_end(s);
if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {
- *pict= *(AVFrame*)s->current_picture_ptr;
+ *pict = *(AVFrame*)s->current_picture_ptr;
ff_print_debug_info(s, pict);
} else {
if (avctx->active_thread_type & FF_THREAD_FRAME)
@@ -1969,7 +1971,7 @@ static int slice_end(AVCodecContext *avctx, AVFrame *pict)
/* latency of 1 frame for I- and P-frames */
/* XXX: use another variable than picture_number */
if (s->last_picture_ptr != NULL) {
- *pict= *(AVFrame*)s->last_picture_ptr;
+ *pict = *(AVFrame*)s->last_picture_ptr;
ff_print_debug_info(s, pict);
}
}
@@ -1985,16 +1987,16 @@ static int mpeg1_decode_sequence(AVCodecContext *avctx,
{
Mpeg1Context *s1 = avctx->priv_data;
MpegEncContext *s = &s1->mpeg_enc_ctx;
- int width,height;
+ int width, height;
int i, v, j;
init_get_bits(&s->gb, buf, buf_size*8);
- width = get_bits(&s->gb, 12);
+ width = get_bits(&s->gb, 12);
height = get_bits(&s->gb, 12);
if (width <= 0 || height <= 0)
return -1;
- s->aspect_ratio_info= get_bits(&s->gb, 4);
+ s->aspect_ratio_info = get_bits(&s->gb, 4);
if (s->aspect_ratio_info == 0) {
av_log(avctx, AV_LOG_ERROR, "aspect ratio has forbidden 0 value\n");
if (avctx->error_recognition >= FF_ER_COMPLIANT)
@@ -2006,52 +2008,53 @@ static int mpeg1_decode_sequence(AVCodecContext *avctx,
s->bit_rate = get_bits(&s->gb, 18) * 400;
if (get_bits1(&s->gb) == 0) /* marker */
return -1;
- s->width = width;
+ s->width = width;
s->height = height;
- s->avctx->rc_buffer_size= get_bits(&s->gb, 10) * 1024*16;
+ s->avctx->rc_buffer_size = get_bits(&s->gb, 10) * 1024 * 16;
skip_bits(&s->gb, 1);
/* get matrix */
if (get_bits1(&s->gb)) {
load_matrix(s, s->chroma_intra_matrix, s->intra_matrix, 1);
} else {
- for(i=0;i<64;i++) {
+ for (i = 0; i < 64; i++) {
j = s->dsp.idct_permutation[i];
v = ff_mpeg1_default_intra_matrix[i];
- s->intra_matrix[j] = v;
+ s->intra_matrix[j] = v;
s->chroma_intra_matrix[j] = v;
}
}
if (get_bits1(&s->gb)) {
load_matrix(s, s->chroma_inter_matrix, s->inter_matrix, 0);
} else {
- for(i=0;i<64;i++) {
- int j= s->dsp.idct_permutation[i];
+ for (i = 0; i < 64; i++) {
+ int j = s->dsp.idct_permutation[i];
v = ff_mpeg1_default_non_intra_matrix[i];
- s->inter_matrix[j] = v;
+ s->inter_matrix[j] = v;
s->chroma_inter_matrix[j] = v;
}
}
- if(show_bits(&s->gb, 23) != 0){
+ if (show_bits(&s->gb, 23) != 0) {
av_log(s->avctx, AV_LOG_ERROR, "sequence header damaged\n");
return -1;
}
/* we set MPEG-2 parameters so that it emulates MPEG-1 */
s->progressive_sequence = 1;
- s->progressive_frame = 1;
- s->picture_structure = PICT_FRAME;
+ s->progressive_frame = 1;
+ s->picture_structure = PICT_FRAME;
s->frame_pred_frame_dct = 1;
- s->chroma_format = 1;
- s->codec_id= s->avctx->codec_id= CODEC_ID_MPEG1VIDEO;
- avctx->sub_id = 1; /* indicates MPEG-1 */
- s->out_format = FMT_MPEG1;
- s->swap_uv = 0;//AFAIK VCR2 does not have SEQ_HEADER
- if(s->flags & CODEC_FLAG_LOW_DELAY) s->low_delay=1;
-
- if(s->avctx->debug & FF_DEBUG_PICT_INFO)
+ s->chroma_format = 1;
+ s->codec_id = s->avctx->codec_id = CODEC_ID_MPEG1VIDEO;
+ avctx->sub_id = 1; /* indicates MPEG-1 */
+ s->out_format = FMT_MPEG1;
+ s->swap_uv = 0; // AFAIK VCR2 does not have SEQ_HEADER
+ if (s->flags & CODEC_FLAG_LOW_DELAY)
+ s->low_delay = 1;
+
+ if (s->avctx->debug & FF_DEBUG_PICT_INFO)
av_log(s->avctx, AV_LOG_DEBUG, "vbv buffer: %d, bitrate:%d\n",
s->avctx->rc_buffer_size, s->bit_rate);
@@ -2071,41 +2074,40 @@ static int vcr2_init_sequence(AVCodecContext *avctx)
}
s->width = avctx->coded_width;
s->height = avctx->coded_height;
- avctx->has_b_frames= 0; //true?
- s->low_delay= 1;
+ avctx->has_b_frames = 0; // true?
+ s->low_delay = 1;
avctx->pix_fmt = mpeg_get_pixelformat(avctx);
avctx->hwaccel = ff_find_hwaccel(avctx->codec->id, avctx->pix_fmt);
- if( avctx->pix_fmt == PIX_FMT_XVMC_MPEG2_IDCT || avctx->hwaccel ||
- s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU )
- if( avctx->idct_algo == FF_IDCT_AUTO )
+ if( avctx->pix_fmt == PIX_FMT_XVMC_MPEG2_IDCT || avctx->hwaccel )
+ if (avctx->idct_algo == FF_IDCT_AUTO)
avctx->idct_algo = FF_IDCT_SIMPLE;
if (MPV_common_init(s) < 0)
return -1;
- exchange_uv(s);//common init reset pblocks, so we swap them here
- s->swap_uv = 1;// in case of xvmc we need to swap uv for each MB
+ exchange_uv(s); // common init reset pblocks, so we swap them here
+ s->swap_uv = 1; // in case of xvmc we need to swap uv for each MB
s1->mpeg_enc_ctx_allocated = 1;
- for(i=0;i<64;i++) {
- int j= s->dsp.idct_permutation[i];
+ for (i = 0; i < 64; i++) {
+ int j = s->dsp.idct_permutation[i];
v = ff_mpeg1_default_intra_matrix[i];
- s->intra_matrix[j] = v;
+ s->intra_matrix[j] = v;
s->chroma_intra_matrix[j] = v;
v = ff_mpeg1_default_non_intra_matrix[i];
- s->inter_matrix[j] = v;
+ s->inter_matrix[j] = v;
s->chroma_inter_matrix[j] = v;
}
- s->progressive_sequence = 1;
- s->progressive_frame = 1;
- s->picture_structure = PICT_FRAME;
- s->frame_pred_frame_dct = 1;
- s->chroma_format = 1;
- s->codec_id= s->avctx->codec_id= CODEC_ID_MPEG2VIDEO;
- avctx->sub_id = 2; /* indicates MPEG-2 */
+ s->progressive_sequence = 1;
+ s->progressive_frame = 1;
+ s->picture_structure = PICT_FRAME;
+ s->frame_pred_frame_dct = 1;
+ s->chroma_format = 1;
+ s->codec_id = s->avctx->codec_id = CODEC_ID_MPEG2VIDEO;
+ avctx->sub_id = 2; /* indicates MPEG-2 */
s1->save_width = s->width;
s1->save_height = s->height;
s1->save_progressive_seq = s->progressive_sequence;
@@ -2116,7 +2118,21 @@ static int vcr2_init_sequence(AVCodecContext *avctx)
static void mpeg_decode_user_data(AVCodecContext *avctx,
const uint8_t *p, int buf_size)
{
- const uint8_t *buf_end = p+buf_size;
+ Mpeg1Context *s = avctx->priv_data;
+ const uint8_t *buf_end = p + buf_size;
+
+ if(buf_size > 29){
+ int i;
+ for(i=0; i<20; i++)
+ if(!memcmp(p+i, "\0TMPGEXS\0", 9)){
+ s->tmpgexs= 1;
+ }
+
+/* for(i=0; !(!p[i-2] && !p[i-1] && p[i]==1) && i<buf_size; i++){
+ av_log(0,0, "%c", p[i]);
+ }
+ av_log(0,0, "\n");*/
+ }
/* we parse the DTG active format information */
if (buf_end - p >= 5 &&
@@ -2136,23 +2152,24 @@ static void mpeg_decode_user_data(AVCodecContext *avctx,
}
static void mpeg_decode_gop(AVCodecContext *avctx,
- const uint8_t *buf, int buf_size){
- Mpeg1Context *s1 = avctx->priv_data;
+ const uint8_t *buf, int buf_size)
+{
+ Mpeg1Context *s1 = avctx->priv_data;
MpegEncContext *s = &s1->mpeg_enc_ctx;
+ int drop_frame_flag;
int time_code_hours, time_code_minutes;
int time_code_seconds, time_code_pictures;
int broken_link;
init_get_bits(&s->gb, buf, buf_size*8);
- skip_bits1(&s->gb); /* drop_frame_flag */
-
- time_code_hours=get_bits(&s->gb,5);
- time_code_minutes = get_bits(&s->gb,6);
- skip_bits1(&s->gb);//marker bit
- time_code_seconds = get_bits(&s->gb,6);
- time_code_pictures = get_bits(&s->gb,6);
+ drop_frame_flag = get_bits(&s->gb, 1);
+ time_code_hours = get_bits(&s->gb, 5);
+ time_code_minutes = get_bits(&s->gb, 6);
+ skip_bits1(&s->gb); // marker bit
+ time_code_seconds = get_bits(&s->gb, 6);
+ time_code_pictures = get_bits(&s->gb, 6);
s->closed_gop = get_bits1(&s->gb);
/*broken_link indicate that after editing the
@@ -2160,10 +2177,11 @@ static void mpeg_decode_gop(AVCodecContext *avctx,
are missing (open gop)*/
broken_link = get_bits1(&s->gb);
- if(s->avctx->debug & FF_DEBUG_PICT_INFO)
- av_log(s->avctx, AV_LOG_DEBUG, "GOP (%2d:%02d:%02d.[%02d]) closed_gop=%d broken_link=%d\n",
- time_code_hours, time_code_minutes, time_code_seconds,
- time_code_pictures, s->closed_gop, broken_link);
+ if (s->avctx->debug & FF_DEBUG_PICT_INFO)
+ av_log(s->avctx, AV_LOG_DEBUG, "GOP (%02d:%02d:%02d%c%02d) closed_gop=%d broken_link=%d\n",
+ time_code_hours, time_code_minutes, time_code_seconds,
+ drop_frame_flag ? ';' : ':',
+ time_code_pictures, s->closed_gop, broken_link);
}
/**
* Find the end of the current frame in the bitstream.
@@ -2172,7 +2190,7 @@ static void mpeg_decode_gop(AVCodecContext *avctx,
int ff_mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size, AVCodecParserContext *s)
{
int i;
- uint32_t state= pc->state;
+ uint32_t state = pc->state;
/* EOF considered as end of frame */
if (buf_size == 0)
@@ -2186,49 +2204,51 @@ int ff_mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size,
4 searching end
*/
- for(i=0; i<buf_size; i++){
- assert(pc->frame_start_found>=0 && pc->frame_start_found<=4);
- if(pc->frame_start_found&1){
- if(state == EXT_START_CODE && (buf[i]&0xF0) != 0x80)
+ for (i = 0; i < buf_size; i++) {
+ assert(pc->frame_start_found >= 0 && pc->frame_start_found <= 4);
+ if (pc->frame_start_found & 1) {
+ if (state == EXT_START_CODE && (buf[i] & 0xF0) != 0x80)
pc->frame_start_found--;
- else if(state == EXT_START_CODE+2){
- if((buf[i]&3) == 3) pc->frame_start_found= 0;
- else pc->frame_start_found= (pc->frame_start_found+1)&3;
+ else if (state == EXT_START_CODE + 2) {
+ if ((buf[i] & 3) == 3)
+ pc->frame_start_found = 0;
+ else
+ pc->frame_start_found = (pc->frame_start_found + 1) & 3;
}
state++;
- }else{
- i= ff_find_start_code(buf+i, buf+buf_size, &state) - buf - 1;
- if(pc->frame_start_found==0 && state >= SLICE_MIN_START_CODE && state <= SLICE_MAX_START_CODE){
+ } else {
+ i = avpriv_mpv_find_start_code(buf + i, buf + buf_size, &state) - buf - 1;
+ if (pc->frame_start_found == 0 && state >= SLICE_MIN_START_CODE && state <= SLICE_MAX_START_CODE) {
i++;
- pc->frame_start_found=4;
+ pc->frame_start_found = 4;
}
- if(state == SEQ_END_CODE){
+ if (state == SEQ_END_CODE) {
pc->state=-1;
return i+1;
}
- if(pc->frame_start_found==2 && state == SEQ_START_CODE)
- pc->frame_start_found= 0;
- if(pc->frame_start_found<4 && state == EXT_START_CODE)
+ if (pc->frame_start_found == 2 && state == SEQ_START_CODE)
+ pc->frame_start_found = 0;
+ if (pc->frame_start_found < 4 && state == EXT_START_CODE)
pc->frame_start_found++;
- if(pc->frame_start_found == 4 && (state&0xFFFFFF00) == 0x100){
- if(state < SLICE_MIN_START_CODE || state > SLICE_MAX_START_CODE){
- pc->frame_start_found=0;
- pc->state=-1;
- return i-3;
+ if (pc->frame_start_found == 4 && (state & 0xFFFFFF00) == 0x100) {
+ if (state < SLICE_MIN_START_CODE || state > SLICE_MAX_START_CODE) {
+ pc->frame_start_found = 0;
+ pc->state = -1;
+ return i - 3;
}
}
- if(pc->frame_start_found == 0 && s && state == PICTURE_START_CODE){
- ff_fetch_timestamp(s, i-3, 1);
+ if (pc->frame_start_found == 0 && s && state == PICTURE_START_CODE) {
+ ff_fetch_timestamp(s, i - 3, 1);
}
}
}
- pc->state= state;
+ pc->state = state;
return END_NOT_FOUND;
}
static int decode_chunks(AVCodecContext *avctx,
- AVFrame *picture, int *data_size,
- const uint8_t *buf, int buf_size);
+ AVFrame *picture, int *data_size,
+ const uint8_t *buf, int buf_size);
/* handle buffering and image synchronisation */
static int mpeg_decode_frame(AVCodecContext *avctx,
@@ -2244,102 +2264,100 @@ static int mpeg_decode_frame(AVCodecContext *avctx,
if (buf_size == 0 || (buf_size == 4 && AV_RB32(buf) == SEQ_END_CODE)) {
/* special case for last picture */
- if (s2->low_delay==0 && s2->next_picture_ptr) {
- *picture= *(AVFrame*)s2->next_picture_ptr;
- s2->next_picture_ptr= NULL;
+ if (s2->low_delay == 0 && s2->next_picture_ptr) {
+ *picture = *(AVFrame*)s2->next_picture_ptr;
+ s2->next_picture_ptr = NULL;
*data_size = sizeof(AVFrame);
}
return buf_size;
}
- if(s2->flags&CODEC_FLAG_TRUNCATED){
- int next= ff_mpeg1_find_frame_end(&s2->parse_context, buf, buf_size, NULL);
+ if (s2->flags & CODEC_FLAG_TRUNCATED) {
+ int next = ff_mpeg1_find_frame_end(&s2->parse_context, buf, buf_size, NULL);
- if( ff_combine_frame(&s2->parse_context, next, (const uint8_t **)&buf, &buf_size) < 0 )
+ if (ff_combine_frame(&s2->parse_context, next, (const uint8_t **)&buf, &buf_size) < 0)
return buf_size;
}
-#if 0
- if (s->repeat_field % 2 == 1) {
- s->repeat_field++;
- //fprintf(stderr,"\nRepeating last frame: %d -> %d! pict: %d %d", avctx->frame_number-1, avctx->frame_number,
- // s2->picture_number, s->repeat_field);
- if (avctx->flags & CODEC_FLAG_REPEAT_FIELD) {
- *data_size = sizeof(AVPicture);
- goto the_end;
- }
- }
-#endif
-
- if(s->mpeg_enc_ctx_allocated==0 && avctx->codec_tag == AV_RL32("VCR2"))
+ if (s->mpeg_enc_ctx_allocated == 0 && avctx->codec_tag == AV_RL32("VCR2"))
vcr2_init_sequence(avctx);
- s->slice_count= 0;
+ s->slice_count = 0;
- if(avctx->extradata && !avctx->frame_number)
- decode_chunks(avctx, picture, data_size, avctx->extradata, avctx->extradata_size);
+ if (avctx->extradata && !avctx->frame_number) {
+ int ret = decode_chunks(avctx, picture, data_size, avctx->extradata, avctx->extradata_size);
+ if (ret < 0 && avctx->error_recognition >= FF_ER_EXPLODE)
+ return ret;
+ }
return decode_chunks(avctx, picture, data_size, buf, buf_size);
}
static int decode_chunks(AVCodecContext *avctx,
- AVFrame *picture, int *data_size,
- const uint8_t *buf, int buf_size)
+ AVFrame *picture, int *data_size,
+ const uint8_t *buf, int buf_size)
{
Mpeg1Context *s = avctx->priv_data;
MpegEncContext *s2 = &s->mpeg_enc_ctx;
const uint8_t *buf_ptr = buf;
const uint8_t *buf_end = buf + buf_size;
int ret, input_size;
- int last_code= 0;
+ int last_code = 0;
- for(;;) {
+ for (;;) {
/* find next start code */
uint32_t start_code = -1;
- buf_ptr = ff_find_start_code(buf_ptr,buf_end, &start_code);
- if (start_code > 0x1ff){
- if(s2->pict_type != AV_PICTURE_TYPE_B || avctx->skip_frame <= AVDISCARD_DEFAULT){
- if(HAVE_THREADS && (avctx->active_thread_type & FF_THREAD_SLICE)){
+ buf_ptr = avpriv_mpv_find_start_code(buf_ptr, buf_end, &start_code);
+ if (start_code > 0x1ff) {
+ if (s2->pict_type != AV_PICTURE_TYPE_B || avctx->skip_frame <= AVDISCARD_DEFAULT) {
+ if (HAVE_THREADS && (avctx->active_thread_type & FF_THREAD_SLICE)) {
int i;
+ av_assert0(avctx->thread_count > 1);
avctx->execute(avctx, slice_decode_thread, &s2->thread_context[0], NULL, s->slice_count, sizeof(void*));
- for(i=0; i<s->slice_count; i++)
+ for (i = 0; i < s->slice_count; i++)
s2->error_count += s2->thread_context[i]->error_count;
}
- if (CONFIG_MPEG_VDPAU_DECODER && avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU)
+ if (CONFIG_VDPAU && uses_vdpau(avctx))
ff_vdpau_mpeg_picture_complete(s2, buf, buf_size, s->slice_count);
if (slice_end(avctx, picture)) {
- if(s2->last_picture_ptr || s2->low_delay) //FIXME merge with the stuff in mpeg_decode_slice
+ if (s2->last_picture_ptr || s2->low_delay) //FIXME merge with the stuff in mpeg_decode_slice
*data_size = sizeof(AVPicture);
}
}
- s2->pict_type= 0;
+ s2->pict_type = 0;
return FFMAX(0, buf_ptr - buf - s2->parse_context.last_index);
}
input_size = buf_end - buf_ptr;
- if(avctx->debug & FF_DEBUG_STARTCODE){
+ if (avctx->debug & FF_DEBUG_STARTCODE) {
av_log(avctx, AV_LOG_DEBUG, "%3X at %td left %d\n", start_code, buf_ptr-buf, input_size);
}
/* prepare data for next start code */
- switch(start_code) {
+ switch (start_code) {
case SEQ_START_CODE:
- if(last_code == 0){
- mpeg1_decode_sequence(avctx, buf_ptr,
- input_size);
- s->sync=1;
- }else{
+ if (last_code == 0) {
+ mpeg1_decode_sequence(avctx, buf_ptr, input_size);
+ if(buf != avctx->extradata)
+ s->sync=1;
+ } else {
av_log(avctx, AV_LOG_ERROR, "ignoring SEQ_START_CODE after %X\n", last_code);
+ if (avctx->error_recognition >= FF_ER_EXPLODE)
+ return AVERROR_INVALIDDATA;
}
break;
case PICTURE_START_CODE:
- if (HAVE_THREADS && (avctx->active_thread_type&FF_THREAD_SLICE) && s->slice_count) {
+ if(s->tmpgexs){
+ s2->intra_dc_precision= 3;
+ s2->intra_matrix[0]= 1;
+ }
+ if (HAVE_THREADS && (avctx->active_thread_type & FF_THREAD_SLICE) && s->slice_count) {
int i;
avctx->execute(avctx, slice_decode_thread,
@@ -2349,31 +2367,35 @@ static int decode_chunks(AVCodecContext *avctx,
s2->error_count += s2->thread_context[i]->error_count;
s->slice_count = 0;
}
- if(last_code == 0 || last_code == SLICE_MIN_START_CODE){
- if(mpeg_decode_postinit(avctx) < 0){
- av_log(avctx, AV_LOG_ERROR, "mpeg_decode_postinit() failure\n");
- return -1;
- }
+ if (last_code == 0 || last_code == SLICE_MIN_START_CODE) {
+ ret = mpeg_decode_postinit(avctx);
+ if (ret < 0) {
+ av_log(avctx, AV_LOG_ERROR, "mpeg_decode_postinit() failure\n");
+ return ret;
+ }
- /* we have a complete image: we try to decompress it */
- if(mpeg1_decode_picture(avctx,
- buf_ptr, input_size) < 0)
- s2->pict_type=0;
+ /* we have a complete image: we try to decompress it */
+ if (mpeg1_decode_picture(avctx, buf_ptr, input_size) < 0)
+ s2->pict_type = 0;
s2->first_slice = 1;
- last_code= PICTURE_START_CODE;
- }else{
+ last_code = PICTURE_START_CODE;
+ } else {
av_log(avctx, AV_LOG_ERROR, "ignoring pic after %X\n", last_code);
+ if (avctx->error_recognition >= FF_ER_EXPLODE)
+ return AVERROR_INVALIDDATA;
}
break;
case EXT_START_CODE:
init_get_bits(&s2->gb, buf_ptr, input_size*8);
- switch(get_bits(&s2->gb, 4)) {
+ switch (get_bits(&s2->gb, 4)) {
case 0x1:
- if(last_code == 0){
+ if (last_code == 0) {
mpeg_decode_sequence_extension(s);
- }else{
+ } else {
av_log(avctx, AV_LOG_ERROR, "ignoring seq ext after %X\n", last_code);
+ if (avctx->error_recognition >= FF_ER_EXPLODE)
+ return AVERROR_INVALIDDATA;
}
break;
case 0x2:
@@ -2386,112 +2408,120 @@ static int decode_chunks(AVCodecContext *avctx,
mpeg_decode_picture_display_extension(s);
break;
case 0x8:
- if(last_code == PICTURE_START_CODE){
- mpeg_decode_picture_coding_extension(s);
- }else{
+ if (last_code == PICTURE_START_CODE) {
+ mpeg_decode_picture_coding_extension(s);
+ } else {
av_log(avctx, AV_LOG_ERROR, "ignoring pic cod ext after %X\n", last_code);
+ if (avctx->error_recognition >= FF_ER_EXPLODE)
+ return AVERROR_INVALIDDATA;
}
break;
}
break;
case USER_START_CODE:
- mpeg_decode_user_data(avctx,
- buf_ptr, input_size);
+ mpeg_decode_user_data(avctx, buf_ptr, input_size);
break;
case GOP_START_CODE:
- if(last_code == 0){
- s2->first_field=0;
- mpeg_decode_gop(avctx,
- buf_ptr, input_size);
+ if (last_code == 0) {
+ s2->first_field=0;
+ mpeg_decode_gop(avctx, buf_ptr, input_size);
s->sync=1;
- }else{
+ } else {
av_log(avctx, AV_LOG_ERROR, "ignoring GOP_START_CODE after %X\n", last_code);
+ if (avctx->error_recognition >= FF_ER_EXPLODE)
+ return AVERROR_INVALIDDATA;
}
break;
default:
if (start_code >= SLICE_MIN_START_CODE &&
- start_code <= SLICE_MAX_START_CODE && last_code!=0) {
- const int field_pic= s2->picture_structure != PICT_FRAME;
- int mb_y= (start_code - SLICE_MIN_START_CODE) << field_pic;
- last_code= SLICE_MIN_START_CODE;
+ start_code <= SLICE_MAX_START_CODE && last_code != 0) {
+ const int field_pic = s2->picture_structure != PICT_FRAME;
+ int mb_y = (start_code - SLICE_MIN_START_CODE) << field_pic;
+ last_code = SLICE_MIN_START_CODE;
- if(s2->picture_structure == PICT_BOTTOM_FIELD)
+ if (s2->picture_structure == PICT_BOTTOM_FIELD)
mb_y++;
- if (mb_y >= s2->mb_height){
+ if (mb_y >= s2->mb_height) {
av_log(s2->avctx, AV_LOG_ERROR, "slice below image (%d >= %d)\n", mb_y, s2->mb_height);
return -1;
}
- if(s2->last_picture_ptr==NULL){
+ if (s2->last_picture_ptr == NULL) {
/* Skip B-frames if we do not have reference frames and gop is not closed */
- if(s2->pict_type==AV_PICTURE_TYPE_B){
- if(!s2->closed_gop)
+ if (s2->pict_type == AV_PICTURE_TYPE_B) {
+ if (!s2->closed_gop)
break;
}
}
- if(s2->pict_type==AV_PICTURE_TYPE_I)
+ if (s2->pict_type == AV_PICTURE_TYPE_I || (s2->flags2 & CODEC_FLAG2_SHOW_ALL))
s->sync=1;
- if(s2->next_picture_ptr==NULL){
+ if (s2->next_picture_ptr == NULL) {
/* Skip P-frames if we do not have a reference frame or we have an invalid header. */
- if(s2->pict_type==AV_PICTURE_TYPE_P && !s->sync) break;
+ if (s2->pict_type == AV_PICTURE_TYPE_P && !s->sync) break;
}
- if( (avctx->skip_frame >= AVDISCARD_NONREF && s2->pict_type==AV_PICTURE_TYPE_B)
- ||(avctx->skip_frame >= AVDISCARD_NONKEY && s2->pict_type!=AV_PICTURE_TYPE_I)
- || avctx->skip_frame >= AVDISCARD_ALL)
+ if ((avctx->skip_frame >= AVDISCARD_NONREF && s2->pict_type == AV_PICTURE_TYPE_B) ||
+ (avctx->skip_frame >= AVDISCARD_NONKEY && s2->pict_type != AV_PICTURE_TYPE_I) ||
+ avctx->skip_frame >= AVDISCARD_ALL)
break;
- if (!s->mpeg_enc_ctx_allocated) break;
+ if (!s->mpeg_enc_ctx_allocated)
+ break;
- if(s2->codec_id == CODEC_ID_MPEG2VIDEO){
- if(mb_y < avctx->skip_top || mb_y >= s2->mb_height - avctx->skip_bottom)
+ if (s2->codec_id == CODEC_ID_MPEG2VIDEO) {
+ if (mb_y < avctx->skip_top || mb_y >= s2->mb_height - avctx->skip_bottom)
break;
}
- if(!s2->pict_type){
+ if (!s2->pict_type) {
av_log(avctx, AV_LOG_ERROR, "Missing picture start code\n");
+ if (avctx->error_recognition >= FF_ER_EXPLODE)
+ return AVERROR_INVALIDDATA;
break;
}
- if(s2->first_slice){
- s2->first_slice=0;
- if(mpeg_field_start(s2, buf, buf_size) < 0)
+ if (s2->first_slice) {
+ s2->first_slice = 0;
+ if (mpeg_field_start(s2, buf, buf_size) < 0)
return -1;
}
- if(!s2->current_picture_ptr){
+ if (!s2->current_picture_ptr) {
av_log(avctx, AV_LOG_ERROR, "current_picture not initialized\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
- if (avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU) {
+ if (uses_vdpau(avctx)) {
s->slice_count++;
break;
}
- if(HAVE_THREADS && (avctx->active_thread_type & FF_THREAD_SLICE)){
+ if (HAVE_THREADS && (avctx->active_thread_type & FF_THREAD_SLICE)) {
int threshold= (s2->mb_height*s->slice_count + avctx->thread_count/2) / avctx->thread_count;
- if(threshold <= mb_y){
- MpegEncContext *thread_context= s2->thread_context[s->slice_count];
-
- thread_context->start_mb_y= mb_y;
- thread_context->end_mb_y = s2->mb_height;
- if(s->slice_count){
- s2->thread_context[s->slice_count-1]->end_mb_y= mb_y;
+ av_assert0(avctx->thread_count > 1);
+ if (threshold <= mb_y) {
+ MpegEncContext *thread_context = s2->thread_context[s->slice_count];
+
+ thread_context->start_mb_y = mb_y;
+ thread_context->end_mb_y = s2->mb_height;
+ if (s->slice_count) {
+ s2->thread_context[s->slice_count-1]->end_mb_y = mb_y;
ff_update_duplicate_context(thread_context, s2);
}
init_get_bits(&thread_context->gb, buf_ptr, input_size*8);
s->slice_count++;
}
- buf_ptr += 2; //FIXME add minimum number of bytes per slice
- }else{
+ buf_ptr += 2; // FIXME add minimum number of bytes per slice
+ } else {
ret = mpeg_decode_slice(s, mb_y, &buf_ptr, input_size);
emms_c();
- if(ret < 0){
- if(s2->resync_mb_x>=0 && s2->resync_mb_y>=0)
- ff_er_add_slice(s2, s2->resync_mb_x, s2->resync_mb_y, s2->mb_x, s2->mb_y, AC_ERROR|DC_ERROR|MV_ERROR);
- }else{
- ff_er_add_slice(s2, s2->resync_mb_x, s2->resync_mb_y, s2->mb_x-1, s2->mb_y, AC_END|DC_END|MV_END);
+ if (ret < 0) {
+ if (avctx->error_recognition >= FF_ER_EXPLODE)
+ return ret;
+ if (s2->resync_mb_x >= 0 && s2->resync_mb_y >= 0)
+ ff_er_add_slice(s2, s2->resync_mb_x, s2->resync_mb_y, s2->mb_x, s2->mb_y, AC_ERROR | DC_ERROR | MV_ERROR);
+ } else {
+ ff_er_add_slice(s2, s2->resync_mb_x, s2->resync_mb_y, s2->mb_x-1, s2->mb_y, AC_END | DC_END | MV_END);
}
}
}
@@ -2500,7 +2530,8 @@ static int decode_chunks(AVCodecContext *avctx,
}
}
-static void flush(AVCodecContext *avctx){
+static void flush(AVCodecContext *avctx)
+{
Mpeg1Context *s = avctx->priv_data;
s->sync=0;
@@ -2531,115 +2562,110 @@ static const AVProfile mpeg2_video_profiles[] = {
AVCodec ff_mpeg1video_decoder = {
- "mpeg1video",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_MPEG1VIDEO,
- sizeof(Mpeg1Context),
- mpeg_decode_init,
- NULL,
- mpeg_decode_end,
- mpeg_decode_frame,
- CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY,
- .flush= flush,
- .max_lowres= 3,
- .long_name= NULL_IF_CONFIG_SMALL("MPEG-1 video"),
- .update_thread_context= ONLY_IF_THREADS_ENABLED(mpeg_decode_update_thread_context)
+ .name = "mpeg1video",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_MPEG1VIDEO,
+ .priv_data_size = sizeof(Mpeg1Context),
+ .init = mpeg_decode_init,
+ .close = mpeg_decode_end,
+ .decode = mpeg_decode_frame,
+ .capabilities = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY | CODEC_CAP_SLICE_THREADS,
+ .flush = flush,
+ .max_lowres = 3,
+ .long_name = NULL_IF_CONFIG_SMALL("MPEG-1 video"),
+ .update_thread_context = ONLY_IF_THREADS_ENABLED(mpeg_decode_update_thread_context)
};
AVCodec ff_mpeg2video_decoder = {
- "mpeg2video",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_MPEG2VIDEO,
- sizeof(Mpeg1Context),
- mpeg_decode_init,
- NULL,
- mpeg_decode_end,
- mpeg_decode_frame,
- CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY | CODEC_CAP_SLICE_THREADS,
- .flush= flush,
- .max_lowres= 3,
- .long_name= NULL_IF_CONFIG_SMALL("MPEG-2 video"),
- .profiles = NULL_IF_CONFIG_SMALL(mpeg2_video_profiles),
+ .name = "mpeg2video",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_MPEG2VIDEO,
+ .priv_data_size = sizeof(Mpeg1Context),
+ .init = mpeg_decode_init,
+ .close = mpeg_decode_end,
+ .decode = mpeg_decode_frame,
+ .capabilities = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY | CODEC_CAP_SLICE_THREADS,
+ .flush = flush,
+ .max_lowres = 3,
+ .long_name = NULL_IF_CONFIG_SMALL("MPEG-2 video"),
+ .profiles = NULL_IF_CONFIG_SMALL(mpeg2_video_profiles),
};
//legacy decoder
AVCodec ff_mpegvideo_decoder = {
- "mpegvideo",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_MPEG2VIDEO,
- sizeof(Mpeg1Context),
- mpeg_decode_init,
- NULL,
- mpeg_decode_end,
- mpeg_decode_frame,
- CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY | CODEC_CAP_SLICE_THREADS,
- .flush= flush,
- .max_lowres= 3,
- .long_name= NULL_IF_CONFIG_SMALL("MPEG-1 video"),
+ .name = "mpegvideo",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_MPEG2VIDEO,
+ .priv_data_size = sizeof(Mpeg1Context),
+ .init = mpeg_decode_init,
+ .close = mpeg_decode_end,
+ .decode = mpeg_decode_frame,
+ .capabilities = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY | CODEC_CAP_SLICE_THREADS,
+ .flush = flush,
+ .max_lowres = 3,
+ .long_name = NULL_IF_CONFIG_SMALL("MPEG-1 video"),
};
#if CONFIG_MPEG_XVMC_DECODER
-static av_cold int mpeg_mc_decode_init(AVCodecContext *avctx){
- if( avctx->active_thread_type & FF_THREAD_SLICE )
+static av_cold int mpeg_mc_decode_init(AVCodecContext *avctx)
+{
+ if (avctx->active_thread_type & FF_THREAD_SLICE)
return -1;
- if( !(avctx->slice_flags & SLICE_FLAG_CODED_ORDER) )
+ if (!(avctx->slice_flags & SLICE_FLAG_CODED_ORDER))
return -1;
- if( !(avctx->slice_flags & SLICE_FLAG_ALLOW_FIELD) ){
+ if (!(avctx->slice_flags & SLICE_FLAG_ALLOW_FIELD)) {
av_dlog(avctx, "mpeg12.c: XvMC decoder will work better if SLICE_FLAG_ALLOW_FIELD is set\n");
}
mpeg_decode_init(avctx);
- avctx->pix_fmt = PIX_FMT_XVMC_MPEG2_IDCT;
- avctx->xvmc_acceleration = 2;//2 - the blocks are packed!
+ avctx->pix_fmt = PIX_FMT_XVMC_MPEG2_IDCT;
+ avctx->xvmc_acceleration = 2; // 2 - the blocks are packed!
return 0;
}
AVCodec ff_mpeg_xvmc_decoder = {
- "mpegvideo_xvmc",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_MPEG2VIDEO_XVMC,
- sizeof(Mpeg1Context),
- mpeg_mc_decode_init,
- NULL,
- mpeg_decode_end,
- mpeg_decode_frame,
- CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED| CODEC_CAP_HWACCEL | CODEC_CAP_DELAY,
- .flush= flush,
- .long_name = NULL_IF_CONFIG_SMALL("MPEG-1/2 video XvMC (X-Video Motion Compensation)"),
+ .name = "mpegvideo_xvmc",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_MPEG2VIDEO_XVMC,
+ .priv_data_size = sizeof(Mpeg1Context),
+ .init = mpeg_mc_decode_init,
+ .close = mpeg_decode_end,
+ .decode = mpeg_decode_frame,
+ .capabilities = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED| CODEC_CAP_HWACCEL | CODEC_CAP_DELAY,
+ .flush = flush,
+ .long_name = NULL_IF_CONFIG_SMALL("MPEG-1/2 video XvMC (X-Video Motion Compensation)"),
};
#endif
#if CONFIG_MPEG_VDPAU_DECODER
AVCodec ff_mpeg_vdpau_decoder = {
- "mpegvideo_vdpau",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_MPEG2VIDEO,
- sizeof(Mpeg1Context),
- mpeg_decode_init,
- NULL,
- mpeg_decode_end,
- mpeg_decode_frame,
- CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_HWACCEL_VDPAU | CODEC_CAP_DELAY,
- .flush= flush,
- .long_name = NULL_IF_CONFIG_SMALL("MPEG-1/2 video (VDPAU acceleration)"),
+ .name = "mpegvideo_vdpau",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_MPEG2VIDEO,
+ .priv_data_size = sizeof(Mpeg1Context),
+ .init = mpeg_decode_init,
+ .close = mpeg_decode_end,
+ .decode = mpeg_decode_frame,
+ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_HWACCEL_VDPAU | CODEC_CAP_DELAY,
+ .flush = flush,
+ .long_name = NULL_IF_CONFIG_SMALL("MPEG-1/2 video (VDPAU acceleration)"),
};
#endif
#if CONFIG_MPEG1_VDPAU_DECODER
AVCodec ff_mpeg1_vdpau_decoder = {
- "mpeg1video_vdpau",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_MPEG1VIDEO,
- sizeof(Mpeg1Context),
- mpeg_decode_init,
- NULL,
- mpeg_decode_end,
- mpeg_decode_frame,
- CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_HWACCEL_VDPAU | CODEC_CAP_DELAY,
- .flush= flush,
- .long_name = NULL_IF_CONFIG_SMALL("MPEG-1 video (VDPAU acceleration)"),
+ .name = "mpeg1video_vdpau",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_MPEG1VIDEO,
+ .priv_data_size = sizeof(Mpeg1Context),
+ .init = mpeg_decode_init,
+ .close = mpeg_decode_end,
+ .decode = mpeg_decode_frame,
+ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_HWACCEL_VDPAU | CODEC_CAP_DELAY,
+ .flush = flush,
+ .long_name = NULL_IF_CONFIG_SMALL("MPEG-1 video (VDPAU acceleration)"),
};
#endif
diff --git a/libavcodec/mpeg12.h b/libavcodec/mpeg12.h
index 4c55726160..541b66bd94 100644
--- a/libavcodec/mpeg12.h
+++ b/libavcodec/mpeg12.h
@@ -2,20 +2,20 @@
* MPEG1/2 common code
* Copyright (c) 2007 Aurelien Jacobs <aurel@gnuage.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/mpeg12data.c b/libavcodec/mpeg12data.c
index 299215f91e..c40883692b 100644
--- a/libavcodec/mpeg12data.c
+++ b/libavcodec/mpeg12data.c
@@ -3,20 +3,20 @@
* copyright (c) 2000,2001 Fabrice Bellard
* copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -305,7 +305,7 @@ const uint8_t ff_mpeg12_mbMotionVectorTable[17][2] = {
{ 0xc, 10 },
};
-const AVRational ff_frame_rate_tab[] = {
+const AVRational avpriv_frame_rate_tab[] = {
{ 0, 0},
{24000, 1001},
{ 24, 1},
diff --git a/libavcodec/mpeg12data.h b/libavcodec/mpeg12data.h
index 3586a614aa..d4ef11e0c6 100644
--- a/libavcodec/mpeg12data.h
+++ b/libavcodec/mpeg12data.h
@@ -3,20 +3,20 @@
* copyright (c) 2000,2001 Fabrice Bellard
* copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -48,7 +48,7 @@ extern const uint8_t ff_mpeg12_mbPatTable[64][2];
extern const uint8_t ff_mpeg12_mbMotionVectorTable[17][2];
-extern const AVRational ff_frame_rate_tab[];
+extern const AVRational avpriv_frame_rate_tab[];
extern const float ff_mpeg1_aspect[16];
extern const AVRational ff_mpeg2_aspect[16];
diff --git a/libavcodec/mpeg12decdata.h b/libavcodec/mpeg12decdata.h
index 323a902336..66ca5c4971 100644
--- a/libavcodec/mpeg12decdata.h
+++ b/libavcodec/mpeg12decdata.h
@@ -3,20 +3,20 @@
* copyright (c) 2000,2001 Fabrice Bellard
* copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c
index eb07ecfc5e..21b957c8cc 100644
--- a/libavcodec/mpeg12enc.c
+++ b/libavcodec/mpeg12enc.c
@@ -3,20 +3,20 @@
* Copyright (c) 2000,2001 Fabrice Bellard
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -27,12 +27,16 @@
#include "avcodec.h"
#include "dsputil.h"
+#include "mathops.h"
#include "mpegvideo.h"
#include "mpeg12.h"
#include "mpeg12data.h"
#include "bytestream.h"
-
+#include "timecode.h"
+#include "libavutil/log.h"
+#include "libavutil/opt.h"
+#include "libavutil/avassert.h"
static const uint8_t inv_non_linear_qscale[13] = {
0, 2, 4, 6, 8,
@@ -117,7 +121,7 @@ static int find_frame_rate_index(MpegEncContext *s){
int64_t d;
for(i=1;i<14;i++) {
- int64_t n0= 1001LL/ff_frame_rate_tab[i].den*ff_frame_rate_tab[i].num*s->avctx->time_base.num;
+ int64_t n0= 1001LL/avpriv_frame_rate_tab[i].den*avpriv_frame_rate_tab[i].num*s->avctx->time_base.num;
int64_t n1= 1001LL*s->avctx->time_base.den;
if(s->avctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL && i>=9) break;
@@ -140,6 +144,13 @@ static av_cold int encode_init(AVCodecContext *avctx)
if(MPV_encode_init(avctx) < 0)
return -1;
+#if FF_API_MPEGVIDEO_GLOBAL_OPTS
+ if (avctx->flags2 & CODEC_FLAG2_DROP_FRAME_TIMECODE)
+ s->drop_frame_timecode = 1;
+ if (avctx->flags & CODEC_FLAG_SVCD_SCAN_OFFSET)
+ s->scan_offset = 1;
+#endif
+
if(find_frame_rate_index(s) < 0){
if(s->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL){
av_log(avctx, AV_LOG_ERROR, "MPEG1/2 does not support %d/%d fps\n", avctx->time_base.den, avctx->time_base.num);
@@ -172,17 +183,24 @@ static av_cold int encode_init(AVCodecContext *avctx)
}
}
- if((avctx->flags2 & CODEC_FLAG2_DROP_FRAME_TIMECODE) && s->frame_rate_index != 4){
+ s->drop_frame_timecode = s->tc.drop = s->drop_frame_timecode || !!(avctx->flags2 & CODEC_FLAG2_DROP_FRAME_TIMECODE);
+ if (s->drop_frame_timecode && s->frame_rate_index != 4) {
av_log(avctx, AV_LOG_ERROR, "Drop frame time code only allowed with 1001/30000 fps\n");
return -1;
}
+ if (s->tc.str) {
+ s->tc.rate = avpriv_frame_rate_tab[s->frame_rate_index];
+ if (ff_init_smtpe_timecode(s, &s->tc) < 0)
+ return -1;
+ s->avctx->timecode_frame_start = s->tc.start;
+ }
return 0;
}
static void put_header(MpegEncContext *s, int header)
{
- align_put_bits(&s->pb);
+ avpriv_align_put_bits(&s->pb);
put_bits(&s->pb, 16, header>>16);
put_sbits(&s->pb, 16, header);
}
@@ -200,8 +218,8 @@ static void mpeg1_encode_sequence_header(MpegEncContext *s)
if(aspect_ratio==0.0) aspect_ratio= 1.0; //pixel aspect 1:1 (VGA)
- if (s->current_picture.key_frame) {
- AVRational framerate= ff_frame_rate_tab[s->frame_rate_index];
+ if (s->current_picture.f.key_frame) {
+ AVRational framerate= avpriv_frame_rate_tab[s->frame_rate_index];
/* mpeg1 header repeated every gop */
put_header(s, SEQ_START_CODE);
@@ -283,20 +301,16 @@ static void mpeg1_encode_sequence_header(MpegEncContext *s)
}
put_header(s, GOP_START_CODE);
- put_bits(&s->pb, 1, !!(s->avctx->flags2 & CODEC_FLAG2_DROP_FRAME_TIMECODE)); /* drop frame flag */
+ put_bits(&s->pb, 1, s->drop_frame_timecode); /* drop frame flag */
/* time code : we must convert from the real frame rate to a
fake mpeg frame rate in case of low frame rate */
fps = (framerate.num + framerate.den/2)/ framerate.den;
- time_code = s->current_picture_ptr->coded_picture_number + s->avctx->timecode_frame_start;
-
- s->gop_picture_number = s->current_picture_ptr->coded_picture_number;
- if (s->avctx->flags2 & CODEC_FLAG2_DROP_FRAME_TIMECODE) {
- /* only works for NTSC 29.97 */
- int d = time_code / 17982;
- int m = time_code % 17982;
- //if (m < 2) m += 2; /* not needed since -2,-1 / 1798 in C returns 0 */
- time_code += 18 * d + 2 * ((m - 2) / 1798);
- }
+ time_code = s->current_picture_ptr->f.coded_picture_number + s->avctx->timecode_frame_start;
+
+ s->gop_picture_number = s->current_picture_ptr->f.coded_picture_number;
+ av_assert0(s->drop_frame_timecode == s->tc.drop);
+ if (s->tc.drop)
+ time_code = ff_framenum_to_drop_timecode(time_code);
put_bits(&s->pb, 5, (uint32_t)((time_code / (fps * 3600)) % 24));
put_bits(&s->pb, 6, (uint32_t)((time_code / (fps * 60)) % 60));
put_bits(&s->pb, 1, 1);
@@ -396,7 +410,7 @@ void mpeg1_encode_picture_header(MpegEncContext *s, int picture_number)
if (s->progressive_sequence) {
put_bits(&s->pb, 1, 0); /* no repeat */
} else {
- put_bits(&s->pb, 1, s->current_picture_ptr->top_field_first);
+ put_bits(&s->pb, 1, s->current_picture_ptr->f.top_field_first);
}
/* XXX: optimize the generation of this flag with entropy
measures */
@@ -413,7 +427,7 @@ void mpeg1_encode_picture_header(MpegEncContext *s, int picture_number)
put_bits(&s->pb, 1, s->progressive_frame);
put_bits(&s->pb, 1, 0); //composite_display_flag
}
- if(s->flags & CODEC_FLAG_SVCD_SCAN_OFFSET){
+ if (s->scan_offset) {
int i;
put_header(s, USER_START_CODE);
@@ -681,8 +695,7 @@ static void mpeg1_encode_motion(MpegEncContext *s, int val, int f_or_b_code)
int bit_size = f_or_b_code - 1;
int range = 1 << bit_size;
/* modulo encoding */
- int l= INT_BIT - 5 - bit_size;
- val= (val<<l)>>l;
+ val = sign_extend(val, 5 + bit_size);
if (val >= 0) {
val--;
@@ -925,30 +938,64 @@ static void mpeg1_encode_block(MpegEncContext *s,
put_bits(&s->pb, table_vlc[112][1], table_vlc[112][0]);
}
+#define OFFSET(x) offsetof(MpegEncContext, x)
+#define VE AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM
+#define COMMON_OPTS\
+ {TIMECODE_OPT(MpegEncContext,\
+ AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)},\
+ { "intra_vlc", "Use MPEG-2 intra VLC table.", OFFSET(intra_vlc_format), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },\
+ { "drop_frame_timecode", "Timecode is in drop frame format.", OFFSET(drop_frame_timecode), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE}, \
+ { "scan_offset", "Reserve space for SVCD scan offset user data.", OFFSET(scan_offset), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },
+
+static const AVOption mpeg1_options[] = {
+ COMMON_OPTS
+ { NULL },
+};
+
+static const AVOption mpeg2_options[] = {
+ COMMON_OPTS
+ { "non_linear_quant", "Use nonlinear quantizer.", OFFSET(q_scale_type), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },
+ { "alternate_scan", "Enable alternate scantable.", OFFSET(alternate_scan), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },
+ { NULL },
+};
+
+#define mpeg12_class(x)\
+static const AVClass mpeg## x ##_class = {\
+ .class_name = "mpeg" #x "video encoder",\
+ .item_name = av_default_item_name,\
+ .option = mpeg## x ##_options,\
+ .version = LIBAVUTIL_VERSION_INT,\
+};
+
+mpeg12_class(1)
+mpeg12_class(2)
+
AVCodec ff_mpeg1video_encoder = {
- "mpeg1video",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_MPEG1VIDEO,
- sizeof(MpegEncContext),
- encode_init,
- MPV_encode_picture,
- MPV_encode_end,
- .supported_framerates= ff_frame_rate_tab+1,
+ .name = "mpeg1video",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_MPEG1VIDEO,
+ .priv_data_size = sizeof(MpegEncContext),
+ .init = encode_init,
+ .encode = MPV_encode_picture,
+ .close = MPV_encode_end,
+ .supported_framerates= avpriv_frame_rate_tab+1,
.pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
.capabilities= CODEC_CAP_DELAY | CODEC_CAP_SLICE_THREADS,
.long_name= NULL_IF_CONFIG_SMALL("MPEG-1 video"),
+ .priv_class = &mpeg1_class,
};
AVCodec ff_mpeg2video_encoder = {
- "mpeg2video",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_MPEG2VIDEO,
- sizeof(MpegEncContext),
- encode_init,
- MPV_encode_picture,
- MPV_encode_end,
- .supported_framerates= ff_frame_rate_tab+1,
+ .name = "mpeg2video",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_MPEG2VIDEO,
+ .priv_data_size = sizeof(MpegEncContext),
+ .init = encode_init,
+ .encode = MPV_encode_picture,
+ .close = MPV_encode_end,
+ .supported_framerates= avpriv_frame_rate_tab+1,
.pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_YUV422P, PIX_FMT_NONE},
.capabilities= CODEC_CAP_DELAY | CODEC_CAP_SLICE_THREADS,
.long_name= NULL_IF_CONFIG_SMALL("MPEG-2 video"),
+ .priv_class = &mpeg2_class,
};
diff --git a/libavcodec/mpeg4audio.c b/libavcodec/mpeg4audio.c
index f0399af8fe..ac546ba137 100644
--- a/libavcodec/mpeg4audio.c
+++ b/libavcodec/mpeg4audio.c
@@ -3,20 +3,20 @@
* Copyright (c) 2008 Baptiste Coudurier <baptiste.coudurier@free.fr>
* Copyright (c) 2009 Alex Converse <alex.converse@gmail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -52,7 +52,7 @@ static int parse_config_ALS(GetBitContext *gb, MPEG4AudioConfig *c)
return 0;
}
-const int ff_mpeg4audio_sample_rates[16] = {
+const int avpriv_mpeg4audio_sample_rates[16] = {
96000, 88200, 64000, 48000, 44100, 32000,
24000, 22050, 16000, 12000, 11025, 8000, 7350
};
@@ -73,10 +73,10 @@ static inline int get_sample_rate(GetBitContext *gb, int *index)
{
*index = get_bits(gb, 4);
return *index == 0x0f ? get_bits(gb, 24) :
- ff_mpeg4audio_sample_rates[*index];
+ avpriv_mpeg4audio_sample_rates[*index];
}
-int ff_mpeg4audio_get_config(MPEG4AudioConfig *c, const uint8_t *buf, int buf_size)
+int avpriv_mpeg4audio_get_config(MPEG4AudioConfig *c, const uint8_t *buf, int buf_size)
{
GetBitContext gb;
int specific_config_bitindex;
@@ -151,7 +151,7 @@ static av_always_inline unsigned int copy_bits(PutBitContext *pb,
return el;
}
-int ff_copy_pce_data(PutBitContext *pb, GetBitContext *gb)
+int avpriv_copy_pce_data(PutBitContext *pb, GetBitContext *gb)
{
int five_bit_ch, four_bit_ch, comment_size, bits;
int offset = put_bits_count(pb);
@@ -173,7 +173,7 @@ int ff_copy_pce_data(PutBitContext *pb, GetBitContext *gb)
copy_bits(pb, gb, 16);
if (bits)
copy_bits(pb, gb, bits);
- align_put_bits(pb);
+ avpriv_align_put_bits(pb);
align_get_bits(gb);
comment_size = copy_bits(pb, gb, 8);
for (; comment_size > 0; comment_size--)
diff --git a/libavcodec/mpeg4audio.h b/libavcodec/mpeg4audio.h
index 2d2b4a232e..3d1f7e0c4c 100644
--- a/libavcodec/mpeg4audio.h
+++ b/libavcodec/mpeg4audio.h
@@ -2,20 +2,20 @@
* MPEG-4 Audio common header
* Copyright (c) 2008 Baptiste Coudurier <baptiste.coudurier@free.fr>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -31,16 +31,16 @@ typedef struct {
int sampling_index;
int sample_rate;
int chan_config;
- int sbr; //< -1 implicit, 1 presence
+ int sbr; ///< -1 implicit, 1 presence
int ext_object_type;
int ext_sampling_index;
int ext_sample_rate;
int ext_chan_config;
int channels;
- int ps; //< -1 implicit, 1 presence
+ int ps; ///< -1 implicit, 1 presence
} MPEG4AudioConfig;
-extern const int ff_mpeg4audio_sample_rates[16];
+extern const int avpriv_mpeg4audio_sample_rates[16];
extern const uint8_t ff_mpeg4audio_channels[8];
/**
* Parse MPEG-4 systems extradata to retrieve audio configuration.
@@ -49,7 +49,7 @@ extern const uint8_t ff_mpeg4audio_channels[8];
* @param[in] buf_size Extradata size.
* @return On error -1 is returned, on success AudioSpecificConfig bit index in extradata.
*/
-int ff_mpeg4audio_get_config(MPEG4AudioConfig *c, const uint8_t *buf, int buf_size);
+int avpriv_mpeg4audio_get_config(MPEG4AudioConfig *c, const uint8_t *buf, int buf_size);
enum AudioObjectType {
AOT_NULL,
@@ -101,6 +101,6 @@ enum AudioObjectType {
#define MAX_PCE_SIZE 304 ///<Maximum size of a PCE including the 3-bit ID_PCE
///<marker and the comment
-int ff_copy_pce_data(PutBitContext *pb, GetBitContext *gb);
+int avpriv_copy_pce_data(PutBitContext *pb, GetBitContext *gb);
#endif /* AVCODEC_MPEG4AUDIO_H */
diff --git a/libavcodec/mpeg4data.h b/libavcodec/mpeg4data.h
index 07cbeee18a..1f4e578ca1 100644
--- a/libavcodec/mpeg4data.h
+++ b/libavcodec/mpeg4data.h
@@ -3,20 +3,20 @@
* H263+ support
* copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/mpeg4video.c b/libavcodec/mpeg4video.c
index a4dc80a420..9a093511d5 100644
--- a/libavcodec/mpeg4video.c
+++ b/libavcodec/mpeg4video.c
@@ -3,20 +3,20 @@
* Copyright (c) 2000,2001 Fabrice Bellard
* Copyright (c) 2002-2010 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -89,7 +89,7 @@ static inline void ff_mpeg4_set_one_direct_mv(MpegEncContext *s, int mx, int my,
uint16_t time_pb= s->pb_time;
int p_mx, p_my;
- p_mx= s->next_picture.motion_val[0][xy][0];
+ p_mx = s->next_picture.f.motion_val[0][xy][0];
if((unsigned)(p_mx + tab_bias) < tab_size){
s->mv[0][i][0] = s->direct_scale_mv[0][p_mx + tab_bias] + mx;
s->mv[1][i][0] = mx ? s->mv[0][i][0] - p_mx
@@ -99,7 +99,7 @@ static inline void ff_mpeg4_set_one_direct_mv(MpegEncContext *s, int mx, int my,
s->mv[1][i][0] = mx ? s->mv[0][i][0] - p_mx
: p_mx*(time_pb - time_pp)/time_pp;
}
- p_my= s->next_picture.motion_val[0][xy][1];
+ p_my = s->next_picture.f.motion_val[0][xy][1];
if((unsigned)(p_my + tab_bias) < tab_size){
s->mv[0][i][1] = s->direct_scale_mv[0][p_my + tab_bias] + my;
s->mv[1][i][1] = my ? s->mv[0][i][1] - p_my
@@ -120,7 +120,7 @@ static inline void ff_mpeg4_set_one_direct_mv(MpegEncContext *s, int mx, int my,
*/
int ff_mpeg4_set_direct_mv(MpegEncContext *s, int mx, int my){
const int mb_index= s->mb_x + s->mb_y*s->mb_stride;
- const int colocated_mb_type= s->next_picture.mb_type[mb_index];
+ const int colocated_mb_type = s->next_picture.f.mb_type[mb_index];
uint16_t time_pp;
uint16_t time_pb;
int i;
@@ -137,7 +137,7 @@ int ff_mpeg4_set_direct_mv(MpegEncContext *s, int mx, int my){
} else if(IS_INTERLACED(colocated_mb_type)){
s->mv_type = MV_TYPE_FIELD;
for(i=0; i<2; i++){
- int field_select= s->next_picture.ref_index[0][4*mb_index + 2*i];
+ int field_select = s->next_picture.f.ref_index[0][4 * mb_index + 2 * i];
s->field_select[0][i]= field_select;
s->field_select[1][i]= i;
if(s->top_field_first){
diff --git a/libavcodec/mpeg4video.h b/libavcodec/mpeg4video.h
index d34e73149c..f1e6a4d172 100644
--- a/libavcodec/mpeg4video.h
+++ b/libavcodec/mpeg4video.h
@@ -3,20 +3,20 @@
* Copyright (c) 2000,2001 Fabrice Bellard
* Copyright (c) 2002-2010 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/mpeg4video_parser.c b/libavcodec/mpeg4video_parser.c
index 2e498d100c..a882f06003 100644
--- a/libavcodec/mpeg4video_parser.c
+++ b/libavcodec/mpeg4video_parser.c
@@ -3,20 +3,20 @@
* Copyright (c) 2003 Fabrice Bellard
* Copyright (c) 2003 Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -99,6 +99,7 @@ static av_cold int mpeg4video_parse_init(AVCodecParserContext *s)
if (!pc->enc)
return -1;
pc->first_picture = 1;
+ pc->enc->quant_precision=5;
return 0;
}
diff --git a/libavcodec/mpeg4video_parser.h b/libavcodec/mpeg4video_parser.h
index d907dc4d5b..822a24cb99 100644
--- a/libavcodec/mpeg4video_parser.h
+++ b/libavcodec/mpeg4video_parser.h
@@ -3,20 +3,20 @@
* Copyright (c) 2003 Fabrice Bellard
* Copyright (c) 2003 Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index 22d7ace789..538706460e 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -3,20 +3,20 @@
* Copyright (c) 2000,2001 Fabrice Bellard
* Copyright (c) 2002-2010 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -55,7 +55,7 @@ void mpeg4_pred_ac(MpegEncContext * s, DCTELEM *block, int n,
{
int i;
int16_t *ac_val, *ac_val1;
- int8_t * const qscale_table= s->current_picture.qscale_table;
+ int8_t * const qscale_table = s->current_picture.f.qscale_table;
/* find prediction */
ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
@@ -113,7 +113,7 @@ static inline int mpeg4_is_resync(MpegEncContext *s){
int bits_count= get_bits_count(&s->gb);
int v= show_bits(&s->gb, 16);
- if(s->workaround_bugs&FF_BUG_NO_PADDING){
+ if(s->workaround_bugs&FF_BUG_NO_PADDING && !s->resync_marker){
return 0;
}
@@ -130,10 +130,11 @@ static inline int mpeg4_is_resync(MpegEncContext *s){
v|= 0x7F >> (7-(bits_count&7));
if(v==0x7F)
- return 1;
+ return s->mb_num;
}else{
if(v == ff_mpeg4_resync_prefix[bits_count&7]){
- int len;
+ int len, mb_num;
+ int mb_num_bits= av_log2(s->mb_num - 1) + 1;
GetBitContext gb= s->gb;
skip_bits(&s->gb, 1);
@@ -143,10 +144,14 @@ static inline int mpeg4_is_resync(MpegEncContext *s){
if(get_bits1(&s->gb)) break;
}
+ mb_num= get_bits(&s->gb, mb_num_bits);
+ if(!mb_num || mb_num > s->mb_num || get_bits_count(&s->gb)+6 > s->gb.size_in_bits)
+ mb_num= -1;
+
s->gb= gb;
if(len>=ff_mpeg4_get_video_packet_prefix_length(s))
- return 1;
+ return mb_num;
}
}
return 0;
@@ -373,16 +378,6 @@ int mpeg4_decode_video_packet_header(MpegEncContext *s)
av_log(s->avctx, AV_LOG_ERROR, "illegal mb_num in video packet (%d %d) \n", mb_num, s->mb_num);
return -1;
}
- if(s->pict_type == AV_PICTURE_TYPE_B){
- int mb_x = 0, mb_y = 0;
-
- while(s->next_picture.mbskip_table[ s->mb_index2xy[ mb_num ] ]) {
- if (!mb_x) ff_thread_await_progress((AVFrame*)s->next_picture_ptr, mb_y++, 0);
- mb_num++;
- if (++mb_x == s->mb_width) mb_x = 0;
- }
- if(mb_num >= s->mb_num) return -1; // slice contains just skipped MBs which where already decoded
- }
s->mb_x= mb_num % s->mb_width;
s->mb_y= mb_num / s->mb_width;
@@ -570,13 +565,13 @@ static int mpeg4_decode_partition_a(MpegEncContext *s){
}while(cbpc == 8);
s->cbp_table[xy]= cbpc & 3;
- s->current_picture.mb_type[xy]= MB_TYPE_INTRA;
+ s->current_picture.f.mb_type[xy] = MB_TYPE_INTRA;
s->mb_intra = 1;
if(cbpc & 4) {
ff_set_qscale(s, s->qscale + quant_tab[get_bits(&s->gb, 2)]);
}
- s->current_picture.qscale_table[xy]= s->qscale;
+ s->current_picture.f.qscale_table[xy]= s->qscale;
s->mbintra_table[xy]= 1;
for(i=0; i<6; i++){
@@ -592,7 +587,7 @@ static int mpeg4_decode_partition_a(MpegEncContext *s){
s->pred_dir_table[xy]= dir;
}else{ /* P/S_TYPE */
int mx, my, pred_x, pred_y, bits;
- int16_t * const mot_val= s->current_picture.motion_val[0][s->block_index[0]];
+ int16_t * const mot_val = s->current_picture.f.motion_val[0][s->block_index[0]];
const int stride= s->b8_stride*2;
try_again:
@@ -604,11 +599,11 @@ try_again:
if(bits&0x10000){
/* skip mb */
if(s->pict_type==AV_PICTURE_TYPE_S && s->vol_sprite_usage==GMC_SPRITE){
- s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_GMC | MB_TYPE_L0;
+ s->current_picture.f.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_GMC | MB_TYPE_L0;
mx= get_amv(s, 0);
my= get_amv(s, 1);
}else{
- s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
+ s->current_picture.f.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
mx=my=0;
}
mot_val[0 ]= mot_val[2 ]=
@@ -634,7 +629,7 @@ try_again:
s->mb_intra = ((cbpc & 4) != 0);
if(s->mb_intra){
- s->current_picture.mb_type[xy]= MB_TYPE_INTRA;
+ s->current_picture.f.mb_type[xy] = MB_TYPE_INTRA;
s->mbintra_table[xy]= 1;
mot_val[0 ]= mot_val[2 ]=
mot_val[0+stride]= mot_val[2+stride]= 0;
@@ -660,11 +655,11 @@ try_again:
my = h263_decode_motion(s, pred_y, s->f_code);
if (my >= 0xffff)
return -1;
- s->current_picture.mb_type[xy]= MB_TYPE_16x16 | MB_TYPE_L0;
+ s->current_picture.f.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_L0;
} else {
mx = get_amv(s, 0);
my = get_amv(s, 1);
- s->current_picture.mb_type[xy]= MB_TYPE_16x16 | MB_TYPE_GMC | MB_TYPE_L0;
+ s->current_picture.f.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_GMC | MB_TYPE_L0;
}
mot_val[0 ]= mot_val[2 ] =
@@ -673,7 +668,7 @@ try_again:
mot_val[1+stride]= mot_val[3+stride]= my;
} else {
int i;
- s->current_picture.mb_type[xy]= MB_TYPE_8x8 | MB_TYPE_L0;
+ s->current_picture.f.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_L0;
for(i=0;i<4;i++) {
int16_t *mot_val= h263_pred_motion(s, i, 0, &pred_x, &pred_y);
mx = h263_decode_motion(s, pred_x, s->f_code);
@@ -725,9 +720,9 @@ static int mpeg4_decode_partition_b(MpegEncContext *s, int mb_count){
}
s->cbp_table[xy]|= cbpy<<2;
- s->current_picture.mb_type[xy] |= ac_pred*MB_TYPE_ACPRED;
+ s->current_picture.f.mb_type[xy] |= ac_pred*MB_TYPE_ACPRED;
}else{ /* P || S_TYPE */
- if(IS_INTRA(s->current_picture.mb_type[xy])){
+ if (IS_INTRA(s->current_picture.f.mb_type[xy])) {
int dir=0,i;
int ac_pred = get_bits1(&s->gb);
int cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
@@ -740,7 +735,7 @@ static int mpeg4_decode_partition_b(MpegEncContext *s, int mb_count){
if(s->cbp_table[xy] & 8) {
ff_set_qscale(s, s->qscale + quant_tab[get_bits(&s->gb, 2)]);
}
- s->current_picture.qscale_table[xy]= s->qscale;
+ s->current_picture.f.qscale_table[xy] = s->qscale;
for(i=0; i<6; i++){
int dc_pred_dir;
@@ -754,10 +749,10 @@ static int mpeg4_decode_partition_b(MpegEncContext *s, int mb_count){
}
s->cbp_table[xy]&= 3; //remove dquant
s->cbp_table[xy]|= cbpy<<2;
- s->current_picture.mb_type[xy] |= ac_pred*MB_TYPE_ACPRED;
+ s->current_picture.f.mb_type[xy] |= ac_pred*MB_TYPE_ACPRED;
s->pred_dir_table[xy]= dir;
- }else if(IS_SKIP(s->current_picture.mb_type[xy])){
- s->current_picture.qscale_table[xy]= s->qscale;
+ } else if (IS_SKIP(s->current_picture.f.mb_type[xy])) {
+ s->current_picture.f.qscale_table[xy] = s->qscale;
s->cbp_table[xy]= 0;
}else{
int cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
@@ -770,7 +765,7 @@ static int mpeg4_decode_partition_b(MpegEncContext *s, int mb_count){
if(s->cbp_table[xy] & 8) {
ff_set_qscale(s, s->qscale + quant_tab[get_bits(&s->gb, 2)]);
}
- s->current_picture.qscale_table[xy]= s->qscale;
+ s->current_picture.f.qscale_table[xy] = s->qscale;
s->cbp_table[xy]&= 3; //remove dquant
s->cbp_table[xy]|= (cbpy^0xf)<<2;
@@ -1091,20 +1086,20 @@ static int mpeg4_decode_partitioned_mb(MpegEncContext *s, DCTELEM block[6][64])
int cbp, mb_type;
const int xy= s->mb_x + s->mb_y*s->mb_stride;
- mb_type= s->current_picture.mb_type[xy];
+ mb_type = s->current_picture.f.mb_type[xy];
cbp = s->cbp_table[xy];
s->use_intra_dc_vlc= s->qscale < s->intra_dc_threshold;
- if(s->current_picture.qscale_table[xy] != s->qscale){
- ff_set_qscale(s, s->current_picture.qscale_table[xy] );
+ if (s->current_picture.f.qscale_table[xy] != s->qscale) {
+ ff_set_qscale(s, s->current_picture.f.qscale_table[xy]);
}
if (s->pict_type == AV_PICTURE_TYPE_P || s->pict_type==AV_PICTURE_TYPE_S) {
int i;
for(i=0; i<4; i++){
- s->mv[0][i][0] = s->current_picture.motion_val[0][ s->block_index[i] ][0];
- s->mv[0][i][1] = s->current_picture.motion_val[0][ s->block_index[i] ][1];
+ s->mv[0][i][0] = s->current_picture.f.motion_val[0][s->block_index[i]][0];
+ s->mv[0][i][1] = s->current_picture.f.motion_val[0][s->block_index[i]][1];
}
s->mb_intra = IS_INTRA(mb_type);
@@ -1122,7 +1117,7 @@ static int mpeg4_decode_partitioned_mb(MpegEncContext *s, DCTELEM block[6][64])
s->mb_skipped = 1;
}
}else if(s->mb_intra){
- s->ac_pred = IS_ACPRED(s->current_picture.mb_type[xy]);
+ s->ac_pred = IS_ACPRED(s->current_picture.f.mb_type[xy]);
}else if(!s->mb_intra){
// s->mcsel= 0; //FIXME do we need to init that
@@ -1135,7 +1130,7 @@ static int mpeg4_decode_partitioned_mb(MpegEncContext *s, DCTELEM block[6][64])
}
} else { /* I-Frame */
s->mb_intra = 1;
- s->ac_pred = IS_ACPRED(s->current_picture.mb_type[xy]);
+ s->ac_pred = IS_ACPRED(s->current_picture.f.mb_type[xy]);
}
if (!IS_SKIP(mb_type)) {
@@ -1188,14 +1183,14 @@ static int mpeg4_decode_mb(MpegEncContext *s,
s->mv_dir = MV_DIR_FORWARD;
s->mv_type = MV_TYPE_16X16;
if(s->pict_type==AV_PICTURE_TYPE_S && s->vol_sprite_usage==GMC_SPRITE){
- s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_GMC | MB_TYPE_16x16 | MB_TYPE_L0;
+ s->current_picture.f.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_GMC | MB_TYPE_16x16 | MB_TYPE_L0;
s->mcsel=1;
s->mv[0][0][0]= get_amv(s, 0);
s->mv[0][0][1]= get_amv(s, 1);
s->mb_skipped = 0;
}else{
- s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
+ s->current_picture.f.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
s->mcsel=0;
s->mv[0][0][0] = 0;
s->mv[0][0][1] = 0;
@@ -1230,7 +1225,7 @@ static int mpeg4_decode_mb(MpegEncContext *s,
s->mv_dir = MV_DIR_FORWARD;
if ((cbpc & 16) == 0) {
if(s->mcsel){
- s->current_picture.mb_type[xy]= MB_TYPE_GMC | MB_TYPE_16x16 | MB_TYPE_L0;
+ s->current_picture.f.mb_type[xy] = MB_TYPE_GMC | MB_TYPE_16x16 | MB_TYPE_L0;
/* 16x16 global motion prediction */
s->mv_type = MV_TYPE_16X16;
mx= get_amv(s, 0);
@@ -1238,7 +1233,7 @@ static int mpeg4_decode_mb(MpegEncContext *s,
s->mv[0][0][0] = mx;
s->mv[0][0][1] = my;
}else if((!s->progressive_sequence) && get_bits1(&s->gb)){
- s->current_picture.mb_type[xy]= MB_TYPE_16x8 | MB_TYPE_L0 | MB_TYPE_INTERLACED;
+ s->current_picture.f.mb_type[xy] = MB_TYPE_16x8 | MB_TYPE_L0 | MB_TYPE_INTERLACED;
/* 16x8 field motion prediction */
s->mv_type= MV_TYPE_FIELD;
@@ -1260,7 +1255,7 @@ static int mpeg4_decode_mb(MpegEncContext *s,
s->mv[0][i][1] = my;
}
}else{
- s->current_picture.mb_type[xy]= MB_TYPE_16x16 | MB_TYPE_L0;
+ s->current_picture.f.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_L0;
/* 16x16 motion prediction */
s->mv_type = MV_TYPE_16X16;
h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
@@ -1277,7 +1272,7 @@ static int mpeg4_decode_mb(MpegEncContext *s,
s->mv[0][0][1] = my;
}
} else {
- s->current_picture.mb_type[xy]= MB_TYPE_8x8 | MB_TYPE_L0;
+ s->current_picture.f.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_L0;
s->mv_type = MV_TYPE_8X8;
for(i=0;i<4;i++) {
mot_val = h263_pred_motion(s, i, 0, &pred_x, &pred_y);
@@ -1314,7 +1309,7 @@ static int mpeg4_decode_mb(MpegEncContext *s,
}
/* if we skipped it in the future P Frame than skip it now too */
- s->mb_skipped= s->next_picture.mbskip_table[s->mb_y * s->mb_stride + s->mb_x]; // Note, skiptab=0 if last was GMC
+ s->mb_skipped = s->next_picture.f.mbskip_table[s->mb_y * s->mb_stride + s->mb_x]; // Note, skiptab=0 if last was GMC
if(s->mb_skipped){
/* skip mb */
@@ -1327,7 +1322,7 @@ static int mpeg4_decode_mb(MpegEncContext *s,
s->mv[0][0][1] = 0;
s->mv[1][0][0] = 0;
s->mv[1][0][1] = 0;
- s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
+ s->current_picture.f.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
goto end;
}
@@ -1433,7 +1428,7 @@ static int mpeg4_decode_mb(MpegEncContext *s,
s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT;
mb_type |= ff_mpeg4_set_direct_mv(s, mx, my);
}
- s->current_picture.mb_type[xy]= mb_type;
+ s->current_picture.f.mb_type[xy] = mb_type;
} else { /* I-Frame */
do{
cbpc = get_vlc2(&s->gb, ff_h263_intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 2);
@@ -1448,9 +1443,9 @@ static int mpeg4_decode_mb(MpegEncContext *s,
intra:
s->ac_pred = get_bits1(&s->gb);
if(s->ac_pred)
- s->current_picture.mb_type[xy]= MB_TYPE_INTRA | MB_TYPE_ACPRED;
+ s->current_picture.f.mb_type[xy] = MB_TYPE_INTRA | MB_TYPE_ACPRED;
else
- s->current_picture.mb_type[xy]= MB_TYPE_INTRA;
+ s->current_picture.f.mb_type[xy] = MB_TYPE_INTRA;
cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
if(cbpy<0){
@@ -1488,16 +1483,21 @@ end:
/* per-MB end of slice check */
if(s->codec_id==CODEC_ID_MPEG4){
- if(mpeg4_is_resync(s)){
- const int delta= s->mb_x + 1 == s->mb_width ? 2 : 1;
+ int next= mpeg4_is_resync(s);
+ if(next) {
+ if (s->mb_x + s->mb_y*s->mb_width + 1 > next && s->avctx->error_recognition >= FF_ER_AGGRESSIVE) {
+ return -1;
+ } else if (s->mb_x + s->mb_y*s->mb_width + 1 >= next)
+ return SLICE_END;
- if(s->pict_type==AV_PICTURE_TYPE_B && s->next_picture.mbskip_table[xy + delta]){
+ if(s->pict_type==AV_PICTURE_TYPE_B){
+ const int delta= s->mb_x + 1 == s->mb_width ? 2 : 1;
ff_thread_await_progress((AVFrame*)s->next_picture_ptr,
(s->mb_x + delta >= s->mb_width) ? FFMIN(s->mb_y+1, s->mb_height-1) : s->mb_y, 0);
+ if (s->next_picture.f.mbskip_table[xy + delta])
+ return SLICE_OK;
}
- if(s->pict_type==AV_PICTURE_TYPE_B && s->next_picture.mbskip_table[xy + delta])
- return SLICE_OK;
return SLICE_END;
}
}
@@ -1508,16 +1508,33 @@ end:
static int mpeg4_decode_gop_header(MpegEncContext * s, GetBitContext *gb){
int hours, minutes, seconds;
- unsigned time_code = show_bits(gb, 18);
-
- if (time_code & 0x40) { /* marker_bit */
- hours = time_code >> 13;
- minutes = time_code >> 7 & 0x3f;
- seconds = time_code & 0x3f;
- s->time_base = seconds + 60*(minutes + 60*hours);
- skip_bits(gb, 20); /* time_code, closed_gov, broken_link */
- } else {
- av_log(s->avctx, AV_LOG_WARNING, "GOP header missing marker_bit\n");
+
+ if(!show_bits(gb, 23)){
+ av_log(s->avctx, AV_LOG_WARNING, "GOP header invalid\n");
+ return -1;
+ }
+
+ hours= get_bits(gb, 5);
+ minutes= get_bits(gb, 6);
+ skip_bits1(gb);
+ seconds= get_bits(gb, 6);
+
+ s->time_base= seconds + 60*(minutes + 60*hours);
+
+ skip_bits1(gb);
+ skip_bits1(gb);
+
+ return 0;
+}
+
+static int mpeg4_decode_profile_level(MpegEncContext * s, GetBitContext *gb){
+
+ s->avctx->profile = get_bits(gb, 4);
+ s->avctx->level = get_bits(gb, 4);
+
+ // for Simple profile, level 0
+ if (s->avctx->profile == 0 && s->avctx->level == 8) {
+ s->avctx->level = 0;
}
return 0;
@@ -1961,11 +1978,12 @@ static int decode_vop_header(MpegEncContext *s, GetBitContext *gb){
}
if(s->avctx->time_base.num)
- s->current_picture_ptr->pts= (s->time + s->avctx->time_base.num/2) / s->avctx->time_base.num;
+ s->current_picture_ptr->f.pts = (s->time + s->avctx->time_base.num / 2) / s->avctx->time_base.num;
else
- s->current_picture_ptr->pts= AV_NOPTS_VALUE;
+ s->current_picture_ptr->f.pts = AV_NOPTS_VALUE;
if(s->avctx->debug&FF_DEBUG_PTS)
- av_log(s->avctx, AV_LOG_DEBUG, "MPEG4 PTS: %"PRId64"\n", s->current_picture_ptr->pts);
+ av_log(s->avctx, AV_LOG_DEBUG, "MPEG4 PTS: %"PRId64"\n",
+ s->current_picture_ptr->f.pts);
check_marker(gb, "before vop_coded");
@@ -2106,7 +2124,7 @@ static int decode_vop_header(MpegEncContext *s, GetBitContext *gb){
*/
int ff_mpeg4_decode_picture_header(MpegEncContext * s, GetBitContext *gb)
{
- int startcode, v;
+ unsigned startcode, v;
/* search next start code */
align_get_bits(gb);
@@ -2176,6 +2194,9 @@ int ff_mpeg4_decode_picture_header(MpegEncContext * s, GetBitContext *gb)
else if(startcode == GOP_STARTCODE){
mpeg4_decode_gop_header(s, gb);
}
+ else if(startcode == VOS_STARTCODE){
+ mpeg4_decode_profile_level(s, gb);
+ }
else if(startcode == VOP_STARTCODE){
break;
}
@@ -2236,35 +2257,53 @@ static av_cold int decode_init(AVCodecContext *avctx)
return 0;
}
+static const AVProfile mpeg4_video_profiles[] = {
+ { FF_PROFILE_MPEG4_SIMPLE, "Simple Profile" },
+ { FF_PROFILE_MPEG4_SIMPLE_SCALABLE, "Simple Scalable Profile" },
+ { FF_PROFILE_MPEG4_CORE, "Core Profile" },
+ { FF_PROFILE_MPEG4_MAIN, "Main Profile" },
+ { FF_PROFILE_MPEG4_N_BIT, "N-bit Profile" },
+ { FF_PROFILE_MPEG4_SCALABLE_TEXTURE, "Scalable Texture Profile" },
+ { FF_PROFILE_MPEG4_SIMPLE_FACE_ANIMATION, "Simple Face Animation Profile" },
+ { FF_PROFILE_MPEG4_BASIC_ANIMATED_TEXTURE, "Basic Animated Texture Profile" },
+ { FF_PROFILE_MPEG4_HYBRID, "Hybrid Profile" },
+ { FF_PROFILE_MPEG4_ADVANCED_REAL_TIME, "Advanced Real Time Simple Profile" },
+ { FF_PROFILE_MPEG4_CORE_SCALABLE, "Code Scalable Profile" },
+ { FF_PROFILE_MPEG4_ADVANCED_CODING, "Advanced Coding Profile" },
+ { FF_PROFILE_MPEG4_ADVANCED_CORE, "Advanced Core Profile" },
+ { FF_PROFILE_MPEG4_ADVANCED_SCALABLE_TEXTURE, "Advanced Scalable Texture Profile" },
+ { FF_PROFILE_MPEG4_SIMPLE_STUDIO, "Simple Studio Profile" },
+ { FF_PROFILE_MPEG4_ADVANCED_SIMPLE, "Advanced Simple Profile" },
+};
+
AVCodec ff_mpeg4_decoder = {
- "mpeg4",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_MPEG4,
- sizeof(MpegEncContext),
- decode_init,
- NULL,
- ff_h263_decode_end,
- ff_h263_decode_frame,
- CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY | CODEC_CAP_FRAME_THREADS,
+ .name = "mpeg4",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_MPEG4,
+ .priv_data_size = sizeof(MpegEncContext),
+ .init = decode_init,
+ .close = ff_h263_decode_end,
+ .decode = ff_h263_decode_frame,
+ .capabilities = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY | CODEC_CAP_FRAME_THREADS,
.flush= ff_mpeg_flush,
.max_lowres= 3,
.long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2"),
.pix_fmts= ff_hwaccel_pixfmt_list_420,
+ .profiles = NULL_IF_CONFIG_SMALL(mpeg4_video_profiles),
.update_thread_context= ONLY_IF_THREADS_ENABLED(ff_mpeg_update_thread_context)
};
#if CONFIG_MPEG4_VDPAU_DECODER
AVCodec ff_mpeg4_vdpau_decoder = {
- "mpeg4_vdpau",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_MPEG4,
- sizeof(MpegEncContext),
- decode_init,
- NULL,
- ff_h263_decode_end,
- ff_h263_decode_frame,
- CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY | CODEC_CAP_HWACCEL_VDPAU,
+ .name = "mpeg4_vdpau",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_MPEG4,
+ .priv_data_size = sizeof(MpegEncContext),
+ .init = decode_init,
+ .close = ff_h263_decode_end,
+ .decode = ff_h263_decode_frame,
+ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY | CODEC_CAP_HWACCEL_VDPAU,
.long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 (VDPAU)"),
.pix_fmts= (const enum PixelFormat[]){PIX_FMT_VDPAU_MPEG4, PIX_FMT_NONE},
};
diff --git a/libavcodec/mpeg4videoenc.c b/libavcodec/mpeg4videoenc.c
index 8a044d6d23..dac9a9c885 100644
--- a/libavcodec/mpeg4videoenc.c
+++ b/libavcodec/mpeg4videoenc.c
@@ -3,23 +3,25 @@
* Copyright (c) 2000,2001 Fabrice Bellard
* Copyright (c) 2002-2010 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include "libavutil/log.h"
+#include "libavutil/opt.h"
#include "mpegvideo.h"
#include "h263.h"
#include "mpeg4video.h"
@@ -124,7 +126,7 @@ static inline int decide_ac_pred(MpegEncContext * s, DCTELEM block[6][64], const
{
int score= 0;
int i, n;
- int8_t * const qscale_table= s->current_picture.qscale_table;
+ int8_t * const qscale_table = s->current_picture.f.qscale_table;
memcpy(zigzag_last_index, s->block_last_index, sizeof(int)*6);
@@ -201,7 +203,7 @@ static inline int decide_ac_pred(MpegEncContext * s, DCTELEM block[6][64], const
*/
void ff_clean_mpeg4_qscales(MpegEncContext *s){
int i;
- int8_t * const qscale_table= s->current_picture.qscale_table;
+ int8_t * const qscale_table = s->current_picture.f.qscale_table;
ff_clean_h263_qscales(s);
@@ -457,7 +459,7 @@ void mpeg4_encode_mb(MpegEncContext * s,
assert(mb_type>=0);
/* nothing to do if this MB was skipped in the next P Frame */
- if(s->next_picture.mbskip_table[s->mb_y * s->mb_stride + s->mb_x]){ //FIXME avoid DCT & ...
+ if (s->next_picture.f.mbskip_table[s->mb_y * s->mb_stride + s->mb_x]) { //FIXME avoid DCT & ...
s->skip_count++;
s->mv[0][0][0]=
s->mv[0][0][1]=
@@ -585,11 +587,9 @@ void mpeg4_encode_mb(MpegEncContext * s,
x= s->mb_x*16;
y= s->mb_y*16;
- if(x+16 > s->width) x= s->width-16;
- if(y+16 > s->height) y= s->height-16;
offset= x + y*s->linesize;
- p_pic= s->new_picture.data[0] + offset;
+ p_pic = s->new_picture.f.data[0] + offset;
s->mb_skipped=1;
for(i=0; i<s->max_b_frames; i++){
@@ -597,12 +597,27 @@ void mpeg4_encode_mb(MpegEncContext * s,
int diff;
Picture *pic= s->reordered_input_picture[i+1];
- if(pic==NULL || pic->pict_type!=AV_PICTURE_TYPE_B) break;
+ if (pic == NULL || pic->f.pict_type != AV_PICTURE_TYPE_B)
+ break;
- b_pic= pic->data[0] + offset;
- if(pic->type != FF_BUFFER_TYPE_SHARED)
+ b_pic = pic->f.data[0] + offset;
+ if (pic->f.type != FF_BUFFER_TYPE_SHARED)
b_pic+= INPLACE_OFFSET;
- diff= s->dsp.sad[0](NULL, p_pic, b_pic, s->linesize, 16);
+
+ if(x+16 > s->width || y+16 > s->height){
+ int x1,y1;
+ int xe= FFMIN(16, s->width - x);
+ int ye= FFMIN(16, s->height- y);
+ diff=0;
+ for(y1=0; y1<ye; y1++){
+ for(x1=0; x1<xe; x1++){
+ diff+= FFABS(p_pic[x1+y1*s->linesize] - b_pic[x1+y1*s->linesize]);
+ }
+ }
+ diff= diff*256/(xe*ye);
+ }else{
+ diff= s->dsp.sad[0](NULL, p_pic, b_pic, s->linesize, 16);
+ }
if(diff>s->qscale*70){ //FIXME check that 70 is optimal
s->mb_skipped=0;
break;
@@ -704,8 +719,8 @@ void mpeg4_encode_mb(MpegEncContext * s,
/* motion vectors: 8x8 mode*/
h263_pred_motion(s, i, 0, &pred_x, &pred_y);
- ff_h263_encode_motion_vector(s, s->current_picture.motion_val[0][ s->block_index[i] ][0] - pred_x,
- s->current_picture.motion_val[0][ s->block_index[i] ][1] - pred_y, s->f_code);
+ ff_h263_encode_motion_vector(s, s->current_picture.f.motion_val[0][ s->block_index[i] ][0] - pred_x,
+ s->current_picture.f.motion_val[0][ s->block_index[i] ][1] - pred_y, s->f_code);
}
}
@@ -803,7 +818,7 @@ void ff_set_mpeg4_time(MpegEncContext * s){
ff_mpeg4_init_direct_mv(s);
}else{
s->last_time_base= s->time_base;
- s->time_base= s->time/s->avctx->time_base.den;
+ s->time_base= FFUDIV(s->time, s->avctx->time_base.den);
}
}
@@ -814,15 +829,16 @@ static void mpeg4_encode_gop_header(MpegEncContext * s){
put_bits(&s->pb, 16, 0);
put_bits(&s->pb, 16, GOP_STARTCODE);
- time= s->current_picture_ptr->pts;
+ time = s->current_picture_ptr->f.pts;
if(s->reordered_input_picture[1])
- time= FFMIN(time, s->reordered_input_picture[1]->pts);
+ time = FFMIN(time, s->reordered_input_picture[1]->f.pts);
time= time*s->avctx->time_base.num;
+ s->last_time_base= FFUDIV(time, s->avctx->time_base.den);
- seconds= time/s->avctx->time_base.den;
- minutes= seconds/60; seconds %= 60;
- hours= minutes/60; minutes %= 60;
- hours%=24;
+ seconds= FFUDIV(time, s->avctx->time_base.den);
+ minutes= FFUDIV(seconds, 60); seconds = FFUMOD(seconds, 60);
+ hours = FFUDIV(minutes, 60); minutes = FFUMOD(minutes, 60);
+ hours = FFUMOD(hours , 24);
put_bits(&s->pb, 5, hours);
put_bits(&s->pb, 6, minutes);
@@ -832,8 +848,6 @@ static void mpeg4_encode_gop_header(MpegEncContext * s){
put_bits(&s->pb, 1, !!(s->flags&CODEC_FLAG_CLOSED_GOP));
put_bits(&s->pb, 1, 0); //broken link == NO
- s->last_time_base= time / s->avctx->time_base.den;
-
ff_mpeg4_stuffing(&s->pb);
}
@@ -1006,9 +1020,8 @@ void mpeg4_encode_picture_header(MpegEncContext * s, int picture_number)
put_bits(&s->pb, 16, VOP_STARTCODE); /* vop header */
put_bits(&s->pb, 2, s->pict_type - 1); /* pict type: I = 0 , P = 1 */
- assert(s->time>=0);
- time_div= s->time/s->avctx->time_base.den;
- time_mod= s->time%s->avctx->time_base.den;
+ time_div= FFUDIV(s->time, s->avctx->time_base.den);
+ time_mod= FFUMOD(s->time, s->avctx->time_base.den);
time_incr= time_div - s->last_time_base;
assert(time_incr >= 0);
while(time_incr--)
@@ -1026,7 +1039,7 @@ void mpeg4_encode_picture_header(MpegEncContext * s, int picture_number)
}
put_bits(&s->pb, 3, 0); /* intra dc VLC threshold */
if(!s->progressive_sequence){
- put_bits(&s->pb, 1, s->current_picture_ptr->top_field_first);
+ put_bits(&s->pb, 1, s->current_picture_ptr->f.top_field_first);
put_bits(&s->pb, 1, s->alternate_scan);
}
//FIXME sprite stuff
@@ -1255,8 +1268,8 @@ void ff_mpeg4_merge_partitions(MpegEncContext *s)
flush_put_bits(&s->tex_pb);
set_put_bits_buffer_size(&s->pb, s->pb2.buf_end - s->pb.buf);
- ff_copy_bits(&s->pb, s->pb2.buf , pb2_len);
- ff_copy_bits(&s->pb, s->tex_pb.buf, tex_pb_len);
+ avpriv_copy_bits(&s->pb, s->pb2.buf , pb2_len);
+ avpriv_copy_bits(&s->pb, s->tex_pb.buf, tex_pb_len);
s->last_bits= put_bits_count(&s->pb);
}
@@ -1273,15 +1286,31 @@ void ff_mpeg4_encode_video_packet_header(MpegEncContext *s)
put_bits(&s->pb, 1, 0); /* no HEC */
}
+#define OFFSET(x) offsetof(MpegEncContext, x)
+#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
+static const AVOption options[] = {
+ { "data_partitioning", "Use data partitioning.", OFFSET(data_partitioning), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },
+ { "alternate_scan", "Enable alternate scantable.", OFFSET(alternate_scan), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },
+ { NULL },
+};
+
+static const AVClass mpeg4enc_class = {
+ .class_name = "MPEG4 encoder",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
AVCodec ff_mpeg4_encoder = {
- "mpeg4",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_MPEG4,
- sizeof(MpegEncContext),
- encode_init,
- MPV_encode_picture,
- MPV_encode_end,
+ .name = "mpeg4",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_MPEG4,
+ .priv_data_size = sizeof(MpegEncContext),
+ .init = encode_init,
+ .encode = MPV_encode_picture,
+ .close = MPV_encode_end,
.pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
.capabilities= CODEC_CAP_DELAY | CODEC_CAP_SLICE_THREADS,
.long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2"),
+ .priv_class = &mpeg4enc_class,
};
diff --git a/libavcodec/mpegaudio.c b/libavcodec/mpegaudio.c
index 1a8363540e..cba52992ef 100644
--- a/libavcodec/mpegaudio.c
+++ b/libavcodec/mpegaudio.c
@@ -2,20 +2,20 @@
* MPEG Audio common code
* Copyright (c) 2001, 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/mpegaudio.h b/libavcodec/mpegaudio.h
index b55680100b..b829cd3f8a 100644
--- a/libavcodec/mpegaudio.h
+++ b/libavcodec/mpegaudio.h
@@ -1,20 +1,20 @@
/*
* copyright (c) 2001 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/mpegaudio_parser.c b/libavcodec/mpegaudio_parser.c
index f07d34bd29..b13b7881ca 100644
--- a/libavcodec/mpegaudio_parser.c
+++ b/libavcodec/mpegaudio_parser.c
@@ -3,20 +3,20 @@
* Copyright (c) 2003 Fabrice Bellard
* Copyright (c) 2003 Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -64,9 +64,10 @@ static int mpegaudio_parse(AVCodecParserContext *s1,
state= (state<<8) + buf[i++];
- ret = ff_mpa_decode_header(avctx, state, &sr, &channels, &frame_size, &bit_rate);
+ ret = avpriv_mpa_decode_header(avctx, state, &sr, &channels, &frame_size, &bit_rate);
if (ret < 4) {
- s->header_count= -2;
+ if(i > 4)
+ s->header_count= -2;
} else {
if((state&SAME_HEADER_MASK) != (s->header&SAME_HEADER_MASK) && s->header)
s->header_count= -3;
diff --git a/libavcodec/mpegaudio_tablegen.c b/libavcodec/mpegaudio_tablegen.c
index b4c240bd7c..90c9de430a 100644
--- a/libavcodec/mpegaudio_tablegen.c
+++ b/libavcodec/mpegaudio_tablegen.c
@@ -3,20 +3,20 @@
*
* Copyright (c) 2009 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/mpegaudio_tablegen.h b/libavcodec/mpegaudio_tablegen.h
index a222f2c423..291e40b9aa 100644
--- a/libavcodec/mpegaudio_tablegen.h
+++ b/libavcodec/mpegaudio_tablegen.h
@@ -3,20 +3,20 @@
*
* Copyright (c) 2009 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/mpegaudiodata.c b/libavcodec/mpegaudiodata.c
index b850d22c9e..32299a47cf 100644
--- a/libavcodec/mpegaudiodata.c
+++ b/libavcodec/mpegaudiodata.c
@@ -2,20 +2,20 @@
* MPEG Audio common tables
* copyright (c) 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -27,7 +27,7 @@
#include "mpegaudiodata.h"
-const uint16_t ff_mpa_bitrate_tab[2][3][15] = {
+const uint16_t avpriv_mpa_bitrate_tab[2][3][15] = {
{ {0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448 },
{0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384 },
{0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320 } },
@@ -37,7 +37,7 @@ const uint16_t ff_mpa_bitrate_tab[2][3][15] = {
}
};
-const uint16_t ff_mpa_freq_tab[3] = { 44100, 48000, 32000 };
+const uint16_t avpriv_mpa_freq_tab[3] = { 44100, 48000, 32000 };
/*******************************************************/
/* half mpeg encoding window (full precision) */
diff --git a/libavcodec/mpegaudiodata.h b/libavcodec/mpegaudiodata.h
index 84458836fa..71645a668d 100644
--- a/libavcodec/mpegaudiodata.h
+++ b/libavcodec/mpegaudiodata.h
@@ -2,20 +2,20 @@
* MPEG Audio common tables
* copyright (c) 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -32,8 +32,8 @@
#define MODE_EXT_MS_STEREO 2
#define MODE_EXT_I_STEREO 1
-extern const uint16_t ff_mpa_bitrate_tab[2][3][15];
-extern const uint16_t ff_mpa_freq_tab[3];
+extern const uint16_t avpriv_mpa_bitrate_tab[2][3][15];
+extern const uint16_t avpriv_mpa_freq_tab[3];
extern const int32_t ff_mpa_enwindow[257];
extern const int ff_mpa_sblimit_table[5];
extern const int ff_mpa_quant_steps[17];
diff --git a/libavcodec/mpegaudiodec.c b/libavcodec/mpegaudiodec.c
index 033d76e049..f5f169a8e3 100644
--- a/libavcodec/mpegaudiodec.c
+++ b/libavcodec/mpegaudiodec.c
@@ -2,20 +2,20 @@
* MPEG Audio decoder
* Copyright (c) 2001, 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -1709,7 +1709,6 @@ static int mp_decode_frame(MPADecodeContext *s,
if (s->error_protection)
skip_bits(&s->gb, 16);
- av_dlog(s->avctx, "frame %d:\n", s->frame_count);
switch(s->layer) {
case 1:
s->avctx->frame_size = 384;
@@ -1790,7 +1789,7 @@ static int decode_frame(AVCodecContext * avctx,
return -1;
}
- if (ff_mpegaudio_decode_header((MPADecodeHeader *)s, header) == 1) {
+ if (avpriv_mpegaudio_decode_header((MPADecodeHeader *)s, header) == 1) {
/* free format: prepare to compute frame size */
s->frame_size = -1;
return -1;
@@ -1810,7 +1809,7 @@ static int decode_frame(AVCodecContext * avctx,
av_log(avctx, AV_LOG_ERROR, "incomplete frame\n");
return -1;
}else if(s->frame_size < buf_size){
- av_log(avctx, AV_LOG_ERROR, "incorrect frame size\n");
+ av_log(avctx, AV_LOG_DEBUG, "incorrect frame size - multiple frames in buffer?\n");
buf_size= s->frame_size;
}
@@ -1863,7 +1862,7 @@ static int decode_frame_adu(AVCodecContext * avctx,
return buf_size;
}
- ff_mpegaudio_decode_header((MPADecodeHeader *)s, header);
+ avpriv_mpegaudio_decode_header((MPADecodeHeader *)s, header);
/* update codec info */
avctx->sample_rate = s->sample_rate;
avctx->channels = s->nb_channels;
@@ -1894,24 +1893,50 @@ typedef struct MP3On4DecodeContext {
int syncword; ///< syncword patch
const uint8_t *coff; ///< channels offsets in output buffer
MPADecodeContext *mp3decctx[5]; ///< MPADecodeContext for every decoder instance
+ OUT_INT *decoded_buf; ///< output buffer for decoded samples
} MP3On4DecodeContext;
#include "mpeg4audio.h"
/* Next 3 arrays are indexed by channel config number (passed via codecdata) */
static const uint8_t mp3Frames[8] = {0,1,1,2,3,3,4,5}; /* number of mp3 decoder instances */
-/* offsets into output buffer, assume output order is FL FR BL BR C LFE */
+/* offsets into output buffer, assume output order is FL FR C LFE BL BR SL SR */
static const uint8_t chan_offset[8][5] = {
{0},
{0}, // C
{0}, // FLR
{2,0}, // C FLR
{2,0,3}, // C FLR BS
- {4,0,2}, // C FLR BLRS
- {4,0,2,5}, // C FLR BLRS LFE
- {4,0,2,6,5}, // C FLR BLRS BLR LFE
+ {2,0,3}, // C FLR BLRS
+ {2,0,4,3}, // C FLR BLRS LFE
+ {2,0,6,4,3}, // C FLR BLRS BLR LFE
};
+/* mp3on4 channel layouts */
+static const int16_t chan_layout[8] = {
+ 0,
+ AV_CH_LAYOUT_MONO,
+ AV_CH_LAYOUT_STEREO,
+ AV_CH_LAYOUT_SURROUND,
+ AV_CH_LAYOUT_4POINT0,
+ AV_CH_LAYOUT_5POINT0,
+ AV_CH_LAYOUT_5POINT1,
+ AV_CH_LAYOUT_7POINT1
+};
+
+static av_cold int decode_close_mp3on4(AVCodecContext * avctx)
+{
+ MP3On4DecodeContext *s = avctx->priv_data;
+ int i;
+
+ for (i = 0; i < s->frames; i++)
+ av_free(s->mp3decctx[i]);
+
+ av_freep(&s->decoded_buf);
+
+ return 0;
+}
+
static int decode_init_mp3on4(AVCodecContext * avctx)
{
@@ -1924,7 +1949,7 @@ static int decode_init_mp3on4(AVCodecContext * avctx)
return -1;
}
- ff_mpeg4audio_get_config(&cfg, avctx->extradata, avctx->extradata_size);
+ avpriv_mpeg4audio_get_config(&cfg, avctx->extradata, avctx->extradata_size);
if (!cfg.chan_config || cfg.chan_config > 7) {
av_log(avctx, AV_LOG_ERROR, "Invalid channel config number.\n");
return -1;
@@ -1932,6 +1957,7 @@ static int decode_init_mp3on4(AVCodecContext * avctx)
s->frames = mp3Frames[cfg.chan_config];
s->coff = chan_offset[cfg.chan_config];
avctx->channels = ff_mpeg4audio_channels[cfg.chan_config];
+ avctx->channel_layout = chan_layout[cfg.chan_config];
if (cfg.sample_rate < 16000)
s->syncword = 0xffe00000;
@@ -1945,6 +1971,8 @@ static int decode_init_mp3on4(AVCodecContext * avctx)
*/
// Allocate zeroed memory for the first decoder context
s->mp3decctx[0] = av_mallocz(sizeof(MPADecodeContext));
+ if (!s->mp3decctx[0])
+ goto alloc_fail;
// Put decoder context in place to make init_decode() happy
avctx->priv_data = s->mp3decctx[0];
decode_init(avctx);
@@ -1957,23 +1985,38 @@ static int decode_init_mp3on4(AVCodecContext * avctx)
*/
for (i = 1; i < s->frames; i++) {
s->mp3decctx[i] = av_mallocz(sizeof(MPADecodeContext));
+ if (!s->mp3decctx[i])
+ goto alloc_fail;
s->mp3decctx[i]->adu_mode = 1;
s->mp3decctx[i]->avctx = avctx;
+ s->mp3decctx[i]->mpadsp = s->mp3decctx[0]->mpadsp;
+ }
+
+ /* Allocate buffer for multi-channel output if needed */
+ if (s->frames > 1) {
+ s->decoded_buf = av_malloc(MPA_FRAME_SIZE * MPA_MAX_CHANNELS *
+ sizeof(*s->decoded_buf));
+ if (!s->decoded_buf)
+ goto alloc_fail;
}
return 0;
+alloc_fail:
+ decode_close_mp3on4(avctx);
+ return AVERROR(ENOMEM);
}
-static av_cold int decode_close_mp3on4(AVCodecContext * avctx)
+static void flush_mp3on4(AVCodecContext *avctx)
{
- MP3On4DecodeContext *s = avctx->priv_data;
int i;
+ MP3On4DecodeContext *s = avctx->priv_data;
- for (i = 0; i < s->frames; i++)
- av_free(s->mp3decctx[i]);
-
- return 0;
+ for (i = 0; i < s->frames; i++) {
+ MPADecodeContext *m = s->mp3decctx[i];
+ memset(m->synth_buf, 0, sizeof(m->synth_buf));
+ m->last_buf_size = 0;
+ }
}
@@ -1988,12 +2031,13 @@ static int decode_frame_mp3on4(AVCodecContext * avctx,
int fsize, len = buf_size, out_size = 0;
uint32_t header;
OUT_INT *out_samples = data;
- OUT_INT decoded_buf[MPA_FRAME_SIZE * MPA_MAX_CHANNELS];
OUT_INT *outptr, *bp;
- int fr, j, n;
+ int fr, j, n, ch;
- if(*data_size < MPA_FRAME_SIZE * MPA_MAX_CHANNELS * s->frames * sizeof(OUT_INT))
- return -1;
+ if (*data_size < MPA_FRAME_SIZE * avctx->channels * sizeof(OUT_INT)) {
+ av_log(avctx, AV_LOG_ERROR, "output buffer is too small\n");
+ return AVERROR(EINVAL);
+ }
*data_size = 0;
// Discard too short frames
@@ -2001,10 +2045,11 @@ static int decode_frame_mp3on4(AVCodecContext * avctx,
return -1;
// If only one decoder interleave is not needed
- outptr = s->frames == 1 ? out_samples : decoded_buf;
+ outptr = s->frames == 1 ? out_samples : s->decoded_buf;
avctx->bit_rate = 0;
+ ch = 0;
for (fr = 0; fr < s->frames; fr++) {
fsize = AV_RB16(buf) >> 4;
fsize = FFMIN3(fsize, len, MPA_MAX_CODED_FRAME_SIZE);
@@ -2016,7 +2061,15 @@ static int decode_frame_mp3on4(AVCodecContext * avctx,
if (ff_mpa_check_header(header) < 0) // Bad header, discard block
break;
- ff_mpegaudio_decode_header((MPADecodeHeader *)m, header);
+ avpriv_mpegaudio_decode_header((MPADecodeHeader *)m, header);
+
+ if (ch + m->nb_channels > avctx->channels) {
+ av_log(avctx, AV_LOG_ERROR, "frame channel count exceeds codec "
+ "channel count\n");
+ return AVERROR_INVALIDDATA;
+ }
+ ch += m->nb_channels;
+
out_size += mp_decode_frame(m, outptr, buf, fsize);
buf += fsize;
len -= fsize;
@@ -2027,13 +2080,13 @@ static int decode_frame_mp3on4(AVCodecContext * avctx,
bp = out_samples + s->coff[fr];
if(m->nb_channels == 1) {
for(j = 0; j < n; j++) {
- *bp = decoded_buf[j];
+ *bp = s->decoded_buf[j];
bp += avctx->channels;
}
} else {
for(j = 0; j < n; j++) {
- bp[0] = decoded_buf[j++];
- bp[1] = decoded_buf[j];
+ bp[0] = s->decoded_buf[j++];
+ bp[1] = s->decoded_buf[j];
bp += avctx->channels;
}
}
@@ -2051,82 +2104,68 @@ static int decode_frame_mp3on4(AVCodecContext * avctx,
#if !CONFIG_FLOAT
#if CONFIG_MP1_DECODER
-AVCodec ff_mp1_decoder =
-{
- "mp1",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_MP1,
- sizeof(MPADecodeContext),
- decode_init,
- NULL,
- NULL,
- decode_frame,
- CODEC_CAP_PARSE_ONLY,
- .flush= flush,
- .long_name= NULL_IF_CONFIG_SMALL("MP1 (MPEG audio layer 1)"),
+AVCodec ff_mp1_decoder = {
+ .name = "mp1",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_MP1,
+ .priv_data_size = sizeof(MPADecodeContext),
+ .init = decode_init,
+ .decode = decode_frame,
+ .capabilities = CODEC_CAP_PARSE_ONLY,
+ .flush = flush,
+ .long_name = NULL_IF_CONFIG_SMALL("MP1 (MPEG audio layer 1)"),
};
#endif
#if CONFIG_MP2_DECODER
-AVCodec ff_mp2_decoder =
-{
- "mp2",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_MP2,
- sizeof(MPADecodeContext),
- decode_init,
- NULL,
- NULL,
- decode_frame,
- CODEC_CAP_PARSE_ONLY,
- .flush= flush,
- .long_name= NULL_IF_CONFIG_SMALL("MP2 (MPEG audio layer 2)"),
+AVCodec ff_mp2_decoder = {
+ .name = "mp2",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_MP2,
+ .priv_data_size = sizeof(MPADecodeContext),
+ .init = decode_init,
+ .decode = decode_frame,
+ .capabilities = CODEC_CAP_PARSE_ONLY,
+ .flush = flush,
+ .long_name = NULL_IF_CONFIG_SMALL("MP2 (MPEG audio layer 2)"),
};
#endif
#if CONFIG_MP3_DECODER
-AVCodec ff_mp3_decoder =
-{
- "mp3",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_MP3,
- sizeof(MPADecodeContext),
- decode_init,
- NULL,
- NULL,
- decode_frame,
- CODEC_CAP_PARSE_ONLY,
- .flush= flush,
- .long_name= NULL_IF_CONFIG_SMALL("MP3 (MPEG audio layer 3)"),
+AVCodec ff_mp3_decoder = {
+ .name = "mp3",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_MP3,
+ .priv_data_size = sizeof(MPADecodeContext),
+ .init = decode_init,
+ .decode = decode_frame,
+ .capabilities = CODEC_CAP_PARSE_ONLY,
+ .flush = flush,
+ .long_name = NULL_IF_CONFIG_SMALL("MP3 (MPEG audio layer 3)"),
};
#endif
#if CONFIG_MP3ADU_DECODER
-AVCodec ff_mp3adu_decoder =
-{
- "mp3adu",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_MP3ADU,
- sizeof(MPADecodeContext),
- decode_init,
- NULL,
- NULL,
- decode_frame_adu,
- CODEC_CAP_PARSE_ONLY,
- .flush= flush,
- .long_name= NULL_IF_CONFIG_SMALL("ADU (Application Data Unit) MP3 (MPEG audio layer 3)"),
+AVCodec ff_mp3adu_decoder = {
+ .name = "mp3adu",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_MP3ADU,
+ .priv_data_size = sizeof(MPADecodeContext),
+ .init = decode_init,
+ .decode = decode_frame_adu,
+ .capabilities = CODEC_CAP_PARSE_ONLY,
+ .flush = flush,
+ .long_name = NULL_IF_CONFIG_SMALL("ADU (Application Data Unit) MP3 (MPEG audio layer 3)"),
};
#endif
#if CONFIG_MP3ON4_DECODER
-AVCodec ff_mp3on4_decoder =
-{
- "mp3on4",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_MP3ON4,
- sizeof(MP3On4DecodeContext),
- decode_init_mp3on4,
- NULL,
- decode_close_mp3on4,
- decode_frame_mp3on4,
- .flush= flush,
- .long_name= NULL_IF_CONFIG_SMALL("MP3onMP4"),
+AVCodec ff_mp3on4_decoder = {
+ .name = "mp3on4",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_MP3ON4,
+ .priv_data_size = sizeof(MP3On4DecodeContext),
+ .init = decode_init_mp3on4,
+ .close = decode_close_mp3on4,
+ .decode = decode_frame_mp3on4,
+ .flush = flush_mp3on4,
+ .long_name = NULL_IF_CONFIG_SMALL("MP3onMP4"),
};
#endif
#endif
diff --git a/libavcodec/mpegaudiodec_float.c b/libavcodec/mpegaudiodec_float.c
index 0ff866af31..312b84278f 100644
--- a/libavcodec/mpegaudiodec_float.c
+++ b/libavcodec/mpegaudiodec_float.c
@@ -2,20 +2,20 @@
* Float MPEG Audio decoder
* Copyright (c) 2010 Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -23,81 +23,67 @@
#include "mpegaudiodec.c"
#if CONFIG_MP1FLOAT_DECODER
-AVCodec ff_mp1float_decoder =
-{
- "mp1float",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_MP1,
- sizeof(MPADecodeContext),
- decode_init,
- NULL,
- .close = NULL,
- decode_frame,
- CODEC_CAP_PARSE_ONLY,
- .flush= flush,
- .long_name= NULL_IF_CONFIG_SMALL("MP1 (MPEG audio layer 1)"),
+AVCodec ff_mp1float_decoder = {
+ .name = "mp1float",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_MP1,
+ .priv_data_size = sizeof(MPADecodeContext),
+ .init = decode_init,
+ .decode = decode_frame,
+ .capabilities = CODEC_CAP_PARSE_ONLY,
+ .flush = flush,
+ .long_name = NULL_IF_CONFIG_SMALL("MP1 (MPEG audio layer 1)"),
};
#endif
#if CONFIG_MP2FLOAT_DECODER
-AVCodec ff_mp2float_decoder =
-{
- "mp2float",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_MP2,
- sizeof(MPADecodeContext),
- decode_init,
- NULL,
- .close = NULL,
- decode_frame,
- CODEC_CAP_PARSE_ONLY,
- .flush= flush,
- .long_name= NULL_IF_CONFIG_SMALL("MP2 (MPEG audio layer 2)"),
+AVCodec ff_mp2float_decoder = {
+ .name = "mp2float",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_MP2,
+ .priv_data_size = sizeof(MPADecodeContext),
+ .init = decode_init,
+ .decode = decode_frame,
+ .capabilities = CODEC_CAP_PARSE_ONLY,
+ .flush = flush,
+ .long_name = NULL_IF_CONFIG_SMALL("MP2 (MPEG audio layer 2)"),
};
#endif
#if CONFIG_MP3FLOAT_DECODER
-AVCodec ff_mp3float_decoder =
-{
- "mp3float",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_MP3,
- sizeof(MPADecodeContext),
- decode_init,
- NULL,
- .close = NULL,
- decode_frame,
- CODEC_CAP_PARSE_ONLY,
- .flush= flush,
- .long_name= NULL_IF_CONFIG_SMALL("MP3 (MPEG audio layer 3)"),
+AVCodec ff_mp3float_decoder = {
+ .name = "mp3float",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_MP3,
+ .priv_data_size = sizeof(MPADecodeContext),
+ .init = decode_init,
+ .decode = decode_frame,
+ .capabilities = CODEC_CAP_PARSE_ONLY,
+ .flush = flush,
+ .long_name = NULL_IF_CONFIG_SMALL("MP3 (MPEG audio layer 3)"),
};
#endif
#if CONFIG_MP3ADUFLOAT_DECODER
-AVCodec ff_mp3adufloat_decoder =
-{
- "mp3adufloat",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_MP3ADU,
- sizeof(MPADecodeContext),
- decode_init,
- NULL,
- .close = NULL,
- decode_frame_adu,
- CODEC_CAP_PARSE_ONLY,
- .flush= flush,
- .long_name= NULL_IF_CONFIG_SMALL("ADU (Application Data Unit) MP3 (MPEG audio layer 3)"),
+AVCodec ff_mp3adufloat_decoder = {
+ .name = "mp3adufloat",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_MP3ADU,
+ .priv_data_size = sizeof(MPADecodeContext),
+ .init = decode_init,
+ .decode = decode_frame_adu,
+ .capabilities = CODEC_CAP_PARSE_ONLY,
+ .flush = flush,
+ .long_name = NULL_IF_CONFIG_SMALL("ADU (Application Data Unit) MP3 (MPEG audio layer 3)"),
};
#endif
#if CONFIG_MP3ON4FLOAT_DECODER
-AVCodec ff_mp3on4float_decoder =
-{
- "mp3on4float",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_MP3ON4,
- sizeof(MP3On4DecodeContext),
- decode_init_mp3on4,
- NULL,
- decode_close_mp3on4,
- decode_frame_mp3on4,
- .flush= flush,
- .long_name= NULL_IF_CONFIG_SMALL("MP3onMP4"),
+AVCodec ff_mp3on4float_decoder = {
+ .name = "mp3on4float",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_MP3ON4,
+ .priv_data_size = sizeof(MP3On4DecodeContext),
+ .init = decode_init_mp3on4,
+ .close = decode_close_mp3on4,
+ .decode = decode_frame_mp3on4,
+ .flush = flush_mp3on4,
+ .long_name = NULL_IF_CONFIG_SMALL("MP3onMP4"),
};
#endif
diff --git a/libavcodec/mpegaudiodecheader.c b/libavcodec/mpegaudiodecheader.c
index be7abc619d..24919ab544 100644
--- a/libavcodec/mpegaudiodecheader.c
+++ b/libavcodec/mpegaudiodecheader.c
@@ -2,20 +2,20 @@
* MPEG Audio header decoder
* Copyright (c) 2001, 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -31,7 +31,7 @@
#include "mpegaudiodecheader.h"
-int ff_mpegaudio_decode_header(MPADecodeHeader *s, uint32_t header)
+int avpriv_mpegaudio_decode_header(MPADecodeHeader *s, uint32_t header)
{
int sample_rate, frame_size, mpeg25, padding;
int sample_rate_index, bitrate_index;
@@ -46,7 +46,7 @@ int ff_mpegaudio_decode_header(MPADecodeHeader *s, uint32_t header)
s->layer = 4 - ((header >> 17) & 3);
/* extract frequency */
sample_rate_index = (header >> 10) & 3;
- sample_rate = ff_mpa_freq_tab[sample_rate_index] >> (s->lsf + mpeg25);
+ sample_rate = avpriv_mpa_freq_tab[sample_rate_index] >> (s->lsf + mpeg25);
sample_rate_index += 3 * (s->lsf + mpeg25);
s->sample_rate_index = sample_rate_index;
s->error_protection = ((header >> 16) & 1) ^ 1;
@@ -67,7 +67,7 @@ int ff_mpegaudio_decode_header(MPADecodeHeader *s, uint32_t header)
s->nb_channels = 2;
if (bitrate_index != 0) {
- frame_size = ff_mpa_bitrate_tab[s->lsf][s->layer - 1][bitrate_index];
+ frame_size = avpriv_mpa_bitrate_tab[s->lsf][s->layer - 1][bitrate_index];
s->bit_rate = frame_size * 1000;
switch(s->layer) {
case 1:
@@ -109,14 +109,14 @@ int ff_mpegaudio_decode_header(MPADecodeHeader *s, uint32_t header)
return 0;
}
-int ff_mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate, int *channels, int *frame_size, int *bit_rate)
+int avpriv_mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate, int *channels, int *frame_size, int *bit_rate)
{
MPADecodeHeader s1, *s = &s1;
if (ff_mpa_check_header(head) != 0)
return -1;
- if (ff_mpegaudio_decode_header(s, head) != 0) {
+ if (avpriv_mpegaudio_decode_header(s, head) != 0) {
return -1;
}
diff --git a/libavcodec/mpegaudiodecheader.h b/libavcodec/mpegaudiodecheader.h
index 2991595b02..c434d00441 100644
--- a/libavcodec/mpegaudiodecheader.h
+++ b/libavcodec/mpegaudiodecheader.h
@@ -2,20 +2,20 @@
* MPEG Audio header decoder
* Copyright (c) 2001, 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -50,11 +50,11 @@ typedef struct MPADecodeHeader {
/* header decoding. MUST check the header before because no
consistency check is done there. Return 1 if free format found and
that the frame size must be computed externally */
-int ff_mpegaudio_decode_header(MPADecodeHeader *s, uint32_t header);
+int avpriv_mpegaudio_decode_header(MPADecodeHeader *s, uint32_t header);
/* useful helper to get mpeg audio stream infos. Return -1 if error in
header, otherwise the coded frame size in bytes */
-int ff_mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate, int *channels, int *frame_size, int *bitrate);
+int avpriv_mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate, int *channels, int *frame_size, int *bitrate);
/* fast header check for resync */
static inline int ff_mpa_check_header(uint32_t header){
diff --git a/libavcodec/mpegaudiodectab.h b/libavcodec/mpegaudiodectab.h
index 1221657988..accd12b8e2 100644
--- a/libavcodec/mpegaudiodectab.h
+++ b/libavcodec/mpegaudiodectab.h
@@ -2,20 +2,20 @@
* MPEG Audio decoder
* copyright (c) 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/mpegaudiodsp.c b/libavcodec/mpegaudiodsp.c
index 438b097d06..d98d25bb21 100644
--- a/libavcodec/mpegaudiodsp.c
+++ b/libavcodec/mpegaudiodsp.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2011 Mans Rullgard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/mpegaudiodsp_template.c b/libavcodec/mpegaudiodsp_template.c
index 5561c46135..02a34079c8 100644
--- a/libavcodec/mpegaudiodsp_template.c
+++ b/libavcodec/mpegaudiodsp_template.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2001, 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/mpegaudioenc.c b/libavcodec/mpegaudioenc.c
index ef265c905d..6b71d01ae9 100644
--- a/libavcodec/mpegaudioenc.c
+++ b/libavcodec/mpegaudioenc.c
@@ -2,20 +2,20 @@
* The simplest mpeg audio layer 2 encoder
* Copyright (c) 2000, 2001 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -25,6 +25,7 @@
*/
#include "avcodec.h"
+#include "internal.h"
#include "put_bits.h"
#define FRAC_BITS 15 /* fractional bits for sb_samples and dct */
@@ -83,9 +84,9 @@ static av_cold int MPA_encode_init(AVCodecContext *avctx)
/* encoding freq */
s->lsf = 0;
for(i=0;i<3;i++) {
- if (ff_mpa_freq_tab[i] == freq)
+ if (avpriv_mpa_freq_tab[i] == freq)
break;
- if ((ff_mpa_freq_tab[i] / 2) == freq) {
+ if ((avpriv_mpa_freq_tab[i] / 2) == freq) {
s->lsf = 1;
break;
}
@@ -98,7 +99,7 @@ static av_cold int MPA_encode_init(AVCodecContext *avctx)
/* encoding bitrate & frequency */
for(i=0;i<15;i++) {
- if (ff_mpa_bitrate_tab[s->lsf][1][i] == bitrate)
+ if (avpriv_mpa_bitrate_tab[s->lsf][1][i] == bitrate)
break;
}
if (i == 15){
@@ -315,8 +316,6 @@ static void filter(MpegAudioContext *s, int ch, const short *samples, int incr)
int tmp1[32];
int *out;
- // print_pow1(samples, 1152);
-
offset = s->samples_offset[ch];
out = &s->sb_samples[ch][0][0][0];
for(j=0;j<36;j++) {
@@ -360,8 +359,6 @@ static void filter(MpegAudioContext *s, int ch, const short *samples, int incr)
}
}
s->samples_offset[ch] = offset;
-
- // print_pow(s->sb_samples, 1152);
}
static void compute_scale_factors(unsigned char scale_code[SBLIMIT],
@@ -763,16 +760,21 @@ static av_cold int MPA_encode_close(AVCodecContext *avctx)
return 0;
}
+static const AVCodecDefault mp2_defaults[] = {
+ { "b", "128k" },
+ { NULL },
+};
+
AVCodec ff_mp2_encoder = {
- "mp2",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_MP2,
- sizeof(MpegAudioContext),
- MPA_encode_init,
- MPA_encode_frame,
- MPA_encode_close,
- NULL,
+ .name = "mp2",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_MP2,
+ .priv_data_size = sizeof(MpegAudioContext),
+ .init = MPA_encode_init,
+ .encode = MPA_encode_frame,
+ .close = MPA_encode_close,
.sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
.supported_samplerates= (const int[]){44100, 48000, 32000, 22050, 24000, 16000, 0},
.long_name = NULL_IF_CONFIG_SMALL("MP2 (MPEG audio layer 2)"),
+ .defaults = mp2_defaults,
};
diff --git a/libavcodec/mpegaudiotab.h b/libavcodec/mpegaudiotab.h
index 45afe9bd16..35129e646c 100644
--- a/libavcodec/mpegaudiotab.h
+++ b/libavcodec/mpegaudiotab.h
@@ -4,20 +4,20 @@
*
* Copyright (c) 2000, 2001 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index ceed41f230..fffa36a456 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -5,20 +5,20 @@
*
* 4MV & hq & B-frame encoding stuff by Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -122,7 +122,7 @@ const enum PixelFormat ff_hwaccel_pixfmt_list_420[] = {
PIX_FMT_NONE
};
-const uint8_t *ff_find_start_code(const uint8_t * restrict p, const uint8_t *end, uint32_t * restrict state){
+const uint8_t *avpriv_mpv_find_start_code(const uint8_t * restrict p, const uint8_t *end, uint32_t * restrict state){
int i;
assert(p<=end);
@@ -155,6 +155,8 @@ const uint8_t *ff_find_start_code(const uint8_t * restrict p, const uint8_t *end
/* init common dct for both encoder and decoder */
av_cold int ff_dct_common_init(MpegEncContext *s)
{
+ dsputil_init(&s->dsp, s->avctx);
+
s->dct_unquantize_h263_intra = dct_unquantize_h263_intra_c;
s->dct_unquantize_h263_inter = dct_unquantize_h263_inter_c;
s->dct_unquantize_mpeg1_intra = dct_unquantize_mpeg1_intra_c;
@@ -198,7 +200,7 @@ av_cold int ff_dct_common_init(MpegEncContext *s)
void ff_copy_picture(Picture *dst, Picture *src){
*dst = *src;
- dst->type= FF_BUFFER_TYPE_COPY;
+ dst->f.type= FF_BUFFER_TYPE_COPY;
}
/**
@@ -206,8 +208,13 @@ void ff_copy_picture(Picture *dst, Picture *src){
*/
static void free_frame_buffer(MpegEncContext *s, Picture *pic)
{
- ff_thread_release_buffer(s->avctx, (AVFrame*)pic);
- av_freep(&pic->hwaccel_picture_private);
+ /* Windows Media Image codecs allocate internal buffers with different
+ dimensions; ignore user defined callbacks for these */
+ if (s->codec_id != CODEC_ID_WMV3IMAGE && s->codec_id != CODEC_ID_VC1IMAGE)
+ ff_thread_release_buffer(s->avctx, (AVFrame*)pic);
+ else
+ avcodec_default_release_buffer(s->avctx, (AVFrame*)pic);
+ av_freep(&pic->f.hwaccel_picture_private);
}
/**
@@ -218,31 +225,35 @@ static int alloc_frame_buffer(MpegEncContext *s, Picture *pic)
int r;
if (s->avctx->hwaccel) {
- assert(!pic->hwaccel_picture_private);
+ assert(!pic->f.hwaccel_picture_private);
if (s->avctx->hwaccel->priv_data_size) {
- pic->hwaccel_picture_private = av_mallocz(s->avctx->hwaccel->priv_data_size);
- if (!pic->hwaccel_picture_private) {
+ pic->f.hwaccel_picture_private = av_mallocz(s->avctx->hwaccel->priv_data_size);
+ if (!pic->f.hwaccel_picture_private) {
av_log(s->avctx, AV_LOG_ERROR, "alloc_frame_buffer() failed (hwaccel private data allocation)\n");
return -1;
}
}
}
- r = ff_thread_get_buffer(s->avctx, (AVFrame*)pic);
+ if (s->codec_id != CODEC_ID_WMV3IMAGE && s->codec_id != CODEC_ID_VC1IMAGE)
+ r = ff_thread_get_buffer(s->avctx, (AVFrame*)pic);
+ else
+ r = avcodec_default_get_buffer(s->avctx, (AVFrame*)pic);
- if (r<0 || !pic->age || !pic->type || !pic->data[0]) {
- av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed (%d %d %d %p)\n", r, pic->age, pic->type, pic->data[0]);
- av_freep(&pic->hwaccel_picture_private);
+ if (r < 0 || !pic->f.age || !pic->f.type || !pic->f.data[0]) {
+ av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed (%d %d %d %p)\n",
+ r, pic->f.age, pic->f.type, pic->f.data[0]);
+ av_freep(&pic->f.hwaccel_picture_private);
return -1;
}
- if (s->linesize && (s->linesize != pic->linesize[0] || s->uvlinesize != pic->linesize[1])) {
+ if (s->linesize && (s->linesize != pic->f.linesize[0] || s->uvlinesize != pic->f.linesize[1])) {
av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed (stride changed)\n");
free_frame_buffer(s, pic);
return -1;
}
- if (pic->linesize[1] != pic->linesize[2]) {
+ if (pic->f.linesize[1] != pic->f.linesize[2]) {
av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed (uv stride mismatch)\n");
free_frame_buffer(s, pic);
return -1;
@@ -264,60 +275,60 @@ int ff_alloc_picture(MpegEncContext *s, Picture *pic, int shared){
int r= -1;
if(shared){
- assert(pic->data[0]);
- assert(pic->type == 0 || pic->type == FF_BUFFER_TYPE_SHARED);
- pic->type= FF_BUFFER_TYPE_SHARED;
+ assert(pic->f.data[0]);
+ assert(pic->f.type == 0 || pic->f.type == FF_BUFFER_TYPE_SHARED);
+ pic->f.type = FF_BUFFER_TYPE_SHARED;
}else{
- assert(!pic->data[0]);
+ assert(!pic->f.data[0]);
if (alloc_frame_buffer(s, pic) < 0)
return -1;
- s->linesize = pic->linesize[0];
- s->uvlinesize= pic->linesize[1];
+ s->linesize = pic->f.linesize[0];
+ s->uvlinesize = pic->f.linesize[1];
}
- if(pic->qscale_table==NULL){
+ if (pic->f.qscale_table == NULL) {
if (s->encoding) {
FF_ALLOCZ_OR_GOTO(s->avctx, pic->mb_var , mb_array_size * sizeof(int16_t) , fail)
FF_ALLOCZ_OR_GOTO(s->avctx, pic->mc_mb_var, mb_array_size * sizeof(int16_t) , fail)
FF_ALLOCZ_OR_GOTO(s->avctx, pic->mb_mean , mb_array_size * sizeof(int8_t ) , fail)
}
- FF_ALLOCZ_OR_GOTO(s->avctx, pic->mbskip_table , mb_array_size * sizeof(uint8_t)+2, fail) //the +2 is for the slice end check
+ FF_ALLOCZ_OR_GOTO(s->avctx, pic->f.mbskip_table, mb_array_size * sizeof(uint8_t) + 2, fail) //the +2 is for the slice end check
FF_ALLOCZ_OR_GOTO(s->avctx, pic->qscale_table_base , (big_mb_num + s->mb_stride) * sizeof(uint8_t) , fail)
FF_ALLOCZ_OR_GOTO(s->avctx, pic->mb_type_base , (big_mb_num + s->mb_stride) * sizeof(uint32_t), fail)
- pic->mb_type= pic->mb_type_base + 2*s->mb_stride+1;
- pic->qscale_table = pic->qscale_table_base + 2*s->mb_stride + 1;
+ pic->f.mb_type = pic->mb_type_base + 2*s->mb_stride + 1;
+ pic->f.qscale_table = pic->qscale_table_base + 2*s->mb_stride + 1;
if(s->out_format == FMT_H264){
for(i=0; i<2; i++){
FF_ALLOCZ_OR_GOTO(s->avctx, pic->motion_val_base[i], 2 * (b4_array_size+4) * sizeof(int16_t), fail)
- pic->motion_val[i]= pic->motion_val_base[i]+4;
- FF_ALLOCZ_OR_GOTO(s->avctx, pic->ref_index[i], 4*mb_array_size * sizeof(uint8_t), fail)
+ pic->f.motion_val[i] = pic->motion_val_base[i] + 4;
+ FF_ALLOCZ_OR_GOTO(s->avctx, pic->f.ref_index[i], 4*mb_array_size * sizeof(uint8_t), fail)
}
- pic->motion_subsample_log2= 2;
+ pic->f.motion_subsample_log2 = 2;
}else if(s->out_format == FMT_H263 || s->encoding || (s->avctx->debug&FF_DEBUG_MV) || (s->avctx->debug_mv)){
for(i=0; i<2; i++){
FF_ALLOCZ_OR_GOTO(s->avctx, pic->motion_val_base[i], 2 * (b8_array_size+4) * sizeof(int16_t), fail)
- pic->motion_val[i]= pic->motion_val_base[i]+4;
- FF_ALLOCZ_OR_GOTO(s->avctx, pic->ref_index[i], 4*mb_array_size * sizeof(uint8_t), fail)
+ pic->f.motion_val[i] = pic->motion_val_base[i] + 4;
+ FF_ALLOCZ_OR_GOTO(s->avctx, pic->f.ref_index[i], 4*mb_array_size * sizeof(uint8_t), fail)
}
- pic->motion_subsample_log2= 3;
+ pic->f.motion_subsample_log2 = 3;
}
if(s->avctx->debug&FF_DEBUG_DCT_COEFF) {
- FF_ALLOCZ_OR_GOTO(s->avctx, pic->dct_coeff, 64 * mb_array_size * sizeof(DCTELEM)*6, fail)
+ FF_ALLOCZ_OR_GOTO(s->avctx, pic->f.dct_coeff, 64 * mb_array_size * sizeof(DCTELEM) * 6, fail)
}
- pic->qstride= s->mb_stride;
- FF_ALLOCZ_OR_GOTO(s->avctx, pic->pan_scan , 1 * sizeof(AVPanScan), fail)
+ pic->f.qstride = s->mb_stride;
+ FF_ALLOCZ_OR_GOTO(s->avctx, pic->f.pan_scan , 1 * sizeof(AVPanScan), fail)
}
/* It might be nicer if the application would keep track of these
* but it would require an API change. */
memmove(s->prev_pict_types+1, s->prev_pict_types, PREV_PICT_TYPES_BUFFER_SIZE-1);
s->prev_pict_types[0]= s->dropable ? AV_PICTURE_TYPE_B : s->pict_type;
- if(pic->age < PREV_PICT_TYPES_BUFFER_SIZE && s->prev_pict_types[pic->age] == AV_PICTURE_TYPE_B)
- pic->age= INT_MAX; // Skipped MBs in B-frames are quite rare in MPEG-1/2 and it is a bit tricky to skip them anyway.
- pic->owner2 = NULL;
+ if (pic->f.age < PREV_PICT_TYPES_BUFFER_SIZE && s->prev_pict_types[pic->f.age] == AV_PICTURE_TYPE_B)
+ pic->f.age = INT_MAX; // Skipped MBs in B-frames are quite rare in MPEG-1/2 and it is a bit tricky to skip them anyway.
+ pic->owner2 = s;
return 0;
fail: //for the FF_ALLOCZ_OR_GOTO macro
@@ -332,30 +343,30 @@ fail: //for the FF_ALLOCZ_OR_GOTO macro
static void free_picture(MpegEncContext *s, Picture *pic){
int i;
- if(pic->data[0] && pic->type!=FF_BUFFER_TYPE_SHARED){
+ if (pic->f.data[0] && pic->f.type != FF_BUFFER_TYPE_SHARED) {
free_frame_buffer(s, pic);
}
av_freep(&pic->mb_var);
av_freep(&pic->mc_mb_var);
av_freep(&pic->mb_mean);
- av_freep(&pic->mbskip_table);
+ av_freep(&pic->f.mbskip_table);
av_freep(&pic->qscale_table_base);
av_freep(&pic->mb_type_base);
- av_freep(&pic->dct_coeff);
- av_freep(&pic->pan_scan);
- pic->mb_type= NULL;
+ av_freep(&pic->f.dct_coeff);
+ av_freep(&pic->f.pan_scan);
+ pic->f.mb_type = NULL;
for(i=0; i<2; i++){
av_freep(&pic->motion_val_base[i]);
- av_freep(&pic->ref_index[i]);
+ av_freep(&pic->f.ref_index[i]);
}
- if(pic->type == FF_BUFFER_TYPE_SHARED){
+ if (pic->f.type == FF_BUFFER_TYPE_SHARED) {
for(i=0; i<4; i++){
- pic->base[i]=
- pic->data[i]= NULL;
+ pic->f.base[i] =
+ pic->f.data[i] = NULL;
}
- pic->type= 0;
+ pic->f.type = 0;
}
}
@@ -366,8 +377,7 @@ static int init_duplicate_context(MpegEncContext *s, MpegEncContext *base){
int i;
// edge emu needs blocksize + filter length - 1 (=17x17 for halfpel / 21x21 for h264)
- FF_ALLOCZ_OR_GOTO(s->avctx, s->allocated_edge_emu_buffer, (s->width+64)*2*21*2, fail); //(width + edge + align)*interlaced*MBsize*tolerance
- s->edge_emu_buffer= s->allocated_edge_emu_buffer + (s->width+64)*2*21;
+ FF_ALLOCZ_OR_GOTO(s->avctx, s->edge_emu_buffer, (s->width+64)*2*21*2, fail); //(width + edge + align)*interlaced*MBsize*tolerance
//FIXME should be linesize instead of s->width*2 but that is not known before get_buffer()
FF_ALLOCZ_OR_GOTO(s->avctx, s->me.scratchpad, (s->width+64)*4*16*2*sizeof(uint8_t), fail)
@@ -405,7 +415,7 @@ fail:
static void free_duplicate_context(MpegEncContext *s){
if(s==NULL) return;
- av_freep(&s->allocated_edge_emu_buffer); s->edge_emu_buffer= NULL;
+ av_freep(&s->edge_emu_buffer);
av_freep(&s->me.scratchpad);
s->me.temp=
s->rd_scratchpad=
@@ -422,7 +432,6 @@ static void free_duplicate_context(MpegEncContext *s){
static void backup_duplicate_context(MpegEncContext *bak, MpegEncContext *src){
#define COPY(a) bak->a= src->a
- COPY(allocated_edge_emu_buffer);
COPY(edge_emu_buffer);
COPY(me.scratchpad);
COPY(me.temp);
@@ -526,9 +535,9 @@ int ff_mpeg_update_thread_context(AVCodecContext *dst, const AVCodecContext *src
if(!s1->first_field){
s->last_pict_type= s1->pict_type;
- if (s1->current_picture_ptr) s->last_lambda_for[s1->pict_type] = s1->current_picture_ptr->quality;
+ if (s1->current_picture_ptr) s->last_lambda_for[s1->pict_type] = s1->current_picture_ptr->f.quality;
- if(s1->pict_type!=FF_B_TYPE){
+ if (s1->pict_type != AV_PICTURE_TYPE_B) {
s->last_non_b_pict_type= s1->pict_type;
}
}
@@ -575,7 +584,11 @@ void MPV_decode_defaults(MpegEncContext *s){
*/
av_cold int MPV_common_init(MpegEncContext *s)
{
- int y_size, c_size, yc_size, i, mb_array_size, mv_table_size, x, y, threads;
+ int y_size, c_size, yc_size, i, mb_array_size, mv_table_size, x, y,
+ threads = (s->encoding ||
+ (HAVE_THREADS &&
+ s->avctx->active_thread_type & FF_THREAD_SLICE)) ?
+ s->avctx->thread_count : 1;
if(s->codec_id == CODEC_ID_MPEG2VIDEO && !s->progressive_sequence)
s->mb_height = (s->height + 31) / 32 * 2;
@@ -589,98 +602,98 @@ av_cold int MPV_common_init(MpegEncContext *s)
if((s->encoding || (s->avctx->active_thread_type & FF_THREAD_SLICE)) &&
(s->avctx->thread_count > MAX_THREADS || (s->avctx->thread_count > s->mb_height && s->mb_height))){
- av_log(s->avctx, AV_LOG_ERROR, "too many threads\n");
- return -1;
+ int max_threads = FFMIN(MAX_THREADS, s->mb_height);
+ av_log(s->avctx, AV_LOG_WARNING, "too many threads (%d), reducing to %d\n",
+ s->avctx->thread_count, max_threads);
+ threads = max_threads;
}
if((s->width || s->height) && av_image_check_size(s->width, s->height, 0, s->avctx))
return -1;
- dsputil_init(&s->dsp, s->avctx);
ff_dct_common_init(s);
s->flags= s->avctx->flags;
s->flags2= s->avctx->flags2;
- if (s->width && s->height) {
- s->mb_width = (s->width + 15) / 16;
- s->mb_stride = s->mb_width + 1;
- s->b8_stride = s->mb_width*2 + 1;
- s->b4_stride = s->mb_width*4 + 1;
- mb_array_size= s->mb_height * s->mb_stride;
- mv_table_size= (s->mb_height+2) * s->mb_stride + 1;
+ s->mb_width = (s->width + 15) / 16;
+ s->mb_stride = s->mb_width + 1;
+ s->b8_stride = s->mb_width*2 + 1;
+ s->b4_stride = s->mb_width*4 + 1;
+ mb_array_size= s->mb_height * s->mb_stride;
+ mv_table_size= (s->mb_height+2) * s->mb_stride + 1;
- /* set chroma shifts */
- avcodec_get_chroma_sub_sample(s->avctx->pix_fmt,&(s->chroma_x_shift),
- &(s->chroma_y_shift) );
+ /* set chroma shifts */
+ avcodec_get_chroma_sub_sample(s->avctx->pix_fmt,&(s->chroma_x_shift),
+ &(s->chroma_y_shift) );
- /* set default edge pos, will be overriden in decode_header if needed */
- s->h_edge_pos= s->mb_width*16;
- s->v_edge_pos= s->mb_height*16;
+ /* set default edge pos, will be overriden in decode_header if needed */
+ s->h_edge_pos= s->mb_width*16;
+ s->v_edge_pos= s->mb_height*16;
- s->mb_num = s->mb_width * s->mb_height;
+ s->mb_num = s->mb_width * s->mb_height;
- s->block_wrap[0]=
- s->block_wrap[1]=
- s->block_wrap[2]=
- s->block_wrap[3]= s->b8_stride;
- s->block_wrap[4]=
- s->block_wrap[5]= s->mb_stride;
+ s->block_wrap[0]=
+ s->block_wrap[1]=
+ s->block_wrap[2]=
+ s->block_wrap[3]= s->b8_stride;
+ s->block_wrap[4]=
+ s->block_wrap[5]= s->mb_stride;
- y_size = s->b8_stride * (2 * s->mb_height + 1);
- c_size = s->mb_stride * (s->mb_height + 1);
- yc_size = y_size + 2 * c_size;
+ y_size = s->b8_stride * (2 * s->mb_height + 1);
+ c_size = s->mb_stride * (s->mb_height + 1);
+ yc_size = y_size + 2 * c_size;
- /* convert fourcc to upper case */
- s->codec_tag = ff_toupper4(s->avctx->codec_tag);
+ /* convert fourcc to upper case */
+ s->codec_tag = avpriv_toupper4(s->avctx->codec_tag);
+ s->stream_codec_tag = avpriv_toupper4(s->avctx->stream_codec_tag);
- s->stream_codec_tag = ff_toupper4(s->avctx->stream_codec_tag);
+ s->avctx->coded_frame= (AVFrame*)&s->current_picture;
- s->avctx->coded_frame= (AVFrame*)&s->current_picture;
-
- FF_ALLOCZ_OR_GOTO(s->avctx, s->mb_index2xy, (s->mb_num+1)*sizeof(int), fail) //error ressilience code looks cleaner with this
- for(y=0; y<s->mb_height; y++){
- for(x=0; x<s->mb_width; x++){
- s->mb_index2xy[ x + y*s->mb_width ] = x + y*s->mb_stride;
- }
+ FF_ALLOCZ_OR_GOTO(s->avctx, s->mb_index2xy, (s->mb_num+1)*sizeof(int), fail) //error ressilience code looks cleaner with this
+ for(y=0; y<s->mb_height; y++){
+ for(x=0; x<s->mb_width; x++){
+ s->mb_index2xy[ x + y*s->mb_width ] = x + y*s->mb_stride;
}
- s->mb_index2xy[ s->mb_height*s->mb_width ] = (s->mb_height-1)*s->mb_stride + s->mb_width; //FIXME really needed?
-
- if (s->encoding) {
- /* Allocate MV tables */
- FF_ALLOCZ_OR_GOTO(s->avctx, s->p_mv_table_base , mv_table_size * 2 * sizeof(int16_t), fail)
- FF_ALLOCZ_OR_GOTO(s->avctx, s->b_forw_mv_table_base , mv_table_size * 2 * sizeof(int16_t), fail)
- FF_ALLOCZ_OR_GOTO(s->avctx, s->b_back_mv_table_base , mv_table_size * 2 * sizeof(int16_t), fail)
- FF_ALLOCZ_OR_GOTO(s->avctx, s->b_bidir_forw_mv_table_base , mv_table_size * 2 * sizeof(int16_t), fail)
- FF_ALLOCZ_OR_GOTO(s->avctx, s->b_bidir_back_mv_table_base , mv_table_size * 2 * sizeof(int16_t), fail)
- FF_ALLOCZ_OR_GOTO(s->avctx, s->b_direct_mv_table_base , mv_table_size * 2 * sizeof(int16_t), fail)
- s->p_mv_table = s->p_mv_table_base + s->mb_stride + 1;
- s->b_forw_mv_table = s->b_forw_mv_table_base + s->mb_stride + 1;
- s->b_back_mv_table = s->b_back_mv_table_base + s->mb_stride + 1;
- s->b_bidir_forw_mv_table= s->b_bidir_forw_mv_table_base + s->mb_stride + 1;
- s->b_bidir_back_mv_table= s->b_bidir_back_mv_table_base + s->mb_stride + 1;
- s->b_direct_mv_table = s->b_direct_mv_table_base + s->mb_stride + 1;
-
- if(s->msmpeg4_version){
- FF_ALLOCZ_OR_GOTO(s->avctx, s->ac_stats, 2*2*(MAX_LEVEL+1)*(MAX_RUN+1)*2*sizeof(int), fail);
- }
- FF_ALLOCZ_OR_GOTO(s->avctx, s->avctx->stats_out, 256, fail);
-
- /* Allocate MB type table */
- FF_ALLOCZ_OR_GOTO(s->avctx, s->mb_type , mb_array_size * sizeof(uint16_t), fail) //needed for encoding
-
- FF_ALLOCZ_OR_GOTO(s->avctx, s->lambda_table, mb_array_size * sizeof(int), fail)
+ }
+ s->mb_index2xy[ s->mb_height*s->mb_width ] = (s->mb_height-1)*s->mb_stride + s->mb_width; //FIXME really needed?
- FF_ALLOCZ_OR_GOTO(s->avctx, s->q_intra_matrix , 64*32 * sizeof(int), fail)
- FF_ALLOCZ_OR_GOTO(s->avctx, s->q_inter_matrix , 64*32 * sizeof(int), fail)
- FF_ALLOCZ_OR_GOTO(s->avctx, s->q_intra_matrix16, 64*32*2 * sizeof(uint16_t), fail)
- FF_ALLOCZ_OR_GOTO(s->avctx, s->q_inter_matrix16, 64*32*2 * sizeof(uint16_t), fail)
- FF_ALLOCZ_OR_GOTO(s->avctx, s->input_picture, MAX_PICTURE_COUNT * sizeof(Picture*), fail)
- FF_ALLOCZ_OR_GOTO(s->avctx, s->reordered_input_picture, MAX_PICTURE_COUNT * sizeof(Picture*), fail)
+ if (s->encoding) {
+ /* Allocate MV tables */
+ FF_ALLOCZ_OR_GOTO(s->avctx, s->p_mv_table_base , mv_table_size * 2 * sizeof(int16_t), fail)
+ FF_ALLOCZ_OR_GOTO(s->avctx, s->b_forw_mv_table_base , mv_table_size * 2 * sizeof(int16_t), fail)
+ FF_ALLOCZ_OR_GOTO(s->avctx, s->b_back_mv_table_base , mv_table_size * 2 * sizeof(int16_t), fail)
+ FF_ALLOCZ_OR_GOTO(s->avctx, s->b_bidir_forw_mv_table_base , mv_table_size * 2 * sizeof(int16_t), fail)
+ FF_ALLOCZ_OR_GOTO(s->avctx, s->b_bidir_back_mv_table_base , mv_table_size * 2 * sizeof(int16_t), fail)
+ FF_ALLOCZ_OR_GOTO(s->avctx, s->b_direct_mv_table_base , mv_table_size * 2 * sizeof(int16_t), fail)
+ s->p_mv_table = s->p_mv_table_base + s->mb_stride + 1;
+ s->b_forw_mv_table = s->b_forw_mv_table_base + s->mb_stride + 1;
+ s->b_back_mv_table = s->b_back_mv_table_base + s->mb_stride + 1;
+ s->b_bidir_forw_mv_table= s->b_bidir_forw_mv_table_base + s->mb_stride + 1;
+ s->b_bidir_back_mv_table= s->b_bidir_back_mv_table_base + s->mb_stride + 1;
+ s->b_direct_mv_table = s->b_direct_mv_table_base + s->mb_stride + 1;
+
+ if(s->msmpeg4_version){
+ FF_ALLOCZ_OR_GOTO(s->avctx, s->ac_stats, 2*2*(MAX_LEVEL+1)*(MAX_RUN+1)*2*sizeof(int), fail);
+ }
+ FF_ALLOCZ_OR_GOTO(s->avctx, s->avctx->stats_out, 256, fail);
+
+ /* Allocate MB type table */
+ FF_ALLOCZ_OR_GOTO(s->avctx, s->mb_type , mb_array_size * sizeof(uint16_t), fail) //needed for encoding
+
+ FF_ALLOCZ_OR_GOTO(s->avctx, s->lambda_table, mb_array_size * sizeof(int), fail)
+
+ FF_ALLOCZ_OR_GOTO(s->avctx, s->q_intra_matrix , 64*32 * sizeof(int), fail)
+ FF_ALLOCZ_OR_GOTO(s->avctx, s->q_chroma_intra_matrix , 64*32 * sizeof(int), fail)
+ FF_ALLOCZ_OR_GOTO(s->avctx, s->q_inter_matrix , 64*32 * sizeof(int), fail)
+ FF_ALLOCZ_OR_GOTO(s->avctx, s->q_intra_matrix16, 64*32*2 * sizeof(uint16_t), fail)
+ FF_ALLOCZ_OR_GOTO(s->avctx, s->q_chroma_intra_matrix16, 64*32*2 * sizeof(uint16_t), fail)
+ FF_ALLOCZ_OR_GOTO(s->avctx, s->q_inter_matrix16, 64*32*2 * sizeof(uint16_t), fail)
+ FF_ALLOCZ_OR_GOTO(s->avctx, s->input_picture, MAX_PICTURE_COUNT * sizeof(Picture*), fail)
+ FF_ALLOCZ_OR_GOTO(s->avctx, s->reordered_input_picture, MAX_PICTURE_COUNT * sizeof(Picture*), fail)
- if(s->avctx->noise_reduction){
- FF_ALLOCZ_OR_GOTO(s->avctx, s->dct_offset, 2 * 64 * sizeof(uint16_t), fail)
- }
+ if(s->avctx->noise_reduction){
+ FF_ALLOCZ_OR_GOTO(s->avctx, s->dct_offset, 2 * 64 * sizeof(uint16_t), fail)
}
}
@@ -690,11 +703,10 @@ av_cold int MPV_common_init(MpegEncContext *s)
avcodec_get_frame_defaults((AVFrame *)&s->picture[i]);
}
- if (s->width && s->height) {
- FF_ALLOCZ_OR_GOTO(s->avctx, s->error_status_table, mb_array_size*sizeof(uint8_t), fail)
+ FF_ALLOCZ_OR_GOTO(s->avctx, s->error_status_table, mb_array_size*sizeof(uint8_t), fail)
- if(s->codec_id==CODEC_ID_MPEG4 || (s->flags & CODEC_FLAG_INTERLACED_ME)){
- /* interlaced direct mode decoding tables */
+ if(s->codec_id==CODEC_ID_MPEG4 || (s->flags & CODEC_FLAG_INTERLACED_ME)){
+ /* interlaced direct mode decoding tables */
for(i=0; i<2; i++){
int j, k;
for(j=0; j<2; j++){
@@ -708,52 +720,48 @@ av_cold int MPV_common_init(MpegEncContext *s)
}
FF_ALLOCZ_OR_GOTO(s->avctx, s->p_field_select_table[i], mb_array_size * 2 * sizeof(uint8_t), fail)
}
- }
- if (s->out_format == FMT_H263) {
- /* cbp values */
- FF_ALLOCZ_OR_GOTO(s->avctx, s->coded_block_base, y_size, fail);
- s->coded_block= s->coded_block_base + s->b8_stride + 1;
-
- /* cbp, ac_pred, pred_dir */
- FF_ALLOCZ_OR_GOTO(s->avctx, s->cbp_table , mb_array_size * sizeof(uint8_t), fail)
- FF_ALLOCZ_OR_GOTO(s->avctx, s->pred_dir_table, mb_array_size * sizeof(uint8_t), fail)
- }
+ }
+ if (s->out_format == FMT_H263) {
+ /* cbp values */
+ FF_ALLOCZ_OR_GOTO(s->avctx, s->coded_block_base, y_size, fail);
+ s->coded_block= s->coded_block_base + s->b8_stride + 1;
- if (s->h263_pred || s->h263_plus || !s->encoding) {
- /* dc values */
- //MN: we need these for error resilience of intra-frames
- FF_ALLOCZ_OR_GOTO(s->avctx, s->dc_val_base, yc_size * sizeof(int16_t), fail);
- s->dc_val[0] = s->dc_val_base + s->b8_stride + 1;
- s->dc_val[1] = s->dc_val_base + y_size + s->mb_stride + 1;
- s->dc_val[2] = s->dc_val[1] + c_size;
- for(i=0;i<yc_size;i++)
- s->dc_val_base[i] = 1024;
- }
+ /* cbp, ac_pred, pred_dir */
+ FF_ALLOCZ_OR_GOTO(s->avctx, s->cbp_table , mb_array_size * sizeof(uint8_t), fail)
+ FF_ALLOCZ_OR_GOTO(s->avctx, s->pred_dir_table, mb_array_size * sizeof(uint8_t), fail)
+ }
- /* which mb is a intra block */
- FF_ALLOCZ_OR_GOTO(s->avctx, s->mbintra_table, mb_array_size, fail);
- memset(s->mbintra_table, 1, mb_array_size);
+ if (s->h263_pred || s->h263_plus || !s->encoding) {
+ /* dc values */
+ //MN: we need these for error resilience of intra-frames
+ FF_ALLOCZ_OR_GOTO(s->avctx, s->dc_val_base, yc_size * sizeof(int16_t), fail);
+ s->dc_val[0] = s->dc_val_base + s->b8_stride + 1;
+ s->dc_val[1] = s->dc_val_base + y_size + s->mb_stride + 1;
+ s->dc_val[2] = s->dc_val[1] + c_size;
+ for(i=0;i<yc_size;i++)
+ s->dc_val_base[i] = 1024;
+ }
- /* init macroblock skip table */
- FF_ALLOCZ_OR_GOTO(s->avctx, s->mbskip_table, mb_array_size+2, fail);
- //Note the +1 is for a quicker mpeg4 slice_end detection
- FF_ALLOCZ_OR_GOTO(s->avctx, s->prev_pict_types, PREV_PICT_TYPES_BUFFER_SIZE, fail);
+ /* which mb is a intra block */
+ FF_ALLOCZ_OR_GOTO(s->avctx, s->mbintra_table, mb_array_size, fail);
+ memset(s->mbintra_table, 1, mb_array_size);
- s->parse_context.state= -1;
- if((s->avctx->debug&(FF_DEBUG_VIS_QP|FF_DEBUG_VIS_MB_TYPE)) || (s->avctx->debug_mv)){
- s->visualization_buffer[0] = av_malloc((s->mb_width*16 + 2*EDGE_WIDTH) * s->mb_height*16 + 2*EDGE_WIDTH);
- s->visualization_buffer[1] = av_malloc((s->mb_width*16 + 2*EDGE_WIDTH) * s->mb_height*16 + 2*EDGE_WIDTH);
- s->visualization_buffer[2] = av_malloc((s->mb_width*16 + 2*EDGE_WIDTH) * s->mb_height*16 + 2*EDGE_WIDTH);
- }
+ /* init macroblock skip table */
+ FF_ALLOCZ_OR_GOTO(s->avctx, s->mbskip_table, mb_array_size+2, fail);
+ //Note the +1 is for a quicker mpeg4 slice_end detection
+ FF_ALLOCZ_OR_GOTO(s->avctx, s->prev_pict_types, PREV_PICT_TYPES_BUFFER_SIZE, fail);
+
+ s->parse_context.state= -1;
+ if((s->avctx->debug&(FF_DEBUG_VIS_QP|FF_DEBUG_VIS_MB_TYPE)) || (s->avctx->debug_mv)){
+ s->visualization_buffer[0] = av_malloc((s->mb_width*16 + 2*EDGE_WIDTH) * s->mb_height*16 + 2*EDGE_WIDTH);
+ s->visualization_buffer[1] = av_malloc((s->mb_width*16 + 2*EDGE_WIDTH) * s->mb_height*16 + 2*EDGE_WIDTH);
+ s->visualization_buffer[2] = av_malloc((s->mb_width*16 + 2*EDGE_WIDTH) * s->mb_height*16 + 2*EDGE_WIDTH);
}
s->context_initialized = 1;
s->thread_context[0]= s;
- if (s->width && s->height) {
if (s->encoding || (HAVE_THREADS && s->avctx->active_thread_type&FF_THREAD_SLICE)) {
- threads = s->avctx->thread_count;
-
for(i=1; i<threads; i++){
s->thread_context[i]= av_malloc(sizeof(MpegEncContext));
memcpy(s->thread_context[i], s, sizeof(MpegEncContext));
@@ -769,7 +777,7 @@ av_cold int MPV_common_init(MpegEncContext *s)
if(init_duplicate_context(s, s) < 0) goto fail;
s->start_mb_y = 0;
s->end_mb_y = s->mb_height;
- }
+
}
return 0;
@@ -837,6 +845,10 @@ void MPV_common_end(MpegEncContext *s)
av_freep(&s->error_status_table);
av_freep(&s->mb_index2xy);
av_freep(&s->lambda_table);
+ if(s->q_chroma_intra_matrix != s->q_intra_matrix ) av_freep(&s->q_chroma_intra_matrix);
+ if(s->q_chroma_intra_matrix16 != s->q_intra_matrix16) av_freep(&s->q_chroma_intra_matrix16);
+ s->q_chroma_intra_matrix= NULL;
+ s->q_chroma_intra_matrix16= NULL;
av_freep(&s->q_intra_matrix);
av_freep(&s->q_inter_matrix);
av_freep(&s->q_intra_matrix16);
@@ -961,7 +973,7 @@ void ff_release_unused_pictures(MpegEncContext *s, int remove_current)
/* release non reference frames */
for(i=0; i<s->picture_count; i++){
- if(s->picture[i].data[0] && !s->picture[i].reference
+ if (s->picture[i].f.data[0] && !s->picture[i].f.reference
&& (!s->picture[i].owner2 || s->picture[i].owner2 == s)
&& (remove_current || &s->picture[i] != s->current_picture_ptr)
/*&& s->picture[i].type!=FF_BUFFER_TYPE_SHARED*/){
@@ -975,14 +987,17 @@ int ff_find_unused_picture(MpegEncContext *s, int shared){
if(shared){
for(i=s->picture_range_start; i<s->picture_range_end; i++){
- if(s->picture[i].data[0]==NULL && s->picture[i].type==0) return i;
+ if (s->picture[i].f.data[0] == NULL && s->picture[i].f.type == 0)
+ return i;
}
}else{
for(i=s->picture_range_start; i<s->picture_range_end; i++){
- if(s->picture[i].data[0]==NULL && s->picture[i].type!=0) return i; //FIXME
+ if (s->picture[i].f.data[0] == NULL && s->picture[i].f.type != 0)
+ return i; //FIXME
}
for(i=s->picture_range_start; i<s->picture_range_end; i++){
- if(s->picture[i].data[0]==NULL) return i;
+ if (s->picture[i].f.data[0] == NULL)
+ return i;
}
}
@@ -1031,16 +1046,18 @@ int MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx)
assert(s->last_picture_ptr==NULL || s->out_format != FMT_H264 || s->codec_id == CODEC_ID_SVQ3);
/* mark&release old frames */
- if (s->pict_type != AV_PICTURE_TYPE_B && s->last_picture_ptr && s->last_picture_ptr != s->next_picture_ptr && s->last_picture_ptr->data[0]) {
+ if (s->pict_type != AV_PICTURE_TYPE_B && s->last_picture_ptr && s->last_picture_ptr != s->next_picture_ptr && s->last_picture_ptr->f.data[0]) {
if(s->out_format != FMT_H264 || s->codec_id == CODEC_ID_SVQ3){
- free_frame_buffer(s, s->last_picture_ptr);
+ if (s->last_picture_ptr->owner2 == s)
+ free_frame_buffer(s, s->last_picture_ptr);
/* release forgotten pictures */
/* if(mpeg124/h263) */
if(!s->encoding){
for(i=0; i<s->picture_count; i++){
- if(s->picture[i].data[0] && &s->picture[i] != s->next_picture_ptr && s->picture[i].reference){
- av_log(avctx, AV_LOG_ERROR, "releasing zombie picture\n");
+ if (s->picture[i].owner2 == s && s->picture[i].f.data[0] && &s->picture[i] != s->next_picture_ptr && s->picture[i].f.reference) {
+ if (!(avctx->active_thread_type & FF_THREAD_FRAME))
+ av_log(avctx, AV_LOG_ERROR, "releasing zombie picture\n");
free_frame_buffer(s, &s->picture[i]);
}
}
@@ -1051,41 +1068,41 @@ int MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx)
if(!s->encoding){
ff_release_unused_pictures(s, 1);
- if(s->current_picture_ptr && s->current_picture_ptr->data[0]==NULL)
+ if (s->current_picture_ptr && s->current_picture_ptr->f.data[0] == NULL)
pic= s->current_picture_ptr; //we already have a unused image (maybe it was set before reading the header)
else{
i= ff_find_unused_picture(s, 0);
pic= &s->picture[i];
}
- pic->reference= 0;
+ pic->f.reference = 0;
if (!s->dropable){
if (s->codec_id == CODEC_ID_H264)
- pic->reference = s->picture_structure;
+ pic->f.reference = s->picture_structure;
else if (s->pict_type != AV_PICTURE_TYPE_B)
- pic->reference = 3;
+ pic->f.reference = 3;
}
- pic->coded_picture_number= s->coded_picture_number++;
+ pic->f.coded_picture_number = s->coded_picture_number++;
if(ff_alloc_picture(s, pic, 0) < 0)
return -1;
s->current_picture_ptr= pic;
//FIXME use only the vars from current_pic
- s->current_picture_ptr->top_field_first= s->top_field_first;
+ s->current_picture_ptr->f.top_field_first = s->top_field_first;
if(s->codec_id == CODEC_ID_MPEG1VIDEO || s->codec_id == CODEC_ID_MPEG2VIDEO) {
if(s->picture_structure != PICT_FRAME)
- s->current_picture_ptr->top_field_first= (s->picture_structure == PICT_TOP_FIELD) == s->first_field;
+ s->current_picture_ptr->f.top_field_first = (s->picture_structure == PICT_TOP_FIELD) == s->first_field;
}
- s->current_picture_ptr->interlaced_frame= !s->progressive_frame && !s->progressive_sequence;
- s->current_picture_ptr->field_picture= s->picture_structure != PICT_FRAME;
+ s->current_picture_ptr->f.interlaced_frame = !s->progressive_frame && !s->progressive_sequence;
+ s->current_picture_ptr->field_picture = s->picture_structure != PICT_FRAME;
}
- s->current_picture_ptr->pict_type= s->pict_type;
+ s->current_picture_ptr->f.pict_type = s->pict_type;
// if(s->flags && CODEC_FLAG_QSCALE)
// s->current_picture_ptr->quality= s->new_picture_ptr->quality;
- s->current_picture_ptr->key_frame= s->pict_type == AV_PICTURE_TYPE_I;
+ s->current_picture_ptr->f.key_frame = s->pict_type == AV_PICTURE_TYPE_I;
ff_copy_picture(&s->current_picture, s->current_picture_ptr);
@@ -1095,13 +1112,13 @@ int MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx)
s->next_picture_ptr= s->current_picture_ptr;
}
/* av_log(s->avctx, AV_LOG_DEBUG, "L%p N%p C%p L%p N%p C%p type:%d drop:%d\n", s->last_picture_ptr, s->next_picture_ptr,s->current_picture_ptr,
- s->last_picture_ptr ? s->last_picture_ptr->data[0] : NULL,
- s->next_picture_ptr ? s->next_picture_ptr->data[0] : NULL,
- s->current_picture_ptr ? s->current_picture_ptr->data[0] : NULL,
+ s->last_picture_ptr ? s->last_picture_ptr->f.data[0] : NULL,
+ s->next_picture_ptr ? s->next_picture_ptr->f.data[0] : NULL,
+ s->current_picture_ptr ? s->current_picture_ptr->f.data[0] : NULL,
s->pict_type, s->dropable);*/
if(s->codec_id != CODEC_ID_H264){
- if((s->last_picture_ptr==NULL || s->last_picture_ptr->data[0]==NULL) &&
+ if ((s->last_picture_ptr == NULL || s->last_picture_ptr->f.data[0] == NULL) &&
(s->pict_type!=AV_PICTURE_TYPE_I || s->picture_structure != PICT_FRAME)){
if (s->pict_type != AV_PICTURE_TYPE_I)
av_log(avctx, AV_LOG_ERROR, "warning: first frame is no keyframe\n");
@@ -1111,15 +1128,23 @@ int MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx)
/* Allocate a dummy frame */
i= ff_find_unused_picture(s, 0);
s->last_picture_ptr= &s->picture[i];
+ s->last_picture_ptr->f.key_frame = 0;
if(ff_alloc_picture(s, s->last_picture_ptr, 0) < 0)
return -1;
+
+ if(s->codec_id == CODEC_ID_FLV1){
+ for(i=0; i<s->height; i++)
+ memset(s->last_picture_ptr->f.data[0] + s->last_picture_ptr->f.linesize[0]*i, 16, s->width);
+ }
+
ff_thread_report_progress((AVFrame*)s->last_picture_ptr, INT_MAX, 0);
ff_thread_report_progress((AVFrame*)s->last_picture_ptr, INT_MAX, 1);
}
- if((s->next_picture_ptr==NULL || s->next_picture_ptr->data[0]==NULL) && s->pict_type==AV_PICTURE_TYPE_B){
+ if ((s->next_picture_ptr == NULL || s->next_picture_ptr->f.data[0] == NULL) && s->pict_type == AV_PICTURE_TYPE_B) {
/* Allocate a dummy frame */
i= ff_find_unused_picture(s, 0);
s->next_picture_ptr= &s->picture[i];
+ s->next_picture_ptr->f.key_frame = 0;
if(ff_alloc_picture(s, s->next_picture_ptr, 0) < 0)
return -1;
ff_thread_report_progress((AVFrame*)s->next_picture_ptr, INT_MAX, 0);
@@ -1130,17 +1155,17 @@ int MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx)
if(s->last_picture_ptr) ff_copy_picture(&s->last_picture, s->last_picture_ptr);
if(s->next_picture_ptr) ff_copy_picture(&s->next_picture, s->next_picture_ptr);
- assert(s->pict_type == AV_PICTURE_TYPE_I || (s->last_picture_ptr && s->last_picture_ptr->data[0]));
+ assert(s->pict_type == AV_PICTURE_TYPE_I || (s->last_picture_ptr && s->last_picture_ptr->f.data[0]));
if(s->picture_structure!=PICT_FRAME && s->out_format != FMT_H264){
int i;
for(i=0; i<4; i++){
if(s->picture_structure == PICT_BOTTOM_FIELD){
- s->current_picture.data[i] += s->current_picture.linesize[i];
+ s->current_picture.f.data[i] += s->current_picture.f.linesize[i];
}
- s->current_picture.linesize[i] *= 2;
- s->last_picture.linesize[i] *=2;
- s->next_picture.linesize[i] *=2;
+ s->current_picture.f.linesize[i] *= 2;
+ s->last_picture.f.linesize[i] *= 2;
+ s->next_picture.f.linesize[i] *= 2;
}
}
@@ -1179,22 +1204,22 @@ void MPV_frame_end(MpegEncContext *s)
//just to make sure that all data is rendered.
if(CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration){
ff_xvmc_field_end(s);
- }else if((s->error_count || s->encoding)
+ }else if((s->error_count || s->encoding || !(s->avctx->codec->capabilities&CODEC_CAP_DRAW_HORIZ_BAND))
&& !s->avctx->hwaccel
&& !(s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU)
&& s->unrestricted_mv
- && s->current_picture.reference
+ && s->current_picture.f.reference
&& !s->intra_only
&& !(s->flags&CODEC_FLAG_EMU_EDGE)) {
int hshift = av_pix_fmt_descriptors[s->avctx->pix_fmt].log2_chroma_w;
int vshift = av_pix_fmt_descriptors[s->avctx->pix_fmt].log2_chroma_h;
- s->dsp.draw_edges(s->current_picture.data[0], s->linesize ,
+ s->dsp.draw_edges(s->current_picture.f.data[0], s->linesize,
s->h_edge_pos , s->v_edge_pos,
EDGE_WIDTH , EDGE_WIDTH , EDGE_TOP | EDGE_BOTTOM);
- s->dsp.draw_edges(s->current_picture.data[1], s->uvlinesize,
+ s->dsp.draw_edges(s->current_picture.f.data[1], s->uvlinesize,
s->h_edge_pos>>hshift, s->v_edge_pos>>vshift,
EDGE_WIDTH>>hshift, EDGE_WIDTH>>vshift, EDGE_TOP | EDGE_BOTTOM);
- s->dsp.draw_edges(s->current_picture.data[2], s->uvlinesize,
+ s->dsp.draw_edges(s->current_picture.f.data[2], s->uvlinesize,
s->h_edge_pos>>hshift, s->v_edge_pos>>vshift,
EDGE_WIDTH>>hshift, EDGE_WIDTH>>vshift, EDGE_TOP | EDGE_BOTTOM);
}
@@ -1202,14 +1227,14 @@ void MPV_frame_end(MpegEncContext *s)
emms_c();
s->last_pict_type = s->pict_type;
- s->last_lambda_for[s->pict_type]= s->current_picture_ptr->quality;
+ s->last_lambda_for[s->pict_type] = s->current_picture_ptr->f.quality;
if(s->pict_type!=AV_PICTURE_TYPE_B){
s->last_non_b_pict_type= s->pict_type;
}
#if 0
/* copy back current_picture variables */
for(i=0; i<MAX_PICTURE_COUNT; i++){
- if(s->picture[i].data[0] == s->current_picture.data[0]){
+ if(s->picture[i].f.data[0] == s->current_picture.f.data[0]){
s->picture[i]= s->current_picture;
break;
}
@@ -1220,7 +1245,7 @@ void MPV_frame_end(MpegEncContext *s)
if(s->encoding){
/* release non-reference frames */
for(i=0; i<s->picture_count; i++){
- if(s->picture[i].data[0] && !s->picture[i].reference /*&& s->picture[i].type!=FF_BUFFER_TYPE_SHARED*/){
+ if (s->picture[i].f.data[0] && !s->picture[i].f.reference /*&& s->picture[i].type != FF_BUFFER_TYPE_SHARED*/) {
free_frame_buffer(s, &s->picture[i]);
}
}
@@ -1233,7 +1258,7 @@ void MPV_frame_end(MpegEncContext *s)
#endif
s->avctx->coded_frame= (AVFrame*)s->current_picture_ptr;
- if (s->codec_id != CODEC_ID_H264 && s->current_picture.reference) {
+ if (s->codec_id != CODEC_ID_H264 && s->current_picture.f.reference) {
ff_thread_report_progress((AVFrame*)s->current_picture_ptr, s->mb_height-1, 0);
}
}
@@ -1330,15 +1355,8 @@ void ff_print_debug_info(MpegEncContext *s, AVFrame *pict){
if(s->avctx->debug&(FF_DEBUG_SKIP | FF_DEBUG_QP | FF_DEBUG_MB_TYPE)){
int x,y;
- av_log(s->avctx,AV_LOG_DEBUG,"New frame, type: ");
- switch (pict->pict_type) {
- case AV_PICTURE_TYPE_I: av_log(s->avctx,AV_LOG_DEBUG,"I\n"); break;
- case AV_PICTURE_TYPE_P: av_log(s->avctx,AV_LOG_DEBUG,"P\n"); break;
- case AV_PICTURE_TYPE_B: av_log(s->avctx,AV_LOG_DEBUG,"B\n"); break;
- case AV_PICTURE_TYPE_S: av_log(s->avctx,AV_LOG_DEBUG,"S\n"); break;
- case AV_PICTURE_TYPE_SI: av_log(s->avctx,AV_LOG_DEBUG,"SI\n"); break;
- case AV_PICTURE_TYPE_SP: av_log(s->avctx,AV_LOG_DEBUG,"SP\n"); break;
- }
+ av_log(s->avctx, AV_LOG_DEBUG, "New frame, type: %c\n",
+ av_get_picture_type_char(pict->pict_type));
for(y=0; y<s->mb_height; y++){
for(x=0; x<s->mb_width; x++){
if(s->avctx->debug&FF_DEBUG_SKIP){
@@ -1421,6 +1439,7 @@ void ff_print_debug_info(MpegEncContext *s, AVFrame *pict){
pict->data[i]= s->visualization_buffer[i];
}
pict->type= FF_BUFFER_TYPE_COPY;
+ pict->opaque= NULL;
ptr= pict->data[0];
block_height = 16>>v_chroma_shift;
@@ -1635,13 +1654,13 @@ static av_always_inline void mpeg_motion_lowres(MpegEncContext *s,
uint8_t *ptr_y, *ptr_cb, *ptr_cr;
int mx, my, src_x, src_y, uvsrc_x, uvsrc_y, uvlinesize, linesize, sx, sy, uvsx, uvsy;
const int lowres= s->avctx->lowres;
- const int op_index= FFMIN(lowres, 2);
+ const int op_index= FFMIN(lowres-1+s->chroma_x_shift, 2);
const int block_s= 8>>lowres;
const int s_mask= (2<<lowres)-1;
const int h_edge_pos = s->h_edge_pos >> lowres;
const int v_edge_pos = s->v_edge_pos >> lowres;
- linesize = s->current_picture.linesize[0] << field_based;
- uvlinesize = s->current_picture.linesize[1] << field_based;
+ linesize = s->current_picture.f.linesize[0] << field_based;
+ uvlinesize = s->current_picture.f.linesize[1] << field_based;
if(s->quarter_sample){ //FIXME obviously not perfect but qpel will not work in lowres anyway
motion_x/=2;
@@ -1670,12 +1689,29 @@ static av_always_inline void mpeg_motion_lowres(MpegEncContext *s,
uvsrc_x = s->mb_x*block_s + (mx >> lowres);
uvsrc_y = mb_y*block_s + (my >> lowres);
} else {
- mx = motion_x / 2;
- my = motion_y / 2;
- uvsx = mx & s_mask;
- uvsy = my & s_mask;
- uvsrc_x = s->mb_x*block_s + (mx >> (lowres+1));
- uvsrc_y =( mb_y*block_s>>field_based) + (my >> (lowres+1));
+ if(s->chroma_y_shift){
+ mx = motion_x / 2;
+ my = motion_y / 2;
+ uvsx = mx & s_mask;
+ uvsy = my & s_mask;
+ uvsrc_x = s->mb_x*block_s + (mx >> (lowres+1));
+ uvsrc_y =( mb_y*block_s>>field_based) + (my >> (lowres+1));
+ } else {
+ if(s->chroma_x_shift){
+ //Chroma422
+ mx = motion_x / 2;
+ uvsx = mx & s_mask;
+ uvsy = motion_y & s_mask;
+ uvsrc_y = src_y;
+ uvsrc_x = s->mb_x*block_s + (mx >> (lowres+1));
+ } else {
+ //Chroma444
+ uvsx = motion_x & s_mask;
+ uvsy = motion_y & s_mask;
+ uvsrc_x = src_x;
+ uvsrc_y = src_y;
+ }
+ }
}
ptr_y = ref_picture[0] + src_y * linesize + src_x;
@@ -1698,7 +1734,7 @@ static av_always_inline void mpeg_motion_lowres(MpegEncContext *s,
}
}
- if(bottom_field){ //FIXME use this for field pix too instead of the obnoxious hack which changes picture.data
+ if(bottom_field){ //FIXME use this for field pix too instead of the obnoxious hack which changes picture.f.data
dest_y += s->linesize;
dest_cb+= s->uvlinesize;
dest_cr+= s->uvlinesize;
@@ -1717,8 +1753,10 @@ static av_always_inline void mpeg_motion_lowres(MpegEncContext *s,
if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
uvsx= (uvsx << 2) >> lowres;
uvsy= (uvsy << 2) >> lowres;
- pix_op[op_index](dest_cb, ptr_cb, uvlinesize, h >> s->chroma_y_shift, uvsx, uvsy);
- pix_op[op_index](dest_cr, ptr_cr, uvlinesize, h >> s->chroma_y_shift, uvsx, uvsy);
+ if(h >> s->chroma_y_shift){
+ pix_op[op_index](dest_cb, ptr_cb, uvlinesize, h >> s->chroma_y_shift, uvsx, uvsy);
+ pix_op[op_index](dest_cr, ptr_cr, uvlinesize, h >> s->chroma_y_shift, uvsx, uvsy);
+ }
}
//FIXME h261 lowres loop filter
}
@@ -1838,7 +1876,7 @@ static inline void MPV_motion_lowres(MpegEncContext *s,
s->mv[dir][1][0], s->mv[dir][1][1], block_s, mb_y);
} else {
if(s->picture_structure != s->field_select[dir][0] + 1 && s->pict_type != AV_PICTURE_TYPE_B && !s->first_field){
- ref_picture= s->current_picture_ptr->data;
+ ref_picture = s->current_picture_ptr->f.data;
}
mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr,
@@ -1854,7 +1892,7 @@ static inline void MPV_motion_lowres(MpegEncContext *s,
if(s->picture_structure == s->field_select[dir][i] + 1 || s->pict_type == AV_PICTURE_TYPE_B || s->first_field){
ref2picture= ref_picture;
}else{
- ref2picture= s->current_picture_ptr->data;
+ ref2picture = s->current_picture_ptr->f.data;
}
mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr,
@@ -1891,7 +1929,7 @@ static inline void MPV_motion_lowres(MpegEncContext *s,
//opposite parity is always in the same frame if this is second field
if(!s->first_field){
- ref_picture = s->current_picture_ptr->data;
+ ref_picture = s->current_picture_ptr->f.data;
}
}
}
@@ -2020,7 +2058,7 @@ void MPV_decode_mb_internal(MpegEncContext *s, DCTELEM block[12][64],
if(s->avctx->debug&FF_DEBUG_DCT_COEFF) {
/* save DCT coefficients */
int i,j;
- DCTELEM *dct = &s->current_picture.dct_coeff[mb_xy*64*6];
+ DCTELEM *dct = &s->current_picture.f.dct_coeff[mb_xy * 64 * 6];
av_log(s->avctx, AV_LOG_DEBUG, "DCT coeffs of MB at %dx%d:\n", s->mb_x, s->mb_y);
for(i=0; i<6; i++){
for(j=0; j<64; j++){
@@ -2031,7 +2069,7 @@ void MPV_decode_mb_internal(MpegEncContext *s, DCTELEM block[12][64],
}
}
- s->current_picture.qscale_table[mb_xy]= s->qscale;
+ s->current_picture.f.qscale_table[mb_xy] = s->qscale;
/* update DC predictors for P macroblocks */
if (!s->mb_intra) {
@@ -2052,8 +2090,8 @@ void MPV_decode_mb_internal(MpegEncContext *s, DCTELEM block[12][64],
int dct_linesize, dct_offset;
op_pixels_func (*op_pix)[4];
qpel_mc_func (*op_qpix)[16];
- const int linesize= s->current_picture.linesize[0]; //not s->linesize as this would be wrong for field pics
- const int uvlinesize= s->current_picture.linesize[1];
+ const int linesize = s->current_picture.f.linesize[0]; //not s->linesize as this would be wrong for field pics
+ const int uvlinesize = s->current_picture.f.linesize[1];
const int readable= s->pict_type != AV_PICTURE_TYPE_B || s->encoding || s->avctx->draw_horiz_band || lowres_flag;
const int block_size= lowres_flag ? 8>>s->avctx->lowres : 8;
@@ -2061,7 +2099,7 @@ void MPV_decode_mb_internal(MpegEncContext *s, DCTELEM block[12][64],
/* skip only during decoding as we might trash the buffers during encoding a bit */
if(!s->encoding){
uint8_t *mbskip_ptr = &s->mbskip_table[mb_xy];
- const int age= s->current_picture.age;
+ const int age = s->current_picture.f.age;
assert(age);
@@ -2073,10 +2111,10 @@ void MPV_decode_mb_internal(MpegEncContext *s, DCTELEM block[12][64],
if(*mbskip_ptr >99) *mbskip_ptr= 99;
/* if previous was skipped too, then nothing to do ! */
- if (*mbskip_ptr >= age && s->current_picture.reference){
+ if (*mbskip_ptr >= age && s->current_picture.f.reference){
return;
}
- } else if(!s->current_picture.reference){
+ } else if(!s->current_picture.f.reference) {
(*mbskip_ptr) ++; /* increase counter so the age can be compared cleanly */
if(*mbskip_ptr >99) *mbskip_ptr= 99;
} else{
@@ -2102,7 +2140,7 @@ void MPV_decode_mb_internal(MpegEncContext *s, DCTELEM block[12][64],
/* decoding or more than one mb_type (MC was already done otherwise) */
if(!s->encoding){
- if(HAVE_PTHREADS && s->avctx->active_thread_type&FF_THREAD_FRAME) {
+ if(HAVE_THREADS && s->avctx->active_thread_type&FF_THREAD_FRAME) {
if (s->mv_dir & MV_DIR_FORWARD) {
ff_thread_await_progress((AVFrame*)s->last_picture_ptr, MPV_lowest_referenced_row(s, 0), 0);
}
@@ -2115,11 +2153,11 @@ void MPV_decode_mb_internal(MpegEncContext *s, DCTELEM block[12][64],
h264_chroma_mc_func *op_pix = s->dsp.put_h264_chroma_pixels_tab;
if (s->mv_dir & MV_DIR_FORWARD) {
- MPV_motion_lowres(s, dest_y, dest_cb, dest_cr, 0, s->last_picture.data, op_pix);
+ MPV_motion_lowres(s, dest_y, dest_cb, dest_cr, 0, s->last_picture.f.data, op_pix);
op_pix = s->dsp.avg_h264_chroma_pixels_tab;
}
if (s->mv_dir & MV_DIR_BACKWARD) {
- MPV_motion_lowres(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.data, op_pix);
+ MPV_motion_lowres(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.f.data, op_pix);
}
}else{
op_qpix= s->me.qpel_put;
@@ -2129,12 +2167,12 @@ void MPV_decode_mb_internal(MpegEncContext *s, DCTELEM block[12][64],
op_pix = s->dsp.put_no_rnd_pixels_tab;
}
if (s->mv_dir & MV_DIR_FORWARD) {
- MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture.data, op_pix, op_qpix);
+ MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture.f.data, op_pix, op_qpix);
op_pix = s->dsp.avg_pixels_tab;
op_qpix= s->me.qpel_avg;
}
if (s->mv_dir & MV_DIR_BACKWARD) {
- MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.data, op_pix, op_qpix);
+ MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.f.data, op_pix, op_qpix);
}
}
}
@@ -2181,17 +2219,17 @@ void MPV_decode_mb_internal(MpegEncContext *s, DCTELEM block[12][64],
}else{
//chroma422
dct_linesize = uvlinesize << s->interlaced_dct;
- dct_offset =(s->interlaced_dct)? uvlinesize : uvlinesize*8;
+ dct_offset =(s->interlaced_dct)? uvlinesize : uvlinesize*block_size;
add_dct(s, block[4], 4, dest_cb, dct_linesize);
add_dct(s, block[5], 5, dest_cr, dct_linesize);
add_dct(s, block[6], 6, dest_cb+dct_offset, dct_linesize);
add_dct(s, block[7], 7, dest_cr+dct_offset, dct_linesize);
if(!s->chroma_x_shift){//Chroma444
- add_dct(s, block[8], 8, dest_cb+8, dct_linesize);
- add_dct(s, block[9], 9, dest_cr+8, dct_linesize);
- add_dct(s, block[10], 10, dest_cb+8+dct_offset, dct_linesize);
- add_dct(s, block[11], 11, dest_cr+8+dct_offset, dct_linesize);
+ add_dct(s, block[8], 8, dest_cb+block_size, dct_linesize);
+ add_dct(s, block[9], 9, dest_cr+block_size, dct_linesize);
+ add_dct(s, block[10], 10, dest_cb+block_size+dct_offset, dct_linesize);
+ add_dct(s, block[11], 11, dest_cr+block_size+dct_offset, dct_linesize);
}
}
}//fi gray
@@ -2233,17 +2271,17 @@ void MPV_decode_mb_internal(MpegEncContext *s, DCTELEM block[12][64],
}else{
dct_linesize = uvlinesize << s->interlaced_dct;
- dct_offset =(s->interlaced_dct)? uvlinesize : uvlinesize*8;
+ dct_offset =(s->interlaced_dct)? uvlinesize : uvlinesize*block_size;
s->dsp.idct_put(dest_cb, dct_linesize, block[4]);
s->dsp.idct_put(dest_cr, dct_linesize, block[5]);
s->dsp.idct_put(dest_cb + dct_offset, dct_linesize, block[6]);
s->dsp.idct_put(dest_cr + dct_offset, dct_linesize, block[7]);
if(!s->chroma_x_shift){//Chroma444
- s->dsp.idct_put(dest_cb + 8, dct_linesize, block[8]);
- s->dsp.idct_put(dest_cr + 8, dct_linesize, block[9]);
- s->dsp.idct_put(dest_cb + 8 + dct_offset, dct_linesize, block[10]);
- s->dsp.idct_put(dest_cr + 8 + dct_offset, dct_linesize, block[11]);
+ s->dsp.idct_put(dest_cb + block_size, dct_linesize, block[8]);
+ s->dsp.idct_put(dest_cr + block_size, dct_linesize, block[9]);
+ s->dsp.idct_put(dest_cb + block_size + dct_offset, dct_linesize, block[10]);
+ s->dsp.idct_put(dest_cr + block_size + dct_offset, dct_linesize, block[11]);
}
}
}//gray
@@ -2283,7 +2321,7 @@ void ff_draw_horiz_band(MpegEncContext *s, int y, int h){
if (!s->avctx->hwaccel
&& !(s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU)
&& s->unrestricted_mv
- && s->current_picture.reference
+ && s->current_picture.f.reference
&& !s->intra_only
&& !(s->flags&CODEC_FLAG_EMU_EDGE)) {
int sides = 0, edge_h;
@@ -2294,12 +2332,15 @@ void ff_draw_horiz_band(MpegEncContext *s, int y, int h){
edge_h= FFMIN(h, s->v_edge_pos - y);
- s->dsp.draw_edges(s->current_picture_ptr->data[0] + y *s->linesize , s->linesize,
- s->h_edge_pos , edge_h , EDGE_WIDTH , EDGE_WIDTH , sides);
- s->dsp.draw_edges(s->current_picture_ptr->data[1] + (y>>vshift)*s->uvlinesize, s->uvlinesize,
- s->h_edge_pos>>hshift, edge_h>>hshift, EDGE_WIDTH>>hshift, EDGE_WIDTH>>vshift, sides);
- s->dsp.draw_edges(s->current_picture_ptr->data[2] + (y>>vshift)*s->uvlinesize, s->uvlinesize,
- s->h_edge_pos>>hshift, edge_h>>hshift, EDGE_WIDTH>>hshift, EDGE_WIDTH>>vshift, sides);
+ s->dsp.draw_edges(s->current_picture_ptr->f.data[0] + y *s->linesize,
+ s->linesize, s->h_edge_pos, edge_h,
+ EDGE_WIDTH, EDGE_WIDTH, sides);
+ s->dsp.draw_edges(s->current_picture_ptr->f.data[1] + (y>>vshift)*s->uvlinesize,
+ s->uvlinesize, s->h_edge_pos>>hshift, edge_h>>vshift,
+ EDGE_WIDTH>>hshift, EDGE_WIDTH>>vshift, sides);
+ s->dsp.draw_edges(s->current_picture_ptr->f.data[2] + (y>>vshift)*s->uvlinesize,
+ s->uvlinesize, s->h_edge_pos>>hshift, edge_h>>vshift,
+ EDGE_WIDTH>>hshift, EDGE_WIDTH>>vshift, sides);
}
h= FFMIN(h, s->avctx->height - y);
@@ -2337,8 +2378,8 @@ void ff_draw_horiz_band(MpegEncContext *s, int y, int h){
}
void ff_init_block_index(MpegEncContext *s){ //FIXME maybe rename
- const int linesize= s->current_picture.linesize[0]; //not s->linesize as this would be wrong for field pics
- const int uvlinesize= s->current_picture.linesize[1];
+ const int linesize = s->current_picture.f.linesize[0]; //not s->linesize as this would be wrong for field pics
+ const int uvlinesize = s->current_picture.f.linesize[1];
const int mb_size= 4 - s->avctx->lowres;
s->block_index[0]= s->b8_stride*(s->mb_y*2 ) - 2 + s->mb_x*2;
@@ -2349,9 +2390,9 @@ void ff_init_block_index(MpegEncContext *s){ //FIXME maybe rename
s->block_index[5]= s->mb_stride*(s->mb_y + s->mb_height + 2) + s->b8_stride*s->mb_height*2 + s->mb_x - 1;
//block_index is not used by mpeg2, so it is not affected by chroma_format
- s->dest[0] = s->current_picture.data[0] + ((s->mb_x - 1) << mb_size);
- s->dest[1] = s->current_picture.data[1] + ((s->mb_x - 1) << (mb_size - s->chroma_x_shift));
- s->dest[2] = s->current_picture.data[2] + ((s->mb_x - 1) << (mb_size - s->chroma_x_shift));
+ s->dest[0] = s->current_picture.f.data[0] + ((s->mb_x - 1) << mb_size);
+ s->dest[1] = s->current_picture.f.data[1] + ((s->mb_x - 1) << (mb_size - s->chroma_x_shift));
+ s->dest[2] = s->current_picture.f.data[2] + ((s->mb_x - 1) << (mb_size - s->chroma_x_shift));
if(!(s->pict_type==AV_PICTURE_TYPE_B && s->avctx->draw_horiz_band && s->picture_structure==PICT_FRAME))
{
@@ -2376,8 +2417,9 @@ void ff_mpeg_flush(AVCodecContext *avctx){
return;
for(i=0; i<s->picture_count; i++){
- if(s->picture[i].data[0] && ( s->picture[i].type == FF_BUFFER_TYPE_INTERNAL
- || s->picture[i].type == FF_BUFFER_TYPE_USER))
+ if (s->picture[i].f.data[0] &&
+ (s->picture[i].f.type == FF_BUFFER_TYPE_INTERNAL ||
+ s->picture[i].f.type == FF_BUFFER_TYPE_USER))
free_frame_buffer(s, &s->picture[i]);
}
s->current_picture_ptr = s->last_picture_ptr = s->next_picture_ptr = NULL;
@@ -2632,6 +2674,6 @@ void ff_set_qscale(MpegEncContext * s, int qscale)
void MPV_report_decode_progress(MpegEncContext *s)
{
- if (s->pict_type != FF_B_TYPE && !s->partitioned_frame && !s->error_occurred)
+ if (s->pict_type != AV_PICTURE_TYPE_B && !s->partitioned_frame && !s->error_occurred)
ff_thread_report_progress((AVFrame*)s->current_picture_ptr, s->mb_y, 0);
}
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index d309fcb83b..d97212c358 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -3,20 +3,20 @@
* Copyright (c) 2000, 2001, 2002 Fabrice Bellard
* Copyright (c) 2002-2004 Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -28,6 +28,7 @@
#ifndef AVCODEC_MPEGVIDEO_H
#define AVCODEC_MPEGVIDEO_H
+#include "avcodec.h"
#include "dsputil.h"
#include "get_bits.h"
#include "put_bits.h"
@@ -35,6 +36,7 @@
#include "parser.h"
#include "mpeg12data.h"
#include "rl.h"
+#include "timecode.h"
#define FRAME_SKIPPED 100 ///< return value for header parsers if frame is not coded
@@ -82,7 +84,7 @@ struct MpegEncContext;
* Picture.
*/
typedef struct Picture{
- FF_COMMON_FRAME
+ struct AVFrame f;
/**
* halfpel luma planes.
@@ -123,10 +125,11 @@ typedef struct Picture{
int pic_id; /**< h264 pic_num (short -> no wrap version of pic_num,
pic_num & max_pic_num; long -> long_pic_num) */
int long_ref; ///< 1->long term reference 0->short term reference
- int ref_poc[2][2][16]; ///< h264 POCs of the frames used as reference (FIXME need per slice)
+ int ref_poc[2][2][32]; ///< h264 POCs of the frames/fields used as reference (FIXME need per slice)
int ref_count[2][2]; ///< number of entries in ref_poc (FIXME need per slice)
int mbaff; ///< h264 1 -> MBAFF frame 0-> not MBAFF
int field_picture; ///< whether or not the picture was encoded in seperate fields
+ int sync; ///< has been decoded after a keyframe
int mb_var_sum; ///< sum of MB variance for current frame
int mc_mb_var_sum; ///< motion compensated MB variance for current frame
@@ -153,7 +156,7 @@ typedef struct MotionEstContext{
int best_bits;
uint32_t *map; ///< map to avoid duplicate evaluations
uint32_t *score_map; ///< map to store the scores
- int map_generation;
+ unsigned map_generation;
int pre_penalty_factor;
int penalty_factor; /**< an estimate of the bits required to
code a given mv value, e.g. (1,0) takes
@@ -198,6 +201,7 @@ typedef struct MotionEstContext{
* MpegEncContext.
*/
typedef struct MpegEncContext {
+ AVClass *class;
struct AVCodecContext *avctx;
/* the following parameters must be initialized before encoding */
int width, height;///< picture size. must be a multiple of 16
@@ -233,7 +237,6 @@ typedef struct MpegEncContext {
int picture_number; //FIXME remove, unclear definition
int picture_in_gop_number; ///< 0-> first pic in gop, ...
int b_frames_since_non_b; ///< used for encoding, relative to not yet reordered input
- int64_t user_specified_pts;///< last non zero pts from AVFrame which was passed into avcodec_encode_video()
int mb_width, mb_height; ///< number of MBs horizontally & vertically
int mb_stride; ///< mb_width+1 used for some arrays to allow simple addressing of left & top MBs without sig11
int b8_stride; ///< 2*mb_width+1 used for some 8x8 block arrays to allow simple addressing
@@ -260,6 +263,8 @@ typedef struct MpegEncContext {
/* WARNING: changes above this line require updates to hardcoded
* offsets used in asm. */
+ int64_t user_specified_pts;///< last non zero pts from AVFrame which was passed into avcodec_encode_video()
+
/** bit output */
PutBitContext pb;
@@ -296,7 +301,7 @@ typedef struct MpegEncContext {
Picture *current_picture_ptr; ///< pointer to the current picture
int picture_count; ///< number of allocated pictures (MAX_PICTURE_COUNT * avctx->thread_count)
int picture_range_start, picture_range_end; ///< the part of picture that this context can allocate in
- uint8_t *visualization_buffer[3]; //< temporary buffer vor MV visualization
+ uint8_t *visualization_buffer[3]; ///< temporary buffer vor MV visualization
int last_dc[3]; ///< last DC values for MPEG1
int16_t *dc_val_base;
int16_t *dc_val[3]; ///< used for mpeg4 DC prediction, all 3 arrays must be continuous
@@ -316,8 +321,7 @@ typedef struct MpegEncContext {
uint8_t *mbintra_table; ///< used to avoid setting {ac, dc, cbp}-pred stuff to zero on inter MB decoding
uint8_t *cbp_table; ///< used to store cbp, ac_pred for partitioned decoding
uint8_t *pred_dir_table; ///< used to store pred_dir for partitioned decoding
- uint8_t *allocated_edge_emu_buffer;
- uint8_t *edge_emu_buffer; ///< points into the middle of allocated_edge_emu_buffer
+ uint8_t *edge_emu_buffer; ///< temporary buffer for if MVs point to out-of-frame data
uint8_t *rd_scratchpad; ///< scratchpad for rate distortion mb decision
uint8_t *obmc_scratchpad;
uint8_t *b_scratchpad; ///< scratchpad used for writing into write only buffers
@@ -443,9 +447,11 @@ typedef struct MpegEncContext {
/** precomputed matrix (combine qscale and DCT renorm) */
int (*q_intra_matrix)[64];
+ int (*q_chroma_intra_matrix)[64];
int (*q_inter_matrix)[64];
/** identical to the above but for MMX & these are not permutated, second 64 entries are bias*/
uint16_t (*q_intra_matrix16)[2][64];
+ uint16_t (*q_chroma_intra_matrix16)[2][64];
uint16_t (*q_inter_matrix16)[2][64];
/* noise reduction */
@@ -641,10 +647,14 @@ typedef struct MpegEncContext {
int interlaced_dct;
int first_slice;
int first_field; ///< is 1 for the first field of a field picture 0 otherwise
+ int drop_frame_timecode; ///< timecode is in drop frame format.
+ int scan_offset; ///< reserve space for SVCD scan offset user data.
/* RTP specific */
int rtp_mode;
+ struct ff_timecode tc;
+
uint8_t *ptr_lastgob;
int swap_uv; //vcr2 codec is an MPEG-2 variant with U and V swapped
DCTELEM (*pblocks[12])[64];
@@ -715,7 +725,7 @@ void ff_update_duplicate_context(MpegEncContext *dst, MpegEncContext *src);
int MPV_lowest_referenced_row(MpegEncContext *s, int dir);
void MPV_report_decode_progress(MpegEncContext *s);
int ff_mpeg_update_thread_context(AVCodecContext *dst, const AVCodecContext *src);
-const uint8_t *ff_find_start_code(const uint8_t *p, const uint8_t *end, uint32_t *state);
+const uint8_t *avpriv_mpv_find_start_code(const uint8_t *p, const uint8_t *end, uint32_t *state);
void ff_set_qscale(MpegEncContext * s, int qscale);
void ff_er_frame_start(MpegEncContext *s);
diff --git a/libavcodec/mpegvideo_common.h b/libavcodec/mpegvideo_common.h
index d0093ce8d2..a4d0167f36 100644
--- a/libavcodec/mpegvideo_common.h
+++ b/libavcodec/mpegvideo_common.h
@@ -5,20 +5,20 @@
*
* 4MV & hq & B-frame encoding stuff by Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -255,8 +255,8 @@ if(s->quarter_sample)
#endif
v_edge_pos = s->v_edge_pos >> field_based;
- linesize = s->current_picture.linesize[0] << field_based;
- uvlinesize = s->current_picture.linesize[1] << field_based;
+ linesize = s->current_picture.f.linesize[0] << field_based;
+ uvlinesize = s->current_picture.f.linesize[1] << field_based;
dxy = ((motion_y & 1) << 1) | (motion_x & 1);
src_x = s->mb_x* 16 + (motion_x >> 1);
@@ -657,30 +657,30 @@ static av_always_inline void MPV_motion_internal(MpegEncContext *s,
assert(!s->mb_skipped);
- memcpy(mv_cache[1][1], s->current_picture.motion_val[0][mot_xy ], sizeof(int16_t)*4);
- memcpy(mv_cache[2][1], s->current_picture.motion_val[0][mot_xy+mot_stride], sizeof(int16_t)*4);
- memcpy(mv_cache[3][1], s->current_picture.motion_val[0][mot_xy+mot_stride], sizeof(int16_t)*4);
+ memcpy(mv_cache[1][1], s->current_picture.f.motion_val[0][mot_xy ], sizeof(int16_t) * 4);
+ memcpy(mv_cache[2][1], s->current_picture.f.motion_val[0][mot_xy + mot_stride], sizeof(int16_t) * 4);
+ memcpy(mv_cache[3][1], s->current_picture.f.motion_val[0][mot_xy + mot_stride], sizeof(int16_t) * 4);
- if(mb_y==0 || IS_INTRA(s->current_picture.mb_type[xy-s->mb_stride])){
+ if (mb_y == 0 || IS_INTRA(s->current_picture.f.mb_type[xy - s->mb_stride])) {
memcpy(mv_cache[0][1], mv_cache[1][1], sizeof(int16_t)*4);
}else{
- memcpy(mv_cache[0][1], s->current_picture.motion_val[0][mot_xy-mot_stride], sizeof(int16_t)*4);
+ memcpy(mv_cache[0][1], s->current_picture.f.motion_val[0][mot_xy - mot_stride], sizeof(int16_t) * 4);
}
- if(mb_x==0 || IS_INTRA(s->current_picture.mb_type[xy-1])){
+ if (mb_x == 0 || IS_INTRA(s->current_picture.f.mb_type[xy - 1])) {
AV_COPY32(mv_cache[1][0], mv_cache[1][1]);
AV_COPY32(mv_cache[2][0], mv_cache[2][1]);
}else{
- AV_COPY32(mv_cache[1][0], s->current_picture.motion_val[0][mot_xy-1]);
- AV_COPY32(mv_cache[2][0], s->current_picture.motion_val[0][mot_xy-1+mot_stride]);
+ AV_COPY32(mv_cache[1][0], s->current_picture.f.motion_val[0][mot_xy - 1]);
+ AV_COPY32(mv_cache[2][0], s->current_picture.f.motion_val[0][mot_xy - 1 + mot_stride]);
}
- if(mb_x+1>=s->mb_width || IS_INTRA(s->current_picture.mb_type[xy+1])){
+ if (mb_x + 1 >= s->mb_width || IS_INTRA(s->current_picture.f.mb_type[xy + 1])) {
AV_COPY32(mv_cache[1][3], mv_cache[1][2]);
AV_COPY32(mv_cache[2][3], mv_cache[2][2]);
}else{
- AV_COPY32(mv_cache[1][3], s->current_picture.motion_val[0][mot_xy+2]);
- AV_COPY32(mv_cache[2][3], s->current_picture.motion_val[0][mot_xy+2+mot_stride]);
+ AV_COPY32(mv_cache[1][3], s->current_picture.f.motion_val[0][mot_xy + 2]);
+ AV_COPY32(mv_cache[2][3], s->current_picture.f.motion_val[0][mot_xy + 2 + mot_stride]);
}
mx = 0;
@@ -817,7 +817,7 @@ static av_always_inline void MPV_motion_internal(MpegEncContext *s,
}
} else {
if(s->picture_structure != s->field_select[dir][0] + 1 && s->pict_type != AV_PICTURE_TYPE_B && !s->first_field){
- ref_picture= s->current_picture_ptr->data;
+ ref_picture = s->current_picture_ptr->f.data;
}
mpeg_motion(s, dest_y, dest_cb, dest_cr,
@@ -834,7 +834,7 @@ static av_always_inline void MPV_motion_internal(MpegEncContext *s,
|| s->pict_type == AV_PICTURE_TYPE_B || s->first_field){
ref2picture= ref_picture;
}else{
- ref2picture= s->current_picture_ptr->data;
+ ref2picture = s->current_picture_ptr->f.data;
}
mpeg_motion(s, dest_y, dest_cb, dest_cr,
@@ -871,7 +871,7 @@ static av_always_inline void MPV_motion_internal(MpegEncContext *s,
//opposite parity is always in the same frame if this is second field
if(!s->first_field){
- ref_picture = s->current_picture_ptr->data;
+ ref_picture = s->current_picture_ptr->f.data;
}
}
}
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 73bcc5b229..7195e200e4 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -5,20 +5,20 @@
*
* 4MV & hq & B-frame encoding stuff by Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -29,6 +29,7 @@
#include "libavutil/intmath.h"
#include "libavutil/mathematics.h"
+#include "libavutil/opt.h"
#include "avcodec.h"
#include "dsputil.h"
#include "mpegvideo.h"
@@ -43,6 +44,7 @@
#include "mpeg4video.h"
#include "internal.h"
#include <limits.h>
+#include "sp5x.h"
//#undef NDEBUG
//#include <assert.h>
@@ -69,7 +71,8 @@ void ff_convert_matrix(DSPContext *dsp, int (*qmat)[64], uint16_t (*qmat16)[2][6
for(qscale=qmin; qscale<=qmax; qscale++){
int i;
- if (dsp->fdct == ff_jpeg_fdct_islow
+ if (dsp->fdct == ff_jpeg_fdct_islow_8 ||
+ dsp->fdct == ff_jpeg_fdct_islow_10
#ifdef FAAN_POSTSCALE
|| dsp->fdct == ff_faandct
#endif
@@ -158,7 +161,7 @@ void ff_write_quant_matrix(PutBitContext *pb, uint16_t *matrix){
* init s->current_picture.qscale_table from s->lambda_table
*/
void ff_init_qscale_tab(MpegEncContext *s){
- int8_t * const qscale_table= s->current_picture.qscale_table;
+ int8_t * const qscale_table = s->current_picture.f.qscale_table;
int i;
for(i=0; i<s->mb_num; i++){
@@ -263,6 +266,7 @@ av_cold int MPV_encode_init(AVCodecContext *avctx)
}
break;
case CODEC_ID_MJPEG:
+ case CODEC_ID_AMV:
if(avctx->pix_fmt != PIX_FMT_YUVJ420P && avctx->pix_fmt != PIX_FMT_YUVJ422P &&
((avctx->pix_fmt != PIX_FMT_YUV420P && avctx->pix_fmt != PIX_FMT_YUV422P) || avctx->strict_std_compliance>FF_COMPLIANCE_UNOFFICIAL)){
av_log(avctx, AV_LOG_ERROR, "colorspace not supported in jpeg\n");
@@ -304,7 +308,10 @@ av_cold int MPV_encode_init(AVCodecContext *avctx)
s->luma_elim_threshold = avctx->luma_elim_threshold;
s->chroma_elim_threshold= avctx->chroma_elim_threshold;
s->strict_std_compliance= avctx->strict_std_compliance;
- s->data_partitioning= avctx->flags & CODEC_FLAG_PART;
+#if FF_API_MPEGVIDEO_GLOBAL_OPTS
+ if (avctx->flags & CODEC_FLAG_PART)
+ s->data_partitioning = 1;
+#endif
s->quarter_sample= (avctx->flags & CODEC_FLAG_QPEL)!=0;
s->mpeg_quant= avctx->mpeg_quant;
s->rtp_mode= !!avctx->rtp_payload_size;
@@ -332,11 +339,13 @@ av_cold int MPV_encode_init(AVCodecContext *avctx)
|| (s->flags&CODEC_FLAG_QP_RD))
&& !s->fixed_qscale;
- s->obmc= !!(s->flags & CODEC_FLAG_OBMC);
s->loop_filter= !!(s->flags & CODEC_FLAG_LOOP_FILTER);
+#if FF_API_MPEGVIDEO_GLOBAL_OPTS
s->alternate_scan= !!(s->flags & CODEC_FLAG_ALT_SCAN);
s->intra_vlc_format= !!(s->flags2 & CODEC_FLAG2_INTRA_VLC);
s->q_scale_type= !!(s->flags2 & CODEC_FLAG2_NON_LINEAR_QUANT);
+ s->obmc= !!(s->flags & CODEC_FLAG_OBMC);
+#endif
if(avctx->rc_max_rate && !avctx->rc_buffer_size){
av_log(avctx, AV_LOG_ERROR, "a vbv buffer size is needed, for encoding with a maximum bitrate\n");
@@ -353,7 +362,7 @@ av_cold int MPV_encode_init(AVCodecContext *avctx)
}
if(avctx->rc_max_rate && avctx->rc_max_rate < avctx->bit_rate){
- av_log(avctx, AV_LOG_INFO, "bitrate above max bitrate\n");
+ av_log(avctx, AV_LOG_ERROR, "bitrate above max bitrate\n");
return -1;
}
@@ -389,20 +398,24 @@ av_cold int MPV_encode_init(AVCodecContext *avctx)
return -1;
}
+#if FF_API_MPEGVIDEO_GLOBAL_OPTS
if(s->obmc && s->codec_id != CODEC_ID_H263 && s->codec_id != CODEC_ID_H263P){
av_log(avctx, AV_LOG_ERROR, "OBMC is only supported with H263(+)\n");
return -1;
}
+#endif
if(s->quarter_sample && s->codec_id != CODEC_ID_MPEG4){
av_log(avctx, AV_LOG_ERROR, "qpel not supported by codec\n");
return -1;
}
+#if FF_API_MPEGVIDEO_GLOBAL_OPTS
if(s->data_partitioning && s->codec_id != CODEC_ID_MPEG4){
av_log(avctx, AV_LOG_ERROR, "data partitioning not supported by codec\n");
return -1;
}
+#endif
if(s->max_b_frames && s->codec_id != CODEC_ID_MPEG4 && s->codec_id != CODEC_ID_MPEG1VIDEO && s->codec_id != CODEC_ID_MPEG2VIDEO){
av_log(avctx, AV_LOG_ERROR, "b frames not supported by codec\n");
@@ -412,9 +425,10 @@ av_cold int MPV_encode_init(AVCodecContext *avctx)
if ((s->codec_id == CODEC_ID_MPEG4 || s->codec_id == CODEC_ID_H263 ||
s->codec_id == CODEC_ID_H263P) &&
(avctx->sample_aspect_ratio.num > 255 || avctx->sample_aspect_ratio.den > 255)) {
- av_log(avctx, AV_LOG_ERROR, "Invalid pixel aspect ratio %i/%i, limit is 255/255\n",
+ av_log(avctx, AV_LOG_WARNING, "Invalid pixel aspect ratio %i/%i, limit is 255/255 reducing\n",
avctx->sample_aspect_ratio.num, avctx->sample_aspect_ratio.den);
- return -1;
+ av_reduce(&avctx->sample_aspect_ratio.num, &avctx->sample_aspect_ratio.den,
+ avctx->sample_aspect_ratio.num, avctx->sample_aspect_ratio.den, 255);
}
if((s->flags & (CODEC_FLAG_INTERLACED_DCT|CODEC_FLAG_INTERLACED_ME|CODEC_FLAG_ALT_SCAN))
@@ -460,10 +474,12 @@ av_cold int MPV_encode_init(AVCodecContext *avctx)
}
if(s->q_scale_type == 1){
+#if FF_API_MPEGVIDEO_GLOBAL_OPTS
if(s->codec_id != CODEC_ID_MPEG2VIDEO){
av_log(avctx, AV_LOG_ERROR, "non linear quant is only available for mpeg2\n");
return -1;
}
+#endif
if(avctx->qmax > 12){
av_log(avctx, AV_LOG_ERROR, "non linear quant only supports qmax <= 12 currently\n");
return -1;
@@ -513,7 +529,7 @@ av_cold int MPV_encode_init(AVCodecContext *avctx)
// return -1;
}
- if(s->mpeg_quant || s->codec_id==CODEC_ID_MPEG1VIDEO || s->codec_id==CODEC_ID_MPEG2VIDEO || s->codec_id==CODEC_ID_MJPEG){
+ if(s->mpeg_quant || s->codec_id==CODEC_ID_MPEG1VIDEO || s->codec_id==CODEC_ID_MPEG2VIDEO || s->codec_id==CODEC_ID_MJPEG || s->codec_id==CODEC_ID_AMV){
s->intra_quant_bias= 3<<(QUANT_BIAS_SHIFT-3); //(a + x*3/8)/x
s->inter_quant_bias= 0;
}else{
@@ -526,6 +542,8 @@ av_cold int MPV_encode_init(AVCodecContext *avctx)
if(avctx->inter_quant_bias != FF_DEFAULT_QUANT_BIAS)
s->inter_quant_bias= avctx->inter_quant_bias;
+ av_log(avctx, AV_LOG_DEBUG, "intra_quant_bias = %d inter_quant_bias = %d\n",s->intra_quant_bias,s->inter_quant_bias);
+
avcodec_get_chroma_sub_sample(avctx->pix_fmt, &chroma_h_shift, &chroma_v_shift);
if(avctx->codec_id == CODEC_ID_MPEG4 && s->avctx->time_base.den > (1<<16)-1){
@@ -550,6 +568,7 @@ av_cold int MPV_encode_init(AVCodecContext *avctx)
break;
case CODEC_ID_LJPEG:
case CODEC_ID_MJPEG:
+ case CODEC_ID_AMV:
s->out_format = FMT_MJPEG;
s->intra_only = 1; /* force intra only for jpeg */
if(avctx->codec->id == CODEC_ID_LJPEG && avctx->pix_fmt == PIX_FMT_BGRA){
@@ -583,11 +602,10 @@ av_cold int MPV_encode_init(AVCodecContext *avctx)
case CODEC_ID_H263:
if (!CONFIG_H263_ENCODER) return -1;
if (ff_match_2uint16(h263_format, FF_ARRAY_ELEMS(h263_format), s->width, s->height) == 8) {
- av_log(avctx, AV_LOG_INFO, "The specified picture size of %dx%d is not valid for the H.263 codec.\nValid sizes are 128x96, 176x144, 352x288, 704x576, and 1408x1152. Try H.263+.\n", s->width, s->height);
+ av_log(avctx, AV_LOG_ERROR, "The specified picture size of %dx%d is not valid for the H.263 codec.\nValid sizes are 128x96, 176x144, 352x288, 704x576, and 1408x1152. Try H.263+.\n", s->width, s->height);
return -1;
}
s->out_format = FMT_H263;
- s->obmc= (avctx->flags & CODEC_FLAG_OBMC) ? 1:0;
avctx->delay=0;
s->low_delay=1;
break;
@@ -595,14 +613,18 @@ av_cold int MPV_encode_init(AVCodecContext *avctx)
s->out_format = FMT_H263;
s->h263_plus = 1;
/* Fx */
- s->umvplus = (avctx->flags & CODEC_FLAG_H263P_UMV) ? 1:0;
+#if FF_API_MPEGVIDEO_GLOBAL_OPTS
+ if (avctx->flags & CODEC_FLAG_H263P_UMV)
+ s->umvplus = 1;
+ if (avctx->flags & CODEC_FLAG_H263P_AIV)
+ s->alt_inter_vlc = 1;
+ if (avctx->flags & CODEC_FLAG_H263P_SLICE_STRUCT)
+ s->h263_slice_structured = 1;
+#endif
s->h263_aic= (avctx->flags & CODEC_FLAG_AC_PRED) ? 1:0;
s->modified_quant= s->h263_aic;
- s->alt_inter_vlc= (avctx->flags & CODEC_FLAG_H263P_AIV) ? 1:0;
- s->obmc= (avctx->flags & CODEC_FLAG_OBMC) ? 1:0;
s->loop_filter= (avctx->flags & CODEC_FLAG_LOOP_FILTER) ? 1:0;
s->unrestricted_mv= s->obmc || s->loop_filter || s->umvplus;
- s->h263_slice_structured= (s->flags & CODEC_FLAG_H263P_SLICE_STRUCT) ? 1:0;
/* /Fx */
/* These are just to be sure */
@@ -915,12 +937,12 @@ static int skip_check(MpegEncContext *s, Picture *p, Picture *ref){
int64_t score64=0;
for(plane=0; plane<3; plane++){
- const int stride= p->linesize[plane];
+ const int stride = p->f.linesize[plane];
const int bw= plane ? 1 : 2;
for(y=0; y<s->mb_height*bw; y++){
for(x=0; x<s->mb_width*bw; x++){
- int off= p->type == FF_BUFFER_TYPE_SHARED ? 0: 16;
- int v= s->dsp.frame_skip_cmp[1](s, p->data[plane] + 8*(x + y*stride)+off, ref->data[plane] + 8*(x + y*stride), stride, 8);
+ int off = p->f.type == FF_BUFFER_TYPE_SHARED ? 0: 16;
+ int v = s->dsp.frame_skip_cmp[1](s, p->f.data[plane] + 8*(x + y*stride)+off, ref->f.data[plane] + 8*(x + y*stride), stride, 8);
switch(s->avctx->frame_skip_exp){
case 0: score= FFMAX(score, v); break;
@@ -944,7 +966,7 @@ static int skip_check(MpegEncContext *s, Picture *p, Picture *ref){
static int estimate_best_b_count(MpegEncContext *s){
AVCodec *codec= avcodec_find_encoder(s->avctx->codec_id);
- AVCodecContext *c= avcodec_alloc_context();
+ AVCodecContext *c = avcodec_alloc_context3(NULL);
AVFrame input[FF_MAX_B_FRAMES+2];
const int scale= s->avctx->brd_scale;
int i, j, out_size, p_lambda, b_lambda, lambda2;
@@ -973,7 +995,7 @@ static int estimate_best_b_count(MpegEncContext *s){
c->time_base= s->avctx->time_base;
c->max_b_frames= s->max_b_frames;
- if (avcodec_open(c, codec) < 0)
+ if (avcodec_open2(c, codec, NULL) < 0)
return -1;
for(i=0; i<s->max_b_frames+2; i++){
@@ -992,15 +1014,15 @@ static int estimate_best_b_count(MpegEncContext *s){
if(pre_input_ptr && (!i || s->input_picture[i-1])) {
pre_input= *pre_input_ptr;
- if(pre_input.type != FF_BUFFER_TYPE_SHARED && i) {
- pre_input.data[0]+=INPLACE_OFFSET;
- pre_input.data[1]+=INPLACE_OFFSET;
- pre_input.data[2]+=INPLACE_OFFSET;
+ if (pre_input.f.type != FF_BUFFER_TYPE_SHARED && i) {
+ pre_input.f.data[0] += INPLACE_OFFSET;
+ pre_input.f.data[1] += INPLACE_OFFSET;
+ pre_input.f.data[2] += INPLACE_OFFSET;
}
- s->dsp.shrink[scale](input[i].data[0], input[i].linesize[0], pre_input.data[0], pre_input.linesize[0], c->width, c->height);
- s->dsp.shrink[scale](input[i].data[1], input[i].linesize[1], pre_input.data[1], pre_input.linesize[1], c->width>>1, c->height>>1);
- s->dsp.shrink[scale](input[i].data[2], input[i].linesize[2], pre_input.data[2], pre_input.linesize[2], c->width>>1, c->height>>1);
+ s->dsp.shrink[scale](input[i].data[0], input[i].linesize[0], pre_input.f.data[0], pre_input.f.linesize[0], c->width, c->height);
+ s->dsp.shrink[scale](input[i].data[1], input[i].linesize[1], pre_input.f.data[1], pre_input.f.linesize[1], c->width >> 1, c->height >> 1);
+ s->dsp.shrink[scale](input[i].data[2], input[i].linesize[2], pre_input.f.data[2], pre_input.f.linesize[2], c->width >> 1, c->height >> 1);
}
}
@@ -1062,23 +1084,23 @@ static int select_input_picture(MpegEncContext *s){
if(s->reordered_input_picture[0]==NULL && s->input_picture[0]){
if(/*s->picture_in_gop_number >= s->gop_size ||*/ s->next_picture_ptr==NULL || s->intra_only){
s->reordered_input_picture[0]= s->input_picture[0];
- s->reordered_input_picture[0]->pict_type= AV_PICTURE_TYPE_I;
- s->reordered_input_picture[0]->coded_picture_number= s->coded_picture_number++;
+ s->reordered_input_picture[0]->f.pict_type = AV_PICTURE_TYPE_I;
+ s->reordered_input_picture[0]->f.coded_picture_number = s->coded_picture_number++;
}else{
int b_frames;
if(s->avctx->frame_skip_threshold || s->avctx->frame_skip_factor){
if(s->picture_in_gop_number < s->gop_size && skip_check(s, s->input_picture[0], s->next_picture_ptr)){
//FIXME check that te gop check above is +-1 correct
-//av_log(NULL, AV_LOG_DEBUG, "skip %p %"PRId64"\n", s->input_picture[0]->data[0], s->input_picture[0]->pts);
+//av_log(NULL, AV_LOG_DEBUG, "skip %p %"PRId64"\n", s->input_picture[0]->f.data[0], s->input_picture[0]->pts);
- if(s->input_picture[0]->type == FF_BUFFER_TYPE_SHARED){
+ if (s->input_picture[0]->f.type == FF_BUFFER_TYPE_SHARED) {
for(i=0; i<4; i++)
- s->input_picture[0]->data[i]= NULL;
- s->input_picture[0]->type= 0;
+ s->input_picture[0]->f.data[i] = NULL;
+ s->input_picture[0]->f.type = 0;
}else{
- assert( s->input_picture[0]->type==FF_BUFFER_TYPE_USER
- || s->input_picture[0]->type==FF_BUFFER_TYPE_INTERNAL);
+ assert( s->input_picture[0]->f.type == FF_BUFFER_TYPE_USER
+ || s->input_picture[0]->f.type == FF_BUFFER_TYPE_INTERNAL);
s->avctx->release_buffer(s->avctx, (AVFrame*)s->input_picture[0]);
}
@@ -1092,7 +1114,7 @@ static int select_input_picture(MpegEncContext *s){
if(s->flags&CODEC_FLAG_PASS2){
for(i=0; i<s->max_b_frames+1; i++){
- int pict_num= s->input_picture[0]->display_picture_number + i;
+ int pict_num = s->input_picture[0]->f.display_picture_number + i;
if(pict_num >= s->rc_context.num_entries)
break;
@@ -1101,7 +1123,7 @@ static int select_input_picture(MpegEncContext *s){
break;
}
- s->input_picture[i]->pict_type=
+ s->input_picture[i]->f.pict_type =
s->rc_context.entry[pict_num].new_pict_type;
}
}
@@ -1113,8 +1135,8 @@ static int select_input_picture(MpegEncContext *s){
for(i=1; i<s->max_b_frames+1; i++){
if(s->input_picture[i] && s->input_picture[i]->b_frame_score==0){
s->input_picture[i]->b_frame_score=
- get_intra_count(s, s->input_picture[i ]->data[0],
- s->input_picture[i-1]->data[0], s->linesize) + 1;
+ get_intra_count(s, s->input_picture[i ]->f.data[0],
+ s->input_picture[i-1]->f.data[0], s->linesize) + 1;
}
}
for(i=0; i<s->max_b_frames+1; i++){
@@ -1140,11 +1162,11 @@ static int select_input_picture(MpegEncContext *s){
//av_log(s->avctx, AV_LOG_DEBUG, "b_frames: %d\n", b_count);
for(i= b_frames - 1; i>=0; i--){
- int type= s->input_picture[i]->pict_type;
+ int type = s->input_picture[i]->f.pict_type;
if(type && type != AV_PICTURE_TYPE_B)
b_frames= i;
}
- if(s->input_picture[b_frames]->pict_type == AV_PICTURE_TYPE_B && b_frames == s->max_b_frames){
+ if (s->input_picture[b_frames]->f.pict_type == AV_PICTURE_TYPE_B && b_frames == s->max_b_frames){
av_log(s->avctx, AV_LOG_ERROR, "warning, too many b frames in a row\n");
}
@@ -1154,49 +1176,49 @@ static int select_input_picture(MpegEncContext *s){
}else{
if(s->flags & CODEC_FLAG_CLOSED_GOP)
b_frames=0;
- s->input_picture[b_frames]->pict_type= AV_PICTURE_TYPE_I;
+ s->input_picture[b_frames]->f.pict_type = AV_PICTURE_TYPE_I;
}
}
if( (s->flags & CODEC_FLAG_CLOSED_GOP)
&& b_frames
- && s->input_picture[b_frames]->pict_type== AV_PICTURE_TYPE_I)
+ && s->input_picture[b_frames]->f.pict_type== AV_PICTURE_TYPE_I)
b_frames--;
s->reordered_input_picture[0]= s->input_picture[b_frames];
- if(s->reordered_input_picture[0]->pict_type != AV_PICTURE_TYPE_I)
- s->reordered_input_picture[0]->pict_type= AV_PICTURE_TYPE_P;
- s->reordered_input_picture[0]->coded_picture_number= s->coded_picture_number++;
+ if (s->reordered_input_picture[0]->f.pict_type != AV_PICTURE_TYPE_I)
+ s->reordered_input_picture[0]->f.pict_type = AV_PICTURE_TYPE_P;
+ s->reordered_input_picture[0]->f.coded_picture_number = s->coded_picture_number++;
for(i=0; i<b_frames; i++){
- s->reordered_input_picture[i+1]= s->input_picture[i];
- s->reordered_input_picture[i+1]->pict_type= AV_PICTURE_TYPE_B;
- s->reordered_input_picture[i+1]->coded_picture_number= s->coded_picture_number++;
+ s->reordered_input_picture[i + 1] = s->input_picture[i];
+ s->reordered_input_picture[i + 1]->f.pict_type = AV_PICTURE_TYPE_B;
+ s->reordered_input_picture[i + 1]->f.coded_picture_number = s->coded_picture_number++;
}
}
}
no_output_pic:
if(s->reordered_input_picture[0]){
- s->reordered_input_picture[0]->reference= s->reordered_input_picture[0]->pict_type!=AV_PICTURE_TYPE_B ? 3 : 0;
+ s->reordered_input_picture[0]->f.reference = s->reordered_input_picture[0]->f.pict_type!=AV_PICTURE_TYPE_B ? 3 : 0;
ff_copy_picture(&s->new_picture, s->reordered_input_picture[0]);
- if(s->reordered_input_picture[0]->type == FF_BUFFER_TYPE_SHARED || s->avctx->rc_buffer_size){
+ if (s->reordered_input_picture[0]->f.type == FF_BUFFER_TYPE_SHARED || s->avctx->rc_buffer_size) {
// input is a shared pix, so we can't modifiy it -> alloc a new one & ensure that the shared one is reuseable
int i= ff_find_unused_picture(s, 0);
Picture *pic= &s->picture[i];
- pic->reference = s->reordered_input_picture[0]->reference;
+ pic->f.reference = s->reordered_input_picture[0]->f.reference;
if(ff_alloc_picture(s, pic, 0) < 0){
return -1;
}
/* mark us unused / free shared pic */
- if(s->reordered_input_picture[0]->type == FF_BUFFER_TYPE_INTERNAL)
+ if (s->reordered_input_picture[0]->f.type == FF_BUFFER_TYPE_INTERNAL)
s->avctx->release_buffer(s->avctx, (AVFrame*)s->reordered_input_picture[0]);
for(i=0; i<4; i++)
- s->reordered_input_picture[0]->data[i]= NULL;
- s->reordered_input_picture[0]->type= 0;
+ s->reordered_input_picture[0]->f.data[i] = NULL;
+ s->reordered_input_picture[0]->f.type = 0;
copy_picture_attributes(s, (AVFrame*)pic, (AVFrame*)s->reordered_input_picture[0]);
@@ -1204,17 +1226,17 @@ no_output_pic:
}else{
// input is not a shared pix -> reuse buffer for current_pix
- assert( s->reordered_input_picture[0]->type==FF_BUFFER_TYPE_USER
- || s->reordered_input_picture[0]->type==FF_BUFFER_TYPE_INTERNAL);
+ assert( s->reordered_input_picture[0]->f.type == FF_BUFFER_TYPE_USER
+ || s->reordered_input_picture[0]->f.type == FF_BUFFER_TYPE_INTERNAL);
s->current_picture_ptr= s->reordered_input_picture[0];
for(i=0; i<4; i++){
- s->new_picture.data[i]+= INPLACE_OFFSET;
+ s->new_picture.f.data[i] += INPLACE_OFFSET;
}
}
ff_copy_picture(&s->current_picture, s->current_picture_ptr);
- s->picture_number= s->new_picture.display_picture_number;
+ s->picture_number = s->new_picture.f.display_picture_number;
//printf("dpn:%d\n", s->picture_number);
}else{
memset(&s->new_picture, 0, sizeof(Picture));
@@ -1249,8 +1271,8 @@ int MPV_encode_picture(AVCodecContext *avctx,
}
/* output? */
- if(s->new_picture.data[0]){
- s->pict_type= s->new_picture.pict_type;
+ if (s->new_picture.f.data[0]) {
+ s->pict_type = s->new_picture.f.pict_type;
//emms_c();
//printf("qs:%f %f %d\n", s->new_picture.quality, s->current_picture.quality, s->qscale);
MPV_frame_start(s, avctx);
@@ -1307,8 +1329,8 @@ vbv_retry:
ff_write_pass1_stats(s);
for(i=0; i<4; i++){
- s->current_picture_ptr->error[i]= s->current_picture.error[i];
- avctx->error[i] += s->current_picture_ptr->error[i];
+ s->current_picture_ptr->f.error[i] = s->current_picture.f.error[i];
+ avctx->error[i] += s->current_picture_ptr->f.error[i];
}
if(s->flags&CODEC_FLAG_PASS1)
@@ -1508,7 +1530,7 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s, int motion_x,
update_qscale(s);
if(!(s->flags&CODEC_FLAG_QP_RD)){
- s->qscale= s->current_picture_ptr->qscale_table[mb_xy];
+ s->qscale = s->current_picture_ptr->f.qscale_table[mb_xy];
s->dquant= s->qscale - last_qp;
if(s->out_format==FMT_H263){
@@ -1532,9 +1554,9 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s, int motion_x,
wrap_y = s->linesize;
wrap_c = s->uvlinesize;
- ptr_y = s->new_picture.data[0] + (mb_y * 16 * wrap_y) + mb_x * 16;
- ptr_cb = s->new_picture.data[1] + (mb_y * mb_block_height * wrap_c) + mb_x * 8;
- ptr_cr = s->new_picture.data[2] + (mb_y * mb_block_height * wrap_c) + mb_x * 8;
+ ptr_y = s->new_picture.f.data[0] + (mb_y * 16 * wrap_y) + mb_x * 16;
+ ptr_cb = s->new_picture.f.data[1] + (mb_y * mb_block_height * wrap_c) + mb_x * 8;
+ ptr_cr = s->new_picture.f.data[2] + (mb_y * mb_block_height * wrap_c) + mb_x * 8;
if(mb_x*16+16 > s->width || mb_y*16+16 > s->height){
uint8_t *ebuf= s->edge_emu_buffer + 32;
@@ -1602,12 +1624,12 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s, int motion_x,
}
if (s->mv_dir & MV_DIR_FORWARD) {
- MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture.data, op_pix, op_qpix);
+ MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture.f.data, op_pix, op_qpix);
op_pix = s->dsp.avg_pixels_tab;
op_qpix= s->dsp.avg_qpel_pixels_tab;
}
if (s->mv_dir & MV_DIR_BACKWARD) {
- MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.data, op_pix, op_qpix);
+ MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.f.data, op_pix, op_qpix);
}
if(s->flags&CODEC_FLAG_INTERLACED_DCT){
@@ -1771,6 +1793,7 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s, int motion_x,
h263_encode_mb(s, s->block, motion_x, motion_y);
break;
case CODEC_ID_MJPEG:
+ case CODEC_ID_AMV:
if (CONFIG_MJPEG_ENCODER)
ff_mjpeg_encode_mb(s, s->block);
break;
@@ -1933,18 +1956,18 @@ static int sse_mb(MpegEncContext *s){
if(w==16 && h==16)
if(s->avctx->mb_cmp == FF_CMP_NSSE){
- return s->dsp.nsse[0](s, s->new_picture.data[0] + s->mb_x*16 + s->mb_y*s->linesize*16, s->dest[0], s->linesize, 16)
- +s->dsp.nsse[1](s, s->new_picture.data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[1], s->uvlinesize, 8)
- +s->dsp.nsse[1](s, s->new_picture.data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[2], s->uvlinesize, 8);
+ return s->dsp.nsse[0](s, s->new_picture.f.data[0] + s->mb_x*16 + s->mb_y*s->linesize*16, s->dest[0], s->linesize, 16)
+ +s->dsp.nsse[1](s, s->new_picture.f.data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[1], s->uvlinesize, 8)
+ +s->dsp.nsse[1](s, s->new_picture.f.data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[2], s->uvlinesize, 8);
}else{
- return s->dsp.sse[0](NULL, s->new_picture.data[0] + s->mb_x*16 + s->mb_y*s->linesize*16, s->dest[0], s->linesize, 16)
- +s->dsp.sse[1](NULL, s->new_picture.data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[1], s->uvlinesize, 8)
- +s->dsp.sse[1](NULL, s->new_picture.data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[2], s->uvlinesize, 8);
+ return s->dsp.sse[0](NULL, s->new_picture.f.data[0] + s->mb_x*16 + s->mb_y*s->linesize*16, s->dest[0], s->linesize, 16)
+ +s->dsp.sse[1](NULL, s->new_picture.f.data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[1], s->uvlinesize, 8)
+ +s->dsp.sse[1](NULL, s->new_picture.f.data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[2], s->uvlinesize, 8);
}
else
- return sse(s, s->new_picture.data[0] + s->mb_x*16 + s->mb_y*s->linesize*16, s->dest[0], w, h, s->linesize)
- +sse(s, s->new_picture.data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[1], w>>1, h>>1, s->uvlinesize)
- +sse(s, s->new_picture.data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[2], w>>1, h>>1, s->uvlinesize);
+ return sse(s, s->new_picture.f.data[0] + s->mb_x*16 + s->mb_y*s->linesize*16, s->dest[0], w, h, s->linesize)
+ +sse(s, s->new_picture.f.data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[1], w>>1, h>>1, s->uvlinesize)
+ +sse(s, s->new_picture.f.data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[2], w>>1, h>>1, s->uvlinesize);
}
static int pre_estimate_motion_thread(AVCodecContext *c, void *arg){
@@ -2003,11 +2026,11 @@ static int mb_var_thread(AVCodecContext *c, void *arg){
for(mb_x=0; mb_x < s->mb_width; mb_x++) {
int xx = mb_x * 16;
int yy = mb_y * 16;
- uint8_t *pix = s->new_picture.data[0] + (yy * s->linesize) + xx;
+ uint8_t *pix = s->new_picture.f.data[0] + (yy * s->linesize) + xx;
int varc;
int sum = s->dsp.pix_sum(pix, s->linesize);
- varc = (s->dsp.pix_norm1(pix, s->linesize) - (((unsigned)(sum*sum))>>8) + 500 + 128)>>8;
+ varc = (s->dsp.pix_norm1(pix, s->linesize) - (((unsigned)sum*sum)>>8) + 500 + 128)>>8;
s->current_picture.mb_var [s->mb_stride * mb_y + mb_x] = varc;
s->current_picture.mb_mean[s->mb_stride * mb_y + mb_x] = (sum+128)>>8;
@@ -2028,7 +2051,7 @@ static void write_slice_end(MpegEncContext *s){
ff_mjpeg_encode_stuffing(&s->pb);
}
- align_put_bits(&s->pb);
+ avpriv_align_put_bits(&s->pb);
flush_put_bits(&s->pb);
if((s->flags&CODEC_FLAG_PASS1) && !s->partitioned_frame)
@@ -2070,7 +2093,12 @@ static int encode_thread(AVCodecContext *c, void *arg){
/* note: quant matrix value (8) is implied here */
s->last_dc[i] = 128 << s->intra_dc_precision;
- s->current_picture.error[i] = 0;
+ s->current_picture.f.error[i] = 0;
+ }
+ if(s->codec_id==CODEC_ID_AMV){
+ s->last_dc[0] = 128*8/13;
+ s->last_dc[1] = 128*8/14;
+ s->last_dc[2] = 128*8/14;
}
s->mb_skip_run = 0;
memset(s->last_mv, 0, sizeof(s->last_mv));
@@ -2271,8 +2299,8 @@ static int encode_thread(AVCodecContext *c, void *arg){
s->mv_type = MV_TYPE_8X8;
s->mb_intra= 0;
for(i=0; i<4; i++){
- s->mv[0][i][0] = s->current_picture.motion_val[0][s->block_index[i]][0];
- s->mv[0][i][1] = s->current_picture.motion_val[0][s->block_index[i]][1];
+ s->mv[0][i][0] = s->current_picture.f.motion_val[0][s->block_index[i]][0];
+ s->mv[0][i][1] = s->current_picture.f.motion_val[0][s->block_index[i]][1];
}
encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER4V, pb, pb2, tex_pb,
&dmin, &next_block, 0, 0);
@@ -2458,24 +2486,24 @@ static int encode_thread(AVCodecContext *c, void *arg){
}
}
- s->current_picture.qscale_table[xy]= best_s.qscale;
+ s->current_picture.f.qscale_table[xy] = best_s.qscale;
copy_context_after_encode(s, &best_s, -1);
pb_bits_count= put_bits_count(&s->pb);
flush_put_bits(&s->pb);
- ff_copy_bits(&backup_s.pb, bit_buf[next_block^1], pb_bits_count);
+ avpriv_copy_bits(&backup_s.pb, bit_buf[next_block^1], pb_bits_count);
s->pb= backup_s.pb;
if(s->data_partitioning){
pb2_bits_count= put_bits_count(&s->pb2);
flush_put_bits(&s->pb2);
- ff_copy_bits(&backup_s.pb2, bit_buf2[next_block^1], pb2_bits_count);
+ avpriv_copy_bits(&backup_s.pb2, bit_buf2[next_block^1], pb2_bits_count);
s->pb2= backup_s.pb2;
tex_pb_bits_count= put_bits_count(&s->tex_pb);
flush_put_bits(&s->tex_pb);
- ff_copy_bits(&backup_s.tex_pb, bit_buf_tex[next_block^1], tex_pb_bits_count);
+ avpriv_copy_bits(&backup_s.tex_pb, bit_buf_tex[next_block^1], tex_pb_bits_count);
s->tex_pb= backup_s.tex_pb;
}
s->last_bits= put_bits_count(&s->pb);
@@ -2525,8 +2553,8 @@ static int encode_thread(AVCodecContext *c, void *arg){
s->mv_type = MV_TYPE_8X8;
s->mb_intra= 0;
for(i=0; i<4; i++){
- s->mv[0][i][0] = s->current_picture.motion_val[0][s->block_index[i]][0];
- s->mv[0][i][1] = s->current_picture.motion_val[0][s->block_index[i]][1];
+ s->mv[0][i][0] = s->current_picture.f.motion_val[0][s->block_index[i]][0];
+ s->mv[0][i][1] = s->current_picture.f.motion_val[0][s->block_index[i]][1];
}
break;
case CANDIDATE_MB_TYPE_DIRECT:
@@ -2627,14 +2655,14 @@ static int encode_thread(AVCodecContext *c, void *arg){
if(s->mb_x*16 + 16 > s->width ) w= s->width - s->mb_x*16;
if(s->mb_y*16 + 16 > s->height) h= s->height- s->mb_y*16;
- s->current_picture.error[0] += sse(
- s, s->new_picture.data[0] + s->mb_x*16 + s->mb_y*s->linesize*16,
+ s->current_picture.f.error[0] += sse(
+ s, s->new_picture.f.data[0] + s->mb_x*16 + s->mb_y*s->linesize*16,
s->dest[0], w, h, s->linesize);
- s->current_picture.error[1] += sse(
- s, s->new_picture.data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*chr_h,
+ s->current_picture.f.error[1] += sse(
+ s, s->new_picture.f.data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*chr_h,
s->dest[1], w>>1, h>>s->chroma_y_shift, s->uvlinesize);
- s->current_picture.error[2] += sse(
- s, s->new_picture.data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*chr_h,
+ s->current_picture.f.error[2] += sse(
+ s, s->new_picture.f.data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*chr_h,
s->dest[2], w>>1, h>>s->chroma_y_shift, s->uvlinesize);
}
if(s->loop_filter){
@@ -2685,9 +2713,9 @@ static void merge_context_after_encode(MpegEncContext *dst, MpegEncContext *src)
MERGE(misc_bits);
MERGE(error_count);
MERGE(padding_bug_score);
- MERGE(current_picture.error[0]);
- MERGE(current_picture.error[1]);
- MERGE(current_picture.error[2]);
+ MERGE(current_picture.f.error[0]);
+ MERGE(current_picture.f.error[1]);
+ MERGE(current_picture.f.error[2]);
if(dst->avctx->noise_reduction){
for(i=0; i<64; i++){
@@ -2698,19 +2726,19 @@ static void merge_context_after_encode(MpegEncContext *dst, MpegEncContext *src)
assert(put_bits_count(&src->pb) % 8 ==0);
assert(put_bits_count(&dst->pb) % 8 ==0);
- ff_copy_bits(&dst->pb, src->pb.buf, put_bits_count(&src->pb));
+ avpriv_copy_bits(&dst->pb, src->pb.buf, put_bits_count(&src->pb));
flush_put_bits(&dst->pb);
}
static int estimate_qp(MpegEncContext *s, int dry_run){
if (s->next_lambda){
- s->current_picture_ptr->quality=
- s->current_picture.quality = s->next_lambda;
+ s->current_picture_ptr->f.quality =
+ s->current_picture.f.quality = s->next_lambda;
if(!dry_run) s->next_lambda= 0;
} else if (!s->fixed_qscale) {
- s->current_picture_ptr->quality=
- s->current_picture.quality = ff_rate_estimate_qscale(s, dry_run);
- if (s->current_picture.quality < 0)
+ s->current_picture_ptr->f.quality =
+ s->current_picture.f.quality = ff_rate_estimate_qscale(s, dry_run);
+ if (s->current_picture.f.quality < 0)
return -1;
}
@@ -2733,7 +2761,7 @@ static int estimate_qp(MpegEncContext *s, int dry_run){
s->lambda= s->lambda_table[0];
//FIXME broken
}else
- s->lambda= s->current_picture.quality;
+ s->lambda = s->current_picture.f.quality;
//printf("%d %d\n", s->avctx->global_quality, s->current_picture.quality);
update_qscale(s);
return 0;
@@ -2741,8 +2769,8 @@ static int estimate_qp(MpegEncContext *s, int dry_run){
/* must be called before writing the header */
static void set_frame_distances(MpegEncContext * s){
- assert(s->current_picture_ptr->pts != AV_NOPTS_VALUE);
- s->time= s->current_picture_ptr->pts*s->avctx->time_base.num;
+ assert(s->current_picture_ptr->f.pts != AV_NOPTS_VALUE);
+ s->time = s->current_picture_ptr->f.pts * s->avctx->time_base.num;
if(s->pict_type==AV_PICTURE_TYPE_B){
s->pb_time= s->pp_time - (s->last_non_b_time - s->time);
@@ -2797,6 +2825,13 @@ static int encode_picture(MpegEncContext *s, int picture_number)
update_qscale(s);
}
+ if(s->codec_id != CODEC_ID_AMV){
+ if(s->q_chroma_intra_matrix != s->q_intra_matrix ) av_freep(&s->q_chroma_intra_matrix);
+ if(s->q_chroma_intra_matrix16 != s->q_intra_matrix16) av_freep(&s->q_chroma_intra_matrix16);
+ s->q_chroma_intra_matrix = s->q_intra_matrix;
+ s->q_chroma_intra_matrix16 = s->q_intra_matrix16;
+ }
+
s->mb_intra=0; //for the rate distortion & bit compare functions
for(i=1; i<context_count; i++){
ff_update_duplicate_context(s->thread_context[i], s);
@@ -2914,14 +2949,33 @@ static int encode_picture(MpegEncContext *s, int picture_number)
s->intra_matrix, s->intra_quant_bias, 8, 8, 1);
s->qscale= 8;
}
+ if(s->codec_id == CODEC_ID_AMV){
+ static const uint8_t y[32]={13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13};
+ static const uint8_t c[32]={14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14};
+ for(i=1;i<64;i++){
+ int j= s->dsp.idct_permutation[ff_zigzag_direct[i]];
+
+ s->intra_matrix[j] = sp5x_quant_table[5*2+0][i];
+ s->chroma_intra_matrix[j] = sp5x_quant_table[5*2+1][i];
+ }
+ s->y_dc_scale_table= y;
+ s->c_dc_scale_table= c;
+ s->intra_matrix[0] = 13;
+ s->chroma_intra_matrix[0] = 14;
+ ff_convert_matrix(&s->dsp, s->q_intra_matrix, s->q_intra_matrix16,
+ s->intra_matrix, s->intra_quant_bias, 8, 8, 1);
+ ff_convert_matrix(&s->dsp, s->q_chroma_intra_matrix, s->q_chroma_intra_matrix16,
+ s->chroma_intra_matrix, s->intra_quant_bias, 8, 8, 1);
+ s->qscale= 8;
+ }
//FIXME var duplication
- s->current_picture_ptr->key_frame=
- s->current_picture.key_frame= s->pict_type == AV_PICTURE_TYPE_I; //FIXME pic_ptr
- s->current_picture_ptr->pict_type=
- s->current_picture.pict_type= s->pict_type;
+ s->current_picture_ptr->f.key_frame =
+ s->current_picture.f.key_frame = s->pict_type == AV_PICTURE_TYPE_I; //FIXME pic_ptr
+ s->current_picture_ptr->f.pict_type =
+ s->current_picture.f.pict_type = s->pict_type;
- if(s->current_picture.key_frame)
+ if (s->current_picture.f.key_frame)
s->picture_in_gop_number=0;
s->last_bits= put_bits_count(&s->pb);
@@ -3048,7 +3102,7 @@ static int dct_quantize_trellis_c(MpegEncContext *s,
block[0] = (block[0] + (q >> 1)) / q;
start_i = 1;
last_non_zero = 0;
- qmat = s->q_intra_matrix[qscale];
+ qmat = n < 4 ? s->q_intra_matrix[qscale] : s->q_chroma_intra_matrix[qscale];
if(s->mpeg_quant || s->out_format == FMT_MPEG1)
bias= 1<<(QMAT_SHIFT-1);
length = s->intra_ac_vlc_length;
@@ -3719,7 +3773,7 @@ int dct_quantize_c(MpegEncContext *s,
block[0] = (block[0] + (q >> 1)) / q;
start_i = 1;
last_non_zero = 0;
- qmat = s->q_intra_matrix[qscale];
+ qmat = n < 4 ? s->q_intra_matrix[qscale] : s->q_chroma_intra_matrix[qscale];
bias= s->intra_quant_bias<<(QMAT_SHIFT - QUANT_BIAS_SHIFT);
} else {
start_i = 0;
@@ -3768,63 +3822,94 @@ int dct_quantize_c(MpegEncContext *s,
return last_non_zero;
}
+#define OFFSET(x) offsetof(MpegEncContext, x)
+#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
+static const AVOption h263_options[] = {
+ { "obmc", "use overlapped block motion compensation.", OFFSET(obmc), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },
+ { "structured_slices","Write slice start position at every GOB header instead of just GOB number.", OFFSET(h263_slice_structured), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE},
+ { NULL },
+};
+
+static const AVClass h263_class = {
+ .class_name = "H.263 encoder",
+ .item_name = av_default_item_name,
+ .option = h263_options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
AVCodec ff_h263_encoder = {
- "h263",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_H263,
- sizeof(MpegEncContext),
- MPV_encode_init,
- MPV_encode_picture,
- MPV_encode_end,
+ .name = "h263",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_H263,
+ .priv_data_size = sizeof(MpegEncContext),
+ .init = MPV_encode_init,
+ .encode = MPV_encode_picture,
+ .close = MPV_encode_end,
.pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
.long_name= NULL_IF_CONFIG_SMALL("H.263 / H.263-1996"),
+ .priv_class = &h263_class,
+};
+
+static const AVOption h263p_options[] = {
+ { "umv", "Use unlimited motion vectors.", OFFSET(umvplus), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },
+ { "aiv", "Use alternative inter VLC.", OFFSET(alt_inter_vlc), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },
+ { "obmc", "use overlapped block motion compensation.", OFFSET(obmc), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },
+ { "structured_slices", "Write slice start position at every GOB header instead of just GOB number.", OFFSET(h263_slice_structured), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE},
+ { NULL },
+};
+static const AVClass h263p_class = {
+ .class_name = "H.263p encoder",
+ .item_name = av_default_item_name,
+ .option = h263p_options,
+ .version = LIBAVUTIL_VERSION_INT,
};
AVCodec ff_h263p_encoder = {
- "h263p",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_H263P,
- sizeof(MpegEncContext),
- MPV_encode_init,
- MPV_encode_picture,
- MPV_encode_end,
+ .name = "h263p",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_H263P,
+ .priv_data_size = sizeof(MpegEncContext),
+ .init = MPV_encode_init,
+ .encode = MPV_encode_picture,
+ .close = MPV_encode_end,
.capabilities = CODEC_CAP_SLICE_THREADS,
.pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
.long_name= NULL_IF_CONFIG_SMALL("H.263+ / H.263-1998 / H.263 version 2"),
+ .priv_class = &h263p_class,
};
AVCodec ff_msmpeg4v2_encoder = {
- "msmpeg4v2",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_MSMPEG4V2,
- sizeof(MpegEncContext),
- MPV_encode_init,
- MPV_encode_picture,
- MPV_encode_end,
+ .name = "msmpeg4v2",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_MSMPEG4V2,
+ .priv_data_size = sizeof(MpegEncContext),
+ .init = MPV_encode_init,
+ .encode = MPV_encode_picture,
+ .close = MPV_encode_end,
.pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
.long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 2"),
};
AVCodec ff_msmpeg4v3_encoder = {
- "msmpeg4",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_MSMPEG4V3,
- sizeof(MpegEncContext),
- MPV_encode_init,
- MPV_encode_picture,
- MPV_encode_end,
+ .name = "msmpeg4",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_MSMPEG4V3,
+ .priv_data_size = sizeof(MpegEncContext),
+ .init = MPV_encode_init,
+ .encode = MPV_encode_picture,
+ .close = MPV_encode_end,
.pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
.long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 3"),
};
AVCodec ff_wmv1_encoder = {
- "wmv1",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_WMV1,
- sizeof(MpegEncContext),
- MPV_encode_init,
- MPV_encode_picture,
- MPV_encode_end,
+ .name = "wmv1",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_WMV1,
+ .priv_data_size = sizeof(MpegEncContext),
+ .init = MPV_encode_init,
+ .encode = MPV_encode_picture,
+ .close = MPV_encode_end,
.pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
.long_name= NULL_IF_CONFIG_SMALL("Windows Media Video 7"),
};
diff --git a/libavcodec/mpegvideo_parser.c b/libavcodec/mpegvideo_parser.c
index 9688e18625..ce55cdd13c 100644
--- a/libavcodec/mpegvideo_parser.c
+++ b/libavcodec/mpegvideo_parser.c
@@ -3,20 +3,20 @@
* Copyright (c) 2000,2001 Fabrice Bellard
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -40,7 +40,7 @@ static void mpegvideo_extract_headers(AVCodecParserContext *s,
while (buf < buf_end) {
start_code= -1;
- buf= ff_find_start_code(buf, buf_end, &start_code);
+ buf= avpriv_mpv_find_start_code(buf, buf_end, &start_code);
bytes_left = buf_end - buf;
switch(start_code) {
case PICTURE_START_CODE:
@@ -57,8 +57,8 @@ static void mpegvideo_extract_headers(AVCodecParserContext *s,
did_set_size=1;
}
frame_rate_index = buf[3] & 0xf;
- pc->frame_rate.den = avctx->time_base.den = ff_frame_rate_tab[frame_rate_index].num;
- pc->frame_rate.num = avctx->time_base.num = ff_frame_rate_tab[frame_rate_index].den;
+ pc->frame_rate.den = avctx->time_base.den = avpriv_frame_rate_tab[frame_rate_index].num;
+ pc->frame_rate.num = avctx->time_base.num = avpriv_frame_rate_tab[frame_rate_index].den;
avctx->bit_rate = ((buf[4]<<10) | (buf[5]<<2) | (buf[6]>>6))*400;
avctx->codec_id = CODEC_ID_MPEG1VIDEO;
avctx->sub_id = 1;
@@ -164,10 +164,13 @@ static int mpegvideo_split(AVCodecContext *avctx,
{
int i;
uint32_t state= -1;
+ int found=0;
for(i=0; i<buf_size; i++){
state= (state<<8) | buf[i];
- if(state != 0x1B3 && state != 0x1B5 && state < 0x200 && state >= 0x100)
+ if(state == 0x1B3){
+ found=1;
+ }else if(found && state != 0x1B5 && state < 0x200 && state >= 0x100)
return i-3;
}
return 0;
diff --git a/libavcodec/mpegvideo_xvmc.c b/libavcodec/mpegvideo_xvmc.c
index 29d8bbbde6..6247e6240c 100644
--- a/libavcodec/mpegvideo_xvmc.c
+++ b/libavcodec/mpegvideo_xvmc.c
@@ -2,20 +2,20 @@
* XVideo Motion Compensation
* Copyright (c) 2003 Ivan Kalvachev
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -41,7 +41,7 @@
*/
void ff_xvmc_init_block(MpegEncContext *s)
{
- struct xvmc_pix_fmt *render = (struct xvmc_pix_fmt*)s->current_picture.data[2];
+ struct xvmc_pix_fmt *render = (struct xvmc_pix_fmt*)s->current_picture.f.data[2];
assert(render && render->xvmc_id == AV_XVMC_ID);
s->block = (DCTELEM (*)[64])(render->data_blocks + render->next_free_data_block_num * 64);
@@ -73,7 +73,7 @@ void ff_xvmc_pack_pblocks(MpegEncContext *s, int cbp)
*/
int ff_xvmc_field_start(MpegEncContext *s, AVCodecContext *avctx)
{
- struct xvmc_pix_fmt *last, *next, *render = (struct xvmc_pix_fmt*)s->current_picture.data[2];
+ struct xvmc_pix_fmt *last, *next, *render = (struct xvmc_pix_fmt*)s->current_picture.f.data[2];
const int mb_block_count = 4 + (1 << s->chroma_format);
assert(avctx);
@@ -113,7 +113,7 @@ int ff_xvmc_field_start(MpegEncContext *s, AVCodecContext *avctx)
case AV_PICTURE_TYPE_I:
return 0; // no prediction from other frames
case AV_PICTURE_TYPE_B:
- next = (struct xvmc_pix_fmt*)s->next_picture.data[2];
+ next = (struct xvmc_pix_fmt*)s->next_picture.f.data[2];
if (!next)
return -1;
if (next->xvmc_id != AV_XVMC_ID)
@@ -121,7 +121,7 @@ int ff_xvmc_field_start(MpegEncContext *s, AVCodecContext *avctx)
render->p_future_surface = next->p_surface;
// no return here, going to set forward prediction
case AV_PICTURE_TYPE_P:
- last = (struct xvmc_pix_fmt*)s->last_picture.data[2];
+ last = (struct xvmc_pix_fmt*)s->last_picture.f.data[2];
if (!last)
last = render; // predict second field from the first
if (last->xvmc_id != AV_XVMC_ID)
@@ -141,7 +141,7 @@ return -1;
*/
void ff_xvmc_field_end(MpegEncContext *s)
{
- struct xvmc_pix_fmt *render = (struct xvmc_pix_fmt*)s->current_picture.data[2];
+ struct xvmc_pix_fmt *render = (struct xvmc_pix_fmt*)s->current_picture.f.data[2];
assert(render);
if (render->filled_mv_blocks_num > 0)
@@ -179,10 +179,10 @@ void ff_xvmc_decode_mb(MpegEncContext *s)
// Do I need to export quant when I could not perform postprocessing?
// Anyway, it doesn't hurt.
- s->current_picture.qscale_table[mb_xy] = s->qscale;
+ s->current_picture.f.qscale_table[mb_xy] = s->qscale;
// start of XVMC-specific code
- render = (struct xvmc_pix_fmt*)s->current_picture.data[2];
+ render = (struct xvmc_pix_fmt*)s->current_picture.f.data[2];
assert(render);
assert(render->xvmc_id == AV_XVMC_ID);
assert(render->mv_blocks);
diff --git a/libavcodec/mqc.c b/libavcodec/mqc.c
new file mode 100644
index 0000000000..700b9574c1
--- /dev/null
+++ b/libavcodec/mqc.c
@@ -0,0 +1,108 @@
+/*
+ * MQ-coder encoder and decoder common functions
+ * Copyright (c) 2007 Kamil Nowosad
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * MQ-coder ecoder and decoder common functions
+ * @file
+ * @author Kamil Nowosad
+ */
+
+#include "mqc.h"
+
+typedef struct {
+ uint16_t qe;
+ uint8_t nmps;
+ uint8_t nlps;
+ uint8_t sw;
+} MqcCxState;
+
+const static MqcCxState cx_states[47] = {
+ {0x5601, 1, 1, 1},
+ {0x3401, 2, 6, 0},
+ {0x1801, 3, 9, 0},
+ {0x0AC1, 4, 12, 0},
+ {0x0521, 5, 29, 0},
+ {0x0221, 38, 33, 0},
+ {0x5601, 7, 6, 1},
+ {0x5401, 8, 14, 0},
+ {0x4801, 9, 14, 0},
+ {0x3801, 10, 14, 0},
+ {0x3001, 11, 17, 0},
+ {0x2401, 12, 18, 0},
+ {0x1C01, 13, 20, 0},
+ {0x1601, 29, 21, 0},
+ {0x5601, 15, 14, 1},
+ {0x5401, 16, 14, 0},
+ {0x5101, 17, 15, 0},
+ {0x4801, 18, 16, 0},
+ {0x3801, 19, 17, 0},
+ {0x3401, 20, 18, 0},
+ {0x3001, 21, 19, 0},
+ {0x2801, 22, 19, 0},
+ {0x2401, 23, 20, 0},
+ {0x2201, 24, 21, 0},
+ {0x1C01, 25, 22, 0},
+ {0x1801, 26, 23, 0},
+ {0x1601, 27, 24, 0},
+ {0x1401, 28, 25, 0},
+ {0x1201, 29, 26, 0},
+ {0x1101, 30, 27, 0},
+ {0x0AC1, 31, 28, 0},
+ {0x09C1, 32, 29, 0},
+ {0x08A1, 33, 30, 0},
+ {0x0521, 34, 31, 0},
+ {0x0441, 35, 32, 0},
+ {0x02A1, 36, 33, 0},
+ {0x0221, 37, 34, 0},
+ {0x0141, 38, 35, 0},
+ {0x0111, 39, 36, 0},
+ {0x0085, 40, 37, 0},
+ {0x0049, 41, 38, 0},
+ {0x0025, 42, 39, 0},
+ {0x0015, 43, 40, 0},
+ {0x0009, 44, 41, 0},
+ {0x0005, 45, 42, 0},
+ {0x0001, 45, 43, 0},
+ {0x5601, 46, 46, 0}
+};
+
+uint16_t ff_mqc_qe [2*47];
+uint8_t ff_mqc_nlps[2*47];
+uint8_t ff_mqc_nmps[2*47];
+
+void ff_mqc_init_contexts(MqcState *mqc)
+{
+ int i;
+ memset(mqc->cx_states, 0, sizeof(mqc->cx_states));
+ mqc->cx_states[MQC_CX_UNI] = 2 * 46;
+ mqc->cx_states[MQC_CX_RL] = 2 * 3;
+ mqc->cx_states[0] = 2 * 4;
+
+ for (i = 0; i < 47; i++){
+ ff_mqc_qe[2*i ] =
+ ff_mqc_qe[2*i+1] = cx_states[i].qe;
+
+ ff_mqc_nlps[2*i ] = 2*cx_states[i].nlps + cx_states[i].sw;
+ ff_mqc_nlps[2*i+1] = 2*cx_states[i].nlps + 1 - cx_states[i].sw;
+ ff_mqc_nmps[2*i ] = 2*cx_states[i].nmps;
+ ff_mqc_nmps[2*i+1] = 2*cx_states[i].nmps + 1;
+ }
+}
diff --git a/libavcodec/mqc.h b/libavcodec/mqc.h
new file mode 100644
index 0000000000..b28c13ec48
--- /dev/null
+++ b/libavcodec/mqc.h
@@ -0,0 +1,75 @@
+/*
+ * MQ-coder
+ * Copyright (c) 2007 Kamil Nowosad
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_MQC_H
+#define AVCODEC_MQC_H
+
+/**
+ * MQ-coder
+ * @file
+ * @author Kamil Nowosad
+ */
+
+#include "avcodec.h"
+
+#define MQC_CX_UNI 17
+#define MQC_CX_RL 18
+
+extern uint16_t ff_mqc_qe[2*47];
+extern uint8_t ff_mqc_nlps[2*47];
+extern uint8_t ff_mqc_nmps[2*47];
+
+typedef struct {
+ uint8_t *bp, *bpstart;
+ unsigned int a;
+ unsigned int c;
+ unsigned int ct;
+ uint8_t cx_states[19];
+} MqcState;
+
+/* encoder */
+
+/** initialize the encoder */
+void ff_mqc_initenc(MqcState *mqc, uint8_t *bp);
+
+/** code bit d with context cx */
+void ff_mqc_encode(MqcState *mqc, uint8_t *cxstate, int d);
+
+/** number of encoded bytes */
+int ff_mqc_length(MqcState *mqc);
+
+/** flush the encoder [returns number of bytes encoded] */
+int ff_mqc_flush(MqcState *mqc);
+
+/* decoder */
+
+/** initialize the decoder */
+void ff_mqc_initdec(MqcState *mqc, uint8_t *bp);
+
+/** returns decoded bit with context cx */
+int ff_mqc_decode(MqcState *mqc, uint8_t *cxstate);
+
+/* common */
+
+/** initialize the contexts */
+void ff_mqc_init_contexts(MqcState *mqc);
+
+#endif /* AVCODEC_MQC_H */
diff --git a/libavcodec/mqcdec.c b/libavcodec/mqcdec.c
new file mode 100644
index 0000000000..56e22f88c7
--- /dev/null
+++ b/libavcodec/mqcdec.c
@@ -0,0 +1,93 @@
+/*
+ * MQ-coder decoder
+ * Copyright (c) 2007 Kamil Nowosad
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * MQ-coder decoder
+ * @file
+ * @author Kamil Nowosad
+ */
+
+#include "mqc.h"
+
+static void bytein(MqcState *mqc)
+{
+ if (*mqc->bp == 0xff){
+ if (*(mqc->bp+1) > 0x8f)
+ mqc->c++;
+ else{
+ mqc->bp++;
+ mqc->c += 2 + 0xfe00 - (*mqc->bp << 9);
+ }
+ } else{
+ mqc->bp++;
+ mqc->c += 1 + 0xff00 - (*mqc->bp << 8);
+ }
+}
+
+static int exchange(MqcState *mqc, uint8_t *cxstate, int lps)
+{
+ int d;
+ if ((mqc->a < ff_mqc_qe[*cxstate]) ^ (!lps)){
+ if (lps)
+ mqc->a = ff_mqc_qe[*cxstate];
+ d = *cxstate & 1;
+ *cxstate = ff_mqc_nmps[*cxstate];
+ } else{
+ if (lps)
+ mqc->a = ff_mqc_qe[*cxstate];
+ d = 1 - (*cxstate & 1);
+ *cxstate = ff_mqc_nlps[*cxstate];
+ }
+ // renormd:
+ do{
+ if (!(mqc->c & 0xff)){
+ mqc->c -= 0x100;
+ bytein(mqc);
+ }
+ mqc->a += mqc->a;
+ mqc->c += mqc->c;
+ } while (!(mqc->a & 0x8000));
+ return d;
+}
+
+void ff_mqc_initdec(MqcState *mqc, uint8_t *bp)
+{
+ ff_mqc_init_contexts(mqc);
+ mqc->bp = bp;
+ mqc->c = (*mqc->bp ^ 0xff) << 16;
+ bytein(mqc);
+ mqc->c = mqc->c << 7;
+ mqc->a = 0x8000;
+}
+
+int ff_mqc_decode(MqcState *mqc, uint8_t *cxstate)
+{
+ mqc->a -= ff_mqc_qe[*cxstate];
+ if ((mqc->c >> 16) < mqc->a){
+ if (mqc->a & 0x8000)
+ return *cxstate & 1;
+ else
+ return exchange(mqc, cxstate, 0);
+ } else {
+ mqc->c -= mqc->a << 16;
+ return exchange(mqc, cxstate, 1);
+ }
+}
diff --git a/libavcodec/mqcenc.c b/libavcodec/mqcenc.c
new file mode 100644
index 0000000000..97d352be44
--- /dev/null
+++ b/libavcodec/mqcenc.c
@@ -0,0 +1,119 @@
+/*
+ * MQ-coder encoder
+ * Copyright (c) 2007 Kamil Nowosad
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * MQ-coder encoder
+ * @file
+ * @author Kamil Nowosad
+ */
+
+#include "mqc.h"
+
+static void byteout(MqcState *mqc)
+{
+retry:
+ if (*mqc->bp == 0xff){
+ mqc->bp++;
+ *mqc->bp = mqc->c >> 20;
+ mqc->c &= 0xfffff;
+ mqc->ct = 7;
+ } else if ((mqc->c & 0x8000000)){
+ (*mqc->bp)++;
+ mqc->c &= 0x7ffffff;
+ goto retry;
+ } else{
+ mqc->bp++;
+ *mqc->bp = mqc->c >> 19;
+ mqc->c &= 0x7ffff;
+ mqc->ct = 8;
+ }
+}
+
+static void renorme(MqcState *mqc)
+{
+ do{
+ mqc->a += mqc->a;
+ mqc->c += mqc->c;
+ if (!--mqc->ct)
+ byteout(mqc);
+ } while (!(mqc->a & 0x8000));
+}
+
+static void setbits(MqcState *mqc)
+{
+ int tmp = mqc->c + mqc->a;
+ mqc->c |= 0xffff;
+ if (mqc->c >= tmp)
+ mqc->c -= 0x8000;
+}
+
+void ff_mqc_initenc(MqcState *mqc, uint8_t *bp)
+{
+ ff_mqc_init_contexts(mqc);
+ mqc->a = 0x8000;
+ mqc->c = 0;
+ mqc->bp = bp-1;
+ mqc->bpstart = bp;
+ mqc->ct = 12 + (*mqc->bp == 0xff);
+}
+
+void ff_mqc_encode(MqcState *mqc, uint8_t *cxstate, int d)
+{
+ int qe;
+
+ qe = ff_mqc_qe[*cxstate];
+ mqc->a -= qe;
+ if ((*cxstate & 1) == d){
+ if (!(mqc->a & 0x8000)){
+ if (mqc->a < qe)
+ mqc->a = qe;
+ else
+ mqc->c += qe;
+ *cxstate = ff_mqc_nmps[*cxstate];
+ renorme(mqc);
+ } else
+ mqc->c += qe;
+ } else{
+ if (mqc->a < qe)
+ mqc->c += qe;
+ else
+ mqc->a = qe;
+ *cxstate = ff_mqc_nlps[*cxstate];
+ renorme(mqc);
+ }
+}
+
+int ff_mqc_length(MqcState *mqc)
+{
+ return mqc->bp - mqc->bpstart;
+}
+
+int ff_mqc_flush(MqcState *mqc)
+{
+ setbits(mqc);
+ mqc->c = mqc->c << mqc->ct;
+ byteout(mqc);
+ mqc->c = mqc->c << mqc->ct;
+ byteout(mqc);
+ if (*mqc->bp != 0xff)
+ mqc->bp++;
+ return mqc->bp - mqc->bpstart;
+}
diff --git a/libavcodec/msgsmdec.c b/libavcodec/msgsmdec.c
index ff9b275b77..e759451c83 100644
--- a/libavcodec/msgsmdec.c
+++ b/libavcodec/msgsmdec.c
@@ -2,20 +2,20 @@
* gsm 06.10 decoder, Microsoft variant
* Copyright (c) 2010 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/msgsmdec.h b/libavcodec/msgsmdec.h
index 76c87f1bd9..3bfd1fd407 100644
--- a/libavcodec/msgsmdec.h
+++ b/libavcodec/msgsmdec.h
@@ -2,20 +2,20 @@
* gsm 06.10 decoder, Microsoft variant
* Copyright (c) 2010 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/msmpeg4.c b/libavcodec/msmpeg4.c
index c740cfa0bd..5b762898af 100644
--- a/libavcodec/msmpeg4.c
+++ b/libavcodec/msmpeg4.c
@@ -5,20 +5,20 @@
*
* msmpeg4v1 & v2 stuff by Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -62,10 +62,6 @@ static uint32_t v2_dc_chroma_table[512][2];
/* vc1 externs */
extern const uint8_t wmv3_dc_scale_table[32];
-#ifdef DEBUG
-int frame_count = 0;
-#endif
-
#include "msmpeg4data.h"
#if CONFIG_ENCODERS //strangely gcc includes this even if it is not referenced
@@ -355,7 +351,7 @@ void msmpeg4_encode_picture_header(MpegEncContext * s, int picture_number)
{
find_best_tables(s);
- align_put_bits(&s->pb);
+ avpriv_align_put_bits(&s->pb);
put_bits(&s->pb, 2, s->pict_type - 1);
put_bits(&s->pb, 5, s->qscale);
@@ -780,10 +776,10 @@ static inline int msmpeg4_pred_dc(MpegEncContext * s, int n,
}else{
if(n<4){
wrap= s->linesize;
- dest= s->current_picture.data[0] + (((n>>1) + 2*s->mb_y) * 8* wrap ) + ((n&1) + 2*s->mb_x) * 8;
+ dest= s->current_picture.f.data[0] + (((n >> 1) + 2*s->mb_y) * 8* wrap ) + ((n & 1) + 2*s->mb_x) * 8;
}else{
wrap= s->uvlinesize;
- dest= s->current_picture.data[n-3] + (s->mb_y * 8 * wrap) + s->mb_x * 8;
+ dest= s->current_picture.f.data[n - 3] + (s->mb_y * 8 * wrap) + s->mb_x * 8;
}
if(s->mb_x==0) a= (1024 + (scale>>1))/scale;
else a= get_dc(dest-8, wrap, scale*8);
@@ -1172,7 +1168,7 @@ static int msmpeg4v34_decode_mb(MpegEncContext *s, DCTELEM block[6][64])
{
int cbp, code, i;
uint8_t *coded_val;
- uint32_t * const mb_type_ptr= &s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride ];
+ uint32_t * const mb_type_ptr = &s->current_picture.f.mb_type[s->mb_x + s->mb_y*s->mb_stride];
if (s->pict_type == AV_PICTURE_TYPE_P) {
if (s->use_skip_mb_code) {
@@ -1884,60 +1880,56 @@ int ff_msmpeg4_decode_motion(MpegEncContext * s,
}
AVCodec ff_msmpeg4v1_decoder = {
- "msmpeg4v1",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_MSMPEG4V1,
- sizeof(MpegEncContext),
- ff_msmpeg4_decode_init,
- NULL,
- ff_h263_decode_end,
- ff_h263_decode_frame,
- CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
+ .name = "msmpeg4v1",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_MSMPEG4V1,
+ .priv_data_size = sizeof(MpegEncContext),
+ .init = ff_msmpeg4_decode_init,
+ .close = ff_h263_decode_end,
+ .decode = ff_h263_decode_frame,
+ .capabilities = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
.max_lowres= 3,
.long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 1"),
.pix_fmts= ff_pixfmt_list_420,
};
AVCodec ff_msmpeg4v2_decoder = {
- "msmpeg4v2",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_MSMPEG4V2,
- sizeof(MpegEncContext),
- ff_msmpeg4_decode_init,
- NULL,
- ff_h263_decode_end,
- ff_h263_decode_frame,
- CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
+ .name = "msmpeg4v2",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_MSMPEG4V2,
+ .priv_data_size = sizeof(MpegEncContext),
+ .init = ff_msmpeg4_decode_init,
+ .close = ff_h263_decode_end,
+ .decode = ff_h263_decode_frame,
+ .capabilities = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
.max_lowres= 3,
.long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 2"),
.pix_fmts= ff_pixfmt_list_420,
};
AVCodec ff_msmpeg4v3_decoder = {
- "msmpeg4",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_MSMPEG4V3,
- sizeof(MpegEncContext),
- ff_msmpeg4_decode_init,
- NULL,
- ff_h263_decode_end,
- ff_h263_decode_frame,
- CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
+ .name = "msmpeg4",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_MSMPEG4V3,
+ .priv_data_size = sizeof(MpegEncContext),
+ .init = ff_msmpeg4_decode_init,
+ .close = ff_h263_decode_end,
+ .decode = ff_h263_decode_frame,
+ .capabilities = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
.max_lowres= 3,
.long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 3"),
.pix_fmts= ff_pixfmt_list_420,
};
AVCodec ff_wmv1_decoder = {
- "wmv1",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_WMV1,
- sizeof(MpegEncContext),
- ff_msmpeg4_decode_init,
- NULL,
- ff_h263_decode_end,
- ff_h263_decode_frame,
- CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
+ .name = "wmv1",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_WMV1,
+ .priv_data_size = sizeof(MpegEncContext),
+ .init = ff_msmpeg4_decode_init,
+ .close = ff_h263_decode_end,
+ .decode = ff_h263_decode_frame,
+ .capabilities = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
.max_lowres= 3,
.long_name= NULL_IF_CONFIG_SMALL("Windows Media Video 7"),
.pix_fmts= ff_pixfmt_list_420,
diff --git a/libavcodec/msmpeg4.h b/libavcodec/msmpeg4.h
index 8a0a066e48..c9d42b48e8 100644
--- a/libavcodec/msmpeg4.h
+++ b/libavcodec/msmpeg4.h
@@ -2,27 +2,23 @@
* MSMPEG4 backend for ffmpeg encoder and decoder
* copyright (c) 2007 Aurelien Jacobs <aurel@gnuage.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-/**
- * @file
- */
-
#ifndef AVCODEC_MSMPEG4_H
#define AVCODEC_MSMPEG4_H
diff --git a/libavcodec/msmpeg4data.c b/libavcodec/msmpeg4data.c
index eeb812297d..f72715dea0 100644
--- a/libavcodec/msmpeg4data.c
+++ b/libavcodec/msmpeg4data.c
@@ -5,20 +5,20 @@
*
* msmpeg4v1 & v2 stuff by Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/msmpeg4data.h b/libavcodec/msmpeg4data.h
index bbb802e441..623d9570a7 100644
--- a/libavcodec/msmpeg4data.h
+++ b/libavcodec/msmpeg4data.h
@@ -5,20 +5,20 @@
*
* msmpeg4v1 & v2 stuff by Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/msrle.c b/libavcodec/msrle.c
index f426b058bd..b9531f34d7 100644
--- a/libavcodec/msrle.c
+++ b/libavcodec/msrle.c
@@ -2,20 +2,20 @@
* Micrsoft RLE Video Decoder
* Copyright (C) 2003 the ffmpeg project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -53,6 +53,9 @@ static av_cold int msrle_decode_init(AVCodecContext *avctx)
s->avctx = avctx;
switch (avctx->bits_per_coded_sample) {
+ case 1:
+ avctx->pix_fmt = PIX_FMT_MONOWHITE;
+ break;
case 4:
case 8:
avctx->pix_fmt = PIX_FMT_PAL8;
@@ -65,6 +68,7 @@ static av_cold int msrle_decode_init(AVCodecContext *avctx)
return -1;
}
+ avcodec_get_frame_defaults(&s->frame);
s->frame.data[0] = NULL;
return 0;
@@ -89,7 +93,7 @@ static int msrle_decode_frame(AVCodecContext *avctx,
return -1;
}
- if (avctx->bits_per_coded_sample <= 8) {
+ if (avctx->bits_per_coded_sample > 1 && avctx->bits_per_coded_sample <= 8) {
const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL);
if (pal) {
@@ -103,7 +107,7 @@ static int msrle_decode_frame(AVCodecContext *avctx,
/* FIXME how to correctly detect RLE ??? */
if (avctx->height * istride == avpkt->size) { /* assume uncompressed */
- int linesize = avctx->width * avctx->bits_per_coded_sample / 8;
+ int linesize = (avctx->width * avctx->bits_per_coded_sample + 7) / 8;
uint8_t *ptr = s->frame.data[0];
uint8_t *buf = avpkt->data + (avctx->height-1)*istride;
int i, j;
@@ -145,14 +149,13 @@ static av_cold int msrle_decode_end(AVCodecContext *avctx)
}
AVCodec ff_msrle_decoder = {
- "msrle",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_MSRLE,
- sizeof(MsrleContext),
- msrle_decode_init,
- NULL,
- msrle_decode_end,
- msrle_decode_frame,
- CODEC_CAP_DR1,
+ .name = "msrle",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_MSRLE,
+ .priv_data_size = sizeof(MsrleContext),
+ .init = msrle_decode_init,
+ .close = msrle_decode_end,
+ .decode = msrle_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name= NULL_IF_CONFIG_SMALL("Microsoft RLE"),
};
diff --git a/libavcodec/msrledec.c b/libavcodec/msrledec.c
index 46cd50dcbc..97510830d5 100644
--- a/libavcodec/msrledec.c
+++ b/libavcodec/msrledec.c
@@ -2,20 +2,20 @@
* Microsoft RLE decoder
* Copyright (C) 2008 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/msrledec.h b/libavcodec/msrledec.h
index 5bde35a1a2..2230162691 100644
--- a/libavcodec/msrledec.h
+++ b/libavcodec/msrledec.h
@@ -2,20 +2,20 @@
* Microsoft RLE decoder
* Copyright (C) 2008 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/msvideo1.c b/libavcodec/msvideo1.c
index a89ec6ac65..570c6282e0 100644
--- a/libavcodec/msvideo1.c
+++ b/libavcodec/msvideo1.c
@@ -2,20 +2,20 @@
* Microsoft Video-1 Decoder
* Copyright (C) 2003 the ffmpeg project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -70,6 +70,7 @@ static av_cold int msvideo1_decode_init(AVCodecContext *avctx)
avctx->pix_fmt = PIX_FMT_RGB555;
}
+ avcodec_get_frame_defaults(&s->frame);
s->frame.data[0] = NULL;
return 0;
@@ -334,14 +335,13 @@ static av_cold int msvideo1_decode_end(AVCodecContext *avctx)
}
AVCodec ff_msvideo1_decoder = {
- "msvideo1",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_MSVIDEO1,
- sizeof(Msvideo1Context),
- msvideo1_decode_init,
- NULL,
- msvideo1_decode_end,
- msvideo1_decode_frame,
- CODEC_CAP_DR1,
+ .name = "msvideo1",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_MSVIDEO1,
+ .priv_data_size = sizeof(Msvideo1Context),
+ .init = msvideo1_decode_init,
+ .close = msvideo1_decode_end,
+ .decode = msvideo1_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name= NULL_IF_CONFIG_SMALL("Microsoft Video 1"),
};
diff --git a/libavcodec/msvideo1enc.c b/libavcodec/msvideo1enc.c
new file mode 100644
index 0000000000..837fca5ea4
--- /dev/null
+++ b/libavcodec/msvideo1enc.c
@@ -0,0 +1,298 @@
+/*
+ * Microsoft Video-1 Encoder
+ * Copyright (c) 2009 Konstantin Shishkov
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * Microsoft Video-1 encoder
+ */
+
+#include "avcodec.h"
+#include "bytestream.h"
+#include "libavutil/lfg.h"
+#include "elbg.h"
+#include "libavutil/imgutils.h"
+/**
+ * Encoder context
+ */
+typedef struct Msvideo1EncContext {
+ AVCodecContext *avctx;
+ AVFrame pic;
+ AVLFG rnd;
+ uint8_t *prev;
+
+ int block[16*3];
+ int block2[16*3];
+ int codebook[8*3];
+ int codebook2[8*3];
+ int output[16*3];
+ int output2[16*3];
+ int avg[3];
+ int bestpos;
+ int keyint;
+} Msvideo1EncContext;
+
+enum MSV1Mode{
+ MODE_SKIP = 0,
+ MODE_FILL,
+ MODE_2COL,
+ MODE_8COL,
+};
+
+#define SKIP_PREFIX 0x8400
+#define SKIPS_MAX 0x0FFF
+#define MKRGB555(in, off) ((in[off] << 10) | (in[off + 1] << 5) | (in[off + 2]))
+
+static const int remap[16] = { 0, 1, 4, 5, 2, 3, 6, 7, 8, 9, 12, 13, 10, 11, 14, 15 };
+
+static int encode_frame(AVCodecContext *avctx, uint8_t *buf, int buf_size, void *data)
+{
+ Msvideo1EncContext * const c = avctx->priv_data;
+ AVFrame *pict = data;
+ AVFrame * const p = &c->pic;
+ uint16_t *src;
+ uint8_t *prevptr;
+ uint8_t *dst = buf;
+ int keyframe = 1;
+ int no_skips = 1;
+ int i, j, k, x, y;
+ int skips = 0;
+
+ *p = *pict;
+ if(!c->prev)
+ c->prev = av_malloc(avctx->width * 3 * (avctx->height + 3));
+ prevptr = c->prev + avctx->width * 3 * (FFALIGN(avctx->height, 4) - 1);
+ src = (uint16_t*)(p->data[0] + p->linesize[0]*(FFALIGN(avctx->height, 4) - 1));
+ if(c->keyint >= avctx->keyint_min)
+ keyframe = 1;
+
+ p->quality = 24;
+
+ for(y = 0; y < avctx->height; y += 4){
+ for(x = 0; x < avctx->width; x += 4){
+ int bestmode = MODE_SKIP;
+ int bestscore = INT_MAX;
+ int flags = 0;
+ int score;
+
+ for(j = 0; j < 4; j++){
+ for(i = 0; i < 4; i++){
+ uint16_t val = src[x + i - j*p->linesize[0]/2];
+ for(k = 0; k < 3; k++){
+ c->block[(i + j*4)*3 + k] =
+ c->block2[remap[i + j*4]*3 + k] = (val >> (10-k*5)) & 0x1F;
+ }
+ }
+ }
+ if(!keyframe){
+ bestscore = 0;
+ for(j = 0; j < 4; j++){
+ for(i = 0; i < 4*3; i++){
+ int t = prevptr[x*3 + i + j*p->linesize[0]] - c->block[i + j*4*3];
+ bestscore += t*t;
+ }
+ }
+ bestscore /= p->quality;
+ }
+ // try to find optimal value to fill whole 4x4 block
+ score = 0;
+ ff_init_elbg(c->block, 3, 16, c->avg, 1, 1, c->output, &c->rnd);
+ ff_do_elbg (c->block, 3, 16, c->avg, 1, 1, c->output, &c->rnd);
+ if(c->avg[0] == 1) // red component = 1 will be written as skip code
+ c->avg[0] = 0;
+ for(j = 0; j < 4; j++){
+ for(i = 0; i < 4; i++){
+ for(k = 0; k < 3; k++){
+ int t = c->avg[k] - c->block[(i+j*4)*3+k];
+ score += t*t;
+ }
+ }
+ }
+ score /= p->quality;
+ score += 2;
+ if(score < bestscore){
+ bestscore = score;
+ bestmode = MODE_FILL;
+ }
+ // search for optimal filling of 2-color block
+ score = 0;
+ ff_init_elbg(c->block, 3, 16, c->codebook, 2, 1, c->output, &c->rnd);
+ ff_do_elbg (c->block, 3, 16, c->codebook, 2, 1, c->output, &c->rnd);
+ // last output value should be always 1, swap codebooks if needed
+ if(!c->output[15]){
+ for(i = 0; i < 3; i++)
+ FFSWAP(uint8_t, c->codebook[i], c->codebook[i+3]);
+ for(i = 0; i < 16; i++)
+ c->output[i] ^= 1;
+ }
+ for(j = 0; j < 4; j++){
+ for(i = 0; i < 4; i++){
+ for(k = 0; k < 3; k++){
+ int t = c->codebook[c->output[i+j*4]*3 + k] - c->block[i*3+k+j*4*3];
+ score += t*t;
+ }
+ }
+ }
+ score /= p->quality;
+ score += 6;
+ if(score < bestscore){
+ bestscore = score;
+ bestmode = MODE_2COL;
+ }
+ // search for optimal filling of 2-color 2x2 subblocks
+ score = 0;
+ for(i = 0; i < 4; i++){
+ ff_init_elbg(c->block2 + i*4*3, 3, 4, c->codebook2 + i*2*3, 2, 1, c->output2 + i*4, &c->rnd);
+ ff_do_elbg (c->block2 + i*4*3, 3, 4, c->codebook2 + i*2*3, 2, 1, c->output2 + i*4, &c->rnd);
+ }
+ // last value should be always 1, swap codebooks if needed
+ if(!c->output2[15]){
+ for(i = 0; i < 3; i++)
+ FFSWAP(uint8_t, c->codebook2[i+18], c->codebook2[i+21]);
+ for(i = 12; i < 16; i++)
+ c->output2[i] ^= 1;
+ }
+ for(j = 0; j < 4; j++){
+ for(i = 0; i < 4; i++){
+ for(k = 0; k < 3; k++){
+ int t = c->codebook2[(c->output2[remap[i+j*4]] + (i&2) + (j&2)*2)*3+k] - c->block[i*3+k + j*4*3];
+ score += t*t;
+ }
+ }
+ }
+ score /= p->quality;
+ score += 18;
+ if(score < bestscore){
+ bestscore = score;
+ bestmode = MODE_8COL;
+ }
+
+ if(bestmode == MODE_SKIP){
+ skips++;
+ no_skips = 0;
+ }
+ if((bestmode != MODE_SKIP && skips) || skips == SKIPS_MAX){
+ bytestream_put_le16(&dst, skips | SKIP_PREFIX);
+ skips = 0;
+ }
+
+ switch(bestmode){
+ case MODE_FILL:
+ bytestream_put_le16(&dst, MKRGB555(c->avg,0) | 0x8000);
+ for(j = 0; j < 4; j++)
+ for(i = 0; i < 4; i++)
+ for(k = 0; k < 3; k++)
+ prevptr[i*3 + k - j*3*avctx->width] = c->avg[k];
+ break;
+ case MODE_2COL:
+ for(j = 0; j < 4; j++){
+ for(i = 0; i < 4; i++){
+ flags |= (c->output[i + j*4]^1) << (i + j*4);
+ for(k = 0; k < 3; k++)
+ prevptr[i*3 + k - j*3*avctx->width] = c->codebook[c->output[i + j*4]*3 + k];
+ }
+ }
+ bytestream_put_le16(&dst, flags);
+ bytestream_put_le16(&dst, MKRGB555(c->codebook, 0));
+ bytestream_put_le16(&dst, MKRGB555(c->codebook, 3));
+ break;
+ case MODE_8COL:
+ for(j = 0; j < 4; j++){
+ for(i = 0; i < 4; i++){
+ flags |= (c->output2[remap[i + j*4]]^1) << (i + j*4);
+ for(k = 0; k < 3; k++)
+ prevptr[i*3 + k - j*3*avctx->width] = c->codebook2[(c->output2[remap[i+j*4]] + (i&2) + (j&2)*2)*3 + k];
+ }
+ }
+ bytestream_put_le16(&dst, flags);
+ bytestream_put_le16(&dst, MKRGB555(c->codebook2, 0) | 0x8000);
+ for(i = 3; i < 24; i += 3)
+ bytestream_put_le16(&dst, MKRGB555(c->codebook2, i));
+ break;
+ }
+ }
+ src -= p->linesize[0] << 1;
+ prevptr -= avctx->width * 3 * 4;
+ }
+ if(skips)
+ bytestream_put_le16(&dst, skips | SKIP_PREFIX);
+ //EOF
+ bytestream_put_byte(&dst, 0);
+ bytestream_put_byte(&dst, 0);
+
+ if(no_skips)
+ keyframe = 1;
+ if(keyframe)
+ c->keyint = 0;
+ else
+ c->keyint++;
+ p->pict_type= keyframe ? FF_I_TYPE : FF_P_TYPE;
+ p->key_frame= keyframe;
+
+ return dst - buf;
+}
+
+
+/**
+ * init encoder
+ */
+static av_cold int encode_init(AVCodecContext *avctx)
+{
+ Msvideo1EncContext * const c = avctx->priv_data;
+
+ c->avctx = avctx;
+ if (av_image_check_size(avctx->width, avctx->height, 0, avctx) < 0) {
+ return -1;
+ }
+
+ avcodec_get_frame_defaults(&c->pic);
+ avctx->coded_frame = (AVFrame*)&c->pic;
+
+ c->keyint = avctx->keyint_min;
+ av_lfg_init(&c->rnd, 1);
+
+ return 0;
+}
+
+
+
+/**
+ * Uninit encoder
+ */
+static av_cold int encode_end(AVCodecContext *avctx)
+{
+ Msvideo1EncContext * const c = avctx->priv_data;
+
+ av_freep(&c->prev);
+
+ return 0;
+}
+
+AVCodec ff_msvideo1_encoder = {
+ "msvideo1",
+ AVMEDIA_TYPE_VIDEO,
+ CODEC_ID_MSVIDEO1,
+ sizeof(Msvideo1EncContext),
+ encode_init,
+ encode_frame,
+ encode_end,
+ .pix_fmts = (const enum PixelFormat[]){PIX_FMT_RGB555, PIX_FMT_NONE},
+ .long_name = NULL_IF_CONFIG_SMALL("Microsoft Video-1"),
+};
diff --git a/libavcodec/mxpegdec.c b/libavcodec/mxpegdec.c
index e710291501..609440650b 100644
--- a/libavcodec/mxpegdec.c
+++ b/libavcodec/mxpegdec.c
@@ -2,20 +2,20 @@
* MxPEG decoder
* Copyright (c) 2011 Anatoly Nenashev
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -47,9 +47,7 @@ static av_cold int mxpeg_decode_init(AVCodecContext *avctx)
s->picture[0].reference = s->picture[1].reference = 3;
s->jpg.picture_ptr = &s->picture[0];
- ff_mjpeg_decode_init(avctx);
-
- return 0;
+ return ff_mjpeg_decode_init(avctx);
}
static int mxpeg_decode_app(MXpegDecodeContext *s,
@@ -82,6 +80,7 @@ static int mxpeg_decode_mxm(MXpegDecodeContext *s,
}
if (s->bitmask_size != bitmask_size) {
+ s->bitmask_size = 0;
av_freep(&s->mxm_bitmask);
s->mxm_bitmask = av_malloc(bitmask_size);
if (!s->mxm_bitmask) {
@@ -275,9 +274,13 @@ static int mxpeg_decode_frame(AVCodecContext *avctx,
return AVERROR(ENOMEM);
}
- ff_mjpeg_decode_sos(jpg, s->mxm_bitmask, reference_ptr);
+ ret = ff_mjpeg_decode_sos(jpg, s->mxm_bitmask, reference_ptr);
+ if (ret < 0 && avctx->error_recognition >= FF_ER_EXPLODE)
+ return ret;
} else {
- ff_mjpeg_decode_sos(jpg, NULL, NULL);
+ ret = ff_mjpeg_decode_sos(jpg, NULL, NULL);
+ if (ret < 0 && avctx->error_recognition >= FF_ER_EXPLODE)
+ return ret;
}
break;
diff --git a/libavcodec/nellymoserdec.c b/libavcodec/nellymoserdec.c
index 59c1b3bdd8..04d966173a 100644
--- a/libavcodec/nellymoserdec.c
+++ b/libavcodec/nellymoserdec.c
@@ -47,8 +47,8 @@
typedef struct NellyMoserDecodeContext {
AVCodecContext* avctx;
- DECLARE_ALIGNED(32, float, float_buf)[NELLY_SAMPLES];
- float state[128];
+ float *float_buf;
+ float state[NELLY_BUF_LEN];
AVLFG random_state;
GetBitContext gb;
float scale_bias;
@@ -137,15 +137,25 @@ static av_cold int decode_init(AVCodecContext * avctx) {
ff_mdct_init(&s->imdct_ctx, 8, 1, 1.0);
dsputil_init(&s->dsp, avctx);
- ff_fmt_convert_init(&s->fmt_conv, avctx);
- s->scale_bias = 1.0/(1*8);
+ if (avctx->request_sample_fmt == AV_SAMPLE_FMT_FLT) {
+ s->scale_bias = 1.0/(32768*8);
+ avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
+ } else {
+ s->scale_bias = 1.0/(1*8);
+ avctx->sample_fmt = AV_SAMPLE_FMT_S16;
+ ff_fmt_convert_init(&s->fmt_conv, avctx);
+ s->float_buf = av_mallocz(NELLY_SAMPLES * sizeof(*s->float_buf));
+ if (!s->float_buf) {
+ av_log(avctx, AV_LOG_ERROR, "error allocating float buffer\n");
+ return AVERROR(ENOMEM);
+ }
+ }
/* Generate overlap window */
if (!ff_sine_128[127])
ff_init_ff_sine_windows(7);
- avctx->sample_fmt = AV_SAMPLE_FMT_S16;
avctx->channel_layout = AV_CH_LAYOUT_MONO;
return 0;
}
@@ -156,19 +166,26 @@ static int decode_tag(AVCodecContext * avctx,
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
NellyMoserDecodeContext *s = avctx->priv_data;
- int blocks, i;
- int16_t* samples;
+ int data_max = *data_size;
+ int blocks, i, block_size;
+ int16_t *samples_s16 = data;
+ float *samples_flt = data;
*data_size = 0;
- samples = (int16_t*)data;
- if (buf_size < avctx->block_align)
+ if (buf_size < avctx->block_align) {
return buf_size;
+ }
- if (buf_size % 64) {
+ if (buf_size % NELLY_BLOCK_LEN) {
av_log(avctx, AV_LOG_ERROR, "Tag size %d.\n", buf_size);
return buf_size;
}
- blocks = buf_size / 64;
+ block_size = NELLY_SAMPLES * av_get_bytes_per_sample(avctx->sample_fmt);
+ blocks = FFMIN(buf_size / NELLY_BLOCK_LEN, data_max / block_size);
+ if (blocks <= 0) {
+ av_log(avctx, AV_LOG_ERROR, "Output buffer is too small\n");
+ return AVERROR(EINVAL);
+ }
/* Normal numbers of blocks for sample rates:
* 8000 Hz - 1
* 11025 Hz - 2
@@ -178,10 +195,17 @@ static int decode_tag(AVCodecContext * avctx,
*/
for (i=0 ; i<blocks ; i++) {
- nelly_decode_block(s, &buf[i*NELLY_BLOCK_LEN], s->float_buf);
- s->fmt_conv.float_to_int16(&samples[i*NELLY_SAMPLES], s->float_buf, NELLY_SAMPLES);
- *data_size += NELLY_SAMPLES*sizeof(int16_t);
+ if (avctx->sample_fmt == SAMPLE_FMT_FLT) {
+ nelly_decode_block(s, buf, samples_flt);
+ samples_flt += NELLY_SAMPLES;
+ } else {
+ nelly_decode_block(s, buf, s->float_buf);
+ s->fmt_conv.float_to_int16(samples_s16, s->float_buf, NELLY_SAMPLES);
+ samples_s16 += NELLY_SAMPLES;
+ }
+ buf += NELLY_BLOCK_LEN;
}
+ *data_size = blocks * block_size;
return buf_size;
}
@@ -189,19 +213,22 @@ static int decode_tag(AVCodecContext * avctx,
static av_cold int decode_end(AVCodecContext * avctx) {
NellyMoserDecodeContext *s = avctx->priv_data;
+ av_freep(&s->float_buf);
ff_mdct_end(&s->imdct_ctx);
return 0;
}
AVCodec ff_nellymoser_decoder = {
- "nellymoser",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_NELLYMOSER,
- sizeof(NellyMoserDecodeContext),
- decode_init,
- NULL,
- decode_end,
- decode_tag,
+ .name = "nellymoser",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_NELLYMOSER,
+ .priv_data_size = sizeof(NellyMoserDecodeContext),
+ .init = decode_init,
+ .close = decode_end,
+ .decode = decode_tag,
.long_name = NULL_IF_CONFIG_SMALL("Nellymoser Asao"),
+ .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLT,
+ AV_SAMPLE_FMT_S16,
+ AV_SAMPLE_FMT_NONE },
};
diff --git a/libavcodec/nellymoserenc.c b/libavcodec/nellymoserenc.c
index 0f94e75c92..1d35cda9a1 100644
--- a/libavcodec/nellymoserenc.c
+++ b/libavcodec/nellymoserenc.c
@@ -4,20 +4,20 @@
*
* Copyright (c) 2008 Bartlomiej Wolowiec
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -28,7 +28,7 @@
*
* Generic codec information: libavcodec/nellymoserdec.c
*
- * Some information also from: http://samples.libav.org/A-codecs/Nelly_Moser/ASAO/ASAO.zip
+ * Some information also from: http://samples.mplayerhq.hu/A-codecs/Nelly_Moser/ASAO/ASAO.zip
* (Copyright Joseph Artsimovich and UAB "DKD")
*
* for more information about nellymoser format, visit:
diff --git a/libavcodec/noise_bsf.c b/libavcodec/noise_bsf.c
index 489e3c7c7c..491fbccc1d 100644
--- a/libavcodec/noise_bsf.c
+++ b/libavcodec/noise_bsf.c
@@ -1,20 +1,20 @@
/*
* copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/nuv.c b/libavcodec/nuv.c
index 3bc6328a04..2a60fe47fc 100644
--- a/libavcodec/nuv.c
+++ b/libavcodec/nuv.c
@@ -2,20 +2,20 @@
* NuppelVideo decoder
* Copyright (c) 2006 Reimar Doeffinger
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
@@ -273,15 +273,14 @@ static av_cold int decode_end(AVCodecContext *avctx) {
}
AVCodec ff_nuv_decoder = {
- "nuv",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_NUV,
- sizeof(NuvContext),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- CODEC_CAP_DR1,
+ .name = "nuv",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_NUV,
+ .priv_data_size = sizeof(NuvContext),
+ .init = decode_init,
+ .close = decode_end,
+ .decode = decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("NuppelVideo/RTJPEG"),
};
diff --git a/libavcodec/options.c b/libavcodec/options.c
index ae9e0c902d..d494efe12b 100644
--- a/libavcodec/options.c
+++ b/libavcodec/options.c
@@ -2,20 +2,20 @@
* Copyright (c) 2001 Fabrice Bellard
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -25,6 +25,8 @@
*/
#include "avcodec.h"
+#include "internal.h"
+#include "libavutil/avassert.h"
#include "libavutil/opt.h"
#include <float.h> /* FLT_MIN, FLT_MAX */
@@ -37,22 +39,27 @@ static const char* context_to_name(void* ptr) {
return "NULL";
}
-static const AVOption *opt_find(void *obj, const char *name, const char *unit, int opt_flags, int search_flags)
+static void *codec_child_next(void *obj, void *prev)
{
AVCodecContext *s = obj;
- AVCodec *c = NULL;
+ if (!prev && s->codec && s->codec->priv_class && s->priv_data)
+ return s->priv_data;
+ return NULL;
+}
- if (s->priv_data) {
- if (s->codec->priv_class)
- return av_opt_find(s->priv_data, name, unit, opt_flags, search_flags);
- return NULL;
- }
+static const AVClass *codec_child_class_next(const AVClass *prev)
+{
+ AVCodec *c = NULL;
- while ((c = av_codec_next(c))) {
- const AVOption *o;
- if (c->priv_class && (o = av_opt_find(&c->priv_class, name, unit, opt_flags, search_flags)))
- return o;
- }
+ /* find the codec that corresponds to prev */
+ while (prev && (c = av_codec_next(c)))
+ if (c->priv_class == prev)
+ break;
+
+ /* find next codec with priv options */
+ while (c = av_codec_next(c))
+ if (c->priv_class)
+ return c->priv_class;
return NULL;
}
@@ -68,404 +75,443 @@ static const AVOption *opt_find(void *obj, const char *name, const char *unit, i
#define AV_CODEC_DEFAULT_BITRATE 200*1000
static const AVOption options[]={
-{"b", "set bitrate (in bits/s)", OFFSET(bit_rate), FF_OPT_TYPE_INT, {.dbl = AV_CODEC_DEFAULT_BITRATE }, INT_MIN, INT_MAX, V|E},
-{"ab", "set bitrate (in bits/s)", OFFSET(bit_rate), FF_OPT_TYPE_INT, {.dbl = 64*1000 }, INT_MIN, INT_MAX, A|E},
-{"bt", "set video bitrate tolerance (in bits/s)", OFFSET(bit_rate_tolerance), FF_OPT_TYPE_INT, {.dbl = AV_CODEC_DEFAULT_BITRATE*20 }, 1, INT_MAX, V|E},
-{"flags", NULL, OFFSET(flags), FF_OPT_TYPE_FLAGS, {.dbl = DEFAULT }, 0, UINT_MAX, V|A|E|D, "flags"},
-{"mv4", "use four motion vector by macroblock (mpeg4)", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_4MV }, INT_MIN, INT_MAX, V|E, "flags"},
-{"obmc", "use overlapped block motion compensation (h263+)", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_OBMC }, INT_MIN, INT_MAX, V|E, "flags"},
-{"qpel", "use 1/4 pel motion compensation", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_QPEL }, INT_MIN, INT_MAX, V|E, "flags"},
-{"loop", "use loop filter", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_LOOP_FILTER }, INT_MIN, INT_MAX, V|E, "flags"},
-{"qscale", "use fixed qscale", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_QSCALE }, INT_MIN, INT_MAX, 0, "flags"},
-{"gmc", "use gmc", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_GMC }, INT_MIN, INT_MAX, V|E, "flags"},
-{"mv0", "always try a mb with mv=<0,0>", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_MV0 }, INT_MIN, INT_MAX, V|E, "flags"},
-{"part", "use data partitioning", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_PART }, INT_MIN, INT_MAX, V|E, "flags"},
-{"input_preserved", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_INPUT_PRESERVED }, INT_MIN, INT_MAX, 0, "flags"},
-{"pass1", "use internal 2pass ratecontrol in first pass mode", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_PASS1 }, INT_MIN, INT_MAX, 0, "flags"},
-{"pass2", "use internal 2pass ratecontrol in second pass mode", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_PASS2 }, INT_MIN, INT_MAX, 0, "flags"},
-{"extern_huff", "use external huffman table (for mjpeg)", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_EXTERN_HUFF }, INT_MIN, INT_MAX, 0, "flags"},
-{"gray", "only decode/encode grayscale", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_GRAY }, INT_MIN, INT_MAX, V|E|D, "flags"},
-{"emu_edge", "don't draw edges", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_EMU_EDGE }, INT_MIN, INT_MAX, 0, "flags"},
-{"psnr", "error[?] variables will be set during encoding", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_PSNR }, INT_MIN, INT_MAX, V|E, "flags"},
-{"truncated", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_TRUNCATED }, INT_MIN, INT_MAX, 0, "flags"},
-{"naq", "normalize adaptive quantization", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_NORMALIZE_AQP }, INT_MIN, INT_MAX, V|E, "flags"},
-{"ildct", "use interlaced dct", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_INTERLACED_DCT }, INT_MIN, INT_MAX, V|E, "flags"},
-{"low_delay", "force low delay", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_LOW_DELAY }, INT_MIN, INT_MAX, V|D|E, "flags"},
-{"alt", "enable alternate scantable (mpeg2/mpeg4)", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_ALT_SCAN }, INT_MIN, INT_MAX, V|E, "flags"},
-{"global_header", "place global headers in extradata instead of every keyframe", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_GLOBAL_HEADER }, INT_MIN, INT_MAX, V|A|E, "flags"},
-{"bitexact", "use only bitexact stuff (except (i)dct)", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_BITEXACT }, INT_MIN, INT_MAX, A|V|S|D|E, "flags"},
-{"aic", "h263 advanced intra coding / mpeg4 ac prediction", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_AC_PRED }, INT_MIN, INT_MAX, V|E, "flags"},
-{"umv", "use unlimited motion vectors", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_H263P_UMV }, INT_MIN, INT_MAX, V|E, "flags"},
-{"cbp", "use rate distortion optimization for cbp", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_CBP_RD }, INT_MIN, INT_MAX, V|E, "flags"},
-{"qprd", "use rate distortion optimization for qp selection", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_QP_RD }, INT_MIN, INT_MAX, V|E, "flags"},
-{"aiv", "h263 alternative inter vlc", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_H263P_AIV }, INT_MIN, INT_MAX, V|E, "flags"},
-{"slice", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_H263P_SLICE_STRUCT }, INT_MIN, INT_MAX, V|E, "flags"},
-{"ilme", "interlaced motion estimation", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_INTERLACED_ME }, INT_MIN, INT_MAX, V|E, "flags"},
-{"scan_offset", "will reserve space for svcd scan offset user data", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_SVCD_SCAN_OFFSET }, INT_MIN, INT_MAX, V|E, "flags"},
-{"cgop", "closed gop", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_CLOSED_GOP }, INT_MIN, INT_MAX, V|E, "flags"},
-{"fast", "allow non spec compliant speedup tricks", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_FAST }, INT_MIN, INT_MAX, V|E, "flags2"},
-{"sgop", "strictly enforce gop size", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_STRICT_GOP }, INT_MIN, INT_MAX, V|E, "flags2"},
-{"noout", "skip bitstream encoding", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_NO_OUTPUT }, INT_MIN, INT_MAX, V|E, "flags2"},
-{"local_header", "place global headers at every keyframe instead of in extradata", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_LOCAL_HEADER }, INT_MIN, INT_MAX, V|E, "flags2"},
-{"sub_id", NULL, OFFSET(sub_id), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
-{"me_method", "set motion estimation method", OFFSET(me_method), FF_OPT_TYPE_INT, {.dbl = ME_EPZS }, INT_MIN, INT_MAX, V|E, "me_method"},
-{"zero", "zero motion estimation (fastest)", 0, FF_OPT_TYPE_CONST, {.dbl = ME_ZERO }, INT_MIN, INT_MAX, V|E, "me_method" },
-{"full", "full motion estimation (slowest)", 0, FF_OPT_TYPE_CONST, {.dbl = ME_FULL }, INT_MIN, INT_MAX, V|E, "me_method" },
-{"epzs", "EPZS motion estimation (default)", 0, FF_OPT_TYPE_CONST, {.dbl = ME_EPZS }, INT_MIN, INT_MAX, V|E, "me_method" },
-{"esa", "esa motion estimation (alias for full)", 0, FF_OPT_TYPE_CONST, {.dbl = ME_FULL }, INT_MIN, INT_MAX, V|E, "me_method" },
-{"tesa", "tesa motion estimation", 0, FF_OPT_TYPE_CONST, {.dbl = ME_TESA }, INT_MIN, INT_MAX, V|E, "me_method" },
-{"dia", "dia motion estimation (alias for epzs)", 0, FF_OPT_TYPE_CONST, {.dbl = ME_EPZS }, INT_MIN, INT_MAX, V|E, "me_method" },
-{"log", "log motion estimation", 0, FF_OPT_TYPE_CONST, {.dbl = ME_LOG }, INT_MIN, INT_MAX, V|E, "me_method" },
-{"phods", "phods motion estimation", 0, FF_OPT_TYPE_CONST, {.dbl = ME_PHODS }, INT_MIN, INT_MAX, V|E, "me_method" },
-{"x1", "X1 motion estimation", 0, FF_OPT_TYPE_CONST, {.dbl = ME_X1 }, INT_MIN, INT_MAX, V|E, "me_method" },
-{"hex", "hex motion estimation", 0, FF_OPT_TYPE_CONST, {.dbl = ME_HEX }, INT_MIN, INT_MAX, V|E, "me_method" },
-{"umh", "umh motion estimation", 0, FF_OPT_TYPE_CONST, {.dbl = ME_UMH }, INT_MIN, INT_MAX, V|E, "me_method" },
-{"iter", "iter motion estimation", 0, FF_OPT_TYPE_CONST, {.dbl = ME_ITER }, INT_MIN, INT_MAX, V|E, "me_method" },
-{"extradata_size", NULL, OFFSET(extradata_size), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
-{"time_base", NULL, OFFSET(time_base), FF_OPT_TYPE_RATIONAL, {.dbl = 0}, INT_MIN, INT_MAX},
-{"g", "set the group of picture size", OFFSET(gop_size), FF_OPT_TYPE_INT, {.dbl = 12 }, INT_MIN, INT_MAX, V|E},
-{"ar", "set audio sampling rate (in Hz)", OFFSET(sample_rate), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
-{"ac", "set number of audio channels", OFFSET(channels), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
-{"cutoff", "set cutoff bandwidth", OFFSET(cutoff), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, A|E},
-{"frame_size", NULL, OFFSET(frame_size), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, A|E},
-{"frame_number", NULL, OFFSET(frame_number), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
-{"delay", NULL, OFFSET(delay), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
-{"qcomp", "video quantizer scale compression (VBR)", OFFSET(qcompress), FF_OPT_TYPE_FLOAT, {.dbl = 0.5 }, -FLT_MAX, FLT_MAX, V|E},
-{"qblur", "video quantizer scale blur (VBR)", OFFSET(qblur), FF_OPT_TYPE_FLOAT, {.dbl = 0.5 }, 0, FLT_MAX, V|E},
-{"qmin", "min video quantizer scale (VBR)", OFFSET(qmin), FF_OPT_TYPE_INT, {.dbl = 2 }, 0, 69, V|E},
-{"qmax", "max video quantizer scale (VBR)", OFFSET(qmax), FF_OPT_TYPE_INT, {.dbl = 31 }, 0, 69, V|E},
-{"qdiff", "max difference between the quantizer scale (VBR)", OFFSET(max_qdiff), FF_OPT_TYPE_INT, {.dbl = 3 }, INT_MIN, INT_MAX, V|E},
-{"bf", "use 'frames' B frames", OFFSET(max_b_frames), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, FF_MAX_B_FRAMES, V|E},
-{"b_qfactor", "qp factor between p and b frames", OFFSET(b_quant_factor), FF_OPT_TYPE_FLOAT, {.dbl = 1.25 }, -FLT_MAX, FLT_MAX, V|E},
-{"rc_strategy", "ratecontrol method", OFFSET(rc_strategy), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
-{"b_strategy", "strategy to choose between I/P/B-frames", OFFSET(b_frame_strategy), FF_OPT_TYPE_INT, {.dbl = 0 }, INT_MIN, INT_MAX, V|E},
-{"wpredp", "weighted prediction analysis method", OFFSET(weighted_p_pred), FF_OPT_TYPE_INT, {.dbl = 0 }, INT_MIN, INT_MAX, V|E},
-{"ps", "rtp payload size in bytes", OFFSET(rtp_payload_size), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
-{"mv_bits", NULL, OFFSET(mv_bits), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
-{"header_bits", NULL, OFFSET(header_bits), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
-{"i_tex_bits", NULL, OFFSET(i_tex_bits), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
-{"p_tex_bits", NULL, OFFSET(p_tex_bits), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
-{"i_count", NULL, OFFSET(i_count), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
-{"p_count", NULL, OFFSET(p_count), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
-{"skip_count", NULL, OFFSET(skip_count), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
-{"misc_bits", NULL, OFFSET(misc_bits), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
-{"frame_bits", NULL, OFFSET(frame_bits), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
-{"codec_tag", NULL, OFFSET(codec_tag), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
-{"bug", "workaround not auto detected encoder bugs", OFFSET(workaround_bugs), FF_OPT_TYPE_FLAGS, {.dbl = FF_BUG_AUTODETECT }, INT_MIN, INT_MAX, V|D, "bug"},
-{"autodetect", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_BUG_AUTODETECT }, INT_MIN, INT_MAX, V|D, "bug"},
-{"old_msmpeg4", "some old lavc generated msmpeg4v3 files (no autodetection)", 0, FF_OPT_TYPE_CONST, {.dbl = FF_BUG_OLD_MSMPEG4 }, INT_MIN, INT_MAX, V|D, "bug"},
-{"xvid_ilace", "Xvid interlacing bug (autodetected if fourcc==XVIX)", 0, FF_OPT_TYPE_CONST, {.dbl = FF_BUG_XVID_ILACE }, INT_MIN, INT_MAX, V|D, "bug"},
-{"ump4", "(autodetected if fourcc==UMP4)", 0, FF_OPT_TYPE_CONST, {.dbl = FF_BUG_UMP4 }, INT_MIN, INT_MAX, V|D, "bug"},
-{"no_padding", "padding bug (autodetected)", 0, FF_OPT_TYPE_CONST, {.dbl = FF_BUG_NO_PADDING }, INT_MIN, INT_MAX, V|D, "bug"},
-{"amv", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_BUG_AMV }, INT_MIN, INT_MAX, V|D, "bug"},
-{"ac_vlc", "illegal vlc bug (autodetected per fourcc)", 0, FF_OPT_TYPE_CONST, {.dbl = FF_BUG_AC_VLC }, INT_MIN, INT_MAX, V|D, "bug"},
-{"qpel_chroma", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_BUG_QPEL_CHROMA }, INT_MIN, INT_MAX, V|D, "bug"},
-{"std_qpel", "old standard qpel (autodetected per fourcc/version)", 0, FF_OPT_TYPE_CONST, {.dbl = FF_BUG_STD_QPEL }, INT_MIN, INT_MAX, V|D, "bug"},
-{"qpel_chroma2", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_BUG_QPEL_CHROMA2 }, INT_MIN, INT_MAX, V|D, "bug"},
-{"direct_blocksize", "direct-qpel-blocksize bug (autodetected per fourcc/version)", 0, FF_OPT_TYPE_CONST, {.dbl = FF_BUG_DIRECT_BLOCKSIZE }, INT_MIN, INT_MAX, V|D, "bug"},
-{"edge", "edge padding bug (autodetected per fourcc/version)", 0, FF_OPT_TYPE_CONST, {.dbl = FF_BUG_EDGE }, INT_MIN, INT_MAX, V|D, "bug"},
-{"hpel_chroma", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_BUG_HPEL_CHROMA }, INT_MIN, INT_MAX, V|D, "bug"},
-{"dc_clip", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_BUG_DC_CLIP }, INT_MIN, INT_MAX, V|D, "bug"},
-{"ms", "workaround various bugs in microsofts broken decoders", 0, FF_OPT_TYPE_CONST, {.dbl = FF_BUG_MS }, INT_MIN, INT_MAX, V|D, "bug"},
-{"trunc", "trancated frames", 0, FF_OPT_TYPE_CONST, {.dbl = FF_BUG_TRUNCATED}, INT_MIN, INT_MAX, V|D, "bug"},
-{"lelim", "single coefficient elimination threshold for luminance (negative values also consider dc coefficient)", OFFSET(luma_elim_threshold), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
-{"celim", "single coefficient elimination threshold for chrominance (negative values also consider dc coefficient)", OFFSET(chroma_elim_threshold), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
-{"strict", "how strictly to follow the standards", OFFSET(strict_std_compliance), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, A|V|D|E, "strict"},
-{"very", "strictly conform to a older more strict version of the spec or reference software", 0, FF_OPT_TYPE_CONST, {.dbl = FF_COMPLIANCE_VERY_STRICT }, INT_MIN, INT_MAX, V|D|E, "strict"},
-{"strict", "strictly conform to all the things in the spec no matter what consequences", 0, FF_OPT_TYPE_CONST, {.dbl = FF_COMPLIANCE_STRICT }, INT_MIN, INT_MAX, V|D|E, "strict"},
-{"normal", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_COMPLIANCE_NORMAL }, INT_MIN, INT_MAX, V|D|E, "strict"},
-{"unofficial", "allow unofficial extensions", 0, FF_OPT_TYPE_CONST, {.dbl = FF_COMPLIANCE_UNOFFICIAL }, INT_MIN, INT_MAX, V|D|E, "strict"},
-{"experimental", "allow non standardized experimental things", 0, FF_OPT_TYPE_CONST, {.dbl = FF_COMPLIANCE_EXPERIMENTAL }, INT_MIN, INT_MAX, V|D|E, "strict"},
-{"b_qoffset", "qp offset between P and B frames", OFFSET(b_quant_offset), FF_OPT_TYPE_FLOAT, {.dbl = 1.25 }, -FLT_MAX, FLT_MAX, V|E},
-{"er", "set error detection aggressivity", OFFSET(error_recognition), FF_OPT_TYPE_INT, {.dbl = FF_ER_CAREFUL }, INT_MIN, INT_MAX, A|V|D, "er"},
-{"careful", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_ER_CAREFUL }, INT_MIN, INT_MAX, V|D, "er"},
-{"compliant", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_ER_COMPLIANT }, INT_MIN, INT_MAX, V|D, "er"},
-{"aggressive", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_ER_AGGRESSIVE }, INT_MIN, INT_MAX, V|D, "er"},
-{"very_aggressive", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_ER_VERY_AGGRESSIVE }, INT_MIN, INT_MAX, V|D, "er"},
-{"has_b_frames", NULL, OFFSET(has_b_frames), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
-{"block_align", NULL, OFFSET(block_align), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
-{"parse_only", NULL, OFFSET(parse_only), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
-{"mpeg_quant", "use MPEG quantizers instead of H.263", OFFSET(mpeg_quant), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
-{"stats_out", NULL, OFFSET(stats_out), FF_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX},
-{"stats_in", NULL, OFFSET(stats_in), FF_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX},
-{"qsquish", "how to keep quantizer between qmin and qmax (0 = clip, 1 = use differentiable function)", OFFSET(rc_qsquish), FF_OPT_TYPE_FLOAT, {.dbl = DEFAULT }, 0, 99, V|E},
-{"rc_qmod_amp", "experimental quantizer modulation", OFFSET(rc_qmod_amp), FF_OPT_TYPE_FLOAT, {.dbl = DEFAULT }, -FLT_MAX, FLT_MAX, V|E},
-{"rc_qmod_freq", "experimental quantizer modulation", OFFSET(rc_qmod_freq), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
-{"rc_override_count", NULL, OFFSET(rc_override_count), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
-{"rc_eq", "set rate control equation", OFFSET(rc_eq), FF_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, V|E},
-{"maxrate", "set max video bitrate tolerance (in bits/s)", OFFSET(rc_max_rate), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
-{"minrate", "set min video bitrate tolerance (in bits/s)", OFFSET(rc_min_rate), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
-{"bufsize", "set ratecontrol buffer size (in bits)", OFFSET(rc_buffer_size), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, A|V|E},
-{"rc_buf_aggressivity", "currently useless", OFFSET(rc_buffer_aggressivity), FF_OPT_TYPE_FLOAT, {.dbl = 1.0 }, -FLT_MAX, FLT_MAX, V|E},
-{"i_qfactor", "qp factor between P and I frames", OFFSET(i_quant_factor), FF_OPT_TYPE_FLOAT, {.dbl = -0.8 }, -FLT_MAX, FLT_MAX, V|E},
-{"i_qoffset", "qp offset between P and I frames", OFFSET(i_quant_offset), FF_OPT_TYPE_FLOAT, {.dbl = 0.0 }, -FLT_MAX, FLT_MAX, V|E},
-{"rc_init_cplx", "initial complexity for 1-pass encoding", OFFSET(rc_initial_cplx), FF_OPT_TYPE_FLOAT, {.dbl = DEFAULT }, -FLT_MAX, FLT_MAX, V|E},
-{"dct", "DCT algorithm", OFFSET(dct_algo), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, INT_MAX, V|E, "dct"},
-{"auto", "autoselect a good one (default)", 0, FF_OPT_TYPE_CONST, {.dbl = FF_DCT_AUTO }, INT_MIN, INT_MAX, V|E, "dct"},
-{"fastint", "fast integer", 0, FF_OPT_TYPE_CONST, {.dbl = FF_DCT_FASTINT }, INT_MIN, INT_MAX, V|E, "dct"},
-{"int", "accurate integer", 0, FF_OPT_TYPE_CONST, {.dbl = FF_DCT_INT }, INT_MIN, INT_MAX, V|E, "dct"},
-{"mmx", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_DCT_MMX }, INT_MIN, INT_MAX, V|E, "dct"},
-{"mlib", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_DCT_MLIB }, INT_MIN, INT_MAX, V|E, "dct"},
-{"altivec", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_DCT_ALTIVEC }, INT_MIN, INT_MAX, V|E, "dct"},
-{"faan", "floating point AAN DCT", 0, FF_OPT_TYPE_CONST, {.dbl = FF_DCT_FAAN }, INT_MIN, INT_MAX, V|E, "dct"},
-{"lumi_mask", "compresses bright areas stronger than medium ones", OFFSET(lumi_masking), FF_OPT_TYPE_FLOAT, {.dbl = 0 }, -FLT_MAX, FLT_MAX, V|E},
-{"tcplx_mask", "temporal complexity masking", OFFSET(temporal_cplx_masking), FF_OPT_TYPE_FLOAT, {.dbl = 0 }, -FLT_MAX, FLT_MAX, V|E},
-{"scplx_mask", "spatial complexity masking", OFFSET(spatial_cplx_masking), FF_OPT_TYPE_FLOAT, {.dbl = 0 }, -FLT_MAX, FLT_MAX, V|E},
-{"p_mask", "inter masking", OFFSET(p_masking), FF_OPT_TYPE_FLOAT, {.dbl = 0 }, -FLT_MAX, FLT_MAX, V|E},
-{"dark_mask", "compresses dark areas stronger than medium ones", OFFSET(dark_masking), FF_OPT_TYPE_FLOAT, {.dbl = 0 }, -FLT_MAX, FLT_MAX, V|E},
-{"idct", "select IDCT implementation", OFFSET(idct_algo), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, INT_MAX, V|E|D, "idct"},
-{"auto", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_IDCT_AUTO }, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"int", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_IDCT_INT }, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"simple", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_IDCT_SIMPLE }, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"simplemmx", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_IDCT_SIMPLEMMX }, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"libmpeg2mmx", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_IDCT_LIBMPEG2MMX }, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"ps2", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_IDCT_PS2 }, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"mlib", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_IDCT_MLIB }, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"arm", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_IDCT_ARM }, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"altivec", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_IDCT_ALTIVEC }, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"sh4", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_IDCT_SH4 }, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"simplearm", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_IDCT_SIMPLEARM }, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"simplearmv5te", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_IDCT_SIMPLEARMV5TE }, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"simplearmv6", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_IDCT_SIMPLEARMV6 }, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"simpleneon", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_IDCT_SIMPLENEON }, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"simplealpha", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_IDCT_SIMPLEALPHA }, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"h264", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_IDCT_H264 }, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"vp3", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_IDCT_VP3 }, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"ipp", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_IDCT_IPP }, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"xvidmmx", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_IDCT_XVIDMMX }, INT_MIN, INT_MAX, V|E|D, "idct"},
-{"faani", "floating point AAN IDCT", 0, FF_OPT_TYPE_CONST, {.dbl = FF_IDCT_FAAN }, INT_MIN, INT_MAX, V|D|E, "idct"},
-{"slice_count", NULL, OFFSET(slice_count), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
-{"ec", "set error concealment strategy", OFFSET(error_concealment), FF_OPT_TYPE_FLAGS, {.dbl = 3 }, INT_MIN, INT_MAX, V|D, "ec"},
-{"guess_mvs", "iterative motion vector (MV) search (slow)", 0, FF_OPT_TYPE_CONST, {.dbl = FF_EC_GUESS_MVS }, INT_MIN, INT_MAX, V|D, "ec"},
-{"deblock", "use strong deblock filter for damaged MBs", 0, FF_OPT_TYPE_CONST, {.dbl = FF_EC_DEBLOCK }, INT_MIN, INT_MAX, V|D, "ec"},
-{"bits_per_coded_sample", NULL, OFFSET(bits_per_coded_sample), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
-{"pred", "prediction method", OFFSET(prediction_method), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E, "pred"},
-{"left", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_PRED_LEFT }, INT_MIN, INT_MAX, V|E, "pred"},
-{"plane", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_PRED_PLANE }, INT_MIN, INT_MAX, V|E, "pred"},
-{"median", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_PRED_MEDIAN }, INT_MIN, INT_MAX, V|E, "pred"},
-{"aspect", "sample aspect ratio", OFFSET(sample_aspect_ratio), FF_OPT_TYPE_RATIONAL, {.dbl = 0}, 0, 10, V|E},
-{"debug", "print specific debug info", OFFSET(debug), FF_OPT_TYPE_FLAGS, {.dbl = DEFAULT }, 0, INT_MAX, V|A|S|E|D, "debug"},
-{"pict", "picture info", 0, FF_OPT_TYPE_CONST, {.dbl = FF_DEBUG_PICT_INFO }, INT_MIN, INT_MAX, V|D, "debug"},
-{"rc", "rate control", 0, FF_OPT_TYPE_CONST, {.dbl = FF_DEBUG_RC }, INT_MIN, INT_MAX, V|E, "debug"},
-{"bitstream", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_DEBUG_BITSTREAM }, INT_MIN, INT_MAX, V|D, "debug"},
-{"mb_type", "macroblock (MB) type", 0, FF_OPT_TYPE_CONST, {.dbl = FF_DEBUG_MB_TYPE }, INT_MIN, INT_MAX, V|D, "debug"},
-{"qp", "per-block quantization parameter (QP)", 0, FF_OPT_TYPE_CONST, {.dbl = FF_DEBUG_QP }, INT_MIN, INT_MAX, V|D, "debug"},
-{"mv", "motion vector", 0, FF_OPT_TYPE_CONST, {.dbl = FF_DEBUG_MV }, INT_MIN, INT_MAX, V|D, "debug"},
-{"dct_coeff", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_DEBUG_DCT_COEFF }, INT_MIN, INT_MAX, V|D, "debug"},
-{"skip", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_DEBUG_SKIP }, INT_MIN, INT_MAX, V|D, "debug"},
-{"startcode", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_DEBUG_STARTCODE }, INT_MIN, INT_MAX, V|D, "debug"},
-{"pts", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_DEBUG_PTS }, INT_MIN, INT_MAX, V|D, "debug"},
-{"er", "error recognition", 0, FF_OPT_TYPE_CONST, {.dbl = FF_DEBUG_ER }, INT_MIN, INT_MAX, V|D, "debug"},
-{"mmco", "memory management control operations (H.264)", 0, FF_OPT_TYPE_CONST, {.dbl = FF_DEBUG_MMCO }, INT_MIN, INT_MAX, V|D, "debug"},
-{"bugs", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_DEBUG_BUGS }, INT_MIN, INT_MAX, V|D, "debug"},
-{"vis_qp", "visualize quantization parameter (QP), lower QP are tinted greener", 0, FF_OPT_TYPE_CONST, {.dbl = FF_DEBUG_VIS_QP }, INT_MIN, INT_MAX, V|D, "debug"},
-{"vis_mb_type", "visualize block types", 0, FF_OPT_TYPE_CONST, {.dbl = FF_DEBUG_VIS_MB_TYPE }, INT_MIN, INT_MAX, V|D, "debug"},
-{"buffers", "picture buffer allocations", 0, FF_OPT_TYPE_CONST, {.dbl = FF_DEBUG_BUFFERS }, INT_MIN, INT_MAX, V|D, "debug"},
-{"thread_ops", "threading operations", 0, FF_OPT_TYPE_CONST, {.dbl = FF_DEBUG_THREADS }, INT_MIN, INT_MAX, V|D, "debug"},
-{"vismv", "visualize motion vectors (MVs)", OFFSET(debug_mv), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, INT_MAX, V|D, "debug_mv"},
-{"pf", "forward predicted MVs of P-frames", 0, FF_OPT_TYPE_CONST, {.dbl = FF_DEBUG_VIS_MV_P_FOR }, INT_MIN, INT_MAX, V|D, "debug_mv"},
-{"bf", "forward predicted MVs of B-frames", 0, FF_OPT_TYPE_CONST, {.dbl = FF_DEBUG_VIS_MV_B_FOR }, INT_MIN, INT_MAX, V|D, "debug_mv"},
-{"bb", "backward predicted MVs of B-frames", 0, FF_OPT_TYPE_CONST, {.dbl = FF_DEBUG_VIS_MV_B_BACK }, INT_MIN, INT_MAX, V|D, "debug_mv"},
-{"cmp", "full pel me compare function", OFFSET(me_cmp), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"subcmp", "sub pel me compare function", OFFSET(me_sub_cmp), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"mbcmp", "macroblock compare function", OFFSET(mb_cmp), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"ildctcmp", "interlaced dct compare function", OFFSET(ildct_cmp), FF_OPT_TYPE_INT, {.dbl = FF_CMP_VSAD }, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"dia_size", "diamond type & size for motion estimation", OFFSET(dia_size), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
-{"last_pred", "amount of motion predictors from the previous frame", OFFSET(last_predictor_count), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
-{"preme", "pre motion estimation", OFFSET(pre_me), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
-{"precmp", "pre motion estimation compare function", OFFSET(me_pre_cmp), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"sad", "sum of absolute differences, fast (default)", 0, FF_OPT_TYPE_CONST, {.dbl = FF_CMP_SAD }, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"sse", "sum of squared errors", 0, FF_OPT_TYPE_CONST, {.dbl = FF_CMP_SSE }, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"satd", "sum of absolute Hadamard transformed differences", 0, FF_OPT_TYPE_CONST, {.dbl = FF_CMP_SATD }, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"dct", "sum of absolute DCT transformed differences", 0, FF_OPT_TYPE_CONST, {.dbl = FF_CMP_DCT }, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"psnr", "sum of squared quantization errors (avoid, low quality)", 0, FF_OPT_TYPE_CONST, {.dbl = FF_CMP_PSNR }, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"bit", "number of bits needed for the block", 0, FF_OPT_TYPE_CONST, {.dbl = FF_CMP_BIT }, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"rd", "rate distortion optimal, slow", 0, FF_OPT_TYPE_CONST, {.dbl = FF_CMP_RD }, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"zero", "0", 0, FF_OPT_TYPE_CONST, {.dbl = FF_CMP_ZERO }, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"vsad", "sum of absolute vertical differences", 0, FF_OPT_TYPE_CONST, {.dbl = FF_CMP_VSAD }, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"vsse", "sum of squared vertical differences", 0, FF_OPT_TYPE_CONST, {.dbl = FF_CMP_VSSE }, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"nsse", "noise preserving sum of squared differences", 0, FF_OPT_TYPE_CONST, {.dbl = FF_CMP_NSSE }, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"b", "set bitrate (in bits/s)", OFFSET(bit_rate), AV_OPT_TYPE_INT, {.dbl = AV_CODEC_DEFAULT_BITRATE }, INT_MIN, INT_MAX, A|V|E},
+{"ab", "set bitrate (in bits/s)", OFFSET(bit_rate), AV_OPT_TYPE_INT, {.dbl = 128*1000 }, INT_MIN, INT_MAX, A|E},
+{"bt", "set video bitrate tolerance (in bits/s)", OFFSET(bit_rate_tolerance), AV_OPT_TYPE_INT, {.dbl = AV_CODEC_DEFAULT_BITRATE*20 }, 1, INT_MAX, V|E},
+{"flags", NULL, OFFSET(flags), AV_OPT_TYPE_FLAGS, {.dbl = DEFAULT }, 0, UINT_MAX, V|A|E|D, "flags"},
+{"mv4", "use four motion vector by macroblock (mpeg4)", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_4MV }, INT_MIN, INT_MAX, V|E, "flags"},
+#if FF_API_MPEGVIDEO_GLOBAL_OPTS
+{"obmc", "use overlapped block motion compensation (h263+)", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_OBMC }, INT_MIN, INT_MAX, V|E, "flags"},
+#endif
+{"qpel", "use 1/4 pel motion compensation", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_QPEL }, INT_MIN, INT_MAX, V|E, "flags"},
+{"loop", "use loop filter", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_LOOP_FILTER }, INT_MIN, INT_MAX, V|E, "flags"},
+{"qscale", "use fixed qscale", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_QSCALE }, INT_MIN, INT_MAX, 0, "flags"},
+{"gmc", "use gmc", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_GMC }, INT_MIN, INT_MAX, V|E, "flags"},
+{"mv0", "always try a mb with mv=<0,0>", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_MV0 }, INT_MIN, INT_MAX, V|E, "flags"},
+#if FF_API_MPEGVIDEO_GLOBAL_OPTS
+{"part", "use data partitioning", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_PART }, INT_MIN, INT_MAX, V|E, "flags"},
+#endif
+{"input_preserved", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_INPUT_PRESERVED }, INT_MIN, INT_MAX, 0, "flags"},
+{"pass1", "use internal 2pass ratecontrol in first pass mode", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_PASS1 }, INT_MIN, INT_MAX, 0, "flags"},
+{"pass2", "use internal 2pass ratecontrol in second pass mode", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_PASS2 }, INT_MIN, INT_MAX, 0, "flags"},
+#if FF_API_MJPEG_GLOBAL_OPTS
+{"extern_huff", "use external huffman table (for mjpeg)", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_EXTERN_HUFF }, INT_MIN, INT_MAX, 0, "flags"},
+#endif
+{"gray", "only decode/encode grayscale", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_GRAY }, INT_MIN, INT_MAX, V|E|D, "flags"},
+{"emu_edge", "don't draw edges", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_EMU_EDGE }, INT_MIN, INT_MAX, 0, "flags"},
+{"psnr", "error[?] variables will be set during encoding", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_PSNR }, INT_MIN, INT_MAX, V|E, "flags"},
+{"truncated", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_TRUNCATED }, INT_MIN, INT_MAX, 0, "flags"},
+{"naq", "normalize adaptive quantization", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_NORMALIZE_AQP }, INT_MIN, INT_MAX, V|E, "flags"},
+{"ildct", "use interlaced dct", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_INTERLACED_DCT }, INT_MIN, INT_MAX, V|E, "flags"},
+{"low_delay", "force low delay", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_LOW_DELAY }, INT_MIN, INT_MAX, V|D|E, "flags"},
+#if FF_API_MPEGVIDEO_GLOBAL_OPTS
+{"alt", "enable alternate scantable (mpeg2/mpeg4)", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_ALT_SCAN }, INT_MIN, INT_MAX, V|E, "flags"},
+#endif
+{"global_header", "place global headers in extradata instead of every keyframe", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_GLOBAL_HEADER }, INT_MIN, INT_MAX, V|A|E, "flags"},
+{"bitexact", "use only bitexact stuff (except (i)dct)", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_BITEXACT }, INT_MIN, INT_MAX, A|V|S|D|E, "flags"},
+{"aic", "h263 advanced intra coding / mpeg4 ac prediction", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_AC_PRED }, INT_MIN, INT_MAX, V|E, "flags"},
+#if FF_API_MPEGVIDEO_GLOBAL_OPTS
+{"umv", "use unlimited motion vectors", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_H263P_UMV }, INT_MIN, INT_MAX, V|E, "flags"},
+#endif
+{"cbp", "use rate distortion optimization for cbp", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_CBP_RD }, INT_MIN, INT_MAX, V|E, "flags"},
+{"qprd", "use rate distortion optimization for qp selection", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_QP_RD }, INT_MIN, INT_MAX, V|E, "flags"},
+#if FF_API_MPEGVIDEO_GLOBAL_OPTS
+{"aiv", "h263 alternative inter vlc", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_H263P_AIV }, INT_MIN, INT_MAX, V|E, "flags"},
+{"slice", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_H263P_SLICE_STRUCT }, INT_MIN, INT_MAX, V|E, "flags"},
+#endif
+{"ilme", "interlaced motion estimation", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_INTERLACED_ME }, INT_MIN, INT_MAX, V|E, "flags"},
+#if FF_API_MPEGVIDEO_GLOBAL_OPTS
+{"scan_offset", "will reserve space for svcd scan offset user data", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_SVCD_SCAN_OFFSET }, INT_MIN, INT_MAX, V|E, "flags"},
+#endif
+{"cgop", "closed gop", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_CLOSED_GOP }, INT_MIN, INT_MAX, V|E, "flags"},
+{"fast", "allow non spec compliant speedup tricks", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_FAST }, INT_MIN, INT_MAX, V|E, "flags2"},
+{"sgop", "strictly enforce gop size", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_STRICT_GOP }, INT_MIN, INT_MAX, V|E, "flags2"},
+{"noout", "skip bitstream encoding", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_NO_OUTPUT }, INT_MIN, INT_MAX, V|E, "flags2"},
+{"local_header", "place global headers at every keyframe instead of in extradata", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_LOCAL_HEADER }, INT_MIN, INT_MAX, V|E, "flags2"},
+{"showall", "Show all frames before the first keyframe", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_SHOW_ALL }, INT_MIN, INT_MAX, V|D, "flags2"},
+{"sub_id", NULL, OFFSET(sub_id), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
+{"me_method", "set motion estimation method", OFFSET(me_method), AV_OPT_TYPE_INT, {.dbl = ME_EPZS }, INT_MIN, INT_MAX, V|E, "me_method"},
+{"zero", "zero motion estimation (fastest)", 0, AV_OPT_TYPE_CONST, {.dbl = ME_ZERO }, INT_MIN, INT_MAX, V|E, "me_method" },
+{"full", "full motion estimation (slowest)", 0, AV_OPT_TYPE_CONST, {.dbl = ME_FULL }, INT_MIN, INT_MAX, V|E, "me_method" },
+{"epzs", "EPZS motion estimation (default)", 0, AV_OPT_TYPE_CONST, {.dbl = ME_EPZS }, INT_MIN, INT_MAX, V|E, "me_method" },
+{"esa", "esa motion estimation (alias for full)", 0, AV_OPT_TYPE_CONST, {.dbl = ME_FULL }, INT_MIN, INT_MAX, V|E, "me_method" },
+{"tesa", "tesa motion estimation", 0, AV_OPT_TYPE_CONST, {.dbl = ME_TESA }, INT_MIN, INT_MAX, V|E, "me_method" },
+{"dia", "dia motion estimation (alias for epzs)", 0, AV_OPT_TYPE_CONST, {.dbl = ME_EPZS }, INT_MIN, INT_MAX, V|E, "me_method" },
+{"log", "log motion estimation", 0, AV_OPT_TYPE_CONST, {.dbl = ME_LOG }, INT_MIN, INT_MAX, V|E, "me_method" },
+{"phods", "phods motion estimation", 0, AV_OPT_TYPE_CONST, {.dbl = ME_PHODS }, INT_MIN, INT_MAX, V|E, "me_method" },
+{"x1", "X1 motion estimation", 0, AV_OPT_TYPE_CONST, {.dbl = ME_X1 }, INT_MIN, INT_MAX, V|E, "me_method" },
+{"hex", "hex motion estimation", 0, AV_OPT_TYPE_CONST, {.dbl = ME_HEX }, INT_MIN, INT_MAX, V|E, "me_method" },
+{"umh", "umh motion estimation", 0, AV_OPT_TYPE_CONST, {.dbl = ME_UMH }, INT_MIN, INT_MAX, V|E, "me_method" },
+{"iter", "iter motion estimation", 0, AV_OPT_TYPE_CONST, {.dbl = ME_ITER }, INT_MIN, INT_MAX, V|E, "me_method" },
+{"extradata_size", NULL, OFFSET(extradata_size), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
+{"time_base", NULL, OFFSET(time_base), AV_OPT_TYPE_RATIONAL, {.dbl = 0}, INT_MIN, INT_MAX},
+{"g", "set the group of picture size", OFFSET(gop_size), AV_OPT_TYPE_INT, {.dbl = 12 }, INT_MIN, INT_MAX, V|E},
+{"ar", "set audio sampling rate (in Hz)", OFFSET(sample_rate), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, A|D|E},
+{"ac", "set number of audio channels", OFFSET(channels), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, A|D|E},
+{"cutoff", "set cutoff bandwidth", OFFSET(cutoff), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, A|E},
+{"frame_size", NULL, OFFSET(frame_size), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, A|E},
+{"frame_number", NULL, OFFSET(frame_number), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
+{"delay", NULL, OFFSET(delay), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
+{"qcomp", "video quantizer scale compression (VBR)", OFFSET(qcompress), AV_OPT_TYPE_FLOAT, {.dbl = 0.5 }, -FLT_MAX, FLT_MAX, V|E},
+{"qblur", "video quantizer scale blur (VBR)", OFFSET(qblur), AV_OPT_TYPE_FLOAT, {.dbl = 0.5 }, -1, FLT_MAX, V|E},
+{"qmin", "min video quantizer scale (VBR)", OFFSET(qmin), AV_OPT_TYPE_INT, {.dbl = 2 }, -1, 69, V|E},
+{"qmax", "max video quantizer scale (VBR)", OFFSET(qmax), AV_OPT_TYPE_INT, {.dbl = 31 }, -1, 69, V|E},
+{"qdiff", "max difference between the quantizer scale (VBR)", OFFSET(max_qdiff), AV_OPT_TYPE_INT, {.dbl = 3 }, INT_MIN, INT_MAX, V|E},
+{"bf", "use 'frames' B frames", OFFSET(max_b_frames), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, -1, FF_MAX_B_FRAMES, V|E},
+{"b_qfactor", "qp factor between p and b frames", OFFSET(b_quant_factor), AV_OPT_TYPE_FLOAT, {.dbl = 1.25 }, -FLT_MAX, FLT_MAX, V|E},
+{"rc_strategy", "ratecontrol method", OFFSET(rc_strategy), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
+{"b_strategy", "strategy to choose between I/P/B-frames", OFFSET(b_frame_strategy), AV_OPT_TYPE_INT, {.dbl = 0 }, INT_MIN, INT_MAX, V|E},
+#if FF_API_X264_GLOBAL_OPTS
+{"wpredp", "weighted prediction analysis method", OFFSET(weighted_p_pred), AV_OPT_TYPE_INT, {.dbl = -1 }, INT_MIN, INT_MAX, V|E},
+#endif
+{"ps", "rtp payload size in bytes", OFFSET(rtp_payload_size), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
+{"mv_bits", NULL, OFFSET(mv_bits), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
+{"header_bits", NULL, OFFSET(header_bits), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
+{"i_tex_bits", NULL, OFFSET(i_tex_bits), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
+{"p_tex_bits", NULL, OFFSET(p_tex_bits), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
+{"i_count", NULL, OFFSET(i_count), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
+{"p_count", NULL, OFFSET(p_count), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
+{"skip_count", NULL, OFFSET(skip_count), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
+{"misc_bits", NULL, OFFSET(misc_bits), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
+{"frame_bits", NULL, OFFSET(frame_bits), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
+{"codec_tag", NULL, OFFSET(codec_tag), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
+{"bug", "workaround not auto detected encoder bugs", OFFSET(workaround_bugs), AV_OPT_TYPE_FLAGS, {.dbl = FF_BUG_AUTODETECT }, INT_MIN, INT_MAX, V|D, "bug"},
+{"autodetect", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_BUG_AUTODETECT }, INT_MIN, INT_MAX, V|D, "bug"},
+{"old_msmpeg4", "some old lavc generated msmpeg4v3 files (no autodetection)", 0, AV_OPT_TYPE_CONST, {.dbl = FF_BUG_OLD_MSMPEG4 }, INT_MIN, INT_MAX, V|D, "bug"},
+{"xvid_ilace", "Xvid interlacing bug (autodetected if fourcc==XVIX)", 0, AV_OPT_TYPE_CONST, {.dbl = FF_BUG_XVID_ILACE }, INT_MIN, INT_MAX, V|D, "bug"},
+{"ump4", "(autodetected if fourcc==UMP4)", 0, AV_OPT_TYPE_CONST, {.dbl = FF_BUG_UMP4 }, INT_MIN, INT_MAX, V|D, "bug"},
+{"no_padding", "padding bug (autodetected)", 0, AV_OPT_TYPE_CONST, {.dbl = FF_BUG_NO_PADDING }, INT_MIN, INT_MAX, V|D, "bug"},
+{"amv", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_BUG_AMV }, INT_MIN, INT_MAX, V|D, "bug"},
+{"ac_vlc", "illegal vlc bug (autodetected per fourcc)", 0, AV_OPT_TYPE_CONST, {.dbl = FF_BUG_AC_VLC }, INT_MIN, INT_MAX, V|D, "bug"},
+{"qpel_chroma", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_BUG_QPEL_CHROMA }, INT_MIN, INT_MAX, V|D, "bug"},
+{"std_qpel", "old standard qpel (autodetected per fourcc/version)", 0, AV_OPT_TYPE_CONST, {.dbl = FF_BUG_STD_QPEL }, INT_MIN, INT_MAX, V|D, "bug"},
+{"qpel_chroma2", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_BUG_QPEL_CHROMA2 }, INT_MIN, INT_MAX, V|D, "bug"},
+{"direct_blocksize", "direct-qpel-blocksize bug (autodetected per fourcc/version)", 0, AV_OPT_TYPE_CONST, {.dbl = FF_BUG_DIRECT_BLOCKSIZE }, INT_MIN, INT_MAX, V|D, "bug"},
+{"edge", "edge padding bug (autodetected per fourcc/version)", 0, AV_OPT_TYPE_CONST, {.dbl = FF_BUG_EDGE }, INT_MIN, INT_MAX, V|D, "bug"},
+{"hpel_chroma", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_BUG_HPEL_CHROMA }, INT_MIN, INT_MAX, V|D, "bug"},
+{"dc_clip", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_BUG_DC_CLIP }, INT_MIN, INT_MAX, V|D, "bug"},
+{"ms", "workaround various bugs in microsofts broken decoders", 0, AV_OPT_TYPE_CONST, {.dbl = FF_BUG_MS }, INT_MIN, INT_MAX, V|D, "bug"},
+{"trunc", "trancated frames", 0, AV_OPT_TYPE_CONST, {.dbl = FF_BUG_TRUNCATED}, INT_MIN, INT_MAX, V|D, "bug"},
+{"lelim", "single coefficient elimination threshold for luminance (negative values also consider dc coefficient)", OFFSET(luma_elim_threshold), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
+{"celim", "single coefficient elimination threshold for chrominance (negative values also consider dc coefficient)", OFFSET(chroma_elim_threshold), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
+{"strict", "how strictly to follow the standards", OFFSET(strict_std_compliance), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, A|V|D|E, "strict"},
+{"very", "strictly conform to a older more strict version of the spec or reference software", 0, AV_OPT_TYPE_CONST, {.dbl = FF_COMPLIANCE_VERY_STRICT }, INT_MIN, INT_MAX, V|D|E, "strict"},
+{"strict", "strictly conform to all the things in the spec no matter what consequences", 0, AV_OPT_TYPE_CONST, {.dbl = FF_COMPLIANCE_STRICT }, INT_MIN, INT_MAX, V|D|E, "strict"},
+{"normal", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_COMPLIANCE_NORMAL }, INT_MIN, INT_MAX, V|D|E, "strict"},
+{"unofficial", "allow unofficial extensions", 0, AV_OPT_TYPE_CONST, {.dbl = FF_COMPLIANCE_UNOFFICIAL }, INT_MIN, INT_MAX, V|D|E, "strict"},
+{"experimental", "allow non standardized experimental things", 0, AV_OPT_TYPE_CONST, {.dbl = FF_COMPLIANCE_EXPERIMENTAL }, INT_MIN, INT_MAX, V|D|E, "strict"},
+{"b_qoffset", "qp offset between P and B frames", OFFSET(b_quant_offset), AV_OPT_TYPE_FLOAT, {.dbl = 1.25 }, -FLT_MAX, FLT_MAX, V|E},
+{"er", "set error detection aggressivity", OFFSET(error_recognition), AV_OPT_TYPE_INT, {.dbl = FF_ER_CAREFUL }, INT_MIN, INT_MAX, A|V|D, "er"},
+{"careful", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_ER_CAREFUL }, INT_MIN, INT_MAX, V|D, "er"},
+{"compliant", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_ER_COMPLIANT }, INT_MIN, INT_MAX, V|D, "er"},
+{"aggressive", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_ER_AGGRESSIVE }, INT_MIN, INT_MAX, V|D, "er"},
+#if FF_API_ER
+{"very_aggressive", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_ER_VERY_AGGRESSIVE }, INT_MIN, INT_MAX, V|D, "er"},
+#endif /* FF_API_ER */
+{"explode", "abort decoding on error recognition", 0, AV_OPT_TYPE_CONST, {.dbl = FF_ER_EXPLODE }, INT_MIN, INT_MAX, V|D, "er"},
+{"has_b_frames", NULL, OFFSET(has_b_frames), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
+{"block_align", NULL, OFFSET(block_align), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
+{"parse_only", NULL, OFFSET(parse_only), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
+{"mpeg_quant", "use MPEG quantizers instead of H.263", OFFSET(mpeg_quant), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
+{"stats_out", NULL, OFFSET(stats_out), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX},
+{"stats_in", NULL, OFFSET(stats_in), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX},
+{"qsquish", "how to keep quantizer between qmin and qmax (0 = clip, 1 = use differentiable function)", OFFSET(rc_qsquish), AV_OPT_TYPE_FLOAT, {.dbl = DEFAULT }, 0, 99, V|E},
+{"rc_qmod_amp", "experimental quantizer modulation", OFFSET(rc_qmod_amp), AV_OPT_TYPE_FLOAT, {.dbl = DEFAULT }, -FLT_MAX, FLT_MAX, V|E},
+{"rc_qmod_freq", "experimental quantizer modulation", OFFSET(rc_qmod_freq), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
+{"rc_override_count", NULL, OFFSET(rc_override_count), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
+{"rc_eq", "set rate control equation", OFFSET(rc_eq), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, V|E},
+{"maxrate", "set max video bitrate tolerance (in bits/s)", OFFSET(rc_max_rate), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
+{"minrate", "set min video bitrate tolerance (in bits/s)", OFFSET(rc_min_rate), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
+{"bufsize", "set ratecontrol buffer size (in bits)", OFFSET(rc_buffer_size), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, A|V|E},
+{"rc_buf_aggressivity", "currently useless", OFFSET(rc_buffer_aggressivity), AV_OPT_TYPE_FLOAT, {.dbl = 1.0 }, -FLT_MAX, FLT_MAX, V|E},
+{"i_qfactor", "qp factor between P and I frames", OFFSET(i_quant_factor), AV_OPT_TYPE_FLOAT, {.dbl = -0.8 }, -FLT_MAX, FLT_MAX, V|E},
+{"i_qoffset", "qp offset between P and I frames", OFFSET(i_quant_offset), AV_OPT_TYPE_FLOAT, {.dbl = 0.0 }, -FLT_MAX, FLT_MAX, V|E},
+{"rc_init_cplx", "initial complexity for 1-pass encoding", OFFSET(rc_initial_cplx), AV_OPT_TYPE_FLOAT, {.dbl = DEFAULT }, -FLT_MAX, FLT_MAX, V|E},
+{"dct", "DCT algorithm", OFFSET(dct_algo), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, INT_MAX, V|E, "dct"},
+{"auto", "autoselect a good one (default)", 0, AV_OPT_TYPE_CONST, {.dbl = FF_DCT_AUTO }, INT_MIN, INT_MAX, V|E, "dct"},
+{"fastint", "fast integer", 0, AV_OPT_TYPE_CONST, {.dbl = FF_DCT_FASTINT }, INT_MIN, INT_MAX, V|E, "dct"},
+{"int", "accurate integer", 0, AV_OPT_TYPE_CONST, {.dbl = FF_DCT_INT }, INT_MIN, INT_MAX, V|E, "dct"},
+{"mmx", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_DCT_MMX }, INT_MIN, INT_MAX, V|E, "dct"},
+{"mlib", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_DCT_MLIB }, INT_MIN, INT_MAX, V|E, "dct"},
+{"altivec", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_DCT_ALTIVEC }, INT_MIN, INT_MAX, V|E, "dct"},
+{"faan", "floating point AAN DCT", 0, AV_OPT_TYPE_CONST, {.dbl = FF_DCT_FAAN }, INT_MIN, INT_MAX, V|E, "dct"},
+{"lumi_mask", "compresses bright areas stronger than medium ones", OFFSET(lumi_masking), AV_OPT_TYPE_FLOAT, {.dbl = 0 }, -FLT_MAX, FLT_MAX, V|E},
+{"tcplx_mask", "temporal complexity masking", OFFSET(temporal_cplx_masking), AV_OPT_TYPE_FLOAT, {.dbl = 0 }, -FLT_MAX, FLT_MAX, V|E},
+{"scplx_mask", "spatial complexity masking", OFFSET(spatial_cplx_masking), AV_OPT_TYPE_FLOAT, {.dbl = 0 }, -FLT_MAX, FLT_MAX, V|E},
+{"p_mask", "inter masking", OFFSET(p_masking), AV_OPT_TYPE_FLOAT, {.dbl = 0 }, -FLT_MAX, FLT_MAX, V|E},
+{"dark_mask", "compresses dark areas stronger than medium ones", OFFSET(dark_masking), AV_OPT_TYPE_FLOAT, {.dbl = 0 }, -FLT_MAX, FLT_MAX, V|E},
+{"idct", "select IDCT implementation", OFFSET(idct_algo), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, INT_MAX, V|E|D, "idct"},
+{"auto", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_IDCT_AUTO }, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"int", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_IDCT_INT }, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"simple", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_IDCT_SIMPLE }, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"simplemmx", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_IDCT_SIMPLEMMX }, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"libmpeg2mmx", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_IDCT_LIBMPEG2MMX }, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"ps2", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_IDCT_PS2 }, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"mlib", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_IDCT_MLIB }, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"arm", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_IDCT_ARM }, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"altivec", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_IDCT_ALTIVEC }, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"sh4", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_IDCT_SH4 }, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"simplearm", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_IDCT_SIMPLEARM }, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"simplearmv5te", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_IDCT_SIMPLEARMV5TE }, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"simplearmv6", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_IDCT_SIMPLEARMV6 }, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"simpleneon", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_IDCT_SIMPLENEON }, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"simplealpha", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_IDCT_SIMPLEALPHA }, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"h264", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_IDCT_H264 }, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"vp3", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_IDCT_VP3 }, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"ipp", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_IDCT_IPP }, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"xvidmmx", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_IDCT_XVIDMMX }, INT_MIN, INT_MAX, V|E|D, "idct"},
+{"faani", "floating point AAN IDCT", 0, AV_OPT_TYPE_CONST, {.dbl = FF_IDCT_FAAN }, INT_MIN, INT_MAX, V|D|E, "idct"},
+{"slice_count", NULL, OFFSET(slice_count), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
+{"ec", "set error concealment strategy", OFFSET(error_concealment), AV_OPT_TYPE_FLAGS, {.dbl = 3 }, INT_MIN, INT_MAX, V|D, "ec"},
+{"guess_mvs", "iterative motion vector (MV) search (slow)", 0, AV_OPT_TYPE_CONST, {.dbl = FF_EC_GUESS_MVS }, INT_MIN, INT_MAX, V|D, "ec"},
+{"deblock", "use strong deblock filter for damaged MBs", 0, AV_OPT_TYPE_CONST, {.dbl = FF_EC_DEBLOCK }, INT_MIN, INT_MAX, V|D, "ec"},
+{"bits_per_coded_sample", NULL, OFFSET(bits_per_coded_sample), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
+{"pred", "prediction method", OFFSET(prediction_method), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E, "pred"},
+{"left", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_PRED_LEFT }, INT_MIN, INT_MAX, V|E, "pred"},
+{"plane", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_PRED_PLANE }, INT_MIN, INT_MAX, V|E, "pred"},
+{"median", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_PRED_MEDIAN }, INT_MIN, INT_MAX, V|E, "pred"},
+{"aspect", "sample aspect ratio", OFFSET(sample_aspect_ratio), AV_OPT_TYPE_RATIONAL, {.dbl = 0}, 0, 10, V|E},
+{"debug", "print specific debug info", OFFSET(debug), AV_OPT_TYPE_FLAGS, {.dbl = DEFAULT }, 0, INT_MAX, V|A|S|E|D, "debug"},
+{"pict", "picture info", 0, AV_OPT_TYPE_CONST, {.dbl = FF_DEBUG_PICT_INFO }, INT_MIN, INT_MAX, V|D, "debug"},
+{"rc", "rate control", 0, AV_OPT_TYPE_CONST, {.dbl = FF_DEBUG_RC }, INT_MIN, INT_MAX, V|E, "debug"},
+{"bitstream", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_DEBUG_BITSTREAM }, INT_MIN, INT_MAX, V|D, "debug"},
+{"mb_type", "macroblock (MB) type", 0, AV_OPT_TYPE_CONST, {.dbl = FF_DEBUG_MB_TYPE }, INT_MIN, INT_MAX, V|D, "debug"},
+{"qp", "per-block quantization parameter (QP)", 0, AV_OPT_TYPE_CONST, {.dbl = FF_DEBUG_QP }, INT_MIN, INT_MAX, V|D, "debug"},
+{"mv", "motion vector", 0, AV_OPT_TYPE_CONST, {.dbl = FF_DEBUG_MV }, INT_MIN, INT_MAX, V|D, "debug"},
+{"dct_coeff", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_DEBUG_DCT_COEFF }, INT_MIN, INT_MAX, V|D, "debug"},
+{"skip", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_DEBUG_SKIP }, INT_MIN, INT_MAX, V|D, "debug"},
+{"startcode", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_DEBUG_STARTCODE }, INT_MIN, INT_MAX, V|D, "debug"},
+{"pts", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_DEBUG_PTS }, INT_MIN, INT_MAX, V|D, "debug"},
+{"er", "error recognition", 0, AV_OPT_TYPE_CONST, {.dbl = FF_DEBUG_ER }, INT_MIN, INT_MAX, V|D, "debug"},
+{"mmco", "memory management control operations (H.264)", 0, AV_OPT_TYPE_CONST, {.dbl = FF_DEBUG_MMCO }, INT_MIN, INT_MAX, V|D, "debug"},
+{"bugs", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_DEBUG_BUGS }, INT_MIN, INT_MAX, V|D, "debug"},
+{"vis_qp", "visualize quantization parameter (QP), lower QP are tinted greener", 0, AV_OPT_TYPE_CONST, {.dbl = FF_DEBUG_VIS_QP }, INT_MIN, INT_MAX, V|D, "debug"},
+{"vis_mb_type", "visualize block types", 0, AV_OPT_TYPE_CONST, {.dbl = FF_DEBUG_VIS_MB_TYPE }, INT_MIN, INT_MAX, V|D, "debug"},
+{"buffers", "picture buffer allocations", 0, AV_OPT_TYPE_CONST, {.dbl = FF_DEBUG_BUFFERS }, INT_MIN, INT_MAX, V|D, "debug"},
+{"thread_ops", "threading operations", 0, AV_OPT_TYPE_CONST, {.dbl = FF_DEBUG_THREADS }, INT_MIN, INT_MAX, V|D, "debug"},
+{"vismv", "visualize motion vectors (MVs)", OFFSET(debug_mv), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, INT_MAX, V|D, "debug_mv"},
+{"pf", "forward predicted MVs of P-frames", 0, AV_OPT_TYPE_CONST, {.dbl = FF_DEBUG_VIS_MV_P_FOR }, INT_MIN, INT_MAX, V|D, "debug_mv"},
+{"bf", "forward predicted MVs of B-frames", 0, AV_OPT_TYPE_CONST, {.dbl = FF_DEBUG_VIS_MV_B_FOR }, INT_MIN, INT_MAX, V|D, "debug_mv"},
+{"bb", "backward predicted MVs of B-frames", 0, AV_OPT_TYPE_CONST, {.dbl = FF_DEBUG_VIS_MV_B_BACK }, INT_MIN, INT_MAX, V|D, "debug_mv"},
+{"cmp", "full pel me compare function", OFFSET(me_cmp), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"subcmp", "sub pel me compare function", OFFSET(me_sub_cmp), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"mbcmp", "macroblock compare function", OFFSET(mb_cmp), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"ildctcmp", "interlaced dct compare function", OFFSET(ildct_cmp), AV_OPT_TYPE_INT, {.dbl = FF_CMP_VSAD }, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"dia_size", "diamond type & size for motion estimation", OFFSET(dia_size), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
+{"last_pred", "amount of motion predictors from the previous frame", OFFSET(last_predictor_count), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
+{"preme", "pre motion estimation", OFFSET(pre_me), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
+{"precmp", "pre motion estimation compare function", OFFSET(me_pre_cmp), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"sad", "sum of absolute differences, fast (default)", 0, AV_OPT_TYPE_CONST, {.dbl = FF_CMP_SAD }, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"sse", "sum of squared errors", 0, AV_OPT_TYPE_CONST, {.dbl = FF_CMP_SSE }, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"satd", "sum of absolute Hadamard transformed differences", 0, AV_OPT_TYPE_CONST, {.dbl = FF_CMP_SATD }, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"dct", "sum of absolute DCT transformed differences", 0, AV_OPT_TYPE_CONST, {.dbl = FF_CMP_DCT }, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"psnr", "sum of squared quantization errors (avoid, low quality)", 0, AV_OPT_TYPE_CONST, {.dbl = FF_CMP_PSNR }, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"bit", "number of bits needed for the block", 0, AV_OPT_TYPE_CONST, {.dbl = FF_CMP_BIT }, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"rd", "rate distortion optimal, slow", 0, AV_OPT_TYPE_CONST, {.dbl = FF_CMP_RD }, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"zero", "0", 0, AV_OPT_TYPE_CONST, {.dbl = FF_CMP_ZERO }, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"vsad", "sum of absolute vertical differences", 0, AV_OPT_TYPE_CONST, {.dbl = FF_CMP_VSAD }, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"vsse", "sum of squared vertical differences", 0, AV_OPT_TYPE_CONST, {.dbl = FF_CMP_VSSE }, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"nsse", "noise preserving sum of squared differences", 0, AV_OPT_TYPE_CONST, {.dbl = FF_CMP_NSSE }, INT_MIN, INT_MAX, V|E, "cmp_func"},
#if CONFIG_SNOW_ENCODER
-{"w53", "5/3 wavelet, only used in snow", 0, FF_OPT_TYPE_CONST, {.dbl = FF_CMP_W53 }, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"w97", "9/7 wavelet, only used in snow", 0, FF_OPT_TYPE_CONST, {.dbl = FF_CMP_W97 }, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"w53", "5/3 wavelet, only used in snow", 0, AV_OPT_TYPE_CONST, {.dbl = FF_CMP_W53 }, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"w97", "9/7 wavelet, only used in snow", 0, AV_OPT_TYPE_CONST, {.dbl = FF_CMP_W97 }, INT_MIN, INT_MAX, V|E, "cmp_func"},
#endif
-{"dctmax", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_CMP_DCTMAX }, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"chroma", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_CMP_CHROMA }, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"pre_dia_size", "diamond type & size for motion estimation pre-pass", OFFSET(pre_dia_size), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
-{"subq", "sub pel motion estimation quality", OFFSET(me_subpel_quality), FF_OPT_TYPE_INT, {.dbl = 8 }, INT_MIN, INT_MAX, V|E},
-{"dtg_active_format", NULL, OFFSET(dtg_active_format), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
-{"me_range", "limit motion vectors range (1023 for DivX player)", OFFSET(me_range), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
-{"ibias", "intra quant bias", OFFSET(intra_quant_bias), FF_OPT_TYPE_INT, {.dbl = FF_DEFAULT_QUANT_BIAS }, INT_MIN, INT_MAX, V|E},
-{"pbias", "inter quant bias", OFFSET(inter_quant_bias), FF_OPT_TYPE_INT, {.dbl = FF_DEFAULT_QUANT_BIAS }, INT_MIN, INT_MAX, V|E},
-{"color_table_id", NULL, OFFSET(color_table_id), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
-{"internal_buffer_count", NULL, OFFSET(internal_buffer_count), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
-{"global_quality", NULL, OFFSET(global_quality), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
-{"coder", NULL, OFFSET(coder_type), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E, "coder"},
-{"vlc", "variable length coder / huffman coder", 0, FF_OPT_TYPE_CONST, {.dbl = FF_CODER_TYPE_VLC }, INT_MIN, INT_MAX, V|E, "coder"},
-{"ac", "arithmetic coder", 0, FF_OPT_TYPE_CONST, {.dbl = FF_CODER_TYPE_AC }, INT_MIN, INT_MAX, V|E, "coder"},
-{"raw", "raw (no encoding)", 0, FF_OPT_TYPE_CONST, {.dbl = FF_CODER_TYPE_RAW }, INT_MIN, INT_MAX, V|E, "coder"},
-{"rle", "run-length coder", 0, FF_OPT_TYPE_CONST, {.dbl = FF_CODER_TYPE_RLE }, INT_MIN, INT_MAX, V|E, "coder"},
-{"deflate", "deflate-based coder", 0, FF_OPT_TYPE_CONST, {.dbl = FF_CODER_TYPE_DEFLATE }, INT_MIN, INT_MAX, V|E, "coder"},
-{"context", "context model", OFFSET(context_model), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
-{"slice_flags", NULL, OFFSET(slice_flags), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
-{"xvmc_acceleration", NULL, OFFSET(xvmc_acceleration), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
-{"mbd", "macroblock decision algorithm (high quality mode)", OFFSET(mb_decision), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E, "mbd"},
-{"simple", "use mbcmp (default)", 0, FF_OPT_TYPE_CONST, {.dbl = FF_MB_DECISION_SIMPLE }, INT_MIN, INT_MAX, V|E, "mbd"},
-{"bits", "use fewest bits", 0, FF_OPT_TYPE_CONST, {.dbl = FF_MB_DECISION_BITS }, INT_MIN, INT_MAX, V|E, "mbd"},
-{"rd", "use best rate distortion", 0, FF_OPT_TYPE_CONST, {.dbl = FF_MB_DECISION_RD }, INT_MIN, INT_MAX, V|E, "mbd"},
-{"stream_codec_tag", NULL, OFFSET(stream_codec_tag), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
-{"sc_threshold", "scene change threshold", OFFSET(scenechange_threshold), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
-{"lmin", "min lagrange factor (VBR)", OFFSET(lmin), FF_OPT_TYPE_INT, {.dbl = 2*FF_QP2LAMBDA }, 0, INT_MAX, V|E},
-{"lmax", "max lagrange factor (VBR)", OFFSET(lmax), FF_OPT_TYPE_INT, {.dbl = 31*FF_QP2LAMBDA }, 0, INT_MAX, V|E},
-{"nr", "noise reduction", OFFSET(noise_reduction), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
-{"rc_init_occupancy", "number of bits which should be loaded into the rc buffer before decoding starts", OFFSET(rc_initial_buffer_occupancy), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
-{"inter_threshold", NULL, OFFSET(inter_threshold), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
-{"flags2", NULL, OFFSET(flags2), FF_OPT_TYPE_FLAGS, {.dbl = CODEC_FLAG2_FASTPSKIP|CODEC_FLAG2_BIT_RESERVOIR|CODEC_FLAG2_PSY|CODEC_FLAG2_MBTREE }, 0, UINT_MAX, V|A|E|D, "flags2"},
-{"error", NULL, OFFSET(error_rate), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
+{"dctmax", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_CMP_DCTMAX }, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"chroma", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_CMP_CHROMA }, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"pre_dia_size", "diamond type & size for motion estimation pre-pass", OFFSET(pre_dia_size), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
+{"subq", "sub pel motion estimation quality", OFFSET(me_subpel_quality), AV_OPT_TYPE_INT, {.dbl = 8 }, INT_MIN, INT_MAX, V|E},
+{"dtg_active_format", NULL, OFFSET(dtg_active_format), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
+{"me_range", "limit motion vectors range (1023 for DivX player)", OFFSET(me_range), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
+{"ibias", "intra quant bias", OFFSET(intra_quant_bias), AV_OPT_TYPE_INT, {.dbl = FF_DEFAULT_QUANT_BIAS }, INT_MIN, INT_MAX, V|E},
+{"pbias", "inter quant bias", OFFSET(inter_quant_bias), AV_OPT_TYPE_INT, {.dbl = FF_DEFAULT_QUANT_BIAS }, INT_MIN, INT_MAX, V|E},
+{"color_table_id", NULL, OFFSET(color_table_id), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
+{"internal_buffer_count", NULL, OFFSET(internal_buffer_count), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
+{"global_quality", NULL, OFFSET(global_quality), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|A|E},
+{"coder", NULL, OFFSET(coder_type), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E, "coder"},
+{"vlc", "variable length coder / huffman coder", 0, AV_OPT_TYPE_CONST, {.dbl = FF_CODER_TYPE_VLC }, INT_MIN, INT_MAX, V|E, "coder"},
+{"ac", "arithmetic coder", 0, AV_OPT_TYPE_CONST, {.dbl = FF_CODER_TYPE_AC }, INT_MIN, INT_MAX, V|E, "coder"},
+{"raw", "raw (no encoding)", 0, AV_OPT_TYPE_CONST, {.dbl = FF_CODER_TYPE_RAW }, INT_MIN, INT_MAX, V|E, "coder"},
+{"rle", "run-length coder", 0, AV_OPT_TYPE_CONST, {.dbl = FF_CODER_TYPE_RLE }, INT_MIN, INT_MAX, V|E, "coder"},
+{"deflate", "deflate-based coder", 0, AV_OPT_TYPE_CONST, {.dbl = FF_CODER_TYPE_DEFLATE }, INT_MIN, INT_MAX, V|E, "coder"},
+{"context", "context model", OFFSET(context_model), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
+{"slice_flags", NULL, OFFSET(slice_flags), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
+{"xvmc_acceleration", NULL, OFFSET(xvmc_acceleration), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
+{"mbd", "macroblock decision algorithm (high quality mode)", OFFSET(mb_decision), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E, "mbd"},
+{"simple", "use mbcmp (default)", 0, AV_OPT_TYPE_CONST, {.dbl = FF_MB_DECISION_SIMPLE }, INT_MIN, INT_MAX, V|E, "mbd"},
+{"bits", "use fewest bits", 0, AV_OPT_TYPE_CONST, {.dbl = FF_MB_DECISION_BITS }, INT_MIN, INT_MAX, V|E, "mbd"},
+{"rd", "use best rate distortion", 0, AV_OPT_TYPE_CONST, {.dbl = FF_MB_DECISION_RD }, INT_MIN, INT_MAX, V|E, "mbd"},
+{"stream_codec_tag", NULL, OFFSET(stream_codec_tag), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
+{"sc_threshold", "scene change threshold", OFFSET(scenechange_threshold), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
+{"lmin", "min lagrange factor (VBR)", OFFSET(lmin), AV_OPT_TYPE_INT, {.dbl = 2*FF_QP2LAMBDA }, 0, INT_MAX, V|E},
+{"lmax", "max lagrange factor (VBR)", OFFSET(lmax), AV_OPT_TYPE_INT, {.dbl = 31*FF_QP2LAMBDA }, 0, INT_MAX, V|E},
+{"nr", "noise reduction", OFFSET(noise_reduction), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
+{"rc_init_occupancy", "number of bits which should be loaded into the rc buffer before decoding starts", OFFSET(rc_initial_buffer_occupancy), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
+{"inter_threshold", NULL, OFFSET(inter_threshold), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
+{"flags2", NULL, OFFSET(flags2), AV_OPT_TYPE_FLAGS, {.dbl = CODEC_FLAG2_FASTPSKIP|CODEC_FLAG2_BIT_RESERVOIR|CODEC_FLAG2_PSY|CODEC_FLAG2_MBTREE }, 0, UINT_MAX, V|A|E|D, "flags2"},
+{"error", NULL, OFFSET(error_rate), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
#if FF_API_ANTIALIAS_ALGO
-{"antialias", "MP3 antialias algorithm", OFFSET(antialias_algo), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|D, "aa"},
-{"auto", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_AA_AUTO }, INT_MIN, INT_MAX, V|D, "aa"},
-{"fastint", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_AA_FASTINT }, INT_MIN, INT_MAX, V|D, "aa"},
-{"int", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_AA_INT }, INT_MIN, INT_MAX, V|D, "aa"},
-{"float", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_AA_FLOAT }, INT_MIN, INT_MAX, V|D, "aa"},
+{"antialias", "MP3 antialias algorithm", OFFSET(antialias_algo), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|D, "aa"},
+{"auto", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_AA_AUTO }, INT_MIN, INT_MAX, V|D, "aa"},
+{"fastint", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_AA_FASTINT }, INT_MIN, INT_MAX, V|D, "aa"},
+{"int", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_AA_INT }, INT_MIN, INT_MAX, V|D, "aa"},
+{"float", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_AA_FLOAT }, INT_MIN, INT_MAX, V|D, "aa"},
+#endif
+{"qns", "quantizer noise shaping", OFFSET(quantizer_noise_shaping), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
+{"threads", NULL, OFFSET(thread_count), AV_OPT_TYPE_INT, {.dbl = 1 }, INT_MIN, INT_MAX, V|E|D},
+{"me_threshold", "motion estimaton threshold", OFFSET(me_threshold), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
+{"mb_threshold", "macroblock threshold", OFFSET(mb_threshold), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
+{"dc", "intra_dc_precision", OFFSET(intra_dc_precision), AV_OPT_TYPE_INT, {.dbl = 0 }, INT_MIN, INT_MAX, V|E},
+{"nssew", "nsse weight", OFFSET(nsse_weight), AV_OPT_TYPE_INT, {.dbl = 8 }, INT_MIN, INT_MAX, V|E},
+{"skip_top", "number of macroblock rows at the top which are skipped", OFFSET(skip_top), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|D},
+{"skip_bottom", "number of macroblock rows at the bottom which are skipped", OFFSET(skip_bottom), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|D},
+{"profile", NULL, OFFSET(profile), AV_OPT_TYPE_INT, {.dbl = FF_PROFILE_UNKNOWN }, INT_MIN, INT_MAX, V|A|E, "profile"},
+{"unknown", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_PROFILE_UNKNOWN }, INT_MIN, INT_MAX, V|A|E, "profile"},
+{"aac_main", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_PROFILE_AAC_MAIN }, INT_MIN, INT_MAX, A|E, "profile"},
+{"aac_low", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_PROFILE_AAC_LOW }, INT_MIN, INT_MAX, A|E, "profile"},
+{"aac_ssr", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_PROFILE_AAC_SSR }, INT_MIN, INT_MAX, A|E, "profile"},
+{"aac_ltp", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_PROFILE_AAC_LTP }, INT_MIN, INT_MAX, A|E, "profile"},
+{"dts", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_PROFILE_DTS }, INT_MIN, INT_MAX, A|E, "profile"},
+{"dts_es", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_PROFILE_DTS_ES }, INT_MIN, INT_MAX, A|E, "profile"},
+{"dts_96_24", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_PROFILE_DTS_96_24 }, INT_MIN, INT_MAX, A|E, "profile"},
+{"dts_hd_hra", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_PROFILE_DTS_HD_HRA }, INT_MIN, INT_MAX, A|E, "profile"},
+{"dts_hd_ma", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_PROFILE_DTS_HD_MA }, INT_MIN, INT_MAX, A|E, "profile"},
+{"level", NULL, OFFSET(level), AV_OPT_TYPE_INT, {.dbl = FF_LEVEL_UNKNOWN }, INT_MIN, INT_MAX, V|A|E, "level"},
+{"unknown", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_LEVEL_UNKNOWN }, INT_MIN, INT_MAX, V|A|E, "level"},
+{"lowres", "decode at 1= 1/2, 2=1/4, 3=1/8 resolutions", OFFSET(lowres), AV_OPT_TYPE_INT, {.dbl = 0 }, 0, INT_MAX, V|A|D},
+{"skip_threshold", "frame skip threshold", OFFSET(frame_skip_threshold), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
+{"skip_factor", "frame skip factor", OFFSET(frame_skip_factor), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
+{"skip_exp", "frame skip exponent", OFFSET(frame_skip_exp), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
+{"skipcmp", "frame skip compare function", OFFSET(frame_skip_cmp), AV_OPT_TYPE_INT, {.dbl = FF_CMP_DCTMAX }, INT_MIN, INT_MAX, V|E, "cmp_func"},
+{"border_mask", "increases the quantizer for macroblocks close to borders", OFFSET(border_masking), AV_OPT_TYPE_FLOAT, {.dbl = DEFAULT }, -FLT_MAX, FLT_MAX, V|E},
+{"mblmin", "min macroblock lagrange factor (VBR)", OFFSET(mb_lmin), AV_OPT_TYPE_INT, {.dbl = FF_QP2LAMBDA * 2 }, 1, FF_LAMBDA_MAX, V|E},
+{"mblmax", "max macroblock lagrange factor (VBR)", OFFSET(mb_lmax), AV_OPT_TYPE_INT, {.dbl = FF_QP2LAMBDA * 31 }, 1, FF_LAMBDA_MAX, V|E},
+{"mepc", "motion estimation bitrate penalty compensation (1.0 = 256)", OFFSET(me_penalty_compensation), AV_OPT_TYPE_INT, {.dbl = 256 }, INT_MIN, INT_MAX, V|E},
+{"skip_loop_filter", NULL, OFFSET(skip_loop_filter), AV_OPT_TYPE_INT, {.dbl = AVDISCARD_DEFAULT }, INT_MIN, INT_MAX, V|D, "avdiscard"},
+{"skip_idct" , NULL, OFFSET(skip_idct) , AV_OPT_TYPE_INT, {.dbl = AVDISCARD_DEFAULT }, INT_MIN, INT_MAX, V|D, "avdiscard"},
+{"skip_frame" , NULL, OFFSET(skip_frame) , AV_OPT_TYPE_INT, {.dbl = AVDISCARD_DEFAULT }, INT_MIN, INT_MAX, V|D, "avdiscard"},
+{"none" , NULL, 0, AV_OPT_TYPE_CONST, {.dbl = AVDISCARD_NONE }, INT_MIN, INT_MAX, V|D, "avdiscard"},
+{"default" , NULL, 0, AV_OPT_TYPE_CONST, {.dbl = AVDISCARD_DEFAULT }, INT_MIN, INT_MAX, V|D, "avdiscard"},
+{"noref" , NULL, 0, AV_OPT_TYPE_CONST, {.dbl = AVDISCARD_NONREF }, INT_MIN, INT_MAX, V|D, "avdiscard"},
+{"bidir" , NULL, 0, AV_OPT_TYPE_CONST, {.dbl = AVDISCARD_BIDIR }, INT_MIN, INT_MAX, V|D, "avdiscard"},
+{"nokey" , NULL, 0, AV_OPT_TYPE_CONST, {.dbl = AVDISCARD_NONKEY }, INT_MIN, INT_MAX, V|D, "avdiscard"},
+{"all" , NULL, 0, AV_OPT_TYPE_CONST, {.dbl = AVDISCARD_ALL }, INT_MIN, INT_MAX, V|D, "avdiscard"},
+{"bidir_refine", "refine the two motion vectors used in bidirectional macroblocks", OFFSET(bidir_refine), AV_OPT_TYPE_INT, {.dbl = 1 }, 0, 4, V|E},
+{"brd_scale", "downscales frames for dynamic B-frame decision", OFFSET(brd_scale), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, 10, V|E},
+#if FF_API_X264_GLOBAL_OPTS
+{"crf", "enables constant quality mode, and selects the quality (x264/VP8)", OFFSET(crf), AV_OPT_TYPE_FLOAT, {.dbl = DEFAULT }, 0, 63, V|E},
+{"cqp", "constant quantization parameter rate control method", OFFSET(cqp), AV_OPT_TYPE_INT, {.dbl = -1 }, INT_MIN, INT_MAX, V|E},
+#endif
+{"keyint_min", "minimum interval between IDR-frames", OFFSET(keyint_min), AV_OPT_TYPE_INT, {.dbl = 25 }, INT_MIN, INT_MAX, V|E},
+{"refs", "reference frames to consider for motion compensation", OFFSET(refs), AV_OPT_TYPE_INT, {.dbl = 1 }, INT_MIN, INT_MAX, V|E},
+{"chromaoffset", "chroma qp offset from luma", OFFSET(chromaoffset), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
+#if FF_API_X264_GLOBAL_OPTS
+{"bframebias", "influences how often B-frames are used", OFFSET(bframebias), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
+#endif
+{"trellis", "rate-distortion optimal quantization", OFFSET(trellis), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|A|E},
+#if FF_API_X264_GLOBAL_OPTS
+{"directpred", "direct mv prediction mode - 0 (none), 1 (spatial), 2 (temporal), 3 (auto)", OFFSET(directpred), AV_OPT_TYPE_INT, {.dbl = -1 }, INT_MIN, INT_MAX, V|E},
+{"bpyramid", "allows B-frames to be used as references for predicting", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_BPYRAMID }, INT_MIN, INT_MAX, V|E, "flags2"},
+{"wpred", "weighted biprediction for b-frames (H.264)", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_WPRED }, INT_MIN, INT_MAX, V|E, "flags2"},
+{"mixed_refs", "one reference per partition, as opposed to one reference per macroblock", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_MIXED_REFS }, INT_MIN, INT_MAX, V|E, "flags2"},
+{"dct8x8", "high profile 8x8 transform (H.264)", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_8X8DCT }, INT_MIN, INT_MAX, V|E, "flags2"},
+{"fastpskip", "fast pskip (H.264)", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_FASTPSKIP }, INT_MIN, INT_MAX, V|E, "flags2"},
+{"aud", "access unit delimiters (H.264)", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_AUD }, INT_MIN, INT_MAX, V|E, "flags2"},
+#endif
+{"skiprd", "RD optimal MB level residual skipping", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_SKIP_RD }, INT_MIN, INT_MAX, V|E, "flags2"},
+#if FF_API_X264_GLOBAL_OPTS
+{"complexityblur", "reduce fluctuations in qp (before curve compression)", OFFSET(complexityblur), AV_OPT_TYPE_FLOAT, {.dbl = -1 }, -1, FLT_MAX, V|E},
+{"deblockalpha", "in-loop deblocking filter alphac0 parameter", OFFSET(deblockalpha), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, -6, 6, V|E},
+{"deblockbeta", "in-loop deblocking filter beta parameter", OFFSET(deblockbeta), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, -6, 6, V|E},
+{"partitions", "macroblock subpartition sizes to consider", OFFSET(partitions), AV_OPT_TYPE_FLAGS, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E, "partitions"},
+{"parti4x4", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = X264_PART_I4X4 }, INT_MIN, INT_MAX, V|E, "partitions"},
+{"parti8x8", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = X264_PART_I8X8 }, INT_MIN, INT_MAX, V|E, "partitions"},
+{"partp4x4", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = X264_PART_P4X4 }, INT_MIN, INT_MAX, V|E, "partitions"},
+{"partp8x8", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = X264_PART_P8X8 }, INT_MIN, INT_MAX, V|E, "partitions"},
+{"partb8x8", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = X264_PART_B8X8 }, INT_MIN, INT_MAX, V|E, "partitions"},
+#endif
+{"sc_factor", "multiplied by qscale for each frame and added to scene_change_score", OFFSET(scenechange_factor), AV_OPT_TYPE_INT, {.dbl = 6 }, 0, INT_MAX, V|E},
+{"mv0_threshold", NULL, OFFSET(mv0_threshold), AV_OPT_TYPE_INT, {.dbl = 256 }, 0, INT_MAX, V|E},
+#if FF_API_MPEGVIDEO_GLOBAL_OPTS
+{"ivlc", "intra vlc table", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_INTRA_VLC }, INT_MIN, INT_MAX, V|E, "flags2"},
#endif
-{"qns", "quantizer noise shaping", OFFSET(quantizer_noise_shaping), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
-{"threads", NULL, OFFSET(thread_count), FF_OPT_TYPE_INT, {.dbl = 1 }, INT_MIN, INT_MAX, V|E|D},
-{"me_threshold", "motion estimaton threshold", OFFSET(me_threshold), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
-{"mb_threshold", "macroblock threshold", OFFSET(mb_threshold), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
-{"dc", "intra_dc_precision", OFFSET(intra_dc_precision), FF_OPT_TYPE_INT, {.dbl = 0 }, INT_MIN, INT_MAX, V|E},
-{"nssew", "nsse weight", OFFSET(nsse_weight), FF_OPT_TYPE_INT, {.dbl = 8 }, INT_MIN, INT_MAX, V|E},
-{"skip_top", "number of macroblock rows at the top which are skipped", OFFSET(skip_top), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|D},
-{"skip_bottom", "number of macroblock rows at the bottom which are skipped", OFFSET(skip_bottom), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|D},
-{"profile", NULL, OFFSET(profile), FF_OPT_TYPE_INT, {.dbl = FF_PROFILE_UNKNOWN }, INT_MIN, INT_MAX, V|A|E, "profile"},
-{"unknown", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_PROFILE_UNKNOWN }, INT_MIN, INT_MAX, V|A|E, "profile"},
-{"aac_main", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_PROFILE_AAC_MAIN }, INT_MIN, INT_MAX, A|E, "profile"},
-{"aac_low", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_PROFILE_AAC_LOW }, INT_MIN, INT_MAX, A|E, "profile"},
-{"aac_ssr", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_PROFILE_AAC_SSR }, INT_MIN, INT_MAX, A|E, "profile"},
-{"aac_ltp", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_PROFILE_AAC_LTP }, INT_MIN, INT_MAX, A|E, "profile"},
-{"dts", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_PROFILE_DTS }, INT_MIN, INT_MAX, A|E, "profile"},
-{"dts_es", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_PROFILE_DTS_ES }, INT_MIN, INT_MAX, A|E, "profile"},
-{"dts_96_24", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_PROFILE_DTS_96_24 }, INT_MIN, INT_MAX, A|E, "profile"},
-{"dts_hd_hra", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_PROFILE_DTS_HD_HRA }, INT_MIN, INT_MAX, A|E, "profile"},
-{"dts_hd_ma", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_PROFILE_DTS_HD_MA }, INT_MIN, INT_MAX, A|E, "profile"},
-{"level", NULL, OFFSET(level), FF_OPT_TYPE_INT, {.dbl = FF_LEVEL_UNKNOWN }, INT_MIN, INT_MAX, V|A|E, "level"},
-{"unknown", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_LEVEL_UNKNOWN }, INT_MIN, INT_MAX, V|A|E, "level"},
-{"lowres", "decode at 1= 1/2, 2=1/4, 3=1/8 resolutions", OFFSET(lowres), FF_OPT_TYPE_INT, {.dbl = 0 }, 0, INT_MAX, V|A|D},
-{"skip_threshold", "frame skip threshold", OFFSET(frame_skip_threshold), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
-{"skip_factor", "frame skip factor", OFFSET(frame_skip_factor), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
-{"skip_exp", "frame skip exponent", OFFSET(frame_skip_exp), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
-{"skipcmp", "frame skip compare function", OFFSET(frame_skip_cmp), FF_OPT_TYPE_INT, {.dbl = FF_CMP_DCTMAX }, INT_MIN, INT_MAX, V|E, "cmp_func"},
-{"border_mask", "increases the quantizer for macroblocks close to borders", OFFSET(border_masking), FF_OPT_TYPE_FLOAT, {.dbl = DEFAULT }, -FLT_MAX, FLT_MAX, V|E},
-{"mblmin", "min macroblock lagrange factor (VBR)", OFFSET(mb_lmin), FF_OPT_TYPE_INT, {.dbl = FF_QP2LAMBDA * 2 }, 1, FF_LAMBDA_MAX, V|E},
-{"mblmax", "max macroblock lagrange factor (VBR)", OFFSET(mb_lmax), FF_OPT_TYPE_INT, {.dbl = FF_QP2LAMBDA * 31 }, 1, FF_LAMBDA_MAX, V|E},
-{"mepc", "motion estimation bitrate penalty compensation (1.0 = 256)", OFFSET(me_penalty_compensation), FF_OPT_TYPE_INT, {.dbl = 256 }, INT_MIN, INT_MAX, V|E},
-{"skip_loop_filter", NULL, OFFSET(skip_loop_filter), FF_OPT_TYPE_INT, {.dbl = AVDISCARD_DEFAULT }, INT_MIN, INT_MAX, V|D, "avdiscard"},
-{"skip_idct" , NULL, OFFSET(skip_idct) , FF_OPT_TYPE_INT, {.dbl = AVDISCARD_DEFAULT }, INT_MIN, INT_MAX, V|D, "avdiscard"},
-{"skip_frame" , NULL, OFFSET(skip_frame) , FF_OPT_TYPE_INT, {.dbl = AVDISCARD_DEFAULT }, INT_MIN, INT_MAX, V|D, "avdiscard"},
-{"none" , NULL, 0, FF_OPT_TYPE_CONST, {.dbl = AVDISCARD_NONE }, INT_MIN, INT_MAX, V|D, "avdiscard"},
-{"default" , NULL, 0, FF_OPT_TYPE_CONST, {.dbl = AVDISCARD_DEFAULT }, INT_MIN, INT_MAX, V|D, "avdiscard"},
-{"noref" , NULL, 0, FF_OPT_TYPE_CONST, {.dbl = AVDISCARD_NONREF }, INT_MIN, INT_MAX, V|D, "avdiscard"},
-{"bidir" , NULL, 0, FF_OPT_TYPE_CONST, {.dbl = AVDISCARD_BIDIR }, INT_MIN, INT_MAX, V|D, "avdiscard"},
-{"nokey" , NULL, 0, FF_OPT_TYPE_CONST, {.dbl = AVDISCARD_NONKEY }, INT_MIN, INT_MAX, V|D, "avdiscard"},
-{"all" , NULL, 0, FF_OPT_TYPE_CONST, {.dbl = AVDISCARD_ALL }, INT_MIN, INT_MAX, V|D, "avdiscard"},
-{"bidir_refine", "refine the two motion vectors used in bidirectional macroblocks", OFFSET(bidir_refine), FF_OPT_TYPE_INT, {.dbl = 1 }, 0, 4, V|E},
-{"brd_scale", "downscales frames for dynamic B-frame decision", OFFSET(brd_scale), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, 10, V|E},
-{"crf", "enables constant quality mode, and selects the quality (x264)", OFFSET(crf), FF_OPT_TYPE_FLOAT, {.dbl = DEFAULT }, 0, 51, V|E},
-{"cqp", "constant quantization parameter rate control method", OFFSET(cqp), FF_OPT_TYPE_INT, {.dbl = -1 }, INT_MIN, INT_MAX, V|E},
-{"keyint_min", "minimum interval between IDR-frames (x264)", OFFSET(keyint_min), FF_OPT_TYPE_INT, {.dbl = 25 }, INT_MIN, INT_MAX, V|E},
-{"refs", "reference frames to consider for motion compensation (Snow)", OFFSET(refs), FF_OPT_TYPE_INT, {.dbl = 1 }, INT_MIN, INT_MAX, V|E},
-{"chromaoffset", "chroma qp offset from luma", OFFSET(chromaoffset), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
-{"bframebias", "influences how often B-frames are used", OFFSET(bframebias), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
-{"trellis", "rate-distortion optimal quantization", OFFSET(trellis), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|A|E},
-{"directpred", "direct mv prediction mode - 0 (none), 1 (spatial), 2 (temporal), 3 (auto)", OFFSET(directpred), FF_OPT_TYPE_INT, {.dbl = 2 }, INT_MIN, INT_MAX, V|E},
-{"bpyramid", "allows B-frames to be used as references for predicting", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_BPYRAMID }, INT_MIN, INT_MAX, V|E, "flags2"},
-{"wpred", "weighted biprediction for b-frames (H.264)", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_WPRED }, INT_MIN, INT_MAX, V|E, "flags2"},
-{"mixed_refs", "one reference per partition, as opposed to one reference per macroblock", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_MIXED_REFS }, INT_MIN, INT_MAX, V|E, "flags2"},
-{"dct8x8", "high profile 8x8 transform (H.264)", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_8X8DCT }, INT_MIN, INT_MAX, V|E, "flags2"},
-{"fastpskip", "fast pskip (H.264)", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_FASTPSKIP }, INT_MIN, INT_MAX, V|E, "flags2"},
-{"aud", "access unit delimiters (H.264)", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_AUD }, INT_MIN, INT_MAX, V|E, "flags2"},
-{"skiprd", "RD optimal MB level residual skipping", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_SKIP_RD }, INT_MIN, INT_MAX, V|E, "flags2"},
-{"complexityblur", "reduce fluctuations in qp (before curve compression)", OFFSET(complexityblur), FF_OPT_TYPE_FLOAT, {.dbl = 20.0 }, FLT_MIN, FLT_MAX, V|E},
-{"deblockalpha", "in-loop deblocking filter alphac0 parameter", OFFSET(deblockalpha), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, -6, 6, V|E},
-{"deblockbeta", "in-loop deblocking filter beta parameter", OFFSET(deblockbeta), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, -6, 6, V|E},
-{"partitions", "macroblock subpartition sizes to consider", OFFSET(partitions), FF_OPT_TYPE_FLAGS, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E, "partitions"},
-{"parti4x4", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = X264_PART_I4X4 }, INT_MIN, INT_MAX, V|E, "partitions"},
-{"parti8x8", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = X264_PART_I8X8 }, INT_MIN, INT_MAX, V|E, "partitions"},
-{"partp4x4", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = X264_PART_P4X4 }, INT_MIN, INT_MAX, V|E, "partitions"},
-{"partp8x8", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = X264_PART_P8X8 }, INT_MIN, INT_MAX, V|E, "partitions"},
-{"partb8x8", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = X264_PART_B8X8 }, INT_MIN, INT_MAX, V|E, "partitions"},
-{"sc_factor", "multiplied by qscale for each frame and added to scene_change_score", OFFSET(scenechange_factor), FF_OPT_TYPE_INT, {.dbl = 6 }, 0, INT_MAX, V|E},
-{"mv0_threshold", NULL, OFFSET(mv0_threshold), FF_OPT_TYPE_INT, {.dbl = 256 }, 0, INT_MAX, V|E},
-{"ivlc", "intra vlc table", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_INTRA_VLC }, INT_MIN, INT_MAX, V|E, "flags2"},
-{"b_sensitivity", "adjusts sensitivity of b_frame_strategy 1", OFFSET(b_sensitivity), FF_OPT_TYPE_INT, {.dbl = 40 }, 1, INT_MAX, V|E},
-{"compression_level", NULL, OFFSET(compression_level), FF_OPT_TYPE_INT, {.dbl = FF_COMPRESSION_DEFAULT }, INT_MIN, INT_MAX, V|A|E},
-{"min_prediction_order", NULL, OFFSET(min_prediction_order), FF_OPT_TYPE_INT, {.dbl = -1 }, INT_MIN, INT_MAX, A|E},
-{"max_prediction_order", NULL, OFFSET(max_prediction_order), FF_OPT_TYPE_INT, {.dbl = -1 }, INT_MIN, INT_MAX, A|E},
+{"b_sensitivity", "adjusts sensitivity of b_frame_strategy 1", OFFSET(b_sensitivity), AV_OPT_TYPE_INT, {.dbl = 40 }, 1, INT_MAX, V|E},
+{"compression_level", NULL, OFFSET(compression_level), AV_OPT_TYPE_INT, {.dbl = FF_COMPRESSION_DEFAULT }, INT_MIN, INT_MAX, V|A|E},
+{"min_prediction_order", NULL, OFFSET(min_prediction_order), AV_OPT_TYPE_INT, {.dbl = -1 }, INT_MIN, INT_MAX, A|E},
+{"max_prediction_order", NULL, OFFSET(max_prediction_order), AV_OPT_TYPE_INT, {.dbl = -1 }, INT_MIN, INT_MAX, A|E},
#if FF_API_FLAC_GLOBAL_OPTS
-{"lpc_coeff_precision", "deprecated, use flac-specific options", OFFSET(lpc_coeff_precision), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, INT_MAX, A|E},
-{"prediction_order_method", "deprecated, use flac-specific options", OFFSET(prediction_order_method), FF_OPT_TYPE_INT, {.dbl = -1 }, INT_MIN, INT_MAX, A|E},
-{"min_partition_order", "deprecated, use flac-specific options", OFFSET(min_partition_order), FF_OPT_TYPE_INT, {.dbl = -1 }, INT_MIN, INT_MAX, A|E},
-{"max_partition_order", "deprecated, use flac-specific options", OFFSET(max_partition_order), FF_OPT_TYPE_INT, {.dbl = -1 }, INT_MIN, INT_MAX, A|E},
+{"lpc_coeff_precision", "deprecated, use flac-specific options", OFFSET(lpc_coeff_precision), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, INT_MAX, A|E},
+{"prediction_order_method", "deprecated, use flac-specific options", OFFSET(prediction_order_method), AV_OPT_TYPE_INT, {.dbl = -1 }, INT_MIN, INT_MAX, A|E},
+{"min_partition_order", "deprecated, use flac-specific options", OFFSET(min_partition_order), AV_OPT_TYPE_INT, {.dbl = -1 }, INT_MIN, INT_MAX, A|E},
+{"max_partition_order", "deprecated, use flac-specific options", OFFSET(max_partition_order), AV_OPT_TYPE_INT, {.dbl = -1 }, INT_MIN, INT_MAX, A|E},
+#endif
+{"timecode_frame_start", "GOP timecode frame start number, in non drop frame format", OFFSET(timecode_frame_start), AV_OPT_TYPE_INT64, {.dbl = 0 }, 0, INT64_MAX, V|E},
+#if FF_API_MPEGVIDEO_GLOBAL_OPTS
+{"drop_frame_timecode", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_DROP_FRAME_TIMECODE }, INT_MIN, INT_MAX, V|E, "flags2"},
+{"non_linear_q", "use non linear quantizer", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_NON_LINEAR_QUANT }, INT_MIN, INT_MAX, V|E, "flags2"},
#endif
-{"timecode_frame_start", "GOP timecode frame start number, in non drop frame format", OFFSET(timecode_frame_start), FF_OPT_TYPE_INT64, {.dbl = 0 }, 0, INT64_MAX, V|E},
-{"drop_frame_timecode", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_DROP_FRAME_TIMECODE }, INT_MIN, INT_MAX, V|E, "flags2"},
-{"non_linear_q", "use non linear quantizer", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_NON_LINEAR_QUANT }, INT_MIN, INT_MAX, V|E, "flags2"},
#if FF_API_REQUEST_CHANNELS
-{"request_channels", "set desired number of audio channels", OFFSET(request_channels), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, INT_MAX, A|D},
+{"request_channels", "set desired number of audio channels", OFFSET(request_channels), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, INT_MAX, A|D},
+#endif
+#if FF_API_DRC_SCALE
+{"drc_scale", "percentage of dynamic range compression to apply", OFFSET(drc_scale), AV_OPT_TYPE_FLOAT, {.dbl = 0.0 }, 0.0, 1.0, A|D},
+#endif
+#if FF_API_LAME_GLOBAL_OPTS
+{"reservoir", "use bit reservoir", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_BIT_RESERVOIR }, INT_MIN, INT_MAX, A|E, "flags2"},
+#endif
+#if FF_API_X264_GLOBAL_OPTS
+{"mbtree", "use macroblock tree ratecontrol (x264 only)", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_MBTREE }, INT_MIN, INT_MAX, V|E, "flags2"},
+#endif
+{"bits_per_raw_sample", NULL, OFFSET(bits_per_raw_sample), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
+{"channel_layout", NULL, OFFSET(channel_layout), AV_OPT_TYPE_INT64, {.dbl = DEFAULT }, 0, INT64_MAX, A|E|D, "channel_layout"},
+{"request_channel_layout", NULL, OFFSET(request_channel_layout), AV_OPT_TYPE_INT64, {.dbl = DEFAULT }, 0, INT64_MAX, A|D, "request_channel_layout"},
+{"rc_max_vbv_use", NULL, OFFSET(rc_max_available_vbv_use), AV_OPT_TYPE_FLOAT, {.dbl = 1.0/3 }, 0.0, FLT_MAX, V|E},
+{"rc_min_vbv_use", NULL, OFFSET(rc_min_vbv_overflow_use), AV_OPT_TYPE_FLOAT, {.dbl = 3 }, 0.0, FLT_MAX, V|E},
+{"ticks_per_frame", NULL, OFFSET(ticks_per_frame), AV_OPT_TYPE_INT, {.dbl = 1 }, 1, INT_MAX, A|V|E|D},
+{"color_primaries", NULL, OFFSET(color_primaries), AV_OPT_TYPE_INT, {.dbl = AVCOL_PRI_UNSPECIFIED }, 1, AVCOL_PRI_NB-1, V|E|D},
+{"color_trc", NULL, OFFSET(color_trc), AV_OPT_TYPE_INT, {.dbl = AVCOL_TRC_UNSPECIFIED }, 1, AVCOL_TRC_NB-1, V|E|D},
+{"colorspace", NULL, OFFSET(colorspace), AV_OPT_TYPE_INT, {.dbl = AVCOL_SPC_UNSPECIFIED }, 1, AVCOL_SPC_NB-1, V|E|D},
+{"color_range", NULL, OFFSET(color_range), AV_OPT_TYPE_INT, {.dbl = AVCOL_RANGE_UNSPECIFIED }, 0, AVCOL_RANGE_NB-1, V|E|D},
+{"chroma_sample_location", NULL, OFFSET(chroma_sample_location), AV_OPT_TYPE_INT, {.dbl = AVCHROMA_LOC_UNSPECIFIED }, 0, AVCHROMA_LOC_NB-1, V|E|D},
+#if FF_API_X264_GLOBAL_OPTS
+{"psy", "use psycho visual optimization", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_PSY }, INT_MIN, INT_MAX, V|E, "flags2"},
+{"psy_rd", "specify psycho visual strength", OFFSET(psy_rd), AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1, FLT_MAX, V|E},
+{"psy_trellis", "specify psycho visual trellis", OFFSET(psy_trellis), AV_OPT_TYPE_FLOAT, {.dbl = -1 }, -1, FLT_MAX, V|E},
+{"aq_mode", "specify aq method", OFFSET(aq_mode), AV_OPT_TYPE_INT, {.dbl = -1 }, -1, INT_MAX, V|E},
+{"aq_strength", "specify aq strength", OFFSET(aq_strength), AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1, FLT_MAX, V|E},
+{"rc_lookahead", "specify number of frames to look ahead for frametype", OFFSET(rc_lookahead), AV_OPT_TYPE_INT, {.dbl = 40 }, -1, INT_MAX, V|E},
+{"ssim", "ssim will be calculated during encoding", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_SSIM }, INT_MIN, INT_MAX, V|E, "flags2"},
+{"intra_refresh", "use periodic insertion of intra blocks instead of keyframes", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_INTRA_REFRESH }, INT_MIN, INT_MAX, V|E, "flags2"},
+{"crf_max", "in crf mode, prevents vbv from lowering quality beyond this point", OFFSET(crf_max), AV_OPT_TYPE_FLOAT, {.dbl = DEFAULT }, 0, 51, V|E},
#endif
-{"drc_scale", "percentage of dynamic range compression to apply", OFFSET(drc_scale), FF_OPT_TYPE_FLOAT, {.dbl = 1.0 }, 0.0, 1.0, A|D},
-{"reservoir", "use bit reservoir", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_BIT_RESERVOIR }, INT_MIN, INT_MAX, A|E, "flags2"},
-{"mbtree", "use macroblock tree ratecontrol (x264 only)", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_MBTREE }, INT_MIN, INT_MAX, V|E, "flags2"},
-{"bits_per_raw_sample", NULL, OFFSET(bits_per_raw_sample), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
-{"channel_layout", NULL, OFFSET(channel_layout), FF_OPT_TYPE_INT64, {.dbl = DEFAULT }, 0, INT64_MAX, A|E|D, "channel_layout"},
-{"request_channel_layout", NULL, OFFSET(request_channel_layout), FF_OPT_TYPE_INT64, {.dbl = DEFAULT }, 0, INT64_MAX, A|D, "request_channel_layout"},
-{"rc_max_vbv_use", NULL, OFFSET(rc_max_available_vbv_use), FF_OPT_TYPE_FLOAT, {.dbl = 1.0/3 }, 0.0, FLT_MAX, V|E},
-{"rc_min_vbv_use", NULL, OFFSET(rc_min_vbv_overflow_use), FF_OPT_TYPE_FLOAT, {.dbl = 3 }, 0.0, FLT_MAX, V|E},
-{"ticks_per_frame", NULL, OFFSET(ticks_per_frame), FF_OPT_TYPE_INT, {.dbl = 1 }, 1, INT_MAX, A|V|E|D},
-{"color_primaries", NULL, OFFSET(color_primaries), FF_OPT_TYPE_INT, {.dbl = AVCOL_PRI_UNSPECIFIED }, 1, AVCOL_PRI_NB-1, V|E|D},
-{"color_trc", NULL, OFFSET(color_trc), FF_OPT_TYPE_INT, {.dbl = AVCOL_TRC_UNSPECIFIED }, 1, AVCOL_TRC_NB-1, V|E|D},
-{"colorspace", NULL, OFFSET(colorspace), FF_OPT_TYPE_INT, {.dbl = AVCOL_SPC_UNSPECIFIED }, 1, AVCOL_SPC_NB-1, V|E|D},
-{"color_range", NULL, OFFSET(color_range), FF_OPT_TYPE_INT, {.dbl = AVCOL_RANGE_UNSPECIFIED }, 0, AVCOL_RANGE_NB-1, V|E|D},
-{"chroma_sample_location", NULL, OFFSET(chroma_sample_location), FF_OPT_TYPE_INT, {.dbl = AVCHROMA_LOC_UNSPECIFIED }, 0, AVCHROMA_LOC_NB-1, V|E|D},
-{"psy", "use psycho visual optimization", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_PSY }, INT_MIN, INT_MAX, V|E, "flags2"},
-{"psy_rd", "specify psycho visual strength", OFFSET(psy_rd), FF_OPT_TYPE_FLOAT, {.dbl = 1.0 }, 0, FLT_MAX, V|E},
-{"psy_trellis", "specify psycho visual trellis", OFFSET(psy_trellis), FF_OPT_TYPE_FLOAT, {.dbl = 0 }, 0, FLT_MAX, V|E},
-{"aq_mode", "specify aq method", OFFSET(aq_mode), FF_OPT_TYPE_INT, {.dbl = 1 }, 0, INT_MAX, V|E},
-{"aq_strength", "specify aq strength", OFFSET(aq_strength), FF_OPT_TYPE_FLOAT, {.dbl = 1.0 }, 0, FLT_MAX, V|E},
-{"rc_lookahead", "specify number of frames to look ahead for frametype", OFFSET(rc_lookahead), FF_OPT_TYPE_INT, {.dbl = 40 }, 0, INT_MAX, V|E},
-{"ssim", "ssim will be calculated during encoding", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_SSIM }, INT_MIN, INT_MAX, V|E, "flags2"},
-{"intra_refresh", "use periodic insertion of intra blocks instead of keyframes", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_INTRA_REFRESH }, INT_MIN, INT_MAX, V|E, "flags2"},
-{"crf_max", "in crf mode, prevents vbv from lowering quality beyond this point", OFFSET(crf_max), FF_OPT_TYPE_FLOAT, {.dbl = DEFAULT }, 0, 51, V|E},
-{"log_level_offset", "set the log level offset", OFFSET(log_level_offset), FF_OPT_TYPE_INT, {.dbl = 0 }, INT_MIN, INT_MAX },
+{"log_level_offset", "set the log level offset", OFFSET(log_level_offset), AV_OPT_TYPE_INT, {.dbl = 0 }, INT_MIN, INT_MAX },
#if FF_API_FLAC_GLOBAL_OPTS
-{"lpc_type", "deprecated, use flac-specific options", OFFSET(lpc_type), FF_OPT_TYPE_INT, {.dbl = AV_LPC_TYPE_DEFAULT }, AV_LPC_TYPE_DEFAULT, AV_LPC_TYPE_NB-1, A|E},
-{"none", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = AV_LPC_TYPE_NONE }, INT_MIN, INT_MAX, A|E, "lpc_type"},
-{"fixed", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = AV_LPC_TYPE_FIXED }, INT_MIN, INT_MAX, A|E, "lpc_type"},
-{"levinson", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = AV_LPC_TYPE_LEVINSON }, INT_MIN, INT_MAX, A|E, "lpc_type"},
-{"cholesky", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = AV_LPC_TYPE_CHOLESKY }, INT_MIN, INT_MAX, A|E, "lpc_type"},
-{"lpc_passes", "deprecated, use flac-specific options", OFFSET(lpc_passes), FF_OPT_TYPE_INT, {.dbl = -1 }, INT_MIN, INT_MAX, A|E},
+{"lpc_type", "deprecated, use flac-specific options", OFFSET(lpc_type), AV_OPT_TYPE_INT, {.dbl = AV_LPC_TYPE_DEFAULT }, AV_LPC_TYPE_DEFAULT, AV_LPC_TYPE_NB-1, A|E},
+{"none", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = AV_LPC_TYPE_NONE }, INT_MIN, INT_MAX, A|E, "lpc_type"},
+{"fixed", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = AV_LPC_TYPE_FIXED }, INT_MIN, INT_MAX, A|E, "lpc_type"},
+{"levinson", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = AV_LPC_TYPE_LEVINSON }, INT_MIN, INT_MAX, A|E, "lpc_type"},
+{"cholesky", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = AV_LPC_TYPE_CHOLESKY }, INT_MIN, INT_MAX, A|E, "lpc_type"},
+{"lpc_passes", "deprecated, use flac-specific options", OFFSET(lpc_passes), AV_OPT_TYPE_INT, {.dbl = -1 }, INT_MIN, INT_MAX, A|E},
#endif
-{"slices", "number of slices, used in parallelized decoding", OFFSET(slices), FF_OPT_TYPE_INT, {.dbl = 0 }, 0, INT_MAX, V|E},
-{"thread_type", "select multithreading type", OFFSET(thread_type), FF_OPT_TYPE_INT, {.dbl = FF_THREAD_SLICE|FF_THREAD_FRAME }, 0, INT_MAX, V|E|D, "thread_type"},
-{"slice", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_THREAD_SLICE }, INT_MIN, INT_MAX, V|E|D, "thread_type"},
-{"frame", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_THREAD_FRAME }, INT_MIN, INT_MAX, V|E|D, "thread_type"},
-{"vbv_delay", "initial buffer fill time in periods of 27Mhz clock", 0, FF_OPT_TYPE_INT64, {.dbl = 0 }, 0, INT64_MAX},
-{"audio_service_type", "audio service type", OFFSET(audio_service_type), FF_OPT_TYPE_INT, {.dbl = AV_AUDIO_SERVICE_TYPE_MAIN }, 0, AV_AUDIO_SERVICE_TYPE_NB-1, A|E, "audio_service_type"},
-{"ma", "Main Audio Service", 0, FF_OPT_TYPE_CONST, {.dbl = AV_AUDIO_SERVICE_TYPE_MAIN }, INT_MIN, INT_MAX, A|E, "audio_service_type"},
-{"ef", "Effects", 0, FF_OPT_TYPE_CONST, {.dbl = AV_AUDIO_SERVICE_TYPE_EFFECTS }, INT_MIN, INT_MAX, A|E, "audio_service_type"},
-{"vi", "Visually Impaired", 0, FF_OPT_TYPE_CONST, {.dbl = AV_AUDIO_SERVICE_TYPE_VISUALLY_IMPAIRED }, INT_MIN, INT_MAX, A|E, "audio_service_type"},
-{"hi", "Hearing Impaired", 0, FF_OPT_TYPE_CONST, {.dbl = AV_AUDIO_SERVICE_TYPE_HEARING_IMPAIRED }, INT_MIN, INT_MAX, A|E, "audio_service_type"},
-{"di", "Dialogue", 0, FF_OPT_TYPE_CONST, {.dbl = AV_AUDIO_SERVICE_TYPE_DIALOGUE }, INT_MIN, INT_MAX, A|E, "audio_service_type"},
-{"co", "Commentary", 0, FF_OPT_TYPE_CONST, {.dbl = AV_AUDIO_SERVICE_TYPE_COMMENTARY }, INT_MIN, INT_MAX, A|E, "audio_service_type"},
-{"em", "Emergency", 0, FF_OPT_TYPE_CONST, {.dbl = AV_AUDIO_SERVICE_TYPE_EMERGENCY }, INT_MIN, INT_MAX, A|E, "audio_service_type"},
-{"vo", "Voice Over", 0, FF_OPT_TYPE_CONST, {.dbl = AV_AUDIO_SERVICE_TYPE_VOICE_OVER }, INT_MIN, INT_MAX, A|E, "audio_service_type"},
-{"ka", "Karaoke", 0, FF_OPT_TYPE_CONST, {.dbl = AV_AUDIO_SERVICE_TYPE_KARAOKE }, INT_MIN, INT_MAX, A|E, "audio_service_type"},
-{"request_sample_fmt", NULL, OFFSET(request_sample_fmt), FF_OPT_TYPE_INT, {.dbl = AV_SAMPLE_FMT_NONE }, AV_SAMPLE_FMT_NONE, AV_SAMPLE_FMT_NB-1, A|D, "request_sample_fmt"},
-{"u8" , "8-bit unsigned integer", 0, FF_OPT_TYPE_CONST, {.dbl = AV_SAMPLE_FMT_U8 }, INT_MIN, INT_MAX, A|D, "request_sample_fmt"},
-{"s16", "16-bit signed integer", 0, FF_OPT_TYPE_CONST, {.dbl = AV_SAMPLE_FMT_S16 }, INT_MIN, INT_MAX, A|D, "request_sample_fmt"},
-{"s32", "32-bit signed integer", 0, FF_OPT_TYPE_CONST, {.dbl = AV_SAMPLE_FMT_S32 }, INT_MIN, INT_MAX, A|D, "request_sample_fmt"},
-{"flt", "32-bit float", 0, FF_OPT_TYPE_CONST, {.dbl = AV_SAMPLE_FMT_FLT }, INT_MIN, INT_MAX, A|D, "request_sample_fmt"},
-{"dbl", "64-bit double", 0, FF_OPT_TYPE_CONST, {.dbl = AV_SAMPLE_FMT_DBL }, INT_MIN, INT_MAX, A|D, "request_sample_fmt"},
+{"slices", "number of slices, used in parallelized decoding", OFFSET(slices), AV_OPT_TYPE_INT, {.dbl = 0 }, 0, INT_MAX, V|E},
+{"thread_type", "select multithreading type", OFFSET(thread_type), AV_OPT_TYPE_FLAGS, {.dbl = FF_THREAD_SLICE|FF_THREAD_FRAME }, 0, INT_MAX, V|E|D, "thread_type"},
+{"slice", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_THREAD_SLICE }, INT_MIN, INT_MAX, V|E|D, "thread_type"},
+{"frame", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_THREAD_FRAME }, INT_MIN, INT_MAX, V|E|D, "thread_type"},
+{"audio_service_type", "audio service type", OFFSET(audio_service_type), AV_OPT_TYPE_INT, {.dbl = AV_AUDIO_SERVICE_TYPE_MAIN }, 0, AV_AUDIO_SERVICE_TYPE_NB-1, A|E, "audio_service_type"},
+{"ma", "Main Audio Service", 0, AV_OPT_TYPE_CONST, {.dbl = AV_AUDIO_SERVICE_TYPE_MAIN }, INT_MIN, INT_MAX, A|E, "audio_service_type"},
+{"ef", "Effects", 0, AV_OPT_TYPE_CONST, {.dbl = AV_AUDIO_SERVICE_TYPE_EFFECTS }, INT_MIN, INT_MAX, A|E, "audio_service_type"},
+{"vi", "Visually Impaired", 0, AV_OPT_TYPE_CONST, {.dbl = AV_AUDIO_SERVICE_TYPE_VISUALLY_IMPAIRED }, INT_MIN, INT_MAX, A|E, "audio_service_type"},
+{"hi", "Hearing Impaired", 0, AV_OPT_TYPE_CONST, {.dbl = AV_AUDIO_SERVICE_TYPE_HEARING_IMPAIRED }, INT_MIN, INT_MAX, A|E, "audio_service_type"},
+{"di", "Dialogue", 0, AV_OPT_TYPE_CONST, {.dbl = AV_AUDIO_SERVICE_TYPE_DIALOGUE }, INT_MIN, INT_MAX, A|E, "audio_service_type"},
+{"co", "Commentary", 0, AV_OPT_TYPE_CONST, {.dbl = AV_AUDIO_SERVICE_TYPE_COMMENTARY }, INT_MIN, INT_MAX, A|E, "audio_service_type"},
+{"em", "Emergency", 0, AV_OPT_TYPE_CONST, {.dbl = AV_AUDIO_SERVICE_TYPE_EMERGENCY }, INT_MIN, INT_MAX, A|E, "audio_service_type"},
+{"vo", "Voice Over", 0, AV_OPT_TYPE_CONST, {.dbl = AV_AUDIO_SERVICE_TYPE_VOICE_OVER }, INT_MIN, INT_MAX, A|E, "audio_service_type"},
+{"ka", "Karaoke", 0, AV_OPT_TYPE_CONST, {.dbl = AV_AUDIO_SERVICE_TYPE_KARAOKE }, INT_MIN, INT_MAX, A|E, "audio_service_type"},
+{"request_sample_fmt", "sample format audio decoders should prefer", OFFSET(request_sample_fmt), AV_OPT_TYPE_INT, {.dbl = AV_SAMPLE_FMT_NONE }, AV_SAMPLE_FMT_NONE, AV_SAMPLE_FMT_NB-1, A|D, "request_sample_fmt"},
+{"u8" , "8-bit unsigned integer", 0, AV_OPT_TYPE_CONST, {.dbl = AV_SAMPLE_FMT_U8 }, INT_MIN, INT_MAX, A|D, "request_sample_fmt"},
+{"s16", "16-bit signed integer", 0, AV_OPT_TYPE_CONST, {.dbl = AV_SAMPLE_FMT_S16 }, INT_MIN, INT_MAX, A|D, "request_sample_fmt"},
+{"s32", "32-bit signed integer", 0, AV_OPT_TYPE_CONST, {.dbl = AV_SAMPLE_FMT_S32 }, INT_MIN, INT_MAX, A|D, "request_sample_fmt"},
+{"flt", "32-bit float", 0, AV_OPT_TYPE_CONST, {.dbl = AV_SAMPLE_FMT_FLT }, INT_MIN, INT_MAX, A|D, "request_sample_fmt"},
+{"dbl", "64-bit double", 0, AV_OPT_TYPE_CONST, {.dbl = AV_SAMPLE_FMT_DBL }, INT_MIN, INT_MAX, A|D, "request_sample_fmt"},
{NULL},
};
@@ -476,40 +522,51 @@ static const AVOption options[]={
#undef D
#undef DEFAULT
-static const AVClass av_codec_context_class = { "AVCodecContext", context_to_name, options, LIBAVUTIL_VERSION_INT, OFFSET(log_level_offset), .opt_find = opt_find};
+static const AVClass av_codec_context_class = {
+ .class_name = "AVCodecContext",
+ .item_name = context_to_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+ .log_level_offset_offset = OFFSET(log_level_offset),
+ .child_next = codec_child_next,
+ .child_class_next = codec_child_class_next,
+};
+#if FF_API_ALLOC_CONTEXT
void avcodec_get_context_defaults2(AVCodecContext *s, enum AVMediaType codec_type){
+ AVCodec c= {0};
+ c.type= codec_type;
+ avcodec_get_context_defaults3(s, &c);
+}
+#endif
+
+int avcodec_get_context_defaults3(AVCodecContext *s, AVCodec *codec){
int flags=0;
memset(s, 0, sizeof(AVCodecContext));
- s->av_class= &av_codec_context_class;
+ s->av_class = &av_codec_context_class;
- s->codec_type = codec_type;
- if(codec_type == AVMEDIA_TYPE_AUDIO)
+ s->codec_type = codec ? codec->type : AVMEDIA_TYPE_UNKNOWN;
+ if(s->codec_type == AVMEDIA_TYPE_AUDIO)
flags= AV_OPT_FLAG_AUDIO_PARAM;
- else if(codec_type == AVMEDIA_TYPE_VIDEO)
+ else if(s->codec_type == AVMEDIA_TYPE_VIDEO)
flags= AV_OPT_FLAG_VIDEO_PARAM;
- else if(codec_type == AVMEDIA_TYPE_SUBTITLE)
+ else if(s->codec_type == AVMEDIA_TYPE_SUBTITLE)
flags= AV_OPT_FLAG_SUBTITLE_PARAM;
av_opt_set_defaults2(s, flags, flags);
- s->time_base= (AVRational){0,1};
- s->get_buffer= avcodec_default_get_buffer;
- s->release_buffer= avcodec_default_release_buffer;
- s->get_format= avcodec_default_get_format;
- s->execute= avcodec_default_execute;
- s->execute2= avcodec_default_execute2;
- s->sample_aspect_ratio= (AVRational){0,1};
- s->pix_fmt= PIX_FMT_NONE;
- s->sample_fmt= AV_SAMPLE_FMT_NONE;
-
- s->palctrl = NULL;
- s->reget_buffer= avcodec_default_reget_buffer;
- s->reordered_opaque= AV_NOPTS_VALUE;
-}
-
-int avcodec_get_context_defaults3(AVCodecContext *s, AVCodec *codec){
- avcodec_get_context_defaults2(s, codec ? codec->type : AVMEDIA_TYPE_UNKNOWN);
+ s->time_base = (AVRational){0,1};
+ s->get_buffer = avcodec_default_get_buffer;
+ s->release_buffer = avcodec_default_release_buffer;
+ s->get_format = avcodec_default_get_format;
+ s->execute = avcodec_default_execute;
+ s->execute2 = avcodec_default_execute2;
+ s->sample_aspect_ratio = (AVRational){0,1};
+ s->pix_fmt = PIX_FMT_NONE;
+ s->sample_fmt = AV_SAMPLE_FMT_NONE;
+
+ s->reget_buffer = avcodec_default_reget_buffer;
+ s->reordered_opaque = AV_NOPTS_VALUE;
if(codec && codec->priv_data_size){
if(!s->priv_data){
s->priv_data= av_mallocz(codec->priv_data_size);
@@ -522,6 +579,15 @@ int avcodec_get_context_defaults3(AVCodecContext *s, AVCodec *codec){
av_opt_set_defaults(s->priv_data);
}
}
+ if (codec && codec->defaults) {
+ int ret;
+ AVCodecDefault *d = codec->defaults;
+ while (d->key) {
+ ret = av_set_string3(s, d->key, d->value, 0, NULL);
+ av_assert0(ret >= 0);
+ d++;
+ }
+ }
return 0;
}
@@ -538,6 +604,7 @@ AVCodecContext *avcodec_alloc_context3(AVCodec *codec){
return avctx;
}
+#if FF_API_ALLOC_CONTEXT
AVCodecContext *avcodec_alloc_context2(enum AVMediaType codec_type){
AVCodecContext *avctx= av_malloc(sizeof(AVCodecContext));
@@ -555,6 +622,7 @@ void avcodec_get_context_defaults(AVCodecContext *s){
AVCodecContext *avcodec_alloc_context(void){
return avcodec_alloc_context2(AVMEDIA_TYPE_UNKNOWN);
}
+#endif
int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src)
{
@@ -569,7 +637,6 @@ int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src)
/* set values specific to opened codecs back to their default state */
dest->priv_data = NULL;
dest->codec = NULL;
- dest->palctrl = NULL;
dest->slice_offset = NULL;
dest->internal_buffer = NULL;
dest->hwaccel = NULL;
@@ -613,3 +680,8 @@ fail:
av_freep(&dest->rc_eq);
return AVERROR(ENOMEM);
}
+
+const AVClass *avcodec_get_class(void)
+{
+ return &av_codec_context_class;
+}
diff --git a/libavcodec/pamenc.c b/libavcodec/pamenc.c
index fbf9fd88aa..d9d849e8ad 100644
--- a/libavcodec/pamenc.c
+++ b/libavcodec/pamenc.c
@@ -2,20 +2,20 @@
* PAM image format
* Copyright (c) 2002, 2003 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -109,12 +109,12 @@ static int pam_encode_frame(AVCodecContext *avctx, unsigned char *outbuf,
AVCodec ff_pam_encoder = {
- "pam",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_PAM,
- sizeof(PNMContext),
- ff_pnm_init,
- pam_encode_frame,
+ .name = "pam",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_PAM,
+ .priv_data_size = sizeof(PNMContext),
+ .init = ff_pnm_init,
+ .encode = pam_encode_frame,
.pix_fmts = (const enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGB32, PIX_FMT_GRAY8, PIX_FMT_MONOWHITE, PIX_FMT_NONE},
.long_name = NULL_IF_CONFIG_SMALL("PAM (Portable AnyMap) image"),
};
diff --git a/libavcodec/parser.c b/libavcodec/parser.c
index 03f548ef6a..ff71656f78 100644
--- a/libavcodec/parser.c
+++ b/libavcodec/parser.c
@@ -3,20 +3,20 @@
* Copyright (c) 2003 Fabrice Bellard
* Copyright (c) 2003 Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -58,12 +58,10 @@ AVCodecParserContext *av_parser_init(int codec_id)
if (!s)
return NULL;
s->parser = parser;
- if (parser->priv_data_size) {
- s->priv_data = av_mallocz(parser->priv_data_size);
- if (!s->priv_data) {
- av_free(s);
- return NULL;
- }
+ s->priv_data = av_mallocz(parser->priv_data_size);
+ if (!s->priv_data) {
+ av_free(s);
+ return NULL;
}
if (parser->parser_init) {
ret = parser->parser_init(s);
diff --git a/libavcodec/parser.h b/libavcodec/parser.h
index 1e85ae4051..6712bfe8b0 100644
--- a/libavcodec/parser.h
+++ b/libavcodec/parser.h
@@ -3,20 +3,20 @@
* Copyright (c) 2003 Fabrice Bellard
* Copyright (c) 2003 Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/pcm-mpeg.c b/libavcodec/pcm-mpeg.c
index a55d48cb96..1e8a39ef76 100644
--- a/libavcodec/pcm-mpeg.c
+++ b/libavcodec/pcm-mpeg.c
@@ -2,20 +2,20 @@
* LPCM codecs for PCM formats found in MPEG streams
* Copyright (c) 2009 Christian Schmidt
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -297,14 +297,10 @@ static int pcm_bluray_decode_frame(AVCodecContext *avctx,
}
AVCodec ff_pcm_bluray_decoder = {
- "pcm_bluray",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_PCM_BLURAY,
- 0,
- NULL,
- NULL,
- NULL,
- pcm_bluray_decode_frame,
+ .name = "pcm_bluray",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_PCM_BLURAY,
+ .decode = pcm_bluray_decode_frame,
.sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32,
AV_SAMPLE_FMT_NONE},
.long_name = NULL_IF_CONFIG_SMALL("PCM signed 16|20|24-bit big-endian for Blu-ray media"),
diff --git a/libavcodec/pcm.c b/libavcodec/pcm.c
index 2ad395dd0e..0c18e0f0d7 100644
--- a/libavcodec/pcm.c
+++ b/libavcodec/pcm.c
@@ -2,20 +2,20 @@
* PCM codecs
* Copyright (c) 2001 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -236,7 +236,7 @@ static av_cold int pcm_decode_init(AVCodecContext * avctx)
/**
* Read PCM samples macro
- * @param type Datatype of native machine format
+ * @param size Data size of native machine format
* @param endian bytestream_get_xxx() endian suffix
* @param src Source pointer (variable name)
* @param dst Destination pointer (variable name)
@@ -244,13 +244,12 @@ static av_cold int pcm_decode_init(AVCodecContext * avctx)
* @param shift Bitshift (bits)
* @param offset Sample value offset
*/
-#define DECODE(type, endian, src, dst, n, shift, offset) \
- dst_##type = (type*)dst; \
+#define DECODE(size, endian, src, dst, n, shift, offset) \
for(;n>0;n--) { \
- register type v = bytestream_get_##endian(&src); \
- *dst_##type++ = (v - offset) << shift; \
- } \
- dst = (short*)dst_##type;
+ uint##size##_t v = bytestream_get_##endian(&src); \
+ AV_WN##size##A(dst, (v - offset) << shift); \
+ dst += size / 8; \
+ }
static int pcm_decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
@@ -260,14 +259,9 @@ static int pcm_decode_frame(AVCodecContext *avctx,
int buf_size = avpkt->size;
PCMDecode *s = avctx->priv_data;
int sample_size, c, n, i;
- short *samples;
+ uint8_t *samples;
const uint8_t *src, *src8, *src2[MAX_CHANNELS];
- uint8_t *dstu8;
- int16_t *dst_int16_t;
int32_t *dst_int32_t;
- int64_t *dst_int64_t;
- uint16_t *dst_uint16_t;
- uint32_t *dst_uint32_t;
samples = data;
src = buf;
@@ -314,29 +308,30 @@ static int pcm_decode_frame(AVCodecContext *avctx,
switch(avctx->codec->id) {
case CODEC_ID_PCM_U32LE:
- DECODE(uint32_t, le32, src, samples, n, 0, 0x80000000)
+ DECODE(32, le32, src, samples, n, 0, 0x80000000)
break;
case CODEC_ID_PCM_U32BE:
- DECODE(uint32_t, be32, src, samples, n, 0, 0x80000000)
+ DECODE(32, be32, src, samples, n, 0, 0x80000000)
break;
case CODEC_ID_PCM_S24LE:
- DECODE(int32_t, le24, src, samples, n, 8, 0)
+ DECODE(32, le24, src, samples, n, 8, 0)
break;
case CODEC_ID_PCM_S24BE:
- DECODE(int32_t, be24, src, samples, n, 8, 0)
+ DECODE(32, be24, src, samples, n, 8, 0)
break;
case CODEC_ID_PCM_U24LE:
- DECODE(uint32_t, le24, src, samples, n, 8, 0x800000)
+ DECODE(32, le24, src, samples, n, 8, 0x800000)
break;
case CODEC_ID_PCM_U24BE:
- DECODE(uint32_t, be24, src, samples, n, 8, 0x800000)
+ DECODE(32, be24, src, samples, n, 8, 0x800000)
break;
case CODEC_ID_PCM_S24DAUD:
for(;n>0;n--) {
uint32_t v = bytestream_get_be24(&src);
v >>= 4; // sync flags are here
- *samples++ = av_reverse[(v >> 8) & 0xff] +
- (av_reverse[v & 0xff] << 8);
+ AV_WN16A(samples, av_reverse[(v >> 8) & 0xff] +
+ (av_reverse[v & 0xff] << 8));
+ samples += 2;
}
break;
case CODEC_ID_PCM_S16LE_PLANAR:
@@ -344,33 +339,33 @@ static int pcm_decode_frame(AVCodecContext *avctx,
for(c=0;c<avctx->channels;c++)
src2[c] = &src[c*n*2];
for(;n>0;n--)
- for(c=0;c<avctx->channels;c++)
- *samples++ = bytestream_get_le16(&src2[c]);
+ for(c=0;c<avctx->channels;c++) {
+ AV_WN16A(samples, bytestream_get_le16(&src2[c]));
+ samples += 2;
+ }
src = src2[avctx->channels-1];
break;
case CODEC_ID_PCM_U16LE:
- DECODE(uint16_t, le16, src, samples, n, 0, 0x8000)
+ DECODE(16, le16, src, samples, n, 0, 0x8000)
break;
case CODEC_ID_PCM_U16BE:
- DECODE(uint16_t, be16, src, samples, n, 0, 0x8000)
+ DECODE(16, be16, src, samples, n, 0, 0x8000)
break;
case CODEC_ID_PCM_S8:
- dstu8= (uint8_t*)samples;
for(;n>0;n--) {
- *dstu8++ = *src++ + 128;
+ *samples++ = *src++ + 128;
}
- samples= (short*)dstu8;
break;
#if HAVE_BIGENDIAN
case CODEC_ID_PCM_F64LE:
- DECODE(int64_t, le64, src, samples, n, 0, 0)
+ DECODE(64, le64, src, samples, n, 0, 0)
break;
case CODEC_ID_PCM_S32LE:
case CODEC_ID_PCM_F32LE:
- DECODE(int32_t, le32, src, samples, n, 0, 0)
+ DECODE(32, le32, src, samples, n, 0, 0)
break;
case CODEC_ID_PCM_S16LE:
- DECODE(int16_t, le16, src, samples, n, 0, 0)
+ DECODE(16, le16, src, samples, n, 0, 0)
break;
case CODEC_ID_PCM_F64BE:
case CODEC_ID_PCM_F32BE:
@@ -378,14 +373,14 @@ static int pcm_decode_frame(AVCodecContext *avctx,
case CODEC_ID_PCM_S16BE:
#else
case CODEC_ID_PCM_F64BE:
- DECODE(int64_t, be64, src, samples, n, 0, 0)
+ DECODE(64, be64, src, samples, n, 0, 0)
break;
case CODEC_ID_PCM_F32BE:
case CODEC_ID_PCM_S32BE:
- DECODE(int32_t, be32, src, samples, n, 0, 0)
+ DECODE(32, be32, src, samples, n, 0, 0)
break;
case CODEC_ID_PCM_S16BE:
- DECODE(int16_t, be16, src, samples, n, 0, 0)
+ DECODE(16, be16, src, samples, n, 0, 0)
break;
case CODEC_ID_PCM_F64LE:
case CODEC_ID_PCM_F32LE:
@@ -395,20 +390,22 @@ static int pcm_decode_frame(AVCodecContext *avctx,
case CODEC_ID_PCM_U8:
memcpy(samples, src, n*sample_size);
src += n*sample_size;
- samples = (short*)((uint8_t*)data + n*sample_size);
+ samples += n * sample_size;
break;
case CODEC_ID_PCM_ZORK:
for(;n>0;n--) {
int x= *src++;
if(x&128) x-= 128;
else x = -x;
- *samples++ = x << 8;
+ AV_WN16A(samples, x << 8);
+ samples += 2;
}
break;
case CODEC_ID_PCM_ALAW:
case CODEC_ID_PCM_MULAW:
for(;n>0;n--) {
- *samples++ = s->table[*src++];
+ AV_WN16A(samples, s->table[*src++]);
+ samples += 2;
}
break;
case CODEC_ID_PCM_DVD:
@@ -438,10 +435,12 @@ static int pcm_decode_frame(AVCodecContext *avctx,
}
break;
default:
- av_log(avctx, AV_LOG_ERROR, "PCM DVD unsupported sample depth\n");
+ av_log(avctx, AV_LOG_ERROR,
+ "PCM DVD unsupported sample depth %i\n",
+ avctx->bits_per_coded_sample);
return -1;
}
- samples = (short *) dst_int32_t;
+ samples = (uint8_t *) dst_int32_t;
break;
case CODEC_ID_PCM_LXF:
dst_int32_t = data;
@@ -461,12 +460,12 @@ static int pcm_decode_frame(AVCodecContext *avctx,
}
}
src += n * avctx->channels * 5;
- samples = (short *) dst_int32_t;
+ samples = (uint8_t *) dst_int32_t;
break;
default:
return -1;
}
- *data_size = (uint8_t *)samples - (uint8_t *)data;
+ *data_size = samples - (uint8_t *)data;
return src - buf;
}
diff --git a/libavcodec/pcm_tablegen.c b/libavcodec/pcm_tablegen.c
index 8a9bcb6fb1..b0fde936c7 100644
--- a/libavcodec/pcm_tablegen.c
+++ b/libavcodec/pcm_tablegen.c
@@ -3,20 +3,20 @@
*
* Copyright (c) 2010 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/pcm_tablegen.h b/libavcodec/pcm_tablegen.h
index 79d6561646..1387210a58 100644
--- a/libavcodec/pcm_tablegen.h
+++ b/libavcodec/pcm_tablegen.h
@@ -3,20 +3,20 @@
*
* Copyright (c) 2010 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/pcx.c b/libavcodec/pcx.c
index 35f85f94c3..b2d433a13d 100644
--- a/libavcodec/pcx.c
+++ b/libavcodec/pcx.c
@@ -5,20 +5,20 @@
* This decoder does not support CGA palettes. I am unable to find samples
* and Netpbm cannot generate them.
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -248,15 +248,13 @@ static av_cold int pcx_end(AVCodecContext *avctx) {
}
AVCodec ff_pcx_decoder = {
- "pcx",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_PCX,
- sizeof(PCXContext),
- pcx_init,
- NULL,
- pcx_end,
- pcx_decode_frame,
- CODEC_CAP_DR1,
- NULL,
+ .name = "pcx",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_PCX,
+ .priv_data_size = sizeof(PCXContext),
+ .init = pcx_init,
+ .close = pcx_end,
+ .decode = pcx_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("PC Paintbrush PCX image"),
};
diff --git a/libavcodec/pcxenc.c b/libavcodec/pcxenc.c
index 81629d0add..816223e736 100644
--- a/libavcodec/pcxenc.c
+++ b/libavcodec/pcxenc.c
@@ -2,28 +2,28 @@
* PC Paintbrush PCX (.pcx) image encoder
* Copyright (c) 2009 Daniel Verkamp <daniel at drv.nu>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
- * PCX image encoder
* @file
+ * PCX image encoder
* @author Daniel Verkamp
- * @sa http://www.qzx.com/pc-gpe/pcx.txt
+ * @see http://www.qzx.com/pc-gpe/pcx.txt
*/
#include "avcodec.h"
@@ -190,13 +190,12 @@ static int pcx_encode_frame(AVCodecContext *avctx,
}
AVCodec ff_pcx_encoder = {
- "pcx",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_PCX,
- sizeof(PCXContext),
- pcx_encode_init,
- pcx_encode_frame,
- NULL,
+ .name = "pcx",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_PCX,
+ .priv_data_size = sizeof(PCXContext),
+ .init = pcx_encode_init,
+ .encode = pcx_encode_frame,
.pix_fmts = (const enum PixelFormat[]){
PIX_FMT_RGB24,
PIX_FMT_RGB8, PIX_FMT_BGR8, PIX_FMT_RGB4_BYTE, PIX_FMT_BGR4_BYTE, PIX_FMT_GRAY8, PIX_FMT_PAL8,
diff --git a/libavcodec/pgssubdec.c b/libavcodec/pgssubdec.c
index 71b8242e70..5a070e435d 100644
--- a/libavcodec/pgssubdec.c
+++ b/libavcodec/pgssubdec.c
@@ -2,20 +2,20 @@
* PGS subtitle decoder
* Copyright (c) 2009 Stephen Backway
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -355,7 +355,6 @@ static int display_end_segment(AVCodecContext *avctx, void *data,
* not been cleared by a subsequent empty display command.
*/
- memset(sub, 0, sizeof(*sub));
// Blank if last object_number was 0.
// Note that this may be wrong for more complex subtitles.
if (!ctx->presentation.object_number)
@@ -469,13 +468,12 @@ static int decode(AVCodecContext *avctx, void *data, int *data_size,
}
AVCodec ff_pgssub_decoder = {
- "pgssub",
- AVMEDIA_TYPE_SUBTITLE,
- CODEC_ID_HDMV_PGS_SUBTITLE,
- sizeof(PGSSubContext),
- init_decoder,
- NULL,
- close_decoder,
- decode,
+ .name = "pgssub",
+ .type = AVMEDIA_TYPE_SUBTITLE,
+ .id = CODEC_ID_HDMV_PGS_SUBTITLE,
+ .priv_data_size = sizeof(PGSSubContext),
+ .init = init_decoder,
+ .close = close_decoder,
+ .decode = decode,
.long_name = NULL_IF_CONFIG_SMALL("HDMV Presentation Graphic Stream subtitles"),
};
diff --git a/libavcodec/pictordec.c b/libavcodec/pictordec.c
index 23f299c214..2bbb63633d 100644
--- a/libavcodec/pictordec.c
+++ b/libavcodec/pictordec.c
@@ -2,20 +2,20 @@
* Pictor/PC Paint decoder
* Copyright (c) 2010 Peter Ross <pross@xvid.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -94,6 +94,14 @@ static const uint8_t cga_mode45_index[6][4] = {
[5] = { 0, 11, 12, 15 }, // mode5, high intensity
};
+static av_cold int decode_init(AVCodecContext *avctx)
+{
+ PicContext *s = avctx->priv_data;
+
+ avcodec_get_frame_defaults(&s->frame);
+ return 0;
+}
+
static int decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
AVPacket *avpkt)
@@ -238,14 +246,13 @@ static av_cold int decode_end(AVCodecContext *avctx)
}
AVCodec ff_pictor_decoder = {
- "pictor",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_PICTOR,
- sizeof(PicContext),
- NULL,
- NULL,
- decode_end,
- decode_frame,
- CODEC_CAP_DR1,
+ .name = "pictor",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_PICTOR,
+ .priv_data_size = sizeof(PicContext),
+ decode_init,
+ .close = decode_end,
+ .decode = decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Pictor/PC Paint"),
};
diff --git a/libavcodec/png.c b/libavcodec/png.c
index 70a080e29e..d7898c0a41 100644
--- a/libavcodec/png.c
+++ b/libavcodec/png.c
@@ -2,20 +2,20 @@
* PNG image format
* Copyright (c) 2003 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avcodec.h"
diff --git a/libavcodec/png.h b/libavcodec/png.h
index b8c72eebc9..d6fac3e673 100644
--- a/libavcodec/png.h
+++ b/libavcodec/png.h
@@ -2,20 +2,20 @@
* PNG image format
* Copyright (c) 2003 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -23,6 +23,9 @@
#define AVCODEC_PNG_H
#include <stdint.h>
+#include <zlib.h>
+
+#include "avcodec.h"
#define PNG_COLOR_MASK_PALETTE 1
#define PNG_COLOR_MASK_COLOR 2
@@ -69,4 +72,41 @@ int ff_png_pass_row_size(int pass, int bits_per_pixel, int width);
void ff_add_png_paeth_prediction(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp);
+typedef struct PNGDecContext {
+ const uint8_t *bytestream;
+ const uint8_t *bytestream_start;
+ const uint8_t *bytestream_end;
+ AVFrame picture1, picture2;
+ AVFrame *current_picture, *last_picture;
+
+ int state;
+ int width, height;
+ int bit_depth;
+ int color_type;
+ int compression_type;
+ int interlace_type;
+ int filter_type;
+ int channels;
+ int bits_per_pixel;
+ int bpp;
+
+ uint8_t *image_buf;
+ int image_linesize;
+ uint32_t palette[256];
+ uint8_t *crow_buf;
+ uint8_t *last_row;
+ uint8_t *tmp_row;
+ int pass;
+ int crow_size; /* compressed row size (include filter type) */
+ int row_size; /* decompressed row size */
+ int pass_row_size; /* decompress row size of the current pass */
+ int y;
+ z_stream zstream;
+
+ void (*add_bytes_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w);
+ void (*add_paeth_prediction)(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp);
+} PNGDecContext;
+
+void ff_png_init_mmx(PNGDecContext *s);
+
#endif /* AVCODEC_PNG_H */
diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
index 7477f6746b..dd3fe67876 100644
--- a/libavcodec/pngdec.c
+++ b/libavcodec/pngdec.c
@@ -2,70 +2,36 @@
* PNG image format
* Copyright (c) 2003 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+
+//#define DEBUG
+
#include "libavutil/imgutils.h"
#include "avcodec.h"
#include "bytestream.h"
#include "png.h"
-#include "dsputil.h"
/* TODO:
- * - add 2, 4 and 16 bit depth support
+ * - add 16 bit depth support
*/
#include <zlib.h>
-//#define DEBUG
-
-typedef struct PNGDecContext {
- DSPContext dsp;
-
- const uint8_t *bytestream;
- const uint8_t *bytestream_start;
- const uint8_t *bytestream_end;
- AVFrame picture1, picture2;
- AVFrame *current_picture, *last_picture;
-
- int state;
- int width, height;
- int bit_depth;
- int color_type;
- int compression_type;
- int interlace_type;
- int filter_type;
- int channels;
- int bits_per_pixel;
- int bpp;
-
- uint8_t *image_buf;
- int image_linesize;
- uint32_t palette[256];
- uint8_t *crow_buf;
- uint8_t *last_row;
- uint8_t *tmp_row;
- int pass;
- int crow_size; /* compressed row size (include filter type) */
- int row_size; /* decompressed row size */
- int pass_row_size; /* decompress row size of the current pass */
- int y;
- z_stream zstream;
-} PNGDecContext;
-
/* Mask to determine which y pixels can be written in a pass */
static const uint8_t png_pass_dsp_ymask[NB_PASSES] = {
0xff, 0xff, 0x0f, 0xcc, 0x33, 0xff, 0x55,
@@ -91,20 +57,46 @@ static void png_put_interlaced_row(uint8_t *dst, int width,
dsp_mask = png_pass_dsp_mask[pass];
switch(bits_per_pixel) {
case 1:
- /* we must initialize the line to zero before writing to it */
- if (pass == 0)
- memset(dst, 0, (width + 7) >> 3);
src_x = 0;
for(x = 0; x < width; x++) {
j = (x & 7);
if ((dsp_mask << j) & 0x80) {
b = (src[src_x >> 3] >> (7 - (src_x & 7))) & 1;
+ dst[x >> 3] &= 0xFF7F>>j;
dst[x >> 3] |= b << (7 - j);
}
if ((mask << j) & 0x80)
src_x++;
}
break;
+ case 2:
+ src_x = 0;
+ for(x = 0; x < width; x++) {
+ int j2 = 2*(x&3);
+ j = (x & 7);
+ if ((dsp_mask << j) & 0x80) {
+ b = (src[src_x >> 2] >> (6 - 2*(src_x & 3))) & 3;
+ dst[x >> 2] &= 0xFF3F>>j2;
+ dst[x >> 2] |= b << (6 - j2);
+ }
+ if ((mask << j) & 0x80)
+ src_x++;
+ }
+ break;
+ case 4:
+ src_x = 0;
+ for(x = 0; x < width; x++) {
+ int j2 = 4*(x&1);
+ j = (x & 7);
+ if ((dsp_mask << j) & 0x80) {
+ b = (src[src_x >> 1] >> (4 - 4*(src_x & 1))) & 15;
+ dst[x >> 1] &= 0xFF0F>>j2;
+ dst[x >> 1] |= b << (4 - j2);
+ }
+ if ((mask << j) & 0x80)
+ src_x++;
+ }
+ break;
default:
bpp = bits_per_pixel >> 3;
d = dst;
@@ -134,7 +126,23 @@ static void png_put_interlaced_row(uint8_t *dst, int width,
}
}
-void ff_add_png_paeth_prediction(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp)
+// 0x7f7f7f7f or 0x7f7f7f7f7f7f7f7f or whatever, depending on the cpu's native arithmetic size
+#define pb_7f (~0UL/255 * 0x7f)
+#define pb_80 (~0UL/255 * 0x80)
+
+static void add_bytes_l2_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w)
+{
+ long i;
+ for(i=0; i<=w-sizeof(long); i+=sizeof(long)){
+ long a = *(long*)(src1+i);
+ long b = *(long*)(src2+i);
+ *(long*)(dst+i) = ((a&pb_7f) + (b&pb_7f)) ^ ((a^b)&pb_80);
+ }
+ for(; i<w; i++)
+ dst[i] = src1[i]+src2[i];
+}
+
+static void add_paeth_prediction_c(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp)
{
int i;
for(i = 0; i < w; i++) {
@@ -191,7 +199,7 @@ void ff_add_png_paeth_prediction(uint8_t *dst, uint8_t *src, uint8_t *top, int w
}
/* NOTE: 'dst' can be equal to 'last' */
-static void png_filter_row(DSPContext *dsp, uint8_t *dst, int filter_type,
+static void png_filter_row(PNGDecContext *s, uint8_t *dst, int filter_type,
uint8_t *src, uint8_t *last, int size, int bpp)
{
int i, p, r, g, b, a;
@@ -217,7 +225,7 @@ static void png_filter_row(DSPContext *dsp, uint8_t *dst, int filter_type,
}
break;
case PNG_FILTER_VALUE_UP:
- dsp->add_bytes_l2(dst, src, last, size);
+ s->add_bytes_l2(dst, src, last, size);
break;
case PNG_FILTER_VALUE_AVG:
for(i = 0; i < bpp; i++) {
@@ -235,10 +243,10 @@ static void png_filter_row(DSPContext *dsp, uint8_t *dst, int filter_type,
if(bpp > 1 && size > 4) {
// would write off the end of the array if we let it process the last pixel with bpp=3
int w = bpp==4 ? size : size-3;
- dsp->add_png_paeth_prediction(dst+i, src+i, last+i, w-i, bpp);
+ s->add_paeth_prediction(dst+i, src+i, last+i, w-i, bpp);
i = w;
}
- ff_add_png_paeth_prediction(dst+i, src+i, last+i, size-i, bpp);
+ add_paeth_prediction_c(dst+i, src+i, last+i, size-i, bpp);
break;
}
}
@@ -291,7 +299,7 @@ static void png_handle_row(PNGDecContext *s)
ptr = s->image_buf + s->image_linesize * s->y;
/* need to swap bytes correctly for RGB_ALPHA */
if (s->color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
- png_filter_row(&s->dsp, s->tmp_row, s->crow_buf[0], s->crow_buf + 1,
+ png_filter_row(s, s->tmp_row, s->crow_buf[0], s->crow_buf + 1,
s->last_row, s->row_size, s->bpp);
convert_to_rgb32(ptr, s->tmp_row, s->width, s->filter_type == PNG_FILTER_TYPE_LOCO);
FFSWAP(uint8_t*, s->last_row, s->tmp_row);
@@ -302,7 +310,7 @@ static void png_handle_row(PNGDecContext *s)
else
last_row = ptr - s->image_linesize;
- png_filter_row(&s->dsp, ptr, s->crow_buf[0], s->crow_buf + 1,
+ png_filter_row(s, ptr, s->crow_buf[0], s->crow_buf + 1,
last_row, s->row_size, s->bpp);
}
/* loco lags by 1 row so that it doesn't interfere with top prediction */
@@ -325,7 +333,7 @@ static void png_handle_row(PNGDecContext *s)
wait for the next one */
if (got_line)
break;
- png_filter_row(&s->dsp, s->tmp_row, s->crow_buf[0], s->crow_buf + 1,
+ png_filter_row(s, s->tmp_row, s->crow_buf[0], s->crow_buf + 1,
s->last_row, s->pass_row_size, s->bpp);
FFSWAP(uint8_t*, s->last_row, s->tmp_row);
got_line = 1;
@@ -337,6 +345,7 @@ static void png_handle_row(PNGDecContext *s)
}
s->y++;
if (s->y == s->height) {
+ memset(s->last_row, 0, s->row_size);
for(;;) {
if (s->pass == NB_PASSES - 1) {
s->state |= PNG_ALLIMAGE;
@@ -485,20 +494,19 @@ static int decode_frame(AVCodecContext *avctx,
} else if (s->bit_depth == 16 &&
s->color_type == PNG_COLOR_TYPE_RGB) {
avctx->pix_fmt = PIX_FMT_RGB48BE;
- } else if (s->bit_depth == 1 &&
- s->color_type == PNG_COLOR_TYPE_GRAY) {
+ } else if (s->bit_depth == 1) {
avctx->pix_fmt = PIX_FMT_MONOBLACK;
} else if (s->color_type == PNG_COLOR_TYPE_PALETTE) {
avctx->pix_fmt = PIX_FMT_PAL8;
} else if (s->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
- avctx->pix_fmt = PIX_FMT_Y400A;
+ avctx->pix_fmt = PIX_FMT_GRAY8A;
} else {
goto fail;
}
if(p->data[0])
avctx->release_buffer(avctx, p);
- p->reference= 0;
+ p->reference= 1;
if(avctx->get_buffer(avctx, p) < 0){
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
goto fail;
@@ -522,7 +530,7 @@ static int decode_frame(AVCodecContext *avctx,
s->image_buf = p->data[0];
s->image_linesize = p->linesize[0];
/* copy the palette if needed */
- if (s->color_type == PNG_COLOR_TYPE_PALETTE)
+ if (avctx->pix_fmt == PIX_FMT_PAL8)
memcpy(p->data[1], s->palette, 256 * sizeof(uint32_t));
/* empty row is used if differencing to the first row */
s->last_row = av_mallocz(s->row_size);
@@ -599,6 +607,32 @@ static int decode_frame(AVCodecContext *avctx,
}
}
exit_loop:
+
+ if(s->bits_per_pixel == 2){
+ int i, j;
+ uint8_t *pd = s->current_picture->data[0];
+ for(j=0; j < s->height; j++) {
+ for(i=s->width/4-1; i>=0; i--) {
+ pd[4*i+3]= pd[i] &3;
+ pd[4*i+2]= (pd[i]>>2)&3;
+ pd[4*i+1]= (pd[i]>>4)&3;
+ pd[4*i+0]= pd[i]>>6;
+ }
+ pd += s->image_linesize;
+ }
+ }
+ if(s->bits_per_pixel == 4){
+ int i, j;
+ uint8_t *pd = s->current_picture->data[0];
+ for(j=0; j < s->height; j++) {
+ for(i=s->width/2-1; i>=0; i--) {
+ pd[2*i+1]= pd[i]&15;
+ pd[2*i+0]= pd[i]>>4;
+ }
+ pd += s->image_linesize;
+ }
+ }
+
/* handle p-frames only if a predecessor frame is available */
if(s->last_picture->data[0] != NULL) {
if(!(avpkt->flags & AV_PKT_FLAG_KEY)) {
@@ -632,14 +666,23 @@ static int decode_frame(AVCodecContext *avctx,
goto the_end;
}
-static av_cold int png_dec_init(AVCodecContext *avctx){
+static av_cold int png_dec_init(AVCodecContext *avctx)
+{
PNGDecContext *s = avctx->priv_data;
s->current_picture = &s->picture1;
s->last_picture = &s->picture2;
avcodec_get_frame_defaults(&s->picture1);
avcodec_get_frame_defaults(&s->picture2);
- dsputil_init(&s->dsp, avctx);
+
+#if HAVE_MMX
+ ff_png_init_mmx(s);
+#endif
+
+ if (!s->add_paeth_prediction)
+ s->add_paeth_prediction = add_paeth_prediction_c;
+ if (!s->add_bytes_l2)
+ s->add_bytes_l2 = add_bytes_l2_c;
return 0;
}
@@ -657,16 +700,13 @@ static av_cold int png_dec_end(AVCodecContext *avctx)
}
AVCodec ff_png_decoder = {
- "png",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_PNG,
- sizeof(PNGDecContext),
- png_dec_init,
- NULL,
- png_dec_end,
- decode_frame,
- CODEC_CAP_DR1 /*| CODEC_CAP_DRAW_HORIZ_BAND*/,
- NULL,
- .max_lowres = 5,
+ .name = "png",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_PNG,
+ .priv_data_size = sizeof(PNGDecContext),
+ .init = png_dec_init,
+ .close = png_dec_end,
+ .decode = decode_frame,
+ .capabilities = CODEC_CAP_DR1 /*| CODEC_CAP_DRAW_HORIZ_BAND*/,
.long_name = NULL_IF_CONFIG_SMALL("PNG image"),
};
diff --git a/libavcodec/pngenc.c b/libavcodec/pngenc.c
index c2ac4901d7..29f4e1a0df 100644
--- a/libavcodec/pngenc.c
+++ b/libavcodec/pngenc.c
@@ -2,20 +2,20 @@
* PNG image format
* Copyright (c) 2003 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avcodec.h"
@@ -437,13 +437,12 @@ static av_cold int png_enc_init(AVCodecContext *avctx){
}
AVCodec ff_png_encoder = {
- "png",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_PNG,
- sizeof(PNGEncContext),
- png_enc_init,
- encode_frame,
- NULL, //encode_end,
+ .name = "png",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_PNG,
+ .priv_data_size = sizeof(PNGEncContext),
+ .init = png_enc_init,
+ .encode = encode_frame,
.pix_fmts= (const enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGB32, PIX_FMT_PAL8, PIX_FMT_GRAY8, PIX_FMT_MONOBLACK, PIX_FMT_NONE},
.long_name= NULL_IF_CONFIG_SMALL("PNG image"),
};
diff --git a/libavcodec/pnm.c b/libavcodec/pnm.c
index 54b55cfa53..dfc18d6013 100644
--- a/libavcodec/pnm.c
+++ b/libavcodec/pnm.c
@@ -2,20 +2,20 @@
* PNM image format
* Copyright (c) 2002, 2003 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -135,7 +135,7 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s)
return -1;
pnm_get(s, buf1, sizeof(buf1));
avctx->height = atoi(buf1);
- if(av_image_check_size(avctx->width, avctx->height, 0, avctx))
+ if(avctx->height <= 0 || av_image_check_size(avctx->width, avctx->height, 0, avctx))
return -1;
if (avctx->pix_fmt != PIX_FMT_MONOWHITE) {
pnm_get(s, buf1, sizeof(buf1));
diff --git a/libavcodec/pnm.h b/libavcodec/pnm.h
index 702921fbdf..ac4b1084fb 100644
--- a/libavcodec/pnm.h
+++ b/libavcodec/pnm.h
@@ -2,20 +2,20 @@
* PNM image format
* Copyright (c) 2002, 2003 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/pnm_parser.c b/libavcodec/pnm_parser.c
index 2dc29871c0..17e8082609 100644
--- a/libavcodec/pnm_parser.c
+++ b/libavcodec/pnm_parser.c
@@ -2,20 +2,20 @@
* PNM image parser
* Copyright (c) 2002, 2003 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/pnmdec.c b/libavcodec/pnmdec.c
index b9f20c0569..dc64f9b70e 100644
--- a/libavcodec/pnmdec.c
+++ b/libavcodec/pnmdec.c
@@ -2,20 +2,20 @@
* PNM image format
* Copyright (c) 2002, 2003 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -33,7 +33,7 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data,
PNMContext * const s = avctx->priv_data;
AVFrame *picture = data;
AVFrame * const p = (AVFrame*)&s->picture;
- int i, j, n, linesize, h, upgrade = 0;
+ int i, j, n, linesize, h, upgrade = 0, is_mono = 0;
unsigned char *ptr;
int components, sample_len;
@@ -88,6 +88,7 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data,
n = (avctx->width + 7) >> 3;
components=1;
sample_len=1;
+ is_mono = 1;
do_read:
ptr = p->data[0];
linesize = p->linesize[0];
@@ -104,10 +105,16 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data,
s->bytestream++;
if(s->bytestream >= s->bytestream_end)
return -1;
- do{
- v= 10*v + c;
- c= (*s->bytestream++) - '0';
- }while(c <= 9);
+ if (is_mono) {
+ /* read a single digit */
+ v = (*s->bytestream++) - '0';
+ } else {
+ /* read a sequence of digits */
+ do {
+ v = 10*v + c;
+ c = (*s->bytestream++) - '0';
+ } while (c <= 9);
+ }
put_bits(&pb, sample_len, (((1<<sample_len)-1)*v + (s->maxval>>1))/s->maxval);
}
flush_put_bits(&pb);
@@ -189,85 +196,75 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data,
#if CONFIG_PGM_DECODER
AVCodec ff_pgm_decoder = {
- "pgm",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_PGM,
- sizeof(PNMContext),
- ff_pnm_init,
- NULL,
- ff_pnm_end,
- pnm_decode_frame,
- CODEC_CAP_DR1,
+ .name = "pgm",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_PGM,
+ .priv_data_size = sizeof(PNMContext),
+ .init = ff_pnm_init,
+ .close = ff_pnm_end,
+ .decode = pnm_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.pix_fmts = (const enum PixelFormat[]){PIX_FMT_GRAY8, PIX_FMT_GRAY16BE, PIX_FMT_NONE},
- .max_lowres = 5,
.long_name = NULL_IF_CONFIG_SMALL("PGM (Portable GrayMap) image"),
};
#endif
#if CONFIG_PGMYUV_DECODER
AVCodec ff_pgmyuv_decoder = {
- "pgmyuv",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_PGMYUV,
- sizeof(PNMContext),
- ff_pnm_init,
- NULL,
- ff_pnm_end,
- pnm_decode_frame,
- CODEC_CAP_DR1,
+ .name = "pgmyuv",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_PGMYUV,
+ .priv_data_size = sizeof(PNMContext),
+ .init = ff_pnm_init,
+ .close = ff_pnm_end,
+ .decode = pnm_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
- .max_lowres = 5,
.long_name = NULL_IF_CONFIG_SMALL("PGMYUV (Portable GrayMap YUV) image"),
};
#endif
#if CONFIG_PPM_DECODER
AVCodec ff_ppm_decoder = {
- "ppm",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_PPM,
- sizeof(PNMContext),
- ff_pnm_init,
- NULL,
- ff_pnm_end,
- pnm_decode_frame,
- CODEC_CAP_DR1,
+ .name = "ppm",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_PPM,
+ .priv_data_size = sizeof(PNMContext),
+ .init = ff_pnm_init,
+ .close = ff_pnm_end,
+ .decode = pnm_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.pix_fmts = (const enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGB48BE, PIX_FMT_NONE},
- .max_lowres = 5,
.long_name = NULL_IF_CONFIG_SMALL("PPM (Portable PixelMap) image"),
};
#endif
#if CONFIG_PBM_DECODER
AVCodec ff_pbm_decoder = {
- "pbm",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_PBM,
- sizeof(PNMContext),
- ff_pnm_init,
- NULL,
- ff_pnm_end,
- pnm_decode_frame,
- CODEC_CAP_DR1,
+ .name = "pbm",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_PBM,
+ .priv_data_size = sizeof(PNMContext),
+ .init = ff_pnm_init,
+ .close = ff_pnm_end,
+ .decode = pnm_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.pix_fmts = (const enum PixelFormat[]){PIX_FMT_MONOWHITE, PIX_FMT_NONE},
- .max_lowres = 5,
.long_name = NULL_IF_CONFIG_SMALL("PBM (Portable BitMap) image"),
};
#endif
#if CONFIG_PAM_DECODER
AVCodec ff_pam_decoder = {
- "pam",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_PAM,
- sizeof(PNMContext),
- ff_pnm_init,
- NULL,
- ff_pnm_end,
- pnm_decode_frame,
- CODEC_CAP_DR1,
+ .name = "pam",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_PAM,
+ .priv_data_size = sizeof(PNMContext),
+ .init = ff_pnm_init,
+ .close = ff_pnm_end,
+ .decode = pnm_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.pix_fmts = (const enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGB32, PIX_FMT_GRAY8, PIX_FMT_MONOWHITE, PIX_FMT_NONE},
- .max_lowres = 5,
.long_name = NULL_IF_CONFIG_SMALL("PAM (Portable AnyMap) image"),
};
#endif
diff --git a/libavcodec/pnmenc.c b/libavcodec/pnmenc.c
index 57cb90c868..15c71f2514 100644
--- a/libavcodec/pnmenc.c
+++ b/libavcodec/pnmenc.c
@@ -2,20 +2,20 @@
* PNM image format
* Copyright (c) 2002, 2003 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -114,12 +114,12 @@ static int pnm_encode_frame(AVCodecContext *avctx, unsigned char *outbuf,
#if CONFIG_PGM_ENCODER
AVCodec ff_pgm_encoder = {
- "pgm",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_PGM,
- sizeof(PNMContext),
- ff_pnm_init,
- pnm_encode_frame,
+ .name = "pgm",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_PGM,
+ .priv_data_size = sizeof(PNMContext),
+ .init = ff_pnm_init,
+ .encode = pnm_encode_frame,
.pix_fmts = (const enum PixelFormat[]){PIX_FMT_GRAY8, PIX_FMT_GRAY16BE, PIX_FMT_NONE},
.long_name = NULL_IF_CONFIG_SMALL("PGM (Portable GrayMap) image"),
};
@@ -127,12 +127,12 @@ AVCodec ff_pgm_encoder = {
#if CONFIG_PGMYUV_ENCODER
AVCodec ff_pgmyuv_encoder = {
- "pgmyuv",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_PGMYUV,
- sizeof(PNMContext),
- ff_pnm_init,
- pnm_encode_frame,
+ .name = "pgmyuv",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_PGMYUV,
+ .priv_data_size = sizeof(PNMContext),
+ .init = ff_pnm_init,
+ .encode = pnm_encode_frame,
.pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
.long_name = NULL_IF_CONFIG_SMALL("PGMYUV (Portable GrayMap YUV) image"),
};
@@ -140,12 +140,12 @@ AVCodec ff_pgmyuv_encoder = {
#if CONFIG_PPM_ENCODER
AVCodec ff_ppm_encoder = {
- "ppm",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_PPM,
- sizeof(PNMContext),
- ff_pnm_init,
- pnm_encode_frame,
+ .name = "ppm",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_PPM,
+ .priv_data_size = sizeof(PNMContext),
+ .init = ff_pnm_init,
+ .encode = pnm_encode_frame,
.pix_fmts = (const enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGB48BE, PIX_FMT_NONE},
.long_name = NULL_IF_CONFIG_SMALL("PPM (Portable PixelMap) image"),
};
@@ -153,12 +153,12 @@ AVCodec ff_ppm_encoder = {
#if CONFIG_PBM_ENCODER
AVCodec ff_pbm_encoder = {
- "pbm",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_PBM,
- sizeof(PNMContext),
- ff_pnm_init,
- pnm_encode_frame,
+ .name = "pbm",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_PBM,
+ .priv_data_size = sizeof(PNMContext),
+ .init = ff_pnm_init,
+ .encode = pnm_encode_frame,
.pix_fmts = (const enum PixelFormat[]){PIX_FMT_MONOWHITE, PIX_FMT_NONE},
.long_name = NULL_IF_CONFIG_SMALL("PBM (Portable BitMap) image"),
};
diff --git a/libavcodec/ppc/asm.S b/libavcodec/ppc/asm.S
index 5cbbf97b64..bbbf8a4a66 100644
--- a/libavcodec/ppc/asm.S
+++ b/libavcodec/ppc/asm.S
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2009 Loren Merritt
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -44,10 +44,13 @@ X(\name):
L(\name):
.endm
-.macro movrel rd, sym
+.macro movrel rd, sym, gp
ld \rd, \sym@got(r2)
.endm
+.macro get_got rd
+.endm
+
#else /* ARCH_PPC64 */
#define PTR .int
@@ -65,15 +68,25 @@ X(\name):
\name:
.endm
-.macro movrel rd, sym
+.macro movrel rd, sym, gp
#if CONFIG_PIC
- lwz \rd, \sym@got(r2)
+ lwz \rd, \sym@got(\gp)
#else
lis \rd, \sym@ha
la \rd, \sym@l(\rd)
#endif
.endm
+.macro get_got rd
+#if CONFIG_PIC
+ bcl 20, 31, .Lgot\@
+.Lgot\@:
+ mflr \rd
+ addis \rd, \rd, _GLOBAL_OFFSET_TABLE_ - .Lgot\@@ha
+ addi \rd, \rd, _GLOBAL_OFFSET_TABLE_ - .Lgot\@@l
+#endif
+.endm
+
#endif /* ARCH_PPC64 */
#if HAVE_IBM_ASM
diff --git a/libavcodec/ppc/dsputil_altivec.c b/libavcodec/ppc/dsputil_altivec.c
index adce61b277..7f36fa9aad 100644
--- a/libavcodec/ppc/dsputil_altivec.c
+++ b/libavcodec/ppc/dsputil_altivec.c
@@ -3,20 +3,20 @@
* Copyright (c) 2002 Dieter Shirley
* Copyright (c) 2003-2004 Romain Dolbeau <romain@dolbeau.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -627,16 +627,6 @@ void put_pixels16_altivec(uint8_t *block, const uint8_t *pixels, int line_size,
// it's faster than -funroll-loops, but using
// -funroll-loops w/ this is bad - 74 cycles again.
// all this is on a 7450, tuning for the 7450
-#if 0
- for (i = 0; i < h; i++) {
- pixelsv1 = vec_ld(0, pixels);
- pixelsv2 = vec_ld(16, pixels);
- vec_st(vec_perm(pixelsv1, pixelsv2, perm),
- 0, block);
- pixels+=line_size;
- block +=line_size;
- }
-#else
for (i = 0; i < h; i += 4) {
pixelsv1 = vec_ld( 0, pixels);
pixelsv2 = vec_ld(15, pixels);
@@ -657,7 +647,6 @@ void put_pixels16_altivec(uint8_t *block, const uint8_t *pixels, int line_size,
pixels+=line_size_4;
block +=line_size_4;
}
-#endif
}
/* next one assumes that ((line_size % 16) == 0) */
@@ -1384,7 +1373,7 @@ static void avg_pixels8_xy2_altivec(uint8_t *block, const uint8_t *pixels, int l
void dsputil_init_altivec(DSPContext* c, AVCodecContext *avctx)
{
- const int high_bit_depth = avctx->codec_id == CODEC_ID_H264 && avctx->bits_per_raw_sample > 8;
+ const int high_bit_depth = avctx->bits_per_raw_sample > 8;
c->pix_abs[0][1] = sad16_x2_altivec;
c->pix_abs[0][2] = sad16_y2_altivec;
@@ -1398,11 +1387,10 @@ void dsputil_init_altivec(DSPContext* c, AVCodecContext *avctx)
c->sse[0]= sse16_altivec;
c->pix_sum = pix_sum_altivec;
c->diff_pixels = diff_pixels_altivec;
- c->get_pixels = get_pixels_altivec;
- if (!high_bit_depth)
- c->clear_block = clear_block_altivec;
c->add_bytes= add_bytes_altivec;
if (!high_bit_depth) {
+ c->get_pixels = get_pixels_altivec;
+ c->clear_block = clear_block_altivec;
c->put_pixels_tab[0][0] = put_pixels16_altivec;
/* the two functions do the same thing, so use the same code */
c->put_no_rnd_pixels_tab[0][0] = put_pixels16_altivec;
diff --git a/libavcodec/ppc/dsputil_altivec.h b/libavcodec/ppc/dsputil_altivec.h
index abf2dd3e0a..4147eec823 100644
--- a/libavcodec/ppc/dsputil_altivec.h
+++ b/libavcodec/ppc/dsputil_altivec.h
@@ -3,20 +3,20 @@
* Copyright (c) 2002 Dieter Shirley
* Copyright (c) 2003-2004 Romain Dolbeau <romain@dolbeau.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/ppc/dsputil_ppc.c b/libavcodec/ppc/dsputil_ppc.c
index 5f131f3196..568f072b54 100644
--- a/libavcodec/ppc/dsputil_ppc.c
+++ b/libavcodec/ppc/dsputil_ppc.c
@@ -3,20 +3,20 @@
* Copyright (c) 2002 Dieter Shirley
* Copyright (c) 2003-2004 Romain Dolbeau <romain@dolbeau.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -48,7 +48,6 @@ static void clear_blocks_dcbz32_ppc(DCTELEM *blocks)
{
register int misal = ((unsigned long)blocks & 0x00000010);
register int i = 0;
-#if 1
if (misal) {
((unsigned long*)blocks)[0] = 0L;
((unsigned long*)blocks)[1] = 0L;
@@ -66,9 +65,6 @@ static void clear_blocks_dcbz32_ppc(DCTELEM *blocks)
((unsigned long*)blocks)[191] = 0L;
i += 16;
}
-#else
- memset(blocks, 0, sizeof(DCTELEM)*6*64);
-#endif
}
/* same as above, when dcbzl clear a whole 128B cache line
@@ -78,7 +74,6 @@ static void clear_blocks_dcbz128_ppc(DCTELEM *blocks)
{
register int misal = ((unsigned long)blocks & 0x0000007f);
register int i = 0;
-#if 1
if (misal) {
// we could probably also optimize this case,
// but there's not much point as the machines
@@ -89,9 +84,6 @@ static void clear_blocks_dcbz128_ppc(DCTELEM *blocks)
for ( ; i < sizeof(DCTELEM)*6*64 ; i += 128) {
__asm__ volatile("dcbzl %0,%1" : : "b" (blocks), "r" (i) : "memory");
}
-#else
- memset(blocks, 0, sizeof(DCTELEM)*6*64);
-#endif
}
#else
static void clear_blocks_dcbz128_ppc(DCTELEM *blocks)
@@ -153,7 +145,15 @@ static void prefetch_ppc(void *mem, int stride, int h)
void dsputil_init_ppc(DSPContext* c, AVCodecContext *avctx)
{
- const int high_bit_depth = avctx->codec_id == CODEC_ID_H264 && avctx->bits_per_raw_sample > 8;
+ const int high_bit_depth = avctx->bits_per_raw_sample > 8;
+ int mm_flags = av_get_cpu_flags();
+
+ if (avctx->dsp_mask) {
+ if (avctx->dsp_mask & AV_CPU_FLAG_FORCE)
+ mm_flags |= (avctx->dsp_mask & 0xffff);
+ else
+ mm_flags &= ~(avctx->dsp_mask & 0xffff);
+ }
// Common optimizations whether AltiVec is available or not
c->prefetch = prefetch_ppc;
@@ -173,20 +173,21 @@ void dsputil_init_ppc(DSPContext* c, AVCodecContext *avctx)
#if HAVE_ALTIVEC
if(CONFIG_H264_DECODER) dsputil_h264_init_ppc(c, avctx);
- if (av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC) {
+ if (mm_flags & AV_CPU_FLAG_ALTIVEC) {
dsputil_init_altivec(c, avctx);
float_init_altivec(c, avctx);
int_init_altivec(c, avctx);
c->gmc1 = gmc1_altivec;
#if CONFIG_ENCODERS
- if (avctx->dct_algo == FF_DCT_AUTO ||
- avctx->dct_algo == FF_DCT_ALTIVEC) {
+ if (avctx->bits_per_raw_sample <= 8 &&
+ (avctx->dct_algo == FF_DCT_AUTO ||
+ avctx->dct_algo == FF_DCT_ALTIVEC)) {
c->fdct = fdct_altivec;
}
#endif //CONFIG_ENCODERS
- if (avctx->lowres==0) {
+ if (avctx->lowres == 0 && avctx->bits_per_raw_sample <= 8) {
if ((avctx->idct_algo == FF_IDCT_AUTO) ||
(avctx->idct_algo == FF_IDCT_ALTIVEC)) {
c->idct_put = idct_put_altivec;
diff --git a/libavcodec/ppc/fdct_altivec.c b/libavcodec/ppc/fdct_altivec.c
index 8dbfe33f77..1cc6f89f4d 100644
--- a/libavcodec/ppc/fdct_altivec.c
+++ b/libavcodec/ppc/fdct_altivec.c
@@ -1,20 +1,20 @@
/*
* Copyright (C) 2003 James Klicman <james@klicman.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -265,7 +265,6 @@ void fdct_altivec(int16_t *block)
* conversion to vector float. The following code section takes advantage
* of this.
*/
-#if 1
/* fdct rows {{{ */
x0 = ((vector float)vec_add(vs16(b00), vs16(b70)));
x7 = ((vector float)vec_sub(vs16(b00), vs16(b70)));
@@ -389,29 +388,6 @@ void fdct_altivec(int16_t *block)
b31 = vec_add(b31, x2);
b11 = vec_add(b11, x3);
/* }}} */
-#else
- /* convert to float {{{ */
-#define CTF(n) \
- vs32(b##n##1) = vec_unpackl(vs16(b##n##0)); \
- vs32(b##n##0) = vec_unpackh(vs16(b##n##0)); \
- b##n##1 = vec_ctf(vs32(b##n##1), 0); \
- b##n##0 = vec_ctf(vs32(b##n##0), 0); \
-
- CTF(0);
- CTF(1);
- CTF(2);
- CTF(3);
- CTF(4);
- CTF(5);
- CTF(6);
- CTF(7);
-
-#undef CTF
- /* }}} */
-
- FDCTROW(b00, b10, b20, b30, b40, b50, b60, b70);
- FDCTROW(b01, b11, b21, b31, b41, b51, b61, b71);
-#endif
/* 8x8 matrix transpose (vector float[8][2]) {{{ */
diff --git a/libavcodec/ppc/fft_altivec.c b/libavcodec/ppc/fft_altivec.c
index 39830b29a0..e171665b37 100644
--- a/libavcodec/ppc/fft_altivec.c
+++ b/libavcodec/ppc/fft_altivec.c
@@ -3,20 +3,20 @@
* AltiVec-enabled
* Copyright (c) 2009 Loren Merritt
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavcodec/fft.h"
diff --git a/libavcodec/ppc/fft_altivec_s.S b/libavcodec/ppc/fft_altivec_s.S
index ab33900582..16ce838c97 100644
--- a/libavcodec/ppc/fft_altivec_s.S
+++ b/libavcodec/ppc/fft_altivec_s.S
@@ -5,20 +5,20 @@
* This algorithm (though not any of the implementation details) is
* based on libdjbfft by D. J. Bernstein.
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -353,6 +353,7 @@ extfunc ff_fft_calc\interleave\()_altivec
mflr r0
stp r0, 2*PS(r1)
stpu r1, -(160+16*PS)(r1)
+ get_got r11
addi r6, r1, 16*PS
stvm r6, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29
mfvrsave r0
@@ -360,14 +361,14 @@ extfunc ff_fft_calc\interleave\()_altivec
li r6, 0xfffffffc
mtvrsave r6
- movrel r6, fft_data
+ movrel r6, fft_data, r11
lvm r6, v14, v15, v16, v17, v18, v19, v20, v21
lvm r6, v22, v23, v24, v25, v26, v27, v28, v29
li r9, 16
- movrel r12, X(ff_cos_tabs)
+ movrel r12, X(ff_cos_tabs), r11
- movrel r6, fft_dispatch_tab\interleave\()_altivec
+ movrel r6, fft_dispatch_tab\interleave\()_altivec, r11
lwz r3, 0(r3)
subi r3, r3, 2
slwi r3, r3, 2+ARCH_PPC64
diff --git a/libavcodec/ppc/float_altivec.c b/libavcodec/ppc/float_altivec.c
index e4010694a2..ba97cbfd3b 100644
--- a/libavcodec/ppc/float_altivec.c
+++ b/libavcodec/ppc/float_altivec.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2006 Luca Barbato <lu_zero@gentoo.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/ppc/fmtconvert_altivec.c b/libavcodec/ppc/fmtconvert_altivec.c
index b1eaf9b482..30de0e637f 100644
--- a/libavcodec/ppc/fmtconvert_altivec.c
+++ b/libavcodec/ppc/fmtconvert_altivec.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2006 Luca Barbato <lu_zero@gentoo.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/ppc/gmc_altivec.c b/libavcodec/ppc/gmc_altivec.c
index 0ed70ab83b..0e93c337f7 100644
--- a/libavcodec/ppc/gmc_altivec.c
+++ b/libavcodec/ppc/gmc_altivec.c
@@ -3,20 +3,20 @@
* AltiVec-enabled
* Copyright (c) 2003 Romain Dolbeau <romain@dolbeau.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/ppc/h264_altivec.c b/libavcodec/ppc/h264_altivec.c
index 05fae831c9..bf4fd0f016 100644
--- a/libavcodec/ppc/h264_altivec.c
+++ b/libavcodec/ppc/h264_altivec.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2004 Romain Dolbeau <romain@dolbeau.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -843,7 +843,8 @@ static void h264_h_loop_filter_luma_altivec(uint8_t *pix, int stride, int alpha,
}
static av_always_inline
-void weight_h264_WxH_altivec(uint8_t *block, int stride, int log2_denom, int weight, int offset, int w, int h)
+void weight_h264_W_altivec(uint8_t *block, int stride, int height,
+ int log2_denom, int weight, int offset, int w)
{
int y, aligned;
vec_u8 vblock;
@@ -864,7 +865,7 @@ void weight_h264_WxH_altivec(uint8_t *block, int stride, int log2_denom, int wei
voffset = vec_splat(vtemp, 5);
aligned = !((unsigned long)block & 0xf);
- for (y=0; y<h; y++) {
+ for (y = 0; y < height; y++) {
vblock = vec_ld(0, block);
v0 = (vec_s16)vec_mergeh(zero_u8v, vblock);
@@ -888,8 +889,8 @@ void weight_h264_WxH_altivec(uint8_t *block, int stride, int log2_denom, int wei
}
static av_always_inline
-void biweight_h264_WxH_altivec(uint8_t *dst, uint8_t *src, int stride, int log2_denom,
- int weightd, int weights, int offset, int w, int h)
+void biweight_h264_W_altivec(uint8_t *dst, uint8_t *src, int stride, int height,
+ int log2_denom, int weightd, int weights, int offset, int w)
{
int y, dst_aligned, src_aligned;
vec_u8 vsrc, vdst;
@@ -912,7 +913,7 @@ void biweight_h264_WxH_altivec(uint8_t *dst, uint8_t *src, int stride, int log2_
dst_aligned = !((unsigned long)dst & 0xf);
src_aligned = !((unsigned long)src & 0xf);
- for (y=0; y<h; y++) {
+ for (y = 0; y < height; y++) {
vdst = vec_ld(0, dst);
vsrc = vec_ld(0, src);
@@ -952,22 +953,21 @@ void biweight_h264_WxH_altivec(uint8_t *dst, uint8_t *src, int stride, int log2_
}
}
-#define H264_WEIGHT(W,H) \
-static void ff_weight_h264_pixels ## W ## x ## H ## _altivec(uint8_t *block, int stride, int log2_denom, int weight, int offset){ \
- weight_h264_WxH_altivec(block, stride, log2_denom, weight, offset, W, H); \
+#define H264_WEIGHT(W) \
+static void ff_weight_h264_pixels ## W ## _altivec(uint8_t *block, int stride, int height, \
+ int log2_denom, int weight, int offset){ \
+ weight_h264_W_altivec(block, stride, height, log2_denom, weight, offset, W); \
}\
-static void ff_biweight_h264_pixels ## W ## x ## H ## _altivec(uint8_t *dst, uint8_t *src, int stride, int log2_denom, int weightd, int weights, int offset){ \
- biweight_h264_WxH_altivec(dst, src, stride, log2_denom, weightd, weights, offset, W, H); \
+static void ff_biweight_h264_pixels ## W ## _altivec(uint8_t *dst, uint8_t *src, int stride, int height, \
+ int log2_denom, int weightd, int weights, int offset){ \
+ biweight_h264_W_altivec(dst, src, stride, height, log2_denom, weightd, weights, offset, W); \
}
-H264_WEIGHT(16,16)
-H264_WEIGHT(16, 8)
-H264_WEIGHT( 8,16)
-H264_WEIGHT( 8, 8)
-H264_WEIGHT( 8, 4)
+H264_WEIGHT(16)
+H264_WEIGHT( 8)
void dsputil_h264_init_ppc(DSPContext* c, AVCodecContext *avctx) {
- const int high_bit_depth = avctx->codec_id == CODEC_ID_H264 && avctx->bits_per_raw_sample > 8;
+ const int high_bit_depth = avctx->bits_per_raw_sample > 8;
if (av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC) {
if (!high_bit_depth) {
@@ -999,12 +999,13 @@ void dsputil_h264_init_ppc(DSPContext* c, AVCodecContext *avctx) {
}
}
-void ff_h264dsp_init_ppc(H264DSPContext *c, const int bit_depth)
+void ff_h264dsp_init_ppc(H264DSPContext *c, const int bit_depth, const int chroma_format_idc)
{
if (av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC) {
if (bit_depth == 8) {
c->h264_idct_add = ff_h264_idct_add_altivec;
- c->h264_idct_add8 = ff_h264_idct_add8_altivec;
+ if (chroma_format_idc == 1)
+ c->h264_idct_add8 = ff_h264_idct_add8_altivec;
c->h264_idct_add16 = ff_h264_idct_add16_altivec;
c->h264_idct_add16intra = ff_h264_idct_add16intra_altivec;
c->h264_idct_dc_add= h264_idct_dc_add_altivec;
@@ -1014,16 +1015,10 @@ void ff_h264dsp_init_ppc(H264DSPContext *c, const int bit_depth)
c->h264_v_loop_filter_luma= h264_v_loop_filter_luma_altivec;
c->h264_h_loop_filter_luma= h264_h_loop_filter_luma_altivec;
- c->weight_h264_pixels_tab[0] = ff_weight_h264_pixels16x16_altivec;
- c->weight_h264_pixels_tab[1] = ff_weight_h264_pixels16x8_altivec;
- c->weight_h264_pixels_tab[2] = ff_weight_h264_pixels8x16_altivec;
- c->weight_h264_pixels_tab[3] = ff_weight_h264_pixels8x8_altivec;
- c->weight_h264_pixels_tab[4] = ff_weight_h264_pixels8x4_altivec;
- c->biweight_h264_pixels_tab[0] = ff_biweight_h264_pixels16x16_altivec;
- c->biweight_h264_pixels_tab[1] = ff_biweight_h264_pixels16x8_altivec;
- c->biweight_h264_pixels_tab[2] = ff_biweight_h264_pixels8x16_altivec;
- c->biweight_h264_pixels_tab[3] = ff_biweight_h264_pixels8x8_altivec;
- c->biweight_h264_pixels_tab[4] = ff_biweight_h264_pixels8x4_altivec;
+ c->weight_h264_pixels_tab[0] = ff_weight_h264_pixels16_altivec;
+ c->weight_h264_pixels_tab[1] = ff_weight_h264_pixels8_altivec;
+ c->biweight_h264_pixels_tab[0] = ff_biweight_h264_pixels16_altivec;
+ c->biweight_h264_pixels_tab[1] = ff_biweight_h264_pixels8_altivec;
}
}
}
diff --git a/libavcodec/ppc/h264_template_altivec.c b/libavcodec/ppc/h264_template_altivec.c
index 2a8f4bf672..2573e9c6f7 100644
--- a/libavcodec/ppc/h264_template_altivec.c
+++ b/libavcodec/ppc/h264_template_altivec.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2004 Romain Dolbeau <romain@dolbeau.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/ppc/idct_altivec.c b/libavcodec/ppc/idct_altivec.c
index cc3adcb526..d65ba24f3a 100644
--- a/libavcodec/ppc/idct_altivec.c
+++ b/libavcodec/ppc/idct_altivec.c
@@ -1,31 +1,31 @@
/*
* Copyright (c) 2001 Michel Lespinasse
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
* NOTE: This code is based on GPL code from the libmpeg2 project. The
* author, Michel Lespinasses, has given explicit permission to release
- * under LGPL as part of Libav.
+ * under LGPL as part of FFmpeg.
*/
/*
- * Libav integration by Dieter Shirley
+ * FFmpeg integration by Dieter Shirley
*
* This file is a direct copy of the AltiVec IDCT module from the libmpeg2
* project. I've deleted all of the libmpeg2-specific code, renamed the
diff --git a/libavcodec/ppc/int_altivec.c b/libavcodec/ppc/int_altivec.c
index 25cbb8f771..61c18c8154 100644
--- a/libavcodec/ppc/int_altivec.c
+++ b/libavcodec/ppc/int_altivec.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2007 Luca Barbato <lu_zero@gentoo.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/ppc/mathops.h b/libavcodec/ppc/mathops.h
index 34ddb11800..dbd714fcd4 100644
--- a/libavcodec/ppc/mathops.h
+++ b/libavcodec/ppc/mathops.h
@@ -3,20 +3,20 @@
* Copyright (c) 2001, 2002 Fabrice Bellard
* Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at> et al
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/ppc/mpegaudiodec_altivec.c b/libavcodec/ppc/mpegaudiodec_altivec.c
index 5df0fdafe4..2de5dd133a 100644
--- a/libavcodec/ppc/mpegaudiodec_altivec.c
+++ b/libavcodec/ppc/mpegaudiodec_altivec.c
@@ -2,20 +2,20 @@
* Altivec optimized MP3 decoding functions
* Copyright (c) 2010 Vitor Sessak
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/ppc/mpegvideo_altivec.c b/libavcodec/ppc/mpegvideo_altivec.c
index e02c094253..0ba532ec26 100644
--- a/libavcodec/ppc/mpegvideo_altivec.c
+++ b/libavcodec/ppc/mpegvideo_altivec.c
@@ -4,20 +4,20 @@
* dct_unquantize_h263_altivec:
* Copyright (c) 2003 Romain Dolbeau <romain@dolbeau.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -267,8 +267,13 @@ static int dct_quantize_altivec(MpegEncContext* s,
baseVector = vec_cts(vec_splat(row0, 0), 0);
vec_ste(baseVector, 0, &oldBaseValue);
- qmat = (vector signed int*)s->q_intra_matrix[qscale];
- biasAddr = &(s->intra_quant_bias);
+ if(n<4){
+ qmat = (vector signed int*)s->q_intra_matrix[qscale];
+ biasAddr = &(s->intra_quant_bias);
+ }else{
+ qmat = (vector signed int*)s->q_chroma_intra_matrix[qscale];
+ biasAddr = &(s->intra_quant_bias);
+ }
} else {
qmat = (vector signed int*)s->q_inter_matrix[qscale];
biasAddr = &(s->inter_quant_bias);
@@ -515,21 +520,6 @@ static void dct_unquantize_h263_altivec(MpegEncContext *s,
qaddv = vec_splat((vec_s16)vec_lde(0, &qadd8), 0);
nqaddv = vec_sub(vczero, qaddv);
-#if 0 // block *is* 16 bytes-aligned, it seems.
- // first make sure block[j] is 16 bytes-aligned
- for(j = 0; (j <= nCoeffs) && ((((unsigned long)block) + (j << 1)) & 0x0000000F) ; j++) {
- level = block[j];
- if (level) {
- if (level < 0) {
- level = level * qmul - qadd;
- } else {
- level = level * qmul + qadd;
- }
- block[j] = level;
- }
- }
-#endif
-
// vectorize all the 16 bytes-aligned blocks
// of 8 elements
for(; (j + 7) <= nCoeffs ; j+=8) {
@@ -573,15 +563,6 @@ void MPV_common_init_altivec(MpegEncContext *s)
{
if (!(av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC)) return;
- if (s->avctx->lowres==0) {
- if ((s->avctx->idct_algo == FF_IDCT_AUTO) ||
- (s->avctx->idct_algo == FF_IDCT_ALTIVEC)) {
- s->dsp.idct_put = idct_put_altivec;
- s->dsp.idct_add = idct_add_altivec;
- s->dsp.idct_permutation_type = FF_TRANSPOSE_IDCT_PERM;
- }
- }
-
// Test to make sure that the dct required alignments are met.
if ((((long)(s->q_intra_matrix) & 0x0f) != 0) ||
(((long)(s->q_inter_matrix) & 0x0f) != 0)) {
@@ -599,9 +580,6 @@ void MPV_common_init_altivec(MpegEncContext *s)
if ((s->avctx->dct_algo == FF_DCT_AUTO) ||
(s->avctx->dct_algo == FF_DCT_ALTIVEC)) {
-#if 0 /* seems to cause trouble under some circumstances */
- s->dct_quantize = dct_quantize_altivec;
-#endif
s->dct_unquantize_h263_intra = dct_unquantize_h263_altivec;
s->dct_unquantize_h263_inter = dct_unquantize_h263_altivec;
}
diff --git a/libavcodec/ppc/regs.h b/libavcodec/ppc/regs.h
index 2edd639531..63861f28fb 100644
--- a/libavcodec/ppc/regs.h
+++ b/libavcodec/ppc/regs.h
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2010 Mans Rullgard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/ppc/types_altivec.h b/libavcodec/ppc/types_altivec.h
index defa20e243..36b6e1f388 100644
--- a/libavcodec/ppc/types_altivec.h
+++ b/libavcodec/ppc/types_altivec.h
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2006 Guillaume Poirier <gpoirier@mplayerhq.hu>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/ppc/util_altivec.h b/libavcodec/ppc/util_altivec.h
index e68e5b593d..cb638dff08 100644
--- a/libavcodec/ppc/util_altivec.h
+++ b/libavcodec/ppc/util_altivec.h
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/ppc/vc1dsp_altivec.c b/libavcodec/ppc/vc1dsp_altivec.c
index 307e0e9f6b..69670619da 100644
--- a/libavcodec/ppc/vc1dsp_altivec.c
+++ b/libavcodec/ppc/vc1dsp_altivec.c
@@ -2,20 +2,20 @@
* VC-1 and WMV3 decoder - DSP functions AltiVec-optimized
* Copyright (c) 2006 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/ppc/vp3dsp_altivec.c b/libavcodec/ppc/vp3dsp_altivec.c
index bbe9170edf..b0509d8b64 100644
--- a/libavcodec/ppc/vp3dsp_altivec.c
+++ b/libavcodec/ppc/vp3dsp_altivec.c
@@ -1,20 +1,20 @@
/*
* Copyright (C) 2009 David Conrad
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/ppc/vp8dsp_altivec.c b/libavcodec/ppc/vp8dsp_altivec.c
index 06874b8b87..8bb60aae0b 100644
--- a/libavcodec/ppc/vp8dsp_altivec.c
+++ b/libavcodec/ppc/vp8dsp_altivec.c
@@ -3,20 +3,20 @@
*
* Copyright (C) 2010 David Conrad
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/proresdec.h b/libavcodec/proresdec.h
new file mode 100644
index 0000000000..b3a81d5044
--- /dev/null
+++ b/libavcodec/proresdec.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2010-2011 Maxim Poliakovski
+ * Copyright (c) 2010-2011 Elvis Presley
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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;
+ * version 2 of the License.
+ *
+ * FFmpeg 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 FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_PRORESDEC_H
+#define AVCODEC_PRORESDEC_H
+
+#include "dsputil.h"
+#include "proresdsp.h"
+
+typedef struct {
+ const uint8_t *data;
+ unsigned mb_x;
+ unsigned mb_y;
+ unsigned mb_count;
+ unsigned data_size;
+} SliceContext;
+
+typedef struct {
+ DSPContext dsp;
+ ProresDSPContext prodsp;
+ AVFrame frame;
+ int frame_type; ///< 0 = progressive, 1 = tff, 2 = bff
+ uint8_t qmat_luma[64];
+ uint8_t qmat_chroma[64];
+ SliceContext *slices;
+ int slice_count; ///< number of slices in the current picture
+ unsigned mb_width; ///< width of the current picture in mb
+ unsigned mb_height; ///< height of the current picture in mb
+ uint8_t progressive_scan[64];
+ uint8_t interlaced_scan[64];
+ const uint8_t *scan;
+ int first_field;
+} ProresContext;
+
+#endif /* AVCODEC_PRORESDEC_H */
diff --git a/libavcodec/proresdec2.c b/libavcodec/proresdec2.c
new file mode 100644
index 0000000000..a96af4fa9f
--- /dev/null
+++ b/libavcodec/proresdec2.c
@@ -0,0 +1,593 @@
+/*
+ * Copyright (c) 2010-2011 Maxim Poliakovski
+ * Copyright (c) 2010-2011 Elvis Presley
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * Known FOURCCs: 'apch' (HQ), 'apcn' (SD), 'apcs' (LT), 'acpo' (Proxy), 'ap4h' (4444)
+ */
+
+//#define DEBUG
+
+#define A32_BITSTREAM_READER
+
+#include "avcodec.h"
+#include "get_bits.h"
+#include "simple_idct.h"
+#include "proresdec.h"
+
+static void permute(uint8_t *dst, const uint8_t *src, const uint8_t permutation[64])
+{
+ int i;
+ for (i = 0; i < 64; i++)
+ dst[i] = permutation[src[i]];
+}
+
+static const uint8_t progressive_scan[64] = {
+ 0, 1, 8, 9, 2, 3, 10, 11,
+ 16, 17, 24, 25, 18, 19, 26, 27,
+ 4, 5, 12, 20, 13, 6, 7, 14,
+ 21, 28, 29, 22, 15, 23, 30, 31,
+ 32, 33, 40, 48, 41, 34, 35, 42,
+ 49, 56, 57, 50, 43, 36, 37, 44,
+ 51, 58, 59, 52, 45, 38, 39, 46,
+ 53, 60, 61, 54, 47, 55, 62, 63
+};
+
+static const uint8_t interlaced_scan[64] = {
+ 0, 8, 1, 9, 16, 24, 17, 25,
+ 2, 10, 3, 11, 18, 26, 19, 27,
+ 32, 40, 33, 34, 41, 48, 56, 49,
+ 42, 35, 43, 50, 57, 58, 51, 59,
+ 4, 12, 5, 6, 13, 20, 28, 21,
+ 14, 7, 15, 22, 29, 36, 44, 37,
+ 30, 23, 31, 38, 45, 52, 60, 53,
+ 46, 39, 47, 54, 61, 62, 55, 63,
+};
+
+static av_cold int decode_init(AVCodecContext *avctx)
+{
+ ProresContext *ctx = avctx->priv_data;
+ uint8_t idct_permutation[64];
+
+ avctx->bits_per_raw_sample = 10;
+
+ dsputil_init(&ctx->dsp, avctx);
+ ff_proresdsp_init(&ctx->prodsp, avctx);
+
+ avctx->coded_frame = &ctx->frame;
+ ctx->frame.type = FF_I_TYPE;
+ ctx->frame.key_frame = 1;
+
+ ff_init_scantable_permutation(idct_permutation,
+ ctx->prodsp.idct_permutation_type);
+
+ permute(ctx->progressive_scan, progressive_scan, idct_permutation);
+ permute(ctx->interlaced_scan, interlaced_scan, idct_permutation);
+
+ return 0;
+}
+
+static int decode_frame_header(ProresContext *ctx, const uint8_t *buf,
+ const int data_size, AVCodecContext *avctx)
+{
+ int hdr_size, width, height, flags;
+ int version;
+ const uint8_t *ptr;
+
+ hdr_size = AV_RB16(buf);
+ av_dlog(avctx, "header size %d\n", hdr_size);
+ if (hdr_size > data_size) {
+ av_log(avctx, AV_LOG_ERROR, "error, wrong header size\n");
+ return -1;
+ }
+
+ version = AV_RB16(buf + 2);
+ av_dlog(avctx, "%.4s version %d\n", buf+4, version);
+ if (version > 1) {
+ av_log(avctx, AV_LOG_ERROR, "unsupported version: %d\n", version);
+ return -1;
+ }
+
+ width = AV_RB16(buf + 8);
+ height = AV_RB16(buf + 10);
+ if (width != avctx->width || height != avctx->height) {
+ av_log(avctx, AV_LOG_ERROR, "picture resolution change: %dx%d -> %dx%d\n",
+ avctx->width, avctx->height, width, height);
+ return -1;
+ }
+
+ ctx->frame_type = (buf[12] >> 2) & 3;
+
+ av_dlog(avctx, "frame type %d\n", ctx->frame_type);
+
+ if (ctx->frame_type == 0) {
+ ctx->scan = ctx->progressive_scan; // permuted
+ } else {
+ ctx->scan = ctx->interlaced_scan; // permuted
+ ctx->frame.interlaced_frame = 1;
+ ctx->frame.top_field_first = ctx->frame_type == 1;
+ }
+
+ avctx->pix_fmt = (buf[12] & 0xC0) == 0xC0 ? PIX_FMT_YUV444P10 : PIX_FMT_YUV422P10;
+
+ ptr = buf + 20;
+ flags = buf[19];
+ av_dlog(avctx, "flags %x\n", flags);
+
+ if (flags & 2) {
+ permute(ctx->qmat_luma, ctx->prodsp.idct_permutation, ptr);
+ ptr += 64;
+ } else {
+ memset(ctx->qmat_luma, 4, 64);
+ }
+
+ if (flags & 1) {
+ permute(ctx->qmat_chroma, ctx->prodsp.idct_permutation, ptr);
+ } else {
+ memset(ctx->qmat_chroma, 4, 64);
+ }
+
+ return hdr_size;
+}
+
+static int decode_picture_header(AVCodecContext *avctx, const uint8_t *buf, const int buf_size)
+{
+ ProresContext *ctx = avctx->priv_data;
+ int i, hdr_size, slice_count;
+ unsigned pic_data_size;
+ int log2_slice_mb_width, log2_slice_mb_height;
+ int slice_mb_count, mb_x, mb_y;
+ const uint8_t *data_ptr, *index_ptr;
+
+ hdr_size = buf[0] >> 3;
+ if (hdr_size < 8 || hdr_size > buf_size) {
+ av_log(avctx, AV_LOG_ERROR, "error, wrong picture header size\n");
+ return -1;
+ }
+
+ pic_data_size = AV_RB32(buf + 1);
+ if (pic_data_size > buf_size) {
+ av_log(avctx, AV_LOG_ERROR, "error, wrong picture data size\n");
+ return -1;
+ }
+
+ log2_slice_mb_width = buf[7] >> 4;
+ log2_slice_mb_height = buf[7] & 0xF;
+ if (log2_slice_mb_width > 3 || log2_slice_mb_height) {
+ av_log(avctx, AV_LOG_ERROR, "unsupported slice resolution: %dx%d\n",
+ 1 << log2_slice_mb_width, 1 << log2_slice_mb_height);
+ return -1;
+ }
+
+ ctx->mb_width = (avctx->width + 15) >> 4;
+ if (ctx->frame_type)
+ ctx->mb_height = (avctx->height + 31) >> 5;
+ else
+ ctx->mb_height = (avctx->height + 15) >> 4;
+
+ slice_count = AV_RB16(buf + 5);
+
+ if (ctx->slice_count != slice_count || !ctx->slices) {
+ av_freep(&ctx->slices);
+ ctx->slices = av_mallocz(slice_count * sizeof(*ctx->slices));
+ if (!ctx->slices)
+ return AVERROR(ENOMEM);
+ ctx->slice_count = slice_count;
+ }
+
+ if (!slice_count)
+ return AVERROR(EINVAL);
+
+ if (hdr_size + slice_count*2 > buf_size) {
+ av_log(avctx, AV_LOG_ERROR, "error, wrong slice count\n");
+ return -1;
+ }
+
+ // parse slice information
+ index_ptr = buf + hdr_size;
+ data_ptr = index_ptr + slice_count*2;
+
+ slice_mb_count = 1 << log2_slice_mb_width;
+ mb_x = 0;
+ mb_y = 0;
+
+ for (i = 0; i < slice_count; i++) {
+ SliceContext *slice = &ctx->slices[i];
+
+ slice->data = data_ptr;
+ data_ptr += AV_RB16(index_ptr + i*2);
+
+ while (ctx->mb_width - mb_x < slice_mb_count)
+ slice_mb_count >>= 1;
+
+ slice->mb_x = mb_x;
+ slice->mb_y = mb_y;
+ slice->mb_count = slice_mb_count;
+ slice->data_size = data_ptr - slice->data;
+
+ if (slice->data_size < 6) {
+ av_log(avctx, AV_LOG_ERROR, "error, wrong slice data size\n");
+ return -1;
+ }
+
+ mb_x += slice_mb_count;
+ if (mb_x == ctx->mb_width) {
+ slice_mb_count = 1 << log2_slice_mb_width;
+ mb_x = 0;
+ mb_y++;
+ }
+ if (data_ptr > buf + buf_size) {
+ av_log(avctx, AV_LOG_ERROR, "error, slice out of bounds\n");
+ return -1;
+ }
+ }
+
+ if (mb_x || mb_y != ctx->mb_height) {
+ av_log(avctx, AV_LOG_ERROR, "error wrong mb count y %d h %d\n",
+ mb_y, ctx->mb_height);
+ return -1;
+ }
+
+ return pic_data_size;
+}
+
+#define DECODE_CODEWORD(val, codebook) \
+ do { \
+ unsigned int rice_order, exp_order, switch_bits; \
+ unsigned int q, buf, bits; \
+ \
+ UPDATE_CACHE(re, gb); \
+ buf = GET_CACHE(re, gb); \
+ \
+ /* number of bits to switch between rice and exp golomb */ \
+ switch_bits = codebook & 3; \
+ rice_order = codebook >> 5; \
+ exp_order = (codebook >> 2) & 7; \
+ \
+ q = 31 - av_log2(buf); \
+ \
+ if (q > switch_bits) { /* exp golomb */ \
+ bits = exp_order - switch_bits + (q<<1); \
+ val = SHOW_UBITS(re, gb, bits) - (1 << exp_order) + \
+ ((switch_bits + 1) << rice_order); \
+ SKIP_BITS(re, gb, bits); \
+ } else if (rice_order) { \
+ SKIP_BITS(re, gb, q+1); \
+ val = (q << rice_order) + SHOW_UBITS(re, gb, rice_order); \
+ SKIP_BITS(re, gb, rice_order); \
+ } else { \
+ val = q; \
+ SKIP_BITS(re, gb, q+1); \
+ } \
+ } while (0); \
+
+#define TOSIGNED(x) (((x) >> 1) ^ (-((x) & 1)))
+
+#define FIRST_DC_CB 0xB8
+
+static const uint8_t dc_codebook[7] = { 0x04, 0x28, 0x28, 0x4D, 0x4D, 0x70, 0x70};
+
+static av_always_inline void decode_dc_coeffs(GetBitContext *gb, DCTELEM *out,
+ int blocks_per_slice)
+{
+ DCTELEM prev_dc;
+ int code, i, sign;
+
+ OPEN_READER(re, gb);
+
+ DECODE_CODEWORD(code, FIRST_DC_CB);
+ prev_dc = TOSIGNED(code);
+ out[0] = prev_dc;
+
+ out += 64; // dc coeff for the next block
+
+ code = 5;
+ sign = 0;
+ for (i = 1; i < blocks_per_slice; i++, out += 64) {
+ DECODE_CODEWORD(code, dc_codebook[FFMIN(code, 6)]);
+ if(code) sign ^= -(code & 1);
+ else sign = 0;
+ prev_dc += (((code + 1) >> 1) ^ sign) - sign;
+ out[0] = prev_dc;
+ }
+ CLOSE_READER(re, gb);
+}
+
+// adaptive codebook switching lut according to previous run/level values
+static const uint8_t run_to_cb[16] = { 0x06, 0x06, 0x05, 0x05, 0x04, 0x29, 0x29, 0x29, 0x29, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x4C };
+static const uint8_t lev_to_cb[10] = { 0x04, 0x0A, 0x05, 0x06, 0x04, 0x28, 0x28, 0x28, 0x28, 0x4C };
+
+static av_always_inline void decode_ac_coeffs(AVCodecContext *avctx, GetBitContext *gb,
+ DCTELEM *out, int blocks_per_slice)
+{
+ ProresContext *ctx = avctx->priv_data;
+ int block_mask, sign;
+ unsigned pos, run, level;
+ int max_coeffs, i, bits_left;
+ int log2_block_count = av_log2(blocks_per_slice);
+
+ OPEN_READER(re, gb);
+
+ run = 4;
+ level = 2;
+
+ max_coeffs = 64 << log2_block_count;
+ block_mask = blocks_per_slice - 1;
+
+ for (pos = block_mask;;) {
+ bits_left = gb->size_in_bits - (((uint8_t*)re_buffer_ptr - gb->buffer)*8 - 32 + re_bit_count);
+ if (!bits_left || (bits_left < 32 && !SHOW_UBITS(re, gb, bits_left)))
+ break;
+
+ DECODE_CODEWORD(run, run_to_cb[FFMIN(run, 15)]);
+ pos += run + 1;
+ if (pos >= max_coeffs) {
+ av_log(avctx, AV_LOG_ERROR, "ac tex damaged %d, %d\n", pos, max_coeffs);
+ return;
+ }
+
+ DECODE_CODEWORD(level, lev_to_cb[FFMIN(level, 9)]);
+ level += 1;
+
+ i = pos >> log2_block_count;
+
+ sign = SHOW_SBITS(re, gb, 1);
+ SKIP_BITS(re, gb, 1);
+ out[((pos & block_mask) << 6) + ctx->scan[i]] = ((level ^ sign) - sign);
+ }
+
+ CLOSE_READER(re, gb);
+}
+
+static void decode_slice_luma(AVCodecContext *avctx, SliceContext *slice,
+ uint8_t *dst, int dst_stride,
+ const uint8_t *buf, unsigned buf_size,
+ const int16_t *qmat)
+{
+ ProresContext *ctx = avctx->priv_data;
+ LOCAL_ALIGNED_16(DCTELEM, blocks, [8*4*64]);
+ DCTELEM *block;
+ GetBitContext gb;
+ int i, blocks_per_slice = slice->mb_count<<2;
+
+ for (i = 0; i < blocks_per_slice; i++)
+ ctx->dsp.clear_block(blocks+(i<<6));
+
+ init_get_bits(&gb, buf, buf_size << 3);
+
+ decode_dc_coeffs(&gb, blocks, blocks_per_slice);
+ decode_ac_coeffs(avctx, &gb, blocks, blocks_per_slice);
+
+ block = blocks;
+ for (i = 0; i < slice->mb_count; i++) {
+ ctx->prodsp.idct_put(dst, dst_stride, block+(0<<6), qmat);
+ ctx->prodsp.idct_put(dst+16, dst_stride, block+(1<<6), qmat);
+ ctx->prodsp.idct_put(dst+8*dst_stride, dst_stride, block+(2<<6), qmat);
+ ctx->prodsp.idct_put(dst+8*dst_stride+16, dst_stride, block+(3<<6), qmat);
+ block += 4*64;
+ dst += 32;
+ }
+}
+
+static void decode_slice_chroma(AVCodecContext *avctx, SliceContext *slice,
+ uint8_t *dst, int dst_stride,
+ const uint8_t *buf, unsigned buf_size,
+ const int16_t *qmat, int log2_blocks_per_mb)
+{
+ ProresContext *ctx = avctx->priv_data;
+ LOCAL_ALIGNED_16(DCTELEM, blocks, [8*4*64]);
+ DCTELEM *block;
+ GetBitContext gb;
+ int i, j, blocks_per_slice = slice->mb_count << log2_blocks_per_mb;
+
+ for (i = 0; i < blocks_per_slice; i++)
+ ctx->dsp.clear_block(blocks+(i<<6));
+
+ init_get_bits(&gb, buf, buf_size << 3);
+
+ decode_dc_coeffs(&gb, blocks, blocks_per_slice);
+ decode_ac_coeffs(avctx, &gb, blocks, blocks_per_slice);
+
+ block = blocks;
+ for (i = 0; i < slice->mb_count; i++) {
+ for (j = 0; j < log2_blocks_per_mb; j++) {
+ ctx->prodsp.idct_put(dst, dst_stride, block+(0<<6), qmat);
+ ctx->prodsp.idct_put(dst+8*dst_stride, dst_stride, block+(1<<6), qmat);
+ block += 2*64;
+ dst += 16;
+ }
+ }
+}
+
+static int decode_slice_thread(AVCodecContext *avctx, void *arg, int jobnr, int threadnr)
+{
+ ProresContext *ctx = avctx->priv_data;
+ SliceContext *slice = &ctx->slices[jobnr];
+ const uint8_t *buf = slice->data;
+ AVFrame *pic = avctx->coded_frame;
+ int i, hdr_size, qscale, log2_chroma_blocks_per_mb;
+ int luma_stride, chroma_stride;
+ int y_data_size, u_data_size, v_data_size;
+ uint8_t *dest_y, *dest_u, *dest_v;
+ int16_t qmat_luma_scaled[64];
+ int16_t qmat_chroma_scaled[64];
+ int mb_x_shift;
+
+ //av_log(avctx, AV_LOG_INFO, "slice %d mb width %d mb x %d y %d\n",
+ // jobnr, slice->mb_count, slice->mb_x, slice->mb_y);
+
+ // slice header
+ hdr_size = buf[0] >> 3;
+ qscale = av_clip(buf[1], 1, 224);
+ qscale = qscale > 128 ? qscale - 96 << 2: qscale;
+ y_data_size = AV_RB16(buf + 2);
+ u_data_size = AV_RB16(buf + 4);
+ v_data_size = slice->data_size - y_data_size - u_data_size - hdr_size;
+ if (hdr_size > 7) v_data_size = AV_RB16(buf + 6);
+
+ if (y_data_size < 0 || u_data_size < 0 || v_data_size < 0) {
+ av_log(avctx, AV_LOG_ERROR, "invalid plane data size\n");
+ return -1;
+ }
+
+ buf += hdr_size;
+
+ for (i = 0; i < 64; i++) {
+ qmat_luma_scaled [i] = ctx->qmat_luma [i] * qscale;
+ qmat_chroma_scaled[i] = ctx->qmat_chroma[i] * qscale;
+ }
+
+ if (ctx->frame_type == 0) {
+ luma_stride = pic->linesize[0];
+ chroma_stride = pic->linesize[1];
+ } else {
+ luma_stride = pic->linesize[0] << 1;
+ chroma_stride = pic->linesize[1] << 1;
+ }
+
+ if (avctx->pix_fmt == PIX_FMT_YUV444P10) {
+ mb_x_shift = 5;
+ log2_chroma_blocks_per_mb = 2;
+ } else {
+ mb_x_shift = 4;
+ log2_chroma_blocks_per_mb = 1;
+ }
+
+ dest_y = pic->data[0] + (slice->mb_y << 4) * luma_stride + (slice->mb_x << 5);
+ dest_u = pic->data[1] + (slice->mb_y << 4) * chroma_stride + (slice->mb_x << mb_x_shift);
+ dest_v = pic->data[2] + (slice->mb_y << 4) * chroma_stride + (slice->mb_x << mb_x_shift);
+
+ if (ctx->frame_type && ctx->first_field ^ ctx->frame.top_field_first) {
+ dest_y += pic->linesize[0];
+ dest_u += pic->linesize[1];
+ dest_v += pic->linesize[2];
+ }
+
+ decode_slice_luma(avctx, slice, dest_y, luma_stride,
+ buf, y_data_size, qmat_luma_scaled);
+
+ if (!(avctx->flags & CODEC_FLAG_GRAY)) {
+ decode_slice_chroma(avctx, slice, dest_u, chroma_stride,
+ buf + y_data_size, u_data_size,
+ qmat_chroma_scaled, log2_chroma_blocks_per_mb);
+ decode_slice_chroma(avctx, slice, dest_v, chroma_stride,
+ buf + y_data_size + u_data_size, v_data_size,
+ qmat_chroma_scaled, log2_chroma_blocks_per_mb);
+ }
+
+ return 0;
+}
+
+static int decode_picture(AVCodecContext *avctx)
+{
+ ProresContext *ctx = avctx->priv_data;
+ int i, threads_ret[ctx->slice_count];
+
+ avctx->execute2(avctx, decode_slice_thread, NULL, threads_ret, ctx->slice_count);
+
+ for (i = 0; i < ctx->slice_count; i++)
+ if (threads_ret[i] < 0)
+ return threads_ret[i];
+
+ return 0;
+}
+
+static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
+ AVPacket *avpkt)
+{
+ ProresContext *ctx = avctx->priv_data;
+ AVFrame *frame = avctx->coded_frame;
+ const uint8_t *buf = avpkt->data;
+ int buf_size = avpkt->size;
+ int frame_hdr_size, pic_size;
+
+ if (buf_size < 28 || AV_RL32(buf + 4) != AV_RL32("icpf")) {
+ av_log(avctx, AV_LOG_ERROR, "invalid frame header\n");
+ return -1;
+ }
+
+ ctx->first_field = 1;
+
+ buf += 8;
+ buf_size -= 8;
+
+ frame_hdr_size = decode_frame_header(ctx, buf, buf_size, avctx);
+ if (frame_hdr_size < 0)
+ return -1;
+
+ buf += frame_hdr_size;
+ buf_size -= frame_hdr_size;
+
+ if (frame->data[0])
+ avctx->release_buffer(avctx, frame);
+
+ if (avctx->get_buffer(avctx, frame) < 0)
+ return -1;
+
+ decode_picture:
+ pic_size = decode_picture_header(avctx, buf, buf_size);
+ if (pic_size < 0) {
+ av_log(avctx, AV_LOG_ERROR, "error decoding picture header\n");
+ return -1;
+ }
+
+ if (decode_picture(avctx)) {
+ av_log(avctx, AV_LOG_ERROR, "error decoding picture\n");
+ return -1;
+ }
+
+ buf += pic_size;
+ buf_size -= pic_size;
+
+ if (ctx->frame_type && buf_size > 0 && ctx->first_field) {
+ ctx->first_field = 0;
+ goto decode_picture;
+ }
+
+ *data_size = sizeof(AVFrame);
+ *(AVFrame*)data = *frame;
+
+ return avpkt->size;
+}
+
+static av_cold int decode_close(AVCodecContext *avctx)
+{
+ ProresContext *ctx = avctx->priv_data;
+
+ AVFrame *frame = avctx->coded_frame;
+ if (frame->data[0])
+ avctx->release_buffer(avctx, frame);
+ av_freep(&ctx->slices);
+
+ return 0;
+}
+
+AVCodec ff_prores_decoder = {
+ .name = "prores",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_PRORES,
+ .priv_data_size = sizeof(ProresContext),
+ .init = decode_init,
+ .close = decode_close,
+ .decode = decode_frame,
+ .long_name = NULL_IF_CONFIG_SMALL("ProRes"),
+ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_SLICE_THREADS,
+};
diff --git a/libavcodec/proresdec_lgpl.c b/libavcodec/proresdec_lgpl.c
new file mode 100644
index 0000000000..84d81ee425
--- /dev/null
+++ b/libavcodec/proresdec_lgpl.c
@@ -0,0 +1,705 @@
+/*
+ * Apple ProRes compatible decoder
+ *
+ * Copyright (c) 2010-2011 Maxim Poliakovski
+ *
+ * This file is part of Libav.
+ *
+ * Libav 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.
+ *
+ * Libav 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * This is a decoder for Apple ProRes 422 SD/HQ/LT/Proxy and ProRes 4444.
+ * It is used for storing and editing high definition video data in Apple's Final Cut Pro.
+ *
+ * @see http://wiki.multimedia.cx/index.php?title=Apple_ProRes
+ */
+
+#define A32_BITSTREAM_READER // some ProRes vlc codes require up to 28 bits to be read at once
+
+#include <stdint.h>
+
+#include "libavutil/intmath.h"
+#include "avcodec.h"
+#include "proresdsp.h"
+#include "get_bits.h"
+
+typedef struct {
+ const uint8_t *index; ///< pointers to the data of this slice
+ int slice_num;
+ int x_pos, y_pos;
+ int slice_width;
+ DECLARE_ALIGNED(16, DCTELEM, blocks[8 * 4 * 64]);
+} ProresThreadData;
+
+typedef struct {
+ ProresDSPContext dsp;
+ AVFrame picture;
+ ScanTable scantable;
+ int scantable_type; ///< -1 = uninitialized, 0 = progressive, 1/2 = interlaced
+
+ int frame_type; ///< 0 = progressive, 1 = top-field first, 2 = bottom-field first
+ int pic_format; ///< 2 = 422, 3 = 444
+ uint8_t qmat_luma[64]; ///< dequantization matrix for luma
+ uint8_t qmat_chroma[64]; ///< dequantization matrix for chroma
+ int qmat_changed; ///< 1 - global quantization matrices changed
+ int prev_slice_sf; ///< scalefactor of the previous decoded slice
+ DECLARE_ALIGNED(16, int16_t, qmat_luma_scaled[64]);
+ DECLARE_ALIGNED(16, int16_t, qmat_chroma_scaled[64]);
+ int total_slices; ///< total number of slices in a picture
+ ProresThreadData *slice_data;
+ int pic_num;
+ int chroma_factor;
+ int mb_chroma_factor;
+ int num_chroma_blocks; ///< number of chrominance blocks in a macroblock
+ int num_x_slices;
+ int num_y_slices;
+ int slice_width_factor;
+ int slice_height_factor;
+ int num_x_mbs;
+ int num_y_mbs;
+ int alpha_info;
+} ProresContext;
+
+
+static const uint8_t progressive_scan[64] = {
+ 0, 1, 8, 9, 2, 3, 10, 11,
+ 16, 17, 24, 25, 18, 19, 26, 27,
+ 4, 5, 12, 20, 13, 6, 7, 14,
+ 21, 28, 29, 22, 15, 23, 30, 31,
+ 32, 33, 40, 48, 41, 34, 35, 42,
+ 49, 56, 57, 50, 43, 36, 37, 44,
+ 51, 58, 59, 52, 45, 38, 39, 46,
+ 53, 60, 61, 54, 47, 55, 62, 63
+};
+
+static const uint8_t interlaced_scan[64] = {
+ 0, 8, 1, 9, 16, 24, 17, 25,
+ 2, 10, 3, 11, 18, 26, 19, 27,
+ 32, 40, 33, 34, 41, 48, 56, 49,
+ 42, 35, 43, 50, 57, 58, 51, 59,
+ 4, 12, 5, 6, 13, 20, 28, 21,
+ 14, 7, 15, 22, 29, 36, 44, 37,
+ 30, 23, 31, 38, 45, 52, 60, 53,
+ 46, 39, 47, 54, 61, 62, 55, 63
+};
+
+
+static av_cold int decode_init(AVCodecContext *avctx)
+{
+ ProresContext *ctx = avctx->priv_data;
+
+ ctx->total_slices = 0;
+ ctx->slice_data = NULL;
+
+ avctx->bits_per_raw_sample = PRORES_BITS_PER_SAMPLE;
+ ff_proresdsp_init(&ctx->dsp, avctx);
+
+ avctx->coded_frame = &ctx->picture;
+ avcodec_get_frame_defaults(&ctx->picture);
+ ctx->picture.type = AV_PICTURE_TYPE_I;
+ ctx->picture.key_frame = 1;
+
+ ctx->scantable_type = -1; // set scantable type to uninitialized
+ memset(ctx->qmat_luma, 4, 64);
+ memset(ctx->qmat_chroma, 4, 64);
+ ctx->prev_slice_sf = 0;
+
+ return 0;
+}
+
+
+static int decode_frame_header(ProresContext *ctx, const uint8_t *buf,
+ const int data_size, AVCodecContext *avctx)
+{
+ int hdr_size, version, width, height, flags;
+ const uint8_t *ptr;
+
+ hdr_size = AV_RB16(buf);
+ if (hdr_size > data_size) {
+ av_log(avctx, AV_LOG_ERROR, "frame data too small\n");
+ return AVERROR_INVALIDDATA;
+ }
+
+ version = AV_RB16(buf + 2);
+ if (version >= 2) {
+ av_log(avctx, AV_LOG_ERROR,
+ "unsupported header version: %d\n", version);
+ return AVERROR_INVALIDDATA;
+ }
+
+ width = AV_RB16(buf + 8);
+ height = AV_RB16(buf + 10);
+ if (width != avctx->width || height != avctx->height) {
+ av_log(avctx, AV_LOG_ERROR,
+ "picture dimension changed: old: %d x %d, new: %d x %d\n",
+ avctx->width, avctx->height, width, height);
+ return AVERROR_INVALIDDATA;
+ }
+
+ ctx->frame_type = (buf[12] >> 2) & 3;
+ if (ctx->frame_type > 2) {
+ av_log(avctx, AV_LOG_ERROR,
+ "unsupported frame type: %d\n", ctx->frame_type);
+ return AVERROR_INVALIDDATA;
+ }
+
+ ctx->chroma_factor = (buf[12] >> 6) & 3;
+ ctx->mb_chroma_factor = ctx->chroma_factor + 2;
+ ctx->num_chroma_blocks = (1 << ctx->chroma_factor) >> 1;
+ switch (ctx->chroma_factor) {
+ case 2:
+ avctx->pix_fmt = PIX_FMT_YUV422P10;
+ break;
+ case 3:
+ avctx->pix_fmt = PIX_FMT_YUV444P10;
+ break;
+ default:
+ av_log(avctx, AV_LOG_ERROR,
+ "unsupported picture format: %d\n", ctx->pic_format);
+ return AVERROR_INVALIDDATA;
+ }
+
+ if (ctx->scantable_type != ctx->frame_type) {
+ if (!ctx->frame_type)
+ ff_init_scantable(ctx->dsp.idct_permutation, &ctx->scantable,
+ progressive_scan);
+ else
+ ff_init_scantable(ctx->dsp.idct_permutation, &ctx->scantable,
+ interlaced_scan);
+ ctx->scantable_type = ctx->frame_type;
+ }
+
+ if (ctx->frame_type) { /* if interlaced */
+ ctx->picture.interlaced_frame = 1;
+ ctx->picture.top_field_first = ctx->frame_type & 1;
+ }
+
+ ctx->alpha_info = buf[17] & 0xf;
+ if (ctx->alpha_info)
+ av_log_missing_feature(avctx, "alpha channel", 0);
+
+ ctx->qmat_changed = 0;
+ ptr = buf + 20;
+ flags = buf[19];
+ if (flags & 2) {
+ if (ptr - buf > hdr_size - 64) {
+ av_log(avctx, AV_LOG_ERROR, "header data too small\n");
+ return AVERROR_INVALIDDATA;
+ }
+ if (memcmp(ctx->qmat_luma, ptr, 64)) {
+ memcpy(ctx->qmat_luma, ptr, 64);
+ ctx->qmat_changed = 1;
+ }
+ ptr += 64;
+ } else {
+ memset(ctx->qmat_luma, 4, 64);
+ ctx->qmat_changed = 1;
+ }
+
+ if (flags & 1) {
+ if (ptr - buf > hdr_size - 64) {
+ av_log(avctx, AV_LOG_ERROR, "header data too small\n");
+ return -1;
+ }
+ if (memcmp(ctx->qmat_chroma, ptr, 64)) {
+ memcpy(ctx->qmat_chroma, ptr, 64);
+ ctx->qmat_changed = 1;
+ }
+ } else {
+ memset(ctx->qmat_chroma, 4, 64);
+ ctx->qmat_changed = 1;
+ }
+
+ return hdr_size;
+}
+
+
+static int decode_picture_header(ProresContext *ctx, const uint8_t *buf,
+ const int data_size, AVCodecContext *avctx)
+{
+ int i, hdr_size, pic_data_size, num_slices;
+ int slice_width_factor, slice_height_factor;
+ int remainder, num_x_slices;
+ const uint8_t *data_ptr, *index_ptr;
+
+ hdr_size = data_size > 0 ? buf[0] >> 3 : 0;
+ if (hdr_size < 8 || hdr_size > data_size) {
+ av_log(avctx, AV_LOG_ERROR, "picture header too small\n");
+ return AVERROR_INVALIDDATA;
+ }
+
+ pic_data_size = AV_RB32(buf + 1);
+ if (pic_data_size > data_size) {
+ av_log(avctx, AV_LOG_ERROR, "picture data too small\n");
+ return AVERROR_INVALIDDATA;
+ }
+
+ slice_width_factor = buf[7] >> 4;
+ slice_height_factor = buf[7] & 0xF;
+ if (slice_width_factor > 3 || slice_height_factor) {
+ av_log(avctx, AV_LOG_ERROR,
+ "unsupported slice dimension: %d x %d\n",
+ 1 << slice_width_factor, 1 << slice_height_factor);
+ return AVERROR_INVALIDDATA;
+ }
+
+ ctx->slice_width_factor = slice_width_factor;
+ ctx->slice_height_factor = slice_height_factor;
+
+ ctx->num_x_mbs = (avctx->width + 15) >> 4;
+ ctx->num_y_mbs = (avctx->height +
+ (1 << (4 + ctx->picture.interlaced_frame)) - 1) >>
+ (4 + ctx->picture.interlaced_frame);
+
+ remainder = ctx->num_x_mbs & ((1 << slice_width_factor) - 1);
+ num_x_slices = (ctx->num_x_mbs >> slice_width_factor) + (remainder & 1) +
+ ((remainder >> 1) & 1) + ((remainder >> 2) & 1);
+
+ num_slices = num_x_slices * ctx->num_y_mbs;
+ if (num_slices != AV_RB16(buf + 5)) {
+ av_log(avctx, AV_LOG_ERROR, "invalid number of slices\n");
+ return AVERROR_INVALIDDATA;
+ }
+
+ if (ctx->total_slices != num_slices) {
+ av_freep(&ctx->slice_data);
+ ctx->slice_data = av_malloc((num_slices + 1) * sizeof(ctx->slice_data[0]));
+ if (!ctx->slice_data)
+ return AVERROR(ENOMEM);
+ ctx->total_slices = num_slices;
+ }
+
+ if (hdr_size + num_slices * 2 > data_size) {
+ av_log(avctx, AV_LOG_ERROR, "slice table too small\n");
+ return AVERROR_INVALIDDATA;
+ }
+
+ /* parse slice table allowing quick access to the slice data */
+ index_ptr = buf + hdr_size;
+ data_ptr = index_ptr + num_slices * 2;
+
+ for (i = 0; i < num_slices; i++) {
+ ctx->slice_data[i].index = data_ptr;
+ data_ptr += AV_RB16(index_ptr + i * 2);
+ }
+ ctx->slice_data[i].index = data_ptr;
+
+ if (data_ptr > buf + data_size) {
+ av_log(avctx, AV_LOG_ERROR, "out of slice data\n");
+ return -1;
+ }
+
+ return pic_data_size;
+}
+
+
+/**
+ * Read an unsigned rice/exp golomb codeword.
+ */
+static inline int decode_vlc_codeword(GetBitContext *gb, uint8_t codebook)
+{
+ unsigned int rice_order, exp_order, switch_bits;
+ unsigned int buf, code;
+ int log, prefix_len, len;
+
+ OPEN_READER(re, gb);
+ UPDATE_CACHE(re, gb);
+ buf = GET_CACHE(re, gb);
+
+ /* number of prefix bits to switch between Rice and expGolomb */
+ switch_bits = (codebook & 3) + 1;
+ rice_order = codebook >> 5; /* rice code order */
+ exp_order = (codebook >> 2) & 7; /* exp golomb code order */
+
+ log = 31 - av_log2(buf); /* count prefix bits (zeroes) */
+
+ if (log < switch_bits) { /* ok, we got a rice code */
+ if (!rice_order) {
+ /* shortcut for faster decoding of rice codes without remainder */
+ code = log;
+ LAST_SKIP_BITS(re, gb, log + 1);
+ } else {
+ prefix_len = log + 1;
+ code = (log << rice_order) + NEG_USR32(buf << prefix_len, rice_order);
+ LAST_SKIP_BITS(re, gb, prefix_len + rice_order);
+ }
+ } else { /* otherwise we got a exp golomb code */
+ len = (log << 1) - switch_bits + exp_order + 1;
+ code = NEG_USR32(buf, len) - (1 << exp_order) + (switch_bits << rice_order);
+ LAST_SKIP_BITS(re, gb, len);
+ }
+
+ CLOSE_READER(re, gb);
+
+ return code;
+}
+
+#define LSB2SIGN(x) (-((x) & 1))
+#define TOSIGNED(x) (((x) >> 1) ^ LSB2SIGN(x))
+
+#define FIRST_DC_CB 0xB8 // rice_order = 5, exp_golomb_order = 6, switch_bits = 0
+
+static uint8_t dc_codebook[4] = {
+ 0x04, // rice_order = 0, exp_golomb_order = 1, switch_bits = 0
+ 0x28, // rice_order = 1, exp_golomb_order = 2, switch_bits = 0
+ 0x4D, // rice_order = 2, exp_golomb_order = 3, switch_bits = 1
+ 0x70 // rice_order = 3, exp_golomb_order = 4, switch_bits = 0
+};
+
+
+/**
+ * Decode DC coefficients for all blocks in a slice.
+ */
+static inline void decode_dc_coeffs(GetBitContext *gb, DCTELEM *out,
+ int nblocks)
+{
+ DCTELEM prev_dc;
+ int i, sign;
+ int16_t delta;
+ unsigned int code;
+
+ code = decode_vlc_codeword(gb, FIRST_DC_CB);
+ out[0] = prev_dc = TOSIGNED(code);
+
+ out += 64; /* move to the DC coeff of the next block */
+ delta = 3;
+
+ for (i = 1; i < nblocks; i++, out += 64) {
+ code = decode_vlc_codeword(gb, dc_codebook[FFMIN(FFABS(delta), 3)]);
+
+ sign = -(((delta >> 15) & 1) ^ (code & 1));
+ delta = (((code + 1) >> 1) ^ sign) - sign;
+ prev_dc += delta;
+ out[0] = prev_dc;
+ }
+}
+
+
+static uint8_t ac_codebook[7] = {
+ 0x04, // rice_order = 0, exp_golomb_order = 1, switch_bits = 0
+ 0x28, // rice_order = 1, exp_golomb_order = 2, switch_bits = 0
+ 0x4C, // rice_order = 2, exp_golomb_order = 3, switch_bits = 0
+ 0x05, // rice_order = 0, exp_golomb_order = 1, switch_bits = 1
+ 0x29, // rice_order = 1, exp_golomb_order = 2, switch_bits = 1
+ 0x06, // rice_order = 0, exp_golomb_order = 1, switch_bits = 2
+ 0x0A, // rice_order = 0, exp_golomb_order = 2, switch_bits = 2
+};
+
+/**
+ * Lookup tables for adaptive switching between codebooks
+ * according with previous run/level value.
+ */
+static uint8_t run_to_cb_index[16] =
+ { 5, 5, 3, 3, 0, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 2 };
+
+static uint8_t lev_to_cb_index[10] = { 0, 6, 3, 5, 0, 1, 1, 1, 1, 2 };
+
+
+/**
+ * Decode AC coefficients for all blocks in a slice.
+ */
+static inline void decode_ac_coeffs(GetBitContext *gb, DCTELEM *out,
+ int blocks_per_slice,
+ int plane_size_factor,
+ const uint8_t *scan)
+{
+ int pos, block_mask, run, level, sign, run_cb_index, lev_cb_index;
+ int max_coeffs, bits_left;
+
+ /* set initial prediction values */
+ run = 4;
+ level = 2;
+
+ max_coeffs = blocks_per_slice << 6;
+ block_mask = blocks_per_slice - 1;
+
+ for (pos = blocks_per_slice - 1; pos < max_coeffs;) {
+ run_cb_index = run_to_cb_index[FFMIN(run, 15)];
+ lev_cb_index = lev_to_cb_index[FFMIN(level, 9)];
+
+ bits_left = get_bits_left(gb);
+ if (bits_left <= 0 || (bits_left <= 8 && !show_bits(gb, bits_left)))
+ return;
+
+ run = decode_vlc_codeword(gb, ac_codebook[run_cb_index]);
+
+ bits_left = get_bits_left(gb);
+ if (bits_left <= 0 || (bits_left <= 8 && !show_bits(gb, bits_left)))
+ return;
+
+ level = decode_vlc_codeword(gb, ac_codebook[lev_cb_index]) + 1;
+
+ pos += run + 1;
+ if (pos >= max_coeffs)
+ break;
+
+ sign = get_sbits(gb, 1);
+ out[((pos & block_mask) << 6) + scan[pos >> plane_size_factor]] =
+ (level ^ sign) - sign;
+ }
+}
+
+
+/**
+ * Decode a slice plane (luma or chroma).
+ */
+static void decode_slice_plane(ProresContext *ctx, ProresThreadData *td,
+ const uint8_t *buf,
+ int data_size, uint16_t *out_ptr,
+ int linesize, int mbs_per_slice,
+ int blocks_per_mb, int plane_size_factor,
+ const int16_t *qmat)
+{
+ GetBitContext gb;
+ DCTELEM *block_ptr;
+ int mb_num, blocks_per_slice;
+
+ blocks_per_slice = mbs_per_slice * blocks_per_mb;
+
+ memset(td->blocks, 0, 8 * 4 * 64 * sizeof(*td->blocks));
+
+ init_get_bits(&gb, buf, data_size << 3);
+
+ decode_dc_coeffs(&gb, td->blocks, blocks_per_slice);
+
+ decode_ac_coeffs(&gb, td->blocks, blocks_per_slice,
+ plane_size_factor, ctx->scantable.permutated);
+
+ /* inverse quantization, inverse transform and output */
+ block_ptr = td->blocks;
+
+ for (mb_num = 0; mb_num < mbs_per_slice; mb_num++, out_ptr += blocks_per_mb * 4) {
+ ctx->dsp.idct_put(out_ptr, linesize, block_ptr, qmat);
+ block_ptr += 64;
+ if (blocks_per_mb > 2) {
+ ctx->dsp.idct_put(out_ptr + 8, linesize, block_ptr, qmat);
+ block_ptr += 64;
+ }
+ ctx->dsp.idct_put(out_ptr + linesize * 4, linesize, block_ptr, qmat);
+ block_ptr += 64;
+ if (blocks_per_mb > 2) {
+ ctx->dsp.idct_put(out_ptr + linesize * 4 + 8, linesize, block_ptr, qmat);
+ block_ptr += 64;
+ }
+ }
+}
+
+
+static int decode_slice(AVCodecContext *avctx, ProresThreadData *td)
+{
+ ProresContext *ctx = avctx->priv_data;
+ int mb_x_pos = td->x_pos;
+ int mb_y_pos = td->y_pos;
+ int pic_num = ctx->pic_num;
+ int slice_num = td->slice_num;
+ int mbs_per_slice = td->slice_width;
+ const uint8_t *buf;
+ uint8_t *y_data, *u_data, *v_data;
+ AVFrame *pic = avctx->coded_frame;
+ int i, sf, slice_width_factor;
+ int slice_data_size, hdr_size, y_data_size, u_data_size, v_data_size;
+ int y_linesize, u_linesize, v_linesize;
+
+ buf = ctx->slice_data[slice_num].index;
+ slice_data_size = ctx->slice_data[slice_num + 1].index - buf;
+
+ slice_width_factor = av_log2(mbs_per_slice);
+
+ y_data = pic->data[0];
+ u_data = pic->data[1];
+ v_data = pic->data[2];
+ y_linesize = pic->linesize[0];
+ u_linesize = pic->linesize[1];
+ v_linesize = pic->linesize[2];
+
+ if (pic->interlaced_frame) {
+ if (!(pic_num ^ pic->top_field_first)) {
+ y_data += y_linesize;
+ u_data += u_linesize;
+ v_data += v_linesize;
+ }
+ y_linesize <<= 1;
+ u_linesize <<= 1;
+ v_linesize <<= 1;
+ }
+
+ if (slice_data_size < 6) {
+ av_log(avctx, AV_LOG_ERROR, "slice data too small\n");
+ return AVERROR_INVALIDDATA;
+ }
+
+ /* parse slice header */
+ hdr_size = buf[0] >> 3;
+ y_data_size = AV_RB16(buf + 2);
+ u_data_size = AV_RB16(buf + 4);
+ v_data_size = hdr_size > 7 ? AV_RB16(buf + 6) :
+ slice_data_size - y_data_size - u_data_size - hdr_size;
+
+ if (hdr_size + y_data_size + u_data_size + v_data_size > slice_data_size ||
+ v_data_size < 0 || hdr_size < 6) {
+ av_log(avctx, AV_LOG_ERROR, "invalid data size\n");
+ return AVERROR_INVALIDDATA;
+ }
+
+ sf = av_clip(buf[1], 1, 224);
+ sf = sf > 128 ? (sf - 96) << 2 : sf;
+
+ /* scale quantization matrixes according with slice's scale factor */
+ /* TODO: this can be SIMD-optimized alot */
+ if (ctx->qmat_changed || sf != ctx->prev_slice_sf) {
+ ctx->prev_slice_sf = sf;
+ for (i = 0; i < 64; i++) {
+ ctx->qmat_luma_scaled[ctx->dsp.idct_permutation[i]] = ctx->qmat_luma[i] * sf;
+ ctx->qmat_chroma_scaled[ctx->dsp.idct_permutation[i]] = ctx->qmat_chroma[i] * sf;
+ }
+ }
+
+ /* decode luma plane */
+ decode_slice_plane(ctx, td, buf + hdr_size, y_data_size,
+ (uint16_t*) (y_data + (mb_y_pos << 4) * y_linesize +
+ (mb_x_pos << 5)), y_linesize,
+ mbs_per_slice, 4, slice_width_factor + 2,
+ ctx->qmat_luma_scaled);
+
+ /* decode U chroma plane */
+ decode_slice_plane(ctx, td, buf + hdr_size + y_data_size, u_data_size,
+ (uint16_t*) (u_data + (mb_y_pos << 4) * u_linesize +
+ (mb_x_pos << ctx->mb_chroma_factor)),
+ u_linesize, mbs_per_slice, ctx->num_chroma_blocks,
+ slice_width_factor + ctx->chroma_factor - 1,
+ ctx->qmat_chroma_scaled);
+
+ /* decode V chroma plane */
+ decode_slice_plane(ctx, td, buf + hdr_size + y_data_size + u_data_size,
+ v_data_size,
+ (uint16_t*) (v_data + (mb_y_pos << 4) * v_linesize +
+ (mb_x_pos << ctx->mb_chroma_factor)),
+ v_linesize, mbs_per_slice, ctx->num_chroma_blocks,
+ slice_width_factor + ctx->chroma_factor - 1,
+ ctx->qmat_chroma_scaled);
+
+ return 0;
+}
+
+
+static int decode_picture(ProresContext *ctx, int pic_num,
+ AVCodecContext *avctx)
+{
+ int slice_num, slice_width, x_pos, y_pos;
+
+ slice_num = 0;
+
+ ctx->pic_num = pic_num;
+ for (y_pos = 0; y_pos < ctx->num_y_mbs; y_pos++) {
+ slice_width = 1 << ctx->slice_width_factor;
+
+ for (x_pos = 0; x_pos < ctx->num_x_mbs && slice_width;
+ x_pos += slice_width) {
+ while (ctx->num_x_mbs - x_pos < slice_width)
+ slice_width >>= 1;
+
+ ctx->slice_data[slice_num].slice_num = slice_num;
+ ctx->slice_data[slice_num].x_pos = x_pos;
+ ctx->slice_data[slice_num].y_pos = y_pos;
+ ctx->slice_data[slice_num].slice_width = slice_width;
+
+ slice_num++;
+ }
+ }
+
+ return avctx->execute(avctx, (void *) decode_slice,
+ ctx->slice_data, NULL, slice_num,
+ sizeof(ctx->slice_data[0]));
+}
+
+
+#define FRAME_ID MKBETAG('i', 'c', 'p', 'f')
+#define MOVE_DATA_PTR(nbytes) buf += (nbytes); buf_size -= (nbytes)
+
+static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
+ AVPacket *avpkt)
+{
+ ProresContext *ctx = avctx->priv_data;
+ AVFrame *picture = avctx->coded_frame;
+ const uint8_t *buf = avpkt->data;
+ int buf_size = avpkt->size;
+ int frame_hdr_size, pic_num, pic_data_size;
+
+ /* check frame atom container */
+ if (buf_size < 28 || buf_size < AV_RB32(buf) ||
+ AV_RB32(buf + 4) != FRAME_ID) {
+ av_log(avctx, AV_LOG_ERROR, "invalid frame\n");
+ return AVERROR_INVALIDDATA;
+ }
+
+ MOVE_DATA_PTR(8);
+
+ frame_hdr_size = decode_frame_header(ctx, buf, buf_size, avctx);
+ if (frame_hdr_size < 0)
+ return AVERROR_INVALIDDATA;
+
+ MOVE_DATA_PTR(frame_hdr_size);
+
+ if (picture->data[0])
+ avctx->release_buffer(avctx, picture);
+
+ picture->reference = 0;
+ if (avctx->get_buffer(avctx, picture) < 0)
+ return -1;
+
+ for (pic_num = 0; ctx->picture.interlaced_frame - pic_num + 1; pic_num++) {
+ pic_data_size = decode_picture_header(ctx, buf, buf_size, avctx);
+ if (pic_data_size < 0)
+ return AVERROR_INVALIDDATA;
+
+ if (decode_picture(ctx, pic_num, avctx))
+ return -1;
+
+ MOVE_DATA_PTR(pic_data_size);
+ }
+
+ *data_size = sizeof(AVPicture);
+ *(AVFrame*) data = *avctx->coded_frame;
+
+ return avpkt->size;
+}
+
+
+static av_cold int decode_close(AVCodecContext *avctx)
+{
+ ProresContext *ctx = avctx->priv_data;
+
+ if (ctx->picture.data[0])
+ avctx->release_buffer(avctx, &ctx->picture);
+
+ av_freep(&ctx->slice_data);
+
+ return 0;
+}
+
+
+AVCodec ff_prores_lgpl_decoder = {
+ .name = "prores_lgpl",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_PRORES,
+ .priv_data_size = sizeof(ProresContext),
+ .init = decode_init,
+ .close = decode_close,
+ .decode = decode_frame,
+ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_SLICE_THREADS,
+ .long_name = NULL_IF_CONFIG_SMALL("Apple ProRes (iCodec Pro)")
+};
diff --git a/libavcodec/proresdsp.c b/libavcodec/proresdsp.c
new file mode 100644
index 0000000000..739ee2b3ec
--- /dev/null
+++ b/libavcodec/proresdsp.c
@@ -0,0 +1,63 @@
+/*
+ * Apple ProRes compatible decoder
+ *
+ * Copyright (c) 2010-2011 Maxim Poliakovski
+ *
+ * This file is part of Libav.
+ *
+ * Libav 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.
+ *
+ * Libav 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "proresdsp.h"
+#include "simple_idct.h"
+
+#define BIAS (1 << (PRORES_BITS_PER_SAMPLE - 1)) ///< bias value for converting signed pixels into unsigned ones
+#define CLIP_MIN (1 << (PRORES_BITS_PER_SAMPLE - 8)) ///< minimum value for clipping resulting pixels
+#define CLIP_MAX (1 << PRORES_BITS_PER_SAMPLE) - CLIP_MIN - 1 ///< maximum value for clipping resulting pixels
+
+#define CLIP_AND_BIAS(x) (av_clip((x) + BIAS, CLIP_MIN, CLIP_MAX))
+
+/**
+ * Add bias value, clamp and output pixels of a slice
+ */
+static void put_pixels(uint16_t *dst, int stride, const DCTELEM *in)
+{
+ int x, y, src_offset, dst_offset;
+
+ for (y = 0, dst_offset = 0; y < 8; y++, dst_offset += stride) {
+ for (x = 0; x < 8; x++) {
+ src_offset = (y << 3) + x;
+
+ dst[dst_offset + x] = CLIP_AND_BIAS(in[src_offset]);
+ }
+ }
+}
+
+static void prores_idct_put_c(uint16_t *out, int linesize, DCTELEM *block, const int16_t *qmat)
+{
+ ff_prores_idct(block, qmat);
+ put_pixels(out, linesize >> 1, block);
+}
+
+void ff_proresdsp_init(ProresDSPContext *dsp, AVCodecContext *avctx)
+{
+ dsp->idct_put = prores_idct_put_c;
+ dsp->idct_permutation_type = FF_NO_IDCT_PERM;
+
+ if (HAVE_MMX) ff_proresdsp_x86_init(dsp, avctx);
+
+ ff_init_scantable_permutation(dsp->idct_permutation,
+ dsp->idct_permutation_type);
+}
diff --git a/libavcodec/proresdsp.h b/libavcodec/proresdsp.h
new file mode 100644
index 0000000000..7e81b0870c
--- /dev/null
+++ b/libavcodec/proresdsp.h
@@ -0,0 +1,40 @@
+/*
+ * Apple ProRes compatible decoder
+ *
+ * Copyright (c) 2010-2011 Maxim Poliakovski
+ *
+ * This file is part of Libav.
+ *
+ * Libav 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.
+ *
+ * Libav 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_PRORESDSP_H
+#define AVCODEC_PRORESDSP_H
+
+#include "dsputil.h"
+
+#define PRORES_BITS_PER_SAMPLE 10 ///< output precision of prores decoder
+
+typedef struct {
+ int idct_permutation_type;
+ uint8_t idct_permutation[64];
+ void (* idct_put) (uint16_t *out, int linesize, DCTELEM *block, const int16_t *qmat);
+} ProresDSPContext;
+
+void ff_proresdsp_init(ProresDSPContext *dsp, AVCodecContext *avctx);
+
+void ff_proresdsp_x86_init(ProresDSPContext *dsp, AVCodecContext *avctx);
+
+#endif /* AVCODEC_PRORESDSP_H */
diff --git a/libavcodec/ps2/dsputil_mmi.c b/libavcodec/ps2/dsputil_mmi.c
index f4503a9030..d04a425b49 100644
--- a/libavcodec/ps2/dsputil_mmi.c
+++ b/libavcodec/ps2/dsputil_mmi.c
@@ -5,20 +5,20 @@
* MMI optimization by Leon van Stuivenberg
* clear_blocks_mmi() by BroadQ
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -142,7 +142,7 @@ static void put_pixels16_mmi(uint8_t *block, const uint8_t *pixels, int line_siz
void dsputil_init_mmi(DSPContext* c, AVCodecContext *avctx)
{
const int idct_algo= avctx->idct_algo;
- const int high_bit_depth = avctx->codec_id == CODEC_ID_H264 && avctx->bits_per_raw_sample > 8;
+ const int high_bit_depth = avctx->bits_per_raw_sample > 8;
if (!high_bit_depth) {
c->clear_blocks = clear_blocks_mmi;
@@ -152,11 +152,12 @@ void dsputil_init_mmi(DSPContext* c, AVCodecContext *avctx)
c->put_pixels_tab[0][0] = put_pixels16_mmi;
c->put_no_rnd_pixels_tab[0][0] = put_pixels16_mmi;
- }
c->get_pixels = get_pixels_mmi;
+ }
- if(idct_algo==FF_IDCT_AUTO || idct_algo==FF_IDCT_PS2){
+ if (avctx->bits_per_raw_sample <= 8 &&
+ (idct_algo==FF_IDCT_AUTO || idct_algo==FF_IDCT_PS2)) {
c->idct_put= ff_mmi_idct_put;
c->idct_add= ff_mmi_idct_add;
c->idct = ff_mmi_idct;
diff --git a/libavcodec/ps2/idct_mmi.c b/libavcodec/ps2/idct_mmi.c
index 86df092075..bfe362a91d 100644
--- a/libavcodec/ps2/idct_mmi.c
+++ b/libavcodec/ps2/idct_mmi.c
@@ -8,20 +8,20 @@
*
* MMI port and (c) 2002 by Leon van Stuivenberg
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/ps2/mmi.h b/libavcodec/ps2/mmi.h
index fc8d32819a..0265456108 100644
--- a/libavcodec/ps2/mmi.h
+++ b/libavcodec/ps2/mmi.h
@@ -1,20 +1,20 @@
/*
* copyright (c) 2002 Leon van Stuivenberg
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/ps2/mpegvideo_mmi.c b/libavcodec/ps2/mpegvideo_mmi.c
index ed56893877..68c3b0d0e7 100644
--- a/libavcodec/ps2/mpegvideo_mmi.c
+++ b/libavcodec/ps2/mpegvideo_mmi.c
@@ -3,20 +3,20 @@
*
* MMI optimization by Leon van Stuivenberg
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/psymodel.c b/libavcodec/psymodel.c
index 740d859456..faadb1b870 100644
--- a/libavcodec/psymodel.c
+++ b/libavcodec/psymodel.c
@@ -2,20 +2,20 @@
* audio encoder psychoacoustic model
* Copyright (C) 2008 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/psymodel.h b/libavcodec/psymodel.h
index 3e866e40cc..a7b7948cd2 100644
--- a/libavcodec/psymodel.h
+++ b/libavcodec/psymodel.h
@@ -2,20 +2,20 @@
* audio encoder psychoacoustic model
* Copyright (C) 2008 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/pthread.c b/libavcodec/pthread.c
index 08ef4ba0c2..b6ebea4407 100644
--- a/libavcodec/pthread.c
+++ b/libavcodec/pthread.c
@@ -6,20 +6,20 @@
* to Michael Niedermayer <michaelni@gmx.at> for writing initial
* implementation.
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -29,11 +29,17 @@
* @see doc/multithreading.txt
*/
-#include <pthread.h>
-
+#include "config.h"
#include "avcodec.h"
+#include "internal.h"
#include "thread.h"
+#if HAVE_PTHREADS
+#include <pthread.h>
+#elif HAVE_W32THREADS
+#include "w32pthreads.h"
+#endif
+
typedef int (action_func)(AVCodecContext *c, void *arg);
typedef int (action_func2)(AVCodecContext *c, void *arg, int jobnr, int threadnr);
@@ -332,6 +338,9 @@ static int update_context_from_thread(AVCodecContext *dst, AVCodecContext *src,
dst->height = src->height;
dst->pix_fmt = src->pix_fmt;
+ dst->coded_width = src->coded_width;
+ dst->coded_height = src->coded_height;
+
dst->has_b_frames = src->has_b_frames;
dst->idct_algo = src->idct_algo;
dst->slice_count = src->slice_count;
@@ -408,9 +417,10 @@ static void release_delayed_buffers(PerThreadContext *p)
FrameThreadContext *fctx = p->parent;
while (p->num_released_buffers > 0) {
- AVFrame *f = &p->released_buffers[--p->num_released_buffers];
+ AVFrame *f;
pthread_mutex_lock(&fctx->buffer_mutex);
+ f = &p->released_buffers[--p->num_released_buffers];
free_progress(f);
f->thread_opaque = NULL;
@@ -598,6 +608,10 @@ void ff_thread_finish_setup(AVCodecContext *avctx) {
if (!(avctx->active_thread_type&FF_THREAD_FRAME)) return;
+ if(p->state == STATE_SETUP_FINISHED){
+ av_log(avctx, AV_LOG_WARNING, "Multiple ff_thread_finish_setup() calls\n");
+ }
+
pthread_mutex_lock(&p->progress_mutex);
p->state = STATE_SETUP_FINISHED;
pthread_cond_broadcast(&p->progress_cond);
@@ -629,7 +643,7 @@ static void frame_thread_free(AVCodecContext *avctx, int thread_count)
park_frame_worker_threads(fctx, thread_count);
- if (fctx->prev_thread)
+ if (fctx->prev_thread && fctx->prev_thread != fctx->threads)
update_context_from_thread(fctx->threads->avctx, fctx->prev_thread->avctx, 0);
fctx->die = 1;
@@ -746,9 +760,12 @@ void ff_thread_flush(AVCodecContext *avctx)
if (!avctx->thread_opaque) return;
park_frame_worker_threads(fctx, avctx->thread_count);
-
- if (fctx->prev_thread)
- update_context_from_thread(fctx->threads->avctx, fctx->prev_thread->avctx, 0);
+ if (fctx->prev_thread) {
+ if (fctx->prev_thread != &fctx->threads[0])
+ update_context_from_thread(fctx->threads[0].avctx, fctx->prev_thread->avctx, 0);
+ if (avctx->codec->flush)
+ avctx->codec->flush(fctx->threads[0].avctx);
+ }
fctx->next_decoding = fctx->next_finished = 0;
fctx->delaying = 1;
@@ -779,6 +796,8 @@ int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f)
f->owner = avctx;
+ ff_init_buffer_info(avctx, f);
+
if (!(avctx->active_thread_type&FF_THREAD_FRAME)) {
f->thread_opaque = NULL;
return avctx->get_buffer(avctx, f);
@@ -836,6 +855,7 @@ int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f)
void ff_thread_release_buffer(AVCodecContext *avctx, AVFrame *f)
{
PerThreadContext *p = avctx->thread_opaque;
+ FrameThreadContext *fctx;
if (!(avctx->active_thread_type&FF_THREAD_FRAME)) {
avctx->release_buffer(avctx, f);
@@ -851,7 +871,10 @@ void ff_thread_release_buffer(AVCodecContext *avctx, AVFrame *f)
av_log(avctx, AV_LOG_DEBUG, "thread_release_buffer called on pic %p, %d buffers used\n",
f, f->owner->internal_buffer_count);
+ fctx = p->parent;
+ pthread_mutex_lock(&fctx->buffer_mutex);
p->released_buffers[p->num_released_buffers++] = *f;
+ pthread_mutex_unlock(&fctx->buffer_mutex);
memset(f->data, 0, sizeof(f->data));
}
@@ -887,6 +910,10 @@ int ff_thread_init(AVCodecContext *avctx)
return -1;
}
+#if HAVE_W32THREADS
+ w32thread_init();
+#endif
+
if (avctx->codec) {
validate_thread_parameters(avctx);
diff --git a/libavcodec/ptx.c b/libavcodec/ptx.c
index c993f6c0f0..fb457f234a 100644
--- a/libavcodec/ptx.c
+++ b/libavcodec/ptx.c
@@ -2,20 +2,20 @@
* V.Flash PTX (.ptx) image decoder
* Copyright (c) 2007 Ivo van Poorten
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -39,12 +39,15 @@ static av_cold int ptx_init(AVCodecContext *avctx) {
static int ptx_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
AVPacket *avpkt) {
const uint8_t *buf = avpkt->data;
+ const uint8_t *buf_end = avpkt->data + avpkt->size;
PTXContext * const s = avctx->priv_data;
AVFrame *picture = data;
AVFrame * const p = &s->picture;
unsigned int offset, w, h, y, stride, bytes_per_pixel;
uint8_t *ptr;
+ if (buf_end - buf < 14)
+ return AVERROR_INVALIDDATA;
offset = AV_RL16(buf);
w = AV_RL16(buf+8);
h = AV_RL16(buf+10);
@@ -57,6 +60,8 @@ static int ptx_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
avctx->pix_fmt = PIX_FMT_RGB555;
+ if (buf_end - buf < offset)
+ return AVERROR_INVALIDDATA;
if (offset != 0x2c)
av_log_ask_for_sample(avctx, "offset != 0x2c\n");
@@ -80,6 +85,8 @@ static int ptx_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
stride = p->linesize[0];
for (y=0; y<h; y++) {
+ if (buf_end - buf < w * bytes_per_pixel)
+ break;
#if HAVE_BIGENDIAN
unsigned int x;
for (x=0; x<w*bytes_per_pixel; x+=bytes_per_pixel)
@@ -107,15 +114,13 @@ static av_cold int ptx_end(AVCodecContext *avctx) {
}
AVCodec ff_ptx_decoder = {
- "ptx",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_PTX,
- sizeof(PTXContext),
- ptx_init,
- NULL,
- ptx_end,
- ptx_decode_frame,
- CODEC_CAP_DR1,
- NULL,
+ .name = "ptx",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_PTX,
+ .priv_data_size = sizeof(PTXContext),
+ .init = ptx_init,
+ .close = ptx_end,
+ .decode = ptx_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("V.Flash PTX image"),
};
diff --git a/libavcodec/put_bits.h b/libavcodec/put_bits.h
index c10dd818f0..9256e7fa4d 100644
--- a/libavcodec/put_bits.h
+++ b/libavcodec/put_bits.h
@@ -1,20 +1,20 @@
/*
* copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -78,7 +78,8 @@ static inline int put_bits_count(PutBitContext *s)
static inline void flush_put_bits(PutBitContext *s)
{
#ifndef BITSTREAM_WRITER_LE
- s->bit_buf<<= s->bit_left;
+ if (s->bit_left < 32)
+ s->bit_buf<<= s->bit_left;
#endif
while (s->bit_left < 32) {
/* XXX: should test end of buffer */
@@ -96,14 +97,14 @@ static inline void flush_put_bits(PutBitContext *s)
}
#ifdef BITSTREAM_WRITER_LE
-#define align_put_bits align_put_bits_unsupported_here
+#define avpriv_align_put_bits align_put_bits_unsupported_here
#define ff_put_string ff_put_string_unsupported_here
-#define ff_copy_bits ff_copy_bits_unsupported_here
+#define avpriv_copy_bits avpriv_copy_bits_unsupported_here
#else
/**
* Pad the bitstream with zeros up to the next byte boundary.
*/
-void align_put_bits(PutBitContext *s);
+void avpriv_align_put_bits(PutBitContext *s);
/**
* Put the string string in the bitstream.
@@ -117,7 +118,7 @@ void ff_put_string(PutBitContext *pb, const char *string, int terminate_string);
*
* @param length the number of bits of src to copy
*/
-void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length);
+void avpriv_copy_bits(PutBitContext *pb, const uint8_t *src, int length);
#endif
/**
diff --git a/libavcodec/qcelpdata.h b/libavcodec/qcelpdata.h
index 5822299348..e71ee9fdb7 100644
--- a/libavcodec/qcelpdata.h
+++ b/libavcodec/qcelpdata.h
@@ -2,20 +2,20 @@
* QCELP decoder
* Copyright (c) 2007 Reynaldo H. Verdejo Pinochet
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -26,7 +26,7 @@
* @file
* Data tables for the QCELP decoder
* @author Reynaldo H. Verdejo Pinochet
- * @remark Libav merging spearheaded by Kenan Gillet
+ * @remark FFmpeg merging spearheaded by Kenan Gillet
* @remark Development mentored by Benjamin Larson
*/
diff --git a/libavcodec/qcelpdec.c b/libavcodec/qcelpdec.c
index 5942a03072..76480f0d85 100644
--- a/libavcodec/qcelpdec.c
+++ b/libavcodec/qcelpdec.c
@@ -2,20 +2,20 @@
* QCELP decoder
* Copyright (c) 2007 Reynaldo H. Verdejo Pinochet
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -23,7 +23,7 @@
* @file
* QCELP decoder
* @author Reynaldo H. Verdejo Pinochet
- * @remark Libav merging spearheaded by Kenan Gillet
+ * @remark FFmpeg merging spearheaded by Kenan Gillet
* @remark Development mentored by Benjamin Larson
*/
@@ -117,18 +117,15 @@ static int decode_lspf(QCELPContext *q, float *lspf)
float tmp_lspf, smooth, erasure_coeff;
const float *predictors;
- if(q->bitrate == RATE_OCTAVE || q->bitrate == I_F_Q)
- {
+ if (q->bitrate == RATE_OCTAVE || q->bitrate == I_F_Q) {
predictors = (q->prev_bitrate != RATE_OCTAVE &&
q->prev_bitrate != I_F_Q ?
q->prev_lspf : q->predictor_lspf);
- if(q->bitrate == RATE_OCTAVE)
- {
+ if (q->bitrate == RATE_OCTAVE) {
q->octave_count++;
- for(i=0; i<10; i++)
- {
+ for (i=0; i<10; i++) {
q->predictor_lspf[i] =
lspf[i] = (q->frame.lspv[i] ? QCELP_LSP_SPREAD_FACTOR
: -QCELP_LSP_SPREAD_FACTOR)
@@ -136,8 +133,7 @@ static int decode_lspf(QCELPContext *q, float *lspf)
+ (i + 1) * ((1 - QCELP_LSP_OCTAVE_PREDICTOR)/11);
}
smooth = (q->octave_count < 10 ? .875 : 0.1);
- }else
- {
+ } else {
erasure_coeff = QCELP_LSP_OCTAVE_PREDICTOR;
assert(q->bitrate == I_F_Q);
@@ -145,8 +141,7 @@ static int decode_lspf(QCELPContext *q, float *lspf)
if(q->erasure_count > 1)
erasure_coeff *= (q->erasure_count < 4 ? 0.9 : 0.7);
- for(i=0; i<10; i++)
- {
+ for(i = 0; i < 10; i++) {
q->predictor_lspf[i] =
lspf[i] = (i + 1) * ( 1 - erasure_coeff)/11
+ erasure_coeff * predictors[i];
@@ -165,27 +160,23 @@ static int decode_lspf(QCELPContext *q, float *lspf)
// Low-pass filter the LSP frequencies.
ff_weighted_vector_sumf(lspf, lspf, q->prev_lspf, smooth, 1.0-smooth, 10);
- }else
- {
+ } else {
q->octave_count = 0;
tmp_lspf = 0.;
- for(i=0; i<5 ; i++)
- {
+ for (i = 0; i < 5; i++) {
lspf[2*i+0] = tmp_lspf += qcelp_lspvq[i][q->frame.lspv[i]][0] * 0.0001;
lspf[2*i+1] = tmp_lspf += qcelp_lspvq[i][q->frame.lspv[i]][1] * 0.0001;
}
// Check for badly received packets.
- if(q->bitrate == RATE_QUARTER)
- {
+ if (q->bitrate == RATE_QUARTER) {
if(lspf[9] <= .70 || lspf[9] >= .97)
return -1;
for(i=3; i<10; i++)
if(fabs(lspf[i] - lspf[i-2]) < .08)
return -1;
- }else
- {
+ } else {
if(lspf[9] <= .66 || lspf[9] >= .985)
return -1;
for(i=4; i<10; i++)
@@ -209,26 +200,21 @@ static void decode_gain_and_index(QCELPContext *q,
int i, subframes_count, g1[16];
float slope;
- if(q->bitrate >= RATE_QUARTER)
- {
- switch(q->bitrate)
- {
+ if (q->bitrate >= RATE_QUARTER) {
+ switch (q->bitrate) {
case RATE_FULL: subframes_count = 16; break;
case RATE_HALF: subframes_count = 4; break;
default: subframes_count = 5;
}
- for(i=0; i<subframes_count; i++)
- {
+ for(i = 0; i < subframes_count; i++) {
g1[i] = 4 * q->frame.cbgain[i];
- if(q->bitrate == RATE_FULL && !((i+1) & 3))
- {
+ if (q->bitrate == RATE_FULL && !((i+1) & 3)) {
g1[i] += av_clip((g1[i-1] + g1[i-2] + g1[i-3]) / 3 - 6, 0, 32);
}
gain[i] = qcelp_g12ga[g1[i]];
- if(q->frame.cbsign[i])
- {
+ if (q->frame.cbsign[i]) {
gain[i] = -gain[i];
q->frame.cindex[i] = (q->frame.cindex[i]-89) & 127;
}
@@ -238,8 +224,7 @@ static void decode_gain_and_index(QCELPContext *q,
q->prev_g1[1] = g1[i-1];
q->last_codebook_gain = qcelp_g12ga[g1[i-1]];
- if(q->bitrate == RATE_QUARTER)
- {
+ if (q->bitrate == RATE_QUARTER) {
// Provide smoothing of the unvoiced excitation energy.
gain[7] = gain[4];
gain[6] = 0.4*gain[3] + 0.6*gain[4];
@@ -249,20 +234,16 @@ static void decode_gain_and_index(QCELPContext *q,
gain[2] = gain[1];
gain[1] = 0.6*gain[0] + 0.4*gain[1];
}
- }else if (q->bitrate != SILENCE)
- {
- if(q->bitrate == RATE_OCTAVE)
- {
+ } else if (q->bitrate != SILENCE) {
+ if (q->bitrate == RATE_OCTAVE) {
g1[0] = 2 * q->frame.cbgain[0]
+ av_clip((q->prev_g1[0] + q->prev_g1[1]) / 2 - 5, 0, 54);
subframes_count = 8;
- }else
- {
+ } else {
assert(q->bitrate == I_F_Q);
g1[0] = q->prev_g1[1];
- switch(q->erasure_count)
- {
+ switch (q->erasure_count) {
case 1 : break;
case 2 : g1[0] -= 1; break;
case 3 : g1[0] -= 2; break;
@@ -296,8 +277,7 @@ static int codebook_sanity_check_for_rate_quarter(const uint8_t *cbgain)
{
int i, diff, prev_diff=0;
- for(i=1; i<5; i++)
- {
+ for(i=1; i<5; i++) {
diff = cbgain[i] - cbgain[i-1];
if(FFABS(diff) > 10)
return -1;
@@ -336,11 +316,9 @@ static void compute_svector(QCELPContext *q, const float *gain,
uint16_t cbseed, cindex;
float *rnd, tmp_gain, fir_filter_value;
- switch(q->bitrate)
- {
+ switch (q->bitrate) {
case RATE_FULL:
- for(i=0; i<16; i++)
- {
+ for (i = 0; i < 16; i++) {
tmp_gain = gain[i] * QCELP_RATE_FULL_CODEBOOK_RATIO;
cindex = -q->frame.cindex[i];
for(j=0; j<10; j++)
@@ -348,8 +326,7 @@ static void compute_svector(QCELPContext *q, const float *gain,
}
break;
case RATE_HALF:
- for(i=0; i<4; i++)
- {
+ for (i = 0; i < 4; i++) {
tmp_gain = gain[i] * QCELP_RATE_HALF_CODEBOOK_RATIO;
cindex = -q->frame.cindex[i];
for (j = 0; j < 40; j++)
@@ -363,11 +340,9 @@ static void compute_svector(QCELPContext *q, const float *gain,
(0x0007 & q->frame.lspv[1])<< 3 |
(0x0038 & q->frame.lspv[0])>> 3 ;
rnd = q->rnd_fir_filter_mem + 20;
- for(i=0; i<8; i++)
- {
+ for (i = 0; i < 8; i++) {
tmp_gain = gain[i] * (QCELP_SQRT1887 / 32768.0);
- for(k=0; k<20; k++)
- {
+ for (k = 0; k < 20; k++) {
cbseed = 521 * cbseed + 259;
*rnd = (int16_t)cbseed;
@@ -386,11 +361,9 @@ static void compute_svector(QCELPContext *q, const float *gain,
break;
case RATE_OCTAVE:
cbseed = q->first16bits;
- for(i=0; i<8; i++)
- {
+ for (i = 0; i < 8; i++) {
tmp_gain = gain[i] * (QCELP_SQRT1887 / 32768.0);
- for(j=0; j<20; j++)
- {
+ for (j = 0; j < 20; j++) {
cbseed = 521 * cbseed + 259;
*cdn_vector++ = tmp_gain * (int16_t)cbseed;
}
@@ -398,8 +371,7 @@ static void compute_svector(QCELPContext *q, const float *gain,
break;
case I_F_Q:
cbseed = -44; // random codebook index
- for(i=0; i<4; i++)
- {
+ for (i = 0; i < 4; i++) {
tmp_gain = gain[i] * QCELP_RATE_FULL_CODEBOOK_RATIO;
for(j=0; j<40; j++)
*cdn_vector++ = tmp_gain * qcelp_rate_full_codebook[cbseed++ & 127];
@@ -459,15 +431,11 @@ static const float *do_pitchfilter(float memory[303], const float v_in[160],
v_out = memory + 143; // Output vector starts at memory[143].
- for(i=0; i<4; i++)
- {
- if(gain[i])
- {
+ for (i = 0; i < 4; i++) {
+ if (gain[i]) {
v_lag = memory + 143 + 40 * i - lag[i];
- for(v_len=v_in+40; v_in<v_len; v_in++)
- {
- if(pfrac[i]) // If it is a fractional lag...
- {
+ for (v_len = v_in + 40; v_in < v_len; v_in++) {
+ if (pfrac[i]) { // If it is a fractional lag...
for(j=0, *v_out=0.; j<4; j++)
*v_out += qcelp_hammsinc_table[j] * (v_lag[j-4] + v_lag[3-j]);
}else
@@ -478,8 +446,7 @@ static const float *do_pitchfilter(float memory[303], const float v_in[160],
v_lag++;
v_out++;
}
- }else
- {
+ } else {
memcpy(v_out, v_in, 40 * sizeof(float));
v_in += 40;
v_out += 40;
@@ -504,31 +471,25 @@ static void apply_pitch_filters(QCELPContext *q, float *cdn_vector)
if(q->bitrate >= RATE_HALF ||
q->bitrate == SILENCE ||
- (q->bitrate == I_F_Q && (q->prev_bitrate >= RATE_HALF)))
- {
+ (q->bitrate == I_F_Q && (q->prev_bitrate >= RATE_HALF))) {
- if(q->bitrate >= RATE_HALF)
- {
+ if(q->bitrate >= RATE_HALF) {
// Compute gain & lag for the whole frame.
- for(i=0; i<4; i++)
- {
+ for (i = 0; i < 4; i++) {
q->pitch_gain[i] = q->frame.plag[i] ? (q->frame.pgain[i] + 1) * 0.25 : 0.0;
q->pitch_lag[i] = q->frame.plag[i] + 16;
}
- }else
- {
+ } else {
float max_pitch_gain;
- if (q->bitrate == I_F_Q)
- {
+ if (q->bitrate == I_F_Q) {
if (q->erasure_count < 3)
max_pitch_gain = 0.9 - 0.3 * (q->erasure_count - 1);
else
max_pitch_gain = 0.0;
- }else
- {
+ } else {
assert(q->bitrate == SILENCE);
max_pitch_gain = 1.0;
}
@@ -553,8 +514,7 @@ static void apply_pitch_filters(QCELPContext *q, float *cdn_vector)
q->frame.pfrac);
apply_gain_ctrl(cdn_vector, v_synthesis_filtered, v_pre_filtered);
- }else
- {
+ } else {
memcpy(q->pitch_synthesis_filter_mem, cdn_vector + 17,
143 * sizeof(float));
memcpy(q->pitch_pre_filter_mem, cdn_vector + 17, 143 * sizeof(float));
@@ -586,8 +546,7 @@ static void lspf2lpc(const float *lspf, float *lpc)
ff_acelp_lspd2lpc(lsp, lpc, 5);
- for (i=0; i<10; i++)
- {
+ for (i = 0; i < 10; i++) {
lpc[i] *= bandwidth_expansion_coeff;
bandwidth_expansion_coeff *= QCELP_BANDWIDTH_EXPANSION_COEFF;
}
@@ -617,8 +576,7 @@ static void interpolate_lpc(QCELPContext *q, const float *curr_lspf,
else
weight = 1.0;
- if(weight != 1.0)
- {
+ if (weight != 1.0) {
ff_weighted_vector_sumf(interpolated_lspf, curr_lspf, q->prev_lspf,
weight, 1.0 - weight, 10);
lspf2lpc(interpolated_lspf, lpc);
@@ -631,8 +589,7 @@ static void interpolate_lpc(QCELPContext *q, const float *curr_lspf,
static qcelp_packet_rate buf_size2bitrate(const int buf_size)
{
- switch(buf_size)
- {
+ switch (buf_size) {
case 35: return RATE_FULL;
case 17: return RATE_HALF;
case 8: return RATE_QUARTER;
@@ -660,34 +617,28 @@ static qcelp_packet_rate determine_bitrate(AVCodecContext *avctx, const int buf_
{
qcelp_packet_rate bitrate;
- if((bitrate = buf_size2bitrate(buf_size)) >= 0)
- {
- if(bitrate > **buf)
- {
+ if ((bitrate = buf_size2bitrate(buf_size)) >= 0) {
+ if (bitrate > **buf) {
QCELPContext *q = avctx->priv_data;
- if (!q->warned_buf_mismatch_bitrate)
- {
+ if (!q->warned_buf_mismatch_bitrate) {
av_log(avctx, AV_LOG_WARNING,
"Claimed bitrate and buffer size mismatch.\n");
q->warned_buf_mismatch_bitrate = 1;
}
bitrate = **buf;
- }else if(bitrate < **buf)
- {
+ } else if (bitrate < **buf) {
av_log(avctx, AV_LOG_ERROR,
"Buffer is too small for the claimed bitrate.\n");
return I_F_Q;
}
(*buf)++;
- }else if((bitrate = buf_size2bitrate(buf_size + 1)) >= 0)
- {
+ } else if ((bitrate = buf_size2bitrate(buf_size + 1)) >= 0) {
av_log(avctx, AV_LOG_WARNING,
"Bitrate byte is missing, guessing the bitrate from packet size.\n");
}else
return I_F_Q;
- if(bitrate == SILENCE)
- {
+ if (bitrate == SILENCE) {
//FIXME: Remove experimental warning when tested with samples.
av_log_ask_for_sample(avctx, "'Blank frame handling is experimental.");
}
@@ -738,26 +689,29 @@ static int qcelp_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
int buf_size = avpkt->size;
QCELPContext *q = avctx->priv_data;
float *outbuffer = data;
- int i;
+ int i, out_size;
float quantized_lspf[10], lpc[10];
float gain[16];
float *formant_mem;
- if((q->bitrate = determine_bitrate(avctx, buf_size, &buf)) == I_F_Q)
- {
+ out_size = 160 * av_get_bytes_per_sample(avctx->sample_fmt);
+ if (*data_size < out_size) {
+ av_log(avctx, AV_LOG_ERROR, "Output buffer is too small\n");
+ return AVERROR(EINVAL);
+ }
+
+ if ((q->bitrate = determine_bitrate(avctx, buf_size, &buf)) == I_F_Q) {
warn_insufficient_frame_quality(avctx, "bitrate cannot be determined.");
goto erasure;
}
if(q->bitrate == RATE_OCTAVE &&
- (q->first16bits = AV_RB16(buf)) == 0xFFFF)
- {
+ (q->first16bits = AV_RB16(buf)) == 0xFFFF) {
warn_insufficient_frame_quality(avctx, "Bitrate is 1/8 and first 16 bits are on.");
goto erasure;
}
- if(q->bitrate > SILENCE)
- {
+ if (q->bitrate > SILENCE) {
const QCELPBitmap *bitmaps = qcelp_unpacking_bitmaps_per_rate[q->bitrate];
const QCELPBitmap *bitmaps_end = qcelp_unpacking_bitmaps_per_rate[q->bitrate]
+ qcelp_unpacking_bitmaps_lengths[q->bitrate];
@@ -771,24 +725,19 @@ static int qcelp_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
unpacked_data[bitmaps->index] |= get_bits(&q->gb, bitmaps->bitlen) << bitmaps->bitpos;
// Check for erasures/blanks on rates 1, 1/4 and 1/8.
- if(q->frame.reserved)
- {
+ if (q->frame.reserved) {
warn_insufficient_frame_quality(avctx, "Wrong data in reserved frame area.");
goto erasure;
}
if(q->bitrate == RATE_QUARTER &&
- codebook_sanity_check_for_rate_quarter(q->frame.cbgain))
- {
+ codebook_sanity_check_for_rate_quarter(q->frame.cbgain)) {
warn_insufficient_frame_quality(avctx, "Codebook gain sanity check failed.");
goto erasure;
}
- if(q->bitrate >= RATE_HALF)
- {
- for(i=0; i<4; i++)
- {
- if(q->frame.pfrac[i] && q->frame.plag[i] >= 124)
- {
+ if (q->bitrate >= RATE_HALF) {
+ for (i = 0; i < 4; i++) {
+ if (q->frame.pfrac[i] && q->frame.plag[i] >= 124) {
warn_insufficient_frame_quality(avctx, "Cannot initialize pitch filter.");
goto erasure;
}
@@ -799,8 +748,7 @@ static int qcelp_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
decode_gain_and_index(q, gain);
compute_svector(q, gain, outbuffer);
- if(decode_lspf(q, quantized_lspf) < 0)
- {
+ if (decode_lspf(q, quantized_lspf) < 0) {
warn_insufficient_frame_quality(avctx, "Badly received packets in frame.");
goto erasure;
}
@@ -808,8 +756,7 @@ static int qcelp_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
apply_pitch_filters(q, outbuffer);
- if(q->bitrate == I_F_Q)
- {
+ if (q->bitrate == I_F_Q) {
erasure:
q->bitrate = I_F_Q;
q->erasure_count++;
@@ -821,8 +768,7 @@ erasure:
q->erasure_count = 0;
formant_mem = q->formant_mem + 10;
- for(i=0; i<4; i++)
- {
+ for (i = 0; i < 4; i++) {
interpolate_lpc(q, quantized_lspf, lpc, i);
ff_celp_lp_synthesis_filterf(formant_mem, lpc, outbuffer + i * 40, 40,
10);
@@ -837,9 +783,9 @@ erasure:
memcpy(q->prev_lspf, quantized_lspf, sizeof(q->prev_lspf));
q->prev_bitrate = q->bitrate;
- *data_size = 160 * sizeof(*outbuffer);
+ *data_size = out_size;
- return *data_size;
+ return buf_size;
}
AVCodec ff_qcelp_decoder =
diff --git a/libavcodec/qdm2.c b/libavcodec/qdm2.c
index 86847adc10..fe785af3db 100644
--- a/libavcodec/qdm2.c
+++ b/libavcodec/qdm2.c
@@ -5,20 +5,20 @@
* Copyright (c) 2005 Alex Beregszaszi
* Copyright (c) 2005 Roberto Togni
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -26,6 +26,7 @@
* @file
* QDM2 decoder
* @author Ewald Snel, Benjamin Larsson, Alex Beregszaszi, Roberto Togni
+ *
* The decoder is not perfect yet, there are still some distortions
* especially on files encoded with 16 or 8 subbands.
*/
@@ -76,6 +77,7 @@ do { \
#define SAMPLES_NEEDED_2(why) \
av_log (NULL,AV_LOG_INFO,"This file triggers some missing code. Please contact the developers.\nPosition: %s\n",why);
+#define QDM2_MAX_FRAME_SIZE 512
typedef int8_t sb_int8_array[2][30][64];
@@ -168,7 +170,7 @@ typedef struct {
/// I/O data
const uint8_t *compressed_data;
int compressed_size;
- float output_buffer[1024];
+ float output_buffer[QDM2_MAX_FRAME_SIZE * 2];
/// Synthesis filter
MPADSPContext mpadsp;
@@ -1353,6 +1355,8 @@ static void qdm2_fft_decode_tones (QDM2Context *q, int duration, GetBitContext *
return;
local_int_14 = (offset >> local_int_8);
+ if (local_int_14 >= FF_ARRAY_ELEMS(fft_level_index_table))
+ return;
if (q->nb_channels > 1) {
channel = get_bits1(gb);
@@ -1797,6 +1801,8 @@ static av_cold int qdm2_decode_init(AVCodecContext *avctx)
avctx->channels = s->nb_channels = s->channels = AV_RB32(extradata);
extradata += 4;
+ if (s->channels > MPA_MAX_CHANNELS)
+ return AVERROR_INVALIDDATA;
avctx->sample_rate = AV_RB32(extradata);
extradata += 4;
@@ -1819,6 +1825,9 @@ static av_cold int qdm2_decode_init(AVCodecContext *avctx)
s->group_order = av_log2(s->group_size) + 1;
s->frame_size = s->group_size / 16; // 16 iterations per super block
+ if (s->frame_size > QDM2_MAX_FRAME_SIZE)
+ return AVERROR_INVALIDDATA;
+
s->sub_sampling = s->fft_order - 7;
s->frequency_range = 255 / (1 << (2 - s->sub_sampling));
@@ -1952,13 +1961,20 @@ static int qdm2_decode_frame(AVCodecContext *avctx,
int buf_size = avpkt->size;
QDM2Context *s = avctx->priv_data;
int16_t *out = data;
- int i;
+ int i, out_size;
if(!buf)
return 0;
if(buf_size < s->checksum_size)
return -1;
+ out_size = 16 * s->channels * s->frame_size *
+ av_get_bytes_per_sample(avctx->sample_fmt);
+ if (*data_size < out_size) {
+ av_log(avctx, AV_LOG_ERROR, "Output buffer is too small\n");
+ return AVERROR(EINVAL);
+ }
+
av_log(avctx, AV_LOG_DEBUG, "decode(%d): %p[%d] -> %p[%d]\n",
buf_size, buf, s->checksum_size, data, *data_size);
@@ -1968,7 +1984,7 @@ static int qdm2_decode_frame(AVCodecContext *avctx,
out += s->channels * s->frame_size;
}
- *data_size = (uint8_t*)out - (uint8_t*)data;
+ *data_size = out_size;
return s->checksum_size;
}
diff --git a/libavcodec/qdm2_tablegen.c b/libavcodec/qdm2_tablegen.c
index 59d82df851..a7a9fb6643 100644
--- a/libavcodec/qdm2_tablegen.c
+++ b/libavcodec/qdm2_tablegen.c
@@ -3,20 +3,20 @@
*
* Copyright (c) 2010 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/qdm2_tablegen.h b/libavcodec/qdm2_tablegen.h
index b2bb294f58..585edfdd65 100644
--- a/libavcodec/qdm2_tablegen.h
+++ b/libavcodec/qdm2_tablegen.h
@@ -3,20 +3,20 @@
*
* Copyright (c) 2010 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -90,7 +90,7 @@ static av_cold void rnd_table_init(void) {
static av_cold void init_noise_samples(void) {
int i;
- int random_seed = 0;
+ unsigned random_seed = 0;
float delta = 1.0 / 16384.0;
for (i = 0; i < 128;i++) {
random_seed = random_seed * 214013 + 2531011;
diff --git a/libavcodec/qdm2data.h b/libavcodec/qdm2data.h
index ad6ea88ff6..355d61387b 100644
--- a/libavcodec/qdm2data.h
+++ b/libavcodec/qdm2data.h
@@ -5,20 +5,20 @@
* Copyright (c) 2005 Alex Beregszaszi
* Copyright (c) 2005 Roberto Togni
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/qdrw.c b/libavcodec/qdrw.c
index 07ac9aa69d..bbc0be029d 100644
--- a/libavcodec/qdrw.c
+++ b/libavcodec/qdrw.c
@@ -2,20 +2,20 @@
* QuickDraw (qdrw) codec
* Copyright (c) 2004 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -37,6 +37,7 @@ static int decode_frame(AVCodecContext *avctx,
AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
+ const uint8_t *buf_end = avpkt->data + avpkt->size;
int buf_size = avpkt->size;
QdrawContext * const a = avctx->priv_data;
AVFrame * const p= (AVFrame*)&a->pic;
@@ -59,6 +60,8 @@ static int decode_frame(AVCodecContext *avctx,
outdata = a->pic.data[0];
+ if (buf_end - buf < 0x68 + 4)
+ return AVERROR_INVALIDDATA;
buf += 0x68; /* jump to palette */
colors = AV_RB32(buf);
buf += 4;
@@ -67,6 +70,8 @@ static int decode_frame(AVCodecContext *avctx,
av_log(avctx, AV_LOG_ERROR, "Error color count - %i(0x%X)\n", colors, colors);
return -1;
}
+ if (buf_end - buf < (colors + 1) * 8)
+ return AVERROR_INVALIDDATA;
pal = (uint32_t*)p->data[1];
for (i = 0; i <= colors; i++) {
@@ -89,6 +94,8 @@ static int decode_frame(AVCodecContext *avctx,
}
p->palette_has_changed = 1;
+ if (buf_end - buf < 18)
+ return AVERROR_INVALIDDATA;
buf += 18; /* skip unneeded data */
for (i = 0; i < avctx->height; i++) {
int size, left, code, pix;
@@ -100,6 +107,9 @@ static int decode_frame(AVCodecContext *avctx,
out = outdata;
size = AV_RB16(buf); /* size of packed line */
buf += 2;
+ if (buf_end - buf < size)
+ return AVERROR_INVALIDDATA;
+
left = size;
next = buf + size;
while (left > 0) {
@@ -115,6 +125,8 @@ static int decode_frame(AVCodecContext *avctx,
} else { /* copy */
if ((out + code) > (outdata + a->pic.linesize[0]))
break;
+ if (buf_end - buf < code + 1)
+ return AVERROR_INVALIDDATA;
memcpy(out, buf, code + 1);
out += code + 1;
buf += code + 1;
@@ -133,8 +145,9 @@ static int decode_frame(AVCodecContext *avctx,
}
static av_cold int decode_init(AVCodecContext *avctx){
-// QdrawContext * const a = avctx->priv_data;
+ QdrawContext * const a = avctx->priv_data;
+ avcodec_get_frame_defaults(&a->pic);
avctx->pix_fmt= PIX_FMT_PAL8;
return 0;
@@ -151,14 +164,13 @@ static av_cold int decode_end(AVCodecContext *avctx){
}
AVCodec ff_qdraw_decoder = {
- "qdraw",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_QDRAW,
- sizeof(QdrawContext),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- CODEC_CAP_DR1,
+ .name = "qdraw",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_QDRAW,
+ .priv_data_size = sizeof(QdrawContext),
+ .init = decode_init,
+ .close = decode_end,
+ .decode = decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Apple QuickDraw"),
};
diff --git a/libavcodec/qpeg.c b/libavcodec/qpeg.c
index 5dd2a2d5ca..84e2b41629 100644
--- a/libavcodec/qpeg.c
+++ b/libavcodec/qpeg.c
@@ -2,20 +2,20 @@
* QPEG codec
* Copyright (c) 2004 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -28,8 +28,7 @@
typedef struct QpegContext{
AVCodecContext *avctx;
- AVFrame pic;
- uint8_t *refdata;
+ AVFrame pic, ref;
uint32_t pal[256];
} QpegContext;
@@ -124,9 +123,12 @@ static void qpeg_decode_inter(const uint8_t *src, uint8_t *dst, int size,
int filled = 0;
int orig_height;
+ if(!refdata)
+ refdata= dst;
+
/* copy prev frame */
for(i = 0; i < height; i++)
- memcpy(refdata + (i * width), dst + (i * stride), width);
+ memcpy(dst + (i * stride), refdata + (i * stride), width);
orig_height = height;
height--;
@@ -172,10 +174,10 @@ static void qpeg_decode_inter(const uint8_t *src, uint8_t *dst, int size,
me_x, me_y, me_w, me_h, filled, height);
else {
/* do motion compensation */
- me_plane = refdata + (filled + me_x) + (height - me_y) * width;
+ me_plane = refdata + (filled + me_x) + (height - me_y) * stride;
for(j = 0; j < me_h; j++) {
for(i = 0; i < me_w; i++)
- dst[filled + i - (j * stride)] = me_plane[i - (j * width)];
+ dst[filled + i - (j * stride)] = me_plane[i - (j * stride)];
}
}
}
@@ -254,14 +256,19 @@ static int decode_frame(AVCodecContext *avctx,
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
QpegContext * const a = avctx->priv_data;
- AVFrame * const p= (AVFrame*)&a->pic;
+ AVFrame * p= (AVFrame*)&a->pic;
+ AVFrame * ref= (AVFrame*)&a->ref;
uint8_t* outdata;
int delta;
const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL);
- p->reference = 3;
- if (avctx->reget_buffer(avctx, p) < 0) {
- av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
+ if(ref->data[0])
+ avctx->release_buffer(avctx, ref);
+ FFSWAP(AVFrame, *ref, *p);
+
+ p->reference= 3;
+ if(avctx->get_buffer(avctx, p) < 0){
+ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return -1;
}
outdata = a->pic.data[0];
@@ -269,7 +276,7 @@ static int decode_frame(AVCodecContext *avctx,
qpeg_decode_intra(buf+0x86, outdata, buf_size - 0x86, a->pic.linesize[0], avctx->width, avctx->height);
} else {
delta = buf[0x85];
- qpeg_decode_inter(buf+0x86, outdata, buf_size - 0x86, a->pic.linesize[0], avctx->width, avctx->height, delta, buf + 4, a->refdata);
+ qpeg_decode_inter(buf+0x86, outdata, buf_size - 0x86, a->pic.linesize[0], avctx->width, avctx->height, delta, buf + 4, a->ref.data[0]);
}
/* make the palette available on the way out */
@@ -288,9 +295,10 @@ static int decode_frame(AVCodecContext *avctx,
static av_cold int decode_init(AVCodecContext *avctx){
QpegContext * const a = avctx->priv_data;
+ avcodec_get_frame_defaults(&a->pic);
+ avcodec_get_frame_defaults(&a->ref);
a->avctx = avctx;
avctx->pix_fmt= PIX_FMT_PAL8;
- a->refdata = av_malloc(avctx->width * avctx->height);
return 0;
}
@@ -298,23 +306,24 @@ static av_cold int decode_init(AVCodecContext *avctx){
static av_cold int decode_end(AVCodecContext *avctx){
QpegContext * const a = avctx->priv_data;
AVFrame * const p= (AVFrame*)&a->pic;
+ AVFrame * const ref= (AVFrame*)&a->ref;
if(p->data[0])
avctx->release_buffer(avctx, p);
+ if(ref->data[0])
+ avctx->release_buffer(avctx, ref);
- av_free(a->refdata);
return 0;
}
AVCodec ff_qpeg_decoder = {
- "qpeg",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_QPEG,
- sizeof(QpegContext),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- CODEC_CAP_DR1,
+ .name = "qpeg",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_QPEG,
+ .priv_data_size = sizeof(QpegContext),
+ .init = decode_init,
+ .close = decode_end,
+ .decode = decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Q-team QPEG"),
};
diff --git a/libavcodec/qtrle.c b/libavcodec/qtrle.c
index e14c306c6b..43aea13b54 100644
--- a/libavcodec/qtrle.c
+++ b/libavcodec/qtrle.c
@@ -2,20 +2,20 @@
* Quicktime Animation (RLE) Video Decoder
* Copyright (C) 2004 the ffmpeg project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -127,6 +127,7 @@ static inline void qtrle_decode_2n4bpp(QtrleContext *s, int stream_ptr,
while (lines_to_change--) {
CHECK_STREAM_PTR(2);
pixel_ptr = row_ptr + (num_pixels * (s->buf[stream_ptr++] - 1));
+ CHECK_PIXEL_PTR(0); /* make sure pixel_ptr is positive */
while ((rle_code = (signed char)s->buf[stream_ptr++]) != -1) {
if (rle_code == 0) {
@@ -183,6 +184,7 @@ static void qtrle_decode_8bpp(QtrleContext *s, int stream_ptr, int row_ptr, int
while (lines_to_change--) {
CHECK_STREAM_PTR(2);
pixel_ptr = row_ptr + (4 * (s->buf[stream_ptr++] - 1));
+ CHECK_PIXEL_PTR(0); /* make sure pixel_ptr is positive */
while ((rle_code = (signed char)s->buf[stream_ptr++]) != -1) {
if (rle_code == 0) {
@@ -236,6 +238,7 @@ static void qtrle_decode_16bpp(QtrleContext *s, int stream_ptr, int row_ptr, int
while (lines_to_change--) {
CHECK_STREAM_PTR(2);
pixel_ptr = row_ptr + (s->buf[stream_ptr++] - 1) * 2;
+ CHECK_PIXEL_PTR(0); /* make sure pixel_ptr is positive */
while ((rle_code = (signed char)s->buf[stream_ptr++]) != -1) {
if (rle_code == 0) {
@@ -285,6 +288,7 @@ static void qtrle_decode_24bpp(QtrleContext *s, int stream_ptr, int row_ptr, int
while (lines_to_change--) {
CHECK_STREAM_PTR(2);
pixel_ptr = row_ptr + (s->buf[stream_ptr++] - 1) * 3;
+ CHECK_PIXEL_PTR(0); /* make sure pixel_ptr is positive */
while ((rle_code = (signed char)s->buf[stream_ptr++]) != -1) {
if (rle_code == 0) {
@@ -336,6 +340,7 @@ static void qtrle_decode_32bpp(QtrleContext *s, int stream_ptr, int row_ptr, int
while (lines_to_change--) {
CHECK_STREAM_PTR(2);
pixel_ptr = row_ptr + (s->buf[stream_ptr++] - 1) * 4;
+ CHECK_PIXEL_PTR(0); /* make sure pixel_ptr is positive */
while ((rle_code = (signed char)s->buf[stream_ptr++]) != -1) {
if (rle_code == 0) {
@@ -417,6 +422,7 @@ static av_cold int qtrle_decode_init(AVCodecContext *avctx)
break;
}
+ avcodec_get_frame_defaults(&s->frame);
s->frame.data[0] = NULL;
return 0;
@@ -463,6 +469,8 @@ static int qtrle_decode_frame(AVCodecContext *avctx,
stream_ptr += 4;
height = AV_RB16(&s->buf[stream_ptr]);
stream_ptr += 4;
+ if (height > s->avctx->height - start_line)
+ goto done;
} else {
start_line = 0;
height = s->avctx->height;
@@ -542,15 +550,14 @@ static av_cold int qtrle_decode_end(AVCodecContext *avctx)
}
AVCodec ff_qtrle_decoder = {
- "qtrle",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_QTRLE,
- sizeof(QtrleContext),
- qtrle_decode_init,
- NULL,
- qtrle_decode_end,
- qtrle_decode_frame,
- CODEC_CAP_DR1,
+ .name = "qtrle",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_QTRLE,
+ .priv_data_size = sizeof(QtrleContext),
+ .init = qtrle_decode_init,
+ .close = qtrle_decode_end,
+ .decode = qtrle_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("QuickTime Animation (RLE) video"),
};
diff --git a/libavcodec/qtrleenc.c b/libavcodec/qtrleenc.c
index 3cad37fd81..0e10c76365 100644
--- a/libavcodec/qtrleenc.c
+++ b/libavcodec/qtrleenc.c
@@ -5,20 +5,20 @@
*
* This file is based on flashsvenc.c.
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -39,6 +39,7 @@ typedef struct QtrleEncContext {
int pixel_size;
AVPicture previous_frame;
unsigned int max_buf_size;
+ int logical_width;
/**
* This array will contain at ith position the value of the best RLE code
* if the line started at pixel i
@@ -67,8 +68,13 @@ static av_cold int qtrle_encode_init(AVCodecContext *avctx)
return -1;
}
s->avctx=avctx;
+ s->logical_width=avctx->width;
switch (avctx->pix_fmt) {
+ case PIX_FMT_GRAY8:
+ s->logical_width = avctx->width / 4;
+ s->pixel_size = 4;
+ break;
case PIX_FMT_RGB555BE:
s->pixel_size = 2;
break;
@@ -82,11 +88,11 @@ static av_cold int qtrle_encode_init(AVCodecContext *avctx)
av_log(avctx, AV_LOG_ERROR, "Unsupported colorspace.\n");
break;
}
- avctx->bits_per_coded_sample = s->pixel_size*8;
+ avctx->bits_per_coded_sample = avctx->pix_fmt == PIX_FMT_GRAY8 ? 40 : s->pixel_size*8;
- s->rlecode_table = av_mallocz(s->avctx->width);
- s->skip_table = av_mallocz(s->avctx->width);
- s->length_table = av_mallocz((s->avctx->width + 1)*sizeof(int));
+ s->rlecode_table = av_mallocz(s->logical_width);
+ s->skip_table = av_mallocz(s->logical_width);
+ s->length_table = av_mallocz((s->logical_width + 1)*sizeof(int));
if (!s->skip_table || !s->length_table || !s->rlecode_table) {
av_log(avctx, AV_LOG_ERROR, "Error allocating memory.\n");
return -1;
@@ -96,10 +102,10 @@ static av_cold int qtrle_encode_init(AVCodecContext *avctx)
return -1;
}
- s->max_buf_size = s->avctx->width*s->avctx->height*s->pixel_size /* image base material */
- + 15 /* header + footer */
- + s->avctx->height*2 /* skip code+rle end */
- + s->avctx->width/MAX_RLE_BULK + 1 /* rle codes */;
+ s->max_buf_size = s->logical_width*s->avctx->height*s->pixel_size /* image base material */
+ + 15 /* header + footer */
+ + s->avctx->height*2 /* skip code+rle end */
+ + s->logical_width/MAX_RLE_BULK + 1 /* rle codes */;
avctx->coded_frame = &s->frame;
return 0;
}
@@ -109,7 +115,7 @@ static av_cold int qtrle_encode_init(AVCodecContext *avctx)
*/
static void qtrle_encode_line(QtrleEncContext *s, AVFrame *p, int line, uint8_t **buf)
{
- int width=s->avctx->width;
+ int width=s->logical_width;
int i;
signed char rlecode;
@@ -224,12 +230,28 @@ static void qtrle_encode_line(QtrleEncContext *s, AVFrame *p, int line, uint8_t
}
else if (rlecode > 0) {
/* bulk copy */
- bytestream_put_buffer(buf, this_line + i*s->pixel_size, rlecode*s->pixel_size);
+ if (s->avctx->pix_fmt == PIX_FMT_GRAY8) {
+ int j;
+ // QT grayscale colorspace has 0=white and 255=black, we will
+ // ignore the palette that is included in the AVFrame because
+ // PIX_FMT_GRAY8 has defined color mapping
+ for (j = 0; j < rlecode*s->pixel_size; ++j)
+ bytestream_put_byte(buf, *(this_line + i*s->pixel_size + j) ^ 0xff);
+ } else {
+ bytestream_put_buffer(buf, this_line + i*s->pixel_size, rlecode*s->pixel_size);
+ }
i += rlecode;
}
else {
/* repeat the bits */
- bytestream_put_buffer(buf, this_line + i*s->pixel_size, s->pixel_size);
+ if (s->avctx->pix_fmt == PIX_FMT_GRAY8) {
+ int j;
+ // QT grayscale colorspace has 0=white and 255=black, ...
+ for (j = 0; j < s->pixel_size; ++j)
+ bytestream_put_byte(buf, *(this_line + i*s->pixel_size + j) ^ 0xff);
+ } else {
+ bytestream_put_buffer(buf, this_line + i*s->pixel_size, s->pixel_size);
+ }
i -= rlecode;
}
}
@@ -245,7 +267,7 @@ static int encode_frame(QtrleEncContext *s, AVFrame *p, uint8_t *buf)
uint8_t *orig_buf = buf;
if (!s->frame.key_frame) {
- unsigned line_size = s->avctx->width * s->pixel_size;
+ unsigned line_size = s->logical_width * s->pixel_size;
for (start_line = 0; start_line < s->avctx->height; start_line++)
if (memcmp(p->data[0] + start_line*p->linesize[0],
s->previous_frame.data[0] + start_line*s->previous_frame.linesize[0],
@@ -322,13 +344,13 @@ static av_cold int qtrle_encode_end(AVCodecContext *avctx)
}
AVCodec ff_qtrle_encoder = {
- "qtrle",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_QTRLE,
- sizeof(QtrleEncContext),
- qtrle_encode_init,
- qtrle_encode_frame,
- qtrle_encode_end,
- .pix_fmts = (const enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGB555BE, PIX_FMT_ARGB, PIX_FMT_NONE},
+ .name = "qtrle",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_QTRLE,
+ .priv_data_size = sizeof(QtrleEncContext),
+ .init = qtrle_encode_init,
+ .encode = qtrle_encode_frame,
+ .close = qtrle_encode_end,
+ .pix_fmts = (const enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGB555BE, PIX_FMT_ARGB, PIX_FMT_GRAY8, PIX_FMT_NONE},
.long_name = NULL_IF_CONFIG_SMALL("QuickTime Animation (RLE) video"),
};
diff --git a/libavcodec/r210dec.c b/libavcodec/r210dec.c
index 9d5f7eee9b..18086c6916 100644
--- a/libavcodec/r210dec.c
+++ b/libavcodec/r210dec.c
@@ -3,20 +3,20 @@
*
* Copyright (c) 2009 Reimar Doeffinger <Reimar.Doeffinger@gmx.de>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -98,29 +98,25 @@ static av_cold int decode_close(AVCodecContext *avctx)
#if CONFIG_R210_DECODER
AVCodec ff_r210_decoder = {
- "r210",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_R210,
- 0,
- decode_init,
- NULL,
- decode_close,
- decode_frame,
- CODEC_CAP_DR1,
+ .name = "r210",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_R210,
+ .init = decode_init,
+ .close = decode_close,
+ .decode = decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Uncompressed RGB 10-bit"),
};
#endif
#if CONFIG_R10K_DECODER
AVCodec ff_r10k_decoder = {
- "r10k",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_R10K,
- 0,
- decode_init,
- NULL,
- decode_close,
- decode_frame,
- CODEC_CAP_DR1,
+ .name = "r10k",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_R10K,
+ .init = decode_init,
+ .close = decode_close,
+ .decode = decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("AJA Kona 10-bit RGB Codec"),
};
#endif
diff --git a/libavcodec/ra144.c b/libavcodec/ra144.c
index fd2ed3299d..761f595934 100644
--- a/libavcodec/ra144.c
+++ b/libavcodec/ra144.c
@@ -2,20 +2,20 @@
* Real Audio 1.0 (14.4K)
* Copyright (c) 2003 the ffmpeg project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -1544,22 +1544,22 @@ void ff_copy_and_dup(int16_t *target, const int16_t *source, int offset)
int ff_eval_refl(int *refl, const int16_t *coefs, AVCodecContext *avctx)
{
int b, i, j;
- int buffer1[10];
- int buffer2[10];
+ int buffer1[LPC_ORDER];
+ int buffer2[LPC_ORDER];
int *bp1 = buffer1;
int *bp2 = buffer2;
- for (i=0; i < 10; i++)
+ for (i=0; i < LPC_ORDER; i++)
buffer2[i] = coefs[i];
- refl[9] = bp2[9];
+ refl[LPC_ORDER-1] = bp2[LPC_ORDER-1];
- if ((unsigned) bp2[9] + 0x1000 > 0x1fff) {
+ if ((unsigned) bp2[LPC_ORDER-1] + 0x1000 > 0x1fff) {
av_log(avctx, AV_LOG_ERROR, "Overflow. Broken sample?\n");
return 1;
}
- for (i=8; i >= 0; i--) {
+ for (i = LPC_ORDER-2; i >= 0; i--) {
b = 0x1000-((bp2[i+1] * bp2[i+1]) >> 12);
if (!b)
@@ -1584,12 +1584,12 @@ int ff_eval_refl(int *refl, const int16_t *coefs, AVCodecContext *avctx)
*/
void ff_eval_coefs(int *coefs, const int *refl)
{
- int buffer[10];
+ int buffer[LPC_ORDER];
int *b1 = buffer;
int *b2 = coefs;
int i, j;
- for (i=0; i < 10; i++) {
+ for (i=0; i < LPC_ORDER; i++) {
b1[i] = refl[i] << 4;
for (j=0; j < i; j++)
@@ -1598,7 +1598,7 @@ void ff_eval_coefs(int *coefs, const int *refl)
FFSWAP(int *, b1, b2);
}
- for (i=0; i < 10; i++)
+ for (i=0; i < LPC_ORDER; i++)
coefs[i] >>= 4;
}
@@ -1606,7 +1606,7 @@ void ff_int_to_int16(int16_t *out, const int *inp)
{
int i;
- for (i=0; i < 10; i++)
+ for (i = 0; i < LPC_ORDER; i++)
*out++ = *inp++;
}
@@ -1629,9 +1629,9 @@ unsigned int ff_rms(const int *data)
{
int i;
unsigned int res = 0x10000;
- int b = 10;
+ int b = LPC_ORDER;
- for (i=0; i < 10; i++) {
+ for (i = 0; i < LPC_ORDER; i++) {
res = (((0x1000000 - data[i]*data[i]) >> 12) * res) >> 12;
if (res == 0)
@@ -1648,13 +1648,13 @@ unsigned int ff_rms(const int *data)
int ff_interp(RA144Context *ractx, int16_t *out, int a, int copyold, int energy)
{
- int work[10];
+ int work[LPC_ORDER];
int b = NBLOCKS - a;
int i;
// Interpolate block coefficients from the this frame's forth block and
// last frame's forth block.
- for (i=0; i<10; i++)
+ for (i = 0; i < LPC_ORDER; i++)
out[i] = (a * ractx->lpc_coef[0][i] + b * ractx->lpc_coef[1][i])>> 2;
if (ff_eval_refl(work, out, ractx->avctx)) {
@@ -1690,7 +1690,7 @@ void ff_subblock_synthesis(RA144Context *ractx, const uint16_t *lpc_coefs,
int cba_idx, int cb1_idx, int cb2_idx,
int gval, int gain)
{
- uint16_t buffer_a[40];
+ uint16_t buffer_a[BLOCKSIZE];
uint16_t *block;
int m[3];
@@ -1711,10 +1711,10 @@ void ff_subblock_synthesis(RA144Context *ractx, const uint16_t *lpc_coefs,
ff_add_wav(block, gain, cba_idx, m, cba_idx? buffer_a: NULL,
ff_cb1_vects[cb1_idx], ff_cb2_vects[cb2_idx]);
- memcpy(ractx->curr_sblock, ractx->curr_sblock + 40,
- 10*sizeof(*ractx->curr_sblock));
+ memcpy(ractx->curr_sblock, ractx->curr_sblock + BLOCKSIZE,
+ LPC_ORDER*sizeof(*ractx->curr_sblock));
- if (ff_celp_lp_synthesis_filter(ractx->curr_sblock + 10, lpc_coefs,
- block, BLOCKSIZE, 10, 1, 0xfff))
- memset(ractx->curr_sblock, 0, 50*sizeof(*ractx->curr_sblock));
+ if (ff_celp_lp_synthesis_filter(ractx->curr_sblock + LPC_ORDER, lpc_coefs,
+ block, BLOCKSIZE, LPC_ORDER, 1, 0, 0xfff))
+ memset(ractx->curr_sblock, 0, (LPC_ORDER+BLOCKSIZE)*sizeof(*ractx->curr_sblock));
}
diff --git a/libavcodec/ra144.h b/libavcodec/ra144.h
index dcdfbb8ccc..722b42e68a 100644
--- a/libavcodec/ra144.h
+++ b/libavcodec/ra144.h
@@ -2,20 +2,20 @@
* Real Audio 1.0 (14.4K)
* Copyright (c) 2003 the ffmpeg project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/ra144dec.c b/libavcodec/ra144dec.c
index e64b6c20b4..2e57e5054c 100644
--- a/libavcodec/ra144dec.c
+++ b/libavcodec/ra144dec.c
@@ -5,20 +5,20 @@
* Copyright (c) 2003 Nick Kurshev
* Based on public domain decoder at http://www.honeypot.net/audio
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -59,29 +59,33 @@ static int ra144_decode_frame(AVCodecContext * avctx, void *vdata,
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
- static const uint8_t sizes[10] = {6, 5, 5, 4, 4, 3, 3, 3, 3, 2};
- unsigned int refl_rms[4]; // RMS of the reflection coefficients
- uint16_t block_coefs[4][10]; // LPC coefficients of each sub-block
- unsigned int lpc_refl[10]; // LPC reflection coefficients of the frame
+ static const uint8_t sizes[LPC_ORDER] = {6, 5, 5, 4, 4, 3, 3, 3, 3, 2};
+ unsigned int refl_rms[NBLOCKS]; // RMS of the reflection coefficients
+ uint16_t block_coefs[NBLOCKS][LPC_ORDER]; // LPC coefficients of each sub-block
+ unsigned int lpc_refl[LPC_ORDER]; // LPC reflection coefficients of the frame
int i, j;
+ int out_size;
int16_t *data = vdata;
unsigned int energy;
RA144Context *ractx = avctx->priv_data;
GetBitContext gb;
- if (*data_size < 2*160)
- return -1;
+ out_size = NBLOCKS * BLOCKSIZE * av_get_bytes_per_sample(avctx->sample_fmt);
+ if (*data_size < out_size) {
+ av_log(avctx, AV_LOG_ERROR, "Output buffer is too small\n");
+ return AVERROR(EINVAL);
+ }
- if(buf_size < 20) {
+ if(buf_size < FRAMESIZE) {
av_log(avctx, AV_LOG_ERROR,
"Frame too small (%d bytes). Truncated file?\n", buf_size);
*data_size = 0;
return buf_size;
}
- init_get_bits(&gb, buf, 20 * 8);
+ init_get_bits(&gb, buf, FRAMESIZE * 8);
- for (i=0; i<10; i++)
+ for (i = 0; i < LPC_ORDER; i++)
lpc_refl[i] = ff_lpc_refl_cb[i][get_bits(&gb, sizes[i])];
ff_eval_coefs(ractx->lpc_coef[0], lpc_refl);
@@ -98,7 +102,7 @@ static int ra144_decode_frame(AVCodecContext * avctx, void *vdata,
ff_int_to_int16(block_coefs[3], ractx->lpc_coef[0]);
- for (i=0; i < 4; i++) {
+ for (i=0; i < NBLOCKS; i++) {
do_output_subblock(ractx, block_coefs[i], refl_rms[i], &gb);
for (j=0; j < BLOCKSIZE; j++)
@@ -110,19 +114,16 @@ static int ra144_decode_frame(AVCodecContext * avctx, void *vdata,
FFSWAP(unsigned int *, ractx->lpc_coef[0], ractx->lpc_coef[1]);
- *data_size = 2*160;
- return 20;
+ *data_size = out_size;
+ return FRAMESIZE;
}
-AVCodec ff_ra_144_decoder =
-{
- "real_144",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_RA_144,
- sizeof(RA144Context),
- ra144_decode_init,
- NULL,
- NULL,
- ra144_decode_frame,
- .long_name = NULL_IF_CONFIG_SMALL("RealAudio 1.0 (14.4K)"),
+AVCodec ff_ra_144_decoder = {
+ .name = "real_144",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_RA_144,
+ .priv_data_size = sizeof(RA144Context),
+ .init = ra144_decode_init,
+ .decode = ra144_decode_frame,
+ .long_name = NULL_IF_CONFIG_SMALL("RealAudio 1.0 (14.4K)"),
};
diff --git a/libavcodec/ra144enc.c b/libavcodec/ra144enc.c
index 6eab6c300f..5a64a5ec74 100644
--- a/libavcodec/ra144enc.c
+++ b/libavcodec/ra144enc.c
@@ -2,20 +2,20 @@
* Real Audio 1.0 (14.4K) encoder
* Copyright (c) 2010 Francesco Lavra <francescolavra@interfree.it>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -508,14 +508,13 @@ static int ra144_encode_frame(AVCodecContext *avctx, uint8_t *frame,
}
-AVCodec ff_ra_144_encoder =
-{
- "real_144",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_RA_144,
- sizeof(RA144Context),
- ra144_encode_init,
- ra144_encode_frame,
- ra144_encode_close,
- .long_name = NULL_IF_CONFIG_SMALL("RealAudio 1.0 (14.4K) encoder"),
+AVCodec ff_ra_144_encoder = {
+ .name = "real_144",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_RA_144,
+ .priv_data_size = sizeof(RA144Context),
+ .init = ra144_encode_init,
+ .encode = ra144_encode_frame,
+ .close = ra144_encode_close,
+ .long_name = NULL_IF_CONFIG_SMALL("RealAudio 1.0 (14.4K) encoder"),
};
diff --git a/libavcodec/ra288.c b/libavcodec/ra288.c
index 64d765cecd..620c711526 100644
--- a/libavcodec/ra288.c
+++ b/libavcodec/ra288.c
@@ -2,20 +2,20 @@
* RealAudio 2.0 (28.8K)
* Copyright (c) 2003 the ffmpeg project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -31,6 +31,9 @@
#define MAX_BACKWARD_FILTER_LEN 40
#define MAX_BACKWARD_FILTER_NONREC 35
+#define RA288_BLOCK_SIZE 5
+#define RA288_BLOCKS_PER_FRAME 32
+
typedef struct {
float sp_lpc[36]; ///< LPC coefficients for speech data (spec: A)
float gain_lpc[10]; ///< LPC coefficients for gain (spec: GB)
@@ -96,14 +99,14 @@ static void decode(RA288Context *ractx, float gain, int cb_coef)
for (i=0; i < 5; i++)
buffer[i] = codetable[cb_coef][i] * sumsum;
- sum = ff_dot_productf(buffer, buffer, 5) * ((1<<24)/5.);
+ sum = ff_dot_productf(buffer, buffer, 5);
- sum = FFMAX(sum, 1);
+ sum = FFMAX(sum, 5. / (1<<24));
/* shift and store */
memmove(gain_block, gain_block + 1, 9 * sizeof(*gain_block));
- gain_block[9] = 10 * log10(sum) - 32;
+ gain_block[9] = 10 * log10(sum) + (10*log10(((1<<24)/5.)) - 32);
ff_celp_lp_synthesis_filterf(block, ractx->sp_lpc, buffer, 5, 36);
}
@@ -165,7 +168,7 @@ static int ra288_decode_frame(AVCodecContext * avctx, void *data,
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
float *out = data;
- int i, j;
+ int i, j, out_size;
RA288Context *ractx = avctx->priv_data;
GetBitContext gb;
@@ -176,18 +179,22 @@ static int ra288_decode_frame(AVCodecContext * avctx, void *data,
return 0;
}
- if (*data_size < 32*5*4)
- return -1;
+ out_size = RA288_BLOCK_SIZE * RA288_BLOCKS_PER_FRAME *
+ av_get_bytes_per_sample(avctx->sample_fmt);
+ if (*data_size < out_size) {
+ av_log(avctx, AV_LOG_ERROR, "Output buffer is too small\n");
+ return AVERROR(EINVAL);
+ }
init_get_bits(&gb, buf, avctx->block_align * 8);
- for (i=0; i < 32; i++) {
+ for (i=0; i < RA288_BLOCKS_PER_FRAME; i++) {
float gain = amptable[get_bits(&gb, 3)];
int cb_coef = get_bits(&gb, 6 + (i&1));
decode(ractx, gain, cb_coef);
- for (j=0; j < 5; j++)
+ for (j=0; j < RA288_BLOCK_SIZE; j++)
*(out++) = ractx->sp_hist[70 + 36 + j];
if ((i & 7) == 3) {
@@ -199,19 +206,16 @@ static int ra288_decode_frame(AVCodecContext * avctx, void *data,
}
}
- *data_size = (char *)out - (char *)data;
+ *data_size = out_size;
return avctx->block_align;
}
-AVCodec ff_ra_288_decoder =
-{
- "real_288",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_RA_288,
- sizeof(RA288Context),
- ra288_decode_init,
- NULL,
- NULL,
- ra288_decode_frame,
- .long_name = NULL_IF_CONFIG_SMALL("RealAudio 2.0 (28.8K)"),
+AVCodec ff_ra_288_decoder = {
+ .name = "real_288",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_RA_288,
+ .priv_data_size = sizeof(RA288Context),
+ .init = ra288_decode_init,
+ .decode = ra288_decode_frame,
+ .long_name = NULL_IF_CONFIG_SMALL("RealAudio 2.0 (28.8K)"),
};
diff --git a/libavcodec/ra288.h b/libavcodec/ra288.h
index 8857f40ac8..d7fd4b54f9 100644
--- a/libavcodec/ra288.h
+++ b/libavcodec/ra288.h
@@ -2,20 +2,20 @@
* RealAudio 2.0 (28.8K)
* Copyright (c) 2003 the ffmpeg project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/rangecoder.c b/libavcodec/rangecoder.c
index 1cd6762cb5..04c2738523 100644
--- a/libavcodec/rangecoder.c
+++ b/libavcodec/rangecoder.c
@@ -2,20 +2,20 @@
* Range coder
* Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/rangecoder.h b/libavcodec/rangecoder.h
index 7ad1bd2e55..47c0362ba3 100644
--- a/libavcodec/rangecoder.h
+++ b/libavcodec/rangecoder.h
@@ -2,20 +2,20 @@
* Range coder
* Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/ratecontrol.c b/libavcodec/ratecontrol.c
index 0d7b995476..41b7d97d32 100644
--- a/libavcodec/ratecontrol.c
+++ b/libavcodec/ratecontrol.c
@@ -3,20 +3,20 @@
*
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -44,9 +44,9 @@ static double get_qscale(MpegEncContext *s, RateControlEntry *rce, double rate_f
void ff_write_pass1_stats(MpegEncContext *s){
snprintf(s->avctx->stats_out, 256, "in:%d out:%d type:%d q:%d itex:%d ptex:%d mv:%d misc:%d fcode:%d bcode:%d mc-var:%d var:%d icount:%d skipcount:%d hbits:%d;\n",
- s->current_picture_ptr->display_picture_number, s->current_picture_ptr->coded_picture_number, s->pict_type,
- s->current_picture.quality, s->i_tex_bits, s->p_tex_bits, s->mv_bits, s->misc_bits,
- s->f_code, s->b_code, s->current_picture.mc_mb_var_sum, s->current_picture.mb_var_sum, s->i_count, s->skip_count, s->header_bits);
+ s->current_picture_ptr->f.display_picture_number, s->current_picture_ptr->f.coded_picture_number, s->pict_type,
+ s->current_picture.f.quality, s->i_tex_bits, s->p_tex_bits, s->mv_bits, s->misc_bits,
+ s->f_code, s->b_code, s->current_picture.mc_mb_var_sum, s->current_picture.mb_var_sum, s->i_count, s->skip_count, s->header_bits);
}
static inline double qp2bits(RateControlEntry *rce, double qp){
@@ -707,10 +707,10 @@ float ff_rate_estimate_qscale(MpegEncContext *s, int dry_run)
//if(dts_pic)
// av_log(NULL, AV_LOG_ERROR, "%Ld %Ld %Ld %d\n", s->current_picture_ptr->pts, s->user_specified_pts, dts_pic->pts, picture_number);
- if(!dts_pic || dts_pic->pts == AV_NOPTS_VALUE)
+ if (!dts_pic || dts_pic->f.pts == AV_NOPTS_VALUE)
wanted_bits= (uint64_t)(s->bit_rate*(double)picture_number/fps);
else
- wanted_bits= (uint64_t)(s->bit_rate*(double)dts_pic->pts/fps);
+ wanted_bits = (uint64_t)(s->bit_rate*(double)dts_pic->f.pts / fps);
}
diff= s->total_bits - wanted_bits;
@@ -861,11 +861,19 @@ static int init_pass2(MpegEncContext *s)
/* find qscale */
for(i=0; i<rcc->num_entries; i++){
+ RateControlEntry *rce= &rcc->entry[i];
qscale[i]= get_qscale(s, &rcc->entry[i], rate_factor, i);
+ rcc->last_qscale_for[rce->pict_type] = qscale[i];
}
assert(filter_size%2==1);
/* fixed I/B QP relative to P mode */
+ for(i=FFMAX(0, rcc->num_entries-300); i<rcc->num_entries; i++){
+ RateControlEntry *rce= &rcc->entry[i];
+
+ qscale[i]= get_diff_limited_q(s, rce, qscale[i]);
+ }
+
for(i=rcc->num_entries-1; i>=0; i--){
RateControlEntry *rce= &rcc->entry[i];
diff --git a/libavcodec/ratecontrol.h b/libavcodec/ratecontrol.h
index 6cd4a18010..32efe01d24 100644
--- a/libavcodec/ratecontrol.h
+++ b/libavcodec/ratecontrol.h
@@ -3,20 +3,20 @@
* Copyright (c) 2000, 2001, 2002 Fabrice Bellard
* Copyright (c) 2002-2004 Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/raw.c b/libavcodec/raw.c
index aa1ea308b0..a26dea8146 100644
--- a/libavcodec/raw.c
+++ b/libavcodec/raw.c
@@ -2,20 +2,20 @@
* Raw Video Codec
* Copyright (c) 2001 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -36,6 +36,7 @@ const PixelFormatTag ff_raw_pix_fmt_tags[] = {
{ PIX_FMT_YUV411P, MKTAG('Y', '4', '1', 'B') },
{ PIX_FMT_YUV422P, MKTAG('Y', '4', '2', 'B') },
{ PIX_FMT_YUV422P, MKTAG('P', '4', '2', '2') },
+ { PIX_FMT_YUV422P, MKTAG('Y', 'V', '1', '6') },
/* yuvjXXX formats are deprecated hacks specific to libav*,
they are identical to yuvXXX */
{ PIX_FMT_YUVJ420P, MKTAG('I', '4', '2', '0') }, /* Planar formats */
@@ -44,7 +45,7 @@ const PixelFormatTag ff_raw_pix_fmt_tags[] = {
{ PIX_FMT_YUVJ422P, MKTAG('Y', '4', '2', 'B') },
{ PIX_FMT_YUVJ422P, MKTAG('P', '4', '2', '2') },
{ PIX_FMT_GRAY8, MKTAG('Y', '8', '0', '0') },
- { PIX_FMT_GRAY8, MKTAG(' ', ' ', 'Y', '8') },
+ { PIX_FMT_GRAY8, MKTAG('Y', '8', ' ', ' ') },
{ PIX_FMT_YUYV422, MKTAG('Y', 'U', 'Y', '2') }, /* Packed formats */
{ PIX_FMT_YUYV422, MKTAG('Y', '4', '2', '2') },
@@ -114,7 +115,7 @@ const PixelFormatTag ff_raw_pix_fmt_tags[] = {
{ PIX_FMT_YUV444P16LE, MKTAG('Y', '3', 0 , 16 ) },
{ PIX_FMT_YUV444P16BE, MKTAG(16 , 0 , '3', 'Y') },
{ PIX_FMT_YUVA420P, MKTAG('Y', '4', 11 , 8 ) },
- { PIX_FMT_Y400A, MKTAG('Y', '2', 0 , 8 ) },
+ { PIX_FMT_GRAY8A, MKTAG('Y', '2', 0 , 8 ) },
/* quicktime */
{ PIX_FMT_UYVY422, MKTAG('2', 'v', 'u', 'y') },
@@ -135,6 +136,7 @@ const PixelFormatTag ff_raw_pix_fmt_tags[] = {
/* special */
{ PIX_FMT_RGB565LE,MKTAG( 3 , 0 , 0 , 0 ) }, /* flipped RGB565LE */
+ { PIX_FMT_YUV444P, MKTAG('Y', 'V', '2', '4') }, /* YUV444P, swapped UV */
{ PIX_FMT_NONE, 0 },
};
diff --git a/libavcodec/raw.h b/libavcodec/raw.h
index 2caa3faff5..4724cd3547 100644
--- a/libavcodec/raw.h
+++ b/libavcodec/raw.h
@@ -2,20 +2,20 @@
* Raw Video Codec
* Copyright (c) 2001 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -35,5 +35,6 @@ typedef struct PixelFormatTag {
} PixelFormatTag;
extern const PixelFormatTag ff_raw_pix_fmt_tags[];
+enum PixelFormat ff_find_pix_fmt(const PixelFormatTag *tags, unsigned int fourcc);
#endif /* AVCODEC_RAW_H */
diff --git a/libavcodec/rawdec.c b/libavcodec/rawdec.c
index 5e8e6c4c43..acaa0ea732 100644
--- a/libavcodec/rawdec.c
+++ b/libavcodec/rawdec.c
@@ -2,20 +2,20 @@
* Raw Video Decoder
* Copyright (c) 2001 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -29,23 +29,34 @@
#include "raw.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/imgutils.h"
+#include "libavutil/opt.h"
typedef struct RawVideoContext {
+ AVClass *av_class;
uint32_t palette[AVPALETTE_COUNT];
unsigned char * buffer; /* block of memory for holding one frame */
int length; /* number of bytes in buffer */
int flip;
AVFrame pic; ///< AVCodecContext.coded_frame
+ int tff;
} RawVideoContext;
+static const AVOption options[]={
+{"top", "top field first", offsetof(RawVideoContext, tff), AV_OPT_TYPE_INT, {.dbl = -1}, -1, 1, AV_OPT_FLAG_DECODING_PARAM|AV_OPT_FLAG_VIDEO_PARAM},
+{NULL}
+};
+static const AVClass class = { "rawdec", NULL, options, LIBAVUTIL_VERSION_INT };
+
static const PixelFormatTag pix_fmt_bps_avi[] = {
+ { PIX_FMT_MONOWHITE, 1 },
+ { PIX_FMT_PAL8, 2 },
{ PIX_FMT_PAL8, 4 },
{ PIX_FMT_PAL8, 8 },
{ PIX_FMT_RGB444, 12 },
{ PIX_FMT_RGB555, 15 },
{ PIX_FMT_RGB555, 16 },
{ PIX_FMT_BGR24, 24 },
- { PIX_FMT_RGB32, 32 },
+ { PIX_FMT_BGRA, 32 },
{ PIX_FMT_NONE, 0 },
};
@@ -59,10 +70,11 @@ static const PixelFormatTag pix_fmt_bps_mov[] = {
{ PIX_FMT_RGB555BE, 16 },
{ PIX_FMT_RGB24, 24 },
{ PIX_FMT_ARGB, 32 },
+ { PIX_FMT_MONOWHITE,33 },
{ PIX_FMT_NONE, 0 },
};
-static enum PixelFormat find_pix_fmt(const PixelFormatTag *tags, unsigned int fourcc)
+enum PixelFormat ff_find_pix_fmt(const PixelFormatTag *tags, unsigned int fourcc)
{
while (tags->pix_fmt >= 0) {
if (tags->fourcc == fourcc)
@@ -77,22 +89,29 @@ static av_cold int raw_init_decoder(AVCodecContext *avctx)
RawVideoContext *context = avctx->priv_data;
if (avctx->codec_tag == MKTAG('r','a','w',' '))
- avctx->pix_fmt = find_pix_fmt(pix_fmt_bps_mov, avctx->bits_per_coded_sample);
+ avctx->pix_fmt = ff_find_pix_fmt(pix_fmt_bps_mov, avctx->bits_per_coded_sample);
else if (avctx->codec_tag == MKTAG('W','R','A','W'))
- avctx->pix_fmt = find_pix_fmt(pix_fmt_bps_avi, avctx->bits_per_coded_sample);
+ avctx->pix_fmt = ff_find_pix_fmt(pix_fmt_bps_avi, avctx->bits_per_coded_sample);
else if (avctx->codec_tag)
- avctx->pix_fmt = find_pix_fmt(ff_raw_pix_fmt_tags, avctx->codec_tag);
+ avctx->pix_fmt = ff_find_pix_fmt(ff_raw_pix_fmt_tags, avctx->codec_tag);
else if (avctx->pix_fmt == PIX_FMT_NONE && avctx->bits_per_coded_sample)
- avctx->pix_fmt = find_pix_fmt(pix_fmt_bps_avi, avctx->bits_per_coded_sample);
+ avctx->pix_fmt = ff_find_pix_fmt(pix_fmt_bps_avi, avctx->bits_per_coded_sample);
+
+ if (avctx->pix_fmt == PIX_FMT_NONE) {
+ av_log(avctx, AV_LOG_ERROR, "Pixel format was not specified and cannot be detected\n");
+ return AVERROR(EINVAL);
+ }
ff_set_systematic_pal2(context->palette, avctx->pix_fmt);
- context->length = avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height);
if((avctx->bits_per_coded_sample == 4 || avctx->bits_per_coded_sample == 2) &&
avctx->pix_fmt==PIX_FMT_PAL8 &&
(!avctx->codec_tag || avctx->codec_tag == MKTAG('r','a','w',' '))){
+ context->length = avpicture_get_size(avctx->pix_fmt, (avctx->width+3)&~3, avctx->height);
context->buffer = av_malloc(context->length);
if (!context->buffer)
return -1;
+ } else {
+ context->length = avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height);
}
context->pic.pict_type = AV_PICTURE_TYPE_I;
context->pic.key_frame = 1;
@@ -122,10 +141,17 @@ static int raw_decode(AVCodecContext *avctx,
AVFrame * frame = (AVFrame *) data;
AVPicture * picture = (AVPicture *) data;
+ frame->pict_type = avctx->coded_frame->pict_type;
frame->interlaced_frame = avctx->coded_frame->interlaced_frame;
frame->top_field_first = avctx->coded_frame->top_field_first;
frame->reordered_opaque = avctx->reordered_opaque;
frame->pkt_pts = avctx->pkt->pts;
+ frame->pkt_pos = avctx->pkt->pos;
+
+ if(context->tff>=0){
+ frame->interlaced_frame = 1;
+ frame->top_field_first = context->tff;
+ }
//2bpp and 4bpp raw in avi and mov (yes this is ugly ...)
if (context->buffer) {
@@ -168,13 +194,21 @@ static int raw_decode(AVCodecContext *avctx,
frame->palette_has_changed = 1;
}
}
- if(avctx->pix_fmt==PIX_FMT_BGR24 && ((frame->linesize[0]+3)&~3)*avctx->height <= buf_size)
+ if((avctx->pix_fmt==PIX_FMT_BGR24 ||
+ avctx->pix_fmt==PIX_FMT_GRAY8 ||
+ avctx->pix_fmt==PIX_FMT_RGB555LE ||
+ avctx->pix_fmt==PIX_FMT_RGB555BE ||
+ avctx->pix_fmt==PIX_FMT_RGB565LE ||
+ avctx->pix_fmt==PIX_FMT_PAL8) &&
+ ((frame->linesize[0]+3)&~3)*avctx->height <= buf_size)
frame->linesize[0] = (frame->linesize[0]+3)&~3;
if(context->flip)
flip(avctx, picture);
if ( avctx->codec_tag == MKTAG('Y', 'V', '1', '2')
+ || avctx->codec_tag == MKTAG('Y', 'V', '1', '6')
+ || avctx->codec_tag == MKTAG('Y', 'V', '2', '4')
|| avctx->codec_tag == MKTAG('Y', 'V', 'U', '9'))
FFSWAP(uint8_t *, picture->data[1], picture->data[2]);
@@ -202,13 +236,13 @@ static av_cold int raw_close_decoder(AVCodecContext *avctx)
}
AVCodec ff_rawvideo_decoder = {
- "rawvideo",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_RAWVIDEO,
- sizeof(RawVideoContext),
- raw_init_decoder,
- NULL,
- raw_close_decoder,
- raw_decode,
+ .name = "rawvideo",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_RAWVIDEO,
+ .priv_data_size = sizeof(RawVideoContext),
+ .init = raw_init_decoder,
+ .close = raw_close_decoder,
+ .decode = raw_decode,
.long_name = NULL_IF_CONFIG_SMALL("raw video"),
+ .priv_class= &class,
};
diff --git a/libavcodec/rawenc.c b/libavcodec/rawenc.c
index 926124c54b..7077de170f 100644
--- a/libavcodec/rawenc.c
+++ b/libavcodec/rawenc.c
@@ -2,20 +2,20 @@
* Raw Video Encoder
* Copyright (c) 2001 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -56,11 +56,11 @@ static int raw_encode(AVCodecContext *avctx,
}
AVCodec ff_rawvideo_encoder = {
- "rawvideo",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_RAWVIDEO,
- sizeof(AVFrame),
- raw_init_encoder,
- raw_encode,
+ .name = "rawvideo",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_RAWVIDEO,
+ .priv_data_size = sizeof(AVFrame),
+ .init = raw_init_encoder,
+ .encode = raw_encode,
.long_name = NULL_IF_CONFIG_SMALL("raw video"),
};
diff --git a/libavcodec/rdft.c b/libavcodec/rdft.c
index 116cfa4366..ebddd8b56b 100644
--- a/libavcodec/rdft.c
+++ b/libavcodec/rdft.c
@@ -2,20 +2,20 @@
* (I)RDFT transforms
* Copyright (c) 2009 Alex Converse <alex dot converse at gmail dot com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>
diff --git a/libavcodec/rdft.h b/libavcodec/rdft.h
index 8ff620fb59..5fb03232a1 100644
--- a/libavcodec/rdft.h
+++ b/libavcodec/rdft.h
@@ -2,20 +2,20 @@
* (I)RDFT transforms
* Copyright (c) 2009 Alex Converse <alex dot converse at gmail dot com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/rectangle.h b/libavcodec/rectangle.h
index 5cc81feeaa..cf4a9ccec3 100644
--- a/libavcodec/rectangle.h
+++ b/libavcodec/rectangle.h
@@ -2,20 +2,20 @@
* rectangle filling function
* Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/remove_extradata_bsf.c b/libavcodec/remove_extradata_bsf.c
index 460482a8ff..f0d9b4513a 100644
--- a/libavcodec/remove_extradata_bsf.c
+++ b/libavcodec/remove_extradata_bsf.c
@@ -1,20 +1,20 @@
/*
* copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/resample.c b/libavcodec/resample.c
index 04bbbf07e4..a1018b44fc 100644
--- a/libavcodec/resample.c
+++ b/libavcodec/resample.c
@@ -2,20 +2,20 @@
* samplerate conversion for both audio and video
* Copyright (c) 2000 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -108,6 +108,39 @@ static void mono_to_stereo(short *output, short *input, int n1)
}
}
+/*
+5.1 to stereo input: [fl, fr, c, lfe, rl, rr]
+- Left = front_left + rear_gain * rear_left + center_gain * center
+- Right = front_right + rear_gain * rear_right + center_gain * center
+Where rear_gain is usually around 0.5-1.0 and
+ center_gain is almost always 0.7 (-3 dB)
+*/
+static void surround_to_stereo(short **output, short *input, int channels, int samples)
+{
+ int i;
+ short l, r;
+
+ for (i = 0; i < samples; i++) {
+ int fl,fr,c,rl,rr;
+ fl = input[0];
+ fr = input[1];
+ c = input[2];
+ // lfe = input[3];
+ rl = input[4];
+ rr = input[5];
+
+ l = av_clip_int16(fl + (0.5 * rl) + (0.7 * c));
+ r = av_clip_int16(fr + (0.5 * rr) + (0.7 * c));
+
+ /* output l & r. */
+ *output[0]++ = l;
+ *output[1]++ = r;
+
+ /* increment input. */
+ input += channels;
+ }
+}
+
static void deinterleave(short **output, short *input, int channels, int samples)
{
int i, j;
@@ -147,6 +180,21 @@ static void ac3_5p1_mux(short *output, short *input1, short *input2, int n)
}
}
+#define SUPPORT_RESAMPLE(ch1, ch2, ch3, ch4, ch5, ch6, ch7, ch8) \
+ ch8<<7 | ch7<<6 | ch6<<5 | ch5<<4 | ch4<<3 | ch3<<2 | ch2<<1 | ch1<<0
+
+static const uint8_t supported_resampling[MAX_CHANNELS] = {
+ // output ch: 1 2 3 4 5 6 7 8
+ SUPPORT_RESAMPLE(1, 1, 0, 0, 0, 0, 0, 0), // 1 input channel
+ SUPPORT_RESAMPLE(1, 1, 0, 0, 0, 1, 0, 0), // 2 input channels
+ SUPPORT_RESAMPLE(0, 0, 1, 0, 0, 0, 0, 0), // 3 input channels
+ SUPPORT_RESAMPLE(0, 0, 0, 1, 0, 0, 0, 0), // 4 input channels
+ SUPPORT_RESAMPLE(0, 0, 0, 0, 1, 0, 0, 0), // 5 input channels
+ SUPPORT_RESAMPLE(0, 1, 0, 0, 0, 1, 0, 0), // 6 input channels
+ SUPPORT_RESAMPLE(0, 0, 0, 0, 0, 0, 1, 0), // 7 input channels
+ SUPPORT_RESAMPLE(0, 0, 0, 0, 0, 0, 0, 1), // 8 input channels
+};
+
ReSampleContext *av_audio_resample_init(int output_channels, int input_channels,
int output_rate, int input_rate,
enum AVSampleFormat sample_fmt_out,
@@ -162,11 +210,15 @@ ReSampleContext *av_audio_resample_init(int output_channels, int input_channels,
MAX_CHANNELS);
return NULL;
}
- if (output_channels > 2 &&
- !(output_channels == 6 && input_channels == 2) &&
- output_channels != input_channels) {
- av_log(NULL, AV_LOG_ERROR,
- "Resampling output channel count must be 1 or 2 for mono input; 1, 2 or 6 for stereo input; or N for N channel input.\n");
+ if (!(supported_resampling[input_channels-1] & (1<<(output_channels-1)))) {
+ int i;
+ av_log(NULL, AV_LOG_ERROR, "Unsupported audio resampling. Allowed "
+ "output channels for %d input channel%s", input_channels,
+ input_channels > 1 ? "s:" : ":");
+ for (i = 0; i < MAX_CHANNELS; i++)
+ if (supported_resampling[input_channels-1] & (1<<i))
+ av_log(NULL, AV_LOG_ERROR, " %d", i + 1);
+ av_log(NULL, AV_LOG_ERROR, "\n");
return NULL;
}
@@ -269,7 +321,7 @@ int audio_resample(ReSampleContext *s, short *output, short *input, int nb_sampl
input = s->buffer[0];
}
- lenout = 4 * nb_samples * s->ratio + 16;
+ lenout= 2*s->output_channels*nb_samples * s->ratio + 16;
if (s->sample_fmt[1] != AV_SAMPLE_FMT_S16) {
output_bak = output;
@@ -301,6 +353,10 @@ int audio_resample(ReSampleContext *s, short *output, short *input, int nb_sampl
} else if (s->output_channels >= 2 && s->input_channels == 1) {
buftmp3[0] = bufout[0];
memcpy(buftmp2[0], input, nb_samples * sizeof(short));
+ } else if (s->input_channels == 6 && s->output_channels ==2) {
+ buftmp3[0] = bufout[0];
+ buftmp3[1] = bufout[1];
+ surround_to_stereo(buftmp2, input, s->input_channels, nb_samples);
} else if (s->output_channels >= s->input_channels && s->input_channels >= 2) {
for (i = 0; i < s->input_channels; i++) {
buftmp3[i] = bufout[i];
@@ -330,7 +386,8 @@ int audio_resample(ReSampleContext *s, short *output, short *input, int nb_sampl
mono_to_stereo(output, buftmp3[0], nb_samples1);
} else if (s->output_channels == 6 && s->input_channels == 2) {
ac3_5p1_mux(output, buftmp3[0], buftmp3[1], nb_samples1);
- } else if (s->output_channels == s->input_channels && s->input_channels >= 2) {
+ } else if ((s->output_channels == s->input_channels && s->input_channels >= 2) ||
+ (s->output_channels == 2 && s->input_channels == 6)) {
interleave(output, buftmp3, s->output_channels, nb_samples1);
}
diff --git a/libavcodec/resample2.c b/libavcodec/resample2.c
index 7560d84bd4..b940059d84 100644
--- a/libavcodec/resample2.c
+++ b/libavcodec/resample2.c
@@ -2,20 +2,20 @@
* audio resampling
* Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/rl.h b/libavcodec/rl.h
index 9c1ad7a642..b2445890e6 100644
--- a/libavcodec/rl.h
+++ b/libavcodec/rl.h
@@ -2,20 +2,20 @@
* Copyright (c) 2000-2002 Fabrice Bellard
* Copyright (c) 2002-2004 Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/rl2.c b/libavcodec/rl2.c
index 3d1cea3995..7d1cf16aee 100644
--- a/libavcodec/rl2.c
+++ b/libavcodec/rl2.c
@@ -2,29 +2,28 @@
* RL2 Video Decoder
* Copyright (C) 2008 Sascha Sommer (saschasommer@freenet.de)
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
- * RL2 Video Decoder
* @file
+ * RL2 Video Decoder
* @author Sascha Sommer (saschasommer@freenet.de)
- * For more information about the RL2 format, visit:
- * http://wiki.multimedia.cx/index.php?title=RL2
+ * @see http://wiki.multimedia.cx/index.php?title=RL2
*/
#include <stdio.h>
@@ -134,6 +133,7 @@ static av_cold int rl2_decode_init(AVCodecContext *avctx)
int i;
s->avctx = avctx;
avctx->pix_fmt = PIX_FMT_PAL8;
+ avcodec_get_frame_defaults(&s->frame);
/** parse extra data */
if(!avctx->extradata || avctx->extradata_size < EXTRADATA1_SIZE){
@@ -220,15 +220,14 @@ static av_cold int rl2_decode_end(AVCodecContext *avctx)
AVCodec ff_rl2_decoder = {
- "rl2",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_RL2,
- sizeof(Rl2Context),
- rl2_decode_init,
- NULL,
- rl2_decode_end,
- rl2_decode_frame,
- CODEC_CAP_DR1,
+ .name = "rl2",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_RL2,
+ .priv_data_size = sizeof(Rl2Context),
+ .init = rl2_decode_init,
+ .close = rl2_decode_end,
+ .decode = rl2_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("RL2 video"),
};
diff --git a/libavcodec/rle.c b/libavcodec/rle.c
index 8a009e72bc..6e468f8991 100644
--- a/libavcodec/rle.c
+++ b/libavcodec/rle.c
@@ -2,20 +2,20 @@
* RLE encoder
* Copyright (c) 2007 Bobby Bingham
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avcodec.h"
diff --git a/libavcodec/rle.h b/libavcodec/rle.h
index 00261d3598..24851321fe 100644
--- a/libavcodec/rle.h
+++ b/libavcodec/rle.h
@@ -1,20 +1,20 @@
/*
* RLE encoder
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/roqaudioenc.c b/libavcodec/roqaudioenc.c
index 46aefb4bef..ac8c94a045 100644
--- a/libavcodec/roqaudioenc.c
+++ b/libavcodec/roqaudioenc.c
@@ -4,20 +4,20 @@
* Copyright (c) 2005 Eric Lasota
* Based on RoQ specs (c)2001 Tim Ferguson
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -154,14 +154,13 @@ static av_cold int roq_dpcm_encode_close(AVCodecContext *avctx)
}
AVCodec ff_roq_dpcm_encoder = {
- "roq_dpcm",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_ROQ_DPCM,
- sizeof(ROQDPCMContext),
- roq_dpcm_encode_init,
- roq_dpcm_encode_frame,
- roq_dpcm_encode_close,
- NULL,
+ .name = "roq_dpcm",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_ROQ_DPCM,
+ .priv_data_size = sizeof(ROQDPCMContext),
+ .init = roq_dpcm_encode_init,
+ .encode = roq_dpcm_encode_frame,
+ .close = roq_dpcm_encode_close,
.sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
.long_name = NULL_IF_CONFIG_SMALL("id RoQ DPCM"),
};
diff --git a/libavcodec/roqvideo.c b/libavcodec/roqvideo.c
index 77df0798db..eb8fc253ad 100644
--- a/libavcodec/roqvideo.c
+++ b/libavcodec/roqvideo.c
@@ -2,20 +2,20 @@
* Copyright (C) 2003 Mike Melanson
* Copyright (C) 2003 Dr. Tim Ferguson
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/roqvideo.h b/libavcodec/roqvideo.h
index a1ff10af7d..3fe11c670b 100644
--- a/libavcodec/roqvideo.h
+++ b/libavcodec/roqvideo.h
@@ -2,20 +2,20 @@
* Copyright (C) 2003 Mike Melanson
* Copyright (C) 2003 Dr. Tim Ferguson
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/roqvideodec.c b/libavcodec/roqvideodec.c
index 06d1309d65..f0c3ebb8d9 100644
--- a/libavcodec/roqvideodec.c
+++ b/libavcodec/roqvideodec.c
@@ -1,20 +1,20 @@
/*
* Copyright (C) 2003 the ffmpeg project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -71,9 +71,17 @@ static void roqvideo_decode_frame(RoqContext *ri)
}
bpos = xpos = ypos = 0;
+ if (chunk_size > buf_end - buf) {
+ av_log(ri->avctx, AV_LOG_ERROR, "Chunk does not fit in input buffer\n");
+ chunk_size = buf_end - buf;
+ }
while(bpos < chunk_size) {
for (yp = ypos; yp < ypos + 16; yp += 8)
for (xp = xpos; xp < xpos + 16; xp += 8) {
+ if (bpos >= chunk_size) {
+ av_log(ri->avctx, AV_LOG_ERROR, "Input buffer too small\n");
+ return;
+ }
if (vqflg_pos < 0) {
vqflg = buf[bpos++]; vqflg |= (buf[bpos++] << 8);
vqflg_pos = 7;
@@ -103,6 +111,10 @@ static void roqvideo_decode_frame(RoqContext *ri)
if(k & 0x01) x += 4;
if(k & 0x02) y += 4;
+ if (bpos >= chunk_size) {
+ av_log(ri->avctx, AV_LOG_ERROR, "Input buffer too small\n");
+ return;
+ }
if (vqflg_pos < 0) {
vqflg = buf[bpos++];
vqflg |= (buf[bpos++] << 8);
@@ -159,6 +171,8 @@ static av_cold int roq_decode_init(AVCodecContext *avctx)
s->avctx = avctx;
s->width = avctx->width;
s->height = avctx->height;
+ avcodec_get_frame_defaults(&s->frames[0]);
+ avcodec_get_frame_defaults(&s->frames[1]);
s->last_frame = &s->frames[0];
s->current_frame = &s->frames[1];
avctx->pix_fmt = PIX_FMT_YUV444P;
@@ -211,14 +225,13 @@ static av_cold int roq_decode_end(AVCodecContext *avctx)
}
AVCodec ff_roq_decoder = {
- "roqvideo",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_ROQ,
- sizeof(RoqContext),
- roq_decode_init,
- NULL,
- roq_decode_end,
- roq_decode_frame,
- CODEC_CAP_DR1,
+ .name = "roqvideo",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_ROQ,
+ .priv_data_size = sizeof(RoqContext),
+ .init = roq_decode_init,
+ .close = roq_decode_end,
+ .decode = roq_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("id RoQ video"),
};
diff --git a/libavcodec/roqvideoenc.c b/libavcodec/roqvideoenc.c
index 052dcef3de..88d6224eac 100644
--- a/libavcodec/roqvideoenc.c
+++ b/libavcodec/roqvideoenc.c
@@ -5,27 +5,27 @@
* Copyright (C) 2004-2007 Eric Lasota
* Based on RoQ specs (C) 2001 Tim Ferguson
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* id RoQ encoder by Vitor. Based on the Switchblade3 library and the
- * Switchblade3 Libav glue by Eric Lasota.
+ * Switchblade3 FFmpeg glue by Eric Lasota.
*/
/*
@@ -1065,16 +1065,15 @@ static int roq_encode_end(AVCodecContext *avctx)
return 0;
}
-AVCodec ff_roq_encoder =
-{
- "roqvideo",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_ROQ,
- sizeof(RoqContext),
- roq_encode_init,
- roq_encode_frame,
- roq_encode_end,
+AVCodec ff_roq_encoder = {
+ .name = "roqvideo",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_ROQ,
+ .priv_data_size = sizeof(RoqContext),
+ .init = roq_encode_init,
+ .encode = roq_encode_frame,
+ .close = roq_encode_end,
.supported_framerates = (const AVRational[]){{30,1}, {0,0}},
- .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUV444P, PIX_FMT_NONE},
- .long_name = NULL_IF_CONFIG_SMALL("id RoQ video"),
+ .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUV444P, PIX_FMT_NONE},
+ .long_name = NULL_IF_CONFIG_SMALL("id RoQ video"),
};
diff --git a/libavcodec/rpza.c b/libavcodec/rpza.c
index 958f103865..ea90ed6756 100644
--- a/libavcodec/rpza.c
+++ b/libavcodec/rpza.c
@@ -2,20 +2,20 @@
* Quicktime Video (RPZA) Video Decoder
* Copyright (C) 2003 the ffmpeg project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -233,6 +233,7 @@ static av_cold int rpza_decode_init(AVCodecContext *avctx)
s->avctx = avctx;
avctx->pix_fmt = PIX_FMT_RGB555;
+ avcodec_get_frame_defaults(&s->frame);
s->frame.data[0] = NULL;
return 0;
@@ -276,14 +277,13 @@ static av_cold int rpza_decode_end(AVCodecContext *avctx)
}
AVCodec ff_rpza_decoder = {
- "rpza",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_RPZA,
- sizeof(RpzaContext),
- rpza_decode_init,
- NULL,
- rpza_decode_end,
- rpza_decode_frame,
- CODEC_CAP_DR1,
+ .name = "rpza",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_RPZA,
+ .priv_data_size = sizeof(RpzaContext),
+ .init = rpza_decode_init,
+ .close = rpza_decode_end,
+ .decode = rpza_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("QuickTime video (RPZA)"),
};
diff --git a/libavcodec/rtjpeg.c b/libavcodec/rtjpeg.c
index 8d1f28a436..303183f230 100644
--- a/libavcodec/rtjpeg.c
+++ b/libavcodec/rtjpeg.c
@@ -2,20 +2,20 @@
* RTJpeg decoding functions
* Copyright (c) 2006 Reimar Doeffinger
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/common.h"
diff --git a/libavcodec/rtjpeg.h b/libavcodec/rtjpeg.h
index d537c93ff4..4bcb9f70ca 100644
--- a/libavcodec/rtjpeg.h
+++ b/libavcodec/rtjpeg.h
@@ -2,20 +2,20 @@
* RTJpeg decoding functions
* copyright (c) 2006 Reimar Doeffinger
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/rv10.c b/libavcodec/rv10.c
index 6227dc6f6c..20e2829e32 100644
--- a/libavcodec/rv10.c
+++ b/libavcodec/rv10.c
@@ -3,20 +3,20 @@
* Copyright (c) 2000,2001 Fabrice Bellard
* Copyright (c) 2002-2004 Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -34,6 +34,10 @@
//#define DEBUG
+#define RV_GET_MAJOR_VER(x) ((x) >> 28)
+#define RV_GET_MINOR_VER(x) (((x) >> 20) & 0xFF)
+#define RV_GET_MICRO_VER(x) (((x) >> 12) & 0xFF)
+
#define DC_VLC_BITS 14 //FIXME find a better solution
static const uint16_t rv_lum_code[256] =
@@ -292,13 +296,24 @@ static int rv10_decode_picture_header(MpegEncContext *s)
static int rv20_decode_picture_header(MpegEncContext *s)
{
int seq, mb_pos, i;
+ int rpr_bits;
- if(s->avctx->sub_id == 0x30202002 || s->avctx->sub_id == 0x30203002){
- if (get_bits(&s->gb, 3)){
- av_log(s->avctx, AV_LOG_ERROR, "unknown triplet set\n");
- return -1;
- }
+#if 0
+ GetBitContext gb= s->gb;
+ for(i=0; i<64; i++){
+ av_log(s->avctx, AV_LOG_DEBUG, "%d", get_bits1(&gb));
+ if(i%4==3) av_log(s->avctx, AV_LOG_DEBUG, " ");
}
+ av_log(s->avctx, AV_LOG_DEBUG, "\n");
+#endif
+#if 0
+ av_log(s->avctx, AV_LOG_DEBUG, "%3dx%03d/%02Xx%02X ", s->width, s->height, s->width/4, s->height/4);
+ for(i=0; i<s->avctx->extradata_size; i++){
+ av_log(s->avctx, AV_LOG_DEBUG, "%02X ", ((uint8_t*)s->avctx->extradata)[i]);
+ if(i%4==3) av_log(s->avctx, AV_LOG_DEBUG, " ");
+ }
+ av_log(s->avctx, AV_LOG_DEBUG, "\n");
+#endif
i= get_bits(&s->gb, 2);
switch(i){
@@ -317,7 +332,7 @@ static int rv20_decode_picture_header(MpegEncContext *s)
}
if (get_bits1(&s->gb)){
- av_log(s->avctx, AV_LOG_ERROR, "unknown bit set\n");
+ av_log(s->avctx, AV_LOG_ERROR, "reserved bit set\n");
return -1;
}
@@ -326,23 +341,21 @@ static int rv20_decode_picture_header(MpegEncContext *s)
av_log(s->avctx, AV_LOG_ERROR, "error, qscale:0\n");
return -1;
}
- if(s->avctx->sub_id == 0x30203002){
- if (get_bits1(&s->gb)){
- av_log(s->avctx, AV_LOG_ERROR, "unknown bit2 set\n");
- return -1;
- }
- }
- if(s->avctx->has_b_frames){
- int f, new_w, new_h;
- int v= s->avctx->extradata_size >= 4 ? 7&((uint8_t*)s->avctx->extradata)[1] : 0;
+ if(RV_GET_MINOR_VER(s->avctx->sub_id) >= 2)
+ s->loop_filter = get_bits1(&s->gb);
- if (get_bits1(&s->gb)){
- av_log(s->avctx, AV_LOG_ERROR, "unknown bit3 set\n");
- }
- seq= get_bits(&s->gb, 13)<<2;
+ if(RV_GET_MINOR_VER(s->avctx->sub_id) <= 1)
+ seq = get_bits(&s->gb, 8) << 7;
+ else
+ seq = get_bits(&s->gb, 13) << 2;
+
+ rpr_bits = s->avctx->extradata[1] & 7;
+ if(rpr_bits){
+ int f, new_w, new_h;
+ rpr_bits = FFMIN((rpr_bits >> 1) + 1, 3);
- f= get_bits(&s->gb, av_log2(v)+1);
+ f = get_bits(&s->gb, rpr_bits);
if(f){
new_w= 4*((uint8_t*)s->avctx->extradata)[6+2*f];
@@ -364,19 +377,12 @@ static int rv20_decode_picture_header(MpegEncContext *s)
}
if(s->avctx->debug & FF_DEBUG_PICT_INFO){
- av_log(s->avctx, AV_LOG_DEBUG, "F %d/%d\n", f, v);
+ av_log(s->avctx, AV_LOG_DEBUG, "F %d/%d\n", f, rpr_bits);
}
- }else{
- seq= get_bits(&s->gb, 8)*128;
}
-// if(s->avctx->sub_id <= 0x20201002){ //0x20201002 definitely needs this
- mb_pos= ff_h263_decode_mba(s);
-/* }else{
- mb_pos= get_bits(&s->gb, av_log2(s->mb_num-1)+1);
- s->mb_x= mb_pos % s->mb_width;
- s->mb_y= mb_pos / s->mb_width;
- }*/
+ mb_pos = ff_h263_decode_mba(s);
+
//av_log(s->avctx, AV_LOG_DEBUG, "%d\n", seq);
seq |= s->time &~0x7FFF;
if(seq - s->time > 0x4000) seq -= 0x8000;
@@ -403,6 +409,9 @@ static int rv20_decode_picture_header(MpegEncContext *s)
av_log(s->avctx, AV_LOG_DEBUG, "\n");*/
s->no_rounding= get_bits1(&s->gb);
+ if(RV_GET_MINOR_VER(s->avctx->sub_id) <= 1 && s->pict_type == AV_PICTURE_TYPE_B)
+ skip_bits(&s->gb, 5); // binary decoder reads 3+2 bits here but they don't seem to be used
+
s->f_code = 1;
s->unrestricted_mv = 1;
s->h263_aic= s->pict_type == AV_PICTURE_TYPE_I;
@@ -427,6 +436,7 @@ static av_cold int rv10_decode_init(AVCodecContext *avctx)
{
MpegEncContext *s = avctx->priv_data;
static int done=0;
+ int major_ver, minor_ver, micro_ver;
if (avctx->extradata_size < 8) {
av_log(avctx, AV_LOG_ERROR, "Extradata is too small.\n");
@@ -445,32 +455,27 @@ static av_cold int rv10_decode_init(AVCodecContext *avctx)
s->h263_long_vectors= ((uint8_t*)avctx->extradata)[3] & 1;
avctx->sub_id= AV_RB32((uint8_t*)avctx->extradata + 4);
- if (avctx->sub_id == 0x10000000) {
- s->rv10_version= 0;
- s->low_delay=1;
- } else if (avctx->sub_id == 0x10001000) {
- s->rv10_version= 3;
- s->low_delay=1;
- } else if (avctx->sub_id == 0x10002000) {
- s->rv10_version= 3;
- s->low_delay=1;
- s->obmc=1;
- } else if (avctx->sub_id == 0x10003000) {
- s->rv10_version= 3;
- s->low_delay=1;
- } else if (avctx->sub_id == 0x10003001) {
- s->rv10_version= 3;
- s->low_delay=1;
- } else if ( avctx->sub_id == 0x20001000
- || (avctx->sub_id >= 0x20100000 && avctx->sub_id < 0x201a0000)) {
- s->low_delay=1;
- } else if ( avctx->sub_id == 0x30202002
- || avctx->sub_id == 0x30203002
- || (avctx->sub_id >= 0x20200002 && avctx->sub_id < 0x20300000)) {
- s->low_delay=0;
- s->avctx->has_b_frames=1;
- } else
+ major_ver = RV_GET_MAJOR_VER(avctx->sub_id);
+ minor_ver = RV_GET_MINOR_VER(avctx->sub_id);
+ micro_ver = RV_GET_MICRO_VER(avctx->sub_id);
+
+ s->low_delay = 1;
+ switch (major_ver) {
+ case 1:
+ s->rv10_version = micro_ver ? 3 : 1;
+ s->obmc = micro_ver == 2;
+ break;
+ case 2:
+ if (minor_ver >= 2) {
+ s->low_delay = 0;
+ s->avctx->has_b_frames = 1;
+ }
+ break;
+ default:
av_log(s->avctx, AV_LOG_ERROR, "unknown header %X\n", avctx->sub_id);
+ av_log_missing_feature(avctx, "RV1/2 version", 1);
+ return AVERROR_PATCHWELCOME;
+ }
if(avctx->debug & FF_DEBUG_PICT_INFO){
av_log(avctx, AV_LOG_DEBUG, "ver:%X ver0:%X\n", avctx->sub_id, avctx->extradata_size >= 4 ? ((uint32_t*)avctx->extradata)[0] : -1);
@@ -542,8 +547,14 @@ static int rv10_decode_packet(AVCodecContext *avctx,
if(MPV_frame_start(s, avctx) < 0)
return -1;
ff_er_frame_start(s);
+ } else {
+ if (s->current_picture_ptr->f.pict_type != s->pict_type) {
+ av_log(s->avctx, AV_LOG_ERROR, "Slice type mismatch\n");
+ return -1;
+ }
}
+
av_dlog(avctx, "qscale=%d\n", s->qscale);
/* default quantization values */
@@ -639,6 +650,8 @@ static int rv10_decode_frame(AVCodecContext *avctx,
const uint8_t *slices_hdr = NULL;
av_dlog(avctx, "*****frame %d size=%d\n", avctx->frame_number, buf_size);
+ s->flags = avctx->flags;
+ s->flags2 = avctx->flags2;
/* no supplementary picture */
if (buf_size == 0) {
@@ -691,30 +704,28 @@ static int rv10_decode_frame(AVCodecContext *avctx,
}
AVCodec ff_rv10_decoder = {
- "rv10",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_RV10,
- sizeof(MpegEncContext),
- rv10_decode_init,
- NULL,
- rv10_decode_end,
- rv10_decode_frame,
- CODEC_CAP_DR1,
+ .name = "rv10",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_RV10,
+ .priv_data_size = sizeof(MpegEncContext),
+ .init = rv10_decode_init,
+ .close = rv10_decode_end,
+ .decode = rv10_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.max_lowres = 3,
.long_name = NULL_IF_CONFIG_SMALL("RealVideo 1.0"),
.pix_fmts= ff_pixfmt_list_420,
};
AVCodec ff_rv20_decoder = {
- "rv20",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_RV20,
- sizeof(MpegEncContext),
- rv10_decode_init,
- NULL,
- rv10_decode_end,
- rv10_decode_frame,
- CODEC_CAP_DR1 | CODEC_CAP_DELAY,
+ .name = "rv20",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_RV20,
+ .priv_data_size = sizeof(MpegEncContext),
+ .init = rv10_decode_init,
+ .close = rv10_decode_end,
+ .decode = rv10_decode_frame,
+ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY,
.flush= ff_mpeg_flush,
.max_lowres = 3,
.long_name = NULL_IF_CONFIG_SMALL("RealVideo 2.0"),
diff --git a/libavcodec/rv10enc.c b/libavcodec/rv10enc.c
index 1cb36fd223..8dd74e844e 100644
--- a/libavcodec/rv10enc.c
+++ b/libavcodec/rv10enc.c
@@ -3,20 +3,20 @@
* Copyright (c) 2000,2001 Fabrice Bellard
* Copyright (c) 2002-2004 Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -32,7 +32,7 @@ void rv10_encode_picture_header(MpegEncContext *s, int picture_number)
{
int full_frame= 0;
- align_put_bits(&s->pb);
+ avpriv_align_put_bits(&s->pb);
put_bits(&s->pb, 1, 1); /* marker */
@@ -57,13 +57,13 @@ void rv10_encode_picture_header(MpegEncContext *s, int picture_number)
}
AVCodec ff_rv10_encoder = {
- "rv10",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_RV10,
- sizeof(MpegEncContext),
- MPV_encode_init,
- MPV_encode_picture,
- MPV_encode_end,
+ .name = "rv10",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_RV10,
+ .priv_data_size = sizeof(MpegEncContext),
+ .init = MPV_encode_init,
+ .encode = MPV_encode_picture,
+ .close = MPV_encode_end,
.pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
.long_name= NULL_IF_CONFIG_SMALL("RealVideo 1.0"),
};
diff --git a/libavcodec/rv20enc.c b/libavcodec/rv20enc.c
index 8eba76b1a2..af7ef6bb72 100644
--- a/libavcodec/rv20enc.c
+++ b/libavcodec/rv20enc.c
@@ -3,20 +3,20 @@
* Copyright (c) 2000,2001 Fabrice Bellard
* Copyright (c) 2002-2004 Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -58,13 +58,13 @@ void rv20_encode_picture_header(MpegEncContext *s, int picture_number){
}
AVCodec ff_rv20_encoder = {
- "rv20",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_RV20,
- sizeof(MpegEncContext),
- MPV_encode_init,
- MPV_encode_picture,
- MPV_encode_end,
+ .name = "rv20",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_RV20,
+ .priv_data_size = sizeof(MpegEncContext),
+ .init = MPV_encode_init,
+ .encode = MPV_encode_picture,
+ .close = MPV_encode_end,
.pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
.long_name= NULL_IF_CONFIG_SMALL("RealVideo 2.0"),
};
diff --git a/libavcodec/rv30.c b/libavcodec/rv30.c
index 62177dda78..6383771dab 100644
--- a/libavcodec/rv30.c
+++ b/libavcodec/rv30.c
@@ -2,20 +2,20 @@
* RV30 decoder
* Copyright (c) 2007 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -51,6 +51,11 @@ static int rv30_parse_slice_header(RV34DecContext *r, GetBitContext *gb, SliceIn
skip_bits1(gb);
si->pts = get_bits(gb, 13);
rpr = get_bits(gb, r->rpr);
+ if (r->s.avctx->extradata_size < 8 + rpr*2) {
+ av_log(r->s.avctx, AV_LOG_WARNING,
+ "Extradata does not contain selected resolution\n");
+ rpr = 0;
+ }
if(rpr){
w = r->s.avctx->extradata[6 + rpr*2] << 2;
h = r->s.avctx->extradata[7 + rpr*2] << 2;
@@ -74,7 +79,7 @@ static int rv30_decode_intra_types(RV34DecContext *r, GetBitContext *gb, int8_t
for(i = 0; i < 4; i++, dst += r->intra_types_stride - 4){
for(j = 0; j < 4; j+= 2){
int code = svq3_get_ue_golomb(gb) << 1;
- if(code >= 81*2){
+ if(code >= 81U*2U){
av_log(r->s.avctx, AV_LOG_ERROR, "Incorrect intra prediction code\n");
return -1;
}
@@ -103,7 +108,7 @@ static int rv30_decode_mb_info(RV34DecContext *r)
GetBitContext *gb = &s->gb;
int code = svq3_get_ue_golomb(gb);
- if(code > 11){
+ if(code > 11U){
av_log(s->avctx, AV_LOG_ERROR, "Incorrect MB type code\n");
return -1;
}
@@ -142,7 +147,7 @@ static void rv30_loop_filter(RV34DecContext *r, int row)
mb_pos = row * s->mb_stride;
for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){
- int mbtype = s->current_picture_ptr->mb_type[mb_pos];
+ int mbtype = s->current_picture_ptr->f.mb_type[mb_pos];
if(IS_INTRA(mbtype) || IS_SEPARATE_DC(mbtype))
r->deblock_coefs[mb_pos] = 0xFFFF;
if(IS_INTRA(mbtype))
@@ -154,11 +159,11 @@ static void rv30_loop_filter(RV34DecContext *r, int row)
*/
mb_pos = row * s->mb_stride;
for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){
- cur_lim = rv30_loop_filt_lim[s->current_picture_ptr->qscale_table[mb_pos]];
+ cur_lim = rv30_loop_filt_lim[s->current_picture_ptr->f.qscale_table[mb_pos]];
if(mb_x)
- left_lim = rv30_loop_filt_lim[s->current_picture_ptr->qscale_table[mb_pos - 1]];
+ left_lim = rv30_loop_filt_lim[s->current_picture_ptr->f.qscale_table[mb_pos - 1]];
for(j = 0; j < 16; j += 4){
- Y = s->current_picture_ptr->data[0] + mb_x*16 + (row*16 + j) * s->linesize + 4 * !mb_x;
+ Y = s->current_picture_ptr->f.data[0] + mb_x*16 + (row*16 + j) * s->linesize + 4 * !mb_x;
for(i = !mb_x; i < 4; i++, Y += 4){
int ij = i + j;
loc_lim = 0;
@@ -178,7 +183,7 @@ static void rv30_loop_filter(RV34DecContext *r, int row)
if(mb_x)
left_cbp = (r->cbp_chroma[mb_pos - 1] >> (k*4)) & 0xF;
for(j = 0; j < 8; j += 4){
- C = s->current_picture_ptr->data[k+1] + mb_x*8 + (row*8 + j) * s->uvlinesize + 4 * !mb_x;
+ C = s->current_picture_ptr->f.data[k + 1] + mb_x*8 + (row*8 + j) * s->uvlinesize + 4 * !mb_x;
for(i = !mb_x; i < 2; i++, C += 4){
int ij = i + (j >> 1);
loc_lim = 0;
@@ -196,11 +201,11 @@ static void rv30_loop_filter(RV34DecContext *r, int row)
}
mb_pos = row * s->mb_stride;
for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){
- cur_lim = rv30_loop_filt_lim[s->current_picture_ptr->qscale_table[mb_pos]];
+ cur_lim = rv30_loop_filt_lim[s->current_picture_ptr->f.qscale_table[mb_pos]];
if(row)
- top_lim = rv30_loop_filt_lim[s->current_picture_ptr->qscale_table[mb_pos - s->mb_stride]];
+ top_lim = rv30_loop_filt_lim[s->current_picture_ptr->f.qscale_table[mb_pos - s->mb_stride]];
for(j = 4*!row; j < 16; j += 4){
- Y = s->current_picture_ptr->data[0] + mb_x*16 + (row*16 + j) * s->linesize;
+ Y = s->current_picture_ptr->f.data[0] + mb_x*16 + (row*16 + j) * s->linesize;
for(i = 0; i < 4; i++, Y += 4){
int ij = i + j;
loc_lim = 0;
@@ -220,7 +225,7 @@ static void rv30_loop_filter(RV34DecContext *r, int row)
if(row)
top_cbp = (r->cbp_chroma[mb_pos - s->mb_stride] >> (k*4)) & 0xF;
for(j = 4*!row; j < 8; j += 4){
- C = s->current_picture_ptr->data[k+1] + mb_x*8 + (row*8 + j) * s->uvlinesize;
+ C = s->current_picture_ptr->f.data[k+1] + mb_x*8 + (row*8 + j) * s->uvlinesize;
for(i = 0; i < 2; i++, C += 4){
int ij = i + (j >> 1);
loc_lim = 0;
@@ -267,16 +272,15 @@ static av_cold int rv30_decode_init(AVCodecContext *avctx)
}
AVCodec ff_rv30_decoder = {
- "rv30",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_RV30,
- sizeof(RV34DecContext),
- rv30_decode_init,
- NULL,
- ff_rv34_decode_end,
- ff_rv34_decode_frame,
- CODEC_CAP_DR1 | CODEC_CAP_DELAY,
- .flush = ff_mpeg_flush,
- .long_name = NULL_IF_CONFIG_SMALL("RealVideo 3.0"),
- .pix_fmts= ff_pixfmt_list_420,
+ .name = "rv30",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_RV30,
+ .priv_data_size = sizeof(RV34DecContext),
+ .init = rv30_decode_init,
+ .close = ff_rv34_decode_end,
+ .decode = ff_rv34_decode_frame,
+ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY,
+ .flush = ff_mpeg_flush,
+ .long_name = NULL_IF_CONFIG_SMALL("RealVideo 3.0"),
+ .pix_fmts = ff_pixfmt_list_420,
};
diff --git a/libavcodec/rv30data.h b/libavcodec/rv30data.h
index 5ee304802c..9cc48a6a31 100644
--- a/libavcodec/rv30data.h
+++ b/libavcodec/rv30data.h
@@ -2,20 +2,20 @@
* RealVideo 3 decoder
* copyright (c) 2007 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/rv30dsp.c b/libavcodec/rv30dsp.c
index c6e0614827..83439600ce 100644
--- a/libavcodec/rv30dsp.c
+++ b/libavcodec/rv30dsp.c
@@ -2,20 +2,20 @@
* RV30 decoder motion compensation functions
* Copyright (c) 2007 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -26,13 +26,14 @@
#include "avcodec.h"
#include "dsputil.h"
+#include "rv34dsp.h"
#define RV30_LOWPASS(OPNAME, OP) \
static av_unused void OPNAME ## rv30_tpel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, const int C1, const int C2){\
- const int h=8;\
+ const int h = 8;\
uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
int i;\
- for(i=0; i<h; i++)\
+ for(i = 0; i < h; i++)\
{\
OP(dst[0], (-(src[-1]+src[2]) + src[0]*C1 + src[1]*C2 + 8)>>4);\
OP(dst[1], (-(src[ 0]+src[3]) + src[1]*C1 + src[2]*C2 + 8)>>4);\
@@ -42,28 +43,28 @@ static av_unused void OPNAME ## rv30_tpel8_h_lowpass(uint8_t *dst, uint8_t *src,
OP(dst[5], (-(src[ 4]+src[7]) + src[5]*C1 + src[6]*C2 + 8)>>4);\
OP(dst[6], (-(src[ 5]+src[8]) + src[6]*C1 + src[7]*C2 + 8)>>4);\
OP(dst[7], (-(src[ 6]+src[9]) + src[7]*C1 + src[8]*C2 + 8)>>4);\
- dst+=dstStride;\
- src+=srcStride;\
+ dst += dstStride;\
+ src += srcStride;\
}\
}\
\
static void OPNAME ## rv30_tpel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, const int C1, const int C2){\
- const int w=8;\
+ const int w = 8;\
uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
int i;\
- for(i=0; i<w; i++)\
+ for(i = 0; i < w; i++)\
{\
- const int srcA= src[-1*srcStride];\
- const int src0= src[0 *srcStride];\
- const int src1= src[1 *srcStride];\
- const int src2= src[2 *srcStride];\
- const int src3= src[3 *srcStride];\
- const int src4= src[4 *srcStride];\
- const int src5= src[5 *srcStride];\
- const int src6= src[6 *srcStride];\
- const int src7= src[7 *srcStride];\
- const int src8= src[8 *srcStride];\
- const int src9= src[9 *srcStride];\
+ const int srcA = src[-1*srcStride];\
+ const int src0 = src[0 *srcStride];\
+ const int src1 = src[1 *srcStride];\
+ const int src2 = src[2 *srcStride];\
+ const int src3 = src[3 *srcStride];\
+ const int src4 = src[4 *srcStride];\
+ const int src5 = src[5 *srcStride];\
+ const int src6 = src[6 *srcStride];\
+ const int src7 = src[7 *srcStride];\
+ const int src8 = src[8 *srcStride];\
+ const int src9 = src[9 *srcStride];\
OP(dst[0*dstStride], (-(srcA+src2) + src0*C1 + src1*C2 + 8)>>4);\
OP(dst[1*dstStride], (-(src0+src3) + src1*C1 + src2*C2 + 8)>>4);\
OP(dst[2*dstStride], (-(src1+src4) + src2*C1 + src3*C2 + 8)>>4);\
@@ -251,41 +252,49 @@ RV30_MC(put_, 16)
RV30_MC(avg_, 8)
RV30_MC(avg_, 16)
-av_cold void ff_rv30dsp_init(DSPContext* c, AVCodecContext *avctx) {
- c->put_rv30_tpel_pixels_tab[0][ 0] = c->put_h264_qpel_pixels_tab[0][0];
- c->put_rv30_tpel_pixels_tab[0][ 1] = put_rv30_tpel16_mc10_c;
- c->put_rv30_tpel_pixels_tab[0][ 2] = put_rv30_tpel16_mc20_c;
- c->put_rv30_tpel_pixels_tab[0][ 4] = put_rv30_tpel16_mc01_c;
- c->put_rv30_tpel_pixels_tab[0][ 5] = put_rv30_tpel16_mc11_c;
- c->put_rv30_tpel_pixels_tab[0][ 6] = put_rv30_tpel16_mc21_c;
- c->put_rv30_tpel_pixels_tab[0][ 8] = put_rv30_tpel16_mc02_c;
- c->put_rv30_tpel_pixels_tab[0][ 9] = put_rv30_tpel16_mc12_c;
- c->put_rv30_tpel_pixels_tab[0][10] = put_rv30_tpel16_mc22_c;
- c->avg_rv30_tpel_pixels_tab[0][ 0] = c->avg_h264_qpel_pixels_tab[0][0];
- c->avg_rv30_tpel_pixels_tab[0][ 1] = avg_rv30_tpel16_mc10_c;
- c->avg_rv30_tpel_pixels_tab[0][ 2] = avg_rv30_tpel16_mc20_c;
- c->avg_rv30_tpel_pixels_tab[0][ 4] = avg_rv30_tpel16_mc01_c;
- c->avg_rv30_tpel_pixels_tab[0][ 5] = avg_rv30_tpel16_mc11_c;
- c->avg_rv30_tpel_pixels_tab[0][ 6] = avg_rv30_tpel16_mc21_c;
- c->avg_rv30_tpel_pixels_tab[0][ 8] = avg_rv30_tpel16_mc02_c;
- c->avg_rv30_tpel_pixels_tab[0][ 9] = avg_rv30_tpel16_mc12_c;
- c->avg_rv30_tpel_pixels_tab[0][10] = avg_rv30_tpel16_mc22_c;
- c->put_rv30_tpel_pixels_tab[1][ 0] = c->put_h264_qpel_pixels_tab[1][0];
- c->put_rv30_tpel_pixels_tab[1][ 1] = put_rv30_tpel8_mc10_c;
- c->put_rv30_tpel_pixels_tab[1][ 2] = put_rv30_tpel8_mc20_c;
- c->put_rv30_tpel_pixels_tab[1][ 4] = put_rv30_tpel8_mc01_c;
- c->put_rv30_tpel_pixels_tab[1][ 5] = put_rv30_tpel8_mc11_c;
- c->put_rv30_tpel_pixels_tab[1][ 6] = put_rv30_tpel8_mc21_c;
- c->put_rv30_tpel_pixels_tab[1][ 8] = put_rv30_tpel8_mc02_c;
- c->put_rv30_tpel_pixels_tab[1][ 9] = put_rv30_tpel8_mc12_c;
- c->put_rv30_tpel_pixels_tab[1][10] = put_rv30_tpel8_mc22_c;
- c->avg_rv30_tpel_pixels_tab[1][ 0] = c->avg_h264_qpel_pixels_tab[1][0];
- c->avg_rv30_tpel_pixels_tab[1][ 1] = avg_rv30_tpel8_mc10_c;
- c->avg_rv30_tpel_pixels_tab[1][ 2] = avg_rv30_tpel8_mc20_c;
- c->avg_rv30_tpel_pixels_tab[1][ 4] = avg_rv30_tpel8_mc01_c;
- c->avg_rv30_tpel_pixels_tab[1][ 5] = avg_rv30_tpel8_mc11_c;
- c->avg_rv30_tpel_pixels_tab[1][ 6] = avg_rv30_tpel8_mc21_c;
- c->avg_rv30_tpel_pixels_tab[1][ 8] = avg_rv30_tpel8_mc02_c;
- c->avg_rv30_tpel_pixels_tab[1][ 9] = avg_rv30_tpel8_mc12_c;
- c->avg_rv30_tpel_pixels_tab[1][10] = avg_rv30_tpel8_mc22_c;
+av_cold void ff_rv30dsp_init(RV34DSPContext *c, DSPContext* dsp) {
+
+ ff_rv34dsp_init(c, dsp);
+
+ c->put_pixels_tab[0][ 0] = dsp->put_h264_qpel_pixels_tab[0][0];
+ c->put_pixels_tab[0][ 1] = put_rv30_tpel16_mc10_c;
+ c->put_pixels_tab[0][ 2] = put_rv30_tpel16_mc20_c;
+ c->put_pixels_tab[0][ 4] = put_rv30_tpel16_mc01_c;
+ c->put_pixels_tab[0][ 5] = put_rv30_tpel16_mc11_c;
+ c->put_pixels_tab[0][ 6] = put_rv30_tpel16_mc21_c;
+ c->put_pixels_tab[0][ 8] = put_rv30_tpel16_mc02_c;
+ c->put_pixels_tab[0][ 9] = put_rv30_tpel16_mc12_c;
+ c->put_pixels_tab[0][10] = put_rv30_tpel16_mc22_c;
+ c->avg_pixels_tab[0][ 0] = dsp->avg_h264_qpel_pixels_tab[0][0];
+ c->avg_pixels_tab[0][ 1] = avg_rv30_tpel16_mc10_c;
+ c->avg_pixels_tab[0][ 2] = avg_rv30_tpel16_mc20_c;
+ c->avg_pixels_tab[0][ 4] = avg_rv30_tpel16_mc01_c;
+ c->avg_pixels_tab[0][ 5] = avg_rv30_tpel16_mc11_c;
+ c->avg_pixels_tab[0][ 6] = avg_rv30_tpel16_mc21_c;
+ c->avg_pixels_tab[0][ 8] = avg_rv30_tpel16_mc02_c;
+ c->avg_pixels_tab[0][ 9] = avg_rv30_tpel16_mc12_c;
+ c->avg_pixels_tab[0][10] = avg_rv30_tpel16_mc22_c;
+ c->put_pixels_tab[1][ 0] = dsp->put_h264_qpel_pixels_tab[1][0];
+ c->put_pixels_tab[1][ 1] = put_rv30_tpel8_mc10_c;
+ c->put_pixels_tab[1][ 2] = put_rv30_tpel8_mc20_c;
+ c->put_pixels_tab[1][ 4] = put_rv30_tpel8_mc01_c;
+ c->put_pixels_tab[1][ 5] = put_rv30_tpel8_mc11_c;
+ c->put_pixels_tab[1][ 6] = put_rv30_tpel8_mc21_c;
+ c->put_pixels_tab[1][ 8] = put_rv30_tpel8_mc02_c;
+ c->put_pixels_tab[1][ 9] = put_rv30_tpel8_mc12_c;
+ c->put_pixels_tab[1][10] = put_rv30_tpel8_mc22_c;
+ c->avg_pixels_tab[1][ 0] = dsp->avg_h264_qpel_pixels_tab[1][0];
+ c->avg_pixels_tab[1][ 1] = avg_rv30_tpel8_mc10_c;
+ c->avg_pixels_tab[1][ 2] = avg_rv30_tpel8_mc20_c;
+ c->avg_pixels_tab[1][ 4] = avg_rv30_tpel8_mc01_c;
+ c->avg_pixels_tab[1][ 5] = avg_rv30_tpel8_mc11_c;
+ c->avg_pixels_tab[1][ 6] = avg_rv30_tpel8_mc21_c;
+ c->avg_pixels_tab[1][ 8] = avg_rv30_tpel8_mc02_c;
+ c->avg_pixels_tab[1][ 9] = avg_rv30_tpel8_mc12_c;
+ c->avg_pixels_tab[1][10] = avg_rv30_tpel8_mc22_c;
+
+ c->put_chroma_pixels_tab[0] = dsp->put_h264_chroma_pixels_tab[0];
+ c->put_chroma_pixels_tab[1] = dsp->put_h264_chroma_pixels_tab[1];
+ c->avg_chroma_pixels_tab[0] = dsp->avg_h264_chroma_pixels_tab[0];
+ c->avg_chroma_pixels_tab[1] = dsp->avg_h264_chroma_pixels_tab[1];
}
diff --git a/libavcodec/rv34.c b/libavcodec/rv34.c
index 98607ea7ff..7df6a61eb9 100644
--- a/libavcodec/rv34.c
+++ b/libavcodec/rv34.c
@@ -2,20 +2,20 @@
* RV30/40 decoder common data
* Copyright (c) 2007 Mike Melanson, Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -171,82 +171,6 @@ static av_cold void rv34_init_tables(void)
/** @} */ // vlc group
-
-/**
- * @name RV30/40 inverse transform functions
- * @{
- */
-
-static av_always_inline void rv34_row_transform(int temp[16], DCTELEM *block)
-{
- int i;
-
- for(i=0; i<4; i++){
- const int z0= 13*(block[i+8*0] + block[i+8*2]);
- const int z1= 13*(block[i+8*0] - block[i+8*2]);
- const int z2= 7* block[i+8*1] - 17*block[i+8*3];
- const int z3= 17* block[i+8*1] + 7*block[i+8*3];
-
- temp[4*i+0]= z0+z3;
- temp[4*i+1]= z1+z2;
- temp[4*i+2]= z1-z2;
- temp[4*i+3]= z0-z3;
- }
-}
-
-/**
- * Real Video 3.0/4.0 inverse transform
- * Code is almost the same as in SVQ3, only scaling is different.
- */
-static void rv34_inv_transform(DCTELEM *block){
- int temp[16];
- int i;
-
- rv34_row_transform(temp, block);
-
- for(i=0; i<4; i++){
- const int z0= 13*(temp[4*0+i] + temp[4*2+i]) + 0x200;
- const int z1= 13*(temp[4*0+i] - temp[4*2+i]) + 0x200;
- const int z2= 7* temp[4*1+i] - 17*temp[4*3+i];
- const int z3= 17* temp[4*1+i] + 7*temp[4*3+i];
-
- block[i*8+0]= (z0 + z3)>>10;
- block[i*8+1]= (z1 + z2)>>10;
- block[i*8+2]= (z1 - z2)>>10;
- block[i*8+3]= (z0 - z3)>>10;
- }
-
-}
-
-/**
- * RealVideo 3.0/4.0 inverse transform for DC block
- *
- * Code is almost the same as rv34_inv_transform()
- * but final coefficients are multiplied by 1.5 and have no rounding.
- */
-static void rv34_inv_transform_noround(DCTELEM *block){
- int temp[16];
- int i;
-
- rv34_row_transform(temp, block);
-
- for(i=0; i<4; i++){
- const int z0= 13*(temp[4*0+i] + temp[4*2+i]);
- const int z1= 13*(temp[4*0+i] - temp[4*2+i]);
- const int z2= 7* temp[4*1+i] - 17*temp[4*3+i];
- const int z3= 17* temp[4*1+i] + 7*temp[4*3+i];
-
- block[i*8+0]= ((z0 + z3)*3)>>11;
- block[i*8+1]= ((z1 + z2)*3)>>11;
- block[i*8+2]= ((z1 - z2)*3)>>11;
- block[i*8+3]= ((z0 - z3)*3)>>11;
- }
-
-}
-
-/** @} */ // transform
-
-
/**
* @name RV30/40 4x4 block decoding functions
* @{
@@ -439,13 +363,13 @@ static int rv34_decode_mb_header(RV34DecContext *r, int8_t *intra_types)
if(!get_bits1(gb))
av_log(s->avctx, AV_LOG_ERROR, "Need DQUANT\n");
}
- s->current_picture_ptr->mb_type[mb_pos] = r->is16 ? MB_TYPE_INTRA16x16 : MB_TYPE_INTRA;
+ s->current_picture_ptr->f.mb_type[mb_pos] = r->is16 ? MB_TYPE_INTRA16x16 : MB_TYPE_INTRA;
r->block_type = r->is16 ? RV34_MB_TYPE_INTRA16x16 : RV34_MB_TYPE_INTRA;
}else{
r->block_type = r->decode_mb_info(r);
if(r->block_type == -1)
return -1;
- s->current_picture_ptr->mb_type[mb_pos] = rv34_mb_type_to_lavc[r->block_type];
+ s->current_picture_ptr->f.mb_type[mb_pos] = rv34_mb_type_to_lavc[r->block_type];
r->mb_type[mb_pos] = r->block_type;
if(r->block_type == RV34_MB_SKIP){
if(s->pict_type == AV_PICTURE_TYPE_P)
@@ -453,7 +377,7 @@ static int rv34_decode_mb_header(RV34DecContext *r, int8_t *intra_types)
if(s->pict_type == AV_PICTURE_TYPE_B)
r->mb_type[mb_pos] = RV34_MB_B_DIRECT;
}
- r->is16 = !!IS_INTRA16x16(s->current_picture_ptr->mb_type[mb_pos]);
+ r->is16 = !!IS_INTRA16x16(s->current_picture_ptr->f.mb_type[mb_pos]);
rv34_decode_mv(r, r->block_type);
if(r->block_type == RV34_MB_SKIP){
fill_rectangle(intra_types, 4, 4, r->intra_types_stride, 0, sizeof(intra_types[0]));
@@ -462,7 +386,7 @@ static int rv34_decode_mb_header(RV34DecContext *r, int8_t *intra_types)
r->chroma_vlc = 1;
r->luma_vlc = 0;
}
- if(IS_INTRA(s->current_picture_ptr->mb_type[mb_pos])){
+ if(IS_INTRA(s->current_picture_ptr->f.mb_type[mb_pos])){
if(r->is16){
t = get_bits(gb, 2);
fill_rectangle(intra_types, 4, 4, r->intra_types_stride, t, sizeof(intra_types[0]));
@@ -527,27 +451,27 @@ static void rv34_pred_mv(RV34DecContext *r, int block_type, int subblock_no, int
c_off = -1;
if(r->avail_cache[avail_index - 1]){
- A[0] = s->current_picture_ptr->motion_val[0][mv_pos-1][0];
- A[1] = s->current_picture_ptr->motion_val[0][mv_pos-1][1];
+ A[0] = s->current_picture_ptr->f.motion_val[0][mv_pos-1][0];
+ A[1] = s->current_picture_ptr->f.motion_val[0][mv_pos-1][1];
}
if(r->avail_cache[avail_index - 4]){
- B[0] = s->current_picture_ptr->motion_val[0][mv_pos-s->b8_stride][0];
- B[1] = s->current_picture_ptr->motion_val[0][mv_pos-s->b8_stride][1];
+ B[0] = s->current_picture_ptr->f.motion_val[0][mv_pos-s->b8_stride][0];
+ B[1] = s->current_picture_ptr->f.motion_val[0][mv_pos-s->b8_stride][1];
}else{
B[0] = A[0];
B[1] = A[1];
}
if(!r->avail_cache[avail_index - 4 + c_off]){
if(r->avail_cache[avail_index - 4] && (r->avail_cache[avail_index - 1] || r->rv30)){
- C[0] = s->current_picture_ptr->motion_val[0][mv_pos-s->b8_stride-1][0];
- C[1] = s->current_picture_ptr->motion_val[0][mv_pos-s->b8_stride-1][1];
+ C[0] = s->current_picture_ptr->f.motion_val[0][mv_pos-s->b8_stride-1][0];
+ C[1] = s->current_picture_ptr->f.motion_val[0][mv_pos-s->b8_stride-1][1];
}else{
C[0] = A[0];
C[1] = A[1];
}
}else{
- C[0] = s->current_picture_ptr->motion_val[0][mv_pos-s->b8_stride+c_off][0];
- C[1] = s->current_picture_ptr->motion_val[0][mv_pos-s->b8_stride+c_off][1];
+ C[0] = s->current_picture_ptr->f.motion_val[0][mv_pos-s->b8_stride+c_off][0];
+ C[1] = s->current_picture_ptr->f.motion_val[0][mv_pos-s->b8_stride+c_off][1];
}
mx = mid_pred(A[0], B[0], C[0]);
my = mid_pred(A[1], B[1], C[1]);
@@ -555,8 +479,8 @@ static void rv34_pred_mv(RV34DecContext *r, int block_type, int subblock_no, int
my += r->dmv[dmv_no][1];
for(j = 0; j < part_sizes_h[block_type]; j++){
for(i = 0; i < part_sizes_w[block_type]; i++){
- s->current_picture_ptr->motion_val[0][mv_pos + i + j*s->b8_stride][0] = mx;
- s->current_picture_ptr->motion_val[0][mv_pos + i + j*s->b8_stride][1] = my;
+ s->current_picture_ptr->f.motion_val[0][mv_pos + i + j*s->b8_stride][0] = mx;
+ s->current_picture_ptr->f.motion_val[0][mv_pos + i + j*s->b8_stride][1] = my;
}
}
}
@@ -568,12 +492,8 @@ static void rv34_pred_mv(RV34DecContext *r, int block_type, int subblock_no, int
*/
static int calc_add_mv(RV34DecContext *r, int dir, int val)
{
- int refdist = GET_PTS_DIFF(r->next_pts, r->last_pts);
- int dist = dir ? -GET_PTS_DIFF(r->next_pts, r->cur_pts) : GET_PTS_DIFF(r->cur_pts, r->last_pts);
- int mul;
+ int mul = dir ? -r->weight2 : r->weight1;
- if(!refdist) return 0;
- mul = (dist << 14) / refdist;
return (val * mul + 0x2000) >> 14;
}
@@ -611,28 +531,28 @@ static void rv34_pred_mv_b(RV34DecContext *r, int block_type, int dir)
int i, j;
Picture *cur_pic = s->current_picture_ptr;
const int mask = dir ? MB_TYPE_L1 : MB_TYPE_L0;
- int type = cur_pic->mb_type[mb_pos];
+ int type = cur_pic->f.mb_type[mb_pos];
memset(A, 0, sizeof(A));
memset(B, 0, sizeof(B));
memset(C, 0, sizeof(C));
if((r->avail_cache[6-1] & type) & mask){
- A[0] = cur_pic->motion_val[dir][mv_pos - 1][0];
- A[1] = cur_pic->motion_val[dir][mv_pos - 1][1];
+ A[0] = cur_pic->f.motion_val[dir][mv_pos - 1][0];
+ A[1] = cur_pic->f.motion_val[dir][mv_pos - 1][1];
has_A = 1;
}
if((r->avail_cache[6-4] & type) & mask){
- B[0] = cur_pic->motion_val[dir][mv_pos - s->b8_stride][0];
- B[1] = cur_pic->motion_val[dir][mv_pos - s->b8_stride][1];
+ B[0] = cur_pic->f.motion_val[dir][mv_pos - s->b8_stride][0];
+ B[1] = cur_pic->f.motion_val[dir][mv_pos - s->b8_stride][1];
has_B = 1;
}
if(r->avail_cache[6-4] && (r->avail_cache[6-2] & type) & mask){
- C[0] = cur_pic->motion_val[dir][mv_pos - s->b8_stride + 2][0];
- C[1] = cur_pic->motion_val[dir][mv_pos - s->b8_stride + 2][1];
+ C[0] = cur_pic->f.motion_val[dir][mv_pos - s->b8_stride + 2][0];
+ C[1] = cur_pic->f.motion_val[dir][mv_pos - s->b8_stride + 2][1];
has_C = 1;
}else if((s->mb_x+1) == s->mb_width && (r->avail_cache[6-5] & type) & mask){
- C[0] = cur_pic->motion_val[dir][mv_pos - s->b8_stride - 1][0];
- C[1] = cur_pic->motion_val[dir][mv_pos - s->b8_stride - 1][1];
+ C[0] = cur_pic->f.motion_val[dir][mv_pos - s->b8_stride - 1][0];
+ C[1] = cur_pic->f.motion_val[dir][mv_pos - s->b8_stride - 1][1];
has_C = 1;
}
@@ -643,12 +563,12 @@ static void rv34_pred_mv_b(RV34DecContext *r, int block_type, int dir)
for(j = 0; j < 2; j++){
for(i = 0; i < 2; i++){
- cur_pic->motion_val[dir][mv_pos + i + j*s->b8_stride][0] = mx;
- cur_pic->motion_val[dir][mv_pos + i + j*s->b8_stride][1] = my;
+ cur_pic->f.motion_val[dir][mv_pos + i + j*s->b8_stride][0] = mx;
+ cur_pic->f.motion_val[dir][mv_pos + i + j*s->b8_stride][1] = my;
}
}
if(block_type == RV34_MB_B_BACKWARD || block_type == RV34_MB_B_FORWARD){
- ZERO8x2(cur_pic->motion_val[!dir][mv_pos], s->b8_stride);
+ ZERO8x2(cur_pic->f.motion_val[!dir][mv_pos], s->b8_stride);
}
}
@@ -665,27 +585,27 @@ static void rv34_pred_mv_rv3(RV34DecContext *r, int block_type, int dir)
int avail_index = avail_indexes[0];
if(r->avail_cache[avail_index - 1]){
- A[0] = s->current_picture_ptr->motion_val[0][mv_pos-1][0];
- A[1] = s->current_picture_ptr->motion_val[0][mv_pos-1][1];
+ A[0] = s->current_picture_ptr->f.motion_val[0][mv_pos - 1][0];
+ A[1] = s->current_picture_ptr->f.motion_val[0][mv_pos - 1][1];
}
if(r->avail_cache[avail_index - 4]){
- B[0] = s->current_picture_ptr->motion_val[0][mv_pos-s->b8_stride][0];
- B[1] = s->current_picture_ptr->motion_val[0][mv_pos-s->b8_stride][1];
+ B[0] = s->current_picture_ptr->f.motion_val[0][mv_pos - s->b8_stride][0];
+ B[1] = s->current_picture_ptr->f.motion_val[0][mv_pos - s->b8_stride][1];
}else{
B[0] = A[0];
B[1] = A[1];
}
if(!r->avail_cache[avail_index - 4 + 2]){
if(r->avail_cache[avail_index - 4] && (r->avail_cache[avail_index - 1])){
- C[0] = s->current_picture_ptr->motion_val[0][mv_pos-s->b8_stride-1][0];
- C[1] = s->current_picture_ptr->motion_val[0][mv_pos-s->b8_stride-1][1];
+ C[0] = s->current_picture_ptr->f.motion_val[0][mv_pos - s->b8_stride - 1][0];
+ C[1] = s->current_picture_ptr->f.motion_val[0][mv_pos - s->b8_stride - 1][1];
}else{
C[0] = A[0];
C[1] = A[1];
}
}else{
- C[0] = s->current_picture_ptr->motion_val[0][mv_pos-s->b8_stride+2][0];
- C[1] = s->current_picture_ptr->motion_val[0][mv_pos-s->b8_stride+2][1];
+ C[0] = s->current_picture_ptr->f.motion_val[0][mv_pos - s->b8_stride + 2][0];
+ C[1] = s->current_picture_ptr->f.motion_val[0][mv_pos - s->b8_stride + 2][1];
}
mx = mid_pred(A[0], B[0], C[0]);
my = mid_pred(A[1], B[1], C[1]);
@@ -694,8 +614,8 @@ static void rv34_pred_mv_rv3(RV34DecContext *r, int block_type, int dir)
for(j = 0; j < 2; j++){
for(i = 0; i < 2; i++){
for(k = 0; k < 2; k++){
- s->current_picture_ptr->motion_val[k][mv_pos + i + j*s->b8_stride][0] = mx;
- s->current_picture_ptr->motion_val[k][mv_pos + i + j*s->b8_stride][1] = my;
+ s->current_picture_ptr->f.motion_val[k][mv_pos + i + j*s->b8_stride][0] = mx;
+ s->current_picture_ptr->f.motion_val[k][mv_pos + i + j*s->b8_stride][1] = my;
}
}
}
@@ -721,7 +641,7 @@ static const int chroma_coeffs[3] = { 0, 3, 5 };
static inline void rv34_mc(RV34DecContext *r, const int block_type,
const int xoff, const int yoff, int mv_off,
const int width, const int height, int dir,
- const int thirdpel,
+ const int thirdpel, int weighted,
qpel_mc_func (*qpel_mc)[16],
h264_chroma_mc_func (*chroma_mc))
{
@@ -733,24 +653,24 @@ static inline void rv34_mc(RV34DecContext *r, const int block_type,
if(thirdpel){
int chroma_mx, chroma_my;
- mx = (s->current_picture_ptr->motion_val[dir][mv_pos][0] + (3 << 24)) / 3 - (1 << 24);
- my = (s->current_picture_ptr->motion_val[dir][mv_pos][1] + (3 << 24)) / 3 - (1 << 24);
- lx = (s->current_picture_ptr->motion_val[dir][mv_pos][0] + (3 << 24)) % 3;
- ly = (s->current_picture_ptr->motion_val[dir][mv_pos][1] + (3 << 24)) % 3;
- chroma_mx = (s->current_picture_ptr->motion_val[dir][mv_pos][0] + 1) >> 1;
- chroma_my = (s->current_picture_ptr->motion_val[dir][mv_pos][1] + 1) >> 1;
+ mx = (s->current_picture_ptr->f.motion_val[dir][mv_pos][0] + (3 << 24)) / 3 - (1 << 24);
+ my = (s->current_picture_ptr->f.motion_val[dir][mv_pos][1] + (3 << 24)) / 3 - (1 << 24);
+ lx = (s->current_picture_ptr->f.motion_val[dir][mv_pos][0] + (3 << 24)) % 3;
+ ly = (s->current_picture_ptr->f.motion_val[dir][mv_pos][1] + (3 << 24)) % 3;
+ chroma_mx = s->current_picture_ptr->f.motion_val[dir][mv_pos][0] / 2;
+ chroma_my = s->current_picture_ptr->f.motion_val[dir][mv_pos][1] / 2;
umx = (chroma_mx + (3 << 24)) / 3 - (1 << 24);
umy = (chroma_my + (3 << 24)) / 3 - (1 << 24);
uvmx = chroma_coeffs[(chroma_mx + (3 << 24)) % 3];
uvmy = chroma_coeffs[(chroma_my + (3 << 24)) % 3];
}else{
int cx, cy;
- mx = s->current_picture_ptr->motion_val[dir][mv_pos][0] >> 2;
- my = s->current_picture_ptr->motion_val[dir][mv_pos][1] >> 2;
- lx = s->current_picture_ptr->motion_val[dir][mv_pos][0] & 3;
- ly = s->current_picture_ptr->motion_val[dir][mv_pos][1] & 3;
- cx = s->current_picture_ptr->motion_val[dir][mv_pos][0] / 2;
- cy = s->current_picture_ptr->motion_val[dir][mv_pos][1] / 2;
+ mx = s->current_picture_ptr->f.motion_val[dir][mv_pos][0] >> 2;
+ my = s->current_picture_ptr->f.motion_val[dir][mv_pos][1] >> 2;
+ lx = s->current_picture_ptr->f.motion_val[dir][mv_pos][0] & 3;
+ ly = s->current_picture_ptr->f.motion_val[dir][mv_pos][1] & 3;
+ cx = s->current_picture_ptr->f.motion_val[dir][mv_pos][0] / 2;
+ cy = s->current_picture_ptr->f.motion_val[dir][mv_pos][1] / 2;
umx = cx >> 2;
umy = cy >> 2;
uvmx = (cx & 3) << 1;
@@ -760,9 +680,9 @@ static inline void rv34_mc(RV34DecContext *r, const int block_type,
uvmx = uvmy = 4;
}
dxy = ly*4 + lx;
- srcY = dir ? s->next_picture_ptr->data[0] : s->last_picture_ptr->data[0];
- srcU = dir ? s->next_picture_ptr->data[1] : s->last_picture_ptr->data[1];
- srcV = dir ? s->next_picture_ptr->data[2] : s->last_picture_ptr->data[2];
+ srcY = dir ? s->next_picture_ptr->f.data[0] : s->last_picture_ptr->f.data[0];
+ srcU = dir ? s->next_picture_ptr->f.data[1] : s->last_picture_ptr->f.data[1];
+ srcV = dir ? s->next_picture_ptr->f.data[2] : s->last_picture_ptr->f.data[2];
src_x = s->mb_x * 16 + xoff + mx;
src_y = s->mb_y * 16 + yoff + my;
uvsrc_x = s->mb_x * 8 + (xoff >> 1) + umx;
@@ -772,7 +692,7 @@ static inline void rv34_mc(RV34DecContext *r, const int block_type,
srcV += uvsrc_y * s->uvlinesize + uvsrc_x;
if( (unsigned)(src_x - !!lx*2) > s->h_edge_pos - !!lx*2 - (width <<3) - 4
|| (unsigned)(src_y - !!ly*2) > s->v_edge_pos - !!ly*2 - (height<<3) - 4){
- uint8_t *uvbuf= s->edge_emu_buffer + 22 * s->linesize;
+ uint8_t *uvbuf = s->edge_emu_buffer + 22 * s->linesize;
srcY -= 2 + 2*s->linesize;
s->dsp.emulated_edge_mc(s->edge_emu_buffer, srcY, s->linesize, (width<<3)+6, (height<<3)+6,
@@ -785,9 +705,15 @@ static inline void rv34_mc(RV34DecContext *r, const int block_type,
srcU = uvbuf;
srcV = uvbuf + 16;
}
- Y = s->dest[0] + xoff + yoff *s->linesize;
- U = s->dest[1] + (xoff>>1) + (yoff>>1)*s->uvlinesize;
- V = s->dest[2] + (xoff>>1) + (yoff>>1)*s->uvlinesize;
+ if(!weighted){
+ Y = s->dest[0] + xoff + yoff *s->linesize;
+ U = s->dest[1] + (xoff>>1) + (yoff>>1)*s->uvlinesize;
+ V = s->dest[2] + (xoff>>1) + (yoff>>1)*s->uvlinesize;
+ }else{
+ Y = r->tmp_b_block_y [dir] + xoff + yoff *s->linesize;
+ U = r->tmp_b_block_uv[dir*2] + (xoff>>1) + (yoff>>1)*s->uvlinesize;
+ V = r->tmp_b_block_uv[dir*2+1] + (xoff>>1) + (yoff>>1)*s->uvlinesize;
+ }
if(block_type == RV34_MB_P_16x8){
qpel_mc[1][dxy](Y, srcY, s->linesize);
@@ -808,43 +734,70 @@ static void rv34_mc_1mv(RV34DecContext *r, const int block_type,
const int xoff, const int yoff, int mv_off,
const int width, const int height, int dir)
{
- rv34_mc(r, block_type, xoff, yoff, mv_off, width, height, dir, r->rv30,
- r->rv30 ? r->s.dsp.put_rv30_tpel_pixels_tab
- : r->s.dsp.put_rv40_qpel_pixels_tab,
- r->rv30 ? r->s.dsp.put_h264_chroma_pixels_tab
- : r->s.dsp.put_rv40_chroma_pixels_tab);
+ rv34_mc(r, block_type, xoff, yoff, mv_off, width, height, dir, r->rv30, 0,
+ r->rdsp.put_pixels_tab,
+ r->rdsp.put_chroma_pixels_tab);
+}
+
+static void rv4_weight(RV34DecContext *r)
+{
+ r->rdsp.rv40_weight_pixels_tab[0](r->s.dest[0],
+ r->tmp_b_block_y[0],
+ r->tmp_b_block_y[1],
+ r->weight1,
+ r->weight2,
+ r->s.linesize);
+ r->rdsp.rv40_weight_pixels_tab[1](r->s.dest[1],
+ r->tmp_b_block_uv[0],
+ r->tmp_b_block_uv[2],
+ r->weight1,
+ r->weight2,
+ r->s.uvlinesize);
+ r->rdsp.rv40_weight_pixels_tab[1](r->s.dest[2],
+ r->tmp_b_block_uv[1],
+ r->tmp_b_block_uv[3],
+ r->weight1,
+ r->weight2,
+ r->s.uvlinesize);
}
static void rv34_mc_2mv(RV34DecContext *r, const int block_type)
{
- rv34_mc(r, block_type, 0, 0, 0, 2, 2, 0, r->rv30,
- r->rv30 ? r->s.dsp.put_rv30_tpel_pixels_tab
- : r->s.dsp.put_rv40_qpel_pixels_tab,
- r->rv30 ? r->s.dsp.put_h264_chroma_pixels_tab
- : r->s.dsp.put_rv40_chroma_pixels_tab);
- rv34_mc(r, block_type, 0, 0, 0, 2, 2, 1, r->rv30,
- r->rv30 ? r->s.dsp.avg_rv30_tpel_pixels_tab
- : r->s.dsp.avg_rv40_qpel_pixels_tab,
- r->rv30 ? r->s.dsp.avg_h264_chroma_pixels_tab
- : r->s.dsp.avg_rv40_chroma_pixels_tab);
+ int weighted = !r->rv30 && block_type != RV34_MB_B_BIDIR && r->weight1 != 8192;
+
+ rv34_mc(r, block_type, 0, 0, 0, 2, 2, 0, r->rv30, weighted,
+ r->rdsp.put_pixels_tab,
+ r->rdsp.put_chroma_pixels_tab);
+ if(!weighted){
+ rv34_mc(r, block_type, 0, 0, 0, 2, 2, 1, r->rv30, 0,
+ r->rdsp.avg_pixels_tab,
+ r->rdsp.avg_chroma_pixels_tab);
+ }else{
+ rv34_mc(r, block_type, 0, 0, 0, 2, 2, 1, r->rv30, 1,
+ r->rdsp.put_pixels_tab,
+ r->rdsp.put_chroma_pixels_tab);
+ rv4_weight(r);
+ }
}
static void rv34_mc_2mv_skip(RV34DecContext *r)
{
int i, j;
+ int weighted = !r->rv30 && r->weight1 != 8192;
+
for(j = 0; j < 2; j++)
for(i = 0; i < 2; i++){
rv34_mc(r, RV34_MB_P_8x8, i*8, j*8, i+j*r->s.b8_stride, 1, 1, 0, r->rv30,
- r->rv30 ? r->s.dsp.put_rv30_tpel_pixels_tab
- : r->s.dsp.put_rv40_qpel_pixels_tab,
- r->rv30 ? r->s.dsp.put_h264_chroma_pixels_tab
- : r->s.dsp.put_rv40_chroma_pixels_tab);
+ weighted,
+ r->rdsp.put_pixels_tab,
+ r->rdsp.put_chroma_pixels_tab);
rv34_mc(r, RV34_MB_P_8x8, i*8, j*8, i+j*r->s.b8_stride, 1, 1, 1, r->rv30,
- r->rv30 ? r->s.dsp.avg_rv30_tpel_pixels_tab
- : r->s.dsp.avg_rv40_qpel_pixels_tab,
- r->rv30 ? r->s.dsp.avg_h264_chroma_pixels_tab
- : r->s.dsp.avg_rv40_chroma_pixels_tab);
+ weighted,
+ weighted ? r->rdsp.put_pixels_tab : r->rdsp.avg_pixels_tab,
+ weighted ? r->rdsp.put_chroma_pixels_tab : r->rdsp.avg_chroma_pixels_tab);
}
+ if(weighted)
+ rv4_weight(r);
}
/** number of motion vectors in each macroblock type */
@@ -870,31 +823,31 @@ static int rv34_decode_mv(RV34DecContext *r, int block_type)
switch(block_type){
case RV34_MB_TYPE_INTRA:
case RV34_MB_TYPE_INTRA16x16:
- ZERO8x2(s->current_picture_ptr->motion_val[0][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], s->b8_stride);
+ ZERO8x2(s->current_picture_ptr->f.motion_val[0][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], s->b8_stride);
return 0;
case RV34_MB_SKIP:
if(s->pict_type == AV_PICTURE_TYPE_P){
- ZERO8x2(s->current_picture_ptr->motion_val[0][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], s->b8_stride);
+ ZERO8x2(s->current_picture_ptr->f.motion_val[0][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], s->b8_stride);
rv34_mc_1mv (r, block_type, 0, 0, 0, 2, 2, 0);
break;
}
case RV34_MB_B_DIRECT:
//surprisingly, it uses motion scheme from next reference frame
- next_bt = s->next_picture_ptr->mb_type[s->mb_x + s->mb_y * s->mb_stride];
+ next_bt = s->next_picture_ptr->f.mb_type[s->mb_x + s->mb_y * s->mb_stride];
if(IS_INTRA(next_bt) || IS_SKIP(next_bt)){
- ZERO8x2(s->current_picture_ptr->motion_val[0][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], s->b8_stride);
- ZERO8x2(s->current_picture_ptr->motion_val[1][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], s->b8_stride);
+ ZERO8x2(s->current_picture_ptr->f.motion_val[0][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], s->b8_stride);
+ ZERO8x2(s->current_picture_ptr->f.motion_val[1][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], s->b8_stride);
}else
for(j = 0; j < 2; j++)
for(i = 0; i < 2; i++)
for(k = 0; k < 2; k++)
for(l = 0; l < 2; l++)
- s->current_picture_ptr->motion_val[l][mv_pos + i + j*s->b8_stride][k] = calc_add_mv(r, l, s->next_picture_ptr->motion_val[0][mv_pos + i + j*s->b8_stride][k]);
+ s->current_picture_ptr->f.motion_val[l][mv_pos + i + j*s->b8_stride][k] = calc_add_mv(r, l, s->next_picture_ptr->f.motion_val[0][mv_pos + i + j*s->b8_stride][k]);
if(!(IS_16X8(next_bt) || IS_8X16(next_bt) || IS_8X8(next_bt))) //we can use whole macroblock MC
rv34_mc_2mv(r, block_type);
else
rv34_mc_2mv_skip(r);
- ZERO8x2(s->current_picture_ptr->motion_val[0][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], s->b8_stride);
+ ZERO8x2(s->current_picture_ptr->f.motion_val[0][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], s->b8_stride);
break;
case RV34_MB_P_16x16:
case RV34_MB_P_MIX16x16:
@@ -1128,7 +1081,7 @@ static int rv34_set_deblock_coef(RV34DecContext *r)
MpegEncContext *s = &r->s;
int hmvmask = 0, vmvmask = 0, i, j;
int midx = s->mb_x * 2 + s->mb_y * 2 * s->b8_stride;
- int16_t (*motion_val)[2] = &s->current_picture_ptr->motion_val[0][midx];
+ int16_t (*motion_val)[2] = &s->current_picture_ptr->f.motion_val[0][midx];
for(j = 0; j < 16; j += 8){
for(i = 0; i < 2; i++){
if(is_mv_diff_gt_3(motion_val + i, 1))
@@ -1170,14 +1123,14 @@ static int rv34_decode_macroblock(RV34DecContext *r, int8_t *intra_types)
dist = (s->mb_x - s->resync_mb_x) + (s->mb_y - s->resync_mb_y) * s->mb_width;
if(s->mb_x && dist)
r->avail_cache[5] =
- r->avail_cache[9] = s->current_picture_ptr->mb_type[mb_pos - 1];
+ r->avail_cache[9] = s->current_picture_ptr->f.mb_type[mb_pos - 1];
if(dist >= s->mb_width)
r->avail_cache[2] =
- r->avail_cache[3] = s->current_picture_ptr->mb_type[mb_pos - s->mb_stride];
+ r->avail_cache[3] = s->current_picture_ptr->f.mb_type[mb_pos - s->mb_stride];
if(((s->mb_x+1) < s->mb_width) && dist >= s->mb_width - 1)
- r->avail_cache[4] = s->current_picture_ptr->mb_type[mb_pos - s->mb_stride + 1];
+ r->avail_cache[4] = s->current_picture_ptr->f.mb_type[mb_pos - s->mb_stride + 1];
if(s->mb_x && dist > s->mb_width)
- r->avail_cache[1] = s->current_picture_ptr->mb_type[mb_pos - s->mb_stride - 1];
+ r->avail_cache[1] = s->current_picture_ptr->f.mb_type[mb_pos - s->mb_stride - 1];
s->qscale = r->si.quant;
cbp = cbp2 = rv34_decode_mb_header(r, intra_types);
@@ -1187,7 +1140,7 @@ static int rv34_decode_macroblock(RV34DecContext *r, int8_t *intra_types)
r->deblock_coefs[mb_pos] = 0xFFFF;
else
r->deblock_coefs[mb_pos] = rv34_set_deblock_coef(r) | r->cbp_luma[mb_pos];
- s->current_picture_ptr->qscale_table[mb_pos] = s->qscale;
+ s->current_picture_ptr->f.qscale_table[mb_pos] = s->qscale;
if(cbp == -1)
return -1;
@@ -1197,7 +1150,7 @@ static int rv34_decode_macroblock(RV34DecContext *r, int8_t *intra_types)
memset(block16, 0, sizeof(block16));
rv34_decode_block(block16, gb, r->cur_vlcs, 3, 0);
rv34_dequant4x4_16x16(block16, rv34_qscale_tab[luma_dc_quant],rv34_qscale_tab[s->qscale]);
- rv34_inv_transform_noround(block16);
+ r->rdsp.rv34_inv_transform_tab[1](block16);
}
for(i = 0; i < 16; i++, cbp >>= 1){
@@ -1209,7 +1162,7 @@ static int rv34_decode_macroblock(RV34DecContext *r, int8_t *intra_types)
rv34_dequant4x4(s->block[blknum] + blkoff, rv34_qscale_tab[s->qscale],rv34_qscale_tab[s->qscale]);
if(r->is16) //FIXME: optimize
s->block[blknum][blkoff] = block16[(i & 3) | ((i & 0xC) << 1)];
- rv34_inv_transform(s->block[blknum] + blkoff);
+ r->rdsp.rv34_inv_transform_tab[0](s->block[blknum] + blkoff);
}
if(r->block_type == RV34_MB_P_MIX16x16)
r->cur_vlcs = choose_vlc_set(r->si.quant, r->si.vlc_set, 1);
@@ -1219,9 +1172,9 @@ static int rv34_decode_macroblock(RV34DecContext *r, int8_t *intra_types)
blkoff = ((i & 1) << 2) + ((i & 2) << 4);
rv34_decode_block(s->block[blknum] + blkoff, gb, r->cur_vlcs, r->chroma_vlc, 1);
rv34_dequant4x4(s->block[blknum] + blkoff, rv34_qscale_tab[rv34_chroma_quant[1][s->qscale]],rv34_qscale_tab[rv34_chroma_quant[0][s->qscale]]);
- rv34_inv_transform(s->block[blknum] + blkoff);
+ r->rdsp.rv34_inv_transform_tab[0](s->block[blknum] + blkoff);
}
- if(IS_INTRA(s->current_picture_ptr->mb_type[mb_pos]))
+ if (IS_INTRA(s->current_picture_ptr->f.mb_type[mb_pos]))
rv34_output_macroblock(r, intra_types, cbp2, r->is16);
else
rv34_apply_differences(r, cbp2);
@@ -1274,17 +1227,50 @@ static int rv34_decode_slice(RV34DecContext *r, int end, const uint8_t* buf, int
r->cbp_luma = av_realloc(r->cbp_luma, r->s.mb_stride * r->s.mb_height * sizeof(*r->cbp_luma));
r->cbp_chroma = av_realloc(r->cbp_chroma, r->s.mb_stride * r->s.mb_height * sizeof(*r->cbp_chroma));
r->deblock_coefs = av_realloc(r->deblock_coefs, r->s.mb_stride * r->s.mb_height * sizeof(*r->deblock_coefs));
+ av_freep(&r->tmp_b_block_base);
}
s->pict_type = r->si.type ? r->si.type : AV_PICTURE_TYPE_I;
if(MPV_frame_start(s, s->avctx) < 0)
return -1;
ff_er_frame_start(s);
+ if (!r->tmp_b_block_base) {
+ int i;
+
+ r->tmp_b_block_base = av_malloc(s->linesize * 48);
+ for (i = 0; i < 2; i++)
+ r->tmp_b_block_y[i] = r->tmp_b_block_base + i * 16 * s->linesize;
+ for (i = 0; i < 4; i++)
+ r->tmp_b_block_uv[i] = r->tmp_b_block_base + 32 * s->linesize
+ + (i >> 1) * 8 * s->uvlinesize + (i & 1) * 16;
+ }
r->cur_pts = r->si.pts;
if(s->pict_type != AV_PICTURE_TYPE_B){
r->last_pts = r->next_pts;
r->next_pts = r->cur_pts;
+ }else{
+ int refdist = GET_PTS_DIFF(r->next_pts, r->last_pts);
+ int dist0 = GET_PTS_DIFF(r->cur_pts, r->last_pts);
+ int dist1 = GET_PTS_DIFF(r->next_pts, r->cur_pts);
+
+ if(!refdist){
+ r->weight1 = r->weight2 = 8192;
+ }else{
+ r->weight1 = (dist0 << 14) / refdist;
+ r->weight2 = (dist1 << 14) / refdist;
+ }
}
s->mb_x = s->mb_y = 0;
+ } else {
+ int slice_type = r->si.type ? r->si.type : AV_PICTURE_TYPE_I;
+
+ if (slice_type != s->pict_type) {
+ av_log(s->avctx, AV_LOG_ERROR, "Slice type mismatch\n");
+ return AVERROR_INVALIDDATA;
+ }
+ if (s->width != r->si.width || s->height != r->si.height) {
+ av_log(s->avctx, AV_LOG_ERROR, "Size mismatch\n");
+ return AVERROR_INVALIDDATA;
+ }
}
r->si.end = end;
@@ -1301,8 +1287,8 @@ static int rv34_decode_slice(RV34DecContext *r, int end, const uint8_t* buf, int
}
memset(r->intra_types_hist, -1, r->intra_types_stride * 4 * 2 * sizeof(*r->intra_types_hist));
s->first_slice_line = 1;
- s->resync_mb_x= s->mb_x;
- s->resync_mb_y= s->mb_y;
+ s->resync_mb_x = s->mb_x;
+ s->resync_mb_y = s->mb_y;
ff_init_block_index(s);
while(!check_slice_end(r, s)) {
@@ -1344,11 +1330,11 @@ av_cold int ff_rv34_decode_init(AVCodecContext *avctx)
MpegEncContext *s = &r->s;
MPV_decode_defaults(s);
- s->avctx= avctx;
+ s->avctx = avctx;
s->out_format = FMT_H263;
- s->codec_id= avctx->codec_id;
+ s->codec_id = avctx->codec_id;
- s->width = avctx->width;
+ s->width = avctx->width;
s->height = avctx->height;
r->s.avctx = avctx;
@@ -1361,7 +1347,16 @@ av_cold int ff_rv34_decode_init(AVCodecContext *avctx)
if (MPV_common_init(s) < 0)
return -1;
- ff_h264_pred_init(&r->h, CODEC_ID_RV40, 8);
+ ff_h264_pred_init(&r->h, CODEC_ID_RV40, 8, 1);
+
+#if CONFIG_RV30_DECODER
+ if (avctx->codec_id == CODEC_ID_RV30)
+ ff_rv30dsp_init(&r->rdsp, &r->s.dsp);
+#endif
+#if CONFIG_RV40_DECODER
+ if (avctx->codec_id == CODEC_ID_RV40)
+ ff_rv40dsp_init(&r->rdsp, &r->s.dsp);
+#endif
r->intra_types_stride = 4*s->mb_stride + 4;
r->intra_types_hist = av_malloc(r->intra_types_stride * 4 * 2 * sizeof(*r->intra_types_hist));
@@ -1404,8 +1399,8 @@ int ff_rv34_decode_frame(AVCodecContext *avctx,
if (buf_size == 0) {
/* special case for last picture */
if (s->low_delay==0 && s->next_picture_ptr) {
- *pict= *(AVFrame*)s->next_picture_ptr;
- s->next_picture_ptr= NULL;
+ *pict = *(AVFrame*)s->next_picture_ptr;
+ s->next_picture_ptr = NULL;
*data_size = sizeof(AVFrame);
}
@@ -1416,41 +1411,48 @@ int ff_rv34_decode_frame(AVCodecContext *avctx,
slice_count = (*buf++) + 1;
slices_hdr = buf + 4;
buf += 8 * slice_count;
+ buf_size -= 1 + 8 * slice_count;
}else
slice_count = avctx->slice_count;
//parse first slice header to check whether this frame can be decoded
- if(get_slice_offset(avctx, slices_hdr, 0) > buf_size){
- av_log(avctx, AV_LOG_ERROR, "Slice offset is greater than frame size\n");
+ if(get_slice_offset(avctx, slices_hdr, 0) < 0 ||
+ get_slice_offset(avctx, slices_hdr, 0) > buf_size){
+ av_log(avctx, AV_LOG_ERROR, "Slice offset is invalid\n");
return -1;
}
- init_get_bits(&s->gb, buf+get_slice_offset(avctx, slices_hdr, 0), buf_size-get_slice_offset(avctx, slices_hdr, 0));
+ init_get_bits(&s->gb, buf+get_slice_offset(avctx, slices_hdr, 0), (buf_size-get_slice_offset(avctx, slices_hdr, 0))*8);
if(r->parse_slice_header(r, &r->s.gb, &si) < 0 || si.start){
av_log(avctx, AV_LOG_ERROR, "First slice header is incorrect\n");
return -1;
}
- if((!s->last_picture_ptr || !s->last_picture_ptr->data[0]) && si.type == AV_PICTURE_TYPE_B)
+ if ((!s->last_picture_ptr || !s->last_picture_ptr->f.data[0]) && si.type == AV_PICTURE_TYPE_B)
return -1;
if( (avctx->skip_frame >= AVDISCARD_NONREF && si.type==AV_PICTURE_TYPE_B)
|| (avctx->skip_frame >= AVDISCARD_NONKEY && si.type!=AV_PICTURE_TYPE_I)
|| avctx->skip_frame >= AVDISCARD_ALL)
- return buf_size;
+ return avpkt->size;
- for(i=0; i<slice_count; i++){
- int offset= get_slice_offset(avctx, slices_hdr, i);
+ for(i = 0; i < slice_count; i++){
+ int offset = get_slice_offset(avctx, slices_hdr, i);
int size;
if(i+1 == slice_count)
- size= buf_size - offset;
+ size = buf_size - offset;
else
- size= get_slice_offset(avctx, slices_hdr, i+1) - offset;
+ size = get_slice_offset(avctx, slices_hdr, i+1) - offset;
- if(offset > buf_size){
- av_log(avctx, AV_LOG_ERROR, "Slice offset is greater than frame size\n");
+ if(offset < 0 || offset > buf_size){
+ av_log(avctx, AV_LOG_ERROR, "Slice offset is invalid\n");
break;
}
r->si.end = s->mb_width * s->mb_height;
if(i+1 < slice_count){
+ if (get_slice_offset(avctx, slices_hdr, i+1) < 0 ||
+ get_slice_offset(avctx, slices_hdr, i+1) > buf_size) {
+ av_log(avctx, AV_LOG_ERROR, "Slice offset is invalid\n");
+ break;
+ }
init_get_bits(&s->gb, buf+get_slice_offset(avctx, slices_hdr, i+1), (buf_size-get_slice_offset(avctx, slices_hdr, i+1))*8);
if(r->parse_slice_header(r, &r->s.gb, &si) < 0){
if(i+2 < slice_count)
@@ -1460,30 +1462,34 @@ int ff_rv34_decode_frame(AVCodecContext *avctx,
}else
r->si.end = si.start;
}
+ if (size < 0 || size > buf_size - offset) {
+ av_log(avctx, AV_LOG_ERROR, "Slice size is invalid\n");
+ break;
+ }
last = rv34_decode_slice(r, r->si.end, buf + offset, size);
s->mb_num_left = r->s.mb_x + r->s.mb_y*r->s.mb_width - r->si.start;
if(last)
break;
}
- if(last){
+ if(last && s->current_picture_ptr){
if(r->loop_filter)
r->loop_filter(r, s->mb_height - 1);
ff_er_frame_end(s);
MPV_frame_end(s);
if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {
- *pict= *(AVFrame*)s->current_picture_ptr;
+ *pict = *(AVFrame*)s->current_picture_ptr;
} else if (s->last_picture_ptr != NULL) {
- *pict= *(AVFrame*)s->last_picture_ptr;
+ *pict = *(AVFrame*)s->last_picture_ptr;
}
if(s->last_picture_ptr || s->low_delay){
*data_size = sizeof(AVFrame);
ff_print_debug_info(s, pict);
}
- s->current_picture_ptr= NULL; //so we can detect if frame_end wasnt called (find some nicer solution...)
+ s->current_picture_ptr = NULL; //so we can detect if frame_end wasnt called (find some nicer solution...)
}
- return buf_size;
+ return avpkt->size;
}
av_cold int ff_rv34_decode_end(AVCodecContext *avctx)
@@ -1494,6 +1500,7 @@ av_cold int ff_rv34_decode_end(AVCodecContext *avctx)
av_freep(&r->intra_types_hist);
r->intra_types = NULL;
+ av_freep(&r->tmp_b_block_base);
av_freep(&r->mb_type);
av_freep(&r->cbp_luma);
av_freep(&r->cbp_chroma);
diff --git a/libavcodec/rv34.h b/libavcodec/rv34.h
index c9f4ff7a13..860aa566e4 100644
--- a/libavcodec/rv34.h
+++ b/libavcodec/rv34.h
@@ -2,20 +2,20 @@
* RV30/40 decoder common data declarations
* Copyright (c) 2007 Mike Melanson, Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -32,6 +32,7 @@
#include "mpegvideo.h"
#include "h264pred.h"
+#include "rv34dsp.h"
#define MB_TYPE_SEPARATE_DC 0x01000000
#define IS_SEPARATE_DC(a) ((a) & MB_TYPE_SEPARATE_DC)
@@ -83,6 +84,7 @@ typedef struct SliceInfo{
/** decoder context */
typedef struct RV34DecContext{
MpegEncContext s;
+ RV34DSPContext rdsp;
int8_t *intra_types_hist;///< old block types, used for prediction
int8_t *intra_types; ///< block types
int intra_types_stride;///< block types array stride
@@ -105,6 +107,7 @@ typedef struct RV34DecContext{
int rpr; ///< one field size in RV30 slice header
int cur_pts, last_pts, next_pts;
+ int weight1, weight2; ///< B frame distance fractions (0.14) used in motion compensation
uint16_t *cbp_luma; ///< CBP values for luma subblocks
uint8_t *cbp_chroma; ///< CBP values for chroma subblocks
@@ -113,6 +116,11 @@ typedef struct RV34DecContext{
/** 8x8 block available flags (for MV prediction) */
DECLARE_ALIGNED(8, uint32_t, avail_cache)[3*4];
+ /** temporary blocks for RV4 weighted MC */
+ uint8_t *tmp_b_block_y[2];
+ uint8_t *tmp_b_block_uv[4];
+ uint8_t *tmp_b_block_base;
+
int (*parse_slice_header)(struct RV34DecContext *r, GetBitContext *gb, SliceInfo *si);
int (*decode_mb_info)(struct RV34DecContext *r);
int (*decode_intra_types)(struct RV34DecContext *r, GetBitContext *gb, int8_t *dst);
diff --git a/libavcodec/rv34_parser.c b/libavcodec/rv34_parser.c
new file mode 100644
index 0000000000..ce8604345e
--- /dev/null
+++ b/libavcodec/rv34_parser.c
@@ -0,0 +1,95 @@
+/*
+ * RV30/40 parser
+ * Copyright (c) 2011 Konstantin Shishkov
+ *
+ * This file is part of Libav.
+ *
+ * Libav 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.
+ *
+ * Libav 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * RV30/40 parser
+ */
+
+#include "parser.h"
+#include "libavutil/intreadwrite.h"
+
+typedef struct {
+ ParseContext pc;
+ int64_t key_dts;
+ int key_pts;
+} RV34ParseContext;
+
+static const int rv_to_av_frame_type[4] = {
+ AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B,
+};
+
+static int rv34_parse(AVCodecParserContext *s,
+ AVCodecContext *avctx,
+ const uint8_t **poutbuf, int *poutbuf_size,
+ const uint8_t *buf, int buf_size)
+{
+ RV34ParseContext *pc = s->priv_data;
+ int type, pts, hdr;
+
+ if (buf_size < 13 + *buf * 8) {
+ *poutbuf = buf;
+ *poutbuf_size = buf_size;
+ return buf_size;
+ }
+
+ hdr = AV_RB32(buf + 9 + *buf * 8);
+ if (avctx->codec_id == CODEC_ID_RV30) {
+ type = (hdr >> 27) & 3;
+ pts = (hdr >> 7) & 0x1FFF;
+ } else {
+ type = (hdr >> 29) & 3;
+ pts = (hdr >> 6) & 0x1FFF;
+ }
+
+ if (type != 3 && s->pts != AV_NOPTS_VALUE) {
+ pc->key_dts = s->pts;
+ pc->key_pts = pts;
+ } else {
+ if (type != 3)
+ s->pts = pc->key_dts + ((pts - pc->key_pts) & 0x1FFF);
+ else
+ s->pts = pc->key_dts - ((pc->key_pts - pts) & 0x1FFF);
+ }
+ s->pict_type = rv_to_av_frame_type[type];
+
+ *poutbuf = buf;
+ *poutbuf_size = buf_size;
+ return buf_size;
+}
+
+#ifdef CONFIG_RV30_PARSER
+AVCodecParser ff_rv30_parser = {
+ { CODEC_ID_RV30 },
+ sizeof(RV34ParseContext),
+ NULL,
+ rv34_parse,
+};
+#endif
+
+#ifdef CONFIG_RV40_PARSER
+AVCodecParser ff_rv40_parser = {
+ { CODEC_ID_RV40 },
+ sizeof(RV34ParseContext),
+ NULL,
+ rv34_parse,
+};
+#endif
diff --git a/libavcodec/rv34data.h b/libavcodec/rv34data.h
index f8f941d061..2155084d09 100644
--- a/libavcodec/rv34data.h
+++ b/libavcodec/rv34data.h
@@ -2,20 +2,20 @@
* RealVideo 4 decoder
* copyright (c) 2007 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/rv34dsp.c b/libavcodec/rv34dsp.c
new file mode 100644
index 0000000000..59038a7a31
--- /dev/null
+++ b/libavcodec/rv34dsp.c
@@ -0,0 +1,106 @@
+/*
+ * RV30/40 decoder common dsp functions
+ * Copyright (c) 2007 Mike Melanson, Konstantin Shishkov
+ * Copyright (c) 2011 Janne Grunau
+ *
+ * This file is part of Libav.
+ *
+ * Libav 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.
+ *
+ * Libav 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * RV30/40 decoder common dsp functions
+ */
+#include "dsputil.h"
+#include "rv34dsp.h"
+
+/**
+ * @name RV30/40 inverse transform functions
+ * @{
+ */
+
+static av_always_inline void rv34_row_transform(int temp[16], DCTELEM *block)
+{
+ int i;
+
+ for(i = 0; i < 4; i++){
+ const int z0 = 13*(block[i+8*0] + block[i+8*2]);
+ const int z1 = 13*(block[i+8*0] - block[i+8*2]);
+ const int z2 = 7* block[i+8*1] - 17*block[i+8*3];
+ const int z3 = 17* block[i+8*1] + 7*block[i+8*3];
+
+ temp[4*i+0] = z0 + z3;
+ temp[4*i+1] = z1 + z2;
+ temp[4*i+2] = z1 - z2;
+ temp[4*i+3] = z0 - z3;
+ }
+}
+
+/**
+ * Real Video 3.0/4.0 inverse transform
+ * Code is almost the same as in SVQ3, only scaling is different.
+ */
+static void rv34_inv_transform_c(DCTELEM *block){
+ int temp[16];
+ int i;
+
+ rv34_row_transform(temp, block);
+
+ for(i = 0; i < 4; i++){
+ const int z0 = 13*(temp[4*0+i] + temp[4*2+i]) + 0x200;
+ const int z1 = 13*(temp[4*0+i] - temp[4*2+i]) + 0x200;
+ const int z2 = 7* temp[4*1+i] - 17*temp[4*3+i];
+ const int z3 = 17* temp[4*1+i] + 7*temp[4*3+i];
+
+ block[i*8+0] = (z0 + z3) >> 10;
+ block[i*8+1] = (z1 + z2) >> 10;
+ block[i*8+2] = (z1 - z2) >> 10;
+ block[i*8+3] = (z0 - z3) >> 10;
+ }
+}
+
+/**
+ * RealVideo 3.0/4.0 inverse transform for DC block
+ *
+ * Code is almost the same as rv34_inv_transform()
+ * but final coefficients are multiplied by 1.5 and have no rounding.
+ */
+static void rv34_inv_transform_noround_c(DCTELEM *block){
+ int temp[16];
+ int i;
+
+ rv34_row_transform(temp, block);
+
+ for(i = 0; i < 4; i++){
+ const int z0 = 13*(temp[4*0+i] + temp[4*2+i]);
+ const int z1 = 13*(temp[4*0+i] - temp[4*2+i]);
+ const int z2 = 7* temp[4*1+i] - 17*temp[4*3+i];
+ const int z3 = 17* temp[4*1+i] + 7*temp[4*3+i];
+
+ block[i*8+0] = ((z0 + z3) * 3) >> 11;
+ block[i*8+1] = ((z1 + z2) * 3) >> 11;
+ block[i*8+2] = ((z1 - z2) * 3) >> 11;
+ block[i*8+3] = ((z0 - z3) * 3) >> 11;
+ }
+}
+
+/** @} */ // transform
+
+
+av_cold void ff_rv34dsp_init(RV34DSPContext *c, DSPContext* dsp) {
+ c->rv34_inv_transform_tab[0] = rv34_inv_transform_c;
+ c->rv34_inv_transform_tab[1] = rv34_inv_transform_noround_c;
+}
diff --git a/libavcodec/rv34dsp.h b/libavcodec/rv34dsp.h
new file mode 100644
index 0000000000..a2ab5f232b
--- /dev/null
+++ b/libavcodec/rv34dsp.h
@@ -0,0 +1,54 @@
+/*
+ * RV30/40 decoder motion compensation functions
+ * Copyright (c) 2008 Konstantin Shishkov
+ *
+ * This file is part of Libav.
+ *
+ * Libav 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.
+ *
+ * Libav 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * RV30/40 decoder motion compensation functions
+ */
+
+#ifndef AVCODEC_RV34DSP_H
+#define AVCODEC_RV34DSP_H
+
+#include "dsputil.h"
+
+typedef void (*rv40_weight_func)(uint8_t *dst/*align width (8 or 16)*/,
+ uint8_t *src1/*align width (8 or 16)*/,
+ uint8_t *src2/*align width (8 or 16)*/,
+ int w1, int w2, int stride);
+
+typedef void (*rv34_inv_transform_func)(DCTELEM *block);
+
+typedef struct RV34DSPContext {
+ qpel_mc_func put_pixels_tab[4][16];
+ qpel_mc_func avg_pixels_tab[4][16];
+ h264_chroma_mc_func put_chroma_pixels_tab[3];
+ h264_chroma_mc_func avg_chroma_pixels_tab[3];
+ rv40_weight_func rv40_weight_pixels_tab[2];
+ rv34_inv_transform_func rv34_inv_transform_tab[2];
+} RV34DSPContext;
+
+void ff_rv30dsp_init(RV34DSPContext *c, DSPContext* dsp);
+void ff_rv34dsp_init(RV34DSPContext *c, DSPContext* dsp);
+void ff_rv40dsp_init(RV34DSPContext *c, DSPContext* dsp);
+
+void ff_rv40dsp_init_x86(RV34DSPContext *c, DSPContext *dsp);
+
+#endif /* AVCODEC_RV34DSP_H */
diff --git a/libavcodec/rv34vlc.h b/libavcodec/rv34vlc.h
index f4670c1625..aa29357c78 100644
--- a/libavcodec/rv34vlc.h
+++ b/libavcodec/rv34vlc.h
@@ -2,20 +2,20 @@
* RealVideo 3/4 decoder
* Copyright (c) 2007 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/rv40.c b/libavcodec/rv40.c
index 46e77bc240..0222983087 100644
--- a/libavcodec/rv40.c
+++ b/libavcodec/rv40.c
@@ -2,20 +2,20 @@
* RV40 decoder
* Copyright (c) 2007 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -231,8 +231,11 @@ static int rv40_decode_mb_info(RV34DecContext *r)
int blocks[RV34_MB_TYPES] = {0};
int count = 0;
- if(!r->s.mb_skip_run)
+ if(!r->s.mb_skip_run) {
r->s.mb_skip_run = svq3_get_ue_golomb(gb) + 1;
+ if(r->s.mb_skip_run > (unsigned)s->mb_num)
+ return -1;
+ }
if(--r->s.mb_skip_run)
return RV34_MB_SKIP;
@@ -475,7 +478,7 @@ static void rv40_loop_filter(RV34DecContext *r, int row)
mb_pos = row * s->mb_stride;
for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){
- int mbtype = s->current_picture_ptr->mb_type[mb_pos];
+ int mbtype = s->current_picture_ptr->f.mb_type[mb_pos];
if(IS_INTRA(mbtype) || IS_SEPARATE_DC(mbtype))
r->cbp_luma [mb_pos] = r->deblock_coefs[mb_pos] = 0xFFFF;
if(IS_INTRA(mbtype))
@@ -489,7 +492,7 @@ static void rv40_loop_filter(RV34DecContext *r, int row)
int avail[4];
int y_to_deblock, c_to_deblock[2];
- q = s->current_picture_ptr->qscale_table[mb_pos];
+ q = s->current_picture_ptr->f.qscale_table[mb_pos];
alpha = rv40_alpha_tab[q];
beta = rv40_beta_tab [q];
betaY = betaC = beta * 3;
@@ -504,7 +507,7 @@ static void rv40_loop_filter(RV34DecContext *r, int row)
if(avail[i]){
int pos = mb_pos + neighbour_offs_x[i] + neighbour_offs_y[i]*s->mb_stride;
mvmasks[i] = r->deblock_coefs[pos];
- mbtype [i] = s->current_picture_ptr->mb_type[pos];
+ mbtype [i] = s->current_picture_ptr->f.mb_type[pos];
cbp [i] = r->cbp_luma[pos];
uvcbp[i][0] = r->cbp_chroma[pos] & 0xF;
uvcbp[i][1] = r->cbp_chroma[pos] >> 4;
@@ -563,7 +566,7 @@ static void rv40_loop_filter(RV34DecContext *r, int row)
}
for(j = 0; j < 16; j += 4){
- Y = s->current_picture_ptr->data[0] + mb_x*16 + (row*16 + j) * s->linesize;
+ Y = s->current_picture_ptr->f.data[0] + mb_x*16 + (row*16 + j) * s->linesize;
for(i = 0; i < 4; i++, Y += 4){
int ij = i + j;
int clip_cur = y_to_deblock & (MASK_CUR << ij) ? clip[POS_CUR] : 0;
@@ -607,7 +610,7 @@ static void rv40_loop_filter(RV34DecContext *r, int row)
}
for(k = 0; k < 2; k++){
for(j = 0; j < 2; j++){
- C = s->current_picture_ptr->data[k+1] + mb_x*8 + (row*8 + j*4) * s->uvlinesize;
+ C = s->current_picture_ptr->f.data[k + 1] + mb_x*8 + (row*8 + j*4) * s->uvlinesize;
for(i = 0; i < 2; i++, C += 4){
int ij = i + j*2;
int clip_cur = c_to_deblock[k] & (MASK_CUR << ij) ? clip[POS_CUR] : 0;
@@ -669,16 +672,15 @@ static av_cold int rv40_decode_init(AVCodecContext *avctx)
}
AVCodec ff_rv40_decoder = {
- "rv40",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_RV40,
- sizeof(RV34DecContext),
- rv40_decode_init,
- NULL,
- ff_rv34_decode_end,
- ff_rv34_decode_frame,
- CODEC_CAP_DR1 | CODEC_CAP_DELAY,
- .flush = ff_mpeg_flush,
- .long_name = NULL_IF_CONFIG_SMALL("RealVideo 4.0"),
- .pix_fmts= ff_pixfmt_list_420,
+ .name = "rv40",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_RV40,
+ .priv_data_size = sizeof(RV34DecContext),
+ .init = rv40_decode_init,
+ .close = ff_rv34_decode_end,
+ .decode = ff_rv34_decode_frame,
+ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY,
+ .flush = ff_mpeg_flush,
+ .long_name = NULL_IF_CONFIG_SMALL("RealVideo 4.0"),
+ .pix_fmts = ff_pixfmt_list_420,
};
diff --git a/libavcodec/rv40data.h b/libavcodec/rv40data.h
index 1b6e8c31b1..436afa84e2 100644
--- a/libavcodec/rv40data.h
+++ b/libavcodec/rv40data.h
@@ -2,20 +2,20 @@
* RealVideo 4 decoder
* copyright (c) 2007 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/rv40dsp.c b/libavcodec/rv40dsp.c
index 2271f5471b..b879643ba1 100644
--- a/libavcodec/rv40dsp.c
+++ b/libavcodec/rv40dsp.c
@@ -2,20 +2,20 @@
* RV40 decoder motion compensation functions
* Copyright (c) 2008 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -26,13 +26,14 @@
#include "avcodec.h"
#include "dsputil.h"
+#include "rv34dsp.h"
#define RV40_LOWPASS(OPNAME, OP) \
static av_unused void OPNAME ## rv40_qpel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride,\
const int h, const int C1, const int C2, const int SHIFT){\
uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
int i;\
- for(i=0; i<h; i++)\
+ for(i = 0; i < h; i++)\
{\
OP(dst[0], (src[-2] + src[ 3] - 5*(src[-1]+src[2]) + src[0]*C1 + src[1]*C2 + (1<<(SHIFT-1))) >> SHIFT);\
OP(dst[1], (src[-1] + src[ 4] - 5*(src[ 0]+src[3]) + src[1]*C1 + src[2]*C2 + (1<<(SHIFT-1))) >> SHIFT);\
@@ -42,8 +43,8 @@ static av_unused void OPNAME ## rv40_qpel8_h_lowpass(uint8_t *dst, uint8_t *src,
OP(dst[5], (src[ 3] + src[ 8] - 5*(src[ 4]+src[7]) + src[5]*C1 + src[6]*C2 + (1<<(SHIFT-1))) >> SHIFT);\
OP(dst[6], (src[ 4] + src[ 9] - 5*(src[ 5]+src[8]) + src[6]*C1 + src[7]*C2 + (1<<(SHIFT-1))) >> SHIFT);\
OP(dst[7], (src[ 5] + src[10] - 5*(src[ 6]+src[9]) + src[7]*C1 + src[8]*C2 + (1<<(SHIFT-1))) >> SHIFT);\
- dst+=dstStride;\
- src+=srcStride;\
+ dst += dstStride;\
+ src += srcStride;\
}\
}\
\
@@ -51,21 +52,21 @@ static void OPNAME ## rv40_qpel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstSt
const int w, const int C1, const int C2, const int SHIFT){\
uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
int i;\
- for(i=0; i<w; i++)\
+ for(i = 0; i < w; i++)\
{\
- const int srcB = src[-2*srcStride];\
- const int srcA = src[-1*srcStride];\
- const int src0 = src[0 *srcStride];\
- const int src1 = src[1 *srcStride];\
- const int src2 = src[2 *srcStride];\
- const int src3 = src[3 *srcStride];\
- const int src4 = src[4 *srcStride];\
- const int src5 = src[5 *srcStride];\
- const int src6 = src[6 *srcStride];\
- const int src7 = src[7 *srcStride];\
- const int src8 = src[8 *srcStride];\
- const int src9 = src[9 *srcStride];\
- const int src10= src[10*srcStride];\
+ const int srcB = src[-2*srcStride];\
+ const int srcA = src[-1*srcStride];\
+ const int src0 = src[0 *srcStride];\
+ const int src1 = src[1 *srcStride];\
+ const int src2 = src[2 *srcStride];\
+ const int src3 = src[3 *srcStride];\
+ const int src4 = src[4 *srcStride];\
+ const int src5 = src[5 *srcStride];\
+ const int src6 = src[6 *srcStride];\
+ const int src7 = src[7 *srcStride];\
+ const int src8 = src[8 *srcStride];\
+ const int src9 = src[9 *srcStride];\
+ const int src10 = src[10*srcStride];\
OP(dst[0*dstStride], (srcB + src3 - 5*(srcA+src2) + src0*C1 + src1*C2 + (1<<(SHIFT-1))) >> SHIFT);\
OP(dst[1*dstStride], (srcA + src4 - 5*(src0+src3) + src1*C1 + src2*C2 + (1<<(SHIFT-1))) >> SHIFT);\
OP(dst[2*dstStride], (src0 + src5 - 5*(src1+src4) + src2*C1 + src3*C2 + (1<<(SHIFT-1))) >> SHIFT);\
@@ -105,10 +106,6 @@ static void OPNAME ## rv40_qpel ## SIZE ## _mc10_c(uint8_t *dst, uint8_t *src, i
OPNAME ## rv40_qpel ## SIZE ## _h_lowpass(dst, src, stride, stride, SIZE, 52, 20, 6);\
}\
\
-static void OPNAME ## rv40_qpel ## SIZE ## _mc20_c(uint8_t *dst, uint8_t *src, int stride){\
- OPNAME ## rv40_qpel ## SIZE ## _h_lowpass(dst, src, stride, stride, SIZE, 20, 20, 5);\
-}\
-\
static void OPNAME ## rv40_qpel ## SIZE ## _mc30_c(uint8_t *dst, uint8_t *src, int stride){\
OPNAME ## rv40_qpel ## SIZE ## _h_lowpass(dst, src, stride, stride, SIZE, 20, 52, 6);\
}\
@@ -119,46 +116,42 @@ static void OPNAME ## rv40_qpel ## SIZE ## _mc01_c(uint8_t *dst, uint8_t *src, i
\
static void OPNAME ## rv40_qpel ## SIZE ## _mc11_c(uint8_t *dst, uint8_t *src, int stride){\
uint8_t full[SIZE*(SIZE+5)];\
- uint8_t * const full_mid= full + SIZE*2;\
+ uint8_t * const full_mid = full + SIZE*2;\
put_rv40_qpel ## SIZE ## _h_lowpass(full, src - 2*stride, SIZE, stride, SIZE+5, 52, 20, 6);\
OPNAME ## rv40_qpel ## SIZE ## _v_lowpass(dst, full_mid, stride, SIZE, SIZE, 52, 20, 6);\
}\
\
static void OPNAME ## rv40_qpel ## SIZE ## _mc21_c(uint8_t *dst, uint8_t *src, int stride){\
uint8_t full[SIZE*(SIZE+5)];\
- uint8_t * const full_mid= full + SIZE*2;\
+ uint8_t * const full_mid = full + SIZE*2;\
put_rv40_qpel ## SIZE ## _h_lowpass(full, src - 2*stride, SIZE, stride, SIZE+5, 20, 20, 5);\
OPNAME ## rv40_qpel ## SIZE ## _v_lowpass(dst, full_mid, stride, SIZE, SIZE, 52, 20, 6);\
}\
\
static void OPNAME ## rv40_qpel ## SIZE ## _mc31_c(uint8_t *dst, uint8_t *src, int stride){\
uint8_t full[SIZE*(SIZE+5)];\
- uint8_t * const full_mid= full + SIZE*2;\
+ uint8_t * const full_mid = full + SIZE*2;\
put_rv40_qpel ## SIZE ## _h_lowpass(full, src - 2*stride, SIZE, stride, SIZE+5, 20, 52, 6);\
OPNAME ## rv40_qpel ## SIZE ## _v_lowpass(dst, full_mid, stride, SIZE, SIZE, 52, 20, 6);\
}\
\
-static void OPNAME ## rv40_qpel ## SIZE ## _mc02_c(uint8_t *dst, uint8_t *src, int stride){\
- OPNAME ## rv40_qpel ## SIZE ## _v_lowpass(dst, src, stride, stride, SIZE, 20, 20, 5);\
-}\
-\
static void OPNAME ## rv40_qpel ## SIZE ## _mc12_c(uint8_t *dst, uint8_t *src, int stride){\
uint8_t full[SIZE*(SIZE+5)];\
- uint8_t * const full_mid= full + SIZE*2;\
+ uint8_t * const full_mid = full + SIZE*2;\
put_rv40_qpel ## SIZE ## _h_lowpass(full, src - 2*stride, SIZE, stride, SIZE+5, 52, 20, 6);\
OPNAME ## rv40_qpel ## SIZE ## _v_lowpass(dst, full_mid, stride, SIZE, SIZE, 20, 20, 5);\
}\
\
static void OPNAME ## rv40_qpel ## SIZE ## _mc22_c(uint8_t *dst, uint8_t *src, int stride){\
uint8_t full[SIZE*(SIZE+5)];\
- uint8_t * const full_mid= full + SIZE*2;\
+ uint8_t * const full_mid = full + SIZE*2;\
put_rv40_qpel ## SIZE ## _h_lowpass(full, src - 2*stride, SIZE, stride, SIZE+5, 20, 20, 5);\
OPNAME ## rv40_qpel ## SIZE ## _v_lowpass(dst, full_mid, stride, SIZE, SIZE, 20, 20, 5);\
}\
\
static void OPNAME ## rv40_qpel ## SIZE ## _mc32_c(uint8_t *dst, uint8_t *src, int stride){\
uint8_t full[SIZE*(SIZE+5)];\
- uint8_t * const full_mid= full + SIZE*2;\
+ uint8_t * const full_mid = full + SIZE*2;\
put_rv40_qpel ## SIZE ## _h_lowpass(full, src - 2*stride, SIZE, stride, SIZE+5, 20, 52, 6);\
OPNAME ## rv40_qpel ## SIZE ## _v_lowpass(dst, full_mid, stride, SIZE, SIZE, 20, 20, 5);\
}\
@@ -169,14 +162,14 @@ static void OPNAME ## rv40_qpel ## SIZE ## _mc03_c(uint8_t *dst, uint8_t *src, i
\
static void OPNAME ## rv40_qpel ## SIZE ## _mc13_c(uint8_t *dst, uint8_t *src, int stride){\
uint8_t full[SIZE*(SIZE+5)];\
- uint8_t * const full_mid= full + SIZE*2;\
+ uint8_t * const full_mid = full + SIZE*2;\
put_rv40_qpel ## SIZE ## _h_lowpass(full, src - 2*stride, SIZE, stride, SIZE+5, 52, 20, 6);\
OPNAME ## rv40_qpel ## SIZE ## _v_lowpass(dst, full_mid, stride, SIZE, SIZE, 20, 52, 6);\
}\
\
static void OPNAME ## rv40_qpel ## SIZE ## _mc23_c(uint8_t *dst, uint8_t *src, int stride){\
uint8_t full[SIZE*(SIZE+5)];\
- uint8_t * const full_mid= full + SIZE*2;\
+ uint8_t * const full_mid = full + SIZE*2;\
put_rv40_qpel ## SIZE ## _h_lowpass(full, src - 2*stride, SIZE, stride, SIZE+5, 20, 20, 5);\
OPNAME ## rv40_qpel ## SIZE ## _v_lowpass(dst, full_mid, stride, SIZE, SIZE, 20, 52, 6);\
}\
@@ -205,50 +198,50 @@ static const int rv40_bias[4][4] = {
#define RV40_CHROMA_MC(OPNAME, OP)\
static void OPNAME ## rv40_chroma_mc4_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\
- const int A=(8-x)*(8-y);\
- const int B=( x)*(8-y);\
- const int C=(8-x)*( y);\
- const int D=( x)*( y);\
+ const int A = (8-x) * (8-y);\
+ const int B = ( x) * (8-y);\
+ const int C = (8-x) * ( y);\
+ const int D = ( x) * ( y);\
int i;\
int bias = rv40_bias[y>>1][x>>1];\
\
assert(x<8 && y<8 && x>=0 && y>=0);\
\
if(D){\
- for(i=0; i<h; i++){\
+ for(i = 0; i < h; i++){\
OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1] + bias));\
OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + bias));\
OP(dst[2], (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + bias));\
OP(dst[3], (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + bias));\
- dst+= stride;\
- src+= stride;\
+ dst += stride;\
+ src += stride;\
}\
}else{\
- const int E= B+C;\
- const int step= C ? stride : 1;\
- for(i=0; i<h; i++){\
+ const int E = B + C;\
+ const int step = C ? stride : 1;\
+ for(i = 0; i < h; i++){\
OP(dst[0], (A*src[0] + E*src[step+0] + bias));\
OP(dst[1], (A*src[1] + E*src[step+1] + bias));\
OP(dst[2], (A*src[2] + E*src[step+2] + bias));\
OP(dst[3], (A*src[3] + E*src[step+3] + bias));\
- dst+= stride;\
- src+= stride;\
+ dst += stride;\
+ src += stride;\
}\
}\
}\
\
static void OPNAME ## rv40_chroma_mc8_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\
- const int A=(8-x)*(8-y);\
- const int B=( x)*(8-y);\
- const int C=(8-x)*( y);\
- const int D=( x)*( y);\
+ const int A = (8-x) * (8-y);\
+ const int B = ( x) * (8-y);\
+ const int C = (8-x) * ( y);\
+ const int D = ( x) * ( y);\
int i;\
int bias = rv40_bias[y>>1][x>>1];\
\
assert(x<8 && y<8 && x>=0 && y>=0);\
\
if(D){\
- for(i=0; i<h; i++){\
+ for(i = 0; i < h; i++){\
OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1] + bias));\
OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + bias));\
OP(dst[2], (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + bias));\
@@ -257,13 +250,13 @@ static void OPNAME ## rv40_chroma_mc8_c(uint8_t *dst/*align 8*/, uint8_t *src/*a
OP(dst[5], (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6] + bias));\
OP(dst[6], (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7] + bias));\
OP(dst[7], (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8] + bias));\
- dst+= stride;\
- src+= stride;\
+ dst += stride;\
+ src += stride;\
}\
}else{\
- const int E= B+C;\
- const int step= C ? stride : 1;\
- for(i=0; i<h; i++){\
+ const int E = B + C;\
+ const int step = C ? stride : 1;\
+ for(i = 0; i < h; i++){\
OP(dst[0], (A*src[0] + E*src[step+0] + bias));\
OP(dst[1], (A*src[1] + E*src[step+1] + bias));\
OP(dst[2], (A*src[2] + E*src[step+2] + bias));\
@@ -272,8 +265,8 @@ static void OPNAME ## rv40_chroma_mc8_c(uint8_t *dst/*align 8*/, uint8_t *src/*a
OP(dst[5], (A*src[5] + E*src[step+5] + bias));\
OP(dst[6], (A*src[6] + E*src[step+6] + bias));\
OP(dst[7], (A*src[7] + E*src[step+7] + bias));\
- dst+= stride;\
- src+= stride;\
+ dst += stride;\
+ src += stride;\
}\
}\
}
@@ -284,70 +277,100 @@ static void OPNAME ## rv40_chroma_mc8_c(uint8_t *dst/*align 8*/, uint8_t *src/*a
RV40_CHROMA_MC(put_, op_put)
RV40_CHROMA_MC(avg_, op_avg)
-void ff_rv40dsp_init(DSPContext* c, AVCodecContext *avctx) {
- c->put_rv40_qpel_pixels_tab[0][ 0] = c->put_h264_qpel_pixels_tab[0][0];
- c->put_rv40_qpel_pixels_tab[0][ 1] = put_rv40_qpel16_mc10_c;
- c->put_rv40_qpel_pixels_tab[0][ 2] = put_rv40_qpel16_mc20_c;
- c->put_rv40_qpel_pixels_tab[0][ 3] = put_rv40_qpel16_mc30_c;
- c->put_rv40_qpel_pixels_tab[0][ 4] = put_rv40_qpel16_mc01_c;
- c->put_rv40_qpel_pixels_tab[0][ 5] = put_rv40_qpel16_mc11_c;
- c->put_rv40_qpel_pixels_tab[0][ 6] = put_rv40_qpel16_mc21_c;
- c->put_rv40_qpel_pixels_tab[0][ 7] = put_rv40_qpel16_mc31_c;
- c->put_rv40_qpel_pixels_tab[0][ 8] = put_rv40_qpel16_mc02_c;
- c->put_rv40_qpel_pixels_tab[0][ 9] = put_rv40_qpel16_mc12_c;
- c->put_rv40_qpel_pixels_tab[0][10] = put_rv40_qpel16_mc22_c;
- c->put_rv40_qpel_pixels_tab[0][11] = put_rv40_qpel16_mc32_c;
- c->put_rv40_qpel_pixels_tab[0][12] = put_rv40_qpel16_mc03_c;
- c->put_rv40_qpel_pixels_tab[0][13] = put_rv40_qpel16_mc13_c;
- c->put_rv40_qpel_pixels_tab[0][14] = put_rv40_qpel16_mc23_c;
- c->avg_rv40_qpel_pixels_tab[0][ 0] = c->avg_h264_qpel_pixels_tab[0][0];
- c->avg_rv40_qpel_pixels_tab[0][ 1] = avg_rv40_qpel16_mc10_c;
- c->avg_rv40_qpel_pixels_tab[0][ 2] = avg_rv40_qpel16_mc20_c;
- c->avg_rv40_qpel_pixels_tab[0][ 3] = avg_rv40_qpel16_mc30_c;
- c->avg_rv40_qpel_pixels_tab[0][ 4] = avg_rv40_qpel16_mc01_c;
- c->avg_rv40_qpel_pixels_tab[0][ 5] = avg_rv40_qpel16_mc11_c;
- c->avg_rv40_qpel_pixels_tab[0][ 6] = avg_rv40_qpel16_mc21_c;
- c->avg_rv40_qpel_pixels_tab[0][ 7] = avg_rv40_qpel16_mc31_c;
- c->avg_rv40_qpel_pixels_tab[0][ 8] = avg_rv40_qpel16_mc02_c;
- c->avg_rv40_qpel_pixels_tab[0][ 9] = avg_rv40_qpel16_mc12_c;
- c->avg_rv40_qpel_pixels_tab[0][10] = avg_rv40_qpel16_mc22_c;
- c->avg_rv40_qpel_pixels_tab[0][11] = avg_rv40_qpel16_mc32_c;
- c->avg_rv40_qpel_pixels_tab[0][12] = avg_rv40_qpel16_mc03_c;
- c->avg_rv40_qpel_pixels_tab[0][13] = avg_rv40_qpel16_mc13_c;
- c->avg_rv40_qpel_pixels_tab[0][14] = avg_rv40_qpel16_mc23_c;
- c->put_rv40_qpel_pixels_tab[1][ 0] = c->put_h264_qpel_pixels_tab[1][0];
- c->put_rv40_qpel_pixels_tab[1][ 1] = put_rv40_qpel8_mc10_c;
- c->put_rv40_qpel_pixels_tab[1][ 2] = put_rv40_qpel8_mc20_c;
- c->put_rv40_qpel_pixels_tab[1][ 3] = put_rv40_qpel8_mc30_c;
- c->put_rv40_qpel_pixels_tab[1][ 4] = put_rv40_qpel8_mc01_c;
- c->put_rv40_qpel_pixels_tab[1][ 5] = put_rv40_qpel8_mc11_c;
- c->put_rv40_qpel_pixels_tab[1][ 6] = put_rv40_qpel8_mc21_c;
- c->put_rv40_qpel_pixels_tab[1][ 7] = put_rv40_qpel8_mc31_c;
- c->put_rv40_qpel_pixels_tab[1][ 8] = put_rv40_qpel8_mc02_c;
- c->put_rv40_qpel_pixels_tab[1][ 9] = put_rv40_qpel8_mc12_c;
- c->put_rv40_qpel_pixels_tab[1][10] = put_rv40_qpel8_mc22_c;
- c->put_rv40_qpel_pixels_tab[1][11] = put_rv40_qpel8_mc32_c;
- c->put_rv40_qpel_pixels_tab[1][12] = put_rv40_qpel8_mc03_c;
- c->put_rv40_qpel_pixels_tab[1][13] = put_rv40_qpel8_mc13_c;
- c->put_rv40_qpel_pixels_tab[1][14] = put_rv40_qpel8_mc23_c;
- c->avg_rv40_qpel_pixels_tab[1][ 0] = c->avg_h264_qpel_pixels_tab[1][0];
- c->avg_rv40_qpel_pixels_tab[1][ 1] = avg_rv40_qpel8_mc10_c;
- c->avg_rv40_qpel_pixels_tab[1][ 2] = avg_rv40_qpel8_mc20_c;
- c->avg_rv40_qpel_pixels_tab[1][ 3] = avg_rv40_qpel8_mc30_c;
- c->avg_rv40_qpel_pixels_tab[1][ 4] = avg_rv40_qpel8_mc01_c;
- c->avg_rv40_qpel_pixels_tab[1][ 5] = avg_rv40_qpel8_mc11_c;
- c->avg_rv40_qpel_pixels_tab[1][ 6] = avg_rv40_qpel8_mc21_c;
- c->avg_rv40_qpel_pixels_tab[1][ 7] = avg_rv40_qpel8_mc31_c;
- c->avg_rv40_qpel_pixels_tab[1][ 8] = avg_rv40_qpel8_mc02_c;
- c->avg_rv40_qpel_pixels_tab[1][ 9] = avg_rv40_qpel8_mc12_c;
- c->avg_rv40_qpel_pixels_tab[1][10] = avg_rv40_qpel8_mc22_c;
- c->avg_rv40_qpel_pixels_tab[1][11] = avg_rv40_qpel8_mc32_c;
- c->avg_rv40_qpel_pixels_tab[1][12] = avg_rv40_qpel8_mc03_c;
- c->avg_rv40_qpel_pixels_tab[1][13] = avg_rv40_qpel8_mc13_c;
- c->avg_rv40_qpel_pixels_tab[1][14] = avg_rv40_qpel8_mc23_c;
+#define RV40_WEIGHT_FUNC(size) \
+static void rv40_weight_func_ ## size (uint8_t *dst, uint8_t *src1, uint8_t *src2, int w1, int w2, int stride)\
+{\
+ int i, j;\
+\
+ for (j = 0; j < size; j++) {\
+ for (i = 0; i < size; i++)\
+ dst[i] = (((w2 * src1[i]) >> 9) + ((w1 * src2[i]) >> 9) + 0x10) >> 5;\
+ src1 += stride;\
+ src2 += stride;\
+ dst += stride;\
+ }\
+}
+
+RV40_WEIGHT_FUNC(16)
+RV40_WEIGHT_FUNC(8)
+
+av_cold void ff_rv40dsp_init(RV34DSPContext *c, DSPContext* dsp) {
+
+ ff_rv34dsp_init(c, dsp);
+
+ c->put_pixels_tab[0][ 0] = dsp->put_h264_qpel_pixels_tab[0][0];
+ c->put_pixels_tab[0][ 1] = put_rv40_qpel16_mc10_c;
+ c->put_pixels_tab[0][ 2] = dsp->put_h264_qpel_pixels_tab[0][2];
+ c->put_pixels_tab[0][ 3] = put_rv40_qpel16_mc30_c;
+ c->put_pixels_tab[0][ 4] = put_rv40_qpel16_mc01_c;
+ c->put_pixels_tab[0][ 5] = put_rv40_qpel16_mc11_c;
+ c->put_pixels_tab[0][ 6] = put_rv40_qpel16_mc21_c;
+ c->put_pixels_tab[0][ 7] = put_rv40_qpel16_mc31_c;
+ c->put_pixels_tab[0][ 8] = dsp->put_h264_qpel_pixels_tab[0][8];
+ c->put_pixels_tab[0][ 9] = put_rv40_qpel16_mc12_c;
+ c->put_pixels_tab[0][10] = put_rv40_qpel16_mc22_c;
+ c->put_pixels_tab[0][11] = put_rv40_qpel16_mc32_c;
+ c->put_pixels_tab[0][12] = put_rv40_qpel16_mc03_c;
+ c->put_pixels_tab[0][13] = put_rv40_qpel16_mc13_c;
+ c->put_pixels_tab[0][14] = put_rv40_qpel16_mc23_c;
+ c->put_pixels_tab[0][15] = ff_put_rv40_qpel16_mc33_c;
+ c->avg_pixels_tab[0][ 0] = dsp->avg_h264_qpel_pixels_tab[0][0];
+ c->avg_pixels_tab[0][ 1] = avg_rv40_qpel16_mc10_c;
+ c->avg_pixels_tab[0][ 2] = dsp->avg_h264_qpel_pixels_tab[0][2];
+ c->avg_pixels_tab[0][ 3] = avg_rv40_qpel16_mc30_c;
+ c->avg_pixels_tab[0][ 4] = avg_rv40_qpel16_mc01_c;
+ c->avg_pixels_tab[0][ 5] = avg_rv40_qpel16_mc11_c;
+ c->avg_pixels_tab[0][ 6] = avg_rv40_qpel16_mc21_c;
+ c->avg_pixels_tab[0][ 7] = avg_rv40_qpel16_mc31_c;
+ c->avg_pixels_tab[0][ 8] = dsp->avg_h264_qpel_pixels_tab[0][8];
+ c->avg_pixels_tab[0][ 9] = avg_rv40_qpel16_mc12_c;
+ c->avg_pixels_tab[0][10] = avg_rv40_qpel16_mc22_c;
+ c->avg_pixels_tab[0][11] = avg_rv40_qpel16_mc32_c;
+ c->avg_pixels_tab[0][12] = avg_rv40_qpel16_mc03_c;
+ c->avg_pixels_tab[0][13] = avg_rv40_qpel16_mc13_c;
+ c->avg_pixels_tab[0][14] = avg_rv40_qpel16_mc23_c;
+ c->avg_pixels_tab[0][15] = ff_avg_rv40_qpel16_mc33_c;
+ c->put_pixels_tab[1][ 0] = dsp->put_h264_qpel_pixels_tab[1][0];
+ c->put_pixels_tab[1][ 1] = put_rv40_qpel8_mc10_c;
+ c->put_pixels_tab[1][ 2] = dsp->put_h264_qpel_pixels_tab[1][2];
+ c->put_pixels_tab[1][ 3] = put_rv40_qpel8_mc30_c;
+ c->put_pixels_tab[1][ 4] = put_rv40_qpel8_mc01_c;
+ c->put_pixels_tab[1][ 5] = put_rv40_qpel8_mc11_c;
+ c->put_pixels_tab[1][ 6] = put_rv40_qpel8_mc21_c;
+ c->put_pixels_tab[1][ 7] = put_rv40_qpel8_mc31_c;
+ c->put_pixels_tab[1][ 8] = dsp->put_h264_qpel_pixels_tab[1][8];
+ c->put_pixels_tab[1][ 9] = put_rv40_qpel8_mc12_c;
+ c->put_pixels_tab[1][10] = put_rv40_qpel8_mc22_c;
+ c->put_pixels_tab[1][11] = put_rv40_qpel8_mc32_c;
+ c->put_pixels_tab[1][12] = put_rv40_qpel8_mc03_c;
+ c->put_pixels_tab[1][13] = put_rv40_qpel8_mc13_c;
+ c->put_pixels_tab[1][14] = put_rv40_qpel8_mc23_c;
+ c->put_pixels_tab[1][15] = ff_put_rv40_qpel8_mc33_c;
+ c->avg_pixels_tab[1][ 0] = dsp->avg_h264_qpel_pixels_tab[1][0];
+ c->avg_pixels_tab[1][ 1] = avg_rv40_qpel8_mc10_c;
+ c->avg_pixels_tab[1][ 2] = dsp->avg_h264_qpel_pixels_tab[1][2];
+ c->avg_pixels_tab[1][ 3] = avg_rv40_qpel8_mc30_c;
+ c->avg_pixels_tab[1][ 4] = avg_rv40_qpel8_mc01_c;
+ c->avg_pixels_tab[1][ 5] = avg_rv40_qpel8_mc11_c;
+ c->avg_pixels_tab[1][ 6] = avg_rv40_qpel8_mc21_c;
+ c->avg_pixels_tab[1][ 7] = avg_rv40_qpel8_mc31_c;
+ c->avg_pixels_tab[1][ 8] = dsp->avg_h264_qpel_pixels_tab[1][8];
+ c->avg_pixels_tab[1][ 9] = avg_rv40_qpel8_mc12_c;
+ c->avg_pixels_tab[1][10] = avg_rv40_qpel8_mc22_c;
+ c->avg_pixels_tab[1][11] = avg_rv40_qpel8_mc32_c;
+ c->avg_pixels_tab[1][12] = avg_rv40_qpel8_mc03_c;
+ c->avg_pixels_tab[1][13] = avg_rv40_qpel8_mc13_c;
+ c->avg_pixels_tab[1][14] = avg_rv40_qpel8_mc23_c;
+ c->avg_pixels_tab[1][15] = ff_avg_rv40_qpel8_mc33_c;
+
+ c->put_chroma_pixels_tab[0] = put_rv40_chroma_mc8_c;
+ c->put_chroma_pixels_tab[1] = put_rv40_chroma_mc4_c;
+ c->avg_chroma_pixels_tab[0] = avg_rv40_chroma_mc8_c;
+ c->avg_chroma_pixels_tab[1] = avg_rv40_chroma_mc4_c;
+
+ c->rv40_weight_pixels_tab[0] = rv40_weight_func_16;
+ c->rv40_weight_pixels_tab[1] = rv40_weight_func_8;
- c->put_rv40_chroma_pixels_tab[0]= put_rv40_chroma_mc8_c;
- c->put_rv40_chroma_pixels_tab[1]= put_rv40_chroma_mc4_c;
- c->avg_rv40_chroma_pixels_tab[0]= avg_rv40_chroma_mc8_c;
- c->avg_rv40_chroma_pixels_tab[1]= avg_rv40_chroma_mc4_c;
+ if (HAVE_MMX)
+ ff_rv40dsp_init_x86(c, dsp);
}
diff --git a/libavcodec/rv40vlc2.h b/libavcodec/rv40vlc2.h
index 2f63fc27e3..15119a145b 100644
--- a/libavcodec/rv40vlc2.h
+++ b/libavcodec/rv40vlc2.h
@@ -2,20 +2,20 @@
* RealVideo 4 decoder
* copyright (c) 2007 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/s302m.c b/libavcodec/s302m.c
index 2e261b612e..4db18eb2d0 100644
--- a/libavcodec/s302m.c
+++ b/libavcodec/s302m.c
@@ -3,20 +3,20 @@
* Copyright (c) 2008 Laurent Aimar <fenrir@videolan.org>
* Copyright (c) 2009 Baptiste Coudurier <baptiste.coudurier@gmail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -58,11 +58,21 @@ static int s302m_parse_frame_header(AVCodecContext *avctx, const uint8_t *buf,
/* Set output properties */
avctx->bits_per_coded_sample = bits;
if (bits > 16)
- avctx->sample_fmt = SAMPLE_FMT_S32;
+ avctx->sample_fmt = AV_SAMPLE_FMT_S32;
else
- avctx->sample_fmt = SAMPLE_FMT_S16;
+ avctx->sample_fmt = AV_SAMPLE_FMT_S16;
avctx->channels = channels;
+ switch(channels) {
+ case 2:
+ avctx->channel_layout = AV_CH_LAYOUT_STEREO;
+ break;
+ case 4:
+ avctx->channel_layout = AV_CH_LAYOUT_QUAD;
+ break;
+ case 8:
+ avctx->channel_layout = AV_CH_LAYOUT_5POINT1_BACK | AV_CH_LAYOUT_STEREO_DOWNMIX;
+ }
avctx->sample_rate = 48000;
avctx->bit_rate = 48000 * avctx->channels * (avctx->bits_per_coded_sample + 4) +
32 * (48000 / (buf_size * 8 /
diff --git a/libavcodec/s3tc.c b/libavcodec/s3tc.c
index e8ca688270..546ee2156f 100644
--- a/libavcodec/s3tc.c
+++ b/libavcodec/s3tc.c
@@ -4,20 +4,20 @@
*
* see also: http://wiki.multimedia.cx/index.php?title=S3TC
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/s3tc.h b/libavcodec/s3tc.h
index 45da6fa8ac..5116dc80f6 100644
--- a/libavcodec/s3tc.h
+++ b/libavcodec/s3tc.h
@@ -2,20 +2,20 @@
* S3 Texture Compression (S3TC) decoding functions
* Copyright (c) 2007 by Ivo van Poorten
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -29,8 +29,8 @@
/**
* Decode DXT1 encoded data to RGB32
- * @param *src source buffer, has to be aligned on a 4-byte boundary
- * @param *dst destination buffer
+ * @param src source buffer, has to be aligned on a 4-byte boundary
+ * @param dst destination buffer
* @param w width of output image
* @param h height of output image
* @param stride line size of output image
@@ -40,8 +40,8 @@ void ff_decode_dxt1(const uint8_t *src, uint8_t *dst,
const unsigned int stride);
/**
* Decode DXT3 encoded data to RGB32
- * @param *src source buffer, has to be aligned on a 4-byte boundary
- * @param *dst destination buffer
+ * @param src source buffer, has to be aligned on a 4-byte boundary
+ * @param dst destination buffer
* @param w width of output image
* @param h height of output image
* @param stride line size of output image
diff --git a/libavcodec/sbr.h b/libavcodec/sbr.h
index 5b0f334219..69c847ac15 100644
--- a/libavcodec/sbr.h
+++ b/libavcodec/sbr.h
@@ -3,20 +3,20 @@
* Copyright (c) 2008-2009 Robert Swain ( rob opendot cl )
* Copyright (c) 2010 Alex Converse <alex.converse@gmail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/sgi.h b/libavcodec/sgi.h
index ca531f00a1..be17f2e237 100644
--- a/libavcodec/sgi.h
+++ b/libavcodec/sgi.h
@@ -2,20 +2,20 @@
* SGI image encoder
* Xiaohui Sun <tjnksxh@hotmail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/sgidec.c b/libavcodec/sgidec.c
index 84cff35390..b0a0b20a5e 100644
--- a/libavcodec/sgidec.c
+++ b/libavcodec/sgidec.c
@@ -2,20 +2,20 @@
* SGI image decoder
* Todd Kirby <doubleshot@pacbell.net>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -260,14 +260,13 @@ static av_cold int sgi_end(AVCodecContext *avctx)
}
AVCodec ff_sgi_decoder = {
- "sgi",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_SGI,
- sizeof(SgiState),
- sgi_init,
- NULL,
- sgi_end,
- decode_frame,
+ .name = "sgi",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_SGI,
+ .priv_data_size = sizeof(SgiState),
+ .init = sgi_init,
+ .close = sgi_end,
+ .decode = decode_frame,
.long_name = NULL_IF_CONFIG_SMALL("SGI image"),
};
diff --git a/libavcodec/sgienc.c b/libavcodec/sgienc.c
index 202f676fc0..1fc6dcb244 100644
--- a/libavcodec/sgienc.c
+++ b/libavcodec/sgienc.c
@@ -2,20 +2,20 @@
* SGI image encoder
* Todd Kirby <doubleshot@pacbell.net>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -160,13 +160,12 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf,
}
AVCodec ff_sgi_encoder = {
- "sgi",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_SGI,
- sizeof(SgiContext),
- encode_init,
- encode_frame,
- NULL,
+ .name = "sgi",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_SGI,
+ .priv_data_size = sizeof(SgiContext),
+ .init = encode_init,
+ .encode = encode_frame,
.pix_fmts= (const enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGBA, PIX_FMT_GRAY8, PIX_FMT_NONE},
.long_name= NULL_IF_CONFIG_SMALL("SGI image"),
};
diff --git a/libavcodec/sh4/dsputil_align.c b/libavcodec/sh4/dsputil_align.c
index db40ece670..e91893683f 100644
--- a/libavcodec/sh4/dsputil_align.c
+++ b/libavcodec/sh4/dsputil_align.c
@@ -3,20 +3,20 @@
*
* Copyright (c) 2001-2003 BERO <bero@geocities.co.jp>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -333,7 +333,7 @@ DEFFUNC(avg,no_rnd,xy,16,OP_XY,PACK)
void dsputil_init_align(DSPContext* c, AVCodecContext *avctx)
{
- const int high_bit_depth = avctx->codec_id == CODEC_ID_H264 && avctx->bits_per_raw_sample > 8;
+ const int high_bit_depth = avctx->bits_per_raw_sample > 8;
if (!high_bit_depth) {
c->put_pixels_tab[0][0] = put_rnd_pixels16_o;
diff --git a/libavcodec/sh4/dsputil_sh4.c b/libavcodec/sh4/dsputil_sh4.c
index 9ea48ad4a1..905e8b15e0 100644
--- a/libavcodec/sh4/dsputil_sh4.c
+++ b/libavcodec/sh4/dsputil_sh4.c
@@ -3,20 +3,20 @@
*
* Copyright (c) 2003 BERO <bero@geocities.co.jp>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -92,12 +92,13 @@ static void idct_add(uint8_t *dest, int line_size, DCTELEM *block)
void dsputil_init_sh4(DSPContext* c, AVCodecContext *avctx)
{
const int idct_algo= avctx->idct_algo;
- const int high_bit_depth = avctx->codec_id == CODEC_ID_H264 && avctx->bits_per_raw_sample > 8;
+ const int high_bit_depth = avctx->bits_per_raw_sample > 8;
dsputil_init_align(c,avctx);
if (!high_bit_depth)
c->clear_blocks = clear_blocks_sh4;
- if(idct_algo==FF_IDCT_AUTO || idct_algo==FF_IDCT_SH4){
+ if (avctx->bits_per_raw_sample <= 8 &&
+ (idct_algo==FF_IDCT_AUTO || idct_algo==FF_IDCT_SH4)) {
c->idct_put = idct_put;
c->idct_add = idct_add;
c->idct = idct_sh4;
diff --git a/libavcodec/sh4/dsputil_sh4.h b/libavcodec/sh4/dsputil_sh4.h
index 5abe34557b..2e554e7370 100644
--- a/libavcodec/sh4/dsputil_sh4.h
+++ b/libavcodec/sh4/dsputil_sh4.h
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/sh4/idct_sh4.c b/libavcodec/sh4/idct_sh4.c
index 0baff396e0..13a85b030e 100644
--- a/libavcodec/sh4/idct_sh4.c
+++ b/libavcodec/sh4/idct_sh4.c
@@ -3,20 +3,20 @@
*
* Copyright (c) 2001-2003 BERO <bero@geocities.co.jp>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/sh4/qpel.c b/libavcodec/sh4/qpel.c
index 3242872e47..2e30ae1137 100644
--- a/libavcodec/sh4/qpel.c
+++ b/libavcodec/sh4/qpel.c
@@ -4,20 +4,20 @@
*
* copyright (c) 2001-2003 BERO <bero@geocities.co.jp>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/sh4/sh4.h b/libavcodec/sh4/sh4.h
index acd12e6ff6..5d46540cb6 100644
--- a/libavcodec/sh4/sh4.h
+++ b/libavcodec/sh4/sh4.h
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2008 Mans Rullgard <mans@mansr.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/shorten.c b/libavcodec/shorten.c
index e4dfa7c59f..df1daebb33 100644
--- a/libavcodec/shorten.c
+++ b/libavcodec/shorten.c
@@ -2,20 +2,20 @@
* Shorten decoder
* Copyright (c) 2005 Jeff Muizelaar
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -28,6 +28,7 @@
#include <limits.h>
#include "avcodec.h"
+#include "bytestream.h"
#include "get_bits.h"
#include "golomb.h"
@@ -69,6 +70,9 @@
#define FN_ZERO 8
#define FN_VERBATIM 9
+/** indicates if the FN_* command is audio or non-audio */
+static const uint8_t is_audio_command[10] = { 1, 1, 1, 1, 0, 0, 0, 1, 1, 0 };
+
#define VERBATIM_CKSIZE_SIZE 5
#define VERBATIM_BYTE_SIZE 8
#define CANONICAL_HEADER_SIZE 44
@@ -98,6 +102,8 @@ typedef struct ShortenContext {
int blocksize;
int bitindex;
int32_t lpcqoffset;
+ int got_header;
+ int got_quit_command;
} ShortenContext;
static av_cold int shorten_decode_init(AVCodecContext * avctx)
@@ -113,6 +119,7 @@ static int allocate_buffers(ShortenContext *s)
{
int i, chan;
int *coeffs;
+ void *tmp_ptr;
for (chan=0; chan<s->channels; chan++) {
if(FFMAX(1, s->nmean) >= UINT_MAX/sizeof(int32_t)){
@@ -124,9 +131,15 @@ static int allocate_buffers(ShortenContext *s)
return -1;
}
- s->offset[chan] = av_realloc(s->offset[chan], sizeof(int32_t)*FFMAX(1, s->nmean));
+ tmp_ptr = av_realloc(s->offset[chan], sizeof(int32_t)*FFMAX(1, s->nmean));
+ if (!tmp_ptr)
+ return AVERROR(ENOMEM);
+ s->offset[chan] = tmp_ptr;
- s->decoded[chan] = av_realloc(s->decoded[chan], sizeof(int32_t)*(s->blocksize + s->nwrap));
+ tmp_ptr = av_realloc(s->decoded[chan], sizeof(int32_t)*(s->blocksize + s->nwrap));
+ if (!tmp_ptr)
+ return AVERROR(ENOMEM);
+ s->decoded[chan] = tmp_ptr;
for (i=0; i<s->nwrap; i++)
s->decoded[chan][i] = 0;
s->decoded[chan] += s->nwrap;
@@ -155,7 +168,7 @@ static void fix_bitshift(ShortenContext *s, int32_t *buffer)
if (s->bitshift != 0)
for (i = 0; i < s->blocksize; i++)
- buffer[s->nwrap + i] <<= s->bitshift;
+ buffer[i] <<= s->bitshift;
}
@@ -181,47 +194,37 @@ static void init_offset(ShortenContext *s)
s->offset[chan][i] = mean;
}
-static inline int get_le32(GetBitContext *gb)
-{
- return av_bswap32(get_bits_long(gb, 32));
-}
-
-static inline short get_le16(GetBitContext *gb)
-{
- return av_bswap16(get_bits_long(gb, 16));
-}
-
-static int decode_wave_header(AVCodecContext *avctx, uint8_t *header, int header_size)
+static int decode_wave_header(AVCodecContext *avctx, const uint8_t *header,
+ int header_size)
{
- GetBitContext hb;
int len;
short wave_format;
- init_get_bits(&hb, header, header_size*8);
- if (get_le32(&hb) != MKTAG('R','I','F','F')) {
+
+ if (bytestream_get_le32(&header) != MKTAG('R','I','F','F')) {
av_log(avctx, AV_LOG_ERROR, "missing RIFF tag\n");
return -1;
}
- skip_bits_long(&hb, 32); /* chunk_size */
+ header += 4; /* chunk size */;
- if (get_le32(&hb) != MKTAG('W','A','V','E')) {
+ if (bytestream_get_le32(&header) != MKTAG('W','A','V','E')) {
av_log(avctx, AV_LOG_ERROR, "missing WAVE tag\n");
return -1;
}
- while (get_le32(&hb) != MKTAG('f','m','t',' ')) {
- len = get_le32(&hb);
- skip_bits(&hb, 8*len);
+ while (bytestream_get_le32(&header) != MKTAG('f','m','t',' ')) {
+ len = bytestream_get_le32(&header);
+ header += len;
}
- len = get_le32(&hb);
+ len = bytestream_get_le32(&header);
if (len < 16) {
av_log(avctx, AV_LOG_ERROR, "fmt chunk was too short\n");
return -1;
}
- wave_format = get_le16(&hb);
+ wave_format = bytestream_get_le16(&header);
switch (wave_format) {
case WAVE_FORMAT_PCM:
@@ -231,11 +234,11 @@ static int decode_wave_header(AVCodecContext *avctx, uint8_t *header, int header
return -1;
}
- avctx->channels = get_le16(&hb);
- avctx->sample_rate = get_le32(&hb);
- avctx->bit_rate = get_le32(&hb) * 8;
- avctx->block_align = get_le16(&hb);
- avctx->bits_per_coded_sample = get_le16(&hb);
+ header += 2; // skip channels (already got from shorten header)
+ avctx->sample_rate = bytestream_get_le32(&header);
+ header += 4; // skip bit rate (represents original uncompressed bit rate)
+ header += 2; // skip block align (not needed)
+ avctx->bits_per_coded_sample = bytestream_get_le16(&header);
if (avctx->bits_per_coded_sample != 16) {
av_log(avctx, AV_LOG_ERROR, "unsupported number of bits per sample\n");
@@ -253,26 +256,142 @@ static int16_t * interleave_buffer(int16_t *samples, int nchan, int blocksize, i
int i, chan;
for (i=0; i<blocksize; i++)
for (chan=0; chan < nchan; chan++)
- *samples++ = FFMIN(buffer[chan][i], 32768);
+ *samples++ = av_clip_int16(buffer[chan][i]);
return samples;
}
-static void decode_subframe_lpc(ShortenContext *s, int channel, int residual_size, int pred_order)
+static const int fixed_coeffs[3][3] = {
+ { 1, 0, 0 },
+ { 2, -1, 0 },
+ { 3, -3, 1 }
+};
+
+static int decode_subframe_lpc(ShortenContext *s, int command, int channel,
+ int residual_size, int32_t coffset)
{
- int sum, i, j;
- int *coeffs = s->coeffs;
+ int pred_order, sum, qshift, init_sum, i, j;
+ const int *coeffs;
+
+ if (command == FN_QLPC) {
+ /* read/validate prediction order */
+ pred_order = get_ur_golomb_shorten(&s->gb, LPCQSIZE);
+ if (pred_order > s->nwrap) {
+ av_log(s->avctx, AV_LOG_ERROR, "invalid pred_order %d\n", pred_order);
+ return AVERROR(EINVAL);
+ }
+ /* read LPC coefficients */
+ for (i=0; i<pred_order; i++)
+ s->coeffs[i] = get_sr_golomb_shorten(&s->gb, LPCQUANT);
+ coeffs = s->coeffs;
+
+ qshift = LPCQUANT;
+ } else {
+ /* fixed LPC coeffs */
+ pred_order = command;
+ coeffs = fixed_coeffs[pred_order-1];
+ qshift = 0;
+ }
- for (i=0; i<pred_order; i++)
- coeffs[i] = get_sr_golomb_shorten(&s->gb, LPCQUANT);
+ /* subtract offset from previous samples to use in prediction */
+ if (command == FN_QLPC && coffset)
+ for (i = -pred_order; i < 0; i++)
+ s->decoded[channel][i] -= coffset;
+ /* decode residual and do LPC prediction */
+ init_sum = pred_order ? (command == FN_QLPC ? s->lpcqoffset : 0) : coffset;
for (i=0; i < s->blocksize; i++) {
- sum = s->lpcqoffset;
+ sum = init_sum;
for (j=0; j<pred_order; j++)
sum += coeffs[j] * s->decoded[channel][i-j-1];
- s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) + (sum >> LPCQUANT);
+ s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) + (sum >> qshift);
}
+
+ /* add offset to current samples */
+ if (command == FN_QLPC && coffset)
+ for (i = 0; i < s->blocksize; i++)
+ s->decoded[channel][i] += coffset;
+
+ return 0;
}
+static int read_header(ShortenContext *s)
+{
+ int i, ret;
+ int maxnlpc = 0;
+ /* shorten signature */
+ if (get_bits_long(&s->gb, 32) != AV_RB32("ajkg")) {
+ av_log(s->avctx, AV_LOG_ERROR, "missing shorten magic 'ajkg'\n");
+ return -1;
+ }
+
+ s->lpcqoffset = 0;
+ s->blocksize = DEFAULT_BLOCK_SIZE;
+ s->channels = 1;
+ s->nmean = -1;
+ s->version = get_bits(&s->gb, 8);
+ s->internal_ftype = get_uint(s, TYPESIZE);
+
+ s->channels = get_uint(s, CHANSIZE);
+ if (s->channels > MAX_CHANNELS) {
+ av_log(s->avctx, AV_LOG_ERROR, "too many channels: %d\n", s->channels);
+ return -1;
+ }
+ s->avctx->channels = s->channels;
+
+ /* get blocksize if version > 0 */
+ if (s->version > 0) {
+ int skip_bytes, blocksize;
+
+ blocksize = get_uint(s, av_log2(DEFAULT_BLOCK_SIZE));
+ if (!blocksize || blocksize > MAX_BLOCKSIZE) {
+ av_log(s->avctx, AV_LOG_ERROR, "invalid or unsupported block size: %d\n",
+ blocksize);
+ return AVERROR(EINVAL);
+ }
+ s->blocksize = blocksize;
+
+ maxnlpc = get_uint(s, LPCQSIZE);
+ s->nmean = get_uint(s, 0);
+
+ skip_bytes = get_uint(s, NSKIPSIZE);
+ for (i=0; i<skip_bytes; i++) {
+ skip_bits(&s->gb, 8);
+ }
+ }
+ s->nwrap = FFMAX(NWRAP, maxnlpc);
+
+ if ((ret = allocate_buffers(s)) < 0)
+ return ret;
+
+ init_offset(s);
+
+ if (s->version > 1)
+ s->lpcqoffset = V2LPCQOFFSET;
+
+ if (get_ur_golomb_shorten(&s->gb, FNSIZE) != FN_VERBATIM) {
+ av_log(s->avctx, AV_LOG_ERROR, "missing verbatim section at beginning of stream\n");
+ return -1;
+ }
+
+ s->header_size = get_ur_golomb_shorten(&s->gb, VERBATIM_CKSIZE_SIZE);
+ if (s->header_size >= OUT_BUFFER_SIZE || s->header_size < CANONICAL_HEADER_SIZE) {
+ av_log(s->avctx, AV_LOG_ERROR, "header is wrong size: %d\n", s->header_size);
+ return -1;
+ }
+
+ for (i=0; i<s->header_size; i++)
+ s->header[i] = (char)get_ur_golomb_shorten(&s->gb, VERBATIM_BYTE_SIZE);
+
+ if (decode_wave_header(s->avctx, s->header, s->header_size) < 0)
+ return -1;
+
+ s->cur_chan = 0;
+ s->bitshift = 0;
+
+ s->got_header = 1;
+
+ return 0;
+}
static int shorten_decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
@@ -283,220 +402,189 @@ static int shorten_decode_frame(AVCodecContext *avctx,
ShortenContext *s = avctx->priv_data;
int i, input_buf_size = 0;
int16_t *samples = data;
+ int ret;
+
+ /* allocate internal bitstream buffer */
if(s->max_framesize == 0){
+ void *tmp_ptr;
s->max_framesize= 1024; // should hopefully be enough for the first header
- s->bitstream= av_fast_realloc(s->bitstream, &s->allocated_bitstream_size, s->max_framesize);
+ tmp_ptr = av_fast_realloc(s->bitstream, &s->allocated_bitstream_size,
+ s->max_framesize);
+ if (!tmp_ptr) {
+ av_log(avctx, AV_LOG_ERROR, "error allocating bitstream buffer\n");
+ return AVERROR(ENOMEM);
+ }
+ s->bitstream = tmp_ptr;
}
+ /* append current packet data to bitstream buffer */
if(1 && s->max_framesize){//FIXME truncated
buf_size= FFMIN(buf_size, s->max_framesize - s->bitstream_size);
input_buf_size= buf_size;
if(s->bitstream_index + s->bitstream_size + buf_size > s->allocated_bitstream_size){
- // printf("memmove\n");
memmove(s->bitstream, &s->bitstream[s->bitstream_index], s->bitstream_size);
s->bitstream_index=0;
}
- memcpy(&s->bitstream[s->bitstream_index + s->bitstream_size], buf, buf_size);
+ if (buf)
+ memcpy(&s->bitstream[s->bitstream_index + s->bitstream_size], buf, buf_size);
buf= &s->bitstream[s->bitstream_index];
buf_size += s->bitstream_size;
s->bitstream_size= buf_size;
- if(buf_size < s->max_framesize){
+ /* do not decode until buffer has at least max_framesize bytes or
+ the end of the file has been reached */
+ if (buf_size < s->max_framesize && avpkt->data) {
*data_size = 0;
return input_buf_size;
}
}
+ /* init and position bitstream reader */
init_get_bits(&s->gb, buf, buf_size*8);
skip_bits(&s->gb, s->bitindex);
- if (!s->blocksize)
- {
- int maxnlpc = 0;
- /* shorten signature */
- if (get_bits_long(&s->gb, 32) != AV_RB32("ajkg")) {
- av_log(s->avctx, AV_LOG_ERROR, "missing shorten magic 'ajkg'\n");
- return -1;
- }
- s->lpcqoffset = 0;
- s->blocksize = DEFAULT_BLOCK_SIZE;
- s->channels = 1;
- s->nmean = -1;
- s->version = get_bits(&s->gb, 8);
- s->internal_ftype = get_uint(s, TYPESIZE);
+ /* process header or next subblock */
+ if (!s->got_header) {
+ if ((ret = read_header(s)) < 0)
+ return ret;
+ *data_size = 0;
+ goto finish_frame;
+ }
- s->channels = get_uint(s, CHANSIZE);
- if (s->channels > MAX_CHANNELS) {
- av_log(s->avctx, AV_LOG_ERROR, "too many channels: %d\n", s->channels);
- return -1;
- }
+ /* if quit command was read previously, don't decode anything */
+ if (s->got_quit_command) {
+ *data_size = 0;
+ return avpkt->size;
+ }
- /* get blocksize if version > 0 */
- if (s->version > 0) {
- int skip_bytes;
- s->blocksize = get_uint(s, av_log2(DEFAULT_BLOCK_SIZE));
- maxnlpc = get_uint(s, LPCQSIZE);
- s->nmean = get_uint(s, 0);
+ s->cur_chan = 0;
+ while (s->cur_chan < s->channels) {
+ int cmd;
+ int len;
- skip_bytes = get_uint(s, NSKIPSIZE);
- for (i=0; i<skip_bytes; i++) {
- skip_bits(&s->gb, 8);
- }
+ if (get_bits_left(&s->gb) < 3+FNSIZE) {
+ *data_size = 0;
+ break;
}
- s->nwrap = FFMAX(NWRAP, maxnlpc);
-
- if (allocate_buffers(s))
- return -1;
-
- init_offset(s);
- if (s->version > 1)
- s->lpcqoffset = V2LPCQOFFSET;
+ cmd = get_ur_golomb_shorten(&s->gb, FNSIZE);
- if (get_ur_golomb_shorten(&s->gb, FNSIZE) != FN_VERBATIM) {
- av_log(s->avctx, AV_LOG_ERROR, "missing verbatim section at beginning of stream\n");
- return -1;
+ if (cmd > FN_VERBATIM) {
+ av_log(avctx, AV_LOG_ERROR, "unknown shorten function %d\n", cmd);
+ *data_size = 0;
+ break;
}
- s->header_size = get_ur_golomb_shorten(&s->gb, VERBATIM_CKSIZE_SIZE);
- if (s->header_size >= OUT_BUFFER_SIZE || s->header_size < CANONICAL_HEADER_SIZE) {
- av_log(s->avctx, AV_LOG_ERROR, "header is wrong size: %d\n", s->header_size);
- return -1;
- }
+ if (!is_audio_command[cmd]) {
+ /* process non-audio command */
+ switch (cmd) {
+ case FN_VERBATIM:
+ len = get_ur_golomb_shorten(&s->gb, VERBATIM_CKSIZE_SIZE);
+ while (len--) {
+ get_ur_golomb_shorten(&s->gb, VERBATIM_BYTE_SIZE);
+ }
+ break;
+ case FN_BITSHIFT:
+ s->bitshift = get_ur_golomb_shorten(&s->gb, BITSHIFTSIZE);
+ break;
+ case FN_BLOCKSIZE: {
+ int blocksize = get_uint(s, av_log2(s->blocksize));
+ if (blocksize > s->blocksize) {
+ av_log(avctx, AV_LOG_ERROR, "Increasing block size is not supported\n");
+ return AVERROR_PATCHWELCOME;
+ }
+ if (!blocksize || blocksize > MAX_BLOCKSIZE) {
+ av_log(avctx, AV_LOG_ERROR, "invalid or unsupported "
+ "block size: %d\n", blocksize);
+ return AVERROR(EINVAL);
+ }
+ s->blocksize = blocksize;
+ break;
+ }
+ case FN_QUIT:
+ s->got_quit_command = 1;
+ break;
+ }
+ if (cmd == FN_BLOCKSIZE || cmd == FN_QUIT) {
+ *data_size = 0;
+ break;
+ }
+ } else {
+ /* process audio command */
+ int residual_size = 0;
+ int channel = s->cur_chan;
+ int32_t coffset;
+
+ /* get Rice code for residual decoding */
+ if (cmd != FN_ZERO) {
+ residual_size = get_ur_golomb_shorten(&s->gb, ENERGYSIZE);
+ /* this is a hack as version 0 differed in defintion of get_sr_golomb_shorten */
+ if (s->version == 0)
+ residual_size--;
+ }
- for (i=0; i<s->header_size; i++)
- s->header[i] = (char)get_ur_golomb_shorten(&s->gb, VERBATIM_BYTE_SIZE);
+ /* calculate sample offset using means from previous blocks */
+ if (s->nmean == 0)
+ coffset = s->offset[channel][0];
+ else {
+ int32_t sum = (s->version < 2) ? 0 : s->nmean / 2;
+ for (i=0; i<s->nmean; i++)
+ sum += s->offset[channel][i];
+ coffset = sum / s->nmean;
+ if (s->version >= 2)
+ coffset >>= FFMIN(1, s->bitshift);
+ }
- if (decode_wave_header(avctx, s->header, s->header_size) < 0)
- return -1;
+ /* decode samples for this channel */
+ if (cmd == FN_ZERO) {
+ for (i=0; i<s->blocksize; i++)
+ s->decoded[channel][i] = 0;
+ } else {
+ if ((ret = decode_subframe_lpc(s, cmd, channel, residual_size, coffset)) < 0)
+ return ret;
+ }
- s->cur_chan = 0;
- s->bitshift = 0;
- }
- else
- {
- int cmd;
- int len;
- cmd = get_ur_golomb_shorten(&s->gb, FNSIZE);
- switch (cmd) {
- case FN_ZERO:
- case FN_DIFF0:
- case FN_DIFF1:
- case FN_DIFF2:
- case FN_DIFF3:
- case FN_QLPC:
- {
- int residual_size = 0;
- int channel = s->cur_chan;
- int32_t coffset;
- if (cmd != FN_ZERO) {
- residual_size = get_ur_golomb_shorten(&s->gb, ENERGYSIZE);
- /* this is a hack as version 0 differed in defintion of get_sr_golomb_shorten */
- if (s->version == 0)
- residual_size--;
- }
+ /* update means with info from the current block */
+ if (s->nmean > 0) {
+ int32_t sum = (s->version < 2) ? 0 : s->blocksize / 2;
+ for (i=0; i<s->blocksize; i++)
+ sum += s->decoded[channel][i];
- if (s->nmean == 0)
- coffset = s->offset[channel][0];
- else {
- int32_t sum = (s->version < 2) ? 0 : s->nmean / 2;
- for (i=0; i<s->nmean; i++)
- sum += s->offset[channel][i];
- coffset = sum / s->nmean;
- if (s->version >= 2)
- coffset >>= FFMIN(1, s->bitshift);
- }
- switch (cmd) {
- case FN_ZERO:
- for (i=0; i<s->blocksize; i++)
- s->decoded[channel][i] = 0;
- break;
- case FN_DIFF0:
- for (i=0; i<s->blocksize; i++)
- s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) + coffset;
- break;
- case FN_DIFF1:
- for (i=0; i<s->blocksize; i++)
- s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) + s->decoded[channel][i - 1];
- break;
- case FN_DIFF2:
- for (i=0; i<s->blocksize; i++)
- s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) + 2*s->decoded[channel][i-1]
- - s->decoded[channel][i-2];
- break;
- case FN_DIFF3:
- for (i=0; i<s->blocksize; i++)
- s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) + 3*s->decoded[channel][i-1]
- - 3*s->decoded[channel][i-2]
- + s->decoded[channel][i-3];
- break;
- case FN_QLPC:
- {
- int pred_order = get_ur_golomb_shorten(&s->gb, LPCQSIZE);
- if (pred_order > s->nwrap) {
- av_log(avctx, AV_LOG_ERROR,
- "invalid pred_order %d\n",
- pred_order);
- return -1;
- }
- for (i=0; i<pred_order; i++)
- s->decoded[channel][i - pred_order] -= coffset;
- decode_subframe_lpc(s, channel, residual_size, pred_order);
- if (coffset != 0)
- for (i=0; i < s->blocksize; i++)
- s->decoded[channel][i] += coffset;
- }
- }
- if (s->nmean > 0) {
- int32_t sum = (s->version < 2) ? 0 : s->blocksize / 2;
- for (i=0; i<s->blocksize; i++)
- sum += s->decoded[channel][i];
-
- for (i=1; i<s->nmean; i++)
- s->offset[channel][i-1] = s->offset[channel][i];
-
- if (s->version < 2)
- s->offset[channel][s->nmean - 1] = sum / s->blocksize;
- else
- s->offset[channel][s->nmean - 1] = (sum / s->blocksize) << s->bitshift;
- }
- for (i=-s->nwrap; i<0; i++)
- s->decoded[channel][i] = s->decoded[channel][i + s->blocksize];
+ for (i=1; i<s->nmean; i++)
+ s->offset[channel][i-1] = s->offset[channel][i];
- fix_bitshift(s, s->decoded[channel]);
+ if (s->version < 2)
+ s->offset[channel][s->nmean - 1] = sum / s->blocksize;
+ else
+ s->offset[channel][s->nmean - 1] = (sum / s->blocksize) << s->bitshift;
+ }
- s->cur_chan++;
- if (s->cur_chan == s->channels) {
- samples = interleave_buffer(samples, s->channels, s->blocksize, s->decoded);
- s->cur_chan = 0;
- goto frame_done;
- }
- }
- break;
- case FN_VERBATIM:
- len = get_ur_golomb_shorten(&s->gb, VERBATIM_CKSIZE_SIZE);
- while (len--) {
- get_ur_golomb_shorten(&s->gb, VERBATIM_BYTE_SIZE);
+ /* copy wrap samples for use with next block */
+ for (i=-s->nwrap; i<0; i++)
+ s->decoded[channel][i] = s->decoded[channel][i + s->blocksize];
+
+ /* shift samples to add in unused zero bits which were removed
+ during encoding */
+ fix_bitshift(s, s->decoded[channel]);
+
+ /* if this is the last channel in the block, output the samples */
+ s->cur_chan++;
+ if (s->cur_chan == s->channels) {
+ int out_size = s->blocksize * s->channels *
+ av_get_bytes_per_sample(avctx->sample_fmt);
+ if (*data_size < out_size) {
+ av_log(avctx, AV_LOG_ERROR, "Output buffer is too small\n");
+ return AVERROR(EINVAL);
}
- break;
- case FN_BITSHIFT:
- s->bitshift = get_ur_golomb_shorten(&s->gb, BITSHIFTSIZE);
- break;
- case FN_BLOCKSIZE:
- s->blocksize = get_uint(s, av_log2(s->blocksize));
- break;
- case FN_QUIT:
- *data_size = 0;
- return buf_size;
- default:
- av_log(avctx, AV_LOG_ERROR, "unknown shorten function %d\n", cmd);
- return -1;
+ samples = interleave_buffer(samples, s->channels, s->blocksize, s->decoded);
+ *data_size = out_size;
+ }
}
}
-frame_done:
- *data_size = (int8_t *)samples - (int8_t *)data;
+ if (s->cur_chan < s->channels)
+ *data_size = 0;
- // s->last_blocksize = s->blocksize;
+finish_frame:
s->bitindex = get_bits_count(&s->gb) - 8*((get_bits_count(&s->gb))/8);
i= (get_bits_count(&s->gb))/8;
if (i > buf_size) {
@@ -528,22 +616,14 @@ static av_cold int shorten_decode_close(AVCodecContext *avctx)
return 0;
}
-static void shorten_flush(AVCodecContext *avctx){
- ShortenContext *s = avctx->priv_data;
-
- s->bitstream_size=
- s->bitstream_index= 0;
-}
-
AVCodec ff_shorten_decoder = {
- "shorten",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_SHORTEN,
- sizeof(ShortenContext),
- shorten_decode_init,
- NULL,
- shorten_decode_close,
- shorten_decode_frame,
- .flush= shorten_flush,
+ .name = "shorten",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_SHORTEN,
+ .priv_data_size = sizeof(ShortenContext),
+ .init = shorten_decode_init,
+ .close = shorten_decode_close,
+ .decode = shorten_decode_frame,
+ .capabilities = CODEC_CAP_DELAY,
.long_name= NULL_IF_CONFIG_SMALL("Shorten"),
};
diff --git a/libavcodec/simple_idct.c b/libavcodec/simple_idct.c
index 4af11bec51..0676cf65fc 100644
--- a/libavcodec/simple_idct.c
+++ b/libavcodec/simple_idct.c
@@ -3,20 +3,20 @@
*
* Copyright (c) 2001 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -25,378 +25,19 @@
* simpleidct in C.
*/
-/*
- based upon some outcommented c code from mpeg2dec (idct_mmx.c
- written by Aaron Holtzman <aholtzma@ess.engr.uvic.ca>)
- */
+#include "libavutil/intreadwrite.h"
#include "avcodec.h"
#include "dsputil.h"
#include "mathops.h"
#include "simple_idct.h"
-#if 0
-#define W1 2841 /* 2048*sqrt (2)*cos (1*pi/16) */
-#define W2 2676 /* 2048*sqrt (2)*cos (2*pi/16) */
-#define W3 2408 /* 2048*sqrt (2)*cos (3*pi/16) */
-#define W4 2048 /* 2048*sqrt (2)*cos (4*pi/16) */
-#define W5 1609 /* 2048*sqrt (2)*cos (5*pi/16) */
-#define W6 1108 /* 2048*sqrt (2)*cos (6*pi/16) */
-#define W7 565 /* 2048*sqrt (2)*cos (7*pi/16) */
-#define ROW_SHIFT 8
-#define COL_SHIFT 17
-#else
-#define W1 22725 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
-#define W2 21407 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
-#define W3 19266 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
-#define W4 16383 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
-#define W5 12873 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
-#define W6 8867 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
-#define W7 4520 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
-#define ROW_SHIFT 11
-#define COL_SHIFT 20 // 6
-#endif
-
-static inline void idctRowCondDC (DCTELEM * row)
-{
- int a0, a1, a2, a3, b0, b1, b2, b3;
-#if HAVE_FAST_64BIT
- uint64_t temp;
-#else
- uint32_t temp;
-#endif
-
-#if HAVE_FAST_64BIT
-#if HAVE_BIGENDIAN
-#define ROW0_MASK 0xffff000000000000LL
-#else
-#define ROW0_MASK 0xffffLL
-#endif
- if(sizeof(DCTELEM)==2){
- if ( ((((uint64_t *)row)[0] & ~ROW0_MASK) |
- ((uint64_t *)row)[1]) == 0) {
- temp = (row[0] << 3) & 0xffff;
- temp += temp << 16;
- temp += temp << 32;
- ((uint64_t *)row)[0] = temp;
- ((uint64_t *)row)[1] = temp;
- return;
- }
- }else{
- if (!(row[1]|row[2]|row[3]|row[4]|row[5]|row[6]|row[7])) {
- row[0]=row[1]=row[2]=row[3]=row[4]=row[5]=row[6]=row[7]= row[0] << 3;
- return;
- }
- }
-#else
- if(sizeof(DCTELEM)==2){
- if (!(((uint32_t*)row)[1] |
- ((uint32_t*)row)[2] |
- ((uint32_t*)row)[3] |
- row[1])) {
- temp = (row[0] << 3) & 0xffff;
- temp += temp << 16;
- ((uint32_t*)row)[0]=((uint32_t*)row)[1] =
- ((uint32_t*)row)[2]=((uint32_t*)row)[3] = temp;
- return;
- }
- }else{
- if (!(row[1]|row[2]|row[3]|row[4]|row[5]|row[6]|row[7])) {
- row[0]=row[1]=row[2]=row[3]=row[4]=row[5]=row[6]=row[7]= row[0] << 3;
- return;
- }
- }
-#endif
-
- a0 = (W4 * row[0]) + (1 << (ROW_SHIFT - 1));
- a1 = a0;
- a2 = a0;
- a3 = a0;
-
- /* no need to optimize : gcc does it */
- a0 += W2 * row[2];
- a1 += W6 * row[2];
- a2 -= W6 * row[2];
- a3 -= W2 * row[2];
-
- b0 = MUL16(W1, row[1]);
- MAC16(b0, W3, row[3]);
- b1 = MUL16(W3, row[1]);
- MAC16(b1, -W7, row[3]);
- b2 = MUL16(W5, row[1]);
- MAC16(b2, -W1, row[3]);
- b3 = MUL16(W7, row[1]);
- MAC16(b3, -W5, row[3]);
-
-#if HAVE_FAST_64BIT
- temp = ((uint64_t*)row)[1];
-#else
- temp = ((uint32_t*)row)[2] | ((uint32_t*)row)[3];
-#endif
- if (temp != 0) {
- a0 += W4*row[4] + W6*row[6];
- a1 += - W4*row[4] - W2*row[6];
- a2 += - W4*row[4] + W2*row[6];
- a3 += W4*row[4] - W6*row[6];
-
- MAC16(b0, W5, row[5]);
- MAC16(b0, W7, row[7]);
-
- MAC16(b1, -W1, row[5]);
- MAC16(b1, -W5, row[7]);
-
- MAC16(b2, W7, row[5]);
- MAC16(b2, W3, row[7]);
-
- MAC16(b3, W3, row[5]);
- MAC16(b3, -W1, row[7]);
- }
-
- row[0] = (a0 + b0) >> ROW_SHIFT;
- row[7] = (a0 - b0) >> ROW_SHIFT;
- row[1] = (a1 + b1) >> ROW_SHIFT;
- row[6] = (a1 - b1) >> ROW_SHIFT;
- row[2] = (a2 + b2) >> ROW_SHIFT;
- row[5] = (a2 - b2) >> ROW_SHIFT;
- row[3] = (a3 + b3) >> ROW_SHIFT;
- row[4] = (a3 - b3) >> ROW_SHIFT;
-}
-
-static inline void idctSparseColPut (uint8_t *dest, int line_size,
- DCTELEM * col)
-{
- int a0, a1, a2, a3, b0, b1, b2, b3;
- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
-
- /* XXX: I did that only to give same values as previous code */
- a0 = W4 * (col[8*0] + ((1<<(COL_SHIFT-1))/W4));
- a1 = a0;
- a2 = a0;
- a3 = a0;
-
- a0 += + W2*col[8*2];
- a1 += + W6*col[8*2];
- a2 += - W6*col[8*2];
- a3 += - W2*col[8*2];
-
- b0 = MUL16(W1, col[8*1]);
- b1 = MUL16(W3, col[8*1]);
- b2 = MUL16(W5, col[8*1]);
- b3 = MUL16(W7, col[8*1]);
-
- MAC16(b0, + W3, col[8*3]);
- MAC16(b1, - W7, col[8*3]);
- MAC16(b2, - W1, col[8*3]);
- MAC16(b3, - W5, col[8*3]);
-
- if(col[8*4]){
- a0 += + W4*col[8*4];
- a1 += - W4*col[8*4];
- a2 += - W4*col[8*4];
- a3 += + W4*col[8*4];
- }
-
- if (col[8*5]) {
- MAC16(b0, + W5, col[8*5]);
- MAC16(b1, - W1, col[8*5]);
- MAC16(b2, + W7, col[8*5]);
- MAC16(b3, + W3, col[8*5]);
- }
-
- if(col[8*6]){
- a0 += + W6*col[8*6];
- a1 += - W2*col[8*6];
- a2 += + W2*col[8*6];
- a3 += - W6*col[8*6];
- }
-
- if (col[8*7]) {
- MAC16(b0, + W7, col[8*7]);
- MAC16(b1, - W5, col[8*7]);
- MAC16(b2, + W3, col[8*7]);
- MAC16(b3, - W1, col[8*7]);
- }
-
- dest[0] = cm[(a0 + b0) >> COL_SHIFT];
- dest += line_size;
- dest[0] = cm[(a1 + b1) >> COL_SHIFT];
- dest += line_size;
- dest[0] = cm[(a2 + b2) >> COL_SHIFT];
- dest += line_size;
- dest[0] = cm[(a3 + b3) >> COL_SHIFT];
- dest += line_size;
- dest[0] = cm[(a3 - b3) >> COL_SHIFT];
- dest += line_size;
- dest[0] = cm[(a2 - b2) >> COL_SHIFT];
- dest += line_size;
- dest[0] = cm[(a1 - b1) >> COL_SHIFT];
- dest += line_size;
- dest[0] = cm[(a0 - b0) >> COL_SHIFT];
-}
-
-static inline void idctSparseColAdd (uint8_t *dest, int line_size,
- DCTELEM * col)
-{
- int a0, a1, a2, a3, b0, b1, b2, b3;
- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
-
- /* XXX: I did that only to give same values as previous code */
- a0 = W4 * (col[8*0] + ((1<<(COL_SHIFT-1))/W4));
- a1 = a0;
- a2 = a0;
- a3 = a0;
-
- a0 += + W2*col[8*2];
- a1 += + W6*col[8*2];
- a2 += - W6*col[8*2];
- a3 += - W2*col[8*2];
-
- b0 = MUL16(W1, col[8*1]);
- b1 = MUL16(W3, col[8*1]);
- b2 = MUL16(W5, col[8*1]);
- b3 = MUL16(W7, col[8*1]);
-
- MAC16(b0, + W3, col[8*3]);
- MAC16(b1, - W7, col[8*3]);
- MAC16(b2, - W1, col[8*3]);
- MAC16(b3, - W5, col[8*3]);
-
- if(col[8*4]){
- a0 += + W4*col[8*4];
- a1 += - W4*col[8*4];
- a2 += - W4*col[8*4];
- a3 += + W4*col[8*4];
- }
-
- if (col[8*5]) {
- MAC16(b0, + W5, col[8*5]);
- MAC16(b1, - W1, col[8*5]);
- MAC16(b2, + W7, col[8*5]);
- MAC16(b3, + W3, col[8*5]);
- }
-
- if(col[8*6]){
- a0 += + W6*col[8*6];
- a1 += - W2*col[8*6];
- a2 += + W2*col[8*6];
- a3 += - W6*col[8*6];
- }
+#define BIT_DEPTH 8
+#include "simple_idct_template.c"
+#undef BIT_DEPTH
- if (col[8*7]) {
- MAC16(b0, + W7, col[8*7]);
- MAC16(b1, - W5, col[8*7]);
- MAC16(b2, + W3, col[8*7]);
- MAC16(b3, - W1, col[8*7]);
- }
-
- dest[0] = cm[dest[0] + ((a0 + b0) >> COL_SHIFT)];
- dest += line_size;
- dest[0] = cm[dest[0] + ((a1 + b1) >> COL_SHIFT)];
- dest += line_size;
- dest[0] = cm[dest[0] + ((a2 + b2) >> COL_SHIFT)];
- dest += line_size;
- dest[0] = cm[dest[0] + ((a3 + b3) >> COL_SHIFT)];
- dest += line_size;
- dest[0] = cm[dest[0] + ((a3 - b3) >> COL_SHIFT)];
- dest += line_size;
- dest[0] = cm[dest[0] + ((a2 - b2) >> COL_SHIFT)];
- dest += line_size;
- dest[0] = cm[dest[0] + ((a1 - b1) >> COL_SHIFT)];
- dest += line_size;
- dest[0] = cm[dest[0] + ((a0 - b0) >> COL_SHIFT)];
-}
-
-static inline void idctSparseCol (DCTELEM * col)
-{
- int a0, a1, a2, a3, b0, b1, b2, b3;
-
- /* XXX: I did that only to give same values as previous code */
- a0 = W4 * (col[8*0] + ((1<<(COL_SHIFT-1))/W4));
- a1 = a0;
- a2 = a0;
- a3 = a0;
-
- a0 += + W2*col[8*2];
- a1 += + W6*col[8*2];
- a2 += - W6*col[8*2];
- a3 += - W2*col[8*2];
-
- b0 = MUL16(W1, col[8*1]);
- b1 = MUL16(W3, col[8*1]);
- b2 = MUL16(W5, col[8*1]);
- b3 = MUL16(W7, col[8*1]);
-
- MAC16(b0, + W3, col[8*3]);
- MAC16(b1, - W7, col[8*3]);
- MAC16(b2, - W1, col[8*3]);
- MAC16(b3, - W5, col[8*3]);
-
- if(col[8*4]){
- a0 += + W4*col[8*4];
- a1 += - W4*col[8*4];
- a2 += - W4*col[8*4];
- a3 += + W4*col[8*4];
- }
-
- if (col[8*5]) {
- MAC16(b0, + W5, col[8*5]);
- MAC16(b1, - W1, col[8*5]);
- MAC16(b2, + W7, col[8*5]);
- MAC16(b3, + W3, col[8*5]);
- }
-
- if(col[8*6]){
- a0 += + W6*col[8*6];
- a1 += - W2*col[8*6];
- a2 += + W2*col[8*6];
- a3 += - W6*col[8*6];
- }
-
- if (col[8*7]) {
- MAC16(b0, + W7, col[8*7]);
- MAC16(b1, - W5, col[8*7]);
- MAC16(b2, + W3, col[8*7]);
- MAC16(b3, - W1, col[8*7]);
- }
-
- col[0 ] = ((a0 + b0) >> COL_SHIFT);
- col[8 ] = ((a1 + b1) >> COL_SHIFT);
- col[16] = ((a2 + b2) >> COL_SHIFT);
- col[24] = ((a3 + b3) >> COL_SHIFT);
- col[32] = ((a3 - b3) >> COL_SHIFT);
- col[40] = ((a2 - b2) >> COL_SHIFT);
- col[48] = ((a1 - b1) >> COL_SHIFT);
- col[56] = ((a0 - b0) >> COL_SHIFT);
-}
-
-void ff_simple_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
-{
- int i;
- for(i=0; i<8; i++)
- idctRowCondDC(block + i*8);
-
- for(i=0; i<8; i++)
- idctSparseColPut(dest + i, line_size, block + i);
-}
-
-void ff_simple_idct_add(uint8_t *dest, int line_size, DCTELEM *block)
-{
- int i;
- for(i=0; i<8; i++)
- idctRowCondDC(block + i*8);
-
- for(i=0; i<8; i++)
- idctSparseColAdd(dest + i, line_size, block + i);
-}
-
-void ff_simple_idct(DCTELEM *block)
-{
- int i;
- for(i=0; i<8; i++)
- idctRowCondDC(block + i*8);
-
- for(i=0; i<8; i++)
- idctSparseCol(block + i);
-}
+#define BIT_DEPTH 10
+#include "simple_idct_template.c"
+#undef BIT_DEPTH
/* 2x4x8 idct */
@@ -467,7 +108,7 @@ void ff_simple_idct248_put(uint8_t *dest, int line_size, DCTELEM *block)
/* IDCT8 on each line */
for(i=0; i<8; i++) {
- idctRowCondDC(block + i*8);
+ idctRowCondDC_8(block + i*8, 0);
}
/* IDCT4 and store */
@@ -542,7 +183,7 @@ void ff_simple_idct84_add(uint8_t *dest, int line_size, DCTELEM *block)
/* IDCT8 on each line */
for(i=0; i<4; i++) {
- idctRowCondDC(block + i*8);
+ idctRowCondDC_8(block + i*8, 0);
}
/* IDCT4 and store */
@@ -562,7 +203,7 @@ void ff_simple_idct48_add(uint8_t *dest, int line_size, DCTELEM *block)
/* IDCT8 and store */
for(i=0; i<4; i++){
- idctSparseColAdd(dest + i, line_size, block + i);
+ idctSparseColAdd_8(dest + i, line_size, block + i);
}
}
@@ -580,3 +221,17 @@ void ff_simple_idct44_add(uint8_t *dest, int line_size, DCTELEM *block)
idct4col_add(dest + i, line_size, block + i);
}
}
+
+void ff_prores_idct(DCTELEM *block, const int16_t *qmat)
+{
+ int i;
+
+ for (i = 0; i < 64; i++)
+ block[i] *= qmat[i];
+
+ for (i = 0; i < 8; i++)
+ idctRowCondDC_10(block + i*8, 2);
+
+ for (i = 0; i < 8; i++)
+ idctSparseCol_10(block + i);
+}
diff --git a/libavcodec/simple_idct.h b/libavcodec/simple_idct.h
index 23bae9c2fe..64d3c2ac31 100644
--- a/libavcodec/simple_idct.h
+++ b/libavcodec/simple_idct.h
@@ -3,20 +3,20 @@
*
* Copyright (c) 2001 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -31,12 +31,23 @@
#include <stdint.h>
#include "dsputil.h"
-void ff_simple_idct_put(uint8_t *dest, int line_size, DCTELEM *block);
-void ff_simple_idct_add(uint8_t *dest, int line_size, DCTELEM *block);
+void ff_simple_idct_put_8(uint8_t *dest, int line_size, DCTELEM *block);
+void ff_simple_idct_add_8(uint8_t *dest, int line_size, DCTELEM *block);
+void ff_simple_idct_8(DCTELEM *block);
+
+void ff_simple_idct_put_10(uint8_t *dest, int line_size, DCTELEM *block);
+void ff_simple_idct_add_10(uint8_t *dest, int line_size, DCTELEM *block);
+void ff_simple_idct_10(DCTELEM *block);
+/**
+ * Special version of ff_simple_idct_10() which does dequantization
+ * and scales by a factor of 2 more between the two IDCTs to account
+ * for larger scale of input coefficients.
+ */
+void ff_prores_idct(DCTELEM *block, const int16_t *qmat);
+
void ff_simple_idct_mmx(int16_t *block);
void ff_simple_idct_add_mmx(uint8_t *dest, int line_size, int16_t *block);
void ff_simple_idct_put_mmx(uint8_t *dest, int line_size, int16_t *block);
-void ff_simple_idct(DCTELEM *block);
void ff_simple_idct248_put(uint8_t *dest, int line_size, DCTELEM *block);
diff --git a/libavcodec/simple_idct_template.c b/libavcodec/simple_idct_template.c
new file mode 100644
index 0000000000..fdec3aab2b
--- /dev/null
+++ b/libavcodec/simple_idct_template.c
@@ -0,0 +1,326 @@
+/*
+ * Simple IDCT
+ *
+ * Copyright (c) 2001 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of Libav.
+ *
+ * Libav 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.
+ *
+ * Libav 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * simpleidct in C.
+ */
+
+/*
+ based upon some outcommented c code from mpeg2dec (idct_mmx.c
+ written by Aaron Holtzman <aholtzma@ess.engr.uvic.ca>)
+ */
+
+#include "bit_depth_template.c"
+
+#undef W1
+#undef W2
+#undef W3
+#undef W4
+#undef W5
+#undef W6
+#undef W7
+#undef ROW_SHIFT
+#undef COL_SHIFT
+#undef DC_SHIFT
+#undef MUL
+#undef MAC
+
+#if BIT_DEPTH == 8
+
+#define W1 22725 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
+#define W2 21407 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
+#define W3 19266 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
+#define W4 16383 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
+#define W5 12873 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
+#define W6 8867 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
+#define W7 4520 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
+
+#define ROW_SHIFT 11
+#define COL_SHIFT 20
+#define DC_SHIFT 3
+
+#define MUL(a, b) MUL16(a, b)
+#define MAC(a, b, c) MAC16(a, b, c)
+
+#elif BIT_DEPTH == 10
+
+#define W1 90901
+#define W2 85627
+#define W3 77062
+#define W4 65535
+#define W5 51491
+#define W6 35468
+#define W7 18081
+
+#define ROW_SHIFT 15
+#define COL_SHIFT 20
+#define DC_SHIFT 1
+
+#define MUL(a, b) ((a) * (b))
+#define MAC(a, b, c) ((a) += (b) * (c))
+
+#else
+
+#error "Unsupported bitdepth"
+
+#endif
+
+static inline void FUNC(idctRowCondDC)(DCTELEM *row, int extra_shift)
+{
+ int a0, a1, a2, a3, b0, b1, b2, b3;
+
+#if HAVE_FAST_64BIT
+#define ROW0_MASK (0xffffLL << 48 * HAVE_BIGENDIAN)
+ if (((((uint64_t *)row)[0] & ~ROW0_MASK) | ((uint64_t *)row)[1]) == 0) {
+ uint64_t temp;
+ if (DC_SHIFT - extra_shift > 0) {
+ temp = (row[0] << (DC_SHIFT - extra_shift)) & 0xffff;
+ } else {
+ temp = (row[0] >> (extra_shift - DC_SHIFT)) & 0xffff;
+ }
+ temp += temp << 16;
+ temp += temp << 32;
+ ((uint64_t *)row)[0] = temp;
+ ((uint64_t *)row)[1] = temp;
+ return;
+ }
+#else
+ if (!(((uint32_t*)row)[1] |
+ ((uint32_t*)row)[2] |
+ ((uint32_t*)row)[3] |
+ row[1])) {
+ uint32_t temp;
+ if (DC_SHIFT - extra_shift > 0) {
+ temp = (row[0] << (DC_SHIFT - extra_shift)) & 0xffff;
+ } else {
+ temp = (row[0] >> (extra_shift - DC_SHIFT)) & 0xffff;
+ }
+ temp += temp << 16;
+ ((uint32_t*)row)[0]=((uint32_t*)row)[1] =
+ ((uint32_t*)row)[2]=((uint32_t*)row)[3] = temp;
+ return;
+ }
+#endif
+
+ a0 = (W4 * row[0]) + (1 << (ROW_SHIFT - 1));
+ a1 = a0;
+ a2 = a0;
+ a3 = a0;
+
+ a0 += W2 * row[2];
+ a1 += W6 * row[2];
+ a2 -= W6 * row[2];
+ a3 -= W2 * row[2];
+
+ b0 = MUL(W1, row[1]);
+ MAC(b0, W3, row[3]);
+ b1 = MUL(W3, row[1]);
+ MAC(b1, -W7, row[3]);
+ b2 = MUL(W5, row[1]);
+ MAC(b2, -W1, row[3]);
+ b3 = MUL(W7, row[1]);
+ MAC(b3, -W5, row[3]);
+
+ if (AV_RN64A(row + 4)) {
+ a0 += W4*row[4] + W6*row[6];
+ a1 += - W4*row[4] - W2*row[6];
+ a2 += - W4*row[4] + W2*row[6];
+ a3 += W4*row[4] - W6*row[6];
+
+ MAC(b0, W5, row[5]);
+ MAC(b0, W7, row[7]);
+
+ MAC(b1, -W1, row[5]);
+ MAC(b1, -W5, row[7]);
+
+ MAC(b2, W7, row[5]);
+ MAC(b2, W3, row[7]);
+
+ MAC(b3, W3, row[5]);
+ MAC(b3, -W1, row[7]);
+ }
+
+ row[0] = (a0 + b0) >> (ROW_SHIFT + extra_shift);
+ row[7] = (a0 - b0) >> (ROW_SHIFT + extra_shift);
+ row[1] = (a1 + b1) >> (ROW_SHIFT + extra_shift);
+ row[6] = (a1 - b1) >> (ROW_SHIFT + extra_shift);
+ row[2] = (a2 + b2) >> (ROW_SHIFT + extra_shift);
+ row[5] = (a2 - b2) >> (ROW_SHIFT + extra_shift);
+ row[3] = (a3 + b3) >> (ROW_SHIFT + extra_shift);
+ row[4] = (a3 - b3) >> (ROW_SHIFT + extra_shift);
+}
+
+#define IDCT_COLS do { \
+ a0 = W4 * (col[8*0] + ((1<<(COL_SHIFT-1))/W4)); \
+ a1 = a0; \
+ a2 = a0; \
+ a3 = a0; \
+ \
+ a0 += W2*col[8*2]; \
+ a1 += W6*col[8*2]; \
+ a2 += -W6*col[8*2]; \
+ a3 += -W2*col[8*2]; \
+ \
+ b0 = MUL(W1, col[8*1]); \
+ b1 = MUL(W3, col[8*1]); \
+ b2 = MUL(W5, col[8*1]); \
+ b3 = MUL(W7, col[8*1]); \
+ \
+ MAC(b0, W3, col[8*3]); \
+ MAC(b1, -W7, col[8*3]); \
+ MAC(b2, -W1, col[8*3]); \
+ MAC(b3, -W5, col[8*3]); \
+ \
+ if (col[8*4]) { \
+ a0 += W4*col[8*4]; \
+ a1 += -W4*col[8*4]; \
+ a2 += -W4*col[8*4]; \
+ a3 += W4*col[8*4]; \
+ } \
+ \
+ if (col[8*5]) { \
+ MAC(b0, W5, col[8*5]); \
+ MAC(b1, -W1, col[8*5]); \
+ MAC(b2, W7, col[8*5]); \
+ MAC(b3, W3, col[8*5]); \
+ } \
+ \
+ if (col[8*6]) { \
+ a0 += W6*col[8*6]; \
+ a1 += -W2*col[8*6]; \
+ a2 += W2*col[8*6]; \
+ a3 += -W6*col[8*6]; \
+ } \
+ \
+ if (col[8*7]) { \
+ MAC(b0, W7, col[8*7]); \
+ MAC(b1, -W5, col[8*7]); \
+ MAC(b2, W3, col[8*7]); \
+ MAC(b3, -W1, col[8*7]); \
+ } \
+ } while (0)
+
+static inline void FUNC(idctSparseColPut)(pixel *dest, int line_size,
+ DCTELEM *col)
+{
+ int a0, a1, a2, a3, b0, b1, b2, b3;
+ INIT_CLIP;
+
+ IDCT_COLS;
+
+ dest[0] = CLIP((a0 + b0) >> COL_SHIFT);
+ dest += line_size;
+ dest[0] = CLIP((a1 + b1) >> COL_SHIFT);
+ dest += line_size;
+ dest[0] = CLIP((a2 + b2) >> COL_SHIFT);
+ dest += line_size;
+ dest[0] = CLIP((a3 + b3) >> COL_SHIFT);
+ dest += line_size;
+ dest[0] = CLIP((a3 - b3) >> COL_SHIFT);
+ dest += line_size;
+ dest[0] = CLIP((a2 - b2) >> COL_SHIFT);
+ dest += line_size;
+ dest[0] = CLIP((a1 - b1) >> COL_SHIFT);
+ dest += line_size;
+ dest[0] = CLIP((a0 - b0) >> COL_SHIFT);
+}
+
+static inline void FUNC(idctSparseColAdd)(pixel *dest, int line_size,
+ DCTELEM *col)
+{
+ int a0, a1, a2, a3, b0, b1, b2, b3;
+ INIT_CLIP;
+
+ IDCT_COLS;
+
+ dest[0] = CLIP(dest[0] + ((a0 + b0) >> COL_SHIFT));
+ dest += line_size;
+ dest[0] = CLIP(dest[0] + ((a1 + b1) >> COL_SHIFT));
+ dest += line_size;
+ dest[0] = CLIP(dest[0] + ((a2 + b2) >> COL_SHIFT));
+ dest += line_size;
+ dest[0] = CLIP(dest[0] + ((a3 + b3) >> COL_SHIFT));
+ dest += line_size;
+ dest[0] = CLIP(dest[0] + ((a3 - b3) >> COL_SHIFT));
+ dest += line_size;
+ dest[0] = CLIP(dest[0] + ((a2 - b2) >> COL_SHIFT));
+ dest += line_size;
+ dest[0] = CLIP(dest[0] + ((a1 - b1) >> COL_SHIFT));
+ dest += line_size;
+ dest[0] = CLIP(dest[0] + ((a0 - b0) >> COL_SHIFT));
+}
+
+static inline void FUNC(idctSparseCol)(DCTELEM *col)
+{
+ int a0, a1, a2, a3, b0, b1, b2, b3;
+
+ IDCT_COLS;
+
+ col[0 ] = ((a0 + b0) >> COL_SHIFT);
+ col[8 ] = ((a1 + b1) >> COL_SHIFT);
+ col[16] = ((a2 + b2) >> COL_SHIFT);
+ col[24] = ((a3 + b3) >> COL_SHIFT);
+ col[32] = ((a3 - b3) >> COL_SHIFT);
+ col[40] = ((a2 - b2) >> COL_SHIFT);
+ col[48] = ((a1 - b1) >> COL_SHIFT);
+ col[56] = ((a0 - b0) >> COL_SHIFT);
+}
+
+void FUNC(ff_simple_idct_put)(uint8_t *dest_, int line_size, DCTELEM *block)
+{
+ pixel *dest = (pixel *)dest_;
+ int i;
+
+ line_size /= sizeof(pixel);
+
+ for (i = 0; i < 8; i++)
+ FUNC(idctRowCondDC)(block + i*8, 0);
+
+ for (i = 0; i < 8; i++)
+ FUNC(idctSparseColPut)(dest + i, line_size, block + i);
+}
+
+void FUNC(ff_simple_idct_add)(uint8_t *dest_, int line_size, DCTELEM *block)
+{
+ pixel *dest = (pixel *)dest_;
+ int i;
+
+ line_size /= sizeof(pixel);
+
+ for (i = 0; i < 8; i++)
+ FUNC(idctRowCondDC)(block + i*8, 0);
+
+ for (i = 0; i < 8; i++)
+ FUNC(idctSparseColAdd)(dest + i, line_size, block + i);
+}
+
+void FUNC(ff_simple_idct)(DCTELEM *block)
+{
+ int i;
+
+ for (i = 0; i < 8; i++)
+ FUNC(idctRowCondDC)(block + i*8, 0);
+
+ for (i = 0; i < 8; i++)
+ FUNC(idctSparseCol)(block + i);
+}
diff --git a/libavcodec/sinewin.c b/libavcodec/sinewin.c
index be38dbc713..1fa0e953f0 100644
--- a/libavcodec/sinewin.c
+++ b/libavcodec/sinewin.c
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/sinewin.h b/libavcodec/sinewin.h
index eefe5bfe7f..61135fd6a2 100644
--- a/libavcodec/sinewin.h
+++ b/libavcodec/sinewin.h
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2008 Robert Swain
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/sinewin_tablegen.c b/libavcodec/sinewin_tablegen.c
index 2f4d1aa2ae..48eb771e48 100644
--- a/libavcodec/sinewin_tablegen.c
+++ b/libavcodec/sinewin_tablegen.c
@@ -3,20 +3,20 @@
*
* Copyright (c) 2009 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/sinewin_tablegen.h b/libavcodec/sinewin_tablegen.h
index 720f1ab6b8..f587595c21 100644
--- a/libavcodec/sinewin_tablegen.h
+++ b/libavcodec/sinewin_tablegen.h
@@ -3,20 +3,20 @@
*
* Copyright (c) 2009 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/sipr.c b/libavcodec/sipr.c
index 2e86861706..098d1074a7 100644
--- a/libavcodec/sipr.c
+++ b/libavcodec/sipr.c
@@ -4,20 +4,20 @@
* Copyright (c) 2008 Vladimir Voroshilov
* Copyright (c) 2009 Vitor Sessak
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -194,14 +194,16 @@ static void decode_parameters(SiprParameters* parms, GetBitContext *pgb,
{
int i, j;
- parms->ma_pred_switch = get_bits(pgb, p->ma_predictor_bits);
+ if (p->ma_predictor_bits)
+ parms->ma_pred_switch = get_bits(pgb, p->ma_predictor_bits);
for (i = 0; i < 5; i++)
parms->vq_indexes[i] = get_bits(pgb, p->vq_indexes_bits[i]);
for (i = 0; i < p->subframe_count; i++) {
parms->pitch_delay[i] = get_bits(pgb, p->pitch_delay_bits[i]);
- parms->gp_index[i] = get_bits(pgb, p->gp_index_bits);
+ if (p->gp_index_bits)
+ parms->gp_index[i] = get_bits(pgb, p->gp_index_bits);
for (j = 0; j < p->number_of_fc_indexes; j++)
parms->fc_indexes[i][j] = get_bits(pgb, p->fc_index_bits[j]);
@@ -509,7 +511,7 @@ static int sipr_decode_frame(AVCodecContext *avctx, void *datap,
GetBitContext gb;
float *data = datap;
int subframe_size = ctx->mode == MODE_16k ? L_SUBFR_16k : SUBFR_SIZE;
- int i;
+ int i, out_size;
ctx->avctx = avctx;
if (avpkt->size < (mode_par->bits_per_frame >> 3)) {
@@ -520,7 +522,11 @@ static int sipr_decode_frame(AVCodecContext *avctx, void *datap,
*data_size = 0;
return -1;
}
- if (*data_size < subframe_size * mode_par->subframe_count * sizeof(float)) {
+
+ out_size = mode_par->frames_per_packet * subframe_size *
+ mode_par->subframe_count *
+ av_get_bytes_per_sample(avctx->sample_fmt);
+ if (*data_size < out_size) {
av_log(avctx, AV_LOG_ERROR,
"Error processing packet: output buffer (%d) too small\n",
*data_size);
@@ -542,20 +548,17 @@ static int sipr_decode_frame(AVCodecContext *avctx, void *datap,
data += subframe_size * mode_par->subframe_count;
}
- *data_size = mode_par->frames_per_packet * subframe_size *
- mode_par->subframe_count * sizeof(float);
+ *data_size = out_size;
return mode_par->bits_per_frame >> 3;
}
AVCodec ff_sipr_decoder = {
- "sipr",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_SIPR,
- sizeof(SiprContext),
- sipr_decoder_init,
- NULL,
- NULL,
- sipr_decode_frame,
+ .name = "sipr",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_SIPR,
+ .priv_data_size = sizeof(SiprContext),
+ .init = sipr_decoder_init,
+ .decode = sipr_decode_frame,
.long_name = NULL_IF_CONFIG_SMALL("RealAudio SIPR / ACELP.NET"),
};
diff --git a/libavcodec/sipr.h b/libavcodec/sipr.h
index 5b2198ea87..3bb0b37016 100644
--- a/libavcodec/sipr.h
+++ b/libavcodec/sipr.h
@@ -4,20 +4,20 @@
* Copyright (c) 2008 Vladimir Voroshilov
* Copyright (c) 2009 Vitor Sessak
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/sipr16k.c b/libavcodec/sipr16k.c
index ca10cd9c70..7fb9252927 100644
--- a/libavcodec/sipr16k.c
+++ b/libavcodec/sipr16k.c
@@ -4,20 +4,20 @@
* Copyright (c) 2008 Vladimir Voroshilov
* Copyright (c) 2009 Vitor Sessak
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/sipr16kdata.h b/libavcodec/sipr16kdata.h
index ec60c29b51..96bf0e96c8 100644
--- a/libavcodec/sipr16kdata.h
+++ b/libavcodec/sipr16kdata.h
@@ -4,20 +4,20 @@
* Copyright (c) 2008 Vladimir Voroshilov
* Copyright (c) 2009 Vitor Sessak
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/siprdata.h b/libavcodec/siprdata.h
index 92037a4a87..ed804ee87c 100644
--- a/libavcodec/siprdata.h
+++ b/libavcodec/siprdata.h
@@ -4,20 +4,20 @@
* Copyright (c) 2008 Vladimir Voroshilov
* Copyright (c) 2009 Vitor Sessak
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/smacker.c b/libavcodec/smacker.c
index 8060e1cee7..c7eafbc261 100644
--- a/libavcodec/smacker.c
+++ b/libavcodec/smacker.c
@@ -2,20 +2,20 @@
* Smacker decoder
* Copyright (c) 2006 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -134,11 +134,13 @@ static int smacker_decode_bigtree(GetBitContext *gb, HuffContext *hc, DBCtx *ctx
return -1;
}
b1 = get_bits_count(gb);
- i1 = get_vlc2(gb, ctx->v1->table, SMKTREE_BITS, 3);
+ i1 = ctx->v1->table ? get_vlc2(gb, ctx->v1->table, SMKTREE_BITS, 3) : 0;
b1 = get_bits_count(gb) - b1;
b2 = get_bits_count(gb);
- i2 = get_vlc2(gb, ctx->v2->table, SMKTREE_BITS, 3);
+ i2 = ctx->v2->table ? get_vlc2(gb, ctx->v2->table, SMKTREE_BITS, 3) : 0;
b2 = get_bits_count(gb) - b2;
+ if (i1 < 0 || i2 < 0)
+ return -1;
val = ctx->recode1[i1] | (ctx->recode2[i2] << 8);
if(val == ctx->escapes[0]) {
ctx->last[0] = hc->current;
@@ -168,7 +170,7 @@ static int smacker_decode_bigtree(GetBitContext *gb, HuffContext *hc, DBCtx *ctx
}
/**
- * Store large tree as Libav's vlc codes
+ * Store large tree as FFmpeg's vlc codes
*/
static int smacker_decode_header_tree(SmackVContext *smk, GetBitContext *gb, int **recodes, int *last, int size)
{
@@ -290,7 +292,8 @@ static int decode_header_trees(SmackVContext *smk) {
smk->mmap_tbl[0] = 0;
smk->mmap_last[0] = smk->mmap_last[1] = smk->mmap_last[2] = 1;
} else {
- smacker_decode_header_tree(smk, &gb, &smk->mmap_tbl, smk->mmap_last, mmap_size);
+ if (smacker_decode_header_tree(smk, &gb, &smk->mmap_tbl, smk->mmap_last, mmap_size))
+ return -1;
}
if(!get_bits1(&gb)) {
av_log(smk->avctx, AV_LOG_INFO, "Skipping MCLR tree\n");
@@ -298,7 +301,8 @@ static int decode_header_trees(SmackVContext *smk) {
smk->mclr_tbl[0] = 0;
smk->mclr_last[0] = smk->mclr_last[1] = smk->mclr_last[2] = 1;
} else {
- smacker_decode_header_tree(smk, &gb, &smk->mclr_tbl, smk->mclr_last, mclr_size);
+ if (smacker_decode_header_tree(smk, &gb, &smk->mclr_tbl, smk->mclr_last, mclr_size))
+ return -1;
}
if(!get_bits1(&gb)) {
av_log(smk->avctx, AV_LOG_INFO, "Skipping FULL tree\n");
@@ -306,7 +310,8 @@ static int decode_header_trees(SmackVContext *smk) {
smk->full_tbl[0] = 0;
smk->full_last[0] = smk->full_last[1] = smk->full_last[2] = 1;
} else {
- smacker_decode_header_tree(smk, &gb, &smk->full_tbl, smk->full_last, full_size);
+ if (smacker_decode_header_tree(smk, &gb, &smk->full_tbl, smk->full_last, full_size))
+ return -1;
}
if(!get_bits1(&gb)) {
av_log(smk->avctx, AV_LOG_INFO, "Skipping TYPE tree\n");
@@ -314,7 +319,8 @@ static int decode_header_trees(SmackVContext *smk) {
smk->type_tbl[0] = 0;
smk->type_last[0] = smk->type_last[1] = smk->type_last[2] = 1;
} else {
- smacker_decode_header_tree(smk, &gb, &smk->type_tbl, smk->type_last, type_size);
+ if (smacker_decode_header_tree(smk, &gb, &smk->type_tbl, smk->type_last, type_size))
+ return -1;
}
return 0;
@@ -515,6 +521,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
avctx->pix_fmt = PIX_FMT_PAL8;
+ avcodec_get_frame_defaults(&c->pic);
/* decode huffman trees from extradata */
if(avctx->extradata_size < 16){
@@ -522,8 +529,8 @@ static av_cold int decode_init(AVCodecContext *avctx)
return -1;
}
- decode_header_trees(c);
-
+ if (decode_header_trees(c))
+ return -1;
return 0;
}
@@ -553,6 +560,10 @@ static av_cold int decode_end(AVCodecContext *avctx)
static av_cold int smka_decode_init(AVCodecContext *avctx)
{
+ if (avctx->channels < 1 || avctx->channels > 2) {
+ av_log(avctx, AV_LOG_ERROR, "invalid number of channels\n");
+ return AVERROR(EINVAL);
+ }
avctx->channel_layout = (avctx->channels==2) ? AV_CH_LAYOUT_STEREO : AV_CH_LAYOUT_MONO;
avctx->sample_fmt = avctx->bits_per_coded_sample == 8 ? AV_SAMPLE_FMT_U8 : AV_SAMPLE_FMT_S16;
return 0;
@@ -576,6 +587,11 @@ static int smka_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
int bits, stereo;
int pred[2] = {0, 0};
+ if (buf_size <= 4) {
+ av_log(avctx, AV_LOG_ERROR, "packet is too small\n");
+ return AVERROR(EINVAL);
+ }
+
unp_size = AV_RL32(buf);
init_get_bits(&gb, buf + 4, (buf_size - 4) * 8);
@@ -591,6 +607,14 @@ static int smka_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
av_log(avctx, AV_LOG_ERROR, "Frame is too large to fit in buffer\n");
return -1;
}
+ if (stereo ^ (avctx->channels != 1)) {
+ av_log(avctx, AV_LOG_ERROR, "channels mismatch\n");
+ return AVERROR(EINVAL);
+ }
+ if (bits && avctx->sample_fmt == AV_SAMPLE_FMT_U8) {
+ av_log(avctx, AV_LOG_ERROR, "sample format mismatch\n");
+ return AVERROR(EINVAL);
+ }
memset(vlc, 0, sizeof(VLC) * 4);
memset(h, 0, sizeof(HuffContext) * 4);
@@ -618,9 +642,9 @@ static int smka_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
if(bits) { //decode 16-bit data
for(i = stereo; i >= 0; i--)
pred[i] = av_bswap16(get_bits(&gb, 16));
- for(i = 0; i < stereo; i++)
+ for(i = 0; i <= stereo; i++)
*samples++ = pred[i];
- for(i = 0; i < unp_size / 2; i++) {
+ for(; i < unp_size / 2; i++) {
if(i & stereo) {
if(vlc[2].table)
res = get_vlc2(&gb, vlc[2].table, SMKTREE_BITS, 3);
@@ -652,9 +676,9 @@ static int smka_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
} else { //8-bit data
for(i = stereo; i >= 0; i--)
pred[i] = get_bits(&gb, 8);
- for(i = 0; i < stereo; i++)
+ for(i = 0; i <= stereo; i++)
*samples8++ = pred[i];
- for(i = 0; i < unp_size; i++) {
+ for(; i < unp_size; i++) {
if(i & stereo){
if(vlc[1].table)
res = get_vlc2(&gb, vlc[1].table, SMKTREE_BITS, 3);
@@ -686,27 +710,23 @@ static int smka_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
}
AVCodec ff_smacker_decoder = {
- "smackvid",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_SMACKVIDEO,
- sizeof(SmackVContext),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- CODEC_CAP_DR1,
+ .name = "smackvid",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_SMACKVIDEO,
+ .priv_data_size = sizeof(SmackVContext),
+ .init = decode_init,
+ .close = decode_end,
+ .decode = decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Smacker video"),
};
AVCodec ff_smackaud_decoder = {
- "smackaud",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_SMACKAUDIO,
- 0,
- smka_decode_init,
- NULL,
- NULL,
- smka_decode_frame,
+ .name = "smackaud",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_SMACKAUDIO,
+ .init = smka_decode_init,
+ .decode = smka_decode_frame,
.long_name = NULL_IF_CONFIG_SMALL("Smacker audio"),
};
diff --git a/libavcodec/smc.c b/libavcodec/smc.c
index e75203d7a5..86f4282d54 100644
--- a/libavcodec/smc.c
+++ b/libavcodec/smc.c
@@ -2,20 +2,20 @@
* Quicktime Graphics (SMC) Video Decoder
* Copyright (C) 2003 the ffmpeg project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -425,6 +425,7 @@ static av_cold int smc_decode_init(AVCodecContext *avctx)
s->avctx = avctx;
avctx->pix_fmt = PIX_FMT_PAL8;
+ avcodec_get_frame_defaults(&s->frame);
s->frame.data[0] = NULL;
return 0;
@@ -475,14 +476,13 @@ static av_cold int smc_decode_end(AVCodecContext *avctx)
}
AVCodec ff_smc_decoder = {
- "smc",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_SMC,
- sizeof(SmcContext),
- smc_decode_init,
- NULL,
- smc_decode_end,
- smc_decode_frame,
- CODEC_CAP_DR1,
+ .name = "smc",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_SMC,
+ .priv_data_size = sizeof(SmcContext),
+ .init = smc_decode_init,
+ .close = smc_decode_end,
+ .decode = smc_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("QuickTime Graphics (SMC)"),
};
diff --git a/libavcodec/snow.c b/libavcodec/snow.c
index 6a63da7aa8..c22a910a59 100644
--- a/libavcodec/snow.c
+++ b/libavcodec/snow.c
@@ -1,24 +1,26 @@
/*
* Copyright (C) 2004 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/intmath.h"
+#include "libavutil/log.h"
+#include "libavutil/opt.h"
#include "avcodec.h"
#include "dsputil.h"
#include "dwt.h"
@@ -199,7 +201,7 @@ typedef struct Plane{
}Plane;
typedef struct SnowContext{
-
+ AVClass *class;
AVCodecContext *avctx;
RangeCoder c;
DSPContext dsp;
@@ -252,6 +254,7 @@ typedef struct SnowContext{
int me_cache[ME_CACHE_SIZE];
int me_cache_generation;
slice_buffer sb;
+ int memc_only;
MpegEncContext m; // needed for motion estimation, should not be used for anything else, the idea is to eventually make the motion estimation independent of MpegEncContext, so this will be removed then (FIXME/XXX)
@@ -1930,16 +1933,14 @@ static av_cold int decode_end(AVCodecContext *avctx)
}
AVCodec ff_snow_decoder = {
- "snow",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_SNOW,
- sizeof(SnowContext),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- CODEC_CAP_DR1 /*| CODEC_CAP_DRAW_HORIZ_BAND*/,
- NULL,
+ .name = "snow",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_SNOW,
+ .priv_data_size = sizeof(SnowContext),
+ .init = decode_init,
+ .close = decode_end,
+ .decode = decode_frame,
+ .capabilities = CODEC_CAP_DR1 /*| CODEC_CAP_DRAW_HORIZ_BAND*/,
.long_name = NULL_IF_CONFIG_SMALL("Snow"),
};
@@ -3308,7 +3309,7 @@ static void update_last_header_values(SnowContext *s){
static int qscale2qlog(int qscale){
return rint(QROOT*log(qscale / (float)FF_QP2LAMBDA)/log(2))
- + 61*QROOT/8; //<64 >60
+ + 61*QROOT/8; ///< 64 > 60
}
static int ratecontrol_1pass(SnowContext *s, AVFrame *pict)
@@ -3441,8 +3442,8 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size,
frame_start(s);
s->m.current_picture_ptr= &s->m.current_picture;
- s->m.last_picture.pts= s->m.current_picture.pts;
- s->m.current_picture.pts= pict->pts;
+ s->m.last_picture.f.pts = s->m.current_picture.f.pts;
+ s->m.current_picture.f.pts = pict->pts;
if(pict->pict_type == AV_PICTURE_TYPE_P){
int block_width = (width +15)>>4;
int block_height= (height+15)>>4;
@@ -3452,14 +3453,14 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size,
assert(s->last_picture[0].data[0]);
s->m.avctx= s->avctx;
- s->m.current_picture.data[0]= s->current_picture.data[0];
- s->m. last_picture.data[0]= s->last_picture[0].data[0];
- s->m. new_picture.data[0]= s-> input_picture.data[0];
+ s->m.current_picture.f.data[0] = s->current_picture.data[0];
+ s->m. last_picture.f.data[0] = s->last_picture[0].data[0];
+ s->m. new_picture.f.data[0] = s-> input_picture.data[0];
s->m. last_picture_ptr= &s->m. last_picture;
s->m.linesize=
- s->m. last_picture.linesize[0]=
- s->m. new_picture.linesize[0]=
- s->m.current_picture.linesize[0]= stride;
+ s->m. last_picture.f.linesize[0] =
+ s->m. new_picture.f.linesize[0] =
+ s->m.current_picture.f.linesize[0] = stride;
s->m.uvlinesize= s->current_picture.linesize[1];
s->m.width = width;
s->m.height= height;
@@ -3520,7 +3521,7 @@ redo_frame:
int x, y;
// int bits= put_bits_count(&s->c.pb);
- if(!(avctx->flags2 & CODEC_FLAG2_MEMC_ONLY)){
+ if (!s->memc_only) {
//FIXME optimize
if(pict->data[plane_index]) //FIXME gray hack
for(y=0; y<h; y++){
@@ -3646,9 +3647,9 @@ redo_frame:
s->current_picture.quality = pict->quality;
s->m.frame_bits = 8*(s->c.bytestream - s->c.bytestream_start);
s->m.p_tex_bits = s->m.frame_bits - s->m.misc_bits - s->m.mv_bits;
- s->m.current_picture.display_picture_number =
- s->m.current_picture.coded_picture_number = avctx->frame_number;
- s->m.current_picture.quality = pict->quality;
+ s->m.current_picture.f.display_picture_number =
+ s->m.current_picture.f.coded_picture_number = avctx->frame_number;
+ s->m.current_picture.f.quality = pict->quality;
s->m.total_bits += 8*(s->c.bytestream - s->c.bytestream_start);
if(s->pass1_rc)
if (ff_rate_estimate_qscale(&s->m, 0) < 0)
@@ -3678,15 +3679,30 @@ static av_cold int encode_end(AVCodecContext *avctx)
return 0;
}
+#define OFFSET(x) offsetof(SnowContext, x)
+#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
+static const AVOption options[] = {
+ { "memc_only", "Only do ME/MC (I frames -> ref, P frame -> ME+MC).", OFFSET(memc_only), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },
+ { NULL },
+};
+
+static const AVClass snowenc_class = {
+ .class_name = "snow encoder",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
AVCodec ff_snow_encoder = {
- "snow",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_SNOW,
- sizeof(SnowContext),
- encode_init,
- encode_frame,
- encode_end,
+ .name = "snow",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_SNOW,
+ .priv_data_size = sizeof(SnowContext),
+ .init = encode_init,
+ .encode = encode_frame,
+ .close = encode_end,
.long_name = NULL_IF_CONFIG_SMALL("Snow"),
+ .priv_class = &snowenc_class,
};
#endif
diff --git a/libavcodec/snow.h b/libavcodec/snow.h
index db61b875c4..7d847e4b37 100644
--- a/libavcodec/snow.h
+++ b/libavcodec/snow.h
@@ -2,20 +2,20 @@
* Copyright (C) 2004 Michael Niedermayer <michaelni@gmx.at>
* Copyright (C) 2006 Robert Edele <yartrebo@earthlink.net>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/sonic.c b/libavcodec/sonic.c
new file mode 100644
index 0000000000..e7cdb3ba81
--- /dev/null
+++ b/libavcodec/sonic.c
@@ -0,0 +1,977 @@
+/*
+ * Simple free lossless/lossy audio codec
+ * Copyright (c) 2004 Alex Beregszaszi
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#include "avcodec.h"
+#include "get_bits.h"
+#include "golomb.h"
+
+/**
+ * @file
+ * Simple free lossless/lossy audio codec
+ * Based on Paul Francis Harrison's Bonk (http://www.logarithmic.net/pfh/bonk)
+ * Written and designed by Alex Beregszaszi
+ *
+ * TODO:
+ * - CABAC put/get_symbol
+ * - independent quantizer for channels
+ * - >2 channels support
+ * - more decorrelation types
+ * - more tap_quant tests
+ * - selectable intlist writers/readers (bonk-style, golomb, cabac)
+ */
+
+#define MAX_CHANNELS 2
+
+#define MID_SIDE 0
+#define LEFT_SIDE 1
+#define RIGHT_SIDE 2
+
+typedef struct SonicContext {
+ int lossless, decorrelation;
+
+ int num_taps, downsampling;
+ double quantization;
+
+ int channels, samplerate, block_align, frame_size;
+
+ int *tap_quant;
+ int *int_samples;
+ int *coded_samples[MAX_CHANNELS];
+
+ // for encoding
+ int *tail;
+ int tail_size;
+ int *window;
+ int window_size;
+
+ // for decoding
+ int *predictor_k;
+ int *predictor_state[MAX_CHANNELS];
+} SonicContext;
+
+#define LATTICE_SHIFT 10
+#define SAMPLE_SHIFT 4
+#define LATTICE_FACTOR (1 << LATTICE_SHIFT)
+#define SAMPLE_FACTOR (1 << SAMPLE_SHIFT)
+
+#define BASE_QUANT 0.6
+#define RATE_VARIATION 3.0
+
+static inline int divide(int a, int b)
+{
+ if (a < 0)
+ return -( (-a + b/2)/b );
+ else
+ return (a + b/2)/b;
+}
+
+static inline int shift(int a,int b)
+{
+ return (a+(1<<(b-1))) >> b;
+}
+
+static inline int shift_down(int a,int b)
+{
+ return (a>>b)+((a<0)?1:0);
+}
+
+#if 1
+static inline int intlist_write(PutBitContext *pb, int *buf, int entries, int base_2_part)
+{
+ int i;
+
+ for (i = 0; i < entries; i++)
+ set_se_golomb(pb, buf[i]);
+
+ return 1;
+}
+
+static inline int intlist_read(GetBitContext *gb, int *buf, int entries, int base_2_part)
+{
+ int i;
+
+ for (i = 0; i < entries; i++)
+ buf[i] = get_se_golomb(gb);
+
+ return 1;
+}
+
+#else
+
+#define ADAPT_LEVEL 8
+
+static int bits_to_store(uint64_t x)
+{
+ int res = 0;
+
+ while(x)
+ {
+ res++;
+ x >>= 1;
+ }
+ return res;
+}
+
+static void write_uint_max(PutBitContext *pb, unsigned int value, unsigned int max)
+{
+ int i, bits;
+
+ if (!max)
+ return;
+
+ bits = bits_to_store(max);
+
+ for (i = 0; i < bits-1; i++)
+ put_bits(pb, 1, value & (1 << i));
+
+ if ( (value | (1 << (bits-1))) <= max)
+ put_bits(pb, 1, value & (1 << (bits-1)));
+}
+
+static unsigned int read_uint_max(GetBitContext *gb, int max)
+{
+ int i, bits, value = 0;
+
+ if (!max)
+ return 0;
+
+ bits = bits_to_store(max);
+
+ for (i = 0; i < bits-1; i++)
+ if (get_bits1(gb))
+ value += 1 << i;
+
+ if ( (value | (1<<(bits-1))) <= max)
+ if (get_bits1(gb))
+ value += 1 << (bits-1);
+
+ return value;
+}
+
+static int intlist_write(PutBitContext *pb, int *buf, int entries, int base_2_part)
+{
+ int i, j, x = 0, low_bits = 0, max = 0;
+ int step = 256, pos = 0, dominant = 0, any = 0;
+ int *copy, *bits;
+
+ copy = av_mallocz(4* entries);
+ if (!copy)
+ return -1;
+
+ if (base_2_part)
+ {
+ int energy = 0;
+
+ for (i = 0; i < entries; i++)
+ energy += abs(buf[i]);
+
+ low_bits = bits_to_store(energy / (entries * 2));
+ if (low_bits > 15)
+ low_bits = 15;
+
+ put_bits(pb, 4, low_bits);
+ }
+
+ for (i = 0; i < entries; i++)
+ {
+ put_bits(pb, low_bits, abs(buf[i]));
+ copy[i] = abs(buf[i]) >> low_bits;
+ if (copy[i] > max)
+ max = abs(copy[i]);
+ }
+
+ bits = av_mallocz(4* entries*max);
+ if (!bits)
+ {
+// av_free(copy);
+ return -1;
+ }
+
+ for (i = 0; i <= max; i++)
+ {
+ for (j = 0; j < entries; j++)
+ if (copy[j] >= i)
+ bits[x++] = copy[j] > i;
+ }
+
+ // store bitstream
+ while (pos < x)
+ {
+ int steplet = step >> 8;
+
+ if (pos + steplet > x)
+ steplet = x - pos;
+
+ for (i = 0; i < steplet; i++)
+ if (bits[i+pos] != dominant)
+ any = 1;
+
+ put_bits(pb, 1, any);
+
+ if (!any)
+ {
+ pos += steplet;
+ step += step / ADAPT_LEVEL;
+ }
+ else
+ {
+ int interloper = 0;
+
+ while (((pos + interloper) < x) && (bits[pos + interloper] == dominant))
+ interloper++;
+
+ // note change
+ write_uint_max(pb, interloper, (step >> 8) - 1);
+
+ pos += interloper + 1;
+ step -= step / ADAPT_LEVEL;
+ }
+
+ if (step < 256)
+ {
+ step = 65536 / step;
+ dominant = !dominant;
+ }
+ }
+
+ // store signs
+ for (i = 0; i < entries; i++)
+ if (buf[i])
+ put_bits(pb, 1, buf[i] < 0);
+
+// av_free(bits);
+// av_free(copy);
+
+ return 0;
+}
+
+static int intlist_read(GetBitContext *gb, int *buf, int entries, int base_2_part)
+{
+ int i, low_bits = 0, x = 0;
+ int n_zeros = 0, step = 256, dominant = 0;
+ int pos = 0, level = 0;
+ int *bits = av_mallocz(4* entries);
+
+ if (!bits)
+ return -1;
+
+ if (base_2_part)
+ {
+ low_bits = get_bits(gb, 4);
+
+ if (low_bits)
+ for (i = 0; i < entries; i++)
+ buf[i] = get_bits(gb, low_bits);
+ }
+
+// av_log(NULL, AV_LOG_INFO, "entries: %d, low bits: %d\n", entries, low_bits);
+
+ while (n_zeros < entries)
+ {
+ int steplet = step >> 8;
+
+ if (!get_bits1(gb))
+ {
+ for (i = 0; i < steplet; i++)
+ bits[x++] = dominant;
+
+ if (!dominant)
+ n_zeros += steplet;
+
+ step += step / ADAPT_LEVEL;
+ }
+ else
+ {
+ int actual_run = read_uint_max(gb, steplet-1);
+
+// av_log(NULL, AV_LOG_INFO, "actual run: %d\n", actual_run);
+
+ for (i = 0; i < actual_run; i++)
+ bits[x++] = dominant;
+
+ bits[x++] = !dominant;
+
+ if (!dominant)
+ n_zeros += actual_run;
+ else
+ n_zeros++;
+
+ step -= step / ADAPT_LEVEL;
+ }
+
+ if (step < 256)
+ {
+ step = 65536 / step;
+ dominant = !dominant;
+ }
+ }
+
+ // reconstruct unsigned values
+ n_zeros = 0;
+ for (i = 0; n_zeros < entries; i++)
+ {
+ while(1)
+ {
+ if (pos >= entries)
+ {
+ pos = 0;
+ level += 1 << low_bits;
+ }
+
+ if (buf[pos] >= level)
+ break;
+
+ pos++;
+ }
+
+ if (bits[i])
+ buf[pos] += 1 << low_bits;
+ else
+ n_zeros++;
+
+ pos++;
+ }
+// av_free(bits);
+
+ // read signs
+ for (i = 0; i < entries; i++)
+ if (buf[i] && get_bits1(gb))
+ buf[i] = -buf[i];
+
+// av_log(NULL, AV_LOG_INFO, "zeros: %d pos: %d\n", n_zeros, pos);
+
+ return 0;
+}
+#endif
+
+static void predictor_init_state(int *k, int *state, int order)
+{
+ int i;
+
+ for (i = order-2; i >= 0; i--)
+ {
+ int j, p, x = state[i];
+
+ for (j = 0, p = i+1; p < order; j++,p++)
+ {
+ int tmp = x + shift_down(k[j] * state[p], LATTICE_SHIFT);
+ state[p] += shift_down(k[j]*x, LATTICE_SHIFT);
+ x = tmp;
+ }
+ }
+}
+
+static int predictor_calc_error(int *k, int *state, int order, int error)
+{
+ int i, x = error - shift_down(k[order-1] * state[order-1], LATTICE_SHIFT);
+
+#if 1
+ int *k_ptr = &(k[order-2]),
+ *state_ptr = &(state[order-2]);
+ for (i = order-2; i >= 0; i--, k_ptr--, state_ptr--)
+ {
+ int k_value = *k_ptr, state_value = *state_ptr;
+ x -= shift_down(k_value * state_value, LATTICE_SHIFT);
+ state_ptr[1] = state_value + shift_down(k_value * x, LATTICE_SHIFT);
+ }
+#else
+ for (i = order-2; i >= 0; i--)
+ {
+ x -= shift_down(k[i] * state[i], LATTICE_SHIFT);
+ state[i+1] = state[i] + shift_down(k[i] * x, LATTICE_SHIFT);
+ }
+#endif
+
+ // don't drift too far, to avoid overflows
+ if (x > (SAMPLE_FACTOR<<16)) x = (SAMPLE_FACTOR<<16);
+ if (x < -(SAMPLE_FACTOR<<16)) x = -(SAMPLE_FACTOR<<16);
+
+ state[0] = x;
+
+ return x;
+}
+
+#if CONFIG_SONIC_ENCODER || CONFIG_SONIC_LS_ENCODER
+// Heavily modified Levinson-Durbin algorithm which
+// copes better with quantization, and calculates the
+// actual whitened result as it goes.
+
+static void modified_levinson_durbin(int *window, int window_entries,
+ int *out, int out_entries, int channels, int *tap_quant)
+{
+ int i;
+ int *state = av_mallocz(4* window_entries);
+
+ memcpy(state, window, 4* window_entries);
+
+ for (i = 0; i < out_entries; i++)
+ {
+ int step = (i+1)*channels, k, j;
+ double xx = 0.0, xy = 0.0;
+#if 1
+ int *x_ptr = &(window[step]), *state_ptr = &(state[0]);
+ j = window_entries - step;
+ for (;j>=0;j--,x_ptr++,state_ptr++)
+ {
+ double x_value = *x_ptr, state_value = *state_ptr;
+ xx += state_value*state_value;
+ xy += x_value*state_value;
+ }
+#else
+ for (j = 0; j <= (window_entries - step); j++);
+ {
+ double stepval = window[step+j], stateval = window[j];
+// xx += (double)window[j]*(double)window[j];
+// xy += (double)window[step+j]*(double)window[j];
+ xx += stateval*stateval;
+ xy += stepval*stateval;
+ }
+#endif
+ if (xx == 0.0)
+ k = 0;
+ else
+ k = (int)(floor(-xy/xx * (double)LATTICE_FACTOR / (double)(tap_quant[i]) + 0.5));
+
+ if (k > (LATTICE_FACTOR/tap_quant[i]))
+ k = LATTICE_FACTOR/tap_quant[i];
+ if (-k > (LATTICE_FACTOR/tap_quant[i]))
+ k = -(LATTICE_FACTOR/tap_quant[i]);
+
+ out[i] = k;
+ k *= tap_quant[i];
+
+#if 1
+ x_ptr = &(window[step]);
+ state_ptr = &(state[0]);
+ j = window_entries - step;
+ for (;j>=0;j--,x_ptr++,state_ptr++)
+ {
+ int x_value = *x_ptr, state_value = *state_ptr;
+ *x_ptr = x_value + shift_down(k*state_value,LATTICE_SHIFT);
+ *state_ptr = state_value + shift_down(k*x_value, LATTICE_SHIFT);
+ }
+#else
+ for (j=0; j <= (window_entries - step); j++)
+ {
+ int stepval = window[step+j], stateval=state[j];
+ window[step+j] += shift_down(k * stateval, LATTICE_SHIFT);
+ state[j] += shift_down(k * stepval, LATTICE_SHIFT);
+ }
+#endif
+ }
+
+ av_free(state);
+}
+
+static inline int code_samplerate(int samplerate)
+{
+ switch (samplerate)
+ {
+ case 44100: return 0;
+ case 22050: return 1;
+ case 11025: return 2;
+ case 96000: return 3;
+ case 48000: return 4;
+ case 32000: return 5;
+ case 24000: return 6;
+ case 16000: return 7;
+ case 8000: return 8;
+ }
+ return -1;
+}
+
+static av_cold int sonic_encode_init(AVCodecContext *avctx)
+{
+ SonicContext *s = avctx->priv_data;
+ PutBitContext pb;
+ int i, version = 0;
+
+ if (avctx->channels > MAX_CHANNELS)
+ {
+ av_log(avctx, AV_LOG_ERROR, "Only mono and stereo streams are supported by now\n");
+ return -1; /* only stereo or mono for now */
+ }
+
+ if (avctx->channels == 2)
+ s->decorrelation = MID_SIDE;
+
+ if (avctx->codec->id == CODEC_ID_SONIC_LS)
+ {
+ s->lossless = 1;
+ s->num_taps = 32;
+ s->downsampling = 1;
+ s->quantization = 0.0;
+ }
+ else
+ {
+ s->num_taps = 128;
+ s->downsampling = 2;
+ s->quantization = 1.0;
+ }
+
+ // max tap 2048
+ if ((s->num_taps < 32) || (s->num_taps > 1024) ||
+ ((s->num_taps>>5)<<5 != s->num_taps))
+ {
+ av_log(avctx, AV_LOG_ERROR, "Invalid number of taps\n");
+ return -1;
+ }
+
+ // generate taps
+ s->tap_quant = av_mallocz(4* s->num_taps);
+ for (i = 0; i < s->num_taps; i++)
+ s->tap_quant[i] = (int)(sqrt(i+1));
+
+ s->channels = avctx->channels;
+ s->samplerate = avctx->sample_rate;
+
+ s->block_align = (int)(2048.0*s->samplerate/44100)/s->downsampling;
+ s->frame_size = s->channels*s->block_align*s->downsampling;
+
+ s->tail = av_mallocz(4* s->num_taps*s->channels);
+ if (!s->tail)
+ return -1;
+ s->tail_size = s->num_taps*s->channels;
+
+ s->predictor_k = av_mallocz(4 * s->num_taps);
+ if (!s->predictor_k)
+ return -1;
+
+ for (i = 0; i < s->channels; i++)
+ {
+ s->coded_samples[i] = av_mallocz(4* s->block_align);
+ if (!s->coded_samples[i])
+ return -1;
+ }
+
+ s->int_samples = av_mallocz(4* s->frame_size);
+
+ s->window_size = ((2*s->tail_size)+s->frame_size);
+ s->window = av_mallocz(4* s->window_size);
+ if (!s->window)
+ return -1;
+
+ avctx->extradata = av_mallocz(16);
+ if (!avctx->extradata)
+ return -1;
+ init_put_bits(&pb, avctx->extradata, 16*8);
+
+ put_bits(&pb, 2, version); // version
+ if (version == 1)
+ {
+ put_bits(&pb, 2, s->channels);
+ put_bits(&pb, 4, code_samplerate(s->samplerate));
+ }
+ put_bits(&pb, 1, s->lossless);
+ if (!s->lossless)
+ put_bits(&pb, 3, SAMPLE_SHIFT); // XXX FIXME: sample precision
+ put_bits(&pb, 2, s->decorrelation);
+ put_bits(&pb, 2, s->downsampling);
+ put_bits(&pb, 5, (s->num_taps >> 5)-1); // 32..1024
+ put_bits(&pb, 1, 0); // XXX FIXME: no custom tap quant table
+
+ flush_put_bits(&pb);
+ avctx->extradata_size = put_bits_count(&pb)/8;
+
+ av_log(avctx, AV_LOG_INFO, "Sonic: ver: %d ls: %d dr: %d taps: %d block: %d frame: %d downsamp: %d\n",
+ version, s->lossless, s->decorrelation, s->num_taps, s->block_align, s->frame_size, s->downsampling);
+
+ avctx->coded_frame = avcodec_alloc_frame();
+ if (!avctx->coded_frame)
+ return AVERROR(ENOMEM);
+ avctx->coded_frame->key_frame = 1;
+ avctx->frame_size = s->block_align*s->downsampling;
+
+ return 0;
+}
+
+static av_cold int sonic_encode_close(AVCodecContext *avctx)
+{
+ SonicContext *s = avctx->priv_data;
+ int i;
+
+ av_freep(&avctx->coded_frame);
+
+ for (i = 0; i < s->channels; i++)
+ av_free(s->coded_samples[i]);
+
+ av_free(s->predictor_k);
+ av_free(s->tail);
+ av_free(s->tap_quant);
+ av_free(s->window);
+ av_free(s->int_samples);
+
+ return 0;
+}
+
+static int sonic_encode_frame(AVCodecContext *avctx,
+ uint8_t *buf, int buf_size, void *data)
+{
+ SonicContext *s = avctx->priv_data;
+ PutBitContext pb;
+ int i, j, ch, quant = 0, x = 0;
+ short *samples = data;
+
+ init_put_bits(&pb, buf, buf_size*8);
+
+ // short -> internal
+ for (i = 0; i < s->frame_size; i++)
+ s->int_samples[i] = samples[i];
+
+ if (!s->lossless)
+ for (i = 0; i < s->frame_size; i++)
+ s->int_samples[i] = s->int_samples[i] << SAMPLE_SHIFT;
+
+ switch(s->decorrelation)
+ {
+ case MID_SIDE:
+ for (i = 0; i < s->frame_size; i += s->channels)
+ {
+ s->int_samples[i] += s->int_samples[i+1];
+ s->int_samples[i+1] -= shift(s->int_samples[i], 1);
+ }
+ break;
+ case LEFT_SIDE:
+ for (i = 0; i < s->frame_size; i += s->channels)
+ s->int_samples[i+1] -= s->int_samples[i];
+ break;
+ case RIGHT_SIDE:
+ for (i = 0; i < s->frame_size; i += s->channels)
+ s->int_samples[i] -= s->int_samples[i+1];
+ break;
+ }
+
+ memset(s->window, 0, 4* s->window_size);
+
+ for (i = 0; i < s->tail_size; i++)
+ s->window[x++] = s->tail[i];
+
+ for (i = 0; i < s->frame_size; i++)
+ s->window[x++] = s->int_samples[i];
+
+ for (i = 0; i < s->tail_size; i++)
+ s->window[x++] = 0;
+
+ for (i = 0; i < s->tail_size; i++)
+ s->tail[i] = s->int_samples[s->frame_size - s->tail_size + i];
+
+ // generate taps
+ modified_levinson_durbin(s->window, s->window_size,
+ s->predictor_k, s->num_taps, s->channels, s->tap_quant);
+ if (intlist_write(&pb, s->predictor_k, s->num_taps, 0) < 0)
+ return -1;
+
+ for (ch = 0; ch < s->channels; ch++)
+ {
+ x = s->tail_size+ch;
+ for (i = 0; i < s->block_align; i++)
+ {
+ int sum = 0;
+ for (j = 0; j < s->downsampling; j++, x += s->channels)
+ sum += s->window[x];
+ s->coded_samples[ch][i] = sum;
+ }
+ }
+
+ // simple rate control code
+ if (!s->lossless)
+ {
+ double energy1 = 0.0, energy2 = 0.0;
+ for (ch = 0; ch < s->channels; ch++)
+ {
+ for (i = 0; i < s->block_align; i++)
+ {
+ double sample = s->coded_samples[ch][i];
+ energy2 += sample*sample;
+ energy1 += fabs(sample);
+ }
+ }
+
+ energy2 = sqrt(energy2/(s->channels*s->block_align));
+ energy1 = sqrt(2.0)*energy1/(s->channels*s->block_align);
+
+ // increase bitrate when samples are like a gaussian distribution
+ // reduce bitrate when samples are like a two-tailed exponential distribution
+
+ if (energy2 > energy1)
+ energy2 += (energy2-energy1)*RATE_VARIATION;
+
+ quant = (int)(BASE_QUANT*s->quantization*energy2/SAMPLE_FACTOR);
+// av_log(avctx, AV_LOG_DEBUG, "quant: %d energy: %f / %f\n", quant, energy1, energy2);
+
+ if (quant < 1)
+ quant = 1;
+ if (quant > 65535)
+ quant = 65535;
+
+ set_ue_golomb(&pb, quant);
+
+ quant *= SAMPLE_FACTOR;
+ }
+
+ // write out coded samples
+ for (ch = 0; ch < s->channels; ch++)
+ {
+ if (!s->lossless)
+ for (i = 0; i < s->block_align; i++)
+ s->coded_samples[ch][i] = divide(s->coded_samples[ch][i], quant);
+
+ if (intlist_write(&pb, s->coded_samples[ch], s->block_align, 1) < 0)
+ return -1;
+ }
+
+// av_log(avctx, AV_LOG_DEBUG, "used bytes: %d\n", (put_bits_count(&pb)+7)/8);
+
+ flush_put_bits(&pb);
+ return (put_bits_count(&pb)+7)/8;
+}
+#endif /* CONFIG_SONIC_ENCODER || CONFIG_SONIC_LS_ENCODER */
+
+#if CONFIG_SONIC_DECODER
+static const int samplerate_table[] =
+ { 44100, 22050, 11025, 96000, 48000, 32000, 24000, 16000, 8000 };
+
+static av_cold int sonic_decode_init(AVCodecContext *avctx)
+{
+ SonicContext *s = avctx->priv_data;
+ GetBitContext gb;
+ int i, version;
+
+ s->channels = avctx->channels;
+ s->samplerate = avctx->sample_rate;
+
+ if (!avctx->extradata)
+ {
+ av_log(avctx, AV_LOG_ERROR, "No mandatory headers present\n");
+ return -1;
+ }
+
+ init_get_bits(&gb, avctx->extradata, avctx->extradata_size);
+
+ version = get_bits(&gb, 2);
+ if (version > 1)
+ {
+ av_log(avctx, AV_LOG_ERROR, "Unsupported Sonic version, please report\n");
+ return -1;
+ }
+
+ if (version == 1)
+ {
+ s->channels = get_bits(&gb, 2);
+ s->samplerate = samplerate_table[get_bits(&gb, 4)];
+ av_log(avctx, AV_LOG_INFO, "Sonicv2 chans: %d samprate: %d\n",
+ s->channels, s->samplerate);
+ }
+
+ if (s->channels > MAX_CHANNELS)
+ {
+ av_log(avctx, AV_LOG_ERROR, "Only mono and stereo streams are supported by now\n");
+ return -1;
+ }
+
+ s->lossless = get_bits1(&gb);
+ if (!s->lossless)
+ skip_bits(&gb, 3); // XXX FIXME
+ s->decorrelation = get_bits(&gb, 2);
+
+ s->downsampling = get_bits(&gb, 2);
+ s->num_taps = (get_bits(&gb, 5)+1)<<5;
+ if (get_bits1(&gb)) // XXX FIXME
+ av_log(avctx, AV_LOG_INFO, "Custom quant table\n");
+
+ s->block_align = (int)(2048.0*s->samplerate/44100)/s->downsampling;
+ s->frame_size = s->channels*s->block_align*s->downsampling;
+// avctx->frame_size = s->block_align;
+
+ av_log(avctx, AV_LOG_INFO, "Sonic: ver: %d ls: %d dr: %d taps: %d block: %d frame: %d downsamp: %d\n",
+ version, s->lossless, s->decorrelation, s->num_taps, s->block_align, s->frame_size, s->downsampling);
+
+ // generate taps
+ s->tap_quant = av_mallocz(4* s->num_taps);
+ for (i = 0; i < s->num_taps; i++)
+ s->tap_quant[i] = (int)(sqrt(i+1));
+
+ s->predictor_k = av_mallocz(4* s->num_taps);
+
+ for (i = 0; i < s->channels; i++)
+ {
+ s->predictor_state[i] = av_mallocz(4* s->num_taps);
+ if (!s->predictor_state[i])
+ return -1;
+ }
+
+ for (i = 0; i < s->channels; i++)
+ {
+ s->coded_samples[i] = av_mallocz(4* s->block_align);
+ if (!s->coded_samples[i])
+ return -1;
+ }
+ s->int_samples = av_mallocz(4* s->frame_size);
+
+ avctx->sample_fmt = AV_SAMPLE_FMT_S16;
+ return 0;
+}
+
+static av_cold int sonic_decode_close(AVCodecContext *avctx)
+{
+ SonicContext *s = avctx->priv_data;
+ int i;
+
+ av_free(s->int_samples);
+ av_free(s->tap_quant);
+ av_free(s->predictor_k);
+
+ for (i = 0; i < s->channels; i++)
+ {
+ av_free(s->predictor_state[i]);
+ av_free(s->coded_samples[i]);
+ }
+
+ return 0;
+}
+
+static int sonic_decode_frame(AVCodecContext *avctx,
+ void *data, int *data_size,
+ AVPacket *avpkt)
+{
+ const uint8_t *buf = avpkt->data;
+ int buf_size = avpkt->size;
+ SonicContext *s = avctx->priv_data;
+ GetBitContext gb;
+ int i, quant, ch, j;
+ short *samples = data;
+
+ if (buf_size == 0) return 0;
+
+// av_log(NULL, AV_LOG_INFO, "buf_size: %d\n", buf_size);
+
+ init_get_bits(&gb, buf, buf_size*8);
+
+ intlist_read(&gb, s->predictor_k, s->num_taps, 0);
+
+ // dequantize
+ for (i = 0; i < s->num_taps; i++)
+ s->predictor_k[i] *= s->tap_quant[i];
+
+ if (s->lossless)
+ quant = 1;
+ else
+ quant = get_ue_golomb(&gb) * SAMPLE_FACTOR;
+
+// av_log(NULL, AV_LOG_INFO, "quant: %d\n", quant);
+
+ for (ch = 0; ch < s->channels; ch++)
+ {
+ int x = ch;
+
+ predictor_init_state(s->predictor_k, s->predictor_state[ch], s->num_taps);
+
+ intlist_read(&gb, s->coded_samples[ch], s->block_align, 1);
+
+ for (i = 0; i < s->block_align; i++)
+ {
+ for (j = 0; j < s->downsampling - 1; j++)
+ {
+ s->int_samples[x] = predictor_calc_error(s->predictor_k, s->predictor_state[ch], s->num_taps, 0);
+ x += s->channels;
+ }
+
+ s->int_samples[x] = predictor_calc_error(s->predictor_k, s->predictor_state[ch], s->num_taps, s->coded_samples[ch][i] * quant);
+ x += s->channels;
+ }
+
+ for (i = 0; i < s->num_taps; i++)
+ s->predictor_state[ch][i] = s->int_samples[s->frame_size - s->channels + ch - i*s->channels];
+ }
+
+ switch(s->decorrelation)
+ {
+ case MID_SIDE:
+ for (i = 0; i < s->frame_size; i += s->channels)
+ {
+ s->int_samples[i+1] += shift(s->int_samples[i], 1);
+ s->int_samples[i] -= s->int_samples[i+1];
+ }
+ break;
+ case LEFT_SIDE:
+ for (i = 0; i < s->frame_size; i += s->channels)
+ s->int_samples[i+1] += s->int_samples[i];
+ break;
+ case RIGHT_SIDE:
+ for (i = 0; i < s->frame_size; i += s->channels)
+ s->int_samples[i] += s->int_samples[i+1];
+ break;
+ }
+
+ if (!s->lossless)
+ for (i = 0; i < s->frame_size; i++)
+ s->int_samples[i] = shift(s->int_samples[i], SAMPLE_SHIFT);
+
+ // internal -> short
+ for (i = 0; i < s->frame_size; i++)
+ samples[i] = av_clip_int16(s->int_samples[i]);
+
+ align_get_bits(&gb);
+
+ *data_size = s->frame_size * 2;
+
+ return (get_bits_count(&gb)+7)/8;
+}
+
+AVCodec ff_sonic_decoder = {
+ "sonic",
+ AVMEDIA_TYPE_AUDIO,
+ CODEC_ID_SONIC,
+ sizeof(SonicContext),
+ sonic_decode_init,
+ NULL,
+ sonic_decode_close,
+ sonic_decode_frame,
+ .long_name = NULL_IF_CONFIG_SMALL("Sonic"),
+};
+#endif /* CONFIG_SONIC_DECODER */
+
+#if CONFIG_SONIC_ENCODER
+AVCodec ff_sonic_encoder = {
+ "sonic",
+ AVMEDIA_TYPE_AUDIO,
+ CODEC_ID_SONIC,
+ sizeof(SonicContext),
+ sonic_encode_init,
+ sonic_encode_frame,
+ sonic_encode_close,
+ NULL,
+ .long_name = NULL_IF_CONFIG_SMALL("Sonic"),
+};
+#endif
+
+#if CONFIG_SONIC_LS_ENCODER
+AVCodec ff_sonic_ls_encoder = {
+ "sonicls",
+ AVMEDIA_TYPE_AUDIO,
+ CODEC_ID_SONIC_LS,
+ sizeof(SonicContext),
+ sonic_encode_init,
+ sonic_encode_frame,
+ sonic_encode_close,
+ NULL,
+ .long_name = NULL_IF_CONFIG_SMALL("Sonic lossless"),
+};
+#endif
diff --git a/libavcodec/sp5x.h b/libavcodec/sp5x.h
index 23c893be7f..004fcbbc93 100644
--- a/libavcodec/sp5x.h
+++ b/libavcodec/sp5x.h
@@ -2,20 +2,20 @@
* Sunplus JPEG tables
* Copyright (c) 2003 the ffmpeg project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -235,100 +235,4 @@ static const uint8_t sp5x_quant_table[20][64]=
124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124 }
};
-#if 0
-/* 4NF-M, not ZigZag */
-static const uint8_t sp5x_quant_table_orig[18][64] =
-{
- /* index 0, Q50 */
- { 16, 11, 10, 16, 24, 40, 51, 61, 12, 12, 14, 19, 26, 58, 60, 55,
- 14, 13, 16, 24, 40, 57, 69, 56, 14, 17, 22, 29, 51, 87, 80, 62,
- 18, 22, 37, 56, 68,109,103, 77, 24, 35, 55, 64, 81,104,113, 92,
- 49, 64, 78, 87,103,121,120,101, 72, 92, 95, 98,112,100,103, 99 },
- { 17, 18, 24, 47, 99, 99, 99, 99, 18, 21, 26, 66, 99, 99, 99, 99,
- 24, 26, 56, 99, 99, 99, 99, 99, 47, 66, 99, 99, 99, 99, 99, 99,
- 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
- 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99 },
-
- /* index 1, Q70 */
- { 10, 7, 6, 10, 14, 24, 31, 37, 7, 7, 8, 11, 16, 35, 36, 33,
- 8, 8, 10, 14, 24, 34, 41, 34, 8, 10, 13, 17, 31, 52, 48, 37,
- 11, 13, 22, 34, 41, 65, 62, 46, 14, 21, 33, 38, 49, 62, 68, 55,
- 29, 38, 47, 52, 62, 73, 72, 61, 43, 55, 57, 59, 67, 60, 62, 59 },
- { 10, 11, 14, 28, 59, 59, 59, 59, 11, 13, 16, 40, 59, 59, 59, 59,
- 14, 16, 34, 59, 59, 59, 59, 59, 28, 40, 59, 59, 59, 59, 59, 59,
- 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59,
- 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59 },
-
- /* index 2, Q80 */
- { 6, 4, 4, 6, 10, 16, 20, 24, 5, 5, 6, 8, 10, 23, 24, 22,
- 6, 5, 6, 10, 16, 23, 28, 22, 6, 7, 9, 12, 20, 35, 32, 25,
- 7, 9, 15, 22, 27, 44, 41, 31, 10, 14, 22, 26, 32, 42, 45, 37,
- 20, 26, 31, 35, 41, 48, 48, 40, 29, 37, 38, 39, 45, 40, 41, 40 },
- { 7, 7, 10, 19, 40, 40, 40, 40, 7, 8, 10, 26, 40, 40, 40, 40,
- 10, 10, 22, 40, 40, 40, 40, 40, 19, 26, 40, 40, 40, 40, 40, 40,
- 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40,
- 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40 },
-
- /* index 3, Q85 */
- { 5, 3, 3, 5, 7, 12, 15, 18, 4, 4, 4, 6, 8, 17, 18, 17,
- 4, 4, 5, 7, 12, 17, 21, 17, 4, 5, 7, 9, 15, 26, 24, 19,
- 5, 7, 11, 17, 20, 33, 31, 23, 7, 11, 17, 19, 24, 31, 34, 28,
- 15, 19, 23, 26, 31, 36, 36, 30, 22, 28, 29, 29, 34, 30, 31, 30 },
- { 5, 5, 7, 14, 30, 30, 30, 30, 5, 6, 8, 20, 30, 30, 30, 30,
- 7, 8, 17, 30, 30, 30, 30, 30, 14, 20, 30, 30, 30, 30, 30, 30,
- 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
- 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30 },
-
- /* index 4, Q90 */
- { 3, 2, 2, 3, 5, 8, 10, 12, 2, 2, 3, 4, 5, 12, 12, 11,
- 3, 3, 3, 5, 8, 11, 14, 11, 3, 3, 4, 6, 10, 17, 16, 12,
- 4, 4, 7, 11, 14, 22, 21, 15, 5, 7, 11, 13, 16, 21, 23, 18,
- 10, 13, 16, 17, 21, 24, 24, 20, 14, 18, 19, 20, 22, 20, 21, 20 },
- { 3, 4, 5, 9, 20, 20, 20, 20, 4, 4, 5, 13, 20, 20, 20, 20,
- 5, 5, 11, 20, 20, 20, 20, 20, 9, 13, 20, 20, 20, 20, 20, 20,
- 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
- 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20 },
-
- /* index 5, Q60 */
- { 13, 9, 8, 13, 19, 32, 41, 49, 10, 10, 11, 15, 21, 46, 48, 44,
- 11, 10, 13, 19, 32, 46, 55, 45, 11, 14, 18, 23, 41, 70, 64, 50,
- 14, 18, 30, 45, 54, 87, 82, 62, 19, 28, 44, 51, 65, 83, 90, 74,
- 39, 51, 62, 70, 82, 97, 96, 81, 58, 74, 76, 78, 90, 80, 82, 79 },
- { 14, 14, 19, 38, 79, 79, 79, 79, 14, 17, 21, 53, 79, 79, 79, 79,
- 19, 21, 45, 79, 79, 79, 79, 79, 38, 53, 79, 79, 79, 79, 79, 79,
- 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79,
- 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79 },
-
- /* index 6, Q25 */
- { 32, 22, 20, 32, 48, 80,102,122, 24, 24, 28, 38, 52,116,120,110,
- 28, 26, 32, 48, 80,114,138,112, 28, 34, 44, 58,102,174,160,124,
- 36, 44, 74,112,136,218,206,154, 48, 70,110,128,162,208,226,184,
- 98,128,156,174,206,242,240,202,144,184,190,196,224,200,206,198 },
- { 34, 36, 48, 94,198,198,198,198, 36, 42, 52,132,198,198,198,198,
- 48, 52,112,198,198,198,198,198, 94,132,198,198,198,198,198,198,
- 198,198,198,198,198,198,198,198,198,198,198,198,198,198,198,198,
- 198,198,198,198,198,198,198,198,198,198,198,198,198,198,198,198 },
-
- /* index 7, Q95 */
- { 2, 1, 1, 2, 2, 4, 5, 6, 1, 1, 1, 2, 3, 6, 6, 6,
- 1, 1, 2, 2, 4, 6, 7, 6, 1, 2, 2, 3, 5, 9, 8, 6,
- 2, 2, 4, 6, 7, 11, 10, 8, 2, 4, 6, 6, 8, 10, 11, 9,
- 5, 6, 8, 9, 10, 12, 12, 10, 7, 9, 10, 10, 11, 10, 10, 10 },
- { 2, 2, 2, 5, 10, 10, 10, 10, 2, 2, 3, 7, 10, 10, 10, 10,
- 2, 3, 6, 10, 10, 10, 10, 10, 5, 7, 10, 10, 10, 10, 10, 10,
- 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
- 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 },
-
- /* index 8, Q93 */
- { 2, 2, 1, 2, 3, 6, 7, 9, 2, 2, 2, 3, 4, 8, 8, 8,
- 2, 2, 2, 3, 6, 8, 10, 8, 2, 2, 3, 4, 7, 12, 11, 9,
- 3, 3, 5, 8, 10, 15, 14, 11, 3, 5, 8, 9, 11, 15, 16, 13,
- 7, 9, 11, 12, 14, 17, 17, 14, 10, 13, 13, 14, 16, 14, 14, 14 },
- { 2, 3, 3, 7, 14, 14, 14, 14, 3, 3, 4, 9, 14, 14, 14, 14,
- 3, 4, 8, 14, 14, 14, 14, 14, 7, 9, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14 }
-};
-#endif
-
#endif /* AVCODEC_SP5X_H */
diff --git a/libavcodec/sp5xdec.c b/libavcodec/sp5xdec.c
index 6726c18ca9..4bf45f5454 100644
--- a/libavcodec/sp5xdec.c
+++ b/libavcodec/sp5xdec.c
@@ -2,20 +2,20 @@
* Sunplus JPEG decoder (SP5X)
* Copyright (c) 2003 Alex Beregszaszi
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -94,29 +94,25 @@ static int sp5x_decode_frame(AVCodecContext *avctx,
}
AVCodec ff_sp5x_decoder = {
- "sp5x",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_SP5X,
- sizeof(MJpegDecodeContext),
- ff_mjpeg_decode_init,
- NULL,
- ff_mjpeg_decode_end,
- sp5x_decode_frame,
- CODEC_CAP_DR1,
- NULL,
- .max_lowres = 5,
+ .name = "sp5x",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_SP5X,
+ .priv_data_size = sizeof(MJpegDecodeContext),
+ .init = ff_mjpeg_decode_init,
+ .close = ff_mjpeg_decode_end,
+ .decode = sp5x_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
+ .max_lowres = 3,
.long_name = NULL_IF_CONFIG_SMALL("Sunplus JPEG (SP5X)"),
};
AVCodec ff_amv_decoder = {
- "amv",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_AMV,
- sizeof(MJpegDecodeContext),
- ff_mjpeg_decode_init,
- NULL,
- ff_mjpeg_decode_end,
- sp5x_decode_frame,
- 0,
+ .name = "amv",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_AMV,
+ .priv_data_size = sizeof(MJpegDecodeContext),
+ .init = ff_mjpeg_decode_init,
+ .close = ff_mjpeg_decode_end,
+ .decode = sp5x_decode_frame,
.long_name = NULL_IF_CONFIG_SMALL("AMV Video"),
};
diff --git a/libavcodec/sparc/dsputil_vis.c b/libavcodec/sparc/dsputil_vis.c
index ab9258b2b9..bb80cd9b44 100644
--- a/libavcodec/sparc/dsputil_vis.c
+++ b/libavcodec/sparc/dsputil_vis.c
@@ -1,20 +1,20 @@
/*
* Copyright (C) 2003 David S. Miller <davem@redhat.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -3953,10 +3953,11 @@ void dsputil_init_vis(DSPContext* c, AVCodecContext *avctx)
{
/* VIS-specific optimizations */
int accel = vis_level ();
- const int high_bit_depth = avctx->codec_id == CODEC_ID_H264 && avctx->bits_per_raw_sample > 8;
+ const int high_bit_depth = avctx->bits_per_raw_sample > 8;
if (accel & ACCEL_SPARC_VIS) {
- if(avctx->idct_algo==FF_IDCT_SIMPLEVIS){
+ if (avctx->bits_per_raw_sample <= 8 &&
+ avctx->idct_algo == FF_IDCT_SIMPLEVIS) {
c->idct_put = ff_simple_idct_put_vis;
c->idct_add = ff_simple_idct_add_vis;
c->idct = ff_simple_idct_vis;
diff --git a/libavcodec/sparc/dsputil_vis.h b/libavcodec/sparc/dsputil_vis.h
index 4be86e25e0..e1cbcb49e3 100644
--- a/libavcodec/sparc/dsputil_vis.h
+++ b/libavcodec/sparc/dsputil_vis.h
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/sparc/simple_idct_vis.c b/libavcodec/sparc/simple_idct_vis.c
index f9fcf809fb..d98bf37651 100644
--- a/libavcodec/sparc/simple_idct_vis.c
+++ b/libavcodec/sparc/simple_idct_vis.c
@@ -5,20 +5,20 @@
* I did consult the following fine web page about dct
* http://www.geocities.com/ssavekar/dct.htm
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/sparc/vis.h b/libavcodec/sparc/vis.h
index 505c735cbb..adee91bd6f 100644
--- a/libavcodec/sparc/vis.h
+++ b/libavcodec/sparc/vis.h
@@ -1,20 +1,20 @@
/*
* Copyright (C) 2003 David S. Miller <davem@redhat.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/srtdec.c b/libavcodec/srtdec.c
index 677c5501f8..aa73f4c7bf 100644
--- a/libavcodec/srtdec.c
+++ b/libavcodec/srtdec.c
@@ -2,20 +2,20 @@
* SubRip subtitle decoder
* Copyright (c) 2010 Aurelien Jacobs <aurel@gnuage.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -216,8 +216,6 @@ static int srt_decode_frame(AVCodecContext *avctx,
if (avpkt->size <= 0)
return avpkt->size;
- ff_ass_init(sub);
-
while (ptr < end && *ptr) {
ptr = read_ts(ptr, &ts_start, &ts_end, &x1, &y1, &x2, &y2);
if (!ptr)
diff --git a/libavcodec/srtenc.c b/libavcodec/srtenc.c
new file mode 100644
index 0000000000..56d3397828
--- /dev/null
+++ b/libavcodec/srtenc.c
@@ -0,0 +1,301 @@
+/*
+ * SubRip subtitle encoder
+ * Copyright (c) 2010 Aurelien Jacobs <aurel@gnuage.org>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdarg.h>
+#include "avcodec.h"
+#include "libavutil/avstring.h"
+#include "ass_split.h"
+#include "ass.h"
+
+
+#define SRT_STACK_SIZE 64
+
+typedef struct {
+ AVCodecContext *avctx;
+ ASSSplitContext *ass_ctx;
+ char buffer[2048];
+ char *ptr;
+ char *end;
+ char *dialog_start;
+ int count;
+ char stack[SRT_STACK_SIZE];
+ int stack_ptr;
+ int alignment_applied;
+} SRTContext;
+
+
+#ifdef __GNUC__
+__attribute__ ((__format__ (__printf__, 2, 3)))
+#endif
+static void srt_print(SRTContext *s, const char *str, ...)
+{
+ va_list vargs;
+ va_start(vargs, str);
+ s->ptr += vsnprintf(s->ptr, s->end - s->ptr, str, vargs);
+ va_end(vargs);
+}
+
+static int srt_stack_push(SRTContext *s, const char c)
+{
+ if (s->stack_ptr >= SRT_STACK_SIZE)
+ return -1;
+ s->stack[s->stack_ptr++] = c;
+ return 0;
+}
+
+static char srt_stack_pop(SRTContext *s)
+{
+ if (s->stack_ptr <= 0)
+ return 0;
+ return s->stack[--s->stack_ptr];
+}
+
+static int srt_stack_find(SRTContext *s, const char c)
+{
+ int i;
+ for (i = s->stack_ptr-1; i >= 0; i--)
+ if (s->stack[i] == c)
+ break;
+ return i;
+}
+
+static void srt_close_tag(SRTContext *s, char tag)
+{
+ srt_print(s, "</%c%s>", tag, tag == 'f' ? "ont" : "");
+}
+
+static void srt_stack_push_pop(SRTContext *s, const char c, int close)
+{
+ if (close) {
+ int i = c ? srt_stack_find(s, c) : 0;
+ if (i < 0)
+ return;
+ while (s->stack_ptr != i)
+ srt_close_tag(s, srt_stack_pop(s));
+ } else if (srt_stack_push(s, c) < 0)
+ av_log(s->avctx, AV_LOG_ERROR, "tag stack overflow\n");
+}
+
+static void srt_style_apply(SRTContext *s, const char *style)
+{
+ ASSStyle *st = ass_style_get(s->ass_ctx, style);
+ if (st) {
+ int c = st->primary_color & 0xFFFFFF;
+ if (st->font_name && strcmp(st->font_name, ASS_DEFAULT_FONT) ||
+ st->font_size != ASS_DEFAULT_FONT_SIZE ||
+ c != ASS_DEFAULT_COLOR) {
+ srt_print(s, "<font");
+ if (st->font_name && strcmp(st->font_name, ASS_DEFAULT_FONT))
+ srt_print(s, " face=\"%s\"", st->font_name);
+ if (st->font_size != ASS_DEFAULT_FONT_SIZE)
+ srt_print(s, " size=\"%d\"", st->font_size);
+ if (c != ASS_DEFAULT_COLOR)
+ srt_print(s, " color=\"#%06x\"",
+ (c & 0xFF0000) >> 16 | c & 0xFF00 | (c & 0xFF) << 16);
+ srt_print(s, ">");
+ srt_stack_push(s, 'f');
+ }
+ if (st->bold != ASS_DEFAULT_BOLD) {
+ srt_print(s, "<b>");
+ srt_stack_push(s, 'b');
+ }
+ if (st->italic != ASS_DEFAULT_ITALIC) {
+ srt_print(s, "<i>");
+ srt_stack_push(s, 'i');
+ }
+ if (st->underline != ASS_DEFAULT_UNDERLINE) {
+ srt_print(s, "<u>");
+ srt_stack_push(s, 'u');
+ }
+ if (st->alignment != ASS_DEFAULT_ALIGNMENT) {
+ srt_print(s, "{\\an%d}", st->alignment);
+ s->alignment_applied = 1;
+ }
+ }
+}
+
+
+static av_cold int srt_encode_init(AVCodecContext *avctx)
+{
+ SRTContext *s = avctx->priv_data;
+ s->avctx = avctx;
+ s->ass_ctx = ff_ass_split(avctx->subtitle_header);
+ return s->ass_ctx ? 0 : AVERROR_INVALIDDATA;
+}
+
+static void srt_text_cb(void *priv, const char *text, int len)
+{
+ SRTContext *s = priv;
+ av_strlcpy(s->ptr, text, FFMIN(s->end-s->ptr, len+1));
+ s->ptr += len;
+}
+
+static void srt_new_line_cb(void *priv, int forced)
+{
+ srt_print(priv, "\r\n");
+}
+
+static void srt_style_cb(void *priv, char style, int close)
+{
+ srt_stack_push_pop(priv, style, close);
+ if (!close)
+ srt_print(priv, "<%c>", style);
+}
+
+static void srt_color_cb(void *priv, unsigned int color, unsigned int color_id)
+{
+ if (color_id > 1)
+ return;
+ srt_stack_push_pop(priv, 'f', color == 0xFFFFFFFF);
+ if (color != 0xFFFFFFFF)
+ srt_print(priv, "<font color=\"#%06x\">",
+ (color & 0xFF0000) >> 16 | color & 0xFF00 | (color & 0xFF) << 16);
+}
+
+static void srt_font_name_cb(void *priv, const char *name)
+{
+ srt_stack_push_pop(priv, 'f', !name);
+ if (name)
+ srt_print(priv, "<font face=\"%s\">", name);
+}
+
+static void srt_font_size_cb(void *priv, int size)
+{
+ srt_stack_push_pop(priv, 'f', size < 0);
+ if (size >= 0)
+ srt_print(priv, "<font size=\"%d\">", size);
+}
+
+static void srt_alignment_cb(void *priv, int alignment)
+{
+ SRTContext *s = priv;
+ if (!s->alignment_applied && alignment >= 0) {
+ srt_print(s, "{\\an%d}", alignment);
+ s->alignment_applied = 1;
+ }
+}
+
+static void srt_cancel_overrides_cb(void *priv, const char *style)
+{
+ srt_stack_push_pop(priv, 0, 1);
+ srt_style_apply(priv, style);
+}
+
+static void srt_move_cb(void *priv, int x1, int y1, int x2, int y2,
+ int t1, int t2)
+{
+ SRTContext *s = priv;
+ char buffer[32];
+ int len = snprintf(buffer, sizeof(buffer),
+ " X1:%03u X2:%03u Y1:%03u Y2:%03u", x1, x2, y1, y2);
+ if (s->end - s->ptr > len) {
+ memmove(s->dialog_start+len, s->dialog_start, s->ptr-s->dialog_start+1);
+ memcpy(s->dialog_start, buffer, len);
+ s->ptr += len;
+ }
+}
+
+static void srt_end_cb(void *priv)
+{
+ srt_stack_push_pop(priv, 0, 1);
+ srt_print(priv, "\r\n\r\n");
+}
+
+static const ASSCodesCallbacks srt_callbacks = {
+ .text = srt_text_cb,
+ .new_line = srt_new_line_cb,
+ .style = srt_style_cb,
+ .color = srt_color_cb,
+ .font_name = srt_font_name_cb,
+ .font_size = srt_font_size_cb,
+ .alignment = srt_alignment_cb,
+ .cancel_overrides = srt_cancel_overrides_cb,
+ .move = srt_move_cb,
+ .end = srt_end_cb,
+};
+
+static int srt_encode_frame(AVCodecContext *avctx,
+ unsigned char *buf, int bufsize, void *data)
+{
+ SRTContext *s = avctx->priv_data;
+ AVSubtitle *sub = data;
+ ASSDialog *dialog;
+ int i, len, num;
+
+ s->ptr = s->buffer;
+ s->end = s->ptr + sizeof(s->buffer);
+
+ for (i=0; i<sub->num_rects; i++) {
+
+ if (sub->rects[i]->type != SUBTITLE_ASS) {
+ av_log(avctx, AV_LOG_ERROR, "Only SUBTITLE_ASS type supported.\n");
+ return AVERROR(ENOSYS);
+ }
+
+ dialog = ff_ass_split_dialog(s->ass_ctx, sub->rects[i]->ass, 0, &num);
+ for (; dialog && num--; dialog++) {
+ int sh, sm, ss, sc = 10 * dialog->start;
+ int eh, em, es, ec = 10 * dialog->end;
+ sh = sc/3600000; sc -= 3600000*sh;
+ sm = sc/ 60000; sc -= 60000*sm;
+ ss = sc/ 1000; sc -= 1000*ss;
+ eh = ec/3600000; ec -= 3600000*eh;
+ em = ec/ 60000; ec -= 60000*em;
+ es = ec/ 1000; ec -= 1000*es;
+ srt_print(s,"%d\r\n%02d:%02d:%02d,%03d --> %02d:%02d:%02d,%03d\r\n",
+ ++s->count, sh, sm, ss, sc, eh, em, es, ec);
+ s->alignment_applied = 0;
+ s->dialog_start = s->ptr - 2;
+ srt_style_apply(s, dialog->style);
+ ff_ass_split_override_codes(&srt_callbacks, s, dialog->text);
+ }
+ }
+
+ if (s->ptr == s->buffer)
+ return 0;
+
+ len = av_strlcpy(buf, s->buffer, bufsize);
+
+ if (len > bufsize-1) {
+ av_log(avctx, AV_LOG_ERROR, "Buffer too small for ASS event.\n");
+ return -1;
+ }
+
+ return len;
+}
+
+static int srt_encode_close(AVCodecContext *avctx)
+{
+ SRTContext *s = avctx->priv_data;
+ ff_ass_split_free(s->ass_ctx);
+ return 0;
+}
+
+AVCodec ff_srt_encoder = {
+ .name = "srt",
+ .long_name = NULL_IF_CONFIG_SMALL("SubRip subtitle"),
+ .type = AVMEDIA_TYPE_SUBTITLE,
+ .id = CODEC_ID_SRT,
+ .priv_data_size = sizeof(SRTContext),
+ .init = srt_encode_init,
+ .encode = srt_encode_frame,
+ .close = srt_encode_close,
+};
diff --git a/libavcodec/sunrast.c b/libavcodec/sunrast.c
index cadffdf1b8..ea7a3e55c0 100644
--- a/libavcodec/sunrast.c
+++ b/libavcodec/sunrast.c
@@ -2,20 +2,20 @@
* Sun Rasterfile (.sun/.ras/im{1,8,24}/.sunras) image decoder
* Copyright (c) 2007, 2008 Ivo van Poorten
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -46,6 +46,7 @@ static av_cold int sunrast_init(AVCodecContext *avctx) {
static int sunrast_decode_frame(AVCodecContext *avctx, void *data,
int *data_size, AVPacket *avpkt) {
const uint8_t *buf = avpkt->data;
+ const uint8_t *buf_end = avpkt->data + avpkt->size;
SUNRASTContext * const s = avctx->priv_data;
AVFrame *picture = data;
AVFrame * const p = &s->picture;
@@ -53,6 +54,9 @@ static int sunrast_decode_frame(AVCodecContext *avctx, void *data,
uint8_t *ptr;
const uint8_t *bufstart = buf;
+ if (avpkt->size < 32)
+ return AVERROR_INVALIDDATA;
+
if (AV_RB32(buf) != 0x59a66a95) {
av_log(avctx, AV_LOG_ERROR, "this is not sunras encoded data\n");
return -1;
@@ -64,13 +68,14 @@ static int sunrast_decode_frame(AVCodecContext *avctx, void *data,
type = AV_RB32(buf+20);
maptype = AV_RB32(buf+24);
maplength = AV_RB32(buf+28);
+ buf += 32;
- if (type == RT_FORMAT_TIFF || type == RT_FORMAT_IFF) {
- av_log(avctx, AV_LOG_ERROR, "unsupported (compression) type\n");
+ if (type < RT_OLD || type > RT_FORMAT_IFF) {
+ av_log(avctx, AV_LOG_ERROR, "invalid (compression) type\n");
return -1;
}
- if (type > RT_FORMAT_IFF) {
- av_log(avctx, AV_LOG_ERROR, "invalid (compression) type\n");
+ if (av_image_check_size(w, h, 0, avctx)) {
+ av_log(avctx, AV_LOG_ERROR, "invalid image size\n");
return -1;
}
if (maptype & ~1) {
@@ -78,7 +83,10 @@ static int sunrast_decode_frame(AVCodecContext *avctx, void *data,
return -1;
}
- buf += 32;
+ if (type == RT_FORMAT_TIFF || type == RT_FORMAT_IFF) {
+ av_log(avctx, AV_LOG_ERROR, "unsupported (compression) type\n");
+ return -1;
+ }
switch (depth) {
case 1:
@@ -98,8 +106,6 @@ static int sunrast_decode_frame(AVCodecContext *avctx, void *data,
if (p->data[0])
avctx->release_buffer(avctx, p);
- if (av_image_check_size(w, h, 0, avctx))
- return -1;
if (w != avctx->width || h != avctx->height)
avcodec_set_dimensions(avctx, w, h);
if (avctx->get_buffer(avctx, p) < 0) {
@@ -109,6 +115,9 @@ static int sunrast_decode_frame(AVCodecContext *avctx, void *data,
p->pict_type = AV_PICTURE_TYPE_I;
+ if (buf_end - buf < maplength)
+ return AVERROR_INVALIDDATA;
+
if (depth != 8 && maplength) {
av_log(avctx, AV_LOG_WARNING, "useless colormap found or file is corrupted, trying to recover\n");
@@ -143,8 +152,11 @@ static int sunrast_decode_frame(AVCodecContext *avctx, void *data,
uint8_t *end = ptr + h*stride;
x = 0;
- while (ptr != end) {
+ while (ptr != end && buf < buf_end) {
run = 1;
+ if (buf_end - buf < 1)
+ return AVERROR_INVALIDDATA;
+
if ((value = *buf++) == 0x80) {
run = *buf++ + 1;
if (run != 1)
@@ -163,6 +175,8 @@ static int sunrast_decode_frame(AVCodecContext *avctx, void *data,
}
} else {
for (y=0; y<h; y++) {
+ if (buf_end - buf < len)
+ break;
memcpy(ptr, buf, len);
ptr += stride;
buf += alen;
@@ -185,15 +199,13 @@ static av_cold int sunrast_end(AVCodecContext *avctx) {
}
AVCodec ff_sunrast_decoder = {
- "sunrast",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_SUNRAST,
- sizeof(SUNRASTContext),
- sunrast_init,
- NULL,
- sunrast_end,
- sunrast_decode_frame,
- CODEC_CAP_DR1,
- NULL,
+ .name = "sunrast",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_SUNRAST,
+ .priv_data_size = sizeof(SUNRASTContext),
+ .init = sunrast_init,
+ .close = sunrast_end,
+ .decode = sunrast_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Sun Rasterfile image"),
};
diff --git a/libavcodec/svq1.c b/libavcodec/svq1.c
index b7e3af0a28..d0e113267b 100644
--- a/libavcodec/svq1.c
+++ b/libavcodec/svq1.c
@@ -8,20 +8,20 @@
*
* SVQ1 Encoder (c) 2004 Mike Melanson <melanson@pcisys.net>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/svq1.h b/libavcodec/svq1.h
index 066ea47fb6..3ade05d848 100644
--- a/libavcodec/svq1.h
+++ b/libavcodec/svq1.h
@@ -8,20 +8,20 @@
*
* SVQ1 Encoder (c) 2004 Mike Melanson <melanson@pcisys.net>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/svq1_cb.h b/libavcodec/svq1_cb.h
index e22cd60e23..7926ce1377 100644
--- a/libavcodec/svq1_cb.h
+++ b/libavcodec/svq1_cb.h
@@ -6,20 +6,20 @@
* Copyright (C) 2002 the xine project
* Copyright (C) 2002 the ffmpeg project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/svq1_vlc.h b/libavcodec/svq1_vlc.h
index 4d03b081ea..272597e1e0 100644
--- a/libavcodec/svq1_vlc.h
+++ b/libavcodec/svq1_vlc.h
@@ -1,20 +1,20 @@
/*
* copyright (C) 2003 the ffmpeg project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/svq1dec.c b/libavcodec/svq1dec.c
index 2a80374569..cb8a622f26 100644
--- a/libavcodec/svq1dec.c
+++ b/libavcodec/svq1dec.c
@@ -8,20 +8,20 @@
*
* SVQ1 Encoder (c) 2004 Mike Melanson <melanson@pcisys.net>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -141,7 +141,7 @@ static const uint8_t string_table[256] = {
break;\
/* add child nodes */\
list[n++] = list[i];\
- list[n++] = list[i] + (((level & 1) ? pitch : 1) << ((level / 2) + 1));\
+ list[n++] = list[i] + (((level & 1) ? pitch : 1) << ((level >> 1) + 1));\
}
#define SVQ1_ADD_CODEBOOK()\
@@ -201,7 +201,7 @@ static const uint8_t string_table[256] = {
entries[j] = (((bit_cache >> (4*(stages - j - 1))) & 0xF) + 16*j) << (level + 1);\
}\
mean -= (stages * 128);\
- n4 = ((mean + (mean >> 31)) << 16) | (mean & 0xFFFF);
+ n4 = (mean << 16) + mean;
static int svq1_decode_block_intra (GetBitContext *bitbuf, uint8_t *pixels, int pitch ) {
uint32_t bit_cache;
@@ -689,12 +689,12 @@ static int svq1_decode_frame(AVCodecContext *avctx,
linesize= s->uvlinesize;
}
- current = s->current_picture.data[i];
+ current = s->current_picture.f.data[i];
if(s->pict_type==AV_PICTURE_TYPE_B){
- previous = s->next_picture.data[i];
+ previous = s->next_picture.f.data[i];
}else{
- previous = s->last_picture.data[i];
+ previous = s->last_picture.f.data[i];
}
if (s->pict_type == AV_PICTURE_TYPE_I) {
@@ -808,15 +808,14 @@ static av_cold int svq1_decode_end(AVCodecContext *avctx)
AVCodec ff_svq1_decoder = {
- "svq1",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_SVQ1,
- sizeof(MpegEncContext),
- svq1_decode_init,
- NULL,
- svq1_decode_end,
- svq1_decode_frame,
- CODEC_CAP_DR1,
+ .name = "svq1",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_SVQ1,
+ .priv_data_size = sizeof(MpegEncContext),
+ .init = svq1_decode_init,
+ .close = svq1_decode_end,
+ .decode = svq1_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.flush= ff_mpeg_flush,
.pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV410P, PIX_FMT_NONE},
.long_name= NULL_IF_CONFIG_SMALL("Sorenson Vector Quantizer 1 / Sorenson Video 1 / SVQ1"),
diff --git a/libavcodec/svq1enc.c b/libavcodec/svq1enc.c
index fbeca803f0..d9af5d80cc 100644
--- a/libavcodec/svq1enc.c
+++ b/libavcodec/svq1enc.c
@@ -2,20 +2,20 @@
* SVQ1 Encoder
* Copyright (C) 2004 Mike Melanson <melanson@pcisys.net>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -284,11 +284,11 @@ static int svq1_encode_plane(SVQ1Context *s, int plane, unsigned char *src_plane
s->m.avctx= s->avctx;
s->m.current_picture_ptr= &s->m.current_picture;
s->m.last_picture_ptr = &s->m.last_picture;
- s->m.last_picture.data[0]= ref_plane;
+ s->m.last_picture.f.data[0] = ref_plane;
s->m.linesize=
- s->m.last_picture.linesize[0]=
- s->m.new_picture.linesize[0]=
- s->m.current_picture.linesize[0]= stride;
+ s->m.last_picture.f.linesize[0] =
+ s->m.new_picture.f.linesize[0] =
+ s->m.current_picture.f.linesize[0] = stride;
s->m.width= width;
s->m.height= height;
s->m.mb_width= block_width;
@@ -318,9 +318,9 @@ static int svq1_encode_plane(SVQ1Context *s, int plane, unsigned char *src_plane
s->m.current_picture.mb_mean= (uint8_t *)s->dummy;
s->m.current_picture.mb_var= (uint16_t*)s->dummy;
s->m.current_picture.mc_mb_var= (uint16_t*)s->dummy;
- s->m.current_picture.mb_type= s->dummy;
+ s->m.current_picture.f.mb_type = s->dummy;
- s->m.current_picture.motion_val[0]= s->motion_val8[plane] + 2;
+ s->m.current_picture.f.motion_val[0] = s->motion_val8[plane] + 2;
s->m.p_mv_table= s->motion_val16[plane] + s->m.mb_stride + 1;
s->m.dsp= s->dsp; //move
ff_init_me(&s->m);
@@ -328,7 +328,7 @@ static int svq1_encode_plane(SVQ1Context *s, int plane, unsigned char *src_plane
s->m.me.dia_size= s->avctx->dia_size;
s->m.first_slice_line=1;
for (y = 0; y < block_height; y++) {
- s->m.new_picture.data[0]= src - y*16*stride; //ugly
+ s->m.new_picture.f.data[0] = src - y*16*stride; //ugly
s->m.mb_y= y;
for(i=0; i<16 && i + 16*y<height; i++){
@@ -461,7 +461,7 @@ static int svq1_encode_plane(SVQ1Context *s, int plane, unsigned char *src_plane
s->rd_total += score[best];
for(i=5; i>=0; i--){
- ff_copy_bits(&s->pb, reorder_buffer[best][i], count[best][i]);
+ avpriv_copy_bits(&s->pb, reorder_buffer[best][i], count[best][i]);
}
if(best==0){
s->dsp.put_pixels_tab[0][0](decoded, temp, stride, 16);
@@ -540,7 +540,7 @@ static int svq1_encode_frame(AVCodecContext *avctx, unsigned char *buf,
return -1;
}
-// align_put_bits(&s->pb);
+// avpriv_align_put_bits(&s->pb);
while(put_bits_count(&s->pb) & 31)
put_bits(&s->pb, 1, 0);
@@ -573,13 +573,13 @@ static av_cold int svq1_encode_end(AVCodecContext *avctx)
AVCodec ff_svq1_encoder = {
- "svq1",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_SVQ1,
- sizeof(SVQ1Context),
- svq1_encode_init,
- svq1_encode_frame,
- svq1_encode_end,
+ .name = "svq1",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_SVQ1,
+ .priv_data_size = sizeof(SVQ1Context),
+ .init = svq1_encode_init,
+ .encode = svq1_encode_frame,
+ .close = svq1_encode_end,
.pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV410P, PIX_FMT_NONE},
.long_name= NULL_IF_CONFIG_SMALL("Sorenson Vector Quantizer 1 / Sorenson Video 1 / SVQ1"),
};
diff --git a/libavcodec/svq1enc_cb.h b/libavcodec/svq1enc_cb.h
index 1c86ebeb98..7eff82ee1f 100644
--- a/libavcodec/svq1enc_cb.h
+++ b/libavcodec/svq1enc_cb.h
@@ -2,20 +2,20 @@
* SVQ1 Encoder
* Copyright (C) 2004 Mike Melanson <melanson@pcisys.net>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/svq3.c b/libavcodec/svq3.c
index a88b069daf..d96ce8ee8d 100644
--- a/libavcodec/svq3.c
+++ b/libavcodec/svq3.c
@@ -1,20 +1,20 @@
/*
- * Copyright (c) 2003 The Libav Project
+ * Copyright (c) 2003 The FFmpeg Project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -37,7 +37,7 @@
*
* You will know you have these parameters passed correctly when the decoder
* correctly decodes this file:
- * http://samples.libav.org/V-codecs/SVQ3/Vertical400kbit.sorenson3.mov
+ * http://samples.mplayerhq.hu/V-codecs/SVQ3/Vertical400kbit.sorenson3.mov
*/
#include "internal.h"
#include "dsputil.h"
@@ -70,6 +70,8 @@ typedef struct {
int unknown_flag;
int next_slice_index;
uint32_t watermark_key;
+ uint8_t *buf;
+ int buf_size;
} SVQ3Context;
#define FULLPEL_MODE 1
@@ -219,7 +221,7 @@ static inline int svq3_decode_block(GetBitContext *gb, DCTELEM *block,
for (limit = (16 >> intra); index < 16; index = limit, limit += 8) {
for (; (vlc = svq3_get_ue_golomb(gb)) != 0; index++) {
- if (vlc == INVALID_VLC)
+ if (vlc < 0)
return -1;
sign = (vlc & 0x1) - 1;
@@ -237,7 +239,7 @@ static inline int svq3_decode_block(GetBitContext *gb, DCTELEM *block,
level = ((vlc + 9) >> 2) - run;
}
} else {
- if (vlc < 16) {
+ if (vlc < 16U) {
run = svq3_dct_tables[intra][vlc].run;
level = svq3_dct_tables[intra][vlc].level;
} else if (intra) {
@@ -288,8 +290,8 @@ static inline void svq3_mc_dir_part(MpegEncContext *s,
}
/* form component predictions */
- dest = s->current_picture.data[0] + x + y*s->linesize;
- src = pic->data[0] + mx + my*s->linesize;
+ dest = s->current_picture.f.data[0] + x + y*s->linesize;
+ src = pic->f.data[0] + mx + my*s->linesize;
if (emu) {
s->dsp.emulated_edge_mc(s->edge_emu_buffer, src, s->linesize, (width + 1), (height + 1),
@@ -309,8 +311,8 @@ static inline void svq3_mc_dir_part(MpegEncContext *s,
blocksize++;
for (i = 1; i < 3; i++) {
- dest = s->current_picture.data[i] + (x >> 1) + (y >> 1)*s->uvlinesize;
- src = pic->data[i] + mx + my*s->uvlinesize;
+ dest = s->current_picture.f.data[i] + (x >> 1) + (y >> 1) * s->uvlinesize;
+ src = pic->f.data[i] + mx + my * s->uvlinesize;
if (emu) {
s->dsp.emulated_edge_mc(s->edge_emu_buffer, src, s->uvlinesize, (width + 1), (height + 1),
@@ -347,8 +349,8 @@ static inline int svq3_mc_dir(H264Context *h, int size, int mode, int dir,
if (mode != PREDICT_MODE) {
pred_motion(h, k, (part_width >> 2), dir, 1, &mx, &my);
} else {
- mx = s->next_picture.motion_val[0][b_xy][0]<<1;
- my = s->next_picture.motion_val[0][b_xy][1]<<1;
+ mx = s->next_picture.f.motion_val[0][b_xy][0] << 1;
+ my = s->next_picture.f.motion_val[0][b_xy][1] << 1;
if (dir == 0) {
mx = ((mx * h->frame_num_offset) / h->prev_frame_num_offset + 1) >> 1;
@@ -425,7 +427,9 @@ static inline int svq3_mc_dir(H264Context *h, int size, int mode, int dir,
}
/* write back motion vectors */
- fill_rectangle(s->current_picture.motion_val[dir][b_xy], part_width>>2, part_height>>2, h->b_stride, pack16to32(mx,my), 4);
+ fill_rectangle(s->current_picture.f.motion_val[dir][b_xy],
+ part_width >> 2, part_height >> 2, h->b_stride,
+ pack16to32(mx, my), 4);
}
}
@@ -448,7 +452,7 @@ static int svq3_decode_mb(SVQ3Context *svq3, unsigned int mb_type)
h->topright_samples_available = 0xFFFF;
if (mb_type == 0) { /* SKIP */
- if (s->pict_type == AV_PICTURE_TYPE_P || s->next_picture.mb_type[mb_xy] == -1) {
+ if (s->pict_type == AV_PICTURE_TYPE_P || s->next_picture.f.mb_type[mb_xy] == -1) {
svq3_mc_dir_part(s, 16*s->mb_x, 16*s->mb_y, 16, 16, 0, 0, 0, 0, 0, 0);
if (s->pict_type == AV_PICTURE_TYPE_B) {
@@ -457,7 +461,7 @@ static int svq3_decode_mb(SVQ3Context *svq3, unsigned int mb_type)
mb_type = MB_TYPE_SKIP;
} else {
- mb_type = FFMIN(s->next_picture.mb_type[mb_xy], 6);
+ mb_type = FFMIN(s->next_picture.f.mb_type[mb_xy], 6);
if (svq3_mc_dir(h, mb_type, PREDICT_MODE, 0, 0) < 0)
return -1;
if (svq3_mc_dir(h, mb_type, PREDICT_MODE, 1, 1) < 0)
@@ -486,7 +490,7 @@ static int svq3_decode_mb(SVQ3Context *svq3, unsigned int mb_type)
for (m = 0; m < 2; m++) {
if (s->mb_x > 0 && h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - 1]+6] != -1) {
for (i = 0; i < 4; i++) {
- *(uint32_t *) h->mv_cache[m][scan8[0] - 1 + i*8] = *(uint32_t *) s->current_picture.motion_val[m][b_xy - 1 + i*h->b_stride];
+ *(uint32_t *) h->mv_cache[m][scan8[0] - 1 + i*8] = *(uint32_t *) s->current_picture.f.motion_val[m][b_xy - 1 + i*h->b_stride];
}
} else {
for (i = 0; i < 4; i++) {
@@ -494,18 +498,18 @@ static int svq3_decode_mb(SVQ3Context *svq3, unsigned int mb_type)
}
}
if (s->mb_y > 0) {
- memcpy(h->mv_cache[m][scan8[0] - 1*8], s->current_picture.motion_val[m][b_xy - h->b_stride], 4*2*sizeof(int16_t));
+ memcpy(h->mv_cache[m][scan8[0] - 1*8], s->current_picture.f.motion_val[m][b_xy - h->b_stride], 4*2*sizeof(int16_t));
memset(&h->ref_cache[m][scan8[0] - 1*8], (h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride]] == -1) ? PART_NOT_AVAILABLE : 1, 4);
if (s->mb_x < (s->mb_width - 1)) {
- *(uint32_t *) h->mv_cache[m][scan8[0] + 4 - 1*8] = *(uint32_t *) s->current_picture.motion_val[m][b_xy - h->b_stride + 4];
+ *(uint32_t *) h->mv_cache[m][scan8[0] + 4 - 1*8] = *(uint32_t *) s->current_picture.f.motion_val[m][b_xy - h->b_stride + 4];
h->ref_cache[m][scan8[0] + 4 - 1*8] =
(h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride + 1]+6] == -1 ||
h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride ] ] == -1) ? PART_NOT_AVAILABLE : 1;
}else
h->ref_cache[m][scan8[0] + 4 - 1*8] = PART_NOT_AVAILABLE;
if (s->mb_x > 0) {
- *(uint32_t *) h->mv_cache[m][scan8[0] - 1 - 1*8] = *(uint32_t *) s->current_picture.motion_val[m][b_xy - h->b_stride - 1];
+ *(uint32_t *) h->mv_cache[m][scan8[0] - 1 - 1*8] = *(uint32_t *) s->current_picture.f.motion_val[m][b_xy - h->b_stride - 1];
h->ref_cache[m][scan8[0] - 1 - 1*8] = (h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride - 1]+3] == -1) ? PART_NOT_AVAILABLE : 1;
}else
h->ref_cache[m][scan8[0] - 1 - 1*8] = PART_NOT_AVAILABLE;
@@ -526,7 +530,7 @@ static int svq3_decode_mb(SVQ3Context *svq3, unsigned int mb_type)
return -1;
} else {
for (i = 0; i < 4; i++) {
- memset(s->current_picture.motion_val[0][b_xy + i*h->b_stride], 0, 4*2*sizeof(int16_t));
+ memset(s->current_picture.f.motion_val[0][b_xy + i*h->b_stride], 0, 4*2*sizeof(int16_t));
}
}
if (mb_type != 1) {
@@ -534,7 +538,7 @@ static int svq3_decode_mb(SVQ3Context *svq3, unsigned int mb_type)
return -1;
} else {
for (i = 0; i < 4; i++) {
- memset(s->current_picture.motion_val[1][b_xy + i*h->b_stride], 0, 4*2*sizeof(int16_t));
+ memset(s->current_picture.f.motion_val[1][b_xy + i*h->b_stride], 0, 4*2*sizeof(int16_t));
}
}
}
@@ -567,7 +571,7 @@ static int svq3_decode_mb(SVQ3Context *svq3, unsigned int mb_type)
for (i = 0; i < 16; i+=2) {
vlc = svq3_get_ue_golomb(&s->gb);
- if (vlc >= 25){
+ if (vlc >= 25U){
av_log(h->s.avctx, AV_LOG_ERROR, "luma prediction:%d\n", vlc);
return -1;
}
@@ -610,7 +614,7 @@ static int svq3_decode_mb(SVQ3Context *svq3, unsigned int mb_type)
dir = i_mb_type_info[mb_type - 8].pred_mode;
dir = (dir >> 1) ^ 3*(dir & 1) ^ 1;
- if ((h->intra16x16_pred_mode = ff_h264_check_intra_pred_mode(h, dir)) == -1){
+ if ((h->intra16x16_pred_mode = ff_h264_check_intra16x16_pred_mode(h, dir)) == -1){
av_log(h->s.avctx, AV_LOG_ERROR, "check_intra_pred_mode = -1\n");
return -1;
}
@@ -621,11 +625,11 @@ static int svq3_decode_mb(SVQ3Context *svq3, unsigned int mb_type)
if (!IS_INTER(mb_type) && s->pict_type != AV_PICTURE_TYPE_I) {
for (i = 0; i < 4; i++) {
- memset(s->current_picture.motion_val[0][b_xy + i*h->b_stride], 0, 4*2*sizeof(int16_t));
+ memset(s->current_picture.f.motion_val[0][b_xy + i*h->b_stride], 0, 4*2*sizeof(int16_t));
}
if (s->pict_type == AV_PICTURE_TYPE_B) {
for (i = 0; i < 4; i++) {
- memset(s->current_picture.motion_val[1][b_xy + i*h->b_stride], 0, 4*2*sizeof(int16_t));
+ memset(s->current_picture.f.motion_val[1][b_xy + i*h->b_stride], 0, 4*2*sizeof(int16_t));
}
}
}
@@ -639,7 +643,7 @@ static int svq3_decode_mb(SVQ3Context *svq3, unsigned int mb_type)
}
if (!IS_INTRA16x16(mb_type) && (!IS_SKIP(mb_type) || s->pict_type == AV_PICTURE_TYPE_B)) {
- if ((vlc = svq3_get_ue_golomb(&s->gb)) >= 48){
+ if ((vlc = svq3_get_ue_golomb(&s->gb)) >= 48U){
av_log(h->s.avctx, AV_LOG_ERROR, "cbp_vlc=%d\n", vlc);
return -1;
}
@@ -649,7 +653,7 @@ static int svq3_decode_mb(SVQ3Context *svq3, unsigned int mb_type)
if (IS_INTRA16x16(mb_type) || (s->pict_type != AV_PICTURE_TYPE_I && s->adaptive_quant && cbp)) {
s->qscale += svq3_get_se_golomb(&s->gb);
- if (s->qscale > 31){
+ if (s->qscale > 31U){
av_log(h->s.avctx, AV_LOG_ERROR, "qscale:%d\n", s->qscale);
return -1;
}
@@ -706,10 +710,10 @@ static int svq3_decode_mb(SVQ3Context *svq3, unsigned int mb_type)
}
h->cbp= cbp;
- s->current_picture.mb_type[mb_xy] = mb_type;
+ s->current_picture.f.mb_type[mb_xy] = mb_type;
if (IS_INTRA(mb_type)) {
- h->chroma_pred_mode = ff_h264_check_intra_pred_mode(h, DC_PRED8x8);
+ h->chroma_pred_mode = ff_h264_check_intra_chroma_pred_mode(h, DC_PRED8x8);
}
return 0;
@@ -753,7 +757,7 @@ static int svq3_decode_slice_header(AVCodecContext *avctx)
skip_bits_long(&s->gb, 0);
}
- if ((i = svq3_get_ue_golomb(&s->gb)) == INVALID_VLC || i >= 3){
+ if ((i = svq3_get_ue_golomb(&s->gb)) >= 3U){
av_log(h->s.avctx, AV_LOG_ERROR, "illegal slice type %d \n", i);
return -1;
}
@@ -827,6 +831,7 @@ static av_cold int svq3_decode_init(AVCodecContext *avctx)
svq3->thirdpel_flag = 1;
svq3->unknown_flag = 0;
+
/* prowl for the "SEQH" marker in the extradata */
extradata = (unsigned char *)avctx->extradata;
for (m = 0; m < avctx->extradata_size; m++) {
@@ -922,7 +927,10 @@ static av_cold int svq3_decode_init(AVCodecContext *avctx)
h->b_stride = 4*s->mb_width;
- ff_h264_alloc_tables(h);
+ if (ff_h264_alloc_tables(h) < 0) {
+ av_log(avctx, AV_LOG_ERROR, "svq3 memory allocation failed\n");
+ return AVERROR(ENOMEM);
+ }
}
return 0;
@@ -932,12 +940,12 @@ static int svq3_decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
AVPacket *avpkt)
{
- const uint8_t *buf = avpkt->data;
SVQ3Context *svq3 = avctx->priv_data;
H264Context *h = &svq3->h;
MpegEncContext *s = &h->s;
int buf_size = avpkt->size;
- int m, mb_type;
+ int m, mb_type, left;
+ uint8_t *buf;
/* special case for last picture */
if (buf_size == 0) {
@@ -949,10 +957,21 @@ static int svq3_decode_frame(AVCodecContext *avctx,
return 0;
}
- init_get_bits (&s->gb, buf, 8*buf_size);
-
s->mb_x = s->mb_y = h->mb_xy = 0;
+ if (svq3->watermark_key) {
+ av_fast_malloc(&svq3->buf, &svq3->buf_size,
+ buf_size+FF_INPUT_BUFFER_PADDING_SIZE);
+ if (!svq3->buf)
+ return AVERROR(ENOMEM);
+ memcpy(svq3->buf, avpkt->data, buf_size);
+ buf = svq3->buf;
+ } else {
+ buf = avpkt->data;
+ }
+
+ init_get_bits(&s->gb, buf, 8*buf_size);
+
if (svq3_decode_slice_header(avctx))
return -1;
@@ -966,8 +985,8 @@ static int svq3_decode_frame(AVCodecContext *avctx,
}
/* for skipping the frame */
- s->current_picture.pict_type = s->pict_type;
- s->current_picture.key_frame = (s->pict_type == AV_PICTURE_TYPE_I);
+ s->current_picture.f.pict_type = s->pict_type;
+ s->current_picture.f.key_frame = (s->pict_type == AV_PICTURE_TYPE_I);
/* Skip B-frames if we do not have reference frames. */
if (s->last_picture_ptr == NULL && s->pict_type == AV_PICTURE_TYPE_B)
@@ -1051,7 +1070,7 @@ static int svq3_decode_frame(AVCodecContext *avctx,
}
if (s->pict_type != AV_PICTURE_TYPE_B && !s->low_delay) {
- s->current_picture.mb_type[s->mb_x + s->mb_y*s->mb_stride] =
+ s->current_picture.f.mb_type[s->mb_x + s->mb_y * s->mb_stride] =
(s->pict_type == AV_PICTURE_TYPE_P && mb_type < 8) ? (mb_type - 1) : -1;
}
}
@@ -1059,6 +1078,18 @@ static int svq3_decode_frame(AVCodecContext *avctx,
ff_draw_horiz_band(s, 16*s->mb_y, 16);
}
+ left = buf_size*8 - get_bits_count(&s->gb);
+
+ if (s->mb_y != s->mb_height || s->mb_x != s->mb_width) {
+ av_log(avctx, AV_LOG_INFO, "frame num %d incomplete pic x %d y %d left %d\n", avctx->frame_number, s->mb_y, s->mb_x, left);
+ //av_hex_dump(stderr, buf+buf_size-8, 8);
+ }
+
+ if (left < 0) {
+ av_log(avctx, AV_LOG_ERROR, "frame num %d left %d\n", avctx->frame_number, left);
+ return -1;
+ }
+
MPV_frame_end(s);
if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {
@@ -1085,19 +1116,21 @@ static int svq3_decode_end(AVCodecContext *avctx)
MPV_common_end(s);
+ av_freep(&svq3->buf);
+ svq3->buf_size = 0;
+
return 0;
}
AVCodec ff_svq3_decoder = {
- "svq3",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_SVQ3,
- sizeof(SVQ3Context),
- svq3_decode_init,
- NULL,
- svq3_decode_end,
- svq3_decode_frame,
- CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_DELAY,
+ .name = "svq3",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_SVQ3,
+ .priv_data_size = sizeof(SVQ3Context),
+ .init = svq3_decode_init,
+ .close = svq3_decode_end,
+ .decode = svq3_decode_frame,
+ .capabilities = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_DELAY,
.long_name = NULL_IF_CONFIG_SMALL("Sorenson Vector Quantizer 3 / Sorenson Video 3 / SVQ3"),
.pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUVJ420P, PIX_FMT_NONE},
};
diff --git a/libavcodec/synth_filter.c b/libavcodec/synth_filter.c
index 8e6f1202fe..5f10530974 100644
--- a/libavcodec/synth_filter.c
+++ b/libavcodec/synth_filter.c
@@ -1,20 +1,20 @@
/*
* copyright (c) 2008 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/synth_filter.h b/libavcodec/synth_filter.h
index 7b73578f68..33edcc437f 100644
--- a/libavcodec/synth_filter.h
+++ b/libavcodec/synth_filter.h
@@ -1,20 +1,20 @@
/*
* copyright (c) 2008 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/tableprint.h b/libavcodec/tableprint.h
index 6f46a7cc8a..e126a72afb 100644
--- a/libavcodec/tableprint.h
+++ b/libavcodec/tableprint.h
@@ -3,20 +3,20 @@
*
* Copyright (c) 2009 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/targa.c b/libavcodec/targa.c
index e57fd8ba65..884bae6cc9 100644
--- a/libavcodec/targa.c
+++ b/libavcodec/targa.c
@@ -2,26 +2,27 @@
* Targa (.tga) image decoder
* Copyright (c) 2006 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/intreadwrite.h"
#include "libavutil/imgutils.h"
#include "avcodec.h"
+#include "bytestream.h"
#include "targa.h"
typedef struct TargaContext {
@@ -108,21 +109,26 @@ static int decode_frame(AVCodecContext *avctx,
AVFrame * const p= (AVFrame*)&s->picture;
uint8_t *dst;
int stride;
- int idlen, compr, y, w, h, bpp, flags;
+ int idlen, pal, compr, y, w, h, bpp, flags;
int first_clr, colors, csize;
/* parse image header */
CHECK_BUFFER_SIZE(buf, buf_end, 18, "header");
idlen = *buf++;
- buf++; /* pal */
+ pal = *buf++;
compr = *buf++;
- first_clr = AV_RL16(buf); buf += 2;
- colors = AV_RL16(buf); buf += 2;
+ first_clr = bytestream_get_le16(&buf);
+ colors = bytestream_get_le16(&buf);
csize = *buf++;
+ if (!pal && (first_clr || colors || csize)) {
+ av_log(avctx, AV_LOG_WARNING, "File without colormap has colormap information set.\n");
+ // specification says we should ignore those value in this case
+ first_clr = colors = csize = 0;
+ }
buf += 2; /* x */
- y = AV_RL16(buf); buf += 2;
- w = AV_RL16(buf); buf += 2;
- h = AV_RL16(buf); buf += 2;
+ y = bytestream_get_le16(&buf);
+ w = bytestream_get_le16(&buf);
+ h = bytestream_get_le16(&buf);
bpp = *buf++;
flags = *buf++;
//skip identifier if any
@@ -186,13 +192,10 @@ static int decode_frame(AVCodecContext *avctx,
if(avctx->pix_fmt != PIX_FMT_PAL8)//should not occur but skip palette anyway
buf += pal_size;
else{
- int r, g, b, t;
+ int t;
int32_t *pal = ((int32_t*)p->data[1]) + first_clr;
for(t = 0; t < colors; t++){
- r = *buf++;
- g = *buf++;
- b = *buf++;
- *pal++ = (b << 16) | (g << 8) | r;
+ *pal++ = (0xff<<24) | bytestream_get_le24(&buf);
}
p->palette_has_changed = 1;
}
@@ -254,15 +257,13 @@ static av_cold int targa_end(AVCodecContext *avctx){
}
AVCodec ff_targa_decoder = {
- "targa",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_TARGA,
- sizeof(TargaContext),
- targa_init,
- NULL,
- targa_end,
- decode_frame,
- CODEC_CAP_DR1,
- NULL,
+ .name = "targa",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_TARGA,
+ .priv_data_size = sizeof(TargaContext),
+ .init = targa_init,
+ .close = targa_end,
+ .decode = decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Truevision Targa image"),
};
diff --git a/libavcodec/targa.h b/libavcodec/targa.h
index f4ef5537b1..158a5ea0f4 100644
--- a/libavcodec/targa.h
+++ b/libavcodec/targa.h
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/targaenc.c b/libavcodec/targaenc.c
index 276bcc83eb..1171f605a2 100644
--- a/libavcodec/targaenc.c
+++ b/libavcodec/targaenc.c
@@ -2,20 +2,20 @@
* Targa (.tga) image encoder
* Copyright (c) 2007 Bobby Bingham
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/thread.h b/libavcodec/thread.h
index 401c4d25a8..9cfb31d5a1 100644
--- a/libavcodec/thread.h
+++ b/libavcodec/thread.h
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2008 Alexander Strange <astrange@ithinksw.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/tiertexseqv.c b/libavcodec/tiertexseqv.c
index 4468f00df1..afe84b8a28 100644
--- a/libavcodec/tiertexseqv.c
+++ b/libavcodec/tiertexseqv.c
@@ -2,20 +2,20 @@
* Tiertex Limited SEQ Video Decoder
* Copyright (c) 2006 Gregory Montoir (cyx@users.sourceforge.net)
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -35,15 +35,19 @@ typedef struct SeqVideoContext {
} SeqVideoContext;
-static const unsigned char *seq_unpack_rle_block(const unsigned char *src, unsigned char *dst, int dst_size)
+static const unsigned char *seq_unpack_rle_block(const unsigned char *src,
+ const unsigned char *src_end,
+ unsigned char *dst, int dst_size)
{
int i, len, sz;
GetBitContext gb;
int code_table[64];
- /* get the rle codes (at most 64 bytes) */
- init_get_bits(&gb, src, 64 * 8);
+ /* get the rle codes */
+ init_get_bits(&gb, src, (src_end - src) * 8);
for (i = 0, sz = 0; i < 64 && sz < dst_size; i++) {
+ if (get_bits_left(&gb) < 4)
+ return NULL;
code_table[i] = get_sbits(&gb, 4);
sz += FFABS(code_table[i]);
}
@@ -54,8 +58,12 @@ static const unsigned char *seq_unpack_rle_block(const unsigned char *src, unsig
len = code_table[i];
if (len < 0) {
len = -len;
+ if (src_end - src < 1)
+ return NULL;
memset(dst, *src++, FFMIN(len, dst_size));
} else {
+ if (src_end - src < len)
+ return NULL;
memcpy(dst, src, FFMIN(len, dst_size));
src += len;
}
@@ -65,25 +73,30 @@ static const unsigned char *seq_unpack_rle_block(const unsigned char *src, unsig
return src;
}
-static const unsigned char *seq_decode_op1(SeqVideoContext *seq, const unsigned char *src, unsigned char *dst)
+static const unsigned char *seq_decode_op1(SeqVideoContext *seq,
+ const unsigned char *src,
+ const unsigned char *src_end,
+ unsigned char *dst)
{
const unsigned char *color_table;
int b, i, len, bits;
GetBitContext gb;
unsigned char block[8 * 8];
+ if (src_end - src < 1)
+ return NULL;
len = *src++;
if (len & 0x80) {
switch (len & 3) {
case 1:
- src = seq_unpack_rle_block(src, block, sizeof(block));
+ src = seq_unpack_rle_block(src, src_end, block, sizeof(block));
for (b = 0; b < 8; b++) {
memcpy(dst, &block[b * 8], 8);
dst += seq->frame.linesize[0];
}
break;
case 2:
- src = seq_unpack_rle_block(src, block, sizeof(block));
+ src = seq_unpack_rle_block(src, src_end, block, sizeof(block));
for (i = 0; i < 8; i++) {
for (b = 0; b < 8; b++)
dst[b * seq->frame.linesize[0]] = block[i * 8 + b];
@@ -92,9 +105,13 @@ static const unsigned char *seq_decode_op1(SeqVideoContext *seq, const unsigned
break;
}
} else {
+ if (len <= 0)
+ return NULL;
+ bits = ff_log2_tab[len - 1] + 1;
+ if (src_end - src < len + 8 * bits)
+ return NULL;
color_table = src;
src += len;
- bits = ff_log2_tab[len - 1] + 1;
init_get_bits(&gb, src, bits * 8 * 8); src += bits * 8;
for (b = 0; b < 8; b++) {
for (i = 0; i < 8; i++)
@@ -106,10 +123,16 @@ static const unsigned char *seq_decode_op1(SeqVideoContext *seq, const unsigned
return src;
}
-static const unsigned char *seq_decode_op2(SeqVideoContext *seq, const unsigned char *src, unsigned char *dst)
+static const unsigned char *seq_decode_op2(SeqVideoContext *seq,
+ const unsigned char *src,
+ const unsigned char *src_end,
+ unsigned char *dst)
{
int i;
+ if (src_end - src < 8 * 8)
+ return NULL;
+
for (i = 0; i < 8; i++) {
memcpy(dst, src, 8);
src += 8;
@@ -119,11 +142,16 @@ static const unsigned char *seq_decode_op2(SeqVideoContext *seq, const unsigned
return src;
}
-static const unsigned char *seq_decode_op3(SeqVideoContext *seq, const unsigned char *src, unsigned char *dst)
+static const unsigned char *seq_decode_op3(SeqVideoContext *seq,
+ const unsigned char *src,
+ const unsigned char *src_end,
+ unsigned char *dst)
{
int pos, offset;
do {
+ if (src_end - src < 2)
+ return NULL;
pos = *src++;
offset = ((pos >> 3) & 7) * seq->frame.linesize[0] + (pos & 7);
dst[offset] = *src++;
@@ -132,8 +160,9 @@ static const unsigned char *seq_decode_op3(SeqVideoContext *seq, const unsigned
return src;
}
-static void seqvideo_decode(SeqVideoContext *seq, const unsigned char *data, int data_size)
+static int seqvideo_decode(SeqVideoContext *seq, const unsigned char *data, int data_size)
{
+ const unsigned char *data_end = data + data_size;
GetBitContext gb;
int flags, i, j, x, y, op;
unsigned char c[3];
@@ -144,6 +173,8 @@ static void seqvideo_decode(SeqVideoContext *seq, const unsigned char *data, int
if (flags & 1) {
palette = (uint32_t *)seq->frame.data[1];
+ if (data_end - data < 256 * 3)
+ return AVERROR_INVALIDDATA;
for (i = 0; i < 256; i++) {
for (j = 0; j < 3; j++, data++)
c[j] = (*data << 2) | (*data >> 4);
@@ -153,6 +184,8 @@ static void seqvideo_decode(SeqVideoContext *seq, const unsigned char *data, int
}
if (flags & 2) {
+ if (data_end - data < 128)
+ return AVERROR_INVALIDDATA;
init_get_bits(&gb, data, 128 * 8); data += 128;
for (y = 0; y < 128; y += 8)
for (x = 0; x < 256; x += 8) {
@@ -160,17 +193,20 @@ static void seqvideo_decode(SeqVideoContext *seq, const unsigned char *data, int
op = get_bits(&gb, 2);
switch (op) {
case 1:
- data = seq_decode_op1(seq, data, dst);
+ data = seq_decode_op1(seq, data, data_end, dst);
break;
case 2:
- data = seq_decode_op2(seq, data, dst);
+ data = seq_decode_op2(seq, data, data_end, dst);
break;
case 3:
- data = seq_decode_op3(seq, data, dst);
+ data = seq_decode_op3(seq, data, data_end, dst);
break;
}
+ if (!data)
+ return AVERROR_INVALIDDATA;
}
}
+ return 0;
}
static av_cold int seqvideo_decode_init(AVCodecContext *avctx)
@@ -180,6 +216,7 @@ static av_cold int seqvideo_decode_init(AVCodecContext *avctx)
seq->avctx = avctx;
avctx->pix_fmt = PIX_FMT_PAL8;
+ avcodec_get_frame_defaults(&seq->frame);
seq->frame.data[0] = NULL;
return 0;
@@ -201,7 +238,8 @@ static int seqvideo_decode_frame(AVCodecContext *avctx,
return -1;
}
- seqvideo_decode(seq, buf, buf_size);
+ if (seqvideo_decode(seq, buf, buf_size))
+ return AVERROR_INVALIDDATA;
*data_size = sizeof(AVFrame);
*(AVFrame *)data = seq->frame;
@@ -220,14 +258,13 @@ static av_cold int seqvideo_decode_end(AVCodecContext *avctx)
}
AVCodec ff_tiertexseqvideo_decoder = {
- "tiertexseqvideo",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_TIERTEXSEQVIDEO,
- sizeof(SeqVideoContext),
- seqvideo_decode_init,
- NULL,
- seqvideo_decode_end,
- seqvideo_decode_frame,
- CODEC_CAP_DR1,
+ .name = "tiertexseqvideo",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_TIERTEXSEQVIDEO,
+ .priv_data_size = sizeof(SeqVideoContext),
+ .init = seqvideo_decode_init,
+ .close = seqvideo_decode_end,
+ .decode = seqvideo_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Tiertex Limited SEQ video"),
};
diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
index 08cd3b0a6f..8d0bb98689 100644
--- a/libavcodec/tiff.c
+++ b/libavcodec/tiff.c
@@ -1,29 +1,29 @@
/*
- * TIFF image decoder
* Copyright (c) 2006 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
- * TIFF image decoder
* @file
+ * TIFF image decoder
* @author Konstantin Shishkov
*/
+
#include "avcodec.h"
#if CONFIG_ZLIB
#include <zlib.h>
@@ -102,6 +102,43 @@ static int tiff_uncompress(uint8_t *dst, unsigned long *len, const uint8_t *src,
}
#endif
+static void av_always_inline horizontal_fill(unsigned int bpp, uint8_t* dst,
+ int usePtr, const uint8_t *src,
+ uint8_t c, int width, int offset)
+{
+ int i;
+
+ if (bpp == 2) {
+ for (i = 0; i < width; i++) {
+ dst[(i+offset)*4+0] = (usePtr ? src[i] : c) >> 6;
+ dst[(i+offset)*4+1] = (usePtr ? src[i] : c) >> 4 & 0x3;
+ dst[(i+offset)*4+2] = (usePtr ? src[i] : c) >> 2 & 0x3;
+ dst[(i+offset)*4+3] = (usePtr ? src[i] : c) & 0x3;
+ }
+ } else if (bpp == 4) {
+ for (i = 0; i < width; i++) {
+ dst[(i+offset)*2+0] = (usePtr ? src[i] : c) >> 4;
+ dst[(i+offset)*2+1] = (usePtr ? src[i] : c) & 0xF;
+ }
+ } else {
+ if (usePtr) {
+ memcpy(dst + offset, src, width);
+ } else {
+ memset(dst + offset, c, width);
+ }
+ }
+}
+
+static void av_always_inline split_nibbles(uint8_t *dst, const uint8_t *src,
+ int width)
+{
+ while (--width >= 0) {
+ // src == dst for LZW
+ dst[width * 2 + 1] = src[width] & 0xF;
+ dst[width * 2 + 0] = src[width] >> 4;
+ }
+}
+
static int tiff_unpack_strip(TiffContext *s, uint8_t* dst, int stride, const uint8_t *src, int size, int lines){
int c, line, pixels, code;
const uint8_t *ssrc = src;
@@ -121,7 +158,11 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t* dst, int stride, const uin
}
src = zbuf;
for(line = 0; line < lines; line++){
- memcpy(dst, src, width);
+ if(s->bpp == 4){
+ split_nibbles(dst, src, width);
+ }else{
+ memcpy(dst, src, width);
+ }
dst += stride;
src += width;
}
@@ -172,8 +213,10 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t* dst, int stride, const uin
}
switch(s->compr){
case TIFF_RAW:
+ if (ssrc + size - src < width)
+ return AVERROR_INVALIDDATA;
if (!s->fill_order) {
- memcpy(dst, src, width);
+ horizontal_fill(s->bpp, dst, 1, src, 0, width, 0);
} else {
int i;
for (i = 0; i < width; i++)
@@ -190,7 +233,7 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t* dst, int stride, const uin
av_log(s->avctx, AV_LOG_ERROR, "Copy went out of bounds\n");
return -1;
}
- memcpy(dst + pixels, src, code);
+ horizontal_fill(s->bpp, dst, 1, src, 0, code, pixels);
src += code;
pixels += code;
}else if(code != -128){ // -127..-1
@@ -200,7 +243,7 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t* dst, int stride, const uin
return -1;
}
c = *src++;
- memset(dst + pixels, c, code);
+ horizontal_fill(s->bpp, dst, 0, NULL, c, code, pixels);
pixels += code;
}
}
@@ -211,6 +254,8 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t* dst, int stride, const uin
av_log(s->avctx, AV_LOG_ERROR, "Decoded only %i bytes of %i\n", pixels, width);
return -1;
}
+ if(s->bpp == 4)
+ split_nibbles(dst, dst, width);
break;
}
dst += stride;
@@ -227,6 +272,8 @@ static int init_image(TiffContext *s)
case 11:
s->avctx->pix_fmt = PIX_FMT_MONOBLACK;
break;
+ case 21:
+ case 41:
case 81:
s->avctx->pix_fmt = PIX_FMT_PAL8;
break;
@@ -265,8 +312,8 @@ static int init_image(TiffContext *s)
} else {
/* make default grayscale pal */
pal = (uint32_t *) s->picture.data[1];
- for (i = 0; i < 256; i++)
- pal[i] = i * 0x010101;
+ for (i = 0; i < 1<<s->bpp; i++)
+ pal[i] = i * 255 / ((1<<s->bpp) - 1) * 0x010101;
}
}
return 0;
@@ -279,6 +326,8 @@ static int tiff_decode_tag(TiffContext *s, const uint8_t *start, const uint8_t *
uint32_t *pal;
const uint8_t *rp, *gp, *bp;
+ if (end_buf - buf < 12)
+ return -1;
tag = tget_short(&buf, s->le);
type = tget_short(&buf, s->le);
count = tget_long(&buf, s->le);
@@ -338,7 +387,7 @@ static int tiff_decode_tag(TiffContext *s, const uint8_t *start, const uint8_t *
case TIFF_SHORT:
case TIFF_LONG:
s->bpp = 0;
- for(i = 0; i < count; i++) s->bpp += tget(&buf, type, s->le);
+ for(i = 0; i < count && buf < end_buf; i++) s->bpp += tget(&buf, type, s->le);
break;
default:
s->bpp = -1;
@@ -452,12 +501,15 @@ static int tiff_decode_tag(TiffContext *s, const uint8_t *start, const uint8_t *
case TIFF_PAL:
pal = (uint32_t *) s->palette;
off = type_sizes[type];
+ if (count / 3 > 256 || end_buf - buf < count / 3 * off * 3)
+ return -1;
rp = buf;
gp = buf + count / 3 * off;
bp = buf + count / 3 * off * 2;
off = (type_sizes[type] - 1) << 3;
for(i = 0; i < count / 3; i++){
- j = (tget(&rp, type, s->le) >> off) << 16;
+ j = 0xff << 24;
+ j |= (tget(&rp, type, s->le) >> off) << 16;
j |= (tget(&gp, type, s->le) >> off) << 8;
j |= tget(&bp, type, s->le) >> off;
pal[i] = j;
@@ -494,12 +546,16 @@ static int decode_frame(AVCodecContext *avctx,
AVFrame *picture = data;
AVFrame * const p= (AVFrame*)&s->picture;
const uint8_t *orig_buf = buf, *end_buf = buf + buf_size;
- int id, le, off, ret;
+ unsigned off;
+ int id, le, ret;
int i, j, entries;
- int stride, soff, ssize;
+ int stride;
+ unsigned soff, ssize;
uint8_t *dst;
//parse image header
+ if (end_buf - buf < 8)
+ return AVERROR_INVALIDDATA;
id = AV_RL16(buf); buf += 2;
if(id == 0x4949) le = 1;
else if(id == 0x4D4D) le = 0;
@@ -519,9 +575,9 @@ static int decode_frame(AVCodecContext *avctx,
}
/* parse image file directory */
off = tget_long(&buf, le);
- if(orig_buf + off + 14 >= end_buf){
+ if (off >= UINT_MAX - 14 || end_buf - orig_buf < off + 14) {
av_log(avctx, AV_LOG_ERROR, "IFD offset is greater than image size\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
buf = orig_buf + off;
entries = tget_short(&buf, le);
@@ -545,23 +601,23 @@ static int decode_frame(AVCodecContext *avctx,
stride = p->linesize[0];
dst = p->data[0];
for(i = 0; i < s->height; i += s->rps){
- if(s->stripsizes)
+ if(s->stripsizes) {
+ if (s->stripsizes >= end_buf)
+ return AVERROR_INVALIDDATA;
ssize = tget(&s->stripsizes, s->sstype, s->le);
- else
+ } else
ssize = s->stripsize;
- if (ssize > buf_size) {
- av_log(avctx, AV_LOG_ERROR, "Buffer size is smaller than strip size\n");
- return -1;
- }
-
if(s->stripdata){
+ if (s->stripdata >= end_buf)
+ return AVERROR_INVALIDDATA;
soff = tget(&s->stripdata, s->sot, s->le);
}else
soff = s->stripoff;
- if (soff < 0) {
- av_log(avctx, AV_LOG_ERROR, "Invalid stripoff: %d\n", soff);
- return AVERROR(EINVAL);
+
+ if (soff > buf_size || ssize > buf_size - soff) {
+ av_log(avctx, AV_LOG_ERROR, "Invalid strip size/offset\n");
+ return -1;
}
if(tiff_unpack_strip(s, dst, stride, orig_buf + soff, ssize, FFMIN(s->rps, s->height - i)) < 0)
break;
@@ -571,22 +627,33 @@ static int decode_frame(AVCodecContext *avctx,
dst = p->data[0];
soff = s->bpp >> 3;
ssize = s->width * soff;
- for(i = 0; i < s->height; i++) {
- for(j = soff; j < ssize; j++)
- dst[j] += dst[j - soff];
- dst += stride;
+ if (s->avctx->pix_fmt == PIX_FMT_RGB48LE) {
+ for (i = 0; i < s->height; i++) {
+ for (j = soff; j < ssize; j += 2)
+ AV_WL16(dst + j, AV_RL16(dst + j) + AV_RL16(dst + j - soff));
+ dst += stride;
+ }
+ } else if (s->avctx->pix_fmt == PIX_FMT_RGB48BE) {
+ for (i = 0; i < s->height; i++) {
+ for (j = soff; j < ssize; j += 2)
+ AV_WB16(dst + j, AV_RB16(dst + j) + AV_RB16(dst + j - soff));
+ dst += stride;
+ }
+ } else {
+ for(i = 0; i < s->height; i++) {
+ for(j = soff; j < ssize; j++)
+ dst[j] += dst[j - soff];
+ dst += stride;
+ }
}
}
if(s->invert){
- uint8_t *src;
- int j;
-
- src = s->picture.data[0];
- for(j = 0; j < s->height; j++){
- for(i = 0; i < s->picture.linesize[0]; i++)
- src[i] = 255 - src[i];
- src += s->picture.linesize[0];
+ dst = s->picture.data[0];
+ for(i = 0; i < s->height; i++){
+ for(j = 0; j < s->picture.linesize[0]; j++)
+ dst[j] = (s->avctx->pix_fmt == PIX_FMT_PAL8 ? (1<<s->bpp) - 1 : 255) - dst[j];
+ dst += s->picture.linesize[0];
}
}
*picture= *(AVFrame*)&s->picture;
@@ -620,15 +687,13 @@ static av_cold int tiff_end(AVCodecContext *avctx)
}
AVCodec ff_tiff_decoder = {
- "tiff",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_TIFF,
- sizeof(TiffContext),
- tiff_init,
- NULL,
- tiff_end,
- decode_frame,
- CODEC_CAP_DR1,
- NULL,
+ .name = "tiff",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_TIFF,
+ .priv_data_size = sizeof(TiffContext),
+ .init = tiff_init,
+ .close = tiff_end,
+ .decode = decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("TIFF image"),
};
diff --git a/libavcodec/tiff.h b/libavcodec/tiff.h
index cd7ec830e7..d5fad42771 100644
--- a/libavcodec/tiff.h
+++ b/libavcodec/tiff.h
@@ -1,29 +1,32 @@
/*
- * TIFF tables
* Copyright (c) 2006 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
- * TIFF tables
* @file
+ * TIFF tables
+ *
+ * For more information about the TIFF format, check the official docs at:
+ * http://partners.adobe.com/public/developer/tiff/index.html
* @author Konstantin Shishkov
*/
+
#ifndef AVCODEC_TIFF_H
#define AVCODEC_TIFF_H
diff --git a/libavcodec/tiffenc.c b/libavcodec/tiffenc.c
index 5cff13bca0..b9a1e20fa5 100644
--- a/libavcodec/tiffenc.c
+++ b/libavcodec/tiffenc.c
@@ -2,32 +2,34 @@
* TIFF image encoder
* Copyright (c) 2007 Bartlomiej Wolowiec
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
- * TIFF image encoder
* @file
+ * TIFF image encoder
* @author Bartlomiej Wolowiec
*/
+
#include "avcodec.h"
#if CONFIG_ZLIB
#include <zlib.h>
#endif
+#include "libavutil/opt.h"
#include "bytestream.h"
#include "tiff.h"
#include "rle.h"
@@ -42,6 +44,7 @@ static const uint8_t type_sizes2[6] = {
};
typedef struct TiffEncoderContext {
+ AVClass *avclass;
AVCodecContext *avctx;
AVFrame picture;
@@ -60,6 +63,7 @@ typedef struct TiffEncoderContext {
int buf_size; ///< buffer size
uint16_t subsampling[2]; ///< YUV subsampling factors
struct LZWEncodeState *lzws; ///< LZW Encode state
+ uint32_t dpi; ///< image resolution in DPI
} TiffEncoderContext;
@@ -209,13 +213,14 @@ static int encode_frame(AVCodecContext * avctx, unsigned char *buf,
uint32_t *strip_sizes = NULL;
uint32_t *strip_offsets = NULL;
int bytes_per_row;
- uint32_t res[2] = { 72, 1 }; // image resolution (72/1)
- static const uint16_t bpp_tab[] = { 8, 8, 8, 8 };
+ uint32_t res[2] = { s->dpi, 1 }; // image resolution (72/1)
+ uint16_t bpp_tab[] = { 8, 8, 8, 8 };
int ret = -1;
int is_yuv = 0;
uint8_t *yuv_line = NULL;
int shift_h, shift_v;
+ s->avctx = avctx;
s->buf_start = buf;
s->buf = &ptr;
s->buf_size = buf_size;
@@ -242,6 +247,14 @@ static int encode_frame(AVCodecContext * avctx, unsigned char *buf,
s->subsampling[1] = 1;
switch (avctx->pix_fmt) {
+ case PIX_FMT_RGB48LE:
+ s->bpp = 48;
+ s->photometric_interpretation = 2;
+ bpp_tab[0] = 16;
+ bpp_tab[1] = 16;
+ bpp_tab[2] = 16;
+ bpp_tab[3] = 16;
+ break;
case PIX_FMT_RGB24:
s->bpp = 24;
s->photometric_interpretation = 2;
@@ -255,12 +268,10 @@ static int encode_frame(AVCodecContext * avctx, unsigned char *buf,
s->photometric_interpretation = 3;
break;
case PIX_FMT_MONOBLACK:
- s->bpp = 1;
- s->photometric_interpretation = 1;
- break;
case PIX_FMT_MONOWHITE:
s->bpp = 1;
- s->photometric_interpretation = 0;
+ s->photometric_interpretation = avctx->pix_fmt == PIX_FMT_MONOBLACK;
+ bpp_tab[0] = 1;
break;
case PIX_FMT_YUV420P:
case PIX_FMT_YUV422P:
@@ -282,7 +293,7 @@ static int encode_frame(AVCodecContext * avctx, unsigned char *buf,
return -1;
}
if (!is_yuv)
- s->bpp_tab_size = (s->bpp >> 3);
+ s->bpp_tab_size = (s->bpp >= 48) ? ((s->bpp + 7) >> 4):((s->bpp + 7) >> 3);
if (s->compr == TIFF_DEFLATE || s->compr == TIFF_ADOBE_DEFLATE || s->compr == TIFF_LZW)
//best choose for DEFLATE
@@ -442,23 +453,25 @@ fail:
return ret;
}
+static const AVOption options[]={
+{"dpi", "set the image resolution (in dpi)", offsetof(TiffEncoderContext, dpi), AV_OPT_TYPE_INT, {.dbl = 72}, 1, 0x10000, AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_ENCODING_PARAM},
+{NULL}
+};
+static const AVClass class = { "tiff", av_default_item_name, options, LIBAVUTIL_VERSION_INT };
+
AVCodec ff_tiff_encoder = {
- "tiff",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_TIFF,
- sizeof(TiffEncoderContext),
- NULL,
- encode_frame,
- NULL,
- NULL,
- 0,
- NULL,
+ .name = "tiff",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_TIFF,
+ .priv_data_size = sizeof(TiffEncoderContext),
+ .encode = encode_frame,
.pix_fmts =
(const enum PixelFormat[]) {PIX_FMT_RGB24, PIX_FMT_PAL8, PIX_FMT_GRAY8,
PIX_FMT_MONOBLACK, PIX_FMT_MONOWHITE,
PIX_FMT_YUV420P, PIX_FMT_YUV422P,
PIX_FMT_YUV444P, PIX_FMT_YUV410P,
- PIX_FMT_YUV411P,
+ PIX_FMT_YUV411P, PIX_FMT_RGB48LE,
PIX_FMT_NONE},
.long_name = NULL_IF_CONFIG_SMALL("TIFF image"),
+ .priv_class= &class,
};
diff --git a/libavcodec/timecode.c b/libavcodec/timecode.c
new file mode 100644
index 0000000000..7f3b1d5ab8
--- /dev/null
+++ b/libavcodec/timecode.c
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2006 Smartjog S.A.S, Baptiste Coudurier <baptiste.coudurier@gmail.com>
+ * Copyright (C) 2011 Smartjog S.A.S, Clément Bœsch <clement.boesch@smartjog.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * Timecode helpers
+ */
+
+#include <stdio.h>
+#include "timecode.h"
+#include "libavutil/log.h"
+
+int ff_framenum_to_drop_timecode(int frame_num)
+{
+ /* only works for NTSC 29.97 */
+ int d = frame_num / 17982;
+ int m = frame_num % 17982;
+ //if (m < 2) m += 2; /* not needed since -2,-1 / 1798 in C returns 0 */
+ return frame_num + 18 * d + 2 * ((m - 2) / 1798);
+}
+
+uint32_t ff_framenum_to_smtpe_timecode(unsigned frame, int fps, int drop)
+{
+ return (0 << 31) | // color frame flag
+ (drop << 30) | // drop frame flag
+ ( ((frame % fps) / 10) << 28) | // tens of frames
+ ( ((frame % fps) % 10) << 24) | // units of frames
+ (0 << 23) | // field phase (NTSC), b0 (PAL)
+ ((((frame / fps) % 60) / 10) << 20) | // tens of seconds
+ ((((frame / fps) % 60) % 10) << 16) | // units of seconds
+ (0 << 15) | // b0 (NTSC), b2 (PAL)
+ ((((frame / (fps * 60)) % 60) / 10) << 12) | // tens of minutes
+ ((((frame / (fps * 60)) % 60) % 10) << 8) | // units of minutes
+ (0 << 7) | // b1
+ (0 << 6) | // b2 (NTSC), field phase (PAL)
+ ((((frame / (fps * 3600) % 24)) / 10) << 4) | // tens of hours
+ ( (frame / (fps * 3600) % 24)) % 10; // units of hours
+}
+
+int ff_init_smtpe_timecode(void *avcl, struct ff_timecode *tc)
+{
+ int hh, mm, ss, ff, fps;
+ char c;
+
+ if (sscanf(tc->str, "%d:%d:%d%c%d", &hh, &mm, &ss, &c, &ff) != 5) {
+ av_log(avcl, AV_LOG_ERROR, "unable to parse timecode, "
+ "syntax: hh:mm:ss[:;.]ff\n");
+ return -1;
+ }
+
+ fps = (tc->rate.num + tc->rate.den/2) / tc->rate.den;
+ tc->start = (hh*3600 + mm*60 + ss) * fps + ff;
+ tc->drop = c != ':'; // drop if ';', '.', ...
+
+ if (tc->drop) { /* adjust frame number */
+ int tmins = 60*hh + mm;
+ if (tc->rate.den != 1001 || fps != 30) {
+ av_log(avcl, AV_LOG_ERROR, "error: drop frame is only allowed with"
+ "30000/1001 FPS");
+ return -2;
+ }
+ tc->start -= 2 * (tmins - tmins/10);
+ }
+ return 0;
+}
diff --git a/libavcodec/timecode.h b/libavcodec/timecode.h
new file mode 100644
index 0000000000..5646199ff7
--- /dev/null
+++ b/libavcodec/timecode.h
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2006 Smartjog S.A.S, Baptiste Coudurier <baptiste.coudurier@gmail.com>
+ * Copyright (C) 2011 Smartjog S.A.S, Clément Bœsch <clement.boesch@smartjog.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * Timecode helpers header
+ */
+
+#ifndef AVCODEC_TIMECODE_H
+#define AVCODEC_TIMECODE_H
+
+#include <stdint.h>
+#include "libavutil/rational.h"
+
+#define TIMECODE_OPT(ctx, flags) \
+ "timecode", "set timecode value following hh:mm:ss[:;.]ff format, " \
+ "use ';' or '.' before frame number for drop frame", \
+ offsetof(ctx, tc.str), \
+ AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, flags
+
+struct ff_timecode {
+ char *str; ///< string following the hh:mm:ss[:;.]ff format
+ int start; ///< timecode frame start
+ int drop; ///< drop flag (1 if drop, else 0)
+ AVRational rate; ///< Frame rate in rationnal form
+};
+
+/**
+ * @brief Adjust frame number for NTSC drop frame time code
+ * @param frame_num Actual frame number to adjust
+ * @return Adjusted frame number
+ * @warning Adjustment is only valid in NTSC 29.97
+ */
+int ff_framenum_to_drop_timecode(int frame_num);
+
+/**
+ * @brief Convert frame id (timecode) to SMPTE 12M binary representation
+ * @param frame Frame number
+ * @param fps Frame rate
+ * @param drop Drop flag
+ * @return The actual binary representation
+ */
+uint32_t ff_framenum_to_smtpe_timecode(unsigned frame, int fps, int drop);
+
+/**
+ * Parse SMTPE 12M time representation (hh:mm:ss[:;.]ff). str and rate fields
+ * from tc struct must be set.
+ *
+ * @param avcl A pointer to an arbitrary struct of which the first field is a
+ * pointer to an AVClass struct (used for av_log).
+ * @param tc Timecode struct pointer
+ * @return 0 on success, negative value on failure
+ * @warning Adjustement is only valid in NTSC 29.97
+ */
+int ff_init_smtpe_timecode(void *avcl, struct ff_timecode *tc);
+
+#endif /* AVCODEC_TIMECODE_H */
diff --git a/libavcodec/tmv.c b/libavcodec/tmv.c
index 80f3ac9cbc..424cddf84d 100644
--- a/libavcodec/tmv.c
+++ b/libavcodec/tmv.c
@@ -2,28 +2,28 @@
* 8088flex TMV video decoder
* Copyright (c) 2009 Daniel Verkamp <daniel at drv.nu>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
- * 8088flex TMV video decoder
* @file
+ * 8088flex TMV video decoder
* @author Daniel Verkamp
- * @sa http://www.oldskool.org/pc/8088_Corruption
+ * @see http://www.oldskool.org/pc/8088_Corruption
*/
#include "avcodec.h"
@@ -34,6 +34,14 @@ typedef struct TMVContext {
AVFrame pic;
} TMVContext;
+static av_cold int tmv_decode_init(AVCodecContext *avctx)
+{
+ TMVContext *tmv = avctx->priv_data;
+
+ avcodec_get_frame_defaults(&tmv->pic);
+ return 0;
+}
+
static int tmv_decode_frame(AVCodecContext *avctx, void *data,
int *data_size, AVPacket *avpkt)
{
@@ -97,6 +105,7 @@ AVCodec ff_tmv_decoder = {
.type = AVMEDIA_TYPE_VIDEO,
.id = CODEC_ID_TMV,
.priv_data_size = sizeof(TMVContext),
+ .init = tmv_decode_init,
.close = tmv_decode_close,
.decode = tmv_decode_frame,
.capabilities = CODEC_CAP_DR1,
diff --git a/libavcodec/truemotion1.c b/libavcodec/truemotion1.c
index 97330d1bb4..9c2a273f1c 100644
--- a/libavcodec/truemotion1.c
+++ b/libavcodec/truemotion1.c
@@ -2,20 +2,20 @@
* Duck TrueMotion 1.0 Decoder
* Copyright (C) 2003 Alex Beregszaszi & Mike Melanson
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -474,6 +474,7 @@ static av_cold int truemotion1_decode_init(AVCodecContext *avctx)
// else
// avctx->pix_fmt = PIX_FMT_RGB555;
+ avcodec_get_frame_defaults(&s->frame);
s->frame.data[0] = NULL;
/* there is a vertical predictor for each pixel in a line; each vertical
@@ -892,14 +893,13 @@ static av_cold int truemotion1_decode_end(AVCodecContext *avctx)
}
AVCodec ff_truemotion1_decoder = {
- "truemotion1",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_TRUEMOTION1,
- sizeof(TrueMotion1Context),
- truemotion1_decode_init,
- NULL,
- truemotion1_decode_end,
- truemotion1_decode_frame,
- CODEC_CAP_DR1,
+ .name = "truemotion1",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_TRUEMOTION1,
+ .priv_data_size = sizeof(TrueMotion1Context),
+ .init = truemotion1_decode_init,
+ .close = truemotion1_decode_end,
+ .decode = truemotion1_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Duck TrueMotion 1.0"),
};
diff --git a/libavcodec/truemotion1data.h b/libavcodec/truemotion1data.h
index c94e3b5add..6a9822a3cc 100644
--- a/libavcodec/truemotion1data.h
+++ b/libavcodec/truemotion1data.h
@@ -6,20 +6,20 @@
* GNU LGPL using the common understanding that data tables necessary for
* decoding algorithms are not necessarily licensable.
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVCODEC_TRUEMOTION1DATA_H
diff --git a/libavcodec/truemotion2.c b/libavcodec/truemotion2.c
index 23abade214..4967e29d93 100644
--- a/libavcodec/truemotion2.c
+++ b/libavcodec/truemotion2.c
@@ -2,20 +2,20 @@
* Duck/ON2 TrueMotion 2 Decoder
* Copyright (c) 2005 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -64,7 +64,7 @@ typedef struct TM2Context{
* Huffman codes for each of streams
*/
typedef struct TM2Codes{
- VLC vlc; ///< table for Libav bitstream reader
+ VLC vlc; ///< table for FFmpeg bitstream reader
int bits;
int *recode; ///< table for converting from code indexes to values
int length;
@@ -817,6 +817,7 @@ static av_cold int decode_init(AVCodecContext *avctx){
l->avctx = avctx;
l->pic.data[0]=NULL;
avctx->pix_fmt = PIX_FMT_BGR24;
+ avcodec_get_frame_defaults(&l->pic);
dsputil_init(&l->dsp, avctx);
@@ -864,14 +865,13 @@ static av_cold int decode_end(AVCodecContext *avctx){
}
AVCodec ff_truemotion2_decoder = {
- "truemotion2",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_TRUEMOTION2,
- sizeof(TM2Context),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- CODEC_CAP_DR1,
+ .name = "truemotion2",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_TRUEMOTION2,
+ .priv_data_size = sizeof(TM2Context),
+ .init = decode_init,
+ .close = decode_end,
+ .decode = decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Duck TrueMotion 2.0"),
};
diff --git a/libavcodec/truespeech.c b/libavcodec/truespeech.c
index df9d918fd7..8cd05145db 100644
--- a/libavcodec/truespeech.c
+++ b/libavcodec/truespeech.c
@@ -2,25 +2,27 @@
* DSP Group TrueSpeech compatible decoder
* Copyright (c) 2005 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/intreadwrite.h"
#include "avcodec.h"
+#include "dsputil.h"
+#include "get_bits.h"
#include "truespeech_data.h"
/**
@@ -32,14 +34,16 @@
* TrueSpeech decoder context
*/
typedef struct {
+ DSPContext dsp;
/* input data */
- int16_t vector[8]; //< input vector: 5/5/4/4/4/3/3/3
- int offset1[2]; //< 8-bit value, used in one copying offset
- int offset2[4]; //< 7-bit value, encodes offsets for copying and for two-point filter
- int pulseoff[4]; //< 4-bit offset of pulse values block
- int pulsepos[4]; //< 27-bit variable, encodes 7 pulse positions
- int pulseval[4]; //< 7x2-bit pulse values
- int flag; //< 1-bit flag, shows how to choose filters
+ uint8_t buffer[32];
+ int16_t vector[8]; ///< input vector: 5/5/4/4/4/3/3/3
+ int offset1[2]; ///< 8-bit value, used in one copying offset
+ int offset2[4]; ///< 7-bit value, encodes offsets for copying and for two-point filter
+ int pulseoff[4]; ///< 4-bit offset of pulse values block
+ int pulsepos[4]; ///< 27-bit variable, encodes 7 pulse positions
+ int pulseval[4]; ///< 7x2-bit pulse values
+ int flag; ///< 1-bit flag, shows how to choose filters
/* temporary data */
int filtbuf[146]; // some big vector used for storing filters
int prevfilt[8]; // filter from previous frame
@@ -54,100 +58,66 @@ typedef struct {
static av_cold int truespeech_decode_init(AVCodecContext * avctx)
{
-// TSContext *c = avctx->priv_data;
+ TSContext *c = avctx->priv_data;
+
+ if (avctx->channels != 1) {
+ av_log_ask_for_sample(avctx, "Unsupported channel count: %d\n", avctx->channels);
+ return AVERROR(EINVAL);
+ }
avctx->sample_fmt = AV_SAMPLE_FMT_S16;
+
+ dsputil_init(&c->dsp, avctx);
+
return 0;
}
static void truespeech_read_frame(TSContext *dec, const uint8_t *input)
{
- uint32_t t;
-
- /* first dword */
- t = AV_RL32(input);
- input += 4;
-
- dec->flag = t & 1;
-
- dec->vector[0] = ts_codebook[0][(t >> 1) & 0x1F];
- dec->vector[1] = ts_codebook[1][(t >> 6) & 0x1F];
- dec->vector[2] = ts_codebook[2][(t >> 11) & 0xF];
- dec->vector[3] = ts_codebook[3][(t >> 15) & 0xF];
- dec->vector[4] = ts_codebook[4][(t >> 19) & 0xF];
- dec->vector[5] = ts_codebook[5][(t >> 23) & 0x7];
- dec->vector[6] = ts_codebook[6][(t >> 26) & 0x7];
- dec->vector[7] = ts_codebook[7][(t >> 29) & 0x7];
-
- /* second dword */
- t = AV_RL32(input);
- input += 4;
-
- dec->offset2[0] = (t >> 0) & 0x7F;
- dec->offset2[1] = (t >> 7) & 0x7F;
- dec->offset2[2] = (t >> 14) & 0x7F;
- dec->offset2[3] = (t >> 21) & 0x7F;
-
- dec->offset1[0] = ((t >> 28) & 0xF) << 4;
-
- /* third dword */
- t = AV_RL32(input);
- input += 4;
-
- dec->pulseval[0] = (t >> 0) & 0x3FFF;
- dec->pulseval[1] = (t >> 14) & 0x3FFF;
-
- dec->offset1[1] = (t >> 28) & 0x0F;
-
- /* fourth dword */
- t = AV_RL32(input);
- input += 4;
-
- dec->pulseval[2] = (t >> 0) & 0x3FFF;
- dec->pulseval[3] = (t >> 14) & 0x3FFF;
-
- dec->offset1[1] |= ((t >> 28) & 0x0F) << 4;
-
- /* fifth dword */
- t = AV_RL32(input);
- input += 4;
-
- dec->pulsepos[0] = (t >> 4) & 0x7FFFFFF;
-
- dec->pulseoff[0] = (t >> 0) & 0xF;
-
- dec->offset1[0] |= (t >> 31) & 1;
-
- /* sixth dword */
- t = AV_RL32(input);
- input += 4;
-
- dec->pulsepos[1] = (t >> 4) & 0x7FFFFFF;
-
- dec->pulseoff[1] = (t >> 0) & 0xF;
-
- dec->offset1[0] |= ((t >> 31) & 1) << 1;
-
- /* seventh dword */
- t = AV_RL32(input);
- input += 4;
-
- dec->pulsepos[2] = (t >> 4) & 0x7FFFFFF;
-
- dec->pulseoff[2] = (t >> 0) & 0xF;
-
- dec->offset1[0] |= ((t >> 31) & 1) << 2;
-
- /* eighth dword */
- t = AV_RL32(input);
- input += 4;
-
- dec->pulsepos[3] = (t >> 4) & 0x7FFFFFF;
-
- dec->pulseoff[3] = (t >> 0) & 0xF;
-
- dec->offset1[0] |= ((t >> 31) & 1) << 3;
-
+ GetBitContext gb;
+
+ dec->dsp.bswap_buf((uint32_t *)dec->buffer, (const uint32_t *)input, 8);
+ init_get_bits(&gb, dec->buffer, 32 * 8);
+
+ dec->vector[7] = ts_codebook[7][get_bits(&gb, 3)];
+ dec->vector[6] = ts_codebook[6][get_bits(&gb, 3)];
+ dec->vector[5] = ts_codebook[5][get_bits(&gb, 3)];
+ dec->vector[4] = ts_codebook[4][get_bits(&gb, 4)];
+ dec->vector[3] = ts_codebook[3][get_bits(&gb, 4)];
+ dec->vector[2] = ts_codebook[2][get_bits(&gb, 4)];
+ dec->vector[1] = ts_codebook[1][get_bits(&gb, 5)];
+ dec->vector[0] = ts_codebook[0][get_bits(&gb, 5)];
+ dec->flag = get_bits1(&gb);
+
+ dec->offset1[0] = get_bits(&gb, 4) << 4;
+ dec->offset2[3] = get_bits(&gb, 7);
+ dec->offset2[2] = get_bits(&gb, 7);
+ dec->offset2[1] = get_bits(&gb, 7);
+ dec->offset2[0] = get_bits(&gb, 7);
+
+ dec->offset1[1] = get_bits(&gb, 4);
+ dec->pulseval[1] = get_bits(&gb, 14);
+ dec->pulseval[0] = get_bits(&gb, 14);
+
+ dec->offset1[1] |= get_bits(&gb, 4) << 4;
+ dec->pulseval[3] = get_bits(&gb, 14);
+ dec->pulseval[2] = get_bits(&gb, 14);
+
+ dec->offset1[0] |= get_bits1(&gb);
+ dec->pulsepos[0] = get_bits_long(&gb, 27);
+ dec->pulseoff[0] = get_bits(&gb, 4);
+
+ dec->offset1[0] |= get_bits1(&gb) << 1;
+ dec->pulsepos[1] = get_bits_long(&gb, 27);
+ dec->pulseoff[1] = get_bits(&gb, 4);
+
+ dec->offset1[0] |= get_bits1(&gb) << 2;
+ dec->pulsepos[2] = get_bits_long(&gb, 27);
+ dec->pulseoff[2] = get_bits(&gb, 4);
+
+ dec->offset1[0] |= get_bits1(&gb) << 3;
+ dec->pulsepos[3] = get_bits_long(&gb, 27);
+ dec->pulseoff[3] = get_bits(&gb, 4);
}
static void truespeech_correlate_filter(TSContext *dec)
@@ -157,7 +127,7 @@ static void truespeech_correlate_filter(TSContext *dec)
for(i = 0; i < 8; i++){
if(i > 0){
- memcpy(tmp, dec->cvector, i * 2);
+ memcpy(tmp, dec->cvector, i * sizeof(*tmp));
for(j = 0; j < i; j++)
dec->cvector[j] = ((tmp[i - j - 1] * dec->vector[i]) +
(dec->cvector[j] << 15) + 0x4000) >> 15;
@@ -199,7 +169,7 @@ static void truespeech_apply_twopoint_filter(TSContext *dec, int quart)
t = dec->offset2[quart];
if(t == 127){
- memset(dec->newvec, 0, 60 * 2);
+ memset(dec->newvec, 0, 60 * sizeof(*dec->newvec));
return;
}
for(i = 0; i < 146; i++)
@@ -224,7 +194,7 @@ static void truespeech_place_pulses(TSContext *dec, int16_t *out, int quart)
int16_t *ptr2;
int coef;
- memset(out, 0, 60 * 2);
+ memset(out, 0, 60 * sizeof(*out));
for(i = 0; i < 7; i++) {
t = dec->pulseval[quart] & 3;
dec->pulseval[quart] >>= 2;
@@ -340,55 +310,53 @@ static int truespeech_decode_frame(AVCodecContext *avctx,
int i, j;
short *samples = data;
- int consumed = 0;
- int16_t out_buf[240];
- int iterations;
+ int iterations, out_size;
- if (!buf_size)
- return 0;
+ iterations = buf_size / 32;
- if (buf_size < 32) {
+ if (!iterations) {
av_log(avctx, AV_LOG_ERROR,
"Too small input buffer (%d bytes), need at least 32 bytes\n", buf_size);
return -1;
}
- iterations = FFMIN(buf_size / 32, *data_size / 480);
+
+ out_size = iterations * 240 * av_get_bytes_per_sample(avctx->sample_fmt);
+ if (*data_size < out_size) {
+ av_log(avctx, AV_LOG_ERROR, "Output buffer is too small\n");
+ return AVERROR(EINVAL);
+ }
+
+ memset(samples, 0, out_size);
+
for(j = 0; j < iterations; j++) {
- truespeech_read_frame(c, buf + consumed);
- consumed += 32;
+ truespeech_read_frame(c, buf);
+ buf += 32;
truespeech_correlate_filter(c);
truespeech_filters_merge(c);
- memset(out_buf, 0, 240 * 2);
for(i = 0; i < 4; i++) {
truespeech_apply_twopoint_filter(c, i);
- truespeech_place_pulses(c, out_buf + i * 60, i);
- truespeech_update_filters(c, out_buf + i * 60, i);
- truespeech_synth(c, out_buf + i * 60, i);
+ truespeech_place_pulses (c, samples, i);
+ truespeech_update_filters(c, samples, i);
+ truespeech_synth (c, samples, i);
+ samples += 60;
}
truespeech_save_prevvec(c);
-
- /* finally output decoded frame */
- for(i = 0; i < 240; i++)
- *samples++ = out_buf[i];
-
}
- *data_size = consumed * 15;
+ *data_size = out_size;
- return consumed;
+ return buf_size;
}
AVCodec ff_truespeech_decoder = {
- "truespeech",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_TRUESPEECH,
- sizeof(TSContext),
- truespeech_decode_init,
- NULL,
- NULL,
- truespeech_decode_frame,
+ .name = "truespeech",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_TRUESPEECH,
+ .priv_data_size = sizeof(TSContext),
+ .init = truespeech_decode_init,
+ .decode = truespeech_decode_frame,
.long_name = NULL_IF_CONFIG_SMALL("DSP Group TrueSpeech"),
};
diff --git a/libavcodec/truespeech_data.h b/libavcodec/truespeech_data.h
index 6e9806a0b5..73ebda5e85 100644
--- a/libavcodec/truespeech_data.h
+++ b/libavcodec/truespeech_data.h
@@ -2,20 +2,20 @@
* DSP Group TrueSpeech compatible decoder
* copyright (c) 2005 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/tscc.c b/libavcodec/tscc.c
index 772906aba6..54c008714f 100644
--- a/libavcodec/tscc.c
+++ b/libavcodec/tscc.c
@@ -2,20 +2,20 @@
* TechSmith Camtasia decoder
* Copyright (c) 2004 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -142,6 +142,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
c->height = avctx->height;
+ avcodec_get_frame_defaults(&c->pic);
// Needed if zlib unused or init aborted before inflateInit
memset(&(c->zstream), 0, sizeof(z_stream));
switch(avctx->bits_per_coded_sample){
@@ -199,15 +200,14 @@ static av_cold int decode_end(AVCodecContext *avctx)
}
AVCodec ff_tscc_decoder = {
- "camtasia",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_TSCC,
- sizeof(CamtasiaContext),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- CODEC_CAP_DR1,
- .long_name = NULL_IF_CONFIG_SMALL("TechSmith Screen Capture Codec"),
+ .name = "camtasia",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_TSCC,
+ .priv_data_size = sizeof(CamtasiaContext),
+ .init = decode_init,
+ .close = decode_end,
+ .decode = decode_frame,
+ .capabilities = CODEC_CAP_DR1,
+ .long_name = NULL_IF_CONFIG_SMALL("TechSmith Screen Capture Codec"),
};
diff --git a/libavcodec/tta.c b/libavcodec/tta.c
index 57f5818d7b..0bd8c600bf 100644
--- a/libavcodec/tta.c
+++ b/libavcodec/tta.c
@@ -2,29 +2,29 @@
* TTA (The Lossless True Audio) decoder
* Copyright (c) 2006 Alex Beregszaszi
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* TTA (The Lossless True Audio) decoder
- * (www.true-audio.com or tta.corecodec.org)
+ * @see http://www.true-audio.com/
+ * @see http://tta.corecodec.org/
* @author Alex Beregszaszi
- *
*/
#define ALT_BITSTREAM_READER_LE
@@ -66,23 +66,6 @@ typedef struct TTAContext {
TTAChannel *ch_ctx;
} TTAContext;
-#if 0
-static inline int shift_1(int i)
-{
- if (i < 32)
- return 1 << i;
- else
- return 0x80000000; // 16 << 31
-}
-
-static inline int shift_16(int i)
-{
- if (i < 28)
- return 16 << i;
- else
- return 0x80000000; // 16 << 27
-}
-#else
static const uint32_t shift_1[] = {
0x00000001, 0x00000002, 0x00000004, 0x00000008,
0x00000010, 0x00000020, 0x00000040, 0x00000080,
@@ -97,7 +80,6 @@ static const uint32_t shift_1[] = {
};
static const uint32_t * const shift_16 = shift_1 + 4;
-#endif
static const int32_t ttafilter_configs[4][2] = {
{10, 1},
@@ -205,6 +187,16 @@ static int tta_get_unary(GetBitContext *gb)
return ret;
}
+static const int64_t tta_channel_layouts[7] = {
+ AV_CH_LAYOUT_STEREO,
+ AV_CH_LAYOUT_STEREO|AV_CH_LOW_FREQUENCY,
+ AV_CH_LAYOUT_QUAD,
+ 0,
+ AV_CH_LAYOUT_5POINT1_BACK,
+ AV_CH_LAYOUT_5POINT1_BACK|AV_CH_BACK_CENTER,
+ AV_CH_LAYOUT_7POINT1_WIDE
+};
+
static av_cold int tta_decode_init(AVCodecContext * avctx)
{
TTAContext *s = avctx->priv_data;
@@ -216,7 +208,7 @@ static av_cold int tta_decode_init(AVCodecContext * avctx)
if (avctx->extradata_size < 30)
return -1;
- init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size);
+ init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size * 8);
if (show_bits_long(&s->gb, 32) == AV_RL32("TTA1"))
{
/* signature */
@@ -234,6 +226,8 @@ static av_cold int tta_decode_init(AVCodecContext * avctx)
}
s->is_float = (s->flags == FORMAT_FLOAT);
avctx->channels = s->channels = get_bits(&s->gb, 16);
+ if (s->channels > 1 && s->channels < 9)
+ avctx->channel_layout = tta_channel_layouts[s->channels-2];
avctx->bits_per_coded_sample = get_bits(&s->gb, 16);
s->bps = (avctx->bits_per_coded_sample + 7) / 8;
avctx->sample_rate = get_bits_long(&s->gb, 32);
@@ -251,9 +245,9 @@ static av_cold int tta_decode_init(AVCodecContext * avctx)
return -1;
}
else switch(s->bps) {
-// case 1: avctx->sample_fmt = AV_SAMPLE_FMT_U8; break;
+ case 1: avctx->sample_fmt = AV_SAMPLE_FMT_U8; break;
case 2: avctx->sample_fmt = AV_SAMPLE_FMT_S16; break;
-// case 3: avctx->sample_fmt = AV_SAMPLE_FMT_S24; break;
+ case 3: avctx->bits_per_coded_sample = 24;
case 4: avctx->sample_fmt = AV_SAMPLE_FMT_S32; break;
default:
av_log_ask_for_sample(s->avctx,
@@ -286,6 +280,8 @@ static av_cold int tta_decode_init(AVCodecContext * avctx)
}
s->decode_buffer = av_mallocz(sizeof(int32_t)*s->frame_length*s->channels);
+ if (!s->decode_buffer)
+ return AVERROR(ENOMEM);
s->ch_ctx = av_malloc(avctx->channels * sizeof(*s->ch_ctx));
if (!s->ch_ctx)
return AVERROR(ENOMEM);
@@ -311,7 +307,7 @@ static int tta_decode_frame(AVCodecContext *avctx,
int cur_chan = 0, framelen = s->frame_length;
int32_t *p;
- if (*data_size < (framelen * s->channels * 2)) {
+ if (*data_size < (framelen * s->channels * av_get_bits_per_sample_fmt(avctx->sample_fmt) / 8)) {
av_log(avctx, AV_LOG_ERROR, "Output buffer size is too small.\n");
return -1;
}
@@ -389,19 +385,6 @@ static int tta_decode_frame(AVCodecContext *avctx,
}
*predictor = *p;
-#if 0
- // extract 32bit float from last two int samples
- if (s->is_float && ((p - data) & 1)) {
- uint32_t neg = *p & 0x80000000;
- uint32_t hi = *(p - 1);
- uint32_t lo = abs(*p) - 1;
-
- hi += (hi || lo) ? 0x3f80 : 0;
- // SWAP16: swap all the 16 bits
- *(p - 1) = (hi << 16) | SWAP16(lo) | neg;
- }
-#endif
-
/*if ((get_bits_count(&s->gb)+7)/8 > buf_size)
{
av_log(NULL, AV_LOG_INFO, "overread!!\n");
@@ -428,6 +411,13 @@ static int tta_decode_frame(AVCodecContext *avctx,
// convert to output buffer
switch(s->bps) {
+ case 1: {
+ uint8_t *samples = data;
+ for (p = s->decode_buffer; p < s->decode_buffer + (framelen * s->channels); p++)
+ *samples++ = *p + 0x80;
+ *data_size = samples - (uint8_t *)data;
+ break;
+ }
case 2: {
uint16_t *samples = data;
for (p = s->decode_buffer; p < s->decode_buffer + (framelen * s->channels); p++) {
@@ -438,6 +428,13 @@ static int tta_decode_frame(AVCodecContext *avctx,
*data_size = (uint8_t *)samples - (uint8_t *)data;
break;
}
+ case 3: {
+ int32_t *samples = data;
+ for (p = s->decode_buffer; p < s->decode_buffer + (framelen * s->channels); p++)
+ *samples++ = AV_RN32(p) << 8;
+ *data_size = (uint8_t *)samples - (uint8_t *)data;
+ break;
+ }
default:
av_log(s->avctx, AV_LOG_ERROR, "Error, only 16bit samples supported!\n");
}
@@ -457,13 +454,12 @@ static av_cold int tta_decode_close(AVCodecContext *avctx) {
}
AVCodec ff_tta_decoder = {
- "tta",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_TTA,
- sizeof(TTAContext),
- tta_decode_init,
- NULL,
- tta_decode_close,
- tta_decode_frame,
+ .name = "tta",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_TTA,
+ .priv_data_size = sizeof(TTAContext),
+ .init = tta_decode_init,
+ .close = tta_decode_close,
+ .decode = tta_decode_frame,
.long_name = NULL_IF_CONFIG_SMALL("True Audio (TTA)"),
};
diff --git a/libavcodec/twinvq.c b/libavcodec/twinvq.c
index 86c81a1b0f..17c268dad1 100644
--- a/libavcodec/twinvq.c
+++ b/libavcodec/twinvq.c
@@ -2,20 +2,20 @@
* TwinVQ decoder
* Copyright (c) 2009 Vitor Sessak
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -1120,15 +1120,13 @@ static av_cold int twin_decode_close(AVCodecContext *avctx)
return 0;
}
-AVCodec ff_twinvq_decoder =
-{
- "twinvq",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_TWINVQ,
- sizeof(TwinContext),
- twin_decode_init,
- NULL,
- twin_decode_close,
- twin_decode_frame,
- .long_name = NULL_IF_CONFIG_SMALL("VQF TwinVQ"),
+AVCodec ff_twinvq_decoder = {
+ .name = "twinvq",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_TWINVQ,
+ .priv_data_size = sizeof(TwinContext),
+ .init = twin_decode_init,
+ .close = twin_decode_close,
+ .decode = twin_decode_frame,
+ .long_name = NULL_IF_CONFIG_SMALL("VQF TwinVQ"),
};
diff --git a/libavcodec/twinvq_data.h b/libavcodec/twinvq_data.h
index 1f1f33408e..3042cd1beb 100644
--- a/libavcodec/twinvq_data.h
+++ b/libavcodec/twinvq_data.h
@@ -2,20 +2,20 @@
* TwinVQ decoder
* Copyright (c) 2009 Vitor Sessak
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/txd.c b/libavcodec/txd.c
index e91b4fbaf3..1b9755cc19 100644
--- a/libavcodec/txd.c
+++ b/libavcodec/txd.c
@@ -4,25 +4,26 @@
*
* See also: http://wiki.multimedia.cx/index.php?title=TXD
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/intreadwrite.h"
#include "libavutil/imgutils.h"
+#include "bytestream.h"
#include "avcodec.h"
#include "s3tc.h"
@@ -42,6 +43,7 @@ static av_cold int txd_init(AVCodecContext *avctx) {
static int txd_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
AVPacket *avpkt) {
const uint8_t *buf = avpkt->data;
+ const uint8_t *buf_end = avpkt->data + avpkt->size;
TXDContext * const s = avctx->priv_data;
AVFrame *picture = data;
AVFrame * const p = &s->picture;
@@ -52,6 +54,8 @@ static int txd_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
const uint32_t *palette = (const uint32_t *)(cur + 88);
uint32_t *pal;
+ if (buf_end - cur < 92)
+ return AVERROR_INVALIDDATA;
version = AV_RL32(cur);
d3d_format = AV_RL32(cur+76);
w = AV_RL16(cur+80);
@@ -69,6 +73,8 @@ static int txd_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
if (depth == 8) {
avctx->pix_fmt = PIX_FMT_PAL8;
+ if (buf_end - cur < 1024)
+ return AVERROR_INVALIDDATA;
cur += 1024;
} else if (depth == 16 || depth == 32)
avctx->pix_fmt = PIX_FMT_RGB32;
@@ -100,6 +106,8 @@ static int txd_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
v = AV_RB32(palette+y);
pal[y] = (v>>8) + (v<<24);
}
+ if (buf_end - cur < w * h)
+ return AVERROR_INVALIDDATA;
for (y=0; y<h; y++) {
memcpy(ptr, cur, w);
ptr += stride;
@@ -110,9 +118,13 @@ static int txd_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
case 0:
if (!flags&1) goto unsupported;
case FF_S3TC_DXT1:
+ if (buf_end - cur < (w/4) * (h/4) * 8)
+ return AVERROR_INVALIDDATA;
ff_decode_dxt1(cur, ptr, w, h, stride);
break;
case FF_S3TC_DXT3:
+ if (buf_end - cur < (w/4) * (h/4) * 16)
+ return AVERROR_INVALIDDATA;
ff_decode_dxt3(cur, ptr, w, h, stride);
break;
default:
@@ -122,6 +134,8 @@ static int txd_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
switch (d3d_format) {
case 0x15:
case 0x16:
+ if (buf_end - cur < h * w * 4)
+ return AVERROR_INVALIDDATA;
for (y=0; y<h; y++) {
memcpy(ptr, cur, w*4);
ptr += stride;
@@ -133,8 +147,12 @@ static int txd_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
}
}
- for (; mipmap_count > 1; mipmap_count--)
- cur += AV_RL32(cur) + 4;
+ for (; mipmap_count > 1 && buf_end - cur >= 4; mipmap_count--) {
+ uint32_t length = bytestream_get_le32(&cur);
+ if (buf_end - cur < length)
+ break;
+ cur += length;
+ }
*picture = s->picture;
*data_size = sizeof(AVPicture);
@@ -156,15 +174,13 @@ static av_cold int txd_end(AVCodecContext *avctx) {
}
AVCodec ff_txd_decoder = {
- "txd",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_TXD,
- sizeof(TXDContext),
- txd_init,
- NULL,
- txd_end,
- txd_decode_frame,
- CODEC_CAP_DR1,
- NULL,
+ .name = "txd",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_TXD,
+ .priv_data_size = sizeof(TXDContext),
+ .init = txd_init,
+ .close = txd_end,
+ .decode = txd_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Renderware TXD (TeXture Dictionary) image"),
};
diff --git a/libavcodec/ulti.c b/libavcodec/ulti.c
index 9a73c627a9..6d41cd9d06 100644
--- a/libavcodec/ulti.c
+++ b/libavcodec/ulti.c
@@ -2,20 +2,20 @@
* IBM Ultimotion Video Decoder
* Copyright (C) 2004 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -49,6 +49,7 @@ static av_cold int ulti_decode_init(AVCodecContext *avctx)
s->height = avctx->height;
s->blocks = (s->width / 8) * (s->height / 8);
avctx->pix_fmt = PIX_FMT_YUV410P;
+ avcodec_get_frame_defaults(&s->frame);
avctx->coded_frame = (AVFrame*) &s->frame;
s->ulti_codebook = ulti_codebook;
@@ -402,16 +403,14 @@ static int ulti_decode_frame(AVCodecContext *avctx,
}
AVCodec ff_ulti_decoder = {
- "ultimotion",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_ULTI,
- sizeof(UltimotionDecodeContext),
- ulti_decode_init,
- NULL,
- ulti_decode_end,
- ulti_decode_frame,
- CODEC_CAP_DR1,
- NULL,
+ .name = "ultimotion",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_ULTI,
+ .priv_data_size = sizeof(UltimotionDecodeContext),
+ .init = ulti_decode_init,
+ .close = ulti_decode_end,
+ .decode = ulti_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("IBM UltiMotion"),
};
diff --git a/libavcodec/ulti_cb.h b/libavcodec/ulti_cb.h
index 0bd83ffd37..7061d839a8 100644
--- a/libavcodec/ulti_cb.h
+++ b/libavcodec/ulti_cb.h
@@ -2,20 +2,20 @@
* IBM Ultimotion Video Decoder
* copyright (C) 2004 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/unary.h b/libavcodec/unary.h
index d14929f797..908dc93507 100644
--- a/libavcodec/unary.h
+++ b/libavcodec/unary.h
@@ -1,20 +1,20 @@
/*
* copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 722f758231..405fc31318 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -3,20 +3,20 @@
* Copyright (c) 2001 Fabrice Bellard
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -32,6 +32,7 @@
#include "libavutil/audioconvert.h"
#include "libavutil/imgutils.h"
#include "libavutil/samplefmt.h"
+#include "libavutil/dict.h"
#include "avcodec.h"
#include "dsputil.h"
#include "libavutil/opt.h"
@@ -84,6 +85,20 @@ AVCodec *av_codec_next(AVCodec *c){
else return first_avcodec;
}
+#if !FF_API_AVCODEC_INIT
+static
+#endif
+void avcodec_init(void)
+{
+ static int initialized = 0;
+
+ if (initialized != 0)
+ return;
+ initialized = 1;
+
+ dsputil_static_init();
+}
+
void avcodec_register(AVCodec *codec)
{
AVCodec **p;
@@ -92,6 +107,9 @@ void avcodec_register(AVCodec *codec)
while (*p != NULL) p = &(*p)->next;
*p = codec;
codec->next = NULL;
+
+ if (codec->init_static_data)
+ codec->init_static_data(codec);
}
unsigned avcodec_get_edge_width(void)
@@ -140,6 +158,8 @@ void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height, int l
case PIX_FMT_YUV420P9BE:
case PIX_FMT_YUV420P10LE:
case PIX_FMT_YUV420P10BE:
+ case PIX_FMT_YUV422P9LE:
+ case PIX_FMT_YUV422P9BE:
case PIX_FMT_YUV422P10LE:
case PIX_FMT_YUV422P10BE:
case PIX_FMT_YUV444P9LE:
@@ -148,7 +168,7 @@ void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height, int l
case PIX_FMT_YUV444P10BE:
w_align= 16; //FIXME check for non mpeg style codecs and use less alignment
h_align= 16;
- if(s->codec_id == CODEC_ID_MPEG2VIDEO || s->codec_id == CODEC_ID_MJPEG || s->codec_id == CODEC_ID_AMV || s->codec_id == CODEC_ID_THP || s->codec_id == CODEC_ID_H264)
+ if(s->codec_id == CODEC_ID_MPEG2VIDEO || s->codec_id == CODEC_ID_MJPEG || s->codec_id == CODEC_ID_AMV || s->codec_id == CODEC_ID_THP || s->codec_id == CODEC_ID_H264 || s->codec_id == CODEC_ID_PRORES)
h_align= 32; // interlaced is rounded up to 2 MBs
break;
case PIX_FMT_YUV411P:
@@ -223,6 +243,22 @@ void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height){
*width=FFALIGN(*width, align);
}
+void ff_init_buffer_info(AVCodecContext *s, AVFrame *pic)
+{
+ if (s->pkt) {
+ pic->pkt_pts = s->pkt->pts;
+ pic->pkt_pos = s->pkt->pos;
+ } else {
+ pic->pkt_pts = AV_NOPTS_VALUE;
+ pic->pkt_pos = -1;
+ }
+ pic->reordered_opaque= s->reordered_opaque;
+ pic->sample_aspect_ratio = s->sample_aspect_ratio;
+ pic->width = s->width;
+ pic->height = s->height;
+ pic->format = s->pix_fmt;
+}
+
int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){
int i;
int w= s->width;
@@ -347,9 +383,18 @@ int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){
}
s->internal_buffer_count++;
- if(s->pkt) pic->pkt_pts= s->pkt->pts;
- else pic->pkt_pts= AV_NOPTS_VALUE;
+ if (s->pkt) {
+ pic->pkt_pts = s->pkt->pts;
+ pic->pkt_pos = s->pkt->pos;
+ } else {
+ pic->pkt_pts = AV_NOPTS_VALUE;
+ pic->pkt_pos = -1;
+ }
pic->reordered_opaque= s->reordered_opaque;
+ pic->sample_aspect_ratio = s->sample_aspect_ratio;
+ pic->width = s->width;
+ pic->height = s->height;
+ pic->format = s->pix_fmt;
if(s->debug&FF_DEBUG_BUFFERS)
av_log(s, AV_LOG_DEBUG, "default_get_buffer called on pic %p, %d buffers used\n", pic, s->internal_buffer_count);
@@ -453,8 +498,11 @@ enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum
void avcodec_get_frame_defaults(AVFrame *pic){
memset(pic, 0, sizeof(AVFrame));
- pic->pts= AV_NOPTS_VALUE;
+ pic->pts = pic->best_effort_timestamp = AV_NOPTS_VALUE;
+ pic->pkt_pos = -1;
pic->key_frame= 1;
+ pic->sample_aspect_ratio = (AVRational){0, 1};
+ pic->format = -1; /* unknown */
}
AVFrame *avcodec_alloc_frame(void){
@@ -467,9 +515,26 @@ AVFrame *avcodec_alloc_frame(void){
return pic;
}
+static void avcodec_get_subtitle_defaults(AVSubtitle *sub)
+{
+ memset(sub, 0, sizeof(*sub));
+ sub->pts = AV_NOPTS_VALUE;
+}
+
+#if FF_API_AVCODEC_OPEN
int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec)
{
+ return avcodec_open2(avctx, codec, NULL);
+}
+#endif
+
+int attribute_align_arg avcodec_open2(AVCodecContext *avctx, AVCodec *codec, AVDictionary **options)
+{
int ret = 0;
+ AVDictionary *tmp = NULL;
+
+ if (options)
+ av_dict_copy(&tmp, *options, 0);
/* If there is a user-supplied mutex locking routine, call it. */
if (ff_lockmgr_cb) {
@@ -496,14 +561,18 @@ int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec)
ret = AVERROR(ENOMEM);
goto end;
}
- if(codec->priv_class){ //this can be droped once all user apps use avcodec_get_context_defaults3()
+ if (codec->priv_class) {
*(AVClass**)avctx->priv_data= codec->priv_class;
av_opt_set_defaults(avctx->priv_data);
}
}
+ if (codec->priv_class && (ret = av_opt_set_dict(avctx->priv_data, &tmp)) < 0)
+ goto free_and_end;
} else {
avctx->priv_data = NULL;
}
+ if ((ret = av_opt_set_dict(avctx, &tmp)) < 0)
+ goto free_and_end;
if(avctx->coded_width && avctx->coded_height)
avcodec_set_dimensions(avctx, avctx->coded_width, avctx->coded_height);
@@ -542,6 +611,9 @@ int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec)
}
avctx->frame_number = 0;
+ if (!HAVE_THREADS)
+ av_log(avctx, AV_LOG_WARNING, "Warning: not compiled with thread support, using thread emulation\n");
+
if (HAVE_THREADS && !avctx->thread_opaque) {
ret = ff_thread_init(avctx);
if (ret < 0) {
@@ -549,11 +621,10 @@ int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec)
}
}
- if (avctx->codec->max_lowres < avctx->lowres) {
- av_log(avctx, AV_LOG_ERROR, "The maximum value for lowres supported by the decoder is %d\n",
+ if (avctx->codec->max_lowres < avctx->lowres || avctx->lowres < 0) {
+ av_log(avctx, AV_LOG_WARNING, "The maximum value for lowres supported by the decoder is %d\n",
avctx->codec->max_lowres);
- ret = AVERROR(EINVAL);
- goto free_and_end;
+ avctx->lowres = avctx->codec->max_lowres;
}
if (avctx->codec->encode) {
int i;
@@ -602,12 +673,19 @@ int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec)
}
}
+ avctx->pts_correction_num_faulty_pts =
+ avctx->pts_correction_num_faulty_dts = 0;
+ avctx->pts_correction_last_pts =
+ avctx->pts_correction_last_dts = INT64_MIN;
+
if(avctx->codec->init && !(avctx->active_thread_type&FF_THREAD_FRAME)){
ret = avctx->codec->init(avctx);
if (ret < 0) {
goto free_and_end;
}
}
+
+ ret=0;
end:
entangled_thread_counter--;
@@ -615,8 +693,14 @@ end:
if (ff_lockmgr_cb) {
(*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE);
}
+ if (options) {
+ av_dict_free(options);
+ *options = tmp;
+ }
+
return ret;
free_and_end:
+ av_dict_free(&tmp);
av_freep(&avctx->priv_data);
avctx->codec= NULL;
goto end;
@@ -664,13 +748,44 @@ int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size,
av_log(avctx, AV_LOG_ERROR, "start_display_time must be 0.\n");
return -1;
}
- if(sub->num_rects == 0 || !sub->rects)
- return -1;
+
ret = avctx->codec->encode(avctx, buf, buf_size, sub);
avctx->frame_number++;
return ret;
}
+/**
+ * Attempt to guess proper monotonic timestamps for decoded video frames
+ * which might have incorrect times. Input timestamps may wrap around, in
+ * which case the output will as well.
+ *
+ * @param pts the pts field of the decoded AVPacket, as passed through
+ * AVFrame.pkt_pts
+ * @param dts the dts field of the decoded AVPacket
+ * @return one of the input values, may be AV_NOPTS_VALUE
+ */
+static int64_t guess_correct_pts(AVCodecContext *ctx,
+ int64_t reordered_pts, int64_t dts)
+{
+ int64_t pts = AV_NOPTS_VALUE;
+
+ if (dts != AV_NOPTS_VALUE) {
+ ctx->pts_correction_num_faulty_dts += dts <= ctx->pts_correction_last_dts;
+ ctx->pts_correction_last_dts = dts;
+ }
+ if (reordered_pts != AV_NOPTS_VALUE) {
+ ctx->pts_correction_num_faulty_pts += reordered_pts <= ctx->pts_correction_last_pts;
+ ctx->pts_correction_last_pts = reordered_pts;
+ }
+ if ((ctx->pts_correction_num_faulty_pts<=ctx->pts_correction_num_faulty_dts || dts == AV_NOPTS_VALUE)
+ && reordered_pts != AV_NOPTS_VALUE)
+ pts = reordered_pts;
+ else
+ pts = dts;
+
+ return pts;
+}
+
int attribute_align_arg avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture,
int *got_picture_ptr,
AVPacket *avpkt)
@@ -681,22 +796,40 @@ int attribute_align_arg avcodec_decode_video2(AVCodecContext *avctx, AVFrame *pi
if((avctx->coded_width||avctx->coded_height) && av_image_check_size(avctx->coded_width, avctx->coded_height, 0, avctx))
return -1;
- avctx->pkt = avpkt;
-
if((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size || (avctx->active_thread_type&FF_THREAD_FRAME)){
- if (HAVE_PTHREADS && avctx->active_thread_type&FF_THREAD_FRAME)
+ av_packet_split_side_data(avpkt);
+ avctx->pkt = avpkt;
+ if (HAVE_THREADS && avctx->active_thread_type&FF_THREAD_FRAME)
ret = ff_thread_decode_frame(avctx, picture, got_picture_ptr,
avpkt);
else {
ret = avctx->codec->decode(avctx, picture, got_picture_ptr,
avpkt);
picture->pkt_dts= avpkt->dts;
+
+ if(!avctx->has_b_frames){
+ picture->pkt_pos= avpkt->pos;
+ }
+ //FIXME these should be under if(!avctx->has_b_frames)
+ if (!picture->sample_aspect_ratio.num)
+ picture->sample_aspect_ratio = avctx->sample_aspect_ratio;
+ if (!picture->width)
+ picture->width = avctx->width;
+ if (!picture->height)
+ picture->height = avctx->height;
+ if (picture->format == PIX_FMT_NONE)
+ picture->format = avctx->pix_fmt;
}
emms_c(); //needed to avoid an emms_c() call before every return;
- if (*got_picture_ptr)
+
+ if (*got_picture_ptr){
avctx->frame_number++;
+ picture->best_effort_timestamp = guess_correct_pts(avctx,
+ picture->pkt_pts,
+ picture->pkt_dts);
+ }
}else
ret= 0;
@@ -711,6 +844,11 @@ int attribute_align_arg avcodec_decode_audio3(AVCodecContext *avctx, int16_t *sa
avctx->pkt = avpkt;
+ if (!avpkt->data && avpkt->size) {
+ av_log(avctx, AV_LOG_ERROR, "invalid packet: NULL data, size != 0\n");
+ return AVERROR(EINVAL);
+ }
+
if((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size){
//FIXME remove the check below _after_ ensuring that all audio check that the available space is enough
if(*frame_size_ptr < AVCODEC_MAX_AUDIO_FRAME_SIZE){
@@ -740,6 +878,7 @@ int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
avctx->pkt = avpkt;
*got_sub_ptr = 0;
+ avcodec_get_subtitle_defaults(sub);
ret = avctx->codec->decode(avctx, sub, got_sub_ptr, avpkt);
if (*got_sub_ptr)
avctx->frame_number++;
@@ -836,14 +975,18 @@ AVCodec *avcodec_find_encoder_by_name(const char *name)
AVCodec *avcodec_find_decoder(enum CodecID id)
{
- AVCodec *p;
+ AVCodec *p, *experimental=NULL;
p = first_avcodec;
while (p) {
- if (p->decode != NULL && p->id == id)
- return p;
+ if (p->decode != NULL && p->id == id) {
+ if (p->capabilities & CODEC_CAP_EXPERIMENTAL && !experimental) {
+ experimental = p;
+ } else
+ return p;
+ }
p = p->next;
}
- return NULL;
+ return experimental;
}
AVCodec *avcodec_find_decoder_by_name(const char *name)
@@ -883,6 +1026,25 @@ static int get_bit_rate(AVCodecContext *ctx)
return bit_rate;
}
+const char *avcodec_get_name(enum CodecID id)
+{
+ AVCodec *codec;
+
+#if !CONFIG_SMALL
+ switch (id) {
+#include "libavcodec/codec_names.h"
+ }
+ av_log(NULL, AV_LOG_WARNING, "Codec 0x%x is not in the full list.\n", id);
+#endif
+ codec = avcodec_find_decoder(id);
+ if (codec)
+ return codec->name;
+ codec = avcodec_find_encoder(id);
+ if (codec)
+ return codec->name;
+ return "unknown_codec";
+}
+
size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_tag)
{
int i, len, ret = 0;
@@ -900,43 +1062,37 @@ size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_ta
void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
{
+ const char *codec_type;
const char *codec_name;
const char *profile = NULL;
AVCodec *p;
- char buf1[32];
int bitrate;
AVRational display_aspect_ratio;
- if (encode)
- p = avcodec_find_encoder(enc->codec_id);
- else
- p = avcodec_find_decoder(enc->codec_id);
-
- if (p) {
- codec_name = p->name;
- profile = av_get_profile_name(p, enc->profile);
- } else if (enc->codec_id == CODEC_ID_MPEG2TS) {
- /* fake mpeg2 transport stream codec (currently not
- registered) */
- codec_name = "mpeg2ts";
- } else if (enc->codec_name[0] != '\0') {
- codec_name = enc->codec_name;
- } else {
- /* output avi tags */
+ if (!buf || buf_size <= 0)
+ return;
+ codec_type = av_get_media_type_string(enc->codec_type);
+ codec_name = avcodec_get_name(enc->codec_id);
+ if (enc->profile != FF_PROFILE_UNKNOWN) {
+ p = encode ? avcodec_find_encoder(enc->codec_id) :
+ avcodec_find_decoder(enc->codec_id);
+ if (p)
+ profile = av_get_profile_name(p, enc->profile);
+ }
+
+ snprintf(buf, buf_size, "%s: %s%s", codec_type ? codec_type : "unknown",
+ codec_name, enc->mb_decision ? " (hq)" : "");
+ buf[0] ^= 'a' ^ 'A'; /* first letter in uppercase */
+ if (profile)
+ snprintf(buf + strlen(buf), buf_size - strlen(buf), " (%s)", profile);
+ if (enc->codec_tag) {
char tag_buf[32];
av_get_codec_tag_string(tag_buf, sizeof(tag_buf), enc->codec_tag);
- snprintf(buf1, sizeof(buf1), "%s / 0x%04X", tag_buf, enc->codec_tag);
- codec_name = buf1;
+ snprintf(buf + strlen(buf), buf_size - strlen(buf),
+ " (%s / 0x%04X)", tag_buf, enc->codec_tag);
}
-
switch(enc->codec_type) {
case AVMEDIA_TYPE_VIDEO:
- snprintf(buf, buf_size,
- "Video: %s%s",
- codec_name, enc->mb_decision ? " (hq)" : "");
- if (profile)
- snprintf(buf + strlen(buf), buf_size - strlen(buf),
- " (%s)", profile);
if (enc->pix_fmt != PIX_FMT_NONE) {
snprintf(buf + strlen(buf), buf_size - strlen(buf),
", %s",
@@ -952,7 +1108,7 @@ void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
enc->height*enc->sample_aspect_ratio.den,
1024*1024);
snprintf(buf + strlen(buf), buf_size - strlen(buf),
- " [PAR %d:%d DAR %d:%d]",
+ " [SAR %d:%d DAR %d:%d]",
enc->sample_aspect_ratio.num, enc->sample_aspect_ratio.den,
display_aspect_ratio.num, display_aspect_ratio.den);
}
@@ -969,12 +1125,6 @@ void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
}
break;
case AVMEDIA_TYPE_AUDIO:
- snprintf(buf, buf_size,
- "Audio: %s",
- codec_name);
- if (profile)
- snprintf(buf + strlen(buf), buf_size - strlen(buf),
- " (%s)", profile);
if (enc->sample_rate) {
snprintf(buf + strlen(buf), buf_size - strlen(buf),
", %d Hz", enc->sample_rate);
@@ -986,17 +1136,7 @@ void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
", %s", av_get_sample_fmt_name(enc->sample_fmt));
}
break;
- case AVMEDIA_TYPE_DATA:
- snprintf(buf, buf_size, "Data: %s", codec_name);
- break;
- case AVMEDIA_TYPE_SUBTITLE:
- snprintf(buf, buf_size, "Subtitle: %s", codec_name);
- break;
- case AVMEDIA_TYPE_ATTACHMENT:
- snprintf(buf, buf_size, "Attachment: %s", codec_name);
- break;
default:
- snprintf(buf, buf_size, "Invalid Codec type %d", enc->codec_type);
return;
}
if (encode) {
@@ -1034,31 +1174,20 @@ unsigned avcodec_version( void )
const char *avcodec_configuration(void)
{
- return LIBAV_CONFIGURATION;
+ return FFMPEG_CONFIGURATION;
}
const char *avcodec_license(void)
{
#define LICENSE_PREFIX "libavcodec license: "
- return LICENSE_PREFIX LIBAV_LICENSE + sizeof(LICENSE_PREFIX) - 1;
-}
-
-void avcodec_init(void)
-{
- static int initialized = 0;
-
- if (initialized != 0)
- return;
- initialized = 1;
-
- dsputil_static_init();
+ return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1;
}
void avcodec_flush_buffers(AVCodecContext *avctx)
{
- if(HAVE_PTHREADS && avctx->active_thread_type&FF_THREAD_FRAME)
+ if(HAVE_THREADS && avctx->active_thread_type&FF_THREAD_FRAME)
ff_thread_flush(avctx);
- if(avctx->codec->flush)
+ else if(avctx->codec->flush)
avctx->codec->flush(avctx);
}
@@ -1096,6 +1225,8 @@ int av_get_bits_per_sample(enum CodecID codec_id){
case CODEC_ID_ADPCM_SBPRO_4:
case CODEC_ID_ADPCM_CT:
case CODEC_ID_ADPCM_IMA_WAV:
+ case CODEC_ID_ADPCM_IMA_QT:
+ case CODEC_ID_ADPCM_SWF:
case CODEC_ID_ADPCM_MS:
case CODEC_ID_ADPCM_YAMAHA:
return 4;
@@ -1167,7 +1298,7 @@ int ff_match_2uint16(const uint16_t (*tab)[2], int size, int a, int b){
void av_log_missing_feature(void *avc, const char *feature, int want_sample)
{
- av_log(avc, AV_LOG_WARNING, "%s not implemented. Update your Libav "
+ av_log(avc, AV_LOG_WARNING, "%s not implemented. Update your FFmpeg "
"version to the newest one from Git. If the problem still "
"occurs, it means that your file has a feature which has not "
"been implemented.\n", feature);
@@ -1184,8 +1315,8 @@ void av_log_ask_for_sample(void *avc, const char *msg, ...)
if (msg)
av_vlog(avc, AV_LOG_WARNING, msg, argument_list);
av_log(avc, AV_LOG_WARNING, "If you want to help, upload a sample "
- "of this file to ftp://upload.libav.org/incoming/ "
- "and contact the libav-devel mailing list.\n");
+ "of this file to ftp://upload.ffmpeg.org/MPlayer/incoming/ "
+ "and contact the ffmpeg-devel mailing list.\n");
va_end(argument_list);
}
@@ -1234,7 +1365,7 @@ int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op))
return 0;
}
-unsigned int ff_toupper4(unsigned int x)
+unsigned int avpriv_toupper4(unsigned int x)
{
return toupper( x &0xFF)
+ (toupper((x>>8 )&0xFF)<<8 )
@@ -1242,11 +1373,14 @@ unsigned int ff_toupper4(unsigned int x)
+ (toupper((x>>24)&0xFF)<<24);
}
-#if !HAVE_PTHREADS
+#if !HAVE_THREADS
int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f)
{
f->owner = avctx;
+
+ ff_init_buffer_info(avctx, f);
+
return avctx->get_buffer(avctx, f);
}
@@ -1276,3 +1410,17 @@ int avcodec_thread_init(AVCodecContext *s, int thread_count)
return ff_thread_init(s);
}
#endif
+
+enum AVMediaType avcodec_get_type(enum CodecID codec_id)
+{
+ if (codec_id <= CODEC_ID_NONE)
+ return AVMEDIA_TYPE_UNKNOWN;
+ else if (codec_id < CODEC_ID_FIRST_AUDIO)
+ return AVMEDIA_TYPE_VIDEO;
+ else if (codec_id < CODEC_ID_FIRST_SUBTITLE)
+ return AVMEDIA_TYPE_AUDIO;
+ else if (codec_id < CODEC_ID_FIRST_UNKNOWN)
+ return AVMEDIA_TYPE_SUBTITLE;
+
+ return AVMEDIA_TYPE_UNKNOWN;
+}
diff --git a/libavcodec/utvideo.c b/libavcodec/utvideo.c
new file mode 100644
index 0000000000..aac3969b15
--- /dev/null
+++ b/libavcodec/utvideo.c
@@ -0,0 +1,460 @@
+/*
+ * Ut Video decoder
+ * Copyright (c) 2011 Konstantin Shishkov
+ *
+ * This file is part of Libav.
+ *
+ * Libav 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.
+ *
+ * Libav 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * Ut Video decoder
+ */
+
+#include <stdlib.h>
+
+#include "libavutil/intreadwrite.h"
+#include "avcodec.h"
+#include "bytestream.h"
+#include "get_bits.h"
+#include "dsputil.h"
+
+enum {
+ PRED_NONE = 0,
+ PRED_LEFT,
+ PRED_GRADIENT,
+ PRED_MEDIAN,
+};
+
+typedef struct UtvideoContext {
+ AVCodecContext *avctx;
+ AVFrame pic;
+ DSPContext dsp;
+
+ uint32_t frame_info_size, flags, frame_info;
+ int planes;
+ int slices;
+ int compression;
+ int interlaced;
+ int frame_pred;
+
+ uint8_t *slice_bits;
+ int slice_bits_size;
+} UtvideoContext;
+
+typedef struct HuffEntry {
+ uint8_t sym;
+ uint8_t len;
+} HuffEntry;
+
+static int huff_cmp(const void *a, const void *b)
+{
+ const HuffEntry *aa = a, *bb = b;
+ return (aa->len - bb->len)*256 + aa->sym - bb->sym;
+}
+
+static int build_huff(const uint8_t *src, VLC *vlc)
+{
+ int i;
+ HuffEntry he[256];
+ int last;
+ uint32_t codes[256];
+ uint8_t bits[256];
+ uint8_t syms[256];
+ uint32_t code;
+
+ for (i = 0; i < 256; i++) {
+ he[i].sym = i;
+ he[i].len = *src++;
+ }
+ qsort(he, 256, sizeof(*he), huff_cmp);
+
+ if (!he[0].len || he[0].len > 32)
+ return -1;
+
+ last = 255;
+ while (he[last].len == 255 && last)
+ last--;
+
+ code = 1;
+ for (i = last; i >= 0; i--) {
+ codes[i] = code >> (32 - he[i].len);
+ bits[i] = he[i].len;
+ syms[i] = he[i].sym;
+ code += 0x80000000u >> (he[i].len - 1);
+ }
+
+ return init_vlc_sparse(vlc, FFMIN(he[last].len, 9), last + 1,
+ bits, sizeof(*bits), sizeof(*bits),
+ codes, sizeof(*codes), sizeof(*codes),
+ syms, sizeof(*syms), sizeof(*syms), 0);
+}
+
+static int decode_plane(UtvideoContext *c, int plane_no,
+ uint8_t *dst, int step, int stride,
+ int width, int height,
+ const uint8_t *src, int src_size, int use_pred)
+{
+ int i, j, slice, pix;
+ int sstart, send;
+ VLC vlc;
+ GetBitContext gb;
+ int prev;
+
+ if (build_huff(src, &vlc)) {
+ av_log(c->avctx, AV_LOG_ERROR, "Cannot build Huffman codes\n");
+ return AVERROR_INVALIDDATA;
+ }
+
+ src += 256;
+ src_size -= 256;
+
+ send = 0;
+ for (slice = 0; slice < c->slices; slice++) {
+ uint8_t *dest;
+ int slice_data_start, slice_data_end, slice_size;
+
+ sstart = send;
+ send = height * (slice + 1) / c->slices;
+ dest = dst + sstart * stride;
+
+ // slice offset and size validation was done earlier
+ slice_data_start = slice ? AV_RL32(src + slice * 4 - 4) : 0;
+ slice_data_end = AV_RL32(src + slice * 4);
+ slice_size = slice_data_end - slice_data_start;
+
+ if (!slice_size) {
+ for (j = sstart; j < send; j++) {
+ for (i = 0; i < width * step; i += step)
+ dest[i] = 0x80;
+ dest += stride;
+ }
+ continue;
+ }
+
+ memcpy(c->slice_bits, src + slice_data_start + c->slices * 4, slice_size);
+ memset(c->slice_bits + slice_size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
+ c->dsp.bswap_buf((uint32_t*)c->slice_bits, (uint32_t*)c->slice_bits,
+ (slice_data_end - slice_data_start + 3) >> 2);
+ init_get_bits(&gb, c->slice_bits, slice_size * 8);
+
+ prev = 0x80;
+ for (j = sstart; j < send; j++) {
+ for (i = 0; i < width * step; i += step) {
+ if (get_bits_left(&gb) <= 0) {
+ av_log(c->avctx, AV_LOG_ERROR, "Slice decoding ran out of bits\n");
+ goto fail;
+ }
+ pix = get_vlc2(&gb, vlc.table, vlc.bits, 4);
+ if (pix < 0) {
+ av_log(c->avctx, AV_LOG_ERROR, "Decoding error\n");
+ goto fail;
+ }
+ if (use_pred) {
+ prev += pix;
+ pix = prev;
+ }
+ dest[i] = pix;
+ }
+ dest += stride;
+ }
+ if (get_bits_left(&gb) > 32)
+ av_log(c->avctx, AV_LOG_WARNING, "%d bits left after decoding slice\n",
+ get_bits_left(&gb));
+ }
+
+ free_vlc(&vlc);
+
+ return 0;
+fail:
+ free_vlc(&vlc);
+ return AVERROR_INVALIDDATA;
+}
+
+static const int rgb_order[4] = { 1, 2, 0, 3 };
+
+static void restore_rgb_planes(uint8_t *src, int step, int stride, int width, int height)
+{
+ int i, j;
+ uint8_t r, g, b;
+
+ for (j = 0; j < height; j++) {
+ for (i = 0; i < width * step; i += step) {
+ r = src[i];
+ g = src[i + 1];
+ b = src[i + 2];
+ src[i] = r + g - 0x80;
+ src[i + 2] = b + g - 0x80;
+ }
+ src += stride;
+ }
+}
+
+static void restore_median(uint8_t *src, int step, int stride,
+ int width, int height, int slices)
+{
+ int i, j, slice;
+ int A, B, C;
+ uint8_t *bsrc;
+ int slice_start, slice_height;
+
+ for (slice = 0; slice < slices; slice++) {
+ slice_start = (slice * height) / slices;
+ slice_height = ((slice + 1) * height) / slices - slice_start;
+
+ bsrc = src + slice_start * stride;
+
+ // first line - left neighbour prediction
+ bsrc[0] += 0x80;
+ A = bsrc[0];
+ for (i = step; i < width * step; i += step) {
+ bsrc[i] += A;
+ A = bsrc[i];
+ }
+ bsrc += stride;
+ if (slice_height == 1)
+ continue;
+ // second line - first element has top predition, the rest uses median
+ C = bsrc[-stride];
+ bsrc[0] += C;
+ A = bsrc[0];
+ for (i = step; i < width * step; i += step) {
+ B = bsrc[i - stride];
+ bsrc[i] += mid_pred(A, B, (uint8_t)(A + B - C));
+ C = B;
+ A = bsrc[i];
+ }
+ bsrc += stride;
+ // the rest of lines use continuous median prediction
+ for (j = 2; j < slice_height; j++) {
+ for (i = 0; i < width * step; i += step) {
+ B = bsrc[i - stride];
+ bsrc[i] += mid_pred(A, B, (uint8_t)(A + B - C));
+ C = B;
+ A = bsrc[i];
+ }
+ bsrc += stride;
+ }
+ }
+}
+
+static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)
+{
+ const uint8_t *buf = avpkt->data;
+ int buf_size = avpkt->size;
+ const uint8_t *buf_end = buf + buf_size;
+ UtvideoContext *c = avctx->priv_data;
+ const uint8_t *ptr;
+ int i, j;
+ const uint8_t *plane_start[5];
+ int plane_size, max_slice_size = 0, slice_start, slice_end, slice_size;
+ int ret;
+
+ if (c->pic.data[0])
+ avctx->release_buffer(avctx, &c->pic);
+
+ c->pic.reference = 1;
+ c->pic.buffer_hints = FF_BUFFER_HINTS_VALID;
+ if ((ret = avctx->get_buffer(avctx, &c->pic)) < 0) {
+ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
+ return ret;
+ }
+
+ /* parse plane structure to retrieve frame flags and validate slice offsets */
+ ptr = buf;
+ for (i = 0; i < c->planes; i++) {
+ plane_start[i] = ptr;
+ if (buf_end - ptr < 256 + 4 * c->slices) {
+ av_log(avctx, AV_LOG_ERROR, "Insufficient data for a plane\n");
+ return AVERROR_INVALIDDATA;
+ }
+ ptr += 256;
+ slice_start = 0;
+ slice_end = 0;
+ for (j = 0; j < c->slices; j++) {
+ slice_end = bytestream_get_le32(&ptr);
+ slice_size = slice_end - slice_start;
+ if (slice_size < 0) {
+ av_log(avctx, AV_LOG_ERROR, "Incorrect slice size\n");
+ return AVERROR_INVALIDDATA;
+ }
+ slice_start = slice_end;
+ max_slice_size = FFMAX(max_slice_size, slice_size);
+ }
+ plane_size = slice_end;
+ if (buf_end - ptr < plane_size) {
+ av_log(avctx, AV_LOG_ERROR, "Plane size is bigger than available data\n");
+ return AVERROR_INVALIDDATA;
+ }
+ ptr += plane_size;
+ }
+ plane_start[c->planes] = ptr;
+ if (buf_end - ptr < c->frame_info_size) {
+ av_log(avctx, AV_LOG_ERROR, "Not enough data for frame information\n");
+ return AVERROR_INVALIDDATA;
+ }
+ c->frame_info = AV_RL32(ptr);
+ av_log(avctx, AV_LOG_DEBUG, "frame information flags %X\n", c->frame_info);
+
+ c->frame_pred = (c->frame_info >> 8) & 3;
+
+ if (c->frame_pred == PRED_GRADIENT) {
+ av_log_ask_for_sample(avctx, "Frame uses gradient prediction\n");
+ return AVERROR_PATCHWELCOME;
+ }
+
+ av_fast_malloc(&c->slice_bits, &c->slice_bits_size,
+ max_slice_size + FF_INPUT_BUFFER_PADDING_SIZE);
+
+ if (!c->slice_bits) {
+ av_log(avctx, AV_LOG_ERROR, "Cannot allocate temporary buffer\n");
+ return AVERROR(ENOMEM);
+ }
+
+ switch (c->avctx->pix_fmt) {
+ case PIX_FMT_RGB24:
+ case PIX_FMT_RGBA:
+ for (i = 0; i < c->planes; i++) {
+ ret = decode_plane(c, i, c->pic.data[0] + rgb_order[i], c->planes,
+ c->pic.linesize[0], avctx->width, avctx->height,
+ plane_start[i], plane_start[i + 1] - plane_start[i],
+ c->frame_pred == PRED_LEFT);
+ if (ret)
+ return ret;
+ if (c->frame_pred == PRED_MEDIAN)
+ restore_median(c->pic.data[0] + rgb_order[i], c->planes,
+ c->pic.linesize[0], avctx->width, avctx->height,
+ c->slices);
+ }
+ restore_rgb_planes(c->pic.data[0], c->planes, c->pic.linesize[0],
+ avctx->width, avctx->height);
+ break;
+ case PIX_FMT_YUV420P:
+ for (i = 0; i < 3; i++) {
+ ret = decode_plane(c, i, c->pic.data[i], 1,
+ c->pic.linesize[i], avctx->width >> !!i, avctx->height >> !!i,
+ plane_start[i], plane_start[i + 1] - plane_start[i],
+ c->frame_pred == PRED_LEFT);
+ if (ret)
+ return ret;
+ if (c->frame_pred == PRED_MEDIAN)
+ restore_median(c->pic.data[i], 1, c->pic.linesize[i],
+ avctx->width >> !!i, avctx->height >> !!i,
+ c->slices);
+ }
+ break;
+ case PIX_FMT_YUV422P:
+ for (i = 0; i < 3; i++) {
+ ret = decode_plane(c, i, c->pic.data[i], 1,
+ c->pic.linesize[i], avctx->width >> !!i, avctx->height,
+ plane_start[i], plane_start[i + 1] - plane_start[i],
+ c->frame_pred == PRED_LEFT);
+ if (ret)
+ return ret;
+ if (c->frame_pred == PRED_MEDIAN)
+ restore_median(c->pic.data[i], 1, c->pic.linesize[i],
+ avctx->width >> !!i, avctx->height, c->slices);
+ }
+ break;
+ }
+
+ *data_size = sizeof(AVFrame);
+ *(AVFrame*)data = c->pic;
+
+ /* always report that the buffer was completely consumed */
+ return buf_size;
+}
+
+static av_cold int decode_init(AVCodecContext *avctx)
+{
+ UtvideoContext * const c = avctx->priv_data;
+
+ c->avctx = avctx;
+
+ dsputil_init(&c->dsp, avctx);
+
+ if (avctx->extradata_size < 16) {
+ av_log(avctx, AV_LOG_ERROR, "Insufficient extradata size %d, should be at least 16\n",
+ avctx->extradata_size);
+ return AVERROR_INVALIDDATA;
+ }
+
+ av_log(avctx, AV_LOG_DEBUG, "Encoder version %d.%d.%d.%d\n",
+ avctx->extradata[3], avctx->extradata[2],
+ avctx->extradata[1], avctx->extradata[0]);
+ av_log(avctx, AV_LOG_DEBUG, "Original format %X\n", AV_RB32(avctx->extradata + 4));
+ c->frame_info_size = AV_RL32(avctx->extradata + 8);
+ c->flags = AV_RL32(avctx->extradata + 12);
+
+ if (c->frame_info_size != 4)
+ av_log_ask_for_sample(avctx, "Frame info is not 4 bytes\n");
+ av_log(avctx, AV_LOG_DEBUG, "Encoding parameters %08X\n", c->flags);
+ c->slices = (c->flags >> 24) + 1;
+ c->compression = c->flags & 1;
+ c->interlaced = c->flags & 0x800;
+
+ c->slice_bits_size = 0;
+
+ switch (avctx->codec_tag) {
+ case MKTAG('U', 'L', 'R', 'G'):
+ c->planes = 3;
+ avctx->pix_fmt = PIX_FMT_RGB24;
+ break;
+ case MKTAG('U', 'L', 'R', 'A'):
+ c->planes = 4;
+ avctx->pix_fmt = PIX_FMT_RGBA;
+ break;
+ case MKTAG('U', 'L', 'Y', '0'):
+ c->planes = 3;
+ avctx->pix_fmt = PIX_FMT_YUV420P;
+ break;
+ case MKTAG('U', 'L', 'Y', '2'):
+ c->planes = 3;
+ avctx->pix_fmt = PIX_FMT_YUV422P;
+ break;
+ default:
+ av_log(avctx, AV_LOG_ERROR, "Unknown Ut Video FOURCC provided (%08X)\n",
+ avctx->codec_tag);
+ return AVERROR_INVALIDDATA;
+ }
+
+ return 0;
+}
+
+static av_cold int decode_end(AVCodecContext *avctx)
+{
+ UtvideoContext * const c = avctx->priv_data;
+
+ if (c->pic.data[0])
+ avctx->release_buffer(avctx, &c->pic);
+
+ av_freep(&c->slice_bits);
+
+ return 0;
+}
+
+AVCodec ff_utvideo_decoder = {
+ .name = "utvideo",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_UTVIDEO,
+ .priv_data_size = sizeof(UtvideoContext),
+ .init = decode_init,
+ .close = decode_end,
+ .decode = decode_frame,
+ .capabilities = CODEC_CAP_DR1,
+ .long_name = NULL_IF_CONFIG_SMALL("Ut Video"),
+};
+
diff --git a/libavcodec/v210dec.c b/libavcodec/v210dec.c
index f4ea65cb96..68dbd3753a 100644
--- a/libavcodec/v210dec.c
+++ b/libavcodec/v210dec.c
@@ -4,49 +4,92 @@
* Copyright (C) 2009 Michael Niedermayer <michaelni@gmx.at>
* Copyright (c) 2009 Baptiste Coudurier <baptiste dot coudurier at gmail dot com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avcodec.h"
+#include "v210dec.h"
#include "libavutil/bswap.h"
+#define READ_PIXELS(a, b, c) \
+ do { \
+ val = av_le2ne32(*src++); \
+ *a++ = val & 0x3FF; \
+ *b++ = (val >> 10) & 0x3FF; \
+ *c++ = (val >> 20) & 0x3FF; \
+ } while (0)
+
+static void v210_planar_unpack_c(const uint32_t *src, uint16_t *y, uint16_t *u, uint16_t *v, int width)
+{
+ uint32_t val;
+ int i;
+
+ for( i = 0; i < width-5; i += 6 ){
+ READ_PIXELS(u, y, v);
+ READ_PIXELS(y, u, y);
+ READ_PIXELS(v, y, u);
+ READ_PIXELS(y, v, y);
+ }
+}
+
static av_cold int decode_init(AVCodecContext *avctx)
{
+ V210DecContext *s = avctx->priv_data;
+
if (avctx->width & 1) {
av_log(avctx, AV_LOG_ERROR, "v210 needs even width\n");
return -1;
}
- avctx->pix_fmt = PIX_FMT_YUV422P16;
+ avctx->pix_fmt = PIX_FMT_YUV422P10;
avctx->bits_per_raw_sample = 10;
avctx->coded_frame = avcodec_alloc_frame();
+ s->unpack_frame = v210_planar_unpack_c;
+
+ if (HAVE_MMX)
+ v210_x86_init(s);
+
return 0;
}
static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
AVPacket *avpkt)
{
- int h, w;
+ V210DecContext *s = avctx->priv_data;
+
+ int h, w, stride, aligned_input;
AVFrame *pic = avctx->coded_frame;
const uint8_t *psrc = avpkt->data;
uint16_t *y, *u, *v;
- int aligned_width = ((avctx->width + 47) / 48) * 48;
- int stride = aligned_width * 8 / 3;
+
+ if (s->custom_stride )
+ stride = s->custom_stride;
+ else {
+ int aligned_width = ((avctx->width + 47) / 48) * 48;
+ stride = aligned_width * 8 / 3;
+ }
+
+ aligned_input = !((uintptr_t)psrc & 0xf) && !(stride & 0xf);
+ if (aligned_input != s->aligned_input) {
+ s->aligned_input = aligned_input;
+ if (HAVE_MMX)
+ v210_x86_init(s);
+ }
if (pic->data[0])
avctx->release_buffer(avctx, pic);
@@ -66,36 +109,31 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
pic->pict_type = AV_PICTURE_TYPE_I;
pic->key_frame = 1;
-#define READ_PIXELS(a, b, c) \
- do { \
- val = av_le2ne32(*src++); \
- *a++ = val << 6; \
- *b++ = (val >> 4) & 0xFFC0; \
- *c++ = (val >> 14) & 0xFFC0; \
- } while (0)
-
for (h = 0; h < avctx->height; h++) {
const uint32_t *src = (const uint32_t*)psrc;
uint32_t val;
- for (w = 0; w < avctx->width - 5; w += 6) {
- READ_PIXELS(u, y, v);
- READ_PIXELS(y, u, y);
- READ_PIXELS(v, y, u);
- READ_PIXELS(y, v, y);
- }
+
+ w = (avctx->width / 6) * 6;
+ s->unpack_frame(src, y, u, v, w);
+
+ y += w;
+ u += w >> 1;
+ v += w >> 1;
+ src += (w << 1) / 3;
+
if (w < avctx->width - 1) {
READ_PIXELS(u, y, v);
val = av_le2ne32(*src++);
- *y++ = val << 6;
+ *y++ = val & 0x3FF;
}
if (w < avctx->width - 3) {
- *u++ = (val >> 4) & 0xFFC0;
- *y++ = (val >> 14) & 0xFFC0;
+ *u++ = (val >> 10) & 0x3FF;
+ *y++ = (val >> 20) & 0x3FF;
val = av_le2ne32(*src++);
- *v++ = val << 6;
- *y++ = (val >> 4) & 0xFFC0;
+ *v++ = val & 0x3FF;
+ *y++ = (val >> 10) & 0x3FF;
}
psrc += stride;
@@ -120,15 +158,29 @@ static av_cold int decode_close(AVCodecContext *avctx)
return 0;
}
+#define V210DEC_FLAGS AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM
+static const AVOption v210dec_options[] = {
+ {"custom_stride", "Custom V210 stride", offsetof(V210DecContext, custom_stride), FF_OPT_TYPE_INT,
+ {.dbl = 0}, INT_MIN, INT_MAX, V210DEC_FLAGS},
+ {NULL}
+};
+
+static const AVClass v210dec_class = {
+ "V210 Decoder",
+ av_default_item_name,
+ v210dec_options,
+ LIBAVUTIL_VERSION_INT,
+};
+
AVCodec ff_v210_decoder = {
- "v210",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_V210,
- 0,
- decode_init,
- NULL,
- decode_close,
- decode_frame,
- CODEC_CAP_DR1,
+ .name = "v210",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_V210,
+ .priv_data_size = sizeof(V210DecContext),
+ .init = decode_init,
+ .close = decode_close,
+ .decode = decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Uncompressed 4:2:2 10-bit"),
+ .priv_class = &v210dec_class,
};
diff --git a/ffserver.h b/libavcodec/v210dec.h
index 43bc79c2c6..48be729a5f 100644
--- a/ffserver.h
+++ b/libavcodec/v210dec.h
@@ -1,7 +1,4 @@
/*
- * Multiple format streaming server
- * copyright (c) 2002 Fabrice Bellard
- *
* This file is part of Libav.
*
* Libav is free software; you can redistribute it and/or
@@ -19,11 +16,19 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef LIBAV_FFSERVER_H
-#define LIBAV_FFSERVER_H
+#ifndef AVCODEC_V210DEC_H
+#define AVCODEC_V210DEC_H
+
+#include "libavutil/log.h"
+#include "libavutil/opt.h"
-/* interface between ffserver and modules */
+typedef struct {
+ AVClass *av_class;
+ int custom_stride;
+ int aligned_input;
+ void (*unpack_frame)(const uint32_t *src, uint16_t *y, uint16_t *u, uint16_t *v, int width);
+} V210DecContext;
-void ffserver_module_init(void);
+void v210_x86_init(V210DecContext *s);
-#endif /* LIBAV_FFSERVER_H */
+#endif /* AVCODEC_V210DEC_H */
diff --git a/libavcodec/v210enc.c b/libavcodec/v210enc.c
index 8b022fa8f8..92577ef80f 100644
--- a/libavcodec/v210enc.c
+++ b/libavcodec/v210enc.c
@@ -4,20 +4,20 @@
* Copyright (C) 2009 Michael Niedermayer <michaelni@gmx.at>
* Copyright (c) 2009 Baptiste Coudurier <baptiste dot coudurier at gmail dot com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -31,8 +31,8 @@ static av_cold int encode_init(AVCodecContext *avctx)
return -1;
}
- if (avctx->pix_fmt != PIX_FMT_YUV422P16) {
- av_log(avctx, AV_LOG_ERROR, "v210 needs YUV422P16\n");
+ if (avctx->pix_fmt != PIX_FMT_YUV422P10) {
+ av_log(avctx, AV_LOG_ERROR, "v210 needs YUV422P10\n");
return -1;
}
@@ -66,11 +66,13 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf,
return -1;
}
+#define CLIP(v) av_clip(v, 4, 1019)
+
#define WRITE_PIXELS(a, b, c) \
do { \
- val = (*a++ >> 6) | \
- ((*b++ & 0xFFC0) << 4); \
- val|= (*c++ & 0xFFC0) << 14; \
+ val = CLIP(*a++); \
+ val |= (CLIP(*b++) << 10) | \
+ (CLIP(*c++) << 20); \
bytestream_put_le32(&p, val); \
} while (0)
@@ -85,17 +87,15 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf,
if (w < avctx->width - 1) {
WRITE_PIXELS(u, y, v);
- val = *y++ >> 6;
+ val = CLIP(*y++);
if (w == avctx->width - 2)
bytestream_put_le32(&p, val);
}
if (w < avctx->width - 3) {
- val |=((*u++ & 0xFFC0) << 4) |
- ((*y++ & 0xFFC0) << 14);
+ val |= (CLIP(*u++) << 10) | (CLIP(*y++) << 20);
bytestream_put_le32(&p, val);
- val = (*v++ >> 6) |
- (*y++ & 0xFFC0) << 4;
+ val = CLIP(*v++) | (CLIP(*y++) << 10);
bytestream_put_le32(&p, val);
}
@@ -118,13 +118,12 @@ static av_cold int encode_close(AVCodecContext *avctx)
}
AVCodec ff_v210_encoder = {
- "v210",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_V210,
- 0,
- encode_init,
- encode_frame,
- encode_close,
- .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUV422P16, PIX_FMT_NONE},
+ .name = "v210",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_V210,
+ .init = encode_init,
+ .encode = encode_frame,
+ .close = encode_close,
+ .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUV422P10, PIX_FMT_NONE},
.long_name = NULL_IF_CONFIG_SMALL("Uncompressed 4:2:2 10-bit"),
};
diff --git a/libavcodec/v210x.c b/libavcodec/v210x.c
index e3b1a3c684..ec74a3384f 100644
--- a/libavcodec/v210x.c
+++ b/libavcodec/v210x.c
@@ -1,20 +1,20 @@
/*
* Copyright (C) 2009 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -133,14 +133,12 @@ static av_cold int decode_close(AVCodecContext *avctx)
}
AVCodec ff_v210x_decoder = {
- "v210x",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_V210X,
- 0,
- decode_init,
- NULL,
- decode_close,
- decode_frame,
- CODEC_CAP_DR1,
+ .name = "v210x",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_V210X,
+ .init = decode_init,
+ .close = decode_close,
+ .decode = decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Uncompressed 4:2:2 10-bit"),
};
diff --git a/libavcodec/vaapi.c b/libavcodec/vaapi.c
index d6b0298ee0..774fde840f 100644
--- a/libavcodec/vaapi.c
+++ b/libavcodec/vaapi.c
@@ -4,20 +4,20 @@
*
* Copyright (C) 2008-2009 Splitted-Desktop Systems
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/vaapi.h b/libavcodec/vaapi.h
index 36fb386acf..4c3bb9bb52 100644
--- a/libavcodec/vaapi.h
+++ b/libavcodec/vaapi.h
@@ -1,23 +1,23 @@
/*
- * Video Acceleration API (shared data between Libav and the video player)
+ * Video Acceleration API (shared data between FFmpeg and the video player)
* HW decode acceleration for MPEG-2, MPEG-4, H.264 and VC-1
*
* Copyright (C) 2008-2009 Splitted-Desktop Systems
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -33,7 +33,7 @@
*/
/**
- * This structure is used to share data between the Libav library and
+ * This structure is used to share data between the FFmpeg library and
* the client video application.
* This shall be zero-allocated and available as
* AVCodecContext.hwaccel_context. All user members can be set once
diff --git a/libavcodec/vaapi_h264.c b/libavcodec/vaapi_h264.c
index 83bf2907de..01c42f5af1 100644
--- a/libavcodec/vaapi_h264.c
+++ b/libavcodec/vaapi_h264.c
@@ -3,29 +3,30 @@
*
* Copyright (C) 2008-2009 Splitted-Desktop Systems
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "vaapi_internal.h"
#include "h264.h"
-/** @file
- * This file implements the glue code between Libav's and VA API's
- * structures for H.264 decoding.
+/**
+ * @file
+ * This file implements the glue code between FFmpeg's and VA API's
+ * structures for H.264 decoding.
*/
/**
@@ -42,10 +43,10 @@ static void init_vaapi_pic(VAPictureH264 *va_pic)
}
/**
- * Translate an Libav Picture into its VA API form.
+ * Translate an FFmpeg Picture into its VA API form.
*
* @param[out] va_pic A pointer to VA API's own picture struct
- * @param[in] pic A pointer to the Libav picture struct to convert
+ * @param[in] pic A pointer to the FFmpeg picture struct to convert
* @param[in] pic_structure The picture field type (as defined in mpegvideo.h),
* supersedes pic's field type if nonzero.
*/
@@ -54,7 +55,7 @@ static void fill_vaapi_pic(VAPictureH264 *va_pic,
int pic_structure)
{
if (pic_structure == 0)
- pic_structure = pic->reference;
+ pic_structure = pic->f.reference;
pic_structure &= PICT_FRAME; /* PICT_TOP_FIELD|PICT_BOTTOM_FIELD */
va_pic->picture_id = ff_vaapi_get_surface_id(pic);
@@ -63,7 +64,7 @@ static void fill_vaapi_pic(VAPictureH264 *va_pic,
va_pic->flags = 0;
if (pic_structure != PICT_FRAME)
va_pic->flags |= (pic_structure & PICT_TOP_FIELD) ? VA_PICTURE_H264_TOP_FIELD : VA_PICTURE_H264_BOTTOM_FIELD;
- if (pic->reference)
+ if (pic->f.reference)
va_pic->flags |= pic->long_ref ? VA_PICTURE_H264_LONG_TERM_REFERENCE : VA_PICTURE_H264_SHORT_TERM_REFERENCE;
va_pic->TopFieldOrderCnt = 0;
@@ -133,24 +134,24 @@ static int fill_vaapi_ReferenceFrames(VAPictureParameterBufferH264 *pic_param,
for (i = 0; i < h->short_ref_count; i++) {
Picture * const pic = h->short_ref[i];
- if (pic && pic->reference && dpb_add(&dpb, pic) < 0)
+ if (pic && pic->f.reference && dpb_add(&dpb, pic) < 0)
return -1;
}
for (i = 0; i < 16; i++) {
Picture * const pic = h->long_ref[i];
- if (pic && pic->reference && dpb_add(&dpb, pic) < 0)
+ if (pic && pic->f.reference && dpb_add(&dpb, pic) < 0)
return -1;
}
return 0;
}
/**
- * Fill in VA API reference picture lists from the Libav reference
+ * Fill in VA API reference picture lists from the FFmpeg reference
* picture list.
*
* @param[out] RefPicList VA API internal reference picture list
- * @param[in] ref_list A pointer to the Libav reference list
+ * @param[in] ref_list A pointer to the FFmpeg reference list
* @param[in] ref_count The number of reference pictures in ref_list
*/
static void fill_vaapi_RefPicList(VAPictureH264 RefPicList[32],
@@ -159,7 +160,7 @@ static void fill_vaapi_RefPicList(VAPictureH264 RefPicList[32],
{
unsigned int i, n = 0;
for (i = 0; i < ref_count; i++)
- if (ref_list[i].reference)
+ if (ref_list[i].f.reference)
fill_vaapi_pic(&RefPicList[n++], &ref_list[i], 0);
for (; n < 32; n++)
@@ -258,7 +259,7 @@ static int start_frame(AVCodecContext *avctx,
pic_param->seq_fields.bits.delta_pic_order_always_zero_flag = h->sps.delta_pic_order_always_zero_flag;
pic_param->num_slice_groups_minus1 = h->pps.slice_group_count - 1;
pic_param->slice_group_map_type = h->pps.mb_slice_group_map_type;
- pic_param->slice_group_change_rate_minus1 = 0; /* XXX: unimplemented in Libav */
+ pic_param->slice_group_change_rate_minus1 = 0; /* XXX: unimplemented in FFmpeg */
pic_param->pic_init_qp_minus26 = h->pps.init_qp - 26;
pic_param->pic_init_qs_minus26 = h->pps.init_qs - 26;
pic_param->chroma_qp_index_offset = h->pps.chroma_qp_index_offset[0];
@@ -281,7 +282,8 @@ static int start_frame(AVCodecContext *avctx,
if (!iq_matrix)
return -1;
memcpy(iq_matrix->ScalingList4x4, h->pps.scaling_matrix4, sizeof(iq_matrix->ScalingList4x4));
- memcpy(iq_matrix->ScalingList8x8, h->pps.scaling_matrix8, sizeof(iq_matrix->ScalingList8x8));
+ memcpy(iq_matrix->ScalingList8x8[0], h->pps.scaling_matrix8[0], sizeof(iq_matrix->ScalingList8x8[0]));
+ memcpy(iq_matrix->ScalingList8x8[1], h->pps.scaling_matrix8[3], sizeof(iq_matrix->ScalingList8x8[0]));
return 0;
}
diff --git a/libavcodec/vaapi_internal.h b/libavcodec/vaapi_internal.h
index 38432e1bc0..e514dd6f44 100644
--- a/libavcodec/vaapi_internal.h
+++ b/libavcodec/vaapi_internal.h
@@ -4,20 +4,20 @@
*
* Copyright (C) 2008-2009 Splitted-Desktop Systems
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -38,7 +38,7 @@
/** Extract VASurfaceID from a Picture */
static inline VASurfaceID ff_vaapi_get_surface_id(Picture *pic)
{
- return (uintptr_t)pic->data[3];
+ return (uintptr_t)pic->f.data[3];
}
/** Common AVHWAccel.end_frame() implementation */
diff --git a/libavcodec/vaapi_mpeg2.c b/libavcodec/vaapi_mpeg2.c
index 561f4bf800..dbe1d1296c 100644
--- a/libavcodec/vaapi_mpeg2.c
+++ b/libavcodec/vaapi_mpeg2.c
@@ -3,20 +3,20 @@
*
* Copyright (C) 2008-2009 Splitted-Desktop Systems
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -109,14 +109,14 @@ static int vaapi_mpeg2_decode_slice(AVCodecContext *avctx, const uint8_t *buffer
MpegEncContext * const s = avctx->priv_data;
VASliceParameterBufferMPEG2 *slice_param;
GetBitContext gb;
- uint32_t start_code, quantiser_scale_code, intra_slice_flag, macroblock_offset;
+ uint32_t quantiser_scale_code, intra_slice_flag, macroblock_offset;
av_dlog(avctx, "vaapi_mpeg2_decode_slice(): buffer %p, size %d\n", buffer, size);
/* Determine macroblock_offset */
init_get_bits(&gb, buffer, 8 * size);
- start_code = get_bits(&gb, 32);
- assert((start_code & 0xffffff00) == 0x00000100);
+ if (get_bits_long(&gb, 32) >> 8 != 1) /* start code */
+ return AVERROR_INVALIDDATA;
quantiser_scale_code = get_bits(&gb, 5);
intra_slice_flag = get_bits1(&gb);
if (intra_slice_flag) {
diff --git a/libavcodec/vaapi_mpeg4.c b/libavcodec/vaapi_mpeg4.c
index fcd429086e..f6e26d4130 100644
--- a/libavcodec/vaapi_mpeg4.c
+++ b/libavcodec/vaapi_mpeg4.c
@@ -3,20 +3,20 @@
*
* Copyright (C) 2008-2009 Splitted-Desktop Systems
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -79,7 +79,7 @@ static int vaapi_mpeg4_start_frame(AVCodecContext *avctx, av_unused const uint8_
pic_param->quant_precision = s->quant_precision;
pic_param->vop_fields.value = 0; /* reset all bits */
pic_param->vop_fields.bits.vop_coding_type = s->pict_type - AV_PICTURE_TYPE_I;
- pic_param->vop_fields.bits.backward_reference_vop_coding_type = s->pict_type == AV_PICTURE_TYPE_B ? s->next_picture.pict_type - AV_PICTURE_TYPE_I : 0;
+ pic_param->vop_fields.bits.backward_reference_vop_coding_type = s->pict_type == AV_PICTURE_TYPE_B ? s->next_picture.f.pict_type - AV_PICTURE_TYPE_I : 0;
pic_param->vop_fields.bits.vop_rounding_type = s->no_rounding;
pic_param->vop_fields.bits.intra_dc_vlc_thr = mpeg4_get_intra_dc_vlc_thr(s);
pic_param->vop_fields.bits.top_field_first = s->top_field_first;
@@ -129,7 +129,7 @@ static int vaapi_mpeg4_decode_slice(AVCodecContext *avctx, const uint8_t *buffer
/* video_plane_with_short_video_header() contains all GOBs
* in-order, and this is what VA API (Intel backend) expects: only
- * a single slice param. So fake macroblock_number for Libav so
+ * a single slice param. So fake macroblock_number for FFmpeg so
* that we don't call vaapi_mpeg4_decode_slice() again
*/
if (avctx->codec->id == CODEC_ID_H263)
diff --git a/libavcodec/vaapi_vc1.c b/libavcodec/vaapi_vc1.c
index 19865dc0e8..09bef4a5f9 100644
--- a/libavcodec/vaapi_vc1.c
+++ b/libavcodec/vaapi_vc1.c
@@ -3,20 +3,20 @@
*
* Copyright (C) 2008-2009 Splitted-Desktop Systems
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -24,7 +24,7 @@
#include "vc1.h"
#include "vc1data.h"
-/** Translate Libav MV modes to VA API */
+/** Translate FFmpeg MV modes to VA API */
static int get_VAMvModeVC1(enum MVModes mv_mode)
{
switch (mv_mode) {
@@ -116,7 +116,19 @@ static inline VAMvModeVC1 vc1_get_MVMODE2(VC1Context *v)
return 0;
}
-/** Pack Libav bitplanes into a VABitPlaneBuffer element */
+/** Reconstruct bitstream TTFRM (7.1.1.41, Table-53) */
+static inline int vc1_get_TTFRM(VC1Context *v)
+{
+ switch (v->ttfrm) {
+ case TT_8X8: return 0;
+ case TT_8X4: return 1;
+ case TT_4X8: return 2;
+ case TT_4X4: return 3;
+ }
+ return 0;
+}
+
+/** Pack FFmpeg bitplanes into a VABitPlaneBuffer element */
static inline void vc1_pack_bitplanes(uint8_t *bitplane, int n, const uint8_t *ff_bp[3], int x, int y, int stride)
{
const int bitplane_index = n / 2;
@@ -239,7 +251,7 @@ static int vaapi_vc1_start_frame(AVCodecContext *avctx, av_unused const uint8_t
pic_param->transform_fields.value = 0; /* reset all bits */
pic_param->transform_fields.bits.variable_sized_transform_flag = v->vstransform;
pic_param->transform_fields.bits.mb_level_transform_type_flag = v->ttmbf;
- pic_param->transform_fields.bits.frame_level_transform_type = v->ttfrm;
+ pic_param->transform_fields.bits.frame_level_transform_type = vc1_get_TTFRM(v);
pic_param->transform_fields.bits.transform_ac_codingset_idx1 = v->c_ac_table_index;
pic_param->transform_fields.bits.transform_ac_codingset_idx2 = v->y_ac_table_index;
pic_param->transform_fields.bits.intra_transform_dc_table = v->s.dc_table_index;
diff --git a/libavcodec/vb.c b/libavcodec/vb.c
index fb37283764..622ea89790 100644
--- a/libavcodec/vb.c
+++ b/libavcodec/vb.c
@@ -2,20 +2,20 @@
* Beam Software VB decoder
* Copyright (c) 2007 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -268,6 +268,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
c->avctx = avctx;
avctx->pix_fmt = PIX_FMT_PAL8;
+ avcodec_get_frame_defaults(&c->pic);
c->frame = av_mallocz(avctx->width * avctx->height);
c->prev_frame = av_mallocz(avctx->width * avctx->height);
@@ -288,14 +289,13 @@ static av_cold int decode_end(AVCodecContext *avctx)
}
AVCodec ff_vb_decoder = {
- "vb",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_VB,
- sizeof(VBDecContext),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
+ .name = "vb",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_VB,
+ .priv_data_size = sizeof(VBDecContext),
+ .init = decode_init,
+ .close = decode_end,
+ .decode = decode_frame,
.long_name = NULL_IF_CONFIG_SMALL("Beam Software VB"),
};
diff --git a/libavcodec/vc1.c b/libavcodec/vc1.c
index 32869b97d1..7c4eb2e157 100644
--- a/libavcodec/vc1.c
+++ b/libavcodec/vc1.c
@@ -1,22 +1,23 @@
/*
* VC-1 and WMV3 decoder common code
+ * Copyright (c) 2011 Mashiat Sarker Shakkhar
* Copyright (c) 2006-2007 Konstantin Shishkov
* Partly based on vc9.c (c) 2005 Anonymous, Alex Beregszaszi, Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -25,6 +26,7 @@
* VC-1 and WMV3 decoder common code
*
*/
+
#include "internal.h"
#include "dsputil.h"
#include "avcodec.h"
@@ -66,14 +68,16 @@ enum Imode {
* @param[in] height Height of this buffer
* @param[in] stride of this buffer
*/
-static void decode_rowskip(uint8_t* plane, int width, int height, int stride, GetBitContext *gb){
+static void decode_rowskip(uint8_t* plane, int width, int height, int stride,
+ GetBitContext *gb)
+{
int x, y;
- for (y=0; y<height; y++){
+ for (y = 0; y < height; y++) {
if (!get_bits1(gb)) //rowskip
memset(plane, 0, width);
else
- for (x=0; x<width; x++)
+ for (x = 0; x < width; x++)
plane[x] = get_bits1(gb);
plane += stride;
}
@@ -86,15 +90,17 @@ static void decode_rowskip(uint8_t* plane, int width, int height, int stride, Ge
* @param[in] stride of this buffer
* @todo FIXME: Optimize
*/
-static void decode_colskip(uint8_t* plane, int width, int height, int stride, GetBitContext *gb){
+static void decode_colskip(uint8_t* plane, int width, int height, int stride,
+ GetBitContext *gb)
+{
int x, y;
- for (x=0; x<width; x++){
+ for (x = 0; x < width; x++) {
if (!get_bits1(gb)) //colskip
- for (y=0; y<height; y++)
+ for (y = 0; y < height; y++)
plane[y*stride] = 0;
else
- for (y=0; y<height; y++)
+ for (y = 0; y < height; y++)
plane[y*stride] = get_bits1(gb);
plane ++;
}
@@ -115,76 +121,76 @@ static int bitplane_decoding(uint8_t* data, int *raw_flag, VC1Context *v)
uint8_t invert, *planep = data;
int width, height, stride;
- width = v->s.mb_width;
- height = v->s.mb_height;
+ width = v->s.mb_width;
+ height = v->s.mb_height >> v->field_mode;
stride = v->s.mb_stride;
invert = get_bits1(gb);
imode = get_vlc2(gb, ff_vc1_imode_vlc.table, VC1_IMODE_VLC_BITS, 1);
*raw_flag = 0;
- switch (imode)
- {
+ switch (imode) {
case IMODE_RAW:
//Data is actually read in the MB layer (same for all tests == "raw")
*raw_flag = 1; //invert ignored
return invert;
case IMODE_DIFF2:
case IMODE_NORM2:
- if ((height * width) & 1)
- {
+ if ((height * width) & 1) {
*planep++ = get_bits1(gb);
- offset = 1;
+ offset = 1;
}
- else offset = 0;
+ else
+ offset = 0;
// decode bitplane as one long line
for (y = offset; y < height * width; y += 2) {
code = get_vlc2(gb, ff_vc1_norm2_vlc.table, VC1_NORM2_VLC_BITS, 1);
*planep++ = code & 1;
offset++;
- if(offset == width) {
- offset = 0;
+ if (offset == width) {
+ offset = 0;
planep += stride - width;
}
*planep++ = code >> 1;
offset++;
- if(offset == width) {
- offset = 0;
+ if (offset == width) {
+ offset = 0;
planep += stride - width;
}
}
break;
case IMODE_DIFF6:
case IMODE_NORM6:
- if(!(height % 3) && (width % 3)) { // use 2x3 decoding
- for(y = 0; y < height; y+= 3) {
- for(x = width & 1; x < width; x += 2) {
+ if (!(height % 3) && (width % 3)) { // use 2x3 decoding
+ for (y = 0; y < height; y += 3) {
+ for (x = width & 1; x < width; x += 2) {
code = get_vlc2(gb, ff_vc1_norm6_vlc.table, VC1_NORM6_VLC_BITS, 2);
- if(code < 0){
+ if (code < 0) {
av_log(v->s.avctx, AV_LOG_DEBUG, "invalid NORM-6 VLC\n");
return -1;
}
- planep[x + 0] = (code >> 0) & 1;
- planep[x + 1] = (code >> 1) & 1;
- planep[x + 0 + stride] = (code >> 2) & 1;
- planep[x + 1 + stride] = (code >> 3) & 1;
+ planep[x + 0] = (code >> 0) & 1;
+ planep[x + 1] = (code >> 1) & 1;
+ planep[x + 0 + stride] = (code >> 2) & 1;
+ planep[x + 1 + stride] = (code >> 3) & 1;
planep[x + 0 + stride * 2] = (code >> 4) & 1;
planep[x + 1 + stride * 2] = (code >> 5) & 1;
}
planep += stride * 3;
}
- if(width & 1) decode_colskip(data, 1, height, stride, &v->s.gb);
+ if (width & 1)
+ decode_colskip(data, 1, height, stride, &v->s.gb);
} else { // 3x2
planep += (height & 1) * stride;
- for(y = height & 1; y < height; y += 2) {
- for(x = width % 3; x < width; x += 3) {
+ for (y = height & 1; y < height; y += 2) {
+ for (x = width % 3; x < width; x += 3) {
code = get_vlc2(gb, ff_vc1_norm6_vlc.table, VC1_NORM6_VLC_BITS, 2);
- if(code < 0){
+ if (code < 0) {
av_log(v->s.avctx, AV_LOG_DEBUG, "invalid NORM-6 VLC\n");
return -1;
}
- planep[x + 0] = (code >> 0) & 1;
- planep[x + 1] = (code >> 1) & 1;
- planep[x + 2] = (code >> 2) & 1;
+ planep[x + 0] = (code >> 0) & 1;
+ planep[x + 1] = (code >> 1) & 1;
+ planep[x + 2] = (code >> 2) & 1;
planep[x + 0 + stride] = (code >> 3) & 1;
planep[x + 1 + stride] = (code >> 4) & 1;
planep[x + 2 + stride] = (code >> 5) & 1;
@@ -192,8 +198,10 @@ static int bitplane_decoding(uint8_t* data, int *raw_flag, VC1Context *v)
planep += stride * 2;
}
x = width % 3;
- if(x) decode_colskip(data , x, height , stride, &v->s.gb);
- if(height & 1) decode_rowskip(data+x, width - x, 1, stride, &v->s.gb);
+ if (x)
+ decode_colskip(data, x, height, stride, &v->s.gb);
+ if (height & 1)
+ decode_rowskip(data + x, width - x, 1, stride, &v->s.gb);
}
break;
case IMODE_ROWSKIP:
@@ -202,33 +210,30 @@ static int bitplane_decoding(uint8_t* data, int *raw_flag, VC1Context *v)
case IMODE_COLSKIP:
decode_colskip(data, width, height, stride, &v->s.gb);
break;
- default: break;
+ default:
+ break;
}
/* Applying diff operator */
- if (imode == IMODE_DIFF2 || imode == IMODE_DIFF6)
- {
+ if (imode == IMODE_DIFF2 || imode == IMODE_DIFF6) {
planep = data;
planep[0] ^= invert;
- for (x=1; x<width; x++)
+ for (x = 1; x < width; x++)
planep[x] ^= planep[x-1];
- for (y=1; y<height; y++)
- {
+ for (y = 1; y < height; y++) {
planep += stride;
planep[0] ^= planep[-stride];
- for (x=1; x<width; x++)
- {
+ for (x = 1; x < width; x++) {
if (planep[x-1] != planep[x-stride]) planep[x] ^= invert;
else planep[x] ^= planep[x-1];
}
}
- }
- else if (invert)
- {
+ } else if (invert) {
planep = data;
- for (x=0; x<stride*height; x++) planep[x] = !planep[x]; //FIXME stride
+ for (x = 0; x < stride * height; x++)
+ planep[x] = !planep[x]; //FIXME stride
}
- return (imode<<1) + invert;
+ return (imode << 1) + invert;
}
/** @} */ //Bitplane group
@@ -243,35 +248,34 @@ static int vop_dquant_decoding(VC1Context *v)
int pqdiff;
//variable size
- if (v->dquant == 2)
- {
+ if (v->dquant == 2) {
pqdiff = get_bits(gb, 3);
- if (pqdiff == 7) v->altpq = get_bits(gb, 5);
- else v->altpq = v->pq + pqdiff + 1;
- }
- else
- {
+ if (pqdiff == 7)
+ v->altpq = get_bits(gb, 5);
+ else
+ v->altpq = v->pq + pqdiff + 1;
+ } else {
v->dquantfrm = get_bits1(gb);
- if ( v->dquantfrm )
- {
+ if (v->dquantfrm) {
v->dqprofile = get_bits(gb, 2);
- switch (v->dqprofile)
- {
+ switch (v->dqprofile) {
case DQPROFILE_SINGLE_EDGE:
case DQPROFILE_DOUBLE_EDGES:
v->dqsbedge = get_bits(gb, 2);
break;
case DQPROFILE_ALL_MBS:
v->dqbilevel = get_bits1(gb);
- if(!v->dqbilevel)
+ if (!v->dqbilevel)
v->halfpq = 0;
- default: break; //Forbidden ?
+ default:
+ break; //Forbidden ?
}
- if (v->dqbilevel || v->dqprofile != DQPROFILE_ALL_MBS)
- {
+ if (v->dqbilevel || v->dqprofile != DQPROFILE_ALL_MBS) {
pqdiff = get_bits(gb, 3);
- if (pqdiff == 7) v->altpq = get_bits(gb, 5);
- else v->altpq = v->pq + pqdiff + 1;
+ if (pqdiff == 7)
+ v->altpq = get_bits(gb, 5);
+ else
+ v->altpq = v->pq + pqdiff + 1;
}
}
}
@@ -291,80 +295,69 @@ int vc1_decode_sequence_header(AVCodecContext *avctx, VC1Context *v, GetBitConte
{
av_log(avctx, AV_LOG_DEBUG, "Header: %0X\n", show_bits(gb, 32));
v->profile = get_bits(gb, 2);
- if (v->profile == PROFILE_COMPLEX)
- {
+ if (v->profile == PROFILE_COMPLEX) {
av_log(avctx, AV_LOG_WARNING, "WMV3 Complex Profile is not fully supported\n");
}
- if (v->profile == PROFILE_ADVANCED)
- {
+ if (v->profile == PROFILE_ADVANCED) {
v->zz_8x4 = ff_vc1_adv_progressive_8x4_zz;
v->zz_4x8 = ff_vc1_adv_progressive_4x8_zz;
return decode_sequence_header_adv(v, gb);
- }
- else
- {
+ } else {
v->zz_8x4 = wmv2_scantableA;
v->zz_4x8 = wmv2_scantableB;
v->res_y411 = get_bits1(gb);
v->res_sprite = get_bits1(gb);
- if (v->res_y411)
- {
+ if (v->res_y411) {
av_log(avctx, AV_LOG_ERROR,
"Old interlaced mode is not supported\n");
return -1;
}
- if (v->res_sprite) {
- av_log(avctx, AV_LOG_ERROR, "WMVP is not fully supported\n");
- }
}
// (fps-2)/4 (->30)
v->frmrtq_postproc = get_bits(gb, 3); //common
// (bitrate-32kbps)/64kbps
v->bitrtq_postproc = get_bits(gb, 5); //common
- v->s.loop_filter = get_bits1(gb); //common
- if(v->s.loop_filter == 1 && v->profile == PROFILE_SIMPLE)
- {
+ v->s.loop_filter = get_bits1(gb); //common
+ if (v->s.loop_filter == 1 && v->profile == PROFILE_SIMPLE) {
av_log(avctx, AV_LOG_ERROR,
"LOOPFILTER shall not be enabled in Simple Profile\n");
}
- if(v->s.avctx->skip_loop_filter >= AVDISCARD_ALL)
+ if (v->s.avctx->skip_loop_filter >= AVDISCARD_ALL)
v->s.loop_filter = 0;
- v->res_x8 = get_bits1(gb); //reserved
- v->multires = get_bits1(gb);
- v->res_fasttx = get_bits1(gb);
- if (!v->res_fasttx)
- {
- v->vc1dsp.vc1_inv_trans_8x8 = ff_simple_idct;
- v->vc1dsp.vc1_inv_trans_8x4 = ff_simple_idct84_add;
- v->vc1dsp.vc1_inv_trans_4x8 = ff_simple_idct48_add;
- v->vc1dsp.vc1_inv_trans_4x4 = ff_simple_idct44_add;
- v->vc1dsp.vc1_inv_trans_8x8_dc = ff_simple_idct_add;
+ v->res_x8 = get_bits1(gb); //reserved
+ v->multires = get_bits1(gb);
+ v->res_fasttx = get_bits1(gb);
+ if (!v->res_fasttx) {
+ v->vc1dsp.vc1_inv_trans_8x8 = ff_simple_idct_8;
+ v->vc1dsp.vc1_inv_trans_8x4 = ff_simple_idct84_add;
+ v->vc1dsp.vc1_inv_trans_4x8 = ff_simple_idct48_add;
+ v->vc1dsp.vc1_inv_trans_4x4 = ff_simple_idct44_add;
+ v->vc1dsp.vc1_inv_trans_8x8_dc = ff_simple_idct_add_8;
v->vc1dsp.vc1_inv_trans_8x4_dc = ff_simple_idct84_add;
v->vc1dsp.vc1_inv_trans_4x8_dc = ff_simple_idct48_add;
v->vc1dsp.vc1_inv_trans_4x4_dc = ff_simple_idct44_add;
}
- v->fastuvmc = get_bits1(gb); //common
- if (!v->profile && !v->fastuvmc)
- {
+ v->fastuvmc = get_bits1(gb); //common
+ if (!v->profile && !v->fastuvmc) {
av_log(avctx, AV_LOG_ERROR,
"FASTUVMC unavailable in Simple Profile\n");
return -1;
}
- v->extended_mv = get_bits1(gb); //common
+ v->extended_mv = get_bits1(gb); //common
if (!v->profile && v->extended_mv)
{
av_log(avctx, AV_LOG_ERROR,
"Extended MVs unavailable in Simple Profile\n");
return -1;
}
- v->dquant = get_bits(gb, 2); //common
- v->vstransform = get_bits1(gb); //common
+ v->dquant = get_bits(gb, 2); //common
+ v->vstransform = get_bits1(gb); //common
- v->res_transtab = get_bits1(gb);
+ v->res_transtab = get_bits1(gb);
if (v->res_transtab)
{
av_log(avctx, AV_LOG_ERROR,
@@ -372,12 +365,11 @@ int vc1_decode_sequence_header(AVCodecContext *avctx, VC1Context *v, GetBitConte
return -1;
}
- v->overlap = get_bits1(gb); //common
+ v->overlap = get_bits1(gb); //common
v->s.resync_marker = get_bits1(gb);
- v->rangered = get_bits1(gb);
- if (v->rangered && v->profile == PROFILE_SIMPLE)
- {
+ v->rangered = get_bits1(gb);
+ if (v->rangered && v->profile == PROFILE_SIMPLE) {
av_log(avctx, AV_LOG_INFO,
"RANGERED should be set to 0 in Simple Profile\n");
}
@@ -388,8 +380,9 @@ int vc1_decode_sequence_header(AVCodecContext *avctx, VC1Context *v, GetBitConte
v->finterpflag = get_bits1(gb); //common
if (v->res_sprite) {
- v->s.avctx->width = v->s.avctx->coded_width = get_bits(gb, 11);
- v->s.avctx->height = v->s.avctx->coded_height = get_bits(gb, 11);
+ int w = get_bits(gb, 11);
+ int h = get_bits(gb, 11);
+ avcodec_set_dimensions(v->s.avctx, w, h);
skip_bits(gb, 5); //frame rate
v->res_x8 = get_bits1(gb);
if (get_bits1(gb)) { // something to do with DC VLC selection
@@ -401,8 +394,7 @@ int vc1_decode_sequence_header(AVCodecContext *avctx, VC1Context *v, GetBitConte
} else {
v->res_rtm_flag = get_bits1(gb); //reserved
}
- if (!v->res_rtm_flag)
- {
+ if (!v->res_rtm_flag) {
// av_log(avctx, AV_LOG_ERROR,
// "0 for reserved RES_RTM_FLAG is forbidden\n");
av_log(avctx, AV_LOG_ERROR,
@@ -410,116 +402,122 @@ int vc1_decode_sequence_header(AVCodecContext *avctx, VC1Context *v, GetBitConte
//return -1;
}
//TODO: figure out what they mean (always 0x402F)
- if(!v->res_fasttx) skip_bits(gb, 16);
+ if (!v->res_fasttx)
+ skip_bits(gb, 16);
av_log(avctx, AV_LOG_DEBUG,
- "Profile %i:\nfrmrtq_postproc=%i, bitrtq_postproc=%i\n"
- "LoopFilter=%i, MultiRes=%i, FastUVMC=%i, Extended MV=%i\n"
- "Rangered=%i, VSTransform=%i, Overlap=%i, SyncMarker=%i\n"
- "DQuant=%i, Quantizer mode=%i, Max B frames=%i\n",
- v->profile, v->frmrtq_postproc, v->bitrtq_postproc,
- v->s.loop_filter, v->multires, v->fastuvmc, v->extended_mv,
- v->rangered, v->vstransform, v->overlap, v->s.resync_marker,
- v->dquant, v->quantizer_mode, avctx->max_b_frames
- );
+ "Profile %i:\nfrmrtq_postproc=%i, bitrtq_postproc=%i\n"
+ "LoopFilter=%i, MultiRes=%i, FastUVMC=%i, Extended MV=%i\n"
+ "Rangered=%i, VSTransform=%i, Overlap=%i, SyncMarker=%i\n"
+ "DQuant=%i, Quantizer mode=%i, Max B frames=%i\n",
+ v->profile, v->frmrtq_postproc, v->bitrtq_postproc,
+ v->s.loop_filter, v->multires, v->fastuvmc, v->extended_mv,
+ v->rangered, v->vstransform, v->overlap, v->s.resync_marker,
+ v->dquant, v->quantizer_mode, avctx->max_b_frames);
return 0;
}
static int decode_sequence_header_adv(VC1Context *v, GetBitContext *gb)
{
+ int w, h;
v->res_rtm_flag = 1;
v->level = get_bits(gb, 3);
- if(v->level >= 5)
- {
+ if (v->level >= 5) {
av_log(v->s.avctx, AV_LOG_ERROR, "Reserved LEVEL %i\n",v->level);
}
v->chromaformat = get_bits(gb, 2);
- if (v->chromaformat != 1)
- {
+ if (v->chromaformat != 1) {
av_log(v->s.avctx, AV_LOG_ERROR,
"Only 4:2:0 chroma format supported\n");
return -1;
}
// (fps-2)/4 (->30)
- v->frmrtq_postproc = get_bits(gb, 3); //common
+ v->frmrtq_postproc = get_bits(gb, 3); //common
// (bitrate-32kbps)/64kbps
- v->bitrtq_postproc = get_bits(gb, 5); //common
- v->postprocflag = get_bits1(gb); //common
-
- v->s.avctx->coded_width = (get_bits(gb, 12) + 1) << 1;
- v->s.avctx->coded_height = (get_bits(gb, 12) + 1) << 1;
- v->s.avctx->width = v->s.avctx->coded_width;
- v->s.avctx->height = v->s.avctx->coded_height;
- v->broadcast = get_bits1(gb);
- v->interlace = get_bits1(gb);
- v->tfcntrflag = get_bits1(gb);
- v->finterpflag = get_bits1(gb);
+ v->bitrtq_postproc = get_bits(gb, 5); //common
+ v->postprocflag = get_bits1(gb); //common
+
+ w = (get_bits(gb, 12) + 1) << 1;
+ h = (get_bits(gb, 12) + 1) << 1;
+ avcodec_set_dimensions(v->s.avctx, w, h);
+ v->broadcast = get_bits1(gb);
+ v->interlace = get_bits1(gb);
+ v->tfcntrflag = get_bits1(gb);
+ v->finterpflag = get_bits1(gb);
skip_bits1(gb); // reserved
- v->s.h_edge_pos = v->s.avctx->coded_width;
- v->s.v_edge_pos = v->s.avctx->coded_height;
-
av_log(v->s.avctx, AV_LOG_DEBUG,
- "Advanced Profile level %i:\nfrmrtq_postproc=%i, bitrtq_postproc=%i\n"
- "LoopFilter=%i, ChromaFormat=%i, Pulldown=%i, Interlace: %i\n"
- "TFCTRflag=%i, FINTERPflag=%i\n",
- v->level, v->frmrtq_postproc, v->bitrtq_postproc,
- v->s.loop_filter, v->chromaformat, v->broadcast, v->interlace,
- v->tfcntrflag, v->finterpflag
- );
+ "Advanced Profile level %i:\nfrmrtq_postproc=%i, bitrtq_postproc=%i\n"
+ "LoopFilter=%i, ChromaFormat=%i, Pulldown=%i, Interlace: %i\n"
+ "TFCTRflag=%i, FINTERPflag=%i\n",
+ v->level, v->frmrtq_postproc, v->bitrtq_postproc,
+ v->s.loop_filter, v->chromaformat, v->broadcast, v->interlace,
+ v->tfcntrflag, v->finterpflag);
v->psf = get_bits1(gb);
- if(v->psf) { //PsF, 6.1.13
+ if (v->psf) { //PsF, 6.1.13
av_log(v->s.avctx, AV_LOG_ERROR, "Progressive Segmented Frame mode: not supported (yet)\n");
return -1;
}
v->s.max_b_frames = v->s.avctx->max_b_frames = 7;
- if(get_bits1(gb)) { //Display Info - decoding is not affected by it
+ if (get_bits1(gb)) { //Display Info - decoding is not affected by it
int w, h, ar = 0;
av_log(v->s.avctx, AV_LOG_DEBUG, "Display extended info:\n");
- v->s.avctx->width = w = get_bits(gb, 14) + 1;
- v->s.avctx->height = h = get_bits(gb, 14) + 1;
+ w = get_bits(gb, 14) + 1;
+ h = get_bits(gb, 14) + 1;
av_log(v->s.avctx, AV_LOG_DEBUG, "Display dimensions: %ix%i\n", w, h);
- if(get_bits1(gb))
+ if (get_bits1(gb))
ar = get_bits(gb, 4);
- if(ar && ar < 14){
+ if (ar && ar < 14) {
v->s.avctx->sample_aspect_ratio = ff_vc1_pixel_aspect[ar];
- }else if(ar == 15){
- w = get_bits(gb, 8);
- h = get_bits(gb, 8);
+ } else if (ar == 15) {
+ w = get_bits(gb, 8) + 1;
+ h = get_bits(gb, 8) + 1;
v->s.avctx->sample_aspect_ratio = (AVRational){w, h};
+ } else {
+ av_reduce(&v->s.avctx->sample_aspect_ratio.num,
+ &v->s.avctx->sample_aspect_ratio.den,
+ v->s.avctx->height * w,
+ v->s.avctx->width * h,
+ 1 << 30);
}
- av_log(v->s.avctx, AV_LOG_DEBUG, "Aspect: %i:%i\n", v->s.avctx->sample_aspect_ratio.num, v->s.avctx->sample_aspect_ratio.den);
+ av_log(v->s.avctx, AV_LOG_DEBUG, "Aspect: %i:%i\n",
+ v->s.avctx->sample_aspect_ratio.num,
+ v->s.avctx->sample_aspect_ratio.den);
- if(get_bits1(gb)){ //framerate stuff
- if(get_bits1(gb)) {
+ if (get_bits1(gb)) { //framerate stuff
+ if (get_bits1(gb)) {
v->s.avctx->time_base.num = 32;
v->s.avctx->time_base.den = get_bits(gb, 16) + 1;
} else {
int nr, dr;
nr = get_bits(gb, 8);
dr = get_bits(gb, 4);
- if(nr && nr < 8 && dr && dr < 3){
+ if (nr && nr < 8 && dr && dr < 3) {
v->s.avctx->time_base.num = ff_vc1_fps_dr[dr - 1];
v->s.avctx->time_base.den = ff_vc1_fps_nr[nr - 1] * 1000;
}
}
+ if (v->broadcast) { // Pulldown may be present
+ v->s.avctx->time_base.den *= 2;
+ v->s.avctx->ticks_per_frame = 2;
+ }
}
- if(get_bits1(gb)){
- v->color_prim = get_bits(gb, 8);
+ if (get_bits1(gb)) {
+ v->color_prim = get_bits(gb, 8);
v->transfer_char = get_bits(gb, 8);
- v->matrix_coef = get_bits(gb, 8);
+ v->matrix_coef = get_bits(gb, 8);
}
}
v->hrd_param_flag = get_bits1(gb);
- if(v->hrd_param_flag) {
+ if (v->hrd_param_flag) {
int i;
v->hrd_num_leaky_buckets = get_bits(gb, 5);
skip_bits(gb, 4); //bitrate exponent
skip_bits(gb, 4); //buffer size exponent
- for(i = 0; i < v->hrd_num_leaky_buckets; i++) {
+ for (i = 0; i < v->hrd_num_leaky_buckets; i++) {
skip_bits(gb, 16); //hrd_rate[n]
skip_bits(gb, 16); //hrd_buffer[n]
}
@@ -532,45 +530,46 @@ int vc1_decode_entry_point(AVCodecContext *avctx, VC1Context *v, GetBitContext *
int i;
av_log(avctx, AV_LOG_DEBUG, "Entry point: %08X\n", show_bits_long(gb, 32));
- v->broken_link = get_bits1(gb);
- v->closed_entry = get_bits1(gb);
- v->panscanflag = get_bits1(gb);
- v->refdist_flag = get_bits1(gb);
- v->s.loop_filter = get_bits1(gb);
- v->fastuvmc = get_bits1(gb);
- v->extended_mv = get_bits1(gb);
- v->dquant = get_bits(gb, 2);
- v->vstransform = get_bits1(gb);
- v->overlap = get_bits1(gb);
+ v->broken_link = get_bits1(gb);
+ v->closed_entry = get_bits1(gb);
+ v->panscanflag = get_bits1(gb);
+ v->refdist_flag = get_bits1(gb);
+ v->s.loop_filter = get_bits1(gb);
+ v->fastuvmc = get_bits1(gb);
+ v->extended_mv = get_bits1(gb);
+ v->dquant = get_bits(gb, 2);
+ v->vstransform = get_bits1(gb);
+ v->overlap = get_bits1(gb);
v->quantizer_mode = get_bits(gb, 2);
- if(v->hrd_param_flag){
- for(i = 0; i < v->hrd_num_leaky_buckets; i++) {
+ if (v->hrd_param_flag) {
+ for (i = 0; i < v->hrd_num_leaky_buckets; i++) {
skip_bits(gb, 8); //hrd_full[n]
}
}
if(get_bits1(gb)){
- avctx->coded_width = (get_bits(gb, 12)+1)<<1;
- avctx->coded_height = (get_bits(gb, 12)+1)<<1;
+ int w = (get_bits(gb, 12)+1)<<1;
+ int h = (get_bits(gb, 12)+1)<<1;
+ avcodec_set_dimensions(avctx, w, h);
}
- if(v->extended_mv)
+ if (v->extended_mv)
v->extended_dmv = get_bits1(gb);
- if((v->range_mapy_flag = get_bits1(gb))) {
+ if ((v->range_mapy_flag = get_bits1(gb))) {
av_log(avctx, AV_LOG_ERROR, "Luma scaling is not supported, expect wrong picture\n");
v->range_mapy = get_bits(gb, 3);
}
- if((v->range_mapuv_flag = get_bits1(gb))) {
+ if ((v->range_mapuv_flag = get_bits1(gb))) {
av_log(avctx, AV_LOG_ERROR, "Chroma scaling is not supported, expect wrong picture\n");
v->range_mapuv = get_bits(gb, 3);
}
av_log(avctx, AV_LOG_DEBUG, "Entry point info:\n"
- "BrokenLink=%i, ClosedEntry=%i, PanscanFlag=%i\n"
- "RefDist=%i, Postproc=%i, FastUVMC=%i, ExtMV=%i\n"
- "DQuant=%i, VSTransform=%i, Overlap=%i, Qmode=%i\n",
- v->broken_link, v->closed_entry, v->panscanflag, v->refdist_flag, v->s.loop_filter,
- v->fastuvmc, v->extended_mv, v->dquant, v->vstransform, v->overlap, v->quantizer_mode);
+ "BrokenLink=%i, ClosedEntry=%i, PanscanFlag=%i\n"
+ "RefDist=%i, Postproc=%i, FastUVMC=%i, ExtMV=%i\n"
+ "DQuant=%i, VSTransform=%i, Overlap=%i, Qmode=%i\n",
+ v->broken_link, v->closed_entry, v->panscanflag, v->refdist_flag, v->s.loop_filter,
+ v->fastuvmc, v->extended_mv, v->dquant, v->vstransform, v->overlap, v->quantizer_mode);
return 0;
}
@@ -579,41 +578,48 @@ int vc1_parse_frame_header(VC1Context *v, GetBitContext* gb)
{
int pqindex, lowquant, status;
- if(v->finterpflag) v->interpfrm = get_bits1(gb);
+ if (v->finterpflag)
+ v->interpfrm = get_bits1(gb);
skip_bits(gb, 2); //framecnt unused
v->rangeredfrm = 0;
- if (v->rangered) v->rangeredfrm = get_bits1(gb);
+ if (v->rangered)
+ v->rangeredfrm = get_bits1(gb);
v->s.pict_type = get_bits1(gb);
if (v->s.avctx->max_b_frames) {
if (!v->s.pict_type) {
- if (get_bits1(gb)) v->s.pict_type = AV_PICTURE_TYPE_I;
- else v->s.pict_type = AV_PICTURE_TYPE_B;
- } else v->s.pict_type = AV_PICTURE_TYPE_P;
- } else v->s.pict_type = v->s.pict_type ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I;
+ if (get_bits1(gb))
+ v->s.pict_type = AV_PICTURE_TYPE_I;
+ else
+ v->s.pict_type = AV_PICTURE_TYPE_B;
+ } else
+ v->s.pict_type = AV_PICTURE_TYPE_P;
+ } else
+ v->s.pict_type = v->s.pict_type ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I;
v->bi_type = 0;
- if(v->s.pict_type == AV_PICTURE_TYPE_B) {
+ if (v->s.pict_type == AV_PICTURE_TYPE_B) {
v->bfraction_lut_index = get_vlc2(gb, ff_vc1_bfraction_vlc.table, VC1_BFRACTION_VLC_BITS, 1);
- v->bfraction = ff_vc1_bfraction_lut[v->bfraction_lut_index];
- if(v->bfraction == 0) {
+ v->bfraction = ff_vc1_bfraction_lut[v->bfraction_lut_index];
+ if (v->bfraction == 0) {
v->s.pict_type = AV_PICTURE_TYPE_BI;
}
}
- if(v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI)
+ if (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI)
skip_bits(gb, 7); // skip buffer fullness
- if(v->parse_only)
+ if (v->parse_only)
return 0;
/* calculate RND */
- if(v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI)
+ if (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI)
v->rnd = 1;
- if(v->s.pict_type == AV_PICTURE_TYPE_P)
+ if (v->s.pict_type == AV_PICTURE_TYPE_P)
v->rnd ^= 1;
/* Quantizer stuff */
pqindex = get_bits(gb, 5);
- if(!pqindex) return -1;
+ if (!pqindex)
+ return -1;
if (v->quantizer_mode == QUANT_FRAME_IMPLICIT)
v->pq = ff_vc1_pquant_table[0][pqindex];
else
@@ -625,63 +631,69 @@ int vc1_parse_frame_header(VC1Context *v, GetBitContext* gb)
if (v->quantizer_mode == QUANT_NON_UNIFORM)
v->pquantizer = 0;
v->pqindex = pqindex;
- if (pqindex < 9) v->halfpq = get_bits1(gb);
- else v->halfpq = 0;
+ if (pqindex < 9)
+ v->halfpq = get_bits1(gb);
+ else
+ v->halfpq = 0;
if (v->quantizer_mode == QUANT_FRAME_EXPLICIT)
v->pquantizer = get_bits1(gb);
v->dquantfrm = 0;
- if (v->extended_mv == 1) v->mvrange = get_unary(gb, 0, 3);
+ if (v->extended_mv == 1)
+ v->mvrange = get_unary(gb, 0, 3);
v->k_x = v->mvrange + 9 + (v->mvrange >> 1); //k_x can be 9 10 12 13
v->k_y = v->mvrange + 8; //k_y can be 8 9 10 11
v->range_x = 1 << (v->k_x - 1);
v->range_y = 1 << (v->k_y - 1);
- if (v->multires && v->s.pict_type != AV_PICTURE_TYPE_B) v->respic = get_bits(gb, 2);
+ if (v->multires && v->s.pict_type != AV_PICTURE_TYPE_B)
+ v->respic = get_bits(gb, 2);
- if(v->res_x8 && (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI)){
+ if (v->res_x8 && (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI)) {
v->x8_type = get_bits1(gb);
- }else v->x8_type = 0;
+ } else
+ v->x8_type = 0;
//av_log(v->s.avctx, AV_LOG_INFO, "%c Frame: QP=[%i]%i (+%i/2) %i\n",
// (v->s.pict_type == AV_PICTURE_TYPE_P) ? 'P' : ((v->s.pict_type == AV_PICTURE_TYPE_I) ? 'I' : 'B'), pqindex, v->pq, v->halfpq, v->rangeredfrm);
- if(v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_P) v->use_ic = 0;
+ if (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_P)
+ v->use_ic = 0;
- switch(v->s.pict_type) {
+ switch (v->s.pict_type) {
case AV_PICTURE_TYPE_P:
- if (v->pq < 5) v->tt_index = 0;
- else if(v->pq < 13) v->tt_index = 1;
- else v->tt_index = 2;
+ if (v->pq < 5) v->tt_index = 0;
+ else if (v->pq < 13) v->tt_index = 1;
+ else v->tt_index = 2;
lowquant = (v->pq > 12) ? 0 : 1;
v->mv_mode = ff_vc1_mv_pmode_table[lowquant][get_unary(gb, 1, 4)];
- if (v->mv_mode == MV_PMODE_INTENSITY_COMP)
- {
+ if (v->mv_mode == MV_PMODE_INTENSITY_COMP) {
int scale, shift, i;
v->mv_mode2 = ff_vc1_mv_pmode_table2[lowquant][get_unary(gb, 1, 3)];
v->lumscale = get_bits(gb, 6);
v->lumshift = get_bits(gb, 6);
- v->use_ic = 1;
+ v->use_ic = 1;
/* fill lookup tables for intensity compensation */
- if(!v->lumscale) {
+ if (!v->lumscale) {
scale = -64;
shift = (255 - v->lumshift * 2) << 6;
- if(v->lumshift > 31)
+ if (v->lumshift > 31)
shift += 128 << 6;
} else {
scale = v->lumscale + 32;
- if(v->lumshift > 31)
+ if (v->lumshift > 31)
shift = (v->lumshift - 64) << 6;
else
shift = v->lumshift << 6;
}
- for(i = 0; i < 256; i++) {
- v->luty[i] = av_clip_uint8((scale * i + shift + 32) >> 6);
+ for (i = 0; i < 256; i++) {
+ v->luty[i] = av_clip_uint8((scale * i + shift + 32) >> 6);
v->lutuv[i] = av_clip_uint8((scale * (i - 128) + 128*64 + 32) >> 6);
}
}
- if(v->mv_mode == MV_PMODE_1MV_HPEL || v->mv_mode == MV_PMODE_1MV_HPEL_BILIN)
+ v->qs_last = v->s.quarter_sample;
+ if (v->mv_mode == MV_PMODE_1MV_HPEL || v->mv_mode == MV_PMODE_1MV_HPEL_BILIN)
v->s.quarter_sample = 0;
- else if(v->mv_mode == MV_PMODE_INTENSITY_COMP) {
- if(v->mv_mode2 == MV_PMODE_1MV_HPEL || v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN)
+ else if (v->mv_mode == MV_PMODE_INTENSITY_COMP) {
+ if (v->mv_mode2 == MV_PMODE_1MV_HPEL || v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN)
v->s.quarter_sample = 0;
else
v->s.quarter_sample = 1;
@@ -689,12 +701,12 @@ int vc1_parse_frame_header(VC1Context *v, GetBitContext* gb)
v->s.quarter_sample = 1;
v->s.mspel = !(v->mv_mode == MV_PMODE_1MV_HPEL_BILIN || (v->mv_mode == MV_PMODE_INTENSITY_COMP && v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN));
- if ((v->mv_mode == MV_PMODE_INTENSITY_COMP &&
- v->mv_mode2 == MV_PMODE_MIXED_MV)
- || v->mv_mode == MV_PMODE_MIXED_MV)
- {
+ if ((v->mv_mode == MV_PMODE_INTENSITY_COMP &&
+ v->mv_mode2 == MV_PMODE_MIXED_MV) ||
+ v->mv_mode == MV_PMODE_MIXED_MV) {
status = bitplane_decoding(v->mv_type_mb_plane, &v->mv_type_is_raw, v);
- if (status < 0) return -1;
+ if (status < 0)
+ return -1;
av_log(v->s.avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: "
"Imode: %i, Invert: %i\n", status>>1, status&1);
} else {
@@ -702,7 +714,8 @@ int vc1_parse_frame_header(VC1Context *v, GetBitContext* gb)
memset(v->mv_type_mb_plane, 0, v->s.mb_stride * v->s.mb_height);
}
status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
- if (status < 0) return -1;
+ if (status < 0)
+ return -1;
av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
"Imode: %i, Invert: %i\n", status>>1, status&1);
@@ -710,18 +723,15 @@ int vc1_parse_frame_header(VC1Context *v, GetBitContext* gb)
v->s.mv_table_index = get_bits(gb, 2); //but using ff_vc1_ tables
v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[get_bits(gb, 2)];
- if (v->dquant)
- {
+ if (v->dquant) {
av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
vop_dquant_decoding(v);
}
v->ttfrm = 0; //FIXME Is that so ?
- if (v->vstransform)
- {
+ if (v->vstransform) {
v->ttmbf = get_bits1(gb);
- if (v->ttmbf)
- {
+ if (v->ttmbf) {
v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)];
}
} else {
@@ -730,38 +740,38 @@ int vc1_parse_frame_header(VC1Context *v, GetBitContext* gb)
}
break;
case AV_PICTURE_TYPE_B:
- if (v->pq < 5) v->tt_index = 0;
- else if(v->pq < 13) v->tt_index = 1;
- else v->tt_index = 2;
+ if (v->pq < 5) v->tt_index = 0;
+ else if (v->pq < 13) v->tt_index = 1;
+ else v->tt_index = 2;
- v->mv_mode = get_bits1(gb) ? MV_PMODE_1MV : MV_PMODE_1MV_HPEL_BILIN;
+ v->mv_mode = get_bits1(gb) ? MV_PMODE_1MV : MV_PMODE_1MV_HPEL_BILIN;
+ v->qs_last = v->s.quarter_sample;
v->s.quarter_sample = (v->mv_mode == MV_PMODE_1MV);
- v->s.mspel = v->s.quarter_sample;
+ v->s.mspel = v->s.quarter_sample;
status = bitplane_decoding(v->direct_mb_plane, &v->dmb_is_raw, v);
- if (status < 0) return -1;
+ if (status < 0)
+ return -1;
av_log(v->s.avctx, AV_LOG_DEBUG, "MB Direct Type plane encoding: "
"Imode: %i, Invert: %i\n", status>>1, status&1);
status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
- if (status < 0) return -1;
+ if (status < 0)
+ return -1;
av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
"Imode: %i, Invert: %i\n", status>>1, status&1);
v->s.mv_table_index = get_bits(gb, 2);
- v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[get_bits(gb, 2)];
+ v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[get_bits(gb, 2)];
- if (v->dquant)
- {
+ if (v->dquant) {
av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
vop_dquant_decoding(v);
}
v->ttfrm = 0;
- if (v->vstransform)
- {
+ if (v->vstransform) {
v->ttmbf = get_bits1(gb);
- if (v->ttmbf)
- {
+ if (v->ttmbf) {
v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)];
}
} else {
@@ -771,85 +781,157 @@ int vc1_parse_frame_header(VC1Context *v, GetBitContext* gb)
break;
}
- if(!v->x8_type)
- {
+ if (!v->x8_type) {
/* AC Syntax */
v->c_ac_table_index = decode012(gb);
- if (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI)
- {
+ if (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI) {
v->y_ac_table_index = decode012(gb);
}
/* DC Syntax */
v->s.dc_table_index = get_bits1(gb);
}
- if(v->s.pict_type == AV_PICTURE_TYPE_BI) {
+ if (v->s.pict_type == AV_PICTURE_TYPE_BI) {
v->s.pict_type = AV_PICTURE_TYPE_B;
- v->bi_type = 1;
+ v->bi_type = 1;
}
return 0;
}
+/* fill lookup tables for intensity compensation */
+#define INIT_LUT(lumscale, lumshift, luty, lutuv) \
+ if (!lumscale) { \
+ scale = -64; \
+ shift = (255 - lumshift * 2) << 6; \
+ if (lumshift > 31) \
+ shift += 128 << 6; \
+ } else { \
+ scale = lumscale + 32; \
+ if (lumshift > 31) \
+ shift = (lumshift - 64) << 6; \
+ else \
+ shift = lumshift << 6; \
+ } \
+ for (i = 0; i < 256; i++) { \
+ luty[i] = av_clip_uint8((scale * i + shift + 32) >> 6); \
+ lutuv[i] = av_clip_uint8((scale * (i - 128) + 128*64 + 32) >> 6); \
+ }
+
int vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb)
{
int pqindex, lowquant;
int status;
+ int mbmodetab, imvtab, icbptab, twomvbptab, fourmvbptab; /* useful only for debugging */
+ int scale, shift, i; /* for initializing LUT for intensity compensation */
+ v->numref=0;
+ v->fcm=0;
+ v->field_mode=0;
v->p_frame_skipped = 0;
+ if (v->second_field) {
+ v->s.pict_type = (v->fptype & 1) ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I;
+ if (v->fptype & 4)
+ v->s.pict_type = (v->fptype & 1) ? AV_PICTURE_TYPE_BI : AV_PICTURE_TYPE_B;
+ v->s.current_picture_ptr->f.pict_type = v->s.pict_type;
+ if (!v->pic_header_flag)
+ goto parse_common_info;
+ }
- if(v->interlace){
+ v->field_mode = 0;
+ if (v->interlace) {
v->fcm = decode012(gb);
- if(v->fcm){
- if(!v->warn_interlaced++)
- av_log(v->s.avctx, AV_LOG_ERROR, "Interlaced frames/fields support is not implemented\n");
- return -1;
+ if (v->fcm) {
+ if (v->fcm == 2)
+ v->field_mode = 1;
+ if (!v->warn_interlaced++)
+ av_log(v->s.avctx, AV_LOG_ERROR,
+ "Interlaced frames/fields support is incomplete\n");
}
+ } else {
+ v->fcm = 0;
}
- switch(get_unary(gb, 0, 4)) {
- case 0:
- v->s.pict_type = AV_PICTURE_TYPE_P;
- break;
- case 1:
- v->s.pict_type = AV_PICTURE_TYPE_B;
- break;
- case 2:
- v->s.pict_type = AV_PICTURE_TYPE_I;
- break;
- case 3:
- v->s.pict_type = AV_PICTURE_TYPE_BI;
- break;
- case 4:
- v->s.pict_type = AV_PICTURE_TYPE_P; // skipped pic
- v->p_frame_skipped = 1;
- return 0;
+
+ if (v->field_mode) {
+ v->fptype = get_bits(gb, 3);
+ v->s.pict_type = (v->fptype & 2) ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I;
+ if (v->fptype & 4) // B-picture
+ v->s.pict_type = (v->fptype & 2) ? AV_PICTURE_TYPE_BI : AV_PICTURE_TYPE_B;
+ } else {
+ switch (get_unary(gb, 0, 4)) {
+ case 0:
+ v->s.pict_type = AV_PICTURE_TYPE_P;
+ break;
+ case 1:
+ v->s.pict_type = AV_PICTURE_TYPE_B;
+ break;
+ case 2:
+ v->s.pict_type = AV_PICTURE_TYPE_I;
+ break;
+ case 3:
+ v->s.pict_type = AV_PICTURE_TYPE_BI;
+ break;
+ case 4:
+ v->s.pict_type = AV_PICTURE_TYPE_P; // skipped pic
+ v->p_frame_skipped = 1;
+ break;
+ }
}
- if(v->tfcntrflag)
+ if (v->tfcntrflag)
skip_bits(gb, 8);
- if(v->broadcast) {
- if(!v->interlace || v->psf) {
+ if (v->broadcast) {
+ if (!v->interlace || v->psf) {
v->rptfrm = get_bits(gb, 2);
} else {
v->tff = get_bits1(gb);
- v->rptfrm = get_bits1(gb);
+ v->rff = get_bits1(gb);
}
}
- if(v->panscanflag) {
+ if (v->panscanflag) {
av_log_missing_feature(v->s.avctx, "Pan-scan", 0);
//...
}
+ if (v->p_frame_skipped) {
+ return 0;
+ }
v->rnd = get_bits1(gb);
- if(v->interlace)
+ if (v->interlace)
v->uvsamp = get_bits1(gb);
- if(v->finterpflag) v->interpfrm = get_bits1(gb);
- if(v->s.pict_type == AV_PICTURE_TYPE_B) {
+ if (v->field_mode) {
+ if (!v->refdist_flag)
+ v->refdist = 0;
+ else {
+ if ((v->s.pict_type != AV_PICTURE_TYPE_B)
+ && (v->s.pict_type != AV_PICTURE_TYPE_BI)) {
+ v->refdist = get_bits(gb, 2);
+ if (v->refdist == 3)
+ v->refdist += get_unary(gb, 0, 16);
+ } else {
+ v->bfraction_lut_index = get_vlc2(gb, ff_vc1_bfraction_vlc.table, VC1_BFRACTION_VLC_BITS, 1);
+ v->bfraction = ff_vc1_bfraction_lut[v->bfraction_lut_index];
+ v->frfd = (v->bfraction * v->refdist) >> 8;
+ v->brfd = v->refdist - v->frfd - 1;
+ if (v->brfd < 0)
+ v->brfd = 0;
+ }
+ }
+ goto parse_common_info;
+ }
+ if (v->finterpflag)
+ v->interpfrm = get_bits1(gb);
+ if (v->s.pict_type == AV_PICTURE_TYPE_B) {
v->bfraction_lut_index = get_vlc2(gb, ff_vc1_bfraction_vlc.table, VC1_BFRACTION_VLC_BITS, 1);
- v->bfraction = ff_vc1_bfraction_lut[v->bfraction_lut_index];
- if(v->bfraction == 0) {
+ v->bfraction = ff_vc1_bfraction_lut[v->bfraction_lut_index];
+ if (v->bfraction == 0) {
v->s.pict_type = AV_PICTURE_TYPE_BI; /* XXX: should not happen here */
}
}
+
+ parse_common_info:
+ if (v->field_mode)
+ v->cur_field_type = !(v->tff ^ v->second_field);
pqindex = get_bits(gb, 5);
- if(!pqindex) return -1;
+ if (!pqindex)
+ return -1;
v->pqindex = pqindex;
if (v->quantizer_mode == QUANT_FRAME_IMPLICIT)
v->pq = ff_vc1_pquant_table[0][pqindex];
@@ -862,118 +944,193 @@ int vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb)
if (v->quantizer_mode == QUANT_NON_UNIFORM)
v->pquantizer = 0;
v->pqindex = pqindex;
- if (pqindex < 9) v->halfpq = get_bits1(gb);
- else v->halfpq = 0;
+ if (pqindex < 9)
+ v->halfpq = get_bits1(gb);
+ else
+ v->halfpq = 0;
if (v->quantizer_mode == QUANT_FRAME_EXPLICIT)
v->pquantizer = get_bits1(gb);
- if(v->postprocflag)
+ if (v->postprocflag)
v->postproc = get_bits(gb, 2);
- if(v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_P) v->use_ic = 0;
+ if (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_P)
+ v->use_ic = 0;
- if(v->parse_only)
+ if (v->parse_only)
return 0;
- switch(v->s.pict_type) {
+ switch (v->s.pict_type) {
case AV_PICTURE_TYPE_I:
case AV_PICTURE_TYPE_BI:
+ if (v->fcm == 1) { //interlace frame picture
+ status = bitplane_decoding(v->fieldtx_plane, &v->fieldtx_is_raw, v);
+ if (status < 0)
+ return -1;
+ av_log(v->s.avctx, AV_LOG_DEBUG, "FIELDTX plane encoding: "
+ "Imode: %i, Invert: %i\n", status>>1, status&1);
+ }
status = bitplane_decoding(v->acpred_plane, &v->acpred_is_raw, v);
- if (status < 0) return -1;
+ if (status < 0)
+ return -1;
av_log(v->s.avctx, AV_LOG_DEBUG, "ACPRED plane encoding: "
- "Imode: %i, Invert: %i\n", status>>1, status&1);
+ "Imode: %i, Invert: %i\n", status>>1, status&1);
v->condover = CONDOVER_NONE;
- if(v->overlap && v->pq <= 8) {
+ if (v->overlap && v->pq <= 8) {
v->condover = decode012(gb);
- if(v->condover == CONDOVER_SELECT) {
+ if (v->condover == CONDOVER_SELECT) {
status = bitplane_decoding(v->over_flags_plane, &v->overflg_is_raw, v);
- if (status < 0) return -1;
+ if (status < 0)
+ return -1;
av_log(v->s.avctx, AV_LOG_DEBUG, "CONDOVER plane encoding: "
- "Imode: %i, Invert: %i\n", status>>1, status&1);
+ "Imode: %i, Invert: %i\n", status>>1, status&1);
}
}
break;
case AV_PICTURE_TYPE_P:
- if (v->extended_mv) v->mvrange = get_unary(gb, 0, 3);
- else v->mvrange = 0;
+ if (v->field_mode) {
+ v->numref = get_bits1(gb);
+ if (!v->numref) {
+ v->reffield = get_bits1(gb);
+ v->ref_field_type[0] = v->reffield ^ !v->cur_field_type;
+ }
+ }
+ if (v->extended_mv)
+ v->mvrange = get_unary(gb, 0, 3);
+ else
+ v->mvrange = 0;
+ if (v->interlace) {
+ if (v->extended_dmv)
+ v->dmvrange = get_unary(gb, 0, 3);
+ else
+ v->dmvrange = 0;
+ if (v->fcm == 1) { // interlaced frame picture
+ v->fourmvswitch = get_bits1(gb);
+ v->intcomp = get_bits1(gb);
+ if (v->intcomp) {
+ v->lumscale = get_bits(gb, 6);
+ v->lumshift = get_bits(gb, 6);
+ INIT_LUT(v->lumscale, v->lumshift, v->luty, v->lutuv);
+ }
+ status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
+ av_log(v->s.avctx, AV_LOG_DEBUG, "SKIPMB plane encoding: "
+ "Imode: %i, Invert: %i\n", status>>1, status&1);
+ mbmodetab = get_bits(gb, 2);
+ if (v->fourmvswitch)
+ v->mbmode_vlc = &ff_vc1_intfr_4mv_mbmode_vlc[mbmodetab];
+ else
+ v->mbmode_vlc = &ff_vc1_intfr_non4mv_mbmode_vlc[mbmodetab];
+ imvtab = get_bits(gb, 2);
+ v->imv_vlc = &ff_vc1_1ref_mvdata_vlc[imvtab];
+ // interlaced p-picture cbpcy range is [1, 63]
+ icbptab = get_bits(gb, 3);
+ v->cbpcy_vlc = &ff_vc1_icbpcy_vlc[icbptab];
+ twomvbptab = get_bits(gb, 2);
+ v->twomvbp_vlc = &ff_vc1_2mv_block_pattern_vlc[twomvbptab];
+ if (v->fourmvswitch) {
+ fourmvbptab = get_bits(gb, 2);
+ v->fourmvbp_vlc = &ff_vc1_4mv_block_pattern_vlc[fourmvbptab];
+ }
+ }
+ }
v->k_x = v->mvrange + 9 + (v->mvrange >> 1); //k_x can be 9 10 12 13
v->k_y = v->mvrange + 8; //k_y can be 8 9 10 11
v->range_x = 1 << (v->k_x - 1);
v->range_y = 1 << (v->k_y - 1);
- if (v->pq < 5) v->tt_index = 0;
- else if(v->pq < 13) v->tt_index = 1;
- else v->tt_index = 2;
-
- lowquant = (v->pq > 12) ? 0 : 1;
- v->mv_mode = ff_vc1_mv_pmode_table[lowquant][get_unary(gb, 1, 4)];
- if (v->mv_mode == MV_PMODE_INTENSITY_COMP)
- {
- int scale, shift, i;
- v->mv_mode2 = ff_vc1_mv_pmode_table2[lowquant][get_unary(gb, 1, 3)];
- v->lumscale = get_bits(gb, 6);
- v->lumshift = get_bits(gb, 6);
- /* fill lookup tables for intensity compensation */
- if(!v->lumscale) {
- scale = -64;
- shift = (255 - v->lumshift * 2) << 6;
- if(v->lumshift > 31)
- shift += 128 << 6;
- } else {
- scale = v->lumscale + 32;
- if(v->lumshift > 31)
- shift = (v->lumshift - 64) << 6;
- else
- shift = v->lumshift << 6;
- }
- for(i = 0; i < 256; i++) {
- v->luty[i] = av_clip_uint8((scale * i + shift + 32) >> 6);
- v->lutuv[i] = av_clip_uint8((scale * (i - 128) + 128*64 + 32) >> 6);
+ if (v->pq < 5)
+ v->tt_index = 0;
+ else if (v->pq < 13)
+ v->tt_index = 1;
+ else
+ v->tt_index = 2;
+ if (v->fcm != 1) {
+ int mvmode;
+ mvmode = get_unary(gb, 1, 4);
+ lowquant = (v->pq > 12) ? 0 : 1;
+ v->mv_mode = ff_vc1_mv_pmode_table[lowquant][mvmode];
+ if (v->mv_mode == MV_PMODE_INTENSITY_COMP) {
+ int mvmode2;
+ mvmode2 = get_unary(gb, 1, 3);
+ v->mv_mode2 = ff_vc1_mv_pmode_table2[lowquant][mvmode2];
+ if (v->field_mode)
+ v->intcompfield = decode210(gb);
+ v->lumscale = get_bits(gb, 6);
+ v->lumshift = get_bits(gb, 6);
+ INIT_LUT(v->lumscale, v->lumshift, v->luty, v->lutuv);
+ if ((v->field_mode) && !v->intcompfield) {
+ v->lumscale2 = get_bits(gb, 6);
+ v->lumshift2 = get_bits(gb, 6);
+ INIT_LUT(v->lumscale2, v->lumshift2, v->luty2, v->lutuv2);
+ }
+ v->use_ic = 1;
}
- v->use_ic = 1;
- }
- if(v->mv_mode == MV_PMODE_1MV_HPEL || v->mv_mode == MV_PMODE_1MV_HPEL_BILIN)
- v->s.quarter_sample = 0;
- else if(v->mv_mode == MV_PMODE_INTENSITY_COMP) {
- if(v->mv_mode2 == MV_PMODE_1MV_HPEL || v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN)
+ v->qs_last = v->s.quarter_sample;
+ if (v->mv_mode == MV_PMODE_1MV_HPEL || v->mv_mode == MV_PMODE_1MV_HPEL_BILIN)
v->s.quarter_sample = 0;
- else
+ else if (v->mv_mode == MV_PMODE_INTENSITY_COMP) {
+ if (v->mv_mode2 == MV_PMODE_1MV_HPEL || v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN)
+ v->s.quarter_sample = 0;
+ else
+ v->s.quarter_sample = 1;
+ } else
v->s.quarter_sample = 1;
- } else
- v->s.quarter_sample = 1;
- v->s.mspel = !(v->mv_mode == MV_PMODE_1MV_HPEL_BILIN || (v->mv_mode == MV_PMODE_INTENSITY_COMP && v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN));
-
- if ((v->mv_mode == MV_PMODE_INTENSITY_COMP &&
+ v->s.mspel = !(v->mv_mode == MV_PMODE_1MV_HPEL_BILIN
+ || (v->mv_mode == MV_PMODE_INTENSITY_COMP
+ && v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN));
+ }
+ if (v->fcm == 0) { // progressive
+ if ((v->mv_mode == MV_PMODE_INTENSITY_COMP &&
v->mv_mode2 == MV_PMODE_MIXED_MV)
- || v->mv_mode == MV_PMODE_MIXED_MV)
- {
- status = bitplane_decoding(v->mv_type_mb_plane, &v->mv_type_is_raw, v);
- if (status < 0) return -1;
- av_log(v->s.avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: "
+ || v->mv_mode == MV_PMODE_MIXED_MV) {
+ status = bitplane_decoding(v->mv_type_mb_plane, &v->mv_type_is_raw, v);
+ if (status < 0)
+ return -1;
+ av_log(v->s.avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: "
+ "Imode: %i, Invert: %i\n", status>>1, status&1);
+ } else {
+ v->mv_type_is_raw = 0;
+ memset(v->mv_type_mb_plane, 0, v->s.mb_stride * v->s.mb_height);
+ }
+ status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
+ if (status < 0)
+ return -1;
+ av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
"Imode: %i, Invert: %i\n", status>>1, status&1);
- } else {
- v->mv_type_is_raw = 0;
- memset(v->mv_type_mb_plane, 0, v->s.mb_stride * v->s.mb_height);
- }
- status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
- if (status < 0) return -1;
- av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
- "Imode: %i, Invert: %i\n", status>>1, status&1);
- /* Hopefully this is correct for P frames */
- v->s.mv_table_index = get_bits(gb, 2); //but using ff_vc1_ tables
- v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[get_bits(gb, 2)];
- if (v->dquant)
- {
+ /* Hopefully this is correct for P frames */
+ v->s.mv_table_index = get_bits(gb, 2); //but using ff_vc1_ tables
+ v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[get_bits(gb, 2)];
+ } else if (v->fcm == 1) { // frame interlaced
+ v->qs_last = v->s.quarter_sample;
+ v->s.quarter_sample = 1;
+ v->s.mspel = 1;
+ } else { // field interlaced
+ mbmodetab = get_bits(gb, 3);
+ imvtab = get_bits(gb, 2 + v->numref);
+ if (!v->numref)
+ v->imv_vlc = &ff_vc1_1ref_mvdata_vlc[imvtab];
+ else
+ v->imv_vlc = &ff_vc1_2ref_mvdata_vlc[imvtab];
+ icbptab = get_bits(gb, 3);
+ v->cbpcy_vlc = &ff_vc1_icbpcy_vlc[icbptab];
+ if ((v->mv_mode == MV_PMODE_INTENSITY_COMP &&
+ v->mv_mode2 == MV_PMODE_MIXED_MV) || v->mv_mode == MV_PMODE_MIXED_MV) {
+ fourmvbptab = get_bits(gb, 2);
+ v->fourmvbp_vlc = &ff_vc1_4mv_block_pattern_vlc[fourmvbptab];
+ v->mbmode_vlc = &ff_vc1_if_mmv_mbmode_vlc[mbmodetab];
+ } else {
+ v->mbmode_vlc = &ff_vc1_if_1mv_mbmode_vlc[mbmodetab];
+ }
+ }
+ if (v->dquant) {
av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
vop_dquant_decoding(v);
}
v->ttfrm = 0; //FIXME Is that so ?
- if (v->vstransform)
- {
+ if (v->vstransform) {
v->ttmbf = get_bits1(gb);
- if (v->ttmbf)
- {
+ if (v->ttmbf) {
v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)];
}
} else {
@@ -982,45 +1139,84 @@ int vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb)
}
break;
case AV_PICTURE_TYPE_B:
- if (v->extended_mv) v->mvrange = get_unary(gb, 0, 3);
- else v->mvrange = 0;
- v->k_x = v->mvrange + 9 + (v->mvrange >> 1); //k_x can be 9 10 12 13
- v->k_y = v->mvrange + 8; //k_y can be 8 9 10 11
+ // TODO: implement interlaced frame B picture decoding
+ if (v->fcm == 1)
+ return -1;
+ if (v->extended_mv)
+ v->mvrange = get_unary(gb, 0, 3);
+ else
+ v->mvrange = 0;
+ v->k_x = v->mvrange + 9 + (v->mvrange >> 1); //k_x can be 9 10 12 13
+ v->k_y = v->mvrange + 8; //k_y can be 8 9 10 11
v->range_x = 1 << (v->k_x - 1);
v->range_y = 1 << (v->k_y - 1);
- if (v->pq < 5) v->tt_index = 0;
- else if(v->pq < 13) v->tt_index = 1;
- else v->tt_index = 2;
-
- v->mv_mode = get_bits1(gb) ? MV_PMODE_1MV : MV_PMODE_1MV_HPEL_BILIN;
- v->s.quarter_sample = (v->mv_mode == MV_PMODE_1MV);
- v->s.mspel = v->s.quarter_sample;
-
- status = bitplane_decoding(v->direct_mb_plane, &v->dmb_is_raw, v);
- if (status < 0) return -1;
- av_log(v->s.avctx, AV_LOG_DEBUG, "MB Direct Type plane encoding: "
- "Imode: %i, Invert: %i\n", status>>1, status&1);
- status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
- if (status < 0) return -1;
- av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
- "Imode: %i, Invert: %i\n", status>>1, status&1);
+ if (v->pq < 5)
+ v->tt_index = 0;
+ else if (v->pq < 13)
+ v->tt_index = 1;
+ else
+ v->tt_index = 2;
- v->s.mv_table_index = get_bits(gb, 2);
- v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[get_bits(gb, 2)];
+ if (v->field_mode) {
+ int mvmode;
+ av_log(v->s.avctx, AV_LOG_ERROR, "B Fields do not work currently\n");
+ return -1;
+ if (v->extended_dmv)
+ v->dmvrange = get_unary(gb, 0, 3);
+ mvmode = get_unary(gb, 1, 3);
+ lowquant = (v->pq > 12) ? 0 : 1;
+ v->mv_mode = ff_vc1_mv_pmode_table2[lowquant][mvmode];
+ v->qs_last = v->s.quarter_sample;
+ v->s.quarter_sample = (v->mv_mode == MV_PMODE_1MV || v->mv_mode == MV_PMODE_MIXED_MV);
+ v->s.mspel = !(v->mv_mode == MV_PMODE_1MV_HPEL_BILIN || v->mv_mode == MV_PMODE_1MV_HPEL);
+ status = bitplane_decoding(v->forward_mb_plane, &v->fmb_is_raw, v);
+ if (status < 0)
+ return -1;
+ av_log(v->s.avctx, AV_LOG_DEBUG, "MB Forward Type plane encoding: "
+ "Imode: %i, Invert: %i\n", status>>1, status&1);
+ mbmodetab = get_bits(gb, 3);
+ if (v->mv_mode == MV_PMODE_MIXED_MV)
+ v->mbmode_vlc = &ff_vc1_if_mmv_mbmode_vlc[mbmodetab];
+ else
+ v->mbmode_vlc = &ff_vc1_if_1mv_mbmode_vlc[mbmodetab];
+ imvtab = get_bits(gb, 3);
+ v->imv_vlc = &ff_vc1_2ref_mvdata_vlc[imvtab];
+ icbptab = get_bits(gb, 3);
+ v->cbpcy_vlc = &ff_vc1_icbpcy_vlc[icbptab];
+ if (v->mv_mode == MV_PMODE_MIXED_MV) {
+ fourmvbptab = get_bits(gb, 2);
+ v->fourmvbp_vlc = &ff_vc1_4mv_block_pattern_vlc[fourmvbptab];
+ }
+ v->numref = 1; // interlaced field B pictures are always 2-ref
+ } else {
+ v->mv_mode = get_bits1(gb) ? MV_PMODE_1MV : MV_PMODE_1MV_HPEL_BILIN;
+ v->qs_last = v->s.quarter_sample;
+ v->s.quarter_sample = (v->mv_mode == MV_PMODE_1MV);
+ v->s.mspel = v->s.quarter_sample;
+ status = bitplane_decoding(v->direct_mb_plane, &v->dmb_is_raw, v);
+ if (status < 0)
+ return -1;
+ av_log(v->s.avctx, AV_LOG_DEBUG, "MB Direct Type plane encoding: "
+ "Imode: %i, Invert: %i\n", status>>1, status&1);
+ status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
+ if (status < 0)
+ return -1;
+ av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
+ "Imode: %i, Invert: %i\n", status>>1, status&1);
+ v->s.mv_table_index = get_bits(gb, 2);
+ v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[get_bits(gb, 2)];
+ }
- if (v->dquant)
- {
+ if (v->dquant) {
av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
vop_dquant_decoding(v);
}
v->ttfrm = 0;
- if (v->vstransform)
- {
+ if (v->vstransform) {
v->ttmbf = get_bits1(gb);
- if (v->ttmbf)
- {
+ if (v->ttmbf) {
v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)];
}
} else {
@@ -1032,19 +1228,19 @@ int vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb)
/* AC Syntax */
v->c_ac_table_index = decode012(gb);
- if (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI)
- {
+ if (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI) {
v->y_ac_table_index = decode012(gb);
}
/* DC Syntax */
v->s.dc_table_index = get_bits1(gb);
- if ((v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI) && v->dquant) {
+ if ((v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI)
+ && v->dquant) {
av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
vop_dquant_decoding(v);
}
v->bi_type = 0;
- if(v->s.pict_type == AV_PICTURE_TYPE_BI) {
+ if (v->s.pict_type == AV_PICTURE_TYPE_BI) {
v->s.pict_type = AV_PICTURE_TYPE_B;
v->bi_type = 1;
}
diff --git a/libavcodec/vc1.h b/libavcodec/vc1.h
index 96e5744228..209d825057 100644
--- a/libavcodec/vc1.h
+++ b/libavcodec/vc1.h
@@ -3,20 +3,20 @@
* Copyright (c) 2006-2007 Konstantin Shishkov
* Partly based on vc9.c (c) 2005 Anonymous, Alex Beregszaszi, Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -30,7 +30,7 @@
/** Markers used in VC-1 AP frame data */
//@{
-enum VC1Code{
+enum VC1Code {
VC1_CODE_RES0 = 0x00000100,
VC1_CODE_ENDOFSEQ = 0x0000010A,
VC1_CODE_SLICE,
@@ -105,12 +105,25 @@ enum MVModes {
};
//@}
+/** MBMODE for interlaced frame P-picture */
+//@{
+enum MBModesIntfr {
+ MV_PMODE_INTFR_1MV,
+ MV_PMODE_INTFR_2MV_FIELD,
+ MV_PMODE_INTFR_2MV,
+ MV_PMODE_INTFR_4MV_FIELD,
+ MV_PMODE_INTFR_4MV,
+ MV_PMODE_INTFR_INTRA,
+};
+//@}
+
/** @name MV types for B frames */
//@{
enum BMVTypes {
BMV_TYPE_BACKWARD,
BMV_TYPE_FORWARD,
- BMV_TYPE_INTERPOLATED
+ BMV_TYPE_INTERPOLATED,
+ BMV_TYPE_DIRECT
};
//@}
@@ -120,10 +133,10 @@ enum TransformTypes {
TT_8X8,
TT_8X4_BOTTOM,
TT_8X4_TOP,
- TT_8X4, //Both halves
+ TT_8X4, // both halves
TT_4X8_RIGHT,
TT_4X8_LEFT,
- TT_4X8, //Both halves
+ TT_4X8, // both halves
TT_4X4
};
//@}
@@ -211,16 +224,16 @@ typedef struct VC1Context{
/** Frame decoding info for all profiles */
//@{
- uint8_t mv_mode; ///< MV coding monde
- uint8_t mv_mode2; ///< Secondary MV coding mode (B frames)
- int k_x; ///< Number of bits for MVs (depends on MV range)
- int k_y; ///< Number of bits for MVs (depends on MV range)
- int range_x, range_y; ///< MV range
- uint8_t pq, altpq; ///< Current/alternate frame quantizer scale
- uint8_t zz_8x8[4][64];///< Zigzag table for TT_8x8, permuted for IDCT
+ uint8_t mv_mode; ///< MV coding monde
+ uint8_t mv_mode2; ///< Secondary MV coding mode (B frames)
+ int k_x; ///< Number of bits for MVs (depends on MV range)
+ int k_y; ///< Number of bits for MVs (depends on MV range)
+ int range_x, range_y; ///< MV range
+ uint8_t pq, altpq; ///< Current/alternate frame quantizer scale
+ uint8_t zz_8x8[4][64]; ///< Zigzag table for TT_8x8, permuted for IDCT
int left_blk_sh, top_blk_sh; ///< Either 3 or 0, positions of l/t in blk[]
- const uint8_t* zz_8x4;///< Zigzag scan table for TT_8x4 coding mode
- const uint8_t* zz_4x8;///< Zigzag scan table for TT_4x8 coding mode
+ const uint8_t* zz_8x4; ///< Zigzag scan table for TT_8x4 coding mode
+ const uint8_t* zz_4x8; ///< Zigzag scan table for TT_4x8 coding mode
/** pquant parameters */
//@{
uint8_t dquantfrm;
@@ -232,15 +245,15 @@ typedef struct VC1Context{
* @see 8.1.1.10, p(1)10
*/
//@{
- int c_ac_table_index; ///< Chroma index from ACFRM element
- int y_ac_table_index; ///< Luma index from AC2FRM element
+ int c_ac_table_index; ///< Chroma index from ACFRM element
+ int y_ac_table_index; ///< Luma index from AC2FRM element
//@}
- int ttfrm; ///< Transform type info present at frame level
- uint8_t ttmbf; ///< Transform type flag
+ int ttfrm; ///< Transform type info present at frame level
+ uint8_t ttmbf; ///< Transform type flag
int *ttblk_base, *ttblk; ///< Transform type at the block level
- int codingset; ///< index of current table set from 11.8 to use for luma block decoding
- int codingset2; ///< index of current table set from 11.8 to use for chroma block decoding
- int pqindex; ///< raw pqindex used in coding set selection
+ int codingset; ///< index of current table set from 11.8 to use for luma block decoding
+ int codingset2; ///< index of current table set from 11.8 to use for chroma block decoding
+ int pqindex; ///< raw pqindex used in coding set selection
int a_avail, c_avail;
uint8_t *mb_type_base, *mb_type[3];
@@ -260,22 +273,24 @@ typedef struct VC1Context{
* -# 2 -> [-512, 511.f] x [-128, 127.f]
* -# 3 -> [-1024, 1023.f] x [-256, 255.f]
*/
- uint8_t mvrange;
- uint8_t pquantizer; ///< Uniform (over sequence) quantizer in use
- VLC *cbpcy_vlc; ///< CBPCY VLC table
- int tt_index; ///< Index for Transform Type tables
- uint8_t* mv_type_mb_plane; ///< bitplane for mv_type == (4MV)
- uint8_t* direct_mb_plane; ///< bitplane for "direct" MBs
- int mv_type_is_raw; ///< mv type mb plane is not coded
- int dmb_is_raw; ///< direct mb plane is raw
- int skip_is_raw; ///< skip mb plane is not coded
- uint8_t luty[256], lutuv[256]; // lookup tables used for intensity compensation
- int use_ic; ///< use intensity compensation in B-frames
- int rnd; ///< rounding control
+ uint8_t mvrange; ///< Extended MV range flag
+ uint8_t pquantizer; ///< Uniform (over sequence) quantizer in use
+ VLC *cbpcy_vlc; ///< CBPCY VLC table
+ int tt_index; ///< Index for Transform Type tables (to decode TTMB)
+ uint8_t* mv_type_mb_plane; ///< bitplane for mv_type == (4MV)
+ uint8_t* direct_mb_plane; ///< bitplane for "direct" MBs
+ uint8_t* forward_mb_plane; ///< bitplane for "forward" MBs
+ int mv_type_is_raw; ///< mv type mb plane is not coded
+ int dmb_is_raw; ///< direct mb plane is raw
+ int fmb_is_raw; ///< forward mb plane is raw
+ int skip_is_raw; ///< skip mb plane is not coded
+ uint8_t luty[256], lutuv[256]; ///< lookup tables used for intensity compensation
+ int use_ic; ///< use intensity compensation in B-frames
+ int rnd; ///< rounding control
/** Frame decoding info for S/M profiles only */
//@{
- uint8_t rangeredfrm; ///< out_sample = CLIP((in_sample-128)*2+128)
+ uint8_t rangeredfrm; ///< out_sample = CLIP((in_sample-128)*2+128)
uint8_t interpfrm;
//@}
@@ -307,10 +322,51 @@ typedef struct VC1Context{
uint8_t range_mapuv;
//@}
+ /** Frame decoding info for interlaced picture */
+ uint8_t dmvrange; ///< Extended differential MV range flag
+ int fourmvswitch;
+ int intcomp;
+ uint8_t lumscale2; ///< for interlaced field P picture
+ uint8_t lumshift2;
+ uint8_t luty2[256], lutuv2[256]; // lookup tables used for intensity compensation
+ VLC* mbmode_vlc;
+ VLC* imv_vlc;
+ VLC* twomvbp_vlc;
+ VLC* fourmvbp_vlc;
+ uint8_t twomvbp;
+ uint8_t fourmvbp;
+ uint8_t* fieldtx_plane;
+ int fieldtx_is_raw;
+ int8_t zzi_8x8[64];
+ uint8_t *blk_mv_type_base, *blk_mv_type; ///< 0: frame MV, 1: field MV (interlaced frame)
+ uint8_t *mv_f_base, *mv_f[2]; ///< 0: MV obtained from same field, 1: opposite field
+ uint8_t *mv_f_last_base, *mv_f_last[2];
+ uint8_t *mv_f_next_base, *mv_f_next[2];
+ int field_mode; ///< 1 for interlaced field pictures
+ int fptype;
+ int second_field;
+ int refdist; ///< distance of the current picture from reference
+ int numref; ///< number of past field pictures used as reference
+ // 0 corresponds to 1 and 1 corresponds to 2 references
+ int reffield; ///< if numref = 0 (1 reference) then reffield decides which
+ // field to use among the two fields from previous frame
+ int intcompfield; ///< which of the two fields to be intensity compensated
+ // 0: both fields, 1: bottom field, 2: top field
+ int cur_field_type; ///< 0: top, 1: bottom
+ int ref_field_type[2]; ///< forward and backward reference field type (top or bottom)
+ int blocks_off, mb_off;
+ int qs_last; ///< if qpel has been used in the previous (tr.) picture
+ int bmvtype;
+ int frfd, brfd; ///< reference frame distance (forward or backward)
+ int pic_header_flag;
+
/** Frame decoding info for sprite modes */
//@{
int new_sprite;
int two_sprites;
+ AVFrame sprite_output_frame;
+ int output_width, output_height, sprite_width, sprite_height;
+ uint8_t* sr_rows[2][2]; ///< Sprite resizer line cache
//@}
int p_frame_skipped;
@@ -322,11 +378,11 @@ typedef struct VC1Context{
uint32_t *cbp_base, *cbp;
uint8_t *is_intra_base, *is_intra;
int16_t (*luma_mv_base)[2], (*luma_mv)[2];
- uint8_t bfraction_lut_index;///< Index for BFRACTION value (see Table 40, reproduced into ff_vc1_bfraction_lut[])
- uint8_t broken_link; ///< Broken link flag (BROKEN_LINK syntax element)
- uint8_t closed_entry; ///< Closed entry point flag (CLOSED_ENTRY syntax element)
+ uint8_t bfraction_lut_index; ///< Index for BFRACTION value (see Table 40, reproduced into ff_vc1_bfraction_lut[])
+ uint8_t broken_link; ///< Broken link flag (BROKEN_LINK syntax element)
+ uint8_t closed_entry; ///< Closed entry point flag (CLOSED_ENTRY syntax element)
- int parse_only; ///< Context is used within parser
+ int parse_only; ///< Context is used within parser
int warn_interlaced;
} VC1Context;
@@ -338,11 +394,12 @@ static av_always_inline const uint8_t* find_next_marker(const uint8_t *src, cons
{
uint32_t mrk = 0xFFFFFFFF;
- if(end-src < 4) return end;
- while(src < end){
+ if (end-src < 4)
+ return end;
+ while (src < end) {
mrk = (mrk << 8) | *src++;
- if(IS_MARKER(mrk))
- return src-4;
+ if (IS_MARKER(mrk))
+ return src - 4;
}
return end;
}
@@ -351,12 +408,13 @@ static av_always_inline int vc1_unescape_buffer(const uint8_t *src, int size, ui
{
int dsize = 0, i;
- if(size < 4){
- for(dsize = 0; dsize < size; dsize++) *dst++ = *src++;
+ if (size < 4) {
+ for (dsize = 0; dsize < size; dsize++)
+ *dst++ = *src++;
return size;
}
- for(i = 0; i < size; i++, src++) {
- if(src[0] == 3 && i >= 2 && !src[-1] && !src[-2] && i < size-1 && src[1] < 4) {
+ for (i = 0; i < size; i++, src++) {
+ if (src[0] == 3 && i >= 2 && !src[-1] && !src[-2] && i < size-1 && src[1] < 4) {
dst[dsize++] = src[1];
src++;
i++;
diff --git a/libavcodec/vc1_parser.c b/libavcodec/vc1_parser.c
index 27ff1bdaa3..99023db492 100644
--- a/libavcodec/vc1_parser.c
+++ b/libavcodec/vc1_parser.c
@@ -3,20 +3,20 @@
* Copyright (c) 2006-2007 Konstantin Shishkov
* Partly based on vc9.c (c) 2005 Anonymous, Alex Beregszaszi, Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -45,6 +45,7 @@ static void vc1_extract_headers(AVCodecParserContext *s, AVCodecContext *avctx,
vpc->v.s.avctx = avctx;
vpc->v.parse_only = 1;
next = buf;
+ s->repeat_pict = 0;
for(start = buf, end = buf + buf_size; next < end; start = next){
int buf2_size, size;
@@ -73,6 +74,20 @@ static void vc1_extract_headers(AVCodecParserContext *s, AVCodecContext *avctx,
else
s->pict_type = vpc->v.s.pict_type;
+ if (avctx->ticks_per_frame > 1){
+ // process pulldown flags
+ s->repeat_pict = 1;
+ // Pulldown flags are only valid when 'broadcast' has been set.
+ // So ticks_per_frame will be 2
+ if (vpc->v.rff){
+ // repeat field
+ s->repeat_pict = 2;
+ }else if (vpc->v.rptfrm){
+ // repeat frames
+ s->repeat_pict = vpc->v.rptfrm * 2 + 1;
+ }
+ }
+
break;
}
}
diff --git a/libavcodec/vc1acdata.h b/libavcodec/vc1acdata.h
index a7a33ff805..78de0f9a24 100644
--- a/libavcodec/vc1acdata.h
+++ b/libavcodec/vc1acdata.h
@@ -2,20 +2,20 @@
* VC-1 and WMV3 decoder
* copyright (c) 2006 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/vc1data.c b/libavcodec/vc1data.c
index 1cbf93e224..7f979ba109 100644
--- a/libavcodec/vc1data.c
+++ b/libavcodec/vc1data.c
@@ -1,22 +1,23 @@
/*
* VC-1 and WMV3 decoder
+ * copyright (c) 2011 Mashiat Sarker Shakkhar
* copyright (c) 2006 Konstantin Shishkov
* (c) 2005 anonymous, Alex Beregszaszi, Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -31,38 +32,70 @@
/** Table for conversion between TTBLK and TTMB */
const int ff_vc1_ttblk_to_tt[3][8] = {
- { TT_8X4, TT_4X8, TT_8X8, TT_4X4, TT_8X4_TOP, TT_8X4_BOTTOM, TT_4X8_RIGHT, TT_4X8_LEFT },
- { TT_8X8, TT_4X8_RIGHT, TT_4X8_LEFT, TT_4X4, TT_8X4, TT_4X8, TT_8X4_BOTTOM, TT_8X4_TOP },
- { TT_8X8, TT_4X8, TT_4X4, TT_8X4_BOTTOM, TT_4X8_RIGHT, TT_4X8_LEFT, TT_8X4, TT_8X4_TOP }
+ { TT_8X4, TT_4X8, TT_8X8, TT_4X4, TT_8X4_TOP, TT_8X4_BOTTOM, TT_4X8_RIGHT, TT_4X8_LEFT },
+ { TT_8X8, TT_4X8_RIGHT, TT_4X8_LEFT, TT_4X4, TT_8X4, TT_4X8, TT_8X4_BOTTOM, TT_8X4_TOP },
+ { TT_8X8, TT_4X8, TT_4X4, TT_8X4_BOTTOM, TT_4X8_RIGHT, TT_4X8_LEFT, TT_8X4, TT_8X4_TOP }
};
const int ff_vc1_ttfrm_to_tt[4] = { TT_8X8, TT_8X4, TT_4X8, TT_4X4 };
/** MV P mode - the 5th element is only used for mode 1 */
const uint8_t ff_vc1_mv_pmode_table[2][5] = {
- { MV_PMODE_1MV_HPEL_BILIN, MV_PMODE_1MV, MV_PMODE_1MV_HPEL, MV_PMODE_INTENSITY_COMP, MV_PMODE_MIXED_MV },
- { MV_PMODE_1MV, MV_PMODE_MIXED_MV, MV_PMODE_1MV_HPEL, MV_PMODE_INTENSITY_COMP, MV_PMODE_1MV_HPEL_BILIN }
+ { MV_PMODE_1MV_HPEL_BILIN, MV_PMODE_1MV, MV_PMODE_1MV_HPEL, MV_PMODE_INTENSITY_COMP, MV_PMODE_MIXED_MV },
+ { MV_PMODE_1MV, MV_PMODE_MIXED_MV, MV_PMODE_1MV_HPEL, MV_PMODE_INTENSITY_COMP, MV_PMODE_1MV_HPEL_BILIN }
};
const uint8_t ff_vc1_mv_pmode_table2[2][4] = {
- { MV_PMODE_1MV_HPEL_BILIN, MV_PMODE_1MV, MV_PMODE_1MV_HPEL, MV_PMODE_MIXED_MV },
- { MV_PMODE_1MV, MV_PMODE_MIXED_MV, MV_PMODE_1MV_HPEL, MV_PMODE_1MV_HPEL_BILIN }
+ { MV_PMODE_1MV_HPEL_BILIN, MV_PMODE_1MV, MV_PMODE_1MV_HPEL, MV_PMODE_MIXED_MV },
+ { MV_PMODE_1MV, MV_PMODE_MIXED_MV, MV_PMODE_1MV_HPEL, MV_PMODE_1MV_HPEL_BILIN }
+};
+
+/* MBMODE table for interlaced frame P-picture */
+const uint8_t ff_vc1_mbmode_intfrp[2][15][4] = {
+ { /* 1: 4-MV, 0: non-4-MV */
+ /* Type, FIELDTX, 1-MV Differential present, Residuals (CBP) present */
+ /* Table 164 - Table 167 */
+ { MV_PMODE_INTFR_1MV , 0, 1, 1 },
+ { MV_PMODE_INTFR_1MV , 1, 1, 1 },
+ { MV_PMODE_INTFR_1MV , 0, 1, 0 },
+ { MV_PMODE_INTFR_1MV , 0, 0, 1 },
+ { MV_PMODE_INTFR_1MV , 1, 0, 1 },
+ { MV_PMODE_INTFR_2MV_FIELD, 0, 0, 1 },
+ { MV_PMODE_INTFR_2MV_FIELD, 1, 0, 1 },
+ { MV_PMODE_INTFR_2MV_FIELD, 0, 0, 0 },
+ { MV_PMODE_INTFR_INTRA , 0, 0, 0 }
+ },
+ {
+ /* Table 160 - Table 163 */
+ { MV_PMODE_INTFR_1MV , 0, 1, 1 },
+ { MV_PMODE_INTFR_1MV , 1, 1, 1 },
+ { MV_PMODE_INTFR_1MV , 0, 1, 0 },
+ { MV_PMODE_INTFR_1MV , 0, 0, 1 },
+ { MV_PMODE_INTFR_1MV , 1, 0, 1 },
+ { MV_PMODE_INTFR_2MV_FIELD, 0, 0, 1 },
+ { MV_PMODE_INTFR_2MV_FIELD, 1, 0, 1 },
+ { MV_PMODE_INTFR_2MV_FIELD, 0, 0, 0 },
+ { MV_PMODE_INTFR_4MV , 0, 0, 1 },
+ { MV_PMODE_INTFR_4MV , 1, 0, 1 },
+ { MV_PMODE_INTFR_4MV , 0, 0, 0 },
+ { MV_PMODE_INTFR_4MV_FIELD, 0, 0, 1 },
+ { MV_PMODE_INTFR_4MV_FIELD, 1, 0, 1 },
+ { MV_PMODE_INTFR_4MV_FIELD, 0, 0, 0 },
+ { MV_PMODE_INTFR_INTRA , 0, 0, 0 }
+ }
};
const int ff_vc1_fps_nr[5] = { 24, 25, 30, 50, 60 },
- ff_vc1_fps_dr[2] = { 1000, 1001 };
+ ff_vc1_fps_dr[2] = { 1000, 1001 };
const uint8_t ff_vc1_pquant_table[3][32] = {
- { /* Implicit quantizer */
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 6, 7, 8, 9, 10, 11, 12,
- 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 27, 29, 31
- },
- { /* Explicit quantizer, pquantizer uniform */
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
- 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31
- },
- { /* Explicit quantizer, pquantizer non-uniform */
- 0, 1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
- 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 29, 31
- }
+ /* Implicit quantizer */
+ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 6, 7, 8, 9, 10, 11, 12,
+ 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 27, 29, 31 },
+ /* Explicit quantizer, pquantizer uniform */
+ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 },
+ /* Explicit quantizer, pquantizer non-uniform */
+ { 0, 1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
+ 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 29, 31 }
};
/** @name VC-1 VLC tables and defines
@@ -84,38 +117,57 @@ VLC ff_vc1_ttmb_vlc[3];
VLC ff_vc1_mv_diff_vlc[4];
#define VC1_CBPCY_P_VLC_BITS 9 //14
VLC ff_vc1_cbpcy_p_vlc[4];
+#define VC1_ICBPCY_VLC_BITS 9
+VLC ff_vc1_icbpcy_vlc[8];
#define VC1_4MV_BLOCK_PATTERN_VLC_BITS 6
VLC ff_vc1_4mv_block_pattern_vlc[4];
+#define VC1_2MV_BLOCK_PATTERN_VLC_BITS 3
+VLC ff_vc1_2mv_block_pattern_vlc[4];
#define VC1_TTBLK_VLC_BITS 5
VLC ff_vc1_ttblk_vlc[3];
#define VC1_SUBBLKPAT_VLC_BITS 6
VLC ff_vc1_subblkpat_vlc[3];
+#define VC1_INTFR_4MV_MBMODE_VLC_BITS 9
+VLC ff_vc1_intfr_4mv_mbmode_vlc[4];
+#define VC1_INTFR_NON4MV_MBMODE_VLC_BITS 6
+VLC ff_vc1_intfr_non4mv_mbmode_vlc[4];
+#define VC1_IF_MMV_MBMODE_VLC_BITS 5
+VLC ff_vc1_if_mmv_mbmode_vlc[8];
+#define VC1_IF_1MV_MBMODE_VLC_BITS 5
+VLC ff_vc1_if_1mv_mbmode_vlc[8];
+#define VC1_1REF_MVDATA_VLC_BITS 9
+VLC ff_vc1_1ref_mvdata_vlc[4];
+#define VC1_2REF_MVDATA_VLC_BITS 9
+VLC ff_vc1_2ref_mvdata_vlc[8];
VLC ff_vc1_ac_coeff_table[8];
+
+#define VC1_IF_MBMODE_VLC_BITS 5 // as a placeholder for VC1_IF_MMV_MBMODE_VLC_BITS
+ // or VC1_IF_1MV_MBMODE_VLC_BITS since they are the same
//@}
-#if B_FRACTION_DEN==840 //original bfraction from vc9data.h, not conforming to standard
+#if B_FRACTION_DEN == 840 // original bfraction from vc9data.h, not conforming to standard
/* bfraction is fractional, we scale to the GCD 3*5*7*8 = 840 */
const int16_t ff_vc1_bfraction_lut[23] = {
- 420 /*1/2*/, 280 /*1/3*/, 560 /*2/3*/, 210 /*1/4*/,
- 630 /*3/4*/, 168 /*1/5*/, 336 /*2/5*/,
- 504 /*3/5*/, 672 /*4/5*/, 140 /*1/6*/, 700 /*5/6*/,
- 120 /*1/7*/, 240 /*2/7*/, 360 /*3/7*/, 480 /*4/7*/,
- 600 /*5/7*/, 720 /*6/7*/, 105 /*1/8*/, 315 /*3/8*/,
- 525 /*5/8*/, 735 /*7/8*/,
- -1 /*inv.*/, 0 /*BI fm*/
+ 420 /*1/2*/, 280 /*1/3*/, 560 /*2/3*/, 210 /*1/4*/,
+ 630 /*3/4*/, 168 /*1/5*/, 336 /*2/5*/,
+ 504 /*3/5*/, 672 /*4/5*/, 140 /*1/6*/, 700 /*5/6*/,
+ 120 /*1/7*/, 240 /*2/7*/, 360 /*3/7*/, 480 /*4/7*/,
+ 600 /*5/7*/, 720 /*6/7*/, 105 /*1/8*/, 315 /*3/8*/,
+ 525 /*5/8*/, 735 /*7/8*/,
+ -1 /*inv.*/, 0 /*BI fm*/
};
#else
/* pre-computed scales for all bfractions and base=256 */
const int16_t ff_vc1_bfraction_lut[23] = {
- 128 /*1/2*/, 85 /*1/3*/, 170 /*2/3*/, 64 /*1/4*/,
- 192 /*3/4*/, 51 /*1/5*/, 102 /*2/5*/,
- 153 /*3/5*/, 204 /*4/5*/, 43 /*1/6*/, 215 /*5/6*/,
- 37 /*1/7*/, 74 /*2/7*/, 111 /*3/7*/, 148 /*4/7*/,
- 185 /*5/7*/, 222 /*6/7*/, 32 /*1/8*/, 96 /*3/8*/,
- 160 /*5/8*/, 224 /*7/8*/,
- -1 /*inv.*/, 0 /*BI fm*/
+ 128 /*1/2*/, 85 /*1/3*/, 170 /*2/3*/, 64 /*1/4*/,
+ 192 /*3/4*/, 51 /*1/5*/, 102 /*2/5*/,
+ 153 /*3/5*/, 204 /*4/5*/, 43 /*1/6*/, 215 /*5/6*/,
+ 37 /*1/7*/, 74 /*2/7*/, 111 /*3/7*/, 148 /*4/7*/,
+ 185 /*5/7*/, 222 /*6/7*/, 32 /*1/8*/, 96 /*3/8*/,
+ 160 /*5/8*/, 224 /*7/8*/,
+ -1 /*inv.*/, 0 /*BI fm*/
};
#endif
@@ -129,154 +181,477 @@ const uint8_t ff_vc1_bfraction_bits[23] = {
7, 7
};
const uint8_t ff_vc1_bfraction_codes[23] = {
- 0, 1, 2, 3,
- 4, 5, 6,
- 112, 113, 114, 115,
- 116, 117, 118, 119,
- 120, 121, 122, 123,
- 124, 125,
- 126, 127
+ 0, 1, 2, 3,
+ 4, 5, 6,
+ 112, 113, 114, 115,
+ 116, 117, 118, 119,
+ 120, 121, 122, 123,
+ 124, 125,
+ 126, 127
};
//Same as H.264
-const AVRational ff_vc1_pixel_aspect[16]={
- {0, 1},
- {1, 1},
- {12, 11},
- {10, 11},
- {16, 11},
- {40, 33},
- {24, 11},
- {20, 11},
- {32, 11},
- {80, 33},
- {18, 11},
- {15, 11},
- {64, 33},
- {160, 99},
- {0, 1},
- {0, 1}
+const AVRational ff_vc1_pixel_aspect[16] = {
+ { 0, 1 },
+ { 1, 1 },
+ { 12, 11 },
+ { 10, 11 },
+ { 16, 11 },
+ { 40, 33 },
+ { 24, 11 },
+ { 20, 11 },
+ { 32, 11 },
+ { 80, 33 },
+ { 18, 11 },
+ { 15, 11 },
+ { 64, 33 },
+ { 160, 99 },
+ { 0, 1 },
+ { 0, 1 }
};
/* BitPlane IMODE - such a small table... */
const uint8_t ff_vc1_imode_codes[7] = {
- 0, 2, 1, 3, 1, 2, 3
+ 0, 2, 1, 3, 1, 2, 3
};
const uint8_t ff_vc1_imode_bits[7] = {
- 4, 2, 3, 2, 4, 3, 3
+ 4, 2, 3, 2, 4, 3, 3
};
/* Normal-2 imode */
const uint8_t ff_vc1_norm2_codes[4] = {
- 0, 4, 5, 3
+ 0, 4, 5, 3
};
const uint8_t ff_vc1_norm2_bits[4] = {
- 1, 3, 3, 2
+ 1, 3, 3, 2
};
const uint16_t ff_vc1_norm6_codes[64] = {
-0x001, 0x002, 0x003, 0x000, 0x004, 0x001, 0x002, 0x047, 0x005, 0x003, 0x004, 0x04B, 0x005, 0x04D, 0x04E, 0x30E,
-0x006, 0x006, 0x007, 0x053, 0x008, 0x055, 0x056, 0x30D, 0x009, 0x059, 0x05A, 0x30C, 0x05C, 0x30B, 0x30A, 0x037,
-0x007, 0x00A, 0x00B, 0x043, 0x00C, 0x045, 0x046, 0x309, 0x00D, 0x049, 0x04A, 0x308, 0x04C, 0x307, 0x306, 0x036,
-0x00E, 0x051, 0x052, 0x305, 0x054, 0x304, 0x303, 0x035, 0x058, 0x302, 0x301, 0x034, 0x300, 0x033, 0x032, 0x007,
+ 0x001, 0x002, 0x003, 0x000, 0x004, 0x001, 0x002, 0x047, 0x005, 0x003, 0x004, 0x04B, 0x005, 0x04D, 0x04E, 0x30E,
+ 0x006, 0x006, 0x007, 0x053, 0x008, 0x055, 0x056, 0x30D, 0x009, 0x059, 0x05A, 0x30C, 0x05C, 0x30B, 0x30A, 0x037,
+ 0x007, 0x00A, 0x00B, 0x043, 0x00C, 0x045, 0x046, 0x309, 0x00D, 0x049, 0x04A, 0x308, 0x04C, 0x307, 0x306, 0x036,
+ 0x00E, 0x051, 0x052, 0x305, 0x054, 0x304, 0x303, 0x035, 0x058, 0x302, 0x301, 0x034, 0x300, 0x033, 0x032, 0x007,
};
const uint8_t ff_vc1_norm6_bits[64] = {
- 1, 4, 4, 8, 4, 8, 8, 10, 4, 8, 8, 10, 8, 10, 10, 13,
- 4, 8, 8, 10, 8, 10, 10, 13, 8, 10, 10, 13, 10, 13, 13, 9,
- 4, 8, 8, 10, 8, 10, 10, 13, 8, 10, 10, 13, 10, 13, 13, 9,
- 8, 10, 10, 13, 10, 13, 13, 9, 10, 13, 13, 9, 13, 9, 9, 6,
-};
-#if 0
-/* Normal-6 imode */
-const uint8_t ff_vc1_norm6_spec[64][5] = {
-{ 0, 1, 1 },
-{ 1, 2, 4 },
-{ 2, 3, 4 },
-{ 3, 0, 8 },
-{ 4, 4, 4 },
-{ 5, 1, 8 },
-{ 6, 2, 8 },
-{ 7, 2, 5, 7, 5 },
-{ 8, 5, 4 },
-{ 9, 3, 8 },
-{10, 4, 8 },
-{11, 2, 5, 11, 5 },
-{12, 5, 8 },
-{13, 2, 5, 13, 5 },
-{14, 2, 5, 14, 5 },
-{15, 3, 5, 14, 8 },
-{16, 6, 4 },
-{17, 6, 8 },
-{18, 7, 8 },
-{19, 2, 5, 19, 5 },
-{20, 8, 8 },
-{21, 2, 5, 21, 5 },
-{22, 2, 5, 22, 5 },
-{23, 3, 5, 13, 8 },
-{24, 9, 8 },
-{25, 2, 5, 25, 5 },
-{26, 2, 5, 26, 5 },
-{27, 3, 5, 12, 8 },
-{28, 2, 5, 28, 5 },
-{29, 3, 5, 11, 8 },
-{30, 3, 5, 10, 8 },
-{31, 3, 5, 7, 4 },
-{32, 7, 4 },
-{33, 10, 8 },
-{34, 11, 8 },
-{35, 2, 5, 3, 5 },
-{36, 12, 8 },
-{37, 2, 5, 5, 5 },
-{38, 2, 5, 6, 5 },
-{39, 3, 5, 9, 8 },
-{40, 13, 8 },
-{41, 2, 5, 9, 5 },
-{42, 2, 5, 10, 5 },
-{43, 3, 5, 8, 8 },
-{44, 2, 5, 12, 5 },
-{45, 3, 5, 7, 8 },
-{46, 3, 5, 6, 8 },
-{47, 3, 5, 6, 4 },
-{48, 14, 8 },
-{49, 2, 5, 17, 5 },
-{50, 2, 5, 18, 5 },
-{51, 3, 5, 5, 8 },
-{52, 2, 5, 20, 5 },
-{53, 3, 5, 4, 8 },
-{54, 3, 5, 3, 8 },
-{55, 3, 5, 5, 4 },
-{56, 2, 5, 24, 5 },
-{57, 3, 5, 2, 8 },
-{58, 3, 5, 1, 8 },
-{59, 3, 5, 4, 4 },
-{60, 3, 5, 0, 8 },
-{61, 3, 5, 3, 4 },
-{62, 3, 5, 2, 4 },
-{63, 3, 5, 1, 1 },
+ 1, 4, 4, 8, 4, 8, 8, 10, 4, 8, 8, 10, 8, 10, 10, 13,
+ 4, 8, 8, 10, 8, 10, 10, 13, 8, 10, 10, 13, 10, 13, 13, 9,
+ 4, 8, 8, 10, 8, 10, 10, 13, 8, 10, 10, 13, 10, 13, 13, 9,
+ 8, 10, 10, 13, 10, 13, 13, 9, 10, 13, 13, 9, 13, 9, 9, 6,
};
-#endif
/* 4MV Block pattern VLC tables */
const uint8_t ff_vc1_4mv_block_pattern_codes[4][16] = {
- { 14, 58, 59, 25, 12, 26, 15, 15, 13, 24, 27, 0, 28, 1, 2, 2},
- { 8, 18, 19, 4, 20, 5, 30, 11, 21, 31, 6, 12, 7, 13, 14, 0},
- { 15, 6, 7, 2, 8, 3, 28, 9, 10, 29, 4, 11, 5, 12, 13, 0},
- { 0, 11, 12, 4, 13, 5, 30, 16, 14, 31, 6, 17, 7, 18, 19, 10}
+ { 14, 58, 59, 25, 12, 26, 15, 15, 13, 24, 27, 0, 28, 1, 2, 2 },
+ { 8, 18, 19, 4, 20, 5, 30, 11, 21, 31, 6, 12, 7, 13, 14, 0 },
+ { 15, 6, 7, 2, 8, 3, 28, 9, 10, 29, 4, 11, 5, 12, 13, 0 },
+ { 0, 11, 12, 4, 13, 5, 30, 16, 14, 31, 6, 17, 7, 18, 19, 10 }
};
const uint8_t ff_vc1_4mv_block_pattern_bits[4][16] = {
- { 5, 6, 6, 5, 5, 5, 5, 4, 5, 5, 5, 3, 5, 3, 3, 2},
- { 4, 5, 5, 4, 5, 4, 5, 4, 5, 5, 4, 4, 4, 4, 4, 2},
- { 4, 4, 4, 4, 4, 4, 5, 4, 4, 5, 4, 4, 4, 4, 4, 3},
- { 2, 4, 4, 4, 4, 4, 5, 5, 4, 5, 4, 5, 4, 5, 5, 4}
+ { 5, 6, 6, 5, 5, 5, 5, 4, 5, 5, 5, 3, 5, 3, 3, 2 },
+ { 4, 5, 5, 4, 5, 4, 5, 4, 5, 5, 4, 4, 4, 4, 4, 2 },
+ { 4, 4, 4, 4, 4, 4, 5, 4, 4, 5, 4, 4, 4, 4, 4, 3 },
+ { 2, 4, 4, 4, 4, 4, 5, 5, 4, 5, 4, 5, 4, 5, 5, 4 }
+};
+
+/* 2MV Block pattern VLC tables */
+const uint8_t ff_vc1_2mv_block_pattern_codes[4][4] = {
+ { 2, 1, 0, 3 }, { 1, 0, 2, 3 }, { 2, 0, 3, 1 }, { 1, 3, 2, 0 }
+};
+
+const uint8_t ff_vc1_2mv_block_pattern_bits[4][4] = {
+ { 2, 2, 2, 2 }, { 1, 2, 3, 3 }, { 3, 2, 3, 1 }, { 1, 3, 3, 2 }
+};
+
+/* Interlaced frame picture 4MV MBMODE VLC tables (p. 246, p. 360) */
+const uint16_t ff_vc1_intfr_4mv_mbmode_codes[4][15] = {
+ { 22, 17, 0, 47, 32, 10, 1, 3, 67, 133, 132, 92, 19, 93, 18 },
+ { 3, 45, 0, 7, 23, 6, 1, 2, 10, 39, 44, 8, 18, 77, 76 },
+ { 15, 6, 28, 9, 41, 6, 2, 15, 14, 8, 40, 29, 0, 21, 11 },
+ { 7, 198, 1, 2, 193, 13, 25, 0, 97, 1599, 98, 398, 798, 192, 1598 }
+};
+
+const uint8_t ff_vc1_intfr_4mv_mbmode_bits[4][15] = {
+ { 5, 5, 2, 6, 6, 4, 2, 2, 7, 8, 8, 7, 5, 7, 5 },
+ { 3, 6, 3, 3, 5, 3, 3, 3, 4, 6, 6, 4, 5, 7, 7 },
+ { 4, 3, 5, 5, 7, 4, 2, 5, 5, 5, 7, 5, 2, 6, 5 },
+ { 4, 9, 1, 3, 9, 5, 6, 2, 8, 12, 8, 10, 11, 9, 12 }
+};
+
+/* Interlaced frame picture NON-4MV MBMODE VLC tables (p. 363) */
+const uint8_t ff_vc1_intfr_non4mv_mbmode_codes[4][9] = {
+ { 9, 22, 0, 17, 16, 10, 1, 3, 23 },
+ { 7, 0, 5, 2, 1, 1, 6, 3, 4 },
+ { 1, 0, 10, 23, 44, 8, 3, 9, 45 },
+ { 7, 97, 1, 2, 49, 13, 25, 0, 96 }
+};
+
+const uint8_t ff_vc1_intfr_non4mv_mbmode_bits[4][9] = {
+ { 4, 5, 2, 5, 5, 4, 2, 2, 5 },
+ { 3, 4, 6, 2, 3, 2, 3, 5, 6 },
+ { 2, 2, 4, 5, 6, 4, 2, 4, 6 },
+ { 4, 8, 1, 3, 7, 5, 6, 2, 8 }
+};
+
+/* Interlaced field picture MBMODE VLC tables (p. 356 - 11.4.1, 11.4.2) */
+/* mixed-MV */
+const uint8_t ff_vc1_if_mmv_mbmode_codes[8][8] = {
+ { 16, 17, 3, 3, 0, 5, 9, 2 },
+ { 8, 9, 3, 6, 7, 0, 5, 2 },
+ { 16, 17, 5, 3, 0, 3, 9, 2 },
+ { 56, 57, 15, 4, 5, 6, 29, 0 },
+ { 52, 53, 27, 14, 15, 2, 12, 0 },
+ { 56, 57, 29, 5, 6, 0, 15, 4 },
+ { 16, 17, 6, 7, 0, 1, 9, 5 },
+ { 56, 57, 0, 5, 6, 29, 4, 15 }
+};
+const uint8_t ff_vc1_if_mmv_mbmode_bits[8][8] = {
+ { 6, 6, 2, 3, 2, 4, 5, 2 },
+ { 5, 5, 3, 3, 3, 2, 4, 2 },
+ { 6, 6, 4, 3, 2, 2, 5, 2 },
+ { 6, 6, 4, 3, 3, 3, 5, 1 },
+ { 6, 6, 5, 4, 4, 2, 4, 1 },
+ { 6, 6, 5, 3, 3, 1, 4, 3 },
+ { 5, 5, 3, 3, 2, 2, 4, 3 },
+ { 6, 6, 1, 3, 3, 5, 3, 4 }
+};
+/* 1MV */
+const uint8_t ff_vc1_if_1mv_mbmode_codes[8][6] = {
+ { 0, 1, 1, 1, 1, 1 },
+ { 0, 1, 1, 1, 1, 1 },
+ { 16, 17, 3, 0, 9, 5 },
+ { 20, 21, 3, 11, 0, 4 },
+ { 4, 5, 2, 3, 3, 0 },
+ { 4, 5, 3, 2, 0, 3 },
+ { 0, 1, 1, 1, 1, 1 },
+ { 16, 17, 9, 5, 3, 0 }
+};
+const uint8_t ff_vc1_if_1mv_mbmode_bits[8][6] = {
+ { 5, 5, 1, 3, 2, 4 },
+ { 5, 5, 1, 2, 3, 4 },
+ { 5, 5, 2, 1, 4, 3 },
+ { 5, 5, 2, 4, 1, 3 },
+ { 4, 4, 2, 3, 2, 2 },
+ { 4, 4, 3, 2, 2, 2 },
+ { 5, 5, 3, 4, 1, 2 },
+ { 5, 5, 4, 3, 2, 1 }
+};
+
+/* Interlaced frame/field picture MVDATA VLC tables */
+
+/* 1-reference tables */
+const uint32_t ff_vc1_1ref_mvdata_codes[4][72] = { /* uint32_t may be too big */
+ {
+ 0x00005, 0x0000C, 0x0001E, 0x00012, 0x0000C, 0x00034, 0x00075, 0x00070,
+ 0x00000, 0x00008, 0x0001B, 0x00008, 0x0001D, 0x0007C, 0x000D6, 0x001DE,
+ 0x001AF, 0x00005, 0x0001B, 0x00026, 0x0001E, 0x00012, 0x00076, 0x0004D,
+ 0x001F6, 0x001F4, 0x00039, 0x0007F, 0x00027, 0x0006A, 0x00071, 0x00035,
+ 0x00071, 0x00068, 0x001DC, 0x00027, 0x00073, 0x000FF, 0x000E8, 0x000E9,
+ 0x0007E, 0x001F9, 0x001F5, 0x001FD, 0x0003E, 0x001CA, 0x003F9, 0x0004C,
+ 0x00069, 0x001FA, 0x001DF, 0x001F7, 0x00070, 0x001DD, 0x00E4D, 0x00727,
+ 0x00392, 0x001C8, 0x001CB, 0x003F8, 0x001AE, 0x001F8, 0x001FB, 0x0E4CE,
+ 0x0E4CF, 0x07260, 0x07261, 0x07262, 0x07263, 0x07264, 0x07265, 0x07266
+ },
+ {
+ 0x00007, 0x00001, 0x00007, 0x00016, 0x00001, 0x00045, 0x00018, 0x002B6,
+ 0x00006, 0x00004, 0x00017, 0x00010, 0x00029, 0x0002C, 0x0015A, 0x00066,
+ 0x0019E, 0x00009, 0x00028, 0x00017, 0x00000, 0x0002A, 0x00004, 0x0005B,
+ 0x000B5, 0x000CE, 0x00006, 0x00044, 0x0000F, 0x00046, 0x0000E, 0x000AC,
+ 0x00032, 0x00037, 0x011EB, 0x0000A, 0x0001A, 0x0011F, 0x00016, 0x00014,
+ 0x0002B, 0x00168, 0x00055, 0x023D5, 0x00057, 0x0002F, 0x00036, 0x0002E,
+ 0x00169, 0x00054, 0x0047B, 0x0019F, 0x02B7D, 0x0008E, 0x00ADE, 0x00479,
+ 0x0056E, 0x008F4, 0x015BF, 0x00478, 0x023D4, 0x0ADF1, 0x056F9, 0xADF0E,
+ 0xADF0F, 0x56F80, 0x56F81, 0x56F82, 0x56F83, 0x56F84, 0x56F85, 0x56F86
+ },
+ {
+ 0x00002, 0x00006, 0x00007, 0x0000D, 0x00007, 0x00030, 0x000FF, 0x001F0,
+ 0x00002, 0x00000, 0x00005, 0x00019, 0x0001E, 0x00007, 0x00063, 0x000FD,
+ 0x00023, 0x0000E, 0x0001B, 0x0001A, 0x00006, 0x00009, 0x00018, 0x000C5,
+ 0x00033, 0x001F1, 0x00002, 0x003FB, 0x001F3, 0x00022, 0x001FC, 0x00042,
+ 0x00623, 0x00083, 0x00620, 0x0007D, 0x00040, 0x00043, 0x003E4, 0x003E5,
+ 0x00191, 0x00FE9, 0x00105, 0x00208, 0x000FC, 0x00624, 0x00622, 0x00190,
+ 0x00626, 0x007F5, 0x00C4B, 0x01FD0, 0x0104D, 0x00065, 0x00C42, 0x000C9,
+ 0x00627, 0x00C43, 0x00C4A, 0x0104E, 0x01FD1, 0x0104F, 0x00412, 0x104CE,
+ 0x104CF, 0x08260, 0x08261, 0x08262, 0x08263, 0x08264, 0x08265, 0x08266
+ },
+ {
+ 0x0000D, 0x00001, 0x00004, 0x00000, 0x00017, 0x00005, 0x0007F, 0x0004D,
+ 0x00003, 0x00011, 0x0003E, 0x0003B, 0x00017, 0x00067, 0x0004A, 0x000C3,
+ 0x000F2, 0x0000A, 0x0002C, 0x00032, 0x0003D, 0x00015, 0x00028, 0x00093,
+ 0x000CC, 0x00096, 0x00003, 0x00075, 0x00020, 0x0002D, 0x00021, 0x00029,
+ 0x00090, 0x001D0, 0x001FB, 0x0001C, 0x0004C, 0x00060, 0x00009, 0x00008,
+ 0x0002D, 0x0009F, 0x001FA, 0x0013D, 0x00031, 0x000FC, 0x00058, 0x00092,
+ 0x000F0, 0x000F1, 0x000CD, 0x00185, 0x00165, 0x0004E, 0x00091, 0x000E9,
+ 0x00184, 0x001D1, 0x001E6, 0x00097, 0x001E7, 0x000B3, 0x0013C, 0x0164E,
+ 0x0164F, 0x00B20, 0x00B21, 0x00B22, 0x00B23, 0x00B24, 0x00B25, 0x00B26
+ }
};
-const uint8_t wmv3_dc_scale_table[32]={
- 0, 2, 4, 8, 8, 8, 9, 9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,18,18,19,19,20,20,21,21
+const uint8_t ff_vc1_1ref_mvdata_bits[4][72] = {
+ {
+ 3, 4, 5, 5, 5, 6, 7, 7, 2, 4, 5, 5, 6, 7, 8, 9, 9, 4,
+ 6, 6, 6, 6, 7, 8, 9, 9, 6, 8, 7, 7, 7, 7, 8, 8, 9, 6,
+ 8, 8, 8, 8, 8, 9, 9, 9, 7, 10, 10, 8, 8, 9, 9, 9, 8, 9,
+ 13, 12, 11, 10, 10, 10, 9, 9, 9, 17, 17, 16, 16, 16, 16, 16, 16, 16
+ },
+ {
+ 3, 3, 4, 5, 5, 7, 8, 10, 3, 4, 5, 5, 6, 7, 9, 10, 12, 4,
+ 6, 6, 5, 6, 6, 8, 9, 11, 4, 7, 7, 7, 7, 8, 9, 9, 13, 5,
+ 8, 9, 8, 8, 9, 10, 10, 14, 7, 9, 9, 9, 10, 10, 11, 12, 14, 8,
+ 12, 11, 11, 12, 13, 11, 14, 16, 15, 20, 20, 19, 19, 19, 19, 19, 19, 19
+ },
+ {
+ 3, 4, 4, 4, 5, 6, 8, 9, 2, 4, 5, 5, 5, 6, 7, 8, 8, 4,
+ 7, 7, 6, 6, 7, 8, 8, 9, 5, 10, 9, 8, 9, 9, 11, 10, 11, 7,
+ 9, 9, 10, 10, 11, 12, 11, 12, 8, 11, 11, 11, 11, 11, 12, 13, 15, 9,
+ 12, 10, 11, 12, 12, 15, 13, 15, 13, 19, 19, 18, 18, 18, 18, 18, 18, 18
+ },
+ {
+ 4, 4, 4, 4, 5, 5, 7, 7, 3, 5, 6, 6, 6, 7, 7, 8, 8, 4,
+ 6, 6, 6, 6, 7, 8, 8, 8, 4, 7, 6, 6, 6, 7, 8, 9, 9, 5,
+ 7, 7, 6, 6, 7, 8, 9, 9, 6, 8, 8, 8, 8, 8, 8, 9, 10, 7,
+ 8, 8, 9, 9, 9, 8, 9, 9, 9, 14, 14, 13, 13, 13, 13, 13, 13, 13
+ }
+};
+
+/* 2-reference tables */
+const uint32_t ff_vc1_2ref_mvdata_codes[8][126] = { /* table 132 - table 139 */
+ {
+ 0x0000C, 0x0001C, 0x0000B, 0x00000, 0x0000E, 0x0002A, 0x00050, 0x00368,
+ 0x00002, 0x0001A, 0x00004, 0x0003A, 0x0001D, 0x0006C, 0x000EF, 0x001BC,
+ 0x0015F, 0x0000F, 0x00003, 0x0001C, 0x0000D, 0x0000B, 0x0003E, 0x000A7,
+ 0x00146, 0x00199, 0x00006, 0x0001F, 0x00004, 0x0003C, 0x00007, 0x001BE,
+ 0x0008B, 0x0002C, 0x007B3, 0x00005, 0x000DB, 0x00056, 0x000EC, 0x00052,
+ 0x001BD, 0x00078, 0x000CF, 0x00573, 0x00009, 0x00023, 0x000ED, 0x00018,
+ 0x00006, 0x00044, 0x000F5, 0x00079, 0x006D2, 0x0006E, 0x0002B, 0x0015D,
+ 0x00017, 0x0037F, 0x00144, 0x000CE, 0x00028, 0x000AB, 0x00010, 0x001B5,
+ 0x000F7, 0x000A6, 0x0007B, 0x00028, 0x001ED, 0x001E9, 0x006FD, 0x00004,
+ 0x000F5, 0x00029, 0x0028A, 0x0028B, 0x0028F, 0x00DF9, 0x00335, 0x01E85,
+ 0x000EE, 0x002BD, 0x0002B, 0x003D8, 0x003D1, 0x00198, 0x001E9, 0x0051D,
+ 0x000B4, 0x0003F, 0x00455, 0x0022B, 0x00229, 0x00451, 0x00578, 0x007B2,
+ 0x00570, 0x00155, 0x00032, 0x003D0, 0x00054, 0x006D3, 0x00571, 0x00454,
+ 0x00334, 0x01BF1, 0x000B7, 0x00029, 0x01E84, 0x0016C, 0x0019B, 0x01BF0,
+ 0x00579, 0x00F43, 0x000B5, 0x008A1, 0x0002A, 0x0016D, 0x008A0, 0x007A0,
+ 0x003D1, 0x00AE5, 0x00154, 0x00AE4, 0x00A39, 0x00A38
+ },
+ {
+ 0x00003, 0x00009, 0x00016, 0x00010, 0x000D7, 0x00335, 0x00574, 0x00555,
+ 0x00000, 0x0001D, 0x00009, 0x00017, 0x0002C, 0x000AD, 0x00374, 0x006B3,
+ 0x00577, 0x0000F, 0x00018, 0x0000A, 0x0002E, 0x00022, 0x0017C, 0x00E7B,
+ 0x01B89, 0x015D8, 0x00008, 0x00034, 0x0006D, 0x00023, 0x001C2, 0x00376,
+ 0x002D3, 0x01C4A, 0x0330A, 0x00014, 0x0006A, 0x00072, 0x0006C, 0x000E3,
+ 0x0019B, 0x0073F, 0x01CF0, 0x00B41, 0x00032, 0x000E6, 0x000E0, 0x000CF,
+ 0x000AB, 0x0019C, 0x002AB, 0x00E2B, 0x015D9, 0x0006F, 0x001C3, 0x000AF,
+ 0x000BF, 0x000AC, 0x0017D, 0x006E3, 0x00E29, 0x01984, 0x00054, 0x000B5,
+ 0x0017A, 0x001AD, 0x00199, 0x00178, 0x00358, 0x002D2, 0x01C4B, 0x0005B,
+ 0x002A8, 0x00331, 0x00388, 0x0038B, 0x00370, 0x00713, 0x00CC3, 0x01CF1,
+ 0x001B9, 0x005EF, 0x00738, 0x002F2, 0x0033B, 0x002B9, 0x006EB, 0x00570,
+ 0x00E24, 0x0039D, 0x005A2, 0x005A3, 0x00E7D, 0x005EE, 0x00739, 0x00554,
+ 0x00AA5, 0x00AA4, 0x00377, 0x01CF5, 0x00BCE, 0x00E79, 0x00660, 0x00674,
+ 0x006EA, 0x00E7C, 0x00D65, 0x002F6, 0x015DA, 0x01B88, 0x005A1, 0x01CF4,
+ 0x005E6, 0x00E28, 0x00575, 0x00D64, 0x00334, 0x0330B, 0x015DB, 0x00B40,
+ 0x00BCF, 0x00DC5, 0x00E2A, 0x00675, 0x00571, 0x00553
+ },
+ {
+ 0x00004, 0x00002, 0x00010, 0x00003, 0x00017, 0x00045, 0x0003E, 0x0007E,
+ 0x00003, 0x00002, 0x00028, 0x0001E, 0x00015, 0x00047, 0x00002, 0x0014D,
+ 0x00060, 0x0000B, 0x00026, 0x00024, 0x00014, 0x00032, 0x0006F, 0x000C3,
+ 0x00531, 0x006E5, 0x00015, 0x0003F, 0x0002D, 0x00001, 0x0013E, 0x000DD,
+ 0x000F6, 0x00305, 0x00331, 0x0000E, 0x00003, 0x00034, 0x00033, 0x0001A,
+ 0x0014A, 0x000C5, 0x000F4, 0x006E4, 0x00001, 0x0003C, 0x0007D, 0x0008D,
+ 0x0009D, 0x00031, 0x0006E, 0x00296, 0x000CD, 0x00025, 0x00149, 0x00032,
+ 0x00089, 0x00036, 0x00088, 0x0006F, 0x00003, 0x0031D, 0x0000E, 0x001AA,
+ 0x0027E, 0x00061, 0x0014E, 0x0014F, 0x00067, 0x000FF, 0x00183, 0x00036,
+ 0x00357, 0x000F5, 0x000C6, 0x000C2, 0x00299, 0x00119, 0x00231, 0x00350,
+ 0x0002C, 0x0018F, 0x00530, 0x00297, 0x00004, 0x001B8, 0x000C0, 0x0027A,
+ 0x00311, 0x0009C, 0x00621, 0x00199, 0x0031C, 0x000F7, 0x003E3, 0x00356,
+ 0x00189, 0x00005, 0x0006B, 0x008C2, 0x00330, 0x004FF, 0x004F0, 0x00351,
+ 0x004F2, 0x001F2, 0x00373, 0x00000, 0x00C41, 0x008C3, 0x009EC, 0x003E2,
+ 0x00304, 0x004F7, 0x004F1, 0x001F0, 0x00148, 0x00C40, 0x009ED, 0x008C0,
+ 0x008C1, 0x004F3, 0x004FE, 0x000FE, 0x001F3, 0x001A9
+ },
+ {
+ 0x00000, 0x00004, 0x0002F, 0x00052, 0x00010, 0x000AD, 0x0050B, 0x00190,
+ 0x00003, 0x00016, 0x00007, 0x0000D, 0x000BB, 0x00173, 0x000C9, 0x0050F,
+ 0x0172C, 0x00003, 0x00011, 0x00005, 0x00043, 0x00023, 0x0004B, 0x0032E,
+ 0x02E5B, 0x00482, 0x00009, 0x0002A, 0x00014, 0x0002A, 0x00108, 0x005CA,
+ 0x0065A, 0x02136, 0x02132, 0x0000B, 0x00013, 0x00041, 0x000B8, 0x00174,
+ 0x00100, 0x014DA, 0x0404E, 0x01437, 0x0002B, 0x00085, 0x000A7, 0x000A0,
+ 0x0014C, 0x0029A, 0x0032C, 0x02133, 0x0142A, 0x00051, 0x00284, 0x000AC,
+ 0x00102, 0x00045, 0x00044, 0x0081B, 0x0065E, 0x00CB7, 0x00018, 0x0050C,
+ 0x00212, 0x002E4, 0x00203, 0x00094, 0x00122, 0x0081A, 0x00655, 0x00033,
+ 0x002BA, 0x00246, 0x00242, 0x00A6E, 0x0040C, 0x00808, 0x02134, 0x0404F,
+ 0x00175, 0x00405, 0x00247, 0x0012A, 0x00A14, 0x002BB, 0x00191, 0x0084F,
+ 0x01438, 0x000AF, 0x00B97, 0x00483, 0x0143B, 0x0032B, 0x00243, 0x0142B,
+ 0x00958, 0x029BF, 0x00049, 0x00A6C, 0x014DB, 0x004AD, 0x014DE, 0x0084E,
+ 0x01434, 0x00257, 0x02E5A, 0x00207, 0x01435, 0x01439, 0x00CB6, 0x0143A,
+ 0x00194, 0x00654, 0x02135, 0x0537C, 0x0015C, 0x00240, 0x01012, 0x0537D,
+ 0x00959, 0x01098, 0x01436, 0x0065F, 0x02026, 0x02137
+ },
+ {
+ 0x00005, 0x00019, 0x00016, 0x00011, 0x0003E, 0x0005E, 0x000EF, 0x000E2,
+ 0x00000, 0x00039, 0x0002B, 0x00026, 0x00028, 0x00012, 0x000C2, 0x000ED,
+ 0x0011D, 0x0000D, 0x00031, 0x0002A, 0x00025, 0x00020, 0x0005C, 0x001ED,
+ 0x0024D, 0x00770, 0x00006, 0x0007A, 0x00060, 0x0004F, 0x00048, 0x00039,
+ 0x00186, 0x00213, 0x00EC6, 0x0000F, 0x00026, 0x0005F, 0x00075, 0x00070,
+ 0x00027, 0x001DB, 0x003C6, 0x0078F, 0x0003F, 0x000A6, 0x000F0, 0x0003A,
+ 0x00052, 0x0004E, 0x000E3, 0x001D9, 0x0030F, 0x00010, 0x001DD, 0x000A7,
+ 0x000F7, 0x00022, 0x00092, 0x003C4, 0x002EF, 0x00762, 0x00079, 0x0008F,
+ 0x001DA, 0x00087, 0x000E8, 0x000BA, 0x00176, 0x000EE, 0x003B0, 0x00085,
+ 0x00119, 0x0030E, 0x00108, 0x001D2, 0x0010C, 0x00773, 0x00424, 0x00434,
+ 0x00071, 0x005DD, 0x001C1, 0x003A7, 0x00127, 0x0008D, 0x0021B, 0x007B2,
+ 0x001DF, 0x003D8, 0x00764, 0x00EE4, 0x003B3, 0x0074D, 0x001D8, 0x005DC,
+ 0x0084A, 0x00499, 0x003C5, 0x01D8E, 0x00765, 0x00435, 0x00771, 0x001C2,
+ 0x00118, 0x003BC, 0x00381, 0x00387, 0x07B33, 0x01097, 0x01096, 0x01ECD,
+ 0x00E99, 0x00F1C, 0x00F1D, 0x00EE5, 0x0011C, 0x07B32, 0x03D98, 0x01D8F,
+ 0x00E98, 0x00F67, 0x003BD, 0x00380, 0x00498, 0x00386
+ },
+ {
+ 0x0000D, 0x00010, 0x0002E, 0x00039, 0x0000D, 0x00074, 0x000ED, 0x000B6,
+ 0x00001, 0x00002, 0x00000, 0x00030, 0x00029, 0x00070, 0x000F3, 0x0008C,
+ 0x00166, 0x00009, 0x00033, 0x00078, 0x00006, 0x000C4, 0x0000B, 0x00163,
+ 0x000CC, 0x005BE, 0x0001F, 0x0002F, 0x00064, 0x00018, 0x000C6, 0x0000A,
+ 0x00162, 0x002C0, 0x00EF3, 0x00007, 0x0000F, 0x000E3, 0x000CA, 0x000B2,
+ 0x0018F, 0x003AE, 0x0075F, 0x00C51, 0x00015, 0x00047, 0x000EE, 0x000E2,
+ 0x000EA, 0x00009, 0x0016A, 0x002C3, 0x0059D, 0x0003D, 0x00008, 0x001D9,
+ 0x00032, 0x0000E, 0x0016E, 0x0032C, 0x0065B, 0x0196B, 0x00002, 0x0000F,
+ 0x001D8, 0x0008D, 0x000B4, 0x001E4, 0x00067, 0x00317, 0x00794, 0x00022,
+ 0x003BE, 0x00315, 0x00034, 0x00037, 0x002DE, 0x0006C, 0x00EFE, 0x0066C,
+ 0x00028, 0x003CB, 0x003AC, 0x00035, 0x0016B, 0x003BD, 0x002C1, 0x0062C,
+ 0x01DFE, 0x0000E, 0x0059E, 0x005BF, 0x000DA, 0x00629, 0x00584, 0x00EB7,
+ 0x00B0A, 0x0066D, 0x0000C, 0x0077E, 0x0059C, 0x00778, 0x0075E, 0x0075A,
+ 0x0062D, 0x00337, 0x00334, 0x00197, 0x01E57, 0x01DE4, 0x0196A, 0x01E56,
+ 0x00C50, 0x00B3F, 0x01E54, 0x00B0B, 0x0018E, 0x001B6, 0x01E55, 0x00CB4,
+ 0x00B3E, 0x00EB6, 0x01DE5, 0x01DFF, 0x00335, 0x001B7
+ },
+ {
+ 0x00001, 0x0000B, 0x00019, 0x0006F, 0x0002A, 0x00075, 0x007EB, 0x00163,
+ 0x00001, 0x0000E, 0x0001A, 0x0003E, 0x0001C, 0x0002D, 0x00164, 0x007EC,
+ 0x00165, 0x00004, 0x00006, 0x00036, 0x0007F, 0x000AE, 0x00158, 0x0015C,
+ 0x0056D, 0xFD510, 0x00000, 0x00004, 0x0007B, 0x000F3, 0x0003B, 0x007ED,
+ 0x002B3, 0x002CC, 0x0056E, 0x00018, 0x0003E, 0x00017, 0x0001E, 0x000AF,
+ 0x003F7, 0x0056F, 0x002CD, 0xFD511, 0x00014, 0x000AD, 0x000AA, 0x00014,
+ 0x000A8, 0x00153, 0x000E8, 0x001FE, 0x00DCF, 0x00078, 0x001B8, 0x00152,
+ 0x000FE, 0x002B1, 0x0015D, 0x00160, 0xFD512, 0xFD513, 0x0007A, 0x002B0,
+ 0x001E5, 0x000E9, 0x000FC, 0x006E6, 0x00DC8, 0x00584, 0xFD514, 0x000AB,
+ 0x00DDE, 0x00159, 0x003F4, 0x00DC9, 0x00DCA, 0x001FA, 0xFD515, 0xFD516,
+ 0x000FC, 0x001FF, 0x001E4, 0x000AF, 0x0015A, 0x00167, 0x00DCB, 0x00585,
+ 0xFD517, 0x003F7, 0x03F55, 0xFD518, 0x00DDC, 0x00586, 0x03F56, 0xFD519,
+ 0x03F57, 0xFD51A, 0x001BA, 0x00587, 0x00588, 0x00DDF, 0x002B2, 0xFD51B,
+ 0x00DCE, 0x003F6, 0xFD51C, 0x00FD4, 0xFD51D, 0xFD51E, 0xFD51F, 0x7EA80,
+ 0x7EA81, 0x0056C, 0x7EA82, 0x7EA83, 0x00376, 0x00589, 0x0058A, 0x7EA84,
+ 0x7EA85, 0x00DDD, 0x7EA86, 0x7EA87, 0x0058B, 0x07EA9
+ },
+ {
+ 0x00003, 0x0000E, 0x0000F, 0x0007E, 0x00062, 0x000C6, 0x00CD9, 0x0063E,
+ 0x00002, 0x00002, 0x00000, 0x00018, 0x0000C, 0x00069, 0x00039, 0x00707,
+ 0x00C7E, 0x00002, 0x0000D, 0x0001B, 0x0000F, 0x0019A, 0x00647, 0x01A37,
+ 0x346C4, 0x0346D, 0x00001, 0x0001E, 0x0007F, 0x0000A, 0x000E1, 0x00661,
+ 0x00CE4, 0x346C5, 0x346C6, 0x0001D, 0x00030, 0x0000D, 0x000CB, 0x00199,
+ 0x00320, 0x0008E, 0x0652E, 0x346C7, 0x0003E, 0x00039, 0x00035, 0x00033,
+ 0x0019F, 0x001C0, 0x00CDA, 0x346C8, 0x346C9, 0x0000B, 0x000D0, 0x0019E,
+ 0x00022, 0x00038, 0x0018E, 0x0031E, 0x03294, 0x0023C, 0x00032, 0x00012,
+ 0x00013, 0x00071, 0x0019D, 0x00020, 0x00C87, 0x00CC0, 0x346CA, 0x00338,
+ 0x00653, 0x001A2, 0x0032A, 0x00322, 0x00CE7, 0x00084, 0x0011F, 0x346CB,
+ 0x00325, 0x00649, 0x0032B, 0x00077, 0x00648, 0x00642, 0x00C86, 0x00C8C,
+ 0x346CC, 0x0003A, 0x019B7, 0x00043, 0x00327, 0x0008C, 0x0008D, 0x00C8D,
+ 0x346CD, 0x346CE, 0x00337, 0x00CE5, 0x00085, 0x00326, 0x00347, 0x00CA4,
+ 0x00C7F, 0x00D1A, 0x346CF, 0x00328, 0x1A360, 0x1A361, 0x00CD8, 0x0068C,
+ 0x03295, 0x03296, 0x0652F, 0x066D8, 0x00331, 0x00706, 0x0023D, 0x00076,
+ 0x00CC1, 0x00382, 0x00CE6, 0x066D9, 0x066DA, 0x066DB
+ }
+};
+
+const uint8_t ff_vc1_2ref_mvdata_bits[8][126] = {
+ {
+ 4, 5, 5, 5, 6, 7, 8, 10, 2, 5, 5, 6, 6, 7, 8, 9,
+ 10, 4, 5, 6, 6, 7, 8, 9, 10, 11, 4, 6, 6, 7, 7, 9,
+ 9, 10, 12, 5, 8, 8, 8, 8, 9, 9, 10, 12, 5, 7, 8, 7,
+ 7, 8, 9, 9, 11, 7, 9, 10, 9, 10, 10, 10, 10, 12, 6, 9,
+ 9, 9, 9, 9, 10, 10, 11, 7, 10, 10, 11, 11, 11, 12, 12, 14,
+ 8, 11, 10, 11, 11, 11, 11, 12, 12, 8, 12, 11, 11, 12, 12, 12,
+ 12, 13, 8, 12, 11, 11, 12, 12, 12, 13, 12, 9, 14, 13, 11, 13,
+ 12, 13, 12, 13, 9, 13, 13, 12, 12, 13, 13, 13, 13, 13
+ },
+ {
+ 3, 4, 5, 6, 8, 10, 11, 11, 2, 5, 5, 6, 7, 8, 10, 11,
+ 11, 4, 5, 5, 6, 7, 9, 12, 13, 13, 4, 6, 7, 7, 9, 10,
+ 11, 13, 14, 5, 7, 7, 7, 8, 9, 11, 13, 13, 6, 8, 8, 8,
+ 8, 9, 10, 12, 13, 7, 9, 8, 8, 8, 9, 11, 12, 13, 7, 9,
+ 9, 9, 9, 9, 10, 11, 13, 8, 10, 10, 10, 10, 10, 11, 12, 13,
+ 9, 11, 11, 10, 10, 10, 11, 11, 12, 10, 12, 12, 12, 11, 11, 11,
+ 12, 12, 10, 13, 12, 12, 11, 11, 11, 12, 12, 10, 13, 13, 12, 13,
+ 11, 12, 11, 12, 10, 14, 13, 13, 12, 12, 12, 11, 11, 11
+ },
+ {
+ 4, 4, 5, 5, 6, 7, 8, 9, 2, 5, 6, 6, 6, 7, 7, 9,
+ 9, 4, 6, 6, 6, 7, 8, 9, 11, 12, 5, 7, 7, 7, 9, 9,
+ 10, 11, 12, 5, 7, 7, 7, 7, 9, 9, 10, 12, 5, 8, 8, 8,
+ 8, 8, 9, 10, 10, 6, 9, 8, 8, 8, 8, 9, 9, 11, 6, 10,
+ 10, 9, 9, 9, 9, 10, 10, 7, 11, 10, 9, 9, 10, 9, 10, 11,
+ 7, 10, 11, 10, 10, 10, 9, 10, 11, 8, 12, 11, 11, 10, 11, 11,
+ 10, 10, 8, 12, 12, 11, 11, 11, 11, 10, 11, 8, 13, 12, 12, 11,
+ 11, 11, 11, 10, 9, 13, 12, 12, 12, 11, 11, 10, 10, 10
+ },
+ {
+ 3, 4, 6, 7, 7, 9, 11, 11, 2, 5, 5, 6, 8, 9, 10, 11,
+ 13, 3, 5, 5, 7, 8, 9, 12, 14, 13, 4, 6, 6, 7, 9, 11,
+ 13, 14, 14, 5, 7, 7, 8, 9, 9, 13, 15, 13, 6, 8, 8, 8,
+ 9, 10, 12, 14, 13, 7, 10, 9, 9, 9, 9, 12, 13, 14, 7, 11,
+ 10, 10, 10, 10, 11, 12, 13, 8, 11, 12, 12, 12, 11, 12, 14, 15,
+ 9, 11, 12, 11, 12, 11, 11, 12, 13, 9, 12, 13, 13, 12, 12, 13,
+ 14, 14, 9, 12, 13, 13, 13, 12, 13, 12, 14, 10, 13, 13, 14, 13,
+ 11, 13, 14, 15, 10, 12, 13, 15, 14, 13, 13, 13, 14, 14
+ },
+ {
+ 4, 5, 5, 5, 6, 7, 8, 8, 2, 6, 6, 6, 6, 6, 8, 9,
+ 10, 4, 6, 6, 6, 6, 7, 9, 10, 11, 4, 7, 7, 7, 7, 7,
+ 9, 10, 12, 5, 7, 7, 7, 7, 7, 9, 10, 11, 6, 8, 8, 7,
+ 7, 7, 8, 9, 10, 6, 9, 8, 8, 7, 8, 10, 10, 11, 7, 9,
+ 9, 8, 8, 8, 9, 9, 10, 8, 10, 10, 9, 9, 9, 11, 11, 11,
+ 8, 11, 10, 10, 9, 9, 10, 11, 10, 10, 12, 12, 11, 11, 10, 11,
+ 12, 11, 10, 13, 12, 11, 11, 10, 10, 11, 11, 11, 15, 13, 13, 13,
+ 12, 12, 12, 12, 10, 15, 14, 13, 12, 12, 11, 11, 11, 11
+ },
+ {
+ 4, 5, 6, 6, 6, 7, 8, 8, 2, 4, 5, 6, 6, 7, 8, 8,
+ 9, 4, 6, 7, 7, 8, 8, 9, 10, 11, 5, 6, 7, 7, 8, 8,
+ 9, 10, 12, 5, 7, 8, 8, 8, 9, 10, 11, 12, 5, 7, 8, 8,
+ 8, 8, 9, 10, 11, 6, 8, 9, 8, 8, 9, 10, 11, 13, 5, 8,
+ 9, 8, 8, 9, 9, 10, 11, 6, 10, 10, 9, 9, 10, 10, 12, 13,
+ 6, 10, 10, 9, 9, 10, 10, 11, 13, 7, 11, 11, 11, 11, 11, 12,
+ 12, 13, 7, 11, 11, 11, 11, 11, 11, 12, 12, 9, 13, 13, 13, 13,
+ 12, 12, 13, 12, 9, 12, 13, 12, 12, 12, 13, 13, 12, 12
+ },
+ {
+ 3, 5, 6, 8, 9, 10, 12, 12, 1, 5, 6, 7, 8, 9, 12, 12,
+ 12, 4, 6, 7, 8, 9, 12, 12, 14, 21, 4, 6, 8, 9, 9, 12,
+ 13, 13, 14, 6, 9, 8, 8, 9, 13, 14, 13, 21, 6, 9, 9, 8,
+ 9, 10, 11, 12, 13, 8, 10, 10, 11, 11, 12, 12, 21, 21, 8, 11,
+ 10, 11, 11, 12, 13, 14, 21, 9, 13, 10, 11, 13, 13, 12, 21, 21,
+ 9, 12, 10, 11, 12, 12, 13, 14, 21, 11, 15, 21, 13, 14, 15, 21,
+ 15, 21, 10, 14, 14, 13, 13, 21, 13, 13, 21, 13, 21, 21, 21, 20,
+ 20, 14, 20, 20, 11, 14, 14, 20, 20, 13, 20, 20, 14, 16
+ },
+ {
+ 2, 5, 6, 8, 9, 10, 13, 13, 2, 4, 5, 6, 8, 9, 10, 13,
+ 14, 3, 5, 7, 8, 10, 12, 15, 20, 16, 4, 6, 8, 8, 10, 12,
+ 13, 20, 20, 7, 8, 8, 9, 10, 11, 12, 16, 20, 7, 8, 8, 8,
+ 10, 11, 13, 20, 20, 8, 10, 10, 10, 10, 11, 12, 15, 14, 8, 9,
+ 9, 9, 10, 10, 13, 13, 20, 11, 12, 11, 11, 11, 13, 12, 13, 20,
+ 11, 12, 11, 11, 12, 12, 13, 13, 20, 10, 14, 11, 11, 12, 12, 13,
+ 20, 20, 11, 13, 12, 11, 12, 13, 14, 14, 20, 11, 19, 19, 13, 13,
+ 15, 15, 16, 16, 11, 13, 14, 11, 13, 12, 13, 16, 16, 16
+ }
+};
+
+const uint8_t wmv3_dc_scale_table[32] = {
+ 0, 2, 4, 8, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13,
+ 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21
};
/* P-Picture CBPCY VLC tables */
-#if 1 // Looks like original tables are not conforming to standard at all. Are they used for old WMV?
+// Looks like original tables are not conforming to standard at all. Are they used for old WMV?
const uint16_t ff_vc1_cbpcy_p_codes[4][64] = {
{
0, 6, 15, 13, 13, 11, 3, 13, 5, 8, 49, 10, 12, 114, 102, 119,
@@ -330,60 +705,141 @@ const uint8_t ff_vc1_cbpcy_p_bits[4][64] = {
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8
}
};
-#else
-const uint16_t ff_vc1_cbpcy_p_codes[4][64] = {
+
+/* Interlaced CBPCY VLC tables (Table 124 - Table 131) */
+const uint16_t ff_vc1_icbpcy_p_codes[8][63] = {
{
- 0, 1, 1, 4, 5, 1, 12, 4, 13, 14, 10, 11, 12, 7, 13, 2,
- 15, 1, 96, 1, 49, 97, 2, 100, 3, 4, 5, 101, 102, 52, 53, 4,
- 6, 7, 54, 103, 8, 9, 10, 110, 11, 12, 111, 56, 114, 58, 115, 5,
- 13, 7, 8, 9, 10, 11, 12, 30, 13, 14, 15, 118, 119, 62, 63, 3
+ 0x2F1A, 0x2F1B, 0x178C, 0x0090, 0x02A8, 0x02A9, 0x0BC7, 0x0091,
+ 0x02AA, 0x02AB, 0x05E0, 0x004A, 0x0096, 0x0097, 0x00BD, 0x0092,
+ 0x02AC, 0x02AD, 0x05E1, 0x0098, 0x0132, 0x0133, 0x0179, 0x0134,
+ 0x026A, 0x026B, 0x02FC, 0x004E, 0x0040, 0x0041, 0x002B, 0x0093,
+ 0x02AE, 0x02AF, 0x05E2, 0x0136, 0x026E, 0x026F, 0x02FD, 0x009E,
+ 0x013E, 0x013F, 0x017F, 0x0050, 0x0042, 0x0043, 0x002C, 0x0051,
+ 0x00A4, 0x00A5, 0x00BE, 0x0053, 0x0044, 0x0045, 0x002D, 0x0054,
+ 0x0046, 0x0047, 0x002E, 0x0003, 0x0000, 0x0001, 0x0001
},
{
- 0, 1, 2, 1, 3, 1, 16, 17, 5, 18, 12, 19, 13, 1, 28, 58,
- 1, 1, 1, 2, 3, 2, 3, 236, 237, 4, 5, 238, 6, 7, 239, 8,
- 9, 240, 10, 11, 121, 122, 12, 13, 14, 15, 241, 246, 16, 17, 124, 63,
- 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 247, 125
+ 0x0041, 0x0042, 0x0100, 0x0043, 0x0088, 0x0089, 0x0101, 0x0045,
+ 0x008C, 0x008D, 0x0102, 0x0010, 0x0022, 0x0023, 0x0024, 0x0047,
+ 0x0010, 0x0011, 0x0103, 0x0025, 0x0058, 0x0059, 0x005A, 0x005B,
+ 0x005A, 0x005B, 0x005C, 0x000C, 0x0030, 0x0031, 0x0019, 0x0009,
+ 0x0014, 0x0015, 0x002C, 0x005C, 0x005D, 0x005E, 0x005F, 0x0026,
+ 0x005D, 0x005E, 0x005F, 0x000D, 0x0034, 0x0035, 0x001B, 0x0014,
+ 0x0027, 0x002A, 0x002B, 0x000E, 0x0038, 0x0039, 0x001D, 0x000F,
+ 0x003C, 0x003D, 0x001F, 0x0005, 0x0009, 0x0000, 0x0003
},
{
- 0, 1, 2, 3, 2, 3, 1, 4, 5, 24, 7, 13, 16, 17, 9, 5,
- 25, 1, 1, 1, 2, 3, 96, 194, 1, 2, 98, 99, 195, 200, 101, 26,
- 201, 102, 412, 413, 414, 54, 220, 111, 221, 3, 224, 113, 225, 114, 230, 29,
- 231, 415, 240, 4, 241, 484, 5, 243, 3, 244, 245, 485, 492, 493, 247, 31
+ 0x0032, 0x0033, 0x001A, 0x0026, 0x00E4, 0x00E5, 0x01E6, 0x0027,
+ 0x00E6, 0x00E7, 0x01E7, 0x000E, 0x0063, 0x006C, 0x0077, 0x0028,
+ 0x00E8, 0x00E9, 0x01E8, 0x007B, 0x00DA, 0x00DB, 0x00EC, 0x00F5,
+ 0x01B8, 0x01B9, 0x01DA, 0x0021, 0x004B, 0x0054, 0x002B, 0x0029,
+ 0x00EA, 0x00EB, 0x01E9, 0x004A, 0x01BA, 0x01BB, 0x01DB, 0x0020,
+ 0x00DE, 0x00DF, 0x00F2, 0x0022, 0x0055, 0x0058, 0x002D, 0x000F,
+ 0x0070, 0x0071, 0x0078, 0x0023, 0x0059, 0x005C, 0x002F, 0x0024,
+ 0x005D, 0x0062, 0x0030, 0x0002, 0x001F, 0x0006, 0x0000
},
{
- 0, 1, 1, 1, 2, 2, 3, 4, 3, 5, 6, 7, 8, 9, 10, 11,
- 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
- 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
- 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 28, 29, 30, 31
- }
+ 0x0028, 0x0029, 0x009D, 0x0000, 0x01EA, 0x01EB, 0x01EC, 0x0001,
+ 0x01ED, 0x01EE, 0x01EF, 0x0005, 0x00F0, 0x00F1, 0x003B, 0x0002,
+ 0x01F0, 0x01F1, 0x01F2, 0x003F, 0x015C, 0x015D, 0x0099, 0x0010,
+ 0x03D0, 0x03D1, 0x0130, 0x000F, 0x009E, 0x009F, 0x00FB, 0x0003,
+ 0x01F3, 0x01F4, 0x01F5, 0x0011, 0x03D2, 0x03D3, 0x0131, 0x0009,
+ 0x015E, 0x015F, 0x009C, 0x0010, 0x00A8, 0x00A9, 0x0038, 0x0006,
+ 0x00F2, 0x00F3, 0x004D, 0x0011, 0x00AA, 0x00AB, 0x0039, 0x0012,
+ 0x00AC, 0x00AD, 0x003A, 0x0006, 0x0016, 0x0017, 0x000E
+ },
+ {
+ 0x003C, 0x003D, 0x001F, 0x000A, 0x0061, 0x0062, 0x0002, 0x000B,
+ 0x0063, 0x0064, 0x0003, 0x0007, 0x0003, 0x0004, 0x000B, 0x000C,
+ 0x0065, 0x0066, 0x0004, 0x0012, 0x000A, 0x000B, 0x0014, 0x001B,
+ 0x0018, 0x0019, 0x0034, 0x002C, 0x0067, 0x0068, 0x0035, 0x000D,
+ 0x0069, 0x006C, 0x0005, 0x0060, 0x001A, 0x001B, 0x0035, 0x0013,
+ 0x000E, 0x000F, 0x0015, 0x002D, 0x006D, 0x006E, 0x0038, 0x0008,
+ 0x0008, 0x0009, 0x000C, 0x002E, 0x006F, 0x0072, 0x003A, 0x002F,
+ 0x0073, 0x0000, 0x003B, 0x0007, 0x0014, 0x0015, 0x0004
+ },
+ {
+ 0x0038, 0x0039, 0x009D, 0x000A, 0x0091, 0x0092, 0x0093, 0x000B,
+ 0x0094, 0x0095, 0x0096, 0x0003, 0x00EE, 0x00EF, 0x0036, 0x000C,
+ 0x0097, 0x0098, 0x0099, 0x0008, 0x01E4, 0x01E5, 0x006A, 0x0018,
+ 0x03CC, 0x03CD, 0x00D6, 0x000E, 0x009E, 0x009F, 0x00F5, 0x000D,
+ 0x009A, 0x009B, 0x009C, 0x0019, 0x03CE, 0x03CF, 0x00D7, 0x0009,
+ 0x01E8, 0x01E9, 0x0090, 0x000F, 0x00E8, 0x00E9, 0x00F6, 0x0005,
+ 0x00F0, 0x00F1, 0x0037, 0x0010, 0x00EA, 0x00EB, 0x00F7, 0x0011,
+ 0x00EC, 0x00ED, 0x0034, 0x0000, 0x003E, 0x003F, 0x0002
+ },
+ {
+ 0x003C, 0x003D, 0x01CF, 0x0000, 0x00BF, 0x00E0, 0x01FC, 0x0001,
+ 0x00E1, 0x00E2, 0x01FD, 0x0009, 0x01F1, 0x01F2, 0x01F3, 0x0002,
+ 0x00E3, 0x00E4, 0x01FE, 0x0011, 0x03EE, 0x03EF, 0x03F0, 0x0021,
+ 0x07E2, 0x07E3, 0x07E4, 0x0018, 0x03F7, 0x03FE, 0x03FF, 0x0003,
+ 0x00E5, 0x00E6, 0x0080, 0x002E, 0x07E5, 0x07E6, 0x07E7, 0x0016,
+ 0x03F4, 0x03F5, 0x03F6, 0x0019, 0x0102, 0x0103, 0x0104, 0x000A,
+ 0x01F4, 0x01F5, 0x01F6, 0x001A, 0x0105, 0x0106, 0x0107, 0x001B,
+ 0x0178, 0x0179, 0x01CE, 0x001D, 0x00BD, 0x00BE, 0x01F0
+ },
+ {
+ 0x0003, 0x0004, 0x01B6, 0x0004, 0x002E, 0x002F, 0x000E, 0x0005,
+ 0x0030, 0x0031, 0x000F, 0x0003, 0x000A, 0x000B, 0x0014, 0x0006,
+ 0x0032, 0x0033, 0x0010, 0x0005, 0x0030, 0x0031, 0x0032, 0x0009,
+ 0x0066, 0x0067, 0x0068, 0x001D, 0x01B7, 0x01B8, 0x01B9, 0x0007,
+ 0x0034, 0x0035, 0x0011, 0x0016, 0x0069, 0x006A, 0x006B, 0x000A,
+ 0x0036, 0x0037, 0x00D8, 0x001E, 0x01BA, 0x01BB, 0x01BC, 0x0004,
+ 0x0015, 0x0016, 0x0017, 0x001F, 0x01BD, 0x01BE, 0x01BF, 0x0000,
+ 0x0010, 0x0011, 0x0012, 0x001C, 0x00D9, 0x00DA, 0x0013
+ }
};
-const uint8_t ff_vc1_cbpcy_p_bits[4][64] = {
+
+const uint8_t ff_vc1_icbpcy_p_bits[8][63] = {
+ {
+ 15, 15, 14, 9, 11, 11, 13, 9, 11, 11, 12, 8, 9, 9, 9, 9,
+ 11, 11, 12, 9, 10, 10, 10, 10, 11, 11, 11, 8, 8, 8, 7, 9,
+ 11, 11, 12, 10, 11, 11, 11, 9, 10, 10, 10, 8, 8, 8, 7, 8,
+ 9, 9, 9, 8, 8, 8, 7, 8, 8, 8, 7, 3, 3, 3, 1
+ },
+ {
+ 7, 7, 9, 7, 8, 8, 9, 7, 8, 8, 9, 6, 7, 7, 7, 7,
+ 7, 7, 9, 7, 8, 8, 8, 8, 9, 9, 9, 6, 7, 7, 6, 6,
+ 7, 7, 8, 8, 9, 9, 9, 7, 8, 8, 8, 6, 7, 7, 6, 6,
+ 7, 7, 7, 6, 7, 7, 6, 6, 7, 7, 6, 3, 4, 3, 2
+ },
{
- 13, 6, 5, 6, 6, 7, 7, 5, 7, 7, 6, 6, 6, 5, 6, 3,
- 7, 8, 8, 13, 7, 8, 13, 8, 13, 13, 13, 8, 8, 7, 7, 3,
- 13, 13, 7, 8, 13, 13, 13, 8, 13, 13, 8, 7, 8, 7, 8, 3,
- 13, 12, 12, 12, 12, 12, 12, 6, 12, 12, 12, 8, 8, 7, 7, 2
+ 6, 6, 5, 6, 8, 8, 9, 6, 8, 8, 9, 5, 7, 7, 7, 6,
+ 8, 8, 9, 7, 8, 8, 8, 8, 9, 9, 9, 6, 7, 7, 6, 6,
+ 8, 8, 9, 7, 9, 9, 9, 6, 8, 8, 8, 6, 7, 7, 6, 5,
+ 7, 7, 7, 6, 7, 7, 6, 6, 7, 7, 6, 3, 5, 4, 2
},
{
- 14, 3, 3, 5, 3, 4, 5, 5, 3, 5, 4, 5, 4, 6, 5, 6,
- 8, 14, 13, 8, 8, 13, 13, 8, 8, 13, 13, 8, 13, 13, 8, 13,
- 13, 8, 13, 13, 7, 7, 13, 13, 13, 13, 8, 8, 13, 13, 7, 6,
- 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 8, 7
+ 6, 6, 8, 4, 9, 9, 9, 4, 9, 9, 9, 4, 8, 8, 7, 4,
+ 9, 9, 9, 6, 9, 9, 8, 6, 10, 10, 9, 5, 8, 8, 8, 4,
+ 9, 9, 9, 6, 10, 10, 9, 5, 9, 9, 8, 5, 8, 8, 7, 4,
+ 8, 8, 7, 5, 8, 8, 7, 5, 8, 8, 7, 3, 5, 5, 4
},
{
- 13, 5, 5, 5, 4, 4, 6, 4, 4, 6, 4, 5, 5, 5, 4, 3,
- 6, 8, 10, 9, 8, 8, 7, 8, 13, 13, 7, 7, 8, 8, 7, 5,
- 8, 7, 9, 9, 9, 6, 8, 7, 8, 13, 8, 7, 8, 7, 8, 5,
- 8, 9, 8, 13, 8, 9, 13, 8, 12, 8, 8, 9, 9, 9, 8, 5
+ 6, 6, 5, 5, 7, 7, 7, 5, 7, 7, 7, 5, 6, 6, 6, 5,
+ 7, 7, 7, 6, 7, 7, 7, 7, 8, 8, 8, 6, 7, 7, 6, 5,
+ 7, 7, 7, 7, 8, 8, 8, 6, 7, 7, 7, 6, 7, 7, 6, 5,
+ 6, 6, 6, 6, 7, 7, 6, 6, 7, 6, 6, 4, 5, 5, 3
},
{
- 9, 2, 3, 9, 2, 9, 9, 9, 2, 9, 9, 9, 9, 9, 9, 9,
- 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
- 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
- 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8
+ 6, 6, 8, 4, 8, 8, 8, 4, 8, 8, 8, 4, 8, 8, 7, 4,
+ 8, 8, 8, 5, 9, 9, 8, 6, 10, 10, 9, 5, 8, 8, 8, 4,
+ 8, 8, 8, 6, 10, 10, 9, 5, 9, 9, 8, 5, 8, 8, 8, 4,
+ 8, 8, 7, 5, 8, 8, 8, 5, 8, 8, 7, 3, 6, 6, 4
+ },
+ {
+ 6, 6, 9, 3, 8, 8, 9, 3, 8, 8, 9, 4, 9, 9, 9, 3,
+ 8, 8, 9, 5, 10, 10, 10, 6, 11, 11, 11, 5, 10, 10, 10, 3,
+ 8, 8, 8, 6, 11, 11, 11, 5, 10, 10, 10, 5, 9, 9, 9, 4,
+ 9, 9, 9, 5, 9, 9, 9, 5, 9, 9, 9, 5, 8, 8, 9
+ },
+ {
+ 6, 6, 10, 3, 7, 7, 7, 3, 7, 7, 7, 4, 8, 8, 8, 3,
+ 7, 7, 7, 5, 9, 9, 9, 6, 10, 10, 10, 6, 10, 10, 10, 3,
+ 7, 7, 7, 6, 10, 10, 10, 5, 9, 9, 9, 6, 10, 10, 10, 4,
+ 8, 8, 8, 6, 10, 10, 10, 5, 9, 9, 9, 6, 9, 9, 9
}
};
-#endif
/* MacroBlock Transform Type: 7.1.3.11, p89
* 8x8:B
@@ -455,26 +911,26 @@ const uint8_t ff_vc1_ttmb_bits[3][16] = {
/* TTBLK (Transform Type per Block) tables */
const uint8_t ff_vc1_ttblk_codes[3][8] = {
- { 0, 1, 3, 5, 16, 17, 18, 19},
- { 3, 0, 1, 2, 3, 5, 8, 9},
- { 1, 0, 1, 4, 6, 7, 10, 11}
+ { 0, 1, 3, 5, 16, 17, 18, 19 },
+ { 3, 0, 1, 2, 3, 5, 8, 9 },
+ { 1, 0, 1, 4, 6, 7, 10, 11 }
};
const uint8_t ff_vc1_ttblk_bits[3][8] = {
- { 2, 2, 2, 3, 5, 5, 5, 5},
- { 2, 3, 3, 3, 3, 3, 4, 4},
- { 2, 3, 3, 3, 3, 3, 4, 4}
+ { 2, 2, 2, 3, 5, 5, 5, 5 },
+ { 2, 3, 3, 3, 3, 3, 4, 4 },
+ { 2, 3, 3, 3, 3, 3, 4, 4 }
};
/* SUBBLKPAT tables, p93-94, reordered */
const uint8_t ff_vc1_subblkpat_codes[3][15] = {
- { 14, 12, 7, 11, 9, 26, 2, 10, 27, 8, 0, 6, 1, 15, 1},
- { 14, 0, 8, 15, 10, 4, 23, 13, 5, 9, 25, 3, 24, 22, 1},
- { 5, 6, 2, 2, 8, 0, 28, 3, 1, 3, 29, 1, 19, 18, 15}
+ { 14, 12, 7, 11, 9, 26, 2, 10, 27, 8, 0, 6, 1, 15, 1 },
+ { 14, 0, 8, 15, 10, 4, 23, 13, 5, 9, 25, 3, 24, 22, 1 },
+ { 5, 6, 2, 2, 8, 0, 28, 3, 1, 3, 29, 1, 19, 18, 15 }
};
const uint8_t ff_vc1_subblkpat_bits[3][15] = {
- { 5, 5, 5, 5, 5, 6, 4, 5, 6, 5, 4, 5, 4, 5, 1},
- { 4, 3, 4, 4, 4, 5, 5, 4, 5, 4, 5, 4, 5, 5, 2},
- { 3, 3, 4, 3, 4, 5, 5, 3, 5, 4, 5, 4, 5, 5, 4}
+ { 5, 5, 5, 5, 5, 6, 4, 5, 6, 5, 4, 5, 4, 5, 1},
+ { 4, 3, 4, 4, 4, 5, 5, 4, 5, 4, 5, 4, 5, 5, 2},
+ { 3, 3, 4, 3, 4, 5, 5, 3, 5, 4, 5, 4, 5, 5, 4}
};
/* MV differential tables, p265 */
@@ -563,83 +1019,113 @@ const uint8_t ff_vc1_mv_diff_bits[4][73] = {
/* DC differentials low+hi-mo, p217 are the same as in msmpeg4data .h */
/* Table 232 */
-const int8_t ff_vc1_simple_progressive_4x4_zz [16] =
-{
- 0, 8, 16, 1,
- 9, 24, 17, 2,
- 10, 18, 25, 3,
- 11, 26, 19, 27
-};
-
-const int8_t ff_vc1_adv_progressive_8x4_zz [32] = /* Table 233 */
-{
- 0, 8, 1, 16, 2, 9, 10, 3,
- 24, 17, 4, 11, 18, 12, 5, 19,
- 25, 13, 20, 26, 27, 6, 21, 28,
- 14, 22, 29, 7, 30, 15, 23, 31
-};
-
-const int8_t ff_vc1_adv_progressive_4x8_zz [32] = /* Table 234 */
-{
- 0, 1, 8, 2,
- 9, 16, 17, 24,
- 10, 32, 25, 18,
- 40, 3, 33, 26,
- 48, 11, 56, 41,
- 34, 49, 57, 42,
- 19, 50, 27, 58,
- 35, 43, 51, 59
-};
-
-const int8_t ff_vc1_adv_interlaced_8x8_zz [64] = /* Table 235 */
-{
- 0, 8, 1, 16, 24, 9, 2, 32,
- 40, 48, 56, 17, 10, 3, 25, 18,
- 11, 4, 33, 41, 49, 57, 26, 34,
- 42, 50, 58, 19, 12, 5, 27, 20,
- 13, 6, 35, 28, 21, 14, 7, 15,
- 22, 29, 36, 43, 51, 59, 60, 52,
- 44, 37, 30, 23, 31, 38, 45, 53,
- 61, 62, 54, 46, 39, 47, 55, 63
-};
-
-const int8_t ff_vc1_adv_interlaced_8x4_zz [32] = /* Table 236 */
-{
- 0, 8, 16, 24, 1, 9, 2, 17,
- 25, 10, 3, 18, 26, 4, 11, 19,
- 12, 5, 13, 20, 27, 6, 21, 28,
- 14, 22, 29, 7, 30, 15, 23, 31
-};
-
-const int8_t ff_vc1_adv_interlaced_4x8_zz [32] = /* Table 237 */
-{
- 0, 1, 2, 8,
- 16, 9, 24, 17,
- 10, 3, 32, 40,
- 48, 56, 25, 18,
- 33, 26, 41, 34,
- 49, 57, 11, 42,
- 19, 50, 27, 58,
- 35, 43, 51, 59
-};
-
-const int8_t ff_vc1_adv_interlaced_4x4_zz [16] = /* Table 238 */
-{
- 0, 8, 16, 24,
- 1, 9, 17, 2,
- 25, 10, 18, 3,
- 26, 11, 19, 27
+const int8_t ff_vc1_simple_progressive_4x4_zz [16] = {
+ 0, 8, 16, 1,
+ 9, 24, 17, 2,
+ 10, 18, 25, 3,
+ 11, 26, 19, 27
+};
+
+const int8_t ff_vc1_adv_progressive_8x4_zz [32] = { /* Table 233 */
+ 0, 8, 1, 16, 2, 9, 10, 3,
+ 24, 17, 4, 11, 18, 12, 5, 19,
+ 25, 13, 20, 26, 27, 6, 21, 28,
+ 14, 22, 29, 7, 30, 15, 23, 31
+};
+
+const int8_t ff_vc1_adv_progressive_4x8_zz [32] = { /* Table 234 */
+ 0, 1, 8, 2,
+ 9, 16, 17, 24,
+ 10, 32, 25, 18,
+ 40, 3, 33, 26,
+ 48, 11, 56, 41,
+ 34, 49, 57, 42,
+ 19, 50, 27, 58,
+ 35, 43, 51, 59
+};
+
+const int8_t ff_vc1_adv_interlaced_8x8_zz [64] = { /* Table 235 */
+ 0, 8, 1, 16, 24, 9, 2, 32,
+ 40, 48, 56, 17, 10, 3, 25, 18,
+ 11, 4, 33, 41, 49, 57, 26, 34,
+ 42, 50, 58, 19, 12, 5, 27, 20,
+ 13, 6, 35, 28, 21, 14, 7, 15,
+ 22, 29, 36, 43, 51, 59, 60, 52,
+ 44, 37, 30, 23, 31, 38, 45, 53,
+ 61, 62, 54, 46, 39, 47, 55, 63
+};
+
+const int8_t ff_vc1_adv_interlaced_8x4_zz [32] = { /* Table 236 */
+ 0, 8, 16, 24, 1, 9, 2, 17,
+ 25, 10, 3, 18, 26, 4, 11, 19,
+ 12, 5, 13, 20, 27, 6, 21, 28,
+ 14, 22, 29, 7, 30, 15, 23, 31
+};
+
+const int8_t ff_vc1_adv_interlaced_4x8_zz [32] = { /* Table 237 */
+ 0, 1, 2, 8,
+ 16, 9, 24, 17,
+ 10, 3, 32, 40,
+ 48, 56, 25, 18,
+ 33, 26, 41, 34,
+ 49, 57, 11, 42,
+ 19, 50, 27, 58,
+ 35, 43, 51, 59
+};
+
+const int8_t ff_vc1_adv_interlaced_4x4_zz [16] = { /* Table 238 */
+ 0, 8, 16, 24,
+ 1, 9, 17, 2,
+ 25, 10, 18, 3,
+ 26, 11, 19, 27
};
/* DQScale as specified in 8.1.3.9 - almost identical to 0x40000/i */
const int32_t ff_vc1_dqscale[63] = {
-0x40000, 0x20000, 0x15555, 0x10000, 0xCCCD, 0xAAAB, 0x9249, 0x8000,
- 0x71C7, 0x6666, 0x5D17, 0x5555, 0x4EC5, 0x4925, 0x4444, 0x4000,
- 0x3C3C, 0x38E4, 0x35E5, 0x3333, 0x30C3, 0x2E8C, 0x2C86, 0x2AAB,
- 0x28F6, 0x2762, 0x25ED, 0x2492, 0x234F, 0x2222, 0x2108, 0x2000,
- 0x1F08, 0x1E1E, 0x1D42, 0x1C72, 0x1BAD, 0x1AF3, 0x1A42, 0x199A,
- 0x18FA, 0x1862, 0x17D0, 0x1746, 0x16C1, 0x1643, 0x15CA, 0x1555,
- 0x14E6, 0x147B, 0x1414, 0x13B1, 0x1352, 0x12F7, 0x129E, 0x1249,
- 0x11F7, 0x11A8, 0x115B, 0x1111, 0x10C9, 0x1084, 0x1000
+ 0x40000, 0x20000, 0x15555, 0x10000, 0xCCCD, 0xAAAB, 0x9249, 0x8000,
+ 0x71C7, 0x6666, 0x5D17, 0x5555, 0x4EC5, 0x4925, 0x4444, 0x4000,
+ 0x3C3C, 0x38E4, 0x35E5, 0x3333, 0x30C3, 0x2E8C, 0x2C86, 0x2AAB,
+ 0x28F6, 0x2762, 0x25ED, 0x2492, 0x234F, 0x2222, 0x2108, 0x2000,
+ 0x1F08, 0x1E1E, 0x1D42, 0x1C72, 0x1BAD, 0x1AF3, 0x1A42, 0x199A,
+ 0x18FA, 0x1862, 0x17D0, 0x1746, 0x16C1, 0x1643, 0x15CA, 0x1555,
+ 0x14E6, 0x147B, 0x1414, 0x13B1, 0x1352, 0x12F7, 0x129E, 0x1249,
+ 0x11F7, 0x11A8, 0x115B, 0x1111, 0x10C9, 0x1084, 0x1000
+};
+
+/* P Interlaced field picture MV predictor scaling values (Table 114) */
+const uint16_t vc1_field_mvpred_scales[2][7][4] = {
+// Refdist:
+// 0 1 2 3 or greater
+ { // current field is first
+ { 128, 192, 213, 224 }, // SCALEOPP
+ { 512, 341, 307, 293 }, // SCALESAME1
+ { 219, 236, 242, 245 }, // SCALESAME2
+ { 32, 48, 53, 56 }, // SCALEZONE1_X
+ { 8, 12, 13, 14 }, // SCALEZONE1_Y
+ { 37, 20, 14, 11 }, // ZONE1OFFSET_X
+ { 10, 5, 4, 3 } // ZONE1OFFSET_Y
+ },
+ { // current field is second
+ { 128, 64, 43, 32 }, // SCALEOPP
+ { 512, 1024, 1536, 2048 }, // SCALESAME1
+ { 219, 204, 200, 198 }, // SCALESAME2
+ { 32, 16, 11, 8 }, // SCALEZONE1_X
+ { 8, 4, 3, 2 }, // SCALEZONE1_Y
+ { 37, 52, 56, 58 }, // ZONE1OFFSET_X
+ { 10, 13, 14, 15 } // ZONE1OFFSET_Y
+ }
+};
+
+/* B Interlaced field picture backward MV predictor scaling values for first field (Table 115) */
+const uint16_t vc1_b_field_mvpred_scales[7][4] = {
+ // BRFD:
+ // 0 1 2 3 or greater
+ { 171, 205, 219, 228 }, // SCALESAME
+ { 384, 320, 299, 288 }, // SCALEOPP1
+ { 230, 239, 244, 246 }, // SCALEOPP2
+ { 43, 51, 55, 57 }, // SCALEZONE1_X
+ { 11, 13, 14, 14 }, // SCALEZONE1_Y
+ { 26, 17, 12, 10 }, // ZONE1OFFSET_X
+ { 7, 4, 3, 3 } // ZONE1OFFSET_Y
};
diff --git a/libavcodec/vc1data.h b/libavcodec/vc1data.h
index 1ccc9bbf6e..f11122504b 100644
--- a/libavcodec/vc1data.h
+++ b/libavcodec/vc1data.h
@@ -3,20 +3,20 @@
* copyright (c) 2006 Konstantin Shishkov
* (c) 2005 anonymous, Alex Beregszaszi, Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -44,6 +44,9 @@ extern const uint8_t ff_vc1_mv_pmode_table2[2][4];
extern const int ff_vc1_fps_nr[5], ff_vc1_fps_dr[2];
extern const uint8_t ff_vc1_pquant_table[3][32];
+/* MBMODE table for interlaced frame P-picture */
+extern const uint8_t ff_vc1_mbmode_intfrp[2][15][4];
+
/** @name VC-1 VLC tables and defines
* @todo TODO move this into the context
*/
@@ -63,31 +66,40 @@ extern VLC ff_vc1_ttmb_vlc[3];
extern VLC ff_vc1_mv_diff_vlc[4];
#define VC1_CBPCY_P_VLC_BITS 9 //14
extern VLC ff_vc1_cbpcy_p_vlc[4];
+#define VC1_ICBPCY_VLC_BITS 9
+extern VLC ff_vc1_icbpcy_vlc[8];
#define VC1_4MV_BLOCK_PATTERN_VLC_BITS 6
extern VLC ff_vc1_4mv_block_pattern_vlc[4];
+#define VC1_2MV_BLOCK_PATTERN_VLC_BITS 3
+extern VLC ff_vc1_2mv_block_pattern_vlc[4];
#define VC1_TTBLK_VLC_BITS 5
extern VLC ff_vc1_ttblk_vlc[3];
#define VC1_SUBBLKPAT_VLC_BITS 6
extern VLC ff_vc1_subblkpat_vlc[3];
+#define VC1_INTFR_4MV_MBMODE_VLC_BITS 9
+extern VLC ff_vc1_intfr_4mv_mbmode_vlc[4];
+#define VC1_INTFR_NON4MV_MBMODE_VLC_BITS 6
+extern VLC ff_vc1_intfr_non4mv_mbmode_vlc[4];
+#define VC1_IF_MMV_MBMODE_VLC_BITS 5
+extern VLC ff_vc1_if_mmv_mbmode_vlc[8];
+#define VC1_IF_1MV_MBMODE_VLC_BITS 5
+extern VLC ff_vc1_if_1mv_mbmode_vlc[8];
+#define VC1_1REF_MVDATA_VLC_BITS 9
+extern VLC ff_vc1_1ref_mvdata_vlc[4];
+#define VC1_2REF_MVDATA_VLC_BITS 9
+extern VLC ff_vc1_2ref_mvdata_vlc[8];
extern VLC ff_vc1_ac_coeff_table[8];
+
+#define VC1_IF_MBMODE_VLC_BITS 5
//@}
-#if 0 //original bfraction from vc9data.h, not conforming to standard
-/* Denominator used for ff_vc1_bfraction_lut */
-#define B_FRACTION_DEN 840
-
-/* bfraction is fractional, we scale to the GCD 3*5*7*8 = 840 */
-extern const int16_t ff_vc1_bfraction_lut[23];
-#else
/* Denominator used for ff_vc1_bfraction_lut */
#define B_FRACTION_DEN 256
/* pre-computed scales for all bfractions and base=256 */
extern const int16_t ff_vc1_bfraction_lut[23];
-#endif
-
extern const uint8_t ff_vc1_bfraction_bits[23];
extern const uint8_t ff_vc1_bfraction_codes[23];
@@ -110,12 +122,20 @@ extern const uint8_t ff_vc1_norm6_spec[64][5];
extern const uint8_t ff_vc1_4mv_block_pattern_codes[4][16];
extern const uint8_t ff_vc1_4mv_block_pattern_bits[4][16];
+/* 2MV Block pattern VLC tables */
+extern const uint8_t ff_vc1_2mv_block_pattern_codes[4][4];
+extern const uint8_t ff_vc1_2mv_block_pattern_bits[4][4];
+
extern const uint8_t wmv3_dc_scale_table[32];
/* P-Picture CBPCY VLC tables */
extern const uint16_t ff_vc1_cbpcy_p_codes[4][64];
extern const uint8_t ff_vc1_cbpcy_p_bits[4][64];
+/* Interlaced CBPCY VLC tables (Table 124 - Table 131) */
+extern const uint16_t ff_vc1_icbpcy_p_codes[8][63];
+extern const uint8_t ff_vc1_icbpcy_p_bits[8][63];
+
/* MacroBlock Transform Type: 7.1.3.11, p89
* 8x8:B
* 8x4:B:btm 8x4:B:top 8x4:B:both,
@@ -140,6 +160,26 @@ extern const uint8_t ff_vc1_subblkpat_bits[3][15];
extern const uint16_t ff_vc1_mv_diff_codes[4][73];
extern const uint8_t ff_vc1_mv_diff_bits[4][73];
+/* Interlaced frame picture MBMODE VLC tables (p. 246, p. 360) */
+extern const uint16_t ff_vc1_intfr_4mv_mbmode_codes[4][15];
+extern const uint8_t ff_vc1_intfr_4mv_mbmode_bits[4][15];
+extern const uint8_t ff_vc1_intfr_non4mv_mbmode_codes[4][9];
+extern const uint8_t ff_vc1_intfr_non4mv_mbmode_bits[4][9];
+
+/* Interlaced field picture MBMODE VLC tables (p. 356 - 11.4.1, 11.4.2) */
+extern const uint8_t ff_vc1_if_mmv_mbmode_codes[8][8];
+extern const uint8_t ff_vc1_if_mmv_mbmode_bits[8][8];
+extern const uint8_t ff_vc1_if_1mv_mbmode_codes[8][6];
+extern const uint8_t ff_vc1_if_1mv_mbmode_bits[8][6];
+
+/* Interlaced frame/field picture MVDATA VLC tables */
+/* 1-reference tables */
+extern const uint32_t ff_vc1_1ref_mvdata_codes[4][72];
+extern const uint8_t ff_vc1_1ref_mvdata_bits[4][72];
+/* 2-reference tables */
+extern const uint32_t ff_vc1_2ref_mvdata_codes[8][126];
+extern const uint8_t ff_vc1_2ref_mvdata_bits[8][126];
+
/* DC differentials low+hi-mo, p217 are the same as in msmpeg4data .h */
/* Scantables/ZZ scan are at 11.9 (p262) and 8.1.1.12 (p10) */
@@ -150,8 +190,14 @@ extern const int8_t ff_vc1_adv_interlaced_8x8_zz [64];
extern const int8_t ff_vc1_adv_interlaced_8x4_zz [32];
extern const int8_t ff_vc1_adv_interlaced_4x8_zz [32];
extern const int8_t ff_vc1_adv_interlaced_4x4_zz [16];
+extern const int8_t ff_vc1_intra_horz_8x8_zz [64];
+extern const int8_t ff_vc1_intra_vert_8x8_zz [64];
/* DQScale as specified in 8.1.3.9 - almost identical to 0x40000/i */
extern const int32_t ff_vc1_dqscale[63];
+/* P Interlaced field picture MV predictor scaling values (Table 114) */
+extern const uint16_t vc1_field_mvpred_scales[2][7][4];
+/* B Interlaced field picture backward MV predictor scaling values for first field (Table 115) */
+extern const uint16_t vc1_b_field_mvpred_scales[7][4];
#endif /* AVCODEC_VC1DATA_H */
diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c
index cf828dd1f0..69fd5be7be 100644
--- a/libavcodec/vc1dec.c
+++ b/libavcodec/vc1dec.c
@@ -1,30 +1,31 @@
/*
* VC-1 and WMV3 decoder
+ * Copyright (c) 2011 Mashiat Sarker Shakkhar
* Copyright (c) 2006-2007 Konstantin Shishkov
* Partly based on vc9.c (c) 2005 Anonymous, Alex Beregszaszi, Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* VC-1 and WMV3 decoder
- *
*/
+
#include "internal.h"
#include "dsputil.h"
#include "avcodec.h"
@@ -48,11 +49,19 @@
static const uint16_t vlc_offs[] = {
- 0, 520, 552, 616, 1128, 1160, 1224, 1740, 1772, 1836, 1900, 2436,
- 2986, 3050, 3610, 4154, 4218, 4746, 5326, 5390, 5902, 6554, 7658, 8620,
- 9262, 10202, 10756, 11310, 12228, 15078
+ 0, 520, 552, 616, 1128, 1160, 1224, 1740, 1772, 1836, 1900, 2436,
+ 2986, 3050, 3610, 4154, 4218, 4746, 5326, 5390, 5902, 6554, 7658, 8342,
+ 9304, 9988, 10630, 11234, 12174, 13006, 13560, 14232, 14786, 15432, 16350, 17522,
+ 20372, 21818, 22330, 22394, 23166, 23678, 23742, 24820, 25332, 25396, 26460, 26980,
+ 27048, 27592, 27600, 27608, 27616, 27624, 28224, 28258, 28290, 28802, 28834, 28866,
+ 29378, 29412, 29444, 29960, 29994, 30026, 30538, 30572, 30604, 31120, 31154, 31186,
+ 31714, 31746, 31778, 32306, 32340, 32372
};
+// offset tables for interlaced picture MVDATA decoding
+static const int offset_table1[9] = { 0, 1, 2, 4, 8, 16, 32, 64, 128 };
+static const int offset_table2[9] = { 0, 1, 3, 7, 15, 31, 63, 127, 255 };
+
/**
* Init VC-1 specific tables and VC1Context members
* @param v The VC1Context to initialize
@@ -62,73 +71,123 @@ static int vc1_init_common(VC1Context *v)
{
static int done = 0;
int i = 0;
- static VLC_TYPE vlc_table[15078][2];
+ static VLC_TYPE vlc_table[32372][2];
v->hrd_rate = v->hrd_buffer = NULL;
/* VLC tables */
- if(!done)
- {
+ if (!done) {
INIT_VLC_STATIC(&ff_vc1_bfraction_vlc, VC1_BFRACTION_VLC_BITS, 23,
- ff_vc1_bfraction_bits, 1, 1,
- ff_vc1_bfraction_codes, 1, 1, 1 << VC1_BFRACTION_VLC_BITS);
+ ff_vc1_bfraction_bits, 1, 1,
+ ff_vc1_bfraction_codes, 1, 1, 1 << VC1_BFRACTION_VLC_BITS);
INIT_VLC_STATIC(&ff_vc1_norm2_vlc, VC1_NORM2_VLC_BITS, 4,
- ff_vc1_norm2_bits, 1, 1,
- ff_vc1_norm2_codes, 1, 1, 1 << VC1_NORM2_VLC_BITS);
+ ff_vc1_norm2_bits, 1, 1,
+ ff_vc1_norm2_codes, 1, 1, 1 << VC1_NORM2_VLC_BITS);
INIT_VLC_STATIC(&ff_vc1_norm6_vlc, VC1_NORM6_VLC_BITS, 64,
- ff_vc1_norm6_bits, 1, 1,
- ff_vc1_norm6_codes, 2, 2, 556);
+ ff_vc1_norm6_bits, 1, 1,
+ ff_vc1_norm6_codes, 2, 2, 556);
INIT_VLC_STATIC(&ff_vc1_imode_vlc, VC1_IMODE_VLC_BITS, 7,
- ff_vc1_imode_bits, 1, 1,
- ff_vc1_imode_codes, 1, 1, 1 << VC1_IMODE_VLC_BITS);
- for (i=0; i<3; i++)
- {
- ff_vc1_ttmb_vlc[i].table = &vlc_table[vlc_offs[i*3+0]];
- ff_vc1_ttmb_vlc[i].table_allocated = vlc_offs[i*3+1] - vlc_offs[i*3+0];
+ ff_vc1_imode_bits, 1, 1,
+ ff_vc1_imode_codes, 1, 1, 1 << VC1_IMODE_VLC_BITS);
+ for (i = 0; i < 3; i++) {
+ ff_vc1_ttmb_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 0]];
+ ff_vc1_ttmb_vlc[i].table_allocated = vlc_offs[i * 3 + 1] - vlc_offs[i * 3 + 0];
init_vlc(&ff_vc1_ttmb_vlc[i], VC1_TTMB_VLC_BITS, 16,
ff_vc1_ttmb_bits[i], 1, 1,
ff_vc1_ttmb_codes[i], 2, 2, INIT_VLC_USE_NEW_STATIC);
- ff_vc1_ttblk_vlc[i].table = &vlc_table[vlc_offs[i*3+1]];
- ff_vc1_ttblk_vlc[i].table_allocated = vlc_offs[i*3+2] - vlc_offs[i*3+1];
+ ff_vc1_ttblk_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 1]];
+ ff_vc1_ttblk_vlc[i].table_allocated = vlc_offs[i * 3 + 2] - vlc_offs[i * 3 + 1];
init_vlc(&ff_vc1_ttblk_vlc[i], VC1_TTBLK_VLC_BITS, 8,
ff_vc1_ttblk_bits[i], 1, 1,
ff_vc1_ttblk_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC);
- ff_vc1_subblkpat_vlc[i].table = &vlc_table[vlc_offs[i*3+2]];
- ff_vc1_subblkpat_vlc[i].table_allocated = vlc_offs[i*3+3] - vlc_offs[i*3+2];
+ ff_vc1_subblkpat_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 2]];
+ ff_vc1_subblkpat_vlc[i].table_allocated = vlc_offs[i * 3 + 3] - vlc_offs[i * 3 + 2];
init_vlc(&ff_vc1_subblkpat_vlc[i], VC1_SUBBLKPAT_VLC_BITS, 15,
ff_vc1_subblkpat_bits[i], 1, 1,
ff_vc1_subblkpat_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC);
}
- for(i=0; i<4; i++)
- {
- ff_vc1_4mv_block_pattern_vlc[i].table = &vlc_table[vlc_offs[i*3+9]];
- ff_vc1_4mv_block_pattern_vlc[i].table_allocated = vlc_offs[i*3+10] - vlc_offs[i*3+9];
+ for (i = 0; i < 4; i++) {
+ ff_vc1_4mv_block_pattern_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 9]];
+ ff_vc1_4mv_block_pattern_vlc[i].table_allocated = vlc_offs[i * 3 + 10] - vlc_offs[i * 3 + 9];
init_vlc(&ff_vc1_4mv_block_pattern_vlc[i], VC1_4MV_BLOCK_PATTERN_VLC_BITS, 16,
ff_vc1_4mv_block_pattern_bits[i], 1, 1,
ff_vc1_4mv_block_pattern_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC);
- ff_vc1_cbpcy_p_vlc[i].table = &vlc_table[vlc_offs[i*3+10]];
- ff_vc1_cbpcy_p_vlc[i].table_allocated = vlc_offs[i*3+11] - vlc_offs[i*3+10];
+ ff_vc1_cbpcy_p_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 10]];
+ ff_vc1_cbpcy_p_vlc[i].table_allocated = vlc_offs[i * 3 + 11] - vlc_offs[i * 3 + 10];
init_vlc(&ff_vc1_cbpcy_p_vlc[i], VC1_CBPCY_P_VLC_BITS, 64,
ff_vc1_cbpcy_p_bits[i], 1, 1,
ff_vc1_cbpcy_p_codes[i], 2, 2, INIT_VLC_USE_NEW_STATIC);
- ff_vc1_mv_diff_vlc[i].table = &vlc_table[vlc_offs[i*3+11]];
- ff_vc1_mv_diff_vlc[i].table_allocated = vlc_offs[i*3+12] - vlc_offs[i*3+11];
+ ff_vc1_mv_diff_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 11]];
+ ff_vc1_mv_diff_vlc[i].table_allocated = vlc_offs[i * 3 + 12] - vlc_offs[i * 3 + 11];
init_vlc(&ff_vc1_mv_diff_vlc[i], VC1_MV_DIFF_VLC_BITS, 73,
ff_vc1_mv_diff_bits[i], 1, 1,
ff_vc1_mv_diff_codes[i], 2, 2, INIT_VLC_USE_NEW_STATIC);
}
- for(i=0; i<8; i++){
- ff_vc1_ac_coeff_table[i].table = &vlc_table[vlc_offs[i+21]];
- ff_vc1_ac_coeff_table[i].table_allocated = vlc_offs[i+22] - vlc_offs[i+21];
+ for (i = 0; i < 8; i++) {
+ ff_vc1_ac_coeff_table[i].table = &vlc_table[vlc_offs[i * 2 + 21]];
+ ff_vc1_ac_coeff_table[i].table_allocated = vlc_offs[i * 2 + 22] - vlc_offs[i * 2 + 21];
init_vlc(&ff_vc1_ac_coeff_table[i], AC_VLC_BITS, vc1_ac_sizes[i],
&vc1_ac_tables[i][0][1], 8, 4,
&vc1_ac_tables[i][0][0], 8, 4, INIT_VLC_USE_NEW_STATIC);
+ /* initialize interlaced MVDATA tables (2-Ref) */
+ ff_vc1_2ref_mvdata_vlc[i].table = &vlc_table[vlc_offs[i * 2 + 22]];
+ ff_vc1_2ref_mvdata_vlc[i].table_allocated = vlc_offs[i * 2 + 23] - vlc_offs[i * 2 + 22];
+ init_vlc(&ff_vc1_2ref_mvdata_vlc[i], VC1_2REF_MVDATA_VLC_BITS, 126,
+ ff_vc1_2ref_mvdata_bits[i], 1, 1,
+ ff_vc1_2ref_mvdata_codes[i], 4, 4, INIT_VLC_USE_NEW_STATIC);
+ }
+ for (i = 0; i < 4; i++) {
+ /* initialize 4MV MBMODE VLC tables for interlaced frame P picture */
+ ff_vc1_intfr_4mv_mbmode_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 37]];
+ ff_vc1_intfr_4mv_mbmode_vlc[i].table_allocated = vlc_offs[i * 3 + 38] - vlc_offs[i * 3 + 37];
+ init_vlc(&ff_vc1_intfr_4mv_mbmode_vlc[i], VC1_INTFR_4MV_MBMODE_VLC_BITS, 15,
+ ff_vc1_intfr_4mv_mbmode_bits[i], 1, 1,
+ ff_vc1_intfr_4mv_mbmode_codes[i], 2, 2, INIT_VLC_USE_NEW_STATIC);
+ /* initialize NON-4MV MBMODE VLC tables for the same */
+ ff_vc1_intfr_non4mv_mbmode_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 38]];
+ ff_vc1_intfr_non4mv_mbmode_vlc[i].table_allocated = vlc_offs[i * 3 + 39] - vlc_offs[i * 3 + 38];
+ init_vlc(&ff_vc1_intfr_non4mv_mbmode_vlc[i], VC1_INTFR_NON4MV_MBMODE_VLC_BITS, 9,
+ ff_vc1_intfr_non4mv_mbmode_bits[i], 1, 1,
+ ff_vc1_intfr_non4mv_mbmode_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC);
+ /* initialize interlaced MVDATA tables (1-Ref) */
+ ff_vc1_1ref_mvdata_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 39]];
+ ff_vc1_1ref_mvdata_vlc[i].table_allocated = vlc_offs[i * 3 + 40] - vlc_offs[i * 3 + 39];
+ init_vlc(&ff_vc1_1ref_mvdata_vlc[i], VC1_1REF_MVDATA_VLC_BITS, 72,
+ ff_vc1_1ref_mvdata_bits[i], 1, 1,
+ ff_vc1_1ref_mvdata_codes[i], 4, 4, INIT_VLC_USE_NEW_STATIC);
+ }
+ for (i = 0; i < 4; i++) {
+ /* Initialize 2MV Block pattern VLC tables */
+ ff_vc1_2mv_block_pattern_vlc[i].table = &vlc_table[vlc_offs[i + 49]];
+ ff_vc1_2mv_block_pattern_vlc[i].table_allocated = vlc_offs[i + 50] - vlc_offs[i + 49];
+ init_vlc(&ff_vc1_2mv_block_pattern_vlc[i], VC1_2MV_BLOCK_PATTERN_VLC_BITS, 4,
+ ff_vc1_2mv_block_pattern_bits[i], 1, 1,
+ ff_vc1_2mv_block_pattern_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC);
+ }
+ for (i = 0; i < 8; i++) {
+ /* Initialize interlaced CBPCY VLC tables (Table 124 - Table 131) */
+ ff_vc1_icbpcy_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 53]];
+ ff_vc1_icbpcy_vlc[i].table_allocated = vlc_offs[i * 3 + 54] - vlc_offs[i * 3 + 53];
+ init_vlc(&ff_vc1_icbpcy_vlc[i], VC1_ICBPCY_VLC_BITS, 63,
+ ff_vc1_icbpcy_p_bits[i], 1, 1,
+ ff_vc1_icbpcy_p_codes[i], 2, 2, INIT_VLC_USE_NEW_STATIC);
+ /* Initialize interlaced field picture MBMODE VLC tables */
+ ff_vc1_if_mmv_mbmode_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 54]];
+ ff_vc1_if_mmv_mbmode_vlc[i].table_allocated = vlc_offs[i * 3 + 55] - vlc_offs[i * 3 + 54];
+ init_vlc(&ff_vc1_if_mmv_mbmode_vlc[i], VC1_IF_MMV_MBMODE_VLC_BITS, 8,
+ ff_vc1_if_mmv_mbmode_bits[i], 1, 1,
+ ff_vc1_if_mmv_mbmode_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC);
+ ff_vc1_if_1mv_mbmode_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 55]];
+ ff_vc1_if_1mv_mbmode_vlc[i].table_allocated = vlc_offs[i * 3 + 56] - vlc_offs[i * 3 + 55];
+ init_vlc(&ff_vc1_if_1mv_mbmode_vlc[i], VC1_IF_1MV_MBMODE_VLC_BITS, 6,
+ ff_vc1_if_1mv_mbmode_bits[i], 1, 1,
+ ff_vc1_if_1mv_mbmode_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC);
}
done = 1;
}
/* Other defaults */
- v->pq = -1;
+ v->pq = -1;
v->mvrange = 0; /* 7.1.1.18, p80 */
return 0;
@@ -162,6 +221,9 @@ enum Imode {
static void vc1_put_signed_blocks_clamped(VC1Context *v)
{
MpegEncContext *s = &v->s;
+ int topleft_mb_pos, top_mb_pos;
+ int stride_y, fieldtx;
+ int v_dist;
/* The put pixels loop is always one MB row behind the decoding loop,
* because we can only put pixels when overlap filtering is done, and
@@ -172,18 +234,22 @@ static void vc1_put_signed_blocks_clamped(VC1Context *v)
* of the right MB edge, we need the next MB present. */
if (!s->first_slice_line) {
if (s->mb_x) {
+ topleft_mb_pos = (s->mb_y - 1) * s->mb_stride + s->mb_x - 1;
+ fieldtx = v->fieldtx_plane[topleft_mb_pos];
+ stride_y = (s->linesize) << fieldtx;
+ v_dist = (16 - fieldtx) >> (fieldtx == 0);
s->dsp.put_signed_pixels_clamped(v->block[v->topleft_blk_idx][0],
s->dest[0] - 16 * s->linesize - 16,
- s->linesize);
+ stride_y);
s->dsp.put_signed_pixels_clamped(v->block[v->topleft_blk_idx][1],
s->dest[0] - 16 * s->linesize - 8,
- s->linesize);
+ stride_y);
s->dsp.put_signed_pixels_clamped(v->block[v->topleft_blk_idx][2],
- s->dest[0] - 8 * s->linesize - 16,
- s->linesize);
+ s->dest[0] - v_dist * s->linesize - 16,
+ stride_y);
s->dsp.put_signed_pixels_clamped(v->block[v->topleft_blk_idx][3],
- s->dest[0] - 8 * s->linesize - 8,
- s->linesize);
+ s->dest[0] - v_dist * s->linesize - 8,
+ stride_y);
s->dsp.put_signed_pixels_clamped(v->block[v->topleft_blk_idx][4],
s->dest[1] - 8 * s->uvlinesize - 8,
s->uvlinesize);
@@ -192,18 +258,22 @@ static void vc1_put_signed_blocks_clamped(VC1Context *v)
s->uvlinesize);
}
if (s->mb_x == s->mb_width - 1) {
+ top_mb_pos = (s->mb_y - 1) * s->mb_stride + s->mb_x;
+ fieldtx = v->fieldtx_plane[top_mb_pos];
+ stride_y = s->linesize << fieldtx;
+ v_dist = fieldtx ? 15 : 8;
s->dsp.put_signed_pixels_clamped(v->block[v->top_blk_idx][0],
s->dest[0] - 16 * s->linesize,
- s->linesize);
+ stride_y);
s->dsp.put_signed_pixels_clamped(v->block[v->top_blk_idx][1],
s->dest[0] - 16 * s->linesize + 8,
- s->linesize);
+ stride_y);
s->dsp.put_signed_pixels_clamped(v->block[v->top_blk_idx][2],
- s->dest[0] - 8 * s->linesize,
- s->linesize);
+ s->dest[0] - v_dist * s->linesize,
+ stride_y);
s->dsp.put_signed_pixels_clamped(v->block[v->top_blk_idx][3],
- s->dest[0] - 8 * s->linesize + 8,
- s->linesize);
+ s->dest[0] - v_dist * s->linesize + 8,
+ stride_y);
s->dsp.put_signed_pixels_clamped(v->block[v->top_blk_idx][4],
s->dest[1] - 8 * s->uvlinesize,
s->uvlinesize);
@@ -232,17 +302,17 @@ static void vc1_loop_filter_iblk(VC1Context *v, int pq)
if (!s->first_slice_line) {
v->vc1dsp.vc1_v_loop_filter16(s->dest[0], s->linesize, pq);
if (s->mb_x)
- v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 16*s->linesize, s->linesize, pq);
- v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 16*s->linesize+8, s->linesize, pq);
- for(j = 0; j < 2; j++){
- v->vc1dsp.vc1_v_loop_filter8(s->dest[j+1], s->uvlinesize, pq);
+ v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 16 * s->linesize, s->linesize, pq);
+ v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 16 * s->linesize + 8, s->linesize, pq);
+ for (j = 0; j < 2; j++) {
+ v->vc1dsp.vc1_v_loop_filter8(s->dest[j + 1], s->uvlinesize, pq);
if (s->mb_x)
- v->vc1dsp.vc1_h_loop_filter8(s->dest[j+1]-8*s->uvlinesize, s->uvlinesize, pq);
+ v->vc1dsp.vc1_h_loop_filter8(s->dest[j + 1] - 8 * s->uvlinesize, s->uvlinesize, pq);
}
}
- v->vc1dsp.vc1_v_loop_filter16(s->dest[0] + 8*s->linesize, s->linesize, pq);
+ v->vc1dsp.vc1_v_loop_filter16(s->dest[0] + 8 * s->linesize, s->linesize, pq);
- if (s->mb_y == s->mb_height-1) {
+ if (s->mb_y == s->end_mb_y - 1) {
if (s->mb_x) {
v->vc1dsp.vc1_h_loop_filter16(s->dest[0], s->linesize, pq);
v->vc1dsp.vc1_h_loop_filter8(s->dest[1], s->uvlinesize, pq);
@@ -267,10 +337,10 @@ static void vc1_loop_filter_iblk_delayed(VC1Context *v, int pq)
if (s->mb_x >= 2)
v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 32 * s->linesize - 16, s->linesize, pq);
v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 32 * s->linesize - 8, s->linesize, pq);
- for(j = 0; j < 2; j++) {
- v->vc1dsp.vc1_v_loop_filter8(s->dest[j+1] - 8 * s->uvlinesize - 8, s->uvlinesize, pq);
+ for (j = 0; j < 2; j++) {
+ v->vc1dsp.vc1_v_loop_filter8(s->dest[j + 1] - 8 * s->uvlinesize - 8, s->uvlinesize, pq);
if (s->mb_x >= 2) {
- v->vc1dsp.vc1_h_loop_filter8(s->dest[j+1] - 16 * s->uvlinesize - 8, s->uvlinesize, pq);
+ v->vc1dsp.vc1_h_loop_filter8(s->dest[j + 1] - 16 * s->uvlinesize - 8, s->uvlinesize, pq);
}
}
}
@@ -284,24 +354,24 @@ static void vc1_loop_filter_iblk_delayed(VC1Context *v, int pq)
if (s->mb_x)
v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 32 * s->linesize, s->linesize, pq);
v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 32 * s->linesize + 8, s->linesize, pq);
- for(j = 0; j < 2; j++) {
- v->vc1dsp.vc1_v_loop_filter8(s->dest[j+1] - 8 * s->uvlinesize, s->uvlinesize, pq);
+ for (j = 0; j < 2; j++) {
+ v->vc1dsp.vc1_v_loop_filter8(s->dest[j + 1] - 8 * s->uvlinesize, s->uvlinesize, pq);
if (s->mb_x >= 2) {
- v->vc1dsp.vc1_h_loop_filter8(s->dest[j+1] - 16 * s->uvlinesize, s->uvlinesize, pq);
+ v->vc1dsp.vc1_h_loop_filter8(s->dest[j + 1] - 16 * s->uvlinesize, s->uvlinesize, pq);
}
}
}
v->vc1dsp.vc1_v_loop_filter16(s->dest[0] - 8 * s->linesize, s->linesize, pq);
}
- if (s->mb_y == s->mb_height) {
+ if (s->mb_y == s->end_mb_y) {
if (s->mb_x) {
if (s->mb_x >= 2)
v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 16 * s->linesize - 16, s->linesize, pq);
v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 16 * s->linesize - 8, s->linesize, pq);
if (s->mb_x >= 2) {
- for(j = 0; j < 2; j++) {
- v->vc1dsp.vc1_h_loop_filter8(s->dest[j+1] - 8 * s->uvlinesize - 8, s->uvlinesize, pq);
+ for (j = 0; j < 2; j++) {
+ v->vc1dsp.vc1_h_loop_filter8(s->dest[j + 1] - 8 * s->uvlinesize - 8, s->uvlinesize, pq);
}
}
}
@@ -311,8 +381,8 @@ static void vc1_loop_filter_iblk_delayed(VC1Context *v, int pq)
v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 16 * s->linesize, s->linesize, pq);
v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 16 * s->linesize + 8, s->linesize, pq);
if (s->mb_x) {
- for(j = 0; j < 2; j++) {
- v->vc1dsp.vc1_h_loop_filter8(s->dest[j+1] - 8 * s->uvlinesize, s->uvlinesize, pq);
+ for (j = 0; j < 2; j++) {
+ v->vc1dsp.vc1_h_loop_filter8(s->dest[j + 1] - 8 * s->uvlinesize, s->uvlinesize, pq);
}
}
}
@@ -337,14 +407,14 @@ static void vc1_smooth_overlap_filter_iblk(VC1Context *v)
* running the V overlap. Therefore, the V overlap makes us trail by one
* MB col and the H overlap filter makes us trail by one MB row. This
* is reflected in the time at which we run the put_pixels loop. */
- if(v->condover == CONDOVER_ALL || v->pq >= 9 || v->over_flags_plane[mb_pos]) {
- if(s->mb_x && (v->condover == CONDOVER_ALL || v->pq >= 9 ||
- v->over_flags_plane[mb_pos - 1])) {
+ if (v->condover == CONDOVER_ALL || v->pq >= 9 || v->over_flags_plane[mb_pos]) {
+ if (s->mb_x && (v->condover == CONDOVER_ALL || v->pq >= 9 ||
+ v->over_flags_plane[mb_pos - 1])) {
v->vc1dsp.vc1_h_s_overlap(v->block[v->left_blk_idx][1],
v->block[v->cur_blk_idx][0]);
v->vc1dsp.vc1_h_s_overlap(v->block[v->left_blk_idx][3],
v->block[v->cur_blk_idx][2]);
- if(!(s->flags & CODEC_FLAG_GRAY)) {
+ if (!(s->flags & CODEC_FLAG_GRAY)) {
v->vc1dsp.vc1_h_s_overlap(v->block[v->left_blk_idx][4],
v->block[v->cur_blk_idx][4]);
v->vc1dsp.vc1_h_s_overlap(v->block[v->left_blk_idx][5],
@@ -357,13 +427,13 @@ static void vc1_smooth_overlap_filter_iblk(VC1Context *v)
v->block[v->cur_blk_idx][3]);
if (s->mb_x == s->mb_width - 1) {
- if(!s->first_slice_line && (v->condover == CONDOVER_ALL || v->pq >= 9 ||
- v->over_flags_plane[mb_pos - s->mb_stride])) {
+ if (!s->first_slice_line && (v->condover == CONDOVER_ALL || v->pq >= 9 ||
+ v->over_flags_plane[mb_pos - s->mb_stride])) {
v->vc1dsp.vc1_v_s_overlap(v->block[v->top_blk_idx][2],
v->block[v->cur_blk_idx][0]);
v->vc1dsp.vc1_v_s_overlap(v->block[v->top_blk_idx][3],
v->block[v->cur_blk_idx][1]);
- if(!(s->flags & CODEC_FLAG_GRAY)) {
+ if (!(s->flags & CODEC_FLAG_GRAY)) {
v->vc1dsp.vc1_v_s_overlap(v->block[v->top_blk_idx][4],
v->block[v->cur_blk_idx][4]);
v->vc1dsp.vc1_v_s_overlap(v->block[v->top_blk_idx][5],
@@ -377,13 +447,13 @@ static void vc1_smooth_overlap_filter_iblk(VC1Context *v)
}
}
if (s->mb_x && (v->condover == CONDOVER_ALL || v->over_flags_plane[mb_pos - 1])) {
- if(!s->first_slice_line && (v->condover == CONDOVER_ALL || v->pq >= 9 ||
- v->over_flags_plane[mb_pos - s->mb_stride - 1])) {
+ if (!s->first_slice_line && (v->condover == CONDOVER_ALL || v->pq >= 9 ||
+ v->over_flags_plane[mb_pos - s->mb_stride - 1])) {
v->vc1dsp.vc1_v_s_overlap(v->block[v->topleft_blk_idx][2],
v->block[v->left_blk_idx][0]);
v->vc1dsp.vc1_v_s_overlap(v->block[v->topleft_blk_idx][3],
v->block[v->left_blk_idx][1]);
- if(!(s->flags & CODEC_FLAG_GRAY)) {
+ if (!(s->flags & CODEC_FLAG_GRAY)) {
v->vc1dsp.vc1_v_s_overlap(v->block[v->topleft_blk_idx][4],
v->block[v->left_blk_idx][4]);
v->vc1dsp.vc1_v_s_overlap(v->block[v->topleft_blk_idx][5],
@@ -403,371 +473,665 @@ static void vc1_smooth_overlap_filter_iblk(VC1Context *v)
static void vc1_mc_1mv(VC1Context *v, int dir)
{
MpegEncContext *s = &v->s;
- DSPContext *dsp = &v->s.dsp;
+ DSPContext *dsp = &v->s.dsp;
uint8_t *srcY, *srcU, *srcV;
int dxy, mx, my, uvmx, uvmy, src_x, src_y, uvsrc_x, uvsrc_y;
-
- if(!v->s.last_picture.data[0])return;
+ int off, off_uv;
+ int v_edge_pos = s->v_edge_pos >> v->field_mode;
+ if (!v->field_mode && !v->s.last_picture.f.data[0])
+ return;
mx = s->mv[dir][0][0];
my = s->mv[dir][0][1];
// store motion vectors for further use in B frames
- if(s->pict_type == AV_PICTURE_TYPE_P) {
- s->current_picture.motion_val[1][s->block_index[0]][0] = mx;
- s->current_picture.motion_val[1][s->block_index[0]][1] = my;
+ if (s->pict_type == AV_PICTURE_TYPE_P) {
+ s->current_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][0] = mx;
+ s->current_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][1] = my;
}
+
uvmx = (mx + ((mx & 3) == 3)) >> 1;
uvmy = (my + ((my & 3) == 3)) >> 1;
v->luma_mv[s->mb_x][0] = uvmx;
v->luma_mv[s->mb_x][1] = uvmy;
- if(v->fastuvmc) {
- uvmx = uvmx + ((uvmx<0)?(uvmx&1):-(uvmx&1));
- uvmy = uvmy + ((uvmy<0)?(uvmy&1):-(uvmy&1));
- }
- if(!dir) {
- srcY = s->last_picture.data[0];
- srcU = s->last_picture.data[1];
- srcV = s->last_picture.data[2];
+
+ if (v->field_mode &&
+ v->cur_field_type != v->ref_field_type[dir]) {
+ my = my - 2 + 4 * v->cur_field_type;
+ uvmy = uvmy - 2 + 4 * v->cur_field_type;
+ }
+
+ if (v->fastuvmc && (v->fcm != 1)) { // fastuvmc shall be ignored for interlaced frame picture
+ uvmx = uvmx + ((uvmx < 0) ? (uvmx & 1) : -(uvmx & 1));
+ uvmy = uvmy + ((uvmy < 0) ? (uvmy & 1) : -(uvmy & 1));
+ }
+ if (v->field_mode) { // interlaced field picture
+ if (!dir) {
+ if ((v->cur_field_type != v->ref_field_type[dir]) && v->cur_field_type) {
+ srcY = s->current_picture.f.data[0];
+ srcU = s->current_picture.f.data[1];
+ srcV = s->current_picture.f.data[2];
+ } else {
+ srcY = s->last_picture.f.data[0];
+ srcU = s->last_picture.f.data[1];
+ srcV = s->last_picture.f.data[2];
+ }
+ } else {
+ srcY = s->next_picture.f.data[0];
+ srcU = s->next_picture.f.data[1];
+ srcV = s->next_picture.f.data[2];
+ }
} else {
- srcY = s->next_picture.data[0];
- srcU = s->next_picture.data[1];
- srcV = s->next_picture.data[2];
+ if (!dir) {
+ srcY = s->last_picture.f.data[0];
+ srcU = s->last_picture.f.data[1];
+ srcV = s->last_picture.f.data[2];
+ } else {
+ srcY = s->next_picture.f.data[0];
+ srcU = s->next_picture.f.data[1];
+ srcV = s->next_picture.f.data[2];
+ }
}
- src_x = s->mb_x * 16 + (mx >> 2);
- src_y = s->mb_y * 16 + (my >> 2);
- uvsrc_x = s->mb_x * 8 + (uvmx >> 2);
- uvsrc_y = s->mb_y * 8 + (uvmy >> 2);
+ src_x = s->mb_x * 16 + (mx >> 2);
+ src_y = s->mb_y * 16 + (my >> 2);
+ uvsrc_x = s->mb_x * 8 + (uvmx >> 2);
+ uvsrc_y = s->mb_y * 8 + (uvmy >> 2);
- if(v->profile != PROFILE_ADVANCED){
+ if (v->profile != PROFILE_ADVANCED) {
src_x = av_clip( src_x, -16, s->mb_width * 16);
src_y = av_clip( src_y, -16, s->mb_height * 16);
uvsrc_x = av_clip(uvsrc_x, -8, s->mb_width * 8);
uvsrc_y = av_clip(uvsrc_y, -8, s->mb_height * 8);
- }else{
+ } else {
src_x = av_clip( src_x, -17, s->avctx->coded_width);
src_y = av_clip( src_y, -18, s->avctx->coded_height + 1);
uvsrc_x = av_clip(uvsrc_x, -8, s->avctx->coded_width >> 1);
uvsrc_y = av_clip(uvsrc_y, -8, s->avctx->coded_height >> 1);
}
- srcY += src_y * s->linesize + src_x;
+ srcY += src_y * s->linesize + src_x;
srcU += uvsrc_y * s->uvlinesize + uvsrc_x;
srcV += uvsrc_y * s->uvlinesize + uvsrc_x;
+ if (v->field_mode && v->ref_field_type[dir]) {
+ srcY += s->current_picture_ptr->f.linesize[0];
+ srcU += s->current_picture_ptr->f.linesize[1];
+ srcV += s->current_picture_ptr->f.linesize[2];
+ }
+
/* for grayscale we should not try to read from unknown area */
- if(s->flags & CODEC_FLAG_GRAY) {
+ if (s->flags & CODEC_FLAG_GRAY) {
srcU = s->edge_emu_buffer + 18 * s->linesize;
srcV = s->edge_emu_buffer + 18 * s->linesize;
}
- if(v->rangeredfrm || (v->mv_mode == MV_PMODE_INTENSITY_COMP)
- || (unsigned)(src_x - s->mspel) > s->h_edge_pos - (mx&3) - 16 - s->mspel*3
- || (unsigned)(src_y - s->mspel) > s->v_edge_pos - (my&3) - 16 - s->mspel*3){
- uint8_t *uvbuf= s->edge_emu_buffer + 19 * s->linesize;
+ if (v->rangeredfrm || (v->mv_mode == MV_PMODE_INTENSITY_COMP)
+ || (unsigned)(src_x - s->mspel) > s->h_edge_pos - (mx&3) - 16 - s->mspel * 3
+ || (unsigned)(src_y - s->mspel) > v_edge_pos - (my&3) - 16 - s->mspel * 3) {
+ uint8_t *uvbuf = s->edge_emu_buffer + 19 * s->linesize;
srcY -= s->mspel * (1 + s->linesize);
- s->dsp.emulated_edge_mc(s->edge_emu_buffer, srcY, s->linesize, 17+s->mspel*2, 17+s->mspel*2,
- src_x - s->mspel, src_y - s->mspel, s->h_edge_pos, s->v_edge_pos);
+ s->dsp.emulated_edge_mc(s->edge_emu_buffer, srcY, s->linesize,
+ 17 + s->mspel * 2, 17 + s->mspel * 2,
+ src_x - s->mspel, src_y - s->mspel,
+ s->h_edge_pos, v_edge_pos);
srcY = s->edge_emu_buffer;
- s->dsp.emulated_edge_mc(uvbuf , srcU, s->uvlinesize, 8+1, 8+1,
- uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1);
- s->dsp.emulated_edge_mc(uvbuf + 16, srcV, s->uvlinesize, 8+1, 8+1,
- uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1);
+ s->dsp.emulated_edge_mc(uvbuf , srcU, s->uvlinesize, 8 + 1, 8 + 1,
+ uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, v_edge_pos >> 1);
+ s->dsp.emulated_edge_mc(uvbuf + 16, srcV, s->uvlinesize, 8 + 1, 8 + 1,
+ uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, v_edge_pos >> 1);
srcU = uvbuf;
srcV = uvbuf + 16;
/* if we deal with range reduction we need to scale source blocks */
- if(v->rangeredfrm) {
+ if (v->rangeredfrm) {
int i, j;
uint8_t *src, *src2;
src = srcY;
- for(j = 0; j < 17 + s->mspel*2; j++) {
- for(i = 0; i < 17 + s->mspel*2; i++) src[i] = ((src[i] - 128) >> 1) + 128;
+ for (j = 0; j < 17 + s->mspel * 2; j++) {
+ for (i = 0; i < 17 + s->mspel * 2; i++)
+ src[i] = ((src[i] - 128) >> 1) + 128;
src += s->linesize;
}
- src = srcU; src2 = srcV;
- for(j = 0; j < 9; j++) {
- for(i = 0; i < 9; i++) {
- src[i] = ((src[i] - 128) >> 1) + 128;
+ src = srcU;
+ src2 = srcV;
+ for (j = 0; j < 9; j++) {
+ for (i = 0; i < 9; i++) {
+ src[i] = ((src[i] - 128) >> 1) + 128;
src2[i] = ((src2[i] - 128) >> 1) + 128;
}
- src += s->uvlinesize;
+ src += s->uvlinesize;
src2 += s->uvlinesize;
}
}
/* if we deal with intensity compensation we need to scale source blocks */
- if(v->mv_mode == MV_PMODE_INTENSITY_COMP) {
+ if (v->mv_mode == MV_PMODE_INTENSITY_COMP) {
int i, j;
uint8_t *src, *src2;
src = srcY;
- for(j = 0; j < 17 + s->mspel*2; j++) {
- for(i = 0; i < 17 + s->mspel*2; i++) src[i] = v->luty[src[i]];
+ for (j = 0; j < 17 + s->mspel * 2; j++) {
+ for (i = 0; i < 17 + s->mspel * 2; i++)
+ src[i] = v->luty[src[i]];
src += s->linesize;
}
- src = srcU; src2 = srcV;
- for(j = 0; j < 9; j++) {
- for(i = 0; i < 9; i++) {
- src[i] = v->lutuv[src[i]];
+ src = srcU;
+ src2 = srcV;
+ for (j = 0; j < 9; j++) {
+ for (i = 0; i < 9; i++) {
+ src[i] = v->lutuv[src[i]];
src2[i] = v->lutuv[src2[i]];
}
- src += s->uvlinesize;
+ src += s->uvlinesize;
src2 += s->uvlinesize;
}
}
srcY += s->mspel * (1 + s->linesize);
}
- if(s->mspel) {
+ if (v->field_mode && v->cur_field_type) {
+ off = s->current_picture_ptr->f.linesize[0];
+ off_uv = s->current_picture_ptr->f.linesize[1];
+ } else {
+ off = 0;
+ off_uv = 0;
+ }
+ if (s->mspel) {
dxy = ((my & 3) << 2) | (mx & 3);
- v->vc1dsp.put_vc1_mspel_pixels_tab[dxy](s->dest[0] , srcY , s->linesize, v->rnd);
- v->vc1dsp.put_vc1_mspel_pixels_tab[dxy](s->dest[0] + 8, srcY + 8, s->linesize, v->rnd);
+ v->vc1dsp.put_vc1_mspel_pixels_tab[dxy](s->dest[0] + off , srcY , s->linesize, v->rnd);
+ v->vc1dsp.put_vc1_mspel_pixels_tab[dxy](s->dest[0] + off + 8, srcY + 8, s->linesize, v->rnd);
srcY += s->linesize * 8;
- v->vc1dsp.put_vc1_mspel_pixels_tab[dxy](s->dest[0] + 8 * s->linesize , srcY , s->linesize, v->rnd);
- v->vc1dsp.put_vc1_mspel_pixels_tab[dxy](s->dest[0] + 8 * s->linesize + 8, srcY + 8, s->linesize, v->rnd);
+ v->vc1dsp.put_vc1_mspel_pixels_tab[dxy](s->dest[0] + off + 8 * s->linesize , srcY , s->linesize, v->rnd);
+ v->vc1dsp.put_vc1_mspel_pixels_tab[dxy](s->dest[0] + off + 8 * s->linesize + 8, srcY + 8, s->linesize, v->rnd);
} else { // hpel mc - always used for luma
dxy = (my & 2) | ((mx & 2) >> 1);
-
- if(!v->rnd)
- dsp->put_pixels_tab[0][dxy](s->dest[0], srcY, s->linesize, 16);
+ if (!v->rnd)
+ dsp->put_pixels_tab[0][dxy](s->dest[0] + off, srcY, s->linesize, 16);
else
- dsp->put_no_rnd_pixels_tab[0][dxy](s->dest[0], srcY, s->linesize, 16);
+ dsp->put_no_rnd_pixels_tab[0][dxy](s->dest[0] + off, srcY, s->linesize, 16);
}
- if(s->flags & CODEC_FLAG_GRAY) return;
+ if (s->flags & CODEC_FLAG_GRAY) return;
/* Chroma MC always uses qpel bilinear */
- uvmx = (uvmx&3)<<1;
- uvmy = (uvmy&3)<<1;
- if(!v->rnd){
- dsp->put_h264_chroma_pixels_tab[0](s->dest[1], srcU, s->uvlinesize, 8, uvmx, uvmy);
- dsp->put_h264_chroma_pixels_tab[0](s->dest[2], srcV, s->uvlinesize, 8, uvmx, uvmy);
- }else{
- v->vc1dsp.put_no_rnd_vc1_chroma_pixels_tab[0](s->dest[1], srcU, s->uvlinesize, 8, uvmx, uvmy);
- v->vc1dsp.put_no_rnd_vc1_chroma_pixels_tab[0](s->dest[2], srcV, s->uvlinesize, 8, uvmx, uvmy);
+ uvmx = (uvmx & 3) << 1;
+ uvmy = (uvmy & 3) << 1;
+ if (!v->rnd) {
+ dsp->put_h264_chroma_pixels_tab[0](s->dest[1] + off_uv, srcU, s->uvlinesize, 8, uvmx, uvmy);
+ dsp->put_h264_chroma_pixels_tab[0](s->dest[2] + off_uv, srcV, s->uvlinesize, 8, uvmx, uvmy);
+ } else {
+ v->vc1dsp.put_no_rnd_vc1_chroma_pixels_tab[0](s->dest[1] + off_uv, srcU, s->uvlinesize, 8, uvmx, uvmy);
+ v->vc1dsp.put_no_rnd_vc1_chroma_pixels_tab[0](s->dest[2] + off_uv, srcV, s->uvlinesize, 8, uvmx, uvmy);
+ }
+}
+
+static inline int median4(int a, int b, int c, int d)
+{
+ if (a < b) {
+ if (c < d) return (FFMIN(b, d) + FFMAX(a, c)) / 2;
+ else return (FFMIN(b, c) + FFMAX(a, d)) / 2;
+ } else {
+ if (c < d) return (FFMIN(a, d) + FFMAX(b, c)) / 2;
+ else return (FFMIN(a, c) + FFMAX(b, d)) / 2;
}
}
/** Do motion compensation for 4-MV macroblock - luminance block
*/
-static void vc1_mc_4mv_luma(VC1Context *v, int n)
+static void vc1_mc_4mv_luma(VC1Context *v, int n, int dir)
{
MpegEncContext *s = &v->s;
DSPContext *dsp = &v->s.dsp;
uint8_t *srcY;
int dxy, mx, my, src_x, src_y;
int off;
+ int fieldmv = (v->fcm == 1) ? v->blk_mv_type[s->block_index[n]] : 0;
+ int v_edge_pos = s->v_edge_pos >> v->field_mode;
+
+ if (!v->field_mode && !v->s.last_picture.f.data[0])
+ return;
- if(!v->s.last_picture.data[0])return;
- mx = s->mv[0][n][0];
- my = s->mv[0][n][1];
- srcY = s->last_picture.data[0];
+ mx = s->mv[dir][n][0];
+ my = s->mv[dir][n][1];
- off = s->linesize * 4 * (n&2) + (n&1) * 8;
+ if (!dir) {
+ if (v->field_mode) {
+ if ((v->cur_field_type != v->ref_field_type[dir]) && v->cur_field_type)
+ srcY = s->current_picture.f.data[0];
+ else
+ srcY = s->last_picture.f.data[0];
+ } else
+ srcY = s->last_picture.f.data[0];
+ } else
+ srcY = s->next_picture.f.data[0];
+
+ if (v->field_mode) {
+ if (v->cur_field_type != v->ref_field_type[dir])
+ my = my - 2 + 4 * v->cur_field_type;
+ }
+
+ if (s->pict_type == AV_PICTURE_TYPE_P && n == 3 && v->field_mode) {
+ int same_count = 0, opp_count = 0, k;
+ int chosen_mv[2][4][2], f;
+ int tx, ty;
+ for (k = 0; k < 4; k++) {
+ f = v->mv_f[0][s->block_index[k] + v->blocks_off];
+ chosen_mv[f][f ? opp_count : same_count][0] = s->mv[0][k][0];
+ chosen_mv[f][f ? opp_count : same_count][1] = s->mv[0][k][1];
+ opp_count += f;
+ same_count += 1 - f;
+ }
+ f = opp_count > same_count;
+ switch (f ? opp_count : same_count) {
+ case 4:
+ tx = median4(chosen_mv[f][0][0], chosen_mv[f][1][0],
+ chosen_mv[f][2][0], chosen_mv[f][3][0]);
+ ty = median4(chosen_mv[f][0][1], chosen_mv[f][1][1],
+ chosen_mv[f][2][1], chosen_mv[f][3][1]);
+ break;
+ case 3:
+ tx = mid_pred(chosen_mv[f][0][0], chosen_mv[f][1][0], chosen_mv[f][2][0]);
+ ty = mid_pred(chosen_mv[f][0][1], chosen_mv[f][1][1], chosen_mv[f][2][1]);
+ break;
+ case 2:
+ tx = (chosen_mv[f][0][0] + chosen_mv[f][1][0]) / 2;
+ ty = (chosen_mv[f][0][1] + chosen_mv[f][1][1]) / 2;
+ break;
+ }
+ s->current_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][0] = tx;
+ s->current_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][1] = ty;
+ for (k = 0; k < 4; k++)
+ v->mv_f[1][s->block_index[k] + v->blocks_off] = f;
+ }
+
+ if (v->fcm == 1) { // not sure if needed for other types of picture
+ int qx, qy;
+ int width = s->avctx->coded_width;
+ int height = s->avctx->coded_height >> 1;
+ qx = (s->mb_x * 16) + (mx >> 2);
+ qy = (s->mb_y * 8) + (my >> 3);
+
+ if (qx < -17)
+ mx -= 4 * (qx + 17);
+ else if (qx > width)
+ mx -= 4 * (qx - width);
+ if (qy < -18)
+ my -= 8 * (qy + 18);
+ else if (qy > height + 1)
+ my -= 8 * (qy - height - 1);
+ }
+
+ if ((v->fcm == 1) && fieldmv)
+ off = ((n > 1) ? s->linesize : 0) + (n & 1) * 8;
+ else
+ off = s->linesize * 4 * (n & 2) + (n & 1) * 8;
+ if (v->field_mode && v->cur_field_type)
+ off += s->current_picture_ptr->f.linesize[0];
- src_x = s->mb_x * 16 + (n&1) * 8 + (mx >> 2);
- src_y = s->mb_y * 16 + (n&2) * 4 + (my >> 2);
+ src_x = s->mb_x * 16 + (n & 1) * 8 + (mx >> 2);
+ if (!fieldmv)
+ src_y = s->mb_y * 16 + (n & 2) * 4 + (my >> 2);
+ else
+ src_y = s->mb_y * 16 + ((n > 1) ? 1 : 0) + (my >> 2);
- if(v->profile != PROFILE_ADVANCED){
- src_x = av_clip( src_x, -16, s->mb_width * 16);
- src_y = av_clip( src_y, -16, s->mb_height * 16);
- }else{
- src_x = av_clip( src_x, -17, s->avctx->coded_width);
- src_y = av_clip( src_y, -18, s->avctx->coded_height + 1);
+ if (v->profile != PROFILE_ADVANCED) {
+ src_x = av_clip(src_x, -16, s->mb_width * 16);
+ src_y = av_clip(src_y, -16, s->mb_height * 16);
+ } else {
+ src_x = av_clip(src_x, -17, s->avctx->coded_width);
+ if (v->fcm == 1) {
+ if (src_y & 1)
+ src_y = av_clip(src_y, -17, s->avctx->coded_height + 1);
+ else
+ src_y = av_clip(src_y, -18, s->avctx->coded_height);
+ } else {
+ src_y = av_clip(src_y, -18, s->avctx->coded_height + 1);
+ }
}
srcY += src_y * s->linesize + src_x;
-
- if(v->rangeredfrm || (v->mv_mode == MV_PMODE_INTENSITY_COMP)
- || (unsigned)(src_x - s->mspel) > s->h_edge_pos - (mx&3) - 8 - s->mspel*2
- || (unsigned)(src_y - s->mspel) > s->v_edge_pos - (my&3) - 8 - s->mspel*2){
- srcY -= s->mspel * (1 + s->linesize);
- s->dsp.emulated_edge_mc(s->edge_emu_buffer, srcY, s->linesize, 9+s->mspel*2, 9+s->mspel*2,
- src_x - s->mspel, src_y - s->mspel, s->h_edge_pos, s->v_edge_pos);
+ if (v->field_mode && v->ref_field_type[dir])
+ srcY += s->current_picture_ptr->f.linesize[0];
+
+ if (fieldmv && !(src_y & 1))
+ v_edge_pos--;
+ if (fieldmv && (src_y & 1) && src_y < 4)
+ src_y--;
+ if (v->rangeredfrm || (v->mv_mode == MV_PMODE_INTENSITY_COMP)
+ || (unsigned)(src_x - s->mspel) > s->h_edge_pos - (mx & 3) - 8 - s->mspel * 2
+ || (unsigned)(src_y - (s->mspel << fieldmv)) > v_edge_pos - (my & 3) - ((8 + s->mspel * 2) << fieldmv)) {
+ srcY -= s->mspel * (1 + (s->linesize << fieldmv));
+ /* check emulate edge stride and offset */
+ s->dsp.emulated_edge_mc(s->edge_emu_buffer, srcY, s->linesize,
+ 9 + s->mspel * 2, (9 + s->mspel * 2) << fieldmv,
+ src_x - s->mspel, src_y - (s->mspel << fieldmv),
+ s->h_edge_pos, v_edge_pos);
srcY = s->edge_emu_buffer;
/* if we deal with range reduction we need to scale source blocks */
- if(v->rangeredfrm) {
+ if (v->rangeredfrm) {
int i, j;
uint8_t *src;
src = srcY;
- for(j = 0; j < 9 + s->mspel*2; j++) {
- for(i = 0; i < 9 + s->mspel*2; i++) src[i] = ((src[i] - 128) >> 1) + 128;
- src += s->linesize;
+ for (j = 0; j < 9 + s->mspel * 2; j++) {
+ for (i = 0; i < 9 + s->mspel * 2; i++)
+ src[i] = ((src[i] - 128) >> 1) + 128;
+ src += s->linesize << fieldmv;
}
}
/* if we deal with intensity compensation we need to scale source blocks */
- if(v->mv_mode == MV_PMODE_INTENSITY_COMP) {
+ if (v->mv_mode == MV_PMODE_INTENSITY_COMP) {
int i, j;
uint8_t *src;
src = srcY;
- for(j = 0; j < 9 + s->mspel*2; j++) {
- for(i = 0; i < 9 + s->mspel*2; i++) src[i] = v->luty[src[i]];
- src += s->linesize;
+ for (j = 0; j < 9 + s->mspel * 2; j++) {
+ for (i = 0; i < 9 + s->mspel * 2; i++)
+ src[i] = v->luty[src[i]];
+ src += s->linesize << fieldmv;
}
}
- srcY += s->mspel * (1 + s->linesize);
+ srcY += s->mspel * (1 + (s->linesize << fieldmv));
}
- if(s->mspel) {
+ if (s->mspel) {
dxy = ((my & 3) << 2) | (mx & 3);
- v->vc1dsp.put_vc1_mspel_pixels_tab[dxy](s->dest[0] + off, srcY, s->linesize, v->rnd);
+ v->vc1dsp.put_vc1_mspel_pixels_tab[dxy](s->dest[0] + off, srcY, s->linesize << fieldmv, v->rnd);
} else { // hpel mc - always used for luma
dxy = (my & 2) | ((mx & 2) >> 1);
- if(!v->rnd)
+ if (!v->rnd)
dsp->put_pixels_tab[1][dxy](s->dest[0] + off, srcY, s->linesize, 8);
else
dsp->put_no_rnd_pixels_tab[1][dxy](s->dest[0] + off, srcY, s->linesize, 8);
}
}
-static inline int median4(int a, int b, int c, int d)
+static av_always_inline int get_chroma_mv(int *mvx, int *mvy, int *a, int flag, int *tx, int *ty)
{
- if(a < b) {
- if(c < d) return (FFMIN(b, d) + FFMAX(a, c)) / 2;
- else return (FFMIN(b, c) + FFMAX(a, d)) / 2;
+ int idx, i;
+ static const int count[16] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4};
+
+ idx = ((a[3] != flag) << 3)
+ | ((a[2] != flag) << 2)
+ | ((a[1] != flag) << 1)
+ | (a[0] != flag);
+ if (!idx) {
+ *tx = median4(mvx[0], mvx[1], mvx[2], mvx[3]);
+ *ty = median4(mvy[0], mvy[1], mvy[2], mvy[3]);
+ return 4;
+ } else if (count[idx] == 1) {
+ switch (idx) {
+ case 0x1:
+ *tx = mid_pred(mvx[1], mvx[2], mvx[3]);
+ *ty = mid_pred(mvy[1], mvy[2], mvy[3]);
+ return 3;
+ case 0x2:
+ *tx = mid_pred(mvx[0], mvx[2], mvx[3]);
+ *ty = mid_pred(mvy[0], mvy[2], mvy[3]);
+ return 3;
+ case 0x4:
+ *tx = mid_pred(mvx[0], mvx[1], mvx[3]);
+ *ty = mid_pred(mvy[0], mvy[1], mvy[3]);
+ return 3;
+ case 0x8:
+ *tx = mid_pred(mvx[0], mvx[1], mvx[2]);
+ *ty = mid_pred(mvy[0], mvy[1], mvy[2]);
+ return 3;
+ }
+ } else if (count[idx] == 2) {
+ int t1 = 0, t2 = 0;
+ for (i = 0; i < 3; i++)
+ if (!a[i]) {
+ t1 = i;
+ break;
+ }
+ for (i = t1 + 1; i < 4; i++)
+ if (!a[i]) {
+ t2 = i;
+ break;
+ }
+ *tx = (mvx[t1] + mvx[t2]) / 2;
+ *ty = (mvy[t1] + mvy[t2]) / 2;
+ return 2;
} else {
- if(c < d) return (FFMIN(a, d) + FFMAX(b, c)) / 2;
- else return (FFMIN(a, c) + FFMAX(b, d)) / 2;
+ return 0;
}
+ return -1;
}
-
/** Do motion compensation for 4-MV macroblock - both chroma blocks
*/
-static void vc1_mc_4mv_chroma(VC1Context *v)
+static void vc1_mc_4mv_chroma(VC1Context *v, int dir)
{
MpegEncContext *s = &v->s;
- DSPContext *dsp = &v->s.dsp;
+ DSPContext *dsp = &v->s.dsp;
uint8_t *srcU, *srcV;
int uvmx, uvmy, uvsrc_x, uvsrc_y;
- int i, idx, tx = 0, ty = 0;
- int mvx[4], mvy[4], intra[4];
- static const int count[16] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4};
+ int k, tx = 0, ty = 0;
+ int mvx[4], mvy[4], intra[4], mv_f[4];
+ int valid_count;
+ int chroma_ref_type = v->cur_field_type, off = 0;
+ int v_edge_pos = s->v_edge_pos >> v->field_mode;
- if(!v->s.last_picture.data[0])return;
- if(s->flags & CODEC_FLAG_GRAY) return;
+ if (!v->field_mode && !v->s.last_picture.f.data[0])
+ return;
+ if (s->flags & CODEC_FLAG_GRAY)
+ return;
- for(i = 0; i < 4; i++) {
- mvx[i] = s->mv[0][i][0];
- mvy[i] = s->mv[0][i][1];
- intra[i] = v->mb_type[0][s->block_index[i]];
+ for (k = 0; k < 4; k++) {
+ mvx[k] = s->mv[dir][k][0];
+ mvy[k] = s->mv[dir][k][1];
+ intra[k] = v->mb_type[0][s->block_index[k]];
+ if (v->field_mode)
+ mv_f[k] = v->mv_f[dir][s->block_index[k] + v->blocks_off];
}
/* calculate chroma MV vector from four luma MVs */
- idx = (intra[3] << 3) | (intra[2] << 2) | (intra[1] << 1) | intra[0];
- if(!idx) { // all blocks are inter
- tx = median4(mvx[0], mvx[1], mvx[2], mvx[3]);
- ty = median4(mvy[0], mvy[1], mvy[2], mvy[3]);
- } else if(count[idx] == 1) { // 3 inter blocks
- switch(idx) {
- case 0x1:
- tx = mid_pred(mvx[1], mvx[2], mvx[3]);
- ty = mid_pred(mvy[1], mvy[2], mvy[3]);
- break;
- case 0x2:
- tx = mid_pred(mvx[0], mvx[2], mvx[3]);
- ty = mid_pred(mvy[0], mvy[2], mvy[3]);
- break;
- case 0x4:
- tx = mid_pred(mvx[0], mvx[1], mvx[3]);
- ty = mid_pred(mvy[0], mvy[1], mvy[3]);
- break;
- case 0x8:
- tx = mid_pred(mvx[0], mvx[1], mvx[2]);
- ty = mid_pred(mvy[0], mvy[1], mvy[2]);
- break;
+ if (!v->field_mode || (v->field_mode && !v->numref)) {
+ valid_count = get_chroma_mv(mvx, mvy, intra, 0, &tx, &ty);
+ if (!valid_count) {
+ v->luma_mv[s->mb_x][0] = v->luma_mv[s->mb_x][1] = 0;
+ return; //no need to do MC for intra blocks
}
- } else if(count[idx] == 2) {
- int t1 = 0, t2 = 0;
- for(i=0; i<3;i++) if(!intra[i]) {t1 = i; break;}
- for(i= t1+1; i<4; i++)if(!intra[i]) {t2 = i; break;}
- tx = (mvx[t1] + mvx[t2]) / 2;
- ty = (mvy[t1] + mvy[t2]) / 2;
} else {
- s->current_picture.motion_val[1][s->block_index[0]][0] = 0;
- s->current_picture.motion_val[1][s->block_index[0]][1] = 0;
- v->luma_mv[s->mb_x][0] = v->luma_mv[s->mb_x][1] = 0;
- return; //no need to do MC for inter blocks
+ int dominant = 0;
+ if (mv_f[0] + mv_f[1] + mv_f[2] + mv_f[3] > 2)
+ dominant = 1;
+ valid_count = get_chroma_mv(mvx, mvy, mv_f, dominant, &tx, &ty);
+ if (dominant)
+ chroma_ref_type = !v->cur_field_type;
}
+ uvmx = (tx + ((tx & 3) == 3)) >> 1;
+ uvmy = (ty + ((ty & 3) == 3)) >> 1;
- s->current_picture.motion_val[1][s->block_index[0]][0] = tx;
- s->current_picture.motion_val[1][s->block_index[0]][1] = ty;
- uvmx = (tx + ((tx&3) == 3)) >> 1;
- uvmy = (ty + ((ty&3) == 3)) >> 1;
v->luma_mv[s->mb_x][0] = uvmx;
v->luma_mv[s->mb_x][1] = uvmy;
- if(v->fastuvmc) {
- uvmx = uvmx + ((uvmx<0)?(uvmx&1):-(uvmx&1));
- uvmy = uvmy + ((uvmy<0)?(uvmy&1):-(uvmy&1));
+
+ if (v->fastuvmc) {
+ uvmx = uvmx + ((uvmx < 0) ? (uvmx & 1) : -(uvmx & 1));
+ uvmy = uvmy + ((uvmy < 0) ? (uvmy & 1) : -(uvmy & 1));
}
+ // Field conversion bias
+ if (v->cur_field_type != chroma_ref_type)
+ uvmy += 2 - 4 * chroma_ref_type;
uvsrc_x = s->mb_x * 8 + (uvmx >> 2);
uvsrc_y = s->mb_y * 8 + (uvmy >> 2);
- if(v->profile != PROFILE_ADVANCED){
- uvsrc_x = av_clip(uvsrc_x, -8, s->mb_width * 8);
- uvsrc_y = av_clip(uvsrc_y, -8, s->mb_height * 8);
- }else{
- uvsrc_x = av_clip(uvsrc_x, -8, s->avctx->coded_width >> 1);
- uvsrc_y = av_clip(uvsrc_y, -8, s->avctx->coded_height >> 1);
+ if (v->profile != PROFILE_ADVANCED) {
+ uvsrc_x = av_clip(uvsrc_x, -8, s->mb_width * 8);
+ uvsrc_y = av_clip(uvsrc_y, -8, s->mb_height * 8);
+ } else {
+ uvsrc_x = av_clip(uvsrc_x, -8, s->avctx->coded_width >> 1);
+ uvsrc_y = av_clip(uvsrc_y, -8, s->avctx->coded_height >> 1);
}
- srcU = s->last_picture.data[1] + uvsrc_y * s->uvlinesize + uvsrc_x;
- srcV = s->last_picture.data[2] + uvsrc_y * s->uvlinesize + uvsrc_x;
- if(v->rangeredfrm || (v->mv_mode == MV_PMODE_INTENSITY_COMP)
- || (unsigned)uvsrc_x > (s->h_edge_pos >> 1) - 9
- || (unsigned)uvsrc_y > (s->v_edge_pos >> 1) - 9){
- s->dsp.emulated_edge_mc(s->edge_emu_buffer , srcU, s->uvlinesize, 8+1, 8+1,
- uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1);
- s->dsp.emulated_edge_mc(s->edge_emu_buffer + 16, srcV, s->uvlinesize, 8+1, 8+1,
- uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1);
+ if (!dir) {
+ if (v->field_mode) {
+ if ((v->cur_field_type != chroma_ref_type) && v->cur_field_type) {
+ srcU = s->current_picture.f.data[1] + uvsrc_y * s->uvlinesize + uvsrc_x;
+ srcV = s->current_picture.f.data[2] + uvsrc_y * s->uvlinesize + uvsrc_x;
+ } else {
+ srcU = s->last_picture.f.data[1] + uvsrc_y * s->uvlinesize + uvsrc_x;
+ srcV = s->last_picture.f.data[2] + uvsrc_y * s->uvlinesize + uvsrc_x;
+ }
+ } else {
+ srcU = s->last_picture.f.data[1] + uvsrc_y * s->uvlinesize + uvsrc_x;
+ srcV = s->last_picture.f.data[2] + uvsrc_y * s->uvlinesize + uvsrc_x;
+ }
+ } else {
+ srcU = s->next_picture.f.data[1] + uvsrc_y * s->uvlinesize + uvsrc_x;
+ srcV = s->next_picture.f.data[2] + uvsrc_y * s->uvlinesize + uvsrc_x;
+ }
+
+ if (v->field_mode) {
+ if (chroma_ref_type) {
+ srcU += s->current_picture_ptr->f.linesize[1];
+ srcV += s->current_picture_ptr->f.linesize[2];
+ }
+ off = v->cur_field_type ? s->current_picture_ptr->f.linesize[1] : 0;
+ }
+
+ if (v->rangeredfrm || (v->mv_mode == MV_PMODE_INTENSITY_COMP)
+ || (unsigned)uvsrc_x > (s->h_edge_pos >> 1) - 9
+ || (unsigned)uvsrc_y > (v_edge_pos >> 1) - 9) {
+ s->dsp.emulated_edge_mc(s->edge_emu_buffer , srcU, s->uvlinesize,
+ 8 + 1, 8 + 1, uvsrc_x, uvsrc_y,
+ s->h_edge_pos >> 1, v_edge_pos >> 1);
+ s->dsp.emulated_edge_mc(s->edge_emu_buffer + 16, srcV, s->uvlinesize,
+ 8 + 1, 8 + 1, uvsrc_x, uvsrc_y,
+ s->h_edge_pos >> 1, v_edge_pos >> 1);
srcU = s->edge_emu_buffer;
srcV = s->edge_emu_buffer + 16;
/* if we deal with range reduction we need to scale source blocks */
- if(v->rangeredfrm) {
+ if (v->rangeredfrm) {
int i, j;
uint8_t *src, *src2;
- src = srcU; src2 = srcV;
- for(j = 0; j < 9; j++) {
- for(i = 0; i < 9; i++) {
- src[i] = ((src[i] - 128) >> 1) + 128;
+ src = srcU;
+ src2 = srcV;
+ for (j = 0; j < 9; j++) {
+ for (i = 0; i < 9; i++) {
+ src[i] = ((src[i] - 128) >> 1) + 128;
src2[i] = ((src2[i] - 128) >> 1) + 128;
}
- src += s->uvlinesize;
+ src += s->uvlinesize;
src2 += s->uvlinesize;
}
}
/* if we deal with intensity compensation we need to scale source blocks */
- if(v->mv_mode == MV_PMODE_INTENSITY_COMP) {
+ if (v->mv_mode == MV_PMODE_INTENSITY_COMP) {
int i, j;
uint8_t *src, *src2;
- src = srcU; src2 = srcV;
- for(j = 0; j < 9; j++) {
- for(i = 0; i < 9; i++) {
- src[i] = v->lutuv[src[i]];
+ src = srcU;
+ src2 = srcV;
+ for (j = 0; j < 9; j++) {
+ for (i = 0; i < 9; i++) {
+ src[i] = v->lutuv[src[i]];
src2[i] = v->lutuv[src2[i]];
}
- src += s->uvlinesize;
+ src += s->uvlinesize;
src2 += s->uvlinesize;
}
}
}
/* Chroma MC always uses qpel bilinear */
- uvmx = (uvmx&3)<<1;
- uvmy = (uvmy&3)<<1;
- if(!v->rnd){
- dsp->put_h264_chroma_pixels_tab[0](s->dest[1], srcU, s->uvlinesize, 8, uvmx, uvmy);
- dsp->put_h264_chroma_pixels_tab[0](s->dest[2], srcV, s->uvlinesize, 8, uvmx, uvmy);
- }else{
- v->vc1dsp.put_no_rnd_vc1_chroma_pixels_tab[0](s->dest[1], srcU, s->uvlinesize, 8, uvmx, uvmy);
- v->vc1dsp.put_no_rnd_vc1_chroma_pixels_tab[0](s->dest[2], srcV, s->uvlinesize, 8, uvmx, uvmy);
+ uvmx = (uvmx & 3) << 1;
+ uvmy = (uvmy & 3) << 1;
+ if (!v->rnd) {
+ dsp->put_h264_chroma_pixels_tab[0](s->dest[1] + off, srcU, s->uvlinesize, 8, uvmx, uvmy);
+ dsp->put_h264_chroma_pixels_tab[0](s->dest[2] + off, srcV, s->uvlinesize, 8, uvmx, uvmy);
+ } else {
+ v->vc1dsp.put_no_rnd_vc1_chroma_pixels_tab[0](s->dest[1] + off, srcU, s->uvlinesize, 8, uvmx, uvmy);
+ v->vc1dsp.put_no_rnd_vc1_chroma_pixels_tab[0](s->dest[2] + off, srcV, s->uvlinesize, 8, uvmx, uvmy);
+ }
+}
+
+/** Do motion compensation for 4-MV field chroma macroblock (both U and V)
+ */
+static void vc1_mc_4mv_chroma4(VC1Context *v)
+{
+ MpegEncContext *s = &v->s;
+ DSPContext *dsp = &v->s.dsp;
+ uint8_t *srcU, *srcV;
+ int uvsrc_x, uvsrc_y;
+ int uvmx_field[4], uvmy_field[4];
+ int i, off, tx, ty;
+ int fieldmv = v->blk_mv_type[s->block_index[0]];
+ static const int s_rndtblfield[16] = { 0, 0, 1, 2, 4, 4, 5, 6, 2, 2, 3, 8, 6, 6, 7, 12 };
+ int v_dist = fieldmv ? 1 : 4; // vertical offset for lower sub-blocks
+ int v_edge_pos = s->v_edge_pos >> 1;
+
+ if (!v->s.last_picture.f.data[0])
+ return;
+ if (s->flags & CODEC_FLAG_GRAY)
+ return;
+
+ for (i = 0; i < 4; i++) {
+ tx = s->mv[0][i][0];
+ uvmx_field[i] = (tx + ((tx & 3) == 3)) >> 1;
+ ty = s->mv[0][i][1];
+ if (fieldmv)
+ uvmy_field[i] = (ty >> 4) * 8 + s_rndtblfield[ty & 0xF];
+ else
+ uvmy_field[i] = (ty + ((ty & 3) == 3)) >> 1;
+ }
+
+ for (i = 0; i < 4; i++) {
+ off = (i & 1) * 4 + ((i & 2) ? v_dist * s->uvlinesize : 0);
+ uvsrc_x = s->mb_x * 8 + (i & 1) * 4 + (uvmx_field[i] >> 2);
+ uvsrc_y = s->mb_y * 8 + ((i & 2) ? v_dist : 0) + (uvmy_field[i] >> 2);
+ // FIXME: implement proper pull-back (see vc1cropmv.c, vc1CROPMV_ChromaPullBack())
+ uvsrc_x = av_clip(uvsrc_x, -8, s->avctx->coded_width >> 1);
+ uvsrc_y = av_clip(uvsrc_y, -8, s->avctx->coded_height >> 1);
+ srcU = s->last_picture.f.data[1] + uvsrc_y * s->uvlinesize + uvsrc_x;
+ srcV = s->last_picture.f.data[2] + uvsrc_y * s->uvlinesize + uvsrc_x;
+ uvmx_field[i] = (uvmx_field[i] & 3) << 1;
+ uvmy_field[i] = (uvmy_field[i] & 3) << 1;
+
+ if (fieldmv && !(uvsrc_y & 1))
+ v_edge_pos--;
+ if (fieldmv && (uvsrc_y & 1) && uvsrc_y < 2)
+ uvsrc_y--;
+ if ((v->mv_mode == MV_PMODE_INTENSITY_COMP)
+ || (unsigned)uvsrc_x > (s->h_edge_pos >> 1) - 5
+ || (unsigned)uvsrc_y > v_edge_pos - (5 << fieldmv)) {
+ s->dsp.emulated_edge_mc(s->edge_emu_buffer, srcU, s->uvlinesize,
+ 5, (5 << fieldmv), uvsrc_x, uvsrc_y,
+ s->h_edge_pos >> 1, v_edge_pos);
+ s->dsp.emulated_edge_mc(s->edge_emu_buffer + 16, srcV, s->uvlinesize,
+ 5, (5 << fieldmv), uvsrc_x, uvsrc_y,
+ s->h_edge_pos >> 1, v_edge_pos);
+ srcU = s->edge_emu_buffer;
+ srcV = s->edge_emu_buffer + 16;
+
+ /* if we deal with intensity compensation we need to scale source blocks */
+ if (v->mv_mode == MV_PMODE_INTENSITY_COMP) {
+ int i, j;
+ uint8_t *src, *src2;
+
+ src = srcU;
+ src2 = srcV;
+ for (j = 0; j < 5; j++) {
+ for (i = 0; i < 5; i++) {
+ src[i] = v->lutuv[src[i]];
+ src2[i] = v->lutuv[src2[i]];
+ }
+ src += s->uvlinesize << 1;
+ src2 += s->uvlinesize << 1;
+ }
+ }
+ }
+ if (!v->rnd) {
+ dsp->put_h264_chroma_pixels_tab[1](s->dest[1] + off, srcU, s->uvlinesize << fieldmv, 4, uvmx_field[i], uvmy_field[i]);
+ dsp->put_h264_chroma_pixels_tab[1](s->dest[2] + off, srcV, s->uvlinesize << fieldmv, 4, uvmx_field[i], uvmy_field[i]);
+ } else {
+ v->vc1dsp.put_no_rnd_vc1_chroma_pixels_tab[1](s->dest[1] + off, srcU, s->uvlinesize << fieldmv, 4, uvmx_field[i], uvmy_field[i]);
+ v->vc1dsp.put_no_rnd_vc1_chroma_pixels_tab[1](s->dest[2] + off, srcV, s->uvlinesize << fieldmv, 4, uvmx_field[i], uvmy_field[i]);
+ }
}
}
@@ -783,37 +1147,34 @@ static void vc1_mc_4mv_chroma(VC1Context *v)
* @brief Get macroblock-level quantizer scale
*/
#define GET_MQUANT() \
- if (v->dquantfrm) \
- { \
- int edges = 0; \
- if (v->dqprofile == DQPROFILE_ALL_MBS) \
- { \
- if (v->dqbilevel) \
- { \
- mquant = (get_bits1(gb)) ? v->altpq : v->pq; \
- } \
- else \
- { \
- mqdiff = get_bits(gb, 3); \
- if (mqdiff != 7) mquant = v->pq + mqdiff; \
- else mquant = get_bits(gb, 5); \
- } \
- } \
- if(v->dqprofile == DQPROFILE_SINGLE_EDGE) \
- edges = 1 << v->dqsbedge; \
- else if(v->dqprofile == DQPROFILE_DOUBLE_EDGES) \
- edges = (3 << v->dqsbedge) % 15; \
- else if(v->dqprofile == DQPROFILE_FOUR_EDGES) \
- edges = 15; \
- if((edges&1) && !s->mb_x) \
- mquant = v->altpq; \
- if((edges&2) && s->first_slice_line) \
- mquant = v->altpq; \
- if((edges&4) && s->mb_x == (s->mb_width - 1)) \
- mquant = v->altpq; \
- if((edges&8) && s->mb_y == (s->mb_height - 1)) \
- mquant = v->altpq; \
- }
+ if (v->dquantfrm) { \
+ int edges = 0; \
+ if (v->dqprofile == DQPROFILE_ALL_MBS) { \
+ if (v->dqbilevel) { \
+ mquant = (get_bits1(gb)) ? v->altpq : v->pq; \
+ } else { \
+ mqdiff = get_bits(gb, 3); \
+ if (mqdiff != 7) \
+ mquant = v->pq + mqdiff; \
+ else \
+ mquant = get_bits(gb, 5); \
+ } \
+ } \
+ if (v->dqprofile == DQPROFILE_SINGLE_EDGE) \
+ edges = 1 << v->dqsbedge; \
+ else if (v->dqprofile == DQPROFILE_DOUBLE_EDGES) \
+ edges = (3 << v->dqsbedge) % 15; \
+ else if (v->dqprofile == DQPROFILE_FOUR_EDGES) \
+ edges = 15; \
+ if ((edges&1) && !s->mb_x) \
+ mquant = v->altpq; \
+ if ((edges&2) && s->first_slice_line) \
+ mquant = v->altpq; \
+ if ((edges&4) && s->mb_x == (s->mb_width - 1)) \
+ mquant = v->altpq; \
+ if ((edges&8) && s->mb_y == (s->mb_height - 1)) \
+ mquant = v->altpq; \
+ }
/**
* @def GET_MVDATA(_dmv_x, _dmv_y)
@@ -822,96 +1183,340 @@ static void vc1_mc_4mv_chroma(VC1Context *v)
* @param _dmv_x Horizontal differential for decoded MV
* @param _dmv_y Vertical differential for decoded MV
*/
-#define GET_MVDATA(_dmv_x, _dmv_y) \
- index = 1 + get_vlc2(gb, ff_vc1_mv_diff_vlc[s->mv_table_index].table,\
- VC1_MV_DIFF_VLC_BITS, 2); \
- if (index > 36) \
- { \
- mb_has_coeffs = 1; \
- index -= 37; \
- } \
- else mb_has_coeffs = 0; \
- s->mb_intra = 0; \
- if (!index) { _dmv_x = _dmv_y = 0; } \
- else if (index == 35) \
- { \
- _dmv_x = get_bits(gb, v->k_x - 1 + s->quarter_sample); \
- _dmv_y = get_bits(gb, v->k_y - 1 + s->quarter_sample); \
- } \
- else if (index == 36) \
- { \
- _dmv_x = 0; \
- _dmv_y = 0; \
- s->mb_intra = 1; \
- } \
- else \
- { \
- index1 = index%6; \
- if (!s->quarter_sample && index1 == 5) val = 1; \
- else val = 0; \
- if(size_table[index1] - val > 0) \
- val = get_bits(gb, size_table[index1] - val); \
- else val = 0; \
- sign = 0 - (val&1); \
- _dmv_x = (sign ^ ((val>>1) + offset_table[index1])) - sign; \
- \
- index1 = index/6; \
- if (!s->quarter_sample && index1 == 5) val = 1; \
- else val = 0; \
- if(size_table[index1] - val > 0) \
- val = get_bits(gb, size_table[index1] - val); \
- else val = 0; \
- sign = 0 - (val&1); \
- _dmv_y = (sign ^ ((val>>1) + offset_table[index1])) - sign; \
- }
+#define GET_MVDATA(_dmv_x, _dmv_y) \
+ index = 1 + get_vlc2(gb, ff_vc1_mv_diff_vlc[s->mv_table_index].table, \
+ VC1_MV_DIFF_VLC_BITS, 2); \
+ if (index > 36) { \
+ mb_has_coeffs = 1; \
+ index -= 37; \
+ } else \
+ mb_has_coeffs = 0; \
+ s->mb_intra = 0; \
+ if (!index) { \
+ _dmv_x = _dmv_y = 0; \
+ } else if (index == 35) { \
+ _dmv_x = get_bits(gb, v->k_x - 1 + s->quarter_sample); \
+ _dmv_y = get_bits(gb, v->k_y - 1 + s->quarter_sample); \
+ } else if (index == 36) { \
+ _dmv_x = 0; \
+ _dmv_y = 0; \
+ s->mb_intra = 1; \
+ } else { \
+ index1 = index % 6; \
+ if (!s->quarter_sample && index1 == 5) val = 1; \
+ else val = 0; \
+ if (size_table[index1] - val > 0) \
+ val = get_bits(gb, size_table[index1] - val); \
+ else val = 0; \
+ sign = 0 - (val&1); \
+ _dmv_x = (sign ^ ((val>>1) + offset_table[index1])) - sign; \
+ \
+ index1 = index / 6; \
+ if (!s->quarter_sample && index1 == 5) val = 1; \
+ else val = 0; \
+ if (size_table[index1] - val > 0) \
+ val = get_bits(gb, size_table[index1] - val); \
+ else val = 0; \
+ sign = 0 - (val & 1); \
+ _dmv_y = (sign ^ ((val >> 1) + offset_table[index1])) - sign; \
+ }
+
+static av_always_inline void get_mvdata_interlaced(VC1Context *v, int *dmv_x,
+ int *dmv_y, int *pred_flag)
+{
+ int index, index1;
+ int extend_x = 0, extend_y = 0;
+ GetBitContext *gb = &v->s.gb;
+ int bits, esc;
+ int val, sign;
+ const int* offs_tab;
+
+ if (v->numref) {
+ bits = VC1_2REF_MVDATA_VLC_BITS;
+ esc = 125;
+ } else {
+ bits = VC1_1REF_MVDATA_VLC_BITS;
+ esc = 71;
+ }
+ switch (v->dmvrange) {
+ case 1:
+ extend_x = 1;
+ break;
+ case 2:
+ extend_y = 1;
+ break;
+ case 3:
+ extend_x = extend_y = 1;
+ break;
+ }
+ index = get_vlc2(gb, v->imv_vlc->table, bits, 3);
+ if (index == esc) {
+ *dmv_x = get_bits(gb, v->k_x);
+ *dmv_y = get_bits(gb, v->k_y);
+ if (v->numref) {
+ *pred_flag = *dmv_y & 1;
+ *dmv_y = (*dmv_y + *pred_flag) >> 1;
+ }
+ }
+ else {
+ if (extend_x)
+ offs_tab = offset_table2;
+ else
+ offs_tab = offset_table1;
+ index1 = (index + 1) % 9;
+ if (index1 != 0) {
+ val = get_bits(gb, index1 + extend_x);
+ sign = 0 -(val & 1);
+ *dmv_x = (sign ^ ((val >> 1) + offs_tab[index1])) - sign;
+ } else
+ *dmv_x = 0;
+ if (extend_y)
+ offs_tab = offset_table2;
+ else
+ offs_tab = offset_table1;
+ index1 = (index + 1) / 9;
+ if (index1 > v->numref) {
+ val = get_bits(gb, (index1 + (extend_y << v->numref)) >> v->numref);
+ sign = 0 - (val & 1);
+ *dmv_y = (sign ^ ((val >> 1) + offs_tab[index1 >> v->numref])) - sign;
+ } else
+ *dmv_y = 0;
+ if (v->numref)
+ *pred_flag = index1 & 1;
+ }
+}
+
+static av_always_inline int scaleforsame_x(VC1Context *v, int n /* MV */, int dir)
+{
+ int scaledvalue, refdist;
+ int scalesame1, scalesame2;
+ int scalezone1_x, zone1offset_x;
+ int table_index = dir ^ v->second_field;
+
+ if (v->s.pict_type != AV_PICTURE_TYPE_B)
+ refdist = v->refdist;
+ else
+ refdist = dir ? v->brfd : v->frfd;
+ if (refdist > 3)
+ refdist = 3;
+ scalesame1 = vc1_field_mvpred_scales[table_index][1][refdist];
+ scalesame2 = vc1_field_mvpred_scales[table_index][2][refdist];
+ scalezone1_x = vc1_field_mvpred_scales[table_index][3][refdist];
+ zone1offset_x = vc1_field_mvpred_scales[table_index][5][refdist];
+
+ if (FFABS(n) > 255)
+ scaledvalue = n;
+ else {
+ if (FFABS(n) < scalezone1_x)
+ scaledvalue = (n * scalesame1) >> 8;
+ else {
+ if (n < 0)
+ scaledvalue = ((n * scalesame2) >> 8) - zone1offset_x;
+ else
+ scaledvalue = ((n * scalesame2) >> 8) + zone1offset_x;
+ }
+ }
+ return av_clip(scaledvalue, -v->range_x, v->range_x - 1);
+}
+
+static av_always_inline int scaleforsame_y(VC1Context *v, int i, int n /* MV */, int dir)
+{
+ int scaledvalue, refdist;
+ int scalesame1, scalesame2;
+ int scalezone1_y, zone1offset_y;
+ int table_index = dir ^ v->second_field;
+
+ if (v->s.pict_type != AV_PICTURE_TYPE_B)
+ refdist = v->refdist;
+ else
+ refdist = dir ? v->brfd : v->frfd;
+ if (refdist > 3)
+ refdist = 3;
+ scalesame1 = vc1_field_mvpred_scales[table_index][1][refdist];
+ scalesame2 = vc1_field_mvpred_scales[table_index][2][refdist];
+ scalezone1_y = vc1_field_mvpred_scales[table_index][4][refdist];
+ zone1offset_y = vc1_field_mvpred_scales[table_index][6][refdist];
+
+ if (FFABS(n) > 63)
+ scaledvalue = n;
+ else {
+ if (FFABS(n) < scalezone1_y)
+ scaledvalue = (n * scalesame1) >> 8;
+ else {
+ if (n < 0)
+ scaledvalue = ((n * scalesame2) >> 8) - zone1offset_y;
+ else
+ scaledvalue = ((n * scalesame2) >> 8) + zone1offset_y;
+ }
+ }
+
+ if (v->cur_field_type && !v->ref_field_type[dir])
+ return av_clip(scaledvalue, -v->range_y / 2 + 1, v->range_y / 2);
+ else
+ return av_clip(scaledvalue, -v->range_y / 2, v->range_y / 2 - 1);
+}
+
+static av_always_inline int scaleforopp_x(VC1Context *v, int n /* MV */)
+{
+ int scalezone1_x, zone1offset_x;
+ int scaleopp1, scaleopp2, brfd;
+ int scaledvalue;
+
+ brfd = FFMIN(v->brfd, 3);
+ scalezone1_x = vc1_b_field_mvpred_scales[3][brfd];
+ zone1offset_x = vc1_b_field_mvpred_scales[5][brfd];
+ scaleopp1 = vc1_b_field_mvpred_scales[1][brfd];
+ scaleopp2 = vc1_b_field_mvpred_scales[2][brfd];
+
+ if (FFABS(n) > 255)
+ scaledvalue = n;
+ else {
+ if (FFABS(n) < scalezone1_x)
+ scaledvalue = (n * scaleopp1) >> 8;
+ else {
+ if (n < 0)
+ scaledvalue = ((n * scaleopp2) >> 8) - zone1offset_x;
+ else
+ scaledvalue = ((n * scaleopp2) >> 8) + zone1offset_x;
+ }
+ }
+ return av_clip(scaledvalue, -v->range_x, v->range_x - 1);
+}
+
+static av_always_inline int scaleforopp_y(VC1Context *v, int n /* MV */, int dir)
+{
+ int scalezone1_y, zone1offset_y;
+ int scaleopp1, scaleopp2, brfd;
+ int scaledvalue;
+
+ brfd = FFMIN(v->brfd, 3);
+ scalezone1_y = vc1_b_field_mvpred_scales[4][brfd];
+ zone1offset_y = vc1_b_field_mvpred_scales[6][brfd];
+ scaleopp1 = vc1_b_field_mvpred_scales[1][brfd];
+ scaleopp2 = vc1_b_field_mvpred_scales[2][brfd];
+
+ if (FFABS(n) > 63)
+ scaledvalue = n;
+ else {
+ if (FFABS(n) < scalezone1_y)
+ scaledvalue = (n * scaleopp1) >> 8;
+ else {
+ if (n < 0)
+ scaledvalue = ((n * scaleopp2) >> 8) - zone1offset_y;
+ else
+ scaledvalue = ((n * scaleopp2) >> 8) + zone1offset_y;
+ }
+ }
+ if (v->cur_field_type && !v->ref_field_type[dir]) {
+ return av_clip(scaledvalue, -v->range_y / 2 + 1, v->range_y / 2);
+ } else {
+ return av_clip(scaledvalue, -v->range_y / 2, v->range_y / 2 - 1);
+ }
+}
+
+static av_always_inline int scaleforsame(VC1Context *v, int i, int n /* MV */,
+ int dim, int dir)
+{
+ int brfd, scalesame;
+
+ if (v->s.pict_type != AV_PICTURE_TYPE_B || v->second_field || !dir) {
+ if (dim)
+ return scaleforsame_y(v, i, n, dir);
+ else
+ return scaleforsame_x(v, n, dir);
+ }
+ brfd = FFMIN(v->brfd, 3);
+ scalesame = vc1_b_field_mvpred_scales[0][brfd];
+
+ return n * scalesame >> 8;
+}
+
+static av_always_inline int scaleforopp(VC1Context *v, int n /* MV */,
+ int dim, int dir)
+{
+ int refdist, scaleopp;
+
+ if (v->s.pict_type == AV_PICTURE_TYPE_B && !v->second_field && dir == 1) {
+ if (dim)
+ return scaleforopp_y(v, n, dir);
+ else
+ return scaleforopp_x(v, n);
+ }
+ if (v->s.pict_type != AV_PICTURE_TYPE_B)
+ refdist = FFMIN(v->refdist, 3);
+ else
+ refdist = dir ? v->brfd : v->frfd;
+ scaleopp = vc1_field_mvpred_scales[dir ^ v->second_field][0][refdist];
+
+ return n * scaleopp >> 8;
+}
/** Predict and set motion vector
*/
-static inline void vc1_pred_mv(VC1Context *v, int n, int dmv_x, int dmv_y, int mv1, int r_x, int r_y, uint8_t* is_intra)
+static inline void vc1_pred_mv(VC1Context *v, int n, int dmv_x, int dmv_y,
+ int mv1, int r_x, int r_y, uint8_t* is_intra,
+ int pred_flag, int dir)
{
MpegEncContext *s = &v->s;
int xy, wrap, off = 0;
int16_t *A, *B, *C;
int px, py;
int sum;
-
+ int mixedmv_pic, num_samefield = 0, num_oppfield = 0;
+ int opposit, f;
+ int16_t samefield_pred[2], oppfield_pred[2];
+ int16_t samefield_predA[2], oppfield_predA[2];
+ int16_t samefield_predB[2], oppfield_predB[2];
+ int16_t samefield_predC[2], oppfield_predC[2];
+ int16_t *predA, *predC;
+ int a_valid, b_valid, c_valid;
+ int hybridmv_thresh, y_bias = 0;
+
+ if (v->mv_mode == MV_PMODE_MIXED_MV ||
+ ((v->mv_mode == MV_PMODE_INTENSITY_COMP) && (v->mv_mode2 == MV_PMODE_MIXED_MV)))
+ mixedmv_pic = 1;
+ else
+ mixedmv_pic = 0;
/* scale MV difference to be quad-pel */
dmv_x <<= 1 - s->quarter_sample;
dmv_y <<= 1 - s->quarter_sample;
wrap = s->b8_stride;
- xy = s->block_index[n];
-
- if(s->mb_intra){
- s->mv[0][n][0] = s->current_picture.motion_val[0][xy][0] = 0;
- s->mv[0][n][1] = s->current_picture.motion_val[0][xy][1] = 0;
- s->current_picture.motion_val[1][xy][0] = 0;
- s->current_picture.motion_val[1][xy][1] = 0;
- if(mv1) { /* duplicate motion data for 1-MV block */
- s->current_picture.motion_val[0][xy + 1][0] = 0;
- s->current_picture.motion_val[0][xy + 1][1] = 0;
- s->current_picture.motion_val[0][xy + wrap][0] = 0;
- s->current_picture.motion_val[0][xy + wrap][1] = 0;
- s->current_picture.motion_val[0][xy + wrap + 1][0] = 0;
- s->current_picture.motion_val[0][xy + wrap + 1][1] = 0;
+ xy = s->block_index[n];
+
+ if (s->mb_intra) {
+ s->mv[0][n][0] = s->current_picture.f.motion_val[0][xy + v->blocks_off][0] = 0;
+ s->mv[0][n][1] = s->current_picture.f.motion_val[0][xy + v->blocks_off][1] = 0;
+ s->current_picture.f.motion_val[1][xy + v->blocks_off][0] = 0;
+ s->current_picture.f.motion_val[1][xy + v->blocks_off][1] = 0;
+ if (mv1) { /* duplicate motion data for 1-MV block */
+ s->current_picture.f.motion_val[0][xy + 1 + v->blocks_off][0] = 0;
+ s->current_picture.f.motion_val[0][xy + 1 + v->blocks_off][1] = 0;
+ s->current_picture.f.motion_val[0][xy + wrap + v->blocks_off][0] = 0;
+ s->current_picture.f.motion_val[0][xy + wrap + v->blocks_off][1] = 0;
+ s->current_picture.f.motion_val[0][xy + wrap + 1 + v->blocks_off][0] = 0;
+ s->current_picture.f.motion_val[0][xy + wrap + 1 + v->blocks_off][1] = 0;
v->luma_mv[s->mb_x][0] = v->luma_mv[s->mb_x][1] = 0;
- s->current_picture.motion_val[1][xy + 1][0] = 0;
- s->current_picture.motion_val[1][xy + 1][1] = 0;
- s->current_picture.motion_val[1][xy + wrap][0] = 0;
- s->current_picture.motion_val[1][xy + wrap][1] = 0;
- s->current_picture.motion_val[1][xy + wrap + 1][0] = 0;
- s->current_picture.motion_val[1][xy + wrap + 1][1] = 0;
+ s->current_picture.f.motion_val[1][xy + 1 + v->blocks_off][0] = 0;
+ s->current_picture.f.motion_val[1][xy + 1 + v->blocks_off][1] = 0;
+ s->current_picture.f.motion_val[1][xy + wrap][0] = 0;
+ s->current_picture.f.motion_val[1][xy + wrap + v->blocks_off][1] = 0;
+ s->current_picture.f.motion_val[1][xy + wrap + 1 + v->blocks_off][0] = 0;
+ s->current_picture.f.motion_val[1][xy + wrap + 1 + v->blocks_off][1] = 0;
}
return;
}
- C = s->current_picture.motion_val[0][xy - 1];
- A = s->current_picture.motion_val[0][xy - wrap];
- if(mv1)
- off = (s->mb_x == (s->mb_width - 1)) ? -1 : 2;
- else {
+ C = s->current_picture.f.motion_val[dir][xy - 1 + v->blocks_off];
+ A = s->current_picture.f.motion_val[dir][xy - wrap + v->blocks_off];
+ if (mv1) {
+ if (v->field_mode && mixedmv_pic)
+ off = (s->mb_x == (s->mb_width - 1)) ? -2 : 2;
+ else
+ off = (s->mb_x == (s->mb_width - 1)) ? -1 : 2;
+ } else {
//in 4-MV mode different blocks have different B predictor position
- switch(n){
+ switch (n) {
case 0:
off = (s->mb_x > 0) ? -1 : 1;
break;
@@ -925,79 +1530,434 @@ static inline void vc1_pred_mv(VC1Context *v, int n, int dmv_x, int dmv_y, int m
off = -1;
}
}
- B = s->current_picture.motion_val[0][xy - wrap + off];
-
- if(!s->first_slice_line || (n==2 || n==3)) { // predictor A is not out of bounds
- if(s->mb_width == 1) {
- px = A[0];
- py = A[1];
+ B = s->current_picture.f.motion_val[dir][xy - wrap + off + v->blocks_off];
+
+ a_valid = !s->first_slice_line || (n == 2 || n == 3);
+ b_valid = a_valid && (s->mb_width > 1);
+ c_valid = s->mb_x || (n == 1 || n == 3);
+ if (v->field_mode) {
+ a_valid = a_valid && !is_intra[xy - wrap];
+ b_valid = b_valid && !is_intra[xy - wrap + off];
+ c_valid = c_valid && !is_intra[xy - 1];
+ }
+
+ if (a_valid) {
+ f = v->mv_f[dir][xy - wrap + v->blocks_off];
+ num_oppfield += f;
+ num_samefield += 1 - f;
+ if (f) {
+ oppfield_predA[0] = A[0];
+ oppfield_predA[1] = A[1];
+ samefield_predA[0] = scaleforsame(v, 0, A[0], 0, dir);
+ samefield_predA[1] = scaleforsame(v, n, A[1], 1, dir);
+ } else {
+ samefield_predA[0] = A[0];
+ samefield_predA[1] = A[1];
+ if (v->numref)
+ oppfield_predA[0] = scaleforopp(v, A[0], 0, dir);
+ if (v->numref)
+ oppfield_predA[1] = scaleforopp(v, A[1], 1, dir);
+ }
+ } else {
+ samefield_predA[0] = samefield_predA[1] = 0;
+ oppfield_predA[0] = oppfield_predA[1] = 0;
+ }
+ if (c_valid) {
+ f = v->mv_f[dir][xy - 1 + v->blocks_off];
+ num_oppfield += f;
+ num_samefield += 1 - f;
+ if (f) {
+ oppfield_predC[0] = C[0];
+ oppfield_predC[1] = C[1];
+ samefield_predC[0] = scaleforsame(v, 0, C[0], 0, dir);
+ samefield_predC[1] = scaleforsame(v, n, C[1], 1, dir);
+ } else {
+ samefield_predC[0] = C[0];
+ samefield_predC[1] = C[1];
+ if (v->numref)
+ oppfield_predC[0] = scaleforopp(v, C[0], 0, dir);
+ if (v->numref)
+ oppfield_predC[1] = scaleforopp(v, C[1], 1, dir);
+ }
+ } else {
+ samefield_predC[0] = samefield_predC[1] = 0;
+ oppfield_predC[0] = oppfield_predC[1] = 0;
+ }
+ if (b_valid) {
+ f = v->mv_f[dir][xy - wrap + off + v->blocks_off];
+ num_oppfield += f;
+ num_samefield += 1 - f;
+ if (f) {
+ oppfield_predB[0] = B[0];
+ oppfield_predB[1] = B[1];
+ samefield_predB[0] = scaleforsame(v, 0, B[0], 0, dir);
+ samefield_predB[1] = scaleforsame(v, n, B[1], 1, dir);
} else {
- px = mid_pred(A[0], B[0], C[0]);
- py = mid_pred(A[1], B[1], C[1]);
+ samefield_predB[0] = B[0];
+ samefield_predB[1] = B[1];
+ if (v->numref)
+ oppfield_predB[0] = scaleforopp(v, B[0], 0, dir);
+ if (v->numref)
+ oppfield_predB[1] = scaleforopp(v, B[1], 1, dir);
}
- } else if(s->mb_x || (n==1 || n==3)) { // predictor C is not out of bounds
- px = C[0];
- py = C[1];
} else {
- px = py = 0;
+ samefield_predB[0] = samefield_predB[1] = 0;
+ oppfield_predB[0] = oppfield_predB[1] = 0;
+ }
+
+ if (a_valid) {
+ samefield_pred[0] = samefield_predA[0];
+ samefield_pred[1] = samefield_predA[1];
+ oppfield_pred[0] = oppfield_predA[0];
+ oppfield_pred[1] = oppfield_predA[1];
+ } else if (c_valid) {
+ samefield_pred[0] = samefield_predC[0];
+ samefield_pred[1] = samefield_predC[1];
+ oppfield_pred[0] = oppfield_predC[0];
+ oppfield_pred[1] = oppfield_predC[1];
+ } else if (b_valid) {
+ samefield_pred[0] = samefield_predB[0];
+ samefield_pred[1] = samefield_predB[1];
+ oppfield_pred[0] = oppfield_predB[0];
+ oppfield_pred[1] = oppfield_predB[1];
+ } else {
+ samefield_pred[0] = samefield_pred[1] = 0;
+ oppfield_pred[0] = oppfield_pred[1] = 0;
+ }
+
+ if (num_samefield + num_oppfield > 1) {
+ samefield_pred[0] = mid_pred(samefield_predA[0], samefield_predB[0], samefield_predC[0]);
+ samefield_pred[1] = mid_pred(samefield_predA[1], samefield_predB[1], samefield_predC[1]);
+ if (v->numref)
+ oppfield_pred[0] = mid_pred(oppfield_predA[0], oppfield_predB[0], oppfield_predC[0]);
+ if (v->numref)
+ oppfield_pred[1] = mid_pred(oppfield_predA[1], oppfield_predB[1], oppfield_predC[1]);
}
+
+ if (v->field_mode) {
+ if (num_samefield <= num_oppfield)
+ opposit = 1 - pred_flag;
+ else
+ opposit = pred_flag;
+ } else
+ opposit = 0;
+ if (opposit) {
+ px = oppfield_pred[0];
+ py = oppfield_pred[1];
+ predA = oppfield_predA;
+ predC = oppfield_predC;
+ v->mv_f[dir][xy + v->blocks_off] = f = 1;
+ v->ref_field_type[dir] = !v->cur_field_type;
+ } else {
+ px = samefield_pred[0];
+ py = samefield_pred[1];
+ predA = samefield_predA;
+ predC = samefield_predC;
+ v->mv_f[dir][xy + v->blocks_off] = f = 0;
+ v->ref_field_type[dir] = v->cur_field_type;
+ }
+
/* Pullback MV as specified in 8.3.5.3.4 */
- {
+ if (!v->field_mode) {
int qx, qy, X, Y;
- qx = (s->mb_x << 6) + ((n==1 || n==3) ? 32 : 0);
- qy = (s->mb_y << 6) + ((n==2 || n==3) ? 32 : 0);
- X = (s->mb_width << 6) - 4;
- Y = (s->mb_height << 6) - 4;
- if(mv1) {
- if(qx + px < -60) px = -60 - qx;
- if(qy + py < -60) py = -60 - qy;
+ qx = (s->mb_x << 6) + ((n == 1 || n == 3) ? 32 : 0);
+ qy = (s->mb_y << 6) + ((n == 2 || n == 3) ? 32 : 0);
+ X = (s->mb_width << 6) - 4;
+ Y = (s->mb_height << 6) - 4;
+ if (mv1) {
+ if (qx + px < -60) px = -60 - qx;
+ if (qy + py < -60) py = -60 - qy;
} else {
- if(qx + px < -28) px = -28 - qx;
- if(qy + py < -28) py = -28 - qy;
+ if (qx + px < -28) px = -28 - qx;
+ if (qy + py < -28) py = -28 - qy;
}
- if(qx + px > X) px = X - qx;
- if(qy + py > Y) py = Y - qy;
+ if (qx + px > X) px = X - qx;
+ if (qy + py > Y) py = Y - qy;
}
- /* Calculate hybrid prediction as specified in 8.3.5.3.5 */
- if((!s->first_slice_line || (n==2 || n==3)) && (s->mb_x || (n==1 || n==3))) {
- if(is_intra[xy - wrap])
- sum = FFABS(px) + FFABS(py);
+
+ if (!v->field_mode || s->pict_type != AV_PICTURE_TYPE_B) {
+ /* Calculate hybrid prediction as specified in 8.3.5.3.5 (also 10.3.5.4.3.5) */
+ if (v->field_mode && !s->quarter_sample)
+ hybridmv_thresh = 16;
else
- sum = FFABS(px - A[0]) + FFABS(py - A[1]);
- if(sum > 32) {
- if(get_bits1(&s->gb)) {
- px = A[0];
- py = A[1];
+ hybridmv_thresh = 32;
+ if (a_valid && c_valid) {
+ if (is_intra[xy - wrap])
+ sum = FFABS(px) + FFABS(py);
+ else
+ sum = FFABS(px - predA[0]) + FFABS(py - predA[1]);
+ if (sum > hybridmv_thresh) {
+ if (get_bits1(&s->gb)) { // read HYBRIDPRED bit
+ px = predA[0];
+ py = predA[1];
+ } else {
+ px = predC[0];
+ py = predC[1];
+ }
} else {
- px = C[0];
- py = C[1];
+ if (is_intra[xy - 1])
+ sum = FFABS(px) + FFABS(py);
+ else
+ sum = FFABS(px - predC[0]) + FFABS(py - predC[1]);
+ if (sum > hybridmv_thresh) {
+ if (get_bits1(&s->gb)) {
+ px = predA[0];
+ py = predA[1];
+ } else {
+ px = predC[0];
+ py = predC[1];
+ }
+ }
}
+ }
+ }
+
+ if (v->field_mode && !s->quarter_sample) {
+ r_x <<= 1;
+ r_y <<= 1;
+ }
+ if (v->field_mode && v->numref)
+ r_y >>= 1;
+ if (v->field_mode && v->cur_field_type && v->ref_field_type[dir] == 0)
+ y_bias = 1;
+ /* store MV using signed modulus of MV range defined in 4.11 */
+ s->mv[dir][n][0] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][0] = ((px + dmv_x + r_x) & ((r_x << 1) - 1)) - r_x;
+ s->mv[dir][n][1] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][1] = ((py + dmv_y + r_y - y_bias) & ((r_y << 1) - 1)) - r_y + y_bias;
+ if (mv1) { /* duplicate motion data for 1-MV block */
+ s->current_picture.f.motion_val[dir][xy + 1 + v->blocks_off][0] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][0];
+ s->current_picture.f.motion_val[dir][xy + 1 + v->blocks_off][1] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][1];
+ s->current_picture.f.motion_val[dir][xy + wrap + v->blocks_off][0] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][0];
+ s->current_picture.f.motion_val[dir][xy + wrap + v->blocks_off][1] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][1];
+ s->current_picture.f.motion_val[dir][xy + wrap + 1 + v->blocks_off][0] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][0];
+ s->current_picture.f.motion_val[dir][xy + wrap + 1 + v->blocks_off][1] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][1];
+ v->mv_f[dir][xy + 1 + v->blocks_off] = v->mv_f[dir][xy + v->blocks_off];
+ v->mv_f[dir][xy + wrap + v->blocks_off] = v->mv_f[dir][xy + wrap + 1 + v->blocks_off] = v->mv_f[dir][xy + v->blocks_off];
+ }
+}
+
+/** Predict and set motion vector for interlaced frame picture MBs
+ */
+static inline void vc1_pred_mv_intfr(VC1Context *v, int n, int dmv_x, int dmv_y,
+ int mvn, int r_x, int r_y, uint8_t* is_intra)
+{
+ MpegEncContext *s = &v->s;
+ int xy, wrap, off = 0;
+ int A[2], B[2], C[2];
+ int px, py;
+ int a_valid = 0, b_valid = 0, c_valid = 0;
+ int field_a, field_b, field_c; // 0: same, 1: opposit
+ int total_valid, num_samefield, num_oppfield;
+ int pos_c, pos_b, n_adj;
+
+ wrap = s->b8_stride;
+ xy = s->block_index[n];
+
+ if (s->mb_intra) {
+ s->mv[0][n][0] = s->current_picture.f.motion_val[0][xy][0] = 0;
+ s->mv[0][n][1] = s->current_picture.f.motion_val[0][xy][1] = 0;
+ s->current_picture.f.motion_val[1][xy][0] = 0;
+ s->current_picture.f.motion_val[1][xy][1] = 0;
+ if (mvn == 1) { /* duplicate motion data for 1-MV block */
+ s->current_picture.f.motion_val[0][xy + 1][0] = 0;
+ s->current_picture.f.motion_val[0][xy + 1][1] = 0;
+ s->current_picture.f.motion_val[0][xy + wrap][0] = 0;
+ s->current_picture.f.motion_val[0][xy + wrap][1] = 0;
+ s->current_picture.f.motion_val[0][xy + wrap + 1][0] = 0;
+ s->current_picture.f.motion_val[0][xy + wrap + 1][1] = 0;
+ v->luma_mv[s->mb_x][0] = v->luma_mv[s->mb_x][1] = 0;
+ s->current_picture.f.motion_val[1][xy + 1][0] = 0;
+ s->current_picture.f.motion_val[1][xy + 1][1] = 0;
+ s->current_picture.f.motion_val[1][xy + wrap][0] = 0;
+ s->current_picture.f.motion_val[1][xy + wrap][1] = 0;
+ s->current_picture.f.motion_val[1][xy + wrap + 1][0] = 0;
+ s->current_picture.f.motion_val[1][xy + wrap + 1][1] = 0;
+ }
+ return;
+ }
+
+ off = ((n == 0) || (n == 1)) ? 1 : -1;
+ /* predict A */
+ if (s->mb_x || (n == 1) || (n == 3)) {
+ if ((v->blk_mv_type[xy]) // current block (MB) has a field MV
+ || (!v->blk_mv_type[xy] && !v->blk_mv_type[xy - 1])) { // or both have frame MV
+ A[0] = s->current_picture.f.motion_val[0][xy - 1][0];
+ A[1] = s->current_picture.f.motion_val[0][xy - 1][1];
+ a_valid = 1;
+ } else { // current block has frame mv and cand. has field MV (so average)
+ A[0] = (s->current_picture.f.motion_val[0][xy - 1][0]
+ + s->current_picture.f.motion_val[0][xy - 1 + off * wrap][0] + 1) >> 1;
+ A[1] = (s->current_picture.f.motion_val[0][xy - 1][1]
+ + s->current_picture.f.motion_val[0][xy - 1 + off * wrap][1] + 1) >> 1;
+ a_valid = 1;
+ }
+ if (!(n & 1) && v->is_intra[s->mb_x - 1]) {
+ a_valid = 0;
+ A[0] = A[1] = 0;
+ }
+ } else
+ A[0] = A[1] = 0;
+ /* Predict B and C */
+ B[0] = B[1] = C[0] = C[1] = 0;
+ if (n == 0 || n == 1 || v->blk_mv_type[xy]) {
+ if (!s->first_slice_line) {
+ if (!v->is_intra[s->mb_x - s->mb_stride]) {
+ b_valid = 1;
+ n_adj = n | 2;
+ pos_b = s->block_index[n_adj] - 2 * wrap;
+ if (v->blk_mv_type[pos_b] && v->blk_mv_type[xy]) {
+ n_adj = (n & 2) | (n & 1);
+ }
+ B[0] = s->current_picture.f.motion_val[0][s->block_index[n_adj] - 2 * wrap][0];
+ B[1] = s->current_picture.f.motion_val[0][s->block_index[n_adj] - 2 * wrap][1];
+ if (v->blk_mv_type[pos_b] && !v->blk_mv_type[xy]) {
+ B[0] = (B[0] + s->current_picture.f.motion_val[0][s->block_index[n_adj ^ 2] - 2 * wrap][0] + 1) >> 1;
+ B[1] = (B[1] + s->current_picture.f.motion_val[0][s->block_index[n_adj ^ 2] - 2 * wrap][1] + 1) >> 1;
+ }
+ }
+ if (s->mb_width > 1) {
+ if (!v->is_intra[s->mb_x - s->mb_stride + 1]) {
+ c_valid = 1;
+ n_adj = 2;
+ pos_c = s->block_index[2] - 2 * wrap + 2;
+ if (v->blk_mv_type[pos_c] && v->blk_mv_type[xy]) {
+ n_adj = n & 2;
+ }
+ C[0] = s->current_picture.f.motion_val[0][s->block_index[n_adj] - 2 * wrap + 2][0];
+ C[1] = s->current_picture.f.motion_val[0][s->block_index[n_adj] - 2 * wrap + 2][1];
+ if (v->blk_mv_type[pos_c] && !v->blk_mv_type[xy]) {
+ C[0] = (1 + C[0] + (s->current_picture.f.motion_val[0][s->block_index[n_adj ^ 2] - 2 * wrap + 2][0])) >> 1;
+ C[1] = (1 + C[1] + (s->current_picture.f.motion_val[0][s->block_index[n_adj ^ 2] - 2 * wrap + 2][1])) >> 1;
+ }
+ if (s->mb_x == s->mb_width - 1) {
+ if (!v->is_intra[s->mb_x - s->mb_stride - 1]) {
+ c_valid = 1;
+ n_adj = 3;
+ pos_c = s->block_index[3] - 2 * wrap - 2;
+ if (v->blk_mv_type[pos_c] && v->blk_mv_type[xy]) {
+ n_adj = n | 1;
+ }
+ C[0] = s->current_picture.f.motion_val[0][s->block_index[n_adj] - 2 * wrap - 2][0];
+ C[1] = s->current_picture.f.motion_val[0][s->block_index[n_adj] - 2 * wrap - 2][1];
+ if (v->blk_mv_type[pos_c] && !v->blk_mv_type[xy]) {
+ C[0] = (1 + C[0] + s->current_picture.f.motion_val[0][s->block_index[1] - 2 * wrap - 2][0]) >> 1;
+ C[1] = (1 + C[1] + s->current_picture.f.motion_val[0][s->block_index[1] - 2 * wrap - 2][1]) >> 1;
+ }
+ } else
+ c_valid = 0;
+ }
+ }
+ }
+ }
+ } else {
+ pos_b = s->block_index[1];
+ b_valid = 1;
+ B[0] = s->current_picture.f.motion_val[0][pos_b][0];
+ B[1] = s->current_picture.f.motion_val[0][pos_b][1];
+ pos_c = s->block_index[0];
+ c_valid = 1;
+ C[0] = s->current_picture.f.motion_val[0][pos_c][0];
+ C[1] = s->current_picture.f.motion_val[0][pos_c][1];
+ }
+
+ total_valid = a_valid + b_valid + c_valid;
+ // check if predictor A is out of bounds
+ if (!s->mb_x && !(n == 1 || n == 3)) {
+ A[0] = A[1] = 0;
+ }
+ // check if predictor B is out of bounds
+ if ((s->first_slice_line && v->blk_mv_type[xy]) || (s->first_slice_line && !(n & 2))) {
+ B[0] = B[1] = C[0] = C[1] = 0;
+ }
+ if (!v->blk_mv_type[xy]) {
+ if (s->mb_width == 1) {
+ px = B[0];
+ py = B[1];
} else {
- if(is_intra[xy - 1])
- sum = FFABS(px) + FFABS(py);
- else
- sum = FFABS(px - C[0]) + FFABS(py - C[1]);
- if(sum > 32) {
- if(get_bits1(&s->gb)) {
+ if (total_valid >= 2) {
+ px = mid_pred(A[0], B[0], C[0]);
+ py = mid_pred(A[1], B[1], C[1]);
+ } else if (total_valid) {
+ if (a_valid) { px = A[0]; py = A[1]; }
+ if (b_valid) { px = B[0]; py = B[1]; }
+ if (c_valid) { px = C[0]; py = C[1]; }
+ } else
+ px = py = 0;
+ }
+ } else {
+ if (a_valid)
+ field_a = (A[1] & 4) ? 1 : 0;
+ else
+ field_a = 0;
+ if (b_valid)
+ field_b = (B[1] & 4) ? 1 : 0;
+ else
+ field_b = 0;
+ if (c_valid)
+ field_c = (C[1] & 4) ? 1 : 0;
+ else
+ field_c = 0;
+
+ num_oppfield = field_a + field_b + field_c;
+ num_samefield = total_valid - num_oppfield;
+ if (total_valid == 3) {
+ if ((num_samefield == 3) || (num_oppfield == 3)) {
+ px = mid_pred(A[0], B[0], C[0]);
+ py = mid_pred(A[1], B[1], C[1]);
+ } else if (num_samefield >= num_oppfield) {
+ /* take one MV from same field set depending on priority
+ the check for B may not be necessary */
+ px = !field_a ? A[0] : B[0];
+ py = !field_a ? A[1] : B[1];
+ } else {
+ px = field_a ? A[0] : B[0];
+ py = field_a ? A[1] : B[1];
+ }
+ } else if (total_valid == 2) {
+ if (num_samefield >= num_oppfield) {
+ if (!field_a && a_valid) {
px = A[0];
py = A[1];
- } else {
+ } else if (!field_b && b_valid) {
+ px = B[0];
+ py = B[1];
+ } else if (c_valid) {
+ px = C[0];
+ py = C[1];
+ } else px = py = 0;
+ } else {
+ if (field_a && a_valid) {
+ px = A[0];
+ py = A[1];
+ } else if (field_b && b_valid) {
+ px = B[0];
+ py = B[1];
+ } else if (c_valid) {
px = C[0];
py = C[1];
}
}
- }
+ } else if (total_valid == 1) {
+ px = (a_valid) ? A[0] : ((b_valid) ? B[0] : C[0]);
+ py = (a_valid) ? A[1] : ((b_valid) ? B[1] : C[1]);
+ } else
+ px = py = 0;
}
+
/* store MV using signed modulus of MV range defined in 4.11 */
- s->mv[0][n][0] = s->current_picture.motion_val[0][xy][0] = ((px + dmv_x + r_x) & ((r_x << 1) - 1)) - r_x;
- s->mv[0][n][1] = s->current_picture.motion_val[0][xy][1] = ((py + dmv_y + r_y) & ((r_y << 1) - 1)) - r_y;
- if(mv1) { /* duplicate motion data for 1-MV block */
- s->current_picture.motion_val[0][xy + 1][0] = s->current_picture.motion_val[0][xy][0];
- s->current_picture.motion_val[0][xy + 1][1] = s->current_picture.motion_val[0][xy][1];
- s->current_picture.motion_val[0][xy + wrap][0] = s->current_picture.motion_val[0][xy][0];
- s->current_picture.motion_val[0][xy + wrap][1] = s->current_picture.motion_val[0][xy][1];
- s->current_picture.motion_val[0][xy + wrap + 1][0] = s->current_picture.motion_val[0][xy][0];
- s->current_picture.motion_val[0][xy + wrap + 1][1] = s->current_picture.motion_val[0][xy][1];
+ s->mv[0][n][0] = s->current_picture.f.motion_val[0][xy][0] = ((px + dmv_x + r_x) & ((r_x << 1) - 1)) - r_x;
+ s->mv[0][n][1] = s->current_picture.f.motion_val[0][xy][1] = ((py + dmv_y + r_y) & ((r_y << 1) - 1)) - r_y;
+ if (mvn == 1) { /* duplicate motion data for 1-MV block */
+ s->current_picture.f.motion_val[0][xy + 1 ][0] = s->current_picture.f.motion_val[0][xy][0];
+ s->current_picture.f.motion_val[0][xy + 1 ][1] = s->current_picture.f.motion_val[0][xy][1];
+ s->current_picture.f.motion_val[0][xy + wrap ][0] = s->current_picture.f.motion_val[0][xy][0];
+ s->current_picture.f.motion_val[0][xy + wrap ][1] = s->current_picture.f.motion_val[0][xy][1];
+ s->current_picture.f.motion_val[0][xy + wrap + 1][0] = s->current_picture.f.motion_val[0][xy][0];
+ s->current_picture.f.motion_val[0][xy + wrap + 1][1] = s->current_picture.f.motion_val[0][xy][1];
+ } else if (mvn == 2) { /* duplicate motion data for 2-Field MV block */
+ s->current_picture.f.motion_val[0][xy + 1][0] = s->current_picture.f.motion_val[0][xy][0];
+ s->current_picture.f.motion_val[0][xy + 1][1] = s->current_picture.f.motion_val[0][xy][1];
+ s->mv[0][n + 1][0] = s->mv[0][n][0];
+ s->mv[0][n + 1][1] = s->mv[0][n][1];
}
}
@@ -1009,112 +1969,138 @@ static void vc1_interp_mc(VC1Context *v)
DSPContext *dsp = &v->s.dsp;
uint8_t *srcY, *srcU, *srcV;
int dxy, mx, my, uvmx, uvmy, src_x, src_y, uvsrc_x, uvsrc_y;
+ int off, off_uv;
+ int v_edge_pos = s->v_edge_pos >> v->field_mode;
- if(!v->s.next_picture.data[0])return;
+ if (!v->field_mode && !v->s.next_picture.f.data[0])
+ return;
- mx = s->mv[1][0][0];
- my = s->mv[1][0][1];
+ mx = s->mv[1][0][0];
+ my = s->mv[1][0][1];
uvmx = (mx + ((mx & 3) == 3)) >> 1;
uvmy = (my + ((my & 3) == 3)) >> 1;
- if(v->fastuvmc) {
- uvmx = uvmx + ((uvmx<0)?-(uvmx&1):(uvmx&1));
- uvmy = uvmy + ((uvmy<0)?-(uvmy&1):(uvmy&1));
+ if (v->field_mode) {
+ if (v->cur_field_type != v->ref_field_type[1])
+ my = my - 2 + 4 * v->cur_field_type;
+ uvmy = uvmy - 2 + 4 * v->cur_field_type;
+ }
+ if (v->fastuvmc) {
+ uvmx = uvmx + ((uvmx < 0) ? -(uvmx & 1) : (uvmx & 1));
+ uvmy = uvmy + ((uvmy < 0) ? -(uvmy & 1) : (uvmy & 1));
}
- srcY = s->next_picture.data[0];
- srcU = s->next_picture.data[1];
- srcV = s->next_picture.data[2];
+ srcY = s->next_picture.f.data[0];
+ srcU = s->next_picture.f.data[1];
+ srcV = s->next_picture.f.data[2];
- src_x = s->mb_x * 16 + (mx >> 2);
- src_y = s->mb_y * 16 + (my >> 2);
- uvsrc_x = s->mb_x * 8 + (uvmx >> 2);
- uvsrc_y = s->mb_y * 8 + (uvmy >> 2);
+ src_x = s->mb_x * 16 + (mx >> 2);
+ src_y = s->mb_y * 16 + (my >> 2);
+ uvsrc_x = s->mb_x * 8 + (uvmx >> 2);
+ uvsrc_y = s->mb_y * 8 + (uvmy >> 2);
- if(v->profile != PROFILE_ADVANCED){
+ if (v->profile != PROFILE_ADVANCED) {
src_x = av_clip( src_x, -16, s->mb_width * 16);
src_y = av_clip( src_y, -16, s->mb_height * 16);
uvsrc_x = av_clip(uvsrc_x, -8, s->mb_width * 8);
uvsrc_y = av_clip(uvsrc_y, -8, s->mb_height * 8);
- }else{
+ } else {
src_x = av_clip( src_x, -17, s->avctx->coded_width);
src_y = av_clip( src_y, -18, s->avctx->coded_height + 1);
uvsrc_x = av_clip(uvsrc_x, -8, s->avctx->coded_width >> 1);
uvsrc_y = av_clip(uvsrc_y, -8, s->avctx->coded_height >> 1);
}
- srcY += src_y * s->linesize + src_x;
+ srcY += src_y * s->linesize + src_x;
srcU += uvsrc_y * s->uvlinesize + uvsrc_x;
srcV += uvsrc_y * s->uvlinesize + uvsrc_x;
+ if (v->field_mode && v->ref_field_type[1]) {
+ srcY += s->current_picture_ptr->f.linesize[0];
+ srcU += s->current_picture_ptr->f.linesize[1];
+ srcV += s->current_picture_ptr->f.linesize[2];
+ }
+
/* for grayscale we should not try to read from unknown area */
- if(s->flags & CODEC_FLAG_GRAY) {
+ if (s->flags & CODEC_FLAG_GRAY) {
srcU = s->edge_emu_buffer + 18 * s->linesize;
srcV = s->edge_emu_buffer + 18 * s->linesize;
}
- if(v->rangeredfrm
- || (unsigned)(src_x - s->mspel) > s->h_edge_pos - (mx&3) - 16 - s->mspel*3
- || (unsigned)(src_y - s->mspel) > s->v_edge_pos - (my&3) - 16 - s->mspel*3){
- uint8_t *uvbuf= s->edge_emu_buffer + 19 * s->linesize;
+ if (v->rangeredfrm
+ || (unsigned)(src_x - s->mspel) > s->h_edge_pos - (mx & 3) - 16 - s->mspel * 3
+ || (unsigned)(src_y - s->mspel) > v_edge_pos - (my & 3) - 16 - s->mspel * 3) {
+ uint8_t *uvbuf = s->edge_emu_buffer + 19 * s->linesize;
srcY -= s->mspel * (1 + s->linesize);
- s->dsp.emulated_edge_mc(s->edge_emu_buffer, srcY, s->linesize, 17+s->mspel*2, 17+s->mspel*2,
- src_x - s->mspel, src_y - s->mspel, s->h_edge_pos, s->v_edge_pos);
+ s->dsp.emulated_edge_mc(s->edge_emu_buffer, srcY, s->linesize,
+ 17 + s->mspel * 2, 17 + s->mspel * 2,
+ src_x - s->mspel, src_y - s->mspel,
+ s->h_edge_pos, v_edge_pos);
srcY = s->edge_emu_buffer;
- s->dsp.emulated_edge_mc(uvbuf , srcU, s->uvlinesize, 8+1, 8+1,
- uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1);
- s->dsp.emulated_edge_mc(uvbuf + 16, srcV, s->uvlinesize, 8+1, 8+1,
- uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1);
+ s->dsp.emulated_edge_mc(uvbuf , srcU, s->uvlinesize, 8 + 1, 8 + 1,
+ uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, v_edge_pos >> 1);
+ s->dsp.emulated_edge_mc(uvbuf + 16, srcV, s->uvlinesize, 8 + 1, 8 + 1,
+ uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, v_edge_pos >> 1);
srcU = uvbuf;
srcV = uvbuf + 16;
/* if we deal with range reduction we need to scale source blocks */
- if(v->rangeredfrm) {
+ if (v->rangeredfrm) {
int i, j;
uint8_t *src, *src2;
src = srcY;
- for(j = 0; j < 17 + s->mspel*2; j++) {
- for(i = 0; i < 17 + s->mspel*2; i++) src[i] = ((src[i] - 128) >> 1) + 128;
+ for (j = 0; j < 17 + s->mspel * 2; j++) {
+ for (i = 0; i < 17 + s->mspel * 2; i++)
+ src[i] = ((src[i] - 128) >> 1) + 128;
src += s->linesize;
}
- src = srcU; src2 = srcV;
- for(j = 0; j < 9; j++) {
- for(i = 0; i < 9; i++) {
- src[i] = ((src[i] - 128) >> 1) + 128;
+ src = srcU;
+ src2 = srcV;
+ for (j = 0; j < 9; j++) {
+ for (i = 0; i < 9; i++) {
+ src[i] = ((src[i] - 128) >> 1) + 128;
src2[i] = ((src2[i] - 128) >> 1) + 128;
}
- src += s->uvlinesize;
+ src += s->uvlinesize;
src2 += s->uvlinesize;
}
}
srcY += s->mspel * (1 + s->linesize);
}
- if(s->mspel) {
+ if (v->field_mode && v->cur_field_type) {
+ off = s->current_picture_ptr->f.linesize[0];
+ off_uv = s->current_picture_ptr->f.linesize[1];
+ } else {
+ off = 0;
+ off_uv = 0;
+ }
+
+ if (s->mspel) {
dxy = ((my & 3) << 2) | (mx & 3);
- v->vc1dsp.avg_vc1_mspel_pixels_tab[dxy](s->dest[0] , srcY , s->linesize, v->rnd);
- v->vc1dsp.avg_vc1_mspel_pixels_tab[dxy](s->dest[0] + 8, srcY + 8, s->linesize, v->rnd);
+ v->vc1dsp.avg_vc1_mspel_pixels_tab[dxy](s->dest[0] + off , srcY , s->linesize, v->rnd);
+ v->vc1dsp.avg_vc1_mspel_pixels_tab[dxy](s->dest[0] + off + 8, srcY + 8, s->linesize, v->rnd);
srcY += s->linesize * 8;
- v->vc1dsp.avg_vc1_mspel_pixels_tab[dxy](s->dest[0] + 8 * s->linesize , srcY , s->linesize, v->rnd);
- v->vc1dsp.avg_vc1_mspel_pixels_tab[dxy](s->dest[0] + 8 * s->linesize + 8, srcY + 8, s->linesize, v->rnd);
+ v->vc1dsp.avg_vc1_mspel_pixels_tab[dxy](s->dest[0] + off + 8 * s->linesize , srcY , s->linesize, v->rnd);
+ v->vc1dsp.avg_vc1_mspel_pixels_tab[dxy](s->dest[0] + off + 8 * s->linesize + 8, srcY + 8, s->linesize, v->rnd);
} else { // hpel mc
dxy = (my & 2) | ((mx & 2) >> 1);
- if(!v->rnd)
- dsp->avg_pixels_tab[0][dxy](s->dest[0], srcY, s->linesize, 16);
+ if (!v->rnd)
+ dsp->avg_pixels_tab[0][dxy](s->dest[0] + off, srcY, s->linesize, 16);
else
- dsp->avg_no_rnd_pixels_tab[0][dxy](s->dest[0], srcY, s->linesize, 16);
+ dsp->avg_no_rnd_pixels_tab[0][dxy](s->dest[0] + off, srcY, s->linesize, 16);
}
- if(s->flags & CODEC_FLAG_GRAY) return;
+ if (s->flags & CODEC_FLAG_GRAY) return;
/* Chroma MC always uses qpel blilinear */
- uvmx = (uvmx&3)<<1;
- uvmy = (uvmy&3)<<1;
- if(!v->rnd){
- dsp->avg_h264_chroma_pixels_tab[0](s->dest[1], srcU, s->uvlinesize, 8, uvmx, uvmy);
- dsp->avg_h264_chroma_pixels_tab[0](s->dest[2], srcV, s->uvlinesize, 8, uvmx, uvmy);
- }else{
- v->vc1dsp.avg_no_rnd_vc1_chroma_pixels_tab[0](s->dest[1], srcU, s->uvlinesize, 8, uvmx, uvmy);
- v->vc1dsp.avg_no_rnd_vc1_chroma_pixels_tab[0](s->dest[2], srcV, s->uvlinesize, 8, uvmx, uvmy);
+ uvmx = (uvmx & 3) << 1;
+ uvmy = (uvmy & 3) << 1;
+ if (!v->rnd) {
+ dsp->avg_h264_chroma_pixels_tab[0](s->dest[1] + off_uv, srcU, s->uvlinesize, 8, uvmx, uvmy);
+ dsp->avg_h264_chroma_pixels_tab[0](s->dest[2] + off_uv, srcV, s->uvlinesize, 8, uvmx, uvmy);
+ } else {
+ v->vc1dsp.avg_no_rnd_vc1_chroma_pixels_tab[0](s->dest[1] + off_uv, srcU, s->uvlinesize, 8, uvmx, uvmy);
+ v->vc1dsp.avg_no_rnd_vc1_chroma_pixels_tab[0](s->dest[2] + off_uv, srcV, s->uvlinesize, 8, uvmx, uvmy);
}
}
@@ -1123,47 +2109,67 @@ static av_always_inline int scale_mv(int value, int bfrac, int inv, int qs)
int n = bfrac;
#if B_FRACTION_DEN==256
- if(inv)
+ if (inv)
n -= 256;
- if(!qs)
+ if (!qs)
return 2 * ((value * n + 255) >> 9);
return (value * n + 128) >> 8;
#else
- if(inv)
+ if (inv)
n -= B_FRACTION_DEN;
- if(!qs)
+ if (!qs)
return 2 * ((value * n + B_FRACTION_DEN - 1) / (2 * B_FRACTION_DEN));
return (value * n + B_FRACTION_DEN/2) / B_FRACTION_DEN;
#endif
}
+static av_always_inline int scale_mv_intfi(int value, int bfrac, int inv,
+ int qs, int qs_last)
+{
+ int n = bfrac;
+
+ if (inv)
+ n -= 256;
+ n <<= !qs_last;
+ if (!qs)
+ return (value * n + 255) >> 9;
+ else
+ return (value * n + 128) >> 8;
+}
+
/** Reconstruct motion vector for B-frame and do motion compensation
*/
-static inline void vc1_b_mc(VC1Context *v, int dmv_x[2], int dmv_y[2], int direct, int mode)
+static inline void vc1_b_mc(VC1Context *v, int dmv_x[2], int dmv_y[2],
+ int direct, int mode)
{
- if(v->use_ic) {
+ if (v->use_ic) {
v->mv_mode2 = v->mv_mode;
- v->mv_mode = MV_PMODE_INTENSITY_COMP;
+ v->mv_mode = MV_PMODE_INTENSITY_COMP;
}
- if(direct) {
+ if (direct) {
vc1_mc_1mv(v, 0);
vc1_interp_mc(v);
- if(v->use_ic) v->mv_mode = v->mv_mode2;
+ if (v->use_ic)
+ v->mv_mode = v->mv_mode2;
return;
}
- if(mode == BMV_TYPE_INTERPOLATED) {
+ if (mode == BMV_TYPE_INTERPOLATED) {
vc1_mc_1mv(v, 0);
vc1_interp_mc(v);
- if(v->use_ic) v->mv_mode = v->mv_mode2;
+ if (v->use_ic)
+ v->mv_mode = v->mv_mode2;
return;
}
- if(v->use_ic && (mode == BMV_TYPE_BACKWARD)) v->mv_mode = v->mv_mode2;
+ if (v->use_ic && (mode == BMV_TYPE_BACKWARD))
+ v->mv_mode = v->mv_mode2;
vc1_mc_1mv(v, (mode == BMV_TYPE_BACKWARD));
- if(v->use_ic) v->mv_mode = v->mv_mode2;
+ if (v->use_ic)
+ v->mv_mode = v->mv_mode2;
}
-static inline void vc1_pred_b_mv(VC1Context *v, int dmv_x[2], int dmv_y[2], int direct, int mvtype)
+static inline void vc1_pred_b_mv(VC1Context *v, int dmv_x[2], int dmv_y[2],
+ int direct, int mvtype)
{
MpegEncContext *s = &v->s;
int xy, wrap, off = 0;
@@ -1184,47 +2190,49 @@ static inline void vc1_pred_b_mv(VC1Context *v, int dmv_x[2], int dmv_y[2], int
wrap = s->b8_stride;
xy = s->block_index[0];
- if(s->mb_intra) {
- s->current_picture.motion_val[0][xy][0] =
- s->current_picture.motion_val[0][xy][1] =
- s->current_picture.motion_val[1][xy][0] =
- s->current_picture.motion_val[1][xy][1] = 0;
+ if (s->mb_intra) {
+ s->current_picture.f.motion_val[0][xy + v->blocks_off][0] =
+ s->current_picture.f.motion_val[0][xy + v->blocks_off][1] =
+ s->current_picture.f.motion_val[1][xy + v->blocks_off][0] =
+ s->current_picture.f.motion_val[1][xy + v->blocks_off][1] = 0;
return;
}
- s->mv[0][0][0] = scale_mv(s->next_picture.motion_val[1][xy][0], v->bfraction, 0, s->quarter_sample);
- s->mv[0][0][1] = scale_mv(s->next_picture.motion_val[1][xy][1], v->bfraction, 0, s->quarter_sample);
- s->mv[1][0][0] = scale_mv(s->next_picture.motion_val[1][xy][0], v->bfraction, 1, s->quarter_sample);
- s->mv[1][0][1] = scale_mv(s->next_picture.motion_val[1][xy][1], v->bfraction, 1, s->quarter_sample);
-
- /* Pullback predicted motion vectors as specified in 8.4.5.4 */
- s->mv[0][0][0] = av_clip(s->mv[0][0][0], -60 - (s->mb_x << 6), (s->mb_width << 6) - 4 - (s->mb_x << 6));
- s->mv[0][0][1] = av_clip(s->mv[0][0][1], -60 - (s->mb_y << 6), (s->mb_height << 6) - 4 - (s->mb_y << 6));
- s->mv[1][0][0] = av_clip(s->mv[1][0][0], -60 - (s->mb_x << 6), (s->mb_width << 6) - 4 - (s->mb_x << 6));
- s->mv[1][0][1] = av_clip(s->mv[1][0][1], -60 - (s->mb_y << 6), (s->mb_height << 6) - 4 - (s->mb_y << 6));
- if(direct) {
- s->current_picture.motion_val[0][xy][0] = s->mv[0][0][0];
- s->current_picture.motion_val[0][xy][1] = s->mv[0][0][1];
- s->current_picture.motion_val[1][xy][0] = s->mv[1][0][0];
- s->current_picture.motion_val[1][xy][1] = s->mv[1][0][1];
+ if (!v->field_mode) {
+ s->mv[0][0][0] = scale_mv(s->next_picture.f.motion_val[1][xy][0], v->bfraction, 0, s->quarter_sample);
+ s->mv[0][0][1] = scale_mv(s->next_picture.f.motion_val[1][xy][1], v->bfraction, 0, s->quarter_sample);
+ s->mv[1][0][0] = scale_mv(s->next_picture.f.motion_val[1][xy][0], v->bfraction, 1, s->quarter_sample);
+ s->mv[1][0][1] = scale_mv(s->next_picture.f.motion_val[1][xy][1], v->bfraction, 1, s->quarter_sample);
+
+ /* Pullback predicted motion vectors as specified in 8.4.5.4 */
+ s->mv[0][0][0] = av_clip(s->mv[0][0][0], -60 - (s->mb_x << 6), (s->mb_width << 6) - 4 - (s->mb_x << 6));
+ s->mv[0][0][1] = av_clip(s->mv[0][0][1], -60 - (s->mb_y << 6), (s->mb_height << 6) - 4 - (s->mb_y << 6));
+ s->mv[1][0][0] = av_clip(s->mv[1][0][0], -60 - (s->mb_x << 6), (s->mb_width << 6) - 4 - (s->mb_x << 6));
+ s->mv[1][0][1] = av_clip(s->mv[1][0][1], -60 - (s->mb_y << 6), (s->mb_height << 6) - 4 - (s->mb_y << 6));
+ }
+ if (direct) {
+ s->current_picture.f.motion_val[0][xy + v->blocks_off][0] = s->mv[0][0][0];
+ s->current_picture.f.motion_val[0][xy + v->blocks_off][1] = s->mv[0][0][1];
+ s->current_picture.f.motion_val[1][xy + v->blocks_off][0] = s->mv[1][0][0];
+ s->current_picture.f.motion_val[1][xy + v->blocks_off][1] = s->mv[1][0][1];
return;
}
- if((mvtype == BMV_TYPE_FORWARD) || (mvtype == BMV_TYPE_INTERPOLATED)) {
- C = s->current_picture.motion_val[0][xy - 2];
- A = s->current_picture.motion_val[0][xy - wrap*2];
+ if ((mvtype == BMV_TYPE_FORWARD) || (mvtype == BMV_TYPE_INTERPOLATED)) {
+ C = s->current_picture.f.motion_val[0][xy - 2];
+ A = s->current_picture.f.motion_val[0][xy - wrap * 2];
off = (s->mb_x == (s->mb_width - 1)) ? -2 : 2;
- B = s->current_picture.motion_val[0][xy - wrap*2 + off];
+ B = s->current_picture.f.motion_val[0][xy - wrap * 2 + off];
- if(!s->mb_x) C[0] = C[1] = 0;
- if(!s->first_slice_line) { // predictor A is not out of bounds
- if(s->mb_width == 1) {
+ if (!s->mb_x) C[0] = C[1] = 0;
+ if (!s->first_slice_line) { // predictor A is not out of bounds
+ if (s->mb_width == 1) {
px = A[0];
py = A[1];
} else {
px = mid_pred(A[0], B[0], C[0]);
py = mid_pred(A[1], B[1], C[1]);
}
- } else if(s->mb_x) { // predictor C is not out of bounds
+ } else if (s->mb_x) { // predictor C is not out of bounds
px = C[0];
py = C[1];
} else {
@@ -1233,34 +2241,34 @@ static inline void vc1_pred_b_mv(VC1Context *v, int dmv_x[2], int dmv_y[2], int
/* Pullback MV as specified in 8.3.5.3.4 */
{
int qx, qy, X, Y;
- if(v->profile < PROFILE_ADVANCED) {
+ if (v->profile < PROFILE_ADVANCED) {
qx = (s->mb_x << 5);
qy = (s->mb_y << 5);
- X = (s->mb_width << 5) - 4;
- Y = (s->mb_height << 5) - 4;
- if(qx + px < -28) px = -28 - qx;
- if(qy + py < -28) py = -28 - qy;
- if(qx + px > X) px = X - qx;
- if(qy + py > Y) py = Y - qy;
+ X = (s->mb_width << 5) - 4;
+ Y = (s->mb_height << 5) - 4;
+ if (qx + px < -28) px = -28 - qx;
+ if (qy + py < -28) py = -28 - qy;
+ if (qx + px > X) px = X - qx;
+ if (qy + py > Y) py = Y - qy;
} else {
qx = (s->mb_x << 6);
qy = (s->mb_y << 6);
- X = (s->mb_width << 6) - 4;
- Y = (s->mb_height << 6) - 4;
- if(qx + px < -60) px = -60 - qx;
- if(qy + py < -60) py = -60 - qy;
- if(qx + px > X) px = X - qx;
- if(qy + py > Y) py = Y - qy;
+ X = (s->mb_width << 6) - 4;
+ Y = (s->mb_height << 6) - 4;
+ if (qx + px < -60) px = -60 - qx;
+ if (qy + py < -60) py = -60 - qy;
+ if (qx + px > X) px = X - qx;
+ if (qy + py > Y) py = Y - qy;
}
}
/* Calculate hybrid prediction as specified in 8.3.5.3.5 */
- if(0 && !s->first_slice_line && s->mb_x) {
- if(is_intra[xy - wrap])
+ if (0 && !s->first_slice_line && s->mb_x) {
+ if (is_intra[xy - wrap])
sum = FFABS(px) + FFABS(py);
else
sum = FFABS(px - A[0]) + FFABS(py - A[1]);
- if(sum > 32) {
- if(get_bits1(&s->gb)) {
+ if (sum > 32) {
+ if (get_bits1(&s->gb)) {
px = A[0];
py = A[1];
} else {
@@ -1268,12 +2276,12 @@ static inline void vc1_pred_b_mv(VC1Context *v, int dmv_x[2], int dmv_y[2], int
py = C[1];
}
} else {
- if(is_intra[xy - 2])
+ if (is_intra[xy - 2])
sum = FFABS(px) + FFABS(py);
else
sum = FFABS(px - C[0]) + FFABS(py - C[1]);
- if(sum > 32) {
- if(get_bits1(&s->gb)) {
+ if (sum > 32) {
+ if (get_bits1(&s->gb)) {
px = A[0];
py = A[1];
} else {
@@ -1287,22 +2295,23 @@ static inline void vc1_pred_b_mv(VC1Context *v, int dmv_x[2], int dmv_y[2], int
s->mv[0][0][0] = ((px + dmv_x[0] + r_x) & ((r_x << 1) - 1)) - r_x;
s->mv[0][0][1] = ((py + dmv_y[0] + r_y) & ((r_y << 1) - 1)) - r_y;
}
- if((mvtype == BMV_TYPE_BACKWARD) || (mvtype == BMV_TYPE_INTERPOLATED)) {
- C = s->current_picture.motion_val[1][xy - 2];
- A = s->current_picture.motion_val[1][xy - wrap*2];
+ if ((mvtype == BMV_TYPE_BACKWARD) || (mvtype == BMV_TYPE_INTERPOLATED)) {
+ C = s->current_picture.f.motion_val[1][xy - 2];
+ A = s->current_picture.f.motion_val[1][xy - wrap * 2];
off = (s->mb_x == (s->mb_width - 1)) ? -2 : 2;
- B = s->current_picture.motion_val[1][xy - wrap*2 + off];
+ B = s->current_picture.f.motion_val[1][xy - wrap * 2 + off];
- if(!s->mb_x) C[0] = C[1] = 0;
- if(!s->first_slice_line) { // predictor A is not out of bounds
- if(s->mb_width == 1) {
+ if (!s->mb_x)
+ C[0] = C[1] = 0;
+ if (!s->first_slice_line) { // predictor A is not out of bounds
+ if (s->mb_width == 1) {
px = A[0];
py = A[1];
} else {
px = mid_pred(A[0], B[0], C[0]);
py = mid_pred(A[1], B[1], C[1]);
}
- } else if(s->mb_x) { // predictor C is not out of bounds
+ } else if (s->mb_x) { // predictor C is not out of bounds
px = C[0];
py = C[1];
} else {
@@ -1311,34 +2320,34 @@ static inline void vc1_pred_b_mv(VC1Context *v, int dmv_x[2], int dmv_y[2], int
/* Pullback MV as specified in 8.3.5.3.4 */
{
int qx, qy, X, Y;
- if(v->profile < PROFILE_ADVANCED) {
+ if (v->profile < PROFILE_ADVANCED) {
qx = (s->mb_x << 5);
qy = (s->mb_y << 5);
- X = (s->mb_width << 5) - 4;
- Y = (s->mb_height << 5) - 4;
- if(qx + px < -28) px = -28 - qx;
- if(qy + py < -28) py = -28 - qy;
- if(qx + px > X) px = X - qx;
- if(qy + py > Y) py = Y - qy;
+ X = (s->mb_width << 5) - 4;
+ Y = (s->mb_height << 5) - 4;
+ if (qx + px < -28) px = -28 - qx;
+ if (qy + py < -28) py = -28 - qy;
+ if (qx + px > X) px = X - qx;
+ if (qy + py > Y) py = Y - qy;
} else {
qx = (s->mb_x << 6);
qy = (s->mb_y << 6);
- X = (s->mb_width << 6) - 4;
- Y = (s->mb_height << 6) - 4;
- if(qx + px < -60) px = -60 - qx;
- if(qy + py < -60) py = -60 - qy;
- if(qx + px > X) px = X - qx;
- if(qy + py > Y) py = Y - qy;
+ X = (s->mb_width << 6) - 4;
+ Y = (s->mb_height << 6) - 4;
+ if (qx + px < -60) px = -60 - qx;
+ if (qy + py < -60) py = -60 - qy;
+ if (qx + px > X) px = X - qx;
+ if (qy + py > Y) py = Y - qy;
}
}
/* Calculate hybrid prediction as specified in 8.3.5.3.5 */
- if(0 && !s->first_slice_line && s->mb_x) {
- if(is_intra[xy - wrap])
+ if (0 && !s->first_slice_line && s->mb_x) {
+ if (is_intra[xy - wrap])
sum = FFABS(px) + FFABS(py);
else
sum = FFABS(px - A[0]) + FFABS(py - A[1]);
- if(sum > 32) {
- if(get_bits1(&s->gb)) {
+ if (sum > 32) {
+ if (get_bits1(&s->gb)) {
px = A[0];
py = A[1];
} else {
@@ -1346,12 +2355,12 @@ static inline void vc1_pred_b_mv(VC1Context *v, int dmv_x[2], int dmv_y[2], int
py = C[1];
}
} else {
- if(is_intra[xy - 2])
+ if (is_intra[xy - 2])
sum = FFABS(px) + FFABS(py);
else
sum = FFABS(px - C[0]) + FFABS(py - C[1]);
- if(sum > 32) {
- if(get_bits1(&s->gb)) {
+ if (sum > 32) {
+ if (get_bits1(&s->gb)) {
px = A[0];
py = A[1];
} else {
@@ -1366,10 +2375,67 @@ static inline void vc1_pred_b_mv(VC1Context *v, int dmv_x[2], int dmv_y[2], int
s->mv[1][0][0] = ((px + dmv_x[1] + r_x) & ((r_x << 1) - 1)) - r_x;
s->mv[1][0][1] = ((py + dmv_y[1] + r_y) & ((r_y << 1) - 1)) - r_y;
}
- s->current_picture.motion_val[0][xy][0] = s->mv[0][0][0];
- s->current_picture.motion_val[0][xy][1] = s->mv[0][0][1];
- s->current_picture.motion_val[1][xy][0] = s->mv[1][0][0];
- s->current_picture.motion_val[1][xy][1] = s->mv[1][0][1];
+ s->current_picture.f.motion_val[0][xy][0] = s->mv[0][0][0];
+ s->current_picture.f.motion_val[0][xy][1] = s->mv[0][0][1];
+ s->current_picture.f.motion_val[1][xy][0] = s->mv[1][0][0];
+ s->current_picture.f.motion_val[1][xy][1] = s->mv[1][0][1];
+}
+
+static inline void vc1_pred_b_mv_intfi(VC1Context *v, int n, int *dmv_x, int *dmv_y, int mv1, int *pred_flag)
+{
+ int dir = (v->bmvtype == BMV_TYPE_BACKWARD) ? 1 : 0;
+ MpegEncContext *s = &v->s;
+ int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
+
+ if (v->bmvtype == BMV_TYPE_DIRECT) {
+ int total_opp, k, f;
+ if (s->next_picture.f.mb_type[mb_pos + v->mb_off] != MB_TYPE_INTRA) {
+ s->mv[0][0][0] = scale_mv_intfi(s->next_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][0],
+ v->bfraction, 0, s->quarter_sample, v->qs_last);
+ s->mv[0][0][1] = scale_mv_intfi(s->next_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][1],
+ v->bfraction, 0, s->quarter_sample, v->qs_last);
+ s->mv[1][0][0] = scale_mv_intfi(s->next_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][0],
+ v->bfraction, 1, s->quarter_sample, v->qs_last);
+ s->mv[1][0][1] = scale_mv_intfi(s->next_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][1],
+ v->bfraction, 1, s->quarter_sample, v->qs_last);
+
+ total_opp = v->mv_f_next[0][s->block_index[0] + v->blocks_off]
+ + v->mv_f_next[0][s->block_index[1] + v->blocks_off]
+ + v->mv_f_next[0][s->block_index[2] + v->blocks_off]
+ + v->mv_f_next[0][s->block_index[3] + v->blocks_off];
+ f = (total_opp > 2) ? 1 : 0;
+ } else {
+ s->mv[0][0][0] = s->mv[0][0][1] = 0;
+ s->mv[1][0][0] = s->mv[1][0][1] = 0;
+ f = 0;
+ }
+ v->ref_field_type[0] = v->ref_field_type[1] = v->cur_field_type ^ f;
+ for (k = 0; k < 4; k++) {
+ s->current_picture.f.motion_val[0][s->block_index[k] + v->blocks_off][0] = s->mv[0][0][0];
+ s->current_picture.f.motion_val[0][s->block_index[k] + v->blocks_off][1] = s->mv[0][0][1];
+ s->current_picture.f.motion_val[1][s->block_index[k] + v->blocks_off][0] = s->mv[1][0][0];
+ s->current_picture.f.motion_val[1][s->block_index[k] + v->blocks_off][1] = s->mv[1][0][1];
+ v->mv_f[0][s->block_index[k] + v->blocks_off] = f;
+ v->mv_f[1][s->block_index[k] + v->blocks_off] = f;
+ }
+ return;
+ }
+ if (v->bmvtype == BMV_TYPE_INTERPOLATED) {
+ vc1_pred_mv(v, 0, dmv_x[0], dmv_y[0], 1, v->range_x, v->range_y, v->mb_type[0], pred_flag[0], 0);
+ vc1_pred_mv(v, 0, dmv_x[1], dmv_y[1], 1, v->range_x, v->range_y, v->mb_type[0], pred_flag[1], 1);
+ return;
+ }
+ if (dir) { // backward
+ vc1_pred_mv(v, n, dmv_x[1], dmv_y[1], mv1, v->range_x, v->range_y, v->mb_type[0], pred_flag[1], 1);
+ if (n == 3 || mv1) {
+ vc1_pred_mv(v, 0, dmv_x[0], dmv_y[0], 1, v->range_x, v->range_y, v->mb_type[0], 0, 0);
+ }
+ } else { // forward
+ vc1_pred_mv(v, n, dmv_x[0], dmv_y[0], mv1, v->range_x, v->range_y, v->mb_type[0], pred_flag[0], 0);
+ if (n == 3 || mv1) {
+ vc1_pred_mv(v, 0, dmv_x[1], dmv_y[1], 1, v->range_x, v->range_y, v->mb_type[0], 0, 1);
+ }
+ }
}
/** Get predicted DC value for I-frames only
@@ -1382,23 +2448,23 @@ static inline void vc1_pred_b_mv(VC1Context *v, int dmv_x[2], int dmv_y[2], int
* @param dir_ptr Prediction direction for use in AC prediction
*/
static inline int vc1_i_pred_dc(MpegEncContext *s, int overlap, int pq, int n,
- int16_t **dc_val_ptr, int *dir_ptr)
+ int16_t **dc_val_ptr, int *dir_ptr)
{
int a, b, c, wrap, pred, scale;
int16_t *dc_val;
static const uint16_t dcpred[32] = {
- -1, 1024, 512, 341, 256, 205, 171, 146, 128,
- 114, 102, 93, 85, 79, 73, 68, 64,
- 60, 57, 54, 51, 49, 47, 45, 43,
- 41, 39, 38, 37, 35, 34, 33
+ -1, 1024, 512, 341, 256, 205, 171, 146, 128,
+ 114, 102, 93, 85, 79, 73, 68, 64,
+ 60, 57, 54, 51, 49, 47, 45, 43,
+ 41, 39, 38, 37, 35, 34, 33
};
/* find prediction - wmv3_dc_scale always used here in fact */
- if (n < 4) scale = s->y_dc_scale;
- else scale = s->c_dc_scale;
+ if (n < 4) scale = s->y_dc_scale;
+ else scale = s->c_dc_scale;
- wrap = s->block_wrap[n];
- dc_val= s->dc_val[0] + s->block_index[n];
+ wrap = s->block_wrap[n];
+ dc_val = s->dc_val[0] + s->block_index[n];
/* B A
* C X
@@ -1407,25 +2473,26 @@ static inline int vc1_i_pred_dc(MpegEncContext *s, int overlap, int pq, int n,
b = dc_val[ - 1 - wrap];
a = dc_val[ - wrap];
- if (pq < 9 || !overlap)
- {
+ if (pq < 9 || !overlap) {
/* Set outer values */
- if (s->first_slice_line && (n!=2 && n!=3)) b=a=dcpred[scale];
- if (s->mb_x == 0 && (n!=1 && n!=3)) b=c=dcpred[scale];
- }
- else
- {
+ if (s->first_slice_line && (n != 2 && n != 3))
+ b = a = dcpred[scale];
+ if (s->mb_x == 0 && (n != 1 && n != 3))
+ b = c = dcpred[scale];
+ } else {
/* Set outer values */
- if (s->first_slice_line && (n!=2 && n!=3)) b=a=0;
- if (s->mb_x == 0 && (n!=1 && n!=3)) b=c=0;
+ if (s->first_slice_line && (n != 2 && n != 3))
+ b = a = 0;
+ if (s->mb_x == 0 && (n != 1 && n != 3))
+ b = c = 0;
}
if (abs(a - b) <= abs(b - c)) {
- pred = c;
- *dir_ptr = 1;//left
+ pred = c;
+ *dir_ptr = 1; // left
} else {
- pred = a;
- *dir_ptr = 0;//top
+ pred = a;
+ *dir_ptr = 0; // top
}
/* update predictor */
@@ -1455,7 +2522,7 @@ static inline int vc1_pred_dc(MpegEncContext *s, int overlap, int pq, int n,
int q1, q2 = 0;
wrap = s->block_wrap[n];
- dc_val= s->dc_val[0] + s->block_index[n];
+ dc_val = s->dc_val[0] + s->block_index[n];
/* B A
* C X
@@ -1464,43 +2531,45 @@ static inline int vc1_pred_dc(MpegEncContext *s, int overlap, int pq, int n,
b = dc_val[ - 1 - wrap];
a = dc_val[ - wrap];
/* scale predictors if needed */
- q1 = s->current_picture.qscale_table[mb_pos];
- if(c_avail && (n!= 1 && n!=3)) {
- q2 = s->current_picture.qscale_table[mb_pos - 1];
- if(q2 && q2 != q1)
+ q1 = s->current_picture.f.qscale_table[mb_pos];
+ if (c_avail && (n != 1 && n != 3)) {
+ q2 = s->current_picture.f.qscale_table[mb_pos - 1];
+ if (q2 && q2 != q1)
c = (c * s->y_dc_scale_table[q2] * ff_vc1_dqscale[s->y_dc_scale_table[q1] - 1] + 0x20000) >> 18;
}
- if(a_avail && (n!= 2 && n!=3)) {
- q2 = s->current_picture.qscale_table[mb_pos - s->mb_stride];
- if(q2 && q2 != q1)
+ if (a_avail && (n != 2 && n != 3)) {
+ q2 = s->current_picture.f.qscale_table[mb_pos - s->mb_stride];
+ if (q2 && q2 != q1)
a = (a * s->y_dc_scale_table[q2] * ff_vc1_dqscale[s->y_dc_scale_table[q1] - 1] + 0x20000) >> 18;
}
- if(a_avail && c_avail && (n!=3)) {
+ if (a_avail && c_avail && (n != 3)) {
int off = mb_pos;
- if(n != 1) off--;
- if(n != 2) off -= s->mb_stride;
- q2 = s->current_picture.qscale_table[off];
- if(q2 && q2 != q1)
+ if (n != 1)
+ off--;
+ if (n != 2)
+ off -= s->mb_stride;
+ q2 = s->current_picture.f.qscale_table[off];
+ if (q2 && q2 != q1)
b = (b * s->y_dc_scale_table[q2] * ff_vc1_dqscale[s->y_dc_scale_table[q1] - 1] + 0x20000) >> 18;
}
- if(a_avail && c_avail) {
- if(abs(a - b) <= abs(b - c)) {
- pred = c;
- *dir_ptr = 1;//left
+ if (a_avail && c_avail) {
+ if (abs(a - b) <= abs(b - c)) {
+ pred = c;
+ *dir_ptr = 1; // left
} else {
- pred = a;
- *dir_ptr = 0;//top
+ pred = a;
+ *dir_ptr = 0; // top
}
- } else if(a_avail) {
- pred = a;
- *dir_ptr = 0;//top
- } else if(c_avail) {
- pred = c;
- *dir_ptr = 1;//left
+ } else if (a_avail) {
+ pred = a;
+ *dir_ptr = 0; // top
+ } else if (c_avail) {
+ pred = c;
+ *dir_ptr = 1; // left
} else {
- pred = 0;
- *dir_ptr = 1;//left
+ pred = 0;
+ *dir_ptr = 1; // left
}
/* update predictor */
@@ -1516,11 +2585,12 @@ static inline int vc1_pred_dc(MpegEncContext *s, int overlap, int pq, int n,
* @{
*/
-static inline int vc1_coded_block_pred(MpegEncContext * s, int n, uint8_t **coded_block_ptr)
+static inline int vc1_coded_block_pred(MpegEncContext * s, int n,
+ uint8_t **coded_block_ptr)
{
int xy, wrap, pred, a, b, c;
- xy = s->block_index[n];
+ xy = s->block_index[n];
wrap = s->b8_stride;
/* B C
@@ -1551,61 +2621,62 @@ static inline int vc1_coded_block_pred(MpegEncContext * s, int n, uint8_t **code
* @param codingset set of VLC to decode data
* @see 8.1.3.4
*/
-static void vc1_decode_ac_coeff(VC1Context *v, int *last, int *skip, int *value, int codingset)
+static void vc1_decode_ac_coeff(VC1Context *v, int *last, int *skip,
+ int *value, int codingset)
{
GetBitContext *gb = &v->s.gb;
int index, escape, run = 0, level = 0, lst = 0;
index = get_vlc2(gb, ff_vc1_ac_coeff_table[codingset].table, AC_VLC_BITS, 3);
if (index != vc1_ac_sizes[codingset] - 1) {
- run = vc1_index_decode_table[codingset][index][0];
+ run = vc1_index_decode_table[codingset][index][0];
level = vc1_index_decode_table[codingset][index][1];
- lst = index >= vc1_last_decode_table[codingset] || get_bits_left(gb) < 0;
- if(get_bits1(gb))
+ lst = index >= vc1_last_decode_table[codingset] || get_bits_left(gb) < 0;
+ if (get_bits1(gb))
level = -level;
} else {
escape = decode210(gb);
if (escape != 2) {
index = get_vlc2(gb, ff_vc1_ac_coeff_table[codingset].table, AC_VLC_BITS, 3);
- run = vc1_index_decode_table[codingset][index][0];
+ run = vc1_index_decode_table[codingset][index][0];
level = vc1_index_decode_table[codingset][index][1];
- lst = index >= vc1_last_decode_table[codingset];
- if(escape == 0) {
- if(lst)
+ lst = index >= vc1_last_decode_table[codingset];
+ if (escape == 0) {
+ if (lst)
level += vc1_last_delta_level_table[codingset][run];
else
level += vc1_delta_level_table[codingset][run];
} else {
- if(lst)
+ if (lst)
run += vc1_last_delta_run_table[codingset][level] + 1;
else
run += vc1_delta_run_table[codingset][level] + 1;
}
- if(get_bits1(gb))
+ if (get_bits1(gb))
level = -level;
} else {
int sign;
lst = get_bits1(gb);
- if(v->s.esc3_level_length == 0) {
- if(v->pq < 8 || v->dquantfrm) { // table 59
+ if (v->s.esc3_level_length == 0) {
+ if (v->pq < 8 || v->dquantfrm) { // table 59
v->s.esc3_level_length = get_bits(gb, 3);
- if(!v->s.esc3_level_length)
+ if (!v->s.esc3_level_length)
v->s.esc3_level_length = get_bits(gb, 2) + 8;
- } else { //table 60
+ } else { // table 60
v->s.esc3_level_length = get_unary(gb, 1, 6) + 2;
}
v->s.esc3_run_length = 3 + get_bits(gb, 2);
}
- run = get_bits(gb, v->s.esc3_run_length);
- sign = get_bits1(gb);
+ run = get_bits(gb, v->s.esc3_run_length);
+ sign = get_bits1(gb);
level = get_bits(gb, v->s.esc3_level_length);
- if(sign)
+ if (sign)
level = -level;
}
}
- *last = lst;
- *skip = run;
+ *last = lst;
+ *skip = run;
*value = level;
}
@@ -1616,7 +2687,8 @@ static void vc1_decode_ac_coeff(VC1Context *v, int *last, int *skip, int *value,
* @param coded are AC coeffs present or not
* @param codingset set of VLC to decode data
*/
-static int vc1_decode_i_block(VC1Context *v, DCTELEM block[64], int n, int coded, int codingset)
+static int vc1_decode_i_block(VC1Context *v, DCTELEM block[64], int n,
+ int coded, int codingset)
{
GetBitContext *gb = &v->s.gb;
MpegEncContext *s = &v->s;
@@ -1632,25 +2704,21 @@ static int vc1_decode_i_block(VC1Context *v, DCTELEM block[64], int n, int coded
} else {
dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
}
- if (dcdiff < 0){
+ if (dcdiff < 0) {
av_log(s->avctx, AV_LOG_ERROR, "Illegal DC VLC\n");
return -1;
}
- if (dcdiff)
- {
- if (dcdiff == 119 /* ESC index value */)
- {
+ if (dcdiff) {
+ if (dcdiff == 119 /* ESC index value */) {
/* TODO: Optimize */
- if (v->pq == 1) dcdiff = get_bits(gb, 10);
+ if (v->pq == 1) dcdiff = get_bits(gb, 10);
else if (v->pq == 2) dcdiff = get_bits(gb, 9);
- else dcdiff = get_bits(gb, 8);
- }
- else
- {
+ else dcdiff = get_bits(gb, 8);
+ } else {
if (v->pq == 1)
- dcdiff = (dcdiff<<2) + get_bits(gb, 2) - 3;
+ dcdiff = (dcdiff << 2) + get_bits(gb, 2) - 3;
else if (v->pq == 2)
- dcdiff = (dcdiff<<1) + get_bits1(gb) - 1;
+ dcdiff = (dcdiff << 1) + get_bits1(gb) - 1;
}
if (get_bits1(gb))
dcdiff = -dcdiff;
@@ -1671,7 +2739,7 @@ static int vc1_decode_i_block(VC1Context *v, DCTELEM block[64], int n, int coded
goto not_coded;
}
- //AC Decoding
+ // AC Decoding
i = 1;
{
@@ -1682,87 +2750,87 @@ static int vc1_decode_i_block(VC1Context *v, DCTELEM block[64], int n, int coded
scale = v->pq * 2 + v->halfpq;
- if(v->s.ac_pred) {
- if(!dc_pred_dir)
+ if (v->s.ac_pred) {
+ if (!dc_pred_dir)
zz_table = v->zz_8x8[2];
else
zz_table = v->zz_8x8[3];
} else
zz_table = v->zz_8x8[1];
- ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
+ ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
ac_val2 = ac_val;
- if(dc_pred_dir) //left
+ if (dc_pred_dir) // left
ac_val -= 16;
- else //top
+ else // top
ac_val -= 16 * s->block_wrap[n];
while (!last) {
vc1_decode_ac_coeff(v, &last, &skip, &value, codingset);
i += skip;
- if(i > 63)
+ if (i > 63)
break;
block[zz_table[i++]] = value;
}
/* apply AC prediction if needed */
- if(s->ac_pred) {
- if(dc_pred_dir) { //left
- for(k = 1; k < 8; k++)
+ if (s->ac_pred) {
+ if (dc_pred_dir) { // left
+ for (k = 1; k < 8; k++)
block[k << v->left_blk_sh] += ac_val[k];
- } else { //top
- for(k = 1; k < 8; k++)
+ } else { // top
+ for (k = 1; k < 8; k++)
block[k << v->top_blk_sh] += ac_val[k + 8];
}
}
/* save AC coeffs for further prediction */
- for(k = 1; k < 8; k++) {
+ for (k = 1; k < 8; k++) {
ac_val2[k] = block[k << v->left_blk_sh];
ac_val2[k + 8] = block[k << v->top_blk_sh];
}
/* scale AC coeffs */
- for(k = 1; k < 64; k++)
- if(block[k]) {
+ for (k = 1; k < 64; k++)
+ if (block[k]) {
block[k] *= scale;
- if(!v->pquantizer)
+ if (!v->pquantizer)
block[k] += (block[k] < 0) ? -v->pq : v->pq;
}
- if(s->ac_pred) i = 63;
+ if (s->ac_pred) i = 63;
}
not_coded:
- if(!coded) {
+ if (!coded) {
int k, scale;
- ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
+ ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
ac_val2 = ac_val;
i = 0;
scale = v->pq * 2 + v->halfpq;
memset(ac_val2, 0, 16 * 2);
- if(dc_pred_dir) {//left
+ if (dc_pred_dir) { // left
ac_val -= 16;
- if(s->ac_pred)
+ if (s->ac_pred)
memcpy(ac_val2, ac_val, 8 * 2);
- } else {//top
+ } else { // top
ac_val -= 16 * s->block_wrap[n];
- if(s->ac_pred)
+ if (s->ac_pred)
memcpy(ac_val2 + 8, ac_val + 8, 8 * 2);
}
/* apply AC prediction if needed */
- if(s->ac_pred) {
- if(dc_pred_dir) { //left
- for(k = 1; k < 8; k++) {
+ if (s->ac_pred) {
+ if (dc_pred_dir) { //left
+ for (k = 1; k < 8; k++) {
block[k << v->left_blk_sh] = ac_val[k] * scale;
- if(!v->pquantizer && block[k << v->left_blk_sh])
+ if (!v->pquantizer && block[k << v->left_blk_sh])
block[k << v->left_blk_sh] += (block[k << v->left_blk_sh] < 0) ? -v->pq : v->pq;
}
- } else { //top
- for(k = 1; k < 8; k++) {
+ } else { // top
+ for (k = 1; k < 8; k++) {
block[k << v->top_blk_sh] = ac_val[k + 8] * scale;
- if(!v->pquantizer && block[k << v->top_blk_sh])
+ if (!v->pquantizer && block[k << v->top_blk_sh])
block[k << v->top_blk_sh] += (block[k << v->top_blk_sh] < 0) ? -v->pq : v->pq;
}
}
@@ -1782,7 +2850,8 @@ not_coded:
* @param codingset set of VLC to decode data
* @param mquant quantizer value for this macroblock
*/
-static int vc1_decode_i_block_adv(VC1Context *v, DCTELEM block[64], int n, int coded, int codingset, int mquant)
+static int vc1_decode_i_block_adv(VC1Context *v, DCTELEM block[64], int n,
+ int coded, int codingset, int mquant)
{
GetBitContext *gb = &v->s.gb;
MpegEncContext *s = &v->s;
@@ -1803,25 +2872,21 @@ static int vc1_decode_i_block_adv(VC1Context *v, DCTELEM block[64], int n, int c
} else {
dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
}
- if (dcdiff < 0){
+ if (dcdiff < 0) {
av_log(s->avctx, AV_LOG_ERROR, "Illegal DC VLC\n");
return -1;
}
- if (dcdiff)
- {
- if (dcdiff == 119 /* ESC index value */)
- {
+ if (dcdiff) {
+ if (dcdiff == 119 /* ESC index value */) {
/* TODO: Optimize */
- if (mquant == 1) dcdiff = get_bits(gb, 10);
+ if (mquant == 1) dcdiff = get_bits(gb, 10);
else if (mquant == 2) dcdiff = get_bits(gb, 9);
- else dcdiff = get_bits(gb, 8);
- }
- else
- {
+ else dcdiff = get_bits(gb, 8);
+ } else {
if (mquant == 1)
- dcdiff = (dcdiff<<2) + get_bits(gb, 2) - 3;
+ dcdiff = (dcdiff << 2) + get_bits(gb, 2) - 3;
else if (mquant == 2)
- dcdiff = (dcdiff<<1) + get_bits1(gb) - 1;
+ dcdiff = (dcdiff << 1) + get_bits1(gb) - 1;
}
if (get_bits1(gb))
dcdiff = -dcdiff;
@@ -1842,122 +2907,136 @@ static int vc1_decode_i_block_adv(VC1Context *v, DCTELEM block[64], int n, int c
i = 1;
/* check if AC is needed at all */
- if(!a_avail && !c_avail) use_pred = 0;
- ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
+ if (!a_avail && !c_avail)
+ use_pred = 0;
+ ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
ac_val2 = ac_val;
scale = mquant * 2 + ((mquant == v->pq) ? v->halfpq : 0);
- if(dc_pred_dir) //left
+ if (dc_pred_dir) // left
ac_val -= 16;
- else //top
+ else // top
ac_val -= 16 * s->block_wrap[n];
- q1 = s->current_picture.qscale_table[mb_pos];
- if(dc_pred_dir && c_avail && mb_pos) q2 = s->current_picture.qscale_table[mb_pos - 1];
- if(!dc_pred_dir && a_avail && mb_pos >= s->mb_stride) q2 = s->current_picture.qscale_table[mb_pos - s->mb_stride];
- if(dc_pred_dir && n==1) q2 = q1;
- if(!dc_pred_dir && n==2) q2 = q1;
- if(n==3) q2 = q1;
-
- if(coded) {
+ q1 = s->current_picture.f.qscale_table[mb_pos];
+ if ( dc_pred_dir && c_avail && mb_pos)
+ q2 = s->current_picture.f.qscale_table[mb_pos - 1];
+ if (!dc_pred_dir && a_avail && mb_pos >= s->mb_stride)
+ q2 = s->current_picture.f.qscale_table[mb_pos - s->mb_stride];
+ if ( dc_pred_dir && n == 1)
+ q2 = q1;
+ if (!dc_pred_dir && n == 2)
+ q2 = q1;
+ if (n == 3)
+ q2 = q1;
+
+ if (coded) {
int last = 0, skip, value;
const uint8_t *zz_table;
int k;
- if(v->s.ac_pred) {
- if(!dc_pred_dir)
- zz_table = v->zz_8x8[2];
+ if (v->s.ac_pred) {
+ if (!use_pred && v->fcm == 1) {
+ zz_table = v->zzi_8x8;
+ } else {
+ if (!dc_pred_dir) // top
+ zz_table = v->zz_8x8[2];
+ else // left
+ zz_table = v->zz_8x8[3];
+ }
+ } else {
+ if (v->fcm != 1)
+ zz_table = v->zz_8x8[1];
else
- zz_table = v->zz_8x8[3];
- } else
- zz_table = v->zz_8x8[1];
+ zz_table = v->zzi_8x8;
+ }
while (!last) {
vc1_decode_ac_coeff(v, &last, &skip, &value, codingset);
i += skip;
- if(i > 63)
+ if (i > 63)
break;
block[zz_table[i++]] = value;
}
/* apply AC prediction if needed */
- if(use_pred) {
+ if (use_pred) {
/* scale predictors if needed*/
- if(q2 && q1!=q2) {
+ if (q2 && q1 != q2) {
q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1;
q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1;
- if(dc_pred_dir) { //left
- for(k = 1; k < 8; k++)
+ if (dc_pred_dir) { // left
+ for (k = 1; k < 8; k++)
block[k << v->left_blk_sh] += (ac_val[k] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
- } else { //top
- for(k = 1; k < 8; k++)
+ } else { // top
+ for (k = 1; k < 8; k++)
block[k << v->top_blk_sh] += (ac_val[k + 8] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
}
} else {
- if(dc_pred_dir) { //left
- for(k = 1; k < 8; k++)
+ if (dc_pred_dir) { //left
+ for (k = 1; k < 8; k++)
block[k << v->left_blk_sh] += ac_val[k];
} else { //top
- for(k = 1; k < 8; k++)
+ for (k = 1; k < 8; k++)
block[k << v->top_blk_sh] += ac_val[k + 8];
}
}
}
/* save AC coeffs for further prediction */
- for(k = 1; k < 8; k++) {
+ for (k = 1; k < 8; k++) {
ac_val2[k ] = block[k << v->left_blk_sh];
ac_val2[k + 8] = block[k << v->top_blk_sh];
}
/* scale AC coeffs */
- for(k = 1; k < 64; k++)
- if(block[k]) {
+ for (k = 1; k < 64; k++)
+ if (block[k]) {
block[k] *= scale;
- if(!v->pquantizer)
+ if (!v->pquantizer)
block[k] += (block[k] < 0) ? -mquant : mquant;
}
- if(use_pred) i = 63;
+ if (use_pred) i = 63;
} else { // no AC coeffs
int k;
memset(ac_val2, 0, 16 * 2);
- if(dc_pred_dir) {//left
- if(use_pred) {
+ if (dc_pred_dir) { // left
+ if (use_pred) {
memcpy(ac_val2, ac_val, 8 * 2);
- if(q2 && q1!=q2) {
+ if (q2 && q1 != q2) {
q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1;
q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1;
- for(k = 1; k < 8; k++)
+ for (k = 1; k < 8; k++)
ac_val2[k] = (ac_val2[k] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
}
}
- } else {//top
- if(use_pred) {
+ } else { // top
+ if (use_pred) {
memcpy(ac_val2 + 8, ac_val + 8, 8 * 2);
- if(q2 && q1!=q2) {
+ if (q2 && q1 != q2) {
q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1;
q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1;
- for(k = 1; k < 8; k++)
+ for (k = 1; k < 8; k++)
ac_val2[k + 8] = (ac_val2[k + 8] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
}
}
}
/* apply AC prediction if needed */
- if(use_pred) {
- if(dc_pred_dir) { //left
- for(k = 1; k < 8; k++) {
+ if (use_pred) {
+ if (dc_pred_dir) { // left
+ for (k = 1; k < 8; k++) {
block[k << v->left_blk_sh] = ac_val2[k] * scale;
- if(!v->pquantizer && block[k << v->left_blk_sh])
+ if (!v->pquantizer && block[k << v->left_blk_sh])
block[k << v->left_blk_sh] += (block[k << v->left_blk_sh] < 0) ? -mquant : mquant;
}
- } else { //top
- for(k = 1; k < 8; k++) {
+ } else { // top
+ for (k = 1; k < 8; k++) {
block[k << v->top_blk_sh] = ac_val2[k + 8] * scale;
- if(!v->pquantizer && block[k << v->top_blk_sh])
+ if (!v->pquantizer && block[k << v->top_blk_sh])
block[k << v->top_blk_sh] += (block[k << v->top_blk_sh] < 0) ? -mquant : mquant;
}
}
@@ -1977,7 +3056,8 @@ static int vc1_decode_i_block_adv(VC1Context *v, DCTELEM block[64], int n, int c
* @param mquant block quantizer
* @param codingset set of VLC to decode data
*/
-static int vc1_decode_intra_block(VC1Context *v, DCTELEM block[64], int n, int coded, int mquant, int codingset)
+static int vc1_decode_intra_block(VC1Context *v, DCTELEM block[64], int n,
+ int coded, int mquant, int codingset)
{
GetBitContext *gb = &v->s.gb;
MpegEncContext *s = &v->s;
@@ -1995,7 +3075,7 @@ static int vc1_decode_intra_block(VC1Context *v, DCTELEM block[64], int n, int c
s->dsp.clear_block(block);
/* XXX: Guard against dumb values of mquant */
- mquant = (mquant < 1) ? 0 : ( (mquant>31) ? 31 : mquant );
+ mquant = (mquant < 1) ? 0 : ((mquant > 31) ? 31 : mquant);
/* Set DC scale - y and c use the same */
s->y_dc_scale = s->y_dc_scale_table[mquant];
@@ -2007,25 +3087,21 @@ static int vc1_decode_intra_block(VC1Context *v, DCTELEM block[64], int n, int c
} else {
dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
}
- if (dcdiff < 0){
+ if (dcdiff < 0) {
av_log(s->avctx, AV_LOG_ERROR, "Illegal DC VLC\n");
return -1;
}
- if (dcdiff)
- {
- if (dcdiff == 119 /* ESC index value */)
- {
+ if (dcdiff) {
+ if (dcdiff == 119 /* ESC index value */) {
/* TODO: Optimize */
- if (mquant == 1) dcdiff = get_bits(gb, 10);
+ if (mquant == 1) dcdiff = get_bits(gb, 10);
else if (mquant == 2) dcdiff = get_bits(gb, 9);
- else dcdiff = get_bits(gb, 8);
- }
- else
- {
+ else dcdiff = get_bits(gb, 8);
+ } else {
if (mquant == 1)
- dcdiff = (dcdiff<<2) + get_bits(gb, 2) - 3;
+ dcdiff = (dcdiff << 2) + get_bits(gb, 2) - 3;
else if (mquant == 2)
- dcdiff = (dcdiff<<1) + get_bits1(gb) - 1;
+ dcdiff = (dcdiff << 1) + get_bits1(gb) - 1;
}
if (get_bits1(gb))
dcdiff = -dcdiff;
@@ -2047,115 +3123,130 @@ static int vc1_decode_intra_block(VC1Context *v, DCTELEM block[64], int n, int c
i = 1;
/* check if AC is needed at all and adjust direction if needed */
- if(!a_avail) dc_pred_dir = 1;
- if(!c_avail) dc_pred_dir = 0;
- if(!a_avail && !c_avail) use_pred = 0;
+ if (!a_avail) dc_pred_dir = 1;
+ if (!c_avail) dc_pred_dir = 0;
+ if (!a_avail && !c_avail) use_pred = 0;
ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
ac_val2 = ac_val;
scale = mquant * 2 + v->halfpq;
- if(dc_pred_dir) //left
+ if (dc_pred_dir) //left
ac_val -= 16;
else //top
ac_val -= 16 * s->block_wrap[n];
- q1 = s->current_picture.qscale_table[mb_pos];
- if(dc_pred_dir && c_avail && mb_pos) q2 = s->current_picture.qscale_table[mb_pos - 1];
- if(!dc_pred_dir && a_avail && mb_pos >= s->mb_stride) q2 = s->current_picture.qscale_table[mb_pos - s->mb_stride];
- if(dc_pred_dir && n==1) q2 = q1;
- if(!dc_pred_dir && n==2) q2 = q1;
- if(n==3) q2 = q1;
-
- if(coded) {
+ q1 = s->current_picture.f.qscale_table[mb_pos];
+ if (dc_pred_dir && c_avail && mb_pos)
+ q2 = s->current_picture.f.qscale_table[mb_pos - 1];
+ if (!dc_pred_dir && a_avail && mb_pos >= s->mb_stride)
+ q2 = s->current_picture.f.qscale_table[mb_pos - s->mb_stride];
+ if ( dc_pred_dir && n == 1)
+ q2 = q1;
+ if (!dc_pred_dir && n == 2)
+ q2 = q1;
+ if (n == 3) q2 = q1;
+
+ if (coded) {
int last = 0, skip, value;
int k;
while (!last) {
vc1_decode_ac_coeff(v, &last, &skip, &value, codingset);
i += skip;
- if(i > 63)
+ if (i > 63)
break;
- block[v->zz_8x8[0][i++]] = value;
+ if (v->fcm == 0)
+ block[v->zz_8x8[0][i++]] = value;
+ else {
+ if (use_pred && (v->fcm == 1)) {
+ if (!dc_pred_dir) // top
+ block[v->zz_8x8[2][i++]] = value;
+ else // left
+ block[v->zz_8x8[3][i++]] = value;
+ } else {
+ block[v->zzi_8x8[i++]] = value;
+ }
+ }
}
/* apply AC prediction if needed */
- if(use_pred) {
+ if (use_pred) {
/* scale predictors if needed*/
- if(q2 && q1!=q2) {
+ if (q2 && q1 != q2) {
q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1;
q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1;
- if(dc_pred_dir) { //left
- for(k = 1; k < 8; k++)
+ if (dc_pred_dir) { // left
+ for (k = 1; k < 8; k++)
block[k << v->left_blk_sh] += (ac_val[k] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
} else { //top
- for(k = 1; k < 8; k++)
+ for (k = 1; k < 8; k++)
block[k << v->top_blk_sh] += (ac_val[k + 8] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
}
} else {
- if(dc_pred_dir) { //left
- for(k = 1; k < 8; k++)
+ if (dc_pred_dir) { // left
+ for (k = 1; k < 8; k++)
block[k << v->left_blk_sh] += ac_val[k];
- } else { //top
- for(k = 1; k < 8; k++)
+ } else { // top
+ for (k = 1; k < 8; k++)
block[k << v->top_blk_sh] += ac_val[k + 8];
}
}
}
/* save AC coeffs for further prediction */
- for(k = 1; k < 8; k++) {
+ for (k = 1; k < 8; k++) {
ac_val2[k ] = block[k << v->left_blk_sh];
ac_val2[k + 8] = block[k << v->top_blk_sh];
}
/* scale AC coeffs */
- for(k = 1; k < 64; k++)
- if(block[k]) {
+ for (k = 1; k < 64; k++)
+ if (block[k]) {
block[k] *= scale;
- if(!v->pquantizer)
+ if (!v->pquantizer)
block[k] += (block[k] < 0) ? -mquant : mquant;
}
- if(use_pred) i = 63;
+ if (use_pred) i = 63;
} else { // no AC coeffs
int k;
memset(ac_val2, 0, 16 * 2);
- if(dc_pred_dir) {//left
- if(use_pred) {
+ if (dc_pred_dir) { // left
+ if (use_pred) {
memcpy(ac_val2, ac_val, 8 * 2);
- if(q2 && q1!=q2) {
+ if (q2 && q1 != q2) {
q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1;
q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1;
- for(k = 1; k < 8; k++)
+ for (k = 1; k < 8; k++)
ac_val2[k] = (ac_val2[k] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
}
}
- } else {//top
- if(use_pred) {
+ } else { // top
+ if (use_pred) {
memcpy(ac_val2 + 8, ac_val + 8, 8 * 2);
- if(q2 && q1!=q2) {
+ if (q2 && q1 != q2) {
q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1;
q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1;
- for(k = 1; k < 8; k++)
+ for (k = 1; k < 8; k++)
ac_val2[k + 8] = (ac_val2[k + 8] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
}
}
}
/* apply AC prediction if needed */
- if(use_pred) {
- if(dc_pred_dir) { //left
- for(k = 1; k < 8; k++) {
+ if (use_pred) {
+ if (dc_pred_dir) { // left
+ for (k = 1; k < 8; k++) {
block[k << v->left_blk_sh] = ac_val2[k] * scale;
- if(!v->pquantizer && block[k << v->left_blk_sh])
+ if (!v->pquantizer && block[k << v->left_blk_sh])
block[k << v->left_blk_sh] += (block[k << v->left_blk_sh] < 0) ? -mquant : mquant;
}
- } else { //top
- for(k = 1; k < 8; k++) {
+ } else { // top
+ for (k = 1; k < 8; k++) {
block[k << v->top_blk_sh] = ac_val2[k + 8] * scale;
- if(!v->pquantizer && block[k << v->top_blk_sh])
+ if (!v->pquantizer && block[k << v->top_blk_sh])
block[k << v->top_blk_sh] += (block[k << v->top_blk_sh] < 0) ? -mquant : mquant;
}
}
@@ -2169,8 +3260,10 @@ static int vc1_decode_intra_block(VC1Context *v, DCTELEM block[64], int n, int c
/** Decode P block
*/
-static int vc1_decode_p_block(VC1Context *v, DCTELEM block[64], int n, int mquant, int ttmb, int first_block,
- uint8_t *dst, int linesize, int skip_block, int *ttmb_out)
+static int vc1_decode_p_block(VC1Context *v, DCTELEM block[64], int n,
+ int mquant, int ttmb, int first_block,
+ uint8_t *dst, int linesize, int skip_block,
+ int *ttmb_out)
{
MpegEncContext *s = &v->s;
GetBitContext *gb = &s->gb;
@@ -2182,50 +3275,56 @@ static int vc1_decode_p_block(VC1Context *v, DCTELEM block[64], int n, int mquan
s->dsp.clear_block(block);
- if(ttmb == -1) {
+ if (ttmb == -1) {
ttblk = ff_vc1_ttblk_to_tt[v->tt_index][get_vlc2(gb, ff_vc1_ttblk_vlc[v->tt_index].table, VC1_TTBLK_VLC_BITS, 1)];
}
- if(ttblk == TT_4X4) {
+ if (ttblk == TT_4X4) {
subblkpat = ~(get_vlc2(gb, ff_vc1_subblkpat_vlc[v->tt_index].table, VC1_SUBBLKPAT_VLC_BITS, 1) + 1);
}
- if((ttblk != TT_8X8 && ttblk != TT_4X4)
+ if ((ttblk != TT_8X8 && ttblk != TT_4X4)
&& ((v->ttmbf || (ttmb != -1 && (ttmb & 8) && !first_block))
|| (!v->res_rtm_flag && !first_block))) {
subblkpat = decode012(gb);
- if(subblkpat) subblkpat ^= 3; //swap decoded pattern bits
- if(ttblk == TT_8X4_TOP || ttblk == TT_8X4_BOTTOM) ttblk = TT_8X4;
- if(ttblk == TT_4X8_RIGHT || ttblk == TT_4X8_LEFT) ttblk = TT_4X8;
+ if (subblkpat)
+ subblkpat ^= 3; // swap decoded pattern bits
+ if (ttblk == TT_8X4_TOP || ttblk == TT_8X4_BOTTOM)
+ ttblk = TT_8X4;
+ if (ttblk == TT_4X8_RIGHT || ttblk == TT_4X8_LEFT)
+ ttblk = TT_4X8;
}
scale = 2 * mquant + ((v->pq == mquant) ? v->halfpq : 0);
// convert transforms like 8X4_TOP to generic TT and SUBBLKPAT
- if(ttblk == TT_8X4_TOP || ttblk == TT_8X4_BOTTOM) {
+ if (ttblk == TT_8X4_TOP || ttblk == TT_8X4_BOTTOM) {
subblkpat = 2 - (ttblk == TT_8X4_TOP);
- ttblk = TT_8X4;
+ ttblk = TT_8X4;
}
- if(ttblk == TT_4X8_RIGHT || ttblk == TT_4X8_LEFT) {
+ if (ttblk == TT_4X8_RIGHT || ttblk == TT_4X8_LEFT) {
subblkpat = 2 - (ttblk == TT_4X8_LEFT);
- ttblk = TT_4X8;
+ ttblk = TT_4X8;
}
- switch(ttblk) {
+ switch (ttblk) {
case TT_8X8:
- pat = 0xF;
- i = 0;
+ pat = 0xF;
+ i = 0;
last = 0;
while (!last) {
vc1_decode_ac_coeff(v, &last, &skip, &value, v->codingset2);
i += skip;
- if(i > 63)
+ if (i > 63)
break;
- idx = v->zz_8x8[0][i++];
+ if (!v->interlace)
+ idx = v->zz_8x8[0][i++];
+ else
+ idx = v->zzi_8x8[i++];
block[idx] = value * scale;
- if(!v->pquantizer)
+ if (!v->pquantizer)
block[idx] += (block[idx] < 0) ? -mquant : mquant;
}
- if(!skip_block){
- if(i==1)
+ if (!skip_block) {
+ if (i == 1)
v->vc1dsp.vc1_inv_trans_8x8_dc(dst, linesize, block);
- else{
+ else {
v->vc1dsp.vc1_inv_trans_8x8(block);
s->dsp.add_pixels_clamped(block, dst, linesize);
}
@@ -2233,71 +3332,80 @@ static int vc1_decode_p_block(VC1Context *v, DCTELEM block[64], int n, int mquan
break;
case TT_4X4:
pat = ~subblkpat & 0xF;
- for(j = 0; j < 4; j++) {
+ for (j = 0; j < 4; j++) {
last = subblkpat & (1 << (3 - j));
- i = 0;
- off = (j & 1) * 4 + (j & 2) * 16;
+ i = 0;
+ off = (j & 1) * 4 + (j & 2) * 16;
while (!last) {
vc1_decode_ac_coeff(v, &last, &skip, &value, v->codingset2);
i += skip;
- if(i > 15)
+ if (i > 15)
break;
- idx = ff_vc1_simple_progressive_4x4_zz[i++];
+ if (!v->interlace)
+ idx = ff_vc1_simple_progressive_4x4_zz[i++];
+ else
+ idx = ff_vc1_adv_interlaced_4x4_zz[i++];
block[idx + off] = value * scale;
- if(!v->pquantizer)
+ if (!v->pquantizer)
block[idx + off] += (block[idx + off] < 0) ? -mquant : mquant;
}
- if(!(subblkpat & (1 << (3 - j))) && !skip_block){
- if(i==1)
- v->vc1dsp.vc1_inv_trans_4x4_dc(dst + (j&1)*4 + (j&2)*2*linesize, linesize, block + off);
+ if (!(subblkpat & (1 << (3 - j))) && !skip_block) {
+ if (i == 1)
+ v->vc1dsp.vc1_inv_trans_4x4_dc(dst + (j & 1) * 4 + (j & 2) * 2 * linesize, linesize, block + off);
else
- v->vc1dsp.vc1_inv_trans_4x4(dst + (j&1)*4 + (j&2)*2*linesize, linesize, block + off);
+ v->vc1dsp.vc1_inv_trans_4x4(dst + (j & 1) * 4 + (j & 2) * 2 * linesize, linesize, block + off);
}
}
break;
case TT_8X4:
- pat = ~((subblkpat & 2)*6 + (subblkpat & 1)*3) & 0xF;
- for(j = 0; j < 2; j++) {
+ pat = ~((subblkpat & 2) * 6 + (subblkpat & 1) * 3) & 0xF;
+ for (j = 0; j < 2; j++) {
last = subblkpat & (1 << (1 - j));
- i = 0;
- off = j * 32;
+ i = 0;
+ off = j * 32;
while (!last) {
vc1_decode_ac_coeff(v, &last, &skip, &value, v->codingset2);
i += skip;
- if(i > 31)
+ if (i > 31)
break;
- idx = v->zz_8x4[i++]+off;
+ if (!v->interlace)
+ idx = v->zz_8x4[i++] + off;
+ else
+ idx = ff_vc1_adv_interlaced_8x4_zz[i++] + off;
block[idx] = value * scale;
- if(!v->pquantizer)
+ if (!v->pquantizer)
block[idx] += (block[idx] < 0) ? -mquant : mquant;
}
- if(!(subblkpat & (1 << (1 - j))) && !skip_block){
- if(i==1)
- v->vc1dsp.vc1_inv_trans_8x4_dc(dst + j*4*linesize, linesize, block + off);
+ if (!(subblkpat & (1 << (1 - j))) && !skip_block) {
+ if (i == 1)
+ v->vc1dsp.vc1_inv_trans_8x4_dc(dst + j * 4 * linesize, linesize, block + off);
else
- v->vc1dsp.vc1_inv_trans_8x4(dst + j*4*linesize, linesize, block + off);
+ v->vc1dsp.vc1_inv_trans_8x4(dst + j * 4 * linesize, linesize, block + off);
}
}
break;
case TT_4X8:
- pat = ~(subblkpat*5) & 0xF;
- for(j = 0; j < 2; j++) {
+ pat = ~(subblkpat * 5) & 0xF;
+ for (j = 0; j < 2; j++) {
last = subblkpat & (1 << (1 - j));
- i = 0;
- off = j * 4;
+ i = 0;
+ off = j * 4;
while (!last) {
vc1_decode_ac_coeff(v, &last, &skip, &value, v->codingset2);
i += skip;
- if(i > 31)
+ if (i > 31)
break;
- idx = v->zz_4x8[i++]+off;
+ if (!v->interlace)
+ idx = v->zz_4x8[i++] + off;
+ else
+ idx = ff_vc1_adv_interlaced_4x8_zz[i++] + off;
block[idx] = value * scale;
- if(!v->pquantizer)
+ if (!v->pquantizer)
block[idx] += (block[idx] < 0) ? -mquant : mquant;
}
- if(!(subblkpat & (1 << (1 - j))) && !skip_block){
- if(i==1)
- v->vc1dsp.vc1_inv_trans_4x8_dc(dst + j*4, linesize, block + off);
+ if (!(subblkpat & (1 << (1 - j))) && !skip_block) {
+ if (i == 1)
+ v->vc1dsp.vc1_inv_trans_4x8_dc(dst + j * 4, linesize, block + off);
else
v->vc1dsp.vc1_inv_trans_4x8(dst + j*4, linesize, block + off);
}
@@ -2316,35 +3424,35 @@ static const int offset_table[6] = { 0, 1, 3, 7, 15, 31 };
static av_always_inline void vc1_apply_p_v_loop_filter(VC1Context *v, int block_num)
{
- MpegEncContext *s = &v->s;
+ MpegEncContext *s = &v->s;
int mb_cbp = v->cbp[s->mb_x - s->mb_stride],
block_cbp = mb_cbp >> (block_num * 4), bottom_cbp,
mb_is_intra = v->is_intra[s->mb_x - s->mb_stride],
block_is_intra = mb_is_intra >> (block_num * 4), bottom_is_intra;
- int idx, linesize = block_num > 3 ? s->uvlinesize : s->linesize, ttblk;
+ int idx, linesize = block_num > 3 ? s->uvlinesize : s->linesize, ttblk;
uint8_t *dst;
- if(block_num > 3) {
+ if (block_num > 3) {
dst = s->dest[block_num - 3];
} else {
dst = s->dest[0] + (block_num & 1) * 8 + ((block_num & 2) * 4 - 8) * linesize;
}
- if (s->mb_y != s->mb_height || block_num < 2) {
+ if (s->mb_y != s->end_mb_y || block_num < 2) {
int16_t (*mv)[2];
int mv_stride;
- if(block_num > 3) {
+ if (block_num > 3) {
bottom_cbp = v->cbp[s->mb_x] >> (block_num * 4);
bottom_is_intra = v->is_intra[s->mb_x] >> (block_num * 4);
mv = &v->luma_mv[s->mb_x - s->mb_stride];
mv_stride = s->mb_stride;
} else {
- bottom_cbp = (block_num < 2) ? (mb_cbp >> ((block_num + 2) * 4)) :
- (v->cbp[s->mb_x] >> ((block_num - 2) * 4));
- bottom_is_intra = (block_num < 2) ? (mb_is_intra >> ((block_num + 2) * 4)) :
- (v->is_intra[s->mb_x] >> ((block_num - 2) * 4));
+ bottom_cbp = (block_num < 2) ? (mb_cbp >> ((block_num + 2) * 4))
+ : (v->cbp[s->mb_x] >> ((block_num - 2) * 4));
+ bottom_is_intra = (block_num < 2) ? (mb_is_intra >> ((block_num + 2) * 4))
+ : (v->is_intra[s->mb_x] >> ((block_num - 2) * 4));
mv_stride = s->b8_stride;
- mv = &s->current_picture.motion_val[0][s->block_index[block_num] - 2 * mv_stride];
+ mv = &s->current_picture.f.motion_val[0][s->block_index[block_num] - 2 * mv_stride];
}
if (bottom_is_intra & 1 || block_is_intra & 1 ||
@@ -2352,7 +3460,7 @@ static av_always_inline void vc1_apply_p_v_loop_filter(VC1Context *v, int block_
v->vc1dsp.vc1_v_loop_filter8(dst, linesize, v->pq);
} else {
idx = ((bottom_cbp >> 2) | block_cbp) & 3;
- if(idx == 3) {
+ if (idx == 3) {
v->vc1dsp.vc1_v_loop_filter8(dst, linesize, v->pq);
} else if (idx) {
if (idx == 1)
@@ -2364,7 +3472,7 @@ static av_always_inline void vc1_apply_p_v_loop_filter(VC1Context *v, int block_
}
dst -= 4 * linesize;
- ttblk = (v->ttblk[s->mb_x - s->mb_stride] >> (block_num * 4)) & 0xf;
+ ttblk = (v->ttblk[s->mb_x - s->mb_stride] >> (block_num * 4)) & 0xF;
if (ttblk == TT_4X4 || ttblk == TT_8X4) {
idx = (block_cbp | (block_cbp >> 2)) & 3;
if (idx == 3) {
@@ -2380,12 +3488,12 @@ static av_always_inline void vc1_apply_p_v_loop_filter(VC1Context *v, int block_
static av_always_inline void vc1_apply_p_h_loop_filter(VC1Context *v, int block_num)
{
- MpegEncContext *s = &v->s;
+ MpegEncContext *s = &v->s;
int mb_cbp = v->cbp[s->mb_x - 1 - s->mb_stride],
block_cbp = mb_cbp >> (block_num * 4), right_cbp,
mb_is_intra = v->is_intra[s->mb_x - 1 - s->mb_stride],
block_is_intra = mb_is_intra >> (block_num * 4), right_is_intra;
- int idx, linesize = block_num > 3 ? s->uvlinesize : s->linesize, ttblk;
+ int idx, linesize = block_num > 3 ? s->uvlinesize : s->linesize, ttblk;
uint8_t *dst;
if (block_num > 3) {
@@ -2397,16 +3505,16 @@ static av_always_inline void vc1_apply_p_h_loop_filter(VC1Context *v, int block_
if (s->mb_x != s->mb_width || !(block_num & 5)) {
int16_t (*mv)[2];
- if(block_num > 3) {
+ if (block_num > 3) {
right_cbp = v->cbp[s->mb_x - s->mb_stride] >> (block_num * 4);
right_is_intra = v->is_intra[s->mb_x - s->mb_stride] >> (block_num * 4);
mv = &v->luma_mv[s->mb_x - s->mb_stride - 1];
- }else{
- right_cbp = (block_num & 1) ? (v->cbp[s->mb_x - s->mb_stride] >> ((block_num - 1) * 4)) :
- (mb_cbp >> ((block_num + 1) * 4));
- right_is_intra = (block_num & 1) ? (v->is_intra[s->mb_x - s->mb_stride] >> ((block_num - 1) * 4)) :
- (mb_is_intra >> ((block_num + 1) * 4));
- mv = &s->current_picture.motion_val[0][s->block_index[block_num] - s->b8_stride * 2 - 2];
+ } else {
+ right_cbp = (block_num & 1) ? (v->cbp[s->mb_x - s->mb_stride] >> ((block_num - 1) * 4))
+ : (mb_cbp >> ((block_num + 1) * 4));
+ right_is_intra = (block_num & 1) ? (v->is_intra[s->mb_x - s->mb_stride] >> ((block_num - 1) * 4))
+ : (mb_is_intra >> ((block_num + 1) * 4));
+ mv = &s->current_picture.f.motion_val[0][s->block_index[block_num] - s->b8_stride * 2 - 2];
}
if (block_is_intra & 1 || right_is_intra & 1 || mv[0][0] != mv[1][0] || mv[0][1] != mv[1][1]) {
v->vc1dsp.vc1_h_loop_filter8(dst, linesize, v->pq);
@@ -2416,9 +3524,9 @@ static av_always_inline void vc1_apply_p_h_loop_filter(VC1Context *v, int block_
v->vc1dsp.vc1_h_loop_filter8(dst, linesize, v->pq);
} else if (idx) {
if (idx == 1)
- v->vc1dsp.vc1_h_loop_filter4(dst+4*linesize, linesize, v->pq);
+ v->vc1dsp.vc1_h_loop_filter4(dst + 4 * linesize, linesize, v->pq);
else
- v->vc1dsp.vc1_h_loop_filter4(dst, linesize, v->pq);
+ v->vc1dsp.vc1_h_loop_filter4(dst, linesize, v->pq);
}
}
}
@@ -2431,9 +3539,9 @@ static av_always_inline void vc1_apply_p_h_loop_filter(VC1Context *v, int block_
v->vc1dsp.vc1_h_loop_filter8(dst, linesize, v->pq);
} else if (idx) {
if (idx == 1)
- v->vc1dsp.vc1_h_loop_filter4(dst + linesize*4, linesize, v->pq);
+ v->vc1dsp.vc1_h_loop_filter4(dst + linesize * 4, linesize, v->pq);
else
- v->vc1dsp.vc1_h_loop_filter4(dst, linesize, v->pq);
+ v->vc1dsp.vc1_h_loop_filter4(dst, linesize, v->pq);
}
}
}
@@ -2463,7 +3571,7 @@ static void vc1_apply_p_loop_filter(VC1Context *v)
}
}
-/** Decode one P-frame MB (in Simple/Main profile)
+/** Decode one P-frame MB
*/
static int vc1_decode_p_mb(VC1Context *v)
{
@@ -2495,208 +3603,543 @@ static int vc1_decode_p_mb(VC1Context *v)
else
skipped = v->s.mbskip_table[mb_pos];
- if (!fourmv) /* 1MV mode */
- {
- if (!skipped)
- {
+ if (!fourmv) { /* 1MV mode */
+ if (!skipped) {
GET_MVDATA(dmv_x, dmv_y);
if (s->mb_intra) {
- s->current_picture.motion_val[1][s->block_index[0]][0] = 0;
- s->current_picture.motion_val[1][s->block_index[0]][1] = 0;
+ s->current_picture.f.motion_val[1][s->block_index[0]][0] = 0;
+ s->current_picture.f.motion_val[1][s->block_index[0]][1] = 0;
}
- s->current_picture.mb_type[mb_pos] = s->mb_intra ? MB_TYPE_INTRA : MB_TYPE_16x16;
- vc1_pred_mv(v, 0, dmv_x, dmv_y, 1, v->range_x, v->range_y, v->mb_type[0]);
+ s->current_picture.f.mb_type[mb_pos] = s->mb_intra ? MB_TYPE_INTRA : MB_TYPE_16x16;
+ vc1_pred_mv(v, 0, dmv_x, dmv_y, 1, v->range_x, v->range_y, v->mb_type[0], 0, 0);
/* FIXME Set DC val for inter block ? */
- if (s->mb_intra && !mb_has_coeffs)
- {
+ if (s->mb_intra && !mb_has_coeffs) {
GET_MQUANT();
s->ac_pred = get_bits1(gb);
- cbp = 0;
- }
- else if (mb_has_coeffs)
- {
- if (s->mb_intra) s->ac_pred = get_bits1(gb);
+ cbp = 0;
+ } else if (mb_has_coeffs) {
+ if (s->mb_intra)
+ s->ac_pred = get_bits1(gb);
cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
GET_MQUANT();
- }
- else
- {
+ } else {
mquant = v->pq;
- cbp = 0;
+ cbp = 0;
}
- s->current_picture.qscale_table[mb_pos] = mquant;
+ s->current_picture.f.qscale_table[mb_pos] = mquant;
if (!v->ttmbf && !s->mb_intra && mb_has_coeffs)
ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table,
VC1_TTMB_VLC_BITS, 2);
- if(!s->mb_intra) vc1_mc_1mv(v, 0);
+ if (!s->mb_intra) vc1_mc_1mv(v, 0);
dst_idx = 0;
- for (i=0; i<6; i++)
- {
+ for (i = 0; i < 6; i++) {
s->dc_val[0][s->block_index[i]] = 0;
dst_idx += i >> 2;
val = ((cbp >> (5 - i)) & 1);
off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
v->mb_type[0][s->block_index[i]] = s->mb_intra;
- if(s->mb_intra) {
+ if (s->mb_intra) {
/* check if prediction blocks A and C are available */
v->a_avail = v->c_avail = 0;
- if(i == 2 || i == 3 || !s->first_slice_line)
+ if (i == 2 || i == 3 || !s->first_slice_line)
v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
- if(i == 1 || i == 3 || s->mb_x)
+ if (i == 1 || i == 3 || s->mb_x)
v->c_avail = v->mb_type[0][s->block_index[i] - 1];
- vc1_decode_intra_block(v, s->block[i], i, val, mquant, (i&4)?v->codingset2:v->codingset);
- if((i>3) && (s->flags & CODEC_FLAG_GRAY)) continue;
+ vc1_decode_intra_block(v, s->block[i], i, val, mquant,
+ (i & 4) ? v->codingset2 : v->codingset);
+ if ((i>3) && (s->flags & CODEC_FLAG_GRAY))
+ continue;
v->vc1dsp.vc1_inv_trans_8x8(s->block[i]);
- if(v->rangeredfrm) for(j = 0; j < 64; j++) s->block[i][j] <<= 1;
+ if (v->rangeredfrm)
+ for (j = 0; j < 64; j++)
+ s->block[i][j] <<= 1;
s->dsp.put_signed_pixels_clamped(s->block[i], s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize);
- if(v->pq >= 9 && v->overlap) {
- if(v->c_avail)
+ if (v->pq >= 9 && v->overlap) {
+ if (v->c_avail)
v->vc1dsp.vc1_h_overlap(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize);
- if(v->a_avail)
+ if (v->a_avail)
v->vc1dsp.vc1_v_overlap(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize);
}
- block_cbp |= 0xF << (i << 2);
+ block_cbp |= 0xF << (i << 2);
block_intra |= 1 << i;
- } else if(val) {
- pat = vc1_decode_p_block(v, s->block[i], i, mquant, ttmb, first_block, s->dest[dst_idx] + off, (i&4)?s->uvlinesize:s->linesize, (i&4) && (s->flags & CODEC_FLAG_GRAY), &block_tt);
+ } else if (val) {
+ pat = vc1_decode_p_block(v, s->block[i], i, mquant, ttmb, first_block,
+ s->dest[dst_idx] + off, (i & 4) ? s->uvlinesize : s->linesize,
+ (i & 4) && (s->flags & CODEC_FLAG_GRAY), &block_tt);
block_cbp |= pat << (i << 2);
- if(!v->ttmbf && ttmb < 8) ttmb = -1;
+ if (!v->ttmbf && ttmb < 8)
+ ttmb = -1;
first_block = 0;
}
}
- }
- else //Skipped
- {
+ } else { // skipped
s->mb_intra = 0;
- for(i = 0; i < 6; i++) {
+ for (i = 0; i < 6; i++) {
v->mb_type[0][s->block_index[i]] = 0;
- s->dc_val[0][s->block_index[i]] = 0;
+ s->dc_val[0][s->block_index[i]] = 0;
}
- s->current_picture.mb_type[mb_pos] = MB_TYPE_SKIP;
- s->current_picture.qscale_table[mb_pos] = 0;
- vc1_pred_mv(v, 0, 0, 0, 1, v->range_x, v->range_y, v->mb_type[0]);
+ s->current_picture.f.mb_type[mb_pos] = MB_TYPE_SKIP;
+ s->current_picture.f.qscale_table[mb_pos] = 0;
+ vc1_pred_mv(v, 0, 0, 0, 1, v->range_x, v->range_y, v->mb_type[0], 0, 0);
vc1_mc_1mv(v, 0);
}
- } //1MV mode
- else //4MV mode
- {
- if (!skipped /* unskipped MB */)
- {
+ } else { // 4MV mode
+ if (!skipped /* unskipped MB */) {
int intra_count = 0, coded_inter = 0;
int is_intra[6], is_coded[6];
/* Get CBPCY */
cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
- for (i=0; i<6; i++)
- {
+ for (i = 0; i < 6; i++) {
val = ((cbp >> (5 - i)) & 1);
s->dc_val[0][s->block_index[i]] = 0;
- s->mb_intra = 0;
- if(i < 4) {
+ s->mb_intra = 0;
+ if (i < 4) {
dmv_x = dmv_y = 0;
- s->mb_intra = 0;
+ s->mb_intra = 0;
mb_has_coeffs = 0;
- if(val) {
+ if (val) {
GET_MVDATA(dmv_x, dmv_y);
}
- vc1_pred_mv(v, i, dmv_x, dmv_y, 0, v->range_x, v->range_y, v->mb_type[0]);
- if(!s->mb_intra) vc1_mc_4mv_luma(v, i);
+ vc1_pred_mv(v, i, dmv_x, dmv_y, 0, v->range_x, v->range_y, v->mb_type[0], 0, 0);
+ if (!s->mb_intra)
+ vc1_mc_4mv_luma(v, i, 0);
intra_count += s->mb_intra;
- is_intra[i] = s->mb_intra;
- is_coded[i] = mb_has_coeffs;
+ is_intra[i] = s->mb_intra;
+ is_coded[i] = mb_has_coeffs;
}
- if(i&4){
+ if (i & 4) {
is_intra[i] = (intra_count >= 3);
is_coded[i] = val;
}
- if(i == 4) vc1_mc_4mv_chroma(v);
+ if (i == 4)
+ vc1_mc_4mv_chroma(v, 0);
v->mb_type[0][s->block_index[i]] = is_intra[i];
- if(!coded_inter) coded_inter = !is_intra[i] & is_coded[i];
+ if (!coded_inter)
+ coded_inter = !is_intra[i] & is_coded[i];
}
// if there are no coded blocks then don't do anything more
dst_idx = 0;
- if(!intra_count && !coded_inter)
+ if (!intra_count && !coded_inter)
goto end;
GET_MQUANT();
- s->current_picture.qscale_table[mb_pos] = mquant;
+ s->current_picture.f.qscale_table[mb_pos] = mquant;
/* test if block is intra and has pred */
{
int intrapred = 0;
- for(i=0; i<6; i++)
- if(is_intra[i]) {
- if(((!s->first_slice_line || (i==2 || i==3)) && v->mb_type[0][s->block_index[i] - s->block_wrap[i]])
- || ((s->mb_x || (i==1 || i==3)) && v->mb_type[0][s->block_index[i] - 1])) {
+ for (i = 0; i < 6; i++)
+ if (is_intra[i]) {
+ if (((!s->first_slice_line || (i == 2 || i == 3)) && v->mb_type[0][s->block_index[i] - s->block_wrap[i]])
+ || ((s->mb_x || (i == 1 || i == 3)) && v->mb_type[0][s->block_index[i] - 1])) {
intrapred = 1;
break;
}
}
- if(intrapred)s->ac_pred = get_bits1(gb);
- else s->ac_pred = 0;
+ if (intrapred)
+ s->ac_pred = get_bits1(gb);
+ else
+ s->ac_pred = 0;
}
if (!v->ttmbf && coded_inter)
ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2);
- for (i=0; i<6; i++)
- {
- dst_idx += i >> 2;
- off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
+ for (i = 0; i < 6; i++) {
+ dst_idx += i >> 2;
+ off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
s->mb_intra = is_intra[i];
if (is_intra[i]) {
/* check if prediction blocks A and C are available */
v->a_avail = v->c_avail = 0;
- if(i == 2 || i == 3 || !s->first_slice_line)
+ if (i == 2 || i == 3 || !s->first_slice_line)
v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
- if(i == 1 || i == 3 || s->mb_x)
+ if (i == 1 || i == 3 || s->mb_x)
v->c_avail = v->mb_type[0][s->block_index[i] - 1];
- vc1_decode_intra_block(v, s->block[i], i, is_coded[i], mquant, (i&4)?v->codingset2:v->codingset);
- if((i>3) && (s->flags & CODEC_FLAG_GRAY)) continue;
+ vc1_decode_intra_block(v, s->block[i], i, is_coded[i], mquant,
+ (i & 4) ? v->codingset2 : v->codingset);
+ if ((i>3) && (s->flags & CODEC_FLAG_GRAY))
+ continue;
v->vc1dsp.vc1_inv_trans_8x8(s->block[i]);
- if(v->rangeredfrm) for(j = 0; j < 64; j++) s->block[i][j] <<= 1;
- s->dsp.put_signed_pixels_clamped(s->block[i], s->dest[dst_idx] + off, (i&4)?s->uvlinesize:s->linesize);
- if(v->pq >= 9 && v->overlap) {
- if(v->c_avail)
+ if (v->rangeredfrm)
+ for (j = 0; j < 64; j++)
+ s->block[i][j] <<= 1;
+ s->dsp.put_signed_pixels_clamped(s->block[i], s->dest[dst_idx] + off,
+ (i & 4) ? s->uvlinesize : s->linesize);
+ if (v->pq >= 9 && v->overlap) {
+ if (v->c_avail)
v->vc1dsp.vc1_h_overlap(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize);
- if(v->a_avail)
+ if (v->a_avail)
v->vc1dsp.vc1_v_overlap(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize);
}
- block_cbp |= 0xF << (i << 2);
+ block_cbp |= 0xF << (i << 2);
block_intra |= 1 << i;
- } else if(is_coded[i]) {
- pat = vc1_decode_p_block(v, s->block[i], i, mquant, ttmb, first_block, s->dest[dst_idx] + off, (i&4)?s->uvlinesize:s->linesize, (i&4) && (s->flags & CODEC_FLAG_GRAY), &block_tt);
+ } else if (is_coded[i]) {
+ pat = vc1_decode_p_block(v, s->block[i], i, mquant, ttmb,
+ first_block, s->dest[dst_idx] + off,
+ (i & 4) ? s->uvlinesize : s->linesize,
+ (i & 4) && (s->flags & CODEC_FLAG_GRAY),
+ &block_tt);
block_cbp |= pat << (i << 2);
- if(!v->ttmbf && ttmb < 8) ttmb = -1;
+ if (!v->ttmbf && ttmb < 8)
+ ttmb = -1;
first_block = 0;
}
}
- }
- else //Skipped MB
- {
- s->mb_intra = 0;
- s->current_picture.qscale_table[mb_pos] = 0;
- for (i=0; i<6; i++) {
+ } else { // skipped MB
+ s->mb_intra = 0;
+ s->current_picture.f.qscale_table[mb_pos] = 0;
+ for (i = 0; i < 6; i++) {
v->mb_type[0][s->block_index[i]] = 0;
- s->dc_val[0][s->block_index[i]] = 0;
+ s->dc_val[0][s->block_index[i]] = 0;
}
- for (i=0; i<4; i++)
- {
- vc1_pred_mv(v, i, 0, 0, 0, v->range_x, v->range_y, v->mb_type[0]);
- vc1_mc_4mv_luma(v, i);
+ for (i = 0; i < 4; i++) {
+ vc1_pred_mv(v, i, 0, 0, 0, v->range_x, v->range_y, v->mb_type[0], 0, 0);
+ vc1_mc_4mv_luma(v, i, 0);
}
- vc1_mc_4mv_chroma(v);
- s->current_picture.qscale_table[mb_pos] = 0;
+ vc1_mc_4mv_chroma(v, 0);
+ s->current_picture.f.qscale_table[mb_pos] = 0;
}
}
end:
- v->cbp[s->mb_x] = block_cbp;
- v->ttblk[s->mb_x] = block_tt;
+ v->cbp[s->mb_x] = block_cbp;
+ v->ttblk[s->mb_x] = block_tt;
v->is_intra[s->mb_x] = block_intra;
return 0;
}
+/* Decode one macroblock in an interlaced frame p picture */
+
+static int vc1_decode_p_mb_intfr(VC1Context *v)
+{
+ MpegEncContext *s = &v->s;
+ GetBitContext *gb = &s->gb;
+ int i;
+ int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
+ int cbp = 0; /* cbp decoding stuff */
+ int mqdiff, mquant; /* MB quantization */
+ int ttmb = v->ttfrm; /* MB Transform type */
+
+ int mb_has_coeffs = 1; /* last_flag */
+ int dmv_x, dmv_y; /* Differential MV components */
+ int val; /* temp value */
+ int first_block = 1;
+ int dst_idx, off;
+ int skipped, fourmv = 0, twomv = 0;
+ int block_cbp = 0, pat, block_tt = 0;
+ int idx_mbmode = 0, mvbp;
+ int stride_y, fieldtx;
+
+ mquant = v->pq; /* Loosy initialization */
+
+ if (v->skip_is_raw)
+ skipped = get_bits1(gb);
+ else
+ skipped = v->s.mbskip_table[mb_pos];
+ if (!skipped) {
+ if (v->fourmvswitch)
+ idx_mbmode = get_vlc2(gb, v->mbmode_vlc->table, VC1_INTFR_4MV_MBMODE_VLC_BITS, 2); // try getting this done
+ else
+ idx_mbmode = get_vlc2(gb, v->mbmode_vlc->table, VC1_INTFR_NON4MV_MBMODE_VLC_BITS, 2); // in a single line
+ switch (ff_vc1_mbmode_intfrp[v->fourmvswitch][idx_mbmode][0]) {
+ /* store the motion vector type in a flag (useful later) */
+ case MV_PMODE_INTFR_4MV:
+ fourmv = 1;
+ v->blk_mv_type[s->block_index[0]] = 0;
+ v->blk_mv_type[s->block_index[1]] = 0;
+ v->blk_mv_type[s->block_index[2]] = 0;
+ v->blk_mv_type[s->block_index[3]] = 0;
+ break;
+ case MV_PMODE_INTFR_4MV_FIELD:
+ fourmv = 1;
+ v->blk_mv_type[s->block_index[0]] = 1;
+ v->blk_mv_type[s->block_index[1]] = 1;
+ v->blk_mv_type[s->block_index[2]] = 1;
+ v->blk_mv_type[s->block_index[3]] = 1;
+ break;
+ case MV_PMODE_INTFR_2MV_FIELD:
+ twomv = 1;
+ v->blk_mv_type[s->block_index[0]] = 1;
+ v->blk_mv_type[s->block_index[1]] = 1;
+ v->blk_mv_type[s->block_index[2]] = 1;
+ v->blk_mv_type[s->block_index[3]] = 1;
+ break;
+ case MV_PMODE_INTFR_1MV:
+ v->blk_mv_type[s->block_index[0]] = 0;
+ v->blk_mv_type[s->block_index[1]] = 0;
+ v->blk_mv_type[s->block_index[2]] = 0;
+ v->blk_mv_type[s->block_index[3]] = 0;
+ break;
+ }
+ if (ff_vc1_mbmode_intfrp[v->fourmvswitch][idx_mbmode][0] == MV_PMODE_INTFR_INTRA) { // intra MB
+ s->current_picture.f.motion_val[1][s->block_index[0]][0] = 0;
+ s->current_picture.f.motion_val[1][s->block_index[0]][1] = 0;
+ s->current_picture.f.mb_type[mb_pos] = MB_TYPE_INTRA;
+ s->mb_intra = v->is_intra[s->mb_x] = 1;
+ for (i = 0; i < 6; i++)
+ v->mb_type[0][s->block_index[i]] = 1;
+ fieldtx = v->fieldtx_plane[mb_pos] = get_bits1(gb);
+ mb_has_coeffs = get_bits1(gb);
+ if (mb_has_coeffs)
+ cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
+ v->s.ac_pred = v->acpred_plane[mb_pos] = get_bits1(gb);
+ GET_MQUANT();
+ s->current_picture.f.qscale_table[mb_pos] = mquant;
+ /* Set DC scale - y and c use the same (not sure if necessary here) */
+ s->y_dc_scale = s->y_dc_scale_table[mquant];
+ s->c_dc_scale = s->c_dc_scale_table[mquant];
+ dst_idx = 0;
+ for (i = 0; i < 6; i++) {
+ s->dc_val[0][s->block_index[i]] = 0;
+ dst_idx += i >> 2;
+ val = ((cbp >> (5 - i)) & 1);
+ v->mb_type[0][s->block_index[i]] = s->mb_intra;
+ v->a_avail = v->c_avail = 0;
+ if (i == 2 || i == 3 || !s->first_slice_line)
+ v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
+ if (i == 1 || i == 3 || s->mb_x)
+ v->c_avail = v->mb_type[0][s->block_index[i] - 1];
+
+ vc1_decode_intra_block(v, s->block[i], i, val, mquant,
+ (i & 4) ? v->codingset2 : v->codingset);
+ if ((i>3) && (s->flags & CODEC_FLAG_GRAY)) continue;
+ v->vc1dsp.vc1_inv_trans_8x8(s->block[i]);
+ if (i < 4) {
+ stride_y = s->linesize << fieldtx;
+ off = (fieldtx) ? ((i & 1) * 8) + ((i & 2) >> 1) * s->linesize : (i & 1) * 8 + 4 * (i & 2) * s->linesize;
+ } else {
+ stride_y = s->uvlinesize;
+ off = 0;
+ }
+ s->dsp.put_signed_pixels_clamped(s->block[i], s->dest[dst_idx] + off, stride_y);
+ //TODO: loop filter
+ }
+
+ } else { // inter MB
+ mb_has_coeffs = ff_vc1_mbmode_intfrp[v->fourmvswitch][idx_mbmode][3];
+ if (mb_has_coeffs)
+ cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
+ if (ff_vc1_mbmode_intfrp[v->fourmvswitch][idx_mbmode][0] == MV_PMODE_INTFR_2MV_FIELD) {
+ v->twomvbp = get_vlc2(gb, v->twomvbp_vlc->table, VC1_2MV_BLOCK_PATTERN_VLC_BITS, 1);
+ } else {
+ if ((ff_vc1_mbmode_intfrp[v->fourmvswitch][idx_mbmode][0] == MV_PMODE_INTFR_4MV)
+ || (ff_vc1_mbmode_intfrp[v->fourmvswitch][idx_mbmode][0] == MV_PMODE_INTFR_4MV_FIELD)) {
+ v->fourmvbp = get_vlc2(gb, v->fourmvbp_vlc->table, VC1_4MV_BLOCK_PATTERN_VLC_BITS, 1);
+ }
+ }
+ s->mb_intra = v->is_intra[s->mb_x] = 0;
+ for (i = 0; i < 6; i++)
+ v->mb_type[0][s->block_index[i]] = 0;
+ fieldtx = v->fieldtx_plane[mb_pos] = ff_vc1_mbmode_intfrp[v->fourmvswitch][idx_mbmode][1];
+ /* for all motion vector read MVDATA and motion compensate each block */
+ dst_idx = 0;
+ if (fourmv) {
+ mvbp = v->fourmvbp;
+ for (i = 0; i < 6; i++) {
+ if (i < 4) {
+ dmv_x = dmv_y = 0;
+ val = ((mvbp >> (3 - i)) & 1);
+ if (val) {
+ get_mvdata_interlaced(v, &dmv_x, &dmv_y, 0);
+ }
+ vc1_pred_mv_intfr(v, i, dmv_x, dmv_y, 0, v->range_x, v->range_y, v->mb_type[0]);
+ vc1_mc_4mv_luma(v, i, 0);
+ } else if (i == 4) {
+ vc1_mc_4mv_chroma4(v);
+ }
+ }
+ } else if (twomv) {
+ mvbp = v->twomvbp;
+ dmv_x = dmv_y = 0;
+ if (mvbp & 2) {
+ get_mvdata_interlaced(v, &dmv_x, &dmv_y, 0);
+ }
+ vc1_pred_mv_intfr(v, 0, dmv_x, dmv_y, 2, v->range_x, v->range_y, v->mb_type[0]);
+ vc1_mc_4mv_luma(v, 0, 0);
+ vc1_mc_4mv_luma(v, 1, 0);
+ dmv_x = dmv_y = 0;
+ if (mvbp & 1) {
+ get_mvdata_interlaced(v, &dmv_x, &dmv_y, 0);
+ }
+ vc1_pred_mv_intfr(v, 2, dmv_x, dmv_y, 2, v->range_x, v->range_y, v->mb_type[0]);
+ vc1_mc_4mv_luma(v, 2, 0);
+ vc1_mc_4mv_luma(v, 3, 0);
+ vc1_mc_4mv_chroma4(v);
+ } else {
+ mvbp = ff_vc1_mbmode_intfrp[v->fourmvswitch][idx_mbmode][2];
+ if (mvbp) {
+ get_mvdata_interlaced(v, &dmv_x, &dmv_y, 0);
+ }
+ vc1_pred_mv_intfr(v, 0, dmv_x, dmv_y, 1, v->range_x, v->range_y, v->mb_type[0]);
+ vc1_mc_1mv(v, 0);
+ }
+ if (cbp)
+ GET_MQUANT(); // p. 227
+ s->current_picture.f.qscale_table[mb_pos] = mquant;
+ if (!v->ttmbf && cbp)
+ ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2);
+ for (i = 0; i < 6; i++) {
+ s->dc_val[0][s->block_index[i]] = 0;
+ dst_idx += i >> 2;
+ val = ((cbp >> (5 - i)) & 1);
+ if (!fieldtx)
+ off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
+ else
+ off = (i & 4) ? 0 : ((i & 1) * 8 + ((i > 1) * s->linesize));
+ if (val) {
+ pat = vc1_decode_p_block(v, s->block[i], i, mquant, ttmb,
+ first_block, s->dest[dst_idx] + off,
+ (i & 4) ? s->uvlinesize : (s->linesize << fieldtx),
+ (i & 4) && (s->flags & CODEC_FLAG_GRAY), &block_tt);
+ block_cbp |= pat << (i << 2);
+ if (!v->ttmbf && ttmb < 8)
+ ttmb = -1;
+ first_block = 0;
+ }
+ }
+ }
+ } else { // skipped
+ s->mb_intra = v->is_intra[s->mb_x] = 0;
+ for (i = 0; i < 6; i++) {
+ v->mb_type[0][s->block_index[i]] = 0;
+ s->dc_val[0][s->block_index[i]] = 0;
+ }
+ s->current_picture.f.mb_type[mb_pos] = MB_TYPE_SKIP;
+ s->current_picture.f.qscale_table[mb_pos] = 0;
+ v->blk_mv_type[s->block_index[0]] = 0;
+ v->blk_mv_type[s->block_index[1]] = 0;
+ v->blk_mv_type[s->block_index[2]] = 0;
+ v->blk_mv_type[s->block_index[3]] = 0;
+ vc1_pred_mv_intfr(v, 0, 0, 0, 1, v->range_x, v->range_y, v->mb_type[0]);
+ vc1_mc_1mv(v, 0);
+ }
+ if (s->mb_x == s->mb_width - 1)
+ memmove(v->is_intra_base, v->is_intra, sizeof(v->is_intra_base[0])*s->mb_stride);
+ return 0;
+}
+
+static int vc1_decode_p_mb_intfi(VC1Context *v)
+{
+ MpegEncContext *s = &v->s;
+ GetBitContext *gb = &s->gb;
+ int i;
+ int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
+ int cbp = 0; /* cbp decoding stuff */
+ int mqdiff, mquant; /* MB quantization */
+ int ttmb = v->ttfrm; /* MB Transform type */
+
+ int mb_has_coeffs = 1; /* last_flag */
+ int dmv_x, dmv_y; /* Differential MV components */
+ int val; /* temp values */
+ int first_block = 1;
+ int dst_idx, off;
+ int pred_flag;
+ int block_cbp = 0, pat, block_tt = 0;
+ int idx_mbmode = 0;
+
+ mquant = v->pq; /* Loosy initialization */
+
+ idx_mbmode = get_vlc2(gb, v->mbmode_vlc->table, VC1_IF_MBMODE_VLC_BITS, 2);
+ if (idx_mbmode <= 1) { // intra MB
+ s->mb_intra = v->is_intra[s->mb_x] = 1;
+ s->current_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][0] = 0;
+ s->current_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][1] = 0;
+ s->current_picture.f.mb_type[mb_pos + v->mb_off] = MB_TYPE_INTRA;
+ GET_MQUANT();
+ s->current_picture.f.qscale_table[mb_pos] = mquant;
+ /* Set DC scale - y and c use the same (not sure if necessary here) */
+ s->y_dc_scale = s->y_dc_scale_table[mquant];
+ s->c_dc_scale = s->c_dc_scale_table[mquant];
+ v->s.ac_pred = v->acpred_plane[mb_pos] = get_bits1(gb);
+ mb_has_coeffs = idx_mbmode & 1;
+ if (mb_has_coeffs)
+ cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_ICBPCY_VLC_BITS, 2);
+ dst_idx = 0;
+ for (i = 0; i < 6; i++) {
+ s->dc_val[0][s->block_index[i]] = 0;
+ v->mb_type[0][s->block_index[i]] = 1;
+ dst_idx += i >> 2;
+ val = ((cbp >> (5 - i)) & 1);
+ v->a_avail = v->c_avail = 0;
+ if (i == 2 || i == 3 || !s->first_slice_line)
+ v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
+ if (i == 1 || i == 3 || s->mb_x)
+ v->c_avail = v->mb_type[0][s->block_index[i] - 1];
+
+ vc1_decode_intra_block(v, s->block[i], i, val, mquant,
+ (i & 4) ? v->codingset2 : v->codingset);
+ if ((i>3) && (s->flags & CODEC_FLAG_GRAY))
+ continue;
+ v->vc1dsp.vc1_inv_trans_8x8(s->block[i]);
+ off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
+ off += v->cur_field_type ? ((i & 4) ? s->current_picture_ptr->f.linesize[1] : s->current_picture_ptr->f.linesize[0]) : 0;
+ s->dsp.put_signed_pixels_clamped(s->block[i], s->dest[dst_idx] + off, (i & 4) ? s->uvlinesize : s->linesize);
+ // TODO: loop filter
+ }
+ } else {
+ s->mb_intra = v->is_intra[s->mb_x] = 0;
+ s->current_picture.f.mb_type[mb_pos + v->mb_off] = MB_TYPE_16x16;
+ for (i = 0; i < 6; i++) v->mb_type[0][s->block_index[i]] = 0;
+ if (idx_mbmode <= 5) { // 1-MV
+ dmv_x = dmv_y = 0;
+ if (idx_mbmode & 1) {
+ get_mvdata_interlaced(v, &dmv_x, &dmv_y, &pred_flag);
+ }
+ vc1_pred_mv(v, 0, dmv_x, dmv_y, 1, v->range_x, v->range_y, v->mb_type[0], pred_flag, 0);
+ vc1_mc_1mv(v, 0);
+ mb_has_coeffs = !(idx_mbmode & 2);
+ } else { // 4-MV
+ v->fourmvbp = get_vlc2(gb, v->fourmvbp_vlc->table, VC1_4MV_BLOCK_PATTERN_VLC_BITS, 1);
+ for (i = 0; i < 6; i++) {
+ if (i < 4) {
+ dmv_x = dmv_y = pred_flag = 0;
+ val = ((v->fourmvbp >> (3 - i)) & 1);
+ if (val) {
+ get_mvdata_interlaced(v, &dmv_x, &dmv_y, &pred_flag);
+ }
+ vc1_pred_mv(v, i, dmv_x, dmv_y, 0, v->range_x, v->range_y, v->mb_type[0], pred_flag, 0);
+ vc1_mc_4mv_luma(v, i, 0);
+ } else if (i == 4)
+ vc1_mc_4mv_chroma(v, 0);
+ }
+ mb_has_coeffs = idx_mbmode & 1;
+ }
+ if (mb_has_coeffs)
+ cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
+ if (cbp) {
+ GET_MQUANT();
+ }
+ s->current_picture.f.qscale_table[mb_pos] = mquant;
+ if (!v->ttmbf && cbp) {
+ ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2);
+ }
+ dst_idx = 0;
+ for (i = 0; i < 6; i++) {
+ s->dc_val[0][s->block_index[i]] = 0;
+ dst_idx += i >> 2;
+ val = ((cbp >> (5 - i)) & 1);
+ off = (i & 4) ? 0 : (i & 1) * 8 + (i & 2) * 4 * s->linesize;
+ if (v->cur_field_type)
+ off += (i & 4) ? s->current_picture_ptr->f.linesize[1] : s->current_picture_ptr->f.linesize[0];
+ if (val) {
+ pat = vc1_decode_p_block(v, s->block[i], i, mquant, ttmb,
+ first_block, s->dest[dst_idx] + off,
+ (i & 4) ? s->uvlinesize : s->linesize,
+ (i & 4) && (s->flags & CODEC_FLAG_GRAY),
+ &block_tt);
+ block_cbp |= pat << (i << 2);
+ if (!v->ttmbf && ttmb < 8) ttmb = -1;
+ first_block = 0;
+ }
+ }
+ }
+ if (s->mb_x == s->mb_width - 1)
+ memmove(v->is_intra_base, v->is_intra, sizeof(v->is_intra_base[0]) * s->mb_stride);
+ return 0;
+}
+
/** Decode one B-frame MB (in Main profile)
*/
static void vc1_decode_b_mb(VC1Context *v)
@@ -2717,7 +4160,7 @@ static void vc1_decode_b_mb(VC1Context *v)
int dmv_x[2], dmv_y[2];
int bmvtype = BMV_TYPE_BACKWARD;
- mquant = v->pq; /* Loosy initialization */
+ mquant = v->pq; /* Loosy initialization */
s->mb_intra = 0;
if (v->dmb_is_raw)
@@ -2730,11 +4173,11 @@ static void vc1_decode_b_mb(VC1Context *v)
skipped = v->s.mbskip_table[mb_pos];
dmv_x[0] = dmv_x[1] = dmv_y[0] = dmv_y[1] = 0;
- for(i = 0; i < 6; i++) {
+ for (i = 0; i < 6; i++) {
v->mb_type[0][s->block_index[i]] = 0;
- s->dc_val[0][s->block_index[i]] = 0;
+ s->dc_val[0][s->block_index[i]] = 0;
}
- s->current_picture.qscale_table[mb_pos] = 0;
+ s->current_picture.f.qscale_table[mb_pos] = 0;
if (!direct) {
if (!skipped) {
@@ -2742,9 +4185,9 @@ static void vc1_decode_b_mb(VC1Context *v)
dmv_x[1] = dmv_x[0];
dmv_y[1] = dmv_y[0];
}
- if(skipped || !s->mb_intra) {
+ if (skipped || !s->mb_intra) {
bmvtype = decode012(gb);
- switch(bmvtype) {
+ switch (bmvtype) {
case 0:
bmvtype = (v->bfraction >= (B_FRACTION_DEN/2)) ? BMV_TYPE_BACKWARD : BMV_TYPE_FORWARD;
break;
@@ -2752,16 +4195,17 @@ static void vc1_decode_b_mb(VC1Context *v)
bmvtype = (v->bfraction >= (B_FRACTION_DEN/2)) ? BMV_TYPE_FORWARD : BMV_TYPE_BACKWARD;
break;
case 2:
- bmvtype = BMV_TYPE_INTERPOLATED;
+ bmvtype = BMV_TYPE_INTERPOLATED;
dmv_x[0] = dmv_y[0] = 0;
}
}
}
- for(i = 0; i < 6; i++)
+ for (i = 0; i < 6; i++)
v->mb_type[0][s->block_index[i]] = s->mb_intra;
if (skipped) {
- if(direct) bmvtype = BMV_TYPE_INTERPOLATED;
+ if (direct)
+ bmvtype = BMV_TYPE_INTERPOLATED;
vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype);
vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
return;
@@ -2770,29 +4214,29 @@ static void vc1_decode_b_mb(VC1Context *v)
cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
GET_MQUANT();
s->mb_intra = 0;
- s->current_picture.qscale_table[mb_pos] = mquant;
- if(!v->ttmbf)
+ s->current_picture.f.qscale_table[mb_pos] = mquant;
+ if (!v->ttmbf)
ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2);
dmv_x[0] = dmv_y[0] = dmv_x[1] = dmv_y[1] = 0;
vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype);
vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
} else {
- if(!mb_has_coeffs && !s->mb_intra) {
+ if (!mb_has_coeffs && !s->mb_intra) {
/* no coded blocks - effectively skipped */
vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype);
vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
return;
}
- if(s->mb_intra && !mb_has_coeffs) {
+ if (s->mb_intra && !mb_has_coeffs) {
GET_MQUANT();
- s->current_picture.qscale_table[mb_pos] = mquant;
+ s->current_picture.f.qscale_table[mb_pos] = mquant;
s->ac_pred = get_bits1(gb);
cbp = 0;
vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype);
} else {
- if(bmvtype == BMV_TYPE_INTERPOLATED) {
+ if (bmvtype == BMV_TYPE_INTERPOLATED) {
GET_MVDATA(dmv_x[0], dmv_y[0]);
- if(!mb_has_coeffs) {
+ if (!mb_has_coeffs) {
/* interpolated skipped block */
vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype);
vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
@@ -2800,47 +4244,210 @@ static void vc1_decode_b_mb(VC1Context *v)
}
}
vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype);
- if(!s->mb_intra) {
+ if (!s->mb_intra) {
vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
}
- if(s->mb_intra)
+ if (s->mb_intra)
s->ac_pred = get_bits1(gb);
cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
GET_MQUANT();
- s->current_picture.qscale_table[mb_pos] = mquant;
- if(!v->ttmbf && !s->mb_intra && mb_has_coeffs)
+ s->current_picture.f.qscale_table[mb_pos] = mquant;
+ if (!v->ttmbf && !s->mb_intra && mb_has_coeffs)
ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2);
}
}
dst_idx = 0;
- for (i=0; i<6; i++)
- {
+ for (i = 0; i < 6; i++) {
s->dc_val[0][s->block_index[i]] = 0;
dst_idx += i >> 2;
val = ((cbp >> (5 - i)) & 1);
off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
v->mb_type[0][s->block_index[i]] = s->mb_intra;
- if(s->mb_intra) {
+ if (s->mb_intra) {
/* check if prediction blocks A and C are available */
v->a_avail = v->c_avail = 0;
- if(i == 2 || i == 3 || !s->first_slice_line)
+ if (i == 2 || i == 3 || !s->first_slice_line)
v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
- if(i == 1 || i == 3 || s->mb_x)
+ if (i == 1 || i == 3 || s->mb_x)
v->c_avail = v->mb_type[0][s->block_index[i] - 1];
- vc1_decode_intra_block(v, s->block[i], i, val, mquant, (i&4)?v->codingset2:v->codingset);
- if((i>3) && (s->flags & CODEC_FLAG_GRAY)) continue;
+ vc1_decode_intra_block(v, s->block[i], i, val, mquant,
+ (i & 4) ? v->codingset2 : v->codingset);
+ if ((i>3) && (s->flags & CODEC_FLAG_GRAY))
+ continue;
v->vc1dsp.vc1_inv_trans_8x8(s->block[i]);
- if(v->rangeredfrm) for(j = 0; j < 64; j++) s->block[i][j] <<= 1;
+ if (v->rangeredfrm)
+ for (j = 0; j < 64; j++)
+ s->block[i][j] <<= 1;
s->dsp.put_signed_pixels_clamped(s->block[i], s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize);
- } else if(val) {
- vc1_decode_p_block(v, s->block[i], i, mquant, ttmb, first_block, s->dest[dst_idx] + off, (i&4)?s->uvlinesize:s->linesize, (i&4) && (s->flags & CODEC_FLAG_GRAY), NULL);
- if(!v->ttmbf && ttmb < 8) ttmb = -1;
+ } else if (val) {
+ vc1_decode_p_block(v, s->block[i], i, mquant, ttmb,
+ first_block, s->dest[dst_idx] + off,
+ (i & 4) ? s->uvlinesize : s->linesize,
+ (i & 4) && (s->flags & CODEC_FLAG_GRAY), NULL);
+ if (!v->ttmbf && ttmb < 8)
+ ttmb = -1;
first_block = 0;
}
}
}
+/** Decode one B-frame MB (in interlaced field B picture)
+ */
+static void vc1_decode_b_mb_intfi(VC1Context *v)
+{
+ MpegEncContext *s = &v->s;
+ GetBitContext *gb = &s->gb;
+ int i, j;
+ int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
+ int cbp = 0; /* cbp decoding stuff */
+ int mqdiff, mquant; /* MB quantization */
+ int ttmb = v->ttfrm; /* MB Transform type */
+ int mb_has_coeffs = 0; /* last_flag */
+ int val; /* temp value */
+ int first_block = 1;
+ int dst_idx, off;
+ int fwd;
+ int dmv_x[2], dmv_y[2], pred_flag[2];
+ int bmvtype = BMV_TYPE_BACKWARD;
+ int idx_mbmode, interpmvp;
+
+ mquant = v->pq; /* Loosy initialization */
+ s->mb_intra = 0;
+
+ idx_mbmode = get_vlc2(gb, v->mbmode_vlc->table, VC1_IF_MBMODE_VLC_BITS, 2);
+ if (idx_mbmode <= 1) { // intra MB
+ s->mb_intra = v->is_intra[s->mb_x] = 1;
+ s->current_picture.f.motion_val[1][s->block_index[0]][0] = 0;
+ s->current_picture.f.motion_val[1][s->block_index[0]][1] = 0;
+ s->current_picture.f.mb_type[mb_pos + v->mb_off] = MB_TYPE_INTRA;
+ GET_MQUANT();
+ s->current_picture.f.qscale_table[mb_pos] = mquant;
+ /* Set DC scale - y and c use the same (not sure if necessary here) */
+ s->y_dc_scale = s->y_dc_scale_table[mquant];
+ s->c_dc_scale = s->c_dc_scale_table[mquant];
+ v->s.ac_pred = v->acpred_plane[mb_pos] = get_bits1(gb);
+ mb_has_coeffs = idx_mbmode & 1;
+ if (mb_has_coeffs)
+ cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_ICBPCY_VLC_BITS, 2);
+ dst_idx = 0;
+ for (i = 0; i < 6; i++) {
+ s->dc_val[0][s->block_index[i]] = 0;
+ dst_idx += i >> 2;
+ val = ((cbp >> (5 - i)) & 1);
+ v->mb_type[0][s->block_index[i]] = s->mb_intra;
+ v->a_avail = v->c_avail = 0;
+ if (i == 2 || i == 3 || !s->first_slice_line)
+ v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
+ if (i == 1 || i == 3 || s->mb_x)
+ v->c_avail = v->mb_type[0][s->block_index[i] - 1];
+
+ vc1_decode_intra_block(v, s->block[i], i, val, mquant,
+ (i & 4) ? v->codingset2 : v->codingset);
+ if ((i>3) && (s->flags & CODEC_FLAG_GRAY))
+ continue;
+ v->vc1dsp.vc1_inv_trans_8x8(s->block[i]);
+ if (v->rangeredfrm)
+ for (j = 0; j < 64; j++)
+ s->block[i][j] <<= 1;
+ off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
+ off += v->cur_field_type ? ((i & 4) ? s->current_picture_ptr->f.linesize[1] : s->current_picture_ptr->f.linesize[0]) : 0;
+ s->dsp.put_signed_pixels_clamped(s->block[i], s->dest[dst_idx] + off, (i & 4) ? s->uvlinesize : s->linesize);
+ // TODO: yet to perform loop filter
+ }
+ } else {
+ s->mb_intra = v->is_intra[s->mb_x] = 0;
+ s->current_picture.f.mb_type[mb_pos + v->mb_off] = MB_TYPE_16x16;
+ for (i = 0; i < 6; i++) v->mb_type[0][s->block_index[i]] = 0;
+ if (v->fmb_is_raw)
+ fwd = v->forward_mb_plane[mb_pos] = get_bits1(gb);
+ else
+ fwd = v->forward_mb_plane[mb_pos];
+ if (idx_mbmode <= 5) { // 1-MV
+ dmv_x[0] = dmv_x[1] = dmv_y[0] = dmv_y[1] = 0;
+ pred_flag[0] = pred_flag[1] = 0;
+ if (fwd)
+ bmvtype = BMV_TYPE_FORWARD;
+ else {
+ bmvtype = decode012(gb);
+ switch (bmvtype) {
+ case 0:
+ bmvtype = BMV_TYPE_BACKWARD;
+ break;
+ case 1:
+ bmvtype = BMV_TYPE_DIRECT;
+ break;
+ case 2:
+ bmvtype = BMV_TYPE_INTERPOLATED;
+ interpmvp = get_bits1(gb);
+ }
+ }
+ v->bmvtype = bmvtype;
+ if (bmvtype != BMV_TYPE_DIRECT && idx_mbmode & 1) {
+ get_mvdata_interlaced(v, &dmv_x[bmvtype == BMV_TYPE_BACKWARD], &dmv_y[bmvtype == BMV_TYPE_BACKWARD], &pred_flag[bmvtype == BMV_TYPE_BACKWARD]);
+ }
+ if (bmvtype == BMV_TYPE_INTERPOLATED && interpmvp) {
+ get_mvdata_interlaced(v, &dmv_x[1], &dmv_y[1], &pred_flag[1]);
+ }
+ if (bmvtype == BMV_TYPE_DIRECT) {
+ dmv_x[0] = dmv_y[0] = pred_flag[0] = 0;
+ dmv_x[1] = dmv_y[1] = pred_flag[0] = 0;
+ }
+ vc1_pred_b_mv_intfi(v, 0, dmv_x, dmv_y, 1, pred_flag);
+ vc1_b_mc(v, dmv_x, dmv_y, (bmvtype == BMV_TYPE_DIRECT), bmvtype);
+ mb_has_coeffs = !(idx_mbmode & 2);
+ } else { // 4-MV
+ if (fwd)
+ bmvtype = BMV_TYPE_FORWARD;
+ v->bmvtype = bmvtype;
+ v->fourmvbp = get_vlc2(gb, v->fourmvbp_vlc->table, VC1_4MV_BLOCK_PATTERN_VLC_BITS, 1);
+ for (i = 0; i < 6; i++) {
+ if (i < 4) {
+ dmv_x[0] = dmv_y[0] = pred_flag[0] = 0;
+ dmv_x[1] = dmv_y[1] = pred_flag[1] = 0;
+ val = ((v->fourmvbp >> (3 - i)) & 1);
+ if (val) {
+ get_mvdata_interlaced(v, &dmv_x[bmvtype == BMV_TYPE_BACKWARD],
+ &dmv_y[bmvtype == BMV_TYPE_BACKWARD],
+ &pred_flag[bmvtype == BMV_TYPE_BACKWARD]);
+ }
+ vc1_pred_b_mv_intfi(v, i, dmv_x, dmv_y, 0, pred_flag);
+ vc1_mc_4mv_luma(v, i, bmvtype == BMV_TYPE_BACKWARD);
+ } else if (i == 4)
+ vc1_mc_4mv_chroma(v, bmvtype == BMV_TYPE_BACKWARD);
+ }
+ mb_has_coeffs = idx_mbmode & 1;
+ }
+ if (mb_has_coeffs)
+ cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
+ if (cbp) {
+ GET_MQUANT();
+ }
+ s->current_picture.f.qscale_table[mb_pos] = mquant;
+ if (!v->ttmbf && cbp) {
+ ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2);
+ }
+ dst_idx = 0;
+ for (i = 0; i < 6; i++) {
+ s->dc_val[0][s->block_index[i]] = 0;
+ dst_idx += i >> 2;
+ val = ((cbp >> (5 - i)) & 1);
+ off = (i & 4) ? 0 : (i & 1) * 8 + (i & 2) * 4 * s->linesize;
+ if (v->cur_field_type)
+ off += (i & 4) ? s->current_picture_ptr->f.linesize[1] : s->current_picture_ptr->f.linesize[0];
+ if (val) {
+ vc1_decode_p_block(v, s->block[i], i, mquant, ttmb,
+ first_block, s->dest[dst_idx] + off,
+ (i & 4) ? s->uvlinesize : s->linesize,
+ (i & 4) && (s->flags & CODEC_FLAG_GRAY), NULL);
+ if (!v->ttmbf && ttmb < 8)
+ ttmb = -1;
+ first_block = 0;
+ }
+ }
+ }
+}
+
/** Decode blocks of I-frame
*/
static void vc1_decode_i_blocks(VC1Context *v)
@@ -2852,7 +4459,7 @@ static void vc1_decode_i_blocks(VC1Context *v)
int mb_pos;
/* select codingmode used for VLC tables selection */
- switch(v->y_ac_table_index){
+ switch (v->y_ac_table_index) {
case 0:
v->codingset = (v->pqindex <= 8) ? CS_HIGH_RATE_INTRA : CS_LOW_MOT_INTRA;
break;
@@ -2864,7 +4471,7 @@ static void vc1_decode_i_blocks(VC1Context *v)
break;
}
- switch(v->c_ac_table_index){
+ switch (v->c_ac_table_index) {
case 0:
v->codingset2 = (v->pqindex <= 8) ? CS_HIGH_RATE_INTER : CS_LOW_MOT_INTER;
break;
@@ -2882,12 +4489,12 @@ static void vc1_decode_i_blocks(VC1Context *v)
//do frame decode
s->mb_x = s->mb_y = 0;
- s->mb_intra = 1;
+ s->mb_intra = 1;
s->first_slice_line = 1;
- for(s->mb_y = 0; s->mb_y < s->mb_height; s->mb_y++) {
+ for (s->mb_y = 0; s->mb_y < s->mb_height; s->mb_y++) {
s->mb_x = 0;
ff_init_block_index(s);
- for(; s->mb_x < s->mb_width; s->mb_x++) {
+ for (; s->mb_x < s->mb_width; s->mb_x++) {
uint8_t *dst[6];
ff_update_block_index(s);
dst[0] = s->dest[0];
@@ -2898,53 +4505,58 @@ static void vc1_decode_i_blocks(VC1Context *v)
dst[5] = s->dest[2];
s->dsp.clear_blocks(s->block[0]);
mb_pos = s->mb_x + s->mb_y * s->mb_width;
- s->current_picture.mb_type[mb_pos] = MB_TYPE_INTRA;
- s->current_picture.qscale_table[mb_pos] = v->pq;
- s->current_picture.motion_val[1][s->block_index[0]][0] = 0;
- s->current_picture.motion_val[1][s->block_index[0]][1] = 0;
+ s->current_picture.f.mb_type[mb_pos] = MB_TYPE_INTRA;
+ s->current_picture.f.qscale_table[mb_pos] = v->pq;
+ s->current_picture.f.motion_val[1][s->block_index[0]][0] = 0;
+ s->current_picture.f.motion_val[1][s->block_index[0]][1] = 0;
// do actual MB decoding and displaying
cbp = get_vlc2(&v->s.gb, ff_msmp4_mb_i_vlc.table, MB_INTRA_VLC_BITS, 2);
v->s.ac_pred = get_bits1(&v->s.gb);
- for(k = 0; k < 6; k++) {
+ for (k = 0; k < 6; k++) {
val = ((cbp >> (5 - k)) & 1);
if (k < 4) {
- int pred = vc1_coded_block_pred(&v->s, k, &coded_val);
- val = val ^ pred;
+ int pred = vc1_coded_block_pred(&v->s, k, &coded_val);
+ val = val ^ pred;
*coded_val = val;
}
cbp |= val << (5 - k);
- vc1_decode_i_block(v, s->block[k], k, val, (k<4)? v->codingset : v->codingset2);
+ vc1_decode_i_block(v, s->block[k], k, val, (k < 4) ? v->codingset : v->codingset2);
- if (k > 3 && (s->flags & CODEC_FLAG_GRAY)) continue;
+ if (k > 3 && (s->flags & CODEC_FLAG_GRAY))
+ continue;
v->vc1dsp.vc1_inv_trans_8x8(s->block[k]);
- if(v->pq >= 9 && v->overlap) {
- if (v->rangeredfrm) for(j = 0; j < 64; j++) s->block[k][j] <<= 1;
+ if (v->pq >= 9 && v->overlap) {
+ if (v->rangeredfrm)
+ for (j = 0; j < 64; j++)
+ s->block[k][j] <<= 1;
s->dsp.put_signed_pixels_clamped(s->block[k], dst[k], k & 4 ? s->uvlinesize : s->linesize);
} else {
- if (v->rangeredfrm) for(j = 0; j < 64; j++) s->block[k][j] = (s->block[k][j] - 64) << 1;
+ if (v->rangeredfrm)
+ for (j = 0; j < 64; j++)
+ s->block[k][j] = (s->block[k][j] - 64) << 1;
s->dsp.put_pixels_clamped(s->block[k], dst[k], k & 4 ? s->uvlinesize : s->linesize);
}
}
- if(v->pq >= 9 && v->overlap) {
- if(s->mb_x) {
+ if (v->pq >= 9 && v->overlap) {
+ if (s->mb_x) {
v->vc1dsp.vc1_h_overlap(s->dest[0], s->linesize);
v->vc1dsp.vc1_h_overlap(s->dest[0] + 8 * s->linesize, s->linesize);
- if(!(s->flags & CODEC_FLAG_GRAY)) {
+ if (!(s->flags & CODEC_FLAG_GRAY)) {
v->vc1dsp.vc1_h_overlap(s->dest[1], s->uvlinesize);
v->vc1dsp.vc1_h_overlap(s->dest[2], s->uvlinesize);
}
}
v->vc1dsp.vc1_h_overlap(s->dest[0] + 8, s->linesize);
v->vc1dsp.vc1_h_overlap(s->dest[0] + 8 * s->linesize + 8, s->linesize);
- if(!s->first_slice_line) {
+ if (!s->first_slice_line) {
v->vc1dsp.vc1_v_overlap(s->dest[0], s->linesize);
v->vc1dsp.vc1_v_overlap(s->dest[0] + 8, s->linesize);
- if(!(s->flags & CODEC_FLAG_GRAY)) {
+ if (!(s->flags & CODEC_FLAG_GRAY)) {
v->vc1dsp.vc1_v_overlap(s->dest[1], s->uvlinesize);
v->vc1dsp.vc1_v_overlap(s->dest[2], s->uvlinesize);
}
@@ -2952,23 +4564,24 @@ static void vc1_decode_i_blocks(VC1Context *v)
v->vc1dsp.vc1_v_overlap(s->dest[0] + 8 * s->linesize, s->linesize);
v->vc1dsp.vc1_v_overlap(s->dest[0] + 8 * s->linesize + 8, s->linesize);
}
- if(v->s.loop_filter) vc1_loop_filter_iblk(v, v->pq);
+ if (v->s.loop_filter) vc1_loop_filter_iblk(v, v->pq);
- if(get_bits_count(&s->gb) > v->bits) {
+ if (get_bits_count(&s->gb) > v->bits) {
ff_er_add_slice(s, 0, 0, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END));
- av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i\n", get_bits_count(&s->gb), v->bits);
+ av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i\n",
+ get_bits_count(&s->gb), v->bits);
return;
}
}
if (!v->s.loop_filter)
ff_draw_horiz_band(s, s->mb_y * 16, 16);
else if (s->mb_y)
- ff_draw_horiz_band(s, (s->mb_y-1) * 16, 16);
+ ff_draw_horiz_band(s, (s->mb_y - 1) * 16, 16);
s->first_slice_line = 0;
}
if (v->s.loop_filter)
- ff_draw_horiz_band(s, (s->mb_height-1)*16, 16);
+ ff_draw_horiz_band(s, (s->mb_height - 1) * 16, 16);
ff_er_add_slice(s, 0, 0, s->mb_width - 1, s->mb_height - 1, (AC_END|DC_END|MV_END));
}
@@ -2986,7 +4599,7 @@ static void vc1_decode_i_blocks_adv(VC1Context *v)
GetBitContext *gb = &s->gb;
/* select codingmode used for VLC tables selection */
- switch(v->y_ac_table_index){
+ switch (v->y_ac_table_index) {
case 0:
v->codingset = (v->pqindex <= 8) ? CS_HIGH_RATE_INTRA : CS_LOW_MOT_INTRA;
break;
@@ -2998,7 +4611,7 @@ static void vc1_decode_i_blocks_adv(VC1Context *v)
break;
}
- switch(v->c_ac_table_index){
+ switch (v->c_ac_table_index) {
case 0:
v->codingset2 = (v->pqindex <= 8) ? CS_HIGH_RATE_INTER : CS_LOW_MOT_INTER;
break;
@@ -3010,32 +4623,34 @@ static void vc1_decode_i_blocks_adv(VC1Context *v)
break;
}
- //do frame decode
- s->mb_x = s->mb_y = 0;
- s->mb_intra = 1;
+ // do frame decode
+ s->mb_x = s->mb_y = 0;
+ s->mb_intra = 1;
s->first_slice_line = 1;
- s->mb_y = s->start_mb_y;
+ s->mb_y = s->start_mb_y;
if (s->start_mb_y) {
s->mb_x = 0;
ff_init_block_index(s);
- memset(&s->coded_block[s->block_index[0]-s->b8_stride], 0,
- s->b8_stride * sizeof(*s->coded_block));
+ memset(&s->coded_block[s->block_index[0] - s->b8_stride], 0,
+ (1 + s->b8_stride) * sizeof(*s->coded_block));
}
- for(; s->mb_y < s->end_mb_y; s->mb_y++) {
+ for (; s->mb_y < s->end_mb_y; s->mb_y++) {
s->mb_x = 0;
ff_init_block_index(s);
- for(;s->mb_x < s->mb_width; s->mb_x++) {
+ for (;s->mb_x < s->mb_width; s->mb_x++) {
DCTELEM (*block)[64] = v->block[v->cur_blk_idx];
ff_update_block_index(s);
s->dsp.clear_blocks(block[0]);
mb_pos = s->mb_x + s->mb_y * s->mb_stride;
- s->current_picture.mb_type[mb_pos] = MB_TYPE_INTRA;
- s->current_picture.motion_val[1][s->block_index[0]][0] = 0;
- s->current_picture.motion_val[1][s->block_index[0]][1] = 0;
+ s->current_picture.f.mb_type[mb_pos + v->mb_off] = MB_TYPE_INTRA;
+ s->current_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][0] = 0;
+ s->current_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][1] = 0;
// do actual MB decoding and displaying
+ if (v->fieldtx_is_raw)
+ v->fieldtx_plane[mb_pos] = get_bits1(&v->s.gb);
cbp = get_vlc2(&v->s.gb, ff_msmp4_mb_i_vlc.table, MB_INTRA_VLC_BITS, 2);
- if(v->acpred_is_raw)
+ if ( v->acpred_is_raw)
v->s.ac_pred = get_bits1(&v->s.gb);
else
v->s.ac_pred = v->acpred_plane[mb_pos];
@@ -3045,37 +4660,41 @@ static void vc1_decode_i_blocks_adv(VC1Context *v)
GET_MQUANT();
- s->current_picture.qscale_table[mb_pos] = mquant;
+ s->current_picture.f.qscale_table[mb_pos] = mquant;
/* Set DC scale - y and c use the same */
s->y_dc_scale = s->y_dc_scale_table[mquant];
s->c_dc_scale = s->c_dc_scale_table[mquant];
- for(k = 0; k < 6; k++) {
+ for (k = 0; k < 6; k++) {
val = ((cbp >> (5 - k)) & 1);
if (k < 4) {
- int pred = vc1_coded_block_pred(&v->s, k, &coded_val);
- val = val ^ pred;
+ int pred = vc1_coded_block_pred(&v->s, k, &coded_val);
+ val = val ^ pred;
*coded_val = val;
}
cbp |= val << (5 - k);
- v->a_avail = !s->first_slice_line || (k==2 || k==3);
- v->c_avail = !!s->mb_x || (k==1 || k==3);
+ v->a_avail = !s->first_slice_line || (k == 2 || k == 3);
+ v->c_avail = !!s->mb_x || (k == 1 || k == 3);
- vc1_decode_i_block_adv(v, block[k], k, val, (k<4)? v->codingset : v->codingset2, mquant);
+ vc1_decode_i_block_adv(v, block[k], k, val,
+ (k < 4) ? v->codingset : v->codingset2, mquant);
- if (k > 3 && (s->flags & CODEC_FLAG_GRAY)) continue;
+ if (k > 3 && (s->flags & CODEC_FLAG_GRAY))
+ continue;
v->vc1dsp.vc1_inv_trans_8x8(block[k]);
}
vc1_smooth_overlap_filter_iblk(v);
vc1_put_signed_blocks_clamped(v);
- if(v->s.loop_filter) vc1_loop_filter_iblk_delayed(v, v->pq);
+ if (v->s.loop_filter) vc1_loop_filter_iblk_delayed(v, v->pq);
- if(get_bits_count(&s->gb) > v->bits) {
+ if (get_bits_count(&s->gb) > v->bits) {
+ // TODO: may need modification to handle slice coding
ff_er_add_slice(s, 0, s->start_mb_y, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END));
- av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i\n", get_bits_count(&s->gb), v->bits);
+ av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i\n",
+ get_bits_count(&s->gb), v->bits);
return;
}
}
@@ -3089,14 +4708,16 @@ static void vc1_decode_i_blocks_adv(VC1Context *v)
/* raw bottom MB row */
s->mb_x = 0;
ff_init_block_index(s);
- for(;s->mb_x < s->mb_width; s->mb_x++) {
+ for (;s->mb_x < s->mb_width; s->mb_x++) {
ff_update_block_index(s);
vc1_put_signed_blocks_clamped(v);
- if(v->s.loop_filter) vc1_loop_filter_iblk_delayed(v, v->pq);
+ if (v->s.loop_filter)
+ vc1_loop_filter_iblk_delayed(v, v->pq);
}
if (v->s.loop_filter)
- ff_draw_horiz_band(s, (s->mb_height-1)*16, 16);
- ff_er_add_slice(s, 0, s->start_mb_y, s->mb_width - 1, s->end_mb_y - 1, (AC_END|DC_END|MV_END));
+ ff_draw_horiz_band(s, (s->end_mb_y-1)*16, 16);
+ ff_er_add_slice(s, 0, s->start_mb_y << v->field_mode, s->mb_width - 1,
+ (s->end_mb_y << v->field_mode) - 1, (AC_END|DC_END|MV_END));
}
static void vc1_decode_p_blocks(VC1Context *v)
@@ -3105,7 +4726,7 @@ static void vc1_decode_p_blocks(VC1Context *v)
int apply_loop_filter;
/* select codingmode used for VLC tables selection */
- switch(v->c_ac_table_index){
+ switch (v->c_ac_table_index) {
case 0:
v->codingset = (v->pqindex <= 8) ? CS_HIGH_RATE_INTRA : CS_LOW_MOT_INTRA;
break;
@@ -3117,7 +4738,7 @@ static void vc1_decode_p_blocks(VC1Context *v)
break;
}
- switch(v->c_ac_table_index){
+ switch (v->c_ac_table_index) {
case 0:
v->codingset2 = (v->pqindex <= 8) ? CS_HIGH_RATE_INTER : CS_LOW_MOT_INTER;
break;
@@ -3129,29 +4750,35 @@ static void vc1_decode_p_blocks(VC1Context *v)
break;
}
- apply_loop_filter = s->loop_filter && !(s->avctx->skip_loop_filter >= AVDISCARD_NONKEY);
+ apply_loop_filter = s->loop_filter && !(s->avctx->skip_loop_filter >= AVDISCARD_NONKEY);
s->first_slice_line = 1;
memset(v->cbp_base, 0, sizeof(v->cbp_base[0])*2*s->mb_stride);
- for(s->mb_y = s->start_mb_y; s->mb_y < s->end_mb_y; s->mb_y++) {
+ for (s->mb_y = s->start_mb_y; s->mb_y < s->end_mb_y; s->mb_y++) {
s->mb_x = 0;
ff_init_block_index(s);
- for(; s->mb_x < s->mb_width; s->mb_x++) {
+ for (; s->mb_x < s->mb_width; s->mb_x++) {
ff_update_block_index(s);
- vc1_decode_p_mb(v);
- if (s->mb_y != s->start_mb_y && apply_loop_filter)
+ if (v->fcm == 2)
+ vc1_decode_p_mb_intfi(v);
+ else if (v->fcm == 1)
+ vc1_decode_p_mb_intfr(v);
+ else vc1_decode_p_mb(v);
+ if (s->mb_y != s->start_mb_y && apply_loop_filter && v->fcm == 0)
vc1_apply_p_loop_filter(v);
- if(get_bits_count(&s->gb) > v->bits || get_bits_count(&s->gb) < 0) {
+ if (get_bits_count(&s->gb) > v->bits || get_bits_count(&s->gb) < 0) {
+ // TODO: may need modification to handle slice coding
ff_er_add_slice(s, 0, s->start_mb_y, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END));
- av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i at %ix%i\n", get_bits_count(&s->gb), v->bits,s->mb_x,s->mb_y);
+ av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i at %ix%i\n",
+ get_bits_count(&s->gb), v->bits, s->mb_x, s->mb_y);
return;
}
}
- memmove(v->cbp_base, v->cbp, sizeof(v->cbp_base[0])*s->mb_stride);
- memmove(v->ttblk_base, v->ttblk, sizeof(v->ttblk_base[0])*s->mb_stride);
- memmove(v->is_intra_base, v->is_intra, sizeof(v->is_intra_base[0])*s->mb_stride);
- memmove(v->luma_mv_base, v->luma_mv, sizeof(v->luma_mv_base[0])*s->mb_stride);
- if (s->mb_y != s->start_mb_y) ff_draw_horiz_band(s, (s->mb_y-1) * 16, 16);
+ memmove(v->cbp_base, v->cbp, sizeof(v->cbp_base[0]) * s->mb_stride);
+ memmove(v->ttblk_base, v->ttblk, sizeof(v->ttblk_base[0]) * s->mb_stride);
+ memmove(v->is_intra_base, v->is_intra, sizeof(v->is_intra_base[0]) * s->mb_stride);
+ memmove(v->luma_mv_base, v->luma_mv, sizeof(v->luma_mv_base[0]) * s->mb_stride);
+ if (s->mb_y != s->start_mb_y) ff_draw_horiz_band(s, (s->mb_y - 1) * 16, 16);
s->first_slice_line = 0;
}
if (apply_loop_filter) {
@@ -3163,8 +4790,9 @@ static void vc1_decode_p_blocks(VC1Context *v)
}
}
if (s->end_mb_y >= s->start_mb_y)
- ff_draw_horiz_band(s, (s->end_mb_y-1) * 16, 16);
- ff_er_add_slice(s, 0, s->start_mb_y, s->mb_width - 1, s->end_mb_y - 1, (AC_END|DC_END|MV_END));
+ ff_draw_horiz_band(s, (s->end_mb_y - 1) * 16, 16);
+ ff_er_add_slice(s, 0, s->start_mb_y << v->field_mode, s->mb_width - 1,
+ (s->end_mb_y << v->field_mode) - 1, (AC_END|DC_END|MV_END));
}
static void vc1_decode_b_blocks(VC1Context *v)
@@ -3172,7 +4800,7 @@ static void vc1_decode_b_blocks(VC1Context *v)
MpegEncContext *s = &v->s;
/* select codingmode used for VLC tables selection */
- switch(v->c_ac_table_index){
+ switch (v->c_ac_table_index) {
case 0:
v->codingset = (v->pqindex <= 8) ? CS_HIGH_RATE_INTRA : CS_LOW_MOT_INTRA;
break;
@@ -3184,7 +4812,7 @@ static void vc1_decode_b_blocks(VC1Context *v)
break;
}
- switch(v->c_ac_table_index){
+ switch (v->c_ac_table_index) {
case 0:
v->codingset2 = (v->pqindex <= 8) ? CS_HIGH_RATE_INTER : CS_LOW_MOT_INTER;
break;
@@ -3197,44 +4825,50 @@ static void vc1_decode_b_blocks(VC1Context *v)
}
s->first_slice_line = 1;
- for(s->mb_y = s->start_mb_y; s->mb_y < s->end_mb_y; s->mb_y++) {
+ for (s->mb_y = s->start_mb_y; s->mb_y < s->end_mb_y; s->mb_y++) {
s->mb_x = 0;
ff_init_block_index(s);
- for(; s->mb_x < s->mb_width; s->mb_x++) {
+ for (; s->mb_x < s->mb_width; s->mb_x++) {
ff_update_block_index(s);
- vc1_decode_b_mb(v);
- if(get_bits_count(&s->gb) > v->bits || get_bits_count(&s->gb) < 0) {
+ if (v->fcm == 2)
+ vc1_decode_b_mb_intfi(v);
+ else
+ vc1_decode_b_mb(v);
+ if (get_bits_count(&s->gb) > v->bits || get_bits_count(&s->gb) < 0) {
+ // TODO: may need modification to handle slice coding
ff_er_add_slice(s, 0, s->start_mb_y, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END));
- av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i at %ix%i\n", get_bits_count(&s->gb), v->bits,s->mb_x,s->mb_y);
+ av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i at %ix%i\n",
+ get_bits_count(&s->gb), v->bits, s->mb_x, s->mb_y);
return;
}
- if(v->s.loop_filter) vc1_loop_filter_iblk(v, v->pq);
+ if (v->s.loop_filter) vc1_loop_filter_iblk(v, v->pq);
}
if (!v->s.loop_filter)
ff_draw_horiz_band(s, s->mb_y * 16, 16);
else if (s->mb_y)
- ff_draw_horiz_band(s, (s->mb_y-1) * 16, 16);
+ ff_draw_horiz_band(s, (s->mb_y - 1) * 16, 16);
s->first_slice_line = 0;
}
if (v->s.loop_filter)
- ff_draw_horiz_band(s, (s->mb_height-1)*16, 16);
- ff_er_add_slice(s, 0, s->start_mb_y, s->mb_width - 1, s->end_mb_y - 1, (AC_END|DC_END|MV_END));
+ ff_draw_horiz_band(s, (s->end_mb_y - 1) * 16, 16);
+ ff_er_add_slice(s, 0, s->start_mb_y << v->field_mode, s->mb_width - 1,
+ (s->end_mb_y << v->field_mode) - 1, (AC_END|DC_END|MV_END));
}
static void vc1_decode_skip_blocks(VC1Context *v)
{
MpegEncContext *s = &v->s;
- ff_er_add_slice(s, 0, 0, s->mb_width - 1, s->mb_height - 1, (AC_END|DC_END|MV_END));
+ ff_er_add_slice(s, 0, s->start_mb_y, s->mb_width - 1, s->end_mb_y - 1, (AC_END|DC_END|MV_END));
s->first_slice_line = 1;
- for(s->mb_y = 0; s->mb_y < s->mb_height; s->mb_y++) {
+ for (s->mb_y = s->start_mb_y; s->mb_y < s->end_mb_y; s->mb_y++) {
s->mb_x = 0;
ff_init_block_index(s);
ff_update_block_index(s);
- memcpy(s->dest[0], s->last_picture.data[0] + s->mb_y * 16 * s->linesize, s->linesize * 16);
- memcpy(s->dest[1], s->last_picture.data[1] + s->mb_y * 8 * s->uvlinesize, s->uvlinesize * 8);
- memcpy(s->dest[2], s->last_picture.data[2] + s->mb_y * 8 * s->uvlinesize, s->uvlinesize * 8);
+ memcpy(s->dest[0], s->last_picture.f.data[0] + s->mb_y * 16 * s->linesize, s->linesize * 16);
+ memcpy(s->dest[1], s->last_picture.f.data[1] + s->mb_y * 8 * s->uvlinesize, s->uvlinesize * 8);
+ memcpy(s->dest[2], s->last_picture.f.data[2] + s->mb_y * 8 * s->uvlinesize, s->uvlinesize * 8);
ff_draw_horiz_band(s, s->mb_y * 16, 16);
s->first_slice_line = 0;
}
@@ -3245,147 +4879,376 @@ static void vc1_decode_blocks(VC1Context *v)
{
v->s.esc3_level_length = 0;
- if(v->x8_type){
- ff_intrax8_decode_picture(&v->x8, 2*v->pq+v->halfpq, v->pq*(!v->pquantizer) );
- }else{
- v->cur_blk_idx = 0;
- v->left_blk_idx = -1;
- v->topleft_blk_idx = 1;
- v->top_blk_idx = 2;
- switch(v->s.pict_type) {
+ if (v->x8_type) {
+ ff_intrax8_decode_picture(&v->x8, 2*v->pq + v->halfpq, v->pq * !v->pquantizer);
+ } else {
+ v->cur_blk_idx = 0;
+ v->left_blk_idx = -1;
+ v->topleft_blk_idx = 1;
+ v->top_blk_idx = 2;
+ switch (v->s.pict_type) {
case AV_PICTURE_TYPE_I:
- if(v->profile == PROFILE_ADVANCED)
+ if (v->profile == PROFILE_ADVANCED)
vc1_decode_i_blocks_adv(v);
else
vc1_decode_i_blocks(v);
break;
case AV_PICTURE_TYPE_P:
- if(v->p_frame_skipped)
+ if (v->p_frame_skipped)
vc1_decode_skip_blocks(v);
else
vc1_decode_p_blocks(v);
break;
case AV_PICTURE_TYPE_B:
- if(v->bi_type){
- if(v->profile == PROFILE_ADVANCED)
+ if (v->bi_type) {
+ if (v->profile == PROFILE_ADVANCED)
vc1_decode_i_blocks_adv(v);
else
vc1_decode_i_blocks(v);
- }else
+ } else
vc1_decode_b_blocks(v);
break;
}
}
}
-static inline float get_float_val(GetBitContext* gb)
+#if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER
+
+typedef struct {
+ /**
+ * Transform coefficients for both sprites in 16.16 fixed point format,
+ * in the order they appear in the bitstream:
+ * x scale
+ * rotation 1 (unused)
+ * x offset
+ * rotation 2 (unused)
+ * y scale
+ * y offset
+ * alpha
+ */
+ int coefs[2][7];
+
+ int effect_type, effect_flag;
+ int effect_pcount1, effect_pcount2; ///< amount of effect parameters stored in effect_params
+ int effect_params1[15], effect_params2[10]; ///< effect parameters in 16.16 fixed point format
+} SpriteData;
+
+static inline int get_fp_val(GetBitContext* gb)
{
- return (float)get_bits_long(gb, 30) / (1<<15) - (1<<14);
+ return (get_bits_long(gb, 30) - (1 << 29)) << 1;
}
-static void vc1_sprite_parse_transform(VC1Context *v, GetBitContext* gb, float c[7])
+static void vc1_sprite_parse_transform(GetBitContext* gb, int c[7])
{
- c[1] = c[3] = 0.0f;
+ c[1] = c[3] = 0;
switch (get_bits(gb, 2)) {
case 0:
- c[0] = 1.0f;
- c[2] = get_float_val(gb);
- c[4] = 1.0f;
+ c[0] = 1 << 16;
+ c[2] = get_fp_val(gb);
+ c[4] = 1 << 16;
break;
case 1:
- c[0] = c[4] = get_float_val(gb);
- c[2] = get_float_val(gb);
+ c[0] = c[4] = get_fp_val(gb);
+ c[2] = get_fp_val(gb);
break;
case 2:
- c[0] = get_float_val(gb);
- c[2] = get_float_val(gb);
- c[4] = get_float_val(gb);
+ c[0] = get_fp_val(gb);
+ c[2] = get_fp_val(gb);
+ c[4] = get_fp_val(gb);
break;
case 3:
- av_log_ask_for_sample(v->s.avctx, NULL);
- c[0] = get_float_val(gb);
- c[1] = get_float_val(gb);
- c[2] = get_float_val(gb);
- c[3] = get_float_val(gb);
- c[4] = get_float_val(gb);
+ c[0] = get_fp_val(gb);
+ c[1] = get_fp_val(gb);
+ c[2] = get_fp_val(gb);
+ c[3] = get_fp_val(gb);
+ c[4] = get_fp_val(gb);
break;
}
- c[5] = get_float_val(gb);
+ c[5] = get_fp_val(gb);
if (get_bits1(gb))
- c[6] = get_float_val(gb);
+ c[6] = get_fp_val(gb);
else
- c[6] = 1.0f;
+ c[6] = 1 << 16;
}
-static void vc1_parse_sprites(VC1Context *v, GetBitContext* gb)
+static void vc1_parse_sprites(VC1Context *v, GetBitContext* gb, SpriteData* sd)
{
- int effect_type, effect_flag, effect_pcount1, effect_pcount2, i;
- float effect_params1[14], effect_params2[10];
-
- float coefs[2][7];
- vc1_sprite_parse_transform(v, gb, coefs[0]);
- av_log(v->s.avctx, AV_LOG_DEBUG, "S1:");
- for (i = 0; i < 7; i++)
- av_log(v->s.avctx, AV_LOG_DEBUG, " %.3f", coefs[0][i]);
- av_log(v->s.avctx, AV_LOG_DEBUG, "\n");
-
- if (v->two_sprites) {
- vc1_sprite_parse_transform(v, gb, coefs[1]);
- av_log(v->s.avctx, AV_LOG_DEBUG, "S2:");
+ AVCodecContext *avctx = v->s.avctx;
+ int sprite, i;
+
+ for (sprite = 0; sprite <= v->two_sprites; sprite++) {
+ vc1_sprite_parse_transform(gb, sd->coefs[sprite]);
+ if (sd->coefs[sprite][1] || sd->coefs[sprite][3])
+ av_log_ask_for_sample(avctx, "Rotation coefficients are not zero");
+ av_log(avctx, AV_LOG_DEBUG, sprite ? "S2:" : "S1:");
for (i = 0; i < 7; i++)
- av_log(v->s.avctx, AV_LOG_DEBUG, " %.3f", coefs[1][i]);
- av_log(v->s.avctx, AV_LOG_DEBUG, "\n");
+ av_log(avctx, AV_LOG_DEBUG, " %d.%.3d",
+ sd->coefs[sprite][i] / (1<<16),
+ (abs(sd->coefs[sprite][i]) & 0xFFFF) * 1000 / (1 << 16));
+ av_log(avctx, AV_LOG_DEBUG, "\n");
}
+
skip_bits(gb, 2);
- if (effect_type = get_bits_long(gb, 30)){
- switch (effect_pcount1 = get_bits(gb, 4)) {
- case 2:
- effect_params1[0] = get_float_val(gb);
- effect_params1[1] = get_float_val(gb);
- break;
+ if (sd->effect_type = get_bits_long(gb, 30)) {
+ switch (sd->effect_pcount1 = get_bits(gb, 4)) {
case 7:
- vc1_sprite_parse_transform(v, gb, effect_params1);
+ vc1_sprite_parse_transform(gb, sd->effect_params1);
break;
case 14:
- vc1_sprite_parse_transform(v, gb, effect_params1);
- vc1_sprite_parse_transform(v, gb, &effect_params1[7]);
+ vc1_sprite_parse_transform(gb, sd->effect_params1);
+ vc1_sprite_parse_transform(gb, sd->effect_params1 + 7);
break;
default:
- av_log_ask_for_sample(v->s.avctx, NULL);
- return;
+ for (i = 0; i < sd->effect_pcount1; i++)
+ sd->effect_params1[i] = get_fp_val(gb);
}
- if (effect_type != 13 || effect_params1[0] != coefs[0][6]) {
+ if (sd->effect_type != 13 || sd->effect_params1[0] != sd->coefs[0][6]) {
// effect 13 is simple alpha blending and matches the opacity above
- av_log(v->s.avctx, AV_LOG_DEBUG, "Effect: %d; params: ", effect_type);
- for (i = 0; i < effect_pcount1; i++)
- av_log(v->s.avctx, AV_LOG_DEBUG, " %.3f", effect_params1[i]);
- av_log(v->s.avctx, AV_LOG_DEBUG, "\n");
+ av_log(avctx, AV_LOG_DEBUG, "Effect: %d; params: ", sd->effect_type);
+ for (i = 0; i < sd->effect_pcount1; i++)
+ av_log(avctx, AV_LOG_DEBUG, " %d.%.2d",
+ sd->effect_params1[i] / (1 << 16),
+ (abs(sd->effect_params1[i]) & 0xFFFF) * 1000 / (1 << 16));
+ av_log(avctx, AV_LOG_DEBUG, "\n");
}
- effect_pcount2 = get_bits(gb, 16);
- if (effect_pcount2 > 10) {
- av_log(v->s.avctx, AV_LOG_ERROR, "Too many effect parameters\n");
+ sd->effect_pcount2 = get_bits(gb, 16);
+ if (sd->effect_pcount2 > 10) {
+ av_log(avctx, AV_LOG_ERROR, "Too many effect parameters\n");
return;
- } else if (effect_pcount2) {
- i = 0;
- av_log(v->s.avctx, AV_LOG_DEBUG, "Effect params 2: ");
- while (i < effect_pcount2){
- effect_params2[i] = get_float_val(gb);
- av_log(v->s.avctx, AV_LOG_DEBUG, " %.3f", effect_params2[i]);
- i++;
+ } else if (sd->effect_pcount2) {
+ i = -1;
+ av_log(avctx, AV_LOG_DEBUG, "Effect params 2: ");
+ while (++i < sd->effect_pcount2) {
+ sd->effect_params2[i] = get_fp_val(gb);
+ av_log(avctx, AV_LOG_DEBUG, " %d.%.2d",
+ sd->effect_params2[i] / (1 << 16),
+ (abs(sd->effect_params2[i]) & 0xFFFF) * 1000 / (1 << 16));
}
- av_log(v->s.avctx, AV_LOG_DEBUG, "\n");
+ av_log(avctx, AV_LOG_DEBUG, "\n");
}
}
- if (effect_flag = get_bits1(gb))
- av_log(v->s.avctx, AV_LOG_DEBUG, "Effect flag set\n");
+ if (sd->effect_flag = get_bits1(gb))
+ av_log(avctx, AV_LOG_DEBUG, "Effect flag set\n");
if (get_bits_count(gb) >= gb->size_in_bits +
- (v->s.avctx->codec_id == CODEC_ID_WMV3 ? 64 : 0))
- av_log(v->s.avctx, AV_LOG_ERROR, "Buffer overrun\n");
+ (avctx->codec_id == CODEC_ID_WMV3IMAGE ? 64 : 0))
+ av_log(avctx, AV_LOG_ERROR, "Buffer overrun\n");
if (get_bits_count(gb) < gb->size_in_bits - 8)
- av_log(v->s.avctx, AV_LOG_WARNING, "Buffer not fully read\n");
+ av_log(avctx, AV_LOG_WARNING, "Buffer not fully read\n");
+}
+
+static void vc1_draw_sprites(VC1Context *v, SpriteData* sd)
+{
+ int i, plane, row, sprite;
+ int sr_cache[2][2] = { { -1, -1 }, { -1, -1 } };
+ uint8_t* src_h[2][2];
+ int xoff[2], xadv[2], yoff[2], yadv[2], alpha;
+ int ysub[2];
+ MpegEncContext *s = &v->s;
+
+ for (i = 0; i < 2; i++) {
+ xoff[i] = av_clip(sd->coefs[i][2], 0, v->sprite_width-1 << 16);
+ xadv[i] = sd->coefs[i][0];
+ if (xadv[i] != 1<<16 || (v->sprite_width << 16) - (v->output_width << 16) - xoff[i])
+ xadv[i] = av_clip(xadv[i], 0, ((v->sprite_width<<16) - xoff[i] - 1) / v->output_width);
+
+ yoff[i] = av_clip(sd->coefs[i][5], 0, v->sprite_height-1 << 16);
+ yadv[i] = av_clip(sd->coefs[i][4], 0, ((v->sprite_height << 16) - yoff[i]) / v->output_height);
+ }
+ alpha = av_clip(sd->coefs[1][6], 0, (1<<16) - 1);
+
+ for (plane = 0; plane < (s->flags&CODEC_FLAG_GRAY ? 1 : 3); plane++) {
+ int width = v->output_width>>!!plane;
+
+ for (row = 0; row < v->output_height>>!!plane; row++) {
+ uint8_t *dst = v->sprite_output_frame.data[plane] +
+ v->sprite_output_frame.linesize[plane] * row;
+
+ for (sprite = 0; sprite <= v->two_sprites; sprite++) {
+ uint8_t *iplane = s->current_picture.f.data[plane];
+ int iline = s->current_picture.f.linesize[plane];
+ int ycoord = yoff[sprite] + yadv[sprite] * row;
+ int yline = ycoord >> 16;
+ ysub[sprite] = ycoord & 0xFFFF;
+ if (sprite) {
+ iplane = s->last_picture.f.data[plane];
+ iline = s->last_picture.f.linesize[plane];
+ }
+ if (!(xoff[sprite] & 0xFFFF) && xadv[sprite] == 1 << 16) {
+ src_h[sprite][0] = iplane + (xoff[sprite] >> 16) + yline * iline;
+ if (ysub[sprite])
+ src_h[sprite][1] = iplane + (xoff[sprite] >> 16) + (yline + 1) * iline;
+ } else {
+ if (sr_cache[sprite][0] != yline) {
+ if (sr_cache[sprite][1] == yline) {
+ FFSWAP(uint8_t*, v->sr_rows[sprite][0], v->sr_rows[sprite][1]);
+ FFSWAP(int, sr_cache[sprite][0], sr_cache[sprite][1]);
+ } else {
+ v->vc1dsp.sprite_h(v->sr_rows[sprite][0], iplane + yline * iline, xoff[sprite], xadv[sprite], width);
+ sr_cache[sprite][0] = yline;
+ }
+ }
+ if (ysub[sprite] && sr_cache[sprite][1] != yline + 1) {
+ v->vc1dsp.sprite_h(v->sr_rows[sprite][1], iplane + (yline + 1) * iline, xoff[sprite], xadv[sprite], width);
+ sr_cache[sprite][1] = yline + 1;
+ }
+ src_h[sprite][0] = v->sr_rows[sprite][0];
+ src_h[sprite][1] = v->sr_rows[sprite][1];
+ }
+ }
+
+ if (!v->two_sprites) {
+ if (ysub[0]) {
+ v->vc1dsp.sprite_v_single(dst, src_h[0][0], src_h[0][1], ysub[0], width);
+ } else {
+ memcpy(dst, src_h[0][0], width);
+ }
+ } else {
+ if (ysub[0] && ysub[1]) {
+ v->vc1dsp.sprite_v_double_twoscale(dst, src_h[0][0], src_h[0][1], ysub[0],
+ src_h[1][0], src_h[1][1], ysub[1], alpha, width);
+ } else if (ysub[0]) {
+ v->vc1dsp.sprite_v_double_onescale(dst, src_h[0][0], src_h[0][1], ysub[0],
+ src_h[1][0], alpha, width);
+ } else if (ysub[1]) {
+ v->vc1dsp.sprite_v_double_onescale(dst, src_h[1][0], src_h[1][1], ysub[1],
+ src_h[0][0], (1<<16)-1-alpha, width);
+ } else {
+ v->vc1dsp.sprite_v_double_noscale(dst, src_h[0][0], src_h[1][0], alpha, width);
+ }
+ }
+ }
+
+ if (!plane) {
+ for (i = 0; i < 2; i++) {
+ xoff[i] >>= 1;
+ yoff[i] >>= 1;
+ }
+ }
+
+ }
+}
+
+
+static int vc1_decode_sprites(VC1Context *v, GetBitContext* gb)
+{
+ MpegEncContext *s = &v->s;
+ AVCodecContext *avctx = s->avctx;
+ SpriteData sd;
+
+ vc1_parse_sprites(v, gb, &sd);
+
+ if (!s->current_picture.f.data[0]) {
+ av_log(avctx, AV_LOG_ERROR, "Got no sprites\n");
+ return -1;
+ }
+
+ if (v->two_sprites && (!s->last_picture_ptr || !s->last_picture.f.data[0])) {
+ av_log(avctx, AV_LOG_WARNING, "Need two sprites, only got one\n");
+ v->two_sprites = 0;
+ }
+
+ if (v->sprite_output_frame.data[0])
+ avctx->release_buffer(avctx, &v->sprite_output_frame);
+
+ v->sprite_output_frame.buffer_hints = FF_BUFFER_HINTS_VALID;
+ v->sprite_output_frame.reference = 0;
+ if (avctx->get_buffer(avctx, &v->sprite_output_frame) < 0) {
+ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
+ return -1;
+ }
+
+ vc1_draw_sprites(v, &sd);
+
+ return 0;
+}
+
+static void vc1_sprite_flush(AVCodecContext *avctx)
+{
+ VC1Context *v = avctx->priv_data;
+ MpegEncContext *s = &v->s;
+ AVFrame *f = &s->current_picture.f;
+ int plane, i;
+
+ /* Windows Media Image codecs have a convergence interval of two keyframes.
+ Since we can't enforce it, clear to black the missing sprite. This is
+ wrong but it looks better than doing nothing. */
+
+ if (f->data[0])
+ for (plane = 0; plane < (s->flags&CODEC_FLAG_GRAY ? 1 : 3); plane++)
+ for (i = 0; i < v->sprite_height>>!!plane; i++)
+ memset(f->data[plane] + i * f->linesize[plane],
+ plane ? 128 : 0, f->linesize[plane]);
+}
+
+#endif
+
+static av_cold int vc1_decode_init_alloc_tables(VC1Context *v)
+{
+ MpegEncContext *s = &v->s;
+ int i;
+
+ /* Allocate mb bitplanes */
+ v->mv_type_mb_plane = av_malloc (s->mb_stride * s->mb_height);
+ v->direct_mb_plane = av_malloc (s->mb_stride * s->mb_height);
+ v->forward_mb_plane = av_malloc (s->mb_stride * s->mb_height);
+ v->fieldtx_plane = av_mallocz(s->mb_stride * s->mb_height);
+ v->acpred_plane = av_malloc (s->mb_stride * s->mb_height);
+ v->over_flags_plane = av_malloc (s->mb_stride * s->mb_height);
+
+ v->n_allocated_blks = s->mb_width + 2;
+ v->block = av_malloc(sizeof(*v->block) * v->n_allocated_blks);
+ v->cbp_base = av_malloc(sizeof(v->cbp_base[0]) * 2 * s->mb_stride);
+ v->cbp = v->cbp_base + s->mb_stride;
+ v->ttblk_base = av_malloc(sizeof(v->ttblk_base[0]) * 2 * s->mb_stride);
+ v->ttblk = v->ttblk_base + s->mb_stride;
+ v->is_intra_base = av_mallocz(sizeof(v->is_intra_base[0]) * 2 * s->mb_stride);
+ v->is_intra = v->is_intra_base + s->mb_stride;
+ v->luma_mv_base = av_malloc(sizeof(v->luma_mv_base[0]) * 2 * s->mb_stride);
+ v->luma_mv = v->luma_mv_base + s->mb_stride;
+
+ /* allocate block type info in that way so it could be used with s->block_index[] */
+ v->mb_type_base = av_malloc(s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride * (s->mb_height + 1) * 2);
+ v->mb_type[0] = v->mb_type_base + s->b8_stride + 1;
+ v->mb_type[1] = v->mb_type_base + s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride + 1;
+ v->mb_type[2] = v->mb_type[1] + s->mb_stride * (s->mb_height + 1);
+
+ /* allocate memory to store block level MV info */
+ v->blk_mv_type_base = av_mallocz( s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride * (s->mb_height + 1) * 2);
+ v->blk_mv_type = v->blk_mv_type_base + s->b8_stride + 1;
+ v->mv_f_base = av_mallocz(2 * (s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride * (s->mb_height + 1) * 2));
+ v->mv_f[0] = v->mv_f_base + s->b8_stride + 1;
+ v->mv_f[1] = v->mv_f[0] + (s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride * (s->mb_height + 1) * 2);
+ v->mv_f_last_base = av_mallocz(2 * (s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride * (s->mb_height + 1) * 2));
+ v->mv_f_last[0] = v->mv_f_last_base + s->b8_stride + 1;
+ v->mv_f_last[1] = v->mv_f_last[0] + (s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride * (s->mb_height + 1) * 2);
+ v->mv_f_next_base = av_mallocz(2 * (s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride * (s->mb_height + 1) * 2));
+ v->mv_f_next[0] = v->mv_f_next_base + s->b8_stride + 1;
+ v->mv_f_next[1] = v->mv_f_next[0] + (s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride * (s->mb_height + 1) * 2);
+
+ /* Init coded blocks info */
+ if (v->profile == PROFILE_ADVANCED) {
+// if (alloc_bitplane(&v->over_flags_plane, s->mb_width, s->mb_height) < 0)
+// return -1;
+// if (alloc_bitplane(&v->ac_pred_plane, s->mb_width, s->mb_height) < 0)
+// return -1;
+ }
+
+ ff_intrax8_common_init(&v->x8,s);
+
+ if (s->avctx->codec_id == CODEC_ID_WMV3IMAGE || s->avctx->codec_id == CODEC_ID_VC1IMAGE) {
+ for (i = 0; i < 4; i++)
+ if (!(v->sr_rows[i >> 1][i & 1] = av_malloc(v->output_width))) return -1;
+ }
+
+ if (!v->mv_type_mb_plane || !v->direct_mb_plane || !v->acpred_plane || !v->over_flags_plane ||
+ !v->block || !v->cbp_base || !v->ttblk_base || !v->is_intra_base || !v->luma_mv_base ||
+ !v->mb_type_base)
+ return -1;
+
+ return 0;
}
/** Initialize a VC1/WMV3 decoder
@@ -3397,9 +5260,14 @@ static av_cold int vc1_decode_init(AVCodecContext *avctx)
VC1Context *v = avctx->priv_data;
MpegEncContext *s = &v->s;
GetBitContext gb;
- int i, cur_width, cur_height;
+ int i;
+
+ /* save the container output size for WMImage */
+ v->output_width = avctx->width;
+ v->output_height = avctx->height;
- if (!avctx->extradata_size || !avctx->extradata) return -1;
+ if (!avctx->extradata_size || !avctx->extradata)
+ return -1;
if (!(avctx->flags & CODEC_FLAG_GRAY))
avctx->pix_fmt = avctx->get_format(avctx, avctx->codec->pix_fmts);
else
@@ -3407,21 +5275,17 @@ static av_cold int vc1_decode_init(AVCodecContext *avctx)
avctx->hwaccel = ff_find_hwaccel(avctx->codec->id, avctx->pix_fmt);
v->s.avctx = avctx;
avctx->flags |= CODEC_FLAG_EMU_EDGE;
- v->s.flags |= CODEC_FLAG_EMU_EDGE;
+ v->s.flags |= CODEC_FLAG_EMU_EDGE;
- if(avctx->idct_algo==FF_IDCT_AUTO){
- avctx->idct_algo=FF_IDCT_WMV2;
+ if (avctx->idct_algo == FF_IDCT_AUTO) {
+ avctx->idct_algo = FF_IDCT_WMV2;
}
- if(ff_msmpeg4_decode_init(avctx) < 0)
+ if (vc1_init_common(v) < 0)
return -1;
- if (vc1_init_common(v) < 0) return -1;
ff_vc1dsp_init(&v->vc1dsp);
- cur_width = avctx->coded_width = avctx->width;
- cur_height = avctx->coded_height = avctx->height;
- if (avctx->codec_id == CODEC_ID_WMV3)
- {
+ if (avctx->codec_id == CODEC_ID_WMV3 || avctx->codec_id == CODEC_ID_WMV3IMAGE) {
int count = 0;
// looks like WMV3 has a sequence header stored in the extradata
@@ -3435,13 +5299,10 @@ static av_cold int vc1_decode_init(AVCodecContext *avctx)
return -1;
count = avctx->extradata_size*8 - get_bits_count(&gb);
- if (count>0)
- {
+ if (count > 0) {
av_log(avctx, AV_LOG_INFO, "Extra data: %i bits left, value: %X\n",
count, get_bits(&gb, count));
- }
- else if (count < 0)
- {
+ } else if (count < 0) {
av_log(avctx, AV_LOG_INFO, "Read %i bits in overflow\n", -count);
}
} else { // VC1/WVC1/WVP2
@@ -3452,30 +5313,31 @@ static av_cold int vc1_decode_init(AVCodecContext *avctx)
uint8_t *buf2 = NULL;
int seq_initialized = 0, ep_initialized = 0;
- if(avctx->extradata_size < 16) {
+ if (avctx->extradata_size < 16) {
av_log(avctx, AV_LOG_ERROR, "Extradata size too small: %i\n", avctx->extradata_size);
return -1;
}
- buf2 = av_mallocz(avctx->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
+ buf2 = av_mallocz(avctx->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
start = find_next_marker(start, end); // in WVC1 extradata first byte is its size, but can be 0 in mkv
- next = start;
- for(; next < end; start = next){
+ next = start;
+ for (; next < end; start = next) {
next = find_next_marker(start + 4, end);
size = next - start - 4;
- if(size <= 0) continue;
+ if (size <= 0)
+ continue;
buf2_size = vc1_unescape_buffer(start + 4, size, buf2);
init_get_bits(&gb, buf2, buf2_size * 8);
- switch(AV_RB32(start)){
+ switch (AV_RB32(start)) {
case VC1_CODE_SEQHDR:
- if(vc1_decode_sequence_header(avctx, v, &gb) < 0){
+ if (vc1_decode_sequence_header(avctx, v, &gb) < 0) {
av_free(buf2);
return -1;
}
seq_initialized = 1;
break;
case VC1_CODE_ENTRYPOINT:
- if(vc1_decode_entry_point(avctx, v, &gb) < 0){
+ if (vc1_decode_entry_point(avctx, v, &gb) < 0) {
av_free(buf2);
return -1;
}
@@ -3484,42 +5346,30 @@ static av_cold int vc1_decode_init(AVCodecContext *avctx)
}
}
av_free(buf2);
- if(!seq_initialized || !ep_initialized){
+ if (!seq_initialized || !ep_initialized) {
av_log(avctx, AV_LOG_ERROR, "Incomplete extradata\n");
return -1;
}
v->res_sprite = (avctx->codec_tag == MKTAG('W','V','P','2'));
}
- // Sequence header information may not have been parsed
- // yet when ff_msmpeg4_decode_init was called the fist time
- // above. If sequence information changes, we need to call
- // it again.
- if (cur_width != avctx->width ||
- cur_height != avctx->height) {
- MPV_common_end(s);
- if(ff_msmpeg4_decode_init(avctx) < 0)
- return -1;
- avctx->coded_width = avctx->width;
- avctx->coded_height = avctx->height;
- }
avctx->profile = v->profile;
if (v->profile == PROFILE_ADVANCED)
avctx->level = v->level;
- avctx->has_b_frames= !!(avctx->max_b_frames);
- s->low_delay = !avctx->has_b_frames;
+ avctx->has_b_frames = !!(avctx->max_b_frames);
- s->mb_width = (avctx->coded_width+15)>>4;
- s->mb_height = (avctx->coded_height+15)>>4;
+ s->mb_width = (avctx->coded_width + 15) >> 4;
+ s->mb_height = (avctx->coded_height + 15) >> 4;
if (v->profile == PROFILE_ADVANCED || v->res_fasttx) {
- for (i = 0; i < 64; i++) {
-#define transpose(x) ((x>>3) | ((x&7)<<3))
+ for (i = 0; i < 64; i++) {
+#define transpose(x) ((x >> 3) | ((x & 7) << 3))
v->zz_8x8[0][i] = transpose(wmv1_scantable[0][i]);
v->zz_8x8[1][i] = transpose(wmv1_scantable[1][i]);
v->zz_8x8[2][i] = transpose(wmv1_scantable[2][i]);
v->zz_8x8[3][i] = transpose(wmv1_scantable[3][i]);
+ v->zzi_8x8[i] = transpose(ff_vc1_adv_interlaced_8x8_zz[i]);
}
v->left_blk_sh = 0;
v->top_blk_sh = 3;
@@ -3529,39 +5379,55 @@ static av_cold int vc1_decode_init(AVCodecContext *avctx)
v->top_blk_sh = 0;
}
- /* Allocate mb bitplanes */
- v->mv_type_mb_plane = av_malloc(s->mb_stride * s->mb_height);
- v->direct_mb_plane = av_malloc(s->mb_stride * s->mb_height);
- v->acpred_plane = av_malloc(s->mb_stride * s->mb_height);
- v->over_flags_plane = av_malloc(s->mb_stride * s->mb_height);
-
- v->n_allocated_blks = s->mb_width + 2;
- v->block = av_malloc(sizeof(*v->block) * v->n_allocated_blks);
- v->cbp_base = av_malloc(sizeof(v->cbp_base[0]) * 2 * s->mb_stride);
- v->cbp = v->cbp_base + s->mb_stride;
- v->ttblk_base = av_malloc(sizeof(v->ttblk_base[0]) * 2 * s->mb_stride);
- v->ttblk = v->ttblk_base + s->mb_stride;
- v->is_intra_base = av_malloc(sizeof(v->is_intra_base[0]) * 2 * s->mb_stride);
- v->is_intra = v->is_intra_base + s->mb_stride;
- v->luma_mv_base = av_malloc(sizeof(v->luma_mv_base[0]) * 2 * s->mb_stride);
- v->luma_mv = v->luma_mv_base + s->mb_stride;
+ if (avctx->codec_id == CODEC_ID_WMV3IMAGE || avctx->codec_id == CODEC_ID_VC1IMAGE) {
+ v->sprite_width = avctx->coded_width;
+ v->sprite_height = avctx->coded_height;
- /* allocate block type info in that way so it could be used with s->block_index[] */
- v->mb_type_base = av_malloc(s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride * (s->mb_height + 1) * 2);
- v->mb_type[0] = v->mb_type_base + s->b8_stride + 1;
- v->mb_type[1] = v->mb_type_base + s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride + 1;
- v->mb_type[2] = v->mb_type[1] + s->mb_stride * (s->mb_height + 1);
+ avctx->coded_width = avctx->width = v->output_width;
+ avctx->coded_height = avctx->height = v->output_height;
- /* Init coded blocks info */
- if (v->profile == PROFILE_ADVANCED)
- {
-// if (alloc_bitplane(&v->over_flags_plane, s->mb_width, s->mb_height) < 0)
-// return -1;
-// if (alloc_bitplane(&v->ac_pred_plane, s->mb_width, s->mb_height) < 0)
-// return -1;
+ // prevent 16.16 overflows
+ if (v->sprite_width > 1 << 14 ||
+ v->sprite_height > 1 << 14 ||
+ v->output_width > 1 << 14 ||
+ v->output_height > 1 << 14) return -1;
}
+ return 0;
+}
- ff_intrax8_common_init(&v->x8,s);
+/** Close a VC1/WMV3 decoder
+ * @warning Initial try at using MpegEncContext stuff
+ */
+static av_cold int vc1_decode_end(AVCodecContext *avctx)
+{
+ VC1Context *v = avctx->priv_data;
+ int i;
+
+ if ((avctx->codec_id == CODEC_ID_WMV3IMAGE || avctx->codec_id == CODEC_ID_VC1IMAGE)
+ && v->sprite_output_frame.data[0])
+ avctx->release_buffer(avctx, &v->sprite_output_frame);
+ for (i = 0; i < 4; i++)
+ av_freep(&v->sr_rows[i >> 1][i & 1]);
+ av_freep(&v->hrd_rate);
+ av_freep(&v->hrd_buffer);
+ MPV_common_end(&v->s);
+ av_freep(&v->mv_type_mb_plane);
+ av_freep(&v->direct_mb_plane);
+ av_freep(&v->forward_mb_plane);
+ av_freep(&v->fieldtx_plane);
+ av_freep(&v->acpred_plane);
+ av_freep(&v->over_flags_plane);
+ av_freep(&v->mb_type_base);
+ av_freep(&v->blk_mv_type_base);
+ av_freep(&v->mv_f_base);
+ av_freep(&v->mv_f_last_base);
+ av_freep(&v->mv_f_next_base);
+ av_freep(&v->block);
+ av_freep(&v->cbp_base);
+ av_freep(&v->ttblk_base);
+ av_freep(&v->is_intra_base); // FIXME use v->mb_type[]
+ av_freep(&v->luma_mv_base);
+ ff_intrax8_common_end(&v->x8);
return 0;
}
@@ -3569,9 +5435,8 @@ static av_cold int vc1_decode_init(AVCodecContext *avctx)
/** Decode a VC1/WMV3 frame
* @todo TODO: Handle VC-1 IDUs (Transport level?)
*/
-static int vc1_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- AVPacket *avpkt)
+static int vc1_decode_frame(AVCodecContext *avctx, void *data,
+ int *data_size, AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size, n_slices = 0, i;
@@ -3579,7 +5444,9 @@ static int vc1_decode_frame(AVCodecContext *avctx,
MpegEncContext *s = &v->s;
AVFrame *pict = data;
uint8_t *buf2 = NULL;
+ uint8_t *buf_field2 = NULL;
const uint8_t *buf_start = buf;
+ int mb_height, n_slices1=-1;
struct {
uint8_t *buf;
GetBitContext gb;
@@ -3589,9 +5456,9 @@ static int vc1_decode_frame(AVCodecContext *avctx,
/* no supplementary picture */
if (buf_size == 0 || (buf_size == 4 && AV_RB32(buf) == VC1_CODE_ENDOFSEQ)) {
/* special case for last picture */
- if (s->low_delay==0 && s->next_picture_ptr) {
- *pict= *(AVFrame*)s->next_picture_ptr;
- s->next_picture_ptr= NULL;
+ if (s->low_delay == 0 && s->next_picture_ptr) {
+ *pict = *(AVFrame*)s->next_picture_ptr;
+ s->next_picture_ptr = NULL;
*data_size = sizeof(AVFrame);
}
@@ -3599,14 +5466,7 @@ static int vc1_decode_frame(AVCodecContext *avctx,
return 0;
}
- /* We need to set current_picture_ptr before reading the header,
- * otherwise we cannot store anything in there. */
- if(s->current_picture_ptr==NULL || s->current_picture_ptr->data[0]){
- int i= ff_find_unused_picture(s, 0);
- s->current_picture_ptr= &s->picture[i];
- }
-
- if (s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU){
+ if (s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU) {
if (v->profile < PROFILE_ADVANCED)
avctx->pix_fmt = PIX_FMT_VDPAU_WMV3;
else
@@ -3614,37 +5474,61 @@ static int vc1_decode_frame(AVCodecContext *avctx,
}
//for advanced profile we may need to parse and unescape data
- if (avctx->codec_id == CODEC_ID_VC1) {
+ if (avctx->codec_id == CODEC_ID_VC1 || avctx->codec_id == CODEC_ID_VC1IMAGE) {
int buf_size2 = 0;
buf2 = av_mallocz(buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
- if(IS_MARKER(AV_RB32(buf))){ /* frame starts with marker and needs to be parsed */
+ if (IS_MARKER(AV_RB32(buf))) { /* frame starts with marker and needs to be parsed */
const uint8_t *start, *end, *next;
int size;
next = buf;
- for(start = buf, end = buf + buf_size; next < end; start = next){
+ for (start = buf, end = buf + buf_size; next < end; start = next) {
next = find_next_marker(start + 4, end);
size = next - start - 4;
- if(size <= 0) continue;
- switch(AV_RB32(start)){
+ if (size <= 0) continue;
+ switch (AV_RB32(start)) {
case VC1_CODE_FRAME:
if (avctx->hwaccel ||
s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU)
buf_start = start;
buf_size2 = vc1_unescape_buffer(start + 4, size, buf2);
break;
+ case VC1_CODE_FIELD: {
+ int buf_size3;
+ slices = av_realloc(slices, sizeof(*slices) * (n_slices+1));
+ if (!slices)
+ goto err;
+ slices[n_slices].buf = av_mallocz(buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
+ if (!slices[n_slices].buf)
+ goto err;
+ buf_size3 = vc1_unescape_buffer(start + 4, size,
+ slices[n_slices].buf);
+ init_get_bits(&slices[n_slices].gb, slices[n_slices].buf,
+ buf_size3 << 3);
+ /* assuming that the field marker is at the exact middle,
+ hope it's correct */
+ slices[n_slices].mby_start = s->mb_height >> 1;
+ n_slices1 = n_slices - 1; // index of the last slice of the first field
+ n_slices++;
+ // not necessary, ad hoc until I find a way to handle WVC1i
+ buf_field2 = av_mallocz(buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
+ vc1_unescape_buffer(start + 4, size, buf_field2);
+ break;
+ }
case VC1_CODE_ENTRYPOINT: /* it should be before frame data */
buf_size2 = vc1_unescape_buffer(start + 4, size, buf2);
- init_get_bits(&s->gb, buf2, buf_size2*8);
+ init_get_bits(&s->gb, buf2, buf_size2 * 8);
vc1_decode_entry_point(avctx, v, &s->gb);
break;
case VC1_CODE_SLICE: {
int buf_size3;
slices = av_realloc(slices, sizeof(*slices) * (n_slices+1));
- if (!slices) goto err;
+ if (!slices)
+ goto err;
slices[n_slices].buf = av_mallocz(buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
- if (!slices[n_slices].buf) goto err;
+ if (!slices[n_slices].buf)
+ goto err;
buf_size3 = vc1_unescape_buffer(start + 4, size,
slices[n_slices].buf);
init_get_bits(&slices[n_slices].gb, slices[n_slices].buf,
@@ -3655,21 +5539,19 @@ static int vc1_decode_frame(AVCodecContext *avctx,
}
}
}
- }else if(v->interlace && ((buf[0] & 0xC0) == 0xC0)){ /* WVC1 interlaced stores both fields divided by marker */
+ } else if (v->interlace && ((buf[0] & 0xC0) == 0xC0)) { /* WVC1 interlaced stores both fields divided by marker */
const uint8_t *divider;
divider = find_next_marker(buf, buf + buf_size);
- if((divider == (buf + buf_size)) || AV_RB32(divider) != VC1_CODE_FIELD){
+ if ((divider == (buf + buf_size)) || AV_RB32(divider) != VC1_CODE_FIELD) {
av_log(avctx, AV_LOG_ERROR, "Error in WVC1 interlaced frame\n");
goto err;
+ } else { // found field marker, unescape second field
+ buf_field2 = av_mallocz(buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
+ vc1_unescape_buffer(divider + 4, buf + buf_size - divider - 4, buf_field2);
}
-
buf_size2 = vc1_unescape_buffer(buf, divider - buf, buf2);
- // TODO
- if(!v->warn_interlaced++)
- av_log(v->s.avctx, AV_LOG_ERROR, "Interlaced WVC1 support is not implemented\n");
- goto err;
- }else{
+ } else {
buf_size2 = vc1_unescape_buffer(buf, buf_size, buf2);
}
init_get_bits(&s->gb, buf2, buf_size2*8);
@@ -3677,54 +5559,105 @@ static int vc1_decode_frame(AVCodecContext *avctx,
init_get_bits(&s->gb, buf, buf_size*8);
if (v->res_sprite) {
- v->new_sprite = !get_bits1(&s->gb);
- v->two_sprites = get_bits1(&s->gb);
- if (!v->new_sprite)
- goto end;
+ v->new_sprite = !get_bits1(&s->gb);
+ v->two_sprites = get_bits1(&s->gb);
+ /* res_sprite means a Windows Media Image stream, CODEC_ID_*IMAGE means
+ we're using the sprite compositor. These are intentionally kept separate
+ so you can get the raw sprites by using the wmv3 decoder for WMVP or
+ the vc1 one for WVP2 */
+ if (avctx->codec_id == CODEC_ID_WMV3IMAGE || avctx->codec_id == CODEC_ID_VC1IMAGE) {
+ if (v->new_sprite) {
+ // switch AVCodecContext parameters to those of the sprites
+ avctx->width = avctx->coded_width = v->sprite_width;
+ avctx->height = avctx->coded_height = v->sprite_height;
+ } else {
+ goto image;
+ }
+ }
+ }
+
+ if (s->context_initialized &&
+ (s->width != avctx->coded_width ||
+ s->height != avctx->coded_height)) {
+ vc1_decode_end(avctx);
+ }
+
+ if (!s->context_initialized) {
+ if (ff_msmpeg4_decode_init(avctx) < 0 || vc1_decode_init_alloc_tables(v) < 0)
+ return -1;
+
+ s->low_delay = !avctx->has_b_frames || v->res_sprite;
+
+ if (v->profile == PROFILE_ADVANCED) {
+ s->h_edge_pos = avctx->coded_width;
+ s->v_edge_pos = avctx->coded_height;
+ }
+ }
+
+ /* We need to set current_picture_ptr before reading the header,
+ * otherwise we cannot store anything in there. */
+ if (s->current_picture_ptr == NULL || s->current_picture_ptr->f.data[0]) {
+ int i = ff_find_unused_picture(s, 0);
+ s->current_picture_ptr = &s->picture[i];
}
// do parse frame header
- if(v->profile < PROFILE_ADVANCED) {
- if(vc1_parse_frame_header(v, &s->gb) == -1) {
+ v->pic_header_flag = 0;
+ if (v->profile < PROFILE_ADVANCED) {
+ if (vc1_parse_frame_header(v, &s->gb) == -1) {
goto err;
}
} else {
- if(vc1_parse_frame_header_adv(v, &s->gb) == -1) {
+ if (vc1_parse_frame_header_adv(v, &s->gb) == -1) {
goto err;
}
}
- if (v->res_sprite && s->pict_type!=AV_PICTURE_TYPE_I) {
- av_log(v->s.avctx, AV_LOG_WARNING, "Sprite decoder: expected I-frame\n");
+ if ((avctx->codec_id == CODEC_ID_WMV3IMAGE || avctx->codec_id == CODEC_ID_VC1IMAGE)
+ && s->pict_type != AV_PICTURE_TYPE_I) {
+ av_log(v->s.avctx, AV_LOG_ERROR, "Sprite decoder: expected I-frame\n");
+ goto err;
+ }
+
+ // process pulldown flags
+ s->current_picture_ptr->f.repeat_pict = 0;
+ // Pulldown flags are only valid when 'broadcast' has been set.
+ // So ticks_per_frame will be 2
+ if (v->rff) {
+ // repeat field
+ s->current_picture_ptr->f.repeat_pict = 1;
+ } else if (v->rptfrm) {
+ // repeat frames
+ s->current_picture_ptr->f.repeat_pict = v->rptfrm * 2;
}
// for skipping the frame
- s->current_picture.pict_type= s->pict_type;
- s->current_picture.key_frame= s->pict_type == AV_PICTURE_TYPE_I;
+ s->current_picture.f.pict_type = s->pict_type;
+ s->current_picture.f.key_frame = s->pict_type == AV_PICTURE_TYPE_I;
/* skip B-frames if we don't have reference frames */
- if(s->last_picture_ptr==NULL && (s->pict_type==AV_PICTURE_TYPE_B || s->dropable)){
+ if (s->last_picture_ptr == NULL && (s->pict_type == AV_PICTURE_TYPE_B || s->dropable)) {
goto err;
}
- if( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type==AV_PICTURE_TYPE_B)
- || (avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=AV_PICTURE_TYPE_I)
- || avctx->skip_frame >= AVDISCARD_ALL) {
+ if ((avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type == AV_PICTURE_TYPE_B) ||
+ (avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type != AV_PICTURE_TYPE_I) ||
+ avctx->skip_frame >= AVDISCARD_ALL) {
goto end;
}
- if(s->next_p_frame_damaged){
- if(s->pict_type==AV_PICTURE_TYPE_B)
+ if (s->next_p_frame_damaged) {
+ if (s->pict_type == AV_PICTURE_TYPE_B)
goto end;
else
- s->next_p_frame_damaged=0;
+ s->next_p_frame_damaged = 0;
}
- if(MPV_frame_start(s, avctx) < 0) {
+ if (MPV_frame_start(s, avctx) < 0) {
goto err;
}
- s->me.qpel_put= s->dsp.put_qpel_pixels_tab;
- s->me.qpel_avg= s->dsp.avg_qpel_pixels_tab;
+ s->me.qpel_put = s->dsp.put_qpel_pixels_tab;
+ s->me.qpel_avg = s->dsp.avg_qpel_pixels_tab;
if ((CONFIG_VC1_VDPAU_DECODER)
&&s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU)
@@ -3740,38 +5673,99 @@ static int vc1_decode_frame(AVCodecContext *avctx,
ff_er_frame_start(s);
v->bits = buf_size * 8;
+ if (v->field_mode) {
+ uint8_t *tmp[2];
+ s->current_picture.f.linesize[0] <<= 1;
+ s->current_picture.f.linesize[1] <<= 1;
+ s->current_picture.f.linesize[2] <<= 1;
+ s->linesize <<= 1;
+ s->uvlinesize <<= 1;
+ tmp[0] = v->mv_f_last[0];
+ tmp[1] = v->mv_f_last[1];
+ v->mv_f_last[0] = v->mv_f_next[0];
+ v->mv_f_last[1] = v->mv_f_next[1];
+ v->mv_f_next[0] = v->mv_f[0];
+ v->mv_f_next[1] = v->mv_f[1];
+ v->mv_f[0] = tmp[0];
+ v->mv_f[1] = tmp[1];
+ }
+ mb_height = s->mb_height >> v->field_mode;
for (i = 0; i <= n_slices; i++) {
- if (i && get_bits1(&s->gb))
- vc1_parse_frame_header_adv(v, &s->gb);
- s->start_mb_y = (i == 0) ? 0 : FFMAX(0, slices[i-1].mby_start);
- s->end_mb_y = (i == n_slices) ? s->mb_height : FFMIN(s->mb_height, slices[i].mby_start);
+ if (i > 0 && slices[i - 1].mby_start >= mb_height) {
+ v->second_field = 1;
+ v->blocks_off = s->mb_width * s->mb_height << 1;
+ v->mb_off = s->mb_stride * s->mb_height >> 1;
+ } else {
+ v->second_field = 0;
+ v->blocks_off = 0;
+ v->mb_off = 0;
+ }
+ if (i) {
+ v->pic_header_flag = 0;
+ if (v->field_mode && i == n_slices1 + 2)
+ vc1_parse_frame_header_adv(v, &s->gb);
+ else if (get_bits1(&s->gb)) {
+ v->pic_header_flag = 1;
+ vc1_parse_frame_header_adv(v, &s->gb);
+ }
+ }
+ s->start_mb_y = (i == 0) ? 0 : FFMAX(0, slices[i-1].mby_start % mb_height);
+ if (!v->field_mode || v->second_field)
+ s->end_mb_y = (i == n_slices ) ? mb_height : FFMIN(mb_height, slices[i].mby_start % mb_height);
+ else
+ s->end_mb_y = (i == n_slices1 + 1) ? mb_height : FFMIN(mb_height, slices[i].mby_start % mb_height);
vc1_decode_blocks(v);
- if (i != n_slices) s->gb = slices[i].gb;
+ if (i != n_slices)
+ s->gb = slices[i].gb;
+ }
+ if (v->field_mode) {
+ av_free(buf_field2);
+ v->second_field = 0;
+ }
+ if (v->field_mode) {
+ if (s->pict_type == AV_PICTURE_TYPE_B) {
+ memcpy(v->mv_f_base, v->mv_f_next_base,
+ 2 * (s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride * (s->mb_height + 1) * 2));
+ }
+ s->current_picture.f.linesize[0] >>= 1;
+ s->current_picture.f.linesize[1] >>= 1;
+ s->current_picture.f.linesize[2] >>= 1;
+ s->linesize >>= 1;
+ s->uvlinesize >>= 1;
}
//av_log(s->avctx, AV_LOG_INFO, "Consumed %i/%i bits\n", get_bits_count(&s->gb), s->gb.size_in_bits);
-// if(get_bits_count(&s->gb) > buf_size * 8)
+// if (get_bits_count(&s->gb) > buf_size * 8)
// return -1;
ff_er_frame_end(s);
}
MPV_frame_end(s);
-assert(s->current_picture.pict_type == s->current_picture_ptr->pict_type);
-assert(s->current_picture.pict_type == s->pict_type);
- if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {
- *pict= *(AVFrame*)s->current_picture_ptr;
- } else if (s->last_picture_ptr != NULL) {
- *pict= *(AVFrame*)s->last_picture_ptr;
- }
-
- if(s->last_picture_ptr || s->low_delay){
+ if (avctx->codec_id == CODEC_ID_WMV3IMAGE || avctx->codec_id == CODEC_ID_VC1IMAGE) {
+image:
+ avctx->width = avctx->coded_width = v->output_width;
+ avctx->height = avctx->coded_height = v->output_height;
+ if (avctx->skip_frame >= AVDISCARD_NONREF)
+ goto end;
+#if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER
+ if (vc1_decode_sprites(v, &s->gb))
+ goto err;
+#endif
+ *pict = v->sprite_output_frame;
*data_size = sizeof(AVFrame);
- ff_print_debug_info(s, pict);
+ } else {
+ if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {
+ *pict = *(AVFrame*)s->current_picture_ptr;
+ } else if (s->last_picture_ptr != NULL) {
+ *pict = *(AVFrame*)s->last_picture_ptr;
+ }
+ if (s->last_picture_ptr || s->low_delay) {
+ *data_size = sizeof(AVFrame);
+ ff_print_debug_info(s, pict);
+ }
}
end:
- if (v->res_sprite)
- vc1_parse_sprites(v, &s->gb);
av_free(buf2);
for (i = 0; i < n_slices; i++)
av_free(slices[i].buf);
@@ -3783,34 +5777,11 @@ err:
for (i = 0; i < n_slices; i++)
av_free(slices[i].buf);
av_free(slices);
+ av_free(buf_field2);
return -1;
}
-/** Close a VC1/WMV3 decoder
- * @warning Initial try at using MpegEncContext stuff
- */
-static av_cold int vc1_decode_end(AVCodecContext *avctx)
-{
- VC1Context *v = avctx->priv_data;
-
- av_freep(&v->hrd_rate);
- av_freep(&v->hrd_buffer);
- MPV_common_end(&v->s);
- av_freep(&v->mv_type_mb_plane);
- av_freep(&v->direct_mb_plane);
- av_freep(&v->acpred_plane);
- av_freep(&v->over_flags_plane);
- av_freep(&v->mb_type_base);
- av_freep(&v->block);
- av_freep(&v->cbp_base);
- av_freep(&v->ttblk_base);
- av_freep(&v->is_intra_base); // FIXME use v->mb_type[]
- av_freep(&v->luma_mv_base);
- ff_intrax8_common_end(&v->x8);
- return 0;
-}
-
static const AVProfile profiles[] = {
{ FF_PROFILE_VC1_SIMPLE, "Simple" },
{ FF_PROFILE_VC1_MAIN, "Main" },
@@ -3820,71 +5791,95 @@ static const AVProfile profiles[] = {
};
AVCodec ff_vc1_decoder = {
- "vc1",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_VC1,
- sizeof(VC1Context),
- vc1_decode_init,
- NULL,
- vc1_decode_end,
- vc1_decode_frame,
- CODEC_CAP_DR1 | CODEC_CAP_DELAY,
- NULL,
- .long_name = NULL_IF_CONFIG_SMALL("SMPTE VC-1"),
- .pix_fmts = ff_hwaccel_pixfmt_list_420,
- .profiles = NULL_IF_CONFIG_SMALL(profiles)
+ .name = "vc1",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_VC1,
+ .priv_data_size = sizeof(VC1Context),
+ .init = vc1_decode_init,
+ .close = vc1_decode_end,
+ .decode = vc1_decode_frame,
+ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY,
+ .long_name = NULL_IF_CONFIG_SMALL("SMPTE VC-1"),
+ .pix_fmts = ff_hwaccel_pixfmt_list_420,
+ .profiles = NULL_IF_CONFIG_SMALL(profiles)
};
#if CONFIG_WMV3_DECODER
AVCodec ff_wmv3_decoder = {
- "wmv3",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_WMV3,
- sizeof(VC1Context),
- vc1_decode_init,
- NULL,
- vc1_decode_end,
- vc1_decode_frame,
- CODEC_CAP_DR1 | CODEC_CAP_DELAY,
- NULL,
- .long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 9"),
- .pix_fmts = ff_hwaccel_pixfmt_list_420,
- .profiles = NULL_IF_CONFIG_SMALL(profiles)
+ .name = "wmv3",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_WMV3,
+ .priv_data_size = sizeof(VC1Context),
+ .init = vc1_decode_init,
+ .close = vc1_decode_end,
+ .decode = vc1_decode_frame,
+ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY,
+ .long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 9"),
+ .pix_fmts = ff_hwaccel_pixfmt_list_420,
+ .profiles = NULL_IF_CONFIG_SMALL(profiles)
};
#endif
#if CONFIG_WMV3_VDPAU_DECODER
AVCodec ff_wmv3_vdpau_decoder = {
- "wmv3_vdpau",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_WMV3,
- sizeof(VC1Context),
- vc1_decode_init,
- NULL,
- vc1_decode_end,
- vc1_decode_frame,
- CODEC_CAP_DR1 | CODEC_CAP_DELAY | CODEC_CAP_HWACCEL_VDPAU,
- NULL,
- .long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 9 VDPAU"),
- .pix_fmts = (const enum PixelFormat[]){PIX_FMT_VDPAU_WMV3, PIX_FMT_NONE},
- .profiles = NULL_IF_CONFIG_SMALL(profiles)
+ .name = "wmv3_vdpau",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_WMV3,
+ .priv_data_size = sizeof(VC1Context),
+ .init = vc1_decode_init,
+ .close = vc1_decode_end,
+ .decode = vc1_decode_frame,
+ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY | CODEC_CAP_HWACCEL_VDPAU,
+ .long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 9 VDPAU"),
+ .pix_fmts = (const enum PixelFormat[]){PIX_FMT_VDPAU_WMV3, PIX_FMT_NONE},
+ .profiles = NULL_IF_CONFIG_SMALL(profiles)
};
#endif
#if CONFIG_VC1_VDPAU_DECODER
AVCodec ff_vc1_vdpau_decoder = {
- "vc1_vdpau",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_VC1,
- sizeof(VC1Context),
- vc1_decode_init,
- NULL,
- vc1_decode_end,
- vc1_decode_frame,
- CODEC_CAP_DR1 | CODEC_CAP_DELAY | CODEC_CAP_HWACCEL_VDPAU,
- NULL,
- .long_name = NULL_IF_CONFIG_SMALL("SMPTE VC-1 VDPAU"),
- .pix_fmts = (const enum PixelFormat[]){PIX_FMT_VDPAU_VC1, PIX_FMT_NONE},
- .profiles = NULL_IF_CONFIG_SMALL(profiles)
+ .name = "vc1_vdpau",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_VC1,
+ .priv_data_size = sizeof(VC1Context),
+ .init = vc1_decode_init,
+ .close = vc1_decode_end,
+ .decode = vc1_decode_frame,
+ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY | CODEC_CAP_HWACCEL_VDPAU,
+ .long_name = NULL_IF_CONFIG_SMALL("SMPTE VC-1 VDPAU"),
+ .pix_fmts = (const enum PixelFormat[]){PIX_FMT_VDPAU_VC1, PIX_FMT_NONE},
+ .profiles = NULL_IF_CONFIG_SMALL(profiles)
+};
+#endif
+
+#if CONFIG_WMV3IMAGE_DECODER
+AVCodec ff_wmv3image_decoder = {
+ .name = "wmv3image",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_WMV3IMAGE,
+ .priv_data_size = sizeof(VC1Context),
+ .init = vc1_decode_init,
+ .close = vc1_decode_end,
+ .decode = vc1_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
+ .flush = vc1_sprite_flush,
+ .long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 9 Image"),
+ .pix_fmts = ff_pixfmt_list_420
+};
+#endif
+
+#if CONFIG_VC1IMAGE_DECODER
+AVCodec ff_vc1image_decoder = {
+ .name = "vc1image",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_VC1IMAGE,
+ .priv_data_size = sizeof(VC1Context),
+ .init = vc1_decode_init,
+ .close = vc1_decode_end,
+ .decode = vc1_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
+ .flush = vc1_sprite_flush,
+ .long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 9 Image v2"),
+ .pix_fmts = ff_pixfmt_list_420
};
#endif
diff --git a/libavcodec/vc1dsp.c b/libavcodec/vc1dsp.c
index 7d0e406677..a9a7dff761 100644
--- a/libavcodec/vc1dsp.c
+++ b/libavcodec/vc1dsp.c
@@ -2,20 +2,20 @@
* VC-1 and WMV3 decoder - DSP functions
* Copyright (c) 2006 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -688,6 +688,26 @@ static void put_no_rnd_vc1_chroma_mc8_c(uint8_t *dst/*align 8*/, uint8_t *src/*a
}
}
+static void put_no_rnd_vc1_chroma_mc4_c(uint8_t *dst, uint8_t *src, int stride, int h, int x, int y){
+ const int A=(8-x)*(8-y);
+ const int B=( x)*(8-y);
+ const int C=(8-x)*( y);
+ const int D=( x)*( y);
+ int i;
+
+ assert(x<8 && y<8 && x>=0 && y>=0);
+
+ for(i=0; i<h; i++)
+ {
+ dst[0] = (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1] + 32 - 4) >> 6;
+ dst[1] = (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + 32 - 4) >> 6;
+ dst[2] = (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + 32 - 4) >> 6;
+ dst[3] = (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + 32 - 4) >> 6;
+ dst+= stride;
+ src+= stride;
+ }
+}
+
#define avg2(a,b) ((a+b+1)>>1)
static void avg_no_rnd_vc1_chroma_mc8_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){
const int A=(8-x)*(8-y);
@@ -713,6 +733,66 @@ static void avg_no_rnd_vc1_chroma_mc8_c(uint8_t *dst/*align 8*/, uint8_t *src/*a
}
}
+#if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER
+
+static void sprite_h_c(uint8_t *dst, const uint8_t *src, int offset, int advance, int count)
+{
+ while (count--) {
+ int a = src[(offset >> 16) ];
+ int b = src[(offset >> 16) + 1];
+ *dst++ = a + ((b - a) * (offset&0xFFFF) >> 16);
+ offset += advance;
+ }
+}
+
+static av_always_inline void sprite_v_template(uint8_t *dst, const uint8_t *src1a, const uint8_t *src1b, int offset1,
+ int two_sprites, const uint8_t *src2a, const uint8_t *src2b, int offset2,
+ int alpha, int scaled, int width)
+{
+ int a1, b1, a2, b2;
+ while (width--) {
+ a1 = *src1a++;
+ if (scaled) {
+ b1 = *src1b++;
+ a1 = a1 + ((b1 - a1) * offset1 >> 16);
+ }
+ if (two_sprites) {
+ a2 = *src2a++;
+ if (scaled > 1) {
+ b2 = *src2b++;
+ a2 = a2 + ((b2 - a2) * offset2 >> 16);
+ }
+ a1 = a1 + ((a2 - a1) * alpha >> 16);
+ }
+ *dst++ = a1;
+ }
+}
+
+static void sprite_v_single_c(uint8_t *dst, const uint8_t *src1a, const uint8_t *src1b, int offset, int width)
+{
+ sprite_v_template(dst, src1a, src1b, offset, 0, NULL, NULL, 0, 0, 1, width);
+}
+
+static void sprite_v_double_noscale_c(uint8_t *dst, const uint8_t *src1a, const uint8_t *src2a, int alpha, int width)
+{
+ sprite_v_template(dst, src1a, NULL, 0, 1, src2a, NULL, 0, alpha, 0, width);
+}
+
+static void sprite_v_double_onescale_c(uint8_t *dst, const uint8_t *src1a, const uint8_t *src1b, int offset1,
+ const uint8_t *src2a, int alpha, int width)
+{
+ sprite_v_template(dst, src1a, src1b, offset1, 1, src2a, NULL, 0, alpha, 1, width);
+}
+
+static void sprite_v_double_twoscale_c(uint8_t *dst, const uint8_t *src1a, const uint8_t *src1b, int offset1,
+ const uint8_t *src2a, const uint8_t *src2b, int offset2,
+ int alpha, int width)
+{
+ sprite_v_template(dst, src1a, src1b, offset1, 1, src2a, src2b, offset2, alpha, 2, width);
+}
+
+#endif
+
av_cold void ff_vc1dsp_init(VC1DSPContext* dsp) {
dsp->vc1_inv_trans_8x8 = vc1_inv_trans_8x8_c;
dsp->vc1_inv_trans_4x8 = vc1_inv_trans_4x8_c;
@@ -769,6 +849,15 @@ av_cold void ff_vc1dsp_init(VC1DSPContext* dsp) {
dsp->put_no_rnd_vc1_chroma_pixels_tab[0]= put_no_rnd_vc1_chroma_mc8_c;
dsp->avg_no_rnd_vc1_chroma_pixels_tab[0]= avg_no_rnd_vc1_chroma_mc8_c;
+ dsp->put_no_rnd_vc1_chroma_pixels_tab[1] = put_no_rnd_vc1_chroma_mc4_c;
+
+#if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER
+ dsp->sprite_h = sprite_h_c;
+ dsp->sprite_v_single = sprite_v_single_c;
+ dsp->sprite_v_double_noscale = sprite_v_double_noscale_c;
+ dsp->sprite_v_double_onescale = sprite_v_double_onescale_c;
+ dsp->sprite_v_double_twoscale = sprite_v_double_twoscale_c;
+#endif
if (HAVE_ALTIVEC)
ff_vc1dsp_init_altivec(dsp);
diff --git a/libavcodec/vc1dsp.h b/libavcodec/vc1dsp.h
index e1b6ba0aa8..d96853aa16 100644
--- a/libavcodec/vc1dsp.h
+++ b/libavcodec/vc1dsp.h
@@ -2,20 +2,20 @@
* VC-1 and WMV3 decoder - DSP functions
* Copyright (c) 2006 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -60,6 +60,16 @@ typedef struct VC1DSPContext {
/* This is really one func used in VC-1 decoding */
h264_chroma_mc_func put_no_rnd_vc1_chroma_pixels_tab[3];
h264_chroma_mc_func avg_no_rnd_vc1_chroma_pixels_tab[3];
+
+ /* Windows Media Image functions */
+ void (*sprite_h)(uint8_t *dst, const uint8_t *src, int offset, int advance, int count);
+ void (*sprite_v_single)(uint8_t *dst, const uint8_t *src1a, const uint8_t *src1b, int offset, int width);
+ void (*sprite_v_double_noscale)(uint8_t *dst, const uint8_t *src1a, const uint8_t *src2a, int alpha, int width);
+ void (*sprite_v_double_onescale)(uint8_t *dst, const uint8_t *src1a, const uint8_t *src1b, int offset1,
+ const uint8_t *src2a, int alpha, int width);
+ void (*sprite_v_double_twoscale)(uint8_t *dst, const uint8_t *src1a, const uint8_t *src1b, int offset1,
+ const uint8_t *src2a, const uint8_t *src2b, int offset2,
+ int alpha, int width);
} VC1DSPContext;
void ff_vc1dsp_init(VC1DSPContext* c);
diff --git a/libavcodec/vcr1.c b/libavcodec/vcr1.c
index aaf8eaebef..0c06813cf1 100644
--- a/libavcodec/vcr1.c
+++ b/libavcodec/vcr1.c
@@ -2,20 +2,20 @@
* ATI VCR1 codec
* Copyright (c) 2003 Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -132,7 +132,7 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size,
emms_c();
- align_put_bits(&a->pb);
+ avpriv_align_put_bits(&a->pb);
while(get_bit_count(&a->pb)&31)
put_bits(&a->pb, 8, 0);
@@ -146,6 +146,7 @@ static av_cold void common_init(AVCodecContext *avctx){
VCR1Context * const a = avctx->priv_data;
avctx->coded_frame= (AVFrame*)&a->picture;
+ avcodec_get_frame_defaults(&a->picture);
a->avctx= avctx;
}
@@ -177,27 +178,25 @@ static av_cold int encode_init(AVCodecContext *avctx){
#endif
AVCodec ff_vcr1_decoder = {
- "vcr1",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_VCR1,
- sizeof(VCR1Context),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- CODEC_CAP_DR1,
+ .name = "vcr1",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_VCR1,
+ .priv_data_size = sizeof(VCR1Context),
+ .init = decode_init,
+ .close = decode_end,
+ .decode = decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("ATI VCR1"),
};
#if CONFIG_VCR1_ENCODER
AVCodec ff_vcr1_encoder = {
- "vcr1",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_VCR1,
- sizeof(VCR1Context),
- encode_init,
- encode_frame,
- //encode_end,
+ .name = "vcr1",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_VCR1,
+ .priv_data_size = sizeof(VCR1Context),
+ .init = encode_init,
+ .encode = encode_frame,
.long_name = NULL_IF_CONFIG_SMALL("ATI VCR1"),
};
#endif
diff --git a/libavcodec/vdpau.c b/libavcodec/vdpau.c
index bdc596ce24..ce5103a6af 100644
--- a/libavcodec/vdpau.c
+++ b/libavcodec/vdpau.c
@@ -4,20 +4,20 @@
*
* Copyright (c) 2008 NVIDIA
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -46,7 +46,7 @@ void ff_vdpau_h264_set_reference_frames(MpegEncContext *s)
Picture *pic;
int i, list, pic_frame_idx;
- render = (struct vdpau_render_state *)s->current_picture_ptr->data[0];
+ render = (struct vdpau_render_state *)s->current_picture_ptr->f.data[0];
assert(render);
rf = &render->info.h264.referenceFrames[0];
@@ -58,11 +58,11 @@ void ff_vdpau_h264_set_reference_frames(MpegEncContext *s)
for (i = 0; i < ls; ++i) {
pic = lp[i];
- if (!pic || !pic->reference)
+ if (!pic || !pic->f.reference)
continue;
pic_frame_idx = pic->long_ref ? pic->pic_id : pic->frame_num;
- render_ref = (struct vdpau_render_state *)pic->data[0];
+ render_ref = (struct vdpau_render_state *)pic->f.data[0];
assert(render_ref);
rf2 = &render->info.h264.referenceFrames[0];
@@ -76,8 +76,8 @@ void ff_vdpau_h264_set_reference_frames(MpegEncContext *s)
++rf2;
}
if (rf2 != rf) {
- rf2->top_is_reference |= (pic->reference & PICT_TOP_FIELD) ? VDP_TRUE : VDP_FALSE;
- rf2->bottom_is_reference |= (pic->reference & PICT_BOTTOM_FIELD) ? VDP_TRUE : VDP_FALSE;
+ rf2->top_is_reference |= (pic->f.reference & PICT_TOP_FIELD) ? VDP_TRUE : VDP_FALSE;
+ rf2->bottom_is_reference |= (pic->f.reference & PICT_BOTTOM_FIELD) ? VDP_TRUE : VDP_FALSE;
continue;
}
@@ -86,8 +86,8 @@ void ff_vdpau_h264_set_reference_frames(MpegEncContext *s)
rf->surface = render_ref->surface;
rf->is_long_term = pic->long_ref;
- rf->top_is_reference = (pic->reference & PICT_TOP_FIELD) ? VDP_TRUE : VDP_FALSE;
- rf->bottom_is_reference = (pic->reference & PICT_BOTTOM_FIELD) ? VDP_TRUE : VDP_FALSE;
+ rf->top_is_reference = (pic->f.reference & PICT_TOP_FIELD) ? VDP_TRUE : VDP_FALSE;
+ rf->bottom_is_reference = (pic->f.reference & PICT_BOTTOM_FIELD) ? VDP_TRUE : VDP_FALSE;
rf->field_order_cnt[0] = pic->field_poc[0];
rf->field_order_cnt[1] = pic->field_poc[1];
rf->frame_idx = pic_frame_idx;
@@ -112,7 +112,7 @@ void ff_vdpau_add_data_chunk(MpegEncContext *s,
{
struct vdpau_render_state *render;
- render = (struct vdpau_render_state *)s->current_picture_ptr->data[0];
+ render = (struct vdpau_render_state *)s->current_picture_ptr->f.data[0];
assert(render);
render->bitstream_buffers= av_fast_realloc(
@@ -133,7 +133,7 @@ void ff_vdpau_h264_picture_start(MpegEncContext *s)
struct vdpau_render_state *render;
int i;
- render = (struct vdpau_render_state *)s->current_picture_ptr->data[0];
+ render = (struct vdpau_render_state *)s->current_picture_ptr->f.data[0];
assert(render);
for (i = 0; i < 2; ++i) {
@@ -151,14 +151,14 @@ void ff_vdpau_h264_picture_complete(MpegEncContext *s)
H264Context *h = s->avctx->priv_data;
struct vdpau_render_state *render;
- render = (struct vdpau_render_state *)s->current_picture_ptr->data[0];
+ render = (struct vdpau_render_state *)s->current_picture_ptr->f.data[0];
assert(render);
render->info.h264.slice_count = h->slice_num;
if (render->info.h264.slice_count < 1)
return;
- render->info.h264.is_reference = (s->current_picture_ptr->reference & 3) ? VDP_TRUE : VDP_FALSE;
+ render->info.h264.is_reference = (s->current_picture_ptr->f.reference & 3) ? VDP_TRUE : VDP_FALSE;
render->info.h264.field_pic_flag = s->picture_structure != PICT_FRAME;
render->info.h264.bottom_field_flag = s->picture_structure == PICT_BOTTOM_FIELD;
render->info.h264.num_ref_frames = h->sps.ref_frame_count;
@@ -198,7 +198,7 @@ void ff_vdpau_mpeg_picture_complete(MpegEncContext *s, const uint8_t *buf,
if (!s->current_picture_ptr) return;
- render = (struct vdpau_render_state *)s->current_picture_ptr->data[0];
+ render = (struct vdpau_render_state *)s->current_picture_ptr->f.data[0];
assert(render);
/* fill VdpPictureInfoMPEG1Or2 struct */
@@ -227,12 +227,12 @@ void ff_vdpau_mpeg_picture_complete(MpegEncContext *s, const uint8_t *buf,
switch(s->pict_type){
case AV_PICTURE_TYPE_B:
- next = (struct vdpau_render_state *)s->next_picture.data[0];
+ next = (struct vdpau_render_state *)s->next_picture.f.data[0];
assert(next);
render->info.mpeg.backward_reference = next->surface;
// no return here, going to set forward prediction
case AV_PICTURE_TYPE_P:
- last = (struct vdpau_render_state *)s->last_picture.data[0];
+ last = (struct vdpau_render_state *)s->last_picture.f.data[0];
if (!last) // FIXME: Does this test make sense?
last = render; // predict second field from the first
render->info.mpeg.forward_reference = last->surface;
@@ -253,7 +253,7 @@ void ff_vdpau_vc1_decode_picture(MpegEncContext *s, const uint8_t *buf,
VC1Context *v = s->avctx->priv_data;
struct vdpau_render_state *render, *last, *next;
- render = (struct vdpau_render_state *)s->current_picture.data[0];
+ render = (struct vdpau_render_state *)s->current_picture.f.data[0];
assert(render);
/* fill LvPictureInfoVC1 struct */
@@ -297,12 +297,12 @@ void ff_vdpau_vc1_decode_picture(MpegEncContext *s, const uint8_t *buf,
switch(s->pict_type){
case AV_PICTURE_TYPE_B:
- next = (struct vdpau_render_state *)s->next_picture.data[0];
+ next = (struct vdpau_render_state *)s->next_picture.f.data[0];
assert(next);
render->info.vc1.backward_reference = next->surface;
// no break here, going to set forward prediction
case AV_PICTURE_TYPE_P:
- last = (struct vdpau_render_state *)s->last_picture.data[0];
+ last = (struct vdpau_render_state *)s->last_picture.f.data[0];
if (!last) // FIXME: Does this test make sense?
last = render; // predict second field from the first
render->info.vc1.forward_reference = last->surface;
@@ -324,7 +324,7 @@ void ff_vdpau_mpeg4_decode_picture(MpegEncContext *s, const uint8_t *buf,
if (!s->current_picture_ptr) return;
- render = (struct vdpau_render_state *)s->current_picture_ptr->data[0];
+ render = (struct vdpau_render_state *)s->current_picture_ptr->f.data[0];
assert(render);
/* fill VdpPictureInfoMPEG4Part2 struct */
@@ -353,13 +353,13 @@ void ff_vdpau_mpeg4_decode_picture(MpegEncContext *s, const uint8_t *buf,
switch (s->pict_type) {
case AV_PICTURE_TYPE_B:
- next = (struct vdpau_render_state *)s->next_picture.data[0];
+ next = (struct vdpau_render_state *)s->next_picture.f.data[0];
assert(next);
render->info.mpeg4.backward_reference = next->surface;
render->info.mpeg4.vop_coding_type = 2;
// no break here, going to set forward prediction
case AV_PICTURE_TYPE_P:
- last = (struct vdpau_render_state *)s->last_picture.data[0];
+ last = (struct vdpau_render_state *)s->last_picture.f.data[0];
assert(last);
render->info.mpeg4.forward_reference = last->surface;
}
@@ -370,4 +370,40 @@ void ff_vdpau_mpeg4_decode_picture(MpegEncContext *s, const uint8_t *buf,
render->bitstream_buffers_used = 0;
}
+// Only dummy functions for now
+static int vdpau_mpeg2_start_frame(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
+{
+ return 0;
+}
+
+static int vdpau_mpeg2_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
+{
+ return 0;
+}
+
+static int vdpau_mpeg2_end_frame(AVCodecContext *avctx)
+{
+ return 0;
+}
+
+AVHWAccel ff_mpeg1_vdpau_hwaccel = {
+ .name = "mpeg1_vdpau",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_MPEG1VIDEO,
+ .pix_fmt = PIX_FMT_VDPAU_MPEG1,
+ .start_frame = vdpau_mpeg2_start_frame,
+ .end_frame = vdpau_mpeg2_end_frame,
+ .decode_slice = vdpau_mpeg2_decode_slice,
+};
+
+AVHWAccel ff_mpeg2_vdpau_hwaccel = {
+ .name = "mpeg2_vdpau",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_MPEG2VIDEO,
+ .pix_fmt = PIX_FMT_VDPAU_MPEG2,
+ .start_frame = vdpau_mpeg2_start_frame,
+ .end_frame = vdpau_mpeg2_end_frame,
+ .decode_slice = vdpau_mpeg2_decode_slice,
+};
+
/* @}*/
diff --git a/libavcodec/vdpau.h b/libavcodec/vdpau.h
index 6f1386067b..f3a547184d 100644
--- a/libavcodec/vdpau.h
+++ b/libavcodec/vdpau.h
@@ -4,20 +4,20 @@
*
* Copyright (C) 2008 NVIDIA
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -31,7 +31,7 @@
* - VDPAU decoding
* - VDPAU presentation
*
- * The VDPAU decoding module parses all headers using Libav
+ * The VDPAU decoding module parses all headers using FFmpeg
* parsing mechanisms and uses VDPAU for the actual decoding.
*
* As per the current implementation, the actual decoding
@@ -56,17 +56,24 @@
#define FF_VDPAU_STATE_USED_FOR_REFERENCE 2
/**
- * @brief This structure is used as a callback between the Libav
+ * @brief This structure is used as a callback between the FFmpeg
* decoder (vd_) and presentation (vo_) module.
* This is used for defining a video frame containing surface,
* picture parameter, bitstream information etc which are passed
- * between the Libav decoder and its clients.
+ * between the FFmpeg decoder and its clients.
*/
struct vdpau_render_state {
VdpVideoSurface surface; ///< Used as rendered surface, never changed.
int state; ///< Holds FF_VDPAU_STATE_* values.
+ /** Describe size/location of the compressed video data.
+ Set to 0 when freeing bitstream_buffers. */
+ int bitstream_buffers_allocated;
+ int bitstream_buffers_used;
+ /** The user is responsible for freeing this buffer using av_freep(). */
+ VdpBitstreamBuffer *bitstream_buffers;
+
/** picture parameter information for all supported codecs */
union VdpPictureInfo {
VdpPictureInfoH264 h264;
@@ -74,13 +81,6 @@ struct vdpau_render_state {
VdpPictureInfoVC1 vc1;
VdpPictureInfoMPEG4Part2 mpeg4;
} info;
-
- /** Describe size/location of the compressed video data.
- Set to 0 when freeing bitstream_buffers. */
- int bitstream_buffers_allocated;
- int bitstream_buffers_used;
- /** The user is responsible for freeing this buffer using av_freep(). */
- VdpBitstreamBuffer *bitstream_buffers;
};
/* @}*/
diff --git a/libavcodec/vdpau_internal.h b/libavcodec/vdpau_internal.h
index 673fd3349b..0a8d0b6b55 100644
--- a/libavcodec/vdpau_internal.h
+++ b/libavcodec/vdpau_internal.h
@@ -4,20 +4,20 @@
*
* Copyright (C) 2008 NVIDIA
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/version.h b/libavcodec/version.h
index aded68e83e..0fd5e72874 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -1,19 +1,19 @@
/*
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -21,7 +21,7 @@
#define AVCODEC_VERSION_H
#define LIBAVCODEC_VERSION_MAJOR 53
-#define LIBAVCODEC_VERSION_MINOR 5
+#define LIBAVCODEC_VERSION_MINOR 23
#define LIBAVCODEC_VERSION_MICRO 0
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
@@ -68,5 +68,38 @@
#ifndef FF_API_GET_PIX_FMT_NAME
#define FF_API_GET_PIX_FMT_NAME (LIBAVCODEC_VERSION_MAJOR < 54)
#endif
+#ifndef FF_API_ALLOC_CONTEXT
+#define FF_API_ALLOC_CONTEXT (LIBAVCODEC_VERSION_MAJOR < 54)
+#endif
+#ifndef FF_API_AVCODEC_OPEN
+#define FF_API_AVCODEC_OPEN (LIBAVCODEC_VERSION_MAJOR < 54)
+#endif
+#ifndef FF_API_DRC_SCALE
+#define FF_API_DRC_SCALE (LIBAVCODEC_VERSION_MAJOR < 54)
+#endif
+#ifndef FF_API_ER
+#define FF_API_ER (LIBAVCODEC_VERSION_MAJOR < 54)
+#endif
+#ifndef FF_API_AVCODEC_INIT
+#define FF_API_AVCODEC_INIT (LIBAVCODEC_VERSION_MAJOR < 54)
+#endif
+#ifndef FF_API_X264_GLOBAL_OPTS
+#define FF_API_X264_GLOBAL_OPTS (LIBAVCODEC_VERSION_MAJOR < 54)
+#endif
+#ifndef FF_API_MPEGVIDEO_GLOBAL_OPTS
+#define FF_API_MPEGVIDEO_GLOBAL_OPTS (LIBAVCODEC_VERSION_MAJOR < 54)
+#endif
+#ifndef FF_API_LAME_GLOBAL_OPTS
+#define FF_API_LAME_GLOBAL_OPTS (LIBAVCODEC_VERSION_MAJOR < 54)
+#endif
+#ifndef FF_API_SNOW_GLOBAL_OPTS
+#define FF_API_SNOW_GLOBAL_OPTS (LIBAVCODEC_VERSION_MAJOR < 54)
+#endif
+#ifndef FF_API_MJPEG_GLOBAL_OPTS
+#define FF_API_MJPEG_GLOBAL_OPTS (LIBAVCODEC_VERSION_MAJOR < 54)
+#endif
+#ifndef FF_API_GET_ALPHA_INFO
+#define FF_API_GET_ALPHA_INFO (LIBAVCODEC_VERSION_MAJOR < 54)
+#endif
#endif /* AVCODEC_VERSION_H */
diff --git a/libavcodec/vmdav.c b/libavcodec/vmdav.c
index 283c2136d5..63ac33db59 100644
--- a/libavcodec/vmdav.c
+++ b/libavcodec/vmdav.c
@@ -2,20 +2,20 @@
* Sierra VMD Audio & Video Decoders
* Copyright (C) 2004 the ffmpeg project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -72,9 +72,11 @@ typedef struct VmdVideoContext {
#define QUEUE_SIZE 0x1000
#define QUEUE_MASK 0x0FFF
-static void lz_unpack(const unsigned char *src, unsigned char *dest, int dest_len)
+static void lz_unpack(const unsigned char *src, int src_len,
+ unsigned char *dest, int dest_len)
{
const unsigned char *s;
+ const unsigned char *s_end;
unsigned char *d;
unsigned char *d_end;
unsigned char queue[QUEUE_SIZE];
@@ -87,8 +89,12 @@ static void lz_unpack(const unsigned char *src, unsigned char *dest, int dest_le
unsigned int i, j;
s = src;
+ s_end = src + src_len;
d = dest;
d_end = d + dest_len;
+
+ if (s_end - s < 8)
+ return;
dataleft = AV_RL32(s);
s += 4;
memset(queue, 0x20, QUEUE_SIZE);
@@ -101,10 +107,10 @@ static void lz_unpack(const unsigned char *src, unsigned char *dest, int dest_le
speclen = 100; /* no speclen */
}
- while (dataleft > 0) {
+ while (s_end - s > 0 && dataleft > 0) {
tag = *s++;
if ((tag == 0xFF) && (dataleft > 8)) {
- if (d + 8 > d_end)
+ if (d_end - d < 8 || s_end - s < 8)
return;
for (i = 0; i < 8; i++) {
queue[qpos++] = *d++ = *s++;
@@ -116,18 +122,23 @@ static void lz_unpack(const unsigned char *src, unsigned char *dest, int dest_le
if (dataleft == 0)
break;
if (tag & 0x01) {
- if (d + 1 > d_end)
+ if (d_end - d < 1 || s_end - s < 1)
return;
queue[qpos++] = *d++ = *s++;
qpos &= QUEUE_MASK;
dataleft--;
} else {
+ if (s_end - s < 2)
+ return;
chainofs = *s++;
chainofs |= ((*s & 0xF0) << 4);
chainlen = (*s++ & 0x0F) + 3;
- if (chainlen == speclen)
+ if (chainlen == speclen) {
+ if (s_end - s < 1)
+ return;
chainlen = *s++ + 0xF + 3;
- if (d + chainlen > d_end)
+ }
+ if (d_end - d < chainlen)
return;
for (j = 0; j < chainlen; j++) {
*d = queue[chainofs++ & QUEUE_MASK];
@@ -142,32 +153,39 @@ static void lz_unpack(const unsigned char *src, unsigned char *dest, int dest_le
}
}
-static int rle_unpack(const unsigned char *src, unsigned char *dest,
- int src_len, int dest_len)
+static int rle_unpack(const unsigned char *src, int src_len, int src_count,
+ unsigned char *dest, int dest_len)
{
const unsigned char *ps;
+ const unsigned char *ps_end;
unsigned char *pd;
int i, l;
unsigned char *dest_end = dest + dest_len;
ps = src;
+ ps_end = src + src_len;
pd = dest;
- if (src_len & 1)
+ if (src_count & 1) {
+ if (ps_end - ps < 1)
+ return 0;
*pd++ = *ps++;
+ }
- src_len >>= 1;
+ src_count >>= 1;
i = 0;
do {
+ if (ps_end - ps < 1)
+ break;
l = *ps++;
if (l & 0x80) {
l = (l & 0x7F) * 2;
- if (pd + l > dest_end)
+ if (dest_end - pd < l || ps_end - ps < l)
return ps - src;
memcpy(pd, ps, l);
ps += l;
pd += l;
} else {
- if (pd + i > dest_end)
+ if (dest_end - pd < i || ps_end - ps < 2)
return ps - src;
for (i = 0; i < l; i++) {
*pd++ = ps[0];
@@ -176,7 +194,7 @@ static int rle_unpack(const unsigned char *src, unsigned char *dest,
ps += 2;
}
i += l;
- } while (i < src_len);
+ } while (i < src_count);
return ps - src;
}
@@ -189,8 +207,10 @@ static void vmd_decode(VmdVideoContext *s)
/* point to the start of the encoded data */
const unsigned char *p = s->buf + 16;
+ const unsigned char *p_end = s->buf + s->size;
const unsigned char *pb;
+ const unsigned char *pb_end;
unsigned char meth;
unsigned char *dp; /* pointer to current frame */
unsigned char *pp; /* pointer to previous frame */
@@ -204,6 +224,16 @@ static void vmd_decode(VmdVideoContext *s)
frame_y = AV_RL16(&s->buf[8]);
frame_width = AV_RL16(&s->buf[10]) - frame_x + 1;
frame_height = AV_RL16(&s->buf[12]) - frame_y + 1;
+ if (frame_x < 0 || frame_width < 0 ||
+ frame_x >= s->avctx->width ||
+ frame_width > s->avctx->width ||
+ frame_x + frame_width > s->avctx->width)
+ return;
+ if (frame_y < 0 || frame_height < 0 ||
+ frame_y >= s->avctx->height ||
+ frame_height > s->avctx->height ||
+ frame_y + frame_height > s->avctx->height)
+ return;
if ((frame_width == s->avctx->width && frame_height == s->avctx->height) &&
(frame_x || frame_y)) {
@@ -216,8 +246,9 @@ static void vmd_decode(VmdVideoContext *s)
/* if only a certain region will be updated, copy the entire previous
* frame before the decode */
- if (frame_x || frame_y || (frame_width != s->avctx->width) ||
- (frame_height != s->avctx->height)) {
+ if (s->prev_frame.data[0] &&
+ (frame_x || frame_y || (frame_width != s->avctx->width) ||
+ (frame_height != s->avctx->height))) {
memcpy(s->frame.data[0], s->prev_frame.data[0],
s->avctx->height * s->frame.linesize[0]);
@@ -225,6 +256,8 @@ static void vmd_decode(VmdVideoContext *s)
/* check if there is a new palette */
if (s->buf[15] & 0x02) {
+ if (p_end - p < 2 + 3 * PALETTE_COUNT)
+ return;
p += 2;
palette32 = (unsigned int *)s->palette;
for (i = 0; i < PALETTE_COUNT; i++) {
@@ -233,16 +266,17 @@ static void vmd_decode(VmdVideoContext *s)
b = *p++ * 4;
palette32[i] = (r << 16) | (g << 8) | (b);
}
- s->size -= (256 * 3 + 2);
}
- if (s->size >= 0) {
+ if (p < p_end) {
/* originally UnpackFrame in VAG's code */
pb = p;
+ pb_end = p_end;
meth = *pb++;
if (meth & 0x80) {
- lz_unpack(pb, s->unpack_buffer, s->unpack_buffer_size);
+ lz_unpack(pb, p_end - pb, s->unpack_buffer, s->unpack_buffer_size);
meth &= 0x7F;
pb = s->unpack_buffer;
+ pb_end = s->unpack_buffer + s->unpack_buffer_size;
}
dp = &s->frame.data[0][frame_y * s->frame.linesize[0] + frame_x];
@@ -252,17 +286,19 @@ static void vmd_decode(VmdVideoContext *s)
for (i = 0; i < frame_height; i++) {
ofs = 0;
do {
+ if (pb_end - pb < 1)
+ return;
len = *pb++;
if (len & 0x80) {
len = (len & 0x7F) + 1;
- if (ofs + len > frame_width)
+ if (ofs + len > frame_width || pb_end - pb < len)
return;
memcpy(&dp[ofs], pb, len);
pb += len;
ofs += len;
} else {
/* interframe pixel copy */
- if (ofs + len + 1 > frame_width)
+ if (ofs + len + 1 > frame_width || !s->prev_frame.data[0])
return;
memcpy(&dp[ofs], &pp[ofs], len + 1);
ofs += len + 1;
@@ -280,6 +316,8 @@ static void vmd_decode(VmdVideoContext *s)
case 2:
for (i = 0; i < frame_height; i++) {
+ if (pb_end -pb < frame_width)
+ return;
memcpy(dp, pb, frame_width);
pb += frame_width;
dp += s->frame.linesize[0];
@@ -291,18 +329,25 @@ static void vmd_decode(VmdVideoContext *s)
for (i = 0; i < frame_height; i++) {
ofs = 0;
do {
+ if (pb_end - pb < 1)
+ return;
len = *pb++;
if (len & 0x80) {
len = (len & 0x7F) + 1;
+ if (pb_end - pb < 1)
+ return;
if (*pb++ == 0xFF)
- len = rle_unpack(pb, &dp[ofs], len, frame_width - ofs);
- else
+ len = rle_unpack(pb, pb_end - pb, len, &dp[ofs], frame_width - ofs);
+ else {
+ if (pb_end - pb < len)
+ return;
memcpy(&dp[ofs], pb, len);
+ }
pb += len;
ofs += len;
} else {
/* interframe pixel copy */
- if (ofs + len + 1 > frame_width)
+ if (ofs + len + 1 > frame_width || !s->prev_frame.data[0])
return;
memcpy(&dp[ofs], &pp[ofs], len + 1);
ofs += len + 1;
@@ -356,6 +401,9 @@ static av_cold int vmdvideo_decode_init(AVCodecContext *avctx)
palette32[i] = (r << 16) | (g << 8) | (b);
}
+ avcodec_get_frame_defaults(&s->frame);
+ avcodec_get_frame_defaults(&s->prev_frame);
+
return 0;
}
@@ -417,9 +465,8 @@ static av_cold int vmdvideo_decode_end(AVCodecContext *avctx)
#define BLOCK_TYPE_SILENCE 3
typedef struct VmdAudioContext {
- AVCodecContext *avctx;
int out_bps;
- int predictors[2];
+ int chunk_size;
} VmdAudioContext;
static const uint16_t vmdaudio_table[128] = {
@@ -442,13 +489,23 @@ static av_cold int vmdaudio_decode_init(AVCodecContext *avctx)
{
VmdAudioContext *s = avctx->priv_data;
- s->avctx = avctx;
+ if (avctx->channels < 1 || avctx->channels > 2) {
+ av_log(avctx, AV_LOG_ERROR, "invalid number of channels\n");
+ return AVERROR(EINVAL);
+ }
+ if (avctx->block_align < 1) {
+ av_log(avctx, AV_LOG_ERROR, "invalid block align\n");
+ return AVERROR(EINVAL);
+ }
+
if (avctx->bits_per_coded_sample == 16)
avctx->sample_fmt = AV_SAMPLE_FMT_S16;
else
avctx->sample_fmt = AV_SAMPLE_FMT_U8;
s->out_bps = av_get_bytes_per_sample(avctx->sample_fmt);
+ s->chunk_size = avctx->block_align + avctx->channels * (s->out_bps == 2);
+
av_log(avctx, AV_LOG_DEBUG, "%d channels, %d bits/sample, "
"block align = %d, sample rate = %d\n",
avctx->channels, avctx->bits_per_coded_sample, avctx->block_align,
@@ -457,41 +514,33 @@ static av_cold int vmdaudio_decode_init(AVCodecContext *avctx)
return 0;
}
-static void vmdaudio_decode_audio(VmdAudioContext *s, unsigned char *data,
- const uint8_t *buf, int buf_size, int stereo)
+static void decode_audio_s16(int16_t *out, const uint8_t *buf, int buf_size,
+ int channels)
{
- int i;
- int chan = 0;
- int16_t *out = (int16_t*)data;
-
- for(i = 0; i < buf_size; i++) {
- if(buf[i] & 0x80)
- s->predictors[chan] -= vmdaudio_table[buf[i] & 0x7F];
- else
- s->predictors[chan] += vmdaudio_table[buf[i]];
- s->predictors[chan] = av_clip_int16(s->predictors[chan]);
- out[i] = s->predictors[chan];
- chan ^= stereo;
+ int ch;
+ const uint8_t *buf_end = buf + buf_size;
+ int predictor[2];
+ int st = channels - 1;
+
+ /* decode initial raw sample */
+ for (ch = 0; ch < channels; ch++) {
+ predictor[ch] = (int16_t)AV_RL16(buf);
+ buf += 2;
+ *out++ = predictor[ch];
}
-}
-static int vmdaudio_loadsound(VmdAudioContext *s, unsigned char *data,
- const uint8_t *buf, int silent_chunks, int data_size)
-{
- int silent_size = s->avctx->block_align * silent_chunks * s->out_bps;
-
- if (silent_chunks) {
- memset(data, s->out_bps == 2 ? 0x00 : 0x80, silent_size);
- data += silent_size;
- }
- if (s->avctx->bits_per_coded_sample == 16)
- vmdaudio_decode_audio(s, data, buf, data_size, s->avctx->channels == 2);
- else {
- /* just copy the data */
- memcpy(data, buf, data_size);
+ /* decode DPCM samples */
+ ch = 0;
+ while (buf < buf_end) {
+ uint8_t b = *buf++;
+ if (b & 0x80)
+ predictor[ch] -= vmdaudio_table[b & 0x7F];
+ else
+ predictor[ch] += vmdaudio_table[b];
+ predictor[ch] = av_clip_int16(predictor[ch]);
+ *out++ = predictor[ch];
+ ch ^= st;
}
-
- return silent_size + data_size * s->out_bps;
}
static int vmdaudio_decode_frame(AVCodecContext *avctx,
@@ -499,10 +548,13 @@ static int vmdaudio_decode_frame(AVCodecContext *avctx,
AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
+ const uint8_t *buf_end;
int buf_size = avpkt->size;
VmdAudioContext *s = avctx->priv_data;
- int block_type, silent_chunks;
- unsigned char *output_samples = (unsigned char *)data;
+ int block_type, silent_chunks, audio_chunks;
+ int nb_samples, out_size;
+ uint8_t *output_samples_u8 = data;
+ int16_t *output_samples_s16 = data;
if (buf_size < 16) {
av_log(avctx, AV_LOG_WARNING, "skipping small junk packet\n");
@@ -518,10 +570,16 @@ static int vmdaudio_decode_frame(AVCodecContext *avctx,
buf += 16;
buf_size -= 16;
+ /* get number of silent chunks */
silent_chunks = 0;
if (block_type == BLOCK_TYPE_INITIAL) {
- uint32_t flags = AV_RB32(buf);
- silent_chunks = av_popcount(flags);
+ uint32_t flags;
+ if (buf_size < 4) {
+ av_log(avctx, AV_LOG_ERROR, "packet is too small\n");
+ return AVERROR(EINVAL);
+ }
+ flags = AV_RB32(buf);
+ silent_chunks = av_popcount(flags);
buf += 4;
buf_size -= 4;
} else if (block_type == BLOCK_TYPE_SILENCE) {
@@ -530,11 +588,41 @@ static int vmdaudio_decode_frame(AVCodecContext *avctx,
}
/* ensure output buffer is large enough */
- if (*data_size < (avctx->block_align*silent_chunks + buf_size) * s->out_bps)
+ audio_chunks = buf_size / s->chunk_size;
+ nb_samples = ((silent_chunks + audio_chunks) * avctx->block_align) / avctx->channels;
+ out_size = nb_samples * avctx->channels * s->out_bps;
+ if (*data_size < out_size)
return -1;
- *data_size = vmdaudio_loadsound(s, output_samples, buf, silent_chunks, buf_size);
+ /* decode silent chunks */
+ if (silent_chunks > 0) {
+ int silent_size = avctx->block_align * silent_chunks;
+ if (s->out_bps == 2) {
+ memset(output_samples_s16, 0x00, silent_size * 2);
+ output_samples_s16 += silent_size;
+ } else {
+ memset(output_samples_u8, 0x80, silent_size);
+ output_samples_u8 += silent_size;
+ }
+ }
+
+ /* decode audio chunks */
+ if (audio_chunks > 0) {
+ buf_end = buf + buf_size;
+ while (buf < buf_end) {
+ if (s->out_bps == 2) {
+ decode_audio_s16(output_samples_s16, buf, s->chunk_size,
+ avctx->channels);
+ output_samples_s16 += avctx->block_align;
+ } else {
+ memcpy(output_samples_u8, buf, s->chunk_size);
+ output_samples_u8 += avctx->block_align;
+ }
+ buf += s->chunk_size;
+ }
+ }
+ *data_size = out_size;
return avpkt->size;
}
@@ -544,26 +632,23 @@ static int vmdaudio_decode_frame(AVCodecContext *avctx,
*/
AVCodec ff_vmdvideo_decoder = {
- "vmdvideo",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_VMDVIDEO,
- sizeof(VmdVideoContext),
- vmdvideo_decode_init,
- NULL,
- vmdvideo_decode_end,
- vmdvideo_decode_frame,
- CODEC_CAP_DR1,
+ .name = "vmdvideo",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_VMDVIDEO,
+ .priv_data_size = sizeof(VmdVideoContext),
+ .init = vmdvideo_decode_init,
+ .close = vmdvideo_decode_end,
+ .decode = vmdvideo_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Sierra VMD video"),
};
AVCodec ff_vmdaudio_decoder = {
- "vmdaudio",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_VMDAUDIO,
- sizeof(VmdAudioContext),
- vmdaudio_decode_init,
- NULL,
- NULL,
- vmdaudio_decode_frame,
+ .name = "vmdaudio",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_VMDAUDIO,
+ .priv_data_size = sizeof(VmdAudioContext),
+ .init = vmdaudio_decode_init,
+ .decode = vmdaudio_decode_frame,
.long_name = NULL_IF_CONFIG_SMALL("Sierra VMD audio"),
};
diff --git a/libavcodec/vmnc.c b/libavcodec/vmnc.c
index f95bef7e1d..4c9b26c6f8 100644
--- a/libavcodec/vmnc.c
+++ b/libavcodec/vmnc.c
@@ -2,20 +2,20 @@
* VMware Screen Codec (VMnc) decoder
* Copyright (c) 2006 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -470,6 +470,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
c->bpp = avctx->bits_per_coded_sample;
c->bpp2 = c->bpp/8;
+ avcodec_get_frame_defaults(&c->pic);
switch(c->bpp){
case 8:
@@ -509,15 +510,14 @@ static av_cold int decode_end(AVCodecContext *avctx)
}
AVCodec ff_vmnc_decoder = {
- "vmnc",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_VMNC,
- sizeof(VmncContext),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- CODEC_CAP_DR1,
+ .name = "vmnc",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_VMNC,
+ .priv_data_size = sizeof(VmncContext),
+ .init = decode_init,
+ .close = decode_end,
+ .decode = decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("VMware Screen Codec / VMware Video"),
};
diff --git a/libavcodec/vorbis.c b/libavcodec/vorbis.c
index f413170b6a..1624948626 100644
--- a/libavcodec/vorbis.c
+++ b/libavcodec/vorbis.c
@@ -3,23 +3,29 @@
* Common code for Vorbis I encoder and decoder
* @author Denes Balatoni ( dbalatoni programozo hu )
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+/**
+ * @file
+ * Common code for Vorbis I encoder and decoder
+ * @author Denes Balatoni ( dbalatoni programozo hu )
+ */
+
#define ALT_BITSTREAM_READER_LE
#include "avcodec.h"
#include "get_bits.h"
diff --git a/libavcodec/vorbis.h b/libavcodec/vorbis.h
index 8501e0a178..15b5d85b36 100644
--- a/libavcodec/vorbis.h
+++ b/libavcodec/vorbis.h
@@ -1,20 +1,20 @@
/*
* copyright (c) 2006 Oded Shimon <ods15@ods15.dyndns.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/vorbis_data.c b/libavcodec/vorbis_data.c
index 4e1fe00863..8fa624168a 100644
--- a/libavcodec/vorbis_data.c
+++ b/libavcodec/vorbis_data.c
@@ -1,20 +1,20 @@
/*
* copyright (c) 2005 Denes Balatoni ( dbalatoni programozo hu )
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/vorbis_enc_data.h b/libavcodec/vorbis_enc_data.h
index a1e743ebe5..affc3d6c86 100644
--- a/libavcodec/vorbis_enc_data.h
+++ b/libavcodec/vorbis_enc_data.h
@@ -1,20 +1,20 @@
/*
* copyright (c) 2006 Oded Shimon <ods15@ods15.dyndns.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/vorbisdec.c b/libavcodec/vorbisdec.c
index 9fc60688a2..59d551e894 100644
--- a/libavcodec/vorbisdec.c
+++ b/libavcodec/vorbisdec.c
@@ -3,23 +3,29 @@
* Vorbis I decoder
* @author Denes Balatoni ( dbalatoni programozo hu )
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+/**
+ * @file
+ * Vorbis I decoder
+ * @author Denes Balatoni ( dbalatoni programozo hu )
+ */
+
#include <inttypes.h>
#include <math.h>
@@ -985,7 +991,7 @@ static av_cold int vorbis_decode_init(AVCodecContext *avccontext)
return -1;
}
- if (ff_split_xiph_headers(headers, headers_len, 30, header_start, header_len) < 0) {
+ if (avpriv_split_xiph_headers(headers, headers_len, 30, header_start, header_len) < 0) {
av_log(avccontext, AV_LOG_ERROR, "Extradata corrupt.\n");
return -1;
}
@@ -1147,7 +1153,7 @@ static int vorbis_floor1_decode(vorbis_context *vc,
uint16_t floor1_Y[258];
uint16_t floor1_Y_final[258];
int floor1_flag[258];
- unsigned class, cdim, cbits, csub, cval, offset, i, j;
+ unsigned partition_class, cdim, cbits, csub, cval, offset, i, j;
int book, adx, ady, dy, off, predicted, err;
@@ -1163,20 +1169,20 @@ static int vorbis_floor1_decode(vorbis_context *vc,
offset = 2;
for (i = 0; i < vf->partitions; ++i) {
- class = vf->partition_class[i];
- cdim = vf->class_dimensions[class];
- cbits = vf->class_subclasses[class];
+ partition_class = vf->partition_class[i];
+ cdim = vf->class_dimensions[partition_class];
+ cbits = vf->class_subclasses[partition_class];
csub = (1 << cbits) - 1;
cval = 0;
av_dlog(NULL, "Cbits %u\n", cbits);
if (cbits) // this reads all subclasses for this partition's class
- cval = get_vlc2(gb, vc->codebooks[vf->class_masterbook[class]].vlc.table,
- vc->codebooks[vf->class_masterbook[class]].nb_bits, 3);
+ cval = get_vlc2(gb, vc->codebooks[vf->class_masterbook[partition_class]].vlc.table,
+ vc->codebooks[vf->class_masterbook[partition_class]].nb_bits, 3);
for (j = 0; j < cdim; ++j) {
- book = vf->subclass_books[class][cval & csub];
+ book = vf->subclass_books[partition_class][cval & csub];
av_dlog(NULL, "book %d Cbits %u cval %u bits:%d\n",
book, cbits, cval, get_bits_count(gb));
@@ -1663,14 +1669,13 @@ static av_cold int vorbis_decode_close(AVCodecContext *avccontext)
}
AVCodec ff_vorbis_decoder = {
- "vorbis",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_VORBIS,
- sizeof(vorbis_context),
- vorbis_decode_init,
- NULL,
- vorbis_decode_close,
- vorbis_decode_frame,
+ .name = "vorbis",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_VORBIS,
+ .priv_data_size = sizeof(vorbis_context),
+ .init = vorbis_decode_init,
+ .close = vorbis_decode_close,
+ .decode = vorbis_decode_frame,
.long_name = NULL_IF_CONFIG_SMALL("Vorbis"),
.channel_layouts = ff_vorbis_channel_layouts,
.sample_fmts = (const enum AVSampleFormat[]) {
diff --git a/libavcodec/vorbisenc.c b/libavcodec/vorbisenc.c
index 67d094b37d..80d722db4c 100644
--- a/libavcodec/vorbisenc.c
+++ b/libavcodec/vorbisenc.c
@@ -1,20 +1,20 @@
/*
* copyright (c) 2006 Oded Shimon <ods15@ods15.dyndns.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -957,7 +957,7 @@ static av_cold int vorbis_encode_init(AVCodecContext *avccontext)
vorbis_enc_context *venc = avccontext->priv_data;
if (avccontext->channels != 2) {
- av_log(avccontext, AV_LOG_ERROR, "Current Libav Vorbis encoder only supports 2 channels.\n");
+ av_log(avccontext, AV_LOG_ERROR, "Current FFmpeg Vorbis encoder only supports 2 channels.\n");
return -1;
}
@@ -1103,13 +1103,13 @@ static av_cold int vorbis_encode_close(AVCodecContext *avccontext)
}
AVCodec ff_vorbis_encoder = {
- "vorbis",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_VORBIS,
- sizeof(vorbis_enc_context),
- vorbis_encode_init,
- vorbis_encode_frame,
- vorbis_encode_close,
+ .name = "vorbis",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_VORBIS,
+ .priv_data_size = sizeof(vorbis_enc_context),
+ .init = vorbis_encode_init,
+ .encode = vorbis_encode_frame,
+ .close = vorbis_encode_close,
.capabilities= CODEC_CAP_DELAY | CODEC_CAP_EXPERIMENTAL,
.sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
.long_name = NULL_IF_CONFIG_SMALL("Vorbis"),
diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c
index c3dff7f89f..82838de61e 100644
--- a/libavcodec/vp3.c
+++ b/libavcodec/vp3.c
@@ -1,20 +1,20 @@
/*
* Copyright (C) 2003-2004 the ffmpeg project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -225,7 +225,7 @@ typedef struct Vp3DecodeContext {
/* these arrays need to be on 16-byte boundaries since SSE2 operations
* index into them */
- DECLARE_ALIGNED(16, int16_t, qmat)[3][2][3][64]; //<qmat[qpi][is_inter][plane]
+ DECLARE_ALIGNED(16, int16_t, qmat)[3][2][3][64]; ///< qmat[qpi][is_inter][plane]
/* This table contains superblock_count * 16 entries. Each set of 16
* numbers corresponds to the fragment indexes 0..15 of the superblock.
@@ -1316,7 +1316,7 @@ static void vp3_draw_horiz_band(Vp3DecodeContext *s, int y)
int h, cy;
int offset[4];
- if (HAVE_PTHREADS && s->avctx->active_thread_type&FF_THREAD_FRAME) {
+ if (HAVE_THREADS && s->avctx->active_thread_type&FF_THREAD_FRAME) {
int y_flipped = s->flipped_image ? s->avctx->height-y : y;
// At the end of the frame, report INT_MAX instead of the height of the frame.
@@ -1400,7 +1400,7 @@ static void render_slice(Vp3DecodeContext *s, int slice)
int fragment_width = s->fragment_width[!!plane];
int fragment_height = s->fragment_height[!!plane];
int fragment_start = s->fragment_start[plane];
- int do_await = !plane && HAVE_PTHREADS && (s->avctx->active_thread_type&FF_THREAD_FRAME);
+ int do_await = !plane && HAVE_THREADS && (s->avctx->active_thread_type&FF_THREAD_FRAME);
if (!s->flipped_image) stride = -stride;
if (CONFIG_GRAY && plane && (s->avctx->flags & CODEC_FLAG_GRAY))
@@ -1877,6 +1877,7 @@ static int vp3_decode_frame(AVCodecContext *avctx,
s->current_frame.reference = 3;
s->current_frame.pict_type = s->keyframe ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;
+ s->current_frame.key_frame = s->keyframe;
if (ff_thread_get_buffer(avctx, &s->current_frame) < 0) {
av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n");
goto error;
@@ -1965,7 +1966,7 @@ static int vp3_decode_frame(AVCodecContext *avctx,
*data_size=sizeof(AVFrame);
*(AVFrame*)data= s->current_frame;
- if (!HAVE_PTHREADS || !(s->avctx->active_thread_type&FF_THREAD_FRAME))
+ if (!HAVE_THREADS || !(s->avctx->active_thread_type&FF_THREAD_FRAME))
update_frames(avctx);
return buf_size;
@@ -1973,7 +1974,7 @@ static int vp3_decode_frame(AVCodecContext *avctx,
error:
ff_thread_report_progress(&s->current_frame, INT_MAX, 0);
- if (!HAVE_PTHREADS || !(s->avctx->active_thread_type&FF_THREAD_FRAME))
+ if (!HAVE_THREADS || !(s->avctx->active_thread_type&FF_THREAD_FRAME))
avctx->release_buffer(avctx, &s->current_frame);
return -1;
@@ -2275,7 +2276,7 @@ static av_cold int theora_decode_init(AVCodecContext *avctx)
return -1;
}
- if (ff_split_xiph_headers(avctx->extradata, avctx->extradata_size,
+ if (avpriv_split_xiph_headers(avctx->extradata, avctx->extradata_size,
42, header_start, header_len) < 0) {
av_log(avctx, AV_LOG_ERROR, "Corrupt extradata\n");
return -1;
@@ -2321,33 +2322,51 @@ static av_cold int theora_decode_init(AVCodecContext *avctx)
return vp3_decode_init(avctx);
}
+static void vp3_decode_flush(AVCodecContext *avctx)
+{
+ Vp3DecodeContext *s = avctx->priv_data;
+
+ if (s->golden_frame.data[0]) {
+ if (s->golden_frame.data[0] == s->last_frame.data[0])
+ memset(&s->last_frame, 0, sizeof(AVFrame));
+ if (s->current_frame.data[0] == s->golden_frame.data[0])
+ memset(&s->current_frame, 0, sizeof(AVFrame));
+ ff_thread_release_buffer(avctx, &s->golden_frame);
+ }
+ if (s->last_frame.data[0]) {
+ if (s->current_frame.data[0] == s->last_frame.data[0])
+ memset(&s->current_frame, 0, sizeof(AVFrame));
+ ff_thread_release_buffer(avctx, &s->last_frame);
+ }
+ if (s->current_frame.data[0])
+ ff_thread_release_buffer(avctx, &s->current_frame);
+}
+
AVCodec ff_theora_decoder = {
- "theora",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_THEORA,
- sizeof(Vp3DecodeContext),
- theora_decode_init,
- NULL,
- vp3_decode_end,
- vp3_decode_frame,
- CODEC_CAP_DR1 | CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_FRAME_THREADS,
- NULL,
+ .name = "theora",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_THEORA,
+ .priv_data_size = sizeof(Vp3DecodeContext),
+ .init = theora_decode_init,
+ .close = vp3_decode_end,
+ .decode = vp3_decode_frame,
+ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_FRAME_THREADS,
+ .flush = vp3_decode_flush,
.long_name = NULL_IF_CONFIG_SMALL("Theora"),
.update_thread_context = ONLY_IF_THREADS_ENABLED(vp3_update_thread_context)
};
#endif
AVCodec ff_vp3_decoder = {
- "vp3",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_VP3,
- sizeof(Vp3DecodeContext),
- vp3_decode_init,
- NULL,
- vp3_decode_end,
- vp3_decode_frame,
- CODEC_CAP_DR1 | CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_FRAME_THREADS,
- NULL,
+ .name = "vp3",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_VP3,
+ .priv_data_size = sizeof(Vp3DecodeContext),
+ .init = vp3_decode_init,
+ .close = vp3_decode_end,
+ .decode = vp3_decode_frame,
+ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_FRAME_THREADS,
+ .flush = vp3_decode_flush,
.long_name = NULL_IF_CONFIG_SMALL("On2 VP3"),
.update_thread_context = ONLY_IF_THREADS_ENABLED(vp3_update_thread_context)
};
diff --git a/libavcodec/vp3_parser.c b/libavcodec/vp3_parser.c
index cfe6b3f2a3..320f9870f9 100644
--- a/libavcodec/vp3_parser.c
+++ b/libavcodec/vp3_parser.c
@@ -1,20 +1,20 @@
/*
* Copyright (C) 2008 Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/vp3data.h b/libavcodec/vp3data.h
index 54d5a6c576..904ec6abf5 100644
--- a/libavcodec/vp3data.h
+++ b/libavcodec/vp3data.h
@@ -1,20 +1,20 @@
/*
* copyright (C) 2003 the ffmpeg project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/vp3dsp.c b/libavcodec/vp3dsp.c
index baa22a5519..94efa3b1d2 100644
--- a/libavcodec/vp3dsp.c
+++ b/libavcodec/vp3dsp.c
@@ -1,20 +1,20 @@
/*
* Copyright (C) 2004 the ffmpeg project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/vp5.c b/libavcodec/vp5.c
index 807309f603..50bd868b51 100644
--- a/libavcodec/vp5.c
+++ b/libavcodec/vp5.c
@@ -1,26 +1,28 @@
-/**
- * @file
- * VP5 compatible video decoder
- *
+/*
* Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+/**
+ * @file
+ * VP5 compatible video decoder
+ */
+
#include <stdlib.h>
#include <string.h>
@@ -116,7 +118,7 @@ static void vp5_parse_vector_models(VP56Context *s)
model->vector_pdv[comp][node] = vp56_rac_gets_nn(c, 7);
}
-static void vp5_parse_coeff_models(VP56Context *s)
+static int vp5_parse_coeff_models(VP56Context *s)
{
VP56RangeCoder *c = &s->c;
VP56Model *model = s->modelp;
@@ -160,6 +162,7 @@ static void vp5_parse_coeff_models(VP56Context *s)
for (ctx=0; ctx<6; ctx++)
for (node=0; node<5; node++)
model->coeff_acct[pt][ct][cg][ctx][node] = av_clip(((model->coeff_ract[pt][ct][cg][node] * vp5_ract_lc[ct][cg][node][ctx][0] + 128) >> 8) + vp5_ract_lc[ct][cg][node][ctx][1], 1, 254);
+ return 0;
}
static void vp5_parse_coeff(VP56Context *s)
@@ -267,14 +270,13 @@ static av_cold int vp5_decode_init(AVCodecContext *avctx)
}
AVCodec ff_vp5_decoder = {
- "vp5",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_VP5,
- sizeof(VP56Context),
- vp5_decode_init,
- NULL,
- ff_vp56_free,
- ff_vp56_decode_frame,
- CODEC_CAP_DR1,
+ .name = "vp5",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_VP5,
+ .priv_data_size = sizeof(VP56Context),
+ .init = vp5_decode_init,
+ .close = ff_vp56_free,
+ .decode = ff_vp56_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("On2 VP5"),
};
diff --git a/libavcodec/vp56.c b/libavcodec/vp56.c
index a181978334..dbbbd54c02 100644
--- a/libavcodec/vp56.c
+++ b/libavcodec/vp56.c
@@ -1,26 +1,28 @@
-/**
- * @file
- * VP5 and VP6 compatible video decoder (common features)
- *
+/*
* Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+/**
+ * @file
+ * VP5 and VP6 compatible video decoder (common features)
+ */
+
#include "avcodec.h"
#include "bytestream.h"
@@ -399,6 +401,8 @@ static void vp56_decode_mb(VP56Context *s, int row, int col, int is_alpha)
frame_current = s->framep[VP56_FRAME_CURRENT];
frame_ref = s->framep[ref_frame];
+ if (mb_type != VP56_MB_INTRA && !frame_ref->data[0])
+ return;
ab = 6*is_alpha;
b_max = 6 - 2*is_alpha;
@@ -463,6 +467,7 @@ static int vp56_size_changed(AVCodecContext *avctx)
s->mb_height = (avctx->coded_height+15) / 16;
if (s->mb_width > 1000 || s->mb_height > 1000) {
+ avcodec_set_dimensions(avctx, 0, 0);
av_log(avctx, AV_LOG_ERROR, "picture too big\n");
return -1;
}
@@ -511,6 +516,18 @@ int ff_vp56_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
if (!res)
return -1;
+ if (res == 2) {
+ int i;
+ for (i = 0; i < 4; i++) {
+ if (s->frames[i].data[0])
+ avctx->release_buffer(avctx, &s->frames[i]);
+ }
+ if (is_alpha) {
+ avcodec_set_dimensions(avctx, 0, 0);
+ return -1;
+ }
+ }
+
if (!is_alpha) {
p->reference = 1;
if (avctx->get_buffer(avctx, p) < 0) {
@@ -537,7 +554,8 @@ int ff_vp56_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
s->mb_type = VP56_MB_INTER_NOVEC_PF;
}
- s->parse_coeff_models(s);
+ if (s->parse_coeff_models(s))
+ goto next;
memset(s->prev_dc, 0, sizeof(s->prev_dc));
s->prev_dc[1][VP56_FRAME_CURRENT] = 128;
@@ -601,6 +619,7 @@ int ff_vp56_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
}
}
+ next:
if (p->key_frame || golden_frame) {
if (s->framep[VP56_FRAME_GOLDEN]->data[0] &&
s->framep[VP56_FRAME_GOLDEN] != s->framep[VP56_FRAME_GOLDEN2])
@@ -653,8 +672,10 @@ av_cold void ff_vp56_init(AVCodecContext *avctx, int flip, int has_alpha)
ff_vp56dsp_init(&s->vp56dsp, avctx->codec->id);
ff_init_scantable(s->dsp.idct_permutation, &s->scantable,ff_zigzag_direct);
- for (i=0; i<4; i++)
+ for (i=0; i<4; i++) {
s->framep[i] = &s->frames[i];
+ avcodec_get_frame_defaults(&s->frames[i]);
+ }
s->framep[VP56_FRAME_UNUSED] = s->framep[VP56_FRAME_GOLDEN];
s->framep[VP56_FRAME_UNUSED2] = s->framep[VP56_FRAME_GOLDEN2];
s->edge_emu_buffer_alloc = NULL;
diff --git a/libavcodec/vp56.h b/libavcodec/vp56.h
index 5a55f7d6a1..7d411f400c 100644
--- a/libavcodec/vp56.h
+++ b/libavcodec/vp56.h
@@ -1,26 +1,28 @@
-/**
- * @file
- * VP5 and VP6 compatible video decoder (common features)
- *
+/*
* Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+/**
+ * @file
+ * VP5 and VP6 compatible video decoder (common features)
+ */
+
#ifndef AVCODEC_VP56_H
#define AVCODEC_VP56_H
@@ -46,7 +48,7 @@ typedef void (*VP56Filter)(VP56Context *s, uint8_t *dst, uint8_t *src,
typedef void (*VP56ParseCoeff)(VP56Context *s);
typedef void (*VP56DefaultModelsInit)(VP56Context *s);
typedef void (*VP56ParseVectorModels)(VP56Context *s);
-typedef void (*VP56ParseCoeffModels)(VP56Context *s);
+typedef int (*VP56ParseCoeffModels)(VP56Context *s);
typedef int (*VP56ParseHeader)(VP56Context *s, const uint8_t *buf,
int buf_size, int *golden_frame);
diff --git a/libavcodec/vp56data.c b/libavcodec/vp56data.c
index 7a418761d1..a161f885d9 100644
--- a/libavcodec/vp56data.c
+++ b/libavcodec/vp56data.c
@@ -1,26 +1,28 @@
-/**
- * @file
- * VP5 and VP6 compatible video decoder (common data)
- *
+/*
* Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+/**
+ * @file
+ * VP5 and VP6 compatible video decoder (common data)
+ */
+
#include "vp56data.h"
const uint8_t vp56_b2p[] = { 0, 0, 0, 0, 1, 2, 3, 3, 3, 3 };
diff --git a/libavcodec/vp56data.h b/libavcodec/vp56data.h
index 7be5921e9f..cb9cf95998 100644
--- a/libavcodec/vp56data.h
+++ b/libavcodec/vp56data.h
@@ -1,26 +1,28 @@
-/**
- * @file
- * VP5 and VP6 compatible video decoder (common data)
- *
+/*
* Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+/**
+ * @file
+ * VP5 and VP6 compatible video decoder (common data)
+ */
+
#ifndef AVCODEC_VP56DATA_H
#define AVCODEC_VP56DATA_H
diff --git a/libavcodec/vp56dsp.c b/libavcodec/vp56dsp.c
index 7b4a771676..c629343a8b 100644
--- a/libavcodec/vp56dsp.c
+++ b/libavcodec/vp56dsp.c
@@ -2,20 +2,20 @@
* Copyright (c) 2006 Aurelien Jacobs <aurel@gnuage.org>
* Copyright (c) 2010 Mans Rullgard <mans@mansr.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/vp56dsp.h b/libavcodec/vp56dsp.h
index 3bd6d27068..74a9cb5309 100644
--- a/libavcodec/vp56dsp.h
+++ b/libavcodec/vp56dsp.h
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2010 Mans Rullgard <mans@mansr.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/vp56rac.c b/libavcodec/vp56rac.c
index c009cadb94..f11531de24 100644
--- a/libavcodec/vp56rac.c
+++ b/libavcodec/vp56rac.c
@@ -2,20 +2,20 @@
* VP5/6/8 decoder
* Copyright (c) 2010 Jason Garrett-Glaser <darkshikari@gmail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/vp5data.h b/libavcodec/vp5data.h
index 11144a31ad..e16ff2da4b 100644
--- a/libavcodec/vp5data.h
+++ b/libavcodec/vp5data.h
@@ -1,26 +1,28 @@
-/**
- * @file
- * VP5 compatible video decoder
- *
+/*
* Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+/**
+ * @file
+ * VP5 compatible video decoder
+ */
+
#ifndef AVCODEC_VP5DATA_H
#define AVCODEC_VP5DATA_H
diff --git a/libavcodec/vp6.c b/libavcodec/vp6.c
index 4f3f402c70..a95e4be5b2 100644
--- a/libavcodec/vp6.c
+++ b/libavcodec/vp6.c
@@ -1,30 +1,32 @@
-/**
- * @file
- * VP6 compatible video decoder
- *
+/*
* Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org>
*
- * The VP6F decoder accepts an optional 1 byte extradata. It is composed of:
- * - upper 4bits: difference between encoded width and visible width
- * - lower 4bits: difference between encoded height and visible height
- *
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+/**
+ * @file
+ * VP6 compatible video decoder
+ *
+ * The VP6F decoder accepts an optional 1 byte extradata. It is composed of:
+ * - upper 4 bits: difference between encoded width and visible width
+ * - lower 4 bits: difference between encoded height and visible height
+ */
+
#include <stdlib.h>
#include "avcodec.h"
@@ -137,8 +139,11 @@ static int vp6_parse_header(VP56Context *s, const uint8_t *buf, int buf_size,
if (coeff_offset) {
buf += coeff_offset;
buf_size -= coeff_offset;
- if (buf_size < 0)
+ if (buf_size < 0) {
+ if (s->framep[VP56_FRAME_CURRENT]->key_frame)
+ avcodec_set_dimensions(s->avctx, 0, 0);
return 0;
+ }
if (s->use_huffman) {
s->parse_coeff = vp6_parse_coeff_huffman;
init_get_bits(&s->gb, buf, buf_size<<3);
@@ -213,8 +218,8 @@ static int vp6_huff_cmp(const void *va, const void *vb)
return (a->count - b->count)*16 + (b->sym - a->sym);
}
-static void vp6_build_huff_tree(VP56Context *s, uint8_t coeff_model[],
- const uint8_t *map, unsigned size, VLC *vlc)
+static int vp6_build_huff_tree(VP56Context *s, uint8_t coeff_model[],
+ const uint8_t *map, unsigned size, VLC *vlc)
{
Node nodes[2*VP6_MAX_HUFF_SIZE], *tmp = &nodes[size];
int a, b, i;
@@ -229,12 +234,12 @@ static void vp6_build_huff_tree(VP56Context *s, uint8_t coeff_model[],
}
free_vlc(vlc);
- /* then build the huffman tree accodring to probabilities */
- ff_huff_build_tree(s->avctx, vlc, size, nodes, vp6_huff_cmp,
- FF_HUFFMAN_FLAG_HNODE_FIRST);
+ /* then build the huffman tree according to probabilities */
+ return ff_huff_build_tree(s->avctx, vlc, size, nodes, vp6_huff_cmp,
+ FF_HUFFMAN_FLAG_HNODE_FIRST);
}
-static void vp6_parse_coeff_models(VP56Context *s)
+static int vp6_parse_coeff_models(VP56Context *s)
{
VP56RangeCoder *c = &s->c;
VP56Model *model = s->modelp;
@@ -279,15 +284,18 @@ static void vp6_parse_coeff_models(VP56Context *s)
if (s->use_huffman) {
for (pt=0; pt<2; pt++) {
- vp6_build_huff_tree(s, model->coeff_dccv[pt],
- vp6_huff_coeff_map, 12, &s->dccv_vlc[pt]);
- vp6_build_huff_tree(s, model->coeff_runv[pt],
- vp6_huff_run_map, 9, &s->runv_vlc[pt]);
+ if (vp6_build_huff_tree(s, model->coeff_dccv[pt],
+ vp6_huff_coeff_map, 12, &s->dccv_vlc[pt]))
+ return -1;
+ if (vp6_build_huff_tree(s, model->coeff_runv[pt],
+ vp6_huff_run_map, 9, &s->runv_vlc[pt]))
+ return -1;
for (ct=0; ct<3; ct++)
for (cg = 0; cg < 6; cg++)
- vp6_build_huff_tree(s, model->coeff_ract[pt][ct][cg],
- vp6_huff_coeff_map, 12,
- &s->ract_vlc[pt][ct][cg]);
+ if (vp6_build_huff_tree(s, model->coeff_ract[pt][ct][cg],
+ vp6_huff_coeff_map, 12,
+ &s->ract_vlc[pt][ct][cg]))
+ return -1;
}
memset(s->nb_null, 0, sizeof(s->nb_null));
} else {
@@ -297,6 +305,7 @@ static void vp6_parse_coeff_models(VP56Context *s)
for (node=0; node<5; node++)
model->coeff_dcct[pt][ctx][node] = av_clip(((model->coeff_dccv[pt][node] * vp6_dccv_lc[ctx][node][0] + 128) >> 8) + vp6_dccv_lc[ctx][node][1], 1, 255);
}
+ return 0;
}
static void vp6_parse_vector_adjustment(VP56Context *s, VP56mv *vect)
@@ -607,42 +616,39 @@ static av_cold int vp6_decode_free(AVCodecContext *avctx)
}
AVCodec ff_vp6_decoder = {
- "vp6",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_VP6,
- sizeof(VP56Context),
- vp6_decode_init,
- NULL,
- vp6_decode_free,
- ff_vp56_decode_frame,
- CODEC_CAP_DR1,
+ .name = "vp6",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_VP6,
+ .priv_data_size = sizeof(VP56Context),
+ .init = vp6_decode_init,
+ .close = vp6_decode_free,
+ .decode = ff_vp56_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("On2 VP6"),
};
/* flash version, not flipped upside-down */
AVCodec ff_vp6f_decoder = {
- "vp6f",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_VP6F,
- sizeof(VP56Context),
- vp6_decode_init,
- NULL,
- vp6_decode_free,
- ff_vp56_decode_frame,
- CODEC_CAP_DR1,
+ .name = "vp6f",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_VP6F,
+ .priv_data_size = sizeof(VP56Context),
+ .init = vp6_decode_init,
+ .close = vp6_decode_free,
+ .decode = ff_vp56_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("On2 VP6 (Flash version)"),
};
/* flash version, not flipped upside-down, with alpha channel */
AVCodec ff_vp6a_decoder = {
- "vp6a",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_VP6A,
- sizeof(VP56Context),
- vp6_decode_init,
- NULL,
- vp6_decode_free,
- ff_vp56_decode_frame,
- CODEC_CAP_DR1,
+ .name = "vp6a",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_VP6A,
+ .priv_data_size = sizeof(VP56Context),
+ .init = vp6_decode_init,
+ .close = vp6_decode_free,
+ .decode = ff_vp56_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("On2 VP6 (Flash version, with alpha channel)"),
};
diff --git a/libavcodec/vp6data.h b/libavcodec/vp6data.h
index 2ba3ef3860..3ebfd0e252 100644
--- a/libavcodec/vp6data.h
+++ b/libavcodec/vp6data.h
@@ -1,26 +1,28 @@
-/**
- * @file
- * VP6 compatible video decoder
- *
+/*
* Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+/**
+ * @file
+ * VP6 compatible video decoder
+ */
+
#ifndef AVCODEC_VP6DATA_H
#define AVCODEC_VP6DATA_H
diff --git a/libavcodec/vp6dsp.c b/libavcodec/vp6dsp.c
index 64282a5b3f..67c6be07de 100644
--- a/libavcodec/vp6dsp.c
+++ b/libavcodec/vp6dsp.c
@@ -1,26 +1,28 @@
-/**
- * @file
- * VP6 DSP-oriented functions
- *
+/*
* Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+/**
+ * @file
+ * VP6 DSP-oriented functions
+ */
+
#include "libavutil/common.h"
#include "vp56dsp.h"
diff --git a/libavcodec/vp8.c b/libavcodec/vp8.c
index e8d3621ea7..8c0380315e 100644
--- a/libavcodec/vp8.c
+++ b/libavcodec/vp8.c
@@ -5,20 +5,20 @@
* Copyright (C) 2010 Ronald S. Bultje
* Copyright (C) 2010 Jason Garrett-Glaser
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -33,27 +33,65 @@
# include "arm/vp8.h"
#endif
-static void vp8_decode_flush(AVCodecContext *avctx)
+static void free_buffers(VP8Context *s)
+{
+ av_freep(&s->macroblocks_base);
+ av_freep(&s->filter_strength);
+ av_freep(&s->intra4x4_pred_mode_top);
+ av_freep(&s->top_nnz);
+ av_freep(&s->edge_emu_buffer);
+ av_freep(&s->top_border);
+
+ s->macroblocks = NULL;
+}
+
+static int vp8_alloc_frame(VP8Context *s, AVFrame *f)
+{
+ int ret;
+ if ((ret = ff_thread_get_buffer(s->avctx, f)) < 0)
+ return ret;
+ if (!s->maps_are_invalid && s->num_maps_to_be_freed) {
+ f->ref_index[0] = s->segmentation_maps[--s->num_maps_to_be_freed];
+ } else if (!(f->ref_index[0] = av_mallocz(s->mb_width * s->mb_height))) {
+ ff_thread_release_buffer(s->avctx, f);
+ return AVERROR(ENOMEM);
+ }
+ return 0;
+}
+
+static void vp8_release_frame(VP8Context *s, AVFrame *f, int is_close)
+{
+ if (!is_close) {
+ if (f->ref_index[0]) {
+ assert(s->num_maps_to_be_freed < FF_ARRAY_ELEMS(s->segmentation_maps));
+ s->segmentation_maps[s->num_maps_to_be_freed++] = f->ref_index[0];
+ f->ref_index[0] = NULL;
+ }
+ } else {
+ av_freep(&f->ref_index[0]);
+ }
+ ff_thread_release_buffer(s->avctx, f);
+}
+
+static void vp8_decode_flush_impl(AVCodecContext *avctx, int force, int is_close)
{
VP8Context *s = avctx->priv_data;
int i;
- if (!avctx->is_copy) {
+ if (!avctx->is_copy || force) {
for (i = 0; i < 5; i++)
if (s->frames[i].data[0])
- ff_thread_release_buffer(avctx, &s->frames[i]);
+ vp8_release_frame(s, &s->frames[i], is_close);
}
memset(s->framep, 0, sizeof(s->framep));
- av_freep(&s->macroblocks_base);
- av_freep(&s->filter_strength);
- av_freep(&s->intra4x4_pred_mode_top);
- av_freep(&s->top_nnz);
- av_freep(&s->edge_emu_buffer);
- av_freep(&s->top_border);
- av_freep(&s->segmentation_map);
+ free_buffers(s);
+ s->maps_are_invalid = 1;
+}
- s->macroblocks = NULL;
+static void vp8_decode_flush(AVCodecContext *avctx)
+{
+ vp8_decode_flush_impl(avctx, 0, 0);
}
static int update_dimensions(VP8Context *s, int width, int height)
@@ -63,7 +101,7 @@ static int update_dimensions(VP8Context *s, int width, int height)
if (av_image_check_size(width, height, 0, s->avctx))
return AVERROR_INVALIDDATA;
- vp8_decode_flush(s->avctx);
+ vp8_decode_flush_impl(s->avctx, 1, 0);
avcodec_set_dimensions(s->avctx, width, height);
}
@@ -76,10 +114,9 @@ static int update_dimensions(VP8Context *s, int width, int height)
s->intra4x4_pred_mode_top = av_mallocz(s->mb_width*4);
s->top_nnz = av_mallocz(s->mb_width*sizeof(*s->top_nnz));
s->top_border = av_mallocz((s->mb_width+1)*sizeof(*s->top_border));
- s->segmentation_map = av_mallocz(s->mb_width*s->mb_height);
if (!s->macroblocks_base || !s->filter_strength || !s->intra4x4_pred_mode_top ||
- !s->top_nnz || !s->top_border || !s->segmentation_map)
+ !s->top_nnz || !s->top_border)
return AVERROR(ENOMEM);
s->macroblocks = s->macroblocks_base + 1;
@@ -273,7 +310,7 @@ static int decode_frame_header(VP8Context *s, const uint8_t *buf, int buf_size)
if (!s->macroblocks_base || /* first frame */
width != s->avctx->width || height != s->avctx->height) {
- if ((ret = update_dimensions(s, width, height) < 0))
+ if ((ret = update_dimensions(s, width, height)) < 0)
return ret;
}
@@ -487,6 +524,7 @@ void decode_mvs(VP8Context *s, VP8Macroblock *mb, int mb_x, int mb_y)
AV_ZERO32(&near_mv[0]);
AV_ZERO32(&near_mv[1]);
+ AV_ZERO32(&near_mv[2]);
/* Process MB on top, left and top-left */
#define MV_EDGE_CHECK(n)\
@@ -919,7 +957,8 @@ void intra_predict(VP8Context *s, uint8_t *dst[3], VP8Macroblock *mb,
int mb_x, int mb_y)
{
AVCodecContext *avctx = s->avctx;
- int x, y, mode, nnz, tr;
+ int x, y, mode, nnz;
+ uint32_t tr;
// for the first row, we need to run xchg_mb_border to init the top edge to 127
// otherwise, skip it if we aren't going to deblock
@@ -948,7 +987,7 @@ void intra_predict(VP8Context *s, uint8_t *dst[3], VP8Macroblock *mb,
// from the top macroblock
if (!(!mb_y && avctx->flags & CODEC_FLAG_EMU_EDGE) &&
mb_x == s->mb_width-1) {
- tr = tr_right[-1]*0x01010101;
+ tr = tr_right[-1]*0x01010101u;
tr_right = (uint8_t *)&tr;
}
@@ -1501,6 +1540,14 @@ static void filter_mb_row_simple(VP8Context *s, AVFrame *curframe, int mb_y)
}
}
+static void release_queued_segmaps(VP8Context *s, int is_close)
+{
+ int leave_behind = is_close ? 0 : !s->maps_are_invalid;
+ while (s->num_maps_to_be_freed > leave_behind)
+ av_freep(&s->segmentation_maps[--s->num_maps_to_be_freed]);
+ s->maps_are_invalid = 0;
+}
+
static int vp8_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
AVPacket *avpkt)
{
@@ -1509,6 +1556,8 @@ static int vp8_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
enum AVDiscard skip_thresh;
AVFrame *av_uninit(curframe), *prev_frame = s->framep[VP56_FRAME_CURRENT];
+ release_queued_segmaps(s, 0);
+
if ((ret = decode_frame_header(s, avpkt->data, avpkt->size)) < 0)
return ret;
@@ -1531,7 +1580,7 @@ static int vp8_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
&s->frames[i] != s->framep[VP56_FRAME_PREVIOUS] &&
&s->frames[i] != s->framep[VP56_FRAME_GOLDEN] &&
&s->frames[i] != s->framep[VP56_FRAME_GOLDEN2])
- ff_thread_release_buffer(avctx, &s->frames[i]);
+ vp8_release_frame(s, &s->frames[i], 0);
// find a free buffer
for (i = 0; i < 5; i++)
@@ -1552,8 +1601,7 @@ static int vp8_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
curframe->key_frame = s->keyframe;
curframe->pict_type = s->keyframe ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;
curframe->reference = referenced ? 3 : 0;
- curframe->ref_index[0] = s->segmentation_map;
- if ((ret = ff_thread_get_buffer(avctx, curframe))) {
+ if ((ret = vp8_alloc_frame(s, curframe))) {
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed!\n");
return ret;
}
@@ -1645,8 +1693,8 @@ static int vp8_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
s->dsp.prefetch(dst[0] + (mb_x&3)*4*s->linesize + 64, s->linesize, 4);
s->dsp.prefetch(dst[1] + (mb_x&7)*s->uvlinesize + 64, dst[2] - dst[1], 2);
- decode_mb_mode(s, mb, mb_x, mb_y, s->segmentation_map + mb_xy,
- prev_frame ? prev_frame->ref_index[0] + mb_xy : NULL);
+ decode_mb_mode(s, mb, mb_x, mb_y, curframe->ref_index[0] + mb_xy,
+ prev_frame && prev_frame->ref_index[0] ? prev_frame->ref_index[0] + mb_xy : NULL);
prefetch_motion(s, mb, mb_x, mb_y, mb_xy, VP56_FRAME_PREVIOUS);
@@ -1721,7 +1769,7 @@ static av_cold int vp8_decode_init(AVCodecContext *avctx)
avctx->pix_fmt = PIX_FMT_YUV420P;
dsputil_init(&s->dsp, avctx);
- ff_h264_pred_init(&s->hpc, CODEC_ID_VP8, 8);
+ ff_h264_pred_init(&s->hpc, CODEC_ID_VP8, 8, 1);
ff_vp8dsp_init(&s->vp8dsp);
return 0;
@@ -1729,7 +1777,8 @@ static av_cold int vp8_decode_init(AVCodecContext *avctx)
static av_cold int vp8_decode_free(AVCodecContext *avctx)
{
- vp8_decode_flush(avctx);
+ vp8_decode_flush_impl(avctx, 0, 1);
+ release_queued_segmaps(avctx->priv_data, 1);
return 0;
}
@@ -1749,6 +1798,11 @@ static int vp8_decode_update_thread_context(AVCodecContext *dst, const AVCodecCo
{
VP8Context *s = dst->priv_data, *s_src = src->priv_data;
+ if (s->macroblocks_base &&
+ (s_src->mb_width != s->mb_width || s_src->mb_height != s->mb_height)) {
+ free_buffers(s);
+ }
+
s->prob[0] = s_src->prob[!s_src->update_probabilities];
s->segmentation = s_src->segmentation;
s->lf_delta = s_src->lf_delta;
@@ -1764,15 +1818,14 @@ static int vp8_decode_update_thread_context(AVCodecContext *dst, const AVCodecCo
}
AVCodec ff_vp8_decoder = {
- "vp8",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_VP8,
- sizeof(VP8Context),
- vp8_decode_init,
- NULL,
- vp8_decode_free,
- vp8_decode_frame,
- CODEC_CAP_DR1 | CODEC_CAP_FRAME_THREADS,
+ .name = "vp8",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_VP8,
+ .priv_data_size = sizeof(VP8Context),
+ .init = vp8_decode_init,
+ .close = vp8_decode_free,
+ .decode = vp8_decode_frame,
+ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_FRAME_THREADS,
.flush = vp8_decode_flush,
.long_name = NULL_IF_CONFIG_SMALL("On2 VP8"),
.init_thread_copy = ONLY_IF_THREADS_ENABLED(vp8_decode_init_thread_copy),
diff --git a/libavcodec/vp8.h b/libavcodec/vp8.h
index 5a96cd436c..36c21df217 100644
--- a/libavcodec/vp8.h
+++ b/libavcodec/vp8.h
@@ -5,20 +5,20 @@
* Copyright (C) 2010 Ronald S. Bultje
* Copyright (C) 2010 Jason Garrett-Glaser
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -130,7 +130,6 @@ typedef struct {
uint8_t *intra4x4_pred_mode_top;
uint8_t intra4x4_pred_mode_left[4];
- uint8_t *segmentation_map;
/**
* Macroblocks can have one of 4 different quants in a frame when
@@ -237,6 +236,16 @@ typedef struct {
H264PredContext hpc;
vp8_mc_func put_pixels_tab[3][3][3];
AVFrame frames[5];
+
+ /**
+ * A list of segmentation_map buffers that are to be free()'ed in
+ * the next decoding iteration. We can't free() them right away
+ * because the map may still be used by subsequent decoding threads.
+ * Unused if frame threading is off.
+ */
+ uint8_t *segmentation_maps[5];
+ int num_maps_to_be_freed;
+ int maps_are_invalid;
} VP8Context;
#endif /* AVCODEC_VP8_H */
diff --git a/libavcodec/vp8_parser.c b/libavcodec/vp8_parser.c
index fbdd0ee5ac..aebf667e73 100644
--- a/libavcodec/vp8_parser.c
+++ b/libavcodec/vp8_parser.c
@@ -1,20 +1,20 @@
/*
* Copyright (C) 2008 Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/vp8data.h b/libavcodec/vp8data.h
index 4ea4581bc9..0ea24d7ed8 100644
--- a/libavcodec/vp8data.h
+++ b/libavcodec/vp8data.h
@@ -1,26 +1,29 @@
-/**
- * VP8 compatible video decoder
- *
+/*
* Copyright (C) 2010 David Conrad
* Copyright (C) 2010 Ronald S. Bultje
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+/**
+ * @file
+ * VP8 compatible video decoder
+ */
+
#ifndef AVCODEC_VP8DATA_H
#define AVCODEC_VP8DATA_H
diff --git a/libavcodec/vp8dsp.c b/libavcodec/vp8dsp.c
index 159c070670..ce90675d87 100644
--- a/libavcodec/vp8dsp.c
+++ b/libavcodec/vp8dsp.c
@@ -1,26 +1,29 @@
-/**
- * VP8 compatible video decoder
- *
+/*
* Copyright (C) 2010 David Conrad
* Copyright (C) 2010 Ronald S. Bultje
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+/**
+ * @file
+ * VP8 compatible video decoder
+ */
+
#include "dsputil.h"
#include "vp8dsp.h"
diff --git a/libavcodec/vp8dsp.h b/libavcodec/vp8dsp.h
index e2fb8e7cbb..987fa59a72 100644
--- a/libavcodec/vp8dsp.h
+++ b/libavcodec/vp8dsp.h
@@ -1,26 +1,28 @@
-/**
- * VP8 compatible video decoder
- *
+/*
* Copyright (C) 2010 David Conrad
* Copyright (C) 2010 Ronald S. Bultje
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+/**
+ * @file
+ * VP8 compatible video decoder
+ */
#ifndef AVCODEC_VP8DSP_H
#define AVCODEC_VP8DSP_H
diff --git a/libavcodec/vqavideo.c b/libavcodec/vqavideo.c
index caffddbfa4..8b57d79dbc 100644
--- a/libavcodec/vqavideo.c
+++ b/libavcodec/vqavideo.c
@@ -2,28 +2,28 @@
* Westwood Studios VQA Video Decoder
* Copyright (C) 2003 the ffmpeg project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
- * VQA Video Decoder by Mike Melanson (melanson@pcisys.net)
- * For more information about the VQA format, visit:
- * http://wiki.multimedia.cx/index.php?title=VQA
+ * VQA Video Decoder
+ * @author Mike Melanson (melanson@pcisys.net)
+ * @see http://wiki.multimedia.cx/index.php?title=VQA
*
* The VQA video decoder outputs PAL8 or RGB555 colorspace data, depending
* on the type of data in the file.
@@ -138,6 +138,10 @@ static av_cold int vqa_decode_init(AVCodecContext *avctx)
/* load up the VQA parameters from the header */
vqa_header = (unsigned char *)s->avctx->extradata;
s->vqa_version = vqa_header[0];
+ if (s->vqa_version < 1 || s->vqa_version > 3) {
+ av_log(s->avctx, AV_LOG_ERROR, " VQA video: unsupported version %d\n", s->vqa_version);
+ return -1;
+ }
s->width = AV_RL16(&vqa_header[6]);
s->height = AV_RL16(&vqa_header[8]);
if(av_image_check_size(s->width, s->height, 0, avctx)){
@@ -179,6 +183,7 @@ static av_cold int vqa_decode_init(AVCodecContext *avctx)
(s->height / s->vector_height) * 2;
s->decode_buffer = av_malloc(s->decode_buffer_size);
+ avcodec_get_frame_defaults(&s->frame);
s->frame.data[0] = NULL;
return 0;
@@ -225,6 +230,8 @@ static void decode_format80(const unsigned char *src, int src_size,
src_index += 2;
av_dlog(NULL, "(1) copy %X bytes from absolute pos %X\n", count, src_pos);
CHECK_COUNT();
+ if (src_pos + count > dest_size)
+ return;
for (i = 0; i < count; i++)
dest[dest_index + i] = dest[src_pos + i];
dest_index += count;
@@ -247,6 +254,8 @@ static void decode_format80(const unsigned char *src, int src_size,
src_index += 2;
av_dlog(NULL, "(3) copy %X bytes from absolute pos %X\n", count, src_pos);
CHECK_COUNT();
+ if (src_pos + count > dest_size)
+ return;
for (i = 0; i < count; i++)
dest[dest_index + i] = dest[src_pos + i];
dest_index += count;
@@ -267,6 +276,8 @@ static void decode_format80(const unsigned char *src, int src_size,
src_index += 2;
av_dlog(NULL, "(5) copy %X bytes from relpos %X\n", count, src_pos);
CHECK_COUNT();
+ if (dest_index < src_pos)
+ return;
for (i = 0; i < count; i++)
dest[dest_index + i] = dest[dest_index - src_pos + i];
dest_index += count;
@@ -600,14 +611,13 @@ static av_cold int vqa_decode_end(AVCodecContext *avctx)
}
AVCodec ff_vqa_decoder = {
- "vqavideo",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_WS_VQA,
- sizeof(VqaContext),
- vqa_decode_init,
- NULL,
- vqa_decode_end,
- vqa_decode_frame,
- CODEC_CAP_DR1,
+ .name = "vqavideo",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_WS_VQA,
+ .priv_data_size = sizeof(VqaContext),
+ .init = vqa_decode_init,
+ .close = vqa_decode_end,
+ .decode = vqa_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Westwood Studios VQA (Vector Quantized Animation) video"),
};
diff --git a/libavcodec/w32pthreads.h b/libavcodec/w32pthreads.h
new file mode 100644
index 0000000000..7774817518
--- /dev/null
+++ b/libavcodec/w32pthreads.h
@@ -0,0 +1,207 @@
+/*
+ * Copyright (C) 2010-2011 x264 project
+ *
+ * Authors: Steven Walters <kemuri9@gmail.com>
+ * Pegasys Inc. <http://www.pegasys-inc.com>
+ *
+ * This file is part of Libav.
+ *
+ * Libav 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.
+ *
+ * Libav 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * w32threads to pthreads wrapper
+ */
+
+#ifndef AVCODEC_W32PTHREADS_H
+#define AVCODEC_W32PTHREADS_H
+
+/* Build up a pthread-like API using underlying Windows API. Have only static
+ * methods so as to not conflict with a potentially linked in pthread-win32
+ * library.
+ * As most functions here are used without checking return values,
+ * only implement return values as necessary. */
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include <process.h>
+
+typedef struct {
+ void *handle;
+ void *(*func)(void* arg);
+ void *arg;
+ void *ret;
+} pthread_t;
+
+/* the conditional variable api for windows 6.0+ uses critical sections and
+ * not mutexes */
+typedef CRITICAL_SECTION pthread_mutex_t;
+
+/* This is the CONDITIONAL_VARIABLE typedef for using Window's native
+ * conditional variables on kernels 6.0+.
+ * MinGW does not currently have this typedef. */
+typedef struct {
+ void *ptr;
+} pthread_cond_t;
+
+/* function pointers to conditional variable API on windows 6.0+ kernels */
+static void (WINAPI *cond_broadcast)(pthread_cond_t *cond);
+static void (WINAPI *cond_init)(pthread_cond_t *cond);
+static void (WINAPI *cond_signal)(pthread_cond_t *cond);
+static BOOL (WINAPI *cond_wait)(pthread_cond_t *cond, pthread_mutex_t *mutex,
+ DWORD milliseconds);
+
+static unsigned __stdcall attribute_align_arg win32thread_worker(void *arg)
+{
+ pthread_t *h = arg;
+ h->ret = h->func(h->arg);
+ return 0;
+}
+
+static int pthread_create(pthread_t *thread, const void *unused_attr,
+ void *(*start_routine)(void*), void *arg)
+{
+ thread->func = start_routine;
+ thread->arg = arg;
+ thread->handle = (void*)_beginthreadex(NULL, 0, win32thread_worker, thread,
+ 0, NULL);
+ return !thread->handle;
+}
+
+static void pthread_join(pthread_t thread, void **value_ptr)
+{
+ DWORD ret = WaitForSingleObject(thread.handle, INFINITE);
+ if (ret != WAIT_OBJECT_0)
+ return;
+ if (value_ptr)
+ *value_ptr = thread.ret;
+ CloseHandle(thread.handle);
+}
+
+#define pthread_mutex_init(m, a) InitializeCriticalSection(m)
+#define pthread_mutex_destroy(m) DeleteCriticalSection(m)
+#define pthread_mutex_lock(m) EnterCriticalSection(m)
+#define pthread_mutex_unlock(m) LeaveCriticalSection(m)
+
+/* for pre-Windows 6.0 platforms we need to define and use our own condition
+ * variable and api */
+typedef struct {
+ pthread_mutex_t mtx_waiter_count;
+ volatile int waiter_count;
+ HANDLE semaphore;
+} win32_cond_t;
+
+static void pthread_cond_init(pthread_cond_t *cond, const void *unused_attr)
+{
+ win32_cond_t *win32_cond = NULL;
+ if (cond_init) {
+ cond_init(cond);
+ return;
+ }
+
+ /* non native condition variables */
+ win32_cond = av_mallocz(sizeof(win32_cond_t));
+ if (!win32_cond)
+ return;
+ cond->ptr = win32_cond;
+ win32_cond->semaphore = CreateSemaphore(NULL, 0, 0x7fffffff, NULL);
+ if (!win32_cond->semaphore)
+ return;
+
+ pthread_mutex_init(&win32_cond->mtx_waiter_count, NULL);
+}
+
+static void pthread_cond_destroy(pthread_cond_t *cond)
+{
+ win32_cond_t *win32_cond = cond->ptr;
+ /* native condition variables do not destroy */
+ if (cond_init)
+ return;
+
+ /* non native condition variables */
+ CloseHandle(win32_cond->semaphore);
+ pthread_mutex_destroy(&win32_cond->mtx_waiter_count);
+ av_freep(&win32_cond);
+ cond->ptr = NULL;
+}
+
+static void pthread_cond_broadcast(pthread_cond_t *cond)
+{
+ win32_cond_t *win32_cond = cond->ptr;
+ if (cond_broadcast) {
+ cond_broadcast(cond);
+ return;
+ }
+
+ /* non native condition variables */
+ pthread_mutex_lock(&win32_cond->mtx_waiter_count);
+ if (win32_cond->waiter_count) {
+ ReleaseSemaphore(win32_cond->semaphore, win32_cond->waiter_count, NULL);
+ win32_cond->waiter_count = 0;
+ }
+ pthread_mutex_unlock(&win32_cond->mtx_waiter_count);
+}
+
+static void pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
+{
+ win32_cond_t *win32_cond = cond->ptr;
+ if (cond_wait) {
+ cond_wait(cond, mutex, INFINITE);
+ return;
+ }
+
+ /* non native condition variables */
+ pthread_mutex_lock(&win32_cond->mtx_waiter_count);
+ win32_cond->waiter_count++;
+ pthread_mutex_unlock(&win32_cond->mtx_waiter_count);
+
+ pthread_mutex_unlock(mutex);
+ WaitForSingleObject(win32_cond->semaphore, INFINITE);
+ pthread_mutex_lock(mutex);
+}
+
+static void pthread_cond_signal(pthread_cond_t *cond)
+{
+ win32_cond_t *win32_cond = cond->ptr;
+ if (cond_signal) {
+ cond_signal(cond);
+ return;
+ }
+
+ /* non-native condition variables */
+ pthread_mutex_lock(&win32_cond->mtx_waiter_count);
+ if (win32_cond->waiter_count) {
+ ReleaseSemaphore(win32_cond->semaphore, 1, NULL);
+ win32_cond->waiter_count--;
+ }
+ pthread_mutex_unlock(&win32_cond->mtx_waiter_count);
+}
+
+static void w32thread_init(void)
+{
+ HANDLE kernel_dll = GetModuleHandle(TEXT("kernel32.dll"));
+ /* if one is available, then they should all be available */
+ cond_init =
+ (void*)GetProcAddress(kernel_dll, "InitializeConditionVariable");
+ cond_broadcast =
+ (void*)GetProcAddress(kernel_dll, "WakeAllConditionVariable");
+ cond_signal =
+ (void*)GetProcAddress(kernel_dll, "WakeConditionVariable");
+ cond_wait =
+ (void*)GetProcAddress(kernel_dll, "SleepConditionVariableCS");
+}
+
+#endif /* AVCODEC_W32PTHREADS_H */
diff --git a/libavcodec/w32thread.c b/libavcodec/w32thread.c
deleted file mode 100644
index 023be0e663..0000000000
--- a/libavcodec/w32thread.c
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
- * Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
- *
- * This file is part of Libav.
- *
- * Libav 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.
- *
- * Libav 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-//#define DEBUG
-
-#include "avcodec.h"
-#include "thread.h"
-
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
-#include <process.h>
-
-typedef struct ThreadContext{
- AVCodecContext *avctx;
- HANDLE thread;
- HANDLE work_sem;
- HANDLE job_sem;
- HANDLE done_sem;
- int (*func)(AVCodecContext *c, void *arg);
- int (*func2)(AVCodecContext *c, void *arg, int, int);
- void *arg;
- int argsize;
- int *jobnr;
- int *ret;
- int threadnr;
-}ThreadContext;
-
-
-static unsigned WINAPI attribute_align_arg thread_func(void *v){
- ThreadContext *c= v;
-
- for(;;){
- int ret, jobnr;
-//printf("thread_func %X enter wait\n", (int)v); fflush(stdout);
- WaitForSingleObject(c->work_sem, INFINITE);
- // avoid trying to access jobnr if we should quit
- if (!c->func && !c->func2)
- break;
- WaitForSingleObject(c->job_sem, INFINITE);
- jobnr = (*c->jobnr)++;
- ReleaseSemaphore(c->job_sem, 1, 0);
-//printf("thread_func %X after wait (func=%X)\n", (int)v, (int)c->func); fflush(stdout);
- if(c->func)
- ret= c->func(c->avctx, (uint8_t *)c->arg + jobnr*c->argsize);
- else
- ret= c->func2(c->avctx, c->arg, jobnr, c->threadnr);
- if (c->ret)
- c->ret[jobnr] = ret;
-//printf("thread_func %X signal complete\n", (int)v); fflush(stdout);
- ReleaseSemaphore(c->done_sem, 1, 0);
- }
-
- return 0;
-}
-
-/**
- * Free what has been allocated by ff_thread_init().
- * Must be called after decoding has finished, especially do not call while avcodec_thread_execute() is running.
- */
-void ff_thread_free(AVCodecContext *s){
- ThreadContext *c= s->thread_opaque;
- int i;
-
- for(i=0; i<s->thread_count; i++){
-
- c[i].func= NULL;
- c[i].func2= NULL;
- }
- ReleaseSemaphore(c[0].work_sem, s->thread_count, 0);
- for(i=0; i<s->thread_count; i++){
- WaitForSingleObject(c[i].thread, INFINITE);
- if(c[i].thread) CloseHandle(c[i].thread);
- }
- if(c[0].work_sem) CloseHandle(c[0].work_sem);
- if(c[0].job_sem) CloseHandle(c[0].job_sem);
- if(c[0].done_sem) CloseHandle(c[0].done_sem);
-
- av_freep(&s->thread_opaque);
-}
-
-static int avcodec_thread_execute(AVCodecContext *s, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size){
- ThreadContext *c= s->thread_opaque;
- int i;
- int jobnr = 0;
-
- assert(s == c->avctx);
-
- /* note, we can be certain that this is not called with the same AVCodecContext by different threads at the same time */
-
- for(i=0; i<s->thread_count; i++){
- c[i].arg= arg;
- c[i].argsize= size;
- c[i].func= func;
- c[i].ret= ret;
- c[i].jobnr = &jobnr;
- }
- ReleaseSemaphore(c[0].work_sem, count, 0);
- for(i=0; i<count; i++)
- WaitForSingleObject(c[0].done_sem, INFINITE);
-
- return 0;
-}
-
-static int avcodec_thread_execute2(AVCodecContext *s, int (*func)(AVCodecContext *c2, void *arg2, int, int),void *arg, int *ret, int count){
- ThreadContext *c= s->thread_opaque;
- int i;
- for(i=0; i<s->thread_count; i++)
- c[i].func2 = func;
- avcodec_thread_execute(s, NULL, arg, ret, count, 0);
-}
-
-int ff_thread_init(AVCodecContext *s){
- int i;
- ThreadContext *c;
- uint32_t threadid;
-
- if(!(s->thread_type & FF_THREAD_SLICE)){
- av_log(s, AV_LOG_WARNING, "The requested thread algorithm is not supported with this thread library.\n");
- return 0;
- }
-
- s->active_thread_type= FF_THREAD_SLICE;
-
- if (s->thread_count <= 1)
- return 0;
-
- assert(!s->thread_opaque);
- c= av_mallocz(sizeof(ThreadContext)*s->thread_count);
- s->thread_opaque= c;
- if(!(c[0].work_sem = CreateSemaphore(NULL, 0, INT_MAX, NULL)))
- goto fail;
- if(!(c[0].job_sem = CreateSemaphore(NULL, 1, 1, NULL)))
- goto fail;
- if(!(c[0].done_sem = CreateSemaphore(NULL, 0, INT_MAX, NULL)))
- goto fail;
-
- for(i=0; i<s->thread_count; i++){
-//printf("init semaphors %d\n", i); fflush(stdout);
- c[i].avctx= s;
- c[i].work_sem = c[0].work_sem;
- c[i].job_sem = c[0].job_sem;
- c[i].done_sem = c[0].done_sem;
- c[i].threadnr = i;
-
-//printf("create thread %d\n", i); fflush(stdout);
- c[i].thread = (HANDLE)_beginthreadex(NULL, 0, thread_func, &c[i], 0, &threadid );
- if( !c[i].thread ) goto fail;
- }
-//printf("init done\n"); fflush(stdout);
-
- s->execute= avcodec_thread_execute;
- s->execute2= avcodec_thread_execute2;
-
- return 0;
-fail:
- ff_thread_free(s);
- return -1;
-}
diff --git a/libavcodec/wavpack.c b/libavcodec/wavpack.c
index e4fe217f59..0a0d8ab23e 100644
--- a/libavcodec/wavpack.c
+++ b/libavcodec/wavpack.c
@@ -2,20 +2,20 @@
* WavPack lossless audio decoder
* Copyright (c) 2006,2011 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#define ALT_BITSTREAM_READER_LE
@@ -292,7 +292,14 @@ static int wv_get_value(WavpackFrameContext *ctx, GetBitContext *gb, int channel
}
}else{
t = get_unary_0_33(gb);
- if(t >= 2) t = get_bits(gb, t - 1) | (1 << (t-1));
+ if(t >= 2){
+ if(get_bits_left(gb) < t-1)
+ goto error;
+ t = get_bits(gb, t - 1) | (1 << (t-1));
+ }else{
+ if(get_bits_left(gb) < 0)
+ goto error;
+ }
ctx->zeroes = t;
if(ctx->zeroes){
memset(ctx->ch[0].median, 0, sizeof(ctx->ch[0].median));
@@ -303,24 +310,24 @@ static int wv_get_value(WavpackFrameContext *ctx, GetBitContext *gb, int channel
}
}
- if(get_bits_count(gb) >= ctx->data_size){
- *last = 1;
- return 0;
- }
-
if(ctx->zero){
t = 0;
ctx->zero = 0;
}else{
t = get_unary_0_33(gb);
- if(get_bits_count(gb) >= ctx->data_size){
- *last = 1;
- return 0;
- }
+ if(get_bits_left(gb) < 0)
+ goto error;
if(t == 16) {
t2 = get_unary_0_33(gb);
- if(t2 < 2) t += t2;
- else t += get_bits(gb, t2 - 1) | (1 << (t2 - 1));
+ if(t2 < 2){
+ if(get_bits_left(gb) < 0)
+ goto error;
+ t += t2;
+ }else{
+ if(get_bits_left(gb) < t2 - 1)
+ goto error;
+ t += get_bits(gb, t2 - 1) | (1 << (t2 - 1));
+ }
}
if(ctx->one){
@@ -360,9 +367,13 @@ static int wv_get_value(WavpackFrameContext *ctx, GetBitContext *gb, int channel
}
if(!c->error_limit){
ret = base + get_tail(gb, add);
+ if (get_bits_left(gb) <= 0)
+ goto error;
}else{
int mid = (base*2 + add + 1) >> 1;
while(add > c->error_limit){
+ if(get_bits_left(gb) <= 0)
+ goto error;
if(get_bits1(gb)){
add -= (mid - base);
base = mid;
@@ -376,6 +387,10 @@ static int wv_get_value(WavpackFrameContext *ctx, GetBitContext *gb, int channel
if(ctx->hybrid_bitrate)
c->slow_level += wp_log2(ret) - LEVEL_DECAY(c->slow_level);
return sign ? ~ret : ret;
+
+error:
+ *last = 1;
+ return 0;
}
static inline int wv_get_value_integer(WavpackFrameContext *s, uint32_t *crc, int S)
@@ -385,7 +400,7 @@ static inline int wv_get_value_integer(WavpackFrameContext *s, uint32_t *crc, in
if(s->extra_bits){
S <<= s->extra_bits;
- if(s->got_extra_bits){
+ if(s->got_extra_bits && get_bits_left(&s->gb_extra_bits) >= s->extra_bits){
S |= get_bits(&s->gb_extra_bits, s->extra_bits);
*crc = *crc * 9 + (S&0xffff) * 3 + ((unsigned)S>>16);
}
@@ -470,6 +485,7 @@ static float wv_get_value_float(WavpackFrameContext *s, uint32_t *crc, int S)
static void wv_reset_saved_context(WavpackFrameContext *s)
{
s->pos = 0;
+ s->samples_left = 0;
s->sc.crc = s->extra_sc.crc = 0xFFFFFFFF;
}
@@ -580,8 +596,12 @@ static inline int wv_unpack_stereo(WavpackFrameContext *s, GetBitContext *gb, vo
count++;
}while(!last && count < s->max_samples);
- s->samples_left -= count;
+ if (last)
+ s->samples_left = 0;
+ else
+ s->samples_left -= count;
if(!s->samples_left){
+ wv_reset_saved_context(s);
if(crc != s->CRC){
av_log(s->avctx, AV_LOG_ERROR, "CRC error\n");
return -1;
@@ -590,7 +610,6 @@ static inline int wv_unpack_stereo(WavpackFrameContext *s, GetBitContext *gb, vo
av_log(s->avctx, AV_LOG_ERROR, "Extra bits CRC error\n");
return -1;
}
- wv_reset_saved_context(s);
}else{
s->pos = pos;
s->sc.crc = crc;
@@ -658,8 +677,12 @@ static inline int wv_unpack_mono(WavpackFrameContext *s, GetBitContext *gb, void
count++;
}while(!last && count < s->max_samples);
- s->samples_left -= count;
+ if (last)
+ s->samples_left = 0;
+ else
+ s->samples_left -= count;
if(!s->samples_left){
+ wv_reset_saved_context(s);
if(crc != s->CRC){
av_log(s->avctx, AV_LOG_ERROR, "CRC error\n");
return -1;
@@ -668,7 +691,6 @@ static inline int wv_unpack_mono(WavpackFrameContext *s, GetBitContext *gb, void
av_log(s->avctx, AV_LOG_ERROR, "Extra bits CRC error\n");
return -1;
}
- wv_reset_saved_context(s);
}else{
s->pos = pos;
s->sc.crc = crc;
@@ -779,7 +801,7 @@ static int wavpack_decode_block(AVCodecContext *avctx, int block_no,
s->samples = AV_RL32(buf); buf += 4;
if(!s->samples){
*data_size = 0;
- return buf_size;
+ return 0;
}
}else{
s->samples = wc->samples;
@@ -841,12 +863,13 @@ static int wavpack_decode_block(AVCodecContext *avctx, int block_no,
}
switch(id & WP_IDF_MASK){
case WP_ID_DECTERMS:
- s->terms = size;
- if(s->terms > MAX_TERMS){
+ if(size > MAX_TERMS){
av_log(avctx, AV_LOG_ERROR, "Too many decorrelation terms\n");
+ s->terms = 0;
buf += ssize;
continue;
}
+ s->terms = size;
for(i = 0; i < s->terms; i++) {
s->decorr[s->terms - i - 1].value = (*buf & 0x1F) - 5;
s->decorr[s->terms - i - 1].delta = *buf >> 5;
@@ -1098,6 +1121,10 @@ static int wavpack_decode_block(AVCodecContext *avctx, int block_no,
samplecount = wv_unpack_stereo(s, &s->gb, samples, AV_SAMPLE_FMT_S32);
else
samplecount = wv_unpack_stereo(s, &s->gb, samples, AV_SAMPLE_FMT_FLT);
+
+ if (samplecount < 0)
+ return -1;
+
samplecount >>= 1;
}else{
const int channel_stride = avctx->channels;
@@ -1109,6 +1136,9 @@ static int wavpack_decode_block(AVCodecContext *avctx, int block_no,
else
samplecount = wv_unpack_mono(s, &s->gb, samples, AV_SAMPLE_FMT_FLT);
+ if (samplecount < 0)
+ return -1;
+
if(s->stereo && avctx->sample_fmt == AV_SAMPLE_FMT_S16){
int16_t *dst = (int16_t*)samples + 1;
int16_t *src = (int16_t*)samples;
@@ -1144,6 +1174,15 @@ static int wavpack_decode_block(AVCodecContext *avctx, int block_no,
return samplecount * bpp;
}
+static void wavpack_decode_flush(AVCodecContext *avctx)
+{
+ WavpackContext *s = avctx->priv_data;
+ int i;
+
+ for (i = 0; i < s->fdec_num; i++)
+ wv_reset_saved_context(s->fdec[i]);
+}
+
static int wavpack_decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
AVPacket *avpkt)
@@ -1176,11 +1215,14 @@ static int wavpack_decode_frame(AVCodecContext *avctx,
if(frame_size < 0 || frame_size > buf_size){
av_log(avctx, AV_LOG_ERROR, "Block %d has invalid size (size %d vs. %d bytes left)\n",
s->block, frame_size, buf_size);
+ wavpack_decode_flush(avctx);
return -1;
}
if((samplecount = wavpack_decode_block(avctx, s->block, data,
- data_size, buf, frame_size)) < 0)
+ data_size, buf, frame_size)) < 0) {
+ wavpack_decode_flush(avctx);
return -1;
+ }
s->block++;
buf += frame_size; buf_size -= frame_size;
}
@@ -1190,14 +1232,14 @@ static int wavpack_decode_frame(AVCodecContext *avctx,
}
AVCodec ff_wavpack_decoder = {
- "wavpack",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_WAVPACK,
- sizeof(WavpackContext),
- wavpack_decode_init,
- NULL,
- wavpack_decode_end,
- wavpack_decode_frame,
+ .name = "wavpack",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_WAVPACK,
+ .priv_data_size = sizeof(WavpackContext),
+ .init = wavpack_decode_init,
+ .close = wavpack_decode_end,
+ .decode = wavpack_decode_frame,
+ .flush = wavpack_decode_flush,
.capabilities = CODEC_CAP_SUBFRAMES,
.long_name = NULL_IF_CONFIG_SMALL("WavPack"),
};
diff --git a/libavcodec/wma.c b/libavcodec/wma.c
index bed47ec35b..67599b7eab 100644
--- a/libavcodec/wma.c
+++ b/libavcodec/wma.c
@@ -1,21 +1,21 @@
/*
* WMA compatible codec
- * Copyright (c) 2002-2007 The Libav Project
+ * Copyright (c) 2002-2007 The FFmpeg Project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/wma.h b/libavcodec/wma.h
index f11d5507dc..fd9d5d8d3b 100644
--- a/libavcodec/wma.h
+++ b/libavcodec/wma.h
@@ -1,21 +1,21 @@
/*
* WMA compatible codec
- * Copyright (c) 2002-2007 The Libav Project
+ * Copyright (c) 2002-2007 The FFmpeg Project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/wmadata.h b/libavcodec/wmadata.h
index 07a1afecc8..381f182fa0 100644
--- a/libavcodec/wmadata.h
+++ b/libavcodec/wmadata.h
@@ -1,21 +1,21 @@
/*
* WMA compatible decoder
- * copyright (c) 2002 The Libav Project
+ * copyright (c) 2002 The FFmpeg Project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/wmadec.c b/libavcodec/wmadec.c
index 479b34c3e0..b4a4c800af 100644
--- a/libavcodec/wmadec.c
+++ b/libavcodec/wmadec.c
@@ -1,21 +1,21 @@
/*
* WMA compatible decoder
- * Copyright (c) 2002 The Libav Project
+ * Copyright (c) 2002 The FFmpeg Project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -102,6 +102,13 @@ static int wma_decode_init(AVCodecContext * avctx)
s->use_bit_reservoir = flags2 & 0x0002;
s->use_variable_block_len = flags2 & 0x0004;
+ if(avctx->codec->id == CODEC_ID_WMAV2 && avctx->extradata_size >= 8){
+ if(AV_RL16(extradata+4)==0xd && s->use_variable_block_len){
+ av_log(avctx, AV_LOG_WARNING, "Disabling use_variable_block_len, if this fails contact the ffmpeg developers and send us the file\n");
+ s->use_variable_block_len= 0; // this fixes issue1503
+ }
+ }
+
if(ff_wma_init(avctx, flags2)<0)
return -1;
@@ -480,6 +487,11 @@ static int wma_decode_block(WMACodecContext *s)
s->block_len_bits = s->frame_len_bits;
}
+ if (s->frame_len_bits - s->block_len_bits >= s->nb_block_sizes){
+ av_log(s->avctx, AV_LOG_ERROR, "block_len_bits not initialized to a valid value\n");
+ return -1;
+ }
+
/* now check if the block length is coherent with the frame length */
s->block_len = 1 << s->block_len_bits;
if ((s->block_pos + s->block_len) > s->frame_len){
@@ -815,8 +827,9 @@ static int wma_decode_superframe(AVCodecContext *avctx,
return 0;
}
if (buf_size < s->block_align)
- return 0;
- buf_size = s->block_align;
+ return AVERROR(EINVAL);
+ if(s->block_align)
+ buf_size = s->block_align;
samples = data;
@@ -899,9 +912,8 @@ static int wma_decode_superframe(AVCodecContext *avctx,
}
//av_log(NULL, AV_LOG_ERROR, "%d %d %d %d outbytes:%d eaten:%d\n", s->frame_len_bits, s->block_len_bits, s->frame_len, s->block_len, (int8_t *)samples - (int8_t *)data, s->block_align);
-
*data_size = (int8_t *)samples - (int8_t *)data;
- return s->block_align;
+ return buf_size;
fail:
/* when error, we reset the bit reservoir */
s->last_superframe_len = 0;
@@ -916,30 +928,26 @@ static av_cold void flush(AVCodecContext *avctx)
s->last_superframe_len= 0;
}
-AVCodec ff_wmav1_decoder =
-{
- "wmav1",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_WMAV1,
- sizeof(WMACodecContext),
- wma_decode_init,
- NULL,
- ff_wma_end,
- wma_decode_superframe,
- .flush=flush,
- .long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio 1"),
+AVCodec ff_wmav1_decoder = {
+ .name = "wmav1",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_WMAV1,
+ .priv_data_size = sizeof(WMACodecContext),
+ .init = wma_decode_init,
+ .close = ff_wma_end,
+ .decode = wma_decode_superframe,
+ .flush = flush,
+ .long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio 1"),
};
-AVCodec ff_wmav2_decoder =
-{
- "wmav2",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_WMAV2,
- sizeof(WMACodecContext),
- wma_decode_init,
- NULL,
- ff_wma_end,
- wma_decode_superframe,
- .flush=flush,
- .long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio 2"),
+AVCodec ff_wmav2_decoder = {
+ .name = "wmav2",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_WMAV2,
+ .priv_data_size = sizeof(WMACodecContext),
+ .init = wma_decode_init,
+ .close = ff_wma_end,
+ .decode = wma_decode_superframe,
+ .flush = flush,
+ .long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio 2"),
};
diff --git a/libavcodec/wmaenc.c b/libavcodec/wmaenc.c
index 3cdb4a0b9b..6ec6d7ce57 100644
--- a/libavcodec/wmaenc.c
+++ b/libavcodec/wmaenc.c
@@ -2,20 +2,20 @@
* WMA compatible encoder
* Copyright (c) 2007 Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -311,7 +311,7 @@ static int encode_block(WMACodecContext *s, float (*src_coefs)[BLOCK_MAX_SIZE],
put_bits(&s->pb, s->coef_vlcs[tindex]->huffbits[1], s->coef_vlcs[tindex]->huffcodes[1]);
}
if (s->version == 1 && s->nb_channels >= 2) {
- align_put_bits(&s->pb);
+ avpriv_align_put_bits(&s->pb);
}
}
return 0;
@@ -327,7 +327,7 @@ static int encode_frame(WMACodecContext *s, float (*src_coefs)[BLOCK_MAX_SIZE],
return INT_MAX;
}
- align_put_bits(&s->pb);
+ avpriv_align_put_bits(&s->pb);
return put_bits_count(&s->pb)/8 - s->block_align;
}
@@ -390,28 +390,26 @@ static int encode_superframe(AVCodecContext *avctx,
return put_bits_ptr(&s->pb) - s->pb.buf;
}
-AVCodec ff_wmav1_encoder =
-{
- "wmav1",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_WMAV1,
- sizeof(WMACodecContext),
- encode_init,
- encode_superframe,
- ff_wma_end,
- .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
- .long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio 1"),
+AVCodec ff_wmav1_encoder = {
+ .name = "wmav1",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_WMAV1,
+ .priv_data_size = sizeof(WMACodecContext),
+ .init = encode_init,
+ .encode = encode_superframe,
+ .close = ff_wma_end,
+ .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
+ .long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio 1"),
};
-AVCodec ff_wmav2_encoder =
-{
- "wmav2",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_WMAV2,
- sizeof(WMACodecContext),
- encode_init,
- encode_superframe,
- ff_wma_end,
- .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
- .long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio 2"),
+AVCodec ff_wmav2_encoder = {
+ .name = "wmav2",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_WMAV2,
+ .priv_data_size = sizeof(WMACodecContext),
+ .init = encode_init,
+ .encode = encode_superframe,
+ .close = ff_wma_end,
+ .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
+ .long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio 2"),
};
diff --git a/libavcodec/wmaprodata.h b/libavcodec/wmaprodata.h
index f8a52bf4f4..53824799d5 100644
--- a/libavcodec/wmaprodata.h
+++ b/libavcodec/wmaprodata.h
@@ -3,20 +3,20 @@
* Copyright (c) 2007 Baptiste Coudurier, Benjamin Larsson, Ulion
* Copyright (c) 2008 - 2009 Sascha Sommer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/wmaprodec.c b/libavcodec/wmaprodec.c
index 4ba8c455ab..119027b7b7 100644
--- a/libavcodec/wmaprodec.c
+++ b/libavcodec/wmaprodec.c
@@ -3,20 +3,20 @@
* Copyright (c) 2007 Baptiste Coudurier, Benjamin Larsson, Ulion
* Copyright (c) 2008 - 2011 Sascha Sommer, Benjamin Larsson
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -309,10 +309,6 @@ static av_cold int decode_init(AVCodecContext *avctx)
s->samples_per_frame = 1 << ff_wma_get_frame_len_bits(avctx->sample_rate,
3, s->decode_flags);
- /** init previous block len */
- for (i = 0; i < avctx->channels; i++)
- s->channel[i].prev_block_len = s->samples_per_frame;
-
/** subframe info */
log2_max_num_subframes = ((s->decode_flags & 0x38) >> 3);
s->max_num_subframes = 1 << log2_max_num_subframes;
@@ -332,6 +328,18 @@ static av_cold int decode_init(AVCodecContext *avctx)
s->num_channels = avctx->channels;
+ if (s->num_channels < 0) {
+ av_log(avctx, AV_LOG_ERROR, "invalid number of channels %d\n", s->num_channels);
+ return AVERROR_INVALIDDATA;
+ } else if (s->num_channels > WMAPRO_MAX_CHANNELS) {
+ av_log_ask_for_sample(avctx, "unsupported number of channels\n");
+ return AVERROR_PATCHWELCOME;
+ }
+
+ /** init previous block len */
+ for (i = 0; i < s->num_channels; i++)
+ s->channel[i].prev_block_len = s->samples_per_frame;
+
/** extract lfe channel position */
s->lfe_channel = -1;
@@ -343,14 +351,6 @@ static av_cold int decode_init(AVCodecContext *avctx)
}
}
- if (s->num_channels < 0) {
- av_log(avctx, AV_LOG_ERROR, "invalid number of channels %d\n", s->num_channels);
- return AVERROR_INVALIDDATA;
- } else if (s->num_channels > WMAPRO_MAX_CHANNELS) {
- av_log_ask_for_sample(avctx, "unsupported number of channels\n");
- return AVERROR_PATCHWELCOME;
- }
-
INIT_VLC_STATIC(&sf_vlc, SCALEVLCBITS, HUFF_SCALE_SIZE,
scale_huffbits, 1, 1,
scale_huffcodes, 2, 2, 616);
@@ -1436,7 +1436,7 @@ static void save_bits(WMAProDecodeCtx *s, GetBitContext* gb, int len,
init_put_bits(&s->pb, s->frame_data, MAX_FRAMESIZE);
}
- buflen = (s->num_saved_bits + len + 8) >> 3;
+ buflen = (put_bits_count(&s->pb) + len + 8) >> 3;
if (len <= 0 || buflen > MAX_FRAMESIZE) {
av_log_ask_for_sample(s->avctx, "input buffer too small\n");
@@ -1446,14 +1446,14 @@ static void save_bits(WMAProDecodeCtx *s, GetBitContext* gb, int len,
s->num_saved_bits += len;
if (!append) {
- ff_copy_bits(&s->pb, gb->buffer + (get_bits_count(gb) >> 3),
+ avpriv_copy_bits(&s->pb, gb->buffer + (get_bits_count(gb) >> 3),
s->num_saved_bits);
} else {
int align = 8 - (get_bits_count(gb) & 7);
align = FFMIN(align, len);
put_bits(&s->pb, align, get_bits(gb, align));
len -= align;
- ff_copy_bits(&s->pb, gb->buffer + (get_bits_count(gb) >> 3), len);
+ avpriv_copy_bits(&s->pb, gb->buffer + (get_bits_count(gb) >> 3), len);
}
skip_bits_long(gb, len);
@@ -1605,14 +1605,13 @@ static void flush(AVCodecContext *avctx)
*@brief wmapro decoder
*/
AVCodec ff_wmapro_decoder = {
- "wmapro",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_WMAPRO,
- sizeof(WMAProDecodeCtx),
- decode_init,
- NULL,
- decode_end,
- decode_packet,
+ .name = "wmapro",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_WMAPRO,
+ .priv_data_size = sizeof(WMAProDecodeCtx),
+ .init = decode_init,
+ .close = decode_end,
+ .decode = decode_packet,
.capabilities = CODEC_CAP_SUBFRAMES,
.flush= flush,
.long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio 9 Professional"),
diff --git a/libavcodec/wmavoice.c b/libavcodec/wmavoice.c
index eb3bcb0629..b7a6f88a5b 100644
--- a/libavcodec/wmavoice.c
+++ b/libavcodec/wmavoice.c
@@ -2,20 +2,20 @@
* Windows Media Audio Voice decoder.
* Copyright (c) 2009 Ronald S. Bultje
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -401,6 +401,10 @@ static av_cold int wmavoice_decode_init(AVCodecContext *ctx)
s->min_pitch_val = ((ctx->sample_rate << 8) / 400 + 50) >> 8;
s->max_pitch_val = ((ctx->sample_rate << 8) * 37 / 2000 + 50) >> 8;
pitch_range = s->max_pitch_val - s->min_pitch_val;
+ if (pitch_range <= 0) {
+ av_log(ctx, AV_LOG_ERROR, "Invalid pitch range; broken extradata?\n");
+ return -1;
+ }
s->pitch_nbits = av_ceil_log2(pitch_range);
s->last_pitch_val = 40;
s->last_acb_type = ACB_TYPE_NONE;
@@ -422,6 +426,10 @@ static av_cold int wmavoice_decode_init(AVCodecContext *ctx)
s->block_conv_table[2] = (pitch_range * 44) >> 6;
s->block_conv_table[3] = s->max_pitch_val - 1;
s->block_delta_pitch_hrange = (pitch_range >> 3) & ~0xF;
+ if (s->block_delta_pitch_hrange <= 0) {
+ av_log(ctx, AV_LOG_ERROR, "Invalid delta pitch hrange; broken extradata?\n");
+ return -1;
+ }
s->block_delta_pitch_nbits = 1 + av_ceil_log2(s->block_delta_pitch_hrange);
s->block_pitch_range = s->block_conv_table[2] +
s->block_conv_table[3] + 1 +
@@ -1077,7 +1085,7 @@ static void aw_pulse_set2(WMAVoiceContext *s, GetBitContext *gb,
int excl_range = s->aw_pulse_range; // always 16 or 24
uint16_t *use_mask_ptr = &use_mask[idx >> 4];
int first_sh = 16 - (idx & 15);
- *use_mask_ptr++ &= 0xFFFF << first_sh;
+ *use_mask_ptr++ &= 0xFFFFu << first_sh;
excl_range -= first_sh;
if (excl_range >= 16) {
*use_mask_ptr++ = 0;
@@ -1864,7 +1872,7 @@ static int parse_packet_header(WMAVoiceContext *s)
* @param size size of the source data, in bytes
* @param gb bit I/O context specifying the current position in the source.
* data. This function might use this to align the bit position to
- * a whole-byte boundary before calling #ff_copy_bits() on aligned
+ * a whole-byte boundary before calling #avpriv_copy_bits() on aligned
* source data
* @param nbits the amount of bits to copy from source to target
*
@@ -1880,10 +1888,12 @@ static void copy_bits(PutBitContext *pb,
rmn_bits = rmn_bytes = get_bits_left(gb);
if (rmn_bits < nbits)
return;
+ if (nbits > pb->size_in_bits - put_bits_count(pb))
+ return;
rmn_bits &= 7; rmn_bytes >>= 3;
if ((rmn_bits = FFMIN(rmn_bits, nbits)) > 0)
put_bits(pb, rmn_bits, get_bits(gb, rmn_bits));
- ff_copy_bits(pb, data + size - rmn_bytes,
+ avpriv_copy_bits(pb, data + size - rmn_bytes,
FFMIN(nbits - rmn_bits, rmn_bytes << 3));
}
@@ -1914,7 +1924,7 @@ static int wmavoice_decode_packet(AVCodecContext *ctx, void *data,
*data_size = 0;
/* Packets are sometimes a multiple of ctx->block_align, with a packet
- * header at each ctx->block_align bytes. However, Libav's ASF demuxer
+ * header at each ctx->block_align bytes. However, FFmpeg's ASF demuxer
* feeds us ASF packets, which may concatenate multiple "codec" packets
* in a single "muxer" packet, so we artificially emulate that by
* capping the packet size at ctx->block_align. */
@@ -2022,15 +2032,14 @@ static av_cold void wmavoice_flush(AVCodecContext *ctx)
}
AVCodec ff_wmavoice_decoder = {
- "wmavoice",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_WMAVOICE,
- sizeof(WMAVoiceContext),
- wmavoice_decode_init,
- NULL,
- wmavoice_decode_end,
- wmavoice_decode_packet,
- CODEC_CAP_SUBFRAMES,
+ .name = "wmavoice",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_WMAVOICE,
+ .priv_data_size = sizeof(WMAVoiceContext),
+ .init = wmavoice_decode_init,
+ .close = wmavoice_decode_end,
+ .decode = wmavoice_decode_packet,
+ .capabilities = CODEC_CAP_SUBFRAMES,
.flush = wmavoice_flush,
.long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio Voice"),
};
diff --git a/libavcodec/wmavoice_data.h b/libavcodec/wmavoice_data.h
index 7f14fb8350..cbf65b043e 100644
--- a/libavcodec/wmavoice_data.h
+++ b/libavcodec/wmavoice_data.h
@@ -2,20 +2,20 @@
* Windows Media Voice (WMAVoice) tables.
* Copyright (c) 2009 Ronald S. Bultje
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/wmv2.c b/libavcodec/wmv2.c
index 74389ef4db..32aaa8f6df 100644
--- a/libavcodec/wmv2.c
+++ b/libavcodec/wmv2.c
@@ -1,20 +1,20 @@
/*
- * Copyright (c) 2002 The Libav Project
+ * Copyright (c) 2002 The FFmpeg Project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/wmv2.h b/libavcodec/wmv2.h
index 80f36ccddb..c69c9f48ee 100644
--- a/libavcodec/wmv2.h
+++ b/libavcodec/wmv2.h
@@ -1,20 +1,20 @@
/*
- * Copyright (c) 2002 The Libav Project
+ * Copyright (c) 2002 The FFmpeg Project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/wmv2dec.c b/libavcodec/wmv2dec.c
index ede5236559..519ae61b93 100644
--- a/libavcodec/wmv2dec.c
+++ b/libavcodec/wmv2dec.c
@@ -1,20 +1,20 @@
/*
- * Copyright (c) 2002 The Libav Project
+ * Copyright (c) 2002 The FFmpeg Project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -32,7 +32,7 @@
static void parse_mb_skip(Wmv2Context * w){
int mb_x, mb_y;
MpegEncContext * const s= &w->s;
- uint32_t * const mb_type= s->current_picture_ptr->mb_type;
+ uint32_t * const mb_type = s->current_picture_ptr->f.mb_type;
w->skip_type= get_bits(&s->gb, 2);
switch(w->skip_type){
@@ -257,11 +257,11 @@ static int16_t *wmv2_pred_motion(Wmv2Context *w, int *px, int *py){
wrap = s->b8_stride;
xy = s->block_index[0];
- mot_val = s->current_picture.motion_val[0][xy];
+ mot_val = s->current_picture.f.motion_val[0][xy];
- A = s->current_picture.motion_val[0][xy - 1];
- B = s->current_picture.motion_val[0][xy - wrap];
- C = s->current_picture.motion_val[0][xy + 2 - wrap];
+ A = s->current_picture.f.motion_val[0][xy - 1];
+ B = s->current_picture.f.motion_val[0][xy - wrap];
+ C = s->current_picture.f.motion_val[0][xy + 2 - wrap];
if(s->mb_x && !s->first_slice_line && !s->mspel && w->top_left_mv_flag)
diff= FFMAX(FFABS(A[0] - B[0]), FFABS(A[1] - B[1]));
@@ -343,7 +343,7 @@ int ff_wmv2_decode_mb(MpegEncContext *s, DCTELEM block[6][64])
if(w->j_type) return 0;
if (s->pict_type == AV_PICTURE_TYPE_P) {
- if(IS_SKIP(s->current_picture.mb_type[s->mb_y * s->mb_stride + s->mb_x])){
+ if (IS_SKIP(s->current_picture.f.mb_type[s->mb_y * s->mb_stride + s->mb_x])) {
/* skip mb */
s->mb_intra = 0;
for(i=0;i<6;i++)
@@ -471,16 +471,14 @@ static av_cold int wmv2_decode_end(AVCodecContext *avctx)
}
AVCodec ff_wmv2_decoder = {
- "wmv2",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_WMV2,
- sizeof(Wmv2Context),
- wmv2_decode_init,
- NULL,
- wmv2_decode_end,
- ff_h263_decode_frame,
- CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
- .max_lowres = 3,
+ .name = "wmv2",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_WMV2,
+ .priv_data_size = sizeof(Wmv2Context),
+ .init = wmv2_decode_init,
+ .close = wmv2_decode_end,
+ .decode = ff_h263_decode_frame,
+ .capabilities = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 8"),
.pix_fmts= ff_pixfmt_list_420,
};
diff --git a/libavcodec/wmv2enc.c b/libavcodec/wmv2enc.c
index 9b7890c0f0..bc9e4fa0ab 100644
--- a/libavcodec/wmv2enc.c
+++ b/libavcodec/wmv2enc.c
@@ -1,20 +1,20 @@
/*
- * Copyright (c) 2002 The Libav Project
+ * Copyright (c) 2002 The FFmpeg Project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -212,13 +212,13 @@ void ff_wmv2_encode_mb(MpegEncContext * s,
}
AVCodec ff_wmv2_encoder = {
- "wmv2",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_WMV2,
- sizeof(Wmv2Context),
- wmv2_encode_init,
- MPV_encode_picture,
- MPV_encode_end,
+ .name = "wmv2",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_WMV2,
+ .priv_data_size = sizeof(Wmv2Context),
+ .init = wmv2_encode_init,
+ .encode = MPV_encode_picture,
+ .close = MPV_encode_end,
.pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
.long_name= NULL_IF_CONFIG_SMALL("Windows Media Video 8"),
};
diff --git a/libavcodec/wnv1.c b/libavcodec/wnv1.c
index 65ad9cdd12..6429a5b748 100644
--- a/libavcodec/wnv1.c
+++ b/libavcodec/wnv1.c
@@ -2,20 +2,20 @@
* Winnov WNV1 codec
* Copyright (c) 2005 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -136,6 +136,7 @@ static av_cold int decode_init(AVCodecContext *avctx){
l->avctx = avctx;
avctx->pix_fmt = PIX_FMT_YUV422P;
+ avcodec_get_frame_defaults(&l->pic);
code_vlc.table = code_table;
code_vlc.table_allocated = 1 << CODE_VLC_BITS;
@@ -157,14 +158,13 @@ static av_cold int decode_end(AVCodecContext *avctx){
}
AVCodec ff_wnv1_decoder = {
- "wnv1",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_WNV1,
- sizeof(WNV1Context),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- CODEC_CAP_DR1,
+ .name = "wnv1",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_WNV1,
+ .priv_data_size = sizeof(WNV1Context),
+ .init = decode_init,
+ .close = decode_end,
+ .decode = decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Winnov WNV1"),
};
diff --git a/libavcodec/ws-snd1.c b/libavcodec/ws-snd1.c
index 534be5661b..17b8cbfa3a 100644
--- a/libavcodec/ws-snd1.c
+++ b/libavcodec/ws-snd1.c
@@ -2,20 +2,20 @@
* Westwood SNDx codecs
* Copyright (c) 2005 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -25,47 +25,50 @@
/**
* @file
- * Westwood SNDx codecs.
+ * Westwood SNDx codecs
*
* Reference documents about VQA format and its audio codecs
* can be found here:
* http://www.multimedia.cx
*/
-static const int8_t ws_adpcm_2bit[] = { -2, -1, 0, 1};
static const int8_t ws_adpcm_4bit[] = {
-9, -8, -6, -5, -4, -3, -2, -1,
- 0, 1, 2, 3, 4, 5, 6, 8 };
-
-#define CLIP8(a) if(a>127)a=127;if(a<-128)a=-128;
+ 0, 1, 2, 3, 4, 5, 6, 8
+};
-static av_cold int ws_snd_decode_init(AVCodecContext * avctx)
+static av_cold int ws_snd_decode_init(AVCodecContext *avctx)
{
-// WSSNDContext *c = avctx->priv_data;
+ if (avctx->channels != 1) {
+ av_log_ask_for_sample(avctx, "unsupported number of channels\n");
+ return AVERROR(EINVAL);
+ }
- avctx->sample_fmt = AV_SAMPLE_FMT_S16;
+ avctx->sample_fmt = AV_SAMPLE_FMT_U8;
return 0;
}
-static int ws_snd_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- AVPacket *avpkt)
+static int ws_snd_decode_frame(AVCodecContext *avctx, void *data,
+ int *data_size, AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
- int buf_size = avpkt->size;
-// WSSNDContext *c = avctx->priv_data;
+ int buf_size = avpkt->size;
int in_size, out_size;
- int sample = 0;
- int i;
- short *samples = data;
+ int sample = 128;
+ uint8_t *samples = data;
+ uint8_t *samples_end;
if (!buf_size)
return 0;
+ if (buf_size < 4) {
+ av_log(avctx, AV_LOG_ERROR, "packet is too small\n");
+ return AVERROR(EINVAL);
+ }
+
out_size = AV_RL16(&buf[0]);
- *data_size = out_size * 2;
- in_size = AV_RL16(&buf[2]);
+ in_size = AV_RL16(&buf[2]);
buf += 4;
if (out_size > *data_size) {
@@ -76,47 +79,63 @@ static int ws_snd_decode_frame(AVCodecContext *avctx,
av_log(avctx, AV_LOG_ERROR, "Frame data is larger than input buffer\n");
return -1;
}
+ samples_end = samples + out_size;
+
if (in_size == out_size) {
- for (i = 0; i < out_size; i++)
- *samples++ = (*buf++ - 0x80) << 8;
+ memcpy(samples, buf, out_size);
+ *data_size = out_size;
return buf_size;
}
- while (out_size > 0) {
- int code;
+ while (samples < samples_end && buf - avpkt->data < buf_size) {
+ int code, smp, size;
uint8_t count;
- code = (*buf) >> 6;
- count = (*buf) & 0x3F;
+ code = *buf >> 6;
+ count = *buf & 0x3F;
buf++;
- switch(code) {
+
+ /* make sure we don't write past the output buffer */
+ switch (code) {
+ case 0: smp = 4; break;
+ case 1: smp = 2; break;
+ case 2: smp = (count & 0x20) ? 1 : count + 1; break;
+ default: smp = count + 1; break;
+ }
+ if (samples_end - samples < smp)
+ break;
+
+ /* make sure we don't read past the input buffer */
+ size = ((code == 2 && (count & 0x20)) || code == 3) ? 0 : count + 1;
+ if ((buf - avpkt->data) + size > buf_size)
+ break;
+
+ switch (code) {
case 0: /* ADPCM 2-bit */
for (count++; count > 0; count--) {
code = *buf++;
- sample += ws_adpcm_2bit[code & 0x3];
- CLIP8(sample);
- *samples++ = sample << 8;
- sample += ws_adpcm_2bit[(code >> 2) & 0x3];
- CLIP8(sample);
- *samples++ = sample << 8;
- sample += ws_adpcm_2bit[(code >> 4) & 0x3];
- CLIP8(sample);
- *samples++ = sample << 8;
- sample += ws_adpcm_2bit[(code >> 6) & 0x3];
- CLIP8(sample);
- *samples++ = sample << 8;
- out_size -= 4;
+ sample += ( code & 0x3) - 2;
+ sample = av_clip_uint8(sample);
+ *samples++ = sample;
+ sample += ((code >> 2) & 0x3) - 2;
+ sample = av_clip_uint8(sample);
+ *samples++ = sample;
+ sample += ((code >> 4) & 0x3) - 2;
+ sample = av_clip_uint8(sample);
+ *samples++ = sample;
+ sample += (code >> 6) - 2;
+ sample = av_clip_uint8(sample);
+ *samples++ = sample;
}
break;
case 1: /* ADPCM 4-bit */
for (count++; count > 0; count--) {
code = *buf++;
sample += ws_adpcm_4bit[code & 0xF];
- CLIP8(sample);
- *samples++ = sample << 8;
+ sample = av_clip_uint8(sample);
+ *samples++ = sample;
sample += ws_adpcm_4bit[code >> 4];
- CLIP8(sample);
- *samples++ = sample << 8;
- out_size -= 2;
+ sample = av_clip_uint8(sample);
+ *samples++ = sample;
}
break;
case 2: /* no compression */
@@ -125,35 +144,31 @@ static int ws_snd_decode_frame(AVCodecContext *avctx,
t = count;
t <<= 3;
sample += t >> 3;
- *samples++ = sample << 8;
- out_size--;
+ sample = av_clip_uint8(sample);
+ *samples++ = sample;
} else { /* copy */
- for (count++; count > 0; count--) {
- *samples++ = (*buf++ - 0x80) << 8;
- out_size--;
- }
- sample = buf[-1] - 0x80;
+ memcpy(samples, buf, smp);
+ samples += smp;
+ buf += smp;
+ sample = buf[-1];
}
break;
default: /* run */
- for(count++; count > 0; count--) {
- *samples++ = sample << 8;
- out_size--;
- }
+ memset(samples, sample, smp);
+ samples += smp;
}
}
+ *data_size = samples - (uint8_t *)data;
+
return buf_size;
}
AVCodec ff_ws_snd1_decoder = {
- "ws_snd1",
- AVMEDIA_TYPE_AUDIO,
- CODEC_ID_WESTWOOD_SND1,
- 0,
- ws_snd_decode_init,
- NULL,
- NULL,
- ws_snd_decode_frame,
+ .name = "ws_snd1",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_WESTWOOD_SND1,
+ .init = ws_snd_decode_init,
+ .decode = ws_snd_decode_frame,
.long_name = NULL_IF_CONFIG_SMALL("Westwood Audio (SND1)"),
};
diff --git a/libavcodec/x86/Makefile b/libavcodec/x86/Makefile
index d3cf0da72b..f4783bc4d2 100644
--- a/libavcodec/x86/Makefile
+++ b/libavcodec/x86/Makefile
@@ -21,17 +21,26 @@ YASM-OBJS-$(CONFIG_H264PRED) += x86/h264_intrapred.o \
x86/h264_intrapred_10bit.o
MMX-OBJS-$(CONFIG_H264PRED) += x86/h264_intrapred_init.o
+MMX-OBJS-$(CONFIG_RV40_DECODER) += x86/rv40dsp.o \
+
YASM-OBJS-$(CONFIG_VC1_DECODER) += x86/vc1dsp_yasm.o
MMX-OBJS-$(CONFIG_AC3DSP) += x86/ac3dsp_mmx.o
YASM-OBJS-$(CONFIG_AC3DSP) += x86/ac3dsp.o
MMX-OBJS-$(CONFIG_CAVS_DECODER) += x86/cavsdsp_mmx.o
MMX-OBJS-$(CONFIG_MPEGAUDIODSP) += x86/mpegaudiodec_mmx.o
+MMX-OBJS-$(CONFIG_PNG_DECODER) += x86/png_mmx.o
MMX-OBJS-$(CONFIG_ENCODERS) += x86/dsputilenc_mmx.o
YASM-OBJS-$(CONFIG_ENCODERS) += x86/dsputilenc_yasm.o
MMX-OBJS-$(CONFIG_GPL) += x86/idct_mmx.o
MMX-OBJS-$(CONFIG_LPC) += x86/lpc_mmx.o
+YASM-OBJS-$(CONFIG_PRORES_LGPL_DECODER) += x86/proresdsp.o
+MMX-OBJS-$(CONFIG_PRORES_LGPL_DECODER) += x86/proresdsp-init.o
+YASM-OBJS-$(CONFIG_PRORES_DECODER) += x86/proresdsp.o
+MMX-OBJS-$(CONFIG_PRORES_DECODER) += x86/proresdsp-init.o
MMX-OBJS-$(CONFIG_DWT) += x86/snowdsp_mmx.o
+YASM-OBJS-$(CONFIG_V210_DECODER) += x86/v210.o
+MMX-OBJS-$(CONFIG_V210_DECODER) += x86/v210-init.o
MMX-OBJS-$(CONFIG_VC1_DECODER) += x86/vc1dsp_mmx.o
YASM-OBJS-$(CONFIG_VP3_DECODER) += x86/vp3dsp.o
YASM-OBJS-$(CONFIG_VP5_DECODER) += x86/vp3dsp.o
diff --git a/libavcodec/x86/ac3dsp.asm b/libavcodec/x86/ac3dsp.asm
index c1b0906a85..59157b7219 100644
--- a/libavcodec/x86/ac3dsp.asm
+++ b/libavcodec/x86/ac3dsp.asm
@@ -2,25 +2,25 @@
;* x86-optimized AC-3 DSP utils
;* Copyright (c) 2011 Justin Ruggles
;*
-;* This file is part of Libav.
+;* This file is part of FFmpeg.
;*
-;* Libav is free software; you can redistribute it and/or
+;* FFmpeg 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.
;*
-;* Libav is distributed in the hope that it will be useful,
+;* FFmpeg 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
;* Lesser General Public License for more details.
;*
;* You should have received a copy of the GNU Lesser General Public
-;* License along with Libav; if not, write to the Free Software
+;* License along with FFmpeg; if not, write to the Free Software
;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
;******************************************************************************
-%include "x86inc.asm"
-%include "x86util.asm"
+%include "libavutil/x86/x86inc.asm"
+%include "libavutil/x86/x86util.asm"
SECTION_RODATA
diff --git a/libavcodec/x86/ac3dsp_mmx.c b/libavcodec/x86/ac3dsp_mmx.c
index 692d240d4c..9578e98d8b 100644
--- a/libavcodec/x86/ac3dsp_mmx.c
+++ b/libavcodec/x86/ac3dsp_mmx.c
@@ -2,20 +2,20 @@
* x86-optimized AC-3 DSP utils
* Copyright (c) 2011 Justin Ruggles
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -50,9 +50,9 @@ extern void ff_ac3_extract_exponents_ssse3(uint8_t *exp, int32_t *coef, int nb_c
av_cold void ff_ac3dsp_init_x86(AC3DSPContext *c, int bit_exact)
{
+#if HAVE_YASM
int mm_flags = av_get_cpu_flags();
-#if HAVE_YASM
if (mm_flags & AV_CPU_FLAG_MMX) {
c->ac3_exponent_min = ff_ac3_exponent_min_mmx;
c->ac3_max_msb_abs_int16 = ff_ac3_max_msb_abs_int16_mmx;
diff --git a/libavcodec/x86/cabac.h b/libavcodec/x86/cabac.h
index 52bea9c53d..5c46342808 100644
--- a/libavcodec/x86/cabac.h
+++ b/libavcodec/x86/cabac.h
@@ -34,8 +34,8 @@
"cmova %%ecx , "range" \n\t"\
"sbb %%ecx , %%ecx \n\t"\
"and %%ecx , "tmp" \n\t"\
- "sub "tmp" , "low" \n\t"\
- "xor %%ecx , "ret" \n\t"
+ "xor %%ecx , "ret" \n\t"\
+ "sub "tmp" , "low" \n\t"
#else /* HAVE_FAST_CMOV */
#define BRANCHLESS_GET_CABAC_UPDATE(ret, cabac, statep, low, lowword, range, tmp)\
"mov "tmp" , %%ecx \n\t"\
@@ -62,21 +62,20 @@
"movzbl " MANGLE(ff_h264_norm_shift) "("range"), %%ecx \n\t"\
"shl %%cl , "range" \n\t"\
"movzbl "MANGLE(ff_h264_mlps_state)"+128("ret"), "tmp" \n\t"\
- "mov "tmpbyte" , "statep" \n\t"\
"shl %%cl , "low" \n\t"\
+ "mov "tmpbyte" , "statep" \n\t"\
"test "lowword" , "lowword" \n\t"\
" jnz 1f \n\t"\
"mov "byte"("cabac"), %%"REG_c" \n\t"\
+ "add"OPSIZE" $2 , "byte "("cabac") \n\t"\
"movzwl (%%"REG_c") , "tmp" \n\t"\
- "bswap "tmp" \n\t"\
- "shr $15 , "tmp" \n\t"\
- "sub $0xFFFF , "tmp" \n\t"\
- "add $2 , %%"REG_c" \n\t"\
- "mov %%"REG_c" , "byte "("cabac") \n\t"\
"lea -1("low") , %%ecx \n\t"\
"xor "low" , %%ecx \n\t"\
"shr $15 , %%ecx \n\t"\
+ "bswap "tmp" \n\t"\
+ "shr $15 , "tmp" \n\t"\
"movzbl " MANGLE(ff_h264_norm_shift) "(%%ecx), %%ecx \n\t"\
+ "sub $0xFFFF , "tmp" \n\t"\
"neg %%ecx \n\t"\
"add $7 , %%ecx \n\t"\
"shl %%cl , "tmp" \n\t"\
diff --git a/libavcodec/x86/cavsdsp_mmx.c b/libavcodec/x86/cavsdsp_mmx.c
index 3bc62ea156..0f5fdaa53d 100644
--- a/libavcodec/x86/cavsdsp_mmx.c
+++ b/libavcodec/x86/cavsdsp_mmx.c
@@ -5,20 +5,20 @@
* MMX-optimized DSP functions, based on H.264 optimizations by
* Michael Niedermayer and Loren Merritt
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/x86/dct32_sse.asm b/libavcodec/x86/dct32_sse.asm
index 46daa43d8c..bd69fe118c 100644
--- a/libavcodec/x86/dct32_sse.asm
+++ b/libavcodec/x86/dct32_sse.asm
@@ -2,25 +2,25 @@
;* 32 point SSE-optimized DCT transform
;* Copyright (c) 2010 Vitor Sessak
;*
-;* This file is part of Libav.
+;* This file is part of FFmpeg.
;*
-;* Libav is free software; you can redistribute it and/or
+;* FFmpeg 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.
;*
-;* Libav is distributed in the hope that it will be useful,
+;* FFmpeg 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
;* Lesser General Public License for more details.
;*
;* You should have received a copy of the GNU Lesser General Public
-;* License along with Libav; if not, write to the Free Software
+;* License along with FFmpeg; if not, write to the Free Software
;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
;******************************************************************************
-%include "x86inc.asm"
-%include "x86util.asm"
+%include "libavutil/x86/x86inc.asm"
+%include "libavutil/x86/x86util.asm"
SECTION_RODATA 32
@@ -63,6 +63,13 @@ ps_p1p1m1m1: dd 0, 0, 0x80000000, 0x80000000, 0, 0, 0x80000000, 0x80000000
mulps %1, %3
%endmacro
+%macro BUTTERFLY0_SSE2 5
+ pshufd %4, %1, %5
+ xorps %1, %2
+ addps %1, %4
+ mulps %1, %3
+%endmacro
+
%macro BUTTERFLY0_AVX 5
vshufps %4, %1, %1, %5
vxorps %1, %1, %2
@@ -405,18 +412,17 @@ INIT_XMM
INIT_XMM
+%macro DCT32_FUNC 1
; void ff_dct32_float_sse(FFTSample *out, const FFTSample *in)
-cglobal dct32_float_sse, 2,3,16, out, in, tmp
+cglobal dct32_float_%1, 2,3,16, out, in, tmp
; pass 1
movaps m0, [inq+0]
- movaps m1, [inq+112]
- shufps m1, m1, 0x1b
+ LOAD_INV m1, [inq+112]
BUTTERFLY m0, m1, [ps_cos_vec], m3
movaps m7, [inq+64]
- movaps m4, [inq+48]
- shufps m4, m4, 0x1b
+ LOAD_INV m4, [inq+48]
BUTTERFLY m7, m4, [ps_cos_vec+32], m3
; pass 2
@@ -427,13 +433,11 @@ cglobal dct32_float_sse, 2,3,16, out, in, tmp
; pass 1
movaps m1, [inq+16]
- movaps m6, [inq+96]
- shufps m6, m6, 0x1b
+ LOAD_INV m6, [inq+96]
BUTTERFLY m1, m6, [ps_cos_vec+16], m3
movaps m4, [inq+80]
- movaps m5, [inq+32]
- shufps m5, m5, 0x1b
+ LOAD_INV m5, [inq+32]
BUTTERFLY m4, m5, [ps_cos_vec+48], m3
; pass 2
@@ -492,3 +496,20 @@ cglobal dct32_float_sse, 2,3,16, out, in, tmp
PASS5
PASS6
RET
+%endmacro
+
+%macro LOAD_INV_SSE 2
+ movaps %1, %2
+ shufps %1, %1, 0x1b
+%endmacro
+
+%define LOAD_INV LOAD_INV_SSE
+DCT32_FUNC sse
+
+%macro LOAD_INV_SSE2 2
+ pshufd %1, %2, 0x1b
+%endmacro
+
+%define LOAD_INV LOAD_INV_SSE2
+%define BUTTERFLY0 BUTTERFLY0_SSE2
+DCT32_FUNC sse2
diff --git a/libavcodec/x86/deinterlace.asm b/libavcodec/x86/deinterlace.asm
index 8613485d5d..a09473bdae 100644
--- a/libavcodec/x86/deinterlace.asm
+++ b/libavcodec/x86/deinterlace.asm
@@ -3,25 +3,25 @@
;* Copyright (c) 2010 Vitor Sessak
;* Copyright (c) 2002 Michael Niedermayer
;*
-;* This file is part of Libav.
+;* This file is part of FFmpeg.
;*
-;* Libav is free software; you can redistribute it and/or
+;* FFmpeg 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.
;*
-;* Libav is distributed in the hope that it will be useful,
+;* FFmpeg 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
;* Lesser General Public License for more details.
;*
;* You should have received a copy of the GNU Lesser General Public
-;* License along with Libav; if not, write to the Free Software
+;* License along with FFmpeg; if not, write to the Free Software
;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
;******************************************************************************
-%include "x86inc.asm"
-%include "x86util.asm"
+%include "libavutil/x86/x86inc.asm"
+%include "libavutil/x86/x86util.asm"
SECTION_RODATA
diff --git a/libavcodec/x86/dnxhd_mmx.c b/libavcodec/x86/dnxhd_mmx.c
index f00ce9b188..1f2b035212 100644
--- a/libavcodec/x86/dnxhd_mmx.c
+++ b/libavcodec/x86/dnxhd_mmx.c
@@ -4,20 +4,20 @@
*
* VC-3 encoder funded by the British Broadcasting Corporation
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -53,6 +53,7 @@ static void get_pixels_8x4_sym_sse2(DCTELEM *block, const uint8_t *pixels, int l
void ff_dnxhd_init_mmx(DNXHDEncContext *ctx)
{
if (av_get_cpu_flags() & AV_CPU_FLAG_SSE2) {
- ctx->get_pixels_8x4_sym = get_pixels_8x4_sym_sse2;
+ if (ctx->cid_table->bit_depth == 8)
+ ctx->get_pixels_8x4_sym = get_pixels_8x4_sym_sse2;
}
}
diff --git a/libavcodec/x86/dsputil_mmx.c b/libavcodec/x86/dsputil_mmx.c
index 7842370fcd..2322a29fb7 100644
--- a/libavcodec/x86/dsputil_mmx.c
+++ b/libavcodec/x86/dsputil_mmx.c
@@ -3,20 +3,20 @@
* Copyright (c) 2000, 2001 Fabrice Bellard
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* MMX optimization by Nick Kurshev <nickols_k@mail.ru>
@@ -42,7 +42,7 @@ DECLARE_ALIGNED(8, const uint64_t, ff_wtwo) = 0x0002000200020002ULL;
DECLARE_ALIGNED(16, const uint64_t, ff_pdw_80000000)[2] =
{0x8000000080000000ULL, 0x8000000080000000ULL};
-DECLARE_ALIGNED(8, const uint64_t, ff_pw_1 ) = 0x0001000100010001ULL;
+DECLARE_ALIGNED(16, const xmm_reg, ff_pw_1 ) = {0x0001000100010001ULL, 0x0001000100010001ULL};
DECLARE_ALIGNED(16, const xmm_reg, ff_pw_2 ) = {0x0002000200020002ULL, 0x0002000200020002ULL};
DECLARE_ALIGNED(16, const xmm_reg, ff_pw_3 ) = {0x0003000300030003ULL, 0x0003000300030003ULL};
DECLARE_ALIGNED(16, const xmm_reg, ff_pw_4 ) = {0x0004000400040004ULL, 0x0004000400040004ULL};
@@ -64,6 +64,8 @@ DECLARE_ALIGNED(16, const xmm_reg, ff_pw_64 ) = {0x0040004000400040ULL, 0x00400
DECLARE_ALIGNED(8, const uint64_t, ff_pw_96 ) = 0x0060006000600060ULL;
DECLARE_ALIGNED(8, const uint64_t, ff_pw_128) = 0x0080008000800080ULL;
DECLARE_ALIGNED(8, const uint64_t, ff_pw_255) = 0x00ff00ff00ff00ffULL;
+DECLARE_ALIGNED(16, const xmm_reg, ff_pw_512) = {0x0200020002000200ULL, 0x0200020002000200ULL};
+DECLARE_ALIGNED(16, const xmm_reg, ff_pw_1019)= {0x03FB03FB03FB03FBULL, 0x03FB03FB03FB03FBULL};
DECLARE_ALIGNED(16, const xmm_reg, ff_pb_0 ) = {0x0000000000000000ULL, 0x0000000000000000ULL};
DECLARE_ALIGNED(16, const xmm_reg, ff_pb_1 ) = {0x0101010101010101ULL, 0x0101010101010101ULL};
@@ -456,12 +458,12 @@ static void put_pixels16_sse2(uint8_t *block, const uint8_t *pixels, int line_si
"movdqu (%1,%3), %%xmm1 \n\t"
"movdqu (%1,%3,2), %%xmm2 \n\t"
"movdqu (%1,%4), %%xmm3 \n\t"
+ "lea (%1,%3,4), %1 \n\t"
"movdqa %%xmm0, (%2) \n\t"
"movdqa %%xmm1, (%2,%3) \n\t"
"movdqa %%xmm2, (%2,%3,2) \n\t"
"movdqa %%xmm3, (%2,%4) \n\t"
"subl $4, %0 \n\t"
- "lea (%1,%3,4), %1 \n\t"
"lea (%2,%3,4), %2 \n\t"
"jnz 1b \n\t"
: "+g"(h), "+r" (pixels), "+r" (block)
@@ -478,6 +480,7 @@ static void avg_pixels16_sse2(uint8_t *block, const uint8_t *pixels, int line_si
"movdqu (%1,%3), %%xmm1 \n\t"
"movdqu (%1,%3,2), %%xmm2 \n\t"
"movdqu (%1,%4), %%xmm3 \n\t"
+ "lea (%1,%3,4), %1 \n\t"
"pavgb (%2), %%xmm0 \n\t"
"pavgb (%2,%3), %%xmm1 \n\t"
"pavgb (%2,%3,2), %%xmm2 \n\t"
@@ -487,7 +490,6 @@ static void avg_pixels16_sse2(uint8_t *block, const uint8_t *pixels, int line_si
"movdqa %%xmm2, (%2,%3,2) \n\t"
"movdqa %%xmm3, (%2,%4) \n\t"
"subl $4, %0 \n\t"
- "lea (%1,%3,4), %1 \n\t"
"lea (%2,%3,4), %2 \n\t"
"jnz 1b \n\t"
: "+g"(h), "+r" (pixels), "+r" (block)
@@ -580,28 +582,6 @@ static void add_bytes_mmx(uint8_t *dst, uint8_t *src, int w){
dst[i+0] += src[i+0];
}
-static void add_bytes_l2_mmx(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){
- x86_reg i=0;
- __asm__ volatile(
- "jmp 2f \n\t"
- "1: \n\t"
- "movq (%2, %0), %%mm0 \n\t"
- "movq 8(%2, %0), %%mm1 \n\t"
- "paddb (%3, %0), %%mm0 \n\t"
- "paddb 8(%3, %0), %%mm1 \n\t"
- "movq %%mm0, (%1, %0) \n\t"
- "movq %%mm1, 8(%1, %0) \n\t"
- "add $16, %0 \n\t"
- "2: \n\t"
- "cmp %4, %0 \n\t"
- " js 1b \n\t"
- : "+r" (i)
- : "r"(dst), "r"(src1), "r"(src2), "r"((x86_reg)w-15)
- );
- for(; i<w; i++)
- dst[i] = src1[i] + src2[i];
-}
-
#if HAVE_7REGS
static void add_hfyu_median_prediction_cmov(uint8_t *dst, const uint8_t *top, const uint8_t *diff, int w, int *left, int *left_top) {
x86_reg w2 = -w;
@@ -877,80 +857,6 @@ static void draw_edges_mmx(uint8_t *buf, int wrap, int width, int height, int w,
}
}
-#define PAETH(cpu, abs3)\
-static void add_png_paeth_prediction_##cpu(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp)\
-{\
- x86_reg i = -bpp;\
- x86_reg end = w-3;\
- __asm__ volatile(\
- "pxor %%mm7, %%mm7 \n"\
- "movd (%1,%0), %%mm0 \n"\
- "movd (%2,%0), %%mm1 \n"\
- "punpcklbw %%mm7, %%mm0 \n"\
- "punpcklbw %%mm7, %%mm1 \n"\
- "add %4, %0 \n"\
- "1: \n"\
- "movq %%mm1, %%mm2 \n"\
- "movd (%2,%0), %%mm1 \n"\
- "movq %%mm2, %%mm3 \n"\
- "punpcklbw %%mm7, %%mm1 \n"\
- "movq %%mm2, %%mm4 \n"\
- "psubw %%mm1, %%mm3 \n"\
- "psubw %%mm0, %%mm4 \n"\
- "movq %%mm3, %%mm5 \n"\
- "paddw %%mm4, %%mm5 \n"\
- abs3\
- "movq %%mm4, %%mm6 \n"\
- "pminsw %%mm5, %%mm6 \n"\
- "pcmpgtw %%mm6, %%mm3 \n"\
- "pcmpgtw %%mm5, %%mm4 \n"\
- "movq %%mm4, %%mm6 \n"\
- "pand %%mm3, %%mm4 \n"\
- "pandn %%mm3, %%mm6 \n"\
- "pandn %%mm0, %%mm3 \n"\
- "movd (%3,%0), %%mm0 \n"\
- "pand %%mm1, %%mm6 \n"\
- "pand %%mm4, %%mm2 \n"\
- "punpcklbw %%mm7, %%mm0 \n"\
- "movq %6, %%mm5 \n"\
- "paddw %%mm6, %%mm0 \n"\
- "paddw %%mm2, %%mm3 \n"\
- "paddw %%mm3, %%mm0 \n"\
- "pand %%mm5, %%mm0 \n"\
- "movq %%mm0, %%mm3 \n"\
- "packuswb %%mm3, %%mm3 \n"\
- "movd %%mm3, (%1,%0) \n"\
- "add %4, %0 \n"\
- "cmp %5, %0 \n"\
- "jle 1b \n"\
- :"+r"(i)\
- :"r"(dst), "r"(top), "r"(src), "r"((x86_reg)bpp), "g"(end),\
- "m"(ff_pw_255)\
- :"memory"\
- );\
-}
-
-#define ABS3_MMX2\
- "psubw %%mm5, %%mm7 \n"\
- "pmaxsw %%mm7, %%mm5 \n"\
- "pxor %%mm6, %%mm6 \n"\
- "pxor %%mm7, %%mm7 \n"\
- "psubw %%mm3, %%mm6 \n"\
- "psubw %%mm4, %%mm7 \n"\
- "pmaxsw %%mm6, %%mm3 \n"\
- "pmaxsw %%mm7, %%mm4 \n"\
- "pxor %%mm7, %%mm7 \n"
-
-#define ABS3_SSSE3\
- "pabsw %%mm3, %%mm3 \n"\
- "pabsw %%mm4, %%mm4 \n"\
- "pabsw %%mm5, %%mm5 \n"
-
-PAETH(mmx2, ABS3_MMX2)
-#if HAVE_SSSE3
-PAETH(ssse3, ABS3_SSSE3)
-#endif
-
#define QPEL_V_LOW(m3,m4,m5,m6, pw_20, pw_3, rnd, in0, in1, in2, in7, out, OP)\
"paddw " #m4 ", " #m3 " \n\t" /* x1 */\
"movq "MANGLE(ff_pw_20)", %%mm4 \n\t" /* 20 */\
@@ -1665,10 +1571,6 @@ QPEL_2TAP(put_, 8, 3dnow)
QPEL_2TAP(avg_, 8, 3dnow)
-#if 0
-static void just_return(void) { return; }
-#endif
-
#if HAVE_YASM
typedef void emu_edge_core_func (uint8_t *buf, const uint8_t *src,
x86_reg linesize, x86_reg start_y,
@@ -1879,7 +1781,7 @@ static void gmc_mmx(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int o
int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height)
{
gmc(dst, src, stride, h, ox, oy, dxx, dxy, dyx, dyy, shift, r,
- width, height, &ff_emulated_edge_mc);
+ width, height, &ff_emulated_edge_mc_8);
}
#endif
@@ -1899,29 +1801,17 @@ PREFETCH(prefetch_3dnow, prefetch)
void ff_put_h264_chroma_mc8_mmx_rnd (uint8_t *dst, uint8_t *src,
int stride, int h, int x, int y);
-void ff_put_rv40_chroma_mc8_mmx (uint8_t *dst, uint8_t *src,
- int stride, int h, int x, int y);
void ff_avg_h264_chroma_mc8_mmx2_rnd (uint8_t *dst, uint8_t *src,
int stride, int h, int x, int y);
-void ff_avg_rv40_chroma_mc8_mmx2 (uint8_t *dst, uint8_t *src,
- int stride, int h, int x, int y);
void ff_avg_h264_chroma_mc8_3dnow_rnd (uint8_t *dst, uint8_t *src,
int stride, int h, int x, int y);
-void ff_avg_rv40_chroma_mc8_3dnow (uint8_t *dst, uint8_t *src,
- int stride, int h, int x, int y);
void ff_put_h264_chroma_mc4_mmx (uint8_t *dst, uint8_t *src,
int stride, int h, int x, int y);
-void ff_put_rv40_chroma_mc4_mmx (uint8_t *dst, uint8_t *src,
- int stride, int h, int x, int y);
void ff_avg_h264_chroma_mc4_mmx2 (uint8_t *dst, uint8_t *src,
int stride, int h, int x, int y);
-void ff_avg_rv40_chroma_mc4_mmx2 (uint8_t *dst, uint8_t *src,
- int stride, int h, int x, int y);
void ff_avg_h264_chroma_mc4_3dnow (uint8_t *dst, uint8_t *src,
int stride, int h, int x, int y);
-void ff_avg_rv40_chroma_mc4_3dnow (uint8_t *dst, uint8_t *src,
- int stride, int h, int x, int y);
void ff_put_h264_chroma_mc2_mmx2 (uint8_t *dst, uint8_t *src,
int stride, int h, int x, int y);
@@ -2441,7 +2331,7 @@ void ff_vector_clip_int32_sse41 (int32_t *dst, const int32_t *src, int32_t min
void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx)
{
int mm_flags = av_get_cpu_flags();
- const int high_bit_depth = avctx->codec_id == CODEC_ID_H264 && avctx->bits_per_raw_sample > 8;
+ const int high_bit_depth = avctx->bits_per_raw_sample > 8;
const int bit_depth = avctx->bits_per_raw_sample;
if (avctx->dsp_mask) {
@@ -2469,7 +2359,7 @@ void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx)
if (mm_flags & AV_CPU_FLAG_MMX) {
const int idct_algo= avctx->idct_algo;
- if(avctx->lowres==0){
+ if (avctx->lowres == 0 && avctx->bits_per_raw_sample <= 8) {
if(idct_algo==FF_IDCT_AUTO || idct_algo==FF_IDCT_SIMPLEMMX){
c->idct_put= ff_simple_idct_put_mmx;
c->idct_add= ff_simple_idct_add_mmx;
@@ -2561,10 +2451,9 @@ void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx)
#endif
c->add_bytes= add_bytes_mmx;
- c->add_bytes_l2= add_bytes_l2_mmx;
if (!high_bit_depth)
- c->draw_edges = draw_edges_mmx;
+ c->draw_edges = draw_edges_mmx;
if (CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
c->h263_v_loop_filter= h263_v_loop_filter_mmx;
@@ -2577,9 +2466,6 @@ void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx)
c->put_h264_chroma_pixels_tab[1]= ff_put_h264_chroma_mc4_mmx;
}
- c->put_rv40_chroma_pixels_tab[0]= ff_put_rv40_chroma_mc8_mmx;
- c->put_rv40_chroma_pixels_tab[1]= ff_put_rv40_chroma_mc4_mmx;
-
c->vector_clip_int32 = ff_vector_clip_int32_mmx;
#endif
@@ -2679,9 +2565,6 @@ void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx)
SET_QPEL_FUNCS(avg_2tap_qpel, 1, 8, mmx2, );
#if HAVE_YASM
- c->avg_rv40_chroma_pixels_tab[0]= ff_avg_rv40_chroma_mc8_mmx2;
- c->avg_rv40_chroma_pixels_tab[1]= ff_avg_rv40_chroma_mc4_mmx2;
-
if (!high_bit_depth) {
c->avg_h264_chroma_pixels_tab[0]= ff_avg_h264_chroma_mc8_mmx2_rnd;
c->avg_h264_chroma_pixels_tab[1]= ff_avg_h264_chroma_mc4_mmx2;
@@ -2698,12 +2581,11 @@ void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx)
c->add_hfyu_median_prediction = ff_add_hfyu_median_prediction_mmx2;
#endif
#if HAVE_7REGS
- if( mm_flags&AV_CPU_FLAG_3DNOW )
+ if (HAVE_AMD3DNOW && (mm_flags & AV_CPU_FLAG_3DNOW))
c->add_hfyu_median_prediction = add_hfyu_median_prediction_cmov;
#endif
- c->add_png_paeth_prediction= add_png_paeth_prediction_mmx2;
- } else if (mm_flags & AV_CPU_FLAG_3DNOW) {
+ } else if (HAVE_AMD3DNOW && (mm_flags & AV_CPU_FLAG_3DNOW)) {
c->prefetch = prefetch_3dnow;
if (!high_bit_depth) {
@@ -2764,8 +2646,6 @@ void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx)
c->avg_h264_chroma_pixels_tab[1]= ff_avg_h264_chroma_mc4_3dnow;
}
- c->avg_rv40_chroma_pixels_tab[0]= ff_avg_rv40_chroma_mc8_3dnow;
- c->avg_rv40_chroma_pixels_tab[1]= ff_avg_rv40_chroma_mc4_3dnow;
#endif
}
@@ -2841,9 +2721,6 @@ void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx)
H264_QPEL_FUNCS_10(2, 0, ssse3_cache64)
H264_QPEL_FUNCS_10(3, 0, ssse3_cache64)
}
-#endif
- c->add_png_paeth_prediction= add_png_paeth_prediction_ssse3;
-#if HAVE_YASM
if (!high_bit_depth) {
c->put_h264_chroma_pixels_tab[0]= ff_put_h264_chroma_mc8_ssse3_rnd;
c->avg_h264_chroma_pixels_tab[0]= ff_avg_h264_chroma_mc8_ssse3_rnd;
@@ -2857,11 +2734,11 @@ void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx)
}
#endif
- if(mm_flags & AV_CPU_FLAG_3DNOW){
+ if (HAVE_AMD3DNOW && (mm_flags & AV_CPU_FLAG_3DNOW)) {
c->vorbis_inverse_coupling = vorbis_inverse_coupling_3dnow;
c->vector_fmul = vector_fmul_3dnow;
}
- if(mm_flags & AV_CPU_FLAG_3DNOWEXT){
+ if (HAVE_AMD3DNOWEXT && (mm_flags & AV_CPU_FLAG_3DNOWEXT)) {
c->vector_fmul_reverse = vector_fmul_reverse_3dnow2;
#if HAVE_6REGS
c->vector_fmul_window = vector_fmul_window_3dnow2;
@@ -2892,7 +2769,7 @@ void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx)
c->scalarproduct_float = ff_scalarproduct_float_sse;
#endif
}
- if(mm_flags & AV_CPU_FLAG_3DNOW)
+ if (HAVE_AMD3DNOW && (mm_flags & AV_CPU_FLAG_3DNOW))
c->vector_fmul_add = vector_fmul_add_3dnow; // faster than sse
if(mm_flags & AV_CPU_FLAG_SSE2){
#if HAVE_YASM
@@ -2953,39 +2830,4 @@ void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx)
if (CONFIG_ENCODERS)
dsputilenc_init_mmx(c, avctx);
-
-#if 0
- // for speed testing
- get_pixels = just_return;
- put_pixels_clamped = just_return;
- add_pixels_clamped = just_return;
-
- pix_abs16x16 = just_return;
- pix_abs16x16_x2 = just_return;
- pix_abs16x16_y2 = just_return;
- pix_abs16x16_xy2 = just_return;
-
- put_pixels_tab[0] = just_return;
- put_pixels_tab[1] = just_return;
- put_pixels_tab[2] = just_return;
- put_pixels_tab[3] = just_return;
-
- put_no_rnd_pixels_tab[0] = just_return;
- put_no_rnd_pixels_tab[1] = just_return;
- put_no_rnd_pixels_tab[2] = just_return;
- put_no_rnd_pixels_tab[3] = just_return;
-
- avg_pixels_tab[0] = just_return;
- avg_pixels_tab[1] = just_return;
- avg_pixels_tab[2] = just_return;
- avg_pixels_tab[3] = just_return;
-
- avg_no_rnd_pixels_tab[0] = just_return;
- avg_no_rnd_pixels_tab[1] = just_return;
- avg_no_rnd_pixels_tab[2] = just_return;
- avg_no_rnd_pixels_tab[3] = just_return;
-
- //av_fdct = just_return;
- //ff_idct = just_return;
-#endif
}
diff --git a/libavcodec/x86/dsputil_mmx.h b/libavcodec/x86/dsputil_mmx.h
index 7ab55e7c51..59a9613609 100644
--- a/libavcodec/x86/dsputil_mmx.h
+++ b/libavcodec/x86/dsputil_mmx.h
@@ -2,20 +2,20 @@
* MMX optimized DSP utils
* Copyright (c) 2007 Aurelien Jacobs <aurel@gnuage.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/x86/dsputil_mmx_avg_template.c b/libavcodec/x86/dsputil_mmx_avg_template.c
index 8b116b74e2..6f768595c0 100644
--- a/libavcodec/x86/dsputil_mmx_avg_template.c
+++ b/libavcodec/x86/dsputil_mmx_avg_template.c
@@ -7,20 +7,20 @@
* mostly rewritten by Michael Niedermayer <michaelni@gmx.at>
* and improved by Zdenek Kabelac <kabi@users.sf.net>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/x86/dsputil_mmx_qns_template.c b/libavcodec/x86/dsputil_mmx_qns_template.c
index 20a40a175e..77a41b9dcb 100644
--- a/libavcodec/x86/dsputil_mmx_qns_template.c
+++ b/libavcodec/x86/dsputil_mmx_qns_template.c
@@ -5,20 +5,20 @@
* MMX optimization by Michael Niedermayer <michaelni@gmx.at>
* 3DNow! and SSSE3 optimization by Zuxy Meng <zuxy.meng@gmail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/x86/dsputil_mmx_rnd_template.c b/libavcodec/x86/dsputil_mmx_rnd_template.c
index 34a2c0bca8..e4c91381fa 100644
--- a/libavcodec/x86/dsputil_mmx_rnd_template.c
+++ b/libavcodec/x86/dsputil_mmx_rnd_template.c
@@ -7,20 +7,20 @@
* mostly rewritten by Michael Niedermayer <michaelni@gmx.at>
* and improved by Zdenek Kabelac <kabi@users.sf.net>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/x86/dsputil_yasm.asm b/libavcodec/x86/dsputil_yasm.asm
index 4e1ec24a7a..6627d21bd8 100644
--- a/libavcodec/x86/dsputil_yasm.asm
+++ b/libavcodec/x86/dsputil_yasm.asm
@@ -2,24 +2,25 @@
;* MMX optimized DSP utils
;* Copyright (c) 2008 Loren Merritt
;*
-;* This file is part of Libav.
+;* This file is part of FFmpeg.
;*
-;* Libav is free software; you can redistribute it and/or
+;* FFmpeg 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.
;*
-;* Libav is distributed in the hope that it will be useful,
+;* FFmpeg 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
;* Lesser General Public License for more details.
;*
;* You should have received a copy of the GNU Lesser General Public
-;* License along with Libav; if not, write to the Free Software
+;* License along with FFmpeg; if not, write to the Free Software
;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
;******************************************************************************
-%include "x86inc.asm"
+%include "libavutil/x86/x86inc.asm"
+%include "x86util.asm"
SECTION_RODATA
pb_f: times 16 db 15
@@ -1054,47 +1055,6 @@ emu_edge mmx
; int32_t max, unsigned int len)
;-----------------------------------------------------------------------------
-%macro PMINSD_MMX 3 ; dst, src, tmp
- mova %3, %2
- pcmpgtd %3, %1
- pxor %1, %2
- pand %1, %3
- pxor %1, %2
-%endmacro
-
-%macro PMAXSD_MMX 3 ; dst, src, tmp
- mova %3, %1
- pcmpgtd %3, %2
- pand %1, %3
- pandn %3, %2
- por %1, %3
-%endmacro
-
-%macro CLIPD_MMX 3-4 ; src/dst, min, max, tmp
- PMINSD_MMX %1, %3, %4
- PMAXSD_MMX %1, %2, %4
-%endmacro
-
-%macro CLIPD_SSE2 3-4 ; src/dst, min (float), max (float), unused
- cvtdq2ps %1, %1
- minps %1, %3
- maxps %1, %2
- cvtps2dq %1, %1
-%endmacro
-
-%macro CLIPD_SSE41 3-4 ; src/dst, min, max, unused
- pminsd %1, %3
- pmaxsd %1, %2
-%endmacro
-
-%macro SPLATD_MMX 1
- punpckldq %1, %1
-%endmacro
-
-%macro SPLATD_SSE2 1
- pshufd %1, %1, 0
-%endmacro
-
%macro VECTOR_CLIP_INT32 4
cglobal vector_clip_int32_%1, 5,5,%2, dst, src, min, max, len
%ifidn %1, sse2
diff --git a/libavcodec/x86/dsputilenc_mmx.c b/libavcodec/x86/dsputilenc_mmx.c
index 037389137b..f13c1219da 100644
--- a/libavcodec/x86/dsputilenc_mmx.c
+++ b/libavcodec/x86/dsputilenc_mmx.c
@@ -3,20 +3,20 @@
* Copyright (c) 2000, 2001 Fabrice Bellard
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* MMX optimization by Nick Kurshev <nickols_k@mail.ru>
@@ -1098,10 +1098,12 @@ static int ssd_int8_vs_int16_mmx(const int8_t *pix1, const int16_t *pix2, int si
void dsputilenc_init_mmx(DSPContext* c, AVCodecContext *avctx)
{
int mm_flags = av_get_cpu_flags();
+ int bit_depth = avctx->bits_per_raw_sample;
if (mm_flags & AV_CPU_FLAG_MMX) {
const int dct_algo = avctx->dct_algo;
- if(dct_algo==FF_DCT_AUTO || dct_algo==FF_DCT_MMX){
+ if (avctx->bits_per_raw_sample <= 8 &&
+ (dct_algo==FF_DCT_AUTO || dct_algo==FF_DCT_MMX)) {
if(mm_flags & AV_CPU_FLAG_SSE2){
c->fdct = ff_fdct_sse2;
}else if(mm_flags & AV_CPU_FLAG_MMX2){
@@ -1111,7 +1113,8 @@ void dsputilenc_init_mmx(DSPContext* c, AVCodecContext *avctx)
}
}
- c->get_pixels = get_pixels_mmx;
+ if (bit_depth <= 8)
+ c->get_pixels = get_pixels_mmx;
c->diff_pixels = diff_pixels_mmx;
c->pix_sum = pix_sum16_mmx;
@@ -1158,7 +1161,8 @@ void dsputilenc_init_mmx(DSPContext* c, AVCodecContext *avctx)
}
if(mm_flags & AV_CPU_FLAG_SSE2){
- c->get_pixels = get_pixels_sse2;
+ if (bit_depth <= 8)
+ c->get_pixels = get_pixels_sse2;
c->sum_abs_dctelem= sum_abs_dctelem_sse2;
#if HAVE_YASM && HAVE_ALIGNED_STACK
c->hadamard8_diff[0]= ff_hadamard8_diff16_sse2;
diff --git a/libavcodec/x86/dsputilenc_yasm.asm b/libavcodec/x86/dsputilenc_yasm.asm
index 6063ff1040..c08f53d39d 100644
--- a/libavcodec/x86/dsputilenc_yasm.asm
+++ b/libavcodec/x86/dsputilenc_yasm.asm
@@ -4,25 +4,25 @@
;* Copyright (c) 2000, 2001 Fabrice Bellard
;* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
;*
-;* This file is part of Libav.
+;* This file is part of FFmpeg.
;*
-;* Libav is free software; you can redistribute it and/or
+;* FFmpeg 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.
;*
-;* Libav is distributed in the hope that it will be useful,
+;* FFmpeg 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
;* Lesser General Public License for more details.
;*
;* You should have received a copy of the GNU Lesser General Public
-;* License along with Libav; if not, write to the Free Software
+;* License along with FFmpeg; if not, write to the Free Software
;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
;*****************************************************************************
-%include "x86inc.asm"
-%include "x86util.asm"
+%include "libavutil/x86/x86inc.asm"
+%include "libavutil/x86/x86util.asm"
SECTION .text
diff --git a/libavcodec/x86/fdct_mmx.c b/libavcodec/x86/fdct_mmx.c
index f35a0591c6..c79a8df04c 100644
--- a/libavcodec/x86/fdct_mmx.c
+++ b/libavcodec/x86/fdct_mmx.c
@@ -13,20 +13,20 @@
* a page about fdct at http://www.geocities.com/ssavekar/dct.htm
* Skal's fdct at http://skal.planet-d.net/coding/dct.html
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/x86/fft.c b/libavcodec/x86/fft.c
index 899f0f7ad5..d2d157c2d3 100644
--- a/libavcodec/x86/fft.c
+++ b/libavcodec/x86/fft.c
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -60,6 +60,8 @@ av_cold void ff_dct_init_mmx(DCTContext *s)
int has_vectors = av_get_cpu_flags();
if (has_vectors & AV_CPU_FLAG_AVX && HAVE_AVX)
s->dct32 = ff_dct32_float_avx;
+ else if (has_vectors & AV_CPU_FLAG_SSE2 && HAVE_SSE)
+ s->dct32 = ff_dct32_float_sse2;
else if (has_vectors & AV_CPU_FLAG_SSE && HAVE_SSE)
s->dct32 = ff_dct32_float_sse;
#endif
diff --git a/libavcodec/x86/fft.h b/libavcodec/x86/fft.h
index 0ade2b2e7b..7fdc858a50 100644
--- a/libavcodec/x86/fft.h
+++ b/libavcodec/x86/fft.h
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -35,6 +35,7 @@ void ff_imdct_calc_sse(FFTContext *s, FFTSample *output, const FFTSample *input)
void ff_imdct_half_sse(FFTContext *s, FFTSample *output, const FFTSample *input);
void ff_imdct_half_avx(FFTContext *s, FFTSample *output, const FFTSample *input);
void ff_dct32_float_sse(FFTSample *out, const FFTSample *in);
+void ff_dct32_float_sse2(FFTSample *out, const FFTSample *in);
void ff_dct32_float_avx(FFTSample *out, const FFTSample *in);
#endif /* AVCODEC_X86_FFT_H */
diff --git a/libavcodec/x86/fft_3dn.c b/libavcodec/x86/fft_3dn.c
index 5a4d3ad2c8..6f2e2e8353 100644
--- a/libavcodec/x86/fft_3dn.c
+++ b/libavcodec/x86/fft_3dn.c
@@ -2,20 +2,20 @@
* FFT/MDCT transform with 3DNow! optimizations
* Copyright (c) 2008 Loren Merritt
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/x86/fft_3dn2.c b/libavcodec/x86/fft_3dn2.c
index 05c0467f08..7a6cac14c4 100644
--- a/libavcodec/x86/fft_3dn2.c
+++ b/libavcodec/x86/fft_3dn2.c
@@ -2,20 +2,20 @@
* FFT/MDCT transform with Extended 3DNow! optimizations
* Copyright (c) 2006-2008 Zuxy MENG Jie, Loren Merritt
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -23,7 +23,7 @@
#include "libavcodec/dsputil.h"
#include "fft.h"
-DECLARE_ALIGNED(8, static const int, m1m1)[2] = { 1<<31, 1<<31 };
+DECLARE_ALIGNED(8, static const unsigned int, m1m1)[2] = { 1U<<31, 1U<<31 };
#ifdef EMULATE_3DNOWEXT
#define PSWAPD(s,d)\
@@ -70,7 +70,7 @@ void ff_imdct_half_3dn2(FFTContext *s, FFTSample *output, const FFTSample *input
in1 = input;
in2 = input + n2 - 1;
#ifdef EMULATE_3DNOWEXT
- __asm__ volatile("movd %0, %%mm7" ::"r"(1<<31));
+ __asm__ volatile("movd %0, %%mm7" ::"r"(1U<<31));
#endif
for(k = 0; k < n4; k++) {
// FIXME a single block is faster, but gcc 2.95 and 3.4.x on 32bit can't compile it
diff --git a/libavcodec/x86/fft_mmx.asm b/libavcodec/x86/fft_mmx.asm
index 27276a1a31..8e5436770e 100644
--- a/libavcodec/x86/fft_mmx.asm
+++ b/libavcodec/x86/fft_mmx.asm
@@ -6,20 +6,20 @@
;* This algorithm (though not any of the implementation details) is
;* based on libdjbfft by D. J. Bernstein.
;*
-;* This file is part of Libav.
+;* This file is part of FFmpeg.
;*
-;* Libav is free software; you can redistribute it and/or
+;* FFmpeg 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.
;*
-;* Libav is distributed in the hope that it will be useful,
+;* FFmpeg 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
;* Lesser General Public License for more details.
;*
;* You should have received a copy of the GNU Lesser General Public
-;* License along with Libav; if not, write to the Free Software
+;* License along with FFmpeg; if not, write to the Free Software
;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
;******************************************************************************
@@ -28,7 +28,7 @@
; in blocks as conventient to the vector size.
; i.e. {4x real, 4x imaginary, 4x real, ...} (or 2x respectively)
-%include "x86inc.asm"
+%include "libavutil/x86/x86inc.asm"
%ifdef ARCH_X86_64
%define pointer resq
@@ -388,6 +388,7 @@ fft32_interleave_avx:
sub r2d, mmsize/4
jg .deint_loop
ret
+
%endif
INIT_XMM
diff --git a/libavcodec/x86/fft_sse.c b/libavcodec/x86/fft_sse.c
index add20dd5b2..43f19fff3b 100644
--- a/libavcodec/x86/fft_sse.c
+++ b/libavcodec/x86/fft_sse.c
@@ -2,20 +2,20 @@
* FFT/MDCT transform with SSE optimizations
* Copyright (c) 2008 Loren Merritt
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -24,8 +24,8 @@
#include "fft.h"
#include "config.h"
-DECLARE_ASM_CONST(16, int, ff_m1m1m1m1)[4] =
- { 1 << 31, 1 << 31, 1 << 31, 1 << 31 };
+DECLARE_ASM_CONST(16, unsigned int, ff_m1m1m1m1)[4] =
+ { 1U << 31, 1U << 31, 1U << 31, 1U << 31 };
void ff_fft_dispatch_sse(FFTComplex *z, int nbits);
void ff_fft_dispatch_interleave_sse(FFTComplex *z, int nbits);
diff --git a/libavcodec/x86/fmtconvert.asm b/libavcodec/x86/fmtconvert.asm
index efab87d570..37e7a094ce 100644
--- a/libavcodec/x86/fmtconvert.asm
+++ b/libavcodec/x86/fmtconvert.asm
@@ -2,28 +2,168 @@
;* x86 optimized Format Conversion Utils
;* Copyright (c) 2008 Loren Merritt
;*
-;* This file is part of Libav.
+;* This file is part of FFmpeg.
;*
-;* Libav is free software; you can redistribute it and/or
+;* FFmpeg 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.
;*
-;* Libav is distributed in the hope that it will be useful,
+;* FFmpeg 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
;* Lesser General Public License for more details.
;*
;* You should have received a copy of the GNU Lesser General Public
-;* License along with Libav; if not, write to the Free Software
+;* License along with FFmpeg; if not, write to the Free Software
;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
;******************************************************************************
-%include "x86inc.asm"
-%include "x86util.asm"
+%include "libavutil/x86/x86inc.asm"
+%include "libavutil/x86/x86util.asm"
SECTION_TEXT
+;---------------------------------------------------------------------------------
+; void int32_to_float_fmul_scalar(float *dst, const int *src, float mul, int len);
+;---------------------------------------------------------------------------------
+%macro INT32_TO_FLOAT_FMUL_SCALAR 2
+%ifdef ARCH_X86_64
+cglobal int32_to_float_fmul_scalar_%1, 3,3,%2, dst, src, len
+%else
+cglobal int32_to_float_fmul_scalar_%1, 4,4,%2, dst, src, mul, len
+ movss m0, mulm
+%endif
+ SPLATD m0
+ shl lenq, 2
+ add srcq, lenq
+ add dstq, lenq
+ neg lenq
+.loop:
+%ifidn %1, sse2
+ cvtdq2ps m1, [srcq+lenq ]
+ cvtdq2ps m2, [srcq+lenq+16]
+%else
+ cvtpi2ps m1, [srcq+lenq ]
+ cvtpi2ps m3, [srcq+lenq+ 8]
+ cvtpi2ps m2, [srcq+lenq+16]
+ cvtpi2ps m4, [srcq+lenq+24]
+ movlhps m1, m3
+ movlhps m2, m4
+%endif
+ mulps m1, m0
+ mulps m2, m0
+ mova [dstq+lenq ], m1
+ mova [dstq+lenq+16], m2
+ add lenq, 32
+ jl .loop
+ REP_RET
+%endmacro
+
+INIT_XMM
+%define SPLATD SPLATD_SSE
+%define movdqa movaps
+INT32_TO_FLOAT_FMUL_SCALAR sse, 5
+%undef movdqa
+%define SPLATD SPLATD_SSE2
+INT32_TO_FLOAT_FMUL_SCALAR sse2, 3
+%undef SPLATD
+
+
+;------------------------------------------------------------------------------
+; void ff_float_to_int16(int16_t *dst, const float *src, long len);
+;------------------------------------------------------------------------------
+%macro FLOAT_TO_INT16 2
+cglobal float_to_int16_%1, 3,3,%2, dst, src, len
+ add lenq, lenq
+ lea srcq, [srcq+2*lenq]
+ add dstq, lenq
+ neg lenq
+.loop:
+%ifidn %1, sse2
+ cvtps2dq m0, [srcq+2*lenq ]
+ cvtps2dq m1, [srcq+2*lenq+16]
+ packssdw m0, m1
+ mova [dstq+lenq], m0
+%else
+ cvtps2pi m0, [srcq+2*lenq ]
+ cvtps2pi m1, [srcq+2*lenq+ 8]
+ cvtps2pi m2, [srcq+2*lenq+16]
+ cvtps2pi m3, [srcq+2*lenq+24]
+ packssdw m0, m1
+ packssdw m2, m3
+ mova [dstq+lenq ], m0
+ mova [dstq+lenq+8], m2
+%endif
+ add lenq, 16
+ js .loop
+%ifnidn %1, sse2
+ emms
+%endif
+ REP_RET
+%endmacro
+
+INIT_XMM
+FLOAT_TO_INT16 sse2, 2
+INIT_MMX
+FLOAT_TO_INT16 sse, 0
+%define cvtps2pi pf2id
+FLOAT_TO_INT16 3dnow, 0
+%undef cvtps2pi
+
+
+;-------------------------------------------------------------------------------
+; void ff_float_to_int16_interleave2(int16_t *dst, const float **src, long len);
+;-------------------------------------------------------------------------------
+%macro FLOAT_TO_INT16_INTERLEAVE2 1
+cglobal float_to_int16_interleave2_%1, 3,4,2, dst, src0, src1, len
+ lea lenq, [4*r2q]
+ mov src1q, [src0q+gprsize]
+ mov src0q, [src0q]
+ add dstq, lenq
+ add src0q, lenq
+ add src1q, lenq
+ neg lenq
+.loop:
+%ifidn %1, sse2
+ cvtps2dq m0, [src0q+lenq]
+ cvtps2dq m1, [src1q+lenq]
+ packssdw m0, m1
+ movhlps m1, m0
+ punpcklwd m0, m1
+ mova [dstq+lenq], m0
+%else
+ cvtps2pi m0, [src0q+lenq ]
+ cvtps2pi m1, [src0q+lenq+8]
+ cvtps2pi m2, [src1q+lenq ]
+ cvtps2pi m3, [src1q+lenq+8]
+ packssdw m0, m1
+ packssdw m2, m3
+ mova m1, m0
+ punpcklwd m0, m2
+ punpckhwd m1, m2
+ mova [dstq+lenq ], m0
+ mova [dstq+lenq+8], m1
+%endif
+ add lenq, 16
+ js .loop
+%ifnidn %1, sse2
+ emms
+%endif
+ REP_RET
+%endmacro
+
+INIT_MMX
+%define cvtps2pi pf2id
+FLOAT_TO_INT16_INTERLEAVE2 3dnow
+%undef cvtps2pi
+%define movdqa movaps
+FLOAT_TO_INT16_INTERLEAVE2 sse
+%undef movdqa
+INIT_XMM
+FLOAT_TO_INT16_INTERLEAVE2 sse2
+
+
%macro PSWAPD_SSE 2
pshufw %1, %2, 0x4e
%endmacro
diff --git a/libavcodec/x86/fmtconvert_mmx.c b/libavcodec/x86/fmtconvert_mmx.c
index 253f60bfc2..a3d8f89816 100644
--- a/libavcodec/x86/fmtconvert_mmx.c
+++ b/libavcodec/x86/fmtconvert_mmx.c
@@ -3,20 +3,20 @@
* Copyright (c) 2000, 2001 Fabrice Bellard
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* MMX optimization by Nick Kurshev <nickols_k@mail.ru>
@@ -26,133 +26,32 @@
#include "libavutil/x86_cpu.h"
#include "libavcodec/fmtconvert.h"
-static void int32_to_float_fmul_scalar_sse(float *dst, const int *src, float mul, int len)
-{
- x86_reg i = -4*len;
- __asm__ volatile(
- "movss %3, %%xmm4 \n"
- "shufps $0, %%xmm4, %%xmm4 \n"
- "1: \n"
- "cvtpi2ps (%2,%0), %%xmm0 \n"
- "cvtpi2ps 8(%2,%0), %%xmm1 \n"
- "cvtpi2ps 16(%2,%0), %%xmm2 \n"
- "cvtpi2ps 24(%2,%0), %%xmm3 \n"
- "movlhps %%xmm1, %%xmm0 \n"
- "movlhps %%xmm3, %%xmm2 \n"
- "mulps %%xmm4, %%xmm0 \n"
- "mulps %%xmm4, %%xmm2 \n"
- "movaps %%xmm0, (%1,%0) \n"
- "movaps %%xmm2, 16(%1,%0) \n"
- "add $32, %0 \n"
- "jl 1b \n"
- :"+r"(i)
- :"r"(dst+len), "r"(src+len), "m"(mul)
- );
-}
-
-static void int32_to_float_fmul_scalar_sse2(float *dst, const int *src, float mul, int len)
-{
- x86_reg i = -4*len;
- __asm__ volatile(
- "movss %3, %%xmm4 \n"
- "shufps $0, %%xmm4, %%xmm4 \n"
- "1: \n"
- "cvtdq2ps (%2,%0), %%xmm0 \n"
- "cvtdq2ps 16(%2,%0), %%xmm1 \n"
- "mulps %%xmm4, %%xmm0 \n"
- "mulps %%xmm4, %%xmm1 \n"
- "movaps %%xmm0, (%1,%0) \n"
- "movaps %%xmm1, 16(%1,%0) \n"
- "add $32, %0 \n"
- "jl 1b \n"
- :"+r"(i)
- :"r"(dst+len), "r"(src+len), "m"(mul)
- );
-}
+#if HAVE_YASM
-static void float_to_int16_3dnow(int16_t *dst, const float *src, long len){
- x86_reg reglen = len;
- // not bit-exact: pf2id uses different rounding than C and SSE
- __asm__ volatile(
- "add %0 , %0 \n\t"
- "lea (%2,%0,2) , %2 \n\t"
- "add %0 , %1 \n\t"
- "neg %0 \n\t"
- "1: \n\t"
- "pf2id (%2,%0,2) , %%mm0 \n\t"
- "pf2id 8(%2,%0,2) , %%mm1 \n\t"
- "pf2id 16(%2,%0,2) , %%mm2 \n\t"
- "pf2id 24(%2,%0,2) , %%mm3 \n\t"
- "packssdw %%mm1 , %%mm0 \n\t"
- "packssdw %%mm3 , %%mm2 \n\t"
- "movq %%mm0 , (%1,%0) \n\t"
- "movq %%mm2 , 8(%1,%0) \n\t"
- "add $16 , %0 \n\t"
- " js 1b \n\t"
- "femms \n\t"
- :"+r"(reglen), "+r"(dst), "+r"(src)
- );
-}
+void ff_int32_to_float_fmul_scalar_sse (float *dst, const int *src, float mul, int len);
+void ff_int32_to_float_fmul_scalar_sse2(float *dst, const int *src, float mul, int len);
-static void float_to_int16_sse(int16_t *dst, const float *src, long len){
- x86_reg reglen = len;
- __asm__ volatile(
- "add %0 , %0 \n\t"
- "lea (%2,%0,2) , %2 \n\t"
- "add %0 , %1 \n\t"
- "neg %0 \n\t"
- "1: \n\t"
- "cvtps2pi (%2,%0,2) , %%mm0 \n\t"
- "cvtps2pi 8(%2,%0,2) , %%mm1 \n\t"
- "cvtps2pi 16(%2,%0,2) , %%mm2 \n\t"
- "cvtps2pi 24(%2,%0,2) , %%mm3 \n\t"
- "packssdw %%mm1 , %%mm0 \n\t"
- "packssdw %%mm3 , %%mm2 \n\t"
- "movq %%mm0 , (%1,%0) \n\t"
- "movq %%mm2 , 8(%1,%0) \n\t"
- "add $16 , %0 \n\t"
- " js 1b \n\t"
- "emms \n\t"
- :"+r"(reglen), "+r"(dst), "+r"(src)
- );
-}
+void ff_float_to_int16_3dnow(int16_t *dst, const float *src, long len);
+void ff_float_to_int16_sse (int16_t *dst, const float *src, long len);
+void ff_float_to_int16_sse2 (int16_t *dst, const float *src, long len);
-static void float_to_int16_sse2(int16_t *dst, const float *src, long len){
- x86_reg reglen = len;
- __asm__ volatile(
- "add %0 , %0 \n\t"
- "lea (%2,%0,2) , %2 \n\t"
- "add %0 , %1 \n\t"
- "neg %0 \n\t"
- "1: \n\t"
- "cvtps2dq (%2,%0,2) , %%xmm0 \n\t"
- "cvtps2dq 16(%2,%0,2) , %%xmm1 \n\t"
- "packssdw %%xmm1 , %%xmm0 \n\t"
- "movdqa %%xmm0 , (%1,%0) \n\t"
- "add $16 , %0 \n\t"
- " js 1b \n\t"
- :"+r"(reglen), "+r"(dst), "+r"(src)
- );
-}
+void ff_float_to_int16_interleave2_3dnow(int16_t *dst, const float **src, long len);
+void ff_float_to_int16_interleave2_sse (int16_t *dst, const float **src, long len);
+void ff_float_to_int16_interleave2_sse2 (int16_t *dst, const float **src, long len);
void ff_float_to_int16_interleave6_sse(int16_t *dst, const float **src, int len);
void ff_float_to_int16_interleave6_3dnow(int16_t *dst, const float **src, int len);
void ff_float_to_int16_interleave6_3dn2(int16_t *dst, const float **src, int len);
-#if !HAVE_YASM
-#define ff_float_to_int16_interleave6_sse(a,b,c) float_to_int16_interleave_misc_sse(a,b,c,6)
-#define ff_float_to_int16_interleave6_3dnow(a,b,c) float_to_int16_interleave_misc_3dnow(a,b,c,6)
-#define ff_float_to_int16_interleave6_3dn2(a,b,c) float_to_int16_interleave_misc_3dnow(a,b,c,6)
-#endif
#define ff_float_to_int16_interleave6_sse2 ff_float_to_int16_interleave6_sse
-#define FLOAT_TO_INT16_INTERLEAVE(cpu, body) \
+#define FLOAT_TO_INT16_INTERLEAVE(cpu) \
/* gcc pessimizes register allocation if this is in the same function as float_to_int16_interleave_sse2*/\
static av_noinline void float_to_int16_interleave_misc_##cpu(int16_t *dst, const float **src, long len, int channels){\
DECLARE_ALIGNED(16, int16_t, tmp)[len];\
int i,j,c;\
for(c=0; c<channels; c++){\
- float_to_int16_##cpu(tmp, src[c], len);\
+ ff_float_to_int16_##cpu(tmp, src[c], len);\
for(i=0, j=c; i<len; i++, j+=channels)\
dst[j] = tmp[i];\
}\
@@ -160,73 +59,18 @@ static av_noinline void float_to_int16_interleave_misc_##cpu(int16_t *dst, const
\
static void float_to_int16_interleave_##cpu(int16_t *dst, const float **src, long len, int channels){\
if(channels==1)\
- float_to_int16_##cpu(dst, src[0], len);\
+ ff_float_to_int16_##cpu(dst, src[0], len);\
else if(channels==2){\
- x86_reg reglen = len; \
- const float *src0 = src[0];\
- const float *src1 = src[1];\
- __asm__ volatile(\
- "shl $2, %0 \n"\
- "add %0, %1 \n"\
- "add %0, %2 \n"\
- "add %0, %3 \n"\
- "neg %0 \n"\
- body\
- :"+r"(reglen), "+r"(dst), "+r"(src0), "+r"(src1)\
- );\
+ ff_float_to_int16_interleave2_##cpu(dst, src, len);\
}else if(channels==6){\
ff_float_to_int16_interleave6_##cpu(dst, src, len);\
}else\
float_to_int16_interleave_misc_##cpu(dst, src, len, channels);\
}
-FLOAT_TO_INT16_INTERLEAVE(3dnow,
- "1: \n"
- "pf2id (%2,%0), %%mm0 \n"
- "pf2id 8(%2,%0), %%mm1 \n"
- "pf2id (%3,%0), %%mm2 \n"
- "pf2id 8(%3,%0), %%mm3 \n"
- "packssdw %%mm1, %%mm0 \n"
- "packssdw %%mm3, %%mm2 \n"
- "movq %%mm0, %%mm1 \n"
- "punpcklwd %%mm2, %%mm0 \n"
- "punpckhwd %%mm2, %%mm1 \n"
- "movq %%mm0, (%1,%0)\n"
- "movq %%mm1, 8(%1,%0)\n"
- "add $16, %0 \n"
- "js 1b \n"
- "femms \n"
-)
-
-FLOAT_TO_INT16_INTERLEAVE(sse,
- "1: \n"
- "cvtps2pi (%2,%0), %%mm0 \n"
- "cvtps2pi 8(%2,%0), %%mm1 \n"
- "cvtps2pi (%3,%0), %%mm2 \n"
- "cvtps2pi 8(%3,%0), %%mm3 \n"
- "packssdw %%mm1, %%mm0 \n"
- "packssdw %%mm3, %%mm2 \n"
- "movq %%mm0, %%mm1 \n"
- "punpcklwd %%mm2, %%mm0 \n"
- "punpckhwd %%mm2, %%mm1 \n"
- "movq %%mm0, (%1,%0)\n"
- "movq %%mm1, 8(%1,%0)\n"
- "add $16, %0 \n"
- "js 1b \n"
- "emms \n"
-)
-
-FLOAT_TO_INT16_INTERLEAVE(sse2,
- "1: \n"
- "cvtps2dq (%2,%0), %%xmm0 \n"
- "cvtps2dq (%3,%0), %%xmm1 \n"
- "packssdw %%xmm1, %%xmm0 \n"
- "movhlps %%xmm0, %%xmm1 \n"
- "punpcklwd %%xmm1, %%xmm0 \n"
- "movdqa %%xmm0, (%1,%0) \n"
- "add $16, %0 \n"
- "js 1b \n"
-)
+FLOAT_TO_INT16_INTERLEAVE(3dnow)
+FLOAT_TO_INT16_INTERLEAVE(sse)
+FLOAT_TO_INT16_INTERLEAVE(sse2)
static void float_to_int16_interleave_3dn2(int16_t *dst, const float **src, long len, int channels){
if(channels==6)
@@ -235,7 +79,6 @@ static void float_to_int16_interleave_3dn2(int16_t *dst, const float **src, long
float_to_int16_interleave_3dnow(dst, src, len, channels);
}
-#if HAVE_YASM
void ff_float_interleave2_mmx(float *dst, const float **src, unsigned int len);
void ff_float_interleave2_sse(float *dst, const float **src, unsigned int len);
@@ -269,34 +112,32 @@ void ff_fmt_convert_init_x86(FmtConvertContext *c, AVCodecContext *avctx)
{
int mm_flags = av_get_cpu_flags();
- if (mm_flags & AV_CPU_FLAG_MMX) {
#if HAVE_YASM
+ if (mm_flags & AV_CPU_FLAG_MMX) {
c->float_interleave = float_interleave_mmx;
-#endif
- if(mm_flags & AV_CPU_FLAG_3DNOW){
+ if (HAVE_AMD3DNOW && mm_flags & AV_CPU_FLAG_3DNOW) {
if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
- c->float_to_int16 = float_to_int16_3dnow;
+ c->float_to_int16 = ff_float_to_int16_3dnow;
c->float_to_int16_interleave = float_to_int16_interleave_3dnow;
}
}
- if(mm_flags & AV_CPU_FLAG_3DNOWEXT){
+ if (HAVE_AMD3DNOWEXT && mm_flags & AV_CPU_FLAG_3DNOWEXT) {
if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
c->float_to_int16_interleave = float_to_int16_interleave_3dn2;
}
}
- if(mm_flags & AV_CPU_FLAG_SSE){
- c->int32_to_float_fmul_scalar = int32_to_float_fmul_scalar_sse;
- c->float_to_int16 = float_to_int16_sse;
+ if (HAVE_SSE && mm_flags & AV_CPU_FLAG_SSE) {
+ c->int32_to_float_fmul_scalar = ff_int32_to_float_fmul_scalar_sse;
+ c->float_to_int16 = ff_float_to_int16_sse;
c->float_to_int16_interleave = float_to_int16_interleave_sse;
-#if HAVE_YASM
c->float_interleave = float_interleave_sse;
-#endif
}
- if(mm_flags & AV_CPU_FLAG_SSE2){
- c->int32_to_float_fmul_scalar = int32_to_float_fmul_scalar_sse2;
- c->float_to_int16 = float_to_int16_sse2;
+ if (HAVE_SSE && mm_flags & AV_CPU_FLAG_SSE2) {
+ c->int32_to_float_fmul_scalar = ff_int32_to_float_fmul_scalar_sse2;
+ c->float_to_int16 = ff_float_to_int16_sse2;
c->float_to_int16_interleave = float_to_int16_interleave_sse2;
}
}
+#endif
}
diff --git a/libavcodec/x86/h264_chromamc.asm b/libavcodec/x86/h264_chromamc.asm
index 0a37994fb9..72aecc0163 100644
--- a/libavcodec/x86/h264_chromamc.asm
+++ b/libavcodec/x86/h264_chromamc.asm
@@ -3,25 +3,25 @@
;* Copyright (c) 2005 Zoltan Hidvegi <hzoli -a- hzoli -d- com>,
;* 2005-2008 Loren Merritt
;*
-;* This file is part of Libav.
+;* This file is part of FFmpeg.
;*
-;* Libav is free software; you can redistribute it and/or
+;* FFmpeg 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.
;*
-;* Libav is distributed in the hope that it will be useful,
+;* FFmpeg 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
;* Lesser General Public License for more details.
;*
;* You should have received a copy of the GNU Lesser General Public
-;* License along with Libav; if not, write to the Free Software
+;* License along with FFmpeg; if not, write to the Free Software
;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
;******************************************************************************
-%include "x86inc.asm"
-%include "x86util.asm"
+%include "libavutil/x86/x86inc.asm"
+%include "libavutil/x86/x86util.asm"
SECTION_RODATA
@@ -72,17 +72,17 @@ SECTION .text
.next4rows
movq mm0, [r1 ]
movq mm1, [r1+r2]
+ add r1, r4
CHROMAMC_AVG mm0, [r0 ]
CHROMAMC_AVG mm1, [r0+r2]
movq [r0 ], mm0
movq [r0+r2], mm1
add r0, r4
- add r1, r4
movq mm0, [r1 ]
movq mm1, [r1+r2]
+ add r1, r4
CHROMAMC_AVG mm0, [r0 ]
CHROMAMC_AVG mm1, [r0+r2]
- add r1, r4
movq [r0 ], mm0
movq [r0+r2], mm1
add r0, r4
@@ -472,8 +472,8 @@ cglobal %1_%2_chroma_mc8_%3, 6, 7, 8
mov r6d, r4d
shl r4d, 8
sub r4, r6
- add r4, 8 ; x*288+8 = x<<8 | (8-x)
mov r6, 8
+ add r4, 8 ; x*288+8 = x<<8 | (8-x)
sub r6d, r5d
imul r6, r4 ; (8-y)*(x*255+8) = (8-y)*x<<8 | (8-y)*(8-x)
imul r4d, r5d ; y *(x*255+8) = y *x<<8 | y *(8-x)
@@ -481,24 +481,23 @@ cglobal %1_%2_chroma_mc8_%3, 6, 7, 8
movd m7, r6d
movd m6, r4d
movdqa m5, [rnd_2d_%2]
+ movq m0, [r1 ]
+ movq m1, [r1+1]
pshuflw m7, m7, 0
pshuflw m6, m6, 0
+ punpcklbw m0, m1
movlhps m7, m7
movlhps m6, m6
- movq m0, [r1 ]
- movq m1, [r1 +1]
- punpcklbw m0, m1
- add r1, r2
.next2rows
- movq m1, [r1 ]
- movq m2, [r1 +1]
- movq m3, [r1+r2 ]
- movq m4, [r1+r2+1]
+ movq m1, [r1+r2*1 ]
+ movq m2, [r1+r2*1+1]
+ movq m3, [r1+r2*2 ]
+ movq m4, [r1+r2*2+1]
lea r1, [r1+r2*2]
punpcklbw m1, m2
- punpcklbw m3, m4
movdqa m2, m1
+ punpcklbw m3, m4
movdqa m4, m3
pmaddubsw m0, m7
pmaddubsw m1, m6
@@ -508,8 +507,8 @@ cglobal %1_%2_chroma_mc8_%3, 6, 7, 8
paddw m2, m5
paddw m1, m0
paddw m3, m2
- movdqa m0, m4
psrlw m1, 6
+ movdqa m0, m4
psrlw m3, 6
%ifidn %1, avg
movq m2, [r0 ]
@@ -576,6 +575,7 @@ cglobal %1_%2_chroma_mc8_%3, 6, 7, 8
movq m1, [r1+r2 ]
movdqa m2, m1
movq m3, [r1+r2*2]
+ lea r1, [r1+r2*2]
punpcklbw m0, m1
punpcklbw m2, m3
pmaddubsw m0, m7
@@ -594,7 +594,6 @@ cglobal %1_%2_chroma_mc8_%3, 6, 7, 8
movhps [r0+r2], m0
sub r3d, 2
lea r0, [r0+r2*2]
- lea r1, [r1+r2*2]
jg .next2yrows
REP_RET
%endmacro
@@ -607,8 +606,8 @@ cglobal %1_%2_chroma_mc4_%3, 6, 7, 0
mov r6, r4
shl r4d, 8
sub r4d, r6d
- add r4d, 8 ; x*288+8
mov r6, 8
+ add r4d, 8 ; x*288+8
sub r6d, r5d
imul r6d, r4d ; (8-y)*(x*255+8) = (8-y)*x<<8 | (8-y)*(8-x)
imul r4d, r5d ; y *(x*255+8) = y *x<<8 | y *(8-x)
@@ -616,17 +615,16 @@ cglobal %1_%2_chroma_mc4_%3, 6, 7, 0
movd m7, r6d
movd m6, r4d
movq m5, [pw_32]
+ movd m0, [r1 ]
pshufw m7, m7, 0
+ punpcklbw m0, [r1+1]
pshufw m6, m6, 0
- movd m0, [r1 ]
- punpcklbw m0, [r1 +1]
- add r1, r2
.next2rows
- movd m1, [r1 ]
- movd m3, [r1+r2 ]
- punpcklbw m1, [r1 +1]
- punpcklbw m3, [r1+r2+1]
+ movd m1, [r1+r2*1 ]
+ movd m3, [r1+r2*2 ]
+ punpcklbw m1, [r1+r2*1+1]
+ punpcklbw m3, [r1+r2*2+1]
lea r1, [r1+r2*2]
movq m2, m1
movq m4, m3
@@ -638,8 +636,8 @@ cglobal %1_%2_chroma_mc4_%3, 6, 7, 0
paddw m2, m5
paddw m1, m0
paddw m3, m2
- movq m0, m4
psrlw m1, 6
+ movq m0, m4
psrlw m3, 6
packuswb m1, m1
packuswb m3, m3
diff --git a/libavcodec/x86/h264_deblock.asm b/libavcodec/x86/h264_deblock.asm
index 9831ca2cd6..9595c0ab55 100644
--- a/libavcodec/x86/h264_deblock.asm
+++ b/libavcodec/x86/h264_deblock.asm
@@ -7,25 +7,25 @@
;* Jason Garrett-Glaser <darkshikari@gmail.com>
;* Oskar Arvidsson <oskar@irock.se>
;*
-;* This file is part of Libav.
+;* This file is part of FFmpeg.
;*
-;* Libav is free software; you can redistribute it and/or
+;* FFmpeg 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.
;*
-;* Libav is distributed in the hope that it will be useful,
+;* FFmpeg 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
;* Lesser General Public License for more details.
;*
;* You should have received a copy of the GNU Lesser General Public
-;* License along with Libav; if not, write to the Free Software
+;* License along with FFmpeg; if not, write to the Free Software
;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
;******************************************************************************
-%include "x86inc.asm"
-%include "x86util.asm"
+%include "libavutil/x86/x86inc.asm"
+%include "libavutil/x86/x86util.asm"
SECTION .text
@@ -240,17 +240,17 @@ cextern pb_A1
; out: m1=p0' m2=q0'
; clobbers: m0,3-6
%macro DEBLOCK_P0_Q0 0
- pxor m5, m1, m2 ; p0^q0
- pand m5, [pb_1] ; (p0^q0)&1
pcmpeqb m4, m4
+ pxor m5, m1, m2 ; p0^q0
pxor m3, m4
+ pand m5, [pb_1] ; (p0^q0)&1
pavgb m3, m0 ; (p1 - q1 + 256)>>1
- pavgb m3, [pb_3] ; (((p1 - q1 + 256)>>1)+4)>>1 = 64+2+(p1-q1)>>2
pxor m4, m1
+ pavgb m3, [pb_3] ; (((p1 - q1 + 256)>>1)+4)>>1 = 64+2+(p1-q1)>>2
pavgb m4, m2 ; (q0 - p0 + 256)>>1
pavgb m3, m5
- paddusb m3, m4 ; d+128+33
mova m6, [pb_A1]
+ paddusb m3, m4 ; d+128+33
psubusb m6, m3
psubusb m3, [pb_A1]
pminub m6, m7
@@ -386,8 +386,10 @@ cglobal deblock_h_luma_8_%1, 5,7
INIT_XMM
DEBLOCK_LUMA sse2
+%ifdef HAVE_AVX
INIT_AVX
DEBLOCK_LUMA avx
+%endif
%else
@@ -411,16 +413,16 @@ cglobal deblock_%2_luma_8_%1, 5,5
LOAD_MASK r2, r3
mov r3, r4mp
+ pcmpeqb m3, m3
movd m4, [r3] ; tc0
punpcklbw m4, m4
punpcklbw m4, m4 ; tc = 4x tc0[3], 4x tc0[2], 4x tc0[1], 4x tc0[0]
mova [esp+%3], m4 ; tc
- pcmpeqb m3, m3
pcmpgtb m4, m3
+ mova m3, [r4] ; p2
pand m4, m7
mova [esp], m4 ; mask
- mova m3, [r4] ; p2
DIFF_GT2 m1, m3, m5, m6, m7 ; |p2-p0| > beta-1
pand m6, m4
pand m4, [esp+%3] ; tc
@@ -430,11 +432,10 @@ cglobal deblock_%2_luma_8_%1, 5,5
mova m4, [r0+2*r1] ; q2
DIFF_GT2 m2, m4, m5, m6, m3 ; |q2-q0| > beta-1
- mova m5, [esp] ; mask
- pand m6, m5
+ pand m6, [esp] ; mask
mova m5, [esp+%3] ; tc
- pand m5, m6
psubb m7, m6
+ pand m5, m6
mova m3, [r0+r1]
LUMA_Q1 m3, m4, [r0+2*r1], [r0+r1], m5, m6
@@ -482,10 +483,10 @@ cglobal deblock_h_luma_8_%1, 0,5
; transpose 16x4 -> original space (only the middle 4 rows were changed by the filter)
mov r0, r0mp
sub r0, 2
- lea r1, [r0+r4]
movq m0, [pix_tmp+0x10]
movq m1, [pix_tmp+0x20]
+ lea r1, [r0+r4]
movq m2, [pix_tmp+0x30]
movq m3, [pix_tmp+0x40]
TRANSPOSE8x4B_STORE PASS8ROWS(r0, r1, r3, r4)
@@ -506,8 +507,10 @@ INIT_MMX
DEBLOCK_LUMA mmxext, v8, 8
INIT_XMM
DEBLOCK_LUMA sse2, v, 16
+%ifdef HAVE_AVX
INIT_AVX
DEBLOCK_LUMA avx, v, 16
+%endif
%endif ; ARCH
@@ -778,8 +781,10 @@ cglobal deblock_h_luma_intra_8_%1, 2,4
INIT_XMM
DEBLOCK_LUMA_INTRA sse2, v
+%ifdef HAVE_AVX
INIT_AVX
DEBLOCK_LUMA_INTRA avx , v
+%endif
%ifndef ARCH_X86_64
INIT_MMX
DEBLOCK_LUMA_INTRA mmxext, v8
diff --git a/libavcodec/x86/h264_deblock_10bit.asm b/libavcodec/x86/h264_deblock_10bit.asm
index baac725eec..b34867a36d 100644
--- a/libavcodec/x86/h264_deblock_10bit.asm
+++ b/libavcodec/x86/h264_deblock_10bit.asm
@@ -24,8 +24,8 @@
;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
;******************************************************************************
-%include "x86inc.asm"
-%include "x86util.asm"
+%include "libavutil/x86/x86inc.asm"
+%include "libavutil/x86/x86util.asm"
SECTION_RODATA
@@ -165,7 +165,7 @@ cglobal deblock_v_luma_10_%1, 5,5,8*(mmsize/16)
SUB rsp, pad
shl r2d, 2
shl r3d, 2
- LOAD_AB m4, m5, r2, r3
+ LOAD_AB m4, m5, r2d, r3d
mov r3, 32/mmsize
mov r2, r0
sub r0, r1
@@ -222,7 +222,7 @@ cglobal deblock_h_luma_10_%1, 5,6,8*(mmsize/16)
SUB rsp, pad
shl r2d, 2
shl r3d, 2
- LOAD_AB m4, m5, r2, r3
+ LOAD_AB m4, m5, r2d, r3d
mov r3, r1
mova am, m4
add r3, r1
@@ -352,7 +352,7 @@ cglobal deblock_v_luma_10_%1, 5,5,15
%define mask2 m11
shl r2d, 2
shl r3d, 2
- LOAD_AB m12, m13, r2, r3
+ LOAD_AB m12, m13, r2d, r3d
mov r2, r0
sub r0, r1
sub r0, r1
@@ -380,7 +380,7 @@ cglobal deblock_v_luma_10_%1, 5,5,15
cglobal deblock_h_luma_10_%1, 5,7,15
shl r2d, 2
shl r3d, 2
- LOAD_AB m12, m13, r2, r3
+ LOAD_AB m12, m13, r2d, r3d
mov r2, r1
add r2, r1
add r2, r1
@@ -419,9 +419,11 @@ cglobal deblock_h_luma_10_%1, 5,7,15
INIT_XMM
DEBLOCK_LUMA_64 sse2
+%ifdef HAVE_AVX
INIT_AVX
DEBLOCK_LUMA_64 avx
%endif
+%endif
%macro SWAPMOVA 2
%ifid %1
@@ -714,8 +716,10 @@ cglobal deblock_h_luma_intra_10_%1, 4,7,16
INIT_XMM
DEBLOCK_LUMA_INTRA_64 sse2
+%ifdef HAVE_AVX
INIT_AVX
DEBLOCK_LUMA_INTRA_64 avx
+%endif
%endif
@@ -799,10 +803,12 @@ DEBLOCK_LUMA_INTRA mmxext
INIT_XMM
DEBLOCK_LUMA sse2
DEBLOCK_LUMA_INTRA sse2
+%ifdef HAVE_AVX
INIT_AVX
DEBLOCK_LUMA avx
DEBLOCK_LUMA_INTRA avx
%endif
+%endif
; in: %1=p0, %2=q0, %3=p1, %4=q1, %5=mask, %6=tmp, %7=tmp
; out: %1=p0', %2=q0'
@@ -858,7 +864,7 @@ cglobal deblock_v_chroma_10_%1, 5,7-(mmsize/16),8*(mmsize/16)
.loop:
%endif
CHROMA_V_LOAD r5
- LOAD_AB m4, m5, r2, r3
+ LOAD_AB m4, m5, r2d, r3d
LOAD_MASK m0, m1, m2, m3, m4, m5, m7, m6, m4
pxor m4, m4
CHROMA_V_LOAD_TC m6, r4
@@ -892,7 +898,7 @@ cglobal deblock_v_chroma_intra_10_%1, 4,6-(mmsize/16),8*(mmsize/16)
.loop:
%endif
CHROMA_V_LOAD r4
- LOAD_AB m4, m5, r2, r3
+ LOAD_AB m4, m5, r2d, r3d
LOAD_MASK m0, m1, m2, m3, m4, m5, m7, m6, m4
CHROMA_DEBLOCK_P0_Q0_INTRA m1, m2, m0, m3, m7, m5, m6
CHROMA_V_STORE
@@ -913,5 +919,7 @@ DEBLOCK_CHROMA mmxext
%endif
INIT_XMM
DEBLOCK_CHROMA sse2
+%ifdef HAVE_AVX
INIT_AVX
DEBLOCK_CHROMA avx
+%endif
diff --git a/libavcodec/x86/h264_i386.h b/libavcodec/x86/h264_i386.h
index 9c86210371..8ea430a82a 100644
--- a/libavcodec/x86/h264_i386.h
+++ b/libavcodec/x86/h264_i386.h
@@ -2,20 +2,20 @@
* H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder
* Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -45,23 +45,18 @@ static int decode_significance_x86(CABACContext *c, int max_coeff,
int minusindex= 4-(intptr_t)index;
int bit;
x86_reg coeff_count;
- int low;
- int range;
__asm__ volatile(
- "movl %a11(%6), %5 \n\t"
- "movl %a12(%6), %3 \n\t"
-
"2: \n\t"
BRANCHLESS_GET_CABAC("%4", "%6", "(%1)", "%3",
- "%w3", "%5", "%k0", "%b0", "%a13")
+ "%w3", "%5", "%k0", "%b0", "%a11")
"test $1, %4 \n\t"
" jz 3f \n\t"
"add %10, %1 \n\t"
BRANCHLESS_GET_CABAC("%4", "%6", "(%1)", "%3",
- "%w3", "%5", "%k0", "%b0", "%a13")
+ "%w3", "%5", "%k0", "%b0", "%a11")
"sub %10, %1 \n\t"
"mov %2, %0 \n\t"
@@ -72,8 +67,7 @@ static int decode_significance_x86(CABACContext *c, int max_coeff,
"test $1, %4 \n\t"
" jnz 4f \n\t"
- "add $4, %0 \n\t"
- "mov %0, %2 \n\t"
+ "add"OPSIZE" $4, %2 \n\t"
"3: \n\t"
"add $1, %1 \n\t"
@@ -86,13 +80,9 @@ static int decode_significance_x86(CABACContext *c, int max_coeff,
"4: \n\t"
"add %9, %k0 \n\t"
"shr $2, %k0 \n\t"
-
- "movl %5, %a11(%6) \n\t"
- "movl %3, %a12(%6) \n\t"
:"=&q"(coeff_count), "+r"(significant_coeff_ctx_base), "+m"(index),
- "=&r"(low), "=&r"(bit), "=&r"(range)
+ "+&r"(c->low), "=&r"(bit), "+&r"(c->range)
:"r"(c), "m"(minusstart), "m"(end), "m"(minusindex), "m"(last_off),
- "i"(offsetof(CABACContext, range)), "i"(offsetof(CABACContext, low)),
"i"(offsetof(CABACContext, bytestream))
: "%"REG_c, "memory"
);
@@ -101,18 +91,13 @@ static int decode_significance_x86(CABACContext *c, int max_coeff,
static int decode_significance_8x8_x86(CABACContext *c,
uint8_t *significant_coeff_ctx_base,
- int *index, x86_reg last_off, const uint8_t *sig_off){
+ int *index, uint8_t *last_coeff_ctx_base, const uint8_t *sig_off){
int minusindex= 4-(intptr_t)index;
int bit;
x86_reg coeff_count;
- int low;
- int range;
x86_reg last=0;
x86_reg state;
__asm__ volatile(
- "movl %a12(%7), %5 \n\t"
- "movl %a13(%7), %3 \n\t"
-
"mov %1, %6 \n\t"
"2: \n\t"
@@ -121,18 +106,17 @@ static int decode_significance_8x8_x86(CABACContext *c,
"add %9, %6 \n\t"
BRANCHLESS_GET_CABAC("%4", "%7", "(%6)", "%3",
- "%w3", "%5", "%k0", "%b0", "%a14")
+ "%w3", "%5", "%k0", "%b0", "%a12")
"mov %1, %k6 \n\t"
"test $1, %4 \n\t"
" jz 3f \n\t"
"movzbl "MANGLE(last_coeff_flag_offset_8x8)"(%k6), %k6\n\t"
- "add %9, %6 \n\t"
"add %11, %6 \n\t"
BRANCHLESS_GET_CABAC("%4", "%7", "(%6)", "%3",
- "%w3", "%5", "%k0", "%b0", "%a14")
+ "%w3", "%5", "%k0", "%b0", "%a12")
"mov %2, %0 \n\t"
"mov %1, %k6 \n\t"
@@ -141,8 +125,7 @@ static int decode_significance_8x8_x86(CABACContext *c,
"test $1, %4 \n\t"
" jnz 4f \n\t"
- "add $4, %0 \n\t"
- "mov %0, %2 \n\t"
+ "add"OPSIZE" $4, %2 \n\t"
"3: \n\t"
"addl $1, %k6 \n\t"
@@ -154,13 +137,9 @@ static int decode_significance_8x8_x86(CABACContext *c,
"4: \n\t"
"addl %8, %k0 \n\t"
"shr $2, %k0 \n\t"
-
- "movl %5, %a12(%7) \n\t"
- "movl %3, %a13(%7) \n\t"
- :"=&q"(coeff_count),"+m"(last), "+m"(index), "=&r"(low), "=&r"(bit),
- "=&r"(range), "=&r"(state)
- :"r"(c), "m"(minusindex), "m"(significant_coeff_ctx_base), "m"(sig_off), "m"(last_off),
- "i"(offsetof(CABACContext, range)), "i"(offsetof(CABACContext, low)),
+ :"=&q"(coeff_count),"+m"(last), "+m"(index), "+&r"(c->low), "=&r"(bit),
+ "+&r"(c->range), "=&r"(state)
+ :"r"(c), "m"(minusindex), "m"(significant_coeff_ctx_base), "m"(sig_off), "m"(last_coeff_ctx_base),
"i"(offsetof(CABACContext, bytestream))
: "%"REG_c, "memory"
);
diff --git a/libavcodec/x86/h264_idct.asm b/libavcodec/x86/h264_idct.asm
index 4788da98e0..dd13bcd72f 100644
--- a/libavcodec/x86/h264_idct.asm
+++ b/libavcodec/x86/h264_idct.asm
@@ -9,25 +9,25 @@
;* Holger Lubitz <hal@duncan.ol.sub.de>
;* Min Chen <chenm001.163.com>
;*
-;* This file is part of Libav.
+;* This file is part of FFmpeg.
;*
-;* Libav is free software; you can redistribute it and/or
+;* FFmpeg 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.
;*
-;* Libav is distributed in the hope that it will be useful,
+;* FFmpeg 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
;* Lesser General Public License for more details.
;*
;* You should have received a copy of the GNU Lesser General Public
-;* License along with Libav; if not, write to the Free Software
+;* License along with FFmpeg; if not, write to the Free Software
;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
;*****************************************************************************
-%include "x86inc.asm"
-%include "x86util.asm"
+%include "libavutil/x86/x86inc.asm"
+%include "libavutil/x86/x86util.asm"
SECTION_RODATA
@@ -82,10 +82,10 @@ cglobal h264_idct_add_8_mmx, 3, 3, 0
RET
%macro IDCT8_1D 2
- mova m4, m5
mova m0, m1
- psraw m4, 1
psraw m1, 1
+ mova m4, m5
+ psraw m4, 1
paddw m4, m5
paddw m1, m0
paddw m4, m7
@@ -95,16 +95,16 @@ cglobal h264_idct_add_8_mmx, 3, 3, 0
psubw m0, m3
psubw m5, m3
+ psraw m3, 1
paddw m0, m7
psubw m5, m7
- psraw m3, 1
psraw m7, 1
psubw m0, m3
psubw m5, m7
- mova m3, m4
mova m7, m1
psraw m1, 2
+ mova m3, m4
psraw m3, 2
paddw m3, m0
psraw m0, 2
@@ -113,12 +113,12 @@ cglobal h264_idct_add_8_mmx, 3, 3, 0
psubw m0, m4
psubw m7, m5
- mova m4, m2
mova m5, m6
- psraw m4, 1
psraw m6, 1
- psubw m4, m5
+ mova m4, m2
+ psraw m4, 1
paddw m6, m2
+ psubw m4, m5
mova m2, %1
mova m5, %2
@@ -337,7 +337,7 @@ cglobal h264_idct8_add4_8_mmx, 5, 7, 0
test r6, r6
jz .skipblock
mov r6d, dword [r1+r5*4]
- lea r6, [r0+r6]
+ add r6, r0
add word [r2], 32
IDCT8_ADD_MMX_START r2 , rsp
IDCT8_ADD_MMX_START r2+8, rsp+64
@@ -391,7 +391,7 @@ cglobal h264_idct_add16_8_mmx2, 5, 7, 0
REP_RET
.no_dc
mov r6d, dword [r1+r5*4]
- lea r6, [r0+r6]
+ add r6, r0
IDCT4_ADD r6, r2, r3
.skipblock
inc r5
@@ -414,7 +414,7 @@ cglobal h264_idct_add16intra_8_mmx, 5, 7, 0
test r6, r6
jz .skipblock
mov r6d, dword [r1+r5*4]
- lea r6, [r0+r6]
+ add r6, r0
IDCT4_ADD r6, r2, r3
.skipblock
inc r5
@@ -456,7 +456,7 @@ cglobal h264_idct_add16intra_8_mmx2, 5, 7, 0
%define dst_regd r1d
%endif
mov dst_regd, dword [r1+r5*4]
- lea dst_reg, [r0+dst_reg]
+ add dst_reg, r0
DC_ADD_MMX2_OP movh, dst_reg, r3, r6
%ifndef ARCH_X86_64
mov r1, r1m
@@ -513,7 +513,7 @@ cglobal h264_idct8_add4_8_mmx2, 5, 7, 0
RET
.no_dc
mov r6d, dword [r1+r5*4]
- lea r6, [r0+r6]
+ add r6, r0
add word [r2], 32
IDCT8_ADD_MMX_START r2 , rsp
IDCT8_ADD_MMX_START r2+8, rsp+64
@@ -558,7 +558,7 @@ INIT_MMX
%define dst_regd r1d
%endif
mov dst_regd, dword [r1+r5*4]
- lea dst_reg, [r0+dst_reg]
+ add dst_reg, r0
DC_ADD_MMX2_OP mova, dst_reg, r3, r6
lea dst_reg, [dst_reg+r3*4]
DC_ADD_MMX2_OP mova, dst_reg, r3, r6
@@ -573,7 +573,7 @@ INIT_MMX
.no_dc
INIT_XMM
mov dst_regd, dword [r1+r5*4]
- lea dst_reg, [r0+dst_reg]
+ add dst_reg, r0
IDCT8_ADD_SSE dst_reg, r2, r3, r6
%ifndef ARCH_X86_64
mov r1, r1m
diff --git a/libavcodec/x86/h264_idct_10bit.asm b/libavcodec/x86/h264_idct_10bit.asm
index 54636a95d0..a9c12da5a2 100644
--- a/libavcodec/x86/h264_idct_10bit.asm
+++ b/libavcodec/x86/h264_idct_10bit.asm
@@ -22,8 +22,8 @@
;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
;******************************************************************************
-%include "x86inc.asm"
-%include "x86util.asm"
+%include "libavutil/x86/x86inc.asm"
+%include "libavutil/x86/x86util.asm"
SECTION_RODATA
diff --git a/libavcodec/x86/h264_intrapred.asm b/libavcodec/x86/h264_intrapred.asm
index cbf3cf7a5c..ed3bda7721 100644
--- a/libavcodec/x86/h264_intrapred.asm
+++ b/libavcodec/x86/h264_intrapred.asm
@@ -5,25 +5,25 @@
;* Copyright (c) 2010 Loren Merritt
;* Copyright (c) 2010 Ronald S. Bultje
;*
-;* This file is part of Libav.
+;* This file is part of FFmpeg.
;*
-;* Libav is free software; you can redistribute it and/or
+;* FFmpeg 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.
;*
-;* Libav is distributed in the hope that it will be useful,
+;* FFmpeg 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
;* Lesser General Public License for more details.
;*
;* You should have received a copy of the GNU Lesser General Public
-;* License along with Libav; if not, write to the Free Software
+;* License along with FFmpeg; if not, write to the Free Software
;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
;******************************************************************************
-%include "x86inc.asm"
-%include "x86util.asm"
+%include "libavutil/x86/x86inc.asm"
+%include "libavutil/x86/x86util.asm"
SECTION_RODATA
@@ -2611,12 +2611,11 @@ cglobal pred4x4_down_left_mmxext, 3,3
punpckldq m1, [r1]
movq m2, m1
movq m3, m1
- movq m4, m1
psllq m1, 8
pxor m2, m1
psrlq m2, 8
- pxor m3, m2
- PRED4x4_LOWPASS m0, m1, m3, m4, m5
+ pxor m2, m3
+ PRED4x4_LOWPASS m0, m1, m2, m3, m4
lea r1, [r0+r2*2]
psrlq m0, 8
movd [r0+r2*1], m0
diff --git a/libavcodec/x86/h264_intrapred_10bit.asm b/libavcodec/x86/h264_intrapred_10bit.asm
index 5cb593ac38..5a06896afe 100644
--- a/libavcodec/x86/h264_intrapred_10bit.asm
+++ b/libavcodec/x86/h264_intrapred_10bit.asm
@@ -22,16 +22,28 @@
;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
;******************************************************************************
-%include "x86inc.asm"
-%include "x86util.asm"
+%include "libavutil/x86/x86inc.asm"
+%include "libavutil/x86/x86util.asm"
SECTION_RODATA
-SECTION .text
-
+cextern pw_16
+cextern pw_8
cextern pw_4
+cextern pw_2
cextern pw_1
+pw_m32101234: dw -3, -2, -1, 0, 1, 2, 3, 4
+pw_m3: times 8 dw -3
+pw_pixel_max: times 8 dw ((1 << 10)-1)
+pw_512: times 8 dw 512
+pd_17: times 4 dd 17
+pd_16: times 4 dd 16
+
+SECTION .text
+
+; dest, left, right, src
+; output: %1 = (t[n-1] + t[n]*2 + t[n+1] + 2) >> 2
%macro PRED4x4_LOWPASS 4
paddw %2, %3
psrlw %2, 1
@@ -52,13 +64,11 @@ cglobal pred4x4_down_right_10_%1, 3,3
movq m3, [r0]
punpckhdq m1, m2
PALIGNR m3, m1, 10, m1
- mova m1, m3
movhps m4, [r1+r2*1-8]
- PALIGNR m3, m4, 14, m4
- mova m2, m3
+ PALIGNR m0, m3, m4, 14, m4
movhps m4, [r1+r2*2-8]
- PALIGNR m3, m4, 14, m4
- PRED4x4_LOWPASS m0, m3, m1, m2
+ PALIGNR m2, m0, m4, 14, m4
+ PRED4x4_LOWPASS m0, m2, m3, m0
movq [r1+r2*2], m0
psrldq m0, 2
movq [r1+r2*1], m0
@@ -92,22 +102,20 @@ cglobal pred4x4_vertical_right_10_%1, 3,3,6
pavgw m5, m0
movhps m1, [r0+r2*1-8]
PALIGNR m0, m1, 14, m1 ; ....t3t2t1t0ltl0
- mova m1, m0
movhps m2, [r0+r2*2-8]
- PALIGNR m0, m2, 14, m2 ; ..t3t2t1t0ltl0l1
- mova m2, m0
+ PALIGNR m1, m0, m2, 14, m2 ; ..t3t2t1t0ltl0l1
movhps m3, [r1+r2*1-8]
- PALIGNR m0, m3, 14, m3 ; t3t2t1t0ltl0l1l2
- PRED4x4_LOWPASS m3, m1, m0, m2
- pslldq m1, m3, 12
- psrldq m3, 4
+ PALIGNR m2, m1, m3, 14, m3 ; t3t2t1t0ltl0l1l2
+ PRED4x4_LOWPASS m1, m0, m2, m1
+ pslldq m0, m1, 12
+ psrldq m1, 4
movq [r0+r2*1], m5
- movq [r0+r2*2], m3
- PALIGNR m5, m1, 14, m2
- pslldq m1, 2
+ movq [r0+r2*2], m1
+ PALIGNR m5, m0, 14, m2
+ pslldq m0, 2
movq [r1+r2*1], m5
- PALIGNR m3, m1, 14, m1
- movq [r1+r2*2], m3
+ PALIGNR m1, m0, 14, m0
+ movq [r1+r2*2], m1
RET
%endmacro
@@ -140,9 +148,9 @@ cglobal pred4x4_horizontal_down_10_%1, 3,3
punpckhdq m1, m2 ; l0 l1 l2 l3
punpckhqdq m1, m0 ; t2 t1 t0 lt l0 l1 l2 l3
psrldq m0, m1, 4 ; .. .. t2 t1 t0 lt l0 l1
- psrldq m2, m1, 2 ; .. t2 t1 t0 lt l0 l1 l2
- pavgw m5, m1, m2
- PRED4x4_LOWPASS m3, m1, m0, m2
+ psrldq m3, m1, 2 ; .. t2 t1 t0 lt l0 l1 l2
+ pavgw m5, m1, m3
+ PRED4x4_LOWPASS m3, m1, m0, m3
punpcklwd m5, m3
psrldq m3, 8
PALIGNR m3, m5, 12, m4
@@ -208,17 +216,15 @@ cglobal pred4x4_dc_10_mmxext, 3,3
;-----------------------------------------------------------------------------
; void pred4x4_down_left(pixel *src, const pixel *topright, int stride)
;-----------------------------------------------------------------------------
-;TODO: more AVX here
%macro PRED4x4_DL 1
cglobal pred4x4_down_left_10_%1, 3,3
sub r0, r2
- movq m1, [r0]
- movhps m1, [r1]
- pslldq m5, m1, 2
- pxor m2, m5, m1
- psrldq m2, 2
- pxor m3, m1, m2
- PRED4x4_LOWPASS m0, m5, m3, m1
+ movq m0, [r0]
+ movhps m0, [r1]
+ psrldq m2, m0, 2
+ pslldq m3, m0, 2
+ pshufhw m2, m2, 10100100b
+ PRED4x4_LOWPASS m0, m3, m2, m0
lea r1, [r0+r2*2]
movhps [r1+r2*2], m0
psrldq m0, 2
@@ -245,10 +251,10 @@ cglobal pred4x4_vertical_left_10_%1, 3,3
sub r0, r2
movu m1, [r0]
movhps m1, [r1]
- psrldq m3, m1, 2
+ psrldq m0, m1, 2
psrldq m2, m1, 4
- pavgw m4, m3, m1
- PRED4x4_LOWPASS m0, m1, m2, m3
+ pavgw m4, m0, m1
+ PRED4x4_LOWPASS m0, m1, m2, m0
lea r1, [r0+r2*2]
movq [r0+r2*1], m4
movq [r0+r2*2], m0
@@ -286,13 +292,13 @@ cglobal pred4x4_horizontal_up_10_mmxext, 3,3
pavgw m2, m0
pshufw m5, m0, 11111110b
- PRED4x4_LOWPASS m3, m0, m5, m1
+ PRED4x4_LOWPASS m1, m0, m5, m1
movq m6, m2
- punpcklwd m6, m3
+ punpcklwd m6, m1
movq [r0+r2*1], m6
psrlq m2, 16
- psrlq m3, 16
- punpcklwd m2, m3
+ psrlq m1, 16
+ punpcklwd m2, m1
movq [r0+r2*2], m2
psrlq m2, 32
movd [r1+r2*1], m2
@@ -321,7 +327,7 @@ cglobal pred8x8_vertical_10_sse2, 2,2
;-----------------------------------------------------------------------------
INIT_XMM
cglobal pred8x8_horizontal_10_sse2, 2,3
- mov r2, 4
+ mov r2d, 4
.loop:
movq m0, [r0+r1*0-8]
movq m1, [r0+r1*1-8]
@@ -332,6 +338,871 @@ cglobal pred8x8_horizontal_10_sse2, 2,3
mova [r0+r1*0], m0
mova [r0+r1*1], m1
lea r0, [r0+r1*2]
- dec r2
+ dec r2d
+ jg .loop
+ REP_RET
+
+;-----------------------------------------------------------------------------
+; void predict_8x8_dc(pixel *src, int stride)
+;-----------------------------------------------------------------------------
+%macro MOV8 2-3
+; sort of a hack, but it works
+%if mmsize==8
+ movq [%1+0], %2
+ movq [%1+8], %3
+%else
+ movdqa [%1], %2
+%endif
+%endmacro
+
+%macro PRED8x8_DC 2
+cglobal pred8x8_dc_10_%1, 2,6
+ sub r0, r1
+ pxor m4, m4
+ movq m0, [r0+0]
+ movq m1, [r0+8]
+%if mmsize==16
+ punpcklwd m0, m1
+ movhlps m1, m0
+ paddw m0, m1
+%else
+ pshufw m2, m0, 00001110b
+ pshufw m3, m1, 00001110b
+ paddw m0, m2
+ paddw m1, m3
+ punpcklwd m0, m1
+%endif
+ %2 m2, m0, 00001110b
+ paddw m0, m2
+
+ lea r5, [r1*3]
+ lea r4, [r0+r1*4]
+ movzx r2d, word [r0+r1*1-2]
+ movzx r3d, word [r0+r1*2-2]
+ add r2d, r3d
+ movzx r3d, word [r0+r5*1-2]
+ add r2d, r3d
+ movzx r3d, word [r4-2]
+ add r2d, r3d
+ movd m2, r2d ; s2
+
+ movzx r2d, word [r4+r1*1-2]
+ movzx r3d, word [r4+r1*2-2]
+ add r2d, r3d
+ movzx r3d, word [r4+r5*1-2]
+ add r2d, r3d
+ movzx r3d, word [r4+r1*4-2]
+ add r2d, r3d
+ movd m3, r2d ; s3
+
+ punpcklwd m2, m3
+ punpckldq m0, m2 ; s0, s1, s2, s3
+ %2 m3, m0, 11110110b ; s2, s1, s3, s3
+ %2 m0, m0, 01110100b ; s0, s1, s3, s1
+ paddw m0, m3
+ psrlw m0, 2
+ pavgw m0, m4 ; s0+s2, s1, s3, s1+s3
+%if mmsize==16
+ punpcklwd m0, m0
+ pshufd m3, m0, 11111010b
+ punpckldq m0, m0
+ SWAP 0,1
+%else
+ pshufw m1, m0, 0x00
+ pshufw m2, m0, 0x55
+ pshufw m3, m0, 0xaa
+ pshufw m4, m0, 0xff
+%endif
+ MOV8 r0+r1*1, m1, m2
+ MOV8 r0+r1*2, m1, m2
+ MOV8 r0+r5*1, m1, m2
+ MOV8 r0+r1*4, m1, m2
+ MOV8 r4+r1*1, m3, m4
+ MOV8 r4+r1*2, m3, m4
+ MOV8 r4+r5*1, m3, m4
+ MOV8 r4+r1*4, m3, m4
+ RET
+%endmacro
+
+INIT_MMX
+PRED8x8_DC mmxext, pshufw
+INIT_XMM
+PRED8x8_DC sse2 , pshuflw
+
+;-----------------------------------------------------------------------------
+; void pred8x8_top_dc(pixel *src, int stride)
+;-----------------------------------------------------------------------------
+INIT_XMM
+cglobal pred8x8_top_dc_10_sse2, 2,4
+ sub r0, r1
+ mova m0, [r0]
+ pshuflw m1, m0, 0x4e
+ pshufhw m1, m1, 0x4e
+ paddw m0, m1
+ pshuflw m1, m0, 0xb1
+ pshufhw m1, m1, 0xb1
+ paddw m0, m1
+ lea r2, [r1*3]
+ lea r3, [r0+r1*4]
+ paddw m0, [pw_2]
+ psrlw m0, 2
+ mova [r0+r1*1], m0
+ mova [r0+r1*2], m0
+ mova [r0+r2*1], m0
+ mova [r0+r1*4], m0
+ mova [r3+r1*1], m0
+ mova [r3+r1*2], m0
+ mova [r3+r2*1], m0
+ mova [r3+r1*4], m0
+ RET
+
+;-----------------------------------------------------------------------------
+; void pred8x8_plane(pixel *src, int stride)
+;-----------------------------------------------------------------------------
+INIT_XMM
+cglobal pred8x8_plane_10_sse2, 2,7,7
+ sub r0, r1
+ lea r2, [r1*3]
+ lea r3, [r0+r1*4]
+ mova m2, [r0]
+ pmaddwd m2, [pw_m32101234]
+ HADDD m2, m1
+ movd m0, [r0-4]
+ psrld m0, 14
+ psubw m2, m0 ; H
+ movd m0, [r3+r1*4-4]
+ movd m1, [r0+12]
+ paddw m0, m1
+ psllw m0, 4 ; 16*(src[7*stride-1] + src[-stride+7])
+ movzx r4d, word [r3+r1*1-2] ; src[4*stride-1]
+ movzx r5d, word [r0+r2*1-2] ; src[2*stride-1]
+ sub r4d, r5d
+ movzx r6d, word [r3+r1*2-2] ; src[5*stride-1]
+ movzx r5d, word [r0+r1*2-2] ; src[1*stride-1]
+ sub r6d, r5d
+ lea r4d, [r4+r6*2]
+ movzx r5d, word [r3+r2*1-2] ; src[6*stride-1]
+ movzx r6d, word [r0+r1*1-2] ; src[0*stride-1]
+ sub r5d, r6d
+ lea r5d, [r5*3]
+ add r4d, r5d
+ movzx r6d, word [r3+r1*4-2] ; src[7*stride-1]
+ movzx r5d, word [r0+r1*0-2] ; src[ -stride-1]
+ sub r6d, r5d
+ lea r4d, [r4+r6*4]
+ movd m3, r4d ; V
+ punpckldq m2, m3
+ pmaddwd m2, [pd_17]
+ paddd m2, [pd_16]
+ psrad m2, 5 ; b, c
+
+ mova m3, [pw_pixel_max]
+ pxor m1, m1
+ SPLATW m0, m0, 1
+ SPLATW m4, m2, 2
+ SPLATW m2, m2, 0
+ pmullw m2, [pw_m32101234] ; b
+ pmullw m5, m4, [pw_m3] ; c
+ paddw m5, [pw_16]
+ mov r2d, 8
+ add r0, r1
+.loop:
+ paddsw m6, m2, m5
+ paddsw m6, m0
+ psraw m6, 5
+ CLIPW m6, m1, m3
+ mova [r0], m6
+ paddw m5, m4
+ add r0, r1
+ dec r2d
jg .loop
REP_RET
+
+
+;-----------------------------------------------------------------------------
+; void pred8x8l_128_dc(pixel *src, int has_topleft, int has_topright, int stride)
+;-----------------------------------------------------------------------------
+%macro PRED8x8L_128_DC 1
+cglobal pred8x8l_128_dc_10_%1, 4,4
+ mova m0, [pw_512] ; (1<<(BIT_DEPTH-1))
+ lea r1, [r3*3]
+ lea r2, [r0+r3*4]
+ MOV8 r0+r3*0, m0, m0
+ MOV8 r0+r3*1, m0, m0
+ MOV8 r0+r3*2, m0, m0
+ MOV8 r0+r1*1, m0, m0
+ MOV8 r2+r3*0, m0, m0
+ MOV8 r2+r3*1, m0, m0
+ MOV8 r2+r3*2, m0, m0
+ MOV8 r2+r1*1, m0, m0
+ RET
+%endmacro
+
+INIT_MMX
+PRED8x8L_128_DC mmxext
+INIT_XMM
+PRED8x8L_128_DC sse2
+
+;-----------------------------------------------------------------------------
+; void pred8x8l_top_dc(pixel *src, int has_topleft, int has_topright, int stride)
+;-----------------------------------------------------------------------------
+%macro PRED8x8L_TOP_DC 1
+cglobal pred8x8l_top_dc_10_%1, 4,4,6
+ sub r0, r3
+ mova m0, [r0]
+ shr r1d, 14
+ shr r2d, 13
+ neg r1
+ pslldq m1, m0, 2
+ psrldq m2, m0, 2
+ pinsrw m1, [r0+r1], 0
+ pinsrw m2, [r0+r2+14], 7
+ lea r1, [r3*3]
+ lea r2, [r0+r3*4]
+ PRED4x4_LOWPASS m0, m2, m1, m0
+ HADDW m0, m1
+ paddw m0, [pw_4]
+ psrlw m0, 3
+ SPLATW m0, m0, 0
+ mova [r0+r3*1], m0
+ mova [r0+r3*2], m0
+ mova [r0+r1*1], m0
+ mova [r0+r3*4], m0
+ mova [r2+r3*1], m0
+ mova [r2+r3*2], m0
+ mova [r2+r1*1], m0
+ mova [r2+r3*4], m0
+ RET
+%endmacro
+
+INIT_XMM
+PRED8x8L_TOP_DC sse2
+%ifdef HAVE_AVX
+INIT_AVX
+PRED8x8L_TOP_DC avx
+%endif
+
+;-----------------------------------------------------------------------------
+;void pred8x8l_dc(pixel *src, int has_topleft, int has_topright, int stride)
+;-----------------------------------------------------------------------------
+;TODO: see if scalar is faster
+%macro PRED8x8L_DC 1
+cglobal pred8x8l_dc_10_%1, 4,6,6
+ sub r0, r3
+ lea r4, [r0+r3*4]
+ lea r5, [r3*3]
+ mova m0, [r0+r3*2-16]
+ punpckhwd m0, [r0+r3*1-16]
+ mova m1, [r4+r3*0-16]
+ punpckhwd m1, [r0+r5*1-16]
+ punpckhdq m1, m0
+ mova m2, [r4+r3*2-16]
+ punpckhwd m2, [r4+r3*1-16]
+ mova m3, [r4+r3*4-16]
+ punpckhwd m3, [r4+r5*1-16]
+ punpckhdq m3, m2
+ punpckhqdq m3, m1
+ mova m0, [r0]
+ shr r1d, 14
+ shr r2d, 13
+ neg r1
+ pslldq m1, m0, 2
+ psrldq m2, m0, 2
+ pinsrw m1, [r0+r1], 0
+ pinsrw m2, [r0+r2+14], 7
+ not r1
+ and r1, r3
+ pslldq m4, m3, 2
+ psrldq m5, m3, 2
+ pshuflw m4, m4, 11100101b
+ pinsrw m5, [r0+r1-2], 7
+ PRED4x4_LOWPASS m3, m4, m5, m3
+ PRED4x4_LOWPASS m0, m2, m1, m0
+ paddw m0, m3
+ HADDW m0, m1
+ paddw m0, [pw_8]
+ psrlw m0, 4
+ SPLATW m0, m0
+ mova [r0+r3*1], m0
+ mova [r0+r3*2], m0
+ mova [r0+r5*1], m0
+ mova [r0+r3*4], m0
+ mova [r4+r3*1], m0
+ mova [r4+r3*2], m0
+ mova [r4+r5*1], m0
+ mova [r4+r3*4], m0
+ RET
+%endmacro
+
+INIT_XMM
+PRED8x8L_DC sse2
+%ifdef HAVE_AVX
+INIT_AVX
+PRED8x8L_DC avx
+%endif
+
+;-----------------------------------------------------------------------------
+; void pred8x8l_vertical(pixel *src, int has_topleft, int has_topright, int stride)
+;-----------------------------------------------------------------------------
+%macro PRED8x8L_VERTICAL 1
+cglobal pred8x8l_vertical_10_%1, 4,4,6
+ sub r0, r3
+ mova m0, [r0]
+ shr r1d, 14
+ shr r2d, 13
+ neg r1
+ pslldq m1, m0, 2
+ psrldq m2, m0, 2
+ pinsrw m1, [r0+r1], 0
+ pinsrw m2, [r0+r2+14], 7
+ lea r1, [r3*3]
+ lea r2, [r0+r3*4]
+ PRED4x4_LOWPASS m0, m2, m1, m0
+ mova [r0+r3*1], m0
+ mova [r0+r3*2], m0
+ mova [r0+r1*1], m0
+ mova [r0+r3*4], m0
+ mova [r2+r3*1], m0
+ mova [r2+r3*2], m0
+ mova [r2+r1*1], m0
+ mova [r2+r3*4], m0
+ RET
+%endmacro
+
+INIT_XMM
+PRED8x8L_VERTICAL sse2
+%ifdef HAVE_AVX
+INIT_AVX
+PRED8x8L_VERTICAL avx
+%endif
+
+;-----------------------------------------------------------------------------
+; void pred8x8l_horizontal(uint8_t *src, int has_topleft, int has_topright, int stride)
+;-----------------------------------------------------------------------------
+%macro PRED8x8L_HORIZONTAL 1
+cglobal pred8x8l_horizontal_10_%1, 4,4,5
+ mova m0, [r0-16]
+ shr r1d, 14
+ dec r1
+ and r1, r3
+ sub r1, r3
+ punpckhwd m0, [r0+r1-16]
+ mova m1, [r0+r3*2-16]
+ punpckhwd m1, [r0+r3*1-16]
+ lea r2, [r0+r3*4]
+ lea r1, [r3*3]
+ punpckhdq m1, m0
+ mova m2, [r2+r3*0-16]
+ punpckhwd m2, [r0+r1-16]
+ mova m3, [r2+r3*2-16]
+ punpckhwd m3, [r2+r3*1-16]
+ punpckhdq m3, m2
+ punpckhqdq m3, m1
+ PALIGNR m4, m3, [r2+r1-16], 14, m0
+ pslldq m0, m4, 2
+ pshuflw m0, m0, 11100101b
+ PRED4x4_LOWPASS m4, m3, m0, m4
+ punpckhwd m3, m4, m4
+ punpcklwd m4, m4
+ pshufd m0, m3, 0xff
+ pshufd m1, m3, 0xaa
+ pshufd m2, m3, 0x55
+ pshufd m3, m3, 0x00
+ mova [r0+r3*0], m0
+ mova [r0+r3*1], m1
+ mova [r0+r3*2], m2
+ mova [r0+r1*1], m3
+ pshufd m0, m4, 0xff
+ pshufd m1, m4, 0xaa
+ pshufd m2, m4, 0x55
+ pshufd m3, m4, 0x00
+ mova [r2+r3*0], m0
+ mova [r2+r3*1], m1
+ mova [r2+r3*2], m2
+ mova [r2+r1*1], m3
+ RET
+%endmacro
+
+INIT_XMM
+%define PALIGNR PALIGNR_MMX
+PRED8x8L_HORIZONTAL sse2
+%define PALIGNR PALIGNR_SSSE3
+PRED8x8L_HORIZONTAL ssse3
+%ifdef HAVE_AVX
+INIT_AVX
+PRED8x8L_HORIZONTAL avx
+%endif
+
+;-----------------------------------------------------------------------------
+;void pred8x8l_down_left(pixel *src, int has_topleft, int has_topright, int stride)
+;-----------------------------------------------------------------------------
+%macro PRED8x8L_DOWN_LEFT 1
+cglobal pred8x8l_down_left_10_%1, 4,4,7
+ sub r0, r3
+ mova m3, [r0]
+ shr r1d, 14
+ neg r1
+ shr r2d, 13
+ pslldq m1, m3, 2
+ psrldq m2, m3, 2
+ pinsrw m1, [r0+r1], 0
+ pinsrw m2, [r0+r2+14], 7
+ PRED4x4_LOWPASS m6, m2, m1, m3
+ jz .fix_tr ; flags from shr r2d
+ mova m1, [r0+16]
+ psrldq m5, m1, 2
+ PALIGNR m2, m1, m3, 14, m3
+ pshufhw m5, m5, 10100100b
+ PRED4x4_LOWPASS m1, m2, m5, m1
+.do_topright:
+ lea r1, [r3*3]
+ psrldq m5, m1, 14
+ lea r2, [r0+r3*4]
+ PALIGNR m2, m1, m6, 2, m0
+ PALIGNR m3, m1, m6, 14, m0
+ PALIGNR m5, m1, 2, m0
+ pslldq m4, m6, 2
+ PRED4x4_LOWPASS m6, m4, m2, m6
+ PRED4x4_LOWPASS m1, m3, m5, m1
+ mova [r2+r3*4], m1
+ PALIGNR m1, m6, 14, m2
+ pslldq m6, 2
+ mova [r2+r1*1], m1
+ PALIGNR m1, m6, 14, m2
+ pslldq m6, 2
+ mova [r2+r3*2], m1
+ PALIGNR m1, m6, 14, m2
+ pslldq m6, 2
+ mova [r2+r3*1], m1
+ PALIGNR m1, m6, 14, m2
+ pslldq m6, 2
+ mova [r0+r3*4], m1
+ PALIGNR m1, m6, 14, m2
+ pslldq m6, 2
+ mova [r0+r1*1], m1
+ PALIGNR m1, m6, 14, m2
+ pslldq m6, 2
+ mova [r0+r3*2], m1
+ PALIGNR m1, m6, 14, m6
+ mova [r0+r3*1], m1
+ RET
+.fix_tr:
+ punpckhwd m3, m3
+ pshufd m1, m3, 0xFF
+ jmp .do_topright
+%endmacro
+
+INIT_XMM
+%define PALIGNR PALIGNR_MMX
+PRED8x8L_DOWN_LEFT sse2
+%define PALIGNR PALIGNR_SSSE3
+PRED8x8L_DOWN_LEFT ssse3
+%ifdef HAVE_AVX
+INIT_AVX
+PRED8x8L_DOWN_LEFT avx
+%endif
+
+;-----------------------------------------------------------------------------
+;void pred8x8l_down_right(pixel *src, int has_topleft, int has_topright, int stride)
+;-----------------------------------------------------------------------------
+%macro PRED8x8L_DOWN_RIGHT 1
+; standard forbids this when has_topleft is false
+; no need to check
+cglobal pred8x8l_down_right_10_%1, 4,5,8
+ sub r0, r3
+ lea r4, [r0+r3*4]
+ lea r1, [r3*3]
+ mova m0, [r0+r3*1-16]
+ punpckhwd m0, [r0+r3*0-16]
+ mova m1, [r0+r1*1-16]
+ punpckhwd m1, [r0+r3*2-16]
+ punpckhdq m1, m0
+ mova m2, [r4+r3*1-16]
+ punpckhwd m2, [r4+r3*0-16]
+ mova m3, [r4+r1*1-16]
+ punpckhwd m3, [r4+r3*2-16]
+ punpckhdq m3, m2
+ punpckhqdq m3, m1
+ mova m0, [r4+r3*4-16]
+ mova m1, [r0]
+ PALIGNR m4, m3, m0, 14, m0
+ PALIGNR m1, m3, 2, m2
+ pslldq m0, m4, 2
+ pshuflw m0, m0, 11100101b
+ PRED4x4_LOWPASS m6, m1, m4, m3
+ PRED4x4_LOWPASS m4, m3, m0, m4
+ mova m3, [r0]
+ shr r2d, 13
+ pslldq m1, m3, 2
+ psrldq m2, m3, 2
+ pinsrw m1, [r0-2], 0
+ pinsrw m2, [r0+r2+14], 7
+ PRED4x4_LOWPASS m3, m2, m1, m3
+ PALIGNR m2, m3, m6, 2, m0
+ PALIGNR m5, m3, m6, 14, m0
+ psrldq m7, m3, 2
+ PRED4x4_LOWPASS m6, m4, m2, m6
+ PRED4x4_LOWPASS m3, m5, m7, m3
+ mova [r4+r3*4], m6
+ PALIGNR m3, m6, 14, m2
+ pslldq m6, 2
+ mova [r0+r3*1], m3
+ PALIGNR m3, m6, 14, m2
+ pslldq m6, 2
+ mova [r0+r3*2], m3
+ PALIGNR m3, m6, 14, m2
+ pslldq m6, 2
+ mova [r0+r1*1], m3
+ PALIGNR m3, m6, 14, m2
+ pslldq m6, 2
+ mova [r0+r3*4], m3
+ PALIGNR m3, m6, 14, m2
+ pslldq m6, 2
+ mova [r4+r3*1], m3
+ PALIGNR m3, m6, 14, m2
+ pslldq m6, 2
+ mova [r4+r3*2], m3
+ PALIGNR m3, m6, 14, m6
+ mova [r4+r1*1], m3
+ RET
+%endmacro
+
+INIT_XMM
+%define PALIGNR PALIGNR_MMX
+PRED8x8L_DOWN_RIGHT sse2
+%define PALIGNR PALIGNR_SSSE3
+PRED8x8L_DOWN_RIGHT ssse3
+%ifdef HAVE_AVX
+INIT_AVX
+PRED8x8L_DOWN_RIGHT avx
+%endif
+
+;-----------------------------------------------------------------------------
+; void pred8x8l_vertical_right(pixel *src, int has_topleft, int has_topright, int stride)
+;-----------------------------------------------------------------------------
+%macro PRED8x8L_VERTICAL_RIGHT 1
+; likewise with 8x8l_down_right
+cglobal pred8x8l_vertical_right_10_%1, 4,5,7
+ sub r0, r3
+ lea r4, [r0+r3*4]
+ lea r1, [r3*3]
+ mova m0, [r0+r3*1-16]
+ punpckhwd m0, [r0+r3*0-16]
+ mova m1, [r0+r1*1-16]
+ punpckhwd m1, [r0+r3*2-16]
+ punpckhdq m1, m0
+ mova m2, [r4+r3*1-16]
+ punpckhwd m2, [r4+r3*0-16]
+ mova m3, [r4+r1*1-16]
+ punpckhwd m3, [r4+r3*2-16]
+ punpckhdq m3, m2
+ punpckhqdq m3, m1
+ mova m0, [r4+r3*4-16]
+ mova m1, [r0]
+ PALIGNR m4, m3, m0, 14, m0
+ PALIGNR m1, m3, 2, m2
+ PRED4x4_LOWPASS m3, m1, m4, m3
+ mova m2, [r0]
+ shr r2d, 13
+ pslldq m1, m2, 2
+ psrldq m5, m2, 2
+ pinsrw m1, [r0-2], 0
+ pinsrw m5, [r0+r2+14], 7
+ PRED4x4_LOWPASS m2, m5, m1, m2
+ PALIGNR m6, m2, m3, 12, m1
+ PALIGNR m5, m2, m3, 14, m0
+ PRED4x4_LOWPASS m0, m6, m2, m5
+ pavgw m2, m5
+ mova [r0+r3*2], m0
+ mova [r0+r3*1], m2
+ pslldq m6, m3, 4
+ pslldq m1, m3, 2
+ PRED4x4_LOWPASS m1, m3, m6, m1
+ PALIGNR m2, m1, 14, m4
+ mova [r0+r1*1], m2
+ pslldq m1, 2
+ PALIGNR m0, m1, 14, m3
+ mova [r0+r3*4], m0
+ pslldq m1, 2
+ PALIGNR m2, m1, 14, m4
+ mova [r4+r3*1], m2
+ pslldq m1, 2
+ PALIGNR m0, m1, 14, m3
+ mova [r4+r3*2], m0
+ pslldq m1, 2
+ PALIGNR m2, m1, 14, m4
+ mova [r4+r1*1], m2
+ pslldq m1, 2
+ PALIGNR m0, m1, 14, m1
+ mova [r4+r3*4], m0
+ RET
+%endmacro
+
+INIT_XMM
+%define PALIGNR PALIGNR_MMX
+PRED8x8L_VERTICAL_RIGHT sse2
+%define PALIGNR PALIGNR_SSSE3
+PRED8x8L_VERTICAL_RIGHT ssse3
+%ifdef HAVE_AVX
+INIT_AVX
+PRED8x8L_VERTICAL_RIGHT avx
+%endif
+
+;-----------------------------------------------------------------------------
+; void pred8x8l_horizontal_up(pixel *src, int has_topleft, int has_topright, int stride)
+;-----------------------------------------------------------------------------
+%macro PRED8x8L_HORIZONTAL_UP 1
+cglobal pred8x8l_horizontal_up_10_%1, 4,4,6
+ mova m0, [r0+r3*0-16]
+ punpckhwd m0, [r0+r3*1-16]
+ shr r1d, 14
+ dec r1
+ and r1, r3
+ sub r1, r3
+ mova m4, [r0+r1*1-16]
+ lea r1, [r3*3]
+ lea r2, [r0+r3*4]
+ mova m1, [r0+r3*2-16]
+ punpckhwd m1, [r0+r1*1-16]
+ punpckhdq m0, m1
+ mova m2, [r2+r3*0-16]
+ punpckhwd m2, [r2+r3*1-16]
+ mova m3, [r2+r3*2-16]
+ punpckhwd m3, [r2+r1*1-16]
+ punpckhdq m2, m3
+ punpckhqdq m0, m2
+ PALIGNR m1, m0, m4, 14, m4
+ psrldq m2, m0, 2
+ pshufhw m2, m2, 10100100b
+ PRED4x4_LOWPASS m0, m1, m2, m0
+ psrldq m1, m0, 2
+ psrldq m2, m0, 4
+ pshufhw m1, m1, 10100100b
+ pshufhw m2, m2, 01010100b
+ pavgw m4, m0, m1
+ PRED4x4_LOWPASS m1, m2, m0, m1
+ punpckhwd m5, m4, m1
+ punpcklwd m4, m1
+ mova [r2+r3*0], m5
+ mova [r0+r3*0], m4
+ pshufd m0, m5, 11111001b
+ pshufd m1, m5, 11111110b
+ pshufd m2, m5, 11111111b
+ mova [r2+r3*1], m0
+ mova [r2+r3*2], m1
+ mova [r2+r1*1], m2
+ PALIGNR m2, m5, m4, 4, m0
+ PALIGNR m3, m5, m4, 8, m1
+ PALIGNR m5, m5, m4, 12, m4
+ mova [r0+r3*1], m2
+ mova [r0+r3*2], m3
+ mova [r0+r1*1], m5
+ RET
+%endmacro
+
+INIT_XMM
+%define PALIGNR PALIGNR_MMX
+PRED8x8L_HORIZONTAL_UP sse2
+%define PALIGNR PALIGNR_SSSE3
+PRED8x8L_HORIZONTAL_UP ssse3
+%ifdef HAVE_AVX
+INIT_AVX
+PRED8x8L_HORIZONTAL_UP avx
+%endif
+
+
+;-----------------------------------------------------------------------------
+; void pred16x16_vertical(pixel *src, int stride)
+;-----------------------------------------------------------------------------
+%macro MOV16 3-5
+ mova [%1+ 0], %2
+ mova [%1+mmsize], %3
+%if mmsize==8
+ mova [%1+ 16], %4
+ mova [%1+ 24], %5
+%endif
+%endmacro
+
+%macro PRED16x16_VERTICAL 1
+cglobal pred16x16_vertical_10_%1, 2,3
+ sub r0, r1
+ mov r2d, 8
+ mova m0, [r0+ 0]
+ mova m1, [r0+mmsize]
+%if mmsize==8
+ mova m2, [r0+16]
+ mova m3, [r0+24]
+%endif
+.loop:
+ MOV16 r0+r1*1, m0, m1, m2, m3
+ MOV16 r0+r1*2, m0, m1, m2, m3
+ lea r0, [r0+r1*2]
+ dec r2d
+ jg .loop
+ REP_RET
+%endmacro
+
+INIT_MMX
+PRED16x16_VERTICAL mmxext
+INIT_XMM
+PRED16x16_VERTICAL sse2
+
+;-----------------------------------------------------------------------------
+; void pred16x16_horizontal(pixel *src, int stride)
+;-----------------------------------------------------------------------------
+%macro PRED16x16_HORIZONTAL 1
+cglobal pred16x16_horizontal_10_%1, 2,3
+ mov r2d, 8
+.vloop:
+ movd m0, [r0+r1*0-4]
+ movd m1, [r0+r1*1-4]
+ SPLATW m0, m0, 1
+ SPLATW m1, m1, 1
+ MOV16 r0+r1*0, m0, m0, m0, m0
+ MOV16 r0+r1*1, m1, m1, m1, m1
+ lea r0, [r0+r1*2]
+ dec r2d
+ jg .vloop
+ REP_RET
+%endmacro
+
+INIT_MMX
+PRED16x16_HORIZONTAL mmxext
+INIT_XMM
+PRED16x16_HORIZONTAL sse2
+
+;-----------------------------------------------------------------------------
+; void pred16x16_dc(pixel *src, int stride)
+;-----------------------------------------------------------------------------
+%macro PRED16x16_DC 1
+cglobal pred16x16_dc_10_%1, 2,6
+ mov r5, r0
+ sub r0, r1
+ mova m0, [r0+0]
+ paddw m0, [r0+mmsize]
+%if mmsize==8
+ paddw m0, [r0+16]
+ paddw m0, [r0+24]
+%endif
+ HADDW m0, m2
+
+ lea r0, [r0+r1-2]
+ movzx r3d, word [r0]
+ movzx r4d, word [r0+r1]
+%rep 7
+ lea r0, [r0+r1*2]
+ movzx r2d, word [r0]
+ add r3d, r2d
+ movzx r2d, word [r0+r1]
+ add r4d, r2d
+%endrep
+ lea r3d, [r3+r4+16]
+
+ movd m1, r3d
+ paddw m0, m1
+ psrlw m0, 5
+ SPLATW m0, m0
+ mov r3d, 8
+.loop:
+ MOV16 r5+r1*0, m0, m0, m0, m0
+ MOV16 r5+r1*1, m0, m0, m0, m0
+ lea r5, [r5+r1*2]
+ dec r3d
+ jg .loop
+ REP_RET
+%endmacro
+
+INIT_MMX
+PRED16x16_DC mmxext
+INIT_XMM
+PRED16x16_DC sse2
+
+;-----------------------------------------------------------------------------
+; void pred16x16_top_dc(pixel *src, int stride)
+;-----------------------------------------------------------------------------
+%macro PRED16x16_TOP_DC 1
+cglobal pred16x16_top_dc_10_%1, 2,3
+ sub r0, r1
+ mova m0, [r0+0]
+ paddw m0, [r0+mmsize]
+%if mmsize==8
+ paddw m0, [r0+16]
+ paddw m0, [r0+24]
+%endif
+ HADDW m0, m2
+
+ SPLATW m0, m0
+ paddw m0, [pw_8]
+ psrlw m0, 4
+ mov r2d, 8
+.loop:
+ MOV16 r0+r1*1, m0, m0, m0, m0
+ MOV16 r0+r1*2, m0, m0, m0, m0
+ lea r0, [r0+r1*2]
+ dec r2d
+ jg .loop
+ REP_RET
+%endmacro
+
+INIT_MMX
+PRED16x16_TOP_DC mmxext
+INIT_XMM
+PRED16x16_TOP_DC sse2
+
+;-----------------------------------------------------------------------------
+; void pred16x16_left_dc(pixel *src, int stride)
+;-----------------------------------------------------------------------------
+%macro PRED16x16_LEFT_DC 1
+cglobal pred16x16_left_dc_10_%1, 2,6
+ mov r5, r0
+
+ sub r0, 2
+ movzx r3d, word [r0]
+ movzx r4d, word [r0+r1]
+%rep 7
+ lea r0, [r0+r1*2]
+ movzx r2d, word [r0]
+ add r3d, r2d
+ movzx r2d, word [r0+r1]
+ add r4d, r2d
+%endrep
+ lea r3d, [r3+r4+8]
+ shr r3d, 4
+
+ movd m0, r3d
+ SPLATW m0, m0
+ mov r3d, 8
+.loop:
+ MOV16 r5+r1*0, m0, m0, m0, m0
+ MOV16 r5+r1*1, m0, m0, m0, m0
+ lea r5, [r5+r1*2]
+ dec r3d
+ jg .loop
+ REP_RET
+%endmacro
+
+INIT_MMX
+PRED16x16_LEFT_DC mmxext
+INIT_XMM
+PRED16x16_LEFT_DC sse2
+
+;-----------------------------------------------------------------------------
+; void pred16x16_128_dc(pixel *src, int stride)
+;-----------------------------------------------------------------------------
+%macro PRED16x16_128_DC 1
+cglobal pred16x16_128_dc_10_%1, 2,3
+ mova m0, [pw_512]
+ mov r2d, 8
+.loop:
+ MOV16 r0+r1*0, m0, m0, m0, m0
+ MOV16 r0+r1*1, m0, m0, m0, m0
+ lea r0, [r0+r1*2]
+ dec r2d
+ jg .loop
+ REP_RET
+%endmacro
+
+INIT_MMX
+PRED16x16_128_DC mmxext
+INIT_XMM
+PRED16x16_128_DC sse2
diff --git a/libavcodec/x86/h264_intrapred_init.c b/libavcodec/x86/h264_intrapred_init.c
index 9d6726c31c..540ec87ad3 100644
--- a/libavcodec/x86/h264_intrapred_init.c
+++ b/libavcodec/x86/h264_intrapred_init.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2010 Jason Garrett-Glaser
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -43,9 +43,56 @@ PRED4x4(horizontal_down, 10, avx)
#define PRED8x8(TYPE, DEPTH, OPT) \
void ff_pred8x8_ ## TYPE ## _ ## DEPTH ## _ ## OPT (uint8_t *src, int stride);
+PRED8x8(dc, 10, mmxext)
+PRED8x8(dc, 10, sse2)
+PRED8x8(top_dc, 10, sse2)
+PRED8x8(plane, 10, sse2)
PRED8x8(vertical, 10, sse2)
PRED8x8(horizontal, 10, sse2)
+#define PRED8x8L(TYPE, DEPTH, OPT)\
+void ff_pred8x8l_ ## TYPE ## _ ## DEPTH ## _ ## OPT (uint8_t *src, int has_topleft, int has_topright, int stride);
+
+PRED8x8L(dc, 10, sse2)
+PRED8x8L(dc, 10, avx)
+PRED8x8L(128_dc, 10, mmxext)
+PRED8x8L(128_dc, 10, sse2)
+PRED8x8L(top_dc, 10, sse2)
+PRED8x8L(top_dc, 10, avx)
+PRED8x8L(vertical, 10, sse2)
+PRED8x8L(vertical, 10, avx)
+PRED8x8L(horizontal, 10, sse2)
+PRED8x8L(horizontal, 10, ssse3)
+PRED8x8L(horizontal, 10, avx)
+PRED8x8L(down_left, 10, sse2)
+PRED8x8L(down_left, 10, ssse3)
+PRED8x8L(down_left, 10, avx)
+PRED8x8L(down_right, 10, sse2)
+PRED8x8L(down_right, 10, ssse3)
+PRED8x8L(down_right, 10, avx)
+PRED8x8L(vertical_right, 10, sse2)
+PRED8x8L(vertical_right, 10, ssse3)
+PRED8x8L(vertical_right, 10, avx)
+PRED8x8L(horizontal_up, 10, sse2)
+PRED8x8L(horizontal_up, 10, ssse3)
+PRED8x8L(horizontal_up, 10, avx)
+
+#define PRED16x16(TYPE, DEPTH, OPT)\
+void ff_pred16x16_ ## TYPE ## _ ## DEPTH ## _ ## OPT (uint8_t *src, int stride);
+
+PRED16x16(dc, 10, mmxext)
+PRED16x16(dc, 10, sse2)
+PRED16x16(top_dc, 10, mmxext)
+PRED16x16(top_dc, 10, sse2)
+PRED16x16(128_dc, 10, mmxext)
+PRED16x16(128_dc, 10, sse2)
+PRED16x16(left_dc, 10, mmxext)
+PRED16x16(left_dc, 10, sse2)
+PRED16x16(vertical, 10, mmxext)
+PRED16x16(vertical, 10, sse2)
+PRED16x16(horizontal, 10, mmxext)
+PRED16x16(horizontal, 10, sse2)
+
void ff_pred16x16_vertical_mmx (uint8_t *src, int stride);
void ff_pred16x16_vertical_sse (uint8_t *src, int stride);
void ff_pred16x16_horizontal_mmx (uint8_t *src, int stride);
@@ -120,23 +167,26 @@ void ff_pred4x4_tm_vp8_mmxext (uint8_t *src, const uint8_t *topright, int s
void ff_pred4x4_tm_vp8_ssse3 (uint8_t *src, const uint8_t *topright, int stride);
void ff_pred4x4_vertical_vp8_mmxext(uint8_t *src, const uint8_t *topright, int stride);
-void ff_h264_pred_init_x86(H264PredContext *h, int codec_id, const int bit_depth)
+void ff_h264_pred_init_x86(H264PredContext *h, int codec_id, const int bit_depth, const int chroma_format_idc)
{
+#if HAVE_YASM
int mm_flags = av_get_cpu_flags();
-#if HAVE_YASM
if (bit_depth == 8) {
if (mm_flags & AV_CPU_FLAG_MMX) {
h->pred16x16[VERT_PRED8x8 ] = ff_pred16x16_vertical_mmx;
h->pred16x16[HOR_PRED8x8 ] = ff_pred16x16_horizontal_mmx;
- h->pred8x8 [VERT_PRED8x8 ] = ff_pred8x8_vertical_mmx;
- h->pred8x8 [HOR_PRED8x8 ] = ff_pred8x8_horizontal_mmx;
+ if (chroma_format_idc == 1) {
+ h->pred8x8 [VERT_PRED8x8 ] = ff_pred8x8_vertical_mmx;
+ h->pred8x8 [HOR_PRED8x8 ] = ff_pred8x8_horizontal_mmx;
+ }
if (codec_id == CODEC_ID_VP8) {
h->pred16x16[PLANE_PRED8x8 ] = ff_pred16x16_tm_vp8_mmx;
h->pred8x8 [PLANE_PRED8x8 ] = ff_pred8x8_tm_vp8_mmx;
h->pred4x4 [TM_VP8_PRED ] = ff_pred4x4_tm_vp8_mmx;
} else {
- h->pred8x8 [PLANE_PRED8x8] = ff_pred8x8_plane_mmx;
+ if (chroma_format_idc == 1)
+ h->pred8x8 [PLANE_PRED8x8] = ff_pred8x8_plane_mmx;
if (codec_id == CODEC_ID_SVQ3) {
h->pred16x16[PLANE_PRED8x8] = ff_pred16x16_plane_svq3_mmx;
} else if (codec_id == CODEC_ID_RV40) {
@@ -150,7 +200,8 @@ void ff_h264_pred_init_x86(H264PredContext *h, int codec_id, const int bit_depth
if (mm_flags & AV_CPU_FLAG_MMX2) {
h->pred16x16[HOR_PRED8x8 ] = ff_pred16x16_horizontal_mmxext;
h->pred16x16[DC_PRED8x8 ] = ff_pred16x16_dc_mmxext;
- h->pred8x8 [HOR_PRED8x8 ] = ff_pred8x8_horizontal_mmxext;
+ if (chroma_format_idc == 1)
+ h->pred8x8[HOR_PRED8x8 ] = ff_pred8x8_horizontal_mmxext;
h->pred8x8l [TOP_DC_PRED ] = ff_pred8x8l_top_dc_mmxext;
h->pred8x8l [DC_PRED ] = ff_pred8x8l_dc_mmxext;
h->pred8x8l [HOR_PRED ] = ff_pred8x8l_horizontal_mmxext;
@@ -174,8 +225,10 @@ void ff_h264_pred_init_x86(H264PredContext *h, int codec_id, const int bit_depth
h->pred4x4 [HOR_UP_PRED ] = ff_pred4x4_horizontal_up_mmxext;
}
if (codec_id == CODEC_ID_SVQ3 || codec_id == CODEC_ID_H264) {
- h->pred8x8 [TOP_DC_PRED8x8 ] = ff_pred8x8_top_dc_mmxext;
- h->pred8x8 [DC_PRED8x8 ] = ff_pred8x8_dc_mmxext;
+ if (chroma_format_idc == 1) {
+ h->pred8x8[TOP_DC_PRED8x8 ] = ff_pred8x8_top_dc_mmxext;
+ h->pred8x8[DC_PRED8x8 ] = ff_pred8x8_dc_mmxext;
+ }
}
if (codec_id == CODEC_ID_VP8) {
h->pred16x16[PLANE_PRED8x8 ] = ff_pred16x16_tm_vp8_mmxext;
@@ -184,7 +237,8 @@ void ff_h264_pred_init_x86(H264PredContext *h, int codec_id, const int bit_depth
h->pred4x4 [TM_VP8_PRED ] = ff_pred4x4_tm_vp8_mmxext;
h->pred4x4 [VERT_PRED ] = ff_pred4x4_vertical_vp8_mmxext;
} else {
- h->pred8x8 [PLANE_PRED8x8] = ff_pred8x8_plane_mmx2;
+ if (chroma_format_idc == 1)
+ h->pred8x8 [PLANE_PRED8x8] = ff_pred8x8_plane_mmx2;
if (codec_id == CODEC_ID_SVQ3) {
h->pred16x16[PLANE_PRED8x8 ] = ff_pred16x16_plane_svq3_mmx2;
} else if (codec_id == CODEC_ID_RV40) {
@@ -210,7 +264,8 @@ void ff_h264_pred_init_x86(H264PredContext *h, int codec_id, const int bit_depth
h->pred16x16[PLANE_PRED8x8 ] = ff_pred16x16_tm_vp8_sse2;
h->pred8x8 [PLANE_PRED8x8 ] = ff_pred8x8_tm_vp8_sse2;
} else {
- h->pred8x8 [PLANE_PRED8x8 ] = ff_pred8x8_plane_sse2;
+ if (chroma_format_idc == 1)
+ h->pred8x8 [PLANE_PRED8x8] = ff_pred8x8_plane_sse2;
if (codec_id == CODEC_ID_SVQ3) {
h->pred16x16[PLANE_PRED8x8] = ff_pred16x16_plane_svq3_sse2;
} else if (codec_id == CODEC_ID_RV40) {
@@ -224,7 +279,8 @@ void ff_h264_pred_init_x86(H264PredContext *h, int codec_id, const int bit_depth
if (mm_flags & AV_CPU_FLAG_SSSE3) {
h->pred16x16[HOR_PRED8x8 ] = ff_pred16x16_horizontal_ssse3;
h->pred16x16[DC_PRED8x8 ] = ff_pred16x16_dc_ssse3;
- h->pred8x8 [HOR_PRED8x8 ] = ff_pred8x8_horizontal_ssse3;
+ if (chroma_format_idc == 1)
+ h->pred8x8 [HOR_PRED8x8 ] = ff_pred8x8_horizontal_ssse3;
h->pred8x8l [TOP_DC_PRED ] = ff_pred8x8l_top_dc_ssse3;
h->pred8x8l [DC_PRED ] = ff_pred8x8l_dc_ssse3;
h->pred8x8l [HOR_PRED ] = ff_pred8x8l_horizontal_ssse3;
@@ -239,7 +295,8 @@ void ff_h264_pred_init_x86(H264PredContext *h, int codec_id, const int bit_depth
h->pred8x8 [PLANE_PRED8x8 ] = ff_pred8x8_tm_vp8_ssse3;
h->pred4x4 [TM_VP8_PRED ] = ff_pred4x4_tm_vp8_ssse3;
} else {
- h->pred8x8 [PLANE_PRED8x8] = ff_pred8x8_plane_ssse3;
+ if (chroma_format_idc == 1)
+ h->pred8x8 [PLANE_PRED8x8] = ff_pred8x8_plane_ssse3;
if (codec_id == CODEC_ID_SVQ3) {
h->pred16x16[PLANE_PRED8x8] = ff_pred16x16_plane_svq3_ssse3;
} else if (codec_id == CODEC_ID_RV40) {
@@ -253,6 +310,18 @@ void ff_h264_pred_init_x86(H264PredContext *h, int codec_id, const int bit_depth
if (mm_flags & AV_CPU_FLAG_MMX2) {
h->pred4x4[DC_PRED ] = ff_pred4x4_dc_10_mmxext;
h->pred4x4[HOR_UP_PRED ] = ff_pred4x4_horizontal_up_10_mmxext;
+
+ if (chroma_format_idc == 1)
+ h->pred8x8[DC_PRED8x8 ] = ff_pred8x8_dc_10_mmxext;
+
+ h->pred8x8l[DC_128_PRED ] = ff_pred8x8l_128_dc_10_mmxext;
+
+ h->pred16x16[DC_PRED8x8 ] = ff_pred16x16_dc_10_mmxext;
+ h->pred16x16[TOP_DC_PRED8x8 ] = ff_pred16x16_top_dc_10_mmxext;
+ h->pred16x16[DC_128_PRED8x8 ] = ff_pred16x16_128_dc_10_mmxext;
+ h->pred16x16[LEFT_DC_PRED8x8 ] = ff_pred16x16_left_dc_10_mmxext;
+ h->pred16x16[VERT_PRED8x8 ] = ff_pred16x16_vertical_10_mmxext;
+ h->pred16x16[HOR_PRED8x8 ] = ff_pred16x16_horizontal_10_mmxext;
}
if (mm_flags & AV_CPU_FLAG_SSE2) {
h->pred4x4[DIAG_DOWN_LEFT_PRED ] = ff_pred4x4_down_left_10_sse2;
@@ -261,20 +330,58 @@ void ff_h264_pred_init_x86(H264PredContext *h, int codec_id, const int bit_depth
h->pred4x4[VERT_RIGHT_PRED ] = ff_pred4x4_vertical_right_10_sse2;
h->pred4x4[HOR_DOWN_PRED ] = ff_pred4x4_horizontal_down_10_sse2;
- h->pred8x8[VERT_PRED8x8 ] = ff_pred8x8_vertical_10_sse2;
- h->pred8x8[HOR_PRED8x8 ] = ff_pred8x8_horizontal_10_sse2;
+ if (chroma_format_idc == 1) {
+ h->pred8x8[DC_PRED8x8 ] = ff_pred8x8_dc_10_sse2;
+ h->pred8x8[TOP_DC_PRED8x8 ] = ff_pred8x8_top_dc_10_sse2;
+ h->pred8x8[PLANE_PRED8x8 ] = ff_pred8x8_plane_10_sse2;
+ h->pred8x8[VERT_PRED8x8 ] = ff_pred8x8_vertical_10_sse2;
+ h->pred8x8[HOR_PRED8x8 ] = ff_pred8x8_horizontal_10_sse2;
+ }
+
+ h->pred8x8l[VERT_PRED ] = ff_pred8x8l_vertical_10_sse2;
+ h->pred8x8l[HOR_PRED ] = ff_pred8x8l_horizontal_10_sse2;
+ h->pred8x8l[DC_PRED ] = ff_pred8x8l_dc_10_sse2;
+ h->pred8x8l[DC_128_PRED ] = ff_pred8x8l_128_dc_10_sse2;
+ h->pred8x8l[TOP_DC_PRED ] = ff_pred8x8l_top_dc_10_sse2;
+ h->pred8x8l[DIAG_DOWN_LEFT_PRED ] = ff_pred8x8l_down_left_10_sse2;
+ h->pred8x8l[DIAG_DOWN_RIGHT_PRED] = ff_pred8x8l_down_right_10_sse2;
+ h->pred8x8l[VERT_RIGHT_PRED ] = ff_pred8x8l_vertical_right_10_sse2;
+ h->pred8x8l[HOR_UP_PRED ] = ff_pred8x8l_horizontal_up_10_sse2;
+
+ h->pred16x16[DC_PRED8x8 ] = ff_pred16x16_dc_10_sse2;
+ h->pred16x16[TOP_DC_PRED8x8 ] = ff_pred16x16_top_dc_10_sse2;
+ h->pred16x16[DC_128_PRED8x8 ] = ff_pred16x16_128_dc_10_sse2;
+ h->pred16x16[LEFT_DC_PRED8x8 ] = ff_pred16x16_left_dc_10_sse2;
+ h->pred16x16[VERT_PRED8x8 ] = ff_pred16x16_vertical_10_sse2;
+ h->pred16x16[HOR_PRED8x8 ] = ff_pred16x16_horizontal_10_sse2;
}
if (mm_flags & AV_CPU_FLAG_SSSE3) {
h->pred4x4[DIAG_DOWN_RIGHT_PRED] = ff_pred4x4_down_right_10_ssse3;
h->pred4x4[VERT_RIGHT_PRED ] = ff_pred4x4_vertical_right_10_ssse3;
h->pred4x4[HOR_DOWN_PRED ] = ff_pred4x4_horizontal_down_10_ssse3;
+
+ h->pred8x8l[HOR_PRED ] = ff_pred8x8l_horizontal_10_ssse3;
+ h->pred8x8l[DIAG_DOWN_LEFT_PRED ] = ff_pred8x8l_down_left_10_ssse3;
+ h->pred8x8l[DIAG_DOWN_RIGHT_PRED] = ff_pred8x8l_down_right_10_ssse3;
+ h->pred8x8l[VERT_RIGHT_PRED ] = ff_pred8x8l_vertical_right_10_ssse3;
+ h->pred8x8l[HOR_UP_PRED ] = ff_pred8x8l_horizontal_up_10_ssse3;
}
#if HAVE_AVX
if (mm_flags & AV_CPU_FLAG_AVX) {
h->pred4x4[DIAG_DOWN_LEFT_PRED ] = ff_pred4x4_down_left_10_avx;
h->pred4x4[DIAG_DOWN_RIGHT_PRED] = ff_pred4x4_down_right_10_avx;
+ h->pred4x4[VERT_LEFT_PRED ] = ff_pred4x4_vertical_left_10_avx;
h->pred4x4[VERT_RIGHT_PRED ] = ff_pred4x4_vertical_right_10_avx;
h->pred4x4[HOR_DOWN_PRED ] = ff_pred4x4_horizontal_down_10_avx;
+
+ h->pred8x8l[VERT_PRED ] = ff_pred8x8l_vertical_10_avx;
+ h->pred8x8l[HOR_PRED ] = ff_pred8x8l_horizontal_10_avx;
+ h->pred8x8l[DC_PRED ] = ff_pred8x8l_dc_10_avx;
+ h->pred8x8l[TOP_DC_PRED ] = ff_pred8x8l_top_dc_10_avx;
+ h->pred8x8l[DIAG_DOWN_RIGHT_PRED] = ff_pred8x8l_down_right_10_avx;
+ h->pred8x8l[DIAG_DOWN_LEFT_PRED ] = ff_pred8x8l_down_left_10_avx;
+ h->pred8x8l[VERT_RIGHT_PRED ] = ff_pred8x8l_vertical_right_10_avx;
+ h->pred8x8l[HOR_UP_PRED ] = ff_pred8x8l_horizontal_up_10_avx;
}
#endif /* HAVE_AVX */
}
diff --git a/libavcodec/x86/h264_qpel_mmx.c b/libavcodec/x86/h264_qpel_mmx.c
index 91ba39f1da..807d8548d6 100644
--- a/libavcodec/x86/h264_qpel_mmx.c
+++ b/libavcodec/x86/h264_qpel_mmx.c
@@ -2,20 +2,20 @@
* Copyright (c) 2004-2005 Michael Niedermayer, Loren Merritt
* Copyright (c) 2011 Daniel Kang
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -399,7 +399,7 @@ static av_noinline void OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(uint8_t *dst,
"2: \n\t"\
\
: "+a"(src), "+c"(dst)\
- : "S"((x86_reg)srcStride), "D"((x86_reg)dstStride), "g"(h)\
+ : "S"((x86_reg)srcStride), "D"((x86_reg)dstStride), "rm"(h)\
: "memory"\
);\
src += 4-(h+5)*srcStride;\
@@ -447,7 +447,7 @@ static av_always_inline void OPNAME ## h264_qpel8or16_hv1_lowpass_ ## MMX(int16_
QPEL_H264HV(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, 15*48)\
"2: \n\t"\
: "+a"(src)\
- : "c"(tmp), "S"((x86_reg)srcStride), "g"(size)\
+ : "c"(tmp), "S"((x86_reg)srcStride), "rm"(size)\
: "memory"\
);\
tmp += 4;\
@@ -824,7 +824,7 @@ static av_noinline void OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(uint8_t *dst,
"2: \n\t"\
\
: "+a"(src), "+c"(dst)\
- : "S"((x86_reg)srcStride), "D"((x86_reg)dstStride), "g"(h)\
+ : "S"((x86_reg)srcStride), "D"((x86_reg)dstStride), "rm"(h)\
: XMM_CLOBBERS("%xmm0", "%xmm1", "%xmm2", "%xmm3", \
"%xmm4", "%xmm5", "%xmm6", "%xmm7",)\
"memory"\
@@ -879,7 +879,7 @@ static av_always_inline void put_h264_qpel8or16_hv1_lowpass_sse2(int16_t *tmp, u
QPEL_H264HV_XMM(%%xmm3, %%xmm4, %%xmm5, %%xmm0, %%xmm1, %%xmm2, 15*48)
"2: \n\t"
: "+a"(src)
- : "c"(tmp), "S"((x86_reg)srcStride), "g"(size)
+ : "c"(tmp), "S"((x86_reg)srcStride), "rm"(size)
: XMM_CLOBBERS("%xmm0", "%xmm1", "%xmm2", "%xmm3",
"%xmm4", "%xmm5", "%xmm6", "%xmm7",)
"memory"
diff --git a/libavcodec/x86/h264_weight.asm b/libavcodec/x86/h264_weight.asm
index d80ca32583..cc96cb1f3b 100644
--- a/libavcodec/x86/h264_weight.asm
+++ b/libavcodec/x86/h264_weight.asm
@@ -4,45 +4,44 @@
;* Copyright (c) 2004-2005 Michael Niedermayer, Loren Merritt
;* Copyright (C) 2010 Eli Friedman <eli.friedman@gmail.com>
;*
-;* This file is part of Libav.
+;* This file is part of FFmpeg.
;*
-;* Libav is free software; you can redistribute it and/or
+;* FFmpeg 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.
;*
-;* Libav is distributed in the hope that it will be useful,
+;* FFmpeg 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
;* Lesser General Public License for more details.
;*
;* You should have received a copy of the GNU Lesser General Public
-;* License along with Libav; if not, write to the Free Software
+;* License along with FFmpeg; if not, write to the Free Software
;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
;******************************************************************************
-%include "x86inc.asm"
+%include "libavutil/x86/x86inc.asm"
SECTION .text
;-----------------------------------------------------------------------------
; biweight pred:
;
-; void h264_biweight_16x16_sse2(uint8_t *dst, uint8_t *src, int stride,
-; int log2_denom, int weightd, int weights,
-; int offset);
+; void h264_biweight_16_sse2(uint8_t *dst, uint8_t *src, int stride,
+; int height, int log2_denom, int weightd,
+; int weights, int offset);
; and
-; void h264_weight_16x16_sse2(uint8_t *dst, int stride,
-; int log2_denom, int weight,
-; int offset);
+; void h264_weight_16_sse2(uint8_t *dst, int stride, int height,
+; int log2_denom, int weight, int offset);
;-----------------------------------------------------------------------------
%macro WEIGHT_SETUP 0
- add r4, r4
- inc r4
- movd m3, r3d
- movd m5, r4d
- movd m6, r2d
+ add r5, r5
+ inc r5
+ movd m3, r4d
+ movd m5, r5d
+ movd m6, r3d
pslld m5, m6
psrld m5, 1
%if mmsize == 16
@@ -71,60 +70,41 @@ SECTION .text
packuswb m0, m1
%endmacro
-%macro WEIGHT_FUNC_DBL_MM 1
-cglobal h264_weight_16x%1_mmx2, 5, 5, 0
+INIT_MMX
+cglobal h264_weight_16_mmx2, 6, 6, 0
WEIGHT_SETUP
- mov r2, %1
-%if %1 == 16
.nextrow
WEIGHT_OP 0, 4
mova [r0 ], m0
WEIGHT_OP 8, 12
mova [r0+8], m0
add r0, r1
- dec r2
+ dec r2d
jnz .nextrow
REP_RET
-%else
- jmp mangle(ff_h264_weight_16x16_mmx2.nextrow)
-%endif
-%endmacro
-INIT_MMX
-WEIGHT_FUNC_DBL_MM 16
-WEIGHT_FUNC_DBL_MM 8
-
-%macro WEIGHT_FUNC_MM 4
-cglobal h264_weight_%1x%2_%4, 7, 7, %3
+%macro WEIGHT_FUNC_MM 3
+cglobal h264_weight_%1_%3, 6, 6, %2
WEIGHT_SETUP
- mov r2, %2
-%if %2 == 16
.nextrow
WEIGHT_OP 0, mmsize/2
mova [r0], m0
add r0, r1
- dec r2
+ dec r2d
jnz .nextrow
REP_RET
-%else
- jmp mangle(ff_h264_weight_%1x16_%4.nextrow)
-%endif
%endmacro
INIT_MMX
-WEIGHT_FUNC_MM 8, 16, 0, mmx2
-WEIGHT_FUNC_MM 8, 8, 0, mmx2
-WEIGHT_FUNC_MM 8, 4, 0, mmx2
+WEIGHT_FUNC_MM 8, 0, mmx2
INIT_XMM
-WEIGHT_FUNC_MM 16, 16, 8, sse2
-WEIGHT_FUNC_MM 16, 8, 8, sse2
+WEIGHT_FUNC_MM 16, 8, sse2
-%macro WEIGHT_FUNC_HALF_MM 5
-cglobal h264_weight_%1x%2_%5, 5, 5, %4
+%macro WEIGHT_FUNC_HALF_MM 3
+cglobal h264_weight_%1_%3, 6, 6, %2
WEIGHT_SETUP
- mov r2, %2/2
+ sar r2d, 1
lea r3, [r1*2]
-%if %2 == mmsize
.nextrow
WEIGHT_OP 0, r1
movh [r0], m0
@@ -135,31 +115,34 @@ cglobal h264_weight_%1x%2_%5, 5, 5, %4
movh [r0+r1], m0
%endif
add r0, r3
- dec r2
+ dec r2d
jnz .nextrow
REP_RET
-%else
- jmp mangle(ff_h264_weight_%1x%3_%5.nextrow)
-%endif
%endmacro
INIT_MMX
-WEIGHT_FUNC_HALF_MM 4, 8, 8, 0, mmx2
-WEIGHT_FUNC_HALF_MM 4, 4, 8, 0, mmx2
-WEIGHT_FUNC_HALF_MM 4, 2, 8, 0, mmx2
+WEIGHT_FUNC_HALF_MM 4, 0, mmx2
+WEIGHT_FUNC_HALF_MM 4, 0, mmx2
+WEIGHT_FUNC_HALF_MM 4, 0, mmx2
INIT_XMM
-WEIGHT_FUNC_HALF_MM 8, 16, 16, 8, sse2
-WEIGHT_FUNC_HALF_MM 8, 8, 16, 8, sse2
-WEIGHT_FUNC_HALF_MM 8, 4, 16, 8, sse2
+WEIGHT_FUNC_HALF_MM 8, 8, sse2
+WEIGHT_FUNC_HALF_MM 8, 8, sse2
+WEIGHT_FUNC_HALF_MM 8, 8, sse2
%macro BIWEIGHT_SETUP 0
- add r6, 1
- or r6, 1
- add r3, 1
- movd m3, r4d
- movd m4, r5d
- movd m5, r6d
- movd m6, r3d
+%ifdef ARCH_X86_64
+%define off_regd r11d
+%else
+%define off_regd r3d
+%endif
+ mov off_regd, r7m
+ add off_regd, 1
+ or off_regd, 1
+ add r4, 1
+ movd m3, r5d
+ movd m4, r6d
+ movd m5, off_regd
+ movd m6, r4d
pslld m5, m6
psrld m5, 1
%if mmsize == 16
@@ -195,11 +178,10 @@ WEIGHT_FUNC_HALF_MM 8, 4, 16, 8, sse2
packuswb m0, m1
%endmacro
-%macro BIWEIGHT_FUNC_DBL_MM 1
-cglobal h264_biweight_16x%1_mmx2, 7, 7, 0
+INIT_MMX
+cglobal h264_biweight_16_mmx2, 7, 7, 0
BIWEIGHT_SETUP
- mov r3, %1
-%if %1 == 16
+ movifnidn r3d, r3m
.nextrow
BIWEIGHT_STEPA 0, 1, 0
BIWEIGHT_STEPA 1, 2, 4
@@ -211,23 +193,14 @@ cglobal h264_biweight_16x%1_mmx2, 7, 7, 0
mova [r0+8], m0
add r0, r2
add r1, r2
- dec r3
+ dec r3d
jnz .nextrow
REP_RET
-%else
- jmp mangle(ff_h264_biweight_16x16_mmx2.nextrow)
-%endif
-%endmacro
-INIT_MMX
-BIWEIGHT_FUNC_DBL_MM 16
-BIWEIGHT_FUNC_DBL_MM 8
-
-%macro BIWEIGHT_FUNC_MM 4
-cglobal h264_biweight_%1x%2_%4, 7, 7, %3
+%macro BIWEIGHT_FUNC_MM 3
+cglobal h264_biweight_%1_%3, 7, 7, %2
BIWEIGHT_SETUP
- mov r3, %2
-%if %2 == 16
+ movifnidn r3d, r3m
.nextrow
BIWEIGHT_STEPA 0, 1, 0
BIWEIGHT_STEPA 1, 2, mmsize/2
@@ -235,28 +208,22 @@ cglobal h264_biweight_%1x%2_%4, 7, 7, %3
mova [r0], m0
add r0, r2
add r1, r2
- dec r3
+ dec r3d
jnz .nextrow
REP_RET
-%else
- jmp mangle(ff_h264_biweight_%1x16_%4.nextrow)
-%endif
%endmacro
INIT_MMX
-BIWEIGHT_FUNC_MM 8, 16, 0, mmx2
-BIWEIGHT_FUNC_MM 8, 8, 0, mmx2
-BIWEIGHT_FUNC_MM 8, 4, 0, mmx2
+BIWEIGHT_FUNC_MM 8, 0, mmx2
INIT_XMM
-BIWEIGHT_FUNC_MM 16, 16, 8, sse2
-BIWEIGHT_FUNC_MM 16, 8, 8, sse2
+BIWEIGHT_FUNC_MM 16, 8, sse2
-%macro BIWEIGHT_FUNC_HALF_MM 5
-cglobal h264_biweight_%1x%2_%5, 7, 7, %4
+%macro BIWEIGHT_FUNC_HALF_MM 3
+cglobal h264_biweight_%1_%3, 7, 7, %2
BIWEIGHT_SETUP
- mov r3, %2/2
+ movifnidn r3d, r3m
+ sar r3, 1
lea r4, [r2*2]
-%if %2 == mmsize
.nextrow
BIWEIGHT_STEPA 0, 1, 0
BIWEIGHT_STEPA 1, 2, r2
@@ -270,31 +237,30 @@ cglobal h264_biweight_%1x%2_%5, 7, 7, %4
%endif
add r0, r4
add r1, r4
- dec r3
+ dec r3d
jnz .nextrow
REP_RET
-%else
- jmp mangle(ff_h264_biweight_%1x%3_%5.nextrow)
-%endif
%endmacro
INIT_MMX
-BIWEIGHT_FUNC_HALF_MM 4, 8, 8, 0, mmx2
-BIWEIGHT_FUNC_HALF_MM 4, 4, 8, 0, mmx2
-BIWEIGHT_FUNC_HALF_MM 4, 2, 8, 0, mmx2
+BIWEIGHT_FUNC_HALF_MM 4, 0, mmx2
INIT_XMM
-BIWEIGHT_FUNC_HALF_MM 8, 16, 16, 8, sse2
-BIWEIGHT_FUNC_HALF_MM 8, 8, 16, 8, sse2
-BIWEIGHT_FUNC_HALF_MM 8, 4, 16, 8, sse2
+BIWEIGHT_FUNC_HALF_MM 8, 8, sse2
%macro BIWEIGHT_SSSE3_SETUP 0
- add r6, 1
- or r6, 1
- add r3, 1
- movd m4, r4d
- movd m0, r5d
- movd m5, r6d
- movd m6, r3d
+%ifdef ARCH_X86_64
+%define off_regd r11d
+%else
+%define off_regd r3d
+%endif
+ mov off_regd, r7m
+ add off_regd, 1
+ or off_regd, 1
+ add r4, 1
+ movd m4, r5d
+ movd m0, r6d
+ movd m5, off_regd
+ movd m6, r4d
pslld m5, m6
psrld m5, 1
punpcklbw m4, m0
@@ -314,12 +280,11 @@ BIWEIGHT_FUNC_HALF_MM 8, 4, 16, 8, sse2
packuswb m0, m2
%endmacro
-%macro BIWEIGHT_SSSE3_16 1
-cglobal h264_biweight_16x%1_ssse3, 7, 7, 8
+INIT_XMM
+cglobal h264_biweight_16_ssse3, 7, 7, 8
BIWEIGHT_SSSE3_SETUP
- mov r3, %1
+ movifnidn r3d, r3m
-%if %1 == 16
.nextrow
movh m0, [r0]
movh m2, [r0+8]
@@ -330,25 +295,17 @@ cglobal h264_biweight_16x%1_ssse3, 7, 7, 8
mova [r0], m0
add r0, r2
add r1, r2
- dec r3
+ dec r3d
jnz .nextrow
REP_RET
-%else
- jmp mangle(ff_h264_biweight_16x16_ssse3.nextrow)
-%endif
-%endmacro
INIT_XMM
-BIWEIGHT_SSSE3_16 16
-BIWEIGHT_SSSE3_16 8
-
-%macro BIWEIGHT_SSSE3_8 1
-cglobal h264_biweight_8x%1_ssse3, 7, 7, 8
+cglobal h264_biweight_8_ssse3, 7, 7, 8
BIWEIGHT_SSSE3_SETUP
- mov r3, %1/2
+ movifnidn r3d, r3m
+ sar r3, 1
lea r4, [r2*2]
-%if %1 == 16
.nextrow
movh m0, [r0]
movh m1, [r1]
@@ -361,15 +318,6 @@ cglobal h264_biweight_8x%1_ssse3, 7, 7, 8
movhps [r0+r2], m0
add r0, r4
add r1, r4
- dec r3
+ dec r3d
jnz .nextrow
REP_RET
-%else
- jmp mangle(ff_h264_biweight_8x16_ssse3.nextrow)
-%endif
-%endmacro
-
-INIT_XMM
-BIWEIGHT_SSSE3_8 16
-BIWEIGHT_SSSE3_8 8
-BIWEIGHT_SSSE3_8 4
diff --git a/libavcodec/x86/h264_weight_10bit.asm b/libavcodec/x86/h264_weight_10bit.asm
index 1c58d72d94..20df6fbab5 100644
--- a/libavcodec/x86/h264_weight_10bit.asm
+++ b/libavcodec/x86/h264_weight_10bit.asm
@@ -36,33 +36,26 @@ cextern pw_1
SECTION .text
;-----------------------------------------------------------------------------
-; void h264_weight(uint8_t *dst, int stride, int log2_denom,
+; void h264_weight(uint8_t *dst, int stride, int height, int log2_denom,
; int weight, int offset);
;-----------------------------------------------------------------------------
-%ifdef ARCH_X86_32
-DECLARE_REG_TMP 2
-%else
-DECLARE_REG_TMP 10
-%endif
-
-%macro WEIGHT_PROLOGUE 1
- mov t0, %1
+%macro WEIGHT_PROLOGUE 0
.prologue
- PROLOGUE 0,5,8
+ PROLOGUE 0,6,8
movifnidn r0, r0mp
movifnidn r1d, r1m
- movifnidn r3d, r3m
movifnidn r4d, r4m
+ movifnidn r5d, r5m
%endmacro
%macro WEIGHT_SETUP 1
mova m0, [pw_1]
- movd m2, r2m
+ movd m2, r3m
pslld m0, m2 ; 1<<log2_denom
SPLATW m0, m0
- shl r4, 19 ; *8, move to upper half of dword
- lea r4, [r4+r3*2+0x10000]
- movd m3, r4d ; weight<<1 | 1+(offset<<(3))
+ shl r5, 19 ; *8, move to upper half of dword
+ lea r5, [r5+r4*2+0x10000]
+ movd m3, r5d ; weight<<1 | 1+(offset<<(3))
pshufd m3, m3, 0
mova m4, [pw_pixel_max]
paddw m2, [sq_1] ; log2_denom+1
@@ -96,8 +89,8 @@ DECLARE_REG_TMP 10
%endmacro
%macro WEIGHT_FUNC_DBL 1
-cglobal h264_weight_16x16_10_%1
- WEIGHT_PROLOGUE 16
+cglobal h264_weight_16_10_%1
+ WEIGHT_PROLOGUE
WEIGHT_SETUP %1
.nextrow
WEIGHT_OP %1, 0
@@ -105,13 +98,9 @@ cglobal h264_weight_16x16_10_%1
WEIGHT_OP %1, 16
mova [r0+16], m5
add r0, r1
- dec t0
+ dec r2d
jnz .nextrow
REP_RET
-
-cglobal h264_weight_16x8_10_%1
- mov t0, 8
- jmp mangle(ff_h264_weight_16x16_10_%1.prologue)
%endmacro
INIT_XMM
@@ -120,24 +109,16 @@ WEIGHT_FUNC_DBL sse4
%macro WEIGHT_FUNC_MM 1
-cglobal h264_weight_8x16_10_%1
- WEIGHT_PROLOGUE 16
+cglobal h264_weight_8_10_%1
+ WEIGHT_PROLOGUE
WEIGHT_SETUP %1
.nextrow
WEIGHT_OP %1, 0
mova [r0], m5
add r0, r1
- dec t0
+ dec r2d
jnz .nextrow
REP_RET
-
-cglobal h264_weight_8x8_10_%1
- mov t0, 8
- jmp mangle(ff_h264_weight_8x16_10_%1.prologue)
-
-cglobal h264_weight_8x4_10_%1
- mov t0, 4
- jmp mangle(ff_h264_weight_8x16_10_%1.prologue)
%endmacro
INIT_XMM
@@ -146,8 +127,9 @@ WEIGHT_FUNC_MM sse4
%macro WEIGHT_FUNC_HALF_MM 1
-cglobal h264_weight_4x8_10_%1
- WEIGHT_PROLOGUE 4
+cglobal h264_weight_4_10_%1
+ WEIGHT_PROLOGUE
+ sar r2d, 1
WEIGHT_SETUP %1
lea r3, [r1*2]
.nextrow
@@ -155,17 +137,9 @@ cglobal h264_weight_4x8_10_%1
movh [r0], m5
movhps [r0+r1], m5
add r0, r3
- dec t0
+ dec r2d
jnz .nextrow
REP_RET
-
-cglobal h264_weight_4x4_10_%1
- mov t0, 2
- jmp mangle(ff_h264_weight_4x8_10_%1.prologue)
-
-cglobal h264_weight_4x2_10_%1
- mov t0, 1
- jmp mangle(ff_h264_weight_4x8_10_%1.prologue)
%endmacro
INIT_XMM
@@ -174,40 +148,40 @@ WEIGHT_FUNC_HALF_MM sse4
;-----------------------------------------------------------------------------
-; void h264_biweight(uint8_t *dst, uint8_t *src, int stride, int log2_denom,
-; int weightd, int weights, int offset);
+; void h264_biweight(uint8_t *dst, uint8_t *src, int stride, int height,
+; int log2_denom, int weightd, int weights, int offset);
;-----------------------------------------------------------------------------
%ifdef ARCH_X86_32
-DECLARE_REG_TMP 2,3
+DECLARE_REG_TMP 3
%else
-DECLARE_REG_TMP 10,2
+DECLARE_REG_TMP 10
%endif
-%macro BIWEIGHT_PROLOGUE 1
- mov t0, %1
+%macro BIWEIGHT_PROLOGUE 0
.prologue
PROLOGUE 0,7,8
movifnidn r0, r0mp
movifnidn r1, r1mp
- movifnidn t1d, r2m
- movifnidn r4d, r4m
+ movifnidn r2d, r2m
movifnidn r5d, r5m
movifnidn r6d, r6m
+ movifnidn t0d, r7m
%endmacro
%macro BIWEIGHT_SETUP 1
- lea r6, [r6*4+1] ; (offset<<2)+1
- or r6, 1
- shl r5, 16
- or r4, r5
- movd m4, r4d ; weightd | weights
- movd m5, r6d ; (offset+1)|1
- movd m6, r3m ; log2_denom
+ lea t0, [t0*4+1] ; (offset<<2)+1
+ or t0, 1
+ shl r6, 16
+ or r5, r6
+ movd m4, r5d ; weightd | weights
+ movd m5, t0d ; (offset+1)|1
+ movd m6, r4m ; log2_denom
pslld m5, m6 ; (((offset<<2)+1)|1)<<log2_denom
paddd m6, [sq_1]
pshufd m4, m4, 0
pshufd m5, m5, 0
mova m3, [pw_pixel_max]
+ movifnidn r3d, r3m
%ifnidn %1, sse4
pxor m7, m7
%endif
@@ -243,23 +217,19 @@ DECLARE_REG_TMP 10,2
%endmacro
%macro BIWEIGHT_FUNC_DBL 1
-cglobal h264_biweight_16x16_10_%1
- BIWEIGHT_PROLOGUE 16
+cglobal h264_biweight_16_10_%1
+ BIWEIGHT_PROLOGUE
BIWEIGHT_SETUP %1
.nextrow
BIWEIGHT %1, 0
mova [r0 ], m0
BIWEIGHT %1, 16
mova [r0+16], m0
- add r0, t1
- add r1, t1
- dec t0
+ add r0, r2
+ add r1, r2
+ dec r3d
jnz .nextrow
REP_RET
-
-cglobal h264_biweight_16x8_10_%1
- mov t0, 8
- jmp mangle(ff_h264_biweight_16x16_10_%1.prologue)
%endmacro
INIT_XMM
@@ -267,25 +237,17 @@ BIWEIGHT_FUNC_DBL sse2
BIWEIGHT_FUNC_DBL sse4
%macro BIWEIGHT_FUNC 1
-cglobal h264_biweight_8x16_10_%1
- BIWEIGHT_PROLOGUE 16
+cglobal h264_biweight_8_10_%1
+ BIWEIGHT_PROLOGUE
BIWEIGHT_SETUP %1
.nextrow
BIWEIGHT %1, 0
mova [r0], m0
- add r0, t1
- add r1, t1
- dec t0
+ add r0, r2
+ add r1, r2
+ dec r3d
jnz .nextrow
REP_RET
-
-cglobal h264_biweight_8x8_10_%1
- mov t0, 8
- jmp mangle(ff_h264_biweight_8x16_10_%1.prologue)
-
-cglobal h264_biweight_8x4_10_%1
- mov t0, 4
- jmp mangle(ff_h264_biweight_8x16_10_%1.prologue)
%endmacro
INIT_XMM
@@ -293,27 +255,20 @@ BIWEIGHT_FUNC sse2
BIWEIGHT_FUNC sse4
%macro BIWEIGHT_FUNC_HALF 1
-cglobal h264_biweight_4x8_10_%1
- BIWEIGHT_PROLOGUE 4
+cglobal h264_biweight_4_10_%1
+ BIWEIGHT_PROLOGUE
BIWEIGHT_SETUP %1
- lea r4, [t1*2]
+ sar r3d, 1
+ lea r4, [r2*2]
.nextrow
- BIWEIGHT %1, 0, t1
+ BIWEIGHT %1, 0, r2
movh [r0 ], m0
- movhps [r0+t1], m0
+ movhps [r0+r2], m0
add r0, r4
add r1, r4
- dec t0
+ dec r3d
jnz .nextrow
REP_RET
-
-cglobal h264_biweight_4x4_10_%1
- mov t0, 2
- jmp mangle(ff_h264_biweight_4x8_10_%1.prologue)
-
-cglobal h264_biweight_4x2_10_%1
- mov t0, 1
- jmp mangle(ff_h264_biweight_4x8_10_%1.prologue)
%endmacro
INIT_XMM
diff --git a/libavcodec/x86/h264dsp_mmx.c b/libavcodec/x86/h264dsp_mmx.c
index 1042552948..b337462aec 100644
--- a/libavcodec/x86/h264dsp_mmx.c
+++ b/libavcodec/x86/h264dsp_mmx.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2004-2005 Michael Niedermayer, Loren Merritt
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -298,66 +298,57 @@ LF_IFUNC(v, luma_intra, 10, mmxext)
/***********************************/
/* weighted prediction */
-#define H264_WEIGHT(W, H, OPT) \
-void ff_h264_weight_ ## W ## x ## H ## _ ## OPT(uint8_t *dst, \
- int stride, int log2_denom, int weight, int offset);
+#define H264_WEIGHT(W, OPT) \
+void ff_h264_weight_ ## W ## _ ## OPT(uint8_t *dst, \
+ int stride, int height, int log2_denom, int weight, int offset);
-#define H264_BIWEIGHT(W, H, OPT) \
-void ff_h264_biweight_ ## W ## x ## H ## _ ## OPT(uint8_t *dst, \
- uint8_t *src, int stride, int log2_denom, int weightd, \
+#define H264_BIWEIGHT(W, OPT) \
+void ff_h264_biweight_ ## W ## _ ## OPT(uint8_t *dst, \
+ uint8_t *src, int stride, int height, int log2_denom, int weightd, \
int weights, int offset);
-#define H264_BIWEIGHT_MMX(W,H) \
-H264_WEIGHT (W, H, mmx2) \
-H264_BIWEIGHT(W, H, mmx2)
-
-#define H264_BIWEIGHT_MMX_SSE(W,H) \
-H264_BIWEIGHT_MMX(W, H) \
-H264_WEIGHT (W, H, sse2) \
-H264_BIWEIGHT (W, H, sse2) \
-H264_BIWEIGHT (W, H, ssse3)
-
-H264_BIWEIGHT_MMX_SSE(16, 16)
-H264_BIWEIGHT_MMX_SSE(16, 8)
-H264_BIWEIGHT_MMX_SSE( 8, 16)
-H264_BIWEIGHT_MMX_SSE( 8, 8)
-H264_BIWEIGHT_MMX_SSE( 8, 4)
-H264_BIWEIGHT_MMX ( 4, 8)
-H264_BIWEIGHT_MMX ( 4, 4)
-H264_BIWEIGHT_MMX ( 4, 2)
-
-#define H264_WEIGHT_10(W, H, DEPTH, OPT) \
-void ff_h264_weight_ ## W ## x ## H ## _ ## DEPTH ## _ ## OPT(uint8_t *dst, \
- int stride, int log2_denom, int weight, int offset);
-
-#define H264_BIWEIGHT_10(W, H, DEPTH, OPT) \
-void ff_h264_biweight_ ## W ## x ## H ## _ ## DEPTH ## _ ## OPT \
- (uint8_t *dst, uint8_t *src, int stride, int log2_denom, \
+#define H264_BIWEIGHT_MMX(W) \
+H264_WEIGHT (W, mmx2) \
+H264_BIWEIGHT(W, mmx2)
+
+#define H264_BIWEIGHT_MMX_SSE(W) \
+H264_BIWEIGHT_MMX(W) \
+H264_WEIGHT (W, sse2) \
+H264_BIWEIGHT (W, sse2) \
+H264_BIWEIGHT (W, ssse3)
+
+H264_BIWEIGHT_MMX_SSE(16)
+H264_BIWEIGHT_MMX_SSE( 8)
+H264_BIWEIGHT_MMX ( 4)
+
+#define H264_WEIGHT_10(W, DEPTH, OPT) \
+void ff_h264_weight_ ## W ## _ ## DEPTH ## _ ## OPT(uint8_t *dst, \
+ int stride, int height, int log2_denom, int weight, int offset);
+
+#define H264_BIWEIGHT_10(W, DEPTH, OPT) \
+void ff_h264_biweight_ ## W ## _ ## DEPTH ## _ ## OPT \
+ (uint8_t *dst, uint8_t *src, int stride, int height, int log2_denom, \
int weightd, int weights, int offset);
-#define H264_BIWEIGHT_10_SSE(W, H, DEPTH) \
-H264_WEIGHT_10 (W, H, DEPTH, sse2) \
-H264_WEIGHT_10 (W, H, DEPTH, sse4) \
-H264_BIWEIGHT_10(W, H, DEPTH, sse2) \
-H264_BIWEIGHT_10(W, H, DEPTH, sse4)
-
-H264_BIWEIGHT_10_SSE(16, 16, 10)
-H264_BIWEIGHT_10_SSE(16, 8, 10)
-H264_BIWEIGHT_10_SSE( 8, 16, 10)
-H264_BIWEIGHT_10_SSE( 8, 8, 10)
-H264_BIWEIGHT_10_SSE( 8, 4, 10)
-H264_BIWEIGHT_10_SSE( 4, 8, 10)
-H264_BIWEIGHT_10_SSE( 4, 4, 10)
-H264_BIWEIGHT_10_SSE( 4, 2, 10)
-
-void ff_h264dsp_init_x86(H264DSPContext *c, const int bit_depth)
+#define H264_BIWEIGHT_10_SSE(W, DEPTH) \
+H264_WEIGHT_10 (W, DEPTH, sse2) \
+H264_WEIGHT_10 (W, DEPTH, sse4) \
+H264_BIWEIGHT_10(W, DEPTH, sse2) \
+H264_BIWEIGHT_10(W, DEPTH, sse4)
+
+H264_BIWEIGHT_10_SSE(16, 10)
+H264_BIWEIGHT_10_SSE( 8, 10)
+H264_BIWEIGHT_10_SSE( 4, 10)
+
+void ff_h264dsp_init_x86(H264DSPContext *c, const int bit_depth, const int chroma_format_idc)
{
int mm_flags = av_get_cpu_flags();
- if (bit_depth == 8) {
- if (mm_flags & AV_CPU_FLAG_MMX2) {
+ if (chroma_format_idc == 1 && mm_flags & AV_CPU_FLAG_MMX2) {
c->h264_loop_filter_strength= h264_loop_filter_strength_mmx2;
}
+
+ if (bit_depth == 8) {
#if HAVE_YASM
if (mm_flags & AV_CPU_FLAG_MMX) {
c->h264_idct_dc_add =
@@ -367,7 +358,8 @@ void ff_h264dsp_init_x86(H264DSPContext *c, const int bit_depth)
c->h264_idct_add16 = ff_h264_idct_add16_8_mmx;
c->h264_idct8_add4 = ff_h264_idct8_add4_8_mmx;
- c->h264_idct_add8 = ff_h264_idct_add8_8_mmx;
+ if (chroma_format_idc == 1)
+ c->h264_idct_add8 = ff_h264_idct_add8_8_mmx;
c->h264_idct_add16intra = ff_h264_idct_add16intra_8_mmx;
c->h264_luma_dc_dequant_idct= ff_h264_luma_dc_dequant_idct_mmx;
@@ -376,57 +368,45 @@ void ff_h264dsp_init_x86(H264DSPContext *c, const int bit_depth)
c->h264_idct8_dc_add = ff_h264_idct8_dc_add_8_mmx2;
c->h264_idct_add16 = ff_h264_idct_add16_8_mmx2;
c->h264_idct8_add4 = ff_h264_idct8_add4_8_mmx2;
- c->h264_idct_add8 = ff_h264_idct_add8_8_mmx2;
+ if (chroma_format_idc == 1)
+ c->h264_idct_add8 = ff_h264_idct_add8_8_mmx2;
c->h264_idct_add16intra= ff_h264_idct_add16intra_8_mmx2;
c->h264_v_loop_filter_chroma= ff_deblock_v_chroma_8_mmxext;
- c->h264_h_loop_filter_chroma= ff_deblock_h_chroma_8_mmxext;
c->h264_v_loop_filter_chroma_intra= ff_deblock_v_chroma_intra_8_mmxext;
- c->h264_h_loop_filter_chroma_intra= ff_deblock_h_chroma_intra_8_mmxext;
+ if (chroma_format_idc == 1) {
+ c->h264_h_loop_filter_chroma= ff_deblock_h_chroma_8_mmxext;
+ c->h264_h_loop_filter_chroma_intra= ff_deblock_h_chroma_intra_8_mmxext;
+ }
#if ARCH_X86_32
c->h264_v_loop_filter_luma= ff_deblock_v_luma_8_mmxext;
c->h264_h_loop_filter_luma= ff_deblock_h_luma_8_mmxext;
c->h264_v_loop_filter_luma_intra = ff_deblock_v_luma_intra_8_mmxext;
c->h264_h_loop_filter_luma_intra = ff_deblock_h_luma_intra_8_mmxext;
#endif
- c->weight_h264_pixels_tab[0]= ff_h264_weight_16x16_mmx2;
- c->weight_h264_pixels_tab[1]= ff_h264_weight_16x8_mmx2;
- c->weight_h264_pixels_tab[2]= ff_h264_weight_8x16_mmx2;
- c->weight_h264_pixels_tab[3]= ff_h264_weight_8x8_mmx2;
- c->weight_h264_pixels_tab[4]= ff_h264_weight_8x4_mmx2;
- c->weight_h264_pixels_tab[5]= ff_h264_weight_4x8_mmx2;
- c->weight_h264_pixels_tab[6]= ff_h264_weight_4x4_mmx2;
- c->weight_h264_pixels_tab[7]= ff_h264_weight_4x2_mmx2;
-
- c->biweight_h264_pixels_tab[0]= ff_h264_biweight_16x16_mmx2;
- c->biweight_h264_pixels_tab[1]= ff_h264_biweight_16x8_mmx2;
- c->biweight_h264_pixels_tab[2]= ff_h264_biweight_8x16_mmx2;
- c->biweight_h264_pixels_tab[3]= ff_h264_biweight_8x8_mmx2;
- c->biweight_h264_pixels_tab[4]= ff_h264_biweight_8x4_mmx2;
- c->biweight_h264_pixels_tab[5]= ff_h264_biweight_4x8_mmx2;
- c->biweight_h264_pixels_tab[6]= ff_h264_biweight_4x4_mmx2;
- c->biweight_h264_pixels_tab[7]= ff_h264_biweight_4x2_mmx2;
+ c->weight_h264_pixels_tab[0]= ff_h264_weight_16_mmx2;
+ c->weight_h264_pixels_tab[1]= ff_h264_weight_8_mmx2;
+ c->weight_h264_pixels_tab[2]= ff_h264_weight_4_mmx2;
+
+ c->biweight_h264_pixels_tab[0]= ff_h264_biweight_16_mmx2;
+ c->biweight_h264_pixels_tab[1]= ff_h264_biweight_8_mmx2;
+ c->biweight_h264_pixels_tab[2]= ff_h264_biweight_4_mmx2;
if (mm_flags&AV_CPU_FLAG_SSE2) {
c->h264_idct8_add = ff_h264_idct8_add_8_sse2;
c->h264_idct_add16 = ff_h264_idct_add16_8_sse2;
c->h264_idct8_add4 = ff_h264_idct8_add4_8_sse2;
- c->h264_idct_add8 = ff_h264_idct_add8_8_sse2;
+ if (chroma_format_idc == 1)
+ c->h264_idct_add8 = ff_h264_idct_add8_8_sse2;
c->h264_idct_add16intra = ff_h264_idct_add16intra_8_sse2;
c->h264_luma_dc_dequant_idct= ff_h264_luma_dc_dequant_idct_sse2;
- c->weight_h264_pixels_tab[0]= ff_h264_weight_16x16_sse2;
- c->weight_h264_pixels_tab[1]= ff_h264_weight_16x8_sse2;
- c->weight_h264_pixels_tab[2]= ff_h264_weight_8x16_sse2;
- c->weight_h264_pixels_tab[3]= ff_h264_weight_8x8_sse2;
- c->weight_h264_pixels_tab[4]= ff_h264_weight_8x4_sse2;
+ c->weight_h264_pixels_tab[0]= ff_h264_weight_16_sse2;
+ c->weight_h264_pixels_tab[1]= ff_h264_weight_8_sse2;
- c->biweight_h264_pixels_tab[0]= ff_h264_biweight_16x16_sse2;
- c->biweight_h264_pixels_tab[1]= ff_h264_biweight_16x8_sse2;
- c->biweight_h264_pixels_tab[2]= ff_h264_biweight_8x16_sse2;
- c->biweight_h264_pixels_tab[3]= ff_h264_biweight_8x8_sse2;
- c->biweight_h264_pixels_tab[4]= ff_h264_biweight_8x4_sse2;
+ c->biweight_h264_pixels_tab[0]= ff_h264_biweight_16_sse2;
+ c->biweight_h264_pixels_tab[1]= ff_h264_biweight_8_sse2;
#if HAVE_ALIGNED_STACK
c->h264_v_loop_filter_luma = ff_deblock_v_luma_8_sse2;
@@ -436,13 +416,10 @@ void ff_h264dsp_init_x86(H264DSPContext *c, const int bit_depth)
#endif
}
if (mm_flags&AV_CPU_FLAG_SSSE3) {
- c->biweight_h264_pixels_tab[0]= ff_h264_biweight_16x16_ssse3;
- c->biweight_h264_pixels_tab[1]= ff_h264_biweight_16x8_ssse3;
- c->biweight_h264_pixels_tab[2]= ff_h264_biweight_8x16_ssse3;
- c->biweight_h264_pixels_tab[3]= ff_h264_biweight_8x8_ssse3;
- c->biweight_h264_pixels_tab[4]= ff_h264_biweight_8x4_ssse3;
+ c->biweight_h264_pixels_tab[0]= ff_h264_biweight_16_ssse3;
+ c->biweight_h264_pixels_tab[1]= ff_h264_biweight_8_ssse3;
}
- if (mm_flags&AV_CPU_FLAG_AVX) {
+ if (HAVE_AVX && mm_flags&AV_CPU_FLAG_AVX) {
#if HAVE_ALIGNED_STACK
c->h264_v_loop_filter_luma = ff_deblock_v_luma_8_avx;
c->h264_h_loop_filter_luma = ff_deblock_h_luma_8_avx;
@@ -471,30 +448,21 @@ void ff_h264dsp_init_x86(H264DSPContext *c, const int bit_depth)
c->h264_idct8_dc_add = ff_h264_idct8_dc_add_10_sse2;
c->h264_idct_add16 = ff_h264_idct_add16_10_sse2;
- c->h264_idct_add8 = ff_h264_idct_add8_10_sse2;
+ if (chroma_format_idc == 1)
+ c->h264_idct_add8 = ff_h264_idct_add8_10_sse2;
c->h264_idct_add16intra= ff_h264_idct_add16intra_10_sse2;
#if HAVE_ALIGNED_STACK
c->h264_idct8_add = ff_h264_idct8_add_10_sse2;
c->h264_idct8_add4 = ff_h264_idct8_add4_10_sse2;
#endif
- c->weight_h264_pixels_tab[0] = ff_h264_weight_16x16_10_sse2;
- c->weight_h264_pixels_tab[1] = ff_h264_weight_16x8_10_sse2;
- c->weight_h264_pixels_tab[2] = ff_h264_weight_8x16_10_sse2;
- c->weight_h264_pixels_tab[3] = ff_h264_weight_8x8_10_sse2;
- c->weight_h264_pixels_tab[4] = ff_h264_weight_8x4_10_sse2;
- c->weight_h264_pixels_tab[5] = ff_h264_weight_4x8_10_sse2;
- c->weight_h264_pixels_tab[6] = ff_h264_weight_4x4_10_sse2;
- c->weight_h264_pixels_tab[7] = ff_h264_weight_4x2_10_sse2;
-
- c->biweight_h264_pixels_tab[0] = ff_h264_biweight_16x16_10_sse2;
- c->biweight_h264_pixels_tab[1] = ff_h264_biweight_16x8_10_sse2;
- c->biweight_h264_pixels_tab[2] = ff_h264_biweight_8x16_10_sse2;
- c->biweight_h264_pixels_tab[3] = ff_h264_biweight_8x8_10_sse2;
- c->biweight_h264_pixels_tab[4] = ff_h264_biweight_8x4_10_sse2;
- c->biweight_h264_pixels_tab[5] = ff_h264_biweight_4x8_10_sse2;
- c->biweight_h264_pixels_tab[6] = ff_h264_biweight_4x4_10_sse2;
- c->biweight_h264_pixels_tab[7] = ff_h264_biweight_4x2_10_sse2;
+ c->weight_h264_pixels_tab[0] = ff_h264_weight_16_10_sse2;
+ c->weight_h264_pixels_tab[1] = ff_h264_weight_8_10_sse2;
+ c->weight_h264_pixels_tab[2] = ff_h264_weight_4_10_sse2;
+
+ c->biweight_h264_pixels_tab[0] = ff_h264_biweight_16_10_sse2;
+ c->biweight_h264_pixels_tab[1] = ff_h264_biweight_8_10_sse2;
+ c->biweight_h264_pixels_tab[2] = ff_h264_biweight_4_10_sse2;
c->h264_v_loop_filter_chroma= ff_deblock_v_chroma_10_sse2;
c->h264_v_loop_filter_chroma_intra= ff_deblock_v_chroma_intra_10_sse2;
@@ -506,23 +474,13 @@ void ff_h264dsp_init_x86(H264DSPContext *c, const int bit_depth)
#endif
}
if (mm_flags&AV_CPU_FLAG_SSE4) {
- c->weight_h264_pixels_tab[0] = ff_h264_weight_16x16_10_sse4;
- c->weight_h264_pixels_tab[1] = ff_h264_weight_16x8_10_sse4;
- c->weight_h264_pixels_tab[2] = ff_h264_weight_8x16_10_sse4;
- c->weight_h264_pixels_tab[3] = ff_h264_weight_8x8_10_sse4;
- c->weight_h264_pixels_tab[4] = ff_h264_weight_8x4_10_sse4;
- c->weight_h264_pixels_tab[5] = ff_h264_weight_4x8_10_sse4;
- c->weight_h264_pixels_tab[6] = ff_h264_weight_4x4_10_sse4;
- c->weight_h264_pixels_tab[7] = ff_h264_weight_4x2_10_sse4;
-
- c->biweight_h264_pixels_tab[0] = ff_h264_biweight_16x16_10_sse4;
- c->biweight_h264_pixels_tab[1] = ff_h264_biweight_16x8_10_sse4;
- c->biweight_h264_pixels_tab[2] = ff_h264_biweight_8x16_10_sse4;
- c->biweight_h264_pixels_tab[3] = ff_h264_biweight_8x8_10_sse4;
- c->biweight_h264_pixels_tab[4] = ff_h264_biweight_8x4_10_sse4;
- c->biweight_h264_pixels_tab[5] = ff_h264_biweight_4x8_10_sse4;
- c->biweight_h264_pixels_tab[6] = ff_h264_biweight_4x4_10_sse4;
- c->biweight_h264_pixels_tab[7] = ff_h264_biweight_4x2_10_sse4;
+ c->weight_h264_pixels_tab[0] = ff_h264_weight_16_10_sse4;
+ c->weight_h264_pixels_tab[1] = ff_h264_weight_8_10_sse4;
+ c->weight_h264_pixels_tab[2] = ff_h264_weight_4_10_sse4;
+
+ c->biweight_h264_pixels_tab[0] = ff_h264_biweight_16_10_sse4;
+ c->biweight_h264_pixels_tab[1] = ff_h264_biweight_8_10_sse4;
+ c->biweight_h264_pixels_tab[2] = ff_h264_biweight_4_10_sse4;
}
#if HAVE_AVX
if (mm_flags&AV_CPU_FLAG_AVX) {
@@ -531,7 +489,8 @@ void ff_h264dsp_init_x86(H264DSPContext *c, const int bit_depth)
c->h264_idct8_dc_add = ff_h264_idct8_dc_add_10_avx;
c->h264_idct_add16 = ff_h264_idct_add16_10_avx;
- c->h264_idct_add8 = ff_h264_idct_add8_10_avx;
+ if (chroma_format_idc == 1)
+ c->h264_idct_add8 = ff_h264_idct_add8_10_avx;
c->h264_idct_add16intra= ff_h264_idct_add16intra_10_avx;
#if HAVE_ALIGNED_STACK
c->h264_idct8_add = ff_h264_idct8_add_10_avx;
diff --git a/libavcodec/x86/idct_mmx_xvid.c b/libavcodec/x86/idct_mmx_xvid.c
index 3055205c81..466cf75bc4 100644
--- a/libavcodec/x86/idct_mmx_xvid.c
+++ b/libavcodec/x86/idct_mmx_xvid.c
@@ -22,20 +22,20 @@
*
* conversion to gcc syntax by Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
- * along with Libav; if not, write to the Free Software Foundation,
+ * along with FFmpeg; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/x86/idct_sse2_xvid.c b/libavcodec/x86/idct_sse2_xvid.c
index 968b400c6d..fc75a57519 100644
--- a/libavcodec/x86/idct_sse2_xvid.c
+++ b/libavcodec/x86/idct_sse2_xvid.c
@@ -9,7 +9,7 @@
*
* Originally from dct/x86_asm/fdct_sse2_skal.asm in Xvid.
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
* Vertical pass is an implementation of the scheme:
* Loeffler C., Ligtenberg A., and Moschytz C.S.:
@@ -23,18 +23,18 @@
*
* More details at http://skal.planet-d.net/coding/dct.html
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
- * along with Libav; if not, write to the Free Software Foundation,
+ * along with FFmpeg; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/x86/idct_xvid.h b/libavcodec/x86/idct_xvid.h
index 495d2caaf9..be91d1c68a 100644
--- a/libavcodec/x86/idct_xvid.h
+++ b/libavcodec/x86/idct_xvid.h
@@ -1,20 +1,20 @@
/*
* XVID MPEG-4 VIDEO CODEC
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/x86/lpc_mmx.c b/libavcodec/x86/lpc_mmx.c
index d41c19b443..1c202e2ccc 100644
--- a/libavcodec/x86/lpc_mmx.c
+++ b/libavcodec/x86/lpc_mmx.c
@@ -2,20 +2,20 @@
* MMX optimized LPC DSP utils
* Copyright (c) 2007 Loren Merritt
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/x86/mathops.h b/libavcodec/x86/mathops.h
index 50b0283151..33d9a6c8ff 100644
--- a/libavcodec/x86/mathops.h
+++ b/libavcodec/x86/mathops.h
@@ -2,20 +2,20 @@
* simple math operations
* Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at> et al
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/x86/mlpdsp.c b/libavcodec/x86/mlpdsp.c
index 400855d7c4..7ea77fc1b8 100644
--- a/libavcodec/x86/mlpdsp.c
+++ b/libavcodec/x86/mlpdsp.c
@@ -2,20 +2,20 @@
* MLP DSP functions x86-optimized
* Copyright (c) 2009 Ramiro Polla
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/x86/motion_est_mmx.c b/libavcodec/x86/motion_est_mmx.c
index 948af98ffb..fefef41058 100644
--- a/libavcodec/x86/motion_est_mmx.c
+++ b/libavcodec/x86/motion_est_mmx.c
@@ -5,20 +5,20 @@
*
* mostly by Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/x86/mpegaudiodec_mmx.c b/libavcodec/x86/mpegaudiodec_mmx.c
index b64461513e..d7f8a0a142 100644
--- a/libavcodec/x86/mpegaudiodec_mmx.c
+++ b/libavcodec/x86/mpegaudiodec_mmx.c
@@ -2,20 +2,20 @@
* MMX optimized MP3 decoding functions
* Copyright (c) 2010 Vitor Sessak
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/x86/mpegvideo_mmx.c b/libavcodec/x86/mpegvideo_mmx.c
index 7dd9a66783..3b8513d3f0 100644
--- a/libavcodec/x86/mpegvideo_mmx.c
+++ b/libavcodec/x86/mpegvideo_mmx.c
@@ -5,20 +5,20 @@
* Optimized for ia32 CPUs by Nick Kurshev <nickols_k@mail.ru>
* h263, mpeg1, mpeg2 dequantizer & draw_edges by Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/x86/mpegvideo_mmx_template.c b/libavcodec/x86/mpegvideo_mmx_template.c
index 0f01cb24b9..6569ba41eb 100644
--- a/libavcodec/x86/mpegvideo_mmx_template.c
+++ b/libavcodec/x86/mpegvideo_mmx_template.c
@@ -3,20 +3,20 @@
*
* Copyright (c) 2002 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -98,7 +98,7 @@ static int RENAME(dct_quantize)(MpegEncContext *s,
x86_reg last_non_zero_p1;
int level=0, q; //=0 is because gcc says uninitialized ...
const uint16_t *qmat, *bias;
- DECLARE_ALIGNED(16, int16_t, temp_block)[64];
+ LOCAL_ALIGNED_16(int16_t, temp_block, [64]);
assert((7&(int)(&temp_block[0])) == 0); //did gcc align it correctly?
@@ -110,10 +110,15 @@ static int RENAME(dct_quantize)(MpegEncContext *s,
if (s->mb_intra) {
int dummy;
- if (n < 4)
+ if (n < 4){
q = s->y_dc_scale;
- else
+ bias = s->q_intra_matrix16[qscale][1];
+ qmat = s->q_intra_matrix16[qscale][0];
+ }else{
q = s->c_dc_scale;
+ bias = s->q_chroma_intra_matrix16[qscale][1];
+ qmat = s->q_chroma_intra_matrix16[qscale][0];
+ }
/* note: block[0] is assumed to be positive */
if (!s->h263_aic) {
__asm__ volatile (
@@ -128,8 +133,6 @@ static int RENAME(dct_quantize)(MpegEncContext *s,
block[0]=0; //avoid fake overflow
// temp_block[0] = (block[0] + (q >> 1)) / q;
last_non_zero_p1 = 1;
- bias = s->q_intra_matrix16[qscale][1];
- qmat = s->q_intra_matrix16[qscale][0];
} else {
last_non_zero_p1 = 0;
bias = s->q_inter_matrix16[qscale][1];
diff --git a/libavcodec/x86/png_mmx.c b/libavcodec/x86/png_mmx.c
new file mode 100644
index 0000000000..3b284122ff
--- /dev/null
+++ b/libavcodec/x86/png_mmx.c
@@ -0,0 +1,143 @@
+/*
+ * MMX optimized PNG utils
+ * Copyright (c) 2008 Loren Merritt
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#include "libavutil/cpu.h"
+#include "libavutil/x86_cpu.h"
+#include "libavcodec/dsputil.h"
+#include "libavcodec/png.h"
+#include "dsputil_mmx.h"
+
+//#undef NDEBUG
+//#include <assert.h>
+
+static void add_bytes_l2_mmx(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w)
+{
+ x86_reg i=0;
+ __asm__ volatile(
+ "jmp 2f \n\t"
+ "1: \n\t"
+ "movq (%2, %0), %%mm0 \n\t"
+ "movq 8(%2, %0), %%mm1 \n\t"
+ "paddb (%3, %0), %%mm0 \n\t"
+ "paddb 8(%3, %0), %%mm1 \n\t"
+ "movq %%mm0, (%1, %0) \n\t"
+ "movq %%mm1, 8(%1, %0) \n\t"
+ "add $16, %0 \n\t"
+ "2: \n\t"
+ "cmp %4, %0 \n\t"
+ " js 1b \n\t"
+ : "+r" (i)
+ : "r"(dst), "r"(src1), "r"(src2), "r"((x86_reg)w-15)
+ );
+ for(; i<w; i++)
+ dst[i] = src1[i] + src2[i];
+}
+
+#define PAETH(cpu, abs3)\
+static void add_paeth_prediction_##cpu(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp)\
+{\
+ x86_reg i, end;\
+ if(bpp>4) add_paeth_prediction_##cpu(dst+bpp/2, src+bpp/2, top+bpp/2, w-bpp/2, -bpp);\
+ if(bpp<0) bpp=-bpp;\
+ i= -bpp;\
+ end = w-3;\
+ __asm__ volatile(\
+ "pxor %%mm7, %%mm7 \n"\
+ "movd (%1,%0), %%mm0 \n"\
+ "movd (%2,%0), %%mm1 \n"\
+ "punpcklbw %%mm7, %%mm0 \n"\
+ "punpcklbw %%mm7, %%mm1 \n"\
+ "add %4, %0 \n"\
+ "1: \n"\
+ "movq %%mm1, %%mm2 \n"\
+ "movd (%2,%0), %%mm1 \n"\
+ "movq %%mm2, %%mm3 \n"\
+ "punpcklbw %%mm7, %%mm1 \n"\
+ "movq %%mm2, %%mm4 \n"\
+ "psubw %%mm1, %%mm3 \n"\
+ "psubw %%mm0, %%mm4 \n"\
+ "movq %%mm3, %%mm5 \n"\
+ "paddw %%mm4, %%mm5 \n"\
+ abs3\
+ "movq %%mm4, %%mm6 \n"\
+ "pminsw %%mm5, %%mm6 \n"\
+ "pcmpgtw %%mm6, %%mm3 \n"\
+ "pcmpgtw %%mm5, %%mm4 \n"\
+ "movq %%mm4, %%mm6 \n"\
+ "pand %%mm3, %%mm4 \n"\
+ "pandn %%mm3, %%mm6 \n"\
+ "pandn %%mm0, %%mm3 \n"\
+ "movd (%3,%0), %%mm0 \n"\
+ "pand %%mm1, %%mm6 \n"\
+ "pand %%mm4, %%mm2 \n"\
+ "punpcklbw %%mm7, %%mm0 \n"\
+ "paddw %%mm6, %%mm0 \n"\
+ "paddw %%mm2, %%mm3 \n"\
+ "paddw %%mm3, %%mm0 \n"\
+ "pand %6 , %%mm0 \n"\
+ "movq %%mm0, %%mm3 \n"\
+ "packuswb %%mm3, %%mm3 \n"\
+ "movd %%mm3, (%1,%0) \n"\
+ "add %4, %0 \n"\
+ "cmp %5, %0 \n"\
+ "jle 1b \n"\
+ :"+r"(i)\
+ :"r"(dst), "r"(top), "r"(src), "r"((x86_reg)bpp), "g"(end),\
+ "m"(ff_pw_255)\
+ :"memory"\
+ );\
+}
+
+#define ABS3_MMX2\
+ "psubw %%mm5, %%mm7 \n"\
+ "pmaxsw %%mm7, %%mm5 \n"\
+ "pxor %%mm6, %%mm6 \n"\
+ "pxor %%mm7, %%mm7 \n"\
+ "psubw %%mm3, %%mm6 \n"\
+ "psubw %%mm4, %%mm7 \n"\
+ "pmaxsw %%mm6, %%mm3 \n"\
+ "pmaxsw %%mm7, %%mm4 \n"\
+ "pxor %%mm7, %%mm7 \n"
+
+#define ABS3_SSSE3\
+ "pabsw %%mm3, %%mm3 \n"\
+ "pabsw %%mm4, %%mm4 \n"\
+ "pabsw %%mm5, %%mm5 \n"
+
+PAETH(mmx2, ABS3_MMX2)
+#if HAVE_SSSE3
+PAETH(ssse3, ABS3_SSSE3)
+#endif
+
+void ff_png_init_mmx(PNGDecContext *s)
+{
+ int mm_flags = av_get_cpu_flags();
+
+ if (mm_flags & AV_CPU_FLAG_MMX2) {
+ s->add_bytes_l2 = add_bytes_l2_mmx;
+ s->add_paeth_prediction = add_paeth_prediction_mmx2;
+#if HAVE_SSSE3
+ if (mm_flags & AV_CPU_FLAG_SSSE3)
+ s->add_paeth_prediction = add_paeth_prediction_ssse3;
+#endif
+ }
+}
diff --git a/libavcodec/x86/proresdsp-init.c b/libavcodec/x86/proresdsp-init.c
new file mode 100644
index 0000000000..c4aeb7f503
--- /dev/null
+++ b/libavcodec/x86/proresdsp-init.c
@@ -0,0 +1,57 @@
+/*
+ * Apple ProRes compatible decoder
+ *
+ * Copyright (c) 2010-2011 Maxim Poliakovski
+ *
+ * This file is part of Libav.
+ *
+ * Libav 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.
+ *
+ * Libav 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavcodec/proresdsp.h"
+
+void ff_prores_idct_put_10_sse2(uint16_t *dst, int linesize,
+ DCTELEM *block, const int16_t *qmat);
+void ff_prores_idct_put_10_sse4(uint16_t *dst, int linesize,
+ DCTELEM *block, const int16_t *qmat);
+void ff_prores_idct_put_10_avx (uint16_t *dst, int linesize,
+ DCTELEM *block, const int16_t *qmat);
+
+void ff_proresdsp_x86_init(ProresDSPContext *dsp, AVCodecContext *avctx)
+{
+#if ARCH_X86_64 && HAVE_YASM
+ int flags = av_get_cpu_flags();
+
+ if(avctx->flags & CODEC_FLAG_BITEXACT)
+ return;
+
+ if (flags & AV_CPU_FLAG_SSE2) {
+ dsp->idct_permutation_type = FF_TRANSPOSE_IDCT_PERM;
+ dsp->idct_put = ff_prores_idct_put_10_sse2;
+ }
+
+ if (flags & AV_CPU_FLAG_SSE4) {
+ dsp->idct_permutation_type = FF_TRANSPOSE_IDCT_PERM;
+ dsp->idct_put = ff_prores_idct_put_10_sse4;
+ }
+
+#if HAVE_AVX
+ if (flags & AV_CPU_FLAG_AVX) {
+ dsp->idct_permutation_type = FF_TRANSPOSE_IDCT_PERM;
+ dsp->idct_put = ff_prores_idct_put_10_avx;
+ }
+#endif /* HAVE_AVX */
+#endif /* ARCH_X86_64 && HAVE_YASM */
+}
diff --git a/libavcodec/x86/proresdsp.asm b/libavcodec/x86/proresdsp.asm
new file mode 100644
index 0000000000..d674308c05
--- /dev/null
+++ b/libavcodec/x86/proresdsp.asm
@@ -0,0 +1,312 @@
+;******************************************************************************
+;* x86-SIMD-optimized IDCT for prores
+;* this is identical to "simple" IDCT written by Michael Niedermayer
+;* except for the clip range
+;*
+;* Copyright (c) 2011 Ronald S. Bultje <rsbultje@gmail.com>
+;*
+;* This file is part of FFmpeg.
+;*
+;* FFmpeg 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.
+;*
+;* FFmpeg 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
+;* Lesser General Public License for more details.
+;*
+;* You should have received a copy of the GNU Lesser General Public
+;* License along with FFmpeg; if not, write to the Free Software
+;* 51, Inc., Foundation Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+;******************************************************************************
+
+%include "x86inc.asm"
+%include "x86util.asm"
+
+%define W1sh2 22725 ; W1 = 90901 = 22725<<2 + 1
+%define W2sh2 21407 ; W2 = 85627 = 21407<<2 - 1
+%define W3sh2 19265 ; W3 = 77062 = 19265<<2 + 2
+%define W4sh2 16384 ; W4 = 65535 = 16384<<2 - 1
+%define W5sh2 12873 ; W5 = 51491 = 12873<<2 - 1
+%define W6sh2 8867 ; W6 = 35468 = 8867<<2
+%define W7sh2 4520 ; W7 = 18081 = 4520<<2 + 1
+
+%ifdef ARCH_X86_64
+
+SECTION_RODATA
+
+w4_plus_w2: times 4 dw W4sh2, +W2sh2
+w4_min_w2: times 4 dw W4sh2, -W2sh2
+w4_plus_w6: times 4 dw W4sh2, +W6sh2
+w4_min_w6: times 4 dw W4sh2, -W6sh2
+w1_plus_w3: times 4 dw W1sh2, +W3sh2
+w3_min_w1: times 4 dw W3sh2, -W1sh2
+w7_plus_w3: times 4 dw W7sh2, +W3sh2
+w3_min_w7: times 4 dw W3sh2, -W7sh2
+w1_plus_w5: times 4 dw W1sh2, +W5sh2
+w5_min_w1: times 4 dw W5sh2, -W1sh2
+w5_plus_w7: times 4 dw W5sh2, +W7sh2
+w7_min_w5: times 4 dw W7sh2, -W5sh2
+pw_88: times 8 dw 0x2008
+
+cextern pw_1
+cextern pw_4
+cextern pw_512
+cextern pw_1019
+
+section .text align=16
+
+; interleave data while maintaining source
+; %1=type, %2=dstlo, %3=dsthi, %4=src, %5=interleave
+%macro SBUTTERFLY3 5
+ punpckl%1 m%2, m%4, m%5
+ punpckh%1 m%3, m%4, m%5
+%endmacro
+
+; %1/%2=src1/dst1, %3/%4=dst2, %5/%6=src2, %7=shift
+; action: %3/%4 = %1/%2 - %5/%6; %1/%2 += %5/%6
+; %1/%2/%3/%4 >>= %7; dword -> word (in %1/%3)
+%macro SUMSUB_SHPK 7
+ psubd %3, %1, %5 ; { a0 - b0 }[0-3]
+ psubd %4, %2, %6 ; { a0 - b0 }[4-7]
+ paddd %1, %5 ; { a0 + b0 }[0-3]
+ paddd %2, %6 ; { a0 + b0 }[4-7]
+ psrad %1, %7
+ psrad %2, %7
+ psrad %3, %7
+ psrad %4, %7
+ packssdw %1, %2 ; row[0]
+ packssdw %3, %4 ; row[7]
+%endmacro
+
+; %1 = row or col (for rounding variable)
+; %2 = number of bits to shift at the end
+; %3 = optimization
+%macro IDCT_1D 3
+ ; a0 = (W4 * row[0]) + (1 << (15 - 1));
+ ; a1 = a0;
+ ; a2 = a0;
+ ; a3 = a0;
+ ; a0 += W2 * row[2];
+ ; a1 += W6 * row[2];
+ ; a2 -= W6 * row[2];
+ ; a3 -= W2 * row[2];
+%ifidn %1, col
+ paddw m10,[pw_88]
+%endif
+%ifidn %1, row
+ paddw m10,[pw_1]
+%endif
+ SBUTTERFLY3 wd, 0, 1, 10, 8 ; { row[0], row[2] }[0-3]/[4-7]
+ pmaddwd m2, m0, [w4_plus_w6]
+ pmaddwd m3, m1, [w4_plus_w6]
+ pmaddwd m4, m0, [w4_min_w6]
+ pmaddwd m5, m1, [w4_min_w6]
+ pmaddwd m6, m0, [w4_min_w2]
+ pmaddwd m7, m1, [w4_min_w2]
+ pmaddwd m0, [w4_plus_w2]
+ pmaddwd m1, [w4_plus_w2]
+
+ ; a0: -1*row[0]-1*row[2]
+ ; a1: -1*row[0]
+ ; a2: -1*row[0]
+ ; a3: -1*row[0]+1*row[2]
+
+ ; a0 += W4*row[4] + W6*row[6]; i.e. -1*row[4]
+ ; a1 -= W4*row[4] + W2*row[6]; i.e. -1*row[4]-1*row[6]
+ ; a2 -= W4*row[4] - W2*row[6]; i.e. -1*row[4]+1*row[6]
+ ; a3 += W4*row[4] - W6*row[6]; i.e. -1*row[4]
+ SBUTTERFLY3 wd, 8, 9, 13, 12 ; { row[4], row[6] }[0-3]/[4-7]
+ pmaddwd m10, m8, [w4_plus_w6]
+ pmaddwd m11, m9, [w4_plus_w6]
+ paddd m0, m10 ; a0[0-3]
+ paddd m1, m11 ; a0[4-7]
+ pmaddwd m10, m8, [w4_min_w6]
+ pmaddwd m11, m9, [w4_min_w6]
+ paddd m6, m10 ; a3[0-3]
+ paddd m7, m11 ; a3[4-7]
+ pmaddwd m10, m8, [w4_min_w2]
+ pmaddwd m11, m9, [w4_min_w2]
+ pmaddwd m8, [w4_plus_w2]
+ pmaddwd m9, [w4_plus_w2]
+ psubd m4, m10 ; a2[0-3] intermediate
+ psubd m5, m11 ; a2[4-7] intermediate
+ psubd m2, m8 ; a1[0-3] intermediate
+ psubd m3, m9 ; a1[4-7] intermediate
+
+ ; load/store
+ mova [r2+ 0], m0
+ mova [r2+ 32], m2
+ mova [r2+ 64], m4
+ mova [r2+ 96], m6
+ mova m10,[r2+ 16] ; { row[1] }[0-7]
+ mova m8, [r2+ 48] ; { row[3] }[0-7]
+ mova m13,[r2+ 80] ; { row[5] }[0-7]
+ mova m14,[r2+112] ; { row[7] }[0-7]
+ mova [r2+ 16], m1
+ mova [r2+ 48], m3
+ mova [r2+ 80], m5
+ mova [r2+112], m7
+%ifidn %1, row
+ pmullw m10,[r3+ 16]
+ pmullw m8, [r3+ 48]
+ pmullw m13,[r3+ 80]
+ pmullw m14,[r3+112]
+%endif
+
+ ; b0 = MUL(W1, row[1]);
+ ; MAC(b0, W3, row[3]);
+ ; b1 = MUL(W3, row[1]);
+ ; MAC(b1, -W7, row[3]);
+ ; b2 = MUL(W5, row[1]);
+ ; MAC(b2, -W1, row[3]);
+ ; b3 = MUL(W7, row[1]);
+ ; MAC(b3, -W5, row[3]);
+ SBUTTERFLY3 wd, 0, 1, 10, 8 ; { row[1], row[3] }[0-3]/[4-7]
+ pmaddwd m2, m0, [w3_min_w7]
+ pmaddwd m3, m1, [w3_min_w7]
+ pmaddwd m4, m0, [w5_min_w1]
+ pmaddwd m5, m1, [w5_min_w1]
+ pmaddwd m6, m0, [w7_min_w5]
+ pmaddwd m7, m1, [w7_min_w5]
+ pmaddwd m0, [w1_plus_w3]
+ pmaddwd m1, [w1_plus_w3]
+
+ ; b0: +1*row[1]+2*row[3]
+ ; b1: +2*row[1]-1*row[3]
+ ; b2: -1*row[1]-1*row[3]
+ ; b3: +1*row[1]+1*row[3]
+
+ ; MAC(b0, W5, row[5]);
+ ; MAC(b0, W7, row[7]);
+ ; MAC(b1, -W1, row[5]);
+ ; MAC(b1, -W5, row[7]);
+ ; MAC(b2, W7, row[5]);
+ ; MAC(b2, W3, row[7]);
+ ; MAC(b3, W3, row[5]);
+ ; MAC(b3, -W1, row[7]);
+ SBUTTERFLY3 wd, 8, 9, 13, 14 ; { row[5], row[7] }[0-3]/[4-7]
+
+ ; b0: -1*row[5]+1*row[7]
+ ; b1: -1*row[5]+1*row[7]
+ ; b2: +1*row[5]+2*row[7]
+ ; b3: +2*row[5]-1*row[7]
+
+ pmaddwd m10, m8, [w1_plus_w5]
+ pmaddwd m11, m9, [w1_plus_w5]
+ pmaddwd m12, m8, [w5_plus_w7]
+ pmaddwd m13, m9, [w5_plus_w7]
+ psubd m2, m10 ; b1[0-3]
+ psubd m3, m11 ; b1[4-7]
+ paddd m0, m12 ; b0[0-3]
+ paddd m1, m13 ; b0[4-7]
+ pmaddwd m12, m8, [w7_plus_w3]
+ pmaddwd m13, m9, [w7_plus_w3]
+ pmaddwd m8, [w3_min_w1]
+ pmaddwd m9, [w3_min_w1]
+ paddd m4, m12 ; b2[0-3]
+ paddd m5, m13 ; b2[4-7]
+ paddd m6, m8 ; b3[0-3]
+ paddd m7, m9 ; b3[4-7]
+
+ ; row[0] = (a0 + b0) >> 15;
+ ; row[7] = (a0 - b0) >> 15;
+ ; row[1] = (a1 + b1) >> 15;
+ ; row[6] = (a1 - b1) >> 15;
+ ; row[2] = (a2 + b2) >> 15;
+ ; row[5] = (a2 - b2) >> 15;
+ ; row[3] = (a3 + b3) >> 15;
+ ; row[4] = (a3 - b3) >> 15;
+ mova m8, [r2+ 0] ; a0[0-3]
+ mova m9, [r2+16] ; a0[4-7]
+ SUMSUB_SHPK m8, m9, m10, m11, m0, m1, %2
+ mova m0, [r2+32] ; a1[0-3]
+ mova m1, [r2+48] ; a1[4-7]
+ SUMSUB_SHPK m0, m1, m9, m11, m2, m3, %2
+ mova m1, [r2+64] ; a2[0-3]
+ mova m2, [r2+80] ; a2[4-7]
+ SUMSUB_SHPK m1, m2, m11, m3, m4, m5, %2
+ mova m2, [r2+96] ; a3[0-3]
+ mova m3, [r2+112] ; a3[4-7]
+ SUMSUB_SHPK m2, m3, m4, m5, m6, m7, %2
+%endmacro
+
+; void prores_idct_put_10_<opt>(uint8_t *pixels, int stride,
+; DCTELEM *block, const int16_t *qmat);
+%macro idct_put_fn 2
+cglobal prores_idct_put_10_%1, 4, 4, %2
+ movsxd r1, r1d
+ pxor m15, m15 ; zero
+
+ ; for (i = 0; i < 8; i++)
+ ; idctRowCondDC(block + i*8);
+ mova m10,[r2+ 0] ; { row[0] }[0-7]
+ mova m8, [r2+32] ; { row[2] }[0-7]
+ mova m13,[r2+64] ; { row[4] }[0-7]
+ mova m12,[r2+96] ; { row[6] }[0-7]
+
+ pmullw m10,[r3+ 0]
+ pmullw m8, [r3+32]
+ pmullw m13,[r3+64]
+ pmullw m12,[r3+96]
+
+ IDCT_1D row, 15, %1
+
+ ; transpose for second part of IDCT
+ TRANSPOSE8x8W 8, 0, 1, 2, 4, 11, 9, 10, 3
+ mova [r2+ 16], m0
+ mova [r2+ 48], m2
+ mova [r2+ 80], m11
+ mova [r2+112], m10
+ SWAP 8, 10
+ SWAP 1, 8
+ SWAP 4, 13
+ SWAP 9, 12
+
+ ; for (i = 0; i < 8; i++)
+ ; idctSparseColAdd(dest + i, line_size, block + i);
+ IDCT_1D col, 18, %1
+
+ ; clip/store
+ mova m3, [pw_4]
+ mova m5, [pw_1019]
+ pmaxsw m8, m3
+ pmaxsw m0, m3
+ pmaxsw m1, m3
+ pmaxsw m2, m3
+ pmaxsw m4, m3
+ pmaxsw m11, m3
+ pmaxsw m9, m3
+ pmaxsw m10, m3
+ pminsw m8, m5
+ pminsw m0, m5
+ pminsw m1, m5
+ pminsw m2, m5
+ pminsw m4, m5
+ pminsw m11, m5
+ pminsw m9, m5
+ pminsw m10, m5
+
+ lea r2, [r1*3]
+ mova [r0 ], m8
+ mova [r0+r1 ], m0
+ mova [r0+r1*2], m1
+ mova [r0+r2 ], m2
+ lea r0, [r0+r1*4]
+ mova [r0 ], m4
+ mova [r0+r1 ], m11
+ mova [r0+r1*2], m9
+ mova [r0+r2 ], m10
+ RET
+%endmacro
+
+INIT_XMM
+idct_put_fn sse2, 16
+INIT_XMM
+idct_put_fn sse4, 16
+INIT_AVX
+idct_put_fn avx, 16
+
+%endif
diff --git a/libavcodec/x86/rv40dsp.c b/libavcodec/x86/rv40dsp.c
new file mode 100644
index 0000000000..9f90ad8bb6
--- /dev/null
+++ b/libavcodec/x86/rv40dsp.c
@@ -0,0 +1,60 @@
+/*
+ * RV40 decoder motion compensation functions x86-optimised
+ * Copyright (c) 2008 Konstantin Shishkov
+ *
+ * This file is part of Libav.
+ *
+ * Libav 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.
+ *
+ * Libav 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * RV40 decoder motion compensation functions x86-optimised
+ */
+
+#include "libavcodec/rv34dsp.h"
+
+void ff_put_rv40_chroma_mc8_mmx (uint8_t *dst, uint8_t *src,
+ int stride, int h, int x, int y);
+void ff_avg_rv40_chroma_mc8_mmx2 (uint8_t *dst, uint8_t *src,
+ int stride, int h, int x, int y);
+void ff_avg_rv40_chroma_mc8_3dnow(uint8_t *dst, uint8_t *src,
+ int stride, int h, int x, int y);
+
+void ff_put_rv40_chroma_mc4_mmx (uint8_t *dst, uint8_t *src,
+ int stride, int h, int x, int y);
+void ff_avg_rv40_chroma_mc4_mmx2 (uint8_t *dst, uint8_t *src,
+ int stride, int h, int x, int y);
+void ff_avg_rv40_chroma_mc4_3dnow(uint8_t *dst, uint8_t *src,
+ int stride, int h, int x, int y);
+
+void ff_rv40dsp_init_x86(RV34DSPContext *c, DSPContext *dsp)
+{
+ av_unused int mm_flags = av_get_cpu_flags();
+
+#if HAVE_YASM
+ if (mm_flags & AV_CPU_FLAG_MMX) {
+ c->put_chroma_pixels_tab[0] = ff_put_rv40_chroma_mc8_mmx;
+ c->put_chroma_pixels_tab[1] = ff_put_rv40_chroma_mc4_mmx;
+ }
+ if (mm_flags & AV_CPU_FLAG_MMX2) {
+ c->avg_chroma_pixels_tab[0] = ff_avg_rv40_chroma_mc8_mmx2;
+ c->avg_chroma_pixels_tab[1] = ff_avg_rv40_chroma_mc4_mmx2;
+ } else if (mm_flags & AV_CPU_FLAG_3DNOW) {
+ c->avg_chroma_pixels_tab[0] = ff_avg_rv40_chroma_mc8_3dnow;
+ c->avg_chroma_pixels_tab[1] = ff_avg_rv40_chroma_mc4_3dnow;
+ }
+#endif
+}
diff --git a/libavcodec/x86/simple_idct_mmx.c b/libavcodec/x86/simple_idct_mmx.c
index d78ae6b508..db479ce257 100644
--- a/libavcodec/x86/simple_idct_mmx.c
+++ b/libavcodec/x86/simple_idct_mmx.c
@@ -3,20 +3,20 @@
*
* Copyright (c) 2001, 2002 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavcodec/dsputil.h"
@@ -37,11 +37,7 @@
#define C1 22725 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
#define C2 21407 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
#define C3 19266 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
-#if 0
-#define C4 16384 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
-#else
#define C4 16383 //cos(i*M_PI/16)*sqrt(2)*(1<<14) - 0.5
-#endif
#define C5 12873 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
#define C6 8867 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
#define C7 4520 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
@@ -80,135 +76,6 @@ DECLARE_ALIGNED(8, static const int16_t, coeffs)[]= {
C3, -C1, C3, -C1
};
-#if 0
-static void unused_var_killer(void)
-{
- int a= wm1010 + d40000;
- temp[0]=a;
-}
-
-static void inline idctCol (int16_t * col, int16_t *input)
-{
-#undef C0
-#undef C1
-#undef C2
-#undef C3
-#undef C4
-#undef C5
-#undef C6
-#undef C7
- int a0, a1, a2, a3, b0, b1, b2, b3;
- const int C0 = 23170; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
- const int C1 = 22725; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
- const int C2 = 21407; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
- const int C3 = 19266; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
- const int C4 = 16383; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
- const int C5 = 12873; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
- const int C6 = 8867; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
- const int C7 = 4520; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
-/*
- if( !(col[8*1] | col[8*2] |col[8*3] |col[8*4] |col[8*5] |col[8*6] | col[8*7])) {
- col[8*0] = col[8*1] = col[8*2] = col[8*3] = col[8*4] =
- col[8*5] = col[8*6] = col[8*7] = col[8*0]<<3;
- return;
- }*/
-
-col[8*0] = input[8*0 + 0];
-col[8*1] = input[8*2 + 0];
-col[8*2] = input[8*0 + 1];
-col[8*3] = input[8*2 + 1];
-col[8*4] = input[8*4 + 0];
-col[8*5] = input[8*6 + 0];
-col[8*6] = input[8*4 + 1];
-col[8*7] = input[8*6 + 1];
-
- a0 = C4*col[8*0] + C2*col[8*2] + C4*col[8*4] + C6*col[8*6] + (1<<(COL_SHIFT-1));
- a1 = C4*col[8*0] + C6*col[8*2] - C4*col[8*4] - C2*col[8*6] + (1<<(COL_SHIFT-1));
- a2 = C4*col[8*0] - C6*col[8*2] - C4*col[8*4] + C2*col[8*6] + (1<<(COL_SHIFT-1));
- a3 = C4*col[8*0] - C2*col[8*2] + C4*col[8*4] - C6*col[8*6] + (1<<(COL_SHIFT-1));
-
- b0 = C1*col[8*1] + C3*col[8*3] + C5*col[8*5] + C7*col[8*7];
- b1 = C3*col[8*1] - C7*col[8*3] - C1*col[8*5] - C5*col[8*7];
- b2 = C5*col[8*1] - C1*col[8*3] + C7*col[8*5] + C3*col[8*7];
- b3 = C7*col[8*1] - C5*col[8*3] + C3*col[8*5] - C1*col[8*7];
-
- col[8*0] = (a0 + b0) >> COL_SHIFT;
- col[8*1] = (a1 + b1) >> COL_SHIFT;
- col[8*2] = (a2 + b2) >> COL_SHIFT;
- col[8*3] = (a3 + b3) >> COL_SHIFT;
- col[8*4] = (a3 - b3) >> COL_SHIFT;
- col[8*5] = (a2 - b2) >> COL_SHIFT;
- col[8*6] = (a1 - b1) >> COL_SHIFT;
- col[8*7] = (a0 - b0) >> COL_SHIFT;
-}
-
-static void inline idctRow (int16_t * output, int16_t * input)
-{
- int16_t row[8];
-
- int a0, a1, a2, a3, b0, b1, b2, b3;
- const int C0 = 23170; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
- const int C1 = 22725; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
- const int C2 = 21407; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
- const int C3 = 19266; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
- const int C4 = 16383; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
- const int C5 = 12873; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
- const int C6 = 8867; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
- const int C7 = 4520; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
-
-row[0] = input[0];
-row[2] = input[1];
-row[4] = input[4];
-row[6] = input[5];
-row[1] = input[8];
-row[3] = input[9];
-row[5] = input[12];
-row[7] = input[13];
-
- if( !(row[1] | row[2] |row[3] |row[4] |row[5] |row[6] | row[7]) ) {
- row[0] = row[1] = row[2] = row[3] = row[4] =
- row[5] = row[6] = row[7] = row[0]<<3;
- output[0] = row[0];
- output[2] = row[1];
- output[4] = row[2];
- output[6] = row[3];
- output[8] = row[4];
- output[10] = row[5];
- output[12] = row[6];
- output[14] = row[7];
- return;
- }
-
- a0 = C4*row[0] + C2*row[2] + C4*row[4] + C6*row[6] + (1<<(ROW_SHIFT-1));
- a1 = C4*row[0] + C6*row[2] - C4*row[4] - C2*row[6] + (1<<(ROW_SHIFT-1));
- a2 = C4*row[0] - C6*row[2] - C4*row[4] + C2*row[6] + (1<<(ROW_SHIFT-1));
- a3 = C4*row[0] - C2*row[2] + C4*row[4] - C6*row[6] + (1<<(ROW_SHIFT-1));
-
- b0 = C1*row[1] + C3*row[3] + C5*row[5] + C7*row[7];
- b1 = C3*row[1] - C7*row[3] - C1*row[5] - C5*row[7];
- b2 = C5*row[1] - C1*row[3] + C7*row[5] + C3*row[7];
- b3 = C7*row[1] - C5*row[3] + C3*row[5] - C1*row[7];
-
- row[0] = (a0 + b0) >> ROW_SHIFT;
- row[1] = (a1 + b1) >> ROW_SHIFT;
- row[2] = (a2 + b2) >> ROW_SHIFT;
- row[3] = (a3 + b3) >> ROW_SHIFT;
- row[4] = (a3 - b3) >> ROW_SHIFT;
- row[5] = (a2 - b2) >> ROW_SHIFT;
- row[6] = (a1 - b1) >> ROW_SHIFT;
- row[7] = (a0 - b0) >> ROW_SHIFT;
-
- output[0] = row[0];
- output[2] = row[1];
- output[4] = row[2];
- output[6] = row[3];
- output[8] = row[4];
- output[10] = row[5];
- output[12] = row[6];
- output[14] = row[7];
-}
-#endif
-
static inline void idct(int16_t *block)
{
DECLARE_ALIGNED(8, int64_t, align_tmp)[16];
diff --git a/libavcodec/x86/snowdsp_mmx.c b/libavcodec/x86/snowdsp_mmx.c
index 3e6bc99796..f107d55e87 100644
--- a/libavcodec/x86/snowdsp_mmx.c
+++ b/libavcodec/x86/snowdsp_mmx.c
@@ -2,20 +2,20 @@
* MMX and SSE2 optimized snow DSP utils
* Copyright (c) 2005-2006 Robert Edele <yartrebo@earthlink.net>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -675,14 +675,14 @@ static void ff_snow_vertical_compose97i_mmx(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM
#define snow_inner_add_yblock_sse2_end_8\
"sal $1, %%"REG_c" \n\t"\
- "add $"PTR_SIZE"*2, %1 \n\t"\
+ "add"OPSIZE" $"PTR_SIZE"*2, %1 \n\t"\
snow_inner_add_yblock_sse2_end_common1\
"sar $1, %%"REG_c" \n\t"\
"sub $2, %2 \n\t"\
snow_inner_add_yblock_sse2_end_common2
#define snow_inner_add_yblock_sse2_end_16\
- "add $"PTR_SIZE"*1, %1 \n\t"\
+ "add"OPSIZE" $"PTR_SIZE"*1, %1 \n\t"\
snow_inner_add_yblock_sse2_end_common1\
"dec %2 \n\t"\
snow_inner_add_yblock_sse2_end_common2
diff --git a/libavcodec/x86/v210-init.c b/libavcodec/x86/v210-init.c
new file mode 100644
index 0000000000..4dd6d6de8a
--- /dev/null
+++ b/libavcodec/x86/v210-init.c
@@ -0,0 +1,48 @@
+/*
+ * This file is part of Libav.
+ *
+ * Libav 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.
+ *
+ * Libav 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/cpu.h"
+#include "libavcodec/v210dec.h"
+
+extern void ff_v210_planar_unpack_unaligned_ssse3(const uint32_t *src, uint16_t *y, uint16_t *u, uint16_t *v, int width);
+extern void ff_v210_planar_unpack_unaligned_avx(const uint32_t *src, uint16_t *y, uint16_t *u, uint16_t *v, int width);
+
+extern void ff_v210_planar_unpack_aligned_ssse3(const uint32_t *src, uint16_t *y, uint16_t *u, uint16_t *v, int width);
+extern void ff_v210_planar_unpack_aligned_avx(const uint32_t *src, uint16_t *y, uint16_t *u, uint16_t *v, int width);
+
+av_cold void v210_x86_init(V210DecContext *s)
+{
+ int cpu_flags = av_get_cpu_flags();
+
+#if HAVE_YASM
+ if (s->aligned_input) {
+ if (cpu_flags & AV_CPU_FLAG_SSSE3)
+ s->unpack_frame = ff_v210_planar_unpack_aligned_ssse3;
+
+ if (cpu_flags & AV_CPU_FLAG_AVX)
+ s->unpack_frame = ff_v210_planar_unpack_aligned_avx;
+ }
+ else {
+ if (cpu_flags & AV_CPU_FLAG_SSSE3)
+ s->unpack_frame = ff_v210_planar_unpack_unaligned_ssse3;
+
+ if (cpu_flags & AV_CPU_FLAG_AVX)
+ s->unpack_frame = ff_v210_planar_unpack_unaligned_avx;
+ }
+#endif
+}
diff --git a/libavcodec/x86/v210.asm b/libavcodec/x86/v210.asm
new file mode 100644
index 0000000000..344bed0beb
--- /dev/null
+++ b/libavcodec/x86/v210.asm
@@ -0,0 +1,85 @@
+;******************************************************************************
+;* V210 SIMD unpack
+;* Copyright (c) 2011 Loren Merritt <lorenm@u.washington.edu>
+;* Copyright (c) 2011 Kieran Kunhya <kieran@kunhya.com>
+;*
+;* This file is part of Libav.
+;*
+;* Libav 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.
+;*
+;* Libav 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
+;* Lesser General Public License for more details.
+;*
+;* You should have received a copy of the GNU Lesser General Public
+;* License along with Libav; if not, write to the Free Software
+;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+;******************************************************************************
+
+%include "libavutil/x86/x86inc.asm"
+%include "libavutil/x86/x86util.asm"
+
+SECTION_RODATA
+
+v210_mask: times 4 dd 0x3ff
+v210_mult: dw 64,4,64,4,64,4,64,4
+v210_luma_shuf: db 8,9,0,1,2,3,12,13,4,5,6,7,-1,-1,-1,-1
+v210_chroma_shuf: db 0,1,8,9,6,7,-1,-1,2,3,4,5,12,13,-1,-1
+
+SECTION .text
+
+%macro v210_planar_unpack 2
+
+; v210_planar_unpack(const uint32_t *src, uint16_t *y, uint16_t *u, uint16_t *v, int width)
+cglobal v210_planar_unpack_%1_%2, 5, 5
+ movsxdifnidn r4, r4d
+ lea r1, [r1+2*r4]
+ add r2, r4
+ add r3, r4
+ neg r4
+
+ mova m3, [v210_mult]
+ mova m4, [v210_mask]
+ mova m5, [v210_luma_shuf]
+ mova m6, [v210_chroma_shuf]
+.loop
+%ifidn %1, unaligned
+ movu m0, [r0]
+%else
+ mova m0, [r0]
+%endif
+
+ pmullw m1, m0, m3
+ psrld m0, 10
+ psrlw m1, 6 ; u0 v0 y1 y2 v1 u2 y4 y5
+ pand m0, m4 ; y0 __ u1 __ y3 __ v2 __
+
+ shufps m2, m1, m0, 0x8d ; y1 y2 y4 y5 y0 __ y3 __
+ pshufb m2, m5 ; y0 y1 y2 y3 y4 y5 __ __
+ movu [r1+2*r4], m2
+
+ shufps m1, m0, 0xd8 ; u0 v0 v1 u2 u1 __ v2 __
+ pshufb m1, m6 ; u0 u1 u2 __ v0 v1 v2 __
+ movq [r2+r4], m1
+ movhps [r3+r4], m1
+
+ add r0, mmsize
+ add r4, 6
+ jl .loop
+
+ REP_RET
+%endmacro
+
+INIT_XMM
+v210_planar_unpack unaligned, ssse3
+INIT_AVX
+v210_planar_unpack unaligned, avx
+
+INIT_XMM
+v210_planar_unpack aligned, ssse3
+INIT_AVX
+v210_planar_unpack aligned, avx
diff --git a/libavcodec/x86/vc1dsp_yasm.asm b/libavcodec/x86/vc1dsp_yasm.asm
index 220cc03da3..572aa0be1e 100644
--- a/libavcodec/x86/vc1dsp_yasm.asm
+++ b/libavcodec/x86/vc1dsp_yasm.asm
@@ -2,25 +2,25 @@
;* VC1 deblocking optimizations
;* Copyright (c) 2009 David Conrad
;*
-;* This file is part of Libav.
+;* This file is part of FFmpeg.
;*
-;* Libav is free software; you can redistribute it and/or
+;* FFmpeg 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.
;*
-;* Libav is distributed in the hope that it will be useful,
+;* FFmpeg 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
;* Lesser General Public License for more details.
;*
;* You should have received a copy of the GNU Lesser General Public
-;* License along with Libav; if not, write to the Free Software
+;* License along with FFmpeg; if not, write to the Free Software
;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
;******************************************************************************
-%include "x86inc.asm"
-%include "x86util.asm"
+%include "libavutil/x86/x86inc.asm"
+%include "libavutil/x86/x86util.asm"
cextern pw_4
cextern pw_5
diff --git a/libavcodec/x86/vp3dsp.asm b/libavcodec/x86/vp3dsp.asm
index 23574383a1..8dac6ab295 100644
--- a/libavcodec/x86/vp3dsp.asm
+++ b/libavcodec/x86/vp3dsp.asm
@@ -2,25 +2,25 @@
;* MMX/SSE2-optimized functions for the VP3 decoder
;* Copyright (c) 2007 Aurelien Jacobs <aurel@gnuage.org>
;*
-;* This file is part of Libav.
+;* This file is part of FFmpeg.
;*
-;* Libav is free software; you can redistribute it and/or
+;* FFmpeg 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.
;*
-;* Libav is distributed in the hope that it will be useful,
+;* FFmpeg 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
;* Lesser General Public License for more details.
;*
;* You should have received a copy of the GNU Lesser General Public
-;* License along with Libav; if not, write to the Free Software
+;* License along with FFmpeg; if not, write to the Free Software
;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
;******************************************************************************
-%include "x86inc.asm"
-%include "x86util.asm"
+%include "libavutil/x86/x86inc.asm"
+%include "libavutil/x86/x86util.asm"
; MMX-optimized functions cribbed from the original VP3 source code.
diff --git a/libavcodec/x86/vp56_arith.h b/libavcodec/x86/vp56_arith.h
index be2dd30b8d..ddbf38b1a9 100644
--- a/libavcodec/x86/vp56_arith.h
+++ b/libavcodec/x86/vp56_arith.h
@@ -4,20 +4,20 @@
* Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org>
* Copyright (C) 2010 Eli Friedman
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/x86/vp56dsp.asm b/libavcodec/x86/vp56dsp.asm
index c70ed60d76..98d8505c8a 100644
--- a/libavcodec/x86/vp56dsp.asm
+++ b/libavcodec/x86/vp56dsp.asm
@@ -3,25 +3,25 @@
;* Copyright (C) 2009 Sebastien Lucas <sebastien.lucas@gmail.com>
;* Copyright (C) 2009 Zuxy Meng <zuxy.meng@gmail.com>
;*
-;* This file is part of Libav.
+;* This file is part of FFmpeg.
;*
-;* Libav is free software; you can redistribute it and/or
+;* FFmpeg 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.
;*
-;* Libav is distributed in the hope that it will be useful,
+;* FFmpeg 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
;* Lesser General Public License for more details.
;*
;* You should have received a copy of the GNU Lesser General Public
-;* License along with Libav; if not, write to the Free Software
+;* License along with FFmpeg; if not, write to the Free Software
;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
;******************************************************************************
-%include "x86inc.asm"
-%include "x86util.asm"
+%include "libavutil/x86/x86inc.asm"
+%include "libavutil/x86/x86util.asm"
cextern pw_64
diff --git a/libavcodec/x86/vp56dsp_init.c b/libavcodec/x86/vp56dsp_init.c
index 29892812ac..87fc935315 100644
--- a/libavcodec/x86/vp56dsp_init.c
+++ b/libavcodec/x86/vp56dsp_init.c
@@ -3,20 +3,20 @@
* Copyright (C) 2009 Sebastien Lucas <sebastien.lucas@gmail.com>
* Copyright (C) 2009 Zuxy Meng <zuxy.meng@gmail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/x86/vp8dsp-init.c b/libavcodec/x86/vp8dsp-init.c
index 8b27b0dadc..a75fdf5bc5 100644
--- a/libavcodec/x86/vp8dsp-init.c
+++ b/libavcodec/x86/vp8dsp-init.c
@@ -3,20 +3,20 @@
* Copyright (c) 2010 Ronald S. Bultje <rsbultje@gmail.com>
* Copyright (c) 2010 Jason Garrett-Glaser <darkshikari@gmail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -283,9 +283,9 @@ DECLARE_LOOP_FILTER(sse4)
av_cold void ff_vp8dsp_init_x86(VP8DSPContext* c)
{
+#if HAVE_YASM
int mm_flags = av_get_cpu_flags();
-#if HAVE_YASM
if (mm_flags & AV_CPU_FLAG_MMX) {
c->vp8_idct_dc_add = ff_vp8_idct_dc_add_mmx;
c->vp8_idct_dc_add4y = ff_vp8_idct_dc_add4y_mmx;
diff --git a/libavcodec/x86/vp8dsp.asm b/libavcodec/x86/vp8dsp.asm
index 7d9ebc9463..833c88a1a0 100644
--- a/libavcodec/x86/vp8dsp.asm
+++ b/libavcodec/x86/vp8dsp.asm
@@ -3,25 +3,25 @@
;* Copyright (c) 2010 Ronald S. Bultje <rsbultje@gmail.com>
;* Copyright (c) 2010 Jason Garrett-Glaser <darkshikari@gmail.com>
;*
-;* This file is part of Libav.
+;* This file is part of FFmpeg.
;*
-;* Libav is free software; you can redistribute it and/or
+;* FFmpeg 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.
;*
-;* Libav is distributed in the hope that it will be useful,
+;* FFmpeg 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
;* Lesser General Public License for more details.
;*
;* You should have received a copy of the GNU Lesser General Public
-;* License along with Libav; if not, write to the Free Software
+;* License along with FFmpeg; if not, write to the Free Software
;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
;******************************************************************************
-%include "x86inc.asm"
-%include "x86util.asm"
+%include "libavutil/x86/x86inc.asm"
+%include "libavutil/x86/x86util.asm"
SECTION_RODATA
diff --git a/libavcodec/xan.c b/libavcodec/xan.c
index 876a9a5558..edd4fe8197 100644
--- a/libavcodec/xan.c
+++ b/libavcodec/xan.c
@@ -2,20 +2,20 @@
* Wing Commander/Xan Video Decoder
* Copyright (C) 2003 the ffmpeg project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -91,24 +91,33 @@ static av_cold int xan_decode_init(AVCodecContext *avctx)
av_freep(&s->buffer1);
return AVERROR(ENOMEM);
}
+ avcodec_get_frame_defaults(&s->last_frame);
+ avcodec_get_frame_defaults(&s->current_frame);
return 0;
}
-static int xan_huffman_decode(unsigned char *dest, const unsigned char *src,
- int dest_len)
+static int xan_huffman_decode(unsigned char *dest, int dest_len,
+ const unsigned char *src, int src_len)
{
unsigned char byte = *src++;
unsigned char ival = byte + 0x16;
const unsigned char * ptr = src + byte*2;
+ int ptr_len = src_len - 1 - byte*2;
unsigned char val = ival;
unsigned char *dest_end = dest + dest_len;
GetBitContext gb;
- init_get_bits(&gb, ptr, 0); // FIXME: no src size available
+ if (ptr_len < 0)
+ return AVERROR_INVALIDDATA;
+
+ init_get_bits(&gb, ptr, ptr_len * 8);
while ( val != 0x16 ) {
- val = src[val - 0x17 + get_bits1(&gb) * byte];
+ unsigned idx = val - 0x17 + get_bits1(&gb) * byte;
+ if (idx >= 2 * byte)
+ return -1;
+ val = src[idx];
if ( val < 0x16 ) {
if (dest >= dest_end)
@@ -126,13 +135,16 @@ static int xan_huffman_decode(unsigned char *dest, const unsigned char *src,
*
* @param dest destination buffer of dest_len, must be padded with at least 130 bytes
*/
-static void xan_unpack(unsigned char *dest, const unsigned char *src, int dest_len)
+static void xan_unpack(unsigned char *dest, int dest_len,
+ const unsigned char *src, int src_len)
{
unsigned char opcode;
int size;
+ unsigned char *dest_org = dest;
unsigned char *dest_end = dest + dest_len;
+ const unsigned char *src_end = src + src_len;
- while (dest < dest_end) {
+ while (dest < dest_end && src < src_end) {
opcode = *src++;
if (opcode < 0xe0) {
@@ -157,9 +169,11 @@ static void xan_unpack(unsigned char *dest, const unsigned char *src, int dest_l
back = ((opcode & 0x10) << 12) + bytestream_get_be16(&src) + 1;
size2 = ((opcode & 0x0c) << 6) + *src++ + 5;
- if (size + size2 > dest_end - dest)
- return;
}
+ if (dest_end - dest < size + size2 ||
+ dest + size - dest_org < back ||
+ src_end - src < size)
+ return;
memcpy(dest, src, size); dest += size; src += size;
av_memcpy_backptr(dest, back, size2);
dest += size2;
@@ -167,6 +181,8 @@ static void xan_unpack(unsigned char *dest, const unsigned char *src, int dest_l
int finish = opcode >= 0xfc;
size = finish ? opcode & 3 : ((opcode & 0x1f) << 2) + 4;
+ if (dest_end - dest < size || src_end - src < size)
+ return;
memcpy(dest, src, size); dest += size; src += size;
if (finish)
return;
@@ -214,15 +230,23 @@ static inline void xan_wc3_copy_pixel_run(XanContext *s,
int width = s->avctx->width;
unsigned char *palette_plane, *prev_palette_plane;
+ if ( y + motion_y < 0 || y + motion_y >= s->avctx->height ||
+ x + motion_x < 0 || x + motion_x >= s->avctx->width)
+ return;
+
palette_plane = s->current_frame.data[0];
prev_palette_plane = s->last_frame.data[0];
+ if (!prev_palette_plane)
+ prev_palette_plane = palette_plane;
stride = s->current_frame.linesize[0];
line_inc = stride - width;
curframe_index = y * stride + x;
curframe_x = x;
prevframe_index = (y + motion_y) * stride + x + motion_x;
prevframe_x = x + motion_x;
- while(pixel_count && (curframe_index < s->frame_size)) {
+ while(pixel_count &&
+ curframe_index < s->frame_size &&
+ prevframe_index < s->frame_size) {
int count = FFMIN3(pixel_count, width - curframe_x, width - prevframe_x);
memcpy(palette_plane + curframe_index, prev_palette_plane + prevframe_index, count);
@@ -244,7 +268,7 @@ static inline void xan_wc3_copy_pixel_run(XanContext *s,
}
}
-static void xan_wc3_decode_frame(XanContext *s) {
+static int xan_wc3_decode_frame(XanContext *s) {
int width = s->avctx->width;
int height = s->avctx->height;
@@ -256,6 +280,7 @@ static void xan_wc3_decode_frame(XanContext *s) {
int x, y;
unsigned char *opcode_buffer = s->buffer1;
+ unsigned char *opcode_buffer_end = s->buffer1 + s->buffer1_size;
int opcode_buffer_size = s->buffer1_size;
const unsigned char *imagedata_buffer = s->buffer2;
@@ -264,22 +289,43 @@ static void xan_wc3_decode_frame(XanContext *s) {
const unsigned char *size_segment;
const unsigned char *vector_segment;
const unsigned char *imagedata_segment;
-
- huffman_segment = s->buf + AV_RL16(&s->buf[0]);
- size_segment = s->buf + AV_RL16(&s->buf[2]);
- vector_segment = s->buf + AV_RL16(&s->buf[4]);
- imagedata_segment = s->buf + AV_RL16(&s->buf[6]);
-
- xan_huffman_decode(opcode_buffer, huffman_segment, opcode_buffer_size);
-
- if (imagedata_segment[0] == 2)
- xan_unpack(s->buffer2, &imagedata_segment[1], s->buffer2_size);
- else
+ int huffman_offset, size_offset, vector_offset, imagedata_offset, imagedata_size;
+
+ if (s->size < 8)
+ return AVERROR_INVALIDDATA;
+
+ huffman_offset = AV_RL16(&s->buf[0]);
+ size_offset = AV_RL16(&s->buf[2]);
+ vector_offset = AV_RL16(&s->buf[4]);
+ imagedata_offset = AV_RL16(&s->buf[6]);
+
+ if (huffman_offset >= s->size ||
+ size_offset >= s->size ||
+ vector_offset >= s->size ||
+ imagedata_offset >= s->size)
+ return AVERROR_INVALIDDATA;
+
+ huffman_segment = s->buf + huffman_offset;
+ size_segment = s->buf + size_offset;
+ vector_segment = s->buf + vector_offset;
+ imagedata_segment = s->buf + imagedata_offset;
+
+ if (xan_huffman_decode(opcode_buffer, opcode_buffer_size,
+ huffman_segment, s->size - huffman_offset) < 0)
+ return AVERROR_INVALIDDATA;
+
+ if (imagedata_segment[0] == 2) {
+ xan_unpack(s->buffer2, s->buffer2_size,
+ &imagedata_segment[1], s->size - imagedata_offset - 1);
+ imagedata_size = s->buffer2_size;
+ } else {
+ imagedata_size = s->size - imagedata_offset - 1;
imagedata_buffer = &imagedata_segment[1];
+ }
/* use the decoded data segments to build the frame */
x = y = 0;
- while (total_pixels) {
+ while (total_pixels && opcode_buffer < opcode_buffer_end) {
opcode = *opcode_buffer++;
size = 0;
@@ -328,6 +374,8 @@ static void xan_wc3_decode_frame(XanContext *s) {
size_segment += 3;
break;
}
+ if (size > total_pixels)
+ break;
if (opcode < 12) {
flag ^= 1;
@@ -336,8 +384,11 @@ static void xan_wc3_decode_frame(XanContext *s) {
xan_wc3_copy_pixel_run(s, x, y, size, 0, 0);
} else {
/* output a run of pixels from imagedata_buffer */
+ if (imagedata_size < size)
+ break;
xan_wc3_output_pixel_run(s, imagedata_buffer, x, y, size);
imagedata_buffer += size;
+ imagedata_size -= size;
}
} else {
/* run-based motion compensation from last frame */
@@ -356,6 +407,7 @@ static void xan_wc3_decode_frame(XanContext *s) {
y += (x + size) / width;
x = (x + size) % width;
}
+ return 0;
}
#if RUNTIME_GAMMA
@@ -503,6 +555,11 @@ static int xan_decode_frame(AVCodecContext *avctx,
}
buf_size = buf_end - buf;
}
+ if (s->palettes_count <= 0) {
+ av_log(s->avctx, AV_LOG_ERROR, "No palette found\n");
+ return AVERROR_INVALIDDATA;
+ }
+
if ((ret = avctx->get_buffer(avctx, &s->current_frame))) {
av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return ret;
@@ -517,7 +574,8 @@ static int xan_decode_frame(AVCodecContext *avctx,
s->buf = buf;
s->size = buf_size;
- xan_wc3_decode_frame(s);
+ if (xan_wc3_decode_frame(s) < 0)
+ return AVERROR_INVALIDDATA;
/* release the last frame if it is allocated */
if (s->last_frame.data[0])
@@ -551,15 +609,13 @@ static av_cold int xan_decode_end(AVCodecContext *avctx)
}
AVCodec ff_xan_wc3_decoder = {
- "xan_wc3",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_XAN_WC3,
- sizeof(XanContext),
- xan_decode_init,
- NULL,
- xan_decode_end,
- xan_decode_frame,
- CODEC_CAP_DR1,
+ .name = "xan_wc3",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_XAN_WC3,
+ .priv_data_size = sizeof(XanContext),
+ .init = xan_decode_init,
+ .close = xan_decode_end,
+ .decode = xan_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Wing Commander III / Xan"),
};
-
diff --git a/libavcodec/xiph.c b/libavcodec/xiph.c
index 0bcfd45eea..0636f8ef59 100644
--- a/libavcodec/xiph.c
+++ b/libavcodec/xiph.c
@@ -1,27 +1,27 @@
/*
- * Copyright (C) 2007 Libav Project
+ * Copyright (C) 2007 FFmpeg Project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/intreadwrite.h"
#include "xiph.h"
-int ff_split_xiph_headers(uint8_t *extradata, int extradata_size,
+int avpriv_split_xiph_headers(uint8_t *extradata, int extradata_size,
int first_header_size, uint8_t *header_start[3],
int header_len[3])
{
diff --git a/libavcodec/xiph.h b/libavcodec/xiph.h
index da18c9c094..cd8caa4810 100644
--- a/libavcodec/xiph.h
+++ b/libavcodec/xiph.h
@@ -1,20 +1,20 @@
/*
- * Copyright (C) 2007 Libav Project
+ * Copyright (C) 2007 FFmpeg Project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -36,8 +36,8 @@
* @param[out] header_len The sizes of each of the three headers.
* @return On error a negative value is returned, on success zero.
*/
-int ff_split_xiph_headers(uint8_t *extradata, int extradata_size,
- int first_header_size, uint8_t *header_start[3],
- int header_len[3]);
+int avpriv_split_xiph_headers(uint8_t *extradata, int extradata_size,
+ int first_header_size, uint8_t *header_start[3],
+ int header_len[3]);
#endif /* AVCODEC_XIPH_H */
diff --git a/libavcodec/xl.c b/libavcodec/xl.c
index 4f17ae54f2..c29e8b3190 100644
--- a/libavcodec/xl.c
+++ b/libavcodec/xl.c
@@ -2,20 +2,20 @@
* Miro VideoXL codec
* Copyright (c) 2004 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -121,8 +121,9 @@ static int decode_frame(AVCodecContext *avctx,
}
static av_cold int decode_init(AVCodecContext *avctx){
-// VideoXLContext * const a = avctx->priv_data;
+ VideoXLContext * const a = avctx->priv_data;
+ avcodec_get_frame_defaults(&a->pic);
avctx->pix_fmt= PIX_FMT_YUV411P;
return 0;
@@ -139,14 +140,13 @@ static av_cold int decode_end(AVCodecContext *avctx){
}
AVCodec ff_xl_decoder = {
- "xl",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_VIXL,
- sizeof(VideoXLContext),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- CODEC_CAP_DR1,
+ .name = "xl",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_VIXL,
+ .priv_data_size = sizeof(VideoXLContext),
+ .init = decode_init,
+ .close = decode_end,
+ .decode = decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Miro VideoXL"),
};
diff --git a/libavcodec/xsubdec.c b/libavcodec/xsubdec.c
index 4afefac2c4..5e0e59faa4 100644
--- a/libavcodec/xsubdec.c
+++ b/libavcodec/xsubdec.c
@@ -2,20 +2,20 @@
* XSUB subtitle decoder
* Copyright (c) 2007 Reimar Döffinger
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -53,11 +53,10 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
AVSubtitle *sub = data;
const uint8_t *buf_end = buf + buf_size;
uint8_t *bitmap;
- int w, h, x, y, rlelen, i;
+ int w, h, x, y, i;
int64_t packet_time = 0;
GetBitContext gb;
-
- memset(sub, 0, sizeof(*sub));
+ int has_alpha = avctx->codec_tag == MKTAG('D','X','S','A');
// check that at least header fits
if (buf_size < 27 + 7 * 2 + 4 * 3) {
@@ -86,7 +85,11 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
// skip bottom right position, it gives no new information
bytestream_get_le16(&buf);
bytestream_get_le16(&buf);
- rlelen = bytestream_get_le16(&buf);
+ // The following value is supposed to indicate the start offset
+ // (relative to the palette) of the data for the second field,
+ // however there are files where it has a bogus value and thus
+ // we just ignore it
+ bytestream_get_le16(&buf);
// allocate sub and set values
sub->rects = av_mallocz(sizeof(*sub->rects));
@@ -104,12 +107,11 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
for (i = 0; i < sub->rects[0]->nb_colors; i++)
((uint32_t*)sub->rects[0]->pict.data[1])[i] = bytestream_get_be24(&buf);
// make all except background (first entry) non-transparent
- for (i = 1; i < sub->rects[0]->nb_colors; i++)
- ((uint32_t*)sub->rects[0]->pict.data[1])[i] |= 0xff000000;
+ for (i = 0; i < sub->rects[0]->nb_colors; i++)
+ ((uint32_t*)sub->rects[0]->pict.data[1])[i] |= (has_alpha ? *buf++ : (i ? 0xff : 0)) << 24;
// process RLE-compressed data
- rlelen = FFMIN(rlelen, buf_end - buf);
- init_get_bits(&gb, buf, rlelen * 8);
+ init_get_bits(&gb, buf, (buf_end - buf) * 8);
bitmap = sub->rects[0]->pict.data[0];
for (y = 0; y < h; y++) {
// interlaced: do odd lines
@@ -134,13 +136,10 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
}
AVCodec ff_xsub_decoder = {
- "xsub",
- AVMEDIA_TYPE_SUBTITLE,
- CODEC_ID_XSUB,
- 0,
- decode_init,
- NULL,
- NULL,
- decode_frame,
+ .name = "xsub",
+ .type = AVMEDIA_TYPE_SUBTITLE,
+ .id = CODEC_ID_XSUB,
+ .init = decode_init,
+ .decode = decode_frame,
.long_name = NULL_IF_CONFIG_SMALL("XSUB"),
};
diff --git a/libavcodec/xsubenc.c b/libavcodec/xsubenc.c
index 0c7d07f09d..4245f45bac 100644
--- a/libavcodec/xsubenc.c
+++ b/libavcodec/xsubenc.c
@@ -3,20 +3,20 @@
* Copyright (c) 2005 DivX, Inc.
* Copyright (c) 2009 Bjorn Axelsson
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -90,7 +90,7 @@ static int xsub_encode_rle(PutBitContext *pb, const uint8_t *bitmap,
if (color != PADDING_COLOR && (PADDING + (w&1)))
put_xsub_rle(pb, PADDING + (w&1), PADDING_COLOR);
- align_put_bits(pb);
+ avpriv_align_put_bits(pb);
bitmap += linesize;
}
@@ -129,7 +129,7 @@ static int xsub_encode(AVCodecContext *avctx, unsigned char *buf,
}
// TODO: support multiple rects
- if (h->num_rects > 1)
+ if (h->num_rects != 1)
av_log(avctx, AV_LOG_WARNING, "Only single rects supported (%d in subtitle.)\n", h->num_rects);
// TODO: render text-based subtitles into bitmaps
@@ -194,7 +194,7 @@ static int xsub_encode(AVCodecContext *avctx, unsigned char *buf,
// Enforce total height to be be multiple of 2
if (h->rects[0]->h & 1) {
put_xsub_rle(&pb, h->rects[0]->w, PADDING_COLOR);
- align_put_bits(&pb);
+ avpriv_align_put_bits(&pb);
}
flush_put_bits(&pb);
@@ -211,12 +211,10 @@ static av_cold int xsub_encoder_init(AVCodecContext *avctx)
}
AVCodec ff_xsub_encoder = {
- "xsub",
- AVMEDIA_TYPE_SUBTITLE,
- CODEC_ID_XSUB,
- 0,
- xsub_encoder_init,
- xsub_encode,
- NULL,
+ .name = "xsub",
+ .type = AVMEDIA_TYPE_SUBTITLE,
+ .id = CODEC_ID_XSUB,
+ .init = xsub_encoder_init,
+ .encode = xsub_encode,
.long_name = NULL_IF_CONFIG_SMALL("DivX subtitles (XSUB)"),
};
diff --git a/libavcodec/xvmc.h b/libavcodec/xvmc.h
index 1239015fcd..93ad8bb9a5 100644
--- a/libavcodec/xvmc.h
+++ b/libavcodec/xvmc.h
@@ -1,20 +1,20 @@
/*
* Copyright (C) 2003 Ivan Kalvachev
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/xvmc_internal.h b/libavcodec/xvmc_internal.h
index 3c6aed8361..04197cefae 100644
--- a/libavcodec/xvmc_internal.h
+++ b/libavcodec/xvmc_internal.h
@@ -1,20 +1,20 @@
/*
* XVideo Motion Compensation internal functions
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/xxan.c b/libavcodec/xxan.c
index 28c868d5ba..938a5581c4 100644
--- a/libavcodec/xxan.c
+++ b/libavcodec/xxan.c
@@ -3,20 +3,20 @@
* Copyright (C) 2011 Konstantin Shishkov
* based on work by Mike Melanson
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -129,7 +129,9 @@ static int xan_unpack(uint8_t *dest, const int dest_len,
if (size + size2 > dest_end - dest)
break;
}
- if (src + size > src_end || dest + size + size2 > dest_end)
+ if (src + size > src_end ||
+ dest + size + size2 > dest_end ||
+ dest + size - orig_dest < back )
return -1;
bytestream_get_buffer(&src, dest, size);
dest += size;
@@ -194,6 +196,8 @@ static int xan_decode_chroma(AVCodecContext *avctx, AVPacket *avpkt)
if (mode) {
for (j = 0; j < avctx->height >> 1; j++) {
for (i = 0; i < avctx->width >> 1; i++) {
+ if (src_end - src < 1)
+ return 0;
val = *src++;
if (val) {
val = AV_RL16(table + (val << 1));
@@ -202,8 +206,6 @@ static int xan_decode_chroma(AVCodecContext *avctx, AVPacket *avpkt)
U[i] = uval | (uval >> 5);
V[i] = vval | (vval >> 5);
}
- if (src == src_end)
- return 0;
}
U += s->pic.linesize[1];
V += s->pic.linesize[2];
@@ -214,6 +216,8 @@ static int xan_decode_chroma(AVCodecContext *avctx, AVPacket *avpkt)
for (j = 0; j < avctx->height >> 2; j++) {
for (i = 0; i < avctx->width >> 1; i += 2) {
+ if (src_end - src < 1)
+ return 0;
val = *src++;
if (val) {
val = AV_RL16(table + (val << 1));
@@ -302,6 +306,9 @@ static int xan_decode_frame_type0(AVCodecContext *avctx, AVPacket *avpkt)
corr_end - corr_off);
if (dec_size < 0)
dec_size = 0;
+ else
+ dec_size = FFMIN(dec_size, s->buffer_size/2 - 1);
+
for (i = 0; i < dec_size; i++)
s->y_buffer[i*2+1] = (s->y_buffer[i*2+1] + (s->scratch_buffer[i] << 1)) & 0x3F;
}
@@ -415,15 +422,14 @@ static av_cold int xan_decode_end(AVCodecContext *avctx)
}
AVCodec ff_xan_wc4_decoder = {
- "xan_wc4",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_XAN_WC4,
- sizeof(XanContext),
- xan_decode_init,
- NULL,
- xan_decode_end,
- xan_decode_frame,
- CODEC_CAP_DR1,
+ .name = "xan_wc4",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_XAN_WC4,
+ .priv_data_size = sizeof(XanContext),
+ .init = xan_decode_init,
+ .close = xan_decode_end,
+ .decode = xan_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Wing Commander IV / Xxan"),
};
diff --git a/libavcodec/yop.c b/libavcodec/yop.c
index 1f1314b6a7..87a91f28d7 100644
--- a/libavcodec/yop.c
+++ b/libavcodec/yop.c
@@ -1,25 +1,24 @@
-/**
- * @file
+/*
* Psygnosis YOP decoder
*
* Copyright (C) 2010 Mohamed Naufal Basheer <naufal11@gmail.com>
* derived from the code by
* Copyright (C) 2009 Thomas P. Higdon <thomas.p.higdon@gmail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -92,6 +91,7 @@ static av_cold int yop_decode_init(AVCodecContext *avctx)
avctx->pix_fmt = PIX_FMT_PAL8;
+ avcodec_get_frame_defaults(&s->frame);
s->num_pal_colors = avctx->extradata[0];
s->first_color[0] = avctx->extradata[1];
s->first_color[1] = avctx->extradata[2];
@@ -249,13 +249,12 @@ static int yop_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
}
AVCodec ff_yop_decoder = {
- "yop",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_YOP,
- sizeof(YopDecContext),
- yop_decode_init,
- NULL,
- yop_decode_close,
- yop_decode_frame,
+ .name = "yop",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_YOP,
+ .priv_data_size = sizeof(YopDecContext),
+ .init = yop_decode_init,
+ .close = yop_decode_close,
+ .decode = yop_decode_frame,
.long_name = NULL_IF_CONFIG_SMALL("Psygnosis YOP Video"),
};
diff --git a/libavcodec/zmbv.c b/libavcodec/zmbv.c
index deae580d20..42da1fb600 100644
--- a/libavcodec/zmbv.c
+++ b/libavcodec/zmbv.c
@@ -2,20 +2,20 @@
* Zip Motion Blocks Video (ZMBV) decoder
* Copyright (c) 2006 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -574,7 +574,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac
default:
av_log(avctx, AV_LOG_ERROR, "Cannot handle format %i\n", c->fmt);
}
- memcpy(c->prev, c->cur, c->width * c->height * (c->bpp / 8));
+ FFSWAP(uint8_t *, c->cur, c->prev);
}
*data_size = sizeof(AVFrame);
*(AVFrame*)data = c->pic;
@@ -599,6 +599,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
c->width = avctx->width;
c->height = avctx->height;
+ avcodec_get_frame_defaults(&c->pic);
c->bpp = avctx->bits_per_coded_sample;
@@ -651,15 +652,14 @@ static av_cold int decode_end(AVCodecContext *avctx)
}
AVCodec ff_zmbv_decoder = {
- "zmbv",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_ZMBV,
- sizeof(ZmbvContext),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- CODEC_CAP_DR1,
+ .name = "zmbv",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_ZMBV,
+ .priv_data_size = sizeof(ZmbvContext),
+ .init = decode_init,
+ .close = decode_end,
+ .decode = decode_frame,
+ .capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Zip Motion Blocks Video"),
};
diff --git a/libavcodec/zmbvenc.c b/libavcodec/zmbvenc.c
index e4f4860ea0..ce65ce4dc0 100644
--- a/libavcodec/zmbvenc.c
+++ b/libavcodec/zmbvenc.c
@@ -2,20 +2,20 @@
* Zip Motion Blocks Video (ZMBV) encoder
* Copyright (c) 2006 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -324,13 +324,13 @@ static av_cold int encode_end(AVCodecContext *avctx)
}
AVCodec ff_zmbv_encoder = {
- "zmbv",
- AVMEDIA_TYPE_VIDEO,
- CODEC_ID_ZMBV,
- sizeof(ZmbvEncContext),
- encode_init,
- encode_frame,
- encode_end,
+ .name = "zmbv",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_ZMBV,
+ .priv_data_size = sizeof(ZmbvEncContext),
+ .init = encode_init,
+ .encode = encode_frame,
+ .close = encode_end,
.pix_fmts = (const enum PixelFormat[]){PIX_FMT_PAL8, PIX_FMT_NONE},
.long_name = NULL_IF_CONFIG_SMALL("Zip Motion Blocks Video"),
};
diff --git a/libavdevice/Makefile b/libavdevice/Makefile
index eaf27ddc42..a640a04a59 100644
--- a/libavdevice/Makefile
+++ b/libavdevice/Makefile
@@ -1,5 +1,8 @@
+include $(SUBDIR)../config.mak
+
NAME = avdevice
FFLIBS = avformat avcodec avutil
+FFLIBS-$(CONFIG_LAVFI_INDEV) += avfilter
HEADERS = avdevice.h
@@ -7,15 +10,22 @@ OBJS = alldevices.o avdevice.o
# input/output devices
OBJS-$(CONFIG_ALSA_INDEV) += alsa-audio-common.o \
- alsa-audio-dec.o
+ alsa-audio-dec.o timefilter.o
OBJS-$(CONFIG_ALSA_OUTDEV) += alsa-audio-common.o \
alsa-audio-enc.o
OBJS-$(CONFIG_BKTR_INDEV) += bktr.o
+OBJS-$(CONFIG_DSHOW_INDEV) += dshow.o dshow_enummediatypes.o \
+ dshow_enumpins.o dshow_filter.o \
+ dshow_pin.o dshow_common.o
OBJS-$(CONFIG_DV1394_INDEV) += dv1394.o
OBJS-$(CONFIG_FBDEV_INDEV) += fbdev.o
-OBJS-$(CONFIG_JACK_INDEV) += jack_audio.o
+OBJS-$(CONFIG_JACK_INDEV) += jack_audio.o timefilter.o
+OBJS-$(CONFIG_LAVFI_INDEV) += lavfi.o
+OBJS-$(CONFIG_OPENAL_INDEV) += openal-dec.o
OBJS-$(CONFIG_OSS_INDEV) += oss_audio.o
OBJS-$(CONFIG_OSS_OUTDEV) += oss_audio.o
+OBJS-$(CONFIG_PULSE_INDEV) += pulse.o
+OBJS-$(CONFIG_SDL_OUTDEV) += sdl.o
OBJS-$(CONFIG_SNDIO_INDEV) += sndio_common.o sndio_dec.o
OBJS-$(CONFIG_SNDIO_OUTDEV) += sndio_common.o sndio_enc.o
OBJS-$(CONFIG_V4L2_INDEV) += v4l2.o
@@ -24,9 +34,12 @@ OBJS-$(CONFIG_VFWCAP_INDEV) += vfwcap.o
OBJS-$(CONFIG_X11_GRAB_DEVICE_INDEV) += x11grab.o
# external libraries
+OBJS-$(CONFIG_LIBCDIO_INDEV) += libcdio.o
OBJS-$(CONFIG_LIBDC1394_INDEV) += libdc1394.o
SKIPHEADERS-$(HAVE_ALSA_ASOUNDLIB_H) += alsa-audio.h
SKIPHEADERS-$(HAVE_SNDIO_H) += sndio_common.h
+TESTPROGS = timefilter
+
include $(SRC_PATH)/subdir.mak
diff --git a/libavdevice/alldevices.c b/libavdevice/alldevices.c
index e7bfb027cd..ace7c17ddf 100644
--- a/libavdevice/alldevices.c
+++ b/libavdevice/alldevices.c
@@ -1,25 +1,24 @@
/*
* Register all the grabbing devices.
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "config.h"
-#include "libavformat/avformat.h"
#include "avdevice.h"
#define REGISTER_OUTDEV(X,x) { \
@@ -41,10 +40,15 @@ void avdevice_register_all(void)
/* devices */
REGISTER_INOUTDEV (ALSA, alsa);
REGISTER_INDEV (BKTR, bktr);
+ REGISTER_INDEV (DSHOW, dshow);
REGISTER_INDEV (DV1394, dv1394);
REGISTER_INDEV (FBDEV, fbdev);
REGISTER_INDEV (JACK, jack);
+ REGISTER_INDEV (LAVFI, lavfi);
+ REGISTER_INDEV (OPENAL, openal);
REGISTER_INOUTDEV (OSS, oss);
+ REGISTER_INDEV (PULSE, pulse);
+ REGISTER_OUTDEV (SDL, sdl);
REGISTER_INOUTDEV (SNDIO, sndio);
REGISTER_INDEV (V4L2, v4l2);
#if FF_API_V4L
@@ -54,5 +58,6 @@ void avdevice_register_all(void)
REGISTER_INDEV (X11_GRAB_DEVICE, x11_grab_device);
/* external libraries */
+ REGISTER_INDEV (LIBCDIO, libcdio);
REGISTER_INDEV (LIBDC1394, libdc1394);
}
diff --git a/libavdevice/alsa-audio-common.c b/libavdevice/alsa-audio-common.c
index 4cfc6e9864..1ed7b6ed5e 100644
--- a/libavdevice/alsa-audio-common.c
+++ b/libavdevice/alsa-audio-common.c
@@ -3,20 +3,20 @@
* Copyright (c) 2007 Luca Abeni ( lucabe72 email it )
* Copyright (c) 2007 Benoit Fouet ( benoit fouet free fr )
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -29,8 +29,9 @@
*/
#include <alsa/asoundlib.h>
-#include "libavformat/avformat.h"
+#include "avdevice.h"
#include "libavutil/avassert.h"
+#include "libavutil/audioconvert.h"
#include "alsa-audio.h"
@@ -260,6 +261,7 @@ av_cold int ff_alsa_open(AVFormatContext *ctx, snd_pcm_stream_t mode,
}
snd_pcm_hw_params_get_buffer_size_max(hw_params, &buffer_size);
+ buffer_size = FFMIN(buffer_size, ALSA_BUFFER_SIZE_MAX);
/* TODO: maybe use ctx->max_picture_buffer somehow */
res = snd_pcm_hw_params_set_buffer_size_near(h, hw_params, &buffer_size);
if (res < 0) {
@@ -269,6 +271,8 @@ av_cold int ff_alsa_open(AVFormatContext *ctx, snd_pcm_stream_t mode,
}
snd_pcm_hw_params_get_period_size_min(hw_params, &period_size, NULL);
+ if (!period_size)
+ period_size = buffer_size / 4;
res = snd_pcm_hw_params_set_period_size_near(h, hw_params, &period_size, NULL);
if (res < 0) {
av_log(ctx, AV_LOG_ERROR, "cannot set ALSA period size (%s)\n",
@@ -316,6 +320,8 @@ av_cold int ff_alsa_close(AVFormatContext *s1)
AlsaData *s = s1->priv_data;
av_freep(&s->reorder_buf);
+ if (CONFIG_ALSA_INDEV)
+ ff_timefilter_destroy(s->timefilter);
snd_pcm_close(s->h);
return 0;
}
diff --git a/libavdevice/alsa-audio-dec.c b/libavdevice/alsa-audio-dec.c
index 937f6a6ef7..bd00b1535b 100644
--- a/libavdevice/alsa-audio-dec.c
+++ b/libavdevice/alsa-audio-dec.c
@@ -3,20 +3,20 @@
* Copyright (c) 2007 Luca Abeni ( lucabe72 email it )
* Copyright (c) 2007 Benoit Fouet ( benoit fouet free fr )
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -46,9 +46,10 @@
*/
#include <alsa/asoundlib.h>
-#include "libavformat/avformat.h"
#include "libavutil/opt.h"
+#include "libavutil/mathematics.h"
+#include "avdevice.h"
#include "alsa-audio.h"
static av_cold int audio_read_header(AVFormatContext *s1,
@@ -58,17 +59,9 @@ static av_cold int audio_read_header(AVFormatContext *s1,
AVStream *st;
int ret;
enum CodecID codec_id;
- snd_pcm_sw_params_t *sw_params;
+ double o;
-#if FF_API_FORMAT_PARAMETERS
- if (ap->sample_rate > 0)
- s->sample_rate = ap->sample_rate;
-
- if (ap->channels > 0)
- s->channels = ap->channels;
-#endif
-
- st = av_new_stream(s1, 0);
+ st = avformat_new_stream(s1, NULL);
if (!st) {
av_log(s1, AV_LOG_ERROR, "Cannot add stream\n");
@@ -82,35 +75,17 @@ static av_cold int audio_read_header(AVFormatContext *s1,
return AVERROR(EIO);
}
- if (snd_pcm_type(s->h) != SND_PCM_TYPE_HW)
- av_log(s1, AV_LOG_WARNING,
- "capture with some ALSA plugins, especially dsnoop, "
- "may hang.\n");
-
- ret = snd_pcm_sw_params_malloc(&sw_params);
- if (ret < 0) {
- av_log(s1, AV_LOG_ERROR, "cannot allocate software parameters structure (%s)\n",
- snd_strerror(ret));
- goto fail;
- }
-
- snd_pcm_sw_params_current(s->h, sw_params);
- snd_pcm_sw_params_set_tstamp_mode(s->h, sw_params, SND_PCM_TSTAMP_ENABLE);
-
- ret = snd_pcm_sw_params(s->h, sw_params);
- snd_pcm_sw_params_free(sw_params);
- if (ret < 0) {
- av_log(s1, AV_LOG_ERROR, "cannot install ALSA software parameters (%s)\n",
- snd_strerror(ret));
- goto fail;
- }
-
/* take real parameters */
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
st->codec->codec_id = codec_id;
st->codec->sample_rate = s->sample_rate;
st->codec->channels = s->channels;
av_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */
+ o = 2 * M_PI * s->period_size / s->sample_rate * 1.5; // bandwidth: 1.5Hz
+ s->timefilter = ff_timefilter_new(1000000.0 / s->sample_rate,
+ sqrt(2 * o), o * o);
+ if (!s->timefilter)
+ goto fail;
return 0;
@@ -122,16 +97,15 @@ fail:
static int audio_read_packet(AVFormatContext *s1, AVPacket *pkt)
{
AlsaData *s = s1->priv_data;
- AVStream *st = s1->streams[0];
int res;
- snd_htimestamp_t timestamp;
- snd_pcm_uframes_t ts_delay;
+ int64_t dts;
+ snd_pcm_sframes_t delay = 0;
- if (av_new_packet(pkt, s->period_size) < 0) {
+ if (av_new_packet(pkt, s->period_size * s->frame_size) < 0) {
return AVERROR(EIO);
}
- while ((res = snd_pcm_readi(s->h, pkt->data, pkt->size / s->frame_size)) < 0) {
+ while ((res = snd_pcm_readi(s->h, pkt->data, s->period_size)) < 0) {
if (res == -EAGAIN) {
av_free_packet(pkt);
@@ -144,14 +118,13 @@ static int audio_read_packet(AVFormatContext *s1, AVPacket *pkt)
return AVERROR(EIO);
}
+ ff_timefilter_reset(s->timefilter);
}
- snd_pcm_htimestamp(s->h, &ts_delay, &timestamp);
- ts_delay += res;
- pkt->pts = timestamp.tv_sec * 1000000LL
- + (timestamp.tv_nsec * st->codec->sample_rate
- - ts_delay * 1000000000LL + st->codec->sample_rate * 500LL)
- / (st->codec->sample_rate * 1000LL);
+ dts = av_gettime();
+ snd_pcm_delay(s->h, &delay);
+ dts -= av_rescale(delay + res, 1000000, s->sample_rate);
+ pkt->pts = ff_timefilter_update(s->timefilter, dts, res);
pkt->size = res * s->frame_size;
@@ -159,8 +132,8 @@ static int audio_read_packet(AVFormatContext *s1, AVPacket *pkt)
}
static const AVOption options[] = {
- { "sample_rate", "", offsetof(AlsaData, sample_rate), FF_OPT_TYPE_INT, {.dbl = 48000}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
- { "channels", "", offsetof(AlsaData, channels), FF_OPT_TYPE_INT, {.dbl = 2}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
+ { "sample_rate", "", offsetof(AlsaData, sample_rate), AV_OPT_TYPE_INT, {.dbl = 48000}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
+ { "channels", "", offsetof(AlsaData, channels), AV_OPT_TYPE_INT, {.dbl = 2}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
{ NULL },
};
@@ -172,13 +145,12 @@ static const AVClass alsa_demuxer_class = {
};
AVInputFormat ff_alsa_demuxer = {
- "alsa",
- NULL_IF_CONFIG_SMALL("ALSA audio input"),
- sizeof(AlsaData),
- NULL,
- audio_read_header,
- audio_read_packet,
- ff_alsa_close,
- .flags = AVFMT_NOFILE,
- .priv_class = &alsa_demuxer_class,
+ .name = "alsa",
+ .long_name = NULL_IF_CONFIG_SMALL("ALSA audio input"),
+ .priv_data_size = sizeof(AlsaData),
+ .read_header = audio_read_header,
+ .read_packet = audio_read_packet,
+ .read_close = ff_alsa_close,
+ .flags = AVFMT_NOFILE,
+ .priv_class = &alsa_demuxer_class,
};
diff --git a/libavdevice/alsa-audio-enc.c b/libavdevice/alsa-audio-enc.c
index f3782c5ab6..446d7a24e5 100644
--- a/libavdevice/alsa-audio-enc.c
+++ b/libavdevice/alsa-audio-enc.c
@@ -3,20 +3,20 @@
* Copyright (c) 2007 Luca Abeni ( lucabe72 email it )
* Copyright (c) 2007 Benoit Fouet ( benoit fouet free fr )
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -38,8 +38,8 @@
*/
#include <alsa/asoundlib.h>
-#include "libavformat/avformat.h"
+#include "avdevice.h"
#include "alsa-audio.h"
static av_cold int audio_write_header(AVFormatContext *s1)
@@ -61,6 +61,7 @@ static av_cold int audio_write_header(AVFormatContext *s1)
st->codec->sample_rate, sample_rate);
goto fail;
}
+ av_set_pts_info(st, 64, 1, sample_rate);
return res;
@@ -101,16 +102,26 @@ static int audio_write_packet(AVFormatContext *s1, AVPacket *pkt)
return 0;
}
+static void
+audio_get_output_timestamp(AVFormatContext *s1, int stream,
+ int64_t *dts, int64_t *wall)
+{
+ AlsaData *s = s1->priv_data;
+ snd_pcm_sframes_t delay = 0;
+ *wall = av_gettime();
+ snd_pcm_delay(s->h, &delay);
+ *dts = s1->streams[0]->cur_dts - delay;
+}
+
AVOutputFormat ff_alsa_muxer = {
- "alsa",
- NULL_IF_CONFIG_SMALL("ALSA audio output"),
- "",
- "",
- sizeof(AlsaData),
- DEFAULT_CODEC_ID,
- CODEC_ID_NONE,
- audio_write_header,
- audio_write_packet,
- ff_alsa_close,
- .flags = AVFMT_NOFILE,
+ .name = "alsa",
+ .long_name = NULL_IF_CONFIG_SMALL("ALSA audio output"),
+ .priv_data_size = sizeof(AlsaData),
+ .audio_codec = DEFAULT_CODEC_ID,
+ .video_codec = CODEC_ID_NONE,
+ .write_header = audio_write_header,
+ .write_packet = audio_write_packet,
+ .write_trailer = ff_alsa_close,
+ .get_output_timestamp = audio_get_output_timestamp,
+ .flags = AVFMT_NOFILE,
};
diff --git a/libavdevice/alsa-audio.h b/libavdevice/alsa-audio.h
index 1e0be1cac7..e453a2011b 100644
--- a/libavdevice/alsa-audio.h
+++ b/libavdevice/alsa-audio.h
@@ -3,20 +3,20 @@
* Copyright (c) 2007 Luca Abeni ( lucabe72 email it )
* Copyright (c) 2007 Benoit Fouet ( benoit fouet free fr )
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -32,21 +32,27 @@
#include <alsa/asoundlib.h>
#include "config.h"
-#include "libavformat/avformat.h"
#include "libavutil/log.h"
+#include "timefilter.h"
+#include "avdevice.h"
/* XXX: we make the assumption that the soundcard accepts this format */
/* XXX: find better solution with "preinit" method, needed also in
other formats */
#define DEFAULT_CODEC_ID AV_NE(CODEC_ID_PCM_S16BE, CODEC_ID_PCM_S16LE)
+typedef void (*ff_reorder_func)(const void *, void *, int);
+
+#define ALSA_BUFFER_SIZE_MAX 65536
+
typedef struct {
AVClass *class;
snd_pcm_t *h;
- int frame_size; ///< preferred size for reads and writes
- int period_size; ///< bytes per sample * channels
+ int frame_size; ///< bytes per sample * channels
+ int period_size; ///< preferred size for reads and writes, in frames
int sample_rate; ///< sample rate set by user
int channels; ///< number of channels set by user
+ TimeFilter *timefilter;
void (*reorder_func)(const void *, void *, int);
void *reorder_buf;
int reorder_buf_size; ///< in frames
diff --git a/libavdevice/avdevice.c b/libavdevice/avdevice.c
index 4813a3dd18..3d67b4b8be 100644
--- a/libavdevice/avdevice.c
+++ b/libavdevice/avdevice.c
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -25,11 +25,11 @@ unsigned avdevice_version(void)
const char * avdevice_configuration(void)
{
- return LIBAV_CONFIGURATION;
+ return FFMPEG_CONFIGURATION;
}
const char * avdevice_license(void)
{
#define LICENSE_PREFIX "libavdevice license: "
- return LICENSE_PREFIX LIBAV_LICENSE + sizeof(LICENSE_PREFIX) - 1;
+ return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1;
}
diff --git a/libavdevice/avdevice.h b/libavdevice/avdevice.h
index d82b26fda6..68e3a46a8d 100644
--- a/libavdevice/avdevice.h
+++ b/libavdevice/avdevice.h
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -20,9 +20,10 @@
#define AVDEVICE_AVDEVICE_H
#include "libavutil/avutil.h"
+#include "libavformat/avformat.h"
#define LIBAVDEVICE_VERSION_MAJOR 53
-#define LIBAVDEVICE_VERSION_MINOR 0
+#define LIBAVDEVICE_VERSION_MINOR 4
#define LIBAVDEVICE_VERSION_MICRO 0
#define LIBAVDEVICE_VERSION_INT AV_VERSION_INT(LIBAVDEVICE_VERSION_MAJOR, \
diff --git a/libavdevice/bktr.c b/libavdevice/bktr.c
index f1ae9ea685..db917c450a 100644
--- a/libavdevice/bktr.c
+++ b/libavdevice/bktr.c
@@ -7,24 +7,23 @@
* and
* simple_grab.c Copyright (c) 1999 Roger Hardiman
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include "libavformat/avformat.h"
#include "libavutil/log.h"
#include "libavutil/opt.h"
#include "libavutil/parseutils.h"
@@ -48,6 +47,7 @@
#include <signal.h>
#include <stdint.h>
#include <strings.h>
+#include "avdevice.h"
typedef struct {
AVClass *class;
@@ -251,17 +251,6 @@ static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap)
AVRational framerate;
int ret = 0;
-#if FF_API_FORMAT_PARAMETERS
- if (ap->standard) {
- if (!strcasecmp(ap->standard, "pal"))
- s->standard = PAL;
- else if (!strcasecmp(ap->standard, "secam"))
- s->standard = SECAM;
- else if (!strcasecmp(ap->standard, "ntsc"))
- s->standard = NTSC;
- }
-#endif
-
if ((ret = av_parse_video_size(&width, &height, s->video_size)) < 0) {
av_log(s1, AV_LOG_ERROR, "Could not parse video size '%s'.\n", s->video_size);
goto out;
@@ -281,16 +270,8 @@ static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap)
av_log(s1, AV_LOG_ERROR, "Could not parse framerate '%s'.\n", s->framerate);
goto out;
}
-#if FF_API_FORMAT_PARAMETERS
- if (ap->width > 0)
- width = ap->width;
- if (ap->height > 0)
- height = ap->height;
- if (ap->time_base.num)
- framerate = (AVRational){ap->time_base.den, ap->time_base.num};
-#endif
- st = av_new_stream(s1, 0);
+ st = avformat_new_stream(s1, NULL);
if (!st) {
ret = AVERROR(ENOMEM);
goto out;
@@ -344,15 +325,15 @@ static int grab_read_close(AVFormatContext *s1)
#define OFFSET(x) offsetof(VideoData, x)
#define DEC AV_OPT_FLAG_DECODING_PARAM
static const AVOption options[] = {
- { "standard", "", offsetof(VideoData, standard), FF_OPT_TYPE_INT, {.dbl = VIDEO_FORMAT}, PAL, NTSCJ, AV_OPT_FLAG_DECODING_PARAM, "standard" },
- { "PAL", "", 0, FF_OPT_TYPE_CONST, {.dbl = PAL}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" },
- { "NTSC", "", 0, FF_OPT_TYPE_CONST, {.dbl = NTSC}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" },
- { "SECAM", "", 0, FF_OPT_TYPE_CONST, {.dbl = SECAM}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" },
- { "PALN", "", 0, FF_OPT_TYPE_CONST, {.dbl = PALN}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" },
- { "PALM", "", 0, FF_OPT_TYPE_CONST, {.dbl = PALM}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" },
- { "NTSCJ", "", 0, FF_OPT_TYPE_CONST, {.dbl = NTSCJ}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" },
- { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), FF_OPT_TYPE_STRING, {.str = "vga"}, 0, 0, DEC },
- { "framerate", "", OFFSET(framerate), FF_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
+ { "standard", "", offsetof(VideoData, standard), AV_OPT_TYPE_INT, {.dbl = VIDEO_FORMAT}, PAL, NTSCJ, AV_OPT_FLAG_DECODING_PARAM, "standard" },
+ { "PAL", "", 0, AV_OPT_TYPE_CONST, {.dbl = PAL}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" },
+ { "NTSC", "", 0, AV_OPT_TYPE_CONST, {.dbl = NTSC}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" },
+ { "SECAM", "", 0, AV_OPT_TYPE_CONST, {.dbl = SECAM}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" },
+ { "PALN", "", 0, AV_OPT_TYPE_CONST, {.dbl = PALN}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" },
+ { "PALM", "", 0, AV_OPT_TYPE_CONST, {.dbl = PALM}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" },
+ { "NTSCJ", "", 0, AV_OPT_TYPE_CONST, {.dbl = NTSCJ}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" },
+ { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), AV_OPT_TYPE_STRING, {.str = "vga"}, 0, 0, DEC },
+ { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
{ NULL },
};
@@ -364,13 +345,12 @@ static const AVClass bktr_class = {
};
AVInputFormat ff_bktr_demuxer = {
- "bktr",
- NULL_IF_CONFIG_SMALL("video grab"),
- sizeof(VideoData),
- NULL,
- grab_read_header,
- grab_read_packet,
- grab_read_close,
- .flags = AVFMT_NOFILE,
- .priv_class = &bktr_class,
+ .name = "bktr",
+ .long_name = NULL_IF_CONFIG_SMALL("video grab"),
+ .priv_data_size = sizeof(VideoData),
+ .read_header = grab_read_header,
+ .read_packet = grab_read_packet,
+ .read_close = grab_read_close,
+ .flags = AVFMT_NOFILE,
+ .priv_class = &bktr_class,
};
diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c
new file mode 100644
index 0000000000..6a77f4b43a
--- /dev/null
+++ b/libavdevice/dshow.c
@@ -0,0 +1,960 @@
+/*
+ * Directshow capture interface
+ * Copyright (c) 2010 Ramiro Polla
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/parseutils.h"
+#include "libavutil/opt.h"
+
+#include "avdevice.h"
+#include "dshow.h"
+
+struct dshow_ctx {
+ const AVClass *class;
+
+ IGraphBuilder *graph;
+
+ char *device_name[2];
+
+ int list_options;
+ int list_devices;
+
+ IBaseFilter *device_filter[2];
+ IPin *device_pin[2];
+ libAVFilter *capture_filter[2];
+ libAVPin *capture_pin[2];
+
+ HANDLE mutex;
+ HANDLE event;
+ AVPacketList *pktl;
+
+ unsigned int curbufsize;
+ unsigned int video_frame_num;
+
+ IMediaControl *control;
+
+ char *video_size;
+ char *framerate;
+
+ int requested_width;
+ int requested_height;
+ AVRational requested_framerate;
+
+ int sample_rate;
+ int sample_size;
+ int channels;
+};
+
+static enum PixelFormat dshow_pixfmt(DWORD biCompression, WORD biBitCount)
+{
+ switch(biCompression) {
+ case MKTAG('U', 'Y', 'V', 'Y'):
+ return PIX_FMT_UYVY422;
+ case MKTAG('Y', 'U', 'Y', '2'):
+ return PIX_FMT_YUYV422;
+ case MKTAG('I', '4', '2', '0'):
+ return PIX_FMT_YUV420P;
+ case BI_RGB:
+ switch(biBitCount) { /* 1-8 are untested */
+ case 1:
+ return PIX_FMT_MONOWHITE;
+ case 4:
+ return PIX_FMT_RGB4;
+ case 8:
+ return PIX_FMT_RGB8;
+ case 16:
+ return PIX_FMT_RGB555;
+ case 24:
+ return PIX_FMT_BGR24;
+ case 32:
+ return PIX_FMT_RGB32;
+ }
+ }
+ return PIX_FMT_NONE;
+}
+
+static enum CodecID dshow_codecid(DWORD biCompression)
+{
+ switch(biCompression) {
+ case MKTAG('d', 'v', 's', 'd'):
+ return CODEC_ID_DVVIDEO;
+ case MKTAG('M', 'J', 'P', 'G'):
+ case MKTAG('m', 'j', 'p', 'g'):
+ return CODEC_ID_MJPEG;
+ }
+ return CODEC_ID_NONE;
+}
+
+static int
+dshow_read_close(AVFormatContext *s)
+{
+ struct dshow_ctx *ctx = s->priv_data;
+ AVPacketList *pktl;
+
+ if (ctx->control) {
+ IMediaControl_Stop(ctx->control);
+ IMediaControl_Release(ctx->control);
+ }
+
+ if (ctx->graph) {
+ IEnumFilters *fenum;
+ int r;
+ r = IGraphBuilder_EnumFilters(ctx->graph, &fenum);
+ if (r == S_OK) {
+ IBaseFilter *f;
+ IEnumFilters_Reset(fenum);
+ while (IEnumFilters_Next(fenum, 1, &f, NULL) == S_OK)
+ if (IGraphBuilder_RemoveFilter(ctx->graph, f) == S_OK)
+ IEnumFilters_Reset(fenum); /* When a filter is removed,
+ * the list must be reset. */
+ IEnumFilters_Release(fenum);
+ }
+ IGraphBuilder_Release(ctx->graph);
+ }
+
+ if (ctx->capture_pin[VideoDevice])
+ libAVPin_Release(ctx->capture_pin[VideoDevice]);
+ if (ctx->capture_pin[AudioDevice])
+ libAVPin_Release(ctx->capture_pin[AudioDevice]);
+ if (ctx->capture_filter[VideoDevice])
+ libAVFilter_Release(ctx->capture_filter[VideoDevice]);
+ if (ctx->capture_filter[AudioDevice])
+ libAVFilter_Release(ctx->capture_filter[AudioDevice]);
+
+ if (ctx->device_pin[VideoDevice])
+ IPin_Release(ctx->device_pin[VideoDevice]);
+ if (ctx->device_pin[AudioDevice])
+ IPin_Release(ctx->device_pin[AudioDevice]);
+ if (ctx->device_filter[VideoDevice])
+ IBaseFilter_Release(ctx->device_filter[VideoDevice]);
+ if (ctx->device_filter[AudioDevice])
+ IBaseFilter_Release(ctx->device_filter[AudioDevice]);
+
+ if (ctx->device_name[0])
+ av_free(ctx->device_name[0]);
+ if (ctx->device_name[1])
+ av_free(ctx->device_name[1]);
+
+ if(ctx->mutex)
+ CloseHandle(ctx->mutex);
+ if(ctx->event)
+ CloseHandle(ctx->event);
+
+ pktl = ctx->pktl;
+ while (pktl) {
+ AVPacketList *next = pktl->next;
+ av_destruct_packet(&pktl->pkt);
+ av_free(pktl);
+ pktl = next;
+ }
+
+ return 0;
+}
+
+static char *dup_wchar_to_utf8(wchar_t *w)
+{
+ char *s = NULL;
+ int l = WideCharToMultiByte(CP_UTF8, 0, w, -1, 0, 0, 0, 0);
+ s = av_malloc(l);
+ if (s)
+ WideCharToMultiByte(CP_UTF8, 0, w, -1, s, l, 0, 0);
+ return s;
+}
+
+static int shall_we_drop(AVFormatContext *s)
+{
+ struct dshow_ctx *ctx = s->priv_data;
+ const uint8_t dropscore[] = {62, 75, 87, 100};
+ const int ndropscores = FF_ARRAY_ELEMS(dropscore);
+ unsigned int buffer_fullness = (ctx->curbufsize*100)/s->max_picture_buffer;
+
+ if(dropscore[++ctx->video_frame_num%ndropscores] <= buffer_fullness) {
+ av_log(s, AV_LOG_ERROR,
+ "real-time buffer %d%% full! frame dropped!\n", buffer_fullness);
+ return 1;
+ }
+
+ return 0;
+}
+
+static void
+callback(void *priv_data, int index, uint8_t *buf, int buf_size, int64_t time)
+{
+ AVFormatContext *s = priv_data;
+ struct dshow_ctx *ctx = s->priv_data;
+ AVPacketList **ppktl, *pktl_next;
+
+// dump_videohdr(s, vdhdr);
+
+ if(shall_we_drop(s))
+ return;
+
+ WaitForSingleObject(ctx->mutex, INFINITE);
+
+ pktl_next = av_mallocz(sizeof(AVPacketList));
+ if(!pktl_next)
+ goto fail;
+
+ if(av_new_packet(&pktl_next->pkt, buf_size) < 0) {
+ av_free(pktl_next);
+ goto fail;
+ }
+
+ pktl_next->pkt.stream_index = index;
+ pktl_next->pkt.pts = time;
+ memcpy(pktl_next->pkt.data, buf, buf_size);
+
+ for(ppktl = &ctx->pktl ; *ppktl ; ppktl = &(*ppktl)->next);
+ *ppktl = pktl_next;
+
+ ctx->curbufsize += buf_size;
+
+ SetEvent(ctx->event);
+ ReleaseMutex(ctx->mutex);
+
+ return;
+fail:
+ ReleaseMutex(ctx->mutex);
+ return;
+}
+
+/**
+ * Cycle through available devices using the device enumerator devenum,
+ * retrieve the device with type specified by devtype and return the
+ * pointer to the object found in *pfilter.
+ * If pfilter is NULL, list all device names.
+ */
+static int
+dshow_cycle_devices(AVFormatContext *avctx, ICreateDevEnum *devenum,
+ enum dshowDeviceType devtype, IBaseFilter **pfilter)
+{
+ struct dshow_ctx *ctx = avctx->priv_data;
+ IBaseFilter *device_filter = NULL;
+ IEnumMoniker *classenum = NULL;
+ IMoniker *m = NULL;
+ const char *device_name = ctx->device_name[devtype];
+ int r;
+
+ const GUID *device_guid[2] = { &CLSID_VideoInputDeviceCategory,
+ &CLSID_AudioInputDeviceCategory };
+ const char *devtypename = (devtype == VideoDevice) ? "video" : "audio";
+
+ r = ICreateDevEnum_CreateClassEnumerator(devenum, device_guid[devtype],
+ (IEnumMoniker **) &classenum, 0);
+ if (r != S_OK) {
+ av_log(avctx, AV_LOG_ERROR, "Could not enumerate %s devices.\n",
+ devtypename);
+ return AVERROR(EIO);
+ }
+
+ while (!device_filter && IEnumMoniker_Next(classenum, 1, &m, NULL) == S_OK) {
+ IPropertyBag *bag = NULL;
+ char *buf = NULL;
+ VARIANT var;
+
+ r = IMoniker_BindToStorage(m, 0, 0, &IID_IPropertyBag, (void *) &bag);
+ if (r != S_OK)
+ goto fail1;
+
+ var.vt = VT_BSTR;
+ r = IPropertyBag_Read(bag, L"FriendlyName", &var, NULL);
+ if (r != S_OK)
+ goto fail1;
+
+ buf = dup_wchar_to_utf8(var.bstrVal);
+
+ if (pfilter) {
+ if (strcmp(device_name, buf))
+ goto fail1;
+
+ IMoniker_BindToObject(m, 0, 0, &IID_IBaseFilter, (void *) &device_filter);
+ } else {
+ av_log(avctx, AV_LOG_INFO, " \"%s\"\n", buf);
+ }
+
+fail1:
+ if (buf)
+ av_free(buf);
+ if (bag)
+ IPropertyBag_Release(bag);
+ IMoniker_Release(m);
+ }
+
+ IEnumMoniker_Release(classenum);
+
+ if (pfilter) {
+ if (!device_filter) {
+ av_log(avctx, AV_LOG_ERROR, "Could not find %s device.\n",
+ devtypename);
+ return AVERROR(EIO);
+ }
+ *pfilter = device_filter;
+ }
+
+ return 0;
+}
+
+/**
+ * Cycle through available formats using the specified pin,
+ * try to set parameters specified through AVOptions and if successful
+ * return 1 in *pformat_set.
+ * If pformat_set is NULL, list all pin capabilities.
+ */
+static void
+dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype,
+ IPin *pin, int *pformat_set)
+{
+ struct dshow_ctx *ctx = avctx->priv_data;
+ IAMStreamConfig *config = NULL;
+ AM_MEDIA_TYPE *type = NULL;
+ int format_set = 0;
+ void *caps = NULL;
+ int i, n, size;
+
+ if (IPin_QueryInterface(pin, &IID_IAMStreamConfig, (void **) &config) != S_OK)
+ return;
+ if (IAMStreamConfig_GetNumberOfCapabilities(config, &n, &size) != S_OK)
+ goto end;
+
+ caps = av_malloc(size);
+ if (!caps)
+ goto end;
+
+ for (i = 0; i < n && !format_set; i++) {
+ IAMStreamConfig_GetStreamCaps(config, i, &type, (void *) caps);
+
+#if DSHOWDEBUG
+ ff_print_AM_MEDIA_TYPE(type);
+#endif
+
+ if (devtype == VideoDevice) {
+ VIDEO_STREAM_CONFIG_CAPS *vcaps = caps;
+ BITMAPINFOHEADER *bih;
+ int64_t *fr;
+#if DSHOWDEBUG
+ ff_print_VIDEO_STREAM_CONFIG_CAPS(vcaps);
+#endif
+ if (IsEqualGUID(&type->formattype, &FORMAT_VideoInfo)) {
+ VIDEOINFOHEADER *v = (void *) type->pbFormat;
+ fr = &v->AvgTimePerFrame;
+ bih = &v->bmiHeader;
+ } else if (IsEqualGUID(&type->formattype, &FORMAT_VideoInfo2)) {
+ VIDEOINFOHEADER2 *v = (void *) type->pbFormat;
+ fr = &v->AvgTimePerFrame;
+ bih = &v->bmiHeader;
+ } else {
+ goto next;
+ }
+ if (!pformat_set) {
+ av_log(avctx, AV_LOG_INFO, " min s=%ldx%ld fps=%g max s=%ldx%ld fps=%g\n",
+ vcaps->MinOutputSize.cx, vcaps->MinOutputSize.cy,
+ 1e7 / vcaps->MinFrameInterval,
+ vcaps->MaxOutputSize.cx, vcaps->MaxOutputSize.cy,
+ 1e7 / vcaps->MaxFrameInterval);
+ continue;
+ }
+ if (ctx->framerate) {
+ int64_t framerate = ((int64_t) ctx->requested_framerate.den*10000000)
+ / ctx->requested_framerate.num;
+ if (framerate > vcaps->MaxFrameInterval ||
+ framerate < vcaps->MinFrameInterval)
+ goto next;
+ *fr = framerate;
+ }
+ if (ctx->video_size) {
+ if (ctx->requested_width > vcaps->MaxOutputSize.cx ||
+ ctx->requested_width < vcaps->MinOutputSize.cx ||
+ ctx->requested_height > vcaps->MaxOutputSize.cy ||
+ ctx->requested_height < vcaps->MinOutputSize.cy)
+ goto next;
+ bih->biWidth = ctx->requested_width;
+ bih->biHeight = ctx->requested_height;
+ }
+ } else {
+ AUDIO_STREAM_CONFIG_CAPS *acaps = caps;
+ WAVEFORMATEX *fx;
+#if DSHOWDEBUG
+ ff_print_AUDIO_STREAM_CONFIG_CAPS(acaps);
+#endif
+ if (IsEqualGUID(&type->formattype, &FORMAT_WaveFormatEx)) {
+ fx = (void *) type->pbFormat;
+ } else {
+ goto next;
+ }
+ if (!pformat_set) {
+ av_log(avctx, AV_LOG_INFO, " min ch=%lu bits=%lu rate=%6lu max ch=%lu bits=%lu rate=%6lu\n",
+ acaps->MinimumChannels, acaps->MinimumBitsPerSample, acaps->MinimumSampleFrequency,
+ acaps->MaximumChannels, acaps->MaximumBitsPerSample, acaps->MaximumSampleFrequency);
+ continue;
+ }
+ if (ctx->sample_rate) {
+ if (ctx->sample_rate > acaps->MaximumSampleFrequency ||
+ ctx->sample_rate < acaps->MinimumSampleFrequency)
+ goto next;
+ fx->nSamplesPerSec = ctx->sample_rate;
+ }
+ if (ctx->sample_size) {
+ if (ctx->sample_size > acaps->MaximumBitsPerSample ||
+ ctx->sample_size < acaps->MinimumBitsPerSample)
+ goto next;
+ fx->wBitsPerSample = ctx->sample_size;
+ }
+ if (ctx->channels) {
+ if (ctx->channels > acaps->MaximumChannels ||
+ ctx->channels < acaps->MinimumChannels)
+ goto next;
+ fx->nChannels = ctx->channels;
+ }
+ }
+ if (IAMStreamConfig_SetFormat(config, type) != S_OK)
+ goto next;
+ format_set = 1;
+next:
+ if (type->pbFormat)
+ CoTaskMemFree(type->pbFormat);
+ CoTaskMemFree(type);
+ }
+end:
+ IAMStreamConfig_Release(config);
+ if (caps)
+ av_free(caps);
+ if (pformat_set)
+ *pformat_set = format_set;
+}
+
+/**
+ * Cycle through available pins using the device_filter device, of type
+ * devtype, retrieve the first output pin and return the pointer to the
+ * object found in *ppin.
+ * If ppin is NULL, cycle through all pins listing audio/video capabilities.
+ */
+static int
+dshow_cycle_pins(AVFormatContext *avctx, enum dshowDeviceType devtype,
+ IBaseFilter *device_filter, IPin **ppin)
+{
+ struct dshow_ctx *ctx = avctx->priv_data;
+ IEnumPins *pins = 0;
+ IPin *device_pin = NULL;
+ IPin *pin;
+ int r;
+
+ const GUID *mediatype[2] = { &MEDIATYPE_Video, &MEDIATYPE_Audio };
+ const char *devtypename = (devtype == VideoDevice) ? "video" : "audio";
+
+ int set_format = (devtype == VideoDevice && (ctx->video_size || ctx->framerate))
+ || (devtype == AudioDevice && (ctx->channels || ctx->sample_rate));
+ int format_set = 0;
+
+ r = IBaseFilter_EnumPins(device_filter, &pins);
+ if (r != S_OK) {
+ av_log(avctx, AV_LOG_ERROR, "Could not enumerate pins.\n");
+ return AVERROR(EIO);
+ }
+
+ if (!ppin) {
+ av_log(avctx, AV_LOG_INFO, "DirectShow %s device options\n",
+ devtypename);
+ }
+ while (!device_pin && IEnumPins_Next(pins, 1, &pin, NULL) == S_OK) {
+ IKsPropertySet *p = NULL;
+ IEnumMediaTypes *types = NULL;
+ PIN_INFO info = {0};
+ AM_MEDIA_TYPE *type;
+ GUID category;
+ DWORD r2;
+
+ IPin_QueryPinInfo(pin, &info);
+ IBaseFilter_Release(info.pFilter);
+
+ if (info.dir != PINDIR_OUTPUT)
+ goto next;
+ if (IPin_QueryInterface(pin, &IID_IKsPropertySet, (void **) &p) != S_OK)
+ goto next;
+ if (IKsPropertySet_Get(p, &AMPROPSETID_Pin, AMPROPERTY_PIN_CATEGORY,
+ NULL, 0, &category, sizeof(GUID), &r2) != S_OK)
+ goto next;
+ if (!IsEqualGUID(&category, &PIN_CATEGORY_CAPTURE))
+ goto next;
+
+ if (!ppin) {
+ char *buf = dup_wchar_to_utf8(info.achName);
+ av_log(avctx, AV_LOG_INFO, " Pin \"%s\"\n", buf);
+ av_free(buf);
+ dshow_cycle_formats(avctx, devtype, pin, NULL);
+ goto next;
+ }
+ if (set_format) {
+ dshow_cycle_formats(avctx, devtype, pin, &format_set);
+ if (!format_set) {
+ goto next;
+ }
+ }
+
+ if (IPin_EnumMediaTypes(pin, &types) != S_OK)
+ goto next;
+
+ IEnumMediaTypes_Reset(types);
+ while (!device_pin && IEnumMediaTypes_Next(types, 1, &type, NULL) == S_OK) {
+ if (IsEqualGUID(&type->majortype, mediatype[devtype])) {
+ device_pin = pin;
+ goto next;
+ }
+ CoTaskMemFree(type);
+ }
+
+next:
+ if (types)
+ IEnumMediaTypes_Release(types);
+ if (p)
+ IKsPropertySet_Release(p);
+ if (device_pin != pin)
+ IPin_Release(pin);
+ }
+
+ IEnumPins_Release(pins);
+
+ if (ppin) {
+ if (set_format && !format_set) {
+ av_log(avctx, AV_LOG_ERROR, "Could not set %s options\n", devtypename);
+ return AVERROR(EIO);
+ }
+ if (!device_pin) {
+ av_log(avctx, AV_LOG_ERROR,
+ "Could not find output pin from %s capture device.\n", devtypename);
+ return AVERROR(EIO);
+ }
+ *ppin = device_pin;
+ }
+
+ return 0;
+}
+
+/**
+ * List options for device with type devtype.
+ *
+ * @param devenum device enumerator used for accessing the device
+ */
+static int
+dshow_list_device_options(AVFormatContext *avctx, ICreateDevEnum *devenum,
+ enum dshowDeviceType devtype)
+{
+ IBaseFilter *device_filter = NULL;
+ int r;
+
+ if ((r = dshow_cycle_devices(avctx, devenum, devtype, &device_filter)) < 0)
+ return r;
+ if ((r = dshow_cycle_pins(avctx, devtype, device_filter, NULL)) < 0)
+ return r;
+
+ return 0;
+}
+
+static int
+dshow_open_device(AVFormatContext *avctx, ICreateDevEnum *devenum,
+ enum dshowDeviceType devtype)
+{
+ struct dshow_ctx *ctx = avctx->priv_data;
+ IBaseFilter *device_filter = NULL;
+ IGraphBuilder *graph = ctx->graph;
+ IPin *device_pin = NULL;
+ libAVPin *capture_pin = NULL;
+ libAVFilter *capture_filter = NULL;
+ int ret = AVERROR(EIO);
+ int r;
+
+ const wchar_t *filter_name[2] = { L"Audio capture filter", L"Video capture filter" };
+
+ if ((r = dshow_cycle_devices(avctx, devenum, devtype, &device_filter)) < 0) {
+ ret = r;
+ goto error;
+ }
+
+ ctx->device_filter [devtype] = device_filter;
+
+ r = IGraphBuilder_AddFilter(graph, device_filter, NULL);
+ if (r != S_OK) {
+ av_log(avctx, AV_LOG_ERROR, "Could not add device filter to graph.\n");
+ goto error;
+ }
+
+ if ((r = dshow_cycle_pins(avctx, devtype, device_filter, &device_pin)) < 0) {
+ ret = r;
+ goto error;
+ }
+ ctx->device_pin[devtype] = device_pin;
+
+ capture_filter = libAVFilter_Create(avctx, callback, devtype);
+ if (!capture_filter) {
+ av_log(avctx, AV_LOG_ERROR, "Could not create grabber filter.\n");
+ goto error;
+ }
+ ctx->capture_filter[devtype] = capture_filter;
+
+ r = IGraphBuilder_AddFilter(graph, (IBaseFilter *) capture_filter,
+ filter_name[devtype]);
+ if (r != S_OK) {
+ av_log(avctx, AV_LOG_ERROR, "Could not add capture filter to graph\n");
+ goto error;
+ }
+
+ libAVPin_AddRef(capture_filter->pin);
+ capture_pin = capture_filter->pin;
+ ctx->capture_pin[devtype] = capture_pin;
+
+ r = IGraphBuilder_ConnectDirect(graph, device_pin, (IPin *) capture_pin, NULL);
+ if (r != S_OK) {
+ av_log(avctx, AV_LOG_ERROR, "Could not connect pins\n");
+ goto error;
+ }
+
+ ret = 0;
+
+error:
+ return ret;
+}
+
+static enum CodecID waveform_codec_id(enum AVSampleFormat sample_fmt)
+{
+ switch (sample_fmt) {
+ case AV_SAMPLE_FMT_U8: return CODEC_ID_PCM_U8;
+ case AV_SAMPLE_FMT_S16: return CODEC_ID_PCM_S16LE;
+ case AV_SAMPLE_FMT_S32: return CODEC_ID_PCM_S32LE;
+ default: return CODEC_ID_NONE; /* Should never happen. */
+ }
+}
+
+static enum SampleFormat sample_fmt_bits_per_sample(int bits)
+{
+ switch (bits) {
+ case 8: return AV_SAMPLE_FMT_U8;
+ case 16: return AV_SAMPLE_FMT_S16;
+ case 32: return AV_SAMPLE_FMT_S32;
+ default: return AV_SAMPLE_FMT_NONE; /* Should never happen. */
+ }
+}
+
+static int
+dshow_add_device(AVFormatContext *avctx, AVFormatParameters *ap,
+ enum dshowDeviceType devtype)
+{
+ struct dshow_ctx *ctx = avctx->priv_data;
+ AM_MEDIA_TYPE type;
+ AVCodecContext *codec;
+ AVStream *st;
+ int ret = AVERROR(EIO);
+
+ st = av_new_stream(avctx, devtype);
+ if (!st) {
+ ret = AVERROR(ENOMEM);
+ goto error;
+ }
+
+ ctx->capture_filter[devtype]->stream_index = st->index;
+
+ libAVPin_ConnectionMediaType(ctx->capture_pin[devtype], &type);
+
+ codec = st->codec;
+ if (devtype == VideoDevice) {
+ BITMAPINFOHEADER *bih = NULL;
+
+ if (IsEqualGUID(&type.formattype, &FORMAT_VideoInfo)) {
+ VIDEOINFOHEADER *v = (void *) type.pbFormat;
+ bih = &v->bmiHeader;
+ } else if (IsEqualGUID(&type.formattype, &FORMAT_VideoInfo2)) {
+ VIDEOINFOHEADER2 *v = (void *) type.pbFormat;
+ bih = &v->bmiHeader;
+ }
+ if (!bih) {
+ av_log(avctx, AV_LOG_ERROR, "Could not get media type.\n");
+ goto error;
+ }
+
+ codec->time_base = ap->time_base;
+ codec->codec_type = AVMEDIA_TYPE_VIDEO;
+ codec->width = bih->biWidth;
+ codec->height = bih->biHeight;
+ codec->pix_fmt = dshow_pixfmt(bih->biCompression, bih->biBitCount);
+ if (codec->pix_fmt == PIX_FMT_NONE) {
+ codec->codec_id = dshow_codecid(bih->biCompression);
+ if (codec->codec_id == CODEC_ID_NONE) {
+ av_log(avctx, AV_LOG_ERROR, "Unknown compression type. "
+ "Please report verbose (-v 9) debug information.\n");
+ dshow_read_close(avctx);
+ return AVERROR_PATCHWELCOME;
+ }
+ codec->bits_per_coded_sample = bih->biBitCount;
+ } else {
+ codec->codec_id = CODEC_ID_RAWVIDEO;
+ if (bih->biCompression == BI_RGB) {
+ codec->bits_per_coded_sample = bih->biBitCount;
+ codec->extradata = av_malloc(9 + FF_INPUT_BUFFER_PADDING_SIZE);
+ if (codec->extradata) {
+ codec->extradata_size = 9;
+ memcpy(codec->extradata, "BottomUp", 9);
+ }
+ }
+ }
+ } else {
+ WAVEFORMATEX *fx = NULL;
+
+ if (IsEqualGUID(&type.formattype, &FORMAT_WaveFormatEx)) {
+ fx = (void *) type.pbFormat;
+ }
+ if (!fx) {
+ av_log(avctx, AV_LOG_ERROR, "Could not get media type.\n");
+ goto error;
+ }
+
+ codec->codec_type = AVMEDIA_TYPE_AUDIO;
+ codec->sample_fmt = sample_fmt_bits_per_sample(fx->wBitsPerSample);
+ codec->codec_id = waveform_codec_id(codec->sample_fmt);
+ codec->sample_rate = fx->nSamplesPerSec;
+ codec->channels = fx->nChannels;
+ }
+
+ av_set_pts_info(st, 64, 1, 10000000);
+
+ ret = 0;
+
+error:
+ return ret;
+}
+
+static int parse_device_name(AVFormatContext *avctx)
+{
+ struct dshow_ctx *ctx = avctx->priv_data;
+ char **device_name = ctx->device_name;
+ char *name = av_strdup(avctx->filename);
+ char *tmp = name;
+ int ret = 1;
+ char *type;
+
+ while ((type = strtok(tmp, "="))) {
+ char *token = strtok(NULL, ":");
+ tmp = NULL;
+
+ if (!strcmp(type, "video")) {
+ device_name[0] = token;
+ } else if (!strcmp(type, "audio")) {
+ device_name[1] = token;
+ } else {
+ device_name[0] = NULL;
+ device_name[1] = NULL;
+ break;
+ }
+ }
+
+ if (!device_name[0] && !device_name[1]) {
+ ret = 0;
+ } else {
+ if (device_name[0])
+ device_name[0] = av_strdup(device_name[0]);
+ if (device_name[1])
+ device_name[1] = av_strdup(device_name[1]);
+ }
+
+ av_free(name);
+ return ret;
+}
+
+static int dshow_read_header(AVFormatContext *avctx, AVFormatParameters *ap)
+{
+ struct dshow_ctx *ctx = avctx->priv_data;
+ IGraphBuilder *graph = NULL;
+ ICreateDevEnum *devenum = NULL;
+ IMediaControl *control = NULL;
+ int ret = AVERROR(EIO);
+ int r;
+
+ if (!ctx->list_devices && !parse_device_name(avctx)) {
+ av_log(avctx, AV_LOG_ERROR, "Malformed dshow input string.\n");
+ goto error;
+ }
+
+ if (ctx->video_size) {
+ r = av_parse_video_size(&ctx->requested_width, &ctx->requested_height, ctx->video_size);
+ if (r < 0) {
+ av_log(avctx, AV_LOG_ERROR, "Could not parse video size '%s'.\n", ctx->video_size);
+ goto error;
+ }
+ }
+ if (ctx->framerate) {
+ r = av_parse_video_rate(&ctx->requested_framerate, ctx->framerate);
+ if (r < 0) {
+ av_log(avctx, AV_LOG_ERROR, "Could not parse framerate '%s'.\n", ctx->framerate);
+ goto error;
+ }
+ }
+
+ CoInitialize(0);
+
+ r = CoCreateInstance(&CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER,
+ &IID_IGraphBuilder, (void **) &graph);
+ if (r != S_OK) {
+ av_log(avctx, AV_LOG_ERROR, "Could not create capture graph.\n");
+ goto error;
+ }
+ ctx->graph = graph;
+
+ r = CoCreateInstance(&CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,
+ &IID_ICreateDevEnum, (void **) &devenum);
+ if (r != S_OK) {
+ av_log(avctx, AV_LOG_ERROR, "Could not enumerate system devices.\n");
+ goto error;
+ }
+
+ if (ctx->list_devices) {
+ av_log(avctx, AV_LOG_INFO, "DirectShow video devices\n");
+ dshow_cycle_devices(avctx, devenum, VideoDevice, NULL);
+ av_log(avctx, AV_LOG_INFO, "DirectShow audio devices\n");
+ dshow_cycle_devices(avctx, devenum, AudioDevice, NULL);
+ ret = AVERROR_EXIT;
+ goto error;
+ }
+ if (ctx->list_options) {
+ if (ctx->device_name[VideoDevice])
+ dshow_list_device_options(avctx, devenum, VideoDevice);
+ if (ctx->device_name[AudioDevice])
+ dshow_list_device_options(avctx, devenum, AudioDevice);
+ ret = AVERROR_EXIT;
+ goto error;
+ }
+
+ if (ctx->device_name[VideoDevice]) {
+ ret = dshow_open_device(avctx, devenum, VideoDevice);
+ if (ret < 0)
+ goto error;
+ ret = dshow_add_device(avctx, ap, VideoDevice);
+ if (ret < 0)
+ goto error;
+ }
+ if (ctx->device_name[AudioDevice]) {
+ ret = dshow_open_device(avctx, devenum, AudioDevice);
+ if (ret < 0)
+ goto error;
+ ret = dshow_add_device(avctx, ap, AudioDevice);
+ if (ret < 0)
+ goto error;
+ }
+
+ ctx->mutex = CreateMutex(NULL, 0, NULL);
+ if (!ctx->mutex) {
+ av_log(avctx, AV_LOG_ERROR, "Could not create Mutex\n");
+ goto error;
+ }
+ ctx->event = CreateEvent(NULL, 1, 0, NULL);
+ if (!ctx->event) {
+ av_log(avctx, AV_LOG_ERROR, "Could not create Event\n");
+ goto error;
+ }
+
+ r = IGraphBuilder_QueryInterface(graph, &IID_IMediaControl, (void **) &control);
+ if (r != S_OK) {
+ av_log(avctx, AV_LOG_ERROR, "Could not get media control.\n");
+ goto error;
+ }
+ ctx->control = control;
+
+ r = IMediaControl_Run(control);
+ if (r == S_FALSE) {
+ OAFilterState pfs;
+ r = IMediaControl_GetState(control, 0, &pfs);
+ }
+ if (r != S_OK) {
+ av_log(avctx, AV_LOG_ERROR, "Could not run filter\n");
+ goto error;
+ }
+
+ ret = 0;
+
+error:
+
+ if (ret < 0)
+ dshow_read_close(avctx);
+
+ if (devenum)
+ ICreateDevEnum_Release(devenum);
+
+ return ret;
+}
+
+static int dshow_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ struct dshow_ctx *ctx = s->priv_data;
+ AVPacketList *pktl = NULL;
+
+ while (!pktl) {
+ WaitForSingleObject(ctx->mutex, INFINITE);
+ pktl = ctx->pktl;
+ if (ctx->pktl) {
+ *pkt = ctx->pktl->pkt;
+ ctx->pktl = ctx->pktl->next;
+ av_free(pktl);
+ }
+ ResetEvent(ctx->event);
+ ReleaseMutex(ctx->mutex);
+ if (!pktl) {
+ if (s->flags & AVFMT_FLAG_NONBLOCK) {
+ return AVERROR(EAGAIN);
+ } else {
+ WaitForSingleObject(ctx->event, INFINITE);
+ }
+ }
+ }
+
+ ctx->curbufsize -= pkt->size;
+
+ return pkt->size;
+}
+
+#define OFFSET(x) offsetof(struct dshow_ctx, x)
+#define DEC AV_OPT_FLAG_DECODING_PARAM
+static const AVOption options[] = {
+ { "video_size", "set video size given a string such as 640x480 or hd720.", OFFSET(video_size), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
+ { "framerate", "set video frame rate", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
+ { "sample_rate", "set audio sample rate", OFFSET(sample_rate), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, DEC },
+ { "sample_size", "set audio sample size", OFFSET(sample_size), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 16, DEC },
+ { "channels", "set number of audio channels, such as 1 or 2", OFFSET(channels), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, DEC },
+ { "list_devices", "list available devices", OFFSET(list_devices), AV_OPT_TYPE_INT, {.dbl=0}, 0, 1, DEC, "list_devices" },
+ { "true", "", 0, AV_OPT_TYPE_CONST, {.dbl=1}, 0, 0, DEC, "list_devices" },
+ { "false", "", 0, AV_OPT_TYPE_CONST, {.dbl=0}, 0, 0, DEC, "list_devices" },
+ { "list_options", "list available options for specified device", OFFSET(list_options), AV_OPT_TYPE_INT, {.dbl=0}, 0, 1, DEC, "list_options" },
+ { "true", "", 0, AV_OPT_TYPE_CONST, {.dbl=1}, 0, 0, DEC, "list_options" },
+ { "false", "", 0, AV_OPT_TYPE_CONST, {.dbl=0}, 0, 0, DEC, "list_options" },
+ { NULL },
+};
+
+static const AVClass dshow_class = {
+ .class_name = "DirectShow indev",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
+AVInputFormat ff_dshow_demuxer = {
+ "dshow",
+ NULL_IF_CONFIG_SMALL("DirectShow capture"),
+ sizeof(struct dshow_ctx),
+ NULL,
+ dshow_read_header,
+ dshow_read_packet,
+ dshow_read_close,
+ .flags = AVFMT_NOFILE,
+ .priv_class = &dshow_class,
+};
diff --git a/libavdevice/dshow.h b/libavdevice/dshow.h
new file mode 100644
index 0000000000..83c71c48e8
--- /dev/null
+++ b/libavdevice/dshow.h
@@ -0,0 +1,268 @@
+/*
+ * DirectShow capture interface
+ * Copyright (c) 2010 Ramiro Polla
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#define DSHOWDEBUG 0
+
+#include "avdevice.h"
+
+#define COBJMACROS
+#include <windows.h>
+#include <dshow.h>
+#include <dvdmedia.h>
+
+long ff_copy_dshow_media_type(AM_MEDIA_TYPE *dst, const AM_MEDIA_TYPE *src);
+void ff_print_VIDEO_STREAM_CONFIG_CAPS(const VIDEO_STREAM_CONFIG_CAPS *caps);
+void ff_print_AUDIO_STREAM_CONFIG_CAPS(const AUDIO_STREAM_CONFIG_CAPS *caps);
+void ff_print_AM_MEDIA_TYPE(const AM_MEDIA_TYPE *type);
+void ff_printGUID(const GUID *g);
+
+#if DSHOWDEBUG
+extern const AVClass *ff_dshow_context_class_ptr;
+#define dshowdebug(...) av_log(&ff_dshow_context_class_ptr, AV_LOG_DEBUG, __VA_ARGS__)
+#else
+#define dshowdebug(...)
+#endif
+
+static inline void nothing(void *foo)
+{
+}
+
+struct GUIDoffset {
+ const GUID *iid;
+ int offset;
+};
+
+enum dshowDeviceType {
+ VideoDevice = 0,
+ AudioDevice = 1,
+};
+
+#define DECLARE_QUERYINTERFACE(class, ...) \
+long WINAPI \
+class##_QueryInterface(class *this, const GUID *riid, void **ppvObject) \
+{ \
+ struct GUIDoffset ifaces[] = __VA_ARGS__; \
+ int i; \
+ dshowdebug(AV_STRINGIFY(class)"_QueryInterface(%p, %p, %p)\n", this, riid, ppvObject); \
+ ff_printGUID(riid); \
+ if (!ppvObject) \
+ return E_POINTER; \
+ for (i = 0; i < sizeof(ifaces)/sizeof(ifaces[0]); i++) { \
+ if (IsEqualGUID(riid, ifaces[i].iid)) { \
+ void *obj = (void *) ((uint8_t *) this + ifaces[i].offset); \
+ class##_AddRef(this); \
+ dshowdebug("\tfound %d with offset %d\n", i, ifaces[i].offset); \
+ *ppvObject = (void *) obj; \
+ return S_OK; \
+ } \
+ } \
+ dshowdebug("\tE_NOINTERFACE\n"); \
+ *ppvObject = NULL; \
+ return E_NOINTERFACE; \
+}
+#define DECLARE_ADDREF(class) \
+unsigned long WINAPI \
+class##_AddRef(class *this) \
+{ \
+ dshowdebug(AV_STRINGIFY(class)"_AddRef(%p)\t%ld\n", this, this->ref+1); \
+ return InterlockedIncrement(&this->ref); \
+}
+#define DECLARE_RELEASE(class) \
+unsigned long WINAPI \
+class##_Release(class *this) \
+{ \
+ long ref = InterlockedDecrement(&this->ref); \
+ dshowdebug(AV_STRINGIFY(class)"_Release(%p)\t%ld\n", this, ref); \
+ if (!ref) \
+ class##_Destroy(this); \
+ return ref; \
+}
+
+#define DECLARE_DESTROY(class, func) \
+void class##_Destroy(class *this) \
+{ \
+ dshowdebug(AV_STRINGIFY(class)"_Destroy(%p)\n", this); \
+ func(this); \
+ if (this) { \
+ if (this->vtbl) \
+ CoTaskMemFree(this->vtbl); \
+ CoTaskMemFree(this); \
+ } \
+}
+#define DECLARE_CREATE(class, setup, ...) \
+class *class##_Create(__VA_ARGS__) \
+{ \
+ class *this = CoTaskMemAlloc(sizeof(class)); \
+ void *vtbl = CoTaskMemAlloc(sizeof(*this->vtbl)); \
+ dshowdebug(AV_STRINGIFY(class)"_Create(%p)\n", this); \
+ if (!this || !vtbl) \
+ goto fail; \
+ ZeroMemory(this, sizeof(class)); \
+ ZeroMemory(vtbl, sizeof(*this->vtbl)); \
+ this->ref = 1; \
+ this->vtbl = vtbl; \
+ if (!setup) \
+ goto fail; \
+ dshowdebug("created "AV_STRINGIFY(class)" %p\n", this); \
+ return this; \
+fail: \
+ class##_Destroy(this); \
+ dshowdebug("could not create "AV_STRINGIFY(class)"\n"); \
+ return NULL; \
+}
+
+#define SETVTBL(vtbl, class, fn) \
+ do { (vtbl)->fn = (void *) class##_##fn; } while(0)
+
+/*****************************************************************************
+ * Forward Declarations
+ ****************************************************************************/
+typedef struct libAVPin libAVPin;
+typedef struct libAVMemInputPin libAVMemInputPin;
+typedef struct libAVEnumPins libAVEnumPins;
+typedef struct libAVEnumMediaTypes libAVEnumMediaTypes;
+typedef struct libAVFilter libAVFilter;
+
+/*****************************************************************************
+ * libAVPin
+ ****************************************************************************/
+struct libAVPin {
+ IPinVtbl *vtbl;
+ long ref;
+ libAVFilter *filter;
+ IPin *connectedto;
+ AM_MEDIA_TYPE type;
+ IMemInputPinVtbl *imemvtbl;
+};
+
+long WINAPI libAVPin_QueryInterface (libAVPin *, const GUID *, void **);
+unsigned long WINAPI libAVPin_AddRef (libAVPin *);
+unsigned long WINAPI libAVPin_Release (libAVPin *);
+long WINAPI libAVPin_Connect (libAVPin *, IPin *, const AM_MEDIA_TYPE *);
+long WINAPI libAVPin_ReceiveConnection (libAVPin *, IPin *, const AM_MEDIA_TYPE *);
+long WINAPI libAVPin_Disconnect (libAVPin *);
+long WINAPI libAVPin_ConnectedTo (libAVPin *, IPin **);
+long WINAPI libAVPin_ConnectionMediaType (libAVPin *, AM_MEDIA_TYPE *);
+long WINAPI libAVPin_QueryPinInfo (libAVPin *, PIN_INFO *);
+long WINAPI libAVPin_QueryDirection (libAVPin *, PIN_DIRECTION *);
+long WINAPI libAVPin_QueryId (libAVPin *, wchar_t **);
+long WINAPI libAVPin_QueryAccept (libAVPin *, const AM_MEDIA_TYPE *);
+long WINAPI libAVPin_EnumMediaTypes (libAVPin *, IEnumMediaTypes **);
+long WINAPI libAVPin_QueryInternalConnections(libAVPin *, IPin **, unsigned long *);
+long WINAPI libAVPin_EndOfStream (libAVPin *);
+long WINAPI libAVPin_BeginFlush (libAVPin *);
+long WINAPI libAVPin_EndFlush (libAVPin *);
+long WINAPI libAVPin_NewSegment (libAVPin *, REFERENCE_TIME, REFERENCE_TIME, double);
+
+long WINAPI libAVMemInputPin_QueryInterface (libAVMemInputPin *, const GUID *, void **);
+unsigned long WINAPI libAVMemInputPin_AddRef (libAVMemInputPin *);
+unsigned long WINAPI libAVMemInputPin_Release (libAVMemInputPin *);
+long WINAPI libAVMemInputPin_GetAllocator (libAVMemInputPin *, IMemAllocator **);
+long WINAPI libAVMemInputPin_NotifyAllocator (libAVMemInputPin *, IMemAllocator *, WINBOOL);
+long WINAPI libAVMemInputPin_GetAllocatorRequirements(libAVMemInputPin *, ALLOCATOR_PROPERTIES *);
+long WINAPI libAVMemInputPin_Receive (libAVMemInputPin *, IMediaSample *);
+long WINAPI libAVMemInputPin_ReceiveMultiple (libAVMemInputPin *, IMediaSample **, long, long *);
+long WINAPI libAVMemInputPin_ReceiveCanBlock (libAVMemInputPin *);
+
+void libAVPin_Destroy(libAVPin *);
+libAVPin *libAVPin_Create (libAVFilter *filter);
+
+void libAVMemInputPin_Destroy(libAVMemInputPin *);
+
+/*****************************************************************************
+ * libAVEnumPins
+ ****************************************************************************/
+struct libAVEnumPins {
+ IEnumPinsVtbl *vtbl;
+ long ref;
+ int pos;
+ libAVPin *pin;
+ libAVFilter *filter;
+};
+
+long WINAPI libAVEnumPins_QueryInterface(libAVEnumPins *, const GUID *, void **);
+unsigned long WINAPI libAVEnumPins_AddRef (libAVEnumPins *);
+unsigned long WINAPI libAVEnumPins_Release (libAVEnumPins *);
+long WINAPI libAVEnumPins_Next (libAVEnumPins *, unsigned long, IPin **, unsigned long *);
+long WINAPI libAVEnumPins_Skip (libAVEnumPins *, unsigned long);
+long WINAPI libAVEnumPins_Reset (libAVEnumPins *);
+long WINAPI libAVEnumPins_Clone (libAVEnumPins *, libAVEnumPins **);
+
+void libAVEnumPins_Destroy(libAVEnumPins *);
+libAVEnumPins *libAVEnumPins_Create (libAVPin *pin, libAVFilter *filter);
+
+/*****************************************************************************
+ * libAVEnumMediaTypes
+ ****************************************************************************/
+struct libAVEnumMediaTypes {
+ IEnumPinsVtbl *vtbl;
+ long ref;
+ int pos;
+ AM_MEDIA_TYPE type;
+};
+
+long WINAPI libAVEnumMediaTypes_QueryInterface(libAVEnumMediaTypes *, const GUID *, void **);
+unsigned long WINAPI libAVEnumMediaTypes_AddRef (libAVEnumMediaTypes *);
+unsigned long WINAPI libAVEnumMediaTypes_Release (libAVEnumMediaTypes *);
+long WINAPI libAVEnumMediaTypes_Next (libAVEnumMediaTypes *, unsigned long, AM_MEDIA_TYPE **, unsigned long *);
+long WINAPI libAVEnumMediaTypes_Skip (libAVEnumMediaTypes *, unsigned long);
+long WINAPI libAVEnumMediaTypes_Reset (libAVEnumMediaTypes *);
+long WINAPI libAVEnumMediaTypes_Clone (libAVEnumMediaTypes *, libAVEnumMediaTypes **);
+
+void libAVEnumMediaTypes_Destroy(libAVEnumMediaTypes *);
+libAVEnumMediaTypes *libAVEnumMediaTypes_Create(const AM_MEDIA_TYPE *type);
+
+/*****************************************************************************
+ * libAVFilter
+ ****************************************************************************/
+struct libAVFilter {
+ IBaseFilterVtbl *vtbl;
+ long ref;
+ const wchar_t *name;
+ libAVPin *pin;
+ FILTER_INFO info;
+ FILTER_STATE state;
+ IReferenceClock *clock;
+ enum dshowDeviceType type;
+ void *priv_data;
+ int stream_index;
+ int64_t start_time;
+ void (*callback)(void *priv_data, int index, uint8_t *buf, int buf_size, int64_t time);
+};
+
+long WINAPI libAVFilter_QueryInterface (libAVFilter *, const GUID *, void **);
+unsigned long WINAPI libAVFilter_AddRef (libAVFilter *);
+unsigned long WINAPI libAVFilter_Release (libAVFilter *);
+long WINAPI libAVFilter_GetClassID (libAVFilter *, CLSID *);
+long WINAPI libAVFilter_Stop (libAVFilter *);
+long WINAPI libAVFilter_Pause (libAVFilter *);
+long WINAPI libAVFilter_Run (libAVFilter *, REFERENCE_TIME);
+long WINAPI libAVFilter_GetState (libAVFilter *, DWORD, FILTER_STATE *);
+long WINAPI libAVFilter_SetSyncSource (libAVFilter *, IReferenceClock *);
+long WINAPI libAVFilter_GetSyncSource (libAVFilter *, IReferenceClock **);
+long WINAPI libAVFilter_EnumPins (libAVFilter *, IEnumPins **);
+long WINAPI libAVFilter_FindPin (libAVFilter *, const wchar_t *, IPin **);
+long WINAPI libAVFilter_QueryFilterInfo(libAVFilter *, FILTER_INFO *);
+long WINAPI libAVFilter_JoinFilterGraph(libAVFilter *, IFilterGraph *, const wchar_t *);
+long WINAPI libAVFilter_QueryVendorInfo(libAVFilter *, wchar_t **);
+
+void libAVFilter_Destroy(libAVFilter *);
+libAVFilter *libAVFilter_Create (void *, void *, enum dshowDeviceType);
diff --git a/libavdevice/dshow_common.c b/libavdevice/dshow_common.c
new file mode 100644
index 0000000000..8fe2f77f31
--- /dev/null
+++ b/libavdevice/dshow_common.c
@@ -0,0 +1,190 @@
+/*
+ * Directshow capture interface
+ * Copyright (c) 2010 Ramiro Polla
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "dshow.h"
+
+long ff_copy_dshow_media_type(AM_MEDIA_TYPE *dst, const AM_MEDIA_TYPE *src)
+{
+ uint8_t *pbFormat = NULL;
+
+ if (src->cbFormat) {
+ pbFormat = CoTaskMemAlloc(src->cbFormat);
+ if (!pbFormat)
+ return E_OUTOFMEMORY;
+ memcpy(pbFormat, src->pbFormat, src->cbFormat);
+ }
+
+ *dst = *src;
+ dst->pUnk = NULL;
+ dst->pbFormat = pbFormat;
+
+ return S_OK;
+}
+
+void ff_printGUID(const GUID *g)
+{
+#if DSHOWDEBUG
+ const uint32_t *d = (const uint32_t *) &g->Data1;
+ const uint16_t *w = (const uint16_t *) &g->Data2;
+ const uint8_t *c = (const uint8_t *) &g->Data4;
+
+ dshowdebug("0x%08x 0x%04x 0x%04x %02x%02x%02x%02x%02x%02x%02x%02x",
+ d[0], w[0], w[1],
+ c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7]);
+#endif
+}
+
+static const char *dshow_context_to_name(void *ptr)
+{
+ return "dshow";
+}
+static const AVClass ff_dshow_context_class = { "DirectShow", dshow_context_to_name };
+const AVClass *ff_dshow_context_class_ptr = &ff_dshow_context_class;
+
+#define dstruct(pctx, sname, var, type) \
+ dshowdebug(" "#var":\t%"type"\n", sname->var)
+
+#if DSHOWDEBUG
+static void dump_bih(void *s, BITMAPINFOHEADER *bih)
+{
+ dshowdebug(" BITMAPINFOHEADER\n");
+ dstruct(s, bih, biSize, "lu");
+ dstruct(s, bih, biWidth, "ld");
+ dstruct(s, bih, biHeight, "ld");
+ dstruct(s, bih, biPlanes, "d");
+ dstruct(s, bih, biBitCount, "d");
+ dstruct(s, bih, biCompression, "lu");
+ dshowdebug(" biCompression:\t\"%.4s\"\n",
+ (char*) &bih->biCompression);
+ dstruct(s, bih, biSizeImage, "lu");
+ dstruct(s, bih, biXPelsPerMeter, "lu");
+ dstruct(s, bih, biYPelsPerMeter, "lu");
+ dstruct(s, bih, biClrUsed, "lu");
+ dstruct(s, bih, biClrImportant, "lu");
+}
+#endif
+
+void ff_print_VIDEO_STREAM_CONFIG_CAPS(const VIDEO_STREAM_CONFIG_CAPS *caps)
+{
+#if DSHOWDEBUG
+ dshowdebug(" VIDEO_STREAM_CONFIG_CAPS\n");
+ dshowdebug(" guid\t");
+ ff_printGUID(&caps->guid);
+ dshowdebug("\n");
+ dshowdebug(" VideoStandard\t%lu\n", caps->VideoStandard);
+ dshowdebug(" InputSize %ld\t%ld\n", caps->InputSize.cx, caps->InputSize.cy);
+ dshowdebug(" MinCroppingSize %ld\t%ld\n", caps->MinCroppingSize.cx, caps->MinCroppingSize.cy);
+ dshowdebug(" MaxCroppingSize %ld\t%ld\n", caps->MaxCroppingSize.cx, caps->MaxCroppingSize.cy);
+ dshowdebug(" CropGranularityX\t%d\n", caps->CropGranularityX);
+ dshowdebug(" CropGranularityY\t%d\n", caps->CropGranularityY);
+ dshowdebug(" CropAlignX\t%d\n", caps->CropAlignX);
+ dshowdebug(" CropAlignY\t%d\n", caps->CropAlignY);
+ dshowdebug(" MinOutputSize %ld\t%ld\n", caps->MinOutputSize.cx, caps->MinOutputSize.cy);
+ dshowdebug(" MaxOutputSize %ld\t%ld\n", caps->MaxOutputSize.cx, caps->MaxOutputSize.cy);
+ dshowdebug(" OutputGranularityX\t%d\n", caps->OutputGranularityX);
+ dshowdebug(" OutputGranularityY\t%d\n", caps->OutputGranularityY);
+ dshowdebug(" StretchTapsX\t%d\n", caps->StretchTapsX);
+ dshowdebug(" StretchTapsY\t%d\n", caps->StretchTapsY);
+ dshowdebug(" ShrinkTapsX\t%d\n", caps->ShrinkTapsX);
+ dshowdebug(" ShrinkTapsY\t%d\n", caps->ShrinkTapsY);
+ dshowdebug(" MinFrameInterval\t%"PRId64"\n", caps->MinFrameInterval);
+ dshowdebug(" MaxFrameInterval\t%"PRId64"\n", caps->MaxFrameInterval);
+ dshowdebug(" MinBitsPerSecond\t%ld\n", caps->MinBitsPerSecond);
+ dshowdebug(" MaxBitsPerSecond\t%ld\n", caps->MaxBitsPerSecond);
+#endif
+}
+
+void ff_print_AUDIO_STREAM_CONFIG_CAPS(const AUDIO_STREAM_CONFIG_CAPS *caps)
+{
+#if DSHOWDEBUG
+ dshowdebug(" AUDIO_STREAM_CONFIG_CAPS\n");
+ dshowdebug(" guid\t");
+ ff_printGUID(&caps->guid);
+ dshowdebug("\n");
+ dshowdebug(" MinimumChannels\t%lu\n", caps->MinimumChannels);
+ dshowdebug(" MaximumChannels\t%lu\n", caps->MaximumChannels);
+ dshowdebug(" ChannelsGranularity\t%lu\n", caps->ChannelsGranularity);
+ dshowdebug(" MinimumBitsPerSample\t%lu\n", caps->MinimumBitsPerSample);
+ dshowdebug(" MaximumBitsPerSample\t%lu\n", caps->MaximumBitsPerSample);
+ dshowdebug(" BitsPerSampleGranularity\t%lu\n", caps->BitsPerSampleGranularity);
+ dshowdebug(" MinimumSampleFrequency\t%lu\n", caps->MinimumSampleFrequency);
+ dshowdebug(" MaximumSampleFrequency\t%lu\n", caps->MaximumSampleFrequency);
+ dshowdebug(" SampleFrequencyGranularity\t%lu\n", caps->SampleFrequencyGranularity);
+#endif
+}
+
+void ff_print_AM_MEDIA_TYPE(const AM_MEDIA_TYPE *type)
+{
+#if DSHOWDEBUG
+ dshowdebug(" majortype\t");
+ ff_printGUID(&type->majortype);
+ dshowdebug("\n");
+ dshowdebug(" subtype\t");
+ ff_printGUID(&type->subtype);
+ dshowdebug("\n");
+ dshowdebug(" bFixedSizeSamples\t%d\n", type->bFixedSizeSamples);
+ dshowdebug(" bTemporalCompression\t%d\n", type->bTemporalCompression);
+ dshowdebug(" lSampleSize\t%lu\n", type->lSampleSize);
+ dshowdebug(" formattype\t");
+ ff_printGUID(&type->formattype);
+ dshowdebug("\n");
+ dshowdebug(" pUnk\t%p\n", type->pUnk);
+ dshowdebug(" cbFormat\t%lu\n", type->cbFormat);
+ dshowdebug(" pbFormat\t%p\n", type->pbFormat);
+
+ if (IsEqualGUID(&type->formattype, &FORMAT_VideoInfo)) {
+ VIDEOINFOHEADER *v = (void *) type->pbFormat;
+ dshowdebug(" rcSource: left %ld top %ld right %ld bottom %ld\n",
+ v->rcSource.left, v->rcSource.top, v->rcSource.right, v->rcSource.bottom);
+ dshowdebug(" rcTarget: left %ld top %ld right %ld bottom %ld\n",
+ v->rcTarget.left, v->rcTarget.top, v->rcTarget.right, v->rcTarget.bottom);
+ dshowdebug(" dwBitRate: %lu\n", v->dwBitRate);
+ dshowdebug(" dwBitErrorRate: %lu\n", v->dwBitErrorRate);
+ dshowdebug(" AvgTimePerFrame: %"PRId64"\n", v->AvgTimePerFrame);
+ dump_bih(NULL, &v->bmiHeader);
+ } else if (IsEqualGUID(&type->formattype, &FORMAT_VideoInfo2)) {
+ VIDEOINFOHEADER2 *v = (void *) type->pbFormat;
+ dshowdebug(" rcSource: left %ld top %ld right %ld bottom %ld\n",
+ v->rcSource.left, v->rcSource.top, v->rcSource.right, v->rcSource.bottom);
+ dshowdebug(" rcTarget: left %ld top %ld right %ld bottom %ld\n",
+ v->rcTarget.left, v->rcTarget.top, v->rcTarget.right, v->rcTarget.bottom);
+ dshowdebug(" dwBitRate: %lu\n", v->dwBitRate);
+ dshowdebug(" dwBitErrorRate: %lu\n", v->dwBitErrorRate);
+ dshowdebug(" AvgTimePerFrame: %"PRId64"\n", v->AvgTimePerFrame);
+ dshowdebug(" dwInterlaceFlags: %lu\n", v->dwInterlaceFlags);
+ dshowdebug(" dwCopyProtectFlags: %lu\n", v->dwCopyProtectFlags);
+ dshowdebug(" dwPictAspectRatioX: %lu\n", v->dwPictAspectRatioX);
+ dshowdebug(" dwPictAspectRatioY: %lu\n", v->dwPictAspectRatioY);
+// dshowdebug(" dwReserved1: %lu\n", v->u.dwReserved1); /* mingw-w64 is buggy and doesn't name unnamed unions */
+ dshowdebug(" dwReserved2: %lu\n", v->dwReserved2);
+ dump_bih(NULL, &v->bmiHeader);
+ } else if (IsEqualGUID(&type->formattype, &FORMAT_WaveFormatEx)) {
+ WAVEFORMATEX *fx = (void *) type->pbFormat;
+ dshowdebug(" wFormatTag: %u\n", fx->wFormatTag);
+ dshowdebug(" nChannels: %u\n", fx->nChannels);
+ dshowdebug(" nSamplesPerSec: %lu\n", fx->nSamplesPerSec);
+ dshowdebug(" nAvgBytesPerSec: %lu\n", fx->nAvgBytesPerSec);
+ dshowdebug(" nBlockAlign: %u\n", fx->nBlockAlign);
+ dshowdebug(" wBitsPerSample: %u\n", fx->wBitsPerSample);
+ dshowdebug(" cbSize: %u\n", fx->cbSize);
+ }
+#endif
+}
diff --git a/libavdevice/dshow_enummediatypes.c b/libavdevice/dshow_enummediatypes.c
new file mode 100644
index 0000000000..a700133ba6
--- /dev/null
+++ b/libavdevice/dshow_enummediatypes.c
@@ -0,0 +1,103 @@
+/*
+ * DirectShow capture interface
+ * Copyright (c) 2010 Ramiro Polla
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "dshow.h"
+
+DECLARE_QUERYINTERFACE(libAVEnumMediaTypes,
+ { {&IID_IUnknown,0}, {&IID_IEnumPins,0} })
+DECLARE_ADDREF(libAVEnumMediaTypes)
+DECLARE_RELEASE(libAVEnumMediaTypes)
+
+long WINAPI
+libAVEnumMediaTypes_Next(libAVEnumMediaTypes *this, unsigned long n,
+ AM_MEDIA_TYPE **types, unsigned long *fetched)
+{
+ int count = 0;
+ dshowdebug("libAVEnumMediaTypes_Next(%p)\n", this);
+ if (!types)
+ return E_POINTER;
+ if (!this->pos && n == 1) {
+ if (!IsEqualGUID(&this->type.majortype, &GUID_NULL)) {
+ AM_MEDIA_TYPE *type = av_malloc(sizeof(AM_MEDIA_TYPE));
+ ff_copy_dshow_media_type(type, &this->type);
+ *types = type;
+ count = 1;
+ }
+ this->pos = 1;
+ }
+ if (fetched)
+ *fetched = count;
+ if (!count)
+ return S_FALSE;
+ return S_OK;
+}
+long WINAPI
+libAVEnumMediaTypes_Skip(libAVEnumMediaTypes *this, unsigned long n)
+{
+ dshowdebug("libAVEnumMediaTypes_Skip(%p)\n", this);
+ if (n) /* Any skip will always fall outside of the only valid type. */
+ return S_FALSE;
+ return S_OK;
+}
+long WINAPI
+libAVEnumMediaTypes_Reset(libAVEnumMediaTypes *this)
+{
+ dshowdebug("libAVEnumMediaTypes_Reset(%p)\n", this);
+ this->pos = 0;
+ return S_OK;
+}
+long WINAPI
+libAVEnumMediaTypes_Clone(libAVEnumMediaTypes *this, libAVEnumMediaTypes **enums)
+{
+ libAVEnumMediaTypes *new;
+ dshowdebug("libAVEnumMediaTypes_Clone(%p)\n", this);
+ if (!enums)
+ return E_POINTER;
+ new = libAVEnumMediaTypes_Create(&this->type);
+ if (!new)
+ return E_OUTOFMEMORY;
+ new->pos = this->pos;
+ *enums = new;
+ return S_OK;
+}
+
+static int
+libAVEnumMediaTypes_Setup(libAVEnumMediaTypes *this, const AM_MEDIA_TYPE *type)
+{
+ IEnumPinsVtbl *vtbl = this->vtbl;
+ SETVTBL(vtbl, libAVEnumMediaTypes, QueryInterface);
+ SETVTBL(vtbl, libAVEnumMediaTypes, AddRef);
+ SETVTBL(vtbl, libAVEnumMediaTypes, Release);
+ SETVTBL(vtbl, libAVEnumMediaTypes, Next);
+ SETVTBL(vtbl, libAVEnumMediaTypes, Skip);
+ SETVTBL(vtbl, libAVEnumMediaTypes, Reset);
+ SETVTBL(vtbl, libAVEnumMediaTypes, Clone);
+
+ if (!type) {
+ this->type.majortype = GUID_NULL;
+ } else {
+ ff_copy_dshow_media_type(&this->type, type);
+ }
+
+ return 1;
+}
+DECLARE_CREATE(libAVEnumMediaTypes, libAVEnumMediaTypes_Setup(this, type), const AM_MEDIA_TYPE *type)
+DECLARE_DESTROY(libAVEnumMediaTypes, nothing)
diff --git a/libavdevice/dshow_enumpins.c b/libavdevice/dshow_enumpins.c
new file mode 100644
index 0000000000..02e967ae63
--- /dev/null
+++ b/libavdevice/dshow_enumpins.c
@@ -0,0 +1,105 @@
+/*
+ * DirectShow capture interface
+ * Copyright (c) 2010 Ramiro Polla
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "dshow.h"
+
+DECLARE_QUERYINTERFACE(libAVEnumPins,
+ { {&IID_IUnknown,0}, {&IID_IEnumPins,0} })
+DECLARE_ADDREF(libAVEnumPins)
+DECLARE_RELEASE(libAVEnumPins)
+
+long WINAPI
+libAVEnumPins_Next(libAVEnumPins *this, unsigned long n, IPin **pins,
+ unsigned long *fetched)
+{
+ int count = 0;
+ dshowdebug("libAVEnumPins_Next(%p)\n", this);
+ if (!pins)
+ return E_POINTER;
+ if (!this->pos && n == 1) {
+ libAVPin_AddRef(this->pin);
+ *pins = (IPin *) this->pin;
+ count = 1;
+ this->pos = 1;
+ }
+ if (fetched)
+ *fetched = count;
+ if (!count)
+ return S_FALSE;
+ return S_OK;
+}
+long WINAPI
+libAVEnumPins_Skip(libAVEnumPins *this, unsigned long n)
+{
+ dshowdebug("libAVEnumPins_Skip(%p)\n", this);
+ if (n) /* Any skip will always fall outside of the only valid pin. */
+ return S_FALSE;
+ return S_OK;
+}
+long WINAPI
+libAVEnumPins_Reset(libAVEnumPins *this)
+{
+ dshowdebug("libAVEnumPins_Reset(%p)\n", this);
+ this->pos = 0;
+ return S_OK;
+}
+long WINAPI
+libAVEnumPins_Clone(libAVEnumPins *this, libAVEnumPins **pins)
+{
+ libAVEnumPins *new;
+ dshowdebug("libAVEnumPins_Clone(%p)\n", this);
+ if (!pins)
+ return E_POINTER;
+ new = libAVEnumPins_Create(this->pin, this->filter);
+ if (!new)
+ return E_OUTOFMEMORY;
+ new->pos = this->pos;
+ *pins = new;
+ return S_OK;
+}
+
+static int
+libAVEnumPins_Setup(libAVEnumPins *this, libAVPin *pin, libAVFilter *filter)
+{
+ IEnumPinsVtbl *vtbl = this->vtbl;
+ SETVTBL(vtbl, libAVEnumPins, QueryInterface);
+ SETVTBL(vtbl, libAVEnumPins, AddRef);
+ SETVTBL(vtbl, libAVEnumPins, Release);
+ SETVTBL(vtbl, libAVEnumPins, Next);
+ SETVTBL(vtbl, libAVEnumPins, Skip);
+ SETVTBL(vtbl, libAVEnumPins, Reset);
+ SETVTBL(vtbl, libAVEnumPins, Clone);
+
+ this->pin = pin;
+ this->filter = filter;
+ libAVFilter_AddRef(this->filter);
+
+ return 1;
+}
+static int
+libAVEnumPins_Cleanup(libAVEnumPins *this)
+{
+ libAVFilter_Release(this->filter);
+ return 1;
+}
+DECLARE_CREATE(libAVEnumPins, libAVEnumPins_Setup(this, pin, filter),
+ libAVPin *pin, libAVFilter *filter)
+DECLARE_DESTROY(libAVEnumPins, libAVEnumPins_Cleanup)
diff --git a/libavdevice/dshow_filter.c b/libavdevice/dshow_filter.c
new file mode 100644
index 0000000000..64e8306536
--- /dev/null
+++ b/libavdevice/dshow_filter.c
@@ -0,0 +1,202 @@
+/*
+ * DirectShow capture interface
+ * Copyright (c) 2010 Ramiro Polla
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "dshow.h"
+
+DECLARE_QUERYINTERFACE(libAVFilter,
+ { {&IID_IUnknown,0}, {&IID_IBaseFilter,0} })
+DECLARE_ADDREF(libAVFilter)
+DECLARE_RELEASE(libAVFilter)
+
+long WINAPI
+libAVFilter_GetClassID(libAVFilter *this, CLSID *id)
+{
+ dshowdebug("libAVFilter_GetClassID(%p)\n", this);
+ /* I'm not creating a ClassID just for this. */
+ return E_FAIL;
+}
+long WINAPI
+libAVFilter_Stop(libAVFilter *this)
+{
+ dshowdebug("libAVFilter_Stop(%p)\n", this);
+ this->state = State_Stopped;
+ return S_OK;
+}
+long WINAPI
+libAVFilter_Pause(libAVFilter *this)
+{
+ dshowdebug("libAVFilter_Pause(%p)\n", this);
+ this->state = State_Paused;
+ return S_OK;
+}
+long WINAPI
+libAVFilter_Run(libAVFilter *this, REFERENCE_TIME start)
+{
+ dshowdebug("libAVFilter_Run(%p) %"PRId64"\n", this, start);
+ this->state = State_Running;
+ this->start_time = start;
+ return S_OK;
+}
+long WINAPI
+libAVFilter_GetState(libAVFilter *this, DWORD ms, FILTER_STATE *state)
+{
+ dshowdebug("libAVFilter_GetState(%p)\n", this);
+ if (!state)
+ return E_POINTER;
+ *state = this->state;
+ return S_OK;
+}
+long WINAPI
+libAVFilter_SetSyncSource(libAVFilter *this, IReferenceClock *clock)
+{
+ dshowdebug("libAVFilter_SetSyncSource(%p)\n", this);
+
+ if (this->clock != clock) {
+ if (this->clock)
+ IReferenceClock_Release(this->clock);
+ this->clock = clock;
+ if (clock)
+ IReferenceClock_AddRef(clock);
+ }
+
+ return S_OK;
+}
+long WINAPI
+libAVFilter_GetSyncSource(libAVFilter *this, IReferenceClock **clock)
+{
+ dshowdebug("libAVFilter_GetSyncSource(%p)\n", this);
+
+ if (!clock)
+ return E_POINTER;
+ if (this->clock)
+ IReferenceClock_AddRef(this->clock);
+ *clock = this->clock;
+
+ return S_OK;
+}
+long WINAPI
+libAVFilter_EnumPins(libAVFilter *this, IEnumPins **enumpin)
+{
+ libAVEnumPins *new;
+ dshowdebug("libAVFilter_EnumPins(%p)\n", this);
+
+ if (!enumpin)
+ return E_POINTER;
+ new = libAVEnumPins_Create(this->pin, this);
+ if (!new)
+ return E_OUTOFMEMORY;
+
+ *enumpin = (IEnumPins *) new;
+ return S_OK;
+}
+long WINAPI
+libAVFilter_FindPin(libAVFilter *this, const wchar_t *id, IPin **pin)
+{
+ libAVPin *found = NULL;
+ dshowdebug("libAVFilter_FindPin(%p)\n", this);
+
+ if (!id || !pin)
+ return E_POINTER;
+ if (!wcscmp(id, L"In")) {
+ found = this->pin;
+ libAVPin_AddRef(found);
+ }
+ *pin = (IPin *) found;
+ if (!found)
+ return VFW_E_NOT_FOUND;
+
+ return S_OK;
+}
+long WINAPI
+libAVFilter_QueryFilterInfo(libAVFilter *this, FILTER_INFO *info)
+{
+ dshowdebug("libAVFilter_QueryFilterInfo(%p)\n", this);
+
+ if (!info)
+ return E_POINTER;
+ if (this->info.pGraph)
+ IFilterGraph_AddRef(this->info.pGraph);
+ *info = this->info;
+
+ return S_OK;
+}
+long WINAPI
+libAVFilter_JoinFilterGraph(libAVFilter *this, IFilterGraph *graph,
+ const wchar_t *name)
+{
+ dshowdebug("libAVFilter_JoinFilterGraph(%p)\n", this);
+
+ this->info.pGraph = graph;
+ if (name)
+ wcscpy(this->info.achName, name);
+
+ return S_OK;
+}
+long WINAPI
+libAVFilter_QueryVendorInfo(libAVFilter *this, wchar_t **info)
+{
+ dshowdebug("libAVFilter_QueryVendorInfo(%p)\n", this);
+
+ if (!info)
+ return E_POINTER;
+ *info = wcsdup(L"libAV");
+
+ return S_OK;
+}
+
+static int
+libAVFilter_Setup(libAVFilter *this, void *priv_data, void *callback,
+ enum dshowDeviceType type)
+{
+ IBaseFilterVtbl *vtbl = this->vtbl;
+ SETVTBL(vtbl, libAVFilter, QueryInterface);
+ SETVTBL(vtbl, libAVFilter, AddRef);
+ SETVTBL(vtbl, libAVFilter, Release);
+ SETVTBL(vtbl, libAVFilter, GetClassID);
+ SETVTBL(vtbl, libAVFilter, Stop);
+ SETVTBL(vtbl, libAVFilter, Pause);
+ SETVTBL(vtbl, libAVFilter, Run);
+ SETVTBL(vtbl, libAVFilter, GetState);
+ SETVTBL(vtbl, libAVFilter, SetSyncSource);
+ SETVTBL(vtbl, libAVFilter, GetSyncSource);
+ SETVTBL(vtbl, libAVFilter, EnumPins);
+ SETVTBL(vtbl, libAVFilter, FindPin);
+ SETVTBL(vtbl, libAVFilter, QueryFilterInfo);
+ SETVTBL(vtbl, libAVFilter, JoinFilterGraph);
+ SETVTBL(vtbl, libAVFilter, QueryVendorInfo);
+
+ this->pin = libAVPin_Create(this);
+
+ this->priv_data = priv_data;
+ this->callback = callback;
+ this->type = type;
+
+ return 1;
+}
+static int
+libAVFilter_Cleanup(libAVFilter *this)
+{
+ libAVPin_Release(this->pin);
+ return 1;
+}
+DECLARE_CREATE(libAVFilter, libAVFilter_Setup(this, priv_data, callback, type),
+ void *priv_data, void *callback, enum dshowDeviceType type)
+DECLARE_DESTROY(libAVFilter, libAVFilter_Cleanup)
diff --git a/libavdevice/dshow_pin.c b/libavdevice/dshow_pin.c
new file mode 100644
index 0000000000..5e14108092
--- /dev/null
+++ b/libavdevice/dshow_pin.c
@@ -0,0 +1,362 @@
+/*
+ * DirectShow capture interface
+ * Copyright (c) 2010 Ramiro Polla
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "dshow.h"
+
+#include <stddef.h>
+#define imemoffset offsetof(libAVPin, imemvtbl)
+
+DECLARE_QUERYINTERFACE(libAVPin,
+ { {&IID_IUnknown,0}, {&IID_IPin,0}, {&IID_IMemInputPin,imemoffset} })
+DECLARE_ADDREF(libAVPin)
+DECLARE_RELEASE(libAVPin)
+
+long WINAPI
+libAVPin_Connect(libAVPin *this, IPin *pin, const AM_MEDIA_TYPE *type)
+{
+ dshowdebug("libAVPin_Connect(%p, %p, %p)\n", this, pin, type);
+ /* Input pins receive connections. */
+ return S_FALSE;
+}
+long WINAPI
+libAVPin_ReceiveConnection(libAVPin *this, IPin *pin,
+ const AM_MEDIA_TYPE *type)
+{
+ enum dshowDeviceType devtype = this->filter->type;
+ dshowdebug("libAVPin_ReceiveConnection(%p)\n", this);
+
+ if (!pin)
+ return E_POINTER;
+ if (this->connectedto)
+ return VFW_E_ALREADY_CONNECTED;
+
+ ff_print_AM_MEDIA_TYPE(type);
+ if (devtype == VideoDevice) {
+ if (!IsEqualGUID(&type->majortype, &MEDIATYPE_Video))
+ return VFW_E_TYPE_NOT_ACCEPTED;
+ } else {
+ if (!IsEqualGUID(&type->majortype, &MEDIATYPE_Audio))
+ return VFW_E_TYPE_NOT_ACCEPTED;
+ }
+
+ IPin_AddRef(pin);
+ this->connectedto = pin;
+
+ ff_copy_dshow_media_type(&this->type, type);
+
+ return S_OK;
+}
+long WINAPI
+libAVPin_Disconnect(libAVPin *this)
+{
+ dshowdebug("libAVPin_Disconnect(%p)\n", this);
+
+ if (this->filter->state != State_Stopped)
+ return VFW_E_NOT_STOPPED;
+ if (!this->connectedto)
+ return S_FALSE;
+ IPin_Release(this->connectedto);
+ this->connectedto = NULL;
+
+ return S_OK;
+}
+long WINAPI
+libAVPin_ConnectedTo(libAVPin *this, IPin **pin)
+{
+ dshowdebug("libAVPin_ConnectedTo(%p)\n", this);
+
+ if (!pin)
+ return E_POINTER;
+ if (!this->connectedto)
+ return VFW_E_NOT_CONNECTED;
+ IPin_AddRef(this->connectedto);
+ *pin = this->connectedto;
+
+ return S_OK;
+}
+long WINAPI
+libAVPin_ConnectionMediaType(libAVPin *this, AM_MEDIA_TYPE *type)
+{
+ dshowdebug("libAVPin_ConnectionMediaType(%p)\n", this);
+
+ if (!type)
+ return E_POINTER;
+ if (!this->connectedto)
+ return VFW_E_NOT_CONNECTED;
+
+ return ff_copy_dshow_media_type(type, &this->type);
+}
+long WINAPI
+libAVPin_QueryPinInfo(libAVPin *this, PIN_INFO *info)
+{
+ dshowdebug("libAVPin_QueryPinInfo(%p)\n", this);
+
+ if (!info)
+ return E_POINTER;
+
+ if (this->filter)
+ libAVFilter_AddRef(this->filter);
+
+ info->pFilter = (IBaseFilter *) this->filter;
+ info->dir = PINDIR_INPUT;
+ wcscpy(info->achName, L"Capture");
+
+ return S_OK;
+}
+long WINAPI
+libAVPin_QueryDirection(libAVPin *this, PIN_DIRECTION *dir)
+{
+ dshowdebug("libAVPin_QueryDirection(%p)\n", this);
+ if (!dir)
+ return E_POINTER;
+ *dir = PINDIR_INPUT;
+ return S_OK;
+}
+long WINAPI
+libAVPin_QueryId(libAVPin *this, wchar_t **id)
+{
+ dshowdebug("libAVPin_QueryId(%p)\n", this);
+
+ if (!id)
+ return E_POINTER;
+
+ *id = wcsdup(L"libAV Pin");
+
+ return S_OK;
+}
+long WINAPI
+libAVPin_QueryAccept(libAVPin *this, const AM_MEDIA_TYPE *type)
+{
+ dshowdebug("libAVPin_QueryAccept(%p)\n", this);
+ return S_FALSE;
+}
+long WINAPI
+libAVPin_EnumMediaTypes(libAVPin *this, IEnumMediaTypes **enumtypes)
+{
+ const AM_MEDIA_TYPE *type = NULL;
+ libAVEnumMediaTypes *new;
+ dshowdebug("libAVPin_EnumMediaTypes(%p)\n", this);
+
+ if (!enumtypes)
+ return E_POINTER;
+ new = libAVEnumMediaTypes_Create(type);
+ if (!new)
+ return E_OUTOFMEMORY;
+
+ *enumtypes = (IEnumMediaTypes *) new;
+ return S_OK;
+}
+long WINAPI
+libAVPin_QueryInternalConnections(libAVPin *this, IPin **pin,
+ unsigned long *npin)
+{
+ dshowdebug("libAVPin_QueryInternalConnections(%p)\n", this);
+ return E_NOTIMPL;
+}
+long WINAPI
+libAVPin_EndOfStream(libAVPin *this)
+{
+ dshowdebug("libAVPin_EndOfStream(%p)\n", this);
+ /* I don't care. */
+ return S_OK;
+}
+long WINAPI
+libAVPin_BeginFlush(libAVPin *this)
+{
+ dshowdebug("libAVPin_BeginFlush(%p)\n", this);
+ /* I don't care. */
+ return S_OK;
+}
+long WINAPI
+libAVPin_EndFlush(libAVPin *this)
+{
+ dshowdebug("libAVPin_EndFlush(%p)\n", this);
+ /* I don't care. */
+ return S_OK;
+}
+long WINAPI
+libAVPin_NewSegment(libAVPin *this, REFERENCE_TIME start, REFERENCE_TIME stop,
+ double rate)
+{
+ dshowdebug("libAVPin_NewSegment(%p)\n", this);
+ /* I don't care. */
+ return S_OK;
+}
+
+static int
+libAVPin_Setup(libAVPin *this, libAVFilter *filter)
+{
+ IPinVtbl *vtbl = this->vtbl;
+ IMemInputPinVtbl *imemvtbl;
+
+ if (!filter)
+ return 0;
+
+ imemvtbl = av_malloc(sizeof(IMemInputPinVtbl));
+ if (!imemvtbl)
+ return 0;
+
+ SETVTBL(imemvtbl, libAVMemInputPin, QueryInterface);
+ SETVTBL(imemvtbl, libAVMemInputPin, AddRef);
+ SETVTBL(imemvtbl, libAVMemInputPin, Release);
+ SETVTBL(imemvtbl, libAVMemInputPin, GetAllocator);
+ SETVTBL(imemvtbl, libAVMemInputPin, NotifyAllocator);
+ SETVTBL(imemvtbl, libAVMemInputPin, GetAllocatorRequirements);
+ SETVTBL(imemvtbl, libAVMemInputPin, Receive);
+ SETVTBL(imemvtbl, libAVMemInputPin, ReceiveMultiple);
+ SETVTBL(imemvtbl, libAVMemInputPin, ReceiveCanBlock);
+
+ this->imemvtbl = imemvtbl;
+
+ SETVTBL(vtbl, libAVPin, QueryInterface);
+ SETVTBL(vtbl, libAVPin, AddRef);
+ SETVTBL(vtbl, libAVPin, Release);
+ SETVTBL(vtbl, libAVPin, Connect);
+ SETVTBL(vtbl, libAVPin, ReceiveConnection);
+ SETVTBL(vtbl, libAVPin, Disconnect);
+ SETVTBL(vtbl, libAVPin, ConnectedTo);
+ SETVTBL(vtbl, libAVPin, ConnectionMediaType);
+ SETVTBL(vtbl, libAVPin, QueryPinInfo);
+ SETVTBL(vtbl, libAVPin, QueryDirection);
+ SETVTBL(vtbl, libAVPin, QueryId);
+ SETVTBL(vtbl, libAVPin, QueryAccept);
+ SETVTBL(vtbl, libAVPin, EnumMediaTypes);
+ SETVTBL(vtbl, libAVPin, QueryInternalConnections);
+ SETVTBL(vtbl, libAVPin, EndOfStream);
+ SETVTBL(vtbl, libAVPin, BeginFlush);
+ SETVTBL(vtbl, libAVPin, EndFlush);
+ SETVTBL(vtbl, libAVPin, NewSegment);
+
+ this->filter = filter;
+
+ return 1;
+}
+DECLARE_CREATE(libAVPin, libAVPin_Setup(this, filter), libAVFilter *filter)
+DECLARE_DESTROY(libAVPin, nothing)
+
+/*****************************************************************************
+ * libAVMemInputPin
+ ****************************************************************************/
+long WINAPI
+libAVMemInputPin_QueryInterface(libAVMemInputPin *this, const GUID *riid,
+ void **ppvObject)
+{
+ libAVPin *pin = (libAVPin *) ((uint8_t *) this - imemoffset);
+ dshowdebug("libAVMemInputPin_QueryInterface(%p)\n", this);
+ return libAVPin_QueryInterface(pin, riid, ppvObject);
+}
+unsigned long WINAPI
+libAVMemInputPin_AddRef(libAVMemInputPin *this)
+{
+ libAVPin *pin = (libAVPin *) ((uint8_t *) this - imemoffset);
+ dshowdebug("libAVMemInputPin_AddRef(%p)\n", this);
+ return libAVPin_AddRef(pin);
+}
+unsigned long WINAPI
+libAVMemInputPin_Release(libAVMemInputPin *this)
+{
+ libAVPin *pin = (libAVPin *) ((uint8_t *) this - imemoffset);
+ dshowdebug("libAVMemInputPin_Release(%p)\n", this);
+ return libAVPin_Release(pin);
+}
+long WINAPI
+libAVMemInputPin_GetAllocator(libAVMemInputPin *this, IMemAllocator **alloc)
+{
+ dshowdebug("libAVMemInputPin_GetAllocator(%p)\n", this);
+ return VFW_E_NO_ALLOCATOR;
+}
+long WINAPI
+libAVMemInputPin_NotifyAllocator(libAVMemInputPin *this, IMemAllocator *alloc,
+ WINBOOL rdwr)
+{
+ dshowdebug("libAVMemInputPin_NotifyAllocator(%p)\n", this);
+ return S_OK;
+}
+long WINAPI
+libAVMemInputPin_GetAllocatorRequirements(libAVMemInputPin *this,
+ ALLOCATOR_PROPERTIES *props)
+{
+ dshowdebug("libAVMemInputPin_GetAllocatorRequirements(%p)\n", this);
+ return E_NOTIMPL;
+}
+long WINAPI
+libAVMemInputPin_Receive(libAVMemInputPin *this, IMediaSample *sample)
+{
+ libAVPin *pin = (libAVPin *) ((uint8_t *) this - imemoffset);
+ enum dshowDeviceType devtype = pin->filter->type;
+ void *priv_data;
+ uint8_t *buf;
+ int buf_size;
+ int index;
+ int64_t curtime;
+
+ dshowdebug("libAVMemInputPin_Receive(%p)\n", this);
+
+ if (!sample)
+ return E_POINTER;
+
+ if (devtype == VideoDevice) {
+ /* PTS from video devices is unreliable. */
+ IReferenceClock *clock = pin->filter->clock;
+ IReferenceClock_GetTime(clock, &curtime);
+ } else {
+ int64_t dummy;
+ IMediaSample_GetTime(sample, &curtime, &dummy);
+ curtime += pin->filter->start_time;
+ }
+
+ buf_size = IMediaSample_GetActualDataLength(sample);
+ IMediaSample_GetPointer(sample, &buf);
+ priv_data = pin->filter->priv_data;
+ index = pin->filter->stream_index;
+
+ pin->filter->callback(priv_data, index, buf, buf_size, curtime);
+
+ return S_OK;
+}
+long WINAPI
+libAVMemInputPin_ReceiveMultiple(libAVMemInputPin *this,
+ IMediaSample **samples, long n, long *nproc)
+{
+ int i;
+ dshowdebug("libAVMemInputPin_ReceiveMultiple(%p)\n", this);
+
+ for (i = 0; i < n; i++)
+ libAVMemInputPin_Receive(this, samples[i]);
+
+ *nproc = n;
+ return S_OK;
+}
+long WINAPI
+libAVMemInputPin_ReceiveCanBlock(libAVMemInputPin *this)
+{
+ dshowdebug("libAVMemInputPin_ReceiveCanBlock(%p)\n", this);
+ /* I swear I will not block. */
+ return S_FALSE;
+}
+
+void
+libAVMemInputPin_Destroy(libAVMemInputPin *this)
+{
+ libAVPin *pin = (libAVPin *) ((uint8_t *) this - imemoffset);
+ dshowdebug("libAVMemInputPin_Destroy(%p)\n", this);
+ return libAVPin_Destroy(pin);
+}
diff --git a/libavdevice/dv1394.c b/libavdevice/dv1394.c
index 565cf4cc4e..44d401a99f 100644
--- a/libavdevice/dv1394.c
+++ b/libavdevice/dv1394.c
@@ -2,20 +2,20 @@
* Linux DV1394 interface
* Copyright (c) 2003 Max Krasnyansky <maxk@qualcomm.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -32,7 +32,7 @@
#include "libavutil/log.h"
#include "libavutil/opt.h"
-#include "libavformat/avformat.h"
+#include "avdevice.h"
#include "libavformat/dv.h"
#include "dv1394.h"
@@ -86,22 +86,10 @@ static int dv1394_read_header(AVFormatContext * context, AVFormatParameters * ap
{
struct dv1394_data *dv = context->priv_data;
- dv->dv_demux = dv_init_demux(context);
+ dv->dv_demux = avpriv_dv_init_demux(context);
if (!dv->dv_demux)
goto failed;
-#if FF_API_FORMAT_PARAMETERS
- if (ap->standard) {
- if (!strcasecmp(ap->standard, "pal"))
- dv->format = DV1394_PAL;
- else
- dv->format = DV1394_NTSC;
- }
-
- if (ap->channel)
- dv->channel = ap->channel;
-#endif
-
/* Open and initialize DV1394 device */
dv->fd = open(context->filename, O_RDONLY);
if (dv->fd < 0) {
@@ -136,7 +124,7 @@ static int dv1394_read_packet(AVFormatContext *context, AVPacket *pkt)
struct dv1394_data *dv = context->priv_data;
int size;
- size = dv_get_packet(dv->dv_demux, pkt);
+ size = avpriv_dv_get_packet(dv->dv_demux, pkt);
if (size > 0)
return size;
@@ -198,9 +186,9 @@ restart_poll:
av_dlog(context, "index %d, avail %d, done %d\n", dv->index, dv->avail,
dv->done);
- size = dv_produce_packet(dv->dv_demux, pkt,
+ size = avpriv_dv_produce_packet(dv->dv_demux, pkt,
dv->ring + (dv->index * DV1394_PAL_FRAME_SIZE),
- DV1394_PAL_FRAME_SIZE);
+ DV1394_PAL_FRAME_SIZE, -1);
dv->index = (dv->index + 1) % DV1394_RING_FRAMES;
dv->done++; dv->avail--;
@@ -226,10 +214,10 @@ static int dv1394_close(AVFormatContext * context)
}
static const AVOption options[] = {
- { "standard", "", offsetof(struct dv1394_data, format), FF_OPT_TYPE_INT, {.dbl = DV1394_NTSC}, DV1394_PAL, DV1394_NTSC, AV_OPT_FLAG_DECODING_PARAM, "standard" },
- { "PAL", "", 0, FF_OPT_TYPE_CONST, {.dbl = DV1394_PAL}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" },
- { "NTSC", "", 0, FF_OPT_TYPE_CONST, {.dbl = DV1394_NTSC}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" },
- { "channel", "", offsetof(struct dv1394_data, channel), FF_OPT_TYPE_INT, {.dbl = DV1394_DEFAULT_CHANNEL}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
+ { "standard", "", offsetof(struct dv1394_data, format), AV_OPT_TYPE_INT, {.dbl = DV1394_NTSC}, DV1394_PAL, DV1394_NTSC, AV_OPT_FLAG_DECODING_PARAM, "standard" },
+ { "PAL", "", 0, AV_OPT_TYPE_CONST, {.dbl = DV1394_PAL}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" },
+ { "NTSC", "", 0, AV_OPT_TYPE_CONST, {.dbl = DV1394_NTSC}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" },
+ { "channel", "", offsetof(struct dv1394_data, channel), AV_OPT_TYPE_INT, {.dbl = DV1394_DEFAULT_CHANNEL}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
{ NULL },
};
diff --git a/libavdevice/dv1394.h b/libavdevice/dv1394.h
index 5ccc68a259..00706f7541 100644
--- a/libavdevice/dv1394.h
+++ b/libavdevice/dv1394.h
@@ -8,20 +8,20 @@
* Copyright (C)1999,2000 Sebastien Rougeaux <sebastien.rougeaux@anu.edu.au>
* Peter Schlaile <udbz@rz.uni-karlsruhe.de>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavdevice/fbdev.c b/libavdevice/fbdev.c
index 2f3e0ff937..494d5f00c2 100644
--- a/libavdevice/fbdev.c
+++ b/libavdevice/fbdev.c
@@ -3,20 +3,20 @@
* Copyright (c) 2009 Giliard B. de Freitas <giliarde@gmail.com>
* Copyright (C) 2002 Gunnar Monell <gmo@linux.nu>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -24,7 +24,7 @@
* @file
* Linux framebuffer input device,
* inspired by code from fbgrab.c by Gunnar Monell.
- * See also http://linux-fbdev.sourceforge.net/.
+ * @see http://linux-fbdev.sourceforge.net/
*/
/* #define DEBUG */
@@ -42,7 +42,7 @@
#include "libavutil/opt.h"
#include "libavutil/parseutils.h"
#include "libavutil/pixdesc.h"
-#include "libavformat/avformat.h"
+#include "avdevice.h"
struct rgb_pixfmt_map_entry {
int bits_per_pixel;
@@ -84,7 +84,7 @@ typedef struct {
int64_t time_frame; ///< time for the next frame to output (in 1/1000000 units)
int fd; ///< framebuffer device file descriptor
- int width, heigth; ///< assumed frame resolution
+ int width, height; ///< assumed frame resolution
int frame_linesize; ///< linesize of the output frame, it is assumed to be constant
int bytes_per_pixel;
@@ -107,12 +107,8 @@ av_cold static int fbdev_read_header(AVFormatContext *avctx,
av_log(avctx, AV_LOG_ERROR, "Could not parse framerate '%s'.\n", fbdev->framerate);
return ret;
}
-#if FF_API_FORMAT_PARAMETERS
- if (ap->time_base.num)
- fbdev->framerate_q = (AVRational){ap->time_base.den, ap->time_base.num};
-#endif
- if (!(st = av_new_stream(avctx, 0)))
+ if (!(st = avformat_new_stream(avctx, NULL)))
return AVERROR(ENOMEM);
av_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in microseconds */
@@ -151,10 +147,10 @@ av_cold static int fbdev_read_header(AVFormatContext *avctx,
}
fbdev->width = fbdev->varinfo.xres;
- fbdev->heigth = fbdev->varinfo.yres;
+ fbdev->height = fbdev->varinfo.yres;
fbdev->bytes_per_pixel = (fbdev->varinfo.bits_per_pixel + 7) >> 3;
fbdev->frame_linesize = fbdev->width * fbdev->bytes_per_pixel;
- fbdev->frame_size = fbdev->frame_linesize * fbdev->heigth;
+ fbdev->frame_size = fbdev->frame_linesize * fbdev->height;
fbdev->time_frame = AV_NOPTS_VALUE;
fbdev->data = mmap(NULL, fbdev->fixinfo.smem_len, PROT_READ, MAP_SHARED, fbdev->fd, 0);
if (fbdev->data == MAP_FAILED) {
@@ -166,15 +162,15 @@ av_cold static int fbdev_read_header(AVFormatContext *avctx,
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
st->codec->codec_id = CODEC_ID_RAWVIDEO;
st->codec->width = fbdev->width;
- st->codec->height = fbdev->heigth;
+ st->codec->height = fbdev->height;
st->codec->pix_fmt = pix_fmt;
st->codec->time_base = (AVRational){fbdev->framerate_q.den, fbdev->framerate_q.num};
st->codec->bit_rate =
- fbdev->width * fbdev->heigth * fbdev->bytes_per_pixel * av_q2d(fbdev->framerate_q) * 8;
+ fbdev->width * fbdev->height * fbdev->bytes_per_pixel * av_q2d(fbdev->framerate_q) * 8;
av_log(avctx, AV_LOG_INFO,
"w:%d h:%d bpp:%d pixfmt:%s fps:%d/%d bit_rate:%d\n",
- fbdev->width, fbdev->heigth, fbdev->varinfo.bits_per_pixel,
+ fbdev->width, fbdev->height, fbdev->varinfo.bits_per_pixel,
av_pix_fmt_descriptors[pix_fmt].name,
fbdev->framerate_q.num, fbdev->framerate_q.den,
st->codec->bit_rate);
@@ -197,20 +193,22 @@ static int fbdev_read_packet(AVFormatContext *avctx, AVPacket *pkt)
fbdev->time_frame = av_gettime();
/* wait based on the frame rate */
- curtime = av_gettime();
- delay = fbdev->time_frame - curtime;
- av_dlog(avctx,
- "time_frame:%"PRId64" curtime:%"PRId64" delay:%"PRId64"\n",
- fbdev->time_frame, curtime, delay);
- if (delay > 0) {
+ while (1) {
+ curtime = av_gettime();
+ delay = fbdev->time_frame - curtime;
+ av_dlog(avctx,
+ "time_frame:%"PRId64" curtime:%"PRId64" delay:%"PRId64"\n",
+ fbdev->time_frame, curtime, delay);
+ if (delay <= 0) {
+ fbdev->time_frame += INT64_C(1000000) / av_q2d(fbdev->framerate_q);
+ break;
+ }
if (avctx->flags & AVFMT_FLAG_NONBLOCK)
return AVERROR(EAGAIN);
ts.tv_sec = delay / 1000000;
ts.tv_nsec = (delay % 1000000) * 1000;
while (nanosleep(&ts, &ts) < 0 && errno == EINTR);
}
- /* compute the time of the next frame */
- fbdev->time_frame += INT64_C(1000000) / av_q2d(fbdev->framerate_q);
if ((ret = av_new_packet(pkt, fbdev->frame_size)) < 0)
return ret;
@@ -227,8 +225,7 @@ static int fbdev_read_packet(AVFormatContext *avctx, AVPacket *pkt)
fbdev->varinfo.yoffset * fbdev->fixinfo.line_length;
pout = pkt->data;
- // TODO it'd be nice if the lines were aligned
- for (i = 0; i < fbdev->heigth; i++) {
+ for (i = 0; i < fbdev->height; i++) {
memcpy(pout, pin, fbdev->frame_linesize);
pin += fbdev->fixinfo.line_length;
pout += fbdev->frame_linesize;
@@ -250,7 +247,7 @@ av_cold static int fbdev_read_close(AVFormatContext *avctx)
#define OFFSET(x) offsetof(FBDevContext, x)
#define DEC AV_OPT_FLAG_DECODING_PARAM
static const AVOption options[] = {
- { "framerate","", OFFSET(framerate), FF_OPT_TYPE_STRING, {.str = "25"}, 0, 0, DEC },
+ { "framerate","", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0, DEC },
{ NULL },
};
diff --git a/libavdevice/jack_audio.c b/libavdevice/jack_audio.c
index 4af89bda9e..42499d363b 100644
--- a/libavdevice/jack_audio.c
+++ b/libavdevice/jack_audio.c
@@ -3,20 +3,20 @@
* Copyright (c) 2009 Samalyse
* Author: Olivier Guilyardi <olivier samalyse com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -26,9 +26,11 @@
#include "libavutil/log.h"
#include "libavutil/fifo.h"
+#include "libavutil/opt.h"
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
-#include "libavformat/timefilter.h"
+#include "timefilter.h"
+#include "avdevice.h"
/**
* Size of the internal FIFO buffers as a number of audio packets
@@ -36,6 +38,7 @@
#define FIFO_PACKETS_NUM 16
typedef struct {
+ AVClass *class;
jack_client_t * client;
int activated;
sem_t packet_count;
@@ -136,7 +139,7 @@ static int supply_new_packets(JackData *self, AVFormatContext *context)
return 0;
}
-static int start_jack(AVFormatContext *context, AVFormatParameters *params)
+static int start_jack(AVFormatContext *context)
{
JackData *self = context->priv_data;
jack_status_t status;
@@ -153,7 +156,6 @@ static int start_jack(AVFormatContext *context, AVFormatParameters *params)
sem_init(&self->packet_count, 0, 0);
self->sample_rate = jack_get_sample_rate(self->client);
- self->nports = params->channels;
self->ports = av_malloc(self->nports * sizeof(*self->ports));
self->buffer_size = jack_get_buffer_size(self->client);
@@ -225,13 +227,10 @@ static int audio_read_header(AVFormatContext *context, AVFormatParameters *param
AVStream *stream;
int test;
- if (params->sample_rate <= 0 || params->channels <= 0)
- return -1;
-
- if ((test = start_jack(context, params)))
+ if ((test = start_jack(context)))
return test;
- stream = av_new_stream(context, 0);
+ stream = avformat_new_stream(context, NULL);
if (!stream) {
stop_jack(self);
return AVERROR(ENOMEM);
@@ -314,13 +313,26 @@ static int audio_read_close(AVFormatContext *context)
return 0;
}
+#define OFFSET(x) offsetof(JackData, x)
+static const AVOption options[] = {
+ { "channels", "Number of audio channels.", OFFSET(nports), AV_OPT_TYPE_INT, { 2 }, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
+ { NULL },
+};
+
+static const AVClass jack_indev_class = {
+ .class_name = "JACK indev",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
AVInputFormat ff_jack_demuxer = {
- "jack",
- NULL_IF_CONFIG_SMALL("JACK Audio Connection Kit"),
- sizeof(JackData),
- NULL,
- audio_read_header,
- audio_read_packet,
- audio_read_close,
- .flags = AVFMT_NOFILE,
+ .name = "jack",
+ .long_name = NULL_IF_CONFIG_SMALL("JACK Audio Connection Kit"),
+ .priv_data_size = sizeof(JackData),
+ .read_header = audio_read_header,
+ .read_packet = audio_read_packet,
+ .read_close = audio_read_close,
+ .flags = AVFMT_NOFILE,
+ .priv_class = &jack_indev_class,
};
diff --git a/libavdevice/lavfi.c b/libavdevice/lavfi.c
new file mode 100644
index 0000000000..9228156988
--- /dev/null
+++ b/libavdevice/lavfi.c
@@ -0,0 +1,344 @@
+/*
+ * Copyright (c) 2011 Stefano Sabatini
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * libavfilter virtual input device
+ */
+
+/* #define DEBUG */
+
+#include "float.h" /* DBL_MIN, DBL_MAX */
+
+#include "libavutil/log.h"
+#include "libavutil/mem.h"
+#include "libavutil/opt.h"
+#include "libavutil/parseutils.h"
+#include "libavutil/pixdesc.h"
+#include "libavfilter/avfilter.h"
+#include "libavfilter/avfiltergraph.h"
+#include "libavfilter/buffersink.h"
+#include "avdevice.h"
+
+typedef struct {
+ AVClass *class; ///< class for private options
+ char *graph_str;
+ AVFilterGraph *graph;
+ AVFilterContext **sinks;
+ int *sink_stream_map;
+ int *stream_sink_map;
+} LavfiContext;
+
+static int *create_all_formats(int n)
+{
+ int i, j, *fmts, count = 0;
+
+ for (i = 0; i < n; i++)
+ if (!(av_pix_fmt_descriptors[i].flags & PIX_FMT_HWACCEL))
+ count++;
+
+ if (!(fmts = av_malloc((count+1) * sizeof(int))))
+ return NULL;
+ for (j = 0, i = 0; i < n; i++) {
+ if (!(av_pix_fmt_descriptors[i].flags & PIX_FMT_HWACCEL))
+ fmts[j++] = i;
+ }
+ fmts[j] = -1;
+ return fmts;
+}
+
+av_cold static int lavfi_read_close(AVFormatContext *avctx)
+{
+ LavfiContext *lavfi = avctx->priv_data;
+
+ av_freep(&lavfi->sink_stream_map);
+ av_freep(&lavfi->stream_sink_map);
+ avfilter_graph_free(&lavfi->graph);
+
+ return 0;
+}
+
+av_cold static int lavfi_read_header(AVFormatContext *avctx,
+ AVFormatParameters *ap)
+{
+ LavfiContext *lavfi = avctx->priv_data;
+ AVFilterInOut *input_links = NULL, *output_links = NULL, *inout;
+ AVFilter *buffersink, *abuffersink;
+ int *pix_fmts = create_all_formats(PIX_FMT_NB);
+ enum AVMediaType type;
+ int ret = 0, i, n;
+
+#define FAIL(ERR) { ret = ERR; goto end; }
+
+ avfilter_register_all();
+
+ buffersink = avfilter_get_by_name("buffersink");
+ abuffersink = avfilter_get_by_name("abuffersink");
+
+ if (!lavfi->graph_str)
+ lavfi->graph_str = av_strdup(avctx->filename);
+
+ /* parse the graph, create a stream for each open output */
+ if (!(lavfi->graph = avfilter_graph_alloc()))
+ FAIL(AVERROR(ENOMEM));
+
+ if ((ret = avfilter_graph_parse(lavfi->graph, lavfi->graph_str,
+ &input_links, &output_links, avctx)) < 0)
+ FAIL(ret);
+
+ if (input_links) {
+ av_log(avctx, AV_LOG_ERROR,
+ "Open inputs in the filtergraph are not acceptable\n");
+ FAIL(AVERROR(EINVAL));
+ }
+
+ /* count the outputs */
+ for (n = 0, inout = output_links; inout; n++, inout = inout->next);
+
+ if (!(lavfi->sink_stream_map = av_malloc(sizeof(int) * n)))
+ FAIL(AVERROR(ENOMEM));
+ if (!(lavfi->stream_sink_map = av_malloc(sizeof(int) * n)))
+ FAIL(AVERROR(ENOMEM));
+
+ for (i = 0; i < n; i++)
+ lavfi->stream_sink_map[i] = -1;
+
+ /* parse the output link names - they need to be of the form out0, out1, ...
+ * create a mapping between them and the streams */
+ for (i = 0, inout = output_links; inout; i++, inout = inout->next) {
+ int stream_idx;
+ if (!strcmp(inout->name, "out"))
+ stream_idx = 0;
+ else if (sscanf(inout->name, "out%d\n", &stream_idx) != 1) {
+ av_log(avctx, AV_LOG_ERROR,
+ "Invalid outpad name '%s'\n", inout->name);
+ FAIL(AVERROR(EINVAL));
+ }
+
+ if ((unsigned)stream_idx >= n) {
+ av_log(avctx, AV_LOG_ERROR,
+ "Invalid index was specified in output '%s', "
+ "must be a non-negative value < %d\n",
+ inout->name, n);
+ FAIL(AVERROR(EINVAL));
+ }
+
+ /* is a video output? */
+ type = inout->filter_ctx->output_pads[inout->pad_idx].type;
+ if (type != AVMEDIA_TYPE_VIDEO && type != AVMEDIA_TYPE_AUDIO) {
+ av_log(avctx, AV_LOG_ERROR,
+ "Output '%s' is not a video or audio output, not yet supported\n", inout->name);
+ FAIL(AVERROR(EINVAL));
+ }
+
+ if (lavfi->stream_sink_map[stream_idx] != -1) {
+ av_log(avctx, AV_LOG_ERROR,
+ "An with stream index %d was already specified\n",
+ stream_idx);
+ FAIL(AVERROR(EINVAL));
+ }
+ lavfi->sink_stream_map[i] = stream_idx;
+ lavfi->stream_sink_map[stream_idx] = i;
+ }
+
+ /* for each open output create a corresponding stream */
+ for (i = 0, inout = output_links; inout; i++, inout = inout->next) {
+ AVStream *st;
+ if (!(st = av_new_stream(avctx, i)))
+ FAIL(AVERROR(ENOMEM));
+ }
+
+ /* create a sink for each output and connect them to the graph */
+ lavfi->sinks = av_malloc(sizeof(AVFilterContext *) * avctx->nb_streams);
+ if (!lavfi->sinks)
+ FAIL(AVERROR(ENOMEM));
+
+ for (i = 0, inout = output_links; inout; i++, inout = inout->next) {
+ AVFilterContext *sink;
+
+ type = inout->filter_ctx->output_pads[inout->pad_idx].type;
+
+ if (type == AVMEDIA_TYPE_VIDEO && ! buffersink ||
+ type == AVMEDIA_TYPE_AUDIO && ! abuffersink) {
+ av_log(avctx, AV_LOG_ERROR, "Missing required buffersink filter, aborting.\n");
+ FAIL(AVERROR_FILTER_NOT_FOUND);
+ }
+
+ if (type == AVMEDIA_TYPE_VIDEO) {
+ AVBufferSinkParams *buffersink_params = av_buffersink_params_alloc();
+ buffersink_params->pixel_fmts = pix_fmts;
+
+#if FF_API_OLD_VSINK_API
+ ret = avfilter_graph_create_filter(&sink, buffersink,
+ inout->name, NULL,
+ pix_fmts, lavfi->graph);
+#else
+ buffersink_params->pixel_fmts = pix_fmts;
+ ret = avfilter_graph_create_filter(&sink, buffersink,
+ inout->name, NULL,
+ buffersink_params, lavfi->graph);
+#endif
+ av_freep(&buffersink_params);
+
+ if (ret < 0)
+ goto end;
+ } else if (type == AVMEDIA_TYPE_AUDIO) {
+ enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_S16, -1 };
+ const int packing_fmts[] = { AVFILTER_PACKED, -1 };
+ const int64_t *chlayouts = avfilter_all_channel_layouts;
+ AVABufferSinkParams *abuffersink_params = av_abuffersink_params_alloc();
+ abuffersink_params->sample_fmts = sample_fmts;
+ abuffersink_params->packing_fmts = packing_fmts;
+ abuffersink_params->channel_layouts = chlayouts;
+
+ ret = avfilter_graph_create_filter(&sink, abuffersink,
+ inout->name, NULL,
+ abuffersink_params, lavfi->graph);
+ av_free(abuffersink_params);
+ if (ret < 0)
+ goto end;
+ }
+
+ lavfi->sinks[i] = sink;
+ if ((ret = avfilter_link(inout->filter_ctx, inout->pad_idx, sink, 0)) < 0)
+ FAIL(ret);
+ }
+
+ /* configure the graph */
+ if ((ret = avfilter_graph_config(lavfi->graph, avctx)) < 0)
+ FAIL(ret);
+
+ /* fill each stream with the information in the corresponding sink */
+ for (i = 0; i < avctx->nb_streams; i++) {
+ AVFilterLink *link = lavfi->sinks[lavfi->stream_sink_map[i]]->inputs[0];
+ AVStream *st = avctx->streams[i];
+ st->codec->codec_type = link->type;
+ av_set_pts_info(st, 64, link->time_base.num, link->time_base.den);
+ if (link->type == AVMEDIA_TYPE_VIDEO) {
+ st->codec->codec_id = CODEC_ID_RAWVIDEO;
+ st->codec->pix_fmt = link->format;
+ st->codec->time_base = link->time_base;
+ st->codec->width = link->w;
+ st->codec->height = link->h;
+ st ->sample_aspect_ratio =
+ st->codec->sample_aspect_ratio = link->sample_aspect_ratio;
+ } else if (link->type == AVMEDIA_TYPE_AUDIO) {
+ st->codec->codec_id = CODEC_ID_PCM_S16LE;
+ st->codec->channels = av_get_channel_layout_nb_channels(link->channel_layout);
+ st->codec->sample_fmt = link->format;
+ st->codec->sample_rate = link->sample_rate;
+ st->codec->time_base = link->time_base;
+ st->codec->channel_layout = link->channel_layout;
+ }
+ }
+
+end:
+ avfilter_inout_free(&input_links);
+ avfilter_inout_free(&output_links);
+ if (ret < 0)
+ lavfi_read_close(avctx);
+ return ret;
+}
+
+static int lavfi_read_packet(AVFormatContext *avctx, AVPacket *pkt)
+{
+ LavfiContext *lavfi = avctx->priv_data;
+ double min_pts = DBL_MAX;
+ int stream_idx, min_pts_sink_idx = 0;
+ AVFilterBufferRef *ref;
+ AVPicture pict;
+ int ret, i, size;
+
+ /* iterate through all the graph sinks. Select the sink with the
+ * minimum PTS */
+ for (i = 0; i < avctx->nb_streams; i++) {
+ AVRational tb = lavfi->sinks[i]->inputs[0]->time_base;
+ double d;
+ int ret = av_buffersink_get_buffer_ref(lavfi->sinks[i],
+ &ref, AV_BUFFERSINK_FLAG_PEEK);
+ if (ret < 0)
+ return ret;
+ d = av_rescale_q(ref->pts, tb, AV_TIME_BASE_Q);
+ av_dlog(avctx, "sink_idx:%d time:%f\n", i, d);
+
+ if (d < min_pts) {
+ min_pts = d;
+ min_pts_sink_idx = i;
+ }
+ }
+ av_dlog(avctx, "min_pts_sink_idx:%i\n", min_pts_sink_idx);
+
+ av_buffersink_get_buffer_ref(lavfi->sinks[min_pts_sink_idx], &ref, 0);
+ stream_idx = lavfi->sink_stream_map[min_pts_sink_idx];
+
+ if (ref->video) {
+ size = avpicture_get_size(ref->format, ref->video->w, ref->video->h);
+ if ((ret = av_new_packet(pkt, size)) < 0)
+ return ret;
+
+ memcpy(pict.data, ref->data, 4*sizeof(ref->data[0]));
+ memcpy(pict.linesize, ref->linesize, 4*sizeof(ref->linesize[0]));
+
+ avpicture_layout(&pict, ref->format, ref->video->w,
+ ref->video->h, pkt->data, size);
+ } else if (ref->audio) {
+ size = ref->audio->nb_samples *
+ av_get_bytes_per_sample(ref->format) *
+ av_get_channel_layout_nb_channels(ref->audio->channel_layout);
+ if ((ret = av_new_packet(pkt, size)) < 0)
+ return ret;
+ memcpy(pkt->data, ref->data[0], size);
+ }
+
+ pkt->stream_index = stream_idx;
+ pkt->pts = ref->pts;
+ pkt->pos = ref->pos;
+ pkt->size = size;
+ avfilter_unref_buffer(ref);
+
+ return size;
+}
+
+#define OFFSET(x) offsetof(LavfiContext, x)
+
+#define DEC AV_OPT_FLAG_DECODING_PARAM
+
+static const AVOption options[] = {
+ { "graph", "Libavfilter graph", OFFSET(graph_str), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, DEC },
+ { NULL },
+};
+
+static const AVClass lavfi_class = {
+ .class_name = "lavfi indev",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
+AVInputFormat ff_lavfi_demuxer = {
+ .name = "lavfi",
+ .long_name = NULL_IF_CONFIG_SMALL("Libavfilter virtual input device"),
+ .priv_data_size = sizeof(LavfiContext),
+ .read_header = lavfi_read_header,
+ .read_packet = lavfi_read_packet,
+ .read_close = lavfi_read_close,
+ .flags = AVFMT_NOFILE,
+ .priv_class = &lavfi_class,
+};
diff --git a/libavdevice/libcdio.c b/libavdevice/libcdio.c
new file mode 100644
index 0000000000..dbd593dde5
--- /dev/null
+++ b/libavdevice/libcdio.c
@@ -0,0 +1,187 @@
+/*
+ * Copyright (c) 2011 Anton Khirnov <anton@khirnov.net>
+ *
+ * This file is part of Libav.
+ *
+ * Libav 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.
+ *
+ * Libav 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * libcdio CD grabbing
+ */
+
+#include <cdio/cdda.h>
+#include <cdio/paranoia.h>
+
+#include "libavutil/log.h"
+#include "libavutil/mem.h"
+#include "libavutil/opt.h"
+
+#include "libavformat/avformat.h"
+#include "libavformat/internal.h"
+
+/* cdio returns some malloced strings that need to be free()d */
+#undef free
+
+typedef struct CDIOContext {
+ const AVClass *class;
+ cdrom_drive_t *drive;
+ cdrom_paranoia_t *paranoia;
+ int32_t last_sector;
+
+ /* private options */
+ int speed;
+ int paranoia_mode;
+} CDIOContext;
+
+static av_cold int read_header(AVFormatContext *ctx, AVFormatParameters *ap)
+{
+ CDIOContext *s = ctx->priv_data;
+ AVStream *st;
+ int ret, i;
+ char *err = NULL;
+
+ if (!(st = avformat_new_stream(ctx, NULL)))
+ return AVERROR(ENOMEM);
+ s->drive = cdio_cddap_identify(ctx->filename, CDDA_MESSAGE_LOGIT, &err);
+ if (!s->drive) {
+ av_log(ctx, AV_LOG_ERROR, "Could not open drive %s.\n", ctx->filename);
+ return AVERROR(EINVAL);
+ }
+ if (err) {
+ av_log(ctx, AV_LOG_VERBOSE, "%s\n", err);
+ free(err);
+ }
+ if ((ret = cdio_cddap_open(s->drive)) < 0 || !s->drive->opened) {
+ av_log(ctx, AV_LOG_ERROR, "Could not open disk in drive %s.\n", ctx->filename);
+ return AVERROR(EINVAL);
+ }
+
+ cdio_cddap_verbose_set(s->drive, CDDA_MESSAGE_LOGIT, CDDA_MESSAGE_LOGIT);
+ if (s->speed)
+ cdio_cddap_speed_set(s->drive, s->speed);
+
+ s->paranoia = cdio_paranoia_init(s->drive);
+ if (!s->paranoia) {
+ av_log(ctx, AV_LOG_ERROR, "Could not init paranoia.\n");
+ return AVERROR(EINVAL);
+ }
+ cdio_paranoia_modeset(s->paranoia, s->paranoia_mode);
+
+ st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
+ if (s->drive->bigendianp)
+ st->codec->codec_id = CODEC_ID_PCM_S16BE;
+ else
+ st->codec->codec_id = CODEC_ID_PCM_S16LE;
+ st->codec->sample_rate = 44100;
+ st->codec->channels = 2;
+ if (s->drive->audio_last_sector != CDIO_INVALID_LSN &&
+ s->drive->audio_first_sector != CDIO_INVALID_LSN)
+ st->duration = s->drive->audio_last_sector - s->drive->audio_first_sector;
+ else if (s->drive->tracks)
+ st->duration = s->drive->disc_toc[s->drive->tracks].dwStartSector;
+ av_set_pts_info(st, 64, CDIO_CD_FRAMESIZE_RAW, 2*st->codec->channels*st->codec->sample_rate);
+
+ for (i = 0; i < s->drive->tracks; i++) {
+ char title[16];
+ snprintf(title, sizeof(title), "track %02d", s->drive->disc_toc[i].bTrack);
+ avpriv_new_chapter(ctx, i, st->time_base, s->drive->disc_toc[i].dwStartSector,
+ s->drive->disc_toc[i+1].dwStartSector, title);
+ }
+
+ s->last_sector = cdio_cddap_disc_lastsector(s->drive);
+
+ return 0;
+}
+
+static int read_packet(AVFormatContext *ctx, AVPacket *pkt)
+{
+ CDIOContext *s = ctx->priv_data;
+ int ret;
+ uint16_t *buf;
+ char *err = NULL;
+
+ if (ctx->streams[0]->cur_dts > s->last_sector)
+ return AVERROR_EOF;
+
+ buf = cdio_paranoia_read(s->paranoia, NULL);
+ if (!buf)
+ return AVERROR_EOF;
+
+ if (err = cdio_cddap_errors(s->drive)) {
+ av_log(ctx, AV_LOG_ERROR, "%s\n", err);
+ free(err);
+ err = NULL;
+ }
+ if (err = cdio_cddap_messages(s->drive)) {
+ av_log(ctx, AV_LOG_VERBOSE, "%s\n", err);
+ free(err);
+ err = NULL;
+ }
+
+ if ((ret = av_new_packet(pkt, CDIO_CD_FRAMESIZE_RAW)) < 0)
+ return ret;
+ memcpy(pkt->data, buf, CDIO_CD_FRAMESIZE_RAW);
+ return 0;
+}
+
+static av_cold int read_close(AVFormatContext *ctx)
+{
+ CDIOContext *s = ctx->priv_data;
+ cdio_paranoia_free(s->paranoia);
+ cdio_cddap_close(s->drive);
+ return 0;
+}
+
+static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp,
+ int flags)
+{
+ CDIOContext *s = ctx->priv_data;
+ AVStream *st = ctx->streams[0];
+
+ cdio_paranoia_seek(s->paranoia, timestamp, SEEK_SET);
+ st->cur_dts = timestamp;
+ return 0;
+}
+
+#define OFFSET(x) offsetof(CDIOContext, x)
+#define DEC AV_OPT_FLAG_DECODING_PARAM
+static const AVOption options[] = {
+ { "speed", "Drive reading speed.", OFFSET(speed), AV_OPT_TYPE_INT, { 0 }, 0, INT_MAX, DEC },
+ { "paranoia_mode", "Error recovery mode.", OFFSET(paranoia_mode), AV_OPT_TYPE_FLAGS, { 0 }, INT_MIN, INT_MAX, DEC, "paranoia_mode" },
+ { "verify", "Verify data integrity in overlap area", 0, AV_OPT_TYPE_CONST, { PARANOIA_MODE_VERIFY }, 0, 0, DEC, "paranoia_mode" },
+ { "overlap", "Perform overlapped reads.", 0, AV_OPT_TYPE_CONST, { PARANOIA_MODE_OVERLAP }, 0, 0, DEC, "paranoia_mode" },
+ { "neverskip", "Do not skip failed reads.", 0, AV_OPT_TYPE_CONST, { PARANOIA_MODE_NEVERSKIP }, 0, 0, DEC, "paranoia_mode" },
+ { NULL },
+};
+
+static const AVClass libcdio_class = {
+ .class_name = "libcdio indev",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
+AVInputFormat ff_libcdio_demuxer = {
+ .name = "libcdio",
+ .read_header = read_header,
+ .read_packet = read_packet,
+ .read_close = read_close,
+ .read_seek = read_seek,
+ .priv_data_size = sizeof(CDIOContext),
+ .flags = AVFMT_NOFILE,
+ .priv_class = &libcdio_class,
+};
diff --git a/libavdevice/libdc1394.c b/libavdevice/libdc1394.c
index bf4e27e51b..2f3a373114 100644
--- a/libavdevice/libdc1394.c
+++ b/libavdevice/libdc1394.c
@@ -2,63 +2,45 @@
* IIDC1394 grab interface (uses libdc1394 and libraw1394)
* Copyright (c) 2004 Roman Shaposhnik
* Copyright (c) 2008 Alessandro Sappia
+ * Copyright (c) 2011 Martin Lambers
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "config.h"
-#include "libavformat/avformat.h"
#include "libavutil/log.h"
+#include "libavutil/mathematics.h"
#include "libavutil/opt.h"
+#include "avdevice.h"
+
+#include <stdlib.h>
+#include <string.h>
#include "libavutil/parseutils.h"
#include "libavutil/pixdesc.h"
-#if HAVE_LIBDC1394_2
#include <dc1394/dc1394.h>
-#elif HAVE_LIBDC1394_1
-#include <libraw1394/raw1394.h>
-#include <libdc1394/dc1394_control.h>
-
-#define DC1394_VIDEO_MODE_320x240_YUV422 MODE_320x240_YUV422
-#define DC1394_VIDEO_MODE_640x480_YUV411 MODE_640x480_YUV411
-#define DC1394_VIDEO_MODE_640x480_YUV422 MODE_640x480_YUV422
-#define DC1394_FRAMERATE_1_875 FRAMERATE_1_875
-#define DC1394_FRAMERATE_3_75 FRAMERATE_3_75
-#define DC1394_FRAMERATE_7_5 FRAMERATE_7_5
-#define DC1394_FRAMERATE_15 FRAMERATE_15
-#define DC1394_FRAMERATE_30 FRAMERATE_30
-#define DC1394_FRAMERATE_60 FRAMERATE_60
-#define DC1394_FRAMERATE_120 FRAMERATE_120
-#define DC1394_FRAMERATE_240 FRAMERATE_240
-#endif
#undef free
typedef struct dc1394_data {
AVClass *class;
-#if HAVE_LIBDC1394_1
- raw1394handle_t handle;
- dc1394_cameracapture camera;
- int channel;
-#elif HAVE_LIBDC1394_2
dc1394_t *d;
dc1394camera_t *camera;
dc1394video_frame_t *frame;
-#endif
int current_frame;
int frame_rate; /**< frames per 1000 seconds (fps * 1000) */
char *video_size; /**< String describing video size, set by a private option. */
@@ -68,16 +50,21 @@ typedef struct dc1394_data {
AVPacket packet;
} dc1394_data;
-struct dc1394_frame_format {
- int width;
- int height;
- enum PixelFormat pix_fmt;
- int frame_size_id;
-} dc1394_frame_formats[] = {
- { 320, 240, PIX_FMT_UYVY422, DC1394_VIDEO_MODE_320x240_YUV422 },
- { 640, 480, PIX_FMT_UYYVYY411, DC1394_VIDEO_MODE_640x480_YUV411 },
- { 640, 480, PIX_FMT_UYVY422, DC1394_VIDEO_MODE_640x480_YUV422 },
- { 0, 0, 0, 0 } /* gotta be the last one */
+/* The list of color codings that we support.
+ * We assume big endian for the dc1394 16bit modes: libdc1394 never sets the
+ * flag little_endian in dc1394video_frame_t. */
+struct dc1394_color_coding {
+ int pix_fmt;
+ int score;
+ uint32_t coding;
+} dc1394_color_codings[] = {
+ { PIX_FMT_GRAY16BE, 1000, DC1394_COLOR_CODING_MONO16 },
+ { PIX_FMT_RGB48BE, 1100, DC1394_COLOR_CODING_RGB16 },
+ { PIX_FMT_GRAY8, 1200, DC1394_COLOR_CODING_MONO8 },
+ { PIX_FMT_RGB24, 1300, DC1394_COLOR_CODING_RGB8 },
+ { PIX_FMT_UYYVYY411, 1400, DC1394_COLOR_CODING_YUV411 },
+ { PIX_FMT_UYVY422, 1500, DC1394_COLOR_CODING_YUV422 },
+ { PIX_FMT_NONE, 0, 0 } /* gotta be the last one */
};
struct dc1394_frame_rate {
@@ -98,12 +85,9 @@ struct dc1394_frame_rate {
#define OFFSET(x) offsetof(dc1394_data, x)
#define DEC AV_OPT_FLAG_DECODING_PARAM
static const AVOption options[] = {
-#if HAVE_LIBDC1394_1
- { "channel", "", offsetof(dc1394_data, channel), FF_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
-#endif
- { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), FF_OPT_TYPE_STRING, {.str = "qvga"}, 0, 0, DEC },
- { "pixel_format", "", OFFSET(pixel_format), FF_OPT_TYPE_STRING, {.str = "uyvy422"}, 0, 0, DEC },
- { "framerate", "", OFFSET(framerate), FF_OPT_TYPE_STRING, {.str = "ntsc"}, 0, 0, DEC },
+ { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), AV_OPT_TYPE_STRING, {.str = "qvga"}, 0, 0, DEC },
+ { "pixel_format", "", OFFSET(pixel_format), AV_OPT_TYPE_STRING, {.str = "uyvy422"}, 0, 0, DEC },
+ { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = "ntsc"}, 0, 0, DEC },
{ NULL },
};
@@ -114,217 +98,183 @@ static const AVClass libdc1394_class = {
.version = LIBAVUTIL_VERSION_INT,
};
-
-static inline int dc1394_read_common(AVFormatContext *c, AVFormatParameters *ap,
- struct dc1394_frame_format **select_fmt, struct dc1394_frame_rate **select_fps)
+static int dc1394_read_header(AVFormatContext *c, AVFormatParameters * ap)
{
dc1394_data* dc1394 = c->priv_data;
- AVStream* vst;
- struct dc1394_frame_format *fmt;
- struct dc1394_frame_rate *fps;
- enum PixelFormat pix_fmt;
- int width, height;
- AVRational framerate;
- int ret = 0;
-
- if ((pix_fmt = av_get_pix_fmt(dc1394->pixel_format)) == PIX_FMT_NONE) {
- av_log(c, AV_LOG_ERROR, "No such pixel format: %s.\n", dc1394->pixel_format);
- ret = AVERROR(EINVAL);
- goto out;
- }
+ AVStream *vst;
+ const struct dc1394_color_coding *cc;
+ const struct dc1394_frame_rate *fr;
+ dc1394camera_list_t *list;
+ dc1394video_modes_t video_modes;
+ dc1394video_mode_t video_mode;
+ dc1394framerates_t frame_rates;
+ dc1394framerate_t frame_rate;
+ uint32_t dc1394_width, dc1394_height, dc1394_color_coding;
+ int rate, best_rate;
+ int score, max_score;
+ int final_width, final_height, final_pix_fmt, final_frame_rate;
+ int res, i, j;
+ int ret=-1;
- if ((ret = av_parse_video_size(&width, &height, dc1394->video_size)) < 0) {
- av_log(c, AV_LOG_ERROR, "Could not parse video size '%s'.\n", dc1394->video_size);
- goto out;
- }
- if ((ret = av_parse_video_rate(&framerate, dc1394->framerate)) < 0) {
- av_log(c, AV_LOG_ERROR, "Could not parse framerate '%s'.\n", dc1394->framerate);
- goto out;
- }
-#if FF_API_FORMAT_PARAMETERS
- if (ap->width > 0)
- width = ap->width;
- if (ap->height > 0)
- height = ap->height;
- if (ap->pix_fmt)
- pix_fmt = ap->pix_fmt;
- if (ap->time_base.num)
- framerate = (AVRational){ap->time_base.den, ap->time_base.num};
-#endif
- dc1394->frame_rate = av_rescale(1000, framerate.num, framerate.den);
-
- for (fmt = dc1394_frame_formats; fmt->width; fmt++)
- if (fmt->pix_fmt == pix_fmt && fmt->width == width && fmt->height == height)
- break;
-
- for (fps = dc1394_frame_rates; fps->frame_rate; fps++)
- if (fps->frame_rate == dc1394->frame_rate)
- break;
-
- if (!fps->frame_rate || !fmt->width) {
- av_log(c, AV_LOG_ERROR, "Can't find matching camera format for %s, %dx%d@%d:1000fps\n", av_get_pix_fmt_name(pix_fmt),
- width, height, dc1394->frame_rate);
- ret = AVERROR(EINVAL);
+ /* Now let us prep the hardware. */
+ dc1394->d = dc1394_new();
+ dc1394_camera_enumerate (dc1394->d, &list);
+ if ( !list || list->num == 0) {
+ av_log(c, AV_LOG_ERROR, "Unable to look for an IIDC camera\n\n");
goto out;
}
- /* create a video stream */
- vst = av_new_stream(c, 0);
- if (!vst) {
- ret = AVERROR(ENOMEM);
- goto out;
+ /* FIXME: To select a specific camera I need to search in list its guid */
+ dc1394->camera = dc1394_camera_new (dc1394->d, list->ids[0].guid);
+ if (list->num > 1) {
+ av_log(c, AV_LOG_INFO, "Working with the first camera found\n");
}
- av_set_pts_info(vst, 64, 1, 1000);
- vst->codec->codec_type = AVMEDIA_TYPE_VIDEO;
- vst->codec->codec_id = CODEC_ID_RAWVIDEO;
- vst->codec->time_base.den = framerate.num;
- vst->codec->time_base.num = framerate.den;
- vst->codec->width = fmt->width;
- vst->codec->height = fmt->height;
- vst->codec->pix_fmt = fmt->pix_fmt;
-
- /* packet init */
- av_init_packet(&dc1394->packet);
- dc1394->packet.size = avpicture_get_size(fmt->pix_fmt, fmt->width, fmt->height);
- dc1394->packet.stream_index = vst->index;
- dc1394->packet.flags |= AV_PKT_FLAG_KEY;
-
- dc1394->current_frame = 0;
- vst->codec->bit_rate = av_rescale(dc1394->packet.size * 8, fps->frame_rate, 1000);
- *select_fps = fps;
- *select_fmt = fmt;
-out:
- return ret;
-}
-
-#if HAVE_LIBDC1394_1
-static int dc1394_v1_read_header(AVFormatContext *c, AVFormatParameters * ap)
-{
- dc1394_data* dc1394 = c->priv_data;
- AVStream* vst;
- nodeid_t* camera_nodes;
- int res;
- struct dc1394_frame_format *fmt = NULL;
- struct dc1394_frame_rate *fps = NULL;
-
- if (dc1394_read_common(c,ap,&fmt,&fps) != 0)
- return -1;
-
-#if FF_API_FORMAT_PARAMETERS
- if (ap->channel)
- dc1394->channel = ap->channel;
-#endif
+ /* Freeing list of cameras */
+ dc1394_camera_free_list (list);
- /* Now let us prep the hardware. */
- dc1394->handle = dc1394_create_handle(0); /* FIXME: gotta have ap->port */
- if (!dc1394->handle) {
- av_log(c, AV_LOG_ERROR, "Can't acquire dc1394 handle on port %d\n", 0 /* ap->port */);
- goto out;
- }
- camera_nodes = dc1394_get_camera_nodes(dc1394->handle, &res, 1);
- if (!camera_nodes || camera_nodes[dc1394->channel] == DC1394_NO_CAMERA) {
- av_log(c, AV_LOG_ERROR, "There's no IIDC camera on the channel %d\n", dc1394->channel);
- goto out_handle;
- }
- res = dc1394_dma_setup_capture(dc1394->handle, camera_nodes[dc1394->channel],
- 0,
- FORMAT_VGA_NONCOMPRESSED,
- fmt->frame_size_id,
- SPEED_400,
- fps->frame_rate_id, 8, 1,
- c->filename,
- &dc1394->camera);
- dc1394_free_camera_nodes(camera_nodes);
+ /* Get the list of video modes supported by the camera. */
+ res = dc1394_video_get_supported_modes (dc1394->camera, &video_modes);
if (res != DC1394_SUCCESS) {
- av_log(c, AV_LOG_ERROR, "Can't prepare camera for the DMA capture\n");
- goto out_handle;
+ av_log(c, AV_LOG_ERROR, "Could not get video formats.\n");
+ goto out_camera;
}
- res = dc1394_start_iso_transmission(dc1394->handle, dc1394->camera.node);
- if (res != DC1394_SUCCESS) {
- av_log(c, AV_LOG_ERROR, "Can't start isochronous transmission\n");
- goto out_handle_dma;
+ if (dc1394->pixel_format) {
+ if ((ap->pix_fmt = av_get_pix_fmt(dc1394->pixel_format)) == PIX_FMT_NONE) {
+ av_log(c, AV_LOG_ERROR, "No such pixel format: %s.\n", dc1394->pixel_format);
+ ret = AVERROR(EINVAL);
+ goto out;
+ }
}
- return 0;
-
-out_handle_dma:
- dc1394_dma_unlisten(dc1394->handle, &dc1394->camera);
- dc1394_dma_release_camera(dc1394->handle, &dc1394->camera);
-out_handle:
- dc1394_destroy_handle(dc1394->handle);
-out:
- return -1;
-}
-
-static int dc1394_v1_read_packet(AVFormatContext *c, AVPacket *pkt)
-{
- struct dc1394_data *dc1394 = c->priv_data;
- int res;
-
- /* discard stale frame */
- if (dc1394->current_frame++) {
- if (dc1394_dma_done_with_buffer(&dc1394->camera) != DC1394_SUCCESS)
- av_log(c, AV_LOG_ERROR, "failed to release %d frame\n", dc1394->current_frame);
+ if (dc1394->video_size) {
+ if ((ret = av_parse_video_size(&ap->width, &ap->height, dc1394->video_size)) < 0) {
+ av_log(c, AV_LOG_ERROR, "Couldn't parse video size.\n");
+ goto out;
+ }
}
- res = dc1394_dma_single_capture(&dc1394->camera);
-
- if (res == DC1394_SUCCESS) {
- dc1394->packet.data = (uint8_t *)(dc1394->camera.capture_buffer);
- dc1394->packet.pts = (dc1394->current_frame * 1000000) / dc1394->frame_rate;
- res = dc1394->packet.size;
- } else {
- av_log(c, AV_LOG_ERROR, "DMA capture failed\n");
- dc1394->packet.data = NULL;
- res = -1;
+ /* Choose the best mode. */
+ rate = (ap->time_base.num ? av_rescale(1000, ap->time_base.den, ap->time_base.num) : -1);
+ max_score = -1;
+ for (i = 0; i < video_modes.num; i++) {
+ if (video_modes.modes[i] == DC1394_VIDEO_MODE_EXIF
+ || (video_modes.modes[i] >= DC1394_VIDEO_MODE_FORMAT7_MIN
+ && video_modes.modes[i] <= DC1394_VIDEO_MODE_FORMAT7_MAX)) {
+ /* These modes are currently not supported as they would require
+ * much more work. For the remaining modes, the functions
+ * dc1394_get_image_size_from_video_mode and
+ * dc1394_get_color_coding_from_video_mode do not need to query the
+ * camera, and thus cannot fail. */
+ continue;
+ }
+ dc1394_get_color_coding_from_video_mode (NULL, video_modes.modes[i],
+ &dc1394_color_coding);
+ for (cc = dc1394_color_codings; cc->pix_fmt != PIX_FMT_NONE; cc++)
+ if (cc->coding == dc1394_color_coding)
+ break;
+ if (cc->pix_fmt == PIX_FMT_NONE) {
+ /* We currently cannot handle this color coding. */
+ continue;
+ }
+ /* Here we know that the mode is supported. Get its frame size and the list
+ * of frame rates supported by the camera for this mode. This list is sorted
+ * in ascending order according to libdc1394 example programs. */
+ dc1394_get_image_size_from_video_mode (NULL, video_modes.modes[i],
+ &dc1394_width, &dc1394_height);
+ res = dc1394_video_get_supported_framerates (dc1394->camera, video_modes.modes[i],
+ &frame_rates);
+ if (res != DC1394_SUCCESS || frame_rates.num == 0) {
+ av_log(c, AV_LOG_ERROR, "Cannot get frame rates for video mode.\n");
+ goto out_camera;
+ }
+ /* Choose the best frame rate. */
+ best_rate = -1;
+ for (j = 0; j < frame_rates.num; j++) {
+ for (fr = dc1394_frame_rates; fr->frame_rate; fr++) {
+ if (fr->frame_rate_id == frame_rates.framerates[j]) {
+ break;
+ }
+ }
+ if (!fr->frame_rate) {
+ /* This frame rate is not supported. */
+ continue;
+ }
+ best_rate = fr->frame_rate;
+ frame_rate = fr->frame_rate_id;
+ if (ap->time_base.num && rate == fr->frame_rate) {
+ /* This is the requested frame rate. */
+ break;
+ }
+ }
+ if (best_rate == -1) {
+ /* No supported rate found. */
+ continue;
+ }
+ /* Here we know that both the mode and the rate are supported. Compute score. */
+ if (ap->width && ap->height
+ && (dc1394_width == ap->width && dc1394_height == ap->height)) {
+ score = 110000;
+ } else {
+ score = dc1394_width * 10; // 1600 - 16000
+ }
+ if (ap->pix_fmt == cc->pix_fmt) {
+ score += 90000;
+ } else {
+ score += cc->score; // 1000 - 1500
+ }
+ if (ap->time_base.num && rate == best_rate) {
+ score += 70000;
+ } else {
+ score += best_rate / 1000; // 1 - 240
+ }
+ if (score > max_score) {
+ video_mode = video_modes.modes[i];
+ final_width = dc1394_width;
+ final_height = dc1394_height;
+ final_pix_fmt = cc->pix_fmt;
+ final_frame_rate = best_rate;
+ max_score = score;
+ }
+ }
+ if (max_score == -1) {
+ av_log(c, AV_LOG_ERROR, "No suitable video mode / frame rate available.\n");
+ goto out_camera;
+ }
+ if (ap->width && ap->height && !(ap->width == final_width && ap->height == final_height)) {
+ av_log(c, AV_LOG_WARNING, "Requested frame size is not available, using fallback.\n");
+ }
+ if (ap->pix_fmt != PIX_FMT_NONE && ap->pix_fmt != final_pix_fmt) {
+ av_log(c, AV_LOG_WARNING, "Requested pixel format is not supported, using fallback.\n");
+ }
+ if (ap->time_base.num && rate != final_frame_rate) {
+ av_log(c, AV_LOG_WARNING, "Requested frame rate is not available, using fallback.\n");
}
- *pkt = dc1394->packet;
- return res;
-}
-
-static int dc1394_v1_close(AVFormatContext * context)
-{
- struct dc1394_data *dc1394 = context->priv_data;
-
- dc1394_stop_iso_transmission(dc1394->handle, dc1394->camera.node);
- dc1394_dma_unlisten(dc1394->handle, &dc1394->camera);
- dc1394_dma_release_camera(dc1394->handle, &dc1394->camera);
- dc1394_destroy_handle(dc1394->handle);
-
- return 0;
-}
-
-#elif HAVE_LIBDC1394_2
-static int dc1394_v2_read_header(AVFormatContext *c, AVFormatParameters * ap)
-{
- dc1394_data* dc1394 = c->priv_data;
- dc1394camera_list_t *list;
- int res, i;
- struct dc1394_frame_format *fmt = NULL;
- struct dc1394_frame_rate *fps = NULL;
-
- if (dc1394_read_common(c,ap,&fmt,&fps) != 0)
- return -1;
+ /* create a video stream */
+ vst = avformat_new_stream(c, NULL);
+ if (!vst)
+ goto out_camera;
+ av_set_pts_info(vst, 64, 1, 1000);
+ vst->codec->codec_type = AVMEDIA_TYPE_VIDEO;
+ vst->codec->codec_id = CODEC_ID_RAWVIDEO;
+ vst->codec->time_base.den = final_frame_rate;
+ vst->codec->time_base.num = 1000;
+ vst->codec->width = final_width;
+ vst->codec->height = final_height;
+ vst->codec->pix_fmt = final_pix_fmt;
- /* Now let us prep the hardware. */
- dc1394->d = dc1394_new();
- dc1394_camera_enumerate (dc1394->d, &list);
- if ( !list || list->num == 0) {
- av_log(c, AV_LOG_ERROR, "Unable to look for an IIDC camera\n\n");
- goto out;
- }
+ /* packet init */
+ av_init_packet(&dc1394->packet);
+ dc1394->packet.size = avpicture_get_size(final_pix_fmt, final_width, final_height);
+ dc1394->packet.stream_index = vst->index;
+ dc1394->packet.flags |= AV_PKT_FLAG_KEY;
- /* FIXME: To select a specific camera I need to search in list its guid */
- dc1394->camera = dc1394_camera_new (dc1394->d, list->ids[0].guid);
- if (list->num > 1) {
- av_log(c, AV_LOG_INFO, "Working with the first camera found\n");
- }
+ dc1394->current_frame = 0;
+ dc1394->frame_rate = final_frame_rate;
- /* Freeing list of cameras */
- dc1394_camera_free_list (list);
+ vst->codec->bit_rate = av_rescale(dc1394->packet.size * 8, final_frame_rate, 1000);
/* Select MAX Speed possible from the cam */
if (dc1394->camera->bmode_capable>0) {
@@ -342,13 +292,13 @@ static int dc1394_v2_read_header(AVFormatContext *c, AVFormatParameters * ap)
goto out_camera;
}
- if (dc1394_video_set_mode(dc1394->camera, fmt->frame_size_id) != DC1394_SUCCESS) {
+ if (dc1394_video_set_mode(dc1394->camera, video_mode) != DC1394_SUCCESS) {
av_log(c, AV_LOG_ERROR, "Couldn't set video format\n");
goto out_camera;
}
- if (dc1394_video_set_framerate(dc1394->camera,fps->frame_rate_id) != DC1394_SUCCESS) {
- av_log(c, AV_LOG_ERROR, "Couldn't set framerate %d \n",fps->frame_rate);
+ if (dc1394_video_set_framerate(dc1394->camera, frame_rate) != DC1394_SUCCESS) {
+ av_log(c, AV_LOG_ERROR, "Could not set framerate %d.\n", final_frame_rate);
goto out_camera;
}
if (dc1394_capture_setup(dc1394->camera, 10, DC1394_CAPTURE_FLAGS_DEFAULT)!=DC1394_SUCCESS) {
@@ -368,10 +318,10 @@ out_camera:
dc1394_camera_free (dc1394->camera);
out:
dc1394_free(dc1394->d);
- return -1;
+ return ret;
}
-static int dc1394_v2_read_packet(AVFormatContext *c, AVPacket *pkt)
+static int dc1394_read_packet(AVFormatContext *c, AVPacket *pkt)
{
struct dc1394_data *dc1394 = c->priv_data;
int res;
@@ -397,7 +347,7 @@ static int dc1394_v2_read_packet(AVFormatContext *c, AVPacket *pkt)
return res;
}
-static int dc1394_v2_close(AVFormatContext * context)
+static int dc1394_close(AVFormatContext * context)
{
struct dc1394_data *dc1394 = context->priv_data;
@@ -411,25 +361,11 @@ static int dc1394_v2_close(AVFormatContext * context)
AVInputFormat ff_libdc1394_demuxer = {
.name = "libdc1394",
- .long_name = NULL_IF_CONFIG_SMALL("dc1394 v.2 A/V grab"),
- .priv_data_size = sizeof(struct dc1394_data),
- .read_header = dc1394_v2_read_header,
- .read_packet = dc1394_v2_read_packet,
- .read_close = dc1394_v2_close,
- .flags = AVFMT_NOFILE,
- .priv_class = &libdc1394_class,
-};
-
-#endif
-#if HAVE_LIBDC1394_1
-AVInputFormat ff_libdc1394_demuxer = {
- .name = "libdc1394",
- .long_name = NULL_IF_CONFIG_SMALL("dc1394 v.1 A/V grab"),
+ .long_name = NULL_IF_CONFIG_SMALL("dc1394 A/V grab"),
.priv_data_size = sizeof(struct dc1394_data),
- .read_header = dc1394_v1_read_header,
- .read_packet = dc1394_v1_read_packet,
- .read_close = dc1394_v1_close,
+ .read_header = dc1394_read_header,
+ .read_packet = dc1394_read_packet,
+ .read_close = dc1394_close,
.flags = AVFMT_NOFILE,
.priv_class = &libdc1394_class,
};
-#endif
diff --git a/libavdevice/openal-dec.c b/libavdevice/openal-dec.c
new file mode 100644
index 0000000000..1b70525c77
--- /dev/null
+++ b/libavdevice/openal-dec.c
@@ -0,0 +1,250 @@
+/*
+ * Copyright (c) 2011 Jonathan Baldwin
+ *
+ * This file is part of FFmpeg.
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
+ * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/**
+ * @file
+ * OpenAL 1.1 capture device for libavdevice
+ **/
+
+#include <AL/al.h>
+#include <AL/alc.h>
+
+#include "libavutil/opt.h"
+#include "avdevice.h"
+
+typedef struct {
+ AVClass *class;
+ /** OpenAL capture device context. **/
+ ALCdevice *device;
+ /** The number of channels in the captured audio. **/
+ int channels;
+ /** The sample rate (in Hz) of the captured audio. **/
+ int sample_rate;
+ /** The sample size (in bits) of the captured audio. **/
+ int sample_size;
+ /** The OpenAL sample format of the captured audio. **/
+ ALCenum sample_format;
+ /** The number of bytes between two consecutive samples of the same channel/component. **/
+ ALCint sample_step;
+ /** If true, print a list of capture devices on this system and exit. **/
+ int list_devices;
+} al_data;
+
+typedef struct {
+ ALCenum al_fmt;
+ enum CodecID codec_id;
+ int channels;
+} al_format_info;
+
+#define LOWEST_AL_FORMAT FFMIN(FFMIN(AL_FORMAT_MONO8,AL_FORMAT_MONO16),FFMIN(AL_FORMAT_STEREO8,AL_FORMAT_STEREO16))
+
+/**
+ * Get information about an AL_FORMAT value.
+ * @param al_fmt the AL_FORMAT value to find information about.
+ * @return A pointer to a structure containing information about the AL_FORMAT value.
+ */
+static inline al_format_info* get_al_format_info(ALCenum al_fmt)
+{
+ static al_format_info info_table[] = {
+ [AL_FORMAT_MONO8-LOWEST_AL_FORMAT] = {AL_FORMAT_MONO8, CODEC_ID_PCM_U8, 1},
+ [AL_FORMAT_MONO16-LOWEST_AL_FORMAT] = {AL_FORMAT_MONO16, AV_NE (CODEC_ID_PCM_S16BE, CODEC_ID_PCM_S16LE), 1},
+ [AL_FORMAT_STEREO8-LOWEST_AL_FORMAT] = {AL_FORMAT_STEREO8, CODEC_ID_PCM_U8, 2},
+ [AL_FORMAT_STEREO16-LOWEST_AL_FORMAT] = {AL_FORMAT_STEREO16, AV_NE (CODEC_ID_PCM_S16BE, CODEC_ID_PCM_S16LE), 2},
+ };
+
+ return &info_table[al_fmt-LOWEST_AL_FORMAT];
+}
+
+/**
+ * Get the OpenAL error code, translated into an av/errno error code.
+ * @param device The ALC device to check for errors.
+ * @param error_msg_ret A pointer to a char* in which to return the error message, or NULL if desired.
+ * @return The error code, or 0 if there is no error.
+ */
+static inline int al_get_error(ALCdevice *device, const char** error_msg_ret)
+{
+ ALCenum error = alcGetError(device);
+ if (error_msg_ret)
+ *error_msg_ret = (const char*) alcGetString(device, error);
+ switch (error) {
+ case ALC_NO_ERROR:
+ return 0;
+ case ALC_INVALID_DEVICE:
+ return AVERROR(ENODEV);
+ break;
+ case ALC_INVALID_CONTEXT:
+ case ALC_INVALID_ENUM:
+ case ALC_INVALID_VALUE:
+ return AVERROR(EINVAL);
+ break;
+ case ALC_OUT_OF_MEMORY:
+ return AVERROR(ENOMEM);
+ break;
+ default:
+ return AVERROR(EIO);
+ }
+}
+
+/**
+ * Print out a list of OpenAL capture devices on this system.
+ */
+static inline void print_al_capture_devices(void *log_ctx)
+{
+ const char *devices;
+
+ if (!(devices = alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER)))
+ return;
+
+ av_log(log_ctx, AV_LOG_INFO, "List of OpenAL capture devices on this system:\n");
+
+ for (; *devices != '\0'; devices += strlen(devices) + 1)
+ av_log(log_ctx, AV_LOG_INFO, " %s\n", devices);
+}
+
+static int read_header(AVFormatContext *ctx, AVFormatParameters *ap)
+{
+ al_data *ad = ctx->priv_data;
+ static const ALCenum sample_formats[2][2] = {
+ { AL_FORMAT_MONO8, AL_FORMAT_STEREO8 },
+ { AL_FORMAT_MONO16, AL_FORMAT_STEREO16 }
+ };
+ int error = 0;
+ const char *error_msg;
+ AVStream *st = NULL;
+ AVCodecContext *codec = NULL;
+
+ if (ad->list_devices) {
+ print_al_capture_devices(ctx);
+ return AVERROR_EXIT;
+ }
+
+ ad->sample_format = sample_formats[ad->sample_size/8-1][ad->channels-1];
+
+ /* Open device for capture */
+ ad->device =
+ alcCaptureOpenDevice(ctx->filename[0] ? ctx->filename : NULL,
+ ad->sample_rate,
+ ad->sample_format,
+ ad->sample_rate); /* Maximum 1 second of sample data to be read at once */
+
+ if (error = al_get_error(ad->device, &error_msg)) goto fail;
+
+ /* Create stream */
+ if (!(st = av_new_stream(ctx, 0))) {
+ error = AVERROR(ENOMEM);
+ goto fail;
+ }
+
+ /* We work in microseconds */
+ av_set_pts_info(st, 64, 1, 1000000);
+
+ /* Set codec parameters */
+ codec = st->codec;
+ codec->codec_type = AVMEDIA_TYPE_AUDIO;
+ codec->sample_rate = ad->sample_rate;
+ codec->channels = get_al_format_info(ad->sample_format)->channels;
+ codec->codec_id = get_al_format_info(ad->sample_format)->codec_id;
+
+ /* This is needed to read the audio data */
+ ad->sample_step = (av_get_bits_per_sample(get_al_format_info(ad->sample_format)->codec_id) *
+ get_al_format_info(ad->sample_format)->channels) / 8;
+
+ /* Finally, start the capture process */
+ alcCaptureStart(ad->device);
+
+ return 0;
+
+fail:
+ /* Handle failure */
+ if (ad->device)
+ alcCaptureCloseDevice(ad->device);
+ if (error_msg)
+ av_log(ctx, AV_LOG_ERROR, "Cannot open device: %s\n", error_msg);
+ return error;
+}
+
+static int read_packet(AVFormatContext* ctx, AVPacket *pkt)
+{
+ al_data *ad = ctx->priv_data;
+ int error=0;
+ const char *error_msg;
+ ALCint nb_samples;
+
+ /* Get number of samples available */
+ alcGetIntegerv(ad->device, ALC_CAPTURE_SAMPLES, (ALCsizei) sizeof(ALCint), &nb_samples);
+ if (error = al_get_error(ad->device, &error_msg)) goto fail;
+
+ /* Create a packet of appropriate size */
+ av_new_packet(pkt, nb_samples*ad->sample_step);
+ pkt->pts = av_gettime();
+
+ /* Fill the packet with the available samples */
+ alcCaptureSamples(ad->device, pkt->data, nb_samples);
+ if (error = al_get_error(ad->device, &error_msg)) goto fail;
+
+ return pkt->size;
+fail:
+ /* Handle failure */
+ if (pkt->data)
+ av_destruct_packet(pkt);
+ if (error_msg)
+ av_log(ctx, AV_LOG_ERROR, "Error: %s\n", error_msg);
+ return error;
+}
+
+static int read_close(AVFormatContext* ctx)
+{
+ al_data *ad = ctx->priv_data;
+
+ if (ad->device) {
+ alcCaptureStop(ad->device);
+ alcCaptureCloseDevice(ad->device);
+ }
+ return 0;
+}
+
+#define OFFSET(x) offsetof(al_data, x)
+
+static const AVOption options[] = {
+ {"channels", "set number of channels", OFFSET(channels), AV_OPT_TYPE_INT, {.dbl=2}, 1, 2, AV_OPT_FLAG_DECODING_PARAM },
+ {"sample_rate", "set sample rate", OFFSET(sample_rate), AV_OPT_TYPE_INT, {.dbl=44100}, 1, 192000, AV_OPT_FLAG_DECODING_PARAM },
+ {"sample_size", "set sample size", OFFSET(sample_size), AV_OPT_TYPE_INT, {.dbl=16}, 8, 16, AV_OPT_FLAG_DECODING_PARAM },
+ {"list_devices", "list available devices", OFFSET(list_devices), AV_OPT_TYPE_INT, {.dbl=0}, 0, 1, AV_OPT_FLAG_DECODING_PARAM, "list_devices" },
+ {"true", "", 0, AV_OPT_TYPE_CONST, {.dbl=1}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "list_devices" },
+ {"false", "", 0, AV_OPT_TYPE_CONST, {.dbl=0}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "list_devices" },
+ {NULL},
+};
+
+static const AVClass class = {
+ .class_name = "openal",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT
+};
+
+AVInputFormat ff_openal_demuxer = {
+ .name = "openal",
+ .long_name = NULL_IF_CONFIG_SMALL("OpenAL audio capture device"),
+ .priv_data_size = sizeof(al_data),
+ .read_probe = NULL,
+ .read_header = read_header,
+ .read_packet = read_packet,
+ .read_close = read_close,
+ .flags = AVFMT_NOFILE,
+ .priv_class = &class
+};
diff --git a/libavdevice/oss_audio.c b/libavdevice/oss_audio.c
index fcbe26ba93..4432376037 100644
--- a/libavdevice/oss_audio.c
+++ b/libavdevice/oss_audio.c
@@ -2,20 +2,20 @@
* Linux audio play and grab interface
* Copyright (c) 2000, 2001 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -39,7 +39,7 @@
#include "libavutil/log.h"
#include "libavutil/opt.h"
#include "libavcodec/avcodec.h"
-#include "libavformat/avformat.h"
+#include "avdevice.h"
#define AUDIO_BLOCK_SIZE 4096
@@ -80,13 +80,6 @@ static int audio_open(AVFormatContext *s1, int is_output, const char *audio_devi
fcntl(audio_fd, F_SETFL, O_NONBLOCK);
s->frame_size = AUDIO_BLOCK_SIZE;
-#if 0
- tmp = (NB_FRAGMENTS << 16) | FRAGMENT_BITS;
- err = ioctl(audio_fd, SNDCTL_DSP_SETFRAGMENT, &tmp);
- if (err < 0) {
- perror("SNDCTL_DSP_SETFRAGMENT");
- }
-#endif
/* select format : favour native format */
err = ioctl(audio_fd, SNDCTL_DSP_GETFMTS, &tmp);
@@ -216,14 +209,7 @@ static int audio_read_header(AVFormatContext *s1, AVFormatParameters *ap)
AVStream *st;
int ret;
-#if FF_API_FORMAT_PARAMETERS
- if (ap->sample_rate > 0)
- s->sample_rate = ap->sample_rate;
- if (ap->channels > 0)
- s->channels = ap->channels;
-#endif
-
- st = av_new_stream(s1, 0);
+ st = avformat_new_stream(s1, NULL);
if (!st) {
return AVERROR(ENOMEM);
}
@@ -296,8 +282,8 @@ static int audio_read_close(AVFormatContext *s1)
#if CONFIG_OSS_INDEV
static const AVOption options[] = {
- { "sample_rate", "", offsetof(AudioData, sample_rate), FF_OPT_TYPE_INT, {.dbl = 48000}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
- { "channels", "", offsetof(AudioData, channels), FF_OPT_TYPE_INT, {.dbl = 2}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
+ { "sample_rate", "", offsetof(AudioData, sample_rate), AV_OPT_TYPE_INT, {.dbl = 48000}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
+ { "channels", "", offsetof(AudioData, channels), AV_OPT_TYPE_INT, {.dbl = 2}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
{ NULL },
};
@@ -309,33 +295,30 @@ static const AVClass oss_demuxer_class = {
};
AVInputFormat ff_oss_demuxer = {
- "oss",
- NULL_IF_CONFIG_SMALL("Open Sound System capture"),
- sizeof(AudioData),
- NULL,
- audio_read_header,
- audio_read_packet,
- audio_read_close,
- .flags = AVFMT_NOFILE,
- .priv_class = &oss_demuxer_class,
+ .name = "oss",
+ .long_name = NULL_IF_CONFIG_SMALL("Open Sound System capture"),
+ .priv_data_size = sizeof(AudioData),
+ .read_header = audio_read_header,
+ .read_packet = audio_read_packet,
+ .read_close = audio_read_close,
+ .flags = AVFMT_NOFILE,
+ .priv_class = &oss_demuxer_class,
};
#endif
#if CONFIG_OSS_OUTDEV
AVOutputFormat ff_oss_muxer = {
- "oss",
- NULL_IF_CONFIG_SMALL("Open Sound System playback"),
- "",
- "",
- sizeof(AudioData),
+ .name = "oss",
+ .long_name = NULL_IF_CONFIG_SMALL("Open Sound System playback"),
+ .priv_data_size = sizeof(AudioData),
/* XXX: we make the assumption that the soundcard accepts this format */
/* XXX: find better solution with "preinit" method, needed also in
other formats */
- AV_NE(CODEC_ID_PCM_S16BE, CODEC_ID_PCM_S16LE),
- CODEC_ID_NONE,
- audio_write_header,
- audio_write_packet,
- audio_write_trailer,
- .flags = AVFMT_NOFILE,
+ .audio_codec = AV_NE(CODEC_ID_PCM_S16BE, CODEC_ID_PCM_S16LE),
+ .video_codec = CODEC_ID_NONE,
+ .write_header = audio_write_header,
+ .write_packet = audio_write_packet,
+ .write_trailer = audio_write_trailer,
+ .flags = AVFMT_NOFILE,
};
#endif
diff --git a/libavdevice/pulse.c b/libavdevice/pulse.c
new file mode 100644
index 0000000000..058cda1eec
--- /dev/null
+++ b/libavdevice/pulse.c
@@ -0,0 +1,191 @@
+/*
+ * Pulseaudio input
+ * Copyright (c) 2011 Luca Barbato <lu_zero@gentoo.org>
+ *
+ * This file is part of Libav.
+ *
+ * Libav 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.
+ *
+ * Libav 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * Pulseaudio input
+ * @author Luca Barbato <lu_zero@gentoo.org>
+ *
+ * This avdevice decoder allows to capture audio from a Pulseaudio device using
+ * the simple api.
+ */
+
+#include <pulse/simple.h>
+#include <pulse/rtclock.h>
+#include <pulse/error.h>
+
+#include "libavformat/avformat.h"
+#include "libavutil/opt.h"
+
+#define DEFAULT_CODEC_ID AV_NE(CODEC_ID_PCM_S16BE, CODEC_ID_PCM_S16LE)
+
+typedef struct PulseData {
+ AVClass *class;
+ char *server;
+ char *name;
+ char *dev;
+ char *stream_name;
+ int sample_rate;
+ int channels;
+ int frame_size;
+ pa_simple *s;
+ int64_t pts;
+} PulseData;
+
+static pa_sample_format_t codec_id_to_pulse_format(int codec_id) {
+ switch (codec_id) {
+ case CODEC_ID_PCM_U8: return PA_SAMPLE_U8;
+ case CODEC_ID_PCM_ALAW: return PA_SAMPLE_ALAW;
+ case CODEC_ID_PCM_MULAW: return PA_SAMPLE_ULAW;
+ case CODEC_ID_PCM_S16LE: return PA_SAMPLE_S16LE;
+ case CODEC_ID_PCM_S16BE: return PA_SAMPLE_S16BE;
+ case CODEC_ID_PCM_F32LE: return PA_SAMPLE_FLOAT32LE;
+ case CODEC_ID_PCM_F32BE: return PA_SAMPLE_FLOAT32BE;
+ case CODEC_ID_PCM_S32LE: return PA_SAMPLE_S32LE;
+ case CODEC_ID_PCM_S32BE: return PA_SAMPLE_S32BE;
+ case CODEC_ID_PCM_S24LE: return PA_SAMPLE_S24LE;
+ case CODEC_ID_PCM_S24BE: return PA_SAMPLE_S24BE;
+ default: return PA_SAMPLE_INVALID;
+ }
+}
+
+static av_cold int pulse_read_header(AVFormatContext *s,
+ AVFormatParameters *ap)
+{
+ PulseData *pd = s->priv_data;
+ AVStream *st;
+ int ret;
+ enum CodecID codec_id =
+ s->audio_codec_id == CODEC_ID_NONE ? DEFAULT_CODEC_ID : s->audio_codec_id;
+ const pa_sample_spec ss = { codec_id_to_pulse_format(codec_id),
+ pd->sample_rate,
+ pd->channels };
+
+ pa_buffer_attr attr = { -1 };
+
+ st = avformat_new_stream(s, NULL);
+
+ if (!st) {
+ av_log(s, AV_LOG_ERROR, "Cannot add stream\n");
+ return AVERROR(ENOMEM);
+ }
+
+ attr.fragsize = pd->frame_size * 4;
+
+ pd->s = pa_simple_new(pd->server, pd->name,
+ PA_STREAM_RECORD,
+ pd->dev, pd->stream_name, &ss,
+ NULL, &attr, &ret);
+ if (!pd->s) {
+ av_log(s, AV_LOG_ERROR, "pa_simple_new failed: %s\n",
+ pa_strerror(ret));
+ return AVERROR(EIO);
+ }
+ /* take real parameters */
+ st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
+ st->codec->codec_id = codec_id;
+ st->codec->sample_rate = pd->sample_rate;
+ st->codec->channels = pd->channels;
+ av_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */
+
+ return 0;
+}
+
+static int pulse_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ PulseData *pd = s->priv_data;
+ int res;
+ pa_usec_t latency, cur;
+ uint64_t frame_duration =
+ (pd->frame_size*1000000LL)/(pd->sample_rate * pd->channels);
+
+ if (av_new_packet(pkt, pd->frame_size) < 0) {
+ return AVERROR(ENOMEM);
+ }
+
+ cur = pa_rtclock_now();
+
+ if ((pa_simple_read(pd->s, pkt->data, pkt->size, &res)) < 0) {
+ av_log(s, AV_LOG_ERROR, "pa_simple_read failed: %s\n",
+ pa_strerror(res));
+ av_free_packet(pkt);
+ return AVERROR(EIO);
+ }
+
+ if ((latency = pa_simple_get_latency(pd->s, &res)) == (pa_usec_t) -1) {
+ av_log(s, AV_LOG_ERROR, "pa_simple_get_latency() failed: %s\n",
+ pa_strerror(res));
+ return AVERROR(EIO);
+ }
+
+ if (!pd->pts) {
+ pd->pts -= latency;
+ }
+
+ pd->pts += frame_duration;
+
+ av_log(s, AV_LOG_DEBUG, "%"PRId64" time %"PRId64","
+ " latency %"PRId64", %"PRId64"\n",
+ av_gettime(), cur, latency, pd->pts);
+
+ pkt->pts = pd->pts;
+
+ return 0;
+}
+
+static av_cold int pulse_close(AVFormatContext *s)
+{
+ PulseData *pd = s->priv_data;
+ pa_simple_free(pd->s);
+ return 0;
+}
+
+#define OFFSET(a) offsetof(PulseData, a)
+#define D AV_OPT_FLAG_DECODING_PARAM
+
+static const AVOption options[] = {
+ { "server", "pulse server name", OFFSET(server), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, D },
+ { "name", "application name", OFFSET(name), AV_OPT_TYPE_STRING, {.str = "ffmpeg"}, 0, 0, D },
+ { "dev", "device to use", OFFSET(dev), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, D },
+ { "stream_name", "stream description", OFFSET(stream_name), AV_OPT_TYPE_STRING, {.str = "record"}, 0, 0, D },
+ { "sample_rate", "", OFFSET(sample_rate), AV_OPT_TYPE_INT, {.dbl = 48000}, 1, INT_MAX, D },
+ { "channels", "", OFFSET(channels), AV_OPT_TYPE_INT, {.dbl = 2}, 1, INT_MAX, D },
+ { "frame_size", "", OFFSET(frame_size), AV_OPT_TYPE_INT, {.dbl = 1024}, 1, INT_MAX, D },
+ { NULL },
+};
+
+static const AVClass pulse_demuxer_class = {
+ .class_name = "Pulse demuxer",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
+AVInputFormat ff_pulse_demuxer = {
+ .name = "pulse",
+ .long_name = NULL_IF_CONFIG_SMALL("Pulse audio input"),
+ .priv_data_size = sizeof(PulseData),
+ .read_header = pulse_read_header,
+ .read_packet = pulse_read_packet,
+ .read_close = pulse_close,
+ .flags = AVFMT_NOFILE,
+ .priv_class = &pulse_demuxer_class,
+};
diff --git a/libavdevice/sdl.c b/libavdevice/sdl.c
new file mode 100644
index 0000000000..5bd219dcd2
--- /dev/null
+++ b/libavdevice/sdl.c
@@ -0,0 +1,230 @@
+/*
+ * Copyright (c) 2011 Stefano Sabatini
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * libSDL output device
+ */
+
+#include <SDL.h>
+#include "libavutil/avstring.h"
+#include "libavutil/opt.h"
+#include "libavutil/parseutils.h"
+#include "libavutil/pixdesc.h"
+#include "avdevice.h"
+
+typedef struct {
+ AVClass *class;
+ SDL_Surface *surface;
+ SDL_Overlay *overlay;
+ char *window_title;
+ char *icon_title;
+ char *window_size;
+ int window_width, window_height;
+ int overlay_width, overlay_height;
+ int overlay_fmt;
+ int sdl_was_already_inited;
+} SDLContext;
+
+struct sdl_overlay_pix_fmt_entry {
+ enum PixelFormat pix_fmt; int overlay_fmt;
+} sdl_overlay_pix_fmt_map[] = {
+ { PIX_FMT_YUV420P, SDL_IYUV_OVERLAY },
+ { PIX_FMT_YUYV422, SDL_YUY2_OVERLAY },
+ { PIX_FMT_UYVY422, SDL_UYVY_OVERLAY },
+ { PIX_FMT_NONE, 0 },
+};
+
+static int sdl_write_trailer(AVFormatContext *s)
+{
+ SDLContext *sdl = s->priv_data;
+
+ av_freep(&sdl->window_title);
+ av_freep(&sdl->icon_title);
+ av_freep(&sdl->window_size);
+
+ if (sdl->overlay) {
+ SDL_FreeYUVOverlay(sdl->overlay);
+ sdl->overlay = NULL;
+ }
+ if (!sdl->sdl_was_already_inited)
+ SDL_Quit();
+
+ return 0;
+}
+
+static int sdl_write_header(AVFormatContext *s)
+{
+ SDLContext *sdl = s->priv_data;
+ AVStream *st = s->streams[0];
+ AVCodecContext *encctx = st->codec;
+ float sar, dar; /* sample and display aspect ratios */
+ int i, ret;
+
+ if (!sdl->window_title)
+ sdl->window_title = av_strdup(s->filename);
+ if (!sdl->icon_title)
+ sdl->icon_title = av_strdup(sdl->window_title);
+
+ if (SDL_WasInit(SDL_INIT_VIDEO)) {
+ av_log(s, AV_LOG_ERROR,
+ "SDL video subsystem was already inited, aborting.\n");
+ sdl->sdl_was_already_inited = 1;
+ ret = AVERROR(EINVAL);
+ goto fail;
+ }
+
+ if (SDL_Init(SDL_INIT_VIDEO) != 0) {
+ av_log(s, AV_LOG_ERROR, "Unable to initialize SDL: %s\n", SDL_GetError());
+ ret = AVERROR(EINVAL);
+ goto fail;
+ }
+
+ if ( s->nb_streams > 1
+ || encctx->codec_type != AVMEDIA_TYPE_VIDEO
+ || encctx->codec_id != CODEC_ID_RAWVIDEO) {
+ av_log(s, AV_LOG_ERROR, "Only supports one rawvideo stream\n");
+ ret = AVERROR(EINVAL);
+ goto fail;
+ }
+
+ for (i = 0; sdl_overlay_pix_fmt_map[i].pix_fmt != PIX_FMT_NONE; i++) {
+ if (sdl_overlay_pix_fmt_map[i].pix_fmt == encctx->pix_fmt) {
+ sdl->overlay_fmt = sdl_overlay_pix_fmt_map[i].overlay_fmt;
+ break;
+ }
+ }
+
+ if (!sdl->overlay_fmt) {
+ av_log(s, AV_LOG_ERROR,
+ "Unsupported pixel format '%s', choose one of yuv420p, yuyv422, or uyvy422.\n",
+ av_get_pix_fmt_name(encctx->pix_fmt));
+ ret = AVERROR(EINVAL);
+ goto fail;
+ }
+
+ if (sdl->window_size) {
+ if (av_parse_video_size(&sdl->window_width, &sdl->window_height,
+ sdl->window_size) < 0) {
+ av_log(s, AV_LOG_ERROR, "Invalid window size '%s'\n", sdl->window_size);
+ ret = AVERROR(EINVAL);
+ goto fail;
+ }
+ }
+
+ /* compute overlay width and height from the codec context information */
+ sar = st->sample_aspect_ratio.num ? av_q2d(st->sample_aspect_ratio) : 1;
+ dar = sar * (float)encctx->width / (float)encctx->height;
+
+ /* we suppose the screen has a 1/1 sample aspect ratio */
+ sdl->overlay_height = encctx->height;
+ sdl->overlay_width = ((int)rint(sdl->overlay_height * dar));
+ if (sdl->overlay_width > encctx->width) {
+ sdl->overlay_width = encctx->width;
+ sdl->overlay_height = ((int)rint(sdl->overlay_width / dar));
+ }
+
+ if (!sdl->window_width || !sdl->window_height) {
+ sdl->window_width = sdl->overlay_width;
+ sdl->window_height = sdl->overlay_height;
+ }
+
+ SDL_WM_SetCaption(sdl->window_title, sdl->icon_title);
+ sdl->surface = SDL_SetVideoMode(sdl->window_width, sdl->window_height,
+ 24, SDL_SWSURFACE);
+ if (!sdl->surface) {
+ av_log(s, AV_LOG_ERROR, "Unable to set video mode: %s\n", SDL_GetError());
+ ret = AVERROR(EINVAL);
+ goto fail;
+ }
+
+ sdl->overlay = SDL_CreateYUVOverlay(sdl->overlay_width, sdl->overlay_height,
+ sdl->overlay_fmt, sdl->surface);
+ if (!sdl->overlay || sdl->overlay->pitches[0] < sdl->overlay_width) {
+ av_log(s, AV_LOG_ERROR,
+ "SDL does not support an overlay with size of %dx%d pixels.\n",
+ sdl->overlay_width, sdl->overlay_height);
+ ret = AVERROR(EINVAL);
+ goto fail;
+ }
+
+ av_log(s, AV_LOG_INFO, "w:%d h:%d fmt:%s sar:%f -> w:%d h:%d\n",
+ encctx->width, encctx->height, av_get_pix_fmt_name(encctx->pix_fmt), sar,
+ sdl->window_width, sdl->window_height);
+ return 0;
+
+fail:
+ sdl_write_trailer(s);
+ return ret;
+}
+
+static int sdl_write_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ SDLContext *sdl = s->priv_data;
+ AVCodecContext *encctx = s->streams[0]->codec;
+ SDL_Rect rect = { 0, 0, sdl->window_width, sdl->window_height };
+ AVPicture pict;
+ int i;
+
+ avpicture_fill(&pict, pkt->data, encctx->pix_fmt, encctx->width, encctx->height);
+
+ SDL_FillRect(sdl->surface, &sdl->surface->clip_rect,
+ SDL_MapRGB(sdl->surface->format, 0, 0, 0));
+ SDL_LockYUVOverlay(sdl->overlay);
+ for (i = 0; i < 3; i++) {
+ sdl->overlay->pixels [i] = pict.data [i];
+ sdl->overlay->pitches[i] = pict.linesize[i];
+ }
+ SDL_DisplayYUVOverlay(sdl->overlay, &rect);
+ SDL_UnlockYUVOverlay(sdl->overlay);
+
+ SDL_UpdateRect(sdl->surface, 0, 0, sdl->overlay_width, sdl->overlay_height);
+
+ return 0;
+}
+
+#define OFFSET(x) offsetof(SDLContext,x)
+
+static const AVOption options[] = {
+ { "window_title", "SDL window title", OFFSET(window_title), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, AV_OPT_FLAG_ENCODING_PARAM },
+ { "icon_title", "SDL iconified window title", OFFSET(icon_title) , AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, AV_OPT_FLAG_ENCODING_PARAM },
+ { "window_size", "SDL window forced size", OFFSET(window_size) , AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, AV_OPT_FLAG_ENCODING_PARAM },
+ { NULL },
+};
+
+static const AVClass sdl_class = {
+ .class_name = "sdl outdev",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
+AVOutputFormat ff_sdl_muxer = {
+ .name = "sdl",
+ .long_name = NULL_IF_CONFIG_SMALL("SDL output device"),
+ .priv_data_size = sizeof(SDLContext),
+ .audio_codec = CODEC_ID_NONE,
+ .video_codec = CODEC_ID_RAWVIDEO,
+ .write_header = sdl_write_header,
+ .write_packet = sdl_write_packet,
+ .write_trailer = sdl_write_trailer,
+ .flags = AVFMT_NOFILE,
+ .priv_class = &sdl_class,
+};
diff --git a/libavdevice/sndio_common.c b/libavdevice/sndio_common.c
index 56c37c76b7..048e72e8a2 100644
--- a/libavdevice/sndio_common.c
+++ b/libavdevice/sndio_common.c
@@ -2,27 +2,27 @@
* sndio play and grab interface
* Copyright (c) 2010 Jacob Meuser
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdint.h>
#include <sndio.h>
-#include "libavformat/avformat.h"
+#include "avdevice.h"
#include "sndio_common.h"
diff --git a/libavdevice/sndio_common.h b/libavdevice/sndio_common.h
index e23b96d146..12218b4b24 100644
--- a/libavdevice/sndio_common.h
+++ b/libavdevice/sndio_common.h
@@ -2,20 +2,20 @@
* sndio play and grab interface
* Copyright (c) 2010 Jacob Meuser
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -25,8 +25,8 @@
#include <stdint.h>
#include <sndio.h>
-#include "libavformat/avformat.h"
#include "libavutil/log.h"
+#include "avdevice.h"
typedef struct {
AVClass *class;
diff --git a/libavdevice/sndio_dec.c b/libavdevice/sndio_dec.c
index 2690ee395c..6d6184c32b 100644
--- a/libavdevice/sndio_dec.c
+++ b/libavdevice/sndio_dec.c
@@ -2,20 +2,20 @@
* sndio play and grab interface
* Copyright (c) 2010 Jacob Meuser
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -34,14 +34,7 @@ static av_cold int audio_read_header(AVFormatContext *s1,
AVStream *st;
int ret;
-#if FF_API_FORMAT_PARAMETERS
- if (ap->sample_rate > 0)
- s->sample_rate = ap->sample_rate;
- if (ap->channels > 0)
- s->channels = ap->channels;
-#endif
-
- st = av_new_stream(s1, 0);
+ st = avformat_new_stream(s1, NULL);
if (!st)
return AVERROR(ENOMEM);
@@ -100,8 +93,8 @@ static av_cold int audio_read_close(AVFormatContext *s1)
}
static const AVOption options[] = {
- { "sample_rate", "", offsetof(SndioData, sample_rate), FF_OPT_TYPE_INT, {.dbl = 48000}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
- { "channels", "", offsetof(SndioData, channels), FF_OPT_TYPE_INT, {.dbl = 2}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
+ { "sample_rate", "", offsetof(SndioData, sample_rate), AV_OPT_TYPE_INT, {.dbl = 48000}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
+ { "channels", "", offsetof(SndioData, channels), AV_OPT_TYPE_INT, {.dbl = 2}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
{ NULL },
};
diff --git a/libavdevice/sndio_enc.c b/libavdevice/sndio_enc.c
index 49a52b355e..9ad5cad08a 100644
--- a/libavdevice/sndio_enc.c
+++ b/libavdevice/sndio_enc.c
@@ -2,28 +2,27 @@
* sndio play and grab interface
* Copyright (c) 2010 Jacob Meuser
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdint.h>
#include <sndio.h>
-#include "libavformat/avformat.h"
-
+#include "avdevice.h"
#include "sndio_common.h"
static av_cold int audio_write_header(AVFormatContext *s1)
diff --git a/libavformat/timefilter.c b/libavdevice/timefilter.c
index 4860a4ff70..3c67a59881 100644
--- a/libavformat/timefilter.c
+++ b/libavdevice/timefilter.c
@@ -5,27 +5,27 @@
* Author: Olivier Guilyardi <olivier samalyse com>
* Michael Niedermayer <michaelni gmx at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "config.h"
-#include "avformat.h"
#include "timefilter.h"
+#include "libavutil/mem.h"
struct TimeFilter {
/// Delay Locked Loop data. These variables refer to mathematical
diff --git a/libavformat/timefilter.h b/libavdevice/timefilter.h
index aa7db533b4..4580904092 100644
--- a/libavformat/timefilter.h
+++ b/libavdevice/timefilter.h
@@ -5,25 +5,25 @@
* Author: Olivier Guilyardi <olivier samalyse com>
* Michael Niedermayer <michaelni gmx at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef AVFORMAT_TIMEFILTER_H
-#define AVFORMAT_TIMEFILTER_H
+#ifndef AVDEVICE_TIMEFILTER_H
+#define AVDEVICE_TIMEFILTER_H
/**
* Opaque type representing a time filter state
@@ -94,4 +94,4 @@ void ff_timefilter_reset(TimeFilter *);
*/
void ff_timefilter_destroy(TimeFilter *);
-#endif /* AVFORMAT_TIMEFILTER_H */
+#endif /* AVDEVICE_TIMEFILTER_H */
diff --git a/libavdevice/v4l.c b/libavdevice/v4l.c
index 1be7adf49d..7c8b3971ea 100644
--- a/libavdevice/v4l.c
+++ b/libavdevice/v4l.c
@@ -2,20 +2,20 @@
* Linux video grab interface
* Copyright (c) 2000,2001 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -29,7 +29,6 @@
#include "libavutil/imgutils.h"
#include "libavutil/log.h"
#include "libavutil/opt.h"
-#include "libavformat/avformat.h"
#include "libavcodec/dsputil.h"
#include <unistd.h>
#include <fcntl.h>
@@ -40,6 +39,7 @@
#include <linux/videodev.h>
#include <time.h>
#include <strings.h>
+#include "avdevice.h"
typedef struct {
AVClass *class;
@@ -98,7 +98,7 @@ static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap)
s->video_win.width = ap->width;
s->video_win.height = ap->height;
- st = av_new_stream(s1, 0);
+ st = avformat_new_stream(s1, NULL);
if (!st)
return AVERROR(ENOMEM);
av_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */
@@ -142,16 +142,6 @@ static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap)
/* set tv standard */
if (!ioctl(video_fd, VIDIOCGTUNER, &tuner)) {
-#if FF_API_FORMAT_PARAMETERS
- if (ap->standard) {
- if (!strcasecmp(ap->standard, "pal"))
- s->standard = VIDEO_MODE_PAL;
- else if (!strcasecmp(ap->standard, "secam"))
- s->standard = VIDEO_MODE_SECAM;
- else
- s->standard = VIDEO_MODE_NTSC;
- }
-#endif
tuner.mode = s->standard;
ioctl(video_fd, VIDIOCSTUNER, &tuner);
}
@@ -349,10 +339,10 @@ static int grab_read_close(AVFormatContext *s1)
}
static const AVOption options[] = {
- { "standard", "", offsetof(VideoData, standard), FF_OPT_TYPE_INT, {.dbl = VIDEO_MODE_NTSC}, VIDEO_MODE_PAL, VIDEO_MODE_NTSC, AV_OPT_FLAG_DECODING_PARAM, "standard" },
- { "PAL", "", 0, FF_OPT_TYPE_CONST, {.dbl = VIDEO_MODE_PAL}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" },
- { "SECAM", "", 0, FF_OPT_TYPE_CONST, {.dbl = VIDEO_MODE_SECAM}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" },
- { "NTSC", "", 0, FF_OPT_TYPE_CONST, {.dbl = VIDEO_MODE_NTSC}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" },
+ { "standard", "", offsetof(VideoData, standard), AV_OPT_TYPE_INT, {.dbl = VIDEO_MODE_NTSC}, VIDEO_MODE_PAL, VIDEO_MODE_NTSC, AV_OPT_FLAG_DECODING_PARAM, "standard" },
+ { "PAL", "", 0, AV_OPT_TYPE_CONST, {.dbl = VIDEO_MODE_PAL}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" },
+ { "SECAM", "", 0, AV_OPT_TYPE_CONST, {.dbl = VIDEO_MODE_SECAM}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" },
+ { "NTSC", "", 0, AV_OPT_TYPE_CONST, {.dbl = VIDEO_MODE_NTSC}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" },
{ NULL },
};
@@ -364,14 +354,13 @@ static const AVClass v4l_class = {
};
AVInputFormat ff_v4l_demuxer = {
- "video4linux",
- NULL_IF_CONFIG_SMALL("Video4Linux device grab"),
- sizeof(VideoData),
- NULL,
- grab_read_header,
- grab_read_packet,
- grab_read_close,
- .flags = AVFMT_NOFILE,
- .priv_class = &v4l_class,
+ .name = "video4linux",
+ .long_name = NULL_IF_CONFIG_SMALL("Video4Linux device grab"),
+ .priv_data_size = sizeof(VideoData),
+ .read_header = grab_read_header,
+ .read_packet = grab_read_packet,
+ .read_close = grab_read_close,
+ .flags = AVFMT_NOFILE,
+ .priv_class = &v4l_class,
};
#endif /* FF_API_V4L */
diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c
index 072be48d40..468d4c1687 100644
--- a/libavdevice/v4l2.c
+++ b/libavdevice/v4l2.c
@@ -1,35 +1,37 @@
/*
- * Video4Linux2 grab interface
* Copyright (c) 2000,2001 Fabrice Bellard
* Copyright (c) 2006 Luca Abeni
*
- * Part of this file is based on the V4L2 video capture example
- * (http://v4l2spec.bytesex.org/v4l2spec/capture.c)
- *
- * Thanks to Michael Niedermayer for providing the mapping between
- * V4L2_PIX_FMT_* and PIX_FMT_*
+ * This file is part of FFmpeg.
*
- *
- * This file is part of Libav.
- *
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+/**
+ * @file
+ * Video4Linux2 grab interface
+ *
+ * Part of this file is based on the V4L2 video capture example
+ * (http://v4l2spec.bytesex.org/v4l2spec/capture.c)
+ *
+ * Thanks to Michael Niedermayer for providing the mapping between
+ * V4L2_PIX_FMT_* and PIX_FMT_*
+ */
+
#undef __STRICT_ANSI__ //workaround due to broken kernel headers
#include "config.h"
-#include "libavformat/avformat.h"
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
@@ -46,6 +48,7 @@
#include "libavutil/imgutils.h"
#include "libavutil/log.h"
#include "libavutil/opt.h"
+#include "avdevice.h"
#include "libavutil/parseutils.h"
#include "libavutil/pixdesc.h"
@@ -120,7 +123,6 @@ static int device_open(AVFormatContext *ctx, uint32_t *capabilities)
if (fd < 0) {
av_log(ctx, AV_LOG_ERROR, "Cannot open video device %s : %s\n",
ctx->filename, strerror(errno));
-
return AVERROR(errno);
}
@@ -136,13 +138,11 @@ static int device_open(AVFormatContext *ctx, uint32_t *capabilities)
av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QUERYCAP): %s\n",
strerror(errno));
close(fd);
-
return AVERROR(err);
}
if ((cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) == 0) {
av_log(ctx, AV_LOG_ERROR, "Not a video capture device\n");
close(fd);
-
return AVERROR(ENODEV);
}
*capabilities = cap.capabilities;
@@ -154,10 +154,9 @@ static int device_init(AVFormatContext *ctx, int *width, int *height, uint32_t p
{
struct video_data *s = ctx->priv_data;
int fd = s->fd;
- struct v4l2_format fmt;
+ struct v4l2_format fmt = {0};
int res;
- memset(&fmt, 0, sizeof(struct v4l2_format));
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
fmt.fmt.pix.width = *width;
fmt.fmt.pix.height = *height;
@@ -240,10 +239,9 @@ static enum CodecID fmt_v4l2codec(uint32_t v4l2_fmt)
static int mmap_init(AVFormatContext *ctx)
{
struct video_data *s = ctx->priv_data;
- struct v4l2_requestbuffers req;
+ struct v4l2_requestbuffers req = {0};
int i, res;
- memset(&req, 0, sizeof(struct v4l2_requestbuffers));
req.count = desired_video_buffers;
req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
req.memory = V4L2_MEMORY_MMAP;
@@ -254,41 +252,35 @@ static int mmap_init(AVFormatContext *ctx)
} else {
av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_REQBUFS)\n");
}
-
return AVERROR(errno);
}
if (req.count < 2) {
av_log(ctx, AV_LOG_ERROR, "Insufficient buffer memory\n");
-
return AVERROR(ENOMEM);
}
s->buffers = req.count;
s->buf_start = av_malloc(sizeof(void *) * s->buffers);
if (s->buf_start == NULL) {
av_log(ctx, AV_LOG_ERROR, "Cannot allocate buffer pointers\n");
-
return AVERROR(ENOMEM);
}
s->buf_len = av_malloc(sizeof(unsigned int) * s->buffers);
if (s->buf_len == NULL) {
av_log(ctx, AV_LOG_ERROR, "Cannot allocate buffer sizes\n");
av_free(s->buf_start);
-
return AVERROR(ENOMEM);
}
for (i = 0; i < req.count; i++) {
- struct v4l2_buffer buf;
+ struct v4l2_buffer buf = {0};
- memset(&buf, 0, sizeof(struct v4l2_buffer));
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.memory = V4L2_MEMORY_MMAP;
buf.index = i;
res = ioctl(s->fd, VIDIOC_QUERYBUF, &buf);
if (res < 0) {
av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QUERYBUF)\n");
-
return AVERROR(errno);
}
@@ -302,7 +294,6 @@ static int mmap_init(AVFormatContext *ctx)
PROT_READ | PROT_WRITE, MAP_SHARED, s->fd, buf.m.offset);
if (s->buf_start[i] == MAP_FAILED) {
av_log(ctx, AV_LOG_ERROR, "mmap: %s\n", strerror(errno));
-
return AVERROR(errno);
}
}
@@ -317,7 +308,7 @@ static int read_init(AVFormatContext *ctx)
static void mmap_release_buffer(AVPacket *pkt)
{
- struct v4l2_buffer buf;
+ struct v4l2_buffer buf = {0};
int res, fd;
struct buff_data *buf_descriptor = pkt->priv;
@@ -325,7 +316,6 @@ static void mmap_release_buffer(AVPacket *pkt)
return;
}
- memset(&buf, 0, sizeof(struct v4l2_buffer));
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.memory = V4L2_MEMORY_MMAP;
buf.index = buf_descriptor->index;
@@ -343,11 +333,10 @@ static void mmap_release_buffer(AVPacket *pkt)
static int mmap_read_frame(AVFormatContext *ctx, AVPacket *pkt)
{
struct video_data *s = ctx->priv_data;
- struct v4l2_buffer buf;
+ struct v4l2_buffer buf = {0};
struct buff_data *buf_descriptor;
int res;
- memset(&buf, 0, sizeof(struct v4l2_buffer));
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.memory = V4L2_MEMORY_MMAP;
@@ -356,17 +345,15 @@ static int mmap_read_frame(AVFormatContext *ctx, AVPacket *pkt)
if (res < 0) {
if (errno == EAGAIN) {
pkt->size = 0;
-
return AVERROR(EAGAIN);
}
av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_DQBUF): %s\n", strerror(errno));
return AVERROR(errno);
}
- assert (buf.index < s->buffers);
+ assert(buf.index < s->buffers);
if (s->frame_size > 0 && buf.bytesused != s->frame_size) {
av_log(ctx, AV_LOG_ERROR, "The v4l2 frame is %d bytes, but %d bytes are expected\n", buf.bytesused, s->frame_size);
-
return AVERROR_INVALIDDATA;
}
@@ -404,9 +391,8 @@ static int mmap_start(AVFormatContext *ctx)
int i, res;
for (i = 0; i < s->buffers; i++) {
- struct v4l2_buffer buf;
+ struct v4l2_buffer buf = {0};
- memset(&buf, 0, sizeof(struct v4l2_buffer));
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.memory = V4L2_MEMORY_MMAP;
buf.index = i;
@@ -414,7 +400,6 @@ static int mmap_start(AVFormatContext *ctx)
res = ioctl(s->fd, VIDIOC_QBUF, &buf);
if (res < 0) {
av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QBUF): %s\n", strerror(errno));
-
return AVERROR(errno);
}
}
@@ -423,7 +408,6 @@ static int mmap_start(AVFormatContext *ctx)
res = ioctl(s->fd, VIDIOC_STREAMON, &type);
if (res < 0) {
av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_STREAMON): %s\n", strerror(errno));
-
return AVERROR(errno);
}
@@ -450,9 +434,9 @@ static void mmap_close(struct video_data *s)
static int v4l2_set_parameters(AVFormatContext *s1, AVFormatParameters *ap)
{
struct video_data *s = s1->priv_data;
- struct v4l2_input input;
- struct v4l2_standard standard;
- struct v4l2_streamparm streamparm = { 0 };
+ struct v4l2_input input = {0};
+ struct v4l2_standard standard = {0};
+ struct v4l2_streamparm streamparm = {0};
struct v4l2_fract *tpf = &streamparm.parm.capture.timeperframe;
int i, ret;
AVRational framerate_q;
@@ -463,15 +447,8 @@ static int v4l2_set_parameters(AVFormatContext *s1, AVFormatParameters *ap)
av_log(s1, AV_LOG_ERROR, "Could not parse framerate '%s'.\n", s->framerate);
return ret;
}
-#if FF_API_FORMAT_PARAMETERS
- if (ap->channel > 0)
- s->channel = ap->channel;
- if (ap->time_base.num)
- framerate_q = (AVRational){ap->time_base.den, ap->time_base.num};
-#endif
/* set tv video input */
- memset (&input, 0, sizeof (input));
input.index = s->channel;
if (ioctl(s->fd, VIDIOC_ENUMINPUT, &input) < 0) {
av_log(s1, AV_LOG_ERROR, "The V4L2 driver ioctl enum input failed:\n");
@@ -486,29 +463,19 @@ static int v4l2_set_parameters(AVFormatContext *s1, AVFormatParameters *ap)
return AVERROR(EIO);
}
-#if FF_API_FORMAT_PARAMETERS
- if (ap->standard) {
- av_freep(&s->standard);
- s->standard = av_strdup(ap->standard);
- }
-#endif
-
if (s->standard) {
av_log(s1, AV_LOG_DEBUG, "The V4L2 driver set standard: %s\n",
s->standard);
/* set tv standard */
- memset (&standard, 0, sizeof (standard));
- for(i=0;;i++) {
+ for (i = 0;; i++) {
standard.index = i;
- if (ioctl(s->fd, VIDIOC_ENUMSTD, &standard) < 0) {
- av_log(s1, AV_LOG_ERROR, "The V4L2 driver ioctl set standard(%s) failed\n",
- s->standard);
- return AVERROR(EIO);
- }
-
- if (!strcasecmp(standard.name, s->standard)) {
+ ret = ioctl(s->fd, VIDIOC_ENUMSTD, &standard);
+ if (ret < 0 || !strcasecmp(standard.name, s->standard))
break;
- }
+ }
+ if (ret < 0) {
+ av_log(s1, AV_LOG_ERROR, "Unknown standard '%s'\n", s->standard);
+ return ret;
}
av_log(s1, AV_LOG_DEBUG, "The V4L2 driver set standard: %s, id: %"PRIu64"\n",
@@ -593,7 +560,7 @@ static int v4l2_read_header(AVFormatContext *s1, AVFormatParameters *ap)
enum CodecID codec_id;
enum PixelFormat pix_fmt = PIX_FMT_NONE;
- st = av_new_stream(s1, 0);
+ st = avformat_new_stream(s1, NULL);
if (!st) {
res = AVERROR(ENOMEM);
goto out;
@@ -609,14 +576,6 @@ static int v4l2_read_header(AVFormatContext *s1, AVFormatParameters *ap)
res = AVERROR(EINVAL);
goto out;
}
-#if FF_API_FORMAT_PARAMETERS
- if (ap->width > 0)
- s->width = ap->width;
- if (ap->height > 0)
- s->height = ap->height;
- if (ap->pix_fmt)
- pix_fmt = ap->pix_fmt;
-#endif
capabilities = 0;
s->fd = device_open(s1, &capabilities);
@@ -671,7 +630,6 @@ static int v4l2_read_header(AVFormatContext *s1, AVFormatParameters *ap)
}
if (res < 0) {
close(s->fd);
-
res = AVERROR(EIO);
goto out;
}
@@ -729,12 +687,13 @@ static int v4l2_read_close(AVFormatContext *s1)
#define OFFSET(x) offsetof(struct video_data, x)
#define DEC AV_OPT_FLAG_DECODING_PARAM
+
static const AVOption options[] = {
- { "standard", "", offsetof(struct video_data, standard), FF_OPT_TYPE_STRING, {.str = NULL }, 0, 0, AV_OPT_FLAG_DECODING_PARAM },
- { "channel", "", offsetof(struct video_data, channel), FF_OPT_TYPE_INT, {.dbl = 0 }, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
- { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), FF_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
- { "pixel_format", "", OFFSET(pixel_format), FF_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
- { "framerate", "", OFFSET(framerate), FF_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
+ { "standard", "", OFFSET(standard), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, AV_OPT_FLAG_DECODING_PARAM },
+ { "channel", "", OFFSET(channel), AV_OPT_TYPE_INT, {.dbl = 0 }, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
+ { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
+ { "pixel_format", "", OFFSET(pixel_format), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
+ { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
{ NULL },
};
@@ -746,13 +705,12 @@ static const AVClass v4l2_class = {
};
AVInputFormat ff_v4l2_demuxer = {
- "video4linux2",
- NULL_IF_CONFIG_SMALL("Video4Linux2 device grab"),
- sizeof(struct video_data),
- NULL,
- v4l2_read_header,
- v4l2_read_packet,
- v4l2_read_close,
- .flags = AVFMT_NOFILE,
- .priv_class = &v4l2_class,
+ .name = "video4linux2",
+ .long_name = NULL_IF_CONFIG_SMALL("Video4Linux2 device grab"),
+ .priv_data_size = sizeof(struct video_data),
+ .read_header = v4l2_read_header,
+ .read_packet = v4l2_read_packet,
+ .read_close = v4l2_read_close,
+ .flags = AVFMT_NOFILE,
+ .priv_class = &v4l2_class,
};
diff --git a/libavdevice/vfwcap.c b/libavdevice/vfwcap.c
index 80f9d00e9c..09330dea46 100644
--- a/libavdevice/vfwcap.c
+++ b/libavdevice/vfwcap.c
@@ -2,36 +2,34 @@
* VFW capture interface
* Copyright (c) 2006-2008 Ramiro Polla
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include "libavformat/avformat.h"
#include "libavutil/log.h"
#include "libavutil/opt.h"
#include "libavutil/parseutils.h"
#include <windows.h>
#include <vfw.h>
+#include "avdevice.h"
/* Defines for VFW missing from MinGW.
* Remove this when MinGW incorporates them. */
#define HWND_MESSAGE ((HWND)-3)
-#define BI_RGB 0
-
/* End of missing MinGW defines */
struct vfw_ctx {
@@ -244,7 +242,7 @@ static int vfw_read_header(AVFormatContext *s, AVFormatParameters *ap)
AVStream *st;
int devnum;
int bisize;
- BITMAPINFO *bi;
+ BITMAPINFO *bi = NULL;
CAPTUREPARMS cparms;
DWORD biCompression;
WORD biBitCount;
@@ -267,11 +265,6 @@ static int vfw_read_header(AVFormatContext *s, AVFormatParameters *ap)
return AVERROR(EIO);
}
-#if FF_API_FORMAT_PARAMETERS
- if (ap->time_base.num)
- framerate_q = (AVRational){ap->time_base.den, ap->time_base.num};
-#endif
-
ctx->hwnd = capCreateCaptureWindow(NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, 0);
if(!ctx->hwnd) {
av_log(s, AV_LOG_ERROR, "Could not create capture window.\n");
@@ -295,12 +288,12 @@ static int vfw_read_header(AVFormatContext *s, AVFormatParameters *ap)
(LPARAM) videostream_cb);
if(!ret) {
av_log(s, AV_LOG_ERROR, "Could not set video stream callback.\n");
- goto fail_io;
+ goto fail;
}
SetWindowLongPtr(ctx->hwnd, GWLP_USERDATA, (LONG_PTR) s);
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if(!st) {
vfw_read_close(s);
return AVERROR(ENOMEM);
@@ -309,7 +302,7 @@ static int vfw_read_header(AVFormatContext *s, AVFormatParameters *ap)
/* Set video format */
bisize = SendMessage(ctx->hwnd, WM_CAP_GET_VIDEOFORMAT, 0, 0);
if(!bisize)
- goto fail_io;
+ goto fail;
bi = av_malloc(bisize);
if(!bi) {
vfw_read_close(s);
@@ -317,24 +310,23 @@ static int vfw_read_header(AVFormatContext *s, AVFormatParameters *ap)
}
ret = SendMessage(ctx->hwnd, WM_CAP_GET_VIDEOFORMAT, bisize, (LPARAM) bi);
if(!ret)
- goto fail_bi;
+ goto fail;
dump_bih(s, &bi->bmiHeader);
+ ret = av_parse_video_rate(&framerate_q, ctx->framerate);
+ if (ret < 0) {
+ av_log(s, AV_LOG_ERROR, "Could not parse framerate '%s'.\n", ctx->framerate);
+ goto fail;
+ }
if (ctx->video_size) {
ret = av_parse_video_size(&bi->bmiHeader.biWidth, &bi->bmiHeader.biHeight, ctx->video_size);
if (ret < 0) {
av_log(s, AV_LOG_ERROR, "Couldn't parse video size.\n");
- goto fail_bi;
+ goto fail;
}
}
-#if FF_API_FORMAT_PARAMETERS
- if (ap->width > 0)
- bi->bmiHeader.biWidth = ap->width;
- if (ap->height > 0)
- bi->bmiHeader.biHeight = ap->height;
-#endif
if (0) {
/* For testing yet unsupported compressions
@@ -351,19 +343,17 @@ static int vfw_read_header(AVFormatContext *s, AVFormatParameters *ap)
ret = SendMessage(ctx->hwnd, WM_CAP_SET_VIDEOFORMAT, bisize, (LPARAM) bi);
if(!ret) {
av_log(s, AV_LOG_ERROR, "Could not set Video Format.\n");
- goto fail_bi;
+ goto fail;
}
biCompression = bi->bmiHeader.biCompression;
biBitCount = bi->bmiHeader.biBitCount;
- av_free(bi);
-
/* Set sequence setup */
ret = SendMessage(ctx->hwnd, WM_CAP_GET_SEQUENCE_SETUP, sizeof(cparms),
(LPARAM) &cparms);
if(!ret)
- goto fail_io;
+ goto fail;
dump_captureparms(s, &cparms);
@@ -378,7 +368,7 @@ static int vfw_read_header(AVFormatContext *s, AVFormatParameters *ap)
ret = SendMessage(ctx->hwnd, WM_CAP_SET_SEQUENCE_SETUP, sizeof(cparms),
(LPARAM) &cparms);
if(!ret)
- goto fail_io;
+ goto fail;
codec = st->codec;
codec->time_base = (AVRational){framerate_q.den, framerate_q.num};
@@ -407,31 +397,31 @@ static int vfw_read_header(AVFormatContext *s, AVFormatParameters *ap)
}
}
+ av_freep(&bi);
+
av_set_pts_info(st, 32, 1, 1000);
ctx->mutex = CreateMutex(NULL, 0, NULL);
if(!ctx->mutex) {
av_log(s, AV_LOG_ERROR, "Could not create Mutex.\n" );
- goto fail_io;
+ goto fail;
}
ctx->event = CreateEvent(NULL, 1, 0, NULL);
if(!ctx->event) {
av_log(s, AV_LOG_ERROR, "Could not create Event.\n" );
- goto fail_io;
+ goto fail;
}
ret = SendMessage(ctx->hwnd, WM_CAP_SEQUENCE_NOFILE, 0, 0);
if(!ret) {
av_log(s, AV_LOG_ERROR, "Could not start capture sequence.\n" );
- goto fail_io;
+ goto fail;
}
return 0;
-fail_bi:
- av_free(bi);
-
-fail_io:
+fail:
+ av_freep(&bi);
vfw_read_close(s);
return AVERROR(EIO);
}
@@ -468,8 +458,8 @@ static int vfw_read_packet(AVFormatContext *s, AVPacket *pkt)
#define OFFSET(x) offsetof(struct vfw_ctx, x)
#define DEC AV_OPT_FLAG_DECODING_PARAM
static const AVOption options[] = {
- { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), FF_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
- { "framerate", "", OFFSET(framerate), FF_OPT_TYPE_STRING, {.str = "ntsc"}, 0, 0, DEC },
+ { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
+ { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = "ntsc"}, 0, 0, DEC },
{ NULL },
};
@@ -481,13 +471,12 @@ static const AVClass vfw_class = {
};
AVInputFormat ff_vfwcap_demuxer = {
- "vfwcap",
- NULL_IF_CONFIG_SMALL("VFW video capture"),
- sizeof(struct vfw_ctx),
- NULL,
- vfw_read_header,
- vfw_read_packet,
- vfw_read_close,
- .flags = AVFMT_NOFILE,
- .priv_class = &vfw_class,
+ .name = "vfwcap",
+ .long_name = NULL_IF_CONFIG_SMALL("VfW video capture"),
+ .priv_data_size = sizeof(struct vfw_ctx),
+ .read_header = vfw_read_header,
+ .read_packet = vfw_read_packet,
+ .read_close = vfw_read_close,
+ .flags = AVFMT_NOFILE,
+ .priv_class = &vfw_class,
};
diff --git a/libavdevice/x11grab.c b/libavdevice/x11grab.c
index 6e77a5c52a..c2a67d7e62 100644
--- a/libavdevice/x11grab.c
+++ b/libavdevice/x11grab.c
@@ -1,9 +1,9 @@
/*
* X11 video grab interface
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav integration:
+ * FFmpeg integration:
* Copyright (C) 2006 Clemens Fruhwirth <clemens@endorphin.org>
* Edouard Gomez <ed.gomez@free.fr>
*
@@ -14,18 +14,18 @@
* Copyright (C) 1997-1998 Rasca, Berlin
* 2003-2004 Karl H. Beckers, Frankfurt
*
- * Libav is free software; you can redistribute it and/or modify
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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 Libav; if not, write to the Free Software
+ * along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -36,7 +36,6 @@
*/
#include "config.h"
-#include "libavformat/avformat.h"
#include "libavutil/log.h"
#include "libavutil/opt.h"
#include "libavutil/parseutils.h"
@@ -47,8 +46,10 @@
#include <X11/Xproto.h>
#include <X11/Xutil.h>
#include <sys/shm.h>
+#include <X11/extensions/shape.h>
#include <X11/extensions/XShm.h>
#include <X11/extensions/Xfixes.h>
+#include "avdevice.h"
/**
* X11 Device Demuxer context
@@ -70,10 +71,75 @@ struct x11_grab
XImage *image; /**< X11 image holding the grab */
int use_shm; /**< !0 when using XShm extension */
XShmSegmentInfo shminfo; /**< When using XShm, keeps track of XShm infos */
- int nomouse;
+ int draw_mouse; /**< Set by a private option. */
+ int follow_mouse; /**< Set by a private option. */
+ int show_region; /**< set by a private option. */
char *framerate; /**< Set by a private option. */
+
+ Window region_win; /**< This is used by show_region option. */
};
+#define REGION_WIN_BORDER 3
+/**
+ * Draw grabbing region window
+ *
+ * @param s x11_grab context
+ */
+static void
+x11grab_draw_region_win(struct x11_grab *s)
+{
+ Display *dpy = s->dpy;
+ int screen;
+ Window win = s->region_win;
+ GC gc;
+
+ screen = DefaultScreen(dpy);
+ gc = XCreateGC(dpy, win, 0, 0);
+ XSetForeground(dpy, gc, WhitePixel(dpy, screen));
+ XSetBackground(dpy, gc, BlackPixel(dpy, screen));
+ XSetLineAttributes(dpy, gc, REGION_WIN_BORDER, LineDoubleDash, 0, 0);
+ XDrawRectangle(dpy, win, gc,
+ 1, 1,
+ (s->width + REGION_WIN_BORDER * 2) - 1 * 2 - 1,
+ (s->height + REGION_WIN_BORDER * 2) - 1 * 2 - 1);
+ XFreeGC(dpy, gc);
+}
+
+/**
+ * Initialize grabbing region window
+ *
+ * @param s x11_grab context
+ */
+static void
+x11grab_region_win_init(struct x11_grab *s)
+{
+ Display *dpy = s->dpy;
+ int screen;
+ XSetWindowAttributes attribs;
+ XRectangle rect;
+
+ screen = DefaultScreen(dpy);
+ attribs.override_redirect = True;
+ s->region_win = XCreateWindow(dpy, RootWindow(dpy, screen),
+ s->x_off - REGION_WIN_BORDER,
+ s->y_off - REGION_WIN_BORDER,
+ s->width + REGION_WIN_BORDER * 2,
+ s->height + REGION_WIN_BORDER * 2,
+ 0, CopyFromParent,
+ InputOutput, CopyFromParent,
+ CWOverrideRedirect, &attribs);
+ rect.x = 0;
+ rect.y = 0;
+ rect.width = s->width;
+ rect.height = s->height;
+ XShapeCombineRectangles(dpy, s->region_win,
+ ShapeBounding, REGION_WIN_BORDER, REGION_WIN_BORDER,
+ &rect, 1, ShapeSubtract, 0);
+ XMapWindow(dpy, s->region_win);
+ XSelectInput(dpy, s->region_win, ExposureMask | StructureNotifyMask);
+ x11grab_draw_region_win(s);
+}
+
/**
* Initialize the x11 grab device demuxer (public device demuxer API).
*
@@ -95,16 +161,17 @@ x11grab_read_header(AVFormatContext *s1, AVFormatParameters *ap)
XImage *image;
int x_off = 0;
int y_off = 0;
+ int screen;
int use_shm;
- char *param, *offset;
+ char *dpyname, *offset;
int ret = 0;
AVRational framerate;
- param = av_strdup(s1->filename);
- offset = strchr(param, '+');
+ dpyname = av_strdup(s1->filename);
+ offset = strchr(dpyname, '+');
if (offset) {
sscanf(offset, "%d,%d", &x_off, &y_off);
- x11grab->nomouse= strstr(offset, "nomouse");
+ x11grab->draw_mouse = !strstr(offset, "nomouse");
*offset= 0;
}
@@ -116,33 +183,42 @@ x11grab_read_header(AVFormatContext *s1, AVFormatParameters *ap)
av_log(s1, AV_LOG_ERROR, "Could not parse framerate: %s.\n", x11grab->framerate);
goto out;
}
-#if FF_API_FORMAT_PARAMETERS
- if (ap->width > 0)
- x11grab->width = ap->width;
- if (ap->height > 0)
- x11grab->height = ap->height;
- if (ap->time_base.num)
- framerate = (AVRational){ap->time_base.den, ap->time_base.num};
-#endif
av_log(s1, AV_LOG_INFO, "device: %s -> display: %s x: %d y: %d width: %d height: %d\n",
- s1->filename, param, x_off, y_off, x11grab->width, x11grab->height);
+ s1->filename, dpyname, x_off, y_off, x11grab->width, x11grab->height);
- dpy = XOpenDisplay(param);
+ dpy = XOpenDisplay(dpyname);
+ av_freep(&dpyname);
if(!dpy) {
av_log(s1, AV_LOG_ERROR, "Could not open X display.\n");
ret = AVERROR(EIO);
goto out;
}
- st = av_new_stream(s1, 0);
+ st = avformat_new_stream(s1, NULL);
if (!st) {
ret = AVERROR(ENOMEM);
goto out;
}
av_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */
+ screen = DefaultScreen(dpy);
+
+ if (x11grab->follow_mouse) {
+ int screen_w, screen_h;
+ Window w;
+
+ screen_w = DisplayWidth(dpy, screen);
+ screen_h = DisplayHeight(dpy, screen);
+ XQueryPointer(dpy, RootWindow(dpy, screen), &w, &w, &x_off, &y_off, &ret, &ret, &ret);
+ x_off -= x11grab->width / 2;
+ y_off -= x11grab->height / 2;
+ x_off = FFMIN(FFMAX(x_off, 0), screen_w - x11grab->width);
+ y_off = FFMIN(FFMAX(y_off, 0), screen_h - x11grab->height);
+ av_log(s1, AV_LOG_INFO, "followmouse is enabled, resetting grabbing region to x: %d y: %d\n", x_off, y_off);
+ }
+
use_shm = XShmQueryExtension(dpy);
- av_log(s1, AV_LOG_INFO, "shared memory extension %s found\n", use_shm ? "" : "not");
+ av_log(s1, AV_LOG_INFO, "shared memory extension%s found\n", use_shm ? "" : " not");
if(use_shm) {
int scr = XDefaultScreen(dpy);
@@ -171,7 +247,7 @@ x11grab_read_header(AVFormatContext *s1, AVFormatParameters *ap)
goto out;
}
} else {
- image = XGetImage(dpy, RootWindow(dpy, DefaultScreen(dpy)),
+ image = XGetImage(dpy, RootWindow(dpy, screen),
x_off,y_off,
x11grab->width, x11grab->height,
AllPlanes, ZPixmap);
@@ -217,21 +293,6 @@ x11grab_read_header(AVFormatContext *s1, AVFormatParameters *ap)
}
break;
case 32:
-#if 0
- GetColorInfo (image, &c_info);
- if ( c_info.alpha_mask == 0xff000000 && image->green_mask == 0x0000ff00) {
- /* byte order is relevant here, not endianness
- * endianness is handled by avcodec, but atm no such thing
- * as having ABGR, instead of ARGB in a word. Since we
- * need this for Solaris/SPARC, but need to do the conversion
- * for every frame we do it outside of this loop, cf. below
- * this matches both ARGB32 and ABGR32 */
- input_pixfmt = PIX_FMT_ARGB32;
- } else {
- av_log(s1, AV_LOG_ERROR,"image depth %i not supported ... aborting\n", image->bits_per_pixel);
- return AVERROR(EIO);
- }
-#endif
input_pixfmt = PIX_FMT_RGB32;
break;
default:
@@ -389,6 +450,10 @@ x11grab_read_packet(AVFormatContext *s1, AVPacket *pkt)
int x_off = s->x_off;
int y_off = s->y_off;
+ int screen;
+ Window root;
+ int follow_mouse = s->follow_mouse;
+
int64_t curtime, delay;
struct timespec ts;
@@ -415,17 +480,65 @@ x11grab_read_packet(AVFormatContext *s1, AVPacket *pkt)
pkt->size = s->frame_size;
pkt->pts = curtime;
+ screen = DefaultScreen(dpy);
+ root = RootWindow(dpy, screen);
+ if (follow_mouse) {
+ int screen_w, screen_h;
+ int pointer_x, pointer_y, _;
+ Window w;
+
+ screen_w = DisplayWidth(dpy, screen);
+ screen_h = DisplayHeight(dpy, screen);
+ XQueryPointer(dpy, root, &w, &w, &pointer_x, &pointer_y, &_, &_, &_);
+ if (follow_mouse == -1) {
+ // follow the mouse, put it at center of grabbing region
+ x_off += pointer_x - s->width / 2 - x_off;
+ y_off += pointer_y - s->height / 2 - y_off;
+ } else {
+ // follow the mouse, but only move the grabbing region when mouse
+ // reaches within certain pixels to the edge.
+ if (pointer_x > x_off + s->width - follow_mouse) {
+ x_off += pointer_x - (x_off + s->width - follow_mouse);
+ } else if (pointer_x < x_off + follow_mouse)
+ x_off -= (x_off + follow_mouse) - pointer_x;
+ if (pointer_y > y_off + s->height - follow_mouse) {
+ y_off += pointer_y - (y_off + s->height - follow_mouse);
+ } else if (pointer_y < y_off + follow_mouse)
+ y_off -= (y_off + follow_mouse) - pointer_y;
+ }
+ // adjust grabbing region position if it goes out of screen.
+ s->x_off = x_off = FFMIN(FFMAX(x_off, 0), screen_w - s->width);
+ s->y_off = y_off = FFMIN(FFMAX(y_off, 0), screen_h - s->height);
+
+ if (s->show_region && s->region_win)
+ XMoveWindow(dpy, s->region_win,
+ s->x_off - REGION_WIN_BORDER,
+ s->y_off - REGION_WIN_BORDER);
+ }
+
+ if (s->show_region) {
+ if (s->region_win) {
+ XEvent evt;
+ // clean up the events, and do the initinal draw or redraw.
+ for (evt.type = NoEventMask; XCheckMaskEvent(dpy, ExposureMask | StructureNotifyMask, &evt); );
+ if (evt.type)
+ x11grab_draw_region_win(s);
+ } else {
+ x11grab_region_win_init(s);
+ }
+ }
+
if(s->use_shm) {
- if (!XShmGetImage(dpy, RootWindow(dpy, DefaultScreen(dpy)), image, x_off, y_off, AllPlanes)) {
+ if (!XShmGetImage(dpy, root, image, x_off, y_off, AllPlanes)) {
av_log (s1, AV_LOG_INFO, "XShmGetImage() failed\n");
}
} else {
- if (!xget_zpixmap(dpy, RootWindow(dpy, DefaultScreen(dpy)), image, x_off, y_off)) {
+ if (!xget_zpixmap(dpy, root, image, x_off, y_off)) {
av_log (s1, AV_LOG_INFO, "XGetZPixmap() failed\n");
}
}
- if(!s->nomouse){
+ if (s->draw_mouse) {
paint_mouse_pointer(image, s);
}
@@ -456,6 +569,10 @@ x11grab_read_close(AVFormatContext *s1)
x11grab->image = NULL;
}
+ if (x11grab->region_win) {
+ XDestroyWindow(x11grab->dpy, x11grab->region_win);
+ }
+
/* Free X11 display */
XCloseDisplay(x11grab->dpy);
return 0;
@@ -464,8 +581,13 @@ x11grab_read_close(AVFormatContext *s1)
#define OFFSET(x) offsetof(struct x11_grab, x)
#define DEC AV_OPT_FLAG_DECODING_PARAM
static const AVOption options[] = {
- { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), FF_OPT_TYPE_STRING, {.str = "vga"}, 0, 0, DEC },
- { "framerate", "", OFFSET(framerate), FF_OPT_TYPE_STRING, {.str = "ntsc"}, 0, 0, DEC },
+ { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), AV_OPT_TYPE_STRING, {.str = "vga"}, 0, 0, DEC },
+ { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = "ntsc"}, 0, 0, DEC },
+ { "draw_mouse", "Draw the mouse pointer.", OFFSET(draw_mouse), AV_OPT_TYPE_INT, { 1 }, 0, 1, DEC },
+ { "follow_mouse", "Move the grabbing region when the mouse pointer reaches within specified amount of pixels to the edge of region.",
+ OFFSET(follow_mouse), AV_OPT_TYPE_INT, { 0 }, -1, INT_MAX, DEC, "follow_mouse" },
+ { "centered", "Keep the mouse pointer at the center of grabbing region when following.", 0, AV_OPT_TYPE_CONST, { -1 }, INT_MIN, INT_MAX, DEC, "follow_mouse" },
+ { "show_region", "Show the grabbing region.", OFFSET(show_region), AV_OPT_TYPE_INT, { 0 }, 0, 1, DEC },
{ NULL },
};
@@ -477,15 +599,13 @@ static const AVClass x11_class = {
};
/** x11 grabber device demuxer declaration */
-AVInputFormat ff_x11_grab_device_demuxer =
-{
- "x11grab",
- NULL_IF_CONFIG_SMALL("X11grab"),
- sizeof(struct x11_grab),
- NULL,
- x11grab_read_header,
- x11grab_read_packet,
- x11grab_read_close,
- .flags = AVFMT_NOFILE,
- .priv_class = &x11_class,
+AVInputFormat ff_x11_grab_device_demuxer = {
+ .name = "x11grab",
+ .long_name = NULL_IF_CONFIG_SMALL("X11grab"),
+ .priv_data_size = sizeof(struct x11_grab),
+ .read_header = x11grab_read_header,
+ .read_packet = x11grab_read_packet,
+ .read_close = x11grab_read_close,
+ .flags = AVFMT_NOFILE,
+ .priv_class = &x11_class,
};
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 02016076bf..08a69e45dc 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -1,9 +1,16 @@
+include $(SUBDIR)../config.mak
+
NAME = avfilter
FFLIBS = avutil
+
+FFLIBS-$(CONFIG_ACONVERT_FILTER) += avcodec
+FFLIBS-$(CONFIG_AMOVIE_FILTER) += avformat avcodec
+FFLIBS-$(CONFIG_ARESAMPLE_FILTER) += avcodec
FFLIBS-$(CONFIG_MOVIE_FILTER) += avformat avcodec
FFLIBS-$(CONFIG_SCALE_FILTER) += swscale
+FFLIBS-$(CONFIG_MP_FILTER) += avcodec
-HEADERS = avfilter.h avfiltergraph.h
+HEADERS = avcodec.h avfilter.h avfiltergraph.h buffersink.h vsrc_buffer.h
OBJS = allfilters.o \
avfilter.o \
@@ -12,17 +19,31 @@ OBJS = allfilters.o \
drawutils.o \
formats.o \
graphparser.o \
+ transform.o \
+OBJS-$(CONFIG_AVCODEC) += avcodec.o
+
+OBJS-$(CONFIG_ACONVERT_FILTER) += af_aconvert.o
+OBJS-$(CONFIG_AFORMAT_FILTER) += af_aformat.o
OBJS-$(CONFIG_ANULL_FILTER) += af_anull.o
+OBJS-$(CONFIG_ARESAMPLE_FILTER) += af_aresample.o
+OBJS-$(CONFIG_ASHOWINFO_FILTER) += af_ashowinfo.o
+OBJS-$(CONFIG_ABUFFER_FILTER) += asrc_abuffer.o
+OBJS-$(CONFIG_AEVALSRC_FILTER) += asrc_aevalsrc.o
+OBJS-$(CONFIG_AMOVIE_FILTER) += src_movie.o
OBJS-$(CONFIG_ANULLSRC_FILTER) += asrc_anullsrc.o
+OBJS-$(CONFIG_ABUFFERSINK_FILTER) += sink_buffer.o
OBJS-$(CONFIG_ANULLSINK_FILTER) += asink_anullsink.o
OBJS-$(CONFIG_BLACKFRAME_FILTER) += vf_blackframe.o
+OBJS-$(CONFIG_BOXBLUR_FILTER) += vf_boxblur.o
OBJS-$(CONFIG_COPY_FILTER) += vf_copy.o
OBJS-$(CONFIG_CROP_FILTER) += vf_crop.o
OBJS-$(CONFIG_CROPDETECT_FILTER) += vf_cropdetect.o
+OBJS-$(CONFIG_DELOGO_FILTER) += vf_delogo.o
+OBJS-$(CONFIG_DESHAKE_FILTER) += vf_deshake.o
OBJS-$(CONFIG_DRAWBOX_FILTER) += vf_drawbox.o
OBJS-$(CONFIG_DRAWTEXT_FILTER) += vf_drawtext.o
OBJS-$(CONFIG_FADE_FILTER) += vf_fade.o
@@ -33,6 +54,11 @@ OBJS-$(CONFIG_FREI0R_FILTER) += vf_frei0r.o
OBJS-$(CONFIG_GRADFUN_FILTER) += vf_gradfun.o
OBJS-$(CONFIG_HFLIP_FILTER) += vf_hflip.o
OBJS-$(CONFIG_HQDN3D_FILTER) += vf_hqdn3d.o
+OBJS-$(CONFIG_LUT_FILTER) += vf_lut.o
+OBJS-$(CONFIG_LUTRGB_FILTER) += vf_lut.o
+OBJS-$(CONFIG_LUTYUV_FILTER) += vf_lut.o
+OBJS-$(CONFIG_MP_FILTER) += vf_mp.o
+OBJS-$(CONFIG_NEGATE_FILTER) += vf_lut.o
OBJS-$(CONFIG_NOFORMAT_FILTER) += vf_format.o
OBJS-$(CONFIG_NULL_FILTER) += vf_null.o
OBJS-$(CONFIG_OCV_FILTER) += vf_libopencv.o
@@ -40,11 +66,14 @@ OBJS-$(CONFIG_OVERLAY_FILTER) += vf_overlay.o
OBJS-$(CONFIG_PAD_FILTER) += vf_pad.o
OBJS-$(CONFIG_PIXDESCTEST_FILTER) += vf_pixdesctest.o
OBJS-$(CONFIG_SCALE_FILTER) += vf_scale.o
+OBJS-$(CONFIG_SELECT_FILTER) += vf_select.o
OBJS-$(CONFIG_SETDAR_FILTER) += vf_aspect.o
OBJS-$(CONFIG_SETPTS_FILTER) += vf_setpts.o
OBJS-$(CONFIG_SETSAR_FILTER) += vf_aspect.o
OBJS-$(CONFIG_SETTB_FILTER) += vf_settb.o
+OBJS-$(CONFIG_SHOWINFO_FILTER) += vf_showinfo.o
OBJS-$(CONFIG_SLICIFY_FILTER) += vf_slicify.o
+OBJS-$(CONFIG_SPLIT_FILTER) += vf_split.o
OBJS-$(CONFIG_TRANSPOSE_FILTER) += vf_transpose.o
OBJS-$(CONFIG_UNSHARP_FILTER) += vf_unsharp.o
OBJS-$(CONFIG_VFLIP_FILTER) += vf_vflip.o
@@ -53,13 +82,79 @@ OBJS-$(CONFIG_YADIF_FILTER) += vf_yadif.o
OBJS-$(CONFIG_BUFFER_FILTER) += vsrc_buffer.o
OBJS-$(CONFIG_COLOR_FILTER) += vsrc_color.o
OBJS-$(CONFIG_FREI0R_SRC_FILTER) += vf_frei0r.o
-OBJS-$(CONFIG_MOVIE_FILTER) += vsrc_movie.o
+OBJS-$(CONFIG_MOVIE_FILTER) += src_movie.o
+OBJS-$(CONFIG_MPTESTSRC_FILTER) += vsrc_mptestsrc.o
OBJS-$(CONFIG_NULLSRC_FILTER) += vsrc_nullsrc.o
+OBJS-$(CONFIG_RGBTESTSRC_FILTER) += vsrc_testsrc.o
+OBJS-$(CONFIG_TESTSRC_FILTER) += vsrc_testsrc.o
+OBJS-$(CONFIG_BUFFERSINK_FILTER) += sink_buffer.o
OBJS-$(CONFIG_NULLSINK_FILTER) += vsink_nullsink.o
+
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/mp_image.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/img_format.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_2xsai.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_decimate.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_denoise3d.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_detc.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_dint.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_divtc.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_down3dright.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_dsize.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_eq2.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_eq.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_field.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_fil.o
+#OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_filmdint.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_fixpts.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_framestep.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_fspp.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_geq.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_harddup.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_hqdn3d.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_hue.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_il.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_ilpack.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_ivtc.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_kerndeint.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_mcdeint.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_mirror.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_noise.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_ow.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_palette.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_perspective.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_phase.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_pp7.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_pullup.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_qp.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_rectangle.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_remove_logo.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_rotate.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_sab.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_screenshot.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_smartblur.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_softpulldown.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_softskip.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_spp.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_stereo3d.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_swapuv.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_telecine.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_tile.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_tinterlace.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_unsharp.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_uspp.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_yuvcsp.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_yvu9.o
+OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/pullup.o
+
+
-include $(SRC_PATH)/$(SUBDIR)$(ARCH)/Makefile
-DIRS = x86
+DIRS = x86 libmpcodecs
+
+TESTPROGS = formats
+
+TOOLS = graph2dot lavfi-showfiltfmts
include $(SRC_PATH)/subdir.mak
diff --git a/libavfilter/af_aconvert.c b/libavfilter/af_aconvert.c
new file mode 100644
index 0000000000..fef096cb8e
--- /dev/null
+++ b/libavfilter/af_aconvert.c
@@ -0,0 +1,418 @@
+/*
+ * Copyright (c) 2010 S.N. Hemanth Meenakshisundaram <smeenaks@ucsd.edu>
+ * Copyright (c) 2011 Stefano Sabatini
+ * Copyright (c) 2011 Mina Nagy Zaki
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * sample format and channel layout conversion audio filter
+ * based on code in libavcodec/resample.c by Fabrice Bellard and
+ * libavcodec/audioconvert.c by Michael Niedermayer
+ */
+
+#include "libavutil/audioconvert.h"
+#include "libavutil/avstring.h"
+#include "libavcodec/audioconvert.h"
+#include "avfilter.h"
+#include "internal.h"
+
+typedef struct {
+ enum AVSampleFormat out_sample_fmt, in_sample_fmt; ///< in/out sample formats
+ int64_t out_chlayout, in_chlayout; ///< in/out channel layout
+ int out_nb_channels, in_nb_channels; ///< number of in/output channels
+ enum AVFilterPacking out_packing_fmt, in_packing_fmt; ///< output packing format
+
+ int max_nb_samples; ///< maximum number of buffered samples
+ AVFilterBufferRef *mix_samplesref; ///< rematrixed buffer
+ AVFilterBufferRef *out_samplesref; ///< output buffer after required conversions
+
+ uint8_t *in_mix[8], *out_mix[8]; ///< input/output for rematrixing functions
+ uint8_t *packed_data[8]; ///< pointers for packing conversion
+ int out_strides[8], in_strides[8]; ///< input/output strides for av_audio_convert
+ uint8_t **in_conv, **out_conv; ///< input/output for av_audio_convert
+
+ AVAudioConvert *audioconvert_ctx; ///< context for conversion to output sample format
+
+ void (*convert_chlayout)(); ///< function to do the requested rematrixing
+} AConvertContext;
+
+#define REMATRIX_FUNC_SIG(NAME) static void REMATRIX_FUNC_NAME(NAME) \
+ (FMT_TYPE *outp[], FMT_TYPE *inp[], int nb_samples, AConvertContext *aconvert)
+
+#define FMT_TYPE uint8_t
+#define REMATRIX_FUNC_NAME(NAME) NAME ## _u8
+#include "af_aconvert_rematrix.c"
+
+#define FMT_TYPE int16_t
+#define REMATRIX_FUNC_NAME(NAME) NAME ## _s16
+#include "af_aconvert_rematrix.c"
+
+#define FMT_TYPE int32_t
+#define REMATRIX_FUNC_NAME(NAME) NAME ## _s32
+#include "af_aconvert_rematrix.c"
+
+#define FLOATING
+
+#define FMT_TYPE float
+#define REMATRIX_FUNC_NAME(NAME) NAME ## _flt
+#include "af_aconvert_rematrix.c"
+
+#define FMT_TYPE double
+#define REMATRIX_FUNC_NAME(NAME) NAME ## _dbl
+#include "af_aconvert_rematrix.c"
+
+#define FMT_TYPE uint8_t
+#define REMATRIX_FUNC_NAME(NAME) NAME
+REMATRIX_FUNC_SIG(stereo_remix_planar)
+{
+ int size = av_get_bytes_per_sample(aconvert->in_sample_fmt) * nb_samples;
+
+ memcpy(outp[0], inp[0], size);
+ memcpy(outp[1], inp[aconvert->in_nb_channels == 1 ? 0 : 1], size);
+}
+
+#define REGISTER_FUNC_PACKING(INCHLAYOUT, OUTCHLAYOUT, FUNC, PACKING) \
+ {INCHLAYOUT, OUTCHLAYOUT, PACKING, AV_SAMPLE_FMT_U8, FUNC##_u8}, \
+ {INCHLAYOUT, OUTCHLAYOUT, PACKING, AV_SAMPLE_FMT_S16, FUNC##_s16}, \
+ {INCHLAYOUT, OUTCHLAYOUT, PACKING, AV_SAMPLE_FMT_S32, FUNC##_s32}, \
+ {INCHLAYOUT, OUTCHLAYOUT, PACKING, AV_SAMPLE_FMT_FLT, FUNC##_flt}, \
+ {INCHLAYOUT, OUTCHLAYOUT, PACKING, AV_SAMPLE_FMT_DBL, FUNC##_dbl},
+
+#define REGISTER_FUNC(INCHLAYOUT, OUTCHLAYOUT, FUNC) \
+ REGISTER_FUNC_PACKING(INCHLAYOUT, OUTCHLAYOUT, FUNC##_packed, AVFILTER_PACKED) \
+ REGISTER_FUNC_PACKING(INCHLAYOUT, OUTCHLAYOUT, FUNC##_planar, AVFILTER_PLANAR)
+
+static struct RematrixFunctionInfo {
+ int64_t in_chlayout, out_chlayout;
+ int planar, sfmt;
+ void (*func)();
+} rematrix_funcs[] = {
+ REGISTER_FUNC (AV_CH_LAYOUT_STEREO, AV_CH_LAYOUT_5POINT1, stereo_to_surround_5p1)
+ REGISTER_FUNC (AV_CH_LAYOUT_5POINT1, AV_CH_LAYOUT_STEREO, surround_5p1_to_stereo)
+ REGISTER_FUNC_PACKING(AV_CH_LAYOUT_STEREO, AV_CH_LAYOUT_MONO, stereo_to_mono_packed, AVFILTER_PACKED)
+ REGISTER_FUNC_PACKING(AV_CH_LAYOUT_MONO, AV_CH_LAYOUT_STEREO, mono_to_stereo_packed, AVFILTER_PACKED)
+ REGISTER_FUNC (0, AV_CH_LAYOUT_MONO, mono_downmix)
+ REGISTER_FUNC_PACKING(0, AV_CH_LAYOUT_STEREO, stereo_downmix_packed, AVFILTER_PACKED)
+
+ // This function works for all sample formats
+ {0, AV_CH_LAYOUT_STEREO, AVFILTER_PLANAR, -1, stereo_remix_planar}
+};
+
+static av_cold int init(AVFilterContext *ctx, const char *args0, void *opaque)
+{
+ AConvertContext *aconvert = ctx->priv;
+ char *arg, *ptr = NULL;
+ int ret = 0;
+ char *args = av_strdup(args0);
+
+ aconvert->out_sample_fmt = AV_SAMPLE_FMT_NONE;
+ aconvert->out_chlayout = 0;
+ aconvert->out_packing_fmt = -1;
+
+ if ((arg = av_strtok(args, ":", &ptr)) && strcmp(arg, "auto")) {
+ if ((ret = ff_parse_sample_format(&aconvert->out_sample_fmt, arg, ctx)) < 0)
+ goto end;
+ }
+ if ((arg = av_strtok(NULL, ":", &ptr)) && strcmp(arg, "auto")) {
+ if ((ret = ff_parse_channel_layout(&aconvert->out_chlayout, arg, ctx)) < 0)
+ goto end;
+ }
+ if ((arg = av_strtok(NULL, ":", &ptr)) && strcmp(arg, "auto")) {
+ if ((ret = ff_parse_packing_format((int *)&aconvert->out_packing_fmt, arg, ctx)) < 0)
+ goto end;
+ }
+
+end:
+ av_freep(&args);
+ return ret;
+}
+
+static av_cold void uninit(AVFilterContext *ctx)
+{
+ AConvertContext *aconvert = ctx->priv;
+ avfilter_unref_buffer(aconvert->mix_samplesref);
+ avfilter_unref_buffer(aconvert->out_samplesref);
+ if (aconvert->audioconvert_ctx)
+ av_audio_convert_free(aconvert->audioconvert_ctx);
+}
+
+static int query_formats(AVFilterContext *ctx)
+{
+ AVFilterFormats *formats = NULL;
+ AConvertContext *aconvert = ctx->priv;
+ AVFilterLink *inlink = ctx->inputs[0];
+ AVFilterLink *outlink = ctx->outputs[0];
+
+ avfilter_formats_ref(avfilter_make_all_formats(AVMEDIA_TYPE_AUDIO),
+ &inlink->out_formats);
+ if (aconvert->out_sample_fmt != AV_SAMPLE_FMT_NONE) {
+ formats = NULL;
+ avfilter_add_format(&formats, aconvert->out_sample_fmt);
+ avfilter_formats_ref(formats, &outlink->in_formats);
+ } else
+ avfilter_formats_ref(avfilter_make_all_formats(AVMEDIA_TYPE_AUDIO),
+ &outlink->in_formats);
+
+ avfilter_formats_ref(avfilter_make_all_channel_layouts(),
+ &inlink->out_chlayouts);
+ if (aconvert->out_chlayout != 0) {
+ formats = NULL;
+ avfilter_add_format(&formats, aconvert->out_chlayout);
+ avfilter_formats_ref(formats, &outlink->in_chlayouts);
+ } else
+ avfilter_formats_ref(avfilter_make_all_channel_layouts(),
+ &outlink->in_chlayouts);
+
+ avfilter_formats_ref(avfilter_make_all_packing_formats(),
+ &inlink->out_packing);
+ if (aconvert->out_packing_fmt != -1) {
+ formats = NULL;
+ avfilter_add_format(&formats, aconvert->out_packing_fmt);
+ avfilter_formats_ref(formats, &outlink->in_packing);
+ } else
+ avfilter_formats_ref(avfilter_make_all_packing_formats(),
+ &outlink->in_packing);
+
+ return 0;
+}
+
+static int config_output(AVFilterLink *outlink)
+{
+ AVFilterLink *inlink = outlink->src->inputs[0];
+ AConvertContext *aconvert = outlink->src->priv;
+ char buf1[64], buf2[64];
+
+ aconvert->in_sample_fmt = inlink->format;
+ aconvert->in_packing_fmt = inlink->planar;
+ if (aconvert->out_packing_fmt == -1)
+ aconvert->out_packing_fmt = outlink->planar;
+ aconvert->in_chlayout = inlink->channel_layout;
+ aconvert->in_nb_channels =
+ av_get_channel_layout_nb_channels(inlink->channel_layout);
+
+ /* if not specified in args, use the format and layout of the output */
+ if (aconvert->out_sample_fmt == AV_SAMPLE_FMT_NONE)
+ aconvert->out_sample_fmt = outlink->format;
+ if (aconvert->out_chlayout == 0)
+ aconvert->out_chlayout = outlink->channel_layout;
+ aconvert->out_nb_channels =
+ av_get_channel_layout_nb_channels(outlink->channel_layout);
+
+ av_get_channel_layout_string(buf1, sizeof(buf1),
+ -1, inlink ->channel_layout);
+ av_get_channel_layout_string(buf2, sizeof(buf2),
+ -1, outlink->channel_layout);
+ av_log(outlink->src, AV_LOG_INFO,
+ "fmt:%s cl:%s planar:%i -> fmt:%s cl:%s planar:%i\n",
+ av_get_sample_fmt_name(inlink ->format), buf1, inlink ->planar,
+ av_get_sample_fmt_name(outlink->format), buf2, outlink->planar);
+
+ /* compute which channel layout conversion to use */
+ if (inlink->channel_layout != outlink->channel_layout) {
+ int i;
+ for (i = 0; i < sizeof(rematrix_funcs); i++) {
+ const struct RematrixFunctionInfo *f = &rematrix_funcs[i];
+ if ((f->in_chlayout == 0 || f->in_chlayout == inlink ->channel_layout) &&
+ (f->out_chlayout == 0 || f->out_chlayout == outlink->channel_layout) &&
+ (f->planar == -1 || f->planar == inlink->planar) &&
+ (f->sfmt == -1 || f->sfmt == inlink->format)
+ ) {
+ aconvert->convert_chlayout = f->func;
+ break;
+ }
+ }
+ if (!aconvert->convert_chlayout) {
+ av_log(outlink->src, AV_LOG_ERROR,
+ "Unsupported channel layout conversion '%s -> %s' requested!\n",
+ buf1, buf2);
+ return AVERROR(EINVAL);
+ }
+ }
+
+ return 0;
+}
+
+static int init_buffers(AVFilterLink *inlink, int nb_samples)
+{
+ AConvertContext *aconvert = inlink->dst->priv;
+ AVFilterLink * const outlink = inlink->dst->outputs[0];
+ int i, packed_stride = 0;
+ const unsigned
+ packing_conv = inlink->planar != outlink->planar &&
+ aconvert->out_nb_channels != 1,
+ format_conv = inlink->format != outlink->format;
+ int nb_channels = aconvert->out_nb_channels;
+
+ uninit(inlink->dst);
+ aconvert->max_nb_samples = nb_samples;
+
+ if (aconvert->convert_chlayout) {
+ /* allocate buffer for storing intermediary mixing samplesref */
+ uint8_t *data[8];
+ int linesize[8];
+ int nb_channels = av_get_channel_layout_nb_channels(outlink->channel_layout);
+
+ if (av_samples_alloc(data, linesize, nb_channels, nb_samples,
+ inlink->format, inlink->planar, 16) < 0)
+ goto fail_no_mem;
+ aconvert->mix_samplesref =
+ avfilter_get_audio_buffer_ref_from_arrays(data, linesize, AV_PERM_WRITE,
+ nb_samples, inlink->format,
+ outlink->channel_layout,
+ inlink->planar);
+ if (!aconvert->mix_samplesref)
+ goto fail_no_mem;
+ }
+
+ // if there's a format/packing conversion we need an audio_convert context
+ if (format_conv || packing_conv) {
+ aconvert->out_samplesref =
+ avfilter_get_audio_buffer(outlink, AV_PERM_WRITE, nb_samples);
+ if (!aconvert->out_samplesref)
+ goto fail_no_mem;
+
+ aconvert->in_strides [0] = av_get_bytes_per_sample(inlink ->format);
+ aconvert->out_strides[0] = av_get_bytes_per_sample(outlink->format);
+
+ aconvert->out_conv = aconvert->out_samplesref->data;
+ if (aconvert->mix_samplesref)
+ aconvert->in_conv = aconvert->mix_samplesref->data;
+
+ if (packing_conv) {
+ // packed -> planar
+ if (outlink->planar == AVFILTER_PLANAR) {
+ if (aconvert->mix_samplesref)
+ aconvert->packed_data[0] = aconvert->mix_samplesref->data[0];
+ aconvert->in_conv = aconvert->packed_data;
+ packed_stride = aconvert->in_strides[0];
+ aconvert->in_strides[0] *= nb_channels;
+ // planar -> packed
+ } else {
+ aconvert->packed_data[0] = aconvert->out_samplesref->data[0];
+ aconvert->out_conv = aconvert->packed_data;
+ packed_stride = aconvert->out_strides[0];
+ aconvert->out_strides[0] *= nb_channels;
+ }
+ } else if (outlink->planar == AVFILTER_PACKED) {
+ /* If there's no packing conversion, and the stream is packed
+ * then we treat the entire stream as one big channel
+ */
+ nb_channels = 1;
+ }
+
+ for (i = 1; i < nb_channels; i++) {
+ aconvert->packed_data[i] = aconvert->packed_data[i-1] + packed_stride;
+ aconvert->in_strides[i] = aconvert->in_strides[0];
+ aconvert->out_strides[i] = aconvert->out_strides[0];
+ }
+
+ aconvert->audioconvert_ctx =
+ av_audio_convert_alloc(outlink->format, nb_channels,
+ inlink->format, nb_channels, NULL, 0);
+ if (!aconvert->audioconvert_ctx)
+ goto fail_no_mem;
+ }
+
+ return 0;
+
+fail_no_mem:
+ av_log(inlink->dst, AV_LOG_ERROR, "Could not allocate memory.\n");
+ return AVERROR(ENOMEM);
+}
+
+static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamplesref)
+{
+ AConvertContext *aconvert = inlink->dst->priv;
+ AVFilterBufferRef *curbuf = insamplesref;
+ AVFilterLink * const outlink = inlink->dst->outputs[0];
+ int chan_mult;
+
+ /* in/reinint the internal buffers if this is the first buffer
+ * provided or it is needed to use a bigger one */
+ if (!aconvert->max_nb_samples ||
+ (curbuf->audio->nb_samples > aconvert->max_nb_samples))
+ if (init_buffers(inlink, curbuf->audio->nb_samples) < 0) {
+ av_log(inlink->dst, AV_LOG_ERROR, "Could not initialize buffers.\n");
+ return;
+ }
+
+ /* if channel mixing is required */
+ if (aconvert->mix_samplesref) {
+ memcpy(aconvert->in_mix, curbuf->data, sizeof(aconvert->in_mix));
+ memcpy(aconvert->out_mix, aconvert->mix_samplesref->data, sizeof(aconvert->out_mix));
+ aconvert->convert_chlayout(aconvert->out_mix,
+ aconvert->in_mix,
+ curbuf->audio->nb_samples,
+ aconvert);
+ curbuf = aconvert->mix_samplesref;
+ }
+
+ if (aconvert->audioconvert_ctx) {
+ if (!aconvert->mix_samplesref) {
+ if (aconvert->in_conv == aconvert->packed_data) {
+ int i, packed_stride = av_get_bytes_per_sample(inlink->format);
+ aconvert->packed_data[0] = curbuf->data[0];
+ for (i = 1; i < aconvert->out_nb_channels; i++)
+ aconvert->packed_data[i] = aconvert->packed_data[i-1] + packed_stride;
+ } else {
+ aconvert->in_conv = curbuf->data;
+ }
+ }
+
+ chan_mult = inlink->planar == outlink->planar && inlink->planar == 0 ?
+ aconvert->out_nb_channels : 1;
+
+ av_audio_convert(aconvert->audioconvert_ctx,
+ (void * const *) aconvert->out_conv,
+ aconvert->out_strides,
+ (const void * const *) aconvert->in_conv,
+ aconvert->in_strides,
+ curbuf->audio->nb_samples * chan_mult);
+
+ curbuf = aconvert->out_samplesref;
+ }
+
+ avfilter_copy_buffer_ref_props(curbuf, insamplesref);
+ curbuf->audio->channel_layout = outlink->channel_layout;
+ curbuf->audio->planar = outlink->planar;
+
+ avfilter_filter_samples(inlink->dst->outputs[0],
+ avfilter_ref_buffer(curbuf, ~0));
+ avfilter_unref_buffer(insamplesref);
+}
+
+AVFilter avfilter_af_aconvert = {
+ .name = "aconvert",
+ .description = NULL_IF_CONFIG_SMALL("Convert the input audio to sample_fmt:channel_layout:packed_fmt."),
+ .priv_size = sizeof(AConvertContext),
+ .init = init,
+ .uninit = uninit,
+ .query_formats = query_formats,
+
+ .inputs = (AVFilterPad[]) {{ .name = "default",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .filter_samples = filter_samples,
+ .min_perms = AV_PERM_READ, },
+ { .name = NULL}},
+ .outputs = (AVFilterPad[]) {{ .name = "default",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .config_props = config_output, },
+ { .name = NULL}},
+};
diff --git a/libavfilter/af_aconvert_rematrix.c b/libavfilter/af_aconvert_rematrix.c
new file mode 100644
index 0000000000..d75ca5aa40
--- /dev/null
+++ b/libavfilter/af_aconvert_rematrix.c
@@ -0,0 +1,172 @@
+/*
+ * Copyright (c) 2011 Mina Nagy Zaki
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * audio rematrixing functions, based on functions from libavcodec/resample.c
+ */
+
+#if defined(FLOATING)
+# define DIV2 /2
+#else
+# define DIV2 >>1
+#endif
+
+REMATRIX_FUNC_SIG(stereo_to_mono_packed)
+{
+ while (nb_samples >= 4) {
+ outp[0][0] = (inp[0][0] + inp[0][1]) DIV2;
+ outp[0][1] = (inp[0][2] + inp[0][3]) DIV2;
+ outp[0][2] = (inp[0][4] + inp[0][5]) DIV2;
+ outp[0][3] = (inp[0][6] + inp[0][7]) DIV2;
+ outp[0] += 4;
+ inp[0] += 8;
+ nb_samples -= 4;
+ }
+ while (nb_samples--) {
+ outp[0][0] = (inp[0][0] + inp[0][1]) DIV2;
+ outp[0]++;
+ inp[0] += 2;
+ }
+}
+
+REMATRIX_FUNC_SIG(stereo_downmix_packed)
+{
+ while (nb_samples--) {
+ *outp[0]++ = inp[0][0];
+ *outp[0]++ = inp[0][1];
+ inp[0] += aconvert->in_nb_channels;
+ }
+}
+
+REMATRIX_FUNC_SIG(mono_to_stereo_packed)
+{
+ while (nb_samples >= 4) {
+ outp[0][0] = outp[0][1] = inp[0][0];
+ outp[0][2] = outp[0][3] = inp[0][1];
+ outp[0][4] = outp[0][5] = inp[0][2];
+ outp[0][6] = outp[0][7] = inp[0][3];
+ outp[0] += 8;
+ inp[0] += 4;
+ nb_samples -= 4;
+ }
+ while (nb_samples--) {
+ outp[0][0] = outp[0][1] = inp[0][0];
+ outp[0] += 2;
+ inp[0] += 1;
+ }
+}
+
+/**
+ * This is for when we have more than 2 input channels, need to downmix to mono
+ * and do not have a conversion formula available. We just use first two input
+ * channels - left and right. This is a placeholder until more conversion
+ * functions are written.
+ */
+REMATRIX_FUNC_SIG(mono_downmix_packed)
+{
+ while (nb_samples--) {
+ outp[0][0] = (inp[0][0] + inp[0][1]) DIV2;
+ inp[0] += aconvert->in_nb_channels;
+ outp[0]++;
+ }
+}
+
+REMATRIX_FUNC_SIG(mono_downmix_planar)
+{
+ FMT_TYPE *out = outp[0];
+
+ while (nb_samples >= 4) {
+ out[0] = (inp[0][0] + inp[1][0]) DIV2;
+ out[1] = (inp[0][1] + inp[1][1]) DIV2;
+ out[2] = (inp[0][2] + inp[1][2]) DIV2;
+ out[3] = (inp[0][3] + inp[1][3]) DIV2;
+ out += 4;
+ inp[0] += 4;
+ inp[1] += 4;
+ nb_samples -= 4;
+ }
+ while (nb_samples--) {
+ out[0] = (inp[0][0] + inp[1][0]) DIV2;
+ out++;
+ inp[0]++;
+ inp[1]++;
+ }
+}
+
+/* Stereo to 5.1 output */
+REMATRIX_FUNC_SIG(stereo_to_surround_5p1_packed)
+{
+ while (nb_samples--) {
+ outp[0][0] = inp[0][0]; /* left */
+ outp[0][1] = inp[0][1]; /* right */
+ outp[0][2] = (inp[0][0] + inp[0][1]) DIV2; /* center */
+ outp[0][3] = 0; /* low freq */
+ outp[0][4] = 0; /* FIXME: left surround: -3dB or -6dB or -9dB of stereo left */
+ outp[0][5] = 0; /* FIXME: right surroud: -3dB or -6dB or -9dB of stereo right */
+ inp[0] += 2;
+ outp[0] += 6;
+ }
+}
+
+REMATRIX_FUNC_SIG(stereo_to_surround_5p1_planar)
+{
+ while (nb_samples--) {
+ *outp[0]++ = *inp[0]; /* left */
+ *outp[1]++ = *inp[1]; /* right */
+ *outp[2]++ = (*inp[0] + *inp[1]) DIV2; /* center */
+ *outp[3]++ = 0; /* low freq */
+ *outp[4]++ = 0; /* FIXME: left surround: -3dB or -6dB or -9dB of stereo left */
+ *outp[5]++ = 0; /* FIXME: right surroud: -3dB or -6dB or -9dB of stereo right */
+ inp[0]++; inp[1]++;
+ }
+}
+
+
+/*
+5.1 to stereo input: [fl, fr, c, lfe, rl, rr]
+- Left = front_left + rear_gain * rear_left + center_gain * center
+- Right = front_right + rear_gain * rear_right + center_gain * center
+Where rear_gain is usually around 0.5-1.0 and
+ center_gain is almost always 0.7 (-3 dB)
+*/
+REMATRIX_FUNC_SIG(surround_5p1_to_stereo_packed)
+{
+ while (nb_samples--) {
+ *outp[0]++ = inp[0][0] + (0.5 * inp[0][4]) + (0.7 * inp[0][2]); //FIXME CLIPPING!
+ *outp[0]++ = inp[0][1] + (0.5 * inp[0][5]) + (0.7 * inp[0][2]); //FIXME CLIPPING!
+
+ inp[0] += 6;
+ }
+}
+
+REMATRIX_FUNC_SIG(surround_5p1_to_stereo_planar)
+{
+ while (nb_samples--) {
+ *outp[0]++ = *inp[0] + (0.5 * *inp[4]) + (0.7 * *inp[2]); //FIXME CLIPPING!
+ *outp[1]++ = *inp[1] + (0.5 * *inp[5]) + (0.7 * *inp[2]); //FIXME CLIPPING!
+
+ inp[0]++; inp[1]++; inp[2]++; inp[3]++; inp[4]++; inp[5]++;
+ }
+}
+
+#undef DIV2
+#undef REMATRIX_FUNC_NAME
+#undef FMT_TYPE
diff --git a/libavfilter/af_aformat.c b/libavfilter/af_aformat.c
new file mode 100644
index 0000000000..20ab940cc8
--- /dev/null
+++ b/libavfilter/af_aformat.c
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2011 Mina Nagy Zaki
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * format audio filter
+ */
+
+#include "libavutil/audioconvert.h"
+#include "libavutil/avstring.h"
+#include "avfilter.h"
+#include "internal.h"
+
+typedef struct {
+ AVFilterFormats *formats, *chlayouts, *packing;
+} AFormatContext;
+
+static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
+{
+ AFormatContext * const aformat = ctx->priv;
+ char *fmts_str = NULL, *fmt_str, *ptr = NULL;
+ int64_t fmt;
+ int ret;
+
+ if (!args)
+ goto arg_fail;
+
+#define ADD_FORMATS(all_formats, fmt_name, fmt_type, fmts_list) \
+ fmts_str = av_get_token(&args, ":"); \
+ if (!fmts_str || !*fmts_str) \
+ goto arg_fail; \
+ if (!strcmp(fmts_str, "all")) { \
+ aformat->fmts_list = all_formats; \
+ } else { \
+ for (fmt_str = fmts_str; \
+ fmt_str = av_strtok(fmt_str, ",", &ptr); fmt_str = NULL) { \
+ if ((ret = ff_parse_##fmt_name((fmt_type *)&fmt, \
+ fmt_str, ctx)) < 0) { \
+ av_freep(&fmts_str); \
+ return ret; \
+ } \
+ avfilter_add_format(&aformat->fmts_list, fmt); \
+ } \
+ } \
+ av_freep(&fmts_str); \
+ if (*args) \
+ args++;
+
+ ADD_FORMATS(avfilter_make_all_formats(AVMEDIA_TYPE_AUDIO), sample_format, int, formats);
+ ADD_FORMATS(avfilter_make_all_channel_layouts(), channel_layout, int64_t, chlayouts);
+ ADD_FORMATS(avfilter_make_all_packing_formats(), packing_format, int, packing);
+
+ return 0;
+
+arg_fail:
+ av_log(ctx, AV_LOG_ERROR, "Invalid arguments, they must be of the form "
+ "sample_fmts:channel_layouts:packing_fmts\n");
+ av_freep(&fmts_str);
+ return AVERROR(EINVAL);
+}
+
+static int query_formats(AVFilterContext *ctx)
+{
+ AFormatContext * const aformat = ctx->priv;
+
+ avfilter_set_common_sample_formats (ctx, aformat->formats);
+ avfilter_set_common_channel_layouts(ctx, aformat->chlayouts);
+ avfilter_set_common_packing_formats(ctx, aformat->packing);
+ return 0;
+}
+
+static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamplesref)
+{
+ avfilter_filter_samples(inlink->dst->outputs[0], insamplesref);
+}
+
+AVFilter avfilter_af_aformat = {
+ .name = "aformat",
+ .description = NULL_IF_CONFIG_SMALL("Convert the input audio to one of the specified formats."),
+ .init = init,
+ .query_formats = query_formats,
+ .priv_size = sizeof(AFormatContext),
+
+ .inputs = (AVFilterPad[]) {{ .name = "default",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .filter_samples = filter_samples},
+ { .name = NULL}},
+ .outputs = (AVFilterPad[]) {{ .name = "default",
+ .type = AVMEDIA_TYPE_AUDIO},
+ { .name = NULL}},
+};
diff --git a/libavfilter/af_anull.c b/libavfilter/af_anull.c
index e2bed36f0a..94e7e17b48 100644
--- a/libavfilter/af_anull.c
+++ b/libavfilter/af_anull.c
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavfilter/af_aresample.c b/libavfilter/af_aresample.c
new file mode 100644
index 0000000000..4cf6936ba8
--- /dev/null
+++ b/libavfilter/af_aresample.c
@@ -0,0 +1,348 @@
+/*
+ * Copyright (c) 2011 Stefano Sabatini
+ * Copyright (c) 2011 Mina Nagy Zaki
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * resampling audio filter
+ */
+
+#include "libavutil/eval.h"
+#include "libavcodec/avcodec.h"
+#include "avfilter.h"
+#include "internal.h"
+
+typedef struct {
+ struct AVResampleContext *resample;
+ int out_rate;
+ double ratio;
+ AVFilterBufferRef *outsamplesref;
+ int unconsumed_nb_samples,
+ max_cached_nb_samples;
+ int16_t *cached_data[8],
+ *resampled_data[8];
+} AResampleContext;
+
+static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
+{
+ AResampleContext *aresample = ctx->priv;
+ int ret;
+
+ if (args) {
+ if ((ret = ff_parse_sample_rate(&aresample->out_rate, args, ctx)) < 0)
+ return ret;
+ } else {
+ aresample->out_rate = -1;
+ }
+
+ return 0;
+}
+
+static av_cold void uninit(AVFilterContext *ctx)
+{
+ AResampleContext *aresample = ctx->priv;
+ if (aresample->outsamplesref) {
+ int nb_channels =
+ av_get_channel_layout_nb_channels(
+ aresample->outsamplesref->audio->channel_layout);
+ avfilter_unref_buffer(aresample->outsamplesref);
+ while (nb_channels--) {
+ av_freep(&(aresample->cached_data[nb_channels]));
+ av_freep(&(aresample->resampled_data[nb_channels]));
+ }
+ }
+
+ if (aresample->resample)
+ av_resample_close(aresample->resample);
+}
+
+static int config_output(AVFilterLink *outlink)
+{
+ AVFilterContext *ctx = outlink->src;
+ AVFilterLink *inlink = ctx->inputs[0];
+ AResampleContext *aresample = ctx->priv;
+
+ if (aresample->out_rate == -1)
+ aresample->out_rate = outlink->sample_rate;
+ else
+ outlink->sample_rate = aresample->out_rate;
+ outlink->time_base = (AVRational) {1, aresample->out_rate};
+
+ //TODO: make the resampling parameters configurable
+ aresample->resample = av_resample_init(aresample->out_rate, inlink->sample_rate,
+ 16, 10, 0, 0.8);
+
+ aresample->ratio = (double)outlink->sample_rate / inlink->sample_rate;
+
+ av_log(ctx, AV_LOG_INFO, "r:%"PRId64"Hz -> r:%"PRId64"Hz\n",
+ inlink->sample_rate, outlink->sample_rate);
+ return 0;
+}
+
+static int query_formats(AVFilterContext *ctx)
+{
+ AVFilterFormats *formats = NULL;
+
+ avfilter_add_format(&formats, AV_SAMPLE_FMT_S16);
+ if (!formats)
+ return AVERROR(ENOMEM);
+ avfilter_set_common_sample_formats(ctx, formats);
+
+ formats = avfilter_make_all_channel_layouts();
+ if (!formats)
+ return AVERROR(ENOMEM);
+ avfilter_set_common_channel_layouts(ctx, formats);
+
+ formats = avfilter_make_all_packing_formats();
+ if (!formats)
+ return AVERROR(ENOMEM);
+ avfilter_set_common_packing_formats(ctx, formats);
+
+ return 0;
+}
+
+static void deinterleave(int16_t **outp, int16_t *in,
+ int nb_channels, int nb_samples)
+{
+ int16_t *out[8];
+ memcpy(out, outp, nb_channels * sizeof(int16_t*));
+
+ switch (nb_channels) {
+ case 2:
+ while (nb_samples--) {
+ *out[0]++ = *in++;
+ *out[1]++ = *in++;
+ }
+ break;
+ case 3:
+ while (nb_samples--) {
+ *out[0]++ = *in++;
+ *out[1]++ = *in++;
+ *out[2]++ = *in++;
+ }
+ break;
+ case 4:
+ while (nb_samples--) {
+ *out[0]++ = *in++;
+ *out[1]++ = *in++;
+ *out[2]++ = *in++;
+ *out[3]++ = *in++;
+ }
+ break;
+ case 5:
+ while (nb_samples--) {
+ *out[0]++ = *in++;
+ *out[1]++ = *in++;
+ *out[2]++ = *in++;
+ *out[3]++ = *in++;
+ *out[4]++ = *in++;
+ }
+ break;
+ case 6:
+ while (nb_samples--) {
+ *out[0]++ = *in++;
+ *out[1]++ = *in++;
+ *out[2]++ = *in++;
+ *out[3]++ = *in++;
+ *out[4]++ = *in++;
+ *out[5]++ = *in++;
+ }
+ break;
+ case 8:
+ while (nb_samples--) {
+ *out[0]++ = *in++;
+ *out[1]++ = *in++;
+ *out[2]++ = *in++;
+ *out[3]++ = *in++;
+ *out[4]++ = *in++;
+ *out[5]++ = *in++;
+ *out[6]++ = *in++;
+ *out[7]++ = *in++;
+ }
+ break;
+ }
+}
+
+static void interleave(int16_t *out, int16_t **inp,
+ int nb_channels, int nb_samples)
+{
+ int16_t *in[8];
+ memcpy(in, inp, nb_channels * sizeof(int16_t*));
+
+ switch (nb_channels) {
+ case 2:
+ while (nb_samples--) {
+ *out++ = *in[0]++;
+ *out++ = *in[1]++;
+ }
+ break;
+ case 3:
+ while (nb_samples--) {
+ *out++ = *in[0]++;
+ *out++ = *in[1]++;
+ *out++ = *in[2]++;
+ }
+ break;
+ case 4:
+ while (nb_samples--) {
+ *out++ = *in[0]++;
+ *out++ = *in[1]++;
+ *out++ = *in[2]++;
+ *out++ = *in[3]++;
+ }
+ break;
+ case 5:
+ while (nb_samples--) {
+ *out++ = *in[0]++;
+ *out++ = *in[1]++;
+ *out++ = *in[2]++;
+ *out++ = *in[3]++;
+ *out++ = *in[4]++;
+ }
+ break;
+ case 6:
+ while (nb_samples--) {
+ *out++ = *in[0]++;
+ *out++ = *in[1]++;
+ *out++ = *in[2]++;
+ *out++ = *in[3]++;
+ *out++ = *in[4]++;
+ *out++ = *in[5]++;
+ }
+ break;
+ case 8:
+ while (nb_samples--) {
+ *out++ = *in[0]++;
+ *out++ = *in[1]++;
+ *out++ = *in[2]++;
+ *out++ = *in[3]++;
+ *out++ = *in[4]++;
+ *out++ = *in[5]++;
+ *out++ = *in[6]++;
+ *out++ = *in[7]++;
+ }
+ break;
+ }
+}
+
+static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamplesref)
+{
+ AResampleContext *aresample = inlink->dst->priv;
+ AVFilterLink * const outlink = inlink->dst->outputs[0];
+ int i,
+ in_nb_samples = insamplesref->audio->nb_samples,
+ cached_nb_samples = in_nb_samples + aresample->unconsumed_nb_samples,
+ requested_out_nb_samples = aresample->ratio * cached_nb_samples,
+ nb_channels =
+ av_get_channel_layout_nb_channels(inlink->channel_layout);
+
+ if (cached_nb_samples > aresample->max_cached_nb_samples) {
+ for (i = 0; i < nb_channels; i++) {
+ aresample->cached_data[i] =
+ av_realloc(aresample->cached_data[i], cached_nb_samples * sizeof(int16_t));
+ aresample->resampled_data[i] =
+ av_realloc(aresample->resampled_data[i],
+ FFALIGN(sizeof(int16_t) * requested_out_nb_samples, 16));
+
+ if (aresample->cached_data[i] == NULL || aresample->resampled_data[i] == NULL)
+ return;
+ }
+ aresample->max_cached_nb_samples = cached_nb_samples;
+
+ if (aresample->outsamplesref)
+ avfilter_unref_buffer(aresample->outsamplesref);
+
+ aresample->outsamplesref =
+ avfilter_get_audio_buffer(outlink, AV_PERM_WRITE, requested_out_nb_samples);
+ outlink->out_buf = aresample->outsamplesref;
+ }
+
+ avfilter_copy_buffer_ref_props(aresample->outsamplesref, insamplesref);
+ aresample->outsamplesref->audio->sample_rate = outlink->sample_rate;
+ aresample->outsamplesref->pts =
+ av_rescale(outlink->sample_rate, insamplesref->pts, inlink->sample_rate);
+
+ /* av_resample() works with planar audio buffers */
+ if (!inlink->planar && nb_channels > 1) {
+ int16_t *out[8];
+ for (i = 0; i < nb_channels; i++)
+ out[i] = aresample->cached_data[i] + aresample->unconsumed_nb_samples;
+
+ deinterleave(out, (int16_t *)insamplesref->data[0],
+ nb_channels, in_nb_samples);
+ } else {
+ for (i = 0; i < nb_channels; i++)
+ memcpy(aresample->cached_data[i] + aresample->unconsumed_nb_samples,
+ insamplesref->data[i],
+ in_nb_samples * sizeof(int16_t));
+ }
+
+ for (i = 0; i < nb_channels; i++) {
+ int consumed_nb_samples;
+ const int is_last = i+1 == nb_channels;
+
+ aresample->outsamplesref->audio->nb_samples =
+ av_resample(aresample->resample,
+ aresample->resampled_data[i], aresample->cached_data[i],
+ &consumed_nb_samples,
+ cached_nb_samples,
+ requested_out_nb_samples, is_last);
+
+ /* move unconsumed data back to the beginning of the cache */
+ aresample->unconsumed_nb_samples = cached_nb_samples - consumed_nb_samples;
+ memmove(aresample->cached_data[i],
+ aresample->cached_data[i] + consumed_nb_samples,
+ aresample->unconsumed_nb_samples * sizeof(int16_t));
+ }
+
+
+ /* copy resampled data to the output samplesref */
+ if (!inlink->planar && nb_channels > 1) {
+ interleave((int16_t *)aresample->outsamplesref->data[0],
+ aresample->resampled_data,
+ nb_channels, aresample->outsamplesref->audio->nb_samples);
+ } else {
+ for (i = 0; i < nb_channels; i++)
+ memcpy(aresample->outsamplesref->data[i], aresample->resampled_data[i],
+ aresample->outsamplesref->audio->nb_samples * sizeof(int16_t));
+ }
+
+ avfilter_filter_samples(outlink, avfilter_ref_buffer(aresample->outsamplesref, ~0));
+ avfilter_unref_buffer(insamplesref);
+}
+
+AVFilter avfilter_af_aresample = {
+ .name = "aresample",
+ .description = NULL_IF_CONFIG_SMALL("Resample audio data."),
+ .init = init,
+ .uninit = uninit,
+ .query_formats = query_formats,
+ .priv_size = sizeof(AResampleContext),
+
+ .inputs = (AVFilterPad[]) {{ .name = "default",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .filter_samples = filter_samples,
+ .min_perms = AV_PERM_READ, },
+ { .name = NULL}},
+ .outputs = (AVFilterPad[]) {{ .name = "default",
+ .config_props = config_output,
+ .type = AVMEDIA_TYPE_AUDIO, },
+ { .name = NULL}},
+};
diff --git a/libavfilter/af_ashowinfo.c b/libavfilter/af_ashowinfo.c
new file mode 100644
index 0000000000..0ad7252421
--- /dev/null
+++ b/libavfilter/af_ashowinfo.c
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) 2011 Stefano Sabatini
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * filter fow showing textual audio frame information
+ */
+
+#include "libavutil/adler32.h"
+#include "libavutil/audioconvert.h"
+#include "avfilter.h"
+
+typedef struct {
+ unsigned int frame;
+} ShowInfoContext;
+
+static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
+{
+ ShowInfoContext *showinfo = ctx->priv;
+ showinfo->frame = 0;
+ return 0;
+}
+
+static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *samplesref)
+{
+ AVFilterContext *ctx = inlink->dst;
+ ShowInfoContext *showinfo = ctx->priv;
+ uint32_t plane_checksum[8] = {0}, checksum = 0;
+ char chlayout_str[128];
+ int plane;
+ int linesize =
+ samplesref->audio->nb_samples *
+ av_get_bytes_per_sample(samplesref->format);
+ if (!samplesref->audio->planar) /* packed layout */
+ linesize *= av_get_channel_layout_nb_channels(samplesref->audio->channel_layout);
+
+ for (plane = 0; samplesref->data[plane] && plane < 8; plane++) {
+ uint8_t *data = samplesref->data[plane];
+
+ plane_checksum[plane] = av_adler32_update(plane_checksum[plane],
+ data, linesize);
+ checksum = av_adler32_update(checksum, data, linesize);
+ }
+
+ av_get_channel_layout_string(chlayout_str, sizeof(chlayout_str), -1,
+ samplesref->audio->channel_layout);
+
+ av_log(ctx, AV_LOG_INFO,
+ "n:%d pts:%"PRId64" pts_time:%f pos:%"PRId64" "
+ "fmt:%s chlayout:%s nb_samples:%d rate:%d planar:%d "
+ "checksum:%u plane_checksum[%u %u %u %u %u %u %u %u]\n",
+ showinfo->frame,
+ samplesref->pts, samplesref->pts * av_q2d(inlink->time_base),
+ samplesref->pos,
+ av_get_sample_fmt_name(samplesref->format),
+ chlayout_str,
+ samplesref->audio->nb_samples,
+ samplesref->audio->sample_rate,
+ samplesref->audio->planar,
+ checksum,
+ plane_checksum[0], plane_checksum[1], plane_checksum[2], plane_checksum[3],
+ plane_checksum[4], plane_checksum[5], plane_checksum[6], plane_checksum[7]);
+
+ showinfo->frame++;
+
+ avfilter_filter_samples(inlink->dst->outputs[0], samplesref);
+}
+
+AVFilter avfilter_af_ashowinfo = {
+ .name = "ashowinfo",
+ .description = NULL_IF_CONFIG_SMALL("Show textual information for each audio frame."),
+
+ .priv_size = sizeof(ShowInfoContext),
+ .init = init,
+
+ .inputs = (AVFilterPad[]) {{ .name = "default",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .get_audio_buffer = avfilter_null_get_audio_buffer,
+ .filter_samples = filter_samples,
+ .min_perms = AV_PERM_READ, },
+ { .name = NULL}},
+
+ .outputs = (AVFilterPad[]) {{ .name = "default",
+ .type = AVMEDIA_TYPE_AUDIO },
+ { .name = NULL}},
+};
diff --git a/libavfilter/all_channel_layouts.h b/libavfilter/all_channel_layouts.h
new file mode 100644
index 0000000000..878e1f5f8e
--- /dev/null
+++ b/libavfilter/all_channel_layouts.h
@@ -0,0 +1,68 @@
+AV_CH_FRONT_CENTER,
+AV_CH_FRONT_CENTER|AV_CH_LOW_FREQUENCY,
+AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT,
+AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_LOW_FREQUENCY,
+AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_FRONT_CENTER,
+AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_FRONT_CENTER|AV_CH_LOW_FREQUENCY,
+AV_CH_FRONT_CENTER|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT,
+AV_CH_FRONT_CENTER|AV_CH_LOW_FREQUENCY|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT,
+AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT,
+AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_LOW_FREQUENCY|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT,
+AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_FRONT_CENTER|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT,
+AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_FRONT_CENTER|AV_CH_LOW_FREQUENCY|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT,
+AV_CH_FRONT_CENTER|AV_CH_BACK_CENTER,
+AV_CH_FRONT_CENTER|AV_CH_LOW_FREQUENCY|AV_CH_BACK_CENTER,
+AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_BACK_CENTER,
+AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_LOW_FREQUENCY|AV_CH_BACK_CENTER,
+AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_FRONT_CENTER|AV_CH_BACK_CENTER,
+AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_FRONT_CENTER|AV_CH_LOW_FREQUENCY|AV_CH_BACK_CENTER,
+AV_CH_FRONT_CENTER|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT,
+AV_CH_FRONT_CENTER|AV_CH_LOW_FREQUENCY|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT,
+AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT,
+AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_LOW_FREQUENCY|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT,
+AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_FRONT_CENTER|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT,
+AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_FRONT_CENTER|AV_CH_LOW_FREQUENCY|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT,
+AV_CH_FRONT_CENTER|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT,
+AV_CH_FRONT_CENTER|AV_CH_LOW_FREQUENCY|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT,
+AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT,
+AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_LOW_FREQUENCY|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT,
+AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_FRONT_CENTER|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT,
+AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_FRONT_CENTER|AV_CH_LOW_FREQUENCY|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT,
+AV_CH_FRONT_CENTER|AV_CH_BACK_CENTER|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT,
+AV_CH_FRONT_CENTER|AV_CH_LOW_FREQUENCY|AV_CH_BACK_CENTER|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT,
+AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_BACK_CENTER|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT,
+AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_LOW_FREQUENCY|AV_CH_BACK_CENTER|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT,
+AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_FRONT_CENTER|AV_CH_BACK_CENTER|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT,
+AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_FRONT_CENTER|AV_CH_LOW_FREQUENCY|AV_CH_BACK_CENTER|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT,
+AV_CH_FRONT_CENTER|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT,
+AV_CH_FRONT_CENTER|AV_CH_LOW_FREQUENCY|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT,
+AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT,
+AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_LOW_FREQUENCY|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT,
+AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_FRONT_CENTER|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT,
+AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_FRONT_CENTER|AV_CH_LOW_FREQUENCY|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT,
+AV_CH_FRONT_CENTER|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT,
+AV_CH_FRONT_CENTER|AV_CH_LOW_FREQUENCY|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT,
+AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT,
+AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_LOW_FREQUENCY|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT,
+AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_FRONT_CENTER|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT,
+AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_FRONT_CENTER|AV_CH_LOW_FREQUENCY|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT,
+AV_CH_FRONT_CENTER|AV_CH_BACK_CENTER|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT,
+AV_CH_FRONT_CENTER|AV_CH_LOW_FREQUENCY|AV_CH_BACK_CENTER|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT,
+AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_BACK_CENTER|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT,
+AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_LOW_FREQUENCY|AV_CH_BACK_CENTER|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT,
+AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_FRONT_CENTER|AV_CH_BACK_CENTER|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT,
+AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_FRONT_CENTER|AV_CH_LOW_FREQUENCY|AV_CH_BACK_CENTER|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT,
+AV_CH_FRONT_CENTER|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT,
+AV_CH_FRONT_CENTER|AV_CH_LOW_FREQUENCY|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT,
+AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT,
+AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_LOW_FREQUENCY|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT,
+AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_FRONT_CENTER|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT,
+AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_FRONT_CENTER|AV_CH_LOW_FREQUENCY|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT,
+AV_CH_FRONT_CENTER|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT,
+AV_CH_FRONT_CENTER|AV_CH_LOW_FREQUENCY|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT,
+AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT,
+AV_CH_FRONT_CENTER|AV_CH_BACK_CENTER|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT,
+AV_CH_FRONT_CENTER|AV_CH_LOW_FREQUENCY|AV_CH_BACK_CENTER|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT,
+AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_BACK_CENTER|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT,
+AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_LOW_FREQUENCY|AV_CH_BACK_CENTER|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT,
+AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_FRONT_CENTER|AV_CH_BACK_CENTER|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT,
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index e29b4f97bd..3c77adb23d 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -2,20 +2,20 @@
* filter registration
* Copyright (c) 2008 Vitor Sessak
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -34,16 +34,27 @@ void avfilter_register_all(void)
return;
initialized = 1;
+ REGISTER_FILTER (ACONVERT, aconvert, af);
+ REGISTER_FILTER (AFORMAT, aformat, af);
REGISTER_FILTER (ANULL, anull, af);
+ REGISTER_FILTER (ARESAMPLE, aresample, af);
+ REGISTER_FILTER (ASHOWINFO, ashowinfo, af);
+ REGISTER_FILTER (ABUFFER, abuffer, asrc);
+ REGISTER_FILTER (AEVALSRC, aevalsrc, asrc);
+ REGISTER_FILTER (AMOVIE, amovie, asrc);
REGISTER_FILTER (ANULLSRC, anullsrc, asrc);
+ REGISTER_FILTER (ABUFFERSINK, abuffersink, asink);
REGISTER_FILTER (ANULLSINK, anullsink, asink);
REGISTER_FILTER (BLACKFRAME, blackframe, vf);
+ REGISTER_FILTER (BOXBLUR, boxblur, vf);
REGISTER_FILTER (COPY, copy, vf);
REGISTER_FILTER (CROP, crop, vf);
REGISTER_FILTER (CROPDETECT, cropdetect, vf);
+ REGISTER_FILTER (DELOGO, delogo, vf);
+ REGISTER_FILTER (DESHAKE, deshake, vf);
REGISTER_FILTER (DRAWBOX, drawbox, vf);
REGISTER_FILTER (DRAWTEXT, drawtext, vf);
REGISTER_FILTER (FADE, fade, vf);
@@ -54,6 +65,11 @@ void avfilter_register_all(void)
REGISTER_FILTER (GRADFUN, gradfun, vf);
REGISTER_FILTER (HFLIP, hflip, vf);
REGISTER_FILTER (HQDN3D, hqdn3d, vf);
+ REGISTER_FILTER (LUT, lut, vf);
+ REGISTER_FILTER (LUTRGB, lutrgb, vf);
+ REGISTER_FILTER (LUTYUV, lutyuv, vf);
+ REGISTER_FILTER (MP, mp, vf);
+ REGISTER_FILTER (NEGATE, negate, vf);
REGISTER_FILTER (NOFORMAT, noformat, vf);
REGISTER_FILTER (NULL, null, vf);
REGISTER_FILTER (OCV, ocv, vf);
@@ -61,11 +77,14 @@ void avfilter_register_all(void)
REGISTER_FILTER (PAD, pad, vf);
REGISTER_FILTER (PIXDESCTEST, pixdesctest, vf);
REGISTER_FILTER (SCALE, scale, vf);
+ REGISTER_FILTER (SELECT, select, vf);
REGISTER_FILTER (SETDAR, setdar, vf);
REGISTER_FILTER (SETPTS, setpts, vf);
REGISTER_FILTER (SETSAR, setsar, vf);
REGISTER_FILTER (SETTB, settb, vf);
+ REGISTER_FILTER (SHOWINFO, showinfo, vf);
REGISTER_FILTER (SLICIFY, slicify, vf);
+ REGISTER_FILTER (SPLIT, split, vf);
REGISTER_FILTER (TRANSPOSE, transpose, vf);
REGISTER_FILTER (UNSHARP, unsharp, vf);
REGISTER_FILTER (VFLIP, vflip, vf);
@@ -75,7 +94,11 @@ void avfilter_register_all(void)
REGISTER_FILTER (COLOR, color, vsrc);
REGISTER_FILTER (FREI0R, frei0r_src, vsrc);
REGISTER_FILTER (MOVIE, movie, vsrc);
+ REGISTER_FILTER (MPTESTSRC, mptestsrc, vsrc);
REGISTER_FILTER (NULLSRC, nullsrc, vsrc);
+ REGISTER_FILTER (RGBTESTSRC, rgbtestsrc, vsrc);
+ REGISTER_FILTER (TESTSRC, testsrc, vsrc);
+ REGISTER_FILTER (BUFFERSINK, buffersink, vsink);
REGISTER_FILTER (NULLSINK, nullsink, vsink);
}
diff --git a/libavfilter/asink_anullsink.c b/libavfilter/asink_anullsink.c
index 3a505e79f2..5a89c2792e 100644
--- a/libavfilter/asink_anullsink.c
+++ b/libavfilter/asink_anullsink.c
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavfilter/asrc_abuffer.c b/libavfilter/asrc_abuffer.c
new file mode 100644
index 0000000000..bfa7e63f2a
--- /dev/null
+++ b/libavfilter/asrc_abuffer.c
@@ -0,0 +1,372 @@
+/*
+ * Copyright (c) 2010 S.N. Hemanth Meenakshisundaram
+ * Copyright (c) 2011 Mina Nagy Zaki
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * memory buffer source for audio
+ */
+
+#include "libavutil/audioconvert.h"
+#include "libavutil/avstring.h"
+#include "libavutil/fifo.h"
+#include "asrc_abuffer.h"
+#include "internal.h"
+
+typedef struct {
+ // Audio format of incoming buffers
+ int sample_rate;
+ unsigned int sample_format;
+ int64_t channel_layout;
+ int packing_format;
+
+ // FIFO buffer of audio buffer ref pointers
+ AVFifoBuffer *fifo;
+
+ // Normalization filters
+ AVFilterContext *aconvert;
+ AVFilterContext *aresample;
+} ABufferSourceContext;
+
+#define FIFO_SIZE 8
+
+static void buf_free(AVFilterBuffer *ptr)
+{
+ av_free(ptr);
+ return;
+}
+
+static void set_link_source(AVFilterContext *src, AVFilterLink *link)
+{
+ link->src = src;
+ link->srcpad = &(src->output_pads[0]);
+ src->outputs[0] = link;
+}
+
+static int reconfigure_filter(ABufferSourceContext *abuffer, AVFilterContext *filt_ctx)
+{
+ int ret;
+ AVFilterLink * const inlink = filt_ctx->inputs[0];
+ AVFilterLink * const outlink = filt_ctx->outputs[0];
+
+ inlink->format = abuffer->sample_format;
+ inlink->channel_layout = abuffer->channel_layout;
+ inlink->planar = abuffer->packing_format;
+ inlink->sample_rate = abuffer->sample_rate;
+
+ filt_ctx->filter->uninit(filt_ctx);
+ memset(filt_ctx->priv, 0, filt_ctx->filter->priv_size);
+ if ((ret = filt_ctx->filter->init(filt_ctx, NULL , NULL)) < 0)
+ return ret;
+ if ((ret = inlink->srcpad->config_props(inlink)) < 0)
+ return ret;
+ return outlink->srcpad->config_props(outlink);
+}
+
+static int insert_filter(ABufferSourceContext *abuffer,
+ AVFilterLink *link, AVFilterContext **filt_ctx,
+ const char *filt_name)
+{
+ int ret;
+
+ if ((ret = avfilter_open(filt_ctx, avfilter_get_by_name(filt_name), NULL)) < 0)
+ return ret;
+
+ link->src->outputs[0] = NULL;
+ if ((ret = avfilter_link(link->src, 0, *filt_ctx, 0)) < 0) {
+ link->src->outputs[0] = link;
+ return ret;
+ }
+
+ set_link_source(*filt_ctx, link);
+
+ if ((ret = reconfigure_filter(abuffer, *filt_ctx)) < 0) {
+ avfilter_free(*filt_ctx);
+ return ret;
+ }
+
+ return 0;
+}
+
+static void remove_filter(AVFilterContext **filt_ctx)
+{
+ AVFilterLink *outlink = (*filt_ctx)->outputs[0];
+ AVFilterContext *src = (*filt_ctx)->inputs[0]->src;
+
+ (*filt_ctx)->outputs[0] = NULL;
+ avfilter_free(*filt_ctx);
+ *filt_ctx = NULL;
+
+ set_link_source(src, outlink);
+}
+
+static inline void log_input_change(void *ctx, AVFilterLink *link, AVFilterBufferRef *ref)
+{
+ char old_layout_str[16], new_layout_str[16];
+ av_get_channel_layout_string(old_layout_str, sizeof(old_layout_str),
+ -1, link->channel_layout);
+ av_get_channel_layout_string(new_layout_str, sizeof(new_layout_str),
+ -1, ref->audio->channel_layout);
+ av_log(ctx, AV_LOG_INFO,
+ "Audio input format changed: "
+ "%s:%s:%d -> %s:%s:%d, normalizing\n",
+ av_get_sample_fmt_name(link->format),
+ old_layout_str, (int)link->sample_rate,
+ av_get_sample_fmt_name(ref->format),
+ new_layout_str, ref->audio->sample_rate);
+}
+
+int av_asrc_buffer_add_audio_buffer_ref(AVFilterContext *ctx,
+ AVFilterBufferRef *samplesref,
+ int av_unused flags)
+{
+ ABufferSourceContext *abuffer = ctx->priv;
+ AVFilterLink *link;
+ int ret, logged = 0;
+
+ if (av_fifo_space(abuffer->fifo) < sizeof(samplesref)) {
+ av_log(ctx, AV_LOG_ERROR,
+ "Buffering limit reached. Please consume some available frames "
+ "before adding new ones.\n");
+ return AVERROR(EINVAL);
+ }
+
+ // Normalize input
+
+ link = ctx->outputs[0];
+ if (samplesref->audio->sample_rate != link->sample_rate) {
+
+ log_input_change(ctx, link, samplesref);
+ logged = 1;
+
+ abuffer->sample_rate = samplesref->audio->sample_rate;
+
+ if (!abuffer->aresample) {
+ ret = insert_filter(abuffer, link, &abuffer->aresample, "aresample");
+ if (ret < 0) return ret;
+ } else {
+ link = abuffer->aresample->outputs[0];
+ if (samplesref->audio->sample_rate == link->sample_rate)
+ remove_filter(&abuffer->aresample);
+ else
+ if ((ret = reconfigure_filter(abuffer, abuffer->aresample)) < 0)
+ return ret;
+ }
+ }
+
+ link = ctx->outputs[0];
+ if (samplesref->format != link->format ||
+ samplesref->audio->channel_layout != link->channel_layout ||
+ samplesref->audio->planar != link->planar) {
+
+ if (!logged) log_input_change(ctx, link, samplesref);
+
+ abuffer->sample_format = samplesref->format;
+ abuffer->channel_layout = samplesref->audio->channel_layout;
+ abuffer->packing_format = samplesref->audio->planar;
+
+ if (!abuffer->aconvert) {
+ ret = insert_filter(abuffer, link, &abuffer->aconvert, "aconvert");
+ if (ret < 0) return ret;
+ } else {
+ link = abuffer->aconvert->outputs[0];
+ if (samplesref->format == link->format &&
+ samplesref->audio->channel_layout == link->channel_layout &&
+ samplesref->audio->planar == link->planar
+ )
+ remove_filter(&abuffer->aconvert);
+ else
+ if ((ret = reconfigure_filter(abuffer, abuffer->aconvert)) < 0)
+ return ret;
+ }
+ }
+
+ if (sizeof(samplesref) != av_fifo_generic_write(abuffer->fifo, &samplesref,
+ sizeof(samplesref), NULL)) {
+ av_log(ctx, AV_LOG_ERROR, "Error while writing to FIFO\n");
+ return AVERROR(EINVAL);
+ }
+
+ return 0;
+}
+
+int av_asrc_buffer_add_samples(AVFilterContext *ctx,
+ uint8_t *data[8], int linesize[8],
+ int nb_samples, int sample_rate,
+ int sample_fmt, int64_t channel_layout, int planar,
+ int64_t pts, int av_unused flags)
+{
+ AVFilterBufferRef *samplesref;
+
+ samplesref = avfilter_get_audio_buffer_ref_from_arrays(
+ data, linesize, AV_PERM_WRITE,
+ nb_samples,
+ sample_fmt, channel_layout, planar);
+ if (!samplesref)
+ return AVERROR(ENOMEM);
+
+ samplesref->buf->free = buf_free;
+ samplesref->pts = pts;
+ samplesref->audio->sample_rate = sample_rate;
+
+ return av_asrc_buffer_add_audio_buffer_ref(ctx, samplesref, 0);
+}
+
+int av_asrc_buffer_add_buffer(AVFilterContext *ctx,
+ uint8_t *buf, int buf_size, int sample_rate,
+ int sample_fmt, int64_t channel_layout, int planar,
+ int64_t pts, int av_unused flags)
+{
+ uint8_t *data[8];
+ int linesize[8];
+ int nb_channels = av_get_channel_layout_nb_channels(channel_layout),
+ nb_samples = buf_size / nb_channels / av_get_bytes_per_sample(sample_fmt);
+
+ av_samples_fill_arrays(data, linesize,
+ buf, nb_channels, nb_samples,
+ sample_fmt, planar, 16);
+
+ return av_asrc_buffer_add_samples(ctx,
+ data, linesize, nb_samples,
+ sample_rate,
+ sample_fmt, channel_layout, planar,
+ pts, flags);
+}
+
+static av_cold int init(AVFilterContext *ctx, const char *args0, void *opaque)
+{
+ ABufferSourceContext *abuffer = ctx->priv;
+ char *arg = NULL, *ptr, chlayout_str[16];
+ char *args = av_strdup(args0);
+ int ret;
+
+ arg = av_strtok(args, ":", &ptr);
+
+#define ADD_FORMAT(fmt_name) \
+ if (!arg) \
+ goto arg_fail; \
+ if ((ret = ff_parse_##fmt_name(&abuffer->fmt_name, arg, ctx)) < 0) { \
+ av_freep(&args); \
+ return ret; \
+ } \
+ if (*args) \
+ arg = av_strtok(NULL, ":", &ptr)
+
+ ADD_FORMAT(sample_rate);
+ ADD_FORMAT(sample_format);
+ ADD_FORMAT(channel_layout);
+ ADD_FORMAT(packing_format);
+
+ abuffer->fifo = av_fifo_alloc(FIFO_SIZE*sizeof(AVFilterBufferRef*));
+ if (!abuffer->fifo) {
+ av_log(ctx, AV_LOG_ERROR, "Failed to allocate fifo, filter init failed.\n");
+ return AVERROR(ENOMEM);
+ }
+
+ av_get_channel_layout_string(chlayout_str, sizeof(chlayout_str),
+ -1, abuffer->channel_layout);
+ av_log(ctx, AV_LOG_INFO, "format:%s layout:%s rate:%d\n",
+ av_get_sample_fmt_name(abuffer->sample_format), chlayout_str,
+ abuffer->sample_rate);
+ av_freep(&args);
+
+ return 0;
+
+arg_fail:
+ av_log(ctx, AV_LOG_ERROR, "Invalid arguments, must be of the form "
+ "sample_rate:sample_fmt:channel_layout:packing\n");
+ av_freep(&args);
+ return AVERROR(EINVAL);
+}
+
+static av_cold void uninit(AVFilterContext *ctx)
+{
+ ABufferSourceContext *abuffer = ctx->priv;
+ av_fifo_free(abuffer->fifo);
+}
+
+static int query_formats(AVFilterContext *ctx)
+{
+ ABufferSourceContext *abuffer = ctx->priv;
+ AVFilterFormats *formats;
+
+ formats = NULL;
+ avfilter_add_format(&formats, abuffer->sample_format);
+ avfilter_set_common_sample_formats(ctx, formats);
+
+ formats = NULL;
+ avfilter_add_format(&formats, abuffer->channel_layout);
+ avfilter_set_common_channel_layouts(ctx, formats);
+
+ formats = NULL;
+ avfilter_add_format(&formats, abuffer->packing_format);
+ avfilter_set_common_packing_formats(ctx, formats);
+
+ return 0;
+}
+
+static int config_output(AVFilterLink *outlink)
+{
+ ABufferSourceContext *abuffer = outlink->src->priv;
+ outlink->sample_rate = abuffer->sample_rate;
+ return 0;
+}
+
+static int request_frame(AVFilterLink *outlink)
+{
+ ABufferSourceContext *abuffer = outlink->src->priv;
+ AVFilterBufferRef *samplesref;
+
+ if (!av_fifo_size(abuffer->fifo)) {
+ av_log(outlink->src, AV_LOG_ERROR,
+ "request_frame() called with no available frames!\n");
+ return AVERROR(EINVAL);
+ }
+
+ av_fifo_generic_read(abuffer->fifo, &samplesref, sizeof(samplesref), NULL);
+ avfilter_filter_samples(outlink, avfilter_ref_buffer(samplesref, ~0));
+ avfilter_unref_buffer(samplesref);
+
+ return 0;
+}
+
+static int poll_frame(AVFilterLink *outlink)
+{
+ ABufferSourceContext *abuffer = outlink->src->priv;
+ return av_fifo_size(abuffer->fifo)/sizeof(AVFilterBufferRef*);
+}
+
+AVFilter avfilter_asrc_abuffer = {
+ .name = "abuffer",
+ .description = NULL_IF_CONFIG_SMALL("Buffer audio frames, and make them accessible to the filterchain."),
+ .priv_size = sizeof(ABufferSourceContext),
+ .query_formats = query_formats,
+
+ .init = init,
+ .uninit = uninit,
+
+ .inputs = (AVFilterPad[]) {{ .name = NULL }},
+ .outputs = (AVFilterPad[]) {{ .name = "default",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .request_frame = request_frame,
+ .poll_frame = poll_frame,
+ .config_props = config_output, },
+ { .name = NULL}},
+};
diff --git a/libavfilter/asrc_abuffer.h b/libavfilter/asrc_abuffer.h
new file mode 100644
index 0000000000..4352c74646
--- /dev/null
+++ b/libavfilter/asrc_abuffer.h
@@ -0,0 +1,80 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVFILTER_ASRC_ABUFFER_H
+#define AVFILTER_ASRC_ABUFFER_H
+
+#include "avfilter.h"
+
+/**
+ * @file
+ * memory buffer source for audio
+ */
+
+/**
+ * Queue an audio buffer to the audio buffer source.
+ *
+ * @param abuffersrc audio source buffer context
+ * @param data pointers to the samples planes
+ * @param linesize linesizes of each audio buffer plane
+ * @param nb_samples number of samples per channel
+ * @param sample_fmt sample format of the audio data
+ * @param ch_layout channel layout of the audio data
+ * @param planar flag to indicate if audio data is planar or packed
+ * @param pts presentation timestamp of the audio buffer
+ * @param flags unused
+ */
+int av_asrc_buffer_add_samples(AVFilterContext *abuffersrc,
+ uint8_t *data[8], int linesize[8],
+ int nb_samples, int sample_rate,
+ int sample_fmt, int64_t ch_layout, int planar,
+ int64_t pts, int av_unused flags);
+
+/**
+ * Queue an audio buffer to the audio buffer source.
+ *
+ * This is similar to av_asrc_buffer_add_samples(), but the samples
+ * are stored in a buffer with known size.
+ *
+ * @param abuffersrc audio source buffer context
+ * @param buf pointer to the samples data, packed is assumed
+ * @param size the size in bytes of the buffer, it must contain an
+ * integer number of samples
+ * @param sample_fmt sample format of the audio data
+ * @param ch_layout channel layout of the audio data
+ * @param pts presentation timestamp of the audio buffer
+ * @param flags unused
+ */
+int av_asrc_buffer_add_buffer(AVFilterContext *abuffersrc,
+ uint8_t *buf, int buf_size,
+ int sample_rate,
+ int sample_fmt, int64_t ch_layout, int planar,
+ int64_t pts, int av_unused flags);
+
+/**
+ * Queue an audio buffer to the audio buffer source.
+ *
+ * @param abuffersrc audio source buffer context
+ * @param samplesref buffer ref to queue
+ * @param flags unused
+ */
+int av_asrc_buffer_add_audio_buffer_ref(AVFilterContext *abuffersrc,
+ AVFilterBufferRef *samplesref,
+ int av_unused flags);
+
+#endif /* AVFILTER_ASRC_ABUFFER_H */
diff --git a/libavfilter/asrc_aevalsrc.c b/libavfilter/asrc_aevalsrc.c
new file mode 100644
index 0000000000..c59617e4e4
--- /dev/null
+++ b/libavfilter/asrc_aevalsrc.c
@@ -0,0 +1,226 @@
+/*
+ * Copyright (c) 2011 Stefano Sabatini
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * eval audio source
+ */
+
+#include "libavutil/audioconvert.h"
+#include "libavutil/avassert.h"
+#include "libavutil/avstring.h"
+#include "libavutil/eval.h"
+#include "libavutil/opt.h"
+#include "avfilter.h"
+#include "internal.h"
+
+static const char *var_names[] = {
+ "n", ///< number of frame
+ "t", ///< timestamp expressed in seconds
+ "s", ///< sample rate
+ NULL
+};
+
+enum var_name {
+ VAR_N,
+ VAR_T,
+ VAR_S,
+ VAR_VARS_NB
+};
+
+typedef struct {
+ const AVClass *class;
+ char *sample_rate_str;
+ int sample_rate;
+ int64_t chlayout;
+ int nb_channels;
+ int64_t pts;
+ AVExpr *expr[8];
+ char *expr_str[8];
+ int nb_samples; ///< number of samples per requested frame
+ uint64_t n;
+ double var_values[VAR_VARS_NB];
+} EvalContext;
+
+#define OFFSET(x) offsetof(EvalContext, x)
+
+static const AVOption eval_options[]= {
+ { "nb_samples", "set the number of samples per requested frame", OFFSET(nb_samples), AV_OPT_TYPE_INT, {.dbl = 1024}, 0, INT_MAX },
+ { "n", "set the number of samples per requested frame", OFFSET(nb_samples), AV_OPT_TYPE_INT, {.dbl = 1024}, 0, INT_MAX },
+ { "sample_rate", "set the sample rate", OFFSET(sample_rate_str), AV_OPT_TYPE_STRING, {.str = "44100"}, CHAR_MIN, CHAR_MAX },
+ { "s", "set the sample rate", OFFSET(sample_rate_str), AV_OPT_TYPE_STRING, {.str = "44100"}, CHAR_MIN, CHAR_MAX },
+{NULL},
+};
+
+static const char *eval_get_name(void *ctx)
+{
+ return "aevalsrc";
+}
+
+static const AVClass eval_class = {
+ "AEvalSrcContext",
+ eval_get_name,
+ eval_options
+};
+
+static int init(AVFilterContext *ctx, const char *args, void *opaque)
+{
+ EvalContext *eval = ctx->priv;
+ char *args1 = av_strdup(args);
+ char *expr, *buf, *bufptr;
+ int ret, i;
+
+ eval->class = &eval_class;
+ av_opt_set_defaults(eval);
+
+ /* parse expressions */
+ buf = args1;
+ i = 0;
+ while (expr = av_strtok(buf, ":", &bufptr)) {
+ if (i >= 8) {
+ av_log(ctx, AV_LOG_ERROR,
+ "More than 8 expressions provided, unsupported.\n");
+ ret = AVERROR(EINVAL);
+ return ret;
+ }
+ ret = av_expr_parse(&eval->expr[i], expr, var_names,
+ NULL, NULL, NULL, NULL, 0, ctx);
+ if (ret < 0)
+ goto end;
+ i++;
+ if (bufptr && *bufptr == ':') { /* found last expression */
+ bufptr++;
+ break;
+ }
+ buf = NULL;
+ }
+
+ /* guess channel layout from nb expressions/channels */
+ eval->nb_channels = i;
+ eval->chlayout = av_get_default_channel_layout(eval->nb_channels);
+ if (!eval->chlayout) {
+ av_log(ctx, AV_LOG_ERROR, "Invalid number of channels '%d' provided\n",
+ eval->nb_channels);
+ ret = AVERROR(EINVAL);
+ goto end;
+ }
+
+ if (bufptr && (ret = av_set_options_string(eval, bufptr, "=", ":")) < 0)
+ goto end;
+
+ if ((ret = ff_parse_sample_rate(&eval->sample_rate, eval->sample_rate_str, ctx)))
+ goto end;
+ eval->n = 0;
+
+end:
+ av_free(args1);
+ return ret;
+}
+
+static void uninit(AVFilterContext *ctx)
+{
+ EvalContext *eval = ctx->priv;
+ int i;
+
+ for (i = 0; i < 8; i++) {
+ av_expr_free(eval->expr[i]);
+ eval->expr[i] = NULL;
+ }
+ av_freep(&eval->sample_rate_str);
+}
+
+static int config_props(AVFilterLink *outlink)
+{
+ EvalContext *eval = outlink->src->priv;
+ char buf[128];
+
+ outlink->time_base = (AVRational){1, eval->sample_rate};
+ outlink->sample_rate = eval->sample_rate;
+
+ eval->var_values[VAR_S] = eval->sample_rate;
+
+ av_get_channel_layout_string(buf, sizeof(buf), 0, eval->chlayout);
+
+ av_log(outlink->src, AV_LOG_INFO,
+ "sample_rate:%d chlayout:%s\n", eval->sample_rate, buf);
+
+ return 0;
+}
+
+static int query_formats(AVFilterContext *ctx)
+{
+ EvalContext *eval = ctx->priv;
+ enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_NONE };
+ int64_t chlayouts[] = { eval->chlayout, -1 };
+ int packing_fmts[] = { AVFILTER_PLANAR, -1 };
+
+ avfilter_set_common_sample_formats (ctx, avfilter_make_format_list(sample_fmts));
+ avfilter_set_common_channel_layouts(ctx, avfilter_make_format64_list(chlayouts));
+ avfilter_set_common_packing_formats(ctx, avfilter_make_format_list(packing_fmts));
+
+ return 0;
+}
+
+static int request_frame(AVFilterLink *outlink)
+{
+ EvalContext *eval = outlink->src->priv;
+ AVFilterBufferRef *samplesref;
+ int i, j;
+
+ samplesref = avfilter_get_audio_buffer(outlink, AV_PERM_WRITE, eval->nb_samples);
+
+ /* evaluate expression for each single sample and for each channel */
+ for (i = 0; i < eval->nb_samples; i++, eval->n++) {
+ eval->var_values[VAR_N] = eval->n;
+ eval->var_values[VAR_T] = eval->var_values[VAR_N] * (double)1/eval->sample_rate;
+
+ for (j = 0; j < eval->nb_channels; j++) {
+ *((double *) samplesref->data[j] + i) =
+ av_expr_eval(eval->expr[j], eval->var_values, NULL);
+ }
+ }
+
+ samplesref->pts = eval->pts;
+ samplesref->pos = -1;
+ samplesref->audio->sample_rate = eval->sample_rate;
+ eval->pts += eval->nb_samples;
+
+ avfilter_filter_samples(outlink, samplesref);
+
+ return 0;
+}
+
+AVFilter avfilter_asrc_aevalsrc = {
+ .name = "aevalsrc",
+ .description = NULL_IF_CONFIG_SMALL("Generate an audio signal generated by an expression."),
+
+ .query_formats = query_formats,
+ .init = init,
+ .uninit = uninit,
+ .priv_size = sizeof(EvalContext),
+
+ .inputs = (AVFilterPad[]) {{ .name = NULL}},
+
+ .outputs = (AVFilterPad[]) {{ .name = "default",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .config_props = config_props,
+ .request_frame = request_frame, },
+ { .name = NULL}},
+};
diff --git a/libavfilter/asrc_anullsrc.c b/libavfilter/asrc_anullsrc.c
index dd671c5d53..6c1a4a946d 100644
--- a/libavfilter/asrc_anullsrc.c
+++ b/libavfilter/asrc_anullsrc.c
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -21,67 +21,109 @@
* null audio source
*/
-#include "avfilter.h"
#include "libavutil/audioconvert.h"
+#include "libavutil/opt.h"
+
+#include "avfilter.h"
+#include "internal.h"
typedef struct {
+ const AVClass *class;
+ char *channel_layout_str;
int64_t channel_layout;
- int64_t sample_rate;
+ char *sample_rate_str;
+ int sample_rate;
+ int nb_samples; ///< number of samples per requested frame
+ int64_t pts;
} ANullContext;
-static int init(AVFilterContext *ctx, const char *args, void *opaque)
+#define OFFSET(x) offsetof(ANullContext, x)
+
+static const AVOption anullsrc_options[]= {
+ { "channel_layout", "set channel_layout", OFFSET(channel_layout_str), AV_OPT_TYPE_STRING, {.str = "stereo"}, 0, 0 },
+ { "cl", "set channel_layout", OFFSET(channel_layout_str), AV_OPT_TYPE_STRING, {.str = "stereo"}, 0, 0 },
+ { "sample_rate", "set sample rate", OFFSET(sample_rate_str) , AV_OPT_TYPE_STRING, {.str = "44100"}, 0, 0 },
+ { "r", "set sample rate", OFFSET(sample_rate_str) , AV_OPT_TYPE_STRING, {.str = "44100"}, 0, 0 },
+ { "nb_samples", "set the number of samples per requested frame", OFFSET(nb_samples), AV_OPT_TYPE_INT, {.dbl = 1024}, 0, INT_MAX },
+ { "n", "set the number of samples per requested frame", OFFSET(nb_samples), AV_OPT_TYPE_INT, {.dbl = 1024}, 0, INT_MAX },
+ { NULL },
+};
+
+static const char *anullsrc_get_name(void *ctx)
{
- ANullContext *priv = ctx->priv;
- char channel_layout_str[128] = "";
+ return "anullsrc";
+}
- priv->sample_rate = 44100;
- priv->channel_layout = AV_CH_LAYOUT_STEREO;
+static const AVClass anullsrc_class = {
+ "ANullSrcContext",
+ anullsrc_get_name,
+ anullsrc_options
+};
- if (args)
- sscanf(args, "%"PRId64":%s", &priv->sample_rate, channel_layout_str);
+static int init(AVFilterContext *ctx, const char *args, void *opaque)
+{
+ ANullContext *null = ctx->priv;
+ int ret;
- if (priv->sample_rate < 0) {
- av_log(ctx, AV_LOG_ERROR, "Invalid negative sample rate: %"PRId64"\n", priv->sample_rate);
- return AVERROR(EINVAL);
+ null->class = &anullsrc_class;
+ av_opt_set_defaults(null);
+
+ if ((ret = (av_set_options_string(null, args, "=", ":"))) < 0) {
+ av_log(ctx, AV_LOG_ERROR, "Error parsing options string: '%s'\n", args);
+ return ret;
}
- if (*channel_layout_str)
- if (!(priv->channel_layout = av_get_channel_layout(channel_layout_str))
- && sscanf(channel_layout_str, "%"PRId64, &priv->channel_layout) != 1) {
- av_log(ctx, AV_LOG_ERROR, "Invalid value '%s' for channel layout\n",
- channel_layout_str);
- return AVERROR(EINVAL);
- }
+ if ((ret = ff_parse_sample_rate(&null->sample_rate,
+ null->sample_rate_str, ctx)) < 0)
+ return ret;
+
+ if ((ret = ff_parse_channel_layout(&null->channel_layout,
+ null->channel_layout_str, ctx)) < 0)
+ return ret;
return 0;
}
static int config_props(AVFilterLink *outlink)
{
- ANullContext *priv = outlink->src->priv;
+ ANullContext *null = outlink->src->priv;
char buf[128];
int chans_nb;
- outlink->sample_rate = priv->sample_rate;
- outlink->channel_layout = priv->channel_layout;
+ outlink->sample_rate = null->sample_rate;
+ outlink->channel_layout = null->channel_layout;
- chans_nb = av_get_channel_layout_nb_channels(priv->channel_layout);
- av_get_channel_layout_string(buf, sizeof(buf), chans_nb, priv->channel_layout);
+ chans_nb = av_get_channel_layout_nb_channels(null->channel_layout);
+ av_get_channel_layout_string(buf, sizeof(buf), chans_nb, null->channel_layout);
av_log(outlink->src, AV_LOG_INFO,
- "sample_rate:%"PRId64 " channel_layout:%"PRId64 " channel_layout_description:'%s'\n",
- priv->sample_rate, priv->channel_layout, buf);
+ "sample_rate:%d channel_layout:'%s' nb_samples:%d\n",
+ null->sample_rate, buf, null->nb_samples);
return 0;
}
-static int request_frame(AVFilterLink *link)
+static int request_frame(AVFilterLink *outlink)
{
- return -1;
+ ANullContext *null = outlink->src->priv;
+ AVFilterBufferRef *samplesref;
+
+ samplesref =
+ avfilter_get_audio_buffer(outlink, AV_PERM_WRITE, null->nb_samples);
+ samplesref->pts = null->pts;
+ samplesref->pos = -1;
+ samplesref->audio->channel_layout = null->channel_layout;
+ samplesref->audio->sample_rate = outlink->sample_rate;
+
+ avfilter_filter_samples(outlink, avfilter_ref_buffer(samplesref, ~0));
+ avfilter_unref_buffer(samplesref);
+
+ null->pts += null->nb_samples;
+ return 0;
}
AVFilter avfilter_asrc_anullsrc = {
.name = "anullsrc",
- .description = NULL_IF_CONFIG_SMALL("Null audio source, never return audio frames."),
+ .description = NULL_IF_CONFIG_SMALL("Null audio source, return empty audio frames."),
.init = init,
.priv_size = sizeof(ANullContext),
diff --git a/libavfilter/avcodec.c b/libavfilter/avcodec.c
new file mode 100644
index 0000000000..2010040d14
--- /dev/null
+++ b/libavfilter/avcodec.c
@@ -0,0 +1,73 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * libavcodec/libavfilter gluing utilities
+ */
+
+#include "avcodec.h"
+
+void avfilter_copy_frame_props(AVFilterBufferRef *dst, const AVFrame *src)
+{
+ dst->pts = src->pts;
+ dst->pos = src->pkt_pos;
+ dst->format = src->format;
+
+ switch (dst->type) {
+ case AVMEDIA_TYPE_VIDEO:
+ dst->video->w = src->width;
+ dst->video->h = src->height;
+ dst->video->sample_aspect_ratio = src->sample_aspect_ratio;
+ dst->video->interlaced = src->interlaced_frame;
+ dst->video->top_field_first = src->top_field_first;
+ dst->video->key_frame = src->key_frame;
+ dst->video->pict_type = src->pict_type;
+ }
+}
+
+AVFilterBufferRef *avfilter_get_video_buffer_ref_from_frame(const AVFrame *frame,
+ int perms)
+{
+ AVFilterBufferRef *picref =
+ avfilter_get_video_buffer_ref_from_arrays(frame->data, frame->linesize, perms,
+ frame->width, frame->height,
+ frame->format);
+ if (!picref)
+ return NULL;
+ avfilter_copy_frame_props(picref, frame);
+ return picref;
+}
+
+int avfilter_fill_frame_from_video_buffer_ref(AVFrame *frame,
+ const AVFilterBufferRef *picref)
+{
+ if (!picref || !picref->video || !frame)
+ return AVERROR(EINVAL);
+
+ memcpy(frame->data, picref->data, sizeof(frame->data));
+ memcpy(frame->linesize, picref->linesize, sizeof(frame->linesize));
+ frame->pkt_pos = picref->pos;
+ frame->interlaced_frame = picref->video->interlaced;
+ frame->top_field_first = picref->video->top_field_first;
+ frame->key_frame = picref->video->key_frame;
+ frame->pict_type = picref->video->pict_type;
+ frame->sample_aspect_ratio = picref->video->sample_aspect_ratio;
+
+ return 0;
+}
diff --git a/libavfilter/avcodec.h b/libavfilter/avcodec.h
new file mode 100644
index 0000000000..dec5ae4a7c
--- /dev/null
+++ b/libavfilter/avcodec.h
@@ -0,0 +1,71 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVFILTER_AVCODEC_H
+#define AVFILTER_AVCODEC_H
+
+/**
+ * @file
+ * libavcodec/libavfilter gluing utilities
+ *
+ * This should be included in an application ONLY if the installed
+ * libavfilter has been compiled with libavcodec support, otherwise
+ * symbols defined below will not be available.
+ */
+
+#include "libavcodec/avcodec.h" // AVFrame
+#include "avfilter.h"
+#include "vsrc_buffer.h"
+
+/**
+ * Copy the frame properties of src to dst, without copying the actual
+ * image data.
+ */
+void avfilter_copy_frame_props(AVFilterBufferRef *dst, const AVFrame *src);
+
+/**
+ * Create and return a picref reference from the data and properties
+ * contained in frame.
+ *
+ * @param perms permissions to assign to the new buffer reference
+ */
+AVFilterBufferRef *avfilter_get_video_buffer_ref_from_frame(const AVFrame *frame, int perms);
+
+/**
+ * Fill an AVFrame with the information stored in picref.
+ *
+ * @param frame an already allocated AVFrame
+ * @param picref a video buffer reference
+ * @return 0 in case of success, a negative AVERROR code in case of
+ * failure
+ */
+int avfilter_fill_frame_from_video_buffer_ref(AVFrame *frame,
+ const AVFilterBufferRef *picref);
+
+/**
+ * Add frame data to buffer_src.
+ *
+ * @param buffer_src pointer to a buffer source context
+ * @param flags a combination of AV_VSRC_BUF_FLAG_* flags
+ * @return >= 0 in case of success, a negative AVERROR code in case of
+ * failure
+ */
+int av_vsrc_buffer_add_frame(AVFilterContext *buffer_src,
+ const AVFrame *frame, int flags);
+
+#endif /* AVFILTER_AVCODEC_H */
diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index abeae14f79..63085dc999 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -2,20 +2,20 @@
* filter layer
* Copyright (c) 2007 Bobby Bingham
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -25,6 +25,8 @@
#include "libavutil/rational.h"
#include "libavutil/audioconvert.h"
#include "libavutil/imgutils.h"
+#include "libavutil/avassert.h"
+#include "libavutil/avstring.h"
#include "avfilter.h"
#include "internal.h"
@@ -34,13 +36,22 @@ unsigned avfilter_version(void) {
const char *avfilter_configuration(void)
{
- return LIBAV_CONFIGURATION;
+ return FFMPEG_CONFIGURATION;
}
const char *avfilter_license(void)
{
#define LICENSE_PREFIX "libavfilter license: "
- return LICENSE_PREFIX LIBAV_LICENSE + sizeof(LICENSE_PREFIX) - 1;
+ return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1;
+}
+
+static void command_queue_pop(AVFilterContext *filter)
+{
+ AVFilterCommand *c= filter->command_queue;
+ av_freep(&c->arg);
+ av_freep(&c->command);
+ filter->command_queue= c->next;
+ av_free(c);
}
AVFilterBufferRef *avfilter_ref_buffer(AVFilterBufferRef *ref, int pmask)
@@ -69,14 +80,47 @@ AVFilterBufferRef *avfilter_ref_buffer(AVFilterBufferRef *ref, int pmask)
return ret;
}
+static void store_in_pool(AVFilterBufferRef *ref)
+{
+ int i;
+ AVFilterPool *pool= ref->buf->priv;
+
+ av_assert0(ref->buf->data[0]);
+
+ if (pool->count == POOL_SIZE) {
+ AVFilterBufferRef *ref1 = pool->pic[0];
+ av_freep(&ref1->video);
+ av_freep(&ref1->audio);
+ av_freep(&ref1->buf->data[0]);
+ av_freep(&ref1->buf);
+ av_free(ref1);
+ memmove(&pool->pic[0], &pool->pic[1], sizeof(void*)*(POOL_SIZE-1));
+ pool->count--;
+ pool->pic[POOL_SIZE-1] = NULL;
+ }
+
+ for (i = 0; i < POOL_SIZE; i++) {
+ if (!pool->pic[i]) {
+ pool->pic[i] = ref;
+ pool->count++;
+ break;
+ }
+ }
+}
+
void avfilter_unref_buffer(AVFilterBufferRef *ref)
{
if (!ref)
return;
- if (!(--ref->buf->refcount))
+ if (!(--ref->buf->refcount)) {
+ if (!ref->buf->free) {
+ store_in_pool(ref);
+ return;
+ }
ref->buf->free(ref->buf);
- av_free(ref->video);
- av_free(ref->audio);
+ }
+ av_freep(&ref->video);
+ av_freep(&ref->audio);
av_free(ref);
}
@@ -131,6 +175,32 @@ int avfilter_link(AVFilterContext *src, unsigned srcpad,
return 0;
}
+void avfilter_link_free(AVFilterLink **link)
+{
+ if (!*link)
+ return;
+
+ if ((*link)->pool) {
+ int i;
+ for (i = 0; i < POOL_SIZE; i++) {
+ if ((*link)->pool->pic[i]) {
+ AVFilterBufferRef *picref = (*link)->pool->pic[i];
+ /* free buffer: picrefs stored in the pool are not
+ * supposed to contain a free callback */
+ av_freep(&picref->buf->data[0]);
+ av_freep(&picref->buf);
+
+ av_freep(&picref->audio);
+ av_freep(&picref->video);
+ av_freep(&(*link)->pool->pic[i]);
+ }
+ }
+ (*link)->pool->count = 0;
+// av_freep(&(*link)->pool);
+ }
+ av_freep(link);
+}
+
int avfilter_insert_filter(AVFilterLink *link, AVFilterContext *filt,
unsigned filt_srcpad_idx, unsigned filt_dstpad_idx)
{
@@ -158,6 +228,12 @@ int avfilter_insert_filter(AVFilterLink *link, AVFilterContext *filt,
if (link->out_formats)
avfilter_formats_changeref(&link->out_formats,
&filt->outputs[filt_dstpad_idx]->out_formats);
+ if (link->out_chlayouts)
+ avfilter_formats_changeref(&link->out_chlayouts,
+ &filt->outputs[filt_dstpad_idx]->out_chlayouts);
+ if (link->out_packing)
+ avfilter_formats_changeref(&link->out_packing,
+ &filt->outputs[filt_dstpad_idx]->out_packing);
return 0;
}
@@ -170,6 +246,8 @@ int avfilter_config_links(AVFilterContext *filter)
for (i = 0; i < filter->input_count; i ++) {
AVFilterLink *link = filter->inputs[i];
+ AVFilterLink *inlink = link->src->input_count ?
+ link->src->inputs[0] : NULL;
if (!link) continue;
@@ -185,24 +263,55 @@ int avfilter_config_links(AVFilterContext *filter)
if ((ret = avfilter_config_links(link->src)) < 0)
return ret;
- if (!(config_link = link->srcpad->config_props))
- config_link = avfilter_default_config_output_link;
- if ((ret = config_link(link)) < 0)
+ if (!(config_link = link->srcpad->config_props)) {
+ if (link->src->input_count != 1) {
+ av_log(link->src, AV_LOG_ERROR, "Source filters and filters "
+ "with more than one input "
+ "must set config_props() "
+ "callbacks on all outputs\n");
+ return AVERROR(EINVAL);
+ }
+ } else if ((ret = config_link(link)) < 0)
return ret;
- if (link->time_base.num == 0 && link->time_base.den == 0)
- link->time_base = link->src && link->src->input_count ?
- link->src->inputs[0]->time_base : AV_TIME_BASE_Q;
-
- if (link->sample_aspect_ratio.num == 0 && link->sample_aspect_ratio.den == 0)
- link->sample_aspect_ratio = link->src->input_count ?
- link->src->inputs[0]->sample_aspect_ratio : (AVRational){1,1};
-
- if (link->sample_rate == 0 && link->src && link->src->input_count)
- link->sample_rate = link->src->inputs[0]->sample_rate;
-
- if (link->channel_layout == 0 && link->src && link->src->input_count)
- link->channel_layout = link->src->inputs[0]->channel_layout;
+ switch (link->type) {
+ case AVMEDIA_TYPE_VIDEO:
+ if (!link->time_base.num && !link->time_base.den)
+ link->time_base = inlink ? inlink->time_base : AV_TIME_BASE_Q;
+
+ if (!link->sample_aspect_ratio.num && !link->sample_aspect_ratio.den)
+ link->sample_aspect_ratio = inlink ?
+ inlink->sample_aspect_ratio : (AVRational){1,1};
+
+ if (inlink) {
+ if (!link->w)
+ link->w = inlink->w;
+ if (!link->h)
+ link->h = inlink->h;
+ } else if (!link->w || !link->h) {
+ av_log(link->src, AV_LOG_ERROR,
+ "Video source filters must set their output link's "
+ "width and height\n");
+ return AVERROR(EINVAL);
+ }
+ break;
+
+ case AVMEDIA_TYPE_AUDIO:
+ if (inlink) {
+ if (!link->sample_rate)
+ link->sample_rate = inlink->sample_rate;
+ if (!link->time_base.num && !link->time_base.den)
+ link->time_base = inlink->time_base;
+ } else if (!link->sample_rate) {
+ av_log(link->src, AV_LOG_ERROR,
+ "Audio source filters must set their output link's "
+ "sample_rate\n");
+ return AVERROR(EINVAL);
+ }
+
+ if (!link->time_base.num && !link->time_base.den)
+ link->time_base = (AVRational) {1, link->sample_rate};
+ }
if ((config_link = link->dstpad->config_props))
if ((ret = config_link(link)) < 0)
@@ -215,7 +324,6 @@ int avfilter_config_links(AVFilterContext *filter)
return 0;
}
-#ifdef DEBUG
static char *ff_get_ref_perms_string(char *buf, size_t buf_size, int perms)
{
snprintf(buf, buf_size, "%s%s%s%s%s%s",
@@ -227,7 +335,6 @@ static char *ff_get_ref_perms_string(char *buf, size_t buf_size, int perms)
perms & AV_PERM_NEG_LINESIZES ? "n" : "");
return buf;
}
-#endif
static void ff_dlog_ref(void *ctx, AVFilterBufferRef *ref, int end)
{
@@ -240,7 +347,7 @@ static void ff_dlog_ref(void *ctx, AVFilterBufferRef *ref, int end)
if (ref->video) {
av_dlog(ctx, " a:%d/%d s:%dx%d i:%c iskey:%d type:%c",
- ref->video->pixel_aspect.num, ref->video->pixel_aspect.den,
+ ref->video->sample_aspect_ratio.num, ref->video->sample_aspect_ratio.den,
ref->video->w, ref->video->h,
!ref->video->interlaced ? 'P' : /* Progressive */
ref->video->top_field_first ? 'T' : 'B', /* Top / Bottom */
@@ -248,10 +355,9 @@ static void ff_dlog_ref(void *ctx, AVFilterBufferRef *ref, int end)
av_get_picture_type_char(ref->video->pict_type));
}
if (ref->audio) {
- av_dlog(ctx, " cl:%"PRId64"d sn:%d s:%d sr:%d p:%d",
+ av_dlog(ctx, " cl:%"PRId64"d n:%d r:%d p:%d",
ref->audio->channel_layout,
ref->audio->nb_samples,
- ref->audio->size,
ref->audio->sample_rate,
ref->audio->planar);
}
@@ -274,8 +380,8 @@ static void ff_dlog_link(void *ctx, AVFilterLink *link, int end)
av_get_channel_layout_string(buf, sizeof(buf), -1, link->channel_layout);
av_dlog(ctx,
- "link[%p r:%"PRId64" cl:%s fmt:%-16s %-16s->%-16s]%s",
- link, link->sample_rate, buf,
+ "link[%p r:%d cl:%s fmt:%-16s %-16s->%-16s]%s",
+ link, (int)link->sample_rate, buf,
av_get_sample_fmt_name(link->format),
link->src ? link->src->filter->name : "",
link->dst ? link->dst->filter->name : "",
@@ -308,7 +414,7 @@ AVFilterBufferRef *avfilter_get_video_buffer(AVFilterLink *link, int perms, int
}
AVFilterBufferRef *
-avfilter_get_video_buffer_ref_from_arrays(uint8_t *data[4], int linesize[4], int perms,
+avfilter_get_video_buffer_ref_from_arrays(uint8_t * const data[4], const int linesize[4], int perms,
int w, int h, enum PixelFormat format)
{
AVFilterBuffer *pic = av_mallocz(sizeof(AVFilterBuffer));
@@ -347,17 +453,16 @@ fail:
return NULL;
}
-AVFilterBufferRef *avfilter_get_audio_buffer(AVFilterLink *link, int perms,
- enum AVSampleFormat sample_fmt, int size,
- int64_t channel_layout, int planar)
+AVFilterBufferRef *avfilter_get_audio_buffer(AVFilterLink *link,
+ int perms, int nb_samples)
{
AVFilterBufferRef *ret = NULL;
if (link->dstpad->get_audio_buffer)
- ret = link->dstpad->get_audio_buffer(link, perms, sample_fmt, size, channel_layout, planar);
+ ret = link->dstpad->get_audio_buffer(link, perms, nb_samples);
if (!ret)
- ret = avfilter_default_get_audio_buffer(link, perms, sample_fmt, size, channel_layout, planar);
+ ret = avfilter_default_get_audio_buffer(link, perms, nb_samples);
if (ret)
ret->type = AVMEDIA_TYPE_AUDIO;
@@ -365,6 +470,48 @@ AVFilterBufferRef *avfilter_get_audio_buffer(AVFilterLink *link, int perms,
return ret;
}
+AVFilterBufferRef *
+avfilter_get_audio_buffer_ref_from_arrays(uint8_t *data[8], int linesize[8], int perms,
+ int nb_samples, enum AVSampleFormat sample_fmt,
+ int64_t channel_layout, int planar)
+{
+ AVFilterBuffer *samples = av_mallocz(sizeof(AVFilterBuffer));
+ AVFilterBufferRef *samplesref = av_mallocz(sizeof(AVFilterBufferRef));
+
+ if (!samples || !samplesref)
+ goto fail;
+
+ samplesref->buf = samples;
+ samplesref->buf->free = ff_avfilter_default_free_buffer;
+ if (!(samplesref->audio = av_mallocz(sizeof(AVFilterBufferRefAudioProps))))
+ goto fail;
+
+ samplesref->audio->nb_samples = nb_samples;
+ samplesref->audio->channel_layout = channel_layout;
+ samplesref->audio->planar = planar;
+
+ /* make sure the buffer gets read permission or it's useless for output */
+ samplesref->perms = perms | AV_PERM_READ;
+
+ samples->refcount = 1;
+ samplesref->type = AVMEDIA_TYPE_AUDIO;
+ samplesref->format = sample_fmt;
+
+ memcpy(samples->data, data, sizeof(samples->data));
+ memcpy(samples->linesize, linesize, sizeof(samples->linesize));
+ memcpy(samplesref->data, data, sizeof(samplesref->data));
+ memcpy(samplesref->linesize, linesize, sizeof(samplesref->linesize));
+
+ return samplesref;
+
+fail:
+ if (samplesref && samplesref->audio)
+ av_freep(&samplesref->audio);
+ av_freep(&samplesref);
+ av_freep(&samples);
+ return NULL;
+}
+
int avfilter_request_frame(AVFilterLink *link)
{
FF_DPRINTF_START(NULL, request_frame); ff_dlog_link(NULL, link, 1);
@@ -401,6 +548,7 @@ void avfilter_start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
void (*start_frame)(AVFilterLink *, AVFilterBufferRef *);
AVFilterPad *dst = link->dstpad;
int perms = picref->perms;
+ AVFilterCommand *cmd= link->dst->command_queue;
FF_DPRINTF_START(NULL, start_frame); ff_dlog_link(NULL, link, 0); av_dlog(NULL, " "); ff_dlog_ref(NULL, picref, 1);
@@ -423,6 +571,15 @@ void avfilter_start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
else
link->cur_buf = picref;
+ while(cmd && cmd->time <= picref->pts * av_q2d(link->time_base)){
+ av_log(link->dst, AV_LOG_DEBUG,
+ "Processing command time:%f command:%s arg:%s\n",
+ cmd->time, cmd->command, cmd->arg);
+ avfilter_process_command(link->dst, cmd->command, cmd->arg, 0, 0, cmd->flags);
+ command_queue_pop(link->dst);
+ cmd= link->dst->command_queue;
+ }
+
start_frame(link, link->cur_buf);
}
@@ -484,10 +641,22 @@ void avfilter_draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
draw_slice(link, y, h, slice_dir);
}
+int avfilter_process_command(AVFilterContext *filter, const char *cmd, const char *arg, char *res, int res_len, int flags)
+{
+ if(!strcmp(cmd, "ping")){
+ av_strlcatf(res, res_len, "pong from:%s %s\n", filter->filter->name, filter->name);
+ return 0;
+ }else if(filter->filter->process_command) {
+ return filter->filter->process_command(filter, cmd, arg, res, res_len, flags);
+ }
+ return AVERROR(ENOSYS);
+}
+
void avfilter_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)
{
void (*filter_samples)(AVFilterLink *, AVFilterBufferRef *);
AVFilterPad *dst = link->dstpad;
+ int i;
FF_DPRINTF_START(NULL, filter_samples); ff_dlog_link(NULL, link, 1);
@@ -503,15 +672,13 @@ void avfilter_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)
samplesref->perms, link->dstpad->min_perms, link->dstpad->rej_perms);
link->cur_buf = avfilter_default_get_audio_buffer(link, dst->min_perms,
- samplesref->format,
- samplesref->audio->size,
- samplesref->audio->channel_layout,
- samplesref->audio->planar);
+ samplesref->audio->nb_samples);
link->cur_buf->pts = samplesref->pts;
link->cur_buf->audio->sample_rate = samplesref->audio->sample_rate;
/* Copy actual data into new samples buffer */
- memcpy(link->cur_buf->data[0], samplesref->data[0], samplesref->audio->size);
+ for (i = 0; samplesref->data[i]; i++)
+ memcpy(link->cur_buf->data[i], samplesref->data[i], samplesref->linesize[0]);
avfilter_unref_buffer(samplesref);
} else
@@ -651,7 +818,7 @@ void avfilter_free(AVFilterContext *filter)
avfilter_formats_unref(&link->in_formats);
avfilter_formats_unref(&link->out_formats);
}
- av_freep(&link);
+ avfilter_link_free(&link);
}
for (i = 0; i < filter->output_count; i++) {
if ((link = filter->outputs[i])) {
@@ -660,7 +827,7 @@ void avfilter_free(AVFilterContext *filter)
avfilter_formats_unref(&link->in_formats);
avfilter_formats_unref(&link->out_formats);
}
- av_freep(&link);
+ avfilter_link_free(&link);
}
av_freep(&filter->name);
@@ -669,6 +836,9 @@ void avfilter_free(AVFilterContext *filter)
av_freep(&filter->inputs);
av_freep(&filter->outputs);
av_freep(&filter->priv);
+ while(filter->command_queue){
+ command_queue_pop(filter);
+ }
av_free(filter);
}
diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
index f8295e77c5..138cc3040c 100644
--- a/libavfilter/avfilter.h
+++ b/libavfilter/avfilter.h
@@ -2,20 +2,20 @@
* filter layer
* Copyright (c) 2007 Bobby Bingham
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -29,8 +29,8 @@
#include "libavutil/rational.h"
#define LIBAVFILTER_VERSION_MAJOR 2
-#define LIBAVFILTER_VERSION_MINOR 4
-#define LIBAVFILTER_VERSION_MICRO 0
+#define LIBAVFILTER_VERSION_MINOR 44
+#define LIBAVFILTER_VERSION_MICRO 1
#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
LIBAVFILTER_VERSION_MINOR, \
@@ -40,6 +40,13 @@
LIBAVFILTER_VERSION_MICRO)
#define LIBAVFILTER_BUILD LIBAVFILTER_VERSION_INT
+#ifndef FF_API_OLD_VSINK_API
+#define FF_API_OLD_VSINK_API (LIBAVFILTER_VERSION_MAJOR < 3)
+#endif
+#ifndef FF_API_OLD_ALL_FORMATS_API
+#define FF_API_OLD_ALL_FORMATS_API (LIBAVFILTER_VERSION_MAJOR < 3)
+#endif
+
#include <stddef.h>
/**
@@ -101,9 +108,8 @@ typedef struct AVFilterBuffer {
*/
typedef struct AVFilterBufferRefAudioProps {
int64_t channel_layout; ///< channel layout of audio buffer
- int nb_samples; ///< number of audio samples
- int size; ///< audio buffer size
- uint32_t sample_rate; ///< audio buffer sample rate
+ int nb_samples; ///< number of audio samples per channel
+ int sample_rate; ///< audio buffer sample rate
int planar; ///< audio buffer - planar or packed
} AVFilterBufferRefAudioProps;
@@ -115,7 +121,7 @@ typedef struct AVFilterBufferRefAudioProps {
typedef struct AVFilterBufferRefVideoProps {
int w; ///< image width
int h; ///< image height
- AVRational pixel_aspect; ///< pixel aspect ratio
+ AVRational sample_aspect_ratio; ///< sample aspect ratio
int interlaced; ///< is frame interlaced
int top_field_first; ///< field order
enum AVPictureType pict_type; ///< picture type of the frame
@@ -163,6 +169,7 @@ static inline void avfilter_copy_buffer_ref_props(AVFilterBufferRef *dst, AVFilt
switch (src->type) {
case AVMEDIA_TYPE_VIDEO: *dst->video = *src->video; break;
case AVMEDIA_TYPE_AUDIO: *dst->audio = *src->audio; break;
+ default: break;
}
}
@@ -227,7 +234,7 @@ void avfilter_unref_buffer(AVFilterBufferRef *ref);
*/
typedef struct AVFilterFormats {
unsigned format_count; ///< number of formats
- int *formats; ///< list of media formats
+ int64_t *formats; ///< list of media formats
unsigned refcount; ///< number of references to this list
struct AVFilterFormats ***refs; ///< references to this list
@@ -237,10 +244,12 @@ typedef struct AVFilterFormats {
* Create a list of supported formats. This is intended for use in
* AVFilter->query_formats().
*
- * @param fmts list of media formats, terminated by -1
+ * @param fmts list of media formats, terminated by -1. If NULL an
+ * empty list is created.
* @return the format list, with no existing references
*/
AVFilterFormats *avfilter_make_format_list(const int *fmts);
+AVFilterFormats *avfilter_make_format64_list(const int64_t *fmts);
/**
* Add fmt to the list of media formats contained in *avff.
@@ -250,12 +259,35 @@ AVFilterFormats *avfilter_make_format_list(const int *fmts);
* @return a non negative value in case of success, or a negative
* value corresponding to an AVERROR code in case of error
*/
-int avfilter_add_format(AVFilterFormats **avff, int fmt);
+int avfilter_add_format(AVFilterFormats **avff, int64_t fmt);
+#if FF_API_OLD_ALL_FORMATS_API
/**
- * Return a list of all formats supported by Libav for the given media type.
+ * @deprecated Use avfilter_make_all_formats() instead.
*/
+attribute_deprecated
AVFilterFormats *avfilter_all_formats(enum AVMediaType type);
+#endif
+
+/**
+ * Return a list of all formats supported by FFmpeg for the given media type.
+ */
+AVFilterFormats *avfilter_make_all_formats(enum AVMediaType type);
+
+/**
+ * A list of all channel layouts supported by libavfilter.
+ */
+extern const int64_t avfilter_all_channel_layouts[];
+
+/**
+ * Return a list of all channel layouts supported by FFmpeg.
+ */
+AVFilterFormats *avfilter_make_all_channel_layouts(void);
+
+/**
+ * Return a list of all audio packing formats.
+ */
+AVFilterFormats *avfilter_make_all_packing_formats(void);
/**
* Return a format list which contains the intersection of the formats of
@@ -374,9 +406,7 @@ struct AVFilterPad {
*
* Input audio pads only.
*/
- AVFilterBufferRef *(*get_audio_buffer)(AVFilterLink *link, int perms,
- enum AVSampleFormat sample_fmt, int size,
- int64_t channel_layout, int planar);
+ AVFilterBufferRef *(*get_audio_buffer)(AVFilterLink *link, int perms, int nb_samples);
/**
* Callback called after the slices of a frame are completely sent. If
@@ -426,15 +456,18 @@ struct AVFilterPad {
/**
* Link configuration callback.
*
- * For output pads, this should set the link properties such as
- * width/height. This should NOT set the format property - that is
- * negotiated between filters by the filter system using the
+ * For output pads, this should set the following link properties:
+ * video: width, height, sample_aspect_ratio, time_base
+ * audio: sample_rate.
+ *
+ * This should NOT set properties such as format, channel_layout, etc which
+ * are negotiated between filters by the filter system using the
* query_formats() callback before this function is called.
*
* For input pads, this should check the properties of the link, and update
* the filter's internal state as necessary.
*
- * For both input and output filters, this should return zero on success,
+ * For both input and output pads, this should return zero on success,
* and another value on error.
*/
int (*config_props)(AVFilterLink *link);
@@ -452,27 +485,23 @@ void avfilter_default_end_frame(AVFilterLink *link);
/** default handler for filter_samples() for audio inputs */
void avfilter_default_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref);
-/** default handler for config_props() for audio/video outputs */
-int avfilter_default_config_output_link(AVFilterLink *link);
-
-/** default handler for config_props() for audio/video inputs */
-int avfilter_default_config_input_link (AVFilterLink *link);
-
/** default handler for get_video_buffer() for video inputs */
AVFilterBufferRef *avfilter_default_get_video_buffer(AVFilterLink *link,
int perms, int w, int h);
/** default handler for get_audio_buffer() for audio inputs */
-AVFilterBufferRef *avfilter_default_get_audio_buffer(AVFilterLink *link, int perms,
- enum AVSampleFormat sample_fmt, int size,
- int64_t channel_layout, int planar);
+AVFilterBufferRef *avfilter_default_get_audio_buffer(AVFilterLink *link,
+ int perms, int nb_samples);
/**
- * A helper for query_formats() which sets all links to the same list of
- * formats. If there are no links hooked to this filter, the list of formats is
- * freed.
+ * Helpers for query_formats() which set all links to the same list of
+ * formats/layouts. If there are no links hooked to this filter, the list
+ * of formats is freed.
*/
-void avfilter_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats);
+void avfilter_set_common_pixel_formats(AVFilterContext *ctx, AVFilterFormats *formats);
+void avfilter_set_common_sample_formats(AVFilterContext *ctx, AVFilterFormats *formats);
+void avfilter_set_common_channel_layouts(AVFilterContext *ctx, AVFilterFormats *formats);
+void avfilter_set_common_packing_formats(AVFilterContext *ctx, AVFilterFormats *formats);
/** Default handler for query_formats() */
int avfilter_default_query_formats(AVFilterContext *ctx);
@@ -494,9 +523,8 @@ AVFilterBufferRef *avfilter_null_get_video_buffer(AVFilterLink *link,
int perms, int w, int h);
/** get_audio_buffer() handler for filters which simply pass audio along */
-AVFilterBufferRef *avfilter_null_get_audio_buffer(AVFilterLink *link, int perms,
- enum AVSampleFormat sample_fmt, int size,
- int64_t channel_layout, int planar);
+AVFilterBufferRef *avfilter_null_get_audio_buffer(AVFilterLink *link,
+ int perms, int nb_samples);
/**
* Filter definition. This defines the pads a filter contains, and all the
@@ -523,9 +551,9 @@ typedef struct AVFilter {
void (*uninit)(AVFilterContext *ctx);
/**
- * Queries formats supported by the filter and its pads, and sets the
- * in_formats for links connected to its output pads, and out_formats
- * for links connected to its input pads.
+ * Queries formats/layouts supported by the filter and its pads, and sets
+ * the in_formats/in_chlayouts for links connected to its output pads,
+ * and out_formats/out_chlayouts for links connected to its input pads.
*
* @return zero on success, a negative value corresponding to an
* AVERROR code otherwise
@@ -540,6 +568,20 @@ typedef struct AVFilter {
* NULL_IF_CONFIG_SMALL() macro to define it.
*/
const char *description;
+
+ /**
+ * Make the filter instance process a command.
+ *
+ * @param cmd the command to process, for handling simplicity all commands must be alphanumeric only
+ * @param arg the argument for the command
+ * @param res a buffer with size res_size where the filter(s) can return a response. This must not change when the command is not supported.
+ * @param flags if AVFILTER_CMD_FLAG_FAST is set and the command would be
+ * timeconsuming then a filter should treat it like an unsupported command
+ *
+ * @returns >=0 on success otherwise an error code.
+ * AVERROR(ENOSYS) on unsupported commands
+ */
+ int (*process_command)(AVFilterContext *, const char *cmd, const char *arg, char *res, int res_len, int flags);
} AVFilter;
/** An instance of a filter */
@@ -559,6 +601,13 @@ struct AVFilterContext {
AVFilterLink **outputs; ///< array of pointers to output links
void *priv; ///< private data for use by the filter
+
+ struct AVFilterCommand *command_queue;
+};
+
+enum AVFilterPacking {
+ AVFILTER_PACKED = 0,
+ AVFILTER_PLANAR,
};
/**
@@ -588,20 +637,32 @@ struct AVFilterLink {
int w; ///< agreed upon image width
int h; ///< agreed upon image height
AVRational sample_aspect_ratio; ///< agreed upon sample aspect ratio
- /* These two parameters apply only to audio */
+ /* These parameters apply only to audio */
int64_t channel_layout; ///< channel layout of current buffer (see libavutil/audioconvert.h)
+#if LIBAVFILTER_VERSION_MAJOR < 3
int64_t sample_rate; ///< samples per second
+#else
+ int sample_rate; ///< samples per second
+#endif
+ int planar; ///< agreed upon packing mode of audio buffers. true if planar.
int format; ///< agreed upon media format
/**
- * Lists of formats supported by the input and output filters respectively.
- * These lists are used for negotiating the format to actually be used,
- * which will be loaded into the format member, above, when chosen.
+ * Lists of formats and channel layouts supported by the input and output
+ * filters respectively. These lists are used for negotiating the format
+ * to actually be used, which will be loaded into the format and
+ * channel_layout members, above, when chosen.
+ *
*/
AVFilterFormats *in_formats;
AVFilterFormats *out_formats;
+ AVFilterFormats *in_chlayouts;
+ AVFilterFormats *out_chlayouts;
+ AVFilterFormats *in_packing;
+ AVFilterFormats *out_packing;
+
/**
* The buffer reference currently being sent across the link by the source
* filter. This is used internally by the filter system to allow
@@ -622,6 +683,8 @@ struct AVFilterLink {
* input link is assumed to be an unchangeable property.
*/
AVRational time_base;
+
+ struct AVFilterPool *pool;
};
/**
@@ -637,6 +700,11 @@ int avfilter_link(AVFilterContext *src, unsigned srcpad,
AVFilterContext *dst, unsigned dstpad);
/**
+ * Free the link in *link, and set its pointer to NULL.
+ */
+void avfilter_link_free(AVFilterLink **link);
+
+/**
* Negotiate the media format, dimensions, etc of all inputs to a filter.
*
* @param filter the filter to negotiate the properties for its inputs
@@ -670,7 +738,7 @@ AVFilterBufferRef *avfilter_get_video_buffer(AVFilterLink *link, int perms,
* @param format the pixel format of the image specified by the data and linesize arrays
*/
AVFilterBufferRef *
-avfilter_get_video_buffer_ref_from_arrays(uint8_t *data[4], int linesize[4], int perms,
+avfilter_get_video_buffer_ref_from_arrays(uint8_t * const data[4], const int linesize[4], int perms,
int w, int h, enum PixelFormat format);
/**
@@ -679,16 +747,29 @@ avfilter_get_video_buffer_ref_from_arrays(uint8_t *data[4], int linesize[4], int
* @param link the output link to the filter from which the buffer will
* be requested
* @param perms the required access permissions
- * @param sample_fmt the format of each sample in the buffer to allocate
- * @param size the buffer size in bytes
- * @param channel_layout the number and type of channels per sample in the buffer to allocate
- * @param planar audio data layout - planar or packed
+ * @param nb_samples the number of samples per channel
* @return A reference to the samples. This must be unreferenced with
* avfilter_unref_buffer when you are finished with it.
*/
AVFilterBufferRef *avfilter_get_audio_buffer(AVFilterLink *link, int perms,
- enum AVSampleFormat sample_fmt, int size,
- int64_t channel_layout, int planar);
+ int nb_samples);
+
+/**
+ * Create an audio buffer reference wrapped around an already
+ * allocated samples buffer.
+ *
+ * @param data pointers to the samples plane buffers
+ * @param linesize linesize for the samples plane buffers
+ * @param perms the required access permissions
+ * @param nb_samples number of samples per channel
+ * @param sample_fmt the format of each sample in the buffer to allocate
+ * @param channel_layout the channel layout of the buffer
+ * @param planar audio data layout - planar or packed
+ */
+AVFilterBufferRef *
+avfilter_get_audio_buffer_ref_from_arrays(uint8_t *data[8], int linesize[8], int perms,
+ int nb_samples, enum AVSampleFormat sample_fmt,
+ int64_t channel_layout, int planar);
/**
* Request an input frame from the filter at the other end of the link.
@@ -742,6 +823,15 @@ void avfilter_end_frame(AVFilterLink *link);
*/
void avfilter_draw_slice(AVFilterLink *link, int y, int h, int slice_dir);
+#define AVFILTER_CMD_FLAG_ONE 1 ///< Stop once a filter understood the command (for target=all for example), fast filters are favored automatically
+#define AVFILTER_CMD_FLAG_FAST 2 ///< Only execute command when its fast (like a video out that supports contrast adjustment in hw)
+
+/**
+ * Make the filter instance process a command.
+ * It is recommanded to use avfilter_graph_send_command().
+ */
+int avfilter_process_command(AVFilterContext *filter, const char *cmd, const char *arg, char *res, int res_len, int flags);
+
/**
* Send a buffer of audio samples to the next filter.
*
diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
index b503c366f8..c97e495c96 100644
--- a/libavfilter/avfiltergraph.c
+++ b/libavfilter/avfiltergraph.c
@@ -3,26 +3,27 @@
* Copyright (c) 2008 Vitor Sessak
* Copyright (c) 2007 Bobby Bingham
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <ctype.h>
#include <string.h>
+#include "libavutil/audioconvert.h"
#include "avfilter.h"
#include "avfiltergraph.h"
#include "internal.h"
@@ -90,7 +91,7 @@ int ff_avfilter_graph_check_validity(AVFilterGraph *graph, AVClass *log_ctx)
av_log(log_ctx, AV_LOG_ERROR,
"Input pad \"%s\" for the filter \"%s\" of type \"%s\" not connected to any source\n",
filt->input_pads[j].name, filt->name, filt->filter->name);
- return -1;
+ return AVERROR(EINVAL);
}
}
@@ -99,7 +100,7 @@ int ff_avfilter_graph_check_validity(AVFilterGraph *graph, AVClass *log_ctx)
av_log(log_ctx, AV_LOG_ERROR,
"Output pad \"%s\" for the filter \"%s\" of type \"%s\" not connected to any destination\n",
filt->output_pads[j].name, filt->name, filt->filter->name);
- return -1;
+ return AVERROR(EINVAL);
}
}
}
@@ -135,11 +136,57 @@ AVFilterContext *avfilter_graph_get_filter(AVFilterGraph *graph, char *name)
return NULL;
}
+static int insert_conv_filter(AVFilterGraph *graph, AVFilterLink *link,
+ const char *filt_name, const char *filt_args)
+{
+ static int auto_count = 0, ret;
+ char inst_name[32];
+ AVFilterContext *filt_ctx;
+
+ snprintf(inst_name, sizeof(inst_name), "auto-inserted %s %d",
+ filt_name, auto_count++);
+
+ if ((ret = avfilter_graph_create_filter(&filt_ctx,
+ avfilter_get_by_name(filt_name),
+ inst_name, filt_args, NULL, graph)) < 0)
+ return ret;
+ if ((ret = avfilter_insert_filter(link, filt_ctx, 0, 0)) < 0)
+ return ret;
+
+ filt_ctx->filter->query_formats(filt_ctx);
+
+ if ( ((link = filt_ctx-> inputs[0]) &&
+ !avfilter_merge_formats(link->in_formats, link->out_formats)) ||
+ ((link = filt_ctx->outputs[0]) &&
+ !avfilter_merge_formats(link->in_formats, link->out_formats))
+ ) {
+ av_log(NULL, AV_LOG_ERROR,
+ "Impossible to convert between the formats supported by the filter "
+ "'%s' and the filter '%s'\n", link->src->name, link->dst->name);
+ return AVERROR(EINVAL);
+ }
+
+ if (link->type == AVMEDIA_TYPE_AUDIO &&
+ (((link = filt_ctx-> inputs[0]) &&
+ (!avfilter_merge_formats(link->in_chlayouts, link->out_chlayouts) ||
+ !avfilter_merge_formats(link->in_packing, link->out_packing))) ||
+ ((link = filt_ctx->outputs[0]) &&
+ (!avfilter_merge_formats(link->in_chlayouts, link->out_chlayouts) ||
+ !avfilter_merge_formats(link->in_packing, link->out_packing))))
+ ) {
+ av_log(NULL, AV_LOG_ERROR,
+ "Impossible to convert between the channel layouts/packing formats supported by the filter "
+ "'%s' and the filter '%s'\n", link->src->name, link->dst->name);
+ return AVERROR(EINVAL);
+ }
+
+ return 0;
+}
+
static int query_formats(AVFilterGraph *graph, AVClass *log_ctx)
{
int i, j, ret;
- int scaler_count = 0;
- char inst_name[30];
+ char filt_args[128];
/* ask all the sub-filters for their supported media formats */
for (i = 0; i < graph->filter_count; i++) {
@@ -155,32 +202,30 @@ static int query_formats(AVFilterGraph *graph, AVClass *log_ctx)
for (j = 0; j < filter->input_count; j++) {
AVFilterLink *link = filter->inputs[j];
- if (link && link->in_formats != link->out_formats) {
- if (!avfilter_merge_formats(link->in_formats,
- link->out_formats)) {
- AVFilterContext *scale;
- char scale_args[256];
- /* couldn't merge format lists. auto-insert scale filter */
- snprintf(inst_name, sizeof(inst_name), "auto-inserted scaler %d",
- scaler_count++);
- snprintf(scale_args, sizeof(scale_args), "0:0:%s", graph->scale_sws_opts);
- if ((ret = avfilter_graph_create_filter(&scale, avfilter_get_by_name("scale"),
- inst_name, scale_args, NULL, graph)) < 0)
- return ret;
- if ((ret = avfilter_insert_filter(link, scale, 0, 0)) < 0)
- return ret;
-
- scale->filter->query_formats(scale);
- if (((link = scale-> inputs[0]) &&
- !avfilter_merge_formats(link->in_formats, link->out_formats)) ||
- ((link = scale->outputs[0]) &&
- !avfilter_merge_formats(link->in_formats, link->out_formats))) {
- av_log(log_ctx, AV_LOG_ERROR,
- "Impossible to convert between the formats supported by the filter "
- "'%s' and the filter '%s'\n", link->src->name, link->dst->name);
- return -1;
- }
- }
+ if (!link) continue;
+
+ if (!link->in_formats || !link->out_formats)
+ return AVERROR(EINVAL);
+
+ if (link->type == AVMEDIA_TYPE_VIDEO &&
+ !avfilter_merge_formats(link->in_formats, link->out_formats)) {
+
+ /* couldn't merge format lists, auto-insert scale filter */
+ snprintf(filt_args, sizeof(filt_args), "0:0:%s",
+ graph->scale_sws_opts);
+ if (ret = insert_conv_filter(graph, link, "scale", filt_args))
+ return ret;
+ }
+ else if (link->type == AVMEDIA_TYPE_AUDIO) {
+ if (!link->in_chlayouts || !link->out_chlayouts ||
+ !link->in_packing || !link->out_packing)
+ return AVERROR(EINVAL);
+
+ if (!avfilter_merge_formats(link->in_formats, link->out_formats) ||
+ !avfilter_merge_formats(link->in_chlayouts, link->out_chlayouts) ||
+ !avfilter_merge_formats(link->in_packing, link->out_packing))
+ if (ret = insert_conv_filter(graph, link, "aconvert", NULL))
+ return ret;
}
}
}
@@ -195,9 +240,20 @@ static void pick_format(AVFilterLink *link)
link->in_formats->format_count = 1;
link->format = link->in_formats->formats[0];
-
avfilter_formats_unref(&link->in_formats);
avfilter_formats_unref(&link->out_formats);
+
+ if (link->type == AVMEDIA_TYPE_AUDIO) {
+ link->in_chlayouts->format_count = 1;
+ link->channel_layout = link->in_chlayouts->formats[0];
+ avfilter_formats_unref(&link->in_chlayouts);
+ avfilter_formats_unref(&link->out_chlayouts);
+
+ link->in_packing->format_count = 1;
+ link->planar = link->in_packing->formats[0] == AVFILTER_PLANAR;
+ avfilter_formats_unref(&link->in_packing);
+ avfilter_formats_unref(&link->out_packing);
+ }
}
static void pick_formats(AVFilterGraph *graph)
@@ -216,9 +272,11 @@ static void pick_formats(AVFilterGraph *graph)
int ff_avfilter_graph_config_formats(AVFilterGraph *graph, AVClass *log_ctx)
{
+ int ret;
+
/* find supported formats from sub-filters, and merge along links */
- if (query_formats(graph, log_ctx))
- return -1;
+ if ((ret = query_formats(graph, log_ctx)) < 0)
+ return ret;
/* Once everything is merged, it's possible that we'll still have
* multiple valid media format choices. We pick the first one. */
@@ -227,7 +285,7 @@ int ff_avfilter_graph_config_formats(AVFilterGraph *graph, AVClass *log_ctx)
return 0;
}
-int avfilter_graph_config(AVFilterGraph *graphctx, AVClass *log_ctx)
+int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx)
{
int ret;
@@ -240,3 +298,61 @@ int avfilter_graph_config(AVFilterGraph *graphctx, AVClass *log_ctx)
return 0;
}
+
+int avfilter_graph_send_command(AVFilterGraph *graph, const char *target, const char *cmd, const char *arg, char *res, int res_len, int flags)
+{
+ int i, r = AVERROR(ENOSYS);
+
+ if(!graph)
+ return r;
+
+ if((flags & AVFILTER_CMD_FLAG_ONE) && !(flags & AVFILTER_CMD_FLAG_FAST)) {
+ r=avfilter_graph_send_command(graph, target, cmd, arg, res, res_len, flags | AVFILTER_CMD_FLAG_FAST);
+ if(r != AVERROR(ENOSYS))
+ return r;
+ }
+
+ if(res_len && res)
+ res[0]= 0;
+
+ for (i = 0; i < graph->filter_count; i++) {
+ AVFilterContext *filter = graph->filters[i];
+ if(!strcmp(target, "all") || (filter->name && !strcmp(target, filter->name)) || !strcmp(target, filter->filter->name)){
+ r = avfilter_process_command(filter, cmd, arg, res, res_len, flags);
+ if(r != AVERROR(ENOSYS)) {
+ if((flags & AVFILTER_CMD_FLAG_ONE) || r<0)
+ return r;
+ }
+ }
+ }
+
+ return r;
+}
+
+int avfilter_graph_queue_command(AVFilterGraph *graph, const char *target, const char *command, const char *arg, int flags, double ts)
+{
+ int i;
+
+ if(!graph)
+ return 0;
+
+ for (i = 0; i < graph->filter_count; i++) {
+ AVFilterContext *filter = graph->filters[i];
+ if(filter && (!strcmp(target, "all") || !strcmp(target, filter->name) || !strcmp(target, filter->filter->name))){
+ AVFilterCommand **que = &filter->command_queue, *next;
+ while(*que && (*que)->time <= ts)
+ que = &(*que)->next;
+ next= *que;
+ *que= av_mallocz(sizeof(AVFilterCommand));
+ (*que)->command = av_strdup(command);
+ (*que)->arg = av_strdup(arg);
+ (*que)->time = ts;
+ (*que)->flags = flags;
+ (*que)->next = next;
+ if(flags & AVFILTER_CMD_FLAG_ONE)
+ return 0;
+ }
+ }
+
+ return 0;
+}
diff --git a/libavfilter/avfiltergraph.h b/libavfilter/avfiltergraph.h
index a0f6b2e01f..76fb8aed43 100644
--- a/libavfilter/avfiltergraph.h
+++ b/libavfilter/avfiltergraph.h
@@ -2,20 +2,20 @@
* Filter graphs
* copyright (c) 2007 Bobby Bingham
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -76,7 +76,7 @@ int avfilter_graph_create_filter(AVFilterContext **filt_ctx, AVFilter *filt,
* @param log_ctx context used for logging
* @return 0 in case of success, a negative AVERROR code otherwise
*/
-int avfilter_graph_config(AVFilterGraph *graphctx, AVClass *log_ctx);
+int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx);
/**
* Free a graph, destroy its links, and set *graph to NULL.
@@ -108,16 +108,68 @@ typedef struct AVFilterInOut {
} AVFilterInOut;
/**
+ * Create an AVFilterInOut.
+ * Must be free with avfilter_inout_free().
+ */
+AVFilterInOut *avfilter_inout_alloc(void);
+
+/**
+ * Free the AVFilterInOut in *inout, and set its pointer to NULL.
+ * If *inout is NULL, do nothing.
+ */
+void avfilter_inout_free(AVFilterInOut **inout);
+
+/**
* Add a graph described by a string to a graph.
*
* @param graph the filter graph where to link the parsed graph context
* @param filters string to be parsed
- * @param inputs linked list to the inputs of the graph
- * @param outputs linked list to the outputs of the graph
+ * @param inputs pointer to a linked list to the inputs of the graph, may be NULL.
+ * If non-NULL, *inputs is updated to contain the list of open inputs
+ * after the parsing, should be freed with avfilter_inout_free().
+ * @param outputs pointer to a linked list to the outputs of the graph, may be NULL.
+ * If non-NULL, *outputs is updated to contain the list of open outputs
+ * after the parsing, should be freed with avfilter_inout_free().
* @return zero on success, a negative AVERROR code on error
*/
int avfilter_graph_parse(AVFilterGraph *graph, const char *filters,
- AVFilterInOut *inputs, AVFilterInOut *outputs,
- AVClass *log_ctx);
+ AVFilterInOut **inputs, AVFilterInOut **outputs,
+ void *log_ctx);
+
+/**
+ * Send a command to one or more filter instances.
+ *
+ * @param graph the filter graph
+ * @param target the filter(s) to which the command should be sent
+ * "all" sends to all filters
+ * otherwise it can be a filter or filter instance name
+ * which will send the command to all matching filters.
+ * @param cmd the command to sent, for handling simplicity all commands must be alphanumeric only
+ * @param arg the argument for the command
+ * @param res a buffer with size res_size where the filter(s) can return a response.
+ *
+ * @returns >=0 on success otherwise an error code.
+ * AVERROR(ENOSYS) on unsupported commands
+ */
+int avfilter_graph_send_command(AVFilterGraph *graph, const char *target, const char *cmd, const char *arg, char *res, int res_len, int flags);
+
+/**
+ * Queue a command for one or more filter instances.
+ *
+ * @param graph the filter graph
+ * @param target the filter(s) to which the command should be sent
+ * "all" sends to all filters
+ * otherwise it can be a filter or filter instance name
+ * which will send the command to all matching filters.
+ * @param cmd the command to sent, for handling simplicity all commands must be alphanummeric only
+ * @param arg the argument for the command
+ * @param ts time at which the command should be sent to the filter
+ *
+ * @note As this executes commands after this function returns, no return code
+ * from the filter is provided, also AVFILTER_CMD_FLAG_ONE is not supported.
+ */
+int avfilter_graph_queue_command(AVFilterGraph *graph, const char *target, const char *cmd, const char *arg, int flags, double ts);
+
+
#endif /* AVFILTER_AVFILTERGRAPH_H */
diff --git a/libavfilter/buffersink.h b/libavfilter/buffersink.h
new file mode 100644
index 0000000000..c5ae7dcdd0
--- /dev/null
+++ b/libavfilter/buffersink.h
@@ -0,0 +1,88 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVFILTER_VSINK_BUFFER_H
+#define AVFILTER_VSINK_BUFFER_H
+
+/**
+ * @file
+ * memory buffer sink API for audio and video
+ */
+
+#include "avfilter.h"
+
+/**
+ * Struct to use for initializing a buffersink context.
+ */
+typedef struct {
+ const enum PixelFormat *pixel_fmts; ///< list of allowed pixel formats, terminated by PIX_FMT_NONE
+} AVBufferSinkParams;
+
+/**
+ * Create an AVBufferSinkParams structure.
+ *
+ * Must be freed with av_free().
+ */
+AVBufferSinkParams *av_buffersink_params_alloc(void);
+
+/**
+ * Struct to use for initializing an abuffersink context.
+ */
+typedef struct {
+ const enum AVSampleFormat *sample_fmts; ///< list of allowed sample formats, terminated by AV_SAMPLE_FMT_NONE
+ const int64_t *channel_layouts; ///< list of allowed channel layouts, terminated by -1
+ const int *packing_fmts; ///< list of allowed packing formats
+} AVABufferSinkParams;
+
+/**
+ * Create an AVABufferSinkParams structure.
+ *
+ * Must be freed with av_free().
+ */
+AVABufferSinkParams *av_abuffersink_params_alloc(void);
+
+/**
+ * Tell av_buffersink_get_buffer_ref() to read video/samples buffer
+ * reference, but not remove it from the buffer. This is useful if you
+ * need only to read a video/samples buffer, without to fetch it.
+ */
+#define AV_BUFFERSINK_FLAG_PEEK 1
+
+/**
+ * Get an audio/video buffer data from buffer_sink and put it in bufref.
+ *
+ * This function works with both audio and video buffer sinks.
+ *
+ * @param buffer_sink pointer to a buffersink or abuffersink context
+ * @param flags a combination of AV_BUFFERSINK_FLAG_* flags
+ * @return >= 0 in case of success, a negative AVERROR code in case of
+ * failure
+ */
+int av_buffersink_get_buffer_ref(AVFilterContext *buffer_sink,
+ AVFilterBufferRef **bufref, int flags);
+
+#if FF_API_OLD_VSINK_API
+/**
+ * @deprecated Use av_buffersink_get_buffer_ref() instead.
+ */
+attribute_deprecated
+int av_vsink_buffer_get_video_buffer_ref(AVFilterContext *buffer_sink,
+ AVFilterBufferRef **picref, int flags);
+#endif
+
+#endif /* AVFILTER_VSINK_BUFFER_H */
diff --git a/libavfilter/defaults.c b/libavfilter/defaults.c
index b891ab1f22..79fb38d70f 100644
--- a/libavfilter/defaults.c
+++ b/libavfilter/defaults.c
@@ -2,20 +2,20 @@
* Filter layer - default implementations
* Copyright (c) 2007 Bobby Bingham
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -25,7 +25,6 @@
#include "avfilter.h"
#include "internal.h"
-/* TODO: buffer pool. see comment for avfilter_default_get_video_buffer() */
void ff_avfilter_default_free_buffer(AVFilterBuffer *ptr)
{
av_free(ptr->data[0]);
@@ -39,10 +38,32 @@ AVFilterBufferRef *avfilter_default_get_video_buffer(AVFilterLink *link, int per
{
int linesize[4];
uint8_t *data[4];
+ int i;
AVFilterBufferRef *picref = NULL;
+ AVFilterPool *pool = link->pool;
+
+ if (pool) {
+ for (i = 0; i < POOL_SIZE; i++) {
+ picref = pool->pic[i];
+ if (picref && picref->buf->format == link->format && picref->buf->w == w && picref->buf->h == h) {
+ AVFilterBuffer *pic = picref->buf;
+ pool->pic[i] = NULL;
+ pool->count--;
+ picref->video->w = w;
+ picref->video->h = h;
+ picref->perms = perms | AV_PERM_READ;
+ picref->format = link->format;
+ pic->refcount = 1;
+ memcpy(picref->data, pic->data, sizeof(picref->data));
+ memcpy(picref->linesize, pic->linesize, sizeof(picref->linesize));
+ return picref;
+ }
+ }
+ } else
+ pool = link->pool = av_mallocz(sizeof(AVFilterPool));
- // +2 is needed for swscaler, +16 to be SIMD-friendly
- if (av_image_alloc(data, linesize, w, h, link->format, 16) < 0)
+ // align: +2 is needed for swscaler, +16 to be SIMD-friendly
+ if ((i = av_image_alloc(data, linesize, w, h, link->format, 16)) < 0)
return NULL;
picref = avfilter_get_video_buffer_ref_from_arrays(data, linesize,
@@ -51,86 +72,38 @@ AVFilterBufferRef *avfilter_default_get_video_buffer(AVFilterLink *link, int per
av_free(data[0]);
return NULL;
}
+ memset(data[0], 128, i);
+
+ picref->buf->priv = pool;
+ picref->buf->free = NULL;
return picref;
}
AVFilterBufferRef *avfilter_default_get_audio_buffer(AVFilterLink *link, int perms,
- enum AVSampleFormat sample_fmt, int size,
- int64_t channel_layout, int planar)
+ int nb_samples)
{
- AVFilterBuffer *samples = av_mallocz(sizeof(AVFilterBuffer));
- AVFilterBufferRef *ref = NULL;
- int i, sample_size, chans_nb, bufsize, per_channel_size, step_size = 0;
- char *buf;
-
- if (!samples || !(ref = av_mallocz(sizeof(AVFilterBufferRef))))
- goto fail;
-
- ref->buf = samples;
- ref->format = sample_fmt;
-
- ref->audio = av_mallocz(sizeof(AVFilterBufferRefAudioProps));
- if (!ref->audio)
- goto fail;
-
- ref->audio->channel_layout = channel_layout;
- ref->audio->size = size;
- ref->audio->planar = planar;
-
- /* make sure the buffer gets read permission or it's useless for output */
- ref->perms = perms | AV_PERM_READ;
-
- samples->refcount = 1;
- samples->free = ff_avfilter_default_free_buffer;
-
- sample_size = av_get_bytes_per_sample(sample_fmt);
- chans_nb = av_get_channel_layout_nb_channels(channel_layout);
-
- per_channel_size = size/chans_nb;
- ref->audio->nb_samples = per_channel_size/sample_size;
-
- /* Set the number of bytes to traverse to reach next sample of a particular channel:
- * For planar, this is simply the sample size.
- * For packed, this is the number of samples * sample_size.
- */
- for (i = 0; i < chans_nb; i++)
- samples->linesize[i] = planar > 0 ? per_channel_size : sample_size;
- memset(&samples->linesize[chans_nb], 0, (8-chans_nb) * sizeof(samples->linesize[0]));
+ AVFilterBufferRef *samplesref = NULL;
+ int linesize[8];
+ uint8_t *data[8];
+ int nb_channels = av_get_channel_layout_nb_channels(link->channel_layout);
/* Calculate total buffer size, round to multiple of 16 to be SIMD friendly */
- bufsize = (size + 15)&~15;
- buf = av_malloc(bufsize);
- if (!buf)
- goto fail;
-
- /* For planar, set the start point of each channel's data within the buffer
- * For packed, set the start point of the entire buffer only
- */
- samples->data[0] = buf;
- if (buf && planar) {
- for (i = 1; i < chans_nb; i++) {
- step_size += per_channel_size;
- samples->data[i] = buf + step_size;
- }
- } else {
- for (i = 1; i < chans_nb; i++)
- samples->data[i] = buf;
- }
-
- memset(&samples->data[chans_nb], 0, (8-chans_nb) * sizeof(samples->data[0]));
-
- memcpy(ref->data, samples->data, sizeof(ref->data));
- memcpy(ref->linesize, samples->linesize, sizeof(ref->linesize));
+ if (av_samples_alloc(data, linesize,
+ nb_channels, nb_samples, link->format,
+ link->planar, 16) < 0)
+ return NULL;
- return ref;
+ samplesref =
+ avfilter_get_audio_buffer_ref_from_arrays(data, linesize, perms,
+ nb_samples, link->format,
+ link->channel_layout, link->planar);
+ if (!samplesref) {
+ av_free(data[0]);
+ return NULL;
+ }
-fail:
- if (ref)
- av_free(ref->audio);
- av_free(ref);
- av_free(samples);
- return NULL;
+ return samplesref;
}
void avfilter_default_start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
@@ -186,10 +159,8 @@ void avfilter_default_filter_samples(AVFilterLink *inlink, AVFilterBufferRef *sa
outlink = inlink->dst->outputs[0];
if (outlink) {
- outlink->out_buf = avfilter_default_get_audio_buffer(inlink, AV_PERM_WRITE, samplesref->format,
- samplesref->audio->size,
- samplesref->audio->channel_layout,
- samplesref->audio->planar);
+ outlink->out_buf = avfilter_default_get_audio_buffer(inlink, AV_PERM_WRITE,
+ samplesref->audio->nb_samples);
outlink->out_buf->pts = samplesref->pts;
outlink->out_buf->audio->sample_rate = samplesref->audio->sample_rate;
avfilter_filter_samples(outlink, avfilter_ref_buffer(outlink->out_buf, ~0));
@@ -200,68 +171,62 @@ void avfilter_default_filter_samples(AVFilterLink *inlink, AVFilterBufferRef *sa
inlink->cur_buf = NULL;
}
-/**
- * default config_link() implementation for output video links to simplify
- * the implementation of one input one output video filters */
-int avfilter_default_config_output_link(AVFilterLink *link)
+static void set_common_formats(AVFilterContext *ctx, AVFilterFormats *fmts,
+ enum AVMediaType type, int offin, int offout)
{
- if (link->src->input_count && link->src->inputs[0]) {
- if (link->type == AVMEDIA_TYPE_VIDEO) {
- link->w = link->src->inputs[0]->w;
- link->h = link->src->inputs[0]->h;
- link->time_base = link->src->inputs[0]->time_base;
- } else if (link->type == AVMEDIA_TYPE_AUDIO) {
- link->channel_layout = link->src->inputs[0]->channel_layout;
- link->sample_rate = link->src->inputs[0]->sample_rate;
- }
- } else {
- /* XXX: any non-simple filter which would cause this branch to be taken
- * really should implement its own config_props() for this link. */
- return -1;
+ int i;
+ for (i = 0; i < ctx->input_count; i++)
+ if (ctx->inputs[i] && ctx->inputs[i]->type == type)
+ avfilter_formats_ref(fmts,
+ (AVFilterFormats **)((uint8_t *)ctx->inputs[i]+offout));
+
+ for (i = 0; i < ctx->output_count; i++)
+ if (ctx->outputs[i] && ctx->outputs[i]->type == type)
+ avfilter_formats_ref(fmts,
+ (AVFilterFormats **)((uint8_t *)ctx->outputs[i]+offin));
+
+ if (!fmts->refcount) {
+ av_free(fmts->formats);
+ av_free(fmts->refs);
+ av_free(fmts);
}
+}
- return 0;
+void avfilter_set_common_pixel_formats(AVFilterContext *ctx, AVFilterFormats *formats)
+{
+ set_common_formats(ctx, formats, AVMEDIA_TYPE_VIDEO,
+ offsetof(AVFilterLink, in_formats),
+ offsetof(AVFilterLink, out_formats));
}
-/**
- * A helper for query_formats() which sets all links to the same list of
- * formats. If there are no links hooked to this filter, the list of formats is
- * freed.
- *
- * FIXME: this will need changed for filters with a mix of pad types
- * (video + audio, etc)
- */
-void avfilter_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
+void avfilter_set_common_sample_formats(AVFilterContext *ctx, AVFilterFormats *formats)
{
- int count = 0, i;
+ set_common_formats(ctx, formats, AVMEDIA_TYPE_AUDIO,
+ offsetof(AVFilterLink, in_formats),
+ offsetof(AVFilterLink, out_formats));
+}
- for (i = 0; i < ctx->input_count; i++) {
- if (ctx->inputs[i]) {
- avfilter_formats_ref(formats, &ctx->inputs[i]->out_formats);
- count++;
- }
- }
- for (i = 0; i < ctx->output_count; i++) {
- if (ctx->outputs[i]) {
- avfilter_formats_ref(formats, &ctx->outputs[i]->in_formats);
- count++;
- }
- }
+void avfilter_set_common_channel_layouts(AVFilterContext *ctx, AVFilterFormats *formats)
+{
+ set_common_formats(ctx, formats, AVMEDIA_TYPE_AUDIO,
+ offsetof(AVFilterLink, in_chlayouts),
+ offsetof(AVFilterLink, out_chlayouts));
+}
- if (!count) {
- av_free(formats->formats);
- av_free(formats->refs);
- av_free(formats);
- }
+void avfilter_set_common_packing_formats(AVFilterContext *ctx, AVFilterFormats *formats)
+{
+ set_common_formats(ctx, formats, AVMEDIA_TYPE_AUDIO,
+ offsetof(AVFilterLink, in_packing),
+ offsetof(AVFilterLink, out_packing));
}
int avfilter_default_query_formats(AVFilterContext *ctx)
{
- enum AVMediaType type = ctx->inputs && ctx->inputs [0] ? ctx->inputs [0]->type :
- ctx->outputs && ctx->outputs[0] ? ctx->outputs[0]->type :
- AVMEDIA_TYPE_VIDEO;
+ avfilter_set_common_pixel_formats(ctx, avfilter_make_all_formats(AVMEDIA_TYPE_VIDEO));
+ avfilter_set_common_sample_formats(ctx, avfilter_make_all_formats(AVMEDIA_TYPE_AUDIO));
+ avfilter_set_common_channel_layouts(ctx, avfilter_make_all_channel_layouts());
+ avfilter_set_common_packing_formats(ctx, avfilter_make_all_packing_formats());
- avfilter_set_common_formats(ctx, avfilter_all_formats(type));
return 0;
}
@@ -291,10 +256,8 @@ AVFilterBufferRef *avfilter_null_get_video_buffer(AVFilterLink *link, int perms,
}
AVFilterBufferRef *avfilter_null_get_audio_buffer(AVFilterLink *link, int perms,
- enum AVSampleFormat sample_fmt, int size,
- int64_t channel_layout, int packed)
+ int nb_samples)
{
- return avfilter_get_audio_buffer(link->dst->outputs[0], perms, sample_fmt,
- size, channel_layout, packed);
+ return avfilter_get_audio_buffer(link->dst->outputs[0], perms, nb_samples);
}
diff --git a/libavfilter/drawutils.c b/libavfilter/drawutils.c
index 6aaf5c5866..dd9ceff117 100644
--- a/libavfilter/drawutils.c
+++ b/libavfilter/drawutils.c
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavfilter/drawutils.h b/libavfilter/drawutils.h
index 7b11c06694..e838660579 100644
--- a/libavfilter/drawutils.h
+++ b/libavfilter/drawutils.h
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavfilter/formats.c b/libavfilter/formats.c
index bb7b921552..46698ef990 100644
--- a/libavfilter/formats.c
+++ b/libavfilter/formats.c
@@ -2,25 +2,28 @@
* Filter layer - format negotiation
* Copyright (c) 2007 Bobby Bingham
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include "libavutil/eval.h"
#include "libavutil/pixdesc.h"
+#include "libavutil/audioconvert.h"
#include "avfilter.h"
+#include "internal.h"
/**
* Add all refs from a to ret and destroy a.
@@ -29,7 +32,7 @@ static void merge_ref(AVFilterFormats *ret, AVFilterFormats *a)
{
int i;
- for(i = 0; i < a->refcount; i ++) {
+ for (i = 0; i < a->refcount; i++) {
ret->refs[ret->refcount] = a->refs[i];
*ret->refs[ret->refcount++] = ret;
}
@@ -44,19 +47,21 @@ AVFilterFormats *avfilter_merge_formats(AVFilterFormats *a, AVFilterFormats *b)
AVFilterFormats *ret;
unsigned i, j, k = 0;
+ if (a == b) return a;
+
ret = av_mallocz(sizeof(AVFilterFormats));
/* merge list of formats */
ret->formats = av_malloc(sizeof(*ret->formats) * FFMIN(a->format_count,
b->format_count));
- for(i = 0; i < a->format_count; i ++)
- for(j = 0; j < b->format_count; j ++)
- if(a->formats[i] == b->formats[j])
+ for (i = 0; i < a->format_count; i++)
+ for (j = 0; j < b->format_count; j++)
+ if (a->formats[i] == b->formats[j])
ret->formats[k++] = a->formats[i];
ret->format_count = k;
/* check that there was at least one common format */
- if(!ret->format_count) {
+ if (!ret->format_count) {
av_free(ret->formats);
av_free(ret);
return NULL;
@@ -70,31 +75,61 @@ AVFilterFormats *avfilter_merge_formats(AVFilterFormats *a, AVFilterFormats *b)
return ret;
}
+int ff_fmt_is_in(int fmt, const int *fmts)
+{
+ const int *p;
+
+ for (p = fmts; *p != -1; p++) {
+ if (fmt == *p)
+ return 1;
+ }
+ return 0;
+}
+
+#define MAKE_FORMAT_LIST() \
+ AVFilterFormats *formats; \
+ int count = 0; \
+ if (fmts) \
+ for (count = 0; fmts[count] != -1; count++) \
+ ; \
+ formats = av_mallocz(sizeof(AVFilterFormats)); \
+ if (!formats) return NULL; \
+ formats->format_count = count; \
+ if (count) { \
+ formats->formats = av_malloc(sizeof(*formats->formats)*count); \
+ if (!formats->formats) { \
+ av_free(formats); \
+ return NULL; \
+ } \
+ }
+
AVFilterFormats *avfilter_make_format_list(const int *fmts)
{
- AVFilterFormats *formats;
- int count;
+ MAKE_FORMAT_LIST();
+ while (count--)
+ formats->formats[count] = fmts[count];
- for (count = 0; fmts[count] != -1; count++)
- ;
+ return formats;
+}
- formats = av_mallocz(sizeof(AVFilterFormats));
- formats->formats = av_malloc(sizeof(*formats->formats) * count);
- formats->format_count = count;
- memcpy(formats->formats, fmts, sizeof(*formats->formats) * count);
+AVFilterFormats *avfilter_make_format64_list(const int64_t *fmts)
+{
+ MAKE_FORMAT_LIST();
+ if (count)
+ memcpy(formats->formats, fmts, sizeof(*formats->formats) * count);
return formats;
}
-int avfilter_add_format(AVFilterFormats **avff, int fmt)
+int avfilter_add_format(AVFilterFormats **avff, int64_t fmt)
{
- int *fmts;
+ int64_t *fmts;
if (!(*avff) && !(*avff = av_mallocz(sizeof(AVFilterFormats))))
return AVERROR(ENOMEM);
fmts = av_realloc((*avff)->formats,
- sizeof((*avff)->formats) * ((*avff)->format_count+1));
+ sizeof(*(*avff)->formats) * ((*avff)->format_count+1));
if (!fmts)
return AVERROR(ENOMEM);
@@ -103,8 +138,15 @@ int avfilter_add_format(AVFilterFormats **avff, int fmt)
return 0;
}
+#if FF_API_OLD_ALL_FORMATS_API
AVFilterFormats *avfilter_all_formats(enum AVMediaType type)
{
+ return avfilter_make_all_formats(type);
+}
+#endif
+
+AVFilterFormats *avfilter_make_all_formats(enum AVMediaType type)
+{
AVFilterFormats *ret = NULL;
int fmt;
int num_formats = type == AVMEDIA_TYPE_VIDEO ? PIX_FMT_NB :
@@ -118,6 +160,27 @@ AVFilterFormats *avfilter_all_formats(enum AVMediaType type)
return ret;
}
+const int64_t avfilter_all_channel_layouts[] = {
+#include "all_channel_layouts.h"
+ -1
+};
+
+AVFilterFormats *avfilter_make_all_channel_layouts(void)
+{
+ return avfilter_make_format64_list(avfilter_all_channel_layouts);
+}
+
+AVFilterFormats *avfilter_make_all_packing_formats(void)
+{
+ static int packing[] = {
+ AVFILTER_PACKED,
+ AVFILTER_PLANAR,
+ -1,
+ };
+
+ return avfilter_make_format_list(packing);
+}
+
void avfilter_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
{
*ref = f;
@@ -128,8 +191,8 @@ void avfilter_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
static int find_ref_index(AVFilterFormats **ref)
{
int i;
- for(i = 0; i < (*ref)->refcount; i ++)
- if((*ref)->refs[i] == ref)
+ for (i = 0; i < (*ref)->refcount; i++)
+ if ((*ref)->refs[i] == ref)
return i;
return -1;
}
@@ -143,11 +206,11 @@ void avfilter_formats_unref(AVFilterFormats **ref)
idx = find_ref_index(ref);
- if(idx >= 0)
+ if (idx >= 0)
memmove((*ref)->refs + idx, (*ref)->refs + idx+1,
sizeof(AVFilterFormats**) * ((*ref)->refcount-idx-1));
- if(!--(*ref)->refcount) {
+ if (!--(*ref)->refcount) {
av_free((*ref)->formats);
av_free((*ref)->refs);
av_free(*ref);
@@ -160,10 +223,104 @@ void avfilter_formats_changeref(AVFilterFormats **oldref,
{
int idx = find_ref_index(oldref);
- if(idx >= 0) {
+ if (idx >= 0) {
(*oldref)->refs[idx] = newref;
*newref = *oldref;
*oldref = NULL;
}
}
+/* internal functions for parsing audio format arguments */
+
+int ff_parse_pixel_format(enum PixelFormat *ret, const char *arg, void *log_ctx)
+{
+ char *tail;
+ int pix_fmt = av_get_pix_fmt(arg);
+ if (pix_fmt == PIX_FMT_NONE) {
+ pix_fmt = strtol(arg, &tail, 0);
+ if (*tail || (unsigned)pix_fmt >= PIX_FMT_NB) {
+ av_log(log_ctx, AV_LOG_ERROR, "Invalid pixel format '%s'\n", arg);
+ return AVERROR(EINVAL);
+ }
+ }
+ *ret = pix_fmt;
+ return 0;
+}
+
+int ff_parse_sample_format(int *ret, const char *arg, void *log_ctx)
+{
+ char *tail;
+ int sfmt = av_get_sample_fmt(arg);
+ if (sfmt == AV_SAMPLE_FMT_NONE) {
+ sfmt = strtol(arg, &tail, 0);
+ if (*tail || (unsigned)sfmt >= AV_SAMPLE_FMT_NB) {
+ av_log(log_ctx, AV_LOG_ERROR, "Invalid sample format '%s'\n", arg);
+ return AVERROR(EINVAL);
+ }
+ }
+ *ret = sfmt;
+ return 0;
+}
+
+int ff_parse_sample_rate(int *ret, const char *arg, void *log_ctx)
+{
+ char *tail;
+ double srate = av_strtod(arg, &tail);
+ if (*tail || srate < 1 || (int)srate != srate || srate > INT_MAX) {
+ av_log(log_ctx, AV_LOG_ERROR, "Invalid sample rate '%s'\n", arg);
+ return AVERROR(EINVAL);
+ }
+ *ret = srate;
+ return 0;
+}
+
+int ff_parse_channel_layout(int64_t *ret, const char *arg, void *log_ctx)
+{
+ char *tail;
+ int64_t chlayout = av_get_channel_layout(arg);
+ if (chlayout == 0) {
+ chlayout = strtol(arg, &tail, 10);
+ if (*tail || chlayout == 0) {
+ av_log(log_ctx, AV_LOG_ERROR, "Invalid channel layout '%s'\n", arg);
+ return AVERROR(EINVAL);
+ }
+ }
+ *ret = chlayout;
+ return 0;
+}
+
+int ff_parse_packing_format(int *ret, const char *arg, void *log_ctx)
+{
+ char *tail;
+ int planar = strtol(arg, &tail, 10);
+ if (*tail) {
+ planar = !strcmp(arg, "packed") ? 0:
+ !strcmp(arg, "planar") ? 1: -1;
+ }
+
+ if (planar != 0 && planar != 1) {
+ av_log(log_ctx, AV_LOG_ERROR, "Invalid packing format '%s'\n", arg);
+ return AVERROR(EINVAL);
+ }
+ *ret = planar;
+ return 0;
+}
+
+#ifdef TEST
+
+#undef printf
+
+int main(void)
+{
+ const int64_t *cl;
+ char buf[512];
+
+ for (cl = avfilter_all_channel_layouts; *cl != -1; cl++) {
+ av_get_channel_layout_string(buf, sizeof(buf), -1, *cl);
+ printf("%s\n", buf);
+ }
+
+ return 0;
+}
+
+#endif
diff --git a/libavfilter/gradfun.h b/libavfilter/gradfun.h
index 6b192a3113..3c01085b83 100644
--- a/libavfilter/gradfun.h
+++ b/libavfilter/gradfun.h
@@ -2,20 +2,20 @@
* Copyright (c) 2010 Nolan Lum <nol888@gmail.com>
* Copyright (c) 2009 Loren Merritt <lorenm@u.washignton.edu>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -33,16 +33,16 @@ typedef struct {
int chroma_r; ///< blur radius for the chroma planes
uint16_t *buf; ///< holds image data for blur algorithm passed into filter.
/// DSP functions.
- void (*filter_line) (uint8_t *dst, uint8_t *src, uint16_t *dc, int width, int thresh, const uint16_t *dithers);
- void (*blur_line) (uint16_t *dc, uint16_t *buf, uint16_t *buf1, uint8_t *src, int src_linesize, int width);
+ void (*filter_line) (uint8_t *dst, const uint8_t *src, const uint16_t *dc, int width, int thresh, const uint16_t *dithers);
+ void (*blur_line) (uint16_t *dc, uint16_t *buf, const uint16_t *buf1, const uint8_t *src, int src_linesize, int width);
} GradFunContext;
-void ff_gradfun_filter_line_c(uint8_t *dst, uint8_t *src, uint16_t *dc, int width, int thresh, const uint16_t *dithers);
-void ff_gradfun_blur_line_c(uint16_t *dc, uint16_t *buf, uint16_t *buf1, uint8_t *src, int src_linesize, int width);
+void ff_gradfun_filter_line_c(uint8_t *dst, const uint8_t *src, const uint16_t *dc, int width, int thresh, const uint16_t *dithers);
+void ff_gradfun_blur_line_c(uint16_t *dc, uint16_t *buf, const uint16_t *buf1, const uint8_t *src, int src_linesize, int width);
-void ff_gradfun_filter_line_mmx2(uint8_t *dst, uint8_t *src, uint16_t *dc, int width, int thresh, const uint16_t *dithers);
-void ff_gradfun_filter_line_ssse3(uint8_t *dst, uint8_t *src, uint16_t *dc, int width, int thresh, const uint16_t *dithers);
+void ff_gradfun_filter_line_mmx2(uint8_t *dst, const uint8_t *src, const uint16_t *dc, int width, int thresh, const uint16_t *dithers);
+void ff_gradfun_filter_line_ssse3(uint8_t *dst, const uint8_t *src, const uint16_t *dc, int width, int thresh, const uint16_t *dithers);
-void ff_gradfun_blur_line_sse2(uint16_t *dc, uint16_t *buf, uint16_t *buf1, uint8_t *src, int src_linesize, int width);
+void ff_gradfun_blur_line_sse2(uint16_t *dc, uint16_t *buf, const uint16_t *buf1, const uint8_t *src, int src_linesize, int width);
#endif /* AVFILTER_GRADFUN_H */
diff --git a/libavfilter/graphparser.c b/libavfilter/graphparser.c
index c1624d8471..bd3022e035 100644
--- a/libavfilter/graphparser.c
+++ b/libavfilter/graphparser.c
@@ -3,20 +3,20 @@
* Copyright (c) 2008 Vitor Sessak
* Copyright (c) 2007 Bobby Bingham
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -36,7 +36,7 @@
*/
static int link_filter(AVFilterContext *src, int srcpad,
AVFilterContext *dst, int dstpad,
- AVClass *log_ctx)
+ void *log_ctx)
{
int ret;
if ((ret = avfilter_link(src, srcpad, dst, dstpad))) {
@@ -55,7 +55,7 @@ static int link_filter(AVFilterContext *src, int srcpad,
* @return a pointer (that need to be freed after use) to the name
* between parenthesis
*/
-static char *parse_link_name(const char **buf, AVClass *log_ctx)
+static char *parse_link_name(const char **buf, void *log_ctx)
{
const char *start = *buf;
char *name;
@@ -92,14 +92,14 @@ static char *parse_link_name(const char **buf, AVClass *log_ctx)
* @return 0 in case of success, a negative AVERROR code otherwise
*/
static int create_filter(AVFilterContext **filt_ctx, AVFilterGraph *ctx, int index,
- const char *filt_name, const char *args, AVClass *log_ctx)
+ const char *filt_name, const char *args, void *log_ctx)
{
AVFilter *filt;
char inst_name[30];
char tmp_args[256];
int ret;
- snprintf(inst_name, sizeof(inst_name), "Parsed filter %d %s", index, filt_name);
+ snprintf(inst_name, sizeof(inst_name), "Parsed_%s_%d", filt_name, index);
filt = avfilter_get_by_name(filt_name);
@@ -141,6 +141,8 @@ static int create_filter(AVFilterContext **filt_ctx, AVFilterGraph *ctx, int ind
* corresponding filter instance which is added to graph with
* create_filter().
*
+ * @param filt_ctx Pointer that is set to the created and configured filter
+ * context on success, set to NULL on failure.
* @param filt_ctx put here a pointer to the created filter context on
* success, NULL otherwise
* @param buf pointer to the buffer to parse, *buf will be updated to
@@ -151,7 +153,7 @@ static int create_filter(AVFilterContext **filt_ctx, AVFilterGraph *ctx, int ind
* @return 0 in case of success, a negative AVERROR code otherwise
*/
static int parse_filter(AVFilterContext **filt_ctx, const char **buf, AVFilterGraph *graph,
- int index, AVClass *log_ctx)
+ int index, void *log_ctx)
{
char *opts = NULL;
char *name = av_get_token(buf, "=,;[\n");
@@ -168,13 +170,18 @@ static int parse_filter(AVFilterContext **filt_ctx, const char **buf, AVFilterGr
return ret;
}
-static void free_inout(AVFilterInOut *head)
+AVFilterInOut *avfilter_inout_alloc(void)
{
- while (head) {
- AVFilterInOut *next = head->next;
- av_free(head->name);
- av_free(head);
- head = next;
+ return av_mallocz(sizeof(AVFilterInOut));
+}
+
+void avfilter_inout_free(AVFilterInOut **inout)
+{
+ while (*inout) {
+ AVFilterInOut *next = (*inout)->next;
+ av_freep(&(*inout)->name);
+ av_freep(inout);
+ *inout = next;
}
}
@@ -201,7 +208,7 @@ static void insert_inout(AVFilterInOut **inouts, AVFilterInOut *element)
static int link_filter_inouts(AVFilterContext *filt_ctx,
AVFilterInOut **curr_inputs,
- AVFilterInOut **open_inputs, AVClass *log_ctx)
+ AVFilterInOut **open_inputs, void *log_ctx)
{
int pad = filt_ctx->input_count, ret;
@@ -249,7 +256,7 @@ static int link_filter_inouts(AVFilterContext *filt_ctx,
}
static int parse_inputs(const char **buf, AVFilterInOut **curr_inputs,
- AVFilterInOut **open_outputs, AVClass *log_ctx)
+ AVFilterInOut **open_outputs, void *log_ctx)
{
int pad = 0;
@@ -284,7 +291,7 @@ static int parse_inputs(const char **buf, AVFilterInOut **curr_inputs,
static int parse_outputs(const char **buf, AVFilterInOut **curr_inputs,
AVFilterInOut **open_inputs,
- AVFilterInOut **open_outputs, AVClass *log_ctx)
+ AVFilterInOut **open_outputs, void *log_ctx)
{
int ret, pad = 0;
@@ -328,13 +335,15 @@ static int parse_outputs(const char **buf, AVFilterInOut **curr_inputs,
}
int avfilter_graph_parse(AVFilterGraph *graph, const char *filters,
- AVFilterInOut *open_inputs,
- AVFilterInOut *open_outputs, AVClass *log_ctx)
+ AVFilterInOut **open_inputs_ptr, AVFilterInOut **open_outputs_ptr,
+ void *log_ctx)
{
- int index = 0, ret;
+ int index = 0, ret = 0;
char chr = 0;
AVFilterInOut *curr_inputs = NULL;
+ AVFilterInOut *open_inputs = open_inputs_ptr ? *open_inputs_ptr : NULL;
+ AVFilterInOut *open_outputs = open_outputs_ptr ? *open_outputs_ptr : NULL;
do {
AVFilterContext *filter;
@@ -342,24 +351,24 @@ int avfilter_graph_parse(AVFilterGraph *graph, const char *filters,
filters += strspn(filters, WHITESPACES);
if ((ret = parse_inputs(&filters, &curr_inputs, &open_outputs, log_ctx)) < 0)
- goto fail;
+ goto end;
if ((ret = parse_filter(&filter, &filters, graph, index, log_ctx)) < 0)
- goto fail;
+ goto end;
if (filter->input_count == 1 && !curr_inputs && !index) {
- /* First input can be omitted if it is "[in]" */
+ /* First input pad, assume it is "[in]" if not specified */
const char *tmp = "[in]";
if ((ret = parse_inputs(&tmp, &curr_inputs, &open_outputs, log_ctx)) < 0)
- goto fail;
+ goto end;
}
if ((ret = link_filter_inouts(filter, &curr_inputs, &open_inputs, log_ctx)) < 0)
- goto fail;
+ goto end;
if ((ret = parse_outputs(&filters, &curr_inputs, &open_inputs, &open_outputs,
log_ctx)) < 0)
- goto fail;
+ goto end;
filters += strspn(filters, WHITESPACES);
chr = *filters++;
@@ -369,7 +378,7 @@ int avfilter_graph_parse(AVFilterGraph *graph, const char *filters,
"Invalid filterchain containing an unlabelled output pad: \"%s\"\n",
filterchain);
ret = AVERROR(EINVAL);
- goto fail;
+ goto end;
}
index++;
} while (chr == ',' || chr == ';');
@@ -379,25 +388,29 @@ int avfilter_graph_parse(AVFilterGraph *graph, const char *filters,
"Unable to parse graph description substring: \"%s\"\n",
filters - 1);
ret = AVERROR(EINVAL);
- goto fail;
+ goto end;
}
- if (open_inputs && !strcmp(open_inputs->name, "out") && curr_inputs) {
- /* Last output can be omitted if it is "[out]" */
+ if (curr_inputs) {
+ /* Last output pad, assume it is "[out]" if not specified */
const char *tmp = "[out]";
if ((ret = parse_outputs(&tmp, &curr_inputs, &open_inputs, &open_outputs,
log_ctx)) < 0)
- goto fail;
+ goto end;
}
- return 0;
-
- fail:
- for (; graph->filter_count > 0; graph->filter_count--)
- avfilter_free(graph->filters[graph->filter_count - 1]);
- av_freep(&graph->filters);
- free_inout(open_inputs);
- free_inout(open_outputs);
- free_inout(curr_inputs);
+end:
+ /* clear open_in/outputs only if not passed as parameters */
+ if (open_inputs_ptr) *open_inputs_ptr = open_inputs;
+ else avfilter_inout_free(&open_inputs);
+ if (open_outputs_ptr) *open_outputs_ptr = open_outputs;
+ else avfilter_inout_free(&open_outputs);
+ avfilter_inout_free(&curr_inputs);
+
+ if (ret < 0) {
+ for (; graph->filter_count > 0; graph->filter_count--)
+ avfilter_free(graph->filters[graph->filter_count - 1]);
+ av_freep(&graph->filters);
+ }
return ret;
}
diff --git a/libavfilter/internal.h b/libavfilter/internal.h
index 64b3f3b865..9f28a839df 100644
--- a/libavfilter/internal.h
+++ b/libavfilter/internal.h
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -27,6 +27,20 @@
#include "avfilter.h"
#include "avfiltergraph.h"
+#define POOL_SIZE 32
+typedef struct AVFilterPool {
+ AVFilterBufferRef *pic[POOL_SIZE];
+ int count;
+} AVFilterPool;
+
+typedef struct AVFilterCommand {
+ double time; ///< time expressed in seconds
+ char *command; ///< command
+ char *arg; ///< optional argument for the command
+ int flags;
+ struct AVFilterCommand *next;
+} AVFilterCommand;
+
/**
* Check for the validity of graph.
*
@@ -52,4 +66,59 @@ int ff_avfilter_graph_config_formats(AVFilterGraph *graphctx, AVClass *log_ctx);
/** default handler for freeing audio/video buffer when there are no references left */
void ff_avfilter_default_free_buffer(AVFilterBuffer *buf);
+/** Tell is a format is contained in the provided list terminated by -1. */
+int ff_fmt_is_in(int fmt, const int *fmts);
+
+/* Functions to parse audio format arguments */
+
+/**
+ * Parse a pixel format.
+ *
+ * @param ret pixel format pointer to where the value should be written
+ * @param arg string to parse
+ * @param log_ctx log context
+ * @return 0 in case of success, a negative AVERROR code on error
+ */
+int ff_parse_pixel_format(enum PixelFormat *ret, const char *arg, void *log_ctx);
+
+/**
+ * Parse a sample rate.
+ *
+ * @param ret unsigned integer pointer to where the value should be written
+ * @param arg string to parse
+ * @param log_ctx log context
+ * @return 0 in case of success, a negative AVERROR code on error
+ */
+int ff_parse_sample_rate(int *ret, const char *arg, void *log_ctx);
+
+/**
+ * Parse a sample format name or a corresponding integer representation.
+ *
+ * @param ret integer pointer to where the value should be written
+ * @param arg string to parse
+ * @param log_ctx log context
+ * @return 0 in case of success, a negative AVERROR code on error
+ */
+int ff_parse_sample_format(int *ret, const char *arg, void *log_ctx);
+
+/**
+ * Parse a channel layout or a corresponding integer representation.
+ *
+ * @param ret 64bit integer pointer to where the value should be written.
+ * @param arg string to parse
+ * @param log_ctx log context
+ * @return 0 in case of success, a negative AVERROR code on error
+ */
+int ff_parse_channel_layout(int64_t *ret, const char *arg, void *log_ctx);
+
+/**
+ * Parse a packing format or a corresponding integer representation.
+ *
+ * @param ret integer pointer to where the value should be written
+ * @param arg string to parse
+ * @param log_ctx log context
+ * @return 0 in case of success, a negative AVERROR code on error
+ */
+int ff_parse_packing_format(int *ret, const char *arg, void *log_ctx);
+
#endif /* AVFILTER_INTERNAL_H */
diff --git a/libavfilter/libmpcodecs/cpudetect.h b/libavfilter/libmpcodecs/cpudetect.h
new file mode 100644
index 0000000000..0f433e707c
--- /dev/null
+++ b/libavfilter/libmpcodecs/cpudetect.h
@@ -0,0 +1,59 @@
+/*
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef MPLAYER_CPUDETECT_H
+#define MPLAYER_CPUDETECT_H
+
+//#include "config.h"
+
+#define CPUTYPE_I386 3
+#define CPUTYPE_I486 4
+#define CPUTYPE_I586 5
+#define CPUTYPE_I686 6
+
+#include "libavutil/x86_cpu.h"
+
+typedef struct cpucaps_s {
+ int cpuType;
+ int cpuModel;
+ int cpuStepping;
+ int hasMMX;
+ int hasMMX2;
+ int has3DNow;
+ int has3DNowExt;
+ int hasSSE;
+ int hasSSE2;
+ int hasSSE3;
+ int hasSSSE3;
+ int hasSSE4a;
+ int isX86;
+ unsigned cl_size; /* size of cache line */
+ int hasAltiVec;
+ int hasTSC;
+} CpuCaps;
+
+extern CpuCaps gCpuCaps;
+
+void do_cpuid(unsigned int ax, unsigned int *p);
+
+void GetCpuCaps(CpuCaps *caps);
+
+/* returned value is malloc()'ed so free() it after use */
+char *GetCpuFriendlyName(unsigned int regs[], unsigned int regs2[]);
+
+#endif /* MPLAYER_CPUDETECT_H */
diff --git a/libavfilter/libmpcodecs/help_mp.h b/libavfilter/libmpcodecs/help_mp.h
new file mode 100644
index 0000000000..87b828d933
--- /dev/null
+++ b/libavfilter/libmpcodecs/help_mp.h
@@ -0,0 +1,2136 @@
+/* WARNING! This is a generated file, do NOT edit.
+ * See the help/ subdirectory for the editable files. */
+
+#ifndef MPLAYER_HELP_MP_H
+#define MPLAYER_HELP_MP_H
+
+// $Revision: 32397 $
+// MASTER FILE. Use this file as base for translations.
+// Translated files should be sent to the mplayer-DOCS mailing list or
+// to the help messages maintainer, see DOCS/tech/MAINTAINERS.
+// The header of the translated file should contain credits and contact
+// information. Before major releases we will notify all translators to update
+// their files. Please do not simply translate and forget this, outdated
+// translations quickly become worthless. To help us spot outdated files put a
+// note like "sync'ed with help_mp-en.h XXX" in the header of the translation.
+// Do NOT translate the above lines, just follow the instructions.
+
+
+// ========================= MPlayer help ===========================
+
+static const char help_text[]=
+"Usage: mplayer [options] [url|path/]filename\n"
+"\n"
+"Basic options: (complete list in the man page)\n"
+" -vo <drv> select video output driver ('-vo help' for a list)\n"
+" -ao <drv> select audio output driver ('-ao help' for a list)\n"
+#ifdef CONFIG_VCD
+" vcd://<trackno> play (S)VCD (Super Video CD) track (raw device, no mount)\n"
+#endif
+#ifdef CONFIG_DVDREAD
+" dvd://<titleno> play DVD title from device instead of plain file\n"
+#endif
+" -alang/-slang select DVD audio/subtitle language (by 2-char country code)\n"
+" -ss <position> seek to given (seconds or hh:mm:ss) position\n"
+" -nosound do not play sound\n"
+" -fs fullscreen playback (or -vm, -zoom, details in the man page)\n"
+" -x <x> -y <y> set display resolution (for use with -vm or -zoom)\n"
+" -sub <file> specify subtitle file to use (also see -subfps, -subdelay)\n"
+" -playlist <file> specify playlist file\n"
+" -vid x -aid y select video (x) and audio (y) stream to play\n"
+" -fps x -srate y change video (x fps) and audio (y Hz) rate\n"
+" -pp <quality> enable postprocessing filter (details in the man page)\n"
+" -framedrop enable frame dropping (for slow machines)\n"
+"\n"
+"Basic keys: (complete list in the man page, also check input.conf)\n"
+" <- or -> seek backward/forward 10 seconds\n"
+" down or up seek backward/forward 1 minute\n"
+" pgdown or pgup seek backward/forward 10 minutes\n"
+" < or > step backward/forward in playlist\n"
+" p or SPACE pause movie (press any key to continue)\n"
+" q or ESC stop playing and quit program\n"
+" + or - adjust audio delay by +/- 0.1 second\n"
+" o cycle OSD mode: none / seekbar / seekbar + timer\n"
+" * or / increase or decrease PCM volume\n"
+" x or z adjust subtitle delay by +/- 0.1 second\n"
+" r or t adjust subtitle position up/down, also see -vf expand\n"
+"\n"
+" * * * SEE THE MAN PAGE FOR DETAILS, FURTHER (ADVANCED) OPTIONS AND KEYS * * *\n"
+"\n";
+
+// ========================= MPlayer messages ===========================
+
+// mplayer.c
+#define MSGTR_Exiting "\nExiting...\n"
+#define MSGTR_ExitingHow "\nExiting... (%s)\n"
+#define MSGTR_Exit_quit "Quit"
+#define MSGTR_Exit_eof "End of file"
+#define MSGTR_Exit_error "Fatal error"
+#define MSGTR_IntBySignal "\nMPlayer interrupted by signal %d in module: %s\n"
+#define MSGTR_NoHomeDir "Cannot find HOME directory.\n"
+#define MSGTR_GetpathProblem "get_path(\"config\") problem\n"
+#define MSGTR_CreatingCfgFile "Creating config file: %s\n"
+#define MSGTR_BuiltinCodecsConf "Using built-in default codecs.conf.\n"
+#define MSGTR_CantLoadFont "Cannot load bitmap font: %s\n"
+#define MSGTR_CantLoadSub "Cannot load subtitles: %s\n"
+#define MSGTR_DumpSelectedStreamMissing "dump: FATAL: Selected stream missing!\n"
+#define MSGTR_CantOpenDumpfile "Cannot open dump file.\n"
+#define MSGTR_CoreDumped "Core dumped ;)\n"
+#define MSGTR_FPSnotspecified "FPS not specified in the header or invalid, use the -fps option.\n"
+#define MSGTR_TryForceAudioFmtStr "Trying to force audio codec driver family %s...\n"
+#define MSGTR_CantFindAudioCodec "Cannot find codec for audio format 0x%X.\n"
+#define MSGTR_TryForceVideoFmtStr "Trying to force video codec driver family %s...\n"
+#define MSGTR_CantFindVideoCodec "Cannot find codec matching selected -vo and video format 0x%X.\n"
+#define MSGTR_CannotInitVO "FATAL: Cannot initialize video driver.\n"
+#define MSGTR_CannotInitAO "Could not open/initialize audio device -> no sound.\n"
+#define MSGTR_StartPlaying "Starting playback...\n"
+
+#define MSGTR_SystemTooSlow "\n\n"\
+" ************************************************\n"\
+" **** Your system is too SLOW to play this! ****\n"\
+" ************************************************\n\n"\
+"Possible reasons, problems, workarounds:\n"\
+"- Most common: broken/buggy _audio_ driver\n"\
+" - Try -ao sdl or use the OSS emulation of ALSA.\n"\
+" - Experiment with different values for -autosync, 30 is a good start.\n"\
+"- Slow video output\n"\
+" - Try a different -vo driver (-vo help for a list) or try -framedrop!\n"\
+"- Slow CPU\n"\
+" - Don't try to play a big DVD/DivX on a slow CPU! Try some of the lavdopts,\n"\
+" e.g. -vfm ffmpeg -lavdopts lowres=1:fast:skiploopfilter=all.\n"\
+"- Broken file\n"\
+" - Try various combinations of -nobps -ni -forceidx -mc 0.\n"\
+"- Slow media (NFS/SMB mounts, DVD, VCD etc)\n"\
+" - Try -cache 8192.\n"\
+"- Are you using -cache to play a non-interleaved AVI file?\n"\
+" - Try -nocache.\n"\
+"Read DOCS/HTML/en/video.html for tuning/speedup tips.\n"\
+"If none of this helps you, read DOCS/HTML/en/bugreports.html.\n\n"
+
+#define MSGTR_NoGui "MPlayer was compiled WITHOUT GUI support.\n"
+#define MSGTR_GuiNeedsX "MPlayer GUI requires X11.\n"
+#define MSGTR_Playing "\nPlaying %s.\n"
+#define MSGTR_NoSound "Audio: no sound\n"
+#define MSGTR_FPSforced "FPS forced to be %5.3f (ftime: %5.3f).\n"
+#define MSGTR_CompiledWithRuntimeDetection "Compiled with runtime CPU detection.\n"
+#define MSGTR_CompiledWithCPUExtensions "Compiled for x86 CPU with extensions:"
+#define MSGTR_AvailableVideoOutputDrivers "Available video output drivers:\n"
+#define MSGTR_AvailableAudioOutputDrivers "Available audio output drivers:\n"
+#define MSGTR_AvailableAudioCodecs "Available audio codecs:\n"
+#define MSGTR_AvailableVideoCodecs "Available video codecs:\n"
+#define MSGTR_AvailableAudioFm "Available (compiled-in) audio codec families/drivers:\n"
+#define MSGTR_AvailableVideoFm "Available (compiled-in) video codec families/drivers:\n"
+#define MSGTR_AvailableFsType "Available fullscreen layer change modes:\n"
+#define MSGTR_UsingRTCTiming "Using Linux hardware RTC timing (%ldHz).\n"
+#define MSGTR_CannotReadVideoProperties "Video: Cannot read properties.\n"
+#define MSGTR_NoStreamFound "No stream found.\n"
+#define MSGTR_ErrorInitializingVODevice "Error opening/initializing the selected video_out (-vo) device.\n"
+#define MSGTR_ForcedVideoCodec "Forced video codec: %s\n"
+#define MSGTR_ForcedAudioCodec "Forced audio codec: %s\n"
+#define MSGTR_Video_NoVideo "Video: no video\n"
+#define MSGTR_NotInitializeVOPorVO "\nFATAL: Could not initialize video filters (-vf) or video output (-vo).\n"
+#define MSGTR_Paused "\n ===== PAUSE =====\r" // no more than 23 characters (status line for audio files)
+#define MSGTR_PlaylistLoadUnable "\nUnable to load playlist %s.\n"
+#define MSGTR_Exit_SIGILL_RTCpuSel \
+"- MPlayer crashed by an 'Illegal Instruction'.\n"\
+" It may be a bug in our new runtime CPU-detection code...\n"\
+" Please read DOCS/HTML/en/bugreports.html.\n"
+#define MSGTR_Exit_SIGILL \
+"- MPlayer crashed by an 'Illegal Instruction'.\n"\
+" It usually happens when you run it on a CPU different than the one it was\n"\
+" compiled/optimized for.\n"\
+" Verify this!\n"
+#define MSGTR_Exit_SIGSEGV_SIGFPE \
+"- MPlayer crashed by bad usage of CPU/FPU/RAM.\n"\
+" Recompile MPlayer with --enable-debug and make a 'gdb' backtrace and\n"\
+" disassembly. Details in DOCS/HTML/en/bugreports_what.html#bugreports_crash.\n"
+#define MSGTR_Exit_SIGCRASH \
+"- MPlayer crashed. This shouldn't happen.\n"\
+" It can be a bug in the MPlayer code _or_ in your drivers _or_ in your\n"\
+" gcc version. If you think it's MPlayer's fault, please read\n"\
+" DOCS/HTML/en/bugreports.html and follow the instructions there. We can't and\n"\
+" won't help unless you provide this information when reporting a possible bug.\n"
+#define MSGTR_LoadingConfig "Loading config '%s'\n"
+#define MSGTR_LoadingProtocolProfile "Loading protocol-related profile '%s'\n"
+#define MSGTR_LoadingExtensionProfile "Loading extension-related profile '%s'\n"
+#define MSGTR_AddedSubtitleFile "SUB: Added subtitle file (%d): %s\n"
+#define MSGTR_RemovedSubtitleFile "SUB: Removed subtitle file (%d): %s\n"
+#define MSGTR_ErrorOpeningOutputFile "Error opening file [%s] for writing!\n"
+#define MSGTR_CommandLine "CommandLine:"
+#define MSGTR_RTCDeviceNotOpenable "Failed to open %s: %s (it should be readable by the user.)\n"
+#define MSGTR_LinuxRTCInitErrorIrqpSet "Linux RTC init error in ioctl (rtc_irqp_set %lu): %s\n"
+#define MSGTR_IncreaseRTCMaxUserFreq "Try adding \"echo %lu > /proc/sys/dev/rtc/max-user-freq\" to your system startup scripts.\n"
+#define MSGTR_LinuxRTCInitErrorPieOn "Linux RTC init error in ioctl (rtc_pie_on): %s\n"
+#define MSGTR_UsingTimingType "Using %s timing.\n"
+#define MSGTR_NoIdleAndGui "The -idle option cannot be used with GMPlayer.\n"
+#define MSGTR_MenuInitialized "Menu initialized: %s\n"
+#define MSGTR_MenuInitFailed "Menu init failed.\n"
+#define MSGTR_Getch2InitializedTwice "WARNING: getch2_init called twice!\n"
+#define MSGTR_DumpstreamFdUnavailable "Cannot dump this stream - no file descriptor available.\n"
+#define MSGTR_CantOpenLibmenuFilterWithThisRootMenu "Can't open libmenu video filter with root menu %s.\n"
+#define MSGTR_AudioFilterChainPreinitError "Error at audio filter chain pre-init!\n"
+#define MSGTR_LinuxRTCReadError "Linux RTC read error: %s\n"
+#define MSGTR_SoftsleepUnderflow "Warning! Softsleep underflow!\n"
+#define MSGTR_DvdnavNullEvent "DVDNAV Event NULL?!\n"
+#define MSGTR_DvdnavHighlightEventBroken "DVDNAV Event: Highlight event broken\n"
+#define MSGTR_DvdnavEvent "DVDNAV Event: %s\n"
+#define MSGTR_DvdnavHighlightHide "DVDNAV Event: Highlight Hide\n"
+#define MSGTR_DvdnavStillFrame "######################################## DVDNAV Event: Still Frame: %d sec(s)\n"
+#define MSGTR_DvdnavNavStop "DVDNAV Event: Nav Stop\n"
+#define MSGTR_DvdnavNavNOP "DVDNAV Event: Nav NOP\n"
+#define MSGTR_DvdnavNavSpuStreamChangeVerbose "DVDNAV Event: Nav SPU Stream Change: phys: %d/%d/%d logical: %d\n"
+#define MSGTR_DvdnavNavSpuStreamChange "DVDNAV Event: Nav SPU Stream Change: phys: %d logical: %d\n"
+#define MSGTR_DvdnavNavAudioStreamChange "DVDNAV Event: Nav Audio Stream Change: phys: %d logical: %d\n"
+#define MSGTR_DvdnavNavVTSChange "DVDNAV Event: Nav VTS Change\n"
+#define MSGTR_DvdnavNavCellChange "DVDNAV Event: Nav Cell Change\n"
+#define MSGTR_DvdnavNavSpuClutChange "DVDNAV Event: Nav SPU CLUT Change\n"
+#define MSGTR_DvdnavNavSeekDone "DVDNAV Event: Nav Seek Done\n"
+#define MSGTR_MenuCall "Menu call\n"
+#define MSGTR_MasterQuit "Option -udp-slave: exiting because master exited\n"
+#define MSGTR_InvalidIP "Option -udp-ip: invalid IP address\n"
+
+// --- edit decision lists
+#define MSGTR_EdlOutOfMem "Can't allocate enough memory to hold EDL data.\n"
+#define MSGTR_EdlOutOfMemFile "Can't allocate enough memory to hold EDL file name [%s].\n"
+#define MSGTR_EdlRecordsNo "Read %d EDL actions.\n"
+#define MSGTR_EdlQueueEmpty "There are no EDL actions to take care of.\n"
+#define MSGTR_EdlCantOpenForWrite "Can't open EDL file [%s] for writing.\n"
+#define MSGTR_EdlCantOpenForRead "Can't open EDL file [%s] for reading.\n"
+#define MSGTR_EdlNOsh_video "Cannot use EDL without video, disabling.\n"
+#define MSGTR_EdlNOValidLine "Invalid EDL line: %s\n"
+#define MSGTR_EdlBadlyFormattedLine "Badly formatted EDL line [%d], discarding.\n"
+#define MSGTR_EdlBadLineOverlap "Last stop position was [%f]; next start is [%f].\n"\
+"Entries must be in chronological order, cannot overlap. Discarding.\n"
+#define MSGTR_EdlBadLineBadStop "Stop time has to be after start time.\n"
+#define MSGTR_EdloutBadStop "EDL skip canceled, last start > stop\n"
+#define MSGTR_EdloutStartSkip "EDL skip start, press 'i' again to end block.\n"
+#define MSGTR_EdloutEndSkip "EDL skip end, line written.\n"
+#define MSGTR_MPEndposNoSizeBased "Option -endpos in MPlayer does not yet support size units.\n"
+
+// mplayer.c OSD
+#define MSGTR_OSDenabled "enabled"
+#define MSGTR_OSDdisabled "disabled"
+#define MSGTR_OSDAudio "Audio: %s"
+#define MSGTR_OSDVideo "Video: %s"
+#define MSGTR_OSDChannel "Channel: %s"
+#define MSGTR_OSDSubDelay "Sub delay: %d ms"
+#define MSGTR_OSDSpeed "Speed: x %6.2f"
+#define MSGTR_OSDosd "OSD: %s"
+#define MSGTR_OSDChapter "Chapter: (%d) %s"
+#define MSGTR_OSDAngle "Angle: %d/%d"
+#define MSGTR_OSDDeinterlace "Deinterlace: %s"
+
+// property values
+#define MSGTR_Enabled "enabled"
+#define MSGTR_EnabledEdl "enabled (EDL)"
+#define MSGTR_Disabled "disabled"
+#define MSGTR_HardFrameDrop "hard"
+#define MSGTR_Unknown "unknown"
+#define MSGTR_Bottom "bottom"
+#define MSGTR_Center "center"
+#define MSGTR_Top "top"
+#define MSGTR_SubSourceFile "file"
+#define MSGTR_SubSourceVobsub "vobsub"
+#define MSGTR_SubSourceDemux "embedded"
+
+// OSD bar names
+#define MSGTR_Volume "Volume"
+#define MSGTR_Panscan "Panscan"
+#define MSGTR_Gamma "Gamma"
+#define MSGTR_Brightness "Brightness"
+#define MSGTR_Contrast "Contrast"
+#define MSGTR_Saturation "Saturation"
+#define MSGTR_Hue "Hue"
+#define MSGTR_Balance "Balance"
+
+// property state
+#define MSGTR_LoopStatus "Loop: %s"
+#define MSGTR_MuteStatus "Mute: %s"
+#define MSGTR_AVDelayStatus "A-V delay: %s"
+#define MSGTR_OnTopStatus "Stay on top: %s"
+#define MSGTR_RootwinStatus "Rootwin: %s"
+#define MSGTR_BorderStatus "Border: %s"
+#define MSGTR_FramedroppingStatus "Framedropping: %s"
+#define MSGTR_VSyncStatus "VSync: %s"
+#define MSGTR_SubSelectStatus "Subtitles: %s"
+#define MSGTR_SubSourceStatus "Sub source: %s"
+#define MSGTR_SubPosStatus "Sub position: %s/100"
+#define MSGTR_SubAlignStatus "Sub alignment: %s"
+#define MSGTR_SubDelayStatus "Sub delay: %s"
+#define MSGTR_SubScale "Sub Scale: %s"
+#define MSGTR_SubVisibleStatus "Subtitles: %s"
+#define MSGTR_SubForcedOnlyStatus "Forced sub only: %s"
+
+// mencoder.c
+#define MSGTR_UsingPass3ControlFile "Using pass3 control file: %s\n"
+#define MSGTR_MissingFilename "\nFilename missing.\n\n"
+#define MSGTR_CannotOpenFile_Device "Cannot open file/device.\n"
+#define MSGTR_CannotOpenDemuxer "Cannot open demuxer.\n"
+#define MSGTR_NoAudioEncoderSelected "\nNo audio encoder (-oac) selected. Select one (see -oac help) or use -nosound.\n"
+#define MSGTR_NoVideoEncoderSelected "\nNo video encoder (-ovc) selected. Select one (see -ovc help).\n"
+#define MSGTR_CannotOpenOutputFile "Cannot open output file '%s'.\n"
+#define MSGTR_EncoderOpenFailed "Failed to open the encoder.\n"
+#define MSGTR_MencoderWrongFormatAVI "\nWARNING: OUTPUT FILE FORMAT IS _AVI_. See -of help.\n"
+#define MSGTR_MencoderWrongFormatMPG "\nWARNING: OUTPUT FILE FORMAT IS _MPEG_. See -of help.\n"
+#define MSGTR_MissingOutputFilename "No output file specified, please see the -o option."
+#define MSGTR_ForcingOutputFourcc "Forcing output FourCC to %x [%.4s].\n"
+#define MSGTR_ForcingOutputAudiofmtTag "Forcing output audio format tag to 0x%x.\n"
+#define MSGTR_DuplicateFrames "\n%d duplicate frame(s)!\n"
+#define MSGTR_SkipFrame "\nSkipping frame!\n"
+#define MSGTR_ResolutionDoesntMatch "\nNew video file has different resolution or colorspace than the previous one.\n"
+#define MSGTR_FrameCopyFileMismatch "\nAll video files must have identical fps, resolution, and codec for -ovc copy.\n"
+#define MSGTR_AudioCopyFileMismatch "\nAll files must have identical audio codec and format for -oac copy.\n"
+#define MSGTR_NoAudioFileMismatch "\nCannot mix video-only files with audio and video files. Try -nosound.\n"
+#define MSGTR_NoSpeedWithFrameCopy "WARNING: -speed is not guaranteed to work correctly with -oac copy!\n"\
+"Your encode might be broken!\n"
+#define MSGTR_ErrorWritingFile "%s: Error writing file.\n"
+#define MSGTR_FlushingVideoFrames "\nFlushing video frames.\n"
+#define MSGTR_FiltersHaveNotBeenConfiguredEmptyFile "Filters have not been configured! Empty file?\n"
+#define MSGTR_RecommendedVideoBitrate "Recommended video bitrate for %s CD: %d\n"
+#define MSGTR_VideoStreamResult "\nVideo stream: %8.3f kbit/s (%d B/s) size: %"PRIu64" bytes %5.3f secs %d frames\n"
+#define MSGTR_AudioStreamResult "\nAudio stream: %8.3f kbit/s (%d B/s) size: %"PRIu64" bytes %5.3f secs\n"
+#define MSGTR_EdlSkipStartEndCurrent "EDL SKIP: Start: %.2f End: %.2f Current: V: %.2f A: %.2f \r"
+#define MSGTR_OpenedStream "success: format: %d data: 0x%X - 0x%x\n"
+#define MSGTR_VCodecFramecopy "videocodec: framecopy (%dx%d %dbpp fourcc=%x)\n"
+#define MSGTR_ACodecFramecopy "audiocodec: framecopy (format=%x chans=%d rate=%d bits=%d B/s=%d sample-%d)\n"
+#define MSGTR_CBRPCMAudioSelected "CBR PCM audio selected.\n"
+#define MSGTR_MP3AudioSelected "MP3 audio selected.\n"
+#define MSGTR_CannotAllocateBytes "Couldn't allocate %d bytes.\n"
+#define MSGTR_SettingAudioDelay "Setting audio delay to %5.3fs.\n"
+#define MSGTR_SettingVideoDelay "Setting video delay to %5.3fs.\n"
+#define MSGTR_SettingAudioInputGain "Setting audio input gain to %f.\n"
+#define MSGTR_LamePresetEquals "\npreset=%s\n\n"
+#define MSGTR_LimitingAudioPreload "Limiting audio preload to 0.4s.\n"
+#define MSGTR_IncreasingAudioDensity "Increasing audio density to 4.\n"
+#define MSGTR_ZeroingAudioPreloadAndMaxPtsCorrection "Forcing audio preload to 0, max pts correction to 0.\n"
+#define MSGTR_CBRAudioByterate "\n\nCBR audio: %d bytes/sec, %d bytes/block\n"
+#define MSGTR_LameVersion "LAME version %s (%s)\n\n"
+#define MSGTR_InvalidBitrateForLamePreset "Error: The bitrate specified is out of the valid range for this preset.\n"\
+"\n"\
+"When using this mode you must enter a value between \"8\" and \"320\".\n"\
+"\n"\
+"For further information try: \"-lameopts preset=help\"\n"
+#define MSGTR_InvalidLamePresetOptions "Error: You did not enter a valid profile and/or options with preset.\n"\
+"\n"\
+"Available profiles are:\n"\
+"\n"\
+" <fast> standard\n"\
+" <fast> extreme\n"\
+" insane\n"\
+" <cbr> (ABR Mode) - The ABR Mode is implied. To use it,\n"\
+" simply specify a bitrate. For example:\n"\
+" \"preset=185\" activates this\n"\
+" preset and uses 185 as an average kbps.\n"\
+"\n"\
+" Some examples:\n"\
+"\n"\
+" \"-lameopts fast:preset=standard \"\n"\
+" or \"-lameopts cbr:preset=192 \"\n"\
+" or \"-lameopts preset=172 \"\n"\
+" or \"-lameopts preset=extreme \"\n"\
+"\n"\
+"For further information try: \"-lameopts preset=help\"\n"
+#define MSGTR_LamePresetsLongInfo "\n"\
+"The preset switches are designed to provide the highest possible quality.\n"\
+"\n"\
+"They have for the most part been subjected to and tuned via rigorous double\n"\
+"blind listening tests to verify and achieve this objective.\n"\
+"\n"\
+"These are continually updated to coincide with the latest developments that\n"\
+"occur and as a result should provide you with nearly the best quality\n"\
+"currently possible from LAME.\n"\
+"\n"\
+"To activate these presets:\n"\
+"\n"\
+" For VBR modes (generally highest quality):\n"\
+"\n"\
+" \"preset=standard\" This preset should generally be transparent\n"\
+" to most people on most music and is already\n"\
+" quite high in quality.\n"\
+"\n"\
+" \"preset=extreme\" If you have extremely good hearing and similar\n"\
+" equipment, this preset will generally provide\n"\
+" slightly higher quality than the \"standard\"\n"\
+" mode.\n"\
+"\n"\
+" For CBR 320kbps (highest quality possible from the preset switches):\n"\
+"\n"\
+" \"preset=insane\" This preset will usually be overkill for most\n"\
+" people and most situations, but if you must\n"\
+" have the absolute highest quality with no\n"\
+" regard to filesize, this is the way to go.\n"\
+"\n"\
+" For ABR modes (high quality per given bitrate but not as high as VBR):\n"\
+"\n"\
+" \"preset=<kbps>\" Using this preset will usually give you good\n"\
+" quality at a specified bitrate. Depending on the\n"\
+" bitrate entered, this preset will determine the\n"\
+" optimal settings for that particular situation.\n"\
+" While this approach works, it is not nearly as\n"\
+" flexible as VBR, and usually will not attain the\n"\
+" same level of quality as VBR at higher bitrates.\n"\
+"\n"\
+"The following options are also available for the corresponding profiles:\n"\
+"\n"\
+" <fast> standard\n"\
+" <fast> extreme\n"\
+" insane\n"\
+" <cbr> (ABR Mode) - The ABR Mode is implied. To use it,\n"\
+" simply specify a bitrate. For example:\n"\
+" \"preset=185\" activates this\n"\
+" preset and uses 185 as an average kbps.\n"\
+"\n"\
+" \"fast\" - Enables the new fast VBR for a particular profile. The\n"\
+" disadvantage to the speed switch is that often times the\n"\
+" bitrate will be slightly higher than with the normal mode\n"\
+" and quality may be slightly lower also.\n"\
+" Warning: with the current version fast presets might result in too\n"\
+" high bitrate compared to regular presets.\n"\
+"\n"\
+" \"cbr\" - If you use the ABR mode (read above) with a significant\n"\
+" bitrate such as 80, 96, 112, 128, 160, 192, 224, 256, 320,\n"\
+" you can use the \"cbr\" option to force CBR mode encoding\n"\
+" instead of the standard abr mode. ABR does provide higher\n"\
+" quality but CBR may be useful in situations such as when\n"\
+" streaming an MP3 over the internet may be important.\n"\
+"\n"\
+" For example:\n"\
+"\n"\
+" \"-lameopts fast:preset=standard \"\n"\
+" or \"-lameopts cbr:preset=192 \"\n"\
+" or \"-lameopts preset=172 \"\n"\
+" or \"-lameopts preset=extreme \"\n"\
+"\n"\
+"\n"\
+"A few aliases are available for ABR mode:\n"\
+"phone => 16kbps/mono phon+/lw/mw-eu/sw => 24kbps/mono\n"\
+"mw-us => 40kbps/mono voice => 56kbps/mono\n"\
+"fm/radio/tape => 112kbps hifi => 160kbps\n"\
+"cd => 192kbps studio => 256kbps"
+#define MSGTR_LameCantInit \
+"Cannot set LAME options, check bitrate/samplerate, some very low bitrates\n"\
+"(<32) need lower samplerates (i.e. -srate 8000).\n"\
+"If everything else fails, try a preset."
+#define MSGTR_ConfigFileError "config file error"
+#define MSGTR_ErrorParsingCommandLine "error parsing command line"
+#define MSGTR_VideoStreamRequired "Video stream is mandatory!\n"
+#define MSGTR_ForcingInputFPS "Input fps will be interpreted as %5.3f instead.\n"
+#define MSGTR_RawvideoDoesNotSupportAudio "Output file format RAWVIDEO does not support audio - disabling audio.\n"
+#define MSGTR_DemuxerDoesntSupportNosound "This demuxer doesn't support -nosound yet.\n"
+#define MSGTR_MemAllocFailed "Memory allocation failed.\n"
+#define MSGTR_NoMatchingFilter "Couldn't find matching filter/ao format!\n"
+#define MSGTR_MP3WaveFormatSizeNot30 "sizeof(MPEGLAYER3WAVEFORMAT)==%d!=30, maybe broken C compiler?\n"
+#define MSGTR_NoLavcAudioCodecName "Audio LAVC, Missing codec name!\n"
+#define MSGTR_LavcAudioCodecNotFound "Audio LAVC, couldn't find encoder for codec %s.\n"
+#define MSGTR_CouldntAllocateLavcContext "Audio LAVC, couldn't allocate context!\n"
+#define MSGTR_CouldntOpenCodec "Couldn't open codec %s, br=%d.\n"
+#define MSGTR_CantCopyAudioFormat "Audio format 0x%x is incompatible with '-oac copy', please try '-oac pcm' instead or use '-fafmttag' to override it.\n"
+
+// cfg-mencoder.h
+#define MSGTR_MEncoderMP3LameHelp "\n\n"\
+" vbr=<0-4> variable bitrate method\n"\
+" 0: cbr (constant bitrate)\n"\
+" 1: mt (Mark Taylor VBR algorithm)\n"\
+" 2: rh (Robert Hegemann VBR algorithm - default)\n"\
+" 3: abr (average bitrate)\n"\
+" 4: mtrh (Mark Taylor Robert Hegemann VBR algorithm)\n"\
+"\n"\
+" abr average bitrate\n"\
+"\n"\
+" cbr constant bitrate\n"\
+" Also forces CBR mode encoding on subsequent ABR presets modes.\n"\
+"\n"\
+" br=<0-1024> specify bitrate in kBit (CBR and ABR only)\n"\
+"\n"\
+" q=<0-9> quality (0-highest, 9-lowest) (only for VBR)\n"\
+"\n"\
+" aq=<0-9> algorithmic quality (0-best/slowest, 9-worst/fastest)\n"\
+"\n"\
+" ratio=<1-100> compression ratio\n"\
+"\n"\
+" vol=<0-10> set audio input gain\n"\
+"\n"\
+" mode=<0-3> (default: auto)\n"\
+" 0: stereo\n"\
+" 1: joint-stereo\n"\
+" 2: dualchannel\n"\
+" 3: mono\n"\
+"\n"\
+" padding=<0-2>\n"\
+" 0: no\n"\
+" 1: all\n"\
+" 2: adjust\n"\
+"\n"\
+" fast Switch on faster encoding on subsequent VBR presets modes,\n"\
+" slightly lower quality and higher bitrates.\n"\
+"\n"\
+" preset=<value> Provide the highest possible quality settings.\n"\
+" medium: VBR encoding, good quality\n"\
+" (150-180 kbps bitrate range)\n"\
+" standard: VBR encoding, high quality\n"\
+" (170-210 kbps bitrate range)\n"\
+" extreme: VBR encoding, very high quality\n"\
+" (200-240 kbps bitrate range)\n"\
+" insane: CBR encoding, highest preset quality\n"\
+" (320 kbps bitrate)\n"\
+" <8-320>: ABR encoding at average given kbps bitrate.\n\n"
+
+// codec-cfg.c
+#define MSGTR_DuplicateFourcc "duplicated FourCC"
+#define MSGTR_TooManyFourccs "too many FourCCs/formats..."
+#define MSGTR_ParseError "parse error"
+#define MSGTR_ParseErrorFIDNotNumber "parse error (format ID not a number?)"
+#define MSGTR_ParseErrorFIDAliasNotNumber "parse error (format ID alias not a number?)"
+#define MSGTR_DuplicateFID "duplicated format ID"
+#define MSGTR_TooManyOut "too many out..."
+#define MSGTR_InvalidCodecName "\ncodec(%s) name is not valid!\n"
+#define MSGTR_CodecLacksFourcc "\ncodec(%s) does not have FourCC/format!\n"
+#define MSGTR_CodecLacksDriver "\ncodec(%s) does not have a driver!\n"
+#define MSGTR_CodecNeedsDLL "\ncodec(%s) needs a 'dll'!\n"
+#define MSGTR_CodecNeedsOutfmt "\ncodec(%s) needs an 'outfmt'!\n"
+#define MSGTR_CantAllocateComment "Can't allocate memory for comment. "
+#define MSGTR_GetTokenMaxNotLessThanMAX_NR_TOKEN "get_token(): max >= MAX_MR_TOKEN!"
+#define MSGTR_ReadingFile "Reading %s: "
+#define MSGTR_CantOpenFileError "Can't open '%s': %s\n"
+#define MSGTR_CantGetMemoryForLine "Can't get memory for 'line': %s\n"
+#define MSGTR_CantReallocCodecsp "Can't realloc '*codecsp': %s\n"
+#define MSGTR_CodecNameNotUnique "Codec name '%s' isn't unique."
+#define MSGTR_CantStrdupName "Can't strdup -> 'name': %s\n"
+#define MSGTR_CantStrdupInfo "Can't strdup -> 'info': %s\n"
+#define MSGTR_CantStrdupDriver "Can't strdup -> 'driver': %s\n"
+#define MSGTR_CantStrdupDLL "Can't strdup -> 'dll': %s"
+#define MSGTR_AudioVideoCodecTotals "%d audio & %d video codecs\n"
+#define MSGTR_CodecDefinitionIncorrect "Codec is not defined correctly."
+#define MSGTR_OutdatedCodecsConf "This codecs.conf is too old and incompatible with this MPlayer release!"
+
+// fifo.c
+#define MSGTR_CannotMakePipe "Cannot make PIPE!\n"
+
+// parser-mecmd.c, parser-mpcmd.c
+#define MSGTR_NoFileGivenOnCommandLine "'--' indicates no more options, but no filename was given on the command line.\n"
+#define MSGTR_TheLoopOptionMustBeAnInteger "The loop option must be an integer: %s\n"
+#define MSGTR_UnknownOptionOnCommandLine "Unknown option on the command line: -%s\n"
+#define MSGTR_ErrorParsingOptionOnCommandLine "Error parsing option on the command line: -%s\n"
+#define MSGTR_InvalidPlayEntry "Invalid play entry %s\n"
+#define MSGTR_NotAnMEncoderOption "-%s is not an MEncoder option\n"
+#define MSGTR_NoFileGiven "No file given\n"
+
+// m_config.c
+#define MSGTR_SaveSlotTooOld "Save slot found from lvl %d is too old: %d !!!\n"
+#define MSGTR_InvalidCfgfileOption "The %s option can't be used in a config file.\n"
+#define MSGTR_InvalidCmdlineOption "The %s option can't be used on the command line.\n"
+#define MSGTR_InvalidSuboption "Error: option '%s' has no suboption '%s'.\n"
+#define MSGTR_MissingSuboptionParameter "Error: suboption '%s' of '%s' must have a parameter!\n"
+#define MSGTR_MissingOptionParameter "Error: option '%s' must have a parameter!\n"
+#define MSGTR_OptionListHeader "\n Name Type Min Max Global CL Cfg\n\n"
+#define MSGTR_TotalOptions "\nTotal: %d options\n"
+#define MSGTR_ProfileInclusionTooDeep "WARNING: Profile inclusion too deep.\n"
+#define MSGTR_NoProfileDefined "No profiles have been defined.\n"
+#define MSGTR_AvailableProfiles "Available profiles:\n"
+#define MSGTR_UnknownProfile "Unknown profile '%s'.\n"
+#define MSGTR_Profile "Profile %s: %s\n"
+
+// m_property.c
+#define MSGTR_PropertyListHeader "\n Name Type Min Max\n\n"
+#define MSGTR_TotalProperties "\nTotal: %d properties\n"
+
+// loader/ldt_keeper.c
+#define MSGTR_LOADER_DYLD_Warning "WARNING: Attempting to use DLL codecs but environment variable\n DYLD_BIND_AT_LAUNCH not set. This will likely crash.\n"
+
+
+// ====================== GUI messages/buttons ========================
+
+// --- labels ---
+#define MSGTR_About "About"
+#define MSGTR_FileSelect "Select file..."
+#define MSGTR_SubtitleSelect "Select subtitle..."
+#define MSGTR_OtherSelect "Select..."
+#define MSGTR_AudioFileSelect "Select external audio channel..."
+#define MSGTR_FontSelect "Select font..."
+// Note: If you change MSGTR_PlayList please see if it still fits MSGTR_MENU_PlayList
+#define MSGTR_PlayList "Playlist"
+#define MSGTR_Equalizer "Equalizer"
+#define MSGTR_ConfigureEqualizer "Configure Equalizer"
+#define MSGTR_SkinBrowser "Skin Browser"
+#define MSGTR_Network "Network streaming..."
+// Note: If you change MSGTR_Preferences please see if it still fits MSGTR_MENU_Preferences
+#define MSGTR_Preferences "Preferences"
+#define MSGTR_AudioPreferences "Audio driver configuration"
+#define MSGTR_NoMediaOpened "No media opened."
+#define MSGTR_VCDTrack "VCD track %d"
+#define MSGTR_NoChapter "No chapter"
+#define MSGTR_Chapter "Chapter %d"
+#define MSGTR_NoFileLoaded "No file loaded."
+
+// --- buttons ---
+#define MSGTR_Ok "OK"
+#define MSGTR_Cancel "Cancel"
+#define MSGTR_Add "Add"
+#define MSGTR_Remove "Remove"
+#define MSGTR_Clear "Clear"
+#define MSGTR_Config "Config"
+#define MSGTR_ConfigDriver "Configure driver"
+#define MSGTR_Browse "Browse"
+
+// --- error messages ---
+#define MSGTR_NEMDB "Sorry, not enough memory to draw buffer."
+#define MSGTR_NEMFMR "Sorry, not enough memory for menu rendering."
+#define MSGTR_IDFGCVD "Sorry, I did not find a GUI-compatible video output driver."
+#define MSGTR_NEEDLAVC "Sorry, you cannot play non-MPEG files with your DXR3/H+ device without reencoding.\nPlease enable lavc in the DXR3/H+ configuration box."
+#define MSGTR_UNKNOWNWINDOWTYPE "Unknown window type found ..."
+
+// --- skin loader error messages
+#define MSGTR_SKIN_ERRORMESSAGE "[skin] error in skin config file on line %d: %s"
+#define MSGTR_SKIN_WARNING1 "[skin] warning: in config file line %d:\nwidget (%s) found but no \"section\" found before"
+#define MSGTR_SKIN_WARNING2 "[skin] warning: in config file line %d:\nwidget (%s) found but no \"subsection\" found before"
+#define MSGTR_SKIN_WARNING3 "[skin] warning: in config file line %d:\nthis subsection is not supported by widget (%s)"
+#define MSGTR_SKIN_SkinFileNotFound "[skin] file ( %s ) not found.\n"
+#define MSGTR_SKIN_SkinFileNotReadable "[skin] file ( %s ) not readable.\n"
+#define MSGTR_SKIN_BITMAP_16bit "Bitmaps of 16 bits or less depth not supported (%s).\n"
+#define MSGTR_SKIN_BITMAP_FileNotFound "File not found (%s)\n"
+#define MSGTR_SKIN_BITMAP_BMPReadError "BMP read error (%s)\n"
+#define MSGTR_SKIN_BITMAP_TGAReadError "TGA read error (%s)\n"
+#define MSGTR_SKIN_BITMAP_PNGReadError "PNG read error (%s)\n"
+#define MSGTR_SKIN_BITMAP_RLENotSupported "RLE packed TGA not supported (%s)\n"
+#define MSGTR_SKIN_BITMAP_UnknownFileType "unknown file type (%s)\n"
+#define MSGTR_SKIN_BITMAP_ConversionError "24 bit to 32 bit conversion error (%s)\n"
+#define MSGTR_SKIN_BITMAP_UnknownMessage "unknown message: %s\n"
+#define MSGTR_SKIN_FONT_NotEnoughtMemory "not enough memory\n"
+#define MSGTR_SKIN_FONT_TooManyFontsDeclared "Too many fonts declared.\n"
+#define MSGTR_SKIN_FONT_FontFileNotFound "Font file not found.\n"
+#define MSGTR_SKIN_FONT_FontImageNotFound "Font image file not found.\n"
+#define MSGTR_SKIN_FONT_NonExistentFontID "non-existent font identifier (%s)\n"
+#define MSGTR_SKIN_UnknownParameter "unknown parameter (%s)\n"
+#define MSGTR_SKIN_SKINCFG_SkinNotFound "Skin not found (%s).\n"
+#define MSGTR_SKIN_SKINCFG_SelectedSkinNotFound "Selected skin ( %s ) not found, trying 'default'...\n"
+#define MSGTR_SKIN_SKINCFG_SkinCfgReadError "skin config file read error (%s)\n"
+#define MSGTR_SKIN_LABEL "Skins:"
+
+// --- GTK menus
+#define MSGTR_MENU_AboutMPlayer "About MPlayer"
+#define MSGTR_MENU_Open "Open..."
+#define MSGTR_MENU_PlayFile "Play file..."
+#define MSGTR_MENU_PlayVCD "Play VCD..."
+#define MSGTR_MENU_PlayDVD "Play DVD..."
+#define MSGTR_MENU_PlayURL "Play URL..."
+#define MSGTR_MENU_LoadSubtitle "Load subtitle..."
+#define MSGTR_MENU_DropSubtitle "Drop subtitle..."
+#define MSGTR_MENU_LoadExternAudioFile "Load external audio file..."
+#define MSGTR_MENU_Playing "Playing"
+#define MSGTR_MENU_Play "Play"
+#define MSGTR_MENU_Pause "Pause"
+#define MSGTR_MENU_Stop "Stop"
+#define MSGTR_MENU_NextStream "Next stream"
+#define MSGTR_MENU_PrevStream "Prev stream"
+#define MSGTR_MENU_Size "Size"
+#define MSGTR_MENU_HalfSize "Half size"
+#define MSGTR_MENU_NormalSize "Normal size"
+#define MSGTR_MENU_DoubleSize "Double size"
+#define MSGTR_MENU_FullScreen "Fullscreen"
+#define MSGTR_MENU_DVD "DVD"
+#define MSGTR_MENU_VCD "VCD"
+#define MSGTR_MENU_PlayDisc "Open disc..."
+#define MSGTR_MENU_ShowDVDMenu "Show DVD menu"
+#define MSGTR_MENU_Titles "Titles"
+#define MSGTR_MENU_Title "Title %2d"
+#define MSGTR_MENU_None "(none)"
+#define MSGTR_MENU_Chapters "Chapters"
+#define MSGTR_MENU_Chapter "Chapter %2d"
+#define MSGTR_MENU_AudioLanguages "Audio languages"
+#define MSGTR_MENU_SubtitleLanguages "Subtitle languages"
+#define MSGTR_MENU_PlayList MSGTR_PlayList
+#define MSGTR_MENU_SkinBrowser "Skin browser"
+#define MSGTR_MENU_Preferences MSGTR_Preferences
+#define MSGTR_MENU_Exit "Exit..."
+#define MSGTR_MENU_Mute "Mute"
+#define MSGTR_MENU_Original "Original"
+#define MSGTR_MENU_AspectRatio "Aspect ratio"
+#define MSGTR_MENU_AudioTrack "Audio track"
+#define MSGTR_MENU_Track "Track %d"
+#define MSGTR_MENU_VideoTrack "Video track"
+#define MSGTR_MENU_Subtitles "Subtitles"
+
+// --- equalizer
+// Note: If you change MSGTR_EQU_Audio please see if it still fits MSGTR_PREFERENCES_Audio
+#define MSGTR_EQU_Audio "Audio"
+// Note: If you change MSGTR_EQU_Video please see if it still fits MSGTR_PREFERENCES_Video
+#define MSGTR_EQU_Video "Video"
+#define MSGTR_EQU_Contrast "Contrast: "
+#define MSGTR_EQU_Brightness "Brightness: "
+#define MSGTR_EQU_Hue "Hue: "
+#define MSGTR_EQU_Saturation "Saturation: "
+#define MSGTR_EQU_Front_Left "Front Left"
+#define MSGTR_EQU_Front_Right "Front Right"
+#define MSGTR_EQU_Back_Left "Rear Left"
+#define MSGTR_EQU_Back_Right "Rear Right"
+#define MSGTR_EQU_Center "Center"
+#define MSGTR_EQU_Bass "Bass"
+#define MSGTR_EQU_All "All"
+#define MSGTR_EQU_Channel1 "Channel 1:"
+#define MSGTR_EQU_Channel2 "Channel 2:"
+#define MSGTR_EQU_Channel3 "Channel 3:"
+#define MSGTR_EQU_Channel4 "Channel 4:"
+#define MSGTR_EQU_Channel5 "Channel 5:"
+#define MSGTR_EQU_Channel6 "Channel 6:"
+
+// --- playlist
+#define MSGTR_PLAYLIST_Path "Path"
+#define MSGTR_PLAYLIST_Selected "Selected files"
+#define MSGTR_PLAYLIST_Files "Files"
+#define MSGTR_PLAYLIST_DirectoryTree "Directory tree"
+
+// --- preferences
+#define MSGTR_PREFERENCES_Audio MSGTR_EQU_Audio
+#define MSGTR_PREFERENCES_Video MSGTR_EQU_Video
+#define MSGTR_PREFERENCES_SubtitleOSD "Subtitles & OSD"
+#define MSGTR_PREFERENCES_Codecs "Codecs & demuxer"
+// Note: If you change MSGTR_PREFERENCES_Misc see if it still fits MSGTR_PREFERENCES_FRAME_Misc
+#define MSGTR_PREFERENCES_Misc "Misc"
+#define MSGTR_PREFERENCES_None "None"
+#define MSGTR_PREFERENCES_DriverDefault "driver default"
+#define MSGTR_PREFERENCES_AvailableDrivers "Available drivers:"
+#define MSGTR_PREFERENCES_DoNotPlaySound "Do not play sound"
+#define MSGTR_PREFERENCES_NormalizeSound "Normalize sound"
+#define MSGTR_PREFERENCES_EnableEqualizer "Enable equalizer"
+#define MSGTR_PREFERENCES_SoftwareMixer "Enable Software Mixer"
+#define MSGTR_PREFERENCES_ExtraStereo "Enable extra stereo"
+#define MSGTR_PREFERENCES_Coefficient "Coefficient:"
+#define MSGTR_PREFERENCES_AudioDelay "Audio delay"
+#define MSGTR_PREFERENCES_DoubleBuffer "Enable double buffering"
+#define MSGTR_PREFERENCES_DirectRender "Enable direct rendering"
+#define MSGTR_PREFERENCES_FrameDrop "Enable frame dropping"
+#define MSGTR_PREFERENCES_HFrameDrop "Enable HARD frame dropping (dangerous)"
+#define MSGTR_PREFERENCES_Flip "Flip image upside down"
+#define MSGTR_PREFERENCES_Panscan "Panscan: "
+#define MSGTR_PREFERENCES_OSDTimer "Timer and indicators"
+#define MSGTR_PREFERENCES_OSDProgress "Progressbars only"
+#define MSGTR_PREFERENCES_OSDTimerPercentageTotalTime "Timer, percentage and total time"
+#define MSGTR_PREFERENCES_Subtitle "Subtitle:"
+#define MSGTR_PREFERENCES_SUB_Delay "Delay: "
+#define MSGTR_PREFERENCES_SUB_FPS "FPS:"
+#define MSGTR_PREFERENCES_SUB_POS "Position: "
+#define MSGTR_PREFERENCES_SUB_AutoLoad "Disable subtitle autoloading"
+#define MSGTR_PREFERENCES_SUB_Unicode "Unicode subtitle"
+#define MSGTR_PREFERENCES_SUB_MPSUB "Convert the given subtitle to MPlayer's subtitle format"
+#define MSGTR_PREFERENCES_SUB_SRT "Convert the given subtitle to the time based SubViewer (SRT) format"
+#define MSGTR_PREFERENCES_SUB_Overlap "Toggle subtitle overlapping"
+#define MSGTR_PREFERENCES_SUB_USE_ASS "SSA/ASS subtitle rendering"
+#define MSGTR_PREFERENCES_SUB_ASS_USE_MARGINS "Use margins"
+#define MSGTR_PREFERENCES_SUB_ASS_TOP_MARGIN "Top: "
+#define MSGTR_PREFERENCES_SUB_ASS_BOTTOM_MARGIN "Bottom: "
+#define MSGTR_PREFERENCES_Font "Font:"
+#define MSGTR_PREFERENCES_FontFactor "Font factor:"
+#define MSGTR_PREFERENCES_PostProcess "Enable postprocessing"
+#define MSGTR_PREFERENCES_AutoQuality "Auto quality: "
+#define MSGTR_PREFERENCES_NI "Use non-interleaved AVI parser"
+#define MSGTR_PREFERENCES_IDX "Rebuild index table, if needed"
+#define MSGTR_PREFERENCES_VideoCodecFamily "Video codec family:"
+#define MSGTR_PREFERENCES_AudioCodecFamily "Audio codec family:"
+#define MSGTR_PREFERENCES_FRAME_OSD_Level "OSD level"
+#define MSGTR_PREFERENCES_FRAME_Subtitle "Subtitle"
+#define MSGTR_PREFERENCES_FRAME_Font "Font"
+#define MSGTR_PREFERENCES_FRAME_PostProcess "Postprocessing"
+#define MSGTR_PREFERENCES_FRAME_CodecDemuxer "Codec & demuxer"
+#define MSGTR_PREFERENCES_FRAME_Cache "Cache"
+#define MSGTR_PREFERENCES_FRAME_Misc MSGTR_PREFERENCES_Misc
+#define MSGTR_PREFERENCES_Audio_Device "Device:"
+#define MSGTR_PREFERENCES_Audio_Mixer "Mixer:"
+#define MSGTR_PREFERENCES_Audio_MixerChannel "Mixer channel:"
+#define MSGTR_PREFERENCES_Message "Please remember that you need to restart playback for some options to take effect!"
+#define MSGTR_PREFERENCES_DXR3_VENC "Video encoder:"
+#define MSGTR_PREFERENCES_DXR3_LAVC "Use LAVC (FFmpeg)"
+#define MSGTR_PREFERENCES_FontEncoding1 "Unicode"
+#define MSGTR_PREFERENCES_FontEncoding2 "Western European Languages (ISO-8859-1)"
+#define MSGTR_PREFERENCES_FontEncoding3 "Western European Languages with Euro (ISO-8859-15)"
+#define MSGTR_PREFERENCES_FontEncoding4 "Slavic/Central European Languages (ISO-8859-2)"
+#define MSGTR_PREFERENCES_FontEncoding5 "Esperanto, Galician, Maltese, Turkish (ISO-8859-3)"
+#define MSGTR_PREFERENCES_FontEncoding6 "Old Baltic charset (ISO-8859-4)"
+#define MSGTR_PREFERENCES_FontEncoding7 "Cyrillic (ISO-8859-5)"
+#define MSGTR_PREFERENCES_FontEncoding8 "Arabic (ISO-8859-6)"
+#define MSGTR_PREFERENCES_FontEncoding9 "Modern Greek (ISO-8859-7)"
+#define MSGTR_PREFERENCES_FontEncoding10 "Turkish (ISO-8859-9)"
+#define MSGTR_PREFERENCES_FontEncoding11 "Baltic (ISO-8859-13)"
+#define MSGTR_PREFERENCES_FontEncoding12 "Celtic (ISO-8859-14)"
+#define MSGTR_PREFERENCES_FontEncoding13 "Hebrew charsets (ISO-8859-8)"
+#define MSGTR_PREFERENCES_FontEncoding14 "Russian (KOI8-R)"
+#define MSGTR_PREFERENCES_FontEncoding15 "Ukrainian, Belarusian (KOI8-U/RU)"
+#define MSGTR_PREFERENCES_FontEncoding16 "Simplified Chinese charset (CP936)"
+#define MSGTR_PREFERENCES_FontEncoding17 "Traditional Chinese charset (BIG5)"
+#define MSGTR_PREFERENCES_FontEncoding18 "Japanese charsets (SHIFT-JIS)"
+#define MSGTR_PREFERENCES_FontEncoding19 "Korean charset (CP949)"
+#define MSGTR_PREFERENCES_FontEncoding20 "Thai charset (CP874)"
+#define MSGTR_PREFERENCES_FontEncoding21 "Cyrillic Windows (CP1251)"
+#define MSGTR_PREFERENCES_FontEncoding22 "Slavic/Central European Windows (CP1250)"
+#define MSGTR_PREFERENCES_FontEncoding23 "Arabic Windows (CP1256)"
+#define MSGTR_PREFERENCES_FontNoAutoScale "No autoscale"
+#define MSGTR_PREFERENCES_FontPropWidth "Proportional to movie width"
+#define MSGTR_PREFERENCES_FontPropHeight "Proportional to movie height"
+#define MSGTR_PREFERENCES_FontPropDiagonal "Proportional to movie diagonal"
+#define MSGTR_PREFERENCES_FontEncoding "Encoding:"
+#define MSGTR_PREFERENCES_FontBlur "Blur:"
+#define MSGTR_PREFERENCES_FontOutLine "Outline:"
+#define MSGTR_PREFERENCES_FontTextScale "Text scale:"
+#define MSGTR_PREFERENCES_FontOSDScale "OSD scale:"
+#define MSGTR_PREFERENCES_Cache "Cache on/off"
+#define MSGTR_PREFERENCES_CacheSize "Cache size: "
+#define MSGTR_PREFERENCES_LoadFullscreen "Start in fullscreen"
+#define MSGTR_PREFERENCES_SaveWinPos "Save window position"
+#define MSGTR_PREFERENCES_XSCREENSAVER "Stop XScreenSaver"
+#define MSGTR_PREFERENCES_PlayBar "Enable playbar"
+#define MSGTR_PREFERENCES_AutoSync "AutoSync on/off"
+#define MSGTR_PREFERENCES_AutoSyncValue "Autosync: "
+#define MSGTR_PREFERENCES_CDROMDevice "CD-ROM device:"
+#define MSGTR_PREFERENCES_DVDDevice "DVD device:"
+#define MSGTR_PREFERENCES_FPS "Movie FPS:"
+#define MSGTR_PREFERENCES_ShowVideoWindow "Show video window when inactive"
+#define MSGTR_PREFERENCES_ArtsBroken "Newer aRts versions are incompatible "\
+ "with GTK 1.x and will crash GMPlayer!"
+
+// -- aboutbox
+#define MSGTR_ABOUT_UHU "GUI development sponsored by UHU Linux\n"
+#define MSGTR_ABOUT_Contributors "Code and documentation contributors\n"
+#define MSGTR_ABOUT_Codecs_libs_contributions "Codecs and third party libraries\n"
+#define MSGTR_ABOUT_Translations "Translations\n"
+#define MSGTR_ABOUT_Skins "Skins\n"
+
+// --- messagebox
+#define MSGTR_MSGBOX_LABEL_FatalError "Fatal error!"
+#define MSGTR_MSGBOX_LABEL_Error "Error!"
+#define MSGTR_MSGBOX_LABEL_Warning "Warning!"
+
+// bitmap.c
+#define MSGTR_NotEnoughMemoryC32To1 "[c32to1] not enough memory for image\n"
+#define MSGTR_NotEnoughMemoryC1To32 "[c1to32] not enough memory for image\n"
+
+// cfg.c
+#define MSGTR_ConfigFileReadError "[cfg] config file read error ...\n"
+#define MSGTR_UnableToSaveOption "[cfg] Unable to save the '%s' option.\n"
+
+// interface.c
+#define MSGTR_DeletingSubtitles "[GUI] Deleting subtitles.\n"
+#define MSGTR_LoadingSubtitles "[GUI] Loading subtitles: %s\n"
+#define MSGTR_AddingVideoFilter "[GUI] Adding video filter: %s\n"
+#define MSGTR_RemovingVideoFilter "[GUI] Removing video filter: %s\n"
+
+// mw.c
+#define MSGTR_NotAFile "This does not seem to be a file: %s !\n"
+
+// ws.c
+#define MSGTR_WS_CouldNotOpenDisplay "[ws] Could not open the display.\n"
+#define MSGTR_WS_RemoteDisplay "[ws] Remote display, disabling XMITSHM.\n"
+#define MSGTR_WS_NoXshm "[ws] Sorry, your system does not support the X shared memory extension.\n"
+#define MSGTR_WS_NoXshape "[ws] Sorry, your system does not support the XShape extension.\n"
+#define MSGTR_WS_ColorDepthTooLow "[ws] Sorry, the color depth is too low.\n"
+#define MSGTR_WS_TooManyOpenWindows "[ws] There are too many open windows.\n"
+#define MSGTR_WS_ShmError "[ws] shared memory extension error\n"
+#define MSGTR_WS_NotEnoughMemoryDrawBuffer "[ws] Sorry, not enough memory to draw buffer.\n"
+#define MSGTR_WS_DpmsUnavailable "DPMS not available?\n"
+#define MSGTR_WS_DpmsNotEnabled "Could not enable DPMS.\n"
+
+// wsxdnd.c
+#define MSGTR_WS_NotAFile "This does not seem to be a file...\n"
+#define MSGTR_WS_DDNothing "D&D: Nothing returned!\n"
+
+// ======================= video output drivers ========================
+
+#define MSGTR_VOincompCodec "The selected video_out device is incompatible with this codec.\n"\
+ "Try appending the scale filter to your filter list,\n"\
+ "e.g. -vf spp,scale instead of -vf spp.\n"
+#define MSGTR_VO_GenericError "This error has occurred"
+#define MSGTR_VO_UnableToAccess "Unable to access"
+#define MSGTR_VO_ExistsButNoDirectory "already exists, but is not a directory."
+#define MSGTR_VO_DirExistsButNotWritable "Output directory already exists, but is not writable."
+#define MSGTR_VO_DirExistsAndIsWritable "Output directory already exists and is writable."
+#define MSGTR_VO_CantCreateDirectory "Unable to create output directory."
+#define MSGTR_VO_CantCreateFile "Unable to create output file."
+#define MSGTR_VO_DirectoryCreateSuccess "Output directory successfully created."
+#define MSGTR_VO_ValueOutOfRange "value out of range"
+#define MSGTR_VO_NoValueSpecified "No value specified."
+#define MSGTR_VO_UnknownSuboptions "unknown suboption(s)"
+
+// aspect.c
+#define MSGTR_LIBVO_ASPECT_NoSuitableNewResFound "[ASPECT] Warning: No suitable new res found!\n"
+#define MSGTR_LIBVO_ASPECT_NoNewSizeFoundThatFitsIntoRes "[ASPECT] Error: No new size found that fits into res!\n"
+
+// font_load_ft.c
+#define MSGTR_LIBVO_FONT_LOAD_FT_NewFaceFailed "New_Face failed. Maybe the font path is wrong.\nPlease supply the text font file (~/.mplayer/subfont.ttf).\n"
+#define MSGTR_LIBVO_FONT_LOAD_FT_NewMemoryFaceFailed "New_Memory_Face failed..\n"
+#define MSGTR_LIBVO_FONT_LOAD_FT_SubFaceFailed "subtitle font: load_sub_face failed.\n"
+#define MSGTR_LIBVO_FONT_LOAD_FT_SubFontCharsetFailed "subtitle font: prepare_charset failed.\n"
+#define MSGTR_LIBVO_FONT_LOAD_FT_CannotPrepareSubtitleFont "Cannot prepare subtitle font.\n"
+#define MSGTR_LIBVO_FONT_LOAD_FT_CannotPrepareOSDFont "Cannot prepare OSD font.\n"
+#define MSGTR_LIBVO_FONT_LOAD_FT_CannotGenerateTables "Cannot generate tables.\n"
+#define MSGTR_LIBVO_FONT_LOAD_FT_DoneFreeTypeFailed "FT_Done_FreeType failed.\n"
+#define MSGTR_LIBVO_FONT_LOAD_FT_FontconfigNoMatch "Fontconfig failed to select a font. Trying without fontconfig...\n"
+
+// sub.c
+#define MSGTR_VO_SUB_Seekbar "Seekbar"
+#define MSGTR_VO_SUB_Play "Play"
+#define MSGTR_VO_SUB_Pause "Pause"
+#define MSGTR_VO_SUB_Stop "Stop"
+#define MSGTR_VO_SUB_Rewind "Rewind"
+#define MSGTR_VO_SUB_Forward "Forward"
+#define MSGTR_VO_SUB_Clock "Clock"
+#define MSGTR_VO_SUB_Contrast "Contrast"
+#define MSGTR_VO_SUB_Saturation "Saturation"
+#define MSGTR_VO_SUB_Volume "Volume"
+#define MSGTR_VO_SUB_Brightness "Brightness"
+#define MSGTR_VO_SUB_Hue "Hue"
+#define MSGTR_VO_SUB_Balance "Balance"
+
+// vo_3dfx.c
+#define MSGTR_LIBVO_3DFX_Only16BppSupported "[VO_3DFX] Only 16bpp supported!"
+#define MSGTR_LIBVO_3DFX_VisualIdIs "[VO_3DFX] Visual ID is %lx.\n"
+#define MSGTR_LIBVO_3DFX_UnableToOpenDevice "[VO_3DFX] Unable to open /dev/3dfx.\n"
+#define MSGTR_LIBVO_3DFX_Error "[VO_3DFX] Error: %d.\n"
+#define MSGTR_LIBVO_3DFX_CouldntMapMemoryArea "[VO_3DFX] Couldn't map 3dfx memory areas: %p,%p,%d.\n"
+#define MSGTR_LIBVO_3DFX_DisplayInitialized "[VO_3DFX] Initialized: %p.\n"
+#define MSGTR_LIBVO_3DFX_UnknownSubdevice "[VO_3DFX] Unknown subdevice: %s.\n"
+
+// vo_aa.c
+#define MSGTR_VO_AA_HelpHeader "\n\nHere are the aalib vo_aa suboptions:\n"
+#define MSGTR_VO_AA_AdditionalOptions "Additional options vo_aa provides:\n" \
+" help print this help message\n" \
+" osdcolor set OSD color\n subcolor set subtitle color\n" \
+" the color parameters are:\n 0 : normal\n" \
+" 1 : dim\n 2 : bold\n 3 : boldfont\n" \
+" 4 : reverse\n 5 : special\n\n\n"
+
+// vo_dxr3.c
+#define MSGTR_LIBVO_DXR3_UnableToLoadNewSPUPalette "[VO_DXR3] Unable to load new SPU palette!\n"
+#define MSGTR_LIBVO_DXR3_UnableToSetPlaymode "[VO_DXR3] Unable to set playmode!\n"
+#define MSGTR_LIBVO_DXR3_UnableToSetSubpictureMode "[VO_DXR3] Unable to set subpicture mode!\n"
+#define MSGTR_LIBVO_DXR3_UnableToGetTVNorm "[VO_DXR3] Unable to get TV norm!\n"
+#define MSGTR_LIBVO_DXR3_AutoSelectedTVNormByFrameRate "[VO_DXR3] Auto-selected TV norm by framerate: "
+#define MSGTR_LIBVO_DXR3_UnableToSetTVNorm "[VO_DXR3] Unable to set TV norm!\n"
+#define MSGTR_LIBVO_DXR3_SettingUpForNTSC "[VO_DXR3] Setting up for NTSC.\n"
+#define MSGTR_LIBVO_DXR3_SettingUpForPALSECAM "[VO_DXR3] Setting up for PAL/SECAM.\n"
+#define MSGTR_LIBVO_DXR3_SettingAspectRatioTo43 "[VO_DXR3] Setting aspect ratio to 4:3.\n"
+#define MSGTR_LIBVO_DXR3_SettingAspectRatioTo169 "[VO_DXR3] Setting aspect ratio to 16:9.\n"
+#define MSGTR_LIBVO_DXR3_OutOfMemory "[VO_DXR3] out of memory\n"
+#define MSGTR_LIBVO_DXR3_UnableToAllocateKeycolor "[VO_DXR3] Unable to allocate keycolor!\n"
+#define MSGTR_LIBVO_DXR3_UnableToAllocateExactKeycolor "[VO_DXR3] Unable to allocate exact keycolor, using closest match (0x%lx).\n"
+#define MSGTR_LIBVO_DXR3_Uninitializing "[VO_DXR3] Uninitializing.\n"
+#define MSGTR_LIBVO_DXR3_FailedRestoringTVNorm "[VO_DXR3] Failed restoring TV norm!\n"
+#define MSGTR_LIBVO_DXR3_EnablingPrebuffering "[VO_DXR3] Enabling prebuffering.\n"
+#define MSGTR_LIBVO_DXR3_UsingNewSyncEngine "[VO_DXR3] Using new sync engine.\n"
+#define MSGTR_LIBVO_DXR3_UsingOverlay "[VO_DXR3] Using overlay.\n"
+#define MSGTR_LIBVO_DXR3_ErrorYouNeedToCompileMplayerWithX11 "[VO_DXR3] Error: Overlay requires compiling with X11 libs/headers installed.\n"
+#define MSGTR_LIBVO_DXR3_WillSetTVNormTo "[VO_DXR3] Will set TV norm to: "
+#define MSGTR_LIBVO_DXR3_AutoAdjustToMovieFrameRatePALPAL60 "auto-adjust to movie framerate (PAL/PAL-60)"
+#define MSGTR_LIBVO_DXR3_AutoAdjustToMovieFrameRatePALNTSC "auto-adjust to movie framerate (PAL/NTSC)"
+#define MSGTR_LIBVO_DXR3_UseCurrentNorm "Use current norm."
+#define MSGTR_LIBVO_DXR3_UseUnknownNormSuppliedCurrentNorm "Unknown norm supplied. Use current norm."
+#define MSGTR_LIBVO_DXR3_ErrorOpeningForWritingTrying "[VO_DXR3] Error opening %s for writing, trying /dev/em8300 instead.\n"
+#define MSGTR_LIBVO_DXR3_ErrorOpeningForWritingTryingMV "[VO_DXR3] Error opening %s for writing, trying /dev/em8300_mv instead.\n"
+#define MSGTR_LIBVO_DXR3_ErrorOpeningForWritingAsWell "[VO_DXR3] Error opening /dev/em8300 for writing as well!\nBailing out.\n"
+#define MSGTR_LIBVO_DXR3_ErrorOpeningForWritingAsWellMV "[VO_DXR3] Error opening /dev/em8300_mv for writing as well!\nBailing out.\n"
+#define MSGTR_LIBVO_DXR3_Opened "[VO_DXR3] Opened: %s.\n"
+#define MSGTR_LIBVO_DXR3_ErrorOpeningForWritingTryingSP "[VO_DXR3] Error opening %s for writing, trying /dev/em8300_sp instead.\n"
+#define MSGTR_LIBVO_DXR3_ErrorOpeningForWritingAsWellSP "[VO_DXR3] Error opening /dev/em8300_sp for writing as well!\nBailing out.\n"
+#define MSGTR_LIBVO_DXR3_UnableToOpenDisplayDuringHackSetup "[VO_DXR3] Unable to open display during overlay hack setup!\n"
+#define MSGTR_LIBVO_DXR3_UnableToInitX11 "[VO_DXR3] Unable to init X11!\n"
+#define MSGTR_LIBVO_DXR3_FailedSettingOverlayAttribute "[VO_DXR3] Failed setting overlay attribute.\n"
+#define MSGTR_LIBVO_DXR3_FailedSettingOverlayScreen "[VO_DXR3] Failed setting overlay screen!\nExiting.\n"
+#define MSGTR_LIBVO_DXR3_FailedEnablingOverlay "[VO_DXR3] Failed enabling overlay!\nExiting.\n"
+#define MSGTR_LIBVO_DXR3_FailedResizingOverlayWindow "[VO_DXR3] Failed resizing overlay window!\n"
+#define MSGTR_LIBVO_DXR3_FailedSettingOverlayBcs "[VO_DXR3] Failed setting overlay bcs!\n"
+#define MSGTR_LIBVO_DXR3_FailedGettingOverlayYOffsetValues "[VO_DXR3] Failed getting overlay Y-offset values!\nExiting.\n"
+#define MSGTR_LIBVO_DXR3_FailedGettingOverlayXOffsetValues "[VO_DXR3] Failed getting overlay X-offset values!\nExiting.\n"
+#define MSGTR_LIBVO_DXR3_FailedGettingOverlayXScaleCorrection "[VO_DXR3] Failed getting overlay X scale correction!\nExiting.\n"
+#define MSGTR_LIBVO_DXR3_YOffset "[VO_DXR3] Yoffset: %d.\n"
+#define MSGTR_LIBVO_DXR3_XOffset "[VO_DXR3] Xoffset: %d.\n"
+#define MSGTR_LIBVO_DXR3_XCorrection "[VO_DXR3] Xcorrection: %d.\n"
+#define MSGTR_LIBVO_DXR3_FailedSetSignalMix "[VO_DXR3] Failed to set signal mix!\n"
+
+// vo_jpeg.c
+#define MSGTR_VO_JPEG_ProgressiveJPEG "Progressive JPEG enabled."
+#define MSGTR_VO_JPEG_NoProgressiveJPEG "Progressive JPEG disabled."
+#define MSGTR_VO_JPEG_BaselineJPEG "Baseline JPEG enabled."
+#define MSGTR_VO_JPEG_NoBaselineJPEG "Baseline JPEG disabled."
+
+// vo_mga.c
+#define MSGTR_LIBVO_MGA_AspectResized "[VO_MGA] aspect(): resized to %dx%d.\n"
+#define MSGTR_LIBVO_MGA_Uninit "[VO] uninit!\n"
+
+// mga_template.c
+#define MSGTR_LIBVO_MGA_ErrorInConfigIoctl "[MGA] error in mga_vid_config ioctl (wrong mga_vid.o version?)"
+#define MSGTR_LIBVO_MGA_CouldNotGetLumaValuesFromTheKernelModule "[MGA] Could not get luma values from the kernel module!\n"
+#define MSGTR_LIBVO_MGA_CouldNotSetLumaValuesFromTheKernelModule "[MGA] Could not set luma values from the kernel module!\n"
+#define MSGTR_LIBVO_MGA_ScreenWidthHeightUnknown "[MGA] Screen width/height unknown!\n"
+#define MSGTR_LIBVO_MGA_InvalidOutputFormat "[MGA] invalid output format %0X\n"
+#define MSGTR_LIBVO_MGA_IncompatibleDriverVersion "[MGA] Your mga_vid driver version is incompatible with this MPlayer version!\n"
+#define MSGTR_LIBVO_MGA_CouldntOpen "[MGA] Couldn't open: %s\n"
+#define MSGTR_LIBVO_MGA_ResolutionTooHigh "[MGA] Source resolution exceeds 1023x1023 in at least one dimension.\n[MGA] Rescale in software or use -lavdopts lowres=1.\n"
+#define MSGTR_LIBVO_MGA_mgavidVersionMismatch "[MGA] mismatch between kernel (%u) and MPlayer (%u) mga_vid driver versions\n"
+
+// vo_null.c
+#define MSGTR_LIBVO_NULL_UnknownSubdevice "[VO_NULL] Unknown subdevice: %s.\n"
+
+// vo_png.c
+#define MSGTR_LIBVO_PNG_Warning1 "[VO_PNG] Warning: compression level set to 0, compression disabled!\n"
+#define MSGTR_LIBVO_PNG_Warning2 "[VO_PNG] Info: Use -vo png:z=<n> to set compression level from 0 to 9.\n"
+#define MSGTR_LIBVO_PNG_Warning3 "[VO_PNG] Info: (0 = no compression, 1 = fastest, lowest - 9 best, slowest compression)\n"
+#define MSGTR_LIBVO_PNG_ErrorOpeningForWriting "\n[VO_PNG] Error opening '%s' for writing!\n"
+#define MSGTR_LIBVO_PNG_ErrorInCreatePng "[VO_PNG] Error in create_png.\n"
+
+// vo_pnm.c
+#define MSGTR_VO_PNM_ASCIIMode "ASCII mode enabled."
+#define MSGTR_VO_PNM_RawMode "Raw mode enabled."
+#define MSGTR_VO_PNM_PPMType "Will write PPM files."
+#define MSGTR_VO_PNM_PGMType "Will write PGM files."
+#define MSGTR_VO_PNM_PGMYUVType "Will write PGMYUV files."
+
+// vo_sdl.c
+#define MSGTR_LIBVO_SDL_CouldntGetAnyAcceptableSDLModeForOutput "[VO_SDL] Couldn't get any acceptable SDL Mode for output.\n"
+#define MSGTR_LIBVO_SDL_SetVideoModeFailed "[VO_SDL] set_video_mode: SDL_SetVideoMode failed: %s.\n"
+#define MSGTR_LIBVO_SDL_SetVideoModeFailedFull "[VO_SDL] Set_fullmode: SDL_SetVideoMode failed: %s.\n"
+#define MSGTR_LIBVO_SDL_MappingI420ToIYUV "[VO_SDL] Mapping I420 to IYUV.\n"
+#define MSGTR_LIBVO_SDL_UnsupportedImageFormat "[VO_SDL] Unsupported image format (0x%X).\n"
+#define MSGTR_LIBVO_SDL_InfoPleaseUseVmOrZoom "[VO_SDL] Info - please use -vm or -zoom to switch to the best resolution.\n"
+#define MSGTR_LIBVO_SDL_FailedToSetVideoMode "[VO_SDL] Failed to set video mode: %s.\n"
+#define MSGTR_LIBVO_SDL_CouldntCreateAYUVOverlay "[VO_SDL] Couldn't create a YUV overlay: %s.\n"
+#define MSGTR_LIBVO_SDL_CouldntCreateARGBSurface "[VO_SDL] Couldn't create an RGB surface: %s.\n"
+#define MSGTR_LIBVO_SDL_UsingDepthColorspaceConversion "[VO_SDL] Using depth/colorspace conversion, this will slow things down (%ibpp -> %ibpp).\n"
+#define MSGTR_LIBVO_SDL_UnsupportedImageFormatInDrawslice "[VO_SDL] Unsupported image format in draw_slice, contact MPlayer developers!\n"
+#define MSGTR_LIBVO_SDL_BlitFailed "[VO_SDL] Blit failed: %s.\n"
+#define MSGTR_LIBVO_SDL_InitializationFailed "[VO_SDL] SDL initialization failed: %s.\n"
+#define MSGTR_LIBVO_SDL_UsingDriver "[VO_SDL] Using driver: %s.\n"
+
+// vo_svga.c
+#define MSGTR_LIBVO_SVGA_ForcedVidmodeNotAvailable "[VO_SVGA] Forced vid_mode %d (%s) not available.\n"
+#define MSGTR_LIBVO_SVGA_ForcedVidmodeTooSmall "[VO_SVGA] Forced vid_mode %d (%s) too small.\n"
+#define MSGTR_LIBVO_SVGA_Vidmode "[VO_SVGA] Vid_mode: %d, %dx%d %dbpp.\n"
+#define MSGTR_LIBVO_SVGA_VgasetmodeFailed "[VO_SVGA] Vga_setmode(%d) failed.\n"
+#define MSGTR_LIBVO_SVGA_VideoModeIsLinearAndMemcpyCouldBeUsed "[VO_SVGA] Video mode is linear and memcpy could be used for image transfer.\n"
+#define MSGTR_LIBVO_SVGA_VideoModeHasHardwareAcceleration "[VO_SVGA] Video mode has hardware acceleration and put_image could be used.\n"
+#define MSGTR_LIBVO_SVGA_IfItWorksForYouIWouldLikeToKnow "[VO_SVGA] If it works for you I would like to know.\n[VO_SVGA] (send log with `mplayer test.avi -v -v -v -v &> svga.log`). Thx!\n"
+#define MSGTR_LIBVO_SVGA_VideoModeHas "[VO_SVGA] Video mode has %d page(s).\n"
+#define MSGTR_LIBVO_SVGA_CenteringImageStartAt "[VO_SVGA] Centering image. Starting at (%d,%d)\n"
+#define MSGTR_LIBVO_SVGA_UsingVidix "[VO_SVGA] Using VIDIX. w=%i h=%i mw=%i mh=%i\n"
+
+// vo_tdfx_vid.c
+#define MSGTR_LIBVO_TDFXVID_Move "[VO_TDXVID] Move %d(%d) x %d => %d.\n"
+#define MSGTR_LIBVO_TDFXVID_AGPMoveFailedToClearTheScreen "[VO_TDFXVID] AGP move failed to clear the screen.\n"
+#define MSGTR_LIBVO_TDFXVID_BlitFailed "[VO_TDFXVID] Blit failed.\n"
+#define MSGTR_LIBVO_TDFXVID_NonNativeOverlayFormatNeedConversion "[VO_TDFXVID] Non-native overlay format needs conversion.\n"
+#define MSGTR_LIBVO_TDFXVID_UnsupportedInputFormat "[VO_TDFXVID] Unsupported input format 0x%x.\n"
+#define MSGTR_LIBVO_TDFXVID_OverlaySetupFailed "[VO_TDFXVID] Overlay setup failed.\n"
+#define MSGTR_LIBVO_TDFXVID_OverlayOnFailed "[VO_TDFXVID] Overlay on failed.\n"
+#define MSGTR_LIBVO_TDFXVID_OverlayReady "[VO_TDFXVID] Overlay ready: %d(%d) x %d @ %d => %d(%d) x %d @ %d.\n"
+#define MSGTR_LIBVO_TDFXVID_TextureBlitReady "[VO_TDFXVID] Texture blit ready: %d(%d) x %d @ %d => %d(%d) x %d @ %d.\n"
+#define MSGTR_LIBVO_TDFXVID_OverlayOffFailed "[VO_TDFXVID] Overlay off failed\n"
+#define MSGTR_LIBVO_TDFXVID_CantOpen "[VO_TDFXVID] Can't open %s: %s.\n"
+#define MSGTR_LIBVO_TDFXVID_CantGetCurrentCfg "[VO_TDFXVID] Can't get current configuration: %s.\n"
+#define MSGTR_LIBVO_TDFXVID_MemmapFailed "[VO_TDFXVID] Memmap failed !!!!!\n"
+#define MSGTR_LIBVO_TDFXVID_GetImageTodo "Get image todo.\n"
+#define MSGTR_LIBVO_TDFXVID_AgpMoveFailed "[VO_TDFXVID] AGP move failed.\n"
+#define MSGTR_LIBVO_TDFXVID_SetYuvFailed "[VO_TDFXVID] Set YUV failed.\n"
+#define MSGTR_LIBVO_TDFXVID_AgpMoveFailedOnYPlane "[VO_TDFXVID] AGP move failed on Y plane.\n"
+#define MSGTR_LIBVO_TDFXVID_AgpMoveFailedOnUPlane "[VO_TDFXVID] AGP move failed on U plane.\n"
+#define MSGTR_LIBVO_TDFXVID_AgpMoveFailedOnVPlane "[VO_TDFXVID] AGP move failed on V plane.\n"
+#define MSGTR_LIBVO_TDFXVID_UnknownFormat "[VO_TDFXVID] unknown format: 0x%x.\n"
+
+// vo_tdfxfb.c
+#define MSGTR_LIBVO_TDFXFB_CantOpen "[VO_TDFXFB] Can't open %s: %s.\n"
+#define MSGTR_LIBVO_TDFXFB_ProblemWithFbitgetFscreenInfo "[VO_TDFXFB] Problem with FBITGET_FSCREENINFO ioctl: %s.\n"
+#define MSGTR_LIBVO_TDFXFB_ProblemWithFbitgetVscreenInfo "[VO_TDFXFB] Problem with FBITGET_VSCREENINFO ioctl: %s.\n"
+#define MSGTR_LIBVO_TDFXFB_ThisDriverOnlySupports "[VO_TDFXFB] This driver only supports the 3Dfx Banshee, Voodoo3 and Voodoo 5.\n"
+#define MSGTR_LIBVO_TDFXFB_OutputIsNotSupported "[VO_TDFXFB] %d bpp output is not supported.\n"
+#define MSGTR_LIBVO_TDFXFB_CouldntMapMemoryAreas "[VO_TDFXFB] Couldn't map memory areas: %s.\n"
+#define MSGTR_LIBVO_TDFXFB_BppOutputIsNotSupported "[VO_TDFXFB] %d bpp output is not supported (This should never have happened).\n"
+#define MSGTR_LIBVO_TDFXFB_SomethingIsWrongWithControl "[VO_TDFXFB] Eik! Something's wrong with control().\n"
+#define MSGTR_LIBVO_TDFXFB_NotEnoughVideoMemoryToPlay "[VO_TDFXFB] Not enough video memory to play this movie. Try at a lower resolution.\n"
+#define MSGTR_LIBVO_TDFXFB_ScreenIs "[VO_TDFXFB] Screen is %dx%d at %d bpp, in is %dx%d at %d bpp, norm is %dx%d.\n"
+
+// vo_tga.c
+#define MSGTR_LIBVO_TGA_UnknownSubdevice "[VO_TGA] Unknown subdevice: %s.\n"
+
+// vo_vesa.c
+#define MSGTR_LIBVO_VESA_FatalErrorOccurred "[VO_VESA] Fatal error occurred! Can't continue.\n"
+#define MSGTR_LIBVO_VESA_UnknownSubdevice "[VO_VESA] unknown subdevice: '%s'.\n"
+#define MSGTR_LIBVO_VESA_YouHaveTooLittleVideoMemory "[VO_VESA] You have too little video memory for this mode:\n[VO_VESA] Required: %08lX present: %08lX.\n"
+#define MSGTR_LIBVO_VESA_YouHaveToSpecifyTheCapabilitiesOfTheMonitor "[VO_VESA] You have to specify the capabilities of the monitor. Not changing refresh rate.\n"
+#define MSGTR_LIBVO_VESA_UnableToFitTheMode "[VO_VESA] The mode does not fit the monitor limits. Not changing refresh rate.\n"
+#define MSGTR_LIBVO_VESA_DetectedInternalFatalError "[VO_VESA] Detected internal fatal error: init is called before preinit.\n"
+#define MSGTR_LIBVO_VESA_SwitchFlipIsNotSupported "[VO_VESA] The -flip option is not supported.\n"
+#define MSGTR_LIBVO_VESA_PossibleReasonNoVbe2BiosFound "[VO_VESA] Possible reason: No VBE2 BIOS found.\n"
+#define MSGTR_LIBVO_VESA_FoundVesaVbeBiosVersion "[VO_VESA] Found VESA VBE BIOS Version %x.%x Revision: %x.\n"
+#define MSGTR_LIBVO_VESA_VideoMemory "[VO_VESA] Video memory: %u Kb.\n"
+#define MSGTR_LIBVO_VESA_Capabilites "[VO_VESA] VESA Capabilities: %s %s %s %s %s.\n"
+#define MSGTR_LIBVO_VESA_BelowWillBePrintedOemInfo "[VO_VESA] !!! OEM info will be printed below !!!\n"
+#define MSGTR_LIBVO_VESA_YouShouldSee5OemRelatedLines "[VO_VESA] You should see 5 OEM related lines below; If not, you've broken vm86.\n"
+#define MSGTR_LIBVO_VESA_OemInfo "[VO_VESA] OEM info: %s.\n"
+#define MSGTR_LIBVO_VESA_OemRevision "[VO_VESA] OEM Revision: %x.\n"
+#define MSGTR_LIBVO_VESA_OemVendor "[VO_VESA] OEM vendor: %s.\n"
+#define MSGTR_LIBVO_VESA_OemProductName "[VO_VESA] OEM Product Name: %s.\n"
+#define MSGTR_LIBVO_VESA_OemProductRev "[VO_VESA] OEM Product Rev: %s.\n"
+#define MSGTR_LIBVO_VESA_Hint "[VO_VESA] Hint: For working TV-Out you should have plugged in the TV connector\n"\
+"[VO_VESA] before booting since VESA BIOS initializes itself only during POST.\n"
+#define MSGTR_LIBVO_VESA_UsingVesaMode "[VO_VESA] Using VESA mode (%u) = %x [%ux%u@%u]\n"
+#define MSGTR_LIBVO_VESA_CantInitializeSwscaler "[VO_VESA] Can't initialize software scaler.\n"
+#define MSGTR_LIBVO_VESA_CantUseDga "[VO_VESA] Can't use DGA. Force bank switching mode. :(\n"
+#define MSGTR_LIBVO_VESA_UsingDga "[VO_VESA] Using DGA (physical resources: %08lXh, %08lXh)"
+#define MSGTR_LIBVO_VESA_CantUseDoubleBuffering "[VO_VESA] Can't use double buffering: not enough video memory.\n"
+#define MSGTR_LIBVO_VESA_CantFindNeitherDga "[VO_VESA] Can find neither DGA nor relocatable window frame.\n"
+#define MSGTR_LIBVO_VESA_YouveForcedDga "[VO_VESA] You've forced DGA. Exiting\n"
+#define MSGTR_LIBVO_VESA_CantFindValidWindowAddress "[VO_VESA] Can't find valid window address.\n"
+#define MSGTR_LIBVO_VESA_UsingBankSwitchingMode "[VO_VESA] Using bank switching mode (physical resources: %08lXh, %08lXh).\n"
+#define MSGTR_LIBVO_VESA_CantAllocateTemporaryBuffer "[VO_VESA] Can't allocate temporary buffer.\n"
+#define MSGTR_LIBVO_VESA_SorryUnsupportedMode "[VO_VESA] Sorry, unsupported mode -- try -x 640 -zoom.\n"
+#define MSGTR_LIBVO_VESA_OhYouReallyHavePictureOnTv "[VO_VESA] Oh you really have a picture on the TV!\n"
+#define MSGTR_LIBVO_VESA_CantInitialozeLinuxVideoOverlay "[VO_VESA] Can't initialize Linux Video Overlay.\n"
+#define MSGTR_LIBVO_VESA_UsingVideoOverlay "[VO_VESA] Using video overlay: %s.\n"
+#define MSGTR_LIBVO_VESA_CantInitializeVidixDriver "[VO_VESA] Can't initialize VIDIX driver.\n"
+#define MSGTR_LIBVO_VESA_UsingVidix "[VO_VESA] Using VIDIX.\n"
+#define MSGTR_LIBVO_VESA_CantFindModeFor "[VO_VESA] Can't find mode for: %ux%u@%u.\n"
+#define MSGTR_LIBVO_VESA_InitializationComplete "[VO_VESA] VESA initialization complete.\n"
+
+// vesa_lvo.c
+#define MSGTR_LIBVO_VESA_ThisBranchIsNoLongerSupported "[VESA_LVO] This branch is no longer supported.\n[VESA_LVO] Please use -vo vesa:vidix instead.\n"
+#define MSGTR_LIBVO_VESA_CouldntOpen "[VESA_LVO] Couldn't open: '%s'\n"
+#define MSGTR_LIBVO_VESA_InvalidOutputFormat "[VESA_LVI] Invalid output format: %s(%0X)\n"
+#define MSGTR_LIBVO_VESA_IncompatibleDriverVersion "[VESA_LVO] Your fb_vid driver version is incompatible with this MPlayer version!\n"
+
+// vo_x11.c
+#define MSGTR_LIBVO_X11_DrawFrameCalled "[VO_X11] draw_frame() called!!!!!!\n"
+
+// vo_xv.c
+#define MSGTR_LIBVO_XV_DrawFrameCalled "[VO_XV] draw_frame() called!!!!!!\n"
+#define MSGTR_LIBVO_XV_SharedMemoryNotSupported "[VO_XV] Shared memory not supported\nReverting to normal Xv.\n"
+#define MSGTR_LIBVO_XV_XvNotSupportedByX11 "[VO_XV] Sorry, Xv not supported by this X11 version/driver\n[VO_XV] ******** Try with -vo x11 or -vo sdl *********\n"
+#define MSGTR_LIBVO_XV_XvQueryAdaptorsFailed "[VO_XV] XvQueryAdaptors failed.\n"
+#define MSGTR_LIBVO_XV_InvalidPortParameter "[VO_XV] Invalid port parameter, overriding with port 0.\n"
+#define MSGTR_LIBVO_XV_CouldNotGrabPort "[VO_XV] Could not grab port %i.\n"
+#define MSGTR_LIBVO_XV_CouldNotFindFreePort "[VO_XV] Could not find free Xvideo port - maybe another process is already\n"\
+"[VO_XV] using it. Close all video applications, and try again. If that does\n"\
+"[VO_XV] not help, see 'mplayer -vo help' for other (non-xv) video out drivers.\n"
+#define MSGTR_LIBVO_XV_NoXvideoSupport "[VO_XV] It seems there is no Xvideo support for your video card available.\n"\
+"[VO_XV] Run 'xvinfo' to verify its Xv support and read\n"\
+"[VO_XV] DOCS/HTML/en/video.html#xv!\n"\
+"[VO_XV] See 'mplayer -vo help' for other (non-xv) video out drivers.\n"\
+"[VO_XV] Try -vo x11.\n"
+#define MSGTR_VO_XV_ImagedimTooHigh "Source image dimensions are too high: %ux%u (maximum is %ux%u)\n"
+
+// vo_yuv4mpeg.c
+#define MSGTR_VO_YUV4MPEG_InterlacedHeightDivisibleBy4 "Interlaced mode requires image height to be divisible by 4."
+#define MSGTR_VO_YUV4MPEG_InterlacedLineBufAllocFail "Unable to allocate line buffer for interlaced mode."
+#define MSGTR_VO_YUV4MPEG_WidthDivisibleBy2 "Image width must be divisible by 2."
+#define MSGTR_VO_YUV4MPEG_OutFileOpenError "Can't get memory or file handle to write \"%s\"!"
+#define MSGTR_VO_YUV4MPEG_OutFileWriteError "Error writing image to output!"
+#define MSGTR_VO_YUV4MPEG_UnknownSubDev "Unknown subdevice: %s"
+#define MSGTR_VO_YUV4MPEG_InterlacedTFFMode "Using interlaced output mode, top-field first."
+#define MSGTR_VO_YUV4MPEG_InterlacedBFFMode "Using interlaced output mode, bottom-field first."
+#define MSGTR_VO_YUV4MPEG_ProgressiveMode "Using (default) progressive frame mode."
+
+// vosub_vidix.c
+#define MSGTR_LIBVO_SUB_VIDIX_CantStartPlayback "[VO_SUB_VIDIX] Can't start playback: %s\n"
+#define MSGTR_LIBVO_SUB_VIDIX_CantStopPlayback "[VO_SUB_VIDIX] Can't stop playback: %s\n"
+#define MSGTR_LIBVO_SUB_VIDIX_InterleavedUvForYuv410pNotSupported "[VO_SUB_VIDIX] Interleaved UV for YUV410P not supported.\n"
+#define MSGTR_LIBVO_SUB_VIDIX_DummyVidixdrawsliceWasCalled "[VO_SUB_VIDIX] Dummy vidix_draw_slice() was called.\n"
+#define MSGTR_LIBVO_SUB_VIDIX_DummyVidixdrawframeWasCalled "[VO_SUB_VIDIX] Dummy vidix_draw_frame() was called.\n"
+#define MSGTR_LIBVO_SUB_VIDIX_UnsupportedFourccForThisVidixDriver "[VO_SUB_VIDIX] Unsupported FourCC for this VIDIX driver: %x (%s).\n"
+#define MSGTR_LIBVO_SUB_VIDIX_VideoServerHasUnsupportedResolution "[VO_SUB_VIDIX] Video server has unsupported resolution (%dx%d), supported: %dx%d-%dx%d.\n"
+#define MSGTR_LIBVO_SUB_VIDIX_VideoServerHasUnsupportedColorDepth "[VO_SUB_VIDIX] Video server has unsupported color depth by vidix (%d).\n"
+#define MSGTR_LIBVO_SUB_VIDIX_DriverCantUpscaleImage "[VO_SUB_VIDIX] VIDIX driver can't upscale image (%d%d -> %d%d).\n"
+#define MSGTR_LIBVO_SUB_VIDIX_DriverCantDownscaleImage "[VO_SUB_VIDIX] VIDIX driver can't downscale image (%d%d -> %d%d).\n"
+#define MSGTR_LIBVO_SUB_VIDIX_CantConfigurePlayback "[VO_SUB_VIDIX] Can't configure playback: %s.\n"
+#define MSGTR_LIBVO_SUB_VIDIX_YouHaveWrongVersionOfVidixLibrary "[VO_SUB_VIDIX] You have the wrong version of the VIDIX library.\n"
+#define MSGTR_LIBVO_SUB_VIDIX_CouldntFindWorkingVidixDriver "[VO_SUB_VIDIX] Couldn't find working VIDIX driver.\n"
+#define MSGTR_LIBVO_SUB_VIDIX_CouldntGetCapability "[VO_SUB_VIDIX] Couldn't get capability: %s.\n"
+
+// x11_common.c
+#define MSGTR_EwmhFullscreenStateFailed "\nX11: Couldn't send EWMH fullscreen event!\n"
+#define MSGTR_CouldNotFindXScreenSaver "xscreensaver_disable: Could not find XScreenSaver window.\n"
+#define MSGTR_SelectedVideoMode "XF86VM: Selected video mode %dx%d for image size %dx%d.\n"
+
+#define MSGTR_InsertingAfVolume "[Mixer] No hardware mixing, inserting volume filter.\n"
+#define MSGTR_NoVolume "[Mixer] No volume control available.\n"
+#define MSGTR_NoBalance "[Mixer] No balance control available.\n"
+
+// old vo drivers that have been replaced
+#define MSGTR_VO_PGM_HasBeenReplaced "The pgm video output driver has been replaced by -vo pnm:pgmyuv.\n"
+#define MSGTR_VO_MD5_HasBeenReplaced "The md5 video output driver has been replaced by -vo md5sum.\n"
+
+
+// ======================= audio output drivers ========================
+
+// audio_out.c
+#define MSGTR_AO_ALSA9_1x_Removed "audio_out: alsa9 and alsa1x modules were removed, use -ao alsa instead.\n"
+#define MSGTR_AO_TryingPreferredAudioDriver "Trying preferred audio driver '%.*s', options '%s'\n"
+#define MSGTR_AO_NoSuchDriver "No such audio driver '%.*s'\n"
+#define MSGTR_AO_FailedInit "Failed to initialize audio driver '%s'\n"
+#define MSGTR_AO_TryingEveryKnown "Trying every known audio driver...\n"
+
+// ao_oss.c
+#define MSGTR_AO_OSS_CantOpenMixer "[AO OSS] audio_setup: Can't open mixer device %s: %s\n"
+#define MSGTR_AO_OSS_ChanNotFound "[AO OSS] audio_setup: Audio card mixer does not have channel '%s', using default.\n"
+#define MSGTR_AO_OSS_CantOpenDev "[AO OSS] audio_setup: Can't open audio device %s: %s\n"
+#define MSGTR_AO_OSS_CantMakeFd "[AO OSS] audio_setup: Can't make file descriptor blocking: %s\n"
+#define MSGTR_AO_OSS_CantSet "[AO OSS] Can't set audio device %s to %s output, trying %s...\n"
+#define MSGTR_AO_OSS_CantSetChans "[AO OSS] audio_setup: Failed to set audio device to %d channels.\n"
+#define MSGTR_AO_OSS_CantUseGetospace "[AO OSS] audio_setup: driver doesn't support SNDCTL_DSP_GETOSPACE :-(\n"
+#define MSGTR_AO_OSS_CantUseSelect "[AO OSS]\n *** Your audio driver DOES NOT support select() ***\n Recompile MPlayer with #undef HAVE_AUDIO_SELECT in config.h !\n\n"
+#define MSGTR_AO_OSS_CantReopen "[AO OSS]\nFatal error: *** CANNOT RE-OPEN / RESET AUDIO DEVICE *** %s\n"
+#define MSGTR_AO_OSS_UnknownUnsupportedFormat "[AO OSS] Unknown/Unsupported OSS format: %x.\n"
+
+// ao_arts.c
+#define MSGTR_AO_ARTS_CantInit "[AO ARTS] %s\n"
+#define MSGTR_AO_ARTS_ServerConnect "[AO ARTS] Connected to sound server.\n"
+#define MSGTR_AO_ARTS_CantOpenStream "[AO ARTS] Unable to open a stream.\n"
+#define MSGTR_AO_ARTS_StreamOpen "[AO ARTS] Stream opened.\n"
+#define MSGTR_AO_ARTS_BufferSize "[AO ARTS] buffer size: %d\n"
+
+// ao_dxr2.c
+#define MSGTR_AO_DXR2_SetVolFailed "[AO DXR2] Setting volume to %d failed.\n"
+#define MSGTR_AO_DXR2_UnsupSamplerate "[AO DXR2] %d Hz not supported, try to resample.\n"
+
+// ao_esd.c
+#define MSGTR_AO_ESD_CantOpenSound "[AO ESD] esd_open_sound failed: %s\n"
+#define MSGTR_AO_ESD_LatencyInfo "[AO ESD] latency: [server: %0.2fs, net: %0.2fs] (adjust %0.2fs)\n"
+#define MSGTR_AO_ESD_CantOpenPBStream "[AO ESD] failed to open ESD playback stream: %s\n"
+
+// ao_mpegpes.c
+#define MSGTR_AO_MPEGPES_CantSetMixer "[AO MPEGPES] DVB audio set mixer failed: %s.\n"
+#define MSGTR_AO_MPEGPES_UnsupSamplerate "[AO MPEGPES] %d Hz not supported, try to resample.\n"
+
+// ao_pcm.c
+#define MSGTR_AO_PCM_FileInfo "[AO PCM] File: %s (%s)\nPCM: Samplerate: %iHz Channels: %s Format %s\n"
+#define MSGTR_AO_PCM_HintInfo "[AO PCM] Info: Faster dumping is achieved with -vc null -vo null -ao pcm:fast\n[AO PCM] Info: To write WAVE files use -ao pcm:waveheader (default).\n"
+#define MSGTR_AO_PCM_CantOpenOutputFile "[AO PCM] Failed to open %s for writing!\n"
+
+// ao_sdl.c
+#define MSGTR_AO_SDL_INFO "[AO SDL] Samplerate: %iHz Channels: %s Format %s\n"
+#define MSGTR_AO_SDL_DriverInfo "[AO SDL] using %s audio driver.\n"
+#define MSGTR_AO_SDL_UnsupportedAudioFmt "[AO SDL] Unsupported audio format: 0x%x.\n"
+#define MSGTR_AO_SDL_CantInit "[AO SDL] SDL Audio initialization failed: %s\n"
+#define MSGTR_AO_SDL_CantOpenAudio "[AO SDL] Unable to open audio: %s\n"
+
+// ao_sgi.c
+#define MSGTR_AO_SGI_INFO "[AO SGI] control.\n"
+#define MSGTR_AO_SGI_InitInfo "[AO SGI] init: Samplerate: %iHz Channels: %s Format %s\n"
+#define MSGTR_AO_SGI_InvalidDevice "[AO SGI] play: invalid device.\n"
+#define MSGTR_AO_SGI_CantSetParms_Samplerate "[AO SGI] init: setparams failed: %s\nCould not set desired samplerate.\n"
+#define MSGTR_AO_SGI_CantSetAlRate "[AO SGI] init: AL_RATE was not accepted on the given resource.\n"
+#define MSGTR_AO_SGI_CantGetParms "[AO SGI] init: getparams failed: %s\n"
+#define MSGTR_AO_SGI_SampleRateInfo "[AO SGI] init: samplerate is now %lf (desired rate is %lf)\n"
+#define MSGTR_AO_SGI_InitConfigError "[AO SGI] init: %s\n"
+#define MSGTR_AO_SGI_InitOpenAudioFailed "[AO SGI] init: Unable to open audio channel: %s\n"
+#define MSGTR_AO_SGI_Uninit "[AO SGI] uninit: ...\n"
+#define MSGTR_AO_SGI_Reset "[AO SGI] reset: ...\n"
+#define MSGTR_AO_SGI_PauseInfo "[AO SGI] audio_pause: ...\n"
+#define MSGTR_AO_SGI_ResumeInfo "[AO SGI] audio_resume: ...\n"
+
+// ao_sun.c
+#define MSGTR_AO_SUN_RtscSetinfoFailed "[AO SUN] rtsc: SETINFO failed.\n"
+#define MSGTR_AO_SUN_RtscWriteFailed "[AO SUN] rtsc: write failed.\n"
+#define MSGTR_AO_SUN_CantOpenAudioDev "[AO SUN] Can't open audio device %s, %s -> nosound.\n"
+#define MSGTR_AO_SUN_UnsupSampleRate "[AO SUN] audio_setup: your card doesn't support %d channel, %s, %d Hz samplerate.\n"
+#define MSGTR_AO_SUN_CantUseSelect "[AO SUN]\n *** Your audio driver DOES NOT support select() ***\nRecompile MPlayer with #undef HAVE_AUDIO_SELECT in config.h !\n\n"
+#define MSGTR_AO_SUN_CantReopenReset "[AO SUN]\nFatal error: *** CANNOT REOPEN / RESET AUDIO DEVICE (%s) ***\n"
+
+// ao_alsa5.c
+#define MSGTR_AO_ALSA5_InitInfo "[AO ALSA5] alsa-init: requested format: %d Hz, %d channels, %s\n"
+#define MSGTR_AO_ALSA5_SoundCardNotFound "[AO ALSA5] alsa-init: no soundcards found.\n"
+#define MSGTR_AO_ALSA5_InvalidFormatReq "[AO ALSA5] alsa-init: invalid format (%s) requested - output disabled.\n"
+#define MSGTR_AO_ALSA5_PlayBackError "[AO ALSA5] alsa-init: playback open error: %s\n"
+#define MSGTR_AO_ALSA5_PcmInfoError "[AO ALSA5] alsa-init: PCM info error: %s\n"
+#define MSGTR_AO_ALSA5_SoundcardsFound "[AO ALSA5] alsa-init: %d soundcard(s) found, using: %s\n"
+#define MSGTR_AO_ALSA5_PcmChanInfoError "[AO ALSA5] alsa-init: PCM channel info error: %s\n"
+#define MSGTR_AO_ALSA5_CantSetParms "[AO ALSA5] alsa-init: error setting parameters: %s\n"
+#define MSGTR_AO_ALSA5_CantSetChan "[AO ALSA5] alsa-init: error setting up channel: %s\n"
+#define MSGTR_AO_ALSA5_ChanPrepareError "[AO ALSA5] alsa-init: channel prepare error: %s\n"
+#define MSGTR_AO_ALSA5_DrainError "[AO ALSA5] alsa-uninit: playback drain error: %s\n"
+#define MSGTR_AO_ALSA5_FlushError "[AO ALSA5] alsa-uninit: playback flush error: %s\n"
+#define MSGTR_AO_ALSA5_PcmCloseError "[AO ALSA5] alsa-uninit: PCM close error: %s\n"
+#define MSGTR_AO_ALSA5_ResetDrainError "[AO ALSA5] alsa-reset: playback drain error: %s\n"
+#define MSGTR_AO_ALSA5_ResetFlushError "[AO ALSA5] alsa-reset: playback flush error: %s\n"
+#define MSGTR_AO_ALSA5_ResetChanPrepareError "[AO ALSA5] alsa-reset: channel prepare error: %s\n"
+#define MSGTR_AO_ALSA5_PauseDrainError "[AO ALSA5] alsa-pause: playback drain error: %s\n"
+#define MSGTR_AO_ALSA5_PauseFlushError "[AO ALSA5] alsa-pause: playback flush error: %s\n"
+#define MSGTR_AO_ALSA5_ResumePrepareError "[AO ALSA5] alsa-resume: channel prepare error: %s\n"
+#define MSGTR_AO_ALSA5_Underrun "[AO ALSA5] alsa-play: alsa underrun, resetting stream.\n"
+#define MSGTR_AO_ALSA5_PlaybackPrepareError "[AO ALSA5] alsa-play: playback prepare error: %s\n"
+#define MSGTR_AO_ALSA5_WriteErrorAfterReset "[AO ALSA5] alsa-play: write error after reset: %s - giving up.\n"
+#define MSGTR_AO_ALSA5_OutPutError "[AO ALSA5] alsa-play: output error: %s\n"
+
+// ao_alsa.c
+#define MSGTR_AO_ALSA_InvalidMixerIndexDefaultingToZero "[AO_ALSA] Invalid mixer index. Defaulting to 0.\n"
+#define MSGTR_AO_ALSA_MixerOpenError "[AO_ALSA] Mixer open error: %s\n"
+#define MSGTR_AO_ALSA_MixerAttachError "[AO_ALSA] Mixer attach %s error: %s\n"
+#define MSGTR_AO_ALSA_MixerRegisterError "[AO_ALSA] Mixer register error: %s\n"
+#define MSGTR_AO_ALSA_MixerLoadError "[AO_ALSA] Mixer load error: %s\n"
+#define MSGTR_AO_ALSA_UnableToFindSimpleControl "[AO_ALSA] Unable to find simple control '%s',%i.\n"
+#define MSGTR_AO_ALSA_ErrorSettingLeftChannel "[AO_ALSA] Error setting left channel, %s\n"
+#define MSGTR_AO_ALSA_ErrorSettingRightChannel "[AO_ALSA] Error setting right channel, %s\n"
+#define MSGTR_AO_ALSA_CommandlineHelp "\n[AO_ALSA] -ao alsa commandline help:\n"\
+"[AO_ALSA] Example: mplayer -ao alsa:device=hw=0.3\n"\
+"[AO_ALSA] Sets first card fourth hardware device.\n\n"\
+"[AO_ALSA] Options:\n"\
+"[AO_ALSA] noblock\n"\
+"[AO_ALSA] Opens device in non-blocking mode.\n"\
+"[AO_ALSA] device=<device-name>\n"\
+"[AO_ALSA] Sets device (change , to . and : to =)\n"
+#define MSGTR_AO_ALSA_ChannelsNotSupported "[AO_ALSA] %d channels are not supported.\n"
+#define MSGTR_AO_ALSA_OpenInNonblockModeFailed "[AO_ALSA] Open in nonblock-mode failed, trying to open in block-mode.\n"
+#define MSGTR_AO_ALSA_PlaybackOpenError "[AO_ALSA] Playback open error: %s\n"
+#define MSGTR_AO_ALSA_ErrorSetBlockMode "[AL_ALSA] Error setting block-mode %s.\n"
+#define MSGTR_AO_ALSA_UnableToGetInitialParameters "[AO_ALSA] Unable to get initial parameters: %s\n"
+#define MSGTR_AO_ALSA_UnableToSetAccessType "[AO_ALSA] Unable to set access type: %s\n"
+#define MSGTR_AO_ALSA_FormatNotSupportedByHardware "[AO_ALSA] Format %s is not supported by hardware, trying default.\n"
+#define MSGTR_AO_ALSA_UnableToSetFormat "[AO_ALSA] Unable to set format: %s\n"
+#define MSGTR_AO_ALSA_UnableToSetChannels "[AO_ALSA] Unable to set channels: %s\n"
+#define MSGTR_AO_ALSA_UnableToDisableResampling "[AO_ALSA] Unable to disable resampling: %s\n"
+#define MSGTR_AO_ALSA_UnableToSetSamplerate2 "[AO_ALSA] Unable to set samplerate-2: %s\n"
+#define MSGTR_AO_ALSA_UnableToSetBufferTimeNear "[AO_ALSA] Unable to set buffer time near: %s\n"
+#define MSGTR_AO_ALSA_UnableToGetPeriodSize "[AO ALSA] Unable to get period size: %s\n"
+#define MSGTR_AO_ALSA_UnableToSetPeriods "[AO_ALSA] Unable to set periods: %s\n"
+#define MSGTR_AO_ALSA_UnableToSetHwParameters "[AO_ALSA] Unable to set hw-parameters: %s\n"
+#define MSGTR_AO_ALSA_UnableToGetBufferSize "[AO_ALSA] Unable to get buffersize: %s\n"
+#define MSGTR_AO_ALSA_UnableToGetSwParameters "[AO_ALSA] Unable to get sw-parameters: %s\n"
+#define MSGTR_AO_ALSA_UnableToSetSwParameters "[AO_ALSA] Unable to set sw-parameters: %s\n"
+#define MSGTR_AO_ALSA_UnableToGetBoundary "[AO_ALSA] Unable to get boundary: %s\n"
+#define MSGTR_AO_ALSA_UnableToSetStartThreshold "[AO_ALSA] Unable to set start threshold: %s\n"
+#define MSGTR_AO_ALSA_UnableToSetStopThreshold "[AO_ALSA] Unable to set stop threshold: %s\n"
+#define MSGTR_AO_ALSA_UnableToSetSilenceSize "[AO_ALSA] Unable to set silence size: %s\n"
+#define MSGTR_AO_ALSA_PcmCloseError "[AO_ALSA] pcm close error: %s\n"
+#define MSGTR_AO_ALSA_NoHandlerDefined "[AO_ALSA] No handler defined!\n"
+#define MSGTR_AO_ALSA_PcmPrepareError "[AO_ALSA] pcm prepare error: %s\n"
+#define MSGTR_AO_ALSA_PcmPauseError "[AO_ALSA] pcm pause error: %s\n"
+#define MSGTR_AO_ALSA_PcmDropError "[AO_ALSA] pcm drop error: %s\n"
+#define MSGTR_AO_ALSA_PcmResumeError "[AO_ALSA] pcm resume error: %s\n"
+#define MSGTR_AO_ALSA_DeviceConfigurationError "[AO_ALSA] Device configuration error."
+#define MSGTR_AO_ALSA_PcmInSuspendModeTryingResume "[AO_ALSA] Pcm in suspend mode, trying to resume.\n"
+#define MSGTR_AO_ALSA_WriteError "[AO_ALSA] Write error: %s\n"
+#define MSGTR_AO_ALSA_TryingToResetSoundcard "[AO_ALSA] Trying to reset soundcard.\n"
+#define MSGTR_AO_ALSA_CannotGetPcmStatus "[AO_ALSA] Cannot get pcm status: %s\n"
+
+// ao_plugin.c
+#define MSGTR_AO_PLUGIN_InvalidPlugin "[AO PLUGIN] invalid plugin: %s\n"
+
+
+// ======================= audio filters ================================
+
+// af_scaletempo.c
+#define MSGTR_AF_ValueOutOfRange MSGTR_VO_ValueOutOfRange
+
+// af_ladspa.c
+#define MSGTR_AF_LADSPA_AvailableLabels "available labels in"
+#define MSGTR_AF_LADSPA_WarnNoInputs "WARNING! This LADSPA plugin has no audio inputs.\n The incoming audio signal will be lost."
+#define MSGTR_AF_LADSPA_ErrMultiChannel "Multi-channel (>2) plugins are not supported (yet).\n Use only mono and stereo plugins."
+#define MSGTR_AF_LADSPA_ErrNoOutputs "This LADSPA plugin has no audio outputs."
+#define MSGTR_AF_LADSPA_ErrInOutDiff "The number of audio inputs and audio outputs of the LADSPA plugin differ."
+#define MSGTR_AF_LADSPA_ErrFailedToLoad "failed to load"
+#define MSGTR_AF_LADSPA_ErrNoDescriptor "Couldn't find ladspa_descriptor() function in the specified library file."
+#define MSGTR_AF_LADSPA_ErrLabelNotFound "Couldn't find label in plugin library."
+#define MSGTR_AF_LADSPA_ErrNoSuboptions "No suboptions specified."
+#define MSGTR_AF_LADSPA_ErrNoLibFile "No library file specified."
+#define MSGTR_AF_LADSPA_ErrNoLabel "No filter label specified."
+#define MSGTR_AF_LADSPA_ErrNotEnoughControls "Not enough controls specified on the command line."
+#define MSGTR_AF_LADSPA_ErrControlBelow "%s: Input control #%d is below lower boundary of %0.4f.\n"
+#define MSGTR_AF_LADSPA_ErrControlAbove "%s: Input control #%d is above upper boundary of %0.4f.\n"
+
+// format.c
+#define MSGTR_AF_FORMAT_UnknownFormat "unknown format "
+
+
+// ========================== INPUT =========================================
+
+// joystick.c
+#define MSGTR_INPUT_JOYSTICK_Opening "Opening joystick device %s\n"
+#define MSGTR_INPUT_JOYSTICK_CantOpen "Can't open joystick device %s: %s\n"
+#define MSGTR_INPUT_JOYSTICK_ErrReading "Error while reading joystick device: %s\n"
+#define MSGTR_INPUT_JOYSTICK_LoosingBytes "Joystick: We lose %d bytes of data\n"
+#define MSGTR_INPUT_JOYSTICK_WarnLostSync "Joystick: warning init event, we have lost sync with driver.\n"
+#define MSGTR_INPUT_JOYSTICK_WarnUnknownEvent "Joystick warning unknown event type %d\n"
+
+// appleir.c
+#define MSGTR_INPUT_APPLE_IR_Init "Initializing Apple IR on %s\n"
+#define MSGTR_INPUT_APPLE_IR_Detect "Detected Apple IR on %s\n"
+#define MSGTR_INPUT_APPLE_IR_CantOpen "Can't open Apple IR device: %s\n"
+
+// input.c
+#define MSGTR_INPUT_INPUT_ErrCantRegister2ManyCmdFds "Too many command file descriptors, cannot register file descriptor %d.\n"
+#define MSGTR_INPUT_INPUT_ErrCantRegister2ManyKeyFds "Too many key file descriptors, cannot register file descriptor %d.\n"
+#define MSGTR_INPUT_INPUT_ErrArgMustBeInt "Command %s: argument %d isn't an integer.\n"
+#define MSGTR_INPUT_INPUT_ErrArgMustBeFloat "Command %s: argument %d isn't a float.\n"
+#define MSGTR_INPUT_INPUT_ErrUnterminatedArg "Command %s: argument %d is unterminated.\n"
+#define MSGTR_INPUT_INPUT_ErrUnknownArg "Unknown argument %d\n"
+#define MSGTR_INPUT_INPUT_Err2FewArgs "Command %s requires at least %d arguments, we found only %d so far.\n"
+#define MSGTR_INPUT_INPUT_ErrReadingCmdFd "Error while reading command file descriptor %d: %s\n"
+#define MSGTR_INPUT_INPUT_ErrCmdBufferFullDroppingContent "Command buffer of file descriptor %d is full: dropping content.\n"
+#define MSGTR_INPUT_INPUT_ErrInvalidCommandForKey "Invalid command for bound key %s"
+#define MSGTR_INPUT_INPUT_ErrSelect "Select error: %s\n"
+#define MSGTR_INPUT_INPUT_ErrOnKeyInFd "Error on key input file descriptor %d\n"
+#define MSGTR_INPUT_INPUT_ErrDeadKeyOnFd "Dead key input on file descriptor %d\n"
+#define MSGTR_INPUT_INPUT_Err2ManyKeyDowns "Too many key down events at the same time\n"
+#define MSGTR_INPUT_INPUT_ErrOnCmdFd "Error on command file descriptor %d\n"
+#define MSGTR_INPUT_INPUT_ErrReadingInputConfig "Error while reading input config file %s: %s\n"
+#define MSGTR_INPUT_INPUT_ErrUnknownKey "Unknown key '%s'\n"
+#define MSGTR_INPUT_INPUT_ErrUnfinishedBinding "Unfinished binding %s\n"
+#define MSGTR_INPUT_INPUT_ErrBuffer2SmallForKeyName "Buffer is too small for this key name: %s\n"
+#define MSGTR_INPUT_INPUT_ErrNoCmdForKey "No command found for key %s"
+#define MSGTR_INPUT_INPUT_ErrBuffer2SmallForCmd "Buffer is too small for command %s\n"
+#define MSGTR_INPUT_INPUT_ErrWhyHere "What are we doing here?\n"
+#define MSGTR_INPUT_INPUT_ErrCantInitJoystick "Can't init input joystick\n"
+#define MSGTR_INPUT_INPUT_ErrCantStatFile "Can't stat %s: %s\n"
+#define MSGTR_INPUT_INPUT_ErrCantOpenFile "Can't open %s: %s\n"
+#define MSGTR_INPUT_INPUT_ErrCantInitAppleRemote "Can't init Apple Remote.\n"
+
+// lirc.c
+#define MSGTR_SettingUpLIRC "Setting up LIRC support...\n"
+#define MSGTR_LIRCopenfailed "Failed to open LIRC support. You will not be able to use your remote control.\n"
+#define MSGTR_LIRCcfgerr "Failed to read LIRC config file %s.\n"
+
+
+// ========================== LIBMPDEMUX ===================================
+
+// muxer.c, muxer_*.c
+#define MSGTR_TooManyStreams "Too many streams!"
+#define MSGTR_RawMuxerOnlyOneStream "Rawaudio muxer supports only one audio stream!\n"
+#define MSGTR_IgnoringVideoStream "Ignoring video stream!\n"
+#define MSGTR_UnknownStreamType "Warning, unknown stream type: %d\n"
+#define MSGTR_WarningLenIsntDivisible "Warning, len isn't divisible by samplesize!\n"
+#define MSGTR_MuxbufMallocErr "Muxer frame buffer cannot allocate memory!\n"
+#define MSGTR_MuxbufReallocErr "Muxer frame buffer cannot reallocate memory!\n"
+#define MSGTR_MuxbufSending "Muxer frame buffer sending %d frame(s) to the muxer.\n"
+#define MSGTR_WritingHeader "Writing header...\n"
+#define MSGTR_WritingTrailer "Writing index...\n"
+
+// demuxer.c, demux_*.c
+#define MSGTR_AudioStreamRedefined "WARNING: Audio stream header %d redefined.\n"
+#define MSGTR_VideoStreamRedefined "WARNING: Video stream header %d redefined.\n"
+#define MSGTR_TooManyAudioInBuffer "\nToo many audio packets in the buffer: (%d in %d bytes).\n"
+#define MSGTR_TooManyVideoInBuffer "\nToo many video packets in the buffer: (%d in %d bytes).\n"
+#define MSGTR_MaybeNI "Maybe you are playing a non-interleaved stream/file or the codec failed?\n" \
+ "For AVI files, try to force non-interleaved mode with the -ni option.\n"
+#define MSGTR_WorkAroundBlockAlignHeaderBug "AVI: Working around CBR-MP3 nBlockAlign header bug!\n"
+#define MSGTR_SwitchToNi "\nBadly interleaved AVI file detected - switching to -ni mode...\n"
+#define MSGTR_InvalidAudioStreamNosound "AVI: invalid audio stream ID: %d - ignoring (nosound)\n"
+#define MSGTR_InvalidAudioStreamUsingDefault "AVI: invalid video stream ID: %d - ignoring (using default)\n"
+#define MSGTR_ON2AviFormat "ON2 AVI format"
+#define MSGTR_Detected_XXX_FileFormat "%s file format detected.\n"
+#define MSGTR_DetectedAudiofile "Audio file detected.\n"
+#define MSGTR_NotSystemStream "Not MPEG System Stream format... (maybe Transport Stream?)\n"
+#define MSGTR_InvalidMPEGES "Invalid MPEG-ES stream??? Contact the author, it may be a bug :(\n"
+#define MSGTR_FormatNotRecognized "============ Sorry, this file format is not recognized/supported =============\n"\
+ "=== If this file is an AVI, ASF or MPEG stream, please contact the author! ===\n"
+#define MSGTR_SettingProcessPriority "Setting process priority: %s\n"
+#define MSGTR_FilefmtFourccSizeFpsFtime "[V] filefmt:%d fourcc:0x%X size:%dx%d fps:%5.3f ftime:=%6.4f\n"
+#define MSGTR_CannotInitializeMuxer "Cannot initialize muxer."
+#define MSGTR_MissingVideoStream "No video stream found.\n"
+#define MSGTR_MissingAudioStream "No audio stream found -> no sound.\n"
+#define MSGTR_MissingVideoStreamBug "Missing video stream!? Contact the author, it may be a bug :(\n"
+
+#define MSGTR_DoesntContainSelectedStream "demux: File doesn't contain the selected audio or video stream.\n"
+
+#define MSGTR_NI_Forced "Forced"
+#define MSGTR_NI_Detected "Detected"
+#define MSGTR_NI_Message "%s NON-INTERLEAVED AVI file format.\n"
+
+#define MSGTR_UsingNINI "Using NON-INTERLEAVED broken AVI file format.\n"
+#define MSGTR_CouldntDetFNo "Could not determine number of frames (for absolute seek).\n"
+#define MSGTR_CantSeekRawAVI "Cannot seek in raw AVI streams. (Index required, try with the -idx switch.)\n"
+#define MSGTR_CantSeekFile "Cannot seek in this file.\n"
+
+#define MSGTR_MOVcomprhdr "MOV: Compressed headers support requires ZLIB!\n"
+#define MSGTR_MOVvariableFourCC "MOV: WARNING: Variable FourCC detected!?\n"
+#define MSGTR_MOVtooManyTrk "MOV: WARNING: too many tracks"
+#define MSGTR_FoundAudioStream "==> Found audio stream: %d\n"
+#define MSGTR_FoundVideoStream "==> Found video stream: %d\n"
+#define MSGTR_DetectedTV "TV detected! ;-)\n"
+#define MSGTR_ErrorOpeningOGGDemuxer "Unable to open the Ogg demuxer.\n"
+#define MSGTR_ASFSearchingForAudioStream "ASF: Searching for audio stream (id:%d).\n"
+#define MSGTR_CannotOpenAudioStream "Cannot open audio stream: %s\n"
+#define MSGTR_CannotOpenSubtitlesStream "Cannot open subtitle stream: %s\n"
+#define MSGTR_OpeningAudioDemuxerFailed "Failed to open audio demuxer: %s\n"
+#define MSGTR_OpeningSubtitlesDemuxerFailed "Failed to open subtitle demuxer: %s\n"
+#define MSGTR_TVInputNotSeekable "TV input is not seekable! (Seeking will probably be for changing channels ;)\n"
+#define MSGTR_DemuxerInfoChanged "Demuxer info %s changed to %s\n"
+#define MSGTR_ClipInfo "Clip info:\n"
+
+#define MSGTR_LeaveTelecineMode "\ndemux_mpg: 30000/1001fps NTSC content detected, switching framerate.\n"
+#define MSGTR_EnterTelecineMode "\ndemux_mpg: 24000/1001fps progressive NTSC content detected, switching framerate.\n"
+
+#define MSGTR_CacheFill "\rCache fill: %5.2f%% (%"PRId64" bytes) "
+#define MSGTR_NoBindFound "No bind found for key '%s'."
+#define MSGTR_FailedToOpen "Failed to open %s.\n"
+
+#define MSGTR_VideoID "[%s] Video stream found, -vid %d\n"
+#define MSGTR_AudioID "[%s] Audio stream found, -aid %d\n"
+#define MSGTR_SubtitleID "[%s] Subtitle stream found, -sid %d\n"
+
+// asfheader.c
+#define MSGTR_MPDEMUX_ASFHDR_HeaderSizeOver1MB "FATAL: header size bigger than 1 MB (%d)!\nPlease contact MPlayer authors, and upload/send this file.\n"
+#define MSGTR_MPDEMUX_ASFHDR_HeaderMallocFailed "Could not allocate %d bytes for header.\n"
+#define MSGTR_MPDEMUX_ASFHDR_EOFWhileReadingHeader "EOF while reading ASF header, broken/incomplete file?\n"
+#define MSGTR_MPDEMUX_ASFHDR_DVRWantsLibavformat "DVR will probably only work with libavformat, try -demuxer 35 if you have problems\n"
+#define MSGTR_MPDEMUX_ASFHDR_NoDataChunkAfterHeader "No data chunk following header!\n"
+#define MSGTR_MPDEMUX_ASFHDR_AudioVideoHeaderNotFound "ASF: no audio or video headers found - broken file?\n"
+#define MSGTR_MPDEMUX_ASFHDR_InvalidLengthInASFHeader "Invalid length in ASF header!\n"
+#define MSGTR_MPDEMUX_ASFHDR_DRMLicenseURL "DRM License URL: %s\n"
+#define MSGTR_MPDEMUX_ASFHDR_DRMProtected "This file has been encumbered with DRM encryption, it will not play in MPlayer!\n"
+
+// aviheader.c
+#define MSGTR_MPDEMUX_AVIHDR_EmptyList "** empty list?!\n"
+#define MSGTR_MPDEMUX_AVIHDR_FoundMovieAt "Found movie at 0x%X - 0x%X\n"
+#define MSGTR_MPDEMUX_AVIHDR_FoundBitmapInfoHeader "Found 'bih', %u bytes of %d\n"
+#define MSGTR_MPDEMUX_AVIHDR_RegeneratingKeyfTableForMPG4V1 "Regenerating keyframe table for M$ mpg4v1 video.\n"
+#define MSGTR_MPDEMUX_AVIHDR_RegeneratingKeyfTableForDIVX3 "Regenerating keyframe table for DIVX3 video.\n"
+#define MSGTR_MPDEMUX_AVIHDR_RegeneratingKeyfTableForMPEG4 "Regenerating keyframe table for MPEG-4 video.\n"
+#define MSGTR_MPDEMUX_AVIHDR_FoundWaveFmt "Found 'wf', %d bytes of %d\n"
+#define MSGTR_MPDEMUX_AVIHDR_FoundAVIV2Header "AVI: dmlh found (size=%d) (total_frames=%d)\n"
+#define MSGTR_MPDEMUX_AVIHDR_ReadingIndexBlockChunksForFrames "Reading INDEX block, %d chunks for %d frames (fpos=%"PRId64").\n"
+#define MSGTR_MPDEMUX_AVIHDR_AdditionalRIFFHdr "Additional RIFF header...\n"
+#define MSGTR_MPDEMUX_AVIHDR_WarnNotExtendedAVIHdr "** Warning: this is no extended AVI header..\n"
+#define MSGTR_MPDEMUX_AVIHDR_BrokenChunk "Broken chunk? chunksize=%d (id=%.4s)\n"
+#define MSGTR_MPDEMUX_AVIHDR_BuildingODMLidx "AVI: ODML: Building ODML index (%d superindexchunks).\n"
+#define MSGTR_MPDEMUX_AVIHDR_BrokenODMLfile "AVI: ODML: Broken (incomplete?) file detected. Will use traditional index.\n"
+#define MSGTR_MPDEMUX_AVIHDR_CantReadIdxFile "Can't read index file %s: %s\n"
+#define MSGTR_MPDEMUX_AVIHDR_NotValidMPidxFile "%s is not a valid MPlayer index file.\n"
+#define MSGTR_MPDEMUX_AVIHDR_FailedMallocForIdxFile "Could not allocate memory for index data from %s.\n"
+#define MSGTR_MPDEMUX_AVIHDR_PrematureEOF "premature end of index file %s\n"
+#define MSGTR_MPDEMUX_AVIHDR_IdxFileLoaded "Loaded index file: %s\n"
+#define MSGTR_MPDEMUX_AVIHDR_GeneratingIdx "Generating Index: %3lu %s \r"
+#define MSGTR_MPDEMUX_AVIHDR_IdxGeneratedForHowManyChunks "AVI: Generated index table for %d chunks!\n"
+#define MSGTR_MPDEMUX_AVIHDR_Failed2WriteIdxFile "Couldn't write index file %s: %s\n"
+#define MSGTR_MPDEMUX_AVIHDR_IdxFileSaved "Saved index file: %s\n"
+
+// demux_audio.c
+#define MSGTR_MPDEMUX_AUDIO_UnknownFormat "Audio demuxer: unknown format %d.\n"
+
+// demux_demuxers.c
+#define MSGTR_MPDEMUX_DEMUXERS_FillBufferError "fill_buffer error: bad demuxer: not vd, ad or sd.\n"
+
+// demux_mkv.c
+#define MSGTR_MPDEMUX_MKV_ZlibInitializationFailed "[mkv] zlib initialization failed.\n"
+#define MSGTR_MPDEMUX_MKV_ZlibDecompressionFailed "[mkv] zlib decompression failed.\n"
+#define MSGTR_MPDEMUX_MKV_LzoInitializationFailed "[mkv] lzo initialization failed.\n"
+#define MSGTR_MPDEMUX_MKV_LzoDecompressionFailed "[mkv] lzo decompression failed.\n"
+#define MSGTR_MPDEMUX_MKV_TrackEncrypted "[mkv] Track number %u has been encrypted and decryption has not yet been\n[mkv] implemented. Skipping track.\n"
+#define MSGTR_MPDEMUX_MKV_UnknownContentEncoding "[mkv] Unknown content encoding type for track %u. Skipping track.\n"
+#define MSGTR_MPDEMUX_MKV_UnknownCompression "[mkv] Track %u has been compressed with an unknown/unsupported compression\n[mkv] algorithm (%u). Skipping track.\n"
+#define MSGTR_MPDEMUX_MKV_ZlibCompressionUnsupported "[mkv] Track %u was compressed with zlib but mplayer has not been compiled\n[mkv] with support for zlib compression. Skipping track.\n"
+#define MSGTR_MPDEMUX_MKV_TrackIDName "[mkv] Track ID %u: %s (%s) \"%s\", %s\n"
+#define MSGTR_MPDEMUX_MKV_TrackID "[mkv] Track ID %u: %s (%s), %s\n"
+#define MSGTR_MPDEMUX_MKV_UnknownCodecID "[mkv] Unknown/unsupported CodecID (%s) or missing/bad CodecPrivate\n[mkv] data (track %u).\n"
+#define MSGTR_MPDEMUX_MKV_FlacTrackDoesNotContainValidHeaders "[mkv] FLAC track does not contain valid headers.\n"
+#define MSGTR_MPDEMUX_MKV_UnknownAudioCodec "[mkv] Unknown/unsupported audio codec ID '%s' for track %u or missing/faulty\n[mkv] private codec data.\n"
+#define MSGTR_MPDEMUX_MKV_SubtitleTypeNotSupported "[mkv] Subtitle type '%s' is not supported.\n"
+#define MSGTR_MPDEMUX_MKV_WillPlayVideoTrack "[mkv] Will play video track %u.\n"
+#define MSGTR_MPDEMUX_MKV_NoVideoTrackFound "[mkv] No video track found/wanted.\n"
+#define MSGTR_MPDEMUX_MKV_NoAudioTrackFound "[mkv] No audio track found/wanted.\n"
+#define MSGTR_MPDEMUX_MKV_WillDisplaySubtitleTrack "[mkv] Will display subtitle track %u.\n"
+#define MSGTR_MPDEMUX_MKV_NoBlockDurationForSubtitleTrackFound "[mkv] Warning: No BlockDuration for subtitle track found.\n"
+#define MSGTR_MPDEMUX_MKV_TooManySublines "[mkv] Warning: too many sublines to render, skipping.\n"
+#define MSGTR_MPDEMUX_MKV_TooManySublinesSkippingAfterFirst "\n[mkv] Warning: too many sublines to render, skipping after first %i.\n"
+
+// demux_nuv.c
+#define MSGTR_MPDEMUX_NUV_NoVideoBlocksInFile "No video blocks in file.\n"
+
+// demux_xmms.c
+#define MSGTR_MPDEMUX_XMMS_FoundPlugin "Found plugin: %s (%s).\n"
+#define MSGTR_MPDEMUX_XMMS_ClosingPlugin "Closing plugin: %s.\n"
+#define MSGTR_MPDEMUX_XMMS_WaitForStart "Waiting for the XMMS plugin to start playback of '%s'...\n"
+
+
+// ========================== LIBMENU ===================================
+
+// common
+#define MSGTR_LIBMENU_NoEntryFoundInTheMenuDefinition "[MENU] No entry found in the menu definition.\n"
+
+// libmenu/menu.c
+#define MSGTR_LIBMENU_SyntaxErrorAtLine "[MENU] syntax error at line: %d\n"
+#define MSGTR_LIBMENU_MenuDefinitionsNeedANameAttrib "[MENU] Menu definitions need a name attribute (line %d).\n"
+#define MSGTR_LIBMENU_BadAttrib "[MENU] bad attribute %s=%s in menu '%s' at line %d\n"
+#define MSGTR_LIBMENU_UnknownMenuType "[MENU] unknown menu type '%s' at line %d\n"
+#define MSGTR_LIBMENU_CantOpenConfigFile "[MENU] Can't open menu config file: %s\n"
+#define MSGTR_LIBMENU_ConfigFileIsTooBig "[MENU] Config file is too big (> %d KB)\n"
+#define MSGTR_LIBMENU_ConfigFileIsEmpty "[MENU] Config file is empty.\n"
+#define MSGTR_LIBMENU_MenuNotFound "[MENU] Menu %s not found.\n"
+#define MSGTR_LIBMENU_MenuInitFailed "[MENU] Menu '%s': Init failed.\n"
+#define MSGTR_LIBMENU_UnsupportedOutformat "[MENU] Unsupported output format!!!!\n"
+
+// libmenu/menu_cmdlist.c
+#define MSGTR_LIBMENU_ListMenuEntryDefinitionsNeedAName "[MENU] List menu entry definitions need a name (line %d).\n"
+#define MSGTR_LIBMENU_ListMenuNeedsAnArgument "[MENU] List menu needs an argument.\n"
+
+// libmenu/menu_console.c
+#define MSGTR_LIBMENU_WaitPidError "[MENU] Waitpid error: %s.\n"
+#define MSGTR_LIBMENU_SelectError "[MENU] Select error.\n"
+#define MSGTR_LIBMENU_ReadErrorOnChildFD "[MENU] Read error on child's file descriptor: %s.\n"
+#define MSGTR_LIBMENU_ConsoleRun "[MENU] Console run: %s ...\n"
+#define MSGTR_LIBMENU_AChildIsAlreadyRunning "[MENU] A child is already running.\n"
+#define MSGTR_LIBMENU_ForkFailed "[MENU] Fork failed !!!\n"
+#define MSGTR_LIBMENU_WriteError "[MENU] write error\n"
+
+// libmenu/menu_filesel.c
+#define MSGTR_LIBMENU_OpendirError "[MENU] opendir error: %s\n"
+#define MSGTR_LIBMENU_ReallocError "[MENU] realloc error: %s\n"
+#define MSGTR_LIBMENU_MallocError "[MENU] memory allocation error: %s\n"
+#define MSGTR_LIBMENU_ReaddirError "[MENU] readdir error: %s\n"
+#define MSGTR_LIBMENU_CantOpenDirectory "[MENU] Can't open directory %s.\n"
+
+// libmenu/menu_param.c
+#define MSGTR_LIBMENU_SubmenuDefinitionNeedAMenuAttribut "[MENU] Submenu definition needs a 'menu' attribute.\n"
+#define MSGTR_LIBMENU_InvalidProperty "[MENU] Invalid property '%s' in pref menu entry. (line %d).\n"
+#define MSGTR_LIBMENU_PrefMenuEntryDefinitionsNeed "[MENU] Pref menu entry definitions need a valid 'property' or 'txt' attribute (line %d).\n"
+#define MSGTR_LIBMENU_PrefMenuNeedsAnArgument "[MENU] Pref menu needs an argument.\n"
+
+// libmenu/menu_pt.c
+#define MSGTR_LIBMENU_CantfindTheTargetItem "[MENU] Can't find the target item ????\n"
+#define MSGTR_LIBMENU_FailedToBuildCommand "[MENU] Failed to build command: %s.\n"
+
+// libmenu/menu_txt.c
+#define MSGTR_LIBMENU_MenuTxtNeedATxtFileName "[MENU] Text menu needs a textfile name (parameter file).\n"
+#define MSGTR_LIBMENU_MenuTxtCantOpen "[MENU] Can't open %s.\n"
+#define MSGTR_LIBMENU_WarningTooLongLineSplitting "[MENU] Warning, line too long. Splitting it.\n"
+#define MSGTR_LIBMENU_ParsedLines "[MENU] Parsed %d lines.\n"
+
+// libmenu/vf_menu.c
+#define MSGTR_LIBMENU_UnknownMenuCommand "[MENU] Unknown command: '%s'.\n"
+#define MSGTR_LIBMENU_FailedToOpenMenu "[MENU] Failed to open menu: '%s'.\n"
+
+
+// ========================== LIBMPCODECS ===================================
+
+// dec_video.c & dec_audio.c:
+#define MSGTR_CantOpenCodec "Could not open codec.\n"
+#define MSGTR_CantCloseCodec "Could not close codec.\n"
+
+#define MSGTR_MissingDLLcodec "ERROR: Could not open required DirectShow codec %s.\n"
+#define MSGTR_ACMiniterror "Could not load/initialize Win32/ACM audio codec (missing DLL file?).\n"
+#define MSGTR_MissingLAVCcodec "Cannot find codec '%s' in libavcodec...\n"
+
+#define MSGTR_MpegNoSequHdr "MPEG: FATAL: EOF while searching for sequence header.\n"
+#define MSGTR_CannotReadMpegSequHdr "FATAL: Cannot read sequence header.\n"
+#define MSGTR_CannotReadMpegSequHdrEx "FATAL: Cannot read sequence header extension.\n"
+#define MSGTR_BadMpegSequHdr "MPEG: bad sequence header\n"
+#define MSGTR_BadMpegSequHdrEx "MPEG: bad sequence header extension\n"
+
+#define MSGTR_ShMemAllocFail "Cannot allocate shared memory.\n"
+#define MSGTR_CantAllocAudioBuf "Cannot allocate audio out buffer.\n"
+
+#define MSGTR_UnknownAudio "Unknown/missing audio format -> no sound\n"
+
+#define MSGTR_UsingExternalPP "[PP] Using external postprocessing filter, max q = %d.\n"
+#define MSGTR_UsingCodecPP "[PP] Using codec's postprocessing, max q = %d.\n"
+#define MSGTR_VideoAttributeNotSupportedByVO_VD "Video attribute '%s' is not supported by selected vo & vd.\n"
+#define MSGTR_VideoCodecFamilyNotAvailableStr "Requested video codec family [%s] (vfm=%s) not available.\nEnable it at compilation.\n"
+#define MSGTR_AudioCodecFamilyNotAvailableStr "Requested audio codec family [%s] (afm=%s) not available.\nEnable it at compilation.\n"
+#define MSGTR_OpeningVideoDecoder "Opening video decoder: [%s] %s\n"
+#define MSGTR_SelectedVideoCodec "Selected video codec: [%s] vfm: %s (%s)\n"
+#define MSGTR_OpeningAudioDecoder "Opening audio decoder: [%s] %s\n"
+#define MSGTR_SelectedAudioCodec "Selected audio codec: [%s] afm: %s (%s)\n"
+#define MSGTR_BuildingAudioFilterChain "Building audio filter chain for %dHz/%dch/%s -> %dHz/%dch/%s...\n"
+#define MSGTR_UninitVideoStr "Uninit video: %s\n"
+#define MSGTR_UninitAudioStr "Uninit audio: %s\n"
+#define MSGTR_VDecoderInitFailed "VDecoder init failed :(\n"
+#define MSGTR_ADecoderInitFailed "ADecoder init failed :(\n"
+#define MSGTR_ADecoderPreinitFailed "ADecoder preinit failed :(\n"
+#define MSGTR_AllocatingBytesForInputBuffer "dec_audio: Allocating %d bytes for input buffer.\n"
+#define MSGTR_AllocatingBytesForOutputBuffer "dec_audio: Allocating %d + %d = %d bytes for output buffer.\n"
+
+// ad_dvdpcm.c:
+#define MSGTR_SamplesWanted "Samples of this format are needed to improve support. Please contact the developers.\n"
+
+// libmpcodecs/ad_libdv.c
+#define MSGTR_MPCODECS_AudioFramesizeDiffers "[AD_LIBDV] Warning! Audio framesize differs! read=%d hdr=%d.\n"
+
+// vd.c
+#define MSGTR_CodecDidNotSet "VDec: Codec did not set sh->disp_w and sh->disp_h, trying workaround.\n"
+#define MSGTR_CouldNotFindColorspace "Could not find matching colorspace - retrying with -vf scale...\n"
+#define MSGTR_MovieAspectIsSet "Movie-Aspect is %.2f:1 - prescaling to correct movie aspect.\n"
+#define MSGTR_MovieAspectUndefined "Movie-Aspect is undefined - no prescaling applied.\n"
+
+// vd_dshow.c, vd_dmo.c
+#define MSGTR_DownloadCodecPackage "You need to upgrade/install the binary codecs package.\nGo to http://www.mplayerhq.hu/dload.html\n"
+#define MSGTR_DShowInitOK "INFO: Win32/DShow video codec init OK.\n"
+#define MSGTR_DMOInitOK "INFO: Win32/DMO video codec init OK.\n"
+
+// libmpcodecs/vd_dmo.c vd_dshow.c vd_vfw.c
+#define MSGTR_MPCODECS_CouldntAllocateImageForCinepakCodec "[VD_DMO] Couldn't allocate image for cinepak codec.\n"
+
+// libmpcodecs/vd_ffmpeg.c
+#define MSGTR_MPCODECS_XVMCAcceleratedCodec "[VD_FFMPEG] XVMC accelerated codec.\n"
+#define MSGTR_MPCODECS_ArithmeticMeanOfQP "[VD_FFMPEG] Arithmetic mean of QP: %2.4f, Harmonic mean of QP: %2.4f\n"
+#define MSGTR_MPCODECS_DRIFailure "[VD_FFMPEG] DRI failure.\n"
+#define MSGTR_MPCODECS_CouldntAllocateImageForCodec "[VD_FFMPEG] Couldn't allocate image for codec.\n"
+#define MSGTR_MPCODECS_XVMCAcceleratedMPEG2 "[VD_FFMPEG] XVMC-accelerated MPEG-2.\n"
+#define MSGTR_MPCODECS_TryingPixfmt "[VD_FFMPEG] Trying pixfmt=%d.\n"
+#define MSGTR_MPCODECS_McGetBufferShouldWorkOnlyWithXVMC "[VD_FFMPEG] The mc_get_buffer should work only with XVMC acceleration!!"
+#define MSGTR_MPCODECS_UnexpectedInitVoError "[VD_FFMPEG] Unexpected init_vo error.\n"
+#define MSGTR_MPCODECS_UnrecoverableErrorRenderBuffersNotTaken "[VD_FFMPEG] Unrecoverable error, render buffers not taken.\n"
+#define MSGTR_MPCODECS_OnlyBuffersAllocatedByVoXvmcAllowed "[VD_FFMPEG] Only buffers allocated by vo_xvmc allowed.\n"
+
+// libmpcodecs/ve_lavc.c
+#define MSGTR_MPCODECS_HighQualityEncodingSelected "[VE_LAVC] High quality encoding selected (non-realtime)!\n"
+#define MSGTR_MPCODECS_UsingConstantQscale "[VE_LAVC] Using constant qscale = %f (VBR).\n"
+
+// libmpcodecs/ve_raw.c
+#define MSGTR_MPCODECS_OutputWithFourccNotSupported "[VE_RAW] Raw output with FourCC [%x] not supported!\n"
+#define MSGTR_MPCODECS_NoVfwCodecSpecified "[VE_RAW] Required VfW codec not specified!!\n"
+
+// vf.c
+#define MSGTR_CouldNotFindVideoFilter "Couldn't find video filter '%s'.\n"
+#define MSGTR_CouldNotOpenVideoFilter "Couldn't open video filter '%s'.\n"
+#define MSGTR_OpeningVideoFilter "Opening video filter: "
+#define MSGTR_CannotFindColorspace "Cannot find matching colorspace, even by inserting 'scale' :(\n"
+
+// libmpcodecs/vf_crop.c
+#define MSGTR_MPCODECS_CropBadPositionWidthHeight "[CROP] Bad position/width/height - cropped area outside of the original!\n"
+
+// libmpcodecs/vf_cropdetect.c
+#define MSGTR_MPCODECS_CropArea "[CROP] Crop area: X: %d..%d Y: %d..%d (-vf crop=%d:%d:%d:%d).\n"
+
+// libmpcodecs/vf_format.c, vf_palette.c, vf_noformat.c
+#define MSGTR_MPCODECS_UnknownFormatName "[VF_FORMAT] Unknown format name: '%s'.\n"
+
+// libmpcodecs/vf_framestep.c vf_noformat.c vf_palette.c vf_tile.c
+#define MSGTR_MPCODECS_ErrorParsingArgument "[VF_FRAMESTEP] Error parsing argument.\n"
+
+// libmpcodecs/ve_vfw.c
+#define MSGTR_MPCODECS_CompressorType "Compressor type: %.4lx\n"
+#define MSGTR_MPCODECS_CompressorSubtype "Compressor subtype: %.4lx\n"
+#define MSGTR_MPCODECS_CompressorFlags "Compressor flags: %lu, version %lu, ICM version: %lu\n"
+#define MSGTR_MPCODECS_Flags "Flags:"
+#define MSGTR_MPCODECS_Quality " quality"
+
+// libmpcodecs/vf_expand.c
+#define MSGTR_MPCODECS_FullDRNotPossible "Full DR not possible, trying SLICES instead!\n"
+#define MSGTR_MPCODECS_WarnNextFilterDoesntSupportSlices "WARNING! Next filter doesn't support SLICES, get ready for sig11...\n"
+#define MSGTR_MPCODECS_FunWhydowegetNULL "Why do we get NULL??\n"
+
+// libmpcodecs/vf_test.c, vf_yuy2.c, vf_yvu9.c
+#define MSGTR_MPCODECS_WarnNextFilterDoesntSupport "%s not supported by next filter/vo :(\n"
+
+
+// ================================== LIBASS ====================================
+
+// ass_bitmap.c
+#define MSGTR_LIBASS_FT_Glyph_To_BitmapError "[ass] FT_Glyph_To_Bitmap error %d \n"
+#define MSGTR_LIBASS_UnsupportedPixelMode "[ass] Unsupported pixel mode: %d\n"
+#define MSGTR_LIBASS_GlyphBBoxTooLarge "[ass] Glyph bounding box too large: %dx%dpx\n"
+
+// ass.c
+#define MSGTR_LIBASS_NoStyleNamedXFoundUsingY "[ass] [%p] Warning: no style named '%s' found, using '%s'\n"
+#define MSGTR_LIBASS_BadTimestamp "[ass] bad timestamp\n"
+#define MSGTR_LIBASS_BadEncodedDataSize "[ass] bad encoded data size\n"
+#define MSGTR_LIBASS_FontLineTooLong "[ass] Font line too long: %d, %s\n"
+#define MSGTR_LIBASS_EventFormatHeaderMissing "[ass] Event format header missing\n"
+#define MSGTR_LIBASS_ErrorOpeningIconvDescriptor "[ass] error opening iconv descriptor.\n"
+#define MSGTR_LIBASS_ErrorRecodingFile "[ass] error recoding file.\n"
+#define MSGTR_LIBASS_FopenFailed "[ass] ass_read_file(%s): fopen failed\n"
+#define MSGTR_LIBASS_FseekFailed "[ass] ass_read_file(%s): fseek failed\n"
+#define MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan100M "[ass] ass_read_file(%s): Refusing to load subtitles larger than 100M\n"
+#define MSGTR_LIBASS_ReadFailed "Read failed, %d: %s\n"
+#define MSGTR_LIBASS_AddedSubtitleFileMemory "[ass] Added subtitle file: <memory> (%d styles, %d events)\n"
+#define MSGTR_LIBASS_AddedSubtitleFileFname "[ass] Added subtitle file: %s (%d styles, %d events)\n"
+#define MSGTR_LIBASS_FailedToCreateDirectory "[ass] Failed to create directory %s\n"
+#define MSGTR_LIBASS_NotADirectory "[ass] Not a directory: %s\n"
+
+// ass_cache.c
+#define MSGTR_LIBASS_TooManyFonts "[ass] Too many fonts\n"
+#define MSGTR_LIBASS_ErrorOpeningFont "[ass] Error opening font: %s, %d\n"
+
+// ass_fontconfig.c
+#define MSGTR_LIBASS_SelectedFontFamilyIsNotTheRequestedOne "[ass] fontconfig: Selected font is not the requested one: '%s' != '%s'\n"
+#define MSGTR_LIBASS_UsingDefaultFontFamily "[ass] fontconfig_select: Using default font family: (%s, %d, %d) -> %s, %d\n"
+#define MSGTR_LIBASS_UsingDefaultFont "[ass] fontconfig_select: Using default font: (%s, %d, %d) -> %s, %d\n"
+#define MSGTR_LIBASS_UsingArialFontFamily "[ass] fontconfig_select: Using 'Arial' font family: (%s, %d, %d) -> %s, %d\n"
+#define MSGTR_LIBASS_FcInitLoadConfigAndFontsFailed "[ass] FcInitLoadConfigAndFonts failed.\n"
+#define MSGTR_LIBASS_UpdatingFontCache "[ass] Updating font cache.\n"
+#define MSGTR_LIBASS_BetaVersionsOfFontconfigAreNotSupported "[ass] Beta versions of fontconfig are not supported.\n[ass] Update before reporting any bugs.\n"
+#define MSGTR_LIBASS_FcStrSetAddFailed "[ass] FcStrSetAdd failed.\n"
+#define MSGTR_LIBASS_FcDirScanFailed "[ass] FcDirScan failed.\n"
+#define MSGTR_LIBASS_FcDirSave "[ass] FcDirSave failed.\n"
+#define MSGTR_LIBASS_FcConfigAppFontAddDirFailed "[ass] FcConfigAppFontAddDir failed\n"
+#define MSGTR_LIBASS_FontconfigDisabledDefaultFontWillBeUsed "[ass] Fontconfig disabled, only default font will be used.\n"
+#define MSGTR_LIBASS_FunctionCallFailed "[ass] %s failed\n"
+
+// ass_render.c
+#define MSGTR_LIBASS_NeitherPlayResXNorPlayResYDefined "[ass] Neither PlayResX nor PlayResY defined. Assuming 384x288.\n"
+#define MSGTR_LIBASS_PlayResYUndefinedSettingY "[ass] PlayResY undefined, setting %d.\n"
+#define MSGTR_LIBASS_PlayResXUndefinedSettingX "[ass] PlayResX undefined, setting %d.\n"
+#define MSGTR_LIBASS_FT_Init_FreeTypeFailed "[ass] FT_Init_FreeType failed.\n"
+#define MSGTR_LIBASS_Init "[ass] Init\n"
+#define MSGTR_LIBASS_InitFailed "[ass] Init failed.\n"
+#define MSGTR_LIBASS_BadCommand "[ass] Bad command: %c%c\n"
+#define MSGTR_LIBASS_ErrorLoadingGlyph "[ass] Error loading glyph.\n"
+#define MSGTR_LIBASS_FT_Glyph_Stroke_Error "[ass] FT_Glyph_Stroke error %d \n"
+#define MSGTR_LIBASS_UnknownEffectType_InternalError "[ass] Unknown effect type (internal error)\n"
+#define MSGTR_LIBASS_NoStyleFound "[ass] No style found!\n"
+#define MSGTR_LIBASS_EmptyEvent "[ass] Empty event!\n"
+#define MSGTR_LIBASS_MAX_GLYPHS_Reached "[ass] MAX_GLYPHS reached: event %d, start = %llu, duration = %llu\n Text = %s\n"
+#define MSGTR_LIBASS_EventHeightHasChanged "[ass] Warning! Event height has changed! \n"
+
+// ass_font.c
+#define MSGTR_LIBASS_GlyphNotFoundReselectingFont "[ass] Glyph 0x%X not found, selecting one more font for (%s, %d, %d)\n"
+#define MSGTR_LIBASS_GlyphNotFound "[ass] Glyph 0x%X not found in font for (%s, %d, %d)\n"
+#define MSGTR_LIBASS_ErrorOpeningMemoryFont "[ass] Error opening memory font: %s\n"
+#define MSGTR_LIBASS_NoCharmaps "[ass] font face with no charmaps\n"
+#define MSGTR_LIBASS_NoCharmapAutodetected "[ass] no charmap autodetected, trying the first one\n"
+
+
+// ================================== stream ====================================
+
+// ai_alsa1x.c
+#define MSGTR_MPDEMUX_AIALSA1X_CannotSetSamplerate "Cannot set samplerate.\n"
+#define MSGTR_MPDEMUX_AIALSA1X_CannotSetBufferTime "Cannot set buffer time.\n"
+#define MSGTR_MPDEMUX_AIALSA1X_CannotSetPeriodTime "Cannot set period time.\n"
+
+// ai_alsa1x.c / ai_alsa.c
+#define MSGTR_MPDEMUX_AIALSA_PcmBrokenConfig "Broken configuration for this PCM: no configurations available.\n"
+#define MSGTR_MPDEMUX_AIALSA_UnavailableAccessType "Access type not available.\n"
+#define MSGTR_MPDEMUX_AIALSA_UnavailableSampleFmt "Sample format not available.\n"
+#define MSGTR_MPDEMUX_AIALSA_UnavailableChanCount "Channel count not available - reverting to default: %d\n"
+#define MSGTR_MPDEMUX_AIALSA_CannotInstallHWParams "Unable to install hardware parameters: %s"
+#define MSGTR_MPDEMUX_AIALSA_PeriodEqualsBufferSize "Can't use period equal to buffer size (%u == %lu)\n"
+#define MSGTR_MPDEMUX_AIALSA_CannotInstallSWParams "Unable to install software parameters:\n"
+#define MSGTR_MPDEMUX_AIALSA_ErrorOpeningAudio "Error opening audio: %s\n"
+#define MSGTR_MPDEMUX_AIALSA_AlsaStatusError "ALSA status error: %s"
+#define MSGTR_MPDEMUX_AIALSA_AlsaXRUN "ALSA xrun!!! (at least %.3f ms long)\n"
+#define MSGTR_MPDEMUX_AIALSA_AlsaStatus "ALSA Status:\n"
+#define MSGTR_MPDEMUX_AIALSA_AlsaXRUNPrepareError "ALSA xrun: prepare error: %s"
+#define MSGTR_MPDEMUX_AIALSA_AlsaReadWriteError "ALSA read/write error"
+
+// ai_oss.c
+#define MSGTR_MPDEMUX_AIOSS_Unable2SetChanCount "Unable to set channel count: %d\n"
+#define MSGTR_MPDEMUX_AIOSS_Unable2SetStereo "Unable to set stereo: %d\n"
+#define MSGTR_MPDEMUX_AIOSS_Unable2Open "Unable to open '%s': %s\n"
+#define MSGTR_MPDEMUX_AIOSS_UnsupportedFmt "unsupported format\n"
+#define MSGTR_MPDEMUX_AIOSS_Unable2SetAudioFmt "Unable to set audio format."
+#define MSGTR_MPDEMUX_AIOSS_Unable2SetSamplerate "Unable to set samplerate: %d\n"
+#define MSGTR_MPDEMUX_AIOSS_Unable2SetTrigger "Unable to set trigger: %d\n"
+#define MSGTR_MPDEMUX_AIOSS_Unable2GetBlockSize "Unable to get block size!\n"
+#define MSGTR_MPDEMUX_AIOSS_AudioBlockSizeZero "Audio block size is zero, setting to %d!\n"
+#define MSGTR_MPDEMUX_AIOSS_AudioBlockSize2Low "Audio block size too low, setting to %d!\n"
+
+// asf_mmst_streaming.c
+#define MSGTR_MPDEMUX_MMST_WriteError "write error\n"
+#define MSGTR_MPDEMUX_MMST_EOFAlert "\nAlert! EOF\n"
+#define MSGTR_MPDEMUX_MMST_PreHeaderReadFailed "pre-header read failed\n"
+#define MSGTR_MPDEMUX_MMST_InvalidHeaderSize "Invalid header size, giving up.\n"
+#define MSGTR_MPDEMUX_MMST_HeaderDataReadFailed "Header data read failed.\n"
+#define MSGTR_MPDEMUX_MMST_packet_lenReadFailed "packet_len read failed.\n"
+#define MSGTR_MPDEMUX_MMST_InvalidRTSPPacketSize "Invalid RTSP packet size, giving up.\n"
+#define MSGTR_MPDEMUX_MMST_CmdDataReadFailed "Command data read failed.\n"
+#define MSGTR_MPDEMUX_MMST_HeaderObject "header object\n"
+#define MSGTR_MPDEMUX_MMST_DataObject "data object\n"
+#define MSGTR_MPDEMUX_MMST_FileObjectPacketLen "file object, packet length = %d (%d)\n"
+#define MSGTR_MPDEMUX_MMST_StreamObjectStreamID "stream object, stream ID: %d\n"
+#define MSGTR_MPDEMUX_MMST_2ManyStreamID "Too many IDs, stream skipped."
+#define MSGTR_MPDEMUX_MMST_UnknownObject "unknown object\n"
+#define MSGTR_MPDEMUX_MMST_MediaDataReadFailed "Media data read failed.\n"
+#define MSGTR_MPDEMUX_MMST_MissingSignature "missing signature\n"
+#define MSGTR_MPDEMUX_MMST_PatentedTechnologyJoke "Everything done. Thank you for downloading a media file containing proprietary and patented technology.\n"
+#define MSGTR_MPDEMUX_MMST_UnknownCmd "unknown command %02x\n"
+#define MSGTR_MPDEMUX_MMST_GetMediaPacketErr "get_media_packet error : %s\n"
+#define MSGTR_MPDEMUX_MMST_Connected "Connected\n"
+
+// asf_streaming.c
+#define MSGTR_MPDEMUX_ASF_StreamChunkSize2Small "Ahhhh, stream_chunck size is too small: %d\n"
+#define MSGTR_MPDEMUX_ASF_SizeConfirmMismatch "size_confirm mismatch!: %d %d\n"
+#define MSGTR_MPDEMUX_ASF_WarnDropHeader "Warning: drop header ????\n"
+#define MSGTR_MPDEMUX_ASF_ErrorParsingChunkHeader "Error while parsing chunk header\n"
+#define MSGTR_MPDEMUX_ASF_NoHeaderAtFirstChunk "Didn't get a header as first chunk !!!!\n"
+#define MSGTR_MPDEMUX_ASF_BufferMallocFailed "Error: Can't allocate %d bytes buffer.\n"
+#define MSGTR_MPDEMUX_ASF_ErrReadingNetworkStream "Error while reading network stream.\n"
+#define MSGTR_MPDEMUX_ASF_ErrChunk2Small "Error: Chunk is too small.\n"
+#define MSGTR_MPDEMUX_ASF_ErrSubChunkNumberInvalid "Error: Subchunk number is invalid.\n"
+#define MSGTR_MPDEMUX_ASF_Bandwidth2SmallCannotPlay "Bandwidth too small, file cannot be played!\n"
+#define MSGTR_MPDEMUX_ASF_Bandwidth2SmallDeselectedAudio "Bandwidth too small, deselected audio stream.\n"
+#define MSGTR_MPDEMUX_ASF_Bandwidth2SmallDeselectedVideo "Bandwidth too small, deselected video stream.\n"
+#define MSGTR_MPDEMUX_ASF_InvalidLenInHeader "Invalid length in ASF header!\n"
+#define MSGTR_MPDEMUX_ASF_ErrReadingChunkHeader "Error while reading chunk header.\n"
+#define MSGTR_MPDEMUX_ASF_ErrChunkBiggerThanPacket "Error: chunk_size > packet_size\n"
+#define MSGTR_MPDEMUX_ASF_ErrReadingChunk "Error while reading chunk.\n"
+#define MSGTR_MPDEMUX_ASF_ASFRedirector "=====> ASF Redirector\n"
+#define MSGTR_MPDEMUX_ASF_InvalidProxyURL "invalid proxy URL\n"
+#define MSGTR_MPDEMUX_ASF_UnknownASFStreamType "unknown ASF stream type\n"
+#define MSGTR_MPDEMUX_ASF_Failed2ParseHTTPResponse "Failed to parse HTTP response.\n"
+#define MSGTR_MPDEMUX_ASF_ServerReturn "Server returned %d:%s\n"
+#define MSGTR_MPDEMUX_ASF_ASFHTTPParseWarnCuttedPragma "ASF HTTP PARSE WARNING : Pragma %s cut from %zd bytes to %d\n"
+#define MSGTR_MPDEMUX_ASF_SocketWriteError "socket write error: %s\n"
+#define MSGTR_MPDEMUX_ASF_HeaderParseFailed "Failed to parse header.\n"
+#define MSGTR_MPDEMUX_ASF_NoStreamFound "No stream found.\n"
+#define MSGTR_MPDEMUX_ASF_UnknownASFStreamingType "unknown ASF streaming type\n"
+#define MSGTR_MPDEMUX_ASF_InfoStreamASFURL "STREAM_ASF, URL: %s\n"
+#define MSGTR_MPDEMUX_ASF_StreamingFailed "Failed, exiting.\n"
+
+// audio_in.c
+#define MSGTR_MPDEMUX_AUDIOIN_ErrReadingAudio "\nError reading audio: %s\n"
+#define MSGTR_MPDEMUX_AUDIOIN_XRUNSomeFramesMayBeLeftOut "Recovered from cross-run, some frames may be left out!\n"
+#define MSGTR_MPDEMUX_AUDIOIN_ErrFatalCannotRecover "Fatal error, cannot recover!\n"
+#define MSGTR_MPDEMUX_AUDIOIN_NotEnoughSamples "\nNot enough audio samples!\n"
+
+// cache2.c
+#define MSGTR_MPDEMUX_CACHE2_NonCacheableStream "\rThis stream is non-cacheable.\n"
+#define MSGTR_MPDEMUX_CACHE2_ReadFileposDiffers "!!! read_filepos differs!!! Report this bug...\n"
+
+// network.c
+#define MSGTR_MPDEMUX_NW_UnknownAF "Unknown address family %d\n"
+#define MSGTR_MPDEMUX_NW_ResolvingHostForAF "Resolving %s for %s...\n"
+#define MSGTR_MPDEMUX_NW_CantResolv "Couldn't resolve name for %s: %s\n"
+#define MSGTR_MPDEMUX_NW_ConnectingToServer "Connecting to server %s[%s]: %d...\n"
+#define MSGTR_MPDEMUX_NW_CantConnect2Server "Failed to connect to server with %s\n"
+#define MSGTR_MPDEMUX_NW_SelectFailed "Select failed.\n"
+#define MSGTR_MPDEMUX_NW_ConnTimeout "connection timeout\n"
+#define MSGTR_MPDEMUX_NW_GetSockOptFailed "getsockopt failed: %s\n"
+#define MSGTR_MPDEMUX_NW_ConnectError "connect error: %s\n"
+#define MSGTR_MPDEMUX_NW_InvalidProxySettingTryingWithout "Invalid proxy setting... Trying without proxy.\n"
+#define MSGTR_MPDEMUX_NW_CantResolvTryingWithoutProxy "Could not resolve remote hostname for AF_INET. Trying without proxy.\n"
+#define MSGTR_MPDEMUX_NW_ErrSendingHTTPRequest "Error while sending HTTP request: Didn't send all the request.\n"
+#define MSGTR_MPDEMUX_NW_ReadFailed "Read failed.\n"
+#define MSGTR_MPDEMUX_NW_Read0CouldBeEOF "http_read_response read 0 (i.e. EOF).\n"
+#define MSGTR_MPDEMUX_NW_AuthFailed "Authentication failed. Please use the -user and -passwd options to provide your\n"\
+"username/password for a list of URLs, or form an URL like:\n"\
+"http://username:password@hostname/file\n"
+#define MSGTR_MPDEMUX_NW_AuthRequiredFor "Authentication required for %s\n"
+#define MSGTR_MPDEMUX_NW_AuthRequired "Authentication required.\n"
+#define MSGTR_MPDEMUX_NW_NoPasswdProvidedTryingBlank "No password provided, trying blank password.\n"
+#define MSGTR_MPDEMUX_NW_ErrServerReturned "Server returns %d: %s\n"
+#define MSGTR_MPDEMUX_NW_CacheSizeSetTo "Cache size set to %d KBytes\n"
+
+// open.c, stream.c:
+#define MSGTR_CdDevNotfound "CD-ROM Device '%s' not found.\n"
+#define MSGTR_ErrTrackSelect "Error selecting VCD track."
+#define MSGTR_ReadSTDIN "Reading from stdin...\n"
+#define MSGTR_UnableOpenURL "Unable to open URL: %s\n"
+#define MSGTR_ConnToServer "Connected to server: %s\n"
+#define MSGTR_FileNotFound "File not found: '%s'\n"
+
+#define MSGTR_SMBInitError "Cannot init the libsmbclient library: %d\n"
+#define MSGTR_SMBFileNotFound "Could not open from LAN: '%s'\n"
+#define MSGTR_SMBNotCompiled "MPlayer was not compiled with SMB reading support.\n"
+
+#define MSGTR_CantOpenBluray "Couldn't open Blu-ray device: %s\n"
+#define MSGTR_CantOpenDVD "Couldn't open DVD device: %s (%s)\n"
+
+// stream_cdda.c
+#define MSGTR_MPDEMUX_CDDA_CantOpenCDDADevice "Can't open CDDA device.\n"
+#define MSGTR_MPDEMUX_CDDA_CantOpenDisc "Can't open disc.\n"
+#define MSGTR_MPDEMUX_CDDA_AudioCDFoundWithNTracks "Found audio CD with %d tracks.\n"
+
+// stream_cddb.c
+#define MSGTR_MPDEMUX_CDDB_FailedToReadTOC "Failed to read TOC.\n"
+#define MSGTR_MPDEMUX_CDDB_FailedToOpenDevice "Failed to open %s device.\n"
+#define MSGTR_MPDEMUX_CDDB_NotAValidURL "not a valid URL\n"
+#define MSGTR_MPDEMUX_CDDB_FailedToSendHTTPRequest "Failed to send the HTTP request.\n"
+#define MSGTR_MPDEMUX_CDDB_FailedToReadHTTPResponse "Failed to read the HTTP response.\n"
+#define MSGTR_MPDEMUX_CDDB_HTTPErrorNOTFOUND "Not Found.\n"
+#define MSGTR_MPDEMUX_CDDB_HTTPErrorUnknown "unknown error code\n"
+#define MSGTR_MPDEMUX_CDDB_NoCacheFound "No cache found.\n"
+#define MSGTR_MPDEMUX_CDDB_NotAllXMCDFileHasBeenRead "Not all the xmcd file has been read.\n"
+#define MSGTR_MPDEMUX_CDDB_FailedToCreateDirectory "Failed to create directory %s.\n"
+#define MSGTR_MPDEMUX_CDDB_NotAllXMCDFileHasBeenWritten "Not all of the xmcd file has been written.\n"
+#define MSGTR_MPDEMUX_CDDB_InvalidXMCDDatabaseReturned "Invalid xmcd database file returned.\n"
+#define MSGTR_MPDEMUX_CDDB_UnexpectedFIXME "unexpected FIXME\n"
+#define MSGTR_MPDEMUX_CDDB_UnhandledCode "unhandled code\n"
+#define MSGTR_MPDEMUX_CDDB_UnableToFindEOL "Unable to find end of line.\n"
+#define MSGTR_MPDEMUX_CDDB_ParseOKFoundAlbumTitle "Parse OK, found: %s\n"
+#define MSGTR_MPDEMUX_CDDB_AlbumNotFound "Album not found.\n"
+#define MSGTR_MPDEMUX_CDDB_ServerReturnsCommandSyntaxErr "Server returns: Command syntax error\n"
+#define MSGTR_MPDEMUX_CDDB_NoSitesInfoAvailable "No sites information available.\n"
+#define MSGTR_MPDEMUX_CDDB_FailedToGetProtocolLevel "Failed to get the protocol level.\n"
+#define MSGTR_MPDEMUX_CDDB_NoCDInDrive "No CD in the drive.\n"
+
+// stream_cue.c
+#define MSGTR_MPDEMUX_CUEREAD_UnexpectedCuefileLine "[bincue] Unexpected cuefile line: %s\n"
+#define MSGTR_MPDEMUX_CUEREAD_BinFilenameTested "[bincue] bin filename tested: %s\n"
+#define MSGTR_MPDEMUX_CUEREAD_CannotFindBinFile "[bincue] Couldn't find the bin file - giving up.\n"
+#define MSGTR_MPDEMUX_CUEREAD_UsingBinFile "[bincue] Using bin file %s.\n"
+#define MSGTR_MPDEMUX_CUEREAD_UnknownModeForBinfile "[bincue] unknown mode for binfile. Should not happen. Aborting.\n"
+#define MSGTR_MPDEMUX_CUEREAD_CannotOpenCueFile "[bincue] Cannot open %s.\n"
+#define MSGTR_MPDEMUX_CUEREAD_ErrReadingFromCueFile "[bincue] Error reading from %s\n"
+#define MSGTR_MPDEMUX_CUEREAD_ErrGettingBinFileSize "[bincue] Error getting size of bin file.\n"
+#define MSGTR_MPDEMUX_CUEREAD_InfoTrackFormat "track %02d: format=%d %02d:%02d:%02d\n"
+#define MSGTR_MPDEMUX_CUEREAD_UnexpectedBinFileEOF "[bincue] unexpected end of bin file\n"
+#define MSGTR_MPDEMUX_CUEREAD_CannotReadNBytesOfPayload "[bincue] Couldn't read %d bytes of payload.\n"
+#define MSGTR_MPDEMUX_CUEREAD_CueStreamInfo_FilenameTrackTracksavail "CUE stream_open, filename=%s, track=%d, available tracks: %d -> %d\n"
+
+// stream_dvd.c
+#define MSGTR_DVDspeedCantOpen "Couldn't open DVD device for writing, changing DVD speed needs write access.\n"
+#define MSGTR_DVDrestoreSpeed "Restoring DVD speed... "
+#define MSGTR_DVDlimitSpeed "Limiting DVD speed to %dKB/s... "
+#define MSGTR_DVDlimitFail "failed\n"
+#define MSGTR_DVDlimitOk "successful\n"
+#define MSGTR_NoDVDSupport "MPlayer was compiled without DVD support, exiting.\n"
+#define MSGTR_DVDnumTitles "There are %d titles on this DVD.\n"
+#define MSGTR_DVDinvalidTitle "Invalid DVD title number: %d\n"
+#define MSGTR_DVDnumChapters "There are %d chapters in this DVD title.\n"
+#define MSGTR_DVDinvalidChapter "Invalid DVD chapter number: %d\n"
+#define MSGTR_DVDinvalidChapterRange "Invalid chapter range specification %s\n"
+#define MSGTR_DVDinvalidLastChapter "Invalid DVD last chapter number: %d\n"
+#define MSGTR_DVDnumAngles "There are %d angles in this DVD title.\n"
+#define MSGTR_DVDinvalidAngle "Invalid DVD angle number: %d\n"
+#define MSGTR_DVDnoIFO "Cannot open the IFO file for DVD title %d.\n"
+#define MSGTR_DVDnoVMG "Can't open VMG info!\n"
+#define MSGTR_DVDnoVOBs "Cannot open title VOBS (VTS_%02d_1.VOB).\n"
+#define MSGTR_DVDnoMatchingAudio "No matching DVD audio language found!\n"
+#define MSGTR_DVDaudioChannel "Selected DVD audio channel: %d language: %c%c\n"
+#define MSGTR_DVDaudioStreamInfo "audio stream: %d format: %s (%s) language: %s aid: %d.\n"
+#define MSGTR_DVDnumAudioChannels "number of audio channels on disk: %d.\n"
+#define MSGTR_DVDnoMatchingSubtitle "No matching DVD subtitle language found!\n"
+#define MSGTR_DVDsubtitleChannel "Selected DVD subtitle channel: %d language: %c%c\n"
+#define MSGTR_DVDsubtitleLanguage "subtitle ( sid ): %d language: %s\n"
+#define MSGTR_DVDnumSubtitles "number of subtitles on disk: %d\n"
+
+// stream_bluray.c
+#define MSGTR_BlurayNoDevice "No Blu-ray device/location was specified ...\n"
+#define MSGTR_BlurayNoTitles "Can't find any Blu-ray-compatible title here.\n"
+#define MSGTR_BlurayOK "Blu-ray successfully opened.\n"
+
+// stream_radio.c
+#define MSGTR_RADIO_ChannelNamesDetected "[radio] Radio channel names detected.\n"
+#define MSGTR_RADIO_FreqRange "[radio] Allowed frequency range is %.2f-%.2f MHz.\n"
+#define MSGTR_RADIO_WrongFreqForChannel "[radio] Wrong frequency for channel %s\n"
+#define MSGTR_RADIO_WrongChannelNumberFloat "[radio] Wrong channel number: %.2f\n"
+#define MSGTR_RADIO_WrongChannelNumberInt "[radio] Wrong channel number: %d\n"
+#define MSGTR_RADIO_WrongChannelName "[radio] Wrong channel name: %s\n"
+#define MSGTR_RADIO_FreqParameterDetected "[radio] Radio frequency parameter detected.\n"
+#define MSGTR_RADIO_DoneParsingChannels "[radio] Done parsing channels.\n"
+#define MSGTR_RADIO_GetTunerFailed "[radio] Warning: ioctl get tuner failed: %s. Setting frac to %d.\n"
+#define MSGTR_RADIO_NotRadioDevice "[radio] %s is no radio device!\n"
+#define MSGTR_RADIO_TunerCapLowYes "[radio] tuner is low:yes frac=%d\n"
+#define MSGTR_RADIO_TunerCapLowNo "[radio] tuner is low:no frac=%d\n"
+#define MSGTR_RADIO_SetFreqFailed "[radio] ioctl set frequency 0x%x (%.2f) failed: %s\n"
+#define MSGTR_RADIO_GetFreqFailed "[radio] ioctl get frequency failed: %s\n"
+#define MSGTR_RADIO_SetMuteFailed "[radio] ioctl set mute failed: %s\n"
+#define MSGTR_RADIO_QueryControlFailed "[radio] ioctl query control failed: %s\n"
+#define MSGTR_RADIO_GetVolumeFailed "[radio] ioctl get volume failed: %s\n"
+#define MSGTR_RADIO_SetVolumeFailed "[radio] ioctl set volume failed: %s\n"
+#define MSGTR_RADIO_DroppingFrame "\n[radio] too bad - dropping audio frame (%d bytes)!\n"
+#define MSGTR_RADIO_BufferEmpty "[radio] grab_audio_frame: buffer empty, waiting for %d data bytes.\n"
+#define MSGTR_RADIO_AudioInitFailed "[radio] audio_in_init failed: %s\n"
+#define MSGTR_RADIO_AudioBuffer "[radio] Audio capture - buffer=%d bytes (block=%d bytes).\n"
+#define MSGTR_RADIO_AllocateBufferFailed "[radio] cannot allocate audio buffer (block=%d,buf=%d): %s\n"
+#define MSGTR_RADIO_CurrentFreq "[radio] Current frequency: %.2f\n"
+#define MSGTR_RADIO_SelectedChannel "[radio] Selected channel: %d - %s (freq: %.2f)\n"
+#define MSGTR_RADIO_ChangeChannelNoChannelList "[radio] Can not change channel: no channel list given.\n"
+#define MSGTR_RADIO_UnableOpenDevice "[radio] Unable to open '%s': %s\n"
+#define MSGTR_RADIO_RadioDevice "[radio] Radio fd: %d, %s\n"
+#define MSGTR_RADIO_InitFracFailed "[radio] init_frac failed.\n"
+#define MSGTR_RADIO_WrongFreq "[radio] Wrong frequency: %.2f\n"
+#define MSGTR_RADIO_UsingFreq "[radio] Using frequency: %.2f.\n"
+#define MSGTR_RADIO_AudioInInitFailed "[radio] audio_in_init failed.\n"
+#define MSGTR_RADIO_BufferString "[radio] %s: in buffer=%d dropped=%d\n"
+#define MSGTR_RADIO_AudioInSetupFailed "[radio] audio_in_setup call failed: %s\n"
+#define MSGTR_RADIO_CaptureStarting "[radio] Starting capture stuff.\n"
+#define MSGTR_RADIO_ClearBufferFailed "[radio] Clearing buffer failed: %s\n"
+#define MSGTR_RADIO_StreamEnableCacheFailed "[radio] Call to stream_enable_cache failed: %s\n"
+#define MSGTR_RADIO_DriverUnknownStr "[radio] Unknown driver name: %s\n"
+#define MSGTR_RADIO_DriverV4L2 "[radio] Using V4Lv2 radio interface.\n"
+#define MSGTR_RADIO_DriverV4L "[radio] Using V4Lv1 radio interface.\n"
+#define MSGTR_RADIO_DriverBSDBT848 "[radio] Using *BSD BT848 radio interface.\n"
+#define MSGTR_RADIO_AvailableDrivers "[radio] Available drivers: "
+
+//tv.c
+#define MSGTR_TV_BogusNormParameter "tv.c: norm_from_string(%s): Bogus norm parameter, setting %s.\n"
+#define MSGTR_TV_NoVideoInputPresent "Error: No video input present!\n"
+#define MSGTR_TV_UnknownImageFormat ""\
+"==================================================================\n"\
+" WARNING: UNTESTED OR UNKNOWN OUTPUT IMAGE FORMAT REQUESTED (0x%x)\n"\
+" This may cause buggy playback or program crash! Bug reports will\n"\
+" be ignored! You should try again with YV12 (which is the default\n"\
+" colorspace) and read the documentation!\n"\
+"==================================================================\n"
+#define MSGTR_TV_SelectedNormId "Selected norm id: %d\n"
+#define MSGTR_TV_SelectedNorm "Selected norm : %s\n"
+#define MSGTR_TV_CannotSetNorm "Error: Cannot set norm!\n"
+#define MSGTR_TV_MJP_WidthHeight " MJP: width %d height %d\n"
+#define MSGTR_TV_UnableToSetWidth "Unable to set requested width: %d\n"
+#define MSGTR_TV_UnableToSetHeight "Unable to set requested height: %d\n"
+#define MSGTR_TV_NoTuner "Selected input hasn't got a tuner!\n"
+#define MSGTR_TV_UnableFindChanlist "Unable to find selected channel list! (%s)\n"
+#define MSGTR_TV_SelectedChanlist "Selected channel list: %s (including %d channels)\n"
+#define MSGTR_TV_ChannelFreqParamConflict "You can't set frequency and channel simultaneously!\n"
+#define MSGTR_TV_ChannelNamesDetected "TV channel names detected.\n"
+#define MSGTR_TV_NoFreqForChannel "Couldn't find frequency for channel %s (%s)\n"
+#define MSGTR_TV_SelectedChannel3 "Selected channel: %s - %s (freq: %.3f)\n"
+#define MSGTR_TV_SelectedChannel2 "Selected channel: %s (freq: %.3f)\n"
+#define MSGTR_TV_SelectedFrequency "Selected frequency: %lu (%.3f)\n"
+#define MSGTR_TV_RequestedChannel "Requested channel: %s\n"
+#define MSGTR_TV_UnsupportedAudioType "Audio type '%s (%x)' unsupported!\n"
+#define MSGTR_TV_AudioFormat " TV audio: %d channels, %d bits, %d Hz\n"
+#define MSGTR_TV_AvailableDrivers "Available drivers:\n"
+#define MSGTR_TV_DriverInfo "Selected driver: %s\n name: %s\n author: %s\n comment: %s\n"
+#define MSGTR_TV_NoSuchDriver "No such driver: %s\n"
+#define MSGTR_TV_DriverAutoDetectionFailed "TV driver autodetection failed.\n"
+#define MSGTR_TV_UnknownColorOption "Unknown color option (%d) specified!\n"
+#define MSGTR_TV_CurrentFrequency "Current frequency: %lu (%.3f)\n"
+#define MSGTR_TV_NoTeletext "No teletext"
+#define MSGTR_TV_Bt848IoctlFailed "tvi_bsdbt848: Call to %s ioctl failed. Error: %s\n"
+#define MSGTR_TV_Bt848InvalidAudioRate "tvi_bsdbt848: Invalid audio rate. Error: %s\n"
+#define MSGTR_TV_Bt848ErrorOpeningBktrDev "tvi_bsdbt848: Unable to open bktr device. Error: %s\n"
+#define MSGTR_TV_Bt848ErrorOpeningTunerDev "tvi_bsdbt848: Unable to open tuner device. Error: %s\n"
+#define MSGTR_TV_Bt848ErrorOpeningDspDev "tvi_bsdbt848: Unable to open dsp device. Error: %s\n"
+#define MSGTR_TV_Bt848ErrorConfiguringDsp "tvi_bsdbt848: Configuration of dsp failed. Error: %s\n"
+#define MSGTR_TV_Bt848ErrorReadingAudio "tvi_bsdbt848: Error reading audio data. Error: %s\n"
+#define MSGTR_TV_Bt848MmapFailed "tvi_bsdbt848: mmap failed. Error: %s\n"
+#define MSGTR_TV_Bt848FrameBufAllocFailed "tvi_bsdbt848: Frame buffer allocation failed. Error: %s\n"
+#define MSGTR_TV_Bt848ErrorSettingWidth "tvi_bsdbt848: Error setting picture width. Error: %s\n"
+#define MSGTR_TV_Bt848ErrorSettingHeight "tvi_bsdbt848: Error setting picture height. Error: %s\n"
+#define MSGTR_TV_Bt848UnableToStopCapture "tvi_bsdbt848: Unable to stop capture. Error: %s\n"
+#define MSGTR_TV_TTSupportedLanguages "Supported Teletext languages:\n"
+#define MSGTR_TV_TTSelectedLanguage "Selected default teletext language: %s\n"
+#define MSGTR_TV_ScannerNotAvailableWithoutTuner "Channel scanner is not available without tuner\n"
+
+//tvi_dshow.c
+#define MSGTR_TVI_DS_UnableConnectInputVideoDecoder "Unable to connect given input to video decoder. Error:0x%x\n"
+#define MSGTR_TVI_DS_UnableConnectInputAudioDecoder "Unable to connect given input to audio decoder. Error:0x%x\n"
+#define MSGTR_TVI_DS_UnableSelectVideoFormat "tvi_dshow: Unable to select video format. Error:0x%x\n"
+#define MSGTR_TVI_DS_UnableSelectAudioFormat "tvi_dshow: Unable to select audio format. Error:0x%x\n"
+#define MSGTR_TVI_DS_UnableGetMediaControlInterface "tvi_dshow: Unable to get IMediaControl interface. Error:0x%x\n"
+#define MSGTR_TVI_DS_UnableStartGraph "tvi_dshow: Unable to start graph! Error:0x%x\n"
+#define MSGTR_TVI_DS_DeviceNotFound "tvi_dshow: Device #%d not found\n"
+#define MSGTR_TVI_DS_UnableGetDeviceName "tvi_dshow: Unable to get name for device #%d\n"
+#define MSGTR_TVI_DS_UsingDevice "tvi_dshow: Using device #%d: %s\n"
+#define MSGTR_TVI_DS_DeviceName "tvi_dshow: Device #%d: %s\n"
+#define MSGTR_TVI_DS_DirectGetFreqFailed "tvi_dshow: Unable to get frequency directly. OS built-in channels table will be used.\n"
+#define MSGTR_TVI_DS_DirectSetFreqFailed "tvi_dshow: Unable to set frequency directly. OS built-in channels table will be used.\n"
+#define MSGTR_TVI_DS_SupportedNorms "tvi_dshow: supported norms:"
+#define MSGTR_TVI_DS_AvailableVideoInputs "tvi_dshow: available video inputs:"
+#define MSGTR_TVI_DS_AvailableAudioInputs "tvi_dshow: available audio inputs:"
+//following phrase will be printed near the selected audio/video input
+#define MSGTR_TVI_DS_InputSelected "(selected)"
+#define MSGTR_TVI_DS_UnableExtractFreqTable "tvi_dshow: Unable to load frequency table from kstvtune.ax\n"
+#define MSGTR_TVI_DS_WrongDeviceParam "tvi_dshow: Wrong device parameter: %s\n"
+#define MSGTR_TVI_DS_WrongDeviceIndex "tvi_dshow: Wrong device index: %d\n"
+#define MSGTR_TVI_DS_WrongADeviceParam "tvi_dshow: Wrong adevice parameter: %s\n"
+#define MSGTR_TVI_DS_WrongADeviceIndex "tvi_dshow: Wrong adevice index: %d\n"
+
+#define MSGTR_TVI_DS_SamplerateNotsupported "tvi_dshow: Samplerate %d is not supported by device. Failing back to first available.\n"
+#define MSGTR_TVI_DS_VideoAdjustigNotSupported "tvi_dshow: Adjusting of brightness/hue/saturation/contrast is not supported by device\n"
+
+#define MSGTR_TVI_DS_ChangingWidthHeightNotSupported "tvi_dshow: Changing video width/height is not supported by device.\n"
+#define MSGTR_TVI_DS_SelectingInputNotSupported "tvi_dshow: Selection of capture source is not supported by device\n"
+#define MSGTR_TVI_DS_FreqTableLoaded "tvi_dshow: loaded system (%s) frequency table for country id=%d (channels:%d).\n"
+#define MSGTR_TVI_DS_ErrorParsingAudioFormatStruct "tvi_dshow: Unable to parse audio format structure.\n"
+#define MSGTR_TVI_DS_ErrorParsingVideoFormatStruct "tvi_dshow: Unable to parse video format structure.\n"
+#define MSGTR_TVI_DS_UnableSetAudioMode "tvi_dshow: Unable to set audio mode %d. Error:0x%x\n"
+#define MSGTR_TVI_DS_UnsupportedMediaType "tvi_dshow: Unsupported media type passed to %s\n"
+#define MSGTR_TVI_DS_UnableGetsupportedVideoFormats "tvi_dshow: Unable to get supported media formats from video pin. Error:0x%x\n"
+#define MSGTR_TVI_DS_UnableGetsupportedAudioFormats "tvi_dshow: Unable to get supported media formats from audio pin. Error:0x%x Disabling audio.\n"
+#define MSGTR_TVI_DS_UnableFindNearestChannel "tvi_dshow: Unable to find nearest channel in system frequency table\n"
+#define MSGTR_TVI_DS_UnableToSetChannel "tvi_dshow: Unable to switch to nearest channel from system frequency table. Error:0x%x\n"
+#define MSGTR_TVI_DS_UnableTerminateVPPin "tvi_dshow: Unable to terminate VideoPort pin with any filter in graph. Error:0x%x\n"
+#define MSGTR_TVI_DS_UnableBuildVideoSubGraph "tvi_dshow: Unable to build video chain of capture graph. Error:0x%x\n"
+#define MSGTR_TVI_DS_UnableBuildAudioSubGraph "tvi_dshow: Unable to build audio chain of capture graph. Error:0x%x\n"
+#define MSGTR_TVI_DS_UnableBuildVBISubGraph "tvi_dshow: Unable to build VBI chain of capture graph. Error:0x%x\n"
+#define MSGTR_TVI_DS_GraphInitFailure "tvi_dshow: Directshow graph initialization failure.\n"
+#define MSGTR_TVI_DS_NoVideoCaptureDevice "tvi_dshow: Unable to find video capture device\n"
+#define MSGTR_TVI_DS_NoAudioCaptureDevice "tvi_dshow: Unable to find audio capture device\n"
+#define MSGTR_TVI_DS_GetActualMediatypeFailed "tvi_dshow: Unable to get actual mediatype (Error:0x%x). Assuming equal to requested.\n"
+
+// url.c
+#define MSGTR_MPDEMUX_URL_StringAlreadyEscaped "String appears to be already escaped in url_escape %c%c1%c2\n"
+
+// subtitles
+#define MSGTR_SUBTITLES_SubRip_UnknownFontColor "SubRip: unknown font color in subtitle: %s\n"
+
+
+/* untranslated messages from the English master file */
+
+
+#endif /* MPLAYER_HELP_MP_H */
diff --git a/libavfilter/libmpcodecs/img_format.c b/libavfilter/libmpcodecs/img_format.c
new file mode 100644
index 0000000000..ba870421d3
--- /dev/null
+++ b/libavfilter/libmpcodecs/img_format.c
@@ -0,0 +1,170 @@
+/*
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "config.h"
+#include "img_format.h"
+#include "stdio.h"
+
+const char *vo_format_name(int format)
+{
+ static char unknown_format[20];
+ switch(format)
+ {
+ case IMGFMT_RGB1: return "RGB 1-bit";
+ case IMGFMT_RGB4: return "RGB 4-bit";
+ case IMGFMT_RG4B: return "RGB 4-bit per byte";
+ case IMGFMT_RGB8: return "RGB 8-bit";
+ case IMGFMT_RGB12: return "RGB 12-bit";
+ case IMGFMT_RGB15: return "RGB 15-bit";
+ case IMGFMT_RGB16: return "RGB 16-bit";
+ case IMGFMT_RGB24: return "RGB 24-bit";
+// case IMGFMT_RGB32: return "RGB 32-bit";
+ case IMGFMT_RGB48LE: return "RGB 48-bit LE";
+ case IMGFMT_RGB48BE: return "RGB 48-bit BE";
+ case IMGFMT_BGR1: return "BGR 1-bit";
+ case IMGFMT_BGR4: return "BGR 4-bit";
+ case IMGFMT_BG4B: return "BGR 4-bit per byte";
+ case IMGFMT_BGR8: return "BGR 8-bit";
+ case IMGFMT_BGR12: return "BGR 12-bit";
+ case IMGFMT_BGR15: return "BGR 15-bit";
+ case IMGFMT_BGR16: return "BGR 16-bit";
+ case IMGFMT_BGR24: return "BGR 24-bit";
+// case IMGFMT_BGR32: return "BGR 32-bit";
+ case IMGFMT_ABGR: return "ABGR";
+ case IMGFMT_BGRA: return "BGRA";
+ case IMGFMT_ARGB: return "ARGB";
+ case IMGFMT_RGBA: return "RGBA";
+ case IMGFMT_YVU9: return "Planar YVU9";
+ case IMGFMT_IF09: return "Planar IF09";
+ case IMGFMT_YV12: return "Planar YV12";
+ case IMGFMT_I420: return "Planar I420";
+ case IMGFMT_IYUV: return "Planar IYUV";
+ case IMGFMT_CLPL: return "Planar CLPL";
+ case IMGFMT_Y800: return "Planar Y800";
+ case IMGFMT_Y8: return "Planar Y8";
+ case IMGFMT_420P16_LE: return "Planar 420P 16-bit little-endian";
+ case IMGFMT_420P16_BE: return "Planar 420P 16-bit big-endian";
+ case IMGFMT_422P16_LE: return "Planar 422P 16-bit little-endian";
+ case IMGFMT_422P16_BE: return "Planar 422P 16-bit big-endian";
+ case IMGFMT_444P16_LE: return "Planar 444P 16-bit little-endian";
+ case IMGFMT_444P16_BE: return "Planar 444P 16-bit big-endian";
+ case IMGFMT_420A: return "Planar 420P with alpha";
+ case IMGFMT_444P: return "Planar 444P";
+ case IMGFMT_422P: return "Planar 422P";
+ case IMGFMT_411P: return "Planar 411P";
+ case IMGFMT_NV12: return "Planar NV12";
+ case IMGFMT_NV21: return "Planar NV21";
+ case IMGFMT_HM12: return "Planar NV12 Macroblock";
+ case IMGFMT_IUYV: return "Packed IUYV";
+ case IMGFMT_IY41: return "Packed IY41";
+ case IMGFMT_IYU1: return "Packed IYU1";
+ case IMGFMT_IYU2: return "Packed IYU2";
+ case IMGFMT_UYVY: return "Packed UYVY";
+ case IMGFMT_UYNV: return "Packed UYNV";
+ case IMGFMT_cyuv: return "Packed CYUV";
+ case IMGFMT_Y422: return "Packed Y422";
+ case IMGFMT_YUY2: return "Packed YUY2";
+ case IMGFMT_YUNV: return "Packed YUNV";
+ case IMGFMT_YVYU: return "Packed YVYU";
+ case IMGFMT_Y41P: return "Packed Y41P";
+ case IMGFMT_Y211: return "Packed Y211";
+ case IMGFMT_Y41T: return "Packed Y41T";
+ case IMGFMT_Y42T: return "Packed Y42T";
+ case IMGFMT_V422: return "Packed V422";
+ case IMGFMT_V655: return "Packed V655";
+ case IMGFMT_CLJR: return "Packed CLJR";
+ case IMGFMT_YUVP: return "Packed YUVP";
+ case IMGFMT_UYVP: return "Packed UYVP";
+ case IMGFMT_MPEGPES: return "Mpeg PES";
+ case IMGFMT_ZRMJPEGNI: return "Zoran MJPEG non-interlaced";
+ case IMGFMT_ZRMJPEGIT: return "Zoran MJPEG top field first";
+ case IMGFMT_ZRMJPEGIB: return "Zoran MJPEG bottom field first";
+ case IMGFMT_XVMC_MOCO_MPEG2: return "MPEG1/2 Motion Compensation";
+ case IMGFMT_XVMC_IDCT_MPEG2: return "MPEG1/2 Motion Compensation and IDCT";
+ case IMGFMT_VDPAU_MPEG1: return "MPEG1 VDPAU acceleration";
+ case IMGFMT_VDPAU_MPEG2: return "MPEG2 VDPAU acceleration";
+ case IMGFMT_VDPAU_H264: return "H.264 VDPAU acceleration";
+ case IMGFMT_VDPAU_MPEG4: return "MPEG-4 Part 2 VDPAU acceleration";
+ case IMGFMT_VDPAU_WMV3: return "WMV3 VDPAU acceleration";
+ case IMGFMT_VDPAU_VC1: return "VC1 VDPAU acceleration";
+ }
+ snprintf(unknown_format,20,"Unknown 0x%04x",format);
+ return unknown_format;
+}
+
+int mp_get_chroma_shift(int format, int *x_shift, int *y_shift)
+{
+ int xs = 0, ys = 0;
+ int bpp;
+ int bpp_factor = 1;
+ int err = 0;
+ switch (format) {
+ case IMGFMT_420P16_LE:
+ case IMGFMT_420P16_BE:
+ bpp_factor = 2;
+ case IMGFMT_420A:
+ case IMGFMT_I420:
+ case IMGFMT_IYUV:
+ case IMGFMT_YV12:
+ xs = 1;
+ ys = 1;
+ break;
+ case IMGFMT_IF09:
+ case IMGFMT_YVU9:
+ xs = 2;
+ ys = 2;
+ break;
+ case IMGFMT_444P16_LE:
+ case IMGFMT_444P16_BE:
+ bpp_factor = 2;
+ case IMGFMT_444P:
+ xs = 0;
+ ys = 0;
+ break;
+ case IMGFMT_422P16_LE:
+ case IMGFMT_422P16_BE:
+ bpp_factor = 2;
+ case IMGFMT_422P:
+ xs = 1;
+ ys = 0;
+ break;
+ case IMGFMT_411P:
+ xs = 2;
+ ys = 0;
+ break;
+ case IMGFMT_440P:
+ xs = 0;
+ ys = 1;
+ break;
+ case IMGFMT_Y8:
+ case IMGFMT_Y800:
+ xs = 31;
+ ys = 31;
+ break;
+ default:
+ err = 1;
+ break;
+ }
+ if (x_shift) *x_shift = xs;
+ if (y_shift) *y_shift = ys;
+ bpp = 8 + ((16 >> xs) >> ys);
+ if (format == IMGFMT_420A)
+ bpp += 8;
+ bpp *= bpp_factor;
+ return err ? 0 : bpp;
+}
diff --git a/libavfilter/libmpcodecs/img_format.h b/libavfilter/libmpcodecs/img_format.h
new file mode 100644
index 0000000000..c95ed4df3c
--- /dev/null
+++ b/libavfilter/libmpcodecs/img_format.h
@@ -0,0 +1,214 @@
+/*
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef MPLAYER_IMG_FORMAT_H
+#define MPLAYER_IMG_FORMAT_H
+
+#include "config.h"
+
+/* RGB/BGR Formats */
+
+#define IMGFMT_RGB_MASK 0xFFFFFF00
+#define IMGFMT_RGB (('R'<<24)|('G'<<16)|('B'<<8))
+#define IMGFMT_RGB1 (IMGFMT_RGB|1)
+#define IMGFMT_RGB4 (IMGFMT_RGB|4)
+#define IMGFMT_RGB4_CHAR (IMGFMT_RGB|4|128) // RGB4 with 1 pixel per byte
+#define IMGFMT_RGB8 (IMGFMT_RGB|8)
+#define IMGFMT_RGB12 (IMGFMT_RGB|12)
+#define IMGFMT_RGB15 (IMGFMT_RGB|15)
+#define IMGFMT_RGB16 (IMGFMT_RGB|16)
+#define IMGFMT_RGB24 (IMGFMT_RGB|24)
+#define IMGFMT_RGB32 (IMGFMT_RGB|32)
+#define IMGFMT_RGB48LE (IMGFMT_RGB|48)
+#define IMGFMT_RGB48BE (IMGFMT_RGB|48|128)
+
+#define IMGFMT_BGR_MASK 0xFFFFFF00
+#define IMGFMT_BGR (('B'<<24)|('G'<<16)|('R'<<8))
+#define IMGFMT_BGR1 (IMGFMT_BGR|1)
+#define IMGFMT_BGR4 (IMGFMT_BGR|4)
+#define IMGFMT_BGR4_CHAR (IMGFMT_BGR|4|128) // BGR4 with 1 pixel per byte
+#define IMGFMT_BGR8 (IMGFMT_BGR|8)
+#define IMGFMT_BGR12 (IMGFMT_BGR|12)
+#define IMGFMT_BGR15 (IMGFMT_BGR|15)
+#define IMGFMT_BGR16 (IMGFMT_BGR|16)
+#define IMGFMT_BGR24 (IMGFMT_BGR|24)
+#define IMGFMT_BGR32 (IMGFMT_BGR|32)
+
+#if HAVE_BIGENDIAN
+#define IMGFMT_ABGR IMGFMT_RGB32
+#define IMGFMT_BGRA (IMGFMT_RGB32|64)
+#define IMGFMT_ARGB IMGFMT_BGR32
+#define IMGFMT_RGBA (IMGFMT_BGR32|64)
+#define IMGFMT_RGB48NE IMGFMT_RGB48BE
+#define IMGFMT_RGB12BE IMGFMT_RGB12
+#define IMGFMT_RGB12LE (IMGFMT_RGB12|64)
+#define IMGFMT_RGB15BE IMGFMT_RGB15
+#define IMGFMT_RGB15LE (IMGFMT_RGB15|64)
+#define IMGFMT_RGB16BE IMGFMT_RGB16
+#define IMGFMT_RGB16LE (IMGFMT_RGB16|64)
+#define IMGFMT_BGR12BE IMGFMT_BGR12
+#define IMGFMT_BGR12LE (IMGFMT_BGR12|64)
+#define IMGFMT_BGR15BE IMGFMT_BGR15
+#define IMGFMT_BGR15LE (IMGFMT_BGR15|64)
+#define IMGFMT_BGR16BE IMGFMT_BGR16
+#define IMGFMT_BGR16LE (IMGFMT_BGR16|64)
+#else
+#define IMGFMT_ABGR (IMGFMT_BGR32|64)
+#define IMGFMT_BGRA IMGFMT_BGR32
+#define IMGFMT_ARGB (IMGFMT_RGB32|64)
+#define IMGFMT_RGBA IMGFMT_RGB32
+#define IMGFMT_RGB48NE IMGFMT_RGB48LE
+#define IMGFMT_RGB12BE (IMGFMT_RGB12|64)
+#define IMGFMT_RGB12LE IMGFMT_RGB12
+#define IMGFMT_RGB15BE (IMGFMT_RGB15|64)
+#define IMGFMT_RGB15LE IMGFMT_RGB15
+#define IMGFMT_RGB16BE (IMGFMT_RGB16|64)
+#define IMGFMT_RGB16LE IMGFMT_RGB16
+#define IMGFMT_BGR12BE (IMGFMT_BGR12|64)
+#define IMGFMT_BGR12LE IMGFMT_BGR12
+#define IMGFMT_BGR15BE (IMGFMT_BGR15|64)
+#define IMGFMT_BGR15LE IMGFMT_BGR15
+#define IMGFMT_BGR16BE (IMGFMT_BGR16|64)
+#define IMGFMT_BGR16LE IMGFMT_BGR16
+#endif
+
+/* old names for compatibility */
+#define IMGFMT_RG4B IMGFMT_RGB4_CHAR
+#define IMGFMT_BG4B IMGFMT_BGR4_CHAR
+
+#define IMGFMT_IS_RGB(fmt) (((fmt)&IMGFMT_RGB_MASK)==IMGFMT_RGB)
+#define IMGFMT_IS_BGR(fmt) (((fmt)&IMGFMT_BGR_MASK)==IMGFMT_BGR)
+
+#define IMGFMT_RGB_DEPTH(fmt) ((fmt)&0x3F)
+#define IMGFMT_BGR_DEPTH(fmt) ((fmt)&0x3F)
+
+
+/* Planar YUV Formats */
+
+#define IMGFMT_YVU9 0x39555659
+#define IMGFMT_IF09 0x39304649
+#define IMGFMT_YV12 0x32315659
+#define IMGFMT_I420 0x30323449
+#define IMGFMT_IYUV 0x56555949
+#define IMGFMT_CLPL 0x4C504C43
+#define IMGFMT_Y800 0x30303859
+#define IMGFMT_Y8 0x20203859
+#define IMGFMT_NV12 0x3231564E
+#define IMGFMT_NV21 0x3132564E
+
+/* unofficial Planar Formats, FIXME if official 4CC exists */
+#define IMGFMT_444P 0x50343434
+#define IMGFMT_422P 0x50323234
+#define IMGFMT_411P 0x50313134
+#define IMGFMT_440P 0x50303434
+#define IMGFMT_HM12 0x32314D48
+
+// 4:2:0 planar with alpha
+#define IMGFMT_420A 0x41303234
+
+#define IMGFMT_444P16_LE 0x51343434
+#define IMGFMT_444P16_BE 0x34343451
+#define IMGFMT_422P16_LE 0x51323234
+#define IMGFMT_422P16_BE 0x34323251
+#define IMGFMT_420P16_LE 0x51303234
+#define IMGFMT_420P16_BE 0x34323051
+#if HAVE_BIGENDIAN
+#define IMGFMT_444P16 IMGFMT_444P16_BE
+#define IMGFMT_422P16 IMGFMT_422P16_BE
+#define IMGFMT_420P16 IMGFMT_420P16_BE
+#else
+#define IMGFMT_444P16 IMGFMT_444P16_LE
+#define IMGFMT_422P16 IMGFMT_422P16_LE
+#define IMGFMT_420P16 IMGFMT_420P16_LE
+#endif
+
+#define IMGFMT_IS_YUVP16_LE(fmt) (((fmt ^ IMGFMT_420P16_LE) & 0xff0000ff) == 0)
+#define IMGFMT_IS_YUVP16_BE(fmt) (((fmt ^ IMGFMT_420P16_BE) & 0xff0000ff) == 0)
+#define IMGFMT_IS_YUVP16_NE(fmt) (((fmt ^ IMGFMT_420P16 ) & 0xff0000ff) == 0)
+#define IMGFMT_IS_YUVP16(fmt) (IMGFMT_IS_YUVP16_LE(fmt) || IMGFMT_IS_YUVP16_BE(fmt))
+
+/* Packed YUV Formats */
+
+#define IMGFMT_IUYV 0x56595549
+#define IMGFMT_IY41 0x31435949
+#define IMGFMT_IYU1 0x31555949
+#define IMGFMT_IYU2 0x32555949
+#define IMGFMT_UYVY 0x59565955
+#define IMGFMT_UYNV 0x564E5955
+#define IMGFMT_cyuv 0x76757963
+#define IMGFMT_Y422 0x32323459
+#define IMGFMT_YUY2 0x32595559
+#define IMGFMT_YUNV 0x564E5559
+#define IMGFMT_YVYU 0x55595659
+#define IMGFMT_Y41P 0x50313459
+#define IMGFMT_Y211 0x31313259
+#define IMGFMT_Y41T 0x54313459
+#define IMGFMT_Y42T 0x54323459
+#define IMGFMT_V422 0x32323456
+#define IMGFMT_V655 0x35353656
+#define IMGFMT_CLJR 0x524A4C43
+#define IMGFMT_YUVP 0x50565559
+#define IMGFMT_UYVP 0x50565955
+
+/* Compressed Formats */
+#define IMGFMT_MPEGPES (('M'<<24)|('P'<<16)|('E'<<8)|('S'))
+#define IMGFMT_MJPEG (('M')|('J'<<8)|('P'<<16)|('G'<<24))
+/* Formats that are understood by zoran chips, we include
+ * non-interlaced, interlaced top-first, interlaced bottom-first */
+#define IMGFMT_ZRMJPEGNI (('Z'<<24)|('R'<<16)|('N'<<8)|('I'))
+#define IMGFMT_ZRMJPEGIT (('Z'<<24)|('R'<<16)|('I'<<8)|('T'))
+#define IMGFMT_ZRMJPEGIB (('Z'<<24)|('R'<<16)|('I'<<8)|('B'))
+
+// I think that this code could not be used by any other codec/format
+#define IMGFMT_XVMC 0x1DC70000
+#define IMGFMT_XVMC_MASK 0xFFFF0000
+#define IMGFMT_IS_XVMC(fmt) (((fmt)&IMGFMT_XVMC_MASK)==IMGFMT_XVMC)
+//these are chroma420
+#define IMGFMT_XVMC_MOCO_MPEG2 (IMGFMT_XVMC|0x02)
+#define IMGFMT_XVMC_IDCT_MPEG2 (IMGFMT_XVMC|0x82)
+
+// VDPAU specific format.
+#define IMGFMT_VDPAU 0x1DC80000
+#define IMGFMT_VDPAU_MASK 0xFFFF0000
+#define IMGFMT_IS_VDPAU(fmt) (((fmt)&IMGFMT_VDPAU_MASK)==IMGFMT_VDPAU)
+#define IMGFMT_VDPAU_MPEG1 (IMGFMT_VDPAU|0x01)
+#define IMGFMT_VDPAU_MPEG2 (IMGFMT_VDPAU|0x02)
+#define IMGFMT_VDPAU_H264 (IMGFMT_VDPAU|0x03)
+#define IMGFMT_VDPAU_WMV3 (IMGFMT_VDPAU|0x04)
+#define IMGFMT_VDPAU_VC1 (IMGFMT_VDPAU|0x05)
+#define IMGFMT_VDPAU_MPEG4 (IMGFMT_VDPAU|0x06)
+
+#define IMGFMT_IS_HWACCEL(fmt) (IMGFMT_IS_VDPAU(fmt) || IMGFMT_IS_XVMC(fmt))
+
+typedef struct {
+ void* data;
+ int size;
+ int id; // stream id. usually 0x1E0
+ int timestamp; // pts, 90000 Hz counter based
+} vo_mpegpes_t;
+
+const char *vo_format_name(int format);
+
+/**
+ * Calculates the scale shifts for the chroma planes for planar YUV
+ *
+ * \return bits-per-pixel for format if successful (i.e. format is 3 or 4-planes planar YUV), 0 otherwise
+ */
+int mp_get_chroma_shift(int format, int *x_shift, int *y_shift);
+
+#endif /* MPLAYER_IMG_FORMAT_H */
diff --git a/libavfilter/libmpcodecs/libvo/fastmemcpy.h b/libavfilter/libmpcodecs/libvo/fastmemcpy.h
new file mode 100644
index 0000000000..5a17d0192a
--- /dev/null
+++ b/libavfilter/libmpcodecs/libvo/fastmemcpy.h
@@ -0,0 +1,99 @@
+/*
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with MPlayer; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef MPLAYER_FASTMEMCPY_H
+#define MPLAYER_FASTMEMCPY_H
+
+#include <inttypes.h>
+#include <string.h>
+#include <stddef.h>
+
+void * fast_memcpy(void * to, const void * from, size_t len);
+void * mem2agpcpy(void * to, const void * from, size_t len);
+
+#if ! defined(CONFIG_FASTMEMCPY) || ! (HAVE_MMX || HAVE_MMX2 || HAVE_AMD3DNOW /* || HAVE_SSE || HAVE_SSE2 */)
+#define mem2agpcpy(a,b,c) memcpy(a,b,c)
+#define fast_memcpy(a,b,c) memcpy(a,b,c)
+#endif
+
+static inline void * mem2agpcpy_pic(void * dst, const void * src, int bytesPerLine, int height, int dstStride, int srcStride)
+{
+ int i;
+ void *retval=dst;
+
+ if(dstStride == srcStride)
+ {
+ if (srcStride < 0) {
+ src = (const uint8_t*)src + (height-1)*srcStride;
+ dst = (uint8_t*)dst + (height-1)*dstStride;
+ srcStride = -srcStride;
+ }
+
+ mem2agpcpy(dst, src, srcStride*height);
+ }
+ else
+ {
+ for(i=0; i<height; i++)
+ {
+ mem2agpcpy(dst, src, bytesPerLine);
+ src = (const uint8_t*)src + srcStride;
+ dst = (uint8_t*)dst + dstStride;
+ }
+ }
+
+ return retval;
+}
+
+#define memcpy_pic(d, s, b, h, ds, ss) memcpy_pic2(d, s, b, h, ds, ss, 0)
+#define my_memcpy_pic(d, s, b, h, ds, ss) memcpy_pic2(d, s, b, h, ds, ss, 1)
+
+/**
+ * \param limit2width always skip data between end of line and start of next
+ * instead of copying the full block when strides are the same
+ */
+static inline void * memcpy_pic2(void * dst, const void * src,
+ int bytesPerLine, int height,
+ int dstStride, int srcStride, int limit2width)
+{
+ int i;
+ void *retval=dst;
+
+ if(!limit2width && dstStride == srcStride)
+ {
+ if (srcStride < 0) {
+ src = (const uint8_t*)src + (height-1)*srcStride;
+ dst = (uint8_t*)dst + (height-1)*dstStride;
+ srcStride = -srcStride;
+ }
+
+ fast_memcpy(dst, src, srcStride*height);
+ }
+ else
+ {
+ for(i=0; i<height; i++)
+ {
+ fast_memcpy(dst, src, bytesPerLine);
+ src = (const uint8_t*)src + srcStride;
+ dst = (uint8_t*)dst + dstStride;
+ }
+ }
+
+ return retval;
+}
+
+#endif /* MPLAYER_FASTMEMCPY_H */
diff --git a/libavfilter/libmpcodecs/libvo/video_out.h b/libavfilter/libmpcodecs/libvo/video_out.h
new file mode 100644
index 0000000000..77b0229991
--- /dev/null
+++ b/libavfilter/libmpcodecs/libvo/video_out.h
@@ -0,0 +1,287 @@
+/*
+ * Copyright (C) Aaron Holtzman - Aug 1999
+ * Strongly modified, most parts rewritten: A'rpi/ESP-team - 2000-2001
+ * (C) MPlayer developers
+ *
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef MPLAYER_VIDEO_OUT_H
+#define MPLAYER_VIDEO_OUT_H
+
+#include <inttypes.h>
+#include <stdarg.h>
+
+//#include "sub/font_load.h"
+#include "../img_format.h"
+//#include "vidix/vidix.h"
+
+#define VO_EVENT_EXPOSE 1
+#define VO_EVENT_RESIZE 2
+#define VO_EVENT_KEYPRESS 4
+#define VO_EVENT_REINIT 8
+#define VO_EVENT_MOVE 16
+
+/* Obsolete: VOCTRL_QUERY_VAA 1 */
+/* does the device support the required format */
+#define VOCTRL_QUERY_FORMAT 2
+/* signal a device reset seek */
+#define VOCTRL_RESET 3
+/* true if vo driver can use GUI created windows */
+#define VOCTRL_GUISUPPORT 4
+#define VOCTRL_GUI_NOWINDOW 19
+/* used to switch to fullscreen */
+#define VOCTRL_FULLSCREEN 5
+/* signal a device pause */
+#define VOCTRL_PAUSE 7
+/* start/resume playback */
+#define VOCTRL_RESUME 8
+/* libmpcodecs direct rendering: */
+#define VOCTRL_GET_IMAGE 9
+#define VOCTRL_DRAW_IMAGE 13
+#define VOCTRL_SET_SPU_PALETTE 14
+/* decoding ahead: */
+#define VOCTRL_GET_NUM_FRAMES 10
+#define VOCTRL_GET_FRAME_NUM 11
+#define VOCTRL_SET_FRAME_NUM 12
+#define VOCTRL_GET_PANSCAN 15
+#define VOCTRL_SET_PANSCAN 16
+/* equalizer controls */
+#define VOCTRL_SET_EQUALIZER 17
+#define VOCTRL_GET_EQUALIZER 18
+//#define VOCTRL_GUI_NOWINDOW 19
+/* Frame duplication */
+#define VOCTRL_DUPLICATE_FRAME 20
+// ... 21
+#define VOCTRL_START_SLICE 21
+
+#define VOCTRL_ONTOP 25
+#define VOCTRL_ROOTWIN 26
+#define VOCTRL_BORDER 27
+#define VOCTRL_DRAW_EOSD 28
+#define VOCTRL_GET_EOSD_RES 29
+
+#define VOCTRL_SET_DEINTERLACE 30
+#define VOCTRL_GET_DEINTERLACE 31
+
+#define VOCTRL_UPDATE_SCREENINFO 32
+
+// Vo can be used by xover
+#define VOCTRL_XOVERLAY_SUPPORT 22
+
+#define VOCTRL_XOVERLAY_SET_COLORKEY 24
+typedef struct {
+ uint32_t x11; // The raw x11 color
+ uint16_t r,g,b;
+} mp_colorkey_t;
+
+#define VOCTRL_XOVERLAY_SET_WIN 23
+typedef struct {
+ int x,y;
+ int w,h;
+} mp_win_t;
+
+#define VO_TRUE 1
+#define VO_FALSE 0
+#define VO_ERROR -1
+#define VO_NOTAVAIL -2
+#define VO_NOTIMPL -3
+
+#define VOFLAG_FULLSCREEN 0x01
+#define VOFLAG_MODESWITCHING 0x02
+#define VOFLAG_SWSCALE 0x04
+#define VOFLAG_FLIPPING 0x08
+#define VOFLAG_HIDDEN 0x10 //< Use to create a hidden window
+#define VOFLAG_STEREO 0x20 //< Use to create a stereo-capable window
+#define VOFLAG_XOVERLAY_SUB_VO 0x10000
+
+typedef struct vo_info_s
+{
+ /* driver name ("Matrox Millennium G200/G400" */
+ const char *name;
+ /* short name (for config strings) ("mga") */
+ const char *short_name;
+ /* author ("Aaron Holtzman <aholtzma@ess.engr.uvic.ca>") */
+ const char *author;
+ /* any additional comments */
+ const char *comment;
+} vo_info_t;
+
+typedef struct vo_functions_s
+{
+ const vo_info_t *info;
+ /*
+ * Preinitializes driver (real INITIALIZATION)
+ * arg - currently it's vo_subdevice
+ * returns: zero on successful initialization, non-zero on error.
+ */
+ int (*preinit)(const char *arg);
+ /*
+ * Initialize (means CONFIGURE) the display driver.
+ * params:
+ * width,height: image source size
+ * d_width,d_height: size of the requested window size, just a hint
+ * fullscreen: flag, 0=windowd 1=fullscreen, just a hint
+ * title: window title, if available
+ * format: fourcc of pixel format
+ * returns : zero on successful initialization, non-zero on error.
+ */
+ int (*config)(uint32_t width, uint32_t height, uint32_t d_width,
+ uint32_t d_height, uint32_t fullscreen, char *title,
+ uint32_t format);
+
+ /*
+ * Control interface
+ */
+ int (*control)(uint32_t request, void *data, ...);
+
+ /*
+ * Display a new RGB/BGR frame of the video to the screen.
+ * params:
+ * src[0] - pointer to the image
+ */
+ int (*draw_frame)(uint8_t *src[]);
+
+ /*
+ * Draw a planar YUV slice to the buffer:
+ * params:
+ * src[3] = source image planes (Y,U,V)
+ * stride[3] = source image planes line widths (in bytes)
+ * w,h = width*height of area to be copied (in Y pixels)
+ * x,y = position at the destination image (in Y pixels)
+ */
+ int (*draw_slice)(uint8_t *src[], int stride[], int w,int h, int x,int y);
+
+ /*
+ * Draws OSD to the screen buffer
+ */
+ void (*draw_osd)(void);
+
+ /*
+ * Blit/Flip buffer to the screen. Must be called after each frame!
+ */
+ void (*flip_page)(void);
+
+ /*
+ * This func is called after every frames to handle keyboard and
+ * other events. It's called in PAUSE mode too!
+ */
+ void (*check_events)(void);
+
+ /*
+ * Closes driver. Should restore the original state of the system.
+ */
+ void (*uninit)(void);
+} vo_functions_t;
+
+const vo_functions_t* init_best_video_out(char** vo_list);
+int config_video_out(const vo_functions_t *vo, uint32_t width, uint32_t height,
+ uint32_t d_width, uint32_t d_height, uint32_t flags,
+ char *title, uint32_t format);
+void list_video_out(void);
+
+// NULL terminated array of all drivers
+extern const vo_functions_t* const video_out_drivers[];
+
+extern int vo_flags;
+
+extern int vo_config_count;
+
+extern int xinerama_screen;
+extern int xinerama_x;
+extern int xinerama_y;
+
+// correct resolution/bpp on screen: (should be autodetected by vo_init())
+extern int vo_depthonscreen;
+extern int vo_screenwidth;
+extern int vo_screenheight;
+
+// requested resolution/bpp: (-x -y -bpp options)
+extern int vo_dx;
+extern int vo_dy;
+extern int vo_dwidth;
+extern int vo_dheight;
+extern int vo_dbpp;
+
+extern int vo_grabpointer;
+extern int vo_doublebuffering;
+extern int vo_directrendering;
+extern int vo_vsync;
+extern int vo_fs;
+extern int vo_fsmode;
+extern float vo_panscan;
+extern int vo_adapter_num;
+extern int vo_refresh_rate;
+extern int vo_keepaspect;
+extern int vo_rootwin;
+extern int vo_ontop;
+extern int vo_border;
+
+extern int vo_gamma_gamma;
+extern int vo_gamma_brightness;
+extern int vo_gamma_saturation;
+extern int vo_gamma_contrast;
+extern int vo_gamma_hue;
+extern int vo_gamma_red_intensity;
+extern int vo_gamma_green_intensity;
+extern int vo_gamma_blue_intensity;
+
+extern int vo_nomouse_input;
+extern int enable_mouse_movements;
+
+extern int vo_pts;
+extern float vo_fps;
+
+extern char *vo_subdevice;
+
+extern int vo_colorkey;
+
+extern char *vo_winname;
+extern char *vo_wintitle;
+
+extern int64_t WinID;
+
+typedef struct {
+ float min;
+ float max;
+ } range_t;
+
+float range_max(range_t *r);
+int in_range(range_t *r, float f);
+range_t *str2range(char *s);
+extern char *monitor_hfreq_str;
+extern char *monitor_vfreq_str;
+extern char *monitor_dotclock_str;
+
+struct mp_keymap {
+ int from;
+ int to;
+};
+int lookup_keymap_table(const struct mp_keymap *map, int key);
+struct vo_rect {
+ int left, right, top, bottom, width, height;
+};
+void calc_src_dst_rects(int src_width, int src_height, struct vo_rect *src, struct vo_rect *dst,
+ struct vo_rect *borders, const struct vo_rect *crop);
+void vo_mouse_movement(int posx, int posy);
+
+static inline int aspect_scaling(void)
+{
+ return vo_fs;
+}
+
+#endif /* MPLAYER_VIDEO_OUT_H */
diff --git a/libavfilter/libmpcodecs/mp_image.c b/libavfilter/libmpcodecs/mp_image.c
new file mode 100644
index 0000000000..bd6d33fe0a
--- /dev/null
+++ b/libavfilter/libmpcodecs/mp_image.c
@@ -0,0 +1,200 @@
+/*
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#if HAVE_MALLOC_H
+#include <malloc.h>
+#endif
+
+#include "img_format.h"
+#include "mp_image.h"
+
+#include "libvo/fastmemcpy.h"
+//#include "libavutil/mem.h"
+
+void mp_image_alloc_planes(mp_image_t *mpi) {
+ // IF09 - allocate space for 4. plane delta info - unused
+ if (mpi->imgfmt == IMGFMT_IF09) {
+ mpi->planes[0]=av_malloc(mpi->bpp*mpi->width*(mpi->height+2)/8+
+ mpi->chroma_width*mpi->chroma_height);
+ } else
+ mpi->planes[0]=av_malloc(mpi->bpp*mpi->width*(mpi->height+2)/8);
+ if (mpi->flags&MP_IMGFLAG_PLANAR) {
+ int bpp = IMGFMT_IS_YUVP16(mpi->imgfmt)? 2 : 1;
+ // YV12/I420/YVU9/IF09. feel free to add other planar formats here...
+ mpi->stride[0]=mpi->stride[3]=bpp*mpi->width;
+ if(mpi->num_planes > 2){
+ mpi->stride[1]=mpi->stride[2]=bpp*mpi->chroma_width;
+ if(mpi->flags&MP_IMGFLAG_SWAPPED){
+ // I420/IYUV (Y,U,V)
+ mpi->planes[1]=mpi->planes[0]+mpi->stride[0]*mpi->height;
+ mpi->planes[2]=mpi->planes[1]+mpi->stride[1]*mpi->chroma_height;
+ if (mpi->num_planes > 3)
+ mpi->planes[3]=mpi->planes[2]+mpi->stride[2]*mpi->chroma_height;
+ } else {
+ // YV12,YVU9,IF09 (Y,V,U)
+ mpi->planes[2]=mpi->planes[0]+mpi->stride[0]*mpi->height;
+ mpi->planes[1]=mpi->planes[2]+mpi->stride[1]*mpi->chroma_height;
+ if (mpi->num_planes > 3)
+ mpi->planes[3]=mpi->planes[1]+mpi->stride[1]*mpi->chroma_height;
+ }
+ } else {
+ // NV12/NV21
+ mpi->stride[1]=mpi->chroma_width;
+ mpi->planes[1]=mpi->planes[0]+mpi->stride[0]*mpi->height;
+ }
+ } else {
+ mpi->stride[0]=mpi->width*mpi->bpp/8;
+ if (mpi->flags & MP_IMGFLAG_RGB_PALETTE)
+ mpi->planes[1] = av_malloc(1024);
+ }
+ mpi->flags|=MP_IMGFLAG_ALLOCATED;
+}
+
+mp_image_t* alloc_mpi(int w, int h, unsigned long int fmt) {
+ mp_image_t* mpi = new_mp_image(w,h);
+
+ mp_image_setfmt(mpi,fmt);
+ mp_image_alloc_planes(mpi);
+
+ return mpi;
+}
+
+void copy_mpi(mp_image_t *dmpi, mp_image_t *mpi) {
+ if(mpi->flags&MP_IMGFLAG_PLANAR){
+ memcpy_pic(dmpi->planes[0],mpi->planes[0], mpi->w, mpi->h,
+ dmpi->stride[0],mpi->stride[0]);
+ memcpy_pic(dmpi->planes[1],mpi->planes[1], mpi->chroma_width, mpi->chroma_height,
+ dmpi->stride[1],mpi->stride[1]);
+ memcpy_pic(dmpi->planes[2], mpi->planes[2], mpi->chroma_width, mpi->chroma_height,
+ dmpi->stride[2],mpi->stride[2]);
+ } else {
+ memcpy_pic(dmpi->planes[0],mpi->planes[0],
+ mpi->w*(dmpi->bpp/8), mpi->h,
+ dmpi->stride[0],mpi->stride[0]);
+ }
+}
+
+void mp_image_setfmt(mp_image_t* mpi,unsigned int out_fmt){
+ mpi->flags&=~(MP_IMGFLAG_PLANAR|MP_IMGFLAG_YUV|MP_IMGFLAG_SWAPPED);
+ mpi->imgfmt=out_fmt;
+ // compressed formats
+ if(out_fmt == IMGFMT_MPEGPES ||
+ out_fmt == IMGFMT_ZRMJPEGNI || out_fmt == IMGFMT_ZRMJPEGIT || out_fmt == IMGFMT_ZRMJPEGIB ||
+ IMGFMT_IS_HWACCEL(out_fmt)){
+ mpi->bpp=0;
+ return;
+ }
+ mpi->num_planes=1;
+ if (IMGFMT_IS_RGB(out_fmt)) {
+ if (IMGFMT_RGB_DEPTH(out_fmt) < 8 && !(out_fmt&128))
+ mpi->bpp = IMGFMT_RGB_DEPTH(out_fmt);
+ else
+ mpi->bpp=(IMGFMT_RGB_DEPTH(out_fmt)+7)&(~7);
+ return;
+ }
+ if (IMGFMT_IS_BGR(out_fmt)) {
+ if (IMGFMT_BGR_DEPTH(out_fmt) < 8 && !(out_fmt&128))
+ mpi->bpp = IMGFMT_BGR_DEPTH(out_fmt);
+ else
+ mpi->bpp=(IMGFMT_BGR_DEPTH(out_fmt)+7)&(~7);
+ mpi->flags|=MP_IMGFLAG_SWAPPED;
+ return;
+ }
+ mpi->flags|=MP_IMGFLAG_YUV;
+ mpi->num_planes=3;
+ if (mp_get_chroma_shift(out_fmt, NULL, NULL)) {
+ mpi->flags|=MP_IMGFLAG_PLANAR;
+ mpi->bpp = mp_get_chroma_shift(out_fmt, &mpi->chroma_x_shift, &mpi->chroma_y_shift);
+ mpi->chroma_width = mpi->width >> mpi->chroma_x_shift;
+ mpi->chroma_height = mpi->height >> mpi->chroma_y_shift;
+ }
+ switch(out_fmt){
+ case IMGFMT_I420:
+ case IMGFMT_IYUV:
+ mpi->flags|=MP_IMGFLAG_SWAPPED;
+ case IMGFMT_YV12:
+ return;
+ case IMGFMT_420A:
+ case IMGFMT_IF09:
+ mpi->num_planes=4;
+ case IMGFMT_YVU9:
+ case IMGFMT_444P:
+ case IMGFMT_422P:
+ case IMGFMT_411P:
+ case IMGFMT_440P:
+ case IMGFMT_444P16_LE:
+ case IMGFMT_444P16_BE:
+ case IMGFMT_422P16_LE:
+ case IMGFMT_422P16_BE:
+ case IMGFMT_420P16_LE:
+ case IMGFMT_420P16_BE:
+ return;
+ case IMGFMT_Y800:
+ case IMGFMT_Y8:
+ /* they're planar ones, but for easier handling use them as packed */
+ mpi->flags&=~MP_IMGFLAG_PLANAR;
+ mpi->num_planes=1;
+ return;
+ case IMGFMT_UYVY:
+ mpi->flags|=MP_IMGFLAG_SWAPPED;
+ case IMGFMT_YUY2:
+ mpi->bpp=16;
+ mpi->num_planes=1;
+ return;
+ case IMGFMT_NV12:
+ mpi->flags|=MP_IMGFLAG_SWAPPED;
+ case IMGFMT_NV21:
+ mpi->flags|=MP_IMGFLAG_PLANAR;
+ mpi->bpp=12;
+ mpi->num_planes=2;
+ mpi->chroma_width=(mpi->width>>0);
+ mpi->chroma_height=(mpi->height>>1);
+ mpi->chroma_x_shift=0;
+ mpi->chroma_y_shift=1;
+ return;
+ }
+ mp_msg(MSGT_DECVIDEO,MSGL_WARN,"mp_image: unknown out_fmt: 0x%X\n",out_fmt);
+ mpi->bpp=0;
+}
+
+mp_image_t* new_mp_image(int w,int h){
+ mp_image_t* mpi = malloc(sizeof(mp_image_t));
+ if(!mpi) return NULL; // error!
+ memset(mpi,0,sizeof(mp_image_t));
+ mpi->width=mpi->w=w;
+ mpi->height=mpi->h=h;
+ return mpi;
+}
+
+void free_mp_image(mp_image_t* mpi){
+ if(!mpi) return;
+ if(mpi->flags&MP_IMGFLAG_ALLOCATED){
+ /* becouse we allocate the whole image in once */
+ av_free(mpi->planes[0]);
+ if (mpi->flags & MP_IMGFLAG_RGB_PALETTE)
+ av_free(mpi->planes[1]);
+ }
+ free(mpi);
+}
+
diff --git a/libavfilter/libmpcodecs/mp_image.h b/libavfilter/libmpcodecs/mp_image.h
new file mode 100644
index 0000000000..50d3fa19a6
--- /dev/null
+++ b/libavfilter/libmpcodecs/mp_image.h
@@ -0,0 +1,150 @@
+/*
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef MPLAYER_MP_IMAGE_H
+#define MPLAYER_MP_IMAGE_H
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#undef printf //FIXME
+#undef fprintf //FIXME
+#include "mp_msg.h"
+#include "libavutil/avutil.h"
+#include "libavutil/avassert.h"
+#undef realloc
+#undef malloc
+#undef free
+#undef rand
+#undef srand
+#undef printf
+#undef strncpy
+#define ASMALIGN(ZEROBITS) ".p2align " #ZEROBITS "\n\t"
+
+
+//--------- codec's requirements (filled by the codec/vf) ---------
+
+//--- buffer content restrictions:
+// set if buffer content shouldn't be modified:
+#define MP_IMGFLAG_PRESERVE 0x01
+// set if buffer content will be READ for next frame's MC: (I/P mpeg frames)
+#define MP_IMGFLAG_READABLE 0x02
+
+//--- buffer width/stride/plane restrictions: (used for direct rendering)
+// stride _have_to_ be aligned to MB boundary: [for DR restrictions]
+#define MP_IMGFLAG_ACCEPT_ALIGNED_STRIDE 0x4
+// stride should be aligned to MB boundary: [for buffer allocation]
+#define MP_IMGFLAG_PREFER_ALIGNED_STRIDE 0x8
+// codec accept any stride (>=width):
+#define MP_IMGFLAG_ACCEPT_STRIDE 0x10
+// codec accept any width (width*bpp=stride -> stride%bpp==0) (>=width):
+#define MP_IMGFLAG_ACCEPT_WIDTH 0x20
+//--- for planar formats only:
+// uses only stride[0], and stride[1]=stride[2]=stride[0]>>mpi->chroma_x_shift
+#define MP_IMGFLAG_COMMON_STRIDE 0x40
+// uses only planes[0], and calculates planes[1,2] from width,height,imgfmt
+#define MP_IMGFLAG_COMMON_PLANE 0x80
+
+#define MP_IMGFLAGMASK_RESTRICTIONS 0xFF
+
+//--------- color info (filled by mp_image_setfmt() ) -----------
+// set if number of planes > 1
+#define MP_IMGFLAG_PLANAR 0x100
+// set if it's YUV colorspace
+#define MP_IMGFLAG_YUV 0x200
+// set if it's swapped (BGR or YVU) plane/byteorder
+#define MP_IMGFLAG_SWAPPED 0x400
+// set if you want memory for palette allocated and managed by vf_get_image etc.
+#define MP_IMGFLAG_RGB_PALETTE 0x800
+
+#define MP_IMGFLAGMASK_COLORS 0xF00
+
+// codec uses drawing/rendering callbacks (draw_slice()-like thing, DR method 2)
+// [the codec will set this flag if it supports callbacks, and the vo _may_
+// clear it in get_image() if draw_slice() not implemented]
+#define MP_IMGFLAG_DRAW_CALLBACK 0x1000
+// set if it's in video buffer/memory: [set by vo/vf's get_image() !!!]
+#define MP_IMGFLAG_DIRECT 0x2000
+// set if buffer is allocated (used in destination images):
+#define MP_IMGFLAG_ALLOCATED 0x4000
+
+// buffer type was printed (do NOT set this flag - it's for INTERNAL USE!!!)
+#define MP_IMGFLAG_TYPE_DISPLAYED 0x8000
+
+// codec doesn't support any form of direct rendering - it has own buffer
+// allocation. so we just export its buffer pointers:
+#define MP_IMGTYPE_EXPORT 0
+// codec requires a static WO buffer, but it does only partial updates later:
+#define MP_IMGTYPE_STATIC 1
+// codec just needs some WO memory, where it writes/copies the whole frame to:
+#define MP_IMGTYPE_TEMP 2
+// I+P type, requires 2+ independent static R/W buffers
+#define MP_IMGTYPE_IP 3
+// I+P+B type, requires 2+ independent static R/W and 1+ temp WO buffers
+#define MP_IMGTYPE_IPB 4
+// Upper 16 bits give desired buffer number, -1 means get next available
+#define MP_IMGTYPE_NUMBERED 5
+// Doesn't need any buffer, incomplete image (probably a first field only)
+// we need this type to be able to differentiate between half frames and
+// all other cases
+#define MP_IMGTYPE_INCOMPLETE 6
+
+#define MP_MAX_PLANES 4
+
+#define MP_IMGFIELD_ORDERED 0x01
+#define MP_IMGFIELD_TOP_FIRST 0x02
+#define MP_IMGFIELD_REPEAT_FIRST 0x04
+#define MP_IMGFIELD_TOP 0x08
+#define MP_IMGFIELD_BOTTOM 0x10
+#define MP_IMGFIELD_INTERLACED 0x20
+
+typedef struct mp_image {
+ unsigned int flags;
+ unsigned char type;
+ int number;
+ unsigned char bpp; // bits/pixel. NOT depth! for RGB it will be n*8
+ unsigned int imgfmt;
+ int width,height; // stored dimensions
+ int x,y,w,h; // visible dimensions
+ unsigned char* planes[MP_MAX_PLANES];
+ int stride[MP_MAX_PLANES];
+ char * qscale;
+ int qstride;
+ int pict_type; // 0->unknown, 1->I, 2->P, 3->B
+ int fields;
+ int qscale_type; // 0->mpeg1/4/h263, 1->mpeg2
+ int num_planes;
+ /* these are only used by planar formats Y,U(Cb),V(Cr) */
+ int chroma_width;
+ int chroma_height;
+ int chroma_x_shift; // horizontal
+ int chroma_y_shift; // vertical
+ int usage_count;
+ /* for private use by filter or vo driver (to store buffer id or dmpi) */
+ void* priv;
+} mp_image_t;
+
+void mp_image_setfmt(mp_image_t* mpi,unsigned int out_fmt);
+mp_image_t* new_mp_image(int w,int h);
+void free_mp_image(mp_image_t* mpi);
+
+mp_image_t* alloc_mpi(int w, int h, unsigned long int fmt);
+void mp_image_alloc_planes(mp_image_t *mpi);
+void copy_mpi(mp_image_t *dmpi, mp_image_t *mpi);
+
+#endif /* MPLAYER_MP_IMAGE_H */
diff --git a/libavfilter/libmpcodecs/mp_msg.h b/libavfilter/libmpcodecs/mp_msg.h
new file mode 100644
index 0000000000..7b6405b883
--- /dev/null
+++ b/libavfilter/libmpcodecs/mp_msg.h
@@ -0,0 +1,164 @@
+/*
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef MPLAYER_MP_MSG_H
+#define MPLAYER_MP_MSG_H
+
+#include <stdarg.h>
+
+// defined in mplayer.c and mencoder.c
+extern int verbose;
+
+// verbosity elevel:
+
+/* Only messages level MSGL_FATAL-MSGL_STATUS should be translated,
+ * messages level MSGL_V and above should not be translated. */
+
+#define MSGL_FATAL 0 // will exit/abort
+#define MSGL_ERR 1 // continues
+#define MSGL_WARN 2 // only warning
+#define MSGL_HINT 3 // short help message
+#define MSGL_INFO 4 // -quiet
+#define MSGL_STATUS 5 // v=0
+#define MSGL_V 6 // v=1
+#define MSGL_DBG2 7 // v=2
+#define MSGL_DBG3 8 // v=3
+#define MSGL_DBG4 9 // v=4
+#define MSGL_DBG5 10 // v=5
+
+#define MSGL_FIXME 1 // for conversions from printf where the appropriate MSGL is not known; set equal to ERR for obtrusiveness
+#define MSGT_FIXME 0 // for conversions from printf where the appropriate MSGT is not known; set equal to GLOBAL for obtrusiveness
+
+// code/module:
+
+#define MSGT_GLOBAL 0 // common player stuff errors
+#define MSGT_CPLAYER 1 // console player (mplayer.c)
+#define MSGT_GPLAYER 2 // gui player
+
+#define MSGT_VO 3 // libvo
+#define MSGT_AO 4 // libao
+
+#define MSGT_DEMUXER 5 // demuxer.c (general stuff)
+#define MSGT_DS 6 // demux stream (add/read packet etc)
+#define MSGT_DEMUX 7 // fileformat-specific stuff (demux_*.c)
+#define MSGT_HEADER 8 // fileformat-specific header (*header.c)
+
+#define MSGT_AVSYNC 9 // mplayer.c timer stuff
+#define MSGT_AUTOQ 10 // mplayer.c auto-quality stuff
+
+#define MSGT_CFGPARSER 11 // cfgparser.c
+
+#define MSGT_DECAUDIO 12 // av decoder
+#define MSGT_DECVIDEO 13
+
+#define MSGT_SEEK 14 // seeking code
+#define MSGT_WIN32 15 // win32 dll stuff
+#define MSGT_OPEN 16 // open.c (stream opening)
+#define MSGT_DVD 17 // open.c (DVD init/read/seek)
+
+#define MSGT_PARSEES 18 // parse_es.c (mpeg stream parser)
+#define MSGT_LIRC 19 // lirc_mp.c and input lirc driver
+
+#define MSGT_STREAM 20 // stream.c
+#define MSGT_CACHE 21 // cache2.c
+
+#define MSGT_MENCODER 22
+
+#define MSGT_XACODEC 23 // XAnim codecs
+
+#define MSGT_TV 24 // TV input subsystem
+
+#define MSGT_OSDEP 25 // OS-dependent parts
+
+#define MSGT_SPUDEC 26 // spudec.c
+
+#define MSGT_PLAYTREE 27 // Playtree handeling (playtree.c, playtreeparser.c)
+
+#define MSGT_INPUT 28
+
+#define MSGT_VFILTER 29
+
+#define MSGT_OSD 30
+
+#define MSGT_NETWORK 31
+
+#define MSGT_CPUDETECT 32
+
+#define MSGT_CODECCFG 33
+
+#define MSGT_SWS 34
+
+#define MSGT_VOBSUB 35
+#define MSGT_SUBREADER 36
+
+#define MSGT_AFILTER 37 // Audio filter messages
+
+#define MSGT_NETST 38 // Netstream
+
+#define MSGT_MUXER 39 // muxer layer
+
+#define MSGT_OSD_MENU 40
+
+#define MSGT_IDENTIFY 41 // -identify output
+
+#define MSGT_RADIO 42
+
+#define MSGT_ASS 43 // libass messages
+
+#define MSGT_LOADER 44 // dll loader messages
+
+#define MSGT_STATUSLINE 45 // playback/encoding status line
+
+#define MSGT_TELETEXT 46 // Teletext decoder
+
+#define MSGT_MAX 64
+
+
+extern char *mp_msg_charset;
+extern int mp_msg_color;
+extern int mp_msg_module;
+
+extern int mp_msg_levels[MSGT_MAX];
+extern int mp_msg_level_all;
+
+
+void mp_msg_init(void);
+int mp_msg_test(int mod, int lev);
+
+#include "config.h"
+
+void mp_msg_va(int mod, int lev, const char *format, va_list va);
+#ifdef __GNUC__
+void mp_msg(int mod, int lev, const char *format, ... ) __attribute__ ((format (printf, 3, 4)));
+# ifdef MP_DEBUG
+# define mp_dbg(mod,lev, args... ) mp_msg(mod, lev, ## args )
+# else
+# define mp_dbg(mod,lev, args... ) /* only useful for developers */
+# endif
+#else // not GNU C
+void mp_msg(int mod, int lev, const char *format, ... );
+# ifdef MP_DEBUG
+# define mp_dbg(mod,lev, ... ) mp_msg(mod, lev, __VA_ARGS__)
+# else
+# define mp_dbg(mod,lev, ... ) /* only useful for developers */
+# endif
+#endif /* __GNUC__ */
+
+const char* filename_recode(const char* filename);
+
+#endif /* MPLAYER_MP_MSG_H */
diff --git a/libavfilter/libmpcodecs/mpbswap.h b/libavfilter/libmpcodecs/mpbswap.h
new file mode 100644
index 0000000000..28f7337841
--- /dev/null
+++ b/libavfilter/libmpcodecs/mpbswap.h
@@ -0,0 +1,34 @@
+/*
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef MPLAYER_MPBSWAP_H
+#define MPLAYER_MPBSWAP_H
+
+#include <sys/types.h>
+#include "config.h"
+#include "libavutil/bswap.h"
+
+#define bswap_16(v) av_bswap16(v)
+#define bswap_32(v) av_bswap32(v)
+#define le2me_16(v) av_le2ne16(v)
+#define le2me_32(v) av_le2ne32(v)
+#define le2me_64(v) av_le2ne64(v)
+#define be2me_16(v) av_be2ne16(v)
+#define be2me_32(v) av_be2ne32(v)
+
+#endif /* MPLAYER_MPBSWAP_H */
diff --git a/libavfilter/libmpcodecs/mpc_info.h b/libavfilter/libmpcodecs/mpc_info.h
new file mode 100644
index 0000000000..8554699120
--- /dev/null
+++ b/libavfilter/libmpcodecs/mpc_info.h
@@ -0,0 +1,43 @@
+/*
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef MPLAYER_MPC_INFO_H
+#define MPLAYER_MPC_INFO_H
+
+typedef struct mp_codec_info_s
+{
+ /* codec long name ("Autodesk FLI/FLC Animation decoder" */
+ const char *name;
+ /* short name (same as driver name in codecs.conf) ("dshow") */
+ const char *short_name;
+ /* interface author/maintainer */
+ const char *maintainer;
+ /* codec author ("Aaron Holtzman <aholtzma@ess.engr.uvic.ca>") */
+ const char *author;
+ /* any additional comments */
+ const char *comment;
+} mp_codec_info_t;
+
+#define CONTROL_OK 1
+#define CONTROL_TRUE 1
+#define CONTROL_FALSE 0
+#define CONTROL_UNKNOWN -1
+#define CONTROL_ERROR -2
+#define CONTROL_NA -3
+
+#endif /* MPLAYER_MPC_INFO_H */
diff --git a/libavfilter/libmpcodecs/pullup.c b/libavfilter/libmpcodecs/pullup.c
new file mode 100644
index 0000000000..c1c4e0f5ca
--- /dev/null
+++ b/libavfilter/libmpcodecs/pullup.c
@@ -0,0 +1,822 @@
+/*
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "config.h"
+#include "pullup.h"
+#include "cpudetect.h"
+
+
+
+#if ARCH_X86
+#if HAVE_MMX
+static int diff_y_mmx(unsigned char *a, unsigned char *b, int s)
+{
+ int ret;
+ __asm__ volatile (
+ "movl $4, %%ecx \n\t"
+ "pxor %%mm4, %%mm4 \n\t"
+ "pxor %%mm7, %%mm7 \n\t"
+
+ "1: \n\t"
+
+ "movq (%%"REG_S"), %%mm0 \n\t"
+ "movq (%%"REG_S"), %%mm2 \n\t"
+ "add %%"REG_a", %%"REG_S" \n\t"
+ "movq (%%"REG_D"), %%mm1 \n\t"
+ "add %%"REG_a", %%"REG_D" \n\t"
+ "psubusb %%mm1, %%mm2 \n\t"
+ "psubusb %%mm0, %%mm1 \n\t"
+ "movq %%mm2, %%mm0 \n\t"
+ "movq %%mm1, %%mm3 \n\t"
+ "punpcklbw %%mm7, %%mm0 \n\t"
+ "punpcklbw %%mm7, %%mm1 \n\t"
+ "punpckhbw %%mm7, %%mm2 \n\t"
+ "punpckhbw %%mm7, %%mm3 \n\t"
+ "paddw %%mm0, %%mm4 \n\t"
+ "paddw %%mm1, %%mm4 \n\t"
+ "paddw %%mm2, %%mm4 \n\t"
+ "paddw %%mm3, %%mm4 \n\t"
+
+ "decl %%ecx \n\t"
+ "jnz 1b \n\t"
+
+ "movq %%mm4, %%mm3 \n\t"
+ "punpcklwd %%mm7, %%mm4 \n\t"
+ "punpckhwd %%mm7, %%mm3 \n\t"
+ "paddd %%mm4, %%mm3 \n\t"
+ "movd %%mm3, %%eax \n\t"
+ "psrlq $32, %%mm3 \n\t"
+ "movd %%mm3, %%edx \n\t"
+ "addl %%edx, %%eax \n\t"
+ "emms \n\t"
+ : "=a" (ret)
+ : "S" (a), "D" (b), "a" (s)
+ : "%ecx", "%edx"
+ );
+ return ret;
+}
+
+static int licomb_y_mmx(unsigned char *a, unsigned char *b, int s)
+{
+ int ret;
+ __asm__ volatile (
+ "movl $4, %%ecx \n\t"
+ "pxor %%mm6, %%mm6 \n\t"
+ "pxor %%mm7, %%mm7 \n\t"
+ "sub %%"REG_a", %%"REG_D" \n\t"
+
+ "2: \n\t"
+
+ "movq (%%"REG_D"), %%mm0 \n\t"
+ "movq (%%"REG_D"), %%mm1 \n\t"
+ "punpcklbw %%mm7, %%mm0 \n\t"
+ "movq (%%"REG_D",%%"REG_a"), %%mm2 \n\t"
+ "punpcklbw %%mm7, %%mm1 \n\t"
+ "punpcklbw %%mm7, %%mm2 \n\t"
+ "paddw %%mm0, %%mm0 \n\t"
+ "paddw %%mm2, %%mm1 \n\t"
+ "movq %%mm0, %%mm2 \n\t"
+ "psubusw %%mm1, %%mm0 \n\t"
+ "psubusw %%mm2, %%mm1 \n\t"
+ "paddw %%mm0, %%mm6 \n\t"
+ "paddw %%mm1, %%mm6 \n\t"
+
+ "movq (%%"REG_S"), %%mm0 \n\t"
+ "movq (%%"REG_D"), %%mm1 \n\t"
+ "punpckhbw %%mm7, %%mm0 \n\t"
+ "movq (%%"REG_D",%%"REG_a"), %%mm2 \n\t"
+ "punpckhbw %%mm7, %%mm1 \n\t"
+ "punpckhbw %%mm7, %%mm2 \n\t"
+ "paddw %%mm0, %%mm0 \n\t"
+ "paddw %%mm2, %%mm1 \n\t"
+ "movq %%mm0, %%mm2 \n\t"
+ "psubusw %%mm1, %%mm0 \n\t"
+ "psubusw %%mm2, %%mm1 \n\t"
+ "paddw %%mm0, %%mm6 \n\t"
+ "paddw %%mm1, %%mm6 \n\t"
+
+ "movq (%%"REG_D",%%"REG_a"), %%mm0 \n\t"
+ "movq (%%"REG_S"), %%mm1 \n\t"
+ "punpcklbw %%mm7, %%mm0 \n\t"
+ "movq (%%"REG_S",%%"REG_a"), %%mm2 \n\t"
+ "punpcklbw %%mm7, %%mm1 \n\t"
+ "punpcklbw %%mm7, %%mm2 \n\t"
+ "paddw %%mm0, %%mm0 \n\t"
+ "paddw %%mm2, %%mm1 \n\t"
+ "movq %%mm0, %%mm2 \n\t"
+ "psubusw %%mm1, %%mm0 \n\t"
+ "psubusw %%mm2, %%mm1 \n\t"
+ "paddw %%mm0, %%mm6 \n\t"
+ "paddw %%mm1, %%mm6 \n\t"
+
+ "movq (%%"REG_D",%%"REG_a"), %%mm0 \n\t"
+ "movq (%%"REG_S"), %%mm1 \n\t"
+ "punpckhbw %%mm7, %%mm0 \n\t"
+ "movq (%%"REG_S",%%"REG_a"), %%mm2 \n\t"
+ "punpckhbw %%mm7, %%mm1 \n\t"
+ "punpckhbw %%mm7, %%mm2 \n\t"
+ "paddw %%mm0, %%mm0 \n\t"
+ "paddw %%mm2, %%mm1 \n\t"
+ "movq %%mm0, %%mm2 \n\t"
+ "psubusw %%mm1, %%mm0 \n\t"
+ "psubusw %%mm2, %%mm1 \n\t"
+ "paddw %%mm0, %%mm6 \n\t"
+ "paddw %%mm1, %%mm6 \n\t"
+
+ "add %%"REG_a", %%"REG_S" \n\t"
+ "add %%"REG_a", %%"REG_D" \n\t"
+ "decl %%ecx \n\t"
+ "jnz 2b \n\t"
+
+ "movq %%mm6, %%mm5 \n\t"
+ "punpcklwd %%mm7, %%mm6 \n\t"
+ "punpckhwd %%mm7, %%mm5 \n\t"
+ "paddd %%mm6, %%mm5 \n\t"
+ "movd %%mm5, %%eax \n\t"
+ "psrlq $32, %%mm5 \n\t"
+ "movd %%mm5, %%edx \n\t"
+ "addl %%edx, %%eax \n\t"
+
+ "emms \n\t"
+ : "=a" (ret)
+ : "S" (a), "D" (b), "a" (s)
+ : "%ecx", "%edx"
+ );
+ return ret;
+}
+
+static int var_y_mmx(unsigned char *a, unsigned char *b, int s)
+{
+ int ret;
+ __asm__ volatile (
+ "movl $3, %%ecx \n\t"
+ "pxor %%mm4, %%mm4 \n\t"
+ "pxor %%mm7, %%mm7 \n\t"
+
+ "1: \n\t"
+
+ "movq (%%"REG_S"), %%mm0 \n\t"
+ "movq (%%"REG_S"), %%mm2 \n\t"
+ "movq (%%"REG_S",%%"REG_a"), %%mm1 \n\t"
+ "add %%"REG_a", %%"REG_S" \n\t"
+ "psubusb %%mm1, %%mm2 \n\t"
+ "psubusb %%mm0, %%mm1 \n\t"
+ "movq %%mm2, %%mm0 \n\t"
+ "movq %%mm1, %%mm3 \n\t"
+ "punpcklbw %%mm7, %%mm0 \n\t"
+ "punpcklbw %%mm7, %%mm1 \n\t"
+ "punpckhbw %%mm7, %%mm2 \n\t"
+ "punpckhbw %%mm7, %%mm3 \n\t"
+ "paddw %%mm0, %%mm4 \n\t"
+ "paddw %%mm1, %%mm4 \n\t"
+ "paddw %%mm2, %%mm4 \n\t"
+ "paddw %%mm3, %%mm4 \n\t"
+
+ "decl %%ecx \n\t"
+ "jnz 1b \n\t"
+
+ "movq %%mm4, %%mm3 \n\t"
+ "punpcklwd %%mm7, %%mm4 \n\t"
+ "punpckhwd %%mm7, %%mm3 \n\t"
+ "paddd %%mm4, %%mm3 \n\t"
+ "movd %%mm3, %%eax \n\t"
+ "psrlq $32, %%mm3 \n\t"
+ "movd %%mm3, %%edx \n\t"
+ "addl %%edx, %%eax \n\t"
+ "emms \n\t"
+ : "=a" (ret)
+ : "S" (a), "a" (s)
+ : "%ecx", "%edx"
+ );
+ return 4*ret;
+}
+#endif
+#endif
+
+#define ABS(a) (((a)^((a)>>31))-((a)>>31))
+
+static int diff_y(unsigned char *a, unsigned char *b, int s)
+{
+ int i, j, diff=0;
+ for (i=4; i; i--) {
+ for (j=0; j<8; j++) diff += ABS(a[j]-b[j]);
+ a+=s; b+=s;
+ }
+ return diff;
+}
+
+static int licomb_y(unsigned char *a, unsigned char *b, int s)
+{
+ int i, j, diff=0;
+ for (i=4; i; i--) {
+ for (j=0; j<8; j++)
+ diff += ABS((a[j]<<1) - b[j-s] - b[j])
+ + ABS((b[j]<<1) - a[j] - a[j+s]);
+ a+=s; b+=s;
+ }
+ return diff;
+}
+
+#if 0
+static int qpcomb_y(unsigned char *a, unsigned char *b, int s)
+{
+ int i, j, diff=0;
+ for (i=4; i; i--) {
+ for (j=0; j<8; j++)
+ diff += ABS(a[j] - 3*b[j-s] + 3*a[j+s] - b[j]);
+ a+=s; b+=s;
+ }
+ return diff;
+}
+
+static int licomb_y_test(unsigned char *a, unsigned char *b, int s)
+{
+ int c = licomb_y(a,b,s);
+ int m = licomb_y_mmx(a,b,s);
+ if (c != m) printf("%d != %d\n", c, m);
+ return m;
+}
+#endif
+
+static int var_y(unsigned char *a, unsigned char *b, int s)
+{
+ int i, j, var=0;
+ for (i=3; i; i--) {
+ for (j=0; j<8; j++) {
+ var += ABS(a[j]-a[j+s]);
+ }
+ a+=s; b+=s;
+ }
+ return 4*var; /* match comb scaling */
+}
+
+
+
+
+
+
+
+
+
+static void alloc_buffer(struct pullup_context *c, struct pullup_buffer *b)
+{
+ int i;
+ if (b->planes) return;
+ b->planes = calloc(c->nplanes, sizeof(unsigned char *));
+ for (i = 0; i < c->nplanes; i++) {
+ b->planes[i] = malloc(c->h[i]*c->stride[i]);
+ /* Deal with idiotic 128=0 for chroma: */
+ memset(b->planes[i], c->background[i], c->h[i]*c->stride[i]);
+ }
+}
+
+struct pullup_buffer *pullup_lock_buffer(struct pullup_buffer *b, int parity)
+{
+ if (!b) return 0;
+ if ((parity+1) & 1) b->lock[0]++;
+ if ((parity+1) & 2) b->lock[1]++;
+ return b;
+}
+
+void pullup_release_buffer(struct pullup_buffer *b, int parity)
+{
+ if (!b) return;
+ if ((parity+1) & 1) b->lock[0]--;
+ if ((parity+1) & 2) b->lock[1]--;
+}
+
+struct pullup_buffer *pullup_get_buffer(struct pullup_context *c, int parity)
+{
+ int i;
+
+ /* Try first to get the sister buffer for the previous field */
+ if (parity < 2 && c->last && parity != c->last->parity
+ && !c->last->buffer->lock[parity]) {
+ alloc_buffer(c, c->last->buffer);
+ return pullup_lock_buffer(c->last->buffer, parity);
+ }
+
+ /* Prefer a buffer with both fields open */
+ for (i = 0; i < c->nbuffers; i++) {
+ if (c->buffers[i].lock[0]) continue;
+ if (c->buffers[i].lock[1]) continue;
+ alloc_buffer(c, &c->buffers[i]);
+ return pullup_lock_buffer(&c->buffers[i], parity);
+ }
+
+ if (parity == 2) return 0;
+
+ /* Search for any half-free buffer */
+ for (i = 0; i < c->nbuffers; i++) {
+ if (((parity+1) & 1) && c->buffers[i].lock[0]) continue;
+ if (((parity+1) & 2) && c->buffers[i].lock[1]) continue;
+ alloc_buffer(c, &c->buffers[i]);
+ return pullup_lock_buffer(&c->buffers[i], parity);
+ }
+
+ return 0;
+}
+
+
+
+
+
+
+static void compute_metric(struct pullup_context *c,
+ struct pullup_field *fa, int pa,
+ struct pullup_field *fb, int pb,
+ int (*func)(unsigned char *, unsigned char *, int), int *dest)
+{
+ unsigned char *a, *b;
+ int x, y;
+ int mp = c->metric_plane;
+ int xstep = c->bpp[mp];
+ int ystep = c->stride[mp]<<3;
+ int s = c->stride[mp]<<1; /* field stride */
+ int w = c->metric_w*xstep;
+
+ if (!fa->buffer || !fb->buffer) return;
+
+ /* Shortcut for duplicate fields (e.g. from RFF flag) */
+ if (fa->buffer == fb->buffer && pa == pb) {
+ memset(dest, 0, c->metric_len * sizeof(int));
+ return;
+ }
+
+ a = fa->buffer->planes[mp] + pa * c->stride[mp] + c->metric_offset;
+ b = fb->buffer->planes[mp] + pb * c->stride[mp] + c->metric_offset;
+
+ for (y = c->metric_h; y; y--) {
+ for (x = 0; x < w; x += xstep) {
+ *dest++ = func(a + x, b + x, s);
+ }
+ a += ystep; b += ystep;
+ }
+}
+
+
+
+
+
+static void alloc_metrics(struct pullup_context *c, struct pullup_field *f)
+{
+ f->diffs = calloc(c->metric_len, sizeof(int));
+ f->comb = calloc(c->metric_len, sizeof(int));
+ f->var = calloc(c->metric_len, sizeof(int));
+ /* add more metrics here as needed */
+}
+
+static struct pullup_field *make_field_queue(struct pullup_context *c, int len)
+{
+ struct pullup_field *head, *f;
+ f = head = calloc(1, sizeof(struct pullup_field));
+ alloc_metrics(c, f);
+ for (; len > 0; len--) {
+ f->next = calloc(1, sizeof(struct pullup_field));
+ f->next->prev = f;
+ f = f->next;
+ alloc_metrics(c, f);
+ }
+ f->next = head;
+ head->prev = f;
+ return head;
+}
+
+static void check_field_queue(struct pullup_context *c)
+{
+ if (c->head->next == c->first) {
+ struct pullup_field *f = calloc(1, sizeof(struct pullup_field));
+ alloc_metrics(c, f);
+ f->prev = c->head;
+ f->next = c->first;
+ c->head->next = f;
+ c->first->prev = f;
+ }
+}
+
+void pullup_submit_field(struct pullup_context *c, struct pullup_buffer *b, int parity)
+{
+ struct pullup_field *f;
+
+ /* Grow the circular list if needed */
+ check_field_queue(c);
+
+ /* Cannot have two fields of same parity in a row; drop the new one */
+ if (c->last && c->last->parity == parity) return;
+
+ f = c->head;
+ f->parity = parity;
+ f->buffer = pullup_lock_buffer(b, parity);
+ f->flags = 0;
+ f->breaks = 0;
+ f->affinity = 0;
+
+ compute_metric(c, f, parity, f->prev->prev, parity, c->diff, f->diffs);
+ compute_metric(c, parity?f->prev:f, 0, parity?f:f->prev, 1, c->comb, f->comb);
+ compute_metric(c, f, parity, f, -1, c->var, f->var);
+
+ /* Advance the circular list */
+ if (!c->first) c->first = c->head;
+ c->last = c->head;
+ c->head = c->head->next;
+}
+
+void pullup_flush_fields(struct pullup_context *c)
+{
+ struct pullup_field *f;
+
+ for (f = c->first; f && f != c->head; f = f->next) {
+ pullup_release_buffer(f->buffer, f->parity);
+ f->buffer = 0;
+ }
+ c->first = c->last = 0;
+}
+
+
+
+
+
+
+
+
+#define F_HAVE_BREAKS 1
+#define F_HAVE_AFFINITY 2
+
+
+#define BREAK_LEFT 1
+#define BREAK_RIGHT 2
+
+
+
+
+static int queue_length(struct pullup_field *begin, struct pullup_field *end)
+{
+ int count = 1;
+ struct pullup_field *f;
+
+ if (!begin || !end) return 0;
+ for (f = begin; f != end; f = f->next) count++;
+ return count;
+}
+
+static int find_first_break(struct pullup_field *f, int max)
+{
+ int i;
+ for (i = 0; i < max; i++) {
+ if (f->breaks & BREAK_RIGHT || f->next->breaks & BREAK_LEFT)
+ return i+1;
+ f = f->next;
+ }
+ return 0;
+}
+
+static void compute_breaks(struct pullup_context *c, struct pullup_field *f0)
+{
+ int i;
+ struct pullup_field *f1 = f0->next;
+ struct pullup_field *f2 = f1->next;
+ struct pullup_field *f3 = f2->next;
+ int l, max_l=0, max_r=0;
+ //struct pullup_field *ff;
+ //for (i=0, ff=c->first; ff != f0; i++, ff=ff->next);
+
+ if (f0->flags & F_HAVE_BREAKS) return;
+ //printf("\n%d: ", i);
+ f0->flags |= F_HAVE_BREAKS;
+
+ /* Special case when fields are 100% identical */
+ if (f0->buffer == f2->buffer && f1->buffer != f3->buffer) {
+ f2->breaks |= BREAK_RIGHT;
+ return;
+ }
+ if (f0->buffer != f2->buffer && f1->buffer == f3->buffer) {
+ f1->breaks |= BREAK_LEFT;
+ return;
+ }
+
+ for (i = 0; i < c->metric_len; i++) {
+ l = f2->diffs[i] - f3->diffs[i];
+ if (l > max_l) max_l = l;
+ if (-l > max_r) max_r = -l;
+ }
+ /* Don't get tripped up when differences are mostly quant error */
+ //printf("%d %d\n", max_l, max_r);
+ if (max_l + max_r < 128) return;
+ if (max_l > 4*max_r) f1->breaks |= BREAK_LEFT;
+ if (max_r > 4*max_l) f2->breaks |= BREAK_RIGHT;
+}
+
+static void compute_affinity(struct pullup_context *c, struct pullup_field *f)
+{
+ int i;
+ int max_l=0, max_r=0, l;
+ if (f->flags & F_HAVE_AFFINITY) return;
+ f->flags |= F_HAVE_AFFINITY;
+ if (f->buffer == f->next->next->buffer) {
+ f->affinity = 1;
+ f->next->affinity = 0;
+ f->next->next->affinity = -1;
+ f->next->flags |= F_HAVE_AFFINITY;
+ f->next->next->flags |= F_HAVE_AFFINITY;
+ return;
+ }
+ if (1) {
+ for (i = 0; i < c->metric_len; i++) {
+ int lv = f->prev->var[i];
+ int rv = f->next->var[i];
+ int v = f->var[i];
+ int lc = f->comb[i] - (v+lv) + ABS(v-lv);
+ int rc = f->next->comb[i] - (v+rv) + ABS(v-rv);
+ lc = lc>0 ? lc : 0;
+ rc = rc>0 ? rc : 0;
+ l = lc - rc;
+ if (l > max_l) max_l = l;
+ if (-l > max_r) max_r = -l;
+ }
+ if (max_l + max_r < 64) return;
+ if (max_r > 6*max_l) f->affinity = -1;
+ else if (max_l > 6*max_r) f->affinity = 1;
+ } else {
+ for (i = 0; i < c->metric_len; i++) {
+ l = f->comb[i] - f->next->comb[i];
+ if (l > max_l) max_l = l;
+ if (-l > max_r) max_r = -l;
+ }
+ if (max_l + max_r < 64) return;
+ if (max_r > 2*max_l) f->affinity = -1;
+ else if (max_l > 2*max_r) f->affinity = 1;
+ }
+}
+
+static void foo(struct pullup_context *c)
+{
+ struct pullup_field *f = c->first;
+ int i, n = queue_length(f, c->last);
+ for (i = 0; i < n-1; i++) {
+ if (i < n-3) compute_breaks(c, f);
+ compute_affinity(c, f);
+ f = f->next;
+ }
+}
+
+static int decide_frame_length(struct pullup_context *c)
+{
+ struct pullup_field *f0 = c->first;
+ struct pullup_field *f1 = f0->next;
+ struct pullup_field *f2 = f1->next;
+ int l;
+
+ if (queue_length(c->first, c->last) < 4) return 0;
+ foo(c);
+
+ if (f0->affinity == -1) return 1;
+
+ l = find_first_break(f0, 3);
+ if (l == 1 && c->strict_breaks < 0) l = 0;
+
+ switch (l) {
+ case 1:
+ if (c->strict_breaks < 1 && f0->affinity == 1 && f1->affinity == -1)
+ return 2;
+ else return 1;
+ case 2:
+ /* FIXME: strictly speaking, f0->prev is no longer valid... :) */
+ if (c->strict_pairs
+ && (f0->prev->breaks & BREAK_RIGHT) && (f2->breaks & BREAK_LEFT)
+ && (f0->affinity != 1 || f1->affinity != -1) )
+ return 1;
+ if (f1->affinity == 1) return 1;
+ else return 2;
+ case 3:
+ if (f2->affinity == 1) return 2;
+ else return 3;
+ default:
+ /* 9 possibilities covered before switch */
+ if (f1->affinity == 1) return 1; /* covers 6 */
+ else if (f1->affinity == -1) return 2; /* covers 6 */
+ else if (f2->affinity == -1) { /* covers 2 */
+ if (f0->affinity == 1) return 3;
+ else return 1;
+ }
+ else return 2; /* the remaining 6 */
+ }
+}
+
+
+static void print_aff_and_breaks(struct pullup_context *c, struct pullup_field *f)
+{
+ int i;
+ struct pullup_field *f0 = f;
+ const char aff_l[] = "+..", aff_r[] = "..+";
+ printf("\naffinity: ");
+ for (i = 0; i < 4; i++) {
+ printf("%c%d%c", aff_l[1+f->affinity], i, aff_r[1+f->affinity]);
+ f = f->next;
+ }
+ f = f0;
+ printf("\nbreaks: ");
+ for (i=0; i<4; i++) {
+ printf("%c%d%c", f->breaks & BREAK_LEFT ? '|' : '.', i, f->breaks & BREAK_RIGHT ? '|' : '.');
+ f = f->next;
+ }
+ printf("\n");
+}
+
+
+
+
+
+struct pullup_frame *pullup_get_frame(struct pullup_context *c)
+{
+ int i;
+ struct pullup_frame *fr = c->frame;
+ int n = decide_frame_length(c);
+ int aff = c->first->next->affinity;
+
+ if (!n) return 0;
+ if (fr->lock) return 0;
+
+ if (c->verbose) {
+ print_aff_and_breaks(c, c->first);
+ printf("duration: %d \n", n);
+ }
+
+ fr->lock++;
+ fr->length = n;
+ fr->parity = c->first->parity;
+ fr->buffer = 0;
+ for (i = 0; i < n; i++) {
+ /* We cheat and steal the buffer without release+relock */
+ fr->ifields[i] = c->first->buffer;
+ c->first->buffer = 0;
+ c->first = c->first->next;
+ }
+
+ if (n == 1) {
+ fr->ofields[fr->parity] = fr->ifields[0];
+ fr->ofields[fr->parity^1] = 0;
+ } else if (n == 2) {
+ fr->ofields[fr->parity] = fr->ifields[0];
+ fr->ofields[fr->parity^1] = fr->ifields[1];
+ } else if (n == 3) {
+ if (aff == 0)
+ aff = (fr->ifields[0] == fr->ifields[1]) ? -1 : 1;
+ /* else if (c->verbose) printf("forced aff: %d \n", aff); */
+ fr->ofields[fr->parity] = fr->ifields[1+aff];
+ fr->ofields[fr->parity^1] = fr->ifields[1];
+ }
+ pullup_lock_buffer(fr->ofields[0], 0);
+ pullup_lock_buffer(fr->ofields[1], 1);
+
+ if (fr->ofields[0] == fr->ofields[1]) {
+ fr->buffer = fr->ofields[0];
+ pullup_lock_buffer(fr->buffer, 2);
+ return fr;
+ }
+ return fr;
+}
+
+static void copy_field(struct pullup_context *c, struct pullup_buffer *dest,
+ struct pullup_buffer *src, int parity)
+{
+ int i, j;
+ unsigned char *d, *s;
+ for (i = 0; i < c->nplanes; i++) {
+ s = src->planes[i] + parity*c->stride[i];
+ d = dest->planes[i] + parity*c->stride[i];
+ for (j = c->h[i]>>1; j; j--) {
+ memcpy(d, s, c->stride[i]);
+ s += c->stride[i]<<1;
+ d += c->stride[i]<<1;
+ }
+ }
+}
+
+void pullup_pack_frame(struct pullup_context *c, struct pullup_frame *fr)
+{
+ int i;
+ if (fr->buffer) return;
+ if (fr->length < 2) return; /* FIXME: deal with this */
+ for (i = 0; i < 2; i++)
+ {
+ if (fr->ofields[i]->lock[i^1]) continue;
+ fr->buffer = fr->ofields[i];
+ pullup_lock_buffer(fr->buffer, 2);
+ copy_field(c, fr->buffer, fr->ofields[i^1], i^1);
+ return;
+ }
+ fr->buffer = pullup_get_buffer(c, 2);
+ copy_field(c, fr->buffer, fr->ofields[0], 0);
+ copy_field(c, fr->buffer, fr->ofields[1], 1);
+}
+
+void pullup_release_frame(struct pullup_frame *fr)
+{
+ int i;
+ for (i = 0; i < fr->length; i++)
+ pullup_release_buffer(fr->ifields[i], fr->parity ^ (i&1));
+ pullup_release_buffer(fr->ofields[0], 0);
+ pullup_release_buffer(fr->ofields[1], 1);
+ if (fr->buffer) pullup_release_buffer(fr->buffer, 2);
+ fr->lock--;
+}
+
+
+
+
+
+
+struct pullup_context *pullup_alloc_context(void)
+{
+ struct pullup_context *c;
+
+ c = calloc(1, sizeof(struct pullup_context));
+
+ return c;
+}
+
+void pullup_preinit_context(struct pullup_context *c)
+{
+ c->bpp = calloc(c->nplanes, sizeof(int));
+ c->w = calloc(c->nplanes, sizeof(int));
+ c->h = calloc(c->nplanes, sizeof(int));
+ c->stride = calloc(c->nplanes, sizeof(int));
+ c->background = calloc(c->nplanes, sizeof(int));
+}
+
+void pullup_init_context(struct pullup_context *c)
+{
+ int mp = c->metric_plane;
+ if (c->nbuffers < 10) c->nbuffers = 10;
+ c->buffers = calloc(c->nbuffers, sizeof (struct pullup_buffer));
+
+ c->metric_w = (c->w[mp] - ((c->junk_left + c->junk_right) << 3)) >> 3;
+ c->metric_h = (c->h[mp] - ((c->junk_top + c->junk_bottom) << 1)) >> 3;
+ c->metric_offset = c->junk_left*c->bpp[mp] + (c->junk_top<<1)*c->stride[mp];
+ c->metric_len = c->metric_w * c->metric_h;
+
+ c->head = make_field_queue(c, 8);
+
+ c->frame = calloc(1, sizeof (struct pullup_frame));
+ c->frame->ifields = calloc(3, sizeof (struct pullup_buffer *));
+
+ switch(c->format) {
+ case PULLUP_FMT_Y:
+ c->diff = diff_y;
+ c->comb = licomb_y;
+ c->var = var_y;
+#if ARCH_X86
+#if HAVE_MMX
+ if (c->cpu & PULLUP_CPU_MMX) {
+ c->diff = diff_y_mmx;
+ c->comb = licomb_y_mmx;
+ c->var = var_y_mmx;
+ }
+#endif
+#endif
+ /* c->comb = qpcomb_y; */
+ break;
+#if 0
+ case PULLUP_FMT_YUY2:
+ c->diff = diff_yuy2;
+ break;
+ case PULLUP_FMT_RGB32:
+ c->diff = diff_rgb32;
+ break;
+#endif
+ }
+}
+
+void pullup_free_context(struct pullup_context *c)
+{
+ struct pullup_field *f;
+ free(c->buffers);
+ f = c->head;
+ do {
+ if (!f) break;
+ free(f->diffs);
+ free(f->comb);
+ f = f->next;
+ free(f->prev);
+ } while (f != c->head);
+ free(c->frame);
+ free(c);
+}
diff --git a/libavfilter/libmpcodecs/pullup.h b/libavfilter/libmpcodecs/pullup.h
new file mode 100644
index 0000000000..9c74fb5944
--- /dev/null
+++ b/libavfilter/libmpcodecs/pullup.h
@@ -0,0 +1,102 @@
+/*
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef MPLAYER_PULLUP_H
+#define MPLAYER_PULLUP_H
+
+#define PULLUP_CPU_MMX 1
+#define PULLUP_CPU_MMX2 2
+#define PULLUP_CPU_3DNOW 4
+#define PULLUP_CPU_3DNOWEXT 8
+#define PULLUP_CPU_SSE 16
+#define PULLUP_CPU_SSE2 32
+
+#define PULLUP_FMT_Y 1
+#define PULLUP_FMT_YUY2 2
+#define PULLUP_FMT_UYVY 3
+#define PULLUP_FMT_RGB32 4
+
+struct pullup_buffer
+{
+ int lock[2];
+ unsigned char **planes;
+};
+
+struct pullup_field
+{
+ int parity;
+ struct pullup_buffer *buffer;
+ unsigned int flags;
+ int breaks;
+ int affinity;
+ int *diffs;
+ int *comb;
+ int *var;
+ struct pullup_field *prev, *next;
+};
+
+struct pullup_frame
+{
+ int lock;
+ int length;
+ int parity;
+ struct pullup_buffer **ifields, *ofields[2];
+ struct pullup_buffer *buffer;
+};
+
+struct pullup_context
+{
+ /* Public interface */
+ int format;
+ int nplanes;
+ int *bpp, *w, *h, *stride, *background;
+ unsigned int cpu;
+ int junk_left, junk_right, junk_top, junk_bottom;
+ int verbose;
+ int metric_plane;
+ int strict_breaks;
+ int strict_pairs;
+ /* Internal data */
+ struct pullup_field *first, *last, *head;
+ struct pullup_buffer *buffers;
+ int nbuffers;
+ int (*diff)(unsigned char *, unsigned char *, int);
+ int (*comb)(unsigned char *, unsigned char *, int);
+ int (*var)(unsigned char *, unsigned char *, int);
+ int metric_w, metric_h, metric_len, metric_offset;
+ struct pullup_frame *frame;
+};
+
+
+struct pullup_buffer *pullup_lock_buffer(struct pullup_buffer *b, int parity);
+void pullup_release_buffer(struct pullup_buffer *b, int parity);
+struct pullup_buffer *pullup_get_buffer(struct pullup_context *c, int parity);
+
+void pullup_submit_field(struct pullup_context *c, struct pullup_buffer *b, int parity);
+void pullup_flush_fields(struct pullup_context *c);
+
+struct pullup_frame *pullup_get_frame(struct pullup_context *c);
+void pullup_pack_frame(struct pullup_context *c, struct pullup_frame *fr);
+void pullup_release_frame(struct pullup_frame *fr);
+
+struct pullup_context *pullup_alloc_context(void);
+void pullup_preinit_context(struct pullup_context *c);
+void pullup_init_context(struct pullup_context *c);
+void pullup_free_context(struct pullup_context *c);
+
+#endif /* MPLAYER_PULLUP_H */
diff --git a/libavfilter/libmpcodecs/vd_ffmpeg.h b/libavfilter/libmpcodecs/vd_ffmpeg.h
new file mode 100644
index 0000000000..004d477330
--- /dev/null
+++ b/libavfilter/libmpcodecs/vd_ffmpeg.h
@@ -0,0 +1,24 @@
+/*
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef MPLAYER_VD_FFMPEG_H
+#define MPLAYER_VD_FFMPEG_H
+
+void init_avcodec(void);
+
+#endif /* MPLAYER_VD_FFMPEG_H */
diff --git a/libavfilter/libmpcodecs/vf.h b/libavfilter/libmpcodecs/vf.h
new file mode 100644
index 0000000000..9119b6209d
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf.h
@@ -0,0 +1,169 @@
+/*
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef MPLAYER_VF_H
+#define MPLAYER_VF_H
+
+//#include "m_option.h"
+#include "mp_image.h"
+
+//extern m_obj_settings_t* vf_settings;
+//extern const m_obj_list_t vf_obj_list;
+
+struct vf_instance;
+struct vf_priv_s;
+
+typedef struct vf_info_s {
+ const char *info;
+ const char *name;
+ const char *author;
+ const char *comment;
+ int (*vf_open)(struct vf_instance *vf,char* args);
+ // Ptr to a struct dscribing the options
+ const void* opts;
+} vf_info_t;
+
+#define NUM_NUMBERED_MPI 50
+
+typedef struct vf_image_context_s {
+ mp_image_t* static_images[2];
+ mp_image_t* temp_images[1];
+ mp_image_t* export_images[1];
+ mp_image_t* numbered_images[NUM_NUMBERED_MPI];
+ int static_idx;
+} vf_image_context_t;
+
+typedef struct vf_format_context_t {
+ int have_configured;
+ int orig_width, orig_height, orig_fmt;
+} vf_format_context_t;
+
+typedef struct vf_instance {
+ const vf_info_t* info;
+ // funcs:
+ int (*config)(struct vf_instance *vf,
+ int width, int height, int d_width, int d_height,
+ unsigned int flags, unsigned int outfmt);
+ int (*control)(struct vf_instance *vf,
+ int request, void* data);
+ int (*query_format)(struct vf_instance *vf,
+ unsigned int fmt);
+ void (*get_image)(struct vf_instance *vf,
+ mp_image_t *mpi);
+ int (*put_image)(struct vf_instance *vf,
+ mp_image_t *mpi, double pts);
+ void (*start_slice)(struct vf_instance *vf,
+ mp_image_t *mpi);
+ void (*draw_slice)(struct vf_instance *vf,
+ unsigned char** src, int* stride, int w,int h, int x, int y);
+ void (*uninit)(struct vf_instance *vf);
+
+ int (*continue_buffered_image)(struct vf_instance *vf);
+ // caps:
+ unsigned int default_caps; // used by default query_format()
+ unsigned int default_reqs; // used by default config()
+ // data:
+ int w, h;
+ vf_image_context_t imgctx;
+ vf_format_context_t fmt;
+ struct vf_instance *next;
+ mp_image_t *dmpi;
+ struct vf_priv_s* priv;
+} vf_instance_t;
+
+// control codes:
+#include "mpc_info.h"
+
+typedef struct vf_seteq_s
+{
+ const char *item;
+ int value;
+} vf_equalizer_t;
+
+#define VFCTRL_QUERY_MAX_PP_LEVEL 4 /* test for postprocessing support (max level) */
+#define VFCTRL_SET_PP_LEVEL 5 /* set postprocessing level */
+#define VFCTRL_SET_EQUALIZER 6 /* set color options (brightness,contrast etc) */
+#define VFCTRL_GET_EQUALIZER 8 /* gset color options (brightness,contrast etc) */
+#define VFCTRL_DRAW_OSD 7
+#define VFCTRL_CHANGE_RECTANGLE 9 /* Change the rectangle boundaries */
+#define VFCTRL_FLIP_PAGE 10 /* Tell the vo to flip pages */
+#define VFCTRL_DUPLICATE_FRAME 11 /* For encoding - encode zero-change frame */
+#define VFCTRL_SKIP_NEXT_FRAME 12 /* For encoding - drop the next frame that passes thru */
+#define VFCTRL_FLUSH_FRAMES 13 /* For encoding - flush delayed frames */
+#define VFCTRL_SCREENSHOT 14 /* Make a screenshot */
+#define VFCTRL_INIT_EOSD 15 /* Select EOSD renderer */
+#define VFCTRL_DRAW_EOSD 16 /* Render EOSD */
+#define VFCTRL_GET_PTS 17 /* Return last pts value that reached vf_vo*/
+#define VFCTRL_SET_DEINTERLACE 18 /* Set deinterlacing status */
+#define VFCTRL_GET_DEINTERLACE 19 /* Get deinterlacing status */
+
+#include "vfcap.h"
+
+//FIXME this should be in a common header, but i dunno which
+#define MP_NOPTS_VALUE (-1LL<<63) //both int64_t and double should be able to represent this exactly
+
+
+// functions:
+void vf_mpi_clear(mp_image_t* mpi,int x0,int y0,int w,int h);
+mp_image_t* vf_get_image(vf_instance_t* vf, unsigned int outfmt, int mp_imgtype, int mp_imgflag, int w, int h);
+
+vf_instance_t* vf_open_plugin(const vf_info_t* const* filter_list, vf_instance_t* next, const char *name, char **args);
+vf_instance_t* vf_open_filter(vf_instance_t* next, const char *name, char **args);
+vf_instance_t* vf_add_before_vo(vf_instance_t **vf, char *name, char **args);
+vf_instance_t* vf_open_encoder(vf_instance_t* next, const char *name, char *args);
+
+unsigned int vf_match_csp(vf_instance_t** vfp,const unsigned int* list,unsigned int preferred);
+void vf_clone_mpi_attributes(mp_image_t* dst, mp_image_t* src);
+void vf_queue_frame(vf_instance_t *vf, int (*)(vf_instance_t *));
+int vf_output_queued_frame(vf_instance_t *vf);
+
+// default wrappers:
+int vf_next_config(struct vf_instance *vf,
+ int width, int height, int d_width, int d_height,
+ unsigned int flags, unsigned int outfmt);
+int vf_next_control(struct vf_instance *vf, int request, void* data);
+void vf_extra_flip(struct vf_instance *vf);
+int vf_next_query_format(struct vf_instance *vf, unsigned int fmt);
+int vf_next_put_image(struct vf_instance *vf,mp_image_t *mpi, double pts);
+void vf_next_draw_slice (struct vf_instance *vf, unsigned char** src, int* stride, int w,int h, int x, int y);
+
+vf_instance_t* append_filters(vf_instance_t* last);
+
+void vf_uninit_filter(vf_instance_t* vf);
+void vf_uninit_filter_chain(vf_instance_t* vf);
+
+int vf_config_wrapper(struct vf_instance *vf,
+ int width, int height, int d_width, int d_height,
+ unsigned int flags, unsigned int outfmt);
+
+static inline int norm_qscale(int qscale, int type)
+{
+ switch (type) {
+ case 0: // MPEG-1
+ return qscale;
+ case 1: // MPEG-2
+ return qscale >> 1;
+ case 2: // H264
+ return qscale >> 2;
+ case 3: // VP56
+ return (63 - qscale + 2) >> 2;
+ }
+ return qscale;
+}
+
+#endif /* MPLAYER_VF_H */
diff --git a/libavfilter/libmpcodecs/vf_2xsai.c b/libavfilter/libmpcodecs/vf_2xsai.c
new file mode 100644
index 0000000000..a19420ff98
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_2xsai.c
@@ -0,0 +1,336 @@
+/*
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+
+#include "config.h"
+#include "mp_msg.h"
+
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+
+//===========================================================================//
+
+/* FIXME: these all belong in the context, not as globals! */
+
+static uint32_t colorMask = 0xF7DEF7DE;
+static uint32_t lowPixelMask = 0x08210821;
+static uint32_t qcolorMask = 0xE79CE79C;
+static uint32_t qlowpixelMask = 0x18631863;
+static uint32_t redblueMask = 0xF81F;
+static uint32_t greenMask = 0x7E0;
+static int PixelsPerMask = 2;
+
+#define makecol(r,g,b) (r+(g<<8)+(b<<16))
+#define makecol_depth(d,r,g,b) (r+(g<<8)+(b<<16))
+
+static int Init_2xSaI(int d)
+{
+
+ int minr = 0, ming = 0, minb = 0;
+ int i;
+
+// if (d != 15 && d != 16 && d != 24 && d != 32)
+// return -1;
+
+ /* Get lowest color bit */
+ for (i = 0; i < 255; i++) {
+ if (!minr)
+ minr = makecol(i, 0, 0);
+ if (!ming)
+ ming = makecol(0, i, 0);
+ if (!minb)
+ minb = makecol(0, 0, i);
+ }
+
+ colorMask = (makecol_depth(d, 255, 0, 0) - minr) | (makecol_depth(d, 0, 255, 0) - ming) | (makecol_depth(d, 0, 0, 255) - minb);
+ lowPixelMask = minr | ming | minb;
+ qcolorMask = (makecol_depth(d, 255, 0, 0) - 3 * minr) | (makecol_depth(d, 0, 255, 0) - 3 * ming) | (makecol_depth(d, 0, 0, 255) - 3 * minb);
+ qlowpixelMask = (minr * 3) | (ming * 3) | (minb * 3);
+ redblueMask = makecol_depth(d, 255, 0, 255);
+ greenMask = makecol_depth(d, 0, 255, 0);
+
+ PixelsPerMask = (d <= 16) ? 2 : 1;
+
+ if (PixelsPerMask == 2) {
+ colorMask |= (colorMask << 16);
+ qcolorMask |= (qcolorMask << 16);
+ lowPixelMask |= (lowPixelMask << 16);
+ qlowpixelMask |= (qlowpixelMask << 16);
+ }
+
+// TRACE("Color Mask: 0x%lX\n", colorMask);
+// TRACE("Low Pixel Mask: 0x%lX\n", lowPixelMask);
+// TRACE("QColor Mask: 0x%lX\n", qcolorMask);
+// TRACE("QLow Pixel Mask: 0x%lX\n", qlowpixelMask);
+
+ return 0;
+}
+
+
+#define GET_RESULT(A, B, C, D) ((A != C || A != D) - (B != C || B != D))
+
+#define INTERPOLATE(A, B) (((A & colorMask) >> 1) + ((B & colorMask) >> 1) + (A & B & lowPixelMask))
+
+#define Q_INTERPOLATE(A, B, C, D) ((A & qcolorMask) >> 2) + ((B & qcolorMask) >> 2) + ((C & qcolorMask) >> 2) + ((D & qcolorMask) >> 2) \
+ + ((((A & qlowpixelMask) + (B & qlowpixelMask) + (C & qlowpixelMask) + (D & qlowpixelMask)) >> 2) & qlowpixelMask)
+
+
+static void Super2xSaI_ex(uint8_t *src, uint32_t src_pitch,
+ uint8_t *dst, uint32_t dst_pitch,
+ uint32_t width, uint32_t height, int sbpp)
+{
+
+ unsigned int x, y;
+ uint32_t color[16];
+ unsigned char *src_line[4];
+
+ /* Point to the first 3 lines. */
+ src_line[0] = src;
+ src_line[1] = src;
+ src_line[2] = src + src_pitch;
+ src_line[3] = src + src_pitch * 2;
+
+ x = 0, y = 0;
+
+ if (PixelsPerMask == 2) {
+ unsigned short *sbp;
+ sbp = (unsigned short*)src_line[0];
+ color[0] = *sbp; color[1] = color[0]; color[2] = color[0]; color[3] = color[0];
+ color[4] = color[0]; color[5] = color[0]; color[6] = *(sbp + 1); color[7] = *(sbp + 2);
+ sbp = (unsigned short*)src_line[2];
+ color[8] = *sbp; color[9] = color[8]; color[10] = *(sbp + 1); color[11] = *(sbp + 2);
+ sbp = (unsigned short*)src_line[3];
+ color[12] = *sbp; color[13] = color[12]; color[14] = *(sbp + 1); color[15] = *(sbp + 2);
+ }
+ else {
+ uint32_t *lbp;
+ lbp = (uint32_t*)src_line[0];
+ color[0] = *lbp; color[1] = color[0]; color[2] = color[0]; color[3] = color[0];
+ color[4] = color[0]; color[5] = color[0]; color[6] = *(lbp + 1); color[7] = *(lbp + 2);
+ lbp = (uint32_t*)src_line[2];
+ color[8] = *lbp; color[9] = color[8]; color[10] = *(lbp + 1); color[11] = *(lbp + 2);
+ lbp = (uint32_t*)src_line[3];
+ color[12] = *lbp; color[13] = color[12]; color[14] = *(lbp + 1); color[15] = *(lbp + 2);
+ }
+
+ for (y = 0; y < height; y++) {
+ unsigned char *dst_line[2];
+
+ dst_line[0] = dst + dst_pitch*2*y;
+ dst_line[1] = dst + dst_pitch*(2*y+1);
+
+ /* Todo: x = width - 2, x = width - 1 */
+
+ for (x = 0; x < width; x++) {
+ uint32_t product1a, product1b, product2a, product2b;
+
+//--------------------------------------- B0 B1 B2 B3 0 1 2 3
+// 4 5* 6 S2 -> 4 5* 6 7
+// 1 2 3 S1 8 9 10 11
+// A0 A1 A2 A3 12 13 14 15
+//--------------------------------------
+ if (color[9] == color[6] && color[5] != color[10]) {
+ product2b = color[9];
+ product1b = product2b;
+ }
+ else if (color[5] == color[10] && color[9] != color[6]) {
+ product2b = color[5];
+ product1b = product2b;
+ }
+ else if (color[5] == color[10] && color[9] == color[6]) {
+ int r = 0;
+
+ r += GET_RESULT(color[6], color[5], color[8], color[13]);
+ r += GET_RESULT(color[6], color[5], color[4], color[1]);
+ r += GET_RESULT(color[6], color[5], color[14], color[11]);
+ r += GET_RESULT(color[6], color[5], color[2], color[7]);
+
+ if (r > 0)
+ product1b = color[6];
+ else if (r < 0)
+ product1b = color[5];
+ else
+ product1b = INTERPOLATE(color[5], color[6]);
+
+ product2b = product1b;
+
+ }
+ else {
+ if (color[6] == color[10] && color[10] == color[13] && color[9] != color[14] && color[10] != color[12])
+ product2b = Q_INTERPOLATE(color[10], color[10], color[10], color[9]);
+ else if (color[5] == color[9] && color[9] == color[14] && color[13] != color[10] && color[9] != color[15])
+ product2b = Q_INTERPOLATE(color[9], color[9], color[9], color[10]);
+ else
+ product2b = INTERPOLATE(color[9], color[10]);
+
+ if (color[6] == color[10] && color[6] == color[1] && color[5] != color[2] && color[6] != color[0])
+ product1b = Q_INTERPOLATE(color[6], color[6], color[6], color[5]);
+ else if (color[5] == color[9] && color[5] == color[2] && color[1] != color[6] && color[5] != color[3])
+ product1b = Q_INTERPOLATE(color[6], color[5], color[5], color[5]);
+ else
+ product1b = INTERPOLATE(color[5], color[6]);
+ }
+
+ if (color[5] == color[10] && color[9] != color[6] && color[4] == color[5] && color[5] != color[14])
+ product2a = INTERPOLATE(color[9], color[5]);
+ else if (color[5] == color[8] && color[6] == color[5] && color[4] != color[9] && color[5] != color[12])
+ product2a = INTERPOLATE(color[9], color[5]);
+ else
+ product2a = color[9];
+
+ if (color[9] == color[6] && color[5] != color[10] && color[8] == color[9] && color[9] != color[2])
+ product1a = INTERPOLATE(color[9], color[5]);
+ else if (color[4] == color[9] && color[10] == color[9] && color[8] != color[5] && color[9] != color[0])
+ product1a = INTERPOLATE(color[9], color[5]);
+ else
+ product1a = color[5];
+
+ if (PixelsPerMask == 2) {
+ *((uint32_t *) (&dst_line[0][x * 4])) = product1a | (product1b << 16);
+ *((uint32_t *) (&dst_line[1][x * 4])) = product2a | (product2b << 16);
+ }
+ else {
+ *((uint32_t *) (&dst_line[0][x * 8])) = product1a;
+ *((uint32_t *) (&dst_line[0][x * 8 + 4])) = product1b;
+ *((uint32_t *) (&dst_line[1][x * 8])) = product2a;
+ *((uint32_t *) (&dst_line[1][x * 8 + 4])) = product2b;
+ }
+
+ /* Move color matrix forward */
+ color[0] = color[1]; color[4] = color[5]; color[8] = color[9]; color[12] = color[13];
+ color[1] = color[2]; color[5] = color[6]; color[9] = color[10]; color[13] = color[14];
+ color[2] = color[3]; color[6] = color[7]; color[10] = color[11]; color[14] = color[15];
+
+ if (x < width - 3) {
+ x += 3;
+ if (PixelsPerMask == 2) {
+ color[3] = *(((unsigned short*)src_line[0]) + x);
+ color[7] = *(((unsigned short*)src_line[1]) + x);
+ color[11] = *(((unsigned short*)src_line[2]) + x);
+ color[15] = *(((unsigned short*)src_line[3]) + x);
+ }
+ else {
+ color[3] = *(((uint32_t*)src_line[0]) + x);
+ color[7] = *(((uint32_t*)src_line[1]) + x);
+ color[11] = *(((uint32_t*)src_line[2]) + x);
+ color[15] = *(((uint32_t*)src_line[3]) + x);
+ }
+ x -= 3;
+ }
+ }
+
+ /* We're done with one line, so we shift the source lines up */
+ src_line[0] = src_line[1];
+ src_line[1] = src_line[2];
+ src_line[2] = src_line[3];
+
+ /* Read next line */
+ if (y + 3 >= height)
+ src_line[3] = src_line[2];
+ else
+ src_line[3] = src_line[2] + src_pitch;
+
+ /* Then shift the color matrix up */
+ if (PixelsPerMask == 2) {
+ unsigned short *sbp;
+ sbp = (unsigned short*)src_line[0];
+ color[0] = *sbp; color[1] = color[0]; color[2] = *(sbp + 1); color[3] = *(sbp + 2);
+ sbp = (unsigned short*)src_line[1];
+ color[4] = *sbp; color[5] = color[4]; color[6] = *(sbp + 1); color[7] = *(sbp + 2);
+ sbp = (unsigned short*)src_line[2];
+ color[8] = *sbp; color[9] = color[9]; color[10] = *(sbp + 1); color[11] = *(sbp + 2);
+ sbp = (unsigned short*)src_line[3];
+ color[12] = *sbp; color[13] = color[12]; color[14] = *(sbp + 1); color[15] = *(sbp + 2);
+ }
+ else {
+ uint32_t *lbp;
+ lbp = (uint32_t*)src_line[0];
+ color[0] = *lbp; color[1] = color[0]; color[2] = *(lbp + 1); color[3] = *(lbp + 2);
+ lbp = (uint32_t*)src_line[1];
+ color[4] = *lbp; color[5] = color[4]; color[6] = *(lbp + 1); color[7] = *(lbp + 2);
+ lbp = (uint32_t*)src_line[2];
+ color[8] = *lbp; color[9] = color[9]; color[10] = *(lbp + 1); color[11] = *(lbp + 2);
+ lbp = (uint32_t*)src_line[3];
+ color[12] = *lbp; color[13] = color[12]; color[14] = *(lbp + 1); color[15] = *(lbp + 2);
+ }
+
+ } // y loop
+
+}
+
+
+//===========================================================================//
+
+static int config(struct vf_instance *vf,
+ int width, int height, int d_width, int d_height,
+ unsigned int flags, unsigned int outfmt){
+
+ Init_2xSaI(outfmt&255);
+
+ return vf_next_config(vf,2*width,2*height,2*d_width,2*d_height,flags,outfmt);
+}
+
+static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
+ mp_image_t *dmpi;
+
+ // hope we'll get DR buffer:
+ dmpi=vf_get_image(vf->next,mpi->imgfmt,
+ MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
+ 2*mpi->w, 2*mpi->h);
+
+ Super2xSaI_ex(mpi->planes[0], mpi->stride[0],
+ dmpi->planes[0], dmpi->stride[0],
+ mpi->w, mpi->h, mpi->bpp/8);
+
+ return vf_next_put_image(vf,dmpi, pts);
+}
+
+//===========================================================================//
+
+static int query_format(struct vf_instance *vf, unsigned int fmt){
+ switch(fmt){
+// case IMGFMT_BGR15:
+// case IMGFMT_BGR16:
+ case IMGFMT_BGR32:
+ return vf_next_query_format(vf,fmt);
+ }
+ return 0;
+}
+
+static int vf_open(vf_instance_t *vf, char *args){
+ vf->config=config;
+ vf->put_image=put_image;
+ vf->query_format=query_format;
+ return 1;
+}
+
+const vf_info_t vf_info_2xsai = {
+ "2xSai BGR bitmap 2x scaler",
+ "2xsai",
+ "A'rpi",
+ "http://elektron.its.tudelft.nl/~dalikifa/",
+ vf_open,
+ NULL
+};
+
+//===========================================================================//
diff --git a/libavfilter/libmpcodecs/vf_decimate.c b/libavfilter/libmpcodecs/vf_decimate.c
new file mode 100644
index 0000000000..1fd7bce3d3
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_decimate.c
@@ -0,0 +1,198 @@
+/*
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "config.h"
+#include "mp_msg.h"
+#include "cpudetect.h"
+
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+
+#include "libvo/fastmemcpy.h"
+
+
+struct vf_priv_s {
+ int hi, lo;
+ float frac;
+ int max, last, cnt;
+};
+
+#if HAVE_MMX && HAVE_EBX_AVAILABLE
+static int diff_MMX(unsigned char *old, unsigned char *new, int os, int ns)
+{
+ volatile short out[4];
+ __asm__ (
+ "movl $8, %%ecx \n\t"
+ "pxor %%mm4, %%mm4 \n\t"
+ "pxor %%mm7, %%mm7 \n\t"
+
+ ASMALIGN(4)
+ "1: \n\t"
+
+ "movq (%%"REG_S"), %%mm0 \n\t"
+ "movq (%%"REG_S"), %%mm2 \n\t"
+ "add %%"REG_a", %%"REG_S" \n\t"
+ "movq (%%"REG_D"), %%mm1 \n\t"
+ "add %%"REG_b", %%"REG_D" \n\t"
+ "psubusb %%mm1, %%mm2 \n\t"
+ "psubusb %%mm0, %%mm1 \n\t"
+ "movq %%mm2, %%mm0 \n\t"
+ "movq %%mm1, %%mm3 \n\t"
+ "punpcklbw %%mm7, %%mm0 \n\t"
+ "punpcklbw %%mm7, %%mm1 \n\t"
+ "punpckhbw %%mm7, %%mm2 \n\t"
+ "punpckhbw %%mm7, %%mm3 \n\t"
+ "paddw %%mm0, %%mm4 \n\t"
+ "paddw %%mm1, %%mm4 \n\t"
+ "paddw %%mm2, %%mm4 \n\t"
+ "paddw %%mm3, %%mm4 \n\t"
+
+ "decl %%ecx \n\t"
+ "jnz 1b \n\t"
+ "movq %%mm4, (%%"REG_d") \n\t"
+ "emms \n\t"
+ :
+ : "S" (old), "D" (new), "a" ((long)os), "b" ((long)ns), "d" (out)
+ : "%ecx", "memory"
+ );
+ return out[0]+out[1]+out[2]+out[3];
+}
+#endif
+
+static int diff_C(unsigned char *old, unsigned char *new, int os, int ns)
+{
+ int x, y, d=0;
+ for (y = 8; y; y--) {
+ for (x = 8; x; x--) {
+ d += abs(new[x] - old[x]);
+ }
+ new += ns;
+ old += os;
+ }
+ return d;
+}
+
+static int (*diff)(unsigned char *, unsigned char *, int, int);
+
+static int diff_to_drop_plane(int hi, int lo, float frac, unsigned char *old, unsigned char *new, int w, int h, int os, int ns)
+{
+ int x, y;
+ int d, c=0;
+ int t = (w/16)*(h/16)*frac;
+ for (y = 0; y < h-7; y += 4) {
+ for (x = 8; x < w-7; x += 4) {
+ d = diff(old+x+y*os, new+x+y*ns, os, ns);
+ if (d > hi) return 0;
+ if (d > lo) {
+ c++;
+ if (c > t) return 0;
+ }
+ }
+ }
+ return 1;
+}
+
+static int diff_to_drop(int hi, int lo, float frac, mp_image_t *old, mp_image_t *new)
+{
+ if (new->flags & MP_IMGFLAG_PLANAR) {
+ return diff_to_drop_plane(hi,lo,frac, old->planes[0], new->planes[0],
+ new->w, new->h, old->stride[0], new->stride[0])
+ && diff_to_drop_plane(hi,lo,frac, old->planes[1], new->planes[1],
+ new->chroma_width, new->chroma_height,
+ old->stride[1], new->stride[1])
+ && diff_to_drop_plane(hi,lo,frac, old->planes[2], new->planes[2],
+ new->chroma_width, new->chroma_height,
+ old->stride[2], new->stride[2]);
+ }
+ return diff_to_drop_plane(hi,lo,frac, old->planes[0], new->planes[0],
+ new->w*(new->bpp/8), new->h, old->stride[0], new->stride[0]);
+}
+
+static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
+{
+ mp_image_t *dmpi;
+
+ dmpi = vf_get_image(vf->next, mpi->imgfmt,
+ MP_IMGTYPE_STATIC, MP_IMGFLAG_ACCEPT_STRIDE |
+ MP_IMGFLAG_PRESERVE | MP_IMGFLAG_READABLE,
+ mpi->width, mpi->height);
+ dmpi->qscale = mpi->qscale;
+ dmpi->qstride = mpi->qstride;
+ dmpi->qscale_type = mpi->qscale_type;
+
+ if (diff_to_drop(vf->priv->hi, vf->priv->lo, vf->priv->frac, dmpi, mpi)) {
+ if (vf->priv->max == 0)
+ return 0;
+ else if ((vf->priv->max > 0) && (vf->priv->cnt++ < vf->priv->max))
+ return 0;
+ else if ((vf->priv->max < 0) && (vf->priv->last+1 >= -vf->priv->max))
+ return vf->priv->last=0;
+ }
+ vf->priv->last++;
+ vf->priv->cnt=0;
+
+ memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h,
+ dmpi->stride[0], mpi->stride[0]);
+ if (mpi->flags & MP_IMGFLAG_PLANAR) {
+ memcpy_pic(dmpi->planes[1], mpi->planes[1],
+ mpi->chroma_width, mpi->chroma_height,
+ dmpi->stride[1], mpi->stride[1]);
+ memcpy_pic(dmpi->planes[2], mpi->planes[2],
+ mpi->chroma_width, mpi->chroma_height,
+ dmpi->stride[2], mpi->stride[2]);
+ }
+ return vf_next_put_image(vf, dmpi, pts);
+}
+
+static void uninit(struct vf_instance *vf)
+{
+ free(vf->priv);
+}
+
+static int vf_open(vf_instance_t *vf, char *args)
+{
+ struct vf_priv_s *p;
+ vf->put_image = put_image;
+ vf->uninit = uninit;
+ vf->default_reqs = VFCAP_ACCEPT_STRIDE;
+ vf->priv = p = calloc(1, sizeof(struct vf_priv_s));
+ p->max = 0;
+ p->hi = 64*12;
+ p->lo = 64*5;
+ p->frac = 0.33;
+ if (args) sscanf(args, "%d:%d:%d:%f", &p->max, &p->hi, &p->lo, &p->frac);
+ diff = diff_C;
+#if HAVE_MMX && HAVE_EBX_AVAILABLE
+ if(gCpuCaps.hasMMX) diff = diff_MMX;
+#endif
+ return 1;
+}
+
+const vf_info_t vf_info_decimate = {
+ "near-duplicate frame remover",
+ "decimate",
+ "Rich Felker",
+ "",
+ vf_open,
+ NULL
+};
diff --git a/libavfilter/libmpcodecs/vf_denoise3d.c b/libavfilter/libmpcodecs/vf_denoise3d.c
new file mode 100644
index 0000000000..a952a22287
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_denoise3d.c
@@ -0,0 +1,268 @@
+/*
+ * Copyright (C) 2003 Daniel Moreno <comac@comac.darktech.org>
+ *
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+#include <math.h>
+
+#include "mp_msg.h"
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+
+#define PARAM1_DEFAULT 4.0
+#define PARAM2_DEFAULT 3.0
+#define PARAM3_DEFAULT 6.0
+
+//===========================================================================//
+
+struct vf_priv_s {
+ int Coefs[4][512];
+ unsigned char *Line;
+ mp_image_t *pmpi;
+};
+
+
+/***************************************************************************/
+
+
+static int config(struct vf_instance *vf,
+ int width, int height, int d_width, int d_height,
+ unsigned int flags, unsigned int outfmt){
+
+ free(vf->priv->Line);
+ vf->priv->Line = malloc(width);
+ vf->priv->pmpi=NULL;
+// vf->default_caps &= !VFCAP_ACCEPT_STRIDE;
+
+ return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
+}
+
+
+static void uninit(struct vf_instance *vf)
+{
+ free(vf->priv->Line);
+}
+
+#define LowPass(Prev, Curr, Coef) (Curr + Coef[Prev - Curr])
+
+static void deNoise(unsigned char *Frame, // mpi->planes[x]
+ unsigned char *FramePrev, // pmpi->planes[x]
+ unsigned char *FrameDest, // dmpi->planes[x]
+ unsigned char *LineAnt, // vf->priv->Line (width bytes)
+ int W, int H, int sStride, int pStride, int dStride,
+ int *Horizontal, int *Vertical, int *Temporal)
+{
+ int X, Y;
+ int sLineOffs = 0, pLineOffs = 0, dLineOffs = 0;
+ unsigned char PixelAnt;
+
+ /* First pixel has no left nor top neighbor. Only previous frame */
+ LineAnt[0] = PixelAnt = Frame[0];
+ FrameDest[0] = LowPass(FramePrev[0], LineAnt[0], Temporal);
+
+ /* Fist line has no top neighbor. Only left one for each pixel and
+ * last frame */
+ for (X = 1; X < W; X++)
+ {
+ PixelAnt = LowPass(PixelAnt, Frame[X], Horizontal);
+ LineAnt[X] = PixelAnt;
+ FrameDest[X] = LowPass(FramePrev[X], LineAnt[X], Temporal);
+ }
+
+ for (Y = 1; Y < H; Y++)
+ {
+ sLineOffs += sStride, pLineOffs += pStride, dLineOffs += dStride;
+ /* First pixel on each line doesn't have previous pixel */
+ PixelAnt = Frame[sLineOffs];
+ LineAnt[0] = LowPass(LineAnt[0], PixelAnt, Vertical);
+ FrameDest[dLineOffs] = LowPass(FramePrev[pLineOffs], LineAnt[0], Temporal);
+
+ for (X = 1; X < W; X++)
+ {
+ /* The rest are normal */
+ PixelAnt = LowPass(PixelAnt, Frame[sLineOffs+X], Horizontal);
+ LineAnt[X] = LowPass(LineAnt[X], PixelAnt, Vertical);
+ FrameDest[dLineOffs+X] = LowPass(FramePrev[pLineOffs+X], LineAnt[X], Temporal);
+ }
+ }
+}
+
+
+
+static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
+ int cw= mpi->w >> mpi->chroma_x_shift;
+ int ch= mpi->h >> mpi->chroma_y_shift;
+ int W = mpi->w, H = mpi->h;
+
+ mp_image_t *dmpi=vf_get_image(vf->next,mpi->imgfmt,
+ MP_IMGTYPE_IP, MP_IMGFLAG_ACCEPT_STRIDE |
+ MP_IMGFLAG_PRESERVE | MP_IMGFLAG_READABLE,
+ mpi->w,mpi->h);
+
+ if(!dmpi) return 0;
+ if (!vf->priv->pmpi) vf->priv->pmpi=mpi;
+
+ deNoise(mpi->planes[0], vf->priv->pmpi->planes[0], dmpi->planes[0],
+ vf->priv->Line, W, H,
+ mpi->stride[0], vf->priv->pmpi->stride[0], dmpi->stride[0],
+ vf->priv->Coefs[0] + 256,
+ vf->priv->Coefs[0] + 256,
+ vf->priv->Coefs[1] + 256);
+ deNoise(mpi->planes[1], vf->priv->pmpi->planes[1], dmpi->planes[1],
+ vf->priv->Line, cw, ch,
+ mpi->stride[1], vf->priv->pmpi->stride[1], dmpi->stride[1],
+ vf->priv->Coefs[2] + 256,
+ vf->priv->Coefs[2] + 256,
+ vf->priv->Coefs[3] + 256);
+ deNoise(mpi->planes[2], vf->priv->pmpi->planes[2], dmpi->planes[2],
+ vf->priv->Line, cw, ch,
+ mpi->stride[2], vf->priv->pmpi->stride[2], dmpi->stride[2],
+ vf->priv->Coefs[2] + 256,
+ vf->priv->Coefs[2] + 256,
+ vf->priv->Coefs[3] + 256);
+
+ vf->priv->pmpi=dmpi; // save reference image
+ return vf_next_put_image(vf,dmpi, pts);
+}
+
+//===========================================================================//
+
+static int query_format(struct vf_instance *vf, unsigned int fmt){
+ switch(fmt)
+ {
+ case IMGFMT_YV12:
+ case IMGFMT_I420:
+ case IMGFMT_IYUV:
+ case IMGFMT_YVU9:
+ case IMGFMT_444P:
+ case IMGFMT_422P:
+ case IMGFMT_411P:
+ return vf_next_query_format(vf, fmt);
+ }
+ return 0;
+}
+
+
+#define ABS(A) ( (A) > 0 ? (A) : -(A) )
+
+static void PrecalcCoefs(int *Ct, double Dist25)
+{
+ int i;
+ double Gamma, Simil, C;
+
+ Gamma = log(0.25) / log(1.0 - Dist25/255.0);
+
+ for (i = -256; i <= 255; i++)
+ {
+ Simil = 1.0 - ABS(i) / 255.0;
+// Ct[256+i] = lround(pow(Simil, Gamma) * (double)i);
+ C = pow(Simil, Gamma) * (double)i;
+ Ct[256+i] = (C<0) ? (C-0.5) : (C+0.5);
+ }
+}
+
+
+static int vf_open(vf_instance_t *vf, char *args){
+ double LumSpac, LumTmp, ChromSpac, ChromTmp;
+ double Param1, Param2, Param3;
+
+ vf->config=config;
+ vf->put_image=put_image;
+ vf->query_format=query_format;
+ vf->uninit=uninit;
+ vf->priv=malloc(sizeof(struct vf_priv_s));
+ memset(vf->priv, 0, sizeof(struct vf_priv_s));
+
+ if (args)
+ {
+ switch(sscanf(args, "%lf:%lf:%lf",
+ &Param1, &Param2, &Param3
+ ))
+ {
+ case 0:
+ LumSpac = PARAM1_DEFAULT;
+ LumTmp = PARAM3_DEFAULT;
+
+ ChromSpac = PARAM2_DEFAULT;
+ ChromTmp = LumTmp * ChromSpac / LumSpac;
+ break;
+
+ case 1:
+ LumSpac = Param1;
+ LumTmp = PARAM3_DEFAULT * Param1 / PARAM1_DEFAULT;
+
+ ChromSpac = PARAM2_DEFAULT * Param1 / PARAM1_DEFAULT;
+ ChromTmp = LumTmp * ChromSpac / LumSpac;
+ break;
+
+ case 2:
+ LumSpac = Param1;
+ LumTmp = PARAM3_DEFAULT * Param1 / PARAM1_DEFAULT;
+
+ ChromSpac = Param2;
+ ChromTmp = LumTmp * ChromSpac / LumSpac;
+ break;
+
+ case 3:
+ LumSpac = Param1;
+ LumTmp = Param3;
+
+ ChromSpac = Param2;
+ ChromTmp = LumTmp * ChromSpac / LumSpac;
+ break;
+
+ default:
+ LumSpac = PARAM1_DEFAULT;
+ LumTmp = PARAM3_DEFAULT;
+
+ ChromSpac = PARAM2_DEFAULT;
+ ChromTmp = LumTmp * ChromSpac / LumSpac;
+ }
+ }
+ else
+ {
+ LumSpac = PARAM1_DEFAULT;
+ LumTmp = PARAM3_DEFAULT;
+
+ ChromSpac = PARAM2_DEFAULT;
+ ChromTmp = LumTmp * ChromSpac / LumSpac;
+ }
+
+ PrecalcCoefs(vf->priv->Coefs[0], LumSpac);
+ PrecalcCoefs(vf->priv->Coefs[1], LumTmp);
+ PrecalcCoefs(vf->priv->Coefs[2], ChromSpac);
+ PrecalcCoefs(vf->priv->Coefs[3], ChromTmp);
+
+ return 1;
+}
+
+const vf_info_t vf_info_denoise3d = {
+ "3D Denoiser (variable lowpass filter)",
+ "denoise3d",
+ "Daniel Moreno",
+ "",
+ vf_open,
+ NULL
+};
+
+//===========================================================================//
diff --git a/libavfilter/libmpcodecs/vf_detc.c b/libavfilter/libmpcodecs/vf_detc.c
new file mode 100644
index 0000000000..28d20e09b7
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_detc.c
@@ -0,0 +1,453 @@
+/*
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "config.h"
+#include "mp_msg.h"
+
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+
+#include "libvo/fastmemcpy.h"
+
+struct metrics {
+ int even;
+ int odd;
+ int noise;
+ int temp;
+};
+
+struct vf_priv_s {
+ int frame;
+ int drop, lastdrop;
+ struct metrics pm;
+ int thres[5];
+ int inframes, outframes;
+ int mode;
+ int (*analyze)(struct vf_priv_s *, mp_image_t *, mp_image_t *);
+ int needread;
+};
+
+#define COMPE(a,b,e) (abs((a)-(b)) < (((a)+(b))>>(e)))
+#define COMPARABLE(a,b) COMPE((a),(b),2)
+#define VERYCLOSE(a,b) COMPE((a),(b),3)
+
+#define OUTER_TC_NBHD(s) ( \
+ COMPARABLE((s)[-1].m.even,(s)[-1].m.odd) && \
+ COMPARABLE((s)[1].m.even,(s)[0].m.odd) && \
+ COMPARABLE((s)[2].m.even,(s)[1].m.odd) && \
+ COMPARABLE((s)[-1].m.noise,(s)[0].m.temp) && \
+ COMPARABLE((s)[2].m.noise,(s)[2].m.temp) )
+
+#define INNER_TC_NBHD(s,l,h) ( \
+ COMPARABLE((s)[0].m.even,(l)) && \
+ COMPARABLE((s)[2].m.odd,(l)) && ( \
+ COMPARABLE((s)[0].m.noise,(h)) || \
+ COMPARABLE((s)[1].m.noise,(h)) ) )
+
+enum {
+ TC_DROP,
+ TC_PROG,
+ TC_IL1,
+ TC_IL2
+};
+
+static void block_diffs(struct metrics *m, unsigned char *old, unsigned char *new, int os, int ns)
+{
+ int x, y, even=0, odd=0, noise, temp;
+ unsigned char *oldp, *newp;
+ m->noise = m->temp = 0;
+ for (x = 8; x; x--) {
+ oldp = old++;
+ newp = new++;
+ noise = temp = 0;
+ for (y = 4; y; y--) {
+ even += abs(newp[0]-oldp[0]);
+ odd += abs(newp[ns]-oldp[os]);
+ noise += newp[ns]-newp[0];
+ temp += oldp[os]-newp[0];
+ oldp += os<<1;
+ newp += ns<<1;
+ }
+ m->noise += abs(noise);
+ m->temp += abs(temp);
+ }
+ m->even = even;
+ m->odd = odd;
+}
+
+static void diff_planes(struct metrics *m, unsigned char *old, unsigned char *new, int w, int h, int os, int ns)
+{
+ int x, y, me=0, mo=0, mn=0, mt=0;
+ struct metrics l;
+ for (y = 0; y < h-7; y += 8) {
+ for (x = 0; x < w-7; x += 8) {
+ block_diffs(&l, old+x+y*os, new+x+y*ns, os, ns);
+ if (l.even > me) me = l.even;
+ if (l.odd > mo) mo = l.odd;
+ if (l.noise > mn) mn = l.noise;
+ if (l.temp > mt) mt = l.temp;
+ }
+ }
+ m->even = me;
+ m->odd = mo;
+ m->noise = mn;
+ m->temp = mt;
+}
+
+static void diff_fields(struct metrics *metr, mp_image_t *old, mp_image_t *new)
+{
+ struct metrics m, mu, mv;
+ diff_planes(&m, old->planes[0], new->planes[0],
+ new->w, new->h, old->stride[0], new->stride[0]);
+ if (new->flags & MP_IMGFLAG_PLANAR) {
+ diff_planes(&mu, old->planes[1], new->planes[1],
+ new->chroma_width, new->chroma_height,
+ old->stride[1], new->stride[1]);
+ diff_planes(&mv, old->planes[2], new->planes[2],
+ new->chroma_width, new->chroma_height,
+ old->stride[2], new->stride[2]);
+ if (mu.even > m.even) m.even = mu.even;
+ if (mu.odd > m.odd) m.odd = mu.odd;
+ if (mu.noise > m.noise) m.noise = mu.noise;
+ if (mu.temp > m.temp) m.temp = mu.temp;
+ if (mv.even > m.even) m.even = mv.even;
+ if (mv.odd > m.odd) m.odd = mv.odd;
+ if (mv.noise > m.noise) m.noise = mv.noise;
+ if (mv.temp > m.temp) m.temp = mv.temp;
+ }
+ *metr = m;
+}
+
+static void status(int f, struct metrics *m)
+{
+ mp_msg(MSGT_VFILTER, MSGL_V, "frame %d: e=%d o=%d n=%d t=%d\n",
+ f, m->even, m->odd, m->noise, m->temp);
+}
+
+static int analyze_fixed_pattern(struct vf_priv_s *p, mp_image_t *new, mp_image_t *old)
+{
+ if (p->frame >= 0) p->frame = (p->frame+1)%5;
+ mp_msg(MSGT_VFILTER, MSGL_V, "frame %d\n", p->frame);
+ switch (p->frame) {
+ case -1: case 0: case 1: case 2:
+ return TC_PROG;
+ case 3:
+ return TC_IL1;
+ case 4:
+ return TC_IL2;
+ }
+ return 0;
+}
+
+static int analyze_aggressive(struct vf_priv_s *p, mp_image_t *new, mp_image_t *old)
+{
+ struct metrics m, pm;
+
+ if (p->frame >= 0) p->frame = (p->frame+1)%5;
+
+ diff_fields(&m, old, new);
+
+ status(p->frame, &m);
+
+ pm = p->pm;
+ p->pm = m;
+
+ if (p->frame == 4) {
+ /* We need to break at scene changes, but is this a valid test? */
+ if ((m.even > p->thres[2]) && (m.odd > p->thres[2]) && (m.temp > p->thres[3])
+ && (m.temp > 5*pm.temp) && (m.temp*2 > m.noise)) {
+ mp_msg(MSGT_VFILTER, MSGL_V, "scene change breaking telecine!\n");
+ p->frame = -1;
+ return TC_DROP;
+ }
+ /* Thres. is to compensate for quantization errors when noise is low */
+ if (m.noise - m.temp > -p->thres[4]) {
+ if (COMPARABLE(m.even, pm.odd)) {
+ //mp_msg(MSGT_VFILTER, MSGL_V, "confirmed field match!\n");
+ return TC_IL2;
+ } else if ((m.even < p->thres[0]) && (m.odd < p->thres[0]) && VERYCLOSE(m.even, m.odd)
+ && VERYCLOSE(m.noise,m.temp) && VERYCLOSE(m.noise,pm.noise)) {
+ mp_msg(MSGT_VFILTER, MSGL_V, "interlaced frame appears in duplicate!!!\n");
+ p->pm = pm; /* hack :) */
+ p->frame = 3;
+ return TC_IL1;
+ }
+ } else {
+ mp_msg(MSGT_VFILTER, MSGL_V, "mismatched telecine fields!\n");
+ p->frame = -1;
+ }
+ }
+
+ if (2*m.even*m.temp < m.odd*m.noise) {
+ mp_msg(MSGT_VFILTER, MSGL_V, "caught telecine sync!\n");
+ p->frame = 3;
+ return TC_IL1;
+ }
+
+ if (p->frame < 3) {
+ if (m.noise > p->thres[3]) {
+ if (m.noise > 2*m.temp) {
+ mp_msg(MSGT_VFILTER, MSGL_V, "merging fields out of sequence!\n");
+ return TC_IL2;
+ }
+ if ((m.noise > 2*pm.noise) && (m.even > p->thres[2]) && (m.odd > p->thres[2])) {
+ mp_msg(MSGT_VFILTER, MSGL_V, "dropping horrible interlaced frame!\n");
+ return TC_DROP;
+ }
+ }
+ }
+
+ switch (p->frame) {
+ case -1:
+ if (4*m.noise > 5*m.temp) {
+ mp_msg(MSGT_VFILTER, MSGL_V, "merging fields out of sequence!\n");
+ return TC_IL2;
+ }
+ case 0:
+ case 1:
+ case 2:
+ return TC_PROG;
+ case 3:
+ if ((m.even > p->thres[1]) && (m.even > m.odd) && (m.temp > m.noise)) {
+ mp_msg(MSGT_VFILTER, MSGL_V, "lost telecine tracking!\n");
+ p->frame = -1;
+ return TC_PROG;
+ }
+ return TC_IL1;
+ case 4:
+ return TC_IL2;
+ }
+ return 0;
+}
+
+static void copy_image(mp_image_t *dmpi, mp_image_t *mpi, int field)
+{
+ switch (field) {
+ case 0:
+ my_memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h/2,
+ dmpi->stride[0]*2, mpi->stride[0]*2);
+ if (mpi->flags & MP_IMGFLAG_PLANAR) {
+ my_memcpy_pic(dmpi->planes[1], mpi->planes[1],
+ mpi->chroma_width, mpi->chroma_height/2,
+ dmpi->stride[1]*2, mpi->stride[1]*2);
+ my_memcpy_pic(dmpi->planes[2], mpi->planes[2],
+ mpi->chroma_width, mpi->chroma_height/2,
+ dmpi->stride[2]*2, mpi->stride[2]*2);
+ }
+ break;
+ case 1:
+ my_memcpy_pic(dmpi->planes[0]+dmpi->stride[0],
+ mpi->planes[0]+mpi->stride[0], mpi->w, mpi->h/2,
+ dmpi->stride[0]*2, mpi->stride[0]*2);
+ if (mpi->flags & MP_IMGFLAG_PLANAR) {
+ my_memcpy_pic(dmpi->planes[1]+dmpi->stride[1],
+ mpi->planes[1]+mpi->stride[1],
+ mpi->chroma_width, mpi->chroma_height/2,
+ dmpi->stride[1]*2, mpi->stride[1]*2);
+ my_memcpy_pic(dmpi->planes[2]+dmpi->stride[2],
+ mpi->planes[2]+mpi->stride[2],
+ mpi->chroma_width, mpi->chroma_height/2,
+ dmpi->stride[2]*2, mpi->stride[2]*2);
+ }
+ break;
+ case 2:
+ memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h,
+ dmpi->stride[0], mpi->stride[0]);
+ if (mpi->flags & MP_IMGFLAG_PLANAR) {
+ memcpy_pic(dmpi->planes[1], mpi->planes[1],
+ mpi->chroma_width, mpi->chroma_height,
+ dmpi->stride[1], mpi->stride[1]);
+ memcpy_pic(dmpi->planes[2], mpi->planes[2],
+ mpi->chroma_width, mpi->chroma_height,
+ dmpi->stride[2], mpi->stride[2]);
+ }
+ break;
+ }
+}
+
+static int do_put_image(struct vf_instance *vf, mp_image_t *dmpi)
+{
+ struct vf_priv_s *p = vf->priv;
+ int dropflag;
+
+ switch (p->drop) {
+ default:
+ dropflag = 0;
+ break;
+ case 1:
+ dropflag = (++p->lastdrop >= 5);
+ break;
+ case 2:
+ dropflag = (++p->lastdrop >= 5) && (4*p->inframes <= 5*p->outframes);
+ break;
+ }
+
+ if (dropflag) {
+ mp_msg(MSGT_VFILTER, MSGL_V, "drop! [%d/%d=%g]\n",
+ p->outframes, p->inframes, (float)p->outframes/p->inframes);
+ p->lastdrop = 0;
+ return 0;
+ }
+
+ p->outframes++;
+ return vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE);
+}
+
+static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
+{
+ int ret=0;
+ mp_image_t *dmpi;
+ struct vf_priv_s *p = vf->priv;
+
+ p->inframes++;
+
+ if (p->needread) dmpi = vf_get_image(vf->next, mpi->imgfmt,
+ MP_IMGTYPE_STATIC, MP_IMGFLAG_ACCEPT_STRIDE |
+ MP_IMGFLAG_PRESERVE | MP_IMGFLAG_READABLE,
+ mpi->width, mpi->height);
+ /* FIXME: is there a good way to get rid of static type? */
+ else dmpi = vf_get_image(vf->next, mpi->imgfmt,
+ MP_IMGTYPE_STATIC, MP_IMGFLAG_ACCEPT_STRIDE |
+ MP_IMGFLAG_PRESERVE, mpi->width, mpi->height);
+
+ switch (p->analyze(p, mpi, dmpi)) {
+ case TC_DROP:
+ /* Don't copy anything unless we'll need to read it. */
+ if (p->needread) copy_image(dmpi, mpi, 2);
+ p->lastdrop = 0;
+ break;
+ case TC_PROG:
+ /* Copy and display the whole frame. */
+ copy_image(dmpi, mpi, 2);
+ ret = do_put_image(vf, dmpi);
+ break;
+ case TC_IL1:
+ /* Only copy bottom field unless we need to read. */
+ if (p->needread) copy_image(dmpi, mpi, 2);
+ else copy_image(dmpi, mpi, 1);
+ p->lastdrop = 0;
+ break;
+ case TC_IL2:
+ /* Copy top field and show frame, then copy bottom if needed. */
+ copy_image(dmpi, mpi, 0);
+ ret = do_put_image(vf, dmpi);
+ if (p->needread) copy_image(dmpi, mpi, 1);
+ break;
+ }
+ return ret;
+}
+
+static int query_format(struct vf_instance *vf, unsigned int fmt)
+{
+ /* FIXME - figure out which other formats work */
+ switch (fmt) {
+ case IMGFMT_YV12:
+ case IMGFMT_IYUV:
+ case IMGFMT_I420:
+ return vf_next_query_format(vf, fmt);
+ }
+ return 0;
+}
+
+static int config(struct vf_instance *vf,
+ int width, int height, int d_width, int d_height,
+ unsigned int flags, unsigned int outfmt)
+{
+ return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
+}
+
+static void uninit(struct vf_instance *vf)
+{
+ free(vf->priv);
+}
+
+static struct {
+ const char *name;
+ int (*func)(struct vf_priv_s *p, mp_image_t *new, mp_image_t *old);
+ int needread;
+} anal_funcs[] = {
+ { "fixed", analyze_fixed_pattern, 0 },
+ { "aggressive", analyze_aggressive, 1 },
+ { NULL, NULL, 0 }
+};
+
+#define STARTVARS if (0)
+#define GETVAR(str, name, out, func) \
+ else if (!strncmp((str), name "=", sizeof(name))) \
+ (out) = (func)((str) + sizeof(name))
+
+static void parse_var(struct vf_priv_s *p, char *var)
+{
+ STARTVARS;
+ GETVAR(var, "dr", p->drop, atoi);
+ GETVAR(var, "t0", p->thres[0], atoi);
+ GETVAR(var, "t1", p->thres[1], atoi);
+ GETVAR(var, "t2", p->thres[2], atoi);
+ GETVAR(var, "t3", p->thres[3], atoi);
+ GETVAR(var, "t4", p->thres[4], atoi);
+ GETVAR(var, "fr", p->frame, atoi);
+ GETVAR(var, "am", p->mode, atoi);
+}
+
+static void parse_args(struct vf_priv_s *p, char *args)
+{
+ char *next, *orig;
+ for (args=orig=av_strdup(args); args; args=next) {
+ next = strchr(args, ':');
+ if (next) *next++ = 0;
+ parse_var(p, args);
+ }
+ free(orig);
+}
+
+static int vf_open(vf_instance_t *vf, char *args)
+{
+ struct vf_priv_s *p;
+ vf->config = config;
+ vf->put_image = put_image;
+ vf->query_format = query_format;
+ vf->uninit = uninit;
+ vf->default_reqs = VFCAP_ACCEPT_STRIDE;
+ vf->priv = p = calloc(1, sizeof(struct vf_priv_s));
+ p->frame = -1;
+ p->thres[0] = 440;
+ p->thres[1] = 720;
+ p->thres[2] = 2500;
+ p->thres[3] = 2500;
+ p->thres[4] = 800;
+ p->drop = 0;
+ p->mode = 1;
+ if (args) parse_args(p, args);
+ p->analyze = anal_funcs[p->mode].func;
+ p->needread = anal_funcs[p->mode].needread;
+ return 1;
+}
+
+const vf_info_t vf_info_detc = {
+ "de-telecine filter",
+ "detc",
+ "Rich Felker",
+ "",
+ vf_open,
+ NULL
+};
diff --git a/libavfilter/libmpcodecs/vf_dint.c b/libavfilter/libmpcodecs/vf_dint.c
new file mode 100644
index 0000000000..ac5bf54a54
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_dint.c
@@ -0,0 +1,214 @@
+/*
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+
+#include "config.h"
+#include "mp_msg.h"
+
+#include "mp_image.h"
+#include "img_format.h"
+#include "vf.h"
+
+struct vf_priv_s {
+ float sense; // first parameter
+ float level; // second parameter
+ unsigned int imgfmt;
+ int diff;
+ uint32_t max;
+// int dfr;
+// int rdfr;
+ int was_dint;
+ mp_image_t *pmpi; // previous mpi
+};
+
+#define MAXROWSIZE 1200
+
+static int config (struct vf_instance *vf,
+ int width, int height, int d_width, int d_height,
+ unsigned int flags, unsigned int outfmt)
+{
+ int rowsize;
+
+ vf->priv->pmpi = vf_get_image (vf->next, outfmt, MP_IMGTYPE_TEMP,
+ 0, width, height);
+ if (!(vf->priv->pmpi->flags & MP_IMGFLAG_PLANAR) &&
+ outfmt != IMGFMT_RGB32 && outfmt != IMGFMT_BGR32 &&
+ outfmt != IMGFMT_RGB24 && outfmt != IMGFMT_BGR24 &&
+ outfmt != IMGFMT_RGB16 && outfmt != IMGFMT_BGR16)
+ {
+ mp_msg (MSGT_VFILTER, MSGL_WARN, "Drop-interlaced filter doesn't support this outfmt :(\n");
+ return 0;
+ }
+ vf->priv->imgfmt = outfmt;
+ // recalculate internal values
+ rowsize = vf->priv->pmpi->width;
+ if (rowsize > MAXROWSIZE) rowsize = MAXROWSIZE;
+ vf->priv->max = vf->priv->level * vf->priv->pmpi->height * rowsize / 2;
+ if (vf->priv->pmpi->flags & MP_IMGFLAG_PLANAR) // planar YUV
+ vf->priv->diff = vf->priv->sense * 256;
+ else
+ vf->priv->diff = vf->priv->sense * (1 << (vf->priv->pmpi->bpp/3));
+ if (vf->priv->diff < 0) vf->priv->diff = 0;
+ if (!(vf->priv->pmpi->flags & MP_IMGFLAG_PLANAR) &&
+ vf->priv->pmpi->bpp < 24 && vf->priv->diff > 31)
+ vf->priv->diff = 31;
+ mp_msg (MSGT_VFILTER, MSGL_INFO, "Drop-interlaced: %dx%d diff %d / level %u\n",
+ vf->priv->pmpi->width, vf->priv->pmpi->height,
+ vf->priv->diff, (unsigned int)vf->priv->max);
+// vf->priv->rdfr = vf->priv->dfr = 0;
+ vf->priv->was_dint = 0;
+ return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
+}
+
+static int put_image (struct vf_instance *vf, mp_image_t *mpi, double pts)
+{
+ int8_t rrow0[MAXROWSIZE];
+ int8_t rrow1[MAXROWSIZE];
+ int8_t rrow2[MAXROWSIZE];
+ int8_t *row0 = rrow0, *row1 = rrow1, *row2 = rrow2/*, *row3 = rrow3*/;
+ int rowsize = mpi->width;
+ uint32_t nok = 0, max = vf->priv->max;
+ int diff = vf->priv->diff;
+ int i, j;
+ register int n1, n2;
+ unsigned char *cur0, *prv0;
+ register unsigned char *cur, *prv;
+
+ if (rowsize > MAXROWSIZE) rowsize = MAXROWSIZE;
+ // check if nothing to do
+ if (mpi->imgfmt == vf->priv->imgfmt)
+ {
+ cur0 = mpi->planes[0] + mpi->stride[0];
+ prv0 = mpi->planes[0];
+ for (j = 1; j < mpi->height && nok <= max; j++)
+ {
+ cur = cur0;
+ prv = prv0;
+ // analyse row (row0)
+ if (mpi->flags & MP_IMGFLAG_PLANAR) // planar YUV - check luminance
+ for (i = 0; i < rowsize; i++)
+ {
+ if (cur[0] - prv[0] > diff)
+ row0[i] = 1;
+ else if (cur[0] - prv[0] < -diff)
+ row0[i] = -1;
+ else
+ row0[i] = 0;
+ cur++;
+ prv++;
+ // check if row0 is 1 but row1 is 0, and row2 is 1 or row2 is 0
+ // but row3 is 1 so it's interlaced ptr (nok++)
+ if (j > 2 && row0[i] > 0 && (row1[i] < 0 || (!row1[i] && row2[i] < 0)) &&
+ (++nok) > max)
+ break;
+ }
+ else if (mpi->bpp < 24) // RGB/BGR 16 - check all colors
+ for (i = 0; i < rowsize; i++)
+ {
+ n1 = cur[0] + (cur[1]<<8);
+ n2 = prv[0] + (prv[1]<<8);
+ if ((n1&0x1f) - (n2&0x1f) > diff ||
+ ((n1>>5)&0x3f) - ((n2>>5)&0x3f) > diff ||
+ ((n1>>11)&0x1f) - ((n2>>11)&0x1f) > diff)
+ row0[i] = 1;
+ else if ((n1&0x1f) - (n2&0x1f) < -diff ||
+ ((n1>>5)&0x3f) - ((n2>>5)&0x3f) < -diff ||
+ ((n1>>11)&0x1f) - ((n2>>11)&0x1f) < -diff)
+ row0[i] = -1;
+ else
+ row0[i] = 0;
+ cur += 2;
+ prv += 2;
+ // check if row0 is 1 but row1 is 0, and row2 is 1 or row2 is 0
+ // but row3 is 1 so it's interlaced ptr (nok++)
+ if (j > 2 && row0[i] > 0 && (row1[i] < 0 || (!row1[i] && row2[i] < 0)) &&
+ (++nok) > max)
+ break;
+ }
+ else // RGB/BGR 24/32
+ for (i = 0; i < rowsize; i++)
+ {
+ if (cur[0] - prv[0] > diff ||
+ cur[1] - prv[1] > diff ||
+ cur[2] - prv[2] > diff)
+ row0[i] = 1;
+ else if (prv[0] - cur[0] > diff ||
+ prv[1] - cur[1] > diff ||
+ prv[2] - cur[2] > diff)
+ row0[i] = -1;
+ else
+ row0[i] = 0;
+ cur += mpi->bpp/8;
+ prv += mpi->bpp/8;
+ // check if row0 is 1 but row1 is 0, and row2 is 1 or row2 is 0
+ // but row3 is 1 so it's interlaced ptr (nok++)
+ if (j > 2 && row0[i] > 0 && (row1[i] < 0 || (!row1[i] && row2[i] < 0)) &&
+ (++nok) > max)
+ break;
+ }
+ cur0 += mpi->stride[0];
+ prv0 += mpi->stride[0];
+ // rotate rows
+ cur = row2;
+ row2 = row1;
+ row1 = row0;
+ row0 = cur;
+ }
+ }
+ // check if number of interlaced is above of max
+ if (nok > max)
+ {
+// vf->priv->dfr++;
+ if (vf->priv->was_dint < 1) // can skip at most one frame!
+ {
+ vf->priv->was_dint++;
+// vf->priv->rdfr++;
+// mp_msg (MSGT_VFILTER, MSGL_INFO, "DI:%d/%d ", vf->priv->rdfr, vf->priv->dfr);
+ return 0;
+ }
+ }
+ vf->priv->was_dint = 0;
+// mp_msg (MSGT_VFILTER, MSGL_INFO, "DI:%d/%d ", vf->priv->rdfr, vf->priv->dfr);
+ return vf_next_put_image (vf, mpi, pts);
+}
+
+static int vf_open(vf_instance_t *vf, char *args){
+ vf->config = config;
+ vf->put_image = put_image;
+// vf->default_reqs=VFCAP_ACCEPT_STRIDE;
+ vf->priv = malloc (sizeof(struct vf_priv_s));
+ vf->priv->sense = 0.1;
+ vf->priv->level = 0.15;
+ vf->priv->pmpi = NULL;
+ if (args)
+ sscanf (args, "%f:%f", &vf->priv->sense, &vf->priv->level);
+ return 1;
+}
+
+const vf_info_t vf_info_dint = {
+ "drop interlaced frames",
+ "dint",
+ "A.G.",
+ "",
+ vf_open,
+ NULL
+};
diff --git a/libavfilter/libmpcodecs/vf_divtc.c b/libavfilter/libmpcodecs/vf_divtc.c
new file mode 100644
index 0000000000..4c171d1728
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_divtc.c
@@ -0,0 +1,721 @@
+/*
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
+#include <math.h>
+
+#include "config.h"
+#include "mp_msg.h"
+#include "cpudetect.h"
+#include "libavutil/common.h"
+#include "mpbswap.h"
+
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+
+#include "libvo/fastmemcpy.h"
+
+const vf_info_t vf_info_divtc;
+
+struct vf_priv_s
+ {
+ int deghost, pass, phase, window, fcount, bcount, frameno, misscount,
+ ocount, sum[5];
+ double threshold;
+ FILE *file;
+ int8_t *bdata;
+ unsigned int *csdata;
+ int *history;
+ };
+
+/*
+ * diff_MMX and diff_C stolen from vf_decimate.c
+ */
+
+#if HAVE_MMX && HAVE_EBX_AVAILABLE
+static int diff_MMX(unsigned char *old, unsigned char *new, int os, int ns)
+ {
+ volatile short out[4];
+ __asm__ (
+ "movl $8, %%ecx \n\t"
+ "pxor %%mm4, %%mm4 \n\t"
+ "pxor %%mm7, %%mm7 \n\t"
+
+ ASMALIGN(4)
+ "1: \n\t"
+
+ "movq (%%"REG_S"), %%mm0 \n\t"
+ "movq (%%"REG_S"), %%mm2 \n\t"
+ "add %%"REG_a", %%"REG_S" \n\t"
+ "movq (%%"REG_D"), %%mm1 \n\t"
+ "add %%"REG_b", %%"REG_D" \n\t"
+ "psubusb %%mm1, %%mm2 \n\t"
+ "psubusb %%mm0, %%mm1 \n\t"
+ "movq %%mm2, %%mm0 \n\t"
+ "movq %%mm1, %%mm3 \n\t"
+ "punpcklbw %%mm7, %%mm0 \n\t"
+ "punpcklbw %%mm7, %%mm1 \n\t"
+ "punpckhbw %%mm7, %%mm2 \n\t"
+ "punpckhbw %%mm7, %%mm3 \n\t"
+ "paddw %%mm0, %%mm4 \n\t"
+ "paddw %%mm1, %%mm4 \n\t"
+ "paddw %%mm2, %%mm4 \n\t"
+ "paddw %%mm3, %%mm4 \n\t"
+
+ "decl %%ecx \n\t"
+ "jnz 1b \n\t"
+ "movq %%mm4, (%%"REG_d") \n\t"
+ "emms \n\t"
+ :
+ : "S" (old), "D" (new), "a" ((long)os), "b" ((long)ns), "d" (out)
+ : "%ecx", "memory"
+ );
+ return out[0]+out[1]+out[2]+out[3];
+ }
+#endif
+
+static int diff_C(unsigned char *old, unsigned char *new, int os, int ns)
+ {
+ int x, y, d=0;
+
+ for(y=8; y; y--, new+=ns, old+=os)
+ for(x=8; x; x--)
+ d+=abs(new[x]-old[x]);
+
+ return d;
+ }
+
+static int (*diff)(unsigned char *, unsigned char *, int, int);
+
+static int diff_plane(unsigned char *old, unsigned char *new,
+ int w, int h, int os, int ns, int arg)
+ {
+ int x, y, d, max=0, sum=0, n=0;
+
+ for(y=0; y<h-7; y+=8)
+ {
+ for(x=0; x<w-7; x+=8)
+ {
+ d=diff(old+x+y*os, new+x+y*ns, os, ns);
+ if(d>max) max=d;
+ sum+=d;
+ n++;
+ }
+ }
+
+ return (sum+n*max)/2;
+ }
+
+/*
+static unsigned int checksum_plane(unsigned char *p, unsigned char *z,
+ int w, int h, int s, int zs, int arg)
+ {
+ unsigned int shift, sum;
+ unsigned char *e;
+
+ for(sum=0; h; h--, p+=s-w)
+ for(e=p+w, shift=32; p<e;)
+ sum^=(*p++)<<(shift=(shift-8)&31);
+
+ return sum;
+ }
+*/
+
+static unsigned int checksum_plane(unsigned char *p, unsigned char *z,
+ int w, int h, int s, int zs, int arg)
+ {
+ unsigned int shift;
+ uint32_t sum, t;
+ unsigned char *e, *e2;
+#if HAVE_FAST_64BIT
+ typedef uint64_t wsum_t;
+#else
+ typedef uint32_t wsum_t;
+#endif
+ wsum_t wsum;
+
+ for(sum=0; h; h--, p+=s-w)
+ {
+ for(shift=0, e=p+w; (int)p&(sizeof(wsum_t)-1) && p<e;)
+ sum^=*p++<<(shift=(shift-8)&31);
+
+ for(wsum=0, e2=e-sizeof(wsum_t)+1; p<e2; p+=sizeof(wsum_t))
+ wsum^=*(wsum_t *)p;
+
+#if HAVE_FAST_64BIT
+ t=be2me_32((uint32_t)(wsum>>32^wsum));
+#else
+ t=be2me_32(wsum);
+#endif
+
+ for(sum^=(t<<shift|t>>(32-shift)); p<e;)
+ sum^=*p++<<(shift=(shift-8)&31);
+ }
+
+ return sum;
+ }
+
+static int deghost_plane(unsigned char *d, unsigned char *s,
+ int w, int h, int ds, int ss, int threshold)
+ {
+ int t;
+ unsigned char *e;
+
+ for(; h; h--, s+=ss-w, d+=ds-w)
+ for(e=d+w; d<e; d++, s++)
+ if(abs(*d-*s)>=threshold)
+ *d=(t=(*d<<1)-*s)<0?0:t>255?255:t;
+
+ return 0;
+ }
+
+static int copyop(unsigned char *d, unsigned char *s, int bpl, int h, int dstride, int sstride, int dummy) {
+ memcpy_pic(d, s, bpl, h, dstride, sstride);
+ return 0;
+}
+
+static int imgop(int(*planeop)(unsigned char *, unsigned char *,
+ int, int, int, int, int),
+ mp_image_t *dst, mp_image_t *src, int arg)
+ {
+ if(dst->flags&MP_IMGFLAG_PLANAR)
+ return planeop(dst->planes[0], src?src->planes[0]:0,
+ dst->w, dst->h,
+ dst->stride[0], src?src->stride[0]:0, arg)+
+ planeop(dst->planes[1], src?src->planes[1]:0,
+ dst->chroma_width, dst->chroma_height,
+ dst->stride[1], src?src->stride[1]:0, arg)+
+ planeop(dst->planes[2], src?src->planes[2]:0,
+ dst->chroma_width, dst->chroma_height,
+ dst->stride[2], src?src->stride[2]:0, arg);
+
+ return planeop(dst->planes[0], src?src->planes[0]:0,
+ dst->w*(dst->bpp/8), dst->h,
+ dst->stride[0], src?src->stride[0]:0, arg);
+ }
+
+/*
+ * Find the phase in which the telecine pattern fits best to the
+ * given 5 frame slice of frame difference measurements.
+ *
+ * If phase1 and phase2 are not negative, only the two specified
+ * phases are tested.
+ */
+
+static int match(struct vf_priv_s *p, int *diffs,
+ int phase1, int phase2, double *strength)
+ {
+ static const int pattern1[]={ -4, 1, 1, 1, 1 },
+ pattern2[]={ -2, -3, 4, 4, -3 }, *pattern;
+ int f, m, n, t[5];
+
+ pattern=p->deghost>0?pattern2:pattern1;
+
+ for(f=0; f<5; f++)
+ {
+ if(phase1<0 || phase2<0 || f==phase1 || f==phase2)
+ {
+ for(n=t[f]=0; n<5; n++)
+ t[f]+=diffs[n]*pattern[(n-f+5)%5];
+ }
+ else
+ t[f]=INT_MIN;
+ }
+
+ /* find the best match */
+ for(m=0, n=1; n<5; n++)
+ if(t[n]>t[m]) m=n;
+
+ if(strength)
+ {
+ /* the second best match */
+ for(f=m?0:1, n=f+1; n<5; n++)
+ if(n!=m && t[n]>t[f]) f=n;
+
+ *strength=(t[m]>0?(double)(t[m]-t[f])/t[m]:0.0);
+ }
+
+ return m;
+ }
+
+static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
+ {
+ mp_image_t *dmpi, *tmpi=0;
+ int n, m, f, newphase;
+ struct vf_priv_s *p=vf->priv;
+ unsigned int checksum;
+ double d;
+
+ dmpi=vf_get_image(vf->next, mpi->imgfmt,
+ MP_IMGTYPE_STATIC, MP_IMGFLAG_ACCEPT_STRIDE |
+ MP_IMGFLAG_PRESERVE | MP_IMGFLAG_READABLE,
+ mpi->width, mpi->height);
+ vf_clone_mpi_attributes(dmpi, mpi);
+
+ newphase=p->phase;
+
+ switch(p->pass)
+ {
+ case 1:
+ fprintf(p->file, "%08x %d\n",
+ (unsigned int)imgop((void *)checksum_plane, mpi, 0, 0),
+ p->frameno?imgop(diff_plane, dmpi, mpi, 0):0);
+ break;
+
+ case 2:
+ if(p->frameno/5>p->bcount)
+ {
+ mp_msg(MSGT_VFILTER, MSGL_ERR,
+ "\n%s: Log file ends prematurely! "
+ "Switching to one pass mode.\n", vf->info->name);
+ p->pass=0;
+ break;
+ }
+
+ checksum=(unsigned int)imgop((void *)checksum_plane, mpi, 0, 0);
+
+ if(checksum!=p->csdata[p->frameno])
+ {
+ for(f=0; f<100; f++)
+ if(p->frameno+f<p->fcount && p->csdata[p->frameno+f]==checksum)
+ break;
+ else if(p->frameno-f>=0 && p->csdata[p->frameno-f]==checksum)
+ {
+ f=-f;
+ break;
+ }
+
+ if(f<100)
+ {
+ mp_msg(MSGT_VFILTER, MSGL_INFO,
+ "\n%s: Mismatch with pass-1: %+d frame(s).\n",
+ vf->info->name, f);
+
+ p->frameno+=f;
+ p->misscount=0;
+ }
+ else if(p->misscount++>=30)
+ {
+ mp_msg(MSGT_VFILTER, MSGL_ERR,
+ "\n%s: Sync with pass-1 lost! "
+ "Switching to one pass mode.\n", vf->info->name);
+ p->pass=0;
+ break;
+ }
+ }
+
+ n=(p->frameno)/5;
+ if(n>=p->bcount) n=p->bcount-1;
+
+ newphase=p->bdata[n];
+ break;
+
+ default:
+ if(p->frameno)
+ {
+ int *sump=p->sum+p->frameno%5,
+ *histp=p->history+p->frameno%p->window;
+
+ *sump-=*histp;
+ *sump+=(*histp=imgop(diff_plane, dmpi, mpi, 0));
+ }
+
+ m=match(p, p->sum, -1, -1, &d);
+
+ if(d>=p->threshold)
+ newphase=m;
+ }
+
+ n=p->ocount++%5;
+
+ if(newphase!=p->phase && ((p->phase+4)%5<n)==((newphase+4)%5<n))
+ {
+ p->phase=newphase;
+ mp_msg(MSGT_VFILTER, MSGL_STATUS,
+ "\n%s: Telecine phase %d.\n", vf->info->name, p->phase);
+ }
+
+ switch((p->frameno++-p->phase+10)%5)
+ {
+ case 0:
+ imgop(copyop, dmpi, mpi, 0);
+ return 0;
+
+ case 4:
+ if(p->deghost>0)
+ {
+ tmpi=vf_get_image(vf->next, mpi->imgfmt,
+ MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE |
+ MP_IMGFLAG_READABLE,
+ mpi->width, mpi->height);
+ vf_clone_mpi_attributes(tmpi, mpi);
+
+ imgop(copyop, tmpi, mpi, 0);
+ imgop(deghost_plane, tmpi, dmpi, p->deghost);
+ imgop(copyop, dmpi, mpi, 0);
+ return vf_next_put_image(vf, tmpi, MP_NOPTS_VALUE);
+ }
+ }
+
+ imgop(copyop, dmpi, mpi, 0);
+ return vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE);
+ }
+
+static int analyze(struct vf_priv_s *p)
+ {
+ int *buf=0, *bp, bufsize=0, n, b, f, i, j, m, s;
+ unsigned int *cbuf=0, *cp;
+ int8_t *pbuf;
+ int8_t lbuf[256];
+ int sum[5];
+ double d;
+
+ /* read the file */
+
+ n=15;
+ while(fgets(lbuf, 256, p->file))
+ {
+ if(n>=bufsize-19)
+ {
+ bufsize=bufsize?bufsize*2:30000;
+ if((bp=realloc(buf, bufsize*sizeof *buf))) buf=bp;
+ if((cp=realloc(cbuf, bufsize*sizeof *cbuf))) cbuf=cp;
+
+ if(!bp || !cp)
+ {
+ mp_msg(MSGT_VFILTER, MSGL_FATAL, "%s: Not enough memory.\n",
+ vf_info_divtc.name);
+ free(buf);
+ free(cbuf);
+ return 0;
+ }
+ }
+ sscanf(lbuf, "%x %d", cbuf+n, buf+n);
+ n++;
+ }
+
+ if(!n)
+ {
+ mp_msg(MSGT_VFILTER, MSGL_FATAL, "%s: Empty 2-pass log file.\n",
+ vf_info_divtc.name);
+ free(buf);
+ free(cbuf);
+ return 0;
+ }
+
+ /* generate some dummy data past the beginning and end of the array */
+
+ buf+=15, cbuf+=15;
+ n-=15;
+
+ memcpy(buf-15, buf, 15*sizeof *buf);
+ memset(cbuf-15, 0, 15*sizeof *cbuf);
+
+ while(n%5)
+ buf[n]=buf[n-5], cbuf[n]=0, n++;
+
+ memcpy(buf+n, buf+n-15, 15*sizeof *buf);
+ memset(cbuf+n, 0, 15*sizeof *cbuf);
+
+ p->csdata=cbuf;
+ p->fcount=n;
+
+ /* array with one slot for each slice of 5 frames */
+
+ p->bdata=pbuf=malloc(p->bcount=b=(n/5));
+ memset(pbuf, 255, b);
+
+ /* resolve the automatic mode */
+
+ if(p->deghost<0)
+ {
+ int deghost=-p->deghost;
+ double s0=0.0, s1=0.0;
+
+ for(f=0; f<n; f+=5)
+ {
+ p->deghost=0; match(p, buf+f, -1, -1, &d); s0+=d;
+ p->deghost=1; match(p, buf+f, -1, -1, &d); s1+=d;
+ }
+
+ p->deghost=s1>s0?deghost:0;
+
+ mp_msg(MSGT_VFILTER, MSGL_INFO,
+ "%s: Deghosting %-3s (relative pattern strength %+.2fdB).\n",
+ vf_info_divtc.name,
+ p->deghost?"ON":"OFF",
+ 10.0*log10(s1/s0));
+ }
+
+ /* analyze the data */
+
+ for(f=0; f<5; f++)
+ for(sum[f]=0, n=-15; n<20; n+=5)
+ sum[f]+=buf[n+f];
+
+ for(f=0; f<b; f++)
+ {
+ m=match(p, sum, -1, -1, &d);
+
+ if(d>=p->threshold)
+ pbuf[f]=m;
+
+ if(f<b-1)
+ for(n=0; n<5; n++)
+ sum[n]=sum[n]-buf[5*(f-3)+n]+buf[5*(f+4)+n];
+ }
+
+ /* fill in the gaps */
+
+ /* the beginning */
+ for(f=0; f<b && pbuf[f]==-1; f++);
+
+ if(f==b)
+ {
+ free(buf-15);
+ mp_msg(MSGT_VFILTER, MSGL_FATAL, "%s: No telecine pattern found!\n",
+ vf_info_divtc.name);
+ return 0;
+ }
+
+ for(n=0; n<f; pbuf[n++]=pbuf[f]);
+
+ /* the end */
+ for(f=b-1; pbuf[f]==-1; f--);
+ for(n=f+1; n<b; pbuf[n++]=pbuf[f]);
+
+ /* the rest */
+ for(f=0;;)
+ {
+ while(f<b && pbuf[f]!=-1) f++;
+ if(f==b) break;
+ for(n=f; pbuf[n]==-1; n++);
+
+ if(pbuf[f-1]==pbuf[n])
+ {
+ /* just a gap */
+ while(f<n) pbuf[f++]=pbuf[n];
+ }
+ else
+ {
+ /* phase change, reanalyze the original data in the gap with zero
+ threshold for only the two phases that appear at the ends */
+
+ for(i=0; i<5; i++)
+ for(sum[i]=0, j=5*f-15; j<5*f; j+=5)
+ sum[i]+=buf[i+j];
+
+ for(i=f; i<n; i++)
+ {
+ pbuf[i]=match(p, sum, pbuf[f-1], pbuf[n], 0);
+
+ for(j=0; j<5; j++)
+ sum[j]=sum[j]-buf[5*(i-3)+j]+buf[5*(i+4)+j];
+ }
+
+ /* estimate the transition point by dividing the gap
+ in the same proportion as the number of matches of each kind */
+
+ for(i=f, m=f; i<n; i++)
+ if(pbuf[i]==pbuf[f-1]) m++;
+
+ /* find the transition of the right direction nearest to the
+ estimated point */
+
+ if(m>f && m<n)
+ {
+ for(j=m; j>f; j--)
+ if(pbuf[j-1]==pbuf[f-1] && pbuf[j]==pbuf[n]) break;
+ for(s=m; s<n; s++)
+ if(pbuf[s-1]==pbuf[f-1] && pbuf[s]==pbuf[n]) break;
+
+ m=(s-m<m-j)?s:j;
+ }
+
+ /* and rewrite the data to allow only this one transition */
+
+ for(i=f; i<m; i++)
+ pbuf[i]=pbuf[f-1];
+
+ for(; i<n; i++)
+ pbuf[i]=pbuf[n];
+
+ f=n;
+ }
+ }
+
+ free(buf-15);
+
+ return 1;
+ }
+
+static int query_format(struct vf_instance *vf, unsigned int fmt)
+ {
+ switch(fmt)
+ {
+ case IMGFMT_444P: case IMGFMT_IYUV: case IMGFMT_RGB24:
+ case IMGFMT_422P: case IMGFMT_UYVY: case IMGFMT_BGR24:
+ case IMGFMT_411P: case IMGFMT_YUY2: case IMGFMT_IF09:
+ case IMGFMT_YV12: case IMGFMT_I420: case IMGFMT_YVU9:
+ case IMGFMT_IUYV: case IMGFMT_Y800: case IMGFMT_Y8:
+ return vf_next_query_format(vf,fmt);
+ }
+
+ return 0;
+ }
+
+static void uninit(struct vf_instance *vf)
+ {
+ if(vf->priv)
+ {
+ if(vf->priv->file) fclose(vf->priv->file);
+ if(vf->priv->csdata) free(vf->priv->csdata-15);
+ free(vf->priv->bdata);
+ free(vf->priv->history);
+ free(vf->priv);
+ }
+ }
+
+static int vf_open(vf_instance_t *vf, char *args)
+ {
+ struct vf_priv_s *p;
+ const char *filename="framediff.log";
+ char *ap, *q, *a;
+
+ if(args && !(args=av_strdup(args)))
+ {
+ nomem:
+ mp_msg(MSGT_VFILTER, MSGL_FATAL,
+ "%s: Not enough memory.\n", vf->info->name);
+ fail:
+ uninit(vf);
+ free(args);
+ return 0;
+ }
+
+ vf->put_image=put_image;
+ vf->uninit=uninit;
+ vf->query_format=query_format;
+ vf->default_reqs=VFCAP_ACCEPT_STRIDE;
+ if(!(vf->priv=p=calloc(1, sizeof(struct vf_priv_s))))
+ goto nomem;
+
+ p->phase=5;
+ p->threshold=0.5;
+ p->window=30;
+
+ if((ap=args))
+ while(*ap)
+ {
+ q=ap;
+ if((ap=strchr(q, ':'))) *ap++=0; else ap=q+strlen(q);
+ if((a=strchr(q, '='))) *a++=0; else a=q+strlen(q);
+
+ switch(*q)
+ {
+ case 0: break;
+ case 'f': filename=a; break;
+ case 't': p->threshold=atof(a); break;
+ case 'w': p->window=5*(atoi(a)+4)/5; break;
+ case 'd': p->deghost=atoi(a); break;
+ case 'p':
+ if(q[1]=='h') p->phase=atoi(a);
+ else p->pass=atoi(a);
+ break;
+
+ case 'h':
+ mp_msg(MSGT_VFILTER, MSGL_INFO,
+ "\n%s options:\n\n"
+ "pass=1|2 - Use 2-pass mode.\n"
+ "file=filename - Set the 2-pass log file name "
+ "(default %s).\n"
+ "threshold=value - Set the pattern recognition "
+ "sensitivity (default %g).\n"
+ "deghost=value - Select deghosting threshold "
+ "(default %d).\n"
+ "window=numframes - Set the statistics window "
+ "for 1-pass mode (default %d).\n"
+ "phase=0|1|2|3|4 - Set the initial phase "
+ "for 1-pass mode (default %d).\n\n"
+ "The option names can be abbreviated to the shortest "
+ "unique prefix.\n\n",
+ vf->info->name, filename, p->threshold, p->deghost,
+ p->window, p->phase%5);
+ break;
+
+ default:
+ mp_msg(MSGT_VFILTER, MSGL_FATAL,
+ "%s: Unknown argument %s.\n", vf->info->name, q);
+ goto fail;
+ }
+ }
+
+ switch(p->pass)
+ {
+ case 1:
+ if(!(p->file=fopen(filename, "w")))
+ {
+ mp_msg(MSGT_VFILTER, MSGL_FATAL,
+ "%s: Can't create file %s.\n", vf->info->name, filename);
+ goto fail;
+ }
+
+ break;
+
+ case 2:
+ if(!(p->file=fopen(filename, "r")))
+ {
+ mp_msg(MSGT_VFILTER, MSGL_FATAL,
+ "%s: Can't open file %s.\n", vf->info->name, filename);
+ goto fail;
+ }
+
+ if(!analyze(p))
+ goto fail;
+
+ fclose(p->file);
+ p->file=0;
+ break;
+ }
+
+ if(p->window<5) p->window=5;
+ if(!(p->history=calloc(sizeof *p->history, p->window)))
+ goto nomem;
+
+ diff = diff_C;
+#if HAVE_MMX && HAVE_EBX_AVAILABLE
+ if(gCpuCaps.hasMMX) diff = diff_MMX;
+#endif
+
+ free(args);
+ return 1;
+ }
+
+const vf_info_t vf_info_divtc =
+ {
+ "inverse telecine for deinterlaced video",
+ "divtc",
+ "Ville Saari",
+ "",
+ vf_open,
+ NULL
+ };
diff --git a/libavfilter/libmpcodecs/vf_down3dright.c b/libavfilter/libmpcodecs/vf_down3dright.c
new file mode 100644
index 0000000000..4dba19a2f0
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_down3dright.c
@@ -0,0 +1,166 @@
+/*
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+
+#include "config.h"
+#include "mp_msg.h"
+#include "cpudetect.h"
+
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+
+#include "libvo/fastmemcpy.h"
+
+struct vf_priv_s {
+ int skipline;
+ int scalew;
+ int scaleh;
+};
+
+static void toright(unsigned char *dst[3], unsigned char *src[3],
+ int dststride[3], int srcstride[3],
+ int w, int h, struct vf_priv_s* p)
+{
+ int k;
+
+ for (k = 0; k < 3; k++) {
+ unsigned char* fromL = src[k];
+ unsigned char* fromR = src[k];
+ unsigned char* to = dst[k];
+ int src = srcstride[k];
+ int dst = dststride[k];
+ int ss;
+ unsigned int dd;
+ int i;
+
+ if (k > 0) {
+ i = h / 4 - p->skipline / 2;
+ ss = src * (h / 4 + p->skipline / 2);
+ dd = w / 4;
+ } else {
+ i = h / 2 - p->skipline;
+ ss = src * (h / 2 + p->skipline);
+ dd = w / 2;
+ }
+ fromR += ss;
+ for ( ; i > 0; i--) {
+ int j;
+ unsigned char* t = to;
+ unsigned char* sL = fromL;
+ unsigned char* sR = fromR;
+
+ if (p->scalew == 1) {
+ for (j = dd; j > 0; j--) {
+ *t++ = (sL[0] + sL[1]) / 2;
+ sL+=2;
+ }
+ for (j = dd ; j > 0; j--) {
+ *t++ = (sR[0] + sR[1]) / 2;
+ sR+=2;
+ }
+ } else {
+ for (j = dd * 2 ; j > 0; j--)
+ *t++ = *sL++;
+ for (j = dd * 2 ; j > 0; j--)
+ *t++ = *sR++;
+ }
+ if (p->scaleh == 1) {
+ fast_memcpy(to + dst, to, dst);
+ to += dst;
+ }
+ to += dst;
+ fromL += src;
+ fromR += src;
+ }
+ //printf("K %d %d %d %d %d \n", k, w, h, src, dst);
+ }
+}
+
+static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
+{
+ mp_image_t *dmpi;
+
+ // hope we'll get DR buffer:
+ dmpi=vf_get_image(vf->next, IMGFMT_YV12,
+ MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE |
+ (vf->priv->scaleh == 1) ? MP_IMGFLAG_READABLE : 0,
+ mpi->w * vf->priv->scalew,
+ mpi->h / vf->priv->scaleh - vf->priv->skipline);
+
+ toright(dmpi->planes, mpi->planes, dmpi->stride,
+ mpi->stride, mpi->w, mpi->h, vf->priv);
+
+ return vf_next_put_image(vf,dmpi, pts);
+}
+
+static int config(struct vf_instance *vf,
+ int width, int height, int d_width, int d_height,
+ unsigned int flags, unsigned int outfmt)
+{
+ /* FIXME - also support UYVY output? */
+ return vf_next_config(vf, width * vf->priv->scalew,
+ height / vf->priv->scaleh - vf->priv->skipline, d_width, d_height, flags, IMGFMT_YV12);
+}
+
+
+static int query_format(struct vf_instance *vf, unsigned int fmt)
+{
+ /* FIXME - really any YUV 4:2:0 input format should work */
+ switch (fmt) {
+ case IMGFMT_YV12:
+ case IMGFMT_IYUV:
+ case IMGFMT_I420:
+ return vf_next_query_format(vf, IMGFMT_YV12);
+ }
+ return 0;
+}
+
+static void uninit(struct vf_instance *vf)
+{
+ free(vf->priv);
+}
+
+static int vf_open(vf_instance_t *vf, char *args)
+{
+ vf->config=config;
+ vf->query_format=query_format;
+ vf->put_image=put_image;
+ vf->uninit=uninit;
+
+ vf->priv = calloc(1, sizeof (struct vf_priv_s));
+ vf->priv->skipline = 0;
+ vf->priv->scalew = 1;
+ vf->priv->scaleh = 2;
+ if (args) sscanf(args, "%d:%d:%d", &vf->priv->skipline, &vf->priv->scalew, &vf->priv->scaleh);
+
+ return 1;
+}
+
+const vf_info_t vf_info_down3dright = {
+ "convert stereo movie from top-bottom to left-right field",
+ "down3dright",
+ "Zdenek Kabelac",
+ "",
+ vf_open,
+ NULL
+};
diff --git a/libavfilter/libmpcodecs/vf_dsize.c b/libavfilter/libmpcodecs/vf_dsize.c
new file mode 100644
index 0000000000..7772b3732d
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_dsize.c
@@ -0,0 +1,123 @@
+/*
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+
+#include "config.h"
+#include "mp_msg.h"
+
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+
+struct vf_priv_s {
+ int w, h;
+ int method; // aspect method, 0 -> downscale, 1-> upscale. +2 -> original aspect.
+ int round;
+ float aspect;
+};
+
+static int config(struct vf_instance *vf,
+ int width, int height, int d_width, int d_height,
+ unsigned int flags, unsigned int outfmt)
+{
+ if (vf->priv->aspect < 0.001) { // did the user input aspect or w,h params
+ if (vf->priv->w == 0) vf->priv->w = d_width;
+ if (vf->priv->h == 0) vf->priv->h = d_height;
+ if (vf->priv->w == -1) vf->priv->w = width;
+ if (vf->priv->h == -1) vf->priv->h = height;
+ if (vf->priv->w == -2) vf->priv->w = vf->priv->h * (double)d_width / d_height;
+ if (vf->priv->w == -3) vf->priv->w = vf->priv->h * (double)width / height;
+ if (vf->priv->h == -2) vf->priv->h = vf->priv->w * (double)d_height / d_width;
+ if (vf->priv->h == -3) vf->priv->h = vf->priv->w * (double)height / width;
+ if (vf->priv->method > -1) {
+ double aspect = (vf->priv->method & 2) ? ((double)height / width) : ((double)d_height / d_width);
+ if ((vf->priv->h > vf->priv->w * aspect) ^ (vf->priv->method & 1)) {
+ vf->priv->h = vf->priv->w * aspect;
+ } else {
+ vf->priv->w = vf->priv->h / aspect;
+ }
+ }
+ if (vf->priv->round > 1) { // round up
+ vf->priv->w += (vf->priv->round - 1 - (vf->priv->w - 1) % vf->priv->round);
+ vf->priv->h += (vf->priv->round - 1 - (vf->priv->h - 1) % vf->priv->round);
+ }
+ d_width = vf->priv->w;
+ d_height = vf->priv->h;
+ } else {
+ if (vf->priv->aspect * height > width) {
+ d_width = height * vf->priv->aspect + .5;
+ d_height = height;
+ } else {
+ d_height = width / vf->priv->aspect + .5;
+ d_width = width;
+ }
+ }
+ return vf_next_config(vf, width, height, d_width, d_height, flags, outfmt);
+}
+
+static void uninit(vf_instance_t *vf) {
+ free(vf->priv);
+ vf->priv = NULL;
+}
+
+static int vf_open(vf_instance_t *vf, char *args)
+{
+ vf->config = config;
+ vf->draw_slice = vf_next_draw_slice;
+ vf->uninit = uninit;
+ //vf->default_caps = 0;
+ vf->priv = calloc(sizeof(struct vf_priv_s), 1);
+ vf->priv->aspect = 0.;
+ vf->priv->w = -1;
+ vf->priv->h = -1;
+ vf->priv->method = -1;
+ vf->priv->round = 1;
+ if (args) {
+ if (strchr(args, '/')) {
+ int w, h;
+ sscanf(args, "%d/%d", &w, &h);
+ vf->priv->aspect = (float)w/h;
+ } else if (strchr(args, '.')) {
+ sscanf(args, "%f", &vf->priv->aspect);
+ } else {
+ sscanf(args, "%d:%d:%d:%d", &vf->priv->w, &vf->priv->h, &vf->priv->method, &vf->priv->round);
+ }
+ }
+ if ((vf->priv->aspect < 0.) || (vf->priv->w < -3) || (vf->priv->h < -3) ||
+ ((vf->priv->w < -1) && (vf->priv->h < -1)) ||
+ (vf->priv->method < -1) || (vf->priv->method > 3) ||
+ (vf->priv->round < 0)) {
+ mp_msg(MSGT_VFILTER, MSGL_ERR, "[dsize] Illegal value(s): aspect: %f w: %d h: %d aspect_method: %d round: %d\n", vf->priv->aspect, vf->priv->w, vf->priv->h, vf->priv->method, vf->priv->round);
+ free(vf->priv); vf->priv = NULL;
+ return -1;
+ }
+ return 1;
+}
+
+const vf_info_t vf_info_dsize = {
+ "reset displaysize/aspect",
+ "dsize",
+ "Rich Felker",
+ "",
+ vf_open,
+ NULL
+};
diff --git a/libavfilter/libmpcodecs/vf_eq.c b/libavfilter/libmpcodecs/vf_eq.c
new file mode 100644
index 0000000000..df4e851363
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_eq.c
@@ -0,0 +1,240 @@
+/*
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+
+#include "config.h"
+#include "mp_msg.h"
+#include "cpudetect.h"
+
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+
+#include "libvo/video_out.h"
+
+static struct vf_priv_s {
+ unsigned char *buf;
+ int brightness;
+ int contrast;
+};
+
+#if HAVE_MMX
+static void process_MMX(unsigned char *dest, int dstride, unsigned char *src, int sstride,
+ int w, int h, int brightness, int contrast)
+{
+ int i;
+ int pel;
+ int dstep = dstride-w;
+ int sstep = sstride-w;
+ short brvec[4];
+ short contvec[4];
+
+ contrast = ((contrast+100)*256*16)/100;
+ brightness = ((brightness+100)*511)/200-128 - contrast/32;
+
+ brvec[0] = brvec[1] = brvec[2] = brvec[3] = brightness;
+ contvec[0] = contvec[1] = contvec[2] = contvec[3] = contrast;
+
+ while (h--) {
+ __asm__ volatile (
+ "movq (%5), %%mm3 \n\t"
+ "movq (%6), %%mm4 \n\t"
+ "pxor %%mm0, %%mm0 \n\t"
+ "movl %4, %%eax\n\t"
+ ASMALIGN(4)
+ "1: \n\t"
+ "movq (%0), %%mm1 \n\t"
+ "movq (%0), %%mm2 \n\t"
+ "punpcklbw %%mm0, %%mm1 \n\t"
+ "punpckhbw %%mm0, %%mm2 \n\t"
+ "psllw $4, %%mm1 \n\t"
+ "psllw $4, %%mm2 \n\t"
+ "pmulhw %%mm4, %%mm1 \n\t"
+ "pmulhw %%mm4, %%mm2 \n\t"
+ "paddw %%mm3, %%mm1 \n\t"
+ "paddw %%mm3, %%mm2 \n\t"
+ "packuswb %%mm2, %%mm1 \n\t"
+ "add $8, %0 \n\t"
+ "movq %%mm1, (%1) \n\t"
+ "add $8, %1 \n\t"
+ "decl %%eax \n\t"
+ "jnz 1b \n\t"
+ : "=r" (src), "=r" (dest)
+ : "0" (src), "1" (dest), "r" (w>>3), "r" (brvec), "r" (contvec)
+ : "%eax"
+ );
+
+ for (i = w&7; i; i--)
+ {
+ pel = ((*src++* contrast)>>12) + brightness;
+ if(pel&768) pel = (-pel)>>31;
+ *dest++ = pel;
+ }
+
+ src += sstep;
+ dest += dstep;
+ }
+ __asm__ volatile ( "emms \n\t" ::: "memory" );
+}
+#endif
+
+static void process_C(unsigned char *dest, int dstride, unsigned char *src, int sstride,
+ int w, int h, int brightness, int contrast)
+{
+ int i;
+ int pel;
+ int dstep = dstride-w;
+ int sstep = sstride-w;
+
+ contrast = ((contrast+100)*256*256)/100;
+ brightness = ((brightness+100)*511)/200-128 - contrast/512;
+
+ while (h--) {
+ for (i = w; i; i--)
+ {
+ pel = ((*src++* contrast)>>16) + brightness;
+ if(pel&768) pel = (-pel)>>31;
+ *dest++ = pel;
+ }
+ src += sstep;
+ dest += dstep;
+ }
+}
+
+static void (*process)(unsigned char *dest, int dstride, unsigned char *src, int sstride,
+ int w, int h, int brightness, int contrast);
+
+/* FIXME: add packed yuv version of process */
+
+static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
+{
+ mp_image_t *dmpi;
+
+ dmpi=vf_get_image(vf->next, mpi->imgfmt,
+ MP_IMGTYPE_EXPORT, 0,
+ mpi->w, mpi->h);
+
+ dmpi->stride[0] = mpi->stride[0];
+ dmpi->planes[1] = mpi->planes[1];
+ dmpi->planes[2] = mpi->planes[2];
+ dmpi->stride[1] = mpi->stride[1];
+ dmpi->stride[2] = mpi->stride[2];
+
+ if (!vf->priv->buf) vf->priv->buf = malloc(mpi->stride[0]*mpi->h);
+
+ if ((vf->priv->brightness == 0) && (vf->priv->contrast == 0))
+ dmpi->planes[0] = mpi->planes[0];
+ else {
+ dmpi->planes[0] = vf->priv->buf;
+ process(dmpi->planes[0], dmpi->stride[0],
+ mpi->planes[0], mpi->stride[0],
+ mpi->w, mpi->h, vf->priv->brightness,
+ vf->priv->contrast);
+ }
+
+ return vf_next_put_image(vf,dmpi, pts);
+}
+
+static int control(struct vf_instance *vf, int request, void* data)
+{
+ vf_equalizer_t *eq;
+
+ switch (request) {
+ case VFCTRL_SET_EQUALIZER:
+ eq = data;
+ if (!strcmp(eq->item,"brightness")) {
+ vf->priv->brightness = eq->value;
+ return CONTROL_TRUE;
+ }
+ else if (!strcmp(eq->item,"contrast")) {
+ vf->priv->contrast = eq->value;
+ return CONTROL_TRUE;
+ }
+ break;
+ case VFCTRL_GET_EQUALIZER:
+ eq = data;
+ if (!strcmp(eq->item,"brightness")) {
+ eq->value = vf->priv->brightness;
+ return CONTROL_TRUE;
+ }
+ else if (!strcmp(eq->item,"contrast")) {
+ eq->value = vf->priv->contrast;
+ return CONTROL_TRUE;
+ }
+ break;
+ }
+ return vf_next_control(vf, request, data);
+}
+
+static int query_format(struct vf_instance *vf, unsigned int fmt)
+{
+ switch (fmt) {
+ case IMGFMT_YVU9:
+ case IMGFMT_IF09:
+ case IMGFMT_YV12:
+ case IMGFMT_I420:
+ case IMGFMT_IYUV:
+ case IMGFMT_CLPL:
+ case IMGFMT_Y800:
+ case IMGFMT_Y8:
+ case IMGFMT_NV12:
+ case IMGFMT_NV21:
+ case IMGFMT_444P:
+ case IMGFMT_422P:
+ case IMGFMT_411P:
+ return vf_next_query_format(vf, fmt);
+ }
+ return 0;
+}
+
+static void uninit(struct vf_instance *vf)
+{
+ free(vf->priv->buf);
+ free(vf->priv);
+}
+
+static int vf_open(vf_instance_t *vf, char *args)
+{
+ vf->control=control;
+ vf->query_format=query_format;
+ vf->put_image=put_image;
+ vf->uninit=uninit;
+
+ vf->priv = malloc(sizeof(struct vf_priv_s));
+ memset(vf->priv, 0, sizeof(struct vf_priv_s));
+ if (args) sscanf(args, "%d:%d", &vf->priv->brightness, &vf->priv->contrast);
+
+ process = process_C;
+#if HAVE_MMX
+ if(gCpuCaps.hasMMX) process = process_MMX;
+#endif
+
+ return 1;
+}
+
+const vf_info_t vf_info_eq = {
+ "soft video equalizer",
+ "eq",
+ "Richard Felker",
+ "",
+ vf_open,
+};
diff --git a/libavfilter/libmpcodecs/vf_eq2.c b/libavfilter/libmpcodecs/vf_eq2.c
new file mode 100644
index 0000000000..fe4a89fb13
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_eq2.c
@@ -0,0 +1,519 @@
+/*
+ * Software equalizer (brightness, contrast, gamma, saturation)
+ *
+ * Hampa Hug <hampa@hampa.ch> (original LUT gamma/contrast/brightness filter)
+ * Daniel Moreno <comac@comac.darktech.org> (saturation, R/G/B gamma support)
+ * Richard Felker (original MMX contrast/brightness code (vf_eq.c))
+ * Michael Niedermayer <michalni@gmx.at> (LUT16)
+ *
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#include <inttypes.h>
+
+#include "config.h"
+#include "mp_msg.h"
+#include "cpudetect.h"
+
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+
+#define LUT16
+
+/* Per channel parameters */
+typedef struct eq2_param_t {
+ unsigned char lut[256];
+#ifdef LUT16
+ uint16_t lut16[256*256];
+#endif
+ int lut_clean;
+
+ void (*adjust) (struct eq2_param_t *par, unsigned char *dst, unsigned char *src,
+ unsigned w, unsigned h, unsigned dstride, unsigned sstride);
+
+ double c;
+ double b;
+ double g;
+ double w;
+} eq2_param_t;
+
+typedef struct vf_priv_s {
+ eq2_param_t param[3];
+
+ double contrast;
+ double brightness;
+ double saturation;
+
+ double gamma;
+ double gamma_weight;
+ double rgamma;
+ double ggamma;
+ double bgamma;
+
+ unsigned buf_w[3];
+ unsigned buf_h[3];
+ unsigned char *buf[3];
+} vf_eq2_t;
+
+
+static
+void create_lut (eq2_param_t *par)
+{
+ unsigned i;
+ double g, v;
+ double lw, gw;
+
+ g = par->g;
+ gw = par->w;
+ lw = 1.0 - gw;
+
+ if ((g < 0.001) || (g > 1000.0)) {
+ g = 1.0;
+ }
+
+ g = 1.0 / g;
+
+ for (i = 0; i < 256; i++) {
+ v = (double) i / 255.0;
+ v = par->c * (v - 0.5) + 0.5 + par->b;
+
+ if (v <= 0.0) {
+ par->lut[i] = 0;
+ }
+ else {
+ v = v*lw + pow(v, g)*gw;
+
+ if (v >= 1.0) {
+ par->lut[i] = 255;
+ }
+ else {
+ par->lut[i] = (unsigned char) (256.0 * v);
+ }
+ }
+ }
+
+#ifdef LUT16
+ for(i=0; i<256*256; i++){
+ par->lut16[i]= par->lut[i&0xFF] + (par->lut[i>>8]<<8);
+ }
+#endif
+
+ par->lut_clean = 1;
+}
+
+#if HAVE_MMX
+static
+void affine_1d_MMX (eq2_param_t *par, unsigned char *dst, unsigned char *src,
+ unsigned w, unsigned h, unsigned dstride, unsigned sstride)
+{
+ unsigned i;
+ int contrast, brightness;
+ unsigned dstep, sstep;
+ int pel;
+ short brvec[4];
+ short contvec[4];
+
+// printf("\nmmx: src=%p dst=%p w=%d h=%d ds=%d ss=%d\n",src,dst,w,h,dstride,sstride);
+
+ contrast = (int) (par->c * 256 * 16);
+ brightness = ((int) (100.0 * par->b + 100.0) * 511) / 200 - 128 - contrast / 32;
+
+ brvec[0] = brvec[1] = brvec[2] = brvec[3] = brightness;
+ contvec[0] = contvec[1] = contvec[2] = contvec[3] = contrast;
+
+ sstep = sstride - w;
+ dstep = dstride - w;
+
+ while (h-- > 0) {
+ __asm__ volatile (
+ "movq (%5), %%mm3 \n\t"
+ "movq (%6), %%mm4 \n\t"
+ "pxor %%mm0, %%mm0 \n\t"
+ "movl %4, %%eax\n\t"
+ ASMALIGN(4)
+ "1: \n\t"
+ "movq (%0), %%mm1 \n\t"
+ "movq (%0), %%mm2 \n\t"
+ "punpcklbw %%mm0, %%mm1 \n\t"
+ "punpckhbw %%mm0, %%mm2 \n\t"
+ "psllw $4, %%mm1 \n\t"
+ "psllw $4, %%mm2 \n\t"
+ "pmulhw %%mm4, %%mm1 \n\t"
+ "pmulhw %%mm4, %%mm2 \n\t"
+ "paddw %%mm3, %%mm1 \n\t"
+ "paddw %%mm3, %%mm2 \n\t"
+ "packuswb %%mm2, %%mm1 \n\t"
+ "add $8, %0 \n\t"
+ "movq %%mm1, (%1) \n\t"
+ "add $8, %1 \n\t"
+ "decl %%eax \n\t"
+ "jnz 1b \n\t"
+ : "=r" (src), "=r" (dst)
+ : "0" (src), "1" (dst), "r" (w >> 3), "r" (brvec), "r" (contvec)
+ : "%eax"
+ );
+
+ for (i = w & 7; i > 0; i--) {
+ pel = ((*src++ * contrast) >> 12) + brightness;
+ if (pel & 768) {
+ pel = (-pel) >> 31;
+ }
+ *dst++ = pel;
+ }
+
+ src += sstep;
+ dst += dstep;
+ }
+
+ __asm__ volatile ( "emms \n\t" ::: "memory" );
+}
+#endif
+
+static
+void apply_lut (eq2_param_t *par, unsigned char *dst, unsigned char *src,
+ unsigned w, unsigned h, unsigned dstride, unsigned sstride)
+{
+ unsigned i, j, w2;
+ unsigned char *lut;
+ uint16_t *lut16;
+
+ if (!par->lut_clean) {
+ create_lut (par);
+ }
+
+ lut = par->lut;
+#ifdef LUT16
+ lut16 = par->lut16;
+ w2= (w>>3)<<2;
+ for (j = 0; j < h; j++) {
+ uint16_t *src16= (uint16_t*)src;
+ uint16_t *dst16= (uint16_t*)dst;
+ for (i = 0; i < w2; i+=4) {
+ dst16[i+0] = lut16[src16[i+0]];
+ dst16[i+1] = lut16[src16[i+1]];
+ dst16[i+2] = lut16[src16[i+2]];
+ dst16[i+3] = lut16[src16[i+3]];
+ }
+ i <<= 1;
+#else
+ w2= (w>>3)<<3;
+ for (j = 0; j < h; j++) {
+ for (i = 0; i < w2; i+=8) {
+ dst[i+0] = lut[src[i+0]];
+ dst[i+1] = lut[src[i+1]];
+ dst[i+2] = lut[src[i+2]];
+ dst[i+3] = lut[src[i+3]];
+ dst[i+4] = lut[src[i+4]];
+ dst[i+5] = lut[src[i+5]];
+ dst[i+6] = lut[src[i+6]];
+ dst[i+7] = lut[src[i+7]];
+ }
+#endif
+ for (; i < w; i++) {
+ dst[i] = lut[src[i]];
+ }
+
+ src += sstride;
+ dst += dstride;
+ }
+}
+
+static
+int put_image (vf_instance_t *vf, mp_image_t *src, double pts)
+{
+ unsigned i;
+ vf_eq2_t *eq2;
+ mp_image_t *dst;
+ unsigned long img_n,img_c;
+
+ eq2 = vf->priv;
+
+ if ((eq2->buf_w[0] != src->w) || (eq2->buf_h[0] != src->h)) {
+ eq2->buf_w[0] = src->w;
+ eq2->buf_h[0] = src->h;
+ eq2->buf_w[1] = eq2->buf_w[2] = src->w >> src->chroma_x_shift;
+ eq2->buf_h[1] = eq2->buf_h[2] = src->h >> src->chroma_y_shift;
+ img_n = eq2->buf_w[0]*eq2->buf_h[0];
+ if(src->num_planes>1){
+ img_c = eq2->buf_w[1]*eq2->buf_h[1];
+ eq2->buf[0] = realloc (eq2->buf[0], img_n + 2*img_c);
+ eq2->buf[1] = eq2->buf[0] + img_n;
+ eq2->buf[2] = eq2->buf[1] + img_c;
+ } else
+ eq2->buf[0] = realloc (eq2->buf[0], img_n);
+ }
+
+ dst = vf_get_image (vf->next, src->imgfmt, MP_IMGTYPE_EXPORT, 0, src->w, src->h);
+
+ for (i = 0; i < ((src->num_planes>1)?3:1); i++) {
+ if (eq2->param[i].adjust != NULL) {
+ dst->planes[i] = eq2->buf[i];
+ dst->stride[i] = eq2->buf_w[i];
+
+ eq2->param[i].adjust (&eq2->param[i], dst->planes[i], src->planes[i],
+ eq2->buf_w[i], eq2->buf_h[i], dst->stride[i], src->stride[i]);
+ }
+ else {
+ dst->planes[i] = src->planes[i];
+ dst->stride[i] = src->stride[i];
+ }
+ }
+
+ return vf_next_put_image (vf, dst, pts);
+}
+
+static
+void check_values (eq2_param_t *par)
+{
+ /* yuck! floating point comparisons... */
+
+ if ((par->c == 1.0) && (par->b == 0.0) && (par->g == 1.0)) {
+ par->adjust = NULL;
+ }
+#if HAVE_MMX
+ else if (par->g == 1.0 && gCpuCaps.hasMMX) {
+ par->adjust = &affine_1d_MMX;
+ }
+#endif
+ else {
+ par->adjust = &apply_lut;
+ }
+}
+
+static
+void print_values (vf_eq2_t *eq2)
+{
+ mp_msg (MSGT_VFILTER, MSGL_V, "vf_eq2: c=%.2f b=%.2f g=%.4f s=%.2f \n",
+ eq2->contrast, eq2->brightness, eq2->gamma, eq2->saturation
+ );
+}
+
+static
+void set_contrast (vf_eq2_t *eq2, double c)
+{
+ eq2->contrast = c;
+ eq2->param[0].c = c;
+ eq2->param[0].lut_clean = 0;
+ check_values (&eq2->param[0]);
+ print_values (eq2);
+}
+
+static
+void set_brightness (vf_eq2_t *eq2, double b)
+{
+ eq2->brightness = b;
+ eq2->param[0].b = b;
+ eq2->param[0].lut_clean = 0;
+ check_values (&eq2->param[0]);
+ print_values (eq2);
+}
+
+static
+void set_gamma (vf_eq2_t *eq2, double g)
+{
+ eq2->gamma = g;
+
+ eq2->param[0].g = eq2->gamma * eq2->ggamma;
+ eq2->param[1].g = sqrt (eq2->bgamma / eq2->ggamma);
+ eq2->param[2].g = sqrt (eq2->rgamma / eq2->ggamma);
+ eq2->param[0].w = eq2->param[1].w = eq2->param[2].w = eq2->gamma_weight;
+
+ eq2->param[0].lut_clean = 0;
+ eq2->param[1].lut_clean = 0;
+ eq2->param[2].lut_clean = 0;
+
+ check_values (&eq2->param[0]);
+ check_values (&eq2->param[1]);
+ check_values (&eq2->param[2]);
+
+ print_values (eq2);
+}
+
+static
+void set_saturation (vf_eq2_t *eq2, double s)
+{
+ eq2->saturation = s;
+
+ eq2->param[1].c = s;
+ eq2->param[2].c = s;
+
+ eq2->param[1].lut_clean = 0;
+ eq2->param[2].lut_clean = 0;
+
+ check_values (&eq2->param[1]);
+ check_values (&eq2->param[2]);
+
+ print_values (eq2);
+}
+
+static
+int control (vf_instance_t *vf, int request, void *data)
+{
+ vf_equalizer_t *eq;
+
+ switch (request) {
+ case VFCTRL_SET_EQUALIZER:
+ eq = (vf_equalizer_t *) data;
+
+ if (strcmp (eq->item, "gamma") == 0) {
+ set_gamma (vf->priv, exp (log (8.0) * eq->value / 100.0));
+ return CONTROL_TRUE;
+ }
+ else if (strcmp (eq->item, "contrast") == 0) {
+ set_contrast (vf->priv, (1.0 / 100.0) * (eq->value + 100));
+ return CONTROL_TRUE;
+ }
+ else if (strcmp (eq->item, "brightness") == 0) {
+ set_brightness (vf->priv, (1.0 / 100.0) * eq->value);
+ return CONTROL_TRUE;
+ }
+ else if (strcmp (eq->item, "saturation") == 0) {
+ set_saturation (vf->priv, (double) (eq->value + 100) / 100.0);
+ return CONTROL_TRUE;
+ }
+ break;
+
+ case VFCTRL_GET_EQUALIZER:
+ eq = (vf_equalizer_t *) data;
+ if (strcmp (eq->item, "gamma") == 0) {
+ eq->value = (int) (100.0 * log (vf->priv->gamma) / log (8.0));
+ return CONTROL_TRUE;
+ }
+ else if (strcmp (eq->item, "contrast") == 0) {
+ eq->value = (int) (100.0 * vf->priv->contrast) - 100;
+ return CONTROL_TRUE;
+ }
+ else if (strcmp (eq->item, "brightness") == 0) {
+ eq->value = (int) (100.0 * vf->priv->brightness);
+ return CONTROL_TRUE;
+ }
+ else if (strcmp (eq->item, "saturation") == 0) {
+ eq->value = (int) (100.0 * vf->priv->saturation) - 100;
+ return CONTROL_TRUE;
+ }
+ break;
+ }
+
+ return vf_next_control (vf, request, data);
+}
+
+static
+int query_format (vf_instance_t *vf, unsigned fmt)
+{
+ switch (fmt) {
+ case IMGFMT_YVU9:
+ case IMGFMT_IF09:
+ case IMGFMT_YV12:
+ case IMGFMT_I420:
+ case IMGFMT_IYUV:
+ case IMGFMT_Y800:
+ case IMGFMT_Y8:
+ case IMGFMT_444P:
+ case IMGFMT_422P:
+ case IMGFMT_411P:
+ return vf_next_query_format (vf, fmt);
+ }
+
+ return 0;
+}
+
+static
+void uninit (vf_instance_t *vf)
+{
+ if (vf->priv != NULL) {
+ free (vf->priv->buf[0]);
+ free (vf->priv);
+ }
+}
+
+static
+int vf_open(vf_instance_t *vf, char *args)
+{
+ unsigned i;
+ vf_eq2_t *eq2;
+ double par[8];
+
+ vf->control = control;
+ vf->query_format = query_format;
+ vf->put_image = put_image;
+ vf->uninit = uninit;
+
+ vf->priv = malloc (sizeof (vf_eq2_t));
+ eq2 = vf->priv;
+
+ for (i = 0; i < 3; i++) {
+ eq2->buf[i] = NULL;
+ eq2->buf_w[i] = 0;
+ eq2->buf_h[i] = 0;
+
+ eq2->param[i].adjust = NULL;
+ eq2->param[i].c = 1.0;
+ eq2->param[i].b = 0.0;
+ eq2->param[i].g = 1.0;
+ eq2->param[i].lut_clean = 0;
+ }
+
+ eq2->contrast = 1.0;
+ eq2->brightness = 0.0;
+ eq2->saturation = 1.0;
+
+ eq2->gamma = 1.0;
+ eq2->gamma_weight = 1.0;
+ eq2->rgamma = 1.0;
+ eq2->ggamma = 1.0;
+ eq2->bgamma = 1.0;
+
+ if (args != NULL) {
+ par[0] = 1.0;
+ par[1] = 1.0;
+ par[2] = 0.0;
+ par[3] = 1.0;
+ par[4] = 1.0;
+ par[5] = 1.0;
+ par[6] = 1.0;
+ par[7] = 1.0;
+ sscanf (args, "%lf:%lf:%lf:%lf:%lf:%lf:%lf:%lf",
+ par, par + 1, par + 2, par + 3, par + 4, par + 5, par + 6, par + 7
+ );
+
+ eq2->rgamma = par[4];
+ eq2->ggamma = par[5];
+ eq2->bgamma = par[6];
+ eq2->gamma_weight = par[7];
+
+ set_gamma (eq2, par[0]);
+ set_contrast (eq2, par[1]);
+ set_brightness (eq2, par[2]);
+ set_saturation (eq2, par[3]);
+ }
+
+ return 1;
+}
+
+const vf_info_t vf_info_eq2 = {
+ "Software equalizer",
+ "eq2",
+ "Hampa Hug, Daniel Moreno, Richard Felker",
+ "",
+ &vf_open,
+ NULL
+};
diff --git a/libavfilter/libmpcodecs/vf_field.c b/libavfilter/libmpcodecs/vf_field.c
new file mode 100644
index 0000000000..fcf24be0bc
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_field.c
@@ -0,0 +1,89 @@
+/*
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "config.h"
+#include "mp_msg.h"
+
+#include "mp_image.h"
+#include "vf.h"
+
+struct vf_priv_s {
+ int field;
+};
+
+//===========================================================================//
+
+static int config(struct vf_instance *vf,
+ int width, int height, int d_width, int d_height,
+ unsigned int flags, unsigned int outfmt){
+ return vf_next_config(vf,width,height/2,d_width,d_height,flags,outfmt);
+}
+
+static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
+ vf->dmpi=vf_get_image(vf->next,mpi->imgfmt,
+ MP_IMGTYPE_EXPORT, MP_IMGFLAG_ACCEPT_STRIDE,
+ mpi->width, mpi->height/2);
+
+ // set up mpi as a double-stride image of dmpi:
+ vf->dmpi->planes[0]=mpi->planes[0]+mpi->stride[0]*vf->priv->field;
+ vf->dmpi->stride[0]=2*mpi->stride[0];
+ if(vf->dmpi->flags&MP_IMGFLAG_PLANAR){
+ vf->dmpi->planes[1]=mpi->planes[1]+
+ mpi->stride[1]*vf->priv->field;
+ vf->dmpi->stride[1]=2*mpi->stride[1];
+ vf->dmpi->planes[2]=mpi->planes[2]+
+ mpi->stride[2]*vf->priv->field;
+ vf->dmpi->stride[2]=2*mpi->stride[2];
+ } else
+ vf->dmpi->planes[1]=mpi->planes[1]; // passthru bgr8 palette!!!
+
+ return vf_next_put_image(vf,vf->dmpi, pts);
+}
+
+//===========================================================================//
+
+static void uninit(struct vf_instance *vf)
+{
+ free(vf->priv);
+}
+
+static int vf_open(vf_instance_t *vf, char *args){
+ vf->config=config;
+ vf->put_image=put_image;
+ vf->uninit=uninit;
+ vf->default_reqs=VFCAP_ACCEPT_STRIDE;
+ vf->priv=calloc(1, sizeof(struct vf_priv_s));
+ if (args) sscanf(args, "%d", &vf->priv->field);
+ vf->priv->field &= 1;
+ return 1;
+}
+
+const vf_info_t vf_info_field = {
+ "extract single field",
+ "field",
+ "Rich Felker",
+ "",
+ vf_open,
+ NULL
+};
+
+//===========================================================================//
diff --git a/libavfilter/libmpcodecs/vf_fil.c b/libavfilter/libmpcodecs/vf_fil.c
new file mode 100644
index 0000000000..7df7eb0af7
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_fil.c
@@ -0,0 +1,116 @@
+/*
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "config.h"
+#include "mp_msg.h"
+
+#include "mp_image.h"
+#include "vf.h"
+
+struct vf_priv_s {
+ int interleave;
+ int height;
+ int width;
+ int stridefactor;
+};
+
+//===========================================================================//
+
+static int config(struct vf_instance *vf,
+ int width, int height, int d_width, int d_height,
+ unsigned int flags, unsigned int outfmt){
+ int pixel_stride= (width+15)&~15; //FIXME this is ust a guess ... especially for non planar its somewhat bad one
+
+#if 0
+ if(mpi->flags&MP_IMGFLAG_PLANAR)
+ pixel_stride= mpi->stride[0];
+ else
+ pixel_stride= 8*mpi->stride[0] / mpi->bpp;
+
+#endif
+
+ if(vf->priv->interleave){
+ vf->priv->height= 2*height;
+ vf->priv->width= width - (pixel_stride/2);
+ vf->priv->stridefactor=1;
+ }else{
+ vf->priv->height= height/2;
+ vf->priv->width= width + pixel_stride;
+ vf->priv->stridefactor=4;
+ }
+//printf("hX %d %d %d\n", vf->priv->width,vf->priv->height,vf->priv->stridefactor);
+
+ return vf_next_config(vf, vf->priv->width, vf->priv->height,
+ (d_width*vf->priv->stridefactor)>>1, 2*d_height/vf->priv->stridefactor, flags, outfmt);
+}
+
+static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
+ if(mpi->flags&MP_IMGFLAG_DIRECT){
+ // we've used DR, so we're ready...
+ return vf_next_put_image(vf,(mp_image_t*)mpi->priv, pts);
+ }
+
+ vf->dmpi=vf_get_image(vf->next,mpi->imgfmt,
+ MP_IMGTYPE_EXPORT, MP_IMGFLAG_ACCEPT_STRIDE,
+ vf->priv->width, vf->priv->height);
+
+ // set up mpi as a double-stride image of dmpi:
+ vf->dmpi->planes[0]=mpi->planes[0];
+ vf->dmpi->stride[0]=(mpi->stride[0]*vf->priv->stridefactor)>>1;
+ if(vf->dmpi->flags&MP_IMGFLAG_PLANAR){
+ vf->dmpi->planes[1]=mpi->planes[1];
+ vf->dmpi->stride[1]=(mpi->stride[1]*vf->priv->stridefactor)>>1;
+ vf->dmpi->planes[2]=mpi->planes[2];
+ vf->dmpi->stride[2]=(mpi->stride[2]*vf->priv->stridefactor)>>1;
+ } else
+ vf->dmpi->planes[1]=mpi->planes[1]; // passthru bgr8 palette!!!
+
+ return vf_next_put_image(vf,vf->dmpi, pts);
+}
+
+//===========================================================================//
+
+static void uninit(struct vf_instance *vf)
+{
+ free(vf->priv);
+}
+
+static int vf_open(vf_instance_t *vf, char *args){
+ vf->config=config;
+ vf->put_image=put_image;
+ vf->uninit=uninit;
+ vf->default_reqs=VFCAP_ACCEPT_STRIDE;
+ vf->priv=calloc(1, sizeof(struct vf_priv_s));
+ vf->priv->interleave= args && (*args == 'i');
+ return 1;
+}
+
+const vf_info_t vf_info_fil = {
+ "fast (de)interleaver",
+ "fil",
+ "Michael Niedermayer",
+ "",
+ vf_open,
+ NULL
+};
+
+//===========================================================================//
diff --git a/libavfilter/libmpcodecs/vf_filmdint.c b/libavfilter/libmpcodecs/vf_filmdint.c
new file mode 100644
index 0000000000..70db246e1d
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_filmdint.c
@@ -0,0 +1,1461 @@
+/*
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/time.h>
+
+#include "config.h"
+#include "mp_msg.h"
+#include "cpudetect.h"
+
+#include "img_format.h"
+#include "mp_image.h"
+#include "vd.h"
+#include "vf.h"
+#include "cmmx.h"
+
+#include "libvo/fastmemcpy.h"
+
+#define NUM_STORED 4
+
+enum pu_field_type_t {
+ PU_1ST_OF_3,
+ PU_2ND_OF_3,
+ PU_3RD_OF_3,
+ PU_1ST_OF_2,
+ PU_2ND_OF_2,
+ PU_INTERLACED
+};
+
+struct metrics {
+ /* This struct maps to a packed word 64-bit MMX register */
+ unsigned short int even;
+ unsigned short int odd;
+ unsigned short int noise;
+ unsigned short int temp;
+} __attribute__ ((aligned (8)));
+
+struct frame_stats {
+ struct metrics tiny, low, high, bigger, twox, max;
+ struct { unsigned int even, odd, noise, temp; } sad;
+ unsigned short interlaced_high;
+ unsigned short interlaced_low;
+ unsigned short num_blocks;
+};
+
+struct vf_priv_s {
+ unsigned long inframes;
+ unsigned long outframes;
+ enum pu_field_type_t prev_type;
+ unsigned swapped, chroma_swapped;
+ unsigned luma_only;
+ unsigned verbose;
+ unsigned fast;
+ unsigned long w, h, cw, ch, stride, chroma_stride, nplanes;
+ unsigned long sad_thres;
+ unsigned long dint_thres;
+ unsigned char *memory_allocated;
+ unsigned char *planes[2*NUM_STORED][4];
+ unsigned char **old_planes;
+ unsigned long static_idx;
+ unsigned long temp_idx;
+ unsigned long crop_x, crop_y, crop_cx, crop_cy;
+ unsigned long export_count, merge_count;
+ unsigned long num_breaks;
+ unsigned long num_copies;
+ long in_inc, out_dec, iosync;
+ long num_fields;
+ long prev_fields;
+ long notout;
+ long mmx2;
+ unsigned small_bytes[2];
+ unsigned mmx_temp[2];
+ struct frame_stats stats[2];
+ struct metrics thres;
+ char chflag;
+ double diff_time, merge_time, decode_time, vo_time, filter_time;
+};
+
+#define PPZ { 2000, 2000, 0, 2000 }
+#define PPR { 2000, 2000, 0, 2000 }
+static const struct frame_stats ppzs = {PPZ,PPZ,PPZ,PPZ,PPZ,PPZ,PPZ,0,0,9999};
+static const struct frame_stats pprs = {PPR,PPR,PPR,PPR,PPR,PPR,PPR,0,0,9999};
+
+#ifndef MIN
+#define MIN(a,b) (((a)<(b))?(a):(b))
+#endif
+#ifndef MAX
+#define MAX(a,b) (((a)>(b))?(a):(b))
+#endif
+
+#define PDIFFUB(X,Y,T) "movq " #X "," #T "\n\t" \
+ "psubusb " #Y "," #T "\n\t" \
+ "psubusb " #X "," #Y "\n\t" \
+ "paddusb " #Y "," #T "\n\t"
+
+#define PDIFFUBT(X,Y,T) "movq " #X "," #T "\n\t" \
+ "psubusb " #Y "," #T "\n\t" \
+ "psubusb " #X "," #Y "\n\t" \
+ "paddusb " #T "," #Y "\n\t"
+
+#define PSUMBW(X,T,Z) "movq " #X "," #T "\n\t" \
+ "punpcklbw " #Z "," #X "\n\t" \
+ "punpckhbw " #Z "," #T "\n\t" \
+ "paddw " #T "," #X "\n\t" \
+ "movq " #X "," #T "\n\t" \
+ "psllq $32, " #T "\n\t" \
+ "paddw " #T "," #X "\n\t" \
+ "movq " #X "," #T "\n\t" \
+ "psllq $16, " #T "\n\t" \
+ "paddw " #T "," #X "\n\t" \
+ "psrlq $48, " #X "\n\t"
+
+#define PSADBW(X,Y,T,Z) PDIFFUBT(X,Y,T) PSUMBW(Y,T,Z)
+
+#define PMAXUB(X,Y) "psubusb " #X "," #Y "\n\tpaddusb " #X "," #Y "\n\t"
+#define PMAXUW(X,Y) "psubusw " #X "," #Y "\n\tpaddusw " #X "," #Y "\n\t"
+#define PMINUBT(X,Y,T) "movq " #Y "," #T "\n\t" \
+ "psubusb " #X "," #T "\n\t" \
+ "psubusb " #T "," #Y "\n\t"
+#define PAVGB(X,Y) "pavgusb " #X "," #Y "\n\t"
+
+static inline void
+get_metrics_c(unsigned char *a, unsigned char *b, int as, int bs, int lines,
+ struct metrics *m)
+{
+ a -= as;
+ b -= bs;
+ do {
+ cmmx_t old_po = *(cmmx_t*)(a );
+ cmmx_t po = *(cmmx_t*)(b );
+ cmmx_t e = *(cmmx_t*)(b + bs);
+ cmmx_t old_o = *(cmmx_t*)(a + 2*as);
+ cmmx_t o = *(cmmx_t*)(b + 2*bs);
+ cmmx_t ne = *(cmmx_t*)(b + 3*bs);
+ cmmx_t old_no = *(cmmx_t*)(a + 4*as);
+ cmmx_t no = *(cmmx_t*)(b + 4*bs);
+
+ cmmx_t qup_old_odd = p31avgb(old_o, old_po);
+ cmmx_t qup_odd = p31avgb( o, po);
+ cmmx_t qdown_old_odd = p31avgb(old_o, old_no);
+ cmmx_t qdown_odd = p31avgb( o, no);
+
+ cmmx_t qup_even = p31avgb(ne, e);
+ cmmx_t qdown_even = p31avgb(e, ne);
+
+ cmmx_t temp_up_diff = pdiffub(qdown_even, qup_old_odd);
+ cmmx_t noise_up_diff = pdiffub(qdown_even, qup_odd);
+ cmmx_t temp_down_diff = pdiffub(qup_even, qdown_old_odd);
+ cmmx_t noise_down_diff = pdiffub(qup_even, qdown_odd);
+
+ cmmx_t odd_diff = pdiffub(o, old_o);
+ m->odd += psumbw(odd_diff);
+ m->even += psadbw(e, *(cmmx_t*)(a+as));
+
+ temp_up_diff = pminub(temp_up_diff, temp_down_diff);
+ temp_up_diff = pminub(temp_up_diff, odd_diff);
+ m->temp += psumbw(temp_up_diff);
+ noise_up_diff = pminub(noise_up_diff, odd_diff);
+ noise_up_diff = pminub(noise_up_diff, noise_down_diff);
+
+ m->noise += psumbw(noise_up_diff);
+ a += 2*as;
+ b += 2*bs;
+ } while (--lines);
+}
+
+static inline void
+get_metrics_fast_c(unsigned char *a, unsigned char *b, int as, int bs,
+ int lines, struct metrics *m)
+{
+ a -= as;
+ b -= bs;
+ do {
+ cmmx_t old_po = (*(cmmx_t*)(a ) >> 1) & ~SIGN_BITS;
+ cmmx_t po = (*(cmmx_t*)(b ) >> 1) & ~SIGN_BITS;
+ cmmx_t old_e = (*(cmmx_t*)(a + as) >> 1) & ~SIGN_BITS;
+ cmmx_t e = (*(cmmx_t*)(b + bs) >> 1) & ~SIGN_BITS;
+ cmmx_t old_o = (*(cmmx_t*)(a + 2*as) >> 1) & ~SIGN_BITS;
+ cmmx_t o = (*(cmmx_t*)(b + 2*bs) >> 1) & ~SIGN_BITS;
+ cmmx_t ne = (*(cmmx_t*)(b + 3*bs) >> 1) & ~SIGN_BITS;
+ cmmx_t old_no = (*(cmmx_t*)(a + 4*as) >> 1) & ~SIGN_BITS;
+ cmmx_t no = (*(cmmx_t*)(b + 4*bs) >> 1) & ~SIGN_BITS;
+
+ cmmx_t qup_old_odd = p31avgb_s(old_o, old_po);
+ cmmx_t qup_odd = p31avgb_s( o, po);
+ cmmx_t qdown_old_odd = p31avgb_s(old_o, old_no);
+ cmmx_t qdown_odd = p31avgb_s( o, no);
+
+ cmmx_t qup_even = p31avgb_s(ne, e);
+ cmmx_t qdown_even = p31avgb_s(e, ne);
+
+ cmmx_t temp_up_diff = pdiffub_s(qdown_even, qup_old_odd);
+ cmmx_t noise_up_diff = pdiffub_s(qdown_even, qup_odd);
+ cmmx_t temp_down_diff = pdiffub_s(qup_even, qdown_old_odd);
+ cmmx_t noise_down_diff = pdiffub_s(qup_even, qdown_odd);
+
+ cmmx_t odd_diff = pdiffub_s(o, old_o);
+ m->odd += psumbw_s(odd_diff) << 1;
+ m->even += psadbw_s(e, old_e) << 1;
+
+ temp_up_diff = pminub_s(temp_up_diff, temp_down_diff);
+ temp_up_diff = pminub_s(temp_up_diff, odd_diff);
+ m->temp += psumbw_s(temp_up_diff) << 1;
+ noise_up_diff = pminub_s(noise_up_diff, odd_diff);
+ noise_up_diff = pminub_s(noise_up_diff, noise_down_diff);
+
+ m->noise += psumbw_s(noise_up_diff) << 1;
+ a += 2*as;
+ b += 2*bs;
+ } while (--lines);
+}
+
+static inline void
+get_metrics_faster_c(unsigned char *a, unsigned char *b, int as, int bs,
+ int lines, struct metrics *m)
+{
+ a -= as;
+ b -= bs;
+ do {
+ cmmx_t old_po = (*(cmmx_t*)(a )>>1) & ~SIGN_BITS;
+ cmmx_t po = (*(cmmx_t*)(b )>>1) & ~SIGN_BITS;
+ cmmx_t old_e = (*(cmmx_t*)(a + as)>>1) & ~SIGN_BITS;
+ cmmx_t e = (*(cmmx_t*)(b + bs)>>1) & ~SIGN_BITS;
+ cmmx_t old_o = (*(cmmx_t*)(a + 2*as)>>1) & ~SIGN_BITS;
+ cmmx_t o = (*(cmmx_t*)(b + 2*bs)>>1) & ~SIGN_BITS;
+ cmmx_t ne = (*(cmmx_t*)(b + 3*bs)>>1) & ~SIGN_BITS;
+
+ cmmx_t down_even = p31avgb_s(e, ne);
+ cmmx_t up_odd = p31avgb_s(o, po);
+ cmmx_t up_old_odd = p31avgb_s(old_o, old_po);
+
+ cmmx_t odd_diff = pdiffub_s(o, old_o);
+ cmmx_t temp_diff = pdiffub_s(down_even, up_old_odd);
+ cmmx_t noise_diff = pdiffub_s(down_even, up_odd);
+
+ m->even += psadbw_s(e, old_e) << 1;
+ m->odd += psumbw_s(odd_diff) << 1;
+
+ temp_diff = pminub_s(temp_diff, odd_diff);
+ noise_diff = pminub_s(noise_diff, odd_diff);
+
+ m->noise += psumbw_s(noise_diff) << 1;
+ m->temp += psumbw_s(temp_diff) << 1;
+ a += 2*as;
+ b += 2*bs;
+ } while (--lines);
+
+}
+
+static inline void
+get_block_stats(struct metrics *m, struct vf_priv_s *p, struct frame_stats *s)
+{
+ unsigned two_e = m->even + MAX(m->even , p->thres.even );
+ unsigned two_o = m->odd + MAX(m->odd , p->thres.odd );
+ unsigned two_n = m->noise + MAX(m->noise, p->thres.noise);
+ unsigned two_t = m->temp + MAX(m->temp , p->thres.temp );
+
+ unsigned e_big = m->even >= (m->odd + two_o + 1)/2;
+ unsigned o_big = m->odd >= (m->even + two_e + 1)/2;
+ unsigned n_big = m->noise >= (m->temp + two_t + 1)/2;
+ unsigned t_big = m->temp >= (m->noise + two_n + 1)/2;
+
+ unsigned e2x = m->even >= two_o;
+ unsigned o2x = m->odd >= two_e;
+ unsigned n2x = m->noise >= two_t;
+ unsigned t2x = m->temp >= two_n;
+
+ unsigned ntiny_e = m->even > p->thres.even ;
+ unsigned ntiny_o = m->odd > p->thres.odd ;
+ unsigned ntiny_n = m->noise > p->thres.noise;
+ unsigned ntiny_t = m->temp > p->thres.temp ;
+
+ unsigned nlow_e = m->even > 2*p->thres.even ;
+ unsigned nlow_o = m->odd > 2*p->thres.odd ;
+ unsigned nlow_n = m->noise > 2*p->thres.noise;
+ unsigned nlow_t = m->temp > 2*p->thres.temp ;
+
+ unsigned high_e = m->even > 4*p->thres.even ;
+ unsigned high_o = m->odd > 4*p->thres.odd ;
+ unsigned high_n = m->noise > 4*p->thres.noise;
+ unsigned high_t = m->temp > 4*p->thres.temp ;
+
+ unsigned low_il = !n_big && !t_big && ntiny_n && ntiny_t;
+ unsigned high_il = !n_big && !t_big && nlow_n && nlow_t;
+
+ if (low_il | high_il) {
+ s->interlaced_low += low_il;
+ s->interlaced_high += high_il;
+ } else {
+ s->tiny.even += ntiny_e;
+ s->tiny.odd += ntiny_o;
+ s->tiny.noise += ntiny_n;
+ s->tiny.temp += ntiny_t;
+
+ s->low .even += nlow_e ;
+ s->low .odd += nlow_o ;
+ s->low .noise += nlow_n ;
+ s->low .temp += nlow_t ;
+
+ s->high.even += high_e ;
+ s->high.odd += high_o ;
+ s->high.noise += high_n ;
+ s->high.temp += high_t ;
+
+ if (m->even >= p->sad_thres) s->sad.even += m->even ;
+ if (m->odd >= p->sad_thres) s->sad.odd += m->odd ;
+ if (m->noise >= p->sad_thres) s->sad.noise += m->noise;
+ if (m->temp >= p->sad_thres) s->sad.temp += m->temp ;
+ }
+ s->num_blocks++;
+ s->max.even = MAX(s->max.even , m->even );
+ s->max.odd = MAX(s->max.odd , m->odd );
+ s->max.noise = MAX(s->max.noise, m->noise);
+ s->max.temp = MAX(s->max.temp , m->temp );
+
+ s->bigger.even += e_big ;
+ s->bigger.odd += o_big ;
+ s->bigger.noise += n_big ;
+ s->bigger.temp += t_big ;
+
+ s->twox.even += e2x ;
+ s->twox.odd += o2x ;
+ s->twox.noise += n2x ;
+ s->twox.temp += t2x ;
+
+}
+
+static inline struct metrics
+block_metrics_c(unsigned char *a, unsigned char *b, int as, int bs,
+ int lines, struct vf_priv_s *p, struct frame_stats *s)
+{
+ struct metrics tm;
+ tm.even = tm.odd = tm.noise = tm.temp = 0;
+ get_metrics_c(a, b, as, bs, lines, &tm);
+ if (sizeof(cmmx_t) < 8)
+ get_metrics_c(a+4, b+4, as, bs, lines, &tm);
+ get_block_stats(&tm, p, s);
+ return tm;
+}
+
+static inline struct metrics
+block_metrics_fast_c(unsigned char *a, unsigned char *b, int as, int bs,
+ int lines, struct vf_priv_s *p, struct frame_stats *s)
+{
+ struct metrics tm;
+ tm.even = tm.odd = tm.noise = tm.temp = 0;
+ get_metrics_fast_c(a, b, as, bs, lines, &tm);
+ if (sizeof(cmmx_t) < 8)
+ get_metrics_fast_c(a+4, b+4, as, bs, lines, &tm);
+ get_block_stats(&tm, p, s);
+ return tm;
+}
+
+static inline struct metrics
+block_metrics_faster_c(unsigned char *a, unsigned char *b, int as, int bs,
+ int lines, struct vf_priv_s *p, struct frame_stats *s)
+{
+ struct metrics tm;
+ tm.even = tm.odd = tm.noise = tm.temp = 0;
+ get_metrics_faster_c(a, b, as, bs, lines, &tm);
+ if (sizeof(cmmx_t) < 8)
+ get_metrics_faster_c(a+4, b+4, as, bs, lines, &tm);
+ get_block_stats(&tm, p, s);
+ return tm;
+}
+
+#define MEQ(X,Y) ((X).even == (Y).even && (X).odd == (Y).odd && (X).temp == (Y).temp && (X).noise == (Y).noise)
+
+#define BLOCK_METRICS_TEMPLATE() \
+ __asm__ volatile("pxor %mm7, %mm7\n\t" /* The result is colleted in mm7 */ \
+ "pxor %mm6, %mm6\n\t" /* Temp to stay at 0 */ \
+ ); \
+ a -= as; \
+ b -= bs; \
+ do { \
+ __asm__ volatile( \
+ "movq (%0,%2), %%mm0\n\t" \
+ "movq (%1,%3), %%mm1\n\t" /* mm1 = even */ \
+ PSADBW(%%mm1, %%mm0, %%mm4, %%mm6) \
+ "paddusw %%mm0, %%mm7\n\t" /* even diff */ \
+ "movq (%0,%2,2), %%mm0\n\t" /* mm0 = old odd */ \
+ "movq (%1,%3,2), %%mm2\n\t" /* mm2 = odd */ \
+ "movq (%0), %%mm3\n\t" \
+ "psubusb %4, %%mm3\n\t" \
+ PAVGB(%%mm0, %%mm3) \
+ PAVGB(%%mm0, %%mm3) /* mm3 = qup old odd */ \
+ "movq %%mm0, %%mm5\n\t" \
+ PSADBW(%%mm2, %%mm0, %%mm4, %%mm6) \
+ "psllq $16, %%mm0\n\t" \
+ "paddusw %%mm0, %%mm7\n\t" \
+ "movq (%1), %%mm4\n\t" \
+ "lea (%0,%2,2), %0\n\t" \
+ "lea (%1,%3,2), %1\n\t" \
+ "psubusb %4, %%mm4\n\t" \
+ PAVGB(%%mm2, %%mm4) \
+ PAVGB(%%mm2, %%mm4) /* mm4 = qup odd */ \
+ PDIFFUBT(%%mm5, %%mm2, %%mm0) /* mm2 =abs(oldodd-odd) */ \
+ "movq (%1,%3), %%mm5\n\t" \
+ "psubusb %4, %%mm5\n\t" \
+ PAVGB(%%mm1, %%mm5) \
+ PAVGB(%%mm5, %%mm1) /* mm1 = qdown even */ \
+ PAVGB((%1,%3), %%mm5) /* mm5 = qup next even */ \
+ PDIFFUBT(%%mm1, %%mm3, %%mm0) /* mm3 = abs(qupoldo-qde) */ \
+ PDIFFUBT(%%mm1, %%mm4, %%mm0) /* mm4 = abs(qupodd-qde) */ \
+ PMINUBT(%%mm2, %%mm3, %%mm0) /* limit temp to odd diff */ \
+ PMINUBT(%%mm2, %%mm4, %%mm0) /* limit noise to odd diff */ \
+ "movq (%1,%3,2), %%mm2\n\t" \
+ "psubusb %4, %%mm2\n\t" \
+ PAVGB((%1), %%mm2) \
+ PAVGB((%1), %%mm2) /* mm2 = qdown odd */ \
+ "movq (%0,%2,2), %%mm1\n\t" \
+ "psubusb %4, %%mm1\n\t" \
+ PAVGB((%0), %%mm1) \
+ PAVGB((%0), %%mm1) /* mm1 = qdown old odd */ \
+ PDIFFUBT(%%mm5, %%mm2, %%mm0) /* mm2 = abs(qdo-qune) */ \
+ PDIFFUBT(%%mm5, %%mm1, %%mm0) /* mm1 = abs(qdoo-qune) */ \
+ PMINUBT(%%mm4, %%mm2, %%mm0) /* current */ \
+ PMINUBT(%%mm3, %%mm1, %%mm0) /* old */ \
+ PSUMBW(%%mm2, %%mm0, %%mm6) \
+ PSUMBW(%%mm1, %%mm0, %%mm6) \
+ "psllq $32, %%mm2\n\t" \
+ "psllq $48, %%mm1\n\t" \
+ "paddusw %%mm2, %%mm7\n\t" \
+ "paddusw %%mm1, %%mm7\n\t" \
+ : "=r" (a), "=r" (b) \
+ : "r"((x86_reg)as), "r"((x86_reg)bs), "m" (ones), "0"(a), "1"(b), "X"(*a), "X"(*b) \
+ ); \
+ } while (--lines);
+
+static inline struct metrics
+block_metrics_3dnow(unsigned char *a, unsigned char *b, int as, int bs,
+ int lines, struct vf_priv_s *p, struct frame_stats *s)
+{
+ struct metrics tm;
+#if !HAVE_AMD3DNOW
+ mp_msg(MSGT_VFILTER, MSGL_FATAL, "block_metrics_3dnow: internal error\n");
+#else
+ static const unsigned long long ones = 0x0101010101010101ull;
+
+ BLOCK_METRICS_TEMPLATE();
+ __asm__ volatile("movq %%mm7, %0\n\temms" : "=m" (tm));
+ get_block_stats(&tm, p, s);
+#endif
+ return tm;
+}
+
+#undef PSUMBW
+#undef PSADBW
+#undef PMAXUB
+#undef PMINUBT
+#undef PAVGB
+
+#define PSUMBW(X,T,Z) "psadbw " #Z "," #X "\n\t"
+#define PSADBW(X,Y,T,Z) "psadbw " #X "," #Y "\n\t"
+#define PMAXUB(X,Y) "pmaxub " #X "," #Y "\n\t"
+#define PMINUBT(X,Y,T) "pminub " #X "," #Y "\n\t"
+#define PAVGB(X,Y) "pavgb " #X "," #Y "\n\t"
+
+static inline struct metrics
+block_metrics_mmx2(unsigned char *a, unsigned char *b, int as, int bs,
+ int lines, struct vf_priv_s *p, struct frame_stats *s)
+{
+ struct metrics tm;
+#if !HAVE_MMX
+ mp_msg(MSGT_VFILTER, MSGL_FATAL, "block_metrics_mmx2: internal error\n");
+#else
+ static const unsigned long long ones = 0x0101010101010101ull;
+ x86_reg interlaced;
+ x86_reg prefetch_line = (((long)a>>3) & 7) + 10;
+#ifdef DEBUG
+ struct frame_stats ts = *s;
+#endif
+ __asm__ volatile("prefetcht0 (%0,%2)\n\t"
+ "prefetcht0 (%1,%3)\n\t" :
+ : "r" (a), "r" (b),
+ "r" (prefetch_line * as), "r" (prefetch_line * bs));
+
+ BLOCK_METRICS_TEMPLATE();
+
+ s->num_blocks++;
+ __asm__ volatile(
+ "movq %3, %%mm0\n\t"
+ "movq %%mm7, %%mm1\n\t"
+ "psubusw %%mm0, %%mm1\n\t"
+ "movq %%mm1, %%mm2\n\t"
+ "paddusw %%mm0, %%mm2\n\t"
+ "paddusw %%mm7, %%mm2\n\t"
+ "pshufw $0xb1, %%mm2, %%mm3\n\t"
+ "pavgw %%mm7, %%mm2\n\t"
+ "pshufw $0xb1, %%mm2, %%mm2\n\t"
+ "psubusw %%mm7, %%mm2\n\t"
+ "pcmpeqw %%mm6, %%mm2\n\t" /* 1 if >= 1.5x */
+ "psubusw %%mm7, %%mm3\n\t"
+ "pcmpeqw %%mm6, %%mm3\n\t" /* 1 if >= 2x */
+ "movq %1, %%mm4\n\t"
+ "movq %2, %%mm5\n\t"
+ "psubw %%mm2, %%mm4\n\t"
+ "psubw %%mm3, %%mm5\n\t"
+ "movq %%mm4, %1\n\t"
+ "movq %%mm5, %2\n\t"
+ "pxor %%mm4, %%mm4\n\t"
+ "pcmpeqw %%mm1, %%mm4\n\t" /* 1 if <= t */
+ "psubusw %%mm0, %%mm1\n\t"
+ "pxor %%mm5, %%mm5\n\t"
+ "pcmpeqw %%mm1, %%mm5\n\t" /* 1 if <= 2t */
+ "psubusw %%mm0, %%mm1\n\t"
+ "psubusw %%mm0, %%mm1\n\t"
+ "pcmpeqw %%mm6, %%mm1\n\t" /* 1 if <= 4t */
+ "pshufw $0xb1, %%mm2, %%mm0\n\t"
+ "por %%mm2, %%mm0\n\t" /* 1 if not close */
+ "punpckhdq %%mm0, %%mm0\n\t"
+ "movq %%mm4, %%mm2\n\t" /* tttt */
+ "punpckhdq %%mm5, %%mm2\n\t" /* ttll */
+ "por %%mm2, %%mm0\n\t"
+ "pcmpeqd %%mm6, %%mm0\n\t" /* close && big */
+ "psrlq $16, %%mm0\n\t"
+ "psrlw $15, %%mm0\n\t"
+ "movd %%mm0, %0\n\t"
+ : "=r" (interlaced), "=m" (s->bigger), "=m" (s->twox)
+ : "m" (p->thres)
+ );
+
+ if (interlaced) {
+ s->interlaced_high += interlaced >> 16;
+ s->interlaced_low += interlaced;
+ } else {
+ __asm__ volatile(
+ "pcmpeqw %%mm0, %%mm0\n\t" /* -1 */
+ "psubw %%mm0, %%mm4\n\t"
+ "psubw %%mm0, %%mm5\n\t"
+ "psubw %%mm0, %%mm1\n\t"
+ "paddw %0, %%mm4\n\t"
+ "paddw %1, %%mm5\n\t"
+ "paddw %2, %%mm1\n\t"
+ "movq %%mm4, %0\n\t"
+ "movq %%mm5, %1\n\t"
+ "movq %%mm1, %2\n\t"
+ : "=m" (s->tiny), "=m" (s->low), "=m" (s->high)
+ );
+
+ __asm__ volatile(
+ "pshufw $0, %2, %%mm0\n\t"
+ "psubusw %%mm7, %%mm0\n\t"
+ "pcmpeqw %%mm6, %%mm0\n\t" /* 0 if below sad_thres */
+ "pand %%mm7, %%mm0\n\t"
+ "movq %%mm0, %%mm1\n\t"
+ "punpcklwd %%mm6, %%mm0\n\t" /* sad even, odd */
+ "punpckhwd %%mm6, %%mm1\n\t" /* sad noise, temp */
+ "paddd %0, %%mm0\n\t"
+ "paddd %1, %%mm1\n\t"
+ "movq %%mm0, %0\n\t"
+ "movq %%mm1, %1\n\t"
+ : "=m" (s->sad.even), "=m" (s->sad.noise)
+ : "m" (p->sad_thres)
+ );
+ }
+
+ __asm__ volatile(
+ "movq %%mm7, (%1)\n\t"
+ PMAXUW((%0), %%mm7)
+ "movq %%mm7, (%0)\n\t"
+ "emms"
+ : : "r" (&s->max), "r" (&tm), "X" (s->max)
+ : "memory"
+ );
+#ifdef DEBUG
+ if (1) {
+ struct metrics cm;
+ a -= 7*as;
+ b -= 7*bs;
+ cm = block_metrics_c(a, b, as, bs, 4, p, &ts);
+ if (!MEQ(tm, cm))
+ mp_msg(MSGT_VFILTER, MSGL_WARN, "Bad metrics\n");
+ if (s) {
+# define CHECK(X) if (!MEQ(s->X, ts.X)) \
+ mp_msg(MSGT_VFILTER, MSGL_WARN, "Bad " #X "\n");
+ CHECK(tiny);
+ CHECK(low);
+ CHECK(high);
+ CHECK(sad);
+ CHECK(max);
+ }
+ }
+#endif
+#endif
+ return tm;
+}
+
+static inline int
+dint_copy_line_mmx2(unsigned char *dst, unsigned char *a, long bos,
+ long cos, int ds, int ss, int w, int t)
+{
+#if !HAVE_MMX
+ mp_msg(MSGT_VFILTER, MSGL_FATAL, "dint_copy_line_mmx2: internal error\n");
+ return 0;
+#else
+ unsigned long len = (w+7) >> 3;
+ int ret;
+ __asm__ volatile (
+ "pxor %%mm6, %%mm6 \n\t" /* deinterlaced pixel counter */
+ "movd %0, %%mm7 \n\t"
+ "punpcklbw %%mm7, %%mm7 \n\t"
+ "punpcklwd %%mm7, %%mm7 \n\t"
+ "punpckldq %%mm7, %%mm7 \n\t" /* mm7 = threshold */
+ : /* no output */
+ : "rm" (t)
+ );
+ do {
+ __asm__ volatile (
+ "movq (%0), %%mm0\n\t"
+ "movq (%0,%3,2), %%mm1\n\t"
+ "movq %%mm0, (%2)\n\t"
+ "pmaxub %%mm1, %%mm0\n\t"
+ "pavgb (%0), %%mm1\n\t"
+ "psubusb %%mm1, %%mm0\n\t"
+ "paddusb %%mm7, %%mm0\n\t" /* mm0 = max-avg+thr */
+ "movq (%0,%1), %%mm2\n\t"
+ "movq (%0,%5), %%mm3\n\t"
+ "movq %%mm2, %%mm4\n\t"
+ PDIFFUBT(%%mm1, %%mm2, %%mm5)
+ PDIFFUBT(%%mm1, %%mm3, %%mm5)
+ "pminub %%mm2, %%mm3\n\t"
+ "pcmpeqb %%mm3, %%mm2\n\t" /* b = min */
+ "pand %%mm2, %%mm4\n\t"
+ "pandn (%0,%5), %%mm2\n\t"
+ "por %%mm4, %%mm2\n\t"
+ "pminub %%mm0, %%mm3\n\t"
+ "pcmpeqb %%mm0, %%mm3\n\t" /* set to 1s if >= threshold */
+ "psubb %%mm3, %%mm6\n\t" /* count pixels above thr. */
+ "pand %%mm3, %%mm1 \n\t"
+ "pandn %%mm2, %%mm3 \n\t"
+ "por %%mm3, %%mm1 \n\t" /* avg if >= threshold */
+ "movq %%mm1, (%2,%4) \n\t"
+ : /* no output */
+ : "r" (a), "r" ((x86_reg)bos), "r" ((x86_reg)dst), "r" ((x86_reg)ss), "r" ((x86_reg)ds), "r" ((x86_reg)cos)
+ );
+ a += 8;
+ dst += 8;
+ } while (--len);
+
+ __asm__ volatile ("pxor %%mm7, %%mm7 \n\t"
+ "psadbw %%mm6, %%mm7 \n\t"
+ "movd %%mm7, %0 \n\t"
+ "emms \n\t"
+ : "=r" (ret)
+ );
+ return ret;
+#endif
+}
+
+static inline int
+dint_copy_line(unsigned char *dst, unsigned char *a, long bos,
+ long cos, int ds, int ss, int w, int t)
+{
+ unsigned long len = ((unsigned long)w+sizeof(cmmx_t)-1) / sizeof(cmmx_t);
+ cmmx_t dint_count = 0;
+ cmmx_t thr;
+ t |= t << 8;
+ thr = t | (t << 16);
+ if (sizeof(cmmx_t) > 4)
+ thr |= thr << (sizeof(cmmx_t)*4);
+ do {
+ cmmx_t e = *(cmmx_t*)a;
+ cmmx_t ne = *(cmmx_t*)(a+2*ss);
+ cmmx_t o = *(cmmx_t*)(a+bos);
+ cmmx_t oo = *(cmmx_t*)(a+cos);
+ cmmx_t maxe = pmaxub(e, ne);
+ cmmx_t avge = pavgb(e, ne);
+ cmmx_t max_diff = maxe - avge + thr; /* 0<=max-avg<128, thr<128 */
+ cmmx_t diffo = pdiffub(avge, o);
+ cmmx_t diffoo = pdiffub(avge, oo);
+ cmmx_t diffcmp = pcmpgtub(diffo, diffoo);
+ cmmx_t bo = ((oo ^ o) & diffcmp) ^ o;
+ cmmx_t diffbo = ((diffoo ^ diffo) & diffcmp) ^ diffo;
+ cmmx_t above_thr = ~pcmpgtub(max_diff, diffbo);
+ cmmx_t bo_or_avg = ((avge ^ bo) & above_thr) ^ bo;
+ dint_count += above_thr & ONE_BYTES;
+ *(cmmx_t*)(dst) = e;
+ *(cmmx_t*)(dst+ds) = bo_or_avg;
+ a += sizeof(cmmx_t);
+ dst += sizeof(cmmx_t);
+ } while (--len);
+ return psumbw(dint_count);
+}
+
+static int
+dint_copy_plane(unsigned char *d, unsigned char *a, unsigned char *b,
+ unsigned char *c, unsigned long w, unsigned long h,
+ unsigned long ds, unsigned long ss, unsigned long threshold,
+ long field, long mmx2)
+{
+ unsigned long ret = 0;
+ long bos = b - a;
+ long cos = c - a;
+ if (field) {
+ fast_memcpy(d, b, w);
+ h--;
+ d += ds;
+ a += ss;
+ }
+ bos += ss;
+ cos += ss;
+ while (h > 2) {
+ if (threshold >= 128) {
+ fast_memcpy(d, a, w);
+ fast_memcpy(d+ds, a+bos, w);
+ } else if (mmx2 == 1) {
+ ret += dint_copy_line_mmx2(d, a, bos, cos, ds, ss, w, threshold);
+ } else
+ ret += dint_copy_line(d, a, bos, cos, ds, ss, w, threshold);
+ h -= 2;
+ d += 2*ds;
+ a += 2*ss;
+ }
+ fast_memcpy(d, a, w);
+ if (h == 2)
+ fast_memcpy(d+ds, a+bos, w);
+ return ret;
+}
+
+static void
+copy_merge_fields(struct vf_priv_s *p, mp_image_t *dmpi,
+ unsigned char **old, unsigned char **new, unsigned long show)
+{
+ unsigned long threshold = 256;
+ unsigned long field = p->swapped;
+ unsigned long dint_pixels = 0;
+ unsigned char **other = old;
+ if (show >= 12 || !(show & 3))
+ show >>= 2, other = new, new = old;
+ if (show <= 2) { /* Single field: de-interlace */
+ threshold = p->dint_thres;
+ field ^= show & 1;
+ old = new;
+ } else if (show == 3)
+ old = new;
+ else
+ field ^= 1;
+ dint_pixels +=dint_copy_plane(dmpi->planes[0], old[0], new[0],
+ other[0], p->w, p->h, dmpi->stride[0],
+ p->stride, threshold, field, p->mmx2);
+ if (dmpi->flags & MP_IMGFLAG_PLANAR) {
+ if (p->luma_only)
+ old = new, other = new;
+ else
+ threshold = threshold/2 + 1;
+ field ^= p->chroma_swapped;
+ dint_copy_plane(dmpi->planes[1], old[1], new[1],
+ other[1], p->cw, p->ch, dmpi->stride[1],
+ p->chroma_stride, threshold, field, p->mmx2);
+ dint_copy_plane(dmpi->planes[2], old[2], new[2],
+ other[2], p->cw, p->ch, dmpi->stride[2],
+ p->chroma_stride, threshold, field, p->mmx2);
+ }
+ if (dint_pixels > 0 && p->verbose)
+ mp_msg(MSGT_VFILTER,MSGL_INFO,"Deinterlaced %lu pixels\n",dint_pixels);
+}
+
+static void diff_planes(struct vf_priv_s *p, struct frame_stats *s,
+ unsigned char *of, unsigned char *nf,
+ int w, int h, int os, int ns, int swapped)
+{
+ int i, y;
+ int align = -(long)nf & 7;
+ of += align;
+ nf += align;
+ w -= align;
+ if (swapped)
+ of -= os, nf -= ns;
+ i = (h*3 >> 7) & ~1;
+ of += i*os + 8;
+ nf += i*ns + 8;
+ h -= i;
+ w -= 16;
+
+ memset(s, 0, sizeof(*s));
+
+ for (y = (h-8) >> 3; y; y--) {
+ if (p->mmx2 == 1) {
+ for (i = 0; i < w; i += 8)
+ block_metrics_mmx2(of+i, nf+i, os, ns, 4, p, s);
+ } else if (p->mmx2 == 2) {
+ for (i = 0; i < w; i += 8)
+ block_metrics_3dnow(of+i, nf+i, os, ns, 4, p, s);
+ } else if (p->fast > 3) {
+ for (i = 0; i < w; i += 8)
+ block_metrics_faster_c(of+i, nf+i, os, ns, 4, p, s);
+ } else if (p->fast > 1) {
+ for (i = 0; i < w; i += 8)
+ block_metrics_fast_c(of+i, nf+i, os, ns, 4, p, s);
+ } else {
+ for (i = 0; i < w; i += 8)
+ block_metrics_c(of+i, nf+i, os, ns, 4, p, s);
+ }
+ of += 8*os;
+ nf += 8*ns;
+ }
+}
+
+#define METRICS(X) (X).even, (X).odd, (X).noise, (X).temp
+
+static void diff_fields(struct vf_priv_s *p, struct frame_stats *s,
+ unsigned char **old, unsigned char **new)
+{
+ diff_planes(p, s, old[0], new[0], p->w, p->h,
+ p->stride, p->stride, p->swapped);
+ s->sad.even = (s->sad.even * 16ul) / s->num_blocks;
+ s->sad.odd = (s->sad.odd * 16ul) / s->num_blocks;
+ s->sad.noise = (s->sad.noise * 16ul) / s->num_blocks;
+ s->sad.temp = (s->sad.temp * 16ul) / s->num_blocks;
+ if (p->verbose)
+ mp_msg(MSGT_VFILTER, MSGL_INFO, "%lu%c M:%d/%d/%d/%d - %d, "
+ "t:%d/%d/%d/%d, l:%d/%d/%d/%d, h:%d/%d/%d/%d, bg:%d/%d/%d/%d, "
+ "2x:%d/%d/%d/%d, sad:%d/%d/%d/%d, lil:%d, hil:%d, ios:%.1f\n",
+ p->inframes, p->chflag, METRICS(s->max), s->num_blocks,
+ METRICS(s->tiny), METRICS(s->low), METRICS(s->high),
+ METRICS(s->bigger), METRICS(s->twox), METRICS(s->sad),
+ s->interlaced_low, s->interlaced_high,
+ p->iosync / (double) p->in_inc);
+}
+
+static const char *parse_args(struct vf_priv_s *p, const char *args)
+{
+ args--;
+ while (args && *++args &&
+ (sscanf(args, "io=%lu:%lu", &p->out_dec, &p->in_inc) == 2 ||
+ sscanf(args, "diff_thres=%hu", &p->thres.even ) == 1 ||
+ sscanf(args, "comb_thres=%hu", &p->thres.noise) == 1 ||
+ sscanf(args, "sad_thres=%lu", &p->sad_thres ) == 1 ||
+ sscanf(args, "dint_thres=%lu", &p->dint_thres ) == 1 ||
+ sscanf(args, "fast=%u", &p->fast ) == 1 ||
+ sscanf(args, "mmx2=%lu", &p->mmx2 ) == 1 ||
+ sscanf(args, "luma_only=%u", &p->luma_only ) == 1 ||
+ sscanf(args, "verbose=%u", &p->verbose ) == 1 ||
+ sscanf(args, "crop=%lu:%lu:%lu:%lu", &p->w,
+ &p->h, &p->crop_x, &p->crop_y) == 4))
+ args = strchr(args, '/');
+ return args;
+}
+
+static unsigned long gcd(unsigned long x, unsigned long y)
+{
+ unsigned long t;
+ if (x > y)
+ t = x, x = y, y = t;
+
+ while (x) {
+ t = y % x;
+ y = x;
+ x = t;
+ }
+ return y;
+}
+
+static void init(struct vf_priv_s *p, mp_image_t *mpi)
+{
+ unsigned long i;
+ unsigned long plane_size, chroma_plane_size;
+ unsigned char *plane;
+ unsigned long cos, los;
+ p->crop_cx = p->crop_x >> mpi->chroma_x_shift;
+ p->crop_cy = p->crop_y >> mpi->chroma_y_shift;
+ if (mpi->flags & MP_IMGFLAG_ACCEPT_STRIDE) {
+ p->stride = (mpi->w + 15) & ~15;
+ p->chroma_stride = p->stride >> mpi->chroma_x_shift;
+ } else {
+ p->stride = mpi->width;
+ p->chroma_stride = mpi->chroma_width;
+ }
+ p->cw = p->w >> mpi->chroma_x_shift;
+ p->ch = p->h >> mpi->chroma_y_shift;
+ p->nplanes = 1;
+ p->static_idx = 0;
+ p->temp_idx = 0;
+ p->old_planes = p->planes[0];
+ plane_size = mpi->h * p->stride;
+ chroma_plane_size = mpi->flags & MP_IMGFLAG_PLANAR ?
+ mpi->chroma_height * p->chroma_stride : 0;
+ p->memory_allocated =
+ malloc(NUM_STORED * (plane_size+2*chroma_plane_size) +
+ 8*p->chroma_stride + 4096);
+ /* align to page boundary */
+ plane = p->memory_allocated + (-(long)p->memory_allocated & 4095);
+ memset(plane, 0, NUM_STORED * plane_size);
+ los = p->crop_x + p->crop_y * p->stride;
+ cos = p->crop_cx + p->crop_cy * p->chroma_stride;
+ for (i = 0; i != NUM_STORED; i++, plane += plane_size) {
+ p->planes[i][0] = plane;
+ p->planes[NUM_STORED + i][0] = plane + los;
+ }
+ if (mpi->flags & MP_IMGFLAG_PLANAR) {
+ p->nplanes = 3;
+ memset(plane, 0x80, NUM_STORED * 2 * chroma_plane_size);
+ for (i = 0; i != NUM_STORED; i++) {
+ p->planes[i][1] = plane;
+ p->planes[NUM_STORED + i][1] = plane + cos;
+ plane += chroma_plane_size;
+ p->planes[i][2] = plane;
+ p->planes[NUM_STORED + i][2] = plane + cos;
+ plane += chroma_plane_size;
+ }
+ }
+ p->out_dec <<= 2;
+ i = gcd(p->in_inc, p->out_dec);
+ p->in_inc /= i;
+ p->out_dec /= i;
+ p->iosync = 0;
+ p->num_fields = 3;
+}
+
+static inline double get_time(void)
+{
+ struct timeval tv;
+ gettimeofday(&tv, 0);
+ return tv.tv_sec + tv.tv_usec * 1e-6;
+}
+
+static void get_image(struct vf_instance *vf, mp_image_t *mpi)
+{
+ struct vf_priv_s *p = vf->priv;
+ static unsigned char **planes, planes_idx;
+
+ if (mpi->type == MP_IMGTYPE_STATIC) return;
+
+ if (!p->planes[0][0]) init(p, mpi);
+
+ if (mpi->type == MP_IMGTYPE_TEMP ||
+ (mpi->type == MP_IMGTYPE_IPB && !(mpi->flags & MP_IMGFLAG_READABLE)))
+ planes_idx = NUM_STORED/2 + (++p->temp_idx % (NUM_STORED/2));
+ else
+ planes_idx = ++p->static_idx % (NUM_STORED/2);
+ planes = p->planes[planes_idx];
+ mpi->priv = p->planes[NUM_STORED + planes_idx];
+ if (mpi->priv == p->old_planes) {
+ unsigned char **old_planes =
+ p->planes[NUM_STORED + 2 + (++p->temp_idx & 1)];
+ my_memcpy_pic(old_planes[0], p->old_planes[0],
+ p->w, p->h, p->stride, p->stride);
+ if (mpi->flags & MP_IMGFLAG_PLANAR) {
+ my_memcpy_pic(old_planes[1], p->old_planes[1],
+ p->cw, p->ch, p->chroma_stride, p->chroma_stride);
+ my_memcpy_pic(old_planes[2], p->old_planes[2],
+ p->cw, p->ch, p->chroma_stride, p->chroma_stride);
+ }
+ p->old_planes = old_planes;
+ p->num_copies++;
+ }
+ mpi->planes[0] = planes[0];
+ mpi->stride[0] = p->stride;
+ if (mpi->flags & MP_IMGFLAG_PLANAR) {
+ mpi->planes[1] = planes[1];
+ mpi->planes[2] = planes[2];
+ mpi->stride[1] = mpi->stride[2] = p->chroma_stride;
+ }
+ mpi->width = p->stride;
+
+ mpi->flags |= MP_IMGFLAG_DIRECT;
+ mpi->flags &= ~MP_IMGFLAG_DRAW_CALLBACK;
+}
+
+static inline long
+cmpe(unsigned long x, unsigned long y, unsigned long err, unsigned long e)
+{
+ long diff = x-y;
+ long unit = ((x+y+err) >> e);
+ long ret = (diff > unit) - (diff < -unit);
+ unit >>= 1;
+ return ret + (diff > unit) - (diff < -unit);
+}
+
+static unsigned long
+find_breaks(struct vf_priv_s *p, struct frame_stats *s)
+{
+ struct frame_stats *ps = &p->stats[(p->inframes-1) & 1];
+ long notfilm = 5*p->in_inc - p->out_dec;
+ unsigned long n = s->num_blocks >> 8;
+ unsigned long sad_comb_cmp = cmpe(s->sad.temp, s->sad.noise, 512, 1);
+ unsigned long ret = 8;
+
+ if (cmpe(s->sad.temp, s->sad.even, 512, 1) > 0)
+ mp_msg(MSGT_VFILTER, MSGL_WARN,
+ "@@@@@@@@ Bottom-first field??? @@@@@@@@\n");
+ if (s->sad.temp > 1000 && s->sad.noise > 1000)
+ return 3;
+ if (s->interlaced_high >= 2*n && s->sad.temp > 256 && s->sad.noise > 256)
+ return 3;
+ if (s->high.noise > s->num_blocks/4 && s->sad.noise > 10000 &&
+ s->sad.noise > 2*s->sad.even && s->sad.noise > 2*ps->sad.odd) {
+ // Mid-frame scene change
+ if (s->tiny.temp + s->interlaced_low < n ||
+ s->low.temp + s->interlaced_high < n/4 ||
+ s->high.temp + s->interlaced_high < n/8 ||
+ s->sad.temp < 160)
+ return 1;
+ return 3;
+ }
+ if (s->high.temp > s->num_blocks/4 && s->sad.temp > 10000 &&
+ s->sad.temp > 2*ps->sad.odd && s->sad.temp > 2*ps->sad.even) {
+ // Start frame scene change
+ if (s->tiny.noise + s->interlaced_low < n ||
+ s->low.noise + s->interlaced_high < n/4 ||
+ s->high.noise + s->interlaced_high < n/8 ||
+ s->sad.noise < 160)
+ return 2;
+ return 3;
+ }
+ if (sad_comb_cmp == 2)
+ return 2;
+ if (sad_comb_cmp == -2)
+ return 1;
+
+ if (s->tiny.odd > 3*MAX(n,s->tiny.even) + s->interlaced_low)
+ return 1;
+ if (s->tiny.even > 3*MAX(n,s->tiny.odd)+s->interlaced_low &&
+ (!sad_comb_cmp || (s->low.noise <= n/4 && s->low.temp <= n/4)))
+ return 4;
+
+ if (s->sad.noise < 64 && s->sad.temp < 64 &&
+ s->low.noise <= n/2 && s->high.noise <= n/4 &&
+ s->low.temp <= n/2 && s->high.temp <= n/4)
+ goto still;
+
+ if (s->tiny.temp > 3*MAX(n,s->tiny.noise) + s->interlaced_low)
+ return 2;
+ if (s->tiny.noise > 3*MAX(n,s->tiny.temp) + s->interlaced_low)
+ return 1;
+
+ if (s->low.odd > 3*MAX(n/4,s->low.even) + s->interlaced_high)
+ return 1;
+ if (s->low.even > 3*MAX(n/4,s->low.odd)+s->interlaced_high &&
+ s->sad.even > 2*s->sad.odd &&
+ (!sad_comb_cmp || (s->low.noise <= n/4 && s->low.temp <= n/4)))
+ return 4;
+
+ if (s->low.temp > 3*MAX(n/4,s->low.noise) + s->interlaced_high)
+ return 2;
+ if (s->low.noise > 3*MAX(n/4,s->low.temp) + s->interlaced_high)
+ return 1;
+
+ if (sad_comb_cmp == 1 && s->sad.noise < 64)
+ return 2;
+ if (sad_comb_cmp == -1 && s->sad.temp < 64)
+ return 1;
+
+ if (s->tiny.odd <= n || (s->tiny.noise <= n/2 && s->tiny.temp <= n/2)) {
+ if (s->interlaced_low <= n) {
+ if (p->num_fields == 1)
+ goto still;
+ if (s->tiny.even <= n || ps->tiny.noise <= n/2)
+ /* Still frame */
+ goto still;
+ if (s->bigger.even >= 2*MAX(n,s->bigger.odd) + s->interlaced_low)
+ return 4;
+ if (s->low.even >= 2*n + s->interlaced_low)
+ return 4;
+ goto still;
+ }
+ }
+ if (s->low.odd <= n/4) {
+ if (s->interlaced_high <= n/4) {
+ if (p->num_fields == 1)
+ goto still;
+ if (s->low.even <= n/4)
+ /* Still frame */
+ goto still;
+ if (s->bigger.even >= 2*MAX(n/4,s->bigger.odd)+s->interlaced_high)
+ return 4;
+ if (s->low.even >= n/2 + s->interlaced_high)
+ return 4;
+ goto still;
+ }
+ }
+ if (s->bigger.temp > 2*MAX(n,s->bigger.noise) + s->interlaced_low)
+ return 2;
+ if (s->bigger.noise > 2*MAX(n,s->bigger.temp) + s->interlaced_low)
+ return 1;
+ if (s->bigger.temp > 2*MAX(n,s->bigger.noise) + s->interlaced_high)
+ return 2;
+ if (s->bigger.noise > 2*MAX(n,s->bigger.temp) + s->interlaced_high)
+ return 1;
+ if (s->twox.temp > 2*MAX(n,s->twox.noise) + s->interlaced_high)
+ return 2;
+ if (s->twox.noise > 2*MAX(n,s->twox.temp) + s->interlaced_high)
+ return 1;
+ if (s->bigger.even > 2*MAX(n,s->bigger.odd) + s->interlaced_low &&
+ s->bigger.temp < n && s->bigger.noise < n)
+ return 4;
+ if (s->interlaced_low > MIN(2*n, s->tiny.odd))
+ return 3;
+ ret = 8 + (1 << (s->sad.temp > s->sad.noise));
+ still:
+ if (p->num_fields == 1 && p->prev_fields == 3 && notfilm >= 0 &&
+ (s->tiny.temp <= s->tiny.noise || s->sad.temp < s->sad.noise+16))
+ return 1;
+ if (p->notout < p->num_fields && p->iosync > 2*p->in_inc && notfilm < 0)
+ notfilm = 0;
+ if (p->num_fields < 2 ||
+ (p->num_fields == 2 && p->prev_fields == 2 && notfilm < 0))
+ return ret;
+ if (!notfilm && (p->prev_fields&~1) == 2) {
+ if (p->prev_fields + p->num_fields == 5) {
+ if (s->tiny.noise <= s->tiny.temp ||
+ s->low.noise == 0 || s->low.noise < s->low.temp ||
+ s->sad.noise < s->sad.temp+16)
+ return 2;
+ }
+ if (p->prev_fields + p->num_fields == 4) {
+ if (s->tiny.temp <= s->tiny.noise ||
+ s->low.temp == 0 || s->low.temp < s->low.noise ||
+ s->sad.temp < s->sad.noise+16)
+ return 1;
+ }
+ }
+ if (p->num_fields > 2 &&
+ ps->sad.noise > s->sad.noise && ps->sad.noise > s->sad.temp)
+ return 4;
+ return 2 >> (s->sad.noise > s->sad.temp);
+}
+
+#define ITOC(X) (!(X) ? ' ' : (X) + ((X)>9 ? 'a'-10 : '0'))
+
+static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
+{
+ mp_image_t *dmpi;
+ struct vf_priv_s *p = vf->priv;
+ unsigned char **planes, **old_planes;
+ struct frame_stats *s = &p->stats[p->inframes & 1];
+ struct frame_stats *ps = &p->stats[(p->inframes-1) & 1];
+ int swapped = 0;
+ const int flags = mpi->fields;
+ int breaks, prev;
+ int show_fields = 0;
+ int dropped_fields = 0;
+ double start_time, diff_time;
+ char prev_chflag = p->chflag;
+ int keep_rate;
+
+ if (!p->planes[0][0]) init(p, mpi);
+
+ old_planes = p->old_planes;
+
+ if ((mpi->flags & MP_IMGFLAG_DIRECT) && mpi->priv) {
+ planes = mpi->priv;
+ mpi->priv = 0;
+ } else {
+ planes = p->planes[2 + (++p->temp_idx & 1)];
+ my_memcpy_pic(planes[0],
+ mpi->planes[0] + p->crop_x + p->crop_y * mpi->stride[0],
+ p->w, p->h, p->stride, mpi->stride[0]);
+ if (mpi->flags & MP_IMGFLAG_PLANAR) {
+ my_memcpy_pic(planes[1],
+ mpi->planes[1] + p->crop_cx + p->crop_cy * mpi->stride[1],
+ p->cw, p->ch, p->chroma_stride, mpi->stride[1]);
+ my_memcpy_pic(planes[2],
+ mpi->planes[2] + p->crop_cx + p->crop_cy * mpi->stride[2],
+ p->cw, p->ch, p->chroma_stride, mpi->stride[2]);
+ p->num_copies++;
+ }
+ }
+
+ p->old_planes = planes;
+ p->chflag = ';';
+ if (flags & MP_IMGFIELD_ORDERED) {
+ swapped = !(flags & MP_IMGFIELD_TOP_FIRST);
+ p->chflag = (flags & MP_IMGFIELD_REPEAT_FIRST ? '|' :
+ flags & MP_IMGFIELD_TOP_FIRST ? ':' : '.');
+ }
+ p->swapped = swapped;
+
+ start_time = get_time();
+ if (p->chflag == '|') {
+ *s = ppzs;
+ p->iosync += p->in_inc;
+ } else if ((p->fast & 1) && prev_chflag == '|')
+ *s = pprs;
+ else
+ diff_fields(p, s, old_planes, planes);
+ diff_time = get_time();
+ p->diff_time += diff_time - start_time;
+ breaks = p->inframes ? find_breaks(p, s) : 2;
+ p->inframes++;
+ keep_rate = 4*p->in_inc == p->out_dec;
+
+ switch (breaks) {
+ case 0:
+ case 8:
+ case 9:
+ case 10:
+ if (!keep_rate && p->notout < p->num_fields && p->iosync < 2*p->in_inc)
+ break;
+ if (p->notout < p->num_fields)
+ dropped_fields = -2;
+ case 4:
+ if (keep_rate || p->iosync >= -2*p->in_inc)
+ show_fields = (4<<p->num_fields)-1;
+ break;
+ case 3:
+ if (keep_rate)
+ show_fields = 2;
+ else if (p->iosync > 0) {
+ if (p->notout >= p->num_fields && p->iosync > 2*p->in_inc) {
+ show_fields = 4; /* prev odd only */
+ if (p->num_fields > 1)
+ show_fields |= 8; /* + prev even */
+ } else {
+ show_fields = 2; /* even only */
+ if (p->notout >= p->num_fields)
+ dropped_fields += p->num_fields;
+ }
+ }
+ break;
+ case 2:
+ if (p->iosync <= -3*p->in_inc) {
+ if (p->notout >= p->num_fields)
+ dropped_fields = p->num_fields;
+ break;
+ }
+ if (p->num_fields == 1) {
+ int prevbreak = ps->sad.noise >= 128;
+ if (p->iosync < 4*p->in_inc) {
+ show_fields = 3;
+ dropped_fields = prevbreak;
+ } else {
+ show_fields = 4 | (!prevbreak << 3);
+ if (p->notout < 1 + p->prev_fields)
+ dropped_fields = -!prevbreak;
+ }
+ break;
+ }
+ default:
+ if (keep_rate)
+ show_fields = 3 << (breaks & 1);
+ else if (p->notout >= p->num_fields &&
+ p->iosync >= (breaks == 1 ? -p->in_inc :
+ p->in_inc << (p->num_fields == 1))) {
+ show_fields = (1 << (2 + p->num_fields)) - (1<<breaks);
+ } else {
+ if (p->notout >= p->num_fields)
+ dropped_fields += p->num_fields + 2 - breaks;
+ if (breaks == 1) {
+ if (p->iosync >= 4*p->in_inc)
+ show_fields = 6;
+ } else if (p->iosync > -3*p->in_inc)
+ show_fields = 3; /* odd+even */
+ }
+ break;
+ }
+
+ show_fields &= 15;
+ prev = p->prev_fields;
+ if (breaks < 8) {
+ if (p->num_fields == 1)
+ breaks &= ~4;
+ if (breaks)
+ p->num_breaks++;
+ if (breaks == 3)
+ p->prev_fields = p->num_fields = 1;
+ else if (breaks) {
+ p->prev_fields = p->num_fields + (breaks==1) - (breaks==4);
+ p->num_fields = breaks - (breaks == 4) + (p->chflag == '|');
+ } else
+ p->num_fields += 2;
+ } else
+ p->num_fields += 2;
+
+ p->iosync += 4 * p->in_inc;
+ if (p->chflag == '|')
+ p->iosync += p->in_inc;
+
+ if (show_fields) {
+ p->iosync -= p->out_dec;
+ p->notout = !(show_fields & 1) + !(show_fields & 3);
+ if (((show_fields & 3) == 3 &&
+ (s->low.noise + s->interlaced_low < (s->num_blocks>>8) ||
+ s->sad.noise < 160)) ||
+ ((show_fields & 12) == 12 &&
+ (ps->low.noise + ps->interlaced_low < (s->num_blocks>>8) ||
+ ps->sad.noise < 160))) {
+ p->export_count++;
+ dmpi = vf_get_image(vf->next, mpi->imgfmt, MP_IMGTYPE_EXPORT,
+ MP_IMGFLAG_PRESERVE|MP_IMGFLAG_READABLE,
+ p->w, p->h);
+ if ((show_fields & 3) != 3) planes = old_planes;
+ dmpi->planes[0] = planes[0];
+ dmpi->stride[0] = p->stride;
+ dmpi->width = mpi->width;
+ if (mpi->flags & MP_IMGFLAG_PLANAR) {
+ dmpi->planes[1] = planes[1];
+ dmpi->planes[2] = planes[2];
+ dmpi->stride[1] = p->chroma_stride;
+ dmpi->stride[2] = p->chroma_stride;
+ }
+ } else {
+ p->merge_count++;
+ dmpi = vf_get_image(vf->next, mpi->imgfmt,
+ MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
+ p->w, p->h);
+ copy_merge_fields(p, dmpi, old_planes, planes, show_fields);
+ }
+ p->outframes++;
+ } else
+ p->notout += 2;
+
+ if (p->verbose)
+ mp_msg(MSGT_VFILTER, MSGL_INFO, "%lu %lu: %x %c %c %lu%s%s%c%s\n",
+ p->inframes, p->outframes,
+ breaks, breaks<8 && breaks>0 ? (int) p->prev_fields+'0' : ' ',
+ ITOC(show_fields),
+ p->num_breaks, 5*p->in_inc == p->out_dec && breaks<8 &&
+ breaks>0 && ((prev&~1)!=2 || prev+p->prev_fields!=5) ?
+ " ######## bad telecine ########" : "",
+ dropped_fields ? " ======== dropped ":"", ITOC(dropped_fields),
+ !show_fields || (show_fields & (show_fields-1)) ?
+ "" : " @@@@@@@@@@@@@@@@@");
+
+ p->merge_time += get_time() - diff_time;
+ return show_fields ? vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE) : 0;
+}
+
+static int query_format(struct vf_instance *vf, unsigned int fmt)
+{
+ /* FIXME - support more formats */
+ switch (fmt) {
+ case IMGFMT_YV12:
+ case IMGFMT_IYUV:
+ case IMGFMT_I420:
+ case IMGFMT_411P:
+ case IMGFMT_422P:
+ case IMGFMT_444P:
+ return vf_next_query_format(vf, fmt);
+ }
+ return 0;
+}
+
+static int config(struct vf_instance *vf,
+ int width, int height, int d_width, int d_height,
+ unsigned int flags, unsigned int outfmt)
+{
+ unsigned long cxm = 0;
+ unsigned long cym = 0;
+ struct vf_priv_s *p = vf->priv;
+ // rounding:
+ if(!IMGFMT_IS_RGB(outfmt) && !IMGFMT_IS_BGR(outfmt)){
+ switch(outfmt){
+ case IMGFMT_444P:
+ case IMGFMT_Y800:
+ case IMGFMT_Y8:
+ break;
+ case IMGFMT_YVU9:
+ case IMGFMT_IF09:
+ cym = 3;
+ case IMGFMT_411P:
+ cxm = 3;
+ break;
+ case IMGFMT_YV12:
+ case IMGFMT_I420:
+ case IMGFMT_IYUV:
+ cym = 1;
+ default:
+ cxm = 1;
+ }
+ }
+ p->chroma_swapped = !!(p->crop_y & (cym+1));
+ if (p->w) p->w += p->crop_x & cxm;
+ if (p->h) p->h += p->crop_y & cym;
+ p->crop_x &= ~cxm;
+ p->crop_y &= ~cym;
+ if (!p->w || p->w > width ) p->w = width;
+ if (!p->h || p->h > height) p->h = height;
+ if (p->crop_x + p->w > width ) p->crop_x = 0;
+ if (p->crop_y + p->h > height) p->crop_y = 0;
+
+ if(!opt_screen_size_x && !opt_screen_size_y){
+ d_width = d_width * p->w/width;
+ d_height = d_height * p->h/height;
+ }
+ return vf_next_config(vf, p->w, p->h, d_width, d_height, flags, outfmt);
+}
+
+static void uninit(struct vf_instance *vf)
+{
+ struct vf_priv_s *p = vf->priv;
+ mp_msg(MSGT_VFILTER, MSGL_INFO, "diff_time: %.3f, merge_time: %.3f, "
+ "export: %lu, merge: %lu, copy: %lu\n", p->diff_time, p->merge_time,
+ p->export_count, p->merge_count, p->num_copies);
+ free(p->memory_allocated);
+ free(p);
+}
+
+static int vf_open(vf_instance_t *vf, char *args)
+{
+ struct vf_priv_s *p;
+ vf->get_image = get_image;
+ vf->put_image = put_image;
+ vf->config = config;
+ vf->query_format = query_format;
+ vf->uninit = uninit;
+ vf->default_reqs = VFCAP_ACCEPT_STRIDE;
+ vf->priv = p = calloc(1, sizeof(struct vf_priv_s));
+ p->out_dec = 5;
+ p->in_inc = 4;
+ p->thres.noise = 128;
+ p->thres.even = 128;
+ p->sad_thres = 64;
+ p->dint_thres = 4;
+ p->luma_only = 0;
+ p->fast = 3;
+ p->mmx2 = gCpuCaps.hasMMX2 ? 1 : gCpuCaps.has3DNow ? 2 : 0;
+ if (args) {
+ const char *args_remain = parse_args(p, args);
+ if (args_remain) {
+ mp_msg(MSGT_VFILTER, MSGL_FATAL,
+ "filmdint: unknown suboption: %s\n", args_remain);
+ return 0;
+ }
+ if (p->out_dec < p->in_inc) {
+ mp_msg(MSGT_VFILTER, MSGL_FATAL,
+ "filmdint: increasing the frame rate is not supported\n");
+ return 0;
+ }
+ }
+ if (p->mmx2 > 2)
+ p->mmx2 = 0;
+#if !HAVE_MMX
+ p->mmx2 = 0;
+#endif
+#if !HAVE_AMD3DNOW
+ p->mmx2 &= 1;
+#endif
+ p->thres.odd = p->thres.even;
+ p->thres.temp = p->thres.noise;
+ p->diff_time = 0;
+ p->merge_time = 0;
+ return 1;
+}
+
+const vf_info_t vf_info_filmdint = {
+ "Advanced inverse telecine filer",
+ "filmdint",
+ "Zoltan Hidvegi",
+ "",
+ vf_open,
+ NULL
+};
diff --git a/libavfilter/libmpcodecs/vf_fixpts.c b/libavfilter/libmpcodecs/vf_fixpts.c
new file mode 100644
index 0000000000..ae32b40d83
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_fixpts.c
@@ -0,0 +1,137 @@
+/*
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+
+#include "config.h"
+#include "mp_msg.h"
+#include "help_mp.h"
+
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+
+struct vf_priv_s {
+ double current;
+ double step;
+ int autostart;
+ int autostep;
+ unsigned have_step:1;
+ unsigned print:1;
+};
+
+static int put_image(vf_instance_t *vf, mp_image_t *src, double pts)
+{
+ struct vf_priv_s *p = vf->priv;
+
+ if (p->print) {
+ if (pts == MP_NOPTS_VALUE)
+ mp_msg(MSGT_VFILTER, MSGL_INFO, "PTS: undef\n");
+ else
+ mp_msg(MSGT_VFILTER, MSGL_INFO, "PTS: %f\n", pts);
+ }
+ if (pts != MP_NOPTS_VALUE && p->autostart != 0) {
+ p->current = pts;
+ if (p->autostart > 0)
+ p->autostart--;
+ } else if (pts != MP_NOPTS_VALUE && p->autostep > 0) {
+ p->step = pts - p->current;
+ p->current = pts;
+ p->autostep--;
+ p->have_step = 1;
+ } else if (p->have_step) {
+ p->current += p->step;
+ pts = p->current;
+ } else {
+ pts = MP_NOPTS_VALUE;
+ }
+ return vf_next_put_image(vf, src, pts);
+}
+
+static void uninit(vf_instance_t *vf)
+{
+ free(vf->priv);
+}
+
+static int parse_args(struct vf_priv_s *p, const char *args)
+{
+ int pos;
+ double num, denom = 1;
+ int iarg;
+
+ while (*args != 0) {
+ pos = 0;
+ if (sscanf(args, "print%n", &pos) == 0 && pos > 0) {
+ p->print = 1;
+ } else if (sscanf(args, "fps=%lf%n/%lf%n", &num, &pos, &denom, &pos) >=
+ 1 && pos > 0) {
+ p->step = denom / num;
+ p->have_step = 1;
+ } else if (sscanf(args, "start=%lf%n", &num, &pos) >= 1 && pos > 0) {
+ p->current = num;
+ } else if (sscanf(args, "autostart=%d%n", &iarg, &pos) == 1 && pos > 0) {
+ p->autostart = iarg;
+ } else if (sscanf(args, "autofps=%d%n", &iarg, &pos) == 1 && pos > 0) {
+ p->autostep = iarg;
+ } else {
+ mp_msg(MSGT_VFILTER, MSGL_FATAL,
+ "fixpts: unknown suboption: %s\n", args);
+ return 0;
+ }
+ args += pos;
+ if (*args == ':')
+ args++;
+ }
+ return 1;
+}
+
+static int open(vf_instance_t *vf, char *args)
+{
+ struct vf_priv_s *p;
+ struct vf_priv_s ptmp = {
+ .current = 0,
+ .step = 0,
+ .autostart = 0,
+ .autostep = 0,
+ .have_step = 0,
+ .print = 0,
+ };
+
+ if (!parse_args(&ptmp, args == NULL ? "" : args))
+ return 0;
+
+ vf->put_image = put_image;
+ vf->uninit = uninit;
+ vf->priv = p = malloc(sizeof(struct vf_priv_s));
+ *p = ptmp;
+ p->current = -p->step;
+
+ return 1;
+}
+
+const vf_info_t vf_info_fixpts = {
+ "Fix presentation timestamps",
+ "fixpts",
+ "Nicolas George",
+ "",
+ &open,
+ NULL
+};
diff --git a/libavfilter/libmpcodecs/vf_framestep.c b/libavfilter/libmpcodecs/vf_framestep.c
new file mode 100644
index 0000000000..cdf5386670
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_framestep.c
@@ -0,0 +1,205 @@
+/*
+ * filter to ouput only 1 every n frame, or only the I (key)frame
+ *
+ * The parameters are:
+ *
+ * [I] | [i]num
+ *
+ * if you call the filter with I (uppercase) as the parameter
+ * ... -vf framestep=I ...
+ * then ONLY the keyframes are outputted.
+ * For DVD it means, generally, one every 15 frames (IBBPBBPBBPBBPBB), for avi it means
+ * every scene change or every keyint value (see -lavcopts).
+ *
+ * if you call the filter with the i (lowercase)
+ * ... -vf framestep=i ...
+ * then a I! followed by a cr is printed when a key frame (eg Intra frame) is
+ * found, leaving the current line of mplayer/mencoder, where you got the
+ * time, in seconds, and frame of the key. Use this information to split the
+ * AVI.
+ *
+ * After the i or alone you can put a positive number and only one frame every
+ * x (the number you set) is passed on the filter chain, limiting the output
+ * of the frame.
+ *
+ * Example
+ * ... -vf framestep=i20 ...
+ * Dump one every 20 frames, printing on the console when a I-Frame is encounter.
+ *
+ * ... -vf framestep=25
+ * Dump one every 25 frames.
+ *
+ * If you call the filter without parameter it does nothing (except using memory
+ * and resource of your system,. of course).
+ *
+ * This filter doesn' t work like the option -sstep seconds.
+ *
+ * The -sstep seek to the new position, without decoding all frames but,
+ * expecially on avi file coded whith mpeg4 (lavc or xvid or divx), the
+ * seek is not always too much precise.
+ *
+ * This filter simply discard the unwanted frames, so you are very precise in
+ * counting the frame but sometime you use a lot of CPU for nothing.
+ *
+ * As usual it depends on what you're doing.
+ *
+ * copyright (c) 2003 Daniele Forghieri ( guru@digitalfantasy.it )
+ *
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "config.h"
+#include "mp_msg.h"
+#include "help_mp.h"
+#include "cpudetect.h"
+
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+
+/* Uncomment if you want to print some info on the format */
+// #define DUMP_FORMAT_DATA
+
+/* Private data */
+struct vf_priv_s {
+ /* Current frame */
+ int frame_cur;
+ /* Frame output step, 0 = all */
+ int frame_step;
+ /* Only I-Frame (2), print on I-Frame (1) */
+ int dump_iframe;
+};
+
+/* Filter handler */
+static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
+{
+ mp_image_t *dmpi;
+ struct vf_priv_s *priv;
+ int skip;
+
+ priv = vf->priv;
+
+ /* Print the 'I' if is a intra frame. The \n advance the current line so you got the
+ * current file time (in second) and the frame number on the console ;-)
+ */
+ if (priv->dump_iframe) {
+ if (mpi->pict_type == 1) {
+ mp_msg(MSGT_VFILTER, MSGL_INFO, "I!\n");
+ }
+ }
+
+ /* decide if frame must be shown */
+ if (priv->dump_iframe == 2) {
+ /* Only key frame */
+ skip = mpi->pict_type == 1 ? 0 : 1;
+ }
+ else {
+ /* Only 1 every frame_step */
+ skip = 0;
+ if ((priv->frame_step != 0) && ((priv->frame_cur % priv->frame_step) != 0)) {
+ skip = 1;
+ }
+ }
+ /* Increment current frame */
+ ++priv->frame_cur;
+
+ if (skip == 0) {
+ /* Get image, export type (we don't modify tghe image) */
+ dmpi=vf_get_image(vf->next, mpi->imgfmt,
+ MP_IMGTYPE_EXPORT, 0,
+ mpi->w, mpi->h);
+ /* Copy only the pointer ( MP_IMGTYPE_EXPORT ! ) */
+ dmpi->planes[0] = mpi->planes[0];
+ dmpi->planes[1] = mpi->planes[1];
+ dmpi->planes[2] = mpi->planes[2];
+
+ dmpi->stride[0] = mpi->stride[0];
+ dmpi->stride[1] = mpi->stride[1];
+ dmpi->stride[2] = mpi->stride[2];
+
+ dmpi->width = mpi->width;
+ dmpi->height = mpi->height;
+
+ /* Chain to next filter / output ... */
+ return vf_next_put_image(vf, dmpi, pts);
+ }
+
+ /* Skip the frame */
+ return 0;
+}
+
+static void uninit(struct vf_instance *vf)
+{
+ /* Free private data */
+ free(vf->priv);
+}
+
+/* Main entry funct for the filter */
+static int vf_open(vf_instance_t *vf, char *args)
+{
+ struct vf_priv_s *p;
+
+ vf->put_image = put_image;
+ vf->uninit = uninit;
+ vf->default_reqs = VFCAP_ACCEPT_STRIDE;
+ vf->priv = p = calloc(1, sizeof(struct vf_priv_s));
+ if (p == NULL) {
+ return 0;
+ }
+
+ if (args != NULL) {
+#ifdef DUMP_FORMAT_DATA
+ if (*args == 'd') {
+ p->dump_iframe = 3;
+ }
+ else
+#endif
+ if (*args == 'I') {
+ /* Dump only KEY (ie INTRA) frame */
+ p->dump_iframe = 2;
+ }
+ else {
+ if (*args == 'i') {
+ /* Print a 'I!' when a i-frame is encounter */
+ p->dump_iframe = 1;
+ ++args;
+ }
+
+ if (*args != '\0') {
+ p->frame_step = atoi(args);
+ if (p->frame_step <= 0) {
+ mp_msg(MSGT_VFILTER, MSGL_WARN, MSGTR_MPCODECS_ErrorParsingArgument);
+ return 0;
+ }
+ }
+ }
+ }
+ return 1;
+}
+
+const vf_info_t vf_info_framestep = {
+ "Dump one every n / key frames",
+ "framestep",
+ "Daniele Forghieri",
+ "",
+ vf_open,
+ NULL
+};
diff --git a/libavfilter/libmpcodecs/vf_fspp.c b/libavfilter/libmpcodecs/vf_fspp.c
new file mode 100644
index 0000000000..a98c70b26c
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_fspp.c
@@ -0,0 +1,2117 @@
+/*
+ * Copyright (C) 2003 Michael Niedermayer <michaelni@gmx.at>
+ * Copyright (C) 2005 Nikolaj Poroshin <porosh3@psu.ru>
+ *
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+/*
+ * This implementation is based on an algorithm described in
+ * "Aria Nosratinia Embedded Post-Processing for
+ * Enhancement of Compressed Images (1999)"
+ * (http://citeseer.nj.nec.com/nosratinia99embedded.html)
+ * Futher, with splitting (i)dct into hor/ver passes, one of them can be
+ * performed once per block, not pixel. This allows for much better speed.
+ */
+
+/*
+ Heavily optimized version of SPP filter by Nikolaj
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+#include <math.h>
+
+#include "config.h"
+
+#include "mp_msg.h"
+#include "cpudetect.h"
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+#include "vd_ffmpeg.h"
+#include "libvo/fastmemcpy.h"
+
+#include "libavutil/internal.h"
+#include "libavutil/intreadwrite.h"
+#include "libavutil/mem.h"
+#include "libavcodec/avcodec.h"
+#include "libavcodec/dsputil.h"
+
+#undef free
+#undef malloc
+
+//===========================================================================//
+#define BLOCKSZ 12
+
+static const short custom_threshold[64]=
+// values (296) can't be too high
+// -it causes too big quant dependence
+// or maybe overflow(check), which results in some flashing
+{ 71, 296, 295, 237, 71, 40, 38, 19,
+ 245, 193, 185, 121, 102, 73, 53, 27,
+ 158, 129, 141, 107, 97, 73, 50, 26,
+ 102, 116, 109, 98, 82, 66, 45, 23,
+ 71, 94, 95, 81, 70, 56, 38, 20,
+ 56, 77, 74, 66, 56, 44, 30, 15,
+ 38, 53, 50, 45, 38, 30, 21, 11,
+ 20, 27, 26, 23, 20, 15, 11, 5
+};
+
+static const uint8_t __attribute__((aligned(32))) dither[8][8]={
+ { 0, 48, 12, 60, 3, 51, 15, 63, },
+ { 32, 16, 44, 28, 35, 19, 47, 31, },
+ { 8, 56, 4, 52, 11, 59, 7, 55, },
+ { 40, 24, 36, 20, 43, 27, 39, 23, },
+ { 2, 50, 14, 62, 1, 49, 13, 61, },
+ { 34, 18, 46, 30, 33, 17, 45, 29, },
+ { 10, 58, 6, 54, 9, 57, 5, 53, },
+ { 42, 26, 38, 22, 41, 25, 37, 21, },
+};
+
+struct vf_priv_s { //align 16 !
+ uint64_t threshold_mtx_noq[8*2];
+ uint64_t threshold_mtx[8*2];//used in both C & MMX (& later SSE2) versions
+
+ int log2_count;
+ int temp_stride;
+ int qp;
+ int mpeg2;
+ int prev_q;
+ uint8_t *src;
+ int16_t *temp;
+ int bframes;
+ char *non_b_qp;
+};
+
+
+#if !HAVE_MMX
+
+//This func reads from 1 slice, 1 and clears 0 & 1
+static void store_slice_c(uint8_t *dst, int16_t *src, int dst_stride, int src_stride, int width, int height, int log2_scale)
+{int y, x;
+#define STORE(pos) \
+ temp= (src[x + pos] + (d[pos]>>log2_scale))>>(6-log2_scale); \
+ src[x + pos]=src[x + pos - 8*src_stride]=0; \
+ if(temp & 0x100) temp= ~(temp>>31); \
+ dst[x + pos]= temp;
+
+ for(y=0; y<height; y++){
+ const uint8_t *d= dither[y];
+ for(x=0; x<width; x+=8){
+ int temp;
+ STORE(0);
+ STORE(1);
+ STORE(2);
+ STORE(3);
+ STORE(4);
+ STORE(5);
+ STORE(6);
+ STORE(7);
+ }
+ src+=src_stride;
+ dst+=dst_stride;
+ }
+}
+
+//This func reads from 2 slices, 0 & 2 and clears 2-nd
+static void store_slice2_c(uint8_t *dst, int16_t *src, int dst_stride, int src_stride, int width, int height, int log2_scale)
+{int y, x;
+#define STORE2(pos) \
+ temp= (src[x + pos] + src[x + pos + 16*src_stride] + (d[pos]>>log2_scale))>>(6-log2_scale); \
+ src[x + pos + 16*src_stride]=0; \
+ if(temp & 0x100) temp= ~(temp>>31); \
+ dst[x + pos]= temp;
+
+ for(y=0; y<height; y++){
+ const uint8_t *d= dither[y];
+ for(x=0; x<width; x+=8){
+ int temp;
+ STORE2(0);
+ STORE2(1);
+ STORE2(2);
+ STORE2(3);
+ STORE2(4);
+ STORE2(5);
+ STORE2(6);
+ STORE2(7);
+ }
+ src+=src_stride;
+ dst+=dst_stride;
+ }
+}
+
+static void mul_thrmat_c(struct vf_priv_s *p,int q)
+{
+ int a;
+ for(a=0;a<64;a++)
+ ((short*)p->threshold_mtx)[a]=q * ((short*)p->threshold_mtx_noq)[a];//ints faster in C
+}
+
+static void column_fidct_c(int16_t* thr_adr, DCTELEM *data, DCTELEM *output, int cnt);
+static void row_idct_c(DCTELEM* workspace,
+ int16_t* output_adr, int output_stride, int cnt);
+static void row_fdct_c(DCTELEM *data, const uint8_t *pixels, int line_size, int cnt);
+
+//this is rather ugly, but there is no need for function pointers
+#define store_slice_s store_slice_c
+#define store_slice2_s store_slice2_c
+#define mul_thrmat_s mul_thrmat_c
+#define column_fidct_s column_fidct_c
+#define row_idct_s row_idct_c
+#define row_fdct_s row_fdct_c
+
+#else /* HAVE_MMX */
+
+//This func reads from 1 slice, 1 and clears 0 & 1
+static void store_slice_mmx(uint8_t *dst, int16_t *src, long dst_stride, long src_stride, long width, long height, long log2_scale)
+{
+ const uint8_t *od=&dither[0][0];
+ const uint8_t *end=&dither[height][0];
+ width = (width+7)&~7;
+ dst_stride-=width;
+ //src_stride=(src_stride-width)*2;
+ __asm__ volatile(
+ "mov %5, %%"REG_d" \n\t"
+ "mov %6, %%"REG_S" \n\t"
+ "mov %7, %%"REG_D" \n\t"
+ "mov %1, %%"REG_a" \n\t"
+ "movd %%"REG_d", %%mm5 \n\t"
+ "xor $-1, %%"REG_d" \n\t"
+ "mov %%"REG_a", %%"REG_c" \n\t"
+ "add $7, %%"REG_d" \n\t"
+ "neg %%"REG_a" \n\t"
+ "sub %0, %%"REG_c" \n\t"
+ "add %%"REG_c", %%"REG_c" \n\t"
+ "movd %%"REG_d", %%mm2 \n\t"
+ "mov %%"REG_c", %1 \n\t"
+ "mov %2, %%"REG_d" \n\t"
+ "shl $4, %%"REG_a" \n\t"
+
+ "2: \n\t"
+ "movq (%%"REG_d"), %%mm3 \n\t"
+ "movq %%mm3, %%mm4 \n\t"
+ "pxor %%mm7, %%mm7 \n\t"
+ "punpcklbw %%mm7, %%mm3 \n\t"
+ "punpckhbw %%mm7, %%mm4 \n\t"
+ "mov %0, %%"REG_c" \n\t"
+ "psraw %%mm5, %%mm3 \n\t"
+ "psraw %%mm5, %%mm4 \n\t"
+ "1: \n\t"
+ "movq %%mm7, (%%"REG_S",%%"REG_a",) \n\t"
+ "movq (%%"REG_S"), %%mm0 \n\t"
+ "movq 8(%%"REG_S"), %%mm1 \n\t"
+
+ "movq %%mm7, 8(%%"REG_S",%%"REG_a",) \n\t"
+ "paddw %%mm3, %%mm0 \n\t"
+ "paddw %%mm4, %%mm1 \n\t"
+
+ "movq %%mm7, (%%"REG_S") \n\t"
+ "psraw %%mm2, %%mm0 \n\t"
+ "psraw %%mm2, %%mm1 \n\t"
+
+ "movq %%mm7, 8(%%"REG_S") \n\t"
+ "packuswb %%mm1, %%mm0 \n\t"
+ "add $16, %%"REG_S" \n\t"
+
+ "movq %%mm0, (%%"REG_D") \n\t"
+ "add $8, %%"REG_D" \n\t"
+ "sub $8, %%"REG_c" \n\t"
+ "jg 1b \n\t"
+ "add %1, %%"REG_S" \n\t"
+ "add $8, %%"REG_d" \n\t"
+ "add %3, %%"REG_D" \n\t"
+ "cmp %4, %%"REG_d" \n\t"
+ "jl 2b \n\t"
+
+ :
+ : "m" (width), "m" (src_stride), "erm" (od), "m" (dst_stride), "erm" (end),
+ "m" (log2_scale), "m" (src), "m" (dst) //input
+ : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S, "%"REG_D
+ );
+}
+
+//This func reads from 2 slices, 0 & 2 and clears 2-nd
+static void store_slice2_mmx(uint8_t *dst, int16_t *src, long dst_stride, long src_stride, long width, long height, long log2_scale)
+{
+ const uint8_t *od=&dither[0][0];
+ const uint8_t *end=&dither[height][0];
+ width = (width+7)&~7;
+ dst_stride-=width;
+ //src_stride=(src_stride-width)*2;
+ __asm__ volatile(
+ "mov %5, %%"REG_d" \n\t"
+ "mov %6, %%"REG_S" \n\t"
+ "mov %7, %%"REG_D" \n\t"
+ "mov %1, %%"REG_a" \n\t"
+ "movd %%"REG_d", %%mm5 \n\t"
+ "xor $-1, %%"REG_d" \n\t"
+ "mov %%"REG_a", %%"REG_c" \n\t"
+ "add $7, %%"REG_d" \n\t"
+ "sub %0, %%"REG_c" \n\t"
+ "add %%"REG_c", %%"REG_c" \n\t"
+ "movd %%"REG_d", %%mm2 \n\t"
+ "mov %%"REG_c", %1 \n\t"
+ "mov %2, %%"REG_d" \n\t"
+ "shl $5, %%"REG_a" \n\t"
+
+ "2: \n\t"
+ "movq (%%"REG_d"), %%mm3 \n\t"
+ "movq %%mm3, %%mm4 \n\t"
+ "pxor %%mm7, %%mm7 \n\t"
+ "punpcklbw %%mm7, %%mm3 \n\t"
+ "punpckhbw %%mm7, %%mm4 \n\t"
+ "mov %0, %%"REG_c" \n\t"
+ "psraw %%mm5, %%mm3 \n\t"
+ "psraw %%mm5, %%mm4 \n\t"
+ "1: \n\t"
+ "movq (%%"REG_S"), %%mm0 \n\t"
+ "movq 8(%%"REG_S"), %%mm1 \n\t"
+ "paddw %%mm3, %%mm0 \n\t"
+
+ "paddw (%%"REG_S",%%"REG_a",), %%mm0 \n\t"
+ "paddw %%mm4, %%mm1 \n\t"
+ "movq 8(%%"REG_S",%%"REG_a",), %%mm6 \n\t"
+
+ "movq %%mm7, (%%"REG_S",%%"REG_a",) \n\t"
+ "psraw %%mm2, %%mm0 \n\t"
+ "paddw %%mm6, %%mm1 \n\t"
+
+ "movq %%mm7, 8(%%"REG_S",%%"REG_a",) \n\t"
+ "psraw %%mm2, %%mm1 \n\t"
+ "packuswb %%mm1, %%mm0 \n\t"
+
+ "movq %%mm0, (%%"REG_D") \n\t"
+ "add $16, %%"REG_S" \n\t"
+ "add $8, %%"REG_D" \n\t"
+ "sub $8, %%"REG_c" \n\t"
+ "jg 1b \n\t"
+ "add %1, %%"REG_S" \n\t"
+ "add $8, %%"REG_d" \n\t"
+ "add %3, %%"REG_D" \n\t"
+ "cmp %4, %%"REG_d" \n\t"
+ "jl 2b \n\t"
+
+ :
+ : "m" (width), "m" (src_stride), "erm" (od), "m" (dst_stride), "erm" (end),
+ "m" (log2_scale), "m" (src), "m" (dst) //input
+ : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_D, "%"REG_S
+ );
+}
+
+static void mul_thrmat_mmx(struct vf_priv_s *p, int q)
+{
+ uint64_t *adr=&p->threshold_mtx_noq[0];
+ __asm__ volatile(
+ "movd %0, %%mm7 \n\t"
+ "add $8*8*2, %%"REG_D" \n\t"
+ "movq 0*8(%%"REG_S"), %%mm0 \n\t"
+ "punpcklwd %%mm7, %%mm7 \n\t"
+ "movq 1*8(%%"REG_S"), %%mm1 \n\t"
+ "punpckldq %%mm7, %%mm7 \n\t"
+ "pmullw %%mm7, %%mm0 \n\t"
+
+ "movq 2*8(%%"REG_S"), %%mm2 \n\t"
+ "pmullw %%mm7, %%mm1 \n\t"
+
+ "movq 3*8(%%"REG_S"), %%mm3 \n\t"
+ "pmullw %%mm7, %%mm2 \n\t"
+
+ "movq %%mm0, 0*8(%%"REG_D") \n\t"
+ "movq 4*8(%%"REG_S"), %%mm4 \n\t"
+ "pmullw %%mm7, %%mm3 \n\t"
+
+ "movq %%mm1, 1*8(%%"REG_D") \n\t"
+ "movq 5*8(%%"REG_S"), %%mm5 \n\t"
+ "pmullw %%mm7, %%mm4 \n\t"
+
+ "movq %%mm2, 2*8(%%"REG_D") \n\t"
+ "movq 6*8(%%"REG_S"), %%mm6 \n\t"
+ "pmullw %%mm7, %%mm5 \n\t"
+
+ "movq %%mm3, 3*8(%%"REG_D") \n\t"
+ "movq 7*8+0*8(%%"REG_S"), %%mm0 \n\t"
+ "pmullw %%mm7, %%mm6 \n\t"
+
+ "movq %%mm4, 4*8(%%"REG_D") \n\t"
+ "movq 7*8+1*8(%%"REG_S"), %%mm1 \n\t"
+ "pmullw %%mm7, %%mm0 \n\t"
+
+ "movq %%mm5, 5*8(%%"REG_D") \n\t"
+ "movq 7*8+2*8(%%"REG_S"), %%mm2 \n\t"
+ "pmullw %%mm7, %%mm1 \n\t"
+
+ "movq %%mm6, 6*8(%%"REG_D") \n\t"
+ "movq 7*8+3*8(%%"REG_S"), %%mm3 \n\t"
+ "pmullw %%mm7, %%mm2 \n\t"
+
+ "movq %%mm0, 7*8+0*8(%%"REG_D") \n\t"
+ "movq 7*8+4*8(%%"REG_S"), %%mm4 \n\t"
+ "pmullw %%mm7, %%mm3 \n\t"
+
+ "movq %%mm1, 7*8+1*8(%%"REG_D") \n\t"
+ "movq 7*8+5*8(%%"REG_S"), %%mm5 \n\t"
+ "pmullw %%mm7, %%mm4 \n\t"
+
+ "movq %%mm2, 7*8+2*8(%%"REG_D") \n\t"
+ "movq 7*8+6*8(%%"REG_S"), %%mm6 \n\t"
+ "pmullw %%mm7, %%mm5 \n\t"
+
+ "movq %%mm3, 7*8+3*8(%%"REG_D") \n\t"
+ "movq 14*8+0*8(%%"REG_S"), %%mm0 \n\t"
+ "pmullw %%mm7, %%mm6 \n\t"
+
+ "movq %%mm4, 7*8+4*8(%%"REG_D") \n\t"
+ "movq 14*8+1*8(%%"REG_S"), %%mm1 \n\t"
+ "pmullw %%mm7, %%mm0 \n\t"
+
+ "movq %%mm5, 7*8+5*8(%%"REG_D") \n\t"
+ "pmullw %%mm7, %%mm1 \n\t"
+
+ "movq %%mm6, 7*8+6*8(%%"REG_D") \n\t"
+ "movq %%mm0, 14*8+0*8(%%"REG_D") \n\t"
+ "movq %%mm1, 14*8+1*8(%%"REG_D") \n\t"
+
+ : "+g" (q), "+S" (adr), "+D" (adr)
+ :
+ );
+}
+
+static void column_fidct_mmx(int16_t* thr_adr, DCTELEM *data, DCTELEM *output, int cnt);
+static void row_idct_mmx(DCTELEM* workspace,
+ int16_t* output_adr, int output_stride, int cnt);
+static void row_fdct_mmx(DCTELEM *data, const uint8_t *pixels, int line_size, int cnt);
+
+#define store_slice_s store_slice_mmx
+#define store_slice2_s store_slice2_mmx
+#define mul_thrmat_s mul_thrmat_mmx
+#define column_fidct_s column_fidct_mmx
+#define row_idct_s row_idct_mmx
+#define row_fdct_s row_fdct_mmx
+#endif // HAVE_MMX
+
+static void filter(struct vf_priv_s *p, uint8_t *dst, uint8_t *src,
+ int dst_stride, int src_stride,
+ int width, int height,
+ uint8_t *qp_store, int qp_stride, int is_luma)
+{
+ int x, x0, y, es, qy, t;
+ const int stride= is_luma ? p->temp_stride : (width+16);//((width+16+15)&(~15))
+ const int step=6-p->log2_count;
+ const int qps= 3 + is_luma;
+ int32_t __attribute__((aligned(32))) block_align[4*8*BLOCKSZ+ 4*8*BLOCKSZ];
+ DCTELEM *block= (DCTELEM *)block_align;
+ DCTELEM *block3=(DCTELEM *)(block_align+4*8*BLOCKSZ);
+
+ memset(block3, 0, 4*8*BLOCKSZ);
+
+ //p->src=src-src_stride*8-8;//!
+ if (!src || !dst) return; // HACK avoid crash for Y8 colourspace
+ for(y=0; y<height; y++){
+ int index= 8 + 8*stride + y*stride;
+ fast_memcpy(p->src + index, src + y*src_stride, width);//this line can be avoided by using DR & user fr.buffers
+ for(x=0; x<8; x++){
+ p->src[index - x - 1]= p->src[index + x ];
+ p->src[index + width + x ]= p->src[index + width - x - 1];
+ }
+ }
+ for(y=0; y<8; y++){
+ fast_memcpy(p->src + ( 7-y)*stride, p->src + ( y+8)*stride, stride);
+ fast_memcpy(p->src + (height+8+y)*stride, p->src + (height-y+7)*stride, stride);
+ }
+ //FIXME (try edge emu)
+
+ for(y=8; y<24; y++)
+ memset(p->temp+ 8 +y*stride, 0,width*sizeof(int16_t));
+
+ for(y=step; y<height+8; y+=step){ //step= 1,2
+ qy=y-4;
+ if (qy>height-1) qy=height-1;
+ if (qy<0) qy=0;
+ qy=(qy>>qps)*qp_stride;
+ row_fdct_s(block, p->src + y*stride +2-(y&1), stride, 2);
+ for(x0=0; x0<width+8-8*(BLOCKSZ-1); x0+=8*(BLOCKSZ-1)){
+ row_fdct_s(block+8*8, p->src + y*stride+8+x0 +2-(y&1), stride, 2*(BLOCKSZ-1));
+ if(p->qp)
+ column_fidct_s((int16_t*)(&p->threshold_mtx[0]), block+0*8, block3+0*8, 8*(BLOCKSZ-1)); //yes, this is a HOTSPOT
+ else
+ for (x=0; x<8*(BLOCKSZ-1); x+=8) {
+ t=x+x0-2; //correct t=x+x0-2-(y&1), but its the same
+ if (t<0) t=0;//t always < width-2
+ t=qp_store[qy+(t>>qps)];
+ t=norm_qscale(t, p->mpeg2);
+ if (t!=p->prev_q) p->prev_q=t, mul_thrmat_s(p, t);
+ column_fidct_s((int16_t*)(&p->threshold_mtx[0]), block+x*8, block3+x*8, 8); //yes, this is a HOTSPOT
+ }
+ row_idct_s(block3+0*8, p->temp + (y&15)*stride+x0+2-(y&1), stride, 2*(BLOCKSZ-1));
+ memmove(block, block+(BLOCKSZ-1)*64, 8*8*sizeof(DCTELEM)); //cycling
+ memmove(block3, block3+(BLOCKSZ-1)*64, 6*8*sizeof(DCTELEM));
+ }
+ //
+ es=width+8-x0; // 8, ...
+ if (es>8)
+ row_fdct_s(block+8*8, p->src + y*stride+8+x0 +2-(y&1), stride, (es-4)>>2);
+ column_fidct_s((int16_t*)(&p->threshold_mtx[0]), block, block3, es&(~1));
+ row_idct_s(block3+0*8, p->temp + (y&15)*stride+x0+2-(y&1), stride, es>>2);
+ {const int y1=y-8+step;//l5-7 l4-6
+ if (!(y1&7) && y1) {
+ if (y1&8) store_slice_s(dst + (y1-8)*dst_stride, p->temp+ 8 +8*stride,
+ dst_stride, stride, width, 8, 5-p->log2_count);
+ else store_slice2_s(dst + (y1-8)*dst_stride, p->temp+ 8 +0*stride,
+ dst_stride, stride, width, 8, 5-p->log2_count);
+ } }
+ }
+
+ if (y&7) { // == height & 7
+ if (y&8) store_slice_s(dst + ((y-8)&~7)*dst_stride, p->temp+ 8 +8*stride,
+ dst_stride, stride, width, y&7, 5-p->log2_count);
+ else store_slice2_s(dst + ((y-8)&~7)*dst_stride, p->temp+ 8 +0*stride,
+ dst_stride, stride, width, y&7, 5-p->log2_count);
+ }
+}
+
+static int config(struct vf_instance *vf,
+ int width, int height, int d_width, int d_height,
+ unsigned int flags, unsigned int outfmt)
+{
+ int h= (height+16+15)&(~15);
+
+ vf->priv->temp_stride= (width+16+15)&(~15);
+ vf->priv->temp= (int16_t*)av_mallocz(vf->priv->temp_stride*3*8*sizeof(int16_t));
+ //this can also be avoided, see above
+ vf->priv->src = (uint8_t*)av_malloc(vf->priv->temp_stride*h*sizeof(uint8_t));
+
+ return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
+}
+
+static void get_image(struct vf_instance *vf, mp_image_t *mpi)
+{
+ if(mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change
+ // ok, we can do pp in-place (or pp disabled):
+ vf->dmpi=vf_get_image(vf->next,mpi->imgfmt,
+ mpi->type, mpi->flags, mpi->width, mpi->height);
+ mpi->planes[0]=vf->dmpi->planes[0];
+ mpi->stride[0]=vf->dmpi->stride[0];
+ mpi->width=vf->dmpi->width;
+ if(mpi->flags&MP_IMGFLAG_PLANAR){
+ mpi->planes[1]=vf->dmpi->planes[1];
+ mpi->planes[2]=vf->dmpi->planes[2];
+ mpi->stride[1]=vf->dmpi->stride[1];
+ mpi->stride[2]=vf->dmpi->stride[2];
+ }
+ mpi->flags|=MP_IMGFLAG_DIRECT;
+}
+
+static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
+{
+ mp_image_t *dmpi;
+ if(!(mpi->flags&MP_IMGFLAG_DIRECT)){
+ // no DR, so get a new image! hope we'll get DR buffer:
+ dmpi=vf_get_image(vf->next,mpi->imgfmt,
+ MP_IMGTYPE_TEMP,
+ MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE,
+ mpi->width,mpi->height);
+ vf_clone_mpi_attributes(dmpi, mpi);
+ }else{
+ dmpi=vf->dmpi;
+ }
+
+ vf->priv->mpeg2= mpi->qscale_type;
+ if(mpi->pict_type != 3 && mpi->qscale && !vf->priv->qp){
+ int w = mpi->qstride;
+ int h = (mpi->h + 15) >> 4;
+ if (!w) {
+ w = (mpi->w + 15) >> 4;
+ h = 1;
+ }
+ if(!vf->priv->non_b_qp)
+ vf->priv->non_b_qp= malloc(w*h);
+ fast_memcpy(vf->priv->non_b_qp, mpi->qscale, w*h);
+ }
+ if(vf->priv->log2_count || !(mpi->flags&MP_IMGFLAG_DIRECT)){
+ char *qp_tab= vf->priv->non_b_qp;
+ if(vf->priv->bframes || !qp_tab)
+ qp_tab= mpi->qscale;
+
+ if(qp_tab || vf->priv->qp){
+ filter(vf->priv, dmpi->planes[0], mpi->planes[0], dmpi->stride[0], mpi->stride[0],
+ mpi->w, mpi->h, qp_tab, mpi->qstride, 1);
+ filter(vf->priv, dmpi->planes[1], mpi->planes[1], dmpi->stride[1], mpi->stride[1],
+ mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, qp_tab, mpi->qstride, 0);
+ filter(vf->priv, dmpi->planes[2], mpi->planes[2], dmpi->stride[2], mpi->stride[2],
+ mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, qp_tab, mpi->qstride, 0);
+ }else{
+ memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h, dmpi->stride[0], mpi->stride[0]);
+ memcpy_pic(dmpi->planes[1], mpi->planes[1], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, dmpi->stride[1], mpi->stride[1]);
+ memcpy_pic(dmpi->planes[2], mpi->planes[2], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, dmpi->stride[2], mpi->stride[2]);
+ }
+ }
+
+#if HAVE_MMX
+ if(gCpuCaps.hasMMX) __asm__ volatile ("emms\n\t");
+#endif
+#if HAVE_MMX2
+ if(gCpuCaps.hasMMX2) __asm__ volatile ("sfence\n\t");
+#endif
+ return vf_next_put_image(vf,dmpi, pts);
+}
+
+static void uninit(struct vf_instance *vf)
+{
+ if(!vf->priv) return;
+
+ av_free(vf->priv->temp);
+ vf->priv->temp= NULL;
+ av_free(vf->priv->src);
+ vf->priv->src= NULL;
+ //free(vf->priv->avctx);
+ //vf->priv->avctx= NULL;
+ free(vf->priv->non_b_qp);
+ vf->priv->non_b_qp= NULL;
+
+ av_free(vf->priv);
+ vf->priv=NULL;
+}
+
+//===========================================================================//
+
+static int query_format(struct vf_instance *vf, unsigned int fmt)
+{
+ switch(fmt){
+ case IMGFMT_YVU9:
+ case IMGFMT_IF09:
+ case IMGFMT_YV12:
+ case IMGFMT_I420:
+ case IMGFMT_IYUV:
+ case IMGFMT_CLPL:
+ case IMGFMT_Y800:
+ case IMGFMT_Y8:
+ case IMGFMT_444P:
+ case IMGFMT_422P:
+ case IMGFMT_411P:
+ return vf_next_query_format(vf,fmt);
+ }
+ return 0;
+}
+
+static int control(struct vf_instance *vf, int request, void* data)
+{
+ switch(request){
+ case VFCTRL_QUERY_MAX_PP_LEVEL:
+ return 5;
+ case VFCTRL_SET_PP_LEVEL:
+ vf->priv->log2_count= *((unsigned int*)data);
+ if (vf->priv->log2_count < 4) vf->priv->log2_count=4;
+ return CONTROL_TRUE;
+ }
+ return vf_next_control(vf,request,data);
+}
+
+static int vf_open(vf_instance_t *vf, char *args)
+{
+ int i=0, bias;
+ int custom_threshold_m[64];
+ int log2c=-1;
+
+ vf->config=config;
+ vf->put_image=put_image;
+ vf->get_image=get_image;
+ vf->query_format=query_format;
+ vf->uninit=uninit;
+ vf->control= control;
+ vf->priv=av_mallocz(sizeof(struct vf_priv_s));//assumes align 16 !
+
+ init_avcodec();
+
+ //vf->priv->avctx= avcodec_alloc_context();
+ //dsputil_init(&vf->priv->dsp, vf->priv->avctx);
+
+ vf->priv->log2_count= 4;
+ vf->priv->bframes = 0;
+
+ if (args) sscanf(args, "%d:%d:%d:%d", &log2c, &vf->priv->qp, &i, &vf->priv->bframes);
+
+ if( log2c >=4 && log2c <=5 )
+ vf->priv->log2_count = log2c;
+ else if( log2c >= 6 )
+ vf->priv->log2_count = 5;
+
+ if(vf->priv->qp < 0)
+ vf->priv->qp = 0;
+
+ if (i < -15) i = -15;
+ if (i > 32) i = 32;
+
+ bias= (1<<4)+i; //regulable
+ vf->priv->prev_q=0;
+ //
+ for(i=0;i<64;i++) //FIXME: tune custom_threshold[] and remove this !
+ custom_threshold_m[i]=(int)(custom_threshold[i]*(bias/71.)+ 0.5);
+ for(i=0;i<8;i++){
+ vf->priv->threshold_mtx_noq[2*i]=(uint64_t)custom_threshold_m[i*8+2]
+ |(((uint64_t)custom_threshold_m[i*8+6])<<16)
+ |(((uint64_t)custom_threshold_m[i*8+0])<<32)
+ |(((uint64_t)custom_threshold_m[i*8+4])<<48);
+ vf->priv->threshold_mtx_noq[2*i+1]=(uint64_t)custom_threshold_m[i*8+5]
+ |(((uint64_t)custom_threshold_m[i*8+3])<<16)
+ |(((uint64_t)custom_threshold_m[i*8+1])<<32)
+ |(((uint64_t)custom_threshold_m[i*8+7])<<48);
+ }
+
+ if (vf->priv->qp) vf->priv->prev_q=vf->priv->qp, mul_thrmat_s(vf->priv, vf->priv->qp);
+
+ return 1;
+}
+
+const vf_info_t vf_info_fspp = {
+ "fast simple postprocess",
+ "fspp",
+ "Michael Niedermayer, Nikolaj Poroshin",
+ "",
+ vf_open,
+ NULL
+};
+
+//====================================================================
+//Specific spp's dct, idct and threshold functions
+//I'd prefer to have them in the separate file.
+
+//#define MANGLE(a) #a
+
+//typedef int16_t DCTELEM; //! only int16_t
+
+#define DCTSIZE 8
+#define DCTSIZE_S "8"
+
+#define FIX(x,s) ((int) ((x) * (1<<s) + 0.5)&0xffff)
+#define C64(x) ((uint64_t)((x)|(x)<<16))<<32 | (uint64_t)(x) | (uint64_t)(x)<<16
+#define FIX64(x,s) C64(FIX(x,s))
+
+#define MULTIPLY16H(x,k) (((x)*(k))>>16)
+#define THRESHOLD(r,x,t) if(((unsigned)((x)+t))>t*2) r=(x);else r=0;
+#define DESCALE(x,n) (((x) + (1 << ((n)-1))) >> n)
+
+#if HAVE_MMX
+
+DECLARE_ASM_CONST(8, uint64_t, MM_FIX_0_382683433)=FIX64(0.382683433, 14);
+DECLARE_ASM_CONST(8, uint64_t, MM_FIX_0_541196100)=FIX64(0.541196100, 14);
+DECLARE_ASM_CONST(8, uint64_t, MM_FIX_0_707106781)=FIX64(0.707106781, 14);
+DECLARE_ASM_CONST(8, uint64_t, MM_FIX_1_306562965)=FIX64(1.306562965, 14);
+
+DECLARE_ASM_CONST(8, uint64_t, MM_FIX_1_414213562_A)=FIX64(1.414213562, 14);
+
+DECLARE_ASM_CONST(8, uint64_t, MM_FIX_1_847759065)=FIX64(1.847759065, 13);
+DECLARE_ASM_CONST(8, uint64_t, MM_FIX_2_613125930)=FIX64(-2.613125930, 13); //-
+DECLARE_ASM_CONST(8, uint64_t, MM_FIX_1_414213562)=FIX64(1.414213562, 13);
+DECLARE_ASM_CONST(8, uint64_t, MM_FIX_1_082392200)=FIX64(1.082392200, 13);
+//for t3,t5,t7 == 0 shortcut
+DECLARE_ASM_CONST(8, uint64_t, MM_FIX_0_847759065)=FIX64(0.847759065, 14);
+DECLARE_ASM_CONST(8, uint64_t, MM_FIX_0_566454497)=FIX64(0.566454497, 14);
+DECLARE_ASM_CONST(8, uint64_t, MM_FIX_0_198912367)=FIX64(0.198912367, 14);
+
+DECLARE_ASM_CONST(8, uint64_t, MM_DESCALE_RND)=C64(4);
+DECLARE_ASM_CONST(8, uint64_t, MM_2)=C64(2);
+
+#else /* !HAVE_MMX */
+
+typedef int32_t int_simd16_t;
+static const int16_t FIX_0_382683433=FIX(0.382683433, 14);
+static const int16_t FIX_0_541196100=FIX(0.541196100, 14);
+static const int16_t FIX_0_707106781=FIX(0.707106781, 14);
+static const int16_t FIX_1_306562965=FIX(1.306562965, 14);
+static const int16_t FIX_1_414213562_A=FIX(1.414213562, 14);
+static const int16_t FIX_1_847759065=FIX(1.847759065, 13);
+static const int16_t FIX_2_613125930=FIX(-2.613125930, 13); //-
+static const int16_t FIX_1_414213562=FIX(1.414213562, 13);
+static const int16_t FIX_1_082392200=FIX(1.082392200, 13);
+
+#endif
+
+#if !HAVE_MMX
+
+static void column_fidct_c(int16_t* thr_adr, DCTELEM *data, DCTELEM *output, int cnt)
+{
+ int_simd16_t tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
+ int_simd16_t tmp10, tmp11, tmp12, tmp13;
+ int_simd16_t z1,z2,z3,z4,z5, z10, z11, z12, z13;
+ int_simd16_t d0, d1, d2, d3, d4, d5, d6, d7;
+
+ DCTELEM* dataptr;
+ DCTELEM* wsptr;
+ int16_t *threshold;
+ int ctr;
+
+ dataptr = data;
+ wsptr = output;
+
+ for (; cnt > 0; cnt-=2) { //start positions
+ threshold=(int16_t*)thr_adr;//threshold_mtx
+ for (ctr = DCTSIZE; ctr > 0; ctr--) {
+ // Process columns from input, add to output.
+ tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
+ tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
+
+ tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
+ tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
+
+ tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
+ tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
+
+ tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
+ tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
+
+ // Even part of FDCT
+
+ tmp10 = tmp0 + tmp3;
+ tmp13 = tmp0 - tmp3;
+ tmp11 = tmp1 + tmp2;
+ tmp12 = tmp1 - tmp2;
+
+ d0 = tmp10 + tmp11;
+ d4 = tmp10 - tmp11;
+
+ z1 = MULTIPLY16H((tmp12 + tmp13) <<2, FIX_0_707106781);
+ d2 = tmp13 + z1;
+ d6 = tmp13 - z1;
+
+ // Even part of IDCT
+
+ THRESHOLD(tmp0, d0, threshold[0*8]);
+ THRESHOLD(tmp1, d2, threshold[2*8]);
+ THRESHOLD(tmp2, d4, threshold[4*8]);
+ THRESHOLD(tmp3, d6, threshold[6*8]);
+ tmp0+=2;
+ tmp10 = (tmp0 + tmp2)>>2;
+ tmp11 = (tmp0 - tmp2)>>2;
+
+ tmp13 = (tmp1 + tmp3)>>2; //+2 ! (psnr decides)
+ tmp12 = MULTIPLY16H((tmp1 - tmp3), FIX_1_414213562_A) - tmp13; //<<2
+
+ tmp0 = tmp10 + tmp13; //->temps
+ tmp3 = tmp10 - tmp13; //->temps
+ tmp1 = tmp11 + tmp12; //->temps
+ tmp2 = tmp11 - tmp12; //->temps
+
+ // Odd part of FDCT
+
+ tmp10 = tmp4 + tmp5;
+ tmp11 = tmp5 + tmp6;
+ tmp12 = tmp6 + tmp7;
+
+ z5 = MULTIPLY16H((tmp10 - tmp12)<<2, FIX_0_382683433);
+ z2 = MULTIPLY16H(tmp10 <<2, FIX_0_541196100) + z5;
+ z4 = MULTIPLY16H(tmp12 <<2, FIX_1_306562965) + z5;
+ z3 = MULTIPLY16H(tmp11 <<2, FIX_0_707106781);
+
+ z11 = tmp7 + z3;
+ z13 = tmp7 - z3;
+
+ d5 = z13 + z2;
+ d3 = z13 - z2;
+ d1 = z11 + z4;
+ d7 = z11 - z4;
+
+ // Odd part of IDCT
+
+ THRESHOLD(tmp4, d1, threshold[1*8]);
+ THRESHOLD(tmp5, d3, threshold[3*8]);
+ THRESHOLD(tmp6, d5, threshold[5*8]);
+ THRESHOLD(tmp7, d7, threshold[7*8]);
+
+ //Simd version uses here a shortcut for the tmp5,tmp6,tmp7 == 0
+ z13 = tmp6 + tmp5;
+ z10 = (tmp6 - tmp5)<<1;
+ z11 = tmp4 + tmp7;
+ z12 = (tmp4 - tmp7)<<1;
+
+ tmp7 = (z11 + z13)>>2; //+2 !
+ tmp11 = MULTIPLY16H((z11 - z13)<<1, FIX_1_414213562);
+ z5 = MULTIPLY16H(z10 + z12, FIX_1_847759065);
+ tmp10 = MULTIPLY16H(z12, FIX_1_082392200) - z5;
+ tmp12 = MULTIPLY16H(z10, FIX_2_613125930) + z5; // - !!
+
+ tmp6 = tmp12 - tmp7;
+ tmp5 = tmp11 - tmp6;
+ tmp4 = tmp10 + tmp5;
+
+ wsptr[DCTSIZE*0]+= (tmp0 + tmp7);
+ wsptr[DCTSIZE*1]+= (tmp1 + tmp6);
+ wsptr[DCTSIZE*2]+= (tmp2 + tmp5);
+ wsptr[DCTSIZE*3]+= (tmp3 - tmp4);
+ wsptr[DCTSIZE*4]+= (tmp3 + tmp4);
+ wsptr[DCTSIZE*5]+= (tmp2 - tmp5);
+ wsptr[DCTSIZE*6]= (tmp1 - tmp6);
+ wsptr[DCTSIZE*7]= (tmp0 - tmp7);
+ //
+ dataptr++; //next column
+ wsptr++;
+ threshold++;
+ }
+ dataptr+=8; //skip each second start pos
+ wsptr +=8;
+ }
+}
+
+#else /* HAVE_MMX */
+
+static void column_fidct_mmx(int16_t* thr_adr, DCTELEM *data, DCTELEM *output, int cnt)
+{
+ uint64_t __attribute__((aligned(8))) temps[4];
+ __asm__ volatile(
+ ASMALIGN(4)
+ "1: \n\t"
+ "movq "DCTSIZE_S"*0*2(%%"REG_S"), %%mm1 \n\t"
+ //
+ "movq "DCTSIZE_S"*3*2(%%"REG_S"), %%mm7 \n\t"
+ "movq %%mm1, %%mm0 \n\t"
+
+ "paddw "DCTSIZE_S"*7*2(%%"REG_S"), %%mm1 \n\t" //t0
+ "movq %%mm7, %%mm3 \n\t"
+
+ "paddw "DCTSIZE_S"*4*2(%%"REG_S"), %%mm7 \n\t" //t3
+ "movq %%mm1, %%mm5 \n\t"
+
+ "movq "DCTSIZE_S"*1*2(%%"REG_S"), %%mm6 \n\t"
+ "psubw %%mm7, %%mm1 \n\t" //t13
+
+ "movq "DCTSIZE_S"*2*2(%%"REG_S"), %%mm2 \n\t"
+ "movq %%mm6, %%mm4 \n\t"
+
+ "paddw "DCTSIZE_S"*6*2(%%"REG_S"), %%mm6 \n\t" //t1
+ "paddw %%mm7, %%mm5 \n\t" //t10
+
+ "paddw "DCTSIZE_S"*5*2(%%"REG_S"), %%mm2 \n\t" //t2
+ "movq %%mm6, %%mm7 \n\t"
+
+ "paddw %%mm2, %%mm6 \n\t" //t11
+ "psubw %%mm2, %%mm7 \n\t" //t12
+
+ "movq %%mm5, %%mm2 \n\t"
+ "paddw %%mm6, %%mm5 \n\t" //d0
+ // i0 t13 t12 i3 i1 d0 - d4
+ "psubw %%mm6, %%mm2 \n\t" //d4
+ "paddw %%mm1, %%mm7 \n\t"
+
+ "movq 4*16(%%"REG_d"), %%mm6 \n\t"
+ "psllw $2, %%mm7 \n\t"
+
+ "psubw 0*16(%%"REG_d"), %%mm5 \n\t"
+ "psubw %%mm6, %%mm2 \n\t"
+
+ "paddusw 0*16(%%"REG_d"), %%mm5 \n\t"
+ "paddusw %%mm6, %%mm2 \n\t"
+
+ "pmulhw "MANGLE(MM_FIX_0_707106781)", %%mm7 \n\t"
+ //
+ "paddw 0*16(%%"REG_d"), %%mm5 \n\t"
+ "paddw %%mm6, %%mm2 \n\t"
+
+ "psubusw 0*16(%%"REG_d"), %%mm5 \n\t"
+ "psubusw %%mm6, %%mm2 \n\t"
+
+//This func is totally compute-bound, operates at huge speed. So, DC shortcut
+// at this place isn't worthwhile due to BTB miss penalty (checked on Pent. 3).
+//However, typical numbers: nondc - 29%%, dc - 46%%, zero - 25%%. All <> 0 case is very rare.
+ "paddw "MANGLE(MM_2)", %%mm5 \n\t"
+ "movq %%mm2, %%mm6 \n\t"
+
+ "paddw %%mm5, %%mm2 \n\t"
+ "psubw %%mm6, %%mm5 \n\t"
+
+ "movq %%mm1, %%mm6 \n\t"
+ "paddw %%mm7, %%mm1 \n\t" //d2
+
+ "psubw 2*16(%%"REG_d"), %%mm1 \n\t"
+ "psubw %%mm7, %%mm6 \n\t" //d6
+
+ "movq 6*16(%%"REG_d"), %%mm7 \n\t"
+ "psraw $2, %%mm5 \n\t"
+
+ "paddusw 2*16(%%"REG_d"), %%mm1 \n\t"
+ "psubw %%mm7, %%mm6 \n\t"
+ // t7 d2 /t11 t4 t6 - d6 /t10
+
+ "paddw 2*16(%%"REG_d"), %%mm1 \n\t"
+ "paddusw %%mm7, %%mm6 \n\t"
+
+ "psubusw 2*16(%%"REG_d"), %%mm1 \n\t"
+ "paddw %%mm7, %%mm6 \n\t"
+
+ "psubw "DCTSIZE_S"*4*2(%%"REG_S"), %%mm3 \n\t"
+ "psubusw %%mm7, %%mm6 \n\t"
+
+ //movq [edi+"DCTSIZE_S"*2*2], mm1
+ //movq [edi+"DCTSIZE_S"*6*2], mm6
+ "movq %%mm1, %%mm7 \n\t"
+ "psraw $2, %%mm2 \n\t"
+
+ "psubw "DCTSIZE_S"*6*2(%%"REG_S"), %%mm4 \n\t"
+ "psubw %%mm6, %%mm1 \n\t"
+
+ "psubw "DCTSIZE_S"*7*2(%%"REG_S"), %%mm0 \n\t"
+ "paddw %%mm7, %%mm6 \n\t" //'t13
+
+ "psraw $2, %%mm6 \n\t" //paddw mm6, MM_2 !! ---
+ "movq %%mm2, %%mm7 \n\t"
+
+ "pmulhw "MANGLE(MM_FIX_1_414213562_A)", %%mm1 \n\t"
+ "paddw %%mm6, %%mm2 \n\t" //'t0
+
+ "movq %%mm2, 0*8+%3 \n\t" //!
+ "psubw %%mm6, %%mm7 \n\t" //'t3
+
+ "movq "DCTSIZE_S"*2*2(%%"REG_S"), %%mm2 \n\t"
+ "psubw %%mm6, %%mm1 \n\t" //'t12
+
+ "psubw "DCTSIZE_S"*5*2(%%"REG_S"), %%mm2 \n\t" //t5
+ "movq %%mm5, %%mm6 \n\t"
+
+ "movq %%mm7, 3*8+%3 \n\t"
+ "paddw %%mm2, %%mm3 \n\t" //t10
+
+ "paddw %%mm4, %%mm2 \n\t" //t11
+ "paddw %%mm0, %%mm4 \n\t" //t12
+
+ "movq %%mm3, %%mm7 \n\t"
+ "psubw %%mm4, %%mm3 \n\t"
+
+ "psllw $2, %%mm3 \n\t"
+ "psllw $2, %%mm7 \n\t" //opt for P6
+
+ "pmulhw "MANGLE(MM_FIX_0_382683433)", %%mm3 \n\t"
+ "psllw $2, %%mm4 \n\t"
+
+ "pmulhw "MANGLE(MM_FIX_0_541196100)", %%mm7 \n\t"
+ "psllw $2, %%mm2 \n\t"
+
+ "pmulhw "MANGLE(MM_FIX_1_306562965)", %%mm4 \n\t"
+ "paddw %%mm1, %%mm5 \n\t" //'t1
+
+ "pmulhw "MANGLE(MM_FIX_0_707106781)", %%mm2 \n\t"
+ "psubw %%mm1, %%mm6 \n\t" //'t2
+ // t7 't12 't11 t4 t6 - 't13 't10 ---
+
+ "paddw %%mm3, %%mm7 \n\t" //z2
+
+ "movq %%mm5, 1*8+%3 \n\t"
+ "paddw %%mm3, %%mm4 \n\t" //z4
+
+ "movq 3*16(%%"REG_d"), %%mm3 \n\t"
+ "movq %%mm0, %%mm1 \n\t"
+
+ "movq %%mm6, 2*8+%3 \n\t"
+ "psubw %%mm2, %%mm1 \n\t" //z13
+
+//===
+ "paddw %%mm2, %%mm0 \n\t" //z11
+ "movq %%mm1, %%mm5 \n\t"
+
+ "movq 5*16(%%"REG_d"), %%mm2 \n\t"
+ "psubw %%mm7, %%mm1 \n\t" //d3
+
+ "paddw %%mm7, %%mm5 \n\t" //d5
+ "psubw %%mm3, %%mm1 \n\t"
+
+ "movq 1*16(%%"REG_d"), %%mm7 \n\t"
+ "psubw %%mm2, %%mm5 \n\t"
+
+ "movq %%mm0, %%mm6 \n\t"
+ "paddw %%mm4, %%mm0 \n\t" //d1
+
+ "paddusw %%mm3, %%mm1 \n\t"
+ "psubw %%mm4, %%mm6 \n\t" //d7
+
+ // d1 d3 - - - d5 d7 -
+ "movq 7*16(%%"REG_d"), %%mm4 \n\t"
+ "psubw %%mm7, %%mm0 \n\t"
+
+ "psubw %%mm4, %%mm6 \n\t"
+ "paddusw %%mm2, %%mm5 \n\t"
+
+ "paddusw %%mm4, %%mm6 \n\t"
+ "paddw %%mm3, %%mm1 \n\t"
+
+ "paddw %%mm2, %%mm5 \n\t"
+ "paddw %%mm4, %%mm6 \n\t"
+
+ "psubusw %%mm3, %%mm1 \n\t"
+ "psubusw %%mm2, %%mm5 \n\t"
+
+ "psubusw %%mm4, %%mm6 \n\t"
+ "movq %%mm1, %%mm4 \n\t"
+
+ "por %%mm5, %%mm4 \n\t"
+ "paddusw %%mm7, %%mm0 \n\t"
+
+ "por %%mm6, %%mm4 \n\t"
+ "paddw %%mm7, %%mm0 \n\t"
+
+ "packssdw %%mm4, %%mm4 \n\t"
+ "psubusw %%mm7, %%mm0 \n\t"
+
+ "movd %%mm4, %%"REG_a" \n\t"
+ "or %%"REG_a", %%"REG_a" \n\t"
+ "jnz 2f \n\t"
+ //movq [edi+"DCTSIZE_S"*3*2], mm1
+ //movq [edi+"DCTSIZE_S"*5*2], mm5
+ //movq [edi+"DCTSIZE_S"*1*2], mm0
+ //movq [edi+"DCTSIZE_S"*7*2], mm6
+ // t4 t5 - - - t6 t7 -
+ //--- t4 (mm0) may be <>0; mm1, mm5, mm6 == 0
+//Typical numbers: nondc - 19%%, dc - 26%%, zero - 55%%. zero case alone isn't worthwhile
+ "movq 0*8+%3, %%mm4 \n\t"
+ "movq %%mm0, %%mm1 \n\t"
+
+ "pmulhw "MANGLE(MM_FIX_0_847759065)", %%mm0 \n\t" //tmp6
+ "movq %%mm1, %%mm2 \n\t"
+
+ "movq "DCTSIZE_S"*0*2(%%"REG_D"), %%mm5 \n\t"
+ "movq %%mm2, %%mm3 \n\t"
+
+ "pmulhw "MANGLE(MM_FIX_0_566454497)", %%mm1 \n\t" //tmp5
+ "paddw %%mm4, %%mm5 \n\t"
+
+ "movq 1*8+%3, %%mm6 \n\t"
+ //paddw mm3, MM_2
+ "psraw $2, %%mm3 \n\t" //tmp7
+
+ "pmulhw "MANGLE(MM_FIX_0_198912367)", %%mm2 \n\t" //-tmp4
+ "psubw %%mm3, %%mm4 \n\t"
+
+ "movq "DCTSIZE_S"*1*2(%%"REG_D"), %%mm7 \n\t"
+ "paddw %%mm3, %%mm5 \n\t"
+
+ "movq %%mm4, "DCTSIZE_S"*7*2(%%"REG_D") \n\t"
+ "paddw %%mm6, %%mm7 \n\t"
+
+ "movq 2*8+%3, %%mm3 \n\t"
+ "psubw %%mm0, %%mm6 \n\t"
+
+ "movq "DCTSIZE_S"*2*2(%%"REG_D"), %%mm4 \n\t"
+ "paddw %%mm0, %%mm7 \n\t"
+
+ "movq %%mm5, "DCTSIZE_S"*0*2(%%"REG_D") \n\t"
+ "paddw %%mm3, %%mm4 \n\t"
+
+ "movq %%mm6, "DCTSIZE_S"*6*2(%%"REG_D") \n\t"
+ "psubw %%mm1, %%mm3 \n\t"
+
+ "movq "DCTSIZE_S"*5*2(%%"REG_D"), %%mm5 \n\t"
+ "paddw %%mm1, %%mm4 \n\t"
+
+ "movq "DCTSIZE_S"*3*2(%%"REG_D"), %%mm6 \n\t"
+ "paddw %%mm3, %%mm5 \n\t"
+
+ "movq 3*8+%3, %%mm0 \n\t"
+ "add $8, %%"REG_S" \n\t"
+
+ "movq %%mm7, "DCTSIZE_S"*1*2(%%"REG_D") \n\t"
+ "paddw %%mm0, %%mm6 \n\t"
+
+ "movq %%mm4, "DCTSIZE_S"*2*2(%%"REG_D") \n\t"
+ "psubw %%mm2, %%mm0 \n\t"
+
+ "movq "DCTSIZE_S"*4*2(%%"REG_D"), %%mm7 \n\t"
+ "paddw %%mm2, %%mm6 \n\t"
+
+ "movq %%mm5, "DCTSIZE_S"*5*2(%%"REG_D") \n\t"
+ "paddw %%mm0, %%mm7 \n\t"
+
+ "movq %%mm6, "DCTSIZE_S"*3*2(%%"REG_D") \n\t"
+
+ "movq %%mm7, "DCTSIZE_S"*4*2(%%"REG_D") \n\t"
+ "add $8, %%"REG_D" \n\t"
+ "jmp 4f \n\t"
+
+ "2: \n\t"
+ //--- non DC2
+ //psraw mm1, 2 w/o it -> offset. thr1, thr1, thr1 (actually thr1, thr1, thr1-1)
+ //psraw mm5, 2
+ //psraw mm0, 2
+ //psraw mm6, 2
+ "movq %%mm5, %%mm3 \n\t"
+ "psubw %%mm1, %%mm5 \n\t"
+
+ "psllw $1, %%mm5 \n\t" //'z10
+ "paddw %%mm1, %%mm3 \n\t" //'z13
+
+ "movq %%mm0, %%mm2 \n\t"
+ "psubw %%mm6, %%mm0 \n\t"
+
+ "movq %%mm5, %%mm1 \n\t"
+ "psllw $1, %%mm0 \n\t" //'z12
+
+ "pmulhw "MANGLE(MM_FIX_2_613125930)", %%mm1 \n\t" //-
+ "paddw %%mm0, %%mm5 \n\t"
+
+ "pmulhw "MANGLE(MM_FIX_1_847759065)", %%mm5 \n\t" //'z5
+ "paddw %%mm6, %%mm2 \n\t" //'z11
+
+ "pmulhw "MANGLE(MM_FIX_1_082392200)", %%mm0 \n\t"
+ "movq %%mm2, %%mm7 \n\t"
+
+ //---
+ "movq 0*8+%3, %%mm4 \n\t"
+ "psubw %%mm3, %%mm2 \n\t"
+
+ "psllw $1, %%mm2 \n\t"
+ "paddw %%mm3, %%mm7 \n\t" //'t7
+
+ "pmulhw "MANGLE(MM_FIX_1_414213562)", %%mm2 \n\t" //'t11
+ "movq %%mm4, %%mm6 \n\t"
+ //paddw mm7, MM_2
+ "psraw $2, %%mm7 \n\t"
+
+ "paddw "DCTSIZE_S"*0*2(%%"REG_D"), %%mm4 \n\t"
+ "psubw %%mm7, %%mm6 \n\t"
+
+ "movq 1*8+%3, %%mm3 \n\t"
+ "paddw %%mm7, %%mm4 \n\t"
+
+ "movq %%mm6, "DCTSIZE_S"*7*2(%%"REG_D") \n\t"
+ "paddw %%mm5, %%mm1 \n\t" //'t12
+
+ "movq %%mm4, "DCTSIZE_S"*0*2(%%"REG_D") \n\t"
+ "psubw %%mm7, %%mm1 \n\t" //'t6
+
+ "movq 2*8+%3, %%mm7 \n\t"
+ "psubw %%mm5, %%mm0 \n\t" //'t10
+
+ "movq 3*8+%3, %%mm6 \n\t"
+ "movq %%mm3, %%mm5 \n\t"
+
+ "paddw "DCTSIZE_S"*1*2(%%"REG_D"), %%mm3 \n\t"
+ "psubw %%mm1, %%mm5 \n\t"
+
+ "psubw %%mm1, %%mm2 \n\t" //'t5
+ "paddw %%mm1, %%mm3 \n\t"
+
+ "movq %%mm5, "DCTSIZE_S"*6*2(%%"REG_D") \n\t"
+ "movq %%mm7, %%mm4 \n\t"
+
+ "paddw "DCTSIZE_S"*2*2(%%"REG_D"), %%mm7 \n\t"
+ "psubw %%mm2, %%mm4 \n\t"
+
+ "paddw "DCTSIZE_S"*5*2(%%"REG_D"), %%mm4 \n\t"
+ "paddw %%mm2, %%mm7 \n\t"
+
+ "movq %%mm3, "DCTSIZE_S"*1*2(%%"REG_D") \n\t"
+ "paddw %%mm2, %%mm0 \n\t" //'t4
+
+ // 't4 't6 't5 - - - - 't7
+ "movq %%mm7, "DCTSIZE_S"*2*2(%%"REG_D") \n\t"
+ "movq %%mm6, %%mm1 \n\t"
+
+ "paddw "DCTSIZE_S"*4*2(%%"REG_D"), %%mm6 \n\t"
+ "psubw %%mm0, %%mm1 \n\t"
+
+ "paddw "DCTSIZE_S"*3*2(%%"REG_D"), %%mm1 \n\t"
+ "paddw %%mm0, %%mm6 \n\t"
+
+ "movq %%mm4, "DCTSIZE_S"*5*2(%%"REG_D") \n\t"
+ "add $8, %%"REG_S" \n\t"
+
+ "movq %%mm6, "DCTSIZE_S"*4*2(%%"REG_D") \n\t"
+
+ "movq %%mm1, "DCTSIZE_S"*3*2(%%"REG_D") \n\t"
+ "add $8, %%"REG_D" \n\t"
+
+ "4: \n\t"
+//=part 2 (the same)===========================================================
+ "movq "DCTSIZE_S"*0*2(%%"REG_S"), %%mm1 \n\t"
+ //
+ "movq "DCTSIZE_S"*3*2(%%"REG_S"), %%mm7 \n\t"
+ "movq %%mm1, %%mm0 \n\t"
+
+ "paddw "DCTSIZE_S"*7*2(%%"REG_S"), %%mm1 \n\t" //t0
+ "movq %%mm7, %%mm3 \n\t"
+
+ "paddw "DCTSIZE_S"*4*2(%%"REG_S"), %%mm7 \n\t" //t3
+ "movq %%mm1, %%mm5 \n\t"
+
+ "movq "DCTSIZE_S"*1*2(%%"REG_S"), %%mm6 \n\t"
+ "psubw %%mm7, %%mm1 \n\t" //t13
+
+ "movq "DCTSIZE_S"*2*2(%%"REG_S"), %%mm2 \n\t"
+ "movq %%mm6, %%mm4 \n\t"
+
+ "paddw "DCTSIZE_S"*6*2(%%"REG_S"), %%mm6 \n\t" //t1
+ "paddw %%mm7, %%mm5 \n\t" //t10
+
+ "paddw "DCTSIZE_S"*5*2(%%"REG_S"), %%mm2 \n\t" //t2
+ "movq %%mm6, %%mm7 \n\t"
+
+ "paddw %%mm2, %%mm6 \n\t" //t11
+ "psubw %%mm2, %%mm7 \n\t" //t12
+
+ "movq %%mm5, %%mm2 \n\t"
+ "paddw %%mm6, %%mm5 \n\t" //d0
+ // i0 t13 t12 i3 i1 d0 - d4
+ "psubw %%mm6, %%mm2 \n\t" //d4
+ "paddw %%mm1, %%mm7 \n\t"
+
+ "movq 1*8+4*16(%%"REG_d"), %%mm6 \n\t"
+ "psllw $2, %%mm7 \n\t"
+
+ "psubw 1*8+0*16(%%"REG_d"), %%mm5 \n\t"
+ "psubw %%mm6, %%mm2 \n\t"
+
+ "paddusw 1*8+0*16(%%"REG_d"), %%mm5 \n\t"
+ "paddusw %%mm6, %%mm2 \n\t"
+
+ "pmulhw "MANGLE(MM_FIX_0_707106781)", %%mm7 \n\t"
+ //
+ "paddw 1*8+0*16(%%"REG_d"), %%mm5 \n\t"
+ "paddw %%mm6, %%mm2 \n\t"
+
+ "psubusw 1*8+0*16(%%"REG_d"), %%mm5 \n\t"
+ "psubusw %%mm6, %%mm2 \n\t"
+
+//This func is totally compute-bound, operates at huge speed. So, DC shortcut
+// at this place isn't worthwhile due to BTB miss penalty (checked on Pent. 3).
+//However, typical numbers: nondc - 29%%, dc - 46%%, zero - 25%%. All <> 0 case is very rare.
+ "paddw "MANGLE(MM_2)", %%mm5 \n\t"
+ "movq %%mm2, %%mm6 \n\t"
+
+ "paddw %%mm5, %%mm2 \n\t"
+ "psubw %%mm6, %%mm5 \n\t"
+
+ "movq %%mm1, %%mm6 \n\t"
+ "paddw %%mm7, %%mm1 \n\t" //d2
+
+ "psubw 1*8+2*16(%%"REG_d"), %%mm1 \n\t"
+ "psubw %%mm7, %%mm6 \n\t" //d6
+
+ "movq 1*8+6*16(%%"REG_d"), %%mm7 \n\t"
+ "psraw $2, %%mm5 \n\t"
+
+ "paddusw 1*8+2*16(%%"REG_d"), %%mm1 \n\t"
+ "psubw %%mm7, %%mm6 \n\t"
+ // t7 d2 /t11 t4 t6 - d6 /t10
+
+ "paddw 1*8+2*16(%%"REG_d"), %%mm1 \n\t"
+ "paddusw %%mm7, %%mm6 \n\t"
+
+ "psubusw 1*8+2*16(%%"REG_d"), %%mm1 \n\t"
+ "paddw %%mm7, %%mm6 \n\t"
+
+ "psubw "DCTSIZE_S"*4*2(%%"REG_S"), %%mm3 \n\t"
+ "psubusw %%mm7, %%mm6 \n\t"
+
+ //movq [edi+"DCTSIZE_S"*2*2], mm1
+ //movq [edi+"DCTSIZE_S"*6*2], mm6
+ "movq %%mm1, %%mm7 \n\t"
+ "psraw $2, %%mm2 \n\t"
+
+ "psubw "DCTSIZE_S"*6*2(%%"REG_S"), %%mm4 \n\t"
+ "psubw %%mm6, %%mm1 \n\t"
+
+ "psubw "DCTSIZE_S"*7*2(%%"REG_S"), %%mm0 \n\t"
+ "paddw %%mm7, %%mm6 \n\t" //'t13
+
+ "psraw $2, %%mm6 \n\t" //paddw mm6, MM_2 !! ---
+ "movq %%mm2, %%mm7 \n\t"
+
+ "pmulhw "MANGLE(MM_FIX_1_414213562_A)", %%mm1 \n\t"
+ "paddw %%mm6, %%mm2 \n\t" //'t0
+
+ "movq %%mm2, 0*8+%3 \n\t" //!
+ "psubw %%mm6, %%mm7 \n\t" //'t3
+
+ "movq "DCTSIZE_S"*2*2(%%"REG_S"), %%mm2 \n\t"
+ "psubw %%mm6, %%mm1 \n\t" //'t12
+
+ "psubw "DCTSIZE_S"*5*2(%%"REG_S"), %%mm2 \n\t" //t5
+ "movq %%mm5, %%mm6 \n\t"
+
+ "movq %%mm7, 3*8+%3 \n\t"
+ "paddw %%mm2, %%mm3 \n\t" //t10
+
+ "paddw %%mm4, %%mm2 \n\t" //t11
+ "paddw %%mm0, %%mm4 \n\t" //t12
+
+ "movq %%mm3, %%mm7 \n\t"
+ "psubw %%mm4, %%mm3 \n\t"
+
+ "psllw $2, %%mm3 \n\t"
+ "psllw $2, %%mm7 \n\t" //opt for P6
+
+ "pmulhw "MANGLE(MM_FIX_0_382683433)", %%mm3 \n\t"
+ "psllw $2, %%mm4 \n\t"
+
+ "pmulhw "MANGLE(MM_FIX_0_541196100)", %%mm7 \n\t"
+ "psllw $2, %%mm2 \n\t"
+
+ "pmulhw "MANGLE(MM_FIX_1_306562965)", %%mm4 \n\t"
+ "paddw %%mm1, %%mm5 \n\t" //'t1
+
+ "pmulhw "MANGLE(MM_FIX_0_707106781)", %%mm2 \n\t"
+ "psubw %%mm1, %%mm6 \n\t" //'t2
+ // t7 't12 't11 t4 t6 - 't13 't10 ---
+
+ "paddw %%mm3, %%mm7 \n\t" //z2
+
+ "movq %%mm5, 1*8+%3 \n\t"
+ "paddw %%mm3, %%mm4 \n\t" //z4
+
+ "movq 1*8+3*16(%%"REG_d"), %%mm3 \n\t"
+ "movq %%mm0, %%mm1 \n\t"
+
+ "movq %%mm6, 2*8+%3 \n\t"
+ "psubw %%mm2, %%mm1 \n\t" //z13
+
+//===
+ "paddw %%mm2, %%mm0 \n\t" //z11
+ "movq %%mm1, %%mm5 \n\t"
+
+ "movq 1*8+5*16(%%"REG_d"), %%mm2 \n\t"
+ "psubw %%mm7, %%mm1 \n\t" //d3
+
+ "paddw %%mm7, %%mm5 \n\t" //d5
+ "psubw %%mm3, %%mm1 \n\t"
+
+ "movq 1*8+1*16(%%"REG_d"), %%mm7 \n\t"
+ "psubw %%mm2, %%mm5 \n\t"
+
+ "movq %%mm0, %%mm6 \n\t"
+ "paddw %%mm4, %%mm0 \n\t" //d1
+
+ "paddusw %%mm3, %%mm1 \n\t"
+ "psubw %%mm4, %%mm6 \n\t" //d7
+
+ // d1 d3 - - - d5 d7 -
+ "movq 1*8+7*16(%%"REG_d"), %%mm4 \n\t"
+ "psubw %%mm7, %%mm0 \n\t"
+
+ "psubw %%mm4, %%mm6 \n\t"
+ "paddusw %%mm2, %%mm5 \n\t"
+
+ "paddusw %%mm4, %%mm6 \n\t"
+ "paddw %%mm3, %%mm1 \n\t"
+
+ "paddw %%mm2, %%mm5 \n\t"
+ "paddw %%mm4, %%mm6 \n\t"
+
+ "psubusw %%mm3, %%mm1 \n\t"
+ "psubusw %%mm2, %%mm5 \n\t"
+
+ "psubusw %%mm4, %%mm6 \n\t"
+ "movq %%mm1, %%mm4 \n\t"
+
+ "por %%mm5, %%mm4 \n\t"
+ "paddusw %%mm7, %%mm0 \n\t"
+
+ "por %%mm6, %%mm4 \n\t"
+ "paddw %%mm7, %%mm0 \n\t"
+
+ "packssdw %%mm4, %%mm4 \n\t"
+ "psubusw %%mm7, %%mm0 \n\t"
+
+ "movd %%mm4, %%"REG_a" \n\t"
+ "or %%"REG_a", %%"REG_a" \n\t"
+ "jnz 3f \n\t"
+ //movq [edi+"DCTSIZE_S"*3*2], mm1
+ //movq [edi+"DCTSIZE_S"*5*2], mm5
+ //movq [edi+"DCTSIZE_S"*1*2], mm0
+ //movq [edi+"DCTSIZE_S"*7*2], mm6
+ // t4 t5 - - - t6 t7 -
+ //--- t4 (mm0) may be <>0; mm1, mm5, mm6 == 0
+//Typical numbers: nondc - 19%%, dc - 26%%, zero - 55%%. zero case alone isn't worthwhile
+ "movq 0*8+%3, %%mm4 \n\t"
+ "movq %%mm0, %%mm1 \n\t"
+
+ "pmulhw "MANGLE(MM_FIX_0_847759065)", %%mm0 \n\t" //tmp6
+ "movq %%mm1, %%mm2 \n\t"
+
+ "movq "DCTSIZE_S"*0*2(%%"REG_D"), %%mm5 \n\t"
+ "movq %%mm2, %%mm3 \n\t"
+
+ "pmulhw "MANGLE(MM_FIX_0_566454497)", %%mm1 \n\t" //tmp5
+ "paddw %%mm4, %%mm5 \n\t"
+
+ "movq 1*8+%3, %%mm6 \n\t"
+ //paddw mm3, MM_2
+ "psraw $2, %%mm3 \n\t" //tmp7
+
+ "pmulhw "MANGLE(MM_FIX_0_198912367)", %%mm2 \n\t" //-tmp4
+ "psubw %%mm3, %%mm4 \n\t"
+
+ "movq "DCTSIZE_S"*1*2(%%"REG_D"), %%mm7 \n\t"
+ "paddw %%mm3, %%mm5 \n\t"
+
+ "movq %%mm4, "DCTSIZE_S"*7*2(%%"REG_D") \n\t"
+ "paddw %%mm6, %%mm7 \n\t"
+
+ "movq 2*8+%3, %%mm3 \n\t"
+ "psubw %%mm0, %%mm6 \n\t"
+
+ "movq "DCTSIZE_S"*2*2(%%"REG_D"), %%mm4 \n\t"
+ "paddw %%mm0, %%mm7 \n\t"
+
+ "movq %%mm5, "DCTSIZE_S"*0*2(%%"REG_D") \n\t"
+ "paddw %%mm3, %%mm4 \n\t"
+
+ "movq %%mm6, "DCTSIZE_S"*6*2(%%"REG_D") \n\t"
+ "psubw %%mm1, %%mm3 \n\t"
+
+ "movq "DCTSIZE_S"*5*2(%%"REG_D"), %%mm5 \n\t"
+ "paddw %%mm1, %%mm4 \n\t"
+
+ "movq "DCTSIZE_S"*3*2(%%"REG_D"), %%mm6 \n\t"
+ "paddw %%mm3, %%mm5 \n\t"
+
+ "movq 3*8+%3, %%mm0 \n\t"
+ "add $24, %%"REG_S" \n\t"
+
+ "movq %%mm7, "DCTSIZE_S"*1*2(%%"REG_D") \n\t"
+ "paddw %%mm0, %%mm6 \n\t"
+
+ "movq %%mm4, "DCTSIZE_S"*2*2(%%"REG_D") \n\t"
+ "psubw %%mm2, %%mm0 \n\t"
+
+ "movq "DCTSIZE_S"*4*2(%%"REG_D"), %%mm7 \n\t"
+ "paddw %%mm2, %%mm6 \n\t"
+
+ "movq %%mm5, "DCTSIZE_S"*5*2(%%"REG_D") \n\t"
+ "paddw %%mm0, %%mm7 \n\t"
+
+ "movq %%mm6, "DCTSIZE_S"*3*2(%%"REG_D") \n\t"
+
+ "movq %%mm7, "DCTSIZE_S"*4*2(%%"REG_D") \n\t"
+ "add $24, %%"REG_D" \n\t"
+ "sub $2, %%"REG_c" \n\t"
+ "jnz 1b \n\t"
+ "jmp 5f \n\t"
+
+ "3: \n\t"
+ //--- non DC2
+ //psraw mm1, 2 w/o it -> offset. thr1, thr1, thr1 (actually thr1, thr1, thr1-1)
+ //psraw mm5, 2
+ //psraw mm0, 2
+ //psraw mm6, 2
+ "movq %%mm5, %%mm3 \n\t"
+ "psubw %%mm1, %%mm5 \n\t"
+
+ "psllw $1, %%mm5 \n\t" //'z10
+ "paddw %%mm1, %%mm3 \n\t" //'z13
+
+ "movq %%mm0, %%mm2 \n\t"
+ "psubw %%mm6, %%mm0 \n\t"
+
+ "movq %%mm5, %%mm1 \n\t"
+ "psllw $1, %%mm0 \n\t" //'z12
+
+ "pmulhw "MANGLE(MM_FIX_2_613125930)", %%mm1 \n\t" //-
+ "paddw %%mm0, %%mm5 \n\t"
+
+ "pmulhw "MANGLE(MM_FIX_1_847759065)", %%mm5 \n\t" //'z5
+ "paddw %%mm6, %%mm2 \n\t" //'z11
+
+ "pmulhw "MANGLE(MM_FIX_1_082392200)", %%mm0 \n\t"
+ "movq %%mm2, %%mm7 \n\t"
+
+ //---
+ "movq 0*8+%3, %%mm4 \n\t"
+ "psubw %%mm3, %%mm2 \n\t"
+
+ "psllw $1, %%mm2 \n\t"
+ "paddw %%mm3, %%mm7 \n\t" //'t7
+
+ "pmulhw "MANGLE(MM_FIX_1_414213562)", %%mm2 \n\t" //'t11
+ "movq %%mm4, %%mm6 \n\t"
+ //paddw mm7, MM_2
+ "psraw $2, %%mm7 \n\t"
+
+ "paddw "DCTSIZE_S"*0*2(%%"REG_D"), %%mm4 \n\t"
+ "psubw %%mm7, %%mm6 \n\t"
+
+ "movq 1*8+%3, %%mm3 \n\t"
+ "paddw %%mm7, %%mm4 \n\t"
+
+ "movq %%mm6, "DCTSIZE_S"*7*2(%%"REG_D") \n\t"
+ "paddw %%mm5, %%mm1 \n\t" //'t12
+
+ "movq %%mm4, "DCTSIZE_S"*0*2(%%"REG_D") \n\t"
+ "psubw %%mm7, %%mm1 \n\t" //'t6
+
+ "movq 2*8+%3, %%mm7 \n\t"
+ "psubw %%mm5, %%mm0 \n\t" //'t10
+
+ "movq 3*8+%3, %%mm6 \n\t"
+ "movq %%mm3, %%mm5 \n\t"
+
+ "paddw "DCTSIZE_S"*1*2(%%"REG_D"), %%mm3 \n\t"
+ "psubw %%mm1, %%mm5 \n\t"
+
+ "psubw %%mm1, %%mm2 \n\t" //'t5
+ "paddw %%mm1, %%mm3 \n\t"
+
+ "movq %%mm5, "DCTSIZE_S"*6*2(%%"REG_D") \n\t"
+ "movq %%mm7, %%mm4 \n\t"
+
+ "paddw "DCTSIZE_S"*2*2(%%"REG_D"), %%mm7 \n\t"
+ "psubw %%mm2, %%mm4 \n\t"
+
+ "paddw "DCTSIZE_S"*5*2(%%"REG_D"), %%mm4 \n\t"
+ "paddw %%mm2, %%mm7 \n\t"
+
+ "movq %%mm3, "DCTSIZE_S"*1*2(%%"REG_D") \n\t"
+ "paddw %%mm2, %%mm0 \n\t" //'t4
+
+ // 't4 't6 't5 - - - - 't7
+ "movq %%mm7, "DCTSIZE_S"*2*2(%%"REG_D") \n\t"
+ "movq %%mm6, %%mm1 \n\t"
+
+ "paddw "DCTSIZE_S"*4*2(%%"REG_D"), %%mm6 \n\t"
+ "psubw %%mm0, %%mm1 \n\t"
+
+ "paddw "DCTSIZE_S"*3*2(%%"REG_D"), %%mm1 \n\t"
+ "paddw %%mm0, %%mm6 \n\t"
+
+ "movq %%mm4, "DCTSIZE_S"*5*2(%%"REG_D") \n\t"
+ "add $24, %%"REG_S" \n\t"
+
+ "movq %%mm6, "DCTSIZE_S"*4*2(%%"REG_D") \n\t"
+
+ "movq %%mm1, "DCTSIZE_S"*3*2(%%"REG_D") \n\t"
+ "add $24, %%"REG_D" \n\t"
+ "sub $2, %%"REG_c" \n\t"
+ "jnz 1b \n\t"
+ "5: \n\t"
+
+ : "+S"(data), "+D"(output), "+c"(cnt), "=o"(temps)
+ : "d"(thr_adr)
+ : "%"REG_a
+ );
+}
+
+#endif // HAVE_MMX
+
+#if !HAVE_MMX
+
+static void row_idct_c(DCTELEM* workspace,
+ int16_t* output_adr, int output_stride, int cnt)
+{
+ int_simd16_t tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
+ int_simd16_t tmp10, tmp11, tmp12, tmp13;
+ int_simd16_t z5, z10, z11, z12, z13;
+ int16_t* outptr;
+ DCTELEM* wsptr;
+
+ cnt*=4;
+ wsptr = workspace;
+ outptr = output_adr;
+ for (; cnt > 0; cnt--) {
+ // Even part
+ //Simd version reads 4x4 block and transposes it
+ tmp10 = ( wsptr[2] + wsptr[3]);
+ tmp11 = ( wsptr[2] - wsptr[3]);
+
+ tmp13 = ( wsptr[0] + wsptr[1]);
+ tmp12 = (MULTIPLY16H( wsptr[0] - wsptr[1], FIX_1_414213562_A)<<2) - tmp13;//this shift order to avoid overflow
+
+ tmp0 = tmp10 + tmp13; //->temps
+ tmp3 = tmp10 - tmp13; //->temps
+ tmp1 = tmp11 + tmp12;
+ tmp2 = tmp11 - tmp12;
+
+ // Odd part
+ //Also transpose, with previous:
+ // ---- ---- ||||
+ // ---- ---- idct ||||
+ // ---- ---- ---> ||||
+ // ---- ---- ||||
+ z13 = wsptr[4] + wsptr[5];
+ z10 = wsptr[4] - wsptr[5];
+ z11 = wsptr[6] + wsptr[7];
+ z12 = wsptr[6] - wsptr[7];
+
+ tmp7 = z11 + z13;
+ tmp11 = MULTIPLY16H(z11 - z13, FIX_1_414213562);
+
+ z5 = MULTIPLY16H(z10 + z12, FIX_1_847759065);
+ tmp10 = MULTIPLY16H(z12, FIX_1_082392200) - z5;
+ tmp12 = MULTIPLY16H(z10, FIX_2_613125930) + z5; // - FIX_
+
+ tmp6 = (tmp12<<3) - tmp7;
+ tmp5 = (tmp11<<3) - tmp6;
+ tmp4 = (tmp10<<3) + tmp5;
+
+ // Final output stage: descale and write column
+ outptr[0*output_stride]+= DESCALE(tmp0 + tmp7, 3);
+ outptr[1*output_stride]+= DESCALE(tmp1 + tmp6, 3);
+ outptr[2*output_stride]+= DESCALE(tmp2 + tmp5, 3);
+ outptr[3*output_stride]+= DESCALE(tmp3 - tmp4, 3);
+ outptr[4*output_stride]+= DESCALE(tmp3 + tmp4, 3);
+ outptr[5*output_stride]+= DESCALE(tmp2 - tmp5, 3);
+ outptr[6*output_stride]+= DESCALE(tmp1 - tmp6, 3); //no += ?
+ outptr[7*output_stride]+= DESCALE(tmp0 - tmp7, 3); //no += ?
+ outptr++;
+
+ wsptr += DCTSIZE; // advance pointer to next row
+ }
+}
+
+#else /* HAVE_MMX */
+
+static void row_idct_mmx (DCTELEM* workspace,
+ int16_t* output_adr, int output_stride, int cnt)
+{
+ uint64_t __attribute__((aligned(8))) temps[4];
+ __asm__ volatile(
+ "lea (%%"REG_a",%%"REG_a",2), %%"REG_d" \n\t"
+ "1: \n\t"
+ "movq "DCTSIZE_S"*0*2(%%"REG_S"), %%mm0 \n\t"
+ //
+
+ "movq "DCTSIZE_S"*1*2(%%"REG_S"), %%mm1 \n\t"
+ "movq %%mm0, %%mm4 \n\t"
+
+ "movq "DCTSIZE_S"*2*2(%%"REG_S"), %%mm2 \n\t"
+ "punpcklwd %%mm1, %%mm0 \n\t"
+
+ "movq "DCTSIZE_S"*3*2(%%"REG_S"), %%mm3 \n\t"
+ "punpckhwd %%mm1, %%mm4 \n\t"
+
+ //transpose 4x4
+ "movq %%mm2, %%mm7 \n\t"
+ "punpcklwd %%mm3, %%mm2 \n\t"
+
+ "movq %%mm0, %%mm6 \n\t"
+ "punpckldq %%mm2, %%mm0 \n\t" //0
+
+ "punpckhdq %%mm2, %%mm6 \n\t" //1
+ "movq %%mm0, %%mm5 \n\t"
+
+ "punpckhwd %%mm3, %%mm7 \n\t"
+ "psubw %%mm6, %%mm0 \n\t"
+
+ "pmulhw "MANGLE(MM_FIX_1_414213562_A)", %%mm0 \n\t"
+ "movq %%mm4, %%mm2 \n\t"
+
+ "punpckldq %%mm7, %%mm4 \n\t" //2
+ "paddw %%mm6, %%mm5 \n\t"
+
+ "punpckhdq %%mm7, %%mm2 \n\t" //3
+ "movq %%mm4, %%mm1 \n\t"
+
+ "psllw $2, %%mm0 \n\t"
+ "paddw %%mm2, %%mm4 \n\t" //t10
+
+ "movq "DCTSIZE_S"*0*2+"DCTSIZE_S"(%%"REG_S"), %%mm3 \n\t"
+ "psubw %%mm2, %%mm1 \n\t" //t11
+
+ "movq "DCTSIZE_S"*1*2+"DCTSIZE_S"(%%"REG_S"), %%mm2 \n\t"
+ "psubw %%mm5, %%mm0 \n\t"
+
+ "movq %%mm4, %%mm6 \n\t"
+ "paddw %%mm5, %%mm4 \n\t" //t0
+
+ "psubw %%mm5, %%mm6 \n\t" //t3
+ "movq %%mm1, %%mm7 \n\t"
+
+ "movq "DCTSIZE_S"*2*2+"DCTSIZE_S"(%%"REG_S"), %%mm5 \n\t"
+ "paddw %%mm0, %%mm1 \n\t" //t1
+
+ "movq %%mm4, 0*8+%3 \n\t" //t0
+ "movq %%mm3, %%mm4 \n\t"
+
+ "movq %%mm6, 1*8+%3 \n\t" //t3
+ "punpcklwd %%mm2, %%mm3 \n\t"
+
+ //transpose 4x4
+ "movq "DCTSIZE_S"*3*2+"DCTSIZE_S"(%%"REG_S"), %%mm6 \n\t"
+ "punpckhwd %%mm2, %%mm4 \n\t"
+
+ "movq %%mm5, %%mm2 \n\t"
+ "punpcklwd %%mm6, %%mm5 \n\t"
+
+ "psubw %%mm0, %%mm7 \n\t" //t2
+ "punpckhwd %%mm6, %%mm2 \n\t"
+
+ "movq %%mm3, %%mm0 \n\t"
+ "punpckldq %%mm5, %%mm3 \n\t" //4
+
+ "punpckhdq %%mm5, %%mm0 \n\t" //5
+ "movq %%mm4, %%mm5 \n\t"
+
+ //
+ "movq %%mm3, %%mm6 \n\t"
+ "punpckldq %%mm2, %%mm4 \n\t" //6
+
+ "psubw %%mm0, %%mm3 \n\t" //z10
+ "punpckhdq %%mm2, %%mm5 \n\t" //7
+
+ "paddw %%mm0, %%mm6 \n\t" //z13
+ "movq %%mm4, %%mm2 \n\t"
+
+ "movq %%mm3, %%mm0 \n\t"
+ "psubw %%mm5, %%mm4 \n\t" //z12
+
+ "pmulhw "MANGLE(MM_FIX_2_613125930)", %%mm0 \n\t" //-
+ "paddw %%mm4, %%mm3 \n\t"
+
+ "pmulhw "MANGLE(MM_FIX_1_847759065)", %%mm3 \n\t" //z5
+ "paddw %%mm5, %%mm2 \n\t" //z11 >
+
+ "pmulhw "MANGLE(MM_FIX_1_082392200)", %%mm4 \n\t"
+ "movq %%mm2, %%mm5 \n\t"
+
+ "psubw %%mm6, %%mm2 \n\t"
+ "paddw %%mm6, %%mm5 \n\t" //t7
+
+ "pmulhw "MANGLE(MM_FIX_1_414213562)", %%mm2 \n\t" //t11
+ "paddw %%mm3, %%mm0 \n\t" //t12
+
+ "psllw $3, %%mm0 \n\t"
+ "psubw %%mm3, %%mm4 \n\t" //t10
+
+ "movq 0*8+%3, %%mm6 \n\t"
+ "movq %%mm1, %%mm3 \n\t"
+
+ "psllw $3, %%mm4 \n\t"
+ "psubw %%mm5, %%mm0 \n\t" //t6
+
+ "psllw $3, %%mm2 \n\t"
+ "paddw %%mm0, %%mm1 \n\t" //d1
+
+ "psubw %%mm0, %%mm2 \n\t" //t5
+ "psubw %%mm0, %%mm3 \n\t" //d6
+
+ "paddw %%mm2, %%mm4 \n\t" //t4
+ "movq %%mm7, %%mm0 \n\t"
+
+ "paddw %%mm2, %%mm7 \n\t" //d2
+ "psubw %%mm2, %%mm0 \n\t" //d5
+
+ "movq "MANGLE(MM_DESCALE_RND)", %%mm2 \n\t" //4
+ "psubw %%mm5, %%mm6 \n\t" //d7
+
+ "paddw 0*8+%3, %%mm5 \n\t" //d0
+ "paddw %%mm2, %%mm1 \n\t"
+
+ "paddw %%mm2, %%mm5 \n\t"
+ "psraw $3, %%mm1 \n\t"
+
+ "paddw %%mm2, %%mm7 \n\t"
+ "psraw $3, %%mm5 \n\t"
+
+ "paddw (%%"REG_D"), %%mm5 \n\t"
+ "psraw $3, %%mm7 \n\t"
+
+ "paddw (%%"REG_D",%%"REG_a",), %%mm1 \n\t"
+ "paddw %%mm2, %%mm0 \n\t"
+
+ "paddw (%%"REG_D",%%"REG_a",2), %%mm7 \n\t"
+ "paddw %%mm2, %%mm3 \n\t"
+
+ "movq %%mm5, (%%"REG_D") \n\t"
+ "paddw %%mm2, %%mm6 \n\t"
+
+ "movq %%mm1, (%%"REG_D",%%"REG_a",) \n\t"
+ "psraw $3, %%mm0 \n\t"
+
+ "movq %%mm7, (%%"REG_D",%%"REG_a",2) \n\t"
+ "add %%"REG_d", %%"REG_D" \n\t" //3*ls
+
+ "movq 1*8+%3, %%mm5 \n\t" //t3
+ "psraw $3, %%mm3 \n\t"
+
+ "paddw (%%"REG_D",%%"REG_a",2), %%mm0 \n\t"
+ "psubw %%mm4, %%mm5 \n\t" //d3
+
+ "paddw (%%"REG_D",%%"REG_d",), %%mm3 \n\t"
+ "psraw $3, %%mm6 \n\t"
+
+ "paddw 1*8+%3, %%mm4 \n\t" //d4
+ "paddw %%mm2, %%mm5 \n\t"
+
+ "paddw (%%"REG_D",%%"REG_a",4), %%mm6 \n\t"
+ "paddw %%mm2, %%mm4 \n\t"
+
+ "movq %%mm0, (%%"REG_D",%%"REG_a",2) \n\t"
+ "psraw $3, %%mm5 \n\t"
+
+ "paddw (%%"REG_D"), %%mm5 \n\t"
+ "psraw $3, %%mm4 \n\t"
+
+ "paddw (%%"REG_D",%%"REG_a",), %%mm4 \n\t"
+ "add $"DCTSIZE_S"*2*4, %%"REG_S" \n\t" //4 rows
+
+ "movq %%mm3, (%%"REG_D",%%"REG_d",) \n\t"
+ "movq %%mm6, (%%"REG_D",%%"REG_a",4) \n\t"
+ "movq %%mm5, (%%"REG_D") \n\t"
+ "movq %%mm4, (%%"REG_D",%%"REG_a",) \n\t"
+
+ "sub %%"REG_d", %%"REG_D" \n\t"
+ "add $8, %%"REG_D" \n\t"
+ "dec %%"REG_c" \n\t"
+ "jnz 1b \n\t"
+
+ : "+S"(workspace), "+D"(output_adr), "+c"(cnt), "=o"(temps)
+ : "a"(output_stride*sizeof(short))
+ : "%"REG_d
+ );
+}
+
+#endif // HAVE_MMX
+
+#if !HAVE_MMX
+
+static void row_fdct_c(DCTELEM *data, const uint8_t *pixels, int line_size, int cnt)
+{
+ int_simd16_t tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
+ int_simd16_t tmp10, tmp11, tmp12, tmp13;
+ int_simd16_t z1, z2, z3, z4, z5, z11, z13;
+ DCTELEM *dataptr;
+
+ cnt*=4;
+ // Pass 1: process rows.
+
+ dataptr = data;
+ for (; cnt > 0; cnt--) {
+ tmp0 = pixels[line_size*0] + pixels[line_size*7];
+ tmp7 = pixels[line_size*0] - pixels[line_size*7];
+ tmp1 = pixels[line_size*1] + pixels[line_size*6];
+ tmp6 = pixels[line_size*1] - pixels[line_size*6];
+ tmp2 = pixels[line_size*2] + pixels[line_size*5];
+ tmp5 = pixels[line_size*2] - pixels[line_size*5];
+ tmp3 = pixels[line_size*3] + pixels[line_size*4];
+ tmp4 = pixels[line_size*3] - pixels[line_size*4];
+
+ // Even part
+
+ tmp10 = tmp0 + tmp3;
+ tmp13 = tmp0 - tmp3;
+ tmp11 = tmp1 + tmp2;
+ tmp12 = tmp1 - tmp2;
+ //Even columns are written first, this leads to different order of columns
+ //in column_fidct(), but they are processed independently, so all ok.
+ //Later in the row_idct() columns readed at the same order.
+ dataptr[2] = tmp10 + tmp11;
+ dataptr[3] = tmp10 - tmp11;
+
+ z1 = MULTIPLY16H((tmp12 + tmp13)<<2, FIX_0_707106781);
+ dataptr[0] = tmp13 + z1;
+ dataptr[1] = tmp13 - z1;
+
+ // Odd part
+
+ tmp10 = (tmp4 + tmp5) <<2;
+ tmp11 = (tmp5 + tmp6) <<2;
+ tmp12 = (tmp6 + tmp7) <<2;
+
+ z5 = MULTIPLY16H(tmp10 - tmp12, FIX_0_382683433);
+ z2 = MULTIPLY16H(tmp10, FIX_0_541196100) + z5;
+ z4 = MULTIPLY16H(tmp12, FIX_1_306562965) + z5;
+ z3 = MULTIPLY16H(tmp11, FIX_0_707106781);
+
+ z11 = tmp7 + z3;
+ z13 = tmp7 - z3;
+
+ dataptr[4] = z13 + z2;
+ dataptr[5] = z13 - z2;
+ dataptr[6] = z11 + z4;
+ dataptr[7] = z11 - z4;
+
+ pixels++; // advance pointer to next column
+ dataptr += DCTSIZE;
+ }
+}
+
+#else /* HAVE_MMX */
+
+static void row_fdct_mmx(DCTELEM *data, const uint8_t *pixels, int line_size, int cnt)
+{
+ uint64_t __attribute__((aligned(8))) temps[4];
+ __asm__ volatile(
+ "lea (%%"REG_a",%%"REG_a",2), %%"REG_d" \n\t"
+ "6: \n\t"
+ "movd (%%"REG_S"), %%mm0 \n\t"
+ "pxor %%mm7, %%mm7 \n\t"
+
+ "movd (%%"REG_S",%%"REG_a",), %%mm1 \n\t"
+ "punpcklbw %%mm7, %%mm0 \n\t"
+
+ "movd (%%"REG_S",%%"REG_a",2), %%mm2 \n\t"
+ "punpcklbw %%mm7, %%mm1 \n\t"
+
+ "punpcklbw %%mm7, %%mm2 \n\t"
+ "add %%"REG_d", %%"REG_S" \n\t"
+
+ "movq %%mm0, %%mm5 \n\t"
+ //
+
+ "movd (%%"REG_S",%%"REG_a",4), %%mm3 \n\t" //7 ;prefetch!
+ "movq %%mm1, %%mm6 \n\t"
+
+ "movd (%%"REG_S",%%"REG_d",), %%mm4 \n\t" //6
+ "punpcklbw %%mm7, %%mm3 \n\t"
+
+ "psubw %%mm3, %%mm5 \n\t"
+ "punpcklbw %%mm7, %%mm4 \n\t"
+
+ "paddw %%mm3, %%mm0 \n\t"
+ "psubw %%mm4, %%mm6 \n\t"
+
+ "movd (%%"REG_S",%%"REG_a",2), %%mm3 \n\t" //5
+ "paddw %%mm4, %%mm1 \n\t"
+
+ "movq %%mm5, 0*8+%3 \n\t" //t7
+ "punpcklbw %%mm7, %%mm3 \n\t"
+
+ "movq %%mm6, 1*8+%3 \n\t" //t6
+ "movq %%mm2, %%mm4 \n\t"
+
+ "movd (%%"REG_S"), %%mm5 \n\t" //3
+ "paddw %%mm3, %%mm2 \n\t"
+
+ "movd (%%"REG_S",%%"REG_a",), %%mm6 \n\t" //4
+ "punpcklbw %%mm7, %%mm5 \n\t"
+
+ "psubw %%mm3, %%mm4 \n\t"
+ "punpcklbw %%mm7, %%mm6 \n\t"
+
+ "movq %%mm5, %%mm3 \n\t"
+ "paddw %%mm6, %%mm5 \n\t" //t3
+
+ "psubw %%mm6, %%mm3 \n\t" //t4 ; t0 t1 t2 t4 t5 t3 - -
+ "movq %%mm0, %%mm6 \n\t"
+
+ "movq %%mm1, %%mm7 \n\t"
+ "psubw %%mm5, %%mm0 \n\t" //t13
+
+ "psubw %%mm2, %%mm1 \n\t"
+ "paddw %%mm2, %%mm7 \n\t" //t11
+
+ "paddw %%mm0, %%mm1 \n\t"
+ "movq %%mm7, %%mm2 \n\t"
+
+ "psllw $2, %%mm1 \n\t"
+ "paddw %%mm5, %%mm6 \n\t" //t10
+
+ "pmulhw "MANGLE(MM_FIX_0_707106781)", %%mm1 \n\t"
+ "paddw %%mm6, %%mm7 \n\t" //d2
+
+ "psubw %%mm2, %%mm6 \n\t" //d3
+ "movq %%mm0, %%mm5 \n\t"
+
+ //transpose 4x4
+ "movq %%mm7, %%mm2 \n\t"
+ "punpcklwd %%mm6, %%mm7 \n\t"
+
+ "paddw %%mm1, %%mm0 \n\t" //d0
+ "punpckhwd %%mm6, %%mm2 \n\t"
+
+ "psubw %%mm1, %%mm5 \n\t" //d1
+ "movq %%mm0, %%mm6 \n\t"
+
+ "movq 1*8+%3, %%mm1 \n\t"
+ "punpcklwd %%mm5, %%mm0 \n\t"
+
+ "punpckhwd %%mm5, %%mm6 \n\t"
+ "movq %%mm0, %%mm5 \n\t"
+
+ "punpckldq %%mm7, %%mm0 \n\t" //0
+ "paddw %%mm4, %%mm3 \n\t"
+
+ "punpckhdq %%mm7, %%mm5 \n\t" //1
+ "movq %%mm6, %%mm7 \n\t"
+
+ "movq %%mm0, "DCTSIZE_S"*0*2(%%"REG_D") \n\t"
+ "punpckldq %%mm2, %%mm6 \n\t" //2
+
+ "movq %%mm5, "DCTSIZE_S"*1*2(%%"REG_D") \n\t"
+ "punpckhdq %%mm2, %%mm7 \n\t" //3
+
+ "movq %%mm6, "DCTSIZE_S"*2*2(%%"REG_D") \n\t"
+ "paddw %%mm1, %%mm4 \n\t"
+
+ "movq %%mm7, "DCTSIZE_S"*3*2(%%"REG_D") \n\t"
+ "psllw $2, %%mm3 \n\t" //t10
+
+ "movq 0*8+%3, %%mm2 \n\t"
+ "psllw $2, %%mm4 \n\t" //t11
+
+ "pmulhw "MANGLE(MM_FIX_0_707106781)", %%mm4 \n\t" //z3
+ "paddw %%mm2, %%mm1 \n\t"
+
+ "psllw $2, %%mm1 \n\t" //t12
+ "movq %%mm3, %%mm0 \n\t"
+
+ "pmulhw "MANGLE(MM_FIX_0_541196100)", %%mm0 \n\t"
+ "psubw %%mm1, %%mm3 \n\t"
+
+ "pmulhw "MANGLE(MM_FIX_0_382683433)", %%mm3 \n\t" //z5
+ "movq %%mm2, %%mm5 \n\t"
+
+ "pmulhw "MANGLE(MM_FIX_1_306562965)", %%mm1 \n\t"
+ "psubw %%mm4, %%mm2 \n\t" //z13
+
+ "paddw %%mm4, %%mm5 \n\t" //z11
+ "movq %%mm2, %%mm6 \n\t"
+
+ "paddw %%mm3, %%mm0 \n\t" //z2
+ "movq %%mm5, %%mm7 \n\t"
+
+ "paddw %%mm0, %%mm2 \n\t" //d4
+ "psubw %%mm0, %%mm6 \n\t" //d5
+
+ "movq %%mm2, %%mm4 \n\t"
+ "paddw %%mm3, %%mm1 \n\t" //z4
+
+ //transpose 4x4
+ "punpcklwd %%mm6, %%mm2 \n\t"
+ "paddw %%mm1, %%mm5 \n\t" //d6
+
+ "punpckhwd %%mm6, %%mm4 \n\t"
+ "psubw %%mm1, %%mm7 \n\t" //d7
+
+ "movq %%mm5, %%mm6 \n\t"
+ "punpcklwd %%mm7, %%mm5 \n\t"
+
+ "punpckhwd %%mm7, %%mm6 \n\t"
+ "movq %%mm2, %%mm7 \n\t"
+
+ "punpckldq %%mm5, %%mm2 \n\t" //4
+ "sub %%"REG_d", %%"REG_S" \n\t"
+
+ "punpckhdq %%mm5, %%mm7 \n\t" //5
+ "movq %%mm4, %%mm5 \n\t"
+
+ "movq %%mm2, "DCTSIZE_S"*0*2+"DCTSIZE_S"(%%"REG_D") \n\t"
+ "punpckldq %%mm6, %%mm4 \n\t" //6
+
+ "movq %%mm7, "DCTSIZE_S"*1*2+"DCTSIZE_S"(%%"REG_D") \n\t"
+ "punpckhdq %%mm6, %%mm5 \n\t" //7
+
+ "movq %%mm4, "DCTSIZE_S"*2*2+"DCTSIZE_S"(%%"REG_D") \n\t"
+ "add $4, %%"REG_S" \n\t"
+
+ "movq %%mm5, "DCTSIZE_S"*3*2+"DCTSIZE_S"(%%"REG_D") \n\t"
+ "add $"DCTSIZE_S"*2*4, %%"REG_D" \n\t" //4 rows
+ "dec %%"REG_c" \n\t"
+ "jnz 6b \n\t"
+
+ : "+S"(pixels), "+D"(data), "+c"(cnt), "=o"(temps)
+ : "a"(line_size)
+ : "%"REG_d);
+}
+
+#endif // HAVE_MMX
diff --git a/libavfilter/libmpcodecs/vf_geq.c b/libavfilter/libmpcodecs/vf_geq.c
new file mode 100644
index 0000000000..22f29387d5
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_geq.c
@@ -0,0 +1,196 @@
+/*
+ * Copyright (C) 2006 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#include <inttypes.h>
+
+#include "config.h"
+
+#include "mp_msg.h"
+
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+
+#include "libavcodec/avcodec.h"
+#include "libavutil/eval.h"
+
+struct vf_priv_s {
+ AVExpr * e[3];
+ int framenum;
+ mp_image_t *mpi;
+};
+
+static int config(struct vf_instance *vf,
+ int width, int height, int d_width, int d_height,
+ unsigned int flags, unsigned int outfmt){
+ return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
+}
+
+static inline double getpix(struct vf_instance *vf, double x, double y, int plane){
+ int xi, yi;
+ mp_image_t *mpi= vf->priv->mpi;
+ int stride= mpi->stride[plane];
+ uint8_t *src= mpi->planes[plane];
+ xi=x= FFMIN(FFMAX(x, 0), (mpi->w >> (plane ? mpi->chroma_x_shift : 0))-1);
+ yi=y= FFMIN(FFMAX(y, 0), (mpi->h >> (plane ? mpi->chroma_y_shift : 0))-1);
+
+ x-=xi;
+ y-=yi;
+
+ return
+ (1-y)*((1-x)*src[xi + yi * stride] + x*src[xi + 1 + yi * stride])
+ + y *((1-x)*src[xi + (yi+1) * stride] + x*src[xi + 1 + (yi+1) * stride]);
+}
+
+//FIXME cubic interpolate
+//FIXME keep the last few frames
+static double lum(void *vf, double x, double y){
+ return getpix(vf, x, y, 0);
+}
+
+static double cb(void *vf, double x, double y){
+ return getpix(vf, x, y, 1);
+}
+
+static double cr(void *vf, double x, double y){
+ return getpix(vf, x, y, 2);
+}
+
+static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
+ mp_image_t *dmpi;
+ int x,y, plane;
+
+ if(!(mpi->flags&MP_IMGFLAG_DIRECT)){
+ // no DR, so get a new image! hope we'll get DR buffer:
+ vf->dmpi=vf_get_image(vf->next,mpi->imgfmt, MP_IMGTYPE_TEMP,
+ MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE,
+ mpi->w,mpi->h);
+ }
+
+ dmpi= vf->dmpi;
+ vf->priv->mpi= mpi;
+
+ vf_clone_mpi_attributes(dmpi, mpi);
+
+ for(plane=0; plane<3; plane++){
+ int w= mpi->w >> (plane ? mpi->chroma_x_shift : 0);
+ int h= mpi->h >> (plane ? mpi->chroma_y_shift : 0);
+ uint8_t *dst = dmpi->planes[plane];
+ int dst_stride= dmpi->stride[plane];
+ double const_values[]={
+ M_PI,
+ M_E,
+ 0,
+ 0,
+ w,
+ h,
+ vf->priv->framenum,
+ w/(double)mpi->w,
+ h/(double)mpi->h,
+ 0
+ };
+ if (!vf->priv->e[plane]) continue;
+ for(y=0; y<h; y++){
+ const_values[3]=y;
+ for(x=0; x<w; x++){
+ const_values[2]=x;
+ dst[x + y * dst_stride] = av_expr_eval(vf->priv->e[plane],
+ const_values, vf);
+ }
+ }
+ }
+
+ vf->priv->framenum++;
+
+ return vf_next_put_image(vf,dmpi, pts);
+}
+
+static void uninit(struct vf_instance *vf){
+ av_free(vf->priv);
+ vf->priv=NULL;
+}
+
+//===========================================================================//
+static int vf_open(vf_instance_t *vf, char *args){
+ char eq[3][2000] = { { 0 }, { 0 }, { 0 } };
+ int plane, res;
+
+ vf->config=config;
+ vf->put_image=put_image;
+// vf->get_image=get_image;
+ vf->uninit=uninit;
+ vf->priv=av_malloc(sizeof(struct vf_priv_s));
+ memset(vf->priv, 0, sizeof(struct vf_priv_s));
+
+ if (args) sscanf(args, "%1999[^:]:%1999[^:]:%1999[^:]", eq[0], eq[1], eq[2]);
+
+ if (!eq[1][0]) strncpy(eq[1], eq[0], sizeof(eq[0])-1);
+ if (!eq[2][0]) strncpy(eq[2], eq[1], sizeof(eq[0])-1);
+
+ for(plane=0; plane<3; plane++){
+ static const char *const_names[]={
+ "PI",
+ "E",
+ "X",
+ "Y",
+ "W",
+ "H",
+ "N",
+ "SW",
+ "SH",
+ NULL
+ };
+ static const char *func2_names[]={
+ "lum",
+ "cb",
+ "cr",
+ "p",
+ NULL
+ };
+ double (*func2[])(void *, double, double)={
+ lum,
+ cb,
+ cr,
+ plane==0 ? lum : (plane==1 ? cb : cr),
+ NULL
+ };
+ res = av_expr_parse(&vf->priv->e[plane], eq[plane], const_names, NULL, NULL, func2_names, func2, 0, NULL);
+
+ if (res < 0) {
+ mp_msg(MSGT_VFILTER, MSGL_ERR, "geq: error loading equation `%s'\n", eq[plane]);
+ return 0;
+ }
+ }
+
+ return 1;
+}
+
+const vf_info_t vf_info_geq = {
+ "generic equation filter",
+ "geq",
+ "Michael Niedermayer",
+ "",
+ vf_open,
+ NULL
+};
diff --git a/libavfilter/libmpcodecs/vf_harddup.c b/libavfilter/libmpcodecs/vf_harddup.c
new file mode 100644
index 0000000000..5b6c2ff010
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_harddup.c
@@ -0,0 +1,92 @@
+/*
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "config.h"
+#include "mp_msg.h"
+
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+
+struct vf_priv_s {
+ mp_image_t *last_mpi;
+};
+
+static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
+{
+ mp_image_t *dmpi;
+
+ vf->priv->last_mpi = mpi;
+
+ dmpi = vf_get_image(vf->next, mpi->imgfmt,
+ MP_IMGTYPE_EXPORT, 0, mpi->width, mpi->height);
+
+ dmpi->planes[0] = mpi->planes[0];
+ dmpi->stride[0] = mpi->stride[0];
+ if (dmpi->flags&MP_IMGFLAG_PLANAR) {
+ dmpi->planes[1] = mpi->planes[1];
+ dmpi->stride[1] = mpi->stride[1];
+ dmpi->planes[2] = mpi->planes[2];
+ dmpi->stride[2] = mpi->stride[2];
+ }
+
+ return vf_next_put_image(vf, dmpi, pts);
+}
+
+static int control(struct vf_instance *vf, int request, void* data)
+{
+ switch (request) {
+ case VFCTRL_DUPLICATE_FRAME:
+ if (!vf->priv->last_mpi) break;
+ // This is a huge hack. We assume nothing
+ // has been called earlier in the filter chain
+ // since the last put_image. This is reasonable
+ // because we're handling a duplicate frame!
+ if (put_image(vf, vf->priv->last_mpi, MP_NOPTS_VALUE))
+ return CONTROL_TRUE;
+ break;
+ }
+ return vf_next_control(vf, request, data);
+}
+
+static void uninit(struct vf_instance *vf)
+{
+ free(vf->priv);
+}
+
+static int vf_open(vf_instance_t *vf, char *args)
+{
+ vf->put_image = put_image;
+ vf->control = control;
+ vf->uninit = uninit;
+ vf->priv = calloc(1, sizeof(struct vf_priv_s));
+ return 1;
+}
+
+const vf_info_t vf_info_harddup = {
+ "resubmit duplicate frames for encoding",
+ "harddup",
+ "Rich Felker",
+ "",
+ vf_open,
+ NULL
+};
diff --git a/libavfilter/libmpcodecs/vf_hqdn3d.c b/libavfilter/libmpcodecs/vf_hqdn3d.c
new file mode 100644
index 0000000000..eba3439d88
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_hqdn3d.c
@@ -0,0 +1,373 @@
+/*
+ * Copyright (C) 2003 Daniel Moreno <comac@comac.darktech.org>
+ *
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+#include <math.h>
+
+#include "mp_msg.h"
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+
+#define PARAM1_DEFAULT 4.0
+#define PARAM2_DEFAULT 3.0
+#define PARAM3_DEFAULT 6.0
+
+//===========================================================================//
+
+struct vf_priv_s {
+ int Coefs[4][512*16];
+ unsigned int *Line;
+ unsigned short *Frame[3];
+};
+
+
+/***************************************************************************/
+
+static void uninit(struct vf_instance *vf)
+{
+ free(vf->priv->Line);
+ free(vf->priv->Frame[0]);
+ free(vf->priv->Frame[1]);
+ free(vf->priv->Frame[2]);
+
+ vf->priv->Line = NULL;
+ vf->priv->Frame[0] = NULL;
+ vf->priv->Frame[1] = NULL;
+ vf->priv->Frame[2] = NULL;
+}
+
+static int config(struct vf_instance *vf,
+ int width, int height, int d_width, int d_height,
+ unsigned int flags, unsigned int outfmt){
+
+ uninit(vf);
+ vf->priv->Line = malloc(width*sizeof(int));
+
+ return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
+}
+
+static inline unsigned int LowPassMul(unsigned int PrevMul, unsigned int CurrMul, int* Coef){
+// int dMul= (PrevMul&0xFFFFFF)-(CurrMul&0xFFFFFF);
+ int dMul= PrevMul-CurrMul;
+ unsigned int d=((dMul+0x10007FF)>>12);
+ return CurrMul + Coef[d];
+}
+
+static void deNoiseTemporal(
+ unsigned char *Frame, // mpi->planes[x]
+ unsigned char *FrameDest, // dmpi->planes[x]
+ unsigned short *FrameAnt,
+ int W, int H, int sStride, int dStride,
+ int *Temporal)
+{
+ long X, Y;
+ unsigned int PixelDst;
+
+ for (Y = 0; Y < H; Y++){
+ for (X = 0; X < W; X++){
+ PixelDst = LowPassMul(FrameAnt[X]<<8, Frame[X]<<16, Temporal);
+ FrameAnt[X] = ((PixelDst+0x1000007F)>>8);
+ FrameDest[X]= ((PixelDst+0x10007FFF)>>16);
+ }
+ Frame += sStride;
+ FrameDest += dStride;
+ FrameAnt += W;
+ }
+}
+
+static void deNoiseSpacial(
+ unsigned char *Frame, // mpi->planes[x]
+ unsigned char *FrameDest, // dmpi->planes[x]
+ unsigned int *LineAnt, // vf->priv->Line (width bytes)
+ int W, int H, int sStride, int dStride,
+ int *Horizontal, int *Vertical)
+{
+ long X, Y;
+ long sLineOffs = 0, dLineOffs = 0;
+ unsigned int PixelAnt;
+ unsigned int PixelDst;
+
+ /* First pixel has no left nor top neighbor. */
+ PixelDst = LineAnt[0] = PixelAnt = Frame[0]<<16;
+ FrameDest[0]= ((PixelDst+0x10007FFF)>>16);
+
+ /* First line has no top neighbor, only left. */
+ for (X = 1; X < W; X++){
+ PixelDst = LineAnt[X] = LowPassMul(PixelAnt, Frame[X]<<16, Horizontal);
+ FrameDest[X]= ((PixelDst+0x10007FFF)>>16);
+ }
+
+ for (Y = 1; Y < H; Y++){
+ unsigned int PixelAnt;
+ sLineOffs += sStride, dLineOffs += dStride;
+ /* First pixel on each line doesn't have previous pixel */
+ PixelAnt = Frame[sLineOffs]<<16;
+ PixelDst = LineAnt[0] = LowPassMul(LineAnt[0], PixelAnt, Vertical);
+ FrameDest[dLineOffs]= ((PixelDst+0x10007FFF)>>16);
+
+ for (X = 1; X < W; X++){
+ unsigned int PixelDst;
+ /* The rest are normal */
+ PixelAnt = LowPassMul(PixelAnt, Frame[sLineOffs+X]<<16, Horizontal);
+ PixelDst = LineAnt[X] = LowPassMul(LineAnt[X], PixelAnt, Vertical);
+ FrameDest[dLineOffs+X]= ((PixelDst+0x10007FFF)>>16);
+ }
+ }
+}
+
+static void deNoise(unsigned char *Frame, // mpi->planes[x]
+ unsigned char *FrameDest, // dmpi->planes[x]
+ unsigned int *LineAnt, // vf->priv->Line (width bytes)
+ unsigned short **FrameAntPtr,
+ int W, int H, int sStride, int dStride,
+ int *Horizontal, int *Vertical, int *Temporal)
+{
+ long X, Y;
+ long sLineOffs = 0, dLineOffs = 0;
+ unsigned int PixelAnt;
+ unsigned int PixelDst;
+ unsigned short* FrameAnt=(*FrameAntPtr);
+
+ if(!FrameAnt){
+ (*FrameAntPtr)=FrameAnt=malloc(W*H*sizeof(unsigned short));
+ for (Y = 0; Y < H; Y++){
+ unsigned short* dst=&FrameAnt[Y*W];
+ unsigned char* src=Frame+Y*sStride;
+ for (X = 0; X < W; X++) dst[X]=src[X]<<8;
+ }
+ }
+
+ if(!Horizontal[0] && !Vertical[0]){
+ deNoiseTemporal(Frame, FrameDest, FrameAnt,
+ W, H, sStride, dStride, Temporal);
+ return;
+ }
+ if(!Temporal[0]){
+ deNoiseSpacial(Frame, FrameDest, LineAnt,
+ W, H, sStride, dStride, Horizontal, Vertical);
+ return;
+ }
+
+ /* First pixel has no left nor top neighbor. Only previous frame */
+ LineAnt[0] = PixelAnt = Frame[0]<<16;
+ PixelDst = LowPassMul(FrameAnt[0]<<8, PixelAnt, Temporal);
+ FrameAnt[0] = ((PixelDst+0x1000007F)>>8);
+ FrameDest[0]= ((PixelDst+0x10007FFF)>>16);
+
+ /* First line has no top neighbor. Only left one for each pixel and
+ * last frame */
+ for (X = 1; X < W; X++){
+ LineAnt[X] = PixelAnt = LowPassMul(PixelAnt, Frame[X]<<16, Horizontal);
+ PixelDst = LowPassMul(FrameAnt[X]<<8, PixelAnt, Temporal);
+ FrameAnt[X] = ((PixelDst+0x1000007F)>>8);
+ FrameDest[X]= ((PixelDst+0x10007FFF)>>16);
+ }
+
+ for (Y = 1; Y < H; Y++){
+ unsigned int PixelAnt;
+ unsigned short* LinePrev=&FrameAnt[Y*W];
+ sLineOffs += sStride, dLineOffs += dStride;
+ /* First pixel on each line doesn't have previous pixel */
+ PixelAnt = Frame[sLineOffs]<<16;
+ LineAnt[0] = LowPassMul(LineAnt[0], PixelAnt, Vertical);
+ PixelDst = LowPassMul(LinePrev[0]<<8, LineAnt[0], Temporal);
+ LinePrev[0] = ((PixelDst+0x1000007F)>>8);
+ FrameDest[dLineOffs]= ((PixelDst+0x10007FFF)>>16);
+
+ for (X = 1; X < W; X++){
+ unsigned int PixelDst;
+ /* The rest are normal */
+ PixelAnt = LowPassMul(PixelAnt, Frame[sLineOffs+X]<<16, Horizontal);
+ LineAnt[X] = LowPassMul(LineAnt[X], PixelAnt, Vertical);
+ PixelDst = LowPassMul(LinePrev[X]<<8, LineAnt[X], Temporal);
+ LinePrev[X] = ((PixelDst+0x1000007F)>>8);
+ FrameDest[dLineOffs+X]= ((PixelDst+0x10007FFF)>>16);
+ }
+ }
+}
+
+
+static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
+ int cw= mpi->w >> mpi->chroma_x_shift;
+ int ch= mpi->h >> mpi->chroma_y_shift;
+ int W = mpi->w, H = mpi->h;
+
+ mp_image_t *dmpi=vf_get_image(vf->next,mpi->imgfmt,
+ MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
+ mpi->w,mpi->h);
+
+ if(!dmpi) return 0;
+
+ deNoise(mpi->planes[0], dmpi->planes[0],
+ vf->priv->Line, &vf->priv->Frame[0], W, H,
+ mpi->stride[0], dmpi->stride[0],
+ vf->priv->Coefs[0],
+ vf->priv->Coefs[0],
+ vf->priv->Coefs[1]);
+ deNoise(mpi->planes[1], dmpi->planes[1],
+ vf->priv->Line, &vf->priv->Frame[1], cw, ch,
+ mpi->stride[1], dmpi->stride[1],
+ vf->priv->Coefs[2],
+ vf->priv->Coefs[2],
+ vf->priv->Coefs[3]);
+ deNoise(mpi->planes[2], dmpi->planes[2],
+ vf->priv->Line, &vf->priv->Frame[2], cw, ch,
+ mpi->stride[2], dmpi->stride[2],
+ vf->priv->Coefs[2],
+ vf->priv->Coefs[2],
+ vf->priv->Coefs[3]);
+
+ return vf_next_put_image(vf,dmpi, pts);
+}
+
+//===========================================================================//
+
+static int query_format(struct vf_instance *vf, unsigned int fmt){
+ switch(fmt)
+ {
+ case IMGFMT_YV12:
+ case IMGFMT_I420:
+ case IMGFMT_IYUV:
+ case IMGFMT_YVU9:
+ case IMGFMT_444P:
+ case IMGFMT_422P:
+ case IMGFMT_411P:
+ return vf_next_query_format(vf, fmt);
+ }
+ return 0;
+}
+
+
+#define ABS(A) ( (A) > 0 ? (A) : -(A) )
+
+static void PrecalcCoefs(int *Ct, double Dist25)
+{
+ int i;
+ double Gamma, Simil, C;
+
+ Gamma = log(0.25) / log(1.0 - Dist25/255.0 - 0.00001);
+
+ for (i = -255*16; i <= 255*16; i++)
+ {
+ Simil = 1.0 - ABS(i) / (16*255.0);
+ C = pow(Simil, Gamma) * 65536.0 * (double)i / 16.0;
+ Ct[16*256+i] = (C<0) ? (C-0.5) : (C+0.5);
+ }
+
+ Ct[0] = (Dist25 != 0);
+}
+
+
+static int vf_open(vf_instance_t *vf, char *args){
+ double LumSpac, LumTmp, ChromSpac, ChromTmp;
+ double Param1, Param2, Param3, Param4;
+
+ vf->config=config;
+ vf->put_image=put_image;
+ vf->query_format=query_format;
+ vf->uninit=uninit;
+ vf->priv=malloc(sizeof(struct vf_priv_s));
+ memset(vf->priv, 0, sizeof(struct vf_priv_s));
+
+ if (args)
+ {
+ switch(sscanf(args, "%lf:%lf:%lf:%lf",
+ &Param1, &Param2, &Param3, &Param4
+ ))
+ {
+ case 0:
+ LumSpac = PARAM1_DEFAULT;
+ LumTmp = PARAM3_DEFAULT;
+
+ ChromSpac = PARAM2_DEFAULT;
+ ChromTmp = LumTmp * ChromSpac / LumSpac;
+ break;
+
+ case 1:
+ LumSpac = Param1;
+ LumTmp = PARAM3_DEFAULT * Param1 / PARAM1_DEFAULT;
+
+ ChromSpac = PARAM2_DEFAULT * Param1 / PARAM1_DEFAULT;
+ ChromTmp = LumTmp * ChromSpac / LumSpac;
+ break;
+
+ case 2:
+ LumSpac = Param1;
+ LumTmp = PARAM3_DEFAULT * Param1 / PARAM1_DEFAULT;
+
+ ChromSpac = Param2;
+ ChromTmp = LumTmp * ChromSpac / LumSpac;
+ break;
+
+ case 3:
+ LumSpac = Param1;
+ LumTmp = Param3;
+
+ ChromSpac = Param2;
+ ChromTmp = LumTmp * ChromSpac / LumSpac;
+ break;
+
+ case 4:
+ LumSpac = Param1;
+ LumTmp = Param3;
+
+ ChromSpac = Param2;
+ ChromTmp = Param4;
+ break;
+
+ default:
+ LumSpac = PARAM1_DEFAULT;
+ LumTmp = PARAM3_DEFAULT;
+
+ ChromSpac = PARAM2_DEFAULT;
+ ChromTmp = LumTmp * ChromSpac / LumSpac;
+ }
+ }
+ else
+ {
+ LumSpac = PARAM1_DEFAULT;
+ LumTmp = PARAM3_DEFAULT;
+
+ ChromSpac = PARAM2_DEFAULT;
+ ChromTmp = LumTmp * ChromSpac / LumSpac;
+ }
+
+ PrecalcCoefs(vf->priv->Coefs[0], LumSpac);
+ PrecalcCoefs(vf->priv->Coefs[1], LumTmp);
+ PrecalcCoefs(vf->priv->Coefs[2], ChromSpac);
+ PrecalcCoefs(vf->priv->Coefs[3], ChromTmp);
+
+ return 1;
+}
+
+const vf_info_t vf_info_hqdn3d = {
+ "High Quality 3D Denoiser",
+ "hqdn3d",
+ "Daniel Moreno & A'rpi",
+ "",
+ vf_open,
+ NULL
+};
+
+//===========================================================================//
diff --git a/libavfilter/libmpcodecs/vf_hue.c b/libavfilter/libmpcodecs/vf_hue.c
new file mode 100644
index 0000000000..9a8fc8b61b
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_hue.c
@@ -0,0 +1,181 @@
+/*
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+#include <math.h>
+
+#include "config.h"
+#include "mp_msg.h"
+#include "cpudetect.h"
+
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+
+#include "libvo/video_out.h"
+
+struct vf_priv_s {
+ uint8_t *buf[2];
+ float hue;
+ float saturation;
+};
+
+static void process_C(uint8_t *udst, uint8_t *vdst, uint8_t *usrc, uint8_t *vsrc, int dststride, int srcstride,
+ int w, int h, float hue, float sat)
+{
+ int i;
+ const int s= rint(sin(hue) * (1<<16) * sat);
+ const int c= rint(cos(hue) * (1<<16) * sat);
+
+ while (h--) {
+ for (i = 0; i<w; i++)
+ {
+ const int u= usrc[i] - 128;
+ const int v= vsrc[i] - 128;
+ int new_u= (c*u - s*v + (1<<15) + (128<<16))>>16;
+ int new_v= (s*u + c*v + (1<<15) + (128<<16))>>16;
+ if(new_u & 768) new_u= (-new_u)>>31;
+ if(new_v & 768) new_v= (-new_v)>>31;
+ udst[i]= new_u;
+ vdst[i]= new_v;
+ }
+ usrc += srcstride;
+ vsrc += srcstride;
+ udst += dststride;
+ vdst += dststride;
+ }
+}
+
+static void (*process)(uint8_t *udst, uint8_t *vdst, uint8_t *usrc, uint8_t *vsrc, int dststride, int srcstride,
+ int w, int h, float hue, float sat);
+
+/* FIXME: add packed yuv version of process */
+
+static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
+{
+ mp_image_t *dmpi;
+
+ dmpi=vf_get_image(vf->next, mpi->imgfmt,
+ MP_IMGTYPE_EXPORT, 0,
+ mpi->w, mpi->h);
+
+ dmpi->planes[0] = mpi->planes[0];
+ dmpi->stride[0] = mpi->stride[0];
+ dmpi->stride[1] = mpi->stride[1];
+ dmpi->stride[2] = mpi->stride[2];
+
+ if (!vf->priv->buf[0]){
+ vf->priv->buf[0] = malloc(mpi->stride[1]*mpi->h >> mpi->chroma_y_shift);
+ vf->priv->buf[1] = malloc(mpi->stride[2]*mpi->h >> mpi->chroma_y_shift);
+ }
+
+ if (vf->priv->hue == 0 && vf->priv->saturation == 1){
+ dmpi->planes[1] = mpi->planes[1];
+ dmpi->planes[2] = mpi->planes[2];
+ }else {
+ dmpi->planes[1] = vf->priv->buf[0];
+ dmpi->planes[2] = vf->priv->buf[1];
+ process(dmpi->planes[1], dmpi->planes[2],
+ mpi->planes[1], mpi->planes[2],
+ dmpi->stride[1],mpi->stride[1],
+ mpi->w>> mpi->chroma_x_shift, mpi->h>> mpi->chroma_y_shift,
+ vf->priv->hue, vf->priv->saturation);
+ }
+
+ return vf_next_put_image(vf,dmpi, pts);
+}
+
+static int control(struct vf_instance *vf, int request, void* data)
+{
+ vf_equalizer_t *eq;
+
+ switch (request) {
+ case VFCTRL_SET_EQUALIZER:
+ eq = data;
+ if (!strcmp(eq->item,"hue")) {
+ vf->priv->hue = eq->value * M_PI / 100;
+ return CONTROL_TRUE;
+ } else if (!strcmp(eq->item,"saturation")) {
+ vf->priv->saturation = (eq->value + 100)/100.0;
+ return CONTROL_TRUE;
+ }
+ break;
+ case VFCTRL_GET_EQUALIZER:
+ eq = data;
+ if (!strcmp(eq->item,"hue")) {
+ eq->value = rint(vf->priv->hue *100 / M_PI);
+ return CONTROL_TRUE;
+ }else if (!strcmp(eq->item,"saturation")) {
+ eq->value = rint(vf->priv->saturation*100 - 100);
+ return CONTROL_TRUE;
+ }
+ break;
+ }
+ return vf_next_control(vf, request, data);
+}
+
+static int query_format(struct vf_instance *vf, unsigned int fmt)
+{
+ switch (fmt) {
+ case IMGFMT_YVU9:
+ case IMGFMT_IF09:
+ case IMGFMT_YV12:
+ case IMGFMT_I420:
+ case IMGFMT_IYUV:
+ case IMGFMT_CLPL:
+ case IMGFMT_444P:
+ case IMGFMT_422P:
+ case IMGFMT_411P:
+ return vf_next_query_format(vf, fmt);
+ }
+ return 0;
+}
+
+static void uninit(struct vf_instance *vf)
+{
+ free(vf->priv->buf[0]);
+ free(vf->priv->buf[1]);
+ free(vf->priv);
+}
+
+static int vf_open(vf_instance_t *vf, char *args)
+{
+ vf->control=control;
+ vf->query_format=query_format;
+ vf->put_image=put_image;
+ vf->uninit=uninit;
+
+ vf->priv = malloc(sizeof(struct vf_priv_s));
+ memset(vf->priv, 0, sizeof(struct vf_priv_s));
+ sscanf(args, "%f:%f", &vf->priv->hue, &vf->priv->saturation);
+ vf->priv->hue *= M_PI / 180.0;
+
+ process = process_C;
+ return 1;
+}
+
+const vf_info_t vf_info_hue = {
+ "hue changer",
+ "hue",
+ "Michael Niedermayer",
+ "",
+ vf_open,
+};
diff --git a/libavfilter/libmpcodecs/vf_il.c b/libavfilter/libmpcodecs/vf_il.c
new file mode 100644
index 0000000000..210e30d3f6
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_il.c
@@ -0,0 +1,148 @@
+/*
+ * Copyright (C) 2002 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+#include <assert.h>
+
+#include "mp_msg.h"
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+#include "libvo/fastmemcpy.h"
+
+
+//===========================================================================//
+
+typedef struct FilterParam{
+ int interleave;
+ int swap;
+}FilterParam;
+
+struct vf_priv_s {
+ FilterParam lumaParam;
+ FilterParam chromaParam;
+};
+
+/***************************************************************************/
+
+static void interleave(uint8_t *dst, uint8_t *src, int w, int h, int dstStride, int srcStride, int interleave, int swap){
+ const int a= swap;
+ const int b= 1-a;
+ const int m= h>>1;
+ int y;
+
+ switch(interleave){
+ case -1:
+ for(y=0; y < m; y++){
+ fast_memcpy(dst + dstStride* y , src + srcStride*(y*2 + a), w);
+ fast_memcpy(dst + dstStride*(y + m), src + srcStride*(y*2 + b), w);
+ }
+ break;
+ case 0:
+ for(y=0; y < m; y++){
+ fast_memcpy(dst + dstStride* y*2 , src + srcStride*(y*2 + a), w);
+ fast_memcpy(dst + dstStride*(y*2+1), src + srcStride*(y*2 + b), w);
+ }
+ break;
+ case 1:
+ for(y=0; y < m; y++){
+ fast_memcpy(dst + dstStride*(y*2+a), src + srcStride* y , w);
+ fast_memcpy(dst + dstStride*(y*2+b), src + srcStride*(y + m), w);
+ }
+ break;
+ }
+}
+
+static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
+ int w;
+ FilterParam *luma = &vf->priv->lumaParam;
+ FilterParam *chroma= &vf->priv->chromaParam;
+
+ mp_image_t *dmpi=vf_get_image(vf->next,mpi->imgfmt,
+ MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
+ mpi->w,mpi->h);
+
+ if(mpi->flags&MP_IMGFLAG_PLANAR)
+ w= mpi->w;
+ else
+ w= mpi->w * mpi->bpp/8;
+
+ interleave(dmpi->planes[0], mpi->planes[0],
+ w, mpi->h, dmpi->stride[0], mpi->stride[0], luma->interleave, luma->swap);
+
+ if(mpi->flags&MP_IMGFLAG_PLANAR){
+ int cw= mpi->w >> mpi->chroma_x_shift;
+ int ch= mpi->h >> mpi->chroma_y_shift;
+
+ interleave(dmpi->planes[1], mpi->planes[1], cw,ch,
+ dmpi->stride[1], mpi->stride[1], chroma->interleave, luma->swap);
+ interleave(dmpi->planes[2], mpi->planes[2], cw,ch,
+ dmpi->stride[2], mpi->stride[2], chroma->interleave, luma->swap);
+ }
+
+ return vf_next_put_image(vf,dmpi, pts);
+}
+
+//===========================================================================//
+
+static void parse(FilterParam *fp, char* args){
+ char *pos;
+ char *max= strchr(args, ':');
+
+ if(!max) max= args + strlen(args);
+
+ pos= strchr(args, 's');
+ if(pos && pos<max) fp->swap=1;
+ pos= strchr(args, 'i');
+ if(pos && pos<max) fp->interleave=1;
+ pos= strchr(args, 'd');
+ if(pos && pos<max) fp->interleave=-1;
+}
+
+static int vf_open(vf_instance_t *vf, char *args){
+
+ vf->put_image=put_image;
+// vf->get_image=get_image;
+ vf->priv=malloc(sizeof(struct vf_priv_s));
+ memset(vf->priv, 0, sizeof(struct vf_priv_s));
+
+ if(args)
+ {
+ char *arg2= strchr(args,':');
+ if(arg2) parse(&vf->priv->chromaParam, arg2+1);
+ parse(&vf->priv->lumaParam, args);
+ }
+
+ return 1;
+}
+
+const vf_info_t vf_info_il = {
+ "(de)interleave",
+ "il",
+ "Michael Niedermayer",
+ "",
+ vf_open,
+ NULL
+};
+
+//===========================================================================//
diff --git a/libavfilter/libmpcodecs/vf_ilpack.c b/libavfilter/libmpcodecs/vf_ilpack.c
new file mode 100644
index 0000000000..db4a849e1f
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_ilpack.c
@@ -0,0 +1,456 @@
+/*
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+
+#include "config.h"
+#include "mp_msg.h"
+#include "cpudetect.h"
+
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+#include "libavutil/attributes.h"
+
+typedef void (pack_func_t)(unsigned char *dst, unsigned char *y,
+ unsigned char *u, unsigned char *v, int w, int us, int vs);
+
+struct vf_priv_s {
+ int mode;
+ pack_func_t *pack[2];
+};
+
+static void pack_nn_C(unsigned char *dst, unsigned char *y,
+ unsigned char *u, unsigned char *v, int w,
+ int av_unused us, int av_unused vs)
+{
+ int j;
+ for (j = w/2; j; j--) {
+ *dst++ = *y++;
+ *dst++ = *u++;
+ *dst++ = *y++;
+ *dst++ = *v++;
+ }
+}
+
+static void pack_li_0_C(unsigned char *dst, unsigned char *y,
+ unsigned char *u, unsigned char *v, int w, int us, int vs)
+{
+ int j;
+ for (j = w/2; j; j--) {
+ *dst++ = *y++;
+ *dst++ = (u[us+us] + 7*u[0])>>3;
+ *dst++ = *y++;
+ *dst++ = (v[vs+vs] + 7*v[0])>>3;
+ u++; v++;
+ }
+}
+
+static void pack_li_1_C(unsigned char *dst, unsigned char *y,
+ unsigned char *u, unsigned char *v, int w, int us, int vs)
+{
+ int j;
+ for (j = w/2; j; j--) {
+ *dst++ = *y++;
+ *dst++ = (3*u[us+us] + 5*u[0])>>3;
+ *dst++ = *y++;
+ *dst++ = (3*v[vs+vs] + 5*v[0])>>3;
+ u++; v++;
+ }
+}
+
+#if HAVE_MMX
+static void pack_nn_MMX(unsigned char *dst, unsigned char *y,
+ unsigned char *u, unsigned char *v, int w,
+ int av_unused us, int av_unused vs)
+{
+ __asm__ volatile (""
+ ASMALIGN(4)
+ "1: \n\t"
+ "movq (%0), %%mm1 \n\t"
+ "movq (%0), %%mm2 \n\t"
+ "movq (%1), %%mm4 \n\t"
+ "movq (%2), %%mm6 \n\t"
+ "punpcklbw %%mm6, %%mm4 \n\t"
+ "punpcklbw %%mm4, %%mm1 \n\t"
+ "punpckhbw %%mm4, %%mm2 \n\t"
+
+ "add $8, %0 \n\t"
+ "add $4, %1 \n\t"
+ "add $4, %2 \n\t"
+ "movq %%mm1, (%3) \n\t"
+ "movq %%mm2, 8(%3) \n\t"
+ "add $16, %3 \n\t"
+ "decl %4 \n\t"
+ "jnz 1b \n\t"
+ "emms \n\t"
+ :
+ : "r" (y), "r" (u), "r" (v), "r" (dst), "r" (w/8)
+ : "memory"
+ );
+ pack_nn_C(dst, y, u, v, (w&7), 0, 0);
+}
+
+#if HAVE_EBX_AVAILABLE
+static void pack_li_0_MMX(unsigned char *dst, unsigned char *y,
+ unsigned char *u, unsigned char *v, int w, int us, int vs)
+{
+ __asm__ volatile (""
+ "push %%"REG_BP" \n\t"
+#if ARCH_X86_64
+ "mov %6, %%"REG_BP" \n\t"
+#else
+ "movl 4(%%"REG_d"), %%"REG_BP" \n\t"
+ "movl (%%"REG_d"), %%"REG_d" \n\t"
+#endif
+ "pxor %%mm0, %%mm0 \n\t"
+
+ ASMALIGN(4)
+ ".Lli0: \n\t"
+ "movq (%%"REG_S"), %%mm1 \n\t"
+ "movq (%%"REG_S"), %%mm2 \n\t"
+
+ "movq (%%"REG_a",%%"REG_d",2), %%mm4 \n\t"
+ "movq (%%"REG_b",%%"REG_BP",2), %%mm6 \n\t"
+ "punpcklbw %%mm0, %%mm4 \n\t"
+ "punpcklbw %%mm0, %%mm6 \n\t"
+ "movq (%%"REG_a"), %%mm3 \n\t"
+ "movq (%%"REG_b"), %%mm5 \n\t"
+ "punpcklbw %%mm0, %%mm3 \n\t"
+ "punpcklbw %%mm0, %%mm5 \n\t"
+ "paddw %%mm3, %%mm4 \n\t"
+ "paddw %%mm5, %%mm6 \n\t"
+ "paddw %%mm3, %%mm4 \n\t"
+ "paddw %%mm5, %%mm6 \n\t"
+ "paddw %%mm3, %%mm4 \n\t"
+ "paddw %%mm5, %%mm6 \n\t"
+ "paddw %%mm3, %%mm4 \n\t"
+ "paddw %%mm5, %%mm6 \n\t"
+ "paddw %%mm3, %%mm4 \n\t"
+ "paddw %%mm5, %%mm6 \n\t"
+ "paddw %%mm3, %%mm4 \n\t"
+ "paddw %%mm5, %%mm6 \n\t"
+ "paddw %%mm3, %%mm4 \n\t"
+ "paddw %%mm5, %%mm6 \n\t"
+ "psrlw $3, %%mm4 \n\t"
+ "psrlw $3, %%mm6 \n\t"
+ "packuswb %%mm4, %%mm4 \n\t"
+ "packuswb %%mm6, %%mm6 \n\t"
+ "punpcklbw %%mm6, %%mm4 \n\t"
+ "punpcklbw %%mm4, %%mm1 \n\t"
+ "punpckhbw %%mm4, %%mm2 \n\t"
+
+ "movq %%mm1, (%%"REG_D") \n\t"
+ "movq %%mm2, 8(%%"REG_D") \n\t"
+
+ "movq 8(%%"REG_S"), %%mm1 \n\t"
+ "movq 8(%%"REG_S"), %%mm2 \n\t"
+
+ "movq (%%"REG_a",%%"REG_d",2), %%mm4 \n\t"
+ "movq (%%"REG_b",%%"REG_BP",2), %%mm6 \n\t"
+ "punpckhbw %%mm0, %%mm4 \n\t"
+ "punpckhbw %%mm0, %%mm6 \n\t"
+ "movq (%%"REG_a"), %%mm3 \n\t"
+ "movq (%%"REG_b"), %%mm5 \n\t"
+ "punpckhbw %%mm0, %%mm3 \n\t"
+ "punpckhbw %%mm0, %%mm5 \n\t"
+ "paddw %%mm3, %%mm4 \n\t"
+ "paddw %%mm5, %%mm6 \n\t"
+ "paddw %%mm3, %%mm4 \n\t"
+ "paddw %%mm5, %%mm6 \n\t"
+ "paddw %%mm3, %%mm4 \n\t"
+ "paddw %%mm5, %%mm6 \n\t"
+ "paddw %%mm3, %%mm4 \n\t"
+ "paddw %%mm5, %%mm6 \n\t"
+ "paddw %%mm3, %%mm4 \n\t"
+ "paddw %%mm5, %%mm6 \n\t"
+ "paddw %%mm3, %%mm4 \n\t"
+ "paddw %%mm5, %%mm6 \n\t"
+ "paddw %%mm3, %%mm4 \n\t"
+ "paddw %%mm5, %%mm6 \n\t"
+ "psrlw $3, %%mm4 \n\t"
+ "psrlw $3, %%mm6 \n\t"
+ "packuswb %%mm4, %%mm4 \n\t"
+ "packuswb %%mm6, %%mm6 \n\t"
+ "punpcklbw %%mm6, %%mm4 \n\t"
+ "punpcklbw %%mm4, %%mm1 \n\t"
+ "punpckhbw %%mm4, %%mm2 \n\t"
+
+ "add $16, %%"REG_S" \n\t"
+ "add $8, %%"REG_a" \n\t"
+ "add $8, %%"REG_b" \n\t"
+
+ "movq %%mm1, 16(%%"REG_D") \n\t"
+ "movq %%mm2, 24(%%"REG_D") \n\t"
+ "add $32, %%"REG_D" \n\t"
+
+ "decl %%ecx \n\t"
+ "jnz .Lli0 \n\t"
+ "emms \n\t"
+ "pop %%"REG_BP" \n\t"
+ :
+ : "S" (y), "D" (dst), "a" (u), "b" (v), "c" (w/16),
+#if ARCH_X86_64
+ "d" ((x86_reg)us), "r" ((x86_reg)vs)
+#else
+ "d" (&us)
+#endif
+ : "memory"
+ );
+ pack_li_0_C(dst, y, u, v, (w&15), us, vs);
+}
+
+static void pack_li_1_MMX(unsigned char *dst, unsigned char *y,
+ unsigned char *u, unsigned char *v, int w, int us, int vs)
+{
+ __asm__ volatile (""
+ "push %%"REG_BP" \n\t"
+#if ARCH_X86_64
+ "mov %6, %%"REG_BP" \n\t"
+#else
+ "movl 4(%%"REG_d"), %%"REG_BP" \n\t"
+ "movl (%%"REG_d"), %%"REG_d" \n\t"
+#endif
+ "pxor %%mm0, %%mm0 \n\t"
+
+ ASMALIGN(4)
+ ".Lli1: \n\t"
+ "movq (%%"REG_S"), %%mm1 \n\t"
+ "movq (%%"REG_S"), %%mm2 \n\t"
+
+ "movq (%%"REG_a",%%"REG_d",2), %%mm4 \n\t"
+ "movq (%%"REG_b",%%"REG_BP",2), %%mm6 \n\t"
+ "punpcklbw %%mm0, %%mm4 \n\t"
+ "punpcklbw %%mm0, %%mm6 \n\t"
+ "movq (%%"REG_a"), %%mm3 \n\t"
+ "movq (%%"REG_b"), %%mm5 \n\t"
+ "punpcklbw %%mm0, %%mm3 \n\t"
+ "punpcklbw %%mm0, %%mm5 \n\t"
+ "movq %%mm4, %%mm7 \n\t"
+ "paddw %%mm4, %%mm4 \n\t"
+ "paddw %%mm7, %%mm4 \n\t"
+ "movq %%mm6, %%mm7 \n\t"
+ "paddw %%mm6, %%mm6 \n\t"
+ "paddw %%mm7, %%mm6 \n\t"
+ "paddw %%mm3, %%mm4 \n\t"
+ "paddw %%mm5, %%mm6 \n\t"
+ "paddw %%mm3, %%mm4 \n\t"
+ "paddw %%mm5, %%mm6 \n\t"
+ "paddw %%mm3, %%mm4 \n\t"
+ "paddw %%mm5, %%mm6 \n\t"
+ "paddw %%mm3, %%mm4 \n\t"
+ "paddw %%mm5, %%mm6 \n\t"
+ "paddw %%mm3, %%mm4 \n\t"
+ "paddw %%mm5, %%mm6 \n\t"
+ "psrlw $3, %%mm4 \n\t"
+ "psrlw $3, %%mm6 \n\t"
+ "packuswb %%mm4, %%mm4 \n\t"
+ "packuswb %%mm6, %%mm6 \n\t"
+ "punpcklbw %%mm6, %%mm4 \n\t"
+ "punpcklbw %%mm4, %%mm1 \n\t"
+ "punpckhbw %%mm4, %%mm2 \n\t"
+
+ "movq %%mm1, (%%"REG_D") \n\t"
+ "movq %%mm2, 8(%%"REG_D") \n\t"
+
+ "movq 8(%%"REG_S"), %%mm1 \n\t"
+ "movq 8(%%"REG_S"), %%mm2 \n\t"
+
+ "movq (%%"REG_a",%%"REG_d",2), %%mm4 \n\t"
+ "movq (%%"REG_b",%%"REG_BP",2), %%mm6 \n\t"
+ "punpckhbw %%mm0, %%mm4 \n\t"
+ "punpckhbw %%mm0, %%mm6 \n\t"
+ "movq (%%"REG_a"), %%mm3 \n\t"
+ "movq (%%"REG_b"), %%mm5 \n\t"
+ "punpckhbw %%mm0, %%mm3 \n\t"
+ "punpckhbw %%mm0, %%mm5 \n\t"
+ "movq %%mm4, %%mm7 \n\t"
+ "paddw %%mm4, %%mm4 \n\t"
+ "paddw %%mm7, %%mm4 \n\t"
+ "movq %%mm6, %%mm7 \n\t"
+ "paddw %%mm6, %%mm6 \n\t"
+ "paddw %%mm7, %%mm6 \n\t"
+ "paddw %%mm3, %%mm4 \n\t"
+ "paddw %%mm5, %%mm6 \n\t"
+ "paddw %%mm3, %%mm4 \n\t"
+ "paddw %%mm5, %%mm6 \n\t"
+ "paddw %%mm3, %%mm4 \n\t"
+ "paddw %%mm5, %%mm6 \n\t"
+ "paddw %%mm3, %%mm4 \n\t"
+ "paddw %%mm5, %%mm6 \n\t"
+ "paddw %%mm3, %%mm4 \n\t"
+ "paddw %%mm5, %%mm6 \n\t"
+ "psrlw $3, %%mm4 \n\t"
+ "psrlw $3, %%mm6 \n\t"
+ "packuswb %%mm4, %%mm4 \n\t"
+ "packuswb %%mm6, %%mm6 \n\t"
+ "punpcklbw %%mm6, %%mm4 \n\t"
+ "punpcklbw %%mm4, %%mm1 \n\t"
+ "punpckhbw %%mm4, %%mm2 \n\t"
+
+ "add $16, %%"REG_S" \n\t"
+ "add $8, %%"REG_a" \n\t"
+ "add $8, %%"REG_b" \n\t"
+
+ "movq %%mm1, 16(%%"REG_D") \n\t"
+ "movq %%mm2, 24(%%"REG_D") \n\t"
+ "add $32, %%"REG_D" \n\t"
+
+ "decl %%ecx \n\t"
+ "jnz .Lli1 \n\t"
+ "emms \n\t"
+ "pop %%"REG_BP" \n\t"
+ :
+ : "S" (y), "D" (dst), "a" (u), "b" (v), "c" (w/16),
+#if ARCH_X86_64
+ "d" ((x86_reg)us), "r" ((x86_reg)vs)
+#else
+ "d" (&us)
+#endif
+ : "memory"
+ );
+ pack_li_1_C(dst, y, u, v, (w&15), us, vs);
+}
+#endif /* HAVE_EBX_AVAILABLE */
+#endif
+
+static pack_func_t *pack_nn;
+static pack_func_t *pack_li_0;
+static pack_func_t *pack_li_1;
+
+static void ilpack(unsigned char *dst, unsigned char *src[3],
+ int dststride, int srcstride[3], int w, int h, pack_func_t *pack[2])
+{
+ int i;
+ unsigned char *y, *u, *v;
+ int ys = srcstride[0], us = srcstride[1], vs = srcstride[2];
+ int a, b;
+
+ y = src[0];
+ u = src[1];
+ v = src[2];
+
+ pack_nn(dst, y, u, v, w, 0, 0);
+ y += ys; dst += dststride;
+ pack_nn(dst, y, u+us, v+vs, w, 0, 0);
+ y += ys; dst += dststride;
+ for (i=2; i<h-2; i++) {
+ a = (i&2) ? 1 : -1;
+ b = (i&1) ^ ((i&2)>>1);
+ pack[b](dst, y, u, v, w, us*a, vs*a);
+ y += ys;
+ if ((i&3) == 1) {
+ u -= us;
+ v -= vs;
+ } else {
+ u += us;
+ v += vs;
+ }
+ dst += dststride;
+ }
+ pack_nn(dst, y, u, v, w, 0, 0);
+ y += ys; dst += dststride; u += us; v += vs;
+ pack_nn(dst, y, u, v, w, 0, 0);
+}
+
+
+static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
+{
+ mp_image_t *dmpi;
+
+ // hope we'll get DR buffer:
+ dmpi=vf_get_image(vf->next, IMGFMT_YUY2,
+ MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
+ mpi->w, mpi->h);
+
+ ilpack(dmpi->planes[0], mpi->planes, dmpi->stride[0], mpi->stride, mpi->w, mpi->h, vf->priv->pack);
+
+ return vf_next_put_image(vf,dmpi, pts);
+}
+
+static int config(struct vf_instance *vf,
+ int width, int height, int d_width, int d_height,
+ unsigned int flags, unsigned int outfmt)
+{
+ /* FIXME - also support UYVY output? */
+ return vf_next_config(vf, width, height, d_width, d_height, flags, IMGFMT_YUY2);
+}
+
+
+static int query_format(struct vf_instance *vf, unsigned int fmt)
+{
+ /* FIXME - really any YUV 4:2:0 input format should work */
+ switch (fmt) {
+ case IMGFMT_YV12:
+ case IMGFMT_IYUV:
+ case IMGFMT_I420:
+ return vf_next_query_format(vf,IMGFMT_YUY2);
+ }
+ return 0;
+}
+
+static int vf_open(vf_instance_t *vf, char *args)
+{
+ vf->config=config;
+ vf->query_format=query_format;
+ vf->put_image=put_image;
+ vf->priv = calloc(1, sizeof(struct vf_priv_s));
+ vf->priv->mode = 1;
+ if (args) sscanf(args, "%d", &vf->priv->mode);
+
+ pack_nn = pack_nn_C;
+ pack_li_0 = pack_li_0_C;
+ pack_li_1 = pack_li_1_C;
+#if HAVE_MMX
+ if(gCpuCaps.hasMMX) {
+ pack_nn = pack_nn_MMX;
+#if HAVE_EBX_AVAILABLE
+ pack_li_0 = pack_li_0_MMX;
+ pack_li_1 = pack_li_1_MMX;
+#endif
+ }
+#endif
+
+ switch(vf->priv->mode) {
+ case 0:
+ vf->priv->pack[0] = vf->priv->pack[1] = pack_nn;
+ break;
+ default:
+ mp_msg(MSGT_VFILTER, MSGL_WARN,
+ "ilpack: unknown mode %d (fallback to linear)\n",
+ vf->priv->mode);
+ case 1:
+ vf->priv->pack[0] = pack_li_0;
+ vf->priv->pack[1] = pack_li_1;
+ break;
+ }
+
+ return 1;
+}
+
+const vf_info_t vf_info_ilpack = {
+ "4:2:0 planar -> 4:2:2 packed reinterlacer",
+ "ilpack",
+ "Richard Felker",
+ "",
+ vf_open,
+ NULL
+};
diff --git a/libavfilter/libmpcodecs/vf_ivtc.c b/libavfilter/libmpcodecs/vf_ivtc.c
new file mode 100644
index 0000000000..b10e50561a
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_ivtc.c
@@ -0,0 +1,550 @@
+/*
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "config.h"
+#include "mp_msg.h"
+#include "cpudetect.h"
+
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+
+#include "libvo/fastmemcpy.h"
+
+
+struct metrics {
+ /* difference: total, even lines, odd lines */
+ int d, e, o;
+ /* noise: temporal, spacial (current), spacial (past) */
+ int t, s, p;
+};
+
+struct frameinfo {
+ /* peak, relative, mean */
+ struct metrics p, r, m;
+};
+
+struct vf_priv_s {
+ struct frameinfo fi[2];
+ mp_image_t *dmpi;
+ int first;
+ int drop, lastdrop, dropnext;
+ int inframes, outframes;
+};
+
+enum {
+ F_DROP,
+ F_MERGE,
+ F_NEXT,
+ F_SHOW
+};
+
+#if HAVE_MMX && HAVE_EBX_AVAILABLE
+static void block_diffs_MMX(struct metrics *m, unsigned char *old, unsigned char *new, int os, int ns)
+{
+ int i;
+ short out[24]; // output buffer for the partial metrics from the mmx code
+
+ __asm__ (
+ "movl $4, %%ecx \n\t"
+ "pxor %%mm4, %%mm4 \n\t" // 4 even difference sums
+ "pxor %%mm5, %%mm5 \n\t" // 4 odd difference sums
+ "pxor %%mm7, %%mm7 \n\t" // all zeros
+
+ ASMALIGN(4)
+ "1: \n\t"
+
+ // Even difference
+ "movq (%%"REG_S"), %%mm0 \n\t"
+ "movq (%%"REG_S"), %%mm2 \n\t"
+ "add %%"REG_a", %%"REG_S" \n\t"
+ "movq (%%"REG_D"), %%mm1 \n\t"
+ "add %%"REG_b", %%"REG_D" \n\t"
+ "psubusb %%mm1, %%mm2 \n\t"
+ "psubusb %%mm0, %%mm1 \n\t"
+ "movq %%mm2, %%mm0 \n\t"
+ "movq %%mm1, %%mm3 \n\t"
+ "punpcklbw %%mm7, %%mm0 \n\t"
+ "punpcklbw %%mm7, %%mm1 \n\t"
+ "punpckhbw %%mm7, %%mm2 \n\t"
+ "punpckhbw %%mm7, %%mm3 \n\t"
+ "paddw %%mm0, %%mm4 \n\t"
+ "paddw %%mm1, %%mm4 \n\t"
+ "paddw %%mm2, %%mm4 \n\t"
+ "paddw %%mm3, %%mm4 \n\t"
+
+ // Odd difference
+ "movq (%%"REG_S"), %%mm0 \n\t"
+ "movq (%%"REG_S"), %%mm2 \n\t"
+ "add %%"REG_a", %%"REG_S" \n\t"
+ "movq (%%"REG_D"), %%mm1 \n\t"
+ "add %%"REG_b", %%"REG_D" \n\t"
+ "psubusb %%mm1, %%mm2 \n\t"
+ "psubusb %%mm0, %%mm1 \n\t"
+ "movq %%mm2, %%mm0 \n\t"
+ "movq %%mm1, %%mm3 \n\t"
+ "punpcklbw %%mm7, %%mm0 \n\t"
+ "punpcklbw %%mm7, %%mm1 \n\t"
+ "punpckhbw %%mm7, %%mm2 \n\t"
+ "punpckhbw %%mm7, %%mm3 \n\t"
+ "paddw %%mm0, %%mm5 \n\t"
+ "paddw %%mm1, %%mm5 \n\t"
+ "paddw %%mm2, %%mm5 \n\t"
+ "paddw %%mm3, %%mm5 \n\t"
+
+ "decl %%ecx \n\t"
+ "jnz 1b \n\t"
+ "movq %%mm4, (%%"REG_d") \n\t"
+ "movq %%mm5, 8(%%"REG_d") \n\t"
+ :
+ : "S" (old), "D" (new), "a" (os), "b" (ns), "d" (out)
+ : "memory"
+ );
+ m->e = out[0]+out[1]+out[2]+out[3];
+ m->o = out[4]+out[5]+out[6]+out[7];
+ m->d = m->e + m->o;
+
+ __asm__ (
+ // First loop to measure first four columns
+ "movl $4, %%ecx \n\t"
+ "pxor %%mm4, %%mm4 \n\t" // Past spacial noise
+ "pxor %%mm5, %%mm5 \n\t" // Temporal noise
+ "pxor %%mm6, %%mm6 \n\t" // Current spacial noise
+
+ ASMALIGN(4)
+ "2: \n\t"
+
+ "movq (%%"REG_S"), %%mm0 \n\t"
+ "movq (%%"REG_S",%%"REG_a"), %%mm1 \n\t"
+ "add %%"REG_a", %%"REG_S" \n\t"
+ "add %%"REG_a", %%"REG_S" \n\t"
+ "movq (%%"REG_D"), %%mm2 \n\t"
+ "movq (%%"REG_D",%%"REG_b"), %%mm3 \n\t"
+ "add %%"REG_b", %%"REG_D" \n\t"
+ "add %%"REG_b", %%"REG_D" \n\t"
+ "punpcklbw %%mm7, %%mm0 \n\t"
+ "punpcklbw %%mm7, %%mm1 \n\t"
+ "punpcklbw %%mm7, %%mm2 \n\t"
+ "punpcklbw %%mm7, %%mm3 \n\t"
+ "paddw %%mm1, %%mm4 \n\t"
+ "paddw %%mm1, %%mm5 \n\t"
+ "paddw %%mm3, %%mm6 \n\t"
+ "psubw %%mm0, %%mm4 \n\t"
+ "psubw %%mm2, %%mm5 \n\t"
+ "psubw %%mm2, %%mm6 \n\t"
+
+ "decl %%ecx \n\t"
+ "jnz 2b \n\t"
+
+ "movq %%mm0, %%mm1 \n\t"
+ "movq %%mm0, %%mm2 \n\t"
+ "movq %%mm0, %%mm3 \n\t"
+ "pcmpgtw %%mm4, %%mm1 \n\t"
+ "pcmpgtw %%mm5, %%mm2 \n\t"
+ "pcmpgtw %%mm6, %%mm3 \n\t"
+ "pxor %%mm1, %%mm4 \n\t"
+ "pxor %%mm2, %%mm5 \n\t"
+ "pxor %%mm3, %%mm6 \n\t"
+ "psubw %%mm1, %%mm4 \n\t"
+ "psubw %%mm2, %%mm5 \n\t"
+ "psubw %%mm3, %%mm6 \n\t"
+ "movq %%mm4, (%%"REG_d") \n\t"
+ "movq %%mm5, 16(%%"REG_d") \n\t"
+ "movq %%mm6, 32(%%"REG_d") \n\t"
+
+ "mov %%"REG_a", %%"REG_c" \n\t"
+ "shl $3, %%"REG_c" \n\t"
+ "sub %%"REG_c", %%"REG_S" \n\t"
+ "mov %%"REG_b", %%"REG_c" \n\t"
+ "shl $3, %%"REG_c" \n\t"
+ "sub %%"REG_c", %%"REG_D" \n\t"
+
+ // Second loop for the last four columns
+ "movl $4, %%ecx \n\t"
+ "pxor %%mm4, %%mm4 \n\t"
+ "pxor %%mm5, %%mm5 \n\t"
+ "pxor %%mm6, %%mm6 \n\t"
+
+ ASMALIGN(4)
+ "3: \n\t"
+
+ "movq (%%"REG_S"), %%mm0 \n\t"
+ "movq (%%"REG_S",%%"REG_a"), %%mm1 \n\t"
+ "add %%"REG_a", %%"REG_S" \n\t"
+ "add %%"REG_a", %%"REG_S" \n\t"
+ "movq (%%"REG_D"), %%mm2 \n\t"
+ "movq (%%"REG_D",%%"REG_b"), %%mm3 \n\t"
+ "add %%"REG_b", %%"REG_D" \n\t"
+ "add %%"REG_b", %%"REG_D" \n\t"
+ "punpckhbw %%mm7, %%mm0 \n\t"
+ "punpckhbw %%mm7, %%mm1 \n\t"
+ "punpckhbw %%mm7, %%mm2 \n\t"
+ "punpckhbw %%mm7, %%mm3 \n\t"
+ "paddw %%mm1, %%mm4 \n\t"
+ "paddw %%mm1, %%mm5 \n\t"
+ "paddw %%mm3, %%mm6 \n\t"
+ "psubw %%mm0, %%mm4 \n\t"
+ "psubw %%mm2, %%mm5 \n\t"
+ "psubw %%mm2, %%mm6 \n\t"
+
+ "decl %%ecx \n\t"
+ "jnz 3b \n\t"
+
+ "movq %%mm0, %%mm1 \n\t"
+ "movq %%mm0, %%mm2 \n\t"
+ "movq %%mm0, %%mm3 \n\t"
+ "pcmpgtw %%mm4, %%mm1 \n\t"
+ "pcmpgtw %%mm5, %%mm2 \n\t"
+ "pcmpgtw %%mm6, %%mm3 \n\t"
+ "pxor %%mm1, %%mm4 \n\t"
+ "pxor %%mm2, %%mm5 \n\t"
+ "pxor %%mm3, %%mm6 \n\t"
+ "psubw %%mm1, %%mm4 \n\t"
+ "psubw %%mm2, %%mm5 \n\t"
+ "psubw %%mm3, %%mm6 \n\t"
+ "movq %%mm4, 8(%%"REG_d") \n\t"
+ "movq %%mm5, 24(%%"REG_d") \n\t"
+ "movq %%mm6, 40(%%"REG_d") \n\t"
+
+ "emms \n\t"
+ :
+ : "S" (old), "D" (new), "a" ((long)os), "b" ((long)ns), "d" (out)
+ : "memory"
+ );
+ m->p = m->t = m->s = 0;
+ for (i=0; i<8; i++) {
+ m->p += out[i];
+ m->t += out[8+i];
+ m->s += out[16+i];
+ }
+ //printf("e=%d o=%d d=%d p=%d t=%d s=%d\n", m->e, m->o, m->d, m->p, m->t, m->s);
+}
+#endif
+
+//#define MAG(a) ((a)*(a))
+//#define MAG(a) (abs(a))
+#define MAG(a) (((a)^((a)>>31))-((a)>>31))
+
+//#define LOWPASS(s) (((s)[-2] + 4*(s)[-1] + 6*(s)[0] + 4*(s)[1] + (s)[2])>>4)
+//#define LOWPASS(s) (((s)[-1] + 2*(s)[0] + (s)[1])>>2)
+#define LOWPASS(s) ((s)[0])
+
+
+static void block_diffs_C(struct metrics *m, unsigned char *old, unsigned char *new, int os, int ns)
+{
+ int x, y, e=0, o=0, s=0, p=0, t=0;
+ unsigned char *oldp, *newp;
+ m->s = m->p = m->t = 0;
+ for (x = 8; x; x--) {
+ oldp = old++;
+ newp = new++;
+ s = p = t = 0;
+ for (y = 4; y; y--) {
+ e += MAG(newp[0]-oldp[0]);
+ o += MAG(newp[ns]-oldp[os]);
+ s += newp[ns]-newp[0];
+ p += oldp[os]-oldp[0];
+ t += oldp[os]-newp[0];
+ oldp += os<<1;
+ newp += ns<<1;
+ }
+ m->s += MAG(s);
+ m->p += MAG(p);
+ m->t += MAG(t);
+ }
+ m->e = e;
+ m->o = o;
+ m->d = e+o;
+}
+
+static void (*block_diffs)(struct metrics *, unsigned char *, unsigned char *, int, int);
+
+#define MAXUP(a,b) ((a) = ((a)>(b)) ? (a) : (b))
+
+static void diff_planes(struct frameinfo *fi,
+ unsigned char *old, unsigned char *new, int w, int h, int os, int ns)
+{
+ int x, y;
+ struct metrics l;
+ struct metrics *peak=&fi->p, *rel=&fi->r, *mean=&fi->m;
+ memset(peak, 0, sizeof(struct metrics));
+ memset(rel, 0, sizeof(struct metrics));
+ memset(mean, 0, sizeof(struct metrics));
+ for (y = 0; y < h-7; y += 8) {
+ for (x = 8; x < w-8-7; x += 8) {
+ block_diffs(&l, old+x+y*os, new+x+y*ns, os, ns);
+ mean->d += l.d;
+ mean->e += l.e;
+ mean->o += l.o;
+ mean->s += l.s;
+ mean->p += l.p;
+ mean->t += l.t;
+ MAXUP(peak->d, l.d);
+ MAXUP(peak->e, l.e);
+ MAXUP(peak->o, l.o);
+ MAXUP(peak->s, l.s);
+ MAXUP(peak->p, l.p);
+ MAXUP(peak->t, l.t);
+ MAXUP(rel->e, l.e-l.o);
+ MAXUP(rel->o, l.o-l.e);
+ MAXUP(rel->s, l.s-l.t);
+ MAXUP(rel->p, l.p-l.t);
+ MAXUP(rel->t, l.t-l.p);
+ MAXUP(rel->d, l.t-l.s); /* hack */
+ }
+ }
+ x = (w/8-2)*(h/8);
+ mean->d /= x;
+ mean->e /= x;
+ mean->o /= x;
+ mean->s /= x;
+ mean->p /= x;
+ mean->t /= x;
+}
+
+static void diff_fields(struct frameinfo *fi, mp_image_t *old, mp_image_t *new)
+{
+ diff_planes(fi, old->planes[0], new->planes[0],
+ new->w, new->h, old->stride[0], new->stride[0]);
+}
+
+static void stats(struct frameinfo *f)
+{
+ mp_msg(MSGT_VFILTER, MSGL_V, " pd=%d re=%d ro=%d rp=%d rt=%d rs=%d rd=%d pp=%d pt=%d ps=%d\r",
+ f->p.d, f->r.e, f->r.o, f->r.p, f->r.t, f->r.s, f->r.d, f->p.p, f->p.t, f->p.s);
+}
+
+static int foo(struct vf_priv_s *p, mp_image_t *new, mp_image_t *cur)
+{
+ struct frameinfo *f = p->fi;
+
+ f[0] = f[1];
+ diff_fields(&f[1], cur, new);
+ stats(&f[1]);
+
+ // Immediately drop this frame if it's already been used.
+ if (p->dropnext) {
+ p->dropnext = 0;
+ return F_DROP;
+ }
+
+ // Sometimes a pulldown frame comes all by itself, so both
+ // its top and bottom field are duplicates from the adjacent
+ // two frames. We can just drop such a frame, but we
+ // immediately show the next frame instead to keep the frame
+ // drops evenly spaced during normal 3:2 pulldown sequences.
+ if ((3*f[1].r.o < f[1].r.e) && (f[1].r.s < f[1].r.d)) {
+ p->dropnext = 1;
+ return F_NEXT;
+ }
+
+ // If none of these conditions hold, we will consider the frame
+ // progressive and just show it as-is.
+ if (!( (3*f[0].r.e < f[0].r.o) ||
+ ((2*f[0].r.d < f[0].r.s) && (f[0].r.s > 1200)) ||
+ ((2*f[1].r.t < f[1].r.p) && (f[1].r.p > 1200)) ))
+ return F_SHOW;
+
+ // Otherwise, we have to decide whether to merge or drop.
+ // If the noise metric only increases minimally, we're off
+ // to a good start...
+ if (((2*f[1].r.t < 3*f[1].r.p) && (f[1].r.t < 3600)) ||
+ (f[1].r.t < 900) || (f[1].r.d < 900)) {
+ // ...and if noise decreases or the duplicate even field
+ // is detected, we go ahead with the merge.
+ if ((3*f[0].r.e < f[0].r.o) || (2*f[1].r.t < f[1].r.p)) {
+ p->dropnext = 1;
+ return F_MERGE;
+ }
+ }
+ return F_DROP;
+}
+
+
+
+static void copy_image(mp_image_t *dmpi, mp_image_t *mpi, int field)
+{
+ switch (field) {
+ case 0:
+ my_memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h/2,
+ dmpi->stride[0]*2, mpi->stride[0]*2);
+ if (mpi->flags & MP_IMGFLAG_PLANAR) {
+ my_memcpy_pic(dmpi->planes[1], mpi->planes[1],
+ mpi->chroma_width, mpi->chroma_height/2,
+ dmpi->stride[1]*2, mpi->stride[1]*2);
+ my_memcpy_pic(dmpi->planes[2], mpi->planes[2],
+ mpi->chroma_width, mpi->chroma_height/2,
+ dmpi->stride[2]*2, mpi->stride[2]*2);
+ }
+ break;
+ case 1:
+ my_memcpy_pic(dmpi->planes[0]+dmpi->stride[0],
+ mpi->planes[0]+mpi->stride[0], mpi->w, mpi->h/2,
+ dmpi->stride[0]*2, mpi->stride[0]*2);
+ if (mpi->flags & MP_IMGFLAG_PLANAR) {
+ my_memcpy_pic(dmpi->planes[1]+dmpi->stride[1],
+ mpi->planes[1]+mpi->stride[1],
+ mpi->chroma_width, mpi->chroma_height/2,
+ dmpi->stride[1]*2, mpi->stride[1]*2);
+ my_memcpy_pic(dmpi->planes[2]+dmpi->stride[2],
+ mpi->planes[2]+mpi->stride[2],
+ mpi->chroma_width, mpi->chroma_height/2,
+ dmpi->stride[2]*2, mpi->stride[2]*2);
+ }
+ break;
+ case 2:
+ memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h,
+ dmpi->stride[0], mpi->stride[0]);
+ if (mpi->flags & MP_IMGFLAG_PLANAR) {
+ memcpy_pic(dmpi->planes[1], mpi->planes[1],
+ mpi->chroma_width, mpi->chroma_height,
+ dmpi->stride[1], mpi->stride[1]);
+ memcpy_pic(dmpi->planes[2], mpi->planes[2],
+ mpi->chroma_width, mpi->chroma_height,
+ dmpi->stride[2], mpi->stride[2]);
+ }
+ break;
+ }
+}
+
+static int do_put_image(struct vf_instance *vf, mp_image_t *dmpi)
+{
+ struct vf_priv_s *p = vf->priv;
+ int dropflag=0;
+
+ if (!p->dropnext) switch (p->drop) {
+ case 0:
+ dropflag = 0;
+ break;
+ case 1:
+ dropflag = (++p->lastdrop >= 5);
+ break;
+ case 2:
+ dropflag = (++p->lastdrop >= 5) && (4*p->inframes <= 5*p->outframes);
+ break;
+ }
+
+ if (dropflag) {
+ //mp_msg(MSGT_VFILTER, MSGL_V, "drop! [%d/%d=%g]\n",
+ // p->outframes, p->inframes, (float)p->outframes/p->inframes);
+ mp_msg(MSGT_VFILTER, MSGL_V, "!");
+ p->lastdrop = 0;
+ return 0;
+ }
+
+ p->outframes++;
+ return vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE);
+}
+
+static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
+{
+ int ret=0;
+ struct vf_priv_s *p = vf->priv;
+
+ p->inframes++;
+
+ if (p->first) { /* hack */
+ p->first = 0;
+ return 1;
+ }
+
+ if (!p->dmpi) p->dmpi = vf_get_image(vf->next, mpi->imgfmt,
+ MP_IMGTYPE_STATIC, MP_IMGFLAG_ACCEPT_STRIDE |
+ MP_IMGFLAG_PRESERVE | MP_IMGFLAG_READABLE,
+ mpi->width, mpi->height);
+ /* FIXME -- not correct, off by one frame! */
+ p->dmpi->qscale = mpi->qscale;
+ p->dmpi->qstride = mpi->qstride;
+ p->dmpi->qscale_type = mpi->qscale_type;
+
+ switch (foo(p, mpi, p->dmpi)) {
+ case F_DROP:
+ copy_image(p->dmpi, mpi, 2);
+ ret = 0;
+ p->lastdrop = 0;
+ mp_msg(MSGT_VFILTER, MSGL_V, "DROP\n");
+ break;
+ case F_MERGE:
+ copy_image(p->dmpi, mpi, 0);
+ ret = do_put_image(vf, p->dmpi);
+ copy_image(p->dmpi, mpi, 1);
+ mp_msg(MSGT_VFILTER, MSGL_V, "MERGE\n");
+ p->dmpi = NULL;
+ break;
+ case F_NEXT:
+ copy_image(p->dmpi, mpi, 2);
+ ret = do_put_image(vf, p->dmpi);
+ mp_msg(MSGT_VFILTER, MSGL_V, "NEXT\n");
+ p->dmpi = NULL;
+ break;
+ case F_SHOW:
+ ret = do_put_image(vf, p->dmpi);
+ copy_image(p->dmpi, mpi, 2);
+ mp_msg(MSGT_VFILTER, MSGL_V, "OK\n");
+ p->dmpi = NULL;
+ break;
+ }
+ return ret;
+}
+
+static int query_format(struct vf_instance *vf, unsigned int fmt)
+{
+ switch (fmt) {
+ case IMGFMT_YV12:
+ case IMGFMT_IYUV:
+ case IMGFMT_I420:
+ return vf_next_query_format(vf, fmt);
+ }
+ return 0;
+}
+
+static void uninit(struct vf_instance *vf)
+{
+ free(vf->priv);
+}
+
+static int vf_open(vf_instance_t *vf, char *args)
+{
+ struct vf_priv_s *p;
+ vf->put_image = put_image;
+ vf->query_format = query_format;
+ vf->uninit = uninit;
+ vf->default_reqs = VFCAP_ACCEPT_STRIDE;
+ vf->priv = p = calloc(1, sizeof(struct vf_priv_s));
+ p->drop = 0;
+ p->first = 1;
+ if (args) sscanf(args, "%d", &p->drop);
+ block_diffs = block_diffs_C;
+#if HAVE_MMX && HAVE_EBX_AVAILABLE
+ if(gCpuCaps.hasMMX) block_diffs = block_diffs_MMX;
+#endif
+ return 1;
+}
+
+const vf_info_t vf_info_ivtc = {
+ "inverse telecine, take 2",
+ "ivtc",
+ "Rich Felker",
+ "",
+ vf_open,
+ NULL
+};
diff --git a/libavfilter/libmpcodecs/vf_kerndeint.c b/libavfilter/libmpcodecs/vf_kerndeint.c
new file mode 100644
index 0000000000..c5197fc542
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_kerndeint.c
@@ -0,0 +1,345 @@
+/*
+ * Original AVISynth Filter Copyright (C) 2003 Donald A. Graft
+ * Adapted to MPlayer by Tobias Diedrich
+ *
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+#include <math.h>
+
+#include "mp_msg.h"
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+#include "libvo/fastmemcpy.h"
+
+//===========================================================================//
+
+struct vf_priv_s {
+ int frame;
+ int map;
+ int order;
+ int thresh;
+ int sharp;
+ int twoway;
+ int do_deinterlace;
+};
+
+
+/***************************************************************************/
+
+
+static int config(struct vf_instance *vf,
+ int width, int height, int d_width, int d_height,
+ unsigned int flags, unsigned int outfmt){
+
+ return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
+}
+
+
+static void uninit(struct vf_instance *vf)
+{
+ free(vf->priv);
+}
+
+static inline int IsRGB(mp_image_t *mpi)
+{
+ return mpi->imgfmt == IMGFMT_RGB;
+}
+
+static inline int IsYUY2(mp_image_t *mpi)
+{
+ return mpi->imgfmt == IMGFMT_YUY2;
+}
+
+#define PLANAR_Y 0
+#define PLANAR_U 1
+#define PLANAR_V 2
+
+static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
+ int cw= mpi->w >> mpi->chroma_x_shift;
+ int ch= mpi->h >> mpi->chroma_y_shift;
+ int W = mpi->w, H = mpi->h;
+ const unsigned char *prvp, *prvpp, *prvpn, *prvpnn, *prvppp, *prvp4p, *prvp4n;
+ const unsigned char *srcp_saved;
+ const unsigned char *srcp, *srcpp, *srcpn, *srcpnn, *srcppp, *srcp3p, *srcp3n, *srcp4p, *srcp4n;
+ unsigned char *dstp, *dstp_saved;
+ int src_pitch;
+ int psrc_pitch;
+ int dst_pitch;
+ int x, y, z;
+ int n = vf->priv->frame++;
+ int val, hi, lo, w, h;
+ double valf;
+ int plane;
+ int threshold = vf->priv->thresh;
+ int order = vf->priv->order;
+ int map = vf->priv->map;
+ int sharp = vf->priv->sharp;
+ int twoway = vf->priv->twoway;
+ mp_image_t *dmpi, *pmpi;
+
+ if(!vf->priv->do_deinterlace)
+ return vf_next_put_image(vf, mpi, pts);
+
+ dmpi=vf_get_image(vf->next,mpi->imgfmt,
+ MP_IMGTYPE_IP, MP_IMGFLAG_ACCEPT_STRIDE,
+ mpi->w,mpi->h);
+ pmpi=vf_get_image(vf->next,mpi->imgfmt,
+ MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
+ mpi->w,mpi->h);
+ if(!dmpi) return 0;
+
+ for (z=0; z<mpi->num_planes; z++) {
+ if (z == 0) plane = PLANAR_Y;
+ else if (z == 1) plane = PLANAR_U;
+ else plane = PLANAR_V;
+
+ h = plane == PLANAR_Y ? H : ch;
+ w = plane == PLANAR_Y ? W : cw;
+
+ srcp = srcp_saved = mpi->planes[z];
+ src_pitch = mpi->stride[z];
+ psrc_pitch = pmpi->stride[z];
+ dstp = dstp_saved = dmpi->planes[z];
+ dst_pitch = dmpi->stride[z];
+ srcp = srcp_saved + (1-order) * src_pitch;
+ dstp = dstp_saved + (1-order) * dst_pitch;
+
+ for (y=0; y<h; y+=2) {
+ fast_memcpy(dstp, srcp, w);
+ srcp += 2*src_pitch;
+ dstp += 2*dst_pitch;
+ }
+
+ // Copy through the lines that will be missed below.
+ fast_memcpy(dstp_saved + order*dst_pitch, srcp_saved + (1-order)*src_pitch, w);
+ fast_memcpy(dstp_saved + (2+order)*dst_pitch, srcp_saved + (3-order)*src_pitch, w);
+ fast_memcpy(dstp_saved + (h-2+order)*dst_pitch, srcp_saved + (h-1-order)*src_pitch, w);
+ fast_memcpy(dstp_saved + (h-4+order)*dst_pitch, srcp_saved + (h-3-order)*src_pitch, w);
+ /* For the other field choose adaptively between using the previous field
+ or the interpolant from the current field. */
+
+ prvp = pmpi->planes[z] + 5*psrc_pitch - (1-order)*psrc_pitch;
+ prvpp = prvp - psrc_pitch;
+ prvppp = prvp - 2*psrc_pitch;
+ prvp4p = prvp - 4*psrc_pitch;
+ prvpn = prvp + psrc_pitch;
+ prvpnn = prvp + 2*psrc_pitch;
+ prvp4n = prvp + 4*psrc_pitch;
+ srcp = srcp_saved + 5*src_pitch - (1-order)*src_pitch;
+ srcpp = srcp - src_pitch;
+ srcppp = srcp - 2*src_pitch;
+ srcp3p = srcp - 3*src_pitch;
+ srcp4p = srcp - 4*src_pitch;
+ srcpn = srcp + src_pitch;
+ srcpnn = srcp + 2*src_pitch;
+ srcp3n = srcp + 3*src_pitch;
+ srcp4n = srcp + 4*src_pitch;
+ dstp = dstp_saved + 5*dst_pitch - (1-order)*dst_pitch;
+ for (y = 5 - (1-order); y <= h - 5 - (1-order); y+=2)
+ {
+ for (x = 0; x < w; x++)
+ {
+ if ((threshold == 0) || (n == 0) ||
+ (abs((int)prvp[x] - (int)srcp[x]) > threshold) ||
+ (abs((int)prvpp[x] - (int)srcpp[x]) > threshold) ||
+ (abs((int)prvpn[x] - (int)srcpn[x]) > threshold))
+ {
+ if (map == 1)
+ {
+ int g = x & ~3;
+ if (IsRGB(mpi) == 1)
+ {
+ dstp[g++] = 255;
+ dstp[g++] = 255;
+ dstp[g++] = 255;
+ dstp[g] = 255;
+ x = g;
+ }
+ else if (IsYUY2(mpi) == 1)
+ {
+ dstp[g++] = 235;
+ dstp[g++] = 128;
+ dstp[g++] = 235;
+ dstp[g] = 128;
+ x = g;
+ }
+ else
+ {
+ if (plane == PLANAR_Y) dstp[x] = 235;
+ else dstp[x] = 128;
+ }
+ }
+ else
+ {
+ if (IsRGB(mpi))
+ {
+ hi = 255;
+ lo = 0;
+ }
+ else if (IsYUY2(mpi))
+ {
+ hi = (x & 1) ? 240 : 235;
+ lo = 16;
+ }
+ else
+ {
+ hi = (plane == PLANAR_Y) ? 235 : 240;
+ lo = 16;
+ }
+
+ if (sharp == 1)
+ {
+ if (twoway == 1)
+ valf = + 0.526*((int)srcpp[x] + (int)srcpn[x])
+ + 0.170*((int)srcp[x] + (int)prvp[x])
+ - 0.116*((int)srcppp[x] + (int)srcpnn[x] + (int)prvppp[x] + (int)prvpnn[x])
+ - 0.026*((int)srcp3p[x] + (int)srcp3n[x])
+ + 0.031*((int)srcp4p[x] + (int)srcp4n[x] + (int)prvp4p[x] + (int)prvp4n[x]);
+ else
+ valf = + 0.526*((int)srcpp[x] + (int)srcpn[x])
+ + 0.170*((int)prvp[x])
+ - 0.116*((int)prvppp[x] + (int)prvpnn[x])
+ - 0.026*((int)srcp3p[x] + (int)srcp3n[x])
+ + 0.031*((int)prvp4p[x] + (int)prvp4p[x]);
+ if (valf > hi) valf = hi;
+ else if (valf < lo) valf = lo;
+ dstp[x] = (int) valf;
+ }
+ else
+ {
+ if (twoway == 1)
+ val = (8*((int)srcpp[x] + (int)srcpn[x]) + 2*((int)srcp[x] + (int)prvp[x]) -
+ (int)(srcppp[x]) - (int)(srcpnn[x]) -
+ (int)(prvppp[x]) - (int)(prvpnn[x])) >> 4;
+ else
+ val = (8*((int)srcpp[x] + (int)srcpn[x]) + 2*((int)prvp[x]) -
+ (int)(prvppp[x]) - (int)(prvpnn[x])) >> 4;
+ if (val > hi) val = hi;
+ else if (val < lo) val = lo;
+ dstp[x] = (int) val;
+ }
+ }
+ }
+ else
+ {
+ dstp[x] = srcp[x];
+ }
+ }
+ prvp += 2*psrc_pitch;
+ prvpp += 2*psrc_pitch;
+ prvppp += 2*psrc_pitch;
+ prvpn += 2*psrc_pitch;
+ prvpnn += 2*psrc_pitch;
+ prvp4p += 2*psrc_pitch;
+ prvp4n += 2*psrc_pitch;
+ srcp += 2*src_pitch;
+ srcpp += 2*src_pitch;
+ srcppp += 2*src_pitch;
+ srcp3p += 2*src_pitch;
+ srcp4p += 2*src_pitch;
+ srcpn += 2*src_pitch;
+ srcpnn += 2*src_pitch;
+ srcp3n += 2*src_pitch;
+ srcp4n += 2*src_pitch;
+ dstp += 2*dst_pitch;
+ }
+
+ srcp = mpi->planes[z];
+ dstp = pmpi->planes[z];
+ for (y=0; y<h; y++) {
+ fast_memcpy(dstp, srcp, w);
+ srcp += src_pitch;
+ dstp += psrc_pitch;
+ }
+ }
+
+ return vf_next_put_image(vf,dmpi, pts);
+}
+
+//===========================================================================//
+
+static int query_format(struct vf_instance *vf, unsigned int fmt){
+ switch(fmt)
+ {
+ case IMGFMT_YV12:
+ case IMGFMT_RGB:
+ case IMGFMT_YUY2:
+ return vf_next_query_format(vf, fmt);
+ }
+ return 0;
+}
+
+static int control(struct vf_instance *vf, int request, void* data){
+ switch (request)
+ {
+ case VFCTRL_GET_DEINTERLACE:
+ *(int*)data = vf->priv->do_deinterlace;
+ return CONTROL_OK;
+ case VFCTRL_SET_DEINTERLACE:
+ vf->priv->do_deinterlace = *(int*)data;
+ return CONTROL_OK;
+ }
+ return vf_next_control (vf, request, data);
+}
+
+static int vf_open(vf_instance_t *vf, char *args){
+
+ vf->control=control;
+ vf->config=config;
+ vf->put_image=put_image;
+ vf->query_format=query_format;
+ vf->uninit=uninit;
+ vf->priv=malloc(sizeof(struct vf_priv_s));
+ memset(vf->priv, 0, sizeof(struct vf_priv_s));
+
+ vf->priv->frame = 0;
+
+ vf->priv->map = 0;
+ vf->priv->order = 0;
+ vf->priv->thresh = 10;
+ vf->priv->sharp = 0;
+ vf->priv->twoway = 0;
+ vf->priv->do_deinterlace=1;
+
+ if (args)
+ {
+ sscanf(args, "%d:%d:%d:%d:%d",
+ &vf->priv->thresh, &vf->priv->map,
+ &vf->priv->order, &vf->priv->sharp,
+ &vf->priv->twoway);
+ }
+ if (vf->priv->order > 1) vf->priv->order = 1;
+
+ return 1;
+}
+
+const vf_info_t vf_info_kerndeint = {
+ "Kernel Deinterlacer",
+ "kerndeint",
+ "Donald Graft",
+ "",
+ vf_open,
+ NULL
+};
+
+//===========================================================================//
diff --git a/libavfilter/libmpcodecs/vf_mcdeint.c b/libavfilter/libmpcodecs/vf_mcdeint.c
new file mode 100644
index 0000000000..64c402cba5
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_mcdeint.c
@@ -0,0 +1,337 @@
+/*
+ * Copyright (C) 2006 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+
+/*
+Known Issues:
+* The motion estimation is somewhat at the mercy of the input, if the input
+ frames are created purely based on spatial interpolation then for example
+ a thin black line or another random and not interpolateable pattern
+ will cause problems
+ Note: completly ignoring the "unavailable" lines during motion estimation
+ didnt look any better, so the most obvious solution would be to improve
+ tfields or penalize problematic motion vectors ...
+
+* If non iterative ME is used then snow currently ignores the OBMC window
+ and as a result sometimes creates artifacts
+
+* only past frames are used, we should ideally use future frames too, something
+ like filtering the whole movie in forward and then backward direction seems
+ like a interresting idea but the current filter framework is FAR from
+ supporting such things
+
+* combining the motion compensated image with the input image also isnt
+ as trivial as it seems, simple blindly taking even lines from one and
+ odd ones from the other doesnt work at all as ME/MC sometimes simple
+ has nothing in the previous frames which matches the current, the current
+ algo has been found by trial and error and almost certainly can be
+ improved ...
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+#include <math.h>
+
+#include "mp_msg.h"
+#include "cpudetect.h"
+
+#include "libavutil/internal.h"
+#include "libavutil/intreadwrite.h"
+#include "libavcodec/avcodec.h"
+#include "libavcodec/dsputil.h"
+
+#undef fprintf
+#undef free
+#undef malloc
+
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+#include "vd_ffmpeg.h"
+
+#define MIN(a,b) ((a) > (b) ? (b) : (a))
+#define MAX(a,b) ((a) < (b) ? (b) : (a))
+#define ABS(a) ((a) > 0 ? (a) : (-(a)))
+
+//===========================================================================//
+
+struct vf_priv_s {
+ int mode;
+ int qp;
+ int parity;
+#if 0
+ int temp_stride[3];
+ uint8_t *src[3];
+ int16_t *temp[3];
+#endif
+ int outbuf_size;
+ uint8_t *outbuf;
+ AVCodecContext *avctx_enc;
+ AVFrame *frame;
+ AVFrame *frame_dec;
+};
+
+static void filter(struct vf_priv_s *p, uint8_t *dst[3], uint8_t *src[3], int dst_stride[3], int src_stride[3], int width, int height){
+ int x, y, i;
+
+ for(i=0; i<3; i++){
+ p->frame->data[i]= src[i];
+ p->frame->linesize[i]= src_stride[i];
+ }
+
+ p->avctx_enc->me_cmp=
+ p->avctx_enc->me_sub_cmp= FF_CMP_SAD /*| (p->parity ? FF_CMP_ODD : FF_CMP_EVEN)*/;
+ p->frame->quality= p->qp*FF_QP2LAMBDA;
+ avcodec_encode_video(p->avctx_enc, p->outbuf, p->outbuf_size, p->frame);
+ p->frame_dec = p->avctx_enc->coded_frame;
+
+ for(i=0; i<3; i++){
+ int is_chroma= !!i;
+ int w= width >>is_chroma;
+ int h= height>>is_chroma;
+ int fils= p->frame_dec->linesize[i];
+ int srcs= src_stride[i];
+
+ for(y=0; y<h; y++){
+ if((y ^ p->parity) & 1){
+ for(x=0; x<w; x++){
+ if((x-2)+(y-1)*w>=0 && (x+2)+(y+1)*w<w*h){ //FIXME either alloc larger images or optimize this
+ uint8_t *filp= &p->frame_dec->data[i][x + y*fils];
+ uint8_t *srcp= &src[i][x + y*srcs];
+ int diff0= filp[-fils] - srcp[-srcs];
+ int diff1= filp[+fils] - srcp[+srcs];
+ int spatial_score= ABS(srcp[-srcs-1] - srcp[+srcs-1])
+ +ABS(srcp[-srcs ] - srcp[+srcs ])
+ +ABS(srcp[-srcs+1] - srcp[+srcs+1]) - 1;
+ int temp= filp[0];
+
+#define CHECK(j)\
+ { int score= ABS(srcp[-srcs-1+j] - srcp[+srcs-1-j])\
+ + ABS(srcp[-srcs +j] - srcp[+srcs -j])\
+ + ABS(srcp[-srcs+1+j] - srcp[+srcs+1-j]);\
+ if(score < spatial_score){\
+ spatial_score= score;\
+ diff0= filp[-fils+j] - srcp[-srcs+j];\
+ diff1= filp[+fils-j] - srcp[+srcs-j];
+
+ CHECK(-1) CHECK(-2) }} }}
+ CHECK( 1) CHECK( 2) }} }}
+#if 0
+ if((diff0 ^ diff1) > 0){
+ int mindiff= ABS(diff0) > ABS(diff1) ? diff1 : diff0;
+ temp-= mindiff;
+ }
+#elif 1
+ if(diff0 + diff1 > 0)
+ temp-= (diff0 + diff1 - ABS( ABS(diff0) - ABS(diff1) )/2)/2;
+ else
+ temp-= (diff0 + diff1 + ABS( ABS(diff0) - ABS(diff1) )/2)/2;
+#else
+ temp-= (diff0 + diff1)/2;
+#endif
+#if 1
+ filp[0]=
+ dst[i][x + y*dst_stride[i]]= temp > 255U ? ~(temp>>31) : temp;
+#else
+ dst[i][x + y*dst_stride[i]]= filp[0];
+ filp[0]= temp > 255U ? ~(temp>>31) : temp;
+#endif
+ }else
+ dst[i][x + y*dst_stride[i]]= p->frame_dec->data[i][x + y*fils];
+ }
+ }
+ }
+ for(y=0; y<h; y++){
+ if(!((y ^ p->parity) & 1)){
+ for(x=0; x<w; x++){
+#if 1
+ p->frame_dec->data[i][x + y*fils]=
+ dst[i][x + y*dst_stride[i]]= src[i][x + y*srcs];
+#else
+ dst[i][x + y*dst_stride[i]]= p->frame_dec->data[i][x + y*fils];
+ p->frame_dec->data[i][x + y*fils]= src[i][x + y*srcs];
+#endif
+ }
+ }
+ }
+ }
+ p->parity ^= 1;
+
+}
+
+static int config(struct vf_instance *vf,
+ int width, int height, int d_width, int d_height,
+ unsigned int flags, unsigned int outfmt){
+ int i;
+ AVCodec *enc= avcodec_find_encoder(CODEC_ID_SNOW);
+
+ for(i=0; i<3; i++){
+ AVCodecContext *avctx_enc;
+#if 0
+ int is_chroma= !!i;
+ int w= ((width + 31) & (~31))>>is_chroma;
+ int h= ((height + 31) & (~31))>>is_chroma;
+
+ vf->priv->temp_stride[i]= w;
+ vf->priv->temp[i]= malloc(vf->priv->temp_stride[i]*h*sizeof(int16_t));
+ vf->priv->src [i]= malloc(vf->priv->temp_stride[i]*h*sizeof(uint8_t));
+#endif
+ avctx_enc=
+ vf->priv->avctx_enc= avcodec_alloc_context();
+ avctx_enc->width = width;
+ avctx_enc->height = height;
+ avctx_enc->time_base= (AVRational){1,25}; // meaningless
+ avctx_enc->gop_size = 300;
+ avctx_enc->max_b_frames= 0;
+ avctx_enc->pix_fmt = PIX_FMT_YUV420P;
+ avctx_enc->flags = CODEC_FLAG_QSCALE | CODEC_FLAG_LOW_DELAY;
+ avctx_enc->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL;
+ avctx_enc->global_quality= 1;
+ avctx_enc->flags2= CODEC_FLAG2_MEMC_ONLY;
+ avctx_enc->me_cmp=
+ avctx_enc->me_sub_cmp= FF_CMP_SAD; //SSE;
+ avctx_enc->mb_cmp= FF_CMP_SSE;
+
+ switch(vf->priv->mode){
+ case 3:
+ avctx_enc->refs= 3;
+ case 2:
+ avctx_enc->me_method= ME_ITER;
+ case 1:
+ avctx_enc->flags |= CODEC_FLAG_4MV;
+ avctx_enc->dia_size=2;
+// avctx_enc->mb_decision = MB_DECISION_RD;
+ case 0:
+ avctx_enc->flags |= CODEC_FLAG_QPEL;
+ }
+
+ avcodec_open(avctx_enc, enc);
+
+ }
+ vf->priv->frame= avcodec_alloc_frame();
+
+ vf->priv->outbuf_size= width*height*10;
+ vf->priv->outbuf= malloc(vf->priv->outbuf_size);
+
+ return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
+}
+
+static void get_image(struct vf_instance *vf, mp_image_t *mpi){
+ if(mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change
+return; //caused problems, dunno why
+ // ok, we can do pp in-place (or pp disabled):
+ vf->dmpi=vf_get_image(vf->next,mpi->imgfmt,
+ mpi->type, mpi->flags | MP_IMGFLAG_READABLE, mpi->width, mpi->height);
+ mpi->planes[0]=vf->dmpi->planes[0];
+ mpi->stride[0]=vf->dmpi->stride[0];
+ mpi->width=vf->dmpi->width;
+ if(mpi->flags&MP_IMGFLAG_PLANAR){
+ mpi->planes[1]=vf->dmpi->planes[1];
+ mpi->planes[2]=vf->dmpi->planes[2];
+ mpi->stride[1]=vf->dmpi->stride[1];
+ mpi->stride[2]=vf->dmpi->stride[2];
+ }
+ mpi->flags|=MP_IMGFLAG_DIRECT;
+}
+
+static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
+ mp_image_t *dmpi;
+
+ if(!(mpi->flags&MP_IMGFLAG_DIRECT)){
+ // no DR, so get a new image! hope we'll get DR buffer:
+ dmpi=vf_get_image(vf->next,mpi->imgfmt,
+ MP_IMGTYPE_TEMP,
+ MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE,
+ mpi->width,mpi->height);
+ vf_clone_mpi_attributes(dmpi, mpi);
+ }else{
+ dmpi=vf->dmpi;
+ }
+
+ filter(vf->priv, dmpi->planes, mpi->planes, dmpi->stride, mpi->stride, mpi->w, mpi->h);
+
+ return vf_next_put_image(vf,dmpi, pts);
+}
+
+static void uninit(struct vf_instance *vf){
+ if(!vf->priv) return;
+
+#if 0
+ for(i=0; i<3; i++){
+ free(vf->priv->temp[i]);
+ vf->priv->temp[i]= NULL;
+ free(vf->priv->src[i]);
+ vf->priv->src[i]= NULL;
+ }
+#endif
+ if (vf->priv->avctx_enc) {
+ avcodec_close(vf->priv->avctx_enc);
+ av_freep(&vf->priv->avctx_enc);
+ }
+
+ free(vf->priv->outbuf);
+ free(vf->priv);
+ vf->priv=NULL;
+}
+
+//===========================================================================//
+static int query_format(struct vf_instance *vf, unsigned int fmt){
+ switch(fmt){
+ case IMGFMT_YV12:
+ case IMGFMT_I420:
+ case IMGFMT_IYUV:
+ case IMGFMT_Y800:
+ case IMGFMT_Y8:
+ return vf_next_query_format(vf,fmt);
+ }
+ return 0;
+}
+
+static int vf_open(vf_instance_t *vf, char *args){
+
+ vf->config=config;
+ vf->put_image=put_image;
+ vf->get_image=get_image;
+ vf->query_format=query_format;
+ vf->uninit=uninit;
+ vf->priv=malloc(sizeof(struct vf_priv_s));
+ memset(vf->priv, 0, sizeof(struct vf_priv_s));
+
+ init_avcodec();
+
+ vf->priv->mode=0;
+ vf->priv->parity= -1;
+ vf->priv->qp=1;
+
+ if (args) sscanf(args, "%d:%d:%d", &vf->priv->mode, &vf->priv->parity, &vf->priv->qp);
+
+ return 1;
+}
+
+const vf_info_t vf_info_mcdeint = {
+ "motion compensating deinterlacer",
+ "mcdeint",
+ "Michael Niedermayer",
+ "",
+ vf_open,
+ NULL
+};
diff --git a/libavfilter/libmpcodecs/vf_mirror.c b/libavfilter/libmpcodecs/vf_mirror.c
new file mode 100644
index 0000000000..5ac05e9145
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_mirror.c
@@ -0,0 +1,131 @@
+/*
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+
+#include "config.h"
+#include "mp_msg.h"
+
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+
+
+static void mirror(unsigned char* dst,unsigned char* src,int dststride,int srcstride,int w,int h,int bpp,unsigned int fmt){
+ int y;
+ for(y=0;y<h;y++){
+ int x;
+ switch(bpp){
+ case 1:
+ for(x=0;x<w;x++) dst[x]=src[w-x-1];
+ break;
+ case 2:
+ switch(fmt){
+ case IMGFMT_UYVY: {
+ // packed YUV is tricky. U,V are 32bpp while Y is 16bpp:
+ int w2=w>>1;
+ for(x=0;x<w2;x++){
+ // TODO: optimize this...
+ dst[x*4+0]=src[0+(w2-x-1)*4];
+ dst[x*4+1]=src[3+(w2-x-1)*4];
+ dst[x*4+2]=src[2+(w2-x-1)*4];
+ dst[x*4+3]=src[1+(w2-x-1)*4];
+ }
+ break; }
+ case IMGFMT_YUY2:
+ case IMGFMT_YVYU: {
+ // packed YUV is tricky. U,V are 32bpp while Y is 16bpp:
+ int w2=w>>1;
+ for(x=0;x<w2;x++){
+ // TODO: optimize this...
+ dst[x*4+0]=src[2+(w2-x-1)*4];
+ dst[x*4+1]=src[1+(w2-x-1)*4];
+ dst[x*4+2]=src[0+(w2-x-1)*4];
+ dst[x*4+3]=src[3+(w2-x-1)*4];
+ }
+ break; }
+ default:
+ for(x=0;x<w;x++) *((short*)(dst+x*2))=*((short*)(src+(w-x-1)*2));
+ }
+ break;
+ case 3:
+ for(x=0;x<w;x++){
+ dst[x*3+0]=src[0+(w-x-1)*3];
+ dst[x*3+1]=src[1+(w-x-1)*3];
+ dst[x*3+2]=src[2+(w-x-1)*3];
+ }
+ break;
+ case 4:
+ for(x=0;x<w;x++) *((int*)(dst+x*4))=*((int*)(src+(w-x-1)*4));
+ }
+ src+=srcstride;
+ dst+=dststride;
+ }
+}
+
+//===========================================================================//
+
+static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
+ mp_image_t *dmpi;
+
+ // hope we'll get DR buffer:
+ dmpi=vf_get_image(vf->next,mpi->imgfmt,
+ MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
+ mpi->w, mpi->h);
+
+ if(mpi->flags&MP_IMGFLAG_PLANAR){
+ mirror(dmpi->planes[0],mpi->planes[0],
+ dmpi->stride[0],mpi->stride[0],
+ dmpi->w,dmpi->h,1,mpi->imgfmt);
+ mirror(dmpi->planes[1],mpi->planes[1],
+ dmpi->stride[1],mpi->stride[1],
+ dmpi->w>>mpi->chroma_x_shift,dmpi->h>>mpi->chroma_y_shift,1,mpi->imgfmt);
+ mirror(dmpi->planes[2],mpi->planes[2],
+ dmpi->stride[2],mpi->stride[2],
+ dmpi->w>>mpi->chroma_x_shift,dmpi->h>>mpi->chroma_y_shift,1,mpi->imgfmt);
+ } else {
+ mirror(dmpi->planes[0],mpi->planes[0],
+ dmpi->stride[0],mpi->stride[0],
+ dmpi->w,dmpi->h,dmpi->bpp>>3,mpi->imgfmt);
+ dmpi->planes[1]=mpi->planes[1]; // passthrough rgb8 palette
+ }
+
+ return vf_next_put_image(vf,dmpi, pts);
+}
+
+//===========================================================================//
+
+static int vf_open(vf_instance_t *vf, char *args){
+ //vf->config=config;
+ vf->put_image=put_image;
+ return 1;
+}
+
+const vf_info_t vf_info_mirror = {
+ "horizontal mirror",
+ "mirror",
+ "Eyck",
+ "",
+ vf_open,
+ NULL
+};
+
+//===========================================================================//
diff --git a/libavfilter/libmpcodecs/vf_noise.c b/libavfilter/libmpcodecs/vf_noise.c
new file mode 100644
index 0000000000..9521619aed
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_noise.c
@@ -0,0 +1,474 @@
+/*
+ * Copyright (C) 2002 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+#include <math.h>
+
+#include "config.h"
+#include "mp_msg.h"
+#include "cpudetect.h"
+
+#if HAVE_MALLOC_H
+#include <malloc.h>
+#endif
+
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+#include "libvo/fastmemcpy.h"
+#include "libavutil/mem.h"
+
+#define MAX_NOISE 4096
+#define MAX_SHIFT 1024
+#define MAX_RES (MAX_NOISE-MAX_SHIFT)
+
+//===========================================================================//
+
+static inline void lineNoise_C(uint8_t *dst, uint8_t *src, int8_t *noise, int len, int shift);
+static inline void lineNoiseAvg_C(uint8_t *dst, uint8_t *src, int len, int8_t **shift);
+
+static void (*lineNoise)(uint8_t *dst, uint8_t *src, int8_t *noise, int len, int shift)= lineNoise_C;
+static void (*lineNoiseAvg)(uint8_t *dst, uint8_t *src, int len, int8_t **shift)= lineNoiseAvg_C;
+
+typedef struct FilterParam{
+ int strength;
+ int uniform;
+ int temporal;
+ int quality;
+ int averaged;
+ int pattern;
+ int shiftptr;
+ int8_t *noise;
+ int8_t *prev_shift[MAX_RES][3];
+}FilterParam;
+
+struct vf_priv_s {
+ FilterParam lumaParam;
+ FilterParam chromaParam;
+ unsigned int outfmt;
+};
+
+static int nonTempRandShift_init;
+static int nonTempRandShift[MAX_RES];
+
+static int patt[4] = {
+ -1,0,1,0
+};
+
+#define RAND_N(range) ((int) ((double)range*rand()/(RAND_MAX+1.0)))
+static int8_t *initNoise(FilterParam *fp){
+ int strength= fp->strength;
+ int uniform= fp->uniform;
+ int averaged= fp->averaged;
+ int pattern= fp->pattern;
+ int8_t *noise= av_malloc(MAX_NOISE*sizeof(int8_t));
+ int i, j;
+
+ srand(123457);
+
+ for(i=0,j=0; i<MAX_NOISE; i++,j++)
+ {
+ if(uniform) {
+ if (averaged) {
+ if (pattern) {
+ noise[i]= (RAND_N(strength) - strength/2)/6
+ +patt[j%4]*strength*0.25/3;
+ } else {
+ noise[i]= (RAND_N(strength) - strength/2)/3;
+ }
+ } else {
+ if (pattern) {
+ noise[i]= (RAND_N(strength) - strength/2)/2
+ + patt[j%4]*strength*0.25;
+ } else {
+ noise[i]= RAND_N(strength) - strength/2;
+ }
+ }
+ } else {
+ double x1, x2, w, y1;
+ do {
+ x1 = 2.0 * rand()/(float)RAND_MAX - 1.0;
+ x2 = 2.0 * rand()/(float)RAND_MAX - 1.0;
+ w = x1 * x1 + x2 * x2;
+ } while ( w >= 1.0 );
+
+ w = sqrt( (-2.0 * log( w ) ) / w );
+ y1= x1 * w;
+ y1*= strength / sqrt(3.0);
+ if (pattern) {
+ y1 /= 2;
+ y1 += patt[j%4]*strength*0.35;
+ }
+ if (y1<-128) y1=-128;
+ else if(y1> 127) y1= 127;
+ if (averaged) y1 /= 3.0;
+ noise[i]= (int)y1;
+ }
+ if (RAND_N(6) == 0) j--;
+ }
+
+
+ for (i = 0; i < MAX_RES; i++)
+ for (j = 0; j < 3; j++)
+ fp->prev_shift[i][j] = noise + (rand()&(MAX_SHIFT-1));
+
+ if(!nonTempRandShift_init){
+ for(i=0; i<MAX_RES; i++){
+ nonTempRandShift[i]= rand()&(MAX_SHIFT-1);
+ }
+ nonTempRandShift_init = 1;
+ }
+
+ fp->noise= noise;
+ fp->shiftptr= 0;
+ return noise;
+}
+
+/***************************************************************************/
+
+#if HAVE_MMX
+static inline void lineNoise_MMX(uint8_t *dst, uint8_t *src, int8_t *noise, int len, int shift){
+ x86_reg mmx_len= len&(~7);
+ noise+=shift;
+
+ __asm__ volatile(
+ "mov %3, %%"REG_a" \n\t"
+ "pcmpeqb %%mm7, %%mm7 \n\t"
+ "psllw $15, %%mm7 \n\t"
+ "packsswb %%mm7, %%mm7 \n\t"
+ ASMALIGN(4)
+ "1: \n\t"
+ "movq (%0, %%"REG_a"), %%mm0 \n\t"
+ "movq (%1, %%"REG_a"), %%mm1 \n\t"
+ "pxor %%mm7, %%mm0 \n\t"
+ "paddsb %%mm1, %%mm0 \n\t"
+ "pxor %%mm7, %%mm0 \n\t"
+ "movq %%mm0, (%2, %%"REG_a") \n\t"
+ "add $8, %%"REG_a" \n\t"
+ " js 1b \n\t"
+ :: "r" (src+mmx_len), "r" (noise+mmx_len), "r" (dst+mmx_len), "g" (-mmx_len)
+ : "%"REG_a
+ );
+ if(mmx_len!=len)
+ lineNoise_C(dst+mmx_len, src+mmx_len, noise+mmx_len, len-mmx_len, 0);
+}
+#endif
+
+//duplicate of previous except movntq
+#if HAVE_MMX2
+static inline void lineNoise_MMX2(uint8_t *dst, uint8_t *src, int8_t *noise, int len, int shift){
+ x86_reg mmx_len= len&(~7);
+ noise+=shift;
+
+ __asm__ volatile(
+ "mov %3, %%"REG_a" \n\t"
+ "pcmpeqb %%mm7, %%mm7 \n\t"
+ "psllw $15, %%mm7 \n\t"
+ "packsswb %%mm7, %%mm7 \n\t"
+ ASMALIGN(4)
+ "1: \n\t"
+ "movq (%0, %%"REG_a"), %%mm0 \n\t"
+ "movq (%1, %%"REG_a"), %%mm1 \n\t"
+ "pxor %%mm7, %%mm0 \n\t"
+ "paddsb %%mm1, %%mm0 \n\t"
+ "pxor %%mm7, %%mm0 \n\t"
+ "movntq %%mm0, (%2, %%"REG_a") \n\t"
+ "add $8, %%"REG_a" \n\t"
+ " js 1b \n\t"
+ :: "r" (src+mmx_len), "r" (noise+mmx_len), "r" (dst+mmx_len), "g" (-mmx_len)
+ : "%"REG_a
+ );
+ if(mmx_len!=len)
+ lineNoise_C(dst+mmx_len, src+mmx_len, noise+mmx_len, len-mmx_len, 0);
+}
+#endif
+
+static inline void lineNoise_C(uint8_t *dst, uint8_t *src, int8_t *noise, int len, int shift){
+ int i;
+ noise+= shift;
+ for(i=0; i<len; i++)
+ {
+ int v= src[i]+ noise[i];
+ if(v>255) dst[i]=255; //FIXME optimize
+ else if(v<0) dst[i]=0;
+ else dst[i]=v;
+ }
+}
+
+/***************************************************************************/
+
+#if HAVE_MMX
+static inline void lineNoiseAvg_MMX(uint8_t *dst, uint8_t *src, int len, int8_t **shift){
+ x86_reg mmx_len= len&(~7);
+
+ __asm__ volatile(
+ "mov %5, %%"REG_a" \n\t"
+ ASMALIGN(4)
+ "1: \n\t"
+ "movq (%1, %%"REG_a"), %%mm1 \n\t"
+ "movq (%0, %%"REG_a"), %%mm0 \n\t"
+ "paddb (%2, %%"REG_a"), %%mm1 \n\t"
+ "paddb (%3, %%"REG_a"), %%mm1 \n\t"
+ "movq %%mm0, %%mm2 \n\t"
+ "movq %%mm1, %%mm3 \n\t"
+ "punpcklbw %%mm0, %%mm0 \n\t"
+ "punpckhbw %%mm2, %%mm2 \n\t"
+ "punpcklbw %%mm1, %%mm1 \n\t"
+ "punpckhbw %%mm3, %%mm3 \n\t"
+ "pmulhw %%mm0, %%mm1 \n\t"
+ "pmulhw %%mm2, %%mm3 \n\t"
+ "paddw %%mm1, %%mm1 \n\t"
+ "paddw %%mm3, %%mm3 \n\t"
+ "paddw %%mm0, %%mm1 \n\t"
+ "paddw %%mm2, %%mm3 \n\t"
+ "psrlw $8, %%mm1 \n\t"
+ "psrlw $8, %%mm3 \n\t"
+ "packuswb %%mm3, %%mm1 \n\t"
+ "movq %%mm1, (%4, %%"REG_a") \n\t"
+ "add $8, %%"REG_a" \n\t"
+ " js 1b \n\t"
+ :: "r" (src+mmx_len), "r" (shift[0]+mmx_len), "r" (shift[1]+mmx_len), "r" (shift[2]+mmx_len),
+ "r" (dst+mmx_len), "g" (-mmx_len)
+ : "%"REG_a
+ );
+
+ if(mmx_len!=len){
+ int8_t *shift2[3]={shift[0]+mmx_len, shift[1]+mmx_len, shift[2]+mmx_len};
+ lineNoiseAvg_C(dst+mmx_len, src+mmx_len, len-mmx_len, shift2);
+ }
+}
+#endif
+
+static inline void lineNoiseAvg_C(uint8_t *dst, uint8_t *src, int len, int8_t **shift){
+ int i;
+ int8_t *src2= (int8_t*)src;
+
+ for(i=0; i<len; i++)
+ {
+ const int n= shift[0][i] + shift[1][i] + shift[2][i];
+ dst[i]= src2[i]+((n*src2[i])>>7);
+ }
+}
+
+/***************************************************************************/
+
+static void noise(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int width, int height, FilterParam *fp){
+ int8_t *noise= fp->noise;
+ int y;
+ int shift=0;
+
+ if(!noise)
+ {
+ if(src==dst) return;
+
+ if(dstStride==srcStride) fast_memcpy(dst, src, srcStride*height);
+ else
+ {
+ for(y=0; y<height; y++)
+ {
+ fast_memcpy(dst, src, width);
+ dst+= dstStride;
+ src+= srcStride;
+ }
+ }
+ return;
+ }
+
+ for(y=0; y<height; y++)
+ {
+ if(fp->temporal) shift= rand()&(MAX_SHIFT -1);
+ else shift= nonTempRandShift[y];
+
+ if(fp->quality==0) shift&= ~7;
+ if (fp->averaged) {
+ lineNoiseAvg(dst, src, width, fp->prev_shift[y]);
+ fp->prev_shift[y][fp->shiftptr] = noise + shift;
+ } else {
+ lineNoise(dst, src, noise, width, shift);
+ }
+ dst+= dstStride;
+ src+= srcStride;
+ }
+ fp->shiftptr++;
+ if (fp->shiftptr == 3) fp->shiftptr = 0;
+}
+
+static int config(struct vf_instance *vf,
+ int width, int height, int d_width, int d_height,
+ unsigned int flags, unsigned int outfmt){
+
+ return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
+}
+
+static void get_image(struct vf_instance *vf, mp_image_t *mpi){
+ if(mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change
+ if(mpi->imgfmt!=vf->priv->outfmt) return; // colorspace differ
+ // ok, we can do pp in-place (or pp disabled):
+ vf->dmpi=vf_get_image(vf->next,mpi->imgfmt,
+ mpi->type, mpi->flags, mpi->w, mpi->h);
+ mpi->planes[0]=vf->dmpi->planes[0];
+ mpi->stride[0]=vf->dmpi->stride[0];
+ mpi->width=vf->dmpi->width;
+ if(mpi->flags&MP_IMGFLAG_PLANAR){
+ mpi->planes[1]=vf->dmpi->planes[1];
+ mpi->planes[2]=vf->dmpi->planes[2];
+ mpi->stride[1]=vf->dmpi->stride[1];
+ mpi->stride[2]=vf->dmpi->stride[2];
+ }
+ mpi->flags|=MP_IMGFLAG_DIRECT;
+}
+
+static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
+ mp_image_t *dmpi;
+
+ if(!(mpi->flags&MP_IMGFLAG_DIRECT)){
+ // no DR, so get a new image! hope we'll get DR buffer:
+ vf->dmpi=vf_get_image(vf->next,vf->priv->outfmt,
+ MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
+ mpi->w,mpi->h);
+//printf("nodr\n");
+ }
+//else printf("dr\n");
+ dmpi= vf->dmpi;
+
+ noise(dmpi->planes[0], mpi->planes[0], dmpi->stride[0], mpi->stride[0], mpi->w, mpi->h, &vf->priv->lumaParam);
+ noise(dmpi->planes[1], mpi->planes[1], dmpi->stride[1], mpi->stride[1], mpi->w/2, mpi->h/2, &vf->priv->chromaParam);
+ noise(dmpi->planes[2], mpi->planes[2], dmpi->stride[2], mpi->stride[2], mpi->w/2, mpi->h/2, &vf->priv->chromaParam);
+
+ vf_clone_mpi_attributes(dmpi, mpi);
+
+#if HAVE_MMX
+ if(gCpuCaps.hasMMX) __asm__ volatile ("emms\n\t");
+#endif
+#if HAVE_MMX2
+ if(gCpuCaps.hasMMX2) __asm__ volatile ("sfence\n\t");
+#endif
+
+ return vf_next_put_image(vf,dmpi, pts);
+}
+
+static void uninit(struct vf_instance *vf){
+ if(!vf->priv) return;
+
+ av_free(vf->priv->chromaParam.noise);
+ vf->priv->chromaParam.noise= NULL;
+
+ av_free(vf->priv->lumaParam.noise);
+ vf->priv->lumaParam.noise= NULL;
+
+ free(vf->priv);
+ vf->priv=NULL;
+}
+
+//===========================================================================//
+
+static int query_format(struct vf_instance *vf, unsigned int fmt){
+ switch(fmt)
+ {
+ case IMGFMT_YV12:
+ case IMGFMT_I420:
+ case IMGFMT_IYUV:
+ return vf_next_query_format(vf,vf->priv->outfmt);
+ }
+ return 0;
+}
+
+static void parse(FilterParam *fp, char* args){
+ char *pos;
+ char *max= strchr(args, ':');
+
+ if(!max) max= args + strlen(args);
+
+ fp->strength= atoi(args);
+ pos= strchr(args, 'u');
+ if(pos && pos<max) fp->uniform=1;
+ pos= strchr(args, 't');
+ if(pos && pos<max) fp->temporal=1;
+ pos= strchr(args, 'h');
+ if(pos && pos<max) fp->quality=1;
+ pos= strchr(args, 'p');
+ if(pos && pos<max) fp->pattern=1;
+ pos= strchr(args, 'a');
+ if(pos && pos<max) {
+ fp->temporal=1;
+ fp->averaged=1;
+ }
+
+ if(fp->strength) initNoise(fp);
+}
+
+static const unsigned int fmt_list[]={
+ IMGFMT_YV12,
+ IMGFMT_I420,
+ IMGFMT_IYUV,
+ 0
+};
+
+static int vf_open(vf_instance_t *vf, char *args){
+ vf->config=config;
+ vf->put_image=put_image;
+ vf->get_image=get_image;
+ vf->query_format=query_format;
+ vf->uninit=uninit;
+ vf->priv=malloc(sizeof(struct vf_priv_s));
+ memset(vf->priv, 0, sizeof(struct vf_priv_s));
+ if(args)
+ {
+ char *arg2= strchr(args,':');
+ if(arg2) parse(&vf->priv->chromaParam, arg2+1);
+ parse(&vf->priv->lumaParam, args);
+ }
+
+ // check csp:
+ vf->priv->outfmt=vf_match_csp(&vf->next,fmt_list,IMGFMT_YV12);
+ if(!vf->priv->outfmt)
+ {
+ uninit(vf);
+ return 0; // no csp match :(
+ }
+
+
+#if HAVE_MMX
+ if(gCpuCaps.hasMMX){
+ lineNoise= lineNoise_MMX;
+ lineNoiseAvg= lineNoiseAvg_MMX;
+ }
+#endif
+#if HAVE_MMX2
+ if(gCpuCaps.hasMMX2) lineNoise= lineNoise_MMX2;
+// if(gCpuCaps.hasMMX) lineNoiseAvg= lineNoiseAvg_MMX2;
+#endif
+
+ return 1;
+}
+
+const vf_info_t vf_info_noise = {
+ "noise generator",
+ "noise",
+ "Michael Niedermayer",
+ "",
+ vf_open,
+ NULL
+};
+
+//===========================================================================//
diff --git a/libavfilter/libmpcodecs/vf_ow.c b/libavfilter/libmpcodecs/vf_ow.c
new file mode 100644
index 0000000000..f7fb02db72
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_ow.c
@@ -0,0 +1,322 @@
+/*
+ * Copyright (C) 2007 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+/**
+ * @todo try to change to int
+ * @todo try lifting based implementation
+ * @todo optimize optimize optimize
+ * @todo hard tresholding
+ * @todo use QP to decide filter strength
+ * @todo wavelet normalization / least squares optimal signal vs. noise thresholds
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <inttypes.h>
+#include <math.h>
+
+#include "mp_msg.h"
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+
+//===========================================================================//
+static const uint8_t __attribute__((aligned(8))) dither[8][8]={
+{ 0, 48, 12, 60, 3, 51, 15, 63, },
+{ 32, 16, 44, 28, 35, 19, 47, 31, },
+{ 8, 56, 4, 52, 11, 59, 7, 55, },
+{ 40, 24, 36, 20, 43, 27, 39, 23, },
+{ 2, 50, 14, 62, 1, 49, 13, 61, },
+{ 34, 18, 46, 30, 33, 17, 45, 29, },
+{ 10, 58, 6, 54, 9, 57, 5, 53, },
+{ 42, 26, 38, 22, 41, 25, 37, 21, },
+};
+//FIXME the above is duplicated in many filters
+
+struct vf_priv_s {
+ float strength[2];
+ float delta;
+ int mode;
+ int depth;
+ float *plane[16][4];
+ int stride;
+};
+
+#define S 1.41421356237 //sqrt(2)
+
+static const double coeff[2][5]={
+ {
+ 0.6029490182363579 *S,
+ 0.2668641184428723 *S,
+ -0.07822326652898785 *S,
+ -0.01686411844287495 *S,
+ 0.02674875741080976 *S
+ },{
+ 1.115087052456994 /S,
+ -0.5912717631142470 /S,
+ -0.05754352622849957 /S,
+ 0.09127176311424948 /S
+ }
+};
+
+static const double icoeff[2][5]={
+ {
+ 1.115087052456994 /S,
+ 0.5912717631142470 /S,
+ -0.05754352622849957 /S,
+ -0.09127176311424948 /S
+ },{
+ 0.6029490182363579 *S,
+ -0.2668641184428723 *S,
+ -0.07822326652898785 *S,
+ 0.01686411844287495 *S,
+ 0.02674875741080976 *S
+ }
+};
+#undef S
+
+static inline int mirror(int x, int w){
+ while((unsigned)x > (unsigned)w){
+ x=-x;
+ if(x<0) x+= 2*w;
+ }
+ return x;
+}
+
+static inline void decompose(float *dstL, float *dstH, float *src, int stride, int w){
+ int x, i;
+ for(x=0; x<w; x++){
+ double sumL= src[x*stride] * coeff[0][0];
+ double sumH= src[x*stride] * coeff[1][0];
+ for(i=1; i<=4; i++){
+ double s= (src[mirror(x-i, w-1)*stride] + src[mirror(x+i, w-1)*stride]);
+
+ sumL+= coeff[0][i]*s;
+ sumH+= coeff[1][i]*s;
+ }
+ dstL[x*stride]= sumL;
+ dstH[x*stride]= sumH;
+ }
+}
+
+static inline void compose(float *dst, float *srcL, float *srcH, int stride, int w){
+ int x, i;
+ for(x=0; x<w; x++){
+ double sumL= srcL[x*stride] * icoeff[0][0];
+ double sumH= srcH[x*stride] * icoeff[1][0];
+ for(i=1; i<=4; i++){
+ int x0= mirror(x-i, w-1)*stride;
+ int x1= mirror(x+i, w-1)*stride;
+
+ sumL+= icoeff[0][i]*(srcL[x0] + srcL[x1]);
+ sumH+= icoeff[1][i]*(srcH[x0] + srcH[x1]);
+ }
+ dst[x*stride]= (sumL + sumH)*0.5;
+ }
+}
+
+static inline void decompose2D(float *dstL, float *dstH, float *src, int xstride, int ystride, int step, int w, int h){
+ int y, x;
+ for(y=0; y<h; y++)
+ for(x=0; x<step; x++)
+ decompose(dstL + ystride*y + xstride*x, dstH + ystride*y + xstride*x, src + ystride*y + xstride*x, step*xstride, (w-x+step-1)/step);
+}
+
+static inline void compose2D(float *dst, float *srcL, float *srcH, int xstride, int ystride, int step, int w, int h){
+ int y, x;
+ for(y=0; y<h; y++)
+ for(x=0; x<step; x++)
+ compose(dst + ystride*y + xstride*x, srcL + ystride*y + xstride*x, srcH + ystride*y + xstride*x, step*xstride, (w-x+step-1)/step);
+}
+
+static void decompose2D2(float *dst[4], float *src, float *temp[2], int stride, int step, int w, int h){
+ decompose2D(temp[0], temp[1], src , 1, stride, step , w, h);
+ decompose2D( dst[0], dst[1], temp[0], stride, 1, step , h, w);
+ decompose2D( dst[2], dst[3], temp[1], stride, 1, step , h, w);
+}
+
+static void compose2D2(float *dst, float *src[4], float *temp[2], int stride, int step, int w, int h){
+ compose2D(temp[0], src[0], src[1], stride, 1, step , h, w);
+ compose2D(temp[1], src[2], src[3], stride, 1, step , h, w);
+ compose2D(dst , temp[0], temp[1], 1, stride, step , w, h);
+}
+
+static void filter(struct vf_priv_s *p, uint8_t *dst, uint8_t *src, int dst_stride, int src_stride, int width, int height, int is_luma){
+ int x,y, i, j;
+// double sum=0;
+ double s= p->strength[!is_luma];
+ int depth= p->depth;
+
+ while(1<<depth > width || 1<<depth > height)
+ depth--;
+
+ for(y=0; y<height; y++)
+ for(x=0; x<width; x++)
+ p->plane[0][0][x + y*p->stride]= src[x + y*src_stride];
+
+ for(i=0; i<depth; i++){
+ decompose2D2(p->plane[i+1], p->plane[i][0], p->plane[0]+1,p->stride, 1<<i, width, height);
+ }
+ for(i=0; i<depth; i++){
+ for(j=1; j<4; j++){
+ for(y=0; y<height; y++){
+ for(x=0; x<width; x++){
+ double v= p->plane[i+1][j][x + y*p->stride];
+ if (v> s) v-=s;
+ else if(v<-s) v+=s;
+ else v =0;
+ p->plane[i+1][j][x + y*p->stride]= v;
+ }
+ }
+ }
+ }
+ for(i=depth-1; i>=0; i--){
+ compose2D2(p->plane[i][0], p->plane[i+1], p->plane[0]+1, p->stride, 1<<i, width, height);
+ }
+
+ for(y=0; y<height; y++)
+ for(x=0; x<width; x++){
+ i= p->plane[0][0][x + y*p->stride] + dither[x&7][y&7]*(1.0/64) + 1.0/128; //yes the rounding is insane but optimal :)
+// double e= i - src[x + y*src_stride];
+// sum += e*e;
+ if((unsigned)i > 255U) i= ~(i>>31);
+ dst[x + y*dst_stride]= i;
+ }
+
+// printf("%f\n", sum/height/width);
+}
+
+static int config(struct vf_instance *vf, int width, int height, int d_width, int d_height, unsigned int flags, unsigned int outfmt){
+ int h= (height+15)&(~15);
+ int i,j;
+
+ vf->priv->stride= (width+15)&(~15);
+ for(j=0; j<4; j++){
+ for(i=0; i<=vf->priv->depth; i++)
+ vf->priv->plane[i][j]= malloc(vf->priv->stride*h*sizeof(vf->priv->plane[0][0][0]));
+ }
+
+ return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
+}
+
+static void get_image(struct vf_instance *vf, mp_image_t *mpi){
+ if(mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change
+ // ok, we can do pp in-place (or pp disabled):
+ vf->dmpi=vf_get_image(vf->next,mpi->imgfmt,
+ mpi->type, mpi->flags | MP_IMGFLAG_READABLE, mpi->width, mpi->height);
+ mpi->planes[0]=vf->dmpi->planes[0];
+ mpi->stride[0]=vf->dmpi->stride[0];
+ mpi->width=vf->dmpi->width;
+ if(mpi->flags&MP_IMGFLAG_PLANAR){
+ mpi->planes[1]=vf->dmpi->planes[1];
+ mpi->planes[2]=vf->dmpi->planes[2];
+ mpi->stride[1]=vf->dmpi->stride[1];
+ mpi->stride[2]=vf->dmpi->stride[2];
+ }
+ mpi->flags|=MP_IMGFLAG_DIRECT;
+}
+
+static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
+ mp_image_t *dmpi;
+
+ if(!(mpi->flags&MP_IMGFLAG_DIRECT)){
+ // no DR, so get a new image! hope we'll get DR buffer:
+ dmpi=vf_get_image(vf->next,mpi->imgfmt,
+ MP_IMGTYPE_TEMP,
+ MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE,
+ mpi->width,mpi->height);
+ vf_clone_mpi_attributes(dmpi, mpi);
+ }else{
+ dmpi=vf->dmpi;
+ }
+
+ filter(vf->priv, dmpi->planes[0], mpi->planes[0], dmpi->stride[0], mpi->stride[0], mpi->w, mpi->h, 1);
+ filter(vf->priv, dmpi->planes[1], mpi->planes[1], dmpi->stride[1], mpi->stride[1], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, 0);
+ filter(vf->priv, dmpi->planes[2], mpi->planes[2], dmpi->stride[2], mpi->stride[2], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, 0);
+
+ return vf_next_put_image(vf,dmpi, pts);
+}
+
+static void uninit(struct vf_instance *vf){
+ int i,j;
+ if(!vf->priv) return;
+
+ for(j=0; j<4; j++){
+ for(i=0; i<16; i++){
+ free(vf->priv->plane[i][j]);
+ vf->priv->plane[i][j]= NULL;
+ }
+ }
+
+ free(vf->priv);
+ vf->priv=NULL;
+}
+
+//===========================================================================//
+static int query_format(struct vf_instance *vf, unsigned int fmt){
+ switch(fmt){
+ case IMGFMT_YVU9:
+ case IMGFMT_IF09:
+ case IMGFMT_YV12:
+ case IMGFMT_I420:
+ case IMGFMT_IYUV:
+ case IMGFMT_CLPL:
+ case IMGFMT_Y800:
+ case IMGFMT_Y8:
+ case IMGFMT_444P:
+ case IMGFMT_422P:
+ case IMGFMT_411P:
+ return vf_next_query_format(vf,fmt);
+ }
+ return 0;
+}
+
+
+static int vf_open(vf_instance_t *vf, char *args){
+ vf->config=config;
+ vf->put_image=put_image;
+ vf->get_image=get_image;
+ vf->query_format=query_format;
+ vf->uninit=uninit;
+ vf->priv=malloc(sizeof(struct vf_priv_s));
+ memset(vf->priv, 0, sizeof(struct vf_priv_s));
+
+ vf->priv->depth= 8;
+ vf->priv->strength[0]= 1.0;
+ vf->priv->strength[1]= 1.0;
+ vf->priv->delta= 1.0;
+
+ if (args) sscanf(args, "%d:%f:%f:%d:%f", &vf->priv->depth,
+ &vf->priv->strength[0],
+ &vf->priv->strength[1],
+ &vf->priv->mode,
+ &vf->priv->delta);
+
+ return 1;
+}
+
+const vf_info_t vf_info_ow = {
+ "overcomplete wavelet denoiser",
+ "ow",
+ "Michael Niedermayer",
+ "",
+ vf_open,
+ NULL
+};
diff --git a/libavfilter/libmpcodecs/vf_palette.c b/libavfilter/libmpcodecs/vf_palette.c
new file mode 100644
index 0000000000..3a7f0869bf
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_palette.c
@@ -0,0 +1,236 @@
+/*
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#define _BSD_SOURCE //strcasecmp
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+
+#include "config.h"
+#include "mp_msg.h"
+#include "help_mp.h"
+
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+#include "mpbswap.h"
+
+#include "libswscale/swscale.h"
+
+//===========================================================================//
+
+// commented out 16 and 15 bit output support, because the conversion
+// routines are incorrrect. they assume the palette to be of the same
+// depth as the output, which is incorrect. --Joey
+
+static const unsigned int bgr_list[]={
+ IMGFMT_BGR32,
+ IMGFMT_BGR24,
+// IMGFMT_BGR16,
+// IMGFMT_BGR15,
+ 0
+};
+static const unsigned int rgb_list[]={
+ IMGFMT_RGB32,
+ IMGFMT_RGB24,
+// IMGFMT_RGB16,
+// IMGFMT_RGB15,
+ 0
+};
+
+/**
+ * Palette is assumed to contain BGR16, see rgb32to16 to convert the palette.
+ */
+static void palette8torgb16(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
+{
+ long i;
+ for (i=0; i<num_pixels; i++)
+ ((uint16_t *)dst)[i] = ((const uint16_t *)palette)[src[i]];
+}
+
+static void palette8tobgr16(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
+{
+ long i;
+ for (i=0; i<num_pixels; i++)
+ ((uint16_t *)dst)[i] = bswap_16(((const uint16_t *)palette)[src[i]]);
+}
+
+static unsigned int gray_pal[256];
+
+static unsigned int find_best(struct vf_instance *vf, unsigned int fmt){
+ unsigned int best=0;
+ int ret;
+ const unsigned int* p;
+ if(fmt==IMGFMT_BGR8) p=bgr_list;
+ else if(fmt==IMGFMT_RGB8) p=rgb_list;
+ else return 0;
+ while(*p){
+ ret=vf->next->query_format(vf->next,*p);
+ mp_msg(MSGT_VFILTER,MSGL_DBG2,"[%s] query(%s) -> %d\n",vf->info->name,vo_format_name(*p),ret&3);
+ if(ret&VFCAP_CSP_SUPPORTED_BY_HW){ best=*p; break;} // no conversion -> bingo!
+ if(ret&VFCAP_CSP_SUPPORTED && !best) best=*p; // best with conversion
+ ++p;
+ }
+ return best;
+}
+
+//===========================================================================//
+
+struct vf_priv_s {
+ unsigned int fmt;
+ int pal_msg;
+};
+
+static int config(struct vf_instance *vf,
+ int width, int height, int d_width, int d_height,
+ unsigned int flags, unsigned int outfmt){
+ if (!vf->priv->fmt)
+ vf->priv->fmt=find_best(vf,outfmt);
+ if(!vf->priv->fmt){
+ // no matching fmt, so force one...
+ if(outfmt==IMGFMT_RGB8) vf->priv->fmt=IMGFMT_RGB32;
+ else if(outfmt==IMGFMT_BGR8) vf->priv->fmt=IMGFMT_BGR32;
+ else return 0;
+ }
+ return vf_next_config(vf,width,height,d_width,d_height,flags,vf->priv->fmt);
+}
+
+static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
+ mp_image_t *dmpi;
+ uint8_t *old_palette = mpi->planes[1];
+
+ // hope we'll get DR buffer:
+ dmpi=vf_get_image(vf->next,vf->priv->fmt,
+ MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
+ mpi->w, mpi->h);
+
+ if (!mpi->planes[1])
+ {
+ if(!vf->priv->pal_msg){
+ mp_msg(MSGT_VFILTER,MSGL_V,"[%s] no palette given, assuming builtin grayscale one\n",vf->info->name);
+ vf->priv->pal_msg=1;
+ }
+ mpi->planes[1] = (unsigned char*)gray_pal;
+ }
+
+ if(mpi->w==mpi->stride[0] && dmpi->w*(dmpi->bpp>>3)==dmpi->stride[0]){
+ // no stride conversion needed
+ switch(IMGFMT_RGB_DEPTH(dmpi->imgfmt)){
+ case 15:
+ case 16:
+ if (IMGFMT_IS_BGR(dmpi->imgfmt))
+ palette8tobgr16(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]);
+ else
+ palette8torgb16(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]);
+ break;
+ case 24:
+ if (IMGFMT_IS_BGR(dmpi->imgfmt))
+ sws_convertPalette8ToPacked24(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]);
+ else
+ sws_convertPalette8ToPacked24(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]);
+ break;
+ case 32:
+ if (IMGFMT_IS_BGR(dmpi->imgfmt))
+ sws_convertPalette8ToPacked32(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]);
+ else
+ sws_convertPalette8ToPacked32(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]);
+ break;
+ }
+ } else {
+ int y;
+ for(y=0;y<mpi->h;y++){
+ unsigned char* src=mpi->planes[0]+y*mpi->stride[0];
+ unsigned char* dst=dmpi->planes[0]+y*dmpi->stride[0];
+ switch(IMGFMT_RGB_DEPTH(dmpi->imgfmt)){
+ case 15:
+ case 16:
+ if (IMGFMT_IS_BGR(dmpi->imgfmt))
+ palette8tobgr16(src,dst,mpi->w,mpi->planes[1]);
+ else
+ palette8torgb16(src,dst,mpi->w,mpi->planes[1]);
+ break;
+ case 24:
+ if (IMGFMT_IS_BGR(dmpi->imgfmt))
+ sws_convertPalette8ToPacked24(src,dst,mpi->w,mpi->planes[1]);
+ else
+ sws_convertPalette8ToPacked24(src,dst,mpi->w,mpi->planes[1]);
+ break;
+ case 32:
+ if (IMGFMT_IS_BGR(dmpi->imgfmt))
+ sws_convertPalette8ToPacked32(src,dst,mpi->w,mpi->planes[1]);
+ else
+ sws_convertPalette8ToPacked32(src,dst,mpi->w,mpi->planes[1]);
+ break;
+ }
+ }
+ }
+ mpi->planes[1] = old_palette;
+
+ return vf_next_put_image(vf,dmpi, pts);
+}
+
+//===========================================================================//
+
+static int query_format(struct vf_instance *vf, unsigned int fmt){
+ int best=find_best(vf,fmt);
+ if(!best) return 0; // no match
+ return vf->next->query_format(vf->next,best);
+}
+
+static void uninit(vf_instance_t *vf) {
+ free(vf->priv);
+}
+
+static int vf_open(vf_instance_t *vf, char *args){
+ unsigned int i;
+ vf->config=config;
+ vf->uninit=uninit;
+ vf->put_image=put_image;
+ vf->query_format=query_format;
+ vf->priv=malloc(sizeof(struct vf_priv_s));
+ memset(vf->priv, 0, sizeof(struct vf_priv_s));
+ for(i=0;i<256;i++) gray_pal[i]=0x01010101*i;
+ if (args)
+ {
+ if (!strcasecmp(args,"rgb15")) vf->priv->fmt=IMGFMT_RGB15; else
+ if (!strcasecmp(args,"rgb16")) vf->priv->fmt=IMGFMT_RGB16; else
+ if (!strcasecmp(args,"rgb24")) vf->priv->fmt=IMGFMT_RGB24; else
+ if (!strcasecmp(args,"rgb32")) vf->priv->fmt=IMGFMT_RGB32; else
+ if (!strcasecmp(args,"bgr15")) vf->priv->fmt=IMGFMT_BGR15; else
+ if (!strcasecmp(args,"bgr16")) vf->priv->fmt=IMGFMT_BGR16; else
+ if (!strcasecmp(args,"bgr24")) vf->priv->fmt=IMGFMT_BGR24; else
+ if (!strcasecmp(args,"bgr32")) vf->priv->fmt=IMGFMT_BGR32; else
+ {
+ mp_msg(MSGT_VFILTER, MSGL_WARN, MSGTR_MPCODECS_UnknownFormatName, args);
+ return 0;
+ }
+ }
+ return 1;
+}
+
+const vf_info_t vf_info_palette = {
+ "8bpp indexed (using palette) -> BGR 15/16/24/32 conversion",
+ "palette",
+ "A'rpi & Alex",
+ "",
+ vf_open,
+ NULL
+};
+
+//===========================================================================//
diff --git a/libavfilter/libmpcodecs/vf_perspective.c b/libavfilter/libmpcodecs/vf_perspective.c
new file mode 100644
index 0000000000..f5a9d6be36
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_perspective.c
@@ -0,0 +1,345 @@
+/*
+ * Copyright (C) 2002 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+#include <assert.h>
+#include <math.h>
+
+#include "config.h"
+#include "mp_msg.h"
+
+#if HAVE_MALLOC_H
+#include <malloc.h>
+#endif
+
+#include "libavutil/mem.h"
+
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+
+#define SUB_PIXEL_BITS 8
+#define SUB_PIXELS (1<<SUB_PIXEL_BITS)
+#define COEFF_BITS 11
+
+//===========================================================================//
+
+struct vf_priv_s {
+ double ref[4][2];
+ int32_t coeff[1<<SUB_PIXEL_BITS][4];
+ int32_t (*pv)[2];
+ int pvStride;
+ int cubic;
+};
+
+
+/***************************************************************************/
+
+static void initPv(struct vf_priv_s *priv, int W, int H){
+ double a,b,c,d,e,f,g,h,D;
+ double (*ref)[2]= priv->ref;
+ int x,y;
+
+ g= ( (ref[0][0] - ref[1][0] - ref[2][0] + ref[3][0])*(ref[2][1] - ref[3][1])
+ - (ref[0][1] - ref[1][1] - ref[2][1] + ref[3][1])*(ref[2][0] - ref[3][0]))*H;
+ h= ( (ref[0][1] - ref[1][1] - ref[2][1] + ref[3][1])*(ref[1][0] - ref[3][0])
+ - (ref[0][0] - ref[1][0] - ref[2][0] + ref[3][0])*(ref[1][1] - ref[3][1]))*W;
+ D= (ref[1][0] - ref[3][0])*(ref[2][1] - ref[3][1])
+ - (ref[2][0] - ref[3][0])*(ref[1][1] - ref[3][1]);
+
+ a= D*(ref[1][0] - ref[0][0])*H + g*ref[1][0];
+ b= D*(ref[2][0] - ref[0][0])*W + h*ref[2][0];
+ c= D*ref[0][0]*W*H;
+ d= D*(ref[1][1] - ref[0][1])*H + g*ref[1][1];
+ e= D*(ref[2][1] - ref[0][1])*W + h*ref[2][1];
+ f= D*ref[0][1]*W*H;
+
+ for(y=0; y<H; y++){
+ for(x=0; x<W; x++){
+ int u, v;
+
+ u= (int)floor( SUB_PIXELS*(a*x + b*y + c)/(g*x + h*y + D*W*H) + 0.5);
+ v= (int)floor( SUB_PIXELS*(d*x + e*y + f)/(g*x + h*y + D*W*H) + 0.5);
+
+ priv->pv[x + y*W][0]= u;
+ priv->pv[x + y*W][1]= v;
+ }
+ }
+}
+
+static double getCoeff(double d){
+ double A= -0.60;
+ double coeff;
+
+ d= fabs(d);
+
+ // Equation is from VirtualDub
+ if(d<1.0)
+ coeff = (1.0 - (A+3.0)*d*d + (A+2.0)*d*d*d);
+ else if(d<2.0)
+ coeff = (-4.0*A + 8.0*A*d - 5.0*A*d*d + A*d*d*d);
+ else
+ coeff=0.0;
+
+ return coeff;
+}
+
+static int config(struct vf_instance *vf,
+ int width, int height, int d_width, int d_height,
+ unsigned int flags, unsigned int outfmt){
+ int i, j;
+
+ vf->priv->pvStride= width;
+ vf->priv->pv= av_malloc(width*height*2*sizeof(int32_t));
+ initPv(vf->priv, width, height);
+
+ for(i=0; i<SUB_PIXELS; i++){
+ double d= i/(double)SUB_PIXELS;
+ double temp[4];
+ double sum=0;
+
+ for(j=0; j<4; j++)
+ temp[j]= getCoeff(j - d - 1);
+
+ for(j=0; j<4; j++)
+ sum+= temp[j];
+
+ for(j=0; j<4; j++)
+ vf->priv->coeff[i][j]= (int)floor((1<<COEFF_BITS)*temp[j]/sum + 0.5);
+ }
+
+ return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
+}
+
+static void uninit(struct vf_instance *vf){
+ if(!vf->priv) return;
+
+ av_free(vf->priv->pv);
+ vf->priv->pv= NULL;
+
+ free(vf->priv);
+ vf->priv=NULL;
+}
+
+static inline void resampleCubic(uint8_t *dst, uint8_t *src, int w, int h, int dstStride, int srcStride, struct vf_priv_s *privParam, int xShift, int yShift){
+ int x, y;
+ struct vf_priv_s priv= *privParam;
+
+ for(y=0; y<h; y++){
+ for(x=0; x<w; x++){
+ int u, v, subU, subV, sum, sx, sy;
+
+ sx= x << xShift;
+ sy= y << yShift;
+ u= priv.pv[sx + sy*priv.pvStride][0]>>xShift;
+ v= priv.pv[sx + sy*priv.pvStride][1]>>yShift;
+ subU= u & (SUB_PIXELS-1);
+ subV= v & (SUB_PIXELS-1);
+ u >>= SUB_PIXEL_BITS;
+ v >>= SUB_PIXEL_BITS;
+
+ if(u>0 && v>0 && u<w-2 && v<h-2){
+ const int index= u + v*srcStride;
+ const int a= priv.coeff[subU][0];
+ const int b= priv.coeff[subU][1];
+ const int c= priv.coeff[subU][2];
+ const int d= priv.coeff[subU][3];
+
+ sum=
+ priv.coeff[subV][0]*( a*src[index - 1 - srcStride] + b*src[index - 0 - srcStride]
+ + c*src[index + 1 - srcStride] + d*src[index + 2 - srcStride])
+ +priv.coeff[subV][1]*( a*src[index - 1 ] + b*src[index - 0 ]
+ + c*src[index + 1 ] + d*src[index + 2 ])
+ +priv.coeff[subV][2]*( a*src[index - 1 + srcStride] + b*src[index - 0 + srcStride]
+ + c*src[index + 1 + srcStride] + d*src[index + 2 + srcStride])
+ +priv.coeff[subV][3]*( a*src[index - 1+2*srcStride] + b*src[index - 0+2*srcStride]
+ + c*src[index + 1+2*srcStride] + d*src[index + 2+2*srcStride]);
+ }else{
+ int dx, dy;
+ sum=0;
+
+ for(dy=0; dy<4; dy++){
+ int iy= v + dy - 1;
+ if (iy< 0) iy=0;
+ else if(iy>=h) iy=h-1;
+ for(dx=0; dx<4; dx++){
+ int ix= u + dx - 1;
+ if (ix< 0) ix=0;
+ else if(ix>=w) ix=w-1;
+
+ sum+= priv.coeff[subU][dx]*priv.coeff[subV][dy]
+ *src[ ix + iy*srcStride];
+ }
+ }
+ }
+ sum= (sum + (1<<(COEFF_BITS*2-1)) ) >> (COEFF_BITS*2);
+ if(sum&~255){
+ if(sum<0) sum=0;
+ else sum=255;
+ }
+ dst[ x + y*dstStride]= sum;
+ }
+ }
+}
+
+static inline void resampleLinear(uint8_t *dst, uint8_t *src, int w, int h, int dstStride, int srcStride,
+ struct vf_priv_s *privParam, int xShift, int yShift){
+ int x, y;
+ struct vf_priv_s priv= *privParam;
+
+ for(y=0; y<h; y++){
+ for(x=0; x<w; x++){
+ int u, v, subU, subV, sum, sx, sy, index, subUI, subVI;
+
+ sx= x << xShift;
+ sy= y << yShift;
+ u= priv.pv[sx + sy*priv.pvStride][0]>>xShift;
+ v= priv.pv[sx + sy*priv.pvStride][1]>>yShift;
+ subU= u & (SUB_PIXELS-1);
+ subV= v & (SUB_PIXELS-1);
+ u >>= SUB_PIXEL_BITS;
+ v >>= SUB_PIXEL_BITS;
+ index= u + v*srcStride;
+ subUI= SUB_PIXELS - subU;
+ subVI= SUB_PIXELS - subV;
+
+ if((unsigned)u < (unsigned)(w - 1)){
+ if((unsigned)v < (unsigned)(h - 1)){
+ sum= subVI*(subUI*src[index ] + subU*src[index +1])
+ +subV *(subUI*src[index+srcStride] + subU*src[index+srcStride+1]);
+ sum= (sum + (1<<(SUB_PIXEL_BITS*2-1)) ) >> (SUB_PIXEL_BITS*2);
+ }else{
+ if(v<0) v= 0;
+ else v= h-1;
+ index= u + v*srcStride;
+ sum= subUI*src[index] + subU*src[index+1];
+ sum= (sum + (1<<(SUB_PIXEL_BITS-1)) ) >> SUB_PIXEL_BITS;
+ }
+ }else{
+ if((unsigned)v < (unsigned)(h - 1)){
+ if(u<0) u= 0;
+ else u= w-1;
+ index= u + v*srcStride;
+ sum= subVI*src[index] + subV*src[index+srcStride];
+ sum= (sum + (1<<(SUB_PIXEL_BITS-1)) ) >> SUB_PIXEL_BITS;
+ }else{
+ if(u<0) u= 0;
+ else u= w-1;
+ if(v<0) v= 0;
+ else v= h-1;
+ index= u + v*srcStride;
+ sum= src[index];
+ }
+ }
+ if(sum&~255){
+ if(sum<0) sum=0;
+ else sum=255;
+ }
+ dst[ x + y*dstStride]= sum;
+ }
+ }
+}
+
+static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
+ int cw= mpi->w >> mpi->chroma_x_shift;
+ int ch= mpi->h >> mpi->chroma_y_shift;
+
+ mp_image_t *dmpi=vf_get_image(vf->next,mpi->imgfmt,
+ MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
+ mpi->w,mpi->h);
+
+ assert(mpi->flags&MP_IMGFLAG_PLANAR);
+
+ if(vf->priv->cubic){
+ resampleCubic(dmpi->planes[0], mpi->planes[0], mpi->w,mpi->h, dmpi->stride[0], mpi->stride[0],
+ vf->priv, 0, 0);
+ resampleCubic(dmpi->planes[1], mpi->planes[1], cw , ch , dmpi->stride[1], mpi->stride[1],
+ vf->priv, mpi->chroma_x_shift, mpi->chroma_y_shift);
+ resampleCubic(dmpi->planes[2], mpi->planes[2], cw , ch , dmpi->stride[2], mpi->stride[2],
+ vf->priv, mpi->chroma_x_shift, mpi->chroma_y_shift);
+ }else{
+ resampleLinear(dmpi->planes[0], mpi->planes[0], mpi->w,mpi->h, dmpi->stride[0], mpi->stride[0],
+ vf->priv, 0, 0);
+ resampleLinear(dmpi->planes[1], mpi->planes[1], cw , ch , dmpi->stride[1], mpi->stride[1],
+ vf->priv, mpi->chroma_x_shift, mpi->chroma_y_shift);
+ resampleLinear(dmpi->planes[2], mpi->planes[2], cw , ch , dmpi->stride[2], mpi->stride[2],
+ vf->priv, mpi->chroma_x_shift, mpi->chroma_y_shift);
+ }
+
+ return vf_next_put_image(vf,dmpi, pts);
+}
+
+//===========================================================================//
+
+static int query_format(struct vf_instance *vf, unsigned int fmt){
+ switch(fmt)
+ {
+ case IMGFMT_YV12:
+ case IMGFMT_I420:
+ case IMGFMT_IYUV:
+ case IMGFMT_YVU9:
+ case IMGFMT_444P:
+ case IMGFMT_422P:
+ case IMGFMT_411P:
+ return vf_next_query_format(vf, fmt);
+ }
+ return 0;
+}
+
+static int vf_open(vf_instance_t *vf, char *args){
+ int e;
+
+ vf->config=config;
+ vf->put_image=put_image;
+// vf->get_image=get_image;
+ vf->query_format=query_format;
+ vf->uninit=uninit;
+ vf->priv=malloc(sizeof(struct vf_priv_s));
+ memset(vf->priv, 0, sizeof(struct vf_priv_s));
+
+ if(args==NULL) return 0;
+
+ e=sscanf(args, "%lf:%lf:%lf:%lf:%lf:%lf:%lf:%lf:%d",
+ &vf->priv->ref[0][0], &vf->priv->ref[0][1],
+ &vf->priv->ref[1][0], &vf->priv->ref[1][1],
+ &vf->priv->ref[2][0], &vf->priv->ref[2][1],
+ &vf->priv->ref[3][0], &vf->priv->ref[3][1],
+ &vf->priv->cubic
+ );
+
+ if(e!=9)
+ return 0;
+
+ return 1;
+}
+
+const vf_info_t vf_info_perspective = {
+ "perspective correcture",
+ "perspective",
+ "Michael Niedermayer",
+ "",
+ vf_open,
+ NULL
+};
+
+//===========================================================================//
diff --git a/libavfilter/libmpcodecs/vf_phase.c b/libavfilter/libmpcodecs/vf_phase.c
new file mode 100644
index 0000000000..7dd642ebc0
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_phase.c
@@ -0,0 +1,301 @@
+/*
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
+
+#include "config.h"
+#include "mp_msg.h"
+
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+
+#include "libvo/fastmemcpy.h"
+
+enum mode { PROGRESSIVE, TOP_FIRST, BOTTOM_FIRST,
+ TOP_FIRST_ANALYZE, BOTTOM_FIRST_ANALYZE,
+ ANALYZE, FULL_ANALYZE, AUTO, AUTO_ANALYZE };
+
+#define fixed_mode(p) ((p)<=BOTTOM_FIRST)
+
+struct vf_priv_s
+ {
+ enum mode mode;
+ int verbose;
+ unsigned char *buf[3];
+ };
+
+/*
+ * Copy fields from either current or buffered previous frame to the
+ * output and store the current frame unmodified to the buffer.
+ */
+
+static void do_plane(unsigned char *to, unsigned char *from,
+ int w, int h, int ts, int fs,
+ unsigned char **bufp, enum mode mode)
+ {
+ unsigned char *buf, *end;
+ int top;
+
+ if(!*bufp)
+ {
+ mode=PROGRESSIVE;
+ if(!(*bufp=malloc(h*w))) return;
+ }
+
+ for(end=to+h*ts, buf=*bufp, top=1; to<end; from+=fs, to+=ts, buf+=w, top^=1)
+ {
+ fast_memcpy(to, mode==(top?BOTTOM_FIRST:TOP_FIRST)?buf:from, w);
+ fast_memcpy(buf, from, w);
+ }
+ }
+
+/*
+ * This macro interpolates the value of both fields at a point halfway
+ * between lines and takes the squared difference. In field resolution
+ * the point is a quarter pixel below a line in one field and a quarter
+ * pixel above a line in other.
+ *
+ * (the result is actually multiplied by 25)
+ */
+
+#define diff(a, as, b, bs) (t=((*a-b[bs])<<2)+a[as<<1]-b[-bs], t*t)
+
+/*
+ * Find which field combination has the smallest average squared difference
+ * between the fields.
+ */
+
+static enum mode analyze_plane(unsigned char *old, unsigned char *new,
+ int w, int h, int os, int ns, enum mode mode,
+ int verbose, int fields)
+ {
+ double bdiff, pdiff, tdiff, scale;
+ int bdif, tdif, pdif;
+ int top, t;
+ unsigned char *end, *rend;
+
+ if(mode==AUTO)
+ mode=fields&MP_IMGFIELD_ORDERED?fields&MP_IMGFIELD_TOP_FIRST?
+ TOP_FIRST:BOTTOM_FIRST:PROGRESSIVE;
+ else if(mode==AUTO_ANALYZE)
+ mode=fields&MP_IMGFIELD_ORDERED?fields&MP_IMGFIELD_TOP_FIRST?
+ TOP_FIRST_ANALYZE:BOTTOM_FIRST_ANALYZE:FULL_ANALYZE;
+
+ if(fixed_mode(mode))
+ bdiff=pdiff=tdiff=65536.0;
+ else
+ {
+ bdiff=pdiff=tdiff=0.0;
+
+ for(end=new+(h-2)*ns, new+=ns, old+=os, top=0;
+ new<end; new+=ns-w, old+=os-w, top^=1)
+ {
+ pdif=tdif=bdif=0;
+
+ switch(mode)
+ {
+ case TOP_FIRST_ANALYZE:
+ if(top)
+ for(rend=new+w; new<rend; new++, old++)
+ pdif+=diff(new, ns, new, ns),
+ tdif+=diff(new, ns, old, os);
+ else
+ for(rend=new+w; new<rend; new++, old++)
+ pdif+=diff(new, ns, new, ns),
+ tdif+=diff(old, os, new, ns);
+ break;
+
+ case BOTTOM_FIRST_ANALYZE:
+ if(top)
+ for(rend=new+w; new<rend; new++, old++)
+ pdif+=diff(new, ns, new, ns),
+ bdif+=diff(old, os, new, ns);
+ else
+ for(rend=new+w; new<rend; new++, old++)
+ pdif+=diff(new, ns, new, ns),
+ bdif+=diff(new, ns, old, os);
+ break;
+
+ case ANALYZE:
+ if(top)
+ for(rend=new+w; new<rend; new++, old++)
+ tdif+=diff(new, ns, old, os),
+ bdif+=diff(old, os, new, ns);
+ else
+ for(rend=new+w; new<rend; new++, old++)
+ bdif+=diff(new, ns, old, os),
+ tdif+=diff(old, os, new, ns);
+ break;
+
+ default: /* FULL_ANALYZE */
+ if(top)
+ for(rend=new+w; new<rend; new++, old++)
+ pdif+=diff(new, ns, new, ns),
+ tdif+=diff(new, ns, old, os),
+ bdif+=diff(old, os, new, ns);
+ else
+ for(rend=new+w; new<rend; new++, old++)
+ pdif+=diff(new, ns, new, ns),
+ bdif+=diff(new, ns, old, os),
+ tdif+=diff(old, os, new, ns);
+ }
+
+ pdiff+=(double)pdif;
+ tdiff+=(double)tdif;
+ bdiff+=(double)bdif;
+ }
+
+ scale=1.0/(w*(h-3))/25.0;
+ pdiff*=scale;
+ tdiff*=scale;
+ bdiff*=scale;
+
+ if(mode==TOP_FIRST_ANALYZE)
+ bdiff=65536.0;
+ else if(mode==BOTTOM_FIRST_ANALYZE)
+ tdiff=65536.0;
+ else if(mode==ANALYZE)
+ pdiff=65536.0;
+
+ if(bdiff<pdiff && bdiff<tdiff)
+ mode=BOTTOM_FIRST;
+ else if(tdiff<pdiff && tdiff<bdiff)
+ mode=TOP_FIRST;
+ else
+ mode=PROGRESSIVE;
+ }
+
+ if( mp_msg_test(MSGT_VFILTER,MSGL_V) )
+ {
+ mp_msg(MSGT_VFILTER, MSGL_INFO, "%c", mode==BOTTOM_FIRST?'b':mode==TOP_FIRST?'t':'p');
+ if(tdiff==65536.0) mp_msg(MSGT_VFILTER, MSGL_INFO," N/A "); else mp_msg(MSGT_VFILTER, MSGL_INFO," %8.2f", tdiff);
+ if(bdiff==65536.0) mp_msg(MSGT_VFILTER, MSGL_INFO," N/A "); else mp_msg(MSGT_VFILTER, MSGL_INFO," %8.2f", bdiff);
+ if(pdiff==65536.0) mp_msg(MSGT_VFILTER, MSGL_INFO," N/A "); else mp_msg(MSGT_VFILTER, MSGL_INFO," %8.2f", pdiff);
+ mp_msg(MSGT_VFILTER, MSGL_INFO," \n");
+ }
+
+ return mode;
+ }
+
+static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
+ {
+ mp_image_t *dmpi;
+ int w;
+ enum mode mode;
+
+ if(!(dmpi=vf_get_image(vf->next, mpi->imgfmt,
+ MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
+ mpi->w, mpi->h)))
+ return 0;
+
+ w=dmpi->w;
+ if(!(dmpi->flags&MP_IMGFLAG_PLANAR))
+ w*=dmpi->bpp/8;
+
+ mode=vf->priv->mode;
+
+ if(!vf->priv->buf[0])
+ mode=PROGRESSIVE;
+ else
+ mode=analyze_plane(vf->priv->buf[0], mpi->planes[0],
+ w, dmpi->h, w, mpi->stride[0], mode,
+ vf->priv->verbose, mpi->fields);
+
+ do_plane(dmpi->planes[0], mpi->planes[0],
+ w, dmpi->h,
+ dmpi->stride[0], mpi->stride[0],
+ &vf->priv->buf[0], mode);
+
+ if(dmpi->flags&MP_IMGFLAG_PLANAR)
+ {
+ do_plane(dmpi->planes[1], mpi->planes[1],
+ dmpi->chroma_width, dmpi->chroma_height,
+ dmpi->stride[1], mpi->stride[1],
+ &vf->priv->buf[1], mode);
+ do_plane(dmpi->planes[2], mpi->planes[2],
+ dmpi->chroma_width, dmpi->chroma_height,
+ dmpi->stride[2], mpi->stride[2],
+ &vf->priv->buf[2], mode);
+ }
+
+ return vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE);
+ }
+
+static void uninit(struct vf_instance *vf)
+ {
+ free(vf->priv->buf[0]);
+ free(vf->priv->buf[1]);
+ free(vf->priv->buf[2]);
+ free(vf->priv);
+ }
+
+static int vf_open(vf_instance_t *vf, char *args)
+ {
+ vf->put_image = put_image;
+ vf->uninit = uninit;
+ vf->default_reqs = VFCAP_ACCEPT_STRIDE;
+
+ if(!(vf->priv = calloc(1, sizeof(struct vf_priv_s))))
+ {
+ uninit(vf);
+ return 0;
+ }
+
+ vf->priv->mode=AUTO_ANALYZE;
+ vf->priv->verbose=0;
+
+ while(args && *args)
+ {
+ switch(*args)
+ {
+ case 't': vf->priv->mode=TOP_FIRST; break;
+ case 'a': vf->priv->mode=AUTO; break;
+ case 'b': vf->priv->mode=BOTTOM_FIRST; break;
+ case 'u': vf->priv->mode=ANALYZE; break;
+ case 'T': vf->priv->mode=TOP_FIRST_ANALYZE; break;
+ case 'A': vf->priv->mode=AUTO_ANALYZE; break;
+ case 'B': vf->priv->mode=BOTTOM_FIRST_ANALYZE; break;
+ case 'U': vf->priv->mode=FULL_ANALYZE; break;
+ case 'p': vf->priv->mode=PROGRESSIVE; break;
+ case 'v': vf->priv->verbose=1; break;
+ case ':': break;
+
+ default:
+ uninit(vf);
+ return 0; /* bad args */
+ }
+
+ if( (args=strchr(args, ':')) ) args++;
+ }
+
+ return 1;
+ }
+
+const vf_info_t vf_info_phase =
+ {
+ "phase shift fields",
+ "phase",
+ "Ville Saari",
+ "",
+ vf_open,
+ NULL
+ };
diff --git a/libavfilter/libmpcodecs/vf_pp7.c b/libavfilter/libmpcodecs/vf_pp7.c
new file mode 100644
index 0000000000..eae30bf7a1
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_pp7.c
@@ -0,0 +1,493 @@
+/*
+ * Copyright (C) 2005 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+#include <math.h>
+
+#include "config.h"
+
+#include "mp_msg.h"
+#include "cpudetect.h"
+
+#if HAVE_MALLOC_H
+#include <malloc.h>
+#endif
+
+#include "libavutil/mem.h"
+
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+#include "libvo/fastmemcpy.h"
+
+#define XMIN(a,b) ((a) < (b) ? (a) : (b))
+#define XMAX(a,b) ((a) > (b) ? (a) : (b))
+
+typedef short DCTELEM;
+
+//===========================================================================//
+static const uint8_t __attribute__((aligned(8))) dither[8][8]={
+{ 0, 48, 12, 60, 3, 51, 15, 63, },
+{ 32, 16, 44, 28, 35, 19, 47, 31, },
+{ 8, 56, 4, 52, 11, 59, 7, 55, },
+{ 40, 24, 36, 20, 43, 27, 39, 23, },
+{ 2, 50, 14, 62, 1, 49, 13, 61, },
+{ 34, 18, 46, 30, 33, 17, 45, 29, },
+{ 10, 58, 6, 54, 9, 57, 5, 53, },
+{ 42, 26, 38, 22, 41, 25, 37, 21, },
+};
+
+struct vf_priv_s {
+ int qp;
+ int mode;
+ int mpeg2;
+ int temp_stride;
+ uint8_t *src;
+};
+#if 0
+static inline void dct7_c(DCTELEM *dst, int s0, int s1, int s2, int s3, int step){
+ int s, d;
+ int dst2[64];
+//#define S0 (1024/0.37796447300922719759)
+#define C0 ((int)(1024*0.37796447300922719759+0.5)) //sqrt(1/7)
+#define C1 ((int)(1024*0.53452248382484879308/6+0.5)) //sqrt(2/7)/6
+
+#define C2 ((int)(1024*0.45221175985034745004/2+0.5))
+#define C3 ((int)(1024*0.36264567479870879474/2+0.5))
+
+//0.1962505182412941918 0.0149276808419397944-0.2111781990832339584
+#define C4 ((int)(1024*0.1962505182412941918+0.5))
+#define C5 ((int)(1024*0.0149276808419397944+0.5))
+//#define C6 ((int)(1024*0.2111781990832339584+0.5))
+#if 0
+ s= s0 + s1 + s2;
+ dst[0*step] = ((s + s3)*C0 + 512) >> 10;
+ s= (s - 6*s3)*C1 + 512;
+ d= (s0-s2)*C4 + (s1-s2)*C5;
+ dst[1*step] = (s + 2*d)>>10;
+ s -= d;
+ d= (s1-s0)*C2 + (s1-s2)*C3;
+ dst[2*step] = (s + d)>>10;
+ dst[3*step] = (s - d)>>10;
+#elif 1
+ s = s3+s3;
+ s3= s-s0;
+ s0= s+s0;
+ s = s2+s1;
+ s2= s2-s1;
+ dst[0*step]= s0 + s;
+ dst[2*step]= s0 - s;
+ dst[1*step]= 2*s3 + s2;
+ dst[3*step]= s3 - 2*s2;
+#else
+ int i,j,n=7;
+ for(i=0; i<7; i+=2){
+ dst2[i*step/2]= 0;
+ for(j=0; j<4; j++)
+ dst2[i*step/2] += src[j*step] * cos(i*M_PI/n*(j+0.5)) * sqrt((i?2.0:1.0)/n);
+ if(fabs(dst2[i*step/2] - dst[i*step/2]) > 20)
+ printf("%d %d %d (%d %d %d %d) -> (%d %d %d %d)\n", i,dst2[i*step/2], dst[i*step/2],src[0*step], src[1*step], src[2*step], src[3*step], dst[0*step], dst[1*step],dst[2*step],dst[3*step]);
+ }
+#endif
+}
+#endif
+
+static inline void dctA_c(DCTELEM *dst, uint8_t *src, int stride){
+ int i;
+
+ for(i=0; i<4; i++){
+ int s0= src[0*stride] + src[6*stride];
+ int s1= src[1*stride] + src[5*stride];
+ int s2= src[2*stride] + src[4*stride];
+ int s3= src[3*stride];
+ int s= s3+s3;
+ s3= s-s0;
+ s0= s+s0;
+ s = s2+s1;
+ s2= s2-s1;
+ dst[0]= s0 + s;
+ dst[2]= s0 - s;
+ dst[1]= 2*s3 + s2;
+ dst[3]= s3 - 2*s2;
+ src++;
+ dst+=4;
+ }
+}
+
+static void dctB_c(DCTELEM *dst, DCTELEM *src){
+ int i;
+
+ for(i=0; i<4; i++){
+ int s0= src[0*4] + src[6*4];
+ int s1= src[1*4] + src[5*4];
+ int s2= src[2*4] + src[4*4];
+ int s3= src[3*4];
+ int s= s3+s3;
+ s3= s-s0;
+ s0= s+s0;
+ s = s2+s1;
+ s2= s2-s1;
+ dst[0*4]= s0 + s;
+ dst[2*4]= s0 - s;
+ dst[1*4]= 2*s3 + s2;
+ dst[3*4]= s3 - 2*s2;
+ src++;
+ dst++;
+ }
+}
+
+#if HAVE_MMX
+static void dctB_mmx(DCTELEM *dst, DCTELEM *src){
+ __asm__ volatile (
+ "movq (%0), %%mm0 \n\t"
+ "movq 1*4*2(%0), %%mm1 \n\t"
+ "paddw 6*4*2(%0), %%mm0 \n\t"
+ "paddw 5*4*2(%0), %%mm1 \n\t"
+ "movq 2*4*2(%0), %%mm2 \n\t"
+ "movq 3*4*2(%0), %%mm3 \n\t"
+ "paddw 4*4*2(%0), %%mm2 \n\t"
+ "paddw %%mm3, %%mm3 \n\t" //s
+ "movq %%mm3, %%mm4 \n\t" //s
+ "psubw %%mm0, %%mm3 \n\t" //s-s0
+ "paddw %%mm0, %%mm4 \n\t" //s+s0
+ "movq %%mm2, %%mm0 \n\t" //s2
+ "psubw %%mm1, %%mm2 \n\t" //s2-s1
+ "paddw %%mm1, %%mm0 \n\t" //s2+s1
+ "movq %%mm4, %%mm1 \n\t" //s0'
+ "psubw %%mm0, %%mm4 \n\t" //s0'-s'
+ "paddw %%mm0, %%mm1 \n\t" //s0'+s'
+ "movq %%mm3, %%mm0 \n\t" //s3'
+ "psubw %%mm2, %%mm3 \n\t"
+ "psubw %%mm2, %%mm3 \n\t"
+ "paddw %%mm0, %%mm2 \n\t"
+ "paddw %%mm0, %%mm2 \n\t"
+ "movq %%mm1, (%1) \n\t"
+ "movq %%mm4, 2*4*2(%1) \n\t"
+ "movq %%mm2, 1*4*2(%1) \n\t"
+ "movq %%mm3, 3*4*2(%1) \n\t"
+ :: "r" (src), "r"(dst)
+ );
+}
+#endif
+
+static void (*dctB)(DCTELEM *dst, DCTELEM *src)= dctB_c;
+
+#define N0 4
+#define N1 5
+#define N2 10
+#define SN0 2
+#define SN1 2.2360679775
+#define SN2 3.16227766017
+#define N (1<<16)
+
+static const int factor[16]={
+ N/(N0*N0), N/(N0*N1), N/(N0*N0),N/(N0*N2),
+ N/(N1*N0), N/(N1*N1), N/(N1*N0),N/(N1*N2),
+ N/(N0*N0), N/(N0*N1), N/(N0*N0),N/(N0*N2),
+ N/(N2*N0), N/(N2*N1), N/(N2*N0),N/(N2*N2),
+};
+
+static const int thres[16]={
+ N/(SN0*SN0), N/(SN0*SN2), N/(SN0*SN0),N/(SN0*SN2),
+ N/(SN2*SN0), N/(SN2*SN2), N/(SN2*SN0),N/(SN2*SN2),
+ N/(SN0*SN0), N/(SN0*SN2), N/(SN0*SN0),N/(SN0*SN2),
+ N/(SN2*SN0), N/(SN2*SN2), N/(SN2*SN0),N/(SN2*SN2),
+};
+
+static int thres2[99][16];
+
+static void init_thres2(void){
+ int qp, i;
+ int bias= 0; //FIXME
+
+ for(qp=0; qp<99; qp++){
+ for(i=0; i<16; i++){
+ thres2[qp][i]= ((i&1)?SN2:SN0) * ((i&4)?SN2:SN0) * XMAX(1,qp) * (1<<2) - 1 - bias;
+ }
+ }
+}
+
+static int hardthresh_c(DCTELEM *src, int qp){
+ int i;
+ int a;
+
+ a= src[0] * factor[0];
+ for(i=1; i<16; i++){
+ unsigned int threshold1= thres2[qp][i];
+ unsigned int threshold2= (threshold1<<1);
+ int level= src[i];
+ if(((unsigned)(level+threshold1))>threshold2){
+ a += level * factor[i];
+ }
+ }
+ return (a + (1<<11))>>12;
+}
+
+static int mediumthresh_c(DCTELEM *src, int qp){
+ int i;
+ int a;
+
+ a= src[0] * factor[0];
+ for(i=1; i<16; i++){
+ unsigned int threshold1= thres2[qp][i];
+ unsigned int threshold2= (threshold1<<1);
+ int level= src[i];
+ if(((unsigned)(level+threshold1))>threshold2){
+ if(((unsigned)(level+2*threshold1))>2*threshold2){
+ a += level * factor[i];
+ }else{
+ if(level>0) a+= 2*(level - (int)threshold1)*factor[i];
+ else a+= 2*(level + (int)threshold1)*factor[i];
+ }
+ }
+ }
+ return (a + (1<<11))>>12;
+}
+
+static int softthresh_c(DCTELEM *src, int qp){
+ int i;
+ int a;
+
+ a= src[0] * factor[0];
+ for(i=1; i<16; i++){
+ unsigned int threshold1= thres2[qp][i];
+ unsigned int threshold2= (threshold1<<1);
+ int level= src[i];
+ if(((unsigned)(level+threshold1))>threshold2){
+ if(level>0) a+= (level - (int)threshold1)*factor[i];
+ else a+= (level + (int)threshold1)*factor[i];
+ }
+ }
+ return (a + (1<<11))>>12;
+}
+
+static int (*requantize)(DCTELEM *src, int qp)= hardthresh_c;
+
+static void filter(struct vf_priv_s *p, uint8_t *dst, uint8_t *src, int dst_stride, int src_stride, int width, int height, uint8_t *qp_store, int qp_stride, int is_luma){
+ int x, y;
+ const int stride= is_luma ? p->temp_stride : ((width+16+15)&(~15));
+ uint8_t *p_src= p->src + 8*stride;
+ DCTELEM *block= (DCTELEM *)p->src;
+ DCTELEM *temp= (DCTELEM *)(p->src + 32);
+
+ if (!src || !dst) return; // HACK avoid crash for Y8 colourspace
+ for(y=0; y<height; y++){
+ int index= 8 + 8*stride + y*stride;
+ fast_memcpy(p_src + index, src + y*src_stride, width);
+ for(x=0; x<8; x++){
+ p_src[index - x - 1]= p_src[index + x ];
+ p_src[index + width + x ]= p_src[index + width - x - 1];
+ }
+ }
+ for(y=0; y<8; y++){
+ fast_memcpy(p_src + ( 7-y)*stride, p_src + ( y+8)*stride, stride);
+ fast_memcpy(p_src + (height+8+y)*stride, p_src + (height-y+7)*stride, stride);
+ }
+ //FIXME (try edge emu)
+
+ for(y=0; y<height; y++){
+ for(x=-8; x<0; x+=4){
+ const int index= x + y*stride + (8-3)*(1+stride) + 8; //FIXME silly offset
+ uint8_t *src = p_src + index;
+ DCTELEM *tp= temp+4*x;
+
+ dctA_c(tp+4*8, src, stride);
+ }
+ for(x=0; x<width; ){
+ const int qps= 3 + is_luma;
+ int qp;
+ int end= XMIN(x+8, width);
+
+ if(p->qp)
+ qp= p->qp;
+ else{
+ qp= qp_store[ (XMIN(x, width-1)>>qps) + (XMIN(y, height-1)>>qps) * qp_stride];
+ qp=norm_qscale(qp, p->mpeg2);
+ }
+ for(; x<end; x++){
+ const int index= x + y*stride + (8-3)*(1+stride) + 8; //FIXME silly offset
+ uint8_t *src = p_src + index;
+ DCTELEM *tp= temp+4*x;
+ int v;
+
+ if((x&3)==0)
+ dctA_c(tp+4*8, src, stride);
+
+ dctB(block, tp);
+
+ v= requantize(block, qp);
+ v= (v + dither[y&7][x&7])>>6;
+ if((unsigned)v > 255)
+ v= (-v)>>31;
+ dst[x + y*dst_stride]= v;
+ }
+ }
+ }
+}
+
+static int config(struct vf_instance *vf,
+ int width, int height, int d_width, int d_height,
+ unsigned int flags, unsigned int outfmt){
+ int h= (height+16+15)&(~15);
+
+ vf->priv->temp_stride= (width+16+15)&(~15);
+ vf->priv->src = av_malloc(vf->priv->temp_stride*(h+8)*sizeof(uint8_t));
+
+ return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
+}
+
+static void get_image(struct vf_instance *vf, mp_image_t *mpi){
+ if(mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change
+ // ok, we can do pp in-place (or pp disabled):
+ vf->dmpi=vf_get_image(vf->next,mpi->imgfmt,
+ mpi->type, mpi->flags | MP_IMGFLAG_READABLE, mpi->width, mpi->height);
+ mpi->planes[0]=vf->dmpi->planes[0];
+ mpi->stride[0]=vf->dmpi->stride[0];
+ mpi->width=vf->dmpi->width;
+ if(mpi->flags&MP_IMGFLAG_PLANAR){
+ mpi->planes[1]=vf->dmpi->planes[1];
+ mpi->planes[2]=vf->dmpi->planes[2];
+ mpi->stride[1]=vf->dmpi->stride[1];
+ mpi->stride[2]=vf->dmpi->stride[2];
+ }
+ mpi->flags|=MP_IMGFLAG_DIRECT;
+}
+
+static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
+ mp_image_t *dmpi;
+
+ if(mpi->flags&MP_IMGFLAG_DIRECT){
+ dmpi=vf->dmpi;
+ }else{
+ // no DR, so get a new image! hope we'll get DR buffer:
+ dmpi=vf_get_image(vf->next,mpi->imgfmt,
+ MP_IMGTYPE_TEMP,
+ MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE,
+ mpi->width,mpi->height);
+ vf_clone_mpi_attributes(dmpi, mpi);
+ }
+
+ vf->priv->mpeg2= mpi->qscale_type;
+ if(mpi->qscale || vf->priv->qp){
+ filter(vf->priv, dmpi->planes[0], mpi->planes[0], dmpi->stride[0], mpi->stride[0], mpi->w, mpi->h, mpi->qscale, mpi->qstride, 1);
+ filter(vf->priv, dmpi->planes[1], mpi->planes[1], dmpi->stride[1], mpi->stride[1], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, mpi->qscale, mpi->qstride, 0);
+ filter(vf->priv, dmpi->planes[2], mpi->planes[2], dmpi->stride[2], mpi->stride[2], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, mpi->qscale, mpi->qstride, 0);
+ }else{
+ memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h, dmpi->stride[0], mpi->stride[0]);
+ memcpy_pic(dmpi->planes[1], mpi->planes[1], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, dmpi->stride[1], mpi->stride[1]);
+ memcpy_pic(dmpi->planes[2], mpi->planes[2], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, dmpi->stride[2], mpi->stride[2]);
+ }
+
+#if HAVE_MMX
+ if(gCpuCaps.hasMMX) __asm__ volatile ("emms\n\t");
+#endif
+#if HAVE_MMX2
+ if(gCpuCaps.hasMMX2) __asm__ volatile ("sfence\n\t");
+#endif
+
+ return vf_next_put_image(vf,dmpi, pts);
+}
+
+static void uninit(struct vf_instance *vf){
+ if(!vf->priv) return;
+
+ av_free(vf->priv->src);
+ vf->priv->src= NULL;
+
+ free(vf->priv);
+ vf->priv=NULL;
+}
+
+//===========================================================================//
+static int query_format(struct vf_instance *vf, unsigned int fmt){
+ switch(fmt){
+ case IMGFMT_YVU9:
+ case IMGFMT_IF09:
+ case IMGFMT_YV12:
+ case IMGFMT_I420:
+ case IMGFMT_IYUV:
+ case IMGFMT_CLPL:
+ case IMGFMT_Y800:
+ case IMGFMT_Y8:
+ case IMGFMT_444P:
+ case IMGFMT_422P:
+ case IMGFMT_411P:
+ return vf_next_query_format(vf,fmt);
+ }
+ return 0;
+}
+
+static int control(struct vf_instance *vf, int request, void* data){
+ return vf_next_control(vf,request,data);
+}
+
+static int vf_open(vf_instance_t *vf, char *args){
+ vf->config=config;
+ vf->put_image=put_image;
+ vf->get_image=get_image;
+ vf->query_format=query_format;
+ vf->uninit=uninit;
+ vf->control= control;
+ vf->priv=malloc(sizeof(struct vf_priv_s));
+ memset(vf->priv, 0, sizeof(struct vf_priv_s));
+
+ if (args) sscanf(args, "%d:%d", &vf->priv->qp, &vf->priv->mode);
+
+ if(vf->priv->qp < 0)
+ vf->priv->qp = 0;
+
+ init_thres2();
+
+ switch(vf->priv->mode){
+ case 0: requantize= hardthresh_c; break;
+ case 1: requantize= softthresh_c; break;
+ default:
+ case 2: requantize= mediumthresh_c; break;
+ }
+
+#if HAVE_MMX
+ if(gCpuCaps.hasMMX){
+ dctB= dctB_mmx;
+ }
+#endif
+#if 0
+ if(gCpuCaps.hasMMX){
+ switch(vf->priv->mode){
+ case 0: requantize= hardthresh_mmx; break;
+ case 1: requantize= softthresh_mmx; break;
+ }
+ }
+#endif
+
+ return 1;
+}
+
+const vf_info_t vf_info_pp7 = {
+ "postprocess 7",
+ "pp7",
+ "Michael Niedermayer",
+ "",
+ vf_open,
+ NULL
+};
diff --git a/libavfilter/libmpcodecs/vf_pullup.c b/libavfilter/libmpcodecs/vf_pullup.c
new file mode 100644
index 0000000000..02a2031591
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_pullup.c
@@ -0,0 +1,314 @@
+/*
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "config.h"
+#include "mp_msg.h"
+#include "cpudetect.h"
+
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+
+#include "libvo/fastmemcpy.h"
+
+#include "pullup.h"
+
+#undef MAX
+#define MAX(a,b) ((a)>(b)?(a):(b))
+
+struct vf_priv_s {
+ struct pullup_context *ctx;
+ int init;
+ int fakecount;
+ char *qbuf;
+};
+
+static void init_pullup(struct vf_instance *vf, mp_image_t *mpi)
+{
+ struct pullup_context *c = vf->priv->ctx;
+
+ if (mpi->flags & MP_IMGFLAG_PLANAR) {
+ c->format = PULLUP_FMT_Y;
+ c->nplanes = 4;
+ pullup_preinit_context(c);
+ c->bpp[0] = c->bpp[1] = c->bpp[2] = 8;
+ c->w[0] = mpi->w;
+ c->h[0] = mpi->h;
+ c->w[1] = c->w[2] = mpi->chroma_width;
+ c->h[1] = c->h[2] = mpi->chroma_height;
+ c->w[3] = ((mpi->w+15)/16) * ((mpi->h+15)/16);
+ c->h[3] = 2;
+ c->stride[0] = mpi->width;
+ c->stride[1] = c->stride[2] = mpi->chroma_width;
+ c->stride[3] = c->w[3];
+ c->background[1] = c->background[2] = 128;
+ }
+
+ if (gCpuCaps.hasMMX) c->cpu |= PULLUP_CPU_MMX;
+ if (gCpuCaps.hasMMX2) c->cpu |= PULLUP_CPU_MMX2;
+ if (gCpuCaps.has3DNow) c->cpu |= PULLUP_CPU_3DNOW;
+ if (gCpuCaps.has3DNowExt) c->cpu |= PULLUP_CPU_3DNOWEXT;
+ if (gCpuCaps.hasSSE) c->cpu |= PULLUP_CPU_SSE;
+ if (gCpuCaps.hasSSE2) c->cpu |= PULLUP_CPU_SSE2;
+
+ pullup_init_context(c);
+
+ vf->priv->init = 1;
+ vf->priv->qbuf = malloc(c->w[3]);
+}
+
+
+#if 0
+static void get_image(struct vf_instance *vf, mp_image_t *mpi)
+{
+ struct pullup_context *c = vf->priv->ctx;
+ struct pullup_buffer *b;
+
+ if (mpi->type == MP_IMGTYPE_STATIC) return;
+
+ if (!vf->priv->init) init_pullup(vf, mpi);
+
+ b = pullup_get_buffer(c, 2);
+ if (!b) return; /* shouldn't happen... */
+
+ mpi->priv = b;
+
+ mpi->planes[0] = b->planes[0];
+ mpi->planes[1] = b->planes[1];
+ mpi->planes[2] = b->planes[2];
+ mpi->stride[0] = c->stride[0];
+ mpi->stride[1] = c->stride[1];
+ mpi->stride[2] = c->stride[2];
+
+ mpi->flags |= MP_IMGFLAG_DIRECT;
+ mpi->flags &= ~MP_IMGFLAG_DRAW_CALLBACK;
+}
+#endif
+
+static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
+{
+ struct pullup_context *c = vf->priv->ctx;
+ struct pullup_buffer *b;
+ struct pullup_frame *f;
+ mp_image_t *dmpi;
+ int ret;
+ int p;
+ int i;
+
+ if (!vf->priv->init) init_pullup(vf, mpi);
+
+ if (mpi->flags & MP_IMGFLAG_DIRECT) {
+ b = mpi->priv;
+ mpi->priv = 0;
+ } else {
+ b = pullup_get_buffer(c, 2);
+ if (!b) {
+ mp_msg(MSGT_VFILTER,MSGL_ERR,"Could not get buffer from pullup!\n");
+ f = pullup_get_frame(c);
+ pullup_release_frame(f);
+ return 0;
+ }
+ memcpy_pic(b->planes[0], mpi->planes[0], mpi->w, mpi->h,
+ c->stride[0], mpi->stride[0]);
+ if (mpi->flags & MP_IMGFLAG_PLANAR) {
+ memcpy_pic(b->planes[1], mpi->planes[1],
+ mpi->chroma_width, mpi->chroma_height,
+ c->stride[1], mpi->stride[1]);
+ memcpy_pic(b->planes[2], mpi->planes[2],
+ mpi->chroma_width, mpi->chroma_height,
+ c->stride[2], mpi->stride[2]);
+ }
+ }
+ if (mpi->qscale) {
+ fast_memcpy(b->planes[3], mpi->qscale, c->w[3]);
+ fast_memcpy(b->planes[3]+c->w[3], mpi->qscale, c->w[3]);
+ }
+
+ p = mpi->fields & MP_IMGFIELD_TOP_FIRST ? 0 :
+ (mpi->fields & MP_IMGFIELD_ORDERED ? 1 : 0);
+ pullup_submit_field(c, b, p);
+ pullup_submit_field(c, b, p^1);
+ if (mpi->fields & MP_IMGFIELD_REPEAT_FIRST)
+ pullup_submit_field(c, b, p);
+
+ pullup_release_buffer(b, 2);
+
+ f = pullup_get_frame(c);
+
+ /* Fake yes for first few frames (buffer depth) to keep from
+ * breaking A/V sync with G1's bad architecture... */
+ if (!f) return vf->priv->fakecount ? (--vf->priv->fakecount,1) : 0;
+
+ if (f->length < 2) {
+ pullup_release_frame(f);
+ f = pullup_get_frame(c);
+ if (!f) return 0;
+ if (f->length < 2) {
+ pullup_release_frame(f);
+ if (!(mpi->fields & MP_IMGFIELD_REPEAT_FIRST))
+ return 0;
+ f = pullup_get_frame(c);
+ if (!f) return 0;
+ if (f->length < 2) {
+ pullup_release_frame(f);
+ return 0;
+ }
+ }
+ }
+
+#if 0
+ /* Average qscale tables from both frames. */
+ if (mpi->qscale) {
+ for (i=0; i<c->w[3]; i++) {
+ vf->priv->qbuf[i] = (f->ofields[0]->planes[3][i]
+ + f->ofields[1]->planes[3][i+c->w[3]])>>1;
+ }
+ }
+#else
+ /* Take worst of qscale tables from both frames. */
+ if (mpi->qscale) {
+ for (i=0; i<c->w[3]; i++) {
+ vf->priv->qbuf[i] = MAX(f->ofields[0]->planes[3][i], f->ofields[1]->planes[3][i+c->w[3]]);
+ }
+ }
+#endif
+
+ /* If the frame isn't already exportable... */
+ while (!f->buffer) {
+ dmpi = vf_get_image(vf->next, mpi->imgfmt,
+ MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
+ mpi->width, mpi->height);
+ /* FIXME: Is it ok to discard dmpi if it's not direct? */
+ if (!(dmpi->flags & MP_IMGFLAG_DIRECT)) {
+ pullup_pack_frame(c, f);
+ break;
+ }
+ /* Direct render fields into output buffer */
+ my_memcpy_pic(dmpi->planes[0], f->ofields[0]->planes[0],
+ mpi->w, mpi->h/2, dmpi->stride[0]*2, c->stride[0]*2);
+ my_memcpy_pic(dmpi->planes[0] + dmpi->stride[0],
+ f->ofields[1]->planes[0] + c->stride[0],
+ mpi->w, mpi->h/2, dmpi->stride[0]*2, c->stride[0]*2);
+ if (mpi->flags & MP_IMGFLAG_PLANAR) {
+ my_memcpy_pic(dmpi->planes[1], f->ofields[0]->planes[1],
+ mpi->chroma_width, mpi->chroma_height/2,
+ dmpi->stride[1]*2, c->stride[1]*2);
+ my_memcpy_pic(dmpi->planes[1] + dmpi->stride[1],
+ f->ofields[1]->planes[1] + c->stride[1],
+ mpi->chroma_width, mpi->chroma_height/2,
+ dmpi->stride[1]*2, c->stride[1]*2);
+ my_memcpy_pic(dmpi->planes[2], f->ofields[0]->planes[2],
+ mpi->chroma_width, mpi->chroma_height/2,
+ dmpi->stride[2]*2, c->stride[2]*2);
+ my_memcpy_pic(dmpi->planes[2] + dmpi->stride[2],
+ f->ofields[1]->planes[2] + c->stride[2],
+ mpi->chroma_width, mpi->chroma_height/2,
+ dmpi->stride[2]*2, c->stride[2]*2);
+ }
+ pullup_release_frame(f);
+ if (mpi->qscale) {
+ dmpi->qscale = vf->priv->qbuf;
+ dmpi->qstride = mpi->qstride;
+ dmpi->qscale_type = mpi->qscale_type;
+ }
+ return vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE);
+ }
+ dmpi = vf_get_image(vf->next, mpi->imgfmt,
+ MP_IMGTYPE_EXPORT, MP_IMGFLAG_ACCEPT_STRIDE,
+ mpi->width, mpi->height);
+
+ dmpi->planes[0] = f->buffer->planes[0];
+ dmpi->planes[1] = f->buffer->planes[1];
+ dmpi->planes[2] = f->buffer->planes[2];
+
+ dmpi->stride[0] = c->stride[0];
+ dmpi->stride[1] = c->stride[1];
+ dmpi->stride[2] = c->stride[2];
+
+ if (mpi->qscale) {
+ dmpi->qscale = vf->priv->qbuf;
+ dmpi->qstride = mpi->qstride;
+ dmpi->qscale_type = mpi->qscale_type;
+ }
+ ret = vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE);
+ pullup_release_frame(f);
+ return ret;
+}
+
+static int query_format(struct vf_instance *vf, unsigned int fmt)
+{
+ /* FIXME - support more formats */
+ switch (fmt) {
+ case IMGFMT_YV12:
+ case IMGFMT_IYUV:
+ case IMGFMT_I420:
+ return vf_next_query_format(vf, fmt);
+ }
+ return 0;
+}
+
+static int config(struct vf_instance *vf,
+ int width, int height, int d_width, int d_height,
+ unsigned int flags, unsigned int outfmt)
+{
+ if (height&3) return 0;
+ return vf_next_config(vf, width, height, d_width, d_height, flags, outfmt);
+}
+
+static void uninit(struct vf_instance *vf)
+{
+ pullup_free_context(vf->priv->ctx);
+ free(vf->priv);
+}
+
+static int vf_open(vf_instance_t *vf, char *args)
+{
+ struct vf_priv_s *p;
+ struct pullup_context *c;
+ //vf->get_image = get_image;
+ vf->put_image = put_image;
+ vf->config = config;
+ vf->query_format = query_format;
+ vf->uninit = uninit;
+ vf->default_reqs = VFCAP_ACCEPT_STRIDE;
+ vf->priv = p = calloc(1, sizeof(struct vf_priv_s));
+ p->ctx = c = pullup_alloc_context();
+ p->fakecount = 1;
+ c->verbose = 1;
+ c->junk_left = c->junk_right = 1;
+ c->junk_top = c->junk_bottom = 4;
+ c->strict_breaks = 0;
+ c->metric_plane = 0;
+ if (args) {
+ sscanf(args, "%d:%d:%d:%d:%d:%d", &c->junk_left, &c->junk_right, &c->junk_top, &c->junk_bottom, &c->strict_breaks, &c->metric_plane);
+ }
+ return 1;
+}
+
+const vf_info_t vf_info_pullup = {
+ "pullup (from field sequence to frames)",
+ "pullup",
+ "Rich Felker",
+ "",
+ vf_open,
+ NULL
+};
diff --git a/libavfilter/libmpcodecs/vf_qp.c b/libavfilter/libmpcodecs/vf_qp.c
new file mode 100644
index 0000000000..d74f138662
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_qp.c
@@ -0,0 +1,177 @@
+/*
+ * Copyright (C) 2004 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#include <inttypes.h>
+
+#include "mp_msg.h"
+#include "cpudetect.h"
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+#include "libvo/fastmemcpy.h"
+
+#include "libavcodec/avcodec.h"
+#include "libavutil/eval.h"
+
+
+struct vf_priv_s {
+ char eq[200];
+ int8_t *qp;
+ int8_t lut[257];
+ int qp_stride;
+};
+
+static int config(struct vf_instance *vf,
+ int width, int height, int d_width, int d_height,
+ unsigned int flags, unsigned int outfmt){
+ int h= (height+15)>>4;
+ int i;
+
+ vf->priv->qp_stride= (width+15)>>4;
+ vf->priv->qp= av_malloc(vf->priv->qp_stride*h*sizeof(int8_t));
+
+ for(i=-129; i<128; i++){
+ double const_values[]={
+ M_PI,
+ M_E,
+ i != -129,
+ i,
+ 0
+ };
+ static const char *const_names[]={
+ "PI",
+ "E",
+ "known",
+ "qp",
+ NULL
+ };
+ double temp_val;
+ int res;
+
+ res= av_expr_parse_and_eval(&temp_val, vf->priv->eq, const_names, const_values, NULL, NULL, NULL, NULL, NULL, 0, NULL);
+
+ if (res < 0){
+ mp_msg(MSGT_VFILTER, MSGL_ERR, "qp: Error evaluating \"%s\" \n", vf->priv->eq);
+ return 0;
+ }
+ vf->priv->lut[i+129]= lrintf(temp_val);
+ }
+
+ return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
+}
+
+static void get_image(struct vf_instance *vf, mp_image_t *mpi){
+ if(mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change
+ // ok, we can do pp in-place (or pp disabled):
+ vf->dmpi=vf_get_image(vf->next,mpi->imgfmt,
+ mpi->type, mpi->flags, mpi->w, mpi->h);
+ mpi->planes[0]=vf->dmpi->planes[0];
+ mpi->stride[0]=vf->dmpi->stride[0];
+ mpi->width=vf->dmpi->width;
+ if(mpi->flags&MP_IMGFLAG_PLANAR){
+ mpi->planes[1]=vf->dmpi->planes[1];
+ mpi->planes[2]=vf->dmpi->planes[2];
+ mpi->stride[1]=vf->dmpi->stride[1];
+ mpi->stride[2]=vf->dmpi->stride[2];
+ }
+ mpi->flags|=MP_IMGFLAG_DIRECT;
+}
+
+static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
+ mp_image_t *dmpi;
+ int x,y;
+
+ if(!(mpi->flags&MP_IMGFLAG_DIRECT)){
+ // no DR, so get a new image! hope we'll get DR buffer:
+ vf->dmpi=vf_get_image(vf->next,mpi->imgfmt,
+ MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE,
+ mpi->w,mpi->h);
+ }
+
+ dmpi= vf->dmpi;
+
+ if(!(mpi->flags&MP_IMGFLAG_DIRECT)){
+ memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h, dmpi->stride[0], mpi->stride[0]);
+ if(mpi->flags&MP_IMGFLAG_PLANAR){
+ memcpy_pic(dmpi->planes[1], mpi->planes[1], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, dmpi->stride[1], mpi->stride[1]);
+ memcpy_pic(dmpi->planes[2], mpi->planes[2], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, dmpi->stride[2], mpi->stride[2]);
+ }
+ }
+ vf_clone_mpi_attributes(dmpi, mpi);
+
+ dmpi->qscale = vf->priv->qp;
+ dmpi->qstride= vf->priv->qp_stride;
+ if(mpi->qscale){
+ for(y=0; y<((dmpi->h+15)>>4); y++){
+ for(x=0; x<vf->priv->qp_stride; x++){
+ dmpi->qscale[x + dmpi->qstride*y]=
+ vf->priv->lut[ 129 + ((int8_t)mpi->qscale[x + mpi->qstride*y]) ];
+ }
+ }
+ }else{
+ int qp= vf->priv->lut[0];
+ for(y=0; y<((dmpi->h+15)>>4); y++){
+ for(x=0; x<vf->priv->qp_stride; x++){
+ dmpi->qscale[x + dmpi->qstride*y]= qp;
+ }
+ }
+ }
+
+ return vf_next_put_image(vf,dmpi, pts);
+}
+
+static void uninit(struct vf_instance *vf){
+ if(!vf->priv) return;
+
+ av_free(vf->priv->qp);
+ vf->priv->qp= NULL;
+
+ av_free(vf->priv);
+ vf->priv=NULL;
+}
+
+//===========================================================================//
+static int vf_open(vf_instance_t *vf, char *args){
+ vf->config=config;
+ vf->put_image=put_image;
+ vf->get_image=get_image;
+ vf->uninit=uninit;
+ vf->priv=av_malloc(sizeof(struct vf_priv_s));
+ memset(vf->priv, 0, sizeof(struct vf_priv_s));
+
+// avcodec_init();
+
+ if (args) strncpy(vf->priv->eq, args, 199);
+
+ return 1;
+}
+
+const vf_info_t vf_info_qp = {
+ "QP changer",
+ "qp",
+ "Michael Niedermayer",
+ "",
+ vf_open,
+ NULL
+};
diff --git a/libavfilter/libmpcodecs/vf_rectangle.c b/libavfilter/libmpcodecs/vf_rectangle.c
new file mode 100644
index 0000000000..21bc209de4
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_rectangle.c
@@ -0,0 +1,181 @@
+/*
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "mp_image.h"
+#include "mp_msg.h"
+#include "vf.h"
+
+#include "libvo/fastmemcpy.h"
+#include "libavutil/common.h"
+
+struct vf_priv_s {
+ int x, y, w, h;
+};
+
+static int
+config(struct vf_instance *vf,
+ int width, int height, int d_width, int d_height,
+ unsigned int flags, unsigned int outfmt)
+{
+ if (vf->priv->w < 0 || width < vf->priv->w)
+ vf->priv->w = width;
+ if (vf->priv->h < 0 || height < vf->priv->h)
+ vf->priv->h = height;
+ if (vf->priv->x < 0)
+ vf->priv->x = (width - vf->priv->w) / 2;
+ if (vf->priv->y < 0)
+ vf->priv->y = (height - vf->priv->h) / 2;
+ if (vf->priv->w + vf->priv->x > width
+ || vf->priv->h + vf->priv->y > height) {
+ mp_msg(MSGT_VFILTER,MSGL_WARN,"rectangle: bad position/width/height - rectangle area is out of the original!\n");
+ return 0;
+ }
+ return vf_next_config(vf, width, height, d_width, d_height, flags, outfmt);
+}
+
+static int
+control(struct vf_instance *vf, int request, void *data)
+{
+ const int *const tmp = data;
+ switch(request){
+ case VFCTRL_CHANGE_RECTANGLE:
+ switch (tmp[0]){
+ case 0:
+ vf->priv->w += tmp[1];
+ return 1;
+ break;
+ case 1:
+ vf->priv->h += tmp[1];
+ return 1;
+ break;
+ case 2:
+ vf->priv->x += tmp[1];
+ return 1;
+ break;
+ case 3:
+ vf->priv->y += tmp[1];
+ return 1;
+ break;
+ default:
+ mp_msg(MSGT_VFILTER,MSGL_FATAL,"Unknown param %d \n", tmp[0]);
+ return 0;
+ }
+ }
+ return vf_next_control(vf, request, data);
+ return 0;
+}
+static int
+put_image(struct vf_instance *vf, mp_image_t* mpi, double pts){
+ mp_image_t* dmpi;
+ unsigned int bpp = mpi->bpp / 8;
+ int x, y, w, h;
+ dmpi = vf_get_image(vf->next, mpi->imgfmt, MP_IMGTYPE_TEMP,
+ MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_PREFER_ALIGNED_STRIDE,
+ mpi->w, mpi->h);
+
+ memcpy_pic(dmpi->planes[0],mpi->planes[0],mpi->w*bpp, mpi->h,
+ dmpi->stride[0],mpi->stride[0]);
+ if(mpi->flags&MP_IMGFLAG_PLANAR && mpi->flags&MP_IMGFLAG_YUV){
+ memcpy_pic(dmpi->planes[1],mpi->planes[1],
+ mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift,
+ dmpi->stride[1],mpi->stride[1]);
+ memcpy_pic(dmpi->planes[2],mpi->planes[2],
+ mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift,
+ dmpi->stride[2],mpi->stride[2]);
+ }
+
+ /* Draw the rectangle */
+
+ mp_msg(MSGT_VFILTER,MSGL_INFO, "rectangle: -vf rectangle=%d:%d:%d:%d \n", vf->priv->w, vf->priv->h, vf->priv->x, vf->priv->y);
+
+ x = FFMIN(vf->priv->x, dmpi->width);
+ x = FFMAX(x, 0);
+
+ w = vf->priv->x + vf->priv->w - 1 - x;
+ w = FFMIN(w, dmpi->width - x);
+ w = FFMAX(w, 0);
+
+ y = FFMIN(vf->priv->y, dmpi->height);
+ y = FFMAX(y, 0);
+
+ h = vf->priv->y + vf->priv->h - 1 - y;
+ h = FFMIN(h, dmpi->height - y);
+ h = FFMAX(h, 0);
+
+ if (0 <= vf->priv->y && vf->priv->y <= dmpi->height) {
+ unsigned char *p = dmpi->planes[0] + y * dmpi->stride[0] + x * bpp;
+ unsigned int count = w * bpp;
+ while (count--)
+ p[count] = 0xff - p[count];
+ }
+ if (h != 1 && vf->priv->y + vf->priv->h - 1 <= mpi->height) {
+ unsigned char *p = dmpi->planes[0] + (vf->priv->y + vf->priv->h - 1) * dmpi->stride[0] + x * bpp;
+ unsigned int count = w * bpp;
+ while (count--)
+ p[count] = 0xff - p[count];
+ }
+ if (0 <= vf->priv->x && vf->priv->x <= dmpi->width) {
+ unsigned char *p = dmpi->planes[0] + y * dmpi->stride[0] + x * bpp;
+ unsigned int count = h;
+ while (count--) {
+ unsigned int i = bpp;
+ while (i--)
+ p[i] = 0xff - p[i];
+ p += dmpi->stride[0];
+ }
+ }
+ if (w != 1 && vf->priv->x + vf->priv->w - 1 <= mpi->width) {
+ unsigned char *p = dmpi->planes[0] + y * dmpi->stride[0] + (vf->priv->x + vf->priv->w - 1) * bpp;
+ unsigned int count = h;
+ while (count--) {
+ unsigned int i = bpp;
+ while (i--)
+ p[i] = 0xff - p[i];
+ p += dmpi->stride[0];
+ }
+ }
+ return vf_next_put_image(vf, dmpi, pts);
+}
+
+static int
+vf_open(vf_instance_t *vf, char *args) {
+ vf->config = config;
+ vf->control = control;
+ vf->put_image = put_image;
+ vf->priv = malloc(sizeof(struct vf_priv_s));
+ vf->priv->x = -1;
+ vf->priv->y = -1;
+ vf->priv->w = -1;
+ vf->priv->h = -1;
+ if (args)
+ sscanf(args, "%d:%d:%d:%d",
+ &vf->priv->w, &vf->priv->h, &vf->priv->x, &vf->priv->y);
+ return 1;
+}
+
+const vf_info_t vf_info_rectangle = {
+ "draw rectangle",
+ "rectangle",
+ "Kim Minh Kaplan",
+ "",
+ vf_open,
+ NULL
+};
diff --git a/libavfilter/libmpcodecs/vf_remove_logo.c b/libavfilter/libmpcodecs/vf_remove_logo.c
new file mode 100644
index 0000000000..a970adc5b0
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_remove_logo.c
@@ -0,0 +1,906 @@
+/*
+ * This filter loads a .pgm mask file showing where a logo is and uses
+ * a blur transform to remove the logo.
+ *
+ * Copyright (C) 2005 Robert Edele <yartrebo@earthlink.net>
+ *
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+/**
+ * \file
+ *
+ * \brief Advanced blur-based logo removing filter.
+
+ * Hello and welcome. This code implements a filter to remove annoying TV
+ * logos and other annoying images placed onto a video stream. It works by filling
+ * in the pixels that comprise the logo with neighboring pixels. The transform is
+ * very loosely based on a gaussian blur, but it is different enough to merit its
+ * own paragraph later on. It is a major improvement on the old delogo filter as
+ * it both uses a better blurring algorithm and uses a bitmap to use an arbitrary
+ * and generally much tighter fitting shape than a rectangle.
+ *
+ * The filter requires 1 argument and has no optional arguments. It requires
+ * a filter bitmap, which must be in PGM or PPM format. A sample invocation would
+ * be -vf remove_logo=/home/username/logo_bitmaps/xyz.pgm. Pixels with a value of
+ * zero are not part of the logo, and non-zero pixels are part of the logo. If you
+ * use white (255) for the logo and black (0) for the rest, you will be safe. For
+ * making the filter bitmap, I recommend taking a screen capture of a black frame
+ * with the logo visible, and then using The GIMP's threshold filter followed by
+ * the erode filter once or twice. If needed, little splotches can be fixed
+ * manually. Remember that if logo pixels are not covered, the filter quality will
+ * be much reduced. Marking too many pixels as part of the logo doesn't hurt as
+ * much, but it will increase the amount of blurring needed to cover over the
+ * image and will destroy more information than necessary. Additionally, this blur
+ * algorithm is O(n) = n^4, where n is the width and height of a hypothetical
+ * square logo, so extra pixels will slow things down on a large lo
+ *
+ * The logo removal algorithm has two key points. The first is that it
+ * distinguishes between pixels in the logo and those not in the logo by using the
+ * passed-in bitmap. Pixels not in the logo are copied over directly without being
+ * modified and they also serve as source pixels for the logo fill-in. Pixels
+ * inside the logo have the mask applied.
+ *
+ * At init-time the bitmap is reprocessed internally, and the distance to the
+ * nearest edge of the logo (Manhattan distance), along with a little extra to
+ * remove rough edges, is stored in each pixel. This is done using an in-place
+ * erosion algorithm, and incrementing each pixel that survives any given erosion.
+ * Once every pixel is eroded, the maximum value is recorded, and a set of masks
+ * from size 0 to this size are generaged. The masks are circular binary masks,
+ * where each pixel within a radius N (where N is the size of the mask) is a 1,
+ * and all other pixels are a 0. Although a gaussian mask would be more
+ * mathematically accurate, a binary mask works better in practice because we
+ * generally do not use the central pixels in the mask (because they are in the
+ * logo region), and thus a gaussian mask will cause too little blur and thus a
+ * very unstable image.
+ *
+ * The mask is applied in a special way. Namely, only pixels in the mask that
+ * line up to pixels outside the logo are used. The dynamic mask size means that
+ * the mask is just big enough so that the edges touch pixels outside the logo, so
+ * the blurring is kept to a minimum and at least the first boundary condition is
+ * met (that the image function itself is continuous), even if the second boundary
+ * condition (that the derivative of the image function is continuous) is not met.
+ * A masking algorithm that does preserve the second boundary coundition
+ * (perhaps something based on a highly-modified bi-cubic algorithm) should offer
+ * even better results on paper, but the noise in a typical TV signal should make
+ * anything based on derivatives hopelessly noisy.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <inttypes.h>
+
+#include "config.h"
+#include "mp_msg.h"
+#include "libvo/fastmemcpy.h"
+
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+
+//===========================================================================//
+
+/** \brief Returns the larger of the two arguments. **/
+#define max(x,y) ((x)>(y)?(x):(y))
+/** \brief Returns the smaller of the two arguments. **/
+#define min(x,y) ((x)>(y)?(y):(x))
+
+/**
+ * \brief Test if a pixel is part of the logo.
+ */
+#define test_filter(image, x, y) ((unsigned char) (image->pixel[((y) * image->width) + (x)]))
+
+/**
+ * \brief Chooses a slightly larger mask size to improve performance.
+ *
+ * This function maps the absolute minimum mask size needed to the mask size we'll
+ * actually use. f(x) = x (the smallest that will work) will produce the sharpest
+ * results, but will be quite jittery. f(x) = 1.25x (what I'm using) is a good
+ * tradeoff in my opinion. This will calculate only at init-time, so you can put a
+ * long expression here without effecting performance.
+ */
+#define apply_mask_fudge_factor(x) (((x) >> 2) + x)
+
+/**
+ * \brief Simple implementation of the PGM image format.
+ *
+ * This struct holds a bare-bones image loaded from a PGM or PPM file. Once
+ * loaded and pre-processed, each pixel in this struct will contain how far from
+ * the edge of the logo each pixel is, using the manhattan distance (|dx| + |dy|).
+ *
+ * pixels in char * pixel can be addressed using (y * width) + height.
+ */
+typedef struct
+{
+ unsigned int width;
+ unsigned int height;
+
+ unsigned char * pixel;
+
+} pgm_structure;
+
+/**
+ * \brief Stores persistant variables.
+ *
+ * Variables stored here are kept from frame to frame, and separate instances of
+ * the filter will get their own separate copies.
+ */
+struct vf_priv_s
+{
+ unsigned int fmt; /* Not exactly sure of the use for this. It came with the example filter I used as a basis for this, and it looks like a lot of stuff will break if I remove it. */
+ int max_mask_size; /* The largest possible mask size that will be needed with the given filter and corresponding half_size_filter. The half_size_filter can have a larger requirment in some rare (but not degenerate) cases. */
+ int * * * mask; /* Stores our collection of masks. The first * is for an array of masks, the second for the y axis, and the third for the x axis. */
+ pgm_structure * filter; /* Stores the full-size filter image. This is used to tell what pixels are in the logo or not in the luma plane. */
+ pgm_structure * half_size_filter; /* Stores a 50% width and 50% height filter image. This is used to tell what pixels are in the logo or not in the chroma planes. */
+ /* These 8 variables store the bounding rectangles that the logo resides in. */
+ int bounding_rectangle_posx1;
+ int bounding_rectangle_posy1;
+ int bounding_rectangle_posx2;
+ int bounding_rectangle_posy2;
+ int bounding_rectangle_half_size_posx1;
+ int bounding_rectangle_half_size_posy1;
+ int bounding_rectangle_half_size_posx2;
+ int bounding_rectangle_half_size_posy2;
+} vf_priv_s;
+
+/**
+ * \brief Mallocs memory and checks to make sure it succeeded.
+ *
+ * \param size How many bytes to allocate.
+ *
+ * \return A pointer to the freshly allocated memory block, or NULL on failutre.
+ *
+ * Mallocs memory, and checks to make sure it was successfully allocated. Because
+ * of how MPlayer works, it cannot safely halt execution, but at least the user
+ * will get an error message before the segfault happens.
+ */
+static void * safe_malloc(int size)
+{
+ void * answer = malloc(size);
+ if (answer == NULL)
+ mp_msg(MSGT_VFILTER, MSGL_ERR, "Unable to allocate memory in vf_remove_logo.c\n");
+
+ return answer;
+}
+
+/**
+ * \brief Calculates the smallest rectangle that will encompass the logo region.
+ *
+ * \param filter This image contains the logo around which the rectangle will
+ * will be fitted.
+ *
+ * The bounding rectangle is calculated by testing successive lines (from the four
+ * sides of the rectangle) until no more can be removed without removing logo
+ * pixels. The results are returned by reference to posx1, posy1, posx2, and
+ * posy2.
+ */
+static void calculate_bounding_rectangle(int * posx1, int * posy1, int * posx2, int * posy2, pgm_structure * filter)
+{
+ int x; /* Temporary variables to run */
+ int y; /* through each row or column. */
+ int start_x;
+ int start_y;
+ int end_x = filter->width - 1;
+ int end_y = filter->height - 1;
+ int did_we_find_a_logo_pixel = 0;
+
+ /* Let's find the top bound first. */
+ for (start_x = 0; start_x < filter->width && !did_we_find_a_logo_pixel; start_x++)
+ {
+ for (y = 0; y < filter->height; y++)
+ {
+ did_we_find_a_logo_pixel |= test_filter(filter, start_x, y);
+ }
+ }
+ start_x--;
+
+ /* Now the bottom bound. */
+ did_we_find_a_logo_pixel = 0;
+ for (end_x = filter->width - 1; end_x > start_x && !did_we_find_a_logo_pixel; end_x--)
+ {
+ for (y = 0; y < filter->height; y++)
+ {
+ did_we_find_a_logo_pixel |= test_filter(filter, end_x, y);
+ }
+ }
+ end_x++;
+
+ /* Left bound. */
+ did_we_find_a_logo_pixel = 0;
+ for (start_y = 0; start_y < filter->height && !did_we_find_a_logo_pixel; start_y++)
+ {
+ for (x = 0; x < filter->width; x++)
+ {
+ did_we_find_a_logo_pixel |= test_filter(filter, x, start_y);
+ }
+ }
+ start_y--;
+
+ /* Right bound. */
+ did_we_find_a_logo_pixel = 0;
+ for (end_y = filter->height - 1; end_y > start_y && !did_we_find_a_logo_pixel; end_y--)
+ {
+ for (x = 0; x < filter->width; x++)
+ {
+ did_we_find_a_logo_pixel |= test_filter(filter, x, end_y);
+ }
+ }
+ end_y++;
+
+ *posx1 = start_x;
+ *posy1 = start_y;
+ *posx2 = end_x;
+ *posy2 = end_y;
+
+ return;
+}
+
+/**
+ * \brief Free mask memory.
+ *
+ * \param vf Data structure which stores our persistant data, and is to be freed.
+ *
+ * We call this function when our filter is done. It will free the memory
+ * allocated to the masks and leave the variables in a safe state.
+ */
+static void destroy_masks(vf_instance_t * vf)
+{
+ int a, b;
+
+ /* Load values from the vf->priv struct for faster dereferencing. */
+ int * * * mask = vf->priv->mask;
+ int max_mask_size = vf->priv->max_mask_size;
+
+ if (mask == NULL)
+ return; /* Nothing allocated, so return before we segfault. */
+
+ /* Free all allocated memory. */
+ for (a = 0; a <= max_mask_size; a++) /* Loop through each mask. */
+ {
+ for (b = -a; b <= a; b++) /* Loop through each scanline in a mask. */
+ {
+ free(mask[a][b + a]); /* Free a scanline. */
+ }
+ free(mask[a]); /* Free a mask. */
+ }
+ free(mask); /* Free the array of pointers pointing to the masks. */
+
+ /* Set the pointer to NULL, so that any duplicate calls to this function will not cause a crash. */
+ vf->priv->mask = NULL;
+
+ return;
+}
+
+/**
+ * \brief Set up our array of masks.
+ *
+ * \param vf Where our filter stores persistance data, like these masks.
+ *
+ * This creates an array of progressively larger masks and calculates their
+ * values. The values will not change during program execution once this function
+ * is done.
+ */
+static void initialize_masks(vf_instance_t * vf)
+{
+ int a, b, c;
+
+ /* Load values from the vf->priv struct for faster dereferencing. */
+ int * * * mask = vf->priv->mask;
+ int max_mask_size = vf->priv->max_mask_size; /* This tells us how many masks we'll need to generate. */
+
+ /* Create a circular mask for each size up to max_mask_size. When the filter is applied, the mask size is
+ determined on a pixel by pixel basis, with pixels nearer the edge of the logo getting smaller mask sizes. */
+ mask = (int * * *) safe_malloc(sizeof(int * *) * (max_mask_size + 1));
+ for (a = 0; a <= max_mask_size; a++)
+ {
+ mask[a] = (int * *) safe_malloc(sizeof(int *) * ((a * 2) + 1));
+ for (b = -a; b <= a; b++)
+ {
+ mask[a][b + a] = (int *) safe_malloc(sizeof(int) * ((a * 2) + 1));
+ for (c = -a; c <= a; c++)
+ {
+ if ((b * b) + (c * c) <= (a * a)) /* Circular 0/1 mask. */
+ mask[a][b + a][c + a] = 1;
+ else
+ mask[a][b + a][c + a] = 0;
+ }
+ }
+ }
+
+ /* Store values back to vf->priv so they aren't lost after the function returns. */
+ vf->priv->mask = mask;
+
+ return;
+}
+
+/**
+ * \brief Pre-processes an image to give distance information.
+ *
+ * \param vf Data structure that holds persistant information. All it is used for
+ in this function is to store the calculated max_mask_size variable.
+ * \param mask This image will be converted from a greyscale image into a
+ * distance image.
+ *
+ * This function takes a greyscale image (pgm_structure * mask) and converts it
+ * in place into a distance image. A distance image is zero for pixels ourside of
+ * the logo and is the manhattan distance (|dx| + |dy|) for pixels inside of the
+ * logo. This will overestimate the distance, but that is safe, and is far easier
+ * to implement than a proper pythagorean distance since I'm using a modified
+ * erosion algorithm to compute the distances.
+ */
+static void convert_mask_to_strength_mask(vf_instance_t * vf, pgm_structure * mask)
+{
+ int x, y; /* Used by our for loops to go through every single pixel in the picture one at a time. */
+ int has_anything_changed = 1; /* Used by the main while() loop to know if anything changed on the last erosion. */
+ int current_pass = 0; /* How many times we've gone through the loop. Used in the in-place erosion algorithm
+ and to get us max_mask_size later on. */
+ int max_mask_size; /* This will record how large a mask the pixel that is the furthest from the edge of the logo
+ (and thus the neediest) is. */
+ char * current_pixel = mask->pixel; /* This stores the actual pixel data. */
+
+ /* First pass, set all non-zero values to 1. After this loop finishes, the data should be considered numeric
+ data for the filter, not color data. */
+ for (x = 0; x < mask->height * mask->width; x++, current_pixel++)
+ if(*current_pixel) *current_pixel = 1;
+
+ /* Second pass and future passes. For each pass, if a pixel is itself the same value as the current pass,
+ and its four neighbors are too, then it is incremented. If no pixels are incremented by the end of the pass,
+ then we go again. Edge pixels are counted as always excluded (this should be true anyway for any sane mask,
+ but if it isn't this will ensure that we eventually exit). */
+ while (has_anything_changed)
+ {
+ current_pass++;
+ current_pixel = mask->pixel;
+
+ has_anything_changed = 0; /* If this doesn't get set by the end of this pass, then we're done. */
+
+ for (y = 1; y < mask->height - 1; y++)
+ {
+ for (x = 1; x < mask->width - 1; x++)
+ {
+ /* Apply the in-place erosion transform. It is based on the following two premises: 1 - Any pixel that fails 1 erosion
+ will fail all future erosions. 2 - Only pixels having survived all erosions up to the present will be >= to
+ current_pass. It doesn't matter if it survived the current pass, failed it, or hasn't been tested yet. */
+ if (*current_pixel >= current_pass && /* By using >= instead of ==, we allow the algorithm to work in place. */
+ *(current_pixel + 1) >= current_pass &&
+ *(current_pixel - 1) >= current_pass &&
+ *(current_pixel + mask->width) >= current_pass &&
+ *(current_pixel - mask->width) >= current_pass)
+ {
+ (*current_pixel)++; /* Increment the value since it still has not been eroded, as evidenced by the if statement
+ that just evaluated to true. */
+ has_anything_changed = 1;
+ }
+ current_pixel++;
+ }
+ }
+ }
+
+ /* Apply the fudge factor, which will increase the size of the mask a little to reduce jitter at the cost of more blur. */
+ for (y = 1; y < mask->height - 1; y++)
+ {
+ for (x = 1; x < mask->width - 1; x++)
+ {
+ mask->pixel[(y * mask->width) + x] = apply_mask_fudge_factor(mask->pixel[(y * mask->width) + x]);
+ }
+ }
+
+ max_mask_size = current_pass + 1; /* As a side-effect, we now know the maximum mask size, which we'll use to generate our masks. */
+ max_mask_size = apply_mask_fudge_factor(max_mask_size); /* Apply the fudge factor to this number too, since we must
+ ensure that enough masks are generated. */
+ vf->priv->max_mask_size = max_mask_size; /* Commit the newly calculated max_mask_size to the vf->priv struct. */
+
+ return;
+}
+
+/**
+ * \brief Our blurring function.
+ *
+ * \param vf Stores persistant data. In this function we are interested in the
+ * array of masks.
+ * \param value_out The properly blurred and delogoed pixel is outputted here.
+ * \param logo_mask Tells us which pixels are in the logo and which aren't.
+ * \param image The image that is having its logo removed.
+ * \param x x-coordinate of the pixel to blur.
+ * \param y y-coordinate of the pixel to blur.
+ * \param plane 0 = luma, 1 = blue chroma, 2 = red chroma (YUV).
+ *
+ * This function is the core of the filter. It takes a pixel that is inside the
+ * logo and blurs it. It does so by finding the average of all the pixels within
+ * the mask and outside of the logo.
+ */
+static void get_blur(const vf_instance_t * const vf, unsigned int * const value_out, const pgm_structure * const logo_mask,
+ const mp_image_t * const image, const int x, const int y, const int plane)
+{
+ int mask_size; /* Mask size tells how large a circle to use. The radius is about (slightly larger than) mask size. */
+ /* Get values from vf->priv for faster dereferencing. */
+ int * * * mask = vf->priv->mask;
+
+ int start_posx, start_posy, end_posx, end_posy;
+ int i, j;
+ unsigned int accumulator = 0, divisor = 0;
+ const unsigned char * mask_read_position; /* What pixel we are reading out of the circular blur mask. */
+ const unsigned char * logo_mask_read_position; /* What pixel we are reading out of the filter image. */
+
+ /* Prepare our bounding rectangle and clip it if need be. */
+ mask_size = test_filter(logo_mask, x, y);
+ start_posx = max(0, x - mask_size);
+ start_posy = max(0, y - mask_size);
+ end_posx = min(image->width - 1, x + mask_size);
+ end_posy = min(image->height - 1, y + mask_size);
+
+ mask_read_position = image->planes[plane] + (image->stride[plane] * start_posy) + start_posx;
+ logo_mask_read_position = logo_mask->pixel + (start_posy * logo_mask->width) + start_posx;
+
+ for (j = start_posy; j <= end_posy; j++)
+ {
+ for (i = start_posx; i <= end_posx; i++)
+ {
+ if (!(*logo_mask_read_position) && mask[mask_size][i - start_posx][j - start_posy])
+ { /* Check to see if this pixel is in the logo or not. Only use the pixel if it is not. */
+ accumulator += *mask_read_position;
+ divisor++;
+ }
+
+ mask_read_position++;
+ logo_mask_read_position++;
+ }
+
+ mask_read_position += (image->stride[plane] - ((end_posx + 1) - start_posx));
+ logo_mask_read_position += (logo_mask->width - ((end_posx + 1) - start_posx));
+ }
+
+ if (divisor == 0) /* This means that not a single pixel is outside of the logo, so we have no data. */
+ { /* We should put some eye catching value here, to indicate the flaw to the user. */
+ *value_out = 255;
+ }
+ else /* Else we need to normalise the data using the divisor. */
+ {
+ *value_out = (accumulator + (divisor / 2)) / divisor; /* Divide, taking into account average rounding error. */
+ }
+
+ return;
+}
+
+/**
+ * \brief Free a pgm_structure. Undoes load_pgm(...).
+ */
+static void destroy_pgm(pgm_structure * to_be_destroyed)
+{
+ if (to_be_destroyed == NULL)
+ return; /* Don't do anything if a NULL pointer was passed it. */
+
+ /* Internally allocated memory. */
+ if (to_be_destroyed->pixel != NULL)
+ {
+ free(to_be_destroyed->pixel);
+ to_be_destroyed->pixel = NULL;
+ }
+
+ /* Free the actual struct instance. This is done here and not by the calling function. */
+ free(to_be_destroyed);
+}
+
+/** \brief Helper function for load_pgm(...) to skip whitespace. */
+static void load_pgm_skip(FILE *f) {
+ int c, comment = 0;
+ do {
+ c = fgetc(f);
+ if (c == '#')
+ comment = 1;
+ if (c == '\n')
+ comment = 0;
+ } while (c != EOF && (isspace(c) || comment));
+ ungetc(c, f);
+}
+
+#define REMOVE_LOGO_LOAD_PGM_ERROR_MESSAGE(message) {mp_msg(MSGT_VFILTER, MSGL_ERR, message); return NULL;}
+
+/**
+ * \brief Loads a raw pgm or ppm file into a newly created pgm_structure object.
+ *
+ * \param file_name The name of the file to be loaded. So long as the file is a
+ * valid pgm or ppm file, it will load correctly, even if the
+ * extension is missing or invalid.
+ *
+ * \return A pointer to the newly created pgm_structure object. Don't forget to
+ * call destroy_pgm(...) when you're done with this. If an error occurs,
+ * NULL is returned.
+ *
+ * Can load either raw pgm (P5) or raw ppm (P6) image files as a binary image.
+ * While a pgm file will be loaded normally (greyscale), the only thing that is
+ * guaranteed with ppm is that all zero (R = 0, G = 0, B = 0) pixels will remain
+ * zero, and non-zero pixels will remain non-zero.
+ */
+static pgm_structure * load_pgm(const char * file_name)
+{
+ int maximum_greyscale_value;
+ FILE * input;
+ int pnm_number;
+ pgm_structure * new_pgm = (pgm_structure *) safe_malloc (sizeof(pgm_structure));
+ char * write_position;
+ char * end_position;
+ int image_size; /* width * height */
+
+ if((input = fopen(file_name, "rb")) == NULL) REMOVE_LOGO_LOAD_PGM_ERROR_MESSAGE("[vf]remove-logo: Unable to open file. File not found or insufficient permissions.\n");
+
+ /* Parse the PGM header. */
+ if (fgetc(input) != 'P') REMOVE_LOGO_LOAD_PGM_ERROR_MESSAGE("[vf]remove-logo: File is not a valid PGM or PPM file.\n");
+ pnm_number = fgetc(input) - '0';
+ if (pnm_number != 5 && pnm_number != 6) REMOVE_LOGO_LOAD_PGM_ERROR_MESSAGE("[vf]remove-logo: Invalid PNM file. Only raw PGM (Portable Gray Map) and raw PPM (Portable Pixel Map) subtypes are allowed.\n");
+ load_pgm_skip(input);
+ if (fscanf(input, "%i", &(new_pgm->width)) != 1) REMOVE_LOGO_LOAD_PGM_ERROR_MESSAGE("[vf]remove-logo: Invalid PGM/PPM header.\n");
+ load_pgm_skip(input);
+ if (fscanf(input, "%i", &(new_pgm->height)) != 1) REMOVE_LOGO_LOAD_PGM_ERROR_MESSAGE("[vf]remove-logo: Invalid PGM/PPM header.\n");
+ load_pgm_skip(input);
+ if (fscanf(input, "%i", &maximum_greyscale_value) != 1) REMOVE_LOGO_LOAD_PGM_ERROR_MESSAGE("[vf]remove-logo: Invalid PGM/PPM header.\n");
+ if (maximum_greyscale_value >= 256) REMOVE_LOGO_LOAD_PGM_ERROR_MESSAGE("[vf]remove_logo: Only 1 byte per pixel (pgm) or 1 byte per color value (ppm) are supported.\n");
+ load_pgm_skip(input);
+
+ new_pgm->pixel = (unsigned char *) safe_malloc (sizeof(unsigned char) * new_pgm->width * new_pgm->height);
+
+ /* Load the pixels. */
+ /* Note: I am aware that fgetc(input) isn't the fastest way of doing things, but it is quite compact and the code only runs once when the filter is initialized.*/
+ image_size = new_pgm->width * new_pgm->height;
+ end_position = new_pgm->pixel + image_size;
+ for (write_position = new_pgm->pixel; write_position < end_position; write_position++)
+ {
+ *write_position = fgetc(input);
+ if (pnm_number == 6) /* This tests to see if the file is a PPM file. */
+ { /* If it is, then consider the pixel set if any of the three color channels are set. Since we just care about == 0 or != 0, a bitwise or will do the trick. */
+ *write_position |= fgetc(input);
+ *write_position |= fgetc(input);
+ }
+ }
+
+ return new_pgm;
+}
+
+/**
+ * \brief Generates a scaled down image with half width, height, and intensity.
+ *
+ * \param vf Our struct for persistant data. In this case, it is used to update
+ * mask_max_size with the larger of the old or new value.
+ * \param input_image The image from which the new half-sized one will be based.
+ *
+ * \return The newly allocated and shrunken image.
+ *
+ * This function not only scales down an image, but halves the value in each pixel
+ * too. The purpose of this is to produce a chroma filter image out of a luma
+ * filter image. The pixel values store the distance to the edge of the logo and
+ * halving the dimensions halves the distance. This function rounds up, because
+ * a downwards rounding error could cause the filter to fail, but an upwards
+ * rounding error will only cause a minor amount of excess blur in the chroma
+ * planes.
+ */
+static pgm_structure * generate_half_size_image(vf_instance_t * vf, pgm_structure * input_image)
+{
+ int x, y;
+ pgm_structure * new_pgm = (pgm_structure *) safe_malloc (sizeof(pgm_structure));
+ int has_anything_changed = 1;
+ int current_pass;
+ int max_mask_size;
+ char * current_pixel;
+
+ new_pgm->width = input_image->width / 2;
+ new_pgm->height = input_image->height / 2;
+ new_pgm->pixel = (unsigned char *) safe_malloc (sizeof(unsigned char) * new_pgm->width * new_pgm->height);
+
+ /* Copy over the image data, using the average of 4 pixels for to calculate each downsampled pixel. */
+ for (y = 0; y < new_pgm->height; y++)
+ for (x = 0; x < new_pgm->width; x++)
+ {
+ /* Set the pixel if there exists a non-zero value in the source pixels, else clear it. */
+ new_pgm->pixel[(y * new_pgm->width) + x] = input_image->pixel[((y << 1) * input_image->width) + (x << 1)] ||
+ input_image->pixel[((y << 1) * input_image->width) + (x << 1) + 1] ||
+ input_image->pixel[(((y << 1) + 1) * input_image->width) + (x << 1)] ||
+ input_image->pixel[(((y << 1) + 1) * input_image->width) + (x << 1) + 1];
+ new_pgm->pixel[(y * new_pgm->width) + x] = min(1, new_pgm->pixel[(y * new_pgm->width) + x]);
+ }
+
+ /* Now we need to recalculate the numbers for the smaller size. Just using the old_value / 2 can cause subtle
+ and fairly rare, but very nasty, bugs. */
+
+ current_pixel = new_pgm->pixel;
+ /* First pass, set all non-zero values to 1. */
+ for (x = 0; x < new_pgm->height * new_pgm->width; x++, current_pixel++)
+ if(*current_pixel) *current_pixel = 1;
+
+ /* Second pass and future passes. For each pass, if a pixel is itself the same value as the current pass,
+ and its four neighbors are too, then it is incremented. If no pixels are incremented by the end of the pass,
+ then we go again. Edge pixels are counted as always excluded (this should be true anyway for any sane mask,
+ but if it isn't this will ensure that we eventually exit). */
+ current_pass = 0;
+ while (has_anything_changed)
+ {
+ current_pass++;
+
+ has_anything_changed = 0; /* If this doesn't get set by the end of this pass, then we're done. */
+
+ for (y = 1; y < new_pgm->height - 1; y++)
+ {
+ for (x = 1; x < new_pgm->width - 1; x++)
+ {
+ if (new_pgm->pixel[(y * new_pgm->width) + x] >= current_pass && /* By using >= instead of ==, we allow the algorithm to work in place. */
+ new_pgm->pixel[(y * new_pgm->width) + (x + 1)] >= current_pass &&
+ new_pgm->pixel[(y * new_pgm->width) + (x - 1)] >= current_pass &&
+ new_pgm->pixel[((y + 1) * new_pgm->width) + x] >= current_pass &&
+ new_pgm->pixel[((y - 1) * new_pgm->width) + x] >= current_pass)
+ {
+ new_pgm->pixel[(y * new_pgm->width) + x]++; /* Increment the value since it still has not been eroded,
+ as evidenced by the if statement that just evaluated to true. */
+ has_anything_changed = 1;
+ }
+ }
+ }
+ }
+
+ for (y = 1; y < new_pgm->height - 1; y++)
+ {
+ for (x = 1; x < new_pgm->width - 1; x++)
+ {
+ new_pgm->pixel[(y * new_pgm->width) + x] = apply_mask_fudge_factor(new_pgm->pixel[(y * new_pgm->width) + x]);
+ }
+ }
+
+ max_mask_size = current_pass + 1; /* As a side-effect, we now know the maximum mask size, which we'll use to generate our masks. */
+ max_mask_size = apply_mask_fudge_factor(max_mask_size);
+ /* Commit the newly calculated max_mask_size to the vf->priv struct. */
+ vf->priv->max_mask_size = max(max_mask_size, vf->priv->max_mask_size);
+
+ return new_pgm;
+}
+
+/**
+ * \brief Checks if YV12 is supported by the next filter.
+ */
+static unsigned int find_best(struct vf_instance *vf){
+ int is_format_okay = vf_next_query_format(vf, IMGFMT_YV12);
+ if ((is_format_okay & VFCAP_CSP_SUPPORTED_BY_HW) || (is_format_okay & VFCAP_CSP_SUPPORTED))
+ return IMGFMT_YV12;
+ else
+ return 0;
+}
+
+//===========================================================================//
+
+/**
+ * \brief Configure the filter and call the next filter's config function.
+ */
+static int config(struct vf_instance *vf, int width, int height, int d_width, int d_height, unsigned int flags, unsigned int outfmt)
+{
+ if(!(vf->priv->fmt=find_best(vf)))
+ return 0;
+ else
+ return vf_next_config(vf,width,height,d_width,d_height,flags,vf->priv->fmt);
+}
+
+/**
+ * \brief Removes the logo from a plane (either luma or chroma).
+ *
+ * \param vf Not needed by this function, but needed by the blur function.
+ * \param source The image to have it's logo removed.
+ * \param destination Where the output image will be stored.
+ * \param source_stride How far apart (in memory) two consecutive lines are.
+ * \param destination Same as source_stride, but for the destination image.
+ * \param width Width of the image. This is the same for source and destination.
+ * \param height Height of the image. This is the same for source and destination.
+ * \param is_image_direct If the image is direct, then source and destination are
+ * the same and we can save a lot of time by not copying pixels that
+ * haven't changed.
+ * \param filter The image that stores the distance to the edge of the logo for
+ * each pixel.
+ * \param logo_start_x Smallest x-coordinate that contains at least 1 logo pixel.
+ * \param logo_start_y Smallest y-coordinate that contains at least 1 logo pixel.
+ * \param logo_end_x Largest x-coordinate that contains at least 1 logo pixel.
+ * \param logo_end_y Largest y-coordinate that contains at least 1 logo pixel.
+ *
+ * This function processes an entire plane. Pixels outside of the logo are copied
+ * to the output without change, and pixels inside the logo have the de-blurring
+ * function applied.
+ */
+static void convert_yv12(const vf_instance_t * const vf, const char * const source, const int source_stride,
+ const mp_image_t * const source_image, const int width, const int height,
+ char * const destination, const int destination_stride, int is_image_direct, pgm_structure * filter,
+ const int plane, const int logo_start_x, const int logo_start_y, const int logo_end_x, const int logo_end_y)
+{
+ int y;
+ int x;
+
+ /* These pointers point to where we are getting our pixel data (inside mpi) and where we are storing it (inside dmpi). */
+ const unsigned char * source_line;
+ unsigned char * destination_line;
+
+ if (!is_image_direct)
+ memcpy_pic(destination, source, width, height, destination_stride, source_stride);
+
+ for (y = logo_start_y; y <= logo_end_y; y++)
+ {
+ source_line = (const unsigned char *) source + (source_stride * y);
+ destination_line = (unsigned char *) destination + (destination_stride * y);
+
+ for (x = logo_start_x; x <= logo_end_x; x++)
+ {
+ unsigned int output;
+
+ if (filter->pixel[(y * filter->width) + x]) /* Only process if we are in the logo. */
+ {
+ get_blur(vf, &output, filter, source_image, x, y, plane);
+ destination_line[x] = output;
+ }
+ else /* Else just copy the data. */
+ if (!is_image_direct)
+ destination_line[x] = source_line[x];
+ }
+ }
+}
+
+/**
+ * \brief Process a frame.
+ *
+ * \param mpi The image sent to use by the previous filter.
+ * \param dmpi Where we will store the processed output image.
+ * \param vf This is how the filter gets access to it's persistant data.
+ *
+ * \return The return code of the next filter, or 0 on failure/error.
+ *
+ * This function processes an entire frame. The frame is sent by the previous
+ * filter, has the logo removed by the filter, and is then sent to the next
+ * filter.
+ */
+static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
+ mp_image_t *dmpi;
+
+ dmpi=vf_get_image(vf->next,vf->priv->fmt,
+ MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
+ mpi->w, mpi->h);
+
+ /* Check to make sure that the filter image and the video stream are the same size. */
+ if (vf->priv->filter->width != mpi->w || vf->priv->filter->height != mpi->h)
+ {
+ mp_msg(MSGT_VFILTER,MSGL_ERR, "Filter image and video stream are not of the same size. (Filter: %d x %d, Stream: %d x %d)\n",
+ vf->priv->filter->width, vf->priv->filter->height, mpi->w, mpi->h);
+ return 0;
+ }
+
+ switch(dmpi->imgfmt){
+ case IMGFMT_YV12:
+ convert_yv12(vf, mpi->planes[0], mpi->stride[0], mpi, mpi->w, mpi->h,
+ dmpi->planes[0], dmpi->stride[0],
+ mpi->flags & MP_IMGFLAG_DIRECT, vf->priv->filter, 0,
+ vf->priv->bounding_rectangle_posx1, vf->priv->bounding_rectangle_posy1,
+ vf->priv->bounding_rectangle_posx2, vf->priv->bounding_rectangle_posy2);
+ convert_yv12(vf, mpi->planes[1], mpi->stride[1], mpi, mpi->w / 2, mpi->h / 2,
+ dmpi->planes[1], dmpi->stride[1],
+ mpi->flags & MP_IMGFLAG_DIRECT, vf->priv->half_size_filter, 1,
+ vf->priv->bounding_rectangle_half_size_posx1, vf->priv->bounding_rectangle_half_size_posy1,
+ vf->priv->bounding_rectangle_half_size_posx2, vf->priv->bounding_rectangle_half_size_posy2);
+ convert_yv12(vf, mpi->planes[2], mpi->stride[2], mpi, mpi->w / 2, mpi->h / 2,
+ dmpi->planes[2], dmpi->stride[2],
+ mpi->flags & MP_IMGFLAG_DIRECT, vf->priv->half_size_filter, 2,
+ vf->priv->bounding_rectangle_half_size_posx1, vf->priv->bounding_rectangle_half_size_posy1,
+ vf->priv->bounding_rectangle_half_size_posx2, vf->priv->bounding_rectangle_half_size_posy2);
+ break;
+
+ default:
+ mp_msg(MSGT_VFILTER,MSGL_ERR,"Unhandled format: 0x%X\n",dmpi->imgfmt);
+ return 0;
+ }
+
+ return vf_next_put_image(vf,dmpi, pts);
+}
+
+//===========================================================================//
+
+/**
+ * \brief Checks to see if the next filter accepts YV12 images.
+ */
+static int query_format(struct vf_instance *vf, unsigned int fmt)
+{
+ if (fmt == IMGFMT_YV12)
+ return vf_next_query_format(vf, IMGFMT_YV12);
+ else
+ return 0;
+}
+
+/**
+ * \brief Frees memory that our filter allocated.
+ *
+ * This is called at exit-time.
+ */
+static void uninit(vf_instance_t *vf)
+{
+ /* Destroy our masks and images. */
+ destroy_pgm(vf->priv->filter);
+ destroy_pgm(vf->priv->half_size_filter);
+ destroy_masks(vf);
+
+ /* Destroy our private structure that had been used to store those masks and images. */
+ free(vf->priv);
+
+ return;
+}
+
+/**
+ * \brief Initializes our filter.
+ *
+ * \param args The arguments passed in from the command line go here. This
+ * filter expects only a single argument telling it where the PGM
+ * or PPM file that describes the logo region is.
+ *
+ * This sets up our instance variables and parses the arguments to the filter.
+ */
+static int vf_open(vf_instance_t *vf, char *args)
+{
+ vf->priv = safe_malloc(sizeof(vf_priv_s));
+ vf->uninit = uninit;
+
+ /* Load our filter image. */
+ if (args)
+ vf->priv->filter = load_pgm(args);
+ else
+ {
+ mp_msg(MSGT_VFILTER, MSGL_ERR, "[vf]remove_logo usage: remove_logo=/path/to/filter_image_file.pgm\n");
+ free(vf->priv);
+ return 0;
+ }
+
+ if (vf->priv->filter == NULL)
+ {
+ /* Error message was displayed by load_pgm(). */
+ free(vf->priv);
+ return 0;
+ }
+
+ /* Create the scaled down filter image for the chroma planes. */
+ convert_mask_to_strength_mask(vf, vf->priv->filter);
+ vf->priv->half_size_filter = generate_half_size_image(vf, vf->priv->filter);
+
+ /* Now that we know how many masks we need (the info is in vf), we can generate the masks. */
+ initialize_masks(vf);
+
+ /* Calculate our bounding rectangles, which determine in what region the logo resides for faster processing. */
+ calculate_bounding_rectangle(&vf->priv->bounding_rectangle_posx1, &vf->priv->bounding_rectangle_posy1,
+ &vf->priv->bounding_rectangle_posx2, &vf->priv->bounding_rectangle_posy2,
+ vf->priv->filter);
+ calculate_bounding_rectangle(&vf->priv->bounding_rectangle_half_size_posx1,
+ &vf->priv->bounding_rectangle_half_size_posy1,
+ &vf->priv->bounding_rectangle_half_size_posx2,
+ &vf->priv->bounding_rectangle_half_size_posy2,
+ vf->priv->half_size_filter);
+
+ vf->config=config;
+ vf->put_image=put_image;
+ vf->query_format=query_format;
+ return 1;
+}
+
+/**
+ * \brief Meta data about our filter.
+ */
+const vf_info_t vf_info_remove_logo = {
+ "Removes a tv logo based on a mask image.",
+ "remove-logo",
+ "Robert Edele",
+ "",
+ vf_open,
+ NULL
+};
+
+//===========================================================================//
diff --git a/libavfilter/libmpcodecs/vf_rotate.c b/libavfilter/libmpcodecs/vf_rotate.c
new file mode 100644
index 0000000000..08d73bec28
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_rotate.c
@@ -0,0 +1,152 @@
+/*
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+
+#include "config.h"
+#include "mp_msg.h"
+
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+
+struct vf_priv_s {
+ int direction;
+};
+
+static void rotate(unsigned char* dst,unsigned char* src,int dststride,int srcstride,int w,int h,int bpp,int dir){
+ int y;
+ if(dir&1){
+ src+=srcstride*(w-1);
+ srcstride*=-1;
+ }
+ if(dir&2){
+ dst+=dststride*(h-1);
+ dststride*=-1;
+ }
+
+ for(y=0;y<h;y++){
+ int x;
+ switch(bpp){
+ case 1:
+ for(x=0;x<w;x++) dst[x]=src[y+x*srcstride];
+ break;
+ case 2:
+ for(x=0;x<w;x++) *((short*)(dst+x*2))=*((short*)(src+y*2+x*srcstride));
+ break;
+ case 3:
+ for(x=0;x<w;x++){
+ dst[x*3+0]=src[0+y*3+x*srcstride];
+ dst[x*3+1]=src[1+y*3+x*srcstride];
+ dst[x*3+2]=src[2+y*3+x*srcstride];
+ }
+ break;
+ case 4:
+ for(x=0;x<w;x++) *((int*)(dst+x*4))=*((int*)(src+y*4+x*srcstride));
+ }
+ dst+=dststride;
+ }
+}
+
+//===========================================================================//
+
+static int config(struct vf_instance *vf,
+ int width, int height, int d_width, int d_height,
+ unsigned int flags, unsigned int outfmt){
+ if (vf->priv->direction & 4) {
+ if (width<height) vf->priv->direction&=3;
+ }
+ if (vf->priv->direction & 4){
+ vf->put_image=vf_next_put_image; // passthru mode!
+ if (vf->next->draw_slice) vf->draw_slice=vf_next_draw_slice;
+/* FIXME: this should be in an other procedure in vf.c; that should always check
+ whether the filter after the passthrough one still (not)supports slices */
+ return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
+ }
+ return vf_next_config(vf,height,width,d_height,d_width,flags,outfmt);
+}
+
+static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
+ mp_image_t *dmpi;
+
+ // hope we'll get DR buffer:
+ dmpi=vf_get_image(vf->next,mpi->imgfmt,
+ MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
+ mpi->h, mpi->w);
+
+ if(mpi->flags&MP_IMGFLAG_PLANAR){
+ rotate(dmpi->planes[0],mpi->planes[0],
+ dmpi->stride[0],mpi->stride[0],
+ dmpi->w,dmpi->h,1,vf->priv->direction);
+ rotate(dmpi->planes[1],mpi->planes[1],
+ dmpi->stride[1],mpi->stride[1],
+ dmpi->w>>mpi->chroma_x_shift,dmpi->h>>mpi->chroma_y_shift,1,vf->priv->direction);
+ rotate(dmpi->planes[2],mpi->planes[2],
+ dmpi->stride[2],mpi->stride[2],
+ dmpi->w>>mpi->chroma_x_shift,dmpi->h>>mpi->chroma_y_shift,1,vf->priv->direction);
+ } else {
+ rotate(dmpi->planes[0],mpi->planes[0],
+ dmpi->stride[0],mpi->stride[0],
+ dmpi->w,dmpi->h,dmpi->bpp>>3,vf->priv->direction);
+ dmpi->planes[1] = mpi->planes[1]; // passthrough rgb8 palette
+ }
+
+ return vf_next_put_image(vf,dmpi, pts);
+}
+
+//===========================================================================//
+
+static int query_format(struct vf_instance *vf, unsigned int fmt){
+ if(IMGFMT_IS_RGB(fmt) || IMGFMT_IS_BGR(fmt)) return vf_next_query_format(vf, fmt);
+ // we can support only symmetric (chroma_x_shift==chroma_y_shift) YUV formats:
+ switch(fmt) {
+ case IMGFMT_YV12:
+ case IMGFMT_I420:
+ case IMGFMT_IYUV:
+ case IMGFMT_YVU9:
+// case IMGFMT_IF09:
+ case IMGFMT_Y8:
+ case IMGFMT_Y800:
+ case IMGFMT_444P:
+ return vf_next_query_format(vf, fmt);
+ }
+ return 0;
+}
+
+static int vf_open(vf_instance_t *vf, char *args){
+ vf->config=config;
+ vf->put_image=put_image;
+ vf->query_format=query_format;
+ vf->priv=malloc(sizeof(struct vf_priv_s));
+ vf->priv->direction=args?atoi(args):0;
+ return 1;
+}
+
+const vf_info_t vf_info_rotate = {
+ "rotate",
+ "rotate",
+ "A'rpi",
+ "",
+ vf_open,
+ NULL
+};
+
+//===========================================================================//
diff --git a/libavfilter/libmpcodecs/vf_sab.c b/libavfilter/libmpcodecs/vf_sab.c
new file mode 100644
index 0000000000..4dadeb798e
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_sab.c
@@ -0,0 +1,323 @@
+/*
+ * Copyright (C) 2002 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+#include <assert.h>
+
+#include "config.h"
+#include "mp_msg.h"
+
+#if HAVE_MALLOC_H
+#include <malloc.h>
+#endif
+
+#include "libavutil/avutil.h"
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+#include "libswscale/swscale.h"
+#include "vf_scale.h"
+
+
+//===========================================================================//
+
+typedef struct FilterParam{
+ float radius;
+ float preFilterRadius;
+ float strength;
+ float quality;
+ struct SwsContext *preFilterContext;
+ uint8_t *preFilterBuf;
+ int preFilterStride;
+ int distWidth;
+ int distStride;
+ int *distCoeff;
+ int colorDiffCoeff[512];
+}FilterParam;
+
+struct vf_priv_s {
+ FilterParam luma;
+ FilterParam chroma;
+};
+
+
+/***************************************************************************/
+
+//FIXME stupid code duplication
+static void getSubSampleFactors(int *h, int *v, int format){
+ switch(format){
+ default:
+ assert(0);
+ case IMGFMT_YV12:
+ case IMGFMT_I420:
+ *h=1;
+ *v=1;
+ break;
+ case IMGFMT_YVU9:
+ *h=2;
+ *v=2;
+ break;
+ case IMGFMT_444P:
+ *h=0;
+ *v=0;
+ break;
+ case IMGFMT_422P:
+ *h=1;
+ *v=0;
+ break;
+ case IMGFMT_411P:
+ *h=2;
+ *v=0;
+ break;
+ }
+}
+
+static int allocStuff(FilterParam *f, int width, int height){
+ int stride= (width+7)&~7;
+ SwsVector *vec;
+ SwsFilter swsF;
+ int i,x,y;
+ f->preFilterBuf= av_malloc(stride*height);
+ f->preFilterStride= stride;
+
+ vec = sws_getGaussianVec(f->preFilterRadius, f->quality);
+ swsF.lumH= swsF.lumV= vec;
+ swsF.chrH= swsF.chrV= NULL;
+ f->preFilterContext= sws_getContext(
+ width, height, PIX_FMT_GRAY8, width, height, PIX_FMT_GRAY8, SWS_POINT, &swsF, NULL, NULL);
+
+ sws_freeVec(vec);
+ vec = sws_getGaussianVec(f->strength, 5.0);
+ for(i=0; i<512; i++){
+ double d;
+ int index= i-256 + vec->length/2;
+
+ if(index<0 || index>=vec->length) d= 0.0;
+ else d= vec->coeff[index];
+
+ f->colorDiffCoeff[i]= (int)(d/vec->coeff[vec->length/2]*(1<<12) + 0.5);
+ }
+ sws_freeVec(vec);
+ vec = sws_getGaussianVec(f->radius, f->quality);
+ f->distWidth= vec->length;
+ f->distStride= (vec->length+7)&~7;
+ f->distCoeff= av_malloc(f->distWidth*f->distStride*sizeof(int32_t));
+
+ for(y=0; y<vec->length; y++){
+ for(x=0; x<vec->length; x++){
+ double d= vec->coeff[x] * vec->coeff[y];
+
+ f->distCoeff[x + y*f->distStride]= (int)(d*(1<<10) + 0.5);
+// if(y==vec->length/2)
+// printf("%6d ", f->distCoeff[x + y*f->distStride]);
+ }
+ }
+ sws_freeVec(vec);
+
+ return 0;
+}
+
+static int config(struct vf_instance *vf,
+ int width, int height, int d_width, int d_height,
+ unsigned int flags, unsigned int outfmt){
+
+ int sw, sh;
+//__asm__ volatile("emms\n\t");
+ allocStuff(&vf->priv->luma, width, height);
+
+ getSubSampleFactors(&sw, &sh, outfmt);
+ allocStuff(&vf->priv->chroma, width>>sw, height>>sh);
+
+ return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
+}
+
+static void freeBuffers(FilterParam *f){
+ if(f->preFilterContext) sws_freeContext(f->preFilterContext);
+ f->preFilterContext=NULL;
+
+ av_free(f->preFilterBuf);
+ f->preFilterBuf=NULL;
+
+ av_free(f->distCoeff);
+ f->distCoeff=NULL;
+}
+
+static void uninit(struct vf_instance *vf){
+ if(!vf->priv) return;
+
+ freeBuffers(&vf->priv->luma);
+ freeBuffers(&vf->priv->chroma);
+
+ free(vf->priv);
+ vf->priv=NULL;
+}
+
+static inline void blur(uint8_t *dst, uint8_t *src, int w, int h, int dstStride, int srcStride, FilterParam *fp){
+ int x, y;
+ FilterParam f= *fp;
+ const int radius= f.distWidth/2;
+ const uint8_t* const srcArray[MP_MAX_PLANES] = {src};
+ uint8_t *dstArray[MP_MAX_PLANES]= {f.preFilterBuf};
+ int srcStrideArray[MP_MAX_PLANES]= {srcStride};
+ int dstStrideArray[MP_MAX_PLANES]= {f.preFilterStride};
+
+// f.preFilterContext->swScale(f.preFilterContext, srcArray, srcStrideArray, 0, h, dstArray, dstStrideArray);
+ sws_scale(f.preFilterContext, srcArray, srcStrideArray, 0, h, dstArray, dstStrideArray);
+
+ for(y=0; y<h; y++){
+ for(x=0; x<w; x++){
+ int sum=0;
+ int div=0;
+ int dy;
+ const int preVal= f.preFilterBuf[x + y*f.preFilterStride];
+#if 0
+ const int srcVal= src[x + y*srcStride];
+if((x/32)&1){
+ dst[x + y*dstStride]= srcVal;
+ if(y%32==0) dst[x + y*dstStride]= 0;
+ continue;
+}
+#endif
+ if(x >= radius && x < w - radius){
+ for(dy=0; dy<radius*2+1; dy++){
+ int dx;
+ int iy= y+dy - radius;
+ if (iy<0) iy= -iy;
+ else if(iy>=h) iy= h+h-iy-1;
+
+ for(dx=0; dx<radius*2+1; dx++){
+ const int ix= x+dx - radius;
+ int factor;
+
+ factor= f.colorDiffCoeff[256+preVal - f.preFilterBuf[ix + iy*f.preFilterStride] ]
+ *f.distCoeff[dx + dy*f.distStride];
+ sum+= src[ix + iy*srcStride] *factor;
+ div+= factor;
+ }
+ }
+ }else{
+ for(dy=0; dy<radius*2+1; dy++){
+ int dx;
+ int iy= y+dy - radius;
+ if (iy<0) iy= -iy;
+ else if(iy>=h) iy= h+h-iy-1;
+
+ for(dx=0; dx<radius*2+1; dx++){
+ int ix= x+dx - radius;
+ int factor;
+ if (ix<0) ix= -ix;
+ else if(ix>=w) ix= w+w-ix-1;
+
+ factor= f.colorDiffCoeff[256+preVal - f.preFilterBuf[ix + iy*f.preFilterStride] ]
+ *f.distCoeff[dx + dy*f.distStride];
+ sum+= src[ix + iy*srcStride] *factor;
+ div+= factor;
+ }
+ }
+ }
+ dst[x + y*dstStride]= (sum + div/2)/div;
+ }
+ }
+}
+
+static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
+ int cw= mpi->w >> mpi->chroma_x_shift;
+ int ch= mpi->h >> mpi->chroma_y_shift;
+
+ mp_image_t *dmpi=vf_get_image(vf->next,mpi->imgfmt,
+ MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
+ mpi->w,mpi->h);
+
+ assert(mpi->flags&MP_IMGFLAG_PLANAR);
+
+ blur(dmpi->planes[0], mpi->planes[0], mpi->w,mpi->h, dmpi->stride[0], mpi->stride[0], &vf->priv->luma);
+ blur(dmpi->planes[1], mpi->planes[1], cw , ch , dmpi->stride[1], mpi->stride[1], &vf->priv->chroma);
+ blur(dmpi->planes[2], mpi->planes[2], cw , ch , dmpi->stride[2], mpi->stride[2], &vf->priv->chroma);
+
+ return vf_next_put_image(vf,dmpi, pts);
+}
+
+//===========================================================================//
+
+static int query_format(struct vf_instance *vf, unsigned int fmt){
+ switch(fmt)
+ {
+ case IMGFMT_YV12:
+ case IMGFMT_I420:
+ case IMGFMT_IYUV:
+ case IMGFMT_YVU9:
+ case IMGFMT_444P:
+ case IMGFMT_422P:
+ case IMGFMT_411P:
+ return vf_next_query_format(vf, fmt);
+ }
+ return 0;
+}
+
+static int vf_open(vf_instance_t *vf, char *args){
+ int e;
+
+ vf->config=config;
+ vf->put_image=put_image;
+// vf->get_image=get_image;
+ vf->query_format=query_format;
+ vf->uninit=uninit;
+ vf->priv=malloc(sizeof(struct vf_priv_s));
+ memset(vf->priv, 0, sizeof(struct vf_priv_s));
+
+ if(args==NULL) return 0;
+
+ e=sscanf(args, "%f:%f:%f:%f:%f:%f",
+ &vf->priv->luma.radius,
+ &vf->priv->luma.preFilterRadius,
+ &vf->priv->luma.strength,
+ &vf->priv->chroma.radius,
+ &vf->priv->chroma.preFilterRadius,
+ &vf->priv->chroma.strength
+ );
+
+ vf->priv->luma.quality = vf->priv->chroma.quality= 3.0;
+
+ if(e==3){
+ vf->priv->chroma.radius= vf->priv->luma.radius;
+ vf->priv->chroma.preFilterRadius = vf->priv->luma.preFilterRadius;
+ vf->priv->chroma.strength= vf->priv->luma.strength;
+ }else if(e!=6)
+ return 0;
+
+// if(vf->priv->luma.radius < 0) return 0;
+// if(vf->priv->chroma.radius < 0) return 0;
+
+ return 1;
+}
+
+const vf_info_t vf_info_sab = {
+ "shape adaptive blur",
+ "sab",
+ "Michael Niedermayer",
+ "",
+ vf_open,
+ NULL
+};
+
+//===========================================================================//
diff --git a/libavfilter/libmpcodecs/vf_scale.h b/libavfilter/libmpcodecs/vf_scale.h
new file mode 100644
index 0000000000..4de3b48ec3
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_scale.h
@@ -0,0 +1,34 @@
+/*
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef MPLAYER_VF_SCALE_H
+#define MPLAYER_VF_SCALE_H
+
+extern int sws_chr_vshift;
+extern int sws_chr_hshift;
+
+extern float sws_chr_gblur;
+extern float sws_lum_gblur;
+extern float sws_chr_sharpen;
+extern float sws_lum_sharpen;
+
+extern int sws_flags;
+
+struct SwsContext *sws_getContextFromCmdLine(int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat);
+
+#endif /* MPLAYER_VF_SCALE_H */
diff --git a/libavfilter/libmpcodecs/vf_screenshot.c b/libavfilter/libmpcodecs/vf_screenshot.c
new file mode 100644
index 0000000000..82b345b446
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_screenshot.c
@@ -0,0 +1,322 @@
+/*
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#if HAVE_MALLOC_H
+#include <malloc.h>
+#endif
+#include <string.h>
+#include <inttypes.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include "mp_msg.h"
+
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+#include "vf_scale.h"
+
+#include "libswscale/swscale.h"
+#include "libavcodec/avcodec.h"
+
+struct vf_priv_s {
+ int frameno;
+ char fname[102];
+ /// shot stores current screenshot mode:
+ /// 0: don't take screenshots
+ /// 1: take single screenshot, reset to 0 afterwards
+ /// 2: take screenshots of each frame
+ int shot, store_slices;
+ int dw, dh, stride;
+ uint8_t *buffer;
+ struct SwsContext *ctx;
+ AVCodecContext *avctx;
+ uint8_t *outbuffer;
+ int outbuffer_size;
+};
+
+//===========================================================================//
+
+static int config(struct vf_instance *vf,
+ int width, int height, int d_width, int d_height,
+ unsigned int flags, unsigned int outfmt)
+{
+ vf->priv->ctx=sws_getContextFromCmdLine(width, height, outfmt,
+ d_width, d_height, IMGFMT_RGB24);
+
+ vf->priv->outbuffer_size = d_width * d_height * 3 * 2;
+ vf->priv->outbuffer = realloc(vf->priv->outbuffer, vf->priv->outbuffer_size);
+ vf->priv->avctx->width = d_width;
+ vf->priv->avctx->height = d_height;
+ vf->priv->avctx->pix_fmt = PIX_FMT_RGB24;
+ vf->priv->avctx->compression_level = 0;
+ vf->priv->dw = d_width;
+ vf->priv->dh = d_height;
+ vf->priv->stride = (3*vf->priv->dw+15)&~15;
+
+ free(vf->priv->buffer); // probably reconfigured
+ vf->priv->buffer = NULL;
+
+ return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
+}
+
+static void write_png(struct vf_priv_s *priv)
+{
+ char *fname = priv->fname;
+ FILE * fp;
+ AVFrame pic;
+ int size;
+
+ fp = fopen (fname, "wb");
+ if (fp == NULL) {
+ mp_msg(MSGT_VFILTER,MSGL_ERR,"\nPNG Error opening %s for writing!\n", fname);
+ return;
+ }
+
+ pic.data[0] = priv->buffer;
+ pic.linesize[0] = priv->stride;
+ size = avcodec_encode_video(priv->avctx, priv->outbuffer, priv->outbuffer_size, &pic);
+ if (size > 0)
+ fwrite(priv->outbuffer, size, 1, fp);
+
+ fclose (fp);
+}
+
+static int fexists(char *fname)
+{
+ struct stat dummy;
+ if (stat(fname, &dummy) == 0) return 1;
+ else return 0;
+}
+
+static void gen_fname(struct vf_priv_s* priv)
+{
+ do {
+ snprintf (priv->fname, 100, "shot%04d.png", ++priv->frameno);
+ } while (fexists(priv->fname) && priv->frameno < 100000);
+ if (fexists(priv->fname)) {
+ priv->fname[0] = '\0';
+ return;
+ }
+
+ mp_msg(MSGT_VFILTER,MSGL_INFO,"*** screenshot '%s' ***\n",priv->fname);
+
+}
+
+static void scale_image(struct vf_priv_s* priv, mp_image_t *mpi)
+{
+ uint8_t *dst[MP_MAX_PLANES] = {NULL};
+ int dst_stride[MP_MAX_PLANES] = {0};
+
+ dst_stride[0] = priv->stride;
+ if (!priv->buffer)
+ priv->buffer = av_malloc(dst_stride[0]*priv->dh);
+
+ dst[0] = priv->buffer;
+ sws_scale(priv->ctx, mpi->planes, mpi->stride, 0, priv->dh, dst, dst_stride);
+}
+
+static void start_slice(struct vf_instance *vf, mp_image_t *mpi)
+{
+ vf->dmpi=vf_get_image(vf->next,mpi->imgfmt,
+ mpi->type, mpi->flags, mpi->width, mpi->height);
+ if (vf->priv->shot) {
+ vf->priv->store_slices = 1;
+ if (!vf->priv->buffer)
+ vf->priv->buffer = av_malloc(vf->priv->stride*vf->priv->dh);
+ }
+
+}
+
+static void draw_slice(struct vf_instance *vf, unsigned char** src,
+ int* stride, int w,int h, int x, int y)
+{
+ if (vf->priv->store_slices) {
+ uint8_t *dst[MP_MAX_PLANES] = {NULL};
+ int dst_stride[MP_MAX_PLANES] = {0};
+ dst_stride[0] = vf->priv->stride;
+ dst[0] = vf->priv->buffer;
+ sws_scale(vf->priv->ctx, src, stride, y, h, dst, dst_stride);
+ }
+ vf_next_draw_slice(vf,src,stride,w,h,x,y);
+}
+
+static void get_image(struct vf_instance *vf, mp_image_t *mpi)
+{
+ // FIXME: should vf.c really call get_image when using slices??
+ if (mpi->flags & MP_IMGFLAG_DRAW_CALLBACK)
+ return;
+ vf->dmpi= vf_get_image(vf->next, mpi->imgfmt,
+ mpi->type, mpi->flags/* | MP_IMGFLAG_READABLE*/, mpi->width, mpi->height);
+
+ mpi->planes[0]=vf->dmpi->planes[0];
+ mpi->stride[0]=vf->dmpi->stride[0];
+ if(mpi->flags&MP_IMGFLAG_PLANAR){
+ mpi->planes[1]=vf->dmpi->planes[1];
+ mpi->planes[2]=vf->dmpi->planes[2];
+ mpi->stride[1]=vf->dmpi->stride[1];
+ mpi->stride[2]=vf->dmpi->stride[2];
+ }
+ mpi->width=vf->dmpi->width;
+
+ mpi->flags|=MP_IMGFLAG_DIRECT;
+
+ mpi->priv=(void*)vf->dmpi;
+}
+
+static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
+{
+ mp_image_t *dmpi = (mp_image_t *)mpi->priv;
+
+ if (mpi->flags & MP_IMGFLAG_DRAW_CALLBACK)
+ dmpi = vf->dmpi;
+ else
+ if(!(mpi->flags&MP_IMGFLAG_DIRECT)){
+ dmpi=vf_get_image(vf->next,mpi->imgfmt,
+ MP_IMGTYPE_EXPORT, 0,
+ mpi->width, mpi->height);
+ vf_clone_mpi_attributes(dmpi, mpi);
+ dmpi->planes[0]=mpi->planes[0];
+ dmpi->planes[1]=mpi->planes[1];
+ dmpi->planes[2]=mpi->planes[2];
+ dmpi->stride[0]=mpi->stride[0];
+ dmpi->stride[1]=mpi->stride[1];
+ dmpi->stride[2]=mpi->stride[2];
+ dmpi->width=mpi->width;
+ dmpi->height=mpi->height;
+ }
+
+ if(vf->priv->shot) {
+ if (vf->priv->shot==1)
+ vf->priv->shot=0;
+ gen_fname(vf->priv);
+ if (vf->priv->fname[0]) {
+ if (!vf->priv->store_slices)
+ scale_image(vf->priv, dmpi);
+ write_png(vf->priv);
+ }
+ vf->priv->store_slices = 0;
+ }
+
+ return vf_next_put_image(vf, dmpi, pts);
+}
+
+static int control (vf_instance_t *vf, int request, void *data)
+{
+ /** data contains an integer argument
+ * 0: take screenshot with the next frame
+ * 1: take screenshots with each frame until the same command is given once again
+ **/
+ if(request==VFCTRL_SCREENSHOT) {
+ if (data && *(int*)data) { // repeated screenshot mode
+ if (vf->priv->shot==2)
+ vf->priv->shot=0;
+ else
+ vf->priv->shot=2;
+ } else { // single screenshot
+ if (!vf->priv->shot)
+ vf->priv->shot=1;
+ }
+ return CONTROL_TRUE;
+ }
+ return vf_next_control (vf, request, data);
+}
+
+
+//===========================================================================//
+
+static int query_format(struct vf_instance *vf, unsigned int fmt)
+{
+ switch(fmt){
+ case IMGFMT_YV12:
+ case IMGFMT_I420:
+ case IMGFMT_IYUV:
+ case IMGFMT_UYVY:
+ case IMGFMT_YUY2:
+ case IMGFMT_BGR32:
+ case IMGFMT_BGR24:
+ case IMGFMT_BGR16:
+ case IMGFMT_BGR15:
+ case IMGFMT_BGR12:
+ case IMGFMT_RGB32:
+ case IMGFMT_RGB24:
+ case IMGFMT_Y800:
+ case IMGFMT_Y8:
+ case IMGFMT_YVU9:
+ case IMGFMT_IF09:
+ case IMGFMT_444P:
+ case IMGFMT_422P:
+ case IMGFMT_411P:
+ return vf_next_query_format(vf, fmt);
+ }
+ return 0;
+}
+
+static void uninit(vf_instance_t *vf)
+{
+ avcodec_close(vf->priv->avctx);
+ av_freep(&vf->priv->avctx);
+ if(vf->priv->ctx) sws_freeContext(vf->priv->ctx);
+ av_free(vf->priv->buffer);
+ free(vf->priv->outbuffer);
+ free(vf->priv);
+}
+
+static int vf_open(vf_instance_t *vf, char *args)
+{
+ vf->config=config;
+ vf->control=control;
+ vf->put_image=put_image;
+ vf->query_format=query_format;
+ vf->start_slice=start_slice;
+ vf->draw_slice=draw_slice;
+ vf->get_image=get_image;
+ vf->uninit=uninit;
+ vf->priv=malloc(sizeof(struct vf_priv_s));
+ vf->priv->frameno=0;
+ vf->priv->shot=0;
+ vf->priv->store_slices=0;
+ vf->priv->buffer=0;
+ vf->priv->outbuffer=0;
+ vf->priv->ctx=0;
+ vf->priv->avctx = avcodec_alloc_context();
+ avcodec_register_all();
+ if (avcodec_open(vf->priv->avctx, avcodec_find_encoder(CODEC_ID_PNG))) {
+ mp_msg(MSGT_VFILTER, MSGL_FATAL, "Could not open libavcodec PNG encoder\n");
+ return 0;
+ }
+ return 1;
+}
+
+
+const vf_info_t vf_info_screenshot = {
+ "screenshot to file",
+ "screenshot",
+ "A'rpi, Jindrich Makovicka",
+ "",
+ vf_open,
+ NULL
+};
+
+//===========================================================================//
diff --git a/libavfilter/libmpcodecs/vf_smartblur.c b/libavfilter/libmpcodecs/vf_smartblur.c
new file mode 100644
index 0000000000..3f0d7c3d6b
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_smartblur.c
@@ -0,0 +1,264 @@
+/*
+ * Copyright (C) 2002 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+#include <assert.h>
+
+#include "mp_msg.h"
+#include "libavutil/avutil.h"
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+#include "libswscale/swscale.h"
+#include "vf_scale.h"
+
+//===========================================================================//
+
+typedef struct FilterParam{
+ float radius;
+ float strength;
+ int threshold;
+ float quality;
+ struct SwsContext *filterContext;
+}FilterParam;
+
+struct vf_priv_s {
+ FilterParam luma;
+ FilterParam chroma;
+};
+
+
+/***************************************************************************/
+
+//FIXME stupid code duplication
+static void getSubSampleFactors(int *h, int *v, int format){
+ switch(format){
+ default:
+ assert(0);
+ case IMGFMT_YV12:
+ case IMGFMT_I420:
+ *h=1;
+ *v=1;
+ break;
+ case IMGFMT_YVU9:
+ *h=2;
+ *v=2;
+ break;
+ case IMGFMT_444P:
+ *h=0;
+ *v=0;
+ break;
+ case IMGFMT_422P:
+ *h=1;
+ *v=0;
+ break;
+ case IMGFMT_411P:
+ *h=2;
+ *v=0;
+ break;
+ }
+}
+
+static int allocStuff(FilterParam *f, int width, int height){
+ SwsVector *vec;
+ SwsFilter swsF;
+
+ vec = sws_getGaussianVec(f->radius, f->quality);
+ sws_scaleVec(vec, f->strength);
+ vec->coeff[vec->length/2]+= 1.0 - f->strength;
+ swsF.lumH= swsF.lumV= vec;
+ swsF.chrH= swsF.chrV= NULL;
+ f->filterContext= sws_getContext(
+ width, height, PIX_FMT_GRAY8, width, height, PIX_FMT_GRAY8, SWS_BICUBIC, &swsF, NULL, NULL);
+
+ sws_freeVec(vec);
+
+ return 0;
+}
+
+static int config(struct vf_instance *vf,
+ int width, int height, int d_width, int d_height,
+ unsigned int flags, unsigned int outfmt){
+
+ int sw, sh;
+
+ allocStuff(&vf->priv->luma, width, height);
+
+ getSubSampleFactors(&sw, &sh, outfmt);
+ allocStuff(&vf->priv->chroma, width>>sw, height>>sh);
+
+ return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
+}
+
+static void freeBuffers(FilterParam *f){
+ if(f->filterContext) sws_freeContext(f->filterContext);
+ f->filterContext=NULL;
+}
+
+static void uninit(struct vf_instance *vf){
+ if(!vf->priv) return;
+
+ freeBuffers(&vf->priv->luma);
+ freeBuffers(&vf->priv->chroma);
+
+ free(vf->priv);
+ vf->priv=NULL;
+}
+
+static inline void blur(uint8_t *dst, uint8_t *src, int w, int h, int dstStride, int srcStride, FilterParam *fp){
+ int x, y;
+ FilterParam f= *fp;
+ const uint8_t* const srcArray[MP_MAX_PLANES] = {src};
+ uint8_t *dstArray[MP_MAX_PLANES]= {dst};
+ int srcStrideArray[MP_MAX_PLANES]= {srcStride};
+ int dstStrideArray[MP_MAX_PLANES]= {dstStride};
+
+ sws_scale(f.filterContext, srcArray, srcStrideArray, 0, h, dstArray, dstStrideArray);
+
+ if(f.threshold > 0){
+ for(y=0; y<h; y++){
+ for(x=0; x<w; x++){
+ const int orig= src[x + y*srcStride];
+ const int filtered= dst[x + y*dstStride];
+ const int diff= orig - filtered;
+
+ if(diff > 0){
+ if(diff > 2*f.threshold){
+ dst[x + y*dstStride]= orig;
+ }else if(diff > f.threshold){
+ dst[x + y*dstStride]= filtered + diff - f.threshold;
+ }
+ }else{
+ if(-diff > 2*f.threshold){
+ dst[x + y*dstStride]= orig;
+ }else if(-diff > f.threshold){
+ dst[x + y*dstStride]= filtered + diff + f.threshold;
+ }
+ }
+ }
+ }
+ }else if(f.threshold < 0){
+ for(y=0; y<h; y++){
+ for(x=0; x<w; x++){
+ const int orig= src[x + y*srcStride];
+ const int filtered= dst[x + y*dstStride];
+ const int diff= orig - filtered;
+
+ if(diff > 0){
+ if(diff > -2*f.threshold){
+ }else if(diff > -f.threshold){
+ dst[x + y*dstStride]= orig - diff - f.threshold;
+ }else
+ dst[x + y*dstStride]= orig;
+ }else{
+ if(diff < 2*f.threshold){
+ }else if(diff < f.threshold){
+ dst[x + y*dstStride]= orig - diff + f.threshold;
+ }else
+ dst[x + y*dstStride]= orig;
+ }
+ }
+ }
+ }
+}
+
+static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
+ int cw= mpi->w >> mpi->chroma_x_shift;
+ int ch= mpi->h >> mpi->chroma_y_shift;
+ int threshold = vf->priv->luma.threshold || vf->priv->chroma.threshold;
+
+ mp_image_t *dmpi=vf_get_image(vf->next,mpi->imgfmt,
+ MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE|
+ (threshold ? MP_IMGFLAG_READABLE : 0),
+ mpi->w,mpi->h);
+
+ assert(mpi->flags&MP_IMGFLAG_PLANAR);
+
+ blur(dmpi->planes[0], mpi->planes[0], mpi->w,mpi->h, dmpi->stride[0], mpi->stride[0], &vf->priv->luma);
+ blur(dmpi->planes[1], mpi->planes[1], cw , ch , dmpi->stride[1], mpi->stride[1], &vf->priv->chroma);
+ blur(dmpi->planes[2], mpi->planes[2], cw , ch , dmpi->stride[2], mpi->stride[2], &vf->priv->chroma);
+
+ return vf_next_put_image(vf,dmpi, pts);
+}
+
+//===========================================================================//
+
+static int query_format(struct vf_instance *vf, unsigned int fmt){
+ switch(fmt)
+ {
+ case IMGFMT_YV12:
+ case IMGFMT_I420:
+ case IMGFMT_IYUV:
+ case IMGFMT_YVU9:
+ case IMGFMT_444P:
+ case IMGFMT_422P:
+ case IMGFMT_411P:
+ return vf_next_query_format(vf, fmt);
+ }
+ return 0;
+}
+
+static int vf_open(vf_instance_t *vf, char *args){
+ int e;
+
+ vf->config=config;
+ vf->put_image=put_image;
+// vf->get_image=get_image;
+ vf->query_format=query_format;
+ vf->uninit=uninit;
+ vf->priv=malloc(sizeof(struct vf_priv_s));
+ memset(vf->priv, 0, sizeof(struct vf_priv_s));
+
+ if(args==NULL) return 0;
+
+ e=sscanf(args, "%f:%f:%d:%f:%f:%d",
+ &vf->priv->luma.radius,
+ &vf->priv->luma.strength,
+ &vf->priv->luma.threshold,
+ &vf->priv->chroma.radius,
+ &vf->priv->chroma.strength,
+ &vf->priv->chroma.threshold
+ );
+
+ vf->priv->luma.quality = vf->priv->chroma.quality= 3.0;
+
+ if(e==3){
+ vf->priv->chroma.radius= vf->priv->luma.radius;
+ vf->priv->chroma.strength= vf->priv->luma.strength;
+ vf->priv->chroma.threshold = vf->priv->luma.threshold;
+ }else if(e!=6)
+ return 0;
+
+ return 1;
+}
+
+const vf_info_t vf_info_smartblur = {
+ "smart blur",
+ "smartblur",
+ "Michael Niedermayer",
+ "",
+ vf_open,
+ NULL
+};
+
+//===========================================================================//
diff --git a/libavfilter/libmpcodecs/vf_softpulldown.c b/libavfilter/libmpcodecs/vf_softpulldown.c
new file mode 100644
index 0000000000..04d1eae3d4
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_softpulldown.c
@@ -0,0 +1,164 @@
+/*
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "config.h"
+#include "mp_msg.h"
+
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+
+#include "libvo/fastmemcpy.h"
+
+struct vf_priv_s {
+ int state;
+ long long in;
+ long long out;
+};
+
+static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
+{
+ mp_image_t *dmpi;
+ int ret = 0;
+ int flags = mpi->fields;
+ int state = vf->priv->state;
+
+ dmpi = vf_get_image(vf->next, mpi->imgfmt,
+ MP_IMGTYPE_STATIC, MP_IMGFLAG_ACCEPT_STRIDE |
+ MP_IMGFLAG_PRESERVE, mpi->width, mpi->height);
+
+ vf->priv->in++;
+
+ if ((state == 0 &&
+ !(flags & MP_IMGFIELD_TOP_FIRST)) ||
+ (state == 1 &&
+ flags & MP_IMGFIELD_TOP_FIRST)) {
+ mp_msg(MSGT_VFILTER, MSGL_WARN,
+ "softpulldown: Unexpected field flags: state=%d top_field_first=%d repeat_first_field=%d\n",
+ state,
+ (flags & MP_IMGFIELD_TOP_FIRST) != 0,
+ (flags & MP_IMGFIELD_REPEAT_FIRST) != 0);
+ state ^= 1;
+ }
+
+ if (state == 0) {
+ ret = vf_next_put_image(vf, mpi, MP_NOPTS_VALUE);
+ vf->priv->out++;
+ if (flags & MP_IMGFIELD_REPEAT_FIRST) {
+ my_memcpy_pic(dmpi->planes[0],
+ mpi->planes[0], mpi->w, mpi->h/2,
+ dmpi->stride[0]*2, mpi->stride[0]*2);
+ if (mpi->flags & MP_IMGFLAG_PLANAR) {
+ my_memcpy_pic(dmpi->planes[1],
+ mpi->planes[1],
+ mpi->chroma_width,
+ mpi->chroma_height/2,
+ dmpi->stride[1]*2,
+ mpi->stride[1]*2);
+ my_memcpy_pic(dmpi->planes[2],
+ mpi->planes[2],
+ mpi->chroma_width,
+ mpi->chroma_height/2,
+ dmpi->stride[2]*2,
+ mpi->stride[2]*2);
+ }
+ state=1;
+ }
+ } else {
+ my_memcpy_pic(dmpi->planes[0]+dmpi->stride[0],
+ mpi->planes[0]+mpi->stride[0], mpi->w, mpi->h/2,
+ dmpi->stride[0]*2, mpi->stride[0]*2);
+ if (mpi->flags & MP_IMGFLAG_PLANAR) {
+ my_memcpy_pic(dmpi->planes[1]+dmpi->stride[1],
+ mpi->planes[1]+mpi->stride[1],
+ mpi->chroma_width, mpi->chroma_height/2,
+ dmpi->stride[1]*2, mpi->stride[1]*2);
+ my_memcpy_pic(dmpi->planes[2]+dmpi->stride[2],
+ mpi->planes[2]+mpi->stride[2],
+ mpi->chroma_width, mpi->chroma_height/2,
+ dmpi->stride[2]*2, mpi->stride[2]*2);
+ }
+ ret = vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE);
+ vf->priv->out++;
+ if (flags & MP_IMGFIELD_REPEAT_FIRST) {
+ ret |= vf_next_put_image(vf, mpi, MP_NOPTS_VALUE);
+ vf->priv->out++;
+ state=0;
+ } else {
+ my_memcpy_pic(dmpi->planes[0],
+ mpi->planes[0], mpi->w, mpi->h/2,
+ dmpi->stride[0]*2, mpi->stride[0]*2);
+ if (mpi->flags & MP_IMGFLAG_PLANAR) {
+ my_memcpy_pic(dmpi->planes[1],
+ mpi->planes[1],
+ mpi->chroma_width,
+ mpi->chroma_height/2,
+ dmpi->stride[1]*2,
+ mpi->stride[1]*2);
+ my_memcpy_pic(dmpi->planes[2],
+ mpi->planes[2],
+ mpi->chroma_width,
+ mpi->chroma_height/2,
+ dmpi->stride[2]*2,
+ mpi->stride[2]*2);
+ }
+ }
+ }
+
+ vf->priv->state = state;
+
+ return ret;
+}
+
+static int config(struct vf_instance *vf,
+ int width, int height, int d_width, int d_height,
+ unsigned int flags, unsigned int outfmt)
+{
+ return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
+}
+
+static void uninit(struct vf_instance *vf)
+{
+ mp_msg(MSGT_VFILTER, MSGL_INFO, "softpulldown: %lld frames in, %lld frames out\n", vf->priv->in, vf->priv->out);
+ free(vf->priv);
+}
+
+static int vf_open(vf_instance_t *vf, char *args)
+{
+ struct vf_priv_s *p;
+ vf->config = config;
+ vf->put_image = put_image;
+ vf->uninit = uninit;
+ vf->default_reqs = VFCAP_ACCEPT_STRIDE;
+ vf->priv = p = calloc(1, sizeof(struct vf_priv_s));
+ vf->priv->state = 0;
+ return 1;
+}
+
+const vf_info_t vf_info_softpulldown = {
+ "mpeg2 soft 3:2 pulldown",
+ "softpulldown",
+ "Tobias Diedrich <ranma+mplayer@tdiedrich.de>",
+ "",
+ vf_open,
+ NULL
+};
diff --git a/libavfilter/libmpcodecs/vf_softskip.c b/libavfilter/libmpcodecs/vf_softskip.c
new file mode 100644
index 0000000000..150c3e7b72
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_softskip.c
@@ -0,0 +1,102 @@
+/*
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "config.h"
+#include "mp_msg.h"
+
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+
+struct vf_priv_s {
+ int skipflag;
+};
+
+static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
+{
+ mp_image_t *dmpi;
+
+ if (vf->priv->skipflag)
+ return vf->priv->skipflag = 0;
+
+ dmpi = vf_get_image(vf->next, mpi->imgfmt,
+ MP_IMGTYPE_EXPORT, 0, mpi->width, mpi->height);
+ vf_clone_mpi_attributes(dmpi, mpi);
+
+ dmpi->planes[0] = mpi->planes[0];
+ dmpi->stride[0] = mpi->stride[0];
+ if (dmpi->flags&MP_IMGFLAG_PLANAR) {
+ dmpi->planes[1] = mpi->planes[1];
+ dmpi->stride[1] = mpi->stride[1];
+ dmpi->planes[2] = mpi->planes[2];
+ dmpi->stride[2] = mpi->stride[2];
+ }
+
+ return vf_next_put_image(vf, dmpi, pts);
+}
+
+static int control(struct vf_instance *vf, int request, void* data)
+{
+ switch (request) {
+ case VFCTRL_SKIP_NEXT_FRAME:
+ vf->priv->skipflag = 1;
+ return CONTROL_TRUE;
+ }
+ return vf_next_control(vf, request, data);
+}
+
+#if 0
+static int query_format(struct vf_instance *vf, unsigned int fmt)
+{
+ /* FIXME - figure out which other formats work */
+ switch (fmt) {
+ case IMGFMT_YV12:
+ case IMGFMT_IYUV:
+ case IMGFMT_I420:
+ return vf_next_query_format(vf, fmt);
+ }
+ return 0;
+}
+#endif
+
+static void uninit(struct vf_instance *vf)
+{
+ free(vf->priv);
+}
+
+static int vf_open(vf_instance_t *vf, char *args)
+{
+ vf->put_image = put_image;
+ vf->control = control;
+ vf->uninit = uninit;
+ vf->priv = calloc(1, sizeof(struct vf_priv_s));
+ return 1;
+}
+
+const vf_info_t vf_info_softskip = {
+ "soft (post-filter) frame skipping for encoding",
+ "softskip",
+ "Rich Felker",
+ "",
+ vf_open,
+ NULL
+};
diff --git a/libavfilter/libmpcodecs/vf_spp.c b/libavfilter/libmpcodecs/vf_spp.c
new file mode 100644
index 0000000000..0b4b2306f4
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_spp.c
@@ -0,0 +1,620 @@
+/*
+ * Copyright (C) 2003 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+/*
+ * This implementation is based on an algorithm described in
+ * "Aria Nosratinia Embedded Post-Processing for
+ * Enhancement of Compressed Images (1999)"
+ * (http://citeseer.nj.nec.com/nosratinia99embedded.html)
+ */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+#include <math.h>
+
+#include "config.h"
+
+#include "mp_msg.h"
+#include "cpudetect.h"
+
+#include "libavutil/internal.h"
+#include "libavutil/intreadwrite.h"
+#include "libavcodec/avcodec.h"
+#include "libavcodec/dsputil.h"
+
+#undef fprintf
+#undef free
+#undef malloc
+
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+#include "vd_ffmpeg.h"
+#include "libvo/fastmemcpy.h"
+
+#define XMIN(a,b) ((a) < (b) ? (a) : (b))
+
+//===========================================================================//
+static const uint8_t __attribute__((aligned(8))) dither[8][8]={
+{ 0, 48, 12, 60, 3, 51, 15, 63, },
+{ 32, 16, 44, 28, 35, 19, 47, 31, },
+{ 8, 56, 4, 52, 11, 59, 7, 55, },
+{ 40, 24, 36, 20, 43, 27, 39, 23, },
+{ 2, 50, 14, 62, 1, 49, 13, 61, },
+{ 34, 18, 46, 30, 33, 17, 45, 29, },
+{ 10, 58, 6, 54, 9, 57, 5, 53, },
+{ 42, 26, 38, 22, 41, 25, 37, 21, },
+};
+
+static const uint8_t offset[127][2]= {
+{0,0},
+{0,0}, {4,4},
+{0,0}, {2,2}, {6,4}, {4,6},
+{0,0}, {5,1}, {2,2}, {7,3}, {4,4}, {1,5}, {6,6}, {3,7},
+
+{0,0}, {4,0}, {1,1}, {5,1}, {3,2}, {7,2}, {2,3}, {6,3},
+{0,4}, {4,4}, {1,5}, {5,5}, {3,6}, {7,6}, {2,7}, {6,7},
+
+{0,0}, {0,2}, {0,4}, {0,6}, {1,1}, {1,3}, {1,5}, {1,7},
+{2,0}, {2,2}, {2,4}, {2,6}, {3,1}, {3,3}, {3,5}, {3,7},
+{4,0}, {4,2}, {4,4}, {4,6}, {5,1}, {5,3}, {5,5}, {5,7},
+{6,0}, {6,2}, {6,4}, {6,6}, {7,1}, {7,3}, {7,5}, {7,7},
+
+{0,0}, {4,4}, {0,4}, {4,0}, {2,2}, {6,6}, {2,6}, {6,2},
+{0,2}, {4,6}, {0,6}, {4,2}, {2,0}, {6,4}, {2,4}, {6,0},
+{1,1}, {5,5}, {1,5}, {5,1}, {3,3}, {7,7}, {3,7}, {7,3},
+{1,3}, {5,7}, {1,7}, {5,3}, {3,1}, {7,5}, {3,5}, {7,1},
+{0,1}, {4,5}, {0,5}, {4,1}, {2,3}, {6,7}, {2,7}, {6,3},
+{0,3}, {4,7}, {0,7}, {4,3}, {2,1}, {6,5}, {2,5}, {6,1},
+{1,0}, {5,4}, {1,4}, {5,0}, {3,2}, {7,6}, {3,6}, {7,2},
+{1,2}, {5,6}, {1,6}, {5,2}, {3,0}, {7,4}, {3,4}, {7,0},
+};
+
+struct vf_priv_s {
+ int log2_count;
+ int qp;
+ int mode;
+ int mpeg2;
+ int temp_stride;
+ uint8_t *src;
+ int16_t *temp;
+ AVCodecContext *avctx;
+ DSPContext dsp;
+ char *non_b_qp;
+};
+
+#define SHIFT 22
+
+static void hardthresh_c(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *permutation){
+ int i;
+ int bias= 0; //FIXME
+ unsigned int threshold1, threshold2;
+
+ threshold1= qp*((1<<4) - bias) - 1;
+ threshold2= (threshold1<<1);
+
+ memset(dst, 0, 64*sizeof(DCTELEM));
+ dst[0]= (src[0] + 4)>>3;
+
+ for(i=1; i<64; i++){
+ int level= src[i];
+ if(((unsigned)(level+threshold1))>threshold2){
+ const int j= permutation[i];
+ dst[j]= (level + 4)>>3;
+ }
+ }
+}
+
+static void softthresh_c(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *permutation){
+ int i;
+ int bias= 0; //FIXME
+ unsigned int threshold1, threshold2;
+
+ threshold1= qp*((1<<4) - bias) - 1;
+ threshold2= (threshold1<<1);
+
+ memset(dst, 0, 64*sizeof(DCTELEM));
+ dst[0]= (src[0] + 4)>>3;
+
+ for(i=1; i<64; i++){
+ int level= src[i];
+ if(((unsigned)(level+threshold1))>threshold2){
+ const int j= permutation[i];
+ if(level>0)
+ dst[j]= (level - threshold1 + 4)>>3;
+ else
+ dst[j]= (level + threshold1 + 4)>>3;
+ }
+ }
+}
+
+#if HAVE_MMX
+static void hardthresh_mmx(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *permutation){
+ int bias= 0; //FIXME
+ unsigned int threshold1;
+
+ threshold1= qp*((1<<4) - bias) - 1;
+
+ __asm__ volatile(
+#define REQUANT_CORE(dst0, dst1, dst2, dst3, src0, src1, src2, src3) \
+ "movq " #src0 ", %%mm0 \n\t"\
+ "movq " #src1 ", %%mm1 \n\t"\
+ "movq " #src2 ", %%mm2 \n\t"\
+ "movq " #src3 ", %%mm3 \n\t"\
+ "psubw %%mm4, %%mm0 \n\t"\
+ "psubw %%mm4, %%mm1 \n\t"\
+ "psubw %%mm4, %%mm2 \n\t"\
+ "psubw %%mm4, %%mm3 \n\t"\
+ "paddusw %%mm5, %%mm0 \n\t"\
+ "paddusw %%mm5, %%mm1 \n\t"\
+ "paddusw %%mm5, %%mm2 \n\t"\
+ "paddusw %%mm5, %%mm3 \n\t"\
+ "paddw %%mm6, %%mm0 \n\t"\
+ "paddw %%mm6, %%mm1 \n\t"\
+ "paddw %%mm6, %%mm2 \n\t"\
+ "paddw %%mm6, %%mm3 \n\t"\
+ "psubusw %%mm6, %%mm0 \n\t"\
+ "psubusw %%mm6, %%mm1 \n\t"\
+ "psubusw %%mm6, %%mm2 \n\t"\
+ "psubusw %%mm6, %%mm3 \n\t"\
+ "psraw $3, %%mm0 \n\t"\
+ "psraw $3, %%mm1 \n\t"\
+ "psraw $3, %%mm2 \n\t"\
+ "psraw $3, %%mm3 \n\t"\
+\
+ "movq %%mm0, %%mm7 \n\t"\
+ "punpcklwd %%mm2, %%mm0 \n\t" /*A*/\
+ "punpckhwd %%mm2, %%mm7 \n\t" /*C*/\
+ "movq %%mm1, %%mm2 \n\t"\
+ "punpcklwd %%mm3, %%mm1 \n\t" /*B*/\
+ "punpckhwd %%mm3, %%mm2 \n\t" /*D*/\
+ "movq %%mm0, %%mm3 \n\t"\
+ "punpcklwd %%mm1, %%mm0 \n\t" /*A*/\
+ "punpckhwd %%mm7, %%mm3 \n\t" /*C*/\
+ "punpcklwd %%mm2, %%mm7 \n\t" /*B*/\
+ "punpckhwd %%mm2, %%mm1 \n\t" /*D*/\
+\
+ "movq %%mm0, " #dst0 " \n\t"\
+ "movq %%mm7, " #dst1 " \n\t"\
+ "movq %%mm3, " #dst2 " \n\t"\
+ "movq %%mm1, " #dst3 " \n\t"
+
+ "movd %2, %%mm4 \n\t"
+ "movd %3, %%mm5 \n\t"
+ "movd %4, %%mm6 \n\t"
+ "packssdw %%mm4, %%mm4 \n\t"
+ "packssdw %%mm5, %%mm5 \n\t"
+ "packssdw %%mm6, %%mm6 \n\t"
+ "packssdw %%mm4, %%mm4 \n\t"
+ "packssdw %%mm5, %%mm5 \n\t"
+ "packssdw %%mm6, %%mm6 \n\t"
+ REQUANT_CORE( (%1), 8(%1), 16(%1), 24(%1), (%0), 8(%0), 64(%0), 72(%0))
+ REQUANT_CORE(32(%1), 40(%1), 48(%1), 56(%1),16(%0),24(%0), 48(%0), 56(%0))
+ REQUANT_CORE(64(%1), 72(%1), 80(%1), 88(%1),32(%0),40(%0), 96(%0),104(%0))
+ REQUANT_CORE(96(%1),104(%1),112(%1),120(%1),80(%0),88(%0),112(%0),120(%0))
+ : : "r" (src), "r" (dst), "g" (threshold1+1), "g" (threshold1+5), "g" (threshold1-4) //FIXME maybe more accurate then needed?
+ );
+ dst[0]= (src[0] + 4)>>3;
+}
+
+static void softthresh_mmx(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *permutation){
+ int bias= 0; //FIXME
+ unsigned int threshold1;
+
+ threshold1= qp*((1<<4) - bias) - 1;
+
+ __asm__ volatile(
+#undef REQUANT_CORE
+#define REQUANT_CORE(dst0, dst1, dst2, dst3, src0, src1, src2, src3) \
+ "movq " #src0 ", %%mm0 \n\t"\
+ "movq " #src1 ", %%mm1 \n\t"\
+ "pxor %%mm6, %%mm6 \n\t"\
+ "pxor %%mm7, %%mm7 \n\t"\
+ "pcmpgtw %%mm0, %%mm6 \n\t"\
+ "pcmpgtw %%mm1, %%mm7 \n\t"\
+ "pxor %%mm6, %%mm0 \n\t"\
+ "pxor %%mm7, %%mm1 \n\t"\
+ "psubusw %%mm4, %%mm0 \n\t"\
+ "psubusw %%mm4, %%mm1 \n\t"\
+ "pxor %%mm6, %%mm0 \n\t"\
+ "pxor %%mm7, %%mm1 \n\t"\
+ "movq " #src2 ", %%mm2 \n\t"\
+ "movq " #src3 ", %%mm3 \n\t"\
+ "pxor %%mm6, %%mm6 \n\t"\
+ "pxor %%mm7, %%mm7 \n\t"\
+ "pcmpgtw %%mm2, %%mm6 \n\t"\
+ "pcmpgtw %%mm3, %%mm7 \n\t"\
+ "pxor %%mm6, %%mm2 \n\t"\
+ "pxor %%mm7, %%mm3 \n\t"\
+ "psubusw %%mm4, %%mm2 \n\t"\
+ "psubusw %%mm4, %%mm3 \n\t"\
+ "pxor %%mm6, %%mm2 \n\t"\
+ "pxor %%mm7, %%mm3 \n\t"\
+\
+ "paddsw %%mm5, %%mm0 \n\t"\
+ "paddsw %%mm5, %%mm1 \n\t"\
+ "paddsw %%mm5, %%mm2 \n\t"\
+ "paddsw %%mm5, %%mm3 \n\t"\
+ "psraw $3, %%mm0 \n\t"\
+ "psraw $3, %%mm1 \n\t"\
+ "psraw $3, %%mm2 \n\t"\
+ "psraw $3, %%mm3 \n\t"\
+\
+ "movq %%mm0, %%mm7 \n\t"\
+ "punpcklwd %%mm2, %%mm0 \n\t" /*A*/\
+ "punpckhwd %%mm2, %%mm7 \n\t" /*C*/\
+ "movq %%mm1, %%mm2 \n\t"\
+ "punpcklwd %%mm3, %%mm1 \n\t" /*B*/\
+ "punpckhwd %%mm3, %%mm2 \n\t" /*D*/\
+ "movq %%mm0, %%mm3 \n\t"\
+ "punpcklwd %%mm1, %%mm0 \n\t" /*A*/\
+ "punpckhwd %%mm7, %%mm3 \n\t" /*C*/\
+ "punpcklwd %%mm2, %%mm7 \n\t" /*B*/\
+ "punpckhwd %%mm2, %%mm1 \n\t" /*D*/\
+\
+ "movq %%mm0, " #dst0 " \n\t"\
+ "movq %%mm7, " #dst1 " \n\t"\
+ "movq %%mm3, " #dst2 " \n\t"\
+ "movq %%mm1, " #dst3 " \n\t"
+
+ "movd %2, %%mm4 \n\t"
+ "movd %3, %%mm5 \n\t"
+ "packssdw %%mm4, %%mm4 \n\t"
+ "packssdw %%mm5, %%mm5 \n\t"
+ "packssdw %%mm4, %%mm4 \n\t"
+ "packssdw %%mm5, %%mm5 \n\t"
+ REQUANT_CORE( (%1), 8(%1), 16(%1), 24(%1), (%0), 8(%0), 64(%0), 72(%0))
+ REQUANT_CORE(32(%1), 40(%1), 48(%1), 56(%1),16(%0),24(%0), 48(%0), 56(%0))
+ REQUANT_CORE(64(%1), 72(%1), 80(%1), 88(%1),32(%0),40(%0), 96(%0),104(%0))
+ REQUANT_CORE(96(%1),104(%1),112(%1),120(%1),80(%0),88(%0),112(%0),120(%0))
+ : : "r" (src), "r" (dst), "g" (threshold1), "rm" (4) //FIXME maybe more accurate then needed?
+ );
+
+ dst[0]= (src[0] + 4)>>3;
+}
+#endif
+
+static inline void add_block(int16_t *dst, int stride, DCTELEM block[64]){
+ int y;
+
+ for(y=0; y<8; y++){
+ *(uint32_t*)&dst[0 + y*stride]+= *(uint32_t*)&block[0 + y*8];
+ *(uint32_t*)&dst[2 + y*stride]+= *(uint32_t*)&block[2 + y*8];
+ *(uint32_t*)&dst[4 + y*stride]+= *(uint32_t*)&block[4 + y*8];
+ *(uint32_t*)&dst[6 + y*stride]+= *(uint32_t*)&block[6 + y*8];
+ }
+}
+
+static void store_slice_c(uint8_t *dst, int16_t *src, int dst_stride, int src_stride, int width, int height, int log2_scale){
+ int y, x;
+
+#define STORE(pos) \
+ temp= ((src[x + y*src_stride + pos]<<log2_scale) + d[pos])>>6;\
+ if(temp & 0x100) temp= ~(temp>>31);\
+ dst[x + y*dst_stride + pos]= temp;
+
+ for(y=0; y<height; y++){
+ const uint8_t *d= dither[y];
+ for(x=0; x<width; x+=8){
+ int temp;
+ STORE(0);
+ STORE(1);
+ STORE(2);
+ STORE(3);
+ STORE(4);
+ STORE(5);
+ STORE(6);
+ STORE(7);
+ }
+ }
+}
+
+#if HAVE_MMX
+static void store_slice_mmx(uint8_t *dst, int16_t *src, int dst_stride, int src_stride, int width, int height, int log2_scale){
+ int y;
+
+ for(y=0; y<height; y++){
+ uint8_t *dst1= dst;
+ int16_t *src1= src;
+ __asm__ volatile(
+ "movq (%3), %%mm3 \n\t"
+ "movq (%3), %%mm4 \n\t"
+ "movd %4, %%mm2 \n\t"
+ "pxor %%mm0, %%mm0 \n\t"
+ "punpcklbw %%mm0, %%mm3 \n\t"
+ "punpckhbw %%mm0, %%mm4 \n\t"
+ "psraw %%mm2, %%mm3 \n\t"
+ "psraw %%mm2, %%mm4 \n\t"
+ "movd %5, %%mm2 \n\t"
+ "1: \n\t"
+ "movq (%0), %%mm0 \n\t"
+ "movq 8(%0), %%mm1 \n\t"
+ "paddw %%mm3, %%mm0 \n\t"
+ "paddw %%mm4, %%mm1 \n\t"
+ "psraw %%mm2, %%mm0 \n\t"
+ "psraw %%mm2, %%mm1 \n\t"
+ "packuswb %%mm1, %%mm0 \n\t"
+ "movq %%mm0, (%1) \n\t"
+ "add $16, %0 \n\t"
+ "add $8, %1 \n\t"
+ "cmp %2, %1 \n\t"
+ " jb 1b \n\t"
+ : "+r" (src1), "+r"(dst1)
+ : "r"(dst + width), "r"(dither[y]), "g"(log2_scale), "g"(6-log2_scale)
+ );
+ src += src_stride;
+ dst += dst_stride;
+ }
+// if(width != mmxw)
+// store_slice_c(dst + mmxw, src + mmxw, dst_stride, src_stride, width - mmxw, log2_scale);
+}
+#endif
+
+static void (*store_slice)(uint8_t *dst, int16_t *src, int dst_stride, int src_stride, int width, int height, int log2_scale)= store_slice_c;
+
+static void (*requantize)(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *permutation)= hardthresh_c;
+
+static void filter(struct vf_priv_s *p, uint8_t *dst, uint8_t *src, int dst_stride, int src_stride, int width, int height, uint8_t *qp_store, int qp_stride, int is_luma){
+ int x, y, i;
+ const int count= 1<<p->log2_count;
+ const int stride= is_luma ? p->temp_stride : ((width+16+15)&(~15));
+ uint64_t __attribute__((aligned(16))) block_align[32];
+ DCTELEM *block = (DCTELEM *)block_align;
+ DCTELEM *block2= (DCTELEM *)(block_align+16);
+
+ if (!src || !dst) return; // HACK avoid crash for Y8 colourspace
+ for(y=0; y<height; y++){
+ int index= 8 + 8*stride + y*stride;
+ fast_memcpy(p->src + index, src + y*src_stride, width);
+ for(x=0; x<8; x++){
+ p->src[index - x - 1]= p->src[index + x ];
+ p->src[index + width + x ]= p->src[index + width - x - 1];
+ }
+ }
+ for(y=0; y<8; y++){
+ fast_memcpy(p->src + ( 7-y)*stride, p->src + ( y+8)*stride, stride);
+ fast_memcpy(p->src + (height+8+y)*stride, p->src + (height-y+7)*stride, stride);
+ }
+ //FIXME (try edge emu)
+
+ for(y=0; y<height+8; y+=8){
+ memset(p->temp + (8+y)*stride, 0, 8*stride*sizeof(int16_t));
+ for(x=0; x<width+8; x+=8){
+ const int qps= 3 + is_luma;
+ int qp;
+
+ if(p->qp)
+ qp= p->qp;
+ else{
+ qp= qp_store[ (XMIN(x, width-1)>>qps) + (XMIN(y, height-1)>>qps) * qp_stride];
+ qp = FFMAX(1, norm_qscale(qp, p->mpeg2));
+ }
+ for(i=0; i<count; i++){
+ const int x1= x + offset[i+count-1][0];
+ const int y1= y + offset[i+count-1][1];
+ const int index= x1 + y1*stride;
+ p->dsp.get_pixels(block, p->src + index, stride);
+ p->dsp.fdct(block);
+ requantize(block2, block, qp, p->dsp.idct_permutation);
+ p->dsp.idct(block2);
+ add_block(p->temp + index, stride, block2);
+ }
+ }
+ if(y)
+ store_slice(dst + (y-8)*dst_stride, p->temp + 8 + y*stride, dst_stride, stride, width, XMIN(8, height+8-y), 6-p->log2_count);
+ }
+#if 0
+ for(y=0; y<height; y++){
+ for(x=0; x<width; x++){
+ if((((x>>6) ^ (y>>6)) & 1) == 0)
+ dst[x + y*dst_stride]= p->src[8 + 8*stride + x + y*stride];
+ if((x&63) == 0 || (y&63)==0)
+ dst[x + y*dst_stride] += 128;
+ }
+ }
+#endif
+ //FIXME reorder for better caching
+}
+
+static int config(struct vf_instance *vf,
+ int width, int height, int d_width, int d_height,
+ unsigned int flags, unsigned int outfmt){
+ int h= (height+16+15)&(~15);
+
+ vf->priv->temp_stride= (width+16+15)&(~15);
+ vf->priv->temp= malloc(vf->priv->temp_stride*h*sizeof(int16_t));
+ vf->priv->src = malloc(vf->priv->temp_stride*h*sizeof(uint8_t));
+
+ return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
+}
+
+static void get_image(struct vf_instance *vf, mp_image_t *mpi){
+ if(mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change
+ // ok, we can do pp in-place (or pp disabled):
+ vf->dmpi=vf_get_image(vf->next,mpi->imgfmt,
+ mpi->type, mpi->flags | MP_IMGFLAG_READABLE, mpi->width, mpi->height);
+ mpi->planes[0]=vf->dmpi->planes[0];
+ mpi->stride[0]=vf->dmpi->stride[0];
+ mpi->width=vf->dmpi->width;
+ if(mpi->flags&MP_IMGFLAG_PLANAR){
+ mpi->planes[1]=vf->dmpi->planes[1];
+ mpi->planes[2]=vf->dmpi->planes[2];
+ mpi->stride[1]=vf->dmpi->stride[1];
+ mpi->stride[2]=vf->dmpi->stride[2];
+ }
+ mpi->flags|=MP_IMGFLAG_DIRECT;
+}
+
+static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
+ mp_image_t *dmpi;
+
+ if(!(mpi->flags&MP_IMGFLAG_DIRECT)){
+ // no DR, so get a new image! hope we'll get DR buffer:
+ dmpi=vf_get_image(vf->next,mpi->imgfmt,
+ MP_IMGTYPE_TEMP,
+ MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE,
+ mpi->width,mpi->height);
+ vf_clone_mpi_attributes(dmpi, mpi);
+ }else{
+ dmpi=vf->dmpi;
+ }
+
+ vf->priv->mpeg2= mpi->qscale_type;
+ if(mpi->pict_type != 3 && mpi->qscale && !vf->priv->qp){
+ int w = mpi->qstride;
+ int h = (mpi->h + 15) >> 4;
+ if (!w) {
+ w = (mpi->w + 15) >> 4;
+ h = 1;
+ }
+ if(!vf->priv->non_b_qp)
+ vf->priv->non_b_qp= malloc(w*h);
+ fast_memcpy(vf->priv->non_b_qp, mpi->qscale, w*h);
+ }
+ if(vf->priv->log2_count || !(mpi->flags&MP_IMGFLAG_DIRECT)){
+ char *qp_tab= vf->priv->non_b_qp;
+ if((vf->priv->mode&4) || !qp_tab)
+ qp_tab= mpi->qscale;
+
+ if(qp_tab || vf->priv->qp){
+ filter(vf->priv, dmpi->planes[0], mpi->planes[0], dmpi->stride[0], mpi->stride[0], mpi->w, mpi->h, qp_tab, mpi->qstride, 1);
+ filter(vf->priv, dmpi->planes[1], mpi->planes[1], dmpi->stride[1], mpi->stride[1], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, qp_tab, mpi->qstride, 0);
+ filter(vf->priv, dmpi->planes[2], mpi->planes[2], dmpi->stride[2], mpi->stride[2], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, qp_tab, mpi->qstride, 0);
+ }else{
+ memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h, dmpi->stride[0], mpi->stride[0]);
+ memcpy_pic(dmpi->planes[1], mpi->planes[1], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, dmpi->stride[1], mpi->stride[1]);
+ memcpy_pic(dmpi->planes[2], mpi->planes[2], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, dmpi->stride[2], mpi->stride[2]);
+ }
+ }
+
+#if HAVE_MMX
+ if(gCpuCaps.hasMMX) __asm__ volatile ("emms\n\t");
+#endif
+#if HAVE_MMX2
+ if(gCpuCaps.hasMMX2) __asm__ volatile ("sfence\n\t");
+#endif
+
+ return vf_next_put_image(vf,dmpi, pts);
+}
+
+static void uninit(struct vf_instance *vf){
+ if(!vf->priv) return;
+
+ free(vf->priv->temp);
+ vf->priv->temp= NULL;
+ free(vf->priv->src);
+ vf->priv->src= NULL;
+ free(vf->priv->avctx);
+ vf->priv->avctx= NULL;
+ free(vf->priv->non_b_qp);
+ vf->priv->non_b_qp= NULL;
+
+ free(vf->priv);
+ vf->priv=NULL;
+}
+
+//===========================================================================//
+static int query_format(struct vf_instance *vf, unsigned int fmt){
+ switch(fmt){
+ case IMGFMT_YVU9:
+ case IMGFMT_IF09:
+ case IMGFMT_YV12:
+ case IMGFMT_I420:
+ case IMGFMT_IYUV:
+ case IMGFMT_CLPL:
+ case IMGFMT_Y800:
+ case IMGFMT_Y8:
+ case IMGFMT_444P:
+ case IMGFMT_422P:
+ case IMGFMT_411P:
+ return vf_next_query_format(vf,fmt);
+ }
+ return 0;
+}
+
+static int control(struct vf_instance *vf, int request, void* data){
+ switch(request){
+ case VFCTRL_QUERY_MAX_PP_LEVEL:
+ return 6;
+ case VFCTRL_SET_PP_LEVEL:
+ vf->priv->log2_count= *((unsigned int*)data);
+ return CONTROL_TRUE;
+ }
+ return vf_next_control(vf,request,data);
+}
+
+static int vf_open(vf_instance_t *vf, char *args){
+
+ int log2c=-1;
+
+ vf->config=config;
+ vf->put_image=put_image;
+ vf->get_image=get_image;
+ vf->query_format=query_format;
+ vf->uninit=uninit;
+ vf->control= control;
+ vf->priv=malloc(sizeof(struct vf_priv_s));
+ memset(vf->priv, 0, sizeof(struct vf_priv_s));
+
+ init_avcodec();
+
+ vf->priv->avctx= avcodec_alloc_context();
+ dsputil_init(&vf->priv->dsp, vf->priv->avctx);
+
+ vf->priv->log2_count= 3;
+
+ if (args) sscanf(args, "%d:%d:%d", &log2c, &vf->priv->qp, &vf->priv->mode);
+
+ if( log2c >=0 && log2c <=6 )
+ vf->priv->log2_count = log2c;
+
+ if(vf->priv->qp < 0)
+ vf->priv->qp = 0;
+
+ switch(vf->priv->mode&3){
+ default:
+ case 0: requantize= hardthresh_c; break;
+ case 1: requantize= softthresh_c; break;
+ }
+
+#if HAVE_MMX
+ if(gCpuCaps.hasMMX){
+ store_slice= store_slice_mmx;
+ switch(vf->priv->mode&3){
+ case 0: requantize= hardthresh_mmx; break;
+ case 1: requantize= softthresh_mmx; break;
+ }
+ }
+#endif
+
+ return 1;
+}
+
+const vf_info_t vf_info_spp = {
+ "simple postprocess",
+ "spp",
+ "Michael Niedermayer",
+ "",
+ vf_open,
+ NULL
+};
diff --git a/libavfilter/libmpcodecs/vf_stereo3d.c b/libavfilter/libmpcodecs/vf_stereo3d.c
new file mode 100644
index 0000000000..b8bc390cfe
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_stereo3d.c
@@ -0,0 +1,512 @@
+/*
+ * Copyright (C) 2010 Gordon Schmidt <gordon.schmidt <at> s2000.tu-chemnitz.de>
+ *
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+//==includes==//
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "config.h"
+#include "mp_msg.h"
+#include "help_mp.h"
+
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+
+#include "libavutil/common.h"
+#include "libvo/fastmemcpy.h"
+
+//==types==//
+typedef enum stereo_code {
+ ANAGLYPH_RC_GRAY, //anaglyph red/cyan gray
+ ANAGLYPH_RC_HALF, //anaglyph red/cyan half colored
+ ANAGLYPH_RC_COLOR, //anaglyph red/cyan colored
+ ANAGLYPH_RC_DUBOIS, //anaglyph red/cyan dubois
+ ANAGLYPH_GM_GRAY, //anaglyph green/magenta gray
+ ANAGLYPH_GM_HALF, //anaglyph green/magenta half colored
+ ANAGLYPH_GM_COLOR, //anaglyph green/magenta colored
+ ANAGLYPH_YB_GRAY, //anaglyph yellow/blue gray
+ ANAGLYPH_YB_HALF, //anaglyph yellow/blue half colored
+ ANAGLYPH_YB_COLOR, //anaglyph yellow/blue colored
+ MONO_L, //mono output for debugging (left eye only)
+ MONO_R, //mono output for debugging (right eye only)
+ SIDE_BY_SIDE_LR, //side by side parallel (left eye left, right eye right)
+ SIDE_BY_SIDE_RL, //side by side crosseye (right eye left, left eye right)
+ SIDE_BY_SIDE_2_LR, //side by side parallel with half width resolution
+ SIDE_BY_SIDE_2_RL, //side by side crosseye with half width resolution
+ ABOVE_BELOW_LR, //above-below (left eye above, right eye below)
+ ABOVE_BELOW_RL, //above-below (right eye above, left eye below)
+ ABOVE_BELOW_2_LR, //above-below with half height resolution
+ ABOVE_BELOW_2_RL, //above-below with half height resolution
+ INTERLEAVE_ROWS_LR, //row-interleave (left eye has top row)
+ INTERLEAVE_ROWS_RL, //row-interleave (right eye has top row)
+ STEREO_CODE_COUNT //no value set - TODO: needs autodetection
+} stereo_code;
+
+typedef struct component {
+ stereo_code fmt;
+ unsigned int width;
+ unsigned int height;
+ unsigned int off_left;
+ unsigned int off_right;
+ unsigned int row_left;
+ unsigned int row_right;
+} component;
+
+//==global variables==//
+static const int ana_coeff[10][3][6] = {
+ {{19595, 38470, 7471, 0, 0, 0}, //ANAGLYPH_RC_GRAY
+ { 0, 0, 0, 19595, 38470, 7471},
+ { 0, 0, 0, 19595, 38470, 7471}},
+ {{19595, 38470, 7471, 0, 0, 0}, //ANAGLYPH_RC_HALF
+ { 0, 0, 0, 0, 65536, 0},
+ { 0, 0, 0, 0, 0, 65536}},
+ {{65536, 0, 0, 0, 0, 0}, //ANAGLYPH_RC_COLOR
+ { 0, 0, 0, 0, 65536, 0},
+ { 0, 0, 0, 0, 0, 65536}},
+ {{29891, 32800, 11559, -2849, -5763, -102}, //ANAGLYPH_RC_DUBOIS
+ {-2627, -2479, -1033, 24804, 48080, -1209},
+ { -997, -1350, -358, -4729, -7403, 80373}},
+ {{ 0, 0, 0, 19595, 38470, 7471}, //ANAGLYPH_GM_GRAY
+ {19595, 38470, 7471, 0, 0, 0},
+ { 0, 0, 0, 19595, 38470, 7471}},
+ {{ 0, 0, 0, 65536, 0, 0}, //ANAGLYPH_GM_HALF
+ {19595, 38470, 7471, 0, 0, 0},
+ { 0, 0, 0, 0, 0, 65536}},
+ {{ 0, 0, 0, 65536, 0, 0}, //ANAGLYPH_GM_COLOR
+ { 0, 65536, 0, 0, 0, 0},
+ { 0, 0, 0, 0, 0, 65536}},
+ {{ 0, 0, 0, 19595, 38470, 7471}, //ANAGLYPH_YB_GRAY
+ { 0, 0, 0, 19595, 38470, 7471},
+ {19595, 38470, 7471, 0, 0, 0}},
+ {{ 0, 0, 0, 65536, 0, 0}, //ANAGLYPH_YB_HALF
+ { 0, 0, 0, 0, 65536, 0},
+ {19595, 38470, 7471, 0, 0, 0}},
+ {{ 0, 0, 0, 65536, 0, 0}, //ANAGLYPH_YB_COLOR
+ { 0, 0, 0, 0, 65536, 0},
+ { 0, 0, 65536, 0, 0, 0}}
+};
+
+struct vf_priv_s {
+ component in;
+ component out;
+ int ana_matrix[3][6];
+ unsigned int width;
+ unsigned int height;
+ unsigned int row_step;
+} const vf_priv_default = {
+ {SIDE_BY_SIDE_LR},
+ {ANAGLYPH_RC_DUBOIS}
+};
+
+//==functions==//
+static inline uint8_t ana_convert(int coeff[6], uint8_t left[3], uint8_t right[3])
+{
+ int sum;
+
+ sum = coeff[0] * left[0] + coeff[3] * right[0]; //red in
+ sum += coeff[1] * left[1] + coeff[4] * right[1]; //green in
+ sum += coeff[2] * left[2] + coeff[5] * right[2]; //blue in
+ return av_clip_uint8(sum >> 16);
+}
+
+static int config(struct vf_instance *vf, int width, int height, int d_width,
+ int d_height, unsigned int flags, unsigned int outfmt)
+{
+ if ((width & 1) || (height & 1)) {
+ mp_msg(MSGT_VFILTER, MSGL_WARN, "[stereo3d] invalid height or width\n");
+ return 0;
+ }
+ //default input values
+ vf->priv->width = width;
+ vf->priv->height = height;
+ vf->priv->row_step = 1;
+ vf->priv->in.width = width;
+ vf->priv->in.height = height;
+ vf->priv->in.off_left = 0;
+ vf->priv->in.off_right = 0;
+ vf->priv->in.row_left = 0;
+ vf->priv->in.row_right = 0;
+
+ //check input format
+ switch (vf->priv->in.fmt) {
+ case SIDE_BY_SIDE_2_LR:
+ d_width *= 2;
+ case SIDE_BY_SIDE_LR:
+ vf->priv->width = width / 2;
+ vf->priv->in.off_right = vf->priv->width * 3;
+ break;
+ case SIDE_BY_SIDE_2_RL:
+ d_width *= 2;
+ case SIDE_BY_SIDE_RL:
+ vf->priv->width = width / 2;
+ vf->priv->in.off_left = vf->priv->width * 3;
+ break;
+ case ABOVE_BELOW_2_LR:
+ d_height *= 2;
+ case ABOVE_BELOW_LR:
+ vf->priv->height = height / 2;
+ vf->priv->in.row_right = vf->priv->height;
+ break;
+ case ABOVE_BELOW_2_RL:
+ d_height *= 2;
+ case ABOVE_BELOW_RL:
+ vf->priv->height = height / 2;
+ vf->priv->in.row_left = vf->priv->height;
+ break;
+ default:
+ mp_msg(MSGT_VFILTER, MSGL_WARN,
+ "[stereo3d] stereo format of input is not supported\n");
+ return 0;
+ break;
+ }
+ //default output values
+ vf->priv->out.width = vf->priv->width;
+ vf->priv->out.height = vf->priv->height;
+ vf->priv->out.off_left = 0;
+ vf->priv->out.off_right = 0;
+ vf->priv->out.row_left = 0;
+ vf->priv->out.row_right = 0;
+
+ //check output format
+ switch (vf->priv->out.fmt) {
+ case ANAGLYPH_RC_GRAY:
+ case ANAGLYPH_RC_HALF:
+ case ANAGLYPH_RC_COLOR:
+ case ANAGLYPH_RC_DUBOIS:
+ case ANAGLYPH_GM_GRAY:
+ case ANAGLYPH_GM_HALF:
+ case ANAGLYPH_GM_COLOR:
+ case ANAGLYPH_YB_GRAY:
+ case ANAGLYPH_YB_HALF:
+ case ANAGLYPH_YB_COLOR:
+ memcpy(vf->priv->ana_matrix, ana_coeff[vf->priv->out.fmt],
+ sizeof(vf->priv->ana_matrix));
+ break;
+ case SIDE_BY_SIDE_2_LR:
+ d_width /= 2;
+ case SIDE_BY_SIDE_LR:
+ vf->priv->out.width = vf->priv->width * 2;
+ vf->priv->out.off_right = vf->priv->width * 3;
+ break;
+ case SIDE_BY_SIDE_2_RL:
+ d_width /= 2;
+ case SIDE_BY_SIDE_RL:
+ vf->priv->out.width = vf->priv->width * 2;
+ vf->priv->out.off_left = vf->priv->width * 3;
+ break;
+ case ABOVE_BELOW_2_LR:
+ d_height /= 2;
+ case ABOVE_BELOW_LR:
+ vf->priv->out.height = vf->priv->height * 2;
+ vf->priv->out.row_right = vf->priv->height;
+ break;
+ case ABOVE_BELOW_2_RL:
+ d_height /= 2;
+ case ABOVE_BELOW_RL:
+ vf->priv->out.height = vf->priv->height * 2;
+ vf->priv->out.row_left = vf->priv->height;
+ break;
+ case INTERLEAVE_ROWS_LR:
+ vf->priv->row_step = 2;
+ vf->priv->height = vf->priv->height / 2;
+ vf->priv->out.off_right = vf->priv->width * 3;
+ vf->priv->in.off_right += vf->priv->in.width * 3;
+ break;
+ case INTERLEAVE_ROWS_RL:
+ vf->priv->row_step = 2;
+ vf->priv->height = vf->priv->height / 2;
+ vf->priv->out.off_left = vf->priv->width * 3;
+ vf->priv->in.off_left += vf->priv->in.width * 3;
+ break;
+ case MONO_R:
+ //same as MONO_L only needs switching of input offsets
+ vf->priv->in.off_left = vf->priv->in.off_right;
+ vf->priv->in.row_left = vf->priv->in.row_right;
+ //nobreak;
+ case MONO_L:
+ //use default settings
+ break;
+ default:
+ mp_msg(MSGT_VFILTER, MSGL_WARN,
+ "[stereo3d] stereo format of output is not supported\n");
+ return 0;
+ break;
+ }
+// if (!opt_screen_size_x && !opt_screen_size_y) {
+ d_width = d_width * vf->priv->out.width / width;
+ d_height = d_height * vf->priv->out.height / height;
+// }
+
+ return vf_next_config(vf, vf->priv->out.width, vf->priv->out.height,
+ d_width, d_height, flags, outfmt);
+}
+
+static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
+{
+ mp_image_t *dmpi;
+ if (vf->priv->in.fmt == vf->priv->out.fmt) { //nothing to do
+ dmpi = mpi;
+ } else {
+ int out_off_left, out_off_right;
+ int in_off_left = vf->priv->in.row_left * mpi->stride[0] +
+ vf->priv->in.off_left;
+ int in_off_right = vf->priv->in.row_right * mpi->stride[0] +
+ vf->priv->in.off_right;
+
+ dmpi = vf_get_image(vf->next, IMGFMT_RGB24, MP_IMGTYPE_TEMP,
+ MP_IMGFLAG_ACCEPT_STRIDE,
+ vf->priv->out.width, vf->priv->out.height);
+ out_off_left = vf->priv->out.row_left * dmpi->stride[0] +
+ vf->priv->out.off_left;
+ out_off_right = vf->priv->out.row_right * dmpi->stride[0] +
+ vf->priv->out.off_right;
+
+ switch (vf->priv->out.fmt) {
+ case SIDE_BY_SIDE_LR:
+ case SIDE_BY_SIDE_RL:
+ case SIDE_BY_SIDE_2_LR:
+ case SIDE_BY_SIDE_2_RL:
+ case ABOVE_BELOW_LR:
+ case ABOVE_BELOW_RL:
+ case ABOVE_BELOW_2_LR:
+ case ABOVE_BELOW_2_RL:
+ case INTERLEAVE_ROWS_LR:
+ case INTERLEAVE_ROWS_RL:
+ memcpy_pic2(dmpi->planes[0] + out_off_left,
+ mpi->planes[0] + in_off_left,
+ 3 * vf->priv->width,
+ vf->priv->height,
+ dmpi->stride[0] * vf->priv->row_step,
+ mpi->stride[0] * vf->priv->row_step,
+ vf->priv->row_step != 1);
+ memcpy_pic2(dmpi->planes[0] + out_off_right,
+ mpi->planes[0] + in_off_right,
+ 3 * vf->priv->width,
+ vf->priv->height,
+ dmpi->stride[0] * vf->priv->row_step,
+ mpi->stride[0] * vf->priv->row_step,
+ vf->priv->row_step != 1);
+ break;
+ case MONO_L:
+ case MONO_R:
+ memcpy_pic(dmpi->planes[0],
+ mpi->planes[0] + in_off_left,
+ 3 * vf->priv->width,
+ vf->priv->height,
+ dmpi->stride[0],
+ mpi->stride[0]);
+ break;
+ case ANAGLYPH_RC_GRAY:
+ case ANAGLYPH_RC_HALF:
+ case ANAGLYPH_RC_COLOR:
+ case ANAGLYPH_RC_DUBOIS:
+ case ANAGLYPH_GM_GRAY:
+ case ANAGLYPH_GM_HALF:
+ case ANAGLYPH_GM_COLOR:
+ case ANAGLYPH_YB_GRAY:
+ case ANAGLYPH_YB_HALF:
+ case ANAGLYPH_YB_COLOR: {
+ int i,x,y,il,ir,o;
+ unsigned char *source = mpi->planes[0];
+ unsigned char *dest = dmpi->planes[0];
+ unsigned int out_width = vf->priv->out.width;
+ int *ana_matrix[3];
+
+ for(i = 0; i < 3; i++)
+ ana_matrix[i] = vf->priv->ana_matrix[i];
+
+ for (y = 0; y < vf->priv->out.height; y++) {
+ o = dmpi->stride[0] * y;
+ il = in_off_left + y * mpi->stride[0];
+ ir = in_off_right + y * mpi->stride[0];
+ for (x = 0; x < out_width; x++) {
+ dest[o ] = ana_convert(
+ ana_matrix[0], source + il, source + ir); //red out
+ dest[o + 1] = ana_convert(
+ ana_matrix[1], source + il, source + ir); //green out
+ dest[o + 2] = ana_convert(
+ ana_matrix[2], source + il, source + ir); //blue out
+ il += 3;
+ ir += 3;
+ o += 3;
+ }
+ }
+ break;
+ }
+ default:
+ mp_msg(MSGT_VFILTER, MSGL_WARN,
+ "[stereo3d] stereo format of output is not supported\n");
+ return 0;
+ break;
+ }
+ }
+ return vf_next_put_image(vf, dmpi, pts);
+}
+
+static int query_format(struct vf_instance *vf, unsigned int fmt)
+{
+ switch (fmt)
+ case IMGFMT_RGB24:
+ return vf_next_query_format(vf, fmt);
+ return 0;
+}
+
+static void uninit(vf_instance_t *vf)
+{
+ free(vf->priv);
+}
+
+static int vf_open(vf_instance_t *vf, char *args)
+{
+ vf->config = config;
+ vf->uninit = uninit;
+ vf->put_image = put_image;
+ vf->query_format = query_format;
+ vf->priv=malloc(sizeof(struct vf_priv_s));
+ memset(vf->priv, 0, sizeof(struct vf_priv_s));
+
+ vf->priv->in.fmt = SIDE_BY_SIDE_LR;
+ vf->priv->out.fmt= ANAGLYPH_RC_DUBOIS;
+ if (args) sscanf(args, "%d:%d", &vf->priv->in.fmt, &vf->priv->out.fmt);
+
+ return 1;
+}
+#if 0
+///Presets usage
+static const struct format_preset {
+ char* name;
+ stereo_code scode;
+} vf_format_presets_defs[] = {
+ {"arcg", ANAGLYPH_RC_GRAY},
+ {"anaglyph_red_cyan_gray", ANAGLYPH_RC_GRAY},
+ {"arch", ANAGLYPH_RC_HALF},
+ {"anaglyph_red_cyan_half_color", ANAGLYPH_RC_HALF},
+ {"arcc", ANAGLYPH_RC_COLOR},
+ {"anaglyph_red_cyan_color", ANAGLYPH_RC_COLOR},
+ {"arcd", ANAGLYPH_RC_DUBOIS},
+ {"anaglyph_red_cyan_dubios", ANAGLYPH_RC_DUBOIS},
+ {"agmg", ANAGLYPH_GM_GRAY},
+ {"anaglyph_green_magenta_gray", ANAGLYPH_GM_GRAY},
+ {"agmh", ANAGLYPH_GM_HALF},
+ {"anaglyph_green_magenta_half_color",ANAGLYPH_GM_HALF},
+ {"agmc", ANAGLYPH_GM_COLOR},
+ {"anaglyph_green_magenta_color", ANAGLYPH_GM_COLOR},
+ {"aybg", ANAGLYPH_YB_GRAY},
+ {"anaglyph_yellow_blue_gray", ANAGLYPH_YB_GRAY},
+ {"aybh", ANAGLYPH_YB_HALF},
+ {"anaglyph_yellow_blue_half_color", ANAGLYPH_YB_HALF},
+ {"aybc", ANAGLYPH_YB_COLOR},
+ {"anaglyph_yellow_blue_color", ANAGLYPH_YB_COLOR},
+ {"ml", MONO_L},
+ {"mono_left", MONO_L},
+ {"mr", MONO_R},
+ {"mono_right", MONO_R},
+ {"sbsl", SIDE_BY_SIDE_LR},
+ {"side_by_side_left_first", SIDE_BY_SIDE_LR},
+ {"sbsr", SIDE_BY_SIDE_RL},
+ {"side_by_side_right_first", SIDE_BY_SIDE_RL},
+ {"sbs2l", SIDE_BY_SIDE_2_LR},
+ {"side_by_side_half_width_left_first", SIDE_BY_SIDE_2_LR},
+ {"sbs2r", SIDE_BY_SIDE_2_RL},
+ {"side_by_side_half_width_right_first",SIDE_BY_SIDE_2_RL},
+ {"abl", ABOVE_BELOW_LR},
+ {"above_below_left_first", ABOVE_BELOW_LR},
+ {"abr", ABOVE_BELOW_RL},
+ {"above_below_right_first", ABOVE_BELOW_RL},
+ {"ab2l", ABOVE_BELOW_2_LR},
+ {"above_below_half_height_left_first", ABOVE_BELOW_2_LR},
+ {"ab2r", ABOVE_BELOW_2_RL},
+ {"above_below_half_height_right_first",ABOVE_BELOW_2_RL},
+ {"irl", INTERLEAVE_ROWS_LR},
+ {"interleave_rows_left_first", INTERLEAVE_ROWS_LR},
+ {"irr", INTERLEAVE_ROWS_RL},
+ {"interleave_rows_right_first", INTERLEAVE_ROWS_RL},
+ { NULL, 0}
+};
+
+#define ST_OFF(f) M_ST_OFF(struct format_preset,f)
+static const m_option_t vf_format_preset_fields_in[] = {
+ {"in", ST_OFF(scode), CONF_TYPE_INT, 0,0,0, NULL},
+ { NULL, NULL, 0, 0, 0, 0, NULL }
+};
+static const m_option_t vf_format_preset_fields_out[] = {
+ {"out", ST_OFF(scode), CONF_TYPE_INT, 0,0,0, NULL},
+ { NULL, NULL, 0, 0, 0, 0, NULL }
+};
+
+static const m_struct_t vf_format_preset_in = {
+ "stereo_format_preset_in",
+ sizeof(struct format_preset),
+ NULL,
+ vf_format_preset_fields_in
+};
+static const m_struct_t vf_format_preset_out = {
+ "stereo_format_preset_out",
+ sizeof(struct format_preset),
+ NULL,
+ vf_format_preset_fields_out
+};
+
+static const m_struct_t vf_opts;
+static const m_obj_presets_t format_preset_in = {
+ (struct m_struct_st*)&vf_format_preset_in,
+ (struct m_struct_st*)&vf_opts,
+ (struct format_preset*)vf_format_presets_defs,
+ ST_OFF(name)
+};
+static const m_obj_presets_t format_preset_out = {
+ (struct m_struct_st*)&vf_format_preset_out,
+ (struct m_struct_st*)&vf_opts,
+ (struct format_preset*)vf_format_presets_defs,
+ ST_OFF(name)
+};
+
+/// Now the options
+#undef ST_OFF
+#define ST_OFF(f) M_ST_OFF(struct vf_priv_s,f)
+static const m_option_t vf_opts_fields[] = {
+ {"stereo_in", 0, CONF_TYPE_OBJ_PRESETS, 0, 0, 0,
+ (m_obj_presets_t*)&format_preset_in},
+ {"stereo_out", 0, CONF_TYPE_OBJ_PRESETS, 0, 0, 0,
+ (m_obj_presets_t*)&format_preset_out},
+ {"in", ST_OFF(in.fmt), CONF_TYPE_INT, 0,0,0, NULL},
+ {"out", ST_OFF(out.fmt), CONF_TYPE_INT, 0,0,0, NULL},
+ { NULL, NULL, 0, 0, 0, 0, NULL }
+};
+
+static const m_struct_t vf_opts = {
+ "stereo3d",
+ sizeof(struct vf_priv_s),
+ &vf_priv_default,
+ vf_opts_fields
+};
+#endif
+
+//==info struct==//
+const vf_info_t vf_info_stereo3d = {
+ "stereoscopic 3d view",
+ "stereo3d",
+ "Gordon Schmidt",
+ "view stereoscopic videos",
+ vf_open,
+// &vf_opts
+};
diff --git a/libavfilter/libmpcodecs/vf_swapuv.c b/libavfilter/libmpcodecs/vf_swapuv.c
new file mode 100644
index 0000000000..4d0e8fcb16
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_swapuv.c
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2002 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+#include <assert.h>
+
+#include "mp_msg.h"
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+
+
+//===========================================================================//
+
+static void get_image(struct vf_instance *vf, mp_image_t *mpi){
+ mp_image_t *dmpi= vf_get_image(vf->next, mpi->imgfmt,
+ mpi->type, mpi->flags, mpi->w, mpi->h);
+
+ mpi->planes[0]=dmpi->planes[0];
+ mpi->planes[1]=dmpi->planes[2];
+ mpi->planes[2]=dmpi->planes[1];
+ mpi->stride[0]=dmpi->stride[0];
+ mpi->stride[1]=dmpi->stride[2];
+ mpi->stride[2]=dmpi->stride[1];
+ mpi->width=dmpi->width;
+
+ mpi->flags|=MP_IMGFLAG_DIRECT;
+ mpi->priv=(void*)dmpi;
+}
+
+static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
+ mp_image_t *dmpi;
+
+ if(mpi->flags&MP_IMGFLAG_DIRECT){
+ dmpi=(mp_image_t*)mpi->priv;
+ } else {
+ dmpi=vf_get_image(vf->next, mpi->imgfmt, MP_IMGTYPE_EXPORT, 0, mpi->w, mpi->h);
+ assert(mpi->flags&MP_IMGFLAG_PLANAR);
+ dmpi->planes[0]=mpi->planes[0];
+ dmpi->planes[1]=mpi->planes[2];
+ dmpi->planes[2]=mpi->planes[1];
+ dmpi->stride[0]=mpi->stride[0];
+ dmpi->stride[1]=mpi->stride[2];
+ dmpi->stride[2]=mpi->stride[1];
+ dmpi->width=mpi->width;
+ }
+
+ vf_clone_mpi_attributes(dmpi, mpi);
+
+ return vf_next_put_image(vf,dmpi, pts);
+}
+
+//===========================================================================//
+
+static int query_format(struct vf_instance *vf, unsigned int fmt){
+ switch(fmt)
+ {
+ case IMGFMT_YV12:
+ case IMGFMT_I420:
+ case IMGFMT_IYUV:
+ case IMGFMT_YVU9:
+ case IMGFMT_444P:
+ case IMGFMT_422P:
+ case IMGFMT_411P:
+ return vf_next_query_format(vf, fmt);
+ }
+ return 0;
+}
+
+static int vf_open(vf_instance_t *vf, char *args){
+ vf->put_image=put_image;
+ vf->get_image=get_image;
+ vf->query_format=query_format;
+ return 1;
+}
+
+const vf_info_t vf_info_swapuv = {
+ "UV swapper",
+ "swapuv",
+ "Michael Niedermayer",
+ "",
+ vf_open,
+ NULL
+};
+
+//===========================================================================//
diff --git a/libavfilter/libmpcodecs/vf_telecine.c b/libavfilter/libmpcodecs/vf_telecine.c
new file mode 100644
index 0000000000..3b92518c84
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_telecine.c
@@ -0,0 +1,155 @@
+/*
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "config.h"
+#include "mp_msg.h"
+
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+
+#include "libvo/fastmemcpy.h"
+
+struct vf_priv_s {
+ int frame;
+};
+
+static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
+{
+ mp_image_t *dmpi;
+ int ret;
+
+ vf->priv->frame = (vf->priv->frame+1)%4;
+
+ dmpi = vf_get_image(vf->next, mpi->imgfmt,
+ MP_IMGTYPE_STATIC, MP_IMGFLAG_ACCEPT_STRIDE |
+ MP_IMGFLAG_PRESERVE, mpi->width, mpi->height);
+
+ ret = 0;
+ // 0/0 1/1 2/2 2/3 3/0
+ switch (vf->priv->frame) {
+ case 0:
+ my_memcpy_pic(dmpi->planes[0]+dmpi->stride[0],
+ mpi->planes[0]+mpi->stride[0], mpi->w, mpi->h/2,
+ dmpi->stride[0]*2, mpi->stride[0]*2);
+ if (mpi->flags & MP_IMGFLAG_PLANAR) {
+ my_memcpy_pic(dmpi->planes[1]+dmpi->stride[1],
+ mpi->planes[1]+mpi->stride[1],
+ mpi->chroma_width, mpi->chroma_height/2,
+ dmpi->stride[1]*2, mpi->stride[1]*2);
+ my_memcpy_pic(dmpi->planes[2]+dmpi->stride[2],
+ mpi->planes[2]+mpi->stride[2],
+ mpi->chroma_width, mpi->chroma_height/2,
+ dmpi->stride[2]*2, mpi->stride[2]*2);
+ }
+ ret = vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE);
+ case 1:
+ case 2:
+ memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h,
+ dmpi->stride[0], mpi->stride[0]);
+ if (mpi->flags & MP_IMGFLAG_PLANAR) {
+ memcpy_pic(dmpi->planes[1], mpi->planes[1],
+ mpi->chroma_width, mpi->chroma_height,
+ dmpi->stride[1], mpi->stride[1]);
+ memcpy_pic(dmpi->planes[2], mpi->planes[2],
+ mpi->chroma_width, mpi->chroma_height,
+ dmpi->stride[2], mpi->stride[2]);
+ }
+ return vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE) || ret;
+ case 3:
+ my_memcpy_pic(dmpi->planes[0]+dmpi->stride[0],
+ mpi->planes[0]+mpi->stride[0], mpi->w, mpi->h/2,
+ dmpi->stride[0]*2, mpi->stride[0]*2);
+ if (mpi->flags & MP_IMGFLAG_PLANAR) {
+ my_memcpy_pic(dmpi->planes[1]+dmpi->stride[1],
+ mpi->planes[1]+mpi->stride[1],
+ mpi->chroma_width, mpi->chroma_height/2,
+ dmpi->stride[1]*2, mpi->stride[1]*2);
+ my_memcpy_pic(dmpi->planes[2]+dmpi->stride[2],
+ mpi->planes[2]+mpi->stride[2],
+ mpi->chroma_width, mpi->chroma_height/2,
+ dmpi->stride[2]*2, mpi->stride[2]*2);
+ }
+ ret = vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE);
+ my_memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h/2,
+ dmpi->stride[0]*2, mpi->stride[0]*2);
+ if (mpi->flags & MP_IMGFLAG_PLANAR) {
+ my_memcpy_pic(dmpi->planes[1], mpi->planes[1],
+ mpi->chroma_width, mpi->chroma_height/2,
+ dmpi->stride[1]*2, mpi->stride[1]*2);
+ my_memcpy_pic(dmpi->planes[2], mpi->planes[2],
+ mpi->chroma_width, mpi->chroma_height/2,
+ dmpi->stride[2]*2, mpi->stride[2]*2);
+ }
+ return ret;
+ }
+ return 0;
+}
+
+#if 0
+static int query_format(struct vf_instance *vf, unsigned int fmt)
+{
+ /* FIXME - figure out which other formats work */
+ switch (fmt) {
+ case IMGFMT_YV12:
+ case IMGFMT_IYUV:
+ case IMGFMT_I420:
+ return vf_next_query_format(vf, fmt);
+ }
+ return 0;
+}
+
+static int config(struct vf_instance *vf,
+ int width, int height, int d_width, int d_height,
+ unsigned int flags, unsigned int outfmt)
+{
+ return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
+}
+#endif
+
+static void uninit(struct vf_instance *vf)
+{
+ free(vf->priv);
+}
+
+static int vf_open(vf_instance_t *vf, char *args)
+{
+ //vf->config = config;
+ vf->put_image = put_image;
+ //vf->query_format = query_format;
+ vf->uninit = uninit;
+ vf->default_reqs = VFCAP_ACCEPT_STRIDE;
+ vf->priv = calloc(1, sizeof(struct vf_priv_s));
+ vf->priv->frame = 1;
+ if (args) sscanf(args, "%d", &vf->priv->frame);
+ vf->priv->frame--;
+ return 1;
+}
+
+const vf_info_t vf_info_telecine = {
+ "telecine filter",
+ "telecine",
+ "Rich Felker",
+ "",
+ vf_open,
+ NULL
+};
diff --git a/libavfilter/libmpcodecs/vf_tile.c b/libavfilter/libmpcodecs/vf_tile.c
new file mode 100644
index 0000000000..9ec037ef4c
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_tile.c
@@ -0,0 +1,330 @@
+/*
+ * filter to tile a serie of image in a single, bigger, image
+ *
+ * The parameters are:
+ *
+ * xtile: number of tile on the x axis (5)
+ * ytile: number of tile on the y axis (5)
+ * xytile: when write the image, it can be different then xtile * ytile
+ * (for example you can write 8 * 7 tile, writing the file every
+ * 50 frame, to have one image every 2 seconds @ 25 fps ).
+ * start: pixel at the start (x/y), default 2
+ * delta: pixel between 2 tile, (x/y), default 4
+ *
+ * For example a valid command line is:
+ * ... -vf tile=10:5:-1:4:8 ...
+ * that make images of 10 * 5 tiles, with 4 pixel at the beginning and
+ * 8 pixel between tiles.
+ *
+ * The default command is:
+ * ... -vf tile=5:5:25:2:4
+ *
+ * If you omit a parameter or put a value less then 0, the default is used.
+ * ... -vf tile=10:5::-1:10
+ *
+ * You can also stop when you're ok
+ * ... -vf tile=10:5
+ * (and this is probably the option you will use more often ...)
+ *
+ * Probably is good to put the scale filter before the tile :-)
+ *
+ * copyright (c) 2003 Daniele Forghieri ( guru@digitalfantasy.it )
+ *
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+// strtoi memcpy_pic
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "config.h"
+#include "mp_msg.h"
+#include "help_mp.h"
+#include "cpudetect.h"
+
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+
+#include "libvo/fastmemcpy.h"
+
+/* private data */
+struct vf_priv_s {
+ /* configuration data */
+ /* Number on hor/ver tiles */
+ int xtile;
+ int ytile;
+ /* When write the whole frame (default = xtile * ytile) */
+ int xytile;
+ /* pixel at start / end (default = 4) */
+ int start;
+ /* pixel between image (default = 2) */
+ int delta;
+// /* Background color, in destination format */
+// int bkgSet;
+
+ /* Work data */
+ int frame_cur;
+};
+
+
+static int config(struct vf_instance *vf,
+ int width, int height, int d_width, int d_height,
+ unsigned int flags, unsigned int outfmt){
+
+ struct vf_priv_s *priv;
+ int xw;
+ int yh;
+
+ /* Calculate new destination size */
+ priv = vf->priv;
+ xw = priv->start * 2 +
+ priv->xtile * width +
+ (priv->xtile - 1) * priv->delta;
+ yh = priv->start * 2 +
+ priv->ytile * height +
+ (priv->ytile - 1) * priv->delta;
+
+ mp_msg(MSGT_VFILTER,MSGL_V,"vf_tile:config size set to %d * %d\n", xw, yh);
+
+ return vf_next_config(vf, xw, yh, xw, yh, flags, outfmt);
+}
+
+/* Filter handler */
+static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
+{
+ mp_image_t *dmpi;
+ struct vf_priv_s *priv;
+ int t;
+ int xw;
+ int yh;
+ int xi;
+ int yi;
+ int by;
+ int dw;
+
+ /* Calculate new size */
+ priv = vf->priv;
+ xw = priv->start * 2 +
+ priv->xtile * mpi->w +
+ (priv->xtile - 1) * priv->delta;
+ yh = priv->start * 2 +
+ priv->ytile * mpi->h+
+ (priv->ytile - 1) * priv->delta;
+
+ /* Get the big image! */
+ dmpi=vf_get_image(vf->next, mpi->imgfmt,
+ MP_IMGTYPE_STATIC, MP_IMGFLAG_ACCEPT_STRIDE,
+ xw, yh);
+
+ /* bytes x pixel & bytes x line */
+ if (mpi->flags & MP_IMGFLAG_PLANAR) {
+ by = 1;
+ dw = mpi->w;
+ }
+ else {
+ by = (mpi->bpp + 7) / 8;
+ dw = mpi->w * by;
+ }
+ /* Index position */
+ t = priv->frame_cur % priv->xytile;
+// if ((t == 0) && (bkg != 0)) {
+// /* First frame, delete the background */
+//
+// }
+
+ /* Position of image */
+ xi = priv->start + (mpi->w + priv->delta) * (t % priv->xtile);
+ yi = priv->start + (mpi->h + priv->delta) * (t / priv->xtile);
+
+ /* Copy first (or only) plane */
+ memcpy_pic( dmpi->planes[0] + xi * by + yi * dmpi->stride[0],
+ mpi->planes[0],
+ dw,
+ mpi->h,
+ dmpi->stride[0],
+ mpi->stride[0]);
+
+ if (mpi->flags & MP_IMGFLAG_PLANAR) {
+ /* Copy the other 2 planes */
+ memcpy_pic( dmpi->planes[1] + (xi >> mpi->chroma_x_shift) + (yi >> mpi->chroma_y_shift) * dmpi->stride[1],
+ mpi->planes[1],
+ mpi->chroma_width,
+ mpi->chroma_height,
+ dmpi->stride[1],
+ mpi->stride[1]);
+ memcpy_pic( dmpi->planes[2] + (xi >> mpi->chroma_x_shift) + (yi >> mpi->chroma_y_shift) * dmpi->stride[2],
+ mpi->planes[2],
+ mpi->chroma_width,
+ mpi->chroma_height,
+ dmpi->stride[2],
+ mpi->stride[2]);
+ }
+
+ /* Increment current frame */
+ ++priv->frame_cur;
+
+ if (t == priv->xytile - 1) {
+ /* Display the composition */
+ dmpi->width = xw;
+ dmpi->height = yh;
+ return vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE);
+ }
+ else {
+ /* Skip the frame */
+ return 0;
+ }
+}
+
+static void uninit(struct vf_instance *vf)
+{
+ /* free local data */
+ free(vf->priv);
+}
+
+/* rgb/bgr 12...32 supported & some Yxxx */
+static int query_format(struct vf_instance *vf, unsigned int fmt)
+{
+ switch (fmt) {
+ /* rgb 12...32 bit */
+ case IMGFMT_RGB12:
+ case IMGFMT_RGB15:
+ case IMGFMT_RGB16:
+ case IMGFMT_RGB24:
+ case IMGFMT_RGB32:
+ /* bgr 12...32 bit */
+ case IMGFMT_BGR12:
+ case IMGFMT_BGR15:
+ case IMGFMT_BGR16:
+ case IMGFMT_BGR24:
+ case IMGFMT_BGR32:
+ /* Various Yxxx Formats */
+ case IMGFMT_444P:
+ case IMGFMT_422P:
+ case IMGFMT_411P:
+ case IMGFMT_YUY2:
+ case IMGFMT_YV12:
+ case IMGFMT_I420:
+ case IMGFMT_YVU9:
+ case IMGFMT_IF09:
+ case IMGFMT_IYUV:
+ return vf_next_query_format(vf, fmt);
+ }
+ return 0;
+}
+
+/* Get an integer from the string pointed by s, adjusting s.
+ * If the value is less then 0 def_val is used.
+ * Return 0 for ok
+ *
+ * Look below ( in vf_open(...) ) for a use ...
+ */
+static int parse_int(char **s, int *rt, int def_val)
+{
+
+ int t = 0;
+
+ if (**s) {
+ /* Get value (dec, hex or octal) */
+ t = strtol( *s, s, 0 );
+
+ /* Use default */
+ if (t < 0) {
+ t = def_val;
+ }
+
+ if (**s == ':') {
+ /* Point to next character (problably a digit) */
+ ++(*s);
+ }
+ else if (**s != '\0') {
+ /* Error, we got some wrong char */
+ return 1;
+ }
+ }
+ else {
+ t = def_val;
+ }
+
+ *rt = t;
+ return 0;
+
+}
+
+/* Main entry funct for the filter */
+static int vf_open(vf_instance_t *vf, char *args)
+{
+ struct vf_priv_s *p;
+ int er;
+
+ vf->put_image = put_image;
+ vf->query_format = query_format;
+ vf->config = config;
+ vf->uninit = uninit;
+ vf->default_reqs = VFCAP_ACCEPT_STRIDE;
+ /* Private data */
+ vf->priv = p = calloc(1, sizeof(struct vf_priv_s));
+ if (p == NULL) {
+ return 0;
+ }
+
+ if (args == NULL) {
+ /* Use the default */
+ args = "";
+ }
+ /* Parse all the arguments */
+ er = parse_int( &args, &p->xtile, 5 );
+ er |= parse_int( &args, &p->ytile, 5 );
+ er |= parse_int( &args, &p->xytile, 0 );
+ er |= parse_int( &args, &p->start, 2 );
+ er |= parse_int( &args, &p->delta, 4 );
+// er |= parse_int( &args, &p->bkgSet, 0 );
+
+ if (er) {
+ mp_msg(MSGT_VFILTER, MSGL_ERR, MSGTR_MPCODECS_ErrorParsingArgument);
+ return 0;
+ }
+ /* Load some default */
+ if ((p->xytile <= 0) || (p->xytile > p->xtile * p->ytile)) {
+ p->xytile = p->xtile * p->ytile;
+ }
+
+ /* Say what happen: use mp_msg(...)? */
+ if ( mp_msg_test(MSGT_VFILTER,MSGL_V) ) {
+ printf("vf_tile: tiling %d * %d, output every %d frames\n",
+ p->xtile,
+ p->ytile,
+ p->xytile);
+ printf("vf_tile: start pixel %d, delta pixel %d\n",
+ p->start,
+ p->delta);
+// printf("vf_tile: background 0x%x\n",
+// p->bkgSet);
+ }
+ return 1;
+}
+
+const vf_info_t vf_info_tile = {
+ "Make a single image tiling x/y images",
+ "tile",
+ "Daniele Forghieri",
+ "",
+ vf_open,
+ NULL
+};
diff --git a/libavfilter/libmpcodecs/vf_tinterlace.c b/libavfilter/libmpcodecs/vf_tinterlace.c
new file mode 100644
index 0000000000..6dbcbc9481
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_tinterlace.c
@@ -0,0 +1,235 @@
+/*
+ * Copyright (C) 2003 Michael Zucchi <notzed@ximian.com>
+ *
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "config.h"
+#include "mp_msg.h"
+
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+
+#include "libvo/fastmemcpy.h"
+
+struct vf_priv_s {
+ int mode;
+ int frame;
+ mp_image_t *dmpi;
+};
+
+static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
+{
+ int ret = 0;
+ mp_image_t *dmpi;
+
+ switch (vf->priv->mode) {
+ case 0:
+ dmpi = vf->priv->dmpi;
+ if (dmpi == NULL) {
+ dmpi = vf_get_image(vf->next, mpi->imgfmt,
+ MP_IMGTYPE_STATIC, MP_IMGFLAG_ACCEPT_STRIDE |
+ MP_IMGFLAG_PRESERVE,
+ mpi->width, mpi->height*2);
+
+ vf->priv->dmpi = dmpi;
+
+ memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h,
+ dmpi->stride[0]*2, mpi->stride[0]);
+ if (mpi->flags & MP_IMGFLAG_PLANAR) {
+ memcpy_pic(dmpi->planes[1], mpi->planes[1],
+ mpi->chroma_width, mpi->chroma_height,
+ dmpi->stride[1]*2, mpi->stride[1]);
+ memcpy_pic(dmpi->planes[2], mpi->planes[2],
+ mpi->chroma_width, mpi->chroma_height,
+ dmpi->stride[2]*2, mpi->stride[2]);
+ }
+ } else {
+ vf->priv->dmpi = NULL;
+
+ memcpy_pic(dmpi->planes[0]+dmpi->stride[0], mpi->planes[0], mpi->w, mpi->h,
+ dmpi->stride[0]*2, mpi->stride[0]);
+ if (mpi->flags & MP_IMGFLAG_PLANAR) {
+ memcpy_pic(dmpi->planes[1]+dmpi->stride[1], mpi->planes[1],
+ mpi->chroma_width, mpi->chroma_height,
+ dmpi->stride[1]*2, mpi->stride[1]);
+ memcpy_pic(dmpi->planes[2]+dmpi->stride[2], mpi->planes[2],
+ mpi->chroma_width, mpi->chroma_height,
+ dmpi->stride[2]*2, mpi->stride[2]);
+ }
+ ret = vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE);
+ }
+ break;
+ case 1:
+ if (vf->priv->frame & 1)
+ ret = vf_next_put_image(vf, mpi, MP_NOPTS_VALUE);
+ break;
+ case 2:
+ if ((vf->priv->frame & 1) == 0)
+ ret = vf_next_put_image(vf, mpi, MP_NOPTS_VALUE);
+ break;
+ case 3:
+ dmpi = vf_get_image(vf->next, mpi->imgfmt,
+ MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
+ mpi->width, mpi->height*2);
+ /* fixme, just clear alternate lines */
+ vf_mpi_clear(dmpi, 0, 0, dmpi->w, dmpi->h);
+ if ((vf->priv->frame & 1) == 0) {
+ memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h,
+ dmpi->stride[0]*2, mpi->stride[0]);
+ if (mpi->flags & MP_IMGFLAG_PLANAR) {
+ memcpy_pic(dmpi->planes[1], mpi->planes[1],
+ mpi->chroma_width, mpi->chroma_height,
+ dmpi->stride[1]*2, mpi->stride[1]);
+ memcpy_pic(dmpi->planes[2], mpi->planes[2],
+ mpi->chroma_width, mpi->chroma_height,
+ dmpi->stride[2]*2, mpi->stride[2]);
+ }
+ } else {
+ memcpy_pic(dmpi->planes[0]+dmpi->stride[0], mpi->planes[0], mpi->w, mpi->h,
+ dmpi->stride[0]*2, mpi->stride[0]);
+ if (mpi->flags & MP_IMGFLAG_PLANAR) {
+ memcpy_pic(dmpi->planes[1]+dmpi->stride[1], mpi->planes[1],
+ mpi->chroma_width, mpi->chroma_height,
+ dmpi->stride[1]*2, mpi->stride[1]);
+ memcpy_pic(dmpi->planes[2]+dmpi->stride[2], mpi->planes[2],
+ mpi->chroma_width, mpi->chroma_height,
+ dmpi->stride[2]*2, mpi->stride[2]);
+ }
+ }
+ ret = vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE);
+ break;
+ case 4:
+ // Interleave even lines (only) from Frame 'i' with odd
+ // lines (only) from Frame 'i+1', halving the Frame
+ // rate and preserving image height.
+
+ dmpi = vf->priv->dmpi;
+
+ // @@ Need help: Should I set dmpi->fields to indicate
+ // that the (new) frame will be interlaced!? E.g. ...
+ // dmpi->fields |= MP_IMGFIELD_INTERLACED;
+ // dmpi->fields |= MP_IMGFIELD_TOP_FIRST;
+ // etc.
+
+ if (dmpi == NULL) {
+ dmpi = vf_get_image(vf->next, mpi->imgfmt,
+ MP_IMGTYPE_STATIC, MP_IMGFLAG_ACCEPT_STRIDE |
+ MP_IMGFLAG_PRESERVE,
+ mpi->width, mpi->height);
+
+ vf->priv->dmpi = dmpi;
+
+ my_memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h/2,
+ dmpi->stride[0]*2, mpi->stride[0]*2);
+ if (mpi->flags & MP_IMGFLAG_PLANAR) {
+ my_memcpy_pic(dmpi->planes[1], mpi->planes[1],
+ mpi->chroma_width, mpi->chroma_height/2,
+ dmpi->stride[1]*2, mpi->stride[1]*2);
+ my_memcpy_pic(dmpi->planes[2], mpi->planes[2],
+ mpi->chroma_width, mpi->chroma_height/2,
+ dmpi->stride[2]*2, mpi->stride[2]*2);
+ }
+ } else {
+ vf->priv->dmpi = NULL;
+
+ my_memcpy_pic(dmpi->planes[0]+dmpi->stride[0],
+ mpi->planes[0]+mpi->stride[0],
+ mpi->w, mpi->h/2,
+ dmpi->stride[0]*2, mpi->stride[0]*2);
+ if (mpi->flags & MP_IMGFLAG_PLANAR) {
+ my_memcpy_pic(dmpi->planes[1]+dmpi->stride[1],
+ mpi->planes[1]+mpi->stride[1],
+ mpi->chroma_width, mpi->chroma_height/2,
+ dmpi->stride[1]*2, mpi->stride[1]*2);
+ my_memcpy_pic(dmpi->planes[2]+dmpi->stride[2],
+ mpi->planes[2]+mpi->stride[2],
+ mpi->chroma_width, mpi->chroma_height/2,
+ dmpi->stride[2]*2, mpi->stride[2]*2);
+ }
+ ret = vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE);
+ }
+ break;
+ }
+
+ vf->priv->frame++;
+
+ return ret;
+}
+
+static int query_format(struct vf_instance *vf, unsigned int fmt)
+{
+ /* FIXME - figure out which other formats work */
+ switch (fmt) {
+ case IMGFMT_YV12:
+ case IMGFMT_IYUV:
+ case IMGFMT_I420:
+ return vf_next_query_format(vf, fmt);
+ }
+ return 0;
+}
+
+static int config(struct vf_instance *vf,
+ int width, int height, int d_width, int d_height,
+ unsigned int flags, unsigned int outfmt)
+{
+ switch (vf->priv->mode) {
+ case 0:
+ case 3:
+ return vf_next_config(vf,width,height*2,d_width,d_height*2,flags,outfmt);
+ case 1: /* odd frames */
+ case 2: /* even frames */
+ case 4: /* alternate frame (height-preserving) interlacing */
+ return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
+ }
+ return 0;
+}
+
+static void uninit(struct vf_instance *vf)
+{
+ free(vf->priv);
+}
+
+static int vf_open(vf_instance_t *vf, char *args)
+{
+ struct vf_priv_s *p;
+ vf->config = config;
+ vf->put_image = put_image;
+ vf->query_format = query_format;
+ vf->uninit = uninit;
+ vf->default_reqs = VFCAP_ACCEPT_STRIDE;
+ vf->priv = p = calloc(1, sizeof(struct vf_priv_s));
+ vf->priv->mode = 0;
+ if (args)
+ sscanf(args, "%d", &vf->priv->mode);
+ vf->priv->frame = 0;
+ return 1;
+}
+
+const vf_info_t vf_info_tinterlace = {
+ "temporal field interlacing",
+ "tinterlace",
+ "Michael Zucchi",
+ "",
+ vf_open,
+ NULL
+};
diff --git a/libavfilter/libmpcodecs/vf_unsharp.c b/libavfilter/libmpcodecs/vf_unsharp.c
new file mode 100644
index 0000000000..db22f78e9d
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_unsharp.c
@@ -0,0 +1,324 @@
+/*
+ * Copyright (C) 2002 Remi Guyomarch <rguyom@pobox.com>
+ *
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+#include <math.h>
+
+#include "config.h"
+#include "mp_msg.h"
+#include "cpudetect.h"
+
+#if HAVE_MALLOC_H
+#include <malloc.h>
+#endif
+
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+#include "libvo/fastmemcpy.h"
+#include "libavutil/common.h"
+
+//===========================================================================//
+
+#define MIN_MATRIX_SIZE 3
+#define MAX_MATRIX_SIZE 63
+
+typedef struct FilterParam {
+ int msizeX, msizeY;
+ double amount;
+ uint32_t *SC[MAX_MATRIX_SIZE-1];
+} FilterParam;
+
+struct vf_priv_s {
+ FilterParam lumaParam;
+ FilterParam chromaParam;
+ unsigned int outfmt;
+};
+
+
+//===========================================================================//
+
+/* This code is based on :
+
+An Efficient algorithm for Gaussian blur using finite-state machines
+Frederick M. Waltz and John W. V. Miller
+
+SPIE Conf. on Machine Vision Systems for Inspection and Metrology VII
+Originally published Boston, Nov 98
+
+*/
+
+static void unsharp( uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int width, int height, FilterParam *fp ) {
+
+ uint32_t **SC = fp->SC;
+ uint32_t SR[MAX_MATRIX_SIZE-1], Tmp1, Tmp2;
+ uint8_t* src2 = src; // avoid gcc warning
+
+ int32_t res;
+ int x, y, z;
+ int amount = fp->amount * 65536.0;
+ int stepsX = fp->msizeX/2;
+ int stepsY = fp->msizeY/2;
+ int scalebits = (stepsX+stepsY)*2;
+ int32_t halfscale = 1 << ((stepsX+stepsY)*2-1);
+
+ if( !fp->amount ) {
+ if( src == dst )
+ return;
+ if( dstStride == srcStride )
+ fast_memcpy( dst, src, srcStride*height );
+ else
+ for( y=0; y<height; y++, dst+=dstStride, src+=srcStride )
+ fast_memcpy( dst, src, width );
+ return;
+ }
+
+ for( y=0; y<2*stepsY; y++ )
+ memset( SC[y], 0, sizeof(SC[y][0]) * (width+2*stepsX) );
+
+ for( y=-stepsY; y<height+stepsY; y++ ) {
+ if( y < height ) src2 = src;
+ memset( SR, 0, sizeof(SR[0]) * (2*stepsX-1) );
+ for( x=-stepsX; x<width+stepsX; x++ ) {
+ Tmp1 = x<=0 ? src2[0] : x>=width ? src2[width-1] : src2[x];
+ for( z=0; z<stepsX*2; z+=2 ) {
+ Tmp2 = SR[z+0] + Tmp1; SR[z+0] = Tmp1;
+ Tmp1 = SR[z+1] + Tmp2; SR[z+1] = Tmp2;
+ }
+ for( z=0; z<stepsY*2; z+=2 ) {
+ Tmp2 = SC[z+0][x+stepsX] + Tmp1; SC[z+0][x+stepsX] = Tmp1;
+ Tmp1 = SC[z+1][x+stepsX] + Tmp2; SC[z+1][x+stepsX] = Tmp2;
+ }
+ if( x>=stepsX && y>=stepsY ) {
+ uint8_t* srx = src - stepsY*srcStride + x - stepsX;
+ uint8_t* dsx = dst - stepsY*dstStride + x - stepsX;
+
+ res = (int32_t)*srx + ( ( ( (int32_t)*srx - (int32_t)((Tmp1+halfscale) >> scalebits) ) * amount ) >> 16 );
+ *dsx = res>255 ? 255 : res<0 ? 0 : (uint8_t)res;
+ }
+ }
+ if( y >= 0 ) {
+ dst += dstStride;
+ src += srcStride;
+ }
+ }
+}
+
+//===========================================================================//
+
+static int config( struct vf_instance *vf,
+ int width, int height, int d_width, int d_height,
+ unsigned int flags, unsigned int outfmt ) {
+
+ int z, stepsX, stepsY;
+ FilterParam *fp;
+ const char *effect;
+
+ // allocate buffers
+
+ fp = &vf->priv->lumaParam;
+ effect = fp->amount == 0 ? "don't touch" : fp->amount < 0 ? "blur" : "sharpen";
+ mp_msg( MSGT_VFILTER, MSGL_INFO, "unsharp: %dx%d:%0.2f (%s luma) \n", fp->msizeX, fp->msizeY, fp->amount, effect );
+ memset( fp->SC, 0, sizeof( fp->SC ) );
+ stepsX = fp->msizeX/2;
+ stepsY = fp->msizeY/2;
+ for( z=0; z<2*stepsY; z++ )
+ fp->SC[z] = av_malloc(sizeof(*(fp->SC[z])) * (width+2*stepsX));
+
+ fp = &vf->priv->chromaParam;
+ effect = fp->amount == 0 ? "don't touch" : fp->amount < 0 ? "blur" : "sharpen";
+ mp_msg( MSGT_VFILTER, MSGL_INFO, "unsharp: %dx%d:%0.2f (%s chroma)\n", fp->msizeX, fp->msizeY, fp->amount, effect );
+ memset( fp->SC, 0, sizeof( fp->SC ) );
+ stepsX = fp->msizeX/2;
+ stepsY = fp->msizeY/2;
+ for( z=0; z<2*stepsY; z++ )
+ fp->SC[z] = av_malloc(sizeof(*(fp->SC[z])) * (width+2*stepsX));
+
+ return vf_next_config( vf, width, height, d_width, d_height, flags, outfmt );
+}
+
+//===========================================================================//
+
+static void get_image( struct vf_instance *vf, mp_image_t *mpi ) {
+ if( mpi->flags & MP_IMGFLAG_PRESERVE )
+ return; // don't change
+ if( mpi->imgfmt!=vf->priv->outfmt )
+ return; // colorspace differ
+
+ vf->dmpi = vf_get_image( vf->next, mpi->imgfmt, mpi->type, mpi->flags, mpi->w, mpi->h );
+ mpi->planes[0] = vf->dmpi->planes[0];
+ mpi->stride[0] = vf->dmpi->stride[0];
+ mpi->width = vf->dmpi->width;
+ if( mpi->flags & MP_IMGFLAG_PLANAR ) {
+ mpi->planes[1] = vf->dmpi->planes[1];
+ mpi->planes[2] = vf->dmpi->planes[2];
+ mpi->stride[1] = vf->dmpi->stride[1];
+ mpi->stride[2] = vf->dmpi->stride[2];
+ }
+ mpi->flags |= MP_IMGFLAG_DIRECT;
+}
+
+static int put_image( struct vf_instance *vf, mp_image_t *mpi, double pts) {
+ mp_image_t *dmpi;
+
+ if( !(mpi->flags & MP_IMGFLAG_DIRECT) )
+ // no DR, so get a new image! hope we'll get DR buffer:
+ vf->dmpi = vf_get_image( vf->next,vf->priv->outfmt, MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, mpi->w, mpi->h);
+ dmpi= vf->dmpi;
+
+ unsharp( dmpi->planes[0], mpi->planes[0], dmpi->stride[0], mpi->stride[0], mpi->w, mpi->h, &vf->priv->lumaParam );
+ unsharp( dmpi->planes[1], mpi->planes[1], dmpi->stride[1], mpi->stride[1], mpi->w/2, mpi->h/2, &vf->priv->chromaParam );
+ unsharp( dmpi->planes[2], mpi->planes[2], dmpi->stride[2], mpi->stride[2], mpi->w/2, mpi->h/2, &vf->priv->chromaParam );
+
+ vf_clone_mpi_attributes(dmpi, mpi);
+
+#if HAVE_MMX
+ if(gCpuCaps.hasMMX)
+ __asm__ volatile ("emms\n\t");
+#endif
+#if HAVE_MMX2
+ if(gCpuCaps.hasMMX2)
+ __asm__ volatile ("sfence\n\t");
+#endif
+
+ return vf_next_put_image( vf, dmpi, pts);
+}
+
+static void uninit( struct vf_instance *vf ) {
+ unsigned int z;
+ FilterParam *fp;
+
+ if( !vf->priv ) return;
+
+ fp = &vf->priv->lumaParam;
+ for( z=0; z<sizeof(fp->SC)/sizeof(fp->SC[0]); z++ ) {
+ av_free( fp->SC[z] );
+ fp->SC[z] = NULL;
+ }
+ fp = &vf->priv->chromaParam;
+ for( z=0; z<sizeof(fp->SC)/sizeof(fp->SC[0]); z++ ) {
+ av_free( fp->SC[z] );
+ fp->SC[z] = NULL;
+ }
+
+ free( vf->priv );
+ vf->priv = NULL;
+}
+
+//===========================================================================//
+
+static int query_format( struct vf_instance *vf, unsigned int fmt ) {
+ switch(fmt) {
+ case IMGFMT_YV12:
+ case IMGFMT_I420:
+ case IMGFMT_IYUV:
+ return vf_next_query_format( vf, vf->priv->outfmt );
+ }
+ return 0;
+}
+
+//===========================================================================//
+
+static void parse( FilterParam *fp, char* args ) {
+
+ // l7x5:0.8:c3x3:-0.2
+
+ char *z;
+ char *pos = args;
+ char *max = args + strlen(args);
+
+ // parse matrix sizes
+ fp->msizeX = ( pos && pos+1<max ) ? atoi( pos+1 ) : 0;
+ z = strchr( pos+1, 'x' );
+ fp->msizeY = ( z && z+1<max ) ? atoi( pos=z+1 ) : fp->msizeX;
+
+ // min/max & odd
+ fp->msizeX = 1 | av_clip(fp->msizeX, MIN_MATRIX_SIZE, MAX_MATRIX_SIZE);
+ fp->msizeY = 1 | av_clip(fp->msizeY, MIN_MATRIX_SIZE, MAX_MATRIX_SIZE);
+
+ // parse amount
+ pos = strchr( pos+1, ':' );
+ fp->amount = ( pos && pos+1<max ) ? atof( pos+1 ) : 0;
+}
+
+//===========================================================================//
+
+static const unsigned int fmt_list[] = {
+ IMGFMT_YV12,
+ IMGFMT_I420,
+ IMGFMT_IYUV,
+ 0
+};
+
+static int vf_open( vf_instance_t *vf, char *args ) {
+ vf->config = config;
+ vf->put_image = put_image;
+ vf->get_image = get_image;
+ vf->query_format = query_format;
+ vf->uninit = uninit;
+ vf->priv = malloc( sizeof(struct vf_priv_s) );
+ memset( vf->priv, 0, sizeof(struct vf_priv_s) );
+
+ if( args ) {
+ char *args2 = strchr( args, 'l' );
+ if( args2 )
+ parse( &vf->priv->lumaParam, args2 );
+ else {
+ vf->priv->lumaParam.amount =
+ vf->priv->lumaParam.msizeX =
+ vf->priv->lumaParam.msizeY = 0;
+ }
+
+ args2 = strchr( args, 'c' );
+ if( args2 )
+ parse( &vf->priv->chromaParam, args2 );
+ else {
+ vf->priv->chromaParam.amount =
+ vf->priv->chromaParam.msizeX =
+ vf->priv->chromaParam.msizeY = 0;
+ }
+
+ if( !vf->priv->lumaParam.msizeX && !vf->priv->chromaParam.msizeX )
+ return 0; // nothing to do
+ }
+
+ // check csp:
+ vf->priv->outfmt = vf_match_csp( &vf->next, fmt_list, IMGFMT_YV12 );
+ if( !vf->priv->outfmt ) {
+ uninit( vf );
+ return 0; // no csp match :(
+ }
+
+ return 1;
+}
+
+const vf_info_t vf_info_unsharp = {
+ "unsharp mask & gaussian blur",
+ "unsharp",
+ "Remi Guyomarch",
+ "",
+ vf_open,
+ NULL
+};
+
+//===========================================================================//
diff --git a/libavfilter/libmpcodecs/vf_uspp.c b/libavfilter/libmpcodecs/vf_uspp.c
new file mode 100644
index 0000000000..d9c5de8fb1
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_uspp.c
@@ -0,0 +1,385 @@
+/*
+ * Copyright (C) 2005 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+#include <math.h>
+#include <assert.h>
+
+#include "config.h"
+
+#include "mp_msg.h"
+#include "cpudetect.h"
+
+#include "libavcodec/avcodec.h"
+
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+#include "vd_ffmpeg.h"
+#include "libvo/fastmemcpy.h"
+
+#define XMIN(a,b) ((a) < (b) ? (a) : (b))
+
+#define BLOCK 16
+
+//===========================================================================//
+static const uint8_t __attribute__((aligned(8))) dither[8][8]={
+{ 0*4, 48*4, 12*4, 60*4, 3*4, 51*4, 15*4, 63*4, },
+{ 32*4, 16*4, 44*4, 28*4, 35*4, 19*4, 47*4, 31*4, },
+{ 8*4, 56*4, 4*4, 52*4, 11*4, 59*4, 7*4, 55*4, },
+{ 40*4, 24*4, 36*4, 20*4, 43*4, 27*4, 39*4, 23*4, },
+{ 2*4, 50*4, 14*4, 62*4, 1*4, 49*4, 13*4, 61*4, },
+{ 34*4, 18*4, 46*4, 30*4, 33*4, 17*4, 45*4, 29*4, },
+{ 10*4, 58*4, 6*4, 54*4, 9*4, 57*4, 5*4, 53*4, },
+{ 42*4, 26*4, 38*4, 22*4, 41*4, 25*4, 37*4, 21*4, },
+};
+
+static const uint8_t offset[511][2]= {
+{ 0, 0},
+{ 0, 0}, { 8, 8},
+{ 0, 0}, { 4, 4}, {12, 8}, { 8,12},
+{ 0, 0}, {10, 2}, { 4, 4}, {14, 6}, { 8, 8}, { 2,10}, {12,12}, { 6,14},
+
+{ 0, 0}, {10, 2}, { 4, 4}, {14, 6}, { 8, 8}, { 2,10}, {12,12}, { 6,14},
+{ 5, 1}, {15, 3}, { 9, 5}, { 3, 7}, {13, 9}, { 7,11}, { 1,13}, {11,15},
+
+{ 0, 0}, { 8, 0}, { 0, 8}, { 8, 8}, { 5, 1}, {13, 1}, { 5, 9}, {13, 9},
+{ 2, 2}, {10, 2}, { 2,10}, {10,10}, { 7, 3}, {15, 3}, { 7,11}, {15,11},
+{ 4, 4}, {12, 4}, { 4,12}, {12,12}, { 1, 5}, { 9, 5}, { 1,13}, { 9,13},
+{ 6, 6}, {14, 6}, { 6,14}, {14,14}, { 3, 7}, {11, 7}, { 3,15}, {11,15},
+
+{ 0, 0}, { 8, 0}, { 0, 8}, { 8, 8}, { 4, 0}, {12, 0}, { 4, 8}, {12, 8},
+{ 1, 1}, { 9, 1}, { 1, 9}, { 9, 9}, { 5, 1}, {13, 1}, { 5, 9}, {13, 9},
+{ 3, 2}, {11, 2}, { 3,10}, {11,10}, { 7, 2}, {15, 2}, { 7,10}, {15,10},
+{ 2, 3}, {10, 3}, { 2,11}, {10,11}, { 6, 3}, {14, 3}, { 6,11}, {14,11},
+{ 0, 4}, { 8, 4}, { 0,12}, { 8,12}, { 4, 4}, {12, 4}, { 4,12}, {12,12},
+{ 1, 5}, { 9, 5}, { 1,13}, { 9,13}, { 5, 5}, {13, 5}, { 5,13}, {13,13},
+{ 3, 6}, {11, 6}, { 3,14}, {11,14}, { 7, 6}, {15, 6}, { 7,14}, {15,14},
+{ 2, 7}, {10, 7}, { 2,15}, {10,15}, { 6, 7}, {14, 7}, { 6,15}, {14,15},
+
+{ 0, 0}, { 8, 0}, { 0, 8}, { 8, 8}, { 0, 2}, { 8, 2}, { 0,10}, { 8,10},
+{ 0, 4}, { 8, 4}, { 0,12}, { 8,12}, { 0, 6}, { 8, 6}, { 0,14}, { 8,14},
+{ 1, 1}, { 9, 1}, { 1, 9}, { 9, 9}, { 1, 3}, { 9, 3}, { 1,11}, { 9,11},
+{ 1, 5}, { 9, 5}, { 1,13}, { 9,13}, { 1, 7}, { 9, 7}, { 1,15}, { 9,15},
+{ 2, 0}, {10, 0}, { 2, 8}, {10, 8}, { 2, 2}, {10, 2}, { 2,10}, {10,10},
+{ 2, 4}, {10, 4}, { 2,12}, {10,12}, { 2, 6}, {10, 6}, { 2,14}, {10,14},
+{ 3, 1}, {11, 1}, { 3, 9}, {11, 9}, { 3, 3}, {11, 3}, { 3,11}, {11,11},
+{ 3, 5}, {11, 5}, { 3,13}, {11,13}, { 3, 7}, {11, 7}, { 3,15}, {11,15},
+{ 4, 0}, {12, 0}, { 4, 8}, {12, 8}, { 4, 2}, {12, 2}, { 4,10}, {12,10},
+{ 4, 4}, {12, 4}, { 4,12}, {12,12}, { 4, 6}, {12, 6}, { 4,14}, {12,14},
+{ 5, 1}, {13, 1}, { 5, 9}, {13, 9}, { 5, 3}, {13, 3}, { 5,11}, {13,11},
+{ 5, 5}, {13, 5}, { 5,13}, {13,13}, { 5, 7}, {13, 7}, { 5,15}, {13,15},
+{ 6, 0}, {14, 0}, { 6, 8}, {14, 8}, { 6, 2}, {14, 2}, { 6,10}, {14,10},
+{ 6, 4}, {14, 4}, { 6,12}, {14,12}, { 6, 6}, {14, 6}, { 6,14}, {14,14},
+{ 7, 1}, {15, 1}, { 7, 9}, {15, 9}, { 7, 3}, {15, 3}, { 7,11}, {15,11},
+{ 7, 5}, {15, 5}, { 7,13}, {15,13}, { 7, 7}, {15, 7}, { 7,15}, {15,15},
+
+{ 0, 0}, { 8, 0}, { 0, 8}, { 8, 8}, { 4, 4}, {12, 4}, { 4,12}, {12,12}, { 0, 4}, { 8, 4}, { 0,12}, { 8,12}, { 4, 0}, {12, 0}, { 4, 8}, {12, 8}, { 2, 2}, {10, 2}, { 2,10}, {10,10}, { 6, 6}, {14, 6}, { 6,14}, {14,14}, { 2, 6}, {10, 6}, { 2,14}, {10,14}, { 6, 2}, {14, 2}, { 6,10}, {14,10}, { 0, 2}, { 8, 2}, { 0,10}, { 8,10}, { 4, 6}, {12, 6}, { 4,14}, {12,14}, { 0, 6}, { 8, 6}, { 0,14}, { 8,14}, { 4, 2}, {12, 2}, { 4,10}, {12,10}, { 2, 0}, {10, 0}, { 2, 8}, {10, 8}, { 6, 4}, {14, 4}, { 6,12}, {14,12}, { 2, 4}, {10, 4}, { 2,12}, {10,12}, { 6, 0}, {14, 0}, { 6, 8}, {14, 8}, { 1, 1}, { 9, 1}, { 1, 9}, { 9, 9}, { 5, 5}, {13, 5}, { 5,13}, {13,13}, { 1, 5}, { 9, 5}, { 1,13}, { 9,13}, { 5, 1}, {13, 1}, { 5, 9}, {13, 9}, { 3, 3}, {11, 3}, { 3,11}, {11,11}, { 7, 7}, {15, 7}, { 7,15}, {15,15}, { 3, 7}, {11, 7}, { 3,15}, {11,15}, { 7, 3}, {15, 3}, { 7,11}, {15,11}, { 1, 3}, { 9, 3}, { 1,11}, { 9,11}, { 5, 7}, {13, 7}, { 5,15}, {13,15}, { 1, 7}, { 9, 7}, { 1,15}, { 9,15}, { 5, 3}, {13, 3}, { 5,11}, {13,11}, { 3, 1}, {11, 1}, { 3, 9}, {11, 9}, { 7, 5}, {15, 5}, { 7,13}, {15,13}, { 3, 5}, {11, 5}, { 3,13}, {11,13}, { 7, 1}, {15, 1}, { 7, 9}, {15, 9}, { 0, 1}, { 8, 1}, { 0, 9}, { 8, 9}, { 4, 5}, {12, 5}, { 4,13}, {12,13}, { 0, 5}, { 8, 5}, { 0,13}, { 8,13}, { 4, 1}, {12, 1}, { 4, 9}, {12, 9}, { 2, 3}, {10, 3}, { 2,11}, {10,11}, { 6, 7}, {14, 7}, { 6,15}, {14,15}, { 2, 7}, {10, 7}, { 2,15}, {10,15}, { 6, 3}, {14, 3}, { 6,11}, {14,11}, { 0, 3}, { 8, 3}, { 0,11}, { 8,11}, { 4, 7}, {12, 7}, { 4,15}, {12,15}, { 0, 7}, { 8, 7}, { 0,15}, { 8,15}, { 4, 3}, {12, 3}, { 4,11}, {12,11}, { 2, 1}, {10, 1}, { 2, 9}, {10, 9}, { 6, 5}, {14, 5}, { 6,13}, {14,13}, { 2, 5}, {10, 5}, { 2,13}, {10,13}, { 6, 1}, {14, 1}, { 6, 9}, {14, 9}, { 1, 0}, { 9, 0}, { 1, 8}, { 9, 8}, { 5, 4}, {13, 4}, { 5,12}, {13,12}, { 1, 4}, { 9, 4}, { 1,12}, { 9,12}, { 5, 0}, {13, 0}, { 5, 8}, {13, 8}, { 3, 2}, {11, 2}, { 3,10}, {11,10}, { 7, 6}, {15, 6}, { 7,14}, {15,14}, { 3, 6}, {11, 6}, { 3,14}, {11,14}, { 7, 2}, {15, 2}, { 7,10}, {15,10}, { 1, 2}, { 9, 2}, { 1,10}, { 9,10}, { 5, 6}, {13, 6}, { 5,14}, {13,14}, { 1, 6}, { 9, 6}, { 1,14}, { 9,14}, { 5, 2}, {13, 2}, { 5,10}, {13,10}, { 3, 0}, {11, 0}, { 3, 8}, {11, 8}, { 7, 4}, {15, 4}, { 7,12}, {15,12}, { 3, 4}, {11, 4}, { 3,12}, {11,12}, { 7, 0}, {15, 0}, { 7, 8}, {15, 8},
+};
+
+struct vf_priv_s {
+ int log2_count;
+ int qp;
+ int mode;
+ int mpeg2;
+ int temp_stride[3];
+ uint8_t *src[3];
+ int16_t *temp[3];
+ int outbuf_size;
+ uint8_t *outbuf;
+ AVCodecContext *avctx_enc[BLOCK*BLOCK];
+ AVFrame *frame;
+ AVFrame *frame_dec;
+};
+
+static void store_slice_c(uint8_t *dst, int16_t *src, int dst_stride, int src_stride, int width, int height, int log2_scale){
+ int y, x;
+
+#define STORE(pos) \
+ temp= ((src[x + y*src_stride + pos]<<log2_scale) + d[pos])>>8;\
+ if(temp & 0x100) temp= ~(temp>>31);\
+ dst[x + y*dst_stride + pos]= temp;
+
+ for(y=0; y<height; y++){
+ const uint8_t *d= dither[y&7];
+ for(x=0; x<width; x+=8){
+ int temp;
+ STORE(0);
+ STORE(1);
+ STORE(2);
+ STORE(3);
+ STORE(4);
+ STORE(5);
+ STORE(6);
+ STORE(7);
+ }
+ }
+}
+
+static void filter(struct vf_priv_s *p, uint8_t *dst[3], uint8_t *src[3], int dst_stride[3], int src_stride[3], int width, int height, uint8_t *qp_store, int qp_stride){
+ int x, y, i, j;
+ const int count= 1<<p->log2_count;
+
+ for(i=0; i<3; i++){
+ int is_chroma= !!i;
+ int w= width >>is_chroma;
+ int h= height>>is_chroma;
+ int stride= p->temp_stride[i];
+ int block= BLOCK>>is_chroma;
+
+ if (!src[i] || !dst[i])
+ continue; // HACK avoid crash for Y8 colourspace
+ for(y=0; y<h; y++){
+ int index= block + block*stride + y*stride;
+ fast_memcpy(p->src[i] + index, src[i] + y*src_stride[i], w);
+ for(x=0; x<block; x++){
+ p->src[i][index - x - 1]= p->src[i][index + x ];
+ p->src[i][index + w + x ]= p->src[i][index + w - x - 1];
+ }
+ }
+ for(y=0; y<block; y++){
+ fast_memcpy(p->src[i] + ( block-1-y)*stride, p->src[i] + ( y+block )*stride, stride);
+ fast_memcpy(p->src[i] + (h+block +y)*stride, p->src[i] + (h-y+block-1)*stride, stride);
+ }
+
+ p->frame->linesize[i]= stride;
+ memset(p->temp[i], 0, (h+2*block)*stride*sizeof(int16_t));
+ }
+
+ if(p->qp)
+ p->frame->quality= p->qp * FF_QP2LAMBDA;
+ else
+ p->frame->quality= norm_qscale(qp_store[0], p->mpeg2) * FF_QP2LAMBDA;
+// init per MB qscale stuff FIXME
+
+ for(i=0; i<count; i++){
+ const int x1= offset[i+count-1][0];
+ const int y1= offset[i+count-1][1];
+ int offset;
+ p->frame->data[0]= p->src[0] + x1 + y1 * p->frame->linesize[0];
+ p->frame->data[1]= p->src[1] + x1/2 + y1/2 * p->frame->linesize[1];
+ p->frame->data[2]= p->src[2] + x1/2 + y1/2 * p->frame->linesize[2];
+
+ avcodec_encode_video(p->avctx_enc[i], p->outbuf, p->outbuf_size, p->frame);
+ p->frame_dec = p->avctx_enc[i]->coded_frame;
+
+ offset= (BLOCK-x1) + (BLOCK-y1)*p->frame_dec->linesize[0];
+ //FIXME optimize
+ for(y=0; y<height; y++){
+ for(x=0; x<width; x++){
+ p->temp[0][ x + y*p->temp_stride[0] ] += p->frame_dec->data[0][ x + y*p->frame_dec->linesize[0] + offset ];
+ }
+ }
+ offset= (BLOCK/2-x1/2) + (BLOCK/2-y1/2)*p->frame_dec->linesize[1];
+ for(y=0; y<height/2; y++){
+ for(x=0; x<width/2; x++){
+ p->temp[1][ x + y*p->temp_stride[1] ] += p->frame_dec->data[1][ x + y*p->frame_dec->linesize[1] + offset ];
+ p->temp[2][ x + y*p->temp_stride[2] ] += p->frame_dec->data[2][ x + y*p->frame_dec->linesize[2] + offset ];
+ }
+ }
+ }
+
+ for(j=0; j<3; j++){
+ int is_chroma= !!j;
+ store_slice_c(dst[j], p->temp[j], dst_stride[j], p->temp_stride[j], width>>is_chroma, height>>is_chroma, 8-p->log2_count);
+ }
+}
+
+static int config(struct vf_instance *vf,
+ int width, int height, int d_width, int d_height,
+ unsigned int flags, unsigned int outfmt){
+ int i;
+ AVCodec *enc= avcodec_find_encoder(CODEC_ID_SNOW);
+
+ for(i=0; i<3; i++){
+ int is_chroma= !!i;
+ int w= ((width + 4*BLOCK-1) & (~(2*BLOCK-1)))>>is_chroma;
+ int h= ((height + 4*BLOCK-1) & (~(2*BLOCK-1)))>>is_chroma;
+
+ vf->priv->temp_stride[i]= w;
+ vf->priv->temp[i]= malloc(vf->priv->temp_stride[i]*h*sizeof(int16_t));
+ vf->priv->src [i]= malloc(vf->priv->temp_stride[i]*h*sizeof(uint8_t));
+ }
+ for(i=0; i< (1<<vf->priv->log2_count); i++){
+ AVCodecContext *avctx_enc;
+
+ avctx_enc=
+ vf->priv->avctx_enc[i]= avcodec_alloc_context();
+ avctx_enc->width = width + BLOCK;
+ avctx_enc->height = height + BLOCK;
+ avctx_enc->time_base= (AVRational){1,25}; // meaningless
+ avctx_enc->gop_size = 300;
+ avctx_enc->max_b_frames= 0;
+ avctx_enc->pix_fmt = PIX_FMT_YUV420P;
+ avctx_enc->flags = CODEC_FLAG_QSCALE | CODEC_FLAG_LOW_DELAY;
+ avctx_enc->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL;
+ avctx_enc->global_quality= 123;
+ avcodec_open(avctx_enc, enc);
+ assert(avctx_enc->codec);
+ }
+ vf->priv->frame= avcodec_alloc_frame();
+ vf->priv->frame_dec= avcodec_alloc_frame();
+
+ vf->priv->outbuf_size= (width + BLOCK)*(height + BLOCK)*10;
+ vf->priv->outbuf= malloc(vf->priv->outbuf_size);
+
+ return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
+}
+
+static void get_image(struct vf_instance *vf, mp_image_t *mpi){
+ if(mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change
+ // ok, we can do pp in-place (or pp disabled):
+ vf->dmpi=vf_get_image(vf->next,mpi->imgfmt,
+ mpi->type, mpi->flags | MP_IMGFLAG_READABLE, mpi->width, mpi->height);
+ mpi->planes[0]=vf->dmpi->planes[0];
+ mpi->stride[0]=vf->dmpi->stride[0];
+ mpi->width=vf->dmpi->width;
+ if(mpi->flags&MP_IMGFLAG_PLANAR){
+ mpi->planes[1]=vf->dmpi->planes[1];
+ mpi->planes[2]=vf->dmpi->planes[2];
+ mpi->stride[1]=vf->dmpi->stride[1];
+ mpi->stride[2]=vf->dmpi->stride[2];
+ }
+ mpi->flags|=MP_IMGFLAG_DIRECT;
+}
+
+static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
+ mp_image_t *dmpi;
+
+ if(!(mpi->flags&MP_IMGFLAG_DIRECT)){
+ // no DR, so get a new image! hope we'll get DR buffer:
+ dmpi=vf_get_image(vf->next,mpi->imgfmt,
+ MP_IMGTYPE_TEMP,
+ MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE,
+ mpi->width,mpi->height);
+ vf_clone_mpi_attributes(dmpi, mpi);
+ }else{
+ dmpi=vf->dmpi;
+ }
+
+ vf->priv->mpeg2= mpi->qscale_type;
+ if(vf->priv->log2_count || !(mpi->flags&MP_IMGFLAG_DIRECT)){
+ if(mpi->qscale || vf->priv->qp){
+ filter(vf->priv, dmpi->planes, mpi->planes, dmpi->stride, mpi->stride, mpi->w, mpi->h, mpi->qscale, mpi->qstride);
+ }else{
+ memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h, dmpi->stride[0], mpi->stride[0]);
+ memcpy_pic(dmpi->planes[1], mpi->planes[1], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, dmpi->stride[1], mpi->stride[1]);
+ memcpy_pic(dmpi->planes[2], mpi->planes[2], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, dmpi->stride[2], mpi->stride[2]);
+ }
+ }
+
+#if HAVE_MMX
+ if(gCpuCaps.hasMMX) __asm__ volatile ("emms\n\t");
+#endif
+#if HAVE_MMX2
+ if(gCpuCaps.hasMMX2) __asm__ volatile ("sfence\n\t");
+#endif
+
+ return vf_next_put_image(vf,dmpi, pts);
+}
+
+static void uninit(struct vf_instance *vf){
+ int i;
+ if(!vf->priv) return;
+
+ for(i=0; i<3; i++){
+ free(vf->priv->temp[i]);
+ vf->priv->temp[i]= NULL;
+ free(vf->priv->src[i]);
+ vf->priv->src[i]= NULL;
+ }
+ for(i=0; i<BLOCK*BLOCK; i++){
+ av_freep(&vf->priv->avctx_enc[i]);
+ }
+
+ free(vf->priv);
+ vf->priv=NULL;
+}
+
+//===========================================================================//
+static int query_format(struct vf_instance *vf, unsigned int fmt){
+ switch(fmt){
+ case IMGFMT_YV12:
+ case IMGFMT_I420:
+ case IMGFMT_IYUV:
+ case IMGFMT_Y800:
+ case IMGFMT_Y8:
+ return vf_next_query_format(vf,fmt);
+ }
+ return 0;
+}
+
+static int control(struct vf_instance *vf, int request, void* data){
+ switch(request){
+ case VFCTRL_QUERY_MAX_PP_LEVEL:
+ return 8;
+ case VFCTRL_SET_PP_LEVEL:
+ vf->priv->log2_count= *((unsigned int*)data);
+ //FIXME we have to realloc a few things here
+ return CONTROL_TRUE;
+ }
+ return vf_next_control(vf,request,data);
+}
+
+static int vf_open(vf_instance_t *vf, char *args){
+
+ int log2c=-1;
+
+ vf->config=config;
+ vf->put_image=put_image;
+ vf->get_image=get_image;
+ vf->query_format=query_format;
+ vf->uninit=uninit;
+ vf->control= control;
+ vf->priv=malloc(sizeof(struct vf_priv_s));
+ memset(vf->priv, 0, sizeof(struct vf_priv_s));
+
+ init_avcodec();
+
+ vf->priv->log2_count= 4;
+
+ if (args) sscanf(args, "%d:%d:%d", &log2c, &vf->priv->qp, &vf->priv->mode);
+
+ if( log2c >=0 && log2c <=8 )
+ vf->priv->log2_count = log2c;
+
+ if(vf->priv->qp < 0)
+ vf->priv->qp = 0;
+
+// #if HAVE_MMX
+// if(gCpuCaps.hasMMX){
+// store_slice= store_slice_mmx;
+// }
+// #endif
+
+ return 1;
+}
+
+const vf_info_t vf_info_uspp = {
+ "ultra simple/slow postprocess",
+ "uspp",
+ "Michael Niedermayer",
+ "",
+ vf_open,
+ NULL
+};
diff --git a/libavfilter/libmpcodecs/vf_yuvcsp.c b/libavfilter/libmpcodecs/vf_yuvcsp.c
new file mode 100644
index 0000000000..102ce14538
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_yuvcsp.c
@@ -0,0 +1,120 @@
+/*
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+
+#include "config.h"
+#include "mp_msg.h"
+
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+
+struct vf_priv_s {
+ int csp;
+};
+
+//===========================================================================//
+
+static int config(struct vf_instance *vf,
+ int width, int height, int d_width, int d_height,
+ unsigned int flags, unsigned int outfmt){
+ return vf_next_config(vf, width, height, d_width, d_height, flags, outfmt);
+}
+
+static inline int clamp_y(int x){
+ return (x > 235) ? 235 : (x < 16) ? 16 : x;
+}
+
+static inline int clamp_c(int x){
+ return (x > 240) ? 240 : (x < 16) ? 16 : x;
+}
+
+static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
+ int i,j;
+ uint8_t *y_in, *cb_in, *cr_in;
+ uint8_t *y_out, *cb_out, *cr_out;
+
+ vf->dmpi=vf_get_image(vf->next,mpi->imgfmt,
+ MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
+ mpi->width, mpi->height);
+
+ y_in = mpi->planes[0];
+ cb_in = mpi->planes[1];
+ cr_in = mpi->planes[2];
+
+ y_out = vf->dmpi->planes[0];
+ cb_out = vf->dmpi->planes[1];
+ cr_out = vf->dmpi->planes[2];
+
+ for (i = 0; i < mpi->height; i++)
+ for (j = 0; j < mpi->width; j++)
+ y_out[i*vf->dmpi->stride[0]+j] = clamp_y(y_in[i*mpi->stride[0]+j]);
+
+ for (i = 0; i < mpi->chroma_height; i++)
+ for (j = 0; j < mpi->chroma_width; j++)
+ {
+ cb_out[i*vf->dmpi->stride[1]+j] = clamp_c(cb_in[i*mpi->stride[1]+j]);
+ cr_out[i*vf->dmpi->stride[2]+j] = clamp_c(cr_in[i*mpi->stride[2]+j]);
+ }
+
+ return vf_next_put_image(vf,vf->dmpi, pts);
+}
+
+//===========================================================================//
+
+/*
+static void uninit(struct vf_instance *vf){
+ free(vf->priv);
+}
+*/
+
+static int query_format(struct vf_instance *vf, unsigned int fmt){
+ switch(fmt){
+ case IMGFMT_YV12:
+ case IMGFMT_I420:
+ case IMGFMT_IYUV:
+ return 1;
+ }
+ return 0;
+}
+
+static int vf_open(vf_instance_t *vf, char *args){
+ vf->config=config;
+ vf->put_image=put_image;
+// vf->uninit=uninit;
+ vf->query_format=query_format;
+// vf->priv=calloc(1, sizeof(struct vf_priv_s));
+// if (args)
+// vf->priv->csp = atoi(args);
+ return 1;
+}
+
+const vf_info_t vf_info_yuvcsp = {
+ "yuv colorspace converter",
+ "yuvcsp",
+ "Alex Beregszaszi",
+ "",
+ vf_open,
+ NULL
+};
+
+//===========================================================================//
diff --git a/libavfilter/libmpcodecs/vf_yvu9.c b/libavfilter/libmpcodecs/vf_yvu9.c
new file mode 100644
index 0000000000..1f74261ccf
--- /dev/null
+++ b/libavfilter/libmpcodecs/vf_yvu9.c
@@ -0,0 +1,105 @@
+/*
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+
+#include "config.h"
+#include "mp_msg.h"
+#include "help_mp.h"
+
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+
+#include "libvo/fastmemcpy.h"
+
+//===========================================================================//
+
+static int config(struct vf_instance *vf,
+ int width, int height, int d_width, int d_height,
+ unsigned int flags, unsigned int outfmt){
+
+ if(vf_next_query_format(vf,IMGFMT_YV12)<=0){
+ mp_msg(MSGT_VFILTER, MSGL_WARN, MSGTR_MPCODECS_WarnNextFilterDoesntSupport, "YVU9");
+ return 0;
+ }
+
+ return vf_next_config(vf,width,height,d_width,d_height,flags,IMGFMT_YV12);
+}
+
+static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
+ mp_image_t *dmpi;
+ int y,w,h;
+
+ // hope we'll get DR buffer:
+ dmpi=vf_get_image(vf->next,IMGFMT_YV12,
+ MP_IMGTYPE_TEMP, 0/*MP_IMGFLAG_ACCEPT_STRIDE*/,
+ mpi->w, mpi->h);
+
+ for(y=0;y<mpi->h;y++)
+ fast_memcpy(dmpi->planes[0]+dmpi->stride[0]*y,
+ mpi->planes[0]+mpi->stride[0]*y,
+ mpi->w);
+
+ w=mpi->w/4; h=mpi->h/2;
+ for(y=0;y<h;y++){
+ unsigned char* s=mpi->planes[1]+mpi->stride[1]*(y>>1);
+ unsigned char* d=dmpi->planes[1]+dmpi->stride[1]*y;
+ int x;
+ for(x=0;x<w;x++) d[2*x]=d[2*x+1]=s[x];
+ }
+ for(y=0;y<h;y++){
+ unsigned char* s=mpi->planes[2]+mpi->stride[2]*(y>>1);
+ unsigned char* d=dmpi->planes[2]+dmpi->stride[2]*y;
+ int x;
+ for(x=0;x<w;x++) d[2*x]=d[2*x+1]=s[x];
+ }
+
+ vf_clone_mpi_attributes(dmpi, mpi);
+
+ return vf_next_put_image(vf,dmpi, pts);
+}
+
+//===========================================================================//
+
+static int query_format(struct vf_instance *vf, unsigned int fmt){
+ if (fmt == IMGFMT_YVU9 || fmt == IMGFMT_IF09)
+ return vf_next_query_format(vf,IMGFMT_YV12) & (~VFCAP_CSP_SUPPORTED_BY_HW);
+ return 0;
+}
+
+static int vf_open(vf_instance_t *vf, char *args){
+ vf->config=config;
+ vf->put_image=put_image;
+ vf->query_format=query_format;
+ return 1;
+}
+
+const vf_info_t vf_info_yvu9 = {
+ "fast YVU9->YV12 conversion",
+ "yvu9",
+ "alex",
+ "",
+ vf_open,
+ NULL
+};
+
+//===========================================================================//
diff --git a/libavfilter/libmpcodecs/vfcap.h b/libavfilter/libmpcodecs/vfcap.h
new file mode 100644
index 0000000000..611d642869
--- /dev/null
+++ b/libavfilter/libmpcodecs/vfcap.h
@@ -0,0 +1,56 @@
+/* VFCAP_* values: they are flags, returned by query_format():
+ *
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef MPLAYER_VFCAP_H
+#define MPLAYER_VFCAP_H
+
+// set, if the given colorspace is supported (with or without conversion)
+#define VFCAP_CSP_SUPPORTED 0x1
+// set, if the given colorspace is supported _without_ conversion
+#define VFCAP_CSP_SUPPORTED_BY_HW 0x2
+// set if the driver/filter can draw OSD
+#define VFCAP_OSD 0x4
+// set if the driver/filter can handle compressed SPU stream
+#define VFCAP_SPU 0x8
+// scaling up/down by hardware, or software:
+#define VFCAP_HWSCALE_UP 0x10
+#define VFCAP_HWSCALE_DOWN 0x20
+#define VFCAP_SWSCALE 0x40
+// driver/filter can do vertical flip (upside-down)
+#define VFCAP_FLIP 0x80
+
+// driver/hardware handles timing (blocking)
+#define VFCAP_TIMER 0x100
+// driver _always_ flip image upside-down (for ve_vfw)
+#define VFCAP_FLIPPED 0x200
+// vf filter: accepts stride (put_image)
+// vo driver: has draw_slice() support for the given csp
+#define VFCAP_ACCEPT_STRIDE 0x400
+// filter does postprocessing (so you shouldn't scale/filter image before it)
+#define VFCAP_POSTPROC 0x800
+// filter cannot be reconfigured to different size & format
+#define VFCAP_CONSTANT 0x1000
+// filter can draw EOSD
+#define VFCAP_EOSD 0x2000
+// filter will draw EOSD at screen resolution (without scaling)
+#define VFCAP_EOSD_UNSCALED 0x4000
+// used by libvo and vf_vo, indicates the VO does not support draw_slice for this format
+#define VOCAP_NOSLICES 0x8000
+
+#endif /* MPLAYER_VFCAP_H */
diff --git a/libavfilter/sink_buffer.c b/libavfilter/sink_buffer.c
new file mode 100644
index 0000000000..1c4996708a
--- /dev/null
+++ b/libavfilter/sink_buffer.c
@@ -0,0 +1,263 @@
+/*
+ * Copyright (c) 2011 Stefano Sabatini
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * buffer video sink
+ */
+
+#include "libavutil/fifo.h"
+#include "avfilter.h"
+#include "buffersink.h"
+
+AVBufferSinkParams *av_buffersink_params_alloc(void)
+{
+ static const int pixel_fmts[] = { -1 };
+ AVBufferSinkParams *params = av_malloc(sizeof(AVBufferSinkParams));
+ if (!params)
+ return NULL;
+
+ params->pixel_fmts = pixel_fmts;
+ return params;
+}
+
+AVABufferSinkParams *av_abuffersink_params_alloc(void)
+{
+ static const int sample_fmts[] = { -1 };
+ static const int packing_fmts[] = { -1 };
+ static const int64_t channel_layouts[] = { -1 };
+ AVABufferSinkParams *params = av_malloc(sizeof(AVABufferSinkParams));
+
+ if (!params)
+ return NULL;
+
+ params->sample_fmts = sample_fmts;
+ params->channel_layouts = channel_layouts;
+ params->packing_fmts = packing_fmts;
+ return params;
+}
+
+typedef struct {
+ AVFifoBuffer *fifo; ///< FIFO buffer of video frame references
+
+ /* only used for video */
+ const enum PixelFormat *pixel_fmts; ///< list of accepted pixel formats, must be terminated with -1
+
+ /* only used for audio */
+ const enum AVSampleFormat *sample_fmts; ///< list of accepted sample formats, terminated by AV_SAMPLE_FMT_NONE
+ const int64_t *channel_layouts; ///< list of accepted channel layouts, terminated by -1
+ const int *packing_fmts; ///< list of accepted packing formats, terminated by -1
+} BufferSinkContext;
+
+#define FIFO_INIT_SIZE 8
+
+static av_cold int common_init(AVFilterContext *ctx)
+{
+ BufferSinkContext *buf = ctx->priv;
+
+ buf->fifo = av_fifo_alloc(FIFO_INIT_SIZE*sizeof(AVFilterBufferRef *));
+ if (!buf->fifo) {
+ av_log(ctx, AV_LOG_ERROR, "Failed to allocate fifo\n");
+ return AVERROR(ENOMEM);
+ }
+ return 0;
+}
+
+static av_cold void common_uninit(AVFilterContext *ctx)
+{
+ BufferSinkContext *buf = ctx->priv;
+ AVFilterBufferRef *picref;
+
+ if (buf->fifo) {
+ while (av_fifo_size(buf->fifo) >= sizeof(AVFilterBufferRef *)) {
+ av_fifo_generic_read(buf->fifo, &picref, sizeof(picref), NULL);
+ avfilter_unref_buffer(picref);
+ }
+ av_fifo_free(buf->fifo);
+ buf->fifo = NULL;
+ }
+}
+
+static void end_frame(AVFilterLink *inlink)
+{
+ AVFilterContext *ctx = inlink->dst;
+ BufferSinkContext *buf = inlink->dst->priv;
+
+ if (av_fifo_space(buf->fifo) < sizeof(AVFilterBufferRef *)) {
+ /* realloc fifo size */
+ if (av_fifo_realloc2(buf->fifo, av_fifo_size(buf->fifo) * 2) < 0) {
+ av_log(ctx, AV_LOG_ERROR,
+ "Cannot buffer more frames. Consume some available frames "
+ "before adding new ones.\n");
+ return;
+ }
+ }
+
+ /* cache frame */
+ av_fifo_generic_write(buf->fifo,
+ &inlink->cur_buf, sizeof(AVFilterBufferRef *), NULL);
+}
+
+int av_buffersink_get_buffer_ref(AVFilterContext *ctx,
+ AVFilterBufferRef **bufref, int flags)
+{
+ BufferSinkContext *buf = ctx->priv;
+ AVFilterLink *inlink = ctx->inputs[0];
+ int ret;
+ *bufref = NULL;
+
+ /* no picref available, fetch it from the filterchain */
+ if (!av_fifo_size(buf->fifo)) {
+ if ((ret = avfilter_request_frame(inlink)) < 0)
+ return ret;
+ }
+
+ if (!av_fifo_size(buf->fifo))
+ return AVERROR(EINVAL);
+
+ if (flags & AV_BUFFERSINK_FLAG_PEEK)
+ *bufref = *((AVFilterBufferRef **)av_fifo_peek2(buf->fifo, 0));
+ else
+ av_fifo_generic_read(buf->fifo, bufref, sizeof(*bufref), NULL);
+
+ return 0;
+}
+
+#if FF_API_OLD_VSINK_API
+int av_vsink_buffer_get_video_buffer_ref(AVFilterContext *ctx,
+ AVFilterBufferRef **picref, int flags)
+{
+ return av_buffersink_get_buffer_ref(ctx, picref, flags);
+}
+#endif
+
+#if CONFIG_BUFFERSINK_FILTER
+
+static av_cold int vsink_init(AVFilterContext *ctx, const char *args, void *opaque)
+{
+ BufferSinkContext *buf = ctx->priv;
+ av_unused AVBufferSinkParams *params;
+
+ if (!opaque) {
+ av_log(ctx, AV_LOG_ERROR,
+ "No opaque field provided\n");
+ return AVERROR(EINVAL);
+ } else {
+#if FF_API_OLD_VSINK_API
+ buf->pixel_fmts = (const enum PixelFormat *)opaque;
+#else
+ params = (AVBufferSinkParams *)opaque;
+ buf->pixel_fmts = params->pixel_fmts;
+#endif
+ }
+
+ return common_init(ctx);
+}
+
+static int vsink_query_formats(AVFilterContext *ctx)
+{
+ BufferSinkContext *buf = ctx->priv;
+
+ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(buf->pixel_fmts));
+ return 0;
+}
+
+AVFilter avfilter_vsink_buffersink = {
+ .name = "buffersink",
+ .description = NULL_IF_CONFIG_SMALL("Buffer video frames, and make them available to the end of the filter graph."),
+ .priv_size = sizeof(BufferSinkContext),
+ .init = vsink_init,
+ .uninit = common_uninit,
+
+ .query_formats = vsink_query_formats,
+
+ .inputs = (AVFilterPad[]) {{ .name = "default",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .end_frame = end_frame,
+ .min_perms = AV_PERM_READ, },
+ { .name = NULL }},
+ .outputs = (AVFilterPad[]) {{ .name = NULL }},
+};
+
+#endif /* CONFIG_BUFFERSINK_FILTER */
+
+#if CONFIG_ABUFFERSINK_FILTER
+
+static void filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)
+{
+ end_frame(link);
+}
+
+static av_cold int asink_init(AVFilterContext *ctx, const char *args, void *opaque)
+{
+ BufferSinkContext *buf = ctx->priv;
+ AVABufferSinkParams *params;
+
+ if (!opaque) {
+ av_log(ctx, AV_LOG_ERROR,
+ "No opaque field provided, an AVABufferSinkParams struct is required\n");
+ return AVERROR(EINVAL);
+ } else
+ params = (AVABufferSinkParams *)opaque;
+
+ buf->sample_fmts = params->sample_fmts;
+ buf->channel_layouts = params->channel_layouts;
+ buf->packing_fmts = params->packing_fmts;
+
+ return common_init(ctx);
+}
+
+static int asink_query_formats(AVFilterContext *ctx)
+{
+ BufferSinkContext *buf = ctx->priv;
+ AVFilterFormats *formats = NULL;
+
+ if (!(formats = avfilter_make_format_list(buf->sample_fmts)))
+ return AVERROR(ENOMEM);
+ avfilter_set_common_sample_formats(ctx, formats);
+
+ if (!(formats = avfilter_make_format64_list(buf->channel_layouts)))
+ return AVERROR(ENOMEM);
+ avfilter_set_common_channel_layouts(ctx, formats);
+
+ if (!(formats = avfilter_make_format_list(buf->packing_fmts)))
+ return AVERROR(ENOMEM);
+ avfilter_set_common_packing_formats(ctx, formats);
+
+ return 0;
+}
+
+AVFilter avfilter_asink_abuffersink = {
+ .name = "abuffersink",
+ .description = NULL_IF_CONFIG_SMALL("Buffer audio frames, and make them available to the end of the filter graph."),
+ .init = asink_init,
+ .uninit = common_uninit,
+ .priv_size = sizeof(BufferSinkContext),
+ .query_formats = asink_query_formats,
+
+ .inputs = (AVFilterPad[]) {{ .name = "default",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .filter_samples = filter_samples,
+ .min_perms = AV_PERM_READ, },
+ { .name = NULL }},
+ .outputs = (AVFilterPad[]) {{ .name = NULL }},
+};
+
+#endif /* CONFIG_ABUFFERSINK_FILTER */
diff --git a/libavfilter/vsrc_movie.c b/libavfilter/src_movie.c
index 7556fa2e9e..c37195a331 100644
--- a/libavfilter/vsrc_movie.c
+++ b/libavfilter/src_movie.c
@@ -2,20 +2,20 @@
* Copyright (c) 2010 Stefano Sabatini
* Copyright (c) 2008 Victor Paesa
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -35,9 +35,11 @@
#include "libavutil/opt.h"
#include "libavutil/imgutils.h"
#include "libavformat/avformat.h"
+#include "avcodec.h"
#include "avfilter.h"
typedef struct {
+ /* common A/V fields */
const AVClass *class;
int64_t seek_point; ///< seekpoint in microseconds
double seek_point_d;
@@ -50,19 +52,27 @@ typedef struct {
int is_done;
AVFrame *frame; ///< video frame to store the decoded images in
+ /* video-only fields */
int w, h;
AVFilterBufferRef *picref;
+
+ /* audio-only fields */
+ void *samples_buf;
+ int samples_buf_size;
+ int bps; ///< bytes per sample
+ AVPacket pkt, pkt0;
+ AVFilterBufferRef *samplesref;
} MovieContext;
#define OFFSET(x) offsetof(MovieContext, x)
static const AVOption movie_options[]= {
-{"format_name", "set format name", OFFSET(format_name), FF_OPT_TYPE_STRING, {.str = 0}, CHAR_MIN, CHAR_MAX },
-{"f", "set format name", OFFSET(format_name), FF_OPT_TYPE_STRING, {.str = 0}, CHAR_MIN, CHAR_MAX },
-{"stream_index", "set stream index", OFFSET(stream_index), FF_OPT_TYPE_INT, {.dbl = -1}, -1, INT_MAX },
-{"si", "set stream index", OFFSET(stream_index), FF_OPT_TYPE_INT, {.dbl = -1}, -1, INT_MAX },
-{"seek_point", "set seekpoint (seconds)", OFFSET(seek_point_d), FF_OPT_TYPE_DOUBLE, {.dbl = 0}, 0, (INT64_MAX-1) / 1000000 },
-{"sp", "set seekpoint (seconds)", OFFSET(seek_point_d), FF_OPT_TYPE_DOUBLE, {.dbl = 0}, 0, (INT64_MAX-1) / 1000000 },
+{"format_name", "set format name", OFFSET(format_name), AV_OPT_TYPE_STRING, {.str = 0}, CHAR_MIN, CHAR_MAX },
+{"f", "set format name", OFFSET(format_name), AV_OPT_TYPE_STRING, {.str = 0}, CHAR_MIN, CHAR_MAX },
+{"stream_index", "set stream index", OFFSET(stream_index), AV_OPT_TYPE_INT, {.dbl = -1}, -1, INT_MAX },
+{"si", "set stream index", OFFSET(stream_index), AV_OPT_TYPE_INT, {.dbl = -1}, -1, INT_MAX },
+{"seek_point", "set seekpoint (seconds)", OFFSET(seek_point_d), AV_OPT_TYPE_DOUBLE, {.dbl = 0}, 0, (INT64_MAX-1) / 1000000 },
+{"sp", "set seekpoint (seconds)", OFFSET(seek_point_d), AV_OPT_TYPE_DOUBLE, {.dbl = 0}, 0, (INT64_MAX-1) / 1000000 },
{NULL},
};
@@ -77,13 +87,31 @@ static const AVClass movie_class = {
movie_options
};
-static int movie_init(AVFilterContext *ctx)
+static av_cold int movie_common_init(AVFilterContext *ctx, const char *args, void *opaque,
+ enum AVMediaType type)
{
MovieContext *movie = ctx->priv;
AVInputFormat *iformat = NULL;
AVCodec *codec;
- int ret;
int64_t timestamp;
+ int ret;
+
+ movie->class = &movie_class;
+ av_opt_set_defaults(movie);
+
+ if (args)
+ movie->file_name = av_get_token(&args, ":");
+ if (!movie->file_name || !*movie->file_name) {
+ av_log(ctx, AV_LOG_ERROR, "No filename provided!\n");
+ return AVERROR(EINVAL);
+ }
+
+ if (*args++ == ':' && (ret = av_set_options_string(movie, args, "=", ":")) < 0) {
+ av_log(ctx, AV_LOG_ERROR, "Error parsing options string: '%s'\n", args);
+ return ret;
+ }
+
+ movie->seek_point = movie->seek_point_d * 1000000 + 0.5;
av_register_all();
@@ -96,7 +124,7 @@ static int movie_init(AVFilterContext *ctx)
"Failed to avformat_open_input '%s'\n", movie->file_name);
return ret;
}
- if ((ret = av_find_stream_info(movie->format_ctx)) < 0)
+ if ((ret = avformat_find_stream_info(movie->format_ctx, NULL)) < 0)
av_log(ctx, AV_LOG_WARNING, "Failed to find stream info\n");
// if seeking requested, we execute it
@@ -119,11 +147,11 @@ static int movie_init(AVFilterContext *ctx)
}
}
- /* select the video stream */
- if ((ret = av_find_best_stream(movie->format_ctx, AVMEDIA_TYPE_VIDEO,
+ /* select the media stream */
+ if ((ret = av_find_best_stream(movie->format_ctx, type,
movie->stream_index, -1, NULL, 0)) < 0) {
- av_log(ctx, AV_LOG_ERROR, "No video stream with index '%d' found\n",
- movie->stream_index);
+ av_log(ctx, AV_LOG_ERROR, "No %s stream with index '%d' found\n",
+ av_get_media_type_string(type), movie->stream_index);
return ret;
}
movie->stream_index = ret;
@@ -139,19 +167,11 @@ static int movie_init(AVFilterContext *ctx)
return AVERROR(EINVAL);
}
- if ((ret = avcodec_open(movie->codec_ctx, codec)) < 0) {
+ if ((ret = avcodec_open2(movie->codec_ctx, codec, NULL)) < 0) {
av_log(ctx, AV_LOG_ERROR, "Failed to open codec\n");
return ret;
}
- if (!(movie->frame = avcodec_alloc_frame()) ) {
- av_log(ctx, AV_LOG_ERROR, "Failed to alloc frame\n");
- return AVERROR(ENOMEM);
- }
-
- movie->w = movie->codec_ctx->width;
- movie->h = movie->codec_ctx->height;
-
av_log(ctx, AV_LOG_INFO, "seek_point:%"PRIi64" format_name:%s file_name:%s stream_index:%d\n",
movie->seek_point, movie->format_name, movie->file_name,
movie->stream_index);
@@ -159,31 +179,7 @@ static int movie_init(AVFilterContext *ctx)
return 0;
}
-static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
-{
- MovieContext *movie = ctx->priv;
- int ret;
- movie->class = &movie_class;
- av_opt_set_defaults2(movie, 0, 0);
-
- if (args)
- movie->file_name = av_get_token(&args, ":");
- if (!movie->file_name || !*movie->file_name) {
- av_log(ctx, AV_LOG_ERROR, "No filename provided!\n");
- return AVERROR(EINVAL);
- }
-
- if (*args++ == ':' && (ret = av_set_options_string(movie, args, "=", ":")) < 0) {
- av_log(ctx, AV_LOG_ERROR, "Error parsing options string: '%s'\n", args);
- return ret;
- }
-
- movie->seek_point = movie->seek_point_d * 1000000 + 0.5;
-
- return movie_init(ctx);
-}
-
-static av_cold void uninit(AVFilterContext *ctx)
+static av_cold void movie_common_uninit(AVFilterContext *ctx)
{
MovieContext *movie = ctx->priv;
@@ -193,20 +189,45 @@ static av_cold void uninit(AVFilterContext *ctx)
avcodec_close(movie->codec_ctx);
if (movie->format_ctx)
av_close_input_file(movie->format_ctx);
+
avfilter_unref_buffer(movie->picref);
av_freep(&movie->frame);
+
+ avfilter_unref_buffer(movie->samplesref);
+ av_freep(&movie->samples_buf);
}
-static int query_formats(AVFilterContext *ctx)
+#if CONFIG_MOVIE_FILTER
+
+static av_cold int movie_init(AVFilterContext *ctx, const char *args, void *opaque)
+{
+ MovieContext *movie = ctx->priv;
+ int ret;
+
+ if ((ret = movie_common_init(ctx, args, opaque, AVMEDIA_TYPE_VIDEO)) < 0)
+ return ret;
+
+ if (!(movie->frame = avcodec_alloc_frame()) ) {
+ av_log(ctx, AV_LOG_ERROR, "Failed to alloc frame\n");
+ return AVERROR(ENOMEM);
+ }
+
+ movie->w = movie->codec_ctx->width;
+ movie->h = movie->codec_ctx->height;
+
+ return 0;
+}
+
+static int movie_query_formats(AVFilterContext *ctx)
{
MovieContext *movie = ctx->priv;
enum PixelFormat pix_fmts[] = { movie->codec_ctx->pix_fmt, PIX_FMT_NONE };
- avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts));
+ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts));
return 0;
}
-static int config_output_props(AVFilterLink *outlink)
+static int movie_config_output_props(AVFilterLink *outlink)
{
MovieContext *movie = outlink->src->priv;
@@ -230,7 +251,6 @@ static int movie_get_frame(AVFilterLink *outlink)
while ((ret = av_read_frame(movie->format_ctx, &pkt)) >= 0) {
// Is this a packet from the video stream?
if (pkt.stream_index == movie->stream_index) {
- movie->codec_ctx->reordered_opaque = pkt.pos;
avcodec_decode_video2(movie->codec_ctx, movie->frame, &frame_decoded, &pkt);
if (frame_decoded) {
@@ -238,28 +258,24 @@ static int movie_get_frame(AVFilterLink *outlink)
movie->picref = avfilter_get_video_buffer(outlink, AV_PERM_WRITE | AV_PERM_PRESERVE |
AV_PERM_REUSE2, outlink->w, outlink->h);
av_image_copy(movie->picref->data, movie->picref->linesize,
- movie->frame->data, movie->frame->linesize,
+ (void*)movie->frame->data, movie->frame->linesize,
movie->picref->format, outlink->w, outlink->h);
+ avfilter_copy_frame_props(movie->picref, movie->frame);
/* FIXME: use a PTS correction mechanism as that in
* ffplay.c when some API will be available for that */
/* use pkt_dts if pkt_pts is not available */
movie->picref->pts = movie->frame->pkt_pts == AV_NOPTS_VALUE ?
movie->frame->pkt_dts : movie->frame->pkt_pts;
-
- movie->picref->pos = movie->frame->reordered_opaque;
- movie->picref->video->pixel_aspect = st->sample_aspect_ratio.num ?
- st->sample_aspect_ratio : movie->codec_ctx->sample_aspect_ratio;
- movie->picref->video->interlaced = movie->frame->interlaced_frame;
- movie->picref->video->top_field_first = movie->frame->top_field_first;
- movie->picref->video->key_frame = movie->frame->key_frame;
- movie->picref->video->pict_type = movie->frame->pict_type;
+ if (!movie->frame->sample_aspect_ratio.num)
+ movie->picref->video->sample_aspect_ratio = st->sample_aspect_ratio;
av_dlog(outlink->src,
"movie_get_frame(): file:'%s' pts:%"PRId64" time:%lf pos:%"PRId64" aspect:%d/%d\n",
movie->file_name, movie->picref->pts,
(double)movie->picref->pts * av_q2d(st->time_base),
movie->picref->pos,
- movie->picref->video->pixel_aspect.num, movie->picref->video->pixel_aspect.den);
+ movie->picref->video->sample_aspect_ratio.num,
+ movie->picref->video->sample_aspect_ratio.den);
// We got it. Free the packet since we are returning
av_free_packet(&pkt);
@@ -277,7 +293,7 @@ static int movie_get_frame(AVFilterLink *outlink)
return ret;
}
-static int request_frame(AVFilterLink *outlink)
+static int movie_request_frame(AVFilterLink *outlink)
{
AVFilterBufferRef *outpicref;
MovieContext *movie = outlink->src->priv;
@@ -302,14 +318,157 @@ AVFilter avfilter_vsrc_movie = {
.name = "movie",
.description = NULL_IF_CONFIG_SMALL("Read from a movie source."),
.priv_size = sizeof(MovieContext),
- .init = init,
- .uninit = uninit,
- .query_formats = query_formats,
+ .init = movie_init,
+ .uninit = movie_common_uninit,
+ .query_formats = movie_query_formats,
.inputs = (AVFilterPad[]) {{ .name = NULL }},
.outputs = (AVFilterPad[]) {{ .name = "default",
.type = AVMEDIA_TYPE_VIDEO,
- .request_frame = request_frame,
- .config_props = config_output_props, },
+ .request_frame = movie_request_frame,
+ .config_props = movie_config_output_props, },
{ .name = NULL}},
};
+
+#endif /* CONFIG_MOVIE_FILTER */
+
+#if CONFIG_AMOVIE_FILTER
+
+static av_cold int amovie_init(AVFilterContext *ctx, const char *args, void *opaque)
+{
+ MovieContext *movie = ctx->priv;
+ int ret;
+
+ if ((ret = movie_common_init(ctx, args, opaque, AVMEDIA_TYPE_AUDIO)) < 0)
+ return ret;
+
+ movie->bps = av_get_bytes_per_sample(movie->codec_ctx->sample_fmt);
+ return 0;
+}
+
+static int amovie_query_formats(AVFilterContext *ctx)
+{
+ MovieContext *movie = ctx->priv;
+ AVCodecContext *c = movie->codec_ctx;
+
+ enum AVSampleFormat sample_fmts[] = { c->sample_fmt, -1 };
+ int packing_fmts[] = { AVFILTER_PACKED, -1 };
+ int64_t chlayouts[] = { c->channel_layout, -1 };
+
+ avfilter_set_common_sample_formats (ctx, avfilter_make_format_list(sample_fmts));
+ avfilter_set_common_packing_formats(ctx, avfilter_make_format_list(packing_fmts));
+ avfilter_set_common_channel_layouts(ctx, avfilter_make_format64_list(chlayouts));
+
+ return 0;
+}
+
+static int amovie_config_output_props(AVFilterLink *outlink)
+{
+ MovieContext *movie = outlink->src->priv;
+ AVCodecContext *c = movie->codec_ctx;
+
+ outlink->sample_rate = c->sample_rate;
+ outlink->time_base = movie->format_ctx->streams[movie->stream_index]->time_base;
+
+ return 0;
+}
+
+static int amovie_get_samples(AVFilterLink *outlink)
+{
+ MovieContext *movie = outlink->src->priv;
+ AVPacket pkt;
+ int ret, samples_size, decoded_data_size;
+
+ if (!movie->pkt.size && movie->is_done == 1)
+ return AVERROR_EOF;
+
+ /* check for another frame, in case the previous one was completely consumed */
+ if (!movie->pkt.size) {
+ while ((ret = av_read_frame(movie->format_ctx, &pkt)) >= 0) {
+ // Is this a packet from the selected stream?
+ if (pkt.stream_index != movie->stream_index) {
+ av_free_packet(&pkt);
+ continue;
+ } else {
+ movie->pkt0 = movie->pkt = pkt;
+ break;
+ }
+ }
+
+ if (ret == AVERROR_EOF) {
+ movie->is_done = 1;
+ return ret;
+ }
+ }
+
+ /* reallocate the buffer for the decoded samples, if necessary */
+ samples_size =
+ FFMAX(movie->pkt.size*sizeof(movie->bps), AVCODEC_MAX_AUDIO_FRAME_SIZE);
+ if (samples_size > movie->samples_buf_size) {
+ movie->samples_buf = av_fast_realloc(movie->samples_buf,
+ &movie->samples_buf_size, samples_size);
+ if (!movie->samples_buf)
+ return AVERROR(ENOMEM);
+ }
+ decoded_data_size = movie->samples_buf_size;
+
+ /* decode and update the movie pkt */
+ ret = avcodec_decode_audio3(movie->codec_ctx, movie->samples_buf,
+ &decoded_data_size, &movie->pkt);
+ if (ret < 0)
+ return ret;
+ movie->pkt.data += ret;
+ movie->pkt.size -= ret;
+
+ /* wrap the decoded data in a samplesref */
+ if (decoded_data_size > 0) {
+ int nb_samples = decoded_data_size / movie->bps / movie->codec_ctx->channels;
+ movie->samplesref =
+ avfilter_get_audio_buffer(outlink, AV_PERM_WRITE, nb_samples);
+ memcpy(movie->samplesref->data[0], movie->samples_buf, decoded_data_size);
+ movie->samplesref->pts = movie->pkt.pts;
+ movie->samplesref->pos = movie->pkt.pos;
+ movie->samplesref->audio->sample_rate = movie->codec_ctx->sample_rate;
+ }
+
+ // We got it. Free the packet since we are returning
+ if (movie->pkt.size <= 0)
+ av_free_packet(&movie->pkt0);
+
+ return 0;
+}
+
+static int amovie_request_frame(AVFilterLink *outlink)
+{
+ MovieContext *movie = outlink->src->priv;
+ int ret;
+
+ if (movie->is_done)
+ return AVERROR_EOF;
+ if ((ret = amovie_get_samples(outlink)) < 0)
+ return ret;
+
+ avfilter_filter_samples(outlink, avfilter_ref_buffer(movie->samplesref, ~0));
+ avfilter_unref_buffer(movie->samplesref);
+ movie->samplesref = NULL;
+
+ return 0;
+}
+
+AVFilter avfilter_asrc_amovie = {
+ .name = "amovie",
+ .description = NULL_IF_CONFIG_SMALL("Read audio from a movie source."),
+ .priv_size = sizeof(MovieContext),
+ .init = amovie_init,
+ .uninit = movie_common_uninit,
+ .query_formats = amovie_query_formats,
+
+ .inputs = (AVFilterPad[]) {{ .name = NULL }},
+ .outputs = (AVFilterPad[]) {{ .name = "default",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .request_frame = amovie_request_frame,
+ .config_props = amovie_config_output_props, },
+ { .name = NULL}},
+};
+
+#endif /* CONFIG_AMOVIE_FILTER */
diff --git a/libavfilter/transform.c b/libavfilter/transform.c
new file mode 100644
index 0000000000..800f784446
--- /dev/null
+++ b/libavfilter/transform.c
@@ -0,0 +1,182 @@
+/*
+ * Copyright (C) 2010 Georg Martius <georg.martius@web.de>
+ * Copyright (C) 2010 Daniel G. Taylor <dan@programmer-art.org>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * transform input video
+ */
+
+#include "libavutil/common.h"
+
+#include "transform.h"
+
+#define INTERPOLATE_METHOD(name) \
+ static uint8_t name(float x, float y, const uint8_t *src, \
+ int width, int height, int stride, uint8_t def)
+
+#define PIXEL(img, x, y, w, h, stride, def) \
+ ((x) < 0 || (y) < 0) ? (def) : \
+ (((x) >= (w) || (y) >= (h)) ? (def) : \
+ img[(x) + (y) * (stride)])
+
+/**
+ * Nearest neighbor interpolation
+ */
+INTERPOLATE_METHOD(interpolate_nearest)
+{
+ return PIXEL(src, (int)(x + 0.5), (int)(y + 0.5), width, height, stride, def);
+}
+
+/**
+ * Bilinear interpolation
+ */
+INTERPOLATE_METHOD(interpolate_bilinear)
+{
+ int x_c, x_f, y_c, y_f;
+ int v1, v2, v3, v4;
+
+ if (x < -1 || x > width || y < -1 || y > height) {
+ return def;
+ } else {
+ x_f = (int)x;
+ x_c = x_f + 1;
+
+ y_f = (int)y;
+ y_c = y_f + 1;
+
+ v1 = PIXEL(src, x_c, y_c, width, height, stride, def);
+ v2 = PIXEL(src, x_c, y_f, width, height, stride, def);
+ v3 = PIXEL(src, x_f, y_c, width, height, stride, def);
+ v4 = PIXEL(src, x_f, y_f, width, height, stride, def);
+
+ return (v1*(x - x_f)*(y - y_f) + v2*((x - x_f)*(y_c - y)) +
+ v3*(x_c - x)*(y - y_f) + v4*((x_c - x)*(y_c - y)));
+ }
+}
+
+/**
+ * Biquadratic interpolation
+ */
+INTERPOLATE_METHOD(interpolate_biquadratic)
+{
+ int x_c, x_f, y_c, y_f;
+ uint8_t v1, v2, v3, v4;
+ float f1, f2, f3, f4;
+
+ if (x < - 1 || x > width || y < -1 || y > height)
+ return def;
+ else {
+ x_f = (int)x;
+ x_c = x_f + 1;
+ y_f = (int)y;
+ y_c = y_f + 1;
+
+ v1 = PIXEL(src, x_c, y_c, width, height, stride, def);
+ v2 = PIXEL(src, x_c, y_f, width, height, stride, def);
+ v3 = PIXEL(src, x_f, y_c, width, height, stride, def);
+ v4 = PIXEL(src, x_f, y_f, width, height, stride, def);
+
+ f1 = 1 - sqrt((x_c - x) * (y_c - y));
+ f2 = 1 - sqrt((x_c - x) * (y - y_f));
+ f3 = 1 - sqrt((x - x_f) * (y_c - y));
+ f4 = 1 - sqrt((x - x_f) * (y - y_f));
+ return (v1 * f1 + v2 * f2 + v3 * f3 + v4 * f4) / (f1 + f2 + f3 + f4);
+ }
+}
+
+void avfilter_get_matrix(float x_shift, float y_shift, float angle, float zoom, float *matrix) {
+ matrix[0] = zoom * cos(angle);
+ matrix[1] = -sin(angle);
+ matrix[2] = x_shift;
+ matrix[3] = -matrix[1];
+ matrix[4] = matrix[0];
+ matrix[5] = y_shift;
+ matrix[6] = 0;
+ matrix[7] = 0;
+ matrix[8] = 1;
+}
+
+void avfilter_add_matrix(const float *m1, const float *m2, float *result)
+{
+ for (int i = 0; i < 9; i++)
+ result[i] = m1[i] + m2[i];
+}
+
+void avfilter_sub_matrix(const float *m1, const float *m2, float *result)
+{
+ for (int i = 0; i < 9; i++)
+ result[i] = m1[i] - m2[i];
+}
+
+void avfilter_mul_matrix(const float *m1, float scalar, float *result)
+{
+ for (int i = 0; i < 9; i++)
+ result[i] = m1[i] * scalar;
+}
+
+void avfilter_transform(const uint8_t *src, uint8_t *dst,
+ int src_stride, int dst_stride,
+ int width, int height, const float *matrix,
+ enum InterpolateMethod interpolate,
+ enum FillMethod fill)
+{
+ int x, y;
+ float x_s, y_s;
+ uint8_t def = 0;
+ uint8_t (*func)(float, float, const uint8_t *, int, int, int, uint8_t) = NULL;
+
+ switch(interpolate) {
+ case INTERPOLATE_NEAREST:
+ func = interpolate_nearest;
+ break;
+ case INTERPOLATE_BILINEAR:
+ func = interpolate_bilinear;
+ break;
+ case INTERPOLATE_BIQUADRATIC:
+ func = interpolate_biquadratic;
+ break;
+ }
+
+ for (y = 0; y < height; y++) {
+ for(x = 0; x < width; x++) {
+ x_s = x * matrix[0] + y * matrix[1] + matrix[2];
+ y_s = x * matrix[3] + y * matrix[4] + matrix[5];
+
+ switch(fill) {
+ case FILL_ORIGINAL:
+ def = src[y * src_stride + x];
+ break;
+ case FILL_CLAMP:
+ y_s = av_clipf(y_s, 0, height - 1);
+ x_s = av_clipf(x_s, 0, width - 1);
+ def = src[(int)y_s * src_stride + (int)x_s];
+ break;
+ case FILL_MIRROR:
+ y_s = (y_s < 0) ? -y_s : (y_s >= height) ? (height + height - y_s) : y_s;
+ x_s = (x_s < 0) ? -x_s : (x_s >= width) ? (width + width - x_s) : x_s;
+ def = src[(int)y_s * src_stride + (int)x_s];
+ }
+
+ dst[y * dst_stride + x] = func(x_s, y_s, src, width, height, src_stride, def);
+ }
+ }
+}
+
diff --git a/libavfilter/transform.h b/libavfilter/transform.h
new file mode 100644
index 0000000000..701c833ecc
--- /dev/null
+++ b/libavfilter/transform.h
@@ -0,0 +1,124 @@
+/*
+ * Copyright (C) 2010 Georg Martius <georg.martius@web.de>
+ * Copyright (C) 2010 Daniel G. Taylor <dan@programmer-art.org>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVFILTER_TRANSFORM_H
+#define AVFILTER_TRANSFORM_H
+
+/**
+ * @file
+ * transform input video
+ *
+ * All matrices are defined as a single 9-item block of contiguous memory. For
+ * example, the identity matrix would be:
+ *
+ * float *matrix = {1, 0, 0,
+ * 0, 1, 0,
+ * 0, 0, 1};
+ */
+
+enum InterpolateMethod {
+ INTERPOLATE_NEAREST, //< Nearest-neighbor (fast)
+ INTERPOLATE_BILINEAR, //< Bilinear
+ INTERPOLATE_BIQUADRATIC, //< Biquadratic (best)
+ INTERPOLATE_COUNT, //< Number of interpolation methods
+};
+
+// Shortcuts for the fastest and best interpolation methods
+#define INTERPOLATE_DEFAULT INTERPOLATE_BILINEAR
+#define INTERPOLATE_FAST INTERPOLATE_NEAREST
+#define INTERPOLATE_BEST INTERPOLATE_BIQUADRATIC
+
+enum FillMethod {
+ FILL_BLANK, //< Fill zeroes at blank locations
+ FILL_ORIGINAL, //< Original image at blank locations
+ FILL_CLAMP, //< Extruded edge value at blank locations
+ FILL_MIRROR, //< Mirrored edge at blank locations
+ FILL_COUNT, //< Number of edge fill methods
+};
+
+// Shortcuts for fill methods
+#define FILL_DEFAULT FILL_ORIGINAL
+
+/**
+ * Get an affine transformation matrix from a given translation, rotation, and
+ * zoom factor. The matrix will look like:
+ *
+ * [ zoom * cos(angle), -sin(angle), x_shift,
+ * sin(angle), zoom * cos(angle), y_shift,
+ * 0, 0, 1 ]
+ *
+ * @param x_shift horizontal translation
+ * @param y_shift vertical translation
+ * @param angle rotation in radians
+ * @param zoom scale percent (1.0 = 100%)
+ * @param matrix 9-item affine transformation matrix
+ */
+void avfilter_get_matrix(float x_shift, float y_shift, float angle, float zoom, float *matrix);
+
+/**
+ * Add two matrices together. result = m1 + m2.
+ *
+ * @param m1 9-item transformation matrix
+ * @param m2 9-item transformation matrix
+ * @param result 9-item transformation matrix
+ */
+void avfilter_add_matrix(const float *m1, const float *m2, float *result);
+
+/**
+ * Subtract one matrix from another. result = m1 - m2.
+ *
+ * @param m1 9-item transformation matrix
+ * @param m2 9-item transformation matrix
+ * @param result 9-item transformation matrix
+ */
+void avfilter_sub_matrix(const float *m1, const float *m2, float *result);
+
+/**
+ * Multiply a matrix by a scalar value. result = m1 * scalar.
+ *
+ * @param m1 9-item transformation matrix
+ * @param scalar a number
+ * @param result 9-item transformation matrix
+ */
+void avfilter_mul_matrix(const float *m1, float scalar, float *result);
+
+/**
+ * Do an affine transformation with the given interpolation method. This
+ * multiplies each vector [x,y,1] by the matrix and then interpolates to
+ * get the final value.
+ *
+ * @param src source image
+ * @param dst destination image
+ * @param src_stride source image line size in bytes
+ * @param dst_stride destination image line size in bytes
+ * @param width image width in pixels
+ * @param height image height in pixels
+ * @param matrix 9-item affine transformation matrix
+ * @param interpolate pixel interpolation method
+ * @param fill edge fill method
+ */
+void avfilter_transform(const uint8_t *src, uint8_t *dst,
+ int src_stride, int dst_stride,
+ int width, int height, const float *matrix,
+ enum InterpolateMethod interpolate,
+ enum FillMethod fill);
+
+#endif /* AVFILTER_TRANSFORM_H */
diff --git a/libavfilter/vf_aspect.c b/libavfilter/vf_aspect.c
index b43aa86bea..5234adb4f5 100644
--- a/libavfilter/vf_aspect.c
+++ b/libavfilter/vf_aspect.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2010 Bobby Bingham
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -66,7 +66,7 @@ static void start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
{
AspectContext *aspect = link->dst->priv;
- picref->video->pixel_aspect = aspect->aspect;
+ picref->video->sample_aspect_ratio = aspect->aspect;
avfilter_start_frame(link->dst->outputs[0], picref);
}
diff --git a/libavfilter/vf_blackframe.c b/libavfilter/vf_blackframe.c
index 770eec94e0..843e8273f4 100644
--- a/libavfilter/vf_blackframe.c
+++ b/libavfilter/vf_blackframe.c
@@ -4,20 +4,20 @@
* Copyright (c) 2006 Julian Hall
* Copyright (c) 2002-2003 Brian J. Murrell
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or modify
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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 Libav; if not, write to the Free Software Foundation, Inc.,
+ * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
@@ -34,6 +34,7 @@ typedef struct {
unsigned int bthresh; ///< black threshold
unsigned int frame; ///< frame number
unsigned int nblack; ///< number of black pixels counted so far
+ unsigned int last_keyframe; ///< frame number of the last received key-frame
} BlackFrameContext;
static int query_formats(AVFilterContext *ctx)
@@ -44,7 +45,7 @@ static int query_formats(AVFilterContext *ctx)
PIX_FMT_NONE
};
- avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts));
+ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts));
return 0;
}
@@ -56,6 +57,7 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
blackframe->bthresh = 32;
blackframe->nblack = 0;
blackframe->frame = 0;
+ blackframe->last_keyframe = 0;
if (args)
sscanf(args, "%u:%u", &blackframe->bamount, &blackframe->bthresh);
@@ -95,11 +97,16 @@ static void end_frame(AVFilterLink *inlink)
AVFilterBufferRef *picref = inlink->cur_buf;
int pblack = 0;
+ if (picref->video->key_frame)
+ blackframe->last_keyframe = blackframe->frame;
+
pblack = blackframe->nblack * 100 / (inlink->w * inlink->h);
if (pblack >= blackframe->bamount)
- av_log(ctx, AV_LOG_INFO, "frame:%u pblack:%u pos:%"PRId64" pts:%"PRId64" t:%f\n",
+ av_log(ctx, AV_LOG_INFO, "frame:%u pblack:%u pos:%"PRId64" pts:%"PRId64" t:%f "
+ "type:%c last_keyframe:%d\n",
blackframe->frame, pblack, picref->pos, picref->pts,
- picref->pts == AV_NOPTS_VALUE ? -1 : picref->pts * av_q2d(inlink->time_base));
+ picref->pts == AV_NOPTS_VALUE ? -1 : picref->pts * av_q2d(inlink->time_base),
+ av_get_picture_type_char(picref->video->pict_type), blackframe->last_keyframe);
blackframe->frame++;
blackframe->nblack = 0;
diff --git a/libavfilter/vf_boxblur.c b/libavfilter/vf_boxblur.c
new file mode 100644
index 0000000000..8d82c436a1
--- /dev/null
+++ b/libavfilter/vf_boxblur.c
@@ -0,0 +1,345 @@
+/*
+ * Copyright (c) 2002 Michael Niedermayer <michaelni@gmx.at>
+ * Copyright (c) 2011 Stefano Sabatini
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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 FFmpeg; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+/**
+ * @file
+ * Apply a boxblur filter to the input video.
+ * Ported from MPlayer libmpcodecs/vf_boxblur.c.
+ */
+
+#include "libavutil/avstring.h"
+#include "libavutil/eval.h"
+#include "libavutil/pixdesc.h"
+#include "avfilter.h"
+
+static const char *var_names[] = {
+ "w",
+ "h",
+ "cw",
+ "ch",
+ "hsub",
+ "vsub",
+ NULL
+};
+
+enum var_name {
+ VAR_W,
+ VAR_H,
+ VAR_CW,
+ VAR_CH,
+ VAR_HSUB,
+ VAR_VSUB,
+ VARS_NB
+};
+
+typedef struct {
+ int radius;
+ int power;
+} FilterParam;
+
+typedef struct {
+ FilterParam luma_param;
+ FilterParam chroma_param;
+ FilterParam alpha_param;
+ char luma_radius_expr [256];
+ char chroma_radius_expr[256];
+ char alpha_radius_expr [256];
+
+ int hsub, vsub;
+ int radius[4];
+ int power[4];
+ uint8_t *temp[2]; ///< temporary buffer used in blur_power()
+} BoxBlurContext;
+
+#define Y 0
+#define U 1
+#define V 2
+#define A 3
+
+static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
+{
+ BoxBlurContext *boxblur = ctx->priv;
+ int e;
+
+ if (!args) {
+ av_log(ctx, AV_LOG_ERROR,
+ "Filter expects 2 or 4 or 6 arguments, none provided\n");
+ return AVERROR(EINVAL);
+ }
+
+ e = sscanf(args, "%255[^:]:%d:%255[^:]:%d:%255[^:]:%d",
+ boxblur->luma_radius_expr, &boxblur->luma_param .power,
+ boxblur->chroma_radius_expr, &boxblur->chroma_param.power,
+ boxblur->alpha_radius_expr, &boxblur->alpha_param .power);
+
+ if (e != 2 && e != 4 && e != 6) {
+ av_log(ctx, AV_LOG_ERROR,
+ "Filter expects 2 or 4 or 6 params, provided %d\n", e);
+ return AVERROR(EINVAL);
+ }
+
+ if (e < 4) {
+ boxblur->chroma_param.power = boxblur->luma_param.power;
+ av_strlcpy(boxblur->chroma_radius_expr, boxblur->luma_radius_expr,
+ sizeof(boxblur->chroma_radius_expr));
+ }
+ if (e < 6) {
+ boxblur->alpha_param.power = boxblur->luma_param.power;
+ av_strlcpy(boxblur->alpha_radius_expr, boxblur->luma_radius_expr,
+ sizeof(boxblur->alpha_radius_expr));
+ }
+
+ return 0;
+}
+
+static av_cold void uninit(AVFilterContext *ctx)
+{
+ BoxBlurContext *boxblur = ctx->priv;
+
+ av_freep(&boxblur->temp[0]);
+ av_freep(&boxblur->temp[1]);
+}
+
+static int query_formats(AVFilterContext *ctx)
+{
+ enum PixelFormat pix_fmts[] = {
+ PIX_FMT_YUV444P, PIX_FMT_YUV422P, PIX_FMT_YUV420P,
+ PIX_FMT_YUV411P, PIX_FMT_YUV410P, PIX_FMT_YUVA420P,
+ PIX_FMT_YUV440P, PIX_FMT_GRAY8,
+ PIX_FMT_YUVJ444P, PIX_FMT_YUVJ422P, PIX_FMT_YUVJ420P,
+ PIX_FMT_YUVJ440P,
+ PIX_FMT_NONE
+ };
+
+ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts));
+ return 0;
+}
+
+static int config_input(AVFilterLink *inlink)
+{
+ AVFilterContext *ctx = inlink->dst;
+ BoxBlurContext *boxblur = ctx->priv;
+ const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[inlink->format];
+ int w = inlink->w, h = inlink->h;
+ int cw, ch;
+ double var_values[VARS_NB], res;
+ char *expr;
+ int ret;
+
+ if (!(boxblur->temp[0] = av_malloc(FFMAX(w, h))) ||
+ !(boxblur->temp[1] = av_malloc(FFMAX(w, h))))
+ return AVERROR(ENOMEM);
+
+ boxblur->hsub = desc->log2_chroma_w;
+ boxblur->vsub = desc->log2_chroma_h;
+
+ var_values[VAR_W] = inlink->w;
+ var_values[VAR_H] = inlink->h;
+ var_values[VAR_CW] = cw = w>>boxblur->hsub;
+ var_values[VAR_CH] = ch = h>>boxblur->vsub;
+ var_values[VAR_HSUB] = 1<<boxblur->hsub;
+ var_values[VAR_VSUB] = 1<<boxblur->vsub;
+
+#define EVAL_RADIUS_EXPR(comp) \
+ expr = boxblur->comp##_radius_expr; \
+ ret = av_expr_parse_and_eval(&res, expr, var_names, var_values, \
+ NULL, NULL, NULL, NULL, NULL, 0, ctx); \
+ boxblur->comp##_param.radius = res; \
+ if (ret < 0) { \
+ av_log(NULL, AV_LOG_ERROR, \
+ "Error when evaluating " #comp " radius expression '%s'\n", expr); \
+ return ret; \
+ }
+ EVAL_RADIUS_EXPR(luma);
+ EVAL_RADIUS_EXPR(chroma);
+ EVAL_RADIUS_EXPR(alpha);
+
+ av_log(ctx, AV_LOG_INFO,
+ "luma_radius:%d luma_power:%d "
+ "chroma_radius:%d chroma_power:%d "
+ "alpha_radius:%d alpha_power:%d "
+ "w:%d chroma_w:%d h:%d chroma_h:%d\n",
+ boxblur->luma_param .radius, boxblur->luma_param .power,
+ boxblur->chroma_param.radius, boxblur->chroma_param.power,
+ boxblur->alpha_param .radius, boxblur->alpha_param .power,
+ w, cw, h, ch);
+
+#define CHECK_RADIUS_VAL(w_, h_, comp) \
+ if (boxblur->comp##_param.radius < 0 || \
+ 2*boxblur->comp##_param.radius > FFMIN(w_, h_)) { \
+ av_log(ctx, AV_LOG_ERROR, \
+ "Invalid " #comp " radius value %d, must be >= 0 and <= %d\n", \
+ boxblur->comp##_param.radius, FFMIN(w_, h_)/2); \
+ return AVERROR(EINVAL); \
+ }
+ CHECK_RADIUS_VAL(w, h, luma);
+ CHECK_RADIUS_VAL(cw, ch, chroma);
+ CHECK_RADIUS_VAL(w, h, alpha);
+
+ boxblur->radius[Y] = boxblur->luma_param.radius;
+ boxblur->radius[U] = boxblur->radius[V] = boxblur->chroma_param.radius;
+ boxblur->radius[A] = boxblur->alpha_param.radius;
+
+ boxblur->power[Y] = boxblur->luma_param.power;
+ boxblur->power[U] = boxblur->power[V] = boxblur->chroma_param.power;
+ boxblur->power[A] = boxblur->alpha_param.power;
+
+ return 0;
+}
+
+static inline void blur(uint8_t *dst, int dst_step, const uint8_t *src, int src_step,
+ int len, int radius)
+{
+ /* Naive boxblur would sum source pixels from x-radius .. x+radius
+ * for destination pixel x. That would be O(radius*width).
+ * If you now look at what source pixels represent 2 consecutive
+ * output pixels, then you see they are almost identical and only
+ * differ by 2 pixels, like:
+ * src0 111111111
+ * dst0 1
+ * src1 111111111
+ * dst1 1
+ * src0-src1 1 -1
+ * so when you know one output pixel you can find the next by just adding
+ * and subtracting 1 input pixel.
+ * The following code adopts this faster variant.
+ */
+ int x, sum = 0;
+ const int length = radius*2 + 1;
+ const int inv = ((1<<16) + length/2)/length;
+
+ for (x = 0; x < radius; x++)
+ sum += src[x*src_step]<<1;
+ sum += src[radius*src_step];
+
+ for (x = 0; x <= radius; x++) {
+ sum += src[(radius+x)*src_step] - src[(radius-x)*src_step];
+ dst[x*dst_step] = (sum*inv + (1<<15))>>16;
+ }
+
+ for (; x < len-radius; x++) {
+ sum += src[(radius+x)*src_step] - src[(x-radius-1)*src_step];
+ dst[x*dst_step] = (sum*inv + (1<<15))>>16;
+ }
+
+ for (; x < len; x++) {
+ sum += src[(2*len-radius-x-1)*src_step] - src[(x-radius-1)*src_step];
+ dst[x*dst_step] = (sum*inv + (1<<15))>>16;
+ }
+}
+
+static inline void blur_power(uint8_t *dst, int dst_step, const uint8_t *src, int src_step,
+ int len, int radius, int power, uint8_t *temp[2])
+{
+ uint8_t *a = temp[0], *b = temp[1];
+
+ if (radius && power) {
+ blur(a, 1, src, src_step, len, radius);
+ for (; power > 2; power--) {
+ uint8_t *c;
+ blur(b, 1, a, 1, len, radius);
+ c = a; a = b; b = c;
+ }
+ if (power > 1) {
+ blur(dst, dst_step, a, 1, len, radius);
+ } else {
+ int i;
+ for (i = 0; i < len; i++)
+ dst[i*dst_step] = a[i];
+ }
+ } else {
+ int i;
+ for (i = 0; i < len; i++)
+ dst[i*dst_step] = src[i*src_step];
+ }
+}
+
+static void hblur(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize,
+ int w, int h, int radius, int power, uint8_t *temp[2])
+{
+ int y;
+
+ if (radius == 0 && dst == src)
+ return;
+
+ for (y = 0; y < h; y++)
+ blur_power(dst + y*dst_linesize, 1, src + y*src_linesize, 1,
+ w, radius, power, temp);
+}
+
+static void vblur(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize,
+ int w, int h, int radius, int power, uint8_t *temp[2])
+{
+ int x;
+
+ if (radius == 0 && dst == src)
+ return;
+
+ for (x = 0; x < w; x++)
+ blur_power(dst + x, dst_linesize, src + x, src_linesize,
+ h, radius, power, temp);
+}
+
+static void draw_slice(AVFilterLink *inlink, int y0, int h0, int slice_dir)
+{
+ AVFilterContext *ctx = inlink->dst;
+ BoxBlurContext *boxblur = ctx->priv;
+ AVFilterLink *outlink = inlink->dst->outputs[0];
+ AVFilterBufferRef *inpicref = inlink ->cur_buf;
+ AVFilterBufferRef *outpicref = outlink->out_buf;
+ int plane;
+ int cw = inlink->w >> boxblur->hsub, ch = h0 >> boxblur->vsub;
+ int w[4] = { inlink->w, cw, cw, inlink->w };
+ int h[4] = { h0, ch, ch, h0 };
+
+ for (plane = 0; inpicref->data[plane] && plane < 4; plane++)
+ hblur(outpicref->data[plane], outpicref->linesize[plane],
+ inpicref ->data[plane], inpicref ->linesize[plane],
+ w[plane], h[plane], boxblur->radius[plane], boxblur->power[plane],
+ boxblur->temp);
+
+ for (plane = 0; inpicref->data[plane] && plane < 4; plane++)
+ vblur(outpicref->data[plane], outpicref->linesize[plane],
+ outpicref->data[plane], outpicref->linesize[plane],
+ w[plane], h[plane], boxblur->radius[plane], boxblur->power[plane],
+ boxblur->temp);
+
+ avfilter_draw_slice(outlink, y0, h0, slice_dir);
+}
+
+AVFilter avfilter_vf_boxblur = {
+ .name = "boxblur",
+ .description = NULL_IF_CONFIG_SMALL("Blur the input."),
+ .priv_size = sizeof(BoxBlurContext),
+ .init = init,
+ .uninit = uninit,
+ .query_formats = query_formats,
+
+ .inputs = (AVFilterPad[]) {{ .name = "default",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .config_props = config_input,
+ .draw_slice = draw_slice,
+ .min_perms = AV_PERM_READ },
+ { .name = NULL}},
+ .outputs = (AVFilterPad[]) {{ .name = "default",
+ .type = AVMEDIA_TYPE_VIDEO, },
+ { .name = NULL}},
+}; \ No newline at end of file
diff --git a/libavfilter/vf_copy.c b/libavfilter/vf_copy.c
index 705ad1e2e6..480ebcc034 100644
--- a/libavfilter/vf_copy.c
+++ b/libavfilter/vf_copy.c
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavfilter/vf_crop.c b/libavfilter/vf_crop.c
index 0880d4e5f9..9215b1e700 100644
--- a/libavfilter/vf_crop.c
+++ b/libavfilter/vf_crop.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2007 Bobby Bingham
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -33,13 +33,15 @@
#include "libavutil/mathematics.h"
static const char *var_names[] = {
- "E",
- "PHI",
- "PI",
"in_w", "iw", ///< width of the input video
"in_h", "ih", ///< height of the input video
"out_w", "ow", ///< width of the cropped video
"out_h", "oh", ///< height of the cropped video
+ "a",
+ "sar",
+ "dar",
+ "hsub",
+ "vsub",
"x",
"y",
"n", ///< number of frame
@@ -49,13 +51,15 @@ static const char *var_names[] = {
};
enum var_name {
- VAR_E,
- VAR_PHI,
- VAR_PI,
VAR_IN_W, VAR_IW,
VAR_IN_H, VAR_IH,
VAR_OUT_W, VAR_OW,
VAR_OUT_H, VAR_OH,
+ VAR_A,
+ VAR_SAR,
+ VAR_DAR,
+ VAR_HSUB,
+ VAR_VSUB,
VAR_X,
VAR_Y,
VAR_N,
@@ -105,7 +109,7 @@ static int query_formats(AVFilterContext *ctx)
PIX_FMT_NONE
};
- avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts));
+ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts));
return 0;
}
@@ -157,11 +161,13 @@ static int config_input(AVFilterLink *link)
const char *expr;
double res;
- crop->var_values[VAR_E] = M_E;
- crop->var_values[VAR_PHI] = M_PHI;
- crop->var_values[VAR_PI] = M_PI;
crop->var_values[VAR_IN_W] = crop->var_values[VAR_IW] = ctx->inputs[0]->w;
crop->var_values[VAR_IN_H] = crop->var_values[VAR_IH] = ctx->inputs[0]->h;
+ crop->var_values[VAR_A] = (float) link->w / link->h;
+ crop->var_values[VAR_SAR] = link->sample_aspect_ratio.num ? av_q2d(link->sample_aspect_ratio) : 1;
+ crop->var_values[VAR_DAR] = crop->var_values[VAR_A] * crop->var_values[VAR_SAR];
+ crop->var_values[VAR_HSUB] = 1<<pix_desc->log2_chroma_w;
+ crop->var_values[VAR_VSUB] = 1<<pix_desc->log2_chroma_h;
crop->var_values[VAR_X] = NAN;
crop->var_values[VAR_Y] = NAN;
crop->var_values[VAR_OUT_W] = crop->var_values[VAR_OW] = NAN;
diff --git a/libavfilter/vf_cropdetect.c b/libavfilter/vf_cropdetect.c
index 34b5dc9a2a..a997cbede8 100644
--- a/libavfilter/vf_cropdetect.c
+++ b/libavfilter/vf_cropdetect.c
@@ -1,19 +1,19 @@
/*
* Copyright (c) 2002 A'rpi
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or modify
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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 Libav; if not, write to the Free Software Foundation, Inc.,
+ * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
@@ -46,7 +46,7 @@ static int query_formats(AVFilterContext *ctx)
PIX_FMT_NONE
};
- avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts));
+ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts));
return 0;
}
diff --git a/libavfilter/vf_delogo.c b/libavfilter/vf_delogo.c
new file mode 100644
index 0000000000..bf6139ebdb
--- /dev/null
+++ b/libavfilter/vf_delogo.c
@@ -0,0 +1,288 @@
+/*
+ * Copyright (c) 2002 Jindrich Makovicka <makovick@gmail.com>
+ * Copyright (c) 2011 Stefano Sabatini
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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 FFmpeg; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+/**
+ * @file
+ * A very simple tv station logo remover
+ * Ported from MPlayer libmpcodecs/vf_delogo.c.
+ */
+
+#include "libavutil/imgutils.h"
+#include "libavutil/opt.h"
+#include "libavutil/pixdesc.h"
+#include "avfilter.h"
+
+/**
+ * Apply a simple delogo algorithm to the image in dst and put the
+ * result in src.
+ *
+ * The algorithm is only applied to the region specified by the logo
+ * parameters.
+ *
+ * @param w width of the input image
+ * @param h height of the input image
+ * @param logo_x x coordinate of the top left corner of the logo region
+ * @param logo_y y coordinate of the top left corner of the logo region
+ * @param logo_w width of the logo
+ * @param logo_h height of the logo
+ * @param band the size of the band around the processed area
+ * @param show show a rectangle around the processed area, useful for
+ * parameters tweaking
+ * @param direct if non-zero perform in-place processing
+ */
+static void apply_delogo(uint8_t *dst, int dst_linesize,
+ uint8_t *src, int src_linesize,
+ int w, int h,
+ int logo_x, int logo_y, int logo_w, int logo_h,
+ int band, int show, int direct)
+{
+ int x, y;
+ int interp, dist;
+ uint8_t *xdst, *xsrc;
+
+ uint8_t *topleft, *botleft, *topright;
+ int xclipl, xclipr, yclipt, yclipb;
+ int logo_x1, logo_x2, logo_y1, logo_y2;
+
+ xclipl = FFMAX(-logo_x, 0);
+ xclipr = FFMAX(logo_x+logo_w-w, 0);
+ yclipt = FFMAX(-logo_y, 0);
+ yclipb = FFMAX(logo_y+logo_h-h, 0);
+
+ logo_x1 = logo_x + xclipl;
+ logo_x2 = logo_x + logo_w - xclipr;
+ logo_y1 = logo_y + yclipt;
+ logo_y2 = logo_y + logo_h - yclipb;
+
+ topleft = src+logo_y1 * src_linesize+logo_x1;
+ topright = src+logo_y1 * src_linesize+logo_x2-1;
+ botleft = src+(logo_y2-1) * src_linesize+logo_x1;
+
+ dst += (logo_y1+1)*dst_linesize;
+ src += (logo_y1+1)*src_linesize;
+
+ if (!direct)
+ av_image_copy_plane(dst, dst_linesize, src, src_linesize, w, h);
+
+ for (y = logo_y1+1; y < logo_y2-1; y++) {
+ for (x = logo_x1+1,
+ xdst = dst+logo_x1+1,
+ xsrc = src+logo_x1+1; x < logo_x2-1; x++, xdst++, xsrc++) {
+ interp =
+ (topleft[src_linesize*(y-logo_y -yclipt)] +
+ topleft[src_linesize*(y-logo_y-1-yclipt)] +
+ topleft[src_linesize*(y-logo_y+1-yclipt)]) * (logo_w-(x-logo_x))/logo_w
+ +
+ (topright[src_linesize*(y-logo_y-yclipt)] +
+ topright[src_linesize*(y-logo_y-1-yclipt)] +
+ topright[src_linesize*(y-logo_y+1-yclipt)]) * (x-logo_x)/logo_w
+ +
+ (topleft[x-logo_x-xclipl] +
+ topleft[x-logo_x-1-xclipl] +
+ topleft[x-logo_x+1-xclipl]) * (logo_h-(y-logo_y))/logo_h
+ +
+ (botleft[x-logo_x-xclipl] +
+ botleft[x-logo_x-1-xclipl] +
+ botleft[x-logo_x+1-xclipl]) * (y-logo_y)/logo_h;
+ interp /= 6;
+
+ if (y >= logo_y+band && y < logo_y+logo_h-band &&
+ x >= logo_x+band && x < logo_x+logo_w-band) {
+ *xdst = interp;
+ } else {
+ dist = 0;
+ if (x < logo_x+band)
+ dist = FFMAX(dist, logo_x-x+band);
+ else if (x >= logo_x+logo_w-band)
+ dist = FFMAX(dist, x-(logo_x+logo_w-1-band));
+
+ if (y < logo_y+band)
+ dist = FFMAX(dist, logo_y-y+band);
+ else if (y >= logo_y+logo_h-band)
+ dist = FFMAX(dist, y-(logo_y+logo_h-1-band));
+
+ *xdst = (*xsrc*dist + interp*(band-dist))/band;
+ if (show && (dist == band-1))
+ *xdst = 0;
+ }
+ }
+
+ dst += dst_linesize;
+ src += src_linesize;
+ }
+}
+
+typedef struct {
+ const AVClass *class;
+ int x, y, w, h, band, show;
+} DelogoContext;
+
+#define OFFSET(x) offsetof(DelogoContext, x)
+
+static const AVOption delogo_options[]= {
+ {"x", "set logo x position", OFFSET(x), AV_OPT_TYPE_INT, {.dbl=-1}, -1, INT_MAX },
+ {"y", "set logo y position", OFFSET(y), AV_OPT_TYPE_INT, {.dbl=-1}, -1, INT_MAX },
+ {"w", "set logo width", OFFSET(w), AV_OPT_TYPE_INT, {.dbl=-1}, -1, INT_MAX },
+ {"h", "set logo height", OFFSET(h), AV_OPT_TYPE_INT, {.dbl=-1}, -1, INT_MAX },
+ {"band", "set delogo area band size", OFFSET(band), AV_OPT_TYPE_INT, {.dbl= 4}, -1, INT_MAX },
+ {"t", "set delogo area band size", OFFSET(band), AV_OPT_TYPE_INT, {.dbl= 4}, -1, INT_MAX },
+ {"show", "show delogo area", OFFSET(show), AV_OPT_TYPE_INT, {.dbl= 0}, 0, 1 },
+ {NULL},
+};
+
+static const char *delogo_get_name(void *ctx)
+{
+ return "delogo";
+}
+
+static const AVClass delogo_class = {
+ .class_name = "DelogoContext",
+ .item_name = delogo_get_name,
+ .option = delogo_options,
+};
+
+static int query_formats(AVFilterContext *ctx)
+{
+ enum PixelFormat pix_fmts[] = {
+ PIX_FMT_YUV444P, PIX_FMT_YUV422P, PIX_FMT_YUV420P,
+ PIX_FMT_YUV411P, PIX_FMT_YUV410P, PIX_FMT_YUV440P,
+ PIX_FMT_YUVA420P, PIX_FMT_GRAY8,
+ PIX_FMT_NONE
+ };
+
+ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts));
+ return 0;
+}
+
+static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
+{
+ DelogoContext *delogo = ctx->priv;
+ int ret = 0;
+
+ delogo->class = &delogo_class;
+ av_opt_set_defaults(delogo);
+
+ if (args)
+ ret = sscanf(args, "%d:%d:%d:%d:%d",
+ &delogo->x, &delogo->y, &delogo->w, &delogo->h, &delogo->band);
+ if (ret == 5) {
+ if (delogo->band < 0)
+ delogo->show = 1;
+ } else if ((ret = (av_set_options_string(delogo, args, "=", ":"))) < 0) {
+ av_log(ctx, AV_LOG_ERROR, "Error parsing options string: '%s'\n", args);
+ return ret;
+ }
+
+#define CHECK_UNSET_OPT(opt) \
+ if (delogo->opt == -1) { \
+ av_log(delogo, AV_LOG_ERROR, "Option %s was not set.\n", #opt); \
+ return AVERROR(EINVAL); \
+ }
+ CHECK_UNSET_OPT(x);
+ CHECK_UNSET_OPT(y);
+ CHECK_UNSET_OPT(w);
+ CHECK_UNSET_OPT(h);
+
+ if (delogo->show)
+ delogo->band = 4;
+
+ av_log(ctx, AV_LOG_INFO, "x:%d y:%d, w:%d h:%d band:%d show:%d\n",
+ delogo->x, delogo->y, delogo->w, delogo->h, delogo->band, delogo->show);
+
+ delogo->w += delogo->band*2;
+ delogo->h += delogo->band*2;
+ delogo->x -= delogo->band;
+ delogo->y -= delogo->band;
+
+ return 0;
+}
+
+static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
+{
+ AVFilterLink *outlink = inlink->dst->outputs[0];
+ AVFilterBufferRef *outpicref;
+
+ if (inpicref->perms & AV_PERM_PRESERVE) {
+ outpicref = avfilter_get_video_buffer(outlink, AV_PERM_WRITE,
+ outlink->w, outlink->h);
+ avfilter_copy_buffer_ref_props(outpicref, inpicref);
+ outpicref->video->w = outlink->w;
+ outpicref->video->h = outlink->h;
+ } else
+ outpicref = inpicref;
+
+ outlink->out_buf = outpicref;
+ avfilter_start_frame(outlink, avfilter_ref_buffer(outpicref, ~0));
+}
+
+static void null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) { }
+
+static void end_frame(AVFilterLink *inlink)
+{
+ DelogoContext *delogo = inlink->dst->priv;
+ AVFilterLink *outlink = inlink->dst->outputs[0];
+ AVFilterBufferRef *inpicref = inlink ->cur_buf;
+ AVFilterBufferRef *outpicref = outlink->out_buf;
+ int direct = inpicref == outpicref;
+ int hsub0 = av_pix_fmt_descriptors[inlink->format].log2_chroma_w;
+ int vsub0 = av_pix_fmt_descriptors[inlink->format].log2_chroma_h;
+ int plane;
+
+ for (plane = 0; plane < 4 && inpicref->data[plane]; plane++) {
+ int hsub = plane == 1 || plane == 2 ? hsub0 : 0;
+ int vsub = plane == 1 || plane == 2 ? vsub0 : 0;
+
+ apply_delogo(outpicref->data[plane], outpicref->linesize[plane],
+ inpicref ->data[plane], inpicref ->linesize[plane],
+ inlink->w>>hsub, inlink->h>>vsub,
+ delogo->x>>hsub, delogo->y>>vsub,
+ delogo->w>>hsub, delogo->h>>vsub,
+ delogo->band>>FFMIN(hsub, vsub),
+ delogo->show, direct);
+ }
+
+ avfilter_draw_slice(outlink, 0, inlink->h, 1);
+ avfilter_end_frame(outlink);
+ avfilter_unref_buffer(inpicref);
+ if (!direct)
+ avfilter_unref_buffer(outpicref);
+}
+
+AVFilter avfilter_vf_delogo = {
+ .name = "delogo",
+ .description = NULL_IF_CONFIG_SMALL("Remove logo from input video."),
+ .priv_size = sizeof(DelogoContext),
+ .init = init,
+ .query_formats = query_formats,
+
+ .inputs = (AVFilterPad[]) {{ .name = "default",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .get_video_buffer = avfilter_null_get_video_buffer,
+ .start_frame = start_frame,
+ .draw_slice = null_draw_slice,
+ .end_frame = end_frame,
+ .min_perms = AV_PERM_WRITE | AV_PERM_READ,
+ .rej_perms = AV_PERM_PRESERVE },
+ { .name = NULL}},
+ .outputs = (AVFilterPad[]) {{ .name = "default",
+ .type = AVMEDIA_TYPE_VIDEO, },
+ { .name = NULL}},
+}; \ No newline at end of file
diff --git a/libavfilter/vf_deshake.c b/libavfilter/vf_deshake.c
new file mode 100644
index 0000000000..e3f22109de
--- /dev/null
+++ b/libavfilter/vf_deshake.c
@@ -0,0 +1,560 @@
+/*
+ * Copyright (C) 2010 Georg Martius <georg.martius@web.de>
+ * Copyright (C) 2010 Daniel G. Taylor <dan@programmer-art.org>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * fast deshake / depan video filter
+ *
+ * SAD block-matching motion compensation to fix small changes in
+ * horizontal and/or vertical shift. This filter helps remove camera shake
+ * from hand-holding a camera, bumping a tripod, moving on a vehicle, etc.
+ *
+ * Algorithm:
+ * - For each frame with one previous reference frame
+ * - For each block in the frame
+ * - If contrast > threshold then find likely motion vector
+ * - For all found motion vectors
+ * - Find most common, store as global motion vector
+ * - Find most likely rotation angle
+ * - Transform image along global motion
+ *
+ * TODO:
+ * - Fill frame edges based on previous/next reference frames
+ * - Fill frame edges by stretching image near the edges?
+ * - Can this be done quickly and look decent?
+ *
+ * Dark Shikari links to http://wiki.videolan.org/SoC_x264_2010#GPU_Motion_Estimation_2
+ * for an algorithm similar to what could be used here to get the gmv
+ * It requires only a couple diamond searches + fast downscaling
+ *
+ * Special thanks to Jason Kotenko for his help with the algorithm and my
+ * inability to see simple errors in C code.
+ */
+
+#include "avfilter.h"
+#include "libavutil/common.h"
+#include "libavutil/mem.h"
+#include "libavutil/pixdesc.h"
+#include "libavcodec/dsputil.h"
+
+#include "transform.h"
+
+#define CHROMA_WIDTH(link) -((-link->w) >> av_pix_fmt_descriptors[link->format].log2_chroma_w)
+#define CHROMA_HEIGHT(link) -((-link->h) >> av_pix_fmt_descriptors[link->format].log2_chroma_h)
+
+enum SearchMethod {
+ EXHAUSTIVE, ///< Search all possible positions
+ SMART_EXHAUSTIVE, ///< Search most possible positions (faster)
+ SEARCH_COUNT
+};
+
+typedef struct {
+ double x; ///< Horizontal shift
+ double y; ///< Vertical shift
+} MotionVector;
+
+typedef struct {
+ MotionVector vector; ///< Motion vector
+ double angle; ///< Angle of rotation
+ double zoom; ///< Zoom percentage
+} Transform;
+
+typedef struct {
+ AVClass av_class;
+ AVFilterBufferRef *ref; ///< Previous frame
+ int rx; ///< Maximum horizontal shift
+ int ry; ///< Maximum vertical shift
+ enum FillMethod edge; ///< Edge fill method
+ int blocksize; ///< Size of blocks to compare
+ int contrast; ///< Contrast threshold
+ enum SearchMethod search; ///< Motion search method
+ AVCodecContext *avctx;
+ DSPContext c; ///< Context providing optimized SAD methods
+ Transform last; ///< Transform from last frame
+ int refcount; ///< Number of reference frames (defines averaging window)
+ FILE *fp;
+ Transform avg;
+ int cw; ///< Crop motion search to this box
+ int ch;
+ int cx;
+ int cy;
+} DeshakeContext;
+
+static int cmp(const double *a, const double *b)
+{
+ return *a < *b ? -1 : ( *a > *b ? 1 : 0 );
+}
+
+/**
+ * Cleaned mean (cuts off 20% of values to remove outliers and then averages)
+ */
+static double clean_mean(double *values, int count)
+{
+ double mean = 0;
+ int cut = count / 5;
+ int x;
+
+ qsort(values, count, sizeof(double), (void*)cmp);
+
+ for (x = cut; x < count - cut; x++) {
+ mean += values[x];
+ }
+
+ return mean / (count - cut * 2);
+}
+
+/**
+ * Find the most likely shift in motion between two frames for a given
+ * macroblock. Test each block against several shifts given by the rx
+ * and ry attributes. Searches using a simple matrix of those shifts and
+ * chooses the most likely shift by the smallest difference in blocks.
+ */
+static void find_block_motion(DeshakeContext *deshake, uint8_t *src1,
+ uint8_t *src2, int cx, int cy, int stride,
+ MotionVector *mv)
+{
+ int x, y;
+ int diff;
+ int smallest = INT_MAX;
+ int tmp, tmp2;
+
+ #define CMP(i, j) deshake->c.sad[0](deshake, src1 + cy * stride + cx, \
+ src2 + (j) * stride + (i), stride, \
+ deshake->blocksize)
+
+ if (deshake->search == EXHAUSTIVE) {
+ // Compare every possible position - this is sloooow!
+ for (y = -deshake->ry; y <= deshake->ry; y++) {
+ for (x = -deshake->rx; x <= deshake->rx; x++) {
+ diff = CMP(cx - x, cy - y);
+ if (diff < smallest) {
+ smallest = diff;
+ mv->x = x;
+ mv->y = y;
+ }
+ }
+ }
+ } else if (deshake->search == SMART_EXHAUSTIVE) {
+ // Compare every other possible position and find the best match
+ for (y = -deshake->ry + 1; y < deshake->ry - 2; y += 2) {
+ for (x = -deshake->rx + 1; x < deshake->rx - 2; x += 2) {
+ diff = CMP(cx - x, cy - y);
+ if (diff < smallest) {
+ smallest = diff;
+ mv->x = x;
+ mv->y = y;
+ }
+ }
+ }
+
+ // Hone in on the specific best match around the match we found above
+ tmp = mv->x;
+ tmp2 = mv->y;
+
+ for (y = tmp2 - 1; y <= tmp2 + 1; y++) {
+ for (x = tmp - 1; x <= tmp + 1; x++) {
+ if (x == tmp && y == tmp2)
+ continue;
+
+ diff = CMP(cx - x, cy - y);
+ if (diff < smallest) {
+ smallest = diff;
+ mv->x = x;
+ mv->y = y;
+ }
+ }
+ }
+ }
+
+ if (smallest > 512) {
+ mv->x = -1;
+ mv->y = -1;
+ }
+ emms_c();
+ //av_log(NULL, AV_LOG_ERROR, "%d\n", smallest);
+ //av_log(NULL, AV_LOG_ERROR, "Final: (%d, %d) = %d x %d\n", cx, cy, mv->x, mv->y);
+}
+
+/**
+ * Find the contrast of a given block. When searching for global motion we
+ * really only care about the high contrast blocks, so using this method we
+ * can actually skip blocks we don't care much about.
+ */
+static int block_contrast(uint8_t *src, int x, int y, int stride, int blocksize)
+{
+ int highest = 0;
+ int lowest = 0;
+ int i, j, pos;
+
+ for (i = 0; i <= blocksize * 2; i++) {
+ // We use a width of 16 here to match the libavcodec sad functions
+ for (j = 0; i <= 15; i++) {
+ pos = (y - i) * stride + (x - j);
+ if (src[pos] < lowest)
+ lowest = src[pos];
+ else if (src[pos] > highest) {
+ highest = src[pos];
+ }
+ }
+ }
+
+ return highest - lowest;
+}
+
+/**
+ * Find the rotation for a given block.
+ */
+static double block_angle(int x, int y, int cx, int cy, MotionVector *shift)
+{
+ double a1, a2, diff;
+
+ a1 = atan2(y - cy, x - cx);
+ a2 = atan2(y - cy + shift->y, x - cx + shift->x);
+
+ diff = a2 - a1;
+
+ return (diff > M_PI) ? diff - 2 * M_PI :
+ (diff < -M_PI) ? diff + 2 * M_PI :
+ diff;
+}
+
+/**
+ * Find the estimated global motion for a scene given the most likely shift
+ * for each block in the frame. The global motion is estimated to be the
+ * same as the motion from most blocks in the frame, so if most blocks
+ * move one pixel to the right and two pixels down, this would yield a
+ * motion vector (1, -2).
+ */
+static void find_motion(DeshakeContext *deshake, uint8_t *src1, uint8_t *src2,
+ int width, int height, int stride, Transform *t)
+{
+ int x, y;
+ MotionVector mv = {0, 0};
+ int counts[128][128];
+ int count_max_value = 0;
+ int contrast;
+
+ int pos;
+ double *angles = av_malloc(sizeof(*angles) * width * height / (16 * deshake->blocksize));
+ double totalangles = 0;
+
+ int center_x = 0, center_y = 0;
+ double p_x, p_y;
+
+ // Reset counts to zero
+ for (x = 0; x < deshake->rx * 2 + 1; x++) {
+ for (y = 0; y < deshake->ry * 2 + 1; y++) {
+ counts[x][y] = 0;
+ }
+ }
+
+ pos = 0;
+ // Find motion for every block and store the motion vector in the counts
+ for (y = deshake->ry; y < height - deshake->ry - (deshake->blocksize * 2); y += deshake->blocksize * 2) {
+ // We use a width of 16 here to match the libavcodec sad functions
+ for (x = deshake->rx; x < width - deshake->rx - 16; x += 16) {
+ // If the contrast is too low, just skip this block as it probably
+ // won't be very useful to us.
+ contrast = block_contrast(src2, x, y, stride, deshake->blocksize);
+ if (contrast > deshake->contrast) {
+ //av_log(NULL, AV_LOG_ERROR, "%d\n", contrast);
+ find_block_motion(deshake, src1, src2, x, y, stride, &mv);
+ if (mv.x != -1 && mv.y != -1) {
+ counts[(int)(mv.x + deshake->rx)][(int)(mv.y + deshake->ry)] += 1;
+ if (x > deshake->rx && y > deshake->ry)
+ angles[pos++] = block_angle(x, y, 0, 0, &mv);
+
+ center_x += mv.x;
+ center_y += mv.y;
+ }
+ }
+ }
+ }
+
+ pos = FFMAX(1, pos);
+
+ center_x /= pos;
+ center_y /= pos;
+
+ for (x = 0; x < pos; x++) {
+ totalangles += angles[x];
+ }
+
+ //av_log(NULL, AV_LOG_ERROR, "Angle: %lf\n", totalangles / (pos - 1));
+ t->angle = totalangles / (pos - 1);
+
+ t->angle = clean_mean(angles, pos);
+ if (t->angle < 0.001)
+ t->angle = 0;
+
+ // Find the most common motion vector in the frame and use it as the gmv
+ for (y = deshake->ry * 2; y >= 0; y--) {
+ for (x = 0; x < deshake->rx * 2 + 1; x++) {
+ //av_log(NULL, AV_LOG_ERROR, "%5d ", counts[x][y]);
+ if (counts[x][y] > count_max_value) {
+ t->vector.x = x - deshake->rx;
+ t->vector.y = y - deshake->ry;
+ count_max_value = counts[x][y];
+ }
+ }
+ //av_log(NULL, AV_LOG_ERROR, "\n");
+ }
+
+ p_x = (center_x - width / 2);
+ p_y = (center_y - height / 2);
+ t->vector.x += (cos(t->angle)-1)*p_x - sin(t->angle)*p_y;
+ t->vector.y += sin(t->angle)*p_x + (cos(t->angle)-1)*p_y;
+
+ // Clamp max shift & rotation?
+ t->vector.x = av_clipf(t->vector.x, -deshake->rx * 2, deshake->rx * 2);
+ t->vector.y = av_clipf(t->vector.y, -deshake->ry * 2, deshake->ry * 2);
+ t->angle = av_clipf(t->angle, -0.1, 0.1);
+
+ //av_log(NULL, AV_LOG_ERROR, "%d x %d\n", avg->x, avg->y);
+ av_free(angles);
+}
+
+static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
+{
+ DeshakeContext *deshake = ctx->priv;
+ char filename[256] = {0};
+
+ deshake->rx = 16;
+ deshake->ry = 16;
+ deshake->edge = FILL_MIRROR;
+ deshake->blocksize = 8;
+ deshake->contrast = 125;
+ deshake->search = EXHAUSTIVE;
+ deshake->refcount = 20;
+
+ deshake->cw = -1;
+ deshake->ch = -1;
+ deshake->cx = -1;
+ deshake->cy = -1;
+
+ if (args) {
+ sscanf(args, "%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%255s",
+ &deshake->cx, &deshake->cy, &deshake->cw, &deshake->ch,
+ &deshake->rx, &deshake->ry, (int *)&deshake->edge,
+ &deshake->blocksize, &deshake->contrast, (int *)&deshake->search, filename);
+
+ deshake->blocksize /= 2;
+
+ deshake->rx = av_clip(deshake->rx, 0, 64);
+ deshake->ry = av_clip(deshake->ry, 0, 64);
+ deshake->edge = av_clip(deshake->edge, FILL_BLANK, FILL_COUNT - 1);
+ deshake->blocksize = av_clip(deshake->blocksize, 4, 128);
+ deshake->contrast = av_clip(deshake->contrast, 1, 255);
+ deshake->search = av_clip(deshake->search, EXHAUSTIVE, SEARCH_COUNT - 1);
+
+ }
+ if (*filename)
+ deshake->fp = fopen(filename, "w");
+ if (deshake->fp)
+ fwrite("Ori x, Avg x, Fin x, Ori y, Avg y, Fin y, Ori angle, Avg angle, Fin angle, Ori zoom, Avg zoom, Fin zoom\n", sizeof(char), 104, deshake->fp);
+
+ // Quadword align left edge of box for MMX code, adjust width if necessary
+ // to keep right margin
+ if (deshake->cx > 0) {
+ deshake->cw += deshake->cx - (deshake->cx & ~15);
+ deshake->cx &= ~15;
+ }
+
+ av_log(ctx, AV_LOG_INFO, "cx: %d, cy: %d, cw: %d, ch: %d, rx: %d, ry: %d, edge: %d blocksize: %d contrast: %d search: %d\n",
+ deshake->cx, deshake->cy, deshake->cw, deshake->ch,
+ deshake->rx, deshake->ry, deshake->edge, deshake->blocksize * 2, deshake->contrast, deshake->search);
+
+ return 0;
+}
+
+static int query_formats(AVFilterContext *ctx)
+{
+ enum PixelFormat pix_fmts[] = {
+ PIX_FMT_YUV420P, PIX_FMT_YUV422P, PIX_FMT_YUV444P, PIX_FMT_YUV410P,
+ PIX_FMT_YUV411P, PIX_FMT_YUV440P, PIX_FMT_YUVJ420P, PIX_FMT_YUVJ422P,
+ PIX_FMT_YUVJ444P, PIX_FMT_YUVJ440P, PIX_FMT_NONE
+ };
+
+ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts));
+
+ return 0;
+}
+
+static int config_props(AVFilterLink *link)
+{
+ DeshakeContext *deshake = link->dst->priv;
+
+ deshake->ref = NULL;
+ deshake->last.vector.x = 0;
+ deshake->last.vector.y = 0;
+ deshake->last.angle = 0;
+ deshake->last.zoom = 0;
+
+ deshake->avctx = avcodec_alloc_context3(NULL);
+ dsputil_init(&deshake->c, deshake->avctx);
+
+ return 0;
+}
+
+static av_cold void uninit(AVFilterContext *ctx)
+{
+ DeshakeContext *deshake = ctx->priv;
+
+ avfilter_unref_buffer(deshake->ref);
+ if (deshake->fp)
+ fclose(deshake->fp);
+}
+
+static void end_frame(AVFilterLink *link)
+{
+ DeshakeContext *deshake = link->dst->priv;
+ AVFilterBufferRef *in = link->cur_buf;
+ AVFilterBufferRef *out = link->dst->outputs[0]->out_buf;
+ Transform t;
+ float matrix[9];
+ float alpha = 2.0 / deshake->refcount;
+ char tmp[256];
+ Transform orig;
+
+ if (deshake->cx < 0 || deshake->cy < 0 || deshake->cw < 0 || deshake->ch < 0) {
+ // Find the most likely global motion for the current frame
+ find_motion(deshake, (deshake->ref == NULL) ? in->data[0] : deshake->ref->data[0], in->data[0], link->w, link->h, in->linesize[0], &t);
+ } else {
+ uint8_t *src1 = (deshake->ref == NULL) ? in->data[0] : deshake->ref->data[0];
+ uint8_t *src2 = in->data[0];
+
+ deshake->cx = FFMIN(deshake->cx, link->w);
+ deshake->cy = FFMIN(deshake->cy, link->h);
+
+ if ((unsigned)deshake->cx + (unsigned)deshake->cw > link->w) deshake->cw = link->w - deshake->cx;
+ if ((unsigned)deshake->cy + (unsigned)deshake->ch > link->h) deshake->ch = link->h - deshake->cy;
+
+ // Quadword align right margin
+ deshake->cw &= ~15;
+
+ src1 += deshake->cy * in->linesize[0] + deshake->cx;
+ src2 += deshake->cy * in->linesize[0] + deshake->cx;
+
+ find_motion(deshake, src1, src2, deshake->cw, deshake->ch, in->linesize[0], &t);
+ }
+
+
+ // Copy transform so we can output it later to compare to the smoothed value
+ orig.vector.x = t.vector.x;
+ orig.vector.y = t.vector.y;
+ orig.angle = t.angle;
+ orig.zoom = t.zoom;
+
+ // Generate a one-sided moving exponential average
+ deshake->avg.vector.x = alpha * t.vector.x + (1.0 - alpha) * deshake->avg.vector.x;
+ deshake->avg.vector.y = alpha * t.vector.y + (1.0 - alpha) * deshake->avg.vector.y;
+ deshake->avg.angle = alpha * t.angle + (1.0 - alpha) * deshake->avg.angle;
+ deshake->avg.zoom = alpha * t.zoom + (1.0 - alpha) * deshake->avg.zoom;
+
+ // Remove the average from the current motion to detect the motion that
+ // is not on purpose, just as jitter from bumping the camera
+ t.vector.x -= deshake->avg.vector.x;
+ t.vector.y -= deshake->avg.vector.y;
+ t.angle -= deshake->avg.angle;
+ t.zoom -= deshake->avg.zoom;
+
+ // Invert the motion to undo it
+ t.vector.x *= -1;
+ t.vector.y *= -1;
+ t.angle *= -1;
+
+ // Write statistics to file
+ if (deshake->fp) {
+ snprintf(tmp, 256, "%f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f\n", orig.vector.x, deshake->avg.vector.x, t.vector.x, orig.vector.y, deshake->avg.vector.y, t.vector.y, orig.angle, deshake->avg.angle, t.angle, orig.zoom, deshake->avg.zoom, t.zoom);
+ fwrite(tmp, sizeof(char), strlen(tmp), deshake->fp);
+ }
+
+ // Turn relative current frame motion into absolute by adding it to the
+ // last absolute motion
+ t.vector.x += deshake->last.vector.x;
+ t.vector.y += deshake->last.vector.y;
+ t.angle += deshake->last.angle;
+ t.zoom += deshake->last.zoom;
+
+ // Shrink motion by 10% to keep things centered in the camera frame
+ t.vector.x *= 0.9;
+ t.vector.y *= 0.9;
+ t.angle *= 0.9;
+
+ // Store the last absolute motion information
+ deshake->last.vector.x = t.vector.x;
+ deshake->last.vector.y = t.vector.y;
+ deshake->last.angle = t.angle;
+ deshake->last.zoom = t.zoom;
+
+ // Generate a luma transformation matrix
+ avfilter_get_matrix(t.vector.x, t.vector.y, t.angle, 1.0 + t.zoom / 100.0, matrix);
+
+ // Transform the luma plane
+ avfilter_transform(in->data[0], out->data[0], in->linesize[0], out->linesize[0], link->w, link->h, matrix, INTERPOLATE_BILINEAR, deshake->edge);
+
+ // Generate a chroma transformation matrix
+ avfilter_get_matrix(t.vector.x / (link->w / CHROMA_WIDTH(link)), t.vector.y / (link->h / CHROMA_HEIGHT(link)), t.angle, 1.0 + t.zoom / 100.0, matrix);
+
+ // Transform the chroma planes
+ avfilter_transform(in->data[1], out->data[1], in->linesize[1], out->linesize[1], CHROMA_WIDTH(link), CHROMA_HEIGHT(link), matrix, INTERPOLATE_BILINEAR, deshake->edge);
+ avfilter_transform(in->data[2], out->data[2], in->linesize[2], out->linesize[2], CHROMA_WIDTH(link), CHROMA_HEIGHT(link), matrix, INTERPOLATE_BILINEAR, deshake->edge);
+
+ // Store the current frame as the reference frame for calculating the
+ // motion of the next frame
+ if (deshake->ref != NULL)
+ avfilter_unref_buffer(deshake->ref);
+
+ // Cleanup the old reference frame
+ deshake->ref = in;
+
+ // Draw the transformed frame information
+ avfilter_draw_slice(link->dst->outputs[0], 0, link->h, 1);
+ avfilter_end_frame(link->dst->outputs[0]);
+ avfilter_unref_buffer(out);
+}
+
+static void draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
+{
+}
+
+AVFilter avfilter_vf_deshake = {
+ .name = "deshake",
+ .description = NULL_IF_CONFIG_SMALL("Stabilize shaky video."),
+
+ .priv_size = sizeof(DeshakeContext),
+
+ .init = init,
+ .uninit = uninit,
+ .query_formats = query_formats,
+
+ .inputs = (AVFilterPad[]) {{ .name = "default",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .draw_slice = draw_slice,
+ .end_frame = end_frame,
+ .config_props = config_props,
+ .min_perms = AV_PERM_READ, },
+ { .name = NULL}},
+
+ .outputs = (AVFilterPad[]) {{ .name = "default",
+ .type = AVMEDIA_TYPE_VIDEO, },
+ { .name = NULL}},
+};
diff --git a/libavfilter/vf_drawbox.c b/libavfilter/vf_drawbox.c
index 37c48c5c89..d4d83044c4 100644
--- a/libavfilter/vf_drawbox.c
+++ b/libavfilter/vf_drawbox.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2008 Affine Systems, Inc (Michael Sullivan, Bobby Impollonia)
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -34,7 +34,7 @@ enum { Y, U, V, A };
typedef struct {
int x, y, w, h;
unsigned char yuv_color[4];
- int vsub, hsub; //< chroma subsampling
+ int vsub, hsub; ///< chroma subsampling
} DrawBoxContext;
static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
@@ -70,7 +70,7 @@ static int query_formats(AVFilterContext *ctx)
PIX_FMT_NONE
};
- avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts));
+ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts));
return 0;
}
diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c
index a3adaa7dfc..3b74bf46b7 100644
--- a/libavfilter/vf_drawtext.c
+++ b/libavfilter/vf_drawtext.c
@@ -3,20 +3,20 @@
* Copyright (c) 2010 S.N. Hemanth Meenakshisundaram
* Copyright (c) 2003 Gustavo Sverzut Barbieri <gsbarbieri@yahoo.com.br>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -30,6 +30,7 @@
#include <time.h>
#include "libavutil/colorspace.h"
+#include "libavutil/eval.h"
#include "libavutil/file.h"
#include "libavutil/opt.h"
#include "libavutil/parseutils.h"
@@ -45,8 +46,51 @@
#include FT_FREETYPE_H
#include FT_GLYPH_H
+static const char *var_names[] = {
+ "w", ///< width of the input video
+ "h", ///< height of the input video
+ "tw", "text_w", ///< width of the rendered text
+ "th", "text_h", ///< height of the rendered text
+ "max_glyph_w", ///< max glyph width
+ "max_glyph_h", ///< max glyph height
+ "max_glyph_a", "ascent", ///< max glyph ascent
+ "max_glyph_d", "descent", ///< min glyph descent
+ "line_h", "lh", ///< line height, same as max_glyph_h
+ "sar",
+ "dar",
+ "hsub",
+ "vsub",
+ "x",
+ "y",
+ "n", ///< number of frame
+ "t", ///< timestamp expressed in seconds
+ NULL
+};
+
+enum var_name {
+ VAR_W,
+ VAR_H,
+ VAR_TW, VAR_TEXT_W,
+ VAR_TH, VAR_TEXT_H,
+ VAR_MAX_GLYPH_W,
+ VAR_MAX_GLYPH_H,
+ VAR_MAX_GLYPH_A, VAR_ASCENT,
+ VAR_MAX_GLYPH_D, VAR_DESCENT,
+ VAR_LINE_H, VAR_LH,
+ VAR_SAR,
+ VAR_DAR,
+ VAR_HSUB,
+ VAR_VSUB,
+ VAR_X,
+ VAR_Y,
+ VAR_N,
+ VAR_T,
+ VAR_VARS_NB
+};
+
typedef struct {
const AVClass *class;
+ int reinit; ///< tells if the filter is being reinited
uint8_t *fontfile; ///< font to be used
uint8_t *text; ///< text to be drawn
uint8_t *expanded_text; ///< used to contain the strftime()-expanded text
@@ -55,8 +99,13 @@ typedef struct {
FT_Vector *positions; ///< positions for each element in the text
size_t nb_positions; ///< number of elements of positions array
char *textfile; ///< file with text to be drawn
- unsigned int x; ///< x position to start drawing text
- unsigned int y; ///< y position to start drawing text
+ int x; ///< x position to start drawing text
+ int y; ///< y position to start drawing text
+ char *x_expr; ///< expression for x position
+ char *y_expr; ///< expression for y position
+ AVExpr *x_pexpr, *y_pexpr; ///< parsed expressions for x and y
+ int max_glyph_w; ///< max glyph width
+ int max_glyph_h; ///< max glyph heigth
int shadowx, shadowy;
unsigned int fontsize; ///< font size to use
char *fontcolor_string; ///< font color as string
@@ -81,42 +130,46 @@ typedef struct {
int pixel_step[4]; ///< distance in bytes between the component of each pixel
uint8_t rgba_map[4]; ///< map RGBA offsets to the positions in the packed RGBA format
uint8_t *box_line[4]; ///< line used for filling the box background
+ int64_t basetime; ///< base pts time in the real world for display
+ double var_values[VAR_VARS_NB];
} DrawTextContext;
#define OFFSET(x) offsetof(DrawTextContext, x)
static const AVOption drawtext_options[]= {
-{"fontfile", "set font file", OFFSET(fontfile), FF_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX },
-{"text", "set text", OFFSET(text), FF_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX },
-{"textfile", "set text file", OFFSET(textfile), FF_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX },
-{"fontcolor","set foreground color", OFFSET(fontcolor_string), FF_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX },
-{"boxcolor", "set box color", OFFSET(boxcolor_string), FF_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX },
-{"shadowcolor", "set shadow color", OFFSET(shadowcolor_string), FF_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX },
-{"box", "set box", OFFSET(draw_box), FF_OPT_TYPE_INT, {.dbl=0}, 0, 1 },
-{"fontsize", "set font size", OFFSET(fontsize), FF_OPT_TYPE_INT, {.dbl=16}, 1, 72 },
-{"x", "set x", OFFSET(x), FF_OPT_TYPE_INT, {.dbl=0}, 0, INT_MAX },
-{"y", "set y", OFFSET(y), FF_OPT_TYPE_INT, {.dbl=0}, 0, INT_MAX },
-{"shadowx", "set x", OFFSET(shadowx), FF_OPT_TYPE_INT, {.dbl=0}, INT_MIN, INT_MAX },
-{"shadowy", "set y", OFFSET(shadowy), FF_OPT_TYPE_INT, {.dbl=0}, INT_MIN, INT_MAX },
-{"tabsize", "set tab size", OFFSET(tabsize), FF_OPT_TYPE_INT, {.dbl=4}, 0, INT_MAX },
+{"fontfile", "set font file", OFFSET(fontfile), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX },
+{"text", "set text", OFFSET(text), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX },
+{"textfile", "set text file", OFFSET(textfile), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX },
+{"fontcolor", "set foreground color", OFFSET(fontcolor_string), AV_OPT_TYPE_STRING, {.str="black"}, CHAR_MIN, CHAR_MAX },
+{"boxcolor", "set box color", OFFSET(boxcolor_string), AV_OPT_TYPE_STRING, {.str="white"}, CHAR_MIN, CHAR_MAX },
+{"shadowcolor", "set shadow color", OFFSET(shadowcolor_string), AV_OPT_TYPE_STRING, {.str="black"}, CHAR_MIN, CHAR_MAX },
+{"box", "set box", OFFSET(draw_box), AV_OPT_TYPE_INT, {.dbl=0}, 0, 1 },
+{"fontsize", "set font size", OFFSET(fontsize), AV_OPT_TYPE_INT, {.dbl=16}, 1, INT_MAX },
+{"x", "set x expression", OFFSET(x_expr), AV_OPT_TYPE_STRING, {.str="0"}, CHAR_MIN, CHAR_MAX },
+{"y", "set y expression", OFFSET(y_expr), AV_OPT_TYPE_STRING, {.str="0"}, CHAR_MIN, CHAR_MAX },
+{"shadowx", "set x", OFFSET(shadowx), AV_OPT_TYPE_INT, {.dbl=0}, INT_MIN, INT_MAX },
+{"shadowy", "set y", OFFSET(shadowy), AV_OPT_TYPE_INT, {.dbl=0}, INT_MIN, INT_MAX },
+{"tabsize", "set tab size", OFFSET(tabsize), AV_OPT_TYPE_INT, {.dbl=4}, 0, INT_MAX },
+{"basetime", "set base time", OFFSET(basetime), AV_OPT_TYPE_INT64, {.dbl=AV_NOPTS_VALUE}, INT64_MIN, INT64_MAX },
+
/* FT_LOAD_* flags */
-{"ft_load_flags", "set font loading flags for libfreetype", OFFSET(ft_load_flags), FF_OPT_TYPE_FLAGS, {.dbl=FT_LOAD_DEFAULT|FT_LOAD_RENDER}, 0, INT_MAX, 0, "ft_load_flags" },
-{"default", "set default", 0, FF_OPT_TYPE_CONST, {FT_LOAD_DEFAULT}, INT_MIN, INT_MAX, 0, "ft_load_flags" },
-{"no_scale", "set no_scale", 0, FF_OPT_TYPE_CONST, {FT_LOAD_NO_SCALE}, INT_MIN, INT_MAX, 0, "ft_load_flags" },
-{"no_hinting", "set no_hinting", 0, FF_OPT_TYPE_CONST, {FT_LOAD_NO_HINTING}, INT_MIN, INT_MAX, 0, "ft_load_flags" },
-{"render", "set render", 0, FF_OPT_TYPE_CONST, {FT_LOAD_RENDER}, INT_MIN, INT_MAX, 0, "ft_load_flags" },
-{"no_bitmap", "set no_bitmap", 0, FF_OPT_TYPE_CONST, {FT_LOAD_NO_BITMAP}, INT_MIN, INT_MAX, 0, "ft_load_flags" },
-{"vertical_layout", "set vertical_layout", 0, FF_OPT_TYPE_CONST, {FT_LOAD_VERTICAL_LAYOUT}, INT_MIN, INT_MAX, 0, "ft_load_flags" },
-{"force_autohint", "set force_autohint", 0, FF_OPT_TYPE_CONST, {FT_LOAD_FORCE_AUTOHINT}, INT_MIN, INT_MAX, 0, "ft_load_flags" },
-{"crop_bitmap", "set crop_bitmap", 0, FF_OPT_TYPE_CONST, {FT_LOAD_CROP_BITMAP}, INT_MIN, INT_MAX, 0, "ft_load_flags" },
-{"pedantic", "set pedantic", 0, FF_OPT_TYPE_CONST, {FT_LOAD_PEDANTIC}, INT_MIN, INT_MAX, 0, "ft_load_flags" },
-{"ignore_global_advance_width", "set ignore_global_advance_width", 0, FF_OPT_TYPE_CONST, {FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH}, INT_MIN, INT_MAX, 0, "ft_load_flags" },
-{"no_recurse", "set no_recurse", 0, FF_OPT_TYPE_CONST, {FT_LOAD_NO_RECURSE}, INT_MIN, INT_MAX, 0, "ft_load_flags" },
-{"ignore_transform", "set ignore_transform", 0, FF_OPT_TYPE_CONST, {FT_LOAD_IGNORE_TRANSFORM}, INT_MIN, INT_MAX, 0, "ft_load_flags" },
-{"monochrome", "set monochrome", 0, FF_OPT_TYPE_CONST, {FT_LOAD_MONOCHROME}, INT_MIN, INT_MAX, 0, "ft_load_flags" },
-{"linear_design", "set linear_design", 0, FF_OPT_TYPE_CONST, {FT_LOAD_LINEAR_DESIGN}, INT_MIN, INT_MAX, 0, "ft_load_flags" },
-{"no_autohint", "set no_autohint", 0, FF_OPT_TYPE_CONST, {FT_LOAD_NO_AUTOHINT}, INT_MIN, INT_MAX, 0, "ft_load_flags" },
+{"ft_load_flags", "set font loading flags for libfreetype", OFFSET(ft_load_flags), AV_OPT_TYPE_FLAGS, {.dbl=FT_LOAD_DEFAULT|FT_LOAD_RENDER}, 0, INT_MAX, 0, "ft_load_flags" },
+{"default", "set default", 0, AV_OPT_TYPE_CONST, {.dbl=FT_LOAD_DEFAULT}, INT_MIN, INT_MAX, 0, "ft_load_flags" },
+{"no_scale", "set no_scale", 0, AV_OPT_TYPE_CONST, {.dbl=FT_LOAD_NO_SCALE}, INT_MIN, INT_MAX, 0, "ft_load_flags" },
+{"no_hinting", "set no_hinting", 0, AV_OPT_TYPE_CONST, {.dbl=FT_LOAD_NO_HINTING}, INT_MIN, INT_MAX, 0, "ft_load_flags" },
+{"render", "set render", 0, AV_OPT_TYPE_CONST, {.dbl=FT_LOAD_RENDER}, INT_MIN, INT_MAX, 0, "ft_load_flags" },
+{"no_bitmap", "set no_bitmap", 0, AV_OPT_TYPE_CONST, {.dbl=FT_LOAD_NO_BITMAP}, INT_MIN, INT_MAX, 0, "ft_load_flags" },
+{"vertical_layout", "set vertical_layout", 0, AV_OPT_TYPE_CONST, {.dbl=FT_LOAD_VERTICAL_LAYOUT}, INT_MIN, INT_MAX, 0, "ft_load_flags" },
+{"force_autohint", "set force_autohint", 0, AV_OPT_TYPE_CONST, {.dbl=FT_LOAD_FORCE_AUTOHINT}, INT_MIN, INT_MAX, 0, "ft_load_flags" },
+{"crop_bitmap", "set crop_bitmap", 0, AV_OPT_TYPE_CONST, {.dbl=FT_LOAD_CROP_BITMAP}, INT_MIN, INT_MAX, 0, "ft_load_flags" },
+{"pedantic", "set pedantic", 0, AV_OPT_TYPE_CONST, {.dbl=FT_LOAD_PEDANTIC}, INT_MIN, INT_MAX, 0, "ft_load_flags" },
+{"ignore_global_advance_width", "set ignore_global_advance_width", 0, AV_OPT_TYPE_CONST, {.dbl=FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH}, INT_MIN, INT_MAX, 0, "ft_load_flags" },
+{"no_recurse", "set no_recurse", 0, AV_OPT_TYPE_CONST, {.dbl=FT_LOAD_NO_RECURSE}, INT_MIN, INT_MAX, 0, "ft_load_flags" },
+{"ignore_transform", "set ignore_transform", 0, AV_OPT_TYPE_CONST, {.dbl=FT_LOAD_IGNORE_TRANSFORM}, INT_MIN, INT_MAX, 0, "ft_load_flags" },
+{"monochrome", "set monochrome", 0, AV_OPT_TYPE_CONST, {.dbl=FT_LOAD_MONOCHROME}, INT_MIN, INT_MAX, 0, "ft_load_flags" },
+{"linear_design", "set linear_design", 0, AV_OPT_TYPE_CONST, {.dbl=FT_LOAD_LINEAR_DESIGN}, INT_MIN, INT_MAX, 0, "ft_load_flags" },
+{"no_autohint", "set no_autohint", 0, AV_OPT_TYPE_CONST, {.dbl=FT_LOAD_NO_AUTOHINT}, INT_MIN, INT_MAX, 0, "ft_load_flags" },
{NULL},
};
@@ -223,10 +276,7 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
Glyph *glyph;
dtext->class = &drawtext_class;
- av_opt_set_defaults2(dtext, 0, 0);
- dtext->fontcolor_string = av_strdup("black");
- dtext->boxcolor_string = av_strdup("white");
- dtext->shadowcolor_string = av_strdup("black");
+ av_opt_set_defaults(dtext);
if ((err = (av_set_options_string(dtext, args, "=", ":"))) < 0) {
av_log(ctx, AV_LOG_ERROR, "Error parsing options string: '%s'\n", args);
@@ -315,10 +365,6 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
}
dtext->tabsize *= glyph->advance;
-#if !HAVE_LOCALTIME_R
- av_log(ctx, AV_LOG_WARNING, "strftime() expansion unavailable!\n");
-#endif
-
return 0;
}
@@ -334,7 +380,7 @@ static int query_formats(AVFilterContext *ctx)
PIX_FMT_NONE
};
- avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts));
+ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts));
return 0;
}
@@ -349,16 +395,25 @@ static av_cold void uninit(AVFilterContext *ctx)
DrawTextContext *dtext = ctx->priv;
int i;
- av_freep(&dtext->fontfile);
- av_freep(&dtext->text);
+ av_expr_free(dtext->x_pexpr); dtext->x_pexpr = NULL;
+ av_expr_free(dtext->y_pexpr); dtext->y_pexpr = NULL;
+
+ av_freep(&dtext->boxcolor_string);
av_freep(&dtext->expanded_text);
av_freep(&dtext->fontcolor_string);
- av_freep(&dtext->boxcolor_string);
- av_freep(&dtext->positions);
+ av_freep(&dtext->fontfile);
av_freep(&dtext->shadowcolor_string);
+ av_freep(&dtext->text);
+ av_freep(&dtext->x_expr);
+ av_freep(&dtext->y_expr);
+
+ av_freep(&dtext->positions);
+ dtext->nb_positions = 0;
+
av_tree_enumerate(dtext->glyphs, NULL, NULL, glyph_enu_free);
av_tree_destroy(dtext->glyphs);
- dtext->glyphs = 0;
+ dtext->glyphs = NULL;
+
FT_Done_Face(dtext->face);
FT_Done_FreeType(dtext->library);
@@ -366,11 +421,11 @@ static av_cold void uninit(AVFilterContext *ctx)
av_freep(&dtext->box_line[i]);
dtext->pixel_step[i] = 0;
}
-
}
static int config_input(AVFilterLink *inlink)
{
+ AVFilterContext *ctx = inlink->dst;
DrawTextContext *dtext = inlink->dst->priv;
const AVPixFmtDescriptor *pix_desc = &av_pix_fmt_descriptors[inlink->format];
int ret;
@@ -398,9 +453,43 @@ static int config_input(AVFilterLink *inlink)
dtext->shadowcolor[3] = rgba[3];
}
+ dtext->var_values[VAR_W] = inlink->w;
+ dtext->var_values[VAR_H] = inlink->h;
+ dtext->var_values[VAR_SAR] = inlink->sample_aspect_ratio.num ? av_q2d(inlink->sample_aspect_ratio) : 1;
+ dtext->var_values[VAR_DAR] = (double)inlink->w / inlink->h * dtext->var_values[VAR_SAR];
+ dtext->var_values[VAR_HSUB] = 1<<pix_desc->log2_chroma_w;
+ dtext->var_values[VAR_VSUB] = 1<<pix_desc->log2_chroma_h;
+ dtext->var_values[VAR_X] = NAN;
+ dtext->var_values[VAR_Y] = NAN;
+ if (!dtext->reinit)
+ dtext->var_values[VAR_N] = 0;
+ dtext->var_values[VAR_T] = NAN;
+
+ if ((ret = av_expr_parse(&dtext->x_pexpr, dtext->x_expr, var_names,
+ NULL, NULL, NULL, NULL, 0, ctx)) < 0 ||
+ (ret = av_expr_parse(&dtext->y_pexpr, dtext->y_expr, var_names,
+ NULL, NULL, NULL, NULL, 0, ctx)) < 0)
+ return AVERROR(EINVAL);
+
return 0;
}
+static int command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
+{
+ DrawTextContext *dtext = ctx->priv;
+
+ if (!strcmp(cmd, "reinit")) {
+ int ret;
+ uninit(ctx);
+ dtext->reinit = 1;
+ if ((ret = init(ctx, arg, NULL)) < 0)
+ return ret;
+ return config_input(ctx->inputs[0]);
+ }
+
+ return AVERROR(ENOSYS);
+}
+
#define GET_BITMAP_VAL(r, c) \
bitmap->pixel_mode == FT_PIXEL_MODE_MONO ? \
(bitmap->buffer[(r) * bitmap->pitch + ((c)>>3)] & (0x80 >> ((c)&7))) * 255 : \
@@ -418,20 +507,18 @@ static int config_input(AVFilterLink *inlink)
}\
}
-static inline int draw_glyph_yuv(AVFilterBufferRef *picref, FT_Bitmap *bitmap, unsigned int x,
- unsigned int y, unsigned int width, unsigned int height,
+static inline int draw_glyph_yuv(AVFilterBufferRef *picref, FT_Bitmap *bitmap,
+ int x, int y, int width, int height,
const uint8_t yuva_color[4], int hsub, int vsub)
{
int r, c, alpha;
unsigned int luma_pos, chroma_pos1, chroma_pos2;
- uint8_t src_val, dst_pixel[4];
+ uint8_t src_val;
for (r = 0; r < bitmap->rows && r+y < height; r++) {
for (c = 0; c < bitmap->width && c+x < width; c++) {
- /* get pixel in the picref (destination) */
- dst_pixel[0] = picref->data[0][ c+x + (y+r) * picref->linesize[0]];
- dst_pixel[1] = picref->data[1][((c+x) >> hsub) + ((y+r) >> vsub) * picref->linesize[1]];
- dst_pixel[2] = picref->data[2][((c+x) >> hsub) + ((y+r) >> vsub) * picref->linesize[2]];
+ if (c+x < 0 || r+y < 0)
+ continue;
/* get intensity value in the glyph bitmap (source) */
src_val = GET_BITMAP_VAL(r, c);
@@ -454,24 +541,17 @@ static inline int draw_glyph_yuv(AVFilterBufferRef *picref, FT_Bitmap *bitmap, u
}
static inline int draw_glyph_rgb(AVFilterBufferRef *picref, FT_Bitmap *bitmap,
- unsigned int x, unsigned int y,
- unsigned int width, unsigned int height, int pixel_step,
+ int x, int y, int width, int height, int pixel_step,
const uint8_t rgba_color[4], const uint8_t rgba_map[4])
{
int r, c, alpha;
uint8_t *p;
- uint8_t src_val, dst_pixel[4];
+ uint8_t src_val;
for (r = 0; r < bitmap->rows && r+y < height; r++) {
for (c = 0; c < bitmap->width && c+x < width; c++) {
- /* get pixel in the picref (destination) */
- dst_pixel[0] = picref->data[0][(c+x + rgba_map[0]) * pixel_step +
- (y+r) * picref->linesize[0]];
- dst_pixel[1] = picref->data[0][(c+x + rgba_map[1]) * pixel_step +
- (y+r) * picref->linesize[0]];
- dst_pixel[2] = picref->data[0][(c+x + rgba_map[2]) * pixel_step +
- (y+r) * picref->linesize[0]];
-
+ if (c+x < 0 || r+y < 0)
+ continue;
/* get intensity value in the glyph bitmap (source) */
src_val = GET_BITMAP_VAL(r, c);
if (!src_val)
@@ -485,8 +565,8 @@ static inline int draw_glyph_rgb(AVFilterBufferRef *picref, FT_Bitmap *bitmap,
return 0;
}
-static inline void drawbox(AVFilterBufferRef *picref, unsigned int x, unsigned int y,
- unsigned int width, unsigned int height,
+static inline void drawbox(AVFilterBufferRef *picref, int x, int y,
+ int width, int height,
uint8_t *line[4], int pixel_step[4], uint8_t color[4],
int hsub, int vsub, int is_rgba_packed, uint8_t rgba_map[4])
{
@@ -520,9 +600,9 @@ static inline int is_newline(uint32_t c)
static int draw_glyphs(DrawTextContext *dtext, AVFilterBufferRef *picref,
int width, int height, const uint8_t rgbcolor[4], const uint8_t yuvcolor[4], int x, int y)
{
- char *text = HAVE_LOCALTIME_R ? dtext->expanded_text : dtext->text;
+ char *text = dtext->expanded_text;
uint32_t code = 0;
- int i;
+ int i, x1, y1;
uint8_t *p;
Glyph *glyph = NULL;
@@ -541,13 +621,16 @@ static int draw_glyphs(DrawTextContext *dtext, AVFilterBufferRef *picref,
glyph->bitmap.pixel_mode != FT_PIXEL_MODE_GRAY)
return AVERROR(EINVAL);
+ x1 = dtext->positions[i].x+dtext->x+x;
+ y1 = dtext->positions[i].y+dtext->y+y;
+
if (dtext->is_packed_rgb) {
draw_glyph_rgb(picref, &glyph->bitmap,
- dtext->positions[i].x+x, dtext->positions[i].y+y, width, height,
+ x1, y1, width, height,
dtext->pixel_step[0], rgbcolor, dtext->rgba_map);
} else {
draw_glyph_yuv(picref, &glyph->bitmap,
- dtext->positions[i].x+x, dtext->positions[i].y+y, width, height,
+ x1, y1, width, height,
yuvcolor, dtext->hsub, dtext->vsub);
}
}
@@ -561,27 +644,35 @@ static int draw_text(AVFilterContext *ctx, AVFilterBufferRef *picref,
DrawTextContext *dtext = ctx->priv;
uint32_t code = 0, prev_code = 0;
int x = 0, y = 0, i = 0, ret;
- int text_height, baseline;
+ int max_text_line_w = 0, len;
+ int box_w, box_h;
char *text = dtext->text;
uint8_t *p;
- int str_w = 0, len;
int y_min = 32000, y_max = -32000;
+ int x_min = 32000, x_max = -32000;
FT_Vector delta;
Glyph *glyph = NULL, *prev_glyph = NULL;
Glyph dummy = { 0 };
-#if HAVE_LOCALTIME_R
time_t now = time(0);
struct tm ltime;
uint8_t *buf = dtext->expanded_text;
int buf_size = dtext->expanded_text_size;
+ if(dtext->basetime != AV_NOPTS_VALUE)
+ now= picref->pts*av_q2d(ctx->inputs[0]->time_base) + dtext->basetime/1000000;
+
if (!buf) {
buf_size = 2*strlen(dtext->text)+1;
buf = av_malloc(buf_size);
}
+#if HAVE_LOCALTIME_R
localtime_r(&now, &ltime);
+#else
+ if(strchr(dtext->text, '%'))
+ ltime= *localtime(&now);
+#endif
do {
*buf = 1;
@@ -594,7 +685,6 @@ static int draw_text(AVFilterContext *ctx, AVFilterBufferRef *picref,
return AVERROR(ENOMEM);
text = dtext->expanded_text = buf;
dtext->expanded_text_size = buf_size;
-#endif
if ((len = strlen(text)) > dtext->nb_positions) {
if (!(dtext->positions =
av_realloc(dtext->positions, len*sizeof(*dtext->positions))))
@@ -602,8 +692,8 @@ static int draw_text(AVFilterContext *ctx, AVFilterBufferRef *picref,
dtext->nb_positions = len;
}
- x = dtext->x;
- y = dtext->y;
+ x = 0;
+ y = 0;
/* load and cache glyphs */
for (i = 0, p = text; *p; i++) {
@@ -617,9 +707,11 @@ static int draw_text(AVFilterContext *ctx, AVFilterBufferRef *picref,
y_min = FFMIN(glyph->bbox.yMin, y_min);
y_max = FFMAX(glyph->bbox.yMax, y_max);
+ x_min = FFMIN(glyph->bbox.xMin, x_min);
+ x_max = FFMAX(glyph->bbox.xMax, x_max);
}
- text_height = y_max - y_min;
- baseline = y_max;
+ dtext->max_glyph_h = y_max - y_min;
+ dtext->max_glyph_w = x_max - x_min;
/* compute and save position for each glyph */
glyph = NULL;
@@ -632,9 +724,9 @@ static int draw_text(AVFilterContext *ctx, AVFilterBufferRef *picref,
prev_code = code;
if (is_newline(code)) {
- str_w = FFMAX(str_w, x - dtext->x);
- y += text_height;
- x = dtext->x;
+ max_text_line_w = FFMAX(max_text_line_w, x);
+ y += dtext->max_glyph_h;
+ x = 0;
continue;
}
@@ -650,26 +742,39 @@ static int draw_text(AVFilterContext *ctx, AVFilterBufferRef *picref,
x += delta.x >> 6;
}
- if (x + glyph->bbox.xMax >= width) {
- str_w = FFMAX(str_w, x - dtext->x);
- y += text_height;
- x = dtext->x;
- }
-
/* save position */
dtext->positions[i].x = x + glyph->bitmap_left;
- dtext->positions[i].y = y - glyph->bitmap_top + baseline;
+ dtext->positions[i].y = y - glyph->bitmap_top + y_max;
if (code == '\t') x = (x / dtext->tabsize + 1)*dtext->tabsize;
else x += glyph->advance;
}
- str_w = FFMIN(width - dtext->x - 1, FFMAX(str_w, x - dtext->x));
- y = FFMIN(y + text_height, height - 1);
+ max_text_line_w = FFMAX(x, max_text_line_w);
+
+ dtext->var_values[VAR_TW] = dtext->var_values[VAR_TEXT_W] = max_text_line_w;
+ dtext->var_values[VAR_TH] = dtext->var_values[VAR_TEXT_H] = y + dtext->max_glyph_h;
+
+ dtext->var_values[VAR_MAX_GLYPH_W] = dtext->max_glyph_w;
+ dtext->var_values[VAR_MAX_GLYPH_H] = dtext->max_glyph_h;
+ dtext->var_values[VAR_MAX_GLYPH_A] = dtext->var_values[VAR_ASCENT ] = y_max;
+ dtext->var_values[VAR_MAX_GLYPH_D] = dtext->var_values[VAR_DESCENT] = y_min;
+
+ dtext->var_values[VAR_LINE_H] = dtext->var_values[VAR_LH] = dtext->max_glyph_h;
+
+ dtext->x = dtext->var_values[VAR_X] = av_expr_eval(dtext->x_pexpr, dtext->var_values, NULL);
+ dtext->y = dtext->var_values[VAR_Y] = av_expr_eval(dtext->y_pexpr, dtext->var_values, NULL);
+ dtext->x = dtext->var_values[VAR_X] = av_expr_eval(dtext->x_pexpr, dtext->var_values, NULL);
+
+ dtext->x &= ~((1 << dtext->hsub) - 1);
+ dtext->y &= ~((1 << dtext->vsub) - 1);
+
+ box_w = FFMIN(width - 1 , max_text_line_w);
+ box_h = FFMIN(height - 1, y + dtext->max_glyph_h);
/* draw box */
if (dtext->draw_box)
- drawbox(picref, dtext->x, dtext->y, str_w, y-dtext->y,
- dtext->box_line, dtext->pixel_step, dtext->boxcolor,
+ drawbox(picref, dtext->x, dtext->y, box_w, box_h,
+ dtext->box_line, dtext->pixel_step, dtext->boxcolor_rgba,
dtext->hsub, dtext->vsub, dtext->is_packed_rgb, dtext->rgba_map);
if (dtext->shadowx || dtext->shadowy) {
@@ -689,10 +794,22 @@ static void null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) { }
static void end_frame(AVFilterLink *inlink)
{
- AVFilterLink *outlink = inlink->dst->outputs[0];
+ AVFilterContext *ctx = inlink->dst;
+ AVFilterLink *outlink = ctx->outputs[0];
+ DrawTextContext *dtext = ctx->priv;
AVFilterBufferRef *picref = inlink->cur_buf;
- draw_text(inlink->dst, picref, picref->video->w, picref->video->h);
+ dtext->var_values[VAR_T] = picref->pts == AV_NOPTS_VALUE ?
+ NAN : picref->pts * av_q2d(inlink->time_base);
+
+ draw_text(ctx, picref, picref->video->w, picref->video->h);
+
+ av_log(ctx, AV_LOG_DEBUG, "n:%d t:%f text_w:%d text_h:%d x:%d y:%d\n",
+ (int)dtext->var_values[VAR_N], dtext->var_values[VAR_T],
+ (int)dtext->var_values[VAR_TEXT_W], (int)dtext->var_values[VAR_TEXT_H],
+ dtext->x, dtext->y);
+
+ dtext->var_values[VAR_N] += 1.0;
avfilter_draw_slice(outlink, 0, picref->video->h, 1);
avfilter_end_frame(outlink);
@@ -720,4 +837,5 @@ AVFilter avfilter_vf_drawtext = {
.outputs = (AVFilterPad[]) {{ .name = "default",
.type = AVMEDIA_TYPE_VIDEO, },
{ .name = NULL}},
+ .process_command = command,
};
diff --git a/libavfilter/vf_fade.c b/libavfilter/vf_fade.c
index 0c8668ce90..6c2a23dac3 100644
--- a/libavfilter/vf_fade.c
+++ b/libavfilter/vf_fade.c
@@ -2,20 +2,20 @@
* Copyright (c) 2010 Brandon Mintern
* Copyright (c) 2007 Bobby Bingham
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -78,7 +78,7 @@ static int query_formats(AVFilterContext *ctx)
PIX_FMT_NONE
};
- avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts));
+ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts));
return 0;
}
diff --git a/libavfilter/vf_fieldorder.c b/libavfilter/vf_fieldorder.c
index 444dffb52c..0913b6950e 100644
--- a/libavfilter/vf_fieldorder.c
+++ b/libavfilter/vf_fieldorder.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2011 Mark Himsley
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavfilter/vf_fifo.c b/libavfilter/vf_fifo.c
index 836cce28b5..32199eddc8 100644
--- a/libavfilter/vf_fifo.c
+++ b/libavfilter/vf_fifo.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2007 Bobby Bingham
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavfilter/vf_format.c b/libavfilter/vf_format.c
index 0b0d094169..ecf6ebe047 100644
--- a/libavfilter/vf_format.c
+++ b/libavfilter/vf_format.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2007 Bobby Bingham
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -25,6 +25,7 @@
#include "libavutil/pixdesc.h"
#include "avfilter.h"
+#include "internal.h"
typedef struct {
/**
@@ -41,7 +42,7 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
FormatContext *format = ctx->priv;
const char *cur, *sep;
char pix_fmt_name[PIX_FMT_NAME_MAXSIZE];
- int pix_fmt_name_len;
+ int pix_fmt_name_len, ret;
enum PixelFormat pix_fmt;
/* parse the list of formats */
@@ -57,12 +58,9 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
memcpy(pix_fmt_name, cur, pix_fmt_name_len);
pix_fmt_name[pix_fmt_name_len] = 0;
- pix_fmt = av_get_pix_fmt(pix_fmt_name);
- if (pix_fmt == PIX_FMT_NONE) {
- av_log(ctx, AV_LOG_ERROR, "Unknown pixel format: %s\n", pix_fmt_name);
- return -1;
- }
+ if ((ret = ff_parse_pixel_format(&pix_fmt, pix_fmt_name, ctx)) < 0)
+ return ret;
format->listed_pix_fmt_flags[pix_fmt] = 1;
}
@@ -88,7 +86,7 @@ static AVFilterFormats *make_format_list(FormatContext *format, int flag)
#if CONFIG_FORMAT_FILTER
static int query_formats_format(AVFilterContext *ctx)
{
- avfilter_set_common_formats(ctx, make_format_list(ctx->priv, 1));
+ avfilter_set_common_pixel_formats(ctx, make_format_list(ctx->priv, 1));
return 0;
}
@@ -118,7 +116,7 @@ AVFilter avfilter_vf_format = {
#if CONFIG_NOFORMAT_FILTER
static int query_formats_noformat(AVFilterContext *ctx)
{
- avfilter_set_common_formats(ctx, make_format_list(ctx->priv, 0));
+ avfilter_set_common_pixel_formats(ctx, make_format_list(ctx->priv, 0));
return 0;
}
diff --git a/libavfilter/vf_frei0r.c b/libavfilter/vf_frei0r.c
index 48683f4fea..5d5a4db1e6 100644
--- a/libavfilter/vf_frei0r.c
+++ b/libavfilter/vf_frei0r.c
@@ -1,19 +1,19 @@
/*
* Copyright (c) 2010 Stefano Sabatini
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -28,6 +28,7 @@
#include <frei0r.h>
#include "libavutil/avstring.h"
#include "libavutil/imgutils.h"
+#include "libavutil/mathematics.h"
#include "libavutil/parseutils.h"
#include "avfilter.h"
@@ -215,7 +216,7 @@ static av_cold int frei0r_init(AVFilterContext *ctx,
/* see: http://piksel.org/frei0r/1.2/spec/1.2/spec/group__pluglocations.html */
if ((path = av_strdup(getenv("FREI0R_PATH")))) {
char *p, *ptr = NULL;
- for (p = path; p = strtok_r(p, ":", &ptr); p = NULL)
+ for (p = path; p = av_strtok(p, ":", &ptr); p = NULL)
if (frei0r->dl_handle = load_path(ctx, p, dl_name))
break;
av_free(path);
@@ -332,7 +333,7 @@ static int query_formats(AVFilterContext *ctx)
if (!formats)
return AVERROR(ENOMEM);
- avfilter_set_common_formats(ctx, formats);
+ avfilter_set_common_pixel_formats(ctx, formats);
return 0;
}
@@ -430,7 +431,7 @@ static int source_request_frame(AVFilterLink *outlink)
{
Frei0rContext *frei0r = outlink->src->priv;
AVFilterBufferRef *picref = avfilter_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h);
- picref->video->pixel_aspect = (AVRational) {1, 1};
+ picref->video->sample_aspect_ratio = (AVRational) {1, 1};
picref->pts = frei0r->pts++;
picref->pos = -1;
diff --git a/libavfilter/vf_gradfun.c b/libavfilter/vf_gradfun.c
index c6663c4102..084dcc5c3c 100644
--- a/libavfilter/vf_gradfun.c
+++ b/libavfilter/vf_gradfun.c
@@ -2,20 +2,20 @@
* Copyright (c) 2010 Nolan Lum <nol888@gmail.com>
* Copyright (c) 2009 Loren Merritt <lorenm@u.washignton.edu>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -49,7 +49,7 @@ DECLARE_ALIGNED(16, static const uint16_t, dither)[8][8] = {
{0x54,0x34,0x4C,0x2C,0x52,0x32,0x4A,0x2A},
};
-void ff_gradfun_filter_line_c(uint8_t *dst, uint8_t *src, uint16_t *dc, int width, int thresh, const uint16_t *dithers)
+void ff_gradfun_filter_line_c(uint8_t *dst, const uint8_t *src, const uint16_t *dc, int width, int thresh, const uint16_t *dithers)
{
int x;
for (x = 0; x < width; x++, dc += x & 1) {
@@ -63,7 +63,7 @@ void ff_gradfun_filter_line_c(uint8_t *dst, uint8_t *src, uint16_t *dc, int widt
}
}
-void ff_gradfun_blur_line_c(uint16_t *dc, uint16_t *buf, uint16_t *buf1, uint8_t *src, int src_linesize, int width)
+void ff_gradfun_blur_line_c(uint16_t *dc, uint16_t *buf, const uint16_t *buf1, const uint8_t *src, int src_linesize, int width)
{
int x, v, old;
for (x = 0; x < width; x++) {
@@ -74,7 +74,7 @@ void ff_gradfun_blur_line_c(uint16_t *dc, uint16_t *buf, uint16_t *buf1, uint8_t
}
}
-static void filter(GradFunContext *ctx, uint8_t *dst, uint8_t *src, int width, int height, int dst_linesize, int src_linesize, int r)
+static void filter(GradFunContext *ctx, uint8_t *dst, const uint8_t *src, int width, int height, int dst_linesize, int src_linesize, int r)
{
int bstride = FFALIGN(width, 16) / 2;
int y;
@@ -160,7 +160,7 @@ static int query_formats(AVFilterContext *ctx)
PIX_FMT_NONE
};
- avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts));
+ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts));
return 0;
}
diff --git a/libavfilter/vf_hflip.c b/libavfilter/vf_hflip.c
index fb8911f851..9b995a9894 100644
--- a/libavfilter/vf_hflip.c
+++ b/libavfilter/vf_hflip.c
@@ -2,20 +2,20 @@
* Copyright (c) 2007 Benoit Fouet
* Copyright (c) 2010 Stefano Sabatini
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -62,7 +62,7 @@ static int query_formats(AVFilterContext *ctx)
PIX_FMT_NONE
};
- avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts));
+ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts));
return 0;
}
diff --git a/libavfilter/vf_hqdn3d.c b/libavfilter/vf_hqdn3d.c
index 2e9a89510b..993ce7623d 100644
--- a/libavfilter/vf_hqdn3d.c
+++ b/libavfilter/vf_hqdn3d.c
@@ -2,20 +2,20 @@
* Copyright (c) 2003 Daniel Moreno <comac AT comac DOT darktech DOT org>
* Copyright (c) 2010 Baptiste Coudurier
*
- * This file is part of Libav, ported from MPlayer.
+ * This file is part of FFmpeg, ported from MPlayer.
*
- * Libav is free software; you can redistribute it and/or modify
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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 Libav; if not, write to the Free Software Foundation, Inc.,
+ * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
@@ -268,7 +268,7 @@ static int query_formats(AVFilterContext *ctx)
PIX_FMT_YUV420P, PIX_FMT_YUV422P, PIX_FMT_YUV411P, PIX_FMT_NONE
};
- avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts));
+ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts));
return 0;
}
diff --git a/libavfilter/vf_libopencv.c b/libavfilter/vf_libopencv.c
index 5a52f246ba..e1b51c52c2 100644
--- a/libavfilter/vf_libopencv.c
+++ b/libavfilter/vf_libopencv.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2010 Stefano Sabatini
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -26,7 +26,7 @@
/* #define DEBUG */
#include <opencv/cv.h>
-#include <opencv/cxtypes.h>
+#include <opencv/cxcore.h>
#include "libavutil/avstring.h"
#include "libavutil/file.h"
#include "avfilter.h"
@@ -61,7 +61,7 @@ static int query_formats(AVFilterContext *ctx)
PIX_FMT_BGR24, PIX_FMT_BGRA, PIX_FMT_GRAY8, PIX_FMT_NONE
};
- avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts));
+ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts));
return 0;
}
diff --git a/libavfilter/vf_lut.c b/libavfilter/vf_lut.c
new file mode 100644
index 0000000000..211a294e43
--- /dev/null
+++ b/libavfilter/vf_lut.c
@@ -0,0 +1,383 @@
+/*
+ * Copyright (c) 2011 Stefano Sabatini
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * Compute a look-up table for binding the input value to the output
+ * value, and apply it to input video.
+ */
+
+#include "libavutil/eval.h"
+#include "libavutil/opt.h"
+#include "libavutil/pixdesc.h"
+#include "avfilter.h"
+#include "internal.h"
+
+static const char *var_names[] = {
+ "w", ///< width of the input video
+ "h", ///< height of the input video
+ "val", ///< input value for the pixel
+ "maxval", ///< max value for the pixel
+ "minval", ///< min value for the pixel
+ "negval", ///< negated value
+ "clipval",
+ NULL
+};
+
+enum var_name {
+ VAR_W,
+ VAR_H,
+ VAR_VAL,
+ VAR_MAXVAL,
+ VAR_MINVAL,
+ VAR_NEGVAL,
+ VAR_CLIPVAL,
+ VAR_VARS_NB
+};
+
+typedef struct {
+ const AVClass *class;
+ uint8_t lut[4][256]; ///< lookup table for each component
+ char *comp_expr_str[4];
+ AVExpr *comp_expr[4];
+ int hsub, vsub;
+ double var_values[VAR_VARS_NB];
+ int is_rgb, is_yuv;
+ int rgba_map[4];
+ int step;
+ int negate_alpha; /* only used by negate */
+} LutContext;
+
+#define Y 0
+#define U 1
+#define V 2
+#define R 0
+#define G 1
+#define B 2
+#define A 3
+
+#define OFFSET(x) offsetof(LutContext, x)
+
+static const AVOption lut_options[] = {
+ {"c0", "set component #0 expression", OFFSET(comp_expr_str[0]), AV_OPT_TYPE_STRING, {.str="val"}, CHAR_MIN, CHAR_MAX},
+ {"c1", "set component #1 expression", OFFSET(comp_expr_str[1]), AV_OPT_TYPE_STRING, {.str="val"}, CHAR_MIN, CHAR_MAX},
+ {"c2", "set component #2 expression", OFFSET(comp_expr_str[2]), AV_OPT_TYPE_STRING, {.str="val"}, CHAR_MIN, CHAR_MAX},
+ {"c3", "set component #3 expression", OFFSET(comp_expr_str[3]), AV_OPT_TYPE_STRING, {.str="val"}, CHAR_MIN, CHAR_MAX},
+ {"y", "set Y expression", OFFSET(comp_expr_str[Y]), AV_OPT_TYPE_STRING, {.str="val"}, CHAR_MIN, CHAR_MAX},
+ {"u", "set U expression", OFFSET(comp_expr_str[U]), AV_OPT_TYPE_STRING, {.str="val"}, CHAR_MIN, CHAR_MAX},
+ {"v", "set V expression", OFFSET(comp_expr_str[V]), AV_OPT_TYPE_STRING, {.str="val"}, CHAR_MIN, CHAR_MAX},
+ {"r", "set R expression", OFFSET(comp_expr_str[R]), AV_OPT_TYPE_STRING, {.str="val"}, CHAR_MIN, CHAR_MAX},
+ {"g", "set G expression", OFFSET(comp_expr_str[G]), AV_OPT_TYPE_STRING, {.str="val"}, CHAR_MIN, CHAR_MAX},
+ {"b", "set B expression", OFFSET(comp_expr_str[B]), AV_OPT_TYPE_STRING, {.str="val"}, CHAR_MIN, CHAR_MAX},
+ {"a", "set A expression", OFFSET(comp_expr_str[A]), AV_OPT_TYPE_STRING, {.str="val"}, CHAR_MIN, CHAR_MAX},
+ {NULL},
+};
+
+static const char *lut_get_name(void *ctx)
+{
+ return "lut";
+}
+
+static const AVClass lut_class = {
+ "LutContext",
+ lut_get_name,
+ lut_options
+};
+
+static int init(AVFilterContext *ctx, const char *args, void *opaque)
+{
+ LutContext *lut = ctx->priv;
+ int ret;
+
+ lut->class = &lut_class;
+ av_opt_set_defaults(lut);
+
+ lut->is_rgb = !strcmp(ctx->filter->name, "lutrgb");
+ lut->is_yuv = !strcmp(ctx->filter->name, "lutyuv");
+ if (args && (ret = av_set_options_string(lut, args, "=", ":")) < 0)
+ return ret;
+
+ return 0;
+}
+
+static av_cold void uninit(AVFilterContext *ctx)
+{
+ LutContext *lut = ctx->priv;
+ int i;
+
+ for (i = 0; i < 4; i++) {
+ av_expr_free(lut->comp_expr[i]);
+ lut->comp_expr[i] = NULL;
+ av_freep(&lut->comp_expr_str[i]);
+ }
+}
+
+#define YUV_FORMATS \
+ PIX_FMT_YUV444P, PIX_FMT_YUV422P, PIX_FMT_YUV420P, \
+ PIX_FMT_YUV411P, PIX_FMT_YUV410P, PIX_FMT_YUV440P, \
+ PIX_FMT_YUVA420P, \
+ PIX_FMT_YUVJ444P, PIX_FMT_YUVJ422P, PIX_FMT_YUVJ420P, \
+ PIX_FMT_YUVJ440P
+
+#define RGB_FORMATS \
+ PIX_FMT_ARGB, PIX_FMT_RGBA, \
+ PIX_FMT_ABGR, PIX_FMT_BGRA, \
+ PIX_FMT_RGB24, PIX_FMT_BGR24
+
+static enum PixelFormat yuv_pix_fmts[] = { YUV_FORMATS, PIX_FMT_NONE };
+static enum PixelFormat rgb_pix_fmts[] = { RGB_FORMATS, PIX_FMT_NONE };
+static enum PixelFormat all_pix_fmts[] = { RGB_FORMATS, YUV_FORMATS, PIX_FMT_NONE };
+
+static int query_formats(AVFilterContext *ctx)
+{
+ LutContext *lut = ctx->priv;
+
+ enum PixelFormat *pix_fmts = lut->is_rgb ? rgb_pix_fmts :
+ lut->is_yuv ? yuv_pix_fmts : all_pix_fmts;
+
+ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts));
+ return 0;
+}
+
+/**
+ * Clip value val in the minval - maxval range.
+ */
+static double clip(void *opaque, double val)
+{
+ LutContext *lut = opaque;
+ double minval = lut->var_values[VAR_MINVAL];
+ double maxval = lut->var_values[VAR_MAXVAL];
+
+ return av_clip(val, minval, maxval);
+}
+
+/**
+ * Compute gamma correction for value val, assuming the minval-maxval
+ * range, val is clipped to a value contained in the same interval.
+ */
+static double compute_gammaval(void *opaque, double gamma)
+{
+ LutContext *lut = opaque;
+ double val = lut->var_values[VAR_CLIPVAL];
+ double minval = lut->var_values[VAR_MINVAL];
+ double maxval = lut->var_values[VAR_MAXVAL];
+
+ return pow((val-minval)/(maxval-minval), gamma) * (maxval-minval)+minval;
+}
+
+static double (* const funcs1[])(void *, double) = {
+ (void *)clip,
+ (void *)compute_gammaval,
+ NULL
+};
+
+static const char * const funcs1_names[] = {
+ "clip",
+ "gammaval",
+ NULL
+};
+
+static int config_props(AVFilterLink *inlink)
+{
+ AVFilterContext *ctx = inlink->dst;
+ LutContext *lut = ctx->priv;
+ const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[inlink->format];
+ int min[4], max[4];
+ int val, comp, ret;
+
+ lut->hsub = desc->log2_chroma_w;
+ lut->vsub = desc->log2_chroma_h;
+
+ lut->var_values[VAR_W] = inlink->w;
+ lut->var_values[VAR_H] = inlink->h;
+
+ switch (inlink->format) {
+ case PIX_FMT_YUV410P:
+ case PIX_FMT_YUV411P:
+ case PIX_FMT_YUV420P:
+ case PIX_FMT_YUV422P:
+ case PIX_FMT_YUV440P:
+ case PIX_FMT_YUV444P:
+ case PIX_FMT_YUVA420P:
+ min[Y] = min[U] = min[V] = 16;
+ max[Y] = 235;
+ max[U] = max[V] = 240;
+ min[A] = 0; max[A] = 255;
+ break;
+ default:
+ min[0] = min[1] = min[2] = min[3] = 0;
+ max[0] = max[1] = max[2] = max[3] = 255;
+ }
+
+ lut->is_yuv = lut->is_rgb = 0;
+ if (ff_fmt_is_in(inlink->format, yuv_pix_fmts)) lut->is_yuv = 1;
+ else if (ff_fmt_is_in(inlink->format, rgb_pix_fmts)) lut->is_rgb = 1;
+
+ if (lut->is_rgb) {
+ switch (inlink->format) {
+ case PIX_FMT_ARGB: lut->rgba_map[A] = 0; lut->rgba_map[R] = 1; lut->rgba_map[G] = 2; lut->rgba_map[B] = 3; break;
+ case PIX_FMT_ABGR: lut->rgba_map[A] = 0; lut->rgba_map[B] = 1; lut->rgba_map[G] = 2; lut->rgba_map[R] = 3; break;
+ case PIX_FMT_RGBA:
+ case PIX_FMT_RGB24: lut->rgba_map[R] = 0; lut->rgba_map[G] = 1; lut->rgba_map[B] = 2; lut->rgba_map[A] = 3; break;
+ case PIX_FMT_BGRA:
+ case PIX_FMT_BGR24: lut->rgba_map[B] = 0; lut->rgba_map[G] = 1; lut->rgba_map[R] = 2; lut->rgba_map[A] = 3; break;
+ }
+ lut->step = av_get_bits_per_pixel(desc) >> 3;
+ }
+
+ for (comp = 0; comp < desc->nb_components; comp++) {
+ double res;
+
+ /* create the parsed expression */
+ ret = av_expr_parse(&lut->comp_expr[comp], lut->comp_expr_str[comp],
+ var_names, funcs1_names, funcs1, NULL, NULL, 0, ctx);
+ if (ret < 0) {
+ av_log(ctx, AV_LOG_ERROR,
+ "Error when parsing the expression '%s' for the component %d.\n",
+ lut->comp_expr_str[comp], comp);
+ return AVERROR(EINVAL);
+ }
+
+ /* compute the lut */
+ lut->var_values[VAR_MAXVAL] = max[comp];
+ lut->var_values[VAR_MINVAL] = min[comp];
+
+ for (val = 0; val < 256; val++) {
+ lut->var_values[VAR_VAL] = val;
+ lut->var_values[VAR_CLIPVAL] = av_clip(val, min[comp], max[comp]);
+ lut->var_values[VAR_NEGVAL] =
+ av_clip(min[comp] + max[comp] - lut->var_values[VAR_VAL],
+ min[comp], max[comp]);
+
+ res = av_expr_eval(lut->comp_expr[comp], lut->var_values, lut);
+ if (isnan(res)) {
+ av_log(ctx, AV_LOG_ERROR,
+ "Error when evaluating the expression '%s' for the value %d for the component #%d.\n",
+ lut->comp_expr_str[comp], val, comp);
+ return AVERROR(EINVAL);
+ }
+ lut->lut[comp][val] = av_clip((int)res, min[comp], max[comp]);
+ av_log(ctx, AV_LOG_DEBUG, "val[%d][%d] = %d\n", comp, val, lut->lut[comp][val]);
+ }
+ }
+
+ return 0;
+}
+
+static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
+{
+ AVFilterContext *ctx = inlink->dst;
+ LutContext *lut = ctx->priv;
+ AVFilterLink *outlink = ctx->outputs[0];
+ AVFilterBufferRef *inpic = inlink ->cur_buf;
+ AVFilterBufferRef *outpic = outlink->out_buf;
+ uint8_t *inrow, *outrow, *inrow0, *outrow0;
+ int i, j, k, plane;
+
+ if (lut->is_rgb) {
+ /* packed */
+ inrow0 = inpic ->data[0] + y * inpic ->linesize[0];
+ outrow0 = outpic->data[0] + y * outpic->linesize[0];
+
+ for (i = 0; i < h; i ++) {
+ inrow = inrow0;
+ outrow = outrow0;
+ for (j = 0; j < inlink->w; j++) {
+ for (k = 0; k < lut->step; k++)
+ outrow[k] = lut->lut[lut->rgba_map[k]][inrow[k]];
+ outrow += lut->step;
+ inrow += lut->step;
+ }
+ inrow0 += inpic ->linesize[0];
+ outrow0 += outpic->linesize[0];
+ }
+ } else {
+ /* planar */
+ for (plane = 0; plane < 4 && inpic->data[plane]; plane++) {
+ int vsub = plane == 1 || plane == 2 ? lut->vsub : 0;
+ int hsub = plane == 1 || plane == 2 ? lut->hsub : 0;
+
+ inrow = inpic ->data[plane] + (y>>vsub) * inpic ->linesize[plane];
+ outrow = outpic->data[plane] + (y>>vsub) * outpic->linesize[plane];
+
+ for (i = 0; i < h>>vsub; i ++) {
+ for (j = 0; j < inlink->w>>hsub; j++)
+ outrow[j] = lut->lut[plane][inrow[j]];
+ inrow += inpic ->linesize[plane];
+ outrow += outpic->linesize[plane];
+ }
+ }
+ }
+
+ avfilter_draw_slice(outlink, y, h, slice_dir);
+}
+
+#define DEFINE_LUT_FILTER(name_, description_, init_) \
+ AVFilter avfilter_vf_##name_ = { \
+ .name = #name_, \
+ .description = NULL_IF_CONFIG_SMALL(description_), \
+ .priv_size = sizeof(LutContext), \
+ \
+ .init = init_, \
+ .uninit = uninit, \
+ .query_formats = query_formats, \
+ \
+ .inputs = (AVFilterPad[]) {{ .name = "default", \
+ .type = AVMEDIA_TYPE_VIDEO, \
+ .draw_slice = draw_slice, \
+ .config_props = config_props, \
+ .min_perms = AV_PERM_READ, }, \
+ { .name = NULL}}, \
+ .outputs = (AVFilterPad[]) {{ .name = "default", \
+ .type = AVMEDIA_TYPE_VIDEO, }, \
+ { .name = NULL}}, \
+ }
+
+#if CONFIG_LUT_FILTER
+DEFINE_LUT_FILTER(lut, "Compute and apply a lookup table to the RGB/YUV input video.", init);
+#endif
+#if CONFIG_LUTYUV_FILTER
+DEFINE_LUT_FILTER(lutyuv, "Compute and apply a lookup table to the YUV input video.", init);
+#endif
+#if CONFIG_LUTRGB_FILTER
+DEFINE_LUT_FILTER(lutrgb, "Compute and apply a lookup table to the RGB input video.", init);
+#endif
+
+#if CONFIG_NEGATE_FILTER
+
+static int negate_init(AVFilterContext *ctx, const char *args, void *opaque)
+{
+ LutContext *lut = ctx->priv;
+ char lut_params[64];
+
+ if (args)
+ sscanf(args, "%d", &lut->negate_alpha);
+
+ av_log(ctx, AV_LOG_DEBUG, "negate_alpha:%d\n", lut->negate_alpha);
+
+ snprintf(lut_params, sizeof(lut_params), "c0=negval:c1=negval:c2=negval:a=%s",
+ lut->negate_alpha ? "negval" : "val");
+
+ return init(ctx, lut_params, opaque);
+}
+
+DEFINE_LUT_FILTER(negate, "Negate input video.", negate_init);
+
+#endif \ No newline at end of file
diff --git a/libavfilter/vf_mp.c b/libavfilter/vf_mp.c
new file mode 100644
index 0000000000..05c3fca9f0
--- /dev/null
+++ b/libavfilter/vf_mp.c
@@ -0,0 +1,900 @@
+/*
+ * Copyright (c) 2011 Michael Niedermayer
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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 FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Parts of this file have been stolen from mplayer
+ */
+
+/**
+ * @file
+ */
+
+#include "avfilter.h"
+#include "libavutil/avassert.h"
+#include "libavutil/pixdesc.h"
+#include "libavutil/intreadwrite.h"
+#include "libavutil/imgutils.h"
+
+#include "libmpcodecs/vf.h"
+#include "libmpcodecs/img_format.h"
+#include "libmpcodecs/cpudetect.h"
+#include "libmpcodecs/vd_ffmpeg.h"
+#include "libmpcodecs/vf_scale.h"
+#include "libmpcodecs/libvo/fastmemcpy.h"
+
+#include "libswscale/swscale.h"
+
+
+//FIXME maybe link the orig in
+//XXX: identical pix_fmt must be following with each others
+static const struct {
+ int fmt;
+ enum PixelFormat pix_fmt;
+} conversion_map[] = {
+ {IMGFMT_ARGB, PIX_FMT_ARGB},
+ {IMGFMT_BGRA, PIX_FMT_BGRA},
+ {IMGFMT_BGR24, PIX_FMT_BGR24},
+ {IMGFMT_BGR16BE, PIX_FMT_RGB565BE},
+ {IMGFMT_BGR16LE, PIX_FMT_RGB565LE},
+ {IMGFMT_BGR15BE, PIX_FMT_RGB555BE},
+ {IMGFMT_BGR15LE, PIX_FMT_RGB555LE},
+ {IMGFMT_BGR12BE, PIX_FMT_RGB444BE},
+ {IMGFMT_BGR12LE, PIX_FMT_RGB444LE},
+ {IMGFMT_BGR8, PIX_FMT_RGB8},
+ {IMGFMT_BGR4, PIX_FMT_RGB4},
+ {IMGFMT_BGR1, PIX_FMT_MONOBLACK},
+ {IMGFMT_RGB1, PIX_FMT_MONOBLACK},
+ {IMGFMT_RG4B, PIX_FMT_BGR4_BYTE},
+ {IMGFMT_BG4B, PIX_FMT_RGB4_BYTE},
+ {IMGFMT_RGB48LE, PIX_FMT_RGB48LE},
+ {IMGFMT_RGB48BE, PIX_FMT_RGB48BE},
+ {IMGFMT_ABGR, PIX_FMT_ABGR},
+ {IMGFMT_RGBA, PIX_FMT_RGBA},
+ {IMGFMT_RGB24, PIX_FMT_RGB24},
+ {IMGFMT_RGB16BE, PIX_FMT_BGR565BE},
+ {IMGFMT_RGB16LE, PIX_FMT_BGR565LE},
+ {IMGFMT_RGB15BE, PIX_FMT_BGR555BE},
+ {IMGFMT_RGB15LE, PIX_FMT_BGR555LE},
+ {IMGFMT_RGB12BE, PIX_FMT_BGR444BE},
+ {IMGFMT_RGB12LE, PIX_FMT_BGR444LE},
+ {IMGFMT_RGB8, PIX_FMT_BGR8},
+ {IMGFMT_RGB4, PIX_FMT_BGR4},
+ {IMGFMT_BGR8, PIX_FMT_PAL8},
+ {IMGFMT_YUY2, PIX_FMT_YUYV422},
+ {IMGFMT_UYVY, PIX_FMT_UYVY422},
+ {IMGFMT_NV12, PIX_FMT_NV12},
+ {IMGFMT_NV21, PIX_FMT_NV21},
+ {IMGFMT_Y800, PIX_FMT_GRAY8},
+ {IMGFMT_Y8, PIX_FMT_GRAY8},
+ {IMGFMT_YVU9, PIX_FMT_YUV410P},
+ {IMGFMT_IF09, PIX_FMT_YUV410P},
+ {IMGFMT_YV12, PIX_FMT_YUV420P},
+ {IMGFMT_I420, PIX_FMT_YUV420P},
+ {IMGFMT_IYUV, PIX_FMT_YUV420P},
+ {IMGFMT_411P, PIX_FMT_YUV411P},
+ {IMGFMT_422P, PIX_FMT_YUV422P},
+ {IMGFMT_444P, PIX_FMT_YUV444P},
+ {IMGFMT_440P, PIX_FMT_YUV440P},
+
+ {IMGFMT_420A, PIX_FMT_YUVA420P},
+
+ {IMGFMT_420P16_LE, PIX_FMT_YUV420P16LE},
+ {IMGFMT_420P16_BE, PIX_FMT_YUV420P16BE},
+ {IMGFMT_422P16_LE, PIX_FMT_YUV422P16LE},
+ {IMGFMT_422P16_BE, PIX_FMT_YUV422P16BE},
+ {IMGFMT_444P16_LE, PIX_FMT_YUV444P16LE},
+ {IMGFMT_444P16_BE, PIX_FMT_YUV444P16BE},
+
+ // YUVJ are YUV formats that use the full Y range and not just
+ // 16 - 235 (see colorspaces.txt).
+ // Currently they are all treated the same way.
+ {IMGFMT_YV12, PIX_FMT_YUVJ420P},
+ {IMGFMT_422P, PIX_FMT_YUVJ422P},
+ {IMGFMT_444P, PIX_FMT_YUVJ444P},
+ {IMGFMT_440P, PIX_FMT_YUVJ440P},
+
+ {IMGFMT_XVMC_MOCO_MPEG2, PIX_FMT_XVMC_MPEG2_MC},
+ {IMGFMT_XVMC_IDCT_MPEG2, PIX_FMT_XVMC_MPEG2_IDCT},
+ {IMGFMT_VDPAU_MPEG1, PIX_FMT_VDPAU_MPEG1},
+ {IMGFMT_VDPAU_MPEG2, PIX_FMT_VDPAU_MPEG2},
+ {IMGFMT_VDPAU_H264, PIX_FMT_VDPAU_H264},
+ {IMGFMT_VDPAU_WMV3, PIX_FMT_VDPAU_WMV3},
+ {IMGFMT_VDPAU_VC1, PIX_FMT_VDPAU_VC1},
+ {IMGFMT_VDPAU_MPEG4, PIX_FMT_VDPAU_MPEG4},
+ {0, PIX_FMT_NONE}
+};
+
+//copied from vf.c
+extern const vf_info_t vf_info_1bpp;
+extern const vf_info_t vf_info_2xsai;
+extern const vf_info_t vf_info_ass;
+extern const vf_info_t vf_info_bmovl;
+extern const vf_info_t vf_info_crop;
+extern const vf_info_t vf_info_decimate;
+extern const vf_info_t vf_info_denoise3d;
+extern const vf_info_t vf_info_detc;
+extern const vf_info_t vf_info_dint;
+extern const vf_info_t vf_info_divtc;
+extern const vf_info_t vf_info_down3dright;
+extern const vf_info_t vf_info_dsize;
+extern const vf_info_t vf_info_dvbscale;
+extern const vf_info_t vf_info_eq2;
+extern const vf_info_t vf_info_eq;
+extern const vf_info_t vf_info_expand;
+extern const vf_info_t vf_info_field;
+extern const vf_info_t vf_info_fil;
+extern const vf_info_t vf_info_filmdint;
+extern const vf_info_t vf_info_fixpts;
+extern const vf_info_t vf_info_flip;
+extern const vf_info_t vf_info_format;
+extern const vf_info_t vf_info_framestep;
+extern const vf_info_t vf_info_fspp;
+extern const vf_info_t vf_info_geq;
+extern const vf_info_t vf_info_halfpack;
+extern const vf_info_t vf_info_harddup;
+extern const vf_info_t vf_info_hqdn3d;
+extern const vf_info_t vf_info_hue;
+extern const vf_info_t vf_info_il;
+extern const vf_info_t vf_info_ilpack;
+extern const vf_info_t vf_info_ivtc;
+extern const vf_info_t vf_info_kerndeint;
+extern const vf_info_t vf_info_lavc;
+extern const vf_info_t vf_info_lavcdeint;
+extern const vf_info_t vf_info_mcdeint;
+extern const vf_info_t vf_info_mirror;
+extern const vf_info_t vf_info_noformat;
+extern const vf_info_t vf_info_noise;
+extern const vf_info_t vf_info_ow;
+extern const vf_info_t vf_info_palette;
+extern const vf_info_t vf_info_perspective;
+extern const vf_info_t vf_info_phase;
+extern const vf_info_t vf_info_pp7;
+extern const vf_info_t vf_info_pp;
+extern const vf_info_t vf_info_pullup;
+extern const vf_info_t vf_info_qp;
+extern const vf_info_t vf_info_rectangle;
+extern const vf_info_t vf_info_remove_logo;
+extern const vf_info_t vf_info_rotate;
+extern const vf_info_t vf_info_sab;
+extern const vf_info_t vf_info_scale;
+extern const vf_info_t vf_info_screenshot;
+extern const vf_info_t vf_info_smartblur;
+extern const vf_info_t vf_info_softpulldown;
+extern const vf_info_t vf_info_softskip;
+extern const vf_info_t vf_info_spp;
+extern const vf_info_t vf_info_stereo3d;
+extern const vf_info_t vf_info_swapuv;
+extern const vf_info_t vf_info_telecine;
+extern const vf_info_t vf_info_test;
+extern const vf_info_t vf_info_tfields;
+extern const vf_info_t vf_info_tile;
+extern const vf_info_t vf_info_tinterlace;
+extern const vf_info_t vf_info_unsharp;
+extern const vf_info_t vf_info_uspp;
+extern const vf_info_t vf_info_vo;
+extern const vf_info_t vf_info_yadif;
+extern const vf_info_t vf_info_yuvcsp;
+extern const vf_info_t vf_info_yvu9;
+extern const vf_info_t vf_info_zrmjpeg;
+
+
+static const vf_info_t* const filters[]={
+ &vf_info_2xsai,
+ &vf_info_decimate,
+ &vf_info_denoise3d,
+ &vf_info_detc,
+ &vf_info_dint,
+ &vf_info_divtc,
+ &vf_info_down3dright,
+ &vf_info_dsize,
+ &vf_info_eq2,
+ &vf_info_eq,
+ &vf_info_field,
+ &vf_info_fil,
+// &vf_info_filmdint, cmmx.h vd.h ‘opt_screen_size_x’
+ &vf_info_fixpts,
+ &vf_info_framestep,
+ &vf_info_fspp,
+ &vf_info_geq,
+ &vf_info_harddup,
+ &vf_info_hqdn3d,
+ &vf_info_hue,
+ &vf_info_il,
+ &vf_info_ilpack,
+ &vf_info_ivtc,
+ &vf_info_kerndeint,
+ &vf_info_mcdeint,
+ &vf_info_mirror,
+ &vf_info_noise,
+ &vf_info_ow,
+ &vf_info_palette,
+ &vf_info_perspective,
+ &vf_info_phase,
+ &vf_info_pp7,
+ &vf_info_pullup,
+ &vf_info_qp,
+ &vf_info_rectangle,
+ &vf_info_remove_logo,
+ &vf_info_rotate,
+ &vf_info_sab,
+ &vf_info_screenshot,
+ &vf_info_smartblur,
+ &vf_info_softpulldown,
+ &vf_info_softskip,
+ &vf_info_spp,
+ &vf_info_stereo3d,
+ &vf_info_swapuv,
+ &vf_info_telecine,
+ &vf_info_tile,
+ &vf_info_tinterlace,
+ &vf_info_unsharp,
+ &vf_info_uspp,
+ &vf_info_yuvcsp,
+ &vf_info_yvu9,
+
+ NULL
+};
+
+/*
+Unsupported filters
+1bpp
+ass
+bmovl
+crop
+dvbscale
+flip
+expand
+format
+halfpack
+lavc
+lavcdeint
+noformat
+pp
+scale
+tfields
+vo
+yadif
+zrmjpeg
+*/
+
+CpuCaps gCpuCaps; //FIXME initialize this so optims work
+
+
+static void sws_getFlagsAndFilterFromCmdLine(int *flags, SwsFilter **srcFilterParam, SwsFilter **dstFilterParam)
+{
+ static int firstTime=1;
+ *flags=0;
+
+#if ARCH_X86
+ if(gCpuCaps.hasMMX)
+ __asm__ volatile("emms\n\t"::: "memory"); //FIXME this should not be required but it IS (even for non-MMX versions)
+#endif
+ if(firstTime)
+ {
+ firstTime=0;
+ *flags= SWS_PRINT_INFO;
+ }
+ else if( mp_msg_test(MSGT_VFILTER,MSGL_DBG2) ) *flags= SWS_PRINT_INFO;
+
+ switch(SWS_BILINEAR)
+ {
+ case 0: *flags|= SWS_FAST_BILINEAR; break;
+ case 1: *flags|= SWS_BILINEAR; break;
+ case 2: *flags|= SWS_BICUBIC; break;
+ case 3: *flags|= SWS_X; break;
+ case 4: *flags|= SWS_POINT; break;
+ case 5: *flags|= SWS_AREA; break;
+ case 6: *flags|= SWS_BICUBLIN; break;
+ case 7: *flags|= SWS_GAUSS; break;
+ case 8: *flags|= SWS_SINC; break;
+ case 9: *flags|= SWS_LANCZOS; break;
+ case 10:*flags|= SWS_SPLINE; break;
+ default:*flags|= SWS_BILINEAR; break;
+ }
+
+ *srcFilterParam= NULL;
+ *dstFilterParam= NULL;
+}
+
+//exact copy from vf_scale.c
+// will use sws_flags & src_filter (from cmd line)
+struct SwsContext *sws_getContextFromCmdLine(int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat)
+{
+ int flags, i;
+ SwsFilter *dstFilterParam, *srcFilterParam;
+ enum PixelFormat dfmt, sfmt;
+
+ for(i=0; conversion_map[i].fmt && dstFormat != conversion_map[i].fmt; i++);
+ dfmt= conversion_map[i].pix_fmt;
+ for(i=0; conversion_map[i].fmt && srcFormat != conversion_map[i].fmt; i++);
+ sfmt= conversion_map[i].pix_fmt;
+
+ if (srcFormat == IMGFMT_RGB8 || srcFormat == IMGFMT_BGR8) sfmt = PIX_FMT_PAL8;
+ sws_getFlagsAndFilterFromCmdLine(&flags, &srcFilterParam, &dstFilterParam);
+
+ return sws_getContext(srcW, srcH, sfmt, dstW, dstH, dfmt, flags , srcFilterParam, dstFilterParam, NULL);
+}
+
+typedef struct {
+ vf_instance_t vf;
+ vf_instance_t next_vf;
+ AVFilterContext *avfctx;
+ int frame_returned;
+} MPContext;
+
+void mp_msg(int mod, int lev, const char *format, ... ){
+ va_list va;
+ va_start(va, format);
+ //FIXME convert lev/mod
+ av_vlog(NULL, AV_LOG_DEBUG, format, va);
+ va_end(va);
+}
+
+int mp_msg_test(int mod, int lev){
+ return 123;
+}
+
+void init_avcodec(void)
+{
+ //we maybe should init but its kinda 1. unneeded 2. a bit inpolite from here
+}
+
+//Exact copy of vf.c
+void vf_clone_mpi_attributes(mp_image_t* dst, mp_image_t* src){
+ dst->pict_type= src->pict_type;
+ dst->fields = src->fields;
+ dst->qscale_type= src->qscale_type;
+ if(dst->width == src->width && dst->height == src->height){
+ dst->qstride= src->qstride;
+ dst->qscale= src->qscale;
+ }
+}
+
+//Exact copy of vf.c
+void vf_next_draw_slice(struct vf_instance *vf,unsigned char** src, int * stride,int w, int h, int x, int y){
+ if (vf->next->draw_slice) {
+ vf->next->draw_slice(vf->next,src,stride,w,h,x,y);
+ return;
+ }
+ if (!vf->dmpi) {
+ mp_msg(MSGT_VFILTER,MSGL_ERR,"draw_slice: dmpi not stored by vf_%s\n", vf->info->name);
+ return;
+ }
+ if (!(vf->dmpi->flags & MP_IMGFLAG_PLANAR)) {
+ memcpy_pic(vf->dmpi->planes[0]+y*vf->dmpi->stride[0]+vf->dmpi->bpp/8*x,
+ src[0], vf->dmpi->bpp/8*w, h, vf->dmpi->stride[0], stride[0]);
+ return;
+ }
+ memcpy_pic(vf->dmpi->planes[0]+y*vf->dmpi->stride[0]+x, src[0],
+ w, h, vf->dmpi->stride[0], stride[0]);
+ memcpy_pic(vf->dmpi->planes[1]+(y>>vf->dmpi->chroma_y_shift)*vf->dmpi->stride[1]+(x>>vf->dmpi->chroma_x_shift),
+ src[1], w>>vf->dmpi->chroma_x_shift, h>>vf->dmpi->chroma_y_shift, vf->dmpi->stride[1], stride[1]);
+ memcpy_pic(vf->dmpi->planes[2]+(y>>vf->dmpi->chroma_y_shift)*vf->dmpi->stride[2]+(x>>vf->dmpi->chroma_x_shift),
+ src[2], w>>vf->dmpi->chroma_x_shift, h>>vf->dmpi->chroma_y_shift, vf->dmpi->stride[2], stride[2]);
+}
+
+//Exact copy of vf.c
+void vf_mpi_clear(mp_image_t* mpi,int x0,int y0,int w,int h){
+ int y;
+ if(mpi->flags&MP_IMGFLAG_PLANAR){
+ y0&=~1;h+=h&1;
+ if(x0==0 && w==mpi->width){
+ // full width clear:
+ memset(mpi->planes[0]+mpi->stride[0]*y0,0,mpi->stride[0]*h);
+ memset(mpi->planes[1]+mpi->stride[1]*(y0>>mpi->chroma_y_shift),128,mpi->stride[1]*(h>>mpi->chroma_y_shift));
+ memset(mpi->planes[2]+mpi->stride[2]*(y0>>mpi->chroma_y_shift),128,mpi->stride[2]*(h>>mpi->chroma_y_shift));
+ } else
+ for(y=y0;y<y0+h;y+=2){
+ memset(mpi->planes[0]+x0+mpi->stride[0]*y,0,w);
+ memset(mpi->planes[0]+x0+mpi->stride[0]*(y+1),0,w);
+ memset(mpi->planes[1]+(x0>>mpi->chroma_x_shift)+mpi->stride[1]*(y>>mpi->chroma_y_shift),128,(w>>mpi->chroma_x_shift));
+ memset(mpi->planes[2]+(x0>>mpi->chroma_x_shift)+mpi->stride[2]*(y>>mpi->chroma_y_shift),128,(w>>mpi->chroma_x_shift));
+ }
+ return;
+ }
+ // packed:
+ for(y=y0;y<y0+h;y++){
+ unsigned char* dst=mpi->planes[0]+mpi->stride[0]*y+(mpi->bpp>>3)*x0;
+ if(mpi->flags&MP_IMGFLAG_YUV){
+ unsigned int* p=(unsigned int*) dst;
+ int size=(mpi->bpp>>3)*w/4;
+ int i;
+#if HAVE_BIGENDIAN
+#define CLEAR_PACKEDYUV_PATTERN 0x00800080
+#define CLEAR_PACKEDYUV_PATTERN_SWAPPED 0x80008000
+#else
+#define CLEAR_PACKEDYUV_PATTERN 0x80008000
+#define CLEAR_PACKEDYUV_PATTERN_SWAPPED 0x00800080
+#endif
+ if(mpi->flags&MP_IMGFLAG_SWAPPED){
+ for(i=0;i<size-3;i+=4) p[i]=p[i+1]=p[i+2]=p[i+3]=CLEAR_PACKEDYUV_PATTERN_SWAPPED;
+ for(;i<size;i++) p[i]=CLEAR_PACKEDYUV_PATTERN_SWAPPED;
+ } else {
+ for(i=0;i<size-3;i+=4) p[i]=p[i+1]=p[i+2]=p[i+3]=CLEAR_PACKEDYUV_PATTERN;
+ for(;i<size;i++) p[i]=CLEAR_PACKEDYUV_PATTERN;
+ }
+ } else
+ memset(dst,0,(mpi->bpp>>3)*w);
+ }
+}
+
+int vf_next_query_format(struct vf_instance *vf, unsigned int fmt){
+ return 1;
+}
+
+//used by delogo
+unsigned int vf_match_csp(vf_instance_t** vfp,const unsigned int* list,unsigned int preferred){
+ return preferred;
+}
+
+mp_image_t* vf_get_image(vf_instance_t* vf, unsigned int outfmt, int mp_imgtype, int mp_imgflag, int w, int h){
+ MPContext *m= (MPContext*)(((uint8_t*)vf) - offsetof(MPContext, next_vf));
+ mp_image_t* mpi=NULL;
+ int w2;
+ int number = mp_imgtype >> 16;
+
+ av_assert0(vf->next == NULL); // all existing filters call this just on next
+
+ //vf_dint needs these as it calls vf_get_image() before configuring the output
+ if(vf->w==0 && w>0) vf->w=w;
+ if(vf->h==0 && h>0) vf->h=h;
+
+ av_assert0(w == -1 || w >= vf->w);
+ av_assert0(h == -1 || h >= vf->h);
+ av_assert0(vf->w > 0);
+ av_assert0(vf->h > 0);
+
+ av_log(m->avfctx, AV_LOG_DEBUG, "get_image: %d:%d, vf: %d:%d\n", w,h,vf->w,vf->h);
+
+ if (w == -1) w = vf->w;
+ if (h == -1) h = vf->h;
+
+ w2=(mp_imgflag&MP_IMGFLAG_ACCEPT_ALIGNED_STRIDE)?((w+15)&(~15)):w;
+
+ // Note: we should call libvo first to check if it supports direct rendering
+ // and if not, then fallback to software buffers:
+ switch(mp_imgtype & 0xff){
+ case MP_IMGTYPE_EXPORT:
+ if(!vf->imgctx.export_images[0]) vf->imgctx.export_images[0]=new_mp_image(w2,h);
+ mpi=vf->imgctx.export_images[0];
+ break;
+ case MP_IMGTYPE_STATIC:
+ if(!vf->imgctx.static_images[0]) vf->imgctx.static_images[0]=new_mp_image(w2,h);
+ mpi=vf->imgctx.static_images[0];
+ break;
+ case MP_IMGTYPE_TEMP:
+ if(!vf->imgctx.temp_images[0]) vf->imgctx.temp_images[0]=new_mp_image(w2,h);
+ mpi=vf->imgctx.temp_images[0];
+ break;
+ case MP_IMGTYPE_IPB:
+ if(!(mp_imgflag&MP_IMGFLAG_READABLE)){ // B frame:
+ if(!vf->imgctx.temp_images[0]) vf->imgctx.temp_images[0]=new_mp_image(w2,h);
+ mpi=vf->imgctx.temp_images[0];
+ break;
+ }
+ case MP_IMGTYPE_IP:
+ if(!vf->imgctx.static_images[vf->imgctx.static_idx]) vf->imgctx.static_images[vf->imgctx.static_idx]=new_mp_image(w2,h);
+ mpi=vf->imgctx.static_images[vf->imgctx.static_idx];
+ vf->imgctx.static_idx^=1;
+ break;
+ case MP_IMGTYPE_NUMBERED:
+ if (number == -1) {
+ int i;
+ for (i = 0; i < NUM_NUMBERED_MPI; i++)
+ if (!vf->imgctx.numbered_images[i] || !vf->imgctx.numbered_images[i]->usage_count)
+ break;
+ number = i;
+ }
+ if (number < 0 || number >= NUM_NUMBERED_MPI) return NULL;
+ if (!vf->imgctx.numbered_images[number]) vf->imgctx.numbered_images[number] = new_mp_image(w2,h);
+ mpi = vf->imgctx.numbered_images[number];
+ mpi->number = number;
+ break;
+ }
+ if(mpi){
+ mpi->type=mp_imgtype;
+ mpi->w=vf->w; mpi->h=vf->h;
+ // keep buffer allocation status & color flags only:
+// mpi->flags&=~(MP_IMGFLAG_PRESERVE|MP_IMGFLAG_READABLE|MP_IMGFLAG_DIRECT);
+ mpi->flags&=MP_IMGFLAG_ALLOCATED|MP_IMGFLAG_TYPE_DISPLAYED|MP_IMGFLAGMASK_COLORS;
+ // accept restrictions, draw_slice and palette flags only:
+ mpi->flags|=mp_imgflag&(MP_IMGFLAGMASK_RESTRICTIONS|MP_IMGFLAG_DRAW_CALLBACK|MP_IMGFLAG_RGB_PALETTE);
+ if(!vf->draw_slice) mpi->flags&=~MP_IMGFLAG_DRAW_CALLBACK;
+ if(mpi->width!=w2 || mpi->height!=h){
+// printf("vf.c: MPI parameters changed! %dx%d -> %dx%d \n", mpi->width,mpi->height,w2,h);
+ if(mpi->flags&MP_IMGFLAG_ALLOCATED){
+ if(mpi->width<w2 || mpi->height<h){
+ // need to re-allocate buffer memory:
+ av_free(mpi->planes[0]);
+ mpi->flags&=~MP_IMGFLAG_ALLOCATED;
+ mp_msg(MSGT_VFILTER,MSGL_V,"vf.c: have to REALLOCATE buffer memory :(\n");
+ }
+// } else {
+ } {
+ mpi->width=w2; mpi->chroma_width=(w2 + (1<<mpi->chroma_x_shift) - 1)>>mpi->chroma_x_shift;
+ mpi->height=h; mpi->chroma_height=(h + (1<<mpi->chroma_y_shift) - 1)>>mpi->chroma_y_shift;
+ }
+ }
+ if(!mpi->bpp) mp_image_setfmt(mpi,outfmt);
+ if(!(mpi->flags&MP_IMGFLAG_ALLOCATED) && mpi->type>MP_IMGTYPE_EXPORT){
+
+ av_assert0(!vf->get_image);
+ // check libvo first!
+ if(vf->get_image) vf->get_image(vf,mpi);
+
+ if(!(mpi->flags&MP_IMGFLAG_DIRECT)){
+ // non-direct and not yet allocated image. allocate it!
+ if (!mpi->bpp) { // no way we can allocate this
+ mp_msg(MSGT_DECVIDEO, MSGL_FATAL,
+ "vf_get_image: Tried to allocate a format that can not be allocated!\n");
+ return NULL;
+ }
+
+ // check if codec prefer aligned stride:
+ if(mp_imgflag&MP_IMGFLAG_PREFER_ALIGNED_STRIDE){
+ int align=(mpi->flags&MP_IMGFLAG_PLANAR &&
+ mpi->flags&MP_IMGFLAG_YUV) ?
+ (8<<mpi->chroma_x_shift)-1 : 15; // -- maybe FIXME
+ w2=((w+align)&(~align));
+ if(mpi->width!=w2){
+#if 0
+ // we have to change width... check if we CAN co it:
+ int flags=vf->query_format(vf,outfmt); // should not fail
+ if(!(flags&3)) mp_msg(MSGT_DECVIDEO,MSGL_WARN,"??? vf_get_image{vf->query_format(outfmt)} failed!\n");
+// printf("query -> 0x%X \n",flags);
+ if(flags&VFCAP_ACCEPT_STRIDE){
+#endif
+ mpi->width=w2;
+ mpi->chroma_width=(w2 + (1<<mpi->chroma_x_shift) - 1)>>mpi->chroma_x_shift;
+// }
+ }
+ }
+
+ mp_image_alloc_planes(mpi);
+// printf("clearing img!\n");
+ vf_mpi_clear(mpi,0,0,mpi->width,mpi->height);
+ }
+ }
+ av_assert0(!vf->start_slice);
+ if(mpi->flags&MP_IMGFLAG_DRAW_CALLBACK)
+ if(vf->start_slice) vf->start_slice(vf,mpi);
+ if(!(mpi->flags&MP_IMGFLAG_TYPE_DISPLAYED)){
+ mp_msg(MSGT_DECVIDEO,MSGL_V,"*** [%s] %s%s mp_image_t, %dx%dx%dbpp %s %s, %d bytes\n",
+ "NULL"/*vf->info->name*/,
+ (mpi->type==MP_IMGTYPE_EXPORT)?"Exporting":
+ ((mpi->flags&MP_IMGFLAG_DIRECT)?"Direct Rendering":"Allocating"),
+ (mpi->flags&MP_IMGFLAG_DRAW_CALLBACK)?" (slices)":"",
+ mpi->width,mpi->height,mpi->bpp,
+ (mpi->flags&MP_IMGFLAG_YUV)?"YUV":((mpi->flags&MP_IMGFLAG_SWAPPED)?"BGR":"RGB"),
+ (mpi->flags&MP_IMGFLAG_PLANAR)?"planar":"packed",
+ mpi->bpp*mpi->width*mpi->height/8);
+ mp_msg(MSGT_DECVIDEO,MSGL_DBG2,"(imgfmt: %x, planes: %p,%p,%p strides: %d,%d,%d, chroma: %dx%d, shift: h:%d,v:%d)\n",
+ mpi->imgfmt, mpi->planes[0], mpi->planes[1], mpi->planes[2],
+ mpi->stride[0], mpi->stride[1], mpi->stride[2],
+ mpi->chroma_width, mpi->chroma_height, mpi->chroma_x_shift, mpi->chroma_y_shift);
+ mpi->flags|=MP_IMGFLAG_TYPE_DISPLAYED;
+ }
+
+ mpi->qscale = NULL;
+ }
+ mpi->usage_count++;
+// printf("\rVF_MPI: %p %p %p %d %d %d \n",
+// mpi->planes[0],mpi->planes[1],mpi->planes[2],
+// mpi->stride[0],mpi->stride[1],mpi->stride[2]);
+ return mpi;
+}
+
+
+int vf_next_put_image(struct vf_instance *vf,mp_image_t *mpi, double pts){
+ MPContext *m= (void*)vf;
+ AVFilterLink *outlink = m->avfctx->outputs[0];
+ AVFilterBuffer *pic = av_mallocz(sizeof(AVFilterBuffer));
+ AVFilterBufferRef *picref = av_mallocz(sizeof(AVFilterBufferRef));
+ int i;
+
+ av_assert0(vf->next);
+
+ av_log(m->avfctx, AV_LOG_DEBUG, "vf_next_put_image\n");
+
+ if (!pic || !picref)
+ goto fail;
+
+ picref->buf = pic;
+ picref->buf->please_use_av_free= (void*)av_free;
+ if (!(picref->video = av_mallocz(sizeof(AVFilterBufferRefVideoProps))))
+ goto fail;
+
+ pic->w = picref->video->w = mpi->w;
+ pic->h = picref->video->h = mpi->h;
+
+ /* make sure the buffer gets read permission or it's useless for output */
+ picref->perms = AV_PERM_READ | AV_PERM_REUSE2;
+// av_assert0(mpi->flags&MP_IMGFLAG_READABLE);
+ if(!(mpi->flags&MP_IMGFLAG_PRESERVE))
+ picref->perms |= AV_PERM_WRITE;
+
+ pic->refcount = 1;
+ picref->type = AVMEDIA_TYPE_VIDEO;
+
+ for(i=0; conversion_map[i].fmt && mpi->imgfmt != conversion_map[i].fmt; i++);
+ pic->format = picref->format = conversion_map[i].pix_fmt;
+
+ memcpy(pic->data, mpi->planes, FFMIN(sizeof(pic->data) , sizeof(mpi->planes)));
+ memcpy(pic->linesize, mpi->stride, FFMIN(sizeof(pic->linesize), sizeof(mpi->stride)));
+ memcpy(picref->data, pic->data, sizeof(picref->data));
+ memcpy(picref->linesize, pic->linesize, sizeof(picref->linesize));
+
+ if(pts != MP_NOPTS_VALUE)
+ picref->pts= pts * av_q2d(outlink->time_base);
+
+ avfilter_start_frame(outlink, avfilter_ref_buffer(picref, ~0));
+ avfilter_draw_slice(outlink, 0, picref->video->h, 1);
+ avfilter_end_frame(outlink);
+ avfilter_unref_buffer(picref);
+ m->frame_returned++;
+
+ return 1;
+fail:
+ if (picref && picref->video)
+ av_free(picref->video);
+ av_free(picref);
+ av_free(pic);
+ return 0;
+}
+
+int vf_next_config(struct vf_instance *vf,
+ int width, int height, int d_width, int d_height,
+ unsigned int voflags, unsigned int outfmt){
+
+ av_assert0(width>0 && height>0);
+ vf->next->w = width; vf->next->h = height;
+
+ return 1;
+#if 0
+ int flags=vf->next->query_format(vf->next,outfmt);
+ if(!flags){
+ // hmm. colorspace mismatch!!!
+ //this is fatal for us ATM
+ return 0;
+ }
+ mp_msg(MSGT_VFILTER,MSGL_V,"REQ: flags=0x%X req=0x%X \n",flags,vf->default_reqs);
+ miss=vf->default_reqs - (flags&vf->default_reqs);
+ if(miss&VFCAP_ACCEPT_STRIDE){
+ // vf requires stride support but vf->next doesn't support it!
+ // let's insert the 'expand' filter, it does the job for us:
+ vf_instance_t* vf2=vf_open_filter(vf->next,"expand",NULL);
+ if(!vf2) return 0; // shouldn't happen!
+ vf->next=vf2;
+ }
+ vf->next->w = width; vf->next->h = height;
+#endif
+ return 1;
+}
+
+int vf_next_control(struct vf_instance *vf, int request, void* data){
+ MPContext *m= (void*)vf;
+ av_log(m->avfctx, AV_LOG_DEBUG, "Received control %d\n", request);
+ return 0;
+}
+
+static int vf_default_query_format(struct vf_instance *vf, unsigned int fmt){
+ MPContext *m= (void*)vf;
+ int i;
+ av_log(m->avfctx, AV_LOG_DEBUG, "query %X\n", fmt);
+
+ for(i=0; conversion_map[i].fmt; i++){
+ if(fmt==conversion_map[i].fmt)
+ return 1; //we suport all
+ }
+ return 0;
+}
+
+
+static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
+{
+ MPContext *m = ctx->priv;
+ char name[256];
+ int i;
+
+ av_log(ctx, AV_LOG_WARNING,
+"This is a unholy filter, it will be purified by the ffmpeg exorcist team\n"
+"which will change its syntax from dark -vf mp to light -vf.\n"
+"Thou shalst not make spells or scripts that depend on it\n");
+
+ m->avfctx= ctx;
+
+ if(!args || 1!=sscanf(args, "%255[^:=]", name)){
+ av_log(ctx, AV_LOG_ERROR, "Invalid parameter.\n");
+ return AVERROR(EINVAL);
+ }
+ args+= strlen(name)+1;
+
+ for(i=0; ;i++){
+ if(!filters[i] || !strcmp(name, filters[i]->name))
+ break;
+ }
+
+ if(!filters[i]){
+ av_log(ctx, AV_LOG_ERROR, "Unknown filter %s\n", name);
+ return AVERROR(EINVAL);
+ }
+
+ memset(&m->vf,0,sizeof(m->vf));
+ m->vf.info= filters[i];
+
+ m->vf.next = &m->next_vf;
+ m->vf.put_image = vf_next_put_image;
+ m->vf.config = vf_next_config;
+ m->vf.query_format= vf_default_query_format;
+ m->vf.control = vf_next_control;
+ m->vf.default_caps=VFCAP_ACCEPT_STRIDE;
+ m->vf.default_reqs=0;
+ if(m->vf.info->opts)
+ av_log(ctx, AV_LOG_ERROR, "opts / m_struct_set is unsupported\n");
+#if 0
+ if(vf->info->opts) { // vf_vo get some special argument
+ const m_struct_t* st = vf->info->opts;
+ void* vf_priv = m_struct_alloc(st);
+ int n;
+ for(n = 0 ; args && args[2*n] ; n++)
+ m_struct_set(st,vf_priv,args[2*n],args[2*n+1]);
+ vf->priv = vf_priv;
+ args = NULL;
+ } else // Otherwise we should have the '_oldargs_'
+ if(args && !strcmp(args[0],"_oldargs_"))
+ args = (char**)args[1];
+ else
+ args = NULL;
+#endif
+ if(m->vf.info->vf_open(&m->vf, args)<=0){
+ av_log(ctx, AV_LOG_ERROR, "vf_open() of %s with arg=%s failed\n", name, args);
+ return -1;
+ }
+
+ return 0;
+}
+
+static int query_formats(AVFilterContext *ctx)
+{
+ AVFilterFormats *avfmts=NULL;
+ MPContext *m = ctx->priv;
+ enum PixelFormat lastpixfmt = PIX_FMT_NONE;
+ int i;
+
+ for(i=0; conversion_map[i].fmt; i++){
+ av_log(ctx, AV_LOG_DEBUG, "query: %X\n", conversion_map[i].fmt);
+ if(m->vf.query_format(&m->vf, conversion_map[i].fmt)){
+ av_log(ctx, AV_LOG_DEBUG, "supported,adding\n");
+ if (conversion_map[i].pix_fmt != lastpixfmt) {
+ avfilter_add_format(&avfmts, conversion_map[i].pix_fmt);
+ lastpixfmt = conversion_map[i].pix_fmt;
+ }
+ }
+ }
+
+ //We assume all allowed input formats are also allowed output formats
+ avfilter_set_common_pixel_formats(ctx, avfmts);
+ return 0;
+}
+
+static int config_inprops(AVFilterLink *inlink)
+{
+ MPContext *m = inlink->dst->priv;
+ int i;
+ for(i=0; conversion_map[i].fmt && conversion_map[i].pix_fmt != inlink->format; i++);
+
+ av_assert0(conversion_map[i].fmt && inlink->w && inlink->h);
+
+ m->vf.fmt.have_configured = 1;
+ m->vf.fmt.orig_height = inlink->h;
+ m->vf.fmt.orig_width = inlink->w;
+ m->vf.fmt.orig_fmt = conversion_map[i].fmt;
+
+ if(m->vf.config(&m->vf, inlink->w, inlink->h, inlink->w, inlink->h, 0, conversion_map[i].fmt)<=0)
+ return -1;
+
+ return 0;
+}
+
+static int config_outprops(AVFilterLink *outlink)
+{
+ MPContext *m = outlink->src->priv;
+
+ outlink->w = m->next_vf.w;
+ outlink->h = m->next_vf.h;
+
+ return 0;
+}
+
+static int request_frame(AVFilterLink *outlink)
+{
+ MPContext *m = outlink->src->priv;
+ int ret;
+
+ av_log(m->avfctx, AV_LOG_DEBUG, "mp request_frame\n");
+
+ for(m->frame_returned=0; !m->frame_returned;){
+ ret=avfilter_request_frame(outlink->src->inputs[0]);
+ if(ret<0)
+ break;
+ }
+
+ av_log(m->avfctx, AV_LOG_DEBUG, "mp request_frame ret=%d\n", ret);
+ return ret;
+}
+
+static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
+{
+}
+
+static void null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
+{
+}
+
+static void end_frame(AVFilterLink *inlink)
+{
+ MPContext *m = inlink->dst->priv;
+ AVFilterBufferRef *inpic = inlink->cur_buf;
+ int i;
+ double pts= MP_NOPTS_VALUE;
+ mp_image_t* mpi = new_mp_image(inpic->video->w, inpic->video->h);
+
+ if(inpic->pts != AV_NOPTS_VALUE)
+ pts= inpic->pts / av_q2d(inlink->time_base);
+
+ for(i=0; conversion_map[i].fmt && conversion_map[i].pix_fmt != inlink->format; i++);
+ mp_image_setfmt(mpi,conversion_map[i].fmt);
+
+ memcpy(mpi->planes, inpic->data, FFMIN(sizeof(inpic->data) , sizeof(mpi->planes)));
+ memcpy(mpi->stride, inpic->linesize, FFMIN(sizeof(inpic->linesize), sizeof(mpi->stride)));
+
+ //FIXME pass interleced & tff flags around
+
+ // mpi->flags|=MP_IMGFLAG_ALLOCATED; ?
+ mpi->flags |= MP_IMGFLAG_READABLE;
+ if(!(inpic->perms & AV_PERM_WRITE))
+ mpi->flags |= MP_IMGFLAG_PRESERVE;
+ if(m->vf.put_image(&m->vf, mpi, pts) == 0){
+ av_log(m->avfctx, AV_LOG_DEBUG, "put_image() says skip\n");
+ }
+ free_mp_image(mpi);
+
+ avfilter_unref_buffer(inpic);
+}
+
+AVFilter avfilter_vf_mp = {
+ .name = "mp",
+ .description = NULL_IF_CONFIG_SMALL("libmpcodecs wrapper."),
+ .init = init,
+ .priv_size = sizeof(MPContext),
+ .query_formats = query_formats,
+
+ .inputs = (AVFilterPad[]) {{ .name = "default",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .start_frame = start_frame,
+ .draw_slice = null_draw_slice,
+ .end_frame = end_frame,
+ .config_props = config_inprops,
+ .min_perms = AV_PERM_READ, },
+ { .name = NULL}},
+ .outputs = (AVFilterPad[]) {{ .name = "default",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .request_frame = request_frame,
+ .config_props = config_outprops, },
+ { .name = NULL}},
+};
diff --git a/libavfilter/vf_null.c b/libavfilter/vf_null.c
index 8414c5f4fa..989cd86fc1 100644
--- a/libavfilter/vf_null.c
+++ b/libavfilter/vf_null.c
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavfilter/vf_overlay.c b/libavfilter/vf_overlay.c
index 39b2375235..de63770af3 100644
--- a/libavfilter/vf_overlay.c
+++ b/libavfilter/vf_overlay.c
@@ -3,20 +3,20 @@
* Copyright (c) 2010 Baptiste Coudurier
* Copyright (c) 2007 Bobby Bingham
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -34,9 +34,6 @@
#include "internal.h"
static const char *var_names[] = {
- "E",
- "PHI",
- "PI",
"main_w", "W", ///< width of the main video
"main_h", "H", ///< height of the main video
"overlay_w", "w", ///< width of the overlay video
@@ -45,9 +42,6 @@ static const char *var_names[] = {
};
enum var_name {
- VAR_E,
- VAR_PHI,
- VAR_PI,
VAR_MAIN_W, VAR_MW,
VAR_MAIN_H, VAR_MH,
VAR_OVERLAY_W, VAR_OW,
@@ -126,10 +120,6 @@ static int config_input_overlay(AVFilterLink *inlink)
/* Finish the configuration by evaluating the expressions
now when both inputs are configured. */
- var_values[VAR_E ] = M_E;
- var_values[VAR_PHI] = M_PHI;
- var_values[VAR_PI ] = M_PI;
-
var_values[VAR_MAIN_W ] = var_values[VAR_MW] = ctx->inputs[MAIN ]->w;
var_values[VAR_MAIN_H ] = var_values[VAR_MH] = ctx->inputs[MAIN ]->h;
var_values[VAR_OVERLAY_W] = var_values[VAR_OW] = ctx->inputs[OVERLAY]->w;
diff --git a/libavfilter/vf_pad.c b/libavfilter/vf_pad.c
index 851172c058..e24cda8e0a 100644
--- a/libavfilter/vf_pad.c
+++ b/libavfilter/vf_pad.c
@@ -2,26 +2,26 @@
* Copyright (c) 2008 vmrsss
* Copyright (c) 2009 Stefano Sabatini
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
- * video padding filter and color source
+ * video padding filter
*/
#include "avfilter.h"
@@ -36,9 +36,6 @@
#include "drawutils.h"
static const char *var_names[] = {
- "PI",
- "PHI",
- "E",
"in_w", "iw",
"in_h", "ih",
"out_w", "ow",
@@ -46,15 +43,14 @@ static const char *var_names[] = {
"x",
"y",
"a",
+ "sar",
+ "dar",
"hsub",
"vsub",
NULL
};
enum var_name {
- VAR_PI,
- VAR_PHI,
- VAR_E,
VAR_IN_W, VAR_IW,
VAR_IN_H, VAR_IH,
VAR_OUT_W, VAR_OW,
@@ -62,6 +58,8 @@ enum var_name {
VAR_X,
VAR_Y,
VAR_A,
+ VAR_SAR,
+ VAR_DAR,
VAR_HSUB,
VAR_VSUB,
VARS_NB
@@ -84,7 +82,7 @@ static int query_formats(AVFilterContext *ctx)
PIX_FMT_NONE
};
- avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts));
+ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts));
return 0;
}
@@ -149,16 +147,16 @@ static int config_input(AVFilterLink *inlink)
pad->hsub = pix_desc->log2_chroma_w;
pad->vsub = pix_desc->log2_chroma_h;
- var_values[VAR_PI] = M_PI;
- var_values[VAR_PHI] = M_PHI;
- var_values[VAR_E] = M_E;
var_values[VAR_IN_W] = var_values[VAR_IW] = inlink->w;
var_values[VAR_IN_H] = var_values[VAR_IH] = inlink->h;
var_values[VAR_OUT_W] = var_values[VAR_OW] = NAN;
var_values[VAR_OUT_H] = var_values[VAR_OH] = NAN;
var_values[VAR_A] = (float) inlink->w / inlink->h;
+ var_values[VAR_SAR] = inlink->sample_aspect_ratio.num ?
+ (float) inlink->sample_aspect_ratio.num / inlink->sample_aspect_ratio.den : 1;
+ var_values[VAR_DAR] = var_values[VAR_A] * var_values[VAR_SAR];
var_values[VAR_HSUB] = 1<<pad->hsub;
- var_values[VAR_VSUB] = 2<<pad->vsub;
+ var_values[VAR_VSUB] = 1<<pad->vsub;
/* evaluate width and height */
av_expr_parse_and_eval(&res, (expr = pad->w_expr),
diff --git a/libavfilter/vf_pixdesctest.c b/libavfilter/vf_pixdesctest.c
index 344f6648f1..a6e5d0c60a 100644
--- a/libavfilter/vf_pixdesctest.c
+++ b/libavfilter/vf_pixdesctest.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2009 Stefano Sabatini
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -92,7 +92,7 @@ static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
for (i = y1; i < y1 + h1; i++) {
av_read_image_line(priv->line,
- inpic->data,
+ (void*)inpic->data,
inpic->linesize,
priv->pix_desc,
0, i, c, w1, 0);
diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c
index 9ec686f8f9..8e258fa5e1 100644
--- a/libavfilter/vf_scale.c
+++ b/libavfilter/vf_scale.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2007 Bobby Bingham
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -28,31 +28,30 @@
#include "libavutil/eval.h"
#include "libavutil/mathematics.h"
#include "libavutil/pixdesc.h"
+#include "libavutil/avassert.h"
#include "libswscale/swscale.h"
static const char *var_names[] = {
- "PI",
- "PHI",
- "E",
"in_w", "iw",
"in_h", "ih",
"out_w", "ow",
"out_h", "oh",
"a",
+ "sar",
+ "dar",
"hsub",
"vsub",
NULL
};
enum var_name {
- VAR_PI,
- VAR_PHI,
- VAR_E,
VAR_IN_W, VAR_IW,
VAR_IN_H, VAR_IH,
VAR_OUT_W, VAR_OW,
VAR_OUT_H, VAR_OH,
VAR_A,
+ VAR_SAR,
+ VAR_DAR,
VAR_HSUB,
VAR_VSUB,
VARS_NB
@@ -60,6 +59,7 @@ enum var_name {
typedef struct {
struct SwsContext *sws; ///< software scaler context
+ struct SwsContext *isws[2]; ///< software scaler context for interlaced material
/**
* New dimensions. Special values are:
@@ -72,6 +72,7 @@ typedef struct {
int hsub, vsub; ///< chroma subsampling
int slice_y; ///< top of current output slice
int input_is_pal; ///< set to 1 if the input format is paletted
+ int interlaced;
char w_expr[256]; ///< width expression string
char h_expr[256]; ///< height expression string
@@ -90,6 +91,10 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
sscanf(args, "%255[^:]:%255[^:]", scale->w_expr, scale->h_expr);
p = strstr(args,"flags=");
if (p) scale->flags = strtoul(p+6, NULL, 0);
+ if(strstr(args,"interl=1")){
+ scale->interlaced=1;
+ }else if(strstr(args,"interl=-1"))
+ scale->interlaced=-1;
}
return 0;
@@ -99,6 +104,8 @@ static av_cold void uninit(AVFilterContext *ctx)
{
ScaleContext *scale = ctx->priv;
sws_freeContext(scale->sws);
+ sws_freeContext(scale->isws[0]);
+ sws_freeContext(scale->isws[1]);
scale->sws = NULL;
}
@@ -142,14 +149,14 @@ static int config_props(AVFilterLink *outlink)
char *expr;
int ret;
- var_values[VAR_PI] = M_PI;
- var_values[VAR_PHI] = M_PHI;
- var_values[VAR_E] = M_E;
var_values[VAR_IN_W] = var_values[VAR_IW] = inlink->w;
var_values[VAR_IN_H] = var_values[VAR_IH] = inlink->h;
var_values[VAR_OUT_W] = var_values[VAR_OW] = NAN;
var_values[VAR_OUT_H] = var_values[VAR_OH] = NAN;
var_values[VAR_A] = (float) inlink->w / inlink->h;
+ var_values[VAR_SAR] = inlink->sample_aspect_ratio.num ?
+ (float) inlink->sample_aspect_ratio.num / inlink->sample_aspect_ratio.den : 1;
+ var_values[VAR_DAR] = var_values[VAR_A] * var_values[VAR_SAR];
var_values[VAR_HSUB] = 1<<av_pix_fmt_descriptors[inlink->format].log2_chroma_w;
var_values[VAR_VSUB] = 1<<av_pix_fmt_descriptors[inlink->format].log2_chroma_h;
@@ -206,12 +213,29 @@ static int config_props(AVFilterLink *outlink)
scale->input_is_pal = av_pix_fmt_descriptors[inlink->format].flags & PIX_FMT_PAL;
+ if (scale->sws)
+ sws_freeContext(scale->sws);
scale->sws = sws_getContext(inlink ->w, inlink ->h, inlink ->format,
outlink->w, outlink->h, outlink->format,
scale->flags, NULL, NULL, NULL);
- if (!scale->sws)
+ if (scale->isws[0])
+ sws_freeContext(scale->isws[0]);
+ scale->isws[0] = sws_getContext(inlink ->w, inlink ->h/2, inlink ->format,
+ outlink->w, outlink->h/2, outlink->format,
+ scale->flags, NULL, NULL, NULL);
+ if (scale->isws[1])
+ sws_freeContext(scale->isws[1]);
+ scale->isws[1] = sws_getContext(inlink ->w, inlink ->h/2, inlink ->format,
+ outlink->w, outlink->h/2, outlink->format,
+ scale->flags, NULL, NULL, NULL);
+ if (!scale->sws || !scale->isws[0] || !scale->isws[1])
return AVERROR(EINVAL);
+ if (inlink->sample_aspect_ratio.num){
+ outlink->sample_aspect_ratio = av_mul_q((AVRational){outlink->h * inlink->w, outlink->w * inlink->h}, inlink->sample_aspect_ratio);
+ } else
+ outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
+
return 0;
fail:
@@ -236,35 +260,56 @@ static void start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
outlink->out_buf = outpicref;
- av_reduce(&outpicref->video->pixel_aspect.num, &outpicref->video->pixel_aspect.den,
- (int64_t)picref->video->pixel_aspect.num * outlink->h * link->w,
- (int64_t)picref->video->pixel_aspect.den * outlink->w * link->h,
+ av_reduce(&outpicref->video->sample_aspect_ratio.num, &outpicref->video->sample_aspect_ratio.den,
+ (int64_t)picref->video->sample_aspect_ratio.num * outlink->h * link->w,
+ (int64_t)picref->video->sample_aspect_ratio.den * outlink->w * link->h,
INT_MAX);
scale->slice_y = 0;
avfilter_start_frame(outlink, avfilter_ref_buffer(outpicref, ~0));
}
+static int scale_slice(AVFilterLink *link, struct SwsContext *sws, int y, int h, int mul, int field)
+{
+ ScaleContext *scale = link->dst->priv;
+ AVFilterBufferRef *cur_pic = link->cur_buf;
+ AVFilterBufferRef *out_buf = link->dst->outputs[0]->out_buf;
+ const uint8_t *in[4];
+ uint8_t *out[4];
+ int in_stride[4],out_stride[4];
+ int i;
+
+ for(i=0; i<4; i++){
+ int vsub= ((i+1)&2) ? scale->vsub : 0;
+ in_stride[i] = cur_pic->linesize[i] * mul;
+ out_stride[i] = out_buf->linesize[i] * mul;
+ in[i] = cur_pic->data[i] + ((y>>vsub)+field) * cur_pic->linesize[i];
+ out[i] = out_buf->data[i] + field * out_buf->linesize[i];
+ }
+ if(scale->input_is_pal){
+ in[1] = cur_pic->data[1];
+ out[1] = out_buf->data[1];
+ }
+
+ return sws_scale(sws, in, in_stride, y/mul, h,
+ out,out_stride);
+}
+
static void draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
{
ScaleContext *scale = link->dst->priv;
int out_h;
- AVFilterBufferRef *cur_pic = link->cur_buf;
- const uint8_t *data[4];
if (scale->slice_y == 0 && slice_dir == -1)
scale->slice_y = link->dst->outputs[0]->h;
- data[0] = cur_pic->data[0] + y * cur_pic->linesize[0];
- data[1] = scale->input_is_pal ?
- cur_pic->data[1] :
- cur_pic->data[1] + (y>>scale->vsub) * cur_pic->linesize[1];
- data[2] = cur_pic->data[2] + (y>>scale->vsub) * cur_pic->linesize[2];
- data[3] = cur_pic->data[3] + y * cur_pic->linesize[3];
-
- out_h = sws_scale(scale->sws, data, cur_pic->linesize, y, h,
- link->dst->outputs[0]->out_buf->data,
- link->dst->outputs[0]->out_buf->linesize);
+ if(scale->interlaced>0 || (scale->interlaced<0 && link->cur_buf->video->interlaced)){
+ av_assert0(y%4 == 0);
+ out_h = scale_slice(link, scale->isws[0], y, (h+1)/2, 2, 0);
+ out_h+= scale_slice(link, scale->isws[1], y, h /2, 2, 1);
+ }else{
+ out_h = scale_slice(link, scale->sws, y, h, 1, 0);
+ }
if (slice_dir == -1)
scale->slice_y -= out_h;
diff --git a/libavfilter/vf_select.c b/libavfilter/vf_select.c
new file mode 100644
index 0000000000..262cccf246
--- /dev/null
+++ b/libavfilter/vf_select.c
@@ -0,0 +1,340 @@
+/*
+ * Copyright (c) 2011 Stefano Sabatini
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * filter for selecting which frame passes in the filterchain
+ */
+
+#include "libavutil/eval.h"
+#include "libavutil/fifo.h"
+#include "avfilter.h"
+
+static const char *var_names[] = {
+ "TB", ///< timebase
+
+ "pts", ///< original pts in the file of the frame
+ "start_pts", ///< first PTS in the stream, expressed in TB units
+ "prev_pts", ///< previous frame PTS
+ "prev_selected_pts", ///< previous selected frame PTS
+
+ "t", ///< first PTS in seconds
+ "start_t", ///< first PTS in the stream, expressed in seconds
+ "prev_t", ///< previous frame time
+ "prev_selected_t", ///< previously selected time
+
+ "pict_type", ///< the type of picture in the movie
+ "I",
+ "P",
+ "B",
+ "S",
+ "SI",
+ "SP",
+ "BI",
+
+ "interlace_type", ///< the frame interlace type
+ "PROGRESSIVE",
+ "TOPFIRST",
+ "BOTTOMFIRST",
+
+ "n", ///< frame number (starting from zero)
+ "selected_n", ///< selected frame number (starting from zero)
+ "prev_selected_n", ///< number of the last selected frame
+
+ "key", ///< tell if the frame is a key frame
+ "pos", ///< original position in the file of the frame
+
+ NULL
+};
+
+enum var_name {
+ VAR_TB,
+
+ VAR_PTS,
+ VAR_START_PTS,
+ VAR_PREV_PTS,
+ VAR_PREV_SELECTED_PTS,
+
+ VAR_T,
+ VAR_START_T,
+ VAR_PREV_T,
+ VAR_PREV_SELECTED_T,
+
+ VAR_PICT_TYPE,
+ VAR_PICT_TYPE_I,
+ VAR_PICT_TYPE_P,
+ VAR_PICT_TYPE_B,
+ VAR_PICT_TYPE_S,
+ VAR_PICT_TYPE_SI,
+ VAR_PICT_TYPE_SP,
+ VAR_PICT_TYPE_BI,
+
+ VAR_INTERLACE_TYPE,
+ VAR_INTERLACE_TYPE_P,
+ VAR_INTERLACE_TYPE_T,
+ VAR_INTERLACE_TYPE_B,
+
+ VAR_N,
+ VAR_SELECTED_N,
+ VAR_PREV_SELECTED_N,
+
+ VAR_KEY,
+ VAR_POS,
+
+ VAR_VARS_NB
+};
+
+#define FIFO_SIZE 8
+
+typedef struct {
+ AVExpr *expr;
+ double var_values[VAR_VARS_NB];
+ double select;
+ int cache_frames;
+ AVFifoBuffer *pending_frames; ///< FIFO buffer of video frames
+} SelectContext;
+
+static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
+{
+ SelectContext *select = ctx->priv;
+ int ret;
+
+ if ((ret = av_expr_parse(&select->expr, args ? args : "1",
+ var_names, NULL, NULL, NULL, NULL, 0, ctx)) < 0) {
+ av_log(ctx, AV_LOG_ERROR, "Error while parsing expression '%s'\n", args);
+ return ret;
+ }
+
+ select->pending_frames = av_fifo_alloc(FIFO_SIZE*sizeof(AVFilterBufferRef*));
+ if (!select->pending_frames) {
+ av_log(ctx, AV_LOG_ERROR, "Failed to allocate pending frames buffer.\n");
+ return AVERROR(ENOMEM);
+ }
+ return 0;
+}
+
+#define INTERLACE_TYPE_P 0
+#define INTERLACE_TYPE_T 1
+#define INTERLACE_TYPE_B 2
+
+static int config_input(AVFilterLink *inlink)
+{
+ SelectContext *select = inlink->dst->priv;
+
+ select->var_values[VAR_N] = 0.0;
+ select->var_values[VAR_SELECTED_N] = 0.0;
+
+ select->var_values[VAR_TB] = av_q2d(inlink->time_base);
+
+ select->var_values[VAR_PREV_PTS] = NAN;
+ select->var_values[VAR_PREV_SELECTED_PTS] = NAN;
+ select->var_values[VAR_PREV_SELECTED_T] = NAN;
+ select->var_values[VAR_START_PTS] = NAN;
+ select->var_values[VAR_START_T] = NAN;
+
+ select->var_values[VAR_PICT_TYPE_I] = AV_PICTURE_TYPE_I;
+ select->var_values[VAR_PICT_TYPE_P] = AV_PICTURE_TYPE_P;
+ select->var_values[VAR_PICT_TYPE_B] = AV_PICTURE_TYPE_B;
+ select->var_values[VAR_PICT_TYPE_SI] = AV_PICTURE_TYPE_SI;
+ select->var_values[VAR_PICT_TYPE_SP] = AV_PICTURE_TYPE_SP;
+
+ select->var_values[VAR_INTERLACE_TYPE_P] = INTERLACE_TYPE_P;
+ select->var_values[VAR_INTERLACE_TYPE_T] = INTERLACE_TYPE_T;
+ select->var_values[VAR_INTERLACE_TYPE_B] = INTERLACE_TYPE_B;;
+
+ return 0;
+}
+
+#define D2TS(d) (isnan(d) ? AV_NOPTS_VALUE : (int64_t)(d))
+#define TS2D(ts) ((ts) == AV_NOPTS_VALUE ? NAN : (double)(ts))
+
+static int select_frame(AVFilterContext *ctx, AVFilterBufferRef *picref)
+{
+ SelectContext *select = ctx->priv;
+ AVFilterLink *inlink = ctx->inputs[0];
+ double res;
+
+ if (isnan(select->var_values[VAR_START_PTS]))
+ select->var_values[VAR_START_PTS] = TS2D(picref->pts);
+ if (isnan(select->var_values[VAR_START_T]))
+ select->var_values[VAR_START_T] = TS2D(picref->pts) * av_q2d(inlink->time_base);
+
+ select->var_values[VAR_PTS] = TS2D(picref->pts);
+ select->var_values[VAR_T ] = TS2D(picref->pts) * av_q2d(inlink->time_base);
+ select->var_values[VAR_POS] = picref->pos == -1 ? NAN : picref->pos;
+ select->var_values[VAR_PREV_PTS] = TS2D(picref ->pts);
+
+ select->var_values[VAR_INTERLACE_TYPE] =
+ !picref->video->interlaced ? INTERLACE_TYPE_P :
+ picref->video->top_field_first ? INTERLACE_TYPE_T : INTERLACE_TYPE_B;
+ select->var_values[VAR_PICT_TYPE] = picref->video->pict_type;
+
+ res = av_expr_eval(select->expr, select->var_values, NULL);
+ av_log(inlink->dst, AV_LOG_DEBUG,
+ "n:%d pts:%d t:%f pos:%d interlace_type:%c key:%d pict_type:%c "
+ "-> select:%f\n",
+ (int)select->var_values[VAR_N],
+ (int)select->var_values[VAR_PTS],
+ select->var_values[VAR_T],
+ (int)select->var_values[VAR_POS],
+ select->var_values[VAR_INTERLACE_TYPE] == INTERLACE_TYPE_P ? 'P' :
+ select->var_values[VAR_INTERLACE_TYPE] == INTERLACE_TYPE_T ? 'T' :
+ select->var_values[VAR_INTERLACE_TYPE] == INTERLACE_TYPE_B ? 'B' : '?',
+ (int)select->var_values[VAR_KEY],
+ av_get_picture_type_char(select->var_values[VAR_PICT_TYPE]),
+ res);
+
+ select->var_values[VAR_N] += 1.0;
+
+ if (res) {
+ select->var_values[VAR_PREV_SELECTED_N] = select->var_values[VAR_N];
+ select->var_values[VAR_PREV_SELECTED_PTS] = select->var_values[VAR_PTS];
+ select->var_values[VAR_PREV_SELECTED_T] = select->var_values[VAR_T];
+ select->var_values[VAR_SELECTED_N] += 1.0;
+ }
+ return res;
+}
+
+static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
+{
+ SelectContext *select = inlink->dst->priv;
+
+ select->select = select_frame(inlink->dst, picref);
+ if (select->select) {
+ /* frame was requested through poll_frame */
+ if (select->cache_frames) {
+ if (!av_fifo_space(select->pending_frames))
+ av_log(inlink->dst, AV_LOG_ERROR,
+ "Buffering limit reached, cannot cache more frames\n");
+ else
+ av_fifo_generic_write(select->pending_frames, &picref,
+ sizeof(picref), NULL);
+ return;
+ }
+ avfilter_start_frame(inlink->dst->outputs[0], avfilter_ref_buffer(picref, ~0));
+ }
+}
+
+static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
+{
+ SelectContext *select = inlink->dst->priv;
+
+ if (select->select && !select->cache_frames)
+ avfilter_draw_slice(inlink->dst->outputs[0], y, h, slice_dir);
+}
+
+static void end_frame(AVFilterLink *inlink)
+{
+ SelectContext *select = inlink->dst->priv;
+ AVFilterBufferRef *picref = inlink->cur_buf;
+
+ if (select->select) {
+ if (select->cache_frames)
+ return;
+ avfilter_end_frame(inlink->dst->outputs[0]);
+ }
+ avfilter_unref_buffer(picref);
+}
+
+static int request_frame(AVFilterLink *outlink)
+{
+ AVFilterContext *ctx = outlink->src;
+ SelectContext *select = ctx->priv;
+ AVFilterLink *inlink = outlink->src->inputs[0];
+ select->select = 0;
+
+ if (av_fifo_size(select->pending_frames)) {
+ AVFilterBufferRef *picref;
+ av_fifo_generic_read(select->pending_frames, &picref, sizeof(picref), NULL);
+ avfilter_start_frame(outlink, avfilter_ref_buffer(picref, ~0));
+ avfilter_draw_slice(outlink, 0, outlink->h, 1);
+ avfilter_end_frame(outlink);
+ avfilter_unref_buffer(picref);
+ return 0;
+ }
+
+ while (!select->select) {
+ int ret = avfilter_request_frame(inlink);
+ if (ret < 0)
+ return ret;
+ }
+
+ return 0;
+}
+
+static int poll_frame(AVFilterLink *outlink)
+{
+ SelectContext *select = outlink->src->priv;
+ AVFilterLink *inlink = outlink->src->inputs[0];
+ int count, ret;
+
+ if (!av_fifo_size(select->pending_frames)) {
+ if ((count = avfilter_poll_frame(inlink)) <= 0)
+ return count;
+ /* request frame from input, and apply select condition to it */
+ select->cache_frames = 1;
+ while (count-- && av_fifo_space(select->pending_frames)) {
+ ret = avfilter_request_frame(inlink);
+ if (ret < 0)
+ break;
+ }
+ select->cache_frames = 0;
+ }
+
+ return av_fifo_size(select->pending_frames)/sizeof(AVFilterBufferRef *);
+}
+
+static av_cold void uninit(AVFilterContext *ctx)
+{
+ SelectContext *select = ctx->priv;
+ AVFilterBufferRef *picref;
+
+ av_expr_free(select->expr);
+ select->expr = NULL;
+
+ while (select->pending_frames &&
+ av_fifo_generic_read(select->pending_frames, &picref, sizeof(picref), NULL) == sizeof(picref))
+ avfilter_unref_buffer(picref);
+ av_fifo_free(select->pending_frames);
+ select->pending_frames = NULL;
+}
+
+AVFilter avfilter_vf_select = {
+ .name = "select",
+ .description = NULL_IF_CONFIG_SMALL("Select frames to pass in output."),
+ .init = init,
+ .uninit = uninit,
+
+ .priv_size = sizeof(SelectContext),
+
+ .inputs = (AVFilterPad[]) {{ .name = "default",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .get_video_buffer = avfilter_null_get_video_buffer,
+ .config_props = config_input,
+ .start_frame = start_frame,
+ .draw_slice = draw_slice,
+ .end_frame = end_frame },
+ { .name = NULL }},
+ .outputs = (AVFilterPad[]) {{ .name = "default",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .poll_frame = poll_frame,
+ .request_frame = request_frame, },
+ { .name = NULL}},
+};
diff --git a/libavfilter/vf_setpts.c b/libavfilter/vf_setpts.c
index f2650923d0..1223be5054 100644
--- a/libavfilter/vf_setpts.c
+++ b/libavfilter/vf_setpts.c
@@ -2,20 +2,20 @@
* Copyright (c) 2010 Stefano Sabatini
* Copyright (c) 2008 Victor Paesa
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -31,11 +31,8 @@
#include "avfilter.h"
static const char *var_names[] = {
- "E", ///< Euler number
"INTERLACED", ///< tell if the current frame is interlaced
"N", ///< frame number (starting at zero)
- "PHI", ///< golden ratio
- "PI", ///< greek pi
"POS", ///< original position in the file of the frame
"PREV_INPTS", ///< previous input PTS
"PREV_OUTPTS", ///< previous output PTS
@@ -46,11 +43,8 @@ static const char *var_names[] = {
};
enum var_name {
- VAR_E,
VAR_INTERLACED,
VAR_N,
- VAR_PHI,
- VAR_PI,
VAR_POS,
VAR_PREV_INPTS,
VAR_PREV_OUTPTS,
@@ -76,10 +70,7 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
return ret;
}
- setpts->var_values[VAR_E ] = M_E;
setpts->var_values[VAR_N ] = 0.0;
- setpts->var_values[VAR_PHI ] = M_PHI;
- setpts->var_values[VAR_PI ] = M_PI;
setpts->var_values[VAR_PREV_INPTS ] = NAN;
setpts->var_values[VAR_PREV_OUTPTS] = NAN;
setpts->var_values[VAR_STARTPTS ] = NAN;
diff --git a/libavfilter/vf_settb.c b/libavfilter/vf_settb.c
index eeb4353915..e74ee65cf2 100644
--- a/libavfilter/vf_settb.c
+++ b/libavfilter/vf_settb.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2010 Stefano Sabatini
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -31,18 +31,12 @@
#include "internal.h"
static const char *var_names[] = {
- "E",
- "PHI",
- "PI",
"AVTB", /* default timebase 1/AV_TIME_BASE */
"intb", /* input timebase */
NULL
};
enum var_name {
- VAR_E,
- VAR_PHI,
- VAR_PI,
VAR_AVTB,
VAR_INTB,
VAR_VARS_NB
@@ -73,9 +67,6 @@ static int config_output_props(AVFilterLink *outlink)
int ret;
double res;
- settb->var_values[VAR_E] = M_E;
- settb->var_values[VAR_PHI] = M_PHI;
- settb->var_values[VAR_PI] = M_PI;
settb->var_values[VAR_AVTB] = av_q2d(AV_TIME_BASE_Q);
settb->var_values[VAR_INTB] = av_q2d(inlink->time_base);
diff --git a/libavfilter/vf_showinfo.c b/libavfilter/vf_showinfo.c
new file mode 100644
index 0000000000..9ce50f44ba
--- /dev/null
+++ b/libavfilter/vf_showinfo.c
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2011 Stefano Sabatini
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * filter for showing textual video frame information
+ */
+
+#include "libavutil/adler32.h"
+#include "libavutil/imgutils.h"
+#include "libavutil/pixdesc.h"
+#include "avfilter.h"
+
+typedef struct {
+ unsigned int frame;
+} ShowInfoContext;
+
+static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
+{
+ ShowInfoContext *showinfo = ctx->priv;
+ showinfo->frame = 0;
+ return 0;
+}
+
+static void end_frame(AVFilterLink *inlink)
+{
+ AVFilterContext *ctx = inlink->dst;
+ ShowInfoContext *showinfo = ctx->priv;
+ AVFilterBufferRef *picref = inlink->cur_buf;
+ uint32_t plane_checksum[4] = {0}, checksum = 0;
+ int i, plane, vsub = av_pix_fmt_descriptors[inlink->format].log2_chroma_h;
+
+ for (plane = 0; picref->data[plane] && plane < 4; plane++) {
+ size_t linesize = av_image_get_linesize(picref->format, picref->video->w, plane);
+ uint8_t *data = picref->data[plane];
+ int h = plane == 1 || plane == 2 ? inlink->h >> vsub : inlink->h;
+
+ for (i = 0; i < h; i++) {
+ plane_checksum[plane] = av_adler32_update(plane_checksum[plane], data, linesize);
+ checksum = av_adler32_update(checksum, data, linesize);
+ data += picref->linesize[plane];
+ }
+ }
+
+ av_log(ctx, AV_LOG_INFO,
+ "n:%d pts:%"PRId64" pts_time:%f pos:%"PRId64" "
+ "fmt:%s sar:%d/%d s:%dx%d i:%c iskey:%d type:%c "
+ "checksum:%u plane_checksum:[%u %u %u %u]\n",
+ showinfo->frame,
+ picref->pts, picref ->pts * av_q2d(inlink->time_base), picref->pos,
+ av_pix_fmt_descriptors[picref->format].name,
+ picref->video->sample_aspect_ratio.num, picref->video->sample_aspect_ratio.den,
+ picref->video->w, picref->video->h,
+ !picref->video->interlaced ? 'P' : /* Progressive */
+ picref->video->top_field_first ? 'T' : 'B', /* Top / Bottom */
+ picref->video->key_frame,
+ av_get_picture_type_char(picref->video->pict_type),
+ checksum, plane_checksum[0], plane_checksum[1], plane_checksum[2], plane_checksum[3]);
+
+ showinfo->frame++;
+ avfilter_end_frame(inlink->dst->outputs[0]);
+}
+
+AVFilter avfilter_vf_showinfo = {
+ .name = "showinfo",
+ .description = NULL_IF_CONFIG_SMALL("Show textual information for each video frame."),
+
+ .priv_size = sizeof(ShowInfoContext),
+ .init = init,
+
+ .inputs = (AVFilterPad[]) {{ .name = "default",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .get_video_buffer = avfilter_null_get_video_buffer,
+ .start_frame = avfilter_null_start_frame,
+ .end_frame = end_frame,
+ .min_perms = AV_PERM_READ, },
+ { .name = NULL}},
+
+ .outputs = (AVFilterPad[]) {{ .name = "default",
+ .type = AVMEDIA_TYPE_VIDEO },
+ { .name = NULL}},
+};
diff --git a/libavfilter/vf_slicify.c b/libavfilter/vf_slicify.c
index cc56fe857c..177ac1f2b9 100644
--- a/libavfilter/vf_slicify.c
+++ b/libavfilter/vf_slicify.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2007 Bobby Bingham
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavfilter/vf_split.c b/libavfilter/vf_split.c
new file mode 100644
index 0000000000..cbebf264fa
--- /dev/null
+++ b/libavfilter/vf_split.c
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2007 Bobby Bingham
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * Video splitter
+ */
+
+#include "avfilter.h"
+
+static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
+{
+ avfilter_start_frame(inlink->dst->outputs[0],
+ avfilter_ref_buffer(picref, ~AV_PERM_WRITE));
+ avfilter_start_frame(inlink->dst->outputs[1],
+ avfilter_ref_buffer(picref, ~AV_PERM_WRITE));
+}
+
+static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
+{
+ avfilter_draw_slice(inlink->dst->outputs[0], y, h, slice_dir);
+ avfilter_draw_slice(inlink->dst->outputs[1], y, h, slice_dir);
+}
+
+static void end_frame(AVFilterLink *inlink)
+{
+ avfilter_end_frame(inlink->dst->outputs[0]);
+ avfilter_end_frame(inlink->dst->outputs[1]);
+
+ avfilter_unref_buffer(inlink->cur_buf);
+}
+
+AVFilter avfilter_vf_split = {
+ .name = "split",
+ .description = NULL_IF_CONFIG_SMALL("Pass on the input to two outputs."),
+
+ .inputs = (AVFilterPad[]) {{ .name = "default",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .get_video_buffer= avfilter_null_get_video_buffer,
+ .start_frame = start_frame,
+ .draw_slice = draw_slice,
+ .end_frame = end_frame, },
+ { .name = NULL}},
+ .outputs = (AVFilterPad[]) {{ .name = "output1",
+ .type = AVMEDIA_TYPE_VIDEO, },
+ { .name = "output2",
+ .type = AVMEDIA_TYPE_VIDEO, },
+ { .name = NULL}},
+};
diff --git a/libavfilter/vf_transpose.c b/libavfilter/vf_transpose.c
index a0ec67c426..f4f72b9c64 100644
--- a/libavfilter/vf_transpose.c
+++ b/libavfilter/vf_transpose.c
@@ -2,20 +2,20 @@
* Copyright (c) 2010 Stefano Sabatini
* Copyright (c) 2008 Vitor Sessak
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -83,7 +83,7 @@ static int query_formats(AVFilterContext *ctx)
PIX_FMT_NONE
};
- avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts));
+ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts));
return 0;
}
@@ -122,11 +122,11 @@ static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
outlink->w, outlink->h);
outlink->out_buf->pts = picref->pts;
- if (picref->video->pixel_aspect.num == 0) {
- outlink->out_buf->video->pixel_aspect = picref->video->pixel_aspect;
+ if (picref->video->sample_aspect_ratio.num == 0) {
+ outlink->out_buf->video->sample_aspect_ratio = picref->video->sample_aspect_ratio;
} else {
- outlink->out_buf->video->pixel_aspect.num = picref->video->pixel_aspect.den;
- outlink->out_buf->video->pixel_aspect.den = picref->video->pixel_aspect.num;
+ outlink->out_buf->video->sample_aspect_ratio.num = picref->video->sample_aspect_ratio.den;
+ outlink->out_buf->video->sample_aspect_ratio.den = picref->video->sample_aspect_ratio.num;
}
avfilter_start_frame(outlink, avfilter_ref_buffer(outlink->out_buf, ~0));
@@ -195,6 +195,8 @@ static void end_frame(AVFilterLink *inlink)
avfilter_unref_buffer(outpic);
}
+static void null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) { }
+
AVFilter avfilter_vf_transpose = {
.name = "transpose",
.description = NULL_IF_CONFIG_SMALL("Transpose input video."),
@@ -207,6 +209,7 @@ AVFilter avfilter_vf_transpose = {
.inputs = (AVFilterPad[]) {{ .name = "default",
.type = AVMEDIA_TYPE_VIDEO,
.start_frame = start_frame,
+ .draw_slice = null_draw_slice,
.end_frame = end_frame,
.min_perms = AV_PERM_READ, },
{ .name = NULL}},
diff --git a/libavfilter/vf_unsharp.c b/libavfilter/vf_unsharp.c
index 274b13c296..e6257e2cab 100644
--- a/libavfilter/vf_unsharp.c
+++ b/libavfilter/vf_unsharp.c
@@ -3,26 +3,26 @@
* Port copyright (c) 2010 Daniel G. Taylor <dan@programmer-art.org>
* Relicensed to the LGPL with permission from Remi Guyomarch.
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
- * blur / sharpen filter, ported to Libav from MPlayer
+ * blur / sharpen filter, ported to FFmpeg from MPlayer
* libmpcodecs/unsharp.c.
*
* This code is based on:
@@ -44,8 +44,8 @@
#define MIN_SIZE 3
#define MAX_SIZE 13
-#define CHROMA_WIDTH(link) -((-link->w) >> av_pix_fmt_descriptors[link->format].log2_chroma_w)
-#define CHROMA_HEIGHT(link) -((-link->h) >> av_pix_fmt_descriptors[link->format].log2_chroma_h)
+/* right-shift and round-up */
+#define SHIFTUP(x,shift) (-((-(x))>>(shift)))
typedef struct FilterParam {
int msize_x; ///< matrix width
@@ -61,15 +61,19 @@ typedef struct FilterParam {
typedef struct {
FilterParam luma; ///< luma parameters (width, height, amount)
FilterParam chroma; ///< chroma parameters (width, height, amount)
+ int hsub, vsub;
} UnsharpContext;
-static void unsharpen(uint8_t *dst, uint8_t *src, int dst_stride, int src_stride, int width, int height, FilterParam *fp)
+static void apply_unsharp( uint8_t *dst, int dst_stride,
+ const uint8_t *src, int src_stride,
+ int width, int height, FilterParam *fp)
{
uint32_t **sc = fp->sc;
uint32_t sr[(MAX_SIZE * MAX_SIZE) - 1], tmp1, tmp2;
int32_t res;
int x, y, z;
+ const uint8_t *src2 = NULL; //silence a warning
if (!fp->amount) {
if (dst_stride == src_stride)
@@ -84,9 +88,12 @@ static void unsharpen(uint8_t *dst, uint8_t *src, int dst_stride, int src_stride
memset(sc[y], 0, sizeof(sc[y][0]) * (width + 2 * fp->steps_x));
for (y = -fp->steps_y; y < height + fp->steps_y; y++) {
+ if (y < height)
+ src2 = src;
+
memset(sr, 0, sizeof(sr[0]) * (2 * fp->steps_x - 1));
for (x = -fp->steps_x; x < width + fp->steps_x; x++) {
- tmp1 = x <= 0 ? src[0] : x >= width ? src[width-1] : src[x];
+ tmp1 = x <= 0 ? src2[0] : x >= width ? src2[width-1] : src2[x];
for (z = 0; z < fp->steps_x * 2; z += 2) {
tmp2 = sr[z + 0] + tmp1; sr[z + 0] = tmp1;
tmp1 = sr[z + 1] + tmp2; sr[z + 1] = tmp2;
@@ -96,8 +103,8 @@ static void unsharpen(uint8_t *dst, uint8_t *src, int dst_stride, int src_stride
tmp1 = sc[z + 1][x + fp->steps_x] + tmp2; sc[z + 1][x + fp->steps_x] = tmp2;
}
if (x >= fp->steps_x && y >= fp->steps_y) {
- uint8_t* srx = src - fp->steps_y * src_stride + x - fp->steps_x;
- uint8_t* dsx = dst - fp->steps_y * dst_stride + x - fp->steps_x;
+ const uint8_t *srx = src - fp->steps_y * src_stride + x - fp->steps_x;
+ uint8_t *dsx = dst - fp->steps_y * dst_stride + x - fp->steps_x;
res = (int32_t)*srx + ((((int32_t) * srx - (int32_t)((tmp1 + fp->halfscale) >> fp->scalebits)) * fp->amount) >> 16);
*dsx = av_clip_uint8(res);
@@ -125,8 +132,8 @@ static void set_filter_param(FilterParam *fp, int msize_x, int msize_y, double a
static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
{
UnsharpContext *unsharp = ctx->priv;
- int lmsize_x = 5, cmsize_x = 0;
- int lmsize_y = 5, cmsize_y = 0;
+ int lmsize_x = 5, cmsize_x = 5;
+ int lmsize_y = 5, cmsize_y = 5;
double lamount = 1.0f, camount = 0.0f;
if (args)
@@ -155,7 +162,7 @@ static int query_formats(AVFilterContext *ctx)
PIX_FMT_YUVJ444P, PIX_FMT_YUVJ440P, PIX_FMT_NONE
};
- avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts));
+ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts));
return 0;
}
@@ -178,8 +185,11 @@ static int config_props(AVFilterLink *link)
{
UnsharpContext *unsharp = link->dst->priv;
+ unsharp->hsub = av_pix_fmt_descriptors[link->format].log2_chroma_w;
+ unsharp->vsub = av_pix_fmt_descriptors[link->format].log2_chroma_h;
+
init_filter_param(link->dst, &unsharp->luma, "luma", link->w);
- init_filter_param(link->dst, &unsharp->chroma, "chroma", CHROMA_WIDTH(link));
+ init_filter_param(link->dst, &unsharp->chroma, "chroma", SHIFTUP(link->w, unsharp->hsub));
return 0;
}
@@ -205,10 +215,12 @@ static void end_frame(AVFilterLink *link)
UnsharpContext *unsharp = link->dst->priv;
AVFilterBufferRef *in = link->cur_buf;
AVFilterBufferRef *out = link->dst->outputs[0]->out_buf;
+ int cw = SHIFTUP(link->w, unsharp->hsub);
+ int ch = SHIFTUP(link->h, unsharp->vsub);
- unsharpen(out->data[0], in->data[0], out->linesize[0], in->linesize[0], link->w, link->h, &unsharp->luma);
- unsharpen(out->data[1], in->data[1], out->linesize[1], in->linesize[1], CHROMA_WIDTH(link), CHROMA_HEIGHT(link), &unsharp->chroma);
- unsharpen(out->data[2], in->data[2], out->linesize[2], in->linesize[2], CHROMA_WIDTH(link), CHROMA_HEIGHT(link), &unsharp->chroma);
+ apply_unsharp(out->data[0], out->linesize[0], in->data[0], in->linesize[0], link->w, link->h, &unsharp->luma);
+ apply_unsharp(out->data[1], out->linesize[1], in->data[1], in->linesize[1], cw, ch, &unsharp->chroma);
+ apply_unsharp(out->data[2], out->linesize[2], in->data[2], in->linesize[2], cw, ch, &unsharp->chroma);
avfilter_unref_buffer(in);
avfilter_draw_slice(link->dst->outputs[0], 0, link->h, 1);
diff --git a/libavfilter/vf_vflip.c b/libavfilter/vf_vflip.c
index 09ba303bb9..e5cede81b5 100644
--- a/libavfilter/vf_vflip.c
+++ b/libavfilter/vf_vflip.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2007 Bobby Bingham
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavfilter/vf_yadif.c b/libavfilter/vf_yadif.c
index 42a7219d26..3d81b94712 100644
--- a/libavfilter/vf_yadif.c
+++ b/libavfilter/vf_yadif.c
@@ -2,20 +2,18 @@
* Copyright (C) 2006-2010 Michael Niedermayer <michaelni@gmx.at>
* 2010 James Darnley <james.darnley@gmail.com>
*
- * This file is part of Libav.
- *
- * Libav is free software; you can redistribute it and/or modify
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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 Libav; if not, write to the Free Software Foundation, Inc.,
+ * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
@@ -38,14 +36,20 @@ typedef struct {
int mode;
/**
- * 0: bottom field first
- * 1: top field first
+ * 0: top field first
+ * 1: bottom field first
* -1: auto-detection
*/
int parity;
int frame_pending;
+ /**
+ * 0: deinterlace all frames
+ * 1: only deinterlace frames marked as interlaced
+ */
+ int auto_enable;
+
AVFilterBufferRef *cur;
AVFilterBufferRef *next;
AVFilterBufferRef *prev;
@@ -141,7 +145,7 @@ static void filter(AVFilterContext *ctx, AVFilterBufferRef *dstpic,
int refs = yadif->cur->linesize[i];
int df = (yadif->csp->comp[i].depth_minus1+1) / 8;
- if (i) {
+ if (i == 1 || i == 2) {
/* Why is this not part of the per-plane description thing? */
w >>= yadif->csp->log2_chroma_w;
h >>= yadif->csp->log2_chroma_h;
@@ -197,14 +201,17 @@ static void return_frame(AVFilterContext *ctx, int is_second)
tff = yadif->parity^1;
}
- if (is_second)
+ if (is_second) {
yadif->out = avfilter_get_video_buffer(link, AV_PERM_WRITE | AV_PERM_PRESERVE |
AV_PERM_REUSE, link->w, link->h);
+ avfilter_copy_buffer_ref_props(yadif->out, yadif->cur);
+ yadif->out->video->interlaced = 0;
+ }
if (!yadif->csp)
yadif->csp = &av_pix_fmt_descriptors[link->format];
if (yadif->csp->comp[0].depth_minus1 == 15)
- yadif->filter_line = filter_line_c_16bit;
+ yadif->filter_line = (void*)filter_line_c_16bit;
filter(ctx, yadif->out, tff ^ !is_second, tff);
@@ -242,6 +249,14 @@ static void start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
if (!yadif->cur)
return;
+ if (yadif->auto_enable && !yadif->cur->video->interlaced) {
+ yadif->out = avfilter_ref_buffer(yadif->cur, AV_PERM_READ);
+ avfilter_unref_buffer(yadif->prev);
+ yadif->prev = NULL;
+ avfilter_start_frame(ctx->outputs[0], yadif->out);
+ return;
+ }
+
if (!yadif->prev)
yadif->prev = avfilter_ref_buffer(yadif->cur, AV_PERM_READ);
@@ -261,6 +276,12 @@ static void end_frame(AVFilterLink *link)
if (!yadif->out)
return;
+ if (yadif->auto_enable && !yadif->cur->video->interlaced) {
+ avfilter_draw_slice(ctx->outputs[0], 0, link->h, 1);
+ avfilter_end_frame(ctx->outputs[0]);
+ return;
+ }
+
return_frame(ctx, 0);
}
@@ -301,6 +322,9 @@ static int poll_frame(AVFilterLink *link)
}
assert(yadif->next || !val);
+ if (yadif->auto_enable && yadif->next && !yadif->next->video->interlaced)
+ return val;
+
return val * ((yadif->mode&1)+1);
}
@@ -331,10 +355,11 @@ static int query_formats(AVFilterContext *ctx)
AV_NE( PIX_FMT_YUV420P16BE, PIX_FMT_YUV420P16LE ),
AV_NE( PIX_FMT_YUV422P16BE, PIX_FMT_YUV422P16LE ),
AV_NE( PIX_FMT_YUV444P16BE, PIX_FMT_YUV444P16LE ),
+ PIX_FMT_YUVA420P,
PIX_FMT_NONE
};
- avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts));
+ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts));
return 0;
}
@@ -346,9 +371,10 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
yadif->mode = 0;
yadif->parity = -1;
+ yadif->auto_enable = 0;
yadif->csp = NULL;
- if (args) sscanf(args, "%d:%d", &yadif->mode, &yadif->parity);
+ if (args) sscanf(args, "%d:%d:%d", &yadif->mode, &yadif->parity, &yadif->auto_enable);
yadif->filter_line = filter_line_c;
if (HAVE_SSSE3 && cpu_flags & AV_CPU_FLAG_SSSE3)
@@ -358,7 +384,7 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
else if (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX)
yadif->filter_line = ff_yadif_filter_line_mmx;
- av_log(ctx, AV_LOG_INFO, "mode:%d parity:%d\n", yadif->mode, yadif->parity);
+ av_log(ctx, AV_LOG_INFO, "mode:%d parity:%d auto_enable:%d\n", yadif->mode, yadif->parity, yadif->auto_enable);
return 0;
}
diff --git a/libavfilter/vsink_nullsink.c b/libavfilter/vsink_nullsink.c
index bdfcb8a2e4..0998bd0f89 100644
--- a/libavfilter/vsink_nullsink.c
+++ b/libavfilter/vsink_nullsink.c
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavfilter/vsrc_buffer.c b/libavfilter/vsrc_buffer.c
index 1f0233e3e3..6ce2490211 100644
--- a/libavfilter/vsrc_buffer.c
+++ b/libavfilter/vsrc_buffer.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2008 Vitor Sessak
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -24,68 +24,135 @@
*/
#include "avfilter.h"
+#include "internal.h"
+#include "avcodec.h"
#include "vsrc_buffer.h"
#include "libavutil/imgutils.h"
typedef struct {
- int64_t pts;
- AVFrame frame;
- int has_frame;
+ AVFilterBufferRef *picref;
int h, w;
enum PixelFormat pix_fmt;
AVRational time_base; ///< time_base to set in the output link
- AVRational pixel_aspect;
+ AVRational sample_aspect_ratio;
+ char sws_param[256];
} BufferSourceContext;
-int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame,
- int64_t pts, AVRational pixel_aspect)
+int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter,
+ AVFilterBufferRef *picref, int flags)
{
BufferSourceContext *c = buffer_filter->priv;
+ AVFilterLink *outlink = buffer_filter->outputs[0];
+ int ret;
+
+ if (c->picref) {
+ if (flags & AV_VSRC_BUF_FLAG_OVERWRITE) {
+ avfilter_unref_buffer(c->picref);
+ c->picref = NULL;
+ } else {
+ av_log(buffer_filter, AV_LOG_ERROR,
+ "Buffering several frames is not supported. "
+ "Please consume all available frames before adding a new one.\n");
+ return AVERROR(EINVAL);
+ }
+ }
+
+ if (picref->video->w != c->w || picref->video->h != c->h || picref->format != c->pix_fmt) {
+ AVFilterContext *scale = buffer_filter->outputs[0]->dst;
+ AVFilterLink *link;
+ char scale_param[1024];
+
+ av_log(buffer_filter, AV_LOG_INFO,
+ "Buffer video input changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s\n",
+ c->w, c->h, av_pix_fmt_descriptors[c->pix_fmt].name,
+ picref->video->w, picref->video->h, av_pix_fmt_descriptors[picref->format].name);
+
+ if (!scale || strcmp(scale->filter->name, "scale")) {
+ AVFilter *f = avfilter_get_by_name("scale");
+
+ av_log(buffer_filter, AV_LOG_INFO, "Inserting scaler filter\n");
+ if ((ret = avfilter_open(&scale, f, "Input equalizer")) < 0)
+ return ret;
+
+ snprintf(scale_param, sizeof(scale_param)-1, "%d:%d:%s", c->w, c->h, c->sws_param);
+ if ((ret = avfilter_init_filter(scale, scale_param, NULL)) < 0) {
+ avfilter_free(scale);
+ return ret;
+ }
+
+ if ((ret = avfilter_insert_filter(buffer_filter->outputs[0], scale, 0, 0)) < 0) {
+ avfilter_free(scale);
+ return ret;
+ }
+ scale->outputs[0]->time_base = scale->inputs[0]->time_base;
+
+ scale->outputs[0]->format= c->pix_fmt;
+ } else if (!strcmp(scale->filter->name, "scale")) {
+ snprintf(scale_param, sizeof(scale_param)-1, "%d:%d:%s",
+ scale->outputs[0]->w, scale->outputs[0]->h, c->sws_param);
+ scale->filter->init(scale, scale_param, NULL);
+ }
- if (c->has_frame) {
- av_log(buffer_filter, AV_LOG_ERROR,
- "Buffering several frames is not supported. "
- "Please consume all available frames before adding a new one.\n"
- );
- //return -1;
+ c->pix_fmt = scale->inputs[0]->format = picref->format;
+ c->w = scale->inputs[0]->w = picref->video->w;
+ c->h = scale->inputs[0]->h = picref->video->h;
+
+ link = scale->outputs[0];
+ if ((ret = link->srcpad->config_props(link)) < 0)
+ return ret;
}
- memcpy(c->frame.data , frame->data , sizeof(frame->data));
- memcpy(c->frame.linesize, frame->linesize, sizeof(frame->linesize));
- c->frame.interlaced_frame= frame->interlaced_frame;
- c->frame.top_field_first = frame->top_field_first;
- c->frame.key_frame = frame->key_frame;
- c->frame.pict_type = frame->pict_type;
- c->pts = pts;
- c->pixel_aspect = pixel_aspect;
- c->has_frame = 1;
+ c->picref = avfilter_get_video_buffer(outlink, AV_PERM_WRITE,
+ picref->video->w, picref->video->h);
+ av_image_copy(c->picref->data, c->picref->linesize,
+ (void*)picref->data, picref->linesize,
+ picref->format, picref->video->w, picref->video->h);
+ avfilter_copy_buffer_ref_props(c->picref, picref);
return 0;
}
+#if CONFIG_AVCODEC
+#include "avcodec.h"
+
+int av_vsrc_buffer_add_frame(AVFilterContext *buffer_src,
+ const AVFrame *frame, int flags)
+{
+ int ret;
+ AVFilterBufferRef *picref =
+ avfilter_get_video_buffer_ref_from_frame(frame, AV_PERM_WRITE);
+ if (!picref)
+ return AVERROR(ENOMEM);
+ ret = av_vsrc_buffer_add_video_buffer_ref(buffer_src, picref, flags);
+ picref->buf->data[0] = NULL;
+ avfilter_unref_buffer(picref);
+
+ return ret;
+}
+#endif
+
static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
{
BufferSourceContext *c = ctx->priv;
char pix_fmt_str[128];
- int n = 0;
+ int ret, n = 0;
+ *c->sws_param = 0;
if (!args ||
- (n = sscanf(args, "%d:%d:%127[^:]:%d:%d:%d:%d", &c->w, &c->h, pix_fmt_str,
+ (n = sscanf(args, "%d:%d:%127[^:]:%d:%d:%d:%d:%255c", &c->w, &c->h, pix_fmt_str,
&c->time_base.num, &c->time_base.den,
- &c->pixel_aspect.num, &c->pixel_aspect.den)) != 7) {
- av_log(ctx, AV_LOG_ERROR, "Expected 7 arguments, but %d found in '%s'\n", n, args);
+ &c->sample_aspect_ratio.num, &c->sample_aspect_ratio.den, c->sws_param)) < 7) {
+ av_log(ctx, AV_LOG_ERROR, "Expected at least 7 arguments, but only %d found in '%s'\n", n, args);
return AVERROR(EINVAL);
}
- if ((c->pix_fmt = av_get_pix_fmt(pix_fmt_str)) == PIX_FMT_NONE) {
- char *tail;
- c->pix_fmt = strtol(pix_fmt_str, &tail, 10);
- if (*tail || c->pix_fmt < 0 || c->pix_fmt >= PIX_FMT_NB) {
- av_log(ctx, AV_LOG_ERROR, "Invalid pixel format string '%s'\n", pix_fmt_str);
- return AVERROR(EINVAL);
- }
- }
- av_log(ctx, AV_LOG_INFO, "w:%d h:%d pixfmt:%s\n", c->w, c->h, av_pix_fmt_descriptors[c->pix_fmt].name);
+ if ((ret = ff_parse_pixel_format(&c->pix_fmt, pix_fmt_str, ctx)) < 0)
+ return ret;
+
+ av_log(ctx, AV_LOG_INFO, "w:%d h:%d pixfmt:%s tb:%d/%d sar:%d/%d sws_param:%s\n",
+ c->w, c->h, av_pix_fmt_descriptors[c->pix_fmt].name,
+ c->time_base.num, c->time_base.den,
+ c->sample_aspect_ratio.num, c->sample_aspect_ratio.den, c->sws_param);
return 0;
}
@@ -94,7 +161,7 @@ static int query_formats(AVFilterContext *ctx)
BufferSourceContext *c = ctx->priv;
enum PixelFormat pix_fmts[] = { c->pix_fmt, PIX_FMT_NONE };
- avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts));
+ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts));
return 0;
}
@@ -104,7 +171,7 @@ static int config_props(AVFilterLink *link)
link->w = c->w;
link->h = c->h;
- link->sample_aspect_ratio = c->pixel_aspect;
+ link->sample_aspect_ratio = c->sample_aspect_ratio;
link->time_base = c->time_base;
return 0;
@@ -113,36 +180,18 @@ static int config_props(AVFilterLink *link)
static int request_frame(AVFilterLink *link)
{
BufferSourceContext *c = link->src->priv;
- AVFilterBufferRef *picref;
- if (!c->has_frame) {
- av_log(link->src, AV_LOG_ERROR,
+ if (!c->picref) {
+ av_log(link->src, AV_LOG_WARNING,
"request_frame() called with no available frame!\n");
- //return -1;
+ return AVERROR(EINVAL);
}
- /* This picture will be needed unmodified later for decoding the next
- * frame */
- picref = avfilter_get_video_buffer(link, AV_PERM_WRITE | AV_PERM_PRESERVE |
- AV_PERM_REUSE2,
- link->w, link->h);
-
- av_image_copy(picref->data, picref->linesize,
- c->frame.data, c->frame.linesize,
- picref->format, link->w, link->h);
-
- picref->pts = c->pts;
- picref->video->pixel_aspect = c->pixel_aspect;
- picref->video->interlaced = c->frame.interlaced_frame;
- picref->video->top_field_first = c->frame.top_field_first;
- picref->video->key_frame = c->frame.key_frame;
- picref->video->pict_type = c->frame.pict_type;
- avfilter_start_frame(link, avfilter_ref_buffer(picref, ~0));
+ avfilter_start_frame(link, avfilter_ref_buffer(c->picref, ~0));
avfilter_draw_slice(link, 0, link->h, 1);
avfilter_end_frame(link);
- avfilter_unref_buffer(picref);
-
- c->has_frame = 0;
+ avfilter_unref_buffer(c->picref);
+ c->picref = NULL;
return 0;
}
@@ -150,7 +199,7 @@ static int request_frame(AVFilterLink *link)
static int poll_frame(AVFilterLink *link)
{
BufferSourceContext *c = link->src->priv;
- return !!(c->has_frame);
+ return !!(c->picref);
}
AVFilter avfilter_vsrc_buffer = {
diff --git a/libavfilter/vsrc_buffer.h b/libavfilter/vsrc_buffer.h
index cfaf7919ac..b661d414ea 100644
--- a/libavfilter/vsrc_buffer.h
+++ b/libavfilter/vsrc_buffer.h
@@ -1,21 +1,20 @@
/*
- * Memory buffer source filter
* Copyright (c) 2008 Vitor Sessak
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -27,10 +26,24 @@
* memory buffer source API for video
*/
-#include "libavcodec/avcodec.h" /* AVFrame */
#include "avfilter.h"
-int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame,
- int64_t pts, AVRational pixel_aspect);
+/**
+ * Tell av_vsrc_buffer_add_video_buffer_ref() to overwrite the already
+ * cached video buffer with the new added one, otherwise the function
+ * will complain and exit.
+ */
+#define AV_VSRC_BUF_FLAG_OVERWRITE 1
+
+/**
+ * Add video buffer data in picref to buffer_src.
+ *
+ * @param buffer_src pointer to a buffer source context
+ * @param flags a combination of AV_VSRC_BUF_FLAG_* flags
+ * @return >= 0 in case of success, a negative AVERROR code in case of
+ * failure
+ */
+int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_src,
+ AVFilterBufferRef *picref, int flags);
#endif /* AVFILTER_VSRC_BUFFER_H */
diff --git a/libavfilter/vsrc_color.c b/libavfilter/vsrc_color.c
index 0fb08d7dc6..b854ff2e4c 100644
--- a/libavfilter/vsrc_color.c
+++ b/libavfilter/vsrc_color.c
@@ -1,23 +1,28 @@
/*
* Copyright (c) 2010 Stefano Sabatini
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+/**
+ * @file
+ * color source
+ */
+
#include "avfilter.h"
#include "libavutil/pixdesc.h"
#include "libavutil/colorspace.h"
@@ -95,7 +100,7 @@ static int query_formats(AVFilterContext *ctx)
PIX_FMT_NONE
};
- avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts));
+ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts));
return 0;
}
@@ -125,6 +130,7 @@ static int color_config_props(AVFilterLink *inlink)
is_packed_rgba ? "rgba" : "yuva");
inlink->w = color->w;
inlink->h = color->h;
+ inlink->time_base = color->time_base;
return 0;
}
@@ -133,9 +139,9 @@ static int color_request_frame(AVFilterLink *link)
{
ColorContext *color = link->src->priv;
AVFilterBufferRef *picref = avfilter_get_video_buffer(link, AV_PERM_WRITE, color->w, color->h);
- picref->video->pixel_aspect = (AVRational) {1, 1};
- picref->pts = av_rescale_q(color->pts++, color->time_base, AV_TIME_BASE_Q);
- picref->pos = 0;
+ picref->video->sample_aspect_ratio = (AVRational) {1, 1};
+ picref->pts = color->pts++;
+ picref->pos = -1;
avfilter_start_frame(link, avfilter_ref_buffer(picref, ~0));
ff_draw_rectangle(picref->data, picref->linesize,
diff --git a/libavfilter/vsrc_mptestsrc.c b/libavfilter/vsrc_mptestsrc.c
new file mode 100644
index 0000000000..e78c092847
--- /dev/null
+++ b/libavfilter/vsrc_mptestsrc.c
@@ -0,0 +1,392 @@
+/*
+ * Copyright (c) 2002 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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 FFmpeg; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+/**
+ * @file
+ * MP test source, ported from MPlayer libmpcodecs/vf_test.c
+ */
+
+#include "libavutil/avstring.h"
+#include "libavutil/opt.h"
+#include "libavutil/parseutils.h"
+#include "libavutil/pixdesc.h"
+#include "avfilter.h"
+
+#define WIDTH 512
+#define HEIGHT 512
+
+enum test_type {
+ TEST_DC_LUMA,
+ TEST_DC_CHROMA,
+ TEST_FREQ_LUMA,
+ TEST_FREQ_CHROMA,
+ TEST_AMP_LUMA,
+ TEST_AMP_CHROMA,
+ TEST_CBP,
+ TEST_MV,
+ TEST_RING1,
+ TEST_RING2,
+ TEST_ALL,
+ TEST_NB
+};
+
+typedef struct MPTestContext {
+ const AVClass *class;
+ unsigned int frame_nb;
+ AVRational time_base;
+ int64_t pts, max_pts;
+ int hsub, vsub;
+ char *size, *rate, *duration;
+ enum test_type test;
+} MPTestContext;
+
+#define OFFSET(x) offsetof(MPTestContext, x)
+
+static const AVOption mptestsrc_options[]= {
+ { "rate", "set video rate", OFFSET(rate), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0 },
+ { "r", "set video rate", OFFSET(rate), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0 },
+ { "duration", "set video duration", OFFSET(duration), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0 },
+ { "d", "set video duration", OFFSET(duration), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0 },
+
+ { "test", "set test to perform", OFFSET(test), AV_OPT_TYPE_INT, {.dbl=TEST_ALL}, 0, INT_MAX, 0, "test" },
+ { "t", "set test to perform", OFFSET(test), AV_OPT_TYPE_INT, {.dbl=TEST_ALL}, 0, INT_MAX, 0, "test" },
+ { "dc_luma", "", 0, AV_OPT_TYPE_CONST, {.dbl=TEST_DC_LUMA}, INT_MIN, INT_MAX, 0, "test" },
+ { "dc_chroma", "", 0, AV_OPT_TYPE_CONST, {.dbl=TEST_DC_CHROMA}, INT_MIN, INT_MAX, 0, "test" },
+ { "freq_luma", "", 0, AV_OPT_TYPE_CONST, {.dbl=TEST_FREQ_LUMA}, INT_MIN, INT_MAX, 0, "test" },
+ { "freq_chroma", "", 0, AV_OPT_TYPE_CONST, {.dbl=TEST_FREQ_CHROMA}, INT_MIN, INT_MAX, 0, "test" },
+ { "amp_luma", "", 0, AV_OPT_TYPE_CONST, {.dbl=TEST_AMP_LUMA}, INT_MIN, INT_MAX, 0, "test" },
+ { "amp_chroma", "", 0, AV_OPT_TYPE_CONST, {.dbl=TEST_AMP_CHROMA}, INT_MIN, INT_MAX, 0, "test" },
+ { "cbp", "", 0, AV_OPT_TYPE_CONST, {.dbl=TEST_CBP}, INT_MIN, INT_MAX, 0, "test" },
+ { "mv", "", 0, AV_OPT_TYPE_CONST, {.dbl=TEST_MV}, INT_MIN, INT_MAX, 0, "test" },
+ { "ring1", "", 0, AV_OPT_TYPE_CONST, {.dbl=TEST_RING1}, INT_MIN, INT_MAX, 0, "test" },
+ { "ring2", "", 0, AV_OPT_TYPE_CONST, {.dbl=TEST_RING2}, INT_MIN, INT_MAX, 0, "test" },
+ { "all", "", 0, AV_OPT_TYPE_CONST, {.dbl=TEST_ALL}, INT_MIN, INT_MAX, 0, "test" },
+
+ { NULL },
+};
+
+static const char *mptestsrc_get_name(void *ctx)
+{
+ return "mptestsrc";
+}
+
+static const AVClass mptestsrc_class = {
+ "MPTestContext",
+ mptestsrc_get_name,
+ mptestsrc_options
+};
+
+static double c[64];
+
+static void init_idct(void)
+{
+ int i, j;
+
+ for (i = 0; i < 8; i++) {
+ double s = i == 0 ? sqrt(0.125) : 0.5;
+
+ for (j = 0; j < 8; j++)
+ c[i*8+j] = s*cos((M_PI/8.0)*i*(j+0.5));
+ }
+}
+
+static void idct(uint8_t *dst, int dst_linesize, int src[64])
+{
+ int i, j, k;
+ double tmp[64];
+
+ for (i = 0; i < 8; i++) {
+ for (j = 0; j < 8; j++) {
+ double sum = 0.0;
+
+ for (k = 0; k < 8; k++)
+ sum += c[k*8+j] * src[8*i+k];
+
+ tmp[8*i+j] = sum;
+ }
+ }
+
+ for (j = 0; j < 8; j++) {
+ for (i = 0; i < 8; i++) {
+ double sum = 0.0;
+
+ for (k = 0; k < 8; k++)
+ sum += c[k*8+i]*tmp[8*k+j];
+
+ dst[dst_linesize*i + j] = av_clip((int)floor(sum+0.5), 0, 255);
+ }
+ }
+}
+
+static void draw_dc(uint8_t *dst, int dst_linesize, int color, int w, int h)
+{
+ int x, y;
+
+ for (y = 0; y < h; y++)
+ for (x = 0; x < w; x++)
+ dst[x + y*dst_linesize] = color;
+}
+
+static void draw_basis(uint8_t *dst, int dst_linesize, int amp, int freq, int dc)
+{
+ int src[64];
+
+ memset(src, 0, 64*sizeof(int));
+ src[0] = dc;
+ if (amp)
+ src[freq] = amp;
+ idct(dst, dst_linesize, src);
+}
+
+static void draw_cbp(uint8_t *dst[3], int dst_linesize[3], int cbp, int amp, int dc)
+{
+ if (cbp&1) draw_basis(dst[0] , dst_linesize[0], amp, 1, dc);
+ if (cbp&2) draw_basis(dst[0]+8 , dst_linesize[0], amp, 1, dc);
+ if (cbp&4) draw_basis(dst[0]+ 8*dst_linesize[0], dst_linesize[0], amp, 1, dc);
+ if (cbp&8) draw_basis(dst[0]+8+8*dst_linesize[0], dst_linesize[0], amp, 1, dc);
+ if (cbp&16) draw_basis(dst[1] , dst_linesize[1], amp, 1, dc);
+ if (cbp&32) draw_basis(dst[2] , dst_linesize[2], amp, 1, dc);
+}
+
+static void dc_test(uint8_t *dst, int dst_linesize, int w, int h, int off)
+{
+ const int step = FFMAX(256/(w*h/256), 1);
+ int x, y, color = off;
+
+ for (y = 0; y < h; y += 16) {
+ for (x = 0; x < w; x += 16) {
+ draw_dc(dst + x + y*dst_linesize, dst_linesize, color, 8, 8);
+ color += step;
+ }
+ }
+}
+
+static void freq_test(uint8_t *dst, int dst_linesize, int off)
+{
+ int x, y, freq = 0;
+
+ for (y = 0; y < 8*16; y += 16) {
+ for (x = 0; x < 8*16; x += 16) {
+ draw_basis(dst + x + y*dst_linesize, dst_linesize, 4*(96+off), freq, 128*8);
+ freq++;
+ }
+ }
+}
+
+static void amp_test(uint8_t *dst, int dst_linesize, int off)
+{
+ int x, y, amp = off;
+
+ for (y = 0; y < 16*16; y += 16) {
+ for (x = 0; x < 16*16; x += 16) {
+ draw_basis(dst + x + y*dst_linesize, dst_linesize, 4*amp, 1, 128*8);
+ amp++;
+ }
+ }
+}
+
+static void cbp_test(uint8_t *dst[3], int dst_linesize[3], int off)
+{
+ int x, y, cbp = 0;
+
+ for (y = 0; y < 16*8; y += 16) {
+ for (x = 0; x < 16*8; x += 16) {
+ uint8_t *dst1[3];
+ dst1[0] = dst[0] + x*2 + y*2*dst_linesize[0];
+ dst1[1] = dst[1] + x + y* dst_linesize[1];
+ dst1[2] = dst[2] + x + y* dst_linesize[2];
+
+ draw_cbp(dst1, dst_linesize, cbp, (64+off)*4, 128*8);
+ cbp++;
+ }
+ }
+}
+
+static void mv_test(uint8_t *dst, int dst_linesize, int off)
+{
+ int x, y;
+
+ for (y = 0; y < 16*16; y++) {
+ if (y&16)
+ continue;
+ for (x = 0; x < 16*16; x++)
+ dst[x + y*dst_linesize] = x + off*8/(y/32+1);
+ }
+}
+
+static void ring1_test(uint8_t *dst, int dst_linesize, int off)
+{
+ int x, y, color = 0;
+
+ for (y = off; y < 16*16; y += 16) {
+ for (x = off; x < 16*16; x += 16) {
+ draw_dc(dst + x + y*dst_linesize, dst_linesize, ((x+y)&16) ? color : -color, 16, 16);
+ color++;
+ }
+ }
+}
+
+static void ring2_test(uint8_t *dst, int dst_linesize, int off)
+{
+ int x, y;
+
+ for (y = 0; y < 16*16; y++) {
+ for (x = 0; x < 16*16; x++) {
+ double d = sqrt((x-8*16)*(x-8*16) + (y-8*16)*(y-8*16));
+ double r = d/20 - (int)(d/20);
+ if (r < off/30.0) {
+ dst[x + y*dst_linesize] = 255;
+ dst[x + y*dst_linesize+256] = 0;
+ } else {
+ dst[x + y*dst_linesize] = x;
+ dst[x + y*dst_linesize+256] = x;
+ }
+ }
+ }
+}
+
+static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
+{
+ MPTestContext *test = ctx->priv;
+ AVRational frame_rate_q;
+ int64_t duration = -1;
+ int ret;
+
+ test->class = &mptestsrc_class;
+ av_opt_set_defaults(test);
+
+ if ((ret = (av_set_options_string(test, args, "=", ":"))) < 0) {
+ av_log(ctx, AV_LOG_ERROR, "Error parsing options string: '%s'\n", args);
+ return ret;
+ }
+
+ if ((ret = av_parse_video_rate(&frame_rate_q, test->rate)) < 0 ||
+ frame_rate_q.den <= 0 || frame_rate_q.num <= 0) {
+ av_log(ctx, AV_LOG_ERROR, "Invalid frame rate: '%s'\n", test->rate);
+ return ret;
+ }
+
+ if ((test->duration) && (ret = av_parse_time(&duration, test->duration, 1)) < 0) {
+ av_log(ctx, AV_LOG_ERROR, "Invalid duration: '%s'\n", test->duration);
+ return ret;
+ }
+
+ test->time_base.num = frame_rate_q.den;
+ test->time_base.den = frame_rate_q.num;
+ test->max_pts = duration >= 0 ?
+ av_rescale_q(duration, AV_TIME_BASE_Q, test->time_base) : -1;
+ test->frame_nb = 0;
+ test->pts = 0;
+
+ av_log(ctx, AV_LOG_INFO, "rate:%d/%d duration:%f\n",
+ frame_rate_q.num, frame_rate_q.den,
+ duration < 0 ? -1 : test->max_pts * av_q2d(test->time_base));
+ init_idct();
+
+ return 0;
+}
+
+static int config_props(AVFilterLink *outlink)
+{
+ AVFilterContext *ctx = outlink->src;
+ MPTestContext *test = ctx->priv;
+ const AVPixFmtDescriptor *pix_desc = &av_pix_fmt_descriptors[outlink->format];
+
+ test->hsub = pix_desc->log2_chroma_w;
+ test->vsub = pix_desc->log2_chroma_h;
+
+ outlink->w = WIDTH;
+ outlink->h = HEIGHT;
+ outlink->time_base = test->time_base;
+
+ return 0;
+}
+
+static int query_formats(AVFilterContext *ctx)
+{
+ static const enum PixelFormat pix_fmts[] = {
+ PIX_FMT_YUV420P, PIX_FMT_NONE
+ };
+
+ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts));
+ return 0;
+}
+
+static int request_frame(AVFilterLink *outlink)
+{
+ MPTestContext *test = outlink->src->priv;
+ AVFilterBufferRef *picref;
+ int w = WIDTH, h = HEIGHT, ch = h>>test->vsub;
+ unsigned int frame = test->frame_nb;
+ enum test_type tt = test->test;
+
+ if (test->max_pts >= 0 && test->pts > test->max_pts)
+ return AVERROR_EOF;
+ picref = avfilter_get_video_buffer(outlink, AV_PERM_WRITE, w, h);
+ picref->pts = test->pts++;
+
+ // clean image
+ memset(picref->data[0], 0, picref->linesize[0] * h);
+ memset(picref->data[1], 128, picref->linesize[1] * ch);
+ memset(picref->data[2], 128, picref->linesize[2] * ch);
+
+ if (tt == TEST_ALL && frame%30) /* draw a black frame at the beginning of each test */
+ tt = (frame/30)%(TEST_NB-1);
+
+ switch (tt) {
+ case TEST_DC_LUMA: dc_test(picref->data[0], picref->linesize[0], 256, 256, frame%30); break;
+ case TEST_DC_CHROMA: dc_test(picref->data[1], picref->linesize[1], 256, 256, frame%30); break;
+ case TEST_FREQ_LUMA: freq_test(picref->data[0], picref->linesize[0], frame%30); break;
+ case TEST_FREQ_CHROMA: freq_test(picref->data[1], picref->linesize[1], frame%30); break;
+ case TEST_AMP_LUMA: amp_test(picref->data[0], picref->linesize[0], frame%30); break;
+ case TEST_AMP_CHROMA: amp_test(picref->data[1], picref->linesize[1], frame%30); break;
+ case TEST_CBP: cbp_test(picref->data , picref->linesize , frame%30); break;
+ case TEST_MV: mv_test(picref->data[0], picref->linesize[0], frame%30); break;
+ case TEST_RING1: ring1_test(picref->data[0], picref->linesize[0], frame%30); break;
+ case TEST_RING2: ring2_test(picref->data[0], picref->linesize[0], frame%30); break;
+ }
+
+ test->frame_nb++;
+
+ avfilter_start_frame(outlink, avfilter_ref_buffer(picref, ~0));
+ avfilter_draw_slice(outlink, 0, picref->video->h, 1);
+ avfilter_end_frame(outlink);
+ avfilter_unref_buffer(picref);
+
+ return 0;
+}
+
+AVFilter avfilter_vsrc_mptestsrc = {
+ .name = "mptestsrc",
+ .description = NULL_IF_CONFIG_SMALL("Generate various test pattern."),
+ .priv_size = sizeof(MPTestContext),
+ .init = init,
+
+ .query_formats = query_formats,
+
+ .inputs = (AVFilterPad[]) {{ .name = NULL}},
+
+ .outputs = (AVFilterPad[]) {{ .name = "default",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .config_props = config_props,
+ .request_frame = request_frame,
+ .config_props = config_props, },
+ { .name = NULL }},
+};
diff --git a/libavfilter/vsrc_nullsrc.c b/libavfilter/vsrc_nullsrc.c
index dfd56fa495..b6d3567877 100644
--- a/libavfilter/vsrc_nullsrc.c
+++ b/libavfilter/vsrc_nullsrc.c
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -28,17 +28,11 @@
#include "avfilter.h"
static const char *var_names[] = {
- "E",
- "PHI",
- "PI",
"AVTB", /* default timebase 1/AV_TIME_BASE */
NULL
};
enum var_name {
- VAR_E,
- VAR_PHI,
- VAR_PI,
VAR_AVTB,
VAR_VARS_NB
};
@@ -76,9 +70,6 @@ static int config_props(AVFilterLink *outlink)
int ret;
double res;
- priv->var_values[VAR_E] = M_E;
- priv->var_values[VAR_PHI] = M_PHI;
- priv->var_values[VAR_PI] = M_PI;
priv->var_values[VAR_AVTB] = av_q2d(AV_TIME_BASE_Q);
if ((ret = av_expr_parse_and_eval(&res, priv->tb_expr, var_names, priv->var_values,
diff --git a/libavfilter/vsrc_testsrc.c b/libavfilter/vsrc_testsrc.c
new file mode 100644
index 0000000000..2447cb355c
--- /dev/null
+++ b/libavfilter/vsrc_testsrc.c
@@ -0,0 +1,498 @@
+/*
+ * Copyright (c) 2007 Nicolas George <nicolas.george@normalesup.org>
+ * Copyright (c) 2011 Stefano Sabatini
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * Misc test sources.
+ *
+ * testsrc is based on the test pattern generator demuxer by Nicolas George:
+ * http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/2007-October/037845.html
+ *
+ * rgbtestsrc is ported from MPlayer libmpcodecs/vf_rgbtest.c by
+ * Michael Niedermayer.
+ */
+
+#include <float.h>
+
+#include "libavutil/opt.h"
+#include "libavutil/intreadwrite.h"
+#include "libavutil/parseutils.h"
+#include "avfilter.h"
+
+typedef struct {
+ const AVClass *class;
+ int h, w;
+ unsigned int nb_frame;
+ AVRational time_base;
+ int64_t pts, max_pts;
+ char *size; ///< video frame size
+ char *rate; ///< video frame rate
+ char *duration; ///< total duration of the generated video
+ AVRational sar; ///< sample aspect ratio
+
+ void (* fill_picture_fn)(AVFilterContext *ctx, AVFilterBufferRef *picref);
+
+ /* only used by rgbtest */
+ int rgba_map[4];
+} TestSourceContext;
+
+#define OFFSET(x) offsetof(TestSourceContext, x)
+
+static const AVOption testsrc_options[]= {
+ { "size", "set video size", OFFSET(size), AV_OPT_TYPE_STRING, {.str = "320x240"}, 0, 0 },
+ { "s", "set video size", OFFSET(size), AV_OPT_TYPE_STRING, {.str = "320x240"}, 0, 0 },
+ { "rate", "set video rate", OFFSET(rate), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0 },
+ { "r", "set video rate", OFFSET(rate), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0 },
+ { "duration", "set video duration", OFFSET(duration), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0 },
+ { "sar", "set video sample aspect ratio", OFFSET(sar), AV_OPT_TYPE_RATIONAL, {.dbl= 1}, 0, INT_MAX },
+ { NULL },
+};
+
+static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
+{
+ TestSourceContext *test = ctx->priv;
+ AVRational frame_rate_q;
+ int64_t duration = -1;
+ int ret = 0;
+
+ av_opt_set_defaults(test);
+
+ if ((ret = (av_set_options_string(test, args, "=", ":"))) < 0) {
+ av_log(ctx, AV_LOG_ERROR, "Error parsing options string: '%s'\n", args);
+ return ret;
+ }
+
+ if ((ret = av_parse_video_size(&test->w, &test->h, test->size)) < 0) {
+ av_log(ctx, AV_LOG_ERROR, "Invalid frame size: '%s'\n", test->size);
+ return ret;
+ }
+
+ if ((ret = av_parse_video_rate(&frame_rate_q, test->rate)) < 0 ||
+ frame_rate_q.den <= 0 || frame_rate_q.num <= 0) {
+ av_log(ctx, AV_LOG_ERROR, "Invalid frame rate: '%s'\n", test->rate);
+ return ret;
+ }
+
+ if ((test->duration) && (ret = av_parse_time(&duration, test->duration, 1)) < 0) {
+ av_log(ctx, AV_LOG_ERROR, "Invalid duration: '%s'\n", test->duration);
+ return ret;
+ }
+
+ test->time_base.num = frame_rate_q.den;
+ test->time_base.den = frame_rate_q.num;
+ test->max_pts = duration >= 0 ?
+ av_rescale_q(duration, AV_TIME_BASE_Q, test->time_base) : -1;
+ test->nb_frame = 0;
+ test->pts = 0;
+
+ av_log(ctx, AV_LOG_DEBUG, "size:%dx%d rate:%d/%d duration:%f sar:%d/%d\n",
+ test->w, test->h, frame_rate_q.num, frame_rate_q.den,
+ duration < 0 ? -1 : test->max_pts * av_q2d(test->time_base),
+ test->sar.num, test->sar.den);
+ return 0;
+}
+
+static int config_props(AVFilterLink *outlink)
+{
+ TestSourceContext *test = outlink->src->priv;
+
+ outlink->w = test->w;
+ outlink->h = test->h;
+ outlink->sample_aspect_ratio = test->sar;
+ outlink->time_base = test->time_base;
+
+ return 0;
+}
+
+static int request_frame(AVFilterLink *outlink)
+{
+ TestSourceContext *test = outlink->src->priv;
+ AVFilterBufferRef *picref;
+
+ if (test->max_pts >= 0 && test->pts > test->max_pts)
+ return AVERROR_EOF;
+ picref = avfilter_get_video_buffer(outlink, AV_PERM_WRITE,
+ test->w, test->h);
+ picref->pts = test->pts++;
+ picref->pos = -1;
+ picref->video->key_frame = 1;
+ picref->video->interlaced = 0;
+ picref->video->pict_type = AV_PICTURE_TYPE_I;
+ picref->video->sample_aspect_ratio = test->sar;
+ test->nb_frame++;
+ test->fill_picture_fn(outlink->src, picref);
+
+ avfilter_start_frame(outlink, avfilter_ref_buffer(picref, ~0));
+ avfilter_draw_slice(outlink, 0, picref->video->h, 1);
+ avfilter_end_frame(outlink);
+ avfilter_unref_buffer(picref);
+
+ return 0;
+}
+
+#if CONFIG_TESTSRC_FILTER
+
+static const char *testsrc_get_name(void *ctx)
+{
+ return "testsrc";
+}
+
+static const AVClass testsrc_class = {
+ .class_name = "TestSourceContext",
+ .item_name = testsrc_get_name,
+ .option = testsrc_options,
+};
+
+/**
+ * Fill a rectangle with value val.
+ *
+ * @param val the RGB value to set
+ * @param dst pointer to the destination buffer to fill
+ * @param dst_linesize linesize of destination
+ * @param segment_width width of the segment
+ * @param x horizontal coordinate where to draw the rectangle in the destination buffer
+ * @param y horizontal coordinate where to draw the rectangle in the destination buffer
+ * @param w width of the rectangle to draw, expressed as a number of segment_width units
+ * @param h height of the rectangle to draw, expressed as a number of segment_width units
+ */
+static void draw_rectangle(unsigned val, uint8_t *dst, int dst_linesize, unsigned segment_width,
+ unsigned x, unsigned y, unsigned w, unsigned h)
+{
+ int i;
+ int step = 3;
+
+ dst += segment_width * (step * x + y * dst_linesize);
+ w *= segment_width * step;
+ h *= segment_width;
+ for (i = 0; i < h; i++) {
+ memset(dst, val, w);
+ dst += dst_linesize;
+ }
+}
+
+static void draw_digit(int digit, uint8_t *dst, unsigned dst_linesize,
+ unsigned segment_width)
+{
+#define TOP_HBAR 1
+#define MID_HBAR 2
+#define BOT_HBAR 4
+#define LEFT_TOP_VBAR 8
+#define LEFT_BOT_VBAR 16
+#define RIGHT_TOP_VBAR 32
+#define RIGHT_BOT_VBAR 64
+ struct {
+ int x, y, w, h;
+ } segments[] = {
+ { 1, 0, 5, 1 }, /* TOP_HBAR */
+ { 1, 6, 5, 1 }, /* MID_HBAR */
+ { 1, 12, 5, 1 }, /* BOT_HBAR */
+ { 0, 1, 1, 5 }, /* LEFT_TOP_VBAR */
+ { 0, 7, 1, 5 }, /* LEFT_BOT_VBAR */
+ { 6, 1, 1, 5 }, /* RIGHT_TOP_VBAR */
+ { 6, 7, 1, 5 } /* RIGHT_BOT_VBAR */
+ };
+ static const unsigned char masks[10] = {
+ /* 0 */ TOP_HBAR |BOT_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR|RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
+ /* 1 */ RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
+ /* 2 */ TOP_HBAR|MID_HBAR|BOT_HBAR|LEFT_BOT_VBAR |RIGHT_TOP_VBAR,
+ /* 3 */ TOP_HBAR|MID_HBAR|BOT_HBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
+ /* 4 */ MID_HBAR |LEFT_TOP_VBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
+ /* 5 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR |RIGHT_BOT_VBAR,
+ /* 6 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR |RIGHT_BOT_VBAR,
+ /* 7 */ TOP_HBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
+ /* 8 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR|RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
+ /* 9 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
+ };
+ unsigned mask = masks[digit];
+ int i;
+
+ draw_rectangle(0, dst, dst_linesize, segment_width, 0, 0, 8, 13);
+ for (i = 0; i < FF_ARRAY_ELEMS(segments); i++)
+ if (mask & (1<<i))
+ draw_rectangle(255, dst, dst_linesize, segment_width,
+ segments[i].x, segments[i].y, segments[i].w, segments[i].h);
+}
+
+#define GRADIENT_SIZE (6 * 256)
+
+static void test_fill_picture(AVFilterContext *ctx, AVFilterBufferRef *picref)
+{
+ TestSourceContext *test = ctx->priv;
+ uint8_t *p, *p0;
+ int x, y;
+ int color, color_rest;
+ int icolor;
+ int radius;
+ int quad0, quad;
+ int dquad_x, dquad_y;
+ int grad, dgrad, rgrad, drgrad;
+ int seg_size;
+ int second;
+ int i;
+ uint8_t *data = picref->data[0];
+ int width = picref->video->w;
+ int height = picref->video->h;
+
+ /* draw colored bars and circle */
+ radius = (width + height) / 4;
+ quad0 = width * width / 4 + height * height / 4 - radius * radius;
+ dquad_y = 1 - height;
+ p0 = data;
+ for (y = 0; y < height; y++) {
+ p = p0;
+ color = 0;
+ color_rest = 0;
+ quad = quad0;
+ dquad_x = 1 - width;
+ for (x = 0; x < width; x++) {
+ icolor = color;
+ if (quad < 0)
+ icolor ^= 7;
+ quad += dquad_x;
+ dquad_x += 2;
+ *(p++) = icolor & 1 ? 255 : 0;
+ *(p++) = icolor & 2 ? 255 : 0;
+ *(p++) = icolor & 4 ? 255 : 0;
+ color_rest += 8;
+ if (color_rest >= width) {
+ color_rest -= width;
+ color++;
+ }
+ }
+ quad0 += dquad_y;
+ dquad_y += 2;
+ p0 += picref->linesize[0];
+ }
+
+ /* draw sliding color line */
+ p = data + picref->linesize[0] * height * 3/4;
+ grad = (256 * test->nb_frame * test->time_base.num / test->time_base.den) %
+ GRADIENT_SIZE;
+ rgrad = 0;
+ dgrad = GRADIENT_SIZE / width;
+ drgrad = GRADIENT_SIZE % width;
+ for (x = 0; x < width; x++) {
+ *(p++) =
+ grad < 256 || grad >= 5 * 256 ? 255 :
+ grad >= 2 * 256 && grad < 4 * 256 ? 0 :
+ grad < 2 * 256 ? 2 * 256 - 1 - grad : grad - 4 * 256;
+ *(p++) =
+ grad >= 4 * 256 ? 0 :
+ grad >= 1 * 256 && grad < 3 * 256 ? 255 :
+ grad < 1 * 256 ? grad : 4 * 256 - 1 - grad;
+ *(p++) =
+ grad < 2 * 256 ? 0 :
+ grad >= 3 * 256 && grad < 5 * 256 ? 255 :
+ grad < 3 * 256 ? grad - 2 * 256 : 6 * 256 - 1 - grad;
+ grad += dgrad;
+ rgrad += drgrad;
+ if (rgrad >= GRADIENT_SIZE) {
+ grad++;
+ rgrad -= GRADIENT_SIZE;
+ }
+ if (grad >= GRADIENT_SIZE)
+ grad -= GRADIENT_SIZE;
+ }
+ for (y = height / 8; y > 0; y--) {
+ memcpy(p, p - picref->linesize[0], 3 * width);
+ p += picref->linesize[0];
+ }
+
+ /* draw digits */
+ seg_size = width / 80;
+ if (seg_size >= 1 && height >= 13 * seg_size) {
+ second = test->nb_frame * test->time_base.num / test->time_base.den;
+ x = width - (width - seg_size * 64) / 2;
+ y = (height - seg_size * 13) / 2;
+ p = data + (x*3 + y * picref->linesize[0]);
+ for (i = 0; i < 8; i++) {
+ p -= 3 * 8 * seg_size;
+ draw_digit(second % 10, p, picref->linesize[0], seg_size);
+ second /= 10;
+ if (second == 0)
+ break;
+ }
+ }
+}
+
+static av_cold int test_init(AVFilterContext *ctx, const char *args, void *opaque)
+{
+ TestSourceContext *test = ctx->priv;
+
+ test->class = &testsrc_class;
+ test->fill_picture_fn = test_fill_picture;
+ return init(ctx, args, opaque);
+}
+
+static int test_query_formats(AVFilterContext *ctx)
+{
+ static const enum PixelFormat pix_fmts[] = {
+ PIX_FMT_RGB24, PIX_FMT_NONE
+ };
+ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts));
+ return 0;
+}
+
+AVFilter avfilter_vsrc_testsrc = {
+ .name = "testsrc",
+ .description = NULL_IF_CONFIG_SMALL("Generate test pattern."),
+ .priv_size = sizeof(TestSourceContext),
+ .init = test_init,
+
+ .query_formats = test_query_formats,
+
+ .inputs = (AVFilterPad[]) {{ .name = NULL}},
+
+ .outputs = (AVFilterPad[]) {{ .name = "default",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .request_frame = request_frame,
+ .config_props = config_props, },
+ { .name = NULL }},
+};
+
+#endif /* CONFIG_TESTSRC_FILTER */
+
+#if CONFIG_RGBTESTSRC_FILTER
+
+static const char *rgbtestsrc_get_name(void *ctx)
+{
+ return "rgbtestsrc";
+}
+
+static const AVClass rgbtestsrc_class = {
+ .class_name = "RGBTestSourceContext",
+ .item_name = rgbtestsrc_get_name,
+ .option = testsrc_options,
+};
+
+#define R 0
+#define G 1
+#define B 2
+#define A 3
+
+static void rgbtest_put_pixel(uint8_t *dst, int dst_linesize,
+ int x, int y, int r, int g, int b, enum PixelFormat fmt,
+ int rgba_map[4])
+{
+ int32_t v;
+ uint8_t *p;
+
+ switch (fmt) {
+ case PIX_FMT_BGR444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r >> 4) << 8) | ((g >> 4) << 4) | (b >> 4); break;
+ case PIX_FMT_RGB444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b >> 4) << 8) | ((g >> 4) << 4) | (r >> 4); break;
+ case PIX_FMT_BGR555: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r>>3)<<10) | ((g>>3)<<5) | (b>>3); break;
+ case PIX_FMT_RGB555: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b>>3)<<10) | ((g>>3)<<5) | (r>>3); break;
+ case PIX_FMT_BGR565: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r>>3)<<11) | ((g>>2)<<5) | (b>>3); break;
+ case PIX_FMT_RGB565: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b>>3)<<11) | ((g>>2)<<5) | (r>>3); break;
+ case PIX_FMT_RGB24:
+ case PIX_FMT_BGR24:
+ v = (r << (rgba_map[R]*8)) + (g << (rgba_map[G]*8)) + (b << (rgba_map[B]*8));
+ p = dst + 3*x + y*dst_linesize;
+ AV_WL24(p, v);
+ break;
+ case PIX_FMT_RGBA:
+ case PIX_FMT_BGRA:
+ case PIX_FMT_ARGB:
+ case PIX_FMT_ABGR:
+ v = (r << (rgba_map[R]*8)) + (g << (rgba_map[G]*8)) + (b << (rgba_map[B]*8));
+ p = dst + 4*x + y*dst_linesize;
+ AV_WL32(p, v);
+ break;
+ }
+}
+
+static void rgbtest_fill_picture(AVFilterContext *ctx, AVFilterBufferRef *picref)
+{
+ TestSourceContext *test = ctx->priv;
+ int x, y, w = picref->video->w, h = picref->video->h;
+
+ for (y = 0; y < h; y++) {
+ for (x = 0; x < picref->video->w; x++) {
+ int c = 256*x/w;
+ int r = 0, g = 0, b = 0;
+
+ if (3*y < h ) r = c;
+ else if (3*y < 2*h) g = c;
+ else b = c;
+
+ rgbtest_put_pixel(picref->data[0], picref->linesize[0], x, y, r, g, b,
+ ctx->outputs[0]->format, test->rgba_map);
+ }
+ }
+}
+
+static av_cold int rgbtest_init(AVFilterContext *ctx, const char *args, void *opaque)
+{
+ TestSourceContext *test = ctx->priv;
+
+ test->class = &rgbtestsrc_class;
+ test->fill_picture_fn = rgbtest_fill_picture;
+ return init(ctx, args, opaque);
+}
+
+static int rgbtest_query_formats(AVFilterContext *ctx)
+{
+ static const enum PixelFormat pix_fmts[] = {
+ PIX_FMT_RGBA, PIX_FMT_ARGB, PIX_FMT_BGRA, PIX_FMT_ABGR,
+ PIX_FMT_BGR24, PIX_FMT_RGB24,
+ PIX_FMT_RGB444, PIX_FMT_BGR444,
+ PIX_FMT_RGB565, PIX_FMT_BGR565,
+ PIX_FMT_RGB555, PIX_FMT_BGR555,
+ PIX_FMT_NONE
+ };
+ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts));
+ return 0;
+}
+
+static int rgbtest_config_props(AVFilterLink *outlink)
+{
+ TestSourceContext *test = outlink->src->priv;
+
+ switch (outlink->format) {
+ case PIX_FMT_ARGB: test->rgba_map[A] = 0; test->rgba_map[R] = 1; test->rgba_map[G] = 2; test->rgba_map[B] = 3; break;
+ case PIX_FMT_ABGR: test->rgba_map[A] = 0; test->rgba_map[B] = 1; test->rgba_map[G] = 2; test->rgba_map[R] = 3; break;
+ case PIX_FMT_RGBA:
+ case PIX_FMT_RGB24: test->rgba_map[R] = 0; test->rgba_map[G] = 1; test->rgba_map[B] = 2; test->rgba_map[A] = 3; break;
+ case PIX_FMT_BGRA:
+ case PIX_FMT_BGR24: test->rgba_map[B] = 0; test->rgba_map[G] = 1; test->rgba_map[R] = 2; test->rgba_map[A] = 3; break;
+ }
+
+ return config_props(outlink);
+}
+
+AVFilter avfilter_vsrc_rgbtestsrc = {
+ .name = "rgbtestsrc",
+ .description = NULL_IF_CONFIG_SMALL("Generate RGB test pattern."),
+ .priv_size = sizeof(TestSourceContext),
+ .init = rgbtest_init,
+
+ .query_formats = rgbtest_query_formats,
+
+ .inputs = (AVFilterPad[]) {{ .name = NULL}},
+
+ .outputs = (AVFilterPad[]) {{ .name = "default",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .request_frame = request_frame,
+ .config_props = rgbtest_config_props, },
+ { .name = NULL }},
+};
+
+#endif /* CONFIG_RGBTESTSRC_FILTER */
diff --git a/libavfilter/x86/gradfun.c b/libavfilter/x86/gradfun.c
index ff3b19d38d..e892117d67 100644
--- a/libavfilter/x86/gradfun.c
+++ b/libavfilter/x86/gradfun.c
@@ -1,20 +1,20 @@
/*
* Copyright (C) 2009 Loren Merritt <lorenm@u.washignton.edu>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -25,7 +25,7 @@
DECLARE_ALIGNED(16, static const uint16_t, pw_7f)[8] = {0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F};
DECLARE_ALIGNED(16, static const uint16_t, pw_ff)[8] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
-void ff_gradfun_filter_line_mmx2(uint8_t *dst, uint8_t *src, uint16_t *dc, int width, int thresh, const uint16_t *dithers)
+void ff_gradfun_filter_line_mmx2(uint8_t *dst, const uint8_t *src, const uint16_t *dc, int width, int thresh, const uint16_t *dithers)
{
#if HAVE_MMX
intptr_t x;
@@ -73,7 +73,7 @@ void ff_gradfun_filter_line_mmx2(uint8_t *dst, uint8_t *src, uint16_t *dc, int w
#endif
}
-void ff_gradfun_filter_line_ssse3(uint8_t *dst, uint8_t *src, uint16_t *dc, int width, int thresh, const uint16_t *dithers)
+void ff_gradfun_filter_line_ssse3(uint8_t *dst, const uint8_t *src, const uint16_t *dc, int width, int thresh, const uint16_t *dithers)
{
#if HAVE_SSSE3
intptr_t x;
@@ -120,7 +120,7 @@ void ff_gradfun_filter_line_ssse3(uint8_t *dst, uint8_t *src, uint16_t *dc, int
#endif // HAVE_SSSE3
}
-void ff_gradfun_blur_line_sse2(uint16_t *dc, uint16_t *buf, uint16_t *buf1, uint8_t *src, int src_linesize, int width)
+void ff_gradfun_blur_line_sse2(uint16_t *dc, uint16_t *buf, const uint16_t *buf1, const uint8_t *src, int src_linesize, int width)
{
#if HAVE_SSE
#define BLURV(load)\
diff --git a/libavfilter/x86/yadif.c b/libavfilter/x86/yadif.c
index 7cd7e19258..2b55c00763 100644
--- a/libavfilter/x86/yadif.c
+++ b/libavfilter/x86/yadif.c
@@ -1,20 +1,20 @@
/*
* Copyright (C) 2006 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or modify
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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 Libav; if not, write to the Free Software Foundation, Inc.,
+ * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
diff --git a/libavfilter/x86/yadif_template.c b/libavfilter/x86/yadif_template.c
index 962a7c777d..0b60526007 100644
--- a/libavfilter/x86/yadif_template.c
+++ b/libavfilter/x86/yadif_template.c
@@ -1,20 +1,20 @@
/*
* Copyright (C) 2006 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or modify
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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 Libav; if not, write to the Free Software Foundation, Inc.,
+ * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
@@ -107,10 +107,8 @@ void RENAME(ff_yadif_filter_line)(uint8_t *dst,
uint8_t *prev, uint8_t *cur, uint8_t *next,
int w, int prefs, int mrefs, int parity, int mode)
{
- DECLARE_ALIGNED(16, uint8_t, tmp0[16]);
- DECLARE_ALIGNED(16, uint8_t, tmp1[16]);
- DECLARE_ALIGNED(16, uint8_t, tmp2[16]);
- DECLARE_ALIGNED(16, uint8_t, tmp3[16]);
+ uint8_t tmp[5*16];
+ uint8_t *tmpA= (uint8_t*)(((uint64_t)(tmp+15)) & ~15);
int x;
#define FILTER\
@@ -124,9 +122,9 @@ void RENAME(ff_yadif_filter_line)(uint8_t *dst,
MOVQ" "MM"3, "MM"4 \n\t"\
"paddw "MM"2, "MM"3 \n\t"\
"psraw $1, "MM"3 \n\t" /* d = (prev2[x] + next2[x])>>1 */\
- MOVQ" "MM"0, %[tmp0] \n\t" /* c */\
- MOVQ" "MM"3, %[tmp1] \n\t" /* d */\
- MOVQ" "MM"1, %[tmp2] \n\t" /* e */\
+ MOVQ" "MM"0, (%[tmpA]) \n\t" /* c */\
+ MOVQ" "MM"3, 16(%[tmpA]) \n\t" /* d */\
+ MOVQ" "MM"1, 32(%[tmpA]) \n\t" /* e */\
"psubw "MM"4, "MM"2 \n\t"\
PABS( MM"4", MM"2") /* temporal_diff0 */\
LOAD("(%[prev],%[mrefs])", MM"3") /* prev[x-refs] */\
@@ -148,7 +146,7 @@ void RENAME(ff_yadif_filter_line)(uint8_t *dst,
"paddw "MM"4, "MM"3 \n\t" /* temporal_diff2 */\
"psrlw $1, "MM"3 \n\t"\
"pmaxsw "MM"3, "MM"2 \n\t"\
- MOVQ" "MM"2, %[tmp3] \n\t" /* diff */\
+ MOVQ" "MM"2, 48(%[tmpA]) \n\t" /* diff */\
\
"paddw "MM"0, "MM"1 \n\t"\
"paddw "MM"0, "MM"0 \n\t"\
@@ -179,7 +177,7 @@ void RENAME(ff_yadif_filter_line)(uint8_t *dst,
CHECK2\
\
/* if(p->mode<2) ... */\
- MOVQ" %[tmp3], "MM"6 \n\t" /* diff */\
+ MOVQ" 48(%[tmpA]), "MM"6 \n\t" /* diff */\
"cmpl $2, %[mode] \n\t"\
"jge 1f \n\t"\
LOAD("(%["prev2"],%[mrefs],2)", MM"2") /* prev2[x-2*refs] */\
@@ -190,9 +188,9 @@ void RENAME(ff_yadif_filter_line)(uint8_t *dst,
"paddw "MM"5, "MM"3 \n\t"\
"psrlw $1, "MM"2 \n\t" /* b */\
"psrlw $1, "MM"3 \n\t" /* f */\
- MOVQ" %[tmp0], "MM"4 \n\t" /* c */\
- MOVQ" %[tmp1], "MM"5 \n\t" /* d */\
- MOVQ" %[tmp2], "MM"7 \n\t" /* e */\
+ MOVQ" (%[tmpA]), "MM"4 \n\t" /* c */\
+ MOVQ" 16(%[tmpA]), "MM"5 \n\t" /* d */\
+ MOVQ" 32(%[tmpA]), "MM"7 \n\t" /* e */\
"psubw "MM"4, "MM"2 \n\t" /* b-c */\
"psubw "MM"7, "MM"3 \n\t" /* f-e */\
MOVQ" "MM"5, "MM"0 \n\t"\
@@ -211,7 +209,7 @@ void RENAME(ff_yadif_filter_line)(uint8_t *dst,
"pmaxsw "MM"4, "MM"6 \n\t" /* diff= MAX3(diff, min, -max); */\
"1: \n\t"\
\
- MOVQ" %[tmp1], "MM"2 \n\t" /* d */\
+ MOVQ" 16(%[tmpA]), "MM"2 \n\t" /* d */\
MOVQ" "MM"2, "MM"3 \n\t"\
"psubw "MM"6, "MM"2 \n\t" /* d-diff */\
"paddw "MM"6, "MM"3 \n\t" /* d+diff */\
@@ -219,11 +217,9 @@ void RENAME(ff_yadif_filter_line)(uint8_t *dst,
"pminsw "MM"3, "MM"1 \n\t" /* d = clip(spatial_pred, d-diff, d+diff); */\
"packuswb "MM"1, "MM"1 \n\t"\
\
- :[tmp0]"=m"(tmp0),\
- [tmp1]"=m"(tmp1),\
- [tmp2]"=m"(tmp2),\
- [tmp3]"=m"(tmp3)\
- :[prev] "r"(prev),\
+ :\
+ :[tmpA] "r"(tmpA),\
+ [prev] "r"(prev),\
[cur] "r"(cur),\
[next] "r"(next),\
[prefs]"r"((x86_reg)prefs),\
diff --git a/libavfilter/yadif.h b/libavfilter/yadif.h
index d658b683d7..ff574daf49 100644
--- a/libavfilter/yadif.h
+++ b/libavfilter/yadif.h
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or modify
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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 Libav; if not, write to the Free Software Foundation, Inc.,
+ * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
diff --git a/libavformat/4xm.c b/libavformat/4xm.c
index 32699da439..3bb8bbdbdc 100644
--- a/libavformat/4xm.c
+++ b/libavformat/4xm.c
@@ -2,20 +2,20 @@
* 4X Technologies .4xm File Demuxer (no muxer)
* Copyright (c) 2003 The ffmpeg Project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -141,7 +141,7 @@ static int fourxm_read_header(AVFormatContext *s,
fourxm->height = AV_RL32(&header[i + 40]);
/* allocate a new AVStream */
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st){
ret= AVERROR(ENOMEM);
goto fail;
@@ -173,13 +173,16 @@ static int fourxm_read_header(AVFormatContext *s,
goto fail;
}
if (current_track + 1 > fourxm->track_count) {
- fourxm->track_count = current_track + 1;
- fourxm->tracks = av_realloc(fourxm->tracks,
- fourxm->track_count * sizeof(AudioTrack));
+ fourxm->tracks = av_realloc_f(fourxm->tracks,
+ sizeof(AudioTrack),
+ current_track + 1);
if (!fourxm->tracks) {
- ret= AVERROR(ENOMEM);
+ ret = AVERROR(ENOMEM);
goto fail;
}
+ memset(&fourxm->tracks[fourxm->track_count], 0,
+ sizeof(AudioTrack) * (current_track + 1 - fourxm->track_count));
+ fourxm->track_count = current_track + 1;
}
fourxm->tracks[current_track].adpcm = AV_RL32(&header[i + 12]);
fourxm->tracks[current_track].channels = AV_RL32(&header[i + 36]);
@@ -196,12 +199,13 @@ static int fourxm_read_header(AVFormatContext *s,
i += 8 + size;
/* allocate a new AVStream */
- st = av_new_stream(s, current_track);
+ st = avformat_new_stream(s, NULL);
if (!st){
ret= AVERROR(ENOMEM);
goto fail;
}
+ st->id = current_track;
av_set_pts_info(st, 60, 1, fourxm->tracks[current_track].sample_rate);
fourxm->tracks[current_track].stream_index = st->index;
@@ -260,7 +264,7 @@ static int fourxm_read_packet(AVFormatContext *s,
return ret;
fourcc_tag = AV_RL32(&header[0]);
size = AV_RL32(&header[4]);
- if (pb->eof_reached)
+ if (url_feof(pb))
return AVERROR(EIO);
switch (fourcc_tag) {
@@ -345,11 +349,11 @@ static int fourxm_read_close(AVFormatContext *s)
}
AVInputFormat ff_fourxm_demuxer = {
- "4xm",
- NULL_IF_CONFIG_SMALL("4X Technologies format"),
- sizeof(FourxmDemuxContext),
- fourxm_probe,
- fourxm_read_header,
- fourxm_read_packet,
- fourxm_read_close,
+ .name = "4xm",
+ .long_name = NULL_IF_CONFIG_SMALL("4X Technologies format"),
+ .priv_data_size = sizeof(FourxmDemuxContext),
+ .read_probe = fourxm_probe,
+ .read_header = fourxm_read_header,
+ .read_packet = fourxm_read_packet,
+ .read_close = fourxm_read_close,
};
diff --git a/libavformat/Makefile b/libavformat/Makefile
index a20db26b03..15ccb291ed 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -1,3 +1,5 @@
+include $(SUBDIR)../config.mak
+
NAME = avformat
FFLIBS = avcodec avutil
@@ -19,10 +21,12 @@ OBJS-$(CONFIG_A64_MUXER) += a64.o
OBJS-$(CONFIG_AAC_DEMUXER) += aacdec.o rawdec.o
OBJS-$(CONFIG_AC3_DEMUXER) += ac3dec.o rawdec.o
OBJS-$(CONFIG_AC3_MUXER) += rawenc.o
+OBJS-$(CONFIG_ACT_DEMUXER) += act.o
+OBJS-$(CONFIG_ADF_DEMUXER) += bintext.o sauce.o
OBJS-$(CONFIG_ADTS_MUXER) += adtsenc.o
OBJS-$(CONFIG_AEA_DEMUXER) += aea.o pcm.o
-OBJS-$(CONFIG_AIFF_DEMUXER) += aiffdec.o riff.o pcm.o
-OBJS-$(CONFIG_AIFF_MUXER) += aiffenc.o riff.o
+OBJS-$(CONFIG_AIFF_DEMUXER) += aiffdec.o riff.o pcm.o isom.o
+OBJS-$(CONFIG_AIFF_MUXER) += aiffenc.o riff.o isom.o
OBJS-$(CONFIG_AMR_DEMUXER) += amr.o
OBJS-$(CONFIG_AMR_MUXER) += amr.o
OBJS-$(CONFIG_ANM_DEMUXER) += anm.o
@@ -44,8 +48,12 @@ OBJS-$(CONFIG_AVS_DEMUXER) += avs.o vocdec.o voc.o
OBJS-$(CONFIG_BETHSOFTVID_DEMUXER) += bethsoftvid.o
OBJS-$(CONFIG_BFI_DEMUXER) += bfi.o
OBJS-$(CONFIG_BINK_DEMUXER) += bink.o
+OBJS-$(CONFIG_BINTEXT_DEMUXER) += bintext.o sauce.o
+OBJS-$(CONFIG_BIT_DEMUXER) += bit.o
+OBJS-$(CONFIG_BIT_MUXER) += bit.o
OBJS-$(CONFIG_C93_DEMUXER) += c93.o vocdec.o voc.o
OBJS-$(CONFIG_CAF_DEMUXER) += cafdec.o caf.o mov.o riff.o isom.o
+OBJS-$(CONFIG_CAF_MUXER) += cafenc.o caf.o riff.o isom.o
OBJS-$(CONFIG_CAVSVIDEO_DEMUXER) += cavsvideodec.o rawdec.o
OBJS-$(CONFIG_CAVSVIDEO_MUXER) += rawenc.o
OBJS-$(CONFIG_CDG_DEMUXER) += cdg.o
@@ -90,6 +98,8 @@ OBJS-$(CONFIG_GXF_DEMUXER) += gxf.o
OBJS-$(CONFIG_GXF_MUXER) += gxfenc.o audiointerleave.o
OBJS-$(CONFIG_G722_DEMUXER) += rawdec.o
OBJS-$(CONFIG_G722_MUXER) += rawenc.o
+OBJS-$(CONFIG_G723_1_DEMUXER) += g723_1.o
+OBJS-$(CONFIG_G723_1_MUXER) += rawenc.o
OBJS-$(CONFIG_H261_DEMUXER) += h261dec.o rawdec.o
OBJS-$(CONFIG_H261_MUXER) += rawenc.o
OBJS-$(CONFIG_H263_DEMUXER) += h263dec.o rawdec.o
@@ -97,6 +107,7 @@ OBJS-$(CONFIG_H263_MUXER) += rawenc.o
OBJS-$(CONFIG_H264_DEMUXER) += h264dec.o rawdec.o
OBJS-$(CONFIG_H264_MUXER) += rawenc.o
OBJS-$(CONFIG_IDCIN_DEMUXER) += idcin.o
+OBJS-$(CONFIG_IDF_DEMUXER) += bintext.o
OBJS-$(CONFIG_IFF_DEMUXER) += iff.o
OBJS-$(CONFIG_IMAGE2_DEMUXER) += img2.o
OBJS-$(CONFIG_IMAGE2_MUXER) += img2.o
@@ -109,7 +120,10 @@ OBJS-$(CONFIG_IV8_DEMUXER) += iv8.o
OBJS-$(CONFIG_IVF_DEMUXER) += ivfdec.o riff.o
OBJS-$(CONFIG_IVF_MUXER) += ivfenc.o
OBJS-$(CONFIG_JV_DEMUXER) += jvdec.o
+OBJS-$(CONFIG_LATM_DEMUXER) += rawdec.o
+OBJS-$(CONFIG_LATM_MUXER) += latmenc.o
OBJS-$(CONFIG_LMLM4_DEMUXER) += lmlm4.o
+OBJS-$(CONFIG_LOAS_DEMUXER) += loasdec.o
OBJS-$(CONFIG_LXF_DEMUXER) += lxfdec.o
OBJS-$(CONFIG_M4V_DEMUXER) += m4vdec.o rawdec.o
OBJS-$(CONFIG_M4V_MUXER) += rawenc.o
@@ -119,6 +133,8 @@ OBJS-$(CONFIG_MATROSKA_MUXER) += matroskaenc.o matroska.o \
riff.o isom.o avc.o \
flacenc_header.o avlanguage.o
OBJS-$(CONFIG_MD5_MUXER) += md5enc.o
+OBJS-$(CONFIG_MICRODVD_DEMUXER) += microdvddec.o
+OBJS-$(CONFIG_MICRODVD_MUXER) += microdvdenc.o rawenc.o
OBJS-$(CONFIG_MJPEG_DEMUXER) += rawdec.o
OBJS-$(CONFIG_MJPEG_MUXER) += rawenc.o
OBJS-$(CONFIG_MLP_DEMUXER) += rawdec.o
@@ -159,6 +175,7 @@ OBJS-$(CONFIG_NUT_DEMUXER) += nutdec.o nut.o riff.o
OBJS-$(CONFIG_NUT_MUXER) += nutenc.o nut.o riff.o
OBJS-$(CONFIG_NUV_DEMUXER) += nuv.o riff.o
OBJS-$(CONFIG_OGG_DEMUXER) += oggdec.o \
+ oggparsecelt.o \
oggparsedirac.o \
oggparseflac.o \
oggparseogm.o \
@@ -211,6 +228,7 @@ OBJS-$(CONFIG_PCM_U32LE_DEMUXER) += pcmdec.o pcm.o rawdec.o
OBJS-$(CONFIG_PCM_U32LE_MUXER) += pcmenc.o rawenc.o
OBJS-$(CONFIG_PCM_U8_DEMUXER) += pcmdec.o pcm.o rawdec.o
OBJS-$(CONFIG_PCM_U8_MUXER) += pcmenc.o rawenc.o
+OBJS-$(CONFIG_PMP_DEMUXER) += pmpdec.o
OBJS-$(CONFIG_PVA_DEMUXER) += pva.o
OBJS-$(CONFIG_QCP_DEMUXER) += qcp.o
OBJS-$(CONFIG_R3D_DEMUXER) += r3d.o
@@ -257,6 +275,7 @@ OBJS-$(CONFIG_SAP_DEMUXER) += sapdec.o
OBJS-$(CONFIG_SAP_MUXER) += sapenc.o rtpenc_chain.o
OBJS-$(CONFIG_SDP_DEMUXER) += rtsp.o
OBJS-$(CONFIG_SEGAFILM_DEMUXER) += segafilm.o
+OBJS-$(CONFIG_SEGMENT_MUXER) += segment.o
OBJS-$(CONFIG_SHORTEN_DEMUXER) += rawdec.o
OBJS-$(CONFIG_SIFF_DEMUXER) += siff.o
OBJS-$(CONFIG_SMACKER_DEMUXER) += smacker.o
@@ -294,16 +313,20 @@ OBJS-$(CONFIG_WEBM_MUXER) += matroskaenc.o matroska.o \
flacenc_header.o avlanguage.o
OBJS-$(CONFIG_WSAUD_DEMUXER) += westwood.o
OBJS-$(CONFIG_WSVQA_DEMUXER) += westwood.o
-OBJS-$(CONFIG_WTV_DEMUXER) += wtv.o asfdec.o asf.o asfcrypt.o \
+OBJS-$(CONFIG_WTV_DEMUXER) += wtvdec.o wtv.o asfdec.o asf.o asfcrypt.o \
avlanguage.o mpegts.o isom.o riff.o
+OBJS-$(CONFIG_WTV_MUXER) += wtvenc.o wtv.o asf.o riff.o
OBJS-$(CONFIG_WV_DEMUXER) += wv.o apetag.o
OBJS-$(CONFIG_XA_DEMUXER) += xa.o
+OBJS-$(CONFIG_XBIN_DEMUXER) += bintext.o sauce.o
+OBJS-$(CONFIG_XMV_DEMUXER) += xmv.o
OBJS-$(CONFIG_XWMA_DEMUXER) += xwma.o riff.o
OBJS-$(CONFIG_YOP_DEMUXER) += yop.o
OBJS-$(CONFIG_YUV4MPEGPIPE_MUXER) += yuv4mpeg.o
OBJS-$(CONFIG_YUV4MPEGPIPE_DEMUXER) += yuv4mpeg.o
# external libraries
+OBJS-$(CONFIG_LIBMODPLUG_DEMUXER) += libmodplug.o
OBJS-$(CONFIG_LIBNUT_DEMUXER) += libnut.o riff.o
OBJS-$(CONFIG_LIBNUT_MUXER) += libnut.o riff.o
@@ -311,6 +334,7 @@ OBJS-$(CONFIG_LIBNUT_MUXER) += libnut.o riff.o
OBJS+= avio.o aviobuf.o
OBJS-$(CONFIG_APPLEHTTP_PROTOCOL) += applehttpproto.o
+OBJS-$(CONFIG_CACHE_PROTOCOL) += cache.o
OBJS-$(CONFIG_CONCAT_PROTOCOL) += concat.o
OBJS-$(CONFIG_CRYPTO_PROTOCOL) += crypto.o
OBJS-$(CONFIG_FILE_PROTOCOL) += file.o
@@ -330,12 +354,8 @@ OBJS-$(CONFIG_RTP_PROTOCOL) += rtpproto.o
OBJS-$(CONFIG_TCP_PROTOCOL) += tcp.o
OBJS-$(CONFIG_UDP_PROTOCOL) += udp.o
-# libavdevice dependencies
-OBJS-$(CONFIG_JACK_INDEV) += timefilter.o
-EXAMPLES = metadata output
-TESTPROGS = timefilter
+TESTPROGS = seek
+TOOLS = pktdumper probetest
include $(SRC_PATH)/subdir.mak
-
-$(SUBDIR)output-example$(EXESUF): ELIBS = -lswscale
diff --git a/libavformat/a64.c b/libavformat/a64.c
index 3d313e5fba..edab918129 100644
--- a/libavformat/a64.c
+++ b/libavformat/a64.c
@@ -2,20 +2,20 @@
* a64 muxer
* Copyright (c) 2009 Tobias Bindhammer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -170,7 +170,7 @@ AVOutputFormat ff_a64_muxer = {
.extensions = "a64, A64",
.priv_data_size = sizeof (A64Context),
.video_codec = CODEC_ID_A64_MULTI,
- a64_write_header,
- a64_write_packet,
- a64_write_trailer
+ .write_header = a64_write_header,
+ .write_packet = a64_write_packet,
+ .write_trailer = a64_write_trailer
};
diff --git a/libavformat/aacdec.c b/libavformat/aacdec.c
index 6a184c77d7..7df11bf95c 100644
--- a/libavformat/aacdec.c
+++ b/libavformat/aacdec.c
@@ -3,20 +3,20 @@
* Copyright (c) 2008 Michael Niedermayer <michaelni@gmx.at>
* Copyright (c) 2009 Robert Swain ( rob opendot cl )
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -47,6 +47,7 @@ static int adts_aac_probe(AVProbeData *p)
fsize = (AV_RB32(buf2 + 3) >> 13) & 0x1FFF;
if(fsize < 7)
break;
+ fsize = FFMIN(fsize, end - buf2);
buf2 += fsize;
}
max_frames = FFMAX(max_frames, frames);
@@ -65,7 +66,7 @@ static int adts_aac_read_header(AVFormatContext *s,
{
AVStream *st;
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
@@ -82,12 +83,11 @@ static int adts_aac_read_header(AVFormatContext *s,
}
AVInputFormat ff_aac_demuxer = {
- "aac",
- NULL_IF_CONFIG_SMALL("raw ADTS AAC"),
- 0,
- adts_aac_probe,
- adts_aac_read_header,
- ff_raw_read_partial_packet,
+ .name = "aac",
+ .long_name = NULL_IF_CONFIG_SMALL("raw ADTS AAC"),
+ .read_probe = adts_aac_probe,
+ .read_header = adts_aac_read_header,
+ .read_packet = ff_raw_read_partial_packet,
.flags= AVFMT_GENERIC_INDEX,
.extensions = "aac",
.value = CODEC_ID_AAC,
diff --git a/libavformat/ac3dec.c b/libavformat/ac3dec.c
index 7ed01029dd..54d4fd2626 100644
--- a/libavformat/ac3dec.c
+++ b/libavformat/ac3dec.c
@@ -2,20 +2,20 @@
* RAW AC-3 and E-AC-3 demuxer
* Copyright (c) 2007 Justin Ruggles <justin.ruggles@gmail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -41,7 +41,7 @@ static int ac3_eac3_probe(AVProbeData *p, enum CodecID expected_codec_id)
for(frames = 0; buf2 < end; frames++) {
init_get_bits(&gbc, buf2, 54);
- if(ff_ac3_parse_header(&gbc, &hdr) < 0)
+ if(avpriv_ac3_parse_header(&gbc, &hdr) < 0)
break;
if(buf2 + hdr.frame_size > end ||
av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, buf2 + 2, hdr.frame_size - 2))
@@ -71,12 +71,11 @@ static int ac3_probe(AVProbeData *p)
}
AVInputFormat ff_ac3_demuxer = {
- "ac3",
- NULL_IF_CONFIG_SMALL("raw AC-3"),
- 0,
- ac3_probe,
- ff_raw_audio_read_header,
- ff_raw_read_partial_packet,
+ .name = "ac3",
+ .long_name = NULL_IF_CONFIG_SMALL("raw AC-3"),
+ .read_probe = ac3_probe,
+ .read_header = ff_raw_audio_read_header,
+ .read_packet = ff_raw_read_partial_packet,
.flags= AVFMT_GENERIC_INDEX,
.extensions = "ac3",
.value = CODEC_ID_AC3,
@@ -90,12 +89,11 @@ static int eac3_probe(AVProbeData *p)
}
AVInputFormat ff_eac3_demuxer = {
- "eac3",
- NULL_IF_CONFIG_SMALL("raw E-AC-3"),
- 0,
- eac3_probe,
- ff_raw_audio_read_header,
- ff_raw_read_partial_packet,
+ .name = "eac3",
+ .long_name = NULL_IF_CONFIG_SMALL("raw E-AC-3"),
+ .read_probe = eac3_probe,
+ .read_header = ff_raw_audio_read_header,
+ .read_packet = ff_raw_read_partial_packet,
.flags= AVFMT_GENERIC_INDEX,
.extensions = "eac3",
.value = CODEC_ID_EAC3,
diff --git a/libavformat/act.c b/libavformat/act.c
new file mode 100644
index 0000000000..8454cd1fc0
--- /dev/null
+++ b/libavformat/act.c
@@ -0,0 +1,207 @@
+/*
+ * ACT file format demuxer
+ * Copyright (c) 2007-2008 Vladimir Voroshilov
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#include "avformat.h"
+#include "riff.h"
+#include "libavcodec/get_bits.h"
+
+#define CHUNK_SIZE 512
+#define RIFF_TAG MKTAG('R','I','F','F')
+#define WAVE_TAG MKTAG('W','A','V','E')
+
+typedef struct{
+ int bytes_left_in_chunk;
+ uint8_t audio_buffer[22];///< temporary buffer for ACT frame
+ char second_packet; ///< 1 - if temporary buffer contains valid (second) G.729 packet
+} ACTContext;
+
+static int probe(AVProbeData *p)
+{
+ int i;
+
+ if ((AV_RL32(&p->buf[0]) != RIFF_TAG) ||
+ (AV_RL32(&p->buf[8]) != WAVE_TAG) ||
+ (AV_RL32(&p->buf[16]) != 16))
+ return 0;
+
+ //We cant be sure that this is ACT and not regular WAV
+ if (p->buf_size<512)
+ return 0;
+
+ for(i=44; i<256; i++)
+ if(p->buf[i])
+ return 0;
+
+ if(p->buf[256]!=0x84)
+ return 0;
+
+ for(i=264; i<512; i++)
+ if(p->buf[i])
+ return 0;
+
+ return AVPROBE_SCORE_MAX;
+}
+
+static int read_header(AVFormatContext *s,
+ AVFormatParameters *ap)
+{
+ ACTContext* ctx = s->priv_data;
+ ByteIOContext *pb = s->pb;
+ int size;
+ AVStream* st;
+
+ int min,sec,msec;
+
+ st=av_new_stream(s, 0);
+ if (!st)
+ return AVERROR(ENOMEM);
+
+ url_fskip(pb, 16);
+ size=get_le32(pb);
+ ff_get_wav_header(pb, st->codec, size);
+
+ /*
+ 8000Hz (Fine-rec) file format has 10 bytes long
+ packets with 10ms of sound data in them
+ */
+ if (st->codec->sample_rate != 8000) {
+ av_log(s, AV_LOG_ERROR, "Sample rate %d is not supported.\n", st->codec->sample_rate);
+ return AVERROR_INVALIDDATA;
+ }
+
+ st->codec->frame_size=80;
+ st->codec->channels=1;
+ av_set_pts_info(st, 64, 1, 100);
+
+ st->codec->codec_id=CODEC_ID_G729;
+
+ url_fseek(pb, 257, SEEK_SET);
+ msec=get_le16(pb);
+ sec=get_byte(pb);
+ min=get_le32(pb);
+
+ st->duration = av_rescale(1000*(min*60+sec)+msec, st->codec->sample_rate, 1000 * st->codec->frame_size);
+
+ ctx->bytes_left_in_chunk=CHUNK_SIZE;
+
+ url_fseek(pb, 512, SEEK_SET);
+
+ return 0;
+}
+
+
+static int read_packet(AVFormatContext *s,
+ AVPacket *pkt)
+{
+ ACTContext *ctx = s->priv_data;
+ ByteIOContext *pb = s->pb;
+ int ret;
+ int frame_size=s->streams[0]->codec->sample_rate==8000?10:22;
+
+
+ if(s->streams[0]->codec->sample_rate==8000)
+ ret=av_new_packet(pkt, 10);
+ else
+ ret=av_new_packet(pkt, 11);
+
+ if(ret)
+ return ret;
+
+ if(s->streams[0]->codec->sample_rate==4400 && !ctx->second_packet)
+ {
+ ret = get_buffer(pb, ctx->audio_buffer, frame_size);
+
+ if(ret<0)
+ return ret;
+ if(ret!=frame_size)
+ return AVERROR(EIO);
+
+ pkt->data[0]=ctx->audio_buffer[11];
+ pkt->data[1]=ctx->audio_buffer[0];
+ pkt->data[2]=ctx->audio_buffer[12];
+ pkt->data[3]=ctx->audio_buffer[1];
+ pkt->data[4]=ctx->audio_buffer[13];
+ pkt->data[5]=ctx->audio_buffer[2];
+ pkt->data[6]=ctx->audio_buffer[14];
+ pkt->data[7]=ctx->audio_buffer[3];
+ pkt->data[8]=ctx->audio_buffer[15];
+ pkt->data[9]=ctx->audio_buffer[4];
+ pkt->data[10]=ctx->audio_buffer[16];
+
+ ctx->second_packet=1;
+ }
+ else if(s->streams[0]->codec->sample_rate==4400 && ctx->second_packet)
+ {
+ pkt->data[0]=ctx->audio_buffer[5];
+ pkt->data[1]=ctx->audio_buffer[17];
+ pkt->data[2]=ctx->audio_buffer[6];
+ pkt->data[3]=ctx->audio_buffer[18];
+ pkt->data[4]=ctx->audio_buffer[7];
+ pkt->data[5]=ctx->audio_buffer[19];
+ pkt->data[6]=ctx->audio_buffer[8];
+ pkt->data[7]=ctx->audio_buffer[20];
+ pkt->data[8]=ctx->audio_buffer[9];
+ pkt->data[9]=ctx->audio_buffer[21];
+ pkt->data[10]=ctx->audio_buffer[10];
+
+ ctx->second_packet=0;
+ }
+ else // 8000 Hz
+ {
+ ret = get_buffer(pb, ctx->audio_buffer, frame_size);
+
+ if(ret<0)
+ return ret;
+ if(ret!=frame_size)
+ return AVERROR(EIO);
+
+ pkt->data[0]=ctx->audio_buffer[5];
+ pkt->data[1]=ctx->audio_buffer[0];
+ pkt->data[2]=ctx->audio_buffer[6];
+ pkt->data[3]=ctx->audio_buffer[1];
+ pkt->data[4]=ctx->audio_buffer[7];
+ pkt->data[5]=ctx->audio_buffer[2];
+ pkt->data[6]=ctx->audio_buffer[8];
+ pkt->data[7]=ctx->audio_buffer[3];
+ pkt->data[8]=ctx->audio_buffer[9];
+ pkt->data[9]=ctx->audio_buffer[4];
+ }
+
+ ctx->bytes_left_in_chunk -= frame_size;
+
+ if(ctx->bytes_left_in_chunk < frame_size)
+ {
+ url_fskip(pb, ctx->bytes_left_in_chunk);
+ ctx->bytes_left_in_chunk=CHUNK_SIZE;
+ }
+
+ pkt->duration=1;
+
+ return ret;
+}
+
+AVInputFormat ff_act_demuxer = {
+ .name = "act",
+ .long_name = "ACT Voice file format",
+ .priv_data_size = sizeof(ACTContext),
+ .read_probe = probe,
+ .read_header = read_header,
+ .read_packet = read_packet,
+};
diff --git a/libavformat/adts.h b/libavformat/adts.h
index 78b42c7101..1da57beff9 100644
--- a/libavformat/adts.h
+++ b/libavformat/adts.h
@@ -3,20 +3,20 @@
* Copyright (c) 2006 Baptiste Coudurier <baptiste.coudurier@smartjog.com>
* Mans Rullgard <mans@mansr.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/adtsenc.c b/libavformat/adtsenc.c
index e858a81d92..4b14b95ef4 100644
--- a/libavformat/adtsenc.c
+++ b/libavformat/adtsenc.c
@@ -3,20 +3,20 @@
* Copyright (c) 2006 Baptiste Coudurier <baptiste.coudurier@smartjog.com>
* Mans Rullgard <mans@mansr.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -35,7 +35,7 @@ int ff_adts_decode_extradata(AVFormatContext *s, ADTSContext *adts, uint8_t *buf
int off;
init_get_bits(&gb, buf, size * 8);
- off = ff_mpeg4audio_get_config(&m4ac, buf, size);
+ off = avpriv_mpeg4audio_get_config(&m4ac, buf, size);
if (off < 0)
return off;
skip_bits_long(&gb, off);
@@ -59,11 +59,15 @@ int ff_adts_decode_extradata(AVFormatContext *s, ADTSContext *adts, uint8_t *buf
av_log(s, AV_LOG_ERROR, "Scalable configurations are not allowed in ADTS\n");
return -1;
}
+ if (get_bits(&gb, 1)) {
+ av_log(s, AV_LOG_ERROR, "Extension flag is not allowed in ADTS\n");
+ return -1;
+ }
if (!adts->channel_conf) {
init_put_bits(&pb, adts->pce_data, MAX_PCE_SIZE);
put_bits(&pb, 3, 5); //ID_PCE
- adts->pce_size = (ff_copy_pce_data(&pb, &gb) + 3) / 8;
+ adts->pce_size = (avpriv_copy_pce_data(&pb, &gb) + 3) / 8;
flush_put_bits(&pb);
}
@@ -138,13 +142,13 @@ static int adts_write_packet(AVFormatContext *s, AVPacket *pkt)
}
AVOutputFormat ff_adts_muxer = {
- "adts",
- NULL_IF_CONFIG_SMALL("ADTS AAC"),
- "audio/aac",
- "aac,adts",
- sizeof(ADTSContext),
- CODEC_ID_AAC,
- CODEC_ID_NONE,
- adts_write_header,
- adts_write_packet,
+ .name = "adts",
+ .long_name = NULL_IF_CONFIG_SMALL("ADTS AAC"),
+ .mime_type = "audio/aac",
+ .extensions = "aac,adts",
+ .priv_data_size = sizeof(ADTSContext),
+ .audio_codec = CODEC_ID_AAC,
+ .video_codec = CODEC_ID_NONE,
+ .write_header = adts_write_header,
+ .write_packet = adts_write_packet,
};
diff --git a/libavformat/aea.c b/libavformat/aea.c
index c6dfbb1c83..9fac6c8de6 100644
--- a/libavformat/aea.c
+++ b/libavformat/aea.c
@@ -3,20 +3,20 @@
*
* Copyright (c) 2009 Benjamin Larsson
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -57,7 +57,7 @@ static int aea_read_probe(AVProbeData *p)
static int aea_read_header(AVFormatContext *s,
AVFormatParameters *ap)
{
- AVStream *st = av_new_stream(s, 0);
+ AVStream *st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
@@ -95,14 +95,12 @@ static int aea_read_packet(AVFormatContext *s, AVPacket *pkt)
}
AVInputFormat ff_aea_demuxer = {
- "aea",
- NULL_IF_CONFIG_SMALL("MD STUDIO audio"),
- 0,
- aea_read_probe,
- aea_read_header,
- aea_read_packet,
- 0,
- pcm_read_seek,
+ .name = "aea",
+ .long_name = NULL_IF_CONFIG_SMALL("MD STUDIO audio"),
+ .read_probe = aea_read_probe,
+ .read_header = aea_read_header,
+ .read_packet = aea_read_packet,
+ .read_seek = pcm_read_seek,
.flags= AVFMT_GENERIC_INDEX,
.extensions = "aea",
};
diff --git a/libavformat/aiff.h b/libavformat/aiff.h
index cd2bd256d6..047f81dc1d 100644
--- a/libavformat/aiff.h
+++ b/libavformat/aiff.h
@@ -2,20 +2,20 @@
* AIFF/AIFF-C muxer/demuxer common header
* Copyright (c) 2006 Patrick Guimond
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/aiffdec.c b/libavformat/aiffdec.c
index 0e815421a7..eee9a1c483 100644
--- a/libavformat/aiffdec.c
+++ b/libavformat/aiffdec.c
@@ -2,20 +2,20 @@
* AIFF/AIFF-C demuxer
* Copyright (c) 2006 Patrick Guimond
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -24,6 +24,7 @@
#include "avformat.h"
#include "pcm.h"
#include "aiff.h"
+#include "isom.h"
#define AIFF 0
#define AIFF_C_VERSION1 0xA2805140
@@ -52,7 +53,7 @@ static int get_tag(AVIOContext *pb, uint32_t * tag)
{
int size;
- if (pb->eof_reached)
+ if (url_feof(pb))
return AVERROR(EIO);
*tag = avio_rl32(pb);
@@ -68,19 +69,20 @@ static int get_tag(AVIOContext *pb, uint32_t * tag)
static void get_meta(AVFormatContext *s, const char *key, int size)
{
uint8_t *str = av_malloc(size+1);
- int res;
- if (!str) {
- avio_skip(s->pb, size);
- return;
- }
-
- res = avio_read(s->pb, str, size);
- if (res < 0)
- return;
+ if (str) {
+ int res = avio_read(s->pb, str, size);
+ if (res < 0){
+ av_free(str);
+ return;
+ }
+ size += (size&1)-res;
+ str[res] = 0;
+ av_dict_set(&s->metadata, key, str, AV_METADATA_DONT_STRDUP_VAL);
+ }else
+ size+= size&1;
- str[res] = 0;
- av_dict_set(&s->metadata, key, str, AV_DICT_DONT_STRDUP_VAL);
+ avio_skip(s->pb, size);
}
/* Returns the number of sound data frames or negative on error */
@@ -196,7 +198,7 @@ static int aiff_read_header(AVFormatContext *s,
filesize -= 4;
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
@@ -254,6 +256,11 @@ static int aiff_read_header(AVFormatContext *s,
st->codec->extradata_size = size;
avio_read(pb, st->codec->extradata, size);
break;
+ case MKTAG('C','H','A','N'):
+ if (size < 12)
+ return AVERROR_INVALIDDATA;
+ ff_mov_read_chan(s, size, st->codec);
+ break;
default: /* Jump */
if (size & 1) /* Always even aligned */
size++;
@@ -268,9 +275,6 @@ static int aiff_read_header(AVFormatContext *s,
got_sound:
/* Now positioned, get the sound data start and end */
- if (st->nb_frames)
- s->file_size = st->nb_frames * st->codec->block_align;
-
av_set_pts_info(st, 64, 1, st->codec->sample_rate);
st->start_time = 0;
st->duration = st->codec->frame_size ?
@@ -313,13 +317,12 @@ static int aiff_read_packet(AVFormatContext *s,
}
AVInputFormat ff_aiff_demuxer = {
- "aiff",
- NULL_IF_CONFIG_SMALL("Audio IFF"),
- sizeof(AIFFInputContext),
- aiff_probe,
- aiff_read_header,
- aiff_read_packet,
- NULL,
- pcm_read_seek,
+ .name = "aiff",
+ .long_name = NULL_IF_CONFIG_SMALL("Audio IFF"),
+ .priv_data_size = sizeof(AIFFInputContext),
+ .read_probe = aiff_probe,
+ .read_header = aiff_read_header,
+ .read_packet = aiff_read_packet,
+ .read_seek = pcm_read_seek,
.codec_tag= (const AVCodecTag* const []){ff_codec_aiff_tags, 0},
};
diff --git a/libavformat/aiffenc.c b/libavformat/aiffenc.c
index 5a64688483..3b2fc38160 100644
--- a/libavformat/aiffenc.c
+++ b/libavformat/aiffenc.c
@@ -2,20 +2,20 @@
* AIFF/AIFF-C muxer
* Copyright (c) 2006 Patrick Guimond
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -23,6 +23,7 @@
#include "avformat.h"
#include "aiff.h"
#include "avio_internal.h"
+#include "isom.h"
typedef struct {
int64_t form;
@@ -62,6 +63,12 @@ static int aiff_write_header(AVFormatContext *s)
avio_wb32(pb, 0xA2805140);
}
+ if (enc->channels > 2 && enc->channel_layout) {
+ ffio_wfourcc(pb, "CHAN");
+ avio_wb32(pb, 12);
+ ff_mov_write_chan(pb, enc->channel_layout);
+ }
+
/* Common chunk */
ffio_wfourcc(pb, "COMM");
avio_wb32(pb, aifc ? 24 : 18); /* size */
@@ -148,15 +155,15 @@ static int aiff_write_trailer(AVFormatContext *s)
}
AVOutputFormat ff_aiff_muxer = {
- "aiff",
- NULL_IF_CONFIG_SMALL("Audio IFF"),
- "audio/aiff",
- "aif,aiff,afc,aifc",
- sizeof(AIFFOutputContext),
- CODEC_ID_PCM_S16BE,
- CODEC_ID_NONE,
- aiff_write_header,
- aiff_write_packet,
- aiff_write_trailer,
+ .name = "aiff",
+ .long_name = NULL_IF_CONFIG_SMALL("Audio IFF"),
+ .mime_type = "audio/aiff",
+ .extensions = "aif,aiff,afc,aifc",
+ .priv_data_size = sizeof(AIFFOutputContext),
+ .audio_codec = CODEC_ID_PCM_S16BE,
+ .video_codec = CODEC_ID_NONE,
+ .write_header = aiff_write_header,
+ .write_packet = aiff_write_packet,
+ .write_trailer = aiff_write_trailer,
.codec_tag= (const AVCodecTag* const []){ff_codec_aiff_tags, 0},
};
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index f1c3d3b768..7e0e9cef52 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -2,20 +2,20 @@
* Register all the formats and protocols
* Copyright (c) 2000, 2001, 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avformat.h"
@@ -51,6 +51,8 @@ void av_register_all(void)
REGISTER_MUXER (A64, a64);
REGISTER_DEMUXER (AAC, aac);
REGISTER_MUXDEMUX (AC3, ac3);
+ REGISTER_DEMUXER (ACT, act);
+ REGISTER_DEMUXER (ADF, adf);
REGISTER_MUXER (ADTS, adts);
REGISTER_DEMUXER (AEA, aea);
REGISTER_MUXDEMUX (AIFF, aiff);
@@ -69,9 +71,11 @@ void av_register_all(void)
REGISTER_DEMUXER (AVS, avs);
REGISTER_DEMUXER (BETHSOFTVID, bethsoftvid);
REGISTER_DEMUXER (BFI, bfi);
+ REGISTER_DEMUXER (BINTEXT, bintext);
REGISTER_DEMUXER (BINK, bink);
+ REGISTER_MUXDEMUX (BIT, bit);
REGISTER_DEMUXER (C93, c93);
- REGISTER_DEMUXER (CAF, caf);
+ REGISTER_MUXDEMUX (CAF, caf);
REGISTER_MUXDEMUX (CAVSVIDEO, cavsvideo);
REGISTER_DEMUXER (CDG, cdg);
REGISTER_MUXER (CRC, crc);
@@ -96,6 +100,7 @@ void av_register_all(void)
REGISTER_MUXER (FRAMECRC, framecrc);
REGISTER_MUXER (FRAMEMD5, framemd5);
REGISTER_MUXDEMUX (G722, g722);
+ REGISTER_MUXDEMUX (G723_1, g723_1);
REGISTER_MUXER (GIF, gif);
REGISTER_DEMUXER (GSM, gsm);
REGISTER_MUXDEMUX (GXF, gxf);
@@ -103,6 +108,7 @@ void av_register_all(void)
REGISTER_MUXDEMUX (H263, h263);
REGISTER_MUXDEMUX (H264, h264);
REGISTER_DEMUXER (IDCIN, idcin);
+ REGISTER_DEMUXER (IDF, idf);
REGISTER_DEMUXER (IFF, iff);
REGISTER_MUXDEMUX (IMAGE2, image2);
REGISTER_MUXDEMUX (IMAGE2PIPE, image2pipe);
@@ -113,12 +119,15 @@ void av_register_all(void)
REGISTER_DEMUXER (IV8, iv8);
REGISTER_MUXDEMUX (IVF, ivf);
REGISTER_DEMUXER (JV, jv);
+ REGISTER_MUXDEMUX (LATM, latm);
REGISTER_DEMUXER (LMLM4, lmlm4);
+ REGISTER_DEMUXER (LOAS, loas);
REGISTER_DEMUXER (LXF, lxf);
REGISTER_MUXDEMUX (M4V, m4v);
REGISTER_MUXER (MD5, md5);
REGISTER_MUXDEMUX (MATROSKA, matroska);
REGISTER_MUXER (MATROSKA_AUDIO, matroska_audio);
+ REGISTER_MUXDEMUX (MICRODVD, microdvd);
REGISTER_MUXDEMUX (MJPEG, mjpeg);
REGISTER_MUXDEMUX (MLP, mlp);
REGISTER_DEMUXER (MM, mm);
@@ -174,6 +183,7 @@ void av_register_all(void)
REGISTER_MUXDEMUX (PCM_U16BE, pcm_u16be);
REGISTER_MUXDEMUX (PCM_U16LE, pcm_u16le);
REGISTER_MUXDEMUX (PCM_U8, pcm_u8);
+ REGISTER_DEMUXER (PMP, pmp);
REGISTER_MUXER (PSP, psp);
REGISTER_DEMUXER (PVA, pva);
REGISTER_DEMUXER (QCP, qcp);
@@ -193,6 +203,7 @@ void av_register_all(void)
av_register_rdt_dynamic_payload_handlers();
#endif
REGISTER_DEMUXER (SEGAFILM, segafilm);
+ REGISTER_MUXER (SEGMENT, segment);
REGISTER_DEMUXER (SHORTEN, shorten);
REGISTER_DEMUXER (SIFF, siff);
REGISTER_DEMUXER (SMACKER, smacker);
@@ -222,18 +233,24 @@ void av_register_all(void)
REGISTER_MUXER (WEBM, webm);
REGISTER_DEMUXER (WSAUD, wsaud);
REGISTER_DEMUXER (WSVQA, wsvqa);
- REGISTER_DEMUXER (WTV, wtv);
+ REGISTER_MUXDEMUX (WTV, wtv);
REGISTER_DEMUXER (WV, wv);
REGISTER_DEMUXER (XA, xa);
+ REGISTER_DEMUXER (XBIN, xbin);
+ REGISTER_DEMUXER (XMV, xmv);
REGISTER_DEMUXER (XWMA, xwma);
REGISTER_DEMUXER (YOP, yop);
REGISTER_MUXDEMUX (YUV4MPEGPIPE, yuv4mpegpipe);
/* external libraries */
+#if CONFIG_LIBMODPLUG
+ REGISTER_DEMUXER (LIBMODPLUG, libmodplug);
+#endif
REGISTER_MUXDEMUX (LIBNUT, libnut);
/* protocols */
REGISTER_PROTOCOL (APPLEHTTP, applehttp);
+ REGISTER_PROTOCOL (CACHE, cache);
REGISTER_PROTOCOL (CONCAT, concat);
REGISTER_PROTOCOL (CRYPTO, crypto);
REGISTER_PROTOCOL (FILE, file);
diff --git a/libavformat/amr.c b/libavformat/amr.c
index 260bd6ada6..8c3b1416c8 100644
--- a/libavformat/amr.c
+++ b/libavformat/amr.c
@@ -2,20 +2,20 @@
* amr file format
* Copyright (c) 2001 ffmpeg project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -84,7 +84,7 @@ static int amr_read_header(AVFormatContext *s,
avio_read(pb, header, 6);
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
{
return AVERROR(ENOMEM);
@@ -123,7 +123,7 @@ static int amr_read_packet(AVFormatContext *s,
int read, size = 0, toc, mode;
int64_t pos = avio_tell(s->pb);
- if (s->pb->eof_reached)
+ if (url_feof(s->pb))
{
return AVERROR(EIO);
}
@@ -174,27 +174,25 @@ static int amr_read_packet(AVFormatContext *s,
#if CONFIG_AMR_DEMUXER
AVInputFormat ff_amr_demuxer = {
- "amr",
- NULL_IF_CONFIG_SMALL("3GPP AMR file format"),
- 0, /*priv_data_size*/
- amr_probe,
- amr_read_header,
- amr_read_packet,
- NULL,
+ .name = "amr",
+ .long_name = NULL_IF_CONFIG_SMALL("3GPP AMR file format"),
+ .priv_data_size = 0, /*priv_data_size*/
+ .read_probe = amr_probe,
+ .read_header = amr_read_header,
+ .read_packet = amr_read_packet,
.flags = AVFMT_GENERIC_INDEX,
};
#endif
#if CONFIG_AMR_MUXER
AVOutputFormat ff_amr_muxer = {
- "amr",
- NULL_IF_CONFIG_SMALL("3GPP AMR file format"),
- "audio/amr",
- "amr",
- 0,
- CODEC_ID_AMR_NB,
- CODEC_ID_NONE,
- amr_write_header,
- amr_write_packet,
+ .name = "amr",
+ .long_name = NULL_IF_CONFIG_SMALL("3GPP AMR file format"),
+ .mime_type = "audio/amr",
+ .extensions = "amr",
+ .audio_codec = CODEC_ID_AMR_NB,
+ .video_codec = CODEC_ID_NONE,
+ .write_header = amr_write_header,
+ .write_packet = amr_write_packet,
};
#endif
diff --git a/libavformat/anm.c b/libavformat/anm.c
index 4d1b5f7620..99864f6b54 100644
--- a/libavformat/anm.c
+++ b/libavformat/anm.c
@@ -2,20 +2,20 @@
* Deluxe Paint Animation demuxer
* Copyright (c) 2009 Peter Ross
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -97,7 +97,7 @@ static int read_header(AVFormatContext *s,
return AVERROR_INVALIDDATA;
/* video stream */
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
@@ -134,18 +134,17 @@ static int read_header(AVFormatContext *s,
/* color cycling and palette data */
st->codec->extradata_size = 16*8 + 4*256;
st->codec->extradata = av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
- if (!st->codec->extradata) {
- ret = AVERROR(ENOMEM);
- goto close_and_return;
- }
+ if (!st->codec->extradata)
+ return AVERROR(ENOMEM);
+
ret = avio_read(pb, st->codec->extradata, st->codec->extradata_size);
if (ret < 0)
- goto close_and_return;
+ return ret;
/* read page table */
ret = avio_seek(pb, anm->page_table_offset, SEEK_SET);
if (ret < 0)
- goto close_and_return;
+ return ret;
for (i = 0; i < MAX_PAGES; i++) {
Page *p = &anm->pt[i];
@@ -156,21 +155,15 @@ static int read_header(AVFormatContext *s,
/* find page of first frame */
anm->page = find_record(anm, 0);
- if (anm->page < 0) {
- ret = anm->page;
- goto close_and_return;
- }
+ if (anm->page < 0)
+ return anm->page;
anm->record = -1;
return 0;
invalid:
av_log_ask_for_sample(s, NULL);
- ret = AVERROR_INVALIDDATA;
-
-close_and_return:
- av_close_input_stream(s);
- return ret;
+ return AVERROR_INVALIDDATA;
}
static int read_packet(AVFormatContext *s,
@@ -181,7 +174,7 @@ static int read_packet(AVFormatContext *s,
Page *p;
int tmp, record_size;
- if (s->pb->eof_reached)
+ if (url_feof(s->pb))
return AVERROR(EIO);
if (anm->page < 0)
@@ -226,10 +219,10 @@ repeat:
}
AVInputFormat ff_anm_demuxer = {
- "anm",
- NULL_IF_CONFIG_SMALL("Deluxe Paint Animation"),
- sizeof(AnmDemuxContext),
- probe,
- read_header,
- read_packet,
+ .name = "anm",
+ .long_name = NULL_IF_CONFIG_SMALL("Deluxe Paint Animation"),
+ .priv_data_size = sizeof(AnmDemuxContext),
+ .read_probe = probe,
+ .read_header = read_header,
+ .read_packet = read_packet,
};
diff --git a/libavformat/apc.c b/libavformat/apc.c
index 40c6f0c4ac..5d7bb6f31c 100644
--- a/libavformat/apc.c
+++ b/libavformat/apc.c
@@ -2,20 +2,20 @@
* CRYO APC audio format demuxer
* Copyright (c) 2007 Anssi Hannula <anssi.hannula@gmail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -39,7 +39,7 @@ static int apc_read_header(AVFormatContext *s, AVFormatParameters *ap)
avio_rl32(pb); /* _APC */
avio_rl32(pb); /* 1.20 */
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
@@ -81,10 +81,9 @@ static int apc_read_packet(AVFormatContext *s, AVPacket *pkt)
}
AVInputFormat ff_apc_demuxer = {
- "apc",
- NULL_IF_CONFIG_SMALL("CRYO APC format"),
- 0,
- apc_probe,
- apc_read_header,
- apc_read_packet,
+ .name = "apc",
+ .long_name = NULL_IF_CONFIG_SMALL("CRYO APC format"),
+ .read_probe = apc_probe,
+ .read_header = apc_read_header,
+ .read_packet = apc_read_packet,
};
diff --git a/libavformat/ape.c b/libavformat/ape.c
index 90b02619e0..93c22af6a2 100644
--- a/libavformat/ape.c
+++ b/libavformat/ape.c
@@ -3,20 +3,20 @@
* Copyright (c) 2007 Benjamin Zores <ben@geexbox.org>
* based upon libdemac from Dave Chapman.
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -129,9 +129,11 @@ static void ape_dumpinfo(AVFormatContext * s, APEContext * ape_ctx)
} else {
for (i = 0; i < ape_ctx->seektablelength / sizeof(uint32_t); i++) {
if (i < ape_ctx->totalframes - 1) {
- av_log(s, AV_LOG_DEBUG, "%8d %d (%d bytes)\n", i, ape_ctx->seektable[i], ape_ctx->seektable[i + 1] - ape_ctx->seektable[i]);
+ av_log(s, AV_LOG_DEBUG, "%8d %"PRIu32" (%"PRIu32" bytes)\n",
+ i, ape_ctx->seektable[i],
+ ape_ctx->seektable[i + 1] - ape_ctx->seektable[i]);
} else {
- av_log(s, AV_LOG_DEBUG, "%8d %d\n", i, ape_ctx->seektable[i]);
+ av_log(s, AV_LOG_DEBUG, "%8d %"PRIu32"\n", i, ape_ctx->seektable[i]);
}
}
}
@@ -169,7 +171,7 @@ static int ape_read_header(AVFormatContext * s, AVFormatParameters * ap)
ape->fileversion = avio_rl16(pb);
if (ape->fileversion < APE_MIN_VERSION || ape->fileversion > APE_MAX_VERSION) {
- av_log(s, AV_LOG_ERROR, "Unsupported file version - %"PRId16".%02"PRId16"\n",
+ av_log(s, AV_LOG_ERROR, "Unsupported file version - %d.%02d\n",
ape->fileversion / 1000, (ape->fileversion % 1000) / 10);
return -1;
}
@@ -253,7 +255,8 @@ static int ape_read_header(AVFormatContext * s, AVFormatParameters * ap)
return -1;
}
if (ape->seektablelength && (ape->seektablelength / sizeof(*ape->seektable)) < ape->totalframes) {
- av_log(s, AV_LOG_ERROR, "Number of seek entries is less than number of frames: %ld vs. %"PRIu32"\n",
+ av_log(s, AV_LOG_ERROR,
+ "Number of seek entries is less than number of frames: %zu vs. %"PRIu32"\n",
ape->seektablelength / sizeof(*ape->seektable), ape->totalframes);
return AVERROR_INVALIDDATA;
}
@@ -270,6 +273,8 @@ static int ape_read_header(AVFormatContext * s, AVFormatParameters * ap)
if (ape->seektablelength > 0) {
ape->seektable = av_malloc(ape->seektablelength);
+ if (!ape->seektable)
+ return AVERROR(ENOMEM);
for (i = 0; i < ape->seektablelength / sizeof(uint32_t); i++)
ape->seektable[i] = avio_rl32(pb);
}
@@ -308,7 +313,7 @@ static int ape_read_header(AVFormatContext * s, AVFormatParameters * ap)
ape->compressiontype);
/* now we are ready: build format streams */
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return -1;
@@ -350,7 +355,7 @@ static int ape_read_packet(AVFormatContext * s, AVPacket * pkt)
APEContext *ape = s->priv_data;
uint32_t extra_size = 8;
- if (s->pb->eof_reached)
+ if (url_feof(s->pb))
return AVERROR(EIO);
if (ape->currentframe > ape->totalframes)
return AVERROR(EIO);
@@ -405,13 +410,13 @@ static int ape_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp
}
AVInputFormat ff_ape_demuxer = {
- "ape",
- NULL_IF_CONFIG_SMALL("Monkey's Audio"),
- sizeof(APEContext),
- ape_probe,
- ape_read_header,
- ape_read_packet,
- ape_read_close,
- ape_read_seek,
+ .name = "ape",
+ .long_name = NULL_IF_CONFIG_SMALL("Monkey's Audio"),
+ .priv_data_size = sizeof(APEContext),
+ .read_probe = ape_probe,
+ .read_header = ape_read_header,
+ .read_packet = ape_read_packet,
+ .read_close = ape_read_close,
+ .read_seek = ape_read_seek,
.extensions = "ape,apl,mac"
};
diff --git a/libavformat/apetag.c b/libavformat/apetag.c
index 257ed48970..8d53e4cdf7 100644
--- a/libavformat/apetag.c
+++ b/libavformat/apetag.c
@@ -3,20 +3,20 @@
* Copyright (c) 2007 Benjamin Zores <ben@geexbox.org>
* based upon libdemac from Dave Chapman.
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/apetag.h b/libavformat/apetag.h
index 9a39d02a2b..8aaef68c38 100644
--- a/libavformat/apetag.h
+++ b/libavformat/apetag.h
@@ -3,20 +3,20 @@
* Copyright (c) 2007 Benjamin Zores <ben@geexbox.org>
* based upon libdemac from Dave Chapman.
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/applehttp.c b/libavformat/applehttp.c
index 7e0c930271..432bf4ebcc 100644
--- a/libavformat/applehttp.c
+++ b/libavformat/applehttp.c
@@ -2,20 +2,20 @@
* Apple HTTP Live Streaming demuxer
* Copyright (c) 2010 Martin Storsjo
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -223,7 +223,7 @@ static int parse_playlist(AppleHTTPContext *c, const char *url,
free_segment_list(var);
var->finished = 0;
}
- while (!in->eof_reached) {
+ while (!url_feof(in)) {
read_chomp_line(in, line, sizeof(line));
if (av_strstart(line, "#EXT-X-STREAM-INF:", &ptr)) {
struct variant_info info = {{0}};
@@ -350,8 +350,8 @@ static int open_input(struct variant *var)
snprintf(url, sizeof(url), "crypto:%s", seg->url);
if ((ret = ffurl_alloc(&var->input, url, AVIO_FLAG_READ)) < 0)
return ret;
- av_set_string3(var->input->priv_data, "key", key, 0, NULL);
- av_set_string3(var->input->priv_data, "iv", iv, 0, NULL);
+ av_opt_set(var->input->priv_data, "key", key, 0);
+ av_opt_set(var->input->priv_data, "iv", iv, 0);
if ((ret = ffurl_connect(var->input)) < 0) {
ffurl_close(var->input);
var->input = NULL;
@@ -412,7 +412,7 @@ reload:
c->end_of_segment = 1;
c->cur_seq_no = v->cur_seq_no;
- if (v->ctx) {
+ if (v->ctx && v->ctx->nb_streams) {
v->needed = 0;
for (i = v->stream_offset; i < v->stream_offset + v->ctx->nb_streams;
i++) {
@@ -505,11 +505,12 @@ static int applehttp_read_header(AVFormatContext *s, AVFormatParameters *ap)
snprintf(bitrate_str, sizeof(bitrate_str), "%d", v->bandwidth);
/* Create new AVStreams for each stream in this variant */
for (j = 0; j < v->ctx->nb_streams; j++) {
- AVStream *st = av_new_stream(s, i);
+ AVStream *st = avformat_new_stream(s, NULL);
if (!st) {
ret = AVERROR(ENOMEM);
goto fail;
}
+ st->id = i;
avcodec_copy_context(st->codec, v->ctx->streams[j]->codec);
if (v->bandwidth)
av_dict_set(&st->metadata, "variant_bitrate", bitrate_str,
@@ -580,7 +581,7 @@ start:
if (var->needed && !var->pkt.data) {
ret = av_read_frame(var->ctx, &var->pkt);
if (ret < 0) {
- if (!var->pb.eof_reached)
+ if (!url_feof(&var->pb))
return ret;
reset_packet(&var->pkt);
}
@@ -668,12 +669,12 @@ static int applehttp_probe(AVProbeData *p)
}
AVInputFormat ff_applehttp_demuxer = {
- "applehttp",
- NULL_IF_CONFIG_SMALL("Apple HTTP Live Streaming format"),
- sizeof(AppleHTTPContext),
- applehttp_probe,
- applehttp_read_header,
- applehttp_read_packet,
- applehttp_close,
- applehttp_read_seek,
+ .name = "applehttp",
+ .long_name = NULL_IF_CONFIG_SMALL("Apple HTTP Live Streaming format"),
+ .priv_data_size = sizeof(AppleHTTPContext),
+ .read_probe = applehttp_probe,
+ .read_header = applehttp_read_header,
+ .read_packet = applehttp_read_packet,
+ .read_close = applehttp_close,
+ .read_seek = applehttp_read_seek,
};
diff --git a/libavformat/applehttpproto.c b/libavformat/applehttpproto.c
index 85f3cfcef4..bb5029d82f 100644
--- a/libavformat/applehttpproto.c
+++ b/libavformat/applehttpproto.c
@@ -2,20 +2,20 @@
* Apple HTTP Live Streaming Protocol Handler
* Copyright (c) 2010 Martin Storsjo
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -123,7 +123,7 @@ static int parse_playlist(URLContext *h, const char *url)
free_segment_list(s);
s->finished = 0;
- while (!in->eof_reached) {
+ while (!url_feof(in)) {
read_chomp_line(in, line, sizeof(line));
if (av_strstart(line, "#EXT-X-STREAM-INF:", &ptr)) {
struct variant_info info = {{0}};
diff --git a/libavformat/asf.c b/libavformat/asf.c
index cc2833ddf6..1f6af18b29 100644
--- a/libavformat/asf.c
+++ b/libavformat/asf.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2000, 2001 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/asf.h b/libavformat/asf.h
index b72445def9..3f6783bf5a 100644
--- a/libavformat/asf.h
+++ b/libavformat/asf.h
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2000, 2001 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -24,6 +24,7 @@
#include <stdint.h>
#include "avformat.h"
#include "metadata.h"
+#include "riff.h"
#define PACKET_SIZE 3200
@@ -48,8 +49,6 @@ typedef struct {
uint32_t palette[256];
} ASFStream;
-typedef uint8_t ff_asf_guid[16];
-
typedef struct {
ff_asf_guid guid; ///< generated by client computer
uint64_t file_size; /**< in bytes
@@ -175,11 +174,4 @@ extern const AVMetadataConv ff_asf_metadata_conv[];
extern AVInputFormat ff_asf_demuxer;
-static av_always_inline int ff_guidcmp(const void *g1, const void *g2)
-{
- return memcmp(g1, g2, sizeof(ff_asf_guid));
-}
-
-void ff_get_guid(AVIOContext *s, ff_asf_guid *g);
-
#endif /* AVFORMAT_ASF_H */
diff --git a/libavformat/asfcrypt.c b/libavformat/asfcrypt.c
index aea3d4f345..750758d822 100644
--- a/libavformat/asfcrypt.c
+++ b/libavformat/asfcrypt.c
@@ -3,20 +3,20 @@
* Copyright (c) 2007 Reimar Doeffinger
* This is a rewrite of code contained in freeme/freeme2
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/asfcrypt.h b/libavformat/asfcrypt.h
index 53388b426e..8b80d63c5d 100644
--- a/libavformat/asfcrypt.h
+++ b/libavformat/asfcrypt.h
@@ -2,20 +2,20 @@
* ASF decryption
* Copyright (c) 2007 Reimar Doeffinger
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/asfdec.c b/libavformat/asfdec.c
index ac559a0edd..6af4439e87 100644
--- a/libavformat/asfdec.c
+++ b/libavformat/asfdec.c
@@ -2,20 +2,20 @@
* ASF compatible demuxer
* Copyright (c) 2000, 2001 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -132,12 +132,6 @@ static void print_guid(const ff_asf_guid *g)
#define print_guid(g)
#endif
-void ff_get_guid(AVIOContext *s, ff_asf_guid *g)
-{
- assert(sizeof(*g) == 16);
- avio_read(s, *g, sizeof(*g));
-}
-
static int asf_probe(AVProbeData *pd)
{
/* check file header */
@@ -171,6 +165,9 @@ static void get_tag(AVFormatContext *s, const char *key, int type, int len)
if (type == 0) { // UTF16-LE
avio_get_str16le(s->pb, len, value, 2*len + 1);
+ } else if (type == -1) { // ASCII
+ get_buffer(s->pb, value, len);
+ value[len]=0;
} else if (type > 1 && type <= 5) { // boolean or DWORD or QWORD or WORD
uint64_t num = get_value(s->pb, type);
snprintf(value, len, "%"PRIu64, num);
@@ -227,7 +224,7 @@ static int asf_read_stream_properties(AVFormatContext *s, int64_t size)
pos1 = avio_tell(pb);
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
av_set_pts_info(st, 32, 1, 1000); /* 32 bit pts in ms */
@@ -235,7 +232,6 @@ static int asf_read_stream_properties(AVFormatContext *s, int64_t size)
if (!asf_st)
return AVERROR(ENOMEM);
st->priv_data = asf_st;
- st->start_time = 0;
start_time = asf->hdr.preroll;
asf_st->stream_language_index = 128; // invalid stream index means no language info
@@ -294,7 +290,7 @@ static int asf_read_stream_properties(AVFormatContext *s, int64_t size)
if (is_dvr_ms_audio) {
// codec_id and codec_tag are unreliable in dvr_ms
// files. Set them later by probing stream.
- st->codec->codec_id = CODEC_ID_PROBE;
+ st->request_probe= 1;
st->codec->codec_tag = 0;
}
if (st->codec->codec_id == CODEC_ID_AAC) {
@@ -573,7 +569,7 @@ static int asf_read_marker(AVFormatContext *s, int64_t size)
name_len = avio_rl32(pb); // name length
if ((ret = avio_get_str16le(pb, name_len * 2, name, sizeof(name))) < name_len)
avio_skip(pb, name_len - ret);
- ff_new_chapter(s, i, (AVRational){1, 10000000}, pres_time, AV_NOPTS_VALUE, name );
+ avpriv_new_chapter(s, i, (AVRational){1, 10000000}, pres_time, AV_NOPTS_VALUE, name );
}
return 0;
@@ -638,16 +634,28 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap)
continue;
} else if (!ff_guidcmp(&g, &ff_asf_marker_header)) {
asf_read_marker(s, gsize);
- } else if (pb->eof_reached) {
+ } else if (url_feof(pb)) {
return -1;
} else {
if (!s->keylen) {
if (!ff_guidcmp(&g, &ff_asf_content_encryption)) {
+ unsigned int len;
+ AVPacket pkt;
av_log(s, AV_LOG_WARNING, "DRM protected stream detected, decoding will likely fail!\n");
+ len= avio_rl32(pb);
+ av_log(s, AV_LOG_DEBUG, "Secret data:\n");
+ av_get_packet(pb, &pkt, len); av_hex_dump_log(s, AV_LOG_DEBUG, pkt.data, pkt.size); av_free_packet(&pkt);
+ len= avio_rl32(pb);
+ get_tag(s, "ASF_Protection_Type", -1, len);
+ len= avio_rl32(pb);
+ get_tag(s, "ASF_Key_ID", -1, len);
+ len= avio_rl32(pb);
+ get_tag(s, "ASF_License_URL", -1, len);
} else if (!ff_guidcmp(&g, &ff_asf_ext_content_encryption)) {
av_log(s, AV_LOG_WARNING, "Ext DRM protected stream detected, decoding will likely fail!\n");
+ av_dict_set(&s->metadata, "encryption", "ASF Extended Content Encryption", 0);
} else if (!ff_guidcmp(&g, &ff_asf_digital_signature)) {
- av_log(s, AV_LOG_WARNING, "Digital signature detected, decoding will likely fail!\n");
+ av_log(s, AV_LOG_INFO, "Digital signature detected!\n");
}
}
}
@@ -659,7 +667,7 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap)
avio_rl64(pb);
avio_r8(pb);
avio_r8(pb);
- if (pb->eof_reached)
+ if (url_feof(pb))
return -1;
asf->data_offset = avio_tell(pb);
asf->packet_size_left = 0;
@@ -744,12 +752,12 @@ static int ff_asf_get_packet(AVFormatContext *s, AVIOContext *pb)
*/
if (pb->error == AVERROR(EAGAIN))
return AVERROR(EAGAIN);
- if (!pb->eof_reached)
+ if (!url_feof(pb))
av_log(s, AV_LOG_ERROR, "ff asf bad header %x at:%"PRId64"\n", c, avio_tell(pb));
}
if ((c & 0x8f) == 0x82) {
if (d || e) {
- if (!pb->eof_reached)
+ if (!url_feof(pb))
av_log(s, AV_LOG_ERROR, "ff asf bad non zero\n");
return -1;
}
@@ -848,6 +856,10 @@ static int asf_read_frame_header(AVFormatContext *s, AVIOContext *pb){
av_log(s, AV_LOG_ERROR, "unexpected packet_replic_size of %d\n", asf->packet_replic_size);
return -1;
}
+ if (rsize > asf->packet_size_left) {
+ av_log(s, AV_LOG_ERROR, "packet_replic_size is invalid\n");
+ return -1;
+ }
if (asf->packet_flags & 0x01) {
DO_2BITS(asf->packet_segsizetype >> 6, asf->packet_frag_size, 0); // 0 is illegal
if (rsize > asf->packet_size_left) {
@@ -865,10 +877,6 @@ static int asf_read_frame_header(AVFormatContext *s, AVIOContext *pb){
}
//printf("Fragsize %d\n", asf->packet_frag_size);
} else {
- if (rsize > asf->packet_size_left) {
- av_log(s, AV_LOG_ERROR, "packet_replic_size is invalid\n");
- return -1;
- }
asf->packet_frag_size = asf->packet_size_left - rsize;
//printf("Using rest %d %d %d\n", asf->packet_frag_size, asf->packet_size_left, rsize);
}
@@ -898,7 +906,7 @@ static int ff_asf_parse_packet(AVFormatContext *s, AVIOContext *pb, AVPacket *pk
ASFStream *asf_st = 0;
for (;;) {
int ret;
- if(pb->eof_reached)
+ if(url_feof(pb))
return AVERROR_EOF;
if (asf->packet_size_left < FRAME_HEADER_SIZE
|| asf->packet_segments < 1) {
@@ -1162,7 +1170,8 @@ static int64_t asf_read_pts(AVFormatContext *s, int stream_index, int64_t *ppos,
if (s->packet_size > 0)
pos= (pos+s->packet_size-1-s->data_offset)/s->packet_size*s->packet_size+ s->data_offset;
*ppos= pos;
- avio_seek(s->pb, pos, SEEK_SET);
+ if (avio_seek(s->pb, pos, SEEK_SET) < 0)
+ return AV_NOPTS_VALUE;
//printf("asf_read_pts\n");
asf_reset_header(s);
@@ -1204,15 +1213,20 @@ static void asf_build_simple_index(AVFormatContext *s, int stream_index)
int64_t current_pos= avio_tell(s->pb);
int i;
- avio_seek(s->pb, asf->data_object_offset + asf->data_object_size, SEEK_SET);
+ if(avio_seek(s->pb, asf->data_object_offset + asf->data_object_size, SEEK_SET) < 0) {
+ asf->index_read= -1;
+ return;
+ }
+
ff_get_guid(s->pb, &g);
/* the data object can be followed by other top-level objects,
skip them until the simple index object is reached */
while (ff_guidcmp(&g, &index_guid)) {
int64_t gsize= avio_rl64(s->pb);
- if (gsize < 24 || s->pb->eof_reached) {
+ if (gsize < 24 || url_feof(s->pb)) {
avio_seek(s->pb, current_pos, SEEK_SET);
+ asf->index_read= -1;
return;
}
avio_skip(s->pb, gsize-24);
@@ -1268,7 +1282,7 @@ static int asf_read_seek(AVFormatContext *s, int stream_index, int64_t pts, int
if (!asf->index_read)
asf_build_simple_index(s, stream_index);
- if((asf->index_read && st->index_entries)){
+ if((asf->index_read > 0 && st->index_entries)){
index= av_index_search_timestamp(st, pts, flags);
if(index >= 0) {
/* find the position */
@@ -1276,7 +1290,8 @@ static int asf_read_seek(AVFormatContext *s, int stream_index, int64_t pts, int
/* do the seek */
av_log(s, AV_LOG_DEBUG, "SEEKTO: %"PRId64"\n", pos);
- avio_seek(s->pb, pos, SEEK_SET);
+ if(avio_seek(s->pb, pos, SEEK_SET) < 0)
+ return -1;
asf_reset_header(s);
return 0;
}
@@ -1289,14 +1304,14 @@ static int asf_read_seek(AVFormatContext *s, int stream_index, int64_t pts, int
}
AVInputFormat ff_asf_demuxer = {
- "asf",
- NULL_IF_CONFIG_SMALL("ASF format"),
- sizeof(ASFContext),
- asf_probe,
- asf_read_header,
- asf_read_packet,
- asf_read_close,
- asf_read_seek,
- asf_read_pts,
+ .name = "asf",
+ .long_name = NULL_IF_CONFIG_SMALL("ASF format"),
+ .priv_data_size = sizeof(ASFContext),
+ .read_probe = asf_probe,
+ .read_header = asf_read_header,
+ .read_packet = asf_read_packet,
+ .read_close = asf_read_close,
+ .read_seek = asf_read_seek,
+ .read_timestamp = asf_read_pts,
.flags = AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH,
};
diff --git a/libavformat/asfenc.c b/libavformat/asfenc.c
index f9b9b3c045..5c6a81fb71 100644
--- a/libavformat/asfenc.c
+++ b/libavformat/asfenc.c
@@ -2,20 +2,20 @@
* ASF muxer
* Copyright (c) 2000, 2001 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avformat.h"
@@ -199,8 +199,8 @@ typedef struct {
/* packet filling */
unsigned char multi_payloads_present;
int packet_size_left;
- int packet_timestamp_start;
- int packet_timestamp_end;
+ int64_t packet_timestamp_start;
+ int64_t packet_timestamp_end;
unsigned int packet_nb_payloads;
uint8_t packet_buf[PACKET_SIZE];
AVIOContext pb;
@@ -215,8 +215,8 @@ typedef struct {
} ASFContext;
static const AVCodecTag codec_asf_bmp_tags[] = {
- { CODEC_ID_MPEG4, MKTAG('M', 'P', '4', 'S') },
{ CODEC_ID_MPEG4, MKTAG('M', '4', 'S', '2') },
+ { CODEC_ID_MPEG4, MKTAG('M', 'P', '4', 'S') },
{ CODEC_ID_MSMPEG4V3, MKTAG('M', 'P', '4', '3') },
{ CODEC_ID_NONE, 0 },
};
@@ -434,10 +434,6 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t data
if (enc->codec_type == AVMEDIA_TYPE_AUDIO) {
/* WAVEFORMATEX header */
int wavsize = ff_put_wav_header(pb, enc);
- if ((enc->codec_id != CODEC_ID_MP3) && (enc->codec_id != CODEC_ID_MP2) && (enc->codec_id != CODEC_ID_ADPCM_IMA_WAV) && (enc->extradata_size==0)) {
- wavsize += 2;
- avio_wl16(pb, 0);
- }
if (wavsize < 0)
return -1;
@@ -684,7 +680,7 @@ static void flush_packet(AVFormatContext *s)
static void put_payload_header(
AVFormatContext *s,
ASFStream *stream,
- int presentation_time,
+ int64_t presentation_time,
int m_obj_size,
int m_obj_offset,
int payload_len,
@@ -711,7 +707,7 @@ static void put_payload_header(
avio_w8(pb, ASF_PAYLOAD_REPLICATED_DATA_LENGTH);
avio_wl32(pb, m_obj_size); //Replicated Data - Media Object Size
- avio_wl32(pb, presentation_time);//Replicated Data - Presentation Time
+ avio_wl32(pb, (uint32_t) presentation_time);//Replicated Data - Presentation Time
if (asf->multi_payloads_present){
avio_wl16(pb, payload_len); //payload length
@@ -722,7 +718,7 @@ static void put_frame(
AVFormatContext *s,
ASFStream *stream,
AVStream *avst,
- int timestamp,
+ int64_t timestamp,
const uint8_t *buf,
int m_obj_size,
int flags
@@ -882,20 +878,20 @@ static int asf_write_trailer(AVFormatContext *s)
#if CONFIG_ASF_MUXER
AVOutputFormat ff_asf_muxer = {
- "asf",
- NULL_IF_CONFIG_SMALL("ASF format"),
- "video/x-ms-asf",
- "asf,wmv,wma",
- sizeof(ASFContext),
+ .name = "asf",
+ .long_name = NULL_IF_CONFIG_SMALL("ASF format"),
+ .mime_type = "video/x-ms-asf",
+ .extensions = "asf,wmv,wma",
+ .priv_data_size = sizeof(ASFContext),
#if CONFIG_LIBMP3LAME
- CODEC_ID_MP3,
+ .audio_codec = CODEC_ID_MP3,
#else
- CODEC_ID_MP2,
+ .audio_codec = CODEC_ID_MP2,
#endif
- CODEC_ID_MSMPEG4V3,
- asf_write_header,
- asf_write_packet,
- asf_write_trailer,
+ .video_codec = CODEC_ID_MSMPEG4V3,
+ .write_header = asf_write_header,
+ .write_packet = asf_write_packet,
+ .write_trailer = asf_write_trailer,
.flags = AVFMT_GLOBALHEADER,
.codec_tag= (const AVCodecTag* const []){codec_asf_bmp_tags, ff_codec_bmp_tags, ff_codec_wav_tags, 0},
};
@@ -903,20 +899,20 @@ AVOutputFormat ff_asf_muxer = {
#if CONFIG_ASF_STREAM_MUXER
AVOutputFormat ff_asf_stream_muxer = {
- "asf_stream",
- NULL_IF_CONFIG_SMALL("ASF format"),
- "video/x-ms-asf",
- "asf,wmv,wma",
- sizeof(ASFContext),
+ .name = "asf_stream",
+ .long_name = NULL_IF_CONFIG_SMALL("ASF format"),
+ .mime_type = "video/x-ms-asf",
+ .extensions = "asf,wmv,wma",
+ .priv_data_size = sizeof(ASFContext),
#if CONFIG_LIBMP3LAME
- CODEC_ID_MP3,
+ .audio_codec = CODEC_ID_MP3,
#else
- CODEC_ID_MP2,
+ .audio_codec = CODEC_ID_WMAV2,
#endif
- CODEC_ID_MSMPEG4V3,
- asf_write_stream_header,
- asf_write_packet,
- asf_write_trailer,
+ .video_codec = CODEC_ID_MSMPEG4V3,
+ .write_header = asf_write_stream_header,
+ .write_packet = asf_write_packet,
+ .write_trailer = asf_write_trailer,
.flags = AVFMT_GLOBALHEADER,
.codec_tag= (const AVCodecTag* const []){codec_asf_bmp_tags, ff_codec_bmp_tags, ff_codec_wav_tags, 0},
};
diff --git a/libavformat/assdec.c b/libavformat/assdec.c
index 08b520e656..4f1126cc0e 100644
--- a/libavformat/assdec.c
+++ b/libavformat/assdec.c
@@ -2,20 +2,20 @@
* SSA/ASS demuxer
* Copyright (c) 2008 Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -83,7 +83,7 @@ static int read_header(AVFormatContext *s, AVFormatParameters *ap)
uint8_t *p, **dst[2]={0};
int pos[2]={0};
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return -1;
av_set_pts_info(st, 64, 1, 100);
@@ -93,7 +93,7 @@ static int read_header(AVFormatContext *s, AVFormatParameters *ap)
header_remaining= INT_MAX;
dst[0] = &st->codec->extradata;
dst[1] = &ass->event_buffer;
- while(!pb->eof_reached){
+ while(!url_feof(pb)){
uint8_t line[MAX_LINESIZE];
len = ff_get_line(pb, line, sizeof(line));
diff --git a/libavformat/assenc.c b/libavformat/assenc.c
index c53af16bbd..b367668d2d 100644
--- a/libavformat/assenc.c
+++ b/libavformat/assenc.c
@@ -2,20 +2,20 @@
* SSA/ASS muxer
* Copyright (c) 2008 Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/au.c b/libavformat/au.c
index 6cffe1c1ce..af00e6d4ff 100644
--- a/libavformat/au.c
+++ b/libavformat/au.c
@@ -2,20 +2,20 @@
* AU muxer and demuxer
* Copyright (c) 2001 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -120,7 +120,7 @@ static int au_probe(AVProbeData *p)
static int au_read_header(AVFormatContext *s,
AVFormatParameters *ap)
{
- int size;
+ int size, bps, data_size = 0;
unsigned int tag;
AVIOContext *pb = s->pb;
unsigned int id, channels, rate;
@@ -132,7 +132,12 @@ static int au_read_header(AVFormatContext *s,
if (tag != MKTAG('.', 's', 'n', 'd'))
return -1;
size = avio_rb32(pb); /* header size */
- avio_rb32(pb); /* data size */
+ data_size = avio_rb32(pb); /* data size in bytes */
+
+ if (data_size < 0 && data_size != AU_UNKNOWN_SIZE) {
+ av_log(s, AV_LOG_ERROR, "Invalid negative data size '%d' found\n", data_size);
+ return AVERROR_INVALIDDATA;
+ }
id = avio_rb32(pb);
rate = avio_rb32(pb);
@@ -140,7 +145,7 @@ static int au_read_header(AVFormatContext *s,
codec = ff_codec_get_id(codec_au_tags, id);
- if (!av_get_bits_per_sample(codec)) {
+ if (!(bps = av_get_bits_per_sample(codec))) {
av_log_ask_for_sample(s, "could not determine bits per sample\n");
return AVERROR_INVALIDDATA;
}
@@ -151,7 +156,7 @@ static int au_read_header(AVFormatContext *s,
}
/* now we are ready: build format streams */
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return -1;
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
@@ -159,6 +164,8 @@ static int au_read_header(AVFormatContext *s,
st->codec->codec_id = codec;
st->codec->channels = channels;
st->codec->sample_rate = rate;
+ if (data_size != AU_UNKNOWN_SIZE)
+ st->duration = (((int64_t)data_size)<<3) / (st->codec->channels * bps);
av_set_pts_info(st, 64, 1, rate);
return 0;
}
@@ -185,30 +192,27 @@ static int au_read_packet(AVFormatContext *s,
#if CONFIG_AU_DEMUXER
AVInputFormat ff_au_demuxer = {
- "au",
- NULL_IF_CONFIG_SMALL("SUN AU format"),
- 0,
- au_probe,
- au_read_header,
- au_read_packet,
- NULL,
- pcm_read_seek,
+ .name = "au",
+ .long_name = NULL_IF_CONFIG_SMALL("SUN AU format"),
+ .read_probe = au_probe,
+ .read_header = au_read_header,
+ .read_packet = au_read_packet,
+ .read_seek = pcm_read_seek,
.codec_tag= (const AVCodecTag* const []){codec_au_tags, 0},
};
#endif
#if CONFIG_AU_MUXER
AVOutputFormat ff_au_muxer = {
- "au",
- NULL_IF_CONFIG_SMALL("SUN AU format"),
- "audio/basic",
- "au",
- 0,
- CODEC_ID_PCM_S16BE,
- CODEC_ID_NONE,
- au_write_header,
- au_write_packet,
- au_write_trailer,
+ .name = "au",
+ .long_name = NULL_IF_CONFIG_SMALL("SUN AU format"),
+ .mime_type = "audio/basic",
+ .extensions = "au",
+ .audio_codec = CODEC_ID_PCM_S16BE,
+ .video_codec = CODEC_ID_NONE,
+ .write_header = au_write_header,
+ .write_packet = au_write_packet,
+ .write_trailer = au_write_trailer,
.codec_tag= (const AVCodecTag* const []){codec_au_tags, 0},
};
#endif //CONFIG_AU_MUXER
diff --git a/libavformat/audiointerleave.c b/libavformat/audiointerleave.c
index e48f826e14..844112fcf5 100644
--- a/libavformat/audiointerleave.c
+++ b/libavformat/audiointerleave.c
@@ -3,20 +3,20 @@
*
* Copyright (c) 2009 Baptiste Coudurier <baptiste dot coudurier at gmail dot com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/audiointerleave.h b/libavformat/audiointerleave.h
index af29629b8a..b37c8aefbd 100644
--- a/libavformat/audiointerleave.h
+++ b/libavformat/audiointerleave.h
@@ -3,20 +3,20 @@
*
* Copyright (c) 2009 Baptiste Coudurier <baptiste dot coudurier at gmail dot com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/avc.c b/libavformat/avc.c
index 70a05ec5bc..ed2125b527 100644
--- a/libavformat/avc.c
+++ b/libavformat/avc.c
@@ -2,20 +2,20 @@
* AVC helper functions for muxers
* Copyright (c) 2006 Baptiste Coudurier <baptiste.coudurier@smartjog.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/avc.h b/libavformat/avc.h
index 56122125a9..46e5e37a54 100644
--- a/libavformat/avc.h
+++ b/libavformat/avc.h
@@ -2,20 +2,20 @@
* AVC helper functions for muxers
* Copyright (c) 2008 Aurelien Jacobs <aurel@gnuage.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 12490c1209..441f85d503 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -1,20 +1,20 @@
/*
* copyright (c) 2001 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -53,7 +53,7 @@ struct AVFormatContext;
* @defgroup metadata_api Public Metadata API
* @{
* The metadata API allows libavformat to export metadata tags to a client
- * application using a sequence of key/value pairs. Like all strings in Libav,
+ * application using a sequence of key/value pairs. Like all strings in FFmpeg,
* metadata must be stored as UTF-8 encoded Unicode. Note that metadata
* exported by demuxers isn't checked to be valid UTF-8 in most cases.
* Important concepts to keep in mind:
@@ -274,6 +274,10 @@ typedef struct AVFormatParameters {
#define AVFMT_NOSTREAMS 0x1000 /**< Format does not require any streams */
#define AVFMT_NOBINSEARCH 0x2000 /**< Format does not allow to fallback to binary search via read_timestamp */
#define AVFMT_NOGENSEARCH 0x4000 /**< Format does not allow to fallback to generic search */
+#define AVFMT_NO_BYTE_SEEK 0x8000 /**< Format does not allow seeking by bytes */
+#define AVFMT_TS_NONSTRICT 0x8000000 /**< Format does not require strictly
+ increasing timestamps, but they must
+ still be monotonic */
typedef struct AVOutputFormat {
const char *name;
@@ -301,10 +305,9 @@ typedef struct AVOutputFormat {
* AVFMT_NODIMENSIONS, AVFMT_NOSTREAMS
*/
int flags;
- /**
- * Currently only used to set pixel format if not YUV420P.
- */
- int (*set_parameters)(struct AVFormatContext *, AVFormatParameters *);
+
+ void *dummy;
+
int (*interleave_packet)(struct AVFormatContext *, AVPacket *out,
AVPacket *in, int flush);
@@ -322,6 +325,17 @@ typedef struct AVOutputFormat {
const AVClass *priv_class; ///< AVClass for the private context
+ /**
+ * Test if the given codec can be stored in this container.
+ *
+ * @return 1 if the codec is supported, 0 if it is not.
+ * A negative number if unknown.
+ */
+ int (*query_codec)(enum CodecID id, int std_compliance);
+
+ void (*get_output_timestamp)(struct AVFormatContext *s, int stream,
+ int64_t *dts, int64_t *wall);
+
/* private fields */
struct AVOutputFormat *next;
} AVOutputFormat;
@@ -398,7 +412,9 @@ typedef struct AVInputFormat {
int64_t *pos, int64_t pos_limit);
/**
- * Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER.
+ * Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_SHOW_IDS,
+ * AVFMT_GENERIC_INDEX, AVFMT_TS_DISCONT, AVFMT_NOBINSEARCH,
+ * AVFMT_NOGENSEARCH, AVFMT_NO_BYTE_SEEK.
*/
int flags;
@@ -456,7 +472,12 @@ enum AVStreamParseType {
typedef struct AVIndexEntry {
int64_t pos;
- int64_t timestamp;
+ int64_t timestamp; /**<
+ * Timestamp in AVStream.time_base units, preferably the time from which on correctly decoded frames are available
+ * when seeking to this entry. That means preferable PTS on keyframe based formats.
+ * But demuxers can choose to store a different timestamp, if it is more convenient for the implementation or nothing better
+ * is known
+ */
#define AVINDEX_KEYFRAME 0x0001
int flags:2;
int size:30; //Yeah, trying to keep the size of this small to reduce memory requirements (it is 24 vs. 32 bytes due to possible 8-byte alignment).
@@ -523,18 +544,22 @@ typedef struct AVStream {
int stream_copy; /**< If set, just copy stream. */
enum AVDiscard discard; ///< Selects which packets can be discarded at will and do not need to be demuxed.
+#if FF_API_AVSTREAM_QUALITY
//FIXME move stuff to a flags field?
/**
* Quality, as it has been removed from AVCodecContext and put in AVVideoFrame.
* MN: dunno if that is the right place for it
*/
- float quality;
+ attribute_deprecated float quality;
+#endif
/**
- * Decoding: pts of the first frame of the stream, in stream time base.
+ * Decoding: pts of the first frame of the stream in presentation order, in stream time base.
* Only set this if you are absolutely 100% sure that the value you set
* it to really is the pts of the first frame.
* This may be undefined (AV_NOPTS_VALUE).
+ * @note The ASF header does NOT contain a correct start_time the ASF
+ * demuxer must NOT set this.
*/
int64_t start_time;
@@ -615,6 +640,13 @@ typedef struct AVStream {
int codec_info_nb_frames;
/**
+ * Stream Identifier
+ * This is the MPEG-TS stream identifier +1
+ * 0 means unknown
+ */
+ int stream_identifier;
+
+ /**
* Stream informations used internally by av_find_stream_info()
*/
#define MAX_STD_TIMEBASES (60*12+5)
@@ -622,9 +654,15 @@ typedef struct AVStream {
int64_t last_dts;
int64_t duration_gcd;
int duration_count;
- double duration_error[MAX_STD_TIMEBASES];
+ double duration_error[2][2][MAX_STD_TIMEBASES];
int64_t codec_info_duration;
} *info;
+
+ /**
+ * flag to indicate that probing is requested
+ * NOT PART OF PUBLIC API
+ */
+ int request_probe;
} AVStream;
#define AV_PROGRAM_RUNNING 1
@@ -642,6 +680,10 @@ typedef struct AVProgram {
unsigned int *stream_index;
unsigned int nb_stream_indexes;
AVDictionary *metadata;
+
+ int program_num;
+ int pmt_pid;
+ int pcr_pid;
} AVProgram;
#define AVFMTCTX_NOHEADER 0x0001 /**< signal that no header is present
@@ -672,7 +714,12 @@ typedef struct AVFormatContext {
AVStream **streams;
char filename[1024]; /**< input or output filename */
/* stream info */
- int64_t timestamp;
+#if FF_API_TIMESTAMP
+ /**
+ * @deprecated use 'creation_time' metadata tag instead
+ */
+ attribute_deprecated int64_t timestamp;
+#endif
int ctx_flags; /**< Format-specific flags, see AVFMTCTX_xx */
/* private data for pts handling (do not modify directly). */
@@ -698,15 +745,17 @@ typedef struct AVFormatContext {
*/
int64_t duration;
+#if FF_API_FILESIZE
/**
* decoding: total file size, 0 if unknown
*/
- int64_t file_size;
+ attribute_deprecated int64_t file_size;
+#endif
/**
* Decoding: total stream bitrate in bit/s, 0 if not
* available. Never set it directly if the file_size and the
- * duration are known as Libav can compute it automatically.
+ * duration are known as FFmpeg can compute it automatically.
*/
int bit_rate;
@@ -716,17 +765,26 @@ typedef struct AVFormatContext {
/* av_seek_frame() support */
int64_t data_offset; /**< offset of the first packet */
- int mux_rate;
+#if FF_API_MUXRATE
+ /**
+ * use mpeg muxer private options instead
+ */
+ attribute_deprecated int mux_rate;
+#endif
unsigned int packet_size;
int preload;
int max_delay;
+#if FF_API_LOOP_OUTPUT
#define AVFMT_NOOUTPUTLOOP -1
#define AVFMT_INFINITEOUTPUTLOOP 0
/**
* number of times to loop output in formats that support it
+ *
+ * @deprecated use the 'loop' private option in the gif muxer.
*/
- int loop_output;
+ attribute_deprecated int loop_output;
+#endif
int flags;
#define AVFMT_FLAG_GENPTS 0x0001 ///< Generate missing pts even if it requires parsing future frames.
@@ -739,8 +797,18 @@ typedef struct AVFormatContext {
#define AVFMT_FLAG_RTP_HINT 0x0040 ///< Deprecated, use the -movflags rtphint muxer specific AVOption instead
#endif
#define AVFMT_FLAG_CUSTOM_IO 0x0080 ///< The caller has supplied a custom AVIOContext, don't avio_close() it.
+#define AVFMT_FLAG_DISCARD_CORRUPT 0x0100 ///< Discard frames marked corrupted
+#define AVFMT_FLAG_MP4A_LATM 0x8000 ///< Enable RTP MP4A-LATM payload
+#define AVFMT_FLAG_SORT_DTS 0x10000 ///< try to interleave outputted packets by dts (using this flag can slow demuxing down)
+#define AVFMT_FLAG_PRIV_OPT 0x20000 ///< Enable use of private options by delaying codec open (this could be made default once all code is converted)
+#define AVFMT_FLAG_KEEP_SIDE_DATA 0x40000 ///< Dont merge side data but keep it seperate.
- int loop_input;
+#if FF_API_LOOP_INPUT
+ /**
+ * @deprecated, use the 'loop' img2 demuxer private option.
+ */
+ attribute_deprecated int loop_input;
+#endif
/**
* decoding: size of data to probe; encoding: unused.
@@ -837,6 +905,20 @@ typedef struct AVFormatContext {
* decoding: number of frames used to probe fps
*/
int fps_probe_size;
+
+ /**
+ * Error recognition; higher values will detect more errors but may
+ * misdetect some more or less valid parts as errors.
+ * - encoding: unused
+ * - decoding: Set by user.
+ */
+ int error_recognition;
+
+ /**
+ * Transport stream id.
+ * This will be moved into demuxer private options. Thus no API/ABI compatibility
+ */
+ int ts_id;
} AVFormatContext;
typedef struct AVPacketList {
@@ -1006,6 +1088,15 @@ AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, int *score_max);
/**
+ * Guess the file format.
+ *
+ * @param is_opened Whether the file is already opened; determines whether
+ * demuxers with or without AVFMT_NOFILE are probed.
+ * @param score_ret The score of the best detection.
+ */
+AVInputFormat *av_probe_input_format3(AVProbeData *pd, int is_opened, int *score_ret);
+
+/**
* Probe a bytestream to determine the input format. Each time a probe returns
* with a score that is too low, the probe buffer size is increased and another
* attempt is made. When the maximum probe size is reached, the input format
@@ -1075,6 +1166,8 @@ attribute_deprecated int av_open_input_file(AVFormatContext **ic_ptr, const char
*/
int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options);
+int av_demuxer_open(AVFormatContext *ic, AVFormatParameters *ap);
+
/**
* Allocate an AVFormatContext.
* avformat_free_context() can be used to free the context and everything
@@ -1082,6 +1175,36 @@ int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputForma
*/
AVFormatContext *avformat_alloc_context(void);
+#if FF_API_ALLOC_OUTPUT_CONTEXT
+/**
+ * @deprecated deprecated in favor of avformat_alloc_output_context2()
+ */
+attribute_deprecated
+AVFormatContext *avformat_alloc_output_context(const char *format,
+ AVOutputFormat *oformat,
+ const char *filename);
+#endif
+
+/**
+ * Allocate an AVFormatContext for an output format.
+ * avformat_free_context() can be used to free the context and
+ * everything allocated by the framework within it.
+ *
+ * @param *ctx is set to the created format context, or to NULL in
+ * case of failure
+ * @param oformat format to use for allocating the context, if NULL
+ * format_name and filename are used instead
+ * @param format_name the name of output format to use for allocating the
+ * context, if NULL filename is used instead
+ * @param filename the name of the filename to use for allocating the
+ * context, may be NULL
+ * @return >= 0 in case of success, a negative AVERROR code in case of
+ * failure
+ */
+int avformat_alloc_output_context2(AVFormatContext **ctx, AVOutputFormat *oformat,
+ const char *format_name, const char *filename);
+
+#if FF_API_FORMAT_PARAMETERS
/**
* Read packets of a media file to get stream information. This
* is useful for file formats with no headers such as MPEG. This
@@ -1094,8 +1217,47 @@ AVFormatContext *avformat_alloc_context(void);
* @return >=0 if OK, AVERROR_xxx on error
* @todo Let the user decide somehow what information is needed so that
* we do not waste time getting stuff the user does not need.
+ *
+ * @deprecated use avformat_find_stream_info.
*/
+attribute_deprecated
int av_find_stream_info(AVFormatContext *ic);
+#endif
+
+/**
+ * Read packets of a media file to get stream information. This
+ * is useful for file formats with no headers such as MPEG. This
+ * function also computes the real framerate in case of MPEG-2 repeat
+ * frame mode.
+ * The logical file position is not changed by this function;
+ * examined packets may be buffered for later processing.
+ *
+ * @param ic media file handle
+ * @param options If non-NULL, an ic.nb_streams long array of pointers to
+ * dictionaries, where i-th member contains options for
+ * codec corresponding to i-th stream.
+ * On return each dictionary will be filled with options that were not found.
+ * @return >=0 if OK, AVERROR_xxx on error
+ *
+ * @note this function isn't guaranteed to open all the codecs, so
+ * options being non-empty at return is a perfectly normal behavior.
+ *
+ * @todo Let the user decide somehow what information is needed so that
+ * we do not waste time getting stuff the user does not need.
+ */
+int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options);
+
+/**
+ * Find the programs which belong to a given stream.
+ *
+ * @param ic media file handle
+ * @param last the last found program, the search will start after this
+ * program, or from the beginning if it is NULL
+ * @param s stream index
+ * @return the next program which belongs to s, NULL if no program is found or
+ * the last program is not among the programs of ic.
+ */
+AVProgram *av_find_program_from_stream(AVFormatContext *ic, AVProgram *last, int s);
/**
* Find the "best" stream in the file.
@@ -1240,6 +1402,7 @@ void av_close_input_file(AVFormatContext *s);
*/
void avformat_free_context(AVFormatContext *s);
+#if FF_API_NEW_STREAM
/**
* Add a new stream to a media file.
*
@@ -1250,7 +1413,27 @@ void avformat_free_context(AVFormatContext *s);
* @param s media file handle
* @param id file-format-dependent stream ID
*/
+attribute_deprecated
AVStream *av_new_stream(AVFormatContext *s, int id);
+#endif
+
+/**
+ * Add a new stream to a media file.
+ *
+ * When demuxing, it is called by the demuxer in read_header(). If the
+ * flag AVFMTCTX_NOHEADER is set in s.ctx_flags, then it may also
+ * be called in read_packet().
+ *
+ * When muxing, should be called by the user before avformat_write_header().
+ *
+ * @param c If non-NULL, the AVCodecContext corresponding to the new stream
+ * will be initialized to use this codec. This is needed for e.g. codec-specific
+ * defaults to be set, so codec should be provided if it is known.
+ *
+ * @return newly created stream or NULL on error.
+ */
+AVStream *avformat_new_stream(AVFormatContext *s, AVCodec *c);
+
AVProgram *av_new_program(AVFormatContext *s, int id);
/**
@@ -1455,7 +1638,28 @@ int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
*/
int av_write_trailer(AVFormatContext *s);
+/**
+ * Get timing information for the data currently output.
+ * The exact meaning of "currently output" depends on the format.
+ * It is mostly relevant for devices that have an internal buffer and/or
+ * work in real time.
+ * @param s media file handle
+ * @param stream stream in the media file
+ * @param dts[out] DTS of the last packet output for the stream, in stream
+ * time_base units
+ * @param wall[out] absolute time when that packet whas output,
+ * in microsecond
+ * @return 0 if OK, AVERROR(ENOSYS) if the format does not support it
+ * Note: some formats or devices may not allow to measure dts and wall
+ * atomically.
+ */
+int av_get_output_timestamp(struct AVFormatContext *s, int stream,
+ int64_t *dts, int64_t *wall);
+
#if FF_API_DUMP_FORMAT
+/**
+ * @deprecated Deprecated in favor of av_dump_format().
+ */
attribute_deprecated void dump_format(AVFormatContext *ic,
int index,
const char *url,
@@ -1542,4 +1746,22 @@ attribute_deprecated int avf_sdp_create(AVFormatContext *ac[], int n_files, char
*/
int av_match_ext(const char *filename, const char *extensions);
+/**
+ * Test if the given container can store a codec.
+ *
+ * @param std_compliance standards compliance level, one of FF_COMPLIANCE_*
+ *
+ * @return 1 if codec with ID codec_id can be stored in ofmt, 0 if it cannot.
+ * A negative number if this information is not available.
+ */
+int avformat_query_codec(AVOutputFormat *ofmt, enum CodecID codec_id, int std_compliance);
+
+/**
+ * Get the AVClass for AVFormatContext. It can be used in combination with
+ * AV_OPT_SEARCH_FAKE_OBJ for examining options.
+ *
+ * @see av_opt_find().
+ */
+const AVClass *avformat_get_class(void);
+
#endif /* AVFORMAT_AVFORMAT_H */
diff --git a/libavformat/avi.c b/libavformat/avi.c
index 9f36b27f35..705ad03ab0 100644
--- a/libavformat/avi.c
+++ b/libavformat/avi.c
@@ -2,20 +2,20 @@
* AVI common data
* Copyright (c) 2010 Anton Khirnov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/avi.h b/libavformat/avi.h
index 05e02977f6..b4e551971a 100644
--- a/libavformat/avi.h
+++ b/libavformat/avi.h
@@ -1,20 +1,20 @@
/*
* copyright (c) 2001 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/avidec.c b/libavformat/avidec.c
index 2ea156e9ec..0995150454 100644
--- a/libavformat/avidec.c
+++ b/libavformat/avidec.c
@@ -2,20 +2,20 @@
* AVI demuxer
* Copyright (c) 2001 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -23,6 +23,7 @@
#include "libavutil/intreadwrite.h"
#include "libavutil/mathematics.h"
#include "libavutil/bswap.h"
+#include "libavutil/opt.h"
#include "libavutil/dict.h"
#include "avformat.h"
#include "avi.h"
@@ -53,9 +54,12 @@ typedef struct AVIStream {
AVFormatContext *sub_ctx;
AVPacket sub_pkt;
uint8_t *sub_buffer;
+
+ int64_t seek_pos;
} AVIStream;
typedef struct {
+ const AVClass *class;
int64_t riff_end;
int64_t movi_end;
int64_t fsize;
@@ -67,9 +71,25 @@ typedef struct {
int stream_index;
DVDemuxContext* dv_demux;
int odml_depth;
+ int use_odml;
#define MAX_ODML_DEPTH 1000
+ int64_t dts_max;
} AVIContext;
+
+static const AVOption options[] = {
+ { "use_odml", "use odml index", offsetof(AVIContext, use_odml), AV_OPT_TYPE_INT, {.dbl = 1}, -1, 1, AV_OPT_FLAG_DECODING_PARAM},
+ { NULL },
+};
+
+static const AVClass demuxer_class = {
+ "AVI demuxer",
+ av_default_item_name,
+ options,
+ LIBAVUTIL_VERSION_INT,
+};
+
+
static const char avi_headers[][8] = {
{ 'R', 'I', 'F', 'F', 'A', 'V', 'I', ' ' },
{ 'R', 'I', 'F', 'F', 'A', 'V', 'I', 'X' },
@@ -137,7 +157,7 @@ static int read_braindead_odml_indx(AVFormatContext *s, int frame_num){
AVIStream *ast;
int i;
int64_t last_pos= -1;
- int64_t filesize= avio_size(s->pb);
+ int64_t filesize= avi->fsize;
av_dlog(s, "longs_pre_entry:%d index_type:%d entries_in_use:%d chunk_id:%X base:%16"PRIX64"\n",
longs_pre_entry,index_type, entries_in_use, chunk_id, base);
@@ -172,9 +192,10 @@ static int read_braindead_odml_indx(AVFormatContext *s, int frame_num){
int key= len >= 0;
len &= 0x7FFFFFFF;
- av_dlog(s, "pos:%"PRId64", len:%X\n", pos, len);
-
- if(pb->eof_reached)
+#ifdef DEBUG_SEEK
+ av_log(s, AV_LOG_ERROR, "pos:%"PRId64", len:%X\n", pos, len);
+#endif
+ if(url_feof(pb))
return -1;
if(last_pos == pos || pos == base - 8)
@@ -191,7 +212,7 @@ static int read_braindead_odml_indx(AVFormatContext *s, int frame_num){
avio_rl32(pb); /* size */
duration = avio_rl32(pb);
- if(pb->eof_reached)
+ if(url_feof(pb))
return -1;
pos = avio_tell(pb);
@@ -201,16 +222,21 @@ static int read_braindead_odml_indx(AVFormatContext *s, int frame_num){
return -1;
}
- avio_seek(pb, offset+8, SEEK_SET);
+ if(avio_seek(pb, offset+8, SEEK_SET) < 0)
+ return -1;
avi->odml_depth++;
read_braindead_odml_indx(s, frame_num);
avi->odml_depth--;
frame_num += duration;
- avio_seek(pb, pos, SEEK_SET);
+ if(avio_seek(pb, pos, SEEK_SET) < 0) {
+ av_log(s, AV_LOG_ERROR, "Failed to restore position after reading index");
+ return -1;
+ }
+
}
}
- avi->index_loaded=1;
+ avi->index_loaded=2;
return 0;
}
@@ -348,8 +374,10 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
if (get_riff(s, pb) < 0)
return -1;
+ av_log(avi, AV_LOG_DEBUG, "use odml:%d\n", avi->use_odml);
+
avi->fsize = avio_size(pb);
- if(avi->fsize<=0)
+ if(avi->fsize<=0 || avi->fsize < avi->riff_end)
avi->fsize= avi->riff_end == 8 ? INT64_MAX : avi->riff_end;
/* first list tag */
@@ -357,7 +385,7 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
codec_type = -1;
frame_period = 0;
for(;;) {
- if (pb->eof_reached)
+ if (url_feof(pb))
goto fail;
tag = avio_rl32(pb);
size = avio_rl32(pb);
@@ -375,7 +403,7 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
if (tag1 == MKTAG('m', 'o', 'v', 'i')) {
avi->movi_list = avio_tell(pb) - 4;
if(size) avi->movi_end = avi->movi_list + size + (size & 1);
- else avi->movi_end = avio_size(pb);
+ else avi->movi_end = avi->fsize;
av_dlog(NULL, "movi end=%"PRIx64"\n", avi->movi_end);
goto end_of_header;
}
@@ -403,7 +431,7 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
/* AVI header */
/* using frame_period is bad idea */
frame_period = avio_rl32(pb);
- avio_skip(pb, 4);
+ avio_rl32(pb); /* max. bytes per second */
avio_rl32(pb);
avi->non_interleaved |= avio_rl32(pb) & AVIF_MUSTUSEINDEX;
@@ -426,10 +454,11 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
break;
}else{
stream_index++;
- st = av_new_stream(s, stream_index);
+ st = avformat_new_stream(s, NULL);
if (!st)
goto fail;
+ st->id = stream_index;
ast = av_mallocz(sizeof(AVIStream));
if (!ast)
goto fail;
@@ -461,7 +490,7 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
av_freep(&s->streams[0]);
s->nb_streams = 0;
if (CONFIG_DV_DEMUXER) {
- avi->dv_demux = dv_init_demux(s);
+ avi->dv_demux = avpriv_dv_init_demux(s);
if (!avi->dv_demux)
goto fail;
}
@@ -533,8 +562,7 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
codec_type = AVMEDIA_TYPE_DATA;
break;
default:
- av_log(s, AV_LOG_ERROR, "unknown stream type %X\n", tag1);
- goto fail;
+ av_log(s, AV_LOG_INFO, "unknown stream type %X\n", tag1);
}
if(ast->sample_size == 0)
st->duration = st->nb_frames;
@@ -543,6 +571,8 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
break;
case MKTAG('s', 't', 'r', 'f'):
/* stream header */
+ if (!size)
+ break;
if (stream_index >= (unsigned)s->nb_streams || avi->dv_demux) {
avio_skip(pb, size);
} else {
@@ -584,7 +614,7 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
/* Extract palette from extradata if bpp <= 8. */
/* This code assumes that extradata contains only palette. */
- /* This is true for all paletted codecs implemented in Libav. */
+ /* This is true for all paletted codecs implemented in FFmpeg. */
if (st->codec->extradata_size && (st->codec->bits_per_coded_sample <= 8)) {
int pal_size = (1 << st->codec->bits_per_coded_sample) << 2;
const uint8_t *pal_src;
@@ -593,7 +623,7 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
pal_src = st->codec->extradata + st->codec->extradata_size - pal_size;
#if HAVE_BIGENDIAN
for (i = 0; i < pal_size/4; i++)
- ast->pal[i] = av_bswap32(((uint32_t*)pal_src)[i]);
+ ast->pal[i] = AV_RL32(pal_src+4*i);
#else
memcpy(ast->pal, pal_src, pal_size);
#endif
@@ -614,7 +644,7 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
if(st->codec->codec_tag==0 && st->codec->height > 0 && st->codec->extradata_size < 1U<<30){
st->codec->extradata_size+= 9;
- st->codec->extradata= av_realloc(st->codec->extradata, st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
+ st->codec->extradata= av_realloc_f(st->codec->extradata, 1, st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
if(st->codec->extradata)
memcpy(st->codec->extradata + st->codec->extradata_size - 9, "BottomUp", 9);
}
@@ -646,6 +676,7 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
if (st->codec->stream_codec_tag == AV_RL32("Axan")){
st->codec->codec_id = CODEC_ID_XAN_DPCM;
st->codec->codec_tag = 0;
+ ast->dshow_block_align = 0;
}
if (amv_file_format){
st->codec->codec_id = CODEC_ID_ADPCM_IMA_AMV;
@@ -654,7 +685,7 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
break;
case AVMEDIA_TYPE_SUBTITLE:
st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;
- st->codec->codec_id = CODEC_ID_PROBE;
+ st->request_probe= 1;
break;
default:
st->codec->codec_type = AVMEDIA_TYPE_DATA;
@@ -667,9 +698,9 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
break;
case MKTAG('i', 'n', 'd', 'x'):
i= avio_tell(pb);
- if(pb->seekable && !(s->flags & AVFMT_FLAG_IGNIDX)){
- read_braindead_odml_indx(s, 0);
- }
+ if(pb->seekable && !(s->flags & AVFMT_FLAG_IGNIDX) && avi->use_odml &&
+ read_braindead_odml_indx(s, 0) < 0 && s->error_recognition >= FF_ER_EXPLODE){
+ goto fail; }
avio_seek(pb, i+size, SEEK_SET);
break;
case MKTAG('v', 'p', 'r', 'p'):
@@ -706,8 +737,9 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
if(size > 1000000){
av_log(s, AV_LOG_ERROR, "Something went wrong during header parsing, "
"I will ignore it and try to continue anyway.\n");
+ if (s->error_recognition >= FF_ER_EXPLODE) goto fail;
avi->movi_list = avio_tell(pb) - 4;
- avi->movi_end = avio_size(pb);
+ avi->movi_end = avi->fsize;
goto end_of_header;
}
/* skip tag */
@@ -725,13 +757,17 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
if(!avi->index_loaded && pb->seekable)
avi_load_index(s);
- avi->index_loaded = 1;
- avi->non_interleaved |= guess_ni_flag(s);
+ avi->index_loaded |= 1;
+ avi->non_interleaved |= guess_ni_flag(s) | (s->flags & AVFMT_FLAG_SORT_DTS);
for(i=0; i<s->nb_streams; i++){
AVStream *st = s->streams[i];
if(st->nb_index_entries)
break;
}
+ // DV-in-AVI cannot be non-interleaved, if set this must be
+ // a mis-detection.
+ if(avi->dv_demux)
+ avi->non_interleaved=0;
if(i==s->nb_streams && avi->non_interleaved) {
av_log(s, AV_LOG_WARNING, "non-interleaved AVI without index, switching to interleaved\n");
avi->non_interleaved=0;
@@ -841,13 +877,14 @@ static int avi_sync(AVFormatContext *s, int exit_early)
{
AVIContext *avi = s->priv_data;
AVIOContext *pb = s->pb;
- int n, d[8];
+ int n;
+ unsigned int d[8];
unsigned int size;
int64_t i, sync;
start_sync:
- memset(d, -1, sizeof(int)*8);
- for(i=sync=avio_tell(pb); !pb->eof_reached; i++) {
+ memset(d, -1, sizeof(d));
+ for(i=sync=avio_tell(pb); !url_feof(pb); i++) {
int j;
for(j=0; j<7; j++)
@@ -858,7 +895,7 @@ start_sync:
n= get_stream_idx(d+2);
//av_log(s, AV_LOG_DEBUG, "%X %X %X %X %X %X %X %X %"PRId64" %d %d\n", d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], i, size, n);
- if(i + (uint64_t)size > avi->fsize || d[0]<0)
+ if(i + (uint64_t)size > avi->fsize || d[0] > 127)
continue;
//parse ix##
@@ -975,7 +1012,7 @@ static int avi_read_packet(AVFormatContext *s, AVPacket *pkt)
void* dstr;
if (CONFIG_DV_DEMUXER && avi->dv_demux) {
- int size = dv_get_packet(avi->dv_demux, pkt);
+ int size = avpriv_dv_get_packet(avi->dv_demux, pkt);
if (size >= 0)
return size;
}
@@ -1010,7 +1047,7 @@ static int avi_read_packet(AVFormatContext *s, AVPacket *pkt)
}
}
if(!best_st)
- return -1;
+ return AVERROR_EOF;
best_ast = best_st->priv_data;
best_ts = av_rescale_q(best_ts, (AVRational){FFMAX(1, best_ast->sample_size), AV_TIME_BASE}, best_st->time_base);
@@ -1026,7 +1063,8 @@ static int avi_read_packet(AVFormatContext *s, AVPacket *pkt)
if(i>=0){
int64_t pos= best_st->index_entries[i].pos;
pos += best_ast->packet_size - best_ast->remaining;
- avio_seek(s->pb, pos + 8, SEEK_SET);
+ if(avio_seek(s->pb, pos + 8, SEEK_SET) < 0)
+ return AVERROR_EOF;
// av_log(s, AV_LOG_DEBUG, "pos=%"PRId64"\n", pos);
assert(best_ast->remaining <= best_ast->packet_size);
@@ -1036,6 +1074,8 @@ static int avi_read_packet(AVFormatContext *s, AVPacket *pkt)
best_ast->packet_size=
best_ast->remaining= best_st->index_entries[i].size;
}
+ else
+ return AVERROR_EOF;
}
resync:
@@ -1075,8 +1115,8 @@ resync:
if (CONFIG_DV_DEMUXER && avi->dv_demux) {
dstr = pkt->destruct;
- size = dv_produce_packet(avi->dv_demux, pkt,
- pkt->data, pkt->size);
+ size = avpriv_dv_produce_packet(avi->dv_demux, pkt,
+ pkt->data, pkt->size, pkt->pos);
pkt->destruct = dstr;
pkt->flags |= AV_PKT_FLAG_KEY;
if (size < 0)
@@ -1105,6 +1145,23 @@ resync:
e= &st->index_entries[index];
if(index >= 0 && e->timestamp == ast->frame_offset){
+ if (index == st->nb_index_entries-1){
+ int key=1;
+ int i;
+ uint32_t state=-1;
+ for(i=0; i<FFMIN(size,256); i++){
+ if(st->codec->codec_id == CODEC_ID_MPEG4){
+ if(state == 0x1B6){
+ key= !(pkt->data[i]&0xC0);
+ break;
+ }
+ }else
+ break;
+ state= (state<<8) + pkt->data[i];
+ }
+ if(!key)
+ e->flags &= ~AVINDEX_KEYFRAME;
+ }
if (e->flags & AVINDEX_KEYFRAME)
pkt->flags |= AV_PKT_FLAG_KEY;
}
@@ -1119,6 +1176,22 @@ resync:
ast->packet_size= 0;
}
+ if(!avi->non_interleaved && pkt->pos >= 0 && ast->seek_pos > pkt->pos){
+ av_free_packet(pkt);
+ goto resync;
+ }
+ ast->seek_pos= 0;
+
+ if(!avi->non_interleaved && st->nb_index_entries>1 && avi->index_loaded>1){
+ int64_t dts= av_rescale_q(pkt->dts, st->time_base, AV_TIME_BASE_Q);
+
+ if(avi->dts_max - dts > 2*AV_TIME_BASE){
+ avi->non_interleaved= 1;
+ av_log(s, AV_LOG_INFO, "Switching to NI mode, due to poor interleaving\n");
+ }else if(avi->dts_max < dts)
+ avi->dts_max = dts;
+ }
+
return size;
}
@@ -1176,7 +1249,7 @@ static int avi_read_idx1(AVFormatContext *s, int size)
av_dlog(s, "%d cum_len=%"PRId64"\n", len, ast->cum_len);
- if(pb->eof_reached)
+ if(url_feof(pb))
return -1;
if(last_pos == pos)
@@ -1232,7 +1305,7 @@ static int avi_load_index(AVFormatContext *s)
goto the_end; // maybe truncated file
av_dlog(s, "movi_end=0x%"PRIx64"\n", avi->movi_end);
for(;;) {
- if (pb->eof_reached)
+ if (url_feof(pb))
break;
tag = avio_rl32(pb);
size = avio_rl32(pb);
@@ -1245,6 +1318,7 @@ static int avi_load_index(AVFormatContext *s)
if (tag == MKTAG('i', 'd', 'x', '1') &&
avi_read_idx1(s, size) >= 0) {
+ avi->index_loaded=2;
ret = 0;
break;
}
@@ -1273,13 +1347,13 @@ static int avi_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp
AVIContext *avi = s->priv_data;
AVStream *st;
int i, index;
- int64_t pos;
+ int64_t pos, pos_min;
AVIStream *ast;
if (!avi->index_loaded) {
/* we only load the index on demand */
avi_load_index(s);
- avi->index_loaded = 1;
+ avi->index_loaded |= 1;
}
assert(stream_index>= 0);
@@ -1301,15 +1375,18 @@ static int avi_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp
/* the av_index_search_timestamp call above. */
assert(stream_index == 0);
+ if(avio_seek(s->pb, pos, SEEK_SET) < 0)
+ return -1;
+
/* Feed the DV video stream version of the timestamp to the */
/* DV demux so it can synthesize correct timestamps. */
dv_offset_reset(avi->dv_demux, timestamp);
- avio_seek(s->pb, pos, SEEK_SET);
avi->stream_index= -1;
return 0;
}
+ pos_min= pos;
for(i = 0; i < s->nb_streams; i++) {
AVStream *st2 = s->streams[i];
AVIStream *ast2 = st2->priv_data;
@@ -1330,25 +1407,35 @@ static int avi_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp
index = av_index_search_timestamp(
st2,
av_rescale_q(timestamp, st->time_base, st2->time_base) * FFMAX(ast2->sample_size, 1),
- flags | AVSEEK_FLAG_BACKWARD);
+ flags | AVSEEK_FLAG_BACKWARD | (st2->codec->codec_type != AVMEDIA_TYPE_VIDEO ? AVSEEK_FLAG_ANY : 0));
if(index<0)
index=0;
+ ast2->seek_pos= st2->index_entries[index].pos;
+ pos_min= FFMIN(pos_min,ast2->seek_pos);
+ }
+ for(i = 0; i < s->nb_streams; i++) {
+ AVStream *st2 = s->streams[i];
+ AVIStream *ast2 = st2->priv_data;
- if(!avi->non_interleaved){
- while(index>0 && st2->index_entries[index].pos > pos)
- index--;
- while(index+1 < st2->nb_index_entries && st2->index_entries[index].pos < pos)
- index++;
- }
+ if (ast2->sub_ctx || st2->nb_index_entries <= 0)
+ continue;
-// av_log(s, AV_LOG_DEBUG, "%"PRId64" %d %"PRId64"\n", timestamp, index, st2->index_entries[index].timestamp);
- /* extract the current frame number */
+ index = av_index_search_timestamp(
+ st2,
+ av_rescale_q(timestamp, st->time_base, st2->time_base) * FFMAX(ast2->sample_size, 1),
+ flags | AVSEEK_FLAG_BACKWARD | (st2->codec->codec_type != AVMEDIA_TYPE_VIDEO ? AVSEEK_FLAG_ANY : 0));
+ if(index<0)
+ index=0;
+ while(!avi->non_interleaved && index>0 && st2->index_entries[index-1].pos >= pos_min)
+ index--;
ast2->frame_offset = st2->index_entries[index].timestamp;
}
/* do the seek */
- avio_seek(s->pb, pos, SEEK_SET);
+ if (avio_seek(s->pb, pos_min, SEEK_SET) < 0)
+ return -1;
avi->stream_index= -1;
+ avi->dts_max= INT_MIN;
return 0;
}
@@ -1389,12 +1476,13 @@ static int avi_probe(AVProbeData *p)
}
AVInputFormat ff_avi_demuxer = {
- "avi",
- NULL_IF_CONFIG_SMALL("AVI format"),
- sizeof(AVIContext),
- avi_probe,
- avi_read_header,
- avi_read_packet,
- avi_read_close,
- avi_read_seek,
+ .name = "avi",
+ .long_name = NULL_IF_CONFIG_SMALL("AVI format"),
+ .priv_data_size = sizeof(AVIContext),
+ .read_probe = avi_probe,
+ .read_header = avi_read_header,
+ .read_packet = avi_read_packet,
+ .read_close = avi_read_close,
+ .read_seek = avi_read_seek,
+ .priv_class = &demuxer_class,
};
diff --git a/libavformat/avienc.c b/libavformat/avienc.c
index 343396cabe..b4dc65c243 100644
--- a/libavformat/avienc.c
+++ b/libavformat/avienc.c
@@ -2,20 +2,20 @@
* AVI muxer
* Copyright (c) 2000 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avformat.h"
@@ -519,16 +519,21 @@ static int avi_write_packet(AVFormatContext *s, AVPacket *pkt)
AVCodecContext *enc= s->streams[stream_index]->codec;
int size= pkt->size;
-// av_log(s, AV_LOG_DEBUG, "%"PRId64" %d %d\n", pkt->dts, avi->packet_count[stream_index], stream_index);
+// av_log(s, AV_LOG_DEBUG, "%"PRId64" %d %d\n", pkt->dts, avist->packet_count, stream_index);
while(enc->block_align==0 && pkt->dts != AV_NOPTS_VALUE && pkt->dts > avist->packet_count){
AVPacket empty_packet;
+ if(pkt->dts - avist->packet_count > 60000){
+ av_log(s, AV_LOG_ERROR, "Too large number of skiped frames %Ld\n", pkt->dts - avist->packet_count);
+ return AVERROR(EINVAL);
+ }
+
av_init_packet(&empty_packet);
empty_packet.size= 0;
empty_packet.data= NULL;
empty_packet.stream_index= stream_index;
avi_write_packet(s, &empty_packet);
-// av_log(s, AV_LOG_DEBUG, "dup %"PRId64" %d\n", pkt->dts, avi->packet_count[stream_index]);
+// av_log(s, AV_LOG_DEBUG, "dup %"PRId64" %d\n", pkt->dts, avist->packet_count);
}
avist->packet_count++;
@@ -558,7 +563,7 @@ static int avi_write_packet(AVFormatContext *s, AVPacket *pkt)
int cl = idx->entry / AVI_INDEX_CLUSTER_SIZE;
int id = idx->entry % AVI_INDEX_CLUSTER_SIZE;
if (idx->ents_allocated <= idx->entry) {
- idx->cluster = av_realloc(idx->cluster, (cl+1)*sizeof(void*));
+ idx->cluster = av_realloc_f(idx->cluster, sizeof(void*), cl+1);
if (!idx->cluster)
return -1;
idx->cluster[cl] = av_malloc(AVI_INDEX_CLUSTER_SIZE*sizeof(AVIIentry));
@@ -639,16 +644,20 @@ static int avi_write_trailer(AVFormatContext *s)
}
AVOutputFormat ff_avi_muxer = {
- "avi",
- NULL_IF_CONFIG_SMALL("AVI format"),
- "video/x-msvideo",
- "avi",
- sizeof(AVIContext),
- CODEC_ID_MP2,
- CODEC_ID_MPEG4,
- avi_write_header,
- avi_write_packet,
- avi_write_trailer,
+ .name = "avi",
+ .long_name = NULL_IF_CONFIG_SMALL("AVI format"),
+ .mime_type = "video/x-msvideo",
+ .extensions = "avi",
+ .priv_data_size = sizeof(AVIContext),
+#if CONFIG_LIBMP3LAME_ENCODER
+ .audio_codec = CODEC_ID_MP3,
+#else
+ .audio_codec = CODEC_ID_AC3,
+#endif
+ .video_codec = CODEC_ID_MPEG4,
+ .write_header = avi_write_header,
+ .write_packet = avi_write_packet,
+ .write_trailer = avi_write_trailer,
.codec_tag= (const AVCodecTag* const []){ff_codec_bmp_tags, ff_codec_wav_tags, 0},
.flags= AVFMT_VARIABLE_FPS,
};
diff --git a/libavformat/avio.c b/libavformat/avio.c
index ac15407fda..b2926c0f3c 100644
--- a/libavformat/avio.c
+++ b/libavformat/avio.c
@@ -2,20 +2,20 @@
* Unbuffered io for ffmpeg system
* Copyright (c) 2001 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -52,21 +52,19 @@ static int default_interrupt_cb(void);
URLProtocol *first_protocol = NULL;
int (*url_interrupt_cb)(void) = default_interrupt_cb;
-#if FF_API_OLD_AVIO
URLProtocol *av_protocol_next(URLProtocol *p)
{
if(p) return p->next;
else return first_protocol;
}
-#endif
const char *avio_enum_protocols(void **opaque, int output)
{
- URLProtocol **p = opaque;
- *p = *p ? (*p)->next : first_protocol;
- if (!*p) return NULL;
- if ((output && (*p)->url_write) || (!output && (*p)->url_read))
- return (*p)->name;
+ URLProtocol *p = *opaque;
+ p = p ? p->next : first_protocol;
+ if (!p) return NULL;
+ if ((output && p->url_write) || (!output && p->url_read))
+ return p->name;
return avio_enum_protocols(opaque, output);
}
@@ -284,7 +282,7 @@ static inline int retry_transfer_wrapper(URLContext *h, unsigned char *buf, int
if (ret)
fast_retries = FFMAX(fast_retries, 2);
len += ret;
- if (url_interrupt_cb())
+ if (len < size && url_interrupt_cb())
return AVERROR_EXIT;
}
return len;
@@ -312,7 +310,7 @@ int ffurl_write(URLContext *h, const unsigned char *buf, int size)
if (h->max_packet_size && size > h->max_packet_size)
return AVERROR(EIO);
- return retry_transfer_wrapper(h, buf, size, size, h->prot->url_write);
+ return retry_transfer_wrapper(h, buf, size, size, (void*)h->prot->url_write);
}
int64_t ffurl_seek(URLContext *h, int64_t pos, int whence)
diff --git a/libavformat/avio.h b/libavformat/avio.h
index be14e3c89d..8210cbd1da 100644
--- a/libavformat/avio.h
+++ b/libavformat/avio.h
@@ -1,20 +1,20 @@
/*
* copyright (c) 2001 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVFORMAT_AVIO_H
@@ -197,12 +197,13 @@ attribute_deprecated int av_url_read_pause(URLContext *h, int pause);
attribute_deprecated int64_t av_url_read_seek(URLContext *h, int stream_index,
int64_t timestamp, int flags);
attribute_deprecated void url_set_interrupt_cb(int (*interrupt_cb)(void));
+
/**
- * If protocol is NULL, returns the first registered protocol,
- * if protocol is non-NULL, returns the next registered protocol after protocol,
- * or NULL if protocol is the last one.
+ * returns the next registered protocol after the given protocol (the first if
+ * NULL is given), or NULL if protocol is the last one.
*/
-attribute_deprecated URLProtocol *av_protocol_next(URLProtocol *p);
+URLProtocol *av_protocol_next(URLProtocol *p);
+
/**
* Register the URLProtocol protocol.
*
@@ -294,10 +295,6 @@ attribute_deprecated int url_fdopen(AVIOContext **s, URLContext *h);
* @}
*/
-/**
- * @deprecated use AVIOContext.eof_reached
- */
-attribute_deprecated int url_feof(AVIOContext *s);
attribute_deprecated int url_ferror(AVIOContext *s);
attribute_deprecated int udp_set_remote_url(URLContext *h, const char *uri);
@@ -438,10 +435,7 @@ int64_t avio_seek(AVIOContext *s, int64_t offset, int whence);
* Skip given number of bytes forward
* @return new position or AVERROR.
*/
-static av_always_inline int64_t avio_skip(AVIOContext *s, int64_t offset)
-{
- return avio_seek(s, offset, SEEK_CUR);
-}
+int64_t avio_skip(AVIOContext *s, int64_t offset);
/**
* ftell() equivalent for AVIOContext.
@@ -458,6 +452,12 @@ static av_always_inline int64_t avio_tell(AVIOContext *s)
*/
int64_t avio_size(AVIOContext *s);
+/**
+ * feof() equivalent for AVIOContext.
+ * @return non zero if and only if end of file
+ */
+int url_feof(AVIOContext *s);
+
/** @warning currently size is limited */
int avio_printf(AVIOContext *s, const char *fmt, ...) av_printf_format(2, 3);
@@ -585,6 +585,7 @@ int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer);
/**
* Iterate through names of available protocols.
+ * @note it is recommanded to use av_protocol_next() instead of this
*
* @param opaque A private pointer representing current protocol.
* It must be a pointer to NULL on first iteration and will
diff --git a/libavformat/avio_internal.h b/libavformat/avio_internal.h
index 1369c43891..4c80163d31 100644
--- a/libavformat/avio_internal.h
+++ b/libavformat/avio_internal.h
@@ -1,19 +1,19 @@
/*
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index fa63ddf2b9..9fc555ee53 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -2,20 +2,20 @@
* Buffered I/O for ffmpeg system
* Copyright (c) 2000,2001 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -237,6 +237,11 @@ int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
return offset;
}
+int64_t avio_skip(AVIOContext *s, int64_t offset)
+{
+ return avio_seek(s, offset, SEEK_CUR);
+}
+
#if FF_API_OLD_AVIO
int url_fskip(AVIOContext *s, int64_t offset)
{
@@ -269,14 +274,18 @@ int64_t avio_size(AVIOContext *s)
return size;
}
-#if FF_API_OLD_AVIO
int url_feof(AVIOContext *s)
{
if(!s)
return 0;
+ if(s->eof_reached){
+ s->eof_reached=0;
+ fill_buffer(s);
+ }
return s->eof_reached;
}
+#if FF_API_OLD_AVIO
int url_ferror(AVIOContext *s)
{
if(!s)
@@ -548,7 +557,7 @@ static void fill_buffer(AVIOContext *s)
}
/* make buffer smaller in case it ended up large after probing */
- if (s->buffer_size > max_buffer_size) {
+ if (s->read_packet && s->buffer_size > max_buffer_size) {
ffio_set_buf_size(s, max_buffer_size);
s->checksum_ptr = dst = s->buffer;
@@ -658,8 +667,8 @@ int avio_read(AVIOContext *s, unsigned char *buf, int size)
}
}
if (size1 == size) {
- if (s->error) return s->error;
- if (s->eof_reached) return AVERROR_EOF;
+ if (s->error) return s->error;
+ if (url_feof(s)) return AVERROR_EOF;
}
return size1 - size;
}
@@ -681,8 +690,8 @@ int ffio_read_partial(AVIOContext *s, unsigned char *buf, int size)
memcpy(buf, s->buf_ptr, len);
s->buf_ptr += len;
if (!len) {
- if (s->error) return s->error;
- if (s->eof_reached) return AVERROR_EOF;
+ if (s->error) return s->error;
+ if (url_feof(s)) return AVERROR_EOF;
}
return len;
}
@@ -769,13 +778,14 @@ int avio_get_str(AVIOContext *s, int maxlen, char *buf, int buflen)
{
int i;
+ if (buflen <= 0)
+ return AVERROR(EINVAL);
// reserve 1 byte for terminating 0
buflen = FFMIN(buflen - 1, maxlen);
for (i = 0; i < buflen; i++)
if (!(buf[i] = avio_r8(s)))
return i + 1;
- if (buflen)
- buf[i] = 0;
+ buf[i] = 0;
for (; i < maxlen; i++)
if (!avio_r8(s))
return i + 1;
@@ -787,6 +797,8 @@ int avio_get_str(AVIOContext *s, int maxlen, char *buf, int buflen)
{\
char* q = buf;\
int ret = 0;\
+ if (buflen <= 0) \
+ return AVERROR(EINVAL); \
while (ret + 1 < maxlen) {\
uint8_t tmp;\
uint32_t ch;\
@@ -838,19 +850,13 @@ int ffio_fdopen(AVIOContext **s, URLContext *h)
if (!buffer)
return AVERROR(ENOMEM);
- *s = av_mallocz(sizeof(AVIOContext));
- if(!*s) {
+ *s = avio_alloc_context(buffer, buffer_size, h->flags & AVIO_FLAG_WRITE, h,
+ ffurl_read, ffurl_write, ffurl_seek);
+ if (!*s) {
av_free(buffer);
return AVERROR(ENOMEM);
}
- if (ffio_init_context(*s, buffer, buffer_size,
- h->flags & AVIO_FLAG_WRITE, h,
- ffurl_read, ffurl_write, ffurl_seek) < 0) {
- av_free(buffer);
- av_freep(s);
- return AVERROR(EIO);
- }
#if FF_API_OLD_AVIO
(*s)->is_streamed = h->is_streamed;
#endif
@@ -912,7 +918,7 @@ int ffio_rewind_with_probe_data(AVIOContext *s, unsigned char *buf, int buf_size
alloc_size = FFMAX(s->buffer_size, new_size);
if (alloc_size > buf_size)
- if (!(buf = av_realloc(buf, alloc_size)))
+ if (!(buf = av_realloc_f(buf, 1, alloc_size)))
return AVERROR(ENOMEM);
if (new_size > buf_size) {
@@ -983,11 +989,11 @@ char *url_fgets(AVIOContext *s, char *buf, int buf_size)
char *q;
c = avio_r8(s);
- if (s->eof_reached)
+ if (url_feof(s))
return NULL;
q = buf;
for(;;) {
- if (s->eof_reached || c == '\n')
+ if (url_feof(s) || c == '\n')
break;
if ((q - buf) < buf_size - 1)
*q++ = c;
@@ -1081,7 +1087,7 @@ static int dyn_buf_write(void *opaque, uint8_t *buf, int buf_size)
}
if (new_allocated_size > d->allocated_size) {
- d->buffer = av_realloc(d->buffer, new_allocated_size);
+ d->buffer = av_realloc_f(d->buffer, 1, new_allocated_size);
if(d->buffer == NULL)
return AVERROR(ENOMEM);
d->allocated_size = new_allocated_size;
diff --git a/libavformat/avisynth.c b/libavformat/avisynth.c
index 5e6f6bf5b9..3e7dd46924 100644
--- a/libavformat/avisynth.c
+++ b/libavformat/avisynth.c
@@ -2,20 +2,20 @@
* AVISynth support for ffmpeg system
* Copyright (c) 2006 DivX, Inc.
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -84,7 +84,8 @@ static int avisynth_read_header(AVFormatContext *s, AVFormatParameters *ap)
if (AVIStreamReadFormat(stream->handle, 0, &wvfmt, &struct_size) != S_OK)
continue;
- st = av_new_stream(s, id);
+ st = avformat_new_stream(s, NULL);
+ st->id = id;
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
st->codec->block_align = wvfmt.nBlockAlign;
@@ -110,7 +111,8 @@ static int avisynth_read_header(AVFormatContext *s, AVFormatParameters *ap)
if (AVIStreamReadFormat(stream->handle, 0, &imgfmt, &struct_size) != S_OK)
continue;
- st = av_new_stream(s, id);
+ st = avformat_new_stream(s, NULL);
+ st->id = id;
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
st->r_frame_rate.num = stream->info.dwRate;
st->r_frame_rate.den = stream->info.dwScale;
@@ -122,6 +124,14 @@ static int avisynth_read_header(AVFormatContext *s, AVFormatParameters *ap)
st->codec->bit_rate = (uint64_t)stream->info.dwSampleSize * (uint64_t)stream->info.dwRate * 8 / (uint64_t)stream->info.dwScale;
st->codec->codec_tag = imgfmt.bmiHeader.biCompression;
st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, imgfmt.bmiHeader.biCompression);
+ if (st->codec->codec_id == CODEC_ID_RAWVIDEO && imgfmt.bmiHeader.biCompression== BI_RGB) {
+ st->codec->extradata = av_malloc(9 + FF_INPUT_BUFFER_PADDING_SIZE);
+ if (st->codec->extradata) {
+ st->codec->extradata_size = 9;
+ memcpy(st->codec->extradata, "BottomUp", 9);
+ }
+ }
+
st->duration = stream->info.dwLength;
}
@@ -165,7 +175,6 @@ static int avisynth_read_packet(AVFormatContext *s, AVPacket *pkt)
res = AVIStreamRead(stream->handle, stream->read, stream->chunck_samples, pkt->data, stream->chunck_size, &read_size, NULL);
- pkt->pts = stream->read;
pkt->size = read_size;
stream->read += stream->chunck_samples;
@@ -208,15 +217,12 @@ static int avisynth_read_seek(AVFormatContext *s, int stream_index, int64_t pts,
}
AVInputFormat ff_avisynth_demuxer = {
- "avs",
- NULL_IF_CONFIG_SMALL("AVISynth"),
- sizeof(AVISynthContext),
- NULL,
- avisynth_read_header,
- avisynth_read_packet,
- avisynth_read_close,
- avisynth_read_seek,
- NULL,
- 0,
- "avs",
+ .name = "avs",
+ .long_name = NULL_IF_CONFIG_SMALL("AVISynth"),
+ .priv_data_size = sizeof(AVISynthContext),
+ .read_header = avisynth_read_header,
+ .read_packet = avisynth_read_packet,
+ .read_close = avisynth_read_close,
+ .read_seek = avisynth_read_seek,
+ .extensions = "avs",
};
diff --git a/libavformat/avlanguage.c b/libavformat/avlanguage.c
index 787382ef13..39f2560d94 100644
--- a/libavformat/avlanguage.c
+++ b/libavformat/avlanguage.c
@@ -1,25 +1,26 @@
/*
* Cyril Comparon, Larbi Joubala, Resonate-MP4 2009
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avlanguage.h"
#include "libavutil/avstring.h"
+#include "libavutil/common.h"
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
@@ -736,7 +737,7 @@ const char *av_convert_lang_to(const char *lang, enum AVLangCodespace target_cod
{
int i;
const LangEntry *entry = NULL;
- const int NB_CODESPACES = sizeof(lang_table_counts)/sizeof(*lang_table_counts);
+ const int NB_CODESPACES = FF_ARRAY_ELEMS(lang_table_counts);
if (target_codespace >= NB_CODESPACES)
return NULL;
diff --git a/libavformat/avlanguage.h b/libavformat/avlanguage.h
index 2ec3e2d372..7fb8968810 100644
--- a/libavformat/avlanguage.h
+++ b/libavformat/avlanguage.h
@@ -1,20 +1,20 @@
/*
* Cyril Comparon, Larbi Joubala, Resonate-MP4 2009
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/avs.c b/libavformat/avs.c
index bd9b31d0f4..492cb0b0c6 100644
--- a/libavformat/avs.c
+++ b/libavformat/avs.c
@@ -2,20 +2,20 @@
* AVS demuxer.
* Copyright (c) 2006 Aurelien Jacobs <aurel@gnuage.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -163,10 +163,14 @@ static int avs_read_packet(AVFormatContext * s, AVPacket * pkt)
sub_type = avio_r8(s->pb);
type = avio_r8(s->pb);
size = avio_rl16(s->pb);
+ if (size < 4)
+ return AVERROR_INVALIDDATA;
avs->remaining_frame_size -= size;
switch (type) {
case AVS_PALETTE:
+ if (size - 4 > sizeof(palette))
+ return AVERROR_INVALIDDATA;
ret = avio_read(s->pb, palette, size - 4);
if (ret < size - 4)
return AVERROR(EIO);
@@ -175,7 +179,7 @@ static int avs_read_packet(AVFormatContext * s, AVPacket * pkt)
case AVS_VIDEO:
if (!avs->st_video) {
- avs->st_video = av_new_stream(s, AVS_VIDEO);
+ avs->st_video = avformat_new_stream(s, NULL);
if (avs->st_video == NULL)
return AVERROR(ENOMEM);
avs->st_video->codec->codec_type = AVMEDIA_TYPE_VIDEO;
@@ -192,7 +196,7 @@ static int avs_read_packet(AVFormatContext * s, AVPacket * pkt)
case AVS_AUDIO:
if (!avs->st_audio) {
- avs->st_audio = av_new_stream(s, AVS_AUDIO);
+ avs->st_audio = avformat_new_stream(s, NULL);
if (avs->st_audio == NULL)
return AVERROR(ENOMEM);
avs->st_audio->codec->codec_type = AVMEDIA_TYPE_AUDIO;
@@ -216,11 +220,11 @@ static int avs_read_close(AVFormatContext * s)
}
AVInputFormat ff_avs_demuxer = {
- "avs",
- NULL_IF_CONFIG_SMALL("AVS format"),
- sizeof(AvsFormat),
- avs_probe,
- avs_read_header,
- avs_read_packet,
- avs_read_close,
+ .name = "avs",
+ .long_name = NULL_IF_CONFIG_SMALL("AVS format"),
+ .priv_data_size = sizeof(AvsFormat),
+ .read_probe = avs_probe,
+ .read_header = avs_read_header,
+ .read_packet = avs_read_packet,
+ .read_close = avs_read_close,
};
diff --git a/libavformat/bethsoftvid.c b/libavformat/bethsoftvid.c
index 5e6a776824..384ac0144d 100644
--- a/libavformat/bethsoftvid.c
+++ b/libavformat/bethsoftvid.c
@@ -2,20 +2,20 @@
* Bethsoft VID format Demuxer
* Copyright (c) 2007 Nicholas Tung
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -23,8 +23,8 @@
* @file
* @brief Bethesda Softworks VID (.vid) file demuxer
* @author Nicholas Tung [ntung (at. ntung com] (2007-03)
- * @sa http://wiki.multimedia.cx/index.php?title=Bethsoft_VID
- * @sa http://www.svatopluk.com/andux/docs/dfvid.html
+ * @see http://wiki.multimedia.cx/index.php?title=Bethsoft_VID
+ * @see http://www.svatopluk.com/andux/docs/dfvid.html
*/
#include "libavutil/intreadwrite.h"
@@ -70,7 +70,7 @@ static int vid_read_header(AVFormatContext *s,
avio_skip(pb, 5);
vid->nframes = avio_rl16(pb);
- stream = av_new_stream(s, 0);
+ stream = avformat_new_stream(s, NULL);
if (!stream)
return AVERROR(ENOMEM);
av_set_pts_info(stream, 32, 1, 60); // 16 ms increments, i.e. 60 fps
@@ -83,7 +83,7 @@ static int vid_read_header(AVFormatContext *s,
avio_rl16(pb);
// done with video codec, set up audio codec
- stream = av_new_stream(s, 0);
+ stream = avformat_new_stream(s, NULL);
if (!stream)
return AVERROR(ENOMEM);
stream->codec->codec_type = AVMEDIA_TYPE_AUDIO;
@@ -179,7 +179,7 @@ static int vid_read_packet(AVFormatContext *s,
int audio_length;
int ret_value;
- if(vid->is_finished || pb->eof_reached)
+ if(vid->is_finished || url_feof(pb))
return AVERROR(EIO);
block_type = avio_r8(pb);
@@ -223,10 +223,10 @@ static int vid_read_packet(AVFormatContext *s,
}
AVInputFormat ff_bethsoftvid_demuxer = {
- "bethsoftvid",
- NULL_IF_CONFIG_SMALL("Bethesda Softworks VID format"),
- sizeof(BVID_DemuxContext),
- vid_probe,
- vid_read_header,
- vid_read_packet,
+ .name = "bethsoftvid",
+ .long_name = NULL_IF_CONFIG_SMALL("Bethesda Softworks VID format"),
+ .priv_data_size = sizeof(BVID_DemuxContext),
+ .read_probe = vid_probe,
+ .read_header = vid_read_header,
+ .read_packet = vid_read_packet,
};
diff --git a/libavformat/bfi.c b/libavformat/bfi.c
index bc26d47c9e..c6371049c6 100644
--- a/libavformat/bfi.c
+++ b/libavformat/bfi.c
@@ -2,20 +2,20 @@
* Brute Force & Ignorance (BFI) demuxer
* Copyright (c) 2008 Sisir Koppaka
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -23,7 +23,7 @@
* @file
* @brief Brute Force & Ignorance (.bfi) file demuxer
* @author Sisir Koppaka ( sisir.koppaka at gmail dot com )
- * @sa http://wiki.multimedia.cx/index.php?title=BFI
+ * @see http://wiki.multimedia.cx/index.php?title=BFI
*/
#include "libavutil/intreadwrite.h"
@@ -55,12 +55,12 @@ static int bfi_read_header(AVFormatContext * s, AVFormatParameters * ap)
int fps, chunk_header;
/* Initialize the video codec... */
- vstream = av_new_stream(s, 0);
+ vstream = avformat_new_stream(s, NULL);
if (!vstream)
return AVERROR(ENOMEM);
/* Initialize the audio codec... */
- astream = av_new_stream(s, 0);
+ astream = avformat_new_stream(s, NULL);
if (!astream)
return AVERROR(ENOMEM);
@@ -109,7 +109,7 @@ static int bfi_read_packet(AVFormatContext * s, AVPacket * pkt)
BFIContext *bfi = s->priv_data;
AVIOContext *pb = s->pb;
int ret, audio_offset, video_offset, chunk_size, audio_size = 0;
- if (bfi->nframes == 0 || pb->eof_reached) {
+ if (bfi->nframes == 0 || url_feof(pb)) {
return AVERROR(EIO);
}
@@ -117,7 +117,7 @@ static int bfi_read_packet(AVFormatContext * s, AVPacket * pkt)
if (!bfi->avflag) {
uint32_t state = 0;
while(state != MKTAG('S','A','V','I')){
- if (pb->eof_reached)
+ if (url_feof(pb))
return AVERROR(EIO);
state = 256*state + avio_r8(pb);
}
@@ -159,10 +159,10 @@ static int bfi_read_packet(AVFormatContext * s, AVPacket * pkt)
}
AVInputFormat ff_bfi_demuxer = {
- "bfi",
- NULL_IF_CONFIG_SMALL("Brute Force & Ignorance"),
- sizeof(BFIContext),
- bfi_probe,
- bfi_read_header,
- bfi_read_packet,
+ .name = "bfi",
+ .long_name = NULL_IF_CONFIG_SMALL("Brute Force & Ignorance"),
+ .priv_data_size = sizeof(BFIContext),
+ .read_probe = bfi_probe,
+ .read_header = bfi_read_header,
+ .read_packet = bfi_read_packet,
};
diff --git a/libavformat/bink.c b/libavformat/bink.c
index 76b457c21b..844498e6f8 100644
--- a/libavformat/bink.c
+++ b/libavformat/bink.c
@@ -3,20 +3,20 @@
* Copyright (c) 2008-2010 Peter Ross (pross@xvid.org)
* Copyright (c) 2009 Daniel Verkamp (daniel@drv.nu)
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -78,7 +78,7 @@ static int read_header(AVFormatContext *s, AVFormatParameters *ap)
uint16_t flags;
int keyframe;
- vst = av_new_stream(s, 0);
+ vst = avformat_new_stream(s, NULL);
if (!vst)
return AVERROR(ENOMEM);
@@ -130,17 +130,22 @@ static int read_header(AVFormatContext *s, AVFormatParameters *ap)
avio_skip(pb, 4 * bink->num_audio_tracks);
for (i = 0; i < bink->num_audio_tracks; i++) {
- ast = av_new_stream(s, 1);
+ ast = avformat_new_stream(s, NULL);
if (!ast)
return AVERROR(ENOMEM);
ast->codec->codec_type = AVMEDIA_TYPE_AUDIO;
- ast->codec->codec_tag = vst->codec->codec_tag;
+ ast->codec->codec_tag = 0;
ast->codec->sample_rate = avio_rl16(pb);
av_set_pts_info(ast, 64, 1, ast->codec->sample_rate);
flags = avio_rl16(pb);
ast->codec->codec_id = flags & BINK_AUD_USEDCT ?
CODEC_ID_BINKAUDIO_DCT : CODEC_ID_BINKAUDIO_RDFT;
ast->codec->channels = flags & BINK_AUD_STEREO ? 2 : 1;
+ ast->codec->extradata = av_mallocz(4 + FF_INPUT_BUFFER_PADDING_SIZE);
+ if (!ast->codec->extradata)
+ return AVERROR(ENOMEM);
+ ast->codec->extradata_size = 4;
+ AV_WL32(ast->codec->extradata, vst->codec->codec_tag);
}
for (i = 0; i < bink->num_audio_tracks; i++)
@@ -251,7 +256,9 @@ static int read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, in
return -1;
/* seek to the first frame */
- avio_seek(s->pb, vst->index_entries[0].pos, SEEK_SET);
+ if (avio_seek(s->pb, vst->index_entries[0].pos, SEEK_SET) < 0)
+ return -1;
+
bink->video_pts = 0;
memset(bink->audio_pts, 0, sizeof(bink->audio_pts));
bink->current_track = -1;
@@ -259,12 +266,11 @@ static int read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, in
}
AVInputFormat ff_bink_demuxer = {
- "bink",
- NULL_IF_CONFIG_SMALL("Bink"),
- sizeof(BinkDemuxContext),
- probe,
- read_header,
- read_packet,
- NULL,
- read_seek,
+ .name = "bink",
+ .long_name = NULL_IF_CONFIG_SMALL("Bink"),
+ .priv_data_size = sizeof(BinkDemuxContext),
+ .read_probe = probe,
+ .read_header = read_header,
+ .read_packet = read_packet,
+ .read_seek = read_seek,
};
diff --git a/libavformat/bintext.c b/libavformat/bintext.c
new file mode 100644
index 0000000000..e03a31e447
--- /dev/null
+++ b/libavformat/bintext.c
@@ -0,0 +1,375 @@
+/*
+ * Binary text demuxer
+ * eXtended BINary text (XBIN) demuxer
+ * Artworx Data Format demuxer
+ * iCEDraw File demuxer
+ * Copyright (c) 2010 Peter Ross <pross@xvid.org>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * Binary text demuxer
+ * eXtended BINary text (XBIN) demuxer
+ * Artworx Data Format demuxer
+ * iCEDraw File demuxer
+ */
+
+#include "libavutil/intreadwrite.h"
+#include "avformat.h"
+#include "sauce.h"
+#include "libavcodec/bintext.h"
+
+#define LINE_RATE 6000 /** characters per second */
+
+typedef struct {
+ int chars_per_frame;
+ uint64_t fsize; /**< file size less metadata buffer */
+} BinDemuxContext;
+
+#if CONFIG_BINTEXT_DEMUXER | CONFIG_ADF_DEMUXER | CONFIG_IDF_DEMUXER
+/**
+ * Given filesize and width, calculate height (assume font_height of 16)
+ */
+static void calculate_height(AVCodecContext *avctx, uint64_t fsize)
+{
+ avctx->height = (fsize / ((avctx->width>>3)*2)) << 4;
+}
+#endif
+
+#if CONFIG_BINTEXT_DEMUXER
+static const uint8_t next_magic[]={
+ 0x1A, 0x1B, '[', '0', ';', '3', '0', ';', '4', '0', 'm', 'N', 'E', 'X', 'T', 0x00
+};
+
+static int next_tag_read(AVFormatContext *avctx, uint64_t *fsize)
+{
+ ByteIOContext *pb = avctx->pb;
+ char buf[36];
+ int len;
+ uint64_t start_pos = url_fsize(pb) - 256;
+
+ url_fseek(pb, start_pos, SEEK_SET);
+ if (get_buffer(pb, buf, sizeof(next_magic)) != sizeof(next_magic))
+ return -1;
+ if (memcmp(buf, next_magic, sizeof(next_magic)))
+ return -1;
+ if (get_byte(pb) != 0x01)
+ return -1;
+
+ *fsize -= 256;
+
+#define GET_EFI2_META(name,size) \
+ len = get_byte(pb); \
+ if (len < 1 || len > size) \
+ return -1; \
+ if (get_buffer(pb, buf, size) == size && *buf) { \
+ buf[len] = 0; \
+ av_metadata_set2(&avctx->metadata, name, buf, 0); \
+ }
+
+ GET_EFI2_META("filename", 12)
+ GET_EFI2_META("author", 20)
+ GET_EFI2_META("publisher", 20)
+ GET_EFI2_META("title", 35)
+
+ return 0;
+}
+
+static void predict_width(AVCodecContext *avctx, uint64_t fsize, int got_width)
+{
+ /** attempt to guess width */
+ if (!got_width)
+ avctx->width = fsize > 4000 ? (160<<3) : (80<<3);
+}
+
+static AVStream * init_stream(AVFormatContext *s,
+ AVFormatParameters *ap)
+{
+ BinDemuxContext *bin = s->priv_data;
+ AVStream *st = av_new_stream(s, 0);
+ if (!st)
+ return NULL;
+ st->codec->codec_tag = 0;
+ st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
+
+ if (!ap->time_base.num) {
+ av_set_pts_info(st, 60, 1, 25);
+ } else {
+ av_set_pts_info(st, 60, ap->time_base.num, ap->time_base.den);
+ }
+
+ /* simulate tty display speed */
+ bin->chars_per_frame = FFMAX(av_q2d(st->time_base) * (ap->sample_rate ? ap->sample_rate : LINE_RATE), 1);
+
+ st->codec->width = ap->width ? ap->width : (80<<3);
+ st->codec->height = ap->height ? ap->height : (25<<4);
+ return st;
+}
+
+static int bintext_read_header(AVFormatContext *s,
+ AVFormatParameters *ap)
+{
+ BinDemuxContext *bin = s->priv_data;
+ ByteIOContext *pb = s->pb;
+
+ AVStream *st = init_stream(s, ap);
+ if (!st)
+ return AVERROR(ENOMEM);
+ st->codec->codec_id = CODEC_ID_BINTEXT;
+
+ st->codec->extradata_size = 2;
+ st->codec->extradata = av_malloc(st->codec->extradata_size);
+ if (!st->codec->extradata)
+ return AVERROR(ENOMEM);
+ st->codec->extradata[0] = 16;
+ st->codec->extradata[1] = 0;
+
+ if (!url_is_streamed(pb)) {
+ int got_width = 0;
+ bin->fsize = url_fsize(pb);
+ if (ff_sauce_read(s, &bin->fsize, &got_width, 0) < 0)
+ next_tag_read(s, &bin->fsize);
+ if (!ap->width)
+ predict_width(st->codec, bin->fsize, got_width);
+ if (!ap->height)
+ calculate_height(st->codec, bin->fsize);
+ url_fseek(pb, 0, SEEK_SET);
+ }
+ return 0;
+};
+#endif /* CONFIG_BINTEXT_DEMUXER */
+
+#if CONFIG_XBIN_DEMUXER
+static int xbin_probe(AVProbeData *p)
+{
+ const uint8_t *d = p->buf;
+
+ if (AV_RL32(d) == MKTAG('X','B','I','N') && d[4] == 0x1A &&
+ AV_RL16(d+5) > 0 && AV_RL16(d+5) <= 160 &&
+ d[9] > 0 && d[9] <= 32)
+ return AVPROBE_SCORE_MAX;
+ return 0;
+}
+
+static int xbin_read_header(AVFormatContext *s,
+ AVFormatParameters *ap)
+{
+ BinDemuxContext *bin = s->priv_data;
+ ByteIOContext *pb = s->pb;
+ char fontheight, flags;
+
+ AVStream *st = init_stream(s, ap);
+ if (!st)
+ return AVERROR(ENOMEM);
+
+ url_fskip(pb, 5);
+ st->codec->width = get_le16(pb)<<3;
+ st->codec->height = get_le16(pb);
+ fontheight = get_byte(pb);
+ st->codec->height *= fontheight;
+ flags = get_byte(pb);
+
+ st->codec->extradata_size = 2;
+ if ((flags & BINTEXT_PALETTE))
+ st->codec->extradata_size += 48;
+ if ((flags & BINTEXT_FONT))
+ st->codec->extradata_size += fontheight * (flags & 0x10 ? 512 : 256);
+ st->codec->codec_id = flags & 4 ? CODEC_ID_XBIN : CODEC_ID_BINTEXT;
+
+ st->codec->extradata = av_malloc(st->codec->extradata_size);
+ if (!st->codec->extradata)
+ return AVERROR(ENOMEM);
+ st->codec->extradata[0] = fontheight;
+ st->codec->extradata[1] = flags;
+ if (get_buffer(pb, st->codec->extradata + 2, st->codec->extradata_size - 2) < 0)
+ return AVERROR(EIO);
+
+ if (!url_is_streamed(pb)) {
+ bin->fsize = url_fsize(pb) - 9 - st->codec->extradata_size;
+ ff_sauce_read(s, &bin->fsize, NULL, 0);
+ url_fseek(pb, 9 + st->codec->extradata_size, SEEK_SET);
+ }
+
+ return 0;
+}
+#endif /* CONFIG_XBIN_DEMUXER */
+
+#if CONFIG_ADF_DEMUXER
+static int adf_read_header(AVFormatContext *s,
+ AVFormatParameters *ap)
+{
+ BinDemuxContext *bin = s->priv_data;
+ ByteIOContext *pb = s->pb;
+ AVStream *st;
+
+ if (get_byte(pb) != 1)
+ return AVERROR_INVALIDDATA;
+
+ st = init_stream(s, ap);
+ if (!st)
+ return AVERROR(ENOMEM);
+ st->codec->codec_id = CODEC_ID_BINTEXT;
+
+ st->codec->extradata_size = 2 + 48 + 4096;
+ st->codec->extradata = av_malloc(st->codec->extradata_size);
+ if (!st->codec->extradata)
+ return AVERROR(ENOMEM);
+ st->codec->extradata[0] = 16;
+ st->codec->extradata[1] = BINTEXT_PALETTE|BINTEXT_FONT;
+
+ if (get_buffer(pb, st->codec->extradata + 2, 24) < 0)
+ return AVERROR(EIO);
+ url_fskip(pb, 144);
+ if (get_buffer(pb, st->codec->extradata + 2 + 24, 24) < 0)
+ return AVERROR(EIO);
+ if (get_buffer(pb, st->codec->extradata + 2 + 48, 4096) < 0)
+ return AVERROR(EIO);
+
+ if (!url_is_streamed(pb)) {
+ int got_width = 0;
+ bin->fsize = url_fsize(pb) - 1 - 192 - 4096;
+ st->codec->width = 80<<3;
+ ff_sauce_read(s, &bin->fsize, &got_width, 0);
+ if (!ap->height)
+ calculate_height(st->codec, bin->fsize);
+ url_fseek(pb, 1 + 192 + 4096, SEEK_SET);
+ }
+ return 0;
+}
+#endif /* CONFIG_ADF_DEMUXER */
+
+#if CONFIG_IDF_DEMUXER
+static const uint8_t idf_magic[] = {
+ 0x04, 0x31, 0x2e, 0x34, 0x00, 0x00, 0x00, 0x00, 0x4f, 0x00, 0x15, 0x00
+};
+
+static int idf_probe(AVProbeData *p)
+{
+ if (p->buf_size < sizeof(idf_magic))
+ return 0;
+ if (!memcmp(p->buf, idf_magic, sizeof(idf_magic)))
+ return AVPROBE_SCORE_MAX;
+ return 0;
+}
+
+static int idf_read_header(AVFormatContext *s,
+ AVFormatParameters *ap)
+{
+ BinDemuxContext *bin = s->priv_data;
+ ByteIOContext *pb = s->pb;
+ AVStream *st;
+ int got_width = 0;
+
+ if (url_is_streamed(pb))
+ return AVERROR(EIO);
+
+ st = init_stream(s, ap);
+ if (!st)
+ return AVERROR(ENOMEM);
+ st->codec->codec_id = CODEC_ID_IDF;
+
+ st->codec->extradata_size = 2 + 48 + 4096;
+ st->codec->extradata = av_malloc(st->codec->extradata_size);
+ if (!st->codec->extradata)
+ return AVERROR(ENOMEM);
+ st->codec->extradata[0] = 16;
+ st->codec->extradata[1] = BINTEXT_PALETTE|BINTEXT_FONT;
+
+ url_fseek(pb, url_fsize(pb) - 4096 - 48, SEEK_SET);
+
+ if (get_buffer(pb, st->codec->extradata + 2 + 48, 4096) < 0)
+ return AVERROR(EIO);
+ if (get_buffer(pb, st->codec->extradata + 2, 48) < 0)
+ return AVERROR(EIO);
+
+ bin->fsize = url_fsize(pb) - 12 - 4096 - 48;
+ ff_sauce_read(s, &bin->fsize, &got_width, 0);
+ if (!ap->height)
+ calculate_height(st->codec, bin->fsize);
+ url_fseek(pb, 12, SEEK_SET);
+ return 0;
+}
+#endif /* CONFIG_IDF_DEMUXER */
+
+static int read_packet(AVFormatContext *s,
+ AVPacket *pkt)
+{
+ BinDemuxContext *bin = s->priv_data;
+
+ if (bin->fsize > 0) {
+ if (av_get_packet(s->pb, pkt, bin->fsize) < 0)
+ return AVERROR(EIO);
+ bin->fsize = -1; /* done */
+ } else if (!bin->fsize) {
+ if (url_feof(s->pb))
+ return AVERROR(EIO);
+ if (av_get_packet(s->pb, pkt, bin->chars_per_frame) < 0)
+ return AVERROR(EIO);
+ } else {
+ return AVERROR(EIO);
+ }
+
+ pkt->flags |= AV_PKT_FLAG_KEY;
+ return 0;
+}
+
+#if CONFIG_BINTEXT_DEMUXER
+AVInputFormat ff_bintext_demuxer = {
+ .name = "bin",
+ .long_name = NULL_IF_CONFIG_SMALL("Binary text"),
+ .priv_data_size = sizeof(BinDemuxContext),
+ .read_header = bintext_read_header,
+ .read_packet = read_packet,
+ .extensions = "bin",
+};
+#endif
+
+#if CONFIG_XBIN_DEMUXER
+AVInputFormat ff_xbin_demuxer = {
+ .name = "xbin",
+ .long_name = NULL_IF_CONFIG_SMALL("eXtended BINary text (XBIN)"),
+ .priv_data_size = sizeof(BinDemuxContext),
+ .read_probe = xbin_probe,
+ .read_header = xbin_read_header,
+ .read_packet = read_packet,
+};
+#endif
+
+#if CONFIG_ADF_DEMUXER
+AVInputFormat ff_adf_demuxer = {
+ .name = "adf",
+ .long_name = NULL_IF_CONFIG_SMALL("Artworx Data Format"),
+ .priv_data_size = sizeof(BinDemuxContext),
+ .read_header = adf_read_header,
+ .read_packet = read_packet,
+ .extensions = "adf",
+};
+#endif
+
+#if CONFIG_IDF_DEMUXER
+AVInputFormat ff_idf_demuxer = {
+ .name = "idf",
+ .long_name = NULL_IF_CONFIG_SMALL("iCE Draw File"),
+ .priv_data_size = sizeof(BinDemuxContext),
+ .read_probe = idf_probe,
+ .read_header = idf_read_header,
+ .read_packet = read_packet,
+ .extensions = "idf",
+};
+#endif
diff --git a/libavformat/bit.c b/libavformat/bit.c
new file mode 100644
index 0000000000..d72d2a8961
--- /dev/null
+++ b/libavformat/bit.c
@@ -0,0 +1,135 @@
+#include "avformat.h"
+#include "libavcodec/get_bits.h"
+#include "libavcodec/put_bits.h"
+
+#define MAX_FRAME_SIZE 10
+
+#define SYNC_WORD 0x6b21
+#define BIT_0 0x7f
+#define BIT_1 0x81
+
+static int probe(AVProbeData *p)
+{
+ int i, j;
+
+ if(p->buf_size < 0x40)
+ return 0;
+
+ for(i=0; i+3<p->buf_size && i< 10*0x50; ){
+ if(AV_RL16(&p->buf[0]) != SYNC_WORD)
+ return 0;
+ j=AV_RL16(&p->buf[2]);
+ if(j!=0x40 && j!=0x50)
+ return 0;
+ i+=j;
+ }
+ return AVPROBE_SCORE_MAX/2;
+}
+
+static int read_header(AVFormatContext *s, AVFormatParameters *ap)
+{
+ AVStream* st;
+
+ st=av_new_stream(s, 0);
+ if (!st)
+ return AVERROR(ENOMEM);
+
+ st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
+ st->codec->codec_id=CODEC_ID_G729;
+ st->codec->sample_rate=8000;
+ st->codec->block_align = 16;
+ st->codec->channels=1;
+
+ av_set_pts_info(st, 64, 1, 100);
+ return 0;
+}
+
+static int read_packet(AVFormatContext *s,
+ AVPacket *pkt)
+{
+ ByteIOContext *pb = s->pb;
+ PutBitContext pbo;
+ uint16_t buf[8 * MAX_FRAME_SIZE + 2];
+ int packet_size;
+ uint16_t* src=buf;
+ int i, j, ret;
+ int64_t pos= avio_tell(pb);
+
+ if(url_feof(pb))
+ return AVERROR_EOF;
+
+ get_le16(pb); // sync word
+ packet_size = get_le16(pb) / 8;
+ if(packet_size > MAX_FRAME_SIZE)
+ return AVERROR_INVALIDDATA;
+
+ ret = get_buffer(pb, (uint8_t*)buf, (8 * packet_size) * sizeof(uint16_t));
+ if(ret<0)
+ return ret;
+ if(ret != 8 * packet_size * sizeof(uint16_t))
+ return AVERROR(EIO);
+
+ av_new_packet(pkt, packet_size);
+
+ init_put_bits(&pbo, pkt->data, packet_size);
+ for(j=0; j < packet_size; j++)
+ for(i=0; i<8;i++)
+ put_bits(&pbo,1, AV_RL16(src++) == BIT_1 ? 1 : 0);
+
+ flush_put_bits(&pbo);
+
+ pkt->duration=1;
+ pkt->pos = pos;
+ return 0;
+}
+
+AVInputFormat ff_bit_demuxer = {
+ .name = "bit",
+ .long_name = NULL_IF_CONFIG_SMALL("G.729 BIT file format"),
+ .read_probe = probe,
+ .read_header = read_header,
+ .read_packet = read_packet,
+ .extensions = "bit",
+};
+
+#ifdef CONFIG_MUXERS
+static int write_header(AVFormatContext *s)
+{
+ AVCodecContext *enc = s->streams[0]->codec;
+
+ enc->codec_id = CODEC_ID_G729;
+ enc->channels = 1;
+ enc->bits_per_coded_sample = 16;
+ enc->block_align = (enc->bits_per_coded_sample * enc->channels) >> 3;
+
+ return 0;
+}
+
+static int write_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ ByteIOContext *pb = s->pb;
+ GetBitContext gb;
+ int i;
+
+ put_le16(pb, SYNC_WORD);
+ put_le16(pb, 8 * 10);
+
+ init_get_bits(&gb, pkt->data, 8*10);
+ for(i=0; i< 8 * 10; i++)
+ put_le16(pb, get_bits1(&gb) ? BIT_1 : BIT_0);
+ put_flush_packet(pb);
+
+ return 0;
+}
+
+AVOutputFormat ff_bit_muxer = {
+ .name = "bit",
+ .long_name = NULL_IF_CONFIG_SMALL("G.729 BIT file format"),
+ .mime_type = "audio/bit",
+ .extensions = "bit",
+ .audio_codec = CODEC_ID_G729,
+ .video_codec = CODEC_ID_NONE,
+ .write_header = write_header,
+ .write_packet = write_packet,
+};
+#endif
diff --git a/libavformat/c93.c b/libavformat/c93.c
index 097565a335..0f4be89545 100644
--- a/libavformat/c93.c
+++ b/libavformat/c93.c
@@ -2,20 +2,20 @@
* Interplay C93 demuxer
* Copyright (c) 2007 Anssi Hannula <anssi.hannula@gmail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -79,7 +79,7 @@ static int read_header(AVFormatContext *s,
/* Audio streams are added if audio packets are found */
s->ctx_flags |= AVFMTCTX_NOHEADER;
- video = av_new_stream(s, 0);
+ video = avformat_new_stream(s, NULL);
if (!video)
return AVERROR(ENOMEM);
@@ -117,7 +117,7 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt)
datasize = avio_rl16(pb);
if (datasize > 42) {
if (!c93->audio) {
- c93->audio = av_new_stream(s, 1);
+ c93->audio = avformat_new_stream(s, NULL);
if (!c93->audio)
return AVERROR(ENOMEM);
c93->audio->codec->codec_type = AVMEDIA_TYPE_AUDIO;
@@ -193,10 +193,10 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt)
}
AVInputFormat ff_c93_demuxer = {
- "c93",
- NULL_IF_CONFIG_SMALL("Interplay C93"),
- sizeof(C93DemuxContext),
- probe,
- read_header,
- read_packet,
+ .name = "c93",
+ .long_name = NULL_IF_CONFIG_SMALL("Interplay C93"),
+ .priv_data_size = sizeof(C93DemuxContext),
+ .read_probe = probe,
+ .read_header = read_header,
+ .read_packet = read_packet,
};
diff --git a/libavformat/cache.c b/libavformat/cache.c
new file mode 100644
index 0000000000..74f008e0d1
--- /dev/null
+++ b/libavformat/cache.c
@@ -0,0 +1,144 @@
+/*
+ * Input cache protocol.
+ * Copyright (c) 2011 Michael Niedermayer
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Based on file.c by Fabrice Bellard
+ */
+
+/**
+ * @TODO
+ * support non continuous caching
+ * support keeping files
+ * support filling with a background thread
+ */
+
+#include "libavutil/avassert.h"
+#include "libavutil/avstring.h"
+#include "libavutil/file.h"
+#include "avformat.h"
+#include <fcntl.h>
+#if HAVE_SETMODE
+#include <io.h>
+#endif
+#include <unistd.h>
+#include <sys/stat.h>
+#include <stdlib.h>
+#include "os_support.h"
+#include "url.h"
+
+typedef struct Context {
+ int fd;
+ int64_t end;
+ int64_t pos;
+ URLContext *inner;
+} Context;
+
+static int cache_open(URLContext *h, const char *arg, int flags)
+{
+ int access;
+ const char *buffername;
+ Context *c;
+
+ c = av_mallocz(sizeof(Context));
+ if (!c) {
+ return AVERROR(ENOMEM);
+ }
+ h->priv_data = c;
+
+ av_strstart(arg, "cache:", &arg);
+
+ c->fd = av_tempfile("ffcache", &buffername, 0, h);
+ if (c->fd < 0){
+ av_log(h, AV_LOG_ERROR, "Failed to create tempfile\n");
+ return c->fd;
+ }
+
+ unlink(buffername);
+ av_free(buffername);
+
+ return ffurl_open(&c->inner, arg, flags);
+}
+
+static int cache_read(URLContext *h, unsigned char *buf, int size)
+{
+ Context *c= h->priv_data;
+ int r;
+
+ if(c->pos<c->end){
+ r = read(c->fd, buf, FFMIN(size, c->end - c->pos));
+ if(r>0)
+ c->pos += r;
+ return (-1 == r)?AVERROR(errno):r;
+ }else{
+ r = ffurl_read(c->inner, buf, size);
+ if(r > 0){
+ int r2= write(c->fd, buf, r);
+ av_assert0(r2==r); // FIXME handle cache failure
+ c->pos += r;
+ c->end += r;
+ }
+ return r;
+ }
+}
+
+static int64_t cache_seek(URLContext *h, int64_t pos, int whence)
+{
+ Context *c= h->priv_data;
+
+ if (whence == AVSEEK_SIZE) {
+ pos= ffurl_seek(c->inner, pos, whence);
+ if(pos <= 0){
+ pos= ffurl_seek(c->inner, -1, SEEK_END);
+ ffurl_seek(c->inner, c->end, SEEK_SET);
+ if(pos <= 0)
+ return c->end;
+ }
+ return pos;
+ }
+
+ pos= lseek(c->fd, pos, whence);
+ if(pos<0){
+ return pos;
+ }else if(pos <= c->end){
+ c->pos= pos;
+ return pos;
+ }else{
+ lseek(c->fd, c->pos, SEEK_SET);
+ return AVERROR(EPIPE);
+ }
+}
+
+static int cache_close(URLContext *h)
+{
+ Context *c= h->priv_data;
+ close(c->fd);
+ ffurl_close(c->inner);
+
+ av_freep(&h->priv_data);
+
+ return 0;
+}
+
+URLProtocol ff_cache_protocol = {
+ .name = "cache",
+ .url_open = cache_open,
+ .url_read = cache_read,
+ .url_seek = cache_seek,
+ .url_close = cache_close,
+};
diff --git a/libavformat/caf.c b/libavformat/caf.c
index c204c90ad1..054533038f 100644
--- a/libavformat/caf.c
+++ b/libavformat/caf.c
@@ -2,20 +2,20 @@
* CAF common code
* Copyright (c) 2007 Justin Ruggles
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -32,27 +32,34 @@
* Known codec tags for CAF
*/
const AVCodecTag ff_codec_caf_tags[] = {
- { CODEC_ID_AAC, MKBETAG('a','a','c',' ') },
- { CODEC_ID_AC3, MKBETAG('a','c','-','3') },
- { CODEC_ID_ALAC, MKBETAG('a','l','a','c') },
+ { CODEC_ID_AAC, MKTAG('a','a','c',' ') },
+ { CODEC_ID_AC3, MKTAG('a','c','-','3') },
+ { CODEC_ID_ADPCM_IMA_QT, MKTAG('i','m','a','4') },
+ { CODEC_ID_ADPCM_IMA_WAV, MKTAG('m','s', 0, 17 ) },
+ { CODEC_ID_ADPCM_MS, MKTAG('m','s', 0, 2 ) },
+ { CODEC_ID_ALAC, MKTAG('a','l','a','c') },
+ { CODEC_ID_AMR_NB, MKTAG('s','a','m','r') },
/* FIXME: use DV demuxer, as done in MOV */
- /*{ CODEC_ID_DVAUDIO, MKBETAG('v','d','v','a') },*/
- /*{ CODEC_ID_DVAUDIO, MKBETAG('d','v','c','a') },*/
- { CODEC_ID_ADPCM_IMA_QT, MKBETAG('i','m','a','4') },
- { CODEC_ID_MACE3, MKBETAG('M','A','C','3') },
- { CODEC_ID_MACE6, MKBETAG('M','A','C','6') },
- { CODEC_ID_MP3, MKBETAG('.','m','p','3') },
- { CODEC_ID_MP2, MKBETAG('.','m','p','2') },
- { CODEC_ID_MP1, MKBETAG('.','m','p','1') },
- { CODEC_ID_PCM_ALAW, MKBETAG('a','l','a','w') },
- { CODEC_ID_PCM_MULAW, MKBETAG('u','l','a','w') },
- { CODEC_ID_QCELP, MKBETAG('Q','c','l','p') },
- { CODEC_ID_QDM2, MKBETAG('Q','D','M','2') },
- { CODEC_ID_QDM2, MKBETAG('Q','D','M','C') },
+ /*{ CODEC_ID_DVAUDIO, MKTAG('v','d','v','a') },*/
+ /*{ CODEC_ID_DVAUDIO, MKTAG('d','v','c','a') },*/
+ { CODEC_ID_GSM, MKTAG('a','g','s','m') },
+ { CODEC_ID_GSM_MS, MKTAG('m','s', 0, '1') },
+ { CODEC_ID_MACE3, MKTAG('M','A','C','3') },
+ { CODEC_ID_MACE6, MKTAG('M','A','C','6') },
+ { CODEC_ID_MP1, MKTAG('.','m','p','1') },
+ { CODEC_ID_MP2, MKTAG('.','m','p','2') },
+ { CODEC_ID_MP3, MKTAG('.','m','p','3') },
+ { CODEC_ID_MP3, MKTAG('m','s', 0 ,'U') },
+ { CODEC_ID_PCM_ALAW, MKTAG('a','l','a','w') },
+ { CODEC_ID_PCM_MULAW, MKTAG('u','l','a','w') },
+ { CODEC_ID_QCELP, MKTAG('Q','c','l','p') },
+ { CODEC_ID_QDM2, MKTAG('Q','D','M','2') },
+ { CODEC_ID_QDM2, MKTAG('Q','D','M','C') },
/* currently unsupported codecs */
- /*{ AC-3 over S/PDIF MKBETAG('c','a','c','3') },*/
- /*{ MPEG4CELP MKBETAG('c','e','l','p') },*/
- /*{ MPEG4HVXC MKBETAG('h','v','x','c') },*/
- /*{ MPEG4TwinVQ MKBETAG('t','w','v','q') },*/
+ /*{ AC-3 over S/PDIF MKTAG('c','a','c','3') },*/
+ /*{ MPEG4CELP MKTAG('c','e','l','p') },*/
+ /*{ MPEG4HVXC MKTAG('h','v','x','c') },*/
+ /*{ MPEG4TwinVQ MKTAG('t','w','v','q') },*/
{ CODEC_ID_NONE, 0 },
};
+
diff --git a/libavformat/caf.h b/libavformat/caf.h
index 7ca4dc5c66..9c25f2c683 100644
--- a/libavformat/caf.h
+++ b/libavformat/caf.h
@@ -2,20 +2,20 @@
* CAF common code
* Copyright (c) 2007 Justin Ruggles
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/cafdec.c b/libavformat/cafdec.c
index 68686cab97..2b747ce8c4 100644
--- a/libavformat/cafdec.c
+++ b/libavformat/cafdec.c
@@ -3,20 +3,20 @@
* Copyright (c) 2007 Justin Ruggles
* Copyright (c) 2009 Peter Ross
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -61,14 +61,14 @@ static int read_desc_chunk(AVFormatContext *s)
int flags;
/* new audio stream */
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
/* parse format description */
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
st->codec->sample_rate = av_int2dbl(avio_rb64(pb));
- st->codec->codec_tag = avio_rb32(pb);
+ st->codec->codec_tag = avio_rl32(pb);
flags = avio_rb32(pb);
caf->bytes_per_packet = avio_rb32(pb);
st->codec->block_align = caf->bytes_per_packet;
@@ -85,7 +85,7 @@ static int read_desc_chunk(AVFormatContext *s)
}
/* determine codec */
- if (st->codec->codec_tag == MKBETAG('l','p','c','m'))
+ if (st->codec->codec_tag == MKTAG('l','p','c','m'))
st->codec->codec_id = ff_mov_get_lpcm_codec_id(st->codec->bits_per_coded_sample, (flags ^ 0x2) | 0x4);
else
st->codec->codec_id = ff_codec_get_id(ff_codec_caf_tags, st->codec->codec_tag);
@@ -187,8 +187,8 @@ static void read_info_chunk(AVFormatContext *s, int64_t size)
for (i = 0; i < nb_entries; i++) {
char key[32];
char value[1024];
- avio_get_str(pb, INT_MAX, key, sizeof(key));
- avio_get_str(pb, INT_MAX, value, sizeof(value));
+ get_strz(pb, key, sizeof(key));
+ get_strz(pb, value, sizeof(value));
av_dict_set(&s->metadata, key, value, 0);
}
}
@@ -221,7 +221,7 @@ static int read_header(AVFormatContext *s,
/* parse each chunk */
found_data = 0;
- while (!pb->eof_reached) {
+ while (!url_feof(pb)) {
/* stop at data chunk if seeking is not supported or
data chunk size is unknown */
@@ -230,7 +230,7 @@ static int read_header(AVFormatContext *s,
tag = avio_rb32(pb);
size = avio_rb64(pb);
- if (pb->eof_reached)
+ if (url_feof(pb))
break;
switch (tag) {
@@ -259,10 +259,16 @@ static int read_header(AVFormatContext *s,
read_info_chunk(s, size);
break;
+ case MKBETAG('c','h','a','n'):
+ if (size < 12)
+ return AVERROR_INVALIDDATA;
+ ff_mov_read_chan(s, size, st->codec);
+ break;
+
default:
#define _(x) ((x) >= ' ' ? (x) : ' ')
- av_log(s, AV_LOG_WARNING, "skipping CAF chunk: %08X (%c%c%c%c)\n",
- tag, _(tag>>24), _((tag>>16)&0xFF), _((tag>>8)&0xFF), _(tag&0xFF));
+ av_log(s, AV_LOG_WARNING, "skipping CAF chunk: %08X (%c%c%c%c), size %"PRId64"\n",
+ tag, _(tag>>24), _((tag>>16)&0xFF), _((tag>>8)&0xFF), _(tag&0xFF), size);
#undef _
case MKBETAG('f','r','e','e'):
if (size < 0)
@@ -286,8 +292,6 @@ static int read_header(AVFormatContext *s,
"block size or frame size are variable.\n");
return AVERROR_INVALIDDATA;
}
- s->file_size = avio_size(pb);
- s->file_size = FFMAX(0, s->file_size);
av_set_pts_info(st, 64, 1, st->codec->sample_rate);
st->start_time = 0;
@@ -309,7 +313,7 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt)
int res, pkt_size = 0, pkt_frames = 0;
int64_t left = CAF_MAX_PKT_SIZE;
- if (pb->eof_reached)
+ if (url_feof(pb))
return AVERROR(EIO);
/* don't read past end of data chunk */
@@ -360,6 +364,7 @@ static int read_seek(AVFormatContext *s, int stream_index,
{
AVStream *st = s->streams[0];
CaffContext *caf = s->priv_data;
+ CaffContext caf2 = *caf;
int64_t pos;
timestamp = FFMAX(timestamp, 0);
@@ -379,18 +384,20 @@ static int read_seek(AVFormatContext *s, int stream_index,
return -1;
}
- avio_seek(s->pb, pos + caf->data_start, SEEK_SET);
+ if (avio_seek(s->pb, pos + caf->data_start, SEEK_SET) < 0) {
+ *caf = caf2;
+ return -1;
+ }
return 0;
}
AVInputFormat ff_caf_demuxer = {
- "caf",
- NULL_IF_CONFIG_SMALL("Apple Core Audio Format"),
- sizeof(CaffContext),
- probe,
- read_header,
- read_packet,
- NULL,
- read_seek,
+ .name = "caf",
+ .long_name = NULL_IF_CONFIG_SMALL("Apple Core Audio Format"),
+ .priv_data_size = sizeof(CaffContext),
+ .read_probe = probe,
+ .read_header = read_header,
+ .read_packet = read_packet,
+ .read_seek = read_seek,
.codec_tag = (const AVCodecTag*[]){ff_codec_caf_tags, 0},
};
diff --git a/libavformat/cafenc.c b/libavformat/cafenc.c
new file mode 100644
index 0000000000..0dd4b349ca
--- /dev/null
+++ b/libavformat/cafenc.c
@@ -0,0 +1,262 @@
+/*
+ * Core Audio Format muxer
+ * Copyright (c) 2011 Carl Eugen Hoyos
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "avformat.h"
+#include "caf.h"
+#include "riff.h"
+#include "isom.h"
+#include "avio_internal.h"
+#include "libavutil/intfloat_readwrite.h"
+
+typedef struct {
+ int64_t data;
+ uint8_t *pkt_sizes;
+ int size_buffer_size;
+ int size_entries_used;
+ int packets;
+} CAFContext;
+
+static uint32_t codec_flags(enum CodecID codec_id) {
+ switch (codec_id) {
+ case CODEC_ID_PCM_F32BE:
+ case CODEC_ID_PCM_F64BE:
+ return 1; //< kCAFLinearPCMFormatFlagIsFloat
+ case CODEC_ID_PCM_S16LE:
+ case CODEC_ID_PCM_S24LE:
+ case CODEC_ID_PCM_S32LE:
+ return 2; //< kCAFLinearPCMFormatFlagIsLittleEndian
+ case CODEC_ID_PCM_F32LE:
+ case CODEC_ID_PCM_F64LE:
+ return 3; //< kCAFLinearPCMFormatFlagIsFloat | kCAFLinearPCMFormatFlagIsLittleEndian
+ default:
+ return 0;
+ }
+}
+
+static uint32_t samples_per_packet(enum CodecID codec_id, int channels) {
+ switch (codec_id) {
+ case CODEC_ID_PCM_S8:
+ case CODEC_ID_PCM_S16LE:
+ case CODEC_ID_PCM_S16BE:
+ case CODEC_ID_PCM_S24LE:
+ case CODEC_ID_PCM_S24BE:
+ case CODEC_ID_PCM_S32LE:
+ case CODEC_ID_PCM_S32BE:
+ case CODEC_ID_PCM_F32LE:
+ case CODEC_ID_PCM_F32BE:
+ case CODEC_ID_PCM_F64LE:
+ case CODEC_ID_PCM_F64BE:
+ case CODEC_ID_PCM_ALAW:
+ case CODEC_ID_PCM_MULAW:
+ return 1;
+ case CODEC_ID_MACE3:
+ case CODEC_ID_MACE6:
+ return 6;
+ case CODEC_ID_ADPCM_IMA_QT:
+ return 64;
+ case CODEC_ID_AMR_NB:
+ case CODEC_ID_GSM:
+ case CODEC_ID_QCELP:
+ return 160;
+ case CODEC_ID_GSM_MS:
+ return 320;
+ case CODEC_ID_MP1:
+ return 384;
+ case CODEC_ID_MP2:
+ case CODEC_ID_MP3:
+ return 1152;
+ case CODEC_ID_AC3:
+ return 1536;
+ case CODEC_ID_ALAC:
+ case CODEC_ID_QDM2:
+ return 4096;
+ case CODEC_ID_ADPCM_IMA_WAV:
+ return (1024 - 4 * channels) * 8 / (4 * channels) + 1;
+ case CODEC_ID_ADPCM_MS:
+ return (1024 - 7 * channels) * 2 / channels + 2;
+ default:
+ return 0;
+ }
+}
+
+static int caf_write_header(AVFormatContext *s)
+{
+ AVIOContext *pb = s->pb;
+ AVCodecContext *enc = s->streams[0]->codec;
+ CAFContext *caf = s->priv_data;
+ unsigned int codec_tag = ff_codec_get_tag(ff_codec_caf_tags, enc->codec_id);
+
+ switch (enc->codec_id) {
+ case CODEC_ID_AAC:
+ case CODEC_ID_AC3:
+ av_log(s, AV_LOG_ERROR, "muxing codec currently unsupported\n");
+ return AVERROR_PATCHWELCOME;
+ }
+
+ switch (enc->codec_id) {
+ case CODEC_ID_PCM_S8:
+ case CODEC_ID_PCM_S16LE:
+ case CODEC_ID_PCM_S16BE:
+ case CODEC_ID_PCM_S24LE:
+ case CODEC_ID_PCM_S24BE:
+ case CODEC_ID_PCM_S32LE:
+ case CODEC_ID_PCM_S32BE:
+ case CODEC_ID_PCM_F32LE:
+ case CODEC_ID_PCM_F32BE:
+ case CODEC_ID_PCM_F64LE:
+ case CODEC_ID_PCM_F64BE:
+ case CODEC_ID_PCM_ALAW:
+ case CODEC_ID_PCM_MULAW:
+ codec_tag = MKTAG('l','p','c','m');
+ }
+
+ if (!codec_tag) {
+ av_log(s, AV_LOG_ERROR, "unsupported codec\n");
+ return AVERROR_INVALIDDATA;
+ }
+
+ if (!enc->block_align && !pb->seekable) {
+ av_log(s, AV_LOG_ERROR, "Muxing variable packet size not supported on non seekable output\n");
+ return AVERROR_INVALIDDATA;
+ }
+
+ ffio_wfourcc(pb, "caff"); //< mFileType
+ avio_wb16(pb, 1); //< mFileVersion
+ avio_wb16(pb, 0); //< mFileFlags
+
+ ffio_wfourcc(pb, "desc"); //< Audio Description chunk
+ avio_wb64(pb, 32); //< mChunkSize
+ avio_wb64(pb, av_dbl2int(enc->sample_rate)); //< mSampleRate
+ avio_wl32(pb, codec_tag); //< mFormatID
+ avio_wb32(pb, codec_flags(enc->codec_id)); //< mFormatFlags
+ avio_wb32(pb, enc->block_align); //< mBytesPerPacket
+ avio_wb32(pb, samples_per_packet(enc->codec_id, enc->channels)); //< mFramesPerPacket
+ avio_wb32(pb, enc->channels); //< mChannelsPerFrame
+ avio_wb32(pb, av_get_bits_per_sample(enc->codec_id)); //< mBitsPerChannel
+
+ if (enc->channel_layout) {
+ ffio_wfourcc(pb, "chan");
+ avio_wb64(pb, 12);
+ ff_mov_write_chan(pb, enc->channel_layout);
+ }
+
+ if (enc->codec_id == CODEC_ID_ALAC) {
+ ffio_wfourcc(pb, "kuki");
+ avio_wb64(pb, 12 + enc->extradata_size);
+ avio_write(pb, "\0\0\0\14frmaalac", 12);
+ avio_write(pb, enc->extradata, enc->extradata_size);
+ } else if (enc->codec_id == CODEC_ID_AMR_NB) {
+ ffio_wfourcc(pb, "kuki");
+ avio_wb64(pb, 29);
+ avio_write(pb, "\0\0\0\14frmasamr", 12);
+ avio_wb32(pb, 0x11); /* size */
+ avio_write(pb, "samrFFMP", 8);
+ avio_w8(pb, 0); /* decoder version */
+
+ avio_wb16(pb, 0x81FF); /* Mode set (all modes for AMR_NB) */
+ avio_w8(pb, 0x00); /* Mode change period (no restriction) */
+ avio_w8(pb, 0x01); /* Frames per sample */
+ } else if (enc->codec_id == CODEC_ID_QDM2) {
+ ffio_wfourcc(pb, "kuki");
+ avio_wb64(pb, enc->extradata_size);
+ avio_write(pb, enc->extradata, enc->extradata_size);
+ }
+
+ ffio_wfourcc(pb, "data"); //< Audio Data chunk
+ caf->data = avio_tell(pb);
+ avio_wb64(pb, -1); //< mChunkSize
+ avio_wb32(pb, 0); //< mEditCount
+
+ avio_flush(pb);
+ return 0;
+}
+
+static int caf_write_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ CAFContext *caf = s->priv_data;
+
+ avio_write(s->pb, pkt->data, pkt->size);
+ if (!s->streams[0]->codec->block_align) {
+ void *pkt_sizes = caf->pkt_sizes;
+ int i, alloc_size = caf->size_entries_used + 5;
+ if (alloc_size < 0) {
+ caf->pkt_sizes = NULL;
+ } else {
+ caf->pkt_sizes = av_fast_realloc(caf->pkt_sizes,
+ &caf->size_buffer_size,
+ alloc_size);
+ }
+ if (!caf->pkt_sizes) {
+ av_free(pkt_sizes);
+ return AVERROR(ENOMEM);
+ }
+ for (i = 4; i > 0; i--) {
+ unsigned top = pkt->size >> i * 7;
+ if (top)
+ caf->pkt_sizes[caf->size_entries_used++] = 128 | top;
+ }
+ caf->pkt_sizes[caf->size_entries_used++] = pkt->size & 127;
+ caf->packets++;
+ }
+ return 0;
+}
+
+static int caf_write_trailer(AVFormatContext *s)
+{
+ AVIOContext *pb = s->pb;
+ AVCodecContext *enc = s->streams[0]->codec;
+
+ if (pb->seekable) {
+ CAFContext *caf = s->priv_data;
+ int64_t file_size = avio_tell(pb);
+
+ avio_seek(pb, caf->data, SEEK_SET);
+ avio_wb64(pb, file_size - caf->data - 8);
+ avio_seek(pb, file_size, SEEK_SET);
+ if (!enc->block_align) {
+ ffio_wfourcc(pb, "pakt");
+ avio_wb64(pb, caf->size_entries_used + 24);
+ avio_wb64(pb, caf->packets); ///< mNumberPackets
+ avio_wb64(pb, caf->packets * samples_per_packet(enc->codec_id, enc->channels)); ///< mNumberValidFrames
+ avio_wb32(pb, 0); ///< mPrimingFrames
+ avio_wb32(pb, 0); ///< mRemainderFrames
+ avio_write(pb, caf->pkt_sizes, caf->size_entries_used);
+ av_freep(&caf->pkt_sizes);
+ caf->size_buffer_size = 0;
+ }
+ avio_flush(pb);
+ }
+ return 0;
+}
+
+AVOutputFormat ff_caf_muxer = {
+ "caf",
+ NULL_IF_CONFIG_SMALL("Apple Core Audio Format"),
+ "audio/x-caf",
+ "caf",
+ sizeof(CAFContext),
+ CODEC_ID_PCM_S16BE,
+ CODEC_ID_NONE,
+ caf_write_header,
+ caf_write_packet,
+ caf_write_trailer,
+ .codec_tag= (const AVCodecTag* const []){ff_codec_caf_tags, 0},
+};
diff --git a/libavformat/cavsvideodec.c b/libavformat/cavsvideodec.c
index 9aa9413f4c..4a399a26d1 100644
--- a/libavformat/cavsvideodec.c
+++ b/libavformat/cavsvideodec.c
@@ -2,20 +2,20 @@
* RAW Chinese AVS video demuxer
* Copyright (c) 2009 Stefan Gehrer <stefan.gehrer@gmx.de>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/cdg.c b/libavformat/cdg.c
index b47a20e06a..75f1fb24c9 100644
--- a/libavformat/cdg.c
+++ b/libavformat/cdg.c
@@ -2,20 +2,20 @@
* CD Graphics Demuxer
* Copyright (c) 2009 Michael Tison
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -28,7 +28,7 @@ static int read_header(AVFormatContext *s, AVFormatParameters *ap)
AVStream *vst;
int ret;
- vst = av_new_stream(s, 0);
+ vst = avformat_new_stream(s, NULL);
if (!vst)
return AVERROR(ENOMEM);
@@ -52,15 +52,19 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt)
ret = av_get_packet(s->pb, pkt, CDG_PACKET_SIZE);
pkt->stream_index = 0;
+ pkt->dts=pkt->pts= s->streams[0]->cur_dts;
+
+ if(ret>5 && (pkt->data[0]&0x3F) == 9 && (pkt->data[1]&0x3F)==1 && !(pkt->data[2+2+1] & 0x0F)){
+ pkt->flags = AV_PKT_FLAG_KEY;
+ }
return ret;
}
AVInputFormat ff_cdg_demuxer = {
- "cdg",
- NULL_IF_CONFIG_SMALL("CD Graphics Format"),
- 0,
- NULL,
- read_header,
- read_packet,
+ .name = "cdg",
+ .long_name = NULL_IF_CONFIG_SMALL("CD Graphics Format"),
+ .read_header = read_header,
+ .read_packet = read_packet,
+ .flags= AVFMT_GENERIC_INDEX,
.extensions = "cdg"
};
diff --git a/libavformat/concat.c b/libavformat/concat.c
index da9bee2cc4..ba1b6a544a 100644
--- a/libavformat/concat.c
+++ b/libavformat/concat.c
@@ -4,20 +4,20 @@
* Copyright (c) 2007 Wolfram Gloger
* Copyright (c) 2010 Michele Orrù
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/crcenc.c b/libavformat/crcenc.c
index 55c99d9d88..f596e665d1 100644
--- a/libavformat/crcenc.c
+++ b/libavformat/crcenc.c
@@ -2,20 +2,20 @@
* CRC encoder (for codec/format testing)
* Copyright (c) 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -55,14 +55,13 @@ static int crc_write_trailer(struct AVFormatContext *s)
}
AVOutputFormat ff_crc_muxer = {
- "crc",
- NULL_IF_CONFIG_SMALL("CRC testing format"),
- NULL,
- "",
- sizeof(CRCState),
- CODEC_ID_PCM_S16LE,
- CODEC_ID_RAWVIDEO,
- crc_write_header,
- crc_write_packet,
- crc_write_trailer,
+ .name = "crc",
+ .long_name = NULL_IF_CONFIG_SMALL("CRC testing format"),
+ .extensions = "",
+ .priv_data_size = sizeof(CRCState),
+ .audio_codec = CODEC_ID_PCM_S16LE,
+ .video_codec = CODEC_ID_RAWVIDEO,
+ .write_header = crc_write_header,
+ .write_packet = crc_write_packet,
+ .write_trailer = crc_write_trailer,
};
diff --git a/libavformat/crypto.c b/libavformat/crypto.c
index 5e7ee1eba3..b9d3e0326f 100644
--- a/libavformat/crypto.c
+++ b/libavformat/crypto.c
@@ -46,8 +46,8 @@ typedef struct {
#define OFFSET(x) offsetof(CryptoContext, x)
static const AVOption options[] = {
- {"key", "AES decryption key", OFFSET(key), FF_OPT_TYPE_BINARY },
- {"iv", "AES decryption initialization vector", OFFSET(iv), FF_OPT_TYPE_BINARY },
+ {"key", "AES decryption key", OFFSET(key), AV_OPT_TYPE_BINARY },
+ {"iv", "AES decryption initialization vector", OFFSET(iv), AV_OPT_TYPE_BINARY },
{ NULL }
};
diff --git a/libavformat/cutils.c b/libavformat/cutils.c
index 092aa8a1a9..76aba56150 100644
--- a/libavformat/cutils.c
+++ b/libavformat/cutils.c
@@ -2,46 +2,25 @@
* Various simple utilities for ffmpeg system
* Copyright (c) 2000, 2001, 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avformat.h"
#include "internal.h"
-/* add one element to a dynamic array */
-void ff_dynarray_add(intptr_t **tab_ptr, int *nb_ptr, intptr_t elem)
-{
- /* see similar ffmpeg.c:grow_array() */
- int nb, nb_alloc;
- intptr_t *tab;
-
- nb = *nb_ptr;
- tab = *tab_ptr;
- if ((nb & (nb - 1)) == 0) {
- if (nb == 0)
- nb_alloc = 1;
- else
- nb_alloc = nb * 2;
- tab = av_realloc(tab, nb_alloc * sizeof(intptr_t));
- *tab_ptr = tab;
- }
- tab[nb++] = elem;
- *nb_ptr = nb;
-}
-
#define ISLEAP(y) (((y) % 4 == 0) && (((y) % 100) != 0 || ((y) % 400) == 0))
#define LEAPS_COUNT(y) ((y)/4 - (y)/100 + (y)/400)
diff --git a/libavformat/daud.c b/libavformat/daud.c
index 1b3cfcf2d9..aa70800085 100644
--- a/libavformat/daud.c
+++ b/libavformat/daud.c
@@ -2,26 +2,26 @@
* D-Cinema audio demuxer
* Copyright (c) 2005 Reimar Döffinger
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avformat.h"
static int daud_header(AVFormatContext *s, AVFormatParameters *ap) {
- AVStream *st = av_new_stream(s, 0);
+ AVStream *st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
@@ -38,7 +38,7 @@ static int daud_header(AVFormatContext *s, AVFormatParameters *ap) {
static int daud_packet(AVFormatContext *s, AVPacket *pkt) {
AVIOContext *pb = s->pb;
int ret, size;
- if (pb->eof_reached)
+ if (url_feof(pb))
return AVERROR(EIO);
size = avio_rb16(pb);
avio_rb16(pb); // unknown
@@ -71,30 +71,23 @@ static int daud_write_packet(struct AVFormatContext *s, AVPacket *pkt)
#if CONFIG_DAUD_DEMUXER
AVInputFormat ff_daud_demuxer = {
- "daud",
- NULL_IF_CONFIG_SMALL("D-Cinema audio format"),
- 0,
- NULL,
- daud_header,
- daud_packet,
- NULL,
- NULL,
+ .name = "daud",
+ .long_name = NULL_IF_CONFIG_SMALL("D-Cinema audio format"),
+ .read_header = daud_header,
+ .read_packet = daud_packet,
.extensions = "302",
};
#endif
#if CONFIG_DAUD_MUXER
-AVOutputFormat ff_daud_muxer =
-{
- "daud",
- NULL_IF_CONFIG_SMALL("D-Cinema audio format"),
- NULL,
- "302",
- 0,
- CODEC_ID_PCM_S24DAUD,
- CODEC_ID_NONE,
- daud_write_header,
- daud_write_packet,
- .flags= AVFMT_NOTIMESTAMPS,
+AVOutputFormat ff_daud_muxer = {
+ .name = "daud",
+ .long_name = NULL_IF_CONFIG_SMALL("D-Cinema audio format"),
+ .extensions = "302",
+ .audio_codec = CODEC_ID_PCM_S24DAUD,
+ .video_codec = CODEC_ID_NONE,
+ .write_header = daud_write_header,
+ .write_packet = daud_write_packet,
+ .flags = AVFMT_NOTIMESTAMPS,
};
#endif
diff --git a/libavformat/dfa.c b/libavformat/dfa.c
index 810853568d..a109a2d2b7 100644
--- a/libavformat/dfa.c
+++ b/libavformat/dfa.c
@@ -2,20 +2,20 @@
* Chronomaster DFA Format Demuxer
* Copyright (c) 2011 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -45,7 +45,7 @@ static int dfa_read_header(AVFormatContext *s,
avio_skip(pb, 2); // unused
frames = avio_rl16(pb);
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
@@ -109,11 +109,10 @@ static int dfa_read_packet(AVFormatContext *s, AVPacket *pkt)
}
AVInputFormat ff_dfa_demuxer = {
- "dfa",
- NULL_IF_CONFIG_SMALL("Chronomaster DFA"),
- 0,
- dfa_probe,
- dfa_read_header,
- dfa_read_packet,
+ .name = "dfa",
+ .long_name = NULL_IF_CONFIG_SMALL("Chronomaster DFA"),
+ .read_probe = dfa_probe,
+ .read_header = dfa_read_header,
+ .read_packet = dfa_read_packet,
.flags = AVFMT_GENERIC_INDEX,
};
diff --git a/libavformat/diracdec.c b/libavformat/diracdec.c
index 8cbd5b5146..6afda533dc 100644
--- a/libavformat/diracdec.c
+++ b/libavformat/diracdec.c
@@ -2,20 +2,20 @@
* RAW Dirac demuxer
* Copyright (c) 2007 Marco Gerards <marco@gnu.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/dnxhddec.c b/libavformat/dnxhddec.c
index 2aa8017ad4..f89782a880 100644
--- a/libavformat/dnxhddec.c
+++ b/libavformat/dnxhddec.c
@@ -3,20 +3,20 @@
* Copyright (c) 2008 Baptiste Coudurier <baptiste.coudurier@gmail.com>
* Copyright (c) 2009 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/dsicin.c b/libavformat/dsicin.c
index d02de46e0f..09e80e944f 100644
--- a/libavformat/dsicin.c
+++ b/libavformat/dsicin.c
@@ -2,20 +2,20 @@
* Delphine Software International CIN File Demuxer
* Copyright (c) 2006 Gregory Montoir (cyx@users.sourceforge.net)
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -107,7 +107,7 @@ static int cin_read_header(AVFormatContext *s, AVFormatParameters *ap)
cin->audio_buffer_size = 0;
/* initialize the video decoder stream */
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
@@ -120,7 +120,7 @@ static int cin_read_header(AVFormatContext *s, AVFormatParameters *ap)
st->codec->height = hdr->video_frame_height;
/* initialize the audio decoder stream */
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
@@ -147,7 +147,7 @@ static int cin_read_frame_header(CinDemuxContext *cin, AVIOContext *pb) {
hdr->video_frame_size = avio_rl32(pb);
hdr->audio_frame_size = avio_rl32(pb);
- if (pb->eof_reached || pb->error)
+ if (url_feof(pb) || pb->error)
return AVERROR(EIO);
if (avio_rl32(pb) != 0xAA55AA55)
@@ -217,10 +217,10 @@ static int cin_read_packet(AVFormatContext *s, AVPacket *pkt)
}
AVInputFormat ff_dsicin_demuxer = {
- "dsicin",
- NULL_IF_CONFIG_SMALL("Delphine Software International CIN format"),
- sizeof(CinDemuxContext),
- cin_probe,
- cin_read_header,
- cin_read_packet,
+ .name = "dsicin",
+ .long_name = NULL_IF_CONFIG_SMALL("Delphine Software International CIN format"),
+ .priv_data_size = sizeof(CinDemuxContext),
+ .read_probe = cin_probe,
+ .read_header = cin_read_header,
+ .read_packet = cin_read_packet,
};
diff --git a/libavformat/dtsdec.c b/libavformat/dtsdec.c
index 943f6a5d5a..e762b85e19 100644
--- a/libavformat/dtsdec.c
+++ b/libavformat/dtsdec.c
@@ -2,20 +2,20 @@
* RAW DTS demuxer
* Copyright (c) 2008 Benjamin Larsson
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -66,12 +66,11 @@ static int dts_probe(AVProbeData *p)
}
AVInputFormat ff_dts_demuxer = {
- "dts",
- NULL_IF_CONFIG_SMALL("raw DTS"),
- 0,
- dts_probe,
- ff_raw_audio_read_header,
- ff_raw_read_partial_packet,
+ .name = "dts",
+ .long_name = NULL_IF_CONFIG_SMALL("raw DTS"),
+ .read_probe = dts_probe,
+ .read_header = ff_raw_audio_read_header,
+ .read_packet = ff_raw_read_partial_packet,
.flags= AVFMT_GENERIC_INDEX,
.extensions = "dts",
.value = CODEC_ID_DTS,
diff --git a/libavformat/dv.c b/libavformat/dv.c
index f38b954605..378f29f0f3 100644
--- a/libavformat/dv.c
+++ b/libavformat/dv.c
@@ -12,20 +12,20 @@
* Copyright (c) 2006 Daniel Maas <dmaas@maasdigital.com>
* Funded by BBC Research & Development
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <time.h>
@@ -211,7 +211,7 @@ static int dv_extract_audio_info(DVDemuxContext* c, uint8_t* frame)
/* Dynamic handling of the audio streams in DV */
for (i = 0; i < ach; i++) {
if (!c->ast[i]) {
- c->ast[i] = av_new_stream(c->fctx, 0);
+ c->ast[i] = avformat_new_stream(c->fctx, NULL);
if (!c->ast[i])
break;
av_set_pts_info(c->ast[i], 64, 1, 30000);
@@ -270,7 +270,7 @@ static int dv_extract_video_info(DVDemuxContext *c, uint8_t* frame)
* The following 3 functions constitute our interface to the world
*/
-DVDemuxContext* dv_init_demux(AVFormatContext *s)
+DVDemuxContext* avpriv_dv_init_demux(AVFormatContext *s)
{
DVDemuxContext *c;
@@ -278,7 +278,7 @@ DVDemuxContext* dv_init_demux(AVFormatContext *s)
if (!c)
return NULL;
- c->vst = av_new_stream(s, 0);
+ c->vst = avformat_new_stream(s, NULL);
if (!c->vst) {
av_free(c);
return NULL;
@@ -299,7 +299,7 @@ DVDemuxContext* dv_init_demux(AVFormatContext *s)
return c;
}
-int dv_get_packet(DVDemuxContext *c, AVPacket *pkt)
+int avpriv_dv_get_packet(DVDemuxContext *c, AVPacket *pkt)
{
int size = -1;
int i;
@@ -316,14 +316,14 @@ int dv_get_packet(DVDemuxContext *c, AVPacket *pkt)
return size;
}
-int dv_produce_packet(DVDemuxContext *c, AVPacket *pkt,
- uint8_t* buf, int buf_size)
+int avpriv_dv_produce_packet(DVDemuxContext *c, AVPacket *pkt,
+ uint8_t* buf, int buf_size, int64_t pos)
{
int size, i;
uint8_t *ppcm[4] = {0};
if (buf_size < DV_PROFILE_BYTES ||
- !(c->sys = ff_dv_frame_profile(c->sys, buf, buf_size)) ||
+ !(c->sys = avpriv_dv_frame_profile(c->sys, buf, buf_size)) ||
buf_size < c->sys->frame_size) {
return -1; /* Broken frame, or not enough data */
}
@@ -332,6 +332,7 @@ int dv_produce_packet(DVDemuxContext *c, AVPacket *pkt,
/* FIXME: in case of no audio/bad audio we have to do something */
size = dv_extract_audio_info(c, buf);
for (i = 0; i < c->ach; i++) {
+ c->audio_pkt[i].pos = pos;
c->audio_pkt[i].size = size;
c->audio_pkt[i].pts = c->abytes * 30000*8 / c->ast[i]->codec->bit_rate;
ppcm[i] = c->audio_buf[i];
@@ -355,6 +356,7 @@ int dv_produce_packet(DVDemuxContext *c, AVPacket *pkt,
size = dv_extract_video_info(c, buf);
av_init_packet(pkt);
pkt->data = buf;
+ pkt->pos = pos;
pkt->size = size;
pkt->flags |= AV_PKT_FLAG_KEY;
pkt->stream_index = c->vst->id;
@@ -369,7 +371,7 @@ static int64_t dv_frame_offset(AVFormatContext *s, DVDemuxContext *c,
int64_t timestamp, int flags)
{
// FIXME: sys may be wrong if last dv_read_packet() failed (buffer is junk)
- const DVprofile* sys = ff_dv_codec_profile(c->vst->codec);
+ const DVprofile* sys = avpriv_dv_codec_profile(c->vst->codec);
int64_t offset;
int64_t size = avio_size(s->pb) - s->data_offset;
int64_t max_offset = ((size-1) / sys->frame_size) * sys->frame_size;
@@ -407,13 +409,13 @@ static int dv_read_header(AVFormatContext *s,
unsigned state, marker_pos = 0;
RawDVContext *c = s->priv_data;
- c->dv_demux = dv_init_demux(s);
+ c->dv_demux = avpriv_dv_init_demux(s);
if (!c->dv_demux)
return -1;
state = avio_rb32(s->pb);
while ((state & 0xffffff7f) != 0x1f07003f) {
- if (s->pb->eof_reached) {
+ if (url_feof(s->pb)) {
av_log(s, AV_LOG_ERROR, "Cannot find DV header.\n");
return -1;
}
@@ -432,7 +434,7 @@ static int dv_read_header(AVFormatContext *s,
avio_seek(s->pb, -DV_PROFILE_BYTES, SEEK_CUR) < 0)
return AVERROR(EIO);
- c->dv_demux->sys = ff_dv_frame_profile(c->dv_demux->sys, c->buf, DV_PROFILE_BYTES);
+ c->dv_demux->sys = avpriv_dv_frame_profile(c->dv_demux->sys, c->buf, DV_PROFILE_BYTES);
if (!c->dv_demux->sys) {
av_log(s, AV_LOG_ERROR, "Can't determine profile of DV input stream.\n");
return -1;
@@ -450,16 +452,17 @@ static int dv_read_packet(AVFormatContext *s, AVPacket *pkt)
int size;
RawDVContext *c = s->priv_data;
- size = dv_get_packet(c->dv_demux, pkt);
+ size = avpriv_dv_get_packet(c->dv_demux, pkt);
if (size < 0) {
+ int64_t pos = avio_tell(s->pb);
if (!c->dv_demux->sys)
return AVERROR(EIO);
size = c->dv_demux->sys->frame_size;
if (avio_read(s->pb, c->buf, size) <= 0)
return AVERROR(EIO);
- size = dv_produce_packet(c->dv_demux, pkt, c->buf, size);
+ size = avpriv_dv_produce_packet(c->dv_demux, pkt, c->buf, size, pos);
}
return size;
@@ -472,10 +475,11 @@ static int dv_read_seek(AVFormatContext *s, int stream_index,
DVDemuxContext *c = r->dv_demux;
int64_t offset = dv_frame_offset(s, c, timestamp, flags);
- dv_offset_reset(c, offset / c->sys->frame_size);
+ if (avio_seek(s->pb, offset, SEEK_SET) < 0)
+ return -1;
- offset = avio_seek(s->pb, offset, SEEK_SET);
- return (offset < 0) ? offset : 0;
+ dv_offset_reset(c, offset / c->sys->frame_size);
+ return 0;
}
static int dv_read_close(AVFormatContext *s)
@@ -520,14 +524,14 @@ static int dv_probe(AVProbeData *p)
#if CONFIG_DV_DEMUXER
AVInputFormat ff_dv_demuxer = {
- "dv",
- NULL_IF_CONFIG_SMALL("DV video format"),
- sizeof(RawDVContext),
- dv_probe,
- dv_read_header,
- dv_read_packet,
- dv_read_close,
- dv_read_seek,
+ .name = "dv",
+ .long_name = NULL_IF_CONFIG_SMALL("DV video format"),
+ .priv_data_size = sizeof(RawDVContext),
+ .read_probe = dv_probe,
+ .read_header = dv_read_header,
+ .read_packet = dv_read_packet,
+ .read_close = dv_read_close,
+ .read_seek = dv_read_seek,
.extensions = "dv,dif",
};
#endif
diff --git a/libavformat/dv.h b/libavformat/dv.h
index 650699d2d7..722067f206 100644
--- a/libavformat/dv.h
+++ b/libavformat/dv.h
@@ -8,20 +8,20 @@
* Raw DV format
* Copyright (c) 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -31,9 +31,9 @@
#include "avformat.h"
typedef struct DVDemuxContext DVDemuxContext;
-DVDemuxContext* dv_init_demux(AVFormatContext* s);
-int dv_get_packet(DVDemuxContext*, AVPacket *);
-int dv_produce_packet(DVDemuxContext*, AVPacket*, uint8_t*, int);
+DVDemuxContext* avpriv_dv_init_demux(AVFormatContext* s);
+int avpriv_dv_get_packet(DVDemuxContext*, AVPacket *);
+int avpriv_dv_produce_packet(DVDemuxContext*, AVPacket*, uint8_t*, int, int64_t);
void dv_offset_reset(DVDemuxContext *c, int64_t frame_offset);
typedef struct DVMuxContext DVMuxContext;
diff --git a/libavformat/dvenc.c b/libavformat/dvenc.c
index 504e3ee26f..ce6568b5eb 100644
--- a/libavformat/dvenc.c
+++ b/libavformat/dvenc.c
@@ -11,20 +11,20 @@
* 50 Mbps (DVCPRO50) support
* Copyright (c) 2006 Daniel Maas <dmaas@maasdigital.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <time.h>
@@ -33,20 +33,25 @@
#include "avformat.h"
#include "internal.h"
#include "libavcodec/dvdata.h"
+#include "libavcodec/timecode.h"
#include "dv.h"
#include "libavutil/fifo.h"
#include "libavutil/mathematics.h"
+#include "libavutil/intreadwrite.h"
+#include "libavutil/opt.h"
struct DVMuxContext {
+ AVClass *av_class;
const DVprofile* sys; /* current DV profile, e.g.: 525/60, 625/50 */
int n_ast; /* number of stereo audio streams (up to 2) */
AVStream *ast[2]; /* stereo audio streams */
AVFifoBuffer *audio_data[2]; /* FIFO for storing excessive amounts of PCM */
int frames; /* current frame number */
- time_t start_time; /* recording start time */
+ int64_t start_time; /* recording start time */
int has_audio; /* frame under contruction has audio */
int has_video; /* frame under contruction has video */
uint8_t frame_buf[DV_MAX_FRAME_SIZE]; /* frame under contruction */
+ struct ff_timecode tc;
};
static const int dv_aaux_packs_dist[12][9] = {
@@ -75,33 +80,23 @@ static int dv_write_pack(enum dv_pack_type pack_id, DVMuxContext *c, uint8_t* bu
struct tm tc;
time_t ct;
int ltc_frame;
+ uint32_t timecode;
va_list ap;
buf[0] = (uint8_t)pack_id;
switch (pack_id) {
case dv_timecode:
- ct = (time_t)av_rescale_rnd(c->frames, c->sys->time_base.num,
- c->sys->time_base.den, AV_ROUND_DOWN);
- brktimegm(ct, &tc);
/*
* LTC drop-frame frame counter drops two frames (0 and 1) every
* minute, unless it is exactly divisible by 10
*/
- ltc_frame = (c->frames + 2 * ct / 60 - 2 * ct / 600) % c->sys->ltc_divisor;
- buf[1] = (0 << 7) | /* color frame: 0 - unsync; 1 - sync mode */
- (1 << 6) | /* drop frame timecode: 0 - nondrop; 1 - drop */
- ((ltc_frame / 10) << 4) | /* tens of frames */
- (ltc_frame % 10); /* units of frames */
- buf[2] = (1 << 7) | /* biphase mark polarity correction: 0 - even; 1 - odd */
- ((tc.tm_sec / 10) << 4) | /* tens of seconds */
- (tc.tm_sec % 10); /* units of seconds */
- buf[3] = (1 << 7) | /* binary group flag BGF0 */
- ((tc.tm_min / 10) << 4) | /* tens of minutes */
- (tc.tm_min % 10); /* units of minutes */
- buf[4] = (1 << 7) | /* binary group flag BGF2 */
- (1 << 6) | /* binary group flag BGF1 */
- ((tc.tm_hour / 10) << 4) | /* tens of hours */
- (tc.tm_hour % 10); /* units of hours */
+ ltc_frame = c->tc.start + c->frames;
+ if (c->tc.drop)
+ ltc_frame = ff_framenum_to_drop_timecode(ltc_frame);
+ timecode = ff_framenum_to_smtpe_timecode(ltc_frame, c->sys->ltc_divisor,
+ c->tc.drop);
+ timecode |= 1<<23 | 1<<15 | 1<<7 | 1<<6; // biphase and binary group flags
+ AV_WB32(buf + 1, timecode);
break;
case dv_audio_source: /* AAUX source pack */
va_start(ap, buf);
@@ -192,8 +187,8 @@ static void dv_inject_audio(DVMuxContext *c, int channel, uint8_t* frame_ptr)
if (of*2 >= size)
continue;
- frame_ptr[d] = av_fifo_peek(c->audio_data[channel], of*2+1); // FIXME: maybe we have to admit
- frame_ptr[d+1] = av_fifo_peek(c->audio_data[channel], of*2); // that DV is a big-endian PCM
+ frame_ptr[d] = *av_fifo_peek2(c->audio_data[channel], of*2+1); // FIXME: maybe we have to admit
+ frame_ptr[d+1] = *av_fifo_peek2(c->audio_data[channel], of*2); // that DV is a big-endian PCM
}
frame_ptr += 16 * 80; /* 15 Video DIFs + 1 Audio DIF */
}
@@ -290,6 +285,7 @@ static DVMuxContext* dv_init_mux(AVFormatContext* s)
{
DVMuxContext *c = s->priv_data;
AVStream *vst = NULL;
+ AVDictionaryEntry *t;
int i;
/* we support at most 1 video and 2 audio streams */
@@ -324,7 +320,7 @@ static DVMuxContext* dv_init_mux(AVFormatContext* s)
c->ast[i]->codec->channels != 2))
goto bail_out;
}
- c->sys = ff_dv_codec_profile(vst->codec);
+ c->sys = avpriv_dv_codec_profile(vst->codec);
if (!c->sys)
goto bail_out;
@@ -337,7 +333,13 @@ static DVMuxContext* dv_init_mux(AVFormatContext* s)
c->frames = 0;
c->has_audio = 0;
c->has_video = 0;
- c->start_time = (time_t)s->timestamp;
+#if FF_API_TIMESTAMP
+ if (s->timestamp)
+ c->start_time = s->timestamp;
+ else
+#endif
+ if (t = av_dict_get(s->metadata, "creation_time", NULL, 0))
+ c->start_time = ff_iso8601_to_unix_time(t->value);
for (i=0; i < c->n_ast; i++) {
if (c->ast[i] && !(c->audio_data[i]=av_fifo_alloc(100*AVCODEC_MAX_AUDIO_FRAME_SIZE))) {
@@ -364,6 +366,8 @@ static void dv_delete_mux(DVMuxContext *c)
static int dv_write_header(AVFormatContext *s)
{
+ DVMuxContext *dvc = s->priv_data;
+
if (!dv_init_mux(s)) {
av_log(s, AV_LOG_ERROR, "Can't initialize DV format!\n"
"Make sure that you supply exactly two streams:\n"
@@ -371,6 +375,12 @@ static int dv_write_header(AVFormatContext *s)
" (50Mbps allows an optional second audio stream)\n");
return -1;
}
+ if (dvc->tc.str) {
+ dvc->tc.rate.num = dvc->sys->time_base.den;
+ dvc->tc.rate.den = dvc->sys->time_base.num;
+ if (ff_init_smtpe_timecode(s, &dvc->tc) < 0)
+ return -1;
+ }
return 0;
}
@@ -400,15 +410,25 @@ static int dv_write_trailer(struct AVFormatContext *s)
return 0;
}
+static const AVClass class = {
+ .class_name = "dv",
+ .item_name = av_default_item_name,
+ .version = LIBAVUTIL_VERSION_INT,
+ .option = (const AVOption[]){
+ {TIMECODE_OPT(DVMuxContext, AV_OPT_FLAG_ENCODING_PARAM)},
+ {NULL},
+ },
+};
+
AVOutputFormat ff_dv_muxer = {
- "dv",
- NULL_IF_CONFIG_SMALL("DV video format"),
- NULL,
- "dv",
- sizeof(DVMuxContext),
- CODEC_ID_PCM_S16LE,
- CODEC_ID_DVVIDEO,
- dv_write_header,
- dv_write_packet,
- dv_write_trailer,
+ .name = "dv",
+ .long_name = NULL_IF_CONFIG_SMALL("DV video format"),
+ .extensions = "dv",
+ .priv_data_size = sizeof(DVMuxContext),
+ .audio_codec = CODEC_ID_PCM_S16LE,
+ .video_codec = CODEC_ID_DVVIDEO,
+ .write_header = dv_write_header,
+ .write_packet = dv_write_packet,
+ .write_trailer = dv_write_trailer,
+ .priv_class = &class,
};
diff --git a/libavformat/dxa.c b/libavformat/dxa.c
index 1e1d50581c..65a61159bc 100644
--- a/libavformat/dxa.c
+++ b/libavformat/dxa.c
@@ -2,20 +2,20 @@
* DXA demuxer
* Copyright (c) 2007 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -87,7 +87,7 @@ static int dxa_read_header(AVFormatContext *s, AVFormatParameters *ap)
h = avio_rb16(pb);
c->has_sound = 0;
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return -1;
@@ -100,14 +100,14 @@ static int dxa_read_header(AVFormatContext *s, AVFormatParameters *ap)
avio_skip(pb, 16);
fsize = avio_rl32(pb);
- ast = av_new_stream(s, 0);
+ ast = avformat_new_stream(s, NULL);
if (!ast)
return -1;
ret = ff_get_wav_header(pb, ast->codec, fsize);
if (ret < 0)
return ret;
// find 'data' chunk
- while(avio_tell(pb) < c->vidpos && !pb->eof_reached){
+ while(avio_tell(pb) < c->vidpos && !url_feof(pb)){
tag = avio_rl32(pb);
fsize = avio_rl32(pb);
if(tag == MKTAG('d', 'a', 't', 'a')) break;
@@ -165,7 +165,7 @@ static int dxa_read_packet(AVFormatContext *s, AVPacket *pkt)
return 0;
}
avio_seek(s->pb, c->vidpos, SEEK_SET);
- while(!s->pb->eof_reached && c->frames){
+ while(!url_feof(s->pb) && c->frames){
avio_read(s->pb, buf, 4);
switch(AV_RL32(buf)){
case MKTAG('N', 'U', 'L', 'L'):
@@ -213,10 +213,10 @@ static int dxa_read_packet(AVFormatContext *s, AVPacket *pkt)
}
AVInputFormat ff_dxa_demuxer = {
- "dxa",
- NULL_IF_CONFIG_SMALL("DXA"),
- sizeof(DXAContext),
- dxa_probe,
- dxa_read_header,
- dxa_read_packet,
+ .name = "dxa",
+ .long_name = NULL_IF_CONFIG_SMALL("DXA"),
+ .priv_data_size = sizeof(DXAContext),
+ .read_probe = dxa_probe,
+ .read_header = dxa_read_header,
+ .read_packet = dxa_read_packet,
};
diff --git a/libavformat/eacdata.c b/libavformat/eacdata.c
index 5c89559ed1..adf48c6a19 100644
--- a/libavformat/eacdata.c
+++ b/libavformat/eacdata.c
@@ -2,20 +2,20 @@
* Electronic Arts .cdata file Demuxer
* Copyright (c) 2007 Peter Ross
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -39,7 +39,7 @@ static int cdata_probe(AVProbeData *p)
{
const uint8_t *b = p->buf;
- if (b[0] == 0x04 && (b[1] == 0x00 || b[1] == 0x04 || b[1] == 0x0C))
+ if (b[0] == 0x04 && (b[1] == 0x00 || b[1] == 0x04 || b[1] == 0x0C || b[1] == 0x14))
return AVPROBE_SCORE_MAX/8;
return 0;
}
@@ -50,28 +50,32 @@ static int cdata_read_header(AVFormatContext *s, AVFormatParameters *ap)
AVIOContext *pb = s->pb;
unsigned int sample_rate, header;
AVStream *st;
+ int64_t channel_layout = 0;
header = avio_rb16(pb);
switch (header) {
case 0x0400: cdata->channels = 1; break;
case 0x0404: cdata->channels = 2; break;
- case 0x040C: cdata->channels = 4; break;
+ case 0x040C: cdata->channels = 4; channel_layout = AV_CH_LAYOUT_QUAD; break;
+ case 0x0414: cdata->channels = 6; channel_layout = AV_CH_LAYOUT_5POINT1_BACK; break;
default:
av_log(s, AV_LOG_INFO, "unknown header 0x%04x\n", header);
return -1;
};
sample_rate = avio_rb16(pb);
- avio_skip(pb, 12);
+ avio_skip(pb, (avio_r8(pb) & 0x20) ? 15 : 11);
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
st->codec->codec_tag = 0; /* no fourcc */
st->codec->codec_id = CODEC_ID_ADPCM_EA_XAS;
st->codec->channels = cdata->channels;
+ st->codec->channel_layout = channel_layout;
st->codec->sample_rate = sample_rate;
+ st->codec->sample_fmt = AV_SAMPLE_FMT_S16;
av_set_pts_info(st, 64, 1, sample_rate);
cdata->audio_pts = 0;
@@ -91,11 +95,11 @@ static int cdata_read_packet(AVFormatContext *s, AVPacket *pkt)
}
AVInputFormat ff_ea_cdata_demuxer = {
- "ea_cdata",
- NULL_IF_CONFIG_SMALL("Electronic Arts cdata"),
- sizeof(CdataDemuxContext),
- cdata_probe,
- cdata_read_header,
- cdata_read_packet,
+ .name = "ea_cdata",
+ .long_name = NULL_IF_CONFIG_SMALL("Electronic Arts cdata"),
+ .priv_data_size = sizeof(CdataDemuxContext),
+ .read_probe = cdata_probe,
+ .read_header = cdata_read_header,
+ .read_packet = cdata_read_packet,
.extensions = "cdata",
};
diff --git a/libavformat/electronicarts.c b/libavformat/electronicarts.c
index 06689ddfb7..0508a06cc4 100644
--- a/libavformat/electronicarts.c
+++ b/libavformat/electronicarts.c
@@ -2,20 +2,20 @@
* Copyright (c) 2004 The ffmpeg Project
* Copyright (c) 2006-2008 Peter Ross
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -109,7 +109,7 @@ static int process_audio_header_elements(AVFormatContext *s)
ea->sample_rate = -1;
ea->num_channels = 1;
- while (!pb->eof_reached && inHeader) {
+ while (!url_feof(pb) && inHeader) {
int inSubheader;
uint8_t byte;
byte = avio_r8(pb);
@@ -118,7 +118,7 @@ static int process_audio_header_elements(AVFormatContext *s)
case 0xFD:
av_log (s, AV_LOG_DEBUG, "entered audio subheader\n");
inSubheader = 1;
- while (!pb->eof_reached && inSubheader) {
+ while (!url_feof(pb) && inSubheader) {
uint8_t subbyte;
subbyte = avio_r8(pb);
@@ -330,12 +330,10 @@ static int process_ea_header(AVFormatContext *s) {
case MVIh_TAG :
ea->video_codec = CODEC_ID_CMV;
- ea->time_base = (AVRational){0,0};
break;
case kVGT_TAG:
ea->video_codec = CODEC_ID_TGV;
- ea->time_base = (AVRational){0,0};
break;
case mTCD_TAG :
@@ -410,14 +408,18 @@ static int ea_read_header(AVFormatContext *s,
if (ea->video_codec) {
/* initialize the video decoder stream */
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
ea->video_stream_index = st->index;
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
st->codec->codec_id = ea->video_codec;
+ // parsing is necessary to make FFmpeg generate correct timestamps
+ if (st->codec->codec_id == CODEC_ID_MPEG2VIDEO)
+ st->need_parsing = AVSTREAM_PARSE_HEADERS;
st->codec->codec_tag = 0; /* no fourcc */
- st->codec->time_base = ea->time_base;
+ if (ea->time_base.num)
+ av_set_pts_info(st, 64, ea->time_base.num, ea->time_base.den);
st->codec->width = ea->width;
st->codec->height = ea->height;
}
@@ -435,7 +437,7 @@ static int ea_read_header(AVFormatContext *s,
}
/* initialize the audio decoder stream */
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
av_set_pts_info(st, 33, 1, ea->sample_rate);
@@ -569,10 +571,10 @@ get_video_packet:
}
AVInputFormat ff_ea_demuxer = {
- "ea",
- NULL_IF_CONFIG_SMALL("Electronic Arts Multimedia Format"),
- sizeof(EaDemuxContext),
- ea_probe,
- ea_read_header,
- ea_read_packet,
+ .name = "ea",
+ .long_name = NULL_IF_CONFIG_SMALL("Electronic Arts Multimedia Format"),
+ .priv_data_size = sizeof(EaDemuxContext),
+ .read_probe = ea_probe,
+ .read_header = ea_read_header,
+ .read_packet = ea_read_packet,
};
diff --git a/libavformat/ffm.h b/libavformat/ffm.h
index 89a14a5a88..04f19cc88e 100644
--- a/libavformat/ffm.h
+++ b/libavformat/ffm.h
@@ -2,20 +2,20 @@
* FFM (ffserver live feed) common header
* Copyright (c) 2001 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/ffmdec.c b/libavformat/ffmdec.c
index 91ab2e4370..b8cf119cb3 100644
--- a/libavformat/ffmdec.c
+++ b/libavformat/ffmdec.c
@@ -2,20 +2,20 @@
* FFM (ffserver live feed) demuxer
* Copyright (c) 2001 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -92,7 +92,7 @@ static int ffm_resync(AVFormatContext *s, int state)
{
av_log(s, AV_LOG_ERROR, "resyncing\n");
while (state != PACKET_ID) {
- if (s->pb->eof_reached) {
+ if (url_feof(s->pb)) {
av_log(s, AV_LOG_ERROR, "cannot find FFM syncword\n");
return -1;
}
@@ -121,6 +121,11 @@ static int ffm_read_data(AVFormatContext *s,
if (avio_tell(pb) == ffm->file_size)
avio_seek(pb, ffm->packet_size, SEEK_SET);
retry_read:
+ if (pb->buffer_size != ffm->packet_size) {
+ int64_t tell = avio_tell(pb);
+ url_setbufsize(pb, ffm->packet_size);
+ avio_seek(pb, tell, SEEK_SET);
+ }
id = avio_rb16(pb); /* PACKET_ID */
if (id != PACKET_ID)
if (ffm_resync(s, id) < 0)
@@ -166,7 +171,7 @@ static int ffm_read_data(AVFormatContext *s,
/* ensure that acutal seeking happens between FFM_PACKET_SIZE
and file_size - FFM_PACKET_SIZE */
-static void ffm_seek1(AVFormatContext *s, int64_t pos1)
+static int64_t ffm_seek1(AVFormatContext *s, int64_t pos1)
{
FFMContext *ffm = s->priv_data;
AVIOContext *pb = s->pb;
@@ -175,7 +180,7 @@ static void ffm_seek1(AVFormatContext *s, int64_t pos1)
pos = FFMIN(pos1, ffm->file_size - FFM_PACKET_SIZE);
pos = FFMAX(pos, FFM_PACKET_SIZE);
av_dlog(s, "seek to %"PRIx64" -> %"PRIx64"\n", pos1, pos);
- avio_seek(pb, pos, SEEK_SET);
+ return avio_seek(pb, pos, SEEK_SET);
}
static int64_t get_dts(AVFormatContext *s, int64_t pos)
@@ -290,7 +295,7 @@ static int ffm_read_header(AVFormatContext *s, AVFormatParameters *ap)
for(i=0;i<nb_streams;i++) {
char rc_eq_buf[128];
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
goto fail;
@@ -301,7 +306,6 @@ static int ffm_read_header(AVFormatContext *s, AVFormatParameters *ap)
codec->codec_id = avio_rb32(pb);
codec->codec_type = avio_r8(pb); /* codec_type */
codec->bit_rate = avio_rb32(pb);
- st->quality = avio_rb32(pb);
codec->flags = avio_rb32(pb);
codec->flags2 = avio_rb32(pb);
codec->debug = avio_rb32(pb);
@@ -320,8 +324,7 @@ static int ffm_read_header(AVFormatContext *s, AVFormatParameters *ap)
codec->qcompress = avio_rb16(pb) / 10000.0;
codec->qblur = avio_rb16(pb) / 10000.0;
codec->bit_rate_tolerance = avio_rb32(pb);
- avio_get_str(pb, INT_MAX, rc_eq_buf, sizeof(rc_eq_buf));
- codec->rc_eq = av_strdup(rc_eq_buf);
+ codec->rc_eq = av_strdup(get_strz(pb, rc_eq_buf, sizeof(rc_eq_buf)));
codec->rc_max_rate = avio_rb32(pb);
codec->rc_min_rate = avio_rb32(pb);
codec->rc_buffer_size = avio_rb32(pb);
@@ -463,11 +466,25 @@ static int ffm_seek(AVFormatContext *s, int stream_index, int64_t wanted_pts, in
av_dlog(s, "wanted_pts=%0.6f\n", wanted_pts / 1000000.0);
/* find the position using linear interpolation (better than
dichotomy in typical cases) */
- pos_min = FFM_PACKET_SIZE;
- pos_max = ffm->file_size - FFM_PACKET_SIZE;
+ if (ffm->write_index && ffm->write_index < ffm->file_size) {
+ if (get_dts(s, FFM_PACKET_SIZE) < wanted_pts) {
+ pos_min = FFM_PACKET_SIZE;
+ pos_max = ffm->write_index - FFM_PACKET_SIZE;
+ } else {
+ pos_min = ffm->write_index;
+ pos_max = ffm->file_size - FFM_PACKET_SIZE;
+ }
+ } else {
+ pos_min = FFM_PACKET_SIZE;
+ pos_max = ffm->file_size - FFM_PACKET_SIZE;
+ }
while (pos_min <= pos_max) {
pts_min = get_dts(s, pos_min);
pts_max = get_dts(s, pos_max);
+ if (pts_min > wanted_pts || pts_max < wanted_pts) {
+ pos = pts_min > wanted_pts ? pos_min : pos_max;
+ goto found;
+ }
/* linear interpolation */
pos1 = (double)(pos_max - pos_min) * (double)(wanted_pts - pts_min) /
(double)(pts_max - pts_min);
@@ -489,7 +506,8 @@ static int ffm_seek(AVFormatContext *s, int stream_index, int64_t wanted_pts, in
pos = (flags & AVSEEK_FLAG_BACKWARD) ? pos_min : pos_max;
found:
- ffm_seek1(s, pos);
+ if (ffm_seek1(s, pos) < 0)
+ return -1;
/* reset read state */
ffm->read_state = READ_HEADER;
@@ -510,12 +528,12 @@ static int ffm_probe(AVProbeData *p)
}
AVInputFormat ff_ffm_demuxer = {
- "ffm",
- NULL_IF_CONFIG_SMALL("FFM (FFserver live feed) format"),
- sizeof(FFMContext),
- ffm_probe,
- ffm_read_header,
- ffm_read_packet,
- ffm_close,
- ffm_seek,
+ .name = "ffm",
+ .long_name = NULL_IF_CONFIG_SMALL("FFM (FFserver live feed) format"),
+ .priv_data_size = sizeof(FFMContext),
+ .read_probe = ffm_probe,
+ .read_header = ffm_read_header,
+ .read_packet = ffm_read_packet,
+ .read_close = ffm_close,
+ .read_seek = ffm_seek,
};
diff --git a/libavformat/ffmenc.c b/libavformat/ffmenc.c
index 9a3eb40ad7..99d2e98dbf 100644
--- a/libavformat/ffmenc.c
+++ b/libavformat/ffmenc.c
@@ -2,20 +2,20 @@
* FFM (ffserver live feed) muxer
* Copyright (c) 2001 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -114,7 +114,6 @@ static int ffm_write_header(AVFormatContext *s)
avio_wb32(pb, codec->codec_id);
avio_w8(pb, codec->codec_type);
avio_wb32(pb, codec->bit_rate);
- avio_wb32(pb, st->quality);
avio_wb32(pb, codec->flags);
avio_wb32(pb, codec->flags2);
avio_wb32(pb, codec->debug);
@@ -242,15 +241,14 @@ static int ffm_write_trailer(AVFormatContext *s)
}
AVOutputFormat ff_ffm_muxer = {
- "ffm",
- NULL_IF_CONFIG_SMALL("FFM (FFserver live feed) format"),
- "",
- "ffm",
- sizeof(FFMContext),
- /* not really used */
- CODEC_ID_MP2,
- CODEC_ID_MPEG1VIDEO,
- ffm_write_header,
- ffm_write_packet,
- ffm_write_trailer,
+ .name = "ffm",
+ .long_name = NULL_IF_CONFIG_SMALL("FFM (FFserver live feed) format"),
+ .mime_type = "",
+ .extensions = "ffm",
+ .priv_data_size = sizeof(FFMContext),
+ .audio_codec = CODEC_ID_MP2,
+ .video_codec = CODEC_ID_MPEG1VIDEO,
+ .write_header = ffm_write_header,
+ .write_packet = ffm_write_packet,
+ .write_trailer = ffm_write_trailer,
};
diff --git a/libavformat/ffmeta.h b/libavformat/ffmeta.h
index a5380ca13d..ae8778d614 100644
--- a/libavformat/ffmeta.h
+++ b/libavformat/ffmeta.h
@@ -2,20 +2,20 @@
* Common data for metadata muxer/demuxer
* Copyright (c) 2010 Anton Khirnov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/ffmetadec.c b/libavformat/ffmetadec.c
index 73d3b83ed7..1d223fb9e0 100644
--- a/libavformat/ffmetadec.c
+++ b/libavformat/ffmetadec.c
@@ -2,20 +2,20 @@
* Metadata demuxer
* Copyright (c) 2010 Anton Khirnov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -50,7 +50,7 @@ static void get_line(AVIOContext *s, uint8_t *buf, int size)
buf[i++] = c;
}
buf[i] = 0;
- } while (!s->eof_reached && (buf[0] == ';' || buf[0] == '#' || buf[0] == 0));
+ } while (!url_feof(s) && (buf[0] == ';' || buf[0] == '#' || buf[0] == 0));
}
static AVChapter *read_chapter(AVFormatContext *s)
@@ -75,7 +75,7 @@ static AVChapter *read_chapter(AVFormatContext *s)
end = AV_NOPTS_VALUE;
}
- return ff_new_chapter(s, s->nb_chapters, tb, start, end, NULL);
+ return avpriv_new_chapter(s, s->nb_chapters, tb, start, end, NULL);
}
static uint8_t *unescape(uint8_t *buf, int size)
@@ -128,11 +128,11 @@ static int read_header(AVFormatContext *s, AVFormatParameters *ap)
AVDictionary **m = &s->metadata;
uint8_t line[1024];
- while(!s->pb->eof_reached) {
+ while(!url_feof(s->pb)) {
get_line(s->pb, line, sizeof(line));
if (!memcmp(line, ID_STREAM, strlen(ID_STREAM))) {
- AVStream *st = av_new_stream(s, 0);
+ AVStream *st = avformat_new_stream(s, NULL);
if (!st)
return -1;
diff --git a/libavformat/ffmetaenc.c b/libavformat/ffmetaenc.c
index 0aadb8a9cc..200c9940a4 100644
--- a/libavformat/ffmetaenc.c
+++ b/libavformat/ffmetaenc.c
@@ -2,20 +2,20 @@
* Metadata muxer
* Copyright (c) 2010 Anton Khirnov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/file.c b/libavformat/file.c
index 649640a927..ffbccba0a4 100644
--- a/libavformat/file.c
+++ b/libavformat/file.c
@@ -2,20 +2,20 @@
* Buffered file io for ffmpeg system
* Copyright (c) 2001 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -37,13 +37,15 @@
static int file_read(URLContext *h, unsigned char *buf, int size)
{
int fd = (intptr_t) h->priv_data;
- return read(fd, buf, size);
+ int r = read(fd, buf, size);
+ return (-1 == r)?AVERROR(errno):r;
}
static int file_write(URLContext *h, const unsigned char *buf, int size)
{
int fd = (intptr_t) h->priv_data;
- return write(fd, buf, size);
+ int r = write(fd, buf, size);
+ return (-1 == r)?AVERROR(errno):r;
}
static int file_get_handle(URLContext *h)
diff --git a/libavformat/filmstripdec.c b/libavformat/filmstripdec.c
index 095bf9e809..8aa8ee0dee 100644
--- a/libavformat/filmstripdec.c
+++ b/libavformat/filmstripdec.c
@@ -2,20 +2,20 @@
* Adobe Filmstrip demuxer
* Copyright (c) 2010 Peter Ross
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -49,7 +49,7 @@ static int read_header(AVFormatContext *s,
return AVERROR_INVALIDDATA;
}
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
@@ -80,7 +80,7 @@ static int read_packet(AVFormatContext *s,
FilmstripDemuxContext *film = s->priv_data;
AVStream *st = s->streams[0];
- if (s->pb->eof_reached)
+ if (url_feof(s->pb))
return AVERROR(EIO);
pkt->dts = avio_tell(s->pb) / (st->codec->width * (st->codec->height + film->leading) * 4);
pkt->size = av_get_packet(s->pb, pkt, st->codec->width * st->codec->height * 4);
@@ -94,18 +94,17 @@ static int read_packet(AVFormatContext *s,
static int read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
{
AVStream *st = s->streams[stream_index];
- avio_seek(s->pb, FFMAX(timestamp, 0) * st->codec->width * st->codec->height * 4, SEEK_SET);
+ if (avio_seek(s->pb, FFMAX(timestamp, 0) * st->codec->width * st->codec->height * 4, SEEK_SET) < 0)
+ return -1;
return 0;
}
AVInputFormat ff_filmstrip_demuxer = {
- "filmstrip",
- NULL_IF_CONFIG_SMALL("Adobe Filmstrip"),
- sizeof(FilmstripDemuxContext),
- NULL,
- read_header,
- read_packet,
- NULL,
- read_seek,
+ .name = "filmstrip",
+ .long_name = NULL_IF_CONFIG_SMALL("Adobe Filmstrip"),
+ .priv_data_size = sizeof(FilmstripDemuxContext),
+ .read_header = read_header,
+ .read_packet = read_packet,
+ .read_seek = read_seek,
.extensions = "flm",
};
diff --git a/libavformat/filmstripenc.c b/libavformat/filmstripenc.c
index 21f47550af..3862cb1dba 100644
--- a/libavformat/filmstripenc.c
+++ b/libavformat/filmstripenc.c
@@ -2,20 +2,20 @@
* Adobe Filmstrip muxer
* Copyright (c) 2010 Peter Ross
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -72,14 +72,13 @@ static int write_trailer(AVFormatContext *s)
}
AVOutputFormat ff_filmstrip_muxer = {
- "filmstrip",
- NULL_IF_CONFIG_SMALL("Adobe Filmstrip"),
- NULL,
- "flm",
- sizeof(FilmstripMuxContext),
- CODEC_ID_NONE,
- CODEC_ID_RAWVIDEO,
- write_header,
- write_packet,
- write_trailer,
+ .name = "filmstrip",
+ .long_name = NULL_IF_CONFIG_SMALL("Adobe Filmstrip"),
+ .extensions = "flm",
+ .priv_data_size = sizeof(FilmstripMuxContext),
+ .audio_codec = CODEC_ID_NONE,
+ .video_codec = CODEC_ID_RAWVIDEO,
+ .write_header = write_header,
+ .write_packet = write_packet,
+ .write_trailer = write_trailer,
};
diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c
index 02452b4c7c..a5a32131a7 100644
--- a/libavformat/flacdec.c
+++ b/libavformat/flacdec.c
@@ -2,20 +2,20 @@
* Raw FLAC demuxer
* Copyright (c) 2001 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -31,7 +31,7 @@ static int flac_read_header(AVFormatContext *s,
int ret, metadata_last=0, metadata_type, metadata_size, found_streaminfo=0;
uint8_t header[4];
uint8_t *buffer=NULL;
- AVStream *st = av_new_stream(s, 0);
+ AVStream *st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
@@ -46,9 +46,9 @@ static int flac_read_header(AVFormatContext *s,
}
/* process metadata blocks */
- while (!s->pb->eof_reached && !metadata_last) {
+ while (!url_feof(s->pb) && !metadata_last) {
avio_read(s->pb, header, 4);
- ff_flac_parse_block_header(header, &metadata_last, &metadata_type,
+ avpriv_flac_parse_block_header(header, &metadata_last, &metadata_type,
&metadata_size);
switch (metadata_type) {
/* allocate and read metadata block for supported types */
@@ -87,7 +87,7 @@ static int flac_read_header(AVFormatContext *s,
buffer = NULL;
/* get codec params from STREAMINFO header */
- ff_flac_parse_streaminfo(st->codec, &si, st->codec->extradata);
+ avpriv_flac_parse_streaminfo(st->codec, &si, st->codec->extradata);
/* set time base and duration */
if (si.samplerate > 0) {
@@ -124,12 +124,11 @@ static int flac_probe(AVProbeData *p)
}
AVInputFormat ff_flac_demuxer = {
- "flac",
- NULL_IF_CONFIG_SMALL("raw FLAC"),
- 0,
- flac_probe,
- flac_read_header,
- ff_raw_read_partial_packet,
+ .name = "flac",
+ .long_name = NULL_IF_CONFIG_SMALL("raw FLAC"),
+ .read_probe = flac_probe,
+ .read_header = flac_read_header,
+ .read_packet = ff_raw_read_partial_packet,
.flags= AVFMT_GENERIC_INDEX,
.extensions = "flac",
.value = CODEC_ID_FLAC,
diff --git a/libavformat/flacenc.c b/libavformat/flacenc.c
index fb28a6ed4c..e7bbb783ab 100644
--- a/libavformat/flacenc.c
+++ b/libavformat/flacenc.c
@@ -2,20 +2,20 @@
* raw FLAC muxer
* Copyright (c) 2006-2009 Justin Ruggles
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -94,7 +94,7 @@ static int flac_write_trailer(struct AVFormatContext *s)
enum FLACExtradataFormat format;
int64_t file_size;
- if (!ff_flac_is_extradata_valid(s->streams[0]->codec, &format, &streaminfo))
+ if (!avpriv_flac_is_extradata_valid(s->streams[0]->codec, &format, &streaminfo))
return -1;
if (pb->seekable) {
@@ -118,15 +118,14 @@ static int flac_write_packet(struct AVFormatContext *s, AVPacket *pkt)
}
AVOutputFormat ff_flac_muxer = {
- "flac",
- NULL_IF_CONFIG_SMALL("raw FLAC"),
- "audio/x-flac",
- "flac",
- 0,
- CODEC_ID_FLAC,
- CODEC_ID_NONE,
- flac_write_header,
- flac_write_packet,
- flac_write_trailer,
+ .name = "flac",
+ .long_name = NULL_IF_CONFIG_SMALL("raw FLAC"),
+ .mime_type = "audio/x-flac",
+ .extensions = "flac",
+ .audio_codec = CODEC_ID_FLAC,
+ .video_codec = CODEC_ID_NONE,
+ .write_header = flac_write_header,
+ .write_packet = flac_write_packet,
+ .write_trailer = flac_write_trailer,
.flags= AVFMT_NOTIMESTAMPS,
};
diff --git a/libavformat/flacenc.h b/libavformat/flacenc.h
index 2edda67043..e83ee32aeb 100644
--- a/libavformat/flacenc.h
+++ b/libavformat/flacenc.h
@@ -2,20 +2,20 @@
* raw FLAC muxer
* Copyright (C) 2009 Justin Ruggles
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/flacenc_header.c b/libavformat/flacenc_header.c
index 90c5a776d3..cfbdc890af 100644
--- a/libavformat/flacenc_header.c
+++ b/libavformat/flacenc_header.c
@@ -2,20 +2,20 @@
* raw FLAC muxer
* Copyright (C) 2009 Justin Ruggles
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -34,7 +34,7 @@ int ff_flac_write_header(AVIOContext *pb, AVCodecContext *codec,
enum FLACExtradataFormat format;
header[4] = last_block ? 0x80 : 0x00;
- if (!ff_flac_is_extradata_valid(codec, &format, &streaminfo))
+ if (!avpriv_flac_is_extradata_valid(codec, &format, &streaminfo))
return -1;
/* write "fLaC" stream marker and first metadata block header if needed */
diff --git a/libavformat/flic.c b/libavformat/flic.c
index fcdf4c8040..f4c1a1b9fa 100644
--- a/libavformat/flic.c
+++ b/libavformat/flic.c
@@ -2,20 +2,20 @@
* FLI/FLC Animation File Demuxer
* Copyright (c) 2003 The ffmpeg Project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -105,7 +105,7 @@ static int flic_read_header(AVFormatContext *s,
speed = FLIC_DEFAULT_SPEED;
/* initialize the decoder streams */
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
flic->video_stream_index = st->index;
@@ -117,7 +117,7 @@ static int flic_read_header(AVFormatContext *s,
if (!st->codec->width || !st->codec->height) {
/* Ugly hack needed for the following sample: */
- /* http://samples.libav.org/fli-flc/fli-bugs/specular.flc */
+ /* http://samples.mplayerhq.hu/fli-flc/fli-bugs/specular.flc */
av_log(s, AV_LOG_WARNING,
"File with no specified width/height. Trying 640x480.\n");
st->codec->width = 640;
@@ -145,7 +145,7 @@ static int flic_read_header(AVFormatContext *s,
*/
if (AV_RL16(&preamble[4]) == FLIC_TFTD_CHUNK_AUDIO) {
/* TFTD videos have an extra 22050 Hz 8-bit mono audio stream */
- ast = av_new_stream(s, 1);
+ ast = avformat_new_stream(s, NULL);
if (!ast)
return AVERROR(ENOMEM);
@@ -261,10 +261,10 @@ static int flic_read_packet(AVFormatContext *s,
}
AVInputFormat ff_flic_demuxer = {
- "flic",
- NULL_IF_CONFIG_SMALL("FLI/FLC/FLX animation format"),
- sizeof(FlicDemuxContext),
- flic_probe,
- flic_read_header,
- flic_read_packet,
+ .name = "flic",
+ .long_name = NULL_IF_CONFIG_SMALL("FLI/FLC/FLX animation format"),
+ .priv_data_size = sizeof(FlicDemuxContext),
+ .read_probe = flic_probe,
+ .read_header = flic_read_header,
+ .read_packet = flic_read_packet,
};
diff --git a/libavformat/flv.h b/libavformat/flv.h
index c86e20a7cf..2165357b6b 100644
--- a/libavformat/flv.h
+++ b/libavformat/flv.h
@@ -1,26 +1,30 @@
-/**
- * @file
+/*
* FLV common header
*
- * Copyright (c) 2006 The Libav Project
+ * Copyright (c) 2006 The FFmpeg Project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+/**
+ * @file
+ * FLV common header
+ */
+
#ifndef AVFORMAT_FLV_H
#define AVFORMAT_FLV_H
@@ -42,6 +46,11 @@
#define AMF_END_OF_OBJECT 0x09
+#define KEYFRAMES_TAG "keyframes"
+#define KEYFRAMES_TIMESTAMP_TAG "times"
+#define KEYFRAMES_BYTEOFFSET_TAG "filepositions"
+
+
enum {
FLV_HEADER_FLAG_HASVIDEO = 1,
FLV_HEADER_FLAG_HASAUDIO = 4,
@@ -54,6 +63,12 @@ enum {
};
enum {
+ FLV_STREAM_TYPE_VIDEO,
+ FLV_STREAM_TYPE_AUDIO,
+ FLV_STREAM_TYPE_DATA,
+};
+
+enum {
FLV_MONO = 0,
FLV_STEREO = 1,
};
@@ -89,6 +104,8 @@ enum {
FLV_CODECID_VP6A = 5,
FLV_CODECID_SCREEN2 = 6,
FLV_CODECID_H264 = 7,
+ FLV_CODECID_REALH263= 8,
+ FLV_CODECID_MPEG4 = 9,
};
enum {
diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c
index 3b7db0e6ca..d48d367500 100644
--- a/libavformat/flvdec.c
+++ b/libavformat/flvdec.c
@@ -1,42 +1,39 @@
/*
* FLV demuxer
- * Copyright (c) 2003 The Libav Project
+ * Copyright (c) 2003 The FFmpeg Project
*
* This demuxer will generate a 1 byte extradata for VP6F content.
* It is composed of:
* - upper 4bits: difference between encoded width and visible width
* - lower 4bits: difference between encoded height and visible height
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/avstring.h"
#include "libavutil/dict.h"
#include "libavutil/intfloat_readwrite.h"
+#include "libavutil/mathematics.h"
#include "libavcodec/bytestream.h"
#include "libavcodec/mpeg4audio.h"
#include "avformat.h"
#include "avio_internal.h"
#include "flv.h"
-#define KEYFRAMES_TAG "keyframes"
-#define KEYFRAMES_TIMESTAMP_TAG "times"
-#define KEYFRAMES_BYTEOFFSET_TAG "filepositions"
-
typedef struct {
int wrong_dts; ///< wrong dts due to negative cts
} FLVContext;
@@ -94,6 +91,7 @@ static int flv_set_video_codec(AVFormatContext *s, AVStream *vstream, int flv_co
AVCodecContext *vcodec = vstream->codec;
switch(flv_codecid) {
case FLV_CODECID_H263 : vcodec->codec_id = CODEC_ID_FLV1 ; break;
+ case FLV_CODECID_REALH263: vcodec->codec_id = CODEC_ID_H263 ; break; // Really mean it this time
case FLV_CODECID_SCREEN: vcodec->codec_id = CODEC_ID_FLASHSV; break;
case FLV_CODECID_SCREEN2: vcodec->codec_id = CODEC_ID_FLASHSV2; break;
case FLV_CODECID_VP6 : vcodec->codec_id = CODEC_ID_VP6F ;
@@ -109,6 +107,9 @@ static int flv_set_video_codec(AVFormatContext *s, AVStream *vstream, int flv_co
case FLV_CODECID_H264:
vcodec->codec_id = CODEC_ID_H264;
return 3; // not 4, reading packet type will consume one byte
+ case FLV_CODECID_MPEG4:
+ vcodec->codec_id = CODEC_ID_MPEG4;
+ return 3;
default:
av_log(s, AV_LOG_INFO, "Unsupported video codec (%x)\n", flv_codecid);
vcodec->codec_tag = flv_codecid;
@@ -132,48 +133,55 @@ static int amf_get_string(AVIOContext *ioc, char *buffer, int buffsize) {
}
static int parse_keyframes_index(AVFormatContext *s, AVIOContext *ioc, AVStream *vstream, int64_t max_pos) {
- unsigned int arraylen = 0, timeslen = 0, fileposlen = 0, i;
- double num_val;
+ unsigned int timeslen = 0, fileposlen = 0, i;
char str_val[256];
int64_t *times = NULL;
int64_t *filepositions = NULL;
int ret = AVERROR(ENOSYS);
int64_t initial_pos = avio_tell(ioc);
+ AVDictionaryEntry *creator = av_dict_get(s->metadata, "metadatacreator",
+ NULL, 0);
+
+ if (creator && !strcmp(creator->value, "MEGA")) {
+ /* Files with this metadatacreator tag seem to have filepositions
+ * pointing at the 4 trailer bytes of the previous packet,
+ * which isn't the norm (nor what we expect here, nor what
+ * jwplayer + lighttpd expect, nor what flvtool2 produces).
+ * Just ignore the index in this case, instead of risking trying
+ * to adjust it to something that might or might not work. */
+ return 0;
+ }
while (avio_tell(ioc) < max_pos - 2 && amf_get_string(ioc, str_val, sizeof(str_val)) > 0) {
- int64_t* current_array;
+ int64_t** current_array;
+ unsigned int arraylen;
// Expect array object in context
if (avio_r8(ioc) != AMF_DATA_TYPE_ARRAY)
break;
arraylen = avio_rb32(ioc);
- /*
- * Expect only 'times' or 'filepositions' sub-arrays in other case refuse to use such metadata
- * for indexing
- */
- if (!strcmp(KEYFRAMES_TIMESTAMP_TAG, str_val) && !times) {
- if (!(times = av_mallocz(sizeof(*times) * arraylen))) {
- ret = AVERROR(ENOMEM);
- goto finish;
- }
- timeslen = arraylen;
- current_array = times;
- } else if (!strcmp(KEYFRAMES_BYTEOFFSET_TAG, str_val) && !filepositions) {
- if (!(filepositions = av_mallocz(sizeof(*filepositions) * arraylen))) {
- ret = AVERROR(ENOMEM);
- goto finish;
- }
- fileposlen = arraylen;
- current_array = filepositions;
- } else // unexpected metatag inside keyframes, will not use such metadata for indexing
+ if(arraylen>>28)
break;
+ if (!strcmp(KEYFRAMES_TIMESTAMP_TAG , str_val) && !times){
+ current_array= &times;
+ timeslen= arraylen;
+ }else if (!strcmp(KEYFRAMES_BYTEOFFSET_TAG, str_val) && !filepositions){
+ current_array= &filepositions;
+ fileposlen= arraylen;
+ }else // unexpected metatag inside keyframes, will not use such metadata for indexing
+ break;
+
+ if (!(*current_array = av_mallocz(sizeof(**current_array) * arraylen))) {
+ ret = AVERROR(ENOMEM);
+ goto finish;
+ }
+
for (i = 0; i < arraylen && avio_tell(ioc) < max_pos - 1; i++) {
if (avio_r8(ioc) != AMF_DATA_TYPE_NUMBER)
goto finish;
- num_val = av_int2dbl(avio_rb64(ioc));
- current_array[i] = num_val;
+ current_array[0][i] = av_int2dbl(avio_rb64(ioc));
}
if (times && filepositions) {
// All done, exiting at a position allowing amf_parse_object
@@ -183,19 +191,16 @@ static int parse_keyframes_index(AVFormatContext *s, AVIOContext *ioc, AVStream
}
}
- if (timeslen == fileposlen)
- for(i = 0; i < arraylen; i++)
+ if (timeslen == fileposlen) {
+ for(i = 0; i < timeslen; i++)
av_add_index_entry(vstream, filepositions[i], times[i]*1000, 0, 0, AVINDEX_KEYFRAME);
- else
+ } else
av_log(s, AV_LOG_WARNING, "Invalid keyframes object, skipping.\n");
finish:
av_freep(&times);
av_freep(&filepositions);
- // If we got unexpected data, but successfully reset back to
- // the start pos, the caller can continue parsing
- if (ret < 0 && avio_seek(ioc, initial_pos, SEEK_SET) > 0)
- return 0;
+ avio_seek(ioc, initial_pos, SEEK_SET);
return ret;
}
@@ -223,9 +228,10 @@ static int amf_parse_object(AVFormatContext *s, AVStream *astream, AVStream *vst
case AMF_DATA_TYPE_OBJECT: {
unsigned int keylen;
- if (key && !strcmp(KEYFRAMES_TAG, key) && depth == 1)
- if (parse_keyframes_index(s, ioc, vstream, max_pos) < 0)
- return -1;
+ if ((vstream || astream) && ioc->seekable && key && !strcmp(KEYFRAMES_TAG, key) && depth == 1)
+ if (parse_keyframes_index(s, ioc, vstream ? vstream : astream,
+ max_pos) < 0)
+ av_log(s, AV_LOG_ERROR, "Keyframe index parsing failed\n");
while(avio_tell(ioc) < max_pos - 2 && (keylen = avio_rb16(ioc))) {
avio_skip(ioc, keylen); //skip key string
@@ -271,17 +277,39 @@ static int amf_parse_object(AVFormatContext *s, AVStream *astream, AVStream *vst
acodec = astream ? astream->codec : NULL;
vcodec = vstream ? vstream->codec : NULL;
+ if (amf_type == AMF_DATA_TYPE_NUMBER) {
+ if (!strcmp(key, "duration"))
+ s->duration = num_val * AV_TIME_BASE;
+ else if (!strcmp(key, "videodatarate") && vcodec && 0 <= (int)(num_val * 1024.0))
+ vcodec->bit_rate = num_val * 1024.0;
+ else if (!strcmp(key, "audiodatarate") && acodec && 0 <= (int)(num_val * 1024.0))
+ acodec->bit_rate = num_val * 1024.0;
+ }
+
+ if (!strcmp(key, "duration") ||
+ !strcmp(key, "filesize") ||
+ !strcmp(key, "width") ||
+ !strcmp(key, "height") ||
+ !strcmp(key, "videodatarate") ||
+ !strcmp(key, "framerate") ||
+ !strcmp(key, "videocodecid") ||
+ !strcmp(key, "audiodatarate") ||
+ !strcmp(key, "audiosamplerate") ||
+ !strcmp(key, "audiosamplesize") ||
+ !strcmp(key, "stereo") ||
+ !strcmp(key, "audiocodecid"))
+ return 0;
+
if(amf_type == AMF_DATA_TYPE_BOOL) {
av_strlcpy(str_val, num_val > 0 ? "true" : "false", sizeof(str_val));
av_dict_set(&s->metadata, key, str_val, 0);
} else if(amf_type == AMF_DATA_TYPE_NUMBER) {
snprintf(str_val, sizeof(str_val), "%.f", num_val);
av_dict_set(&s->metadata, key, str_val, 0);
- if(!strcmp(key, "duration")) s->duration = num_val * AV_TIME_BASE;
- else if(!strcmp(key, "videodatarate") && vcodec && 0 <= (int)(num_val * 1024.0))
- vcodec->bit_rate = num_val * 1024.0;
- else if(!strcmp(key, "audiodatarate") && acodec && 0 <= (int)(num_val * 1024.0))
- acodec->bit_rate = num_val * 1024.0;
+ } else if(amf_type == AMF_DATA_TYPE_OBJECT){
+ if(s->nb_streams==1 && ((!acodec && !strcmp(key, "audiocodecid")) || (!vcodec && !strcmp(key, "videocodecid")))){
+ s->ctx_flags &= ~AVFMTCTX_NOHEADER; //If there is either audio/video missing, codecid will be an empty object
+ }
} else if (amf_type == AMF_DATA_TYPE_STRING)
av_dict_set(&s->metadata, key, str_val, 0);
}
@@ -291,13 +319,12 @@ static int amf_parse_object(AVFormatContext *s, AVStream *astream, AVStream *vst
static int flv_read_metabody(AVFormatContext *s, int64_t next_pos) {
AMFDataType type;
- AVStream *stream, *astream, *vstream;
+ AVStream *stream, *astream, *vstream, *dstream;
AVIOContext *ioc;
int i;
char buffer[11]; //only needs to hold the string "onMetaData". Anything longer is something we don't want.
- astream = NULL;
- vstream = NULL;
+ vstream = astream = dstream = NULL;
ioc = s->pb;
//first object needs to be "onMetaData" string
@@ -308,8 +335,9 @@ static int flv_read_metabody(AVFormatContext *s, int64_t next_pos) {
//find the streams now so that amf_parse_object doesn't need to do the lookup every time it is called.
for(i = 0; i < s->nb_streams; i++) {
stream = s->streams[i];
- if (stream->codec->codec_type == AVMEDIA_TYPE_AUDIO) astream = stream;
- else if(stream->codec->codec_type == AVMEDIA_TYPE_VIDEO) vstream = stream;
+ if(stream->codec->codec_type == AVMEDIA_TYPE_VIDEO) vstream = stream;
+ else if(stream->codec->codec_type == AVMEDIA_TYPE_AUDIO) astream = stream;
+ else if(stream->codec->codec_type == AVMEDIA_TYPE_VIDEO) dstream = stream;
}
//parse the second object (we want a mixed array)
@@ -319,11 +347,19 @@ static int flv_read_metabody(AVFormatContext *s, int64_t next_pos) {
return 0;
}
-static AVStream *create_stream(AVFormatContext *s, int is_audio){
- AVStream *st = av_new_stream(s, is_audio);
+static AVStream *create_stream(AVFormatContext *s, int stream_type){
+ AVStream *st = avformat_new_stream(s, NULL);
if (!st)
return NULL;
- st->codec->codec_type = is_audio ? AVMEDIA_TYPE_AUDIO : AVMEDIA_TYPE_VIDEO;
+ st->id = stream_type;
+ switch(stream_type) {
+ case FLV_STREAM_TYPE_VIDEO: st->codec->codec_type = AVMEDIA_TYPE_VIDEO; break;
+ case FLV_STREAM_TYPE_AUDIO: st->codec->codec_type = AVMEDIA_TYPE_AUDIO; break;
+ case FLV_STREAM_TYPE_DATA:
+ st->codec->codec_type = AVMEDIA_TYPE_DATA;
+ st->codec->codec_id = CODEC_ID_NONE; // Going to rely on copy for now
+ av_log(s, AV_LOG_DEBUG, "Data stream created\n");
+ }
av_set_pts_info(st, 32, 1, 1000); /* 32 bit pts in ms */
return st;
}
@@ -347,13 +383,15 @@ static int flv_read_header(AVFormatContext *s,
s->ctx_flags |= AVFMTCTX_NOHEADER;
if(flags & FLV_HEADER_FLAG_HASVIDEO){
- if(!create_stream(s, 0))
+ if(!create_stream(s, FLV_STREAM_TYPE_VIDEO))
return AVERROR(ENOMEM);
}
if(flags & FLV_HEADER_FLAG_HASAUDIO){
- if(!create_stream(s, 1))
+ if(!create_stream(s, FLV_STREAM_TYPE_AUDIO))
return AVERROR(ENOMEM);
}
+ // Flag doesn't indicate whether or not there is script-data present. Must
+ // create that stream if it's encountered.
offset = avio_rb32(s->pb);
avio_seek(s->pb, offset, SEEK_SET);
@@ -378,7 +416,8 @@ static int flv_get_extradata(AVFormatContext *s, AVStream *st, int size)
static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)
{
FLVContext *flv = s->priv_data;
- int ret, i, type, size, flags, is_audio;
+ int ret, i, type, size, flags;
+ int stream_type=-1;
int64_t next, pos;
int64_t dts, pts = AV_NOPTS_VALUE;
AVStream *st = NULL;
@@ -390,7 +429,7 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)
dts = avio_rb24(s->pb);
dts |= avio_r8(s->pb) << 24;
av_dlog(s, "type:%d, size:%d, dts:%"PRId64"\n", type, size, dts);
- if (s->pb->eof_reached)
+ if (url_feof(s->pb))
return AVERROR_EOF;
avio_skip(s->pb, 3); /* stream id, always 0 */
flags = 0;
@@ -401,20 +440,26 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)
next= size + avio_tell(s->pb);
if (type == FLV_TAG_TYPE_AUDIO) {
- is_audio=1;
+ stream_type=FLV_STREAM_TYPE_AUDIO;
flags = avio_r8(s->pb);
size--;
} else if (type == FLV_TAG_TYPE_VIDEO) {
- is_audio=0;
+ stream_type=FLV_STREAM_TYPE_VIDEO;
flags = avio_r8(s->pb);
size--;
if ((flags & 0xf0) == 0x50) /* video info / command frame */
goto skip;
- } else {
- if (type == FLV_TAG_TYPE_META && size > 13+1+4)
+ } else if (type == FLV_TAG_TYPE_META) {
+ if (size > 13+1+4 && dts == 0) { // Header-type metadata stuff
flv_read_metabody(s, next);
- else /* skip packet */
- av_log(s, AV_LOG_DEBUG, "skipping flv packet: type %d, size %d, flags %d\n", type, size, flags);
+ goto skip;
+ } else if (dts != 0) { // Script-data "special" metadata frames - don't skip
+ stream_type=FLV_STREAM_TYPE_DATA;
+ } else {
+ goto skip;
+ }
+ } else {
+ av_log(s, AV_LOG_DEBUG, "skipping flv packet: type %d, size %d, flags %d\n", type, size, flags);
skip:
avio_seek(s->pb, next, SEEK_SET);
continue;
@@ -427,17 +472,17 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)
/* now find stream */
for(i=0;i<s->nb_streams;i++) {
st = s->streams[i];
- if (st->id == is_audio)
+ if (st->id == stream_type)
break;
}
if(i == s->nb_streams){
- av_log(s, AV_LOG_ERROR, "invalid stream\n");
- st= create_stream(s, is_audio);
+ av_log(s, AV_LOG_WARNING, "Stream discovered after head already parsed\n");
+ st= create_stream(s, stream_type);
s->ctx_flags &= ~AVFMTCTX_NOHEADER;
}
- av_dlog(s, "%d %X %d \n", is_audio, flags, st->discard);
- if( (st->discard >= AVDISCARD_NONKEY && !((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY || is_audio))
- ||(st->discard >= AVDISCARD_BIDIR && ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_DISP_INTER && !is_audio))
+ av_dlog(s, "%d %X %d \n", stream_type, flags, st->discard);
+ if( (st->discard >= AVDISCARD_NONKEY && !((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY || (stream_type == FLV_STREAM_TYPE_AUDIO)))
+ ||(st->discard >= AVDISCARD_BIDIR && ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_DISP_INTER && (stream_type == FLV_STREAM_TYPE_VIDEO)))
|| st->discard >= AVDISCARD_ALL
){
avio_seek(s->pb, next, SEEK_SET);
@@ -464,7 +509,7 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)
avio_seek(s->pb, pos, SEEK_SET);
}
- if(is_audio){
+ if(stream_type == FLV_STREAM_TYPE_AUDIO){
if(!st->codec->channels || !st->codec->sample_rate || !st->codec->bits_per_coded_sample) {
st->codec->channels = (flags & FLV_AUDIO_CHANNEL_MASK) == FLV_STEREO ? 2 : 1;
st->codec->sample_rate = (44100 << ((flags & FLV_AUDIO_SAMPLERATE_MASK) >> FLV_AUDIO_SAMPLERATE_OFFSET) >> 3);
@@ -473,15 +518,16 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)
if(!st->codec->codec_id){
flv_set_audio_codec(s, st, flags & FLV_AUDIO_CODECID_MASK);
}
- }else{
+ } else if(stream_type == FLV_STREAM_TYPE_VIDEO) {
size -= flv_set_video_codec(s, st, flags & FLV_VIDEO_CODECID_MASK);
}
if (st->codec->codec_id == CODEC_ID_AAC ||
- st->codec->codec_id == CODEC_ID_H264) {
+ st->codec->codec_id == CODEC_ID_H264 ||
+ st->codec->codec_id == CODEC_ID_MPEG4) {
int type = avio_r8(s->pb);
size--;
- if (st->codec->codec_id == CODEC_ID_H264) {
+ if (st->codec->codec_id == CODEC_ID_H264 || st->codec->codec_id == CODEC_ID_MPEG4) {
int32_t cts = (avio_rb24(s->pb)+0xff800000)^0xff800000; // sign extension
pts = dts + cts;
if (cts < 0) { // dts are wrong
@@ -491,12 +537,13 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)
if (flv->wrong_dts)
dts = AV_NOPTS_VALUE;
}
- if (type == 0) {
+
+ if (type == 0 && !st->codec->extradata) {
if ((ret = flv_get_extradata(s, st, size)) < 0)
return ret;
if (st->codec->codec_id == CODEC_ID_AAC) {
MPEG4AudioConfig cfg;
- ff_mpeg4audio_get_config(&cfg, st->codec->extradata,
+ avpriv_mpeg4audio_get_config(&cfg, st->codec->extradata,
st->codec->extradata_size);
st->codec->channels = cfg.channels;
if (cfg.ext_sample_rate)
@@ -529,7 +576,9 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)
pkt->pts = pts == AV_NOPTS_VALUE ? dts : pts;
pkt->stream_index = st->index;
- if (is_audio || ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY))
+ if ( stream_type == FLV_STREAM_TYPE_AUDIO ||
+ ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY) ||
+ stream_type == FLV_STREAM_TYPE_DATA)
pkt->flags |= AV_PKT_FLAG_KEY;
leave:
@@ -571,12 +620,12 @@ static int flv_read_seek2(AVFormatContext *s, int stream_index,
#endif
AVInputFormat ff_flv_demuxer = {
- "flv",
- NULL_IF_CONFIG_SMALL("FLV format"),
- sizeof(FLVContext),
- flv_probe,
- flv_read_header,
- flv_read_packet,
+ .name = "flv",
+ .long_name = NULL_IF_CONFIG_SMALL("FLV format"),
+ .priv_data_size = sizeof(FLVContext),
+ .read_probe = flv_probe,
+ .read_header = flv_read_header,
+ .read_packet = flv_read_packet,
.read_seek = flv_read_seek,
#if 0
.read_seek2 = flv_read_seek2,
diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c
index a3e7e25692..627bb6d3ab 100644
--- a/libavformat/flvenc.c
+++ b/libavformat/flvenc.c
@@ -1,24 +1,25 @@
/*
* FLV muxer
- * Copyright (c) 2003 The Libav Project
+ * Copyright (c) 2003 The FFmpeg Project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include "libavutil/intreadwrite.h"
#include "libavutil/intfloat_readwrite.h"
#include "avformat.h"
#include "flv.h"
@@ -32,6 +33,8 @@
static const AVCodecTag flv_video_codec_ids[] = {
{CODEC_ID_FLV1, FLV_CODECID_H263 },
+ {CODEC_ID_H263, FLV_CODECID_REALH263},
+ {CODEC_ID_MPEG4, FLV_CODECID_MPEG4 },
{CODEC_ID_FLASHSV, FLV_CODECID_SCREEN},
{CODEC_ID_FLASHSV2, FLV_CODECID_SCREEN2},
{CODEC_ID_VP6F, FLV_CODECID_VP6 },
@@ -57,10 +60,13 @@ typedef struct FLVContext {
int64_t duration_offset;
int64_t filesize_offset;
int64_t duration;
- int delay; ///< first dts delay for AVC
- int64_t last_video_ts;
} FLVContext;
+typedef struct FLVStreamContext {
+ int delay; ///< first dts delay for each stream (needed for AVC & Speex)
+ int64_t last_ts; ///< last timestamp for each stream
+} FLVStreamContext;
+
static int get_audio_flags(AVCodecContext *enc){
int flags = (enc->bits_per_coded_sample == 16) ? FLV_SAMPLESSIZE_16BIT : FLV_SAMPLESSIZE_8BIT;
@@ -75,11 +81,6 @@ static int get_audio_flags(AVCodecContext *enc){
av_log(enc, AV_LOG_ERROR, "flv only supports mono Speex audio\n");
return -1;
}
- if (enc->frame_size / 320 > 8) {
- av_log(enc, AV_LOG_WARNING, "Warning: Speex stream has more than "
- "8 frames per packet. Adobe Flash "
- "Player cannot handle this!\n");
- }
return FLV_CODECID_SPEEX | FLV_SAMPLERATE_11025HZ | FLV_SAMPLESSIZE_16BIT;
} else {
switch (enc->sample_rate) {
@@ -177,13 +178,14 @@ static int flv_write_header(AVFormatContext *s)
AVIOContext *pb = s->pb;
FLVContext *flv = s->priv_data;
AVCodecContext *audio_enc = NULL, *video_enc = NULL;
- int i;
+ int i, metadata_count = 0;
double framerate = 0.0;
- int metadata_size_pos, data_size;
+ int64_t metadata_size_pos, data_size, metadata_count_pos;
AVDictionaryEntry *tag = NULL;
for(i=0; i<s->nb_streams; i++){
AVCodecContext *enc = s->streams[i]->codec;
+ FLVStreamContext *sc;
if (enc->codec_type == AVMEDIA_TYPE_VIDEO) {
if (s->streams[i]->r_frame_rate.den && s->streams[i]->r_frame_rate.num) {
framerate = av_q2d(s->streams[i]->r_frame_rate);
@@ -195,12 +197,18 @@ static int flv_write_header(AVFormatContext *s)
av_log(enc, AV_LOG_ERROR, "video codec not compatible with flv\n");
return -1;
}
- } else {
+ } else if (enc->codec_type == AVMEDIA_TYPE_AUDIO) {
audio_enc = enc;
if(get_audio_flags(enc)<0)
return -1;
}
av_set_pts_info(s->streams[i], 32, 1, 1000); /* 32 bit pts in ms */
+
+ sc = av_mallocz(sizeof(FLVStreamContext));
+ if (!sc)
+ return AVERROR(ENOMEM);
+ s->streams[i]->priv_data = sc;
+ sc->last_ts = -1;
}
avio_write(pb, "FLV", 3);
avio_w8(pb,1);
@@ -220,8 +228,6 @@ static int flv_write_header(AVFormatContext *s)
}
}
- flv->last_video_ts = -1;
-
/* write meta_tag */
avio_w8(pb, 18); // tag type META
metadata_size_pos= avio_tell(pb);
@@ -237,7 +243,9 @@ static int flv_write_header(AVFormatContext *s)
/* mixed array (hash) with size and string/type/data tuples */
avio_w8(pb, AMF_DATA_TYPE_MIXEDARRAY);
- avio_wb32(pb, 5*!!video_enc + 5*!!audio_enc + 2); // +2 for duration and file size
+ metadata_count_pos = avio_tell(pb);
+ metadata_count = 5*!!video_enc + 5*!!audio_enc + 2; // +2 for duration and file size
+ avio_wb32(pb, metadata_count);
put_amf_string(pb, "duration");
flv->duration_offset= avio_tell(pb);
@@ -278,9 +286,26 @@ static int flv_write_header(AVFormatContext *s)
}
while ((tag = av_dict_get(s->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) {
+ if( !strcmp(tag->key, "width")
+ ||!strcmp(tag->key, "height")
+ ||!strcmp(tag->key, "videodatarate")
+ ||!strcmp(tag->key, "framerate")
+ ||!strcmp(tag->key, "videocodecid")
+ ||!strcmp(tag->key, "audiodatarate")
+ ||!strcmp(tag->key, "audiosamplerate")
+ ||!strcmp(tag->key, "audiosamplesize")
+ ||!strcmp(tag->key, "stereo")
+ ||!strcmp(tag->key, "audiocodecid")
+ ||!strcmp(tag->key, "duration")
+ ||!strcmp(tag->key, "onMetaData")
+ ){
+ av_log(s, AV_LOG_DEBUG, "ignoring metadata for %s\n", tag->key);
+ continue;
+ }
put_amf_string(pb, tag->key);
avio_w8(pb, AMF_DATA_TYPE_STRING);
put_amf_string(pb, tag->value);
+ metadata_count++;
}
put_amf_string(pb, "filesize");
@@ -292,6 +317,10 @@ static int flv_write_header(AVFormatContext *s)
/* write total size of tag */
data_size= avio_tell(pb) - metadata_size_pos - 10;
+
+ avio_seek(pb, metadata_count_pos, SEEK_SET);
+ avio_wb32(pb, metadata_count);
+
avio_seek(pb, metadata_size_pos, SEEK_SET);
avio_wb24(pb, data_size);
avio_skip(pb, data_size + 10 - 3);
@@ -299,7 +328,7 @@ static int flv_write_header(AVFormatContext *s)
for (i = 0; i < s->nb_streams; i++) {
AVCodecContext *enc = s->streams[i]->codec;
- if (enc->codec_id == CODEC_ID_AAC || enc->codec_id == CODEC_ID_H264) {
+ if (enc->codec_id == CODEC_ID_AAC || enc->codec_id == CODEC_ID_H264 || enc->codec_id == CODEC_ID_MPEG4) {
int64_t pos;
avio_w8(pb, enc->codec_type == AVMEDIA_TYPE_VIDEO ?
FLV_TAG_TYPE_VIDEO : FLV_TAG_TYPE_AUDIO);
@@ -340,9 +369,10 @@ static int flv_write_trailer(AVFormatContext *s)
/* Add EOS tag */
for (i = 0; i < s->nb_streams; i++) {
AVCodecContext *enc = s->streams[i]->codec;
+ FLVStreamContext *sc = s->streams[i]->priv_data;
if (enc->codec_type == AVMEDIA_TYPE_VIDEO &&
- enc->codec_id == CODEC_ID_H264) {
- put_avc_eos_tag(pb, flv->last_video_ts);
+ (enc->codec_id == CODEC_ID_H264 || enc->codec_id == CODEC_ID_MPEG4)) {
+ put_avc_eos_tag(pb, sc->last_ts);
}
}
@@ -363,6 +393,7 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt)
AVIOContext *pb = s->pb;
AVCodecContext *enc = s->streams[pkt->stream_index]->codec;
FLVContext *flv = s->priv_data;
+ FLVStreamContext *sc = s->streams[pkt->stream_index]->priv_data;
unsigned ts;
int size= pkt->size;
uint8_t *data= NULL;
@@ -373,7 +404,7 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt)
if(enc->codec_id == CODEC_ID_VP6 || enc->codec_id == CODEC_ID_VP6F ||
enc->codec_id == CODEC_ID_AAC)
flags_size= 2;
- else if(enc->codec_id == CODEC_ID_H264)
+ else if(enc->codec_id == CODEC_ID_H264 || enc->codec_id == CODEC_ID_MPEG4)
flags_size= 5;
else
flags_size= 1;
@@ -383,47 +414,66 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt)
flags = enc->codec_tag;
if(flags == 0) {
- av_log(enc, AV_LOG_ERROR, "video codec %X not compatible with flv\n",enc->codec_id);
+ av_log(enc, AV_LOG_ERROR, "video codec %s not compatible with flv\n", avcodec_get_name(enc->codec_id));
return -1;
}
flags |= pkt->flags & AV_PKT_FLAG_KEY ? FLV_FRAME_KEY : FLV_FRAME_INTER;
- } else {
- assert(enc->codec_type == AVMEDIA_TYPE_AUDIO);
+ } else if (enc->codec_type == AVMEDIA_TYPE_AUDIO) {
flags = get_audio_flags(enc);
assert(size);
avio_w8(pb, FLV_TAG_TYPE_AUDIO);
+ } else {
+ // In-band flv metadata ("scriptdata")
+ assert(enc->codec_type == AVMEDIA_TYPE_DATA);
+ avio_w8(pb, FLV_TAG_TYPE_META);
+ flags_size = 0;
+ flags = NULL;
}
- if (enc->codec_id == CODEC_ID_H264) {
+ if (enc->codec_id == CODEC_ID_H264 || enc->codec_id == CODEC_ID_MPEG4) {
/* check if extradata looks like mp4 formated */
if (enc->extradata_size > 0 && *(uint8_t*)enc->extradata != 1) {
if (ff_avc_parse_nal_units_buf(pkt->data, &data, &size) < 0)
return -1;
}
- if (!flv->delay && pkt->dts < 0)
- flv->delay = -pkt->dts;
+ } else if (enc->codec_id == CODEC_ID_AAC && pkt->size > 2 &&
+ (AV_RB16(pkt->data) & 0xfff0) == 0xfff0) {
+ av_log(s, AV_LOG_ERROR, "malformated aac bitstream, use -absf aac_adtstoasc\n");
+ return -1;
}
+ if (!sc->delay && pkt->dts < 0)
+ sc->delay = -pkt->dts;
- ts = pkt->dts + flv->delay; // add delay to force positive dts
- if (enc->codec_type == AVMEDIA_TYPE_VIDEO) {
- if (flv->last_video_ts < ts)
- flv->last_video_ts = ts;
+ ts = pkt->dts + sc->delay; // add delay to force positive dts
+
+ /* check Speex packet duration */
+ if (enc->codec_id == CODEC_ID_SPEEX && ts - sc->last_ts > 160) {
+ av_log(s, AV_LOG_WARNING, "Warning: Speex stream has more than "
+ "8 frames per packet. Adobe Flash "
+ "Player cannot handle this!\n");
}
+
+ if (sc->last_ts < ts)
+ sc->last_ts = ts;
+
avio_wb24(pb,size + flags_size);
avio_wb24(pb,ts);
avio_w8(pb,(ts >> 24) & 0x7F); // timestamps are 32bits _signed_
avio_wb24(pb,flv->reserved);
- avio_w8(pb,flags);
+
+ if(flags_size)
+ avio_w8(pb,flags);
+
if (enc->codec_id == CODEC_ID_VP6)
avio_w8(pb,0);
if (enc->codec_id == CODEC_ID_VP6F)
avio_w8(pb, enc->extradata_size ? enc->extradata[0] : 0);
else if (enc->codec_id == CODEC_ID_AAC)
avio_w8(pb,1); // AAC raw
- else if (enc->codec_id == CODEC_ID_H264) {
+ else if (enc->codec_id == CODEC_ID_H264 || enc->codec_id == CODEC_ID_MPEG4) {
avio_w8(pb,1); // AVC NALU
avio_wb24(pb,pkt->pts - pkt->dts);
}
@@ -431,7 +481,7 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt)
avio_write(pb, data ? data : pkt->data, size);
avio_wb32(pb,size+flags_size+11); // previous tag size
- flv->duration = FFMAX(flv->duration, pkt->pts + flv->delay + pkt->duration);
+ flv->duration = FFMAX(flv->duration, pkt->pts + sc->delay + pkt->duration);
avio_flush(pb);
@@ -441,20 +491,20 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt)
}
AVOutputFormat ff_flv_muxer = {
- "flv",
- NULL_IF_CONFIG_SMALL("FLV format"),
- "video/x-flv",
- "flv",
- sizeof(FLVContext),
+ .name = "flv",
+ .long_name = NULL_IF_CONFIG_SMALL("FLV format"),
+ .mime_type = "video/x-flv",
+ .extensions = "flv",
+ .priv_data_size = sizeof(FLVContext),
#if CONFIG_LIBMP3LAME
- CODEC_ID_MP3,
+ .audio_codec = CODEC_ID_MP3,
#else // CONFIG_LIBMP3LAME
- CODEC_ID_ADPCM_SWF,
+ .audio_codec = CODEC_ID_ADPCM_SWF,
#endif // CONFIG_LIBMP3LAME
- CODEC_ID_FLV1,
- flv_write_header,
- flv_write_packet,
- flv_write_trailer,
+ .video_codec = CODEC_ID_FLV1,
+ .write_header = flv_write_header,
+ .write_packet = flv_write_packet,
+ .write_trailer = flv_write_trailer,
.codec_tag= (const AVCodecTag* const []){flv_video_codec_ids, flv_audio_codec_ids, 0},
.flags= AVFMT_GLOBALHEADER | AVFMT_VARIABLE_FPS,
};
diff --git a/libavformat/framecrcenc.c b/libavformat/framecrcenc.c
index 2bd3f547d3..65ca670bbd 100644
--- a/libavformat/framecrcenc.c
+++ b/libavformat/framecrcenc.c
@@ -2,20 +2,20 @@
* frame CRC encoder (for codec/format testing)
* Copyright (c) 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -34,14 +34,10 @@ static int framecrc_write_packet(struct AVFormatContext *s, AVPacket *pkt)
}
AVOutputFormat ff_framecrc_muxer = {
- "framecrc",
- NULL_IF_CONFIG_SMALL("framecrc testing format"),
- NULL,
- "",
- 0,
- CODEC_ID_PCM_S16LE,
- CODEC_ID_RAWVIDEO,
- NULL,
- framecrc_write_packet,
- NULL,
+ .name = "framecrc",
+ .long_name = NULL_IF_CONFIG_SMALL("framecrc testing format"),
+ .extensions = "",
+ .audio_codec = CODEC_ID_PCM_S16LE,
+ .video_codec = CODEC_ID_RAWVIDEO,
+ .write_packet = framecrc_write_packet,
};
diff --git a/libavformat/g723_1.c b/libavformat/g723_1.c
new file mode 100644
index 0000000000..19441a1b19
--- /dev/null
+++ b/libavformat/g723_1.c
@@ -0,0 +1,83 @@
+/*
+ * G.723.1 demuxer
+ * Copyright (c) 2010 Mohamed Naufal Basheer
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * G.723.1 demuxer
+ */
+
+#include "avformat.h"
+
+static const uint8_t frame_size[4] = {24, 20, 4, 1};
+
+static int g723_1_init(AVFormatContext *s, AVFormatParameters *ap)
+{
+ AVStream *st;
+
+ st = av_new_stream(s, 0);
+ if (!st)
+ return AVERROR(ENOMEM);
+
+ st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
+ st->codec->codec_id = CODEC_ID_G723_1;
+ st->codec->channels = 1;
+ st->codec->sample_rate = 8000;
+
+ av_set_pts_info(st, 64, 1, st->codec->sample_rate);
+
+ return 0;
+}
+
+static int g723_1_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ int size, byte, ret;
+
+ pkt->pos = url_ftell(s->pb);
+ byte = get_byte(s->pb);
+ size = frame_size[byte & 3];
+
+ ret = av_new_packet(pkt, size);
+ if (ret < 0)
+ return ret;
+
+ pkt->data[0] = byte;
+ pkt->duration = 240;
+ pkt->stream_index = 0;
+
+ ret = get_buffer(s->pb, pkt->data + 1, size - 1);
+ if (ret < size - 1) {
+ av_free_packet(pkt);
+ return ret < 0 ? ret : AVERROR_EOF;
+ }
+
+ return pkt->size;
+}
+
+AVInputFormat ff_g723_1_demuxer = {
+ "g723_1",
+ NULL_IF_CONFIG_SMALL("G.723.1 format"),
+ 0,
+ NULL,
+ g723_1_init,
+ g723_1_read_packet,
+ .extensions = "tco,rco",
+ .flags = AVFMT_GENERIC_INDEX
+};
diff --git a/libavformat/gif.c b/libavformat/gif.c
index 55deb4d207..200bc70573 100644
--- a/libavformat/gif.c
+++ b/libavformat/gif.c
@@ -2,20 +2,20 @@
* Animated GIF muxer
* Copyright (c) 2000 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -40,6 +40,8 @@
*/
#include "avformat.h"
+#include "libavutil/log.h"
+#include "libavutil/opt.h"
/* The GIF format uses reversed order for bitstreams... */
/* at least they don't use PDP_ENDIAN :) */
@@ -245,8 +247,10 @@ static int gif_image_write_image(AVIOContext *pb,
}
typedef struct {
+ AVClass *class; /** Class for private options. */
int64_t time, file_time;
uint8_t buffer[100]; /* data chunks */
+ int loop;
} GIFContext;
static int gif_write_header(AVFormatContext *s)
@@ -254,7 +258,7 @@ static int gif_write_header(AVFormatContext *s)
GIFContext *gif = s->priv_data;
AVIOContext *pb = s->pb;
AVCodecContext *enc, *video_enc;
- int i, width, height, loop_count /*, rate*/;
+ int i, width, height /*, rate*/;
/* XXX: do we reject audio streams or just ignore them ?
if(s->nb_streams > 1)
@@ -276,7 +280,6 @@ static int gif_write_header(AVFormatContext *s)
} else {
width = video_enc->width;
height = video_enc->height;
- loop_count = s->loop_output;
// rate = video_enc->time_base.den;
}
@@ -285,7 +288,12 @@ static int gif_write_header(AVFormatContext *s)
return AVERROR(EIO);
}
- gif_image_write_header(pb, width, height, loop_count, NULL);
+#if FF_API_LOOP_OUTPUT
+ if (s->loop_output)
+ gif->loop = s->loop_output;
+#endif
+
+ gif_image_write_header(pb, width, height, gif->loop, NULL);
avio_flush(s->pb);
return 0;
@@ -340,15 +348,30 @@ static int gif_write_trailer(AVFormatContext *s)
return 0;
}
+#define OFFSET(x) offsetof(GIFContext, x)
+#define ENC AV_OPT_FLAG_ENCODING_PARAM
+static const AVOption options[] = {
+ { "loop", "Number of times to loop the output.", OFFSET(loop), AV_OPT_TYPE_INT, {0}, 0, 65535, ENC },
+ { NULL },
+};
+
+static const AVClass gif_muxer_class = {
+ .class_name = "GIF muxer",
+ .item_name = av_default_item_name,
+ .version = LIBAVUTIL_VERSION_INT,
+ .option = options,
+};
+
AVOutputFormat ff_gif_muxer = {
- "gif",
- NULL_IF_CONFIG_SMALL("GIF Animation"),
- "image/gif",
- "gif",
- sizeof(GIFContext),
- CODEC_ID_NONE,
- CODEC_ID_RAWVIDEO,
- gif_write_header,
- gif_write_packet,
- gif_write_trailer,
+ .name = "gif",
+ .long_name = NULL_IF_CONFIG_SMALL("GIF Animation"),
+ .mime_type = "image/gif",
+ .extensions = "gif",
+ .priv_data_size = sizeof(GIFContext),
+ .audio_codec = CODEC_ID_NONE,
+ .video_codec = CODEC_ID_RAWVIDEO,
+ .write_header = gif_write_header,
+ .write_packet = gif_write_packet,
+ .write_trailer = gif_write_trailer,
+ .priv_class = &gif_muxer_class,
};
diff --git a/libavformat/gopher.c b/libavformat/gopher.c
index 79d1feba6b..9eeffaca28 100644
--- a/libavformat/gopher.c
+++ b/libavformat/gopher.c
@@ -5,20 +5,20 @@
*
* based on libavformat/http.c, Copyright (c) 2000, 2001 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/gxf.c b/libavformat/gxf.c
index 54fdadfc32..d42c3fd307 100644
--- a/libavformat/gxf.c
+++ b/libavformat/gxf.c
@@ -2,20 +2,20 @@
* GXF demuxer.
* Copyright (c) 2006 Reimar Doeffinger
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -81,9 +81,10 @@ static int get_sindex(AVFormatContext *s, int id, int format) {
i = ff_find_stream_index(s, id);
if (i >= 0)
return i;
- st = av_new_stream(s, id);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
+ st->id = id;
switch (format) {
case 3:
case 4:
@@ -184,9 +185,9 @@ static void gxf_material_tags(AVIOContext *pb, int *len, struct gxf_stream_info
* @return fps as AVRational, or 0 / 0 if unknown
*/
static AVRational fps_tag2avr(int32_t fps) {
- extern const AVRational ff_frame_rate_tab[];
+ extern const AVRational avpriv_frame_rate_tab[];
if (fps < 1 || fps > 9) fps = 9;
- return ff_frame_rate_tab[9 - fps]; // values have opposite order
+ return avpriv_frame_rate_tab[9 - fps]; // values have opposite order
}
/**
@@ -264,7 +265,7 @@ static int gxf_header(AVFormatContext *s, AVFormatParameters *ap) {
int map_len;
int len;
AVRational main_timebase = {0, 0};
- struct gxf_stream_info si;
+ struct gxf_stream_info *si = s->priv_data;
int i;
if (!parse_packet_header(pb, &pkt_type, &map_len) || pkt_type != PKT_MAP) {
av_log(s, AV_LOG_ERROR, "map packet not found\n");
@@ -282,7 +283,7 @@ static int gxf_header(AVFormatContext *s, AVFormatParameters *ap) {
return 0;
}
map_len -= len;
- gxf_material_tags(pb, &len, &si);
+ gxf_material_tags(pb, &len, si);
avio_skip(pb, len);
map_len -= 2;
len = avio_rb16(pb); // length of track description
@@ -300,7 +301,7 @@ static int gxf_header(AVFormatContext *s, AVFormatParameters *ap) {
track_id = avio_r8(pb);
track_len = avio_rb16(pb);
len -= track_len;
- gxf_track_tags(pb, &track_len, &si);
+ gxf_track_tags(pb, &track_len, si);
avio_skip(pb, track_len);
if (!(track_type & 0x80)) {
av_log(s, AV_LOG_ERROR, "invalid track type %x\n", track_type);
@@ -316,12 +317,12 @@ static int gxf_header(AVFormatContext *s, AVFormatParameters *ap) {
if (idx < 0) continue;
st = s->streams[idx];
if (!main_timebase.num || !main_timebase.den) {
- main_timebase.num = si.frames_per_second.den;
- main_timebase.den = si.frames_per_second.num * 2;
+ main_timebase.num = si->frames_per_second.den;
+ main_timebase.den = si->frames_per_second.num * 2;
}
- st->start_time = si.first_field;
- if (si.first_field != AV_NOPTS_VALUE && si.last_field != AV_NOPTS_VALUE)
- st->duration = si.last_field - si.first_field;
+ st->start_time = si->first_field;
+ if (si->first_field != AV_NOPTS_VALUE && si->last_field != AV_NOPTS_VALUE)
+ st->duration = si->last_field - si->first_field;
}
if (len < 0)
av_log(s, AV_LOG_ERROR, "invalid track description length specified\n");
@@ -346,6 +347,8 @@ static int gxf_header(AVFormatContext *s, AVFormatParameters *ap) {
avio_skip(pb, 0x30); // payload description
fps = fps_umf2avr(avio_rl32(pb));
if (!main_timebase.num || !main_timebase.den) {
+ av_log(s, AV_LOG_WARNING, "No FPS track tag, using UMF fps tag."
+ " This might give wrong results.\n");
// this may not always be correct, but simply the best we can get
main_timebase.num = fps.den;
main_timebase.den = fps.num * 2;
@@ -368,7 +371,7 @@ static int gxf_header(AVFormatContext *s, AVFormatParameters *ap) {
#define READ_ONE() \
{ \
- if (!max_interval-- || pb->eof_reached) \
+ if (!max_interval-- || url_feof(pb)) \
goto out; \
tmp = tmp << 8 | avio_r8(pb); \
}
@@ -422,13 +425,15 @@ static int gxf_packet(AVFormatContext *s, AVPacket *pkt) {
AVIOContext *pb = s->pb;
GXFPktType pkt_type;
int pkt_len;
+ struct gxf_stream_info *si = s->priv_data;
+
while (!pb->eof_reached) {
AVStream *st;
int track_type, track_id, ret;
int field_nr, field_info, skip = 0;
int stream_index;
if (!parse_packet_header(pb, &pkt_type, &pkt_len)) {
- if (!pb->eof_reached)
+ if (!url_feof(pb))
av_log(s, AV_LOG_ERROR, "sync lost\n");
return -1;
}
@@ -473,6 +478,11 @@ static int gxf_packet(AVFormatContext *s, AVPacket *pkt) {
avio_skip(pb, skip);
pkt->stream_index = stream_index;
pkt->dts = field_nr;
+
+ //set duration manually for DV or else lavf misdetects the frame rate
+ if (st->codec->codec_id == CODEC_ID_DVVIDEO)
+ pkt->duration = si->fields_per_frame;
+
return ret;
}
return AVERROR(EIO);
@@ -516,13 +526,12 @@ static int64_t gxf_read_timestamp(AVFormatContext *s, int stream_index,
}
AVInputFormat ff_gxf_demuxer = {
- "gxf",
- NULL_IF_CONFIG_SMALL("GXF format"),
- 0,
- gxf_probe,
- gxf_header,
- gxf_packet,
- NULL,
- gxf_seek,
- gxf_read_timestamp,
+ .name = "gxf",
+ .long_name = NULL_IF_CONFIG_SMALL("GXF format"),
+ .priv_data_size = sizeof(struct gxf_stream_info),
+ .read_probe = gxf_probe,
+ .read_header = gxf_header,
+ .read_packet = gxf_packet,
+ .read_seek = gxf_seek,
+ .read_timestamp = gxf_read_timestamp,
};
diff --git a/libavformat/gxf.h b/libavformat/gxf.h
index c1ac399458..dcdcdefc2d 100644
--- a/libavformat/gxf.h
+++ b/libavformat/gxf.h
@@ -2,20 +2,20 @@
* GXF demuxer
* copyright (c) 2006 Reimar Doeffinger
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/gxfenc.c b/libavformat/gxfenc.c
index 5a3ff39ab2..3d56eba287 100644
--- a/libavformat/gxfenc.c
+++ b/libavformat/gxfenc.c
@@ -2,20 +2,20 @@
* GXF muxer.
* Copyright (c) 2006 SmartJog S.A., Baptiste Coudurier <baptiste dot coudurier at smartjog dot com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -342,8 +342,9 @@ static int gxf_write_map_packet(AVFormatContext *s, int rewrite)
if (!rewrite) {
if (!(gxf->map_offsets_nb % 30)) {
- gxf->map_offsets = av_realloc(gxf->map_offsets,
- (gxf->map_offsets_nb+30)*sizeof(*gxf->map_offsets));
+ gxf->map_offsets = av_realloc_f(gxf->map_offsets,
+ sizeof(*gxf->map_offsets),
+ gxf->map_offsets_nb+30);
if (!gxf->map_offsets) {
av_log(s, AV_LOG_ERROR, "could not realloc map offsets\n");
return -1;
@@ -394,9 +395,20 @@ static int gxf_write_umf_material_description(AVFormatContext *s)
GXFContext *gxf = s->priv_data;
AVIOContext *pb = s->pb;
int timecode_base = gxf->time_base.den == 60000 ? 60 : 50;
+ int64_t timestamp = 0;
+ AVDictionaryEntry *t;
+ uint32_t timecode;
+
+#if FF_API_TIMESTAMP
+ if (s->timestamp)
+ timestamp = s->timestamp;
+ else
+#endif
+ if (t = av_dict_get(s->metadata, "creation_time", NULL, 0))
+ timestamp = ff_iso8601_to_unix_time(t->value);
// XXX drop frame
- uint32_t timecode =
+ timecode =
gxf->nb_fields / (timecode_base * 3600) % 24 << 24 | // hours
gxf->nb_fields / (timecode_base * 60) % 60 << 16 | // minutes
gxf->nb_fields / timecode_base % 60 << 8 | // seconds
@@ -409,8 +421,8 @@ static int gxf_write_umf_material_description(AVFormatContext *s)
avio_wl32(pb, gxf->nb_fields); /* mark out */
avio_wl32(pb, 0); /* timecode mark in */
avio_wl32(pb, timecode); /* timecode mark out */
- avio_wl64(pb, s->timestamp); /* modification time */
- avio_wl64(pb, s->timestamp); /* creation time */
+ avio_wl64(pb, timestamp); /* modification time */
+ avio_wl64(pb, timestamp); /* creation time */
avio_wl16(pb, 0); /* reserved */
avio_wl16(pb, 0); /* reserved */
avio_wl16(pb, gxf->audio_tracks);
@@ -878,8 +890,9 @@ static int gxf_write_packet(AVFormatContext *s, AVPacket *pkt)
if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
if (!(gxf->flt_entries_nb % 500)) {
- gxf->flt_entries = av_realloc(gxf->flt_entries,
- (gxf->flt_entries_nb+500)*sizeof(*gxf->flt_entries));
+ gxf->flt_entries = av_realloc_f(gxf->flt_entries,
+ sizeof(*gxf->flt_entries),
+ gxf->flt_entries_nb+500);
if (!gxf->flt_entries) {
av_log(s, AV_LOG_ERROR, "could not reallocate flt entries\n");
return -1;
@@ -933,17 +946,14 @@ static int gxf_interleave_packet(AVFormatContext *s, AVPacket *out, AVPacket *pk
}
AVOutputFormat ff_gxf_muxer = {
- "gxf",
- NULL_IF_CONFIG_SMALL("GXF format"),
- NULL,
- "gxf",
- sizeof(GXFContext),
- CODEC_ID_PCM_S16LE,
- CODEC_ID_MPEG2VIDEO,
- gxf_write_header,
- gxf_write_packet,
- gxf_write_trailer,
- 0,
- NULL,
- gxf_interleave_packet,
+ .name = "gxf",
+ .long_name = NULL_IF_CONFIG_SMALL("GXF format"),
+ .extensions = "gxf",
+ .priv_data_size = sizeof(GXFContext),
+ .audio_codec = CODEC_ID_PCM_S16LE,
+ .video_codec = CODEC_ID_MPEG2VIDEO,
+ .write_header = gxf_write_header,
+ .write_packet = gxf_write_packet,
+ .write_trailer = gxf_write_trailer,
+ .interleave_packet = gxf_interleave_packet,
};
diff --git a/libavformat/h261dec.c b/libavformat/h261dec.c
index 1b416d4fc7..354a7c78c1 100644
--- a/libavformat/h261dec.c
+++ b/libavformat/h261dec.c
@@ -2,20 +2,20 @@
* RAW H.261 video demuxer
* Copyright (c) 2009 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/h263dec.c b/libavformat/h263dec.c
index b9185cbcb6..b07e9782b8 100644
--- a/libavformat/h263dec.c
+++ b/libavformat/h263dec.c
@@ -2,20 +2,20 @@
* RAW H.263 video demuxer
* Copyright (c) 2009 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/h264dec.c b/libavformat/h264dec.c
index f9086476d5..e7c6d70deb 100644
--- a/libavformat/h264dec.c
+++ b/libavformat/h264dec.c
@@ -2,20 +2,20 @@
* RAW H.264 video demuxer
* Copyright (c) 2008 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -54,7 +54,7 @@ static int h264_probe(AVProbeData *p)
case 1: sli++; break;
case 5: idr++; break;
case 7:
- if(p->buf[i+2]&0x0F)
+ if(p->buf[i+2]&0x03)
return 0;
sps++;
break;
diff --git a/libavformat/http.c b/libavformat/http.c
index aa8c6657db..265aff27e0 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -2,20 +2,20 @@
* HTTP protocol for ffmpeg client
* Copyright (c) 2000, 2001 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -54,7 +54,7 @@ typedef struct {
#define OFFSET(x) offsetof(HTTPContext, x)
static const AVOption options[] = {
-{"chunksize", "use chunked transfer-encoding for posts, -1 disables it, 0 enables it", OFFSET(chunksize), FF_OPT_TYPE_INT64, {.dbl = 0}, -1, 0 }, /* Default to 0, for chunked POSTs */
+{"chunksize", "use chunked transfer-encoding for posts, -1 disables it, 0 enables it", OFFSET(chunksize), AV_OPT_TYPE_INT64, {.dbl = 0}, -1, 0 }, /* Default to 0, for chunked POSTs */
{NULL}
};
static const AVClass httpcontext_class = {
@@ -265,6 +265,8 @@ static int process_line(URLContext *h, char *line, int line_count,
s->filesize = atoll(slash+1);
}
h->is_streamed = 0; /* we _can_ in fact seek */
+ } else if (!strcasecmp(tag, "Accept-Ranges") && !strncmp(p, "bytes", 5)) {
+ h->is_streamed = 0;
} else if (!strcasecmp (tag, "Transfer-Encoding") && !strncasecmp(p, "chunked", 7)) {
s->filesize = -1;
s->chunksize = 0;
diff --git a/libavformat/http.h b/libavformat/http.h
index c5ff5e134c..d01a004e9f 100644
--- a/libavformat/http.h
+++ b/libavformat/http.h
@@ -2,20 +2,20 @@
* HTTP definitions
* Copyright (c) 2010 Josh Allmann
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/httpauth.c b/libavformat/httpauth.c
index 1dda1ac8f0..58e0e82ed1 100644
--- a/libavformat/httpauth.c
+++ b/libavformat/httpauth.c
@@ -2,20 +2,20 @@
* HTTP authentication
* Copyright (c) 2010 Martin Storsjo
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/httpauth.h b/libavformat/httpauth.h
index d2a4a55305..ebab3fca29 100644
--- a/libavformat/httpauth.h
+++ b/libavformat/httpauth.h
@@ -2,20 +2,20 @@
* HTTP authentication
* Copyright (c) 2010 Martin Storsjo
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/id3v1.c b/libavformat/id3v1.c
index 87930ff361..2d1e806920 100644
--- a/libavformat/id3v1.c
+++ b/libavformat/id3v1.c
@@ -2,20 +2,20 @@
* ID3v1 header parser
* Copyright (c) 2003 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/id3v1.h b/libavformat/id3v1.h
index 4842f16f53..8eb58be2d1 100644
--- a/libavformat/id3v1.h
+++ b/libavformat/id3v1.h
@@ -2,20 +2,20 @@
* ID3v1 header parser
* Copyright (c) 2003 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/id3v2.c b/libavformat/id3v2.c
index be6c03bbe5..32870648cf 100644
--- a/libavformat/id3v2.c
+++ b/libavformat/id3v2.c
@@ -1,24 +1,31 @@
/*
- * ID3v2 header parser
* Copyright (c) 2003 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+/**
+ * @file
+ * ID3v2 header parser
+ *
+ * Specifications available at:
+ * http://id3.org/Developer_Information
+ */
+
#include "id3v2.h"
#include "id3v1.h"
#include "libavutil/avstring.h"
@@ -26,6 +33,66 @@
#include "libavutil/dict.h"
#include "avio_internal.h"
+const AVMetadataConv ff_id3v2_34_metadata_conv[] = {
+ { "TALB", "album"},
+ { "TCOM", "composer"},
+ { "TCON", "genre"},
+ { "TCOP", "copyright"},
+ { "TENC", "encoded_by"},
+ { "TIT2", "title"},
+ { "TLAN", "language"},
+ { "TPE1", "artist"},
+ { "TPE2", "album_artist"},
+ { "TPE3", "performer"},
+ { "TPOS", "disc"},
+ { "TPUB", "publisher"},
+ { "TRCK", "track"},
+ { "TSSE", "encoder"},
+ { 0 }
+};
+
+const AVMetadataConv ff_id3v2_4_metadata_conv[] = {
+ { "TDRL", "date"},
+ { "TDRC", "date"},
+ { "TDEN", "creation_time"},
+ { "TSOA", "album-sort"},
+ { "TSOP", "artist-sort"},
+ { "TSOT", "title-sort"},
+ { 0 }
+};
+
+static const AVMetadataConv id3v2_2_metadata_conv[] = {
+ { "TAL", "album"},
+ { "TCO", "genre"},
+ { "TT2", "title"},
+ { "TEN", "encoded_by"},
+ { "TP1", "artist"},
+ { "TP2", "album_artist"},
+ { "TP3", "performer"},
+ { "TRK", "track"},
+ { 0 }
+};
+
+
+const char ff_id3v2_tags[][4] = {
+ "TALB", "TBPM", "TCOM", "TCON", "TCOP", "TDLY", "TENC", "TEXT",
+ "TFLT", "TIT1", "TIT2", "TIT3", "TKEY", "TLAN", "TLEN", "TMED",
+ "TOAL", "TOFN", "TOLY", "TOPE", "TOWN", "TPE1", "TPE2", "TPE3",
+ "TPE4", "TPOS", "TPUB", "TRCK", "TRSN", "TRSO", "TSRC", "TSSE",
+ { 0 },
+};
+
+const char ff_id3v2_4_tags[][4] = {
+ "TDEN", "TDOR", "TDRC", "TDRL", "TDTG", "TIPL", "TMCL", "TMOO",
+ "TPRO", "TSOA", "TSOP", "TSOT", "TSST",
+ { 0 },
+};
+
+const char ff_id3v2_3_tags[][4] = {
+ "TDAT", "TIME", "TORY", "TRDA", "TSIZ", "TYER",
+ { 0 },
+};
+
int ff_id3v2_match(const uint8_t *buf, const char * magic)
{
return buf[0] == magic[0] &&
@@ -59,81 +126,220 @@ static unsigned int get_size(AVIOContext *s, int len)
return v;
}
-static void read_ttag(AVFormatContext *s, AVIOContext *pb, int taglen, const char *key)
+/**
+ * Free GEOB type extra metadata.
+ */
+static void free_geobtag(void *obj)
{
- char *q, dst[512];
- const char *val = NULL;
- int len, dstlen = sizeof(dst) - 1;
- unsigned genre;
- unsigned int (*get)(AVIOContext*) = avio_rb16;
+ ID3v2ExtraMetaGEOB *geob = obj;
+ av_free(geob->mime_type);
+ av_free(geob->file_name);
+ av_free(geob->description);
+ av_free(geob->data);
+ av_free(geob);
+}
- dst[0] = 0;
- if (taglen < 1)
- return;
+/**
+ * Decode characters to UTF-8 according to encoding type. The decoded buffer is
+ * always null terminated. Stop reading when either *maxread bytes are read from
+ * pb or U+0000 character is found.
+ *
+ * @param dst Pointer where the address of the buffer with the decoded bytes is
+ * stored. Buffer must be freed by caller.
+ * @param maxread Pointer to maximum number of characters to read from the
+ * AVIOContext. After execution the value is decremented by the number of bytes
+ * actually read.
+ * @returns 0 if no error occured, dst is uninitialized on error
+ */
+static int decode_str(AVFormatContext *s, AVIOContext *pb, int encoding,
+ uint8_t **dst, int *maxread)
+{
+ int ret;
+ uint8_t tmp;
+ uint32_t ch = 1;
+ int left = *maxread;
+ unsigned int (*get)(AVIOContext*) = avio_rb16;
+ AVIOContext *dynbuf;
- taglen--; /* account for encoding type byte */
+ if ((ret = avio_open_dyn_buf(&dynbuf)) < 0) {
+ av_log(s, AV_LOG_ERROR, "Error opening memory stream\n");
+ return ret;
+ }
- switch (avio_r8(pb)) { /* encoding type */
+ switch (encoding) {
case ID3v2_ENCODING_ISO8859:
- q = dst;
- while (taglen-- && q - dst < dstlen - 7) {
- uint8_t tmp;
- PUT_UTF8(avio_r8(pb), tmp, *q++ = tmp;)
+ while (left && ch) {
+ ch = avio_r8(pb);
+ PUT_UTF8(ch, tmp, avio_w8(dynbuf, tmp);)
+ left--;
}
- *q = 0;
break;
case ID3v2_ENCODING_UTF16BOM:
- taglen -= 2;
+ if ((left -= 2) < 0) {
+ av_log(s, AV_LOG_ERROR, "Cannot read BOM value, input too short\n");
+ avio_close_dyn_buf(dynbuf, dst);
+ av_freep(dst);
+ return AVERROR_INVALIDDATA;
+ }
switch (avio_rb16(pb)) {
case 0xfffe:
get = avio_rl16;
case 0xfeff:
break;
default:
- av_log(s, AV_LOG_ERROR, "Incorrect BOM value in tag %s.\n", key);
- return;
+ av_log(s, AV_LOG_ERROR, "Incorrect BOM value\n");
+ avio_close_dyn_buf(dynbuf, dst);
+ av_freep(dst);
+ *maxread = left;
+ return AVERROR_INVALIDDATA;
}
// fall-through
case ID3v2_ENCODING_UTF16BE:
- q = dst;
- while (taglen > 1 && q - dst < dstlen - 7) {
- uint32_t ch;
- uint8_t tmp;
-
- GET_UTF16(ch, ((taglen -= 2) >= 0 ? get(pb) : 0), break;)
- PUT_UTF8(ch, tmp, *q++ = tmp;)
+ while ((left > 1) && ch) {
+ GET_UTF16(ch, ((left -= 2) >= 0 ? get(pb) : 0), break;)
+ PUT_UTF8(ch, tmp, avio_w8(dynbuf, tmp);)
}
- *q = 0;
+ if (left < 0)
+ left += 2; /* did not read last char from pb */
break;
case ID3v2_ENCODING_UTF8:
- len = FFMIN(taglen, dstlen);
- avio_read(pb, dst, len);
- dst[len] = 0;
+ while (left && ch) {
+ ch = avio_r8(pb);
+ avio_w8(dynbuf, ch);
+ left--;
+ }
break;
default:
- av_log(s, AV_LOG_WARNING, "Unknown encoding in tag %s.\n", key);
+ av_log(s, AV_LOG_WARNING, "Unknown encoding\n");
+ }
+
+ if (ch)
+ avio_w8(dynbuf, 0);
+
+ avio_close_dyn_buf(dynbuf, dst);
+ *maxread = left;
+
+ return 0;
+}
+
+/**
+ * Parse a text tag.
+ */
+static void read_ttag(AVFormatContext *s, AVIOContext *pb, int taglen, const char *key)
+{
+ uint8_t *dst;
+ int encoding, dict_flags = AV_DICT_DONT_OVERWRITE;
+ unsigned genre;
+
+ if (taglen < 1)
+ return;
+
+ encoding = avio_r8(pb);
+ taglen--; /* account for encoding type byte */
+
+ if (decode_str(s, pb, encoding, &dst, &taglen) < 0) {
+ av_log(s, AV_LOG_ERROR, "Error reading frame %s, skipped\n", key);
+ return;
}
if (!(strcmp(key, "TCON") && strcmp(key, "TCO"))
&& (sscanf(dst, "(%d)", &genre) == 1 || sscanf(dst, "%d", &genre) == 1)
- && genre <= ID3v1_GENRE_MAX)
- val = ff_id3v1_genre_str[genre];
- else if (!(strcmp(key, "TXXX") && strcmp(key, "TXX"))) {
- /* dst now contains two 0-terminated strings */
- dst[dstlen] = 0;
- len = strlen(dst);
+ && genre <= ID3v1_GENRE_MAX) {
+ av_freep(&dst);
+ dst = ff_id3v1_genre_str[genre];
+ } else if (!(strcmp(key, "TXXX") && strcmp(key, "TXX"))) {
+ /* dst now contains the key, need to get value */
key = dst;
- val = dst + FFMIN(len + 1, dstlen);
+ if (decode_str(s, pb, encoding, &dst, &taglen) < 0) {
+ av_log(s, AV_LOG_ERROR, "Error reading frame %s, skipped\n", key);
+ av_freep(&key);
+ return;
+ }
+ dict_flags |= AV_DICT_DONT_STRDUP_VAL | AV_DICT_DONT_STRDUP_KEY;
}
else if (*dst)
- val = dst;
+ dict_flags |= AV_DICT_DONT_STRDUP_VAL;
- if (val)
- av_dict_set(&s->metadata, key, val, AV_DICT_DONT_OVERWRITE);
+ if (dst)
+ av_dict_set(&s->metadata, key, dst, dict_flags);
+}
+
+/**
+ * Parse GEOB tag into a ID3v2ExtraMetaGEOB struct.
+ */
+static void read_geobtag(AVFormatContext *s, AVIOContext *pb, int taglen, char *tag, ID3v2ExtraMeta **extra_meta)
+{
+ ID3v2ExtraMetaGEOB *geob_data = NULL;
+ ID3v2ExtraMeta *new_extra = NULL;
+ char encoding;
+ unsigned int len;
+
+ if (taglen < 1)
+ return;
+
+ geob_data = av_mallocz(sizeof(ID3v2ExtraMetaGEOB));
+ if (!geob_data) {
+ av_log(s, AV_LOG_ERROR, "Failed to alloc %zu bytes\n", sizeof(ID3v2ExtraMetaGEOB));
+ return;
+ }
+
+ new_extra = av_mallocz(sizeof(ID3v2ExtraMeta));
+ if (!new_extra) {
+ av_log(s, AV_LOG_ERROR, "Failed to alloc %zu bytes\n", sizeof(ID3v2ExtraMeta));
+ goto fail;
+ }
+
+ /* read encoding type byte */
+ encoding = avio_r8(pb);
+ taglen--;
+
+ /* read MIME type (always ISO-8859) */
+ if (decode_str(s, pb, ID3v2_ENCODING_ISO8859, &geob_data->mime_type, &taglen) < 0
+ || taglen <= 0)
+ goto fail;
+
+ /* read file name */
+ if (decode_str(s, pb, encoding, &geob_data->file_name, &taglen) < 0
+ || taglen <= 0)
+ goto fail;
+
+ /* read content description */
+ if (decode_str(s, pb, encoding, &geob_data->description, &taglen) < 0
+ || taglen < 0)
+ goto fail;
+
+ if (taglen) {
+ /* save encapsulated binary data */
+ geob_data->data = av_malloc(taglen);
+ if (!geob_data->data) {
+ av_log(s, AV_LOG_ERROR, "Failed to alloc %d bytes\n", taglen);
+ goto fail;
+ }
+ if ((len = avio_read(pb, geob_data->data, taglen)) < taglen)
+ av_log(s, AV_LOG_WARNING, "Error reading GEOB frame, data truncated.\n");
+ geob_data->datasize = len;
+ } else {
+ geob_data->data = NULL;
+ geob_data->datasize = 0;
+ }
+
+ /* add data to the list */
+ new_extra->tag = "GEOB";
+ new_extra->data = geob_data;
+ new_extra->next = *extra_meta;
+ *extra_meta = new_extra;
+
+ return;
+
+fail:
+ av_log(s, AV_LOG_ERROR, "Error reading frame %s, skipped\n", tag);
+ free_geobtag(geob_data);
+ av_free(new_extra);
+ return;
}
static int is_number(const char *str)
@@ -182,16 +388,50 @@ finish:
av_dict_set(m, "date", date, 0);
}
-static void ff_id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t flags)
+typedef struct ID3v2EMFunc {
+ const char *tag3;
+ const char *tag4;
+ void (*read)(AVFormatContext*, AVIOContext*, int, char*, ID3v2ExtraMeta **);
+ void (*free)(void *);
+} ID3v2EMFunc;
+
+static const ID3v2EMFunc id3v2_extra_meta_funcs[] = {
+ { "GEO", "GEOB", read_geobtag, free_geobtag },
+ { NULL }
+};
+
+/**
+ * Get the corresponding ID3v2EMFunc struct for a tag.
+ * @param isv34 Determines if v2.2 or v2.3/4 strings are used
+ * @return A pointer to the ID3v2EMFunc struct if found, NULL otherwise.
+ */
+static const ID3v2EMFunc *get_extra_meta_func(const char *tag, int isv34)
+{
+ int i = 0;
+ while (id3v2_extra_meta_funcs[i].tag3) {
+ if (!memcmp(tag,
+ (isv34 ? id3v2_extra_meta_funcs[i].tag4 :
+ id3v2_extra_meta_funcs[i].tag3),
+ (isv34 ? 4 : 3)))
+ return &id3v2_extra_meta_funcs[i];
+ i++;
+ }
+ return &id3v2_extra_meta_funcs[i];
+}
+
+static void ff_id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t flags, ID3v2ExtraMeta **extra_meta)
{
- int isv34, tlen, unsync;
+ int isv34, unsync;
+ unsigned tlen;
char tag[5];
int64_t next, end = avio_tell(s->pb) + len;
int taghdrlen;
const char *reason = NULL;
AVIOContext pb;
+ AVIOContext *pbx;
unsigned char *buffer = NULL;
int buffer_size = 0;
+ const ID3v2EMFunc *extra_func;
switch (version) {
case 2:
@@ -237,14 +477,24 @@ static void ff_id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t
tag[3] = 0;
tlen = avio_rb24(s->pb);
}
- if (tlen <= 0 || tlen > len - taghdrlen) {
- av_log(s, AV_LOG_WARNING, "Invalid size in frame %s, skipping the rest of tag.\n", tag);
+ if (tlen > (1<<28))
break;
- }
len -= taghdrlen + tlen;
+
+ if (len < 0)
+ break;
+
next = avio_tell(s->pb) + tlen;
+ if (!tlen) {
+ if (tag[0])
+ av_log(s, AV_LOG_DEBUG, "Invalid empty frame %s, skipping.\n", tag);
+ continue;
+ }
+
if (tflags & ID3v2_FLAG_DATALEN) {
+ if (tlen < 4)
+ break;
avio_rb32(s->pb);
tlen -= 4;
}
@@ -252,7 +502,8 @@ static void ff_id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t
if (tflags & (ID3v2_FLAG_ENCRYPTION | ID3v2_FLAG_COMPRESSION)) {
av_log(s, AV_LOG_WARNING, "Skipping encrypted/compressed ID3v2 frame %s.\n", tag);
avio_skip(s->pb, tlen);
- } else if (tag[0] == 'T') {
+ /* check for text tag or supported special meta tag */
+ } else if (tag[0] == 'T' || (extra_meta && (extra_func = get_extra_meta_func(tag, isv34)))) {
if (unsync || tunsync) {
int i, j;
av_fast_malloc(&buffer, &buffer_size, tlen);
@@ -268,10 +519,17 @@ static void ff_id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t
}
}
ffio_init_context(&pb, buffer, j, 0, NULL, NULL, NULL, NULL);
- read_ttag(s, &pb, j, tag);
+ tlen = j;
+ pbx = &pb; // read from sync buffer
} else {
- read_ttag(s, s->pb, tlen, tag);
+ pbx = s->pb; // read straight from input
}
+ if (tag[0] == 'T')
+ /* parse text tag */
+ read_ttag(s, pbx, tlen, tag);
+ else
+ /* parse special meta tag */
+ extra_func->read(s, pbx, tlen, tag, extra_meta);
}
else if (!tag[0]) {
if (tag[1])
@@ -295,7 +553,7 @@ seek:
return;
}
-void ff_id3v2_read(AVFormatContext *s, const char *magic)
+void ff_id3v2_read_all(AVFormatContext *s, const char *magic, ID3v2ExtraMeta **extra_meta)
{
int len, ret;
uint8_t buf[ID3v2_HEADER_SIZE];
@@ -315,73 +573,32 @@ void ff_id3v2_read(AVFormatContext *s, const char *magic)
((buf[7] & 0x7f) << 14) |
((buf[8] & 0x7f) << 7) |
(buf[9] & 0x7f);
- ff_id3v2_parse(s, len, buf[3], buf[5]);
+ ff_id3v2_parse(s, len, buf[3], buf[5], extra_meta);
} else {
avio_seek(s->pb, off, SEEK_SET);
}
} while (found_header);
ff_metadata_conv(&s->metadata, NULL, ff_id3v2_34_metadata_conv);
- ff_metadata_conv(&s->metadata, NULL, ff_id3v2_2_metadata_conv);
+ ff_metadata_conv(&s->metadata, NULL, id3v2_2_metadata_conv);
ff_metadata_conv(&s->metadata, NULL, ff_id3v2_4_metadata_conv);
merge_date(&s->metadata);
}
-const AVMetadataConv ff_id3v2_34_metadata_conv[] = {
- { "TALB", "album"},
- { "TCOM", "composer"},
- { "TCON", "genre"},
- { "TCOP", "copyright"},
- { "TENC", "encoded_by"},
- { "TIT2", "title"},
- { "TLAN", "language"},
- { "TPE1", "artist"},
- { "TPE2", "album_artist"},
- { "TPE3", "performer"},
- { "TPOS", "disc"},
- { "TPUB", "publisher"},
- { "TRCK", "track"},
- { "TSSE", "encoder"},
- { 0 }
-};
-
-const AVMetadataConv ff_id3v2_4_metadata_conv[] = {
- { "TDRL", "date"},
- { "TDRC", "date"},
- { "TDEN", "creation_time"},
- { "TSOA", "album-sort"},
- { "TSOP", "artist-sort"},
- { "TSOT", "title-sort"},
- { 0 }
-};
-
-const AVMetadataConv ff_id3v2_2_metadata_conv[] = {
- { "TAL", "album"},
- { "TCO", "genre"},
- { "TT2", "title"},
- { "TEN", "encoded_by"},
- { "TP1", "artist"},
- { "TP2", "album_artist"},
- { "TP3", "performer"},
- { "TRK", "track"},
- { 0 }
-};
-
-
-const char ff_id3v2_tags[][4] = {
- "TALB", "TBPM", "TCOM", "TCON", "TCOP", "TDLY", "TENC", "TEXT",
- "TFLT", "TIT1", "TIT2", "TIT3", "TKEY", "TLAN", "TLEN", "TMED",
- "TOAL", "TOFN", "TOLY", "TOPE", "TOWN", "TPE1", "TPE2", "TPE3",
- "TPE4", "TPOS", "TPUB", "TRCK", "TRSN", "TRSO", "TSRC", "TSSE",
- { 0 },
-};
-
-const char ff_id3v2_4_tags[][4] = {
- "TDEN", "TDOR", "TDRC", "TDRL", "TDTG", "TIPL", "TMCL", "TMOO",
- "TPRO", "TSOA", "TSOP", "TSOT", "TSST",
- { 0 },
-};
+void ff_id3v2_read(AVFormatContext *s, const char *magic)
+{
+ ff_id3v2_read_all(s, magic, NULL);
+}
-const char ff_id3v2_3_tags[][4] = {
- "TDAT", "TIME", "TORY", "TRDA", "TSIZ", "TYER",
- { 0 },
-};
+void ff_id3v2_free_extra_meta(ID3v2ExtraMeta **extra_meta)
+{
+ ID3v2ExtraMeta *current = *extra_meta, *next;
+ const ID3v2EMFunc *extra_func;
+
+ while (current) {
+ if ((extra_func = get_extra_meta_func(current->tag, 1)))
+ extra_func->free(current->data);
+ next = current->next;
+ av_freep(&current);
+ current = next;
+ }
+}
diff --git a/libavformat/id3v2.h b/libavformat/id3v2.h
index 3e0e65a92e..58cacdfeda 100644
--- a/libavformat/id3v2.h
+++ b/libavformat/id3v2.h
@@ -2,20 +2,20 @@
* ID3v2 header parser
* Copyright (c) 2003 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -45,6 +45,20 @@ enum ID3v2Encoding {
ID3v2_ENCODING_UTF8 = 3,
};
+typedef struct ID3v2ExtraMeta {
+ const char *tag;
+ void *data;
+ struct ID3v2ExtraMeta *next;
+} ID3v2ExtraMeta;
+
+typedef struct ID3v2ExtraMetaGEOB {
+ uint32_t datasize;
+ uint8_t *mime_type;
+ uint8_t *file_name;
+ uint8_t *description;
+ uint8_t *data;
+} ID3v2ExtraMetaGEOB;
+
/**
* Detect ID3v2 Header.
* @param buf must be ID3v2_HEADER_SIZE byte long
@@ -61,13 +75,25 @@ int ff_id3v2_match(const uint8_t *buf, const char *magic);
int ff_id3v2_tag_len(const uint8_t *buf);
/**
- * Read an ID3v2 tag
+ * Read an ID3v2 tag (text tags only)
*/
void ff_id3v2_read(AVFormatContext *s, const char *magic);
+/**
+ * Read an ID3v2 tag, including supported extra metadata (currently only GEOB)
+ * @param extra_meta If not NULL, extra metadata is parsed into a list of
+ * ID3v2ExtraMeta structs and *extra_meta points to the head of the list
+ */
+void ff_id3v2_read_all(AVFormatContext *s, const char *magic, ID3v2ExtraMeta **extra_meta);
+
+/**
+ * Free memory allocated parsing special (non-text) metadata.
+ * @param extra_meta Pointer to a pointer to the head of a ID3v2ExtraMeta list, *extra_meta is set to NULL.
+ */
+void ff_id3v2_free_extra_meta(ID3v2ExtraMeta **extra_meta);
+
extern const AVMetadataConv ff_id3v2_34_metadata_conv[];
extern const AVMetadataConv ff_id3v2_4_metadata_conv[];
-extern const AVMetadataConv ff_id3v2_2_metadata_conv[];
/**
* A list of text information frames allowed in both ID3 v2.3 and v2.4
diff --git a/libavformat/idcin.c b/libavformat/idcin.c
index 04ae687c6c..9d28043572 100644
--- a/libavformat/idcin.c
+++ b/libavformat/idcin.c
@@ -2,20 +2,20 @@
* id Quake II CIN File Demuxer
* Copyright (c) 2003 The ffmpeg Project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -153,7 +153,7 @@ static int idcin_read_header(AVFormatContext *s,
bytes_per_sample = avio_rl32(pb);
channels = avio_rl32(pb);
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
av_set_pts_info(st, 33, 1, IDCIN_FPS);
@@ -174,7 +174,7 @@ static int idcin_read_header(AVFormatContext *s,
/* if sample rate is 0, assume no audio */
if (sample_rate) {
idcin->audio_present = 1;
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
av_set_pts_info(st, 33, 1, IDCIN_FPS);
@@ -224,7 +224,7 @@ static int idcin_read_packet(AVFormatContext *s,
unsigned char palette_buffer[768];
uint32_t palette[256];
- if (s->pb->eof_reached)
+ if (url_feof(s->pb))
return AVERROR(EIO);
if (idcin->next_chunk_is_video) {
@@ -292,10 +292,10 @@ static int idcin_read_packet(AVFormatContext *s,
}
AVInputFormat ff_idcin_demuxer = {
- "idcin",
- NULL_IF_CONFIG_SMALL("id Cinematic format"),
- sizeof(IdcinDemuxContext),
- idcin_probe,
- idcin_read_header,
- idcin_read_packet,
+ .name = "idcin",
+ .long_name = NULL_IF_CONFIG_SMALL("id Cinematic format"),
+ .priv_data_size = sizeof(IdcinDemuxContext),
+ .read_probe = idcin_probe,
+ .read_header = idcin_read_header,
+ .read_packet = idcin_read_packet,
};
diff --git a/libavformat/idroqdec.c b/libavformat/idroqdec.c
index d9315966ea..63ba5917a5 100644
--- a/libavformat/idroqdec.c
+++ b/libavformat/idroqdec.c
@@ -2,20 +2,20 @@
* id RoQ (.roq) File Demuxer
* Copyright (c) 2003 The ffmpeg Project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -84,7 +84,7 @@ static int roq_read_header(AVFormatContext *s,
roq->audio_frame_count = 0;
roq->audio_stream_index = -1;
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
av_set_pts_info(st, 63, 1, framerate);
@@ -111,7 +111,7 @@ static int roq_read_packet(AVFormatContext *s,
while (!packet_read) {
- if (s->pb->eof_reached)
+ if (url_feof(s->pb))
return AVERROR(EIO);
/* get the next chunk preamble */
@@ -166,7 +166,7 @@ static int roq_read_packet(AVFormatContext *s,
case RoQ_SOUND_MONO:
case RoQ_SOUND_STEREO:
if (roq->audio_stream_index == -1) {
- AVStream *st = av_new_stream(s, 1);
+ AVStream *st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
av_set_pts_info(st, 32, 1, RoQ_AUDIO_SAMPLE_RATE);
@@ -216,10 +216,10 @@ static int roq_read_packet(AVFormatContext *s,
}
AVInputFormat ff_roq_demuxer = {
- "RoQ",
- NULL_IF_CONFIG_SMALL("id RoQ format"),
- sizeof(RoqDemuxContext),
- roq_probe,
- roq_read_header,
- roq_read_packet,
+ .name = "RoQ",
+ .long_name = NULL_IF_CONFIG_SMALL("id RoQ format"),
+ .priv_data_size = sizeof(RoqDemuxContext),
+ .read_probe = roq_probe,
+ .read_header = roq_read_header,
+ .read_packet = roq_read_packet,
};
diff --git a/libavformat/idroqenc.c b/libavformat/idroqenc.c
index 688d58d1ab..b8305261fd 100644
--- a/libavformat/idroqenc.c
+++ b/libavformat/idroqenc.c
@@ -2,20 +2,20 @@
* id RoQ (.roq) File muxer
* Copyright (c) 2007 Vitor Sessak
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -35,15 +35,12 @@ static int roq_write_header(struct AVFormatContext *s)
return 0;
}
-AVOutputFormat ff_roq_muxer =
-{
- "RoQ",
- NULL_IF_CONFIG_SMALL("raw id RoQ format"),
- NULL,
- "roq",
- 0,
- CODEC_ID_ROQ_DPCM,
- CODEC_ID_ROQ,
- roq_write_header,
- ff_raw_write_packet,
+AVOutputFormat ff_roq_muxer = {
+ .name = "RoQ",
+ .long_name = NULL_IF_CONFIG_SMALL("raw id RoQ format"),
+ .extensions = "roq",
+ .audio_codec = CODEC_ID_ROQ_DPCM,
+ .video_codec = CODEC_ID_ROQ,
+ .write_header = roq_write_header,
+ .write_packet = ff_raw_write_packet,
};
diff --git a/libavformat/iff.c b/libavformat/iff.c
index 2b84986aff..2283ed505a 100644
--- a/libavformat/iff.c
+++ b/libavformat/iff.c
@@ -1,23 +1,22 @@
/*
- * IFF (.iff) file demuxer
* Copyright (c) 2008 Jaikrishnan Menon <realityman@gmx.net>
* Copyright (c) 2010 Peter Ross <pross@xvid.org>
* Copyright (c) 2010 Sebastian Vater <cdgs.basty@googlemail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -29,6 +28,7 @@
* http://wiki.multimedia.cx/index.php?title=IFF
*/
+#include "libavcodec/bytestream.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/dict.h"
#include "avformat.h"
@@ -41,6 +41,7 @@
#define ID_PBM MKTAG('P','B','M',' ')
#define ID_ILBM MKTAG('I','L','B','M')
#define ID_BMHD MKTAG('B','M','H','D')
+#define ID_CAMG MKTAG('C','A','M','G')
#define ID_CMAP MKTAG('C','M','A','P')
#define ID_FORM MKTAG('F','O','R','M')
@@ -59,7 +60,15 @@
#define RIGHT 4
#define STEREO 6
-#define PACKET_SIZE 1024
+/**
+ * This number of bytes if added at the beginning of each AVPacket
+ * which contain additional information about video properties
+ * which has to be shared between demuxer and decoder.
+ * This number may change between frames, e.g. the demuxer might
+ * set it to smallest possible size of 2 to indicate that there's
+ * no extradata changing in this frame.
+ */
+#define IFF_EXTRA_VIDEO_SIZE 9
typedef enum {
COMP_NONE,
@@ -76,22 +85,15 @@ typedef struct {
uint64_t body_pos;
uint32_t body_size;
uint32_t sent_bytes;
- uint32_t audio_frame_count;
+ svx8_compression_type svx8_compression;
+ bitmap_compression_type bitmap_compression; ///< delta compression method used
+ unsigned bpp; ///< bits per plane to decode (differs from bits_per_coded_sample if HAM)
+ unsigned ham; ///< 0 if non-HAM or number of hold bits (6 for bpp > 6, 4 otherwise)
+ unsigned flags; ///< 1 for EHB, 0 is no extra half darkening
+ unsigned transparency; ///< transparency color index in palette
+ unsigned masking; ///< masking method used
} IffDemuxContext;
-
-static void interleave_stereo(const uint8_t *src, uint8_t *dest, int size)
-{
- uint8_t *end = dest + size;
- size = size>>1;
-
- while(dest < end) {
- *dest++ = *src;
- *dest++ = *(src+size);
- src++;
- }
-}
-
/* Metadata string read */
static int get_metadata(AVFormatContext *s,
const char *const tag,
@@ -127,10 +129,13 @@ static int iff_read_header(AVFormatContext *s,
IffDemuxContext *iff = s->priv_data;
AVIOContext *pb = s->pb;
AVStream *st;
+ uint8_t *buf;
uint32_t chunk_id, data_size;
- int compression = -1;
+ uint32_t screenmode = 0;
+ unsigned transparency = 0;
+ unsigned masking = 0; // no mask
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
@@ -139,7 +144,7 @@ static int iff_read_header(AVFormatContext *s,
// codec_tag used by ByteRun1 decoder to distinguish progressive (PBM) and interlaced (ILBM) content
st->codec->codec_tag = avio_rl32(pb);
- while(!pb->eof_reached) {
+ while(!url_feof(pb)) {
uint64_t orig_pos;
int res;
const char *metadata_tag = NULL;
@@ -157,7 +162,7 @@ static int iff_read_header(AVFormatContext *s,
st->codec->sample_rate = avio_rb16(pb);
if (data_size >= 16) {
avio_skip(pb, 1);
- compression = avio_r8(pb);
+ iff->svx8_compression = avio_r8(pb);
}
break;
@@ -172,16 +177,23 @@ static int iff_read_header(AVFormatContext *s,
st->codec->channels = (avio_rb32(pb) < 6) ? 1 : 2;
break;
+ case ID_CAMG:
+ if (data_size < 4)
+ return AVERROR_INVALIDDATA;
+ screenmode = avio_rb32(pb);
+ break;
+
case ID_CMAP:
- st->codec->extradata_size = data_size;
- st->codec->extradata = av_malloc(data_size);
+ st->codec->extradata_size = data_size + IFF_EXTRA_VIDEO_SIZE;
+ st->codec->extradata = av_malloc(data_size + IFF_EXTRA_VIDEO_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);
if (!st->codec->extradata)
return AVERROR(ENOMEM);
- if (avio_read(pb, st->codec->extradata, data_size) < 0)
+ if (avio_read(pb, st->codec->extradata + IFF_EXTRA_VIDEO_SIZE, data_size) < 0)
return AVERROR(EIO);
break;
case ID_BMHD:
+ iff->bitmap_compression = -1;
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
if (data_size <= 8)
return AVERROR_INVALIDDATA;
@@ -189,33 +201,25 @@ static int iff_read_header(AVFormatContext *s,
st->codec->height = avio_rb16(pb);
avio_skip(pb, 4); // x, y offset
st->codec->bits_per_coded_sample = avio_r8(pb);
- if (data_size >= 11) {
- avio_skip(pb, 1); // masking
- compression = avio_r8(pb);
+ if (data_size >= 10)
+ masking = avio_r8(pb);
+ if (data_size >= 11)
+ iff->bitmap_compression = avio_r8(pb);
+ if (data_size >= 14) {
+ avio_skip(pb, 1); // padding
+ transparency = avio_rb16(pb);
}
if (data_size >= 16) {
- avio_skip(pb, 3); // paddding, transparent
st->sample_aspect_ratio.num = avio_r8(pb);
st->sample_aspect_ratio.den = avio_r8(pb);
}
break;
case ID_ANNO:
- case ID_TEXT:
- metadata_tag = "comment";
- break;
-
- case ID_AUTH:
- metadata_tag = "artist";
- break;
-
- case ID_COPYRIGHT:
- metadata_tag = "copyright";
- break;
-
- case ID_NAME:
- metadata_tag = "title";
- break;
+ case ID_TEXT: metadata_tag = "comment"; break;
+ case ID_AUTH: metadata_tag = "artist"; break;
+ case ID_COPYRIGHT: metadata_tag = "copyright"; break;
+ case ID_NAME: metadata_tag = "title"; break;
}
if (metadata_tag) {
@@ -233,9 +237,9 @@ static int iff_read_header(AVFormatContext *s,
case AVMEDIA_TYPE_AUDIO:
av_set_pts_info(st, 32, 1, st->codec->sample_rate);
- switch(compression) {
+ switch (iff->svx8_compression) {
case COMP_NONE:
- st->codec->codec_id = CODEC_ID_PCM_S8;
+ st->codec->codec_id = CODEC_ID_8SVX_RAW;
break;
case COMP_FIB:
st->codec->codec_id = CODEC_ID_8SVX_FIB;
@@ -244,17 +248,42 @@ static int iff_read_header(AVFormatContext *s,
st->codec->codec_id = CODEC_ID_8SVX_EXP;
break;
default:
- av_log(s, AV_LOG_ERROR, "unknown compression method\n");
+ av_log(s, AV_LOG_ERROR,
+ "Unknown SVX8 compression method '%d'\n", iff->svx8_compression);
return -1;
}
- st->codec->bits_per_coded_sample = 8;
+ st->codec->bits_per_coded_sample = iff->svx8_compression == COMP_NONE ? 8 : 4;
st->codec->bit_rate = st->codec->channels * st->codec->sample_rate * st->codec->bits_per_coded_sample;
st->codec->block_align = st->codec->channels * st->codec->bits_per_coded_sample;
break;
case AVMEDIA_TYPE_VIDEO:
- switch (compression) {
+ iff->bpp = st->codec->bits_per_coded_sample;
+ if ((screenmode & 0x800 /* Hold And Modify */) && iff->bpp <= 8) {
+ iff->ham = iff->bpp > 6 ? 6 : 4;
+ st->codec->bits_per_coded_sample = 24;
+ }
+ iff->flags = (screenmode & 0x80 /* Extra HalfBrite */) && iff->bpp <= 8;
+ iff->masking = masking;
+ iff->transparency = transparency;
+
+ if (!st->codec->extradata) {
+ st->codec->extradata_size = IFF_EXTRA_VIDEO_SIZE;
+ st->codec->extradata = av_malloc(IFF_EXTRA_VIDEO_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);
+ if (!st->codec->extradata)
+ return AVERROR(ENOMEM);
+ }
+ buf = st->codec->extradata;
+ bytestream_put_be16(&buf, IFF_EXTRA_VIDEO_SIZE);
+ bytestream_put_byte(&buf, iff->bitmap_compression);
+ bytestream_put_byte(&buf, iff->bpp);
+ bytestream_put_byte(&buf, iff->ham);
+ bytestream_put_byte(&buf, iff->flags);
+ bytestream_put_be16(&buf, iff->transparency);
+ bytestream_put_byte(&buf, iff->masking);
+
+ switch (iff->bitmap_compression) {
case BITMAP_RAW:
st->codec->codec_id = CODEC_ID_IFF_ILBM;
break;
@@ -262,7 +291,8 @@ static int iff_read_header(AVFormatContext *s,
st->codec->codec_id = CODEC_ID_IFF_BYTERUN1;
break;
default:
- av_log(s, AV_LOG_ERROR, "unknown compression method\n");
+ av_log(s, AV_LOG_ERROR,
+ "Unknown bitmap compression method '%d'\n", iff->bitmap_compression);
return AVERROR_INVALIDDATA;
}
break;
@@ -282,44 +312,37 @@ static int iff_read_packet(AVFormatContext *s,
int ret;
if(iff->sent_bytes >= iff->body_size)
- return AVERROR(EIO);
+ return AVERROR_EOF;
- if(st->codec->channels == 2) {
- uint8_t sample_buffer[PACKET_SIZE];
+ if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
+ ret = av_get_packet(pb, pkt, iff->body_size);
+ } else if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
+ uint8_t *buf;
- ret = avio_read(pb, sample_buffer, PACKET_SIZE);
- if(av_new_packet(pkt, PACKET_SIZE) < 0) {
- av_log(s, AV_LOG_ERROR, "cannot allocate packet\n");
+ if (av_new_packet(pkt, iff->body_size + 2) < 0) {
return AVERROR(ENOMEM);
}
- interleave_stereo(sample_buffer, pkt->data, PACKET_SIZE);
- } else if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
- ret = av_get_packet(pb, pkt, iff->body_size);
+
+ buf = pkt->data;
+ bytestream_put_be16(&buf, 2);
+ ret = avio_read(pb, buf, iff->body_size);
} else {
- ret = av_get_packet(pb, pkt, PACKET_SIZE);
+ av_abort();
}
if(iff->sent_bytes == 0)
pkt->flags |= AV_PKT_FLAG_KEY;
+ iff->sent_bytes = iff->body_size;
- if(st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
- iff->sent_bytes += PACKET_SIZE;
- } else {
- iff->sent_bytes = iff->body_size;
- }
pkt->stream_index = 0;
- if(st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
- pkt->pts = iff->audio_frame_count;
- iff->audio_frame_count += ret / st->codec->channels;
- }
return ret;
}
AVInputFormat ff_iff_demuxer = {
- "IFF",
- NULL_IF_CONFIG_SMALL("IFF format"),
- sizeof(IffDemuxContext),
- iff_probe,
- iff_read_header,
- iff_read_packet,
+ .name = "IFF",
+ .long_name = NULL_IF_CONFIG_SMALL("IFF format"),
+ .priv_data_size = sizeof(IffDemuxContext),
+ .read_probe = iff_probe,
+ .read_header = iff_read_header,
+ .read_packet = iff_read_packet,
};
diff --git a/libavformat/img2.c b/libavformat/img2.c
index 4eef62371d..7b89a9c980 100644
--- a/libavformat/img2.c
+++ b/libavformat/img2.c
@@ -3,20 +3,20 @@
* Copyright (c) 2000, 2001, 2002 Fabrice Bellard
* Copyright (c) 2004 Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -38,10 +38,12 @@ typedef struct {
int img_number;
int img_count;
int is_pipe;
+ int split_planes; /**< use independent file for each Y, U, V plane */
char path[1024];
char *pixel_format; /**< Set by a private option. */
char *video_size; /**< Set by a private option. */
char *framerate; /**< Set by a private option. */
+ int loop;
} VideoData;
typedef struct {
@@ -53,6 +55,7 @@ static const IdStrMap img_tags[] = {
{ CODEC_ID_MJPEG , "jpeg"},
{ CODEC_ID_MJPEG , "jpg"},
{ CODEC_ID_LJPEG , "ljpg"},
+ { CODEC_ID_JPEGLS , "jls"},
{ CODEC_ID_PNG , "png"},
{ CODEC_ID_PNG , "mng"},
{ CODEC_ID_PPM , "ppm"},
@@ -66,6 +69,7 @@ static const IdStrMap img_tags[] = {
{ CODEC_ID_MPEG4 , "mpg4-img"},
{ CODEC_ID_FFV1 , "ffv1-img"},
{ CODEC_ID_RAWVIDEO , "y"},
+ { CODEC_ID_RAWVIDEO , "raw"},
{ CODEC_ID_BMP , "bmp"},
{ CODEC_ID_GIF , "gif"},
{ CODEC_ID_TARGA , "tga"},
@@ -81,6 +85,7 @@ static const IdStrMap img_tags[] = {
{ CODEC_ID_SUNRAST , "im8"},
{ CODEC_ID_SUNRAST , "im24"},
{ CODEC_ID_SUNRAST , "sunras"},
+ { CODEC_ID_JPEG2000 , "j2k"},
{ CODEC_ID_JPEG2000 , "jp2"},
{ CODEC_ID_JPEG2000 , "jpc"},
{ CODEC_ID_DPX , "dpx"},
@@ -215,7 +220,7 @@ static int read_header(AVFormatContext *s1, AVFormatParameters *ap)
s1->ctx_flags |= AVFMTCTX_NOHEADER;
- st = av_new_stream(s1, 0);
+ st = avformat_new_stream(s1, NULL);
if (!st) {
return AVERROR(ENOMEM);
}
@@ -232,15 +237,10 @@ static int read_header(AVFormatContext *s1, AVFormatParameters *ap)
av_log(s, AV_LOG_ERROR, "Could not parse framerate: %s.\n", s->framerate);
return ret;
}
-#if FF_API_FORMAT_PARAMETERS
- if (ap->pix_fmt != PIX_FMT_NONE)
- pix_fmt = ap->pix_fmt;
- if (ap->width > 0)
- width = ap->width;
- if (ap->height > 0)
- height = ap->height;
- if (ap->time_base.num)
- framerate = (AVRational){ap->time_base.den, ap->time_base.num};
+
+#if FF_API_LOOP_INPUT
+ if (s1->loop_input)
+ s->loop = s1->loop_input;
#endif
av_strlcpy(s->path, s1->filename, sizeof(s->path));
@@ -280,6 +280,8 @@ static int read_header(AVFormatContext *s1, AVFormatParameters *ap)
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
st->codec->codec_id = s1->audio_codec_id;
}else{
+ const char *str= strrchr(s->path, '.');
+ s->split_planes = str && !strcasecmp(str + 1, "y");
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
st->codec->codec_id = av_str2id(img_tags, s->path);
}
@@ -300,7 +302,7 @@ static int read_packet(AVFormatContext *s1, AVPacket *pkt)
if (!s->is_pipe) {
/* loop over input */
- if (s1->loop_input && s->img_number > s->img_last) {
+ if (s->loop && s->img_number > s->img_last) {
s->img_number = s->img_first;
}
if (s->img_number > s->img_last)
@@ -317,7 +319,7 @@ static int read_packet(AVFormatContext *s1, AVPacket *pkt)
}
size[i]= avio_size(f[i]);
- if(codec->codec_id != CODEC_ID_RAWVIDEO)
+ if(!s->split_planes)
break;
filename[ strlen(filename) - 1 ]= 'U' + i;
}
@@ -326,7 +328,7 @@ static int read_packet(AVFormatContext *s1, AVPacket *pkt)
infer_size(&codec->width, &codec->height, size[0]);
} else {
f[0] = s1->pb;
- if (f[0]->eof_reached)
+ if (url_feof(f[0]))
return AVERROR(EIO);
size[0]= 4096;
}
@@ -363,6 +365,7 @@ static int read_packet(AVFormatContext *s1, AVPacket *pkt)
static int write_header(AVFormatContext *s)
{
VideoData *img = s->priv_data;
+ const char *str;
img->img_number = 1;
av_strlcpy(img->path, s->filename, sizeof(img->path));
@@ -373,6 +376,8 @@ static int write_header(AVFormatContext *s)
else
img->is_pipe = 1;
+ str = strrchr(img->path, '.');
+ img->split_planes = str && !strcasecmp(str + 1, "y");
return 0;
}
@@ -390,7 +395,7 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
av_log(s, AV_LOG_ERROR,
"Could not get frame filename number %d from pattern '%s'\n",
img->img_number, img->path);
- return AVERROR(EIO);
+ return AVERROR(EINVAL);
}
for(i=0; i<3; i++){
if (avio_open(&pb[i], filename, AVIO_FLAG_WRITE) < 0) {
@@ -398,7 +403,7 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
return AVERROR(EIO);
}
- if(codec->codec_id != CODEC_ID_RAWVIDEO)
+ if(!img->split_planes)
break;
filename[ strlen(filename) - 1 ]= 'U' + i;
}
@@ -406,7 +411,7 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
pb[0] = s->pb;
}
- if(codec->codec_id == CODEC_ID_RAWVIDEO){
+ if(img->split_planes){
int ysize = codec->width * codec->height;
avio_write(pb[0], pkt->data , ysize);
avio_write(pb[1], pkt->data + ysize, (pkt->size - ysize)/2);
@@ -431,11 +436,13 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
avio_wb32(pb[0], 0);
ffio_wfourcc(pb[0], "jp2 ");
avio_write(pb[0], st->codec->extradata, st->codec->extradata_size);
+ }else if(pkt->size >= 8 && AV_RB32(pkt->data) == 0xFF4FFF51){
+ //jpeg2000 codestream
}else if(pkt->size < 8 ||
(!st->codec->extradata_size &&
AV_RL32(pkt->data+4) != MKTAG('j','P',' ',' '))){ // signature
error:
- av_log(s, AV_LOG_ERROR, "malformated jpeg2000 codestream\n");
+ av_log(s, AV_LOG_ERROR, "malformated jpeg2000 codestream %X\n", AV_RB32(pkt->data));
return -1;
}
}
@@ -455,21 +462,21 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
#define OFFSET(x) offsetof(VideoData, x)
#define DEC AV_OPT_FLAG_DECODING_PARAM
static const AVOption options[] = {
- { "pixel_format", "", OFFSET(pixel_format), FF_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
- { "video_size", "", OFFSET(video_size), FF_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
- { "framerate", "", OFFSET(framerate), FF_OPT_TYPE_STRING, {.str = "25"}, 0, 0, DEC },
+ { "pixel_format", "", OFFSET(pixel_format), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
+ { "video_size", "", OFFSET(video_size), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
+ { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0, DEC },
+ { "loop", "", OFFSET(loop), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 1, DEC },
{ NULL },
};
+/* input */
+#if CONFIG_IMAGE2_DEMUXER
static const AVClass img2_class = {
.class_name = "image2 demuxer",
.item_name = av_default_item_name,
.option = options,
.version = LIBAVUTIL_VERSION_INT,
};
-
-/* input */
-#if CONFIG_IMAGE2_DEMUXER
AVInputFormat ff_image2_demuxer = {
.name = "image2",
.long_name = NULL_IF_CONFIG_SMALL("image2 sequence"),
@@ -482,13 +489,19 @@ AVInputFormat ff_image2_demuxer = {
};
#endif
#if CONFIG_IMAGE2PIPE_DEMUXER
+static const AVClass img2pipe_class = {
+ .class_name = "image2pipe demuxer",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
AVInputFormat ff_image2pipe_demuxer = {
.name = "image2pipe",
.long_name = NULL_IF_CONFIG_SMALL("piped image2 sequence"),
.priv_data_size = sizeof(VideoData),
.read_header = read_header,
.read_packet = read_packet,
- .priv_class = &img2_class,
+ .priv_class = &img2pipe_class,
};
#endif
@@ -497,7 +510,7 @@ AVInputFormat ff_image2pipe_demuxer = {
AVOutputFormat ff_image2_muxer = {
.name = "image2",
.long_name = NULL_IF_CONFIG_SMALL("image2 sequence"),
- .extensions = "bmp,dpx,jpeg,jpg,ljpg,pam,pbm,pcx,pgm,pgmyuv,png,"
+ .extensions = "bmp,dpx,jls,jpeg,jpg,ljpg,pam,pbm,pcx,pgm,pgmyuv,png,"
"ppm,sgi,tga,tif,tiff,jp2",
.priv_data_size = sizeof(VideoData),
.video_codec = CODEC_ID_MJPEG,
diff --git a/libavformat/ingenientdec.c b/libavformat/ingenientdec.c
index febeb2ec35..97774abbcd 100644
--- a/libavformat/ingenientdec.c
+++ b/libavformat/ingenientdec.c
@@ -2,20 +2,20 @@
* RAW Ingenient MJPEG demuxer
* Copyright (c) 2005 Alex Beregszaszi
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -58,15 +58,16 @@ static int ingenient_read_packet(AVFormatContext *s, AVPacket *pkt)
return ret;
}
+FF_RAWVIDEO_DEMUXER_CLASS(ingenient)
+
AVInputFormat ff_ingenient_demuxer = {
- "ingenient",
- NULL_IF_CONFIG_SMALL("raw Ingenient MJPEG"),
- sizeof(FFRawVideoDemuxerContext),
- NULL,
- ff_raw_video_read_header,
- ingenient_read_packet,
+ .name = "ingenient",
+ .long_name = NULL_IF_CONFIG_SMALL("raw Ingenient MJPEG"),
+ .priv_data_size = sizeof(FFRawVideoDemuxerContext),
+ .read_header = ff_raw_video_read_header,
+ .read_packet = ingenient_read_packet,
.flags= AVFMT_GENERIC_INDEX,
.extensions = "cgi", // FIXME
.value = CODEC_ID_MJPEG,
- .priv_class = &ff_rawvideo_demuxer_class,
+ .priv_class = &ingenient_demuxer_class,
};
diff --git a/libavformat/internal.h b/libavformat/internal.h
index aba890def4..a2e80f2de3 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -1,20 +1,20 @@
/*
* copyright (c) 2001 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -37,20 +37,18 @@ typedef struct AVCodecTag {
unsigned int tag;
} AVCodecTag;
-void ff_dynarray_add(intptr_t **tab_ptr, int *nb_ptr, intptr_t elem);
-
#ifdef __GNUC__
#define dynarray_add(tab, nb_ptr, elem)\
do {\
__typeof__(tab) _tab = (tab);\
__typeof__(elem) _elem = (elem);\
(void)sizeof(**_tab == _elem); /* check that types are compatible */\
- ff_dynarray_add((intptr_t **)_tab, nb_ptr, (intptr_t)_elem);\
+ av_dynarray_add(_tab, nb_ptr, _elem);\
} while(0)
#else
#define dynarray_add(tab, nb_ptr, elem)\
do {\
- ff_dynarray_add((intptr_t **)(tab), nb_ptr, (intptr_t)(elem));\
+ av_dynarray_add((tab), nb_ptr, (elem));\
} while(0)
#endif
@@ -225,8 +223,8 @@ int ff_add_index_entry(AVIndexEntry **index_entries,
*
* @return AVChapter or NULL on error
*/
-AVChapter *ff_new_chapter(AVFormatContext *s, int id, AVRational time_base,
- int64_t start, int64_t end, const char *title);
+AVChapter *avpriv_new_chapter(AVFormatContext *s, int id, AVRational time_base,
+ int64_t start, int64_t end, const char *title);
/**
* Ensure the index uses less memory than the maximum specified in
@@ -248,4 +246,9 @@ void ff_make_absolute_url(char *buf, int size, const char *base,
enum CodecID ff_guess_image2_codec(const char *filename);
+/**
+ * Convert a date string in ISO8601 format to Unix timestamp.
+ */
+int64_t ff_iso8601_to_unix_time(const char *datestr);
+
#endif /* AVFORMAT_INTERNAL_H */
diff --git a/libavformat/ipmovie.c b/libavformat/ipmovie.c
index e8ba0643f6..562b19a29c 100644
--- a/libavformat/ipmovie.c
+++ b/libavformat/ipmovie.c
@@ -2,20 +2,20 @@
* Interplay MVE File Demuxer
* Copyright (c) 2003 The ffmpeg Project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -224,7 +224,7 @@ static int process_ipmovie_chunk(IPMVEContext *s, AVIOContext *pb,
return chunk_type;
/* read the next chunk, wherever the file happens to be pointing */
- if (pb->eof_reached)
+ if (url_feof(pb))
return CHUNK_EOF;
if (avio_read(pb, chunk_preamble, CHUNK_PREAMBLE_SIZE) !=
CHUNK_PREAMBLE_SIZE)
@@ -270,7 +270,7 @@ static int process_ipmovie_chunk(IPMVEContext *s, AVIOContext *pb,
while ((chunk_size > 0) && (chunk_type != CHUNK_BAD)) {
/* read the next chunk, wherever the file happens to be pointing */
- if (pb->eof_reached) {
+ if (url_feof(pb)) {
chunk_type = CHUNK_EOF;
break;
}
@@ -530,7 +530,7 @@ static int ipmovie_read_header(AVFormatContext *s,
while (memcmp(signature_buffer, signature, sizeof(signature))) {
memmove(signature_buffer, signature_buffer + 1, sizeof(signature_buffer) - 1);
signature_buffer[sizeof(signature_buffer) - 1] = avio_r8(pb);
- if (pb->eof_reached)
+ if (url_feof(pb))
return AVERROR_EOF;
}
/* initialize private context members */
@@ -559,7 +559,7 @@ static int ipmovie_read_header(AVFormatContext *s,
return AVERROR_INVALIDDATA;
/* initialize the stream decoders */
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
av_set_pts_info(st, 63, 1, 1000000);
@@ -572,7 +572,7 @@ static int ipmovie_read_header(AVFormatContext *s,
st->codec->bits_per_coded_sample = ipmovie->video_bpp;
if (ipmovie->audio_type) {
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
av_set_pts_info(st, 32, 1, ipmovie->audio_sample_rate);
@@ -616,10 +616,10 @@ static int ipmovie_read_packet(AVFormatContext *s,
}
AVInputFormat ff_ipmovie_demuxer = {
- "ipmovie",
- NULL_IF_CONFIG_SMALL("Interplay MVE format"),
- sizeof(IPMVEContext),
- ipmovie_probe,
- ipmovie_read_header,
- ipmovie_read_packet,
+ .name = "ipmovie",
+ .long_name = NULL_IF_CONFIG_SMALL("Interplay MVE format"),
+ .priv_data_size = sizeof(IPMVEContext),
+ .read_probe = ipmovie_probe,
+ .read_header = ipmovie_read_header,
+ .read_packet = ipmovie_read_packet,
};
diff --git a/libavformat/isom.c b/libavformat/isom.c
index eb17e25474..81a89fa405 100644
--- a/libavformat/isom.c
+++ b/libavformat/isom.c
@@ -4,20 +4,20 @@
* Copyright (c) 2002 Francois Revol <revol@free.fr>
* Copyright (c) 2006 Baptiste Coudurier <baptiste.coudurier@free.fr>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -137,11 +137,18 @@ const AVCodecTag codec_movvideo_tags[] = {
{ CODEC_ID_RAWVIDEO, MKTAG('W', 'R', 'A', 'W') },
{ CODEC_ID_H264, MKTAG('a', 'v', 'c', '1') }, /* AVC-1/H.264 */
- { CODEC_ID_H264, MKTAG('a', 'i', '5', '5') }, /* AVC Intra 50 / 1080 interlace */
- { CODEC_ID_H264, MKTAG('a', 'i', '5', 'q') }, /* AVC Intra 50 / 720 */
- { CODEC_ID_H264, MKTAG('a', 'i', '1', '5') }, /* AVC Intra 100 / 1080 interlace */
- { CODEC_ID_H264, MKTAG('a', 'i', '1', 'q') }, /* AVC Intra 100 / 720 */
- { CODEC_ID_H264, MKTAG('a', 'i', '1', '2') }, /* AVC Intra 100 / 1080 */
+ { CODEC_ID_H264, MKTAG('a', 'i', '5', 'p') }, /* AVC-Intra 50M 720p24/30/60 */
+ { CODEC_ID_H264, MKTAG('a', 'i', '5', 'q') }, /* AVC-Intra 50M 720p25/50 */
+ { CODEC_ID_H264, MKTAG('a', 'i', '5', '2') }, /* AVC-Intra 50M 1080p25/50 */
+ { CODEC_ID_H264, MKTAG('a', 'i', '5', '3') }, /* AVC-Intra 50M 1080p24/30/60 */
+ { CODEC_ID_H264, MKTAG('a', 'i', '5', '5') }, /* AVC-Intra 50M 1080i50 */
+ { CODEC_ID_H264, MKTAG('a', 'i', '5', '6') }, /* AVC-Intra 50M 1080i60 */
+ { CODEC_ID_H264, MKTAG('a', 'i', '1', 'p') }, /* AVC-Intra 100M 720p24/30/60 */
+ { CODEC_ID_H264, MKTAG('a', 'i', '1', 'q') }, /* AVC-Intra 100M 720p25/50 */
+ { CODEC_ID_H264, MKTAG('a', 'i', '1', '2') }, /* AVC-Intra 100M 1080p25/50 */
+ { CODEC_ID_H264, MKTAG('a', 'i', '1', '3') }, /* AVC-Intra 100M 1080p24/30/60 */
+ { CODEC_ID_H264, MKTAG('a', 'i', '1', '5') }, /* AVC-Intra 100M 1080i50 */
+ { CODEC_ID_H264, MKTAG('a', 'i', '1', '6') }, /* AVC-Intra 100M 1080i60 */
{ CODEC_ID_MPEG1VIDEO, MKTAG('m', '1', 'v', '1') }, /* Apple MPEG-1 Camcorder */
{ CODEC_ID_MPEG1VIDEO, MKTAG('m', 'p', 'e', 'g') }, /* MPEG */
@@ -197,6 +204,8 @@ const AVCodecTag codec_movvideo_tags[] = {
{ CODEC_ID_DIRAC, MKTAG('d', 'r', 'a', 'c') },
{ CODEC_ID_DNXHD, MKTAG('A', 'V', 'd', 'n') }, /* AVID DNxHD */
+// { CODEC_ID_FLV1, MKTAG('H', '2', '6', '3') }, /* Flash Media Server */
+ { CODEC_ID_MSMPEG4V3, MKTAG('3', 'I', 'V', 'D') }, /* 3ivx DivX Doctor */
{ CODEC_ID_RAWVIDEO, MKTAG('A', 'V', '1', 'x') }, /* AVID 1:1x */
{ CODEC_ID_RAWVIDEO, MKTAG('A', 'V', 'u', 'p') },
{ CODEC_ID_SGI, MKTAG('s', 'g', 'i', ' ') }, /* SGI */
@@ -247,11 +256,13 @@ const AVCodecTag codec_movaudio_tags[] = {
{ CODEC_ID_AC3, MKTAG('s', 'a', 'c', '3') }, /* Nero Recode */
{ CODEC_ID_DTS, MKTAG('d', 't', 's', 'c') }, /* mp4ra.org */
{ CODEC_ID_DTS, MKTAG('D', 'T', 'S', ' ') }, /* non-standard */
+ { CODEC_ID_EAC3, MKTAG('e', 'c', '-', '3') }, /* ETSI TS 102 366 Annex F */
{ CODEC_ID_AMR_NB, MKTAG('s', 'a', 'm', 'r') }, /* AMR-NB 3gp */
{ CODEC_ID_AMR_WB, MKTAG('s', 'a', 'w', 'b') }, /* AMR-WB 3gp */
{ CODEC_ID_GSM, MKTAG('a', 'g', 's', 'm') },
+ { CODEC_ID_NELLYMOSER, MKTAG('n', 'm', 'o', 's') }, /* Flash Media Server */
{ CODEC_ID_ALAC, MKTAG('a', 'l', 'a', 'c') }, /* Apple Lossless */
{ CODEC_ID_QCELP, MKTAG('Q','c','l','p') },
@@ -264,6 +275,8 @@ const AVCodecTag codec_movaudio_tags[] = {
{ CODEC_ID_DVAUDIO, MKTAG('v', 'd', 'v', 'a') },
{ CODEC_ID_DVAUDIO, MKTAG('d', 'v', 'c', 'a') },
+ { CODEC_ID_SPEEX, MKTAG('s','p','e','x') }, /* Flash Media Server */
+
{ CODEC_ID_WMAV2, MKTAG('W', 'M', 'A', '2') },
{ CODEC_ID_NONE, 0 },
@@ -372,6 +385,22 @@ int ff_mp4_read_descr(AVFormatContext *fc, AVIOContext *pb, int *tag)
return len;
}
+void ff_mp4_parse_es_descr(AVIOContext *pb, int *es_id)
+{
+ int flags;
+ if (es_id) *es_id = avio_rb16(pb);
+ else avio_rb16(pb);
+ flags = avio_r8(pb);
+ if (flags & 0x80) //streamDependenceFlag
+ avio_rb16(pb);
+ if (flags & 0x40) { //URL_Flag
+ int len = avio_r8(pb);
+ avio_skip(pb, len);
+ }
+ if (flags & 0x20) //OCRstreamFlag
+ avio_rb16(pb);
+}
+
static const AVCodecTag mp4_audio_types[] = {
{ CODEC_ID_MP3ON4, AOT_PS }, /* old mp3on4 draft */
{ CODEC_ID_MP3ON4, AOT_L1 }, /* layer 1 */
@@ -395,7 +424,7 @@ int ff_mp4_read_dec_config_descr(AVFormatContext *fc, AVStream *st, AVIOContext
len = ff_mp4_read_descr(fc, pb, &tag);
if (tag == MP4DecSpecificDescrTag) {
av_dlog(fc, "Specific MPEG4 header len=%d\n", len);
- if((uint64_t)len > (1<<30))
+ if (!len || (uint64_t)len > (1<<30))
return -1;
av_free(st->codec->extradata);
st->codec->extradata = av_mallocz(len + FF_INPUT_BUFFER_PADDING_SIZE);
@@ -405,11 +434,11 @@ int ff_mp4_read_dec_config_descr(AVFormatContext *fc, AVStream *st, AVIOContext
st->codec->extradata_size = len;
if (st->codec->codec_id == CODEC_ID_AAC) {
MPEG4AudioConfig cfg;
- ff_mpeg4audio_get_config(&cfg, st->codec->extradata,
+ avpriv_mpeg4audio_get_config(&cfg, st->codec->extradata,
st->codec->extradata_size);
st->codec->channels = cfg.channels;
if (cfg.object_type == 29 && cfg.sampling_index < 3) // old mp3on4
- st->codec->sample_rate = ff_mpa_freq_tab[cfg.sampling_index];
+ st->codec->sample_rate = avpriv_mpa_freq_tab[cfg.sampling_index];
else if (cfg.ext_sample_rate)
st->codec->sample_rate = cfg.ext_sample_rate;
else
@@ -425,3 +454,87 @@ int ff_mp4_read_dec_config_descr(AVFormatContext *fc, AVStream *st, AVIOContext
}
return 0;
}
+
+typedef struct MovChannelLayout {
+ int64_t channel_layout;
+ uint32_t layout_tag;
+} MovChannelLayout;
+
+static const MovChannelLayout mov_channel_layout[] = {
+ { AV_CH_LAYOUT_MONO, (100<<16) | 1}, // kCAFChannelLayoutTag_Mono
+ { AV_CH_LAYOUT_STEREO, (101<<16) | 2}, // kCAFChannelLayoutTag_Stereo
+ { AV_CH_LAYOUT_STEREO, (102<<16) | 2}, // kCAFChannelLayoutTag_StereoHeadphones
+ { AV_CH_LAYOUT_2_1, (131<<16) | 3}, // kCAFChannelLayoutTag_ITU_2_1
+ { AV_CH_LAYOUT_QUAD, (132<<16) | 4}, // kCAFChannelLayoutTag_ITU_2_2
+ { AV_CH_LAYOUT_2_2, (132<<16) | 4}, // kCAFChannelLayoutTag_ITU_2_2
+ { AV_CH_LAYOUT_QUAD, (108<<16) | 4}, // kCAFChannelLayoutTag_Quadraphonic
+ { AV_CH_LAYOUT_SURROUND, (113<<16) | 3}, // kCAFChannelLayoutTag_MPEG_3_0_A
+ { AV_CH_LAYOUT_4POINT0, (115<<16) | 4}, // kCAFChannelLayoutTag_MPEG_4_0_A
+ { AV_CH_LAYOUT_5POINT0_BACK, (117<<16) | 5}, // kCAFChannelLayoutTag_MPEG_5_0_A
+ { AV_CH_LAYOUT_5POINT0, (117<<16) | 5}, // kCAFChannelLayoutTag_MPEG_5_0_A
+ { AV_CH_LAYOUT_5POINT1_BACK, (121<<16) | 6}, // kCAFChannelLayoutTag_MPEG_5_1_A
+ { AV_CH_LAYOUT_5POINT1, (121<<16) | 6}, // kCAFChannelLayoutTag_MPEG_5_1_A
+ { AV_CH_LAYOUT_7POINT1, (128<<16) | 8}, // kCAFChannelLayoutTag_MPEG_7_1_C
+ { AV_CH_LAYOUT_7POINT1_WIDE, (126<<16) | 8}, // kCAFChannelLayoutTag_MPEG_7_1_A
+ { AV_CH_LAYOUT_5POINT1_BACK|AV_CH_LAYOUT_STEREO_DOWNMIX, (130<<16) | 8}, // kCAFChannelLayoutTag_SMPTE_DTV
+ { AV_CH_LAYOUT_STEREO|AV_CH_LOW_FREQUENCY, (133<<16) | 3}, // kCAFChannelLayoutTag_DVD_4
+ { AV_CH_LAYOUT_2_1|AV_CH_LOW_FREQUENCY, (134<<16) | 4}, // kCAFChannelLayoutTag_DVD_5
+ { AV_CH_LAYOUT_QUAD|AV_CH_LOW_FREQUENCY, (135<<16) | 4}, // kCAFChannelLayoutTag_DVD_6
+ { AV_CH_LAYOUT_2_2|AV_CH_LOW_FREQUENCY, (135<<16) | 4}, // kCAFChannelLayoutTag_DVD_6
+ { AV_CH_LAYOUT_SURROUND|AV_CH_LOW_FREQUENCY, (136<<16) | 4}, // kCAFChannelLayoutTag_DVD_10
+ { AV_CH_LAYOUT_4POINT0|AV_CH_LOW_FREQUENCY, (137<<16) | 5}, // kCAFChannelLayoutTag_DVD_11
+ { 0, 0},
+};
+
+void ff_mov_read_chan(AVFormatContext *s, int64_t size, AVCodecContext *codec)
+{
+ uint32_t layout_tag;
+ AVIOContext *pb = s->pb;
+ const MovChannelLayout *layouts = mov_channel_layout;
+ layout_tag = avio_rb32(pb);
+ size -= 4;
+ if (layout_tag == 0) { // kCAFChannelLayoutTag_UseChannelDescriptions
+ // Channel descriptions not implemented
+ av_log_ask_for_sample(s, "Unimplemented container channel layout.\n");
+ avio_skip(pb, size);
+ return;
+ }
+ if (layout_tag == 0x10000) { // kCAFChannelLayoutTag_UseChannelBitmap
+ codec->channel_layout = avio_rb32(pb);
+ size -= 4;
+ avio_skip(pb, size);
+ return;
+ }
+ while (layouts->channel_layout) {
+ if (layout_tag == layouts->layout_tag) {
+ codec->channel_layout = layouts->channel_layout;
+ break;
+ }
+ layouts++;
+ }
+ if (!codec->channel_layout)
+ av_log(s, AV_LOG_WARNING, "Unknown container channel layout.\n");
+ avio_skip(pb, size);
+}
+
+void ff_mov_write_chan(AVIOContext *pb, int64_t channel_layout)
+{
+ const MovChannelLayout *layouts;
+ uint32_t layout_tag = 0;
+
+ for (layouts = mov_channel_layout; layouts->channel_layout; layouts++)
+ if (channel_layout == layouts->channel_layout) {
+ layout_tag = layouts->layout_tag;
+ break;
+ }
+
+ if (layout_tag) {
+ avio_wb32(pb, layout_tag); // mChannelLayoutTag
+ avio_wb32(pb, 0); // mChannelBitmap
+ } else {
+ avio_wb32(pb, 0x10000); // kCAFChannelLayoutTag_UseChannelBitmap
+ avio_wb32(pb, channel_layout);
+ }
+ avio_wb32(pb, 0); // mNumberChannelDescriptions
+}
+
diff --git a/libavformat/isom.h b/libavformat/isom.h
index ef3fe1484f..7fc2b546f8 100644
--- a/libavformat/isom.h
+++ b/libavformat/isom.h
@@ -4,20 +4,20 @@
* copyright (c) 2002 Francois Revol <revol@free.fr>
* copyright (c) 2006 Baptiste Coudurier <baptiste.coudurier@free.fr>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -146,6 +146,7 @@ typedef struct MOVContext {
int ff_mp4_read_descr_len(AVIOContext *pb);
int ff_mp4_read_descr(AVFormatContext *fc, AVIOContext *pb, int *tag);
int ff_mp4_read_dec_config_descr(AVFormatContext *fc, AVStream *st, AVIOContext *pb);
+void ff_mp4_parse_es_descr(AVIOContext *pb, int *es_id);
#define MP4IODescrTag 0x02
#define MP4ESDescrTag 0x03
@@ -156,5 +157,7 @@ int ff_mov_read_esds(AVFormatContext *fc, AVIOContext *pb, MOVAtom atom);
enum CodecID ff_mov_get_lpcm_codec_id(int bps, int flags);
int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries);
+void ff_mov_read_chan(AVFormatContext *s, int64_t size, AVCodecContext *codec);
+void ff_mov_write_chan(AVIOContext *pb, int64_t channel_layout);
#endif /* AVFORMAT_ISOM_H */
diff --git a/libavformat/iss.c b/libavformat/iss.c
index fe5203dbcd..4b6314d5b9 100644
--- a/libavformat/iss.c
+++ b/libavformat/iss.c
@@ -2,20 +2,20 @@
* ISS (.iss) file demuxer
* Copyright (c) 2008 Jaikrishnan Menon <realityman@gmx.net>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -23,8 +23,7 @@
* @file
* Funcom ISS file demuxer
* @author Jaikrishnan Menon
- * for more information on the .iss file format, visit:
- * http://wiki.multimedia.cx/index.php?title=FunCom_ISS
+ * @see http://wiki.multimedia.cx/index.php?title=FunCom_ISS
*/
#include "avformat.h"
@@ -89,7 +88,7 @@ static av_cold int iss_read_header(AVFormatContext *s, AVFormatParameters *ap)
iss->sample_start_pos = avio_tell(pb);
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
@@ -123,11 +122,11 @@ static int iss_read_packet(AVFormatContext *s, AVPacket *pkt)
}
AVInputFormat ff_iss_demuxer = {
- "ISS",
- NULL_IF_CONFIG_SMALL("Funcom ISS format"),
- sizeof(IssDemuxContext),
- iss_probe,
- iss_read_header,
- iss_read_packet,
+ .name = "ISS",
+ .long_name = NULL_IF_CONFIG_SMALL("Funcom ISS format"),
+ .priv_data_size = sizeof(IssDemuxContext),
+ .read_probe = iss_probe,
+ .read_header = iss_read_header,
+ .read_packet = iss_read_packet,
};
diff --git a/libavformat/iv8.c b/libavformat/iv8.c
index 22e60cf8f0..03593982bf 100644
--- a/libavformat/iv8.c
+++ b/libavformat/iv8.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2009 Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -40,7 +40,7 @@ static int read_header(AVFormatContext *s, AVFormatParameters *ap)
{
AVStream *st;
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
@@ -85,12 +85,11 @@ retry:
}
AVInputFormat ff_iv8_demuxer = {
- "iv8",
- NULL_IF_CONFIG_SMALL("A format generated by IndigoVision 8000 video server"),
- 0,
- probe,
- read_header,
- read_packet,
+ .name = "iv8",
+ .long_name = NULL_IF_CONFIG_SMALL("A format generated by IndigoVision 8000 video server"),
+ .read_probe = probe,
+ .read_header = read_header,
+ .read_packet = read_packet,
.flags= AVFMT_GENERIC_INDEX,
.value = CODEC_ID_MPEG4,
};
diff --git a/libavformat/ivfdec.c b/libavformat/ivfdec.c
index 390173105a..cc7687e4da 100644
--- a/libavformat/ivfdec.c
+++ b/libavformat/ivfdec.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2010 David Conrad
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -40,7 +40,7 @@ static int read_header(AVFormatContext *s, AVFormatParameters *ap)
avio_rl16(s->pb); // version
avio_rl16(s->pb); // header size
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
@@ -80,12 +80,11 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt)
}
AVInputFormat ff_ivf_demuxer = {
- "ivf",
- NULL_IF_CONFIG_SMALL("On2 IVF"),
- 0,
- probe,
- read_header,
- read_packet,
+ .name = "ivf",
+ .long_name = NULL_IF_CONFIG_SMALL("On2 IVF"),
+ .read_probe = probe,
+ .read_header = read_header,
+ .read_packet = read_packet,
.flags= AVFMT_GENERIC_INDEX,
.codec_tag = (const AVCodecTag*[]){ff_codec_bmp_tags, 0},
};
diff --git a/libavformat/ivfenc.c b/libavformat/ivfenc.c
index 55ce58615b..5fffaf7959 100644
--- a/libavformat/ivfenc.c
+++ b/libavformat/ivfenc.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2010 Reimar Döffinger
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avformat.h"
diff --git a/libavformat/jvdec.c b/libavformat/jvdec.c
index d4008f7148..7e1a6ce7b4 100644
--- a/libavformat/jvdec.c
+++ b/libavformat/jvdec.c
@@ -2,20 +2,20 @@
* Bitmap Brothers JV demuxer
* Copyright (c) 2005, 2011 Peter Ross <pross@xvid.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -69,8 +69,8 @@ static int read_header(AVFormatContext *s,
avio_skip(pb, 80);
- ast = av_new_stream(s, 0);
- vst = av_new_stream(s, 1);
+ ast = avformat_new_stream(s, NULL);
+ vst = avformat_new_stream(s, NULL);
if (!ast || !vst)
return AVERROR(ENOMEM);
@@ -139,7 +139,7 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt)
AVIOContext *pb = s->pb;
AVStream *ast = s->streams[0];
- while (!s->pb->eof_reached && jv->pts < ast->nb_index_entries) {
+ while (!url_feof(s->pb) && jv->pts < ast->nb_index_entries) {
const AVIndexEntry *e = ast->index_entries + jv->pts;
const JVFrame *jvf = jv->frames + jv->pts;
@@ -207,10 +207,11 @@ static int read_seek(AVFormatContext *s, int stream_index,
if (i < 0 || i >= ast->nb_index_entries)
return 0;
+ if (avio_seek(s->pb, ast->index_entries[i].pos, SEEK_SET) < 0)
+ return -1;
jv->state = JV_AUDIO;
jv->pts = i;
- avio_seek(s->pb, ast->index_entries[i].pos, SEEK_SET);
return 0;
}
diff --git a/libavformat/latmenc.c b/libavformat/latmenc.c
new file mode 100644
index 0000000000..56522106d6
--- /dev/null
+++ b/libavformat/latmenc.c
@@ -0,0 +1,198 @@
+/*
+ * LATM/LOAS muxer
+ * Copyright (c) 2011 Kieran Kunhya <kieran@kunhya.com>
+ *
+ * This file is part of Libav.
+ *
+ * Libav 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.
+ *
+ * Libav 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavcodec/get_bits.h"
+#include "libavcodec/put_bits.h"
+#include "libavcodec/avcodec.h"
+#include "libavcodec/mpeg4audio.h"
+#include "libavutil/opt.h"
+#include "avformat.h"
+#include "rawenc.h"
+
+typedef struct {
+ AVClass *av_class;
+ int off;
+ int channel_conf;
+ int object_type;
+ int counter;
+ int mod;
+} LATMContext;
+
+static const AVOption options[] = {
+ {"smc-interval", "StreamMuxConfig interval.",
+ offsetof(LATMContext, mod), AV_OPT_TYPE_INT, {.dbl = 0x0014}, 0x0001, 0xffff, AV_OPT_FLAG_ENCODING_PARAM},
+ {NULL},
+};
+
+static const AVClass latm_muxer_class = {
+ .class_name = "LATM/LOAS muxer",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
+static int latm_decode_extradata(LATMContext *ctx, uint8_t *buf, int size)
+{
+ GetBitContext gb;
+ MPEG4AudioConfig m4ac;
+
+ init_get_bits(&gb, buf, size * 8);
+ ctx->off = avpriv_mpeg4audio_get_config(&m4ac, buf, size);
+ if (ctx->off < 0)
+ return ctx->off;
+ skip_bits_long(&gb, ctx->off);
+
+ /* FIXME: are any formats not allowed in LATM? */
+
+ if (m4ac.object_type > AOT_SBR && m4ac.object_type != AOT_ALS) {
+ av_log(ctx, AV_LOG_ERROR, "Muxing MPEG-4 AOT %d in LATM is not supported\n", m4ac.object_type);
+ return AVERROR_INVALIDDATA;
+ }
+ ctx->channel_conf = m4ac.chan_config;
+ ctx->object_type = m4ac.object_type;
+
+ return 0;
+}
+
+static int latm_write_header(AVFormatContext *s)
+{
+ LATMContext *ctx = s->priv_data;
+ AVCodecContext *avctx = s->streams[0]->codec;
+
+ if (avctx->codec_id == CODEC_ID_AAC_LATM)
+ return 0;
+
+ if (avctx->extradata_size > 0 &&
+ latm_decode_extradata(ctx, avctx->extradata, avctx->extradata_size) < 0)
+ return AVERROR_INVALIDDATA;
+
+ return 0;
+}
+
+static int latm_write_frame_header(AVFormatContext *s, PutBitContext *bs)
+{
+ LATMContext *ctx = s->priv_data;
+ AVCodecContext *avctx = s->streams[0]->codec;
+ GetBitContext gb;
+ int header_size;
+
+ /* AudioMuxElement */
+ put_bits(bs, 1, !!ctx->counter);
+
+ if (!ctx->counter) {
+ init_get_bits(&gb, avctx->extradata, avctx->extradata_size * 8);
+
+ /* StreamMuxConfig */
+ put_bits(bs, 1, 0); /* audioMuxVersion */
+ put_bits(bs, 1, 1); /* allStreamsSameTimeFraming */
+ put_bits(bs, 6, 0); /* numSubFrames */
+ put_bits(bs, 4, 0); /* numProgram */
+ put_bits(bs, 3, 0); /* numLayer */
+
+ /* AudioSpecificConfig */
+ if (ctx->object_type == AOT_ALS) {
+ header_size = avctx->extradata_size-(ctx->off + 7) >> 3;
+ avpriv_copy_bits(bs, &avctx->extradata[ctx->off], header_size);
+ } else {
+ avpriv_copy_bits(bs, avctx->extradata, ctx->off + 3);
+
+ if (!ctx->channel_conf) {
+ avpriv_copy_pce_data(bs, &gb);
+ }
+ }
+
+ put_bits(bs, 3, 0); /* frameLengthType */
+ put_bits(bs, 8, 0xff); /* latmBufferFullness */
+
+ put_bits(bs, 1, 0); /* otherDataPresent */
+ put_bits(bs, 1, 0); /* crcCheckPresent */
+ }
+
+ ctx->counter++;
+ ctx->counter %= ctx->mod;
+
+ return 0;
+}
+
+static int latm_write_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ AVIOContext *pb = s->pb;
+ PutBitContext bs;
+ int i, len;
+ uint8_t loas_header[] = "\x56\xe0\x00";
+ uint8_t *buf;
+
+ if (s->streams[0]->codec->codec_id == CODEC_ID_AAC_LATM)
+ return ff_raw_write_packet(s, pkt);
+
+ if (pkt->size > 2 && pkt->data[0] == 0xff && (pkt->data[1] >> 4) == 0xf) {
+ av_log(s, AV_LOG_ERROR, "ADTS header detected - ADTS will not be incorrectly muxed into LATM\n");
+ return AVERROR_INVALIDDATA;
+ }
+
+ buf = av_malloc(pkt->size+1024);
+ if (!buf)
+ return AVERROR(ENOMEM);
+
+ init_put_bits(&bs, buf, pkt->size+1024);
+
+ latm_write_frame_header(s, &bs);
+
+ /* PayloadLengthInfo() */
+ for (i = 0; i <= pkt->size-255; i+=255)
+ put_bits(&bs, 8, 255);
+
+ put_bits(&bs, 8, pkt->size-i);
+
+ /* The LATM payload is written unaligned */
+
+ /* PayloadMux() */
+ for (i = 0; i < pkt->size; i++)
+ put_bits(&bs, 8, pkt->data[i]);
+
+ avpriv_align_put_bits(&bs);
+ flush_put_bits(&bs);
+
+ len = put_bits_count(&bs) >> 3;
+
+ loas_header[1] |= (len >> 8) & 0x1f;
+ loas_header[2] |= len & 0xff;
+
+ avio_write(pb, loas_header, 3);
+ avio_write(pb, buf, len);
+
+ av_free(buf);
+
+ return 0;
+}
+
+AVOutputFormat ff_latm_muxer = {
+ .name = "latm",
+ .long_name = NULL_IF_CONFIG_SMALL("LOAS/LATM"),
+ .mime_type = "audio/MP4A-LATM",
+ .extensions = "latm,loas",
+ .priv_data_size = sizeof(LATMContext),
+ .audio_codec = CODEC_ID_AAC,
+ .video_codec = CODEC_ID_NONE,
+ .write_header = latm_write_header,
+ .write_packet = latm_write_packet,
+ .priv_class = &latm_muxer_class,
+};
diff --git a/libavformat/libavformat.v b/libavformat/libavformat.v
index 0ec1c3c4de..7ed2d76647 100644
--- a/libavformat/libavformat.v
+++ b/libavformat/libavformat.v
@@ -1,7 +1,27 @@
LIBAVFORMAT_$MAJOR {
- global: *;
- local:
- ff_*_demuxer;
- ff_*_muxer;
- ff_*_protocol;
+ global: av*;
+ #FIXME those are for avserver
+ ff_inet_aton;
+ ff_socket_nonblock;
+ ffm_set_write_index;
+ ffm_read_write_index;
+ ffm_write_write_index;
+ ff_rtsp_parse_line;
+ ff_rtp_get_local_rtp_port;
+ ff_rtp_get_local_rtcp_port;
+ ffio_open_dyn_packet_buf;
+ url_open;
+ url_close;
+ url_write;
+ url_get_max_packet_size;
+ #those are deprecated, remove on next bump
+ find_info_tag;
+ parse_date;
+ dump_format;
+ url_*;
+ ff_timefilter_destroy;
+ ff_timefilter_new;
+ ff_timefilter_update;
+ ff_timefilter_reset;
+ local: *;
};
diff --git a/libavformat/libmodplug.c b/libavformat/libmodplug.c
new file mode 100644
index 0000000000..8b4e4f3bcd
--- /dev/null
+++ b/libavformat/libmodplug.c
@@ -0,0 +1,367 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+* @file
+* ModPlug demuxer
+* @todo better probing than extensions matching
+*/
+
+#include <libmodplug/modplug.h>
+#include "libavutil/avstring.h"
+#include "libavutil/eval.h"
+#include "libavutil/opt.h"
+#include "avformat.h"
+
+typedef struct ModPlugContext {
+ const AVClass *class;
+ ModPlugFile *f;
+ uint8_t *buf; ///< input file content
+
+ /* options */
+ int noise_reduction;
+ int reverb_depth;
+ int reverb_delay;
+ int bass_amount;
+ int bass_range;
+ int surround_depth;
+ int surround_delay;
+
+ int max_size; ///< max file size to allocate
+
+ /* optional video stream */
+ double ts_per_packet; ///< used to define the pts/dts using packet_count;
+ int packet_count; ///< total number of audio packets
+ int print_textinfo; ///< bool flag for printing speed, tempo, order, ...
+ int video_stream; ///< 1 if the user want a video stream, otherwise 0
+ int w; ///< video stream width in char (one char = 8x8px)
+ int h; ///< video stream height in char (one char = 8x8px)
+ int video_switch; ///< 1 if current packet is video, otherwise 0
+ int fsize; ///< constant frame size
+ int linesize; ///< line size in bytes
+ char *color_eval; ///< color eval user input expression
+ AVExpr *expr; ///< parsed color eval expression
+} ModPlugContext;
+
+static const char *var_names[] = {
+ "x", "y",
+ "w", "h",
+ "t",
+ "speed", "tempo", "order", "pattern", "row",
+ NULL
+};
+
+enum var_name {
+ VAR_X, VAR_Y,
+ VAR_W, VAR_H,
+ VAR_TIME,
+ VAR_SPEED, VAR_TEMPO, VAR_ORDER, VAR_PATTERN, VAR_ROW,
+ VAR_VARS_NB
+};
+
+#define FF_MODPLUG_MAX_FILE_SIZE (100 * 1<<20) // 100M
+#define FF_MODPLUG_DEF_FILE_SIZE ( 5 * 1<<20) // 5M
+
+#define OFFSET(x) offsetof(ModPlugContext, x)
+#define D AV_OPT_FLAG_DECODING_PARAM
+static const AVOption options[] = {
+ {"noise_reduction", "Enable noise reduction 0(off)-1(on)", OFFSET(noise_reduction), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 1, D},
+ {"reverb_depth", "Reverb level 0(quiet)-100(loud)", OFFSET(reverb_depth), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 100, D},
+ {"reverb_delay", "Reverb delay in ms, usually 40-200ms", OFFSET(reverb_delay), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, D},
+ {"bass_amount", "XBass level 0(quiet)-100(loud)", OFFSET(bass_amount), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 100, D},
+ {"bass_range", "XBass cutoff in Hz 10-100", OFFSET(bass_range), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 100, D},
+ {"surround_depth", "Surround level 0(quiet)-100(heavy)", OFFSET(surround_depth), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 100, D},
+ {"surround_delay", "Surround delay in ms, usually 5-40ms", OFFSET(surround_delay), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, D},
+ {"max_size", "Max file size supported (in bytes). Default is 5MB. Set to 0 for no limit (not recommended)",
+ OFFSET(max_size), AV_OPT_TYPE_INT, {.dbl = FF_MODPLUG_DEF_FILE_SIZE}, 0, FF_MODPLUG_MAX_FILE_SIZE, D},
+ {"video_stream_expr", "Color formula", OFFSET(color_eval), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, D},
+ {"video_stream", "Make demuxer output a video stream", OFFSET(video_stream), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 1, D},
+ {"video_stream_w", "Video stream width in char (one char = 8x8px)", OFFSET(w), AV_OPT_TYPE_INT, {.dbl = 30}, 20, 512, D},
+ {"video_stream_h", "Video stream height in char (one char = 8x8px)", OFFSET(h), AV_OPT_TYPE_INT, {.dbl = 30}, 20, 512, D},
+ {"video_stream_ptxt", "Print speed, tempo, order, ... in video stream", OFFSET(print_textinfo), AV_OPT_TYPE_INT, {.dbl = 1}, 0, 1, D},
+ {NULL},
+};
+
+#define SET_OPT_IF_REQUESTED(libopt, opt, flag) do { \
+ if (modplug->opt) { \
+ settings.libopt = modplug->opt; \
+ settings.mFlags |= flag; \
+ } \
+} while (0)
+
+#define ADD_META_MULTIPLE_ENTRIES(entry_name, fname) do { \
+ if (n_## entry_name ##s) { \
+ unsigned i, n = 0; \
+ \
+ for (i = 0; i < n_## entry_name ##s; i++) { \
+ char item_name[64] = {0}; \
+ fname(f, i, item_name); \
+ if (!*item_name) \
+ continue; \
+ if (n) \
+ av_dict_set(&s->metadata, #entry_name, "\n", AV_DICT_APPEND); \
+ av_dict_set(&s->metadata, #entry_name, item_name, AV_DICT_APPEND); \
+ n++; \
+ } \
+ \
+ extra = av_asprintf(", %u/%u " #entry_name "%s", \
+ n, n_## entry_name ##s, n > 1 ? "s" : ""); \
+ if (!extra) \
+ return AVERROR(ENOMEM); \
+ av_dict_set(&s->metadata, "extra info", extra, AV_DICT_APPEND); \
+ av_free(extra); \
+ } \
+} while (0)
+
+static int modplug_load_metadata(AVFormatContext *s)
+{
+ ModPlugContext *modplug = s->priv_data;
+ ModPlugFile *f = modplug->f;
+ char *extra;
+ const char *name = ModPlug_GetName(f);
+ const char *msg = ModPlug_GetMessage(f);
+
+ unsigned n_instruments = ModPlug_NumInstruments(f);
+ unsigned n_samples = ModPlug_NumSamples(f);
+ unsigned n_patterns = ModPlug_NumPatterns(f);
+ unsigned n_channels = ModPlug_NumChannels(f);
+
+ if (name && *name) av_dict_set(&s->metadata, "name", name, 0);
+ if (msg && *msg) av_dict_set(&s->metadata, "message", msg, 0);
+
+ extra = av_asprintf("%u pattern%s, %u channel%s",
+ n_patterns, n_patterns > 1 ? "s" : "",
+ n_channels, n_channels > 1 ? "s" : "");
+ if (!extra)
+ return AVERROR(ENOMEM);
+ av_dict_set(&s->metadata, "extra info", extra, AV_DICT_DONT_STRDUP_VAL);
+
+ ADD_META_MULTIPLE_ENTRIES(instrument, ModPlug_InstrumentName);
+ ADD_META_MULTIPLE_ENTRIES(sample, ModPlug_SampleName);
+
+ return 0;
+}
+
+#define AUDIO_PKT_SIZE 512
+
+static int modplug_read_header(AVFormatContext *s, AVFormatParameters *ap)
+{
+ AVStream *st;
+ AVIOContext *pb = s->pb;
+ ModPlug_Settings settings;
+ ModPlugContext *modplug = s->priv_data;
+ int sz = avio_size(pb);
+
+ if (sz < 0) {
+ av_log(s, AV_LOG_WARNING, "Could not determine file size\n");
+ sz = modplug->max_size;
+ } else if (modplug->max_size && sz > modplug->max_size) {
+ sz = modplug->max_size;
+ av_log(s, AV_LOG_WARNING, "Max file size reach%s, allocating %dB "
+ "but demuxing is likely to fail due to incomplete buffer\n",
+ sz == FF_MODPLUG_DEF_FILE_SIZE ? " (see -max_size)" : "", sz);
+ }
+
+ if (modplug->color_eval) {
+ int r = av_expr_parse(&modplug->expr, modplug->color_eval, var_names,
+ NULL, NULL, NULL, NULL, 0, s);
+ if (r < 0)
+ return r;
+ }
+
+ modplug->buf = av_malloc(modplug->max_size);
+ if (!modplug->buf)
+ return AVERROR(ENOMEM);
+ sz = avio_read(pb, modplug->buf, sz);
+
+ ModPlug_GetSettings(&settings);
+ settings.mChannels = 2;
+ settings.mBits = 16;
+ settings.mFrequency = 44100;
+ settings.mResamplingMode = MODPLUG_RESAMPLE_FIR; // best quality
+ settings.mLoopCount = 0; // prevents looping forever
+
+ if (modplug->noise_reduction) settings.mFlags |= MODPLUG_ENABLE_NOISE_REDUCTION;
+ SET_OPT_IF_REQUESTED(mReverbDepth, reverb_depth, MODPLUG_ENABLE_REVERB);
+ SET_OPT_IF_REQUESTED(mReverbDelay, reverb_delay, MODPLUG_ENABLE_REVERB);
+ SET_OPT_IF_REQUESTED(mBassAmount, bass_amount, MODPLUG_ENABLE_MEGABASS);
+ SET_OPT_IF_REQUESTED(mBassRange, bass_range, MODPLUG_ENABLE_MEGABASS);
+ SET_OPT_IF_REQUESTED(mSurroundDepth, surround_depth, MODPLUG_ENABLE_SURROUND);
+ SET_OPT_IF_REQUESTED(mSurroundDelay, surround_delay, MODPLUG_ENABLE_SURROUND);
+
+ if (modplug->reverb_depth) settings.mReverbDepth = modplug->reverb_depth;
+ if (modplug->reverb_delay) settings.mReverbDelay = modplug->reverb_delay;
+ if (modplug->bass_amount) settings.mBassAmount = modplug->bass_amount;
+ if (modplug->bass_range) settings.mBassRange = modplug->bass_range;
+ if (modplug->surround_depth) settings.mSurroundDepth = modplug->surround_depth;
+ if (modplug->surround_delay) settings.mSurroundDelay = modplug->surround_delay;
+
+ ModPlug_SetSettings(&settings);
+
+ modplug->f = ModPlug_Load(modplug->buf, sz);
+ if (!modplug->f)
+ return AVERROR_INVALIDDATA;
+
+ st = av_new_stream(s, 0);
+ if (!st)
+ return AVERROR(ENOMEM);
+ av_set_pts_info(st, 64, 1, 1000);
+ st->duration = ModPlug_GetLength(modplug->f);
+ st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
+ st->codec->codec_id = CODEC_ID_PCM_S16LE;
+ st->codec->channels = settings.mChannels;
+ st->codec->sample_rate = settings.mFrequency;
+
+ // timebase = 1/1000, 2ch 16bits 44.1kHz-> 2*2*44100
+ modplug->ts_per_packet = 1000*AUDIO_PKT_SIZE / (4*44100.);
+
+ if (modplug->video_stream) {
+ AVStream *vst = av_new_stream(s, 1);
+ if (!vst)
+ return AVERROR(ENOMEM);
+ av_set_pts_info(vst, 64, 1, 1000);
+ vst->duration = st->duration;
+ vst->codec->codec_type = AVMEDIA_TYPE_VIDEO;
+ vst->codec->codec_id = CODEC_ID_XBIN;
+ vst->codec->width = modplug->w << 3;
+ vst->codec->height = modplug->h << 3;
+ modplug->linesize = modplug->w * 3;
+ modplug->fsize = modplug->linesize * modplug->h;
+ }
+
+ return modplug_load_metadata(s);
+}
+
+static void write_text(uint8_t *dst, const char *s, int linesize, int x, int y)
+{
+ int i;
+ dst += y*linesize + x*3;
+ for (i = 0; s[i]; i++, dst += 3) {
+ dst[0] = 0x0; // count - 1
+ dst[1] = s[i]; // char
+ dst[2] = 0x0f; // background / foreground
+ }
+}
+
+#define PRINT_INFO(line, name, idvalue) do { \
+ snprintf(intbuf, sizeof(intbuf), "%.0f", var_values[idvalue]); \
+ write_text(pkt->data, name ":", modplug->linesize, 0+1, line+1); \
+ write_text(pkt->data, intbuf, modplug->linesize, 10+1, line+1); \
+} while (0)
+
+static int modplug_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ ModPlugContext *modplug = s->priv_data;
+
+ if (modplug->video_stream) {
+ modplug->video_switch ^= 1; // one video packet for one audio packet
+ if (modplug->video_switch) {
+ double var_values[VAR_VARS_NB];
+
+ var_values[VAR_W ] = modplug->w;
+ var_values[VAR_H ] = modplug->h;
+ var_values[VAR_TIME ] = modplug->packet_count * modplug->ts_per_packet;
+ var_values[VAR_SPEED ] = ModPlug_GetCurrentSpeed (modplug->f);
+ var_values[VAR_TEMPO ] = ModPlug_GetCurrentTempo (modplug->f);
+ var_values[VAR_ORDER ] = ModPlug_GetCurrentOrder (modplug->f);
+ var_values[VAR_PATTERN] = ModPlug_GetCurrentPattern(modplug->f);
+ var_values[VAR_ROW ] = ModPlug_GetCurrentRow (modplug->f);
+
+ if (av_new_packet(pkt, modplug->fsize) < 0)
+ return AVERROR(ENOMEM);
+ pkt->stream_index = 1;
+ memset(pkt->data, 0, modplug->fsize);
+
+ if (modplug->print_textinfo) {
+ char intbuf[32];
+ PRINT_INFO(0, "speed", VAR_SPEED);
+ PRINT_INFO(1, "tempo", VAR_TEMPO);
+ PRINT_INFO(2, "order", VAR_ORDER);
+ PRINT_INFO(3, "pattern", VAR_PATTERN);
+ PRINT_INFO(4, "row", VAR_ROW);
+ PRINT_INFO(5, "ts", VAR_TIME);
+ }
+
+ if (modplug->expr) {
+ int x, y;
+ for (y = 0; y < modplug->h; y++) {
+ for (x = 0; x < modplug->w; x++) {
+ double color;
+ var_values[VAR_X] = x;
+ var_values[VAR_Y] = y;
+ color = av_expr_eval(modplug->expr, var_values, NULL);
+ pkt->data[y*modplug->linesize + x*3 + 2] |= av_clip((int)color, 0, 0xf)<<4;
+ }
+ }
+ }
+ pkt->pts = pkt->dts = var_values[VAR_TIME];
+ pkt->flags |= AV_PKT_FLAG_KEY;
+ return 0;
+ }
+ }
+
+ if (av_new_packet(pkt, AUDIO_PKT_SIZE) < 0)
+ return AVERROR(ENOMEM);
+
+ if (modplug->video_stream)
+ pkt->pts = pkt->dts = modplug->packet_count++ * modplug->ts_per_packet;
+
+ pkt->size = ModPlug_Read(modplug->f, pkt->data, AUDIO_PKT_SIZE);
+ if (pkt->size <= 0) {
+ av_free_packet(pkt);
+ return pkt->size == 0 ? AVERROR_EOF : AVERROR(EIO);
+ }
+ return 0;
+}
+
+static int modplug_read_close(AVFormatContext *s)
+{
+ ModPlugContext *modplug = s->priv_data;
+ ModPlug_Unload(modplug->f);
+ av_freep(&modplug->buf);
+ return 0;
+}
+
+static int modplug_read_seek(AVFormatContext *s, int stream_idx, int64_t ts, int flags)
+{
+ ModPlugContext *modplug = s->priv_data;
+ ModPlug_Seek(modplug->f, (int)ts);
+ if (modplug->video_stream)
+ modplug->packet_count = ts / modplug->ts_per_packet;
+ return 0;
+}
+
+static const AVClass modplug_class = {
+ .class_name = "ModPlug demuxer",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
+AVInputFormat ff_libmodplug_demuxer = {
+ .name = "libmodplug",
+ .long_name = NULL_IF_CONFIG_SMALL("ModPlug demuxer"),
+ .priv_data_size = sizeof(ModPlugContext),
+ .read_header = modplug_read_header,
+ .read_packet = modplug_read_packet,
+ .read_close = modplug_read_close,
+ .read_seek = modplug_read_seek,
+ .extensions = "669,abc,amf,ams,dbm,dmf,dsm,far,it,mdl,med,mid,mod,mt2,mtm,okt,psm,ptm,s3m,stm,ult,umx,xm"
+ ",itgz,itr,itz,mdgz,mdr,mdz,s3gz,s3r,s3z,xmgz,xmr,xmz", // compressed mods
+ .priv_class = &modplug_class,
+};
diff --git a/libavformat/libnut.c b/libavformat/libnut.c
index 76a621a2d7..7628abdfb8 100644
--- a/libavformat/libnut.c
+++ b/libavformat/libnut.c
@@ -2,20 +2,20 @@
* NUT (de)muxing via libnut
* copyright (c) 2006 Oded Shimon <ods15@ods15.dyndns.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -151,16 +151,16 @@ static int nut_write_trailer(AVFormatContext * avf) {
}
AVOutputFormat ff_libnut_muxer = {
- "libnut",
- "nut format",
- "video/x-nut",
- "nut",
- sizeof(NUTContext),
- CODEC_ID_VORBIS,
- CODEC_ID_MPEG4,
- nut_write_header,
- nut_write_packet,
- nut_write_trailer,
+ .name = "libnut",
+ .long_name = "nut format",
+ .mime_type = "video/x-nut",
+ .extensions = "nut",
+ .priv_data_size = sizeof(NUTContext),
+ .audio_codec = CODEC_ID_VORBIS,
+ .video_codec = CODEC_ID_MPEG4,
+ .write_header = nut_write_header,
+ .write_packet = nut_write_packet,
+ .write_trailer = nut_write_trailer,
.flags = AVFMT_GLOBALHEADER,
};
#endif /* CONFIG_LIBNUT_MUXER */
@@ -213,7 +213,7 @@ static int nut_read_header(AVFormatContext * avf, AVFormatParameters * ap) {
priv->s = s;
for (i = 0; s[i].type != -1 && i < 2; i++) {
- AVStream * st = av_new_stream(avf, i);
+ AVStream * st = avformat_new_stream(avf, NULL);
int j;
for (j = 0; j < s[i].fourcc_len && j < 8; j++) st->codec->codec_tag |= s[i].fourcc[j]<<(j*8);
@@ -298,13 +298,13 @@ static int nut_read_close(AVFormatContext *s) {
}
AVInputFormat ff_libnut_demuxer = {
- "libnut",
- NULL_IF_CONFIG_SMALL("NUT format"),
- sizeof(NUTContext),
- nut_probe,
- nut_read_header,
- nut_read_packet,
- nut_read_close,
- nut_read_seek,
+ .name = "libnut",
+ .long_name = NULL_IF_CONFIG_SMALL("NUT format"),
+ .priv_data_size = sizeof(NUTContext),
+ .read_probe = nut_probe,
+ .read_header = nut_read_header,
+ .read_packet = nut_read_packet,
+ .read_close = nut_read_close,
+ .read_seek = nut_read_seek,
.extensions = "nut",
};
diff --git a/libavformat/librtmp.c b/libavformat/librtmp.c
index 30fe8a196b..01b6c3deb0 100644
--- a/libavformat/librtmp.c
+++ b/libavformat/librtmp.c
@@ -2,20 +2,20 @@
* RTMP network protocol
* Copyright (c) 2010 Howard Chu
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -24,6 +24,7 @@
* RTMP protocol based on http://rtmpdump.mplayerhq.hu/ librtmp
*/
+#include "libavutil/mathematics.h"
#include "avformat.h"
#include "url.h"
diff --git a/libavformat/lmlm4.c b/libavformat/lmlm4.c
index eafc1b60bd..96007aa472 100644
--- a/libavformat/lmlm4.c
+++ b/libavformat/lmlm4.c
@@ -5,20 +5,20 @@
* Due to a lack of sample files, only files with one channel are supported.
* u-law and ADPCM audio are unsupported for the same reason.
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -60,14 +60,14 @@ static int lmlm4_probe(AVProbeData * pd) {
static int lmlm4_read_header(AVFormatContext *s, AVFormatParameters *ap) {
AVStream *st;
- if (!(st = av_new_stream(s, 0)))
+ if (!(st = avformat_new_stream(s, NULL)))
return AVERROR(ENOMEM);
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
st->codec->codec_id = CODEC_ID_MPEG4;
st->need_parsing = AVSTREAM_PARSE_HEADERS;
av_set_pts_info(st, 64, 1001, 30000);
- if (!(st = av_new_stream(s, 1)))
+ if (!(st = avformat_new_stream(s, NULL)))
return AVERROR(ENOMEM);
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
st->codec->codec_id = CODEC_ID_MP2;
@@ -118,10 +118,9 @@ static int lmlm4_read_packet(AVFormatContext *s, AVPacket *pkt) {
}
AVInputFormat ff_lmlm4_demuxer = {
- "lmlm4",
- NULL_IF_CONFIG_SMALL("lmlm4 raw format"),
- 0,
- lmlm4_probe,
- lmlm4_read_header,
- lmlm4_read_packet,
+ .name = "lmlm4",
+ .long_name = NULL_IF_CONFIG_SMALL("lmlm4 raw format"),
+ .read_probe = lmlm4_probe,
+ .read_header = lmlm4_read_header,
+ .read_packet = lmlm4_read_packet,
};
diff --git a/libavformat/loasdec.c b/libavformat/loasdec.c
new file mode 100644
index 0000000000..dd74b304fb
--- /dev/null
+++ b/libavformat/loasdec.c
@@ -0,0 +1,88 @@
+/*
+ * LOAS AudioSyncStream demuxer
+ * Copyright (c) 2008 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/intreadwrite.h"
+#include "libavutil/internal.h"
+#include "avformat.h"
+#include "rawdec.h"
+
+static int loas_probe(AVProbeData *p)
+{
+ int max_frames = 0, first_frames = 0;
+ int fsize, frames;
+ uint8_t *buf0 = p->buf;
+ uint8_t *buf2;
+ uint8_t *buf;
+ uint8_t *end = buf0 + p->buf_size - 3;
+ buf = buf0;
+
+ for(; buf < end; buf= buf2+1) {
+ buf2 = buf;
+
+ for(frames = 0; buf2 < end; frames++) {
+ uint32_t header = AV_RB24(buf2);
+ if((header >> 13) != 0x2B7)
+ break;
+ fsize = (header & 0x1FFF) + 3;
+ if(fsize < 7)
+ break;
+ fsize = FFMIN(fsize, end - buf2);
+ buf2 += fsize;
+ }
+ max_frames = FFMAX(max_frames, frames);
+ if(buf == buf0)
+ first_frames= frames;
+ }
+ if (first_frames>=3) return AVPROBE_SCORE_MAX/2+1;
+ else if(max_frames>100)return AVPROBE_SCORE_MAX/2;
+ else if(max_frames>=3) return AVPROBE_SCORE_MAX/4;
+ else if(max_frames>=1) return 1;
+ else return 0;
+}
+
+static int loas_read_header(AVFormatContext *s,
+ AVFormatParameters *ap)
+{
+ AVStream *st;
+
+ st = av_new_stream(s, 0);
+ if (!st)
+ return AVERROR(ENOMEM);
+
+ st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
+ st->codec->codec_id = s->iformat->value;
+ st->need_parsing = AVSTREAM_PARSE_FULL;
+
+ //LCM of all possible AAC sample rates
+ av_set_pts_info(st, 64, 1, 28224000);
+
+ return 0;
+}
+
+AVInputFormat ff_loas_demuxer = {
+ .name = "loas",
+ .long_name = NULL_IF_CONFIG_SMALL("LOAS AudioSyncStream"),
+ .read_probe = loas_probe,
+ .read_header = loas_read_header,
+ .read_packet = ff_raw_read_partial_packet,
+ .flags= AVFMT_GENERIC_INDEX,
+ .value = CODEC_ID_AAC_LATM,
+};
diff --git a/libavformat/lxfdec.c b/libavformat/lxfdec.c
index 0f7e4268d2..855e625284 100644
--- a/libavformat/lxfdec.c
+++ b/libavformat/lxfdec.c
@@ -2,20 +2,20 @@
* LXF demuxer
* Copyright (c) 2010 Tomas Härdin
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -90,7 +90,7 @@ static int sync(AVFormatContext *s, uint8_t *header)
return ret < 0 ? ret : AVERROR_EOF;
while (memcmp(buf, LXF_IDENT, LXF_IDENT_LENGTH)) {
- if (s->pb->eof_reached)
+ if (url_feof(s->pb))
return AVERROR_EOF;
memmove(buf, &buf[1], LXF_IDENT_LENGTH-1);
@@ -217,7 +217,7 @@ static int lxf_read_header(AVFormatContext *s, AVFormatParameters *ap)
if ((ret = avio_read(pb, header_data, LXF_HEADER_DATA_SIZE)) != LXF_HEADER_DATA_SIZE)
return ret < 0 ? ret : AVERROR_EOF;
- if (!(st = av_new_stream(s, 0)))
+ if (!(st = avformat_new_stream(s, NULL)))
return AVERROR(ENOMEM);
st->duration = AV_RL32(&header_data[32]);
@@ -243,7 +243,7 @@ static int lxf_read_header(AVFormatContext *s, AVFormatParameters *ap)
av_log(s, AV_LOG_WARNING, "VBI data not yet supported\n");
if ((lxf->channels = (disk_params >> 2) & 0xF)) {
- if (!(st = av_new_stream(s, 1)))
+ if (!(st = avformat_new_stream(s, NULL)))
return AVERROR(ENOMEM);
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
diff --git a/libavformat/m4vdec.c b/libavformat/m4vdec.c
index e856aadc10..88f838022e 100644
--- a/libavformat/m4vdec.c
+++ b/libavformat/m4vdec.c
@@ -2,20 +2,20 @@
* RAW MPEG-4 video demuxer
* Copyright (c) 2006 Thijs Vermeir <thijs.vermeir@barco.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -45,7 +45,7 @@ static int mpeg4video_probe(AVProbeData *probe_packet)
}
if (VOP >= VISO && VOP >= VOL && VO >= VOL && VOL > 0 && res==0)
- return AVPROBE_SCORE_MAX/2;
+ return VOP+VO > 3 ? AVPROBE_SCORE_MAX/2 : AVPROBE_SCORE_MAX/4;
return 0;
}
diff --git a/libavformat/matroska.c b/libavformat/matroska.c
index b448af21aa..52481d7556 100644
--- a/libavformat/matroska.c
+++ b/libavformat/matroska.c
@@ -2,20 +2,20 @@
* Matroska common data
* Copyright (c) 2003-2004 The ffmpeg Project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -99,3 +99,27 @@ const AVMetadataConv ff_mkv_metadata_conv[] = {
{ "PART_NUMBER" , "track" },
{ 0 }
};
+
+const char * const matroska_video_stereo_mode[MATROSKA_VIDEO_STEREO_MODE_COUNT] = {
+ "mono",
+ "left_right",
+ "bottom_top",
+ "top_bottom",
+ "checkerboard_rl",
+ "checkerboard_lr"
+ "row_interleaved_rl",
+ "row_interleaved_lr",
+ "col_interleaved_rl",
+ "col_interleaved_lr",
+ "anaglyph_cyan_red",
+ "right_left",
+ "anaglyph_green_magenta",
+ "block_lr",
+ "block_rl",
+};
+
+const char * const matroska_video_stereo_plane[MATROSKA_VIDEO_STEREO_PLANE_COUNT] = {
+ "left",
+ "right",
+ "background",
+};
diff --git a/libavformat/matroska.h b/libavformat/matroska.h
index 8e747e6a9c..ab7e3269fa 100644
--- a/libavformat/matroska.h
+++ b/libavformat/matroska.h
@@ -2,20 +2,20 @@
* Matroska constants
* Copyright (c) 2003-2004 The ffmpeg Project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -77,8 +77,13 @@
#define MATROSKA_ID_TRACKNUMBER 0xD7
#define MATROSKA_ID_TRACKUID 0x73C5
#define MATROSKA_ID_TRACKTYPE 0x83
-#define MATROSKA_ID_TRACKAUDIO 0xE1
-#define MATROSKA_ID_TRACKVIDEO 0xE0
+#define MATROSKA_ID_TRACKVIDEO 0xE0
+#define MATROSKA_ID_TRACKAUDIO 0xE1
+#define MATROSKA_ID_TRACKOPERATION 0xE2
+#define MATROSKA_ID_TRACKCOMBINEPLANES 0xE3
+#define MATROSKA_ID_TRACKPLANE 0xE4
+#define MATROSKA_ID_TRACKPLANEUID 0xE5
+#define MATROSKA_ID_TRACKPLANETYPE 0xE6
#define MATROSKA_ID_CODECID 0x86
#define MATROSKA_ID_CODECPRIVATE 0x63A2
#define MATROSKA_ID_CODECNAME 0x258688
@@ -253,8 +258,13 @@ typedef struct CodecMime{
/* max. depth in the EBML tree structure */
#define EBML_MAX_DEPTH 16
+#define MATROSKA_VIDEO_STEREO_MODE_COUNT 15
+#define MATROSKA_VIDEO_STEREO_PLANE_COUNT 3
+
extern const CodecTags ff_mkv_codec_tags[];
extern const CodecMime ff_mkv_mime_tags[];
extern const AVMetadataConv ff_mkv_metadata_conv[];
+extern const char * const matroska_video_stereo_mode[MATROSKA_VIDEO_STEREO_MODE_COUNT];
+extern const char * const matroska_video_stereo_plane[MATROSKA_VIDEO_STEREO_PLANE_COUNT];
#endif /* AVFORMAT_MATROSKA_H */
diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index a1e827f093..78e337bfab 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -1,21 +1,21 @@
/*
* Matroska file demuxer
- * Copyright (c) 2003-2008 The Libav Project
+ * Copyright (c) 2003-2008 The FFmpeg Project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -112,7 +112,8 @@ typedef struct {
uint64_t display_height;
uint64_t pixel_width;
uint64_t pixel_height;
- uint64_t fourcc;
+ EbmlBin color_space;
+ uint64_t stereo_mode;
} MatroskaTrackVideo;
typedef struct {
@@ -133,6 +134,15 @@ typedef struct {
} MatroskaTrackAudio;
typedef struct {
+ uint64_t uid;
+ uint64_t type;
+} MatroskaTrackPlane;
+
+typedef struct {
+ EbmlList combine_planes;
+} MatroskaTrackOperation;
+
+typedef struct {
uint64_t num;
uint64_t uid;
uint64_t type;
@@ -146,6 +156,7 @@ typedef struct {
uint64_t flag_forced;
MatroskaTrackVideo video;
MatroskaTrackAudio audio;
+ MatroskaTrackOperation operation;
EbmlList encodings;
AVStream *stream;
@@ -244,6 +255,9 @@ typedef struct {
/* What to skip before effectively reading a packet. */
int skip_to_keyframe;
uint64_t skip_to_timecode;
+
+ /* File has a CUES element, but we defer parsing until it is needed. */
+ int cues_parsing_deferred;
} MatroskaDemuxContext;
typedef struct {
@@ -291,14 +305,14 @@ static EbmlSyntax matroska_track_video[] = {
{ MATROSKA_ID_VIDEODISPLAYHEIGHT, EBML_UINT, 0, offsetof(MatroskaTrackVideo,display_height) },
{ MATROSKA_ID_VIDEOPIXELWIDTH, EBML_UINT, 0, offsetof(MatroskaTrackVideo,pixel_width) },
{ MATROSKA_ID_VIDEOPIXELHEIGHT, EBML_UINT, 0, offsetof(MatroskaTrackVideo,pixel_height) },
- { MATROSKA_ID_VIDEOCOLORSPACE, EBML_UINT, 0, offsetof(MatroskaTrackVideo,fourcc) },
+ { MATROSKA_ID_VIDEOCOLORSPACE, EBML_BIN, 0, offsetof(MatroskaTrackVideo,color_space) },
+ { MATROSKA_ID_VIDEOSTEREOMODE, EBML_UINT, 0, offsetof(MatroskaTrackVideo,stereo_mode) },
{ MATROSKA_ID_VIDEOPIXELCROPB, EBML_NONE },
{ MATROSKA_ID_VIDEOPIXELCROPT, EBML_NONE },
{ MATROSKA_ID_VIDEOPIXELCROPL, EBML_NONE },
{ MATROSKA_ID_VIDEOPIXELCROPR, EBML_NONE },
{ MATROSKA_ID_VIDEODISPLAYUNIT, EBML_NONE },
{ MATROSKA_ID_VIDEOFLAGINTERLACED,EBML_NONE },
- { MATROSKA_ID_VIDEOSTEREOMODE, EBML_NONE },
{ MATROSKA_ID_VIDEOASPECTRATIO, EBML_NONE },
{ 0 }
};
@@ -330,6 +344,22 @@ static EbmlSyntax matroska_track_encodings[] = {
{ 0 }
};
+static EbmlSyntax matroska_track_plane[] = {
+ { MATROSKA_ID_TRACKPLANEUID, EBML_UINT, 0, offsetof(MatroskaTrackPlane,uid) },
+ { MATROSKA_ID_TRACKPLANETYPE, EBML_UINT, 0, offsetof(MatroskaTrackPlane,type) },
+ { 0 }
+};
+
+static EbmlSyntax matroska_track_combine_planes[] = {
+ { MATROSKA_ID_TRACKPLANE, EBML_NEST, sizeof(MatroskaTrackPlane), offsetof(MatroskaTrackOperation,combine_planes), {.n=matroska_track_plane} },
+ { 0 }
+};
+
+static EbmlSyntax matroska_track_operation[] = {
+ { MATROSKA_ID_TRACKCOMBINEPLANES, EBML_NEST, 0, 0, {.n=matroska_track_combine_planes} },
+ { 0 }
+};
+
static EbmlSyntax matroska_track[] = {
{ MATROSKA_ID_TRACKNUMBER, EBML_UINT, 0, offsetof(MatroskaTrack,num) },
{ MATROSKA_ID_TRACKNAME, EBML_UTF8, 0, offsetof(MatroskaTrack,name) },
@@ -344,6 +374,7 @@ static EbmlSyntax matroska_track[] = {
{ MATROSKA_ID_TRACKFLAGFORCED, EBML_UINT, 0, offsetof(MatroskaTrack,flag_forced), {.u=0} },
{ MATROSKA_ID_TRACKVIDEO, EBML_NEST, 0, offsetof(MatroskaTrack,video), {.n=matroska_track_video} },
{ MATROSKA_ID_TRACKAUDIO, EBML_NEST, 0, offsetof(MatroskaTrack,audio), {.n=matroska_track_audio} },
+ { MATROSKA_ID_TRACKOPERATION, EBML_NEST, 0, offsetof(MatroskaTrack,operation), {.n=matroska_track_operation} },
{ MATROSKA_ID_TRACKCONTENTENCODINGS,EBML_NEST, 0, 0, {.n=matroska_track_encodings} },
{ MATROSKA_ID_TRACKFLAGENABLED, EBML_NONE },
{ MATROSKA_ID_TRACKFLAGLACING, EBML_NONE },
@@ -487,7 +518,7 @@ static EbmlSyntax matroska_segments[] = {
static EbmlSyntax matroska_blockgroup[] = {
{ MATROSKA_ID_BLOCK, EBML_BIN, 0, offsetof(MatroskaBlock,bin) },
{ MATROSKA_ID_SIMPLEBLOCK, EBML_BIN, 0, offsetof(MatroskaBlock,bin) },
- { MATROSKA_ID_BLOCKDURATION, EBML_UINT, 0, offsetof(MatroskaBlock,duration), {.u=AV_NOPTS_VALUE} },
+ { MATROSKA_ID_BLOCKDURATION, EBML_UINT, 0, offsetof(MatroskaBlock,duration) },
{ MATROSKA_ID_BLOCKREFERENCE, EBML_UINT, 0, offsetof(MatroskaBlock,reference) },
{ 1, EBML_UINT, 0, offsetof(MatroskaBlock,non_simple), {.u=1} },
{ 0 }
@@ -550,7 +581,7 @@ static int ebml_read_num(MatroskaDemuxContext *matroska, AVIOContext *pb,
* use it safely here to catch EOS. */
if (!(total = avio_r8(pb))) {
/* we might encounter EOS here */
- if (!pb->eof_reached) {
+ if (!url_feof(pb)) {
int64_t pos = avio_tell(pb);
av_log(matroska->ctx, AV_LOG_ERROR,
"Read error at pos. %"PRIu64" (0x%"PRIx64")\n",
@@ -798,11 +829,15 @@ static int ebml_parse_elem(MatroskaDemuxContext *matroska,
uint32_t id = syntax->id;
uint64_t length;
int res;
+ void *newelem;
data = (char *)data + syntax->data_offset;
if (syntax->list_elem_size) {
EbmlList *list = data;
- list->elem = av_realloc(list->elem, (list->nb_elem+1)*syntax->list_elem_size);
+ newelem = av_realloc(list->elem, (list->nb_elem+1)*syntax->list_elem_size);
+ if (!newelem)
+ return AVERROR(ENOMEM);
+ list->elem = newelem;
data = (char*)list->elem + list->nb_elem*syntax->list_elem_size;
memset(data, 0, syntax->list_elem_size);
list->nb_elem++;
@@ -900,6 +935,8 @@ static int matroska_probe(AVProbeData *p)
* Not fully fool-proof, but good enough. */
for (i = 0; i < FF_ARRAY_ELEMS(matroska_doctypes); i++) {
int probelen = strlen(matroska_doctypes[i]);
+ if (total < probelen)
+ continue;
for (n = 4+size; n <= 4+size+total-probelen; n++)
if (!memcmp(p->buf+n, matroska_doctypes[i], probelen))
return AVPROBE_SCORE_MAX;
@@ -930,6 +967,7 @@ static int matroska_decode_buffer(uint8_t** buf, int* buf_size,
uint8_t* data = *buf;
int isize = *buf_size;
uint8_t* pkt_data = NULL;
+ uint8_t* newpktdata;
int pkt_size = isize;
int result = 0;
int olen;
@@ -959,10 +997,18 @@ static int matroska_decode_buffer(uint8_t** buf, int* buf_size,
zstream.avail_in = isize;
do {
pkt_size *= 3;
- pkt_data = av_realloc(pkt_data, pkt_size);
+ newpktdata = av_realloc(pkt_data, pkt_size);
+ if (!newpktdata) {
+ inflateEnd(&zstream);
+ goto failed;
+ }
+ pkt_data = newpktdata;
zstream.avail_out = pkt_size - zstream.total_out;
zstream.next_out = pkt_data + zstream.total_out;
- result = inflate(&zstream, Z_NO_FLUSH);
+ if (pkt_data) {
+ result = inflate(&zstream, Z_NO_FLUSH);
+ } else
+ result = Z_MEM_ERROR;
} while (result==Z_OK && pkt_size<10000000);
pkt_size = zstream.total_out;
inflateEnd(&zstream);
@@ -980,10 +1026,18 @@ static int matroska_decode_buffer(uint8_t** buf, int* buf_size,
bzstream.avail_in = isize;
do {
pkt_size *= 3;
- pkt_data = av_realloc(pkt_data, pkt_size);
+ newpktdata = av_realloc(pkt_data, pkt_size);
+ if (!newpktdata) {
+ BZ2_bzDecompressEnd(&bzstream);
+ goto failed;
+ }
+ pkt_data = newpktdata;
bzstream.avail_out = pkt_size - bzstream.total_out_lo32;
bzstream.next_out = pkt_data + bzstream.total_out_lo32;
- result = BZ2_bzDecompress(&bzstream);
+ if (pkt_data) {
+ result = BZ2_bzDecompress(&bzstream);
+ } else
+ result = BZ_MEM_ERROR;
} while (result==BZ_OK && pkt_size<10000000);
pkt_size = bzstream.total_out_lo32;
BZ2_bzDecompressEnd(&bzstream);
@@ -1010,7 +1064,8 @@ static void matroska_fix_ass_packet(MatroskaDemuxContext *matroska,
char *line, *layer, *ptr = pkt->data, *end = ptr+pkt->size;
for (; *ptr!=',' && ptr<end-1; ptr++);
if (*ptr == ',')
- layer = ++ptr;
+ ptr++;
+ layer = ptr;
for (; *ptr!=',' && ptr<end-1; ptr++);
if (*ptr == ',') {
int64_t end_pts = pkt->pts + display_duration;
@@ -1035,13 +1090,17 @@ static void matroska_fix_ass_packet(MatroskaDemuxContext *matroska,
}
}
-static void matroska_merge_packets(AVPacket *out, AVPacket *in)
+static int matroska_merge_packets(AVPacket *out, AVPacket *in)
{
- out->data = av_realloc(out->data, out->size+in->size);
+ void *newdata = av_realloc(out->data, out->size+in->size);
+ if (!newdata)
+ return AVERROR(ENOMEM);
+ out->data = newdata;
memcpy(out->data+out->size, in->data, in->size);
out->size += in->size;
av_destruct_packet(in);
av_free(in);
+ return 0;
}
static void matroska_convert_tag(AVFormatContext *s, EbmlList *list,
@@ -1110,7 +1169,7 @@ static void matroska_convert_tags(AVFormatContext *s)
}
}
-static void matroska_execute_seekhead(MatroskaDemuxContext *matroska)
+static int matroska_parse_seekhead_entry(MatroskaDemuxContext *matroska, int idx)
{
EbmlList *seekhead_list = &matroska->seekhead;
MatroskaSeekhead *seekhead = seekhead_list->elem;
@@ -1118,6 +1177,54 @@ static void matroska_execute_seekhead(MatroskaDemuxContext *matroska)
int64_t before_pos = avio_tell(matroska->ctx->pb);
uint32_t saved_id = matroska->current_id;
MatroskaLevel level;
+ int64_t offset;
+ int ret = 0;
+
+ if (idx >= seekhead_list->nb_elem
+ || seekhead[idx].id == MATROSKA_ID_SEEKHEAD
+ || seekhead[idx].id == MATROSKA_ID_CLUSTER)
+ return 0;
+
+ /* seek */
+ offset = seekhead[idx].pos + matroska->segment_start;
+ if (avio_seek(matroska->ctx->pb, offset, SEEK_SET) == offset) {
+ /* We don't want to lose our seekhead level, so we add
+ * a dummy. This is a crude hack. */
+ if (matroska->num_levels == EBML_MAX_DEPTH) {
+ av_log(matroska->ctx, AV_LOG_INFO,
+ "Max EBML element depth (%d) reached, "
+ "cannot parse further.\n", EBML_MAX_DEPTH);
+ ret = AVERROR_INVALIDDATA;
+ } else {
+ level.start = 0;
+ level.length = (uint64_t)-1;
+ matroska->levels[matroska->num_levels] = level;
+ matroska->num_levels++;
+ matroska->current_id = 0;
+
+ ret = ebml_parse(matroska, matroska_segment, matroska);
+
+ /* remove dummy level */
+ while (matroska->num_levels) {
+ uint64_t length = matroska->levels[--matroska->num_levels].length;
+ if (length == (uint64_t)-1)
+ break;
+ }
+ }
+ }
+ /* seek back */
+ avio_seek(matroska->ctx->pb, before_pos, SEEK_SET);
+ matroska->level_up = level_up;
+ matroska->current_id = saved_id;
+
+ return ret;
+}
+
+static void matroska_execute_seekhead(MatroskaDemuxContext *matroska)
+{
+ EbmlList *seekhead_list = &matroska->seekhead;
+ MatroskaSeekhead *seekhead = seekhead_list->elem;
+ int64_t before_pos = avio_tell(matroska->ctx->pb);
int i;
// we should not do any seeking in the streaming case
@@ -1125,47 +1232,60 @@ static void matroska_execute_seekhead(MatroskaDemuxContext *matroska)
(matroska->ctx->flags & AVFMT_FLAG_IGNIDX))
return;
- for (i=0; i<seekhead_list->nb_elem; i++) {
- int64_t offset = seekhead[i].pos + matroska->segment_start;
-
- if (seekhead[i].pos <= before_pos
- || seekhead[i].id == MATROSKA_ID_SEEKHEAD
- || seekhead[i].id == MATROSKA_ID_CLUSTER)
+ for (i = 0; i < seekhead_list->nb_elem; i++) {
+ if (seekhead[i].pos <= before_pos)
continue;
- /* seek */
- if (avio_seek(matroska->ctx->pb, offset, SEEK_SET) != offset)
+ // defer cues parsing until we actually need cue data.
+ if (seekhead[i].id == MATROSKA_ID_CUES) {
+ matroska->cues_parsing_deferred = 1;
continue;
-
- /* We don't want to lose our seekhead level, so we add
- * a dummy. This is a crude hack. */
- if (matroska->num_levels == EBML_MAX_DEPTH) {
- av_log(matroska->ctx, AV_LOG_INFO,
- "Max EBML element depth (%d) reached, "
- "cannot parse further.\n", EBML_MAX_DEPTH);
- break;
}
- level.start = 0;
- level.length = (uint64_t)-1;
- matroska->levels[matroska->num_levels] = level;
- matroska->num_levels++;
- matroska->current_id = 0;
+ if (matroska_parse_seekhead_entry(matroska, i) < 0)
+ break;
+ }
+}
- ebml_parse(matroska, matroska_segment, matroska);
+static void matroska_add_index_entries(MatroskaDemuxContext *matroska) {
+ EbmlList *index_list;
+ MatroskaIndex *index;
+ int index_scale = 1;
+ int i, j;
- /* remove dummy level */
- while (matroska->num_levels) {
- uint64_t length = matroska->levels[--matroska->num_levels].length;
- if (length == (uint64_t)-1)
- break;
+ index_list = &matroska->index;
+ index = index_list->elem;
+ if (index_list->nb_elem
+ && index[0].time > 1E14/matroska->time_scale) {
+ av_log(matroska->ctx, AV_LOG_WARNING, "Working around broken index.\n");
+ index_scale = matroska->time_scale;
+ }
+ for (i = 0; i < index_list->nb_elem; i++) {
+ EbmlList *pos_list = &index[i].pos;
+ MatroskaIndexPos *pos = pos_list->elem;
+ for (j = 0; j < pos_list->nb_elem; j++) {
+ MatroskaTrack *track = matroska_find_track_by_num(matroska, pos[j].track);
+ if (track && track->stream)
+ av_add_index_entry(track->stream,
+ pos[j].pos + matroska->segment_start,
+ index[i].time/index_scale, 0, 0,
+ AVINDEX_KEYFRAME);
}
}
+}
- /* seek back */
- avio_seek(matroska->ctx->pb, before_pos, SEEK_SET);
- matroska->level_up = level_up;
- matroska->current_id = saved_id;
+static void matroska_parse_cues(MatroskaDemuxContext *matroska) {
+ EbmlList *seekhead_list = &matroska->seekhead;
+ MatroskaSeekhead *seekhead = seekhead_list->elem;
+ int i;
+
+ for (i = 0; i < seekhead_list->nb_elem; i++)
+ if (seekhead[i].id == MATROSKA_ID_CUES)
+ break;
+ assert(i <= seekhead_list->nb_elem);
+
+ matroska_parse_seekhead_entry(matroska, i);
+ matroska_add_index_entries(matroska);
}
static int matroska_aac_profile(char *codec_id)
@@ -1183,8 +1303,8 @@ static int matroska_aac_sri(int samplerate)
{
int sri;
- for (sri=0; sri<FF_ARRAY_ELEMS(ff_mpeg4audio_sample_rates); sri++)
- if (ff_mpeg4audio_sample_rates[sri] == samplerate)
+ for (sri=0; sri<FF_ARRAY_ELEMS(avpriv_mpeg4audio_sample_rates); sri++)
+ if (avpriv_mpeg4audio_sample_rates[sri] == samplerate)
break;
return sri;
}
@@ -1197,26 +1317,28 @@ static int matroska_read_header(AVFormatContext *s, AVFormatParameters *ap)
EbmlList *chapters_list = &matroska->chapters;
MatroskaChapter *chapters;
MatroskaTrack *tracks;
- EbmlList *index_list;
- MatroskaIndex *index;
- int index_scale = 1;
uint64_t max_start = 0;
Ebml ebml = { 0 };
AVStream *st;
- int i, j, res;
+ int i, j, k, res;
matroska->ctx = s;
/* First read the EBML header. */
if (ebml_parse(matroska, ebml_syntax, &ebml)
|| ebml.version > EBML_VERSION || ebml.max_size > sizeof(uint64_t)
- || ebml.id_length > sizeof(uint32_t) || ebml.doctype_version > 2) {
+ || ebml.id_length > sizeof(uint32_t) || ebml.doctype_version > 3) {
av_log(matroska->ctx, AV_LOG_ERROR,
"EBML header using unsupported features\n"
"(EBML version %"PRIu64", doctype %s, doc version %"PRIu64")\n",
ebml.version, ebml.doctype, ebml.doctype_version);
ebml_free(ebml_syntax, &ebml);
return AVERROR_PATCHWELCOME;
+ } else if (ebml.doctype_version == 3) {
+ av_log(matroska->ctx, AV_LOG_WARNING,
+ "EBML header using unsupported features\n"
+ "(EBML version %"PRIu64", doctype %s, doc version %"PRIu64")\n",
+ ebml.version, ebml.doctype, ebml.doctype_version);
}
for (i = 0; i < FF_ARRAY_ELEMS(matroska_doctypes); i++)
if (!strcmp(ebml.doctype, matroska_doctypes[i]))
@@ -1242,11 +1364,12 @@ static int matroska_read_header(AVFormatContext *s, AVFormatParameters *ap)
for (i=0; i < matroska->tracks.nb_elem; i++) {
MatroskaTrack *track = &tracks[i];
enum CodecID codec_id = CODEC_ID_NONE;
- EbmlList *encodings_list = &tracks->encodings;
+ EbmlList *encodings_list = &track->encodings;
MatroskaTrackEncoding *encodings = encodings_list->elem;
uint8_t *extradata = NULL;
int extradata_size = 0;
int extradata_offset = 0;
+ uint32_t fourcc = 0;
AVIOContext b;
/* Apply some sanity checks. */
@@ -1268,13 +1391,15 @@ static int matroska_read_header(AVFormatContext *s, AVFormatParameters *ap)
track->video.display_width = track->video.pixel_width;
if (!track->video.display_height)
track->video.display_height = track->video.pixel_height;
+ if (track->video.color_space.size == 4)
+ fourcc = AV_RL32(track->video.color_space.data);
} else if (track->type == MATROSKA_TRACK_TYPE_AUDIO) {
if (!track->audio.out_samplerate)
track->audio.out_samplerate = track->audio.samplerate;
}
if (encodings_list->nb_elem > 1) {
av_log(matroska->ctx, AV_LOG_ERROR,
- "Multiple combined encodings no supported");
+ "Multiple combined encodings not supported");
} else if (encodings_list->nb_elem == 1) {
if (encodings[0].type ||
(encodings[0].compression.algo != MATROSKA_TRACK_ENCODING_COMP_HEADERSTRIP &&
@@ -1319,7 +1444,7 @@ static int matroska_read_header(AVFormatContext *s, AVFormatParameters *ap)
}
}
- st = track->stream = av_new_stream(s, 0);
+ st = track->stream = avformat_new_stream(s, NULL);
if (st == NULL)
return AVERROR(ENOMEM);
@@ -1327,8 +1452,8 @@ static int matroska_read_header(AVFormatContext *s, AVFormatParameters *ap)
&& track->codec_priv.size >= 40
&& track->codec_priv.data != NULL) {
track->ms_compat = 1;
- track->video.fourcc = AV_RL32(track->codec_priv.data + 16);
- codec_id = ff_codec_get_id(ff_codec_bmp_tags, track->video.fourcc);
+ fourcc = AV_RL32(track->codec_priv.data + 16);
+ codec_id = ff_codec_get_id(ff_codec_bmp_tags, fourcc);
extradata_offset = 40;
} else if (!strcmp(track->codec_id, "A_MS/ACM")
&& track->codec_priv.size >= 14
@@ -1344,8 +1469,8 @@ static int matroska_read_header(AVFormatContext *s, AVFormatParameters *ap)
} else if (!strcmp(track->codec_id, "V_QUICKTIME")
&& (track->codec_priv.size >= 86)
&& (track->codec_priv.data != NULL)) {
- track->video.fourcc = AV_RL32(track->codec_priv.data);
- codec_id=ff_codec_get_id(codec_movvideo_tags, track->video.fourcc);
+ fourcc = AV_RL32(track->codec_priv.data);
+ codec_id = ff_codec_get_id(codec_movvideo_tags, fourcc);
} else if (codec_id == CODEC_ID_PCM_S16BE) {
switch (track->audio.bitdepth) {
case 8: codec_id = CODEC_ID_PCM_U8; break;
@@ -1463,8 +1588,10 @@ static int matroska_read_header(AVFormatContext *s, AVFormatParameters *ap)
}
if (track->type == MATROSKA_TRACK_TYPE_VIDEO) {
+ MatroskaTrackPlane *planes = track->operation.combine_planes.elem;
+
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
- st->codec->codec_tag = track->video.fourcc;
+ st->codec->codec_tag = fourcc;
st->codec->width = track->video.pixel_width;
st->codec->height = track->video.pixel_height;
av_reduce(&st->sample_aspect_ratio.num,
@@ -1476,6 +1603,25 @@ static int matroska_read_header(AVFormatContext *s, AVFormatParameters *ap)
st->need_parsing = AVSTREAM_PARSE_HEADERS;
if (track->default_duration)
st->avg_frame_rate = av_d2q(1000000000.0/track->default_duration, INT_MAX);
+
+ /* export stereo mode flag as metadata tag */
+ if (track->video.stereo_mode && track->video.stereo_mode < MATROSKA_VIDEO_STEREO_MODE_COUNT)
+ av_dict_set(&st->metadata, "stereo_mode", matroska_video_stereo_mode[track->video.stereo_mode], 0);
+
+ /* if we have virtual track, mark the real tracks */
+ for (j=0; j < track->operation.combine_planes.nb_elem; j++) {
+ char buf[32];
+ if (planes[j].type >= MATROSKA_VIDEO_STEREO_PLANE_COUNT)
+ continue;
+ snprintf(buf, sizeof(buf), "%s_%d",
+ matroska_video_stereo_plane[planes[j].type], i);
+ for (k=0; k < matroska->tracks.nb_elem; k++)
+ if (planes[j].uid == tracks[k].uid) {
+ av_dict_set(&s->streams[k]->metadata,
+ "stereo_mode", buf, 0);
+ break;
+ }
+ }
} else if (track->type == MATROSKA_TRACK_TYPE_AUDIO) {
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
st->codec->sample_rate = track->audio.out_samplerate;
@@ -1493,10 +1639,11 @@ static int matroska_read_header(AVFormatContext *s, AVFormatParameters *ap)
attachements[j].bin.data && attachements[j].bin.size > 0)) {
av_log(matroska->ctx, AV_LOG_ERROR, "incomplete attachment\n");
} else {
- AVStream *st = av_new_stream(s, 0);
+ AVStream *st = avformat_new_stream(s, NULL);
if (st == NULL)
break;
av_dict_set(&st->metadata, "filename",attachements[j].filename, 0);
+ av_dict_set(&st->metadata, "mimetype", attachements[j].mime, 0);
st->codec->codec_id = CODEC_ID_NONE;
st->codec->codec_type = AVMEDIA_TYPE_ATTACHMENT;
st->codec->extradata = av_malloc(attachements[j].bin.size);
@@ -1521,7 +1668,7 @@ static int matroska_read_header(AVFormatContext *s, AVFormatParameters *ap)
if (chapters[i].start != AV_NOPTS_VALUE && chapters[i].uid
&& (max_start==0 || chapters[i].start > max_start)) {
chapters[i].chapter =
- ff_new_chapter(s, chapters[i].uid, (AVRational){1, 1000000000},
+ avpriv_new_chapter(s, chapters[i].uid, (AVRational){1, 1000000000},
chapters[i].start, chapters[i].end,
chapters[i].title);
av_dict_set(&chapters[i].chapter->metadata,
@@ -1529,26 +1676,7 @@ static int matroska_read_header(AVFormatContext *s, AVFormatParameters *ap)
max_start = chapters[i].start;
}
- index_list = &matroska->index;
- index = index_list->elem;
- if (index_list->nb_elem
- && index[0].time > 100000000000000/matroska->time_scale) {
- av_log(matroska->ctx, AV_LOG_WARNING, "Working around broken index.\n");
- index_scale = matroska->time_scale;
- }
- for (i=0; i<index_list->nb_elem; i++) {
- EbmlList *pos_list = &index[i].pos;
- MatroskaIndexPos *pos = pos_list->elem;
- for (j=0; j<pos_list->nb_elem; j++) {
- MatroskaTrack *track = matroska_find_track_by_num(matroska,
- pos[j].track);
- if (track && track->stream)
- av_add_index_entry(track->stream,
- pos[j].pos + matroska->segment_start,
- index[i].time/index_scale, 0, 0,
- AVINDEX_KEYFRAME);
- }
- }
+ matroska_add_index_entries(matroska);
matroska_convert_tags(s);
@@ -1566,11 +1694,13 @@ static int matroska_deliver_packet(MatroskaDemuxContext *matroska,
memcpy(pkt, matroska->packets[0], sizeof(AVPacket));
av_free(matroska->packets[0]);
if (matroska->num_packets > 1) {
+ void *newpackets;
memmove(&matroska->packets[0], &matroska->packets[1],
(matroska->num_packets - 1) * sizeof(AVPacket *));
- matroska->packets =
- av_realloc(matroska->packets, (matroska->num_packets - 1) *
- sizeof(AVPacket *));
+ newpackets = av_realloc(matroska->packets,
+ (matroska->num_packets - 1) * sizeof(AVPacket *));
+ if (newpackets)
+ matroska->packets = newpackets;
} else {
av_freep(&matroska->packets);
}
@@ -1628,7 +1758,7 @@ static int matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data,
st = track->stream;
if (st->discard >= AVDISCARD_ALL)
return res;
- if (duration == AV_NOPTS_VALUE)
+ if (!duration)
duration = track->default_duration / matroska->time_scale;
block_time = AV_RB16(data);
@@ -1724,7 +1854,7 @@ static int matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data,
lace_size[n] = lace_size[n - 1] + snum;
total += lace_size[n];
}
- lace_size[n] = size - total;
+ lace_size[laces - 1] = size - total;
break;
}
}
@@ -1863,8 +1993,6 @@ static int matroska_parse_cluster(MatroskaDemuxContext *matroska)
for (i=0; i<blocks_list->nb_elem && !res; i++)
if (blocks[i].bin.size > 0 && blocks[i].bin.data) {
int is_keyframe = blocks[i].non_simple ? !blocks[i].reference : -1;
- if (!blocks[i].non_simple)
- blocks[i].duration = AV_NOPTS_VALUE;
res=matroska_parse_block(matroska,
blocks[i].bin.data, blocks[i].bin.size,
blocks[i].bin.pos, cluster.timecode,
@@ -1898,6 +2026,12 @@ static int matroska_read_seek(AVFormatContext *s, int stream_index,
AVStream *st = s->streams[stream_index];
int i, index, index_sub, index_min;
+ /* Parse the CUES now since we need the index data to seek. */
+ if (matroska->cues_parsing_deferred) {
+ matroska_parse_cues(matroska);
+ matroska->cues_parsing_deferred = 0;
+ }
+
if (!st->nb_index_entries)
return 0;
timestamp = FFMAX(timestamp, st->index_entries[0].timestamp);
@@ -1958,12 +2092,12 @@ static int matroska_read_close(AVFormatContext *s)
}
AVInputFormat ff_matroska_demuxer = {
- "matroska,webm",
- NULL_IF_CONFIG_SMALL("Matroska/WebM file format"),
- sizeof(MatroskaDemuxContext),
- matroska_probe,
- matroska_read_header,
- matroska_read_packet,
- matroska_read_close,
- matroska_read_seek,
+ .name = "matroska,webm",
+ .long_name = NULL_IF_CONFIG_SMALL("Matroska/WebM file format"),
+ .priv_data_size = sizeof(MatroskaDemuxContext),
+ .read_probe = matroska_probe,
+ .read_header = matroska_read_header,
+ .read_packet = matroska_read_packet,
+ .read_close = matroska_read_close,
+ .read_seek = matroska_read_seek,
};
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index d132b65f5b..6cf4156cb8 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -2,20 +2,20 @@
* Matroska muxer
* Copyright (c) 2007 David Conrad
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -91,6 +91,8 @@ typedef struct MatroskaMuxContext {
unsigned int audio_buffer_size;
AVPacket cur_audio_pkt;
+
+ int have_attachments;
} MatroskaMuxContext;
@@ -421,7 +423,7 @@ static int put_xiph_codecpriv(AVFormatContext *s, AVIOContext *pb, AVCodecContex
else
first_header_size = 42;
- if (ff_split_xiph_headers(codec->extradata, codec->extradata_size,
+ if (avpriv_split_xiph_headers(codec->extradata, codec->extradata_size,
first_header_size, header_start, header_len) < 0) {
av_log(s, AV_LOG_ERROR, "Extradata corrupt.\n");
return -1;
@@ -441,7 +443,7 @@ static void get_aac_sample_rates(AVFormatContext *s, AVCodecContext *codec, int
{
MPEG4AudioConfig mp4ac;
- if (ff_mpeg4audio_get_config(&mp4ac, codec->extradata, codec->extradata_size) < 0) {
+ if (avpriv_mpeg4audio_get_config(&mp4ac, codec->extradata, codec->extradata_size) < 0) {
av_log(s, AV_LOG_WARNING, "Error parsing AAC extradata, unable to determine samplerate.\n");
return;
}
@@ -528,6 +530,11 @@ static int mkv_write_tracks(AVFormatContext *s)
int output_sample_rate = 0;
AVDictionaryEntry *tag;
+ if (codec->codec_type == AVMEDIA_TYPE_ATTACHMENT) {
+ mkv->have_attachments = 1;
+ continue;
+ }
+
if (!bit_depth)
bit_depth = av_get_bytes_per_sample(codec->sample_fmt) << 3;
@@ -589,31 +596,38 @@ static int mkv_write_tracks(AVFormatContext *s)
// XXX: interlace flag?
put_ebml_uint (pb, MATROSKA_ID_VIDEOPIXELWIDTH , codec->width);
put_ebml_uint (pb, MATROSKA_ID_VIDEOPIXELHEIGHT, codec->height);
- if ((tag = av_dict_get(s->metadata, "stereo_mode", NULL, 0))) {
- uint8_t stereo_fmt = atoi(tag->value);
- int valid_fmt = 0;
-
- switch (mkv->mode) {
- case MODE_WEBM:
- if (stereo_fmt <= MATROSKA_VIDEO_STEREOMODE_TYPE_TOP_BOTTOM
- || stereo_fmt == MATROSKA_VIDEO_STEREOMODE_TYPE_RIGHT_LEFT)
- valid_fmt = 1;
- break;
- case MODE_MATROSKAv2:
- if (stereo_fmt <= MATROSKA_VIDEO_STEREOMODE_TYPE_BOTH_EYES_BLOCK_RL)
- valid_fmt = 1;
- break;
- }
-
- if (valid_fmt)
- put_ebml_uint (pb, MATROSKA_ID_VIDEOSTEREOMODE, stereo_fmt);
+
+ if ((tag = av_dict_get(st->metadata, "stereo_mode", NULL, 0)) ||
+ (tag = av_dict_get( s->metadata, "stereo_mode", NULL, 0))) {
+ // save stereo mode flag
+ uint64_t st_mode = MATROSKA_VIDEO_STEREO_MODE_COUNT;
+
+ for (j=0; j<MATROSKA_VIDEO_STEREO_MODE_COUNT; j++)
+ if (!strcmp(tag->value, matroska_video_stereo_mode[j])){
+ st_mode = j;
+ break;
+ }
+
+ if ((mkv->mode == MODE_WEBM && st_mode > 3 && st_mode != 11)
+ || st_mode >= MATROSKA_VIDEO_STEREO_MODE_COUNT) {
+ av_log(s, AV_LOG_ERROR,
+ "The specified stereo mode is not valid.\n");
+ return AVERROR(EINVAL);
+ } else
+ put_ebml_uint(pb, MATROSKA_ID_VIDEOSTEREOMODE, st_mode);
}
+
if (st->sample_aspect_ratio.num) {
int d_width = codec->width*av_q2d(st->sample_aspect_ratio);
put_ebml_uint(pb, MATROSKA_ID_VIDEODISPLAYWIDTH , d_width);
put_ebml_uint(pb, MATROSKA_ID_VIDEODISPLAYHEIGHT, codec->height);
put_ebml_uint(pb, MATROSKA_ID_VIDEODISPLAYUNIT, 3);
}
+
+ if (codec->codec_id == CODEC_ID_RAWVIDEO) {
+ uint32_t color_space = av_le2ne32(codec->codec_tag);
+ put_ebml_binary(pb, MATROSKA_ID_VIDEOCOLORSPACE, &color_space, sizeof(color_space));
+ }
end_ebml_master(pb, subinfo);
break;
@@ -753,7 +767,7 @@ static int mkv_write_tag(AVFormatContext *s, AVDictionary *m, unsigned int eleme
end_ebml_master(s->pb, targets);
while ((t = av_dict_get(m, "", t, AV_DICT_IGNORE_SUFFIX)))
- if (strcasecmp(t->key, "title"))
+ if (strcasecmp(t->key, "title") && strcasecmp(t->key, "stereo_mode"))
mkv_write_simpletag(s->pb, t);
end_ebml_master(s->pb, tag);
@@ -797,6 +811,68 @@ static int mkv_write_tags(AVFormatContext *s)
return 0;
}
+static int mkv_write_attachments(AVFormatContext *s)
+{
+ MatroskaMuxContext *mkv = s->priv_data;
+ AVIOContext *pb = s->pb;
+ ebml_master attachments;
+ AVLFG c;
+ int i, ret;
+
+ if (!mkv->have_attachments)
+ return 0;
+
+ av_lfg_init(&c, av_get_random_seed());
+
+ ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_ATTACHMENTS, avio_tell(pb));
+ if (ret < 0) return ret;
+
+ attachments = start_ebml_master(pb, MATROSKA_ID_ATTACHMENTS, 0);
+
+ for (i = 0; i < s->nb_streams; i++) {
+ AVStream *st = s->streams[i];
+ ebml_master attached_file;
+ AVDictionaryEntry *t;
+ const char *mimetype = NULL;
+
+ if (st->codec->codec_type != AVMEDIA_TYPE_ATTACHMENT)
+ continue;
+
+ attached_file = start_ebml_master(pb, MATROSKA_ID_ATTACHEDFILE, 0);
+
+ if (t = av_dict_get(st->metadata, "title", NULL, 0))
+ put_ebml_string(pb, MATROSKA_ID_FILEDESC, t->value);
+ if (!(t = av_dict_get(st->metadata, "filename", NULL, 0))) {
+ av_log(s, AV_LOG_ERROR, "Attachment stream %d has no filename tag.\n", i);
+ return AVERROR(EINVAL);
+ }
+ put_ebml_string(pb, MATROSKA_ID_FILENAME, t->value);
+ if (t = av_dict_get(st->metadata, "mimetype", NULL, 0))
+ mimetype = t->value;
+ else if (st->codec->codec_id != CODEC_ID_NONE ) {
+ int i;
+ for (i = 0; ff_mkv_mime_tags[i].id != CODEC_ID_NONE; i++)
+ if (ff_mkv_mime_tags[i].id == st->codec->codec_id) {
+ mimetype = ff_mkv_mime_tags[i].str;
+ break;
+ }
+ }
+ if (!mimetype) {
+ av_log(s, AV_LOG_ERROR, "Attachment stream %d has no mimetype tag and "
+ "it cannot be deduced from the codec id.\n", i);
+ return AVERROR(EINVAL);
+ }
+
+ put_ebml_string(pb, MATROSKA_ID_FILEMIMETYPE, mimetype);
+ put_ebml_binary(pb, MATROSKA_ID_FILEDATA, st->codec->extradata, st->codec->extradata_size);
+ put_ebml_uint(pb, MATROSKA_ID_FILEUID, av_lfg_get(&c));
+ end_ebml_master(pb, attached_file);
+ }
+ end_ebml_master(pb, attachments);
+
+ return 0;
+}
+
static int mkv_write_header(AVFormatContext *s)
{
MatroskaMuxContext *mkv = s->priv_data;
@@ -870,6 +946,9 @@ static int mkv_write_header(AVFormatContext *s)
ret = mkv_write_tags(s);
if (ret < 0) return ret;
+
+ ret = mkv_write_attachments(s);
+ if (ret < 0) return ret;
}
if (!s->pb->seekable)
@@ -932,7 +1011,7 @@ static int mkv_write_ass_blocks(AVFormatContext *s, AVIOContext *pb, AVPacket *p
size -= start - data;
sscanf(data, "Dialogue: %d,", &layer);
i = snprintf(buffer, sizeof(buffer), "%"PRId64",%d,",
- s->streams[pkt->stream_index]->nb_frames++, layer);
+ s->streams[pkt->stream_index]->nb_frames, layer);
size = FFMIN(i+size, sizeof(buffer));
memcpy(buffer+i, start, size-i);
@@ -1191,53 +1270,80 @@ static int mkv_write_trailer(AVFormatContext *s)
return 0;
}
+static int mkv_query_codec(enum CodecID codec_id, int std_compliance)
+{
+ int i;
+ for (i = 0; ff_mkv_codec_tags[i].id != CODEC_ID_NONE; i++)
+ if (ff_mkv_codec_tags[i].id == codec_id)
+ return 1;
+
+ if (std_compliance < FF_COMPLIANCE_NORMAL) { // mkv theoretically supports any
+ enum AVMediaType type = avcodec_get_type(codec_id); // video/audio through VFW/ACM
+ if (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO)
+ return 1;
+ }
+
+ return 0;
+}
+
#if CONFIG_MATROSKA_MUXER
AVOutputFormat ff_matroska_muxer = {
- "matroska",
- NULL_IF_CONFIG_SMALL("Matroska file format"),
- "video/x-matroska",
- "mkv",
- sizeof(MatroskaMuxContext),
- CODEC_ID_MP2,
- CODEC_ID_MPEG4,
- mkv_write_header,
- mkv_write_packet,
- mkv_write_trailer,
- .flags = AVFMT_GLOBALHEADER | AVFMT_VARIABLE_FPS,
- .codec_tag = (const AVCodecTag* const []){ff_codec_bmp_tags, ff_codec_wav_tags, 0},
- .subtitle_codec = CODEC_ID_TEXT,
+ .name = "matroska",
+ .long_name = NULL_IF_CONFIG_SMALL("Matroska file format"),
+ .mime_type = "video/x-matroska",
+ .extensions = "mkv",
+ .priv_data_size = sizeof(MatroskaMuxContext),
+#if CONFIG_LIBVORBIS_ENCODER
+ .audio_codec = CODEC_ID_VORBIS,
+#else
+ .audio_codec = CODEC_ID_AC3,
+#endif
+#if CONFIG_LIBX264_ENCODER
+ .video_codec = CODEC_ID_H264,
+#else
+ .video_codec = CODEC_ID_MPEG4,
+#endif
+ .write_header = mkv_write_header,
+ .write_packet = mkv_write_packet,
+ .write_trailer = mkv_write_trailer,
+ .flags = AVFMT_GLOBALHEADER | AVFMT_VARIABLE_FPS,
+ .subtitle_codec = CODEC_ID_SSA,
+ .query_codec = mkv_query_codec,
};
#endif
#if CONFIG_WEBM_MUXER
AVOutputFormat ff_webm_muxer = {
- "webm",
- NULL_IF_CONFIG_SMALL("WebM file format"),
- "video/webm",
- "webm",
- sizeof(MatroskaMuxContext),
- CODEC_ID_VORBIS,
- CODEC_ID_VP8,
- mkv_write_header,
- mkv_write_packet,
- mkv_write_trailer,
- .flags = AVFMT_GLOBALHEADER | AVFMT_VARIABLE_FPS,
+ .name = "webm",
+ .long_name = NULL_IF_CONFIG_SMALL("WebM file format"),
+ .mime_type = "video/webm",
+ .extensions = "webm",
+ .priv_data_size = sizeof(MatroskaMuxContext),
+ .audio_codec = CODEC_ID_VORBIS,
+ .video_codec = CODEC_ID_VP8,
+ .write_header = mkv_write_header,
+ .write_packet = mkv_write_packet,
+ .write_trailer = mkv_write_trailer,
+ .flags = AVFMT_GLOBALHEADER | AVFMT_VARIABLE_FPS | AVFMT_TS_NONSTRICT,
};
#endif
#if CONFIG_MATROSKA_AUDIO_MUXER
AVOutputFormat ff_matroska_audio_muxer = {
- "matroska",
- NULL_IF_CONFIG_SMALL("Matroska file format"),
- "audio/x-matroska",
- "mka",
- sizeof(MatroskaMuxContext),
- CODEC_ID_MP2,
- CODEC_ID_NONE,
- mkv_write_header,
- mkv_write_packet,
- mkv_write_trailer,
+ .name = "matroska",
+ .long_name = NULL_IF_CONFIG_SMALL("Matroska file format"),
+ .mime_type = "audio/x-matroska",
+ .extensions = "mka",
+ .priv_data_size = sizeof(MatroskaMuxContext),
+#if CONFIG_LIBVORBIS_ENCODER
+ .audio_codec = CODEC_ID_VORBIS,
+#else
+ .audio_codec = CODEC_ID_AC3,
+#endif
+ .video_codec = CODEC_ID_NONE,
+ .write_header = mkv_write_header,
+ .write_packet = mkv_write_packet,
+ .write_trailer = mkv_write_trailer,
.flags = AVFMT_GLOBALHEADER,
- .codec_tag = (const AVCodecTag* const []){ff_codec_wav_tags, 0},
};
#endif
diff --git a/libavformat/md5enc.c b/libavformat/md5enc.c
index 3b7d0ea8d8..512e082778 100644
--- a/libavformat/md5enc.c
+++ b/libavformat/md5enc.c
@@ -2,20 +2,20 @@
* MD5 encoder (for codec/format testing)
* Copyright (c) 2009 Reimar Döffinger, based on crcenc (c) 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -66,16 +66,15 @@ static int write_trailer(struct AVFormatContext *s)
}
AVOutputFormat ff_md5_muxer = {
- "md5",
- NULL_IF_CONFIG_SMALL("MD5 testing format"),
- NULL,
- "",
- PRIVSIZE,
- CODEC_ID_PCM_S16LE,
- CODEC_ID_RAWVIDEO,
- write_header,
- write_packet,
- write_trailer,
+ .name = "md5",
+ .long_name = NULL_IF_CONFIG_SMALL("MD5 testing format"),
+ .extensions = "",
+ .priv_data_size = PRIVSIZE,
+ .audio_codec = CODEC_ID_PCM_S16LE,
+ .video_codec = CODEC_ID_RAWVIDEO,
+ .write_header = write_header,
+ .write_packet = write_packet,
+ .write_trailer = write_trailer,
};
#endif
@@ -96,15 +95,12 @@ static int framemd5_write_packet(struct AVFormatContext *s, AVPacket *pkt)
}
AVOutputFormat ff_framemd5_muxer = {
- "framemd5",
- NULL_IF_CONFIG_SMALL("Per-frame MD5 testing format"),
- NULL,
- "",
- PRIVSIZE,
- CODEC_ID_PCM_S16LE,
- CODEC_ID_RAWVIDEO,
- NULL,
- framemd5_write_packet,
- NULL,
+ .name = "framemd5",
+ .long_name = NULL_IF_CONFIG_SMALL("Per-frame MD5 testing format"),
+ .extensions = "",
+ .priv_data_size = PRIVSIZE,
+ .audio_codec = CODEC_ID_PCM_S16LE,
+ .video_codec = CODEC_ID_RAWVIDEO,
+ .write_packet = framemd5_write_packet,
};
#endif
diff --git a/libavformat/md5proto.c b/libavformat/md5proto.c
index 4630c49f5c..3f099da440 100644
--- a/libavformat/md5proto.c
+++ b/libavformat/md5proto.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2010 Mans Rullgard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/metadata.c b/libavformat/metadata.c
index d8957dfa95..e6fbe30da9 100644
--- a/libavformat/metadata.c
+++ b/libavformat/metadata.c
@@ -1,20 +1,20 @@
/*
* copyright (c) 2009 Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/metadata.h b/libavformat/metadata.h
index 33e0d1ff6c..d826c6f144 100644
--- a/libavformat/metadata.h
+++ b/libavformat/metadata.h
@@ -1,20 +1,20 @@
/*
* copyright (c) 2009 Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/microdvddec.c b/libavformat/microdvddec.c
new file mode 100644
index 0000000000..95c76afc8d
--- /dev/null
+++ b/libavformat/microdvddec.c
@@ -0,0 +1,129 @@
+/*
+ * MicroDVD subtitle demuxer
+ * Copyright (c) 2010 Aurelien Jacobs <aurel@gnuage.org>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "avformat.h"
+#include "internal.h"
+#include "libavutil/intreadwrite.h"
+
+#define MAX_LINESIZE 2048
+
+
+typedef struct {
+ uint8_t lines[3][MAX_LINESIZE];
+ int64_t pos[3];
+} MicroDVDContext;
+
+
+static int microdvd_probe(AVProbeData *p)
+{
+ unsigned char c, *ptr = p->buf;
+ int i;
+
+ if (AV_RB24(ptr) == 0xEFBBBF)
+ ptr += 3; /* skip UTF-8 BOM */
+
+ for (i=0; i<3; i++) {
+ if (sscanf(ptr, "{%*d}{}%c", &c) != 1 &&
+ sscanf(ptr, "{%*d}{%*d}%c", &c) != 1 &&
+ sscanf(ptr, "{DEFAULT}{}%c", &c) != 1)
+ return 0;
+ ptr += strcspn(ptr, "\n") + 1;
+ }
+ return AVPROBE_SCORE_MAX;
+}
+
+static int microdvd_read_header(AVFormatContext *s, AVFormatParameters *ap)
+{
+ AVRational pts_info = (AVRational){ 2997, 125 }; /* default: 23.976 fps */
+ MicroDVDContext *microdvd = s->priv_data;
+ AVStream *st = av_new_stream(s, 0);
+ int i, frame;
+ double fps;
+ char c;
+
+ if (!st)
+ return -1;
+ for (i=0; i<FF_ARRAY_ELEMS(microdvd->lines); i++) {
+ microdvd->pos[i] = avio_tell(s->pb);
+ ff_get_line(s->pb, microdvd->lines[i], sizeof(microdvd->lines[i]));
+ if ((sscanf(microdvd->lines[i], "{%d}{}%6lf", &frame, &fps) == 2 ||
+ sscanf(microdvd->lines[i], "{%d}{%*d}%6lf", &frame, &fps) == 2)
+ && frame <= 1 && fps > 3 && fps < 100)
+ pts_info = av_d2q(fps, 100000);
+ if (sscanf(microdvd->lines[i], "{DEFAULT}{}%c", &c) == 1) {
+ st->codec->extradata = av_strdup(microdvd->lines[i] + 11);
+ st->codec->extradata_size = strlen(st->codec->extradata);
+ i--;
+ }
+ }
+ av_set_pts_info(st, 64, pts_info.den, pts_info.num);
+ st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;
+ st->codec->codec_id = CODEC_ID_MICRODVD;
+ return 0;
+}
+
+static int64_t get_pts(const char *buf)
+{
+ int frame;
+ char c;
+
+ if (sscanf(buf, "{%d}{%c", &frame, &c) == 2)
+ return frame;
+ return AV_NOPTS_VALUE;
+}
+
+static int microdvd_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ MicroDVDContext *microdvd = s->priv_data;
+ char buffer[MAX_LINESIZE];
+ int64_t pos = avio_tell(s->pb);
+ int i, len = 0, res = AVERROR_EOF;
+
+ for (i=0; i<FF_ARRAY_ELEMS(microdvd->lines); i++) {
+ if (microdvd->lines[i][0]) {
+ strcpy(buffer, microdvd->lines[i]);
+ pos = microdvd->pos[i];
+ len = strlen(buffer);
+ microdvd->lines[i][0] = 0;
+ break;
+ }
+ }
+ if (!len)
+ len = ff_get_line(s->pb, buffer, sizeof(buffer));
+
+ if (buffer[0] && !(res = av_new_packet(pkt, len))) {
+ memcpy(pkt->data, buffer, len);
+ pkt->flags |= AV_PKT_FLAG_KEY;
+ pkt->pos = pos;
+ pkt->pts = pkt->dts = get_pts(buffer);
+ }
+ return res;
+}
+
+AVInputFormat ff_microdvd_demuxer = {
+ .name = "microdvd",
+ .long_name = NULL_IF_CONFIG_SMALL("MicroDVD subtitle format"),
+ .priv_data_size = sizeof(MicroDVDContext),
+ .read_probe = microdvd_probe,
+ .read_header = microdvd_read_header,
+ .read_packet = microdvd_read_packet,
+ .flags = AVFMT_GENERIC_INDEX,
+};
diff --git a/libavformat/microdvdenc.c b/libavformat/microdvdenc.c
new file mode 100644
index 0000000000..b2abc547e6
--- /dev/null
+++ b/libavformat/microdvdenc.c
@@ -0,0 +1,51 @@
+/*
+ * MicroDVD subtitle muxer
+ * Copyright (c) 2010 Aurelien Jacobs <aurel@gnuage.org>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "avformat.h"
+#include "rawenc.h"
+
+static int microdvd_write_header(struct AVFormatContext *s)
+{
+ AVCodecContext *avctx = s->streams[0]->codec;
+
+ if (s->nb_streams != 1 || avctx->codec_id != CODEC_ID_MICRODVD) {
+ av_log(s, AV_LOG_ERROR, "Exactly one MicroDVD stream is needed.\n");
+ return -1;
+ }
+
+ if (avctx->extradata && avctx->extradata_size > 0) {
+ avio_write(s->pb, "{DEFAULT}{}", 11);
+ avio_write(s->pb, avctx->extradata, avctx->extradata_size);
+ avio_flush(s->pb);
+ }
+ return 0;
+}
+
+AVOutputFormat ff_microdvd_muxer = {
+ .name = "microdvd",
+ .long_name = NULL_IF_CONFIG_SMALL("MicroDVD subtitle format"),
+ .mime_type = "text/x-microdvd",
+ .extensions = "sub",
+ .write_header = microdvd_write_header,
+ .write_packet = ff_raw_write_packet,
+ .flags = AVFMT_NOTIMESTAMPS,
+ .subtitle_codec = CODEC_ID_MICRODVD,
+};
diff --git a/libavformat/mm.c b/libavformat/mm.c
index dae659f3c6..3ad47418fc 100644
--- a/libavformat/mm.c
+++ b/libavformat/mm.c
@@ -2,20 +2,20 @@
* American Laser Games MM Format Demuxer
* Copyright (c) 2006 Peter Ross
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -105,7 +105,7 @@ static int read_header(AVFormatContext *s,
avio_skip(pb, length - 10); /* unknown data */
/* video stream */
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
@@ -117,7 +117,7 @@ static int read_header(AVFormatContext *s,
/* audio stream */
if (length == MM_HEADER_LEN_AV) {
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
@@ -187,10 +187,10 @@ static int read_packet(AVFormatContext *s,
}
AVInputFormat ff_mm_demuxer = {
- "mm",
- NULL_IF_CONFIG_SMALL("American Laser Games MM format"),
- sizeof(MmDemuxContext),
- probe,
- read_header,
- read_packet,
+ .name = "mm",
+ .long_name = NULL_IF_CONFIG_SMALL("American Laser Games MM format"),
+ .priv_data_size = sizeof(MmDemuxContext),
+ .read_probe = probe,
+ .read_header = read_header,
+ .read_packet = read_packet,
};
diff --git a/libavformat/mmf.c b/libavformat/mmf.c
index 3848d5cf56..956f567203 100644
--- a/libavformat/mmf.c
+++ b/libavformat/mmf.c
@@ -2,20 +2,20 @@
* Yamaha SMAF format
* Copyright (c) 2005 Vidar Madsen
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avformat.h"
@@ -241,7 +241,7 @@ static int mmf_read_header(AVFormatContext *s,
}
mmf->data_size = size;
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
@@ -265,7 +265,7 @@ static int mmf_read_packet(AVFormatContext *s,
MMFContext *mmf = s->priv_data;
int ret, size;
- if (s->pb->eof_reached)
+ if (url_feof(s->pb))
return AVERROR(EIO);
size = MAX_SIZE;
@@ -291,27 +291,26 @@ static int mmf_read_packet(AVFormatContext *s,
#if CONFIG_MMF_DEMUXER
AVInputFormat ff_mmf_demuxer = {
- "mmf",
- NULL_IF_CONFIG_SMALL("Yamaha SMAF"),
- sizeof(MMFContext),
- mmf_probe,
- mmf_read_header,
- mmf_read_packet,
- NULL,
- pcm_read_seek,
+ .name = "mmf",
+ .long_name = NULL_IF_CONFIG_SMALL("Yamaha SMAF"),
+ .priv_data_size = sizeof(MMFContext),
+ .read_probe = mmf_probe,
+ .read_header = mmf_read_header,
+ .read_packet = mmf_read_packet,
+ .read_seek = pcm_read_seek,
};
#endif
#if CONFIG_MMF_MUXER
AVOutputFormat ff_mmf_muxer = {
- "mmf",
- NULL_IF_CONFIG_SMALL("Yamaha SMAF"),
- "application/vnd.smaf",
- "mmf",
- sizeof(MMFContext),
- CODEC_ID_ADPCM_YAMAHA,
- CODEC_ID_NONE,
- mmf_write_header,
- mmf_write_packet,
- mmf_write_trailer,
+ .name = "mmf",
+ .long_name = NULL_IF_CONFIG_SMALL("Yamaha SMAF"),
+ .mime_type = "application/vnd.smaf",
+ .extensions = "mmf",
+ .priv_data_size = sizeof(MMFContext),
+ .audio_codec = CODEC_ID_ADPCM_YAMAHA,
+ .video_codec = CODEC_ID_NONE,
+ .write_header = mmf_write_header,
+ .write_packet = mmf_write_packet,
+ .write_trailer = mmf_write_trailer,
};
#endif
diff --git a/libavformat/mms.c b/libavformat/mms.c
index 192e7039af..46fbede90c 100644
--- a/libavformat/mms.c
+++ b/libavformat/mms.c
@@ -4,20 +4,20 @@
* Copyright (c) 2007 Björn Axelsson
* Copyright (c) 2010 Zhentan Feng <spyfeng at gmail dot com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "mms.h"
diff --git a/libavformat/mms.h b/libavformat/mms.h
index 36e772c7f9..0117089d24 100644
--- a/libavformat/mms.h
+++ b/libavformat/mms.h
@@ -2,20 +2,20 @@
* MMS protocol common definitions.
* Copyright (c) 2010 Zhentan Feng <spyfeng at gmail dot com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVFORMAT_MMS_H
diff --git a/libavformat/mmsh.c b/libavformat/mmsh.c
index 0ce282c906..029baed211 100644
--- a/libavformat/mmsh.c
+++ b/libavformat/mmsh.c
@@ -2,20 +2,20 @@
* MMS protocol over HTTP
* Copyright (c) 2010 Zhentan Feng <spyfeng at gmail dot com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -243,7 +243,7 @@ static int mmsh_open(URLContext *h, const char *uri, int flags)
"Pragma: no-cache,rate=1.000000,stream-time=0,"
"stream-offset=0:0,request-context=%u,max-duration=0\r\n"
CLIENTGUID
- "Connection: Close\r\n\r\n",
+ "Connection: Close\r\n",
host, port, mmsh->request_seq++);
ff_http_set_headers(mms->mms_hd, headers);
@@ -283,7 +283,7 @@ static int mmsh_open(URLContext *h, const char *uri, int flags)
CLIENTGUID
"Pragma: stream-switch-count=%d\r\n"
"Pragma: stream-switch-entry=%s\r\n"
- "Connection: Close\r\n\r\n",
+ "Connection: Close\r\n",
host, port, mmsh->request_seq++, mms->stream_num, stream_selection);
av_freep(&stream_selection);
if (err < 0) {
diff --git a/libavformat/mmst.c b/libavformat/mmst.c
index e1904de1e2..a3db288b35 100644
--- a/libavformat/mmst.c
+++ b/libavformat/mmst.c
@@ -4,20 +4,20 @@
* Copyright (c) 2007 Björn Axelsson
* Copyright (c) 2010 Zhentan Feng <spyfeng at gmail dot com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -152,7 +152,7 @@ static int send_command_packet(MMSTContext *mmst)
return 0;
}
-static void mms_put_utf16(MMSContext *mms, uint8_t *src)
+static void mms_put_utf16(MMSContext *mms, const uint8_t *src)
{
AVIOContext bic;
int size = mms->write_out_ptr - mms->out_buffer;
diff --git a/libavformat/mov.c b/libavformat/mov.c
index acde35d97e..198f3cd938 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3,20 +3,20 @@
* Copyright (c) 2001 Fabrice Bellard
* Copyright (c) 2009 Baptiste Coudurier <baptiste dot coudurier at gmail dot com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -35,6 +35,7 @@
#include "riff.h"
#include "isom.h"
#include "libavcodec/get_bits.h"
+#include "id3v1.h"
#if CONFIG_ZLIB
#include <zlib.h>
@@ -81,15 +82,64 @@ typedef struct MOVParseTableEntry {
static const MOVParseTableEntry mov_default_parse_table[];
-static int mov_metadata_trkn(MOVContext *c, AVIOContext *pb, unsigned len)
+static int mov_metadata_track_or_disc_number(MOVContext *c, AVIOContext *pb,
+ unsigned len, const char *key)
{
char buf[16];
+ short current, total;
avio_rb16(pb); // unknown
- snprintf(buf, sizeof(buf), "%d", avio_rb16(pb));
- av_dict_set(&c->fc->metadata, "track", buf, 0);
+ current = avio_rb16(pb);
+ total = avio_rb16(pb);
+ if (!total)
+ snprintf(buf, sizeof(buf), "%d", current);
+ else
+ snprintf(buf, sizeof(buf), "%d/%d", current, total);
+ av_dict_set(&c->fc->metadata, key, buf, 0);
+
+ return 0;
+}
+
+static int mov_metadata_int8_bypass_padding(MOVContext *c, AVIOContext *pb,
+ unsigned len, const char *key)
+{
+ char buf[16];
+
+ /* bypass padding bytes */
+ avio_r8(pb);
+ avio_r8(pb);
+ avio_r8(pb);
+
+ snprintf(buf, sizeof(buf), "%hu", avio_r8(pb));
+ av_dict_set(&c->fc->metadata, key, buf, 0);
+
+ return 0;
+}
+
+static int mov_metadata_int8_no_padding(MOVContext *c, AVIOContext *pb,
+ unsigned len, const char *key)
+{
+ char buf[16];
+
+ snprintf(buf, sizeof(buf), "%hu", avio_r8(pb));
+ av_dict_set(&c->fc->metadata, key, buf, 0);
+
+ return 0;
+}
+
+static int mov_metadata_gnre(MOVContext *c, AVIOContext *pb,
+ unsigned len, const char *key)
+{
+ short genre;
+ char buf[20];
- avio_rb16(pb); // total tracks
+ avio_r8(pb); // unknown
+
+ genre = avio_r8(pb);
+ if (genre < 1 || genre > ID3v1_GENRE_MAX)
+ return 0;
+ snprintf(buf, sizeof(buf), "%s", ff_id3v1_genre_str[genre-1]);
+ av_dict_set(&c->fc->metadata, key, buf, 0);
return 0;
}
@@ -140,20 +190,25 @@ static int mov_read_udta_string(MOVContext *c, AVIOContext *pb, MOVAtom atom)
const char *key = NULL;
uint16_t str_size, langcode = 0;
uint32_t data_type = 0;
- int (*parse)(MOVContext*, AVIOContext*, unsigned) = NULL;
+ int (*parse)(MOVContext*, AVIOContext*, unsigned, const char*) = NULL;
switch (atom.type) {
case MKTAG(0xa9,'n','a','m'): key = "title"; break;
case MKTAG(0xa9,'a','u','t'):
case MKTAG(0xa9,'A','R','T'): key = "artist"; break;
+ case MKTAG( 'a','A','R','T'): key = "album_artist"; break;
case MKTAG(0xa9,'w','r','t'): key = "composer"; break;
case MKTAG( 'c','p','r','t'):
case MKTAG(0xa9,'c','p','y'): key = "copyright"; break;
+ case MKTAG(0xa9,'g','r','p'): key = "grouping"; break;
+ case MKTAG(0xa9,'l','y','r'): key = "lyrics"; break;
case MKTAG(0xa9,'c','m','t'):
case MKTAG(0xa9,'i','n','f'): key = "comment"; break;
case MKTAG(0xa9,'a','l','b'): key = "album"; break;
case MKTAG(0xa9,'d','a','y'): key = "date"; break;
case MKTAG(0xa9,'g','e','n'): key = "genre"; break;
+ case MKTAG( 'g','n','r','e'): key = "genre";
+ parse = mov_metadata_gnre; break;
case MKTAG(0xa9,'t','o','o'):
case MKTAG(0xa9,'s','w','r'): key = "encoder"; break;
case MKTAG(0xa9,'e','n','c'): key = "encoder"; break;
@@ -163,7 +218,19 @@ static int mov_read_udta_string(MOVContext *c, AVIOContext *pb, MOVAtom atom)
case MKTAG( 't','v','e','n'): key = "episode_id";break;
case MKTAG( 't','v','n','n'): key = "network"; break;
case MKTAG( 't','r','k','n'): key = "track";
- parse = mov_metadata_trkn; break;
+ parse = mov_metadata_track_or_disc_number; break;
+ case MKTAG( 'd','i','s','k'): key = "disc";
+ parse = mov_metadata_track_or_disc_number; break;
+ case MKTAG( 't','v','e','s'): key = "episode_sort";
+ parse = mov_metadata_int8_bypass_padding; break;
+ case MKTAG( 't','v','s','n'): key = "season_number";
+ parse = mov_metadata_int8_bypass_padding; break;
+ case MKTAG( 's','t','i','k'): key = "media_type";
+ parse = mov_metadata_int8_no_padding; break;
+ case MKTAG( 'h','d','v','d'): key = "hd_video";
+ parse = mov_metadata_int8_no_padding; break;
+ case MKTAG( 'p','g','a','p'): key = "gapless_playback";
+ parse = mov_metadata_int8_no_padding; break;
}
if (c->itunes_metadata && atom.size > 8) {
@@ -198,7 +265,7 @@ static int mov_read_udta_string(MOVContext *c, AVIOContext *pb, MOVAtom atom)
str_size = FFMIN3(sizeof(str)-1, str_size, atom.size);
if (parse)
- parse(c, pb, str_size);
+ parse(c, pb, str_size, key);
else {
if (data_type == 3 || (data_type == 0 && langcode < 0x800)) { // MAC Encoded
mov_read_mac_string(c, pb, str_size, str, sizeof(str));
@@ -246,7 +313,7 @@ static int mov_read_chpl(MOVContext *c, AVIOContext *pb, MOVAtom atom)
avio_read(pb, str, str_len);
str[str_len] = 0;
- ff_new_chapter(c->fc, i, (AVRational){1,10000000}, start, AV_NOPTS_VALUE, str);
+ avpriv_new_chapter(c->fc, i, (AVRational){1,10000000}, start, AV_NOPTS_VALUE, str);
}
return 0;
}
@@ -259,11 +326,11 @@ static int mov_read_default(MOVContext *c, AVIOContext *pb, MOVAtom atom)
if (atom.size < 0)
atom.size = INT64_MAX;
- while (total_size + 8 < atom.size && !pb->eof_reached) {
+ while (total_size + 8 < atom.size && !url_feof(pb)) {
int (*parse)(MOVContext*, AVIOContext*, MOVAtom) = NULL;
a.size = atom.size;
a.type=0;
- if(atom.size >= 8) {
+ if (atom.size >= 8) {
a.size = avio_rb32(pb);
a.type = avio_rl32(pb);
}
@@ -280,7 +347,7 @@ static int mov_read_default(MOVContext *c, AVIOContext *pb, MOVAtom atom)
break;
}
a.size -= 8;
- if(a.size < 0)
+ if (a.size < 0)
break;
a.size = FFMIN(a.size, atom.size - total_size);
@@ -447,11 +514,11 @@ static int mov_read_hdlr(MOVContext *c, AVIOContext *pb, MOVAtom atom)
if (type == MKTAG('v','i','d','e'))
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
- else if(type == MKTAG('s','o','u','n'))
+ else if (type == MKTAG('s','o','u','n'))
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
- else if(type == MKTAG('m','1','a',' '))
+ else if (type == MKTAG('m','1','a',' '))
st->codec->codec_id = CODEC_ID_MP2;
- else if(type == MKTAG('s','u','b','p'))
+ else if ((type == MKTAG('s','u','b','p')) || (type == MKTAG('c','l','c','p')))
st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;
avio_rb32(pb); /* component manufacture */
@@ -473,8 +540,7 @@ int ff_mov_read_esds(AVFormatContext *fc, AVIOContext *pb, MOVAtom atom)
avio_rb32(pb); /* version + flags */
ff_mp4_read_descr(fc, pb, &tag);
if (tag == MP4ESDescrTag) {
- avio_rb16(pb); /* ID */
- avio_r8(pb); /* priority */
+ ff_mp4_parse_es_descr(pb, NULL);
} else
avio_rb16(pb); /* ID */
@@ -549,7 +615,7 @@ static int mov_read_pasp(MOVContext *c, AVIOContext *pb, MOVAtom atom)
/* this atom contains actual media data */
static int mov_read_mdat(MOVContext *c, AVIOContext *pb, MOVAtom atom)
{
- if(atom.size == 0) /* wrong one (MP4) */
+ if (atom.size == 0) /* wrong one (MP4) */
return 0;
c->found_mdat=1;
return 0; /* now go for moov */
@@ -703,7 +769,7 @@ static int mov_read_smi(MOVContext *c, AVIOContext *pb, MOVAtom atom)
return 0;
st = c->fc->streams[c->fc->nb_streams-1];
- if((uint64_t)atom.size > (1<<30))
+ if ((uint64_t)atom.size > (1<<30))
return -1;
// currently SVQ3 decoder expect full STSD header - so let's fake it
@@ -728,7 +794,7 @@ static int mov_read_enda(MOVContext *c, AVIOContext *pb, MOVAtom atom)
return 0;
st = c->fc->streams[c->fc->nb_streams-1];
- little_endian = avio_rb16(pb);
+ little_endian = avio_rb16(pb) & 0xFF;
av_dlog(c->fc, "enda %d\n", little_endian);
if (little_endian == 1) {
switch (st->codec->codec_id) {
@@ -752,7 +818,8 @@ static int mov_read_enda(MOVContext *c, AVIOContext *pb, MOVAtom atom)
}
/* FIXME modify qdm2/svq3/h264 decoders to take full atom as extradata */
-static int mov_read_extradata(MOVContext *c, AVIOContext *pb, MOVAtom atom)
+static int mov_read_extradata(MOVContext *c, AVIOContext *pb, MOVAtom atom,
+ enum CodecID codec_id)
{
AVStream *st;
uint64_t size;
@@ -761,11 +828,15 @@ static int mov_read_extradata(MOVContext *c, AVIOContext *pb, MOVAtom atom)
if (c->fc->nb_streams < 1) // will happen with jp2 files
return 0;
st= c->fc->streams[c->fc->nb_streams-1];
+
+ if (st->codec->codec_id != codec_id)
+ return 0; /* unexpected codec_id - don't mess with extradata */
+
size= (uint64_t)st->codec->extradata_size + atom.size + 8 + FF_INPUT_BUFFER_PADDING_SIZE;
- if(size > INT_MAX || (uint64_t)atom.size > INT_MAX)
+ if (size > INT_MAX || (uint64_t)atom.size > INT_MAX)
return -1;
buf= av_realloc(st->codec->extradata, size);
- if(!buf)
+ if (!buf)
return -1;
st->codec->extradata= buf;
buf+= st->codec->extradata_size;
@@ -776,6 +847,27 @@ static int mov_read_extradata(MOVContext *c, AVIOContext *pb, MOVAtom atom)
return 0;
}
+/* wrapper functions for reading ALAC/AVS/MJPEG/MJPEG2000 extradata atoms only for those codecs */
+static int mov_read_alac(MOVContext *c, AVIOContext *pb, MOVAtom atom)
+{
+ return mov_read_extradata(c, pb, atom, CODEC_ID_ALAC);
+}
+
+static int mov_read_avss(MOVContext *c, AVIOContext *pb, MOVAtom atom)
+{
+ return mov_read_extradata(c, pb, atom, CODEC_ID_AVS);
+}
+
+static int mov_read_fiel(MOVContext *c, AVIOContext *pb, MOVAtom atom)
+{
+ return mov_read_extradata(c, pb, atom, CODEC_ID_MJPEG);
+}
+
+static int mov_read_jp2h(MOVContext *c, AVIOContext *pb, MOVAtom atom)
+{
+ return mov_read_extradata(c, pb, atom, CODEC_ID_JPEG2000);
+}
+
static int mov_read_wave(MOVContext *c, AVIOContext *pb, MOVAtom atom)
{
AVStream *st;
@@ -784,7 +876,7 @@ static int mov_read_wave(MOVContext *c, AVIOContext *pb, MOVAtom atom)
return 0;
st = c->fc->streams[c->fc->nb_streams-1];
- if((uint64_t)atom.size > (1<<30))
+ if ((uint64_t)atom.size > (1<<30))
return -1;
if (st->codec->codec_id == CODEC_ID_QDM2 || st->codec->codec_id == CODEC_ID_QDMC) {
@@ -815,7 +907,7 @@ static int mov_read_glbl(MOVContext *c, AVIOContext *pb, MOVAtom atom)
return 0;
st = c->fc->streams[c->fc->nb_streams-1];
- if((uint64_t)atom.size > (1<<30))
+ if ((uint64_t)atom.size > (1<<30))
return -1;
av_free(st->codec->extradata);
@@ -842,7 +934,7 @@ static int mov_read_strf(MOVContext *c, AVIOContext *pb, MOVAtom atom)
return 0;
st = c->fc->streams[c->fc->nb_streams-1];
- if((uint64_t)atom.size > (1<<30))
+ if ((uint64_t)atom.size > (1<<30))
return -1;
av_free(st->codec->extradata);
@@ -871,7 +963,7 @@ static int mov_read_stco(MOVContext *c, AVIOContext *pb, MOVAtom atom)
entries = avio_rb32(pb);
- if(entries >= UINT_MAX/sizeof(int64_t))
+ if (entries >= UINT_MAX/sizeof(int64_t))
return -1;
sc->chunk_offsets = av_malloc(entries * sizeof(int64_t));
@@ -880,10 +972,10 @@ static int mov_read_stco(MOVContext *c, AVIOContext *pb, MOVAtom atom)
sc->chunk_count = entries;
if (atom.type == MKTAG('s','t','c','o'))
- for(i=0; i<entries; i++)
+ for (i=0; i<entries; i++)
sc->chunk_offsets[i] = avio_rb32(pb);
else if (atom.type == MKTAG('c','o','6','4'))
- for(i=0; i<entries; i++)
+ for (i=0; i<entries; i++)
sc->chunk_offsets[i] = avio_rb64(pb);
else
return -1;
@@ -937,7 +1029,7 @@ int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries)
st = c->fc->streams[c->fc->nb_streams-1];
sc = st->priv_data;
- for(pseudo_stream_id=0; pseudo_stream_id<entries; pseudo_stream_id++) {
+ for (pseudo_stream_id=0; pseudo_stream_id<entries; pseudo_stream_id++) {
//Parsing Sample description table
enum CodecID id;
int dref_id = 1;
@@ -985,9 +1077,9 @@ int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries)
id = ff_codec_get_id(ff_codec_bmp_tags, format);
if (id > 0)
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
- else if(st->codec->codec_type == AVMEDIA_TYPE_DATA){
+ else if (st->codec->codec_type == AVMEDIA_TYPE_DATA){
id = ff_codec_get_id(ff_codec_movsubtitle_tags, format);
- if(id > 0)
+ if (id > 0)
st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;
}
}
@@ -996,7 +1088,7 @@ int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries)
(format >> 0) & 0xff, (format >> 8) & 0xff, (format >> 16) & 0xff,
(format >> 24) & 0xff, st->codec->codec_type);
- if(st->codec->codec_type==AVMEDIA_TYPE_VIDEO) {
+ if (st->codec->codec_type==AVMEDIA_TYPE_VIDEO) {
unsigned int color_depth, len;
int color_greyscale;
@@ -1048,6 +1140,9 @@ int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries)
color_index = 255;
color_dec = 256 / (color_count - 1);
for (j = 0; j < color_count; j++) {
+ if (id == CODEC_ID_CINEPAK){
+ r = g = b = color_count - 1 - color_index;
+ }else
r = g = b = color_index;
sc->palette[j] =
(r << 16) | (g << 8) | (b);
@@ -1099,7 +1194,7 @@ int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries)
}
sc->has_palette = 1;
}
- } else if(st->codec->codec_type==AVMEDIA_TYPE_AUDIO) {
+ } else if (st->codec->codec_type==AVMEDIA_TYPE_AUDIO) {
int bits_per_sample, flags;
uint16_t version = avio_rb16(pb);
@@ -1118,13 +1213,13 @@ int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries)
//Read QT version 1 fields. In version 0 these do not exist.
av_dlog(c->fc, "version =%d, isom =%d\n",version,c->isom);
- if(!c->isom) {
- if(version==1) {
+ if (!c->isom) {
+ if (version==1) {
sc->samples_per_frame = avio_rb32(pb);
avio_rb32(pb); /* bytes per packet */
sc->bytes_per_frame = avio_rb32(pb);
avio_rb32(pb); /* bytes per sample */
- } else if(version==2) {
+ } else if (version==2) {
avio_rb32(pb); /* sizeof struct only */
st->codec->sample_rate = av_int2dbl(avio_rb64(pb)); /* float 64 */
st->codec->channels = avio_rb32(pb);
@@ -1179,7 +1274,7 @@ int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries)
st->codec->bits_per_coded_sample = bits_per_sample;
sc->sample_size = (bits_per_sample >> 3) * st->codec->channels;
}
- } else if(st->codec->codec_type==AVMEDIA_TYPE_SUBTITLE){
+ } else if (st->codec->codec_type==AVMEDIA_TYPE_SUBTITLE){
// ttxt stsd contains display flags, justification, background
// color, fonts, and default styles, so fake an atom to read it
MOVAtom fake_atom = { .size = size - (avio_tell(pb) - start_pos) };
@@ -1189,7 +1284,18 @@ int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries)
st->codec->width = sc->width;
st->codec->height = sc->height;
} else {
- /* other codec type, just skip (rtp, mp4s, tmcd ...) */
+ if (st->codec->codec_tag == MKTAG('t','m','c','d')) {
+ int val;
+ avio_rb32(pb); /* reserved */
+ val = avio_rb32(pb); /* flags */
+ if (val & 1)
+ st->codec->flags2 |= CODEC_FLAG2_DROP_FRAME_TIMECODE;
+ avio_rb32(pb);
+ avio_rb32(pb);
+ st->codec->time_base.den = get_byte(pb);
+ st->codec->time_base.num = 1;
+ }
+ /* other codec type, just skip (rtp, mp4s, ...) */
avio_skip(pb, size - (avio_tell(pb) - start_pos));
}
/* this will read extra atoms at the end (wave, alac, damr, avcC, SMI ...) */
@@ -1201,7 +1307,7 @@ int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries)
avio_skip(pb, a.size);
}
- if(st->codec->codec_type==AVMEDIA_TYPE_AUDIO && st->codec->sample_rate==0 && sc->time_scale>1)
+ if (st->codec->codec_type==AVMEDIA_TYPE_AUDIO && st->codec->sample_rate==0 && sc->time_scale>1)
st->codec->sample_rate= sc->time_scale;
/* special codec parameters handling */
@@ -1209,7 +1315,7 @@ int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries)
#if CONFIG_DV_DEMUXER
case CODEC_ID_DVAUDIO:
c->dv_fctx = avformat_alloc_context();
- c->dv_demux = dv_init_demux(c->dv_fctx);
+ c->dv_demux = avpriv_dv_init_demux(c->dv_fctx);
if (!c->dv_demux) {
av_log(c->fc, AV_LOG_ERROR, "dv demux context init error\n");
return -1;
@@ -1254,6 +1360,9 @@ int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries)
st->codec->sample_rate = AV_RB32(st->codec->extradata+32);
}
break;
+ case CODEC_ID_AC3:
+ st->need_parsing = AVSTREAM_PARSE_FULL;
+ break;
default:
break;
}
@@ -1290,14 +1399,14 @@ static int mov_read_stsc(MOVContext *c, AVIOContext *pb, MOVAtom atom)
av_dlog(c->fc, "track[%i].stsc.entries = %i\n", c->fc->nb_streams-1, entries);
- if(entries >= UINT_MAX / sizeof(*sc->stsc_data))
+ if (entries >= UINT_MAX / sizeof(*sc->stsc_data))
return -1;
sc->stsc_data = av_malloc(entries * sizeof(*sc->stsc_data));
if (!sc->stsc_data)
return AVERROR(ENOMEM);
sc->stsc_count = entries;
- for(i=0; i<entries; i++) {
+ for (i=0; i<entries; i++) {
sc->stsc_data[i].first = avio_rb32(pb);
sc->stsc_data[i].count = avio_rb32(pb);
sc->stsc_data[i].id = avio_rb32(pb);
@@ -1352,14 +1461,14 @@ static int mov_read_stss(MOVContext *c, AVIOContext *pb, MOVAtom atom)
av_dlog(c->fc, "keyframe_count = %d\n", entries);
- if(entries >= UINT_MAX / sizeof(int))
+ if (entries >= UINT_MAX / sizeof(int))
return -1;
sc->keyframes = av_malloc(entries * sizeof(int));
if (!sc->keyframes)
return AVERROR(ENOMEM);
sc->keyframe_count = entries;
- for(i=0; i<entries; i++) {
+ for (i=0; i<entries; i++) {
sc->keyframes[i] = avio_rb32(pb);
//av_dlog(c->fc, "keyframes[]=%d\n", sc->keyframes[i]);
}
@@ -1427,7 +1536,7 @@ static int mov_read_stsz(MOVContext *c, AVIOContext *pb, MOVAtom atom)
init_get_bits(&gb, buf, 8*num_bytes);
- for(i=0; i<entries; i++)
+ for (i=0; i<entries; i++)
sc->sample_sizes[i] = get_bits_long(&gb, field_size);
av_free(buf);
@@ -1451,32 +1560,41 @@ static int mov_read_stts(MOVContext *c, AVIOContext *pb, MOVAtom atom)
avio_rb24(pb); /* flags */
entries = avio_rb32(pb);
- av_dlog(c->fc, "track[%i].stts.entries = %i\n", c->fc->nb_streams-1, entries);
+ av_dlog(c->fc, "track[%i].stts.entries = %i\n",
+ c->fc->nb_streams-1, entries);
+
+ if (!entries || entries >= UINT_MAX / sizeof(*sc->stts_data))
+ return AVERROR(EINVAL);
- if(entries >= UINT_MAX / sizeof(*sc->stts_data))
- return -1;
sc->stts_data = av_malloc(entries * sizeof(*sc->stts_data));
if (!sc->stts_data)
return AVERROR(ENOMEM);
+
sc->stts_count = entries;
- for(i=0; i<entries; i++) {
+ for (i=0; i<entries; i++) {
int sample_duration;
int sample_count;
sample_count=avio_rb32(pb);
sample_duration = avio_rb32(pb);
+ /* sample_duration < 0 is invalid based on the spec */
+ if (sample_duration < 0) {
+ av_log(c->fc, AV_LOG_ERROR, "Invalid SampleDelta in STTS %d", sample_duration);
+ sample_duration = 1;
+ }
sc->stts_data[i].count= sample_count;
sc->stts_data[i].duration= sample_duration;
- av_dlog(c->fc, "sample_count=%d, sample_duration=%d\n",sample_count,sample_duration);
+ av_dlog(c->fc, "sample_count=%d, sample_duration=%d\n",
+ sample_count, sample_duration);
duration+=(int64_t)sample_duration*sample_count;
total_sample_count+=sample_count;
}
st->nb_frames= total_sample_count;
- if(duration)
+ if (duration)
st->duration= duration;
return 0;
}
@@ -1498,20 +1616,20 @@ static int mov_read_ctts(MOVContext *c, AVIOContext *pb, MOVAtom atom)
av_dlog(c->fc, "track[%i].ctts.entries = %i\n", c->fc->nb_streams-1, entries);
- if(entries >= UINT_MAX / sizeof(*sc->ctts_data))
+ if (entries >= UINT_MAX / sizeof(*sc->ctts_data))
return -1;
sc->ctts_data = av_malloc(entries * sizeof(*sc->ctts_data));
if (!sc->ctts_data)
return AVERROR(ENOMEM);
sc->ctts_count = entries;
- for(i=0; i<entries; i++) {
+ for (i=0; i<entries; i++) {
int count =avio_rb32(pb);
int duration =avio_rb32(pb);
sc->ctts_data[i].count = count;
sc->ctts_data[i].duration= duration;
- if (duration < 0)
+ if (duration < 0 && i+2<entries)
sc->dts_shift = FFMAX(sc->dts_shift, -duration);
}
@@ -1538,7 +1656,7 @@ static void mov_build_index(MOVContext *mov, AVStream *st)
sc->time_offset = av_rescale(sc->time_offset, sc->time_scale, mov->time_scale);
current_dts = -sc->time_offset;
if (sc->ctts_data && sc->stts_data &&
- sc->ctts_data[0].duration / sc->stts_data[0].duration > 16) {
+ sc->ctts_data[0].duration / FFMAX(sc->stts_data[0].duration, 1) > 16) {
/* more than 16 frames delay, dts are likely wrong
this happens with files created by iMovie */
sc->wrong_dts = 1;
@@ -1588,7 +1706,7 @@ static void mov_build_index(MOVContext *mov, AVStream *st)
if (keyframe)
distance = 0;
sample_size = sc->sample_size > 0 ? sc->sample_size : sc->sample_sizes[current_sample];
- if(sc->pseudo_stream_id == -1 ||
+ if (sc->pseudo_stream_id == -1 ||
sc->stsc_data[stsc_index].id - 1 == sc->pseudo_stream_id) {
AVIndexEntry *e = &st->index_entries[st->nb_index_entries++];
e->pos = current_offset;
@@ -1700,13 +1818,13 @@ static void mov_build_index(MOVContext *mov, AVStream *st)
}
}
-static int mov_open_dref(AVIOContext **pb, char *src, MOVDref *ref)
+static int mov_open_dref(AVIOContext **pb, const char *src, MOVDref *ref)
{
/* try relative path, we do not try the absolute because it can leak information about our
system to an attacker */
if (ref->nlvl_to > 0 && ref->nlvl_from > 0) {
char filename[1024];
- char *src_path;
+ const char *src_path;
int i, l;
/* find a source dir */
@@ -1749,8 +1867,9 @@ static int mov_read_trak(MOVContext *c, AVIOContext *pb, MOVAtom atom)
MOVStreamContext *sc;
int ret;
- st = av_new_stream(c->fc, c->fc->nb_streams);
+ st = avformat_new_stream(c->fc, NULL);
if (!st) return AVERROR(ENOMEM);
+ st->id = c->fc->nb_streams;
sc = av_mallocz(sizeof(MOVStreamContext));
if (!sc) return AVERROR(ENOMEM);
@@ -1924,6 +2043,10 @@ static int mov_read_tkhd(MOVContext *c, AVIOContext *pb, MOVAtom atom)
sc->width = width >> 16;
sc->height = height >> 16;
+ if (display_matrix[0][0] == -65536 && display_matrix[1][1] == -65536) {
+ av_dict_set(&st->metadata, "rotate", "180", 0);
+ }
+
// transform the display width/height according to the matrix
// skip this if the display matrix is the default identity matrix
// or if it is rotating the picture, ex iPhone 3GS
@@ -2153,9 +2276,9 @@ static int mov_read_cmov(MOVContext *c, AVIOContext *pb, MOVAtom atom)
return AVERROR(ENOMEM);
}
avio_read(pb, cmov_data, cmov_len);
- if(uncompress (moov_data, (uLongf *) &moov_len, (const Bytef *)cmov_data, cmov_len) != Z_OK)
+ if (uncompress (moov_data, (uLongf *) &moov_len, (const Bytef *)cmov_data, cmov_len) != Z_OK)
goto free_and_return;
- if(ffio_init_context(&ctx, moov_data, moov_len, 0, NULL, NULL, NULL, NULL) != 0)
+ if (ffio_init_context(&ctx, moov_data, moov_len, 0, NULL, NULL, NULL, NULL) != 0)
goto free_and_return;
atom.type = MKTAG('m','o','o','v');
atom.size = moov_len;
@@ -2184,10 +2307,10 @@ static int mov_read_elst(MOVContext *c, AVIOContext *pb, MOVAtom atom)
avio_rb24(pb); /* flags */
edit_count = avio_rb32(pb); /* entries */
- if((uint64_t)edit_count*12+8 > atom.size)
+ if ((uint64_t)edit_count*12+8 > atom.size)
return -1;
- for(i=0; i<edit_count; i++){
+ for (i=0; i<edit_count; i++){
int64_t time;
int64_t duration;
if (version == 1) {
@@ -2203,7 +2326,7 @@ static int mov_read_elst(MOVContext *c, AVIOContext *pb, MOVAtom atom)
}
}
- if(edit_count > 1)
+ if (edit_count > 1)
av_log(c->fc, AV_LOG_WARNING, "multiple edit list entries, "
"a/v desync might occur, patch welcome\n");
@@ -2211,8 +2334,17 @@ static int mov_read_elst(MOVContext *c, AVIOContext *pb, MOVAtom atom)
return 0;
}
+static int mov_read_chan(MOVContext *c, AVIOContext *pb, MOVAtom atom)
+{
+ if (atom.size < 16)
+ return AVERROR_INVALIDDATA;
+ avio_skip(pb, 4);
+ ff_mov_read_chan(c->fc, atom.size - 4, c->fc->streams[0]->codec);
+ return 0;
+}
+
static const MOVParseTableEntry mov_default_parse_table[] = {
-{ MKTAG('a','v','s','s'), mov_read_extradata },
+{ MKTAG('a','v','s','s'), mov_read_avss },
{ MKTAG('c','h','p','l'), mov_read_chpl },
{ MKTAG('c','o','6','4'), mov_read_stco },
{ MKTAG('c','t','t','s'), mov_read_ctts }, /* composition time to sample */
@@ -2221,12 +2353,12 @@ static const MOVParseTableEntry mov_default_parse_table[] = {
{ MKTAG('e','d','t','s'), mov_read_default },
{ MKTAG('e','l','s','t'), mov_read_elst },
{ MKTAG('e','n','d','a'), mov_read_enda },
-{ MKTAG('f','i','e','l'), mov_read_extradata },
+{ MKTAG('f','i','e','l'), mov_read_fiel },
{ MKTAG('f','t','y','p'), mov_read_ftyp },
{ MKTAG('g','l','b','l'), mov_read_glbl },
{ MKTAG('h','d','l','r'), mov_read_hdlr },
{ MKTAG('i','l','s','t'), mov_read_ilst },
-{ MKTAG('j','p','2','h'), mov_read_extradata },
+{ MKTAG('j','p','2','h'), mov_read_jp2h },
{ MKTAG('m','d','a','t'), mov_read_mdat },
{ MKTAG('m','d','h','d'), mov_read_mdhd },
{ MKTAG('m','d','i','a'), mov_read_default },
@@ -2237,7 +2369,7 @@ static const MOVParseTableEntry mov_default_parse_table[] = {
{ MKTAG('m','v','e','x'), mov_read_default },
{ MKTAG('m','v','h','d'), mov_read_mvhd },
{ MKTAG('S','M','I',' '), mov_read_smi }, /* Sorenson extension ??? */
-{ MKTAG('a','l','a','c'), mov_read_extradata }, /* alac specific atom */
+{ MKTAG('a','l','a','c'), mov_read_alac }, /* alac specific atom */
{ MKTAG('a','v','c','C'), mov_read_glbl },
{ MKTAG('p','a','s','p'), mov_read_pasp },
{ MKTAG('s','t','b','l'), mov_read_default },
@@ -2265,6 +2397,7 @@ static const MOVParseTableEntry mov_default_parse_table[] = {
{ MKTAG('w','i','d','e'), mov_read_wide }, /* place holder */
{ MKTAG('w','f','e','x'), mov_read_wfex },
{ MKTAG('c','m','o','v'), mov_read_cmov },
+{ MKTAG('c','h','a','n'), mov_read_chan },
{ 0, NULL }
};
@@ -2276,7 +2409,7 @@ static int mov_probe(AVProbeData *p)
/* check file header */
offset = 0;
- for(;;) {
+ for (;;) {
/* ignore invalid offset */
if ((offset + 8) > (unsigned int)p->buf_size)
return score;
@@ -2358,17 +2491,24 @@ static void mov_read_chapters(AVFormatContext *s)
// The samples could theoretically be in any encoding if there's an encd
// atom following, but in practice are only utf-8 or utf-16, distinguished
// instead by the presence of a BOM
- ch = avio_rb16(sc->pb);
- if (ch == 0xfeff)
- avio_get_str16be(sc->pb, len, title, title_len);
- else if (ch == 0xfffe)
- avio_get_str16le(sc->pb, len, title, title_len);
- else {
- AV_WB16(title, ch);
- avio_get_str(sc->pb, len - 2, title + 2, title_len - 2);
+ if (!len) {
+ title[0] = 0;
+ } else {
+ ch = avio_rb16(sc->pb);
+ if (ch == 0xfeff)
+ avio_get_str16be(sc->pb, len, title, title_len);
+ else if (ch == 0xfffe)
+ avio_get_str16le(sc->pb, len, title, title_len);
+ else {
+ AV_WB16(title, ch);
+ if (len == 1 || len == 2)
+ title[len] = 0;
+ else
+ get_strz(sc->pb, title + 2, len - 1);
+ }
}
- ff_new_chapter(s, i, st->time_base, sample->timestamp, end, title);
+ avpriv_new_chapter(s, i, st->time_base, sample->timestamp, end, title);
av_freep(&title);
}
finish:
@@ -2384,7 +2524,7 @@ static int mov_read_header(AVFormatContext *s, AVFormatParameters *ap)
mov->fc = s;
/* .mov and .mp4 aren't streamable anyway (only progressive download if moov is before mdat) */
- if(pb->seekable)
+ if (pb->seekable)
atom.size = avio_size(pb);
else
atom.size = INT64_MAX;
@@ -2445,7 +2585,7 @@ static int mov_read_packet(AVFormatContext *s, AVPacket *pkt)
mov->found_mdat = 0;
if (s->pb->seekable||
mov_read_default(mov, s->pb, (MOVAtom){ AV_RL32("root"), INT64_MAX }) < 0 ||
- s->pb->eof_reached)
+ url_feof(s->pb))
return AVERROR_EOF;
av_dlog(s, "read fragments, offset 0x%"PRIx64"\n", avio_tell(s->pb));
goto retry;
@@ -2476,10 +2616,10 @@ static int mov_read_packet(AVFormatContext *s, AVPacket *pkt)
}
#if CONFIG_DV_DEMUXER
if (mov->dv_demux && sc->dv_audio_container) {
- dv_produce_packet(mov->dv_demux, pkt, pkt->data, pkt->size);
+ avpriv_dv_produce_packet(mov->dv_demux, pkt, pkt->data, pkt->size, pkt->pos);
av_free(pkt->data);
pkt->size = 0;
- ret = dv_get_packet(mov->dv_demux, pkt);
+ ret = avpriv_dv_get_packet(mov->dv_demux, pkt);
if (ret < 0)
return ret;
}
@@ -2592,12 +2732,10 @@ static int mov_read_close(AVFormatContext *s)
av_freep(&sc->drefs);
if (sc->pb && sc->pb != s->pb)
avio_close(sc->pb);
-
- av_freep(&st->codec->palctrl);
}
if (mov->dv_demux) {
- for(i = 0; i < mov->dv_fctx->nb_streams; i++) {
+ for (i = 0; i < mov->dv_fctx->nb_streams; i++) {
av_freep(&mov->dv_fctx->streams[i]->codec);
av_freep(&mov->dv_fctx->streams[i]);
}
@@ -2611,12 +2749,12 @@ static int mov_read_close(AVFormatContext *s)
}
AVInputFormat ff_mov_demuxer = {
- "mov,mp4,m4a,3gp,3g2,mj2",
- NULL_IF_CONFIG_SMALL("QuickTime/MPEG-4/Motion JPEG 2000 format"),
- sizeof(MOVContext),
- mov_probe,
- mov_read_header,
- mov_read_packet,
- mov_read_close,
- mov_read_seek,
+ .name = "mov,mp4,m4a,3gp,3g2,mj2",
+ .long_name = NULL_IF_CONFIG_SMALL("QuickTime/MPEG-4/Motion JPEG 2000 format"),
+ .priv_data_size = sizeof(MOVContext),
+ .read_probe = mov_probe,
+ .read_header = mov_read_header,
+ .read_packet = mov_read_packet,
+ .read_close = mov_read_close,
+ .read_seek = mov_read_seek,
};
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 0de7c4d44d..1d5a96e51a 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -4,20 +4,20 @@
* Copyright (c) 2004 Gildas Bazin <gbazin at videolan dot org>
* Copyright (c) 2009 Baptiste Coudurier <baptiste dot coudurier at gmail dot com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -42,17 +42,18 @@
#include <assert.h>
static const AVOption options[] = {
- { "movflags", "MOV muxer flags", offsetof(MOVMuxContext, flags), FF_OPT_TYPE_FLAGS, {.dbl = 0}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
- { "rtphint", "Add RTP hint tracks", 0, FF_OPT_TYPE_CONST, {.dbl = FF_MOV_FLAG_RTP_HINT}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
+ { "movflags", "MOV muxer flags", offsetof(MOVMuxContext, flags), AV_OPT_TYPE_FLAGS, {.dbl = 0}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
+ { "rtphint", "Add RTP hint tracks", 0, AV_OPT_TYPE_CONST, {.dbl = FF_MOV_FLAG_RTP_HINT}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
FF_RTP_FLAG_OPTS(MOVMuxContext, rtp_flags),
{ NULL },
};
-static const AVClass mov_muxer_class = {
- .class_name = "MOV/3GP/MP4/3G2 muxer",
- .item_name = av_default_item_name,
- .option = options,
- .version = LIBAVUTIL_VERSION_INT,
+#define MOV_CLASS(flavor)\
+static const AVClass flavor ## _muxer_class = {\
+ .class_name = #flavor " muxer",\
+ .item_name = av_default_item_name,\
+ .option = options,\
+ .version = LIBAVUTIL_VERSION_INT,\
};
//FIXME support 64 bit variant with wide placeholders
@@ -208,7 +209,7 @@ static int mov_write_ac3_tag(AVIOContext *pb, MOVTrack *track)
avio_wb32(pb, 11);
ffio_wfourcc(pb, "dac3");
- init_get_bits(&gbc, track->vosData+4, track->vosLen-4);
+ init_get_bits(&gbc, track->vosData+4, (track->vosLen-4) * 8);
fscod = get_bits(&gbc, 2);
frmsizecod = get_bits(&gbc, 6);
bsid = get_bits(&gbc, 5);
@@ -266,10 +267,20 @@ static void putDescr(AVIOContext *pb, int tag, unsigned int size)
avio_w8(pb, size & 0x7F);
}
+static unsigned compute_avg_bitrate(MOVTrack *track)
+{
+ uint64_t size = 0;
+ int i;
+ for (i = 0; i < track->entry; i++)
+ size += track->cluster[i].size;
+ return size * 8 * track->timescale / track->trackDuration;
+}
+
static int mov_write_esds_tag(AVIOContext *pb, MOVTrack *track) // Basic
{
int64_t pos = avio_tell(pb);
int decoderSpecificInfoLen = track->vosLen ? 5+track->vosLen : 0;
+ unsigned avg_bitrate;
avio_wb32(pb, 0); // size
ffio_wfourcc(pb, "esds");
@@ -301,11 +312,10 @@ static int mov_write_esds_tag(AVIOContext *pb, MOVTrack *track) // Basic
avio_w8(pb, track->enc->rc_buffer_size>>(3+16)); // Buffersize DB (24 bits)
avio_wb16(pb, (track->enc->rc_buffer_size>>3)&0xFFFF); // Buffersize DB
- avio_wb32(pb, FFMAX(track->enc->bit_rate, track->enc->rc_max_rate)); // maxbitrate (FIXME should be max rate in any 1 sec window)
- if(track->enc->rc_max_rate != track->enc->rc_min_rate || track->enc->rc_min_rate==0)
- avio_wb32(pb, 0); // vbr
- else
- avio_wb32(pb, track->enc->rc_max_rate); // avg bitrate
+ avg_bitrate = compute_avg_bitrate(track);
+ // maxbitrate (FIXME should be max rate in any 1 sec window)
+ avio_wb32(pb, FFMAX3(track->enc->bit_rate, track->enc->rc_max_rate, avg_bitrate));
+ avio_wb32(pb, avg_bitrate);
if (track->vosLen) {
// DecoderSpecific info descriptor
@@ -711,7 +721,7 @@ static int mov_get_codec_tag(AVFormatContext *s, MOVTrack *track)
if (!tag) { // if no mac fcc found, try with Microsoft tags
tag = ff_codec_get_tag(ff_codec_bmp_tags, track->enc->codec_id);
if (tag)
- av_log(s, AV_LOG_INFO, "Warning, using MS style video codec tag, "
+ av_log(s, AV_LOG_WARNING, "Using MS style video codec tag, "
"the file may be unplayable!\n");
}
} else if (track->enc->codec_type == AVMEDIA_TYPE_AUDIO) {
@@ -720,7 +730,7 @@ static int mov_get_codec_tag(AVFormatContext *s, MOVTrack *track)
int ms_tag = ff_codec_get_tag(ff_codec_wav_tags, track->enc->codec_id);
if (ms_tag) {
tag = MKTAG('m', 's', ((ms_tag >> 8) & 0xff), (ms_tag & 0xff));
- av_log(s, AV_LOG_INFO, "Warning, using MS style audio codec tag, "
+ av_log(s, AV_LOG_WARNING, "Using MS style audio codec tag, "
"the file may be unplayable!\n");
}
}
@@ -1216,7 +1226,8 @@ static int mov_write_tkhd_tag(AVIOContext *pb, MOVTrack *track, AVStream *st)
avio_wb32(pb, 0); /* reserved */
avio_wb32(pb, 0); /* reserved */
- avio_wb32(pb, 0x0); /* reserved (Layer & Alternate group) */
+ avio_wb16(pb, 0); /* layer */
+ avio_wb16(pb, st ? st->codec->codec_type : 0); /* alternate group) */
/* Volume, only for audio */
if(track->enc->codec_type == AVMEDIA_TYPE_AUDIO)
avio_wb16(pb, 0x0100);
@@ -2002,7 +2013,7 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt)
if (enc->codec_id == CODEC_ID_AMR_NB) {
/* We must find out how many AMR blocks there are in one packet */
static uint16_t packed_size[16] =
- {13, 14, 16, 18, 20, 21, 27, 32, 6, 0, 0, 0, 0, 0, 0, 0};
+ {13, 14, 16, 18, 20, 21, 27, 32, 6, 0, 0, 0, 0, 0, 0, 1};
int len = 0;
while (len < size && samplesInChunk < 100) {
@@ -2032,6 +2043,10 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt)
/* from x264 or from bytestream h264 */
/* nal reformating needed */
size = ff_avc_parse_nal_units(pb, pkt->data, pkt->size);
+ } else if (enc->codec_id == CODEC_ID_AAC && pkt->size > 2 &&
+ (AV_RB16(pkt->data) & 0xfff0) == 0xfff0) {
+ av_log(s, AV_LOG_ERROR, "malformated aac bitstream, use -absf aac_adtstoasc\n");
+ return -1;
} else {
avio_write(pb, pkt->data, size);
}
@@ -2047,7 +2062,7 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt)
}
if (!(trk->entry % MOV_INDEX_CLUSTER_SIZE)) {
- trk->cluster = av_realloc(trk->cluster, (trk->entry + MOV_INDEX_CLUSTER_SIZE) * sizeof(*trk->cluster));
+ trk->cluster = av_realloc_f(trk->cluster, sizeof(*trk->cluster), (trk->entry + MOV_INDEX_CLUSTER_SIZE));
if (!trk->cluster)
return -1;
}
@@ -2102,7 +2117,7 @@ static void mov_create_chapter_track(AVFormatContext *s, int tracknum)
track->mode = mov->mode;
track->tag = MKTAG('t','e','x','t');
track->timescale = MOV_TIMESCALE;
- track->enc = avcodec_alloc_context();
+ track->enc = avcodec_alloc_context3(NULL);
track->enc->codec_type = AVMEDIA_TYPE_SUBTITLE;
for (i = 0; i < s->nb_chapters; i++) {
@@ -2129,6 +2144,7 @@ static int mov_write_header(AVFormatContext *s)
{
AVIOContext *pb = s->pb;
MOVMuxContext *mov = s->priv_data;
+ AVDictionaryEntry *t;
int i, hint_track = 0;
if (!s->pb->seekable) {
@@ -2259,7 +2275,15 @@ static int mov_write_header(AVFormatContext *s)
}
mov_write_mdat_tag(pb, mov);
- mov->time = s->timestamp + 0x7C25B080; //1970 based -> 1904 based
+
+#if FF_API_TIMESTAMP
+ if (s->timestamp)
+ mov->time = s->timestamp;
+ else
+#endif
+ if (t = av_dict_get(s->metadata, "creation_time", NULL, 0))
+ mov->time = ff_iso8601_to_unix_time(t->value);
+ mov->time += 0x7C25B080; //1970 based -> 1904 based
if (mov->chapter_track)
mov_create_chapter_track(s, mov->chapter_track);
@@ -2328,104 +2352,118 @@ static int mov_write_trailer(AVFormatContext *s)
}
#if CONFIG_MOV_MUXER
+MOV_CLASS(mov)
AVOutputFormat ff_mov_muxer = {
- "mov",
- NULL_IF_CONFIG_SMALL("MOV format"),
- NULL,
- "mov",
- sizeof(MOVMuxContext),
- CODEC_ID_AAC,
- CODEC_ID_MPEG4,
- mov_write_header,
- ff_mov_write_packet,
- mov_write_trailer,
+ .name = "mov",
+ .long_name = NULL_IF_CONFIG_SMALL("MOV format"),
+ .extensions = "mov",
+ .priv_data_size = sizeof(MOVMuxContext),
+ .audio_codec = CODEC_ID_AAC,
+#if CONFIG_LIBX264_ENCODER
+ .video_codec = CODEC_ID_H264,
+#else
+ .video_codec = CODEC_ID_MPEG4,
+#endif
+ .write_header = mov_write_header,
+ .write_packet = ff_mov_write_packet,
+ .write_trailer = mov_write_trailer,
.flags = AVFMT_GLOBALHEADER,
.codec_tag = (const AVCodecTag* const []){codec_movvideo_tags, codec_movaudio_tags, 0},
.priv_class = &mov_muxer_class,
};
#endif
#if CONFIG_TGP_MUXER
+MOV_CLASS(tgp)
AVOutputFormat ff_tgp_muxer = {
- "3gp",
- NULL_IF_CONFIG_SMALL("3GP format"),
- NULL,
- "3gp",
- sizeof(MOVMuxContext),
- CODEC_ID_AMR_NB,
- CODEC_ID_H263,
- mov_write_header,
- ff_mov_write_packet,
- mov_write_trailer,
+ .name = "3gp",
+ .long_name = NULL_IF_CONFIG_SMALL("3GP format"),
+ .extensions = "3gp",
+ .priv_data_size = sizeof(MOVMuxContext),
+ .audio_codec = CODEC_ID_AMR_NB,
+ .video_codec = CODEC_ID_H263,
+ .write_header = mov_write_header,
+ .write_packet = ff_mov_write_packet,
+ .write_trailer = mov_write_trailer,
.flags = AVFMT_GLOBALHEADER,
.codec_tag = (const AVCodecTag* const []){codec_3gp_tags, 0},
- .priv_class = &mov_muxer_class,
+ .priv_class = &tgp_muxer_class,
};
#endif
#if CONFIG_MP4_MUXER
+MOV_CLASS(mp4)
AVOutputFormat ff_mp4_muxer = {
- "mp4",
- NULL_IF_CONFIG_SMALL("MP4 format"),
- "application/mp4",
- "mp4",
- sizeof(MOVMuxContext),
- CODEC_ID_AAC,
- CODEC_ID_MPEG4,
- mov_write_header,
- ff_mov_write_packet,
- mov_write_trailer,
+ .name = "mp4",
+ .long_name = NULL_IF_CONFIG_SMALL("MP4 format"),
+ .mime_type = "application/mp4",
+ .extensions = "mp4",
+ .priv_data_size = sizeof(MOVMuxContext),
+ .audio_codec = CODEC_ID_AAC,
+#if CONFIG_LIBX264_ENCODER
+ .video_codec = CODEC_ID_H264,
+#else
+ .video_codec = CODEC_ID_MPEG4,
+#endif
+ .write_header = mov_write_header,
+ .write_packet = ff_mov_write_packet,
+ .write_trailer = mov_write_trailer,
.flags = AVFMT_GLOBALHEADER,
.codec_tag = (const AVCodecTag* const []){ff_mp4_obj_type, 0},
- .priv_class = &mov_muxer_class,
+ .priv_class = &mp4_muxer_class,
};
#endif
#if CONFIG_PSP_MUXER
+MOV_CLASS(psp)
AVOutputFormat ff_psp_muxer = {
- "psp",
- NULL_IF_CONFIG_SMALL("PSP MP4 format"),
- NULL,
- "mp4,psp",
- sizeof(MOVMuxContext),
- CODEC_ID_AAC,
- CODEC_ID_MPEG4,
- mov_write_header,
- ff_mov_write_packet,
- mov_write_trailer,
+ .name = "psp",
+ .long_name = NULL_IF_CONFIG_SMALL("PSP MP4 format"),
+ .extensions = "mp4,psp",
+ .priv_data_size = sizeof(MOVMuxContext),
+ .audio_codec = CODEC_ID_AAC,
+#if CONFIG_LIBX264_ENCODER
+ .video_codec = CODEC_ID_H264,
+#else
+ .video_codec = CODEC_ID_MPEG4,
+#endif
+ .write_header = mov_write_header,
+ .write_packet = ff_mov_write_packet,
+ .write_trailer = mov_write_trailer,
.flags = AVFMT_GLOBALHEADER,
.codec_tag = (const AVCodecTag* const []){ff_mp4_obj_type, 0},
- .priv_class = &mov_muxer_class,
+ .priv_class = &psp_muxer_class,
};
#endif
#if CONFIG_TG2_MUXER
+MOV_CLASS(tg2)
AVOutputFormat ff_tg2_muxer = {
- "3g2",
- NULL_IF_CONFIG_SMALL("3GP2 format"),
- NULL,
- "3g2",
- sizeof(MOVMuxContext),
- CODEC_ID_AMR_NB,
- CODEC_ID_H263,
- mov_write_header,
- ff_mov_write_packet,
- mov_write_trailer,
+ .name = "3g2",
+ .long_name = NULL_IF_CONFIG_SMALL("3GP2 format"),
+ .extensions = "3g2",
+ .priv_data_size = sizeof(MOVMuxContext),
+ .audio_codec = CODEC_ID_AMR_NB,
+ .video_codec = CODEC_ID_H263,
+ .write_header = mov_write_header,
+ .write_packet = ff_mov_write_packet,
+ .write_trailer = mov_write_trailer,
.flags = AVFMT_GLOBALHEADER,
.codec_tag = (const AVCodecTag* const []){codec_3gp_tags, 0},
- .priv_class = &mov_muxer_class,
+ .priv_class = &tg2_muxer_class,
};
#endif
#if CONFIG_IPOD_MUXER
+MOV_CLASS(ipod)
AVOutputFormat ff_ipod_muxer = {
- "ipod",
- NULL_IF_CONFIG_SMALL("iPod H.264 MP4 format"),
- "application/mp4",
- "m4v,m4a",
- sizeof(MOVMuxContext),
- CODEC_ID_AAC,
- CODEC_ID_H264,
- mov_write_header,
- ff_mov_write_packet,
- mov_write_trailer,
+ .name = "ipod",
+ .long_name = NULL_IF_CONFIG_SMALL("iPod H.264 MP4 format"),
+ .mime_type = "application/mp4",
+ .extensions = "m4v,m4a",
+ .priv_data_size = sizeof(MOVMuxContext),
+ .audio_codec = CODEC_ID_AAC,
+ .video_codec = CODEC_ID_H264,
+ .write_header = mov_write_header,
+ .write_packet = ff_mov_write_packet,
+ .write_trailer = mov_write_trailer,
.flags = AVFMT_GLOBALHEADER,
.codec_tag = (const AVCodecTag* const []){codec_ipod_tags, 0},
- .priv_class = &mov_muxer_class,
+ .priv_class = &ipod_muxer_class,
};
#endif
diff --git a/libavformat/movenc.h b/libavformat/movenc.h
index 39cdb39284..610683fa6a 100644
--- a/libavformat/movenc.h
+++ b/libavformat/movenc.h
@@ -4,20 +4,20 @@
* Copyright (c) 2004 Gildas Bazin <gbazin at videolan dot org>
* Copyright (c) 2009 Baptiste Coudurier <baptiste dot coudurier at gmail dot com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/movenchint.c b/libavformat/movenchint.c
index 615714627c..8e96355abc 100644
--- a/libavformat/movenchint.c
+++ b/libavformat/movenchint.c
@@ -2,20 +2,20 @@
* MOV, 3GP, MP4 muxer RTP hinting
* Copyright (c) 2010 Martin Storsjo
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -36,7 +36,7 @@ int ff_mov_init_hinting(AVFormatContext *s, int index, int src_index)
track->tag = MKTAG('r','t','p',' ');
track->src_track = src_index;
- track->enc = avcodec_alloc_context();
+ track->enc = avcodec_alloc_context3(NULL);
if (!track->enc)
goto fail;
track->enc->codec_type = AVMEDIA_TYPE_DATA;
diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c
index 70ced02218..3101bae99d 100644
--- a/libavformat/mp3dec.c
+++ b/libavformat/mp3dec.c
@@ -2,20 +2,20 @@
* MP3 demuxer
* Copyright (c) 2003 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -51,7 +51,7 @@ static int mp3_read_probe(AVProbeData *p)
for(frames = 0; buf2 < end; frames++) {
header = AV_RB32(buf2);
- fsize = ff_mpa_decode_header(&avctx, header, &sample_rate, &sample_rate, &sample_rate, &sample_rate);
+ fsize = avpriv_mpa_decode_header(&avctx, header, &sample_rate, &sample_rate, &sample_rate, &sample_rate);
if(fsize < 0)
break;
buf2 += fsize;
@@ -86,7 +86,7 @@ static int mp3_parse_vbr_tags(AVFormatContext *s, AVStream *st, int64_t base)
if(ff_mpa_check_header(v) < 0)
return -1;
- if (ff_mpegaudio_decode_header(&c, v) == 0)
+ if (avpriv_mpegaudio_decode_header(&c, v) == 0)
vbrtag_size = c.frame_size;
if(c.layer != 3)
return -1;
@@ -110,8 +110,8 @@ static int mp3_parse_vbr_tags(AVFormatContext *s, AVStream *st, int64_t base)
if(avio_rb16(s->pb) == 1) {
/* skip delay and quality */
avio_skip(s->pb, 4);
- frames = avio_rb32(s->pb);
size = avio_rb32(s->pb);
+ frames = avio_rb32(s->pb);
}
}
@@ -137,7 +137,7 @@ static int mp3_read_header(AVFormatContext *s,
AVStream *st;
int64_t off;
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
@@ -174,7 +174,9 @@ static int mp3_read_packet(AVFormatContext *s, AVPacket *pkt)
pkt->stream_index = 0;
if (ret <= 0) {
- return AVERROR(EIO);
+ if(ret<0)
+ return ret;
+ return AVERROR_EOF;
}
if (ret > ID3v1_TAG_SIZE &&
@@ -188,12 +190,11 @@ static int mp3_read_packet(AVFormatContext *s, AVPacket *pkt)
}
AVInputFormat ff_mp3_demuxer = {
- "mp3",
- NULL_IF_CONFIG_SMALL("MPEG audio layer 2/3"),
- 0,
- mp3_read_probe,
- mp3_read_header,
- mp3_read_packet,
+ .name = "mp3",
+ .long_name = NULL_IF_CONFIG_SMALL("MPEG audio layer 2/3"),
+ .read_probe = mp3_read_probe,
+ .read_header = mp3_read_header,
+ .read_packet = mp3_read_packet,
.flags= AVFMT_GENERIC_INDEX,
.extensions = "mp2,mp3,m2a", /* XXX: use probe */
};
diff --git a/libavformat/mp3enc.c b/libavformat/mp3enc.c
index 092d16ecc1..b847350232 100644
--- a/libavformat/mp3enc.c
+++ b/libavformat/mp3enc.c
@@ -2,31 +2,39 @@
* MP3 muxer
* Copyright (c) 2003 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <strings.h>
#include "avformat.h"
+#include "avio_internal.h"
#include "id3v1.h"
#include "id3v2.h"
#include "rawenc.h"
#include "libavutil/avstring.h"
+#include "libavcodec/mpegaudio.h"
+#include "libavcodec/mpegaudiodata.h"
+#include "libavcodec/mpegaudiodecheader.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/opt.h"
+#include "libavcodec/mpegaudio.h"
+#include "libavcodec/mpegaudiodata.h"
+#include "libavcodec/mpegaudiodecheader.h"
+#include "libavformat/avio_internal.h"
#include "libavutil/dict.h"
static int id3v1_set_string(AVFormatContext *s, const char *key,
@@ -128,42 +136,64 @@ static int id3v2_put_ttag(AVFormatContext *s, const char *str1, const char *str2
return len + ID3v2_HEADER_SIZE;
}
-static int mp3_write_trailer(struct AVFormatContext *s)
+#define VBR_NUM_BAGS 400
+#define VBR_TOC_SIZE 100
+typedef struct MP3Context {
+ const AVClass *class;
+ int id3v2_version;
+ int write_id3v1;
+ int64_t frames_offset;
+ int32_t frames;
+ int32_t size;
+ uint32_t want;
+ uint32_t seen;
+ uint32_t pos;
+ uint64_t bag[VBR_NUM_BAGS];
+} MP3Context;
+
+static int mp2_write_trailer(struct AVFormatContext *s)
{
uint8_t buf[ID3v1_TAG_SIZE];
+ MP3Context *mp3 = s->priv_data;
/* write the id3v1 tag */
- if (id3v1_create_tag(s, buf) > 0) {
+ if (mp3 && mp3->write_id3v1 && id3v1_create_tag(s, buf) > 0) {
avio_write(s->pb, buf, ID3v1_TAG_SIZE);
- avio_flush(s->pb);
}
+
+ /* write number of frames */
+ if (mp3 && mp3->frames_offset) {
+ avio_seek(s->pb, mp3->frames_offset, SEEK_SET);
+ avio_wb32(s->pb, s->streams[0]->nb_frames);
+ avio_seek(s->pb, 0, SEEK_END);
+ }
+
+ avio_flush(s->pb);
+
return 0;
}
#if CONFIG_MP2_MUXER
AVOutputFormat ff_mp2_muxer = {
- "mp2",
- NULL_IF_CONFIG_SMALL("MPEG audio layer 2"),
- "audio/x-mpeg",
- "mp2,m2a",
- 0,
- CODEC_ID_MP2,
- CODEC_ID_NONE,
- NULL,
- ff_raw_write_packet,
- mp3_write_trailer,
+ .name = "mp2",
+ .long_name = NULL_IF_CONFIG_SMALL("MPEG audio layer 2"),
+ .mime_type = "audio/x-mpeg",
+ .extensions = "mp2,m2a",
+ .audio_codec = CODEC_ID_MP2,
+ .video_codec = CODEC_ID_NONE,
+ .write_packet = ff_raw_write_packet,
+ .write_trailer = mp2_write_trailer,
+ .flags = AVFMT_NOTIMESTAMPS,
};
#endif
#if CONFIG_MP3_MUXER
-typedef struct MP3Context {
- const AVClass *class;
- int id3v2_version;
-} MP3Context;
static const AVOption options[] = {
{ "id3v2_version", "Select ID3v2 version to write. Currently 3 and 4 are supported.",
- offsetof(MP3Context, id3v2_version), FF_OPT_TYPE_INT, {.dbl = 4}, 3, 4, AV_OPT_FLAG_ENCODING_PARAM},
+ offsetof(MP3Context, id3v2_version), AV_OPT_TYPE_INT, {.dbl = 4}, 3, 4, AV_OPT_FLAG_ENCODING_PARAM},
+ { "write_id3v1", "Enable ID3v1 writing. ID3v1 tags are written in UTF-8 which may not be supported by most software.",
+ offsetof(MP3Context, write_id3v1), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM},
{ NULL },
};
@@ -189,6 +219,143 @@ static int id3v2_check_write_tag(AVFormatContext *s, AVDictionaryEntry *t, const
return -1;
}
+static const int64_t xing_offtbl[2][2] = {{32, 17}, {17,9}};
+
+/*
+ * Write an empty XING header and initialize respective data.
+ */
+static int mp3_write_xing(AVFormatContext *s)
+{
+ AVCodecContext *codec = s->streams[0]->codec;
+ MP3Context *mp3 = s->priv_data;
+ int bitrate_idx = 3;
+ int64_t xing_offset;
+ int32_t mask, header;
+ MPADecodeHeader c;
+ int srate_idx, i, channels;
+ int needed;
+
+ for (i = 0; i < FF_ARRAY_ELEMS(avpriv_mpa_freq_tab); i++)
+ if (avpriv_mpa_freq_tab[i] == codec->sample_rate) {
+ srate_idx = i;
+ break;
+ }
+ if (i == FF_ARRAY_ELEMS(avpriv_mpa_freq_tab)) {
+ av_log(s, AV_LOG_ERROR, "Unsupported sample rate.\n");
+ return -1;
+ }
+
+ switch (codec->channels) {
+ case 1: channels = MPA_MONO; break;
+ case 2: channels = MPA_STEREO; break;
+ default: av_log(s, AV_LOG_ERROR, "Unsupported number of channels.\n"); return -1;
+ }
+
+ /* dummy MPEG audio header */
+ header = 0xff << 24; // sync
+ header |= (0x7 << 5 | 0x3 << 3 | 0x1 << 1 | 0x1) << 16; // sync/mpeg-1/layer 3/no crc*/
+ header |= (srate_idx << 2) << 8;
+ header |= channels << 6;
+
+ for (;;) {
+ if (15 == bitrate_idx)
+ return -1;
+
+ mask = (bitrate_idx << 4) << 8;
+ header |= mask;
+ avpriv_mpegaudio_decode_header(&c, header);
+ xing_offset=xing_offtbl[c.lsf == 1][c.nb_channels == 1];
+ needed = 4 // header
+ + xing_offset
+ + 4 // xing tag
+ + 4 // frames/size/toc flags
+ + 4 // frames
+ + 4 // size
+ + VBR_TOC_SIZE; // toc
+
+ if (needed <= c.frame_size)
+ break;
+
+ header &= ~mask;
+ ++bitrate_idx;
+ }
+
+ avio_wb32(s->pb, header);
+ ffio_fill(s->pb, 0, xing_offset);
+ avio_wb32(s->pb, MKBETAG('X', 'i', 'n', 'g'));
+ avio_wb32(s->pb, 0x01 | 0x02 | 0x04); // frames/size/toc
+
+ mp3->frames_offset = avio_tell(s->pb);
+ mp3->size = c.frame_size;
+ mp3->want=1;
+ mp3->seen=0;
+ mp3->pos=0;
+
+ avio_wb32(s->pb, 0); // frames
+ avio_wb32(s->pb, 0); // size
+
+ // toc
+ for (i = 0; i < VBR_TOC_SIZE; ++i)
+ avio_w8(s->pb, (uint8_t)(255 * i / VBR_TOC_SIZE));
+
+ ffio_fill(s->pb, 0, c.frame_size - needed);
+ avio_flush(s->pb);
+
+ return 0;
+}
+
+/*
+ * Add a frame to XING data.
+ * Following lame's "VbrTag.c".
+ */
+static void mp3_xing_add_frame(AVFormatContext *s, AVPacket *pkt)
+{
+ MP3Context *mp3 = s->priv_data;
+ int i;
+
+ ++mp3->frames;
+ mp3->size += pkt->size;
+
+ if (mp3->want == ++mp3->seen) {
+ mp3->bag[mp3->pos] = mp3->size;
+
+ if (VBR_NUM_BAGS == ++mp3->pos) {
+ /* shrink table to half size by throwing away each second bag. */
+ for (i = 1; i < VBR_NUM_BAGS; i += 2)
+ mp3->bag[i >> 1] = mp3->bag[i];
+
+ /* double wanted amount per bag. */
+ mp3->want <<= 1;
+ /* adjust current position to half of table size. */
+ mp3->pos >>= 1;
+ }
+
+ mp3->seen = 0;
+ }
+}
+
+static void mp3_fix_xing(AVFormatContext *s)
+{
+ MP3Context *mp3 = s->priv_data;
+ int i;
+
+ avio_flush(s->pb);
+ avio_seek(s->pb, mp3->frames_offset, SEEK_SET);
+ avio_wb32(s->pb, mp3->frames);
+ avio_wb32(s->pb, mp3->size);
+
+ avio_w8(s->pb, 0); // first toc entry has to be zero.
+
+ for (i = 1; i < VBR_TOC_SIZE; ++i) {
+ int j = i * mp3->pos / VBR_TOC_SIZE;
+ int seek_point = 256LL * mp3->bag[j] / mp3->size;
+ avio_w8(s->pb, FFMIN(seek_point, 255));
+ }
+
+ avio_flush(s->pb);
+ avio_seek(s->pb, 0, SEEK_END);
+}
+
/**
* Write an ID3v2 header at beginning of stream
*/
@@ -237,21 +404,74 @@ static int mp3_write_header(struct AVFormatContext *s)
id3v2_put_size(s, totlen);
avio_seek(s->pb, cur_pos, SEEK_SET);
+ if (s->pb->seekable)
+ mp3_write_xing(s);
+
+ return 0;
+}
+
+static int mp3_write_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ if (! pkt || ! pkt->data || pkt->size < 4)
+ return ff_raw_write_packet(s, pkt);
+ else {
+ MP3Context *mp3 = s->priv_data;
+#ifdef FILTER_VBR_HEADERS
+ MPADecodeHeader c;
+ int base;
+
+ ff_mpegaudio_decode_header(&c, AV_RB32(pkt->data));
+
+ /* filter out XING and INFO headers. */
+ base = 4 + xing_offtbl[c.lsf == 1][c.nb_channels == 1];
+
+ if (base + 4 <= pkt->size) {
+ uint32_t v = AV_RB32(pkt->data + base);
+
+ if (MKBETAG('X','i','n','g') == v || MKBETAG('I','n','f','o') == v)
+ return 0;
+ }
+
+ /* filter out VBRI headers. */
+ base = 4 + 32;
+
+ if (base + 4 <= pkt->size && MKBETAG('V','B','R','I') == AV_RB32(pkt->data + base))
+ return 0;
+#endif
+
+ if (mp3->frames_offset)
+ mp3_xing_add_frame(s, pkt);
+
+ return ff_raw_write_packet(s, pkt);
+ }
+}
+
+static int mp3_write_trailer(AVFormatContext *s)
+{
+ MP3Context *mp3 = s->priv_data;
+ int ret=mp2_write_trailer(s);
+
+ if (ret < 0)
+ return ret;
+
+ if (mp3->frames_offset)
+ mp3_fix_xing(s);
+
return 0;
}
AVOutputFormat ff_mp3_muxer = {
- "mp3",
- NULL_IF_CONFIG_SMALL("MPEG audio layer 3"),
- "audio/x-mpeg",
- "mp3",
- sizeof(MP3Context),
- CODEC_ID_MP3,
- CODEC_ID_NONE,
- mp3_write_header,
- ff_raw_write_packet,
- mp3_write_trailer,
- AVFMT_NOTIMESTAMPS,
+ .name = "mp3",
+ .long_name = NULL_IF_CONFIG_SMALL("MPEG audio layer 3"),
+ .mime_type = "audio/x-mpeg",
+ .extensions = "mp3",
+ .priv_data_size = sizeof(MP3Context),
+ .audio_codec = CODEC_ID_MP3,
+ .video_codec = CODEC_ID_NONE,
+ .write_header = mp3_write_header,
+ .write_packet = mp3_write_packet,
+ .write_trailer = mp3_write_trailer,
+ .flags = AVFMT_NOTIMESTAMPS,
.priv_class = &mp3_muxer_class,
};
#endif
diff --git a/libavformat/mpc.c b/libavformat/mpc.c
index 0aec1e81d3..f377e1f990 100644
--- a/libavformat/mpc.c
+++ b/libavformat/mpc.c
@@ -2,20 +2,20 @@
* Musepack demuxer
* Copyright (c) 2006 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -70,13 +70,21 @@ static int mpc_read_header(AVFormatContext *s, AVFormatParameters *ap)
av_log(s, AV_LOG_ERROR, "Too many frames, seeking is not possible\n");
return -1;
}
- c->frames = av_malloc(c->fcount * sizeof(MPCFrame));
+ if(c->fcount){
+ c->frames = av_malloc(c->fcount * sizeof(MPCFrame));
+ if(!c->frames){
+ av_log(s, AV_LOG_ERROR, "Cannot allocate seektable\n");
+ return AVERROR(ENOMEM);
+ }
+ }else{
+ av_log(s, AV_LOG_WARNING, "Container reports no frames\n");
+ }
c->curframe = 0;
c->lastframe = -1;
c->curbits = 8;
c->frames_noted = 0;
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
@@ -111,7 +119,7 @@ static int mpc_read_packet(AVFormatContext *s, AVPacket *pkt)
int ret, size, size2, curbits, cur = c->curframe;
int64_t tmp, pos;
- if (c->curframe >= c->fcount)
+ if (c->curframe >= c->fcount && c->fcount)
return -1;
if(c->curframe != c->lastframe + 1){
@@ -133,7 +141,7 @@ static int mpc_read_packet(AVFormatContext *s, AVPacket *pkt)
avio_seek(s->pb, pos, SEEK_SET);
size = ((size2 + curbits + 31) & ~31) >> 3;
- if(cur == c->frames_noted){
+ if(cur == c->frames_noted && c->fcount){
c->frames[cur].pos = pos;
c->frames[cur].size = size;
c->frames[cur].skip = curbits - 20;
@@ -146,7 +154,7 @@ static int mpc_read_packet(AVFormatContext *s, AVPacket *pkt)
return AVERROR(EIO);
pkt->data[0] = curbits;
- pkt->data[1] = (c->curframe > c->fcount);
+ pkt->data[1] = (c->curframe > c->fcount) && c->fcount;
pkt->data[2] = 0;
pkt->data[3] = 0;
@@ -214,13 +222,13 @@ static int mpc_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp
AVInputFormat ff_mpc_demuxer = {
- "mpc",
- NULL_IF_CONFIG_SMALL("Musepack"),
- sizeof(MPCContext),
- mpc_probe,
- mpc_read_header,
- mpc_read_packet,
- mpc_read_close,
- mpc_read_seek,
+ .name = "mpc",
+ .long_name = NULL_IF_CONFIG_SMALL("Musepack"),
+ .priv_data_size = sizeof(MPCContext),
+ .read_probe = mpc_probe,
+ .read_header = mpc_read_header,
+ .read_packet = mpc_read_packet,
+ .read_close = mpc_read_close,
+ .read_seek = mpc_read_seek,
.extensions = "mpc",
};
diff --git a/libavformat/mpc8.c b/libavformat/mpc8.c
index c4810f6eaf..22e2adcb1c 100644
--- a/libavformat/mpc8.c
+++ b/libavformat/mpc8.c
@@ -2,20 +2,20 @@
* Musepack SV8 demuxer
* Copyright (c) 2007 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -201,7 +201,7 @@ static int mpc8_read_header(AVFormatContext *s, AVFormatParameters *ap)
return -1;
}
- while(!pb->eof_reached){
+ while(!url_feof(pb)){
pos = avio_tell(pb);
mpc8_get_chunk_header(pb, &tag, &size);
if(tag == TAG_STREAMHDR)
@@ -222,7 +222,7 @@ static int mpc8_read_header(AVFormatContext *s, AVFormatParameters *ap)
c->samples = ffio_read_varlen(pb);
ffio_read_varlen(pb); //silence samples at the beginning
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
@@ -248,7 +248,7 @@ static int mpc8_read_packet(AVFormatContext *s, AVPacket *pkt)
int tag;
int64_t pos, size;
- while(!s->pb->eof_reached){
+ while(!url_feof(s->pb)){
pos = avio_tell(s->pb);
mpc8_get_chunk_header(s->pb, &tag, &size);
if (size < 0)
@@ -264,7 +264,7 @@ static int mpc8_read_packet(AVFormatContext *s, AVPacket *pkt)
return AVERROR(EIO);
mpc8_handle_chunk(s, tag, pos, size);
}
- return 0;
+ return AVERROR_EOF;
}
static int mpc8_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
@@ -274,19 +274,19 @@ static int mpc8_read_seek(AVFormatContext *s, int stream_index, int64_t timestam
int index = av_index_search_timestamp(st, timestamp, flags);
if(index < 0) return -1;
- avio_seek(s->pb, st->index_entries[index].pos, SEEK_SET);
+ if (avio_seek(s->pb, st->index_entries[index].pos, SEEK_SET) < 0)
+ return -1;
c->frame = st->index_entries[index].timestamp;
return 0;
}
AVInputFormat ff_mpc8_demuxer = {
- "mpc8",
- NULL_IF_CONFIG_SMALL("Musepack SV8"),
- sizeof(MPCContext),
- mpc8_probe,
- mpc8_read_header,
- mpc8_read_packet,
- NULL,
- mpc8_read_seek,
+ .name = "mpc8",
+ .long_name = NULL_IF_CONFIG_SMALL("Musepack SV8"),
+ .priv_data_size = sizeof(MPCContext),
+ .read_probe = mpc8_probe,
+ .read_header = mpc8_read_header,
+ .read_packet = mpc8_read_packet,
+ .read_seek = mpc8_read_seek,
};
diff --git a/libavformat/mpeg.c b/libavformat/mpeg.c
index 496b9d45f5..5b72c93c2c 100644
--- a/libavformat/mpeg.c
+++ b/libavformat/mpeg.c
@@ -2,20 +2,20 @@
* MPEG1/2 demuxer
* Copyright (c) 2000, 2001, 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -49,6 +49,10 @@ static int check_pes(uint8_t *p, uint8_t *end){
return pes1||pes2;
}
+static int check_pack_header(const uint8_t *buf) {
+ return (buf[1] & 0xC0) == 0x40 || (buf[1] & 0xF0) == 0x20;
+}
+
static int mpegps_probe(AVProbeData *p)
{
uint32_t code= -1;
@@ -61,14 +65,16 @@ static int mpegps_probe(AVProbeData *p)
if ((code & 0xffffff00) == 0x100) {
int len= p->buf[i+1] << 8 | p->buf[i+2];
int pes= check_pes(p->buf+i, p->buf+p->buf_size);
+ int pack = check_pack_header(p->buf+i);
if(code == SYSTEM_HEADER_START_CODE) sys++;
- else if(code == PACK_START_CODE) pspack++;
+ else if(code == PACK_START_CODE && pack) pspack++;
else if((code & 0xf0) == VIDEO_ID && pes) vid++;
// skip pes payload to avoid start code emulation for private
// and audio streams
else if((code & 0xe0) == AUDIO_ID && pes) {audio++; i+=len;}
else if(code == PRIVATE_STREAM_1 && pes) {priv1++; i+=len;}
+ else if(code == 0x1fd && pes) vid++; //VC1
else if((code & 0xf0) == VIDEO_ID && !pes) invalid++;
else if((code & 0xe0) == AUDIO_ID && !pes) invalid++;
@@ -76,7 +82,7 @@ static int mpegps_probe(AVProbeData *p)
}
}
- if(vid+audio > invalid) /* invalid VDR files nd short PES streams */
+ if(vid+audio > invalid+1) /* invalid VDR files nd short PES streams */
score= AVPROBE_SCORE_MAX/4;
//av_log(NULL, AV_LOG_ERROR, "%d %d %d %d %d %d len:%d\n", sys, priv1, pspack,vid, audio, invalid, p->buf_size);
@@ -105,6 +111,7 @@ static int mpegps_read_header(AVFormatContext *s,
MpegDemuxContext *m = s->priv_data;
const char *sofdec = "Sofdec";
int v, i = 0;
+ int64_t last_pos = avio_tell(s->pb);
m->header_state = 0xff;
s->ctx_flags |= AVFMTCTX_NOHEADER;
@@ -112,12 +119,14 @@ static int mpegps_read_header(AVFormatContext *s,
m->sofdec = -1;
do {
v = avio_r8(s->pb);
- m->header_state = m->header_state << 8 | v;
m->sofdec++;
} while (v == sofdec[i] && i++ < 6);
m->sofdec = (m->sofdec == 6) ? 1 : 0;
+ if (!m->sofdec)
+ avio_seek(s->pb, last_pos, SEEK_SET);
+
/* no need to do more */
return 0;
}
@@ -141,7 +150,7 @@ static int find_next_start_code(AVIOContext *pb, int *size_ptr,
state = *header_state;
n = *size_ptr;
while (n > 0) {
- if (pb->eof_reached)
+ if (url_feof(pb))
break;
v = avio_r8(pb);
n--;
@@ -251,7 +260,7 @@ static int mpegps_read_pes_header(AVFormatContext *s,
last_sync = avio_tell(s->pb);
//printf("startcode=%x pos=0x%"PRIx64"\n", startcode, avio_tell(s->pb));
if (startcode < 0){
- if(s->pb->eof_reached)
+ if(url_feof(s->pb))
return AVERROR_EOF;
//FIXME we should remember header_state
return AVERROR(EAGAIN);
@@ -418,7 +427,8 @@ static int mpegps_read_packet(AVFormatContext *s,
{
MpegDemuxContext *m = s->priv_data;
AVStream *st;
- int len, startcode, i, es_type;
+ int len, startcode, i, es_type, ret;
+ int request_probe= 0;
enum CodecID codec_id = CODEC_ID_NONE;
enum AVMediaType type;
int64_t pts, dts, dummy_pos; //dummy_pos is needed for the index building to work
@@ -477,7 +487,7 @@ static int mpegps_read_packet(AVFormatContext *s,
if(!memcmp(buf, avs_seqh, 4) && (buf[6] != 0 || buf[7] != 1))
codec_id = CODEC_ID_CAVS;
else
- codec_id = CODEC_ID_PROBE;
+ request_probe= 1;
type = AVMEDIA_TYPE_VIDEO;
} else if (startcode >= 0x1c0 && startcode <= 0x1df) {
type = AVMEDIA_TYPE_AUDIO;
@@ -527,11 +537,13 @@ static int mpegps_read_packet(AVFormatContext *s,
goto redo;
}
/* no stream found: add a new stream */
- st = av_new_stream(s, startcode);
+ st = avformat_new_stream(s, NULL);
if (!st)
goto skip;
+ st->id = startcode;
st->codec->codec_type = type;
st->codec->codec_id = codec_id;
+ st->request_probe = request_probe;
if (codec_id != CODEC_ID_PCM_S16BE)
st->need_parsing = AVSTREAM_PARSE_FULL;
found:
@@ -561,8 +573,7 @@ static int mpegps_read_packet(AVFormatContext *s,
else if (st->codec->bits_per_coded_sample == 28)
return AVERROR(EINVAL);
}
- av_new_packet(pkt, len);
- avio_read(s->pb, pkt->data, pkt->size);
+ ret = av_get_packet(s->pb, pkt, len);
pkt->pts = pts;
pkt->dts = dts;
pkt->pos = dummy_pos;
@@ -571,7 +582,7 @@ static int mpegps_read_packet(AVFormatContext *s,
pkt->stream_index, pkt->pts / 90000.0, pkt->dts / 90000.0,
pkt->size);
- return 0;
+ return (ret < 0) ? ret : 0;
}
static int64_t mpegps_read_dts(AVFormatContext *s, int stream_index,
@@ -603,14 +614,13 @@ static int64_t mpegps_read_dts(AVFormatContext *s, int stream_index,
}
AVInputFormat ff_mpegps_demuxer = {
- "mpeg",
- NULL_IF_CONFIG_SMALL("MPEG-PS format"),
- sizeof(MpegDemuxContext),
- mpegps_probe,
- mpegps_read_header,
- mpegps_read_packet,
- NULL,
- NULL, //mpegps_read_seek,
- mpegps_read_dts,
+ .name = "mpeg",
+ .long_name = NULL_IF_CONFIG_SMALL("MPEG-PS format"),
+ .priv_data_size = sizeof(MpegDemuxContext),
+ .read_probe = mpegps_probe,
+ .read_header = mpegps_read_header,
+ .read_packet = mpegps_read_packet,
+ .read_seek = NULL, //mpegps_read_seek,
+ .read_timestamp = mpegps_read_dts,
.flags = AVFMT_SHOW_IDS|AVFMT_TS_DISCONT,
};
diff --git a/libavformat/mpeg.h b/libavformat/mpeg.h
index 75dddf346b..ca019c9eb2 100644
--- a/libavformat/mpeg.h
+++ b/libavformat/mpeg.h
@@ -2,20 +2,20 @@
* MPEG1/2 muxer and demuxer common defines
* Copyright (c) 2000, 2001, 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/mpegenc.c b/libavformat/mpegenc.c
index 5859254492..817f541805 100644
--- a/libavformat/mpegenc.c
+++ b/libavformat/mpegenc.c
@@ -2,25 +2,27 @@
* MPEG1/2 muxer
* Copyright (c) 2000, 2001, 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/fifo.h"
+#include "libavutil/log.h"
#include "libavutil/mathematics.h"
+#include "libavutil/opt.h"
#include "libavcodec/put_bits.h"
#include "avformat.h"
#include "mpeg.h"
@@ -56,6 +58,7 @@ typedef struct {
} StreamInfo;
typedef struct {
+ const AVClass *class;
int packet_size; /* required packet size */
int packet_number;
int pack_header_freq; /* frequency (in packets^-1) at which we send pack headers */
@@ -416,9 +419,12 @@ static int mpeg_mux_init(AVFormatContext *ctx)
video_bitrate += codec_rate;
}
+#if FF_API_MUXRATE
if(ctx->mux_rate){
s->mux_rate= (ctx->mux_rate + (8 * 50) - 1) / (8 * 50);
- } else {
+ } else
+#endif
+ if (!s->mux_rate) {
/* we increase slightly the bitrate to take into account the
headers. XXX: compute it exactly */
bitrate += bitrate*5/100;
@@ -920,7 +926,7 @@ static int flush_packet(AVFormatContext *ctx, int stream_index,
/* output data */
assert(payload_size - stuffing_size <= av_fifo_size(stream->fifo));
- av_fifo_generic_read(stream->fifo, ctx->pb, payload_size - stuffing_size, &avio_write);
+ av_fifo_generic_read(stream->fifo, ctx->pb, payload_size - stuffing_size, (void*)avio_write);
stream->bytes_to_iframe -= payload_size - stuffing_size;
}else{
payload_size=
@@ -1227,77 +1233,101 @@ static int mpeg_mux_end(AVFormatContext *ctx)
return 0;
}
+#define OFFSET(x) offsetof(MpegMuxContext, x)
+#define E AV_OPT_FLAG_ENCODING_PARAM
+static const AVOption options[] = {
+ { "muxrate", NULL, OFFSET(mux_rate), AV_OPT_TYPE_INT, {0}, 0, INT_MAX, E },
+ { NULL },
+};
+
+#define MPEGENC_CLASS(flavor)\
+static const AVClass flavor ## _class = {\
+ .class_name = #flavor " muxer",\
+ .item_name = av_default_item_name,\
+ .version = LIBAVUTIL_VERSION_INT,\
+ .option = options,\
+};
+
#if CONFIG_MPEG1SYSTEM_MUXER
+MPEGENC_CLASS(mpeg)
AVOutputFormat ff_mpeg1system_muxer = {
- "mpeg",
- NULL_IF_CONFIG_SMALL("MPEG-1 System format"),
- "video/mpeg",
- "mpg,mpeg",
- sizeof(MpegMuxContext),
- CODEC_ID_MP2,
- CODEC_ID_MPEG1VIDEO,
- mpeg_mux_init,
- mpeg_mux_write_packet,
- mpeg_mux_end,
+ .name = "mpeg",
+ .long_name = NULL_IF_CONFIG_SMALL("MPEG-1 System format"),
+ .mime_type = "video/mpeg",
+ .extensions = "mpg,mpeg",
+ .priv_data_size = sizeof(MpegMuxContext),
+ .audio_codec = CODEC_ID_MP2,
+ .video_codec = CODEC_ID_MPEG1VIDEO,
+ .write_header = mpeg_mux_init,
+ .write_packet = mpeg_mux_write_packet,
+ .write_trailer = mpeg_mux_end,
+ .priv_class = &mpeg_class,
};
#endif
#if CONFIG_MPEG1VCD_MUXER
+MPEGENC_CLASS(vcd)
AVOutputFormat ff_mpeg1vcd_muxer = {
- "vcd",
- NULL_IF_CONFIG_SMALL("MPEG-1 System format (VCD)"),
- "video/mpeg",
- NULL,
- sizeof(MpegMuxContext),
- CODEC_ID_MP2,
- CODEC_ID_MPEG1VIDEO,
- mpeg_mux_init,
- mpeg_mux_write_packet,
- mpeg_mux_end,
+ .name = "vcd",
+ .long_name = NULL_IF_CONFIG_SMALL("MPEG-1 System format (VCD)"),
+ .mime_type = "video/mpeg",
+ .priv_data_size = sizeof(MpegMuxContext),
+ .audio_codec = CODEC_ID_MP2,
+ .video_codec = CODEC_ID_MPEG1VIDEO,
+ .write_header = mpeg_mux_init,
+ .write_packet = mpeg_mux_write_packet,
+ .write_trailer = mpeg_mux_end,
+ .priv_class = &vcd_class,
};
#endif
#if CONFIG_MPEG2VOB_MUXER
+MPEGENC_CLASS(vob)
AVOutputFormat ff_mpeg2vob_muxer = {
- "vob",
- NULL_IF_CONFIG_SMALL("MPEG-2 PS format (VOB)"),
- "video/mpeg",
- "vob",
- sizeof(MpegMuxContext),
- CODEC_ID_MP2,
- CODEC_ID_MPEG2VIDEO,
- mpeg_mux_init,
- mpeg_mux_write_packet,
- mpeg_mux_end,
+ .name = "vob",
+ .long_name = NULL_IF_CONFIG_SMALL("MPEG-2 PS format (VOB)"),
+ .mime_type = "video/mpeg",
+ .extensions = "vob",
+ .priv_data_size = sizeof(MpegMuxContext),
+ .audio_codec = CODEC_ID_MP2,
+ .video_codec = CODEC_ID_MPEG2VIDEO,
+ .write_header = mpeg_mux_init,
+ .write_packet = mpeg_mux_write_packet,
+ .write_trailer = mpeg_mux_end,
+ .priv_class = &vob_class,
};
#endif
/* Same as mpeg2vob_mux except that the pack size is 2324 */
#if CONFIG_MPEG2SVCD_MUXER
+MPEGENC_CLASS(svcd)
AVOutputFormat ff_mpeg2svcd_muxer = {
- "svcd",
- NULL_IF_CONFIG_SMALL("MPEG-2 PS format (VOB)"),
- "video/mpeg",
- "vob",
- sizeof(MpegMuxContext),
- CODEC_ID_MP2,
- CODEC_ID_MPEG2VIDEO,
- mpeg_mux_init,
- mpeg_mux_write_packet,
- mpeg_mux_end,
+ .name = "svcd",
+ .long_name = NULL_IF_CONFIG_SMALL("MPEG-2 PS format (VOB)"),
+ .mime_type = "video/mpeg",
+ .extensions = "vob",
+ .priv_data_size = sizeof(MpegMuxContext),
+ .audio_codec = CODEC_ID_MP2,
+ .video_codec = CODEC_ID_MPEG2VIDEO,
+ .write_header = mpeg_mux_init,
+ .write_packet = mpeg_mux_write_packet,
+ .write_trailer = mpeg_mux_end,
+ .priv_class = &svcd_class,
};
#endif
/* Same as mpeg2vob_mux except the 'is_dvd' flag is set to produce NAV pkts */
#if CONFIG_MPEG2DVD_MUXER
+MPEGENC_CLASS(dvd)
AVOutputFormat ff_mpeg2dvd_muxer = {
- "dvd",
- NULL_IF_CONFIG_SMALL("MPEG-2 PS format (DVD VOB)"),
- "video/mpeg",
- "dvd",
- sizeof(MpegMuxContext),
- CODEC_ID_MP2,
- CODEC_ID_MPEG2VIDEO,
- mpeg_mux_init,
- mpeg_mux_write_packet,
- mpeg_mux_end,
+ .name = "dvd",
+ .long_name = NULL_IF_CONFIG_SMALL("MPEG-2 PS format (DVD VOB)"),
+ .mime_type = "video/mpeg",
+ .extensions = "dvd",
+ .priv_data_size = sizeof(MpegMuxContext),
+ .audio_codec = CODEC_ID_MP2,
+ .video_codec = CODEC_ID_MPEG2VIDEO,
+ .write_header = mpeg_mux_init,
+ .write_packet = mpeg_mux_write_packet,
+ .write_trailer = mpeg_mux_end,
+ .priv_class = &dvd_class,
};
#endif
diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index f2ae567789..5000134a25 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -2,20 +2,20 @@
* MPEG2 transport stream (aka DVB) demuxer
* Copyright (c) 2002-2003 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -25,7 +25,9 @@
#include "libavutil/intreadwrite.h"
#include "libavutil/log.h"
#include "libavutil/dict.h"
+#include "libavutil/mathematics.h"
#include "libavutil/opt.h"
+#include "libavutil/avassert.h"
#include "libavcodec/bytestream.h"
#include "avformat.h"
#include "mpegts.h"
@@ -125,7 +127,7 @@ struct MpegTSContext {
};
static const AVOption options[] = {
- {"compute_pcr", "Compute exact PCR for each transport stream packet.", offsetof(MpegTSContext, mpeg2ts_compute_pcr), FF_OPT_TYPE_INT,
+ {"compute_pcr", "Compute exact PCR for each transport stream packet.", offsetof(MpegTSContext, mpeg2ts_compute_pcr), AV_OPT_TYPE_INT,
{.dbl = 0}, 0, 1, AV_OPT_FLAG_DECODING_PARAM },
{ NULL },
};
@@ -163,6 +165,7 @@ typedef struct PESContext {
enum MpegTSState state;
/* used to get the format */
int data_index;
+ int flags; /**< copied to the AVPacket flags */
int total_size;
int pes_header_size;
int extended_stream_id;
@@ -220,6 +223,17 @@ static void add_pid_to_pmt(MpegTSContext *ts, unsigned int programid, unsigned i
p->pids[p->nb_pids++] = pid;
}
+static void set_pcr_pid(AVFormatContext *s, unsigned int programid, unsigned int pid)
+{
+ int i;
+ for(i=0; i<s->nb_programs; i++) {
+ if(s->programs[i]->id == programid) {
+ s->programs[i]->pcr_pid = pid;
+ break;
+ }
+ }
+}
+
/**
* @brief discard_pid() decides if the pid is to be discarded according
* to caller's programs selection
@@ -512,7 +526,9 @@ static const StreamType ISO_types[] = {
{ 0x04, AVMEDIA_TYPE_AUDIO, CODEC_ID_MP3 },
{ 0x0f, AVMEDIA_TYPE_AUDIO, CODEC_ID_AAC },
{ 0x10, AVMEDIA_TYPE_VIDEO, CODEC_ID_MPEG4 },
- { 0x11, AVMEDIA_TYPE_AUDIO, CODEC_ID_AAC_LATM }, /* LATM syntax */
+ /* Makito encoder sets stream type 0x11 for AAC,
+ * so auto-detect LOAS/LATM instead of hardcoding it. */
+// { 0x11, AVMEDIA_TYPE_AUDIO, CODEC_ID_AAC_LATM }, /* LATM syntax */
{ 0x1b, AVMEDIA_TYPE_VIDEO, CODEC_ID_H264 },
{ 0xd1, AVMEDIA_TYPE_VIDEO, CODEC_ID_DIRAC },
{ 0xea, AVMEDIA_TYPE_VIDEO, CODEC_ID_VC1 },
@@ -525,6 +541,8 @@ static const StreamType HDMV_types[] = {
{ 0x82, AVMEDIA_TYPE_AUDIO, CODEC_ID_DTS },
{ 0x83, AVMEDIA_TYPE_AUDIO, CODEC_ID_TRUEHD },
{ 0x84, AVMEDIA_TYPE_AUDIO, CODEC_ID_EAC3 },
+ { 0x85, AVMEDIA_TYPE_AUDIO, CODEC_ID_DTS }, /* DTS HD */
+ { 0x86, AVMEDIA_TYPE_AUDIO, CODEC_ID_DTS }, /* DTS HD MASTER*/
{ 0x90, AVMEDIA_TYPE_SUBTITLE, CODEC_ID_HDMV_PGS_SUBTITLE },
{ 0 },
};
@@ -540,6 +558,10 @@ static const StreamType REGD_types[] = {
{ MKTAG('d','r','a','c'), AVMEDIA_TYPE_VIDEO, CODEC_ID_DIRAC },
{ MKTAG('A','C','-','3'), AVMEDIA_TYPE_AUDIO, CODEC_ID_AC3 },
{ MKTAG('B','S','S','D'), AVMEDIA_TYPE_AUDIO, CODEC_ID_S302M },
+ { MKTAG('D','T','S','1'), AVMEDIA_TYPE_AUDIO, CODEC_ID_DTS },
+ { MKTAG('D','T','S','2'), AVMEDIA_TYPE_AUDIO, CODEC_ID_DTS },
+ { MKTAG('D','T','S','3'), AVMEDIA_TYPE_AUDIO, CODEC_ID_DTS },
+ { MKTAG('V','C','-','1'), AVMEDIA_TYPE_VIDEO, CODEC_ID_VC1 },
{ 0 },
};
@@ -560,6 +582,7 @@ static void mpegts_find_stream_type(AVStream *st,
if (stream_type == types->stream_type) {
st->codec->codec_type = types->codec_type;
st->codec->codec_id = types->codec_id;
+ st->request_probe = 0;
return;
}
}
@@ -568,6 +591,8 @@ static void mpegts_find_stream_type(AVStream *st,
static int mpegts_set_stream_info(AVStream *st, PESContext *pes,
uint32_t stream_type, uint32_t prog_reg_desc)
{
+ int old_codec_type= st->codec->codec_type;
+ int old_codec_id = st->codec->codec_id;
av_set_pts_info(st, 33, 1, 90000);
st->priv_data = pes;
st->codec->codec_type = AVMEDIA_TYPE_DATA;
@@ -596,12 +621,13 @@ static int mpegts_set_stream_info(AVStream *st, PESContext *pes,
return AVERROR(ENOMEM);
memcpy(sub_pes, pes, sizeof(*sub_pes));
- sub_st = av_new_stream(pes->stream, pes->pid);
+ sub_st = avformat_new_stream(pes->stream, NULL);
if (!sub_st) {
av_free(sub_pes);
return AVERROR(ENOMEM);
}
+ sub_st->id = pes->pid;
av_set_pts_info(sub_st, 33, 1, 90000);
sub_st->priv_data = sub_pes;
sub_st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
@@ -612,6 +638,10 @@ static int mpegts_set_stream_info(AVStream *st, PESContext *pes,
}
if (st->codec->codec_id == CODEC_ID_NONE)
mpegts_find_stream_type(st, pes->stream_type, MISC_types);
+ if (st->codec->codec_id == CODEC_ID_NONE){
+ st->codec->codec_id = old_codec_id;
+ st->codec->codec_type= old_codec_type;
+ }
return 0;
}
@@ -623,6 +653,12 @@ static void new_pes_packet(PESContext *pes, AVPacket *pkt)
pkt->destruct = av_destruct_packet;
pkt->data = pes->buffer;
pkt->size = pes->data_index;
+
+ if(pes->total_size != MAX_PES_PAYLOAD &&
+ pes->pes_header_size + pes->data_index != pes->total_size + 6) {
+ av_log(pes->stream, AV_LOG_WARNING, "PES packet size mismatch\n");
+ pes->flags |= AV_PKT_FLAG_CORRUPT;
+ }
memset(pkt->data+pkt->size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
// Separate out the AC3 substream from an HDMV combined TrueHD/AC3 PID
@@ -634,12 +670,14 @@ static void new_pes_packet(PESContext *pes, AVPacket *pkt)
pkt->dts = pes->dts;
/* store position of first TS packet of this PES packet */
pkt->pos = pes->ts_packet_pos;
+ pkt->flags = pes->flags;
/* reset pts values */
pes->pts = AV_NOPTS_VALUE;
pes->dts = AV_NOPTS_VALUE;
pes->buffer = NULL;
pes->data_index = 0;
+ pes->flags = 0;
}
/* return non zero if a packet could be constructed */
@@ -690,9 +728,10 @@ static int mpegts_push_data(MpegTSFilter *filter,
/* stream not present in PMT */
if (!pes->st) {
- pes->st = av_new_stream(ts->stream, pes->pid);
+ pes->st = avformat_new_stream(ts->stream, NULL);
if (!pes->st)
return AVERROR(ENOMEM);
+ pes->st->id = pes->pid;
mpegts_set_stream_info(pes->st, pes, 0, 0);
}
@@ -712,10 +751,10 @@ static int mpegts_push_data(MpegTSFilter *filter,
code != 0x1ff && code != 0x1f2 && /* program_stream_directory, DSMCC_stream */
code != 0x1f8) { /* ITU-T Rec. H.222.1 type E stream */
pes->state = MPEGTS_PESHEADER;
- if (pes->st->codec->codec_id == CODEC_ID_NONE) {
+ if (pes->st->codec->codec_id == CODEC_ID_NONE && !pes->st->request_probe) {
av_dlog(pes->stream, "pid=%x stream_type=%x probing\n",
pes->pid, pes->stream_type);
- pes->st->codec->codec_id = CODEC_ID_PROBE;
+ pes->st->request_probe= 1;
}
} else {
pes->state = MPEGTS_PAYLOAD;
@@ -876,9 +915,8 @@ static int mp4_read_iods(AVFormatContext *s, const uint8_t *buf, unsigned size,
avio_r8(&pb);
len = ff_mp4_read_descr(s, &pb, &tag);
if (tag == MP4ESDescrTag) {
- *es_id = avio_rb16(&pb); /* ES_ID */
+ ff_mp4_parse_es_descr(&pb, es_id);
av_dlog(s, "ES_ID %#x\n", *es_id);
- avio_r8(&pb); /* priority */
len = ff_mp4_read_descr(s, &pb, &tag);
if (tag == MP4DecConfigDescrTag) {
*dec_config_descr = av_malloc(len);
@@ -992,6 +1030,9 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type
stream_type == STREAM_TYPE_PRIVATE_DATA)
mpegts_find_stream_type(st, st->codec->codec_tag, REGD_types);
break;
+ case 0x52: /* stream identifier descriptor */
+ st->stream_identifier = 1 + get8(pp, desc_end);
+ break;
default:
break;
}
@@ -1032,6 +1073,7 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len
if (pcr_pid < 0)
return;
add_pid_to_pmt(ts, h->id, pcr_pid);
+ set_pcr_pid(ts->stream, h->id, pcr_pid);
av_dlog(ts->stream, "pcr_pid=0x%x\n", pcr_pid);
@@ -1067,7 +1109,7 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len
// stop parsing after pmt, we found header
if (!ts->stream->nb_streams)
- ts->stop_parse = 1;
+ ts->stop_parse = 2;
for(;;) {
st = 0;
@@ -1081,14 +1123,18 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len
/* now create ffmpeg stream */
if (ts->pids[pid] && ts->pids[pid]->type == MPEGTS_PES) {
pes = ts->pids[pid]->u.pes_filter.opaque;
- if (!pes->st)
- pes->st = av_new_stream(pes->stream, pes->pid);
+ if (!pes->st) {
+ pes->st = avformat_new_stream(pes->stream, NULL);
+ st->id = pes->pid;
+ }
st = pes->st;
} else {
if (ts->pids[pid]) mpegts_close_filter(ts, ts->pids[pid]); //wrongly added sdt filter probably
pes = add_pes_stream(ts, pid, pcr_pid);
- if (pes)
- st = av_new_stream(pes->stream, pes->pid);
+ if (pes) {
+ st = avformat_new_stream(pes->stream, NULL);
+ st->id = pes->pid;
+ }
}
if (!st)
@@ -1130,6 +1176,7 @@ static void pat_cb(MpegTSFilter *filter, const uint8_t *section, int section_len
SectionHeader h1, *h = &h1;
const uint8_t *p, *p_end;
int sid, pmt_pid;
+ AVProgram *program;
av_dlog(ts->stream, "PAT:\n");
hex_dump_debug(ts->stream, (uint8_t *)section, section_len);
@@ -1141,6 +1188,8 @@ static void pat_cb(MpegTSFilter *filter, const uint8_t *section, int section_len
if (h->tid != PAT_TID)
return;
+ ts->stream->ts_id = h->id;
+
clear_programs(ts);
for(;;) {
sid = get16(&p, p_end);
@@ -1155,7 +1204,9 @@ static void pat_cb(MpegTSFilter *filter, const uint8_t *section, int section_len
if (sid == 0x0000) {
/* NIT info */
} else {
- av_new_program(ts->stream, sid);
+ program = av_new_program(ts->stream, sid);
+ program->program_num = sid;
+ program->pmt_pid = pmt_pid;
if (ts->pids[pmt_pid])
mpegts_close_filter(ts, ts->pids[pmt_pid]);
mpegts_open_section_filter(ts, pmt_pid, pmt_cb, ts, 1);
@@ -1247,7 +1298,8 @@ static int handle_packet(MpegTSContext *ts, const uint8_t *packet)
{
AVFormatContext *s = ts->stream;
MpegTSFilter *tss;
- int len, pid, cc, cc_ok, afc, is_start;
+ int len, pid, cc, expected_cc, cc_ok, afc, is_start, is_discontinuity,
+ has_adaptation, has_payload;
const uint8_t *p, *p_end;
int64_t pos;
@@ -1263,19 +1315,38 @@ static int handle_packet(MpegTSContext *ts, const uint8_t *packet)
if (!tss)
return 0;
+ afc = (packet[3] >> 4) & 3;
+ if (afc == 0) /* reserved value */
+ return 0;
+ has_adaptation = afc & 2;
+ has_payload = afc & 1;
+ is_discontinuity = has_adaptation
+ && packet[4] != 0 /* with length > 0 */
+ && (packet[5] & 0x80); /* and discontinuity indicated */
+
/* continuity check (currently not used) */
cc = (packet[3] & 0xf);
- cc_ok = (tss->last_cc < 0) || ((((tss->last_cc + 1) & 0x0f) == cc));
+ expected_cc = has_payload ? (tss->last_cc + 1) & 0x0f : tss->last_cc;
+ cc_ok = pid == 0x1FFF // null packet PID
+ || is_discontinuity
+ || tss->last_cc < 0
+ || expected_cc == cc;
+
tss->last_cc = cc;
+ if (!cc_ok) {
+ av_log(ts->stream, AV_LOG_DEBUG,
+ "Continuity check failed for pid %d expected %d got %d\n",
+ pid, expected_cc, cc);
+ if(tss->type == MPEGTS_PES) {
+ PESContext *pc = tss->u.pes_filter.opaque;
+ pc->flags |= AV_PKT_FLAG_CORRUPT;
+ }
+ }
- /* skip adaptation field */
- afc = (packet[3] >> 4) & 3;
- p = packet + 4;
- if (afc == 0) /* reserved value */
- return 0;
- if (afc == 2) /* adaptation field only */
+ if (!has_payload)
return 0;
- if (afc == 3) {
+ p = packet + 4;
+ if (has_adaptation) {
/* skip adapation field */
p += p[0] + 1;
}
@@ -1332,7 +1403,7 @@ static int mpegts_resync(AVFormatContext *s)
for(i = 0;i < MAX_RESYNC_SIZE; i++) {
c = avio_r8(pb);
- if (pb->eof_reached)
+ if (url_feof(pb))
return -1;
if (c == 0x47) {
avio_seek(pb, -1, SEEK_CUR);
@@ -1376,24 +1447,46 @@ static int handle_packets(MpegTSContext *ts, int nb_packets)
{
AVFormatContext *s = ts->stream;
uint8_t packet[TS_PACKET_SIZE];
- int packet_num, ret;
+ int packet_num, ret = 0;
+
+ if (avio_tell(s->pb) != ts->last_pos) {
+ int i;
+ av_dlog(ts->stream, "Skipping after seek\n");
+ /* seek detected, flush pes buffer */
+ for (i = 0; i < NB_PID_MAX; i++) {
+ if (ts->pids[i]) {
+ if (ts->pids[i]->type == MPEGTS_PES) {
+ PESContext *pes = ts->pids[i]->u.pes_filter.opaque;
+ av_freep(&pes->buffer);
+ pes->data_index = 0;
+ pes->state = MPEGTS_SKIP; /* skip until pes header */
+ }
+ ts->pids[i]->last_cc = -1;
+ }
+ }
+ }
ts->stop_parse = 0;
packet_num = 0;
for(;;) {
- if (ts->stop_parse>0)
- break;
packet_num++;
- if (nb_packets != 0 && packet_num >= nb_packets)
+ if (nb_packets != 0 && packet_num >= nb_packets ||
+ ts->stop_parse > 1) {
+ ret = AVERROR(EAGAIN);
break;
+ }
+ if (ts->stop_parse > 0)
+ break;
+
ret = read_packet(s, packet, ts->raw_packet_size);
if (ret != 0)
- return ret;
+ break;
ret = handle_packet(ts, packet);
if (ret != 0)
- return ret;
+ break;
}
- return 0;
+ ts->last_pos = avio_tell(s->pb);
+ return ret;
}
static int mpegts_probe(AVProbeData *p)
@@ -1460,29 +1553,20 @@ static int mpegts_read_header(AVFormatContext *s,
{
MpegTSContext *ts = s->priv_data;
AVIOContext *pb = s->pb;
- uint8_t buf[5*1024];
+ uint8_t buf[8*1024];
int len;
int64_t pos;
-#if FF_API_FORMAT_PARAMETERS
- if (ap) {
- if (ap->mpeg2ts_compute_pcr)
- ts->mpeg2ts_compute_pcr = ap->mpeg2ts_compute_pcr;
- if(ap->mpeg2ts_raw){
- av_log(s, AV_LOG_ERROR, "use mpegtsraw_demuxer!\n");
- return -1;
- }
- }
-#endif
-
- /* read the first 1024 bytes to get packet size */
+ /* read the first 8192 bytes to get packet size */
pos = avio_tell(pb);
len = avio_read(pb, buf, sizeof(buf));
if (len != sizeof(buf))
goto fail;
ts->raw_packet_size = get_packet_size(buf, sizeof(buf));
- if (ts->raw_packet_size <= 0)
- goto fail;
+ if (ts->raw_packet_size <= 0) {
+ av_log(s, AV_LOG_WARNING, "Could not detect TS packet size, defaulting to non-FEC/DVHS\n");
+ ts->raw_packet_size = TS_PACKET_SIZE;
+ }
ts->stream = s;
ts->auto_guess = 0;
@@ -1490,8 +1574,11 @@ static int mpegts_read_header(AVFormatContext *s,
/* normal demux */
/* first do a scaning to get all the services */
+ /* NOTE: We attempt to seek on non-seekable files as well, as the
+ * probe buffer usually is big enough. Only warn if the seek failed
+ * on files where the seek should work. */
if (avio_seek(pb, pos, SEEK_SET) < 0)
- av_log(s, AV_LOG_ERROR, "Unable to seek back to the start\n");
+ av_log(s, pb->seekable ? AV_LOG_ERROR : AV_LOG_INFO, "Unable to seek back to the start\n");
mpegts_open_section_filter(ts, SDT_PID, sdt_cb, ts, 1);
@@ -1514,7 +1601,7 @@ static int mpegts_read_header(AVFormatContext *s,
/* only read packets */
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
goto fail;
av_set_pts_info(st, 60, 1, 27000000);
@@ -1611,18 +1698,6 @@ static int mpegts_read_packet(AVFormatContext *s,
MpegTSContext *ts = s->priv_data;
int ret, i;
- if (avio_tell(s->pb) != ts->last_pos) {
- /* seek detected, flush pes buffer */
- for (i = 0; i < NB_PID_MAX; i++) {
- if (ts->pids[i] && ts->pids[i]->type == MPEGTS_PES) {
- PESContext *pes = ts->pids[i]->u.pes_filter.opaque;
- av_freep(&pes->buffer);
- pes->data_index = 0;
- pes->state = MPEGTS_SKIP; /* skip until pes header */
- }
- }
- }
-
ts->pkt = pkt;
ret = handle_packets(ts, 0);
if (ret < 0) {
@@ -1640,8 +1715,6 @@ static int mpegts_read_packet(AVFormatContext *s,
}
}
- ts->last_pos = avio_tell(s->pb);
-
return ret;
}
@@ -1665,36 +1738,58 @@ static int64_t mpegts_get_pcr(AVFormatContext *s, int stream_index,
int64_t pos, timestamp;
uint8_t buf[TS_PACKET_SIZE];
int pcr_l, pcr_pid = ((PESContext*)s->streams[stream_index]->priv_data)->pcr_pid;
- const int find_next= 1;
pos = ((*ppos + ts->raw_packet_size - 1 - ts->pos47) / ts->raw_packet_size) * ts->raw_packet_size + ts->pos47;
- if (find_next) {
- for(;;) {
- avio_seek(s->pb, pos, SEEK_SET);
- if (avio_read(s->pb, buf, TS_PACKET_SIZE) != TS_PACKET_SIZE)
+ while(pos < pos_limit) {
+ if (avio_seek(s->pb, pos, SEEK_SET) < 0)
+ return AV_NOPTS_VALUE;
+ if (avio_read(s->pb, buf, TS_PACKET_SIZE) != TS_PACKET_SIZE)
+ return AV_NOPTS_VALUE;
+ if (buf[0] != 0x47) {
+ if (mpegts_resync(s) < 0)
return AV_NOPTS_VALUE;
- if ((pcr_pid < 0 || (AV_RB16(buf + 1) & 0x1fff) == pcr_pid) &&
- parse_pcr(&timestamp, &pcr_l, buf) == 0) {
- break;
- }
- pos += ts->raw_packet_size;
+ pos = url_ftell(s->pb);
+ continue;
}
- } else {
- for(;;) {
- pos -= ts->raw_packet_size;
- if (pos < 0)
- return AV_NOPTS_VALUE;
- avio_seek(s->pb, pos, SEEK_SET);
- if (avio_read(s->pb, buf, TS_PACKET_SIZE) != TS_PACKET_SIZE)
- return AV_NOPTS_VALUE;
- if ((pcr_pid < 0 || (AV_RB16(buf + 1) & 0x1fff) == pcr_pid) &&
- parse_pcr(&timestamp, &pcr_l, buf) == 0) {
- break;
+ if ((pcr_pid < 0 || (AV_RB16(buf + 1) & 0x1fff) == pcr_pid) &&
+ parse_pcr(&timestamp, &pcr_l, buf) == 0) {
+ *ppos = pos;
+ return timestamp;
+ }
+ pos += ts->raw_packet_size;
+ }
+
+ return AV_NOPTS_VALUE;
+}
+
+static int64_t mpegts_get_dts(AVFormatContext *s, int stream_index,
+ int64_t *ppos, int64_t pos_limit)
+{
+ MpegTSContext *ts = s->priv_data;
+ int64_t pos, timestamp;
+ pos = ((*ppos + ts->raw_packet_size - 1 - ts->pos47) / ts->raw_packet_size) * ts->raw_packet_size + ts->pos47;
+ ff_read_frame_flush(s);
+ if (avio_seek(s->pb, pos, SEEK_SET) < 0)
+ return AV_NOPTS_VALUE;
+ while(pos < pos_limit) {
+ int ret;
+ AVPacket pkt;
+ av_init_packet(&pkt);
+ ret= av_read_frame(s, &pkt);
+ if(ret < 0)
+ return AV_NOPTS_VALUE;
+ av_free_packet(&pkt);
+ if(pkt.dts != AV_NOPTS_VALUE && pkt.pos >= 0){
+ ff_reduce_index(s, pkt.stream_index);
+ av_add_index_entry(s->streams[pkt.stream_index], pkt.pos, pkt.dts, 0, 0, AVINDEX_KEYFRAME /* FIXME keyframe? */);
+ if(pkt.stream_index == stream_index){
+ *ppos= pkt.pos;
+ return pkt.dts;
}
}
+ pos = pkt.pos;
}
- *ppos = pos;
- return timestamp;
+ return AV_NOPTS_VALUE;
}
#ifdef USE_SYNCPOINT_SEARCH
@@ -1781,31 +1876,6 @@ static int read_seek(AVFormatContext *s, int stream_index, int64_t target_ts, in
return ret;
}
-#else
-
-static int read_seek(AVFormatContext *s, int stream_index, int64_t target_ts, int flags){
- MpegTSContext *ts = s->priv_data;
- uint8_t buf[TS_PACKET_SIZE];
- int64_t pos;
-
- if(av_seek_frame_binary(s, stream_index, target_ts, flags) < 0)
- return -1;
-
- pos= avio_tell(s->pb);
-
- for(;;) {
- avio_seek(s->pb, pos, SEEK_SET);
- if (avio_read(s->pb, buf, TS_PACKET_SIZE) != TS_PACKET_SIZE)
- return -1;
-// pid = AV_RB16(buf + 1) & 0x1fff;
- if(buf[1] & 0x40) break;
- pos += ts->raw_packet_size;
- }
- avio_seek(s->pb, pos, SEEK_SET);
-
- return 0;
-}
-
#endif
/**************************************************************/
@@ -1822,6 +1892,9 @@ MpegTSContext *ff_mpegts_parse_open(AVFormatContext *s)
ts->raw_packet_size = TS_PACKET_SIZE;
ts->stream = s;
ts->auto_guess = 1;
+ mpegts_open_section_filter(ts, SDT_PID, sdt_cb, ts, 1);
+ mpegts_open_section_filter(ts, PAT_PID, pat_cb, ts, 1);
+
return ts;
}
@@ -1834,10 +1907,8 @@ int ff_mpegts_parse_packet(MpegTSContext *ts, AVPacket *pkt,
len1 = len;
ts->pkt = pkt;
- ts->stop_parse = 0;
for(;;) {
- if (ts->stop_parse>0)
- break;
+ ts->stop_parse = 0;
if (len < TS_PACKET_SIZE)
return -1;
if (buf[0] != 0x47) {
@@ -1847,6 +1918,8 @@ int ff_mpegts_parse_packet(MpegTSContext *ts, AVPacket *pkt,
handle_packet(ts, buf);
buf += TS_PACKET_SIZE;
len -= TS_PACKET_SIZE;
+ if (ts->stop_parse == 1)
+ break;
}
}
return len1 - len;
@@ -1862,15 +1935,14 @@ void ff_mpegts_parse_close(MpegTSContext *ts)
}
AVInputFormat ff_mpegts_demuxer = {
- "mpegts",
- NULL_IF_CONFIG_SMALL("MPEG-2 transport stream format"),
- sizeof(MpegTSContext),
- mpegts_probe,
- mpegts_read_header,
- mpegts_read_packet,
- mpegts_read_close,
- read_seek,
- mpegts_get_pcr,
+ .name = "mpegts",
+ .long_name = NULL_IF_CONFIG_SMALL("MPEG-2 transport stream format"),
+ .priv_data_size = sizeof(MpegTSContext),
+ .read_probe = mpegts_probe,
+ .read_header = mpegts_read_header,
+ .read_packet = mpegts_read_packet,
+ .read_close = mpegts_read_close,
+ .read_timestamp = mpegts_get_dts,
.flags = AVFMT_SHOW_IDS|AVFMT_TS_DISCONT,
#ifdef USE_SYNCPOINT_SEARCH
.read_seek2 = read_seek2,
@@ -1878,15 +1950,13 @@ AVInputFormat ff_mpegts_demuxer = {
};
AVInputFormat ff_mpegtsraw_demuxer = {
- "mpegtsraw",
- NULL_IF_CONFIG_SMALL("MPEG-2 raw transport stream format"),
- sizeof(MpegTSContext),
- NULL,
- mpegts_read_header,
- mpegts_raw_read_packet,
- mpegts_read_close,
- read_seek,
- mpegts_get_pcr,
+ .name = "mpegtsraw",
+ .long_name = NULL_IF_CONFIG_SMALL("MPEG-2 raw transport stream format"),
+ .priv_data_size = sizeof(MpegTSContext),
+ .read_header = mpegts_read_header,
+ .read_packet = mpegts_raw_read_packet,
+ .read_close = mpegts_read_close,
+ .read_timestamp = mpegts_get_dts,
.flags = AVFMT_SHOW_IDS|AVFMT_TS_DISCONT,
#ifdef USE_SYNCPOINT_SEARCH
.read_seek2 = read_seek2,
diff --git a/libavformat/mpegts.h b/libavformat/mpegts.h
index 73ef2ed10a..e60329711b 100644
--- a/libavformat/mpegts.h
+++ b/libavformat/mpegts.h
@@ -2,20 +2,20 @@
* MPEG2 transport stream defines
* Copyright (c) 2003 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 83ede1d79b..fa773ebbee 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -2,20 +2,20 @@
* MPEG2 transport stream (aka DVB) muxer
* Copyright (c) 2003 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -24,6 +24,7 @@
#include "libavutil/dict.h"
#include "libavutil/mathematics.h"
#include "libavutil/opt.h"
+#include "libavutil/avassert.h"
#include "libavcodec/mpegvideo.h"
#include "avformat.h"
#include "internal.h"
@@ -75,19 +76,24 @@ typedef struct MpegTSWrite {
int pmt_start_pid;
int start_pid;
+ int m2ts_mode;
} MpegTSWrite;
static const AVOption options[] = {
{ "mpegts_transport_stream_id", "Set transport_stream_id field.",
- offsetof(MpegTSWrite, transport_stream_id), FF_OPT_TYPE_INT, {.dbl = 0x0001 }, 0x0001, 0xffff, AV_OPT_FLAG_ENCODING_PARAM},
+ offsetof(MpegTSWrite, transport_stream_id), AV_OPT_TYPE_INT, {.dbl = 0x0001 }, 0x0001, 0xffff, AV_OPT_FLAG_ENCODING_PARAM},
{ "mpegts_original_network_id", "Set original_network_id field.",
- offsetof(MpegTSWrite, original_network_id), FF_OPT_TYPE_INT, {.dbl = 0x0001 }, 0x0001, 0xffff, AV_OPT_FLAG_ENCODING_PARAM},
+ offsetof(MpegTSWrite, original_network_id), AV_OPT_TYPE_INT, {.dbl = 0x0001 }, 0x0001, 0xffff, AV_OPT_FLAG_ENCODING_PARAM},
{ "mpegts_service_id", "Set service_id field.",
- offsetof(MpegTSWrite, service_id), FF_OPT_TYPE_INT, {.dbl = 0x0001 }, 0x0001, 0xffff, AV_OPT_FLAG_ENCODING_PARAM},
+ offsetof(MpegTSWrite, service_id), AV_OPT_TYPE_INT, {.dbl = 0x0001 }, 0x0001, 0xffff, AV_OPT_FLAG_ENCODING_PARAM},
{ "mpegts_pmt_start_pid", "Set the first pid of the PMT.",
- offsetof(MpegTSWrite, pmt_start_pid), FF_OPT_TYPE_INT, {.dbl = 0x1000 }, 0x1000, 0x1f00, AV_OPT_FLAG_ENCODING_PARAM},
+ offsetof(MpegTSWrite, pmt_start_pid), AV_OPT_TYPE_INT, {.dbl = 0x1000 }, 0x0010, 0x1f00, AV_OPT_FLAG_ENCODING_PARAM},
{ "mpegts_start_pid", "Set the first pid.",
- offsetof(MpegTSWrite, start_pid), FF_OPT_TYPE_INT, {.dbl = 0x0100 }, 0x0100, 0x0f00, AV_OPT_FLAG_ENCODING_PARAM},
+ offsetof(MpegTSWrite, start_pid), AV_OPT_TYPE_INT, {.dbl = 0x0100 }, 0x0100, 0x0f00, AV_OPT_FLAG_ENCODING_PARAM},
+ {"mpegts_m2ts_mode", "Enable m2ts mode.",
+ offsetof(MpegTSWrite, m2ts_mode), AV_OPT_TYPE_INT, {.dbl = -1 },
+ -1,1, AV_OPT_FLAG_ENCODING_PARAM},
+ { "muxrate", NULL, offsetof(MpegTSWrite, mux_rate), AV_OPT_TYPE_INT, {1}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM},
{ NULL },
};
@@ -184,7 +190,7 @@ static int mpegts_write_section1(MpegTSSection *s, int tid, int id,
/*********************************************/
/* mpegts writer */
-#define DEFAULT_PROVIDER_NAME "Libav"
+#define DEFAULT_PROVIDER_NAME "FFmpeg"
#define DEFAULT_SERVICE_NAME "Service01"
/* a PES packet header is generated every DEFAULT_PES_HEADER_FREQ packets */
@@ -204,6 +210,7 @@ typedef struct MpegTSWriteStream {
int first_pts_check; ///< first pts check needed
int64_t payload_pts;
int64_t payload_dts;
+ int payload_flags;
uint8_t payload[DEFAULT_PES_PAYLOAD_SIZE];
ADTSContext *adts;
} MpegTSWriteStream;
@@ -433,9 +440,28 @@ static MpegTSService *mpegts_add_service(MpegTSWrite *ts,
return service;
}
+static int64_t get_pcr(const MpegTSWrite *ts, AVIOContext *pb)
+{
+ return av_rescale(avio_tell(pb) + 11, 8 * PCR_TIME_BASE, ts->mux_rate) +
+ ts->first_pcr;
+}
+
+static void mpegts_prefix_m2ts_header(AVFormatContext *s)
+{
+ MpegTSWrite *ts = s->priv_data;
+ if (ts->m2ts_mode) {
+ int64_t pcr = get_pcr(s->priv_data, s->pb);
+ uint32_t tp_extra_header = pcr % 0x3fffffff;
+ tp_extra_header = AV_RB32(&tp_extra_header);
+ avio_write(s->pb, (unsigned char *) &tp_extra_header,
+ sizeof(tp_extra_header));
+ }
+}
+
static void section_write_packet(MpegTSSection *s, const uint8_t *packet)
{
AVFormatContext *ctx = s->opaque;
+ mpegts_prefix_m2ts_header(ctx);
avio_write(ctx->pb, packet, TS_PACKET_SIZE);
}
@@ -538,7 +564,10 @@ static int mpegts_write_header(AVFormatContext *s)
service->pcr_pid = ts_st->pid;
}
- ts->mux_rate = s->mux_rate ? s->mux_rate : 1;
+#if FF_API_MUXRATE
+ if (s->mux_rate)
+ ts->mux_rate = s->mux_rate;
+#endif
if (ts->mux_rate > 1) {
service->pcr_packet_period = (ts->mux_rate * PCR_RETRANS_TIME) /
@@ -583,6 +612,14 @@ static int mpegts_write_header(AVFormatContext *s)
service->pcr_packet_period,
ts->sdt_packet_period, ts->pat_packet_period);
+ if (ts->m2ts_mode == -1) {
+ if (av_match_ext(s->filename, "m2ts")) {
+ ts->m2ts_mode = 1;
+ } else {
+ ts->m2ts_mode = 0;
+ }
+ }
+
avio_flush(s->pb);
return 0;
@@ -615,13 +652,7 @@ static void retransmit_si_info(AVFormatContext *s)
}
}
-static int64_t get_pcr(const MpegTSWrite *ts, AVIOContext *pb)
-{
- return av_rescale(avio_tell(pb) + 11, 8 * PCR_TIME_BASE, ts->mux_rate) +
- ts->first_pcr;
-}
-
-static uint8_t* write_pcr_bits(uint8_t *buf, int64_t pcr)
+static int write_pcr_bits(uint8_t *buf, int64_t pcr)
{
int64_t pcr_low = pcr % 300, pcr_high = pcr / 300;
@@ -632,7 +663,7 @@ static uint8_t* write_pcr_bits(uint8_t *buf, int64_t pcr)
*buf++ = pcr_high << 7 | pcr_low >> 8 | 0x7e;
*buf++ = pcr_low;
- return buf;
+ return 6;
}
/* Write a single null transport stream packet */
@@ -647,6 +678,7 @@ static void mpegts_insert_null_packet(AVFormatContext *s)
*q++ = 0xff;
*q++ = 0x10;
memset(q, 0x0FF, TS_PACKET_SIZE - (q - buf));
+ mpegts_prefix_m2ts_header(s);
avio_write(s->pb, buf, TS_PACKET_SIZE);
}
@@ -668,10 +700,11 @@ static void mpegts_insert_pcr_only(AVFormatContext *s, AVStream *st)
*q++ = 0x10; /* Adaptation flags: PCR present */
/* PCR coded into 6 bytes */
- q = write_pcr_bits(q, get_pcr(ts, s->pb));
+ q += write_pcr_bits(q, get_pcr(ts, s->pb));
/* stuffing bytes */
memset(q, 0xFF, TS_PACKET_SIZE - (q - buf));
+ mpegts_prefix_m2ts_header(s);
avio_write(s->pb, buf, TS_PACKET_SIZE);
}
@@ -689,6 +722,39 @@ static void write_pts(uint8_t *q, int fourbits, int64_t pts)
*q++ = val;
}
+/* Set an adaptation field flag in an MPEG-TS packet*/
+static void set_af_flag(uint8_t *pkt, int flag)
+{
+ // expect at least one flag to set
+ assert(flag);
+
+ if ((pkt[3] & 0x20) == 0) {
+ // no AF yet, set adaptation field flag
+ pkt[3] |= 0x20;
+ // 1 byte length, no flags
+ pkt[4] = 1;
+ pkt[5] = 0;
+ }
+ pkt[5] |= flag;
+}
+
+/* Extend the adaptation field by size bytes */
+static void extend_af(uint8_t *pkt, int size)
+{
+ // expect already existing adaptation field
+ assert(pkt[3] & 0x20);
+ pkt[4] += size;
+}
+
+/* Get a pointer to MPEG-TS payload (right after TS packet header) */
+static uint8_t *get_ts_payload_start(uint8_t *pkt)
+{
+ if (pkt[3] & 0x20)
+ return pkt + 5 + pkt[4];
+ else
+ return pkt + 4;
+}
+
/* Add a pes header to the front of payload, and segment into an integer number of
* ts packets. The final ts packet is padded using an over-sized adaptation header
* to exactly fill the last ts packet.
@@ -696,7 +762,7 @@ static void write_pts(uint8_t *q, int fourbits, int64_t pts)
*/
static void mpegts_write_pes(AVFormatContext *s, AVStream *st,
const uint8_t *payload, int payload_size,
- int64_t pts, int64_t dts)
+ int64_t pts, int64_t dts, int key)
{
MpegTSWriteStream *ts_st = st->priv_data;
MpegTSWrite *ts = s->priv_data;
@@ -741,8 +807,17 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st,
*q++ = val;
*q++ = ts_st->pid;
ts_st->cc = (ts_st->cc + 1) & 0xf;
- *q++ = 0x10 | ts_st->cc | (write_pcr ? 0x20 : 0);
+ *q++ = 0x10 | ts_st->cc; // payload indicator + CC
+ if (key && is_start && pts != AV_NOPTS_VALUE) {
+ // set Random Access for key frames
+ if (ts_st->pid == ts_st->service->pcr_pid)
+ write_pcr = 1;
+ set_af_flag(buf, 0x40);
+ q = get_ts_payload_start(buf);
+ }
if (write_pcr) {
+ set_af_flag(buf, 0x10);
+ q = get_ts_payload_start(buf);
// add 11, pcr references the last byte of program clock reference base
if (ts->mux_rate > 1)
pcr = get_pcr(ts, s->pb);
@@ -750,9 +825,8 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st,
pcr = (dts - delay)*300;
if (dts != AV_NOPTS_VALUE && dts < pcr / 300)
av_log(s, AV_LOG_WARNING, "dts < pcr, TS is invalid\n");
- *q++ = 7; /* AFC length */
- *q++ = 0x10; /* flags: PCR present */
- q = write_pcr_bits(q, pcr);
+ extend_af(buf, write_pcr_bits(q, pcr));
+ q = get_ts_payload_start(buf);
}
if (is_start) {
int pes_extension = 0;
@@ -867,6 +941,7 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st,
memcpy(buf + TS_PACKET_SIZE - len, payload, len);
payload += len;
payload_size -= len;
+ mpegts_prefix_m2ts_header(s);
avio_write(s->pb, buf, TS_PACKET_SIZE);
}
avio_flush(s->pb);
@@ -904,7 +979,7 @@ static int mpegts_write_packet(AVFormatContext *s, AVPacket *pkt)
}
do {
- p = ff_find_start_code(p, buf_end, &state);
+ p = avpriv_mpv_find_start_code(p, buf_end, &state);
//av_log(s, AV_LOG_INFO, "nal %d\n", state & 0x1f);
} while (p < buf_end && (state & 0x1f) != 9 &&
(state & 0x1f) != 5 && (state & 0x1f) != 1);
@@ -948,22 +1023,25 @@ static int mpegts_write_packet(AVFormatContext *s, AVPacket *pkt)
}
}
- if (st->codec->codec_type != AVMEDIA_TYPE_AUDIO) {
+ if (ts_st->payload_index && ts_st->payload_index + size > DEFAULT_PES_PAYLOAD_SIZE) {
+ mpegts_write_pes(s, st, ts_st->payload, ts_st->payload_index,
+ ts_st->payload_pts, ts_st->payload_dts,
+ ts_st->payload_flags & AV_PKT_FLAG_KEY);
+ ts_st->payload_index = 0;
+ }
+
+ if (st->codec->codec_type != AVMEDIA_TYPE_AUDIO || size > DEFAULT_PES_PAYLOAD_SIZE) {
+ av_assert0(!ts_st->payload_index);
// for video and subtitle, write a single pes packet
- mpegts_write_pes(s, st, buf, size, pts, dts);
+ mpegts_write_pes(s, st, buf, size, pts, dts, pkt->flags & AV_PKT_FLAG_KEY);
av_free(data);
return 0;
}
- if (ts_st->payload_index + size > DEFAULT_PES_PAYLOAD_SIZE) {
- mpegts_write_pes(s, st, ts_st->payload, ts_st->payload_index,
- ts_st->payload_pts, ts_st->payload_dts);
- ts_st->payload_index = 0;
- }
-
if (!ts_st->payload_index) {
ts_st->payload_pts = pts;
ts_st->payload_dts = dts;
+ ts_st->payload_flags = pkt->flags;
}
memcpy(ts_st->payload + ts_st->payload_index, buf, size);
@@ -988,7 +1066,8 @@ static int mpegts_write_end(AVFormatContext *s)
ts_st = st->priv_data;
if (ts_st->payload_index > 0) {
mpegts_write_pes(s, st, ts_st->payload, ts_st->payload_index,
- ts_st->payload_pts, ts_st->payload_dts);
+ ts_st->payload_pts, ts_st->payload_dts,
+ ts_st->payload_flags & AV_PKT_FLAG_KEY);
}
av_freep(&ts_st->adts);
}
@@ -1006,15 +1085,15 @@ static int mpegts_write_end(AVFormatContext *s)
}
AVOutputFormat ff_mpegts_muxer = {
- "mpegts",
- NULL_IF_CONFIG_SMALL("MPEG-2 transport stream format"),
- "video/x-mpegts",
- "ts,m2t",
- sizeof(MpegTSWrite),
- CODEC_ID_MP2,
- CODEC_ID_MPEG2VIDEO,
- mpegts_write_header,
- mpegts_write_packet,
- mpegts_write_end,
+ .name = "mpegts",
+ .long_name = NULL_IF_CONFIG_SMALL("MPEG-2 transport stream format"),
+ .mime_type = "video/x-mpegts",
+ .extensions = "ts,m2t,m2ts",
+ .priv_data_size = sizeof(MpegTSWrite),
+ .audio_codec = CODEC_ID_MP2,
+ .video_codec = CODEC_ID_MPEG2VIDEO,
+ .write_header = mpegts_write_header,
+ .write_packet = mpegts_write_packet,
+ .write_trailer = mpegts_write_end,
.priv_class = &mpegts_muxer_class,
};
diff --git a/libavformat/mpegvideodec.c b/libavformat/mpegvideodec.c
index 9fea117632..d38d6955e4 100644
--- a/libavformat/mpegvideodec.c
+++ b/libavformat/mpegvideodec.c
@@ -3,20 +3,20 @@
* Copyright (c) 2002-2003 Fabrice Bellard
* Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/mpjpeg.c b/libavformat/mpjpeg.c
index ebb57bf87c..46a98b3d44 100644
--- a/libavformat/mpjpeg.c
+++ b/libavformat/mpjpeg.c
@@ -2,20 +2,20 @@
* Multipart JPEG format
* Copyright (c) 2000, 2001, 2002, 2003 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avformat.h"
@@ -54,14 +54,13 @@ static int mpjpeg_write_trailer(AVFormatContext *s)
}
AVOutputFormat ff_mpjpeg_muxer = {
- "mpjpeg",
- NULL_IF_CONFIG_SMALL("MIME multipart JPEG format"),
- "multipart/x-mixed-replace;boundary=" BOUNDARY_TAG,
- "mjpg",
- 0,
- CODEC_ID_NONE,
- CODEC_ID_MJPEG,
- mpjpeg_write_header,
- mpjpeg_write_packet,
- mpjpeg_write_trailer,
+ .name = "mpjpeg",
+ .long_name = NULL_IF_CONFIG_SMALL("MIME multipart JPEG format"),
+ .mime_type = "multipart/x-mixed-replace;boundary=" BOUNDARY_TAG,
+ .extensions = "mjpg",
+ .audio_codec = CODEC_ID_NONE,
+ .video_codec = CODEC_ID_MJPEG,
+ .write_header = mpjpeg_write_header,
+ .write_packet = mpjpeg_write_packet,
+ .write_trailer = mpjpeg_write_trailer,
};
diff --git a/libavformat/msnwc_tcp.c b/libavformat/msnwc_tcp.c
index d9d8000e8b..b394b8779b 100644
--- a/libavformat/msnwc_tcp.c
+++ b/libavformat/msnwc_tcp.c
@@ -1,20 +1,20 @@
/*
* Copyright (C) 2008 Ramiro Polla
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -75,7 +75,7 @@ static int msnwc_tcp_read_header(AVFormatContext *ctx, AVFormatParameters *ap)
AVCodecContext *codec;
AVStream *st;
- st = av_new_stream(ctx, 0);
+ st = avformat_new_stream(ctx, NULL);
if(!st)
return AVERROR(ENOMEM);
@@ -88,9 +88,9 @@ static int msnwc_tcp_read_header(AVFormatContext *ctx, AVFormatParameters *ap)
/* Some files start with "connected\r\n\r\n".
* So skip until we find the first byte of struct size */
- while(avio_r8(pb) != HEADER_SIZE && !pb->eof_reached);
+ while(avio_r8(pb) != HEADER_SIZE && !url_feof(pb));
- if(pb->eof_reached) {
+ if(url_feof(pb)) {
av_log(ctx, AV_LOG_ERROR, "Could not find valid start.");
return -1;
}
@@ -131,10 +131,9 @@ static int msnwc_tcp_read_packet(AVFormatContext *ctx, AVPacket *pkt)
}
AVInputFormat ff_msnwc_tcp_demuxer = {
- "msnwctcp",
- NULL_IF_CONFIG_SMALL("MSN TCP Webcam stream"),
- 0,
- msnwc_tcp_probe,
- msnwc_tcp_read_header,
- msnwc_tcp_read_packet,
+ .name = "msnwctcp",
+ .long_name = NULL_IF_CONFIG_SMALL("MSN TCP Webcam stream"),
+ .read_probe = msnwc_tcp_probe,
+ .read_header = msnwc_tcp_read_header,
+ .read_packet = msnwc_tcp_read_packet,
};
diff --git a/libavformat/mtv.c b/libavformat/mtv.c
index 92d38e13cd..966e9bb8b0 100644
--- a/libavformat/mtv.c
+++ b/libavformat/mtv.c
@@ -2,20 +2,20 @@
* mtv demuxer
* Copyright (c) 2006 Reynaldo H. Verdejo Pinochet
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -32,8 +32,6 @@
#define MTV_HEADER_SIZE 512
#define MTV_AUDIO_PADDING_SIZE 12
#define AUDIO_SAMPLING_RATE 44100
-#define VIDEO_SID 0
-#define AUDIO_SID 1
typedef struct MTVDemuxContext {
@@ -118,7 +116,7 @@ static int mtv_read_header(AVFormatContext *s, AVFormatParameters *ap)
// video - raw rgb565
- st = av_new_stream(s, VIDEO_SID);
+ st = avformat_new_stream(s, NULL);
if(!st)
return AVERROR(ENOMEM);
@@ -134,7 +132,7 @@ static int mtv_read_header(AVFormatContext *s, AVFormatParameters *ap)
// audio - mp3
- st = av_new_stream(s, AUDIO_SID);
+ st = avformat_new_stream(s, NULL);
if(!st)
return AVERROR(ENOMEM);
@@ -171,7 +169,7 @@ static int mtv_read_packet(AVFormatContext *s, AVPacket *pkt)
return ret;
pkt->pos -= MTV_AUDIO_PADDING_SIZE;
- pkt->stream_index = AUDIO_SID;
+ pkt->stream_index = 1;
}else
{
@@ -190,17 +188,17 @@ static int mtv_read_packet(AVFormatContext *s, AVPacket *pkt)
for(i=0;i<mtv->img_segment_size/2;i++)
*((uint16_t *)pkt->data+i) = av_bswap16(*((uint16_t *)pkt->data+i));
#endif
- pkt->stream_index = VIDEO_SID;
+ pkt->stream_index = 0;
}
return ret;
}
AVInputFormat ff_mtv_demuxer = {
- "MTV",
- NULL_IF_CONFIG_SMALL("MTV format"),
- sizeof(MTVDemuxContext),
- mtv_probe,
- mtv_read_header,
- mtv_read_packet,
+ .name = "MTV",
+ .long_name = NULL_IF_CONFIG_SMALL("MTV format"),
+ .priv_data_size = sizeof(MTVDemuxContext),
+ .read_probe = mtv_probe,
+ .read_header = mtv_read_header,
+ .read_packet = mtv_read_packet,
};
diff --git a/libavformat/mvi.c b/libavformat/mvi.c
index 809cdf5a3b..8586d10e07 100644
--- a/libavformat/mvi.c
+++ b/libavformat/mvi.c
@@ -2,20 +2,20 @@
* Motion Pixels MVI Demuxer
* Copyright (c) 2008 Gregory Montoir (cyx@users.sourceforge.net)
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -42,11 +42,11 @@ static int read_header(AVFormatContext *s, AVFormatParameters *ap)
AVStream *ast, *vst;
unsigned int version, frames_count, msecs_per_frame, player_version;
- ast = av_new_stream(s, 0);
+ ast = avformat_new_stream(s, NULL);
if (!ast)
return AVERROR(ENOMEM);
- vst = av_new_stream(s, 0);
+ vst = avformat_new_stream(s, NULL);
if (!vst)
return AVERROR(ENOMEM);
@@ -124,11 +124,10 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt)
}
AVInputFormat ff_mvi_demuxer = {
- "mvi",
- NULL_IF_CONFIG_SMALL("Motion Pixels MVI format"),
- sizeof(MviDemuxContext),
- NULL,
- read_header,
- read_packet,
+ .name = "mvi",
+ .long_name = NULL_IF_CONFIG_SMALL("Motion Pixels MVI format"),
+ .priv_data_size = sizeof(MviDemuxContext),
+ .read_header = read_header,
+ .read_packet = read_packet,
.extensions = "mvi"
};
diff --git a/libavformat/mxf.c b/libavformat/mxf.c
index 6192368da0..b39a9b64cc 100644
--- a/libavformat/mxf.c
+++ b/libavformat/mxf.c
@@ -2,23 +2,24 @@
* MXF
* Copyright (c) 2006 SmartJog S.A., Baptiste Coudurier <baptiste dot coudurier at smartjog dot com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include "libavutil/common.h"
#include "mxf.h"
/**
@@ -41,6 +42,8 @@ const MXFCodecUL ff_mxf_codec_uls[] = {
{ { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x07,0x04,0x01,0x02,0x02,0x03,0x01,0x01,0x00 }, 14, CODEC_ID_JPEG2000 }, /* JPEG2000 Codestream */
{ { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x01,0x7F,0x00,0x00,0x00 }, 13, CODEC_ID_RAWVIDEO }, /* Uncompressed */
{ { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x03,0x02,0x00,0x00 }, 14, CODEC_ID_DNXHD }, /* SMPTE VC-3/DNxHD */
+ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0A,0x04,0x01,0x02,0x02,0x01,0x32,0x00,0x00 }, 14, CODEC_ID_H264 }, /* H.264/MPEG-4 AVC Intra */
+ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0A,0x04,0x01,0x02,0x01,0x01,0x02,0x02,0x00 }, 15, CODEC_ID_V210 }, /* V210 */
/* SoundEssenceCompression */
{ { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 }, 13, CODEC_ID_PCM_S16LE }, /* Uncompressed */
{ { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x7F,0x00,0x00,0x00 }, 13, CODEC_ID_PCM_S16LE },
@@ -80,7 +83,7 @@ static const struct {
{PIX_FMT_PAL8, {'P', 8 }},
};
-static const int num_pixel_layouts = sizeof(ff_mxf_pixel_layouts) / sizeof(*ff_mxf_pixel_layouts);
+static const int num_pixel_layouts = FF_ARRAY_ELEMS(ff_mxf_pixel_layouts);
int ff_mxf_decode_pixel_layout(const char pixel_layout[16], enum PixelFormat *pix_fmt)
{
diff --git a/libavformat/mxf.h b/libavformat/mxf.h
index beb66281ab..4f5d4c0d95 100644
--- a/libavformat/mxf.h
+++ b/libavformat/mxf.h
@@ -2,20 +2,20 @@
* MXF
* Copyright (c) 2006 SmartJog S.A., Baptiste Coudurier <baptiste dot coudurier at smartjog dot com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVFORMAT_MXF_H
diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index cf2bb6cc65..e1fec3dbbb 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -2,20 +2,20 @@
* MXF demuxer.
* Copyright (c) 2006 SmartJog S.A., Baptiste Coudurier <baptiste dot coudurier at smartjog dot com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -51,6 +51,34 @@
#include "avformat.h"
#include "mxf.h"
+typedef enum {
+ Header,
+ BodyPartition,
+ Footer
+} MXFPartitionType;
+
+typedef enum {
+ OP1a,
+ OP1b,
+ OP1c,
+ OP2a,
+ OP2b,
+ OP2c,
+ OP3a,
+ OP3b,
+ OP3c,
+ OPAtom,
+} MXFOP;
+
+typedef struct {
+ int closed;
+ int complete;
+ MXFPartitionType type;
+ uint64_t previous_partition;
+ int index_sid;
+ int body_sid;
+} MXFPartition;
+
typedef struct {
UID uid;
enum MXFMetadataSetType type;
@@ -126,6 +154,9 @@ typedef struct {
} MXFMetadataSet;
typedef struct {
+ MXFPartition *partitions;
+ unsigned partitions_count;
+ MXFOP op;
UID *packages_refs;
int packages_count;
MXFMetadataSet **metadata_sets;
@@ -134,6 +165,7 @@ typedef struct {
struct AVAES *aesc;
uint8_t *local_tags;
int local_tags_count;
+ uint64_t footer_partition;
} MXFContext;
enum MXFWrappingScheme {
@@ -180,7 +212,7 @@ static int64_t klv_decode_ber_length(AVIOContext *pb)
static int mxf_read_sync(AVIOContext *pb, const uint8_t *key, unsigned size)
{
int i, b;
- for (i = 0; i < size && !pb->eof_reached; i++) {
+ for (i = 0; i < size && !url_feof(pb); i++) {
b = avio_r8(pb);
if (b == key[0])
i = 0;
@@ -224,12 +256,13 @@ static int mxf_get_d10_aes3_packet(AVIOContext *pb, AVStream *st, AVPacket *pkt,
if (length > 61444) /* worst case PAL 1920 samples 8 channels */
return -1;
- av_new_packet(pkt, length);
- avio_read(pb, pkt->data, length);
+ length = av_get_packet(pb, pkt, length);
+ if (length < 0)
+ return length;
data_ptr = pkt->data;
end_ptr = pkt->data + length;
buf_ptr = pkt->data + 4; /* skip SMPTE 331M header */
- for (; buf_ptr < end_ptr; ) {
+ for (; buf_ptr + st->codec->channels*4 < end_ptr; ) {
for (i = 0; i < st->codec->channels; i++) {
uint32_t sample = bytestream_get_le32(&buf_ptr);
if (st->codec->bits_per_coded_sample == 24)
@@ -239,7 +272,7 @@ static int mxf_get_d10_aes3_packet(AVIOContext *pb, AVStream *st, AVPacket *pkt,
}
buf_ptr += 32 - st->codec->channels*4; // always 8 channels stored SMPTE 331M
}
- pkt->size = data_ptr - pkt->data;
+ av_shrink_packet(pkt, data_ptr - pkt->data);
return 0;
}
@@ -291,12 +324,16 @@ static int mxf_decrypt_triplet(AVFormatContext *s, AVPacket *pkt, KLVPacket *klv
if (memcmp(tmpbuf, checkv, 16))
av_log(s, AV_LOG_ERROR, "probably incorrect decryption key\n");
size -= 32;
- av_get_packet(pb, pkt, size);
+ size = av_get_packet(pb, pkt, size);
+ if (size < 0)
+ return size;
+ else if (size < plaintext_size)
+ return AVERROR_INVALIDDATA;
size -= plaintext_size;
if (mxf->aesc)
av_aes_crypt(mxf->aesc, &pkt->data[plaintext_size],
&pkt->data[plaintext_size], size >> 4, ivec, 1);
- pkt->size = orig_size;
+ av_shrink_packet(pkt, orig_size);
pkt->stream_index = index;
avio_skip(pb, end - avio_tell(pb));
return 0;
@@ -306,7 +343,7 @@ static int mxf_read_packet(AVFormatContext *s, AVPacket *pkt)
{
KLVPacket klv;
- while (!s->pb->eof_reached) {
+ while (!url_feof(s->pb)) {
if (klv_read_packet(&klv, s->pb) < 0)
return -1;
PRINT_KEY(s, "read packet", klv.key);
@@ -333,8 +370,11 @@ static int mxf_read_packet(AVFormatContext *s, AVPacket *pkt)
av_log(s, AV_LOG_ERROR, "error reading D-10 aes3 frame\n");
return -1;
}
- } else
- av_get_packet(s->pb, pkt, klv.length);
+ } else {
+ int ret = av_get_packet(s->pb, pkt, klv.length);
+ if (ret < 0)
+ return ret;
+ }
pkt->stream_index = index;
pkt->pos = klv.offset;
return 0;
@@ -365,6 +405,80 @@ static int mxf_read_primer_pack(void *arg, AVIOContext *pb, int tag, int size, U
return 0;
}
+static int mxf_read_partition_pack(void *arg, ByteIOContext *pb, int tag, int size, UID uid)
+{
+ MXFContext *mxf = arg;
+ MXFPartition *partition;
+ UID op;
+ uint64_t footer_partition;
+
+ if (mxf->partitions_count+1 >= UINT_MAX / sizeof(*mxf->partitions))
+ return AVERROR(ENOMEM);
+
+ mxf->partitions = av_realloc(mxf->partitions, (mxf->partitions_count + 1) * sizeof(*mxf->partitions));
+ if (!mxf->partitions)
+ return AVERROR(ENOMEM);
+
+ partition = &mxf->partitions[mxf->partitions_count++];
+
+ switch(uid[13]) {
+ case 2:
+ partition->type = Header;
+ break;
+ case 3:
+ partition->type = BodyPartition;
+ break;
+ case 4:
+ partition->type = Footer;
+ break;
+ default:
+ av_log(mxf->fc, AV_LOG_ERROR, "unknown partition type %i\n", uid[13]);
+ return AVERROR_INVALIDDATA;
+ }
+
+ /* consider both footers to be closed (there is only Footer and CompleteFooter) */
+ partition->closed = partition->type == Footer || !(uid[14] & 1);
+ partition->complete = uid[14] > 2;
+ avio_skip(pb, 16);
+ partition->previous_partition = avio_rb64(pb);
+ footer_partition = avio_rb64(pb);
+ avio_skip(pb, 16);
+ partition->index_sid = avio_rb32(pb);
+ avio_skip(pb, 8);
+ partition->body_sid = avio_rb32(pb);
+ avio_read(pb, op, sizeof(UID));
+
+ /* some files don'thave FooterPartition set in every partition */
+ if (footer_partition) {
+ if (mxf->footer_partition && mxf->footer_partition != footer_partition) {
+ av_log(mxf->fc, AV_LOG_ERROR, "inconsistent FooterPartition value: %li != %li\n",
+ mxf->footer_partition, footer_partition);
+ } else {
+ mxf->footer_partition = footer_partition;
+ }
+ }
+
+ av_dlog(mxf->fc, "PartitionPack: PreviousPartition = 0x%lx, "
+ "FooterPartition = 0x%lx, IndexSID = %i, BodySID = %i\n",
+ partition->previous_partition, footer_partition,
+ partition->index_sid, partition->body_sid);
+
+ if (op[12] == 1 && op[13] == 1) mxf->op = OP1a;
+ else if (op[12] == 1 && op[13] == 2) mxf->op = OP1b;
+ else if (op[12] == 1 && op[13] == 3) mxf->op = OP1c;
+ else if (op[12] == 2 && op[13] == 1) mxf->op = OP2a;
+ else if (op[12] == 2 && op[13] == 2) mxf->op = OP2b;
+ else if (op[12] == 2 && op[13] == 3) mxf->op = OP2c;
+ else if (op[12] == 3 && op[13] == 1) mxf->op = OP3a;
+ else if (op[12] == 3 && op[13] == 2) mxf->op = OP3b;
+ else if (op[12] == 3 && op[13] == 3) mxf->op = OP3c;
+ else if (op[12] == 0x10) mxf->op = OPAtom;
+ else
+ av_log(mxf->fc, AV_LOG_ERROR, "unknown operational pattern: %02xh %02xh\n", op[12], op[13]);
+
+ return 0;
+}
+
static int mxf_add_metadata_set(MXFContext *mxf, void *metadata_set)
{
if (mxf->metadata_sets_count+1 >= UINT_MAX / sizeof(*mxf->metadata_sets))
@@ -600,7 +714,7 @@ static int mxf_read_generic_descriptor(void *arg, AVIOContext *pb, int tag, int
default:
/* Private uid used by SONY C0023S01.mxf */
if (IS_KLV_KEY(uid, mxf_sony_mpeg4_extradata)) {
- descriptor->extradata = av_malloc(size);
+ descriptor->extradata = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);
if (!descriptor->extradata)
return -1;
descriptor->extradata_size = size;
@@ -738,11 +852,12 @@ static int mxf_parse_structural_metadata(MXFContext *mxf)
if (!source_track)
continue;
- st = av_new_stream(mxf->fc, source_track->track_id);
+ st = avformat_new_stream(mxf->fc, NULL);
if (!st) {
av_log(mxf->fc, AV_LOG_ERROR, "could not allocate stream\n");
return -1;
}
+ st->id = source_track->track_id;
st->priv_data = source_track;
st->duration = component->duration;
if (st->duration == -1)
@@ -821,12 +936,12 @@ static int mxf_parse_structural_metadata(MXFContext *mxf)
st->codec->sample_rate = descriptor->sample_rate.num / descriptor->sample_rate.den;
/* TODO: implement CODEC_ID_RAWAUDIO */
if (st->codec->codec_id == CODEC_ID_PCM_S16LE) {
- if (descriptor->bits_per_sample == 24)
+ if (descriptor->bits_per_sample > 16 && descriptor->bits_per_sample <= 24)
st->codec->codec_id = CODEC_ID_PCM_S24LE;
else if (descriptor->bits_per_sample == 32)
st->codec->codec_id = CODEC_ID_PCM_S32LE;
} else if (st->codec->codec_id == CODEC_ID_PCM_S16BE) {
- if (descriptor->bits_per_sample == 24)
+ if (descriptor->bits_per_sample > 16 && descriptor->bits_per_sample <= 24)
st->codec->codec_id = CODEC_ID_PCM_S24BE;
else if (descriptor->bits_per_sample == 32)
st->codec->codec_id = CODEC_ID_PCM_S32BE;
@@ -844,6 +959,16 @@ static int mxf_parse_structural_metadata(MXFContext *mxf)
static const MXFMetadataReadTableEntry mxf_metadata_read_table[] = {
{ { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x05,0x01,0x00 }, mxf_read_primer_pack },
+ { { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x02,0x01,0x00 }, mxf_read_partition_pack },
+ { { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x02,0x02,0x00 }, mxf_read_partition_pack },
+ { { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x02,0x03,0x00 }, mxf_read_partition_pack },
+ { { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x02,0x04,0x00 }, mxf_read_partition_pack },
+ { { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x03,0x01,0x00 }, mxf_read_partition_pack },
+ { { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x03,0x02,0x00 }, mxf_read_partition_pack },
+ { { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x03,0x03,0x00 }, mxf_read_partition_pack },
+ { { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x03,0x04,0x00 }, mxf_read_partition_pack },
+ { { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x04,0x02,0x00 }, mxf_read_partition_pack },
+ { { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x04,0x04,0x00 }, mxf_read_partition_pack },
{ { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x18,0x00 }, mxf_read_content_storage, 0, AnyType },
{ { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x37,0x00 }, mxf_read_source_package, sizeof(MXFPackage), SourcePackage },
{ { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x36,0x00 }, mxf_read_material_package, sizeof(MXFPackage), MaterialPackage },
@@ -915,7 +1040,7 @@ static int mxf_read_header(AVFormatContext *s, AVFormatParameters *ap)
}
avio_seek(s->pb, -14, SEEK_CUR);
mxf->fc = s;
- while (!s->pb->eof_reached) {
+ while (!url_feof(s->pb)) {
const MXFMetadataReadTableEntry *metadata;
if (klv_read_packet(&klv, s->pb) < 0)
@@ -934,8 +1059,11 @@ static int mxf_read_header(AVFormatContext *s, AVFormatParameters *ap)
int res;
if (klv.key[5] == 0x53) {
res = mxf_read_local_tags(mxf, &klv, metadata->read, metadata->ctx_size, metadata->type);
- } else
- res = metadata->read(mxf, s->pb, 0, 0, NULL);
+ } else {
+ uint64_t next = avio_tell(s->pb) + klv.length;
+ res = metadata->read(mxf, s->pb, 0, 0, klv.key);
+ avio_seek(s->pb, next, SEEK_SET);
+ }
if (res < 0) {
av_log(s, AV_LOG_ERROR, "error reading header metadata\n");
return -1;
@@ -976,6 +1104,7 @@ static int mxf_read_close(AVFormatContext *s)
}
av_freep(&mxf->metadata_sets[i]);
}
+ av_freep(&mxf->partitions);
av_freep(&mxf->metadata_sets);
av_freep(&mxf->aesc);
av_freep(&mxf->local_tags);
@@ -1010,18 +1139,19 @@ static int mxf_read_seek(AVFormatContext *s, int stream_index, int64_t sample_ti
if (sample_time < 0)
sample_time = 0;
seconds = av_rescale(sample_time, st->time_base.num, st->time_base.den);
- avio_seek(s->pb, (s->bit_rate * seconds) >> 3, SEEK_SET);
+ if (avio_seek(s->pb, (s->bit_rate * seconds) >> 3, SEEK_SET) < 0)
+ return -1;
av_update_cur_dts(s, st, sample_time);
return 0;
}
AVInputFormat ff_mxf_demuxer = {
- "mxf",
- NULL_IF_CONFIG_SMALL("Material eXchange Format"),
- sizeof(MXFContext),
- mxf_probe,
- mxf_read_header,
- mxf_read_packet,
- mxf_read_close,
- mxf_read_seek,
+ .name = "mxf",
+ .long_name = NULL_IF_CONFIG_SMALL("Material eXchange Format"),
+ .priv_data_size = sizeof(MXFContext),
+ .read_probe = mxf_probe,
+ .read_header = mxf_read_header,
+ .read_packet = mxf_read_packet,
+ .read_close = mxf_read_close,
+ .read_seek = mxf_read_seek,
};
diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
index 16fa0dadd1..ce71ed2e51 100644
--- a/libavformat/mxfenc.c
+++ b/libavformat/mxfenc.c
@@ -3,20 +3,20 @@
* Copyright (c) 2008 GUCAS, Zhentan Feng <spyfeng at gmail dot com>
* Copyright (c) 2008 Baptiste Coudurier <baptiste dot coudurier at gmail dot com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -35,10 +35,13 @@
#include <math.h>
#include <time.h>
+#include "libavutil/opt.h"
#include "libavutil/random_seed.h"
#include "libavcodec/bytestream.h"
+#include "libavcodec/timecode.h"
#include "audiointerleave.h"
#include "avformat.h"
+#include "internal.h"
#include "mxf.h"
static const int NTSC_samples_per_frame[] = { 1602, 1601, 1602, 1601, 1602, 0 };
@@ -170,6 +173,7 @@ static const MXFContainerEssenceEntry mxf_essence_container_uls[] = {
};
typedef struct MXFContext {
+ AVClass *av_class;
int64_t footer_partition_offset;
int essence_container_count;
AVRational time_base;
@@ -183,10 +187,9 @@ typedef struct MXFContext {
unsigned body_partitions_count;
int last_key_index; ///< index of last key frame
uint64_t duration;
+ struct ff_timecode tc;
AVStream *timecode_track;
int timecode_base; ///< rounded time code base (25 or 30)
- int timecode_start; ///< frame number computed from mpeg-2 gop header timecode
- int timecode_drop_frame; ///< time code use drop frame method frop mpeg-2 essence gop header
int edit_unit_byte_count; ///< fixed edit unit byte count
uint64_t body_offset;
uint32_t instance_number;
@@ -499,7 +502,7 @@ static void mxf_write_identification(AVFormatContext *s)
{
MXFContext *mxf = s->priv_data;
AVIOContext *pb = s->pb;
- const char *company = "Libav";
+ const char *company = "FFmpeg";
const char *product = "OP1a Muxer";
const char *version;
int length;
@@ -664,7 +667,7 @@ static void mxf_write_timecode_component(AVFormatContext *s, AVStream *st, enum
// Start Time Code
mxf_write_local_tag(pb, 8, 0x1501);
- avio_wb64(pb, mxf->timecode_start);
+ avio_wb64(pb, mxf->tc.start);
// Rounded Time Code Base
mxf_write_local_tag(pb, 2, 0x1502);
@@ -672,7 +675,7 @@ static void mxf_write_timecode_component(AVFormatContext *s, AVStream *st, enum
// Drop Frame
mxf_write_local_tag(pb, 1, 0x1503);
- avio_w8(pb, mxf->timecode_drop_frame);
+ avio_w8(pb, mxf->tc.drop);
}
static void mxf_write_structural_component(AVFormatContext *s, AVStream *st, enum MXFMetadataSetType type)
@@ -1284,6 +1287,8 @@ static const UID mxf_mpeg2_codec_uls[] = {
{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x03,0x03,0x00 }, // MP-HL Long GOP
{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x04,0x02,0x00 }, // 422P-HL I-Frame
{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x04,0x03,0x00 }, // 422P-HL Long GOP
+ { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x05,0x02,0x00 }, // MP@H-14 I-Frame
+ { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x05,0x03,0x00 }, // MP@H-14 Long GOP
};
static const UID *mxf_get_mpeg2_codec_ul(AVCodecContext *avctx)
@@ -1295,6 +1300,8 @@ static const UID *mxf_get_mpeg2_codec_ul(AVCodecContext *avctx)
return &mxf_mpeg2_codec_uls[0+long_gop];
else if (avctx->level == 4) // High
return &mxf_mpeg2_codec_uls[4+long_gop];
+ else if (avctx->level == 6) // High 14
+ return &mxf_mpeg2_codec_uls[8+long_gop];
} else if (avctx->profile == 0) { // 422
if (avctx->level == 5) // Main
return &mxf_mpeg2_codec_uls[2+long_gop];
@@ -1308,7 +1315,6 @@ static int mxf_parse_mpeg2_frame(AVFormatContext *s, AVStream *st,
AVPacket *pkt, MXFIndexEntry *e)
{
MXFStreamContext *sc = st->priv_data;
- MXFContext *mxf = s->priv_data;
uint32_t c = -1;
int i;
@@ -1328,21 +1334,6 @@ static int mxf_parse_mpeg2_frame(AVFormatContext *s, AVStream *st,
if (e->flags & 0x40) // sequence header present
e->flags |= 0x80; // random access
}
- if (!mxf->header_written) {
- unsigned hours = (pkt->data[i+1]>>2) & 0x1f;
- unsigned minutes = ((pkt->data[i+1] & 0x03) << 4) | (pkt->data[i+2]>>4);
- unsigned seconds = ((pkt->data[i+2] & 0x07) << 3) | (pkt->data[i+3]>>5);
- unsigned frames = ((pkt->data[i+3] & 0x1f) << 1) | (pkt->data[i+4]>>7);
- mxf->timecode_drop_frame = !!(pkt->data[i+1] & 0x80);
- mxf->timecode_start = (hours*3600 + minutes*60 + seconds) *
- mxf->timecode_base + frames;
- if (mxf->timecode_drop_frame) {
- unsigned tminutes = 60 * hours + minutes;
- mxf->timecode_start -= 2 * (tminutes - tminutes / 10);
- }
- av_log(s, AV_LOG_DEBUG, "frame %d %d:%d:%d%c%d\n", mxf->timecode_start,
- hours, minutes, seconds, mxf->timecode_drop_frame ? ';':':', frames);
- }
} else if (c == 0x1b3) { // seq
e->flags |= 0x40;
switch ((pkt->data[i+4]>>4) & 0xf) {
@@ -1407,6 +1398,8 @@ static int mxf_write_header(AVFormatContext *s)
int i;
uint8_t present[FF_ARRAY_ELEMS(mxf_essence_container_uls)] = {0};
const int *samples_per_frame = NULL;
+ AVDictionaryEntry *t;
+ int64_t timestamp = 0;
if (!s->nb_streams)
return -1;
@@ -1436,6 +1429,12 @@ static int mxf_write_header(AVFormatContext *s)
return -1;
}
av_set_pts_info(st, 64, mxf->time_base.num, mxf->time_base.den);
+ if (mxf->tc.str) {
+ mxf->tc.rate.num = mxf->time_base.den;
+ mxf->tc.rate.den = mxf->time_base.num;
+ if (ff_init_smtpe_timecode(s, &mxf->tc) < 0)
+ return -1;
+ }
if (s->oformat == &ff_mxf_d10_muxer) {
if (st->codec->bit_rate == 50000000)
if (mxf->time_base.den == 25) sc->index = 3;
@@ -1512,8 +1511,15 @@ static int mxf_write_header(AVFormatContext *s)
sc->order = AV_RB32(sc->track_essence_element_key+12);
}
+#if FF_API_TIMESTAMP
if (s->timestamp)
- mxf->timestamp = mxf_parse_timestamp(s->timestamp);
+ timestamp = s->timestamp;
+ else
+#endif
+ if (t = av_dict_get(s->metadata, "creation_time", NULL, 0))
+ timestamp = ff_iso8601_to_unix_time(t->value);
+ if (timestamp)
+ mxf->timestamp = mxf_parse_timestamp(timestamp);
mxf->duration = -1;
mxf->timecode_track = av_mallocz(sizeof(*mxf->timecode_track));
@@ -1536,24 +1542,6 @@ static int mxf_write_header(AVFormatContext *s)
static const uint8_t system_metadata_pack_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x03,0x01,0x04,0x01,0x01,0x00 };
static const uint8_t system_metadata_package_set_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x43,0x01,0x01,0x0D,0x01,0x03,0x01,0x04,0x01,0x02,0x01 };
-static uint32_t ff_framenum_to_12m_time_code(unsigned frame, int drop, int fps)
-{
- return (0 << 31) | // color frame flag
- (drop << 30) | // drop frame flag
- ( ((frame % fps) / 10) << 28) | // tens of frames
- ( ((frame % fps) % 10) << 24) | // units of frames
- (0 << 23) | // field phase (NTSC), b0 (PAL)
- ((((frame / fps) % 60) / 10) << 20) | // tens of seconds
- ((((frame / fps) % 60) % 10) << 16) | // units of seconds
- (0 << 15) | // b0 (NTSC), b2 (PAL)
- ((((frame / (fps * 60)) % 60) / 10) << 12) | // tens of minutes
- ((((frame / (fps * 60)) % 60) % 10) << 8) | // units of minutes
- (0 << 7) | // b1
- (0 << 6) | // b2 (NTSC), field phase (PAL)
- ((((frame / (fps * 3600) % 24)) / 10) << 4) | // tens of hours
- ( (frame / (fps * 3600) % 24)) % 10; // units of hours
-}
-
static void mxf_write_system_item(AVFormatContext *s)
{
MXFContext *mxf = s->priv_data;
@@ -1561,7 +1549,7 @@ static void mxf_write_system_item(AVFormatContext *s)
unsigned frame;
uint32_t time_code;
- frame = mxf->timecode_start + mxf->last_indexed_edit_unit + mxf->edit_units_count;
+ frame = mxf->tc.start + mxf->last_indexed_edit_unit + mxf->edit_units_count;
// write system metadata pack
avio_write(pb, system_metadata_pack_key, 16);
@@ -1582,7 +1570,11 @@ static void mxf_write_system_item(AVFormatContext *s)
avio_wb64(pb, 0); // creation date/time stamp
avio_w8(pb, 0x81); // SMPTE 12M time code
- time_code = ff_framenum_to_12m_time_code(frame, mxf->timecode_drop_frame, mxf->timecode_base);
+ time_code = frame;
+ if (mxf->tc.drop)
+ time_code = ff_framenum_to_drop_timecode(time_code);
+ time_code = ff_framenum_to_smtpe_timecode(time_code, mxf->timecode_base,
+ mxf->tc.drop);
avio_wb32(pb, time_code);
avio_wb32(pb, 0); // binary group data
avio_wb64(pb, 0);
@@ -1879,34 +1871,53 @@ static int mxf_interleave(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int
mxf_interleave_get_packet, mxf_compare_timestamps);
}
+static const AVClass mxf_class = {
+ .class_name = "mxf",
+ .item_name = av_default_item_name,
+ .version = LIBAVUTIL_VERSION_INT,
+ .option = (const AVOption[]){
+ {TIMECODE_OPT(MXFContext, AV_OPT_FLAG_ENCODING_PARAM)},
+ {NULL}
+ },
+};
+
+static const AVClass mxf_d10_class = {
+ .class_name = "mxf_d10",
+ .item_name = av_default_item_name,
+ .version = LIBAVUTIL_VERSION_INT,
+ .option = (const AVOption[]){
+ {TIMECODE_OPT(MXFContext, AV_OPT_FLAG_ENCODING_PARAM)},
+ {NULL}
+ },
+};
+
AVOutputFormat ff_mxf_muxer = {
- "mxf",
- NULL_IF_CONFIG_SMALL("Material eXchange Format"),
- "application/mxf",
- "mxf",
- sizeof(MXFContext),
- CODEC_ID_PCM_S16LE,
- CODEC_ID_MPEG2VIDEO,
- mxf_write_header,
- mxf_write_packet,
- mxf_write_footer,
- AVFMT_NOTIMESTAMPS,
- NULL,
- mxf_interleave,
+ .name = "mxf",
+ .long_name = NULL_IF_CONFIG_SMALL("Material eXchange Format"),
+ .mime_type = "application/mxf",
+ .extensions = "mxf",
+ .priv_data_size = sizeof(MXFContext),
+ .audio_codec = CODEC_ID_PCM_S16LE,
+ .video_codec = CODEC_ID_MPEG2VIDEO,
+ .write_header = mxf_write_header,
+ .write_packet = mxf_write_packet,
+ .write_trailer = mxf_write_footer,
+ .flags = AVFMT_NOTIMESTAMPS,
+ .interleave_packet = mxf_interleave,
+ .priv_class = &mxf_class,
};
AVOutputFormat ff_mxf_d10_muxer = {
- "mxf_d10",
- NULL_IF_CONFIG_SMALL("Material eXchange Format, D-10 Mapping"),
- "application/mxf",
- NULL,
- sizeof(MXFContext),
- CODEC_ID_PCM_S16LE,
- CODEC_ID_MPEG2VIDEO,
- mxf_write_header,
- mxf_write_packet,
- mxf_write_footer,
- AVFMT_NOTIMESTAMPS,
- NULL,
- mxf_interleave,
+ .name = "mxf_d10",
+ .long_name = NULL_IF_CONFIG_SMALL("Material eXchange Format, D-10 Mapping"),
+ .mime_type = "application/mxf",
+ .priv_data_size = sizeof(MXFContext),
+ .audio_codec = CODEC_ID_PCM_S16LE,
+ .video_codec = CODEC_ID_MPEG2VIDEO,
+ .write_header = mxf_write_header,
+ .write_packet = mxf_write_packet,
+ .write_trailer = mxf_write_footer,
+ .flags = AVFMT_NOTIMESTAMPS,
+ .interleave_packet = mxf_interleave,
+ .priv_class = &mxf_d10_class,
};
diff --git a/libavformat/mxg.c b/libavformat/mxg.c
index 5caa68a667..04991b3530 100644
--- a/libavformat/mxg.c
+++ b/libavformat/mxg.c
@@ -2,20 +2,20 @@
* MxPEG clip file demuxer
* Copyright (c) 2010 Anatoly Nenashev
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -24,8 +24,6 @@
#include "avformat.h"
#include "avio.h"
-#define VIDEO_STREAM_INDEX 0
-#define AUDIO_STREAM_INDEX 1
#define DEFAULT_PACKET_SIZE 1024
#define OVERREAD_SIZE 3
@@ -44,14 +42,14 @@ static int mxg_read_header(AVFormatContext *s, AVFormatParameters *ap)
MXGContext *mxg = s->priv_data;
/* video parameters will be extracted from the compressed bitstream */
- video_st = av_new_stream(s, VIDEO_STREAM_INDEX);
+ video_st = avformat_new_stream(s, NULL);
if (!video_st)
return AVERROR(ENOMEM);
video_st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
video_st->codec->codec_id = CODEC_ID_MXPEG;
av_set_pts_info(video_st, 64, 1, 1000000);
- audio_st = av_new_stream(s, AUDIO_STREAM_INDEX);
+ audio_st = avformat_new_stream(s, NULL);
if (!audio_st)
return AVERROR(ENOMEM);
audio_st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
@@ -132,7 +130,7 @@ static int mxg_read_packet(AVFormatContext *s, AVPacket *pkt)
uint8_t *startmarker_ptr, *end, *search_end, marker;
MXGContext *mxg = s->priv_data;
- while (!s->pb->eof_reached && !s->pb->error){
+ while (!url_feof(s->pb) && !s->pb->error){
if (mxg->cache_size <= OVERREAD_SIZE) {
/* update internal buffer */
ret = mxg_update_cache(s, DEFAULT_PACKET_SIZE + OVERREAD_SIZE);
@@ -166,7 +164,7 @@ static int mxg_read_packet(AVFormatContext *s, AVPacket *pkt)
}
pkt->pts = pkt->dts = mxg->dts;
- pkt->stream_index = VIDEO_STREAM_INDEX;
+ pkt->stream_index = 0;
pkt->destruct = NULL;
pkt->size = mxg->buffer_ptr - mxg->soi_ptr;
pkt->data = mxg->soi_ptr;
@@ -204,7 +202,7 @@ static int mxg_read_packet(AVFormatContext *s, AVPacket *pkt)
if (marker == APP13 && size >= 16) { /* audio data */
/* time (GMT) of first sample in usec since 1970, little-endian */
pkt->pts = pkt->dts = AV_RL64(startmarker_ptr + 8);
- pkt->stream_index = AUDIO_STREAM_INDEX;
+ pkt->stream_index = 1;
pkt->destruct = NULL;
pkt->size = size - 14;
pkt->data = startmarker_ptr + 16;
diff --git a/libavformat/ncdec.c b/libavformat/ncdec.c
index 7e43adcd1e..3430035f3f 100644
--- a/libavformat/ncdec.c
+++ b/libavformat/ncdec.c
@@ -3,20 +3,20 @@
* Copyright (c) 2009 Nicolas Martin (martinic at iro dot umontreal dot ca)
* Edouard Auvinet
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -45,7 +45,7 @@ static int nc_probe(AVProbeData *probe_packet)
static int nc_read_header(AVFormatContext *s, AVFormatParameters *ap)
{
- AVStream *st = av_new_stream(s, 0);
+ AVStream *st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
@@ -66,7 +66,7 @@ static int nc_read_packet(AVFormatContext *s, AVPacket *pkt)
uint32_t state=-1;
while (state != NC_VIDEO_FLAG) {
- if (s->pb->eof_reached)
+ if (url_feof(s->pb))
return AVERROR(EIO);
state = (state<<8) + avio_r8(s->pb);
}
@@ -91,11 +91,10 @@ static int nc_read_packet(AVFormatContext *s, AVPacket *pkt)
}
AVInputFormat ff_nc_demuxer = {
- "nc",
- NULL_IF_CONFIG_SMALL("NC camera feed format"),
- 0,
- nc_probe,
- nc_read_header,
- nc_read_packet,
+ .name = "nc",
+ .long_name = NULL_IF_CONFIG_SMALL("NC camera feed format"),
+ .read_probe = nc_probe,
+ .read_header = nc_read_header,
+ .read_packet = nc_read_packet,
.extensions = "v",
};
diff --git a/libavformat/network.h b/libavformat/network.h
index 80d094a0de..f7e19b196e 100644
--- a/libavformat/network.h
+++ b/libavformat/network.h
@@ -1,20 +1,20 @@
/*
- * Copyright (c) 2007 The Libav Project
+ * Copyright (c) 2007 The FFmpeg Project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/nsvdec.c b/libavformat/nsvdec.c
index 4787331def..5de7512f99 100644
--- a/libavformat/nsvdec.c
+++ b/libavformat/nsvdec.c
@@ -1,21 +1,21 @@
/*
* NSV demuxer
- * Copyright (c) 2004 The Libav Project
+ * Copyright (c) 2004 The FFmpeg Project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -23,6 +23,7 @@
#include "avformat.h"
#include "riff.h"
#include "libavutil/dict.h"
+#include "libavutil/intreadwrite.h"
//#define DEBUG_DUMP_INDEX // XXX dumbdriving-271.nsv breaks with it commented!!
#define CHECK_SUBSEQUENT_NSVS
@@ -231,7 +232,7 @@ static int nsv_resync(AVFormatContext *s)
//nsv->state = NSV_UNSYNC;
for (i = 0; i < NSV_MAX_RESYNC; i++) {
- if (pb->eof_reached) {
+ if (url_feof(pb)) {
av_dlog(s, "NSV EOF\n");
nsv->state = NSV_UNSYNC;
return -1;
@@ -298,7 +299,7 @@ static int nsv_parse_NSVf_header(AVFormatContext *s, AVFormatParameters *ap)
table_entries_used = avio_rl32(pb);
av_dlog(s, "NSV NSVf info-strings size: %d, table entries: %d, bis %d\n",
strings_size, table_entries, table_entries_used);
- if (pb->eof_reached)
+ if (url_feof(pb))
return -1;
av_dlog(s, "NSV got header; filepos %"PRId64"\n", avio_tell(pb));
@@ -333,7 +334,7 @@ static int nsv_parse_NSVf_header(AVFormatContext *s, AVFormatParameters *ap)
}
av_free(strings);
}
- if (pb->eof_reached)
+ if (url_feof(pb))
return -1;
av_dlog(s, "NSV got infos; filepos %"PRId64"\n", avio_tell(pb));
@@ -380,7 +381,7 @@ static int nsv_parse_NSVf_header(AVFormatContext *s, AVFormatParameters *ap)
avio_seek(pb, nsv->base_offset + size, SEEK_SET); /* required for dumbdriving-271.nsv (2 extra bytes) */
- if (pb->eof_reached)
+ if (url_feof(pb))
return -1;
nsv->state = NSV_HAS_READ_NSVF;
return 0;
@@ -437,10 +438,11 @@ static int nsv_parse_NSVs_header(AVFormatContext *s, AVFormatParameters *ap)
nsv->vheight = vwidth;
if (vtag != T_NONE) {
int i;
- st = av_new_stream(s, NSV_ST_VIDEO);
+ st = avformat_new_stream(s, NULL);
if (!st)
goto fail;
+ st->id = NSV_ST_VIDEO;
nst = av_mallocz(sizeof(NSVStream));
if (!nst)
goto fail;
@@ -468,10 +470,11 @@ static int nsv_parse_NSVs_header(AVFormatContext *s, AVFormatParameters *ap)
}
if (atag != T_NONE) {
#ifndef DISABLE_AUDIO
- st = av_new_stream(s, NSV_ST_AUDIO);
+ st = avformat_new_stream(s, NULL);
if (!st)
goto fail;
+ st->id = NSV_ST_AUDIO;
nst = av_mallocz(sizeof(NSVStream));
if (!nst)
goto fail;
@@ -556,7 +559,7 @@ static int nsv_read_chunk(AVFormatContext *s, int fill_header)
return 0; //-1; /* hey! eat what you've in your plate first! */
null_chunk_retry:
- if (pb->eof_reached)
+ if (url_feof(pb))
return -1;
for (i = 0; i < NSV_MAX_RESYNC_TRIES && nsv->state < NSV_FOUND_NSVS && !err; i++)
@@ -590,7 +593,7 @@ null_chunk_retry:
vsize -= auxsize + sizeof(uint16_t) + sizeof(uint32_t); /* that's becoming braindead */
}
- if (pb->eof_reached)
+ if (url_feof(pb))
return -1;
if (!vsize && !asize) {
nsv->state = NSV_UNSYNC;
@@ -702,7 +705,9 @@ static int nsv_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp
if(index < 0)
return -1;
- avio_seek(s->pb, st->index_entries[index].pos, SEEK_SET);
+ if (avio_seek(s->pb, st->index_entries[index].pos, SEEK_SET) < 0)
+ return -1;
+
nst->frame_offset = st->index_entries[index].timestamp;
nsv->state = NSV_UNSYNC;
return 0;
@@ -738,10 +743,8 @@ static int nsv_read_close(AVFormatContext *s)
static int nsv_probe(AVProbeData *p)
{
- int i;
- int score;
- int vsize, asize, auxcount;
- score = 0;
+ int i, score = 0;
+
av_dlog(NULL, "nsv_probe(), buf_size %d\n", p->buf_size);
/* check file header */
/* streamed files might not have any header */
@@ -753,19 +756,14 @@ static int nsv_probe(AVProbeData *p)
/* seems the servers don't bother starting clean chunks... */
/* sometimes even the first header is at 9KB or something :^) */
for (i = 1; i < p->buf_size - 3; i++) {
- if (p->buf[i+0] == 'N' && p->buf[i+1] == 'S' &&
- p->buf[i+2] == 'V' && p->buf[i+3] == 's') {
- score = AVPROBE_SCORE_MAX/5;
+ if (AV_RL32(p->buf + i) == AV_RL32("NSVs")) {
/* Get the chunk size and check if at the end we are getting 0xBEEF */
- auxcount = p->buf[i+19];
- vsize = p->buf[i+20] | p->buf[i+21] << 8;
- asize = p->buf[i+22] | p->buf[i+23] << 8;
- vsize = (vsize << 4) | (auxcount >> 4);
- if ((asize + vsize + i + 23) < p->buf_size - 2) {
- if (p->buf[i+23+asize+vsize+1] == 0xEF &&
- p->buf[i+23+asize+vsize+2] == 0xBE)
- return AVPROBE_SCORE_MAX-20;
- }
+ int vsize = AV_RL24(p->buf+i+19) >> 4;
+ int asize = AV_RL16(p->buf+i+22);
+ int offset = i + 23 + asize + vsize + 1;
+ if (offset <= p->buf_size - 2 && AV_RL16(p->buf + offset) == 0xBEEF)
+ return 4*AVPROBE_SCORE_MAX/5;
+ score = AVPROBE_SCORE_MAX/5;
}
}
/* so we'll have more luck on extension... */
@@ -776,12 +774,12 @@ static int nsv_probe(AVProbeData *p)
}
AVInputFormat ff_nsv_demuxer = {
- "nsv",
- NULL_IF_CONFIG_SMALL("Nullsoft Streaming Video"),
- sizeof(NSVContext),
- nsv_probe,
- nsv_read_header,
- nsv_read_packet,
- nsv_read_close,
- nsv_read_seek,
+ .name = "nsv",
+ .long_name = NULL_IF_CONFIG_SMALL("Nullsoft Streaming Video"),
+ .priv_data_size = sizeof(NSVContext),
+ .read_probe = nsv_probe,
+ .read_header = nsv_read_header,
+ .read_packet = nsv_read_packet,
+ .read_close = nsv_read_close,
+ .read_seek = nsv_read_seek,
};
diff --git a/libavformat/nullenc.c b/libavformat/nullenc.c
index 8e38b278b1..2ab92dff75 100644
--- a/libavformat/nullenc.c
+++ b/libavformat/nullenc.c
@@ -2,20 +2,20 @@
* RAW null muxer
* Copyright (c) 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -27,14 +27,10 @@ static int null_write_packet(struct AVFormatContext *s, AVPacket *pkt)
}
AVOutputFormat ff_null_muxer = {
- "null",
- NULL_IF_CONFIG_SMALL("raw null video format"),
- NULL,
- NULL,
- 0,
- AV_NE(CODEC_ID_PCM_S16BE, CODEC_ID_PCM_S16LE),
- CODEC_ID_RAWVIDEO,
- NULL,
- null_write_packet,
+ .name = "null",
+ .long_name = NULL_IF_CONFIG_SMALL("raw null video format"),
+ .audio_codec = AV_NE(CODEC_ID_PCM_S16BE, CODEC_ID_PCM_S16LE),
+ .video_codec = CODEC_ID_RAWVIDEO,
+ .write_packet = null_write_packet,
.flags = AVFMT_NOFILE | AVFMT_RAWPICTURE | AVFMT_NOTIMESTAMPS,
};
diff --git a/libavformat/nut.c b/libavformat/nut.c
index 1ce048d645..2a5e6fe567 100644
--- a/libavformat/nut.c
+++ b/libavformat/nut.c
@@ -2,20 +2,20 @@
* nut
* Copyright (c) 2004-2007 Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/nut.h b/libavformat/nut.h
index 419b123bee..033bc0898e 100644
--- a/libavformat/nut.h
+++ b/libavformat/nut.h
@@ -2,20 +2,20 @@
* "NUT" Container Format (de)muxer
* Copyright (c) 2006 Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/nutdec.c b/libavformat/nutdec.c
index 93888a2bd6..6015bf6900 100644
--- a/libavformat/nutdec.c
+++ b/libavformat/nutdec.c
@@ -3,20 +3,20 @@
* Copyright (c) 2004-2006 Michael Niedermayer
* Copyright (c) 2003 Alex Beregszaszi
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -120,7 +120,7 @@ static uint64_t find_any_startcode(AVIOContext *bc, int64_t pos){
if(pos >= 0)
avio_seek(bc, pos, SEEK_SET); //note, this may fail if the stream is not seekable, but that should not matter, as in this case we simply start where we currently are
- while(!bc->eof_reached){
+ while(!url_feof(bc)){
state= (state<<8) | avio_r8(bc);
if((state>>56) != 'N')
continue;
@@ -288,7 +288,7 @@ static int decode_main_header(NUTContext *nut){
nut->stream = av_mallocz(sizeof(StreamContext)*stream_count);
for(i=0; i<stream_count; i++){
- av_new_stream(s, i);
+ avformat_new_stream(s, NULL);
}
return 0;
@@ -416,7 +416,7 @@ static int decode_info_header(NUTContext *nut){
if(chapter_id && !stream_id_plus1){
int64_t start= chapter_start / nut->time_base_count;
- chapter= ff_new_chapter(s, chapter_id,
+ chapter= avpriv_new_chapter(s, chapter_id,
nut->time_base[chapter_start % nut->time_base_count],
start, start + chapter_len, NULL);
metadata = &chapter->metadata;
@@ -787,7 +787,7 @@ static int nut_read_packet(AVFormatContext *s, AVPacket *pkt)
pos-=8;
}else{
frame_code = avio_r8(bc);
- if(bc->eof_reached)
+ if(url_feof(bc))
return -1;
if(frame_code == 'N'){
tmp= frame_code;
@@ -924,14 +924,14 @@ static int nut_read_close(AVFormatContext *s)
#if CONFIG_NUT_DEMUXER
AVInputFormat ff_nut_demuxer = {
- "nut",
- NULL_IF_CONFIG_SMALL("NUT format"),
- sizeof(NUTContext),
- nut_probe,
- nut_read_header,
- nut_read_packet,
- nut_read_close,
- read_seek,
+ .name = "nut",
+ .long_name = NULL_IF_CONFIG_SMALL("NUT format"),
+ .priv_data_size = sizeof(NUTContext),
+ .read_probe = nut_probe,
+ .read_header = nut_read_header,
+ .read_packet = nut_read_packet,
+ .read_close = nut_read_close,
+ .read_seek = read_seek,
.extensions = "nut",
.codec_tag = (const AVCodecTag * const []) { ff_codec_bmp_tags, ff_nut_video_tags, ff_codec_wav_tags, ff_nut_subtitle_tags, 0 },
};
diff --git a/libavformat/nutenc.c b/libavformat/nutenc.c
index 412c670387..3c963debd6 100644
--- a/libavformat/nutenc.c
+++ b/libavformat/nutenc.c
@@ -2,20 +2,20 @@
* nut muxer
* Copyright (c) 2004-2007 Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -59,10 +59,10 @@ static int find_expected_header(AVCodecContext *c, int size, int key_frame, uint
else if(sample_rate < (44100 + 48000)/2) sample_rate_index=0;
else sample_rate_index=1;
- sample_rate= ff_mpa_freq_tab[sample_rate_index] >> (lsf + mpeg25);
+ sample_rate= avpriv_mpa_freq_tab[sample_rate_index] >> (lsf + mpeg25);
for(bitrate_index=2; bitrate_index<30; bitrate_index++){
- frame_size = ff_mpa_bitrate_tab[lsf][layer-1][bitrate_index>>1];
+ frame_size = avpriv_mpa_bitrate_tab[lsf][layer-1][bitrate_index>>1];
frame_size = (frame_size * 144000) / (sample_rate << lsf) + (bitrate_index&1);
if(frame_size == size)
@@ -177,6 +177,7 @@ static void build_frame_code(AVFormatContext *s){
}
key_frame= intra_only;
+#if 1
if(is_audio){
int frame_bytes= codec->frame_size*(int64_t)codec->bit_rate / (8*codec->sample_rate);
int pts;
@@ -200,6 +201,7 @@ static void build_frame_code(AVFormatContext *s){
ft->pts_delta=1;
start2++;
}
+#endif
if(codec->has_b_frames){
pred_count=5;
@@ -578,7 +580,7 @@ static int write_headers(AVFormatContext *avctx, AVIOContext *bc){
return 0;
}
-static int write_header(AVFormatContext *s){
+static int nut_write_header(AVFormatContext *s){
NUTContext *nut = s->priv_data;
AVIOContext *bc = s->pb;
int i, j, ret;
@@ -586,11 +588,10 @@ static int write_header(AVFormatContext *s){
nut->avf= s;
nut->stream = av_mallocz(sizeof(StreamContext)*s->nb_streams);
- if (s->nb_chapters)
- nut->chapter = av_mallocz(sizeof(ChapterContext)*s->nb_chapters);
+ nut->chapter = av_mallocz(sizeof(ChapterContext)*s->nb_chapters);
nut->time_base= av_mallocz(sizeof(AVRational )*(s->nb_streams +
s->nb_chapters));
- if (!nut->stream || (s->nb_chapters && !nut->chapter) || !nut->time_base) {
+ if (!nut->stream || !nut->chapter || !nut->time_base) {
av_freep(&nut->stream);
av_freep(&nut->chapter);
av_freep(&nut->time_base);
@@ -691,7 +692,7 @@ static int find_best_header_idx(NUTContext *nut, AVPacket *pkt){
return best_i;
}
-static int write_packet(AVFormatContext *s, AVPacket *pkt){
+static int nut_write_packet(AVFormatContext *s, AVPacket *pkt){
NUTContext *nut = s->priv_data;
StreamContext *nus= &nut->stream[pkt->stream_index];
AVIOContext *bc = s->pb, *dyn_bc;
@@ -845,7 +846,7 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt){
return 0;
}
-static int write_trailer(AVFormatContext *s){
+static int nut_write_trailer(AVFormatContext *s){
NUTContext *nut= s->priv_data;
AVIOContext *bc= s->pb;
@@ -861,22 +862,22 @@ static int write_trailer(AVFormatContext *s){
}
AVOutputFormat ff_nut_muxer = {
- "nut",
- NULL_IF_CONFIG_SMALL("NUT format"),
- "video/x-nut",
- "nut",
- sizeof(NUTContext),
+ .name = "nut",
+ .long_name = NULL_IF_CONFIG_SMALL("NUT format"),
+ .mime_type = "video/x-nut",
+ .extensions = "nut",
+ .priv_data_size = sizeof(NUTContext),
#if CONFIG_LIBVORBIS
- CODEC_ID_VORBIS,
+ .audio_codec = CODEC_ID_VORBIS,
#elif CONFIG_LIBMP3LAME
- CODEC_ID_MP3,
+ .audio_codec = CODEC_ID_MP3,
#else
- CODEC_ID_MP2,
+ .audio_codec = CODEC_ID_MP2,
#endif
- CODEC_ID_MPEG4,
- write_header,
- write_packet,
- write_trailer,
+ .video_codec = CODEC_ID_MPEG4,
+ .write_header = nut_write_header,
+ .write_packet = nut_write_packet,
+ .write_trailer = nut_write_trailer,
.flags = AVFMT_GLOBALHEADER | AVFMT_VARIABLE_FPS,
.codec_tag = (const AVCodecTag * const []){ ff_codec_bmp_tags, ff_nut_video_tags, ff_codec_wav_tags, ff_nut_subtitle_tags, 0 },
};
diff --git a/libavformat/nuv.c b/libavformat/nuv.c
index 854aadd990..caf85b0ef8 100644
--- a/libavformat/nuv.c
+++ b/libavformat/nuv.c
@@ -2,20 +2,20 @@
* NuppelVideo demuxer.
* Copyright (c) 2006 Reimar Doeffinger
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -61,7 +61,7 @@ static int get_codec_data(AVIOContext *pb, AVStream *vst,
nuv_frametype frametype;
if (!vst && !myth)
return 1; // no codec data needed
- while (!pb->eof_reached) {
+ while (!url_feof(pb)) {
int size, subtype;
frametype = avio_r8(pb);
switch (frametype) {
@@ -153,7 +153,7 @@ static int nuv_header(AVFormatContext *s, AVFormatParameters *ap) {
if (v_packs) {
ctx->v_id = stream_nr++;
- vst = av_new_stream(s, ctx->v_id);
+ vst = avformat_new_stream(s, NULL);
if (!vst)
return AVERROR(ENOMEM);
vst->codec->codec_type = AVMEDIA_TYPE_VIDEO;
@@ -169,7 +169,7 @@ static int nuv_header(AVFormatContext *s, AVFormatParameters *ap) {
if (a_packs) {
ctx->a_id = stream_nr++;
- ast = av_new_stream(s, ctx->a_id);
+ ast = avformat_new_stream(s, NULL);
if (!ast)
return AVERROR(ENOMEM);
ast->codec->codec_type = AVMEDIA_TYPE_AUDIO;
@@ -196,7 +196,7 @@ static int nuv_packet(AVFormatContext *s, AVPacket *pkt) {
uint8_t hdr[HDRSIZE];
nuv_frametype frametype;
int ret, size;
- while (!pb->eof_reached) {
+ while (!url_feof(pb)) {
int copyhdrsize = ctx->rtjpg_video ? HDRSIZE : 0;
uint64_t pos = avio_tell(pb);
ret = avio_read(pb, hdr, HDRSIZE);
@@ -219,10 +219,9 @@ static int nuv_packet(AVFormatContext *s, AVPacket *pkt) {
ret = av_new_packet(pkt, copyhdrsize + size);
if (ret < 0)
return ret;
- // HACK: we have no idea if it is a keyframe,
- // but if we mark none seeking will not work at all.
- pkt->flags |= AV_PKT_FLAG_KEY;
+
pkt->pos = pos;
+ pkt->flags |= hdr[2] == 0 ? AV_PKT_FLAG_KEY : 0;
pkt->pts = AV_RL32(&hdr[4]);
pkt->stream_index = ctx->v_id;
memcpy(pkt->data, hdr, copyhdrsize);
@@ -258,14 +257,88 @@ static int nuv_packet(AVFormatContext *s, AVPacket *pkt) {
return AVERROR(EIO);
}
+/**
+ * \brief looks for the string RTjjjjjjjjjj in the stream too resync reading
+ * \return 1 if the syncword is found 0 otherwise.
+ */
+static int nuv_resync(AVFormatContext *s, int64_t pos_limit) {
+ AVIOContext *pb = s->pb;
+ uint32_t tag = 0;
+ while(!url_feof(pb) && avio_tell(pb) < pos_limit) {
+ tag = (tag << 8) | avio_r8(pb);
+ if (tag == MKBETAG('R','T','j','j') &&
+ (tag = avio_rb32(pb)) == MKBETAG('j','j','j','j') &&
+ (tag = avio_rb32(pb)) == MKBETAG('j','j','j','j'))
+ return 1;
+ }
+ return 0;
+}
+
+/**
+ * \brief attempts to read a timestamp from stream at the given stream position
+ * \return timestamp if successfull and AV_NOPTS_VALUE if failure
+ */
+static int64_t nuv_read_dts(AVFormatContext *s, int stream_index,
+ int64_t *ppos, int64_t pos_limit)
+{
+ NUVContext *ctx = s->priv_data;
+ AVIOContext *pb = s->pb;
+ uint8_t hdr[HDRSIZE];
+ nuv_frametype frametype;
+ int size, key, idx;
+ int64_t pos, dts;
+
+ if (avio_seek(pb, *ppos, SEEK_SET) < 0)
+ return AV_NOPTS_VALUE;
+
+ if (!nuv_resync(s, pos_limit))
+ return AV_NOPTS_VALUE;
+
+ while (!url_feof(pb) && avio_tell(pb) < pos_limit) {
+ if (avio_read(pb, hdr, HDRSIZE) < HDRSIZE)
+ return AV_NOPTS_VALUE;
+ frametype = hdr[0];
+ size = PKTSIZE(AV_RL32(&hdr[8]));
+ switch (frametype) {
+ case NUV_SEEKP:
+ break;
+ case NUV_AUDIO:
+ case NUV_VIDEO:
+ if (frametype == NUV_VIDEO) {
+ idx = ctx->v_id;
+ key = hdr[2] == 0;
+ } else {
+ idx = ctx->a_id;
+ key = 1;
+ }
+ if (stream_index == idx) {
+
+ pos = avio_tell(s->pb) - HDRSIZE;
+ dts = AV_RL32(&hdr[4]);
+
+ // TODO - add general support in av_gen_search, so it adds positions after reading timestamps
+ av_add_index_entry(s->streams[stream_index], pos, dts, size + HDRSIZE, 0,
+ key ? AVINDEX_KEYFRAME : 0);
+
+ *ppos = pos;
+ return dts;
+ }
+ default:
+ avio_skip(pb, size);
+ break;
+ }
+ }
+ return AV_NOPTS_VALUE;
+}
+
+
AVInputFormat ff_nuv_demuxer = {
- "nuv",
- NULL_IF_CONFIG_SMALL("NuppelVideo format"),
- sizeof(NUVContext),
- nuv_probe,
- nuv_header,
- nuv_packet,
- NULL,
- NULL,
+ .name = "nuv",
+ .long_name = NULL_IF_CONFIG_SMALL("NuppelVideo format"),
+ .priv_data_size = sizeof(NUVContext),
+ .read_probe = nuv_probe,
+ .read_header = nuv_header,
+ .read_packet = nuv_packet,
+ .read_timestamp = nuv_read_dts,
.flags = AVFMT_GENERIC_INDEX,
};
diff --git a/libavformat/oggdec.c b/libavformat/oggdec.c
index e33de7d978..8e7653c6b8 100644
--- a/libavformat/oggdec.c
+++ b/libavformat/oggdec.c
@@ -29,7 +29,6 @@
DEALINGS IN THE SOFTWARE.
**/
-
#include <stdio.h>
#include "oggdec.h"
#include "avformat.h"
@@ -45,6 +44,7 @@ static const struct ogg_codec * const ogg_codecs[] = {
&ff_vorbis_codec,
&ff_theora_codec,
&ff_flac_codec,
+ &ff_celt_codec,
&ff_old_dirac_codec,
&ff_old_flac_codec,
&ff_ogm_video_codec,
@@ -92,14 +92,24 @@ static int ogg_restore(AVFormatContext *s, int discard)
ogg->state = ost->next;
if (!discard){
+ struct ogg_stream *old_streams = ogg->streams;
+
for (i = 0; i < ogg->nstreams; i++)
av_free (ogg->streams[i].buf);
avio_seek (bc, ost->pos, SEEK_SET);
ogg->curidx = ost->curidx;
ogg->nstreams = ost->nstreams;
- memcpy(ogg->streams, ost->streams,
- ost->nstreams * sizeof(*ogg->streams));
+ ogg->streams = av_realloc (ogg->streams,
+ ogg->nstreams * sizeof (*ogg->streams));
+
+ if (ogg->streams) {
+ memcpy(ogg->streams, ost->streams,
+ ost->nstreams * sizeof(*ogg->streams));
+ } else {
+ av_free(old_streams);
+ ogg->nstreams = 0;
+ }
}
av_free (ost);
@@ -161,10 +171,11 @@ static int ogg_new_stream(AVFormatContext *s, uint32_t serial, int new_avstream)
os->header = -1;
if (new_avstream) {
- st = av_new_stream(s, idx);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
+ st->id = idx;
av_set_pts_info(st, 64, 1, 1000000);
}
@@ -213,7 +224,7 @@ static int ogg_read_page(AVFormatContext *s, int *str)
break;
c = avio_r8(bc);
- if (bc->eof_reached)
+ if (url_feof(bc))
return AVERROR_EOF;
sync[sp++ & 3] = c;
}while (i++ < MAX_PAGE_SIZE);
@@ -361,8 +372,6 @@ static int ogg_packet(AVFormatContext *s, int *str, int *dstart, int *dsize,
}
}while (!complete);
- av_dlog(s, "ogg_packet: idx %i, frame size %i, start %i\n",
- idx, os->psize, os->pstart);
if (os->granule == -1)
av_log(s, AV_LOG_WARNING, "Page at %"PRId64" is missing granule\n", os->page_pos);
@@ -412,6 +421,8 @@ static int ogg_packet(AVFormatContext *s, int *str, int *dstart, int *dsize,
*fpos = os->sync_pos;
os->pstart += os->psize;
os->psize = 0;
+ if(os->pstart == os->bufpos)
+ os->bufpos = os->pstart = 0;
os->sync_pos = os->page_pos;
}
@@ -451,6 +462,7 @@ static int ogg_get_length(AVFormatContext *s)
struct ogg *ogg = s->priv_data;
int i;
int64_t size, end;
+ int streams_left=0;
if(!s->pb->seekable)
return 0;
@@ -472,13 +484,37 @@ static int ogg_get_length(AVFormatContext *s)
ogg->streams[i].codec) {
s->streams[i]->duration =
ogg_gptopts (s, i, ogg->streams[i].granule, NULL);
- if (s->streams[i]->start_time != AV_NOPTS_VALUE)
+ if (s->streams[i]->start_time != AV_NOPTS_VALUE){
s->streams[i]->duration -= s->streams[i]->start_time;
+ streams_left-= (ogg->streams[i].got_start==-1);
+ ogg->streams[i].got_start= 1;
+ }else if(!ogg->streams[i].got_start){
+ ogg->streams[i].got_start= -1;
+ streams_left++;
+ }
}
}
ogg_restore (s, 0);
+ ogg_save (s);
+ avio_seek (s->pb, 0, SEEK_SET);
+ while (!ogg_read_page (s, &i)){
+ if (ogg->streams[i].granule != -1 && ogg->streams[i].granule != 0 &&
+ ogg->streams[i].codec) {
+ if(s->streams[i]->duration && s->streams[i]->start_time == AV_NOPTS_VALUE && !ogg->streams[i].got_start){
+ int64_t start= ogg_gptopts (s, i, ogg->streams[i].granule, NULL);
+ if(av_rescale_q(start, s->streams[i]->time_base, AV_TIME_BASE_Q) > AV_TIME_BASE)
+ s->streams[i]->duration -= start;
+ ogg->streams[i].got_start= 1;
+ streams_left--;
+ }
+ if(streams_left<=0)
+ break;
+ }
+ }
+ ogg_restore (s, 0);
+
return 0;
}
@@ -592,15 +628,15 @@ static int64_t ogg_read_timestamp(AVFormatContext *s, int stream_index,
int64_t *pos_arg, int64_t pos_limit)
{
struct ogg *ogg = s->priv_data;
- struct ogg_stream *os = ogg->streams + stream_index;
AVIOContext *bc = s->pb;
int64_t pts = AV_NOPTS_VALUE;
- int i;
+ int i = -1;
avio_seek(bc, *pos_arg, SEEK_SET);
ogg_reset(ogg);
while (avio_tell(bc) < pos_limit && !ogg_packet(s, &i, NULL, NULL, pos_arg)) {
if (i == stream_index) {
+ struct ogg_stream *os = ogg->streams + stream_index;
pts = ogg_calc_pts(s, i, NULL);
if (os->keyframe_seek && !(os->pflags & AV_PKT_FLAG_KEY))
pts = AV_NOPTS_VALUE;
@@ -626,6 +662,7 @@ static int ogg_read_seek(AVFormatContext *s, int stream_index,
os->keyframe_seek = 1;
ret = av_seek_frame_binary(s, stream_index, timestamp, flags);
+ os = ogg->streams + stream_index;
if (ret < 0)
os->keyframe_seek = 0;
return ret;
diff --git a/libavformat/oggdec.h b/libavformat/oggdec.h
index e7d1022734..7f5452f2b0 100644
--- a/libavformat/oggdec.h
+++ b/libavformat/oggdec.h
@@ -75,6 +75,7 @@ struct ogg_stream {
int incomplete; ///< whether we're expecting a continuation in the next page
int page_end; ///< current packet is the last one completed in the page
int keyframe_seek;
+ int got_start;
void *private;
};
@@ -98,6 +99,7 @@ struct ogg {
#define OGG_FLAG_BOS 2
#define OGG_FLAG_EOS 4
+extern const struct ogg_codec ff_celt_codec;
extern const struct ogg_codec ff_dirac_codec;
extern const struct ogg_codec ff_flac_codec;
extern const struct ogg_codec ff_ogm_audio_codec;
diff --git a/libavformat/oggenc.c b/libavformat/oggenc.c
index 2b2189c10e..53350719fa 100644
--- a/libavformat/oggenc.c
+++ b/libavformat/oggenc.c
@@ -2,24 +2,25 @@
* Ogg muxer
* Copyright (c) 2007 Baptiste Coudurier <baptiste dot coudurier at free dot fr>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/crc.h"
+#include "libavutil/opt.h"
#include "libavutil/mathematics.h"
#include "libavutil/random_seed.h"
#include "libavcodec/xiph.h"
@@ -63,9 +64,26 @@ typedef struct OGGPageList {
} OGGPageList;
typedef struct {
+ const AVClass *class;
OGGPageList *page_list;
+ int pref_size; ///< preferred page size (0 => fill all segments)
} OGGContext;
+
+static const AVOption options[] = {
+ { "oggpagesize", "Set preferred Ogg page size.",
+ offsetof(OGGContext, pref_size), AV_OPT_TYPE_INT, {.dbl = 0}, 0, MAX_PAGE_SIZE, AV_OPT_FLAG_ENCODING_PARAM},
+ { NULL },
+};
+
+static const AVClass ogg_muxer_class = {
+ "Ogg muxer",
+ av_default_item_name,
+ options,
+ LIBAVUTIL_VERSION_INT,
+};
+
+
static void ogg_update_checksum(AVFormatContext *s, AVIOContext *pb, int64_t crc_offset)
{
int64_t pos = avio_tell(pb);
@@ -175,6 +193,7 @@ static int ogg_buffer_data(AVFormatContext *s, AVStream *st,
uint8_t *data, unsigned size, int64_t granule)
{
OGGStreamContext *oggstream = st->priv_data;
+ OGGContext *ogg = s->priv_data;
int total_segments = size / 255 + 1;
uint8_t *p = data;
int i, segments, len, flush = 0;
@@ -210,8 +229,9 @@ static int ogg_buffer_data(AVFormatContext *s, AVStream *st,
if (i == total_segments)
page->granule = granule;
- if (page->segments_count == 255) {
- ogg_buffer_page(s, oggstream);
+ if(page->segments_count == 255 ||
+ (ogg->pref_size > 0 && page->size >= ogg->pref_size)) {
+ ogg_buffer_page(s, oggstream);
}
}
@@ -254,7 +274,7 @@ static int ogg_build_flac_headers(AVCodecContext *avctx,
uint8_t *streaminfo;
uint8_t *p;
- if (!ff_flac_is_extradata_valid(avctx, &format, &streaminfo))
+ if (!avpriv_flac_is_extradata_valid(avctx, &format, &streaminfo))
return -1;
// first packet: STREAMINFO
@@ -377,7 +397,7 @@ static int ogg_write_header(AVFormatContext *s)
int header_type = st->codec->codec_id == CODEC_ID_VORBIS ? 3 : 0x81;
int framing_bit = st->codec->codec_id == CODEC_ID_VORBIS ? 1 : 0;
- if (ff_split_xiph_headers(st->codec->extradata, st->codec->extradata_size,
+ if (avpriv_split_xiph_headers(st->codec->extradata, st->codec->extradata_size,
st->codec->codec_id == CODEC_ID_VORBIS ? 30 : 42,
oggstream->header, oggstream->header_len) < 0) {
av_log(s, AV_LOG_ERROR, "Extradata corrupted\n");
@@ -496,23 +516,26 @@ static int ogg_write_trailer(AVFormatContext *s)
OGGStreamContext *oggstream = st->priv_data;
if (st->codec->codec_id == CODEC_ID_FLAC ||
st->codec->codec_id == CODEC_ID_SPEEX) {
- av_free(oggstream->header[0]);
- av_free(oggstream->header[1]);
+ av_freep(&oggstream->header[0]);
+ av_freep(&oggstream->header[1]);
}
+ else
+ av_freep(&oggstream->header[1]);
av_freep(&st->priv_data);
}
return 0;
}
AVOutputFormat ff_ogg_muxer = {
- "ogg",
- NULL_IF_CONFIG_SMALL("Ogg"),
- "application/ogg",
- "ogg,ogv,spx",
- sizeof(OGGContext),
- CODEC_ID_FLAC,
- CODEC_ID_THEORA,
- ogg_write_header,
- ogg_write_packet,
- ogg_write_trailer,
+ .name = "ogg",
+ .long_name = NULL_IF_CONFIG_SMALL("Ogg"),
+ .mime_type = "application/ogg",
+ .extensions = "ogg,ogv,spx",
+ .priv_data_size = sizeof(OGGContext),
+ .audio_codec = CODEC_ID_FLAC,
+ .video_codec = CODEC_ID_THEORA,
+ .write_header = ogg_write_header,
+ .write_packet = ogg_write_packet,
+ .write_trailer = ogg_write_trailer,
+ .priv_class = &ogg_muxer_class,
};
diff --git a/libavformat/oggparsecelt.c b/libavformat/oggparsecelt.c
new file mode 100644
index 0000000000..0af6fccfa2
--- /dev/null
+++ b/libavformat/oggparsecelt.c
@@ -0,0 +1,95 @@
+/*
+ * Xiph CELT / Opus parser for Ogg
+ * Copyright (c) 2011 Nicolas George
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <string.h>
+
+#include "libavutil/intreadwrite.h"
+#include "avformat.h"
+#include "oggdec.h"
+
+struct oggcelt_private {
+ int extra_headers_left;
+};
+
+static int celt_header(AVFormatContext *s, int idx)
+{
+ struct ogg *ogg = s->priv_data;
+ struct ogg_stream *os = ogg->streams + idx;
+ AVStream *st = s->streams[idx];
+ struct oggcelt_private *priv = os->private;
+ uint8_t *p = os->buf + os->pstart;
+
+ if (os->psize == 60 &&
+ !memcmp(p, ff_celt_codec.magic, ff_celt_codec.magicsize)) {
+ /* Main header */
+
+ uint32_t version, sample_rate, nb_channels, frame_size;
+ uint32_t overlap, extra_headers;
+ uint8_t *extradata;
+
+ extradata = av_malloc(2 * sizeof(uint32_t) +
+ FF_INPUT_BUFFER_PADDING_SIZE);
+ priv = av_malloc(sizeof(struct oggcelt_private));
+ if (!extradata || !priv) {
+ av_free(extradata);
+ av_free(priv);
+ return AVERROR(ENOMEM);
+ }
+ version = AV_RL32(p + 28);
+ /* unused header size field skipped */
+ sample_rate = AV_RL32(p + 36);
+ nb_channels = AV_RL32(p + 40);
+ frame_size = AV_RL32(p + 44);
+ overlap = AV_RL32(p + 48);
+ /* unused bytes per packet field skipped */
+ extra_headers = AV_RL32(p + 56);
+ st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
+ st->codec->codec_id = CODEC_ID_CELT;
+ st->codec->sample_rate = sample_rate;
+ st->codec->channels = nb_channels;
+ st->codec->frame_size = frame_size;
+ av_free(st->codec->extradata);
+ st->codec->extradata = extradata;
+ st->codec->extradata_size = 2 * sizeof(uint32_t);
+ if (sample_rate)
+ av_set_pts_info(st, 64, 1, sample_rate);
+ priv->extra_headers_left = 1 + extra_headers;
+ av_free(os->private);
+ os->private = priv;
+ AV_WL32(extradata + 0, overlap);
+ AV_WL32(extradata + 4, version);
+ return 1;
+ } else if (priv && priv->extra_headers_left) {
+ /* Extra headers (vorbiscomment) */
+
+ ff_vorbis_comment(s, &st->metadata, p, os->psize);
+ priv->extra_headers_left--;
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+const struct ogg_codec ff_celt_codec = {
+ .magic = "CELT ",
+ .magicsize = 8,
+ .header = celt_header,
+};
diff --git a/libavformat/oggparsedirac.c b/libavformat/oggparsedirac.c
index f6afafd0e4..524736a416 100644
--- a/libavformat/oggparsedirac.c
+++ b/libavformat/oggparsedirac.c
@@ -1,20 +1,20 @@
/*
* Copyright (C) 2008 David Conrad
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -36,7 +36,7 @@ static int dirac_header(AVFormatContext *s, int idx)
return 0;
init_get_bits(&gb, os->buf + os->pstart + 13, (os->psize - 13) * 8);
- if (ff_dirac_parse_sequence_header(st->codec, &gb, &source) < 0)
+ if (avpriv_dirac_parse_sequence_header(st->codec, &gb, &source) < 0)
return -1;
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
diff --git a/libavformat/oggparseflac.c b/libavformat/oggparseflac.c
index 53cd0fa582..87239c6a53 100644
--- a/libavformat/oggparseflac.c
+++ b/libavformat/oggparseflac.c
@@ -1,20 +1,20 @@
/*
* Copyright (C) 2005 Matthieu CASTET
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -55,7 +55,7 @@ flac_header (AVFormatContext * s, int idx)
if (get_bits_long(&gb, 32) != FLAC_STREAMINFO_SIZE)
return -1;
- ff_flac_parse_streaminfo(st->codec, &si, streaminfo_start);
+ avpriv_flac_parse_streaminfo(st->codec, &si, streaminfo_start);
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
st->codec->codec_id = CODEC_ID_FLAC;
diff --git a/libavformat/oggparseskeleton.c b/libavformat/oggparseskeleton.c
index ceb7c6991e..e318e9e718 100644
--- a/libavformat/oggparseskeleton.c
+++ b/libavformat/oggparseskeleton.c
@@ -1,20 +1,20 @@
/*
* Copyright (C) 2010 David Conrad
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/oggparsespeex.c b/libavformat/oggparsespeex.c
index 2f4aec7f07..bbeeb20d60 100644
--- a/libavformat/oggparsespeex.c
+++ b/libavformat/oggparsespeex.c
@@ -31,6 +31,7 @@
#include "oggdec.h"
struct speex_params {
+ int packet_size;
int final_packet_duration;
int seq;
};
@@ -58,14 +59,10 @@ static int speex_header(AVFormatContext *s, int idx) {
st->codec->sample_rate = AV_RL32(p + 36);
st->codec->channels = AV_RL32(p + 48);
- /* We treat the whole Speex packet as a single frame everywhere Speex
- is handled in Libav. This avoids the complexities of splitting
- and joining individual Speex frames, which are not always
- byte-aligned. */
- st->codec->frame_size = AV_RL32(p + 56);
- frames_per_packet = AV_RL32(p + 64);
+ spxp->packet_size = AV_RL32(p + 56);
+ frames_per_packet = AV_RL32(p + 64);
if (frames_per_packet)
- st->codec->frame_size *= frames_per_packet;
+ spxp->packet_size *= frames_per_packet;
st->codec->extradata_size = os->psize;
st->codec->extradata = av_malloc(st->codec->extradata_size
@@ -95,7 +92,7 @@ static int speex_packet(AVFormatContext *s, int idx)
struct ogg *ogg = s->priv_data;
struct ogg_stream *os = ogg->streams + idx;
struct speex_params *spxp = os->private;
- int packet_size = s->streams[idx]->codec->frame_size;
+ int packet_size = spxp->packet_size;
if (os->flags & OGG_FLAG_EOS && os->lastpts != AV_NOPTS_VALUE &&
os->granule > 0) {
@@ -108,9 +105,10 @@ static int speex_packet(AVFormatContext *s, int idx)
if (!os->lastpts && os->granule > 0)
/* first packet */
- os->pduration = os->granule - packet_size * (ogg_page_packets(os) - 1);
- else if (os->flags & OGG_FLAG_EOS && os->segp == os->nsegs &&
- spxp->final_packet_duration)
+ os->lastpts = os->lastdts = os->granule - packet_size *
+ ogg_page_packets(os);
+ if (os->flags & OGG_FLAG_EOS && os->segp == os->nsegs &&
+ spxp->final_packet_duration)
/* final packet */
os->pduration = spxp->final_packet_duration;
else
diff --git a/libavformat/oggparsevorbis.c b/libavformat/oggparsevorbis.c
index 86951f3e2f..8a406976b5 100644
--- a/libavformat/oggparsevorbis.c
+++ b/libavformat/oggparsevorbis.c
@@ -45,7 +45,7 @@ static int ogm_chapter(AVFormatContext *as, uint8_t *key, uint8_t *val)
if (sscanf(val, "%02d:%02d:%02d.%03d", &h, &m, &s, &ms) < 4)
return 0;
- ff_new_chapter(as, cnum, (AVRational){1,1000},
+ avpriv_new_chapter(as, cnum, (AVRational){1,1000},
ms + 1000*(s + 60*(m + 60*h)),
AV_NOPTS_VALUE, NULL);
av_free(val);
diff --git a/libavformat/oma.c b/libavformat/oma.c
index 0ec81ebefb..eeb920553a 100644
--- a/libavformat/oma.c
+++ b/libavformat/oma.c
@@ -3,21 +3,22 @@
*
* Copyright (c) 2008 Maxim Poliakovski
* 2008 Benjamin Larsson
+ * 2011 David Goldwich
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -36,20 +37,19 @@
* - Sound data organized in packets follow the EA3 header
* (can be encrypted using the Sony DRM!).
*
- * LIMITATIONS: This version supports only plain (unencrypted) OMA files.
- * If any DRM-protected (encrypted) file is encountered you will get the
- * corresponding error message. Try to remove the encryption using any
- * Sony software (for example SonicStage).
* CODEC SUPPORT: Only ATRAC3 codec is currently supported!
*/
#include "avformat.h"
#include "libavutil/intreadwrite.h"
+#include "libavutil/des.h"
#include "pcm.h"
#include "riff.h"
#include "id3v2.h"
#define EA3_HEADER_SIZE 96
+#define ID3v2_EA3_MAGIC "ea3"
+#define OMA_ENC_HEADER_SIZE 16
enum {
OMA_CODECID_ATRAC3 = 0,
@@ -65,7 +65,211 @@ static const AVCodecTag codec_oma_tags[] = {
{ CODEC_ID_MP3, OMA_CODECID_MP3 },
};
-#define ID3v2_EA3_MAGIC "ea3"
+static const uint64_t leaf_table[] = {
+ 0xd79e8283acea4620, 0x7a9762f445afd0d8,
+ 0x354d60a60b8c79f1, 0x584e1cde00b07aee,
+ 0x1573cd93da7df623, 0x47f98d79620dd535
+};
+
+typedef struct OMAContext {
+ uint64_t content_start;
+ int encrypted;
+ uint16_t k_size;
+ uint16_t e_size;
+ uint16_t i_size;
+ uint16_t s_size;
+ uint32_t rid;
+ uint8_t r_val[24];
+ uint8_t n_val[24];
+ uint8_t m_val[8];
+ uint8_t s_val[8];
+ uint8_t sm_val[8];
+ uint8_t e_val[8];
+ uint8_t iv[8];
+ struct AVDES av_des;
+} OMAContext;
+
+static void hex_log(AVFormatContext *s, int level, const char *name, const uint8_t *value, int len)
+{
+ char buf[33];
+ len = FFMIN(len, 16);
+ if (av_log_get_level() < level)
+ return;
+ ff_data_to_hex(buf, value, len, 1);
+ buf[len<<1] = '\0';
+ av_log(s, level, "%s: %s\n", name, buf);
+}
+
+static int kset(AVFormatContext *s, const uint8_t *r_val, const uint8_t *n_val, int len)
+{
+ OMAContext *oc = s->priv_data;
+
+ if (!r_val && !n_val)
+ return -1;
+
+ len = FFMIN(len, 16);
+
+ /* use first 64 bits in the third round again */
+ if (r_val) {
+ if (r_val != oc->r_val) {
+ memset(oc->r_val, 0, 24);
+ memcpy(oc->r_val, r_val, len);
+ }
+ memcpy(&oc->r_val[16], r_val, 8);
+ }
+ if (n_val) {
+ if (n_val != oc->n_val) {
+ memset(oc->n_val, 0, 24);
+ memcpy(oc->n_val, n_val, len);
+ }
+ memcpy(&oc->n_val[16], n_val, 8);
+ }
+
+ return 0;
+}
+
+static int rprobe(AVFormatContext *s, uint8_t *enc_header, const uint8_t *r_val)
+{
+ OMAContext *oc = s->priv_data;
+ unsigned int pos;
+ struct AVDES av_des;
+
+ if (!enc_header || !r_val)
+ return -1;
+
+ /* m_val */
+ av_des_init(&av_des, r_val, 192, 1);
+ av_des_crypt(&av_des, oc->m_val, &enc_header[48], 1, NULL, 1);
+
+ /* s_val */
+ av_des_init(&av_des, oc->m_val, 64, 0);
+ av_des_crypt(&av_des, oc->s_val, NULL, 1, NULL, 0);
+
+ /* sm_val */
+ pos = OMA_ENC_HEADER_SIZE + oc->k_size + oc->e_size;
+ av_des_init(&av_des, oc->s_val, 64, 0);
+ av_des_mac(&av_des, oc->sm_val, &enc_header[pos], (oc->i_size >> 3));
+
+ pos += oc->i_size;
+
+ return memcmp(&enc_header[pos], oc->sm_val, 8) ? -1 : 0;
+}
+
+static int nprobe(AVFormatContext *s, uint8_t *enc_header, const uint8_t *n_val)
+{
+ OMAContext *oc = s->priv_data;
+ uint32_t pos, taglen, datalen;
+ struct AVDES av_des;
+
+ if (!enc_header || !n_val)
+ return -1;
+
+ pos = OMA_ENC_HEADER_SIZE + oc->k_size;
+ if (!memcmp(&enc_header[pos], "EKB ", 4))
+ pos += 32;
+
+ if (AV_RB32(&enc_header[pos]) != oc->rid)
+ av_log(s, AV_LOG_DEBUG, "Mismatching RID\n");
+
+ taglen = AV_RB32(&enc_header[pos+32]);
+ datalen = AV_RB32(&enc_header[pos+36]) >> 4;
+
+ pos += 44 + taglen;
+
+ av_des_init(&av_des, n_val, 192, 1);
+ while (datalen-- > 0) {
+ av_des_crypt(&av_des, oc->r_val, &enc_header[pos], 2, NULL, 1);
+ kset(s, oc->r_val, NULL, 16);
+ if (!rprobe(s, enc_header, oc->r_val))
+ return 0;
+ pos += 16;
+ }
+
+ return -1;
+}
+
+static int decrypt_init(AVFormatContext *s, ID3v2ExtraMeta *em, uint8_t *header)
+{
+ OMAContext *oc = s->priv_data;
+ ID3v2ExtraMetaGEOB *geob = NULL;
+ uint8_t *gdata;
+
+ oc->encrypted = 1;
+ av_log(s, AV_LOG_INFO, "File is encrypted\n");
+
+ /* find GEOB metadata */
+ while (em) {
+ if (!strcmp(em->tag, "GEOB") &&
+ (geob = em->data) &&
+ !strcmp(geob->description, "OMG_LSI") ||
+ !strcmp(geob->description, "OMG_BKLSI")) {
+ break;
+ }
+ em = em->next;
+ }
+ if (!em) {
+ av_log(s, AV_LOG_ERROR, "No encryption header found\n");
+ return -1;
+ }
+
+ if (geob->datasize < 64) {
+ av_log(s, AV_LOG_ERROR, "Invalid GEOB data size: %u\n", geob->datasize);
+ return -1;
+ }
+
+ gdata = geob->data;
+
+ if (AV_RB16(gdata) != 1)
+ av_log(s, AV_LOG_WARNING, "Unknown version in encryption header\n");
+
+ oc->k_size = AV_RB16(&gdata[2]);
+ oc->e_size = AV_RB16(&gdata[4]);
+ oc->i_size = AV_RB16(&gdata[6]);
+ oc->s_size = AV_RB16(&gdata[8]);
+
+ if (memcmp(&gdata[OMA_ENC_HEADER_SIZE], "KEYRING ", 12)) {
+ av_log(s, AV_LOG_ERROR, "Invalid encryption header\n");
+ return -1;
+ }
+ oc->rid = AV_RB32(&gdata[OMA_ENC_HEADER_SIZE + 28]);
+ av_log(s, AV_LOG_DEBUG, "RID: %.8x\n", oc->rid);
+
+ memcpy(oc->iv, &header[0x58], 8);
+ hex_log(s, AV_LOG_DEBUG, "IV", oc->iv, 8);
+
+ hex_log(s, AV_LOG_DEBUG, "CBC-MAC", &gdata[OMA_ENC_HEADER_SIZE+oc->k_size+oc->e_size+oc->i_size], 8);
+
+ if (s->keylen > 0) {
+ kset(s, s->key, s->key, s->keylen);
+ }
+ if (!memcmp(oc->r_val, (const uint8_t[8]){0}, 8) ||
+ rprobe(s, gdata, oc->r_val) < 0 &&
+ nprobe(s, gdata, oc->n_val) < 0) {
+ int i;
+ for (i = 0; i < sizeof(leaf_table); i += 2) {
+ uint8_t buf[16];
+ AV_WL64(buf, leaf_table[i]);
+ AV_WL64(&buf[8], leaf_table[i+1]);
+ kset(s, buf, buf, 16);
+ if (!rprobe(s, gdata, oc->r_val) || !nprobe(s, gdata, oc->n_val))
+ break;
+ }
+ if (i >= sizeof(leaf_table)) {
+ av_log(s, AV_LOG_ERROR, "Invalid key\n");
+ return -1;
+ }
+ }
+
+ /* e_val */
+ av_des_init(&oc->av_des, oc->m_val, 64, 0);
+ av_des_crypt(&oc->av_des, oc->e_val, &gdata[OMA_ENC_HEADER_SIZE + 40], 1, NULL, 0);
+ hex_log(s, AV_LOG_DEBUG, "EK", oc->e_val, 8);
+
+ /* init e_val */
+ av_des_init(&oc->av_des, oc->e_val, 64, 1);
+
+ return 0;
+}
static int oma_read_header(AVFormatContext *s,
AVFormatParameters *ap)
@@ -77,8 +281,10 @@ static int oma_read_header(AVFormatContext *s,
uint8_t buf[EA3_HEADER_SIZE];
uint8_t *edata;
AVStream *st;
+ ID3v2ExtraMeta *extra_meta = NULL;
+ OMAContext *oc = s->priv_data;
- ff_id3v2_read(s, ID3v2_EA3_MAGIC);
+ ff_id3v2_read_all(s, ID3v2_EA3_MAGIC, &extra_meta);
ret = avio_read(s->pb, buf, EA3_HEADER_SIZE);
if (ret < EA3_HEADER_SIZE)
return -1;
@@ -88,15 +294,20 @@ static int oma_read_header(AVFormatContext *s,
return -1;
}
+ oc->content_start = avio_tell(s->pb);
+
+ /* encrypted file */
eid = AV_RB16(&buf[6]);
- if (eid != -1 && eid != -128) {
- av_log(s, AV_LOG_ERROR, "Encrypted file! Eid: %d\n", eid);
+ if (eid != -1 && eid != -128 && decrypt_init(s, extra_meta, buf) < 0) {
+ ff_id3v2_free_extra_meta(&extra_meta);
return -1;
}
+ ff_id3v2_free_extra_meta(&extra_meta);
+
codec_params = AV_RB24(&buf[33]);
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
@@ -159,12 +370,20 @@ static int oma_read_header(AVFormatContext *s,
static int oma_read_packet(AVFormatContext *s, AVPacket *pkt)
{
- int ret = av_get_packet(s->pb, pkt, s->streams[0]->codec->block_align);
+ OMAContext *oc = s->priv_data;
+ int packet_size = s->streams[0]->codec->block_align;
+ int ret = av_get_packet(s->pb, pkt, packet_size);
- pkt->stream_index = 0;
if (ret <= 0)
return AVERROR(EIO);
+ pkt->stream_index = 0;
+
+ if (oc->encrypted) {
+ /* previous unencrypted block saved in IV for the next packet (CBC mode) */
+ av_des_crypt(&oc->av_des, pkt->data, pkt->data, (packet_size >> 3), oc->iv, 1);
+ }
+
return ret;
}
@@ -190,18 +409,38 @@ static int oma_read_probe(AVProbeData *p)
return 0;
}
+static int oma_read_seek(struct AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
+{
+ OMAContext *oc = s->priv_data;
+
+ pcm_read_seek(s, stream_index, timestamp, flags);
+
+ if (oc->encrypted) {
+ /* readjust IV for CBC */
+ int64_t pos = avio_tell(s->pb);
+ if (pos < oc->content_start)
+ memset(oc->iv, 0, 8);
+ else {
+ if (avio_seek(s->pb, -8, SEEK_CUR) < 0 || avio_read(s->pb, oc->iv, 8) < 8) {
+ memset(oc->iv, 0, 8);
+ return -1;
+ }
+ }
+ }
+
+ return 0;
+}
AVInputFormat ff_oma_demuxer = {
- "oma",
- NULL_IF_CONFIG_SMALL("Sony OpenMG audio"),
- 0,
- oma_read_probe,
- oma_read_header,
- oma_read_packet,
- 0,
- pcm_read_seek,
- .flags= AVFMT_GENERIC_INDEX,
- .extensions = "oma,aa3",
- .codec_tag= (const AVCodecTag* const []){codec_oma_tags, 0},
+ .name = "oma",
+ .long_name = NULL_IF_CONFIG_SMALL("Sony OpenMG audio"),
+ .priv_data_size = sizeof(OMAContext),
+ .read_probe = oma_read_probe,
+ .read_header = oma_read_header,
+ .read_packet = oma_read_packet,
+ .read_seek = oma_read_seek,
+ .flags = AVFMT_GENERIC_INDEX,
+ .extensions = "oma,omg,aa3",
+ .codec_tag = (const AVCodecTag* const []){codec_oma_tags, 0},
};
diff --git a/libavformat/options.c b/libavformat/options.c
index c2729b75d9..64bc7a8996 100644
--- a/libavformat/options.c
+++ b/libavformat/options.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2000, 2001, 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avformat.h"
@@ -33,30 +33,36 @@ static const char* format_to_name(void* ptr)
else return "NULL";
}
-static const AVOption *opt_find(void *obj, const char *name, const char *unit, int opt_flags, int search_flags)
+static void *format_child_next(void *obj, void *prev)
+{
+ AVFormatContext *s = obj;
+ if (!prev && s->priv_data &&
+ ((s->iformat && s->iformat->priv_class) ||
+ s->oformat && s->oformat->priv_class))
+ return s->priv_data;
+ return NULL;
+}
+
+static const AVClass *format_child_class_next(const AVClass *prev)
{
- AVFormatContext *s = obj;
AVInputFormat *ifmt = NULL;
AVOutputFormat *ofmt = NULL;
- if (s->priv_data) {
- if ((s->iformat && !s->iformat->priv_class) ||
- (s->oformat && !s->oformat->priv_class))
- return NULL;
- return av_opt_find(s->priv_data, name, unit, opt_flags, search_flags);
- }
-
- while ((ifmt = av_iformat_next(ifmt))) {
- const AVOption *o;
-
- if (ifmt->priv_class && (o = av_opt_find(&ifmt->priv_class, name, unit, opt_flags, search_flags)))
- return o;
- }
- while ((ofmt = av_oformat_next(ofmt))) {
- const AVOption *o;
-
- if (ofmt->priv_class && (o = av_opt_find(&ofmt->priv_class, name, unit, opt_flags, search_flags)))
- return o;
- }
+
+ while (prev && (ifmt = av_iformat_next(ifmt)))
+ if (ifmt->priv_class == prev)
+ break;
+ if ((prev && ifmt) || (!prev))
+ while (ifmt = av_iformat_next(ifmt))
+ if (ifmt->priv_class)
+ return ifmt->priv_class;
+
+ while (prev && (ofmt = av_oformat_next(ofmt)))
+ if (ofmt->priv_class == prev)
+ break;
+ while (ofmt = av_oformat_next(ofmt))
+ if (ofmt->priv_class)
+ return ofmt->priv_class;
+
return NULL;
}
@@ -67,26 +73,35 @@ static const AVOption *opt_find(void *obj, const char *name, const char *unit, i
#define D AV_OPT_FLAG_DECODING_PARAM
static const AVOption options[]={
-{"probesize", "set probing size", OFFSET(probesize), FF_OPT_TYPE_INT, {.dbl = 5000000 }, 32, INT_MAX, D},
-{"muxrate", "set mux rate", OFFSET(mux_rate), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, INT_MAX, E},
-{"packetsize", "set packet size", OFFSET(packet_size), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, INT_MAX, E},
-{"fflags", NULL, OFFSET(flags), FF_OPT_TYPE_FLAGS, {.dbl = DEFAULT }, INT_MIN, INT_MAX, D|E, "fflags"},
-{"ignidx", "ignore index", 0, FF_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_IGNIDX }, INT_MIN, INT_MAX, D, "fflags"},
-{"genpts", "generate pts", 0, FF_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_GENPTS }, INT_MIN, INT_MAX, D, "fflags"},
-{"nofillin", "do not fill in missing values that can be exactly calculated", 0, FF_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_NOFILLIN }, INT_MIN, INT_MAX, D, "fflags"},
-{"noparse", "disable AVParsers, this needs nofillin too", 0, FF_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_NOPARSE }, INT_MIN, INT_MAX, D, "fflags"},
-{"igndts", "ignore dts", 0, FF_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_IGNDTS }, INT_MIN, INT_MAX, D, "fflags"},
+{"probesize", "set probing size", OFFSET(probesize), AV_OPT_TYPE_INT, {.dbl = 5000000 }, 32, INT_MAX, D},
+#if FF_API_MUXRATE
+{"muxrate", "set mux rate", OFFSET(mux_rate), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, INT_MAX, E},
+#endif
+{"packetsize", "set packet size", OFFSET(packet_size), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, INT_MAX, E},
+{"fflags", NULL, OFFSET(flags), AV_OPT_TYPE_FLAGS, {.dbl = DEFAULT }, INT_MIN, INT_MAX, D|E, "fflags"},
+{"ignidx", "ignore index", 0, AV_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_IGNIDX }, INT_MIN, INT_MAX, D, "fflags"},
+{"genpts", "generate pts", 0, AV_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_GENPTS }, INT_MIN, INT_MAX, D, "fflags"},
+{"nofillin", "do not fill in missing values that can be exactly calculated", 0, AV_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_NOFILLIN }, INT_MIN, INT_MAX, D, "fflags"},
+{"noparse", "disable AVParsers, this needs nofillin too", 0, AV_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_NOPARSE }, INT_MIN, INT_MAX, D, "fflags"},
+{"igndts", "ignore dts", 0, AV_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_IGNDTS }, INT_MIN, INT_MAX, D, "fflags"},
#if FF_API_FLAG_RTP_HINT
-{"rtphint", "add rtp hinting (deprecated, use the -movflags rtphint option instead)", 0, FF_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_RTP_HINT }, INT_MIN, INT_MAX, E, "fflags"},
+{"rtphint", "add rtp hinting (deprecated, use the -movflags rtphint option instead)", 0, AV_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_RTP_HINT }, INT_MIN, INT_MAX, E, "fflags"},
#endif
-{"analyzeduration", "how many microseconds are analyzed to estimate duration", OFFSET(max_analyze_duration), FF_OPT_TYPE_INT, {.dbl = 5*AV_TIME_BASE }, 0, INT_MAX, D},
-{"cryptokey", "decryption key", OFFSET(key), FF_OPT_TYPE_BINARY, {.dbl = 0}, 0, 0, D},
-{"indexmem", "max memory used for timestamp index (per stream)", OFFSET(max_index_size), FF_OPT_TYPE_INT, {.dbl = 1<<20 }, 0, INT_MAX, D},
-{"rtbufsize", "max memory used for buffering real-time frames", OFFSET(max_picture_buffer), FF_OPT_TYPE_INT, {.dbl = 3041280 }, 0, INT_MAX, D}, /* defaults to 1s of 15fps 352x288 YUYV422 video */
-{"fdebug", "print specific debug info", OFFSET(debug), FF_OPT_TYPE_FLAGS, {.dbl = DEFAULT }, 0, INT_MAX, E|D, "fdebug"},
-{"ts", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_FDEBUG_TS }, INT_MIN, INT_MAX, E|D, "fdebug"},
-{"max_delay", "maximum muxing or demuxing delay in microseconds", OFFSET(max_delay), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, INT_MAX, E|D},
-{"fpsprobesize", "number of frames used to probe fps", OFFSET(fps_probe_size), FF_OPT_TYPE_INT, {.dbl = -1}, -1, INT_MAX-1, D},
+{"discardcorrupt", "discard corrupted frames", 0, AV_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_DISCARD_CORRUPT }, INT_MIN, INT_MAX, D, "fflags"},
+{"sortdts", "try to interleave outputted packets by dts", 0, AV_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_SORT_DTS }, INT_MIN, INT_MAX, D, "fflags"},
+{"keepside", "dont merge side data", 0, AV_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_KEEP_SIDE_DATA }, INT_MIN, INT_MAX, D, "fflags"},
+{"latm", "enable RTP MP4A-LATM payload", 0, AV_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_MP4A_LATM }, INT_MIN, INT_MAX, E, "fflags"},
+{"analyzeduration", "how many microseconds are analyzed to estimate duration", OFFSET(max_analyze_duration), AV_OPT_TYPE_INT, {.dbl = 5*AV_TIME_BASE }, 0, INT_MAX, D},
+{"cryptokey", "decryption key", OFFSET(key), AV_OPT_TYPE_BINARY, {.dbl = 0}, 0, 0, D},
+{"indexmem", "max memory used for timestamp index (per stream)", OFFSET(max_index_size), AV_OPT_TYPE_INT, {.dbl = 1<<20 }, 0, INT_MAX, D},
+{"rtbufsize", "max memory used for buffering real-time frames", OFFSET(max_picture_buffer), AV_OPT_TYPE_INT, {.dbl = 3041280 }, 0, INT_MAX, D}, /* defaults to 1s of 15fps 352x288 YUYV422 video */
+{"fdebug", "print specific debug info", OFFSET(debug), AV_OPT_TYPE_FLAGS, {.dbl = DEFAULT }, 0, INT_MAX, E|D, "fdebug"},
+{"ts", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_FDEBUG_TS }, INT_MIN, INT_MAX, E|D, "fdebug"},
+{"max_delay", "maximum muxing or demuxing delay in microseconds", OFFSET(max_delay), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, INT_MAX, E|D},
+{"fer", "set error detection aggressivity", OFFSET(error_recognition), AV_OPT_TYPE_INT, {.dbl = FF_ER_CAREFUL }, INT_MIN, INT_MAX, D, "fer"},
+{"careful", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_ER_CAREFUL }, INT_MIN, INT_MAX, D, "fer"},
+{"explode", "abort decoding on error recognition", 0, AV_OPT_TYPE_CONST, {.dbl = FF_ER_EXPLODE }, INT_MIN, INT_MAX, D, "fer"},
+{"fpsprobesize", "number of frames used to probe fps", OFFSET(fps_probe_size), AV_OPT_TYPE_INT, {.dbl = -1}, -1, INT_MAX-1, D},
{NULL},
};
@@ -99,7 +114,8 @@ static const AVClass av_format_context_class = {
.item_name = format_to_name,
.option = options,
.version = LIBAVUTIL_VERSION_INT,
- .opt_find = opt_find,
+ .child_next = format_child_next,
+ .child_class_next = format_child_class_next,
};
static void avformat_get_context_defaults(AVFormatContext *s)
@@ -119,3 +135,8 @@ AVFormatContext *avformat_alloc_context(void)
avformat_get_context_defaults(ic);
return ic;
}
+
+const AVClass *avformat_get_class(void)
+{
+ return &av_format_context_class;
+}
diff --git a/libavformat/os_support.c b/libavformat/os_support.c
index a0fcd6c9ba..ac9086c3c3 100644
--- a/libavformat/os_support.c
+++ b/libavformat/os_support.c
@@ -3,20 +3,20 @@
* Copyright (c) 2000, 2001, 2002 Fabrice Bellard
* copyright (c) 2002 Francois Revol
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/os_support.h b/libavformat/os_support.h
index 521e9978a2..f770528365 100644
--- a/libavformat/os_support.h
+++ b/libavformat/os_support.h
@@ -2,20 +2,20 @@
* various utilities for ffmpeg system
* copyright (c) 2000, 2001, 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/pcm.c b/libavformat/pcm.c
index 7d5fed5601..d66be59ccb 100644
--- a/libavformat/pcm.c
+++ b/libavformat/pcm.c
@@ -2,20 +2,20 @@
* PCM common functions
* Copyright (c) 2003 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/pcm.h b/libavformat/pcm.h
index 228df1394b..7c0b7d70aa 100644
--- a/libavformat/pcm.h
+++ b/libavformat/pcm.h
@@ -2,20 +2,20 @@
* PCM common functions
* Copyright (C) 2007 Aurelien Jacobs <aurel@gnuage.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/pcmdec.c b/libavformat/pcmdec.c
index 343bbf0ae2..542ee17749 100644
--- a/libavformat/pcmdec.c
+++ b/libavformat/pcmdec.c
@@ -2,26 +2,28 @@
* RAW PCM demuxers
* Copyright (c) 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avformat.h"
#include "rawdec.h"
#include "pcm.h"
+#include "libavutil/log.h"
+#include "libavutil/opt.h"
#define RAW_SAMPLES 1024
@@ -46,20 +48,30 @@ static int raw_read_packet(AVFormatContext *s, AVPacket *pkt)
return ret;
}
-#define PCMDEF(name, long_name, ext, codec) \
-AVInputFormat ff_pcm_ ## name ## _demuxer = {\
- #name,\
- NULL_IF_CONFIG_SMALL(long_name),\
- sizeof(RawAudioDemuxerContext),\
- NULL,\
- ff_raw_read_header,\
- raw_read_packet,\
- NULL,\
- pcm_read_seek,\
- .flags= AVFMT_GENERIC_INDEX,\
- .extensions = ext,\
- .value = codec,\
- .priv_class = &ff_rawaudio_demuxer_class,\
+static const AVOption pcm_options[] = {
+ { "sample_rate", "", offsetof(RawAudioDemuxerContext, sample_rate), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
+ { "channels", "", offsetof(RawAudioDemuxerContext, channels), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
+ { NULL },
+};
+
+#define PCMDEF(name_, long_name_, ext, codec) \
+static const AVClass name_ ## _demuxer_class = { \
+ .class_name = #name_ " demuxer", \
+ .item_name = av_default_item_name, \
+ .option = pcm_options, \
+ .version = LIBAVUTIL_VERSION_INT, \
+}; \
+AVInputFormat ff_pcm_ ## name_ ## _demuxer = { \
+ .name = #name_, \
+ .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
+ .priv_data_size = sizeof(RawAudioDemuxerContext), \
+ .read_header = ff_raw_read_header, \
+ .read_packet = raw_read_packet, \
+ .read_seek = pcm_read_seek, \
+ .flags = AVFMT_GENERIC_INDEX, \
+ .extensions = ext, \
+ .value = codec, \
+ .priv_class = &name_ ## _demuxer_class, \
};
PCMDEF(f64be, "PCM 64 bit floating-point big-endian format",
diff --git a/libavformat/pcmenc.c b/libavformat/pcmenc.c
index 928124e9b0..12e64b0fb8 100644
--- a/libavformat/pcmenc.c
+++ b/libavformat/pcmenc.c
@@ -2,38 +2,35 @@
* RAW PCM muxers
* Copyright (c) 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avformat.h"
#include "rawenc.h"
-#define PCMDEF(name, long_name, ext, codec) \
-AVOutputFormat ff_pcm_ ## name ## _muxer = {\
- #name,\
- NULL_IF_CONFIG_SMALL(long_name),\
- NULL,\
- ext,\
- 0,\
- codec,\
- CODEC_ID_NONE,\
- NULL,\
- ff_raw_write_packet,\
- .flags= AVFMT_NOTIMESTAMPS,\
+#define PCMDEF(name_, long_name_, ext, codec) \
+AVOutputFormat ff_pcm_ ## name_ ## _muxer = { \
+ .name = #name_, \
+ .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
+ .extensions = ext, \
+ .audio_codec = codec, \
+ .video_codec = CODEC_ID_NONE, \
+ .write_packet = ff_raw_write_packet, \
+ .flags = AVFMT_NOTIMESTAMPS, \
};
PCMDEF(f64be, "PCM 64 bit floating-point big-endian format",
diff --git a/libavformat/pmpdec.c b/libavformat/pmpdec.c
new file mode 100644
index 0000000000..ba40003359
--- /dev/null
+++ b/libavformat/pmpdec.c
@@ -0,0 +1,172 @@
+/*
+ * PMP demuxer.
+ * Copyright (c) 2011 Reimar Döffinger
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/intreadwrite.h"
+#include "avformat.h"
+
+typedef struct {
+ int cur_stream;
+ int num_streams;
+ int audio_packets;
+ int current_packet;
+ uint32_t *packet_sizes;
+ int packet_sizes_alloc;
+} PMPContext;
+
+static int pmp_probe(AVProbeData *p) {
+ if (AV_RN32(p->buf) == AV_RN32("pmpm") &&
+ AV_RL32(p->buf + 4) == 1)
+ return AVPROBE_SCORE_MAX;
+ return 0;
+}
+
+static int pmp_header(AVFormatContext *s, AVFormatParameters *ap) {
+ PMPContext *pmp = s->priv_data;
+ AVIOContext *pb = s->pb;
+ int tb_num, tb_den;
+ int index_cnt;
+ int audio_codec_id = CODEC_ID_NONE;
+ int srate, channels;
+ int i;
+ uint64_t pos;
+ AVStream *vst = av_new_stream(s, 0);
+ if (!vst)
+ return AVERROR(ENOMEM);
+ vst->codec->codec_type = AVMEDIA_TYPE_VIDEO;
+ avio_skip(pb, 8);
+ switch (avio_rl32(pb)) {
+ case 0:
+ vst->codec->codec_id = CODEC_ID_MPEG4;
+ break;
+ case 1:
+ vst->codec->codec_id = CODEC_ID_H264;
+ break;
+ default:
+ av_log(s, AV_LOG_ERROR, "Unsupported video format\n");
+ break;
+ }
+ index_cnt = avio_rl32(pb);
+ vst->codec->width = avio_rl32(pb);
+ vst->codec->height = avio_rl32(pb);
+
+ tb_num = avio_rl32(pb);
+ tb_den = avio_rl32(pb);
+ av_set_pts_info(vst, 32, tb_num, tb_den);
+ vst->nb_frames = index_cnt;
+ vst->duration = index_cnt;
+
+ switch (avio_rl32(pb)) {
+ case 0:
+ audio_codec_id = CODEC_ID_MP3;
+ break;
+ case 1:
+ av_log(s, AV_LOG_ERROR, "AAC not yet correctly supported\n");
+ audio_codec_id = CODEC_ID_AAC;
+ break;
+ default:
+ av_log(s, AV_LOG_ERROR, "Unsupported audio format\n");
+ break;
+ }
+ pmp->num_streams = avio_rl16(pb) + 1;
+ avio_skip(pb, 10);
+ srate = avio_rl32(pb);
+ channels = avio_rl32(pb) + 1;
+ for (i = 1; i < pmp->num_streams; i++) {
+ AVStream *ast = av_new_stream(s, i);
+ if (!ast)
+ return AVERROR(ENOMEM);
+ ast->codec->codec_type = AVMEDIA_TYPE_AUDIO;
+ ast->codec->codec_id = audio_codec_id;
+ ast->codec->channels = channels;
+ ast->codec->sample_rate = srate;
+ av_set_pts_info(ast, 32, 1, srate);
+ }
+ pos = avio_tell(pb) + 4*index_cnt;
+ for (i = 0; i < index_cnt; i++) {
+ int size = avio_rl32(pb);
+ int flags = size & 1 ? AVINDEX_KEYFRAME : 0;
+ size >>= 1;
+ av_add_index_entry(vst, pos, i, size, 0, flags);
+ pos += size;
+ }
+ return 0;
+}
+
+static int pmp_packet(AVFormatContext *s, AVPacket *pkt) {
+ PMPContext *pmp = s->priv_data;
+ AVIOContext *pb = s->pb;
+ int ret = 0;
+ int i;
+
+ if (url_feof(pb))
+ return AVERROR_EOF;
+ if (pmp->cur_stream == 0) {
+ int num_packets;
+ pmp->audio_packets = avio_r8(pb);
+ num_packets = (pmp->num_streams - 1) * pmp->audio_packets + 1;
+ avio_skip(pb, 8);
+ pmp->current_packet = 0;
+ av_fast_malloc(&pmp->packet_sizes,
+ &pmp->packet_sizes_alloc,
+ num_packets * sizeof(*pmp->packet_sizes));
+ for (i = 0; i < num_packets; i++)
+ pmp->packet_sizes[i] = avio_rl32(pb);
+ }
+ ret = av_get_packet(pb, pkt, pmp->packet_sizes[pmp->current_packet]);
+ if (ret >= 0) {
+ ret = 0;
+ // FIXME: this is a hack that should be remove once
+ // compute_pkt_fields can handle
+ if (pmp->cur_stream == 0)
+ pkt->dts = s->streams[0]->cur_dts++;
+ pkt->stream_index = pmp->cur_stream;
+ }
+ if (pmp->current_packet % pmp->audio_packets == 0)
+ pmp->cur_stream = (pmp->cur_stream + 1) % pmp->num_streams;
+ pmp->current_packet++;
+ return ret;
+}
+
+static int pmp_seek(AVFormatContext *s, int stream_index,
+ int64_t ts, int flags) {
+ PMPContext *pmp = s->priv_data;
+ pmp->cur_stream = 0;
+ // fallback to default seek now
+ return -1;
+}
+
+static int pmp_close(AVFormatContext *s)
+{
+ PMPContext *pmp = s->priv_data;
+ av_freep(&pmp->packet_sizes);
+ return 0;
+}
+
+AVInputFormat ff_pmp_demuxer = {
+ .name = "pmp",
+ .long_name = NULL_IF_CONFIG_SMALL("Playstation Portable PMP format"),
+ .priv_data_size = sizeof(PMPContext),
+ .read_probe = pmp_probe,
+ .read_header = pmp_header,
+ .read_packet = pmp_packet,
+ .read_seek = pmp_seek,
+ .read_close = pmp_close,
+};
diff --git a/libavformat/psxstr.c b/libavformat/psxstr.c
index 646244238c..675a4b11df 100644
--- a/libavformat/psxstr.c
+++ b/libavformat/psxstr.c
@@ -2,20 +2,20 @@
* Sony Playstation (PSX) STR File Demuxer
* Copyright (c) 2003 The ffmpeg Project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -68,6 +68,8 @@ static const char sync_header[12] = {0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf
static int str_probe(AVProbeData *p)
{
uint8_t *sector= p->buf;
+ uint8_t *end= sector + p->buf_size;
+ int aud=0, vid=0;
if (p->buf_size < RAW_CD_SECTOR_SIZE)
return 0;
@@ -79,20 +81,52 @@ static int str_probe(AVProbeData *p)
sector += RIFF_HEADER_SIZE;
}
- /* look for CD sync header (00, 0xFF x 10, 00) */
- if (memcmp(sector,sync_header,sizeof(sync_header)))
- return 0;
+ while (end - sector >= RAW_CD_SECTOR_SIZE) {
+ /* look for CD sync header (00, 0xFF x 10, 00) */
+ if (memcmp(sector,sync_header,sizeof(sync_header)))
+ return 0;
- if(sector[0x11] >= 32)
- return 0;
- if( (sector[0x12] & CDXA_TYPE_MASK) != CDXA_TYPE_VIDEO
- && (sector[0x12] & CDXA_TYPE_MASK) != CDXA_TYPE_AUDIO
- && (sector[0x12] & CDXA_TYPE_MASK) != CDXA_TYPE_DATA)
- return 0;
+ if (sector[0x11] >= 32)
+ return 0;
+
+ switch (sector[0x12] & CDXA_TYPE_MASK) {
+ case CDXA_TYPE_DATA:
+ case CDXA_TYPE_VIDEO: {
+ int current_sector = AV_RL16(&sector[0x1C]);
+ int sector_count = AV_RL16(&sector[0x1E]);
+ int frame_size = AV_RL32(&sector[0x24]);
+
+ if(!( frame_size>=0
+ && current_sector < sector_count
+ && sector_count*VIDEO_DATA_CHUNK_SIZE >=frame_size)){
+ return 0;
+ }
+ /*st->codec->width = AV_RL16(&sector[0x28]);
+ st->codec->height = AV_RL16(&sector[0x2A]);*/
+
+// if (current_sector == sector_count-1) {
+ vid++;
+// }
+
+ }
+ break;
+ case CDXA_TYPE_AUDIO:
+ if(sector[0x13]&0x2A)
+ return 0;
+ aud++;
+ break;
+ default:
+ if(sector[0x12] & CDXA_TYPE_MASK)
+ return 0;
+ }
+ sector += RAW_CD_SECTOR_SIZE;
+ }
/* MPEG files (like those ripped from VCDs) can also look like this;
* only return half certainty */
- return 50;
+ if(vid+aud > 3) return 50;
+ else if(vid+aud) return 1;
+ else return 0;
}
static int str_read_header(AVFormatContext *s,
@@ -162,7 +196,7 @@ static int str_read_packet(AVFormatContext *s,
if(str->channels[channel].video_stream_index < 0){
/* allocate a new AVStream */
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
av_set_pts_info(st, 64, 1, 15);
@@ -210,7 +244,7 @@ static int str_read_packet(AVFormatContext *s,
if(str->channels[channel].audio_stream_index < 0){
int fmt = sector[0x13];
/* allocate a new AVStream */
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
@@ -240,7 +274,7 @@ static int str_read_packet(AVFormatContext *s,
break;
}
- if (pb->eof_reached)
+ if (url_feof(pb))
return AVERROR(EIO);
}
}
@@ -258,11 +292,11 @@ static int str_read_close(AVFormatContext *s)
}
AVInputFormat ff_str_demuxer = {
- "psxstr",
- NULL_IF_CONFIG_SMALL("Sony Playstation STR format"),
- sizeof(StrDemuxContext),
- str_probe,
- str_read_header,
- str_read_packet,
- str_read_close,
+ .name = "psxstr",
+ .long_name = NULL_IF_CONFIG_SMALL("Sony Playstation STR format"),
+ .priv_data_size = sizeof(StrDemuxContext),
+ .read_probe = str_probe,
+ .read_header = str_read_header,
+ .read_packet = str_read_packet,
+ .read_close = str_read_close,
};
diff --git a/libavformat/pva.c b/libavformat/pva.c
index 79b959cef6..7e8fa8eb73 100644
--- a/libavformat/pva.c
+++ b/libavformat/pva.c
@@ -2,20 +2,20 @@
* TechnoTrend PVA (.pva) demuxer
* Copyright (c) 2007, 2008 Ivo van Poorten
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -31,19 +31,32 @@ typedef struct {
int continue_pes;
} PVAContext;
+static int pva_check(uint8_t *p) {
+ int length = AV_RB16(p + 6);
+ if (AV_RB16(p) != PVA_MAGIC || !p[2] || p[2] > 2 || p[4] != 0x55 ||
+ (p[5] & 0xe0) || length > PVA_MAX_PAYLOAD_LENGTH)
+ return -1;
+ return length + 8;
+}
+
static int pva_probe(AVProbeData * pd) {
unsigned char *buf = pd->buf;
+ int len = pva_check(buf);
- if (AV_RB16(buf) == PVA_MAGIC && buf[2] && buf[2] < 3 && buf[4] == 0x55)
+ if (len < 0)
+ return 0;
+
+ if (pd->buf_size >= len + 8 &&
+ pva_check(buf + len) >= 0)
return AVPROBE_SCORE_MAX / 2;
- return 0;
+ return AVPROBE_SCORE_MAX / 4;
}
static int pva_read_header(AVFormatContext *s, AVFormatParameters *ap) {
AVStream *st;
- if (!(st = av_new_stream(s, 0)))
+ if (!(st = avformat_new_stream(s, NULL)))
return AVERROR(ENOMEM);
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
st->codec->codec_id = CODEC_ID_MPEG2VIDEO;
@@ -51,7 +64,7 @@ static int pva_read_header(AVFormatContext *s, AVFormatParameters *ap) {
av_set_pts_info(st, 32, 1, 90000);
av_add_index_entry(st, 0, 0, 0, 0, AVINDEX_KEYFRAME);
- if (!(st = av_new_stream(s, 1)))
+ if (!(st = avformat_new_stream(s, NULL)))
return AVERROR(ENOMEM);
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
st->codec->codec_id = CODEC_ID_MP2;
@@ -201,11 +214,11 @@ static int64_t pva_read_timestamp(struct AVFormatContext *s, int stream_index,
}
AVInputFormat ff_pva_demuxer = {
- "pva",
- NULL_IF_CONFIG_SMALL("TechnoTrend PVA file and stream format"),
- sizeof(PVAContext),
- pva_probe,
- pva_read_header,
- pva_read_packet,
+ .name = "pva",
+ .long_name = NULL_IF_CONFIG_SMALL("TechnoTrend PVA file and stream format"),
+ .priv_data_size = sizeof(PVAContext),
+ .read_probe = pva_probe,
+ .read_header = pva_read_header,
+ .read_packet = pva_read_packet,
.read_timestamp = pva_read_timestamp
};
diff --git a/libavformat/qcp.c b/libavformat/qcp.c
index 635d531f44..c88c39b25d 100644
--- a/libavformat/qcp.c
+++ b/libavformat/qcp.c
@@ -2,20 +2,20 @@
* QCP format (.qcp) demuxer
* Copyright (c) 2009 Kenan Gillet
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -23,7 +23,7 @@
* @file
* QCP format (.qcp) demuxer
* @author Kenan Gillet
- * @sa RFC 3625: "The QCP File Format and Media Types for Speech Data"
+ * @see RFC 3625: "The QCP File Format and Media Types for Speech Data"
* http://tools.ietf.org/html/rfc3625
*/
@@ -84,7 +84,7 @@ static int qcp_read_header(AVFormatContext *s, AVFormatParameters *ap)
{
AVIOContext *pb = s->pb;
QCPContext *c = s->priv_data;
- AVStream *st = av_new_stream(s, 0);
+ AVStream *st = avformat_new_stream(s, NULL);
uint8_t buf[16];
int i, nb_rates;
@@ -92,8 +92,7 @@ static int qcp_read_header(AVFormatContext *s, AVFormatParameters *ap)
return AVERROR(ENOMEM);
avio_rb32(pb); // "RIFF"
- s->file_size = avio_rl32(pb) + 8;
- avio_skip(pb, 8 + 4 + 1 + 1); // "QLCMfmt " + chunk-size + major-version + minor-version
+ avio_skip(pb, 4 + 8 + 4 + 1 + 1); // filesize + "QLCMfmt " + chunk-size + major-version + minor-version
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
st->codec->channels = 1;
@@ -140,7 +139,7 @@ static int qcp_read_packet(AVFormatContext *s, AVPacket *pkt)
QCPContext *c = s->priv_data;
unsigned int chunk_size, tag;
- while(!pb->eof_reached) {
+ while(!url_feof(pb)) {
if (c->data_size) {
int pkt_size, ret, mode = avio_r8(pb);
diff --git a/libavformat/qtpalette.h b/libavformat/qtpalette.h
index ecc85d3408..7d6802f73c 100644
--- a/libavformat/qtpalette.h
+++ b/libavformat/qtpalette.h
@@ -3,20 +3,20 @@
* Automatically generated from a utility derived from XAnim:
* http://xanim.va.pubnix.com/home.html
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/r3d.c b/libavformat/r3d.c
index 5dd7f997e5..75fc4a4c96 100644
--- a/libavformat/r3d.c
+++ b/libavformat/r3d.c
@@ -2,20 +2,20 @@
* R3D REDCODE demuxer
* Copyright (c) 2008 Baptiste Coudurier <baptiste dot coudurier at gmail dot com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -52,7 +52,7 @@ static int read_atom(AVFormatContext *s, Atom *atom)
static int r3d_read_red1(AVFormatContext *s)
{
- AVStream *st = av_new_stream(s, 0);
+ AVStream *st = avformat_new_stream(s, NULL);
char filename[258];
int tmp;
int av_unused tmp2;
@@ -89,7 +89,7 @@ static int r3d_read_red1(AVFormatContext *s)
tmp = avio_r8(s->pb); // audio channels
av_dlog(s, "audio channels %d\n", tmp);
if (tmp > 0) {
- AVStream *ast = av_new_stream(s, 1);
+ AVStream *ast = avformat_new_stream(s, NULL);
if (!ast)
return AVERROR(ENOMEM);
ast->codec->codec_type = AVMEDIA_TYPE_AUDIO;
@@ -365,7 +365,8 @@ static int r3d_seek(AVFormatContext *s, int stream_index, int64_t sample_time, i
frame_num, sample_time);
if (frame_num < r3d->video_offsets_count) {
- avio_seek(s->pb, r3d->video_offsets_count, SEEK_SET);
+ if (avio_seek(s->pb, r3d->video_offsets_count, SEEK_SET) < 0)
+ return -1;
} else {
av_log(s, AV_LOG_ERROR, "could not seek to frame %d\n", frame_num);
return -1;
@@ -384,12 +385,12 @@ static int r3d_close(AVFormatContext *s)
}
AVInputFormat ff_r3d_demuxer = {
- "r3d",
- NULL_IF_CONFIG_SMALL("REDCODE R3D format"),
- sizeof(R3DContext),
- r3d_probe,
- r3d_read_header,
- r3d_read_packet,
- r3d_close,
- r3d_seek,
+ .name = "r3d",
+ .long_name = NULL_IF_CONFIG_SMALL("REDCODE R3D format"),
+ .priv_data_size = sizeof(R3DContext),
+ .read_probe = r3d_probe,
+ .read_header = r3d_read_header,
+ .read_packet = r3d_read_packet,
+ .read_close = r3d_close,
+ .read_seek = r3d_seek,
};
diff --git a/libavformat/rawdec.c b/libavformat/rawdec.c
index cc05c353e9..37e9b0c8f1 100644
--- a/libavformat/rawdec.c
+++ b/libavformat/rawdec.c
@@ -3,20 +3,20 @@
* Copyright (c) 2001 Fabrice Bellard
* Copyright (c) 2005 Alex Beregszaszi
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -33,7 +33,7 @@ int ff_raw_read_header(AVFormatContext *s, AVFormatParameters *ap)
AVStream *st;
enum CodecID id;
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
@@ -49,17 +49,14 @@ int ff_raw_read_header(AVFormatContext *s, AVFormatParameters *ap)
case AVMEDIA_TYPE_AUDIO: {
RawAudioDemuxerContext *s1 = s->priv_data;
-#if FF_API_FORMAT_PARAMETERS
- if (ap->sample_rate)
- st->codec->sample_rate = ap->sample_rate;
- if (ap->channels)
- st->codec->channels = ap->channels;
- else st->codec->channels = 1;
-#endif
+ st->codec->channels = 1;
+
+ if (id == CODEC_ID_ADPCM_G722)
+ st->codec->sample_rate = 16000;
- if (s1->sample_rate)
+ if (s1 && s1->sample_rate)
st->codec->sample_rate = s1->sample_rate;
- if (s1->channels)
+ if (s1 && s1->channels)
st->codec->channels = s1->channels;
st->codec->bits_per_coded_sample = av_get_bits_per_sample(st->codec->codec_id);
@@ -87,16 +84,6 @@ int ff_raw_read_header(AVFormatContext *s, AVFormatParameters *ap)
av_log(s, AV_LOG_ERROR, "Could not parse framerate: %s.\n", s1->framerate);
goto fail;
}
-#if FF_API_FORMAT_PARAMETERS
- if (ap->width > 0)
- width = ap->width;
- if (ap->height > 0)
- height = ap->height;
- if (ap->pix_fmt)
- pix_fmt = ap->pix_fmt;
- if (ap->time_base.num)
- framerate = (AVRational){ap->time_base.den, ap->time_base.num};
-#endif
av_set_pts_info(st, 64, framerate.den, framerate.num);
st->codec->width = width;
st->codec->height = height;
@@ -135,12 +122,13 @@ int ff_raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
int ff_raw_audio_read_header(AVFormatContext *s,
AVFormatParameters *ap)
{
- AVStream *st = av_new_stream(s, 0);
+ AVStream *st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
st->codec->codec_id = s->iformat->value;
st->need_parsing = AVSTREAM_PARSE_FULL;
+ st->start_time = 0;
/* the parameters will be extracted from the compressed bitstream */
return 0;
@@ -156,7 +144,7 @@ int ff_raw_video_read_header(AVFormatContext *s,
int ret = 0;
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st) {
ret = AVERROR(ENOMEM);
goto fail;
@@ -170,10 +158,6 @@ int ff_raw_video_read_header(AVFormatContext *s,
av_log(s, AV_LOG_ERROR, "Could not parse framerate: %s.\n", s1->framerate);
goto fail;
}
-#if FF_API_FORMAT_PARAMETERS
- if (ap->time_base.num)
- framerate = (AVRational){ap->time_base.den, ap->time_base.num};
-#endif
st->codec->time_base = (AVRational){framerate.den, framerate.num};
av_set_pts_info(st, 64, 1, 1200000);
@@ -184,78 +168,59 @@ fail:
/* Note: Do not forget to add new entries to the Makefile as well. */
-static const AVOption audio_options[] = {
- { "sample_rate", "", offsetof(RawAudioDemuxerContext, sample_rate), FF_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
- { "channels", "", offsetof(RawAudioDemuxerContext, channels), FF_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
- { NULL },
-};
-
-const AVClass ff_rawaudio_demuxer_class = {
- .class_name = "rawaudio demuxer",
- .item_name = av_default_item_name,
- .option = audio_options,
- .version = LIBAVUTIL_VERSION_INT,
-};
-
#define OFFSET(x) offsetof(FFRawVideoDemuxerContext, x)
#define DEC AV_OPT_FLAG_DECODING_PARAM
-static const AVOption video_options[] = {
- { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), FF_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
- { "pixel_format", "", OFFSET(pixel_format), FF_OPT_TYPE_STRING, {.str = "yuv420p"}, 0, 0, DEC },
- { "framerate", "", OFFSET(framerate), FF_OPT_TYPE_STRING, {.str = "25"}, 0, 0, DEC },
+const AVOption ff_rawvideo_options[] = {
+ { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0, DEC},
{ NULL },
};
-#undef OFFSET
-#undef DEC
-
-const AVClass ff_rawvideo_demuxer_class = {
- .class_name = "rawvideo demuxer",
- .item_name = av_default_item_name,
- .option = video_options,
- .version = LIBAVUTIL_VERSION_INT,
-};
#if CONFIG_G722_DEMUXER
AVInputFormat ff_g722_demuxer = {
- "g722",
- NULL_IF_CONFIG_SMALL("raw G.722"),
- sizeof(RawAudioDemuxerContext),
- NULL,
- ff_raw_read_header,
- ff_raw_read_partial_packet,
+ .name = "g722",
+ .long_name = NULL_IF_CONFIG_SMALL("raw G.722"),
+ .read_header = ff_raw_read_header,
+ .read_packet = ff_raw_read_partial_packet,
.flags= AVFMT_GENERIC_INDEX,
.extensions = "g722,722",
.value = CODEC_ID_ADPCM_G722,
- .priv_class = &ff_rawaudio_demuxer_class,
};
#endif
#if CONFIG_GSM_DEMUXER
AVInputFormat ff_gsm_demuxer = {
- "gsm",
- NULL_IF_CONFIG_SMALL("raw GSM"),
- 0,
- NULL,
- ff_raw_audio_read_header,
- ff_raw_read_partial_packet,
+ .name = "gsm",
+ .long_name = NULL_IF_CONFIG_SMALL("raw GSM"),
+ .read_header = ff_raw_audio_read_header,
+ .read_packet = ff_raw_read_partial_packet,
.flags= AVFMT_GENERIC_INDEX,
.extensions = "gsm",
.value = CODEC_ID_GSM,
};
#endif
+#if CONFIG_LATM_DEMUXER
+AVInputFormat ff_latm_demuxer = {
+ .name = "latm",
+ .long_name = NULL_IF_CONFIG_SMALL("raw LOAS/LATM"),
+ .read_header = ff_raw_audio_read_header,
+ .read_packet = ff_raw_read_partial_packet,
+ .flags= AVFMT_GENERIC_INDEX,
+ .extensions = "latm",
+ .value = CODEC_ID_AAC_LATM,
+};
+#endif
+
#if CONFIG_MJPEG_DEMUXER
FF_DEF_RAWVIDEO_DEMUXER(mjpeg, "raw MJPEG video", NULL, "mjpg,mjpeg", CODEC_ID_MJPEG)
#endif
#if CONFIG_MLP_DEMUXER
AVInputFormat ff_mlp_demuxer = {
- "mlp",
- NULL_IF_CONFIG_SMALL("raw MLP"),
- 0,
- NULL,
- ff_raw_audio_read_header,
- ff_raw_read_partial_packet,
+ .name = "mlp",
+ .long_name = NULL_IF_CONFIG_SMALL("raw MLP"),
+ .read_header = ff_raw_audio_read_header,
+ .read_packet = ff_raw_read_partial_packet,
.flags= AVFMT_GENERIC_INDEX,
.extensions = "mlp",
.value = CODEC_ID_MLP,
@@ -264,12 +229,10 @@ AVInputFormat ff_mlp_demuxer = {
#if CONFIG_TRUEHD_DEMUXER
AVInputFormat ff_truehd_demuxer = {
- "truehd",
- NULL_IF_CONFIG_SMALL("raw TrueHD"),
- 0,
- NULL,
- ff_raw_audio_read_header,
- ff_raw_read_partial_packet,
+ .name = "truehd",
+ .long_name = NULL_IF_CONFIG_SMALL("raw TrueHD"),
+ .read_header = ff_raw_audio_read_header,
+ .read_packet = ff_raw_read_partial_packet,
.flags= AVFMT_GENERIC_INDEX,
.extensions = "thd",
.value = CODEC_ID_TRUEHD,
@@ -278,13 +241,11 @@ AVInputFormat ff_truehd_demuxer = {
#if CONFIG_SHORTEN_DEMUXER
AVInputFormat ff_shorten_demuxer = {
- "shn",
- NULL_IF_CONFIG_SMALL("raw Shorten"),
- 0,
- NULL,
- ff_raw_audio_read_header,
- ff_raw_read_partial_packet,
- .flags= AVFMT_GENERIC_INDEX,
+ .name = "shn",
+ .long_name = NULL_IF_CONFIG_SMALL("raw Shorten"),
+ .read_header = ff_raw_audio_read_header,
+ .read_packet = ff_raw_read_partial_packet,
+ .flags = AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH | AVFMT_NO_BYTE_SEEK,
.extensions = "shn",
.value = CODEC_ID_SHORTEN,
};
diff --git a/libavformat/rawdec.h b/libavformat/rawdec.h
index 76e8053f6d..a2011ebcba 100644
--- a/libavformat/rawdec.h
+++ b/libavformat/rawdec.h
@@ -2,20 +2,20 @@
* RAW demuxers
* Copyright (C) 2007 Aurelien Jacobs <aurel@gnuage.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -24,6 +24,7 @@
#include "avformat.h"
#include "libavutil/log.h"
+#include "libavutil/opt.h"
typedef struct RawAudioDemuxerContext {
AVClass *class;
@@ -38,8 +39,7 @@ typedef struct FFRawVideoDemuxerContext {
char *framerate; /**< String describing framerate, set by a private option. */
} FFRawVideoDemuxerContext;
-extern const AVClass ff_rawaudio_demuxer_class;
-extern const AVClass ff_rawvideo_demuxer_class;
+extern const AVOption ff_rawvideo_options[];
int ff_raw_read_header(AVFormatContext *s, AVFormatParameters *ap);
@@ -49,7 +49,16 @@ int ff_raw_audio_read_header(AVFormatContext *s, AVFormatParameters *ap);
int ff_raw_video_read_header(AVFormatContext *s, AVFormatParameters *ap);
+#define FF_RAWVIDEO_DEMUXER_CLASS(name)\
+static const AVClass name ## _demuxer_class = {\
+ .class_name = #name " demuxer",\
+ .item_name = av_default_item_name,\
+ .option = ff_rawvideo_options,\
+ .version = LIBAVUTIL_VERSION_INT,\
+};
+
#define FF_DEF_RAWVIDEO_DEMUXER(shortname, longname, probe, ext, id)\
+FF_RAWVIDEO_DEMUXER_CLASS(shortname)\
AVInputFormat ff_ ## shortname ## _demuxer = {\
.name = #shortname,\
.long_name = NULL_IF_CONFIG_SMALL(longname),\
@@ -60,7 +69,7 @@ AVInputFormat ff_ ## shortname ## _demuxer = {\
.flags = AVFMT_GENERIC_INDEX,\
.value = id,\
.priv_data_size = sizeof(FFRawVideoDemuxerContext),\
- .priv_class = &ff_rawvideo_demuxer_class,\
+ .priv_class = &shortname ## _demuxer_class,\
};
#endif /* AVFORMAT_RAWDEC_H */
diff --git a/libavformat/rawenc.c b/libavformat/rawenc.c
index 00e43df9a7..b2ff79abf3 100644
--- a/libavformat/rawenc.c
+++ b/libavformat/rawenc.c
@@ -3,20 +3,20 @@
* Copyright (c) 2001 Fabrice Bellard
* Copyright (c) 2005 Alex Beregszaszi
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -34,195 +34,176 @@ int ff_raw_write_packet(AVFormatContext *s, AVPacket *pkt)
#if CONFIG_AC3_MUXER
AVOutputFormat ff_ac3_muxer = {
- "ac3",
- NULL_IF_CONFIG_SMALL("raw AC-3"),
- "audio/x-ac3",
- "ac3",
- 0,
- CODEC_ID_AC3,
- CODEC_ID_NONE,
- NULL,
- ff_raw_write_packet,
+ .name = "ac3",
+ .long_name = NULL_IF_CONFIG_SMALL("raw AC-3"),
+ .mime_type = "audio/x-ac3",
+ .extensions = "ac3",
+ .audio_codec = CODEC_ID_AC3,
+ .video_codec = CODEC_ID_NONE,
+ .write_packet = ff_raw_write_packet,
.flags= AVFMT_NOTIMESTAMPS,
};
#endif
#if CONFIG_DIRAC_MUXER
AVOutputFormat ff_dirac_muxer = {
- "dirac",
- NULL_IF_CONFIG_SMALL("raw Dirac"),
- NULL,
- "drc",
- 0,
- CODEC_ID_NONE,
- CODEC_ID_DIRAC,
- NULL,
- ff_raw_write_packet,
+ .name = "dirac",
+ .long_name = NULL_IF_CONFIG_SMALL("raw Dirac"),
+ .extensions = "drc",
+ .audio_codec = CODEC_ID_NONE,
+ .video_codec = CODEC_ID_DIRAC,
+ .write_packet = ff_raw_write_packet,
.flags= AVFMT_NOTIMESTAMPS,
};
#endif
#if CONFIG_DNXHD_MUXER
AVOutputFormat ff_dnxhd_muxer = {
- "dnxhd",
- NULL_IF_CONFIG_SMALL("raw DNxHD (SMPTE VC-3)"),
- NULL,
- "dnxhd",
- 0,
- CODEC_ID_NONE,
- CODEC_ID_DNXHD,
- NULL,
- ff_raw_write_packet,
+ .name = "dnxhd",
+ .long_name = NULL_IF_CONFIG_SMALL("raw DNxHD (SMPTE VC-3)"),
+ .extensions = "dnxhd",
+ .audio_codec = CODEC_ID_NONE,
+ .video_codec = CODEC_ID_DNXHD,
+ .write_packet = ff_raw_write_packet,
.flags= AVFMT_NOTIMESTAMPS,
};
#endif
#if CONFIG_DTS_MUXER
AVOutputFormat ff_dts_muxer = {
- "dts",
- NULL_IF_CONFIG_SMALL("raw DTS"),
- "audio/x-dca",
- "dts",
- 0,
- CODEC_ID_DTS,
- CODEC_ID_NONE,
- NULL,
- ff_raw_write_packet,
+ .name = "dts",
+ .long_name = NULL_IF_CONFIG_SMALL("raw DTS"),
+ .mime_type = "audio/x-dca",
+ .extensions = "dts",
+ .audio_codec = CODEC_ID_DTS,
+ .video_codec = CODEC_ID_NONE,
+ .write_packet = ff_raw_write_packet,
.flags= AVFMT_NOTIMESTAMPS,
};
#endif
#if CONFIG_EAC3_MUXER
AVOutputFormat ff_eac3_muxer = {
- "eac3",
- NULL_IF_CONFIG_SMALL("raw E-AC-3"),
- "audio/x-eac3",
- "eac3",
- 0,
- CODEC_ID_EAC3,
- CODEC_ID_NONE,
- NULL,
- ff_raw_write_packet,
+ .name = "eac3",
+ .long_name = NULL_IF_CONFIG_SMALL("raw E-AC-3"),
+ .mime_type = "audio/x-eac3",
+ .extensions = "eac3",
+ .audio_codec = CODEC_ID_EAC3,
+ .video_codec = CODEC_ID_NONE,
+ .write_packet = ff_raw_write_packet,
.flags= AVFMT_NOTIMESTAMPS,
};
#endif
#if CONFIG_G722_MUXER
AVOutputFormat ff_g722_muxer = {
- "g722",
- NULL_IF_CONFIG_SMALL("raw G.722"),
- "audio/G722",
- "g722",
- 0,
- CODEC_ID_ADPCM_G722,
- CODEC_ID_NONE,
- NULL,
- ff_raw_write_packet,
+ .name = "g722",
+ .long_name = NULL_IF_CONFIG_SMALL("raw G.722"),
+ .mime_type = "audio/G722",
+ .extensions = "g722",
+ .audio_codec = CODEC_ID_ADPCM_G722,
+ .video_codec = CODEC_ID_NONE,
+ .write_packet = ff_raw_write_packet,
+ .flags= AVFMT_NOTIMESTAMPS,
+};
+#endif
+
+#if CONFIG_G723_1_MUXER
+AVOutputFormat ff_g723_1_muxer = {
+ .name = "g723_1",
+ .long_name = NULL_IF_CONFIG_SMALL("raw G.723.1"),
+ .mime_type = "audio/g723",
+ .extensions = "tco,rco",
+ .audio_codec = CODEC_ID_G723_1,
+ .video_codec = CODEC_ID_NONE,
+ .write_packet = ff_raw_write_packet,
.flags= AVFMT_NOTIMESTAMPS,
};
#endif
#if CONFIG_H261_MUXER
AVOutputFormat ff_h261_muxer = {
- "h261",
- NULL_IF_CONFIG_SMALL("raw H.261"),
- "video/x-h261",
- "h261",
- 0,
- CODEC_ID_NONE,
- CODEC_ID_H261,
- NULL,
- ff_raw_write_packet,
+ .name = "h261",
+ .long_name = NULL_IF_CONFIG_SMALL("raw H.261"),
+ .mime_type = "video/x-h261",
+ .extensions = "h261",
+ .audio_codec = CODEC_ID_NONE,
+ .video_codec = CODEC_ID_H261,
+ .write_packet = ff_raw_write_packet,
.flags= AVFMT_NOTIMESTAMPS,
};
#endif
#if CONFIG_H263_MUXER
AVOutputFormat ff_h263_muxer = {
- "h263",
- NULL_IF_CONFIG_SMALL("raw H.263"),
- "video/x-h263",
- "h263",
- 0,
- CODEC_ID_NONE,
- CODEC_ID_H263,
- NULL,
- ff_raw_write_packet,
+ .name = "h263",
+ .long_name = NULL_IF_CONFIG_SMALL("raw H.263"),
+ .mime_type = "video/x-h263",
+ .extensions = "h263",
+ .audio_codec = CODEC_ID_NONE,
+ .video_codec = CODEC_ID_H263,
+ .write_packet = ff_raw_write_packet,
.flags= AVFMT_NOTIMESTAMPS,
};
#endif
#if CONFIG_H264_MUXER
AVOutputFormat ff_h264_muxer = {
- "h264",
- NULL_IF_CONFIG_SMALL("raw H.264 video format"),
- NULL,
- "h264",
- 0,
- CODEC_ID_NONE,
- CODEC_ID_H264,
- NULL,
- ff_raw_write_packet,
+ .name = "h264",
+ .long_name = NULL_IF_CONFIG_SMALL("raw H.264 video format"),
+ .extensions = "h264",
+ .audio_codec = CODEC_ID_NONE,
+ .video_codec = CODEC_ID_H264,
+ .write_packet = ff_raw_write_packet,
.flags= AVFMT_NOTIMESTAMPS,
};
#endif
#if CONFIG_CAVSVIDEO_MUXER
AVOutputFormat ff_cavsvideo_muxer = {
- "cavsvideo",
- NULL_IF_CONFIG_SMALL("raw Chinese AVS video"),
- NULL,
- "cavs",
- 0,
- CODEC_ID_NONE,
- CODEC_ID_CAVS,
- NULL,
- ff_raw_write_packet,
+ .name = "cavsvideo",
+ .long_name = NULL_IF_CONFIG_SMALL("raw Chinese AVS video"),
+ .extensions = "cavs",
+ .audio_codec = CODEC_ID_NONE,
+ .video_codec = CODEC_ID_CAVS,
+ .write_packet = ff_raw_write_packet,
.flags= AVFMT_NOTIMESTAMPS,
};
#endif
#if CONFIG_M4V_MUXER
AVOutputFormat ff_m4v_muxer = {
- "m4v",
- NULL_IF_CONFIG_SMALL("raw MPEG-4 video format"),
- NULL,
- "m4v",
- 0,
- CODEC_ID_NONE,
- CODEC_ID_MPEG4,
- NULL,
- ff_raw_write_packet,
+ .name = "m4v",
+ .long_name = NULL_IF_CONFIG_SMALL("raw MPEG-4 video format"),
+ .extensions = "m4v",
+ .audio_codec = CODEC_ID_NONE,
+ .video_codec = CODEC_ID_MPEG4,
+ .write_packet = ff_raw_write_packet,
.flags= AVFMT_NOTIMESTAMPS,
};
#endif
#if CONFIG_MJPEG_MUXER
AVOutputFormat ff_mjpeg_muxer = {
- "mjpeg",
- NULL_IF_CONFIG_SMALL("raw MJPEG video"),
- "video/x-mjpeg",
- "mjpg,mjpeg",
- 0,
- CODEC_ID_NONE,
- CODEC_ID_MJPEG,
- NULL,
- ff_raw_write_packet,
+ .name = "mjpeg",
+ .long_name = NULL_IF_CONFIG_SMALL("raw MJPEG video"),
+ .mime_type = "video/x-mjpeg",
+ .extensions = "mjpg,mjpeg",
+ .audio_codec = CODEC_ID_NONE,
+ .video_codec = CODEC_ID_MJPEG,
+ .write_packet = ff_raw_write_packet,
.flags= AVFMT_NOTIMESTAMPS,
};
#endif
#if CONFIG_MLP_MUXER
AVOutputFormat ff_mlp_muxer = {
- "mlp",
- NULL_IF_CONFIG_SMALL("raw MLP"),
- NULL,
- "mlp",
- 0,
- CODEC_ID_MLP,
- CODEC_ID_NONE,
- NULL,
- ff_raw_write_packet,
+ .name = "mlp",
+ .long_name = NULL_IF_CONFIG_SMALL("raw MLP"),
+ .extensions = "mlp",
+ .audio_codec = CODEC_ID_MLP,
+ .video_codec = CODEC_ID_NONE,
+ .write_packet = ff_raw_write_packet,
.flags= AVFMT_NOTIMESTAMPS,
};
#endif
@@ -241,60 +222,49 @@ AVOutputFormat ff_srt_muxer = {
#if CONFIG_TRUEHD_MUXER
AVOutputFormat ff_truehd_muxer = {
- "truehd",
- NULL_IF_CONFIG_SMALL("raw TrueHD"),
- NULL,
- "thd",
- 0,
- CODEC_ID_TRUEHD,
- CODEC_ID_NONE,
- NULL,
- ff_raw_write_packet,
+ .name = "truehd",
+ .long_name = NULL_IF_CONFIG_SMALL("raw TrueHD"),
+ .extensions = "thd",
+ .audio_codec = CODEC_ID_TRUEHD,
+ .video_codec = CODEC_ID_NONE,
+ .write_packet = ff_raw_write_packet,
.flags= AVFMT_NOTIMESTAMPS,
};
#endif
#if CONFIG_MPEG1VIDEO_MUXER
AVOutputFormat ff_mpeg1video_muxer = {
- "mpeg1video",
- NULL_IF_CONFIG_SMALL("raw MPEG-1 video"),
- "video/x-mpeg",
- "mpg,mpeg,m1v",
- 0,
- CODEC_ID_NONE,
- CODEC_ID_MPEG1VIDEO,
- NULL,
- ff_raw_write_packet,
+ .name = "mpeg1video",
+ .long_name = NULL_IF_CONFIG_SMALL("raw MPEG-1 video"),
+ .mime_type = "video/x-mpeg",
+ .extensions = "mpg,mpeg,m1v",
+ .audio_codec = CODEC_ID_NONE,
+ .video_codec = CODEC_ID_MPEG1VIDEO,
+ .write_packet = ff_raw_write_packet,
.flags= AVFMT_NOTIMESTAMPS,
};
#endif
#if CONFIG_MPEG2VIDEO_MUXER
AVOutputFormat ff_mpeg2video_muxer = {
- "mpeg2video",
- NULL_IF_CONFIG_SMALL("raw MPEG-2 video"),
- NULL,
- "m2v",
- 0,
- CODEC_ID_NONE,
- CODEC_ID_MPEG2VIDEO,
- NULL,
- ff_raw_write_packet,
+ .name = "mpeg2video",
+ .long_name = NULL_IF_CONFIG_SMALL("raw MPEG-2 video"),
+ .extensions = "m2v",
+ .audio_codec = CODEC_ID_NONE,
+ .video_codec = CODEC_ID_MPEG2VIDEO,
+ .write_packet = ff_raw_write_packet,
.flags= AVFMT_NOTIMESTAMPS,
};
#endif
#if CONFIG_RAWVIDEO_MUXER
AVOutputFormat ff_rawvideo_muxer = {
- "rawvideo",
- NULL_IF_CONFIG_SMALL("raw video format"),
- NULL,
- "yuv,rgb",
- 0,
- CODEC_ID_NONE,
- CODEC_ID_RAWVIDEO,
- NULL,
- ff_raw_write_packet,
+ .name = "rawvideo",
+ .long_name = NULL_IF_CONFIG_SMALL("raw video format"),
+ .extensions = "yuv,rgb",
+ .audio_codec = CODEC_ID_NONE,
+ .video_codec = CODEC_ID_RAWVIDEO,
+ .write_packet = ff_raw_write_packet,
.flags= AVFMT_NOTIMESTAMPS,
};
#endif
diff --git a/libavformat/rawenc.h b/libavformat/rawenc.h
index daa5489da8..b5523090b8 100644
--- a/libavformat/rawenc.h
+++ b/libavformat/rawenc.h
@@ -2,20 +2,20 @@
* RAW muxers
* Copyright (C) 2007 Aurelien Jacobs <aurel@gnuage.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/rawvideodec.c b/libavformat/rawvideodec.c
index f8d9b65f36..8bd0dc92f0 100644
--- a/libavformat/rawvideodec.c
+++ b/libavformat/rawvideodec.c
@@ -2,20 +2,20 @@
* RAW video demuxer
* Copyright (c) 2001 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -44,15 +44,30 @@ static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt)
return 0;
}
+#define OFFSET(x) offsetof(FFRawVideoDemuxerContext, x)
+#define DEC AV_OPT_FLAG_DECODING_PARAM
+static const AVOption rawvideo_options[] = {
+ { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
+ { "pixel_format", "", OFFSET(pixel_format), AV_OPT_TYPE_STRING, {.str = "yuv420p"}, 0, 0, DEC },
+ { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0, DEC },
+ { NULL },
+};
+
+static const AVClass rawvideo_demuxer_class = {
+ .class_name = "rawvideo demuxer",
+ .item_name = av_default_item_name,
+ .option = rawvideo_options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
AVInputFormat ff_rawvideo_demuxer = {
- "rawvideo",
- NULL_IF_CONFIG_SMALL("raw video format"),
- sizeof(FFRawVideoDemuxerContext),
- NULL,
- ff_raw_read_header,
- rawvideo_read_packet,
+ .name = "rawvideo",
+ .long_name = NULL_IF_CONFIG_SMALL("raw video format"),
+ .priv_data_size = sizeof(FFRawVideoDemuxerContext),
+ .read_header = ff_raw_read_header,
+ .read_packet = rawvideo_read_packet,
.flags= AVFMT_GENERIC_INDEX,
.extensions = "yuv,cif,qcif,rgb",
.value = CODEC_ID_RAWVIDEO,
- .priv_class = &ff_rawvideo_demuxer_class,
+ .priv_class = &rawvideo_demuxer_class,
};
diff --git a/libavformat/rdt.c b/libavformat/rdt.c
index 9155cfc480..74f9c55fba 100644
--- a/libavformat/rdt.c
+++ b/libavformat/rdt.c
@@ -2,20 +2,20 @@
* Realmedia RTSP protocol (RDT) support.
* Copyright (c) 2007 Ronald S. Bultje
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -459,8 +459,9 @@ add_dstream(AVFormatContext *s, AVStream *orig_st)
{
AVStream *st;
- if (!(st = av_new_stream(s, orig_st->id)))
+ if (!(st = avformat_new_stream(s, NULL)))
return NULL;
+ st->id = orig_st->id;
st->codec->codec_type = orig_st->codec->codec_type;
st->first_dts = orig_st->first_dts;
diff --git a/libavformat/rdt.h b/libavformat/rdt.h
index 08b17bc397..c2ec94b8b4 100644
--- a/libavformat/rdt.h
+++ b/libavformat/rdt.h
@@ -2,20 +2,20 @@
* Realmedia RTSP (RDT) definitions
* Copyright (c) 2007 Ronald S. Bultje <rbultje@ronald.bitfreak.net>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -80,16 +80,16 @@ void ff_rdt_subscribe_rule(char *cmd, int size,
*
* @param buf input buffer
* @param len length of input buffer
- * @param set_id will be set to the set ID this packet belongs to
- * @param seq_no will be set to the sequence number of the packet
- * @param stream_id will be set to the stream ID this packet belongs to
- * @param is_keyframe will be whether this packet belongs to a keyframe
- * @param timestamp will be set to the timestamp of the packet
+ * @param pset_id will be set to the set ID this packet belongs to
+ * @param pseq_no will be set to the sequence number of the packet
+ * @param pstream_id will be set to the stream ID this packet belongs to
+ * @param pis_keyframe will be whether this packet belongs to a keyframe
+ * @param ptimestamp will be set to the timestamp of the packet
* @return the amount of bytes consumed, or negative on error
*/
int ff_rdt_parse_header(const uint8_t *buf, int len,
- int *set_id, int *seq_no, int *stream_id,
- int *is_keyframe, uint32_t *timestamp);
+ int *pset_id, int *pseq_no, int *pstream_id,
+ int *pis_keyframe, uint32_t *ptimestamp);
/**
* Parse RDT-style packet data (header + media data).
diff --git a/libavformat/riff.c b/libavformat/riff.c
index 27f45b91d9..7492df7c0b 100644
--- a/libavformat/riff.c
+++ b/libavformat/riff.c
@@ -2,20 +2,20 @@
* RIFF codec tags
* Copyright (c) 2000 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -36,6 +36,7 @@ const AVCodecTag ff_codec_bmp_tags[] = {
{ CODEC_ID_H264, MKTAG('a', 'v', 'c', '1') },
{ CODEC_ID_H264, MKTAG('D', 'A', 'V', 'C') },
{ CODEC_ID_H264, MKTAG('V', 'S', 'S', 'H') },
+ { CODEC_ID_H264, MKTAG('Q', '2', '6', '4') }, /* QNAP surveillance system */
{ CODEC_ID_H263, MKTAG('H', '2', '6', '3') },
{ CODEC_ID_H263, MKTAG('X', '2', '6', '3') },
{ CODEC_ID_H263, MKTAG('T', '2', '6', '3') },
@@ -87,6 +88,8 @@ const AVCodecTag ff_codec_bmp_tags[] = {
{ CODEC_ID_MPEG4, MKTAG('G', 'E', 'O', 'V') },
{ CODEC_ID_MPEG4, MKTAG('S', 'I', 'P', 'P') }, /* Samsung SHR-6040 */
{ CODEC_ID_MPEG4, MKTAG('X', 'V', 'I', 'X') },
+ { CODEC_ID_MPEG4, MKTAG('D', 'r', 'e', 'X') },
+ { CODEC_ID_MPEG4, MKTAG('Q', 'M', 'P', '4') }, /* QNAP Systems */
{ CODEC_ID_MSMPEG4V3, MKTAG('M', 'P', '4', '3') },
{ CODEC_ID_MSMPEG4V3, MKTAG('D', 'I', 'V', '3') },
{ CODEC_ID_MSMPEG4V3, MKTAG('M', 'P', 'G', '3') },
@@ -131,6 +134,7 @@ const AVCodecTag ff_codec_bmp_tags[] = {
{ CODEC_ID_MPEG2VIDEO, MKTAG('s', 'l', 'i', 'f') },
{ CODEC_ID_MPEG2VIDEO, MKTAG('E', 'M', '2', 'V') },
{ CODEC_ID_MPEG2VIDEO, MKTAG('M', '7', '0', '1') }, /* Matrox MPEG2 intra-only */
+ { CODEC_ID_MPEG2VIDEO, MKTAG('m', 'p', 'g', 'v') },
{ CODEC_ID_MJPEG, MKTAG('M', 'J', 'P', 'G') },
{ CODEC_ID_MJPEG, MKTAG('L', 'J', 'P', 'G') },
{ CODEC_ID_MJPEG, MKTAG('d', 'm', 'b', '1') },
@@ -172,10 +176,13 @@ const AVCodecTag ff_codec_bmp_tags[] = {
{ CODEC_ID_RAWVIDEO, MKTAG('y', 'u', 'v', 's') },
{ CODEC_ID_RAWVIDEO, MKTAG('P', '4', '2', '2') },
{ CODEC_ID_RAWVIDEO, MKTAG('Y', 'V', '1', '2') },
+ { CODEC_ID_RAWVIDEO, MKTAG('Y', 'V', '1', '6') },
+ { CODEC_ID_RAWVIDEO, MKTAG('Y', 'V', '2', '4') },
{ CODEC_ID_RAWVIDEO, MKTAG('U', 'Y', 'V', 'Y') },
{ CODEC_ID_RAWVIDEO, MKTAG('V', 'Y', 'U', 'Y') },
{ CODEC_ID_RAWVIDEO, MKTAG('I', 'Y', 'U', 'V') },
{ CODEC_ID_RAWVIDEO, MKTAG('Y', '8', '0', '0') },
+ { CODEC_ID_RAWVIDEO, MKTAG('Y', '8', ' ', ' ') },
{ CODEC_ID_RAWVIDEO, MKTAG('H', 'D', 'Y', 'C') },
{ CODEC_ID_RAWVIDEO, MKTAG('Y', 'V', 'U', '9') },
{ CODEC_ID_RAWVIDEO, MKTAG('V', 'D', 'T', 'Z') }, /* SoftLab-NSK VideoTizer */
@@ -236,10 +243,10 @@ const AVCodecTag ff_codec_bmp_tags[] = {
{ CODEC_ID_QPEG, MKTAG('Q', '1', '.', '0') },
{ CODEC_ID_QPEG, MKTAG('Q', '1', '.', '1') },
{ CODEC_ID_WMV3, MKTAG('W', 'M', 'V', '3') },
- { CODEC_ID_WMV3, MKTAG('W', 'M', 'V', 'P') },
+ { CODEC_ID_WMV3IMAGE, MKTAG('W', 'M', 'V', 'P') },
{ CODEC_ID_VC1, MKTAG('W', 'V', 'C', '1') },
{ CODEC_ID_VC1, MKTAG('W', 'M', 'V', 'A') },
- { CODEC_ID_VC1, MKTAG('W', 'V', 'P', '2') },
+ { CODEC_ID_VC1IMAGE, MKTAG('W', 'V', 'P', '2') },
{ CODEC_ID_LOCO, MKTAG('L', 'O', 'C', 'O') },
{ CODEC_ID_WNV1, MKTAG('W', 'N', 'V', '1') },
{ CODEC_ID_AASC, MKTAG('A', 'A', 'S', 'C') },
@@ -253,6 +260,8 @@ const AVCodecTag ff_codec_bmp_tags[] = {
{ CODEC_ID_CAVS, MKTAG('C', 'A', 'V', 'S') },
{ CODEC_ID_JPEG2000, MKTAG('m', 'j', 'p', '2') },
{ CODEC_ID_JPEG2000, MKTAG('M', 'J', '2', 'C') },
+ { CODEC_ID_JPEG2000, MKTAG('L', 'J', '2', 'C') },
+ { CODEC_ID_JPEG2000, MKTAG('L', 'J', '2', 'K') },
{ CODEC_ID_VMNC, MKTAG('V', 'M', 'n', 'c') },
{ CODEC_ID_TARGA, MKTAG('t', 'g', 'a', ' ') },
{ CODEC_ID_PNG, MKTAG('M', 'P', 'N', 'G') },
@@ -268,6 +277,14 @@ const AVCodecTag ff_codec_bmp_tags[] = {
{ CODEC_ID_DPX, MKTAG('d', 'p', 'x', ' ') },
{ CODEC_ID_KGV1, MKTAG('K', 'G', 'V', '1') },
{ CODEC_ID_LAGARITH, MKTAG('L', 'A', 'G', 'S') },
+ { CODEC_ID_G2M, MKTAG('G', '2', 'M', '2') },
+ { CODEC_ID_G2M, MKTAG('G', '2', 'M', '3') },
+ { CODEC_ID_G2M, MKTAG('G', '2', 'M', '4') },
+ { CODEC_ID_AMV, MKTAG('A', 'M', 'V', 'F') },
+ { CODEC_ID_UTVIDEO, MKTAG('U', 'L', 'R', 'A') },
+ { CODEC_ID_UTVIDEO, MKTAG('U', 'L', 'R', 'G') },
+ { CODEC_ID_UTVIDEO, MKTAG('U', 'L', 'Y', '0') },
+ { CODEC_ID_UTVIDEO, MKTAG('U', 'L', 'Y', '2') },
{ CODEC_ID_NONE, 0 }
};
@@ -287,6 +304,7 @@ const AVCodecTag ff_codec_wav_tags[] = {
{ CODEC_ID_ADPCM_YAMAHA, 0x0020 },
{ CODEC_ID_TRUESPEECH, 0x0022 },
{ CODEC_ID_GSM_MS, 0x0031 },
+ { CODEC_ID_AMR_NB, 0x0038 }, /* rogue format number */
{ CODEC_ID_ADPCM_G726, 0x0045 },
{ CODEC_ID_MP2, 0x0050 },
{ CODEC_ID_MP3, 0x0055 },
@@ -317,6 +335,7 @@ const AVCodecTag ff_codec_wav_tags[] = {
{ CODEC_ID_PCM_MULAW, 0x6c75 },
{ CODEC_ID_AAC, 0x706d },
{ CODEC_ID_AAC, 0x4143 },
+ { CODEC_ID_SPEEX, 0xA109 },
{ CODEC_ID_FLAC, 0xF1AC },
{ CODEC_ID_ADPCM_SWF, ('S'<<8)+'F' },
{ CODEC_ID_VORBIS, ('V'<<8)+'o' }, //HACK/FIXME, does vorbis in WAV/AVI have an (in)official id?
@@ -329,6 +348,14 @@ const AVCodecTag ff_codec_wav_tags[] = {
{ CODEC_ID_NONE, 0 },
};
+const AVCodecGuid ff_codec_wav_guids[] = {
+ {CODEC_ID_AC3, {0x2C,0x80,0x6D,0xE0,0x46,0xDB,0xCF,0x11,0xB4,0xD1,0x00,0x80,0x5F,0x6C,0xBB,0xEA}},
+ {CODEC_ID_ATRAC3P, {0xBF,0xAA,0x23,0xE9,0x58,0xCB,0x71,0x44,0xA1,0x19,0xFF,0xFA,0x01,0xE4,0xCE,0x62}},
+ {CODEC_ID_EAC3, {0xAF,0x87,0xFB,0xA7,0x02,0x2D,0xFB,0x42,0xA4,0xD4,0x05,0xCD,0x93,0x84,0x3B,0xDD}},
+ {CODEC_ID_MP2, {0x2B,0x80,0x6D,0xE0,0x46,0xDB,0xCF,0x11,0xB4,0xD1,0x00,0x80,0x5F,0x6C,0xBB,0xEA}},
+ {CODEC_ID_NONE}
+};
+
#if CONFIG_MUXERS
int64_t ff_start_tag(AVIOContext *pb, const char *tag)
{
@@ -431,20 +458,18 @@ int ff_put_wav_header(AVIOContext *pb, AVCodecContext *enc)
riff_extradata_start= enc->extradata;
riff_extradata= enc->extradata + enc->extradata_size;
hdrsize += enc->extradata_size;
- } else if (!waveformatextensible){
- hdrsize -= 2;
}
if(waveformatextensible) { /* write WAVEFORMATEXTENSIBLE extensions */
hdrsize += 22;
avio_wl16(pb, riff_extradata - riff_extradata_start + 22); /* 22 is WAVEFORMATEXTENSIBLE size */
- avio_wl16(pb, enc->bits_per_coded_sample); /* ValidBitsPerSample || SamplesPerBlock || Reserved */
+ avio_wl16(pb, bps); /* ValidBitsPerSample || SamplesPerBlock || Reserved */
avio_wl32(pb, enc->channel_layout); /* dwChannelMask */
avio_wl32(pb, enc->codec_tag); /* GUID + next 3 */
avio_wl32(pb, 0x00100000);
avio_wl32(pb, 0xAA000080);
avio_wl32(pb, 0x719B3800);
- } else if(riff_extradata - riff_extradata_start) {
- avio_wl16(pb, riff_extradata - riff_extradata_start);
+ } else {
+ avio_wl16(pb, riff_extradata - riff_extradata_start); /* cbSize */
}
avio_write(pb, riff_extradata_start, riff_extradata - riff_extradata_start);
if(hdrsize&1){
@@ -494,7 +519,6 @@ int ff_get_wav_header(AVIOContext *pb, AVCodecContext *codec, int size)
id = avio_rl16(pb);
codec->codec_type = AVMEDIA_TYPE_AUDIO;
- codec->codec_tag = id;
codec->channels = avio_rl16(pb);
codec->sample_rate = avio_rl32(pb);
codec->bit_rate = avio_rl32(pb) * 8;
@@ -503,15 +527,29 @@ int ff_get_wav_header(AVIOContext *pb, AVCodecContext *codec, int size)
codec->bits_per_coded_sample = 8;
}else
codec->bits_per_coded_sample = avio_rl16(pb);
+ if (id == 0xFFFE) {
+ codec->codec_tag = 0;
+ } else {
+ codec->codec_tag = id;
+ codec->codec_id = ff_wav_codec_get_id(id, codec->bits_per_coded_sample);
+ }
if (size >= 18) { /* We're obviously dealing with WAVEFORMATEX */
int cbSize = avio_rl16(pb); /* cbSize */
size -= 18;
cbSize = FFMIN(size, cbSize);
if (cbSize >= 22 && id == 0xfffe) { /* WAVEFORMATEXTENSIBLE */
+ ff_asf_guid subformat;
codec->bits_per_coded_sample = avio_rl16(pb);
codec->channel_layout = avio_rl32(pb); /* dwChannelMask */
- id = avio_rl32(pb); /* 4 first bytes of GUID */
- avio_skip(pb, 12); /* skip end of GUID */
+ ff_get_guid(pb, &subformat);
+ if (!memcmp(subformat + 4, (const uint8_t[]){FF_MEDIASUBTYPE_BASE_GUID}, 12)) {
+ codec->codec_tag = AV_RL32(subformat);
+ codec->codec_id = ff_wav_codec_get_id(codec->codec_tag, codec->bits_per_coded_sample);
+ } else {
+ codec->codec_id = ff_codec_guid_get_id(ff_codec_wav_guids, subformat);
+ if (!codec->codec_id)
+ av_log(codec, AV_LOG_WARNING, "unknown subformat:"FF_PRI_GUID"\n", FF_ARG_GUID(subformat));
+ }
cbSize -= 22;
size -= 22;
}
@@ -529,7 +567,6 @@ int ff_get_wav_header(AVIOContext *pb, AVCodecContext *codec, int size)
if (size > 0)
avio_skip(pb, size);
}
- codec->codec_id = ff_wav_codec_get_id(id, codec->bits_per_coded_sample);
if (codec->codec_id == CODEC_ID_AAC_LATM) {
/* channels and sample_rate values are those prior to applying SBR and/or PS */
codec->channels = 0;
@@ -599,3 +636,19 @@ void ff_parse_specific_params(AVCodecContext *stream, int *au_rate, int *au_ssiz
*au_scale /= gcd;
*au_rate /= gcd;
}
+
+void ff_get_guid(AVIOContext *s, ff_asf_guid *g)
+{
+ assert(sizeof(*g) == 16);
+ avio_read(s, *g, sizeof(*g));
+}
+
+enum CodecID ff_codec_guid_get_id(const AVCodecGuid *guids, ff_asf_guid guid)
+{
+ int i;
+ for (i = 0; guids[i].id != CODEC_ID_NONE; i++) {
+ if (!ff_guidcmp(guids[i].guid, guid))
+ return guids[i].id;
+ }
+ return CODEC_ID_NONE;
+}
diff --git a/libavformat/riff.h b/libavformat/riff.h
index a2fa8b7b1c..85caacbb69 100644
--- a/libavformat/riff.h
+++ b/libavformat/riff.h
@@ -2,20 +2,20 @@
* RIFF codec tags
* copyright (c) 2000 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -54,4 +54,30 @@ unsigned int ff_codec_get_tag(const AVCodecTag *tags, enum CodecID id);
enum CodecID ff_codec_get_id(const AVCodecTag *tags, unsigned int tag);
void ff_parse_specific_params(AVCodecContext *stream, int *au_rate, int *au_ssize, int *au_scale);
+typedef uint8_t ff_asf_guid[16];
+
+#define FF_PRI_GUID \
+ "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
+#define FF_ARG_GUID(g) \
+ g[0],g[1],g[2],g[3],g[4],g[5],g[6],g[7],g[8],g[9],g[10],g[11],g[12],g[13],g[14],g[15]
+
+static av_always_inline int ff_guidcmp(const void *g1, const void *g2)
+{
+ return memcmp(g1, g2, sizeof(ff_asf_guid));
+}
+
+void ff_get_guid(AVIOContext *s, ff_asf_guid *g);
+
+typedef struct {
+ enum CodecID id;
+ ff_asf_guid guid;
+} AVCodecGuid;
+
+enum CodecID ff_codec_guid_get_id(const AVCodecGuid *guids, ff_asf_guid guid);
+
+extern const AVCodecGuid ff_codec_wav_guids[];
+
+#define FF_MEDIASUBTYPE_BASE_GUID \
+ 0x00,0x00,0x10,0x00,0x80,0x00,0x00,0xAA,0x00,0x38,0x9B,0x71
+
#endif /* AVFORMAT_RIFF_H */
diff --git a/libavformat/rl2.c b/libavformat/rl2.c
index 12cb391ad8..743250a922 100644
--- a/libavformat/rl2.c
+++ b/libavformat/rl2.c
@@ -2,20 +2,20 @@
* RL2 Format Demuxer
* Copyright (c) 2008 Sascha Sommer (saschasommer@freenet.de)
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -23,8 +23,7 @@
* RL2 file demuxer
* @file
* @author Sascha Sommer (saschasommer@freenet.de)
- * For more information regarding the RL2 file format, visit:
- * http://wiki.multimedia.cx/index.php?title=RL2
+ * @see http://wiki.multimedia.cx/index.php?title=RL2
*
* extradata:
* 2 byte le initial drawing offset within 320x200 viewport
@@ -111,7 +110,7 @@ static av_cold int rl2_read_header(AVFormatContext *s,
def_sound_size = avio_rl16(pb);
/** setup video stream */
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if(!st)
return AVERROR(ENOMEM);
@@ -141,7 +140,7 @@ static av_cold int rl2_read_header(AVFormatContext *s,
pts_num = def_sound_size;
pts_den = rate;
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
@@ -287,13 +286,12 @@ static int rl2_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp
}
AVInputFormat ff_rl2_demuxer = {
- "rl2",
- NULL_IF_CONFIG_SMALL("RL2 format"),
- sizeof(Rl2DemuxContext),
- rl2_probe,
- rl2_read_header,
- rl2_read_packet,
- NULL,
- rl2_read_seek,
+ .name = "rl2",
+ .long_name = NULL_IF_CONFIG_SMALL("RL2 format"),
+ .priv_data_size = sizeof(Rl2DemuxContext),
+ .read_probe = rl2_probe,
+ .read_header = rl2_read_header,
+ .read_packet = rl2_read_packet,
+ .read_seek = rl2_read_seek,
};
diff --git a/libavformat/rm.c b/libavformat/rm.c
index 9c0ad4a58b..f2942964d4 100644
--- a/libavformat/rm.c
+++ b/libavformat/rm.c
@@ -2,20 +2,20 @@
* "Real" compatible muxer and demuxer common code.
* Copyright (c) 2009 Aurelien Jacobs <aurel@gnuage.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/rm.h b/libavformat/rm.h
index 9d104ad74c..6de10924ab 100644
--- a/libavformat/rm.h
+++ b/libavformat/rm.h
@@ -2,20 +2,20 @@
* "Real" compatible muxer and demuxer.
* Copyright (c) 2000, 2001 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/rmdec.c b/libavformat/rmdec.c
index fbc4d0cee6..b73b51aaf8 100644
--- a/libavformat/rmdec.c
+++ b/libavformat/rmdec.c
@@ -2,20 +2,20 @@
* "Real" compatible demuxer.
* Copyright (c) 2000, 2001 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -26,6 +26,13 @@
#include "riff.h"
#include "rm.h"
+#define DEINT_ID_GENR MKTAG('g', 'e', 'n', 'r') ///< interleaving for Cooker/Atrac
+#define DEINT_ID_INT0 MKTAG('I', 'n', 't', '0') ///< no interleaving needed
+#define DEINT_ID_INT4 MKTAG('I', 'n', 't', '4') ///< interleaving for 28.8
+#define DEINT_ID_SIPR MKTAG('s', 'i', 'p', 'r') ///< interleaving for Sipro
+#define DEINT_ID_VBRF MKTAG('v', 'b', 'r', 'f') ///< VBR case for AAC
+#define DEINT_ID_VBRS MKTAG('v', 'b', 'r', 's') ///< VBR case for AAC
+
struct RMStream {
AVPacket pkt; ///< place to store merged video frame / reordered audio data
int videobufsize; ///< current assembled frame size
@@ -39,6 +46,7 @@ struct RMStream {
int sub_packet_size, sub_packet_h, coded_framesize; ///< Descrambling parameters from container
int audio_framesize; /// Audio frame size from container
int sub_packet_lengths[16]; /// Length of each subpacket
+ int32_t deint_id; ///< deinterleaver used in audio stream
};
typedef struct {
@@ -147,6 +155,7 @@ static int rm_read_audio_stream_info(AVFormatContext *s, AVIOContext *pb,
st->codec->channels = 1;
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
st->codec->codec_id = CODEC_ID_RA_144;
+ ast->deint_id = DEINT_ID_INT0;
} else {
int flavor, sub_packet_h, coded_framesize, sub_packet_size;
int codecdata_length;
@@ -172,17 +181,19 @@ static int rm_read_audio_stream_info(AVFormatContext *s, AVIOContext *pb,
avio_rb32(pb);
st->codec->channels = avio_rb16(pb);
if (version == 5) {
- avio_rb32(pb);
+ ast->deint_id = avio_rl32(pb);
avio_read(pb, buf, 4);
buf[4] = 0;
} else {
get_str8(pb, buf, sizeof(buf)); /* desc */
+ ast->deint_id = AV_RL32(buf);
get_str8(pb, buf, sizeof(buf)); /* desc */
}
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
st->codec->codec_tag = AV_RL32(buf);
st->codec->codec_id = ff_codec_get_id(ff_rm_codec_tags,
st->codec->codec_tag);
+
switch (st->codec->codec_id) {
case CODEC_ID_AC3:
st->need_parsing = AVSTREAM_PARSE_FULL;
@@ -191,13 +202,6 @@ static int rm_read_audio_stream_info(AVFormatContext *s, AVIOContext *pb,
st->codec->extradata_size= 0;
ast->audio_framesize = st->codec->block_align;
st->codec->block_align = coded_framesize;
-
- if(ast->audio_framesize >= UINT_MAX / sub_packet_h){
- av_log(s, AV_LOG_ERROR, "ast->audio_framesize * sub_packet_h too large\n");
- return -1;
- }
-
- av_new_packet(&ast->pkt, ast->audio_framesize * sub_packet_h);
break;
case CODEC_ID_COOK:
case CODEC_ID_ATRAC3:
@@ -229,12 +233,6 @@ static int rm_read_audio_stream_info(AVFormatContext *s, AVIOContext *pb,
if ((ret = rm_read_extradata(pb, st->codec, codecdata_length)) < 0)
return ret;
- if(ast->audio_framesize >= UINT_MAX / sub_packet_h){
- av_log(s, AV_LOG_ERROR, "rm->audio_framesize * sub_packet_h too large\n");
- return -1;
- }
-
- av_new_packet(&ast->pkt, ast->audio_framesize * sub_packet_h);
break;
case CODEC_ID_AAC:
avio_rb16(pb); avio_r8(pb);
@@ -254,6 +252,37 @@ static int rm_read_audio_stream_info(AVFormatContext *s, AVIOContext *pb,
default:
av_strlcpy(st->codec->codec_name, buf, sizeof(st->codec->codec_name));
}
+ if (ast->deint_id == DEINT_ID_INT4 ||
+ ast->deint_id == DEINT_ID_GENR ||
+ ast->deint_id == DEINT_ID_SIPR) {
+ if (st->codec->block_align <= 0 ||
+ ast->audio_framesize * sub_packet_h > (unsigned)INT_MAX ||
+ ast->audio_framesize * sub_packet_h < st->codec->block_align)
+ return AVERROR_INVALIDDATA;
+ if (av_new_packet(&ast->pkt, ast->audio_framesize * sub_packet_h) < 0)
+ return AVERROR(ENOMEM);
+ }
+ switch (ast->deint_id) {
+ case DEINT_ID_INT4:
+ if (ast->coded_framesize > ast->audio_framesize ||
+ ast->coded_framesize * sub_packet_h > (2 + (sub_packet_h & 1)) * ast->audio_framesize)
+ return AVERROR_INVALIDDATA;
+ break;
+ case DEINT_ID_GENR:
+ if (ast->sub_packet_size <= 0 ||
+ ast->sub_packet_size > ast->audio_framesize)
+ return AVERROR_INVALIDDATA;
+ break;
+ case DEINT_ID_SIPR:
+ case DEINT_ID_INT0:
+ case DEINT_ID_VBRS:
+ case DEINT_ID_VBRF:
+ break;
+ default:
+ av_log(NULL,0,"Unknown interleaver %X\n", ast->deint_id);
+ return AVERROR_INVALIDDATA;
+ }
+
if (read_all) {
avio_r8(pb);
avio_r8(pb);
@@ -293,30 +322,21 @@ ff_rm_read_mdpr_codecdata (AVFormatContext *s, AVIOContext *pb,
// av_log(s, AV_LOG_DEBUG, "%X %X\n", st->codec->codec_tag, MKTAG('R', 'V', '2', '0'));
if (st->codec->codec_id == CODEC_ID_NONE)
goto fail1;
- st->codec->width = avio_rb16(pb);
+ st->codec->width = avio_rb16(pb);
st->codec->height = avio_rb16(pb);
- st->codec->time_base.num= 1;
- fps= avio_rb16(pb);
+ avio_skip(pb, 2); // looks like bits per sample
+ avio_skip(pb, 4); // always zero?
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
- avio_rb32(pb);
- avio_skip(pb, 2);
- avio_rb16(pb);
+ st->need_parsing = AVSTREAM_PARSE_TIMESTAMPS;
+ fps = avio_rb32(pb);
if ((ret = rm_read_extradata(pb, st->codec, codec_data_size - (avio_tell(pb) - codec_pos))) < 0)
return ret;
-// av_log(s, AV_LOG_DEBUG, "fps= %d fps2= %d\n", fps, fps2);
- st->codec->time_base.den = fps * st->codec->time_base.num;
- //XXX: do we really need that?
- switch(st->codec->extradata[4]>>4){
- case 1: st->codec->codec_id = CODEC_ID_RV10; break;
- case 2: st->codec->codec_id = CODEC_ID_RV20; break;
- case 3: st->codec->codec_id = CODEC_ID_RV30; break;
- case 4: st->codec->codec_id = CODEC_ID_RV40; break;
- default:
- av_log(st->codec, AV_LOG_ERROR, "extra:%02X %02X %02X %02X %02X\n", st->codec->extradata[0], st->codec->extradata[1], st->codec->extradata[2], st->codec->extradata[3], st->codec->extradata[4]);
- goto fail1;
- }
+ av_reduce(&st->codec->time_base.num, &st->codec->time_base.den,
+ 0x10000, fps, (1 << 30) - 1);
+ st->avg_frame_rate.num = st->codec->time_base.den;
+ st->avg_frame_rate.den = st->codec->time_base.num;
}
skip:
@@ -371,13 +391,13 @@ skip:
return 0;
}
-static int rm_read_header_old(AVFormatContext *s, AVFormatParameters *ap)
+static int rm_read_header_old(AVFormatContext *s)
{
RMDemuxContext *rm = s->priv_data;
AVStream *st;
rm->old_format = 1;
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return -1;
st->priv_data = ff_rm_alloc_rmstream();
@@ -399,7 +419,7 @@ static int rm_read_header(AVFormatContext *s, AVFormatParameters *ap)
tag = avio_rl32(pb);
if (tag == MKTAG('.', 'r', 'a', 0xfd)) {
/* very old .ra format */
- return rm_read_header_old(s, ap);
+ return rm_read_header_old(s);
} else if (tag != MKTAG('.', 'R', 'M', 'F')) {
return AVERROR(EIO);
}
@@ -410,7 +430,7 @@ static int rm_read_header(AVFormatContext *s, AVFormatParameters *ap)
avio_rb32(pb); /* number of headers */
for(;;) {
- if (pb->eof_reached)
+ if (url_feof(pb))
return -1;
tag = avio_rl32(pb);
tag_size = avio_rb32(pb);
@@ -443,7 +463,7 @@ static int rm_read_header(AVFormatContext *s, AVFormatParameters *ap)
rm_read_metadata(s, 1);
break;
case MKTAG('M', 'D', 'P', 'R'):
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
st->id = avio_rb16(pb);
@@ -514,7 +534,7 @@ static int sync(AVFormatContext *s, int64_t *timestamp, int *flags, int *stream_
AVStream *st;
uint32_t state=0xFFFFFFFF;
- while(!pb->eof_reached){
+ while(!url_feof(pb)){
int len, num, i;
*pos= avio_tell(pb) - 3;
if(rm->remaining_len > 0){
@@ -578,7 +598,8 @@ skip:
static int rm_assemble_video_frame(AVFormatContext *s, AVIOContext *pb,
RMDemuxContext *rm, RMStream *vst,
- AVPacket *pkt, int len, int *pseq)
+ AVPacket *pkt, int len, int *pseq,
+ int64_t *timestamp)
{
int hdr, seq, pic_num, len2, pos;
int type;
@@ -598,8 +619,10 @@ static int rm_assemble_video_frame(AVFormatContext *s, AVIOContext *pb,
return -1;
rm->remaining_len = len;
if(type&1){ // frame, not slice
- if(type == 3) // frame as a part of packet
+ if(type == 3){ // frame as a part of packet
len= len2;
+ *timestamp = pos;
+ }
if(rm->remaining_len < len)
return -1;
rm->remaining_len -= len;
@@ -707,13 +730,12 @@ ff_rm_parse_packet (AVFormatContext *s, AVIOContext *pb,
if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
rm->current_stream= st->id;
- if(rm_assemble_video_frame(s, pb, rm, ast, pkt, len, seq))
+ if(rm_assemble_video_frame(s, pb, rm, ast, pkt, len, seq, &timestamp))
return -1; //got partial frame
} else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
- if ((st->codec->codec_id == CODEC_ID_RA_288) ||
- (st->codec->codec_id == CODEC_ID_COOK) ||
- (st->codec->codec_id == CODEC_ID_ATRAC3) ||
- (st->codec->codec_id == CODEC_ID_SIPR)) {
+ if ((ast->deint_id == DEINT_ID_GENR) ||
+ (ast->deint_id == DEINT_ID_INT4) ||
+ (ast->deint_id == DEINT_ID_SIPR)) {
int x;
int sps = ast->sub_packet_size;
int cfs = ast->coded_framesize;
@@ -726,30 +748,30 @@ ff_rm_parse_packet (AVFormatContext *s, AVIOContext *pb,
if (!y)
ast->audiotimestamp = timestamp;
- switch(st->codec->codec_id) {
- case CODEC_ID_RA_288:
+ switch (ast->deint_id) {
+ case DEINT_ID_INT4:
for (x = 0; x < h/2; x++)
avio_read(pb, ast->pkt.data+x*2*w+y*cfs, cfs);
break;
- case CODEC_ID_ATRAC3:
- case CODEC_ID_COOK:
+ case DEINT_ID_GENR:
for (x = 0; x < w/sps; x++)
avio_read(pb, ast->pkt.data+sps*(h*x+((h+1)/2)*(y&1)+(y>>1)), sps);
break;
- case CODEC_ID_SIPR:
+ case DEINT_ID_SIPR:
avio_read(pb, ast->pkt.data + y * w, w);
break;
}
if (++(ast->sub_packet_cnt) < h)
return -1;
- if (st->codec->codec_id == CODEC_ID_SIPR)
+ if (ast->deint_id == DEINT_ID_SIPR)
ff_rm_reorder_sipr_data(ast->pkt.data, h, w);
ast->sub_packet_cnt = 0;
rm->audio_stream_num = st->index;
rm->audio_pkt_cnt = h * w / st->codec->block_align;
- } else if (st->codec->codec_id == CODEC_ID_AAC) {
+ } else if ((ast->deint_id == DEINT_ID_VBRF) ||
+ (ast->deint_id == DEINT_ID_VBRS)) {
int x;
rm->audio_stream_num = st->index;
ast->sub_packet_cnt = (avio_rb16(pb) & 0xf0) >> 4;
@@ -782,7 +804,7 @@ ff_rm_parse_packet (AVFormatContext *s, AVIOContext *pb,
}
#endif
- pkt->pts= timestamp;
+ pkt->pts = timestamp;
if (flags & 2)
pkt->flags |= AV_PKT_FLAG_KEY;
@@ -797,7 +819,8 @@ ff_rm_retrieve_cache (AVFormatContext *s, AVIOContext *pb,
assert (rm->audio_pkt_cnt > 0);
- if (st->codec->codec_id == CODEC_ID_AAC)
+ if (ast->deint_id == DEINT_ID_VBRF ||
+ ast->deint_id == DEINT_ID_VBRS)
av_get_packet(pb, pkt, ast->sub_packet_lengths[ast->sub_packet_cnt - rm->audio_pkt_cnt]);
else {
av_new_packet(pkt, st->codec->block_align);
@@ -847,7 +870,7 @@ static int rm_read_packet(AVFormatContext *s, AVPacket *pkt)
st = s->streams[i];
}
- if(len<0 || s->pb->eof_reached)
+ if(len<0 || url_feof(s->pb))
return AVERROR(EIO);
res = ff_rm_parse_packet (s, s->pb, st, st->priv_data, len, pkt,
@@ -903,7 +926,9 @@ static int64_t rm_read_dts(AVFormatContext *s, int stream_index,
if(rm->old_format)
return AV_NOPTS_VALUE;
- avio_seek(s->pb, pos, SEEK_SET);
+ if (avio_seek(s->pb, pos, SEEK_SET) < 0)
+ return AV_NOPTS_VALUE;
+
rm->remaining_len=0;
for(;;){
int seq=1;
@@ -935,23 +960,19 @@ static int64_t rm_read_dts(AVFormatContext *s, int stream_index,
}
AVInputFormat ff_rm_demuxer = {
- "rm",
- NULL_IF_CONFIG_SMALL("RealMedia format"),
- sizeof(RMDemuxContext),
- rm_probe,
- rm_read_header,
- rm_read_packet,
- rm_read_close,
- NULL,
- rm_read_dts,
+ .name = "rm",
+ .long_name = NULL_IF_CONFIG_SMALL("RealMedia format"),
+ .priv_data_size = sizeof(RMDemuxContext),
+ .read_probe = rm_probe,
+ .read_header = rm_read_header,
+ .read_packet = rm_read_packet,
+ .read_close = rm_read_close,
+ .read_timestamp = rm_read_dts,
};
AVInputFormat ff_rdt_demuxer = {
- "rdt",
- NULL_IF_CONFIG_SMALL("RDT demuxer"),
- sizeof(RMDemuxContext),
- NULL,
- NULL,
- NULL,
- rm_read_close,
+ .name = "rdt",
+ .long_name = NULL_IF_CONFIG_SMALL("RDT demuxer"),
+ .priv_data_size = sizeof(RMDemuxContext),
+ .read_close = rm_read_close,
};
diff --git a/libavformat/rmenc.c b/libavformat/rmenc.c
index 2476cb0590..a601331e2e 100644
--- a/libavformat/rmenc.c
+++ b/libavformat/rmenc.c
@@ -2,20 +2,20 @@
* "Real" compatible muxer.
* Copyright (c) 2000, 2001 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avformat.h"
@@ -461,15 +461,15 @@ static int rm_write_trailer(AVFormatContext *s)
AVOutputFormat ff_rm_muxer = {
- "rm",
- NULL_IF_CONFIG_SMALL("RealMedia format"),
- "application/vnd.rn-realmedia",
- "rm,ra",
- sizeof(RMMuxContext),
- CODEC_ID_AC3,
- CODEC_ID_RV10,
- rm_write_header,
- rm_write_packet,
- rm_write_trailer,
+ .name = "rm",
+ .long_name = NULL_IF_CONFIG_SMALL("RealMedia format"),
+ .mime_type = "application/vnd.rn-realmedia",
+ .extensions = "rm,ra",
+ .priv_data_size = sizeof(RMMuxContext),
+ .audio_codec = CODEC_ID_AC3,
+ .video_codec = CODEC_ID_RV10,
+ .write_header = rm_write_header,
+ .write_packet = rm_write_packet,
+ .write_trailer = rm_write_trailer,
.codec_tag= (const AVCodecTag* const []){ff_rm_codec_tags, 0},
};
diff --git a/libavformat/rpl.c b/libavformat/rpl.c
index f67d3cd7c4..b8214e3604 100644
--- a/libavformat/rpl.c
+++ b/libavformat/rpl.c
@@ -2,20 +2,20 @@
* ARMovie/RPL demuxer
* Copyright (c) 2007 Christian Ohm, 2008 Eli Friedman
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -139,7 +139,7 @@ static int rpl_read_header(AVFormatContext *s, AVFormatParameters *ap)
av_dict_set(&s->metadata, "author" , line, 0);
// video headers
- vst = av_new_stream(s, 0);
+ vst = avformat_new_stream(s, NULL);
if (!vst)
return AVERROR(ENOMEM);
vst->codec->codec_type = AVMEDIA_TYPE_VIDEO;
@@ -181,7 +181,7 @@ static int rpl_read_header(AVFormatContext *s, AVFormatParameters *ap)
// samples, though. This code will ignore additional tracks.
audio_format = read_line_and_int(pb, &error); // audio format ID
if (audio_format) {
- ast = av_new_stream(s, 0);
+ ast = avformat_new_stream(s, NULL);
if (!ast)
return AVERROR(ENOMEM);
ast->codec->codec_type = AVMEDIA_TYPE_AUDIO;
@@ -351,10 +351,10 @@ static int rpl_read_packet(AVFormatContext *s, AVPacket *pkt)
}
AVInputFormat ff_rpl_demuxer = {
- "rpl",
- NULL_IF_CONFIG_SMALL("RPL/ARMovie format"),
- sizeof(RPLContext),
- rpl_probe,
- rpl_read_header,
- rpl_read_packet,
+ .name = "rpl",
+ .long_name = NULL_IF_CONFIG_SMALL("RPL/ARMovie format"),
+ .priv_data_size = sizeof(RPLContext),
+ .read_probe = rpl_probe,
+ .read_header = rpl_read_header,
+ .read_packet = rpl_read_packet,
};
diff --git a/libavformat/rso.c b/libavformat/rso.c
index fc39abcc8a..178fd3f224 100644
--- a/libavformat/rso.c
+++ b/libavformat/rso.c
@@ -2,20 +2,20 @@
* RSO format common data
* Copyright (c) 2010 Rafael Carre
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/rso.h b/libavformat/rso.h
index bdb39e8d7f..acb0f14063 100644
--- a/libavformat/rso.h
+++ b/libavformat/rso.h
@@ -2,20 +2,20 @@
* RSO format common data
* Copyright (c) 2010 Rafael Carre
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/rsodec.c b/libavformat/rsodec.c
index 98de8fe669..14adc04b4b 100644
--- a/libavformat/rsodec.c
+++ b/libavformat/rsodec.c
@@ -3,20 +3,20 @@
* Copyright (c) 2001 Fabrice Bellard (original AU code)
* Copyright (c) 2010 Rafael Carre
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -54,7 +54,7 @@ static int rso_read_header(AVFormatContext *s, AVFormatParameters *ap)
}
/* now we are ready: build format streams */
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
diff --git a/libavformat/rsoenc.c b/libavformat/rsoenc.c
index 338ecf0173..ca9985b070 100644
--- a/libavformat/rsoenc.c
+++ b/libavformat/rsoenc.c
@@ -3,20 +3,20 @@
* Copyright (c) 2001 Fabrice Bellard (original AU code)
* Copyright (c) 2010 Rafael Carre
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/rtmp.h b/libavformat/rtmp.h
index 45de73ef2b..b0436c0391 100644
--- a/libavformat/rtmp.h
+++ b/libavformat/rtmp.h
@@ -2,20 +2,20 @@
* RTMP definitions
* Copyright (c) 2009 Kostya Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/rtmppkt.c b/libavformat/rtmppkt.c
index 6bf641a742..7e2ccdc6ac 100644
--- a/libavformat/rtmppkt.c
+++ b/libavformat/rtmppkt.c
@@ -2,20 +2,20 @@
* RTMP input format
* Copyright (c) 2009 Kostya Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/rtmppkt.h b/libavformat/rtmppkt.h
index 8372484fbd..8acbfc116b 100644
--- a/libavformat/rtmppkt.h
+++ b/libavformat/rtmppkt.h
@@ -2,20 +2,20 @@
* RTMP packet utilities
* Copyright (c) 2009 Kostya Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c
index de4eb0fd23..ed483cf37f 100644
--- a/libavformat/rtmpproto.c
+++ b/libavformat/rtmpproto.c
@@ -2,20 +2,20 @@
* RTMP network protocol
* Copyright (c) 2009 Kostya Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -71,6 +71,9 @@ typedef struct RTMPContext {
uint32_t client_report_size; ///< number of bytes after which client should report to server
uint32_t bytes_read; ///< number of bytes read from server
uint32_t last_bytes_read; ///< number of bytes read last reported to server
+ int skip_bytes; ///< number of bytes to skip from the input FLV stream in the next write call
+ uint8_t flv_header[11]; ///< partial incoming flv packet header
+ int flv_header_bytes; ///< number of initialized bytes in flv_header
} RTMPContext;
#define PLAYER_KEY_OPEN_PART_LEN 30 ///< length of partial key used for first client digest signing
@@ -879,6 +882,7 @@ static int rtmp_open(URLContext *s, const char *uri, int flags)
rt->flv_size = 0;
rt->flv_data = NULL;
rt->flv_off = 0;
+ rt->skip_bytes = 13;
}
s->max_packet_size = rt->stream->max_packet_size;
@@ -925,25 +929,29 @@ static int rtmp_write(URLContext *s, const uint8_t *buf, int size)
uint32_t ts;
const uint8_t *buf_temp = buf;
- if (size < 11) {
- av_log(s, AV_LOG_DEBUG, "FLV packet too small %d\n", size);
- return 0;
- }
-
do {
- if (!rt->flv_off) {
- //skip flv header
- if (buf_temp[0] == 'F' && buf_temp[1] == 'L' && buf_temp[2] == 'V') {
- buf_temp += 9 + 4;
- size_temp -= 9 + 4;
- }
+ if (rt->skip_bytes) {
+ int skip = FFMIN(rt->skip_bytes, size_temp);
+ buf_temp += skip;
+ size_temp -= skip;
+ rt->skip_bytes -= skip;
+ continue;
+ }
+
+ if (rt->flv_header_bytes < 11) {
+ const uint8_t *header = rt->flv_header;
+ int copy = FFMIN(11 - rt->flv_header_bytes, size_temp);
+ bytestream_get_buffer(&buf_temp, rt->flv_header + rt->flv_header_bytes, copy);
+ rt->flv_header_bytes += copy;
+ size_temp -= copy;
+ if (rt->flv_header_bytes < 11)
+ break;
- pkttype = bytestream_get_byte(&buf_temp);
- pktsize = bytestream_get_be24(&buf_temp);
- ts = bytestream_get_be24(&buf_temp);
- ts |= bytestream_get_byte(&buf_temp) << 24;
- bytestream_get_be24(&buf_temp);
- size_temp -= 11;
+ pkttype = bytestream_get_byte(&header);
+ pktsize = bytestream_get_be24(&header);
+ ts = bytestream_get_be24(&header);
+ ts |= bytestream_get_byte(&header) << 24;
+ bytestream_get_be24(&header);
rt->flv_size = pktsize;
//force 12bytes header
@@ -966,20 +974,23 @@ static int rtmp_write(URLContext *s, const uint8_t *buf, int size)
if (rt->flv_size - rt->flv_off > size_temp) {
bytestream_get_buffer(&buf_temp, rt->flv_data + rt->flv_off, size_temp);
rt->flv_off += size_temp;
+ size_temp = 0;
} else {
bytestream_get_buffer(&buf_temp, rt->flv_data + rt->flv_off, rt->flv_size - rt->flv_off);
+ size_temp -= rt->flv_size - rt->flv_off;
rt->flv_off += rt->flv_size - rt->flv_off;
}
if (rt->flv_off == rt->flv_size) {
- bytestream_get_be32(&buf_temp);
+ rt->skip_bytes = 4;
ff_rtmp_packet_write(rt->stream, &rt->out_pkt, rt->chunk_size, rt->prev_pkt[1]);
ff_rtmp_packet_destroy(&rt->out_pkt);
rt->flv_size = 0;
rt->flv_off = 0;
+ rt->flv_header_bytes = 0;
}
- } while (buf_temp - buf < size_temp);
+ } while (buf_temp - buf < size);
return size;
}
diff --git a/libavformat/rtp.c b/libavformat/rtp.c
index d59b6941b6..98d96160db 100644
--- a/libavformat/rtp.c
+++ b/libavformat/rtp.c
@@ -2,23 +2,24 @@
* RTP input/output format
* Copyright (c) 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include <libavutil/opt.h>
#include "avformat.h"
#include "rtp.h"
@@ -43,7 +44,7 @@ static const struct
{
{0, "PCMU", AVMEDIA_TYPE_AUDIO, CODEC_ID_PCM_MULAW, 8000, 1},
{3, "GSM", AVMEDIA_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1},
- {4, "G723", AVMEDIA_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1},
+ {4, "G723", AVMEDIA_TYPE_AUDIO, CODEC_ID_G723_1, 8000, 1},
{5, "DVI4", AVMEDIA_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1},
{6, "DVI4", AVMEDIA_TYPE_AUDIO, CODEC_ID_NONE, 16000, 1},
{7, "LPC", AVMEDIA_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1},
@@ -89,21 +90,32 @@ int ff_rtp_get_codec_info(AVCodecContext *codec, int payload_type)
return -1;
}
-int ff_rtp_get_payload_type(AVCodecContext *codec)
+int ff_rtp_get_payload_type(AVFormatContext *fmt, AVCodecContext *codec)
{
- int i, payload_type;
+ int i;
+ AVOutputFormat *ofmt = fmt ? fmt->oformat : NULL;
+
+ /* Was the payload type already specified for the RTP muxer? */
+ if (ofmt && ofmt->priv_class) {
+ int64_t payload_type;
+ if (av_opt_get_int(fmt->priv_data, "payload_type", 0, &payload_type) >= 0 &&
+ payload_type >= 0)
+ return (int)payload_type;
+ }
- /* compute the payload type */
- for (payload_type = -1, i = 0; AVRtpPayloadTypes[i].pt >= 0; ++i)
+ /* static payload type */
+ for (i = 0; AVRtpPayloadTypes[i].pt >= 0; ++i)
if (AVRtpPayloadTypes[i].codec_id == codec->codec_id) {
if (codec->codec_id == CODEC_ID_H263)
continue;
if (codec->codec_id == CODEC_ID_PCM_S16BE)
if (codec->channels != AVRtpPayloadTypes[i].audio_channels)
continue;
- payload_type = AVRtpPayloadTypes[i].pt;
+ return AVRtpPayloadTypes[i].pt;
}
- return payload_type;
+
+ /* dynamic payload type */
+ return RTP_PT_PRIVATE + (codec->codec_type == AVMEDIA_TYPE_AUDIO);
}
const char *ff_rtp_enc_name(int payload_type)
diff --git a/libavformat/rtp.h b/libavformat/rtp.h
index 36157ce172..5297e17f6a 100644
--- a/libavformat/rtp.h
+++ b/libavformat/rtp.h
@@ -2,36 +2,36 @@
* RTP definitions
* Copyright (c) 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVFORMAT_RTP_H
#define AVFORMAT_RTP_H
+#include "libavformat/avformat.h"
#include "libavcodec/avcodec.h"
/**
- * Return the payload type for a given codec.
+ * Return the payload type for a given codec used in the given format context.
*
+ * @param fmt The context of the format
* @param codec The context of the codec
- * @return In case of unknown payload type or dynamic payload type, a
- * negative value is returned; otherwise, the payload type (the 'PT' field
- * in the RTP header) is returned.
+ * @return The payload type (the 'PT' field in the RTP header).
*/
-int ff_rtp_get_payload_type(AVCodecContext *codec);
+int ff_rtp_get_payload_type(AVFormatContext *fmt, AVCodecContext *codec);
/**
* Initialize a codec context based on the payload type.
diff --git a/libavformat/rtpdec.c b/libavformat/rtpdec.c
index 2c262d9bd3..9023dd6985 100644
--- a/libavformat/rtpdec.c
+++ b/libavformat/rtpdec.c
@@ -2,20 +2,20 @@
* RTP input format
* Copyright (c) 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -112,14 +112,15 @@ RTPDynamicProtocolHandler *ff_rtp_handler_find_by_id(int id,
static int rtcp_parse_packet(RTPDemuxContext *s, const unsigned char *buf, int len)
{
int payload_len;
- while (len >= 2) {
+ while (len >= 4) {
+ payload_len = FFMIN(len, (AV_RB16(buf + 2) + 1) * 4);
+
switch (buf[1]) {
case RTCP_SR:
- if (len < 16) {
+ if (payload_len < 20) {
av_log(NULL, AV_LOG_ERROR, "Invalid length for RTCP SR packet\n");
return AVERROR_INVALIDDATA;
}
- payload_len = (AV_RB16(buf + 2) + 1) * 4;
s->last_rtcp_ntp_time = AV_RB64(buf + 8);
s->last_rtcp_timestamp = AV_RB32(buf + 16);
@@ -130,14 +131,13 @@ static int rtcp_parse_packet(RTPDemuxContext *s, const unsigned char *buf, int l
s->rtcp_ts_offset = s->last_rtcp_timestamp - s->base_timestamp;
}
- buf += payload_len;
- len -= payload_len;
break;
case RTCP_BYE:
return -RTCP_BYE;
- default:
- return -1;
}
+
+ buf += payload_len;
+ len -= payload_len;
}
return -1;
}
@@ -218,23 +218,7 @@ static int rtp_valid_packet_in_sequence(RTPStatistics *s, uint16_t seq)
return 1;
}
-#if 0
-/**
-* This function is currently unused; without a valid local ntp time, I don't see how we could calculate the
-* difference between the arrival and sent timestamp. As a result, the jitter and transit statistics values
-* never change. I left this in in case someone else can see a way. (rdm)
-*/
-static void rtcp_update_jitter(RTPStatistics *s, uint32_t sent_timestamp, uint32_t arrival_timestamp)
-{
- uint32_t transit= arrival_timestamp - sent_timestamp;
- int d;
- s->transit= transit;
- d= FFABS(transit - s->transit);
- s->jitter += d - ((s->jitter + 8)>>4);
-}
-#endif
-
-int rtp_check_and_send_back_rr(RTPDemuxContext *s, int count)
+int ff_rtp_check_and_send_back_rr(RTPDemuxContext *s, int count)
{
AVIOContext *pb;
uint8_t *buf;
@@ -331,7 +315,7 @@ int rtp_check_and_send_back_rr(RTPDemuxContext *s, int count)
return 0;
}
-void rtp_send_punch_packets(URLContext* rtp_handle)
+void ff_rtp_send_punch_packets(URLContext* rtp_handle)
{
AVIOContext *pb;
uint8_t *buf;
@@ -375,7 +359,7 @@ void rtp_send_punch_packets(URLContext* rtp_handle)
* MPEG2TS streams to indicate that they should be demuxed inside the
* rtp demux (otherwise CODEC_ID_MPEG2TS packets are returned)
*/
-RTPDemuxContext *rtp_parse_open(AVFormatContext *s1, AVStream *st, URLContext *rtpc, int payload_type, int queue_size)
+RTPDemuxContext *ff_rtp_parse_open(AVFormatContext *s1, AVStream *st, URLContext *rtpc, int payload_type, int queue_size)
{
RTPDemuxContext *s;
@@ -423,8 +407,8 @@ RTPDemuxContext *rtp_parse_open(AVFormatContext *s1, AVStream *st, URLContext *r
}
void
-rtp_parse_set_dynamic_protocol(RTPDemuxContext *s, PayloadContext *ctx,
- RTPDynamicProtocolHandler *handler)
+ff_rtp_parse_set_dynamic_protocol(RTPDemuxContext *s, PayloadContext *ctx,
+ RTPDynamicProtocolHandler *handler)
{
s->dynamic_protocol_context = ctx;
s->parse_packet = handler->parse_packet;
@@ -738,8 +722,8 @@ static int rtp_parse_one_packet(RTPDemuxContext *s, AVPacket *pkt,
* @return 0 if a packet is returned, 1 if a packet is returned and more can follow
* (use buf as NULL to read the next). -1 if no packet (error or no more packet).
*/
-int rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt,
- uint8_t **bufptr, int len)
+int ff_rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt,
+ uint8_t **bufptr, int len)
{
int rv = rtp_parse_one_packet(s, pkt, bufptr, len);
s->prev_ret = rv;
@@ -748,7 +732,7 @@ int rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt,
return rv ? rv : has_next_packet(s);
}
-void rtp_parse_close(RTPDemuxContext *s)
+void ff_rtp_parse_close(RTPDemuxContext *s)
{
ff_rtp_reset_packet_queue(s);
if (!strcmp(ff_rtp_enc_name(s->payload_type), "MP2T")) {
diff --git a/libavformat/rtpdec.h b/libavformat/rtpdec.h
index a4d21aa688..dbb45f5709 100644
--- a/libavformat/rtpdec.h
+++ b/libavformat/rtpdec.h
@@ -3,20 +3,20 @@
* Copyright (c) 2002 Fabrice Bellard
* Copyright (c) 2006 Ryan Martell <rdm4@martellventures.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVFORMAT_RTPDEC_H
@@ -38,18 +38,18 @@ typedef struct RTPDynamicProtocolHandler_s RTPDynamicProtocolHandler;
#define RTP_NOTS_VALUE ((uint32_t)-1)
typedef struct RTPDemuxContext RTPDemuxContext;
-RTPDemuxContext *rtp_parse_open(AVFormatContext *s1, AVStream *st, URLContext *rtpc, int payload_type, int queue_size);
-void rtp_parse_set_dynamic_protocol(RTPDemuxContext *s, PayloadContext *ctx,
- RTPDynamicProtocolHandler *handler);
-int rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt,
- uint8_t **buf, int len);
-void rtp_parse_close(RTPDemuxContext *s);
+RTPDemuxContext *ff_rtp_parse_open(AVFormatContext *s1, AVStream *st, URLContext *rtpc, int payload_type, int queue_size);
+void ff_rtp_parse_set_dynamic_protocol(RTPDemuxContext *s, PayloadContext *ctx,
+ RTPDynamicProtocolHandler *handler);
+int ff_rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt,
+ uint8_t **buf, int len);
+void ff_rtp_parse_close(RTPDemuxContext *s);
int64_t ff_rtp_queued_packet_time(RTPDemuxContext *s);
void ff_rtp_reset_packet_queue(RTPDemuxContext *s);
-int rtp_get_local_rtp_port(URLContext *h);
-int rtp_get_local_rtcp_port(URLContext *h);
+int ff_rtp_get_local_rtp_port(URLContext *h);
+int ff_rtp_get_local_rtcp_port(URLContext *h);
-int rtp_set_remote_url(URLContext *h, const char *uri);
+int ff_rtp_set_remote_url(URLContext *h, const char *uri);
/**
* Send a dummy packet on both port pairs to set up the connection
@@ -62,19 +62,19 @@ int rtp_set_remote_url(URLContext *h, const char *uri);
* The same routine is used with RDT too, even if RDT doesn't use normal
* RTP packets otherwise.
*/
-void rtp_send_punch_packets(URLContext* rtp_handle);
+void ff_rtp_send_punch_packets(URLContext* rtp_handle);
/**
* some rtp servers assume client is dead if they don't hear from them...
* so we send a Receiver Report to the provided ByteIO context
* (we don't have access to the rtcp handle from here)
*/
-int rtp_check_and_send_back_rr(RTPDemuxContext *s, int count);
+int ff_rtp_check_and_send_back_rr(RTPDemuxContext *s, int count);
/**
* Get the file handle for the RTCP socket.
*/
-int rtp_get_rtcp_file_handle(URLContext *h);
+int ff_rtp_get_rtcp_file_handle(URLContext *h);
// these statistics are used for rtcp receiver reports...
typedef struct {
diff --git a/libavformat/rtpdec_amr.c b/libavformat/rtpdec_amr.c
index b7ff3aa05e..fbf4321698 100644
--- a/libavformat/rtpdec_amr.c
+++ b/libavformat/rtpdec_amr.c
@@ -2,20 +2,20 @@
* RTP AMR Depacketizer, RFC 3267
* Copyright (c) 2010 Martin Storsjo
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/rtpdec_asf.c b/libavformat/rtpdec_asf.c
index 287025f377..b481c37c82 100644
--- a/libavformat/rtpdec_asf.c
+++ b/libavformat/rtpdec_asf.c
@@ -2,20 +2,20 @@
* Microsoft RTP/ASF support.
* Copyright (c) 2008 Ronald S. Bultje
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -233,8 +233,14 @@ static int asfrtp_parse_packet(AVFormatContext *s, PayloadContext *asf,
int cur_len = start_off + len_off - off;
int prev_len = out_len;
+ void *newmem;
out_len += cur_len;
- asf->buf = av_realloc(asf->buf, out_len);
+ if (FFMIN(cur_len, len - off) < 0)
+ return -1;
+ newmem = av_realloc(asf->buf, out_len);
+ if (!newmem)
+ return -1;
+ asf->buf = newmem;
memcpy(asf->buf + prev_len, buf + off,
FFMIN(cur_len, len - off));
avio_skip(pb, cur_len);
diff --git a/libavformat/rtpdec_formats.h b/libavformat/rtpdec_formats.h
index 708c2996d6..16f5a9d3e4 100644
--- a/libavformat/rtpdec_formats.h
+++ b/libavformat/rtpdec_formats.h
@@ -2,20 +2,20 @@
* RTP depacketizer declarations
* Copyright (c) 2010 Martin Storsjo
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/rtpdec_h263.c b/libavformat/rtpdec_h263.c
index 0fb1b25eb0..ea42fff320 100644
--- a/libavformat/rtpdec_h263.c
+++ b/libavformat/rtpdec_h263.c
@@ -2,20 +2,20 @@
* RTP H.263 Depacketizer, RFC 4629
* Copyright (c) 2010 Martin Storsjo
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/rtpdec_h264.c b/libavformat/rtpdec_h264.c
index effdc1fe66..730ed14807 100644
--- a/libavformat/rtpdec_h264.c
+++ b/libavformat/rtpdec_h264.c
@@ -2,20 +2,20 @@
* RTP H264 Protocol (RFC3984)
* Copyright (c) 2006 Ryan Martell
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/rtpdec_latm.c b/libavformat/rtpdec_latm.c
index 42317a9529..4bf2c3fb23 100644
--- a/libavformat/rtpdec_latm.c
+++ b/libavformat/rtpdec_latm.c
@@ -2,20 +2,20 @@
* RTP Depacketization of MP4A-LATM, RFC 3016
* Copyright (c) 2010 Martin Storsjo
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/rtpdec_mpeg4.c b/libavformat/rtpdec_mpeg4.c
index 7a63cc315b..07f07ae10a 100644
--- a/libavformat/rtpdec_mpeg4.c
+++ b/libavformat/rtpdec_mpeg4.c
@@ -3,20 +3,20 @@
* Copyright (c) 2010 Fabrice Bellard
* Romain Degez
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/rtpdec_qcelp.c b/libavformat/rtpdec_qcelp.c
index 325683c396..5eb6770297 100644
--- a/libavformat/rtpdec_qcelp.c
+++ b/libavformat/rtpdec_qcelp.c
@@ -2,20 +2,20 @@
* RTP Depacketization of QCELP/PureVoice, RFC 2658
* Copyright (c) 2010 Martin Storsjo
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/rtpdec_qdm2.c b/libavformat/rtpdec_qdm2.c
index 66dd874003..c4314ec2c4 100644
--- a/libavformat/rtpdec_qdm2.c
+++ b/libavformat/rtpdec_qdm2.c
@@ -2,20 +2,20 @@
* QDesign Music 2 (QDM2) payload for RTP
* Copyright (c) 2010 Ronald S. Bultje
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/rtpdec_qt.c b/libavformat/rtpdec_qt.c
index 8dd2968398..fd63aa7d43 100644
--- a/libavformat/rtpdec_qt.c
+++ b/libavformat/rtpdec_qt.c
@@ -2,20 +2,20 @@
* RTP/Quicktime support.
* Copyright (c) 2009 Ronald S. Bultje
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/rtpdec_svq3.c b/libavformat/rtpdec_svq3.c
index 331434245e..7800766ecf 100644
--- a/libavformat/rtpdec_svq3.c
+++ b/libavformat/rtpdec_svq3.c
@@ -2,28 +2,28 @@
* Sorenson-3 (SVQ3/SV3V) payload for RTP
* Copyright (c) 2010 Ronald S. Bultje
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* @brief RTP support for the SV3V (SVQ3) payload
- * (http://wiki.multimedia.cx/index.php?title=Sorenson_Video_3#Packetization)
* @author Ronald S. Bultje <rbultje@ronald.bitfreak.net>
+ * @see http://wiki.multimedia.cx/index.php?title=Sorenson_Video_3#Packetization
*/
#include <string.h>
diff --git a/libavformat/rtpdec_vp8.c b/libavformat/rtpdec_vp8.c
index 026728ec9d..bfc96570d1 100644
--- a/libavformat/rtpdec_vp8.c
+++ b/libavformat/rtpdec_vp8.c
@@ -2,20 +2,20 @@
* RTP VP8 Depacketizer
* Copyright (c) 2010 Josh Allmann
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -23,7 +23,7 @@
* @file
* @brief RTP support for the VP8 payload
* @author Josh Allmann <joshua.allmann@gmail.com>
- * ( http://www.webmproject.org/code/specs/rtp/ )
+ * @see http://www.webmproject.org/code/specs/rtp/
*/
#include "libavcodec/bytestream.h"
diff --git a/libavformat/rtpdec_xiph.c b/libavformat/rtpdec_xiph.c
index a7f36ef59a..6aeea2fd3c 100644
--- a/libavformat/rtpdec_xiph.c
+++ b/libavformat/rtpdec_xiph.c
@@ -3,20 +3,20 @@
* Copyright (c) 2009 Colin McQuillian
* Copyright (c) 2010 Josh Allmann
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/rtpenc.c b/libavformat/rtpenc.c
index c412158778..83f728bc37 100644
--- a/libavformat/rtpenc.c
+++ b/libavformat/rtpenc.c
@@ -2,20 +2,20 @@
* RTP output format
* Copyright (c) 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -32,6 +32,7 @@
static const AVOption options[] = {
FF_RTP_FLAG_OPTS(RTPMuxContext, flags),
+ { "payload_type", "Specify RTP payload type", offsetof(RTPMuxContext, payload_type), AV_OPT_TYPE_INT, {.dbl = -1 }, -1, 127, AV_OPT_FLAG_ENCODING_PARAM },
{ NULL },
};
@@ -87,15 +88,13 @@ static int rtp_write_header(AVFormatContext *s1)
return -1;
st = s1->streams[0];
if (!is_supported(st->codec->codec_id)) {
- av_log(s1, AV_LOG_ERROR, "Unsupported codec %x\n", st->codec->codec_id);
+ av_log(s1, AV_LOG_ERROR, "Unsupported codec %s\n", avcodec_get_name(st->codec->codec_id));
return -1;
}
- s->payload_type = ff_rtp_get_payload_type(st->codec);
if (s->payload_type < 0)
- s->payload_type = RTP_PT_PRIVATE + (st->codec->codec_type == AVMEDIA_TYPE_AUDIO);
-
+ s->payload_type = ff_rtp_get_payload_type(s1, st->codec);
s->base_timestamp = av_get_random_seed();
s->timestamp = s->base_timestamp;
s->cur_timestamp = 0;
@@ -462,15 +461,13 @@ static int rtp_write_trailer(AVFormatContext *s1)
}
AVOutputFormat ff_rtp_muxer = {
- "rtp",
- NULL_IF_CONFIG_SMALL("RTP output format"),
- NULL,
- NULL,
- sizeof(RTPMuxContext),
- CODEC_ID_PCM_MULAW,
- CODEC_ID_NONE,
- rtp_write_header,
- rtp_write_packet,
- rtp_write_trailer,
+ .name = "rtp",
+ .long_name = NULL_IF_CONFIG_SMALL("RTP output format"),
+ .priv_data_size = sizeof(RTPMuxContext),
+ .audio_codec = CODEC_ID_PCM_MULAW,
+ .video_codec = CODEC_ID_MPEG4,
+ .write_header = rtp_write_header,
+ .write_packet = rtp_write_packet,
+ .write_trailer = rtp_write_trailer,
.priv_class = &rtp_muxer_class,
};
diff --git a/libavformat/rtpenc.h b/libavformat/rtpenc.h
index 3a9e19be06..901336322d 100644
--- a/libavformat/rtpenc.h
+++ b/libavformat/rtpenc.h
@@ -2,20 +2,20 @@
* RTP muxer definitions
* Copyright (c) 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVFORMAT_RTPENC_H
@@ -66,8 +66,8 @@ typedef struct RTPMuxContext RTPMuxContext;
#define FF_RTP_FLAG_MP4A_LATM 1
#define FF_RTP_FLAG_OPTS(ctx, fieldname) \
- { "rtpflags", "RTP muxer flags", offsetof(ctx, fieldname), FF_OPT_TYPE_FLAGS, {.dbl = 0}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "rtpflags" }, \
- { "latm", "Use MP4A-LATM packetization instead of MPEG4-GENERIC for AAC", 0, FF_OPT_TYPE_CONST, {.dbl = FF_RTP_FLAG_MP4A_LATM}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "rtpflags" } \
+ { "rtpflags", "RTP muxer flags", offsetof(ctx, fieldname), AV_OPT_TYPE_FLAGS, {.dbl = 0}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "rtpflags" }, \
+ { "latm", "Use MP4A-LATM packetization instead of MPEG4-GENERIC for AAC", 0, AV_OPT_TYPE_CONST, {.dbl = FF_RTP_FLAG_MP4A_LATM}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "rtpflags" } \
void ff_rtp_send_data(AVFormatContext *s1, const uint8_t *buf1, int len, int m);
diff --git a/libavformat/rtpenc_aac.c b/libavformat/rtpenc_aac.c
index 86318dfa6e..e19b28697e 100644
--- a/libavformat/rtpenc_aac.c
+++ b/libavformat/rtpenc_aac.c
@@ -1,20 +1,20 @@
/*
* copyright (c) 2007 Luca Abeni
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/rtpenc_amr.c b/libavformat/rtpenc_amr.c
index 4da7ace32a..367789fccd 100644
--- a/libavformat/rtpenc_amr.c
+++ b/libavformat/rtpenc_amr.c
@@ -3,20 +3,20 @@
* Copyright (c) 2007 Luca Abeni
* Copyright (c) 2009 Martin Storsjo
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/rtpenc_chain.c b/libavformat/rtpenc_chain.c
index 0fb47f6234..f4590faa08 100644
--- a/libavformat/rtpenc_chain.c
+++ b/libavformat/rtpenc_chain.c
@@ -2,20 +2,20 @@
* RTP muxer chaining code
* Copyright (c) 2010 Martin Storsjo
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -31,6 +31,8 @@ AVFormatContext *ff_rtp_chain_mux_open(AVFormatContext *s, AVStream *st,
AVFormatContext *rtpctx;
int ret;
AVOutputFormat *rtp_format = av_guess_format("rtp", NULL, NULL);
+ uint8_t *rtpflags;
+ AVDictionary *opts = NULL;
if (!rtp_format)
return NULL;
@@ -41,7 +43,7 @@ AVFormatContext *ff_rtp_chain_mux_open(AVFormatContext *s, AVStream *st,
return NULL;
rtpctx->oformat = rtp_format;
- if (!av_new_stream(rtpctx, 0)) {
+ if (!avformat_new_stream(rtpctx, NULL)) {
av_free(rtpctx);
return NULL;
}
@@ -49,13 +51,10 @@ AVFormatContext *ff_rtp_chain_mux_open(AVFormatContext *s, AVStream *st,
rtpctx->max_delay = s->max_delay;
/* Copy other stream parameters. */
rtpctx->streams[0]->sample_aspect_ratio = st->sample_aspect_ratio;
+ rtpctx->flags |= s->flags & AVFMT_FLAG_MP4A_LATM;
- av_set_parameters(rtpctx, NULL);
- /* Copy the rtpflags values straight through */
- if (s->oformat->priv_class &&
- av_find_opt(s->priv_data, "rtpflags", NULL, 0, 0))
- av_set_int(rtpctx->priv_data, "rtpflags",
- av_get_int(s->priv_data, "rtpflags", NULL));
+ if (av_opt_get(s, "rtpflags", AV_OPT_SEARCH_CHILDREN, &rtpflags) >= 0)
+ av_dict_set(&opts, "rtpflags", rtpflags, AV_DICT_DONT_STRDUP_VAL);
/* Set the synchronized start time. */
rtpctx->start_time_realtime = s->start_time_realtime;
@@ -66,7 +65,8 @@ AVFormatContext *ff_rtp_chain_mux_open(AVFormatContext *s, AVStream *st,
ffio_fdopen(&rtpctx->pb, handle);
} else
ffio_open_dyn_packet_buf(&rtpctx->pb, packet_size);
- ret = avformat_write_header(rtpctx, NULL);
+ ret = avformat_write_header(rtpctx, &opts);
+ av_dict_free(&opts);
if (ret) {
if (handle) {
diff --git a/libavformat/rtpenc_chain.h b/libavformat/rtpenc_chain.h
index 6bdddcfe99..8e6b80aa3f 100644
--- a/libavformat/rtpenc_chain.h
+++ b/libavformat/rtpenc_chain.h
@@ -2,20 +2,20 @@
* RTP muxer chaining code
* Copyright (c) 2010 Martin Storsjo
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/rtpenc_h263.c b/libavformat/rtpenc_h263.c
index fbc696e1b4..84403a1069 100644
--- a/libavformat/rtpenc_h263.c
+++ b/libavformat/rtpenc_h263.c
@@ -3,20 +3,20 @@
* Copyright (c) 2009 Luca Abeni
* Copyright (c) 2009 Martin Storsjo
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/rtpenc_h264.c b/libavformat/rtpenc_h264.c
index 9ca6f7f68e..11074d0d51 100644
--- a/libavformat/rtpenc_h264.c
+++ b/libavformat/rtpenc_h264.c
@@ -2,20 +2,20 @@
* RTP packetization for H.264 (RFC3984)
* Copyright (c) 2008 Luca Abeni
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -29,6 +29,24 @@
#include "avc.h"
#include "rtpenc.h"
+static const uint8_t *avc_mp4_find_startcode(const uint8_t *start, const uint8_t *end, int nal_length_size)
+{
+ int res = 0;
+
+ if (end - start < nal_length_size) {
+ return NULL;
+ }
+ while (nal_length_size--) {
+ res = (res << 8) | *start++;
+ }
+
+ if (end - start < res) {
+ return NULL;
+ }
+
+ return res + start;
+}
+
static void nal_send(AVFormatContext *s1, const uint8_t *buf, int size, int last)
{
RTPMuxContext *s = s1->priv_data;
@@ -66,12 +84,20 @@ void ff_rtp_send_h264(AVFormatContext *s1, const uint8_t *buf1, int size)
RTPMuxContext *s = s1->priv_data;
s->timestamp = s->cur_timestamp;
- r = ff_avc_find_startcode(buf1, buf1 + size);
+ r = s->nal_length_size ? (avc_mp4_find_startcode(buf1, buf1 + size, s->nal_length_size) ? buf1 : buf1 + size) : ff_avc_find_startcode(buf1, buf1 + size);
while (r < buf1 + size) {
const uint8_t *r1;
- while(!*(r++));
- r1 = ff_avc_find_startcode(r, buf1 + size);
+ if (s->nal_length_size) {
+ r1 = avc_mp4_find_startcode(r, buf1 + size, s->nal_length_size);
+ if (!r1) {
+ r1 = buf1 + size;
+ }
+ r += s->nal_length_size;
+ } else {
+ while(!*(r++));
+ r1 = ff_avc_find_startcode(r, buf1 + size);
+ }
nal_send(s1, r, r1 - r, (r1 == buf1 + size));
r = r1;
}
diff --git a/libavformat/rtpenc_latm.c b/libavformat/rtpenc_latm.c
index 64676771a7..7535a0fd5f 100644
--- a/libavformat/rtpenc_latm.c
+++ b/libavformat/rtpenc_latm.c
@@ -2,9 +2,9 @@
* RTP Packetization of MPEG-4 Audio (RFC 3016)
* Copyright (c) 2011 Juan Carlos Rodriguez <ing.juancarlosrodriguez@hotmail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
diff --git a/libavformat/rtpenc_mpv.c b/libavformat/rtpenc_mpv.c
index f6a5d7726a..0c617337b2 100644
--- a/libavformat/rtpenc_mpv.c
+++ b/libavformat/rtpenc_mpv.c
@@ -3,20 +3,20 @@
* Copyright (c) 2002 Fabrice Bellard
* Copyright (c) 2007 Luca Abeni
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -56,7 +56,7 @@ void ff_rtp_send_mpegvideo(AVFormatContext *s1, const uint8_t *buf1, int size)
r1 = buf1;
while (1) {
start_code = -1;
- r = ff_find_start_code(r1, end, &start_code);
+ r = avpriv_mpv_find_start_code(r1, end, &start_code);
if((start_code & 0xFFFFFF00) == 0x100) {
/* New start code found */
if (start_code == 0x100) {
diff --git a/libavformat/rtpenc_vp8.c b/libavformat/rtpenc_vp8.c
index afedbb49c0..e865514cef 100644
--- a/libavformat/rtpenc_vp8.c
+++ b/libavformat/rtpenc_vp8.c
@@ -2,20 +2,20 @@
* RTP VP8 Packetizer
* Copyright (c) 2010 Josh Allmann
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/rtpenc_xiph.c b/libavformat/rtpenc_xiph.c
index 07086b1a12..57686326a8 100644
--- a/libavformat/rtpenc_xiph.c
+++ b/libavformat/rtpenc_xiph.c
@@ -2,20 +2,20 @@
* RTP packetization for Xiph audio and video
* Copyright (c) 2010 Josh Allmann
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/rtpproto.c b/libavformat/rtpproto.c
index dba1d35b03..4f4cde621c 100644
--- a/libavformat/rtpproto.c
+++ b/libavformat/rtpproto.c
@@ -2,20 +2,20 @@
* RTP network protocol
* Copyright (c) 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -60,7 +60,7 @@ typedef struct RTPContext {
* @return zero if no error.
*/
-int rtp_set_remote_url(URLContext *h, const char *uri)
+int ff_rtp_set_remote_url(URLContext *h, const char *uri)
{
RTPContext *s = h->priv_data;
char hostname[256];
@@ -115,6 +115,7 @@ static void build_udp_url(char *buf, int buf_size,
url_add_option(buf, buf_size, "pkt_size=%d", max_packet_size);
if (connect)
url_add_option(buf, buf_size, "connect=1");
+ url_add_option(buf, buf_size, "fifo_size=0");
}
/**
@@ -225,20 +226,6 @@ static int rtp_read(URLContext *h, uint8_t *buf, int size)
int len, n;
struct pollfd p[2] = {{s->rtp_fd, POLLIN, 0}, {s->rtcp_fd, POLLIN, 0}};
-#if 0
- for(;;) {
- from_len = sizeof(from);
- len = recvfrom (s->rtp_fd, buf, size, 0,
- (struct sockaddr *)&from, &from_len);
- if (len < 0) {
- if (ff_neterrno() == AVERROR(EAGAIN) ||
- ff_neterrno() == AVERROR(EINTR))
- continue;
- return AVERROR(EIO);
- }
- break;
- }
-#else
for(;;) {
if (url_interrupt_cb())
return AVERROR_EXIT;
@@ -277,7 +264,6 @@ static int rtp_read(URLContext *h, uint8_t *buf, int size)
return AVERROR(EIO);
}
}
-#endif
return len;
}
@@ -296,14 +282,6 @@ static int rtp_write(URLContext *h, const uint8_t *buf, int size)
}
ret = ffurl_write(hd, buf, size);
-#if 0
- {
- struct timespec ts;
- ts.tv_sec = 0;
- ts.tv_nsec = 10 * 1000000;
- nanosleep(&ts, NULL);
- }
-#endif
return ret;
}
@@ -323,7 +301,7 @@ static int rtp_close(URLContext *h)
* @return the local port number
*/
-int rtp_get_local_rtp_port(URLContext *h)
+int ff_rtp_get_local_rtp_port(URLContext *h)
{
RTPContext *s = h->priv_data;
return ff_udp_get_local_port(s->rtp_hd);
@@ -335,7 +313,7 @@ int rtp_get_local_rtp_port(URLContext *h)
* @return the local port number
*/
-int rtp_get_local_rtcp_port(URLContext *h)
+int ff_rtp_get_local_rtcp_port(URLContext *h)
{
RTPContext *s = h->priv_data;
return ff_udp_get_local_port(s->rtcp_hd);
@@ -347,7 +325,7 @@ static int rtp_get_file_handle(URLContext *h)
return s->rtp_fd;
}
-int rtp_get_rtcp_file_handle(URLContext *h) {
+int ff_rtp_get_rtcp_file_handle(URLContext *h) {
RTPContext *s = h->priv_data;
return s->rtcp_fd;
}
diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index ce9bf1e1eb..11533968eb 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -2,20 +2,20 @@
* RTSP/SDP client
* Copyright (c) 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -45,6 +45,7 @@
#include "rtpdec_formats.h"
#include "rtpenc_chain.h"
#include "url.h"
+#include "rtpenc.h"
//#define DEBUG
@@ -56,6 +57,36 @@
#define SDP_MAX_SIZE 16384
#define RECVBUF_SIZE 10 * RTP_MAX_PACKET_LENGTH
+#define OFFSET(x) offsetof(RTSPState, x)
+#define DEC AV_OPT_FLAG_DECODING_PARAM
+#define ENC AV_OPT_FLAG_ENCODING_PARAM
+
+#define RTSP_FLAG_OPTS(name, longname) \
+ { name, longname, OFFSET(rtsp_flags), AV_OPT_TYPE_FLAGS, {0}, INT_MIN, INT_MAX, DEC, "rtsp_flags" }, \
+ { "filter_src", "Only receive packets from the negotiated peer IP", 0, AV_OPT_TYPE_CONST, {RTSP_FLAG_FILTER_SRC}, 0, 0, DEC, "rtsp_flags" }
+
+const AVOption ff_rtsp_options[] = {
+ { "initial_pause", "Don't start playing the stream immediately", OFFSET(initial_pause), AV_OPT_TYPE_INT, {0}, 0, 1, DEC },
+ FF_RTP_FLAG_OPTS(RTSPState, rtp_muxer_flags),
+ { "rtsp_transport", "RTSP transport protocols", OFFSET(lower_transport_mask), AV_OPT_TYPE_FLAGS, {0}, INT_MIN, INT_MAX, DEC|ENC, "rtsp_transport" }, \
+ { "udp", "UDP", 0, AV_OPT_TYPE_CONST, {1 << RTSP_LOWER_TRANSPORT_UDP}, 0, 0, DEC|ENC, "rtsp_transport" }, \
+ { "tcp", "TCP", 0, AV_OPT_TYPE_CONST, {1 << RTSP_LOWER_TRANSPORT_TCP}, 0, 0, DEC|ENC, "rtsp_transport" }, \
+ { "udp_multicast", "UDP multicast", 0, AV_OPT_TYPE_CONST, {1 << RTSP_LOWER_TRANSPORT_UDP_MULTICAST}, 0, 0, DEC, "rtsp_transport" },
+ { "http", "HTTP tunneling", 0, AV_OPT_TYPE_CONST, {(1 << RTSP_LOWER_TRANSPORT_HTTP)}, 0, 0, DEC, "rtsp_transport" },
+ RTSP_FLAG_OPTS("rtsp_flags", "RTSP flags"),
+ { NULL },
+};
+
+static const AVOption sdp_options[] = {
+ RTSP_FLAG_OPTS("sdp_flags", "SDP flags"),
+ { NULL },
+};
+
+static const AVOption rtp_options[] = {
+ RTSP_FLAG_OPTS("rtp_flags", "RTP flags"),
+ { NULL },
+};
+
static void get_word_until_chars(char *buf, int buf_size,
const char *sep, const char **pp)
{
@@ -326,9 +357,10 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1,
if (!strcmp(ff_rtp_enc_name(rtsp_st->sdp_payload_type), "MP2T")) {
/* no corresponding stream */
} else {
- st = av_new_stream(s, rt->nb_rtsp_streams - 1);
+ st = avformat_new_stream(s, NULL);
if (!st)
return;
+ st->id = rt->nb_rtsp_streams - 1;
rtsp_st->stream_index = st->index;
st->codec->codec_type = codec_type;
if (rtsp_st->sdp_payload_type < RTP_PT_PRIVATE) {
@@ -501,7 +533,7 @@ void ff_rtsp_undo_setup(AVFormatContext *s)
} else if (rt->transport == RTSP_TRANSPORT_RDT && CONFIG_RTPDEC)
ff_rdt_parse_close(rtsp_st->transport_priv);
else if (CONFIG_RTPDEC)
- rtp_parse_close(rtsp_st->transport_priv);
+ ff_rtp_parse_close(rtsp_st->transport_priv);
}
rtsp_st->transport_priv = NULL;
if (rtsp_st->rtp_handle)
@@ -558,7 +590,7 @@ static int rtsp_open_transport_ctx(AVFormatContext *s, RTSPStream *rtsp_st)
rtsp_st->dynamic_protocol_context,
rtsp_st->dynamic_handler);
else if (CONFIG_RTPDEC)
- rtsp_st->transport_priv = rtp_parse_open(s, st, rtsp_st->rtp_handle,
+ rtsp_st->transport_priv = ff_rtp_parse_open(s, st, rtsp_st->rtp_handle,
rtsp_st->sdp_payload_type,
(rt->lower_transport == RTSP_LOWER_TRANSPORT_TCP || !s->max_delay)
? 0 : RTP_REORDER_QUEUE_DEFAULT_SIZE);
@@ -567,9 +599,9 @@ static int rtsp_open_transport_ctx(AVFormatContext *s, RTSPStream *rtsp_st)
return AVERROR(ENOMEM);
} else if (rt->transport != RTSP_TRANSPORT_RDT && CONFIG_RTPDEC) {
if (rtsp_st->dynamic_handler) {
- rtp_parse_set_dynamic_protocol(rtsp_st->transport_priv,
- rtsp_st->dynamic_protocol_context,
- rtsp_st->dynamic_handler);
+ ff_rtp_parse_set_dynamic_protocol(rtsp_st->transport_priv,
+ rtsp_st->dynamic_protocol_context,
+ rtsp_st->dynamic_handler);
}
}
@@ -808,6 +840,9 @@ void ff_rtsp_parse_line(RTSPMessageHeader *reply, const char *buf,
if (strstr(p, "GET_PARAMETER") &&
method && !strcmp(method, "OPTIONS"))
rt->get_parameter_supported = 1;
+ } else if (av_stristart(p, "x-Accept-Dynamic-Rate:", &p) && rt) {
+ p += strspn(p, SPACE_CHARS);
+ rt->accept_dynamic_rate = atoi(p);
}
}
@@ -1116,20 +1151,12 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port,
}
}
-#if 0
- /* then try on any port */
- if (ffurl_open(&rtsp_st->rtp_handle, "rtp://", AVIO_FLAG_READ) < 0) {
- err = AVERROR_INVALIDDATA;
- goto fail;
- }
-#else
av_log(s, AV_LOG_ERROR, "Unable to open an input RTP port\n");
err = AVERROR(EIO);
goto fail;
-#endif
rtp_opened:
- port = rtp_get_local_rtp_port(rtsp_st->rtp_handle);
+ port = ff_rtp_get_local_rtp_port(rtsp_st->rtp_handle);
have_port:
snprintf(transport, sizeof(transport) - 1,
"%s/UDP;", trans_pref);
@@ -1173,6 +1200,8 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port,
snprintf(cmd, sizeof(cmd),
"Transport: %s\r\n",
transport);
+ if (rt->accept_dynamic_rate)
+ av_strlcat(cmd, "x-Dynamic-Rate: 0\r\n", sizeof(cmd));
if (i == 0 && rt->server_type == RTSP_SERVER_REAL && CONFIG_RTPDEC) {
char real_res[41], real_csum[9];
ff_rdt_calc_response_and_checksum(real_res, real_csum,
@@ -1221,7 +1250,7 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port,
case RTSP_LOWER_TRANSPORT_UDP: {
char url[1024], options[30] = "";
- if (rt->filter_source)
+ if (rt->rtsp_flags & RTSP_FLAG_FILTER_SRC)
av_strlcpy(options, "?connect=1", sizeof(options));
/* Use source address if specified */
if (reply->transports[0].source[0]) {
@@ -1233,7 +1262,7 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port,
reply->transports[0].server_port_min, "%s", options);
}
if (!(rt->server_type == RTSP_SERVER_WMS && i > 1) &&
- rtp_set_remote_url(rtsp_st->rtp_handle, url) < 0) {
+ ff_rtp_set_remote_url(rtsp_st->rtp_handle, url) < 0) {
err = AVERROR_INVALIDDATA;
goto fail;
}
@@ -1243,7 +1272,7 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port,
*/
if (!(rt->server_type == RTSP_SERVER_WMS && i > 1) && s->iformat &&
CONFIG_RTPDEC)
- rtp_send_punch_packets(rtsp_st->rtp_handle);
+ ff_rtp_send_punch_packets(rtsp_st->rtp_handle);
break;
}
case RTSP_LOWER_TRANSPORT_UDP_MULTICAST: {
@@ -1311,8 +1340,17 @@ int ff_rtsp_connect(AVFormatContext *s)
if (!ff_network_init())
return AVERROR(EIO);
-redirect:
+
rt->control_transport = RTSP_MODE_PLAIN;
+ if (rt->lower_transport_mask & (1 << RTSP_LOWER_TRANSPORT_HTTP)) {
+ rt->lower_transport_mask = 1 << RTSP_LOWER_TRANSPORT_TCP;
+ rt->control_transport = RTSP_MODE_TUNNEL;
+ }
+ /* Only pass through valid flags from here */
+ rt->lower_transport_mask &= (1 << RTSP_LOWER_TRANSPORT_NB) - 1;
+
+redirect:
+ lower_transport_mask = rt->lower_transport_mask;
/* extract hostname and port */
av_url_split(NULL, 0, auth, sizeof(auth),
host, sizeof(host), &port, path, sizeof(path), s->filename);
@@ -1322,6 +1360,7 @@ redirect:
if (port < 0)
port = RTSP_DEFAULT_PORT;
+#if FF_API_RTSP_URL_OPTIONS
/* search for options */
option_list = strrchr(path, '?');
if (option_list) {
@@ -1329,6 +1368,7 @@ redirect:
* the options back into the same string. */
filename = option_list;
while (option_list) {
+ int handled = 1;
/* move the option pointer */
option = ++option_list;
option_list = strchr(option_list, '&');
@@ -1346,7 +1386,7 @@ redirect:
lower_transport_mask |= (1<< RTSP_LOWER_TRANSPORT_TCP);
rt->control_transport = RTSP_MODE_TUNNEL;
} else if (!strcmp(option, "filter_src")) {
- rt->filter_source = 1;
+ rt->rtsp_flags |= RTSP_FLAG_FILTER_SRC;
} else {
/* Write options back into the buffer, using memmove instead
* of strcpy since the strings may overlap. */
@@ -1354,10 +1394,16 @@ redirect:
memmove(++filename, option, len);
filename += len;
if (option_list) *filename = '&';
+ handled = 0;
}
+ if (handled)
+ av_log(s, AV_LOG_WARNING, "Options passed via URL are "
+ "deprecated, use -rtsp_transport "
+ "and -rtsp_flags instead.\n");
}
*filename = 0;
}
+#endif
if (!lower_transport_mask)
lower_transport_mask = (1 << RTSP_LOWER_TRANSPORT_NB) - 1;
@@ -1577,7 +1623,7 @@ static int udp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st,
if (rtsp_st->rtp_handle) {
p[max_p].fd = ffurl_get_file_handle(rtsp_st->rtp_handle);
p[max_p++].events = POLLIN;
- p[max_p].fd = rtp_get_rtcp_file_handle(rtsp_st->rtp_handle);
+ p[max_p].fd = ff_rtp_get_rtcp_file_handle(rtsp_st->rtp_handle);
p[max_p++].events = POLLIN;
}
}
@@ -1632,7 +1678,7 @@ int ff_rtsp_fetch_packet(AVFormatContext *s, AVPacket *pkt)
if (rt->transport == RTSP_TRANSPORT_RDT) {
ret = ff_rdt_parse_packet(rt->cur_transport_priv, pkt, NULL, 0);
} else
- ret = rtp_parse_packet(rt->cur_transport_priv, pkt, NULL, 0);
+ ret = ff_rtp_parse_packet(rt->cur_transport_priv, pkt, NULL, 0);
if (ret == 0) {
rt->cur_transport_priv = NULL;
return 0;
@@ -1680,13 +1726,13 @@ int ff_rtsp_fetch_packet(AVFormatContext *s, AVPacket *pkt)
case RTSP_LOWER_TRANSPORT_UDP_MULTICAST:
len = udp_read_packet(s, &rtsp_st, rt->recvbuf, RECVBUF_SIZE, wait_end);
if (len > 0 && rtsp_st->transport_priv && rt->transport == RTSP_TRANSPORT_RTP)
- rtp_check_and_send_back_rr(rtsp_st->transport_priv, len);
+ ff_rtp_check_and_send_back_rr(rtsp_st->transport_priv, len);
break;
}
if (len == AVERROR(EAGAIN) && first_queue_st &&
rt->transport == RTSP_TRANSPORT_RTP) {
rtsp_st = first_queue_st;
- ret = rtp_parse_packet(rtsp_st->transport_priv, pkt, NULL, 0);
+ ret = ff_rtp_parse_packet(rtsp_st->transport_priv, pkt, NULL, 0);
goto end;
}
if (len < 0)
@@ -1696,7 +1742,7 @@ int ff_rtsp_fetch_packet(AVFormatContext *s, AVPacket *pkt)
if (rt->transport == RTSP_TRANSPORT_RDT) {
ret = ff_rdt_parse_packet(rtsp_st->transport_priv, pkt, &rt->recvbuf, len);
} else {
- ret = rtp_parse_packet(rtsp_st->transport_priv, pkt, &rt->recvbuf, len);
+ ret = ff_rtp_parse_packet(rtsp_st->transport_priv, pkt, &rt->recvbuf, len);
if (ret < 0) {
/* Either bad packet, or a RTCP packet. Check if the
* first_rtcp_ntp_time field was initialized. */
@@ -1800,8 +1846,9 @@ static int sdp_read_header(AVFormatContext *s, AVFormatParameters *ap)
namebuf, sizeof(namebuf), NULL, 0, NI_NUMERICHOST);
ff_url_join(url, sizeof(url), "rtp", NULL,
namebuf, rtsp_st->sdp_port,
- "?localport=%d&ttl=%d", rtsp_st->sdp_port,
- rtsp_st->sdp_ttl);
+ "?localport=%d&ttl=%d&connect=%d", rtsp_st->sdp_port,
+ rtsp_st->sdp_ttl,
+ rt->rtsp_flags & RTSP_FLAG_FILTER_SRC ? 1 : 0);
if (ffurl_open(&rtsp_st->rtp_handle, url, AVIO_FLAG_READ_WRITE) < 0) {
err = AVERROR_INVALIDDATA;
goto fail;
@@ -1823,14 +1870,22 @@ static int sdp_read_close(AVFormatContext *s)
return 0;
}
+static const AVClass sdp_demuxer_class = {
+ .class_name = "SDP demuxer",
+ .item_name = av_default_item_name,
+ .option = sdp_options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
AVInputFormat ff_sdp_demuxer = {
- "sdp",
- NULL_IF_CONFIG_SMALL("SDP"),
- sizeof(RTSPState),
- sdp_probe,
- sdp_read_header,
- ff_rtsp_fetch_packet,
- sdp_read_close,
+ .name = "sdp",
+ .long_name = NULL_IF_CONFIG_SMALL("SDP"),
+ .priv_data_size = sizeof(RTSPState),
+ .read_probe = sdp_probe,
+ .read_header = sdp_read_header,
+ .read_packet = ff_rtsp_fetch_packet,
+ .read_close = sdp_read_close,
+ .priv_class = &sdp_demuxer_class
};
#endif /* CONFIG_SDP_DEMUXER */
@@ -1927,15 +1982,23 @@ fail:
return ret;
}
+static const AVClass rtp_demuxer_class = {
+ .class_name = "RTP demuxer",
+ .item_name = av_default_item_name,
+ .option = rtp_options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
AVInputFormat ff_rtp_demuxer = {
- "rtp",
- NULL_IF_CONFIG_SMALL("RTP input format"),
- sizeof(RTSPState),
- rtp_probe,
- rtp_read_header,
- ff_rtsp_fetch_packet,
- sdp_read_close,
+ .name = "rtp",
+ .long_name = NULL_IF_CONFIG_SMALL("RTP input format"),
+ .priv_data_size = sizeof(RTSPState),
+ .read_probe = rtp_probe,
+ .read_header = rtp_read_header,
+ .read_packet = ff_rtsp_fetch_packet,
+ .read_close = sdp_read_close,
.flags = AVFMT_NOFILE,
+ .priv_class = &rtp_demuxer_class
};
#endif /* CONFIG_RTP_DEMUXER */
diff --git a/libavformat/rtsp.h b/libavformat/rtsp.h
index 7d2460fe2f..da61829da2 100644
--- a/libavformat/rtsp.h
+++ b/libavformat/rtsp.h
@@ -2,20 +2,20 @@
* RTSP definitions
* Copyright (c) 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVFORMAT_RTSP_H
@@ -29,6 +29,7 @@
#include "httpauth.h"
#include "libavutil/log.h"
+#include "libavutil/opt.h"
/**
* Network layer over which RTP/etc packet data will be transported.
@@ -37,7 +38,10 @@ enum RTSPLowerTransport {
RTSP_LOWER_TRANSPORT_UDP = 0, /**< UDP/unicast */
RTSP_LOWER_TRANSPORT_TCP = 1, /**< TCP; interleaved in RTSP */
RTSP_LOWER_TRANSPORT_UDP_MULTICAST = 2, /**< UDP/multicast */
- RTSP_LOWER_TRANSPORT_NB
+ RTSP_LOWER_TRANSPORT_NB,
+ RTSP_LOWER_TRANSPORT_HTTP = 8, /**< HTTP tunneled - not a proper
+ transport mode as such,
+ only for use via AVOptions */
};
/**
@@ -220,9 +224,6 @@ typedef struct RTSPState {
* see rtsp_read_play() and rtsp_read_seek(). */
int64_t seek_timestamp;
- /* XXX: currently we use unbuffered input */
- // AVIOContext rtsp_gb;
-
int seq; /**< RTSP command sequence number */
/** copy of RTSPMessageHeader->session_id, i.e. the server-provided session
@@ -316,10 +317,6 @@ typedef struct RTSPState {
/** Reusable buffer for receiving packets */
uint8_t* recvbuf;
- /** Filter incoming UDP packets - receive packets only from the right
- * source address and port. */
- int filter_source;
-
/**
* A mask with all requested transport methods
*/
@@ -349,8 +346,20 @@ typedef struct RTSPState {
* Option flags for the chained RTP muxer.
*/
int rtp_muxer_flags;
+
+ /** Whether the server accepts the x-Dynamic-Rate header */
+ int accept_dynamic_rate;
+
+ /**
+ * Various option flags for the RTSP muxer/demuxer.
+ */
+ int rtsp_flags;
} RTSPState;
+#define RTSP_FLAG_FILTER_SRC 0x1 /**< Filter incoming UDP packets -
+ receive packets only from the right
+ source address and port. */
+
/**
* Describes a single stream, as identified by a single m= line block in the
* SDP content. In the case of RDT, one RTSPStream can represent multiple
@@ -488,9 +497,9 @@ void ff_rtsp_close_streams(AVFormatContext *s);
/**
* Close all connection handles within the RTSP (de)muxer
*
- * @param rt RTSP (de)muxer context
+ * @param s RTSP (de)muxer context
*/
-void ff_rtsp_close_connections(AVFormatContext *rt);
+void ff_rtsp_close_connections(AVFormatContext *s);
/**
* Get the description of the stream and set up the RTSPStream child
@@ -537,4 +546,6 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port,
*/
void ff_rtsp_undo_setup(AVFormatContext *s);
+extern const AVOption ff_rtsp_options[];
+
#endif /* AVFORMAT_RTSP_H */
diff --git a/libavformat/rtspcodes.h b/libavformat/rtspcodes.h
index 63ceb66cfe..9ee96bfcd0 100644
--- a/libavformat/rtspcodes.h
+++ b/libavformat/rtspcodes.h
@@ -2,20 +2,20 @@
* RTSP definitions
* copyright (c) 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/rtspdec.c b/libavformat/rtspdec.c
index 2dff46d1de..f55b8cf2a2 100644
--- a/libavformat/rtspdec.c
+++ b/libavformat/rtspdec.c
@@ -2,27 +2,26 @@
* RTSP demuxer
* Copyright (c) 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/avstring.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mathematics.h"
-#include "libavutil/opt.h"
#include "avformat.h"
#include "internal.h"
@@ -164,11 +163,6 @@ static int rtsp_read_header(AVFormatContext *s,
return AVERROR(ENOMEM);
rt->real_setup = rt->real_setup_cache + s->nb_streams;
-#if FF_API_FORMAT_PARAMETERS
- if (ap->initial_pause)
- rt->initial_pause = ap->initial_pause;
-#endif
-
if (rt->initial_pause) {
/* do not start immediately */
} else {
@@ -209,7 +203,7 @@ redo:
id = buf[0];
len = AV_RB16(buf + 1);
av_dlog(s, "id=%d len=%d\n", id, len);
- if (len > buf_size || len < 12)
+ if (len > buf_size || len < 8)
goto redo;
/* get the data */
ret = ffurl_read_complete(rt->rtsp_hd, buf, len);
@@ -383,12 +377,6 @@ static int rtsp_read_close(AVFormatContext *s)
{
RTSPState *rt = s->priv_data;
-#if 0
- /* NOTE: it is valid to flush the buffer here */
- if (rt->lower_transport == RTSP_LOWER_TRANSPORT_TCP) {
- avio_close(&rt->rtsp_gb);
- }
-#endif
ff_rtsp_send_cmd_async(s, "TEARDOWN", rt->control_uri, NULL);
ff_rtsp_close_streams(s);
@@ -399,27 +387,22 @@ static int rtsp_read_close(AVFormatContext *s)
return 0;
}
-static const AVOption options[] = {
- { "initial_pause", "Don't start playing the stream immediately", offsetof(RTSPState, initial_pause), FF_OPT_TYPE_INT, {.dbl = 0}, 0, 1, AV_OPT_FLAG_DECODING_PARAM },
- { NULL },
-};
-
const AVClass rtsp_demuxer_class = {
.class_name = "RTSP demuxer",
.item_name = av_default_item_name,
- .option = options,
+ .option = ff_rtsp_options,
.version = LIBAVUTIL_VERSION_INT,
};
AVInputFormat ff_rtsp_demuxer = {
- "rtsp",
- NULL_IF_CONFIG_SMALL("RTSP input format"),
- sizeof(RTSPState),
- rtsp_probe,
- rtsp_read_header,
- rtsp_read_packet,
- rtsp_read_close,
- rtsp_read_seek,
+ .name = "rtsp",
+ .long_name = NULL_IF_CONFIG_SMALL("RTSP input format"),
+ .priv_data_size = sizeof(RTSPState),
+ .read_probe = rtsp_probe,
+ .read_header = rtsp_read_header,
+ .read_packet = rtsp_read_packet,
+ .read_close = rtsp_read_close,
+ .read_seek = rtsp_read_seek,
.flags = AVFMT_NOFILE,
.read_play = rtsp_read_play,
.read_pause = rtsp_read_pause,
diff --git a/libavformat/rtspenc.c b/libavformat/rtspenc.c
index b76b6adb99..b54ae28eb8 100644
--- a/libavformat/rtspenc.c
+++ b/libavformat/rtspenc.c
@@ -2,20 +2,20 @@
* RTSP muxer
* Copyright (c) 2010 Martin Storsjo
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -33,20 +33,13 @@
#include "libavutil/intreadwrite.h"
#include "libavutil/avstring.h"
#include "url.h"
-#include "libavutil/opt.h"
-#include "rtpenc.h"
#define SDP_MAX_SIZE 16384
-static const AVOption options[] = {
- FF_RTP_FLAG_OPTS(RTSPState, rtp_muxer_flags),
- { NULL },
-};
-
static const AVClass rtsp_muxer_class = {
.class_name = "RTSP muxer",
.item_name = av_default_item_name,
- .option = options,
+ .option = ff_rtsp_options,
.version = LIBAVUTIL_VERSION_INT,
};
@@ -241,16 +234,14 @@ static int rtsp_write_close(AVFormatContext *s)
}
AVOutputFormat ff_rtsp_muxer = {
- "rtsp",
- NULL_IF_CONFIG_SMALL("RTSP output format"),
- NULL,
- NULL,
- sizeof(RTSPState),
- CODEC_ID_AAC,
- CODEC_ID_MPEG4,
- rtsp_write_header,
- rtsp_write_packet,
- rtsp_write_close,
+ .name = "rtsp",
+ .long_name = NULL_IF_CONFIG_SMALL("RTSP output format"),
+ .priv_data_size = sizeof(RTSPState),
+ .audio_codec = CODEC_ID_AAC,
+ .video_codec = CODEC_ID_MPEG4,
+ .write_header = rtsp_write_header,
+ .write_packet = rtsp_write_packet,
+ .write_trailer = rtsp_write_close,
.flags = AVFMT_NOFILE | AVFMT_GLOBALHEADER,
.priv_class = &rtsp_muxer_class,
};
diff --git a/libavformat/sapdec.c b/libavformat/sapdec.c
index 15d772c780..68e3c5c095 100644
--- a/libavformat/sapdec.c
+++ b/libavformat/sapdec.c
@@ -2,20 +2,20 @@
* Session Announcement Protocol (RFC 2974) demuxer
* Copyright (c) 2010 Martin Storsjo
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -163,11 +163,12 @@ static int sap_read_header(AVFormatContext *s,
if (sap->sdp_ctx->ctx_flags & AVFMTCTX_NOHEADER)
s->ctx_flags |= AVFMTCTX_NOHEADER;
for (i = 0; i < sap->sdp_ctx->nb_streams; i++) {
- AVStream *st = av_new_stream(s, i);
+ AVStream *st = avformat_new_stream(s, NULL);
if (!st) {
ret = AVERROR(ENOMEM);
goto fail;
}
+ st->id = i;
avcodec_copy_context(st->codec, sap->sdp_ctx->streams[i]->codec);
st->time_base = sap->sdp_ctx->streams[i]->time_base;
}
@@ -211,11 +212,12 @@ static int sap_fetch_packet(AVFormatContext *s, AVPacket *pkt)
if (s->ctx_flags & AVFMTCTX_NOHEADER) {
while (sap->sdp_ctx->nb_streams > s->nb_streams) {
int i = s->nb_streams;
- AVStream *st = av_new_stream(s, i);
+ AVStream *st = avformat_new_stream(s, NULL);
if (!st) {
av_free_packet(pkt);
return AVERROR(ENOMEM);
}
+ st->id = i;
avcodec_copy_context(st->codec, sap->sdp_ctx->streams[i]->codec);
st->time_base = sap->sdp_ctx->streams[i]->time_base;
}
@@ -224,13 +226,13 @@ static int sap_fetch_packet(AVFormatContext *s, AVPacket *pkt)
}
AVInputFormat ff_sap_demuxer = {
- "sap",
- NULL_IF_CONFIG_SMALL("SAP input format"),
- sizeof(struct SAPState),
- sap_probe,
- sap_read_header,
- sap_fetch_packet,
- sap_read_close,
+ .name = "sap",
+ .long_name = NULL_IF_CONFIG_SMALL("SAP input format"),
+ .priv_data_size = sizeof(struct SAPState),
+ .read_probe = sap_probe,
+ .read_header = sap_read_header,
+ .read_packet = sap_fetch_packet,
+ .read_close = sap_read_close,
.flags = AVFMT_NOFILE,
};
diff --git a/libavformat/sapenc.c b/libavformat/sapenc.c
index 3abd79e4e8..b84cce50a4 100644
--- a/libavformat/sapenc.c
+++ b/libavformat/sapenc.c
@@ -2,20 +2,20 @@
* Session Announcement Protocol (RFC 2974) muxer
* Copyright (c) 2010 Martin Storsjo
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -250,16 +250,14 @@ static int sap_write_packet(AVFormatContext *s, AVPacket *pkt)
}
AVOutputFormat ff_sap_muxer = {
- "sap",
- NULL_IF_CONFIG_SMALL("SAP output format"),
- NULL,
- NULL,
- sizeof(struct SAPState),
- CODEC_ID_AAC,
- CODEC_ID_MPEG4,
- sap_write_header,
- sap_write_packet,
- sap_write_close,
+ .name = "sap",
+ .long_name = NULL_IF_CONFIG_SMALL("SAP output format"),
+ .priv_data_size = sizeof(struct SAPState),
+ .audio_codec = CODEC_ID_AAC,
+ .video_codec = CODEC_ID_MPEG4,
+ .write_header = sap_write_header,
+ .write_packet = sap_write_packet,
+ .write_trailer = sap_write_close,
.flags = AVFMT_NOFILE | AVFMT_GLOBALHEADER,
};
diff --git a/libavformat/sauce.c b/libavformat/sauce.c
index a125241335..21cc95bccb 100644
--- a/libavformat/sauce.c
+++ b/libavformat/sauce.c
@@ -2,20 +2,20 @@
* SAUCE header parser
* Copyright (c) 2010 Peter Ross <pross@xvid.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/sauce.h b/libavformat/sauce.h
index 62d8e688a4..0ba9ae5b4a 100644
--- a/libavformat/sauce.h
+++ b/libavformat/sauce.h
@@ -2,20 +2,20 @@
* SAUCE header parser
* Copyright (c) 2010 Peter Ross <pross@xvid.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/sdp.c b/libavformat/sdp.c
index c227c7f603..37eee26485 100644
--- a/libavformat/sdp.c
+++ b/libavformat/sdp.c
@@ -1,20 +1,20 @@
/*
* copyright (c) 2007 Luca Abeni
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -252,7 +252,7 @@ static char *xiph_extradata2config(AVCodecContext *c)
return NULL;
}
- if (ff_split_xiph_headers(c->extradata, c->extradata_size,
+ if (avpriv_split_xiph_headers(c->extradata, c->extradata_size,
first_header_size, header_start,
header_len) < 0) {
av_log(c, AV_LOG_ERROR, "Extradata corrupt.\n");
@@ -342,7 +342,7 @@ static char *latm_context2config(AVCodecContext *c)
char *config;
for (rate_index = 0; rate_index < 16; rate_index++)
- if (ff_mpeg4audio_sample_rates[rate_index] == c->sample_rate)
+ if (avpriv_mpeg4audio_sample_rates[rate_index] == c->sample_rate)
break;
if (rate_index == 16) {
av_log(c, AV_LOG_ERROR, "Unsupported sample rate\n");
@@ -532,10 +532,7 @@ void ff_sdp_write_media(char *buff, int size, AVCodecContext *c, const char *des
const char *type;
int payload_type;
- payload_type = ff_rtp_get_payload_type(c);
- if (payload_type < 0) {
- payload_type = RTP_PT_PRIVATE + (c->codec_type == AVMEDIA_TYPE_AUDIO);
- }
+ payload_type = ff_rtp_get_payload_type(fmt, c);
switch (c->codec_type) {
case AVMEDIA_TYPE_VIDEO : type = "video" ; break;
diff --git a/tests/seek_test.c b/libavformat/seek-test.c
index 71b2a2d6c0..cea36cabb2 100644
--- a/tests/seek_test.c
+++ b/libavformat/seek-test.c
@@ -2,20 +2,20 @@
* Copyright (c) 2003 Fabrice Bellard
* Copyright (c) 2007 Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -86,7 +86,7 @@ int main(int argc, char **argv)
exit(1);
}
- ret = av_find_stream_info(ic);
+ ret = avformat_find_stream_info(ic, NULL);
if (ret < 0) {
fprintf(stderr, "%s: could not find codec parameters\n", filename);
exit(1);
diff --git a/libavformat/seek.c b/libavformat/seek.c
index 6c4286bb8e..65211bfacf 100644
--- a/libavformat/seek.c
+++ b/libavformat/seek.c
@@ -3,20 +3,20 @@
*
* Copyright (c) 2009 Ivan Schreter
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/seek.h b/libavformat/seek.h
index fd95f497d6..408f7d6ac7 100644
--- a/libavformat/seek.h
+++ b/libavformat/seek.h
@@ -3,20 +3,20 @@
*
* Copyright (c) 2009 Ivan Schreter
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/segafilm.c b/libavformat/segafilm.c
index 0ad5fbbe0b..1ae105eb77 100644
--- a/libavformat/segafilm.c
+++ b/libavformat/segafilm.c
@@ -2,20 +2,20 @@
* Sega FILM Format (CPK) Demuxer
* Copyright (c) 2003 The ffmpeg Project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -111,11 +111,16 @@ static int film_read_header(AVFormatContext *s,
film->audio_samplerate = AV_RB16(&scratch[24]);
film->audio_channels = scratch[21];
film->audio_bits = scratch[22];
- if (film->audio_bits == 8)
- film->audio_type = CODEC_ID_PCM_S8;
- else if (film->audio_bits == 16)
- film->audio_type = CODEC_ID_PCM_S16BE;
- else
+ if (scratch[23] == 2)
+ film->audio_type = CODEC_ID_ADPCM_ADX;
+ else if (film->audio_channels > 0) {
+ if (film->audio_bits == 8)
+ film->audio_type = CODEC_ID_PCM_S8;
+ else if (film->audio_bits == 16)
+ film->audio_type = CODEC_ID_PCM_S16BE;
+ else
+ film->audio_type = CODEC_ID_NONE;
+ } else
film->audio_type = CODEC_ID_NONE;
}
@@ -129,7 +134,7 @@ static int film_read_header(AVFormatContext *s,
/* initialize the decoder streams */
if (film->video_type) {
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
film->video_stream_index = st->index;
@@ -141,7 +146,7 @@ static int film_read_header(AVFormatContext *s,
}
if (film->audio_type) {
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
film->audio_stream_index = st->index;
@@ -149,12 +154,19 @@ static int film_read_header(AVFormatContext *s,
st->codec->codec_id = film->audio_type;
st->codec->codec_tag = 1;
st->codec->channels = film->audio_channels;
- st->codec->bits_per_coded_sample = film->audio_bits;
st->codec->sample_rate = film->audio_samplerate;
+
+ if (film->audio_type == CODEC_ID_ADPCM_ADX) {
+ st->codec->bits_per_coded_sample = 18 * 8 / 32;
+ st->codec->block_align = st->codec->channels * 18;
+ } else {
+ st->codec->bits_per_coded_sample = film->audio_bits;
+ st->codec->block_align = st->codec->channels *
+ st->codec->bits_per_coded_sample / 8;
+ }
+
st->codec->bit_rate = st->codec->channels * st->codec->sample_rate *
st->codec->bits_per_coded_sample;
- st->codec->block_align = st->codec->channels *
- st->codec->bits_per_coded_sample / 8;
}
/* load the sample table */
@@ -167,6 +179,8 @@ static int film_read_header(AVFormatContext *s,
if(film->sample_count >= UINT_MAX / sizeof(film_sample))
return -1;
film->sample_table = av_malloc(film->sample_count * sizeof(film_sample));
+ if (!film->sample_table)
+ return AVERROR(ENOMEM);
for(i=0; i<s->nb_streams; i++)
av_set_pts_info(s->streams[i], 33, 1, film->base_clock);
@@ -187,8 +201,12 @@ static int film_read_header(AVFormatContext *s,
film->sample_table[i].pts *= film->base_clock;
film->sample_table[i].pts /= film->audio_samplerate;
- audio_frame_counter += (film->sample_table[i].sample_size /
- (film->audio_channels * film->audio_bits / 8));
+ if (film->audio_type == CODEC_ID_ADPCM_ADX)
+ audio_frame_counter += (film->sample_table[i].sample_size * 32 /
+ (18 * film->audio_channels));
+ else if (film->audio_type != CODEC_ID_NONE)
+ audio_frame_counter += (film->sample_table[i].sample_size /
+ (film->audio_channels * film->audio_bits / 8));
} else {
film->sample_table[i].stream = film->video_stream_index;
film->sample_table[i].pts = AV_RB32(&scratch[8]) & 0x7FFFFFFF;
@@ -227,7 +245,8 @@ static int film_read_packet(AVFormatContext *s,
return AVERROR(ENOMEM);
avio_read(pb, pkt->data, sample->sample_size);
} else if ((sample->stream == film->audio_stream_index) &&
- (film->audio_channels == 2)) {
+ (film->audio_channels == 2) &&
+ (film->audio_type != CODEC_ID_ADPCM_ADX)) {
/* stereo PCM needs to be interleaved */
if (av_new_packet(pkt, sample->sample_size))
@@ -238,6 +257,10 @@ static int film_read_packet(AVFormatContext *s,
av_free(film->stereo_buffer);
film->stereo_buffer_size = sample->sample_size;
film->stereo_buffer = av_malloc(film->stereo_buffer_size);
+ if (!film->stereo_buffer) {
+ film->stereo_buffer_size = 0;
+ return AVERROR(ENOMEM);
+ }
}
pkt->pos= avio_tell(pb);
@@ -283,11 +306,11 @@ static int film_read_close(AVFormatContext *s)
}
AVInputFormat ff_segafilm_demuxer = {
- "film_cpk",
- NULL_IF_CONFIG_SMALL("Sega FILM/CPK format"),
- sizeof(FilmDemuxContext),
- film_probe,
- film_read_header,
- film_read_packet,
- film_read_close,
+ .name = "film_cpk",
+ .long_name = NULL_IF_CONFIG_SMALL("Sega FILM/CPK format"),
+ .priv_data_size = sizeof(FilmDemuxContext),
+ .read_probe = film_probe,
+ .read_header = film_read_header,
+ .read_packet = film_read_packet,
+ .read_close = film_read_close,
};
diff --git a/libavformat/segment.c b/libavformat/segment.c
new file mode 100644
index 0000000000..80716bcf90
--- /dev/null
+++ b/libavformat/segment.c
@@ -0,0 +1,234 @@
+/*
+ * Generic Segmenter
+ * Copyright (c) 2011, Luca Barbato
+ *
+ * This file is part of Libav.
+ *
+ * Libav 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.
+ *
+ * Libav 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/avstring.h"
+#include "libavutil/log.h"
+#include "libavutil/opt.h"
+#include "libavutil/mathematics.h"
+#include "libavutil/parseutils.h"
+#include "avformat.h"
+#include "internal.h"
+#include <strings.h>
+#include <float.h>
+
+typedef struct {
+ const AVClass *class; /**< Class for private options. */
+ int number;
+ AVFormatContext *avf;
+ char *format; /**< Set by a private option. */
+ char *pattern; /**< Set by a private option. */
+ char *path; /**< Set by a private option. */
+ float time; /**< Set by a private option. */
+ int64_t offset_time;
+ int64_t recording_time;
+} SegmentContext;
+
+#if CONFIG_SEGMENT_MUXER
+
+static int segment_header(SegmentContext *s)
+{
+ AVFormatContext *oc = s->avf;
+ int err = 0;
+
+ av_strlcpy(oc->filename, s->path, sizeof(oc->filename));
+
+ av_strlcatf(oc->filename, sizeof(oc->filename),
+ s->pattern, s->number++);
+
+ if ((err = avio_open(&oc->pb, oc->filename, AVIO_FLAG_WRITE)) < 0) {
+ return err;
+ }
+
+ if (!oc->priv_data && oc->oformat->priv_data_size > 0) {
+ oc->priv_data = av_mallocz(oc->oformat->priv_data_size);
+ if (!oc->priv_data) {
+ avio_close(oc->pb);
+ return AVERROR(ENOMEM);
+ }
+ }
+
+ if ((err = oc->oformat->write_header(oc)) < 0) {
+ avio_close(oc->pb);
+ av_freep(&oc->priv_data);
+ }
+
+ return err;
+}
+
+static int segment_trailer(AVFormatContext *oc)
+{
+ int ret = 0;
+
+ if(oc->oformat->write_trailer)
+ ret = oc->oformat->write_trailer(oc);
+
+ avio_close(oc->pb);
+ av_freep(&oc->priv_data);
+
+ return ret;
+}
+
+static int seg_write_header(AVFormatContext *s)
+{
+ SegmentContext *seg = s->priv_data;
+ AVFormatContext *oc;
+ int ret;
+
+ seg->number = 0;
+ seg->recording_time = seg->time*1000000;
+ seg->offset_time = 0;
+
+ if (!seg->path) {
+ char *t;
+ seg->path = av_strdup(s->filename);
+ t = strrchr(seg->path, '.');
+ if (t) *t = '\0';
+ }
+
+ oc = avformat_alloc_context();
+
+ if (!oc) {
+ return AVERROR(ENOMEM);
+ }
+
+ oc->oformat = av_guess_format(seg->format, NULL, NULL);
+
+ if (!oc->oformat) {
+ avformat_free_context(oc);
+ return AVERROR_MUXER_NOT_FOUND;
+ }
+
+ seg->avf = oc;
+
+ oc->streams = s->streams;
+ oc->nb_streams = s->nb_streams;
+
+ av_strlcpy(oc->filename, seg->path, sizeof(oc->filename));
+
+ av_strlcatf(oc->filename, sizeof(oc->filename),
+ seg->pattern, seg->number++);
+
+ if ((ret = avio_open(&oc->pb, oc->filename, AVIO_FLAG_WRITE)) < 0) {
+ avformat_free_context(oc);
+ return ret;
+ }
+
+ if ((ret = avformat_write_header(oc, NULL)) < 0) {
+ avio_close(oc->pb);
+ }
+
+ if (ret)
+ avformat_free_context(oc);
+
+ avio_printf(s->pb, "%s\n", oc->filename);
+ avio_flush(s->pb);
+
+ return ret;
+}
+
+static int seg_write_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ SegmentContext *seg = s->priv_data;
+ AVFormatContext *oc = seg->avf;
+ AVStream *st = oc->streams[pkt->stream_index];
+ int ret;
+
+ if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO &&
+ av_compare_ts(pkt->pts, st->time_base,
+ seg->recording_time*seg->number,
+ (AVRational){1, 1000000}) >= 0 &&
+ pkt->flags & AV_PKT_FLAG_KEY) {
+ av_log(s, AV_LOG_INFO, "I'd reset at %d %"PRId64"\n",
+ pkt->stream_index, pkt->pts);
+
+ ret = segment_trailer(oc);
+ if (!ret)
+ ret = segment_header(seg);
+
+ if (ret) {
+ avformat_free_context(oc);
+ return ret;
+ }
+ avio_printf(s->pb, "%s\n", oc->filename);
+ avio_flush(s->pb);
+ }
+
+ ret = oc->oformat->write_packet(oc, pkt);
+
+ return ret;
+}
+
+static int seg_write_trailer(struct AVFormatContext *s)
+{
+ SegmentContext *seg = s->priv_data;
+ AVFormatContext *oc = seg->avf;
+
+ return segment_trailer(oc);
+}
+
+#endif /* CONFIG_SEGMENT_MUXER */
+
+#define OFFSET(x) offsetof(SegmentContext, x)
+#define E AV_OPT_FLAG_ENCODING_PARAM
+static const AVOption options[] = {
+ { "container_format", "container format used for the segments", OFFSET(format), AV_OPT_TYPE_STRING, {.str = "nut"}, 0, 0, E },
+ { "segment_time", "segment lenght in seconds", OFFSET(time), AV_OPT_TYPE_FLOAT, {.dbl = 2}, 0, FLT_MAX, E },
+ { "segment_pattern", "pattern to use in segment files", OFFSET(pattern),AV_OPT_TYPE_STRING, {.str = "%03d"}, 0, 0, E },
+ { "segment_basename", "basename to use in segment files", OFFSET(path ),AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E },
+ { NULL },
+};
+
+static const AVClass seg_class = {
+ .class_name = "segment muxer",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
+/* input
+#if CONFIG_IMAGE2_DEMUXER
+AVInputFormat ff_image2_demuxer = {
+ .name = "image2",
+ .long_name = NULL_IF_CONFIG_SMALL("image2 sequence"),
+ .priv_data_size = sizeof(VideoData),
+ .read_probe = read_probe,
+ .read_header = read_header,
+ .read_packet = read_packet,
+ .flags = AVFMT_NOFILE,
+ .priv_class = &img2_class,
+};
+#endif
+*/
+
+/* output */
+#if CONFIG_SEGMENT_MUXER
+AVOutputFormat ff_segment_muxer = {
+ .name = "segment",
+ .long_name = NULL_IF_CONFIG_SMALL("segment muxer"),
+ .extensions = "m3u8",
+ .priv_data_size = sizeof(SegmentContext),
+ .flags = AVFMT_GLOBALHEADER,
+ .write_header = seg_write_header,
+ .write_packet = seg_write_packet,
+ .write_trailer = seg_write_trailer,
+ .priv_class = &seg_class,
+};
+#endif
diff --git a/libavformat/sierravmd.c b/libavformat/sierravmd.c
index c0fb22211b..e1367c29ae 100644
--- a/libavformat/sierravmd.c
+++ b/libavformat/sierravmd.c
@@ -2,20 +2,20 @@
* Sierra VMD Format Demuxer
* Copyright (c) 2004 The ffmpeg Project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -104,7 +104,7 @@ static int vmd_read_header(AVFormatContext *s,
else
vmd->is_indeo3 = 0;
/* start up the decoders */
- vst = av_new_stream(s, 0);
+ vst = avformat_new_stream(s, NULL);
if (!vst)
return AVERROR(ENOMEM);
av_set_pts_info(vst, 33, 1, 10);
@@ -125,7 +125,7 @@ static int vmd_read_header(AVFormatContext *s,
/* if sample rate is 0, assume no audio */
vmd->sample_rate = AV_RL16(&vmd->vmd_header[804]);
if (vmd->sample_rate) {
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
vmd->audio_stream_index = st->index;
@@ -281,11 +281,11 @@ static int vmd_read_close(AVFormatContext *s)
}
AVInputFormat ff_vmd_demuxer = {
- "vmd",
- NULL_IF_CONFIG_SMALL("Sierra VMD format"),
- sizeof(VmdDemuxContext),
- vmd_probe,
- vmd_read_header,
- vmd_read_packet,
- vmd_read_close,
+ .name = "vmd",
+ .long_name = NULL_IF_CONFIG_SMALL("Sierra VMD format"),
+ .priv_data_size = sizeof(VmdDemuxContext),
+ .read_probe = vmd_probe,
+ .read_header = vmd_read_header,
+ .read_packet = vmd_read_packet,
+ .read_close = vmd_read_close,
};
diff --git a/libavformat/siff.c b/libavformat/siff.c
index 23c122f7a7..77cbc66804 100644
--- a/libavformat/siff.c
+++ b/libavformat/siff.c
@@ -2,20 +2,20 @@
* Beam Software SIFF demuxer
* Copyright (c) 2007 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -71,7 +71,7 @@ static int siff_probe(AVProbeData *p)
static int create_audio_stream(AVFormatContext *s, SIFFContext *c)
{
AVStream *ast;
- ast = av_new_stream(s, 0);
+ ast = avformat_new_stream(s, NULL);
if (!ast)
return -1;
ast->codec->codec_type = AVMEDIA_TYPE_AUDIO;
@@ -115,7 +115,7 @@ static int siff_parse_vbv1(AVFormatContext *s, SIFFContext *c, AVIOContext *pb)
avio_skip(pb, 16); //zeroes
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return -1;
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
@@ -228,11 +228,11 @@ static int siff_read_packet(AVFormatContext *s, AVPacket *pkt)
}
AVInputFormat ff_siff_demuxer = {
- "siff",
- NULL_IF_CONFIG_SMALL("Beam Software SIFF"),
- sizeof(SIFFContext),
- siff_probe,
- siff_read_header,
- siff_read_packet,
+ .name = "siff",
+ .long_name = NULL_IF_CONFIG_SMALL("Beam Software SIFF"),
+ .priv_data_size = sizeof(SIFFContext),
+ .read_probe = siff_probe,
+ .read_header = siff_read_header,
+ .read_packet = siff_read_packet,
.extensions = "vb,son"
};
diff --git a/libavformat/smacker.c b/libavformat/smacker.c
index db9a02bb6c..3ffb65eee0 100644
--- a/libavformat/smacker.c
+++ b/libavformat/smacker.c
@@ -2,20 +2,20 @@
* Smacker demuxer
* Copyright (c) 2006 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -31,11 +31,11 @@
#define SMACKER_FLAG_RING_FRAME 0x01
enum SAudFlags {
- SMK_AUD_PACKED = 0x80000000,
- SMK_AUD_16BITS = 0x20000000,
- SMK_AUD_STEREO = 0x10000000,
- SMK_AUD_BINKAUD = 0x08000000,
- SMK_AUD_USEDCT = 0x04000000
+ SMK_AUD_PACKED = 0x80,
+ SMK_AUD_16BITS = 0x20,
+ SMK_AUD_STEREO = 0x10,
+ SMK_AUD_BINKAUD = 0x08,
+ SMK_AUD_USEDCT = 0x04
};
typedef struct SmackerContext {
@@ -48,6 +48,7 @@ typedef struct SmackerContext {
uint32_t audio[7];
uint32_t treesize;
uint32_t mmap_size, mclr_size, full_size, type_size;
+ uint8_t aflags[7];
uint32_t rates[7];
uint32_t pad;
/* frame info */
@@ -129,8 +130,10 @@ static int smacker_read_header(AVFormatContext *s, AVFormatParameters *ap)
smk->mclr_size = avio_rl32(pb);
smk->full_size = avio_rl32(pb);
smk->type_size = avio_rl32(pb);
- for(i = 0; i < 7; i++)
- smk->rates[i] = avio_rl32(pb);
+ for(i = 0; i < 7; i++) {
+ smk->rates[i] = avio_rl24(pb);
+ smk->aflags[i] = avio_r8(pb);
+ }
smk->pad = avio_rl32(pb);
/* setup data */
if(smk->frames > 0xFFFFFF) {
@@ -151,7 +154,7 @@ static int smacker_read_header(AVFormatContext *s, AVFormatParameters *ap)
}
/* init video codec */
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return -1;
smk->videoindex = st->index;
@@ -173,23 +176,23 @@ static int smacker_read_header(AVFormatContext *s, AVFormatParameters *ap)
/* handle possible audio streams */
for(i = 0; i < 7; i++) {
smk->indexes[i] = -1;
- if(smk->rates[i] & 0xFFFFFF){
- ast[i] = av_new_stream(s, 0);
+ if (smk->rates[i]) {
+ ast[i] = avformat_new_stream(s, NULL);
smk->indexes[i] = ast[i]->index;
ast[i]->codec->codec_type = AVMEDIA_TYPE_AUDIO;
- if (smk->rates[i] & SMK_AUD_BINKAUD) {
+ if (smk->aflags[i] & SMK_AUD_BINKAUD) {
ast[i]->codec->codec_id = CODEC_ID_BINKAUDIO_RDFT;
- } else if (smk->rates[i] & SMK_AUD_USEDCT) {
+ } else if (smk->aflags[i] & SMK_AUD_USEDCT) {
ast[i]->codec->codec_id = CODEC_ID_BINKAUDIO_DCT;
- } else if (smk->rates[i] & SMK_AUD_PACKED){
+ } else if (smk->aflags[i] & SMK_AUD_PACKED){
ast[i]->codec->codec_id = CODEC_ID_SMACKAUDIO;
ast[i]->codec->codec_tag = MKTAG('S', 'M', 'K', 'A');
} else {
ast[i]->codec->codec_id = CODEC_ID_PCM_U8;
}
- ast[i]->codec->channels = (smk->rates[i] & SMK_AUD_STEREO) ? 2 : 1;
- ast[i]->codec->sample_rate = smk->rates[i] & 0xFFFFFF;
- ast[i]->codec->bits_per_coded_sample = (smk->rates[i] & SMK_AUD_16BITS) ? 16 : 8;
+ ast[i]->codec->channels = (smk->aflags[i] & SMK_AUD_STEREO) ? 2 : 1;
+ ast[i]->codec->sample_rate = smk->rates[i];
+ ast[i]->codec->bits_per_coded_sample = (smk->aflags[i] & SMK_AUD_16BITS) ? 16 : 8;
if(ast[i]->codec->bits_per_coded_sample == 16 && ast[i]->codec->codec_id == CODEC_ID_PCM_U8)
ast[i]->codec->codec_id = CODEC_ID_PCM_S16LE;
av_set_pts_info(ast[i], 64, 1, ast[i]->codec->sample_rate
@@ -234,7 +237,7 @@ static int smacker_read_packet(AVFormatContext *s, AVPacket *pkt)
int frame_size = 0;
int palchange = 0;
- if (s->pb->eof_reached || smk->cur_frame >= smk->frames)
+ if (url_feof(s->pb) || smk->cur_frame >= smk->frames)
return AVERROR_EOF;
/* if we demuxed all streams, pass another frame */
@@ -286,11 +289,16 @@ static int smacker_read_packet(AVFormatContext *s, AVPacket *pkt)
for(i = 0; i < 7; i++) {
if(flags & 1) {
int size;
+ uint8_t *tmpbuf;
+
size = avio_rl32(s->pb) - 4;
frame_size -= size;
frame_size -= 4;
smk->curstream++;
- smk->bufs[smk->curstream] = av_realloc(smk->bufs[smk->curstream], size);
+ tmpbuf = av_realloc(smk->bufs[smk->curstream], size);
+ if (!tmpbuf)
+ return AVERROR(ENOMEM);
+ smk->bufs[smk->curstream] = tmpbuf;
smk->buf_sizes[smk->curstream] = size;
ret = avio_read(s->pb, smk->bufs[smk->curstream], size);
if(ret != size)
@@ -299,7 +307,9 @@ static int smacker_read_packet(AVFormatContext *s, AVPacket *pkt)
}
flags >>= 1;
}
- if (av_new_packet(pkt, frame_size + 768))
+ if (frame_size < 0)
+ return AVERROR_INVALIDDATA;
+ if (av_new_packet(pkt, frame_size + 769))
return AVERROR(ENOMEM);
if(smk->frm_size[smk->cur_frame] & 1)
palchange |= 2;
@@ -340,11 +350,11 @@ static int smacker_read_close(AVFormatContext *s)
}
AVInputFormat ff_smacker_demuxer = {
- "smk",
- NULL_IF_CONFIG_SMALL("Smacker video"),
- sizeof(SmackerContext),
- smacker_probe,
- smacker_read_header,
- smacker_read_packet,
- smacker_read_close,
+ .name = "smk",
+ .long_name = NULL_IF_CONFIG_SMALL("Smacker video"),
+ .priv_data_size = sizeof(SmackerContext),
+ .read_probe = smacker_probe,
+ .read_header = smacker_read_header,
+ .read_packet = smacker_read_packet,
+ .read_close = smacker_read_close,
};
diff --git a/libavformat/sol.c b/libavformat/sol.c
index 1ebb4d2e30..cd5b2d75a4 100644
--- a/libavformat/sol.c
+++ b/libavformat/sol.c
@@ -2,20 +2,20 @@
* Sierra SOL demuxer
* Copyright Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -110,7 +110,7 @@ static int sol_read_header(AVFormatContext *s,
else id = 0;
/* now we are ready: build format streams */
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return -1;
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
@@ -129,9 +129,11 @@ static int sol_read_packet(AVFormatContext *s,
{
int ret;
- if (s->pb->eof_reached)
+ if (url_feof(s->pb))
return AVERROR(EIO);
ret= av_get_packet(s->pb, pkt, MAX_SIZE);
+ if (ret < 0)
+ return ret;
pkt->stream_index = 0;
/* note: we need to modify the packet size here to handle the last
@@ -141,12 +143,10 @@ static int sol_read_packet(AVFormatContext *s,
}
AVInputFormat ff_sol_demuxer = {
- "sol",
- NULL_IF_CONFIG_SMALL("Sierra SOL format"),
- 0,
- sol_probe,
- sol_read_header,
- sol_read_packet,
- NULL,
- pcm_read_seek,
+ .name = "sol",
+ .long_name = NULL_IF_CONFIG_SMALL("Sierra SOL format"),
+ .read_probe = sol_probe,
+ .read_header = sol_read_header,
+ .read_packet = sol_read_packet,
+ .read_seek = pcm_read_seek,
};
diff --git a/libavformat/sox.h b/libavformat/sox.h
index e59531bea3..f4a12e93ff 100644
--- a/libavformat/sox.h
+++ b/libavformat/sox.h
@@ -2,20 +2,20 @@
* SoX native format common data
* Copyright (c) 2009 Daniel Verkamp <daniel@drv.nu>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/soxdec.c b/libavformat/soxdec.c
index b3b35b12fd..dac4bedfb3 100644
--- a/libavformat/soxdec.c
+++ b/libavformat/soxdec.c
@@ -5,28 +5,28 @@
* Based on libSoX sox-fmt.c
* Copyright (c) 2008 robs@users.sourceforge.net
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
- * SoX native format demuxer
* @file
+ * SoX native format demuxer
* @author Daniel Verkamp
- * @sa http://wiki.multimedia.cx/index.php?title=SoX_native_intermediate_format
+ * @see http://wiki.multimedia.cx/index.php?title=SoX_native_intermediate_format
*/
#include "libavutil/intreadwrite.h"
@@ -51,7 +51,7 @@ static int sox_read_header(AVFormatContext *s,
double sample_rate, sample_rate_frac;
AVStream *st;
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
@@ -129,7 +129,7 @@ static int sox_read_packet(AVFormatContext *s,
{
int ret, size;
- if (s->pb->eof_reached)
+ if (url_feof(s->pb))
return AVERROR_EOF;
size = SOX_SAMPLES*s->streams[0]->codec->block_align;
@@ -143,12 +143,10 @@ static int sox_read_packet(AVFormatContext *s,
}
AVInputFormat ff_sox_demuxer = {
- "sox",
- NULL_IF_CONFIG_SMALL("SoX native format"),
- 0,
- sox_probe,
- sox_read_header,
- sox_read_packet,
- NULL,
- pcm_read_seek,
+ .name = "sox",
+ .long_name = NULL_IF_CONFIG_SMALL("SoX native format"),
+ .read_probe = sox_probe,
+ .read_header = sox_read_header,
+ .read_packet = sox_read_packet,
+ .read_seek = pcm_read_seek,
};
diff --git a/libavformat/soxenc.c b/libavformat/soxenc.c
index a0faa466df..a8549b0ffa 100644
--- a/libavformat/soxenc.c
+++ b/libavformat/soxenc.c
@@ -5,28 +5,28 @@
* Based on libSoX sox-fmt.c
* Copyright (c) 2008 robs@users.sourceforge.net
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
- * SoX native format muxer
* @file
+ * SoX native format muxer
* @author Daniel Verkamp
- * @sa http://wiki.multimedia.cx/index.php?title=SoX_native_intermediate_format
+ * @see http://wiki.multimedia.cx/index.php?title=SoX_native_intermediate_format
*/
#include "libavutil/intreadwrite.h"
@@ -116,14 +116,13 @@ static int sox_write_trailer(AVFormatContext *s)
}
AVOutputFormat ff_sox_muxer = {
- "sox",
- NULL_IF_CONFIG_SMALL("SoX native format"),
- NULL,
- "sox",
- sizeof(SoXContext),
- CODEC_ID_PCM_S32LE,
- CODEC_ID_NONE,
- sox_write_header,
- sox_write_packet,
- sox_write_trailer,
+ .name = "sox",
+ .long_name = NULL_IF_CONFIG_SMALL("SoX native format"),
+ .extensions = "sox",
+ .priv_data_size = sizeof(SoXContext),
+ .audio_codec = CODEC_ID_PCM_S32LE,
+ .video_codec = CODEC_ID_NONE,
+ .write_header = sox_write_header,
+ .write_packet = sox_write_packet,
+ .write_trailer = sox_write_trailer,
};
diff --git a/libavformat/spdif.c b/libavformat/spdif.c
index 777ac47ba5..604141a261 100644
--- a/libavformat/spdif.c
+++ b/libavformat/spdif.c
@@ -2,20 +2,20 @@
* IEC 61937 common code
* Copyright (c) 2009 Bartlomiej Wolowiec
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/spdif.h b/libavformat/spdif.h
index b2a6b63be4..4b11de20d1 100644
--- a/libavformat/spdif.h
+++ b/libavformat/spdif.h
@@ -2,20 +2,20 @@
* IEC 61937 common header
* Copyright (c) 2009 Bartlomiej Wolowiec
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/spdifdec.c b/libavformat/spdifdec.c
index 1c0902548c..b0e9afb7b3 100644
--- a/libavformat/spdifdec.c
+++ b/libavformat/spdifdec.c
@@ -2,20 +2,20 @@
* IEC 61937 demuxer
* Copyright (c) 2010 Anssi Hannula <anssi.hannula at iki.fi>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -57,7 +57,7 @@ static int spdif_get_offset_and_codec(AVFormatContext *s,
break;
case IEC61937_MPEG2_AAC:
init_get_bits(&gbc, buf, AAC_ADTS_HEADER_SIZE * 8);
- if (ff_aac_parse_header(&gbc, &aac_hdr)) {
+ if (avpriv_aac_parse_header(&gbc, &aac_hdr)) {
if (s) /* be silent during a probe */
av_log(s, AV_LOG_ERROR, "Invalid AAC packet in IEC 61937\n");
return AVERROR_INVALIDDATA;
@@ -171,7 +171,7 @@ static int spdif_read_packet(AVFormatContext *s, AVPacket *pkt)
while (state != (AV_BSWAP16C(SYNCWORD1) << 16 | AV_BSWAP16C(SYNCWORD2))) {
state = (state << 8) | avio_r8(pb);
- if (pb->eof_reached)
+ if (url_feof(pb))
return AVERROR_EOF;
}
@@ -205,7 +205,7 @@ static int spdif_read_packet(AVFormatContext *s, AVPacket *pkt)
if (!s->nb_streams) {
/* first packet, create a stream */
- AVStream *st = av_new_stream(s, 0);
+ AVStream *st = avformat_new_stream(s, NULL);
if (!st) {
av_free_packet(pkt);
return AVERROR(ENOMEM);
@@ -226,11 +226,10 @@ static int spdif_read_packet(AVFormatContext *s, AVPacket *pkt)
}
AVInputFormat ff_spdif_demuxer = {
- "spdif",
- NULL_IF_CONFIG_SMALL("IEC 61937 (compressed data in S/PDIF)"),
- 0,
- spdif_probe,
- spdif_read_header,
- spdif_read_packet,
+ .name = "spdif",
+ .long_name = NULL_IF_CONFIG_SMALL("IEC 61937 (compressed data in S/PDIF)"),
+ .read_probe = spdif_probe,
+ .read_header = spdif_read_header,
+ .read_packet = spdif_read_packet,
.flags = AVFMT_GENERIC_INDEX,
};
diff --git a/libavformat/spdifenc.c b/libavformat/spdifenc.c
index 735546096f..53aa27c446 100644
--- a/libavformat/spdifenc.c
+++ b/libavformat/spdifenc.c
@@ -4,20 +4,20 @@
* Copyright (c) 2010 Anssi Hannula
* Copyright (c) 2010 Carl Eugen Hoyos
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -86,10 +86,10 @@ typedef struct IEC61937Context {
} IEC61937Context;
static const AVOption options[] = {
-{ "spdif_flags", "IEC 61937 encapsulation flags", offsetof(IEC61937Context, spdif_flags), FF_OPT_TYPE_FLAGS, {.dbl = 0}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "spdif_flags" },
-{ "be", "output in big-endian format (for use as s16be)", 0, FF_OPT_TYPE_CONST, {.dbl = SPDIF_FLAG_BIGENDIAN}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "spdif_flags" },
-{ "dtshd_rate", "mux complete DTS frames in HD mode at the specified IEC958 rate (in Hz, default 0=disabled)", offsetof(IEC61937Context, dtshd_rate), FF_OPT_TYPE_INT, {.dbl = 0}, 0, 768000, AV_OPT_FLAG_ENCODING_PARAM },
-{ "dtshd_fallback_time", "min secs to strip HD for after an overflow (-1: till the end, default 60)", offsetof(IEC61937Context, dtshd_fallback), FF_OPT_TYPE_INT, {.dbl = 60}, -1, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM },
+{ "spdif_flags", "IEC 61937 encapsulation flags", offsetof(IEC61937Context, spdif_flags), AV_OPT_TYPE_FLAGS, {.dbl = 0}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "spdif_flags" },
+{ "be", "output in big-endian format (for use as s16be)", 0, AV_OPT_TYPE_CONST, {.dbl = SPDIF_FLAG_BIGENDIAN}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "spdif_flags" },
+{ "dtshd_rate", "mux complete DTS frames in HD mode at the specified IEC958 rate (in Hz, default 0=disabled)", offsetof(IEC61937Context, dtshd_rate), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 768000, AV_OPT_FLAG_ENCODING_PARAM },
+{ "dtshd_fallback_time", "min secs to strip HD for after an overflow (-1: till the end, default 60)", offsetof(IEC61937Context, dtshd_fallback), AV_OPT_TYPE_INT, {.dbl = 60}, -1, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM },
{ NULL },
};
@@ -349,7 +349,7 @@ static int spdif_header_aac(AVFormatContext *s, AVPacket *pkt)
int ret;
init_get_bits(&gbc, pkt->data, AAC_ADTS_HEADER_SIZE * 8);
- ret = ff_aac_parse_header(&gbc, &hdr);
+ ret = avpriv_aac_parse_header(&gbc, &hdr);
if (ret < 0) {
av_log(s, AV_LOG_ERROR, "Wrong AAC file format\n");
return AVERROR_INVALIDDATA;
@@ -518,13 +518,13 @@ static int spdif_write_packet(struct AVFormatContext *s, AVPacket *pkt)
}
if (ctx->extra_bswap ^ (ctx->spdif_flags & SPDIF_FLAG_BIGENDIAN)) {
- avio_write(s->pb, ctx->out_buf, ctx->out_bytes & ~1);
+ avio_write(s->pb, ctx->out_buf, ctx->out_bytes & ~1);
} else {
- av_fast_malloc(&ctx->buffer, &ctx->buffer_size, ctx->out_bytes + FF_INPUT_BUFFER_PADDING_SIZE);
- if (!ctx->buffer)
- return AVERROR(ENOMEM);
- ff_spdif_bswap_buf16((uint16_t *)ctx->buffer, (uint16_t *)ctx->out_buf, ctx->out_bytes >> 1);
- avio_write(s->pb, ctx->buffer, ctx->out_bytes & ~1);
+ av_fast_malloc(&ctx->buffer, &ctx->buffer_size, ctx->out_bytes + FF_INPUT_BUFFER_PADDING_SIZE);
+ if (!ctx->buffer)
+ return AVERROR(ENOMEM);
+ ff_spdif_bswap_buf16((uint16_t *)ctx->buffer, (uint16_t *)ctx->out_buf, ctx->out_bytes >> 1);
+ avio_write(s->pb, ctx->buffer, ctx->out_bytes & ~1);
}
/* a final lone byte has to be MSB aligned */
@@ -541,16 +541,15 @@ static int spdif_write_packet(struct AVFormatContext *s, AVPacket *pkt)
}
AVOutputFormat ff_spdif_muxer = {
- "spdif",
- NULL_IF_CONFIG_SMALL("IEC 61937 (used on S/PDIF - IEC958)"),
- NULL,
- "spdif",
- sizeof(IEC61937Context),
- CODEC_ID_AC3,
- CODEC_ID_NONE,
- spdif_write_header,
- spdif_write_packet,
- spdif_write_trailer,
+ .name = "spdif",
+ .long_name = NULL_IF_CONFIG_SMALL("IEC 61937 (used on S/PDIF - IEC958)"),
+ .extensions = "spdif",
+ .priv_data_size = sizeof(IEC61937Context),
+ .audio_codec = CODEC_ID_AC3,
+ .video_codec = CODEC_ID_NONE,
+ .write_header = spdif_write_header,
+ .write_packet = spdif_write_packet,
+ .write_trailer = spdif_write_trailer,
.flags = AVFMT_NOTIMESTAMPS,
.priv_class = &class,
};
diff --git a/libavformat/srtdec.c b/libavformat/srtdec.c
index 72c5c80f6b..2828cc7af3 100644
--- a/libavformat/srtdec.c
+++ b/libavformat/srtdec.c
@@ -2,20 +2,20 @@
* SubRip subtitle demuxer
* Copyright (c) 2010 Aurelien Jacobs <aurel@gnuage.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -42,7 +42,7 @@ static int srt_probe(AVProbeData *p)
static int srt_read_header(AVFormatContext *s, AVFormatParameters *ap)
{
- AVStream *st = av_new_stream(s, 0);
+ AVStream *st = avformat_new_stream(s, NULL);
if (!st)
return -1;
av_set_pts_info(st, 64, 1, 1000);
@@ -81,7 +81,7 @@ static int srt_read_packet(AVFormatContext *s, AVPacket *pkt)
do {
ptr2 = ptr;
ptr += ff_get_line(s->pb, ptr, sizeof(buffer)+buffer-ptr);
- } while (!is_eol(*ptr2) && !s->pb->eof_reached && ptr-buffer<sizeof(buffer)-1);
+ } while (!is_eol(*ptr2) && !url_feof(s->pb) && ptr-buffer<sizeof(buffer)-1);
if (buffer[0] && !(res = av_new_packet(pkt, ptr-buffer))) {
memcpy(pkt->data, buffer, pkt->size);
diff --git a/libavformat/swf.h b/libavformat/swf.h
index 2be6cd5795..affebe9c73 100644
--- a/libavformat/swf.h
+++ b/libavformat/swf.h
@@ -3,20 +3,20 @@
* Copyright (c) 2000 Fabrice Bellard
* Copyright (c) 2003 Tinic Uro
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/swfdec.c b/libavformat/swfdec.c
index c838fa8e61..175e40ee19 100644
--- a/libavformat/swfdec.c
+++ b/libavformat/swfdec.c
@@ -3,20 +3,20 @@
* Copyright (c) 2000 Fabrice Bellard
* Copyright (c) 2003 Tinic Uro
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -27,8 +27,8 @@ static int get_swf_tag(AVIOContext *pb, int *len_ptr)
{
int tag, len;
- if (pb->eof_reached)
- return -1;
+ if (url_feof(pb))
+ return AVERROR_EOF;
tag = avio_rl16(pb);
len = tag & 0x3f;
@@ -90,7 +90,7 @@ static int swf_read_packet(AVFormatContext *s, AVPacket *pkt)
uint64_t pos = avio_tell(pb);
tag = get_swf_tag(pb, &len);
if (tag < 0)
- return AVERROR(EIO);
+ return tag;
if (tag == TAG_VIDEOSTREAM) {
int ch_id = avio_rl16(pb);
len -= 2;
@@ -106,9 +106,10 @@ static int swf_read_packet(AVFormatContext *s, AVPacket *pkt)
avio_rl16(pb);
avio_r8(pb);
/* Check for FLV1 */
- vst = av_new_stream(s, ch_id);
+ vst = avformat_new_stream(s, NULL);
if (!vst)
return -1;
+ vst->id = ch_id;
vst->codec->codec_type = AVMEDIA_TYPE_VIDEO;
vst->codec->codec_id = ff_codec_get_id(swf_codec_tags, avio_r8(pb));
av_set_pts_info(vst, 16, 256, swf->frame_rate);
@@ -127,17 +128,19 @@ static int swf_read_packet(AVFormatContext *s, AVPacket *pkt)
avio_r8(pb);
v = avio_r8(pb);
swf->samples_per_frame = avio_rl16(pb);
- ast = av_new_stream(s, -1); /* -1 to avoid clash with video stream ch_id */
+ ast = avformat_new_stream(s, NULL);
if (!ast)
return -1;
+ ast->id = -1; /* -1 to avoid clash with video stream ch_id */
ast->codec->channels = 1 + (v&1);
ast->codec->codec_type = AVMEDIA_TYPE_AUDIO;
ast->codec->codec_id = ff_codec_get_id(swf_audio_codec_tags, (v>>4) & 15);
ast->need_parsing = AVSTREAM_PARSE_FULL;
sample_rate_code= (v>>2) & 3;
if (!sample_rate_code)
- return AVERROR(EIO);
- ast->codec->sample_rate = 11025 << (sample_rate_code-1);
+ ast->codec->sample_rate = 5512;
+ else
+ ast->codec->sample_rate = 11025 << (sample_rate_code-1);
av_set_pts_info(ast, 64, 1, ast->codec->sample_rate);
len -= 4;
} else if (tag == TAG_VIDEOFRAME) {
@@ -176,9 +179,10 @@ static int swf_read_packet(AVFormatContext *s, AVPacket *pkt)
break;
}
if (i == s->nb_streams) {
- vst = av_new_stream(s, -2); /* -2 to avoid clash with video stream and audio stream */
+ vst = avformat_new_stream(s, NULL);
if (!vst)
return -1;
+ vst->id = -2; /* -2 to avoid clash with video stream and audio stream */
vst->codec->codec_type = AVMEDIA_TYPE_VIDEO;
vst->codec->codec_id = CODEC_ID_MJPEG;
av_set_pts_info(vst, 64, 256, swf->frame_rate);
@@ -207,10 +211,10 @@ static int swf_read_packet(AVFormatContext *s, AVPacket *pkt)
}
AVInputFormat ff_swf_demuxer = {
- "swf",
- NULL_IF_CONFIG_SMALL("Flash format"),
- sizeof(SWFContext),
- swf_probe,
- swf_read_header,
- swf_read_packet,
+ .name = "swf",
+ .long_name = NULL_IF_CONFIG_SMALL("Flash format"),
+ .priv_data_size = sizeof(SWFContext),
+ .read_probe = swf_probe,
+ .read_header = swf_read_header,
+ .read_packet = swf_read_packet,
};
diff --git a/libavformat/swfenc.c b/libavformat/swfenc.c
index 4c5c3155ab..af812d09eb 100644
--- a/libavformat/swfenc.c
+++ b/libavformat/swfenc.c
@@ -3,20 +3,20 @@
* Copyright (c) 2000 Fabrice Bellard
* Copyright (c) 2003 Tinic Uro
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -421,7 +421,7 @@ static int swf_write_video(AVFormatContext *s,
put_swf_tag(s, TAG_STREAMBLOCK | TAG_LONG);
avio_wl16(pb, swf->sound_samples);
avio_wl16(pb, 0); // seek samples
- av_fifo_generic_read(swf->audio_fifo, pb, frame_size, &avio_write);
+ av_fifo_generic_read(swf->audio_fifo, pb, frame_size, (void*)avio_write);
put_swf_end_tag(s);
/* update FIFO */
@@ -507,29 +507,28 @@ static int swf_write_trailer(AVFormatContext *s)
#if CONFIG_SWF_MUXER
AVOutputFormat ff_swf_muxer = {
- "swf",
- NULL_IF_CONFIG_SMALL("Flash format"),
- "application/x-shockwave-flash",
- "swf",
- sizeof(SWFContext),
- CODEC_ID_MP3,
- CODEC_ID_FLV1,
- swf_write_header,
- swf_write_packet,
- swf_write_trailer,
+ .name = "swf",
+ .long_name = NULL_IF_CONFIG_SMALL("Flash format"),
+ .mime_type = "application/x-shockwave-flash",
+ .extensions = "swf",
+ .priv_data_size = sizeof(SWFContext),
+ .audio_codec = CODEC_ID_MP3,
+ .video_codec = CODEC_ID_FLV1,
+ .write_header = swf_write_header,
+ .write_packet = swf_write_packet,
+ .write_trailer = swf_write_trailer,
};
#endif
#if CONFIG_AVM2_MUXER
AVOutputFormat ff_avm2_muxer = {
- "avm2",
- NULL_IF_CONFIG_SMALL("Flash 9 (AVM2) format"),
- "application/x-shockwave-flash",
- NULL,
- sizeof(SWFContext),
- CODEC_ID_MP3,
- CODEC_ID_FLV1,
- swf_write_header,
- swf_write_packet,
- swf_write_trailer,
+ .name = "avm2",
+ .long_name = NULL_IF_CONFIG_SMALL("Flash 9 (AVM2) format"),
+ .mime_type = "application/x-shockwave-flash",
+ .priv_data_size = sizeof(SWFContext),
+ .audio_codec = CODEC_ID_MP3,
+ .video_codec = CODEC_ID_FLV1,
+ .write_header = swf_write_header,
+ .write_packet = swf_write_packet,
+ .write_trailer = swf_write_trailer,
};
#endif
diff --git a/libavformat/tcp.c b/libavformat/tcp.c
index e602a556d2..eb982d5675 100644
--- a/libavformat/tcp.c
+++ b/libavformat/tcp.c
@@ -2,20 +2,20 @@
* TCP protocol
* Copyright (c) 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avformat.h"
@@ -45,7 +45,7 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
char buf[256];
int ret;
socklen_t optlen;
- int timeout = 100;
+ int timeout = 50;
char hostname[1024],proto[1024],path[1024];
char portstr[10];
diff --git a/libavformat/thp.c b/libavformat/thp.c
index 51dbd810cd..e2aba3bc32 100644
--- a/libavformat/thp.c
+++ b/libavformat/thp.c
@@ -2,20 +2,20 @@
* THP Demuxer
* Copyright (c) 2007 Marco Gerards
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -94,7 +94,7 @@ static int thp_read_header(AVFormatContext *s,
break;
/* Video component. */
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
@@ -117,7 +117,7 @@ static int thp_read_header(AVFormatContext *s,
break;
/* Audio component. */
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
@@ -189,10 +189,10 @@ static int thp_read_packet(AVFormatContext *s,
}
AVInputFormat ff_thp_demuxer = {
- "thp",
- NULL_IF_CONFIG_SMALL("THP"),
- sizeof(ThpDemuxContext),
- thp_probe,
- thp_read_header,
- thp_read_packet
+ .name = "thp",
+ .long_name = NULL_IF_CONFIG_SMALL("THP"),
+ .priv_data_size = sizeof(ThpDemuxContext),
+ .read_probe = thp_probe,
+ .read_header = thp_read_header,
+ .read_packet = thp_read_packet
};
diff --git a/libavformat/tiertexseq.c b/libavformat/tiertexseq.c
index 7ca0464550..dfed70ceae 100644
--- a/libavformat/tiertexseq.c
+++ b/libavformat/tiertexseq.c
@@ -2,20 +2,20 @@
* Tiertex Limited SEQ File Demuxer
* Copyright (c) 2006 Gregory Montoir (cyx@users.sourceforge.net)
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -206,7 +206,7 @@ static int seq_read_header(AVFormatContext *s, AVFormatParameters *ap)
seq->audio_buffer_full = 0;
/* initialize the video decoder stream */
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
@@ -219,7 +219,7 @@ static int seq_read_header(AVFormatContext *s, AVFormatParameters *ap)
st->codec->height = SEQ_FRAME_H;
/* initialize the audio decoder stream */
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
@@ -303,11 +303,11 @@ static int seq_read_close(AVFormatContext *s)
}
AVInputFormat ff_tiertexseq_demuxer = {
- "tiertexseq",
- NULL_IF_CONFIG_SMALL("Tiertex Limited SEQ format"),
- sizeof(SeqDemuxContext),
- seq_probe,
- seq_read_header,
- seq_read_packet,
- seq_read_close,
+ .name = "tiertexseq",
+ .long_name = NULL_IF_CONFIG_SMALL("Tiertex Limited SEQ format"),
+ .priv_data_size = sizeof(SeqDemuxContext),
+ .read_probe = seq_probe,
+ .read_header = seq_read_header,
+ .read_packet = seq_read_packet,
+ .read_close = seq_read_close,
};
diff --git a/libavformat/tmv.c b/libavformat/tmv.c
index f894eab46a..03d6e08f0e 100644
--- a/libavformat/tmv.c
+++ b/libavformat/tmv.c
@@ -2,28 +2,28 @@
* 8088flex TMV file demuxer
* Copyright (c) 2009 Daniel Verkamp <daniel at drv.nu>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
- * 8088flex TMV file demuxer
* @file
+ * 8088flex TMV file demuxer
* @author Daniel Verkamp
- * @sa http://www.oldskool.org/pc/8088_Corruption
+ * @see http://www.oldskool.org/pc/8088_Corruption
*/
#include "libavutil/intreadwrite.h"
@@ -73,10 +73,10 @@ static int tmv_read_header(AVFormatContext *s, AVFormatParameters *ap)
if (avio_rl32(pb) != TMV_TAG)
return -1;
- if (!(vst = av_new_stream(s, 0)))
+ if (!(vst = avformat_new_stream(s, NULL)))
return AVERROR(ENOMEM);
- if (!(ast = av_new_stream(s, 0)))
+ if (!(ast = avformat_new_stream(s, NULL)))
return AVERROR(ENOMEM);
ast->codec->sample_rate = avio_rl16(pb);
@@ -146,7 +146,7 @@ static int tmv_read_packet(AVFormatContext *s, AVPacket *pkt)
int ret, pkt_size = tmv->stream_index ?
tmv->audio_chunk_size : tmv->video_chunk_size;
- if (pb->eof_reached)
+ if (url_feof(pb))
return AVERROR_EOF;
ret = av_get_packet(pb, pkt, pkt_size);
@@ -173,19 +173,19 @@ static int tmv_read_seek(AVFormatContext *s, int stream_index,
pos = timestamp *
(tmv->audio_chunk_size + tmv->video_chunk_size + tmv->padding);
- avio_seek(s->pb, pos + TMV_HEADER_SIZE, SEEK_SET);
+ if (avio_seek(s->pb, pos + TMV_HEADER_SIZE, SEEK_SET) < 0)
+ return -1;
tmv->stream_index = 0;
return 0;
}
AVInputFormat ff_tmv_demuxer = {
- "tmv",
- NULL_IF_CONFIG_SMALL("8088flex TMV"),
- sizeof(TMVContext),
- tmv_probe,
- tmv_read_header,
- tmv_read_packet,
- NULL,
- tmv_read_seek,
+ .name = "tmv",
+ .long_name = NULL_IF_CONFIG_SMALL("8088flex TMV"),
+ .priv_data_size = sizeof(TMVContext),
+ .read_probe = tmv_probe,
+ .read_header = tmv_read_header,
+ .read_packet = tmv_read_packet,
+ .read_seek = tmv_read_seek,
.flags = AVFMT_GENERIC_INDEX,
};
diff --git a/libavformat/tta.c b/libavformat/tta.c
index 49234a81e4..ca2d36b44f 100644
--- a/libavformat/tta.c
+++ b/libavformat/tta.c
@@ -2,20 +2,20 @@
* TTA demuxer
* Copyright (c) 2006 Alex Beregszaszi
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -77,7 +77,7 @@ static int tta_read_header(AVFormatContext *s, AVFormatParameters *ap)
return -1;
}
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
@@ -137,21 +137,21 @@ static int tta_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp
int index = av_index_search_timestamp(st, timestamp, flags);
if (index < 0)
return -1;
+ if (avio_seek(s->pb, st->index_entries[index].pos, SEEK_SET) < 0)
+ return -1;
c->currentframe = index;
- avio_seek(s->pb, st->index_entries[index].pos, SEEK_SET);
return 0;
}
AVInputFormat ff_tta_demuxer = {
- "tta",
- NULL_IF_CONFIG_SMALL("True Audio"),
- sizeof(TTAContext),
- tta_probe,
- tta_read_header,
- tta_read_packet,
- NULL,
- tta_read_seek,
+ .name = "tta",
+ .long_name = NULL_IF_CONFIG_SMALL("True Audio"),
+ .priv_data_size = sizeof(TTAContext),
+ .read_probe = tta_probe,
+ .read_header = tta_read_header,
+ .read_packet = tta_read_packet,
+ .read_seek = tta_read_seek,
.extensions = "tta",
};
diff --git a/libavformat/tty.c b/libavformat/tty.c
index ee6b2f1334..5c9fee7908 100644
--- a/libavformat/tty.c
+++ b/libavformat/tty.c
@@ -2,20 +2,20 @@
* Tele-typewriter demuxer
* Copyright (c) 2010 Peter Ross <pross@xvid.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -76,7 +76,7 @@ static int read_header(AVFormatContext *avctx,
{
TtyDemuxContext *s = avctx->priv_data;
int width = 0, height = 0, ret = 0;
- AVStream *st = av_new_stream(avctx, 0);
+ AVStream *st = avformat_new_stream(avctx, NULL);
AVRational framerate;
if (!st) {
@@ -95,23 +95,11 @@ static int read_header(AVFormatContext *avctx,
av_log(avctx, AV_LOG_ERROR, "Could not parse framerate: %s.\n", s->framerate);
goto fail;
}
-#if FF_API_FORMAT_PARAMETERS
- if (ap->width > 0)
- width = ap->width;
- if (ap->height > 0)
- height = ap->height;
- if (ap->time_base.num)
- framerate = (AVRational){ap->time_base.den, ap->time_base.num};
-#endif
st->codec->width = width;
st->codec->height = height;
av_set_pts_info(st, 60, framerate.den, framerate.num);
/* simulate tty display speed */
-#if FF_API_FORMAT_PARAMETERS
- if (ap->sample_rate)
- s->chars_per_frame = ap->sample_rate;
-#endif
s->chars_per_frame = FFMAX(av_q2d(st->time_base)*s->chars_per_frame, 1);
if (avctx->pb->seekable) {
@@ -133,7 +121,7 @@ static int read_packet(AVFormatContext *avctx, AVPacket *pkt)
TtyDemuxContext *s = avctx->priv_data;
int n;
- if (avctx->pb->eof_reached)
+ if (url_feof(avctx->pb))
return AVERROR_EOF;
n = s->chars_per_frame;
@@ -154,9 +142,9 @@ static int read_packet(AVFormatContext *avctx, AVPacket *pkt)
#define OFFSET(x) offsetof(TtyDemuxContext, x)
#define DEC AV_OPT_FLAG_DECODING_PARAM
static const AVOption options[] = {
- { "chars_per_frame", "", offsetof(TtyDemuxContext, chars_per_frame), FF_OPT_TYPE_INT, {.dbl = 6000}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM},
- { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), FF_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
- { "framerate", "", OFFSET(framerate), FF_OPT_TYPE_STRING, {.str = "25"}, 0, 0, DEC },
+ { "chars_per_frame", "", offsetof(TtyDemuxContext, chars_per_frame), AV_OPT_TYPE_INT, {.dbl = 6000}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM},
+ { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
+ { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0, DEC },
{ NULL },
};
diff --git a/libavformat/txd.c b/libavformat/txd.c
index 0a93b7c760..5d9f969270 100644
--- a/libavformat/txd.c
+++ b/libavformat/txd.c
@@ -2,20 +2,20 @@
* Renderware TeXture Dictionary (.txd) demuxer
* Copyright (c) 2007 Ivo van Poorten
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -40,7 +40,7 @@ static int txd_probe(AVProbeData * pd) {
static int txd_read_header(AVFormatContext *s, AVFormatParameters *ap) {
AVStream *st;
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
@@ -61,7 +61,7 @@ next_chunk:
chunk_size = avio_rl32(pb);
marker = avio_rl32(pb);
- if (s->pb->eof_reached)
+ if (url_feof(s->pb))
return AVERROR_EOF;
if (marker != TXD_MARKER && marker != TXD_MARKER2) {
av_log(s, AV_LOG_ERROR, "marker does not match\n");
@@ -90,12 +90,10 @@ next_chunk:
return 0;
}
-AVInputFormat ff_txd_demuxer =
-{
- "txd",
- NULL_IF_CONFIG_SMALL("Renderware TeXture Dictionary"),
- 0,
- txd_probe,
- txd_read_header,
- txd_read_packet,
+AVInputFormat ff_txd_demuxer = {
+ .name = "txd",
+ .long_name = NULL_IF_CONFIG_SMALL("Renderware TeXture Dictionary"),
+ .read_probe = txd_probe,
+ .read_header = txd_read_header,
+ .read_packet = txd_read_packet,
};
diff --git a/libavformat/udp.c b/libavformat/udp.c
index bd95a811de..151e070d19 100644
--- a/libavformat/udp.c
+++ b/libavformat/udp.c
@@ -2,20 +2,20 @@
* UDP prototype streaming system
* Copyright (c) 2000, 2001, 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -29,11 +29,18 @@
#include "avformat.h"
#include "avio_internal.h"
#include "libavutil/parseutils.h"
+#include "libavutil/fifo.h"
+#include "libavutil/intreadwrite.h"
#include <unistd.h>
#include "internal.h"
#include "network.h"
#include "os_support.h"
#include "url.h"
+
+#if HAVE_PTHREADS
+#include <pthread.h>
+#endif
+
#include <sys/time.h>
#ifndef IPV6_ADD_MEMBERSHIP
@@ -41,6 +48,9 @@
#define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP
#endif
+#define UDP_TX_BUF_SIZE 32768
+#define UDP_MAX_PKT_SIZE 65536
+
typedef struct {
int udp_fd;
int ttl;
@@ -51,10 +61,17 @@ typedef struct {
struct sockaddr_storage dest_addr;
int dest_addr_len;
int is_connected;
-} UDPContext;
-#define UDP_TX_BUF_SIZE 32768
-#define UDP_MAX_PKT_SIZE 65536
+ /* Circular Buffer variables for use in UDP receive code */
+ int circular_buffer_size;
+ AVFifoBuffer *fifo;
+ int circular_buffer_error;
+#if HAVE_PTHREADS
+ pthread_t circular_buffer_thread;
+#endif
+ uint8_t tmp[UDP_MAX_PKT_SIZE+4];
+ int remaining_in_dg;
+} UDPContext;
static int udp_set_multicast_ttl(int sockfd, int mcastTTL,
struct sockaddr *addr)
@@ -298,6 +315,64 @@ static int udp_get_file_handle(URLContext *h)
return s->udp_fd;
}
+static void *circular_buffer_task( void *_URLContext)
+{
+ URLContext *h = _URLContext;
+ UDPContext *s = h->priv_data;
+ fd_set rfds;
+ struct timeval tv;
+
+ for(;;) {
+ int left;
+ int ret;
+ int len;
+
+ if (url_interrupt_cb()) {
+ s->circular_buffer_error = EINTR;
+ return NULL;
+ }
+
+ FD_ZERO(&rfds);
+ FD_SET(s->udp_fd, &rfds);
+ tv.tv_sec = 1;
+ tv.tv_usec = 0;
+ ret = select(s->udp_fd + 1, &rfds, NULL, NULL, &tv);
+ if (ret < 0) {
+ if (ff_neterrno() == AVERROR(EINTR))
+ continue;
+ s->circular_buffer_error = EIO;
+ return NULL;
+ }
+
+ if (!(ret > 0 && FD_ISSET(s->udp_fd, &rfds)))
+ continue;
+
+ /* How much do we have left to the end of the buffer */
+ /* Whats the minimum we can read so that we dont comletely fill the buffer */
+ left = av_fifo_space(s->fifo);
+
+ /* No Space left, error, what do we do now */
+ if(left < UDP_MAX_PKT_SIZE + 4) {
+ av_log(h, AV_LOG_ERROR, "circular_buffer: OVERRUN\n");
+ s->circular_buffer_error = EIO;
+ return NULL;
+ }
+ left = FFMIN(left, s->fifo->end - s->fifo->wptr);
+ len = recv(s->udp_fd, s->tmp+4, sizeof(s->tmp)-4, 0);
+ if (len < 0) {
+ if (ff_neterrno() != AVERROR(EAGAIN) && ff_neterrno() != AVERROR(EINTR)) {
+ s->circular_buffer_error = EIO;
+ return NULL;
+ }
+ continue;
+ }
+ AV_WL32(s->tmp, len);
+ av_fifo_generic_write(s->fifo, s->tmp, len+4, NULL);
+ }
+
+ return NULL;
+}
+
/* put it in UDP context */
/* return non zero if error */
static int udp_open(URLContext *h, const char *uri, int flags)
@@ -325,6 +400,8 @@ static int udp_open(URLContext *h, const char *uri, int flags)
s->ttl = 16;
s->buffer_size = is_output ? UDP_TX_BUF_SIZE : UDP_MAX_PKT_SIZE;
+ s->circular_buffer_size = 7*188*4096;
+
p = strchr(uri, '?');
if (p) {
if (av_find_info_tag(buf, sizeof(buf), "reuse", p)) {
@@ -350,6 +427,9 @@ static int udp_open(URLContext *h, const char *uri, int flags)
if (av_find_info_tag(buf, sizeof(buf), "connect", p)) {
s->is_connected = strtol(buf, NULL, 10);
}
+ if (av_find_info_tag(buf, sizeof(buf), "fifo_size", p)) {
+ s->circular_buffer_size = strtol(buf, NULL, 10)*188;
+ }
}
/* fill the dest addr */
@@ -431,10 +511,23 @@ static int udp_open(URLContext *h, const char *uri, int flags)
}
s->udp_fd = udp_fd;
+
+#if HAVE_PTHREADS
+ if (!is_output && s->circular_buffer_size) {
+ /* start the task going */
+ s->fifo = av_fifo_alloc(s->circular_buffer_size);
+ if (pthread_create(&s->circular_buffer_thread, NULL, circular_buffer_task, h)) {
+ av_log(h, AV_LOG_ERROR, "pthread_create failed\n");
+ goto fail;
+ }
+ }
+#endif
+
return 0;
fail:
if (udp_fd >= 0)
closesocket(udp_fd);
+ av_fifo_free(s->fifo);
av_free(s);
return AVERROR(EIO);
}
@@ -443,6 +536,38 @@ static int udp_read(URLContext *h, uint8_t *buf, int size)
{
UDPContext *s = h->priv_data;
int ret;
+ int avail;
+ fd_set rfds;
+ struct timeval tv;
+
+ if (s->fifo) {
+
+ do {
+ avail = av_fifo_size(s->fifo);
+ if (avail) { // >=size) {
+ uint8_t tmp[4];
+
+ av_fifo_generic_read(s->fifo, tmp, 4, NULL);
+ avail= AV_RL32(tmp);
+ if(avail > size){
+ av_log(h, AV_LOG_WARNING, "Part of datagram lost due to insufficient buffer size\n");
+ avail= size;
+ }
+
+ av_fifo_generic_read(s->fifo, buf, avail, NULL);
+ return avail;
+ }
+ else {
+ FD_ZERO(&rfds);
+ FD_SET(s->udp_fd, &rfds);
+ tv.tv_sec = 1;
+ tv.tv_usec = 0;
+ ret = select(s->udp_fd + 1, &rfds, NULL, NULL, &tv);
+ if (ret<0)
+ return ret;
+ }
+ } while( 1);
+ }
if (!(h->flags & AVIO_FLAG_NONBLOCK)) {
ret = ff_network_wait_fd(s->udp_fd, 0);
@@ -450,6 +575,7 @@ static int udp_read(URLContext *h, uint8_t *buf, int size)
return ret;
}
ret = recv(s->udp_fd, buf, size, 0);
+
return ret < 0 ? ff_neterrno() : ret;
}
@@ -481,6 +607,7 @@ static int udp_close(URLContext *h)
if (s->is_multicast && (h->flags & AVIO_FLAG_READ))
udp_leave_multicast_group(s->udp_fd, (struct sockaddr *)&s->dest_addr);
closesocket(s->udp_fd);
+ av_fifo_free(s->fifo);
av_free(s);
return 0;
}
diff --git a/libavformat/url.h b/libavformat/url.h
index caafe07cce..103f7b6c00 100644
--- a/libavformat/url.h
+++ b/libavformat/url.h
@@ -1,19 +1,19 @@
/*
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -74,12 +74,12 @@ typedef struct URLProtocol {
* @return 0 in case of success, a negative value corresponding to an
* AVERROR code in case of failure
*/
-int ffurl_alloc(URLContext **h, const char *url, int flags);
+int ffurl_alloc(URLContext **puc, const char *filename, int flags);
/**
* Connect an URLContext that has been allocated by ffurl_alloc
*/
-int ffurl_connect(URLContext *h);
+int ffurl_connect(URLContext *uc);
/**
* Create an URLContext for accessing to the resource indicated by
@@ -92,7 +92,7 @@ int ffurl_connect(URLContext *h);
* @return 0 in case of success, a negative value corresponding to an
* AVERROR code in case of failure
*/
-int ffurl_open(URLContext **h, const char *url, int flags);
+int ffurl_open(URLContext **puc, const char *filename, int flags);
/**
* Read up to size bytes from the resource accessed by h, and store
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 060e58e9b2..db27024904 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -1,21 +1,21 @@
/*
- * various utility functions for use within Libav
+ * various utility functions for use within FFmpeg
* Copyright (c) 2000, 2001, 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -25,6 +25,7 @@
#include "avio_internal.h"
#include "internal.h"
#include "libavcodec/internal.h"
+#include "libavcodec/raw.h"
#include "libavutil/opt.h"
#include "libavutil/dict.h"
#include "libavutil/pixdesc.h"
@@ -48,7 +49,7 @@
/**
* @file
- * various utility functions for use within Libav
+ * various utility functions for use within FFmpeg
*/
unsigned avformat_version(void)
@@ -58,13 +59,13 @@ unsigned avformat_version(void)
const char *avformat_configuration(void)
{
- return LIBAV_CONFIGURATION;
+ return FFMPEG_CONFIGURATION;
}
const char *avformat_license(void)
{
#define LICENSE_PREFIX "libavformat license: "
- return LICENSE_PREFIX LIBAV_LICENSE + sizeof(LICENSE_PREFIX) - 1;
+ return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1;
}
/* fraction handling */
@@ -79,7 +80,7 @@ const char *avformat_license(void)
* @param num must be >= 0
* @param den must be >= 1
*/
-static void av_frac_init(AVFrac *f, int64_t val, int64_t num, int64_t den)
+static void frac_init(AVFrac *f, int64_t val, int64_t num, int64_t den)
{
num += (den >> 1);
if (num >= den) {
@@ -97,7 +98,7 @@ static void av_frac_init(AVFrac *f, int64_t val, int64_t num, int64_t den)
* @param f fractional number
* @param incr increment, can be positive or negative
*/
-static void av_frac_add(AVFrac *f, int64_t incr)
+static void frac_add(AVFrac *f, int64_t incr)
{
int64_t num, den;
@@ -304,11 +305,11 @@ int av_filename_number_test(const char *filename)
return filename && (av_get_frame_filename(buf, sizeof(buf), filename, 1)>=0);
}
-AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, int *score_max)
+AVInputFormat *av_probe_input_format3(AVProbeData *pd, int is_opened, int *score_ret)
{
AVProbeData lpd = *pd;
AVInputFormat *fmt1 = NULL, *fmt;
- int score, id3 = 0;
+ int score, score_max=0;
if (lpd.buf_size > 10 && ff_id3v2_match(lpd.buf, ID3v2_DEFAULT_MAGIC)) {
int id3len = ff_id3v2_tag_len(lpd.buf);
@@ -316,7 +317,6 @@ AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, int *score
lpd.buf += id3len;
lpd.buf_size -= id3len;
}
- id3 = 1;
}
fmt = NULL;
@@ -326,36 +326,40 @@ AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, int *score
score = 0;
if (fmt1->read_probe) {
score = fmt1->read_probe(&lpd);
+ if(!score && fmt1->extensions && av_match_ext(lpd.filename, fmt1->extensions))
+ score = 1;
} else if (fmt1->extensions) {
if (av_match_ext(lpd.filename, fmt1->extensions)) {
score = 50;
}
}
- if (score > *score_max) {
- *score_max = score;
+ if (score > score_max) {
+ score_max = score;
fmt = fmt1;
- }else if (score == *score_max)
+ }else if (score == score_max)
fmt = NULL;
}
-
- /* a hack for files with huge id3v2 tags -- try to guess by file extension. */
- if (!fmt && id3 && *score_max < AVPROBE_SCORE_MAX/4) {
- while ((fmt = av_iformat_next(fmt)))
- if (fmt->extensions && av_match_ext(lpd.filename, fmt->extensions)) {
- *score_max = AVPROBE_SCORE_MAX/4;
- break;
- }
- }
-
+ *score_ret= score_max;
return fmt;
}
+AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, int *score_max)
+{
+ int score_ret;
+ AVInputFormat *fmt= av_probe_input_format3(pd, is_opened, &score_ret);
+ if(score_ret > *score_max){
+ *score_max= score_ret;
+ return fmt;
+ }else
+ return NULL;
+}
+
AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened){
int score=0;
return av_probe_input_format2(pd, is_opened, &score);
}
-static int set_codec_from_probe_data(AVFormatContext *s, AVStream *st, AVProbeData *pd, int score)
+static int set_codec_from_probe_data(AVFormatContext *s, AVStream *st, AVProbeData *pd)
{
static const struct {
const char *name; enum CodecID id; enum AVMediaType type;
@@ -365,12 +369,14 @@ static int set_codec_from_probe_data(AVFormatContext *s, AVStream *st, AVProbeDa
{ "dts" , CODEC_ID_DTS , AVMEDIA_TYPE_AUDIO },
{ "eac3" , CODEC_ID_EAC3 , AVMEDIA_TYPE_AUDIO },
{ "h264" , CODEC_ID_H264 , AVMEDIA_TYPE_VIDEO },
+ { "loas" , CODEC_ID_AAC_LATM , AVMEDIA_TYPE_AUDIO },
{ "m4v" , CODEC_ID_MPEG4 , AVMEDIA_TYPE_VIDEO },
{ "mp3" , CODEC_ID_MP3 , AVMEDIA_TYPE_AUDIO },
{ "mpegvideo", CODEC_ID_MPEG2VIDEO, AVMEDIA_TYPE_VIDEO },
{ 0 }
};
- AVInputFormat *fmt = av_probe_input_format2(pd, 1, &score);
+ int score;
+ AVInputFormat *fmt = av_probe_input_format3(pd, 1, &score);
if (fmt) {
int i;
@@ -384,7 +390,7 @@ static int set_codec_from_probe_data(AVFormatContext *s, AVStream *st, AVProbeDa
}
}
}
- return !!fmt;
+ return score;
}
/************************************************************/
@@ -399,6 +405,7 @@ static AVDictionary *convert_format_parameters(AVFormatParameters *ap)
if (!ap)
return NULL;
+ AV_NOWARN_DEPRECATED(
if (ap->time_base.num) {
snprintf(buf, sizeof(buf), "%d/%d", ap->time_base.den, ap->time_base.num);
av_dict_set(&opts, "framerate", buf, 0);
@@ -431,6 +438,7 @@ static AVDictionary *convert_format_parameters(AVFormatParameters *ap)
if (ap->initial_pause) {
av_dict_set(&opts, "initial_pause", "1", 0);
}
+ )
return opts;
}
@@ -452,10 +460,12 @@ int av_open_input_stream(AVFormatContext **ic_ptr,
}
opts = convert_format_parameters(ap);
+ AV_NOWARN_DEPRECATED(
if(!ap->prealloced_context)
- ic = avformat_alloc_context();
+ *ic_ptr = ic = avformat_alloc_context();
else
ic = *ic_ptr;
+ )
if (!ic) {
err = AVERROR(ENOMEM);
goto fail;
@@ -466,16 +476,33 @@ int av_open_input_stream(AVFormatContext **ic_ptr,
else
ic->pb = pb;
- err = avformat_open_input(&ic, filename, fmt, &opts);
+ if ((err = avformat_open_input(&ic, filename, fmt, &opts)) < 0)
+ goto fail;
ic->pb = ic->pb ? ic->pb : pb; // don't leak custom pb if it wasn't set above
- *ic_ptr = ic;
fail:
+ *ic_ptr = ic;
av_dict_free(&opts);
return err;
}
#endif
+int av_demuxer_open(AVFormatContext *ic, AVFormatParameters *ap){
+ int err;
+
+ if (ic->iformat->read_header) {
+ err = ic->iformat->read_header(ic, ap);
+ if (err < 0)
+ return err;
+ }
+
+ if (ic->pb && !ic->data_offset)
+ ic->data_offset = avio_tell(ic->pb);
+
+ return 0;
+}
+
+
/** size of probe buffer, for guessing file type from file contents */
#define PROBE_BUF_MIN 2048
#define PROBE_BUF_MAX (1<<20)
@@ -500,17 +527,23 @@ int av_probe_input_buffer(AVIOContext *pb, AVInputFormat **fmt,
return AVERROR(EINVAL);
}
- for(probe_size= PROBE_BUF_MIN; probe_size<=max_probe_size && !*fmt && ret >= 0;
+ for(probe_size= PROBE_BUF_MIN; probe_size<=max_probe_size && !*fmt;
probe_size = FFMIN(probe_size<<1, FFMAX(max_probe_size, probe_size+1))) {
- int ret, score = probe_size < max_probe_size ? AVPROBE_SCORE_MAX/4 : 0;
+ int score = probe_size < max_probe_size ? AVPROBE_SCORE_MAX/4 : 0;
int buf_offset = (probe_size == PROBE_BUF_MIN) ? 0 : probe_size>>1;
+ void *buftmp;
if (probe_size < offset) {
continue;
}
/* read probe data */
- buf = av_realloc(buf, probe_size + AVPROBE_PADDING_SIZE);
+ buftmp = av_realloc(buf, probe_size + AVPROBE_PADDING_SIZE);
+ if(!buftmp){
+ av_free(buf);
+ return AVERROR(ENOMEM);
+ }
+ buf=buftmp;
if ((ret = avio_read(pb, buf + buf_offset, probe_size - buf_offset)) < 0) {
/* fail if error was not end of file, otherwise, lower score */
if (ret != AVERROR_EOF) {
@@ -529,9 +562,9 @@ int av_probe_input_buffer(AVIOContext *pb, AVInputFormat **fmt,
*fmt = av_probe_input_format2(&pd, 1, &score);
if(*fmt){
if(score <= AVPROBE_SCORE_MAX/4){ //this can only be true in the last iteration
- av_log(logctx, AV_LOG_WARNING, "Format detected only with low score of %d, misdetection possible!\n", score);
+ av_log(logctx, AV_LOG_WARNING, "Format %s detected only with low score of %d, misdetection possible!\n", (*fmt)->name, score);
}else
- av_log(logctx, AV_LOG_DEBUG, "Probed with size=%d and score=%d\n", probe_size, score);
+ av_log(logctx, AV_LOG_DEBUG, "Format %s probed with size=%d and score=%d\n", (*fmt)->name, probe_size, score);
}
}
@@ -556,8 +589,10 @@ int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
int err;
AVDictionary *opts = convert_format_parameters(ap);
+ AV_NOWARN_DEPRECATED(
if (!ap || !ap->prealloced_context)
*ic_ptr = NULL;
+ )
err = avformat_open_input(ic_ptr, filename, fmt, &opts);
@@ -577,7 +612,8 @@ static int init_input(AVFormatContext *s, const char *filename)
if (!s->iformat)
return av_probe_input_buffer(s->pb, &s->iformat, filename, s, 0, 0);
else if (s->iformat->flags & AVFMT_NOFILE)
- return AVERROR(EINVAL);
+ av_log(s, AV_LOG_WARNING, "Custom AVIOContext makes no sense and "
+ "will be ignored with AVFMT_NOFILE format.\n");
return 0;
}
@@ -586,7 +622,7 @@ static int init_input(AVFormatContext *s, const char *filename)
return 0;
if ((ret = avio_open(&s->pb, filename, AVIO_FLAG_READ)) < 0)
- return ret;
+ return ret;
if (s->iformat)
return 0;
return av_probe_input_buffer(s->pb, &s->iformat, filename, s, 0, 0);
@@ -596,7 +632,7 @@ int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputForma
{
AVFormatContext *s = *ps;
int ret = 0;
- AVFormatParameters ap = { 0 };
+ AVFormatParameters ap = { { 0 } };
AVDictionary *tmp = NULL;
if (!s && !(s = avformat_alloc_context()))
@@ -642,11 +678,11 @@ int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputForma
if (s->pb)
ff_id3v2_read(s, ID3v2_DEFAULT_MAGIC);
- if (s->iformat->read_header)
+ if (!(s->flags&AVFMT_FLAG_PRIV_OPT) && s->iformat->read_header)
if ((ret = s->iformat->read_header(s, &ap)) < 0)
goto fail;
- if (s->pb && !s->data_offset)
+ if (!(s->flags&AVFMT_FLAG_PRIV_OPT) && s->pb && !s->data_offset)
s->data_offset = avio_tell(s->pb);
s->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE;
@@ -696,12 +732,7 @@ int av_read_packet(AVFormatContext *s, AVPacket *pkt)
if (pktl) {
*pkt = pktl->pkt;
- if(s->streams[pkt->stream_index]->codec->codec_id != CODEC_ID_PROBE ||
- !s->streams[pkt->stream_index]->probe_packets ||
- s->raw_packet_buffer_remaining_size < pkt->size){
- AVProbeData *pd = &s->streams[pkt->stream_index]->probe_data;
- av_freep(&pd->buf);
- pd->buf_size = 0;
+ if(s->streams[pkt->stream_index]->request_probe <= 0){
s->raw_packet_buffer = pktl->next;
s->raw_packet_buffer_remaining_size += pkt->size;
av_free(pktl);
@@ -715,9 +746,28 @@ int av_read_packet(AVFormatContext *s, AVPacket *pkt)
if (!pktl || ret == AVERROR(EAGAIN))
return ret;
for (i = 0; i < s->nb_streams; i++)
- s->streams[i]->probe_packets = 0;
+ if(s->streams[i]->request_probe > 0)
+ s->streams[i]->request_probe = -1;
continue;
}
+
+ if ((s->flags & AVFMT_FLAG_DISCARD_CORRUPT) &&
+ (pkt->flags & AV_PKT_FLAG_CORRUPT)) {
+ av_log(s, AV_LOG_WARNING,
+ "Dropped corrupted packet (stream = %d)\n",
+ pkt->stream_index);
+ av_free_packet(pkt);
+ continue;
+ }
+
+ if(!(s->flags & AVFMT_FLAG_KEEP_SIDE_DATA))
+ av_packet_merge_side_data(pkt);
+
+ if(pkt->stream_index >= (unsigned)s->nb_streams){
+ av_log(s, AV_LOG_ERROR, "Invalid stream index %d\n", pkt->stream_index);
+ continue;
+ }
+
st= s->streams[pkt->stream_index];
switch(st->codec->codec_type){
@@ -732,16 +782,16 @@ int av_read_packet(AVFormatContext *s, AVPacket *pkt)
break;
}
- if(!pktl && (st->codec->codec_id != CODEC_ID_PROBE ||
- !st->probe_packets))
+ if(!pktl && st->request_probe <= 0)
return ret;
add_to_pktbuf(&s->raw_packet_buffer, pkt, &s->raw_packet_buffer_end);
s->raw_packet_buffer_remaining_size -= pkt->size;
- if(st->codec->codec_id == CODEC_ID_PROBE){
+ if(st->request_probe>0){
AVProbeData *pd = &st->probe_data;
- av_log(s, AV_LOG_DEBUG, "probing stream %d\n", st->index);
+ int end;
+ av_log(s, AV_LOG_DEBUG, "probing stream %d pp:%d\n", st->index, st->probe_packets);
--st->probe_packets;
pd->buf = av_realloc(pd->buf, pd->buf_size+pkt->size+AVPROBE_PADDING_SIZE);
@@ -749,13 +799,20 @@ int av_read_packet(AVFormatContext *s, AVPacket *pkt)
pd->buf_size += pkt->size;
memset(pd->buf+pd->buf_size, 0, AVPROBE_PADDING_SIZE);
- if(av_log2(pd->buf_size) != av_log2(pd->buf_size - pkt->size)){
- //FIXME we dont reduce score to 0 for the case of running out of buffer space in bytes
- set_codec_from_probe_data(s, st, pd, st->probe_packets > 0 ? AVPROBE_SCORE_MAX/4 : 0);
- if(st->codec->codec_id != CODEC_ID_PROBE){
+ end= s->raw_packet_buffer_remaining_size <= 0
+ || st->probe_packets<=0;
+
+ if(end || av_log2(pd->buf_size) != av_log2(pd->buf_size - pkt->size)){
+ int score= set_codec_from_probe_data(s, st, pd);
+ if( (st->codec->codec_id != CODEC_ID_NONE && score > AVPROBE_SCORE_MAX/4)
+ || end){
pd->buf_size=0;
av_freep(&pd->buf);
+ st->request_probe= -1;
+ if(st->codec->codec_id != CODEC_ID_NONE){
av_log(s, AV_LOG_DEBUG, "probed stream %d\n", st->index);
+ }else
+ av_log(s, AV_LOG_WARNING, "probed stream %d failed\n", st->index);
}
}
}
@@ -842,6 +899,7 @@ static int is_intra_only(AVCodecContext *enc){
case CODEC_ID_MJPEG:
case CODEC_ID_MJPEGB:
case CODEC_ID_LJPEG:
+ case CODEC_ID_PRORES:
case CODEC_ID_RAWVIDEO:
case CODEC_ID_DVVIDEO:
case CODEC_ID_HUFFYUV:
@@ -954,8 +1012,7 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st,
pc && pc->pict_type != AV_PICTURE_TYPE_B)
presentation_delayed = 1;
- if(pkt->pts != AV_NOPTS_VALUE && pkt->dts != AV_NOPTS_VALUE && pkt->dts > pkt->pts && st->pts_wrap_bits<63
- /*&& pkt->dts-(1LL<<st->pts_wrap_bits) < pkt->pts*/){
+ if(pkt->pts != AV_NOPTS_VALUE && pkt->dts != AV_NOPTS_VALUE && pkt->dts - (1LL<<(st->pts_wrap_bits-1)) > pkt->pts && st->pts_wrap_bits<63){
pkt->dts -= 1LL<<st->pts_wrap_bits;
}
@@ -963,7 +1020,7 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st,
// we take the conservative approach and discard both
// Note, if this is misbehaving for a H.264 file then possibly presentation_delayed is not set correctly.
if(delay==1 && pkt->dts == pkt->pts && pkt->dts != AV_NOPTS_VALUE && presentation_delayed){
- av_log(s, AV_LOG_DEBUG, "invalid dts/pts combination\n");
+ av_log(s, AV_LOG_DEBUG, "invalid dts/pts combination %"PRIi64"\n", pkt->dts);
pkt->dts= pkt->pts= AV_NOPTS_VALUE;
}
@@ -1087,7 +1144,7 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st,
}
-static int av_read_frame_internal(AVFormatContext *s, AVPacket *pkt)
+static int read_frame_internal(AVFormatContext *s, AVPacket *pkt)
{
AVStream *st;
int len, ret, i;
@@ -1101,7 +1158,10 @@ static int av_read_frame_internal(AVFormatContext *s, AVPacket *pkt)
if (!st->need_parsing || !st->parser) {
/* no parsing needed: we just output the packet as is */
/* raw data support */
- *pkt = st->cur_pkt; st->cur_pkt.data= NULL;
+ *pkt = st->cur_pkt;
+ st->cur_pkt.data= NULL;
+ st->cur_pkt.side_data_elems = 0;
+ st->cur_pkt.side_data = NULL;
compute_pkt_fields(s, st, NULL, pkt);
s->cur_st = NULL;
if ((s->iformat->flags & AVFMT_GENERIC_INDEX) &&
@@ -1136,13 +1196,14 @@ static int av_read_frame_internal(AVFormatContext *s, AVPacket *pkt)
st->cur_pkt.data = NULL;
assert(st->cur_len == 0);
}else{
- pkt->destruct = NULL;
+ pkt->destruct = NULL;
}
compute_pkt_fields(s, st, st->parser, pkt);
if((s->iformat->flags & AVFMT_GENERIC_INDEX) && pkt->flags & AV_PKT_FLAG_KEY){
+ int64_t pos= (st->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) ? pkt->pos : st->parser->frame_offset;
ff_reduce_index(s, st->index);
- av_add_index_entry(st, st->parser->frame_offset, pkt->dts,
+ av_add_index_entry(st, pos, pkt->dts,
0, 0, AVINDEX_KEYFRAME);
}
@@ -1206,6 +1267,9 @@ static int av_read_frame_internal(AVFormatContext *s, AVPacket *pkt)
if (st->need_parsing && !st->parser && !(s->flags & AVFMT_FLAG_NOPARSE)) {
st->parser = av_parser_init(st->codec->codec_id);
if (!st->parser) {
+ av_log(s, AV_LOG_WARNING, "parser not found for codec "
+ "%s, packets or times may be invalid.\n",
+ avcodec_get_name(st->codec->codec_id));
/* no parser available: just output the raw packets */
st->need_parsing = AVSTREAM_PARSE_NONE;
}else if(st->need_parsing == AVSTREAM_PARSE_HEADERS){
@@ -1217,7 +1281,7 @@ static int av_read_frame_internal(AVFormatContext *s, AVPacket *pkt)
}
}
if(s->debug & FF_FDEBUG_TS)
- av_log(s, AV_LOG_DEBUG, "av_read_frame_internal stream=%d, pts=%"PRId64", dts=%"PRId64", size=%d, duration=%d, flags=%d\n",
+ av_log(s, AV_LOG_DEBUG, "read_frame_internal stream=%d, pts=%"PRId64", dts=%"PRId64", size=%d, duration=%d, flags=%d\n",
pkt->stream_index,
pkt->pts,
pkt->dts,
@@ -1263,7 +1327,7 @@ int av_read_frame(AVFormatContext *s, AVPacket *pkt)
}
}
if(genpts){
- int ret= av_read_frame_internal(s, pkt);
+ int ret= read_frame_internal(s, pkt);
if(ret<0){
if(pktl && ret != AVERROR(EAGAIN)){
eof=1;
@@ -1277,7 +1341,7 @@ int av_read_frame(AVFormatContext *s, AVPacket *pkt)
return AVERROR(ENOMEM);
}else{
assert(!s->packet_buffer);
- return av_read_frame_internal(s, pkt);
+ return read_frame_internal(s, pkt);
}
}
}
@@ -1538,6 +1602,7 @@ int av_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts
if ((ret = avio_seek(s->pb, pos, SEEK_SET)) < 0)
return ret;
+ ff_read_frame_flush(s);
av_update_cur_dts(s, st, ts);
return 0;
@@ -1557,6 +1622,11 @@ int64_t av_gen_search(AVFormatContext *s, int stream_index, int64_t target_ts, i
return -1;
}
+ if(ts_min >= target_ts){
+ *ts_ret= ts_min;
+ return pos_min;
+ }
+
if(ts_max == AV_NOPTS_VALUE){
int step= 1024;
filesize = avio_size(s->pb);
@@ -1582,6 +1652,11 @@ int64_t av_gen_search(AVFormatContext *s, int stream_index, int64_t target_ts, i
pos_limit= pos_max;
}
+ if(ts_max <= target_ts){
+ *ts_ret= ts_max;
+ return pos_max;
+ }
+
if(ts_min > ts_max){
return -1;
}else if(ts_min == ts_max){
@@ -1639,17 +1714,19 @@ int64_t av_gen_search(AVFormatContext *s, int stream_index, int64_t target_ts, i
pos = (flags & AVSEEK_FLAG_BACKWARD) ? pos_min : pos_max;
ts = (flags & AVSEEK_FLAG_BACKWARD) ? ts_min : ts_max;
+#if 0
pos_min = pos;
ts_min = read_timestamp(s, stream_index, &pos_min, INT64_MAX);
pos_min++;
ts_max = read_timestamp(s, stream_index, &pos_min, INT64_MAX);
av_dlog(s, "pos=0x%"PRIx64" %"PRId64"<=%"PRId64"<=%"PRId64"\n",
pos, ts_min, target_ts, ts_max);
+#endif
*ts_ret= ts;
return pos;
}
-static int av_seek_frame_byte(AVFormatContext *s, int stream_index, int64_t pos, int flags){
+static int seek_frame_byte(AVFormatContext *s, int stream_index, int64_t pos, int flags){
int64_t pos_min, pos_max;
#if 0
AVStream *st;
@@ -1674,7 +1751,7 @@ static int av_seek_frame_byte(AVFormatContext *s, int stream_index, int64_t pos,
return 0;
}
-static int av_seek_frame_generic(AVFormatContext *s,
+static int seek_frame_generic(AVFormatContext *s,
int stream_index, int64_t timestamp, int flags)
{
int index;
@@ -1690,8 +1767,8 @@ static int av_seek_frame_generic(AVFormatContext *s,
return -1;
if(index < 0 || index==st->nb_index_entries-1){
- int i;
AVPacket pkt;
+ int nonkey=0;
if(st->nb_index_entries){
assert(st->index_entries);
@@ -1703,17 +1780,21 @@ static int av_seek_frame_generic(AVFormatContext *s,
if ((ret = avio_seek(s->pb, s->data_offset, SEEK_SET)) < 0)
return ret;
}
- for(i=0;; i++) {
- int ret;
+ for (;;) {
+ int read_status;
do{
- ret = av_read_frame(s, &pkt);
- }while(ret == AVERROR(EAGAIN));
- if(ret<0)
+ read_status = av_read_frame(s, &pkt);
+ } while (read_status == AVERROR(EAGAIN));
+ if (read_status < 0)
break;
av_free_packet(&pkt);
- if(stream_index == pkt.stream_index){
- if((pkt.flags & AV_PKT_FLAG_KEY) && pkt.dts > timestamp)
+ if(stream_index == pkt.stream_index && pkt.dts > timestamp){
+ if(pkt.flags & AV_PKT_FLAG_KEY)
+ break;
+ if(nonkey++ > 1000){
+ av_log(s, AV_LOG_ERROR,"seek_frame_generic failed as this stream seems to contain no keyframes after the target timestamp, %d non keyframes found\n", nonkey);
break;
+ }
}
}
index = av_index_search_timestamp(st, timestamp, flags);
@@ -1722,10 +1803,12 @@ static int av_seek_frame_generic(AVFormatContext *s,
return -1;
ff_read_frame_flush(s);
+ AV_NOWARN_DEPRECATED(
if (s->iformat->read_seek){
if(s->iformat->read_seek(s, stream_index, timestamp, flags) >= 0)
return 0;
}
+ )
ie = &st->index_entries[index];
if ((ret = avio_seek(s->pb, ie->pos, SEEK_SET)) < 0)
return ret;
@@ -1739,10 +1822,12 @@ int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int f
int ret;
AVStream *st;
- ff_read_frame_flush(s);
-
- if(flags & AVSEEK_FLAG_BYTE)
- return av_seek_frame_byte(s, stream_index, timestamp, flags);
+ if (flags & AVSEEK_FLAG_BYTE) {
+ if (s->iformat->flags & AVFMT_NO_BYTE_SEEK)
+ return -1;
+ ff_read_frame_flush(s);
+ return seek_frame_byte(s, stream_index, timestamp, flags);
+ }
if(stream_index < 0){
stream_index= av_find_default_stream_index(s);
@@ -1750,23 +1835,29 @@ int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int f
return -1;
st= s->streams[stream_index];
- /* timestamp for default must be expressed in AV_TIME_BASE units */
+ /* timestamp for default must be expressed in AV_TIME_BASE units */
timestamp = av_rescale(timestamp, st->time_base.den, AV_TIME_BASE * (int64_t)st->time_base.num);
}
/* first, we try the format specific seek */
- if (s->iformat->read_seek)
+ AV_NOWARN_DEPRECATED(
+ if (s->iformat->read_seek) {
+ ff_read_frame_flush(s);
ret = s->iformat->read_seek(s, stream_index, timestamp, flags);
- else
+ } else
ret = -1;
+ )
if (ret >= 0) {
return 0;
}
- if(s->iformat->read_timestamp && !(s->iformat->flags & AVFMT_NOBINSEARCH))
+ if (s->iformat->read_timestamp && !(s->iformat->flags & AVFMT_NOBINSEARCH)) {
+ ff_read_frame_flush(s);
return av_seek_frame_binary(s, stream_index, timestamp, flags);
- else if (!(s->iformat->flags & AVFMT_NOGENSEARCH))
- return av_seek_frame_generic(s, stream_index, timestamp, flags);
+ } else if (!(s->iformat->flags & AVFMT_NOGENSEARCH)) {
+ ff_read_frame_flush(s);
+ return seek_frame_generic(s, stream_index, timestamp, flags);
+ }
else
return -1;
}
@@ -1776,10 +1867,10 @@ int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int
if(min_ts > ts || max_ts < ts)
return -1;
- ff_read_frame_flush(s);
-
- if (s->iformat->read_seek2)
+ if (s->iformat->read_seek2) {
+ ff_read_frame_flush(s);
return s->iformat->read_seek2(s, stream_index, min_ts, ts, max_ts, flags);
+ }
if(s->iformat->read_timestamp){
//try to seek via read_timestamp()
@@ -1787,10 +1878,12 @@ int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int
//Fallback to old API if new is not implemented but old is
//Note the old has somewat different sematics
+ AV_NOWARN_DEPRECATED(
if(s->iformat->read_seek || 1)
return av_seek_frame(s, stream_index, ts, flags | (ts - min_ts > (uint64_t)(max_ts - ts) ? AVSEEK_FLAG_BACKWARD : 0));
+ )
- // try some generic seek like av_seek_frame_generic() but with new ts semantics
+ // try some generic seek like seek_frame_generic() but with new ts semantics
}
/*******************************************************/
@@ -1800,10 +1893,12 @@ int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int
*
* @return TRUE if the stream has accurate duration for at least one component.
*/
-static int av_has_duration(AVFormatContext *ic)
+static int has_duration(AVFormatContext *ic)
{
int i;
AVStream *st;
+ if(ic->duration != AV_NOPTS_VALUE)
+ return 1;
for(i = 0;i < ic->nb_streams; i++) {
st = ic->streams[i];
@@ -1818,20 +1913,25 @@ static int av_has_duration(AVFormatContext *ic)
*
* Also computes the global bitrate if possible.
*/
-static void av_update_stream_timings(AVFormatContext *ic)
+static void update_stream_timings(AVFormatContext *ic)
{
- int64_t start_time, start_time1, end_time, end_time1;
- int64_t duration, duration1;
+ int64_t start_time, start_time1, start_time_text, end_time, end_time1;
+ int64_t duration, duration1, filesize;
int i;
AVStream *st;
start_time = INT64_MAX;
+ start_time_text = INT64_MAX;
end_time = INT64_MIN;
duration = INT64_MIN;
for(i = 0;i < ic->nb_streams; i++) {
st = ic->streams[i];
if (st->start_time != AV_NOPTS_VALUE && st->time_base.den) {
start_time1= av_rescale_q(st->start_time, st->time_base, AV_TIME_BASE_Q);
+ if (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) {
+ if (start_time1 < start_time_text)
+ start_time_text = start_time1;
+ } else
if (start_time1 < start_time)
start_time = start_time1;
if (st->duration != AV_NOPTS_VALUE) {
@@ -1847,6 +1947,8 @@ static void av_update_stream_timings(AVFormatContext *ic)
duration = duration1;
}
}
+ if (start_time == INT64_MAX || (start_time > start_time_text && start_time - start_time_text < AV_TIME_BASE))
+ start_time = start_time_text;
if (start_time != INT64_MAX) {
ic->start_time = start_time;
if (end_time != INT64_MIN) {
@@ -1854,14 +1956,14 @@ static void av_update_stream_timings(AVFormatContext *ic)
duration = end_time - start_time;
}
}
- if (duration != INT64_MIN) {
+ if (duration != INT64_MIN && ic->duration == AV_NOPTS_VALUE) {
ic->duration = duration;
- if (ic->file_size > 0) {
+ }
+ if (ic->pb && (filesize = avio_size(ic->pb)) > 0 && ic->duration != AV_NOPTS_VALUE) {
/* compute the bitrate */
- ic->bit_rate = (double)ic->file_size * 8.0 * AV_TIME_BASE /
+ ic->bit_rate = (double)filesize * 8.0 * AV_TIME_BASE /
(double)ic->duration;
}
- }
}
static void fill_all_stream_timings(AVFormatContext *ic)
@@ -1869,7 +1971,7 @@ static void fill_all_stream_timings(AVFormatContext *ic)
int i;
AVStream *st;
- av_update_stream_timings(ic);
+ update_stream_timings(ic);
for(i = 0;i < ic->nb_streams; i++) {
st = ic->streams[i];
if (st->start_time == AV_NOPTS_VALUE) {
@@ -1881,7 +1983,7 @@ static void fill_all_stream_timings(AVFormatContext *ic)
}
}
-static void av_estimate_timings_from_bit_rate(AVFormatContext *ic)
+static void estimate_timings_from_bit_rate(AVFormatContext *ic)
{
int64_t filesize, duration;
int bit_rate, i;
@@ -1900,9 +2002,8 @@ static void av_estimate_timings_from_bit_rate(AVFormatContext *ic)
/* if duration is already set, we believe it */
if (ic->duration == AV_NOPTS_VALUE &&
- ic->bit_rate != 0 &&
- ic->file_size != 0) {
- filesize = ic->file_size;
+ ic->bit_rate != 0) {
+ filesize = ic->pb ? avio_size(ic->pb) : 0;
if (filesize > 0) {
for(i = 0; i < ic->nb_streams; i++) {
st = ic->streams[i];
@@ -1918,7 +2019,7 @@ static void av_estimate_timings_from_bit_rate(AVFormatContext *ic)
#define DURATION_MAX_RETRY 3
/* only usable for MPEG-PS streams */
-static void av_estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset)
+static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset)
{
AVPacket pkt1, *pkt = &pkt1;
AVStream *st;
@@ -1935,7 +2036,7 @@ static void av_estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset
for (i=0; i<ic->nb_streams; i++) {
st = ic->streams[i];
if (st->start_time == AV_NOPTS_VALUE && st->first_dts == AV_NOPTS_VALUE)
- av_log(st->codec, AV_LOG_WARNING, "start time is not set in av_estimate_timings_from_pts\n");
+ av_log(st->codec, AV_LOG_WARNING, "start time is not set in estimate_timings_from_pts\n");
if (st->parser) {
av_parser_close(st->parser);
@@ -1946,42 +2047,43 @@ static void av_estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset
/* estimate the end time (duration) */
/* XXX: may need to support wrapping */
- filesize = ic->file_size;
+ filesize = ic->pb ? avio_size(ic->pb) : 0;
end_time = AV_NOPTS_VALUE;
do{
- offset = filesize - (DURATION_MAX_READ_SIZE<<retry);
- if (offset < 0)
- offset = 0;
+ offset = filesize - (DURATION_MAX_READ_SIZE<<retry);
+ if (offset < 0)
+ offset = 0;
- avio_seek(ic->pb, offset, SEEK_SET);
- read_size = 0;
- for(;;) {
- if (read_size >= DURATION_MAX_READ_SIZE<<(FFMAX(retry-1,0)))
- break;
+ avio_seek(ic->pb, offset, SEEK_SET);
+ read_size = 0;
+ for(;;) {
+ if (read_size >= DURATION_MAX_READ_SIZE<<(FFMAX(retry-1,0)))
+ break;
- do{
- ret = av_read_packet(ic, pkt);
- }while(ret == AVERROR(EAGAIN));
- if (ret != 0)
- break;
- read_size += pkt->size;
- st = ic->streams[pkt->stream_index];
- if (pkt->pts != AV_NOPTS_VALUE &&
- (st->start_time != AV_NOPTS_VALUE ||
- st->first_dts != AV_NOPTS_VALUE)) {
- duration = end_time = pkt->pts;
- if (st->start_time != AV_NOPTS_VALUE) duration -= st->start_time;
- else duration -= st->first_dts;
- if (duration < 0)
- duration += 1LL<<st->pts_wrap_bits;
- if (duration > 0) {
- if (st->duration == AV_NOPTS_VALUE ||
- st->duration < duration)
- st->duration = duration;
+ do {
+ ret = av_read_packet(ic, pkt);
+ } while(ret == AVERROR(EAGAIN));
+ if (ret != 0)
+ break;
+ read_size += pkt->size;
+ st = ic->streams[pkt->stream_index];
+ if (pkt->pts != AV_NOPTS_VALUE &&
+ (st->start_time != AV_NOPTS_VALUE ||
+ st->first_dts != AV_NOPTS_VALUE)) {
+ duration = end_time = pkt->pts;
+ if (st->start_time != AV_NOPTS_VALUE)
+ duration -= st->start_time;
+ else
+ duration -= st->first_dts;
+ if (duration < 0)
+ duration += 1LL<<st->pts_wrap_bits;
+ if (duration > 0) {
+ if (st->duration == AV_NOPTS_VALUE || st->duration < duration)
+ st->duration = duration;
+ }
}
+ av_free_packet(pkt);
}
- av_free_packet(pkt);
- }
}while( end_time==AV_NOPTS_VALUE
&& filesize > (DURATION_MAX_READ_SIZE<<retry)
&& ++retry <= DURATION_MAX_RETRY);
@@ -1997,7 +2099,7 @@ static void av_estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset
}
}
-static void av_estimate_timings(AVFormatContext *ic, int64_t old_offset)
+static void estimate_timings(AVFormatContext *ic, int64_t old_offset)
{
int64_t file_size;
@@ -2009,23 +2111,22 @@ static void av_estimate_timings(AVFormatContext *ic, int64_t old_offset)
if (file_size < 0)
file_size = 0;
}
- ic->file_size = file_size;
if ((!strcmp(ic->iformat->name, "mpeg") ||
!strcmp(ic->iformat->name, "mpegts")) &&
file_size && ic->pb->seekable) {
/* get accurate estimate from the PTSes */
- av_estimate_timings_from_pts(ic, old_offset);
- } else if (av_has_duration(ic)) {
+ estimate_timings_from_pts(ic, old_offset);
+ } else if (has_duration(ic)) {
/* at least one component has timings - we use them for all
the components */
fill_all_stream_timings(ic);
} else {
av_log(ic, AV_LOG_WARNING, "Estimating duration from bitrate, this may be inaccurate\n");
/* less precise: use bitrate info */
- av_estimate_timings_from_bit_rate(ic);
+ estimate_timings_from_bit_rate(ic);
}
- av_update_stream_timings(ic);
+ update_stream_timings(ic);
{
int i;
@@ -2043,29 +2144,31 @@ static void av_estimate_timings(AVFormatContext *ic, int64_t old_offset)
}
}
-static int has_codec_parameters(AVCodecContext *enc)
+static int has_codec_parameters(AVCodecContext *avctx)
{
int val;
- switch(enc->codec_type) {
+ switch (avctx->codec_type) {
case AVMEDIA_TYPE_AUDIO:
- val = enc->sample_rate && enc->channels && enc->sample_fmt != AV_SAMPLE_FMT_NONE;
- if(!enc->frame_size &&
- (enc->codec_id == CODEC_ID_VORBIS ||
- enc->codec_id == CODEC_ID_AAC ||
- enc->codec_id == CODEC_ID_MP1 ||
- enc->codec_id == CODEC_ID_MP2 ||
- enc->codec_id == CODEC_ID_MP3 ||
- enc->codec_id == CODEC_ID_SPEEX))
+ val = avctx->sample_rate && avctx->channels && avctx->sample_fmt != AV_SAMPLE_FMT_NONE;
+ if (!avctx->frame_size &&
+ (avctx->codec_id == CODEC_ID_VORBIS ||
+ avctx->codec_id == CODEC_ID_AAC ||
+ avctx->codec_id == CODEC_ID_MP1 ||
+ avctx->codec_id == CODEC_ID_MP2 ||
+ avctx->codec_id == CODEC_ID_MP3 ||
+ avctx->codec_id == CODEC_ID_CELT))
return 0;
break;
case AVMEDIA_TYPE_VIDEO:
- val = enc->width && enc->pix_fmt != PIX_FMT_NONE;
+ val = avctx->width && avctx->pix_fmt != PIX_FMT_NONE;
break;
+ case AVMEDIA_TYPE_DATA:
+ if(avctx->codec_id == CODEC_ID_NONE) return 1;
default:
val = 1;
break;
}
- return enc->codec_id != CODEC_ID_NONE && val != 0;
+ return avctx->codec_id != CODEC_ID_NONE && val != 0;
}
static int has_decode_delay_been_guessed(AVStream *st)
@@ -2074,7 +2177,7 @@ static int has_decode_delay_been_guessed(AVStream *st)
st->codec_info_nb_frames >= 6 + st->codec->has_b_frames;
}
-static int try_decode_frame(AVStream *st, AVPacket *avpkt)
+static int try_decode_frame(AVStream *st, AVPacket *avpkt, AVDictionary **options)
{
int16_t *samples;
AVCodec *codec;
@@ -2085,12 +2188,13 @@ static int try_decode_frame(AVStream *st, AVPacket *avpkt)
codec = avcodec_find_decoder(st->codec->codec_id);
if (!codec)
return -1;
- ret = avcodec_open(st->codec, codec);
+ ret = avcodec_open2(st->codec, codec, options);
if (ret < 0)
return ret;
}
- if(!has_codec_parameters(st->codec) || !has_decode_delay_been_guessed(st)){
+ if(!has_codec_parameters(st->codec) || !has_decode_delay_been_guessed(st) ||
+ (!st->codec_info_nb_frames && st->codec->codec->capabilities & CODEC_CAP_CHANNEL_CONF)) {
switch(st->codec->codec_type) {
case AVMEDIA_TYPE_VIDEO:
avcodec_get_frame_defaults(&picture);
@@ -2132,7 +2236,7 @@ enum CodecID ff_codec_get_id(const AVCodecTag *tags, unsigned int tag)
return tags[i].id;
}
for(i=0; tags[i].id != CODEC_ID_NONE; i++) {
- if (ff_toupper4(tag) == ff_toupper4(tags[i].tag))
+ if (avpriv_toupper4(tag) == avpriv_toupper4(tags[i].tag))
return tags[i].id;
}
return CODEC_ID_NONE;
@@ -2204,12 +2308,20 @@ static int tb_unreliable(AVCodecContext *c){
return 0;
}
+#if FF_API_FORMAT_PARAMETERS
int av_find_stream_info(AVFormatContext *ic)
{
+ return avformat_find_stream_info(ic, NULL);
+}
+#endif
+
+int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
+{
int i, count, ret, read_size, j;
AVStream *st;
AVPacket pkt1, *pkt;
int64_t old_offset = avio_tell(ic->pb);
+ int orig_nb_streams = ic->nb_streams; // new streams might appear, no options for those
for(i=0;i<ic->nb_streams;i++) {
AVCodec *codec;
@@ -2235,12 +2347,19 @@ int av_find_stream_info(AVFormatContext *ic)
/* Ensure that subtitle_header is properly set. */
if (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE
&& codec && !st->codec->codec)
- avcodec_open(st->codec, codec);
+ avcodec_open2(st->codec, codec, options ? &options[i] : NULL);
//try to just open decoders, in case this is enough to get parameters
if(!has_codec_parameters(st->codec)){
- if (codec && !st->codec->codec)
- avcodec_open(st->codec, codec);
+ if (codec && !st->codec->codec){
+ AVDictionary *tmp = NULL;
+ if (options){
+ av_dict_copy(&tmp, options[i], 0);
+ av_dict_set(&tmp, "threads", 0, 0);
+ }
+ avcodec_open2(st->codec, codec, options ? &tmp : NULL);
+ av_dict_free(&tmp);
+ }
}
}
@@ -2278,7 +2397,7 @@ int av_find_stream_info(AVFormatContext *ic)
break;
if(st->parser && st->parser->parser->split && !st->codec->extradata)
break;
- if(st->first_dts == AV_NOPTS_VALUE)
+ if(st->first_dts == AV_NOPTS_VALUE && (st->codec->codec_type == AVMEDIA_TYPE_VIDEO || st->codec->codec_type == AVMEDIA_TYPE_AUDIO))
break;
}
if (i == ic->nb_streams) {
@@ -2301,7 +2420,7 @@ int av_find_stream_info(AVFormatContext *ic)
/* NOTE: a new stream can be added there if no header in file
(AVFMTCTX_NOHEADER) */
- ret = av_read_frame_internal(ic, &pkt1);
+ ret = read_frame_internal(ic, &pkt1);
if (ret == AVERROR(EAGAIN))
continue;
@@ -2329,28 +2448,31 @@ int av_find_stream_info(AVFormatContext *ic)
st = ic->streams[pkt->stream_index];
if (st->codec_info_nb_frames>1) {
- if (st->time_base.den > 0 && av_rescale_q(st->info->codec_info_duration, st->time_base, AV_TIME_BASE_Q) >= ic->max_analyze_duration) {
- av_log(ic, AV_LOG_WARNING, "max_analyze_duration reached\n");
+ int64_t t;
+ if (st->time_base.den > 0 && (t=av_rescale_q(st->info->codec_info_duration, st->time_base, AV_TIME_BASE_Q)) >= ic->max_analyze_duration) {
+ av_log(ic, AV_LOG_WARNING, "max_analyze_duration %d reached at %"PRId64"\n", ic->max_analyze_duration, t);
break;
}
st->info->codec_info_duration += pkt->duration;
}
{
int64_t last = st->info->last_dts;
- int64_t duration= pkt->dts - last;
- if(pkt->dts != AV_NOPTS_VALUE && last != AV_NOPTS_VALUE && duration>0){
- double dur= duration * av_q2d(st->time_base);
+ if(pkt->dts != AV_NOPTS_VALUE && last != AV_NOPTS_VALUE && pkt->dts > last){
+ double dts= pkt->dts * av_q2d(st->time_base);
+ int64_t duration= pkt->dts - last;
// if(st->codec->codec_type == AVMEDIA_TYPE_VIDEO)
// av_log(NULL, AV_LOG_ERROR, "%f\n", dur);
- if (st->info->duration_count < 2)
- memset(st->info->duration_error, 0, sizeof(st->info->duration_error));
- for (i=1; i<FF_ARRAY_ELEMS(st->info->duration_error); i++) {
+ for (i=1; i<FF_ARRAY_ELEMS(st->info->duration_error[0][0]); i++) {
int framerate= get_std_framerate(i);
- int ticks= lrintf(dur*framerate/(1001*12));
- double error= dur - ticks*1001*12/(double)framerate;
- st->info->duration_error[i] += error*error;
+ double sdts= dts*framerate/(1001*12);
+ for(j=0; j<2; j++){
+ int ticks= lrintf(sdts+j*0.5);
+ double error= sdts - ticks + j*0.5;
+ st->info->duration_error[j][0][i] += error;
+ st->info->duration_error[j][1][i] += error*error;
+ }
}
st->info->duration_count++;
// ignore the first 4 values, they might have some random jitter
@@ -2379,11 +2501,7 @@ int av_find_stream_info(AVFormatContext *ic)
least one frame of codec data, this makes sure the codec initializes
the channel configuration and does not only trust the values from the container.
*/
- if (!has_codec_parameters(st->codec) ||
- !has_decode_delay_been_guessed(st) ||
- (st->codec->codec &&
- st->codec->codec->capabilities & CODEC_CAP_CHANNEL_CONF))
- try_decode_frame(st, pkt);
+ try_decode_frame(st, pkt, (options && i < orig_nb_streams )? &options[i] : NULL);
st->codec_info_nb_frames++;
count++;
@@ -2402,29 +2520,40 @@ int av_find_stream_info(AVFormatContext *ic)
(st->codec_info_nb_frames-2)*(int64_t)st->time_base.den,
st->info->codec_info_duration*(int64_t)st->time_base.num, 60000);
if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
- if(st->codec->codec_id == CODEC_ID_RAWVIDEO && !st->codec->codec_tag && !st->codec->bits_per_coded_sample)
- st->codec->codec_tag= avcodec_pix_fmt_to_codec_tag(st->codec->pix_fmt);
+ if(st->codec->codec_id == CODEC_ID_RAWVIDEO && !st->codec->codec_tag && !st->codec->bits_per_coded_sample){
+ uint32_t tag= avcodec_pix_fmt_to_codec_tag(st->codec->pix_fmt);
+ if(ff_find_pix_fmt(ff_raw_pix_fmt_tags, tag) == st->codec->pix_fmt)
+ st->codec->codec_tag= tag;
+ }
// the check for tb_unreliable() is not completely correct, since this is not about handling
// a unreliable/inexact time base, but a time base that is finer than necessary, as e.g.
// ipmovie.c produces.
- if (tb_unreliable(st->codec) && st->info->duration_count > 15 && st->info->duration_gcd > 1 && !st->r_frame_rate.num)
+ if (tb_unreliable(st->codec) && st->info->duration_count > 15 && st->info->duration_gcd > FFMAX(1, st->time_base.den/(500LL*st->time_base.num)) && !st->r_frame_rate.num)
av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den, st->time_base.den, st->time_base.num * st->info->duration_gcd, INT_MAX);
if (st->info->duration_count && !st->r_frame_rate.num
&& tb_unreliable(st->codec) /*&&
//FIXME we should not special-case MPEG-2, but this needs testing with non-MPEG-2 ...
st->time_base.num*duration_sum[i]/st->info->duration_count*101LL > st->time_base.den*/){
int num = 0;
- double best_error= 2*av_q2d(st->time_base);
- best_error = best_error*best_error*st->info->duration_count*1000*12*30;
-
- for (j=1; j<FF_ARRAY_ELEMS(st->info->duration_error); j++) {
- double error = st->info->duration_error[j] * get_std_framerate(j);
-// if(st->codec->codec_type == AVMEDIA_TYPE_VIDEO)
-// av_log(NULL, AV_LOG_ERROR, "%f %f\n", get_std_framerate(j) / 12.0/1001, error);
- if(error < best_error){
- best_error= error;
- num = get_std_framerate(j);
+ double best_error= 0.01;
+
+ for (j=1; j<FF_ARRAY_ELEMS(st->info->duration_error[0][0]); j++) {
+ int k;
+
+ if(st->info->codec_info_duration && st->info->codec_info_duration*av_q2d(st->time_base) < (1001*12.0)/get_std_framerate(j))
+ continue;
+ for(k=0; k<2; k++){
+ int n= st->info->duration_count;
+ double a= st->info->duration_error[k][0][j] / n;
+ double error= st->info->duration_error[k][1][j]/n - a*a;
+
+ if(error < best_error && best_error> 0.000000001){
+ best_error= error;
+ num = get_std_framerate(j);
+ }
+ if(error < 0.02)
+ av_log(NULL, AV_LOG_DEBUG, "rfps: %f %f\n", get_std_framerate(j) / 12.0/1001, error);
}
}
// do not increase frame rate by more than 1 % in order to match a standard rate.
@@ -2461,7 +2590,7 @@ int av_find_stream_info(AVFormatContext *ic)
}
}
- av_estimate_timings(ic, old_offset);
+ estimate_timings(ic, old_offset);
compute_chapters_end(ic);
@@ -2496,14 +2625,20 @@ int av_find_stream_info(AVFormatContext *ic)
return ret;
}
-static AVProgram *find_program_from_stream(AVFormatContext *ic, int s)
+AVProgram *av_find_program_from_stream(AVFormatContext *ic, AVProgram *last, int s)
{
int i, j;
- for (i = 0; i < ic->nb_programs; i++)
- for (j = 0; j < ic->programs[i]->nb_stream_indexes; j++)
- if (ic->programs[i]->stream_index[j] == s)
- return ic->programs[i];
+ for (i = 0; i < ic->nb_programs; i++) {
+ if (ic->programs[i] == last) {
+ last = NULL;
+ } else {
+ if (!last)
+ for (j = 0; j < ic->programs[i]->nb_stream_indexes; j++)
+ if (ic->programs[i]->stream_index[j] == s)
+ return ic->programs[i];
+ }
+ }
return NULL;
}
@@ -2520,7 +2655,7 @@ int av_find_best_stream(AVFormatContext *ic,
AVCodec *decoder = NULL, *best_decoder = NULL;
if (related_stream >= 0 && wanted_stream_nb < 0) {
- AVProgram *p = find_program_from_stream(ic, related_stream);
+ AVProgram *p = av_find_program_from_stream(ic, NULL, related_stream);
if (p) {
program = p->stream_index;
nb_streams = p->nb_stream_indexes;
@@ -2605,13 +2740,13 @@ void avformat_free_context(AVFormatContext *s)
av_free_packet(&st->cur_pkt);
}
av_dict_free(&st->metadata);
- av_free(st->index_entries);
- av_free(st->codec->extradata);
- av_free(st->codec->subtitle_header);
- av_free(st->codec);
- av_free(st->priv_data);
- av_free(st->info);
- av_free(st);
+ av_freep(&st->index_entries);
+ av_freep(&st->codec->extradata);
+ av_freep(&st->codec->subtitle_header);
+ av_freep(&st->codec);
+ av_freep(&st->priv_data);
+ av_freep(&st->info);
+ av_freep(&st);
}
for(i=s->nb_programs-1; i>=0; i--) {
av_dict_free(&s->programs[i]->metadata);
@@ -2622,7 +2757,7 @@ void avformat_free_context(AVFormatContext *s)
av_freep(&s->priv_data);
while(s->nb_chapters--) {
av_dict_free(&s->chapters[s->nb_chapters]->metadata);
- av_free(s->chapters[s->nb_chapters]);
+ av_freep(&s->chapters[s->nb_chapters]);
}
av_freep(&s->chapters);
av_dict_free(&s->metadata);
@@ -2639,8 +2774,18 @@ void av_close_input_file(AVFormatContext *s)
avio_close(pb);
}
+#if FF_API_NEW_STREAM
AVStream *av_new_stream(AVFormatContext *s, int id)
{
+ AVStream *st = avformat_new_stream(s, NULL);
+ if (st)
+ st->id = id;
+ return st;
+}
+#endif
+
+AVStream *avformat_new_stream(AVFormatContext *s, AVCodec *c)
+{
AVStream *st;
int i;
AVStream **streams;
@@ -2660,13 +2805,12 @@ AVStream *av_new_stream(AVFormatContext *s, int id)
return NULL;
}
- st->codec= avcodec_alloc_context();
+ st->codec = avcodec_alloc_context3(c);
if (s->iformat) {
/* no default bitrate if decoding */
st->codec->bit_rate = 0;
}
st->index = s->nb_streams;
- st->id = id;
st->start_time = AV_NOPTS_VALUE;
st->duration = AV_NOPTS_VALUE;
/* we set the current DTS to 0 so that formats without any timestamps
@@ -2713,7 +2857,7 @@ AVProgram *av_new_program(AVFormatContext *ac, int id)
return program;
}
-AVChapter *ff_new_chapter(AVFormatContext *s, int id, AVRational time_base, int64_t start, int64_t end, const char *title)
+AVChapter *avpriv_new_chapter(AVFormatContext *s, int id, AVRational time_base, int64_t start, int64_t end, const char *title)
{
AVChapter *chapter = NULL;
int i;
@@ -2743,8 +2887,6 @@ AVChapter *ff_new_chapter(AVFormatContext *s, int id, AVRational time_base, int6
#if FF_API_FORMAT_PARAMETERS
int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap)
{
- int ret;
-
if (s->oformat->priv_data_size > 0) {
s->priv_data = av_mallocz(s->oformat->priv_data_size);
if (!s->priv_data)
@@ -2756,12 +2898,70 @@ int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap)
} else
s->priv_data = NULL;
- if (s->oformat->set_parameters) {
- ret = s->oformat->set_parameters(s, ap);
- if (ret < 0)
- return ret;
+ return 0;
+}
+#endif
+
+int avformat_alloc_output_context2(AVFormatContext **avctx, AVOutputFormat *oformat,
+ const char *format, const char *filename)
+{
+ AVFormatContext *s = avformat_alloc_context();
+ int ret = 0;
+
+ *avctx = NULL;
+ if (!s)
+ goto nomem;
+
+ if (!oformat) {
+ if (format) {
+ oformat = av_guess_format(format, NULL, NULL);
+ if (!oformat) {
+ av_log(s, AV_LOG_ERROR, "Requested output format '%s' is not a suitable output format\n", format);
+ ret = AVERROR(EINVAL);
+ goto error;
+ }
+ } else {
+ oformat = av_guess_format(NULL, filename, NULL);
+ if (!oformat) {
+ ret = AVERROR(EINVAL);
+ av_log(s, AV_LOG_ERROR, "Unable to find a suitable output format for '%s'\n",
+ filename);
+ goto error;
+ }
+ }
}
+
+ s->oformat = oformat;
+ if (s->oformat->priv_data_size > 0) {
+ s->priv_data = av_mallocz(s->oformat->priv_data_size);
+ if (!s->priv_data)
+ goto nomem;
+ if (s->oformat->priv_class) {
+ *(const AVClass**)s->priv_data= s->oformat->priv_class;
+ av_opt_set_defaults(s->priv_data);
+ }
+ } else
+ s->priv_data = NULL;
+
+ if (filename)
+ av_strlcpy(s->filename, filename, sizeof(s->filename));
+ *avctx = s;
return 0;
+nomem:
+ av_log(s, AV_LOG_ERROR, "Out of memory\n");
+ ret = AVERROR(ENOMEM);
+error:
+ avformat_free_context(s);
+ return ret;
+}
+
+#if FF_API_ALLOC_OUTPUT_CONTEXT
+AVFormatContext *avformat_alloc_output_context(const char *format,
+ AVOutputFormat *oformat, const char *filename)
+{
+ AVFormatContext *avctx;
+ int ret = avformat_alloc_output_context2(&avctx, oformat, format, filename);
+ return ret < 0 ? NULL : avctx;
}
#endif
@@ -2781,7 +2981,7 @@ static int validate_codec_tag(AVFormatContext *s, AVStream *st)
for (n = 0; s->oformat->codec_tag[n]; n++) {
avctag = s->oformat->codec_tag[n];
while (avctag->id != CODEC_ID_NONE) {
- if (ff_toupper4(avctag->tag) == ff_toupper4(st->codec->codec_tag)) {
+ if (avpriv_toupper4(avctag->tag) == avpriv_toupper4(st->codec->codec_tag)) {
id = avctag->id;
if (id == st->codec->codec_id)
return 1;
@@ -2815,6 +3015,9 @@ int avformat_write_header(AVFormatContext *s, AVDictionary **options)
av_dict_copy(&tmp, *options, 0);
if ((ret = av_opt_set_dict(s, &tmp)) < 0)
goto fail;
+ if (s->priv_data && s->oformat->priv_class && *(const AVClass**)s->priv_data==s->oformat->priv_class &&
+ (ret = av_opt_set_dict(s->priv_data, &tmp)) < 0)
+ goto fail;
// some sanity checks
if (s->nb_streams == 0 && !(s->oformat->flags & AVFMT_NOSTREAMS)) {
@@ -2848,7 +3051,9 @@ int avformat_write_header(AVFormatContext *s, AVDictionary **options)
ret = AVERROR(EINVAL);
goto fail;
}
- if(av_cmp_q(st->sample_aspect_ratio, st->codec->sample_aspect_ratio)){
+ if(av_cmp_q(st->sample_aspect_ratio, st->codec->sample_aspect_ratio)
+ && FFABS(av_q2d(st->sample_aspect_ratio) - av_q2d(st->codec->sample_aspect_ratio)) > 0.004*av_q2d(st->sample_aspect_ratio)
+ ){
av_log(s, AV_LOG_ERROR, "Aspect ratio mismatch between encoder and muxer layer\n");
ret = AVERROR(EINVAL);
goto fail;
@@ -2925,7 +3130,7 @@ int avformat_write_header(AVFormatContext *s, AVDictionary **options)
ret = AVERROR_INVALIDDATA;
goto fail;
}
- av_frac_init(&st->pts, 0, 0, den);
+ frac_init(&st->pts, 0, 0, den);
}
}
@@ -2979,7 +3184,7 @@ static int compute_pkt_fields2(AVFormatContext *s, AVStream *st, AVPacket *pkt){
pkt->dts= st->pts_buffer[0];
}
- if(st->cur_dts && st->cur_dts != AV_NOPTS_VALUE && st->cur_dts >= pkt->dts){
+ if(st->cur_dts && st->cur_dts != AV_NOPTS_VALUE && ((!(s->oformat->flags & AVFMT_TS_NONSTRICT) && st->cur_dts >= pkt->dts) || st->cur_dts > pkt->dts)){
av_log(s, AV_LOG_ERROR,
"Application provided invalid, non monotonically increasing dts to muxer in stream %d: %"PRId64" >= %"PRId64"\n",
st->index, st->cur_dts, pkt->dts);
@@ -3003,11 +3208,11 @@ static int compute_pkt_fields2(AVFormatContext *s, AVStream *st, AVPacket *pkt){
likely equal to the encoder delay, but it would be better if we
had the real timestamps from the encoder */
if (frame_size >= 0 && (pkt->size || st->pts.num!=st->pts.den>>1 || st->pts.val)) {
- av_frac_add(&st->pts, (int64_t)st->time_base.den * frame_size);
+ frac_add(&st->pts, (int64_t)st->time_base.den * frame_size);
}
break;
case AVMEDIA_TYPE_VIDEO:
- av_frac_add(&st->pts, (int64_t)st->time_base.den * st->codec->time_base.num);
+ frac_add(&st->pts, (int64_t)st->time_base.den * st->codec->time_base.num);
break;
default:
break;
@@ -3023,6 +3228,9 @@ int av_write_frame(AVFormatContext *s, AVPacket *pkt)
return ret;
ret= s->oformat->write_packet(s, pkt);
+
+ if (ret >= 0)
+ s->streams[pkt->stream_index]->nb_frames++;
return ret;
}
@@ -3076,17 +3284,44 @@ static int ff_interleave_compare_dts(AVFormatContext *s, AVPacket *next, AVPacke
int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush){
AVPacketList *pktl;
- int stream_count=0;
+ int stream_count=0, noninterleaved_count=0;
+ int64_t delta_dts_max = 0;
int i;
if(pkt){
ff_interleave_add_packet(s, pkt, ff_interleave_compare_dts);
}
- for(i=0; i < s->nb_streams; i++)
- stream_count+= !!s->streams[i]->last_in_packet_buffer;
+ for(i=0; i < s->nb_streams; i++) {
+ if (s->streams[i]->last_in_packet_buffer) {
+ ++stream_count;
+ } else if(s->streams[i]->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) {
+ ++noninterleaved_count;
+ }
+ }
- if(stream_count && (s->nb_streams == stream_count || flush)){
+ if (s->nb_streams == stream_count) {
+ flush = 1;
+ } else if (!flush){
+ for(i=0; i < s->nb_streams; i++) {
+ if (s->streams[i]->last_in_packet_buffer) {
+ int64_t delta_dts =
+ av_rescale_q(s->streams[i]->last_in_packet_buffer->pkt.dts,
+ s->streams[i]->time_base,
+ AV_TIME_BASE_Q) -
+ av_rescale_q(s->packet_buffer->pkt.dts,
+ s->streams[s->packet_buffer->pkt.stream_index]->time_base,
+ AV_TIME_BASE_Q);
+ delta_dts_max= FFMAX(delta_dts_max, delta_dts);
+ }
+ }
+ if(s->nb_streams == stream_count+noninterleaved_count &&
+ delta_dts_max > 20*AV_TIME_BASE) {
+ av_log(s, AV_LOG_DEBUG, "flushing with %d noninterleaved\n", noninterleaved_count);
+ flush = 1;
+ }
+ }
+ if(stream_count && flush){
pktl= s->packet_buffer;
*out= pktl->pkt;
@@ -3113,7 +3348,7 @@ int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket *pk
* @return 1 if a packet was output, 0 if no packet could be output,
* < 0 if an error occurred
*/
-static int av_interleave_packet(AVFormatContext *s, AVPacket *out, AVPacket *in, int flush){
+static int interleave_packet(AVFormatContext *s, AVPacket *out, AVPacket *in, int flush){
if(s->oformat->interleave_packet)
return s->oformat->interleave_packet(s, out, in, flush);
else
@@ -3138,17 +3373,21 @@ int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt){
for(;;){
AVPacket opkt;
- int ret= av_interleave_packet(s, &opkt, pkt, 0);
+ int ret= interleave_packet(s, &opkt, pkt, 0);
if(ret<=0) //FIXME cleanup needed for ret<0 ?
return ret;
ret= s->oformat->write_packet(s, &opkt);
+ if (ret >= 0)
+ s->streams[opkt.stream_index]->nb_frames++;
av_free_packet(&opkt);
pkt= NULL;
if(ret<0)
return ret;
+ if(s->pb && s->pb->error)
+ return s->pb->error;
}
}
@@ -3158,23 +3397,29 @@ int av_write_trailer(AVFormatContext *s)
for(;;){
AVPacket pkt;
- ret= av_interleave_packet(s, &pkt, NULL, 1);
+ ret= interleave_packet(s, &pkt, NULL, 1);
if(ret<0) //FIXME cleanup needed for ret<0 ?
goto fail;
if(!ret)
break;
ret= s->oformat->write_packet(s, &pkt);
+ if (ret >= 0)
+ s->streams[pkt.stream_index]->nb_frames++;
av_free_packet(&pkt);
if(ret<0)
goto fail;
+ if(s->pb && s->pb->error)
+ goto fail;
}
if(s->oformat->write_trailer)
ret = s->oformat->write_trailer(s);
fail:
+ if(ret == 0)
+ ret = s->pb ? s->pb->error : 0;
for(i=0;i<s->nb_streams;i++) {
av_freep(&s->streams[i]->priv_data);
av_freep(&s->streams[i]->index_entries);
@@ -3185,6 +3430,15 @@ fail:
return ret;
}
+int av_get_output_timestamp(struct AVFormatContext *s, int stream,
+ int64_t *dts, int64_t *wall)
+{
+ if (!s->oformat || !s->oformat->get_output_timestamp)
+ return AVERROR(ENOSYS);
+ s->oformat->get_output_timestamp(s, stream, dts, wall);
+ return 0;
+}
+
void ff_program_add_stream_index(AVFormatContext *ac, int progid, unsigned int idx)
{
int i, j;
@@ -3227,8 +3481,13 @@ static void dump_metadata(void *ctx, AVDictionary *m, const char *indent)
av_log(ctx, AV_LOG_INFO, "%sMetadata:\n", indent);
while((tag=av_dict_get(m, "", tag, AV_DICT_IGNORE_SUFFIX))) {
- if(strcmp("language", tag->key))
- av_log(ctx, AV_LOG_INFO, "%s %-16s: %s\n", indent, tag->key, tag->value);
+ if(strcmp("language", tag->key)){
+ char tmp[256];
+ int i;
+ av_strlcpy(tmp, tag->value, sizeof(tmp));
+ for(i=0; i<strlen(tmp); i++) if(tmp[i]==0xd) tmp[i]=' ';
+ av_log(ctx, AV_LOG_INFO, "%s %-16s: %s\n", indent, tag->key, tmp);
+ }
}
}
}
@@ -3242,7 +3501,7 @@ static void dump_stream_format(AVFormatContext *ic, int i, int index, int is_out
int g = av_gcd(st->time_base.num, st->time_base.den);
AVDictionaryEntry *lang = av_dict_get(st->metadata, "language", NULL, 0);
avcodec_string(buf, sizeof(buf), st->codec, is_output);
- av_log(NULL, AV_LOG_INFO, " Stream #%d.%d", index, i);
+ av_log(NULL, AV_LOG_INFO, " Stream #%d:%d", index, i);
/* the pid is an important information, so we display it */
/* XXX: add a generic system */
if (flags & AVFMT_SHOW_IDS)
@@ -3258,7 +3517,7 @@ static void dump_stream_format(AVFormatContext *ic, int i, int index, int is_out
st->codec->width*st->sample_aspect_ratio.num,
st->codec->height*st->sample_aspect_ratio.den,
1024*1024);
- av_log(NULL, AV_LOG_INFO, ", PAR %d:%d DAR %d:%d",
+ av_log(NULL, AV_LOG_INFO, ", SAR %d:%d DAR %d:%d",
st->sample_aspect_ratio.num, st->sample_aspect_ratio.den,
display_aspect_ratio.num, display_aspect_ratio.den);
}
@@ -3312,7 +3571,7 @@ void av_dump_format(AVFormatContext *ic,
int is_output)
{
int i;
- uint8_t *printed = av_mallocz(ic->nb_streams);
+ uint8_t *printed = ic->nb_streams ? av_mallocz(ic->nb_streams) : NULL;
if (ic->nb_streams && !printed)
return;
@@ -3869,3 +4128,30 @@ void ff_make_absolute_url(char *buf, int size, const char *base,
}
av_strlcat(buf, rel, size);
}
+
+int64_t ff_iso8601_to_unix_time(const char *datestr)
+{
+#if HAVE_STRPTIME
+ struct tm time = {0};
+ strptime(datestr, "%Y - %m - %dT%T", &time);
+ return mktime(&time);
+#else
+ av_log(NULL, AV_LOG_WARNING, "strptime() unavailable on this system, cannot convert "
+ "the date string.\n");
+ return 0;
+#endif
+}
+
+int avformat_query_codec(AVOutputFormat *ofmt, enum CodecID codec_id, int std_compliance)
+{
+ if (ofmt) {
+ if (ofmt->query_codec)
+ return ofmt->query_codec(codec_id, std_compliance);
+ else if (ofmt->codec_tag)
+ return !!av_codec_get_tag(ofmt->codec_tag, codec_id);
+ else if (codec_id == ofmt->video_codec || codec_id == ofmt->audio_codec ||
+ codec_id == ofmt->subtitle_codec)
+ return 1;
+ }
+ return AVERROR_PATCHWELCOME;
+}
diff --git a/libavformat/vc1test.c b/libavformat/vc1test.c
index 07f3247aa3..ed72119188 100644
--- a/libavformat/vc1test.c
+++ b/libavformat/vc1test.c
@@ -2,20 +2,20 @@
* VC1 Test Bitstreams Format Demuxer
* Copyright (c) 2006, 2008 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -54,7 +54,7 @@ static int vc1t_read_header(AVFormatContext *s,
return -1;
/* init video codec */
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return -1;
@@ -92,7 +92,7 @@ static int vc1t_read_packet(AVFormatContext *s,
int keyframe = 0;
uint32_t pts;
- if(pb->eof_reached)
+ if(url_feof(pb))
return AVERROR(EIO);
frame_size = avio_rl24(pb);
@@ -110,11 +110,10 @@ static int vc1t_read_packet(AVFormatContext *s,
}
AVInputFormat ff_vc1t_demuxer = {
- "vc1test",
- NULL_IF_CONFIG_SMALL("VC-1 test bitstream format"),
- 0,
- vc1t_probe,
- vc1t_read_header,
- vc1t_read_packet,
+ .name = "vc1test",
+ .long_name = NULL_IF_CONFIG_SMALL("VC-1 test bitstream format"),
+ .read_probe = vc1t_probe,
+ .read_header = vc1t_read_header,
+ .read_packet = vc1t_read_packet,
.flags = AVFMT_GENERIC_INDEX,
};
diff --git a/libavformat/vc1testenc.c b/libavformat/vc1testenc.c
index 2b0728d248..20580fb3cf 100644
--- a/libavformat/vc1testenc.c
+++ b/libavformat/vc1testenc.c
@@ -2,20 +2,20 @@
* VC-1 test bitstreams format muxer.
* Copyright (c) 2008 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avformat.h"
@@ -82,14 +82,14 @@ static int vc1test_write_trailer(AVFormatContext *s)
}
AVOutputFormat ff_vc1t_muxer = {
- "rcv",
- NULL_IF_CONFIG_SMALL("VC-1 test bitstream"),
- "",
- "rcv",
- sizeof(RCVContext),
- CODEC_ID_NONE,
- CODEC_ID_WMV3,
- vc1test_write_header,
- vc1test_write_packet,
- vc1test_write_trailer,
+ .name = "rcv",
+ .long_name = NULL_IF_CONFIG_SMALL("VC-1 test bitstream"),
+ .mime_type = "",
+ .extensions = "rcv",
+ .priv_data_size = sizeof(RCVContext),
+ .audio_codec = CODEC_ID_NONE,
+ .video_codec = CODEC_ID_WMV3,
+ .write_header = vc1test_write_header,
+ .write_packet = vc1test_write_packet,
+ .write_trailer = vc1test_write_trailer,
};
diff --git a/libavformat/version.h b/libavformat/version.h
index 3cc1718f2b..333a3a0125 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -1,20 +1,20 @@
/*
* Version macros.
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -24,7 +24,7 @@
#include "libavutil/avutil.h"
#define LIBAVFORMAT_VERSION_MAJOR 53
-#define LIBAVFORMAT_VERSION_MINOR 2
+#define LIBAVFORMAT_VERSION_MINOR 17
#define LIBAVFORMAT_VERSION_MICRO 0
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
@@ -68,11 +68,38 @@
#ifndef FF_API_SDP_CREATE
#define FF_API_SDP_CREATE (LIBAVFORMAT_VERSION_MAJOR < 54)
#endif
+#ifndef FF_API_ALLOC_OUTPUT_CONTEXT
+#define FF_API_ALLOC_OUTPUT_CONTEXT (LIBAVFORMAT_VERSION_MAJOR < 54)
+#endif
#ifndef FF_API_FORMAT_PARAMETERS
#define FF_API_FORMAT_PARAMETERS (LIBAVFORMAT_VERSION_MAJOR < 54)
#endif
#ifndef FF_API_FLAG_RTP_HINT
#define FF_API_FLAG_RTP_HINT (LIBAVFORMAT_VERSION_MAJOR < 54)
#endif
+#ifndef FF_API_AVSTREAM_QUALITY
+#define FF_API_AVSTREAM_QUALITY (LIBAVFORMAT_VERSION_MAJOR < 54)
+#endif
+#ifndef FF_API_LOOP_INPUT
+#define FF_API_LOOP_INPUT (LIBAVFORMAT_VERSION_MAJOR < 54)
+#endif
+#ifndef FF_API_LOOP_OUTPUT
+#define FF_API_LOOP_OUTPUT (LIBAVFORMAT_VERSION_MAJOR < 54)
+#endif
+#ifndef FF_API_TIMESTAMP
+#define FF_API_TIMESTAMP (LIBAVFORMAT_VERSION_MAJOR < 54)
+#endif
+#ifndef FF_API_FILESIZE
+#define FF_API_FILESIZE (LIBAVFORMAT_VERSION_MAJOR < 54)
+#endif
+#ifndef FF_API_MUXRATE
+#define FF_API_MUXRATE (LIBAVFORMAT_VERSION_MAJOR < 54)
+#endif
+#ifndef FF_API_RTSP_URL_OPTIONS
+#define FF_API_RTSP_URL_OPTIONS (LIBAVFORMAT_VERSION_MAJOR < 54)
+#endif
+#ifndef FF_API_NEW_STREAM
+#define FF_API_NEW_STREAM (LIBAVFORMAT_VERSION_MAJOR < 54)
+#endif
#endif /* AVFORMAT_VERSION_H */
diff --git a/libavformat/voc.c b/libavformat/voc.c
index 314623ee74..53e02f9464 100644
--- a/libavformat/voc.c
+++ b/libavformat/voc.c
@@ -2,20 +2,20 @@
* Creative Voice File common data.
* Copyright (c) 2006 Aurelien Jacobs <aurel@gnuage.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/voc.h b/libavformat/voc.h
index abd8fdbfff..3f995ad31f 100644
--- a/libavformat/voc.h
+++ b/libavformat/voc.h
@@ -2,20 +2,20 @@
* Creative Voice File demuxer.
* Copyright (c) 2006 Aurelien Jacobs <aurel@gnuage.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/vocdec.c b/libavformat/vocdec.c
index eaa2f25492..6ee8d33964 100644
--- a/libavformat/vocdec.c
+++ b/libavformat/vocdec.c
@@ -2,20 +2,20 @@
* Creative Voice File demuxer.
* Copyright (c) 2006 Aurelien Jacobs <aurel@gnuage.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -52,7 +52,7 @@ static int voc_read_header(AVFormatContext *s, AVFormatParameters *ap)
return AVERROR(ENOSYS);
}
avio_skip(pb, header_size);
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
@@ -142,7 +142,7 @@ voc_get_packet(AVFormatContext *s, AVPacket *pkt, AVStream *st, int max_size)
}
}
- dec->bit_rate = dec->sample_rate * dec->bits_per_coded_sample;
+ dec->bit_rate = dec->sample_rate * dec->channels * dec->bits_per_coded_sample;
if (max_size <= 0)
max_size = 2048;
@@ -157,11 +157,11 @@ static int voc_read_packet(AVFormatContext *s, AVPacket *pkt)
}
AVInputFormat ff_voc_demuxer = {
- "voc",
- NULL_IF_CONFIG_SMALL("Creative Voice file format"),
- sizeof(VocDecContext),
- voc_probe,
- voc_read_header,
- voc_read_packet,
+ .name = "voc",
+ .long_name = NULL_IF_CONFIG_SMALL("Creative Voice file format"),
+ .priv_data_size = sizeof(VocDecContext),
+ .read_probe = voc_probe,
+ .read_header = voc_read_header,
+ .read_packet = voc_read_packet,
.codec_tag=(const AVCodecTag* const []){ff_voc_codec_tags, 0},
};
diff --git a/libavformat/vocenc.c b/libavformat/vocenc.c
index bbb69c8c01..0a9f24bdc2 100644
--- a/libavformat/vocenc.c
+++ b/libavformat/vocenc.c
@@ -2,20 +2,20 @@
* Creative Voice File muxer.
* Copyright (c) 2006 Aurelien Jacobs <aurel@gnuage.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -90,15 +90,15 @@ static int voc_write_trailer(AVFormatContext *s)
}
AVOutputFormat ff_voc_muxer = {
- "voc",
- NULL_IF_CONFIG_SMALL("Creative Voice file format"),
- "audio/x-voc",
- "voc",
- sizeof(VocEncContext),
- CODEC_ID_PCM_U8,
- CODEC_ID_NONE,
- voc_write_header,
- voc_write_packet,
- voc_write_trailer,
+ .name = "voc",
+ .long_name = NULL_IF_CONFIG_SMALL("Creative Voice file format"),
+ .mime_type = "audio/x-voc",
+ .extensions = "voc",
+ .priv_data_size = sizeof(VocEncContext),
+ .audio_codec = CODEC_ID_PCM_U8,
+ .video_codec = CODEC_ID_NONE,
+ .write_header = voc_write_header,
+ .write_packet = voc_write_packet,
+ .write_trailer = voc_write_trailer,
.codec_tag=(const AVCodecTag* const []){ff_voc_codec_tags, 0},
};
diff --git a/libavformat/vorbiscomment.c b/libavformat/vorbiscomment.c
index 56936d7666..9b38e6a791 100644
--- a/libavformat/vorbiscomment.c
+++ b/libavformat/vorbiscomment.c
@@ -2,20 +2,20 @@
* VorbisComment writer
* Copyright (c) 2009 James Darnley
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/vorbiscomment.h b/libavformat/vorbiscomment.h
index 7b82dc1c95..b147092071 100644
--- a/libavformat/vorbiscomment.h
+++ b/libavformat/vorbiscomment.h
@@ -2,20 +2,20 @@
* VorbisComment writer
* Copyright (c) 2009 James Darnley
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavformat/vqf.c b/libavformat/vqf.c
index dd02abd70a..1530128f4a 100644
--- a/libavformat/vqf.c
+++ b/libavformat/vqf.c
@@ -2,20 +2,20 @@
* VQF demuxer
* Copyright (c) 2009 Vitor Sessak
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -64,7 +64,7 @@ static void add_metadata(AVFormatContext *s, const char *tag,
static int vqf_read_header(AVFormatContext *s, AVFormatParameters *ap)
{
VqfContext *c = s->priv_data;
- AVStream *st = av_new_stream(s, 0);
+ AVStream *st = avformat_new_stream(s, NULL);
int chunk_tag;
int rate_flag = -1;
int header_size;
@@ -250,13 +250,12 @@ static int vqf_read_seek(AVFormatContext *s,
}
AVInputFormat ff_vqf_demuxer = {
- "vqf",
- NULL_IF_CONFIG_SMALL("Nippon Telegraph and Telephone Corporation (NTT) TwinVQ"),
- sizeof(VqfContext),
- vqf_probe,
- vqf_read_header,
- vqf_read_packet,
- NULL,
- vqf_read_seek,
+ .name = "vqf",
+ .long_name = NULL_IF_CONFIG_SMALL("Nippon Telegraph and Telephone Corporation (NTT) TwinVQ"),
+ .priv_data_size = sizeof(VqfContext),
+ .read_probe = vqf_probe,
+ .read_header = vqf_read_header,
+ .read_packet = vqf_read_packet,
+ .read_seek = vqf_read_seek,
.extensions = "vqf",
};
diff --git a/libavformat/wav.c b/libavformat/wav.c
index 391461044b..b690cc1a8f 100644
--- a/libavformat/wav.c
+++ b/libavformat/wav.c
@@ -6,39 +6,109 @@
* RF64 demuxer
* Copyright (c) 2009 Daniel Verkamp
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include "libavutil/avassert.h"
+#include "libavutil/dict.h"
+#include "libavutil/log.h"
#include "libavutil/mathematics.h"
+#include "libavutil/opt.h"
#include "avformat.h"
#include "avio_internal.h"
#include "pcm.h"
#include "riff.h"
+#include "avio.h"
+#include "avio_internal.h"
+#include "metadata.h"
typedef struct {
+ const AVClass *class;
int64_t data;
int64_t data_end;
int64_t minpts;
int64_t maxpts;
int last_duration;
int w64;
+ int write_bext;
+ int64_t smv_data_ofs;
+ int smv_block_size;
+ int smv_frames_per_jpeg;
+ int smv_block;
+ int smv_last_stream;
+ int smv_eof;
+ int audio_eof;
} WAVContext;
#if CONFIG_WAV_MUXER
+static inline void bwf_write_bext_string(AVFormatContext *s, const char *key, int maxlen)
+{
+ AVDictionaryEntry *tag;
+ int len = 0;
+
+ if (tag = av_dict_get(s->metadata, key, NULL, 0)) {
+ len = strlen(tag->value);
+ len = FFMIN(len, maxlen);
+ avio_write(s->pb, tag->value, len);
+ }
+
+ ffio_fill(s->pb, 0, maxlen - len);
+}
+
+static void bwf_write_bext_chunk(AVFormatContext *s)
+{
+ AVDictionaryEntry *tmp_tag;
+ uint64_t time_reference = 0;
+ int64_t bext = ff_start_tag(s->pb, "bext");
+
+ bwf_write_bext_string(s, "description", 256);
+ bwf_write_bext_string(s, "originator", 32);
+ bwf_write_bext_string(s, "originator_reference", 32);
+ bwf_write_bext_string(s, "origination_date", 10);
+ bwf_write_bext_string(s, "origination_time", 8);
+
+ if (tmp_tag = av_dict_get(s->metadata, "time_reference", NULL, 0))
+ time_reference = strtoll(tmp_tag->value, NULL, 10);
+ avio_wl64(s->pb, time_reference);
+ avio_wl16(s->pb, 1); // set version to 1
+
+ if (tmp_tag = av_dict_get(s->metadata, "umid", NULL, 0)) {
+ unsigned char umidpart_str[17] = {0};
+ int i;
+ uint64_t umidpart;
+ int len = strlen(tmp_tag->value+2);
+
+ for (i = 0; i < len/16; i++) {
+ memcpy(umidpart_str, tmp_tag->value + 2 + (i*16), 16);
+ umidpart = strtoll(umidpart_str, NULL, 16);
+ avio_wb64(s->pb, umidpart);
+ }
+ ffio_fill(s->pb, 0, 64 - i*8);
+ } else
+ ffio_fill(s->pb, 0, 64); // zero UMID
+
+ ffio_fill(s->pb, 0, 190); // Reserved
+
+ if (tmp_tag = av_dict_get(s->metadata, "coding_history", NULL, 0))
+ avio_put_str(s->pb, tmp_tag->value);
+
+ ff_end_tag(s->pb, bext);
+}
+
static int wav_write_header(AVFormatContext *s)
{
WAVContext *wav = s->priv_data;
@@ -65,6 +135,9 @@ static int wav_write_header(AVFormatContext *s)
ff_end_tag(pb, fact);
}
+ if (wav->write_bext)
+ bwf_write_bext_chunk(s);
+
av_set_pts_info(s->streams[0], 64, 1, s->streams[0]->codec->sample_rate);
wav->maxpts = wav->last_duration = 0;
wav->minpts = INT64_MAX;
@@ -125,18 +198,33 @@ static int wav_write_trailer(AVFormatContext *s)
return 0;
}
+#define OFFSET(x) offsetof(WAVContext, x)
+#define ENC AV_OPT_FLAG_ENCODING_PARAM
+static const AVOption options[] = {
+ { "write_bext", "Write BEXT chunk.", OFFSET(write_bext), AV_OPT_TYPE_INT, { 0 }, 0, 1, ENC },
+ { NULL },
+};
+
+static const AVClass wav_muxer_class = {
+ .class_name = "WAV muxer",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
AVOutputFormat ff_wav_muxer = {
- "wav",
- NULL_IF_CONFIG_SMALL("WAV format"),
- "audio/x-wav",
- "wav",
- sizeof(WAVContext),
- CODEC_ID_PCM_S16LE,
- CODEC_ID_NONE,
- wav_write_header,
- wav_write_packet,
- wav_write_trailer,
+ .name = "wav",
+ .long_name = NULL_IF_CONFIG_SMALL("WAV format"),
+ .mime_type = "audio/x-wav",
+ .extensions = "wav",
+ .priv_data_size = sizeof(WAVContext),
+ .audio_codec = CODEC_ID_PCM_S16LE,
+ .video_codec = CODEC_ID_NONE,
+ .write_header = wav_write_header,
+ .write_packet = wav_write_packet,
+ .write_trailer = wav_write_trailer,
.codec_tag= (const AVCodecTag* const []){ff_codec_wav_tags, 0},
+ .priv_class = &wav_muxer_class,
};
#endif /* CONFIG_WAV_MUXER */
@@ -156,7 +244,7 @@ static int64_t find_tag(AVIOContext *pb, uint32_t tag1)
int64_t size;
for (;;) {
- if (pb->eof_reached)
+ if (url_feof(pb))
return -1;
size = next_tag(pb, &tag);
if (tag == tag1)
@@ -186,6 +274,117 @@ static int wav_probe(AVProbeData *p)
return 0;
}
+static int wav_parse_fmt_tag(AVFormatContext *s, int64_t size, AVStream **st)
+{
+ AVIOContext *pb = s->pb;
+ int ret;
+
+ /* parse fmt header */
+ *st = avformat_new_stream(s, NULL);
+ if (!*st)
+ return AVERROR(ENOMEM);
+
+ ret = ff_get_wav_header(pb, (*st)->codec, size);
+ if (ret < 0)
+ return ret;
+ (*st)->need_parsing = AVSTREAM_PARSE_FULL;
+
+ av_set_pts_info(*st, 64, 1, (*st)->codec->sample_rate);
+
+ return 0;
+}
+
+static inline int wav_parse_bext_string(AVFormatContext *s, const char *key,
+ int length)
+{
+ char temp[257];
+ int ret;
+
+ av_assert0(length <= sizeof(temp));
+ if ((ret = avio_read(s->pb, temp, length)) < 0)
+ return ret;
+
+ temp[length] = 0;
+
+ if (strlen(temp))
+ return av_dict_set(&s->metadata, key, temp, 0);
+
+ return 0;
+}
+
+static int wav_parse_bext_tag(AVFormatContext *s, int64_t size)
+{
+ char temp[131], *coding_history;
+ int ret, x;
+ uint64_t time_reference;
+ int64_t umid_parts[8], umid_mask = 0;
+
+ if ((ret = wav_parse_bext_string(s, "description", 256)) < 0 ||
+ (ret = wav_parse_bext_string(s, "originator", 32)) < 0 ||
+ (ret = wav_parse_bext_string(s, "originator_reference", 32)) < 0 ||
+ (ret = wav_parse_bext_string(s, "origination_date", 10)) < 0 ||
+ (ret = wav_parse_bext_string(s, "origination_time", 8)) < 0)
+ return ret;
+
+ time_reference = avio_rl64(s->pb);
+ snprintf(temp, sizeof(temp), "%"PRIu64, time_reference);
+ if ((ret = av_dict_set(&s->metadata, "time_reference", temp, 0)) < 0)
+ return ret;
+
+ /* check if version is >= 1, in which case an UMID may be present */
+ if (avio_rl16(s->pb) >= 1) {
+ for (x = 0; x < 8; x++)
+ umid_mask |= umid_parts[x] = avio_rb64(s->pb);
+
+ if (umid_mask) {
+ /* the string formatting below is per SMPTE 330M-2004 Annex C */
+ if (umid_parts[4] == 0 && umid_parts[5] == 0 && umid_parts[6] == 0 && umid_parts[7] == 0) {
+ /* basic UMID */
+ snprintf(temp, sizeof(temp), "0x%016"PRIX64"%016"PRIX64"%016"PRIX64"%016"PRIX64,
+ umid_parts[0], umid_parts[1], umid_parts[2], umid_parts[3]);
+ } else {
+ /* extended UMID */
+ snprintf(temp, sizeof(temp), "0x%016"PRIX64"%016"PRIX64"%016"PRIX64"%016"PRIX64
+ "0x%016"PRIX64"%016"PRIX64"%016"PRIX64"%016"PRIX64,
+ umid_parts[0], umid_parts[1], umid_parts[2], umid_parts[3],
+ umid_parts[4], umid_parts[5], umid_parts[6], umid_parts[7]);
+ }
+
+ if ((ret = av_dict_set(&s->metadata, "umid", temp, 0)) < 0)
+ return ret;
+ }
+
+ avio_skip(s->pb, 190);
+ } else
+ avio_skip(s->pb, 254);
+
+ if (size > 602) {
+ /* CodingHistory present */
+ size -= 602;
+
+ if (!(coding_history = av_malloc(size+1)))
+ return AVERROR(ENOMEM);
+
+ if ((ret = avio_read(s->pb, coding_history, size)) < 0)
+ return ret;
+
+ coding_history[size] = 0;
+ if ((ret = av_dict_set(&s->metadata, "coding_history", coding_history,
+ AV_DICT_DONT_STRDUP_VAL)) < 0)
+ return ret;
+ }
+
+ return 0;
+}
+
+static const AVMetadataConv wav_metadata_conv[] = {
+ {"description", "comment" },
+ {"originator", "encoded_by" },
+ {"origination_date", "date" },
+ {"origination_time", "creation_time"},
+ {0},
+};
+
/* wav input */
static int wav_read_header(AVFormatContext *s,
AVFormatParameters *ap)
@@ -195,9 +394,12 @@ static int wav_read_header(AVFormatContext *s,
int rf64;
unsigned int tag;
AVIOContext *pb = s->pb;
- AVStream *st;
+ AVStream *st = NULL;
WAVContext *wav = s->priv_data;
- int ret;
+ int ret, got_fmt = 0;
+ int64_t next_tag_ofs, data_ofs = -1;
+
+ wav->smv_data_ofs = -1;
/* check RIFF header */
tag = avio_rl32(pb);
@@ -214,54 +416,116 @@ static int wav_read_header(AVFormatContext *s,
if (avio_rl32(pb) != MKTAG('d', 's', '6', '4'))
return -1;
size = avio_rl32(pb);
- if (size < 16)
+ if (size < 24)
return -1;
avio_rl64(pb); /* RIFF size */
data_size = avio_rl64(pb);
sample_count = avio_rl64(pb);
- avio_skip(pb, size - 16); /* skip rest of ds64 chunk */
+ if (data_size < 0 || sample_count < 0) {
+ av_log(s, AV_LOG_ERROR, "negative data_size and/or sample_count in "
+ "ds64: data_size = %"PRId64", sample_count = %"PRId64"\n",
+ data_size, sample_count);
+ return AVERROR_INVALIDDATA;
+ }
+ avio_skip(pb, size - 24); /* skip rest of ds64 chunk */
+
}
- /* parse fmt header */
- size = find_tag(pb, MKTAG('f', 'm', 't', ' '));
- if (size < 0)
- return -1;
- st = av_new_stream(s, 0);
- if (!st)
- return AVERROR(ENOMEM);
+ for (;;) {
+ AVStream *vst;
+ size = next_tag(pb, &tag);
+ next_tag_ofs = avio_tell(pb) + size;
- ret = ff_get_wav_header(pb, st->codec, size);
- if (ret < 0)
- return ret;
- st->need_parsing = AVSTREAM_PARSE_FULL;
+ if (url_feof(pb))
+ break;
- av_set_pts_info(st, 64, 1, st->codec->sample_rate);
+ switch (tag) {
+ case MKTAG('f', 'm', 't', ' '):
+ /* only parse the first 'fmt ' tag found */
+ if (!got_fmt && (ret = wav_parse_fmt_tag(s, size, &st) < 0)) {
+ return ret;
+ } else if (got_fmt)
+ av_log(s, AV_LOG_WARNING, "found more than one 'fmt ' tag\n");
- for (;;) {
- if (pb->eof_reached)
- return -1;
- size = next_tag(pb, &tag);
- if (tag == MKTAG('d', 'a', 't', 'a')){
+ got_fmt = 1;
+ break;
+ case MKTAG('d', 'a', 't', 'a'):
+ if (!got_fmt) {
+ av_log(s, AV_LOG_ERROR, "found no 'fmt ' tag before the 'data' tag\n");
+ return AVERROR_INVALIDDATA;
+ }
+
+ if (rf64) {
+ next_tag_ofs = wav->data_end = avio_tell(pb) + data_size;
+ } else {
+ data_size = size;
+ next_tag_ofs = wav->data_end = size ? next_tag_ofs : INT64_MAX;
+ }
+
+ data_ofs = avio_tell(pb);
+
+ /* don't look for footer metadata if we can't seek or if we don't
+ * know where the data tag ends
+ */
+ if (!pb->seekable || (!rf64 && !size))
+ goto break_loop;
+ break;
+ case MKTAG('f','a','c','t'):
+ if (!sample_count)
+ sample_count = avio_rl32(pb);
+ break;
+ case MKTAG('b','e','x','t'):
+ if ((ret = wav_parse_bext_tag(s, size)) < 0)
+ return ret;
+ break;
+ case MKTAG('S','M','V','0'):
+ // SMV file, a wav file with video appended.
+ if (size != MKTAG('0','2','0','0')) {
+ av_log(s, AV_LOG_ERROR, "Unknown SMV version found\n");
+ goto break_loop;
+ }
+ av_log(s, AV_LOG_DEBUG, "Found SMV data\n");
+ vst = av_new_stream(s, 1);
+ if (!vst)
+ return AVERROR(ENOMEM);
+ avio_r8(pb);
+ vst->codec->codec_type = AVMEDIA_TYPE_VIDEO;
+ vst->codec->codec_id = CODEC_ID_MJPEG;
+ vst->codec->width = avio_rl24(pb);
+ vst->codec->height = avio_rl24(pb);
+ size = avio_rl24(pb);
+ wav->smv_data_ofs = avio_tell(pb) + (size - 5) * 3;
+ avio_rl24(pb);
+ wav->smv_block_size = avio_rl24(pb);
+ av_set_pts_info(vst, 32, 1, avio_rl24(pb));
+ vst->duration = avio_rl24(pb);
+ avio_rl24(pb);
+ avio_rl24(pb);
+ wav->smv_frames_per_jpeg = avio_rl24(pb);
+ goto break_loop;
+ }
+
+ /* seek to next tag unless we know that we'll run into EOF */
+ if ((avio_size(pb) > 0 && next_tag_ofs >= avio_size(pb)) ||
+ avio_seek(pb, next_tag_ofs, SEEK_SET) < 0) {
break;
- }else if (tag == MKTAG('f','a','c','t') && !sample_count){
- sample_count = avio_rl32(pb);
- size -= 4;
}
- avio_skip(pb, size);
}
- if (rf64)
- size = data_size;
- if (size < 0)
- return -1;
- if (!size) {
- wav->data_end = INT64_MAX;
- } else
- wav->data_end= avio_tell(pb) + size;
+break_loop:
+ if (data_ofs < 0) {
+ av_log(s, AV_LOG_ERROR, "no 'data' tag found\n");
+ return AVERROR_INVALIDDATA;
+ }
+
+ avio_seek(pb, data_ofs, SEEK_SET);
if (!sample_count && st->codec->channels && av_get_bits_per_sample(st->codec->codec_id))
- sample_count = (size<<3) / (st->codec->channels * (uint64_t)av_get_bits_per_sample(st->codec->codec_id));
+ sample_count = (data_size<<3) / (st->codec->channels * (uint64_t)av_get_bits_per_sample(st->codec->codec_id));
if (sample_count)
st->duration = sample_count;
+
+ ff_metadata_conv_ctx(s, NULL, wav_metadata_conv);
+
return 0;
}
@@ -273,7 +537,7 @@ static int64_t find_guid(AVIOContext *pb, const uint8_t guid1[16])
uint8_t guid[16];
int64_t size;
- while (!pb->eof_reached) {
+ while (!url_feof(pb)) {
avio_read(pb, guid, 16);
size = avio_rl64(pb);
if (size <= 24)
@@ -298,6 +562,45 @@ static int wav_read_packet(AVFormatContext *s,
AVStream *st;
WAVContext *wav = s->priv_data;
+ if (wav->smv_data_ofs > 0) {
+ int64_t audio_dts, video_dts;
+smv_retry:
+ audio_dts = s->streams[0]->cur_dts;
+ video_dts = s->streams[1]->cur_dts;
+ if (audio_dts != AV_NOPTS_VALUE && video_dts != AV_NOPTS_VALUE) {
+ audio_dts = av_rescale_q(audio_dts, s->streams[0]->time_base, AV_TIME_BASE_Q);
+ video_dts = av_rescale_q(video_dts, s->streams[1]->time_base, AV_TIME_BASE_Q);
+ wav->smv_last_stream = video_dts >= audio_dts;
+ }
+ wav->smv_last_stream = !wav->smv_last_stream;
+ wav->smv_last_stream |= wav->audio_eof;
+ wav->smv_last_stream &= !wav->smv_eof;
+ if (wav->smv_last_stream) {
+ uint64_t old_pos = avio_tell(s->pb);
+ uint64_t new_pos = wav->smv_data_ofs +
+ wav->smv_block * wav->smv_block_size;
+ if (avio_seek(s->pb, new_pos, SEEK_SET) < 0) {
+ ret = AVERROR_EOF;
+ goto smv_out;
+ }
+ size = avio_rl24(s->pb);
+ ret = av_get_packet(s->pb, pkt, size);
+ if (ret < 0)
+ goto smv_out;
+ pkt->pos -= 3;
+ pkt->pts = wav->smv_block * wav->smv_frames_per_jpeg;
+ wav->smv_block++;
+ pkt->stream_index = 1;
+smv_out:
+ avio_seek(s->pb, old_pos, SEEK_SET);
+ if (ret == AVERROR_EOF) {
+ wav->smv_eof = 1;
+ goto smv_retry;
+ }
+ return ret;
+ }
+ }
+
st = s->streams[0];
left = wav->data_end - avio_tell(s->pb);
@@ -306,8 +609,12 @@ static int wav_read_packet(AVFormatContext *s,
left = find_guid(s->pb, guid_data) - 24;
else
left = find_tag(s->pb, MKTAG('d', 'a', 't', 'a'));
- if (left < 0)
+ if (left < 0) {
+ wav->audio_eof = 1;
+ if (wav->smv_data_ofs > 0 && !wav->smv_eof)
+ goto smv_retry;
return AVERROR_EOF;
+ }
wav->data_end= avio_tell(s->pb) + left;
}
@@ -329,7 +636,18 @@ static int wav_read_packet(AVFormatContext *s,
static int wav_read_seek(AVFormatContext *s,
int stream_index, int64_t timestamp, int flags)
{
+ WAVContext *wav = s->priv_data;
AVStream *st;
+ wav->smv_eof = 0;
+ wav->audio_eof = 0;
+ if (wav->smv_data_ofs > 0) {
+ int64_t smv_timestamp = timestamp;
+ if (stream_index == 0)
+ smv_timestamp = av_rescale_q(timestamp, s->streams[0]->time_base, s->streams[1]->time_base);
+ else
+ timestamp = av_rescale_q(smv_timestamp, s->streams[1]->time_base, s->streams[0]->time_base);
+ wav->smv_block = smv_timestamp / wav->smv_frames_per_jpeg;
+ }
st = s->streams[0];
switch (st->codec->codec_id) {
@@ -346,14 +664,13 @@ static int wav_read_seek(AVFormatContext *s,
}
AVInputFormat ff_wav_demuxer = {
- "wav",
- NULL_IF_CONFIG_SMALL("WAV format"),
- sizeof(WAVContext),
- wav_probe,
- wav_read_header,
- wav_read_packet,
- NULL,
- wav_read_seek,
+ .name = "wav",
+ .long_name = NULL_IF_CONFIG_SMALL("WAV format"),
+ .priv_data_size = sizeof(WAVContext),
+ .read_probe = wav_probe,
+ .read_header = wav_read_header,
+ .read_packet = wav_read_packet,
+ .read_seek = wav_read_seek,
.flags= AVFMT_GENERIC_INDEX,
.codec_tag= (const AVCodecTag* const []){ff_codec_wav_tags, 0},
};
@@ -409,7 +726,7 @@ static int w64_read_header(AVFormatContext *s, AVFormatParameters *ap)
return -1;
}
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
@@ -435,14 +752,13 @@ static int w64_read_header(AVFormatContext *s, AVFormatParameters *ap)
}
AVInputFormat ff_w64_demuxer = {
- "w64",
- NULL_IF_CONFIG_SMALL("Sony Wave64 format"),
- sizeof(WAVContext),
- w64_probe,
- w64_read_header,
- wav_read_packet,
- NULL,
- wav_read_seek,
+ .name = "w64",
+ .long_name = NULL_IF_CONFIG_SMALL("Sony Wave64 format"),
+ .priv_data_size = sizeof(WAVContext),
+ .read_probe = w64_probe,
+ .read_header = w64_read_header,
+ .read_packet = wav_read_packet,
+ .read_seek = wav_read_seek,
.flags = AVFMT_GENERIC_INDEX,
.codec_tag = (const AVCodecTag* const []){ff_codec_wav_tags, 0},
};
diff --git a/libavformat/wc3movie.c b/libavformat/wc3movie.c
index 03483de737..9190a1a035 100644
--- a/libavformat/wc3movie.c
+++ b/libavformat/wc3movie.c
@@ -2,20 +2,20 @@
* Wing Commander III Movie (.mve) File Demuxer
* Copyright (c) 2003 The ffmpeg Project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -157,13 +157,13 @@ static int wc3_read_header(AVFormatContext *s,
fourcc_tag = avio_rl32(pb);
/* chunk sizes are 16-bit aligned */
size = (avio_rb32(pb) + 1) & (~1);
- if (pb->eof_reached)
+ if (url_feof(pb))
return AVERROR(EIO);
} while (fourcc_tag != BRCH_TAG);
/* initialize the decoder streams */
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
av_set_pts_info(st, 33, 1, WC3_FRAME_FPS);
@@ -174,7 +174,7 @@ static int wc3_read_header(AVFormatContext *s,
st->codec->width = wc3->width;
st->codec->height = wc3->height;
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
av_set_pts_info(st, 33, 1, WC3_FRAME_FPS);
@@ -208,7 +208,7 @@ static int wc3_read_packet(AVFormatContext *s,
fourcc_tag = avio_rl32(pb);
/* chunk sizes are 16-bit aligned */
size = (avio_rb32(pb) + 1) & (~1);
- if (pb->eof_reached)
+ if (url_feof(pb))
return AVERROR(EIO);
switch (fourcc_tag) {
@@ -292,11 +292,11 @@ static int wc3_read_close(AVFormatContext *s)
}
AVInputFormat ff_wc3_demuxer = {
- "wc3movie",
- NULL_IF_CONFIG_SMALL("Wing Commander III movie format"),
- sizeof(Wc3DemuxContext),
- wc3_probe,
- wc3_read_header,
- wc3_read_packet,
- wc3_read_close,
+ .name = "wc3movie",
+ .long_name = NULL_IF_CONFIG_SMALL("Wing Commander III movie format"),
+ .priv_data_size = sizeof(Wc3DemuxContext),
+ .read_probe = wc3_probe,
+ .read_header = wc3_read_header,
+ .read_packet = wc3_read_packet,
+ .read_close = wc3_read_close,
};
diff --git a/libavformat/westwood.c b/libavformat/westwood.c
index 7c2b17d11c..95aba13354 100644
--- a/libavformat/westwood.c
+++ b/libavformat/westwood.c
@@ -2,20 +2,20 @@
* Westwood Studios Multimedia Formats Demuxer (VQA, AUD)
* Copyright (c) 2003 The ffmpeg Project
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -144,7 +144,7 @@ static int wsaud_read_header(AVFormatContext *s,
wsaud->audio_bits = (((header[10] & 0x2) >> 1) + 1) * 8;
/* initialize the audio decoder stream */
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
av_set_pts_info(st, 33, 1, wsaud->audio_samplerate);
@@ -221,7 +221,7 @@ static int wsvqa_read_header(AVFormatContext *s,
unsigned int chunk_size;
/* initialize the video decoder stream */
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
av_set_pts_info(st, 33, 1, VQA_FRAMERATE);
@@ -247,7 +247,7 @@ static int wsvqa_read_header(AVFormatContext *s,
/* initialize the audio decoder stream for VQA v1 or nonzero samplerate */
if (AV_RL16(&header[24]) || (AV_RL16(&header[0]) == 1 && AV_RL16(&header[2]) == 1)) {
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
av_set_pts_info(st, 33, 1, VQA_FRAMERATE);
@@ -277,10 +277,8 @@ static int wsvqa_read_header(AVFormatContext *s,
/* there are 0 or more chunks before the FINF chunk; iterate until
* FINF has been skipped and the file will be ready to be demuxed */
do {
- if (avio_read(pb, scratch, VQA_PREAMBLE_SIZE) != VQA_PREAMBLE_SIZE) {
- av_free(st->codec->extradata);
+ if (avio_read(pb, scratch, VQA_PREAMBLE_SIZE) != VQA_PREAMBLE_SIZE)
return AVERROR(EIO);
- }
chunk_tag = AV_RB32(&scratch[0]);
chunk_size = AV_RB32(&scratch[4]);
@@ -368,21 +366,21 @@ static int wsvqa_read_packet(AVFormatContext *s,
#if CONFIG_WSAUD_DEMUXER
AVInputFormat ff_wsaud_demuxer = {
- "wsaud",
- NULL_IF_CONFIG_SMALL("Westwood Studios audio format"),
- sizeof(WsAudDemuxContext),
- wsaud_probe,
- wsaud_read_header,
- wsaud_read_packet,
+ .name = "wsaud",
+ .long_name = NULL_IF_CONFIG_SMALL("Westwood Studios audio format"),
+ .priv_data_size = sizeof(WsAudDemuxContext),
+ .read_probe = wsaud_probe,
+ .read_header = wsaud_read_header,
+ .read_packet = wsaud_read_packet,
};
#endif
#if CONFIG_WSVQA_DEMUXER
AVInputFormat ff_wsvqa_demuxer = {
- "wsvqa",
- NULL_IF_CONFIG_SMALL("Westwood Studios VQA format"),
- sizeof(WsVqaDemuxContext),
- wsvqa_probe,
- wsvqa_read_header,
- wsvqa_read_packet,
+ .name = "wsvqa",
+ .long_name = NULL_IF_CONFIG_SMALL("Westwood Studios VQA format"),
+ .priv_data_size = sizeof(WsVqaDemuxContext),
+ .read_probe = wsvqa_probe,
+ .read_header = wsvqa_read_header,
+ .read_packet = wsvqa_read_packet,
};
#endif
diff --git a/libavformat/wtv.c b/libavformat/wtv.c
index cc6fc8be48..7a29309e58 100644
--- a/libavformat/wtv.c
+++ b/libavformat/wtv.c
@@ -1,1110 +1,76 @@
/*
- * Windows Television (WTV) demuxer
+ * Windows Television (WTV)
* Copyright (c) 2010-2011 Peter Ross <pross@xvid.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-/**
- * @file
- * Windows Television (WTV) demuxer
- * @author Peter Ross <pross@xvid.org>
- */
-
-#include "libavutil/intreadwrite.h"
-#include "libavutil/intfloat_readwrite.h"
-#include "libavutil/dict.h"
-#include "avformat.h"
-#include "internal.h"
-#include "riff.h"
-#include "asf.h"
-#include "mpegts.h"
-#include <strings.h>
-
-/* Macros for formating GUIDs */
-#define PRI_GUID \
- "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
-#define ARG_GUID(g) \
- g[0],g[1],g[2],g[3],g[4],g[5],g[6],g[7],g[8],g[9],g[10],g[11],g[12],g[13],g[14],g[15]
-
-#define PRI_PRETTY_GUID \
- "%08x-%04x-%04x-%02x%02x%02x%02x%02x%02x%02x%02x"
-#define ARG_PRETTY_GUID(g) \
- AV_RL32(g),AV_RL16(g+4),AV_RL16(g+6),g[8],g[9],g[10],g[11],g[12],g[13],g[14],g[15]
-#define LEN_PRETTY_GUID 34
-
-/*
- *
- * File system routines
- *
- */
-
-#define WTV_SECTOR_BITS 12
-#define WTV_SECTOR_SIZE (1 << WTV_SECTOR_BITS)
-#define WTV_BIGSECTOR_BITS 18
-
-typedef struct {
- AVIOContext *pb_filesystem; /** file system (AVFormatContext->pb) */
-
- int sector_bits; /** sector shift bits; used to convert sector number into pb_filesystem offset */
- uint32_t *sectors; /** file allocation table */
- int nb_sectors; /** number of sectors */
-
- int error;
- int64_t position;
- int64_t length;
-} WtvFile;
-
-/**
- * @return bytes read, 0 on end of file, or <0 on error
- */
-static int wtvfile_read_packet(void *opaque, uint8_t *buf, int buf_size)
-{
- WtvFile *wf = opaque;
- AVIOContext *pb = wf->pb_filesystem;
- int nread = 0;
-
- if (wf->error || pb->error)
- return -1;
- if (wf->position >= wf->length || pb->eof_reached)
- return 0;
-
- buf_size = FFMIN(buf_size, wf->length - wf->position);
- while(nread < buf_size) {
- int n;
- int remaining_in_sector = (1 << wf->sector_bits) - (wf->position & ((1 << wf->sector_bits) - 1));
- int read_request = FFMIN(buf_size - nread, remaining_in_sector);
-
- n = avio_read(pb, buf, read_request);
- if (n <= 0)
- break;
- nread += n;
- buf += n;
- wf->position += n;
- if (n == remaining_in_sector) {
- int i = wf->position >> wf->sector_bits;
- if (i >= wf->nb_sectors ||
- (wf->sectors[i] != wf->sectors[i - 1] + (1 << (wf->sector_bits - WTV_SECTOR_BITS)) &&
- avio_seek(pb, (int64_t)wf->sectors[i] << WTV_SECTOR_BITS, SEEK_SET) < 0)) {
- wf->error = 1;
- break;
- }
- }
- }
- return nread;
-}
+#include "wtv.h"
-/**
- * @return position (or file length)
- */
-static int64_t wtvfile_seek(void *opaque, int64_t offset, int whence)
-{
- WtvFile *wf = opaque;
- AVIOContext *pb = wf->pb_filesystem;
-
- if (whence == AVSEEK_SIZE)
- return wf->length;
- else if (whence == SEEK_CUR)
- offset = wf->position + offset;
- else if (whence == SEEK_END)
- offset = wf->length;
-
- wf->error = offset < 0 || offset >= wf->length ||
- avio_seek(pb, ((int64_t)wf->sectors[offset >> wf->sector_bits] << WTV_SECTOR_BITS)
- + (offset & ((1 << wf->sector_bits) - 1)), SEEK_SET) < 0;
- wf->position = offset;
- return offset;
-}
-
-/**
- * read non-zero integers (le32) from input stream
- * @param pb
- * @param[out] data destination
- * @param count maximum number of integers to read
- * @return total number of integers read
- */
-static int read_ints(AVIOContext *pb, uint32_t *data, int count)
-{
- int i, total = 0;
- for (i = 0; i < count; i++) {
- if ((data[total] = avio_rl32(pb)))
- total++;
- }
- return total;
-}
-
-/**
- * Open file
- * @param first_sector First sector
- * @param length Length of file (bytes)
- * @param depth File allocation table depth
- * @return NULL on error
- */
-static AVIOContext * wtvfile_open_sector(int first_sector, uint64_t length, int depth, AVFormatContext *s)
-{
- AVIOContext *pb;
- WtvFile *wf;
- uint8_t *buffer;
-
- if (avio_seek(s->pb, first_sector << WTV_SECTOR_BITS, SEEK_SET) < 0)
- return NULL;
-
- wf = av_mallocz(sizeof(WtvFile));
- if (!wf)
- return NULL;
-
- if (depth == 0) {
- wf->sectors = av_malloc(sizeof(uint32_t));
- if (!wf->sectors) {
- av_free(wf);
- return NULL;
- }
- wf->sectors[0] = first_sector;
- wf->nb_sectors = 1;
- wf->sector_bits = WTV_SECTOR_BITS;
- } else if (depth == 1) {
- wf->sectors = av_malloc(WTV_SECTOR_SIZE);
- if (!wf->sectors) {
- av_free(wf);
- return NULL;
- }
- wf->nb_sectors = read_ints(s->pb, wf->sectors, WTV_SECTOR_SIZE / 4);
- wf->sector_bits = length & (1ULL<<63) ? WTV_SECTOR_BITS : WTV_BIGSECTOR_BITS;
- } else if (depth == 2) {
- uint32_t sectors1[WTV_SECTOR_SIZE / 4];
- int nb_sectors1 = read_ints(s->pb, sectors1, WTV_SECTOR_SIZE / 4);
- int i;
-
- wf->sectors = av_malloc(nb_sectors1 << WTV_SECTOR_BITS);
- if (!wf->sectors) {
- av_free(wf);
- return NULL;
- }
- wf->nb_sectors = 0;
- for (i = 0; i < nb_sectors1; i++) {
- if (avio_seek(s->pb, (int64_t)sectors1[i] << WTV_SECTOR_BITS, SEEK_SET) < 0)
- break;
- wf->nb_sectors += read_ints(s->pb, wf->sectors + i * WTV_SECTOR_SIZE / 4, WTV_SECTOR_SIZE / 4);
- }
- wf->sector_bits = length & (1ULL<<63) ? WTV_SECTOR_BITS : WTV_BIGSECTOR_BITS;
- } else {
- av_log(s, AV_LOG_ERROR, "unsupported file allocation table depth (0x%x)\n", depth);
- av_free(wf);
- return NULL;
- }
-
- if (!wf->nb_sectors) {
- av_free(wf->sectors);
- av_free(wf);
- return NULL;
- }
-
- /* check length */
- length &= 0xFFFFFFFFFFFF;
- if (length > ((int64_t)wf->nb_sectors << wf->sector_bits)) {
- av_log(s, AV_LOG_WARNING, "reported file length (0x%"PRIx64") exceeds number of available sectors (0x%"PRIx64")\n", length, (int64_t)wf->nb_sectors << wf->sector_bits);
- length = (int64_t)wf->nb_sectors << wf->sector_bits;
- }
- wf->length = length;
-
- /* seek to intial sector */
- wf->position = 0;
- if (avio_seek(s->pb, (int64_t)wf->sectors[0] << WTV_SECTOR_BITS, SEEK_SET) < 0) {
- av_free(wf->sectors);
- av_free(wf);
- return NULL;
- }
-
- wf->pb_filesystem = s->pb;
- buffer = av_malloc(1 << wf->sector_bits);
- if (!buffer) {
- av_free(wf->sectors);
- av_free(wf);
- return NULL;
- }
-
- pb = avio_alloc_context(buffer, 1 << wf->sector_bits, 0, wf,
- wtvfile_read_packet, NULL, wtvfile_seek);
- if (!pb) {
- av_free(buffer);
- av_free(wf->sectors);
- av_free(wf);
- }
- return pb;
-}
-
-static const ff_asf_guid dir_entry_guid =
+/* WTV GUIDs*/
+const ff_asf_guid ff_dir_entry_guid =
{0x92,0xB7,0x74,0x91,0x59,0x70,0x70,0x44,0x88,0xDF,0x06,0x3B,0x82,0xCC,0x21,0x3D};
-
-/**
- * Open file using filename
- * @param[in] buf directory buffer
- * @param buf_size directory buffer size
- * @param[in] filename
- * @param filename_size size of filename
- * @return NULL on error
- */
-static AVIOContext * wtvfile_open2(AVFormatContext *s, const uint8_t *buf, int buf_size, const uint8_t *filename, int filename_size)
-{
- const uint8_t *buf_end = buf + buf_size;
-
- while(buf + 48 <= buf_end) {
- int dir_length, name_size, first_sector, depth;
- uint64_t file_length;
- const uint8_t *name;
- if (ff_guidcmp(buf, dir_entry_guid)) {
- av_log(s, AV_LOG_ERROR, "unknown guid "PRI_GUID", expected dir_entry_guid; "
- "remaining directory entries ignored\n", ARG_GUID(buf));
- break;
- }
- dir_length = AV_RL16(buf + 16);
- file_length = AV_RL64(buf + 24);
- name_size = 2 * AV_RL32(buf + 32);
- if (buf + 48 + name_size > buf_end) {
- av_log(s, AV_LOG_ERROR, "filename exceeds buffer size; remaining directory entries ignored\n");
- break;
- }
- first_sector = AV_RL32(buf + 40 + name_size);
- depth = AV_RL32(buf + 44 + name_size);
-
- /* compare file name; test optional null terminator */
- name = buf + 40;
- if (name_size >= filename_size &&
- !memcmp(name, filename, filename_size) &&
- (name_size < filename_size + 2 || !AV_RN16(name + filename_size)))
- return wtvfile_open_sector(first_sector, file_length, depth, s);
-
- buf += dir_length;
- }
- return 0;
-}
-
-#define wtvfile_open(s, buf, buf_size, filename) \
- wtvfile_open2(s, buf, buf_size, filename, sizeof(filename))
-
-/**
- * Close file opened with wtvfile_open_sector(), or wtv_open()
- */
-static void wtvfile_close(AVIOContext *pb)
-{
- WtvFile *wf = pb->opaque;
- av_free(wf->sectors);
- av_free(pb);
-}
-
-/*
- *
- * Main demuxer
- *
- */
-
-typedef struct {
- int seen_data;
-} WtvStream;
-
-typedef struct {
- AVIOContext *pb; /** timeline file */
- int64_t epoch;
- int64_t pts; /** pts for next data chunk */
- int64_t last_valid_pts; /** latest valid pts, used for interative seeking */
-
- /* maintain private seek index, as the AVIndexEntry->pos is relative to the
- start of the 'timeline' file, not the file system (AVFormatContext->pb) */
- AVIndexEntry *index_entries;
- int nb_index_entries;
- unsigned int index_entries_allocated_size;
-} WtvContext;
-
-typedef struct {
- enum CodecID id;
- ff_asf_guid guid;
-} AVCodecGuid;
-
-static enum CodecID ff_codec_guid_get_id(const AVCodecGuid *guids, ff_asf_guid guid)
-{
- int i;
- for (i = 0; guids[i].id != CODEC_ID_NONE; i++) {
- if (!ff_guidcmp(guids[i].guid, guid))
- return guids[i].id;
- }
- return CODEC_ID_NONE;
-}
-
-/* WTV GUIDs */
-static const ff_asf_guid wtv_guid =
+const ff_asf_guid ff_wtv_guid =
{0xB7,0xD8,0x00,0x20,0x37,0x49,0xDA,0x11,0xA6,0x4E,0x00,0x07,0xE9,0x5E,0xAD,0x8D};
-static const ff_asf_guid metadata_guid =
- {0x5A,0xFE,0xD7,0x6D,0xC8,0x1D,0x8F,0x4A,0x99,0x22,0xFA,0xB1,0x1C,0x38,0x14,0x53};
-static const ff_asf_guid timestamp_guid =
+const ff_asf_guid ff_timestamp_guid =
{0x5B,0x05,0xE6,0x1B,0x97,0xA9,0x49,0x43,0x88,0x17,0x1A,0x65,0x5A,0x29,0x8A,0x97};
-static const ff_asf_guid data_guid =
+const ff_asf_guid ff_data_guid =
{0x95,0xC3,0xD2,0xC2,0x7E,0x9A,0xDA,0x11,0x8B,0xF7,0x00,0x07,0xE9,0x5E,0xAD,0x8D};
-static const ff_asf_guid stream_guid =
+const ff_asf_guid ff_stream_guid =
{0xED,0xA4,0x13,0x23,0x2D,0xBF,0x4F,0x45,0xAD,0x8A,0xD9,0x5B,0xA7,0xF9,0x1F,0xEE};
-static const ff_asf_guid stream2_guid =
- {0xA2,0xC3,0xD2,0xC2,0x7E,0x9A,0xDA,0x11,0x8B,0xF7,0x00,0x07,0xE9,0x5E,0xAD,0x8D};
-static const ff_asf_guid EVENTID_SubtitleSpanningEvent =
- {0x48,0xC0,0xCE,0x5D,0xB9,0xD0,0x63,0x41,0x87,0x2C,0x4F,0x32,0x22,0x3B,0xE8,0x8A};
-static const ff_asf_guid EVENTID_LanguageSpanningEvent =
- {0x6D,0x66,0x92,0xE2,0x02,0x9C,0x8D,0x44,0xAA,0x8D,0x78,0x1A,0x93,0xFD,0xC3,0x95};
-static const ff_asf_guid EVENTID_AudioDescriptorSpanningEvent =
- {0x1C,0xD4,0x7B,0x10,0xDA,0xA6,0x91,0x46,0x83,0x69,0x11,0xB2,0xCD,0xAA,0x28,0x8E};
-static const ff_asf_guid EVENTID_CtxADescriptorSpanningEvent =
- {0xE6,0xA2,0xB4,0x3A,0x47,0x42,0x34,0x4B,0x89,0x6C,0x30,0xAF,0xA5,0xD2,0x1C,0x24};
-static const ff_asf_guid EVENTID_CSDescriptorSpanningEvent =
- {0xD9,0x79,0xE7,0xEf,0xF0,0x97,0x86,0x47,0x80,0x0D,0x95,0xCF,0x50,0x5D,0xDC,0x66};
-static const ff_asf_guid EVENTID_DVBScramblingControlSpanningEvent =
- {0xC4,0xE1,0xD4,0x4B,0xA1,0x90,0x09,0x41,0x82,0x36,0x27,0xF0,0x0E,0x7D,0xCC,0x5B};
-static const ff_asf_guid EVENTID_StreamIDSpanningEvent =
- {0x68,0xAB,0xF1,0xCA,0x53,0xE1,0x41,0x4D,0xA6,0xB3,0xA7,0xC9,0x98,0xDB,0x75,0xEE};
-static const ff_asf_guid EVENTID_TeletextSpanningEvent =
- {0x50,0xD9,0x99,0x95,0x33,0x5F,0x17,0x46,0xAF,0x7C,0x1E,0x54,0xB5,0x10,0xDA,0xA3};
-static const ff_asf_guid EVENTID_AudioTypeSpanningEvent =
- {0xBE,0xBF,0x1C,0x50,0x49,0xB8,0xCE,0x42,0x9B,0xE9,0x3D,0xB8,0x69,0xFB,0x82,0xB3};
-
-/* Windows media GUIDs */
+const ff_asf_guid ff_mediatype_audio =
+ {'a','u','d','s',FF_MEDIASUBTYPE_BASE_GUID};
+const ff_asf_guid ff_mediatype_video =
+ {'v','i','d','s',FF_MEDIASUBTYPE_BASE_GUID};
+const ff_asf_guid ff_format_none =
+ {0xD6,0x17,0x64,0x0F,0x18,0xC3,0xD0,0x11,0xA4,0x3F,0x00,0xA0,0xC9,0x22,0x31,0x96};
-#define MEDIASUBTYPE_BASE_GUID \
- 0x00,0x00,0x10,0x00,0x80,0x00,0x00,0xAA,0x00,0x38,0x9B,0x71
+/* declare utf16le strings */
+#define _ , 0,
+const uint8_t ff_timeline_le16[] =
+ {'t'_'i'_'m'_'e'_'l'_'i'_'n'_'e', 0};
+const uint8_t ff_timeline_table_0_entries_Events_le16[] =
+ {'t'_'i'_'m'_'e'_'l'_'i'_'n'_'e'_'.'_'t'_'a'_'b'_'l'_'e'_'.'_'0'_'.'_'e'_'n'_'t'_'r'_'i'_'e'_'s'_'.'_'E'_'v'_'e'_'n'_'t'_'s', 0};
+const uint8_t ff_table_0_entries_legacy_attrib_le16[] =
+ {'t'_'a'_'b'_'l'_'e'_'.'_'0'_'.'_'e'_'n'_'t'_'r'_'i'_'e'_'s'_'.'_'l'_'e'_'g'_'a'_'c'_'y'_'_'_'a'_'t'_'t'_'r'_'i'_'b', 0};
+const uint8_t ff_table_0_entries_time_le16[] =
+ {'t'_'a'_'b'_'l'_'e'_'.'_'0'_'.'_'e'_'n'_'t'_'r'_'i'_'e'_'s'_'.'_'t'_'i'_'m'_'e', 0};
+#undef _
-/* Media types */
-static const ff_asf_guid mediatype_audio =
- {'a','u','d','s',MEDIASUBTYPE_BASE_GUID};
-static const ff_asf_guid mediatype_video =
- {'v','i','d','s',MEDIASUBTYPE_BASE_GUID};
-static const ff_asf_guid mediasubtype_mpeg1payload =
- {0x81,0xEB,0x36,0xE4,0x4F,0x52,0xCE,0x11,0x9F,0x53,0x00,0x20,0xAF,0x0B,0xA7,0x70};
-static const ff_asf_guid mediatype_mpeg2_sections =
- {0x6C,0x17,0x5F,0x45,0x06,0x4B,0xCE,0x47,0x9A,0xEF,0x8C,0xAE,0xF7,0x3D,0xF7,0xB5};
-static const ff_asf_guid mediatype_mpeg2_pes =
- {0x20,0x80,0x6D,0xE0,0x46,0xDB,0xCF,0x11,0xB4,0xD1,0x00,0x80,0x5F,0x6C,0xBB,0xEA};
-static const ff_asf_guid mediatype_mstvcaption =
- {0x89,0x8A,0x8B,0xB8,0x49,0xB0,0x80,0x4C,0xAD,0xCF,0x58,0x98,0x98,0x5E,0x22,0xC1};
+const ff_asf_guid ff_DSATTRIB_TRANSPORT_PROPERTIES =
+ {0x12,0xF6,0x22,0xB6,0xAD,0x47,0x71,0x46,0xAD,0x6C,0x05,0xA9,0x8E,0x65,0xDE,0x3A};
+const ff_asf_guid ff_metadata_guid =
+ {0x5A,0xFE,0xD7,0x6D,0xC8,0x1D,0x8F,0x4A,0x99,0x22,0xFA,0xB1,0x1C,0x38,0x14,0x53};
+const ff_asf_guid ff_stream2_guid =
+ {0xA2,0xC3,0xD2,0xC2,0x7E,0x9A,0xDA,0x11,0x8B,0xF7,0x00,0x07,0xE9,0x5E,0xAD,0x8D};
/* Media subtypes */
-static const ff_asf_guid mediasubtype_cpfilters_processed =
+const ff_asf_guid ff_mediasubtype_cpfilters_processed =
{0x28,0xBD,0xAD,0x46,0xD0,0x6F,0x96,0x47,0x93,0xB2,0x15,0x5C,0x51,0xDC,0x04,0x8D};
-static const ff_asf_guid mediasubtype_dvb_subtitle =
- {0xC3,0xCB,0xFF,0x34,0xB3,0xD5,0x71,0x41,0x90,0x02,0xD4,0xC6,0x03,0x01,0x69,0x7F};
-static const ff_asf_guid mediasubtype_teletext =
- {0xE3,0x76,0x2A,0xF7,0x0A,0xEB,0xD0,0x11,0xAC,0xE4,0x00,0x00,0xC0,0xCC,0x16,0xBA};
-static const ff_asf_guid mediasubtype_dtvccdata =
- {0xAA,0xDD,0x2A,0xF5,0xF0,0x36,0xF5,0x43,0x95,0xEA,0x6D,0x86,0x64,0x84,0x26,0x2A};
-static const ff_asf_guid mediasubtype_mpeg2_sections =
- {0x79,0x85,0x9F,0x4A,0xF8,0x6B,0x92,0x43,0x8A,0x6D,0xD2,0xDD,0x09,0xFA,0x78,0x61};
/* Formats */
-static const ff_asf_guid format_cpfilters_processed =
+const ff_asf_guid ff_format_cpfilters_processed =
{0x6F,0xB3,0x39,0x67,0x5F,0x1D,0xC2,0x4A,0x81,0x92,0x28,0xBB,0x0E,0x73,0xD1,0x6A};
-static const ff_asf_guid format_waveformatex =
+const ff_asf_guid ff_format_waveformatex =
{0x81,0x9F,0x58,0x05,0x56,0xC3,0xCE,0x11,0xBF,0x01,0x00,0xAA,0x00,0x55,0x59,0x5A};
-static const ff_asf_guid format_videoinfo2 =
- {0xA0,0x76,0x2A,0xF7,0x0A,0xEB,0xD0,0x11,0xAC,0xE4,0x00,0x00,0xC0,0xCC,0x16,0xBA};
-static const ff_asf_guid format_mpeg2_video =
+const ff_asf_guid ff_format_mpeg2_video =
{0xE3,0x80,0x6D,0xE0,0x46,0xDB,0xCF,0x11,0xB4,0xD1,0x00,0x80,0x5F,0x6C,0xBB,0xEA};
-static const ff_asf_guid format_none =
- {0xD6,0x17,0x64,0x0F,0x18,0xC3,0xD0,0x11,0xA4,0x3F,0x00,0xA0,0xC9,0x22,0x31,0x96};
-static const AVCodecGuid video_guids[] = {
+const AVCodecGuid ff_video_guids[] = {
{CODEC_ID_MPEG2VIDEO, {0x26,0x80,0x6D,0xE0,0x46,0xDB,0xCF,0x11,0xB4,0xD1,0x00,0x80,0x5F,0x6C,0xBB,0xEA}},
{CODEC_ID_NONE}
};
-
-static const AVCodecGuid audio_guids[] = {
- {CODEC_ID_AC3, {0x2C,0x80,0x6D,0xE0,0x46,0xDB,0xCF,0x11,0xB4,0xD1,0x00,0x80,0x5F,0x6C,0xBB,0xEA}},
- {CODEC_ID_EAC3, {0xAF,0x87,0xFB,0xA7,0x02,0x2D,0xFB,0x42,0xA4,0xD4,0x05,0xCD,0x93,0x84,0x3B,0xDD}},
- {CODEC_ID_MP2, {0x2B,0x80,0x6D,0xE0,0x46,0xDB,0xCF,0x11,0xB4,0xD1,0x00,0x80,0x5F,0x6C,0xBB,0xEA}},
- {CODEC_ID_NONE}
-};
-
-static int read_probe(AVProbeData *p)
-{
- return ff_guidcmp(p->buf, wtv_guid) ? 0 : AVPROBE_SCORE_MAX;
-}
-
-/**
- * Convert win32 FILETIME to ISO-8601 string
- */
-static void filetime_to_iso8601(char *buf, int buf_size, int64_t value)
-{
- time_t t = (value / 10000000LL) - 11644473600LL;
- strftime(buf, buf_size, "%Y-%m-%d %H:%M:%S", gmtime(&t));
-}
-
-/**
- * Convert crazy time (100ns since 1 Jan 0001) to ISO-8601 string
- */
-static void crazytime_to_iso8601(char *buf, int buf_size, int64_t value)
-{
- time_t t = (value / 10000000LL) - 719162LL*86400LL;
- strftime(buf, buf_size, "%Y-%m-%d %H:%M:%S", gmtime(&t));
-}
-
-/**
- * Convert OLE DATE to ISO-8601 string
- */
-static void oledate_to_iso8601(char *buf, int buf_size, int64_t value)
-{
- time_t t = 631112400LL + 86400*av_int2dbl(value);
- strftime(buf, buf_size, "%Y-%m-%d %H:%M:%S", gmtime(&t));
-}
-
-static void get_attachment(AVFormatContext *s, AVIOContext *pb, int length)
-{
- char mime[1024];
- char description[1024];
- unsigned int filesize;
- AVStream *st;
- int64_t pos = avio_tell(pb);
-
- avio_get_str16le(pb, INT_MAX, mime, sizeof(mime));
- if (strcmp(mime, "image/jpeg"))
- goto done;
-
- avio_r8(pb);
- avio_get_str16le(pb, INT_MAX, description, sizeof(description));
- filesize = avio_rl32(pb);
- if (!filesize)
- goto done;
-
- st = av_new_stream(s, 0);
- if (!st)
- goto done;
- av_dict_set(&st->metadata, "title", description, 0);
- st->codec->codec_id = CODEC_ID_MJPEG;
- st->codec->codec_type = AVMEDIA_TYPE_ATTACHMENT;
- st->codec->extradata = av_mallocz(filesize);
- if (!st->codec->extradata)
- goto done;
- st->codec->extradata_size = filesize;
- avio_read(pb, st->codec->extradata, filesize);
-done:
- avio_seek(pb, pos + length, SEEK_SET);
-}
-
-static void get_tag(AVFormatContext *s, AVIOContext *pb, const char *key, int type, int length)
-{
- int buf_size = FFMAX(2*length, LEN_PRETTY_GUID) + 1;
- char *buf = av_malloc(buf_size);
- if (!buf)
- return;
-
- if (type == 0 && length == 4) {
- snprintf(buf, buf_size, "%"PRIi32, avio_rl32(pb));
- } else if (type == 1) {
- avio_get_str16le(pb, length, buf, buf_size);
- if (!strlen(buf)) {
- av_free(buf);
- return;
- }
- } else if (type == 3 && length == 4) {
- strcpy(buf, avio_rl32(pb) ? "true" : "false");
- } else if (type == 4 && length == 8) {
- int64_t num = avio_rl64(pb);
- if (!strcmp(key, "WM/EncodingTime") ||
- !strcmp(key, "WM/MediaOriginalBroadcastDateTime"))
- filetime_to_iso8601(buf, buf_size, num);
- else if (!strcmp(key, "WM/WMRVEncodeTime") ||
- !strcmp(key, "WM/WMRVEndTime"))
- crazytime_to_iso8601(buf, buf_size, num);
- else if (!strcmp(key, "WM/WMRVExpirationDate"))
- oledate_to_iso8601(buf, buf_size, num);
- else if (!strcmp(key, "WM/WMRVBitrate"))
- snprintf(buf, buf_size, "%f", av_int2dbl(num));
- else
- snprintf(buf, buf_size, "%"PRIi64, num);
- } else if (type == 5 && length == 2) {
- snprintf(buf, buf_size, "%"PRIi16, avio_rl16(pb));
- } else if (type == 6 && length == 16) {
- ff_asf_guid guid;
- avio_read(pb, guid, 16);
- snprintf(buf, buf_size, PRI_PRETTY_GUID, ARG_PRETTY_GUID(guid));
- } else if (type == 2 && !strcmp(key, "WM/Picture")) {
- get_attachment(s, pb, length);
- av_freep(&buf);
- return;
- } else {
- av_freep(&buf);
- av_log(s, AV_LOG_WARNING, "unsupported metadata entry; key:%s, type:%d, length:0x%x\n", key, type, length);
- avio_skip(pb, length);
- return;
- }
-
- av_dict_set(&s->metadata, key, buf, 0);
- av_freep(&buf);
-}
-
-/**
- * Parse metadata entries
- */
-static void parse_legacy_attrib(AVFormatContext *s, AVIOContext *pb)
-{
- ff_asf_guid guid;
- int length, type;
- while(!pb->eof_reached) {
- char key[1024];
- ff_get_guid(pb, &guid);
- type = avio_rl32(pb);
- length = avio_rl32(pb);
- if (!length)
- break;
- if (ff_guidcmp(&guid, metadata_guid)) {
- av_log(s, AV_LOG_WARNING, "unknown guid "PRI_GUID", expected metadata_guid; "
- "remaining metadata entries ignored\n", ARG_GUID(guid));
- break;
- }
- avio_get_str16le(pb, INT_MAX, key, sizeof(key));
- get_tag(s, pb, key, type, length);
- }
-
- ff_metadata_conv(&s->metadata, NULL, ff_asf_metadata_conv);
-}
-
-/**
- * parse VIDEOINFOHEADER2 structure
- * @return bytes consumed
- */
-static int parse_videoinfoheader2(AVFormatContext *s, AVStream *st)
-{
- WtvContext *wtv = s->priv_data;
- AVIOContext *pb = wtv->pb;
-
- avio_skip(pb, 72); // picture aspect ratio is unreliable
- ff_get_bmp_header(pb, st);
-
- return 72 + 40;
-}
-
-/**
- * Parse MPEG1WAVEFORMATEX extradata structure
- */
-static void parse_mpeg1waveformatex(AVStream *st)
-{
- /* fwHeadLayer */
- switch (AV_RL16(st->codec->extradata)) {
- case 0x0001 : st->codec->codec_id = CODEC_ID_MP1; break;
- case 0x0002 : st->codec->codec_id = CODEC_ID_MP2; break;
- case 0x0004 : st->codec->codec_id = CODEC_ID_MP3; break;
- }
-
- st->codec->bit_rate = AV_RL32(st->codec->extradata + 2); /* dwHeadBitrate */
-
- /* dwHeadMode */
- switch (AV_RL16(st->codec->extradata + 6)) {
- case 1 : case 2 : case 4 : st->codec->channels = 2; break;
- case 8 : st->codec->channels = 1; break;
- }
-}
-
-/**
- * Initialise stream
- * @param st Stream to initialise, or NULL to create and initialise new stream
- * @return NULL on error
- */
-static AVStream * new_stream(AVFormatContext *s, AVStream *st, int sid, int codec_type)
-{
- if (st) {
- if (st->codec->extradata) {
- av_freep(&st->codec->extradata);
- st->codec->extradata_size = 0;
- }
- } else {
- WtvStream *wst = av_mallocz(sizeof(WtvStream));
- if (!wst)
- return NULL;
- st = av_new_stream(s, sid);
- if (!st)
- return NULL;
- st->priv_data = wst;
- }
- st->codec->codec_type = codec_type;
- st->need_parsing = AVSTREAM_PARSE_FULL;
- av_set_pts_info(st, 64, 1, 10000000);
- return st;
-}
-
-/**
- * parse Media Type structure and populate stream
- * @param st Stream, or NULL to create new stream
- * @param mediatype Mediatype GUID
- * @param subtype Subtype GUID
- * @param formattype Format GUID
- * @param size Size of format buffer
- * @return NULL on error
- */
-static AVStream * parse_media_type(AVFormatContext *s, AVStream *st, int sid,
- ff_asf_guid mediatype, ff_asf_guid subtype,
- ff_asf_guid formattype, int size)
-{
- WtvContext *wtv = s->priv_data;
- AVIOContext *pb = wtv->pb;
- if (!ff_guidcmp(subtype, mediasubtype_cpfilters_processed) &&
- !ff_guidcmp(formattype, format_cpfilters_processed)) {
- ff_asf_guid actual_subtype;
- ff_asf_guid actual_formattype;
-
- if (size < 32) {
- av_log(s, AV_LOG_WARNING, "format buffer size underflow\n");
- avio_skip(pb, size);
- return NULL;
- }
-
- avio_skip(pb, size - 32);
- ff_get_guid(pb, &actual_subtype);
- ff_get_guid(pb, &actual_formattype);
- avio_seek(pb, -size, SEEK_CUR);
-
- st = parse_media_type(s, st, sid, mediatype, actual_subtype, actual_formattype, size - 32);
- avio_skip(pb, 32);
- return st;
- } else if (!ff_guidcmp(mediatype, mediatype_audio)) {
- st = new_stream(s, st, sid, AVMEDIA_TYPE_AUDIO);
- if (!st)
- return NULL;
- if (!ff_guidcmp(formattype, format_waveformatex)) {
- int ret = ff_get_wav_header(pb, st->codec, size);
- if (ret < 0)
- return NULL;
- } else {
- if (ff_guidcmp(formattype, format_none))
- av_log(s, AV_LOG_WARNING, "unknown formattype:"PRI_GUID"\n", ARG_GUID(formattype));
- avio_skip(pb, size);
- }
-
- if (!memcmp(subtype + 4, (const uint8_t[]){MEDIASUBTYPE_BASE_GUID}, 12)) {
- st->codec->codec_id = ff_wav_codec_get_id(AV_RL32(subtype), st->codec->bits_per_coded_sample);
- } else if (!ff_guidcmp(subtype, mediasubtype_mpeg1payload)) {
- if (st->codec->extradata && st->codec->extradata_size >= 22)
- parse_mpeg1waveformatex(st);
- else
- av_log(s, AV_LOG_WARNING, "MPEG1WAVEFORMATEX underflow\n");
- } else {
- st->codec->codec_id = ff_codec_guid_get_id(audio_guids, subtype);
- if (st->codec->codec_id == CODEC_ID_NONE)
- av_log(s, AV_LOG_WARNING, "unknown subtype:"PRI_GUID"\n", ARG_GUID(subtype));
- }
- return st;
- } else if (!ff_guidcmp(mediatype, mediatype_video)) {
- st = new_stream(s, st, sid, AVMEDIA_TYPE_VIDEO);
- if (!st)
- return NULL;
- if (!ff_guidcmp(formattype, format_videoinfo2)) {
- int consumed = parse_videoinfoheader2(s, st);
- avio_skip(pb, FFMAX(size - consumed, 0));
- } else if (!ff_guidcmp(formattype, format_mpeg2_video)) {
- int consumed = parse_videoinfoheader2(s, st);
- avio_skip(pb, FFMAX(size - consumed, 0));
- } else {
- if (ff_guidcmp(formattype, format_none))
- av_log(s, AV_LOG_WARNING, "unknown formattype:"PRI_GUID"\n", ARG_GUID(formattype));
- avio_skip(pb, size);
- }
-
- if (!memcmp(subtype + 4, (const uint8_t[]){MEDIASUBTYPE_BASE_GUID}, 12)) {
- st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, AV_RL32(subtype));
- } else {
- st->codec->codec_id = ff_codec_guid_get_id(video_guids, subtype);
- }
- if (st->codec->codec_id == CODEC_ID_NONE)
- av_log(s, AV_LOG_WARNING, "unknown subtype:"PRI_GUID"\n", ARG_GUID(subtype));
- return st;
- } else if (!ff_guidcmp(mediatype, mediatype_mpeg2_pes) &&
- !ff_guidcmp(subtype, mediasubtype_dvb_subtitle)) {
- st = new_stream(s, st, sid, AVMEDIA_TYPE_SUBTITLE);
- if (!st)
- return NULL;
- if (ff_guidcmp(formattype, format_none))
- av_log(s, AV_LOG_WARNING, "unknown formattype:"PRI_GUID"\n", ARG_GUID(formattype));
- avio_skip(pb, size);
- st->codec->codec_id = CODEC_ID_DVB_SUBTITLE;
- return st;
- } else if (!ff_guidcmp(mediatype, mediatype_mstvcaption) &&
- (!ff_guidcmp(subtype, mediasubtype_teletext) || !ff_guidcmp(subtype, mediasubtype_dtvccdata))) {
- st = new_stream(s, st, sid, AVMEDIA_TYPE_SUBTITLE);
- if (!st)
- return NULL;
- if (ff_guidcmp(formattype, format_none))
- av_log(s, AV_LOG_WARNING, "unknown formattype:"PRI_GUID"\n", ARG_GUID(formattype));
- avio_skip(pb, size);
- st->codec->codec_id = CODEC_ID_DVB_TELETEXT;
- return st;
- } else if (!ff_guidcmp(mediatype, mediatype_mpeg2_sections) &&
- !ff_guidcmp(subtype, mediasubtype_mpeg2_sections)) {
- if (ff_guidcmp(formattype, format_none))
- av_log(s, AV_LOG_WARNING, "unknown formattype:"PRI_GUID"\n", ARG_GUID(formattype));
- avio_skip(pb, size);
- return NULL;
- }
-
- av_log(s, AV_LOG_WARNING, "unknown media type, mediatype:"PRI_GUID
- ", subtype:"PRI_GUID", formattype:"PRI_GUID"\n",
- ARG_GUID(mediatype), ARG_GUID(subtype), ARG_GUID(formattype));
- avio_skip(pb, size);
- return NULL;
-}
-
-enum {
- SEEK_TO_DATA = 0,
- SEEK_TO_PTS,
-};
-
-/**
- * Parse WTV chunks
- * @param mode SEEK_TO_DATA or SEEK_TO_PTS
- * @param seekts timestamp
- * @param[out] len_ptr Length of data chunk
- * @return stream index of data chunk, or <0 on error
- */
-static int parse_chunks(AVFormatContext *s, int mode, int64_t seekts, int *len_ptr)
-{
- WtvContext *wtv = s->priv_data;
- AVIOContext *pb = wtv->pb;
- while (!pb->eof_reached) {
- ff_asf_guid g;
- int len, sid, consumed;
-
- ff_get_guid(pb, &g);
- len = avio_rl32(pb);
- if (len < 32)
- break;
- sid = avio_rl32(pb) & 0x7FFF;
- avio_skip(pb, 8);
- consumed = 32;
-
- if (!ff_guidcmp(g, stream_guid)) {
- if (ff_find_stream_index(s, sid) < 0) {
- ff_asf_guid mediatype, subtype, formattype;
- int size;
- avio_skip(pb, 28);
- ff_get_guid(pb, &mediatype);
- ff_get_guid(pb, &subtype);
- avio_skip(pb, 12);
- ff_get_guid(pb, &formattype);
- size = avio_rl32(pb);
- parse_media_type(s, 0, sid, mediatype, subtype, formattype, size);
- consumed += 92 + size;
- }
- } else if (!ff_guidcmp(g, stream2_guid)) {
- int stream_index = ff_find_stream_index(s, sid);
- if (stream_index >= 0 && !((WtvStream*)s->streams[stream_index]->priv_data)->seen_data) {
- ff_asf_guid mediatype, subtype, formattype;
- int size;
- avio_skip(pb, 12);
- ff_get_guid(pb, &mediatype);
- ff_get_guid(pb, &subtype);
- avio_skip(pb, 12);
- ff_get_guid(pb, &formattype);
- size = avio_rl32(pb);
- parse_media_type(s, s->streams[stream_index], sid, mediatype, subtype, formattype, size);
- consumed += 76 + size;
- }
- } else if (!ff_guidcmp(g, EVENTID_AudioDescriptorSpanningEvent) ||
- !ff_guidcmp(g, EVENTID_CtxADescriptorSpanningEvent) ||
- !ff_guidcmp(g, EVENTID_CSDescriptorSpanningEvent) ||
- !ff_guidcmp(g, EVENTID_StreamIDSpanningEvent) ||
- !ff_guidcmp(g, EVENTID_SubtitleSpanningEvent) ||
- !ff_guidcmp(g, EVENTID_TeletextSpanningEvent)) {
- int stream_index = ff_find_stream_index(s, sid);
- if (stream_index >= 0) {
- AVStream *st = s->streams[stream_index];
- uint8_t buf[258];
- const uint8_t *pbuf = buf;
- int buf_size;
-
- avio_skip(pb, 8);
- consumed += 8;
- if (!ff_guidcmp(g, EVENTID_CtxADescriptorSpanningEvent) ||
- !ff_guidcmp(g, EVENTID_CSDescriptorSpanningEvent)) {
- avio_skip(pb, 6);
- consumed += 6;
- }
-
- buf_size = FFMIN(len - consumed, sizeof(buf));
- avio_read(pb, buf, buf_size);
- consumed += buf_size;
- ff_parse_mpeg2_descriptor(s, st, 0, &pbuf, buf + buf_size, 0, 0, 0, 0);
- }
- } else if (!ff_guidcmp(g, EVENTID_AudioTypeSpanningEvent)) {
- int stream_index = ff_find_stream_index(s, sid);
- if (stream_index >= 0) {
- AVStream *st = s->streams[stream_index];
- int audio_type;
- avio_skip(pb, 8);
- audio_type = avio_r8(pb);
- if (audio_type == 2)
- st->disposition |= AV_DISPOSITION_HEARING_IMPAIRED;
- else if (audio_type == 3)
- st->disposition |= AV_DISPOSITION_VISUAL_IMPAIRED;
- consumed += 9;
- }
- } else if (!ff_guidcmp(g, EVENTID_DVBScramblingControlSpanningEvent)) {
- int stream_index = ff_find_stream_index(s, sid);
- if (stream_index >= 0) {
- avio_skip(pb, 12);
- if (avio_rl32(pb))
- av_log(s, AV_LOG_WARNING, "DVB scrambled stream detected (st:%d), decoding will likely fail\n", stream_index);
- consumed += 16;
- }
- } else if (!ff_guidcmp(g, EVENTID_LanguageSpanningEvent)) {
- int stream_index = ff_find_stream_index(s, sid);
- if (stream_index >= 0) {
- AVStream *st = s->streams[stream_index];
- uint8_t language[4];
- avio_skip(pb, 12);
- avio_read(pb, language, 3);
- if (language[0]) {
- language[3] = 0;
- av_dict_set(&st->metadata, "language", language, 0);
- if (!strcmp(language, "nar") || !strcmp(language, "NAR"))
- st->disposition |= AV_DISPOSITION_VISUAL_IMPAIRED;
- }
- consumed += 15;
- }
- } else if (!ff_guidcmp(g, timestamp_guid)) {
- int stream_index = ff_find_stream_index(s, sid);
- if (stream_index >= 0) {
- avio_skip(pb, 8);
- wtv->pts = avio_rl64(pb);
- consumed += 16;
- if (wtv->pts == -1)
- wtv->pts = AV_NOPTS_VALUE;
- else {
- wtv->last_valid_pts = wtv->pts;
- if (wtv->epoch == AV_NOPTS_VALUE || wtv->pts < wtv->epoch)
- wtv->epoch = wtv->pts;
- if (mode == SEEK_TO_PTS && wtv->pts >= seekts) {
-#define WTV_PAD8(x) (((x) + 7) & ~7)
- avio_skip(pb, WTV_PAD8(len) - consumed);
- return 0;
- }
- }
- }
- } else if (!ff_guidcmp(g, data_guid)) {
- int stream_index = ff_find_stream_index(s, sid);
- if (mode == SEEK_TO_DATA && stream_index >= 0 && len > 32) {
- WtvStream *wst = s->streams[stream_index]->priv_data;
- wst->seen_data = 1;
- if (len_ptr) {
- *len_ptr = len;
- }
- return stream_index;
- }
- } else if (
- !ff_guidcmp(g, /* DSATTRIB_CAPTURE_STREAMTIME */ (const ff_asf_guid){0x14,0x56,0x1A,0x0C,0xCD,0x30,0x40,0x4F,0xBC,0xBF,0xD0,0x3E,0x52,0x30,0x62,0x07}) ||
- !ff_guidcmp(g, /* DSATTRIB_PicSampleSeq */ (const ff_asf_guid){0x02,0xAE,0x5B,0x2F,0x8F,0x7B,0x60,0x4F,0x82,0xD6,0xE4,0xEA,0x2F,0x1F,0x4C,0x99}) ||
- !ff_guidcmp(g, /* DSATTRIB_TRANSPORT_PROPERTIES */ (const ff_asf_guid){0x12,0xF6,0x22,0xB6,0xAD,0x47,0x71,0x46,0xAD,0x6C,0x05,0xA9,0x8E,0x65,0xDE,0x3A}) ||
- !ff_guidcmp(g, /* dvr_ms_vid_frame_rep_data */ (const ff_asf_guid){0xCC,0x32,0x64,0xDD,0x29,0xE2,0xDB,0x40,0x80,0xF6,0xD2,0x63,0x28,0xD2,0x76,0x1F}) ||
- !ff_guidcmp(g, /* EVENTID_ChannelChangeSpanningEvent */ (const ff_asf_guid){0xE5,0xC5,0x67,0x90,0x5C,0x4C,0x05,0x42,0x86,0xC8,0x7A,0xFE,0x20,0xFE,0x1E,0xFA}) ||
- !ff_guidcmp(g, /* EVENTID_ChannelInfoSpanningEvent */ (const ff_asf_guid){0x80,0x6D,0xF3,0x41,0x32,0x41,0xC2,0x4C,0xB1,0x21,0x01,0xA4,0x32,0x19,0xD8,0x1B}) ||
- !ff_guidcmp(g, /* EVENTID_ChannelTypeSpanningEvent */ (const ff_asf_guid){0x51,0x1D,0xAB,0x72,0xD2,0x87,0x9B,0x48,0xBA,0x11,0x0E,0x08,0xDC,0x21,0x02,0x43}) ||
- !ff_guidcmp(g, /* EVENTID_PIDListSpanningEvent */ (const ff_asf_guid){0x65,0x8F,0xFC,0x47,0xBB,0xE2,0x34,0x46,0x9C,0xEF,0xFD,0xBF,0xE6,0x26,0x1D,0x5C}) ||
- !ff_guidcmp(g, /* EVENTID_SignalAndServiceStatusSpanningEvent */ (const ff_asf_guid){0xCB,0xC5,0x68,0x80,0x04,0x3C,0x2B,0x49,0xB4,0x7D,0x03,0x08,0x82,0x0D,0xCE,0x51}) ||
- !ff_guidcmp(g, /* EVENTID_StreamTypeSpanningEvent */ (const ff_asf_guid){0xBC,0x2E,0xAF,0x82,0xA6,0x30,0x64,0x42,0xA8,0x0B,0xAD,0x2E,0x13,0x72,0xAC,0x60}) ||
- !ff_guidcmp(g, (const ff_asf_guid){0x1E,0xBE,0xC3,0xC5,0x43,0x92,0xDC,0x11,0x85,0xE5,0x00,0x12,0x3F,0x6F,0x73,0xB9}) ||
- !ff_guidcmp(g, (const ff_asf_guid){0x3B,0x86,0xA2,0xB1,0xEB,0x1E,0xC3,0x44,0x8C,0x88,0x1C,0xA3,0xFF,0xE3,0xE7,0x6A}) ||
- !ff_guidcmp(g, (const ff_asf_guid){0x4E,0x7F,0x4C,0x5B,0xC4,0xD0,0x38,0x4B,0xA8,0x3E,0x21,0x7F,0x7B,0xBF,0x52,0xE7}) ||
- !ff_guidcmp(g, (const ff_asf_guid){0x63,0x36,0xEB,0xFE,0xA1,0x7E,0xD9,0x11,0x83,0x08,0x00,0x07,0xE9,0x5E,0xAD,0x8D}) ||
- !ff_guidcmp(g, (const ff_asf_guid){0x70,0xE9,0xF1,0xF8,0x89,0xA4,0x4C,0x4D,0x83,0x73,0xB8,0x12,0xE0,0xD5,0xF8,0x1E}) ||
- !ff_guidcmp(g, (const ff_asf_guid){0x96,0xC3,0xD2,0xC2,0x7E,0x9A,0xDA,0x11,0x8B,0xF7,0x00,0x07,0xE9,0x5E,0xAD,0x8D}) ||
- !ff_guidcmp(g, (const ff_asf_guid){0x97,0xC3,0xD2,0xC2,0x7E,0x9A,0xDA,0x11,0x8B,0xF7,0x00,0x07,0xE9,0x5E,0xAD,0x8D}) ||
- !ff_guidcmp(g, (const ff_asf_guid){0xA1,0xC3,0xD2,0xC2,0x7E,0x9A,0xDA,0x11,0x8B,0xF7,0x00,0x07,0xE9,0x5E,0xAD,0x8D})) {
- //ignore known guids
- } else
- av_log(s, AV_LOG_WARNING, "unsupported chunk:"PRI_GUID"\n", ARG_GUID(g));
-
- avio_skip(pb, WTV_PAD8(len) - consumed);
- }
- return AVERROR_EOF;
-}
-
-/* declare utf16le strings */
-#define _ , 0,
-static const uint8_t timeline_le16[] =
- {'t'_'i'_'m'_'e'_'l'_'i'_'n'_'e', 0};
-static const uint8_t table_0_entries_legacy_attrib_le16[] =
- {'t'_'a'_'b'_'l'_'e'_'.'_'0'_'.'_'e'_'n'_'t'_'r'_'i'_'e'_'s'_'.'_'l'_'e'_'g'_'a'_'c'_'y'_'_'_'a'_'t'_'t'_'r'_'i'_'b', 0};
-static const uint8_t table_0_entries_time_le16[] =
- {'t'_'a'_'b'_'l'_'e'_'.'_'0'_'.'_'e'_'n'_'t'_'r'_'i'_'e'_'s'_'.'_'t'_'i'_'m'_'e', 0};
-static const uint8_t timeline_table_0_entries_Events_le16[] =
- {'t'_'i'_'m'_'e'_'l'_'i'_'n'_'e'_'.'_'t'_'a'_'b'_'l'_'e'_'.'_'0'_'.'_'e'_'n'_'t'_'r'_'i'_'e'_'s'_'.'_'E'_'v'_'e'_'n'_'t'_'s', 0};
-#undef _
-
-static int read_header(AVFormatContext *s, AVFormatParameters *ap)
-{
- WtvContext *wtv = s->priv_data;
- int root_sector, root_size;
- uint8_t root[WTV_SECTOR_SIZE];
- AVIOContext *pb;
- int64_t timeline_pos;
- int ret;
-
- wtv->epoch =
- wtv->pts =
- wtv->last_valid_pts = AV_NOPTS_VALUE;
-
- /* read root directory sector */
- avio_skip(s->pb, 0x30);
- root_size = avio_rl32(s->pb);
- if (root_size > sizeof(root)) {
- av_log(s, AV_LOG_ERROR, "root directory size exceeds sector size\n");
- return AVERROR_INVALIDDATA;
- }
- avio_skip(s->pb, 4);
- root_sector = avio_rl32(s->pb);
-
- avio_seek(s->pb, root_sector << WTV_SECTOR_BITS, SEEK_SET);
- root_size = avio_read(s->pb, root, root_size);
- if (root_size < 0)
- return AVERROR_INVALIDDATA;
-
- /* parse chunks up until first data chunk */
- wtv->pb = wtvfile_open(s, root, root_size, timeline_le16);
- if (!wtv->pb) {
- av_log(s, AV_LOG_ERROR, "timeline data missing\n");
- return AVERROR_INVALIDDATA;
- }
-
- ret = parse_chunks(s, SEEK_TO_DATA, 0, 0);
- if (ret < 0)
- return ret;
- avio_seek(wtv->pb, -32, SEEK_CUR);
-
- timeline_pos = avio_tell(s->pb); // save before opening another file
-
- /* read metadata */
- pb = wtvfile_open(s, root, root_size, table_0_entries_legacy_attrib_le16);
- if (pb) {
- parse_legacy_attrib(s, pb);
- wtvfile_close(pb);
- }
-
- /* read seek index */
- if (s->nb_streams) {
- AVStream *st = s->streams[0];
- pb = wtvfile_open(s, root, root_size, table_0_entries_time_le16);
- if (pb) {
- while(1) {
- uint64_t timestamp = avio_rl64(pb);
- uint64_t frame_nb = avio_rl64(pb);
- if (pb->eof_reached)
- break;
- ff_add_index_entry(&wtv->index_entries, &wtv->nb_index_entries, &wtv->index_entries_allocated_size,
- 0, timestamp, frame_nb, 0, AVINDEX_KEYFRAME);
- }
- wtvfile_close(pb);
-
- if (wtv->nb_index_entries) {
- pb = wtvfile_open(s, root, root_size, timeline_table_0_entries_Events_le16);
- if (pb) {
- int i;
- while (1) {
- uint64_t frame_nb = avio_rl64(pb);
- uint64_t position = avio_rl64(pb);
- if (pb->eof_reached)
- break;
- for (i = wtv->nb_index_entries - 1; i >= 0; i--) {
- AVIndexEntry *e = wtv->index_entries + i;
- if (frame_nb > e->size)
- break;
- if (position > e->pos)
- e->pos = position;
- }
- }
- wtvfile_close(pb);
- st->duration = wtv->index_entries[wtv->nb_index_entries - 1].timestamp;
- }
- }
- }
- }
-
- avio_seek(s->pb, timeline_pos, SEEK_SET);
- return 0;
-}
-
-static int read_packet(AVFormatContext *s, AVPacket *pkt)
-{
- WtvContext *wtv = s->priv_data;
- AVIOContext *pb = wtv->pb;
- int stream_index, len, ret;
-
- stream_index = parse_chunks(s, SEEK_TO_DATA, 0, &len);
- if (stream_index < 0)
- return stream_index;
-
- ret = av_get_packet(pb, pkt, len - 32);
- if (ret < 0)
- return ret;
- pkt->stream_index = stream_index;
- pkt->pts = wtv->pts;
- avio_skip(pb, WTV_PAD8(len) - len);
- return 0;
-}
-
-static int read_seek(AVFormatContext *s, int stream_index,
- int64_t ts, int flags)
-{
- WtvContext *wtv = s->priv_data;
- AVIOContext *pb = wtv->pb;
- AVStream *st = s->streams[0];
- int64_t ts_relative;
- int i;
-
- if ((flags & AVSEEK_FLAG_FRAME) || (flags & AVSEEK_FLAG_BYTE))
- return AVERROR(ENOSYS);
-
- /* timestamp adjustment is required because wtv->pts values are absolute,
- * whereas AVIndexEntry->timestamp values are relative to epoch. */
- ts_relative = ts;
- if (wtv->epoch != AV_NOPTS_VALUE)
- ts_relative -= wtv->epoch;
-
- i = ff_index_search_timestamp(wtv->index_entries, wtv->nb_index_entries, ts_relative, flags);
- if (i < 0) {
- if (wtv->last_valid_pts == AV_NOPTS_VALUE || ts < wtv->last_valid_pts)
- avio_seek(pb, 0, SEEK_SET);
- else if (st->duration != AV_NOPTS_VALUE && ts_relative > st->duration && wtv->nb_index_entries)
- avio_seek(pb, wtv->index_entries[wtv->nb_index_entries - 1].pos, SEEK_SET);
- if (parse_chunks(s, SEEK_TO_PTS, ts, 0) < 0)
- return AVERROR(ERANGE);
- return 0;
- }
- wtv->pts = wtv->index_entries[i].timestamp;
- if (wtv->epoch != AV_NOPTS_VALUE)
- wtv->pts += wtv->epoch;
- wtv->last_valid_pts = wtv->pts;
- avio_seek(pb, wtv->index_entries[i].pos, SEEK_SET);
- return 0;
-}
-
-static int read_close(AVFormatContext *s)
-{
- WtvContext *wtv = s->priv_data;
- wtvfile_close(wtv->pb);
- return 0;
-}
-
-AVInputFormat ff_wtv_demuxer = {
- .name = "wtv",
- .long_name = NULL_IF_CONFIG_SMALL("Windows Television (WTV)"),
- .priv_data_size = sizeof(WtvContext),
- .read_probe = read_probe,
- .read_header = read_header,
- .read_packet = read_packet,
- .read_seek = read_seek,
- .read_close = read_close,
- .flags = AVFMT_SHOW_IDS,
-};
diff --git a/libavformat/wtv.h b/libavformat/wtv.h
new file mode 100644
index 0000000000..7e4f243551
--- /dev/null
+++ b/libavformat/wtv.h
@@ -0,0 +1,55 @@
+/*
+ * Windows Television (WTV)
+ * Copyright (c) 2010-2011 Peter Ross <pross@xvid.org>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVFORMAT_WTV_H
+#define AVFORMAT_WTV_H
+
+#include "riff.h"
+#include "asf.h"
+
+#define WTV_SECTOR_BITS 12
+#define WTV_SECTOR_SIZE (1 << WTV_SECTOR_BITS)
+#define WTV_BIGSECTOR_BITS 18
+#define WTV_PAD8(x) (((x) + 7) & ~7)
+
+extern const uint8_t ff_timeline_le16[16];
+extern const uint8_t ff_timeline_table_0_entries_Events_le16[62];
+extern const uint8_t ff_table_0_entries_legacy_attrib_le16[58];
+extern const uint8_t ff_table_0_entries_time_le16[40];
+
+extern const ff_asf_guid ff_dir_entry_guid;
+extern const ff_asf_guid ff_wtv_guid;
+extern const ff_asf_guid ff_timestamp_guid;
+extern const ff_asf_guid ff_data_guid;
+extern const ff_asf_guid ff_stream_guid;
+extern const ff_asf_guid ff_mediatype_audio;
+extern const ff_asf_guid ff_mediatype_video;
+extern const ff_asf_guid ff_format_none;
+extern const AVCodecGuid ff_video_guids[];
+
+extern const ff_asf_guid ff_DSATTRIB_TRANSPORT_PROPERTIES;
+extern const ff_asf_guid ff_metadata_guid;
+extern const ff_asf_guid ff_stream2_guid;
+extern const ff_asf_guid ff_mediasubtype_cpfilters_processed;
+extern const ff_asf_guid ff_format_cpfilters_processed;
+extern const ff_asf_guid ff_format_waveformatex;
+extern const ff_asf_guid ff_format_mpeg2_video;
+#endif /* AVFORMAT_WTV_H */
diff --git a/libavformat/wtvdec.c b/libavformat/wtvdec.c
new file mode 100644
index 0000000000..88587c4b52
--- /dev/null
+++ b/libavformat/wtvdec.c
@@ -0,0 +1,1038 @@
+/*
+ * Windows Television (WTV) demuxer
+ * Copyright (c) 2010-2011 Peter Ross <pross@xvid.org>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * Windows Television (WTV) demuxer
+ * @author Peter Ross <pross@xvid.org>
+ */
+
+#include "libavutil/intreadwrite.h"
+#include "libavutil/intfloat_readwrite.h"
+#include "avformat.h"
+#include "internal.h"
+#include "wtv.h"
+#include "mpegts.h"
+#include <strings.h>
+
+/* Macros for formating GUIDs */
+#define PRI_PRETTY_GUID \
+ "%08x-%04x-%04x-%02x%02x%02x%02x%02x%02x%02x%02x"
+#define ARG_PRETTY_GUID(g) \
+ AV_RL32(g),AV_RL16(g+4),AV_RL16(g+6),g[8],g[9],g[10],g[11],g[12],g[13],g[14],g[15]
+#define LEN_PRETTY_GUID 34
+
+/*
+ *
+ * File system routines
+ *
+ */
+
+typedef struct {
+ AVIOContext *pb_filesystem; /** file system (AVFormatContext->pb) */
+
+ int sector_bits; /** sector shift bits; used to convert sector number into pb_filesystem offset */
+ uint32_t *sectors; /** file allocation table */
+ int nb_sectors; /** number of sectors */
+
+ int error;
+ int64_t position;
+ int64_t length;
+} WtvFile;
+
+/**
+ * @return bytes read, 0 on end of file, or <0 on error
+ */
+static int wtvfile_read_packet(void *opaque, uint8_t *buf, int buf_size)
+{
+ WtvFile *wf = opaque;
+ AVIOContext *pb = wf->pb_filesystem;
+ int nread = 0;
+
+ if (wf->error || pb->error)
+ return -1;
+ if (wf->position >= wf->length || url_feof(pb))
+ return 0;
+
+ buf_size = FFMIN(buf_size, wf->length - wf->position);
+ while(nread < buf_size) {
+ int n;
+ int remaining_in_sector = (1 << wf->sector_bits) - (wf->position & ((1 << wf->sector_bits) - 1));
+ int read_request = FFMIN(buf_size - nread, remaining_in_sector);
+
+ n = avio_read(pb, buf, read_request);
+ if (n <= 0)
+ break;
+ nread += n;
+ buf += n;
+ wf->position += n;
+ if (n == remaining_in_sector) {
+ int i = wf->position >> wf->sector_bits;
+ if (i >= wf->nb_sectors ||
+ (wf->sectors[i] != wf->sectors[i - 1] + (1 << (wf->sector_bits - WTV_SECTOR_BITS)) &&
+ avio_seek(pb, (int64_t)wf->sectors[i] << WTV_SECTOR_BITS, SEEK_SET) < 0)) {
+ wf->error = 1;
+ break;
+ }
+ }
+ }
+ return nread;
+}
+
+/**
+ * @return position (or file length)
+ */
+static int64_t wtvfile_seek(void *opaque, int64_t offset, int whence)
+{
+ WtvFile *wf = opaque;
+ AVIOContext *pb = wf->pb_filesystem;
+
+ if (whence == AVSEEK_SIZE)
+ return wf->length;
+ else if (whence == SEEK_CUR)
+ offset = wf->position + offset;
+ else if (whence == SEEK_END)
+ offset = wf->length;
+
+ wf->error = offset < 0 || offset >= wf->length ||
+ avio_seek(pb, ((int64_t)wf->sectors[offset >> wf->sector_bits] << WTV_SECTOR_BITS)
+ + (offset & ((1 << wf->sector_bits) - 1)), SEEK_SET) < 0;
+ wf->position = offset;
+ return offset;
+}
+
+/**
+ * read non-zero integers (le32) from input stream
+ * @param pb
+ * @param[out] data destination
+ * @param count maximum number of integers to read
+ * @return total number of integers read
+ */
+static int read_ints(AVIOContext *pb, uint32_t *data, int count)
+{
+ int i, total = 0;
+ for (i = 0; i < count; i++) {
+ if ((data[total] = avio_rl32(pb)))
+ total++;
+ }
+ return total;
+}
+
+/**
+ * Open file
+ * @param first_sector First sector
+ * @param length Length of file (bytes)
+ * @param depth File allocation table depth
+ * @return NULL on error
+ */
+static AVIOContext * wtvfile_open_sector(int first_sector, uint64_t length, int depth, AVFormatContext *s)
+{
+ AVIOContext *pb;
+ WtvFile *wf;
+ uint8_t *buffer;
+
+ if (avio_seek(s->pb, first_sector << WTV_SECTOR_BITS, SEEK_SET) < 0)
+ return NULL;
+
+ wf = av_mallocz(sizeof(WtvFile));
+ if (!wf)
+ return NULL;
+
+ if (depth == 0) {
+ wf->sectors = av_malloc(sizeof(uint32_t));
+ if (!wf->sectors) {
+ av_free(wf);
+ return NULL;
+ }
+ wf->sectors[0] = first_sector;
+ wf->nb_sectors = 1;
+ } else if (depth == 1) {
+ wf->sectors = av_malloc(WTV_SECTOR_SIZE);
+ if (!wf->sectors) {
+ av_free(wf);
+ return NULL;
+ }
+ wf->nb_sectors = read_ints(s->pb, wf->sectors, WTV_SECTOR_SIZE / 4);
+ } else if (depth == 2) {
+ uint32_t sectors1[WTV_SECTOR_SIZE / 4];
+ int nb_sectors1 = read_ints(s->pb, sectors1, WTV_SECTOR_SIZE / 4);
+ int i;
+
+ wf->sectors = av_malloc(nb_sectors1 << WTV_SECTOR_BITS);
+ if (!wf->sectors) {
+ av_free(wf);
+ return NULL;
+ }
+ wf->nb_sectors = 0;
+ for (i = 0; i < nb_sectors1; i++) {
+ if (avio_seek(s->pb, (int64_t)sectors1[i] << WTV_SECTOR_BITS, SEEK_SET) < 0)
+ break;
+ wf->nb_sectors += read_ints(s->pb, wf->sectors + i * WTV_SECTOR_SIZE / 4, WTV_SECTOR_SIZE / 4);
+ }
+ } else {
+ av_log(s, AV_LOG_ERROR, "unsupported file allocation table depth (0x%x)\n", depth);
+ av_free(wf);
+ return NULL;
+ }
+ wf->sector_bits = length & (1ULL<<63) ? WTV_SECTOR_BITS : WTV_BIGSECTOR_BITS;
+
+ if (!wf->nb_sectors) {
+ av_free(wf->sectors);
+ av_free(wf);
+ return NULL;
+ }
+
+ /* check length */
+ length &= 0xFFFFFFFFFFFF;
+ if (length > ((int64_t)wf->nb_sectors << wf->sector_bits)) {
+ av_log(s, AV_LOG_WARNING, "reported file length (0x%"PRIx64") exceeds number of available sectors (0x%"PRIx64")\n", length, (int64_t)wf->nb_sectors << wf->sector_bits);
+ length = (int64_t)wf->nb_sectors << wf->sector_bits;
+ }
+ wf->length = length;
+
+ /* seek to intial sector */
+ wf->position = 0;
+ if (avio_seek(s->pb, (int64_t)wf->sectors[0] << WTV_SECTOR_BITS, SEEK_SET) < 0) {
+ av_free(wf->sectors);
+ av_free(wf);
+ return NULL;
+ }
+
+ wf->pb_filesystem = s->pb;
+ buffer = av_malloc(1 << wf->sector_bits);
+ if (!buffer) {
+ av_free(wf->sectors);
+ av_free(wf);
+ return NULL;
+ }
+
+ pb = avio_alloc_context(buffer, 1 << wf->sector_bits, 0, wf,
+ wtvfile_read_packet, NULL, wtvfile_seek);
+ if (!pb) {
+ av_free(buffer);
+ av_free(wf->sectors);
+ av_free(wf);
+ }
+ return pb;
+}
+
+/**
+ * Open file using filename
+ * @param[in] buf directory buffer
+ * @param buf_size directory buffer size
+ * @param[in] filename
+ * @param filename_size size of filename
+ * @return NULL on error
+ */
+static AVIOContext * wtvfile_open2(AVFormatContext *s, const uint8_t *buf, int buf_size, const uint8_t *filename, int filename_size)
+{
+ const uint8_t *buf_end = buf + buf_size;
+
+ while(buf + 48 <= buf_end) {
+ int dir_length, name_size, first_sector, depth;
+ uint64_t file_length;
+ const uint8_t *name;
+ if (ff_guidcmp(buf, ff_dir_entry_guid)) {
+ av_log(s, AV_LOG_ERROR, "unknown guid "FF_PRI_GUID", expected dir_entry_guid; "
+ "remaining directory entries ignored\n", FF_ARG_GUID(buf));
+ break;
+ }
+ dir_length = AV_RL16(buf + 16);
+ file_length = AV_RL64(buf + 24);
+ name_size = 2 * AV_RL32(buf + 32);
+ if (buf + 48 + name_size > buf_end) {
+ av_log(s, AV_LOG_ERROR, "filename exceeds buffer size; remaining directory entries ignored\n");
+ break;
+ }
+ first_sector = AV_RL32(buf + 40 + name_size);
+ depth = AV_RL32(buf + 44 + name_size);
+
+ /* compare file name; test optional null terminator */
+ name = buf + 40;
+ if (name_size >= filename_size &&
+ !memcmp(name, filename, filename_size) &&
+ (name_size < filename_size + 2 || !AV_RN16(name + filename_size)))
+ return wtvfile_open_sector(first_sector, file_length, depth, s);
+
+ buf += dir_length;
+ }
+ return 0;
+}
+
+#define wtvfile_open(s, buf, buf_size, filename) \
+ wtvfile_open2(s, buf, buf_size, filename, sizeof(filename))
+
+/**
+ * Close file opened with wtvfile_open_sector(), or wtv_open()
+ */
+static void wtvfile_close(AVIOContext *pb)
+{
+ WtvFile *wf = pb->opaque;
+ av_free(wf->sectors);
+ av_free(pb);
+}
+
+/*
+ *
+ * Main demuxer
+ *
+ */
+
+typedef struct {
+ int seen_data;
+} WtvStream;
+
+typedef struct {
+ AVIOContext *pb; /** timeline file */
+ int64_t epoch;
+ int64_t pts; /** pts for next data chunk */
+ int64_t last_valid_pts; /** latest valid pts, used for interative seeking */
+
+ /* maintain private seek index, as the AVIndexEntry->pos is relative to the
+ start of the 'timeline' file, not the file system (AVFormatContext->pb) */
+ AVIndexEntry *index_entries;
+ int nb_index_entries;
+ unsigned int index_entries_allocated_size;
+} WtvContext;
+
+/* WTV GUIDs */
+static const ff_asf_guid EVENTID_SubtitleSpanningEvent =
+ {0x48,0xC0,0xCE,0x5D,0xB9,0xD0,0x63,0x41,0x87,0x2C,0x4F,0x32,0x22,0x3B,0xE8,0x8A};
+static const ff_asf_guid EVENTID_LanguageSpanningEvent =
+ {0x6D,0x66,0x92,0xE2,0x02,0x9C,0x8D,0x44,0xAA,0x8D,0x78,0x1A,0x93,0xFD,0xC3,0x95};
+static const ff_asf_guid EVENTID_AudioDescriptorSpanningEvent =
+ {0x1C,0xD4,0x7B,0x10,0xDA,0xA6,0x91,0x46,0x83,0x69,0x11,0xB2,0xCD,0xAA,0x28,0x8E};
+static const ff_asf_guid EVENTID_CtxADescriptorSpanningEvent =
+ {0xE6,0xA2,0xB4,0x3A,0x47,0x42,0x34,0x4B,0x89,0x6C,0x30,0xAF,0xA5,0xD2,0x1C,0x24};
+static const ff_asf_guid EVENTID_CSDescriptorSpanningEvent =
+ {0xD9,0x79,0xE7,0xEf,0xF0,0x97,0x86,0x47,0x80,0x0D,0x95,0xCF,0x50,0x5D,0xDC,0x66};
+static const ff_asf_guid EVENTID_DVBScramblingControlSpanningEvent =
+ {0xC4,0xE1,0xD4,0x4B,0xA1,0x90,0x09,0x41,0x82,0x36,0x27,0xF0,0x0E,0x7D,0xCC,0x5B};
+static const ff_asf_guid EVENTID_StreamIDSpanningEvent =
+ {0x68,0xAB,0xF1,0xCA,0x53,0xE1,0x41,0x4D,0xA6,0xB3,0xA7,0xC9,0x98,0xDB,0x75,0xEE};
+static const ff_asf_guid EVENTID_TeletextSpanningEvent =
+ {0x50,0xD9,0x99,0x95,0x33,0x5F,0x17,0x46,0xAF,0x7C,0x1E,0x54,0xB5,0x10,0xDA,0xA3};
+static const ff_asf_guid EVENTID_AudioTypeSpanningEvent =
+ {0xBE,0xBF,0x1C,0x50,0x49,0xB8,0xCE,0x42,0x9B,0xE9,0x3D,0xB8,0x69,0xFB,0x82,0xB3};
+
+/* Windows media GUIDs */
+
+/* Media types */
+static const ff_asf_guid mediasubtype_mpeg1payload =
+ {0x81,0xEB,0x36,0xE4,0x4F,0x52,0xCE,0x11,0x9F,0x53,0x00,0x20,0xAF,0x0B,0xA7,0x70};
+static const ff_asf_guid mediatype_mpeg2_sections =
+ {0x6C,0x17,0x5F,0x45,0x06,0x4B,0xCE,0x47,0x9A,0xEF,0x8C,0xAE,0xF7,0x3D,0xF7,0xB5};
+static const ff_asf_guid mediatype_mpeg2_pes =
+ {0x20,0x80,0x6D,0xE0,0x46,0xDB,0xCF,0x11,0xB4,0xD1,0x00,0x80,0x5F,0x6C,0xBB,0xEA};
+static const ff_asf_guid mediatype_mstvcaption =
+ {0x89,0x8A,0x8B,0xB8,0x49,0xB0,0x80,0x4C,0xAD,0xCF,0x58,0x98,0x98,0x5E,0x22,0xC1};
+
+/* Media subtypes */
+static const ff_asf_guid mediasubtype_dvb_subtitle =
+ {0xC3,0xCB,0xFF,0x34,0xB3,0xD5,0x71,0x41,0x90,0x02,0xD4,0xC6,0x03,0x01,0x69,0x7F};
+static const ff_asf_guid mediasubtype_teletext =
+ {0xE3,0x76,0x2A,0xF7,0x0A,0xEB,0xD0,0x11,0xAC,0xE4,0x00,0x00,0xC0,0xCC,0x16,0xBA};
+static const ff_asf_guid mediasubtype_dtvccdata =
+ {0xAA,0xDD,0x2A,0xF5,0xF0,0x36,0xF5,0x43,0x95,0xEA,0x6D,0x86,0x64,0x84,0x26,0x2A};
+static const ff_asf_guid mediasubtype_mpeg2_sections =
+ {0x79,0x85,0x9F,0x4A,0xF8,0x6B,0x92,0x43,0x8A,0x6D,0xD2,0xDD,0x09,0xFA,0x78,0x61};
+
+/* Formats */
+static const ff_asf_guid format_videoinfo2 =
+ {0xA0,0x76,0x2A,0xF7,0x0A,0xEB,0xD0,0x11,0xAC,0xE4,0x00,0x00,0xC0,0xCC,0x16,0xBA};
+
+static int read_probe(AVProbeData *p)
+{
+ return ff_guidcmp(p->buf, ff_wtv_guid) ? 0 : AVPROBE_SCORE_MAX;
+}
+
+/**
+ * Convert win32 FILETIME to ISO-8601 string
+ */
+static void filetime_to_iso8601(char *buf, int buf_size, int64_t value)
+{
+ time_t t = (value / 10000000LL) - 11644473600LL;
+ strftime(buf, buf_size, "%Y-%m-%d %H:%M:%S", gmtime(&t));
+}
+
+/**
+ * Convert crazy time (100ns since 1 Jan 0001) to ISO-8601 string
+ */
+static void crazytime_to_iso8601(char *buf, int buf_size, int64_t value)
+{
+ time_t t = (value / 10000000LL) - 719162LL*86400LL;
+ strftime(buf, buf_size, "%Y-%m-%d %H:%M:%S", gmtime(&t));
+}
+
+/**
+ * Convert OLE DATE to ISO-8601 string
+ * @return <0 on error
+ */
+static int oledate_to_iso8601(char *buf, int buf_size, int64_t value)
+{
+ time_t t = (av_int2dbl(value) - 25569.0) * 86400;
+ struct tm *result= gmtime(&t);
+ if (!result)
+ return -1;
+ strftime(buf, buf_size, "%Y-%m-%d %H:%M:%S", result);
+ return 0;
+}
+
+static void get_attachment(AVFormatContext *s, AVIOContext *pb, int length)
+{
+ char mime[1024];
+ char description[1024];
+ unsigned int filesize;
+ AVStream *st;
+ int64_t pos = avio_tell(pb);
+
+ avio_get_str16le(pb, INT_MAX, mime, sizeof(mime));
+ if (strcmp(mime, "image/jpeg"))
+ goto done;
+
+ avio_r8(pb);
+ avio_get_str16le(pb, INT_MAX, description, sizeof(description));
+ filesize = avio_rl32(pb);
+ if (!filesize)
+ goto done;
+
+ st = avformat_new_stream(s, NULL);
+ if (!st)
+ goto done;
+ av_dict_set(&st->metadata, "title", description, 0);
+ st->codec->codec_id = CODEC_ID_MJPEG;
+ st->codec->codec_type = AVMEDIA_TYPE_ATTACHMENT;
+ st->codec->extradata = av_mallocz(filesize);
+ if (!st->codec->extradata)
+ goto done;
+ st->codec->extradata_size = filesize;
+ avio_read(pb, st->codec->extradata, filesize);
+done:
+ avio_seek(pb, pos + length, SEEK_SET);
+}
+
+static void get_tag(AVFormatContext *s, AVIOContext *pb, const char *key, int type, int length)
+{
+ int buf_size = FFMAX(2*length, LEN_PRETTY_GUID) + 1;
+ char *buf = av_malloc(buf_size);
+ if (!buf)
+ return;
+
+ if (type == 0 && length == 4) {
+ snprintf(buf, buf_size, "%"PRIi32, avio_rl32(pb));
+ } else if (type == 1) {
+ avio_get_str16le(pb, length, buf, buf_size);
+ if (!strlen(buf)) {
+ av_free(buf);
+ return;
+ }
+ } else if (type == 3 && length == 4) {
+ strcpy(buf, avio_rl32(pb) ? "true" : "false");
+ } else if (type == 4 && length == 8) {
+ int64_t num = avio_rl64(pb);
+ if (!strcmp(key, "WM/EncodingTime") ||
+ !strcmp(key, "WM/MediaOriginalBroadcastDateTime"))
+ filetime_to_iso8601(buf, buf_size, num);
+ else if (!strcmp(key, "WM/WMRVEncodeTime") ||
+ !strcmp(key, "WM/WMRVEndTime"))
+ crazytime_to_iso8601(buf, buf_size, num);
+ else if (!strcmp(key, "WM/WMRVExpirationDate")) {
+ if (oledate_to_iso8601(buf, buf_size, num) < 0 ) {
+ av_free(buf);
+ return;
+ }
+ } else if (!strcmp(key, "WM/WMRVBitrate"))
+ snprintf(buf, buf_size, "%f", av_int2dbl(num));
+ else
+ snprintf(buf, buf_size, "%"PRIi64, num);
+ } else if (type == 5 && length == 2) {
+ snprintf(buf, buf_size, "%"PRIi16, avio_rl16(pb));
+ } else if (type == 6 && length == 16) {
+ ff_asf_guid guid;
+ avio_read(pb, guid, 16);
+ snprintf(buf, buf_size, PRI_PRETTY_GUID, ARG_PRETTY_GUID(guid));
+ } else if (type == 2 && !strcmp(key, "WM/Picture")) {
+ get_attachment(s, pb, length);
+ av_freep(&buf);
+ return;
+ } else {
+ av_freep(&buf);
+ av_log(s, AV_LOG_WARNING, "unsupported metadata entry; key:%s, type:%d, length:0x%x\n", key, type, length);
+ avio_skip(pb, length);
+ return;
+ }
+
+ av_dict_set(&s->metadata, key, buf, 0);
+ av_freep(&buf);
+}
+
+/**
+ * Parse metadata entries
+ */
+static void parse_legacy_attrib(AVFormatContext *s, AVIOContext *pb)
+{
+ ff_asf_guid guid;
+ int length, type;
+ while(!url_feof(pb)) {
+ char key[1024];
+ ff_get_guid(pb, &guid);
+ type = avio_rl32(pb);
+ length = avio_rl32(pb);
+ if (!length)
+ break;
+ if (ff_guidcmp(&guid, ff_metadata_guid)) {
+ av_log(s, AV_LOG_WARNING, "unknown guid "FF_PRI_GUID", expected metadata_guid; "
+ "remaining metadata entries ignored\n", FF_ARG_GUID(guid));
+ break;
+ }
+ avio_get_str16le(pb, INT_MAX, key, sizeof(key));
+ get_tag(s, pb, key, type, length);
+ }
+
+ ff_metadata_conv(&s->metadata, NULL, ff_asf_metadata_conv);
+}
+
+/**
+ * parse VIDEOINFOHEADER2 structure
+ * @return bytes consumed
+ */
+static int parse_videoinfoheader2(AVFormatContext *s, AVStream *st)
+{
+ WtvContext *wtv = s->priv_data;
+ AVIOContext *pb = wtv->pb;
+
+ avio_skip(pb, 72); // picture aspect ratio is unreliable
+ ff_get_bmp_header(pb, st);
+
+ return 72 + 40;
+}
+
+/**
+ * Parse MPEG1WAVEFORMATEX extradata structure
+ */
+static void parse_mpeg1waveformatex(AVStream *st)
+{
+ /* fwHeadLayer */
+ switch (AV_RL16(st->codec->extradata)) {
+ case 0x0001 : st->codec->codec_id = CODEC_ID_MP1; break;
+ case 0x0002 : st->codec->codec_id = CODEC_ID_MP2; break;
+ case 0x0004 : st->codec->codec_id = CODEC_ID_MP3; break;
+ }
+
+ st->codec->bit_rate = AV_RL32(st->codec->extradata + 2); /* dwHeadBitrate */
+
+ /* dwHeadMode */
+ switch (AV_RL16(st->codec->extradata + 6)) {
+ case 1 : case 2 : case 4 : st->codec->channels = 2; break;
+ case 8 : st->codec->channels = 1; break;
+ }
+}
+
+/**
+ * Initialise stream
+ * @param st Stream to initialise, or NULL to create and initialise new stream
+ * @return NULL on error
+ */
+static AVStream * new_stream(AVFormatContext *s, AVStream *st, int sid, int codec_type)
+{
+ if (st) {
+ if (st->codec->extradata) {
+ av_freep(&st->codec->extradata);
+ st->codec->extradata_size = 0;
+ }
+ } else {
+ WtvStream *wst = av_mallocz(sizeof(WtvStream));
+ if (!wst)
+ return NULL;
+ st = avformat_new_stream(s, NULL);
+ if (!st)
+ return NULL;
+ st->id = sid;
+ st->priv_data = wst;
+ }
+ st->codec->codec_type = codec_type;
+ st->need_parsing = AVSTREAM_PARSE_FULL;
+ av_set_pts_info(st, 64, 1, 10000000);
+ return st;
+}
+
+/**
+ * parse Media Type structure and populate stream
+ * @param st Stream, or NULL to create new stream
+ * @param mediatype Mediatype GUID
+ * @param subtype Subtype GUID
+ * @param formattype Format GUID
+ * @param size Size of format buffer
+ * @return NULL on error
+ */
+static AVStream * parse_media_type(AVFormatContext *s, AVStream *st, int sid,
+ ff_asf_guid mediatype, ff_asf_guid subtype,
+ ff_asf_guid formattype, int size)
+{
+ WtvContext *wtv = s->priv_data;
+ AVIOContext *pb = wtv->pb;
+ if (!ff_guidcmp(subtype, ff_mediasubtype_cpfilters_processed) &&
+ !ff_guidcmp(formattype, ff_format_cpfilters_processed)) {
+ ff_asf_guid actual_subtype;
+ ff_asf_guid actual_formattype;
+
+ if (size < 32) {
+ av_log(s, AV_LOG_WARNING, "format buffer size underflow\n");
+ avio_skip(pb, size);
+ return NULL;
+ }
+
+ avio_skip(pb, size - 32);
+ ff_get_guid(pb, &actual_subtype);
+ ff_get_guid(pb, &actual_formattype);
+ avio_seek(pb, -size, SEEK_CUR);
+
+ st = parse_media_type(s, st, sid, mediatype, actual_subtype, actual_formattype, size - 32);
+ avio_skip(pb, 32);
+ return st;
+ } else if (!ff_guidcmp(mediatype, ff_mediatype_audio)) {
+ st = new_stream(s, st, sid, AVMEDIA_TYPE_AUDIO);
+ if (!st)
+ return NULL;
+ if (!ff_guidcmp(formattype, ff_format_waveformatex)) {
+ int ret = ff_get_wav_header(pb, st->codec, size);
+ if (ret < 0)
+ return NULL;
+ } else {
+ if (ff_guidcmp(formattype, ff_format_none))
+ av_log(s, AV_LOG_WARNING, "unknown formattype:"FF_PRI_GUID"\n", FF_ARG_GUID(formattype));
+ avio_skip(pb, size);
+ }
+
+ if (!memcmp(subtype + 4, (const uint8_t[]){FF_MEDIASUBTYPE_BASE_GUID}, 12)) {
+ st->codec->codec_id = ff_wav_codec_get_id(AV_RL32(subtype), st->codec->bits_per_coded_sample);
+ } else if (!ff_guidcmp(subtype, mediasubtype_mpeg1payload)) {
+ if (st->codec->extradata && st->codec->extradata_size >= 22)
+ parse_mpeg1waveformatex(st);
+ else
+ av_log(s, AV_LOG_WARNING, "MPEG1WAVEFORMATEX underflow\n");
+ } else {
+ st->codec->codec_id = ff_codec_guid_get_id(ff_codec_wav_guids, subtype);
+ if (st->codec->codec_id == CODEC_ID_NONE)
+ av_log(s, AV_LOG_WARNING, "unknown subtype:"FF_PRI_GUID"\n", FF_ARG_GUID(subtype));
+ }
+ return st;
+ } else if (!ff_guidcmp(mediatype, ff_mediatype_video)) {
+ st = new_stream(s, st, sid, AVMEDIA_TYPE_VIDEO);
+ if (!st)
+ return NULL;
+ if (!ff_guidcmp(formattype, format_videoinfo2)) {
+ int consumed = parse_videoinfoheader2(s, st);
+ avio_skip(pb, FFMAX(size - consumed, 0));
+ } else if (!ff_guidcmp(formattype, ff_format_mpeg2_video)) {
+ int consumed = parse_videoinfoheader2(s, st);
+ avio_skip(pb, FFMAX(size - consumed, 0));
+ } else {
+ if (ff_guidcmp(formattype, ff_format_none))
+ av_log(s, AV_LOG_WARNING, "unknown formattype:"FF_PRI_GUID"\n", FF_ARG_GUID(formattype));
+ avio_skip(pb, size);
+ }
+
+ if (!memcmp(subtype + 4, (const uint8_t[]){FF_MEDIASUBTYPE_BASE_GUID}, 12)) {
+ st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, AV_RL32(subtype));
+ } else {
+ st->codec->codec_id = ff_codec_guid_get_id(ff_video_guids, subtype);
+ }
+ if (st->codec->codec_id == CODEC_ID_NONE)
+ av_log(s, AV_LOG_WARNING, "unknown subtype:"FF_PRI_GUID"\n", FF_ARG_GUID(subtype));
+ return st;
+ } else if (!ff_guidcmp(mediatype, mediatype_mpeg2_pes) &&
+ !ff_guidcmp(subtype, mediasubtype_dvb_subtitle)) {
+ st = new_stream(s, st, sid, AVMEDIA_TYPE_SUBTITLE);
+ if (!st)
+ return NULL;
+ if (ff_guidcmp(formattype, ff_format_none))
+ av_log(s, AV_LOG_WARNING, "unknown formattype:"FF_PRI_GUID"\n", FF_ARG_GUID(formattype));
+ avio_skip(pb, size);
+ st->codec->codec_id = CODEC_ID_DVB_SUBTITLE;
+ return st;
+ } else if (!ff_guidcmp(mediatype, mediatype_mstvcaption) &&
+ (!ff_guidcmp(subtype, mediasubtype_teletext) || !ff_guidcmp(subtype, mediasubtype_dtvccdata))) {
+ st = new_stream(s, st, sid, AVMEDIA_TYPE_SUBTITLE);
+ if (!st)
+ return NULL;
+ if (ff_guidcmp(formattype, ff_format_none))
+ av_log(s, AV_LOG_WARNING, "unknown formattype:"FF_PRI_GUID"\n", FF_ARG_GUID(formattype));
+ avio_skip(pb, size);
+ st->codec->codec_id = CODEC_ID_DVB_TELETEXT;
+ return st;
+ } else if (!ff_guidcmp(mediatype, mediatype_mpeg2_sections) &&
+ !ff_guidcmp(subtype, mediasubtype_mpeg2_sections)) {
+ if (ff_guidcmp(formattype, ff_format_none))
+ av_log(s, AV_LOG_WARNING, "unknown formattype:"FF_PRI_GUID"\n", FF_ARG_GUID(formattype));
+ avio_skip(pb, size);
+ return NULL;
+ }
+
+ av_log(s, AV_LOG_WARNING, "unknown media type, mediatype:"FF_PRI_GUID
+ ", subtype:"FF_PRI_GUID", formattype:"FF_PRI_GUID"\n",
+ FF_ARG_GUID(mediatype), FF_ARG_GUID(subtype), FF_ARG_GUID(formattype));
+ avio_skip(pb, size);
+ return NULL;
+}
+
+enum {
+ SEEK_TO_DATA = 0,
+ SEEK_TO_PTS,
+};
+
+/**
+ * Parse WTV chunks
+ * @param mode SEEK_TO_DATA or SEEK_TO_PTS
+ * @param seekts timestamp
+ * @param[out] len_ptr Length of data chunk
+ * @return stream index of data chunk, or <0 on error
+ */
+static int parse_chunks(AVFormatContext *s, int mode, int64_t seekts, int *len_ptr)
+{
+ WtvContext *wtv = s->priv_data;
+ AVIOContext *pb = wtv->pb;
+ while (!url_feof(pb)) {
+ ff_asf_guid g;
+ int len, sid, consumed;
+
+ ff_get_guid(pb, &g);
+ len = avio_rl32(pb);
+ if (len < 32)
+ break;
+ sid = avio_rl32(pb) & 0x7FFF;
+ avio_skip(pb, 8);
+ consumed = 32;
+
+ if (!ff_guidcmp(g, ff_stream_guid)) {
+ if (ff_find_stream_index(s, sid) < 0) {
+ ff_asf_guid mediatype, subtype, formattype;
+ int size;
+ avio_skip(pb, 28);
+ ff_get_guid(pb, &mediatype);
+ ff_get_guid(pb, &subtype);
+ avio_skip(pb, 12);
+ ff_get_guid(pb, &formattype);
+ size = avio_rl32(pb);
+ parse_media_type(s, 0, sid, mediatype, subtype, formattype, size);
+ consumed += 92 + size;
+ }
+ } else if (!ff_guidcmp(g, ff_stream2_guid)) {
+ int stream_index = ff_find_stream_index(s, sid);
+ if (stream_index >= 0 && !((WtvStream*)s->streams[stream_index]->priv_data)->seen_data) {
+ ff_asf_guid mediatype, subtype, formattype;
+ int size;
+ avio_skip(pb, 12);
+ ff_get_guid(pb, &mediatype);
+ ff_get_guid(pb, &subtype);
+ avio_skip(pb, 12);
+ ff_get_guid(pb, &formattype);
+ size = avio_rl32(pb);
+ parse_media_type(s, s->streams[stream_index], sid, mediatype, subtype, formattype, size);
+ consumed += 76 + size;
+ }
+ } else if (!ff_guidcmp(g, EVENTID_AudioDescriptorSpanningEvent) ||
+ !ff_guidcmp(g, EVENTID_CtxADescriptorSpanningEvent) ||
+ !ff_guidcmp(g, EVENTID_CSDescriptorSpanningEvent) ||
+ !ff_guidcmp(g, EVENTID_StreamIDSpanningEvent) ||
+ !ff_guidcmp(g, EVENTID_SubtitleSpanningEvent) ||
+ !ff_guidcmp(g, EVENTID_TeletextSpanningEvent)) {
+ int stream_index = ff_find_stream_index(s, sid);
+ if (stream_index >= 0) {
+ AVStream *st = s->streams[stream_index];
+ uint8_t buf[258];
+ const uint8_t *pbuf = buf;
+ int buf_size;
+
+ avio_skip(pb, 8);
+ consumed += 8;
+ if (!ff_guidcmp(g, EVENTID_CtxADescriptorSpanningEvent) ||
+ !ff_guidcmp(g, EVENTID_CSDescriptorSpanningEvent)) {
+ avio_skip(pb, 6);
+ consumed += 6;
+ }
+
+ buf_size = FFMIN(len - consumed, sizeof(buf));
+ avio_read(pb, buf, buf_size);
+ consumed += buf_size;
+ ff_parse_mpeg2_descriptor(s, st, 0, &pbuf, buf + buf_size, 0, 0, 0, 0);
+ }
+ } else if (!ff_guidcmp(g, EVENTID_AudioTypeSpanningEvent)) {
+ int stream_index = ff_find_stream_index(s, sid);
+ if (stream_index >= 0) {
+ AVStream *st = s->streams[stream_index];
+ int audio_type;
+ avio_skip(pb, 8);
+ audio_type = avio_r8(pb);
+ if (audio_type == 2)
+ st->disposition |= AV_DISPOSITION_HEARING_IMPAIRED;
+ else if (audio_type == 3)
+ st->disposition |= AV_DISPOSITION_VISUAL_IMPAIRED;
+ consumed += 9;
+ }
+ } else if (!ff_guidcmp(g, EVENTID_DVBScramblingControlSpanningEvent)) {
+ int stream_index = ff_find_stream_index(s, sid);
+ if (stream_index >= 0) {
+ avio_skip(pb, 12);
+ if (avio_rl32(pb))
+ av_log(s, AV_LOG_WARNING, "DVB scrambled stream detected (st:%d), decoding will likely fail\n", stream_index);
+ consumed += 16;
+ }
+ } else if (!ff_guidcmp(g, EVENTID_LanguageSpanningEvent)) {
+ int stream_index = ff_find_stream_index(s, sid);
+ if (stream_index >= 0) {
+ AVStream *st = s->streams[stream_index];
+ uint8_t language[4];
+ avio_skip(pb, 12);
+ avio_read(pb, language, 3);
+ if (language[0]) {
+ language[3] = 0;
+ av_dict_set(&st->metadata, "language", language, 0);
+ if (!strcmp(language, "nar") || !strcmp(language, "NAR"))
+ st->disposition |= AV_DISPOSITION_VISUAL_IMPAIRED;
+ }
+ consumed += 15;
+ }
+ } else if (!ff_guidcmp(g, ff_timestamp_guid)) {
+ int stream_index = ff_find_stream_index(s, sid);
+ if (stream_index >= 0) {
+ avio_skip(pb, 8);
+ wtv->pts = avio_rl64(pb);
+ consumed += 16;
+ if (wtv->pts == -1)
+ wtv->pts = AV_NOPTS_VALUE;
+ else {
+ wtv->last_valid_pts = wtv->pts;
+ if (wtv->epoch == AV_NOPTS_VALUE || wtv->pts < wtv->epoch)
+ wtv->epoch = wtv->pts;
+ if (mode == SEEK_TO_PTS && wtv->pts >= seekts) {
+ avio_skip(pb, WTV_PAD8(len) - consumed);
+ return 0;
+ }
+ }
+ }
+ } else if (!ff_guidcmp(g, ff_data_guid)) {
+ int stream_index = ff_find_stream_index(s, sid);
+ if (mode == SEEK_TO_DATA && stream_index >= 0 && len > 32) {
+ WtvStream *wst = s->streams[stream_index]->priv_data;
+ wst->seen_data = 1;
+ if (len_ptr) {
+ *len_ptr = len;
+ }
+ return stream_index;
+ }
+ } else if (
+ !ff_guidcmp(g, /* DSATTRIB_CAPTURE_STREAMTIME */ (const ff_asf_guid){0x14,0x56,0x1A,0x0C,0xCD,0x30,0x40,0x4F,0xBC,0xBF,0xD0,0x3E,0x52,0x30,0x62,0x07}) ||
+ !ff_guidcmp(g, /* DSATTRIB_PicSampleSeq */ (const ff_asf_guid){0x02,0xAE,0x5B,0x2F,0x8F,0x7B,0x60,0x4F,0x82,0xD6,0xE4,0xEA,0x2F,0x1F,0x4C,0x99}) ||
+ !ff_guidcmp(g, /* DSATTRIB_TRANSPORT_PROPERTIES */ ff_DSATTRIB_TRANSPORT_PROPERTIES) ||
+ !ff_guidcmp(g, /* dvr_ms_vid_frame_rep_data */ (const ff_asf_guid){0xCC,0x32,0x64,0xDD,0x29,0xE2,0xDB,0x40,0x80,0xF6,0xD2,0x63,0x28,0xD2,0x76,0x1F}) ||
+ !ff_guidcmp(g, /* EVENTID_ChannelChangeSpanningEvent */ (const ff_asf_guid){0xE5,0xC5,0x67,0x90,0x5C,0x4C,0x05,0x42,0x86,0xC8,0x7A,0xFE,0x20,0xFE,0x1E,0xFA}) ||
+ !ff_guidcmp(g, /* EVENTID_ChannelInfoSpanningEvent */ (const ff_asf_guid){0x80,0x6D,0xF3,0x41,0x32,0x41,0xC2,0x4C,0xB1,0x21,0x01,0xA4,0x32,0x19,0xD8,0x1B}) ||
+ !ff_guidcmp(g, /* EVENTID_ChannelTypeSpanningEvent */ (const ff_asf_guid){0x51,0x1D,0xAB,0x72,0xD2,0x87,0x9B,0x48,0xBA,0x11,0x0E,0x08,0xDC,0x21,0x02,0x43}) ||
+ !ff_guidcmp(g, /* EVENTID_PIDListSpanningEvent */ (const ff_asf_guid){0x65,0x8F,0xFC,0x47,0xBB,0xE2,0x34,0x46,0x9C,0xEF,0xFD,0xBF,0xE6,0x26,0x1D,0x5C}) ||
+ !ff_guidcmp(g, /* EVENTID_SignalAndServiceStatusSpanningEvent */ (const ff_asf_guid){0xCB,0xC5,0x68,0x80,0x04,0x3C,0x2B,0x49,0xB4,0x7D,0x03,0x08,0x82,0x0D,0xCE,0x51}) ||
+ !ff_guidcmp(g, /* EVENTID_StreamTypeSpanningEvent */ (const ff_asf_guid){0xBC,0x2E,0xAF,0x82,0xA6,0x30,0x64,0x42,0xA8,0x0B,0xAD,0x2E,0x13,0x72,0xAC,0x60}) ||
+ !ff_guidcmp(g, (const ff_asf_guid){0x1E,0xBE,0xC3,0xC5,0x43,0x92,0xDC,0x11,0x85,0xE5,0x00,0x12,0x3F,0x6F,0x73,0xB9}) ||
+ !ff_guidcmp(g, (const ff_asf_guid){0x3B,0x86,0xA2,0xB1,0xEB,0x1E,0xC3,0x44,0x8C,0x88,0x1C,0xA3,0xFF,0xE3,0xE7,0x6A}) ||
+ !ff_guidcmp(g, (const ff_asf_guid){0x4E,0x7F,0x4C,0x5B,0xC4,0xD0,0x38,0x4B,0xA8,0x3E,0x21,0x7F,0x7B,0xBF,0x52,0xE7}) ||
+ !ff_guidcmp(g, (const ff_asf_guid){0x63,0x36,0xEB,0xFE,0xA1,0x7E,0xD9,0x11,0x83,0x08,0x00,0x07,0xE9,0x5E,0xAD,0x8D}) ||
+ !ff_guidcmp(g, (const ff_asf_guid){0x70,0xE9,0xF1,0xF8,0x89,0xA4,0x4C,0x4D,0x83,0x73,0xB8,0x12,0xE0,0xD5,0xF8,0x1E}) ||
+ !ff_guidcmp(g, (const ff_asf_guid){0x96,0xC3,0xD2,0xC2,0x7E,0x9A,0xDA,0x11,0x8B,0xF7,0x00,0x07,0xE9,0x5E,0xAD,0x8D}) ||
+ !ff_guidcmp(g, (const ff_asf_guid){0x97,0xC3,0xD2,0xC2,0x7E,0x9A,0xDA,0x11,0x8B,0xF7,0x00,0x07,0xE9,0x5E,0xAD,0x8D}) ||
+ !ff_guidcmp(g, (const ff_asf_guid){0xA1,0xC3,0xD2,0xC2,0x7E,0x9A,0xDA,0x11,0x8B,0xF7,0x00,0x07,0xE9,0x5E,0xAD,0x8D})) {
+ //ignore known guids
+ } else
+ av_log(s, AV_LOG_WARNING, "unsupported chunk:"FF_PRI_GUID"\n", FF_ARG_GUID(g));
+
+ avio_skip(pb, WTV_PAD8(len) - consumed);
+ }
+ return AVERROR_EOF;
+}
+
+static int read_header(AVFormatContext *s, AVFormatParameters *ap)
+{
+ WtvContext *wtv = s->priv_data;
+ int root_sector, root_size;
+ uint8_t root[WTV_SECTOR_SIZE];
+ AVIOContext *pb;
+ int64_t timeline_pos;
+ int ret;
+
+ wtv->epoch =
+ wtv->pts =
+ wtv->last_valid_pts = AV_NOPTS_VALUE;
+
+ /* read root directory sector */
+ avio_skip(s->pb, 0x30);
+ root_size = avio_rl32(s->pb);
+ if (root_size > sizeof(root)) {
+ av_log(s, AV_LOG_ERROR, "root directory size exceeds sector size\n");
+ return AVERROR_INVALIDDATA;
+ }
+ avio_skip(s->pb, 4);
+ root_sector = avio_rl32(s->pb);
+
+ avio_seek(s->pb, root_sector << WTV_SECTOR_BITS, SEEK_SET);
+ root_size = avio_read(s->pb, root, root_size);
+ if (root_size < 0)
+ return AVERROR_INVALIDDATA;
+
+ /* parse chunks up until first data chunk */
+ wtv->pb = wtvfile_open(s, root, root_size, ff_timeline_le16);
+ if (!wtv->pb) {
+ av_log(s, AV_LOG_ERROR, "timeline data missing\n");
+ return AVERROR_INVALIDDATA;
+ }
+
+ ret = parse_chunks(s, SEEK_TO_DATA, 0, 0);
+ if (ret < 0)
+ return ret;
+ avio_seek(wtv->pb, -32, SEEK_CUR);
+
+ timeline_pos = avio_tell(s->pb); // save before opening another file
+
+ /* read metadata */
+ pb = wtvfile_open(s, root, root_size, ff_table_0_entries_legacy_attrib_le16);
+ if (pb) {
+ parse_legacy_attrib(s, pb);
+ wtvfile_close(pb);
+ }
+
+ /* read seek index */
+ if (s->nb_streams) {
+ AVStream *st = s->streams[0];
+ pb = wtvfile_open(s, root, root_size, ff_table_0_entries_time_le16);
+ if (pb) {
+ while(1) {
+ uint64_t timestamp = avio_rl64(pb);
+ uint64_t frame_nb = avio_rl64(pb);
+ if (url_feof(pb))
+ break;
+ ff_add_index_entry(&wtv->index_entries, &wtv->nb_index_entries, &wtv->index_entries_allocated_size,
+ 0, timestamp, frame_nb, 0, AVINDEX_KEYFRAME);
+ }
+ wtvfile_close(pb);
+
+ if (wtv->nb_index_entries) {
+ pb = wtvfile_open(s, root, root_size, ff_timeline_table_0_entries_Events_le16);
+ if (pb) {
+ int i;
+ while (1) {
+ uint64_t frame_nb = avio_rl64(pb);
+ uint64_t position = avio_rl64(pb);
+ if (url_feof(pb))
+ break;
+ for (i = wtv->nb_index_entries - 1; i >= 0; i--) {
+ AVIndexEntry *e = wtv->index_entries + i;
+ if (frame_nb > e->size)
+ break;
+ if (position > e->pos)
+ e->pos = position;
+ }
+ }
+ wtvfile_close(pb);
+ st->duration = wtv->index_entries[wtv->nb_index_entries - 1].timestamp;
+ }
+ }
+ }
+ }
+
+ avio_seek(s->pb, timeline_pos, SEEK_SET);
+ return 0;
+}
+
+static int read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ WtvContext *wtv = s->priv_data;
+ AVIOContext *pb = wtv->pb;
+ int stream_index, len, ret;
+
+ stream_index = parse_chunks(s, SEEK_TO_DATA, 0, &len);
+ if (stream_index < 0)
+ return stream_index;
+
+ ret = av_get_packet(pb, pkt, len - 32);
+ if (ret < 0)
+ return ret;
+ pkt->stream_index = stream_index;
+ pkt->pts = wtv->pts;
+ avio_skip(pb, WTV_PAD8(len) - len);
+ return 0;
+}
+
+static int read_seek(AVFormatContext *s, int stream_index,
+ int64_t ts, int flags)
+{
+ WtvContext *wtv = s->priv_data;
+ AVIOContext *pb = wtv->pb;
+ AVStream *st = s->streams[0];
+ int64_t ts_relative;
+ int i;
+
+ if ((flags & AVSEEK_FLAG_FRAME) || (flags & AVSEEK_FLAG_BYTE))
+ return AVERROR(ENOSYS);
+
+ /* timestamp adjustment is required because wtv->pts values are absolute,
+ * whereas AVIndexEntry->timestamp values are relative to epoch. */
+ ts_relative = ts;
+ if (wtv->epoch != AV_NOPTS_VALUE)
+ ts_relative -= wtv->epoch;
+
+ i = ff_index_search_timestamp(wtv->index_entries, wtv->nb_index_entries, ts_relative, flags);
+ if (i < 0) {
+ if (wtv->last_valid_pts == AV_NOPTS_VALUE || ts < wtv->last_valid_pts) {
+ if (avio_seek(pb, 0, SEEK_SET) < 0)
+ return -1;
+ } else if (st->duration != AV_NOPTS_VALUE && ts_relative > st->duration && wtv->nb_index_entries) {
+ if (avio_seek(pb, wtv->index_entries[wtv->nb_index_entries - 1].pos, SEEK_SET) < 0)
+ return -1;
+ }
+ if (parse_chunks(s, SEEK_TO_PTS, ts, 0) < 0)
+ return AVERROR(ERANGE);
+ return 0;
+ }
+ if (avio_seek(pb, wtv->index_entries[i].pos, SEEK_SET) < 0)
+ return -1;
+ wtv->pts = wtv->index_entries[i].timestamp;
+ if (wtv->epoch != AV_NOPTS_VALUE)
+ wtv->pts += wtv->epoch;
+ wtv->last_valid_pts = wtv->pts;
+ return 0;
+}
+
+static int read_close(AVFormatContext *s)
+{
+ WtvContext *wtv = s->priv_data;
+ wtvfile_close(wtv->pb);
+ return 0;
+}
+
+AVInputFormat ff_wtv_demuxer = {
+ .name = "wtv",
+ .long_name = NULL_IF_CONFIG_SMALL("Windows Television (WTV)"),
+ .priv_data_size = sizeof(WtvContext),
+ .read_probe = read_probe,
+ .read_header = read_header,
+ .read_packet = read_packet,
+ .read_seek = read_seek,
+ .read_close = read_close,
+ .flags = AVFMT_SHOW_IDS,
+};
diff --git a/libavformat/wtvenc.c b/libavformat/wtvenc.c
new file mode 100644
index 0000000000..b571833920
--- /dev/null
+++ b/libavformat/wtvenc.c
@@ -0,0 +1,722 @@
+/*
+ * Windows Television (WTV) muxer
+ * Copyright (c) 2011 Zhentan Feng <spyfeng at gmail dot com>
+ * Copyright (c) 2011 Peter Ross <pross@xvid.org>
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/intreadwrite.h"
+#include "libavutil/avassert.h"
+#include "avformat.h"
+#include "internal.h"
+#include "wtv.h"
+
+#define WTV_BIGSECTOR_SIZE (1 << WTV_BIGSECTOR_BITS)
+#define INDEX_BASE 0x2
+#define MAX_NB_INDEX 10
+
+/* declare utf16le strings */
+#define _ , 0,
+static const uint8_t timeline_table_0_header_events[] =
+ {'t'_'i'_'m'_'e'_'l'_'i'_'n'_'e'_'.'_'t'_'a'_'b'_'l'_'e'_'.'_'0'_'.'_'h'_'e'_'a'_'d'_'e'_'r'_'.'_'E'_'v'_'e'_'n'_'t'_'s', 0};
+static const uint8_t table_0_header_legacy_attrib[] =
+ {'t'_'a'_'b'_'l'_'e'_'.'_'0'_'.'_'h'_'e'_'a'_'d'_'e'_'r'_'.'_'l'_'e'_'g'_'a'_'c'_'y'_'_'_'a'_'t'_'t'_'r'_'i'_'b', 0};
+static const uint8_t table_0_redirector_legacy_attrib[] =
+ {'t'_'a'_'b'_'l'_'e'_'.'_'0'_'.'_'r'_'e'_'d'_'i'_'r'_'e'_'c'_'t'_'o'_'r'_'.'_'l'_'e'_'g'_'a'_'c'_'y'_'_'_'a'_'t'_'t'_'r'_'i'_'b', 0};
+static const uint8_t table_0_header_time[] =
+ {'t'_'a'_'b'_'l'_'e'_'.'_'0'_'.'_'h'_'e'_'a'_'d'_'e'_'r'_'.'_'t'_'i'_'m'_'e', 0};
+static const uint8_t legacy_attrib[] =
+ {'l'_'e'_'g'_'a'_'c'_'y'_'_'_'a'_'t'_'t'_'r'_'i'_'b', 0};
+#undef _
+
+static const ff_asf_guid sub_wtv_guid =
+ {0x8C,0xC3,0xD2,0xC2,0x7E,0x9A,0xDA,0x11,0x8B,0xF7,0x00,0x07,0xE9,0x5E,0xAD,0x8D};
+static const ff_asf_guid stream1_guid =
+ {0xA1,0xC3,0xD2,0xC2,0x7E,0x9A,0xDA,0x11,0x8B,0xF7,0x00,0x07,0xE9,0x5E,0xAD,0x8D};
+static const ff_asf_guid sync_guid =
+ {0x97,0xC3,0xD2,0xC2,0x7E,0x9A,0xDA,0x11,0x8B,0xF7,0x00,0x07,0xE9,0x5E,0xAD,0x8D};
+static const ff_asf_guid index_guid =
+ {0x96,0xc3,0xd2,0xc2,0x7e,0x9a,0xda,0x11,0x8b,0xf7,0x00,0x07,0xe9,0x5e,0xad,0x8d};
+
+enum WtvFileIndex {
+ WTV_TIMELINE_TABLE_0_HEADER_EVENTS = 0,
+ WTV_TIMELINE_TABLE_0_ENTRIES_EVENTS,
+ WTV_TIMELINE,
+ WTV_TABLE_0_HEADER_LEGACY_ATTRIB,
+ WTV_TABLE_0_ENTRIES_LEGACY_ATTRIB,
+ WTV_TABLE_0_REDIRECTOR_LEGACY_ATTRIB,
+ WTV_TABLE_0_HEADER_TIME,
+ WTV_TABLE_0_ENTRIES_TIME,
+ WTV_FILES
+};
+
+typedef struct {
+ int64_t length;
+ const void *header;
+ int depth;
+ int first_sector;
+} WtvFile;
+
+typedef struct {
+ int64_t pos;
+ int64_t serial;
+ const ff_asf_guid * guid;
+ int stream_id;
+} WtvChunkEntry;
+
+typedef struct {
+ int64_t timeline_start_pos;
+ WtvFile file[WTV_FILES];
+ int64_t serial; /** chunk serial number */
+ int64_t last_chunk_pos; /** last chunk position */
+ int64_t frame_nb;
+
+ WtvChunkEntry index[MAX_NB_INDEX];
+ int nb_index;
+ int first_video_flag;
+ int64_t sync_pos;
+} WtvContext;
+
+typedef int WTVHeaderWriteFunc(AVIOContext *pb);
+
+typedef struct {
+ const uint8_t *header;
+ int header_size;
+ WTVHeaderWriteFunc *write_header;
+}WTVRootEntryTable;
+
+static int write_pad(AVIOContext *pb, int size)
+{
+ for (; size > 0; size--)
+ avio_w8(pb, 0);
+ return 0;
+}
+
+static void put_guid(AVIOContext *s, const ff_asf_guid *g)
+{
+ assert(sizeof(*g) == 16);
+ avio_write(s, *g, sizeof(*g));
+ }
+
+static const ff_asf_guid *get_codec_guid(enum CodecID id, const AVCodecGuid *av_guid)
+{
+ int i;
+ for (i = 0; av_guid[i].id != CODEC_ID_NONE; i++) {
+ if (id == av_guid[i].id)
+ return &(av_guid[i].guid);
+ }
+ return NULL;
+}
+
+/**
+ * Write chunk header. If header chunk (0x80000000 set) then add to list of header chunks
+ */
+static void write_chunk_header(AVFormatContext *s, const ff_asf_guid *guid, int length, int stream_id)
+{
+ WtvContext *wctx = s->priv_data;
+ AVIOContext *pb = s->pb;
+
+ wctx->last_chunk_pos = avio_tell(pb) - wctx->timeline_start_pos;
+ put_guid(pb, guid);
+ avio_wl32(pb, 32 + length);
+ avio_wl32(pb, stream_id);
+ avio_wl64(pb, wctx->serial);
+
+ if ((stream_id & 0x80000000) && guid != &index_guid) {
+ WtvChunkEntry *t = wctx->index + wctx->nb_index;
+ av_assert0(wctx->nb_index < MAX_NB_INDEX);
+ t->pos = wctx->last_chunk_pos;
+ t->serial = wctx->serial;
+ t->guid = guid;
+ t->stream_id = stream_id & 0x3FFFFFFF;
+ wctx->nb_index++;
+ }
+}
+
+static void write_chunk_header2(AVFormatContext *s, const ff_asf_guid *guid, int stream_id)
+{
+ WtvContext *wctx = s->priv_data;
+ AVIOContext *pb = s->pb;
+
+ int64_t last_chunk_pos = wctx->last_chunk_pos;
+ write_chunk_header(s, guid, 0, stream_id); // length updated later
+ avio_wl64(pb, last_chunk_pos);
+}
+
+static void finish_chunk_noindex(AVFormatContext *s)
+{
+ WtvContext *wctx = s->priv_data;
+ AVIOContext *pb = s->pb;
+
+ // update the chunk_len field and pad.
+ int64_t chunk_len = avio_tell(pb) - (wctx->last_chunk_pos + wctx->timeline_start_pos);
+ avio_seek(pb, -(chunk_len - 16), SEEK_CUR);
+ avio_wl32(pb, chunk_len);
+ avio_seek(pb, chunk_len - (16 + 4), SEEK_CUR);
+
+ write_pad(pb, WTV_PAD8(chunk_len) - chunk_len);
+ wctx->serial++;
+}
+
+static void write_index(AVFormatContext *s)
+{
+ AVIOContext *pb = s->pb;
+ WtvContext *wctx = s->priv_data;
+ int i;
+
+ write_chunk_header2(s, &index_guid, 0x80000000);
+ avio_wl32(pb, 0);
+ avio_wl32(pb, 0);
+
+ for (i = 0; i < wctx->nb_index; i++) {
+ WtvChunkEntry *t = wctx->index + i;
+ put_guid(pb, t->guid);
+ avio_wl64(pb, t->pos);
+ avio_wl32(pb, t->stream_id);
+ avio_wl32(pb, 0); // checksum?
+ avio_wl64(pb, t->serial);
+ }
+ wctx->nb_index = 0; // reset index
+ finish_chunk_noindex(s);
+}
+
+static void finish_chunk(AVFormatContext *s)
+{
+ WtvContext *wctx = s->priv_data;
+ finish_chunk_noindex(s);
+ if (wctx->nb_index == MAX_NB_INDEX)
+ write_index(s);
+}
+
+static int write_stream_codec_info(AVFormatContext *s, AVStream *st)
+{
+ WtvContext *wctx = s->priv_data;
+ const ff_asf_guid *g, *media_type, *format_type;
+ AVIOContext *pb = s->pb;
+ int64_t hdr_pos_start;
+ int hdr_size = 0;
+
+ if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
+ g = get_codec_guid(st->codec->codec_id, ff_video_guids);
+ media_type = &ff_mediatype_video;
+ format_type = &ff_format_mpeg2_video;
+ } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
+ g = get_codec_guid(st->codec->codec_id, ff_codec_wav_guids);
+ media_type = &ff_mediatype_audio;
+ format_type = &ff_format_waveformatex;
+ } else {
+ av_log(s, AV_LOG_ERROR, "unknown codec_type (0x%x)\n", st->codec->codec_type);
+ return -1;
+ }
+
+ if (g == NULL) {
+ av_log(s, AV_LOG_ERROR, "can't get video codec_id (0x%x) guid.\n", st->codec->codec_id);
+ return -1;
+ }
+
+ put_guid(pb, media_type); // mediatype
+ put_guid(pb, &ff_mediasubtype_cpfilters_processed); // subtype
+ write_pad(pb, 12);
+ put_guid(pb,&ff_format_cpfilters_processed); // format type
+ avio_wl32(pb, 0); // size
+
+ hdr_pos_start = avio_tell(pb);
+ if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
+ if (wctx->first_video_flag) {
+ write_pad(pb, 216); //The size is sensitive.
+ wctx->first_video_flag = 0;
+ } else {
+ write_pad(pb, 72); // aspect ratio
+ ff_put_bmp_header(pb, st->codec, ff_codec_bmp_tags, 0);
+ }
+ } else {
+ ff_put_wav_header(pb, st->codec);
+ }
+ hdr_size = avio_tell(pb) - hdr_pos_start;
+
+ // seek back write hdr_size
+ avio_seek(pb, -(hdr_size + 4), SEEK_CUR);
+ avio_wl32(pb, hdr_size + 32);
+ avio_seek(pb, hdr_size, SEEK_CUR);
+ put_guid(pb, g); // actual_subtype
+ put_guid(pb, format_type); // actual_formattype
+
+ return 0;
+}
+
+static int write_stream_codec(AVFormatContext *s, AVStream * st)
+{
+ AVIOContext *pb = s->pb;
+ int ret;
+ write_chunk_header2(s, &stream1_guid, 0x80000000 | 0x01);
+
+ avio_wl32(pb, 0x01);
+ write_pad(pb, 4);
+ write_pad(pb, 4);
+
+ ret = write_stream_codec_info(s, st);
+ if (ret < 0) {
+ av_log(s, AV_LOG_ERROR, "write stream codec info failed codec_type(0x%x)\n", st->codec->codec_type);
+ return -1;
+ }
+
+ finish_chunk(s);
+ return 0;
+}
+
+static void write_sync(AVFormatContext *s)
+{
+ AVIOContext *pb = s->pb;
+ WtvContext *wctx = s->priv_data;
+ int64_t last_chunk_pos = wctx->last_chunk_pos;
+ wctx->sync_pos = avio_tell(pb) - wctx->timeline_start_pos;;
+
+ write_chunk_header(s, &sync_guid, 0x18, 0);
+ write_pad(pb, 24);
+
+ finish_chunk(s);
+
+ wctx->last_chunk_pos = last_chunk_pos;
+}
+
+static void write_DSATTRIB_TRANSPORT_PROPERTIES_init(AVFormatContext *s, int stream_index)
+{
+ AVIOContext *pb = s->pb;
+ write_chunk_header2(s, &ff_DSATTRIB_TRANSPORT_PROPERTIES, 0x80000000 | stream_index);
+ avio_wl64(pb, stream_index);
+ avio_wl64(pb, -1);
+ avio_wl64(pb, 0);
+ finish_chunk(s);
+}
+
+static int write_stream_data(AVFormatContext *s, AVStream *st, int flag)
+{
+ AVIOContext *pb = s->pb;
+ int ret;
+
+ if (!flag) {
+ write_chunk_header2(s, &ff_stream_guid, 0x80000000 | (st->index + INDEX_BASE));
+ avio_wl32(pb, 0x00000001);
+ avio_wl32(pb, st->index + INDEX_BASE); //stream_id
+ avio_wl32(pb, 0x00000001);
+ write_pad(pb, 8);
+ } else {
+ write_chunk_header2(s, &ff_stream2_guid, 0x80000000 | (st->index + INDEX_BASE));
+ write_pad(pb, 4);
+ }
+
+ ret = write_stream_codec_info(s, st);
+ if (ret < 0) {
+ av_log(s, AV_LOG_ERROR, "write stream codec info failed codec_type(0x%x)\n", st->codec->codec_type);
+ return -1;
+ }
+ finish_chunk(s);
+
+ av_set_pts_info(st, 64, 1, 10000000);
+
+ return 0;
+}
+
+static int write_header(AVFormatContext *s)
+{
+ AVIOContext *pb = s->pb;
+ WtvContext *wctx = s->priv_data;
+ int i, pad, ret;
+ AVStream *st;
+
+ put_guid(pb, &ff_wtv_guid);
+ put_guid(pb, &sub_wtv_guid);
+
+ avio_wl32(pb, 0x01);
+ avio_wl32(pb, 0x02);
+ avio_wl32(pb, 1 << WTV_SECTOR_BITS);
+ avio_wl32(pb, 1 << WTV_BIGSECTOR_BITS);
+
+ //write initial root fields
+ avio_wl32(pb, 0); // root_size, update later
+ write_pad(pb, 4);
+ avio_wl32(pb, 0); // root_sector, update it later.
+
+ write_pad(pb, 32);
+ avio_wl32(pb, 0); // file ends pointer, update it later.
+
+ pad = (1 << WTV_SECTOR_BITS) - avio_tell(pb);
+ write_pad(pb, pad);
+ wctx->timeline_start_pos = avio_tell(pb);
+
+ wctx->serial = 1;
+ wctx->last_chunk_pos = -1;
+ wctx->first_video_flag = 1;
+
+ for (i = 0; i < s->nb_streams; i++) {
+ st = s->streams[i];
+ ret = write_stream_codec(s, st);
+ if (ret < 0) {
+ av_log(s, AV_LOG_ERROR, "write stream codec failed codec_type(0x%x)\n", st->codec->codec_type);
+ return -1;
+ }
+ if (i + 1 < s->nb_streams) {
+ write_sync(s);
+ }
+ }
+
+ for (i = 0; i < s->nb_streams; i++) {
+ st = s->streams[i];
+ ret = write_stream_data(s, st, 0);
+ if (ret < 0) {
+ av_log(s, AV_LOG_ERROR, "write stream data failed codec_type(0x%x)\n", st->codec->codec_type);
+ return -1;
+ }
+ ret = write_stream_data(s, st, 1);
+ if (ret < 0) {
+ av_log(s, AV_LOG_ERROR, "write stream2 data failed codec_type(0x%x)\n", st->codec->codec_type);
+ return -1;
+ }
+ }
+
+ for (i = 0; i < s->nb_streams; i++)
+ write_DSATTRIB_TRANSPORT_PROPERTIES_init(s, INDEX_BASE + i);
+
+ if (wctx->nb_index)
+ write_index(s);
+
+ return 0;
+}
+
+static void write_timestamp(AVFormatContext *s, AVPacket *pkt)
+{
+ AVIOContext *pb = s->pb;
+ WtvContext *wctx = s->priv_data;
+ AVCodecContext *enc = s->streams[pkt->stream_index]->codec;
+ int flag = 0;
+ int64_t frame_number = 0;
+
+ if (enc->codec_type == AVMEDIA_TYPE_VIDEO) {
+ wctx->frame_nb++;
+ frame_number = wctx->frame_nb;
+ flag = pkt->flags & AV_PKT_FLAG_KEY ? 1 : 0;
+ }
+ write_chunk_header(s, &ff_timestamp_guid, 56, 0x40000000 | (INDEX_BASE + pkt->stream_index));
+ write_pad(pb, 8);
+ avio_wl64(pb, pkt->pts == AV_NOPTS_VALUE ? -1 : pkt->pts);
+ avio_wl64(pb, pkt->pts == AV_NOPTS_VALUE ? -1 : pkt->pts);
+
+ avio_wl64(pb, frame_number);
+ avio_wl64(pb, 0);
+ avio_wl64(pb, flag);
+ avio_wl64(pb, 0);
+}
+
+static int write_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ AVIOContext *pb = s->pb;
+ WtvContext *wctx = s->priv_data;
+
+ // write timestamp chunk
+ write_timestamp(s, pkt);
+
+ write_chunk_header(s, &ff_data_guid, pkt->size, INDEX_BASE + pkt->stream_index);
+ avio_write(pb, pkt->data, pkt->size);
+ write_pad(pb, WTV_PAD8(pkt->size) - pkt->size);
+
+ wctx->serial++;
+ avio_flush(pb);
+ return 0;
+}
+
+static int write_table0_header_envents(AVIOContext *pb)
+{
+ avio_wl32(pb, 0x10);
+ write_pad(pb, 84);
+ avio_wl64(pb, 0x32);
+ return 96;
+}
+
+static int write_table0_header_legacy_attrib(AVIOContext *pb)
+{
+ int pad = 0;
+ avio_wl32(pb, 0xFFFFFFFF);
+ write_pad(pb, 12);
+ avio_write(pb, legacy_attrib, sizeof(legacy_attrib));
+ pad = WTV_PAD8(sizeof(legacy_attrib)) - sizeof(legacy_attrib);
+ write_pad(pb, pad);
+ write_pad(pb, 32);
+ return 48 + WTV_PAD8(sizeof(legacy_attrib));
+}
+
+static int write_table0_header_time(AVIOContext *pb)
+{
+ avio_wl32(pb, 0x10);
+ write_pad(pb, 76);
+ avio_wl64(pb, 0x40);
+ return 88;
+}
+
+static const WTVRootEntryTable wtv_root_entry_table[] = {
+ { timeline_table_0_header_events, sizeof(timeline_table_0_header_events), write_table0_header_envents},
+ { ff_timeline_table_0_entries_Events_le16, sizeof(ff_timeline_table_0_entries_Events_le16), NULL},
+ { ff_timeline_le16, sizeof(ff_timeline_le16), NULL},
+ { table_0_header_legacy_attrib, sizeof(table_0_header_legacy_attrib), write_table0_header_legacy_attrib},
+ { ff_table_0_entries_legacy_attrib_le16, sizeof(ff_table_0_entries_legacy_attrib_le16), NULL},
+ { table_0_redirector_legacy_attrib, sizeof(table_0_redirector_legacy_attrib), NULL},
+ { table_0_header_time, sizeof(table_0_header_time), write_table0_header_time},
+ { ff_table_0_entries_time_le16, sizeof(ff_table_0_entries_time_le16), NULL},
+};
+
+static int write_root_table(AVFormatContext *s, int64_t sector_pos)
+{
+ AVIOContext *pb = s->pb;
+ WtvContext *wctx = s->priv_data;
+ int size, pad;
+ int i;
+
+ const WTVRootEntryTable *h = wtv_root_entry_table;
+ for (i = 0; i < sizeof(wtv_root_entry_table)/sizeof(WTVRootEntryTable); i++, h++) {
+ WtvFile *w = &wctx->file[i];
+ int filename_padding = WTV_PAD8(h->header_size) - h->header_size;
+ WTVHeaderWriteFunc *write = h->write_header;
+ int len = 0;
+ int64_t len_pos;
+
+ put_guid(pb, &ff_dir_entry_guid);
+ len_pos = avio_tell(pb);
+ avio_wl16(pb, 40 + h->header_size + filename_padding + 8); // maybe updated later
+ write_pad(pb, 6);
+ avio_wl64(pb, write ? 0 : w->length);// maybe update later
+ avio_wl32(pb, (h->header_size + filename_padding) >> 1);
+ write_pad(pb, 4);
+
+ avio_write(pb, h->header, h->header_size);
+ write_pad(pb, filename_padding);
+
+ if (write) {
+ len = write(pb);
+ // update length field
+ avio_seek(pb, len_pos, SEEK_SET);
+ avio_wl64(pb, 40 + h->header_size + filename_padding + len);
+ avio_wl64(pb, len |(1ULL<<62) | (1ULL<<60));
+ avio_seek(pb, 8 + h->header_size + filename_padding + len, SEEK_CUR);
+ } else {
+ avio_wl32(pb, w->first_sector);
+ avio_wl32(pb, w->depth);
+ }
+ }
+
+ // caculate root table size
+ size = avio_tell(pb) - sector_pos;
+ pad = WTV_SECTOR_SIZE- size;
+ write_pad(pb, pad);
+
+ return size;
+}
+
+static void write_fat(AVIOContext *pb, int start_sector, int nb_sectors, int shift)
+{
+ int i;
+ for (i = 0; i < nb_sectors; i++) {
+ avio_wl32(pb, start_sector + (i << shift));
+ }
+ // pad left sector pointer size
+ write_pad(pb, WTV_SECTOR_SIZE - (nb_sectors << 2));
+}
+
+static int write_fat_sector(AVFormatContext *s, int64_t start_pos, int nb_sectors, int sector_bits, int depth)
+{
+ int64_t start_sector = start_pos >> WTV_SECTOR_BITS;
+ int shift = sector_bits - WTV_SECTOR_BITS;
+
+ int64_t fat = avio_tell(s->pb);
+ write_fat(s->pb, start_sector, nb_sectors, shift);
+
+ if (depth == 2) {
+ int64_t start_sector1 = fat >> WTV_SECTOR_BITS;
+ int nb_sectors1 = ((nb_sectors << 2) + WTV_SECTOR_SIZE - 1) / WTV_SECTOR_SIZE;
+ int64_t fat1 = avio_tell(s->pb);
+
+ write_fat(s->pb, start_sector1, nb_sectors1, 0);
+ return fat1;
+ }
+
+ return fat;
+}
+
+static void write_table_entries_events(AVFormatContext *s)
+{
+ AVIOContext *pb = s->pb;
+ WtvContext *wctx = s->priv_data;
+
+ //FIXME: output frame_nb, position pairs.
+ //We only set the first sync_chunk position here.
+ avio_wl64(pb, 0x2); avio_wl64(pb, wctx->sync_pos);
+}
+
+static void write_tag(AVIOContext *pb, const char *key, const char *value)
+{
+ put_guid(pb, &ff_metadata_guid);
+ avio_wl32(pb, 1);
+ avio_wl32(pb, strlen(value)*2 + 2);
+ avio_put_str16le(pb, key);
+ avio_put_str16le(pb, value);
+}
+
+static void write_table_entries_attrib(AVFormatContext *s)
+{
+ AVDictionaryEntry *tag = 0;
+
+ //FIXME: translate special tags (e.g. WM/Bitrate) to binary representation
+ ff_metadata_conv(&s->metadata, ff_asf_metadata_conv, NULL);
+ while((tag = av_dict_get(s->metadata, "", tag, AV_DICT_IGNORE_SUFFIX)))
+ write_tag(s->pb, tag->key, tag->value);
+}
+
+static void write_table_redirector_legacy_attrib(AVFormatContext *s)
+{
+ AVIOContext *pb = s->pb;
+ AVDictionaryEntry *tag = 0;
+ int64_t pos = 0;
+
+ //FIXME: translate special tags to binary representation
+ while((tag = av_dict_get(s->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) {
+ avio_wl64(pb, pos);
+ pos += 16 + 4 + 4 + strlen(tag->key)*2 + 2 + strlen(tag->value)*2 + 2;
+ }
+}
+
+/**
+ * Pad the remainder of a file
+ * Write out fat table
+ * @return <0 on error
+ */
+static int finish_file(AVFormatContext *s, enum WtvFileIndex index, int64_t start_pos)
+{
+ WtvContext *wctx = s->priv_data;
+ AVIOContext *pb = s->pb;
+ WtvFile *w = &wctx->file[index];
+ int64_t end_pos = avio_tell(pb);
+ int sector_bits, nb_sectors, pad;
+
+ av_assert0(index < WTV_FILES);
+
+ w->length = (end_pos - start_pos);
+
+ // determine optimal fat table depth, sector_bits, nb_sectors
+ if (w->length <= WTV_SECTOR_SIZE) {
+ w->depth = 0;
+ sector_bits = WTV_SECTOR_BITS;
+ } else if (w->length <= (WTV_SECTOR_SIZE / 4) * WTV_SECTOR_SIZE) {
+ w->depth = 1;
+ sector_bits = WTV_SECTOR_BITS;
+ } else if (w->length <= (WTV_SECTOR_SIZE / 4) * WTV_BIGSECTOR_SIZE) {
+ w->depth = 1;
+ sector_bits = WTV_BIGSECTOR_BITS;
+ } else if (w->length <= (int64_t)(WTV_SECTOR_SIZE / 4) * (WTV_SECTOR_SIZE / 4) * WTV_SECTOR_SIZE) {
+ w->depth = 2;
+ sector_bits = WTV_SECTOR_BITS;
+ } else if (w->length <= (int64_t)(WTV_SECTOR_SIZE / 4) * (WTV_SECTOR_SIZE / 4) * WTV_BIGSECTOR_SIZE) {
+ w->depth = 2;
+ sector_bits = WTV_BIGSECTOR_BITS;
+ } else {
+ av_log(s, AV_LOG_ERROR, "unsupported file allocation table depth (%"PRIi64" bytes)\n", w->length);
+ return -1;
+ }
+
+ // determine the nb_sectors
+ nb_sectors = (int)(w->length >> sector_bits);
+
+ // pad sector of timeline
+ pad = (1 << sector_bits) - (w->length % (1 << sector_bits));
+ if (pad) {
+ nb_sectors++;
+ write_pad(pb, pad);
+ }
+
+ //write fat table
+ if (w->depth > 0) {
+ w->first_sector = write_fat_sector(s, start_pos, nb_sectors, sector_bits, w->depth);
+ } else {
+ w->first_sector = start_pos;
+ }
+ w->first_sector >>= WTV_SECTOR_BITS;
+
+ w->length |= 1ULL<<60;
+ if (sector_bits == WTV_SECTOR_BITS)
+ w->length |= 1ULL<<63;
+
+ return 0;
+}
+
+static int write_trailer(AVFormatContext *s)
+{
+ WtvContext *wctx = s->priv_data;
+ AVIOContext *pb = s->pb;
+ int root_size;
+ int64_t sector_pos;
+ int64_t start_pos, file_end_pos;
+
+ if (finish_file(s, WTV_TIMELINE, wctx->timeline_start_pos) < 0)
+ return -1;
+
+ start_pos = avio_tell(pb);
+ write_table_entries_events(s);
+ if (finish_file(s, WTV_TIMELINE_TABLE_0_ENTRIES_EVENTS, start_pos) < 0)
+ return -1;
+
+ start_pos = avio_tell(pb);
+ write_table_entries_attrib(s);
+ if (finish_file(s, WTV_TABLE_0_ENTRIES_LEGACY_ATTRIB, start_pos) < 0)
+ return -1;
+
+ start_pos = avio_tell(pb);
+ write_table_redirector_legacy_attrib(s);
+ if (finish_file(s, WTV_TABLE_0_REDIRECTOR_LEGACY_ATTRIB, start_pos) < 0)
+ return -1;
+
+ start_pos = avio_tell(pb);
+ //FIXME: output timestamp, frame_nb pairs here.
+ if (finish_file(s, WTV_TABLE_0_ENTRIES_TIME, start_pos) < 0)
+ return -1;
+
+ // write root table
+ sector_pos = avio_tell(pb);
+ root_size = write_root_table(s, sector_pos);
+
+ file_end_pos = avio_tell(pb);
+ // update root value
+ avio_seek(pb, 0x30, SEEK_SET);
+ avio_wl32(pb, root_size);
+ avio_seek(pb, 4, SEEK_CUR);
+ avio_wl32(pb, sector_pos >> WTV_SECTOR_BITS);
+ avio_seek(pb, 0x5c, SEEK_SET);
+ avio_wl32(pb, file_end_pos >> WTV_SECTOR_BITS);
+
+ avio_flush(pb);
+ return 0;
+}
+
+AVOutputFormat ff_wtv_muxer = {
+ .name = "wtv",
+ .long_name = NULL_IF_CONFIG_SMALL("Windows Television (WTV)"),
+ .extensions = "wtv",
+ .priv_data_size = sizeof(WtvContext),
+ .audio_codec = CODEC_ID_MP2,
+ .video_codec = CODEC_ID_MPEG2VIDEO,
+ .write_header = write_header,
+ .write_packet = write_packet,
+ .write_trailer = write_trailer,
+ .codec_tag = (const AVCodecTag* const []){ ff_codec_bmp_tags,
+ ff_codec_wav_tags, 0 },
+};
diff --git a/libavformat/wv.c b/libavformat/wv.c
index d6d7099ba7..72c8df0f24 100644
--- a/libavformat/wv.c
+++ b/libavformat/wv.c
@@ -2,20 +2,20 @@
* WavPack demuxer
* Copyright (c) 2006,2011 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -220,7 +220,7 @@ static int wv_read_header(AVFormatContext *s,
}
/* now we are ready: build format streams */
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return -1;
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
@@ -250,14 +250,16 @@ static int wv_read_packet(AVFormatContext *s,
WVContext *wc = s->priv_data;
int ret;
int size, ver, off;
+ int64_t pos;
- if (s->pb->eof_reached)
+ if (url_feof(s->pb))
return AVERROR(EIO);
if(wc->block_parsed){
if(wv_read_block_header(s, s->pb, 0) < 0)
return -1;
}
+ pos = wc->pos;
off = wc->multichannel ? 4 : 0;
if(av_new_packet(pkt, wc->blksize + WV_EXTRA_SIZE + off) < 0)
return AVERROR(ENOMEM);
@@ -314,7 +316,7 @@ static int wv_read_packet(AVFormatContext *s,
pkt->stream_index = 0;
wc->block_parsed = 1;
pkt->pts = wc->soff;
- av_add_index_entry(s->streams[0], wc->pos, pkt->pts, 0, 0, AVINDEX_KEYFRAME);
+ av_add_index_entry(s->streams[0], pos, pkt->pts, 0, 0, AVINDEX_KEYFRAME);
return 0;
}
@@ -328,7 +330,8 @@ static int wv_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp,
int64_t pos, pts;
/* if found, seek there */
- if (index >= 0){
+ if (index >= 0 &&
+ timestamp <= st->index_entries[st->nb_index_entries - 1].timestamp) {
wc->block_parsed = 1;
avio_seek(s->pb, st->index_entries[index].pos, SEEK_SET);
return 0;
@@ -351,12 +354,11 @@ static int wv_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp,
}
AVInputFormat ff_wv_demuxer = {
- "wv",
- NULL_IF_CONFIG_SMALL("WavPack"),
- sizeof(WVContext),
- wv_probe,
- wv_read_header,
- wv_read_packet,
- NULL,
- wv_read_seek,
+ .name = "wv",
+ .long_name = NULL_IF_CONFIG_SMALL("WavPack"),
+ .priv_data_size = sizeof(WVContext),
+ .read_probe = wv_probe,
+ .read_header = wv_read_header,
+ .read_packet = wv_read_packet,
+ .read_seek = wv_read_seek,
};
diff --git a/libavformat/xa.c b/libavformat/xa.c
index c3421a34e7..dd7811dd91 100644
--- a/libavformat/xa.c
+++ b/libavformat/xa.c
@@ -2,20 +2,20 @@
* Maxis XA (.xa) File Demuxer
* Copyright (c) 2008 Robert Marston
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -70,7 +70,7 @@ static int xa_read_header(AVFormatContext *s,
AVStream *st;
/*Set up the XA Audio Decoder*/
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
@@ -119,10 +119,10 @@ static int xa_read_packet(AVFormatContext *s,
}
AVInputFormat ff_xa_demuxer = {
- "xa",
- NULL_IF_CONFIG_SMALL("Maxis XA File Format"),
- sizeof(MaxisXADemuxContext),
- xa_probe,
- xa_read_header,
- xa_read_packet,
+ .name = "xa",
+ .long_name = NULL_IF_CONFIG_SMALL("Maxis XA File Format"),
+ .priv_data_size = sizeof(MaxisXADemuxContext),
+ .read_probe = xa_probe,
+ .read_header = xa_read_header,
+ .read_packet = xa_read_packet,
};
diff --git a/libavformat/xmv.c b/libavformat/xmv.c
new file mode 100644
index 0000000000..aeafcb6904
--- /dev/null
+++ b/libavformat/xmv.c
@@ -0,0 +1,557 @@
+/*
+ * Microsoft XMV demuxer
+ * Copyright (c) 2011 Sven Hesse <drmccoy@drmccoy.de>
+ * Copyright (c) 2011 Matthew Hoops <clone2727@gmail.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * Microsoft XMV demuxer
+ */
+
+#include <stdint.h>
+
+#include "libavutil/intreadwrite.h"
+
+#include "avformat.h"
+#include "riff.h"
+
+/** The min size of an XMV header. */
+#define XMV_MIN_HEADER_SIZE 36
+
+/** Audio flag: ADPCM'd 5.1 stream, front left / right channels */
+#define XMV_AUDIO_ADPCM51_FRONTLEFTRIGHT 1
+/** Audio flag: ADPCM'd 5.1 stream, front center / low frequency channels */
+#define XMV_AUDIO_ADPCM51_FRONTCENTERLOW 2
+/** Audio flag: ADPCM'd 5.1 stream, rear left / right channels */
+#define XMV_AUDIO_ADPCM51_REARLEFTRIGHT 4
+
+/** Audio flag: Any of the ADPCM'd 5.1 stream flags. */
+#define XMV_AUDIO_ADPCM51 (XMV_AUDIO_ADPCM51_FRONTLEFTRIGHT | \
+ XMV_AUDIO_ADPCM51_FRONTCENTERLOW | \
+ XMV_AUDIO_ADPCM51_REARLEFTRIGHT)
+
+/** A video packet with an XMV file. */
+typedef struct XMVVideoPacket {
+ int stream_index; ///< The decoder stream index for this video packet.
+
+ uint32_t data_size; ///< The size of the remaining video data.
+ uint64_t data_offset; ///< The offset of the video data within the file.
+
+ uint32_t current_frame; ///< The current frame within this video packet.
+ uint32_t frame_count; ///< The amount of frames within this video packet.
+
+ int has_extradata; ///< Does the video packet contain extra data?
+ uint8_t extradata[4]; ///< The extra data
+
+ int64_t last_pts; ///< PTS of the last video frame.
+ int64_t pts; ///< PTS of the most current video frame.
+} XMVVideoPacket;
+
+/** An audio packet with an XMV file. */
+typedef struct XMVAudioPacket {
+ int stream_index; ///< The decoder stream index for this audio packet.
+
+ /* Stream format properties. */
+ uint16_t compression; ///< The type of compression.
+ uint16_t channels; ///< Number of channels.
+ uint32_t sample_rate; ///< Sampling rate.
+ uint16_t bits_per_sample; ///< Bits per compressed sample.
+ uint32_t bit_rate; ///< Bits of compressed data per second.
+ uint16_t flags; ///< Flags
+ uint16_t block_align; ///< Bytes per compressed block.
+ uint16_t block_samples; ///< Decompressed samples per compressed block.
+
+ enum CodecID codec_id; ///< The codec ID of the compression scheme.
+
+ uint32_t data_size; ///< The size of the remaining audio data.
+ uint64_t data_offset; ///< The offset of the audio data within the file.
+
+ uint32_t frame_size; ///< Number of bytes to put into an audio frame.
+
+ uint64_t block_count; ///< Running counter of decompressed audio block.
+} XMVAudioPacket;
+
+/** Context for demuxing an XMV file. */
+typedef struct XMVDemuxContext {
+ uint16_t audio_track_count; ///< Number of audio track in this file.
+
+ uint32_t this_packet_size; ///< Size of the current packet.
+ uint32_t next_packet_size; ///< Size of the next packet.
+
+ uint64_t this_packet_offset; ///< Offset of the current packet.
+ uint64_t next_packet_offset; ///< Offset of the next packet.
+
+ uint16_t current_stream; ///< The index of the stream currently handling.
+ uint16_t stream_count; ///< The number of streams in this file.
+
+ XMVVideoPacket video; ///< The video packet contained in each packet.
+ XMVAudioPacket *audio; ///< The audio packets contained in each packet.
+} XMVDemuxContext;
+
+static int xmv_probe(AVProbeData *p)
+{
+ uint32_t file_version;
+
+ if (p->buf_size < XMV_MIN_HEADER_SIZE)
+ return 0;
+
+ file_version = AV_RL32(p->buf + 16);
+ if ((file_version == 0) || (file_version > 4))
+ return 0;
+
+ if (!memcmp(p->buf + 12, "xobX", 4))
+ return AVPROBE_SCORE_MAX;
+
+ return 0;
+}
+
+static int xmv_read_header(AVFormatContext *s,
+ AVFormatParameters *ap)
+{
+ XMVDemuxContext *xmv = s->priv_data;
+ AVIOContext *pb = s->pb;
+ AVStream *vst = NULL;
+
+ uint32_t file_version;
+ uint32_t this_packet_size;
+ uint16_t audio_track;
+
+ avio_skip(pb, 4); /* Next packet size */
+
+ this_packet_size = avio_rl32(pb);
+
+ avio_skip(pb, 4); /* Max packet size */
+ avio_skip(pb, 4); /* "xobX" */
+
+ file_version = avio_rl32(pb);
+ if ((file_version != 4) && (file_version != 2))
+ av_log_ask_for_sample(s, "Found uncommon version %d\n", file_version);
+
+
+ /* Video track */
+
+ vst = avformat_new_stream(s, NULL);
+ if (!vst)
+ return AVERROR(ENOMEM);
+
+ av_set_pts_info(vst, 32, 1, 1000);
+
+ vst->codec->codec_type = AVMEDIA_TYPE_VIDEO;
+ vst->codec->codec_id = CODEC_ID_WMV2;
+ vst->codec->codec_tag = MKBETAG('W', 'M', 'V', '2');
+ vst->codec->width = avio_rl32(pb);
+ vst->codec->height = avio_rl32(pb);
+
+ vst->duration = avio_rl32(pb);
+
+ xmv->video.stream_index = vst->index;
+
+ /* Audio tracks */
+
+ xmv->audio_track_count = avio_rl16(pb);
+
+ avio_skip(pb, 2); /* Unknown (padding?) */
+
+ xmv->audio = av_malloc(xmv->audio_track_count * sizeof(XMVAudioPacket));
+ if (!xmv->audio)
+ return AVERROR(ENOMEM);
+
+ for (audio_track = 0; audio_track < xmv->audio_track_count; audio_track++) {
+ XMVAudioPacket *packet = &xmv->audio[audio_track];
+ AVStream *ast = NULL;
+
+ packet->compression = avio_rl16(pb);
+ packet->channels = avio_rl16(pb);
+ packet->sample_rate = avio_rl32(pb);
+ packet->bits_per_sample = avio_rl16(pb);
+ packet->flags = avio_rl16(pb);
+
+ packet->bit_rate = packet->bits_per_sample *
+ packet->sample_rate *
+ packet->channels;
+ packet->block_align = 36 * packet->channels;
+ packet->block_samples = 64;
+ packet->codec_id = ff_wav_codec_get_id(packet->compression,
+ packet->bits_per_sample);
+
+ packet->stream_index = -1;
+
+ packet->frame_size = 0;
+ packet->block_count = 0;
+
+ /* TODO: ADPCM'd 5.1 sound is encoded in three separate streams.
+ * Those need to be interleaved to a proper 5.1 stream. */
+ if (packet->flags & XMV_AUDIO_ADPCM51)
+ av_log(s, AV_LOG_WARNING, "Unsupported 5.1 ADPCM audio stream "
+ "(0x%04X)\n", packet->flags);
+
+ ast = avformat_new_stream(s, NULL);
+ if (!ast)
+ return AVERROR(ENOMEM);
+
+ ast->codec->codec_type = AVMEDIA_TYPE_AUDIO;
+ ast->codec->codec_id = packet->codec_id;
+ ast->codec->codec_tag = packet->compression;
+ ast->codec->channels = packet->channels;
+ ast->codec->sample_rate = packet->sample_rate;
+ ast->codec->bits_per_coded_sample = packet->bits_per_sample;
+ ast->codec->bit_rate = packet->bit_rate;
+ ast->codec->block_align = 36 * packet->channels;
+
+ av_set_pts_info(ast, 32, packet->block_samples, packet->sample_rate);
+
+ packet->stream_index = ast->index;
+
+ ast->duration = vst->duration;
+ }
+
+
+ /* Initialize the packet context */
+
+ xmv->next_packet_offset = avio_tell(pb);
+ xmv->next_packet_size = this_packet_size - xmv->next_packet_offset;
+ xmv->stream_count = xmv->audio_track_count + 1;
+
+ return 0;
+}
+
+static void xmv_read_extradata(uint8_t *extradata, AVIOContext *pb)
+{
+ /* Read the XMV extradata */
+
+ uint32_t data = avio_rl32(pb);
+
+ int mspel_bit = !!(data & 0x01);
+ int loop_filter = !!(data & 0x02);
+ int abt_flag = !!(data & 0x04);
+ int j_type_bit = !!(data & 0x08);
+ int top_left_mv_flag = !!(data & 0x10);
+ int per_mb_rl_bit = !!(data & 0x20);
+ int slice_count = (data >> 6) & 7;
+
+ /* Write it back as standard WMV2 extradata */
+
+ data = 0;
+
+ data |= mspel_bit << 15;
+ data |= loop_filter << 14;
+ data |= abt_flag << 13;
+ data |= j_type_bit << 12;
+ data |= top_left_mv_flag << 11;
+ data |= per_mb_rl_bit << 10;
+ data |= slice_count << 7;
+
+ AV_WB32(extradata, data);
+}
+
+static int xmv_process_packet_header(AVFormatContext *s)
+{
+ XMVDemuxContext *xmv = s->priv_data;
+ AVIOContext *pb = s->pb;
+
+ uint8_t data[8];
+ uint16_t audio_track;
+ uint64_t data_offset;
+
+ /* Next packet size */
+ xmv->next_packet_size = avio_rl32(pb);
+
+ /* Packet video header */
+
+ if (avio_read(pb, data, 8) != 8)
+ return AVERROR(EIO);
+
+ xmv->video.data_size = AV_RL32(data) & 0x007FFFFF;
+
+ xmv->video.current_frame = 0;
+ xmv->video.frame_count = (AV_RL32(data) >> 23) & 0xFF;
+
+ xmv->video.has_extradata = (data[3] & 0x80) != 0;
+
+ /* Adding the audio data sizes and the video data size keeps you 4 bytes
+ * short for every audio track. But as playing around with XMV files with
+ * ADPCM audio showed, taking the extra 4 bytes from the audio data gives
+ * you either completely distorted audio or click (when skipping the
+ * remaining 68 bytes of the ADPCM block). Substracting 4 bytes for every
+ * audio track from the video data works at least for the audio. Probably
+ * some alignment thing?
+ * The video data has (always?) lots of padding, so it should work out...
+ */
+ xmv->video.data_size -= xmv->audio_track_count * 4;
+
+ xmv->current_stream = 0;
+ if (!xmv->video.frame_count) {
+ xmv->video.frame_count = 1;
+ xmv->current_stream = 1;
+ }
+
+ /* Packet audio header */
+
+ for (audio_track = 0; audio_track < xmv->audio_track_count; audio_track++) {
+ XMVAudioPacket *packet = &xmv->audio[audio_track];
+
+ if (avio_read(pb, data, 4) != 4)
+ return AVERROR(EIO);
+
+ packet->data_size = AV_RL32(data) & 0x007FFFFF;
+ if ((packet->data_size == 0) && (audio_track != 0))
+ /* This happens when I create an XMV with several identical audio
+ * streams. From the size calculations, duplicating the previous
+ * stream's size works out, but the track data itself is silent.
+ * Maybe this should also redirect the offset to the previous track?
+ */
+ packet->data_size = xmv->audio[audio_track - 1].data_size;
+
+ /* Carve up the audio data in frame_count slices */
+ packet->frame_size = packet->data_size / xmv->video.frame_count;
+ packet->frame_size -= packet->frame_size % packet->block_align;
+ }
+
+ /* Packet data offsets */
+
+ data_offset = avio_tell(pb);
+
+ xmv->video.data_offset = data_offset;
+ data_offset += xmv->video.data_size;
+
+ for (audio_track = 0; audio_track < xmv->audio_track_count; audio_track++) {
+ xmv->audio[audio_track].data_offset = data_offset;
+ data_offset += xmv->audio[audio_track].data_size;
+ }
+
+ /* Video frames header */
+
+ /* Read new video extra data */
+ if (xmv->video.data_size > 0) {
+ if (xmv->video.has_extradata) {
+ xmv_read_extradata(xmv->video.extradata, pb);
+
+ xmv->video.data_size -= 4;
+ xmv->video.data_offset += 4;
+
+ if (xmv->video.stream_index >= 0) {
+ AVStream *vst = s->streams[xmv->video.stream_index];
+
+ assert(xmv->video.stream_index < s->nb_streams);
+
+ if (vst->codec->extradata_size < 4) {
+ av_free(vst->codec->extradata);
+
+ vst->codec->extradata =
+ av_malloc(4 + FF_INPUT_BUFFER_PADDING_SIZE);
+ vst->codec->extradata_size = 4;
+ }
+
+ memcpy(vst->codec->extradata, xmv->video.extradata, 4);
+ }
+ }
+ }
+
+ return 0;
+}
+
+static int xmv_fetch_new_packet(AVFormatContext *s)
+{
+ XMVDemuxContext *xmv = s->priv_data;
+ AVIOContext *pb = s->pb;
+ int result;
+
+ /* Seek to it */
+ xmv->this_packet_offset = xmv->next_packet_offset;
+ if (avio_seek(pb, xmv->this_packet_offset, SEEK_SET) != xmv->this_packet_offset)
+ return AVERROR(EIO);
+
+ /* Update the size */
+ xmv->this_packet_size = xmv->next_packet_size;
+ if (xmv->this_packet_size < (12 + xmv->audio_track_count * 4))
+ return AVERROR(EIO);
+
+ /* Process the header */
+ result = xmv_process_packet_header(s);
+ if (result)
+ return result;
+
+ /* Update the offset */
+ xmv->next_packet_offset = xmv->this_packet_offset + xmv->this_packet_size;
+
+ return 0;
+}
+
+static int xmv_fetch_audio_packet(AVFormatContext *s,
+ AVPacket *pkt, uint32_t stream)
+{
+ XMVDemuxContext *xmv = s->priv_data;
+ AVIOContext *pb = s->pb;
+ XMVAudioPacket *audio = &xmv->audio[stream];
+
+ uint32_t data_size;
+ uint32_t block_count;
+ int result;
+
+ /* Seek to it */
+ if (avio_seek(pb, audio->data_offset, SEEK_SET) != audio->data_offset)
+ return AVERROR(EIO);
+
+ if ((xmv->video.current_frame + 1) < xmv->video.frame_count)
+ /* Not the last frame, get at most frame_size bytes. */
+ data_size = FFMIN(audio->frame_size, audio->data_size);
+ else
+ /* Last frame, get the rest. */
+ data_size = audio->data_size;
+
+ /* Read the packet */
+ result = av_get_packet(pb, pkt, data_size);
+ if (result <= 0)
+ return result;
+
+ pkt->stream_index = audio->stream_index;
+
+ /* Calculate the PTS */
+
+ block_count = data_size / audio->block_align;
+
+ pkt->duration = block_count;
+ pkt->pts = audio->block_count;
+ pkt->dts = AV_NOPTS_VALUE;
+
+ audio->block_count += block_count;
+
+ /* Advance offset */
+ audio->data_size -= data_size;
+ audio->data_offset += data_size;
+
+ return 0;
+}
+
+static int xmv_fetch_video_packet(AVFormatContext *s,
+ AVPacket *pkt)
+{
+ XMVDemuxContext *xmv = s->priv_data;
+ AVIOContext *pb = s->pb;
+ XMVVideoPacket *video = &xmv->video;
+
+ int result;
+ uint32_t frame_header;
+ uint32_t frame_size, frame_timestamp;
+ uint8_t *data, *end;
+
+ /* Seek to it */
+ if (avio_seek(pb, video->data_offset, SEEK_SET) != video->data_offset)
+ return AVERROR(EIO);
+
+ /* Read the frame header */
+ frame_header = avio_rl32(pb);
+
+ frame_size = (frame_header & 0x1FFFF) * 4 + 4;
+ frame_timestamp = (frame_header >> 17);
+
+ if ((frame_size + 4) > video->data_size)
+ return AVERROR(EIO);
+
+ /* Get the packet data */
+ result = av_get_packet(pb, pkt, frame_size);
+ if (result != frame_size)
+ return result;
+
+ /* Contrary to normal WMV2 video, the bit stream in XMV's
+ * WMV2 is little-endian.
+ * TODO: This manual swap is of course suboptimal.
+ */
+ for (data = pkt->data, end = pkt->data + frame_size; data < end; data += 4)
+ AV_WB32(data, AV_RL32(data));
+
+ pkt->stream_index = video->stream_index;
+
+ /* Calculate the PTS */
+
+ video->last_pts = frame_timestamp + video->pts;
+
+ pkt->duration = 0;
+ pkt->pts = video->last_pts;
+ pkt->dts = AV_NOPTS_VALUE;
+
+ video->pts += frame_timestamp;
+
+ /* Keyframe? */
+ pkt->flags = (pkt->data[0] & 0x80) ? 0 : AV_PKT_FLAG_KEY;
+
+ /* Advance offset */
+ video->data_size -= frame_size + 4;
+ video->data_offset += frame_size + 4;
+
+ return 0;
+}
+
+static int xmv_read_packet(AVFormatContext *s,
+ AVPacket *pkt)
+{
+ XMVDemuxContext *xmv = s->priv_data;
+ int result;
+
+ if (xmv->video.current_frame == xmv->video.frame_count) {
+ /* No frames left in this packet, so we fetch a new one */
+
+ result = xmv_fetch_new_packet(s);
+ if (result)
+ return result;
+ }
+
+ if (xmv->current_stream == 0) {
+ /* Fetch a video frame */
+
+ result = xmv_fetch_video_packet(s, pkt);
+ if (result)
+ return result;
+
+ } else {
+ /* Fetch an audio frame */
+
+ result = xmv_fetch_audio_packet(s, pkt, xmv->current_stream - 1);
+ if (result)
+ return result;
+ }
+
+ /* Increase our counters */
+ if (++xmv->current_stream >= xmv->stream_count) {
+ xmv->current_stream = 0;
+ xmv->video.current_frame += 1;
+ }
+
+ return 0;
+}
+
+static int xmv_read_close(AVFormatContext *s)
+{
+ XMVDemuxContext *xmv = s->priv_data;
+
+ av_free(xmv->audio);
+
+ return 0;
+}
+
+AVInputFormat ff_xmv_demuxer = {
+ .name = "xmv",
+ .long_name = NULL_IF_CONFIG_SMALL("Microsoft XMV"),
+ .priv_data_size = sizeof(XMVDemuxContext),
+ .read_probe = xmv_probe,
+ .read_header = xmv_read_header,
+ .read_packet = xmv_read_packet,
+ .read_close = xmv_read_close,
+};
diff --git a/libavformat/xwma.c b/libavformat/xwma.c
index d18ab48795..94208abc47 100644
--- a/libavformat/xwma.c
+++ b/libavformat/xwma.c
@@ -2,20 +2,20 @@
* xWMA demuxer
* Copyright (c) 2011 Max Horn
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -69,7 +69,7 @@ static int xwma_read_header(AVFormatContext *s, AVFormatParameters *ap)
if (tag != MKTAG('f', 'm', 't', ' '))
return -1;
size = avio_rl32(pb);
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
@@ -252,10 +252,10 @@ static int xwma_read_packet(AVFormatContext *s, AVPacket *pkt)
}
AVInputFormat ff_xwma_demuxer = {
- "xwma",
- NULL_IF_CONFIG_SMALL("Microsoft xWMA"),
- sizeof(XWMAContext),
- xwma_probe,
- xwma_read_header,
- xwma_read_packet,
+ .name = "xwma",
+ .long_name = NULL_IF_CONFIG_SMALL("Microsoft xWMA"),
+ .priv_data_size = sizeof(XWMAContext),
+ .read_probe = xwma_probe,
+ .read_header = xwma_read_header,
+ .read_packet = xwma_read_packet,
};
diff --git a/libavformat/yop.c b/libavformat/yop.c
index e3671874a1..8cadf125a2 100644
--- a/libavformat/yop.c
+++ b/libavformat/yop.c
@@ -1,25 +1,24 @@
-/**
- * @file
+/*
* Psygnosis YOP demuxer
*
* Copyright (C) 2010 Mohamed Naufal Basheer <naufal11@gmail.com>
* derived from the code by
* Copyright (C) 2009 Thomas P. Higdon <thomas.p.higdon@gmail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -57,8 +56,8 @@ static int yop_read_header(AVFormatContext *s, AVFormatParameters *ap)
int frame_rate, ret;
- audio_stream = av_new_stream(s, 0);
- video_stream = av_new_stream(s, 1);
+ audio_stream = avformat_new_stream(s, NULL);
+ video_stream = avformat_new_stream(s, NULL);
// Extra data that will be passed to the decoder
video_stream->codec->extradata_size = 8;
@@ -184,8 +183,6 @@ static int yop_read_seek(AVFormatContext *s, int stream_index,
int64_t frame_pos, pos_min, pos_max;
int frame_count;
- av_free_packet(&yop->video_packet);
-
if (!stream_index)
return -1;
@@ -196,21 +193,25 @@ static int yop_read_seek(AVFormatContext *s, int stream_index,
timestamp = FFMAX(0, FFMIN(frame_count, timestamp));
frame_pos = timestamp * yop->frame_size + pos_min;
+
+ if (avio_seek(s->pb, frame_pos, SEEK_SET) < 0)
+ return -1;
+
+ av_free_packet(&yop->video_packet);
yop->odd_frame = timestamp & 1;
- avio_seek(s->pb, frame_pos, SEEK_SET);
return 0;
}
AVInputFormat ff_yop_demuxer = {
- "yop",
- NULL_IF_CONFIG_SMALL("Psygnosis YOP Format"),
- sizeof(YopDecContext),
- yop_probe,
- yop_read_header,
- yop_read_packet,
- yop_read_close,
- yop_read_seek,
+ .name = "yop",
+ .long_name = NULL_IF_CONFIG_SMALL("Psygnosis YOP Format"),
+ .priv_data_size = sizeof(YopDecContext),
+ .read_probe = yop_probe,
+ .read_header = yop_read_header,
+ .read_packet = yop_read_packet,
+ .read_close = yop_read_close,
+ .read_seek = yop_read_seek,
.extensions = "yop",
.flags = AVFMT_GENERIC_INDEX,
};
diff --git a/libavformat/yuv4mpeg.c b/libavformat/yuv4mpeg.c
index 9a6a0c8315..97d2261a93 100644
--- a/libavformat/yuv4mpeg.c
+++ b/libavformat/yuv4mpeg.c
@@ -2,20 +2,20 @@
* YUV4MPEG format
* Copyright (c) 2001, 2002, 2003 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avformat.h"
@@ -154,6 +154,12 @@ static int yuv4_write_header(AVFormatContext *s)
if (s->nb_streams != 1)
return AVERROR(EIO);
+ if (s->streams[0]->codec->codec_id != CODEC_ID_RAWVIDEO) {
+ av_log(s, AV_LOG_ERROR,
+ "A non-rawvideo stream was selected, but yuv4mpeg only handles rawvideo streams\n");
+ return AVERROR(EINVAL);
+ }
+
if (s->streams[0]->codec->pix_fmt == PIX_FMT_YUV411P) {
av_log(s, AV_LOG_ERROR, "Warning: generating rarely used 4:1:1 YUV stream, some mjpegtools might not work.\n");
}
@@ -170,15 +176,15 @@ static int yuv4_write_header(AVFormatContext *s)
}
AVOutputFormat ff_yuv4mpegpipe_muxer = {
- "yuv4mpegpipe",
- NULL_IF_CONFIG_SMALL("YUV4MPEG pipe format"),
- "",
- "y4m",
- sizeof(int),
- CODEC_ID_NONE,
- CODEC_ID_RAWVIDEO,
- yuv4_write_header,
- yuv4_write_packet,
+ .name = "yuv4mpegpipe",
+ .long_name = NULL_IF_CONFIG_SMALL("YUV4MPEG pipe format"),
+ .mime_type = "",
+ .extensions = "y4m",
+ .priv_data_size = sizeof(int),
+ .audio_codec = CODEC_ID_NONE,
+ .video_codec = CODEC_ID_RAWVIDEO,
+ .write_header = yuv4_write_header,
+ .write_packet = yuv4_write_packet,
.flags = AVFMT_RAWPICTURE,
};
#endif
@@ -327,7 +333,7 @@ static int yuv4_read_header(AVFormatContext *s, AVFormatParameters *ap)
aspectd = 1;
}
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if(!st)
return AVERROR(ENOMEM);
st->codec->width = width;
@@ -391,12 +397,12 @@ static int yuv4_probe(AVProbeData *pd)
#if CONFIG_YUV4MPEGPIPE_DEMUXER
AVInputFormat ff_yuv4mpegpipe_demuxer = {
- "yuv4mpegpipe",
- NULL_IF_CONFIG_SMALL("YUV4MPEG pipe format"),
- sizeof(struct frame_attributes),
- yuv4_probe,
- yuv4_read_header,
- yuv4_read_packet,
+ .name = "yuv4mpegpipe",
+ .long_name = NULL_IF_CONFIG_SMALL("YUV4MPEG pipe format"),
+ .priv_data_size = sizeof(struct frame_attributes),
+ .read_probe = yuv4_probe,
+ .read_header = yuv4_read_header,
+ .read_packet = yuv4_read_packet,
.extensions = "y4m"
};
#endif
diff --git a/libavutil/Makefile b/libavutil/Makefile
index c07217b803..3a5ceba16d 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -1,3 +1,5 @@
+include $(SUBDIR)../config.mak
+
NAME = avutil
HEADERS = adler32.h \
@@ -75,7 +77,9 @@ OBJS-$(ARCH_ARM) += arm/cpu.o
OBJS-$(ARCH_PPC) += ppc/cpu.o
OBJS-$(ARCH_X86) += x86/cpu.o
-TESTPROGS = adler32 aes base64 cpu crc des eval lls md5 sha tree
+
+TESTPROGS = adler32 aes avstring base64 cpu crc des eval file fifo lfg lls \
+ md5 opt pca parseutils rational sha tree
TESTPROGS-$(HAVE_LZO1X_999_COMPRESS) += lzo
DIRS = arm bfin sh4 x86
diff --git a/libavutil/adler32.h b/libavutil/adler32.h
index 913db2d0b6..0b890bcc11 100644
--- a/libavutil/adler32.h
+++ b/libavutil/adler32.h
@@ -1,20 +1,20 @@
/*
* copyright (c) 2006 Mans Rullgard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavutil/aes.c b/libavutil/aes.c
index ace317f38a..49093efc53 100644
--- a/libavutil/aes.c
+++ b/libavutil/aes.c
@@ -3,20 +3,20 @@
*
* some optimization ideas from aes128.c by Reimar Doeffinger
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavutil/aes.h b/libavutil/aes.h
index 6e5d320487..368f70cbbb 100644
--- a/libavutil/aes.h
+++ b/libavutil/aes.h
@@ -1,20 +1,20 @@
/*
* copyright (c) 2007 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavutil/arm/bswap.h b/libavutil/arm/bswap.h
index 478ae981fb..c5e74cc6d5 100644
--- a/libavutil/arm/bswap.h
+++ b/libavutil/arm/bswap.h
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavutil/arm/cpu.c b/libavutil/arm/cpu.c
index 835513ed84..742c3e498d 100644
--- a/libavutil/arm/cpu.c
+++ b/libavutil/arm/cpu.c
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavutil/arm/intmath.h b/libavutil/arm/intmath.h
index b6a45c1395..52af66e722 100644
--- a/libavutil/arm/intmath.h
+++ b/libavutil/arm/intmath.h
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2010 Mans Rullgard <mans@mansr.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -106,7 +106,7 @@ static av_always_inline av_const int32_t av_clipl_int32_arm(int64_t a)
"mvnne %1, #1<<31 \n\t"
"moveq %0, %Q2 \n\t"
"eorne %0, %1, %R2, asr #31 \n\t"
- : "=r"(x), "=&r"(y) : "r"(a));
+ : "=r"(x), "=&r"(y) : "r"(a):"cc");
return x;
}
diff --git a/libavutil/arm/intreadwrite.h b/libavutil/arm/intreadwrite.h
index 613abe511c..0292aabafd 100644
--- a/libavutil/arm/intreadwrite.h
+++ b/libavutil/arm/intreadwrite.h
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavutil/arm/timer.h b/libavutil/arm/timer.h
index 4bca877d00..5e8bc8edd0 100644
--- a/libavutil/arm/timer.h
+++ b/libavutil/arm/timer.h
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2009 Mans Rullgard <mans@mansr.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavutil/attributes.h b/libavutil/attributes.h
index ef990a1d4f..3f761ef679 100644
--- a/libavutil/attributes.h
+++ b/libavutil/attributes.h
@@ -1,20 +1,20 @@
/*
* copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -88,6 +88,24 @@
#endif
#endif
+/**
+ * Disable warnings about deprecated features
+ * This is useful for sections of code kept for backward compatibility and
+ * scheduled for removal.
+ */
+#ifndef AV_NOWARN_DEPRECATED
+#if AV_GCC_VERSION_AT_LEAST(4,6)
+# define AV_NOWARN_DEPRECATED(code) \
+ _Pragma("GCC diagnostic push") \
+ _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") \
+ code \
+ _Pragma("GCC diagnostic pop")
+#else
+# define AV_NOWARN_DEPRECATED(code) code
+#endif
+#endif
+
+
#ifndef av_unused
#if defined(__GNUC__)
# define av_unused __attribute__((unused))
@@ -118,7 +136,7 @@
#endif
#ifndef av_uninit
-#if defined(__GNUC__) && !defined(__ICC)
+#if defined(__GNUC__) && !defined(__INTEL_COMPILER)
# define av_uninit(x) x=x
#else
# define av_uninit(x) x
diff --git a/libavutil/audioconvert.c b/libavutil/audioconvert.c
index fa27f0168b..d89796de1a 100644
--- a/libavutil/audioconvert.c
+++ b/libavutil/audioconvert.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -28,11 +28,26 @@
#include "audioconvert.h"
static const char * const channel_names[] = {
- "FL", "FR", "FC", "LFE", "BL", "BR", "FLC", "FRC",
- "BC", "SL", "SR", "TC", "TFL", "TFC", "TFR", "TBL",
- "TBC", "TBR",
- [29] = "DL",
- [30] = "DR",
+ [0] = "FL", /* front left */
+ [1] = "FR", /* front right */
+ [2] = "FC", /* front center */
+ [3] = "LFE", /* low frequency */
+ [4] = "BL", /* back left */
+ [5] = "BR", /* back right */
+ [6] = "FLC", /* front left-of-center */
+ [7] = "FRC", /* front right-of-center */
+ [8] = "BC", /* back-center */
+ [9] = "SL", /* side left */
+ [10] = "SR", /* side right */
+ [11] = "TC", /* top center */
+ [12] = "TFL", /* top front left */
+ [13] = "TFC", /* top front center */
+ [14] = "TFR", /* top front right */
+ [15] = "TBL", /* top back left */
+ [16] = "TBC", /* top back center */
+ [17] = "TBR", /* top back right */
+ [29] = "DL", /* downmix left */
+ [30] = "DR", /* downmix right */
};
static const char *get_channel_name(int channel_id)
@@ -51,13 +66,13 @@ static const struct {
{ "stereo", 2, AV_CH_LAYOUT_STEREO },
{ "4.0", 4, AV_CH_LAYOUT_4POINT0 },
{ "quad", 4, AV_CH_LAYOUT_QUAD },
- { "5.0", 5, AV_CH_LAYOUT_5POINT0 },
+ { "5.0(side)", 5, AV_CH_LAYOUT_5POINT0 },
{ "5.0", 5, AV_CH_LAYOUT_5POINT0_BACK },
- { "5.1", 6, AV_CH_LAYOUT_5POINT1 },
+ { "5.1(side)", 6, AV_CH_LAYOUT_5POINT1 },
{ "5.1", 6, AV_CH_LAYOUT_5POINT1_BACK },
- { "5.1+downmix", 8, AV_CH_LAYOUT_5POINT1|AV_CH_LAYOUT_STEREO_DOWNMIX, },
{ "7.1", 8, AV_CH_LAYOUT_7POINT1 },
{ "7.1(wide)", 8, AV_CH_LAYOUT_7POINT1_WIDE },
+ { "5.1+downmix", 8, AV_CH_LAYOUT_5POINT1|AV_CH_LAYOUT_STEREO_DOWNMIX, },
{ "7.1+downmix", 10, AV_CH_LAYOUT_7POINT1|AV_CH_LAYOUT_STEREO_DOWNMIX, },
{ 0 }
};
@@ -91,13 +106,14 @@ void av_get_channel_layout_string(char *buf, int buf_size,
snprintf(buf, buf_size, "%d channels", nb_channels);
if (channel_layout) {
- int i,ch;
+ int i, ch;
av_strlcat(buf, " (", buf_size);
- for(i=0,ch=0; i<64; i++) {
- if ((channel_layout & (1L<<i))) {
+ for (i = 0, ch = 0; i < 64; i++) {
+ if ((channel_layout & (1L << i))) {
const char *name = get_channel_name(i);
if (name) {
- if (ch>0) av_strlcat(buf, "|", buf_size);
+ if (ch > 0)
+ av_strlcat(buf, "|", buf_size);
av_strlcat(buf, name, buf_size);
}
ch++;
@@ -115,3 +131,11 @@ int av_get_channel_layout_nb_channels(int64_t channel_layout)
x &= x-1; // unset lowest set bit
return count;
}
+
+int64_t av_get_default_channel_layout(int nb_channels) {
+ int i;
+ for (i = 0; channel_layout_map[i].name; i++)
+ if (nb_channels == channel_layout_map[i].nb_channels)
+ return channel_layout_map[i].layout;
+ return 0;
+}
diff --git a/libavutil/audioconvert.h b/libavutil/audioconvert.h
index e37a2e84c1..8cef7f650a 100644
--- a/libavutil/audioconvert.h
+++ b/libavutil/audioconvert.h
@@ -2,20 +2,20 @@
* Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
* Copyright (c) 2008 Peter Ross
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -92,4 +92,9 @@ void av_get_channel_layout_string(char *buf, int buf_size, int nb_channels, int6
*/
int av_get_channel_layout_nb_channels(int64_t channel_layout);
+/**
+ * Return default channel layout for a given number of channels.
+ */
+int64_t av_get_default_channel_layout(int nb_channels);
+
#endif /* AVUTIL_AUDIOCONVERT_H */
diff --git a/libavutil/avassert.h b/libavutil/avassert.h
index b223d26e8d..e100d0bfdd 100644
--- a/libavutil/avassert.h
+++ b/libavutil/avassert.h
@@ -1,20 +1,20 @@
/*
* copyright (c) 2010 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavutil/avr32/bswap.h b/libavutil/avr32/bswap.h
index 857f024054..e79d53f369 100644
--- a/libavutil/avr32/bswap.h
+++ b/libavutil/avr32/bswap.h
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavutil/avr32/intreadwrite.h b/libavutil/avr32/intreadwrite.h
index e0049feb09..c6fd3aa470 100644
--- a/libavutil/avr32/intreadwrite.h
+++ b/libavutil/avr32/intreadwrite.h
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2009 Mans Rullgard <mans@mansr.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavutil/avstring.c b/libavutil/avstring.c
index 2b8c2d4a1d..247cd71745 100644
--- a/libavutil/avstring.c
+++ b/libavutil/avstring.c
@@ -2,20 +2,20 @@
* Copyright (c) 2000, 2001, 2002 Fabrice Bellard
* Copyright (c) 2007 Mans Rullgard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -51,11 +51,11 @@ int av_stristart(const char *str, const char *pfx, const char **ptr)
char *av_stristr(const char *s1, const char *s2)
{
if (!*s2)
- return s1;
+ return (char*)(intptr_t)s1;
do {
if (av_stristart(s1, s2, NULL))
- return s1;
+ return (char*)(intptr_t)s1;
} while (*s1++);
return NULL;
@@ -91,6 +91,32 @@ size_t av_strlcatf(char *dst, size_t size, const char *fmt, ...)
return len;
}
+char *av_asprintf(const char *fmt, ...)
+{
+ char *p = NULL;
+ va_list va;
+ int len;
+
+ va_start(va, fmt);
+ len = vsnprintf(NULL, 0, fmt, va);
+ va_end(va);
+ if (len < 0)
+ goto end;
+
+ p = av_malloc(len + 1);
+ if (!p)
+ goto end;
+
+ va_start(va, fmt);
+ len = vsnprintf(p, len + 1, fmt, va);
+ va_end(va);
+ if (len < 0)
+ av_freep(&p);
+
+end:
+ return p;
+}
+
char *av_d2str(double d)
{
char *str= av_malloc(16);
@@ -134,6 +160,35 @@ char *av_get_token(const char **buf, const char *term)
return ret;
}
+char *av_strtok(char *s, const char *delim, char **saveptr)
+{
+ char *tok;
+
+ if (!s && !(s = *saveptr))
+ return NULL;
+
+ /* skip leading delimiters */
+ s += strspn(s, delim);
+
+ /* s now points to the first non delimiter char, or to the end of the string */
+ if (!*s) {
+ *saveptr = NULL;
+ return NULL;
+ }
+ tok = s++;
+
+ /* skip non delimiters */
+ s += strcspn(s, delim);
+ if (*s) {
+ *s = 0;
+ *saveptr = s+1;
+ } else {
+ *saveptr = NULL;
+ }
+
+ return tok;
+}
+
#ifdef TEST
#undef printf
diff --git a/libavutil/avstring.h b/libavutil/avstring.h
index 44ed89d654..0b2205a9be 100644
--- a/libavutil/avstring.h
+++ b/libavutil/avstring.h
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2007 Mans Rullgard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -111,6 +111,16 @@ size_t av_strlcat(char *dst, const char *src, size_t size);
size_t av_strlcatf(char *dst, size_t size, const char *fmt, ...) av_printf_format(3, 4);
/**
+ * Print arguments following specified format into a large enough auto
+ * allocated buffer. It is similar to GNU asprintf().
+ * @param fmt printf-compatible format string, specifying how the
+ * following parameters are used.
+ * @return the allocated string
+ * @note You have to free the string yourself with av_free().
+ */
+char *av_asprintf(const char *fmt, ...) av_printf_format(1, 2);
+
+/**
* Convert a number to a av_malloced string.
*/
char *av_d2str(double d);
@@ -131,4 +141,28 @@ char *av_d2str(double d);
*/
char *av_get_token(const char **buf, const char *term);
+/**
+ * Split the string into several tokens which can be accessed by
+ * successive calls to av_strtok().
+ *
+ * A token is defined as a sequence of characters not belonging to the
+ * set specified in delim.
+ *
+ * On the first call to av_strtok(), s should point to the string to
+ * parse, and the value of saveptr is ignored. In subsequent calls, s
+ * should be NULL, and saveptr should be unchanged since the previous
+ * call.
+ *
+ * This function is similar to strtok_r() defined in POSIX.1.
+ *
+ * @param s the string to parse, may be NULL
+ * @param delim 0-terminated list of token delimiters, must be non-NULL
+ * @param saveptr user-provided pointer which points to stored
+ * information necessary for av_strtok() to continue scanning the same
+ * string. saveptr is updated to point to the next character after the
+ * first delimiter found, or to NULL if the string was terminated
+ * @return the found token, or NULL when no token is found
+ */
+char *av_strtok(char *s, const char *delim, char **saveptr);
+
#endif /* AVUTIL_AVSTRING_H */
diff --git a/libavutil/avutil.h b/libavutil/avutil.h
index 01e4e2fb7f..d7eca65e6f 100644
--- a/libavutil/avutil.h
+++ b/libavutil/avutil.h
@@ -1,20 +1,20 @@
/*
* copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -40,7 +40,7 @@
#define AV_VERSION(a, b, c) AV_VERSION_DOT(a, b, c)
#define LIBAVUTIL_VERSION_MAJOR 51
-#define LIBAVUTIL_VERSION_MINOR 8
+#define LIBAVUTIL_VERSION_MINOR 22
#define LIBAVUTIL_VERSION_MICRO 0
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
@@ -57,12 +57,21 @@
* Those FF_API_* defines are not part of public API.
* They may change, break or disappear at any time.
*/
+#ifndef FF_API_OLD_EVAL_NAMES
+#define FF_API_OLD_EVAL_NAMES (LIBAVUTIL_VERSION_MAJOR < 52)
+#endif
#ifndef FF_API_GET_BITS_PER_SAMPLE_FMT
#define FF_API_GET_BITS_PER_SAMPLE_FMT (LIBAVUTIL_VERSION_MAJOR < 52)
#endif
#ifndef FF_API_FIND_OPT
#define FF_API_FIND_OPT (LIBAVUTIL_VERSION_MAJOR < 52)
#endif
+#ifndef FF_API_AV_FIFO_PEEK
+#define FF_API_AV_FIFO_PEEK (LIBAVUTIL_VERSION_MAJOR < 52)
+#endif
+#ifndef FF_API_OLD_AVOPTIONS
+#define FF_API_OLD_AVOPTIONS (LIBAVUTIL_VERSION_MAJOR < 52)
+#endif
/**
* Return the LIBAVUTIL_VERSION_INT constant.
@@ -89,6 +98,12 @@ enum AVMediaType {
AVMEDIA_TYPE_NB
};
+/**
+ * Return a string describing the media_type enum, NULL if media_type
+ * is unknown.
+ */
+const char *av_get_media_type_string(enum AVMediaType media_type);
+
#define FF_LAMBDA_SHIFT 7
#define FF_LAMBDA_SCALE (1<<FF_LAMBDA_SHIFT)
#define FF_QP2LAMBDA 118 ///< factor to convert from H.263 QP to lambda
@@ -101,7 +116,8 @@ enum AVMediaType {
#define AV_TIME_BASE_Q (AVRational){1, AV_TIME_BASE}
enum AVPictureType {
- AV_PICTURE_TYPE_I = 1, ///< Intra
+ AV_PICTURE_TYPE_NONE = 0, ///< Undefined
+ AV_PICTURE_TYPE_I, ///< Intra
AV_PICTURE_TYPE_P, ///< Predicted
AV_PICTURE_TYPE_B, ///< Bi-dir predicted
AV_PICTURE_TYPE_S, ///< S(GMC)-VOP MPEG4
@@ -119,7 +135,20 @@ enum AVPictureType {
*/
char av_get_picture_type_char(enum AVPictureType pict_type);
+/**
+ * Return x default pointer in case p is NULL.
+ */
+static inline const void *av_x_if_null(const void *p, const void *x)
+{
+ return p ? p : x;
+}
+
#include "common.h"
#include "error.h"
+#include "mathematics.h"
+#include "rational.h"
+#include "intfloat_readwrite.h"
+#include "log.h"
+#include "pixfmt.h"
#endif /* AVUTIL_AVUTIL_H */
diff --git a/libavutil/base64.c b/libavutil/base64.c
index 73872b8c99..1b70fa9f33 100644
--- a/libavutil/base64.c
+++ b/libavutil/base64.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2006 Ryan Martell. (rdm4@martellventures.com)
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavutil/base64.h b/libavutil/base64.h
index 96c0a4a41e..092980b093 100644
--- a/libavutil/base64.h
+++ b/libavutil/base64.h
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2006 Ryan Martell. (rdm4@martellventures.com)
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavutil/bfin/bswap.h b/libavutil/bfin/bswap.h
index 2837a2f7e1..363ed40bc5 100644
--- a/libavutil/bfin/bswap.h
+++ b/libavutil/bfin/bswap.h
@@ -1,20 +1,20 @@
/*
* Copyright (C) 2007 Marc Hoffman
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavutil/bfin/timer.h b/libavutil/bfin/timer.h
index 49d32a8f6b..644573daec 100644
--- a/libavutil/bfin/timer.h
+++ b/libavutil/bfin/timer.h
@@ -1,20 +1,20 @@
/*
* Copyright (C) 2007 Marc Hoffman
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavutil/bswap.h b/libavutil/bswap.h
index 3657ccd402..303bcf3532 100644
--- a/libavutil/bswap.h
+++ b/libavutil/bswap.h
@@ -1,20 +1,20 @@
/*
* copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -74,6 +74,11 @@ static av_always_inline av_const uint32_t av_bswap32(uint32_t x)
#ifndef av_bswap64
static inline uint64_t av_const av_bswap64(uint64_t x)
{
+#if 0
+ x= ((x<< 8)&0xFF00FF00FF00FF00ULL) | ((x>> 8)&0x00FF00FF00FF00FFULL);
+ x= ((x<<16)&0xFFFF0000FFFF0000ULL) | ((x>>16)&0x0000FFFF0000FFFFULL);
+ return (x>>32) | (x<<32);
+#else
union {
uint64_t ll;
uint32_t l[2];
@@ -82,6 +87,7 @@ static inline uint64_t av_const av_bswap64(uint64_t x)
r.l[0] = av_bswap32 (w.l[1]);
r.l[1] = av_bswap32 (w.l[0]);
return r.ll;
+#endif
}
#endif
diff --git a/libavutil/colorspace.h b/libavutil/colorspace.h
index 8757566c78..f438159811 100644
--- a/libavutil/colorspace.h
+++ b/libavutil/colorspace.h
@@ -2,20 +2,20 @@
* Colorspace conversion defines
* Copyright (c) 2001, 2002, 2003 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavutil/common.h b/libavutil/common.h
index 9691f5bcf8..d60e8638a5 100644
--- a/libavutil/common.h
+++ b/libavutil/common.h
@@ -1,20 +1,20 @@
/*
* copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -47,6 +47,8 @@
#define RSHIFT(a,b) ((a) > 0 ? ((a) + ((1<<(b))>>1))>>(b) : ((a) + ((1<<(b))>>1)-1)>>(b))
/* assume b>0 */
#define ROUNDED_DIV(a,b) (((a)>0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b))
+#define FFUDIV(a,b) (((a)>0 ?(a):(a)-(b)+1) / (b))
+#define FFUMOD(a,b) ((a)-(b)*FFUDIV(a,b))
#define FFABS(a) ((a) >= 0 ? (a) : (-(a)))
#define FFSIGN(a) ((a) > 0 ? 1 : -1)
diff --git a/libavutil/cpu.c b/libavutil/cpu.c
index baa7922daa..fa64a83cfa 100644
--- a/libavutil/cpu.c
+++ b/libavutil/cpu.c
@@ -1,28 +1,33 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "cpu.h"
#include "config.h"
+static int flags, checked;
+
+void av_force_cpu_flags(int arg){
+ flags = arg;
+ checked = 1;
+}
+
int av_get_cpu_flags(void)
{
- static int flags, checked;
-
if (checked)
return flags;
@@ -60,6 +65,8 @@ static const struct {
{ AV_CPU_FLAG_SSE4, "sse4.1" },
{ AV_CPU_FLAG_SSE42, "sse4.2" },
{ AV_CPU_FLAG_AVX, "avx" },
+ { AV_CPU_FLAG_XOP, "xop" },
+ { AV_CPU_FLAG_FMA4, "fma4" },
{ AV_CPU_FLAG_3DNOW, "3dnow" },
{ AV_CPU_FLAG_3DNOWEXT, "3dnowext" },
#endif
diff --git a/libavutil/cpu.h b/libavutil/cpu.h
index 777cdc01d1..5f7eed2b60 100644
--- a/libavutil/cpu.h
+++ b/libavutil/cpu.h
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2000, 2001, 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -38,6 +38,8 @@
#define AV_CPU_FLAG_SSE4 0x0100 ///< Penryn SSE4.1 functions
#define AV_CPU_FLAG_SSE42 0x0200 ///< Nehalem SSE4.2 functions
#define AV_CPU_FLAG_AVX 0x4000 ///< AVX functions: requires OS support even if YMM registers aren't used
+#define AV_CPU_FLAG_XOP 0x0400 ///< Bulldozer XOP functions
+#define AV_CPU_FLAG_FMA4 0x0800 ///< Bulldozer FMA4 functions
#define AV_CPU_FLAG_IWMMXT 0x0100 ///< XScale IWMMXT
#define AV_CPU_FLAG_ALTIVEC 0x0001 ///< standard
@@ -46,6 +48,13 @@
*/
int av_get_cpu_flags(void);
+
+/**
+ * Disables cpu detection and forces the specified flags.
+ */
+void av_force_cpu_flags(int flags);
+
+
/* The following CPU-specific functions shall not be called directly. */
int ff_get_cpu_flags_arm(void);
int ff_get_cpu_flags_ppc(void);
diff --git a/libavutil/crc.c b/libavutil/crc.c
index 6c9f92809f..d0e736ed4d 100644
--- a/libavutil/crc.c
+++ b/libavutil/crc.c
@@ -1,20 +1,20 @@
/*
* copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -57,7 +57,7 @@ static AVCRC av_crc_table[AV_CRC_MAX][257];
* @return <0 on failure
*/
int av_crc_init(AVCRC *ctx, int le, int bits, uint32_t poly, int ctx_size){
- int i, j;
+ unsigned i, j;
uint32_t c;
if (bits < 8 || bits > 32 || poly >= (1LL<<bits))
diff --git a/libavutil/crc.h b/libavutil/crc.h
index a934119413..6c0baab5ac 100644
--- a/libavutil/crc.h
+++ b/libavutil/crc.h
@@ -1,20 +1,20 @@
/*
* copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavutil/crc_data.h b/libavutil/crc_data.h
index 8e4e6af31f..afa25e7cfc 100644
--- a/libavutil/crc_data.h
+++ b/libavutil/crc_data.h
@@ -1,20 +1,20 @@
/*
* copyright (c) 2008 Aurelien Jacobs <aurel@gnuage.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavutil/des.c b/libavutil/des.c
index db2227b6ec..b876dccd53 100644
--- a/libavutil/des.c
+++ b/libavutil/des.c
@@ -2,20 +2,20 @@
* DES encryption/decryption
* Copyright (c) 2007 Reimar Doeffinger
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <inttypes.h>
@@ -39,7 +39,7 @@ static const uint8_t IP_shuffle[] = {
};
#undef T
-#if defined(CONFIG_SMALL) || defined(GENTABLES)
+#if CONFIG_SMALL || defined(GENTABLES)
#define T(a, b, c, d) 32-a,32-b,32-c,32-d
static const uint8_t P_shuffle[] = {
T(16, 7, 20, 21),
@@ -298,7 +298,7 @@ int av_des_init(AVDES *d, const uint8_t *key, int key_bits, int decrypt) {
return 0;
}
-void av_des_crypt(AVDES *d, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv, int decrypt) {
+static void av_des_crypt_mac(AVDES *d, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv, int decrypt, int mac) {
uint64_t iv_val = iv ? AV_RB64(iv) : 0;
while (count-- > 0) {
uint64_t dst_val;
@@ -321,12 +321,21 @@ void av_des_crypt(AVDES *d, uint8_t *dst, const uint8_t *src, int count, uint8_t
}
AV_WB64(dst, dst_val);
src += 8;
- dst += 8;
+ if (!mac)
+ dst += 8;
}
if (iv)
AV_WB64(iv, iv_val);
}
+void av_des_crypt(AVDES *d, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv, int decrypt) {
+ av_des_crypt_mac(d, dst, src, count, iv, decrypt, 0);
+}
+
+void av_des_mac(AVDES *d, uint8_t *dst, const uint8_t *src, int count) {
+ av_des_crypt_mac(d, dst, src, count, (uint8_t[8]){0}, 0, 1);
+}
+
#ifdef TEST
#undef printf
#undef rand
diff --git a/libavutil/des.h b/libavutil/des.h
index 935d7c5d71..2feb0468db 100644
--- a/libavutil/des.h
+++ b/libavutil/des.h
@@ -2,20 +2,20 @@
* DES encryption/decryption
* Copyright (c) 2007 Reimar Doeffinger
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -33,7 +33,7 @@ struct AVDES {
* @brief Initializes an AVDES context.
*
* @param key_bits must be 64 or 192
- * @param decrypt 0 for encryption, 1 for decryption
+ * @param decrypt 0 for encryption/CBC-MAC, 1 for decryption
*/
int av_des_init(struct AVDES *d, const uint8_t *key, int key_bits, int decrypt);
@@ -49,4 +49,13 @@ int av_des_init(struct AVDES *d, const uint8_t *key, int key_bits, int decrypt);
*/
void av_des_crypt(struct AVDES *d, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv, int decrypt);
+/**
+ * @brief Calculates CBC-MAC using the DES algorithm.
+ *
+ * @param count number of 8 byte blocks
+ * @param dst destination array, can be equal to src, must be 8-byte aligned
+ * @param src source array, can be equal to dst, must be 8-byte aligned, may be NULL
+ */
+void av_des_mac(struct AVDES *d, uint8_t *dst, const uint8_t *src, int count);
+
#endif /* AVUTIL_DES_H */
diff --git a/libavutil/dict.c b/libavutil/dict.c
index 3ea7e55b30..a0e7fb4c0e 100644
--- a/libavutil/dict.c
+++ b/libavutil/dict.c
@@ -1,20 +1,20 @@
/*
* copyright (c) 2009 Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -75,11 +75,11 @@ int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags
}
if (value) {
if (flags & AV_DICT_DONT_STRDUP_KEY) {
- m->elems[m->count].key = key;
+ m->elems[m->count].key = (char*)(intptr_t)key;
} else
m->elems[m->count].key = av_strdup(key );
if (flags & AV_DICT_DONT_STRDUP_VAL) {
- m->elems[m->count].value = value;
+ m->elems[m->count].value = (char*)(intptr_t)value;
} else if (oldval && flags & AV_DICT_APPEND) {
int len = strlen(oldval) + strlen(value) + 1;
if (!(oldval = av_realloc(oldval, len)))
diff --git a/libavutil/dict.h b/libavutil/dict.h
index 397ce3852f..84f58ec473 100644
--- a/libavutil/dict.h
+++ b/libavutil/dict.h
@@ -1,34 +1,72 @@
/*
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* Public dictionary API.
+ * @deprecated
+ * AVDictionary is provided for compatibility with libav. It is both in
+ * implementation as well as API inefficient. It does not scale and is
+ * extremely slow with large dictionaries.
+ * It is recommended that new code uses our tree container from tree.c/h
+ * where applicable, which uses AVL trees to achieve O(log n) performance.
*/
#ifndef AVUTIL_DICT_H
#define AVUTIL_DICT_H
+/**
+ * @defgroup dict_api Public Dictionary API
+ * @{
+ * Dictionaries are used for storing key:value pairs. To create
+ * an AVDictionary, simply pass an address of a NULL pointer to
+ * av_dict_set(). NULL can be used as an empty dictionary wherever
+ * a pointer to an AVDictionary is required.
+ * Use av_dict_get() to retrieve an entry or iterate over all
+ * entries and finally av_dict_free() to free the dictionary
+ * and all its contents.
+ *
+ * @code
+ * AVDictionary *d = NULL; // "create" an empty dictionary
+ * av_dict_set(&d, "foo", "bar", 0); // add an entry
+ *
+ * char *k = av_strdup("key"); // if your strings are already allocated,
+ * char *v = av_strdup("value"); // you can avoid copying them like this
+ * av_dict_set(&d, k, v, AV_DICT_DONT_STRDUP_KEY | AV_DICT_DONT_STRDUP_VAL);
+ *
+ * AVDictionaryEntry *t = NULL;
+ * while (t = av_dict_get(d, "", t, AV_DICT_IGNORE_SUFFIX)) {
+ * <....> // iterate over all entries in d
+ * }
+ *
+ * av_dict_free(&d);
+ * @endcode
+ *
+ * @}
+ */
+
#define AV_DICT_MATCH_CASE 1
#define AV_DICT_IGNORE_SUFFIX 2
-#define AV_DICT_DONT_STRDUP_KEY 4
-#define AV_DICT_DONT_STRDUP_VAL 8
+#define AV_DICT_DONT_STRDUP_KEY 4 /**< Take ownership of a key that's been
+ allocated with av_malloc() and children. */
+#define AV_DICT_DONT_STRDUP_VAL 8 /**< Take ownership of a value that's been
+ allocated with av_malloc() and chilren. */
#define AV_DICT_DONT_OVERWRITE 16 ///< Don't overwrite existing entries.
#define AV_DICT_APPEND 32 /**< If the entry already exists, append to it. Note that no
delimiter is added, the strings are simply concatenated. */
@@ -74,7 +112,8 @@ int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags
void av_dict_copy(AVDictionary **dst, AVDictionary *src, int flags);
/**
- * Free all the memory allocated for an AVDictionary struct.
+ * Free all the memory allocated for an AVDictionary struct
+ * and all keys and values.
*/
void av_dict_free(AVDictionary **m);
diff --git a/libavutil/error.c b/libavutil/error.c
index ddcc038650..d296395c09 100644
--- a/libavutil/error.c
+++ b/libavutil/error.c
@@ -1,21 +1,22 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#undef _GNU_SOURCE
#include "avutil.h"
#include "avstring.h"
@@ -35,7 +36,7 @@ int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
case AVERROR_INVALIDDATA: errstr = "Invalid data found when processing input" ; break;
case AVERROR_MUXER_NOT_FOUND: errstr = "Muxer not found" ; break;
case AVERROR_OPTION_NOT_FOUND: errstr = "Option not found" ; break;
- case AVERROR_PATCHWELCOME: errstr = "Not yet implemented in Libav, patches welcome"; break;
+ case AVERROR_PATCHWELCOME: errstr = "Not yet implemented in FFmpeg, patches welcome"; break;
case AVERROR_PROTOCOL_NOT_FOUND:errstr = "Protocol not found" ; break;
case AVERROR_STREAM_NOT_FOUND: errstr = "Stream not found" ; break;
}
diff --git a/libavutil/error.h b/libavutil/error.h
index ba12d2bfae..47d366ebbc 100644
--- a/libavutil/error.h
+++ b/libavutil/error.h
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -47,7 +47,7 @@
#define AVERROR_INVALIDDATA (-MKTAG( 'I','N','D','A')) ///< Invalid data found when processing input
#define AVERROR_MUXER_NOT_FOUND (-MKTAG(0xF8,'M','U','X')) ///< Muxer not found
#define AVERROR_OPTION_NOT_FOUND (-MKTAG(0xF8,'O','P','T')) ///< Option not found
-#define AVERROR_PATCHWELCOME (-MKTAG( 'P','A','W','E')) ///< Not yet implemented in Libav, patches welcome
+#define AVERROR_PATCHWELCOME (-MKTAG( 'P','A','W','E')) ///< Not yet implemented in FFmpeg, patches welcome
#define AVERROR_PROTOCOL_NOT_FOUND (-MKTAG(0xF8,'P','R','O')) ///< Protocol not found
#define AVERROR_STREAM_NOT_FOUND (-MKTAG(0xF8,'S','T','R')) ///< Stream not found
diff --git a/libavutil/eval.c b/libavutil/eval.c
index 4d55f42664..3a8b60d505 100644
--- a/libavutil/eval.c
+++ b/libavutil/eval.c
@@ -2,20 +2,20 @@
* Copyright (c) 2002-2006 Michael Niedermayer <michaelni@gmx.at>
* Copyright (c) 2006 Oded Shimon <ods15@ods15.dyndns.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -44,7 +44,7 @@ typedef struct Parser {
int log_offset;
void *log_ctx;
#define VARS 10
- double var[VARS];
+ double *var;
} Parser;
static const AVClass class = { "Eval", av_default_item_name, NULL, LIBAVUTIL_VERSION_INT, offsetof(Parser,log_offset), offsetof(Parser,log_ctx) };
@@ -72,11 +72,23 @@ static const int8_t si_prefixes['z' - 'E' + 1] = {
['Y'-'E']= 24,
};
+static const struct {
+ const char *name;
+ double value;
+} constants[] = {
+ { "E", M_E },
+ { "PI", M_PI },
+ { "PHI", M_PHI },
+};
+
double av_strtod(const char *numstr, char **tail)
{
double d;
char *next;
- d = strtod(numstr, &next);
+ if(numstr[0]=='0' && (numstr[1]|0x20)=='x') {
+ d = strtoul(numstr, &next, 16);
+ } else
+ d = strtod(numstr, &next);
/* if parsing succeeded, check for and interpret postfixes */
if (next!=numstr) {
if (*next >= 'E' && *next <= 'z') {
@@ -123,6 +135,7 @@ struct AVExpr {
e_mod, e_max, e_min, e_eq, e_gt, e_gte,
e_pow, e_mul, e_div, e_add,
e_last, e_st, e_while, e_floor, e_ceil, e_trunc,
+ e_sqrt, e_not, e_random, e_hypot, e_gcd,
} type;
double value; // is sign in other types
union {
@@ -132,6 +145,7 @@ struct AVExpr {
double (*func2)(void *, double, double);
} a;
struct AVExpr *param[2];
+ double *var;
};
static double eval_expr(Parser *p, AVExpr *e)
@@ -149,6 +163,15 @@ static double eval_expr(Parser *p, AVExpr *e)
case e_floor: return e->value * floor(eval_expr(p, e->param[0]));
case e_ceil : return e->value * ceil (eval_expr(p, e->param[0]));
case e_trunc: return e->value * trunc(eval_expr(p, e->param[0]));
+ case e_sqrt: return e->value * sqrt (eval_expr(p, e->param[0]));
+ case e_not: return e->value * (eval_expr(p, e->param[0]) == 0);
+ case e_random:{
+ int idx= av_clip(eval_expr(p, e->param[0]), 0, VARS-1);
+ uint64_t r= isnan(p->var[idx]) ? 0 : p->var[idx];
+ r= r*1664525+1013904223;
+ p->var[idx]= r;
+ return e->value * (r * (1.0/UINT64_MAX));
+ }
case e_while: {
double d = NAN;
while (eval_expr(p, e->param[0]))
@@ -160,6 +183,7 @@ static double eval_expr(Parser *p, AVExpr *e)
double d2 = eval_expr(p, e->param[1]);
switch (e->type) {
case e_mod: return e->value * (d - floor(d/d2)*d2);
+ case e_gcd: return e->value * av_gcd(d,d2);
case e_max: return e->value * (d > d2 ? d : d2);
case e_min: return e->value * (d < d2 ? d : d2);
case e_eq: return e->value * (d == d2 ? 1.0 : 0.0);
@@ -171,6 +195,7 @@ static double eval_expr(Parser *p, AVExpr *e)
case e_add: return e->value * (d + d2);
case e_last:return e->value * d2;
case e_st : return e->value * (p->var[av_clip(d, 0, VARS-1)]= d2);
+ case e_hypot:return e->value * (sqrt(d*d + d2*d2));
}
}
}
@@ -184,6 +209,7 @@ void av_expr_free(AVExpr *e)
if (!e) return;
av_expr_free(e->param[0]);
av_expr_free(e->param[1]);
+ av_freep(&e->var);
av_freep(&e);
}
@@ -216,6 +242,15 @@ static int parse_primary(AVExpr **e, Parser *p)
return 0;
}
}
+ for (i = 0; i < FF_ARRAY_ELEMS(constants); i++) {
+ if (strmatch(p->s, constants[i].name)) {
+ p->s += strlen(constants[i].name);
+ d->type = e_value;
+ d->value = constants[i].value;
+ *e = d;
+ return 0;
+ }
+ }
p->s= strchr(p->s, '(');
if (p->s==NULL) {
@@ -283,6 +318,12 @@ static int parse_primary(AVExpr **e, Parser *p)
else if (strmatch(next, "floor" )) d->type = e_floor;
else if (strmatch(next, "ceil" )) d->type = e_ceil;
else if (strmatch(next, "trunc" )) d->type = e_trunc;
+ else if (strmatch(next, "sqrt" )) d->type = e_sqrt;
+ else if (strmatch(next, "not" )) d->type = e_not;
+ else if (strmatch(next, "pow" )) d->type = e_pow;
+ else if (strmatch(next, "random")) d->type = e_random;
+ else if (strmatch(next, "hypot" )) d->type = e_hypot;
+ else if (strmatch(next, "gcd" )) d->type = e_gcd;
else {
for (i=0; p->func1_names && p->func1_names[i]; i++) {
if (strmatch(next, p->func1_names[i])) {
@@ -450,6 +491,9 @@ static int verify_expr(AVExpr *e)
case e_floor:
case e_ceil:
case e_trunc:
+ case e_sqrt:
+ case e_not:
+ case e_random:
return verify_expr(e->param[0]);
default: return verify_expr(e->param[0]) && verify_expr(e->param[1]);
}
@@ -489,6 +533,7 @@ int av_expr_parse(AVExpr **expr, const char *s,
if ((ret = parse_expr(&e, &p)) < 0)
goto end;
if (*p.s) {
+ av_expr_free(e);
av_log(&p, AV_LOG_ERROR, "Invalid chars '%s' at the end of expression '%s'\n", p.s, s0);
ret = AVERROR(EINVAL);
goto end;
@@ -498,6 +543,7 @@ int av_expr_parse(AVExpr **expr, const char *s,
ret = AVERROR(EINVAL);
goto end;
}
+ e->var= av_mallocz(sizeof(double) *VARS);
*expr = e;
end:
av_free(w);
@@ -507,6 +553,7 @@ end:
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
{
Parser p = { 0 };
+ p.var= e->var;
p.const_values = const_values;
p.opaque = opaque;
@@ -531,6 +578,38 @@ int av_expr_parse_and_eval(double *d, const char *s,
return isnan(*d) ? AVERROR(EINVAL) : 0;
}
+#if FF_API_OLD_EVAL_NAMES
+int av_parse_expr(AVExpr **expr, const char *s,
+ const char * const *const_names,
+ const char * const *func1_names, double (* const *funcs1)(void *, double),
+ const char * const *func2_names, double (* const *funcs2)(void *, double, double),
+ int log_offset, void *log_ctx)
+{
+ return av_expr_parse(expr, s, const_names, func1_names, funcs1, func2_names, funcs2,
+ log_offset, log_ctx);
+}
+
+double av_eval_expr(AVExpr *e, const double *const_values, void *opaque)
+{
+ return av_expr_eval(e, const_values, opaque);
+}
+
+int av_parse_and_eval_expr(double *res, const char *s,
+ const char * const *const_names, const double *const_values,
+ const char * const *func1_names, double (* const *funcs1)(void *, double),
+ const char * const *func2_names, double (* const *funcs2)(void *, double, double),
+ void *opaque, int log_offset, void *log_ctx)
+{
+ return av_expr_parse_and_eval(res, s, const_names, const_values, func1_names, funcs1, func2_names, funcs2,
+ opaque, log_offset, log_ctx);
+}
+
+void av_free_expr(AVExpr *e)
+{
+ av_expr_free(e);
+}
+#endif /* FF_API_OLD_EVAL_NAMES */
+
#ifdef TEST
#undef printf
#include <string.h>
@@ -558,7 +637,7 @@ int main(int argc, char **argv)
"-PI",
"+PI",
"1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)",
- "80G/80Gi"
+ "80G/80Gi",
"1k",
"1Gi",
"1gi",
@@ -599,6 +678,15 @@ int main(int argc, char **argv)
"trunc(-123.123)",
"ceil(123.123)",
"ceil(-123.123)",
+ "sqrt(1764)",
+ "isnan(sqrt(-1))",
+ "not(1)",
+ "not(NAN)",
+ "not(0)",
+ "pow(0,1.23)",
+ "pow(PI,1.23)",
+ "PI^1.23",
+ "pow(-1,1.23)",
NULL
};
@@ -607,7 +695,11 @@ int main(int argc, char **argv)
av_expr_parse_and_eval(&d, *expr,
const_names, const_values,
NULL, NULL, NULL, NULL, NULL, 0, NULL);
- printf("'%s' -> %f\n\n", *expr, d);
+ if(isnan(d)){
+ printf("'%s' -> nan\n\n", *expr);
+ }else{
+ printf("'%s' -> %f\n\n", *expr, d);
+ }
}
av_expr_parse_and_eval(&d, "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)",
diff --git a/libavutil/eval.h b/libavutil/eval.h
index c485c69fb1..ee378a29b4 100644
--- a/libavutil/eval.h
+++ b/libavutil/eval.h
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2002 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -91,6 +91,39 @@ double av_expr_eval(AVExpr *e, const double *const_values, void *opaque);
*/
void av_expr_free(AVExpr *e);
+#if FF_API_OLD_EVAL_NAMES
+/**
+ * @deprecated Deprecated in favor of av_expr_parse_and_eval().
+ */
+attribute_deprecated
+int av_parse_and_eval_expr(double *res, const char *s,
+ const char * const *const_names, const double *const_values,
+ const char * const *func1_names, double (* const *funcs1)(void *, double),
+ const char * const *func2_names, double (* const *funcs2)(void *, double, double),
+ void *opaque, int log_offset, void *log_ctx);
+
+/**
+ * @deprecated Deprecated in favor of av_expr_parse().
+ */
+attribute_deprecated
+int av_parse_expr(AVExpr **expr, const char *s,
+ const char * const *const_names,
+ const char * const *func1_names, double (* const *funcs1)(void *, double),
+ const char * const *func2_names, double (* const *funcs2)(void *, double, double),
+ int log_offset, void *log_ctx);
+/**
+ * @deprecated Deprecated in favor of av_expr_eval().
+ */
+attribute_deprecated
+double av_eval_expr(AVExpr *e, const double *const_values, void *opaque);
+
+/**
+ * @deprecated Deprecated in favor of av_expr_free().
+ */
+attribute_deprecated
+void av_free_expr(AVExpr *e);
+#endif /* FF_API_OLD_EVAL_NAMES */
+
/**
* Parse the string in numstr and return its value as a double. If
* the string is empty, contains only whitespaces, or does not contain
diff --git a/libavutil/fifo.c b/libavutil/fifo.c
index f87a99dee5..3ebd5f9b20 100644
--- a/libavutil/fifo.c
+++ b/libavutil/fifo.c
@@ -3,20 +3,20 @@
* Copyright (c) 2000, 2001, 2002 Fabrice Bellard
* Copyright (c) 2006 Roman Shaposhnik
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "common.h"
@@ -25,7 +25,7 @@
AVFifoBuffer *av_fifo_alloc(unsigned int size)
{
AVFifoBuffer *f= av_mallocz(sizeof(AVFifoBuffer));
- if(!f)
+ if (!f)
return NULL;
f->buffer = av_malloc(size);
f->end = f->buffer + size;
@@ -37,8 +37,8 @@ AVFifoBuffer *av_fifo_alloc(unsigned int size)
void av_fifo_free(AVFifoBuffer *f)
{
- if(f){
- av_free(f->buffer);
+ if (f) {
+ av_freep(&f->buffer);
av_free(f);
}
}
@@ -59,20 +59,21 @@ int av_fifo_space(AVFifoBuffer *f)
return f->end - f->buffer - av_fifo_size(f);
}
-int av_fifo_realloc2(AVFifoBuffer *f, unsigned int new_size) {
- unsigned int old_size= f->end - f->buffer;
+int av_fifo_realloc2(AVFifoBuffer *f, unsigned int new_size)
+{
+ unsigned int old_size = f->end - f->buffer;
- if(old_size < new_size){
- int len= av_fifo_size(f);
- AVFifoBuffer *f2= av_fifo_alloc(new_size);
+ if (old_size < new_size) {
+ int len = av_fifo_size(f);
+ AVFifoBuffer *f2 = av_fifo_alloc(new_size);
if (!f2)
- return -1;
+ return AVERROR(ENOMEM);
av_fifo_generic_read(f, f2->buffer, len, NULL);
f2->wptr += len;
f2->wndx += len;
av_free(f->buffer);
- *f= *f2;
+ *f = *f2;
av_free(f2);
}
return 0;
@@ -84,8 +85,8 @@ int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int (*func)(void
int total = size;
do {
int len = FFMIN(f->end - f->wptr, size);
- if(func) {
- if(func(src, f->wptr, len) <= 0)
+ if (func) {
+ if (func(src, f->wptr, len) <= 0)
break;
} else {
memcpy(f->wptr, src, len);
@@ -127,3 +128,39 @@ void av_fifo_drain(AVFifoBuffer *f, int size)
f->rptr -= f->end - f->buffer;
f->rndx += size;
}
+
+#ifdef TEST
+
+#undef printf
+
+int main(void)
+{
+ /* create a FIFO buffer */
+ AVFifoBuffer *fifo = av_fifo_alloc(13 * sizeof(int));
+ int i, j, n;
+
+ /* fill data */
+ for (i = 0; av_fifo_space(fifo) >= sizeof(int); i++)
+ av_fifo_generic_write(fifo, &i, sizeof(int), NULL);
+
+ /* peek at FIFO */
+ n = av_fifo_size(fifo)/sizeof(int);
+ for (i = -n+1; i < n; i++) {
+ int *v = (int *)av_fifo_peek2(fifo, i*sizeof(int));
+ printf("%d: %d\n", i, *v);
+ }
+ printf("\n");
+
+ /* read data */
+ for (i = 0; av_fifo_size(fifo) >= sizeof(int); i++) {
+ av_fifo_generic_read(fifo, &j, sizeof(int), NULL);
+ printf("%d ", j);
+ }
+ printf("\n");
+
+ av_fifo_free(fifo);
+
+ return 0;
+}
+
+#endif
diff --git a/libavutil/fifo.h b/libavutil/fifo.h
index cd361b0222..22a9aa5d18 100644
--- a/libavutil/fifo.h
+++ b/libavutil/fifo.h
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -25,6 +25,7 @@
#define AVUTIL_FIFO_H
#include <stdint.h>
+#include "avutil.h"
typedef struct AVFifoBuffer {
uint8_t *buffer;
@@ -41,20 +42,20 @@ AVFifoBuffer *av_fifo_alloc(unsigned int size);
/**
* Free an AVFifoBuffer.
- * @param *f AVFifoBuffer to free
+ * @param f AVFifoBuffer to free
*/
void av_fifo_free(AVFifoBuffer *f);
/**
* Reset the AVFifoBuffer to the state right after av_fifo_alloc, in particular it is emptied.
- * @param *f AVFifoBuffer to reset
+ * @param f AVFifoBuffer to reset
*/
void av_fifo_reset(AVFifoBuffer *f);
/**
* Return the amount of data in bytes in the AVFifoBuffer, that is the
* amount of data you can read from it.
- * @param *f AVFifoBuffer to read from
+ * @param f AVFifoBuffer to read from
* @return size
*/
int av_fifo_size(AVFifoBuffer *f);
@@ -62,27 +63,27 @@ int av_fifo_size(AVFifoBuffer *f);
/**
* Return the amount of space in bytes in the AVFifoBuffer, that is the
* amount of data you can write into it.
- * @param *f AVFifoBuffer to write into
+ * @param f AVFifoBuffer to write into
* @return size
*/
int av_fifo_space(AVFifoBuffer *f);
/**
* Feed data from an AVFifoBuffer to a user-supplied callback.
- * @param *f AVFifoBuffer to read from
+ * @param f AVFifoBuffer to read from
* @param buf_size number of bytes to read
- * @param *func generic read function
- * @param *dest data destination
+ * @param func generic read function
+ * @param dest data destination
*/
int av_fifo_generic_read(AVFifoBuffer *f, void *dest, int buf_size, void (*func)(void*, void*, int));
/**
* Feed data from a user-supplied callback to an AVFifoBuffer.
- * @param *f AVFifoBuffer to write to
- * @param *src data source; non-const since it may be used as a
+ * @param f AVFifoBuffer to write to
+ * @param src data source; non-const since it may be used as a
* modifiable context by the function defined in func
* @param size number of bytes to write
- * @param *func generic write function; the first parameter is src,
+ * @param func generic write function; the first parameter is src,
* the second is dest_buf, the third is dest_buf_size.
* func must return the number of bytes written to dest_buf, or <= 0 to
* indicate no more data available to write.
@@ -93,7 +94,9 @@ int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int (*func)(void
/**
* Resize an AVFifoBuffer.
- * @param *f AVFifoBuffer to resize
+ * In case of reallocation failure, the old FIFO is kept unchanged.
+ *
+ * @param f AVFifoBuffer to resize
* @param size new AVFifoBuffer size in bytes
* @return <0 for failure, >=0 otherwise
*/
@@ -101,16 +104,40 @@ int av_fifo_realloc2(AVFifoBuffer *f, unsigned int size);
/**
* Read and discard the specified amount of data from an AVFifoBuffer.
- * @param *f AVFifoBuffer to read from
+ * @param f AVFifoBuffer to read from
* @param size amount of data to read in bytes
*/
void av_fifo_drain(AVFifoBuffer *f, int size);
-static inline uint8_t av_fifo_peek(AVFifoBuffer *f, int offs)
+/**
+ * Return a pointer to the data stored in a FIFO buffer at a certain offset.
+ * The FIFO buffer is not modified.
+ *
+ * @param f AVFifoBuffer to peek at, f must be non-NULL
+ * @param offs an offset in bytes, its absolute value must be less
+ * than the used buffer size or the returned pointer will
+ * point outside to the buffer data.
+ * The used buffer size can be checked with av_fifo_size().
+ */
+static inline uint8_t *av_fifo_peek2(const AVFifoBuffer *f, int offs)
{
uint8_t *ptr = f->rptr + offs;
if (ptr >= f->end)
- ptr -= f->end - f->buffer;
- return *ptr;
+ ptr = f->buffer + (ptr - f->end);
+ else if (ptr < f->buffer)
+ ptr = f->end - (f->buffer - ptr);
+ return ptr;
+}
+
+#if FF_API_AV_FIFO_PEEK
+/**
+ * @deprecated Use av_fifo_peek2() instead.
+ */
+attribute_deprecated
+static inline uint8_t av_fifo_peek(AVFifoBuffer *f, int offs)
+{
+ return *av_fifo_peek2(f, offs);
}
+#endif
+
#endif /* AVUTIL_FIFO_H */
diff --git a/libavutil/file.c b/libavutil/file.c
index 649bb767a0..e59335a77a 100644
--- a/libavutil/file.c
+++ b/libavutil/file.c
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -130,6 +130,52 @@ void av_file_unmap(uint8_t *bufptr, size_t size)
#endif
}
+int av_tempfile(const char *prefix, char **filename, int log_offset, void *log_ctx) {
+ FileLogContext file_log_ctx = { &file_log_ctx_class, log_offset, log_ctx };
+ int fd=-1;
+#if !HAVE_MKSTEMP
+ void *ptr= tempnam(NULL, prefix);
+ if(!ptr)
+ ptr= tempnam(".", prefix);
+ *filename = av_strdup(ptr);
+#undef free
+ free(ptr);
+#else
+ size_t len = strlen(prefix) + 12; /* room for "/tmp/" and "XXXXXX\0" */
+ *filename = av_malloc(len);
+#endif
+ /* -----common section-----*/
+ if (*filename == NULL) {
+ av_log(&file_log_ctx, AV_LOG_ERROR, "ff_tempfile: Cannot allocate file name\n");
+ return AVERROR(ENOMEM);
+ }
+#if !HAVE_MKSTEMP
+# ifndef O_BINARY
+# define O_BINARY 0
+# endif
+# ifndef O_EXCL
+# define O_EXCL 0
+# endif
+ fd = open(*filename, O_RDWR | O_BINARY | O_CREAT | O_EXCL, 0600);
+#else
+ snprintf(*filename, len, "/tmp/%sXXXXXX", prefix);
+ fd = mkstemp(*filename);
+#ifdef _WIN32
+ if (fd < 0) {
+ snprintf(*filename, len, "./%sXXXXXX", prefix);
+ fd = mkstemp(*filename);
+ }
+#endif
+#endif
+ /* -----common section-----*/
+ if (fd < 0) {
+ int err = AVERROR(errno);
+ av_log(&file_log_ctx, AV_LOG_ERROR, "ff_tempfile: Cannot open temporary file %s\n", *filename);
+ return err;
+ }
+ return fd; /* success */
+}
+
#ifdef TEST
#undef printf
diff --git a/libavutil/file.h b/libavutil/file.h
index c481c37f93..f3af9ef7e5 100644
--- a/libavutil/file.h
+++ b/libavutil/file.h
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -49,4 +49,13 @@ int av_file_map(const char *filename, uint8_t **bufptr, size_t *size,
*/
void av_file_unmap(uint8_t *bufptr, size_t size);
+/**
+ * Wrapper to work around the lack of mkstemp() on mingw.
+ * Also, tries to create file in /tmp first, if possible.
+ * *prefix can be a character constant; *filename will be allocated internally.
+ * @return file descriptor of opened file (or -1 on error)
+ * and opened file name in **filename.
+ */
+int av_tempfile(const char *prefix, char **filename, int log_offset, void *log_ctx);
+
#endif /* AVUTIL_FILE_H */
diff --git a/libavutil/imgutils.c b/libavutil/imgutils.c
index 5cd71e21ce..9447779c36 100644
--- a/libavutil/imgutils.c
+++ b/libavutil/imgutils.c
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -44,24 +44,41 @@ void av_image_fill_max_pixsteps(int max_pixsteps[4], int max_pixstep_comps[4],
}
}
+static inline
+int image_get_linesize(int width, int plane,
+ int max_step, int max_step_comp,
+ const AVPixFmtDescriptor *desc)
+{
+ int s, shifted_w, linesize;
+
+ if (width < 0)
+ return AVERROR(EINVAL);
+ s = (max_step_comp == 1 || max_step_comp == 2) ? desc->log2_chroma_w : 0;
+ shifted_w = ((width + (1 << s) - 1)) >> s;
+ if (shifted_w && max_step > INT_MAX / shifted_w)
+ return AVERROR(EINVAL);
+ linesize = max_step * shifted_w;
+ if (desc->flags & PIX_FMT_BITSTREAM)
+ linesize = (linesize + 7) >> 3;
+ return linesize;
+}
+
int av_image_get_linesize(enum PixelFormat pix_fmt, int width, int plane)
{
const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt];
int max_step [4]; /* max pixel step for each plane */
int max_step_comp[4]; /* the component for each plane which has the max pixel step */
- int s;
- if (desc->flags & PIX_FMT_BITSTREAM)
- return (width * (desc->comp[0].step_minus1+1) + 7) >> 3;
+ if ((unsigned)pix_fmt >= PIX_FMT_NB || desc->flags & PIX_FMT_HWACCEL)
+ return AVERROR(EINVAL);
av_image_fill_max_pixsteps(max_step, max_step_comp, desc);
- s = (max_step_comp[plane] == 1 || max_step_comp[plane] == 2) ? desc->log2_chroma_w : 0;
- return max_step[plane] * (((width + (1 << s) - 1)) >> s);
+ return image_get_linesize(width, plane, max_step[plane], max_step_comp[plane], desc);
}
int av_image_fill_linesizes(int linesizes[4], enum PixelFormat pix_fmt, int width)
{
- int i;
+ int i, ret;
const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt];
int max_step [4]; /* max pixel step for each plane */
int max_step_comp[4]; /* the component for each plane which has the max pixel step */
@@ -71,20 +88,11 @@ int av_image_fill_linesizes(int linesizes[4], enum PixelFormat pix_fmt, int widt
if ((unsigned)pix_fmt >= PIX_FMT_NB || desc->flags & PIX_FMT_HWACCEL)
return AVERROR(EINVAL);
- if (desc->flags & PIX_FMT_BITSTREAM) {
- if (width > (INT_MAX -7) / (desc->comp[0].step_minus1+1))
- return AVERROR(EINVAL);
- linesizes[0] = (width * (desc->comp[0].step_minus1+1) + 7) >> 3;
- return 0;
- }
-
av_image_fill_max_pixsteps(max_step, max_step_comp, desc);
for (i = 0; i < 4; i++) {
- int s = (max_step_comp[i] == 1 || max_step_comp[i] == 2) ? desc->log2_chroma_w : 0;
- int shifted_w = ((width + (1 << s) - 1)) >> s;
- if (max_step[i] > INT_MAX / shifted_w)
- return AVERROR(EINVAL);
- linesizes[i] = max_step[i] * shifted_w;
+ if ((ret = image_get_linesize(width, i, max_step[i], max_step_comp[i], desc)) < 0)
+ return ret;
+ linesizes[i] = ret;
}
return 0;
diff --git a/libavutil/imgutils.h b/libavutil/imgutils.h
index 6017a70f71..f976d210b9 100644
--- a/libavutil/imgutils.h
+++ b/libavutil/imgutils.h
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavutil/integer.c b/libavutil/integer.c
new file mode 100644
index 0000000000..4f9b66cbc8
--- /dev/null
+++ b/libavutil/integer.c
@@ -0,0 +1,197 @@
+/*
+ * arbitrary precision integers
+ * Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * arbitrary precision integers
+ * @author Michael Niedermayer <michaelni@gmx.at>
+ */
+
+#include "common.h"
+#include "integer.h"
+
+AVInteger av_add_i(AVInteger a, AVInteger b){
+ int i, carry=0;
+
+ for(i=0; i<AV_INTEGER_SIZE; i++){
+ carry= (carry>>16) + a.v[i] + b.v[i];
+ a.v[i]= carry;
+ }
+ return a;
+}
+
+AVInteger av_sub_i(AVInteger a, AVInteger b){
+ int i, carry=0;
+
+ for(i=0; i<AV_INTEGER_SIZE; i++){
+ carry= (carry>>16) + a.v[i] - b.v[i];
+ a.v[i]= carry;
+ }
+ return a;
+}
+
+int av_log2_i(AVInteger a){
+ int i;
+
+ for(i=AV_INTEGER_SIZE-1; i>=0; i--){
+ if(a.v[i])
+ return av_log2_16bit(a.v[i]) + 16*i;
+ }
+ return -1;
+}
+
+AVInteger av_mul_i(AVInteger a, AVInteger b){
+ AVInteger out;
+ int i, j;
+ int na= (av_log2_i(a)+16) >> 4;
+ int nb= (av_log2_i(b)+16) >> 4;
+
+ memset(&out, 0, sizeof(out));
+
+ for(i=0; i<na; i++){
+ unsigned int carry=0;
+
+ if(a.v[i])
+ for(j=i; j<AV_INTEGER_SIZE && j-i<=nb; j++){
+ carry= (carry>>16) + out.v[j] + a.v[i]*b.v[j-i];
+ out.v[j]= carry;
+ }
+ }
+
+ return out;
+}
+
+int av_cmp_i(AVInteger a, AVInteger b){
+ int i;
+ int v= (int16_t)a.v[AV_INTEGER_SIZE-1] - (int16_t)b.v[AV_INTEGER_SIZE-1];
+ if(v) return (v>>16)|1;
+
+ for(i=AV_INTEGER_SIZE-2; i>=0; i--){
+ int v= a.v[i] - b.v[i];
+ if(v) return (v>>16)|1;
+ }
+ return 0;
+}
+
+AVInteger av_shr_i(AVInteger a, int s){
+ AVInteger out;
+ int i;
+
+ for(i=0; i<AV_INTEGER_SIZE; i++){
+ unsigned int index= i + (s>>4);
+ unsigned int v=0;
+ if(index+1<AV_INTEGER_SIZE) v = a.v[index+1]<<16;
+ if(index <AV_INTEGER_SIZE) v+= a.v[index ];
+ out.v[i]= v >> (s&15);
+ }
+ return out;
+}
+
+AVInteger av_mod_i(AVInteger *quot, AVInteger a, AVInteger b){
+ int i= av_log2_i(a) - av_log2_i(b);
+ AVInteger quot_temp;
+ if(!quot) quot = &quot_temp;
+
+ assert((int16_t)a[AV_INTEGER_SIZE-1] >= 0 && (int16_t)b[AV_INTEGER_SIZE-1] >= 0);
+ assert(av_log2(b)>=0);
+
+ if(i > 0)
+ b= av_shr_i(b, -i);
+
+ memset(quot, 0, sizeof(AVInteger));
+
+ while(i-- >= 0){
+ *quot= av_shr_i(*quot, -1);
+ if(av_cmp_i(a, b) >= 0){
+ a= av_sub_i(a, b);
+ quot->v[0] += 1;
+ }
+ b= av_shr_i(b, 1);
+ }
+ return a;
+}
+
+AVInteger av_div_i(AVInteger a, AVInteger b){
+ AVInteger quot;
+ av_mod_i(&quot, a, b);
+ return quot;
+}
+
+AVInteger av_int2i(int64_t a){
+ AVInteger out;
+ int i;
+
+ for(i=0; i<AV_INTEGER_SIZE; i++){
+ out.v[i]= a;
+ a>>=16;
+ }
+ return out;
+}
+
+int64_t av_i2int(AVInteger a){
+ int i;
+ int64_t out=(int8_t)a.v[AV_INTEGER_SIZE-1];
+
+ for(i= AV_INTEGER_SIZE-2; i>=0; i--){
+ out = (out<<16) + a.v[i];
+ }
+ return out;
+}
+
+#ifdef TEST
+#undef NDEBUG
+#include <assert.h>
+
+const uint8_t ff_log2_tab[256]={
+ 0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
+ 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+ 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
+ 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
+ 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
+ 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
+ 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
+ 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
+};
+
+int main(void){
+ int64_t a,b;
+
+ for(a=7; a<256*256*256; a+=13215){
+ for(b=3; b<256*256*256; b+=27118){
+ AVInteger ai= av_int2i(a);
+ AVInteger bi= av_int2i(b);
+
+ assert(av_i2int(ai) == a);
+ assert(av_i2int(bi) == b);
+ assert(av_i2int(av_add_i(ai,bi)) == a+b);
+ assert(av_i2int(av_sub_i(ai,bi)) == a-b);
+ assert(av_i2int(av_mul_i(ai,bi)) == a*b);
+ assert(av_i2int(av_shr_i(ai, 9)) == a>>9);
+ assert(av_i2int(av_shr_i(ai,-9)) == a<<9);
+ assert(av_i2int(av_shr_i(ai, 17)) == a>>17);
+ assert(av_i2int(av_shr_i(ai,-17)) == a<<17);
+ assert(av_log2_i(ai) == av_log2(a));
+ assert(av_i2int(av_div_i(ai,bi)) == a/b);
+ }
+ }
+ return 0;
+}
+#endif
diff --git a/libavutil/integer.h b/libavutil/integer.h
new file mode 100644
index 0000000000..45f733c04c
--- /dev/null
+++ b/libavutil/integer.h
@@ -0,0 +1,86 @@
+/*
+ * arbitrary precision integers
+ * Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * arbitrary precision integers
+ * @author Michael Niedermayer <michaelni@gmx.at>
+ */
+
+#ifndef AVUTIL_INTEGER_H
+#define AVUTIL_INTEGER_H
+
+#include <stdint.h>
+#include "common.h"
+
+#define AV_INTEGER_SIZE 8
+
+typedef struct AVInteger{
+ uint16_t v[AV_INTEGER_SIZE];
+} AVInteger;
+
+AVInteger av_add_i(AVInteger a, AVInteger b) av_const;
+AVInteger av_sub_i(AVInteger a, AVInteger b) av_const;
+
+/**
+ * Return the rounded-down value of the base 2 logarithm of the given
+ * AVInteger. This is simply the index of the most significant bit
+ * which is 1, or 0 if all bits are 0.
+ */
+int av_log2_i(AVInteger a) av_const;
+AVInteger av_mul_i(AVInteger a, AVInteger b) av_const;
+
+/**
+ * Return 0 if a==b, 1 if a>b and -1 if a<b.
+ */
+int av_cmp_i(AVInteger a, AVInteger b) av_const;
+
+/**
+ * bitwise shift
+ * @param s the number of bits by which the value should be shifted right,
+ may be negative for shifting left
+ */
+AVInteger av_shr_i(AVInteger a, int s) av_const;
+
+/**
+ * Return a % b.
+ * @param quot a/b will be stored here.
+ */
+AVInteger av_mod_i(AVInteger *quot, AVInteger a, AVInteger b);
+
+/**
+ * Return a/b.
+ */
+AVInteger av_div_i(AVInteger a, AVInteger b) av_const;
+
+/**
+ * Convert the given int64_t to an AVInteger.
+ */
+AVInteger av_int2i(int64_t a) av_const;
+
+/**
+ * Convert the given AVInteger to an int64_t.
+ * If the AVInteger is too large to fit into an int64_t,
+ * then only the least significant 64 bits will be used.
+ */
+int64_t av_i2int(AVInteger a) av_const;
+
+#endif /* AVUTIL_INTEGER_H */
diff --git a/libavutil/internal.h b/libavutil/internal.h
index 5ed3fb81c3..eecc1280df 100644
--- a/libavutil/internal.h
+++ b/libavutil/internal.h
@@ -1,20 +1,20 @@
/*
* copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -37,6 +37,7 @@
#include "config.h"
#include "attributes.h"
#include "timer.h"
+#include "cpu.h"
#include "dict.h"
struct AVDictionary {
@@ -187,12 +188,11 @@ struct AVDictionary {
# define NULL_IF_CONFIG_SMALL(x) x
#endif
-
/**
* Define a function with only the non-default version specified.
*
* On systems with ELF shared libraries, all symbols exported from
- * Libav libraries are tagged with the name and major version of the
+ * FFmpeg libraries are tagged with the name and major version of the
* library to which they belong. If a function is moved from one
* library to another, a wrapper must be retained in the original
* location to preserve binary compatibility.
@@ -235,7 +235,8 @@ struct AVDictionary {
*/
static av_always_inline void emms_c(void)
{
- __asm__ volatile ("emms" ::: "memory");
+ if(av_get_cpu_flags() & AV_CPU_FLAG_MMX)
+ __asm__ volatile ("emms" ::: "memory");
}
#else /* HAVE_MMX */
#define emms_c()
diff --git a/libavutil/intfloat_readwrite.c b/libavutil/intfloat_readwrite.c
index 21a1c31667..991aa7886c 100644
--- a/libavutil/intfloat_readwrite.c
+++ b/libavutil/intfloat_readwrite.c
@@ -3,20 +3,20 @@
*
* Copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -30,13 +30,13 @@
#include "intfloat_readwrite.h"
double av_int2dbl(int64_t v){
- if(v+v > 0xFFEULL<<52)
+ if((uint64_t)v+v > 0xFFEULL<<52)
return NAN;
return ldexp(((v&((1LL<<52)-1)) + (1LL<<52)) * (v>>63|1), (v>>52&0x7FF)-1075);
}
float av_int2flt(int32_t v){
- if(v+v > 0xFF000000U)
+ if((uint32_t)v+v > 0xFF000000U)
return NAN;
return ldexp(((v&0x7FFFFF) + (1<<23)) * (v>>31|1), (v>>23&0xFF)-150);
}
diff --git a/libavutil/intfloat_readwrite.h b/libavutil/intfloat_readwrite.h
index 10ecbed76c..1b80fc6e95 100644
--- a/libavutil/intfloat_readwrite.h
+++ b/libavutil/intfloat_readwrite.h
@@ -1,20 +1,20 @@
/*
* copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavutil/intmath.h b/libavutil/intmath.h
index 3325975556..8b400ef054 100644
--- a/libavutil/intmath.h
+++ b/libavutil/intmath.h
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2010 Mans Rullgard <mans@mansr.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavutil/intreadwrite.h b/libavutil/intreadwrite.h
index 01eb27804a..09d796c8b8 100644
--- a/libavutil/intreadwrite.h
+++ b/libavutil/intreadwrite.h
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavutil/inverse.c b/libavutil/inverse.c
index 5a5c490e0a..74c7a933ea 100644
--- a/libavutil/inverse.c
+++ b/libavutil/inverse.c
@@ -2,20 +2,20 @@
* Inverse table
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavutil/lfg.c b/libavutil/lfg.c
index 7fab806f8c..b5db5a4b17 100644
--- a/libavutil/lfg.c
+++ b/libavutil/lfg.c
@@ -2,20 +2,20 @@
* Lagged Fibonacci PRNG
* Copyright (c) 2008 Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavutil/lfg.h b/libavutil/lfg.h
index 904d00a669..854ffce737 100644
--- a/libavutil/lfg.h
+++ b/libavutil/lfg.h
@@ -2,20 +2,20 @@
* Lagged Fibonacci PRNG
* Copyright (c) 2008 Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavutil/libm.h b/libavutil/libm.h
index 783f3cdfab..7e5f668e16 100644
--- a/libavutil/libm.h
+++ b/libavutil/libm.h
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavutil/lls.c b/libavutil/lls.c
index 679738530d..dcefc2cbad 100644
--- a/libavutil/lls.c
+++ b/libavutil/lls.c
@@ -3,20 +3,20 @@
*
* Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -30,105 +30,123 @@
#include "lls.h"
-void av_init_lls(LLSModel *m, int indep_count){
+void av_init_lls(LLSModel *m, int indep_count)
+{
memset(m, 0, sizeof(LLSModel));
-
- m->indep_count= indep_count;
+ m->indep_count = indep_count;
}
-void av_update_lls(LLSModel *m, double *var, double decay){
- int i,j;
+void av_update_lls(LLSModel *m, double *var, double decay)
+{
+ int i, j;
- for(i=0; i<=m->indep_count; i++){
- for(j=i; j<=m->indep_count; j++){
+ for (i = 0; i <= m->indep_count; i++) {
+ for (j = i; j <= m->indep_count; j++) {
m->covariance[i][j] *= decay;
- m->covariance[i][j] += var[i]*var[j];
+ m->covariance[i][j] += var[i] * var[j];
}
}
}
-void av_solve_lls(LLSModel *m, double threshold, int min_order){
- int i,j,k;
- double (*factor)[MAX_VARS+1]= (void*)&m->covariance[1][0];
- double (*covar )[MAX_VARS+1]= (void*)&m->covariance[1][1];
- double *covar_y = m->covariance[0];
- int count= m->indep_count;
-
- for(i=0; i<count; i++){
- for(j=i; j<count; j++){
- double sum= covar[i][j];
-
- for(k=i-1; k>=0; k--)
- sum -= factor[i][k]*factor[j][k];
-
- if(i==j){
- if(sum < threshold)
- sum= 1.0;
- factor[i][i]= sqrt(sum);
- }else
- factor[j][i]= sum / factor[i][i];
+void av_solve_lls(LLSModel *m, double threshold, int min_order)
+{
+ int i, j, k;
+ double (*factor)[MAX_VARS + 1] = (void *) &m->covariance[1][0];
+ double (*covar) [MAX_VARS + 1] = (void *) &m->covariance[1][1];
+ double *covar_y = m->covariance[0];
+ int count = m->indep_count;
+
+ for (i = 0; i < count; i++) {
+ for (j = i; j < count; j++) {
+ double sum = covar[i][j];
+
+ for (k = i - 1; k >= 0; k--)
+ sum -= factor[i][k] * factor[j][k];
+
+ if (i == j) {
+ if (sum < threshold)
+ sum = 1.0;
+ factor[i][i] = sqrt(sum);
+ } else {
+ factor[j][i] = sum / factor[i][i];
+ }
}
}
- for(i=0; i<count; i++){
- double sum= covar_y[i+1];
- for(k=i-1; k>=0; k--)
- sum -= factor[i][k]*m->coeff[0][k];
- m->coeff[0][i]= sum / factor[i][i];
+
+ for (i = 0; i < count; i++) {
+ double sum = covar_y[i + 1];
+
+ for (k = i - 1; k >= 0; k--)
+ sum -= factor[i][k] * m->coeff[0][k];
+
+ m->coeff[0][i] = sum / factor[i][i];
}
- for(j=count-1; j>=min_order; j--){
- for(i=j; i>=0; i--){
- double sum= m->coeff[0][i];
- for(k=i+1; k<=j; k++)
- sum -= factor[k][i]*m->coeff[j][k];
- m->coeff[j][i]= sum / factor[i][i];
+ for (j = count - 1; j >= min_order; j--) {
+ for (i = j; i >= 0; i--) {
+ double sum = m->coeff[0][i];
+
+ for (k = i + 1; k <= j; k++)
+ sum -= factor[k][i] * m->coeff[j][k];
+
+ m->coeff[j][i] = sum / factor[i][i];
}
- m->variance[j]= covar_y[0];
- for(i=0; i<=j; i++){
- double sum= m->coeff[j][i]*covar[i][i] - 2*covar_y[i+1];
- for(k=0; k<i; k++)
- sum += 2*m->coeff[j][k]*covar[k][i];
- m->variance[j] += m->coeff[j][i]*sum;
+ m->variance[j] = covar_y[0];
+
+ for (i = 0; i <= j; i++) {
+ double sum = m->coeff[j][i] * covar[i][i] - 2 * covar_y[i + 1];
+
+ for (k = 0; k < i; k++)
+ sum += 2 * m->coeff[j][k] * covar[k][i];
+
+ m->variance[j] += m->coeff[j][i] * sum;
}
}
}
-double av_evaluate_lls(LLSModel *m, double *param, int order){
+double av_evaluate_lls(LLSModel *m, double *param, int order)
+{
int i;
- double out= 0;
+ double out = 0;
- for(i=0; i<=order; i++)
- out+= param[i]*m->coeff[order][i];
+ for (i = 0; i <= order; i++)
+ out += param[i] * m->coeff[order][i];
return out;
}
#ifdef TEST
-#include <stdlib.h>
#include <stdio.h>
+#include <limits.h>
+#include "lfg.h"
-int main(void){
+int main(void)
+{
LLSModel m;
int i, order;
+ AVLFG lfg;
+ av_lfg_init(&lfg, 1);
av_init_lls(&m, 3);
- for(i=0; i<100; i++){
+ for (i = 0; i < 100; i++) {
double var[4];
double eval;
- var[0] = (rand() / (double)RAND_MAX - 0.5)*2;
- var[1] = var[0] + rand() / (double)RAND_MAX - 0.5;
- var[2] = var[1] + rand() / (double)RAND_MAX - 0.5;
- var[3] = var[2] + rand() / (double)RAND_MAX - 0.5;
+
+ var[0] = (av_lfg_get(&lfg) / (double) UINT_MAX - 0.5) * 2;
+ var[1] = var[0] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
+ var[2] = var[1] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
+ var[3] = var[2] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
av_update_lls(&m, var, 0.99);
av_solve_lls(&m, 0.001, 0);
- for(order=0; order<3; order++){
- eval= av_evaluate_lls(&m, var+1, order);
+ for (order = 0; order < 3; order++) {
+ eval = av_evaluate_lls(&m, var + 1, order);
printf("real:%9f order:%d pred:%9f var:%f coeffs:%f %9f %9f\n",
- var[0], order, eval, sqrt(m.variance[order] / (i+1)),
- m.coeff[order][0], m.coeff[order][1], m.coeff[order][2]);
+ var[0], order, eval, sqrt(m.variance[order] / (i + 1)),
+ m.coeff[order][0], m.coeff[order][1],
+ m.coeff[order][2]);
}
}
return 0;
diff --git a/libavutil/lls.h b/libavutil/lls.h
index 3db391bb93..d168e59749 100644
--- a/libavutil/lls.h
+++ b/libavutil/lls.h
@@ -3,20 +3,20 @@
*
* Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavutil/log.c b/libavutil/log.c
index c44130c26e..fd5e2cbbe2 100644
--- a/libavutil/log.c
+++ b/libavutil/log.c
@@ -2,20 +2,20 @@
* log functions
* Copyright (c) 2003 Michel Bardiaux
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -26,7 +26,6 @@
#include <unistd.h>
#include <stdlib.h>
-#include "avstring.h"
#include "avutil.h"
#include "log.h"
@@ -80,6 +79,14 @@ const char* av_default_item_name(void* ptr){
return (*(AVClass**)ptr)->class_name;
}
+static void sanitize(uint8_t *line){
+ while(*line){
+ if(*line < 0x08 || (*line > 0x0D && *line < 0x20))
+ *line='?';
+ line++;
+ }
+}
+
void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
{
static int print_prefix=1;
@@ -110,7 +117,7 @@ void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
if(!is_atty) is_atty= isatty(2) ? 1 : -1;
#endif
- if(print_prefix && (flags & AV_LOG_SKIP_REPEATED) && !strncmp(line, prev, sizeof line)){
+ if(print_prefix && (flags & AV_LOG_SKIP_REPEATED) && !strcmp(line, prev)){
count++;
if(is_atty==1)
fprintf(stderr, " Last message repeated %d times\r", count);
@@ -120,8 +127,9 @@ void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
fprintf(stderr, " Last message repeated %d times\n", count);
count=0;
}
+ strcpy(prev, line);
+ sanitize(line);
colored_fputs(av_clip(level>>3, 0, 6), line);
- av_strlcpy(prev, line, sizeof line);
}
static void (*av_log_callback)(void*, int, const char*, va_list) = av_log_default_callback;
diff --git a/libavutil/log.h b/libavutil/log.h
index c1d9a6c393..b8683302a2 100644
--- a/libavutil/log.h
+++ b/libavutil/log.h
@@ -1,20 +1,20 @@
/*
* copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -30,7 +30,7 @@
* arbitrary struct of which the first field is a pointer to an
* AVClass struct (e.g. AVCodecContext, AVFormatContext etc.).
*/
-typedef struct {
+typedef struct AVClass {
/**
* The name of the class; usually it is the same name as the
* context structure type to which the AVClass is associated.
@@ -73,11 +73,19 @@ typedef struct {
int parent_log_context_offset;
/**
- * A function for extended searching, e.g. in possible
- * children objects.
+ * Return next AVOptions-enabled child or NULL
*/
- const struct AVOption* (*opt_find)(void *obj, const char *name, const char *unit,
- int opt_flags, int search_flags);
+ void* (*child_next)(void *obj, void *prev);
+
+ /**
+ * Return an AVClass corresponding to next potential
+ * AVOptions-enabled child.
+ *
+ * The difference between child_next and this is that
+ * child_next iterates over _already existing_ objects, while
+ * child_class_next iterates over _all possible_ children.
+ */
+ const struct AVClass* (*child_class_next)(const struct AVClass *prev);
} AVClass;
/* av_log API */
@@ -147,7 +155,7 @@ const char* av_default_item_name(void* ctx);
#ifdef DEBUG
# define av_dlog(pctx, ...) av_log(pctx, AV_LOG_DEBUG, __VA_ARGS__)
#else
-# define av_dlog(pctx, ...)
+# define av_dlog(pctx, ...) do { if (0) av_log(pctx, AV_LOG_DEBUG, __VA_ARGS__); } while (0)
#endif
/**
@@ -156,7 +164,7 @@ const char* av_default_item_name(void* ctx);
* "Last message repeated x times" messages below (f)printf messages with some
* bad luck.
* Also to receive the last, "last repeated" line if any, the user app must
- * call av_log(NULL, AV_LOG_QUIET, ""); at the end
+ * call av_log(NULL, AV_LOG_QUIET, "%s", ""); at the end
*/
#define AV_LOG_SKIP_REPEATED 1
void av_log_set_flags(int arg);
diff --git a/libavutil/lzo.c b/libavutil/lzo.c
index 743d596656..bac762ecc3 100644
--- a/libavutil/lzo.c
+++ b/libavutil/lzo.c
@@ -2,20 +2,20 @@
* LZO 1x decompression
* Copyright (c) 2006 Reimar Doeffinger
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavutil/lzo.h b/libavutil/lzo.h
index be86bba6bc..ae5fc53c61 100644
--- a/libavutil/lzo.h
+++ b/libavutil/lzo.h
@@ -2,20 +2,20 @@
* LZO 1x decompression
* copyright (c) 2006 Reimar Doeffinger
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavutil/mathematics.c b/libavutil/mathematics.c
index e6ce2f98ad..180f72e3f0 100644
--- a/libavutil/mathematics.c
+++ b/libavutil/mathematics.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -27,6 +27,7 @@
#include <stdint.h>
#include <limits.h>
#include "mathematics.h"
+#include "libavutil/common.h"
const uint8_t ff_sqrt_tab[256]={
0, 16, 23, 28, 32, 36, 40, 43, 46, 48, 51, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 77, 79, 80, 82, 84, 85, 87, 88, 90,
@@ -139,6 +140,8 @@ int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq){
int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b){
int64_t a= tb_a.num * (int64_t)tb_b.den;
int64_t b= tb_b.num * (int64_t)tb_a.den;
+ if((FFABS(ts_a)|a|FFABS(ts_b)|b)<=INT_MAX)
+ return (ts_a*a > ts_b*b) - (ts_a*a < ts_b*b);
if (av_rescale_rnd(ts_a, a, b, AV_ROUND_DOWN) < ts_b) return -1;
if (av_rescale_rnd(ts_b, b, a, AV_ROUND_DOWN) < ts_a) return 1;
return 0;
diff --git a/libavutil/mathematics.h b/libavutil/mathematics.h
index 35494bb391..882a516393 100644
--- a/libavutil/mathematics.h
+++ b/libavutil/mathematics.h
@@ -1,20 +1,20 @@
/*
* copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavutil/md5.c b/libavutil/md5.c
index ca0e598d2e..471a510a73 100644
--- a/libavutil/md5.c
+++ b/libavutil/md5.c
@@ -13,20 +13,20 @@
* If you use gcc, then version 4.1 or later and -fomit-frame-pointer is
* strongly recommended.
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavutil/md5.h b/libavutil/md5.h
index c178bbb4d5..969202a807 100644
--- a/libavutil/md5.h
+++ b/libavutil/md5.h
@@ -1,20 +1,20 @@
/*
* copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavutil/mem.c b/libavutil/mem.c
index 27bb30b8ef..a53676c553 100644
--- a/libavutil/mem.c
+++ b/libavutil/mem.c
@@ -2,20 +2,20 @@
* default memory allocator for libavutil
* Copyright (c) 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -24,6 +24,8 @@
* default memory allocator for libavutil
*/
+#define _XOPEN_SOURCE 600
+
#include "config.h"
#include <limits.h>
@@ -57,10 +59,14 @@ void free(void *ptr);
#endif /* MALLOC_PREFIX */
+#define ALIGN (HAVE_AVX ? 32 : 16)
+
/* You can redefine av_malloc and av_free in your project to use your
memory allocator. You do not need to suppress this file because the
linker will do it automatically. */
+#define MAX_MALLOC_SIZE INT_MAX
+
void *av_malloc(size_t size)
{
void *ptr = NULL;
@@ -69,21 +75,22 @@ void *av_malloc(size_t size)
#endif
/* let's disallow possible ambiguous cases */
- if(size > (INT_MAX-32) )
+ if (size > (MAX_MALLOC_SIZE-32))
return NULL;
#if CONFIG_MEMALIGN_HACK
- ptr = malloc(size+32);
+ ptr = malloc(size+ALIGN);
if(!ptr)
return ptr;
- diff= ((-(long)ptr - 1)&31) + 1;
+ diff= ((-(long)ptr - 1)&(ALIGN-1)) + 1;
ptr = (char*)ptr + diff;
((char*)ptr)[-1]= diff;
#elif HAVE_POSIX_MEMALIGN
- if (posix_memalign(&ptr,32,size))
+ if (size) //OSX on SDK 10.6 has a broken posix_memalign implementation
+ if (posix_memalign(&ptr,ALIGN,size))
ptr = NULL;
#elif HAVE_MEMALIGN
- ptr = memalign(32,size);
+ ptr = memalign(ALIGN,size);
/* Why 64?
Indeed, we should align it:
on 4 for 386
@@ -111,6 +118,8 @@ void *av_malloc(size_t size)
#else
ptr = malloc(size);
#endif
+ if(!ptr && !size)
+ ptr= av_malloc(1);
return ptr;
}
@@ -121,19 +130,36 @@ void *av_realloc(void *ptr, size_t size)
#endif
/* let's disallow possible ambiguous cases */
- if(size > (INT_MAX-16) )
+ if (size > (MAX_MALLOC_SIZE-16))
return NULL;
#if CONFIG_MEMALIGN_HACK
//FIXME this isn't aligned correctly, though it probably isn't needed
if(!ptr) return av_malloc(size);
diff= ((char*)ptr)[-1];
- return (char*)realloc((char*)ptr - diff, size + diff) + diff;
+ ptr= realloc((char*)ptr - diff, size + diff);
+ if(ptr) ptr = (char*)ptr + diff;
+ return ptr;
#else
- return realloc(ptr, size);
+ return realloc(ptr, size + !size);
#endif
}
+void *av_realloc_f(void *ptr, size_t nelem, size_t elsize)
+{
+ size_t size;
+ void *r;
+
+ if (av_size_mult(elsize, nelem, &size)) {
+ av_free(ptr);
+ return NULL;
+ }
+ r = av_realloc(ptr, size);
+ if (!r && size)
+ av_free(ptr);
+ return r;
+}
+
void av_free(void *ptr)
{
#if CONFIG_MEMALIGN_HACK
@@ -159,6 +185,13 @@ void *av_mallocz(size_t size)
return ptr;
}
+void *av_calloc(size_t nmemb, size_t size)
+{
+ if (size <= 0 || nmemb >= INT_MAX / size)
+ return NULL;
+ return av_mallocz(nmemb * size);
+}
+
char *av_strdup(const char *s)
{
char *ptr= NULL;
@@ -171,3 +204,23 @@ char *av_strdup(const char *s)
return ptr;
}
+/* add one element to a dynamic array */
+void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem)
+{
+ /* see similar ffmpeg.c:grow_array() */
+ int nb, nb_alloc;
+ intptr_t *tab;
+
+ nb = *nb_ptr;
+ tab = *(intptr_t**)tab_ptr;
+ if ((nb & (nb - 1)) == 0) {
+ if (nb == 0)
+ nb_alloc = 1;
+ else
+ nb_alloc = nb * 2;
+ tab = av_realloc(tab, nb_alloc * sizeof(intptr_t));
+ *(intptr_t**)tab_ptr = tab;
+ }
+ tab[nb++] = (intptr_t)elem;
+ *nb_ptr = nb;
+}
diff --git a/libavutil/mem.h b/libavutil/mem.h
index 5dea492021..179e12f32f 100644
--- a/libavutil/mem.h
+++ b/libavutil/mem.h
@@ -1,20 +1,20 @@
/*
* copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -27,9 +27,10 @@
#define AVUTIL_MEM_H
#include "attributes.h"
+#include "error.h"
#include "avutil.h"
-#if defined(__ICC) && _ICC < 1200 || defined(__SUNPRO_C)
+#if defined(__INTEL_COMPILER) && __INTEL_COMPILER < 1110 || defined(__SUNPRO_C)
#define DECLARE_ALIGNED(n,t,v) t __attribute__ ((aligned (n))) v
#define DECLARE_ASM_CONST(n,t,v) const t __attribute__ ((aligned (n))) v
#elif defined(__TI_COMPILER_VERSION__)
@@ -76,10 +77,10 @@ void *av_malloc(size_t size) av_malloc_attrib av_alloc_size(1);
* Allocate or reallocate a block of memory.
* If ptr is NULL and size > 0, allocate a new block. If
* size is zero, free the memory block pointed to by ptr.
- * @param size Size in bytes for the memory block to be allocated or
- * reallocated.
* @param ptr Pointer to a memory block already allocated with
* av_malloc(z)() or av_realloc() or NULL.
+ * @param size Size in bytes for the memory block to be allocated or
+ * reallocated.
* @return Pointer to a newly reallocated block or NULL if the block
* cannot be reallocated or the function is used to free the memory block.
* @see av_fast_realloc()
@@ -87,6 +88,16 @@ void *av_malloc(size_t size) av_malloc_attrib av_alloc_size(1);
void *av_realloc(void *ptr, size_t size) av_alloc_size(2);
/**
+ * Allocate or reallocate a block of memory.
+ * This function does the same thing as av_realloc, except:
+ * - It takes two arguments and checks the result of the multiplication for
+ * integer overflow.
+ * - It frees the input block in case of failure, thus avoiding the memory
+ * leak with the classic "buf = realloc(buf); if (!buf) return -1;".
+ */
+void *av_realloc_f(void *ptr, size_t nelem, size_t elsize);
+
+/**
* Free a memory block which has been allocated with av_malloc(z)() or
* av_realloc().
* @param ptr Pointer to the memory block which should be freed.
@@ -107,6 +118,18 @@ void av_free(void *ptr);
void *av_mallocz(size_t size) av_malloc_attrib av_alloc_size(1);
/**
+ * Allocate a block of nmemb * size bytes with alignment suitable for all
+ * memory accesses (including vectors if available on the CPU) and
+ * zero all the bytes of the block.
+ * The allocation will fail if nmemb * size is greater than or equal
+ * to INT_MAX.
+ * @param nmemb
+ * @param size
+ * @return Pointer to the allocated block, NULL if it cannot be allocated.
+ */
+void *av_calloc(size_t nmemb, size_t size) av_malloc_attrib;
+
+/**
* Duplicate the string s.
* @param s string to be duplicated
* @return Pointer to a newly allocated string containing a
@@ -123,4 +146,28 @@ char *av_strdup(const char *s) av_malloc_attrib;
*/
void av_freep(void *ptr);
+/**
+ * Add an element to a dynamic array.
+ *
+ * @param tab_ptr Pointer to the array.
+ * @param nb_ptr Pointer to the number of elements in the array.
+ * @param elem Element to be added.
+ */
+void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem);
+
+/**
+ * Multiply two size_t values checking for overflow.
+ * @return 0 if success, AVERROR(EINVAL) if overflow.
+ */
+static inline int av_size_mult(size_t a, size_t b, size_t *r)
+{
+ size_t t = a * b;
+ /* Hack inspired from glibc: only try the division if nelem and elsize
+ * are both greater than sqrt(SIZE_MAX). */
+ if ((a | b) >= ((size_t)1 << (sizeof(size_t) * 4)) && a && t / a != b)
+ return AVERROR(EINVAL);
+ *r = t;
+ return 0;
+}
+
#endif /* AVUTIL_MEM_H */
diff --git a/libavutil/mips/intreadwrite.h b/libavutil/mips/intreadwrite.h
index 0e0cc065a9..cd4a9a9a67 100644
--- a/libavutil/mips/intreadwrite.h
+++ b/libavutil/mips/intreadwrite.h
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2009 Mans Rullgard <mans@mansr.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavutil/opt.c b/libavutil/opt.c
index 65e02135d5..0666a60d66 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -2,20 +2,20 @@
* AVOptions
* Copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -36,10 +36,9 @@
//FIXME order them and do a bin search
const AVOption *av_find_opt(void *v, const char *name, const char *unit, int mask, int flags)
{
- AVClass *c= *(AVClass**)v; //FIXME silly way of storing AVClass
- const AVOption *o= c->option;
+ const AVOption *o = NULL;
- for (; o && o->name; o++) {
+ while ((o = av_next_option(v, o))) {
if (!strcmp(o->name, name) && (!unit || (o->unit && !strcmp(o->unit, unit))) && (o->flags & mask) == flags)
return o;
}
@@ -47,36 +46,50 @@ const AVOption *av_find_opt(void *v, const char *name, const char *unit, int mas
}
#endif
+#if FF_API_OLD_AVOPTIONS
const AVOption *av_next_option(void *obj, const AVOption *last)
{
+ return av_opt_next(obj, last);
+}
+#endif
+
+const AVOption *av_opt_next(void *obj, const AVOption *last)
+{
if (last && last[1].name) return ++last;
- else if (last) return NULL;
+ else if (last || !(*(AVClass**)obj)->option->name) return NULL;
else return (*(AVClass**)obj)->option;
}
-static int av_set_number2(void *obj, const char *name, double num, int den, int64_t intnum, const AVOption **o_out)
+static int read_number(const AVOption *o, void *dst, double *num, int *den, int64_t *intnum)
{
- const AVOption *o = av_opt_find(obj, name, NULL, 0, 0);
- void *dst;
- if (o_out)
- *o_out= o;
- if (!o || o->offset<=0)
- return AVERROR_OPTION_NOT_FOUND;
+ switch (o->type) {
+ case AV_OPT_TYPE_FLAGS: *intnum = *(unsigned int*)dst;return 0;
+ case AV_OPT_TYPE_INT: *intnum = *(int *)dst;return 0;
+ case AV_OPT_TYPE_INT64: *intnum = *(int64_t *)dst;return 0;
+ case AV_OPT_TYPE_FLOAT: *num = *(float *)dst;return 0;
+ case AV_OPT_TYPE_DOUBLE: *num = *(double *)dst;return 0;
+ case AV_OPT_TYPE_RATIONAL: *intnum = ((AVRational*)dst)->num;
+ *den = ((AVRational*)dst)->den;
+ return 0;
+ case AV_OPT_TYPE_CONST: *num = o->default_val.dbl; return 0;
+ }
+ return AVERROR(EINVAL);
+}
+static int write_number(void *obj, const AVOption *o, void *dst, double num, int den, int64_t intnum)
+{
if (o->max*den < num*intnum || o->min*den > num*intnum) {
- av_log(obj, AV_LOG_ERROR, "Value %lf for parameter '%s' out of range\n", num, name);
+ av_log(obj, AV_LOG_ERROR, "Value %lf for parameter '%s' out of range\n", num, o->name);
return AVERROR(ERANGE);
}
- dst= ((uint8_t*)obj) + o->offset;
-
switch (o->type) {
- case FF_OPT_TYPE_FLAGS:
- case FF_OPT_TYPE_INT: *(int *)dst= llrint(num/den)*intnum; break;
- case FF_OPT_TYPE_INT64: *(int64_t *)dst= llrint(num/den)*intnum; break;
- case FF_OPT_TYPE_FLOAT: *(float *)dst= num*intnum/den; break;
- case FF_OPT_TYPE_DOUBLE:*(double *)dst= num*intnum/den; break;
- case FF_OPT_TYPE_RATIONAL:
+ case AV_OPT_TYPE_FLAGS:
+ case AV_OPT_TYPE_INT: *(int *)dst= llrint(num/den)*intnum; break;
+ case AV_OPT_TYPE_INT64: *(int64_t *)dst= llrint(num/den)*intnum; break;
+ case AV_OPT_TYPE_FLOAT: *(float *)dst= num*intnum/den; break;
+ case AV_OPT_TYPE_DOUBLE:*(double *)dst= num*intnum/den; break;
+ case AV_OPT_TYPE_RATIONAL:
if ((int)num == num) *(AVRational*)dst= (AVRational){num*intnum, den};
else *(AVRational*)dst= av_d2q(num*intnum/den, 1<<24);
break;
@@ -86,15 +99,6 @@ static int av_set_number2(void *obj, const char *name, double num, int den, int6
return 0;
}
-static const AVOption *av_set_number(void *obj, const char *name, double num, int den, int64_t intnum)
-{
- const AVOption *o = NULL;
- if (av_set_number2(obj, name, num, den, intnum, &o) < 0)
- return NULL;
- else
- return o;
-}
-
static const double const_values[] = {
M_PI,
M_E,
@@ -116,113 +120,202 @@ static int hexchar2int(char c) {
return -1;
}
+static int set_string_binary(void *obj, const AVOption *o, const char *val, uint8_t **dst)
+{
+ int *lendst = (int *)(dst + 1);
+ uint8_t *bin, *ptr;
+ int len = strlen(val);
+
+ av_freep(dst);
+ *lendst = 0;
+
+ if (len & 1)
+ return AVERROR(EINVAL);
+ len /= 2;
+
+ ptr = bin = av_malloc(len);
+ while (*val) {
+ int a = hexchar2int(*val++);
+ int b = hexchar2int(*val++);
+ if (a < 0 || b < 0) {
+ av_free(bin);
+ return AVERROR(EINVAL);
+ }
+ *ptr++ = (a << 4) | b;
+ }
+ *dst = bin;
+ *lendst = len;
+
+ return 0;
+}
+
+static int set_string(void *obj, const AVOption *o, const char *val, uint8_t **dst)
+{
+ av_freep(dst);
+ *dst = av_strdup(val);
+ return 0;
+}
+
+static int set_string_number(void *obj, const AVOption *o, const char *val, void *dst)
+{
+ int ret = 0, notfirst = 0;
+ for (;;) {
+ int i, den = 1;
+ char buf[256];
+ int cmd = 0;
+ double d, num = 1;
+ int64_t intnum = 1;
+
+ if (*val == '+' || *val == '-')
+ cmd = *(val++);
+
+ for (i = 0; i < sizeof(buf) - 1 && val[i] && val[i] != '+' && val[i] != '-'; i++)
+ buf[i] = val[i];
+ buf[i] = 0;
+
+ {
+ const AVOption *o_named = av_opt_find(obj, buf, o->unit, 0, 0);
+ if (o_named && o_named->type == AV_OPT_TYPE_CONST)
+ d = o_named->default_val.dbl;
+ else if (!strcmp(buf, "default")) d = o->default_val.dbl;
+ else if (!strcmp(buf, "max" )) d = o->max;
+ else if (!strcmp(buf, "min" )) d = o->min;
+ else if (!strcmp(buf, "none" )) d = 0;
+ else if (!strcmp(buf, "all" )) d = ~0;
+ else {
+ int res = av_expr_parse_and_eval(&d, buf, const_names, const_values, NULL, NULL, NULL, NULL, NULL, 0, obj);
+ if (res < 0) {
+ av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\"\n", val);
+ return res;
+ }
+ }
+ }
+ if (o->type == AV_OPT_TYPE_FLAGS) {
+ read_number(o, dst, NULL, NULL, &intnum);
+ if (cmd == '+') d = intnum | (int64_t)d;
+ else if (cmd == '-') d = intnum &~(int64_t)d;
+ } else {
+ read_number(o, dst, &num, &den, &intnum);
+ if (cmd == '+') d = notfirst*num*intnum/den + d;
+ else if (cmd == '-') d = notfirst*num*intnum/den - d;
+ }
+
+ if ((ret = write_number(obj, o, dst, d, 1, 1)) < 0)
+ return ret;
+ val += i;
+ if (!*val)
+ return 0;
+ notfirst = 1;
+ }
+
+ return 0;
+}
+
+#if FF_API_OLD_AVOPTIONS
int av_set_string3(void *obj, const char *name, const char *val, int alloc, const AVOption **o_out)
{
- int ret;
const AVOption *o = av_opt_find(obj, name, NULL, 0, 0);
if (o_out)
*o_out = o;
- if (!o)
+ return av_opt_set(obj, name, val, 0);
+}
+#endif
+
+int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
+{
+ void *dst, *target_obj;
+ const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
+ if (!o || !target_obj)
return AVERROR_OPTION_NOT_FOUND;
- if (!val || o->offset<=0)
+ if (!val && o->type != AV_OPT_TYPE_STRING)
return AVERROR(EINVAL);
- if (o->type == FF_OPT_TYPE_BINARY) {
- uint8_t **dst = (uint8_t **)(((uint8_t*)obj) + o->offset);
- int *lendst = (int *)(dst + 1);
- uint8_t *bin, *ptr;
- int len = strlen(val);
- av_freep(dst);
- *lendst = 0;
- if (len & 1) return AVERROR(EINVAL);
- len /= 2;
- ptr = bin = av_malloc(len);
- while (*val) {
- int a = hexchar2int(*val++);
- int b = hexchar2int(*val++);
- if (a < 0 || b < 0) {
- av_free(bin);
- return AVERROR(EINVAL);
- }
- *ptr++ = (a << 4) | b;
- }
- *dst = bin;
- *lendst = len;
- return 0;
+ dst = ((uint8_t*)target_obj) + o->offset;
+ switch (o->type) {
+ case AV_OPT_TYPE_STRING: return set_string(obj, o, val, dst);
+ case AV_OPT_TYPE_BINARY: return set_string_binary(obj, o, val, dst);
+ case AV_OPT_TYPE_FLAGS:
+ case AV_OPT_TYPE_INT:
+ case AV_OPT_TYPE_INT64:
+ case AV_OPT_TYPE_FLOAT:
+ case AV_OPT_TYPE_DOUBLE:
+ case AV_OPT_TYPE_RATIONAL: return set_string_number(obj, o, val, dst);
}
- if (o->type != FF_OPT_TYPE_STRING) {
- int notfirst=0;
- for (;;) {
- int i;
- char buf[256];
- int cmd=0;
- double d;
-
- if (*val == '+' || *val == '-')
- cmd= *(val++);
-
- for (i=0; i<sizeof(buf)-1 && val[i] && val[i]!='+' && val[i]!='-'; i++)
- buf[i]= val[i];
- buf[i]=0;
-
- {
- const AVOption *o_named = av_opt_find(obj, buf, o->unit, 0, 0);
- if (o_named && o_named->type == FF_OPT_TYPE_CONST)
- d= o_named->default_val.dbl;
- else if (!strcmp(buf, "default")) d= o->default_val.dbl;
- else if (!strcmp(buf, "max" )) d= o->max;
- else if (!strcmp(buf, "min" )) d= o->min;
- else if (!strcmp(buf, "none" )) d= 0;
- else if (!strcmp(buf, "all" )) d= ~0;
- else {
- int res = av_expr_parse_and_eval(&d, buf, const_names, const_values, NULL, NULL, NULL, NULL, NULL, 0, obj);
- if (res < 0) {
- av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\"\n", val);
- return res;
- }
- }
- }
- if (o->type == FF_OPT_TYPE_FLAGS) {
- if (cmd=='+') d= av_get_int(obj, name, NULL) | (int64_t)d;
- else if (cmd=='-') d= av_get_int(obj, name, NULL) &~(int64_t)d;
- } else {
- if (cmd=='+') d= notfirst*av_get_double(obj, name, NULL) + d;
- else if (cmd=='-') d= notfirst*av_get_double(obj, name, NULL) - d;
- }
- if ((ret = av_set_number2(obj, name, d, 1, 1, o_out)) < 0)
- return ret;
- val+= i;
- if (!*val)
- return 0;
- notfirst=1;
- }
- }
+ av_log(obj, AV_LOG_ERROR, "Invalid option type.\n");
+ return AVERROR(EINVAL);
+}
- if (alloc) {
- av_free(*(void**)(((uint8_t*)obj) + o->offset));
- val= av_strdup(val);
+#define OPT_EVAL_NUMBER(name, opttype, vartype)\
+ int av_opt_eval_ ## name(void *obj, const AVOption *o, const char *val, vartype *name ## _out)\
+ {\
+ if (!o || o->type != opttype)\
+ return AVERROR(EINVAL);\
+ return set_string_number(obj, o, val, name ## _out);\
}
- memcpy(((uint8_t*)obj) + o->offset, &val, sizeof(val));
- return 0;
+OPT_EVAL_NUMBER(flags, AV_OPT_TYPE_FLAGS, int)
+OPT_EVAL_NUMBER(int, AV_OPT_TYPE_INT, int)
+OPT_EVAL_NUMBER(int64, AV_OPT_TYPE_INT64, int64_t)
+OPT_EVAL_NUMBER(float, AV_OPT_TYPE_FLOAT, float)
+OPT_EVAL_NUMBER(double, AV_OPT_TYPE_DOUBLE, double)
+OPT_EVAL_NUMBER(q, AV_OPT_TYPE_RATIONAL, AVRational)
+
+static int set_number(void *obj, const char *name, double num, int den, int64_t intnum,
+ int search_flags)
+{
+ void *dst, *target_obj;
+ const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
+
+ if (!o || !target_obj)
+ return AVERROR_OPTION_NOT_FOUND;
+
+ dst = ((uint8_t*)target_obj) + o->offset;
+ return write_number(obj, o, dst, num, den, intnum);
}
+#if FF_API_OLD_AVOPTIONS
const AVOption *av_set_double(void *obj, const char *name, double n)
{
- return av_set_number(obj, name, n, 1, 1);
+ const AVOption *o = av_opt_find(obj, name, NULL, 0, 0);
+ if (set_number(obj, name, n, 1, 1, 0) < 0)
+ return NULL;
+ return o;
}
const AVOption *av_set_q(void *obj, const char *name, AVRational n)
{
- return av_set_number(obj, name, n.num, n.den, 1);
+ const AVOption *o = av_opt_find(obj, name, NULL, 0, 0);
+ if (set_number(obj, name, n.num, n.den, 1, 0) < 0)
+ return NULL;
+ return o;
}
const AVOption *av_set_int(void *obj, const char *name, int64_t n)
{
- return av_set_number(obj, name, 1, 1, n);
+ const AVOption *o = av_opt_find(obj, name, NULL, 0, 0);
+ if (set_number(obj, name, 1, 1, n, 0) < 0)
+ return NULL;
+ return o;
+}
+#endif
+
+int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
+{
+ return set_number(obj, name, 1, 1, val, search_flags);
+}
+
+int av_opt_set_double(void *obj, const char *name, double val, int search_flags)
+{
+ return set_number(obj, name, val, 1, 1, search_flags);
}
+int av_opt_set_q(void *obj, const char *name, AVRational val, int search_flags)
+{
+ return set_number(obj, name, val.num, val.den, 1, search_flags);
+}
+
+#if FF_API_OLD_AVOPTIONS
/**
*
* @param buf a buffer which is used for returning non string values as strings, can be NULL
@@ -230,27 +323,28 @@ const AVOption *av_set_int(void *obj, const char *name, int64_t n)
*/
const char *av_get_string(void *obj, const char *name, const AVOption **o_out, char *buf, int buf_len)
{
- const AVOption *o = av_opt_find(obj, name, NULL, 0, 0);
+ const AVOption *o = av_opt_find(obj, name, NULL, 0, AV_OPT_SEARCH_CHILDREN);
void *dst;
uint8_t *bin;
int len, i;
- if (!o || o->offset<=0)
+ if (!o)
return NULL;
- if (o->type != FF_OPT_TYPE_STRING && (!buf || !buf_len))
+ if (o->type != AV_OPT_TYPE_STRING && (!buf || !buf_len))
return NULL;
dst= ((uint8_t*)obj) + o->offset;
if (o_out) *o_out= o;
switch (o->type) {
- case FF_OPT_TYPE_FLAGS: snprintf(buf, buf_len, "0x%08X",*(int *)dst);break;
- case FF_OPT_TYPE_INT: snprintf(buf, buf_len, "%d" , *(int *)dst);break;
- case FF_OPT_TYPE_INT64: snprintf(buf, buf_len, "%"PRId64, *(int64_t*)dst);break;
- case FF_OPT_TYPE_FLOAT: snprintf(buf, buf_len, "%f" , *(float *)dst);break;
- case FF_OPT_TYPE_DOUBLE: snprintf(buf, buf_len, "%f" , *(double *)dst);break;
- case FF_OPT_TYPE_RATIONAL: snprintf(buf, buf_len, "%d/%d", ((AVRational*)dst)->num, ((AVRational*)dst)->den);break;
- case FF_OPT_TYPE_STRING: return *(void**)dst;
- case FF_OPT_TYPE_BINARY:
+ case AV_OPT_TYPE_FLAGS: snprintf(buf, buf_len, "0x%08X",*(int *)dst);break;
+ case AV_OPT_TYPE_INT: snprintf(buf, buf_len, "%d" , *(int *)dst);break;
+ case AV_OPT_TYPE_INT64: snprintf(buf, buf_len, "%"PRId64, *(int64_t*)dst);break;
+ case AV_OPT_TYPE_FLOAT: snprintf(buf, buf_len, "%f" , *(float *)dst);break;
+ case AV_OPT_TYPE_DOUBLE: snprintf(buf, buf_len, "%f" , *(double *)dst);break;
+ case AV_OPT_TYPE_RATIONAL: snprintf(buf, buf_len, "%d/%d", ((AVRational*)dst)->num, ((AVRational*)dst)->den);break;
+ case AV_OPT_TYPE_CONST: snprintf(buf, buf_len, "%f" , o->default_val.dbl);break;
+ case AV_OPT_TYPE_STRING: return *(void**)dst;
+ case AV_OPT_TYPE_BINARY:
len = *(int*)(((uint8_t *)dst) + sizeof(uint8_t *));
if (len >= (buf_len + 1)/2) return NULL;
bin = *(uint8_t**)dst;
@@ -260,40 +354,82 @@ const char *av_get_string(void *obj, const char *name, const AVOption **o_out, c
}
return buf;
}
+#endif
-static int av_get_number(void *obj, const char *name, const AVOption **o_out, double *num, int *den, int64_t *intnum)
+int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
{
- const AVOption *o = av_opt_find(obj, name, NULL, 0, 0);
- void *dst;
- if (!o || o->offset<=0)
- goto error;
+ void *dst, *target_obj;
+ const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
+ uint8_t *bin, buf[128];
+ int len, i, ret;
- dst= ((uint8_t*)obj) + o->offset;
+ if (!o || !target_obj || (o->offset<=0 && o->type != AV_OPT_TYPE_CONST))
+ return AVERROR_OPTION_NOT_FOUND;
- if (o_out) *o_out= o;
+ dst = (uint8_t*)target_obj + o->offset;
+ buf[0] = 0;
switch (o->type) {
- case FF_OPT_TYPE_FLAGS: *intnum= *(unsigned int*)dst;return 0;
- case FF_OPT_TYPE_INT: *intnum= *(int *)dst;return 0;
- case FF_OPT_TYPE_INT64: *intnum= *(int64_t*)dst;return 0;
- case FF_OPT_TYPE_FLOAT: *num= *(float *)dst;return 0;
- case FF_OPT_TYPE_DOUBLE: *num= *(double *)dst;return 0;
- case FF_OPT_TYPE_RATIONAL: *intnum= ((AVRational*)dst)->num;
- *den = ((AVRational*)dst)->den;
- return 0;
+ case AV_OPT_TYPE_FLAGS: ret = snprintf(buf, sizeof(buf), "0x%08X", *(int *)dst);break;
+ case AV_OPT_TYPE_INT: ret = snprintf(buf, sizeof(buf), "%d" , *(int *)dst);break;
+ case AV_OPT_TYPE_INT64: ret = snprintf(buf, sizeof(buf), "%"PRId64, *(int64_t*)dst);break;
+ case AV_OPT_TYPE_FLOAT: ret = snprintf(buf, sizeof(buf), "%f" , *(float *)dst);break;
+ case AV_OPT_TYPE_DOUBLE: ret = snprintf(buf, sizeof(buf), "%f" , *(double *)dst);break;
+ case AV_OPT_TYPE_RATIONAL: ret = snprintf(buf, sizeof(buf), "%d/%d", ((AVRational*)dst)->num, ((AVRational*)dst)->den);break;
+ case AV_OPT_TYPE_CONST: ret = snprintf(buf, sizeof(buf), "%f" , o->default_val.dbl);break;
+ case AV_OPT_TYPE_STRING:
+ if (*(uint8_t**)dst)
+ *out_val = av_strdup(*(uint8_t**)dst);
+ else
+ *out_val = av_strdup("");
+ return 0;
+ case AV_OPT_TYPE_BINARY:
+ len = *(int*)(((uint8_t *)dst) + sizeof(uint8_t *));
+ if ((uint64_t)len*2 + 1 > INT_MAX)
+ return AVERROR(EINVAL);
+ if (!(*out_val = av_malloc(len*2 + 1)))
+ return AVERROR(ENOMEM);
+ bin = *(uint8_t**)dst;
+ for (i = 0; i < len; i++)
+ snprintf(*out_val + i*2, 3, "%02X", bin[i]);
+ return 0;
+ default:
+ return AVERROR(EINVAL);
}
+
+ if (ret >= sizeof(buf))
+ return AVERROR(EINVAL);
+ *out_val = av_strdup(buf);
+ return 0;
+}
+
+static int get_number(void *obj, const char *name, const AVOption **o_out, double *num, int *den, int64_t *intnum,
+ int search_flags)
+{
+ void *dst, *target_obj;
+ const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
+ if (!o || !target_obj)
+ goto error;
+
+ dst = ((uint8_t*)target_obj) + o->offset;
+
+ if (o_out) *o_out= o;
+
+ return read_number(o, dst, num, den, intnum);
+
error:
*den=*intnum=0;
return -1;
}
+#if FF_API_OLD_AVOPTIONS
double av_get_double(void *obj, const char *name, const AVOption **o_out)
{
int64_t intnum=1;
double num=1;
int den=1;
- if (av_get_number(obj, name, o_out, &num, &den, &intnum) < 0)
+ if (get_number(obj, name, o_out, &num, &den, &intnum, 0) < 0)
return NAN;
return num*intnum/den;
}
@@ -304,7 +440,7 @@ AVRational av_get_q(void *obj, const char *name, const AVOption **o_out)
double num=1;
int den=1;
- if (av_get_number(obj, name, o_out, &num, &den, &intnum) < 0)
+ if (get_number(obj, name, o_out, &num, &den, &intnum, 0) < 0)
return (AVRational){0, 0};
if (num == 1.0 && (int)intnum == intnum)
return (AVRational){intnum, den};
@@ -318,19 +454,63 @@ int64_t av_get_int(void *obj, const char *name, const AVOption **o_out)
double num=1;
int den=1;
- if (av_get_number(obj, name, o_out, &num, &den, &intnum) < 0)
+ if (get_number(obj, name, o_out, &num, &den, &intnum, 0) < 0)
return -1;
return num*intnum/den;
}
+#endif
+
+int av_opt_get_int(void *obj, const char *name, int search_flags, int64_t *out_val)
+{
+ int64_t intnum = 1;
+ double num = 1;
+ int ret, den = 1;
+
+ if ((ret = get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
+ return ret;
+ *out_val = num*intnum/den;
+ return 0;
+}
+
+int av_opt_get_double(void *obj, const char *name, int search_flags, double *out_val)
+{
+ int64_t intnum = 1;
+ double num = 1;
+ int ret, den = 1;
+
+ if ((ret = get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
+ return ret;
+ *out_val = num*intnum/den;
+ return 0;
+}
+
+int av_opt_get_q(void *obj, const char *name, int search_flags, AVRational *out_val)
+{
+ int64_t intnum = 1;
+ double num = 1;
+ int ret, den = 1;
+
+ if ((ret = get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
+ return ret;
+
+ if (num == 1.0 && (int)intnum == intnum)
+ *out_val = (AVRational){intnum, den};
+ else
+ *out_val = av_d2q(num*intnum/den, 1<<24);
+ return 0;
+}
int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name)
{
- const AVOption *field = av_find_opt(obj, field_name, NULL, 0, 0);
- const AVOption *flag = av_find_opt(obj, flag_name, NULL, 0, 0);
+ const AVOption *field = av_opt_find(obj, field_name, NULL, 0, 0);
+ const AVOption *flag = av_opt_find(obj, flag_name,
+ field ? field->unit : NULL, 0, 0);
+ int64_t res;
- if (!field || !flag || flag->type != FF_OPT_TYPE_CONST)
+ if (!field || !flag || flag->type != AV_OPT_TYPE_CONST ||
+ av_opt_get_int(obj, field_name, 0, &res) < 0)
return 0;
- return av_get_int(obj, field_name, NULL) & (int) flag->default_val.dbl;
+ return res & (int) flag->default_val.dbl;
}
static void opt_list(void *obj, void *av_log_obj, const char *unit,
@@ -338,7 +518,7 @@ static void opt_list(void *obj, void *av_log_obj, const char *unit,
{
const AVOption *opt=NULL;
- while ((opt= av_next_option(obj, opt))) {
+ while ((opt = av_opt_next(obj, opt))) {
if (!(opt->flags & req_flags) || (opt->flags & rej_flags))
continue;
@@ -346,43 +526,43 @@ static void opt_list(void *obj, void *av_log_obj, const char *unit,
* Don't print anything but CONST's on level two.
* Only print items from the requested unit.
*/
- if (!unit && opt->type==FF_OPT_TYPE_CONST)
+ if (!unit && opt->type==AV_OPT_TYPE_CONST)
continue;
- else if (unit && opt->type!=FF_OPT_TYPE_CONST)
+ else if (unit && opt->type!=AV_OPT_TYPE_CONST)
continue;
- else if (unit && opt->type==FF_OPT_TYPE_CONST && strcmp(unit, opt->unit))
+ else if (unit && opt->type==AV_OPT_TYPE_CONST && strcmp(unit, opt->unit))
continue;
- else if (unit && opt->type == FF_OPT_TYPE_CONST)
+ else if (unit && opt->type == AV_OPT_TYPE_CONST)
av_log(av_log_obj, AV_LOG_INFO, " %-15s ", opt->name);
else
av_log(av_log_obj, AV_LOG_INFO, "-%-17s ", opt->name);
switch (opt->type) {
- case FF_OPT_TYPE_FLAGS:
+ case AV_OPT_TYPE_FLAGS:
av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "<flags>");
break;
- case FF_OPT_TYPE_INT:
+ case AV_OPT_TYPE_INT:
av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "<int>");
break;
- case FF_OPT_TYPE_INT64:
+ case AV_OPT_TYPE_INT64:
av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "<int64>");
break;
- case FF_OPT_TYPE_DOUBLE:
+ case AV_OPT_TYPE_DOUBLE:
av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "<double>");
break;
- case FF_OPT_TYPE_FLOAT:
+ case AV_OPT_TYPE_FLOAT:
av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "<float>");
break;
- case FF_OPT_TYPE_STRING:
+ case AV_OPT_TYPE_STRING:
av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "<string>");
break;
- case FF_OPT_TYPE_RATIONAL:
+ case AV_OPT_TYPE_RATIONAL:
av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "<rational>");
break;
- case FF_OPT_TYPE_BINARY:
+ case AV_OPT_TYPE_BINARY:
av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "<binary>");
break;
- case FF_OPT_TYPE_CONST:
+ case AV_OPT_TYPE_CONST:
default:
av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "");
break;
@@ -396,7 +576,7 @@ static void opt_list(void *obj, void *av_log_obj, const char *unit,
if (opt->help)
av_log(av_log_obj, AV_LOG_INFO, " %s", opt->help);
av_log(av_log_obj, AV_LOG_INFO, "\n");
- if (opt->unit && opt->type != FF_OPT_TYPE_CONST) {
+ if (opt->unit && opt->type != AV_OPT_TYPE_CONST) {
opt_list(obj, av_log_obj, opt->unit, req_flags, rej_flags);
}
}
@@ -414,51 +594,54 @@ int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags)
return 0;
}
-/** Set the values of the AVCodecContext or AVFormatContext structure.
- * They are set to the defaults specified in the according AVOption options
- * array default_val field.
- *
- * @param s AVCodecContext or AVFormatContext for which the defaults will be set
- */
+void av_opt_set_defaults(void *s)
+{
+#if FF_API_OLD_AVOPTIONS
+ av_opt_set_defaults2(s, 0, 0);
+}
+
void av_opt_set_defaults2(void *s, int mask, int flags)
{
+#endif
const AVOption *opt = NULL;
- while ((opt = av_next_option(s, opt)) != NULL) {
+ while ((opt = av_opt_next(s, opt)) != NULL) {
+#if FF_API_OLD_AVOPTIONS
if ((opt->flags & mask) != flags)
continue;
+#endif
switch (opt->type) {
- case FF_OPT_TYPE_CONST:
+ case AV_OPT_TYPE_CONST:
/* Nothing to be done here */
break;
- case FF_OPT_TYPE_FLAGS:
- case FF_OPT_TYPE_INT: {
+ case AV_OPT_TYPE_FLAGS:
+ case AV_OPT_TYPE_INT: {
int val;
val = opt->default_val.dbl;
- av_set_int(s, opt->name, val);
+ av_opt_set_int(s, opt->name, val, 0);
}
break;
- case FF_OPT_TYPE_INT64:
+ case AV_OPT_TYPE_INT64:
if ((double)(opt->default_val.dbl+0.6) == opt->default_val.dbl)
av_log(s, AV_LOG_DEBUG, "loss of precision in default of %s\n", opt->name);
- av_set_int(s, opt->name, opt->default_val.dbl);
+ av_opt_set_int(s, opt->name, opt->default_val.dbl, 0);
break;
- case FF_OPT_TYPE_DOUBLE:
- case FF_OPT_TYPE_FLOAT: {
+ case AV_OPT_TYPE_DOUBLE:
+ case AV_OPT_TYPE_FLOAT: {
double val;
val = opt->default_val.dbl;
- av_set_double(s, opt->name, val);
+ av_opt_set_double(s, opt->name, val, 0);
}
break;
- case FF_OPT_TYPE_RATIONAL: {
+ case AV_OPT_TYPE_RATIONAL: {
AVRational val;
val = av_d2q(opt->default_val.dbl, INT_MAX);
- av_set_q(s, opt->name, val);
+ av_opt_set_q(s, opt->name, val, 0);
}
break;
- case FF_OPT_TYPE_STRING:
- av_set_string3(s, opt->name, opt->default_val.str, 1, NULL);
+ case AV_OPT_TYPE_STRING:
+ av_opt_set(s, opt->name, opt->default_val.str, 0);
break;
- case FF_OPT_TYPE_BINARY:
+ case AV_OPT_TYPE_BINARY:
/* Cannot set default for binary */
break;
default:
@@ -467,11 +650,6 @@ void av_opt_set_defaults2(void *s, int mask, int flags)
}
}
-void av_opt_set_defaults(void *s)
-{
- av_opt_set_defaults2(s, 0, 0);
-}
-
/**
* Store the value in the field in ctx that is named like key.
* ctx must be an AVClass context, storing is done using AVOptions.
@@ -486,7 +664,7 @@ void av_opt_set_defaults(void *s)
* set, or a negative value corresponding to an AVERROR code in case
* of error:
* AVERROR(EINVAL) if the key/value pair cannot be parsed,
- * the error code issued by av_set_string3() if the key/value pair
+ * the error code issued by av_opt_set() if the key/value pair
* cannot be set
*/
static int parse_key_value_pair(void *ctx, const char **buf,
@@ -507,7 +685,7 @@ static int parse_key_value_pair(void *ctx, const char **buf,
av_log(ctx, AV_LOG_DEBUG, "Setting value '%s' for key '%s'\n", val, key);
- ret = av_set_string3(ctx, key, val, 1, NULL);
+ ret = av_opt_set(ctx, key, val, 0);
if (ret == AVERROR_OPTION_NOT_FOUND)
av_log(ctx, AV_LOG_ERROR, "Key '%s' not found.\n", key);
@@ -521,6 +699,9 @@ int av_set_options_string(void *ctx, const char *opts,
{
int ret, count = 0;
+ if (!opts)
+ return 0;
+
while (*opts) {
if ((ret = parse_key_value_pair(ctx, &opts, key_val_sep, pairs_sep)) < 0)
return ret;
@@ -536,8 +717,8 @@ int av_set_options_string(void *ctx, const char *opts,
void av_opt_free(void *obj)
{
const AVOption *o = NULL;
- while ((o = av_next_option(obj, o)))
- if (o->type == FF_OPT_TYPE_STRING || o->type == FF_OPT_TYPE_BINARY)
+ while ((o = av_opt_next(obj, o)))
+ if (o->type == AV_OPT_TYPE_STRING || o->type == AV_OPT_TYPE_BINARY)
av_freep((uint8_t *)obj + o->offset);
}
@@ -548,7 +729,7 @@ int av_opt_set_dict(void *obj, AVDictionary **options)
int ret = 0;
while ((t = av_dict_get(*options, "", t, AV_DICT_IGNORE_SUFFIX))) {
- ret = av_set_string3(obj, t->key, t->value, 1, NULL);
+ ret = av_opt_set(obj, t->key, t->value, 0);
if (ret == AVERROR_OPTION_NOT_FOUND)
av_dict_set(&tmp, t->key, t->value, 0);
else if (ret < 0) {
@@ -565,21 +746,60 @@ int av_opt_set_dict(void *obj, AVDictionary **options)
const AVOption *av_opt_find(void *obj, const char *name, const char *unit,
int opt_flags, int search_flags)
{
- AVClass *c = *(AVClass**)obj;
+ return av_opt_find2(obj, name, unit, opt_flags, search_flags, NULL);
+}
+
+const AVOption *av_opt_find2(void *obj, const char *name, const char *unit,
+ int opt_flags, int search_flags, void **target_obj)
+{
+ const AVClass *c = *(AVClass**)obj;
const AVOption *o = NULL;
- if (c->opt_find && search_flags & AV_OPT_SEARCH_CHILDREN &&
- (o = c->opt_find(obj, name, unit, opt_flags, search_flags)))
- return o;
+ if (search_flags & AV_OPT_SEARCH_CHILDREN) {
+ if (search_flags & AV_OPT_SEARCH_FAKE_OBJ) {
+ const AVClass *child = NULL;
+ while (child = av_opt_child_class_next(c, child))
+ if (o = av_opt_find2(&child, name, unit, opt_flags, search_flags, NULL))
+ return o;
+ } else {
+ void *child = NULL;
+ while (child = av_opt_child_next(obj, child))
+ if (o = av_opt_find2(child, name, unit, opt_flags, search_flags, target_obj))
+ return o;
+ }
+ }
- while (o = av_next_option(obj, o)) {
- if (!strcmp(o->name, name) && (!unit || (o->unit && !strcmp(o->unit, unit))) &&
- (o->flags & opt_flags) == opt_flags)
+ while (o = av_opt_next(obj, o)) {
+ if (!strcmp(o->name, name) && (o->flags & opt_flags) == opt_flags &&
+ ((!unit && o->type != AV_OPT_TYPE_CONST) ||
+ (unit && o->type == AV_OPT_TYPE_CONST && o->unit && !strcmp(o->unit, unit)))) {
+ if (target_obj) {
+ if (!(search_flags & AV_OPT_SEARCH_FAKE_OBJ))
+ *target_obj = obj;
+ else
+ *target_obj = NULL;
+ }
return o;
+ }
}
return NULL;
}
+void *av_opt_child_next(void *obj, void *prev)
+{
+ const AVClass *c = *(AVClass**)obj;
+ if (c->child_next)
+ return c->child_next(obj, prev);
+ return NULL;
+}
+
+const AVClass *av_opt_child_class_next(const AVClass *parent, const AVClass *prev)
+{
+ if (parent->child_class_next)
+ return parent->child_class_next(prev);
+ return NULL;
+}
+
#ifdef TEST
#undef printf
@@ -601,14 +821,14 @@ typedef struct TestContext
#define TEST_FLAG_MU 04
static const AVOption test_options[]= {
-{"num", "set num", OFFSET(num), FF_OPT_TYPE_INT, {0}, 0, 100 },
-{"toggle", "set toggle", OFFSET(toggle), FF_OPT_TYPE_INT, {0}, 0, 1 },
-{"rational", "set rational", OFFSET(rational), FF_OPT_TYPE_RATIONAL, {0}, 0, 10 },
-{"string", "set string", OFFSET(string), FF_OPT_TYPE_STRING, {0}, CHAR_MIN, CHAR_MAX },
-{"flags", "set flags", OFFSET(flags), FF_OPT_TYPE_FLAGS, {0}, 0, INT_MAX, 0, "flags" },
-{"cool", "set cool flag ", 0, FF_OPT_TYPE_CONST, {TEST_FLAG_COOL}, INT_MIN, INT_MAX, 0, "flags" },
-{"lame", "set lame flag ", 0, FF_OPT_TYPE_CONST, {TEST_FLAG_LAME}, INT_MIN, INT_MAX, 0, "flags" },
-{"mu", "set mu flag ", 0, FF_OPT_TYPE_CONST, {TEST_FLAG_MU}, INT_MIN, INT_MAX, 0, "flags" },
+{"num", "set num", OFFSET(num), AV_OPT_TYPE_INT, {0}, 0, 100 },
+{"toggle", "set toggle", OFFSET(toggle), AV_OPT_TYPE_INT, {0}, 0, 1 },
+{"rational", "set rational", OFFSET(rational), AV_OPT_TYPE_RATIONAL, {0}, 0, 10 },
+{"string", "set string", OFFSET(string), AV_OPT_TYPE_STRING, {0}, CHAR_MIN, CHAR_MAX },
+{"flags", "set flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, {0}, 0, INT_MAX, 0, "flags" },
+{"cool", "set cool flag ", 0, AV_OPT_TYPE_CONST, {TEST_FLAG_COOL}, INT_MIN, INT_MAX, 0, "flags" },
+{"lame", "set lame flag ", 0, AV_OPT_TYPE_CONST, {TEST_FLAG_LAME}, INT_MIN, INT_MAX, 0, "flags" },
+{"mu", "set mu flag ", 0, AV_OPT_TYPE_CONST, {TEST_FLAG_MU}, INT_MIN, INT_MAX, 0, "flags" },
{NULL},
};
@@ -653,7 +873,7 @@ int main(void)
};
test_ctx.class = &test_class;
- av_opt_set_defaults2(&test_ctx, 0, 0);
+ av_opt_set_defaults(&test_ctx);
test_ctx.string = av_strdup("default");
av_log_set_level(AV_LOG_DEBUG);
diff --git a/libavutil/opt.h b/libavutil/opt.h
index 30aa54f5b6..d10b98512a 100644
--- a/libavutil/opt.h
+++ b/libavutil/opt.h
@@ -2,20 +2,20 @@
* AVOptions
* copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -30,9 +30,203 @@
#include "rational.h"
#include "avutil.h"
#include "dict.h"
+#include "log.h"
+
+/**
+ * @defgroup avoptions AVOptions
+ * @{
+ * AVOptions provide a generic system to declare options on arbitrary structs
+ * ("objects"). An option can have a help text, a type and a range of possible
+ * values. Options may then be enumerated, read and written to.
+ *
+ * @section avoptions_implement Implementing AVOptions
+ * This section describes how to add AVOptions capabilities to a struct.
+ *
+ * All AVOptions-related information is stored in an AVClass. Therefore
+ * the first member of the struct must be a pointer to an AVClass describing it.
+ * The option field of the AVClass must be set to a NULL-terminated static array
+ * of AVOptions. Each AVOption must have a non-empty name, a type, a default
+ * value and for number-type AVOptions also a range of allowed values. It must
+ * also declare an offset in bytes from the start of the struct, where the field
+ * associated with this AVOption is located. Other fields in the AVOption struct
+ * should also be set when applicable, but are not required.
+ *
+ * The following example illustrates an AVOptions-enabled struct:
+ * @code
+ * typedef struct test_struct {
+ * AVClass *class;
+ * int int_opt;
+ * char *str_opt;
+ * uint8_t *bin_opt;
+ * int bin_len;
+ * } test_struct;
+ *
+ * static const AVOption options[] = {
+ * { "test_int", "This is a test option of int type.", offsetof(test_struct, int_opt),
+ * AV_OPT_TYPE_INT, { -1 }, INT_MIN, INT_MAX },
+ * { "test_str", "This is a test option of string type.", offsetof(test_struct, str_opt),
+ * AV_OPT_TYPE_STRING },
+ * { "test_bin", "This is a test option of binary type.", offsetof(test_struct, bin_opt),
+ * AV_OPT_TYPE_BINARY },
+ * { NULL },
+ * };
+ *
+ * static const AVClass test_class = {
+ * .class_name = "test class",
+ * .item_name = av_default_item_name,
+ * .option = options,
+ * .version = LIBAVUTIL_VERSION_INT,
+ * };
+ * @endcode
+ *
+ * Next, when allocating your struct, you must ensure that the AVClass pointer
+ * is set to the correct value. Then, av_opt_set_defaults() must be called to
+ * initialize defaults. After that the struct is ready to be used with the
+ * AVOptions API.
+ *
+ * When cleaning up, you may use the av_opt_free() function to automatically
+ * free all the allocated string and binary options.
+ *
+ * Continuing with the above example:
+ *
+ * @code
+ * test_struct *alloc_test_struct(void)
+ * {
+ * test_struct *ret = av_malloc(sizeof(*ret));
+ * ret->class = &test_class;
+ * av_opt_set_defaults(ret);
+ * return ret;
+ * }
+ * void free_test_struct(test_struct **foo)
+ * {
+ * av_opt_free(*foo);
+ * av_freep(foo);
+ * }
+ * @endcode
+ *
+ * @subsection avoptions_implement_nesting Nesting
+ * It may happen that an AVOptions-enabled struct contains another
+ * AVOptions-enabled struct as a member (e.g. AVCodecContext in
+ * libavcodec exports generic options, while its priv_data field exports
+ * codec-specific options). In such a case, it is possible to set up the
+ * parent struct to export a child's options. To do that, simply
+ * implement AVClass.child_next() and AVClass.child_class_next() in the
+ * parent struct's AVClass.
+ * Assuming that the test_struct from above now also contains a
+ * child_struct field:
+ *
+ * @code
+ * typedef struct child_struct {
+ * AVClass *class;
+ * int flags_opt;
+ * } child_struct;
+ * static const AVOption child_opts[] = {
+ * { "test_flags", "This is a test option of flags type.",
+ * offsetof(child_struct, flags_opt), AV_OPT_TYPE_FLAGS, { 0 }, INT_MIN, INT_MAX },
+ * { NULL },
+ * };
+ * static const AVClass child_class = {
+ * .class_name = "child class",
+ * .item_name = av_default_item_name,
+ * .option = child_opts,
+ * .version = LIBAVUTIL_VERSION_INT,
+ * };
+ *
+ * void *child_next(void *obj, void *prev)
+ * {
+ * test_struct *t = obj;
+ * if (!prev && t->child_struct)
+ * return t->child_struct;
+ * return NULL
+ * }
+ * const AVClass child_class_next(const AVClass *prev)
+ * {
+ * return prev ? NULL : &child_class;
+ * }
+ * @endcode
+ * Putting child_next() and child_class_next() as defined above into
+ * test_class will now make child_struct's options accessible through
+ * test_struct (again, proper setup as described above needs to be done on
+ * child_struct right after it is created).
+ *
+ * From the above example it might not be clear why both child_next()
+ * and child_class_next() are needed. The distinction is that child_next()
+ * iterates over actually existing objects, while child_class_next()
+ * iterates over all possible child classes. E.g. if an AVCodecContext
+ * was initialized to use a codec which has private options, then its
+ * child_next() will return AVCodecContext.priv_data and finish
+ * iterating. OTOH child_class_next() on AVCodecContext.av_class will
+ * iterate over all available codecs with private options.
+ *
+ * @subsection avoptions_implement_named_constants Named constants
+ * It is possible to create named constants for options. Simply set the unit
+ * field of the option the constants should apply to to a string and
+ * create the constants themselves as options of type AV_OPT_TYPE_CONST
+ * with their unit field set to the same string.
+ * Their default_val field should contain the value of the named
+ * constant.
+ * For example, to add some named constants for the test_flags option
+ * above, put the following into the child_opts array:
+ * @code
+ * { "test_flags", "This is a test option of flags type.",
+ * offsetof(child_struct, flags_opt), AV_OPT_TYPE_FLAGS, { 0 }, INT_MIN, INT_MAX, "test_unit" },
+ * { "flag1", "This is a flag with value 16", 0, AV_OPT_TYPE_CONST, { 16 }, 0, 0, "test_unit" },
+ * @endcode
+ *
+ * @section avoptions_use Using AVOptions
+ * This section deals with accessing options in an AVOptions-enabled struct.
+ * Such structs in Libav are e.g. AVCodecContext in libavcodec or
+ * AVFormatContext in libavformat.
+ *
+ * @subsection avoptions_use_examine Examining AVOptions
+ * The basic functions for examining options are av_opt_next(), which iterates
+ * over all options defined for one object, and av_opt_find(), which searches
+ * for an option with the given name.
+ *
+ * The situation is more complicated with nesting. An AVOptions-enabled struct
+ * may have AVOptions-enabled children. Passing the AV_OPT_SEARCH_CHILDREN flag
+ * to av_opt_find() will make the function search children recursively.
+ *
+ * For enumerating there are basically two cases. The first is when you want to
+ * get all options that may potentially exist on the struct and its children
+ * (e.g. when constructing documentation). In that case you should call
+ * av_opt_child_class_next() recursively on the parent struct's AVClass. The
+ * second case is when you have an already initialized struct with all its
+ * children and you want to get all options that can be actually written or read
+ * from it. In that case you should call av_opt_child_next() recursively (and
+ * av_opt_next() on each result).
+ *
+ * @subsection avoptions_use_get_set Reading and writing AVOptions
+ * When setting options, you often have a string read directly from the
+ * user. In such a case, simply passing it to av_opt_set() is enough. For
+ * non-string type options, av_opt_set() will parse the string according to the
+ * option type.
+ *
+ * Similarly av_opt_get() will read any option type and convert it to a string
+ * which will be returned. Do not forget that the string is allocated, so you
+ * have to free it with av_free().
+ *
+ * In some cases it may be more convenient to put all options into an
+ * AVDictionary and call av_opt_set_dict() on it. A specific case of this
+ * are the format/codec open functions in lavf/lavc which take a dictionary
+ * filled with option as a parameter. This allows to set some options
+ * that cannot be set otherwise, since e.g. the input file format is not known
+ * before the file is actually opened.
+ * @}
+ */
enum AVOptionType{
- FF_OPT_TYPE_FLAGS,
+ AV_OPT_TYPE_FLAGS,
+ AV_OPT_TYPE_INT,
+ AV_OPT_TYPE_INT64,
+ AV_OPT_TYPE_DOUBLE,
+ AV_OPT_TYPE_FLOAT,
+ AV_OPT_TYPE_STRING,
+ AV_OPT_TYPE_RATIONAL,
+ AV_OPT_TYPE_BINARY, ///< offset must point to a pointer immediately followed by an int for the length
+ AV_OPT_TYPE_CONST = 128,
+#if FF_API_OLD_AVOPTIONS
+ FF_OPT_TYPE_FLAGS = 0,
FF_OPT_TYPE_INT,
FF_OPT_TYPE_INT64,
FF_OPT_TYPE_DOUBLE,
@@ -41,6 +235,7 @@ enum AVOptionType{
FF_OPT_TYPE_RATIONAL,
FF_OPT_TYPE_BINARY, ///< offset must point to a pointer immediately followed by an int for the length
FF_OPT_TYPE_CONST=128,
+#endif
};
/**
@@ -111,6 +306,7 @@ attribute_deprecated
const AVOption *av_find_opt(void *obj, const char *name, const char *unit, int mask, int flags);
#endif
+#if FF_API_OLD_AVOPTIONS
/**
* Set the field of obj with the given name to value.
*
@@ -129,25 +325,27 @@ const AVOption *av_find_opt(void *obj, const char *name, const char *unit, int m
* similarly, '-' unsets a flag.
* @param[out] o_out if non-NULL put here a pointer to the AVOption
* found
- * @param alloc when 1 then the old value will be av_freed() and the
- * new av_strduped()
- * when 0 then no av_free() nor av_strdup() will be used
+ * @param alloc this parameter is currently ignored
* @return 0 if the value has been set, or an AVERROR code in case of
* error:
- * AVERROR(ENOENT) if no matching option exists
+ * AVERROR_OPTION_NOT_FOUND if no matching option exists
* AVERROR(ERANGE) if the value is out of range
* AVERROR(EINVAL) if the value is not valid
+ * @deprecated use av_opt_set()
*/
+attribute_deprecated
int av_set_string3(void *obj, const char *name, const char *val, int alloc, const AVOption **o_out);
-const AVOption *av_set_double(void *obj, const char *name, double n);
-const AVOption *av_set_q(void *obj, const char *name, AVRational n);
-const AVOption *av_set_int(void *obj, const char *name, int64_t n);
-double av_get_double(void *obj, const char *name, const AVOption **o_out);
-AVRational av_get_q(void *obj, const char *name, const AVOption **o_out);
-int64_t av_get_int(void *obj, const char *name, const AVOption **o_out);
-const char *av_get_string(void *obj, const char *name, const AVOption **o_out, char *buf, int buf_len);
-const AVOption *av_next_option(void *obj, const AVOption *last);
+attribute_deprecated const AVOption *av_set_double(void *obj, const char *name, double n);
+attribute_deprecated const AVOption *av_set_q(void *obj, const char *name, AVRational n);
+attribute_deprecated const AVOption *av_set_int(void *obj, const char *name, int64_t n);
+
+attribute_deprecated double av_get_double(void *obj, const char *name, const AVOption **o_out);
+attribute_deprecated AVRational av_get_q(void *obj, const char *name, const AVOption **o_out);
+attribute_deprecated int64_t av_get_int(void *obj, const char *name, const AVOption **o_out);
+attribute_deprecated const char *av_get_string(void *obj, const char *name, const AVOption **o_out, char *buf, int buf_len);
+attribute_deprecated const AVOption *av_next_option(void *obj, const AVOption *last);
+#endif
/**
* Show the obj options.
@@ -160,8 +358,17 @@ const AVOption *av_next_option(void *obj, const AVOption *last);
*/
int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags);
+/**
+ * Set the values of all AVOption fields to their default values.
+ *
+ * @param s an AVOption-enabled struct (its first member must be a pointer to AVClass)
+ */
void av_opt_set_defaults(void *s);
+
+#if FF_API_OLD_AVOPTIONS
+attribute_deprecated
void av_opt_set_defaults2(void *s, int mask, int flags);
+#endif
/**
* Parse the key/value pairs list in opts. For each key/value pair
@@ -169,6 +376,7 @@ void av_opt_set_defaults2(void *s, int mask, int flags);
* key. ctx must be an AVClass context, storing is done using
* AVOptions.
*
+ * @param opts options string to parse, may be NULL
* @param key_val_sep a 0-terminated list of characters used to
* separate key from value
* @param pairs_sep a 0-terminated list of characters used to separate
@@ -213,8 +421,39 @@ int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name)
*/
int av_opt_set_dict(void *obj, struct AVDictionary **options);
+/**
+ * @defgroup opt_eval_funcs Evaluating option strings
+ * @{
+ * This group of functions can be used to evaluate option strings
+ * and get numbers out of them. They do the same thing as av_opt_set(),
+ * except the result is written into the caller-supplied pointer.
+ *
+ * @param obj a struct whose first element is a pointer to AVClass.
+ * @param o an option for which the string is to be evaluated.
+ * @param val string to be evaluated.
+ * @param *_out value of the string will be written here.
+ *
+ * @return 0 on success, a negative number on failure.
+ */
+int av_opt_eval_flags (void *obj, const AVOption *o, const char *val, int *flags_out);
+int av_opt_eval_int (void *obj, const AVOption *o, const char *val, int *int_out);
+int av_opt_eval_int64 (void *obj, const AVOption *o, const char *val, int64_t *int64_out);
+int av_opt_eval_float (void *obj, const AVOption *o, const char *val, float *float_out);
+int av_opt_eval_double(void *obj, const AVOption *o, const char *val, double *double_out);
+int av_opt_eval_q (void *obj, const AVOption *o, const char *val, AVRational *q_out);
+/**
+ * @}
+ */
+
#define AV_OPT_SEARCH_CHILDREN 0x0001 /**< Search in possible children of the
given object first. */
+/**
+ * The obj passed to av_opt_find() is fake -- only a double pointer to AVClass
+ * instead of a required pointer to a struct containing AVClass. This is
+ * useful for searching for options without needing to allocate the corresponding
+ * object.
+ */
+#define AV_OPT_SEARCH_FAKE_OBJ 0x0002
/**
* Look for an option in an object. Consider only options which
@@ -222,6 +461,8 @@ int av_opt_set_dict(void *obj, struct AVDictionary **options);
*
* @param[in] obj A pointer to a struct whose first element is a
* pointer to an AVClass.
+ * Alternatively a double pointer to an AVClass, if
+ * AV_OPT_SEARCH_FAKE_OBJ search flag is set.
* @param[in] name The name of the option to look for.
* @param[in] unit When searching for named constants, name of the unit
* it belongs to.
@@ -239,4 +480,112 @@ int av_opt_set_dict(void *obj, struct AVDictionary **options);
const AVOption *av_opt_find(void *obj, const char *name, const char *unit,
int opt_flags, int search_flags);
+/**
+ * Look for an option in an object. Consider only options which
+ * have all the specified flags set.
+ *
+ * @param[in] obj A pointer to a struct whose first element is a
+ * pointer to an AVClass.
+ * Alternatively a double pointer to an AVClass, if
+ * AV_OPT_SEARCH_FAKE_OBJ search flag is set.
+ * @param[in] name The name of the option to look for.
+ * @param[in] unit When searching for named constants, name of the unit
+ * it belongs to.
+ * @param opt_flags Find only options with all the specified flags set (AV_OPT_FLAG).
+ * @param search_flags A combination of AV_OPT_SEARCH_*.
+ * @param[out] target_obj if non-NULL, an object to which the option belongs will be
+ * written here. It may be different from obj if AV_OPT_SEARCH_CHILDREN is present
+ * in search_flags. This parameter is ignored if search_flags contain
+ * AV_OPT_SEARCH_FAKE_OBJ.
+ *
+ * @return A pointer to the option found, or NULL if no option
+ * was found.
+ */
+const AVOption *av_opt_find2(void *obj, const char *name, const char *unit,
+ int opt_flags, int search_flags, void **target_obj);
+
+/**
+ * Iterate over all AVOptions belonging to obj.
+ *
+ * @param obj an AVOptions-enabled struct or a double pointer to an
+ * AVClass describing it.
+ * @param prev result of the previous call to av_opt_next() on this object
+ * or NULL
+ * @return next AVOption or NULL
+ */
+const AVOption *av_opt_next(void *obj, const AVOption *prev);
+
+/**
+ * Iterate over AVOptions-enabled children of obj.
+ *
+ * @param prev result of a previous call to this function or NULL
+ * @return next AVOptions-enabled child or NULL
+ */
+void *av_opt_child_next(void *obj, void *prev);
+
+/**
+ * Iterate over potential AVOptions-enabled children of parent.
+ *
+ * @param prev result of a previous call to this function or NULL
+ * @return AVClass corresponding to next potential child or NULL
+ */
+const AVClass *av_opt_child_class_next(const AVClass *parent, const AVClass *prev);
+
+/**
+ * @defgroup opt_set_funcs Option setting functions
+ * @{
+ * Those functions set the field of obj with the given name to value.
+ *
+ * @param[in] obj A struct whose first element is a pointer to an AVClass.
+ * @param[in] name the name of the field to set
+ * @param[in] val The value to set. In case of av_opt_set() if the field is not
+ * of a string type, then the given string is parsed.
+ * SI postfixes and some named scalars are supported.
+ * If the field is of a numeric type, it has to be a numeric or named
+ * scalar. Behavior with more than one scalar and +- infix operators
+ * is undefined.
+ * If the field is of a flags type, it has to be a sequence of numeric
+ * scalars or named flags separated by '+' or '-'. Prefixing a flag
+ * with '+' causes it to be set without affecting the other flags;
+ * similarly, '-' unsets a flag.
+ * @param search_flags flags passed to av_opt_find2. I.e. if AV_OPT_SEARCH_CHILDREN
+ * is passed here, then the option may be set on a child of obj.
+ *
+ * @return 0 if the value has been set, or an AVERROR code in case of
+ * error:
+ * AVERROR_OPTION_NOT_FOUND if no matching option exists
+ * AVERROR(ERANGE) if the value is out of range
+ * AVERROR(EINVAL) if the value is not valid
+ */
+int av_opt_set (void *obj, const char *name, const char *val, int search_flags);
+int av_opt_set_int (void *obj, const char *name, int64_t val, int search_flags);
+int av_opt_set_double(void *obj, const char *name, double val, int search_flags);
+int av_opt_set_q (void *obj, const char *name, AVRational val, int search_flags);
+/**
+ * @}
+ */
+
+/**
+ * @defgroup opt_get_funcs Option getting functions
+ * @{
+ * Those functions get a value of the option with the given name from an object.
+ *
+ * @param[in] obj a struct whose first element is a pointer to an AVClass.
+ * @param[in] name name of the option to get.
+ * @param[in] search_flags flags passed to av_opt_find2. I.e. if AV_OPT_SEARCH_CHILDREN
+ * is passed here, then the option may be found in a child of obj.
+ * @param[out] out_val value of the option will be written here
+ * @return 0 on success, a negative error code otherwise
+ */
+/**
+ * @note the returned string will av_malloc()ed and must be av_free()ed by the caller
+ */
+int av_opt_get (void *obj, const char *name, int search_flags, uint8_t **out_val);
+int av_opt_get_int (void *obj, const char *name, int search_flags, int64_t *out_val);
+int av_opt_get_double(void *obj, const char *name, int search_flags, double *out_val);
+int av_opt_get_q (void *obj, const char *name, int search_flags, AVRational *out_val);
+/**
+ * @}
+ */
+
#endif /* AVUTIL_OPT_H */
diff --git a/libavutil/parseutils.c b/libavutil/parseutils.c
index 9bac7ab9ce..698b2d97ca 100644
--- a/libavutil/parseutils.c
+++ b/libavutil/parseutils.c
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -97,7 +97,7 @@ int av_parse_video_size(int *width_ptr, int *height_ptr, const char *str)
{
int i;
int n = FF_ARRAY_ELEMS(video_size_abbrs);
- char *p;
+ const char *p;
int width = 0, height = 0;
for (i = 0; i < n; i++) {
@@ -109,10 +109,10 @@ int av_parse_video_size(int *width_ptr, int *height_ptr, const char *str)
}
if (i == n) {
p = str;
- width = strtol(p, &p, 10);
+ width = strtol(p, (void*)&p, 10);
if (*p)
p++;
- height = strtol(p, &p, 10);
+ height = strtol(p, (void*)&p, 10);
}
if (width <= 0 || height <= 0)
return AVERROR(EINVAL);
@@ -401,7 +401,16 @@ static int date_get_num(const char **pp,
return val;
}
-/* small strptime for ffmpeg */
+/**
+ * Parse the input string p according to the format string fmt and
+ * store its results in the structure dt.
+ * This implementation supports only a subset of the formats supported
+ * by the standard strptime().
+ *
+ * @return a pointer to the first character not processed in this
+ * function call, or NULL in case the function fails to match all of
+ * the fmt string and therefore an error occurred
+ */
static
const char *small_strptime(const char *p, const char *fmt,
struct tm *dt)
@@ -484,7 +493,7 @@ static time_t mktimegm(struct tm *tm)
return t;
}
-int av_parse_time(int64_t *timeval, const char *datestr, int duration)
+int av_parse_time(int64_t *timeval, const char *timestr, int duration)
{
const char *p;
int64_t t;
@@ -506,19 +515,19 @@ int av_parse_time(int64_t *timeval, const char *datestr, int duration)
#undef time
time_t now = time(0);
- len = strlen(datestr);
+ len = strlen(timestr);
if (len > 0)
- lastch = datestr[len - 1];
+ lastch = timestr[len - 1];
else
lastch = '\0';
is_utc = (lastch == 'z' || lastch == 'Z');
memset(&dt, 0, sizeof(dt));
- p = datestr;
+ p = timestr;
q = NULL;
if (!duration) {
- if (!strncasecmp(datestr, "now", len)) {
+ if (!strncasecmp(timestr, "now", len)) {
*timeval = (int64_t) now * 1000000;
return 0;
}
@@ -555,16 +564,16 @@ int av_parse_time(int64_t *timeval, const char *datestr, int duration)
}
}
} else {
- /* parse datestr as a duration */
+ /* parse timestr as a duration */
if (p[0] == '-') {
negative = 1;
++p;
}
- /* parse datestr as HH:MM:SS */
+ /* parse timestr as HH:MM:SS */
q = small_strptime(p, time_fmt[0], &dt);
if (!q) {
- /* parse datestr as S+ */
- dt.tm_sec = strtol(p, (char **)&q, 10);
+ /* parse timestr as S+ */
+ dt.tm_sec = strtol(p, (void *)&q, 10);
if (q == p) {
/* the parsing didn't succeed */
*timeval = INT64_MIN;
diff --git a/libavutil/parseutils.h b/libavutil/parseutils.h
index befbbb56a1..dfaec5eb9b 100644
--- a/libavutil/parseutils.h
+++ b/libavutil/parseutils.h
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -83,7 +83,7 @@ int av_parse_color(uint8_t *rgba_color, const char *color_string, int slen,
* January, 1970 up to the time of the parsed date. If timestr cannot
* be successfully parsed, set *time to INT64_MIN.
- * @param datestr a string representing a date or a duration.
+ * @param timestr a string representing a date or a duration.
* - If a date the syntax is:
* @code
* [{YYYY-MM-DD|YYYYMMDD}[T|t| ]]{{HH[:MM[:SS[.m...]]]}|{HH[MM[SS[.m...]]]}}[Z]
diff --git a/libavutil/pca.c b/libavutil/pca.c
new file mode 100644
index 0000000000..0839d68ed2
--- /dev/null
+++ b/libavutil/pca.c
@@ -0,0 +1,245 @@
+/*
+ * principal component analysis (PCA)
+ * Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * principal component analysis (PCA)
+ */
+
+#include "common.h"
+#include "pca.h"
+
+typedef struct PCA{
+ int count;
+ int n;
+ double *covariance;
+ double *mean;
+}PCA;
+
+PCA *ff_pca_init(int n){
+ PCA *pca;
+ if(n<=0)
+ return NULL;
+
+ pca= av_mallocz(sizeof(PCA));
+ pca->n= n;
+ pca->count=0;
+ pca->covariance= av_mallocz(sizeof(double)*n*n);
+ pca->mean= av_mallocz(sizeof(double)*n);
+
+ return pca;
+}
+
+void ff_pca_free(PCA *pca){
+ av_freep(&pca->covariance);
+ av_freep(&pca->mean);
+ av_free(pca);
+}
+
+void ff_pca_add(PCA *pca, double *v){
+ int i, j;
+ const int n= pca->n;
+
+ for(i=0; i<n; i++){
+ pca->mean[i] += v[i];
+ for(j=i; j<n; j++)
+ pca->covariance[j + i*n] += v[i]*v[j];
+ }
+ pca->count++;
+}
+
+int ff_pca(PCA *pca, double *eigenvector, double *eigenvalue){
+ int i, j, pass;
+ int k=0;
+ const int n= pca->n;
+ double z[n];
+
+ memset(eigenvector, 0, sizeof(double)*n*n);
+
+ for(j=0; j<n; j++){
+ pca->mean[j] /= pca->count;
+ eigenvector[j + j*n] = 1.0;
+ for(i=0; i<=j; i++){
+ pca->covariance[j + i*n] /= pca->count;
+ pca->covariance[j + i*n] -= pca->mean[i] * pca->mean[j];
+ pca->covariance[i + j*n] = pca->covariance[j + i*n];
+ }
+ eigenvalue[j]= pca->covariance[j + j*n];
+ z[j]= 0;
+ }
+
+ for(pass=0; pass < 50; pass++){
+ double sum=0;
+
+ for(i=0; i<n; i++)
+ for(j=i+1; j<n; j++)
+ sum += fabs(pca->covariance[j + i*n]);
+
+ if(sum == 0){
+ for(i=0; i<n; i++){
+ double maxvalue= -1;
+ for(j=i; j<n; j++){
+ if(eigenvalue[j] > maxvalue){
+ maxvalue= eigenvalue[j];
+ k= j;
+ }
+ }
+ eigenvalue[k]= eigenvalue[i];
+ eigenvalue[i]= maxvalue;
+ for(j=0; j<n; j++){
+ double tmp= eigenvector[k + j*n];
+ eigenvector[k + j*n]= eigenvector[i + j*n];
+ eigenvector[i + j*n]= tmp;
+ }
+ }
+ return pass;
+ }
+
+ for(i=0; i<n; i++){
+ for(j=i+1; j<n; j++){
+ double covar= pca->covariance[j + i*n];
+ double t,c,s,tau,theta, h;
+
+ if(pass < 3 && fabs(covar) < sum / (5*n*n)) //FIXME why pass < 3
+ continue;
+ if(fabs(covar) == 0.0) //FIXME should not be needed
+ continue;
+ if(pass >=3 && fabs((eigenvalue[j]+z[j])/covar) > (1LL<<32) && fabs((eigenvalue[i]+z[i])/covar) > (1LL<<32)){
+ pca->covariance[j + i*n]=0.0;
+ continue;
+ }
+
+ h= (eigenvalue[j]+z[j]) - (eigenvalue[i]+z[i]);
+ theta=0.5*h/covar;
+ t=1.0/(fabs(theta)+sqrt(1.0+theta*theta));
+ if(theta < 0.0) t = -t;
+
+ c=1.0/sqrt(1+t*t);
+ s=t*c;
+ tau=s/(1.0+c);
+ z[i] -= t*covar;
+ z[j] += t*covar;
+
+#define ROTATE(a,i,j,k,l) {\
+ double g=a[j + i*n];\
+ double h=a[l + k*n];\
+ a[j + i*n]=g-s*(h+g*tau);\
+ a[l + k*n]=h+s*(g-h*tau); }
+ for(k=0; k<n; k++) {
+ if(k!=i && k!=j){
+ ROTATE(pca->covariance,FFMIN(k,i),FFMAX(k,i),FFMIN(k,j),FFMAX(k,j))
+ }
+ ROTATE(eigenvector,k,i,k,j)
+ }
+ pca->covariance[j + i*n]=0.0;
+ }
+ }
+ for (i=0; i<n; i++) {
+ eigenvalue[i] += z[i];
+ z[i]=0.0;
+ }
+ }
+
+ return -1;
+}
+
+#ifdef TEST
+
+#undef printf
+#include <stdio.h>
+#include <stdlib.h>
+#include "lfg.h"
+
+int main(void){
+ PCA *pca;
+ int i, j, k;
+#define LEN 8
+ double eigenvector[LEN*LEN];
+ double eigenvalue[LEN];
+ AVLFG prng;
+
+ av_lfg_init(&prng, 1);
+
+ pca= ff_pca_init(LEN);
+
+ for(i=0; i<9000000; i++){
+ double v[2*LEN+100];
+ double sum=0;
+ int pos = av_lfg_get(&prng) % LEN;
+ int v2 = av_lfg_get(&prng) % 101 - 50;
+ v[0] = av_lfg_get(&prng) % 101 - 50;
+ for(j=1; j<8; j++){
+ if(j<=pos) v[j]= v[0];
+ else v[j]= v2;
+ sum += v[j];
+ }
+/* for(j=0; j<LEN; j++){
+ v[j] -= v[pos];
+ }*/
+// sum += av_lfg_get(&prng) % 10;
+/* for(j=0; j<LEN; j++){
+ v[j] -= sum/LEN;
+ }*/
+// lbt1(v+100,v+100,LEN);
+ ff_pca_add(pca, v);
+ }
+
+
+ ff_pca(pca, eigenvector, eigenvalue);
+ for(i=0; i<LEN; i++){
+ pca->count= 1;
+ pca->mean[i]= 0;
+
+// (0.5^|x|)^2 = 0.5^2|x| = 0.25^|x|
+
+
+// pca.covariance[i + i*LEN]= pow(0.5, fabs
+ for(j=i; j<LEN; j++){
+ printf("%f ", pca->covariance[i + j*LEN]);
+ }
+ printf("\n");
+ }
+
+ for(i=0; i<LEN; i++){
+ double v[LEN];
+ double error=0;
+ memset(v, 0, sizeof(v));
+ for(j=0; j<LEN; j++){
+ for(k=0; k<LEN; k++){
+ v[j] += pca->covariance[FFMIN(k,j) + FFMAX(k,j)*LEN] * eigenvector[i + k*LEN];
+ }
+ v[j] /= eigenvalue[i];
+ error += fabs(v[j] - eigenvector[i + j*LEN]);
+ }
+ printf("%f ", error);
+ }
+ printf("\n");
+
+ for(i=0; i<LEN; i++){
+ for(j=0; j<LEN; j++){
+ printf("%9.6f ", eigenvector[i + j*LEN]);
+ }
+ printf(" %9.1f %f\n", eigenvalue[i], eigenvalue[i]/eigenvalue[0]);
+ }
+
+ return 0;
+}
+#endif
diff --git a/libavutil/pca.h b/libavutil/pca.h
new file mode 100644
index 0000000000..00ddd60c7e
--- /dev/null
+++ b/libavutil/pca.h
@@ -0,0 +1,35 @@
+/*
+ * principal component analysis (PCA)
+ * Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * principal component analysis (PCA)
+ */
+
+#ifndef AVUTIL_PCA_H
+#define AVUTIL_PCA_H
+
+struct PCA *ff_pca_init(int n);
+void ff_pca_free(struct PCA *pca);
+void ff_pca_add(struct PCA *pca, double *v);
+int ff_pca(struct PCA *pca, double *eigenvector, double *eigenvalue);
+
+#endif /* AVUTIL_PCA_H */
diff --git a/libavutil/pixdesc.c b/libavutil/pixdesc.c
index efc7c7ea0e..5d0a9dfaeb 100644
--- a/libavutil/pixdesc.c
+++ b/libavutil/pixdesc.c
@@ -2,20 +2,20 @@
* pixel format descriptor
* Copyright (c) 2009 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -561,6 +561,31 @@ const AVPixFmtDescriptor av_pix_fmt_descriptors[PIX_FMT_NB] = {
{0,5,5,0,15}, /* B */
},
},
+ [PIX_FMT_RGBA64BE] = {
+ .name = "rgba64be",
+ .nb_components= 4,
+ .log2_chroma_w= 0,
+ .log2_chroma_h= 0,
+ .comp = {
+ {0,5,1,0,15}, /* R */
+ {0,5,3,0,15}, /* G */
+ {0,5,5,0,15}, /* B */
+ {0,5,7,0,15}, /* A */
+ },
+ .flags = PIX_FMT_BE,
+ },
+ [PIX_FMT_RGBA64LE] = {
+ .name = "rgba64le",
+ .nb_components= 4,
+ .log2_chroma_w= 0,
+ .log2_chroma_h= 0,
+ .comp = {
+ {0,5,1,0,15}, /* R */
+ {0,5,3,0,15}, /* G */
+ {0,5,5,0,15}, /* B */
+ {0,5,7,0,15}, /* B */
+ },
+ },
[PIX_FMT_RGB565BE] = {
.name = "rgb565be",
.nb_components= 3,
@@ -653,6 +678,31 @@ const AVPixFmtDescriptor av_pix_fmt_descriptors[PIX_FMT_NB] = {
{0,5,5,0,15}, /* R */
},
},
+ [PIX_FMT_BGRA64BE] = {
+ .name = "bgra64be",
+ .nb_components= 4,
+ .log2_chroma_w= 0,
+ .log2_chroma_h= 0,
+ .comp = {
+ {0,5,1,0,15}, /* B */
+ {0,5,3,0,15}, /* G */
+ {0,5,5,0,15}, /* R */
+ {0,5,7,0,15}, /* A */
+ },
+ .flags = PIX_FMT_BE,
+ },
+ [PIX_FMT_BGRA64LE] = {
+ .name = "bgra64le",
+ .nb_components= 4,
+ .log2_chroma_w= 0,
+ .log2_chroma_h= 0,
+ .comp = {
+ {0,5,1,0,15}, /* B */
+ {0,5,3,0,15}, /* G */
+ {0,5,5,0,15}, /* R */
+ {0,5,7,0,15}, /* A */
+ },
+ },
[PIX_FMT_BGR565BE] = {
.name = "bgr565be",
.nb_components= 3,
@@ -809,6 +859,29 @@ const AVPixFmtDescriptor av_pix_fmt_descriptors[PIX_FMT_NB] = {
},
.flags = PIX_FMT_BE,
},
+ [PIX_FMT_YUV422P9LE] = {
+ .name = "yuv422p9le",
+ .nb_components= 3,
+ .log2_chroma_w= 1,
+ .log2_chroma_h= 0,
+ .comp = {
+ {0,1,1,0,8}, /* Y */
+ {1,1,1,0,8}, /* U */
+ {2,1,1,0,8}, /* V */
+ },
+ },
+ [PIX_FMT_YUV422P9BE] = {
+ .name = "yuv422p9be",
+ .nb_components= 3,
+ .log2_chroma_w= 1,
+ .log2_chroma_h= 0,
+ .comp = {
+ {0,1,1,0,8}, /* Y */
+ {1,1,1,0,8}, /* U */
+ {2,1,1,0,8}, /* V */
+ },
+ .flags = PIX_FMT_BE,
+ },
[PIX_FMT_YUV422P10LE] = {
.name = "yuv422p10le",
.nb_components= 3,
@@ -918,9 +991,9 @@ const AVPixFmtDescriptor av_pix_fmt_descriptors[PIX_FMT_NB] = {
.log2_chroma_w= 0,
.log2_chroma_h= 0,
.comp = {
- {0,1,1,0,9}, /* Y */
- {1,1,1,0,9}, /* U */
- {2,1,1,0,9}, /* V */
+ {0,1,1,0,8}, /* Y */
+ {1,1,1,0,8}, /* U */
+ {2,1,1,0,8}, /* V */
},
.flags = PIX_FMT_BE,
},
@@ -930,14 +1003,23 @@ const AVPixFmtDescriptor av_pix_fmt_descriptors[PIX_FMT_NB] = {
.log2_chroma_h = 1,
.flags = PIX_FMT_HWACCEL,
},
- [PIX_FMT_Y400A] = {
- .name = "y400a",
+ [PIX_FMT_GRAY8A] = {
+ .name = "gray8a",
.nb_components= 2,
.comp = {
{0,1,1,0,7}, /* Y */
{0,1,2,0,7}, /* A */
},
},
+ [PIX_FMT_GBR24P] = {
+ .name = "gbr24p",
+ .nb_components= 3,
+ .comp = {
+ {1,0,1,0,7}, /* B */
+ {0,0,1,0,7}, /* G */
+ {2,0,1,0,7}, /* R */
+ },
+ },
};
static enum PixelFormat get_pix_fmt_internal(const char *name)
diff --git a/libavutil/pixdesc.h b/libavutil/pixdesc.h
index 979a23539b..f0de9981ec 100644
--- a/libavutil/pixdesc.h
+++ b/libavutil/pixdesc.h
@@ -2,20 +2,20 @@
* pixel format descriptor
* Copyright (c) 2009 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavutil/pixfmt.h b/libavutil/pixfmt.h
index 9bf793866a..25c9ef99ff 100644
--- a/libavutil/pixfmt.h
+++ b/libavutil/pixfmt.h
@@ -1,20 +1,20 @@
/*
* copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -132,9 +132,13 @@ enum PixelFormat {
PIX_FMT_RGB444BE, ///< packed RGB 4:4:4, 16bpp, (msb)4A 4R 4G 4B(lsb), big-endian, most significant bits to 0
PIX_FMT_BGR444LE, ///< packed BGR 4:4:4, 16bpp, (msb)4A 4B 4G 4R(lsb), little-endian, most significant bits to 1
PIX_FMT_BGR444BE, ///< packed BGR 4:4:4, 16bpp, (msb)4A 4B 4G 4R(lsb), big-endian, most significant bits to 1
- PIX_FMT_Y400A, ///< 8bit gray, 8bit alpha
+ PIX_FMT_GRAY8A, ///< 8bit gray, 8bit alpha
PIX_FMT_BGR48BE, ///< packed RGB 16:16:16, 48bpp, 16B, 16G, 16R, the 2-byte value for each R/G/B component is stored as big-endian
PIX_FMT_BGR48LE, ///< packed RGB 16:16:16, 48bpp, 16B, 16G, 16R, the 2-byte value for each R/G/B component is stored as little-endian
+
+ //the following 10 formats have the disadvantage of needing 1 format for each bit depth, thus
+ //If you want to support multiple bit depths, then using PIX_FMT_YUV420P16* with the bpp stored seperately
+ //is better
PIX_FMT_YUV420P9BE, ///< planar YUV 4:2:0, 13.5bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
PIX_FMT_YUV420P9LE, ///< planar YUV 4:2:0, 13.5bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
PIX_FMT_YUV420P10BE,///< planar YUV 4:2:0, 15bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
@@ -145,9 +149,20 @@ enum PixelFormat {
PIX_FMT_YUV444P9LE, ///< planar YUV 4:4:4, 27bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
PIX_FMT_YUV444P10BE,///< planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
PIX_FMT_YUV444P10LE,///< planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
+ PIX_FMT_YUV422P9BE, ///< planar YUV 4:2:2, 18bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
+ PIX_FMT_YUV422P9LE, ///< planar YUV 4:2:2, 18bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
+
+ PIX_FMT_RGBA64BE, ///< packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is stored as big-endian
+ PIX_FMT_RGBA64LE, ///< packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is stored as little-endian
+ PIX_FMT_BGRA64BE, ///< packed RGBA 16:16:16:16, 64bpp, 16B, 16G, 16R, 16A, the 2-byte value for each R/G/B/A component is stored as big-endian
+ PIX_FMT_BGRA64LE, ///< packed RGBA 16:16:16:16, 64bpp, 16B, 16G, 16R, 16A, the 2-byte value for each R/G/B/A component is stored as little-endian
+ PIX_FMT_GBR24P, ///< planar GBR, 24bpp, 8G, 8B, 8R.
+
PIX_FMT_NB, ///< number of pixel formats, DO NOT USE THIS if you want to link with shared libav* because the number of formats might differ between versions
};
+#define PIX_FMT_Y400A PIX_FMT_GRAY8A
+
#if AV_HAVE_BIGENDIAN
# define PIX_FMT_NE(be, le) PIX_FMT_##be
#else
@@ -170,6 +185,7 @@ enum PixelFormat {
#define PIX_FMT_BGR444 PIX_FMT_NE(BGR444BE, BGR444LE)
#define PIX_FMT_YUV420P9 PIX_FMT_NE(YUV420P9BE , YUV420P9LE)
+#define PIX_FMT_YUV422P9 PIX_FMT_NE(YUV422P9BE , YUV422P9LE)
#define PIX_FMT_YUV444P9 PIX_FMT_NE(YUV444P9BE , YUV444P9LE)
#define PIX_FMT_YUV420P10 PIX_FMT_NE(YUV420P10BE, YUV420P10LE)
#define PIX_FMT_YUV422P10 PIX_FMT_NE(YUV422P10BE, YUV422P10LE)
@@ -178,4 +194,6 @@ enum PixelFormat {
#define PIX_FMT_YUV422P16 PIX_FMT_NE(YUV422P16BE, YUV422P16LE)
#define PIX_FMT_YUV444P16 PIX_FMT_NE(YUV444P16BE, YUV444P16LE)
+#define PIX_FMT_RGBA64 PIX_FMT_NE(RGBA64BE, RGBA64LE)
+#define PIX_FMT_BGRA64 PIX_FMT_NE(BGRA64BE, BGRA64LE)
#endif /* AVUTIL_PIXFMT_H */
diff --git a/libavutil/ppc/cpu.c b/libavutil/ppc/cpu.c
index 002571161a..fc38be6f65 100644
--- a/libavutil/ppc/cpu.c
+++ b/libavutil/ppc/cpu.c
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavutil/ppc/intreadwrite.h b/libavutil/ppc/intreadwrite.h
index fec54e63c5..3667703cf0 100644
--- a/libavutil/ppc/intreadwrite.h
+++ b/libavutil/ppc/intreadwrite.h
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2008 Mans Rullgard <mans@mansr.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavutil/ppc/timer.h b/libavutil/ppc/timer.h
index 0981d0cdbc..155fc01507 100644
--- a/libavutil/ppc/timer.h
+++ b/libavutil/ppc/timer.h
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2005 Luca Barbato <lu_zero@gentoo.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavutil/random_seed.c b/libavutil/random_seed.c
index a1078d8bbb..81805e5db0 100644
--- a/libavutil/random_seed.c
+++ b/libavutil/random_seed.c
@@ -1,29 +1,29 @@
/*
* Copyright (c) 2009 Baptiste Coudurier <baptiste.coudurier@gmail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <unistd.h>
#include <fcntl.h>
+#include <math.h>
+#include <time.h>
#include "timer.h"
-#include "time.h"
#include "random_seed.h"
-#include "avutil.h"
static int read_random(uint32_t *dst, const char *file)
{
diff --git a/libavutil/random_seed.h b/libavutil/random_seed.h
index 5bfeb8b835..bb957879be 100644
--- a/libavutil/random_seed.h
+++ b/libavutil/random_seed.h
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2009 Baptiste Coudurier <baptiste.coudurier@gmail.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -24,12 +24,11 @@
#include <stdint.h>
/**
- * Get random data.
- *
- * This function can be called repeatedly to generate more random bits
- * as needed. It is generally quite slow, and usually used to seed a
- * PRNG. As it uses /dev/urandom and /dev/random, the quality of the
- * returned random data depends on the platform.
+ * Get a seed to use in conjunction with random functions.
+ * This function tries to provide a good seed at a best effort bases.
+ * Its possible to call this function multiple times if more bits are needed.
+ * It can be quite slow, which is why it should only be used as seed for a faster
+ * PRNG. The quality of the seed depends on the platform.
*/
uint32_t av_get_random_seed(void);
diff --git a/libavutil/rational.c b/libavutil/rational.c
index ac5111b896..b1bd655158 100644
--- a/libavutil/rational.c
+++ b/libavutil/rational.c
@@ -2,20 +2,20 @@
* rational numbers
* Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavutil/rational.h b/libavutil/rational.h
index a4871148bd..789e4aca2c 100644
--- a/libavutil/rational.h
+++ b/libavutil/rational.h
@@ -2,20 +2,20 @@
* rational numbers
* Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavutil/rc4.c b/libavutil/rc4.c
index 3bf710f3f1..4e52ba5ac1 100644
--- a/libavutil/rc4.c
+++ b/libavutil/rc4.c
@@ -4,20 +4,20 @@
*
* loosely based on LibTomCrypt by Tom St Denis
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avutil.h"
diff --git a/libavutil/rc4.h b/libavutil/rc4.h
index ec3b47cc8a..9362fd8880 100644
--- a/libavutil/rc4.h
+++ b/libavutil/rc4.h
@@ -1,20 +1,20 @@
/*
* RC4 encryption/decryption/pseudo-random number generator
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavutil/samplefmt.c b/libavutil/samplefmt.c
index 5b0bfa0257..6f7070e43c 100644
--- a/libavutil/samplefmt.c
+++ b/libavutil/samplefmt.c
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -79,3 +79,52 @@ int av_get_bits_per_sample_fmt(enum AVSampleFormat sample_fmt)
0 : sample_fmt_info[sample_fmt].bits;
}
#endif
+
+int av_samples_fill_arrays(uint8_t *pointers[8], int linesizes[8],
+ uint8_t *buf, int nb_channels, int nb_samples,
+ enum AVSampleFormat sample_fmt, int planar, int align)
+{
+ int i, linesize;
+ int sample_size = av_get_bytes_per_sample(sample_fmt);
+
+ if (nb_channels * (uint64_t)nb_samples * sample_size >= INT_MAX - align*(uint64_t)nb_channels)
+ return AVERROR(EINVAL);
+ linesize = planar ? FFALIGN(nb_samples*sample_size, align) :
+ FFALIGN(nb_samples*sample_size*nb_channels, align);
+
+ if (pointers) {
+ pointers[0] = buf;
+ for (i = 1; planar && i < nb_channels; i++) {
+ pointers[i] = pointers[i-1] + linesize;
+ }
+ memset(&pointers[i], 0, (8-i) * sizeof(pointers[0]));
+ }
+
+ if (linesizes) {
+ linesizes[0] = linesize;
+ for (i = 1; planar && i < nb_channels; i++)
+ linesizes[i] = linesizes[0];
+ memset(&linesizes[i], 0, (8-i) * sizeof(linesizes[0]));
+ }
+
+ return planar ? linesize * nb_channels : linesize;
+}
+
+int av_samples_alloc(uint8_t *pointers[8], int linesizes[8],
+ int nb_channels, int nb_samples,
+ enum AVSampleFormat sample_fmt, int planar,
+ int align)
+{
+ uint8_t *buf;
+ int size = av_samples_fill_arrays(NULL, NULL,
+ NULL, nb_channels, nb_samples,
+ sample_fmt, planar, align);
+
+ buf = av_mallocz(size);
+ if (!buf)
+ return AVERROR(ENOMEM);
+
+ return av_samples_fill_arrays(pointers, linesizes,
+ buf, nb_channels, nb_samples,
+ sample_fmt, planar, align);
+}
diff --git a/libavutil/samplefmt.h b/libavutil/samplefmt.h
index e38214927f..b06755d2ce 100644
--- a/libavutil/samplefmt.h
+++ b/libavutil/samplefmt.h
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -77,4 +77,49 @@ int av_get_bits_per_sample_fmt(enum AVSampleFormat sample_fmt);
*/
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt);
-#endif /* AVUTIL_SAMPLEFMT_H */
+/**
+ * Fill channel data pointers and linesizes for samples with sample
+ * format sample_fmt.
+ *
+ * The pointers array is filled with the pointers to the samples data:
+ * for planar, set the start point of each plane's data within the buffer,
+ * for packed, set the start point of the entire buffer only.
+ *
+ * The linesize array is filled with the aligned size of each samples
+ * plane, that is linesize[i] will contain the linesize of the plane i,
+ * and will be zero for all the unused planes. All linesize values are
+ * equal.
+ *
+ * @param pointers array to be filled with the pointer for each plane, may be NULL
+ * @param linesizes array to be filled with the linesize, may be NULL
+ * @param buf the pointer to a buffer containing the samples
+ * @param nb_samples the number of samples in a single channel
+ * @param planar 1 if the samples layout is planar, 0 if it is packed
+ * @param nb_channels the number of channels
+ * @return the total size of the buffer, a negative
+ * error code in case of failure
+ */
+int av_samples_fill_arrays(uint8_t *pointers[8], int linesizes[8],
+ uint8_t *buf, int nb_channels, int nb_samples,
+ enum AVSampleFormat sample_fmt, int planar, int align);
+
+/**
+ * Allocate a samples buffer for nb_samples samples, and
+ * fill pointers and linesizes accordingly.
+ * The allocated samples buffer has to be freed by using
+ * av_freep(&pointers[0]).
+ *
+ * @param nb_channels number of audio channels
+ * @param nb_samples number of samples per channel
+ * @param planar 1 if the samples layout is planar, 0 if packed,
+ * @param align the value to use for buffer size alignment
+ * @return the size in bytes required for the samples buffer, a negative
+ * error code in case of failure
+ * @see av_samples_fill_arrays()
+ */
+int av_samples_alloc(uint8_t *pointers[8], int linesizes[8],
+ int nb_channels, int nb_samples,
+ enum AVSampleFormat sample_fmt, int planar,
+ int align);
+
+#endif /* AVCORE_SAMPLEFMT_H */
diff --git a/libavutil/sh4/bswap.h b/libavutil/sh4/bswap.h
index 1ff1bfdd37..48dd27f806 100644
--- a/libavutil/sh4/bswap.h
+++ b/libavutil/sh4/bswap.h
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavutil/sha.c b/libavutil/sha.c
index 5af742dc48..301d1606b4 100644
--- a/libavutil/sha.c
+++ b/libavutil/sha.c
@@ -4,20 +4,20 @@
* based on public domain SHA-1 code by Steve Reid <steve@edmweb.com>
* and on BSD-licensed SHA-2 code by Aaron D. Gifford
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavutil/sha.h b/libavutil/sha.h
index df261fa4b5..543f5a1949 100644
--- a/libavutil/sha.h
+++ b/libavutil/sha.h
@@ -1,20 +1,20 @@
/*
* Copyright (C) 2007 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavutil/softfloat.c b/libavutil/softfloat.c
new file mode 100644
index 0000000000..efa0420b4f
--- /dev/null
+++ b/libavutil/softfloat.c
@@ -0,0 +1,72 @@
+/*
+ * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <inttypes.h>
+#include <stdio.h>
+#include <assert.h>
+#include "softfloat.h"
+#include "common.h"
+#include "log.h"
+
+#undef printf
+
+int main(void){
+ SoftFloat one= av_int2sf(1, 0);
+ SoftFloat sf1, sf2;
+ double d1, d2;
+ int i, j;
+ av_log_set_level(AV_LOG_DEBUG);
+
+ d1= 1;
+ for(i= 0; i<10; i++){
+ d1= 1/(d1+1);
+ }
+ printf("test1 double=%d\n", (int)(d1 * (1<<24)));
+
+ sf1= one;
+ for(i= 0; i<10; i++){
+ sf1= av_div_sf(one, av_normalize_sf(av_add_sf(one, sf1)));
+ }
+ printf("test1 sf =%d\n", av_sf2int(sf1, 24));
+
+
+ for(i= 0; i<100; i++){
+ START_TIMER
+ d1= i;
+ d2= i/100.0;
+ for(j= 0; j<1000; j++){
+ d1= (d1+1)*d2;
+ }
+ STOP_TIMER("float add mul")
+ }
+ printf("test2 double=%d\n", (int)(d1 * (1<<24)));
+
+ for(i= 0; i<100; i++){
+ START_TIMER
+ sf1= av_int2sf(i, 0);
+ sf2= av_div_sf(av_int2sf(i, 2), av_int2sf(200, 3));
+ for(j= 0; j<1000; j++){
+ sf1= av_mul_sf(av_add_sf(sf1, one),sf2);
+ }
+ STOP_TIMER("softfloat add mul")
+ }
+ printf("test2 sf =%d (%d %d)\n", av_sf2int(sf1, 24), sf1.exp, sf1.mant);
+ return 0;
+}
diff --git a/libavutil/softfloat.h b/libavutil/softfloat.h
new file mode 100644
index 0000000000..97e09ea7e7
--- /dev/null
+++ b/libavutil/softfloat.h
@@ -0,0 +1,126 @@
+/*
+ * Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_SOFTFLOAT_H
+#define AVUTIL_SOFTFLOAT_H
+
+#include <stdint.h>
+#include "common.h"
+
+#define MIN_EXP -126
+#define MAX_EXP 126
+#define ONE_BITS 29
+
+typedef struct SoftFloat{
+ int32_t exp;
+ int32_t mant;
+}SoftFloat;
+
+static av_const SoftFloat av_normalize_sf(SoftFloat a){
+ if(a.mant){
+#if 1
+ while((a.mant + 0x20000000U)<0x40000000U){
+ a.mant += a.mant;
+ a.exp -= 1;
+ }
+#else
+ int s=ONE_BITS + 1 - av_log2(a.mant ^ (a.mant<<1));
+ a.exp -= s;
+ a.mant <<= s;
+#endif
+ if(a.exp < MIN_EXP){
+ a.exp = MIN_EXP;
+ a.mant= 0;
+ }
+ }else{
+ a.exp= MIN_EXP;
+ }
+ return a;
+}
+
+static inline av_const SoftFloat av_normalize1_sf(SoftFloat a){
+#if 1
+ if(a.mant + 0x40000000 < 0){
+ a.exp++;
+ a.mant>>=1;
+ }
+ return a;
+#elif 1
+ int t= a.mant + 0x40000000 < 0;
+ return (SoftFloat){a.exp+t, a.mant>>t};
+#else
+ int t= (a.mant + 0x40000000U)>>31;
+ return (SoftFloat){a.exp+t, a.mant>>t};
+#endif
+}
+
+/**
+ * @return Will not be more denormalized than a+b. So if either input is
+ * normalized, then the output will not be worse then the other input.
+ * If both are normalized, then the output will be normalized.
+ */
+static inline av_const SoftFloat av_mul_sf(SoftFloat a, SoftFloat b){
+ a.exp += b.exp;
+ a.mant = (a.mant * (int64_t)b.mant) >> ONE_BITS;
+ return av_normalize1_sf(a);
+}
+
+/**
+ * b has to be normalized and not zero.
+ * @return Will not be more denormalized than a.
+ */
+static av_const SoftFloat av_div_sf(SoftFloat a, SoftFloat b){
+ a.exp -= b.exp+1;
+ a.mant = ((int64_t)a.mant<<(ONE_BITS+1)) / b.mant;
+ return av_normalize1_sf(a);
+}
+
+static inline av_const int av_cmp_sf(SoftFloat a, SoftFloat b){
+ int t= a.exp - b.exp;
+ if(t<0) return (a.mant >> (-t)) - b.mant ;
+ else return a.mant - (b.mant >> t);
+}
+
+static inline av_const SoftFloat av_add_sf(SoftFloat a, SoftFloat b){
+ int t= a.exp - b.exp;
+ if(t<0) return av_normalize1_sf((SoftFloat){b.exp, b.mant + (a.mant >> (-t))});
+ else return av_normalize1_sf((SoftFloat){a.exp, a.mant + (b.mant >> t )});
+}
+
+static inline av_const SoftFloat av_sub_sf(SoftFloat a, SoftFloat b){
+ return av_add_sf(a, (SoftFloat){b.exp, -b.mant});
+}
+
+//FIXME sqrt, log, exp, pow, sin, cos
+
+static inline av_const SoftFloat av_int2sf(int v, int frac_bits){
+ return av_normalize_sf((SoftFloat){ONE_BITS-frac_bits, v});
+}
+
+/**
+ * Rounding is to -inf.
+ */
+static inline av_const int av_sf2int(SoftFloat v, int frac_bits){
+ v.exp += frac_bits - ONE_BITS;
+ if(v.exp >= 0) return v.mant << v.exp ;
+ else return v.mant >>(-v.exp);
+}
+
+#endif /* AVUTIL_SOFTFLOAT_H */
diff --git a/libavutil/timer.h b/libavutil/timer.h
index a2ca5cf828..8a0cad56ca 100644
--- a/libavutil/timer.h
+++ b/libavutil/timer.h
@@ -1,26 +1,28 @@
-/**
- * @file
- * high precision timer, useful to profile code
- *
+/*
* copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+/**
+ * @file
+ * high precision timer, useful to profile code
+ */
+
#ifndef AVUTIL_TIMER_H
#define AVUTIL_TIMER_H
diff --git a/libavutil/tomi/intreadwrite.h b/libavutil/tomi/intreadwrite.h
index 92950043e4..778b804ca1 100644
--- a/libavutil/tomi/intreadwrite.h
+++ b/libavutil/tomi/intreadwrite.h
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2010 Mans Rullgard <mans@mansr.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavutil/tree.c b/libavutil/tree.c
index 067e5b096e..8769c76b0f 100644
--- a/libavutil/tree.c
+++ b/libavutil/tree.c
@@ -1,20 +1,20 @@
/*
* copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavutil/tree.h b/libavutil/tree.h
index 9115e2fec1..8c7de2ffbf 100644
--- a/libavutil/tree.h
+++ b/libavutil/tree.h
@@ -1,20 +1,20 @@
/*
* copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavutil/utils.c b/libavutil/utils.c
index 9b18c97908..e6c8424ab4 100644
--- a/libavutil/utils.c
+++ b/libavutil/utils.c
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -31,13 +31,25 @@ unsigned avutil_version(void)
const char *avutil_configuration(void)
{
- return LIBAV_CONFIGURATION;
+ return FFMPEG_CONFIGURATION;
}
const char *avutil_license(void)
{
#define LICENSE_PREFIX "libavutil license: "
- return LICENSE_PREFIX LIBAV_LICENSE + sizeof(LICENSE_PREFIX) - 1;
+ return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1;
+}
+
+const char *av_get_media_type_string(enum AVMediaType media_type)
+{
+ switch (media_type) {
+ case AVMEDIA_TYPE_VIDEO: return "video";
+ case AVMEDIA_TYPE_AUDIO: return "audio";
+ case AVMEDIA_TYPE_DATA: return "data";
+ case AVMEDIA_TYPE_SUBTITLE: return "subtitle";
+ case AVMEDIA_TYPE_ATTACHMENT: return "attachment";
+ default: return NULL;
+ }
}
char av_get_picture_type_char(enum AVPictureType pict_type)
diff --git a/libavutil/x86/bswap.h b/libavutil/x86/bswap.h
index b60d9ccd6c..b0d62b248a 100644
--- a/libavutil/x86/bswap.h
+++ b/libavutil/x86/bswap.h
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavutil/x86/cpu.c b/libavutil/x86/cpu.c
index 78aeadf0a1..bb3f1b325b 100644
--- a/libavutil/x86/cpu.c
+++ b/libavutil/x86/cpu.c
@@ -3,20 +3,20 @@
* (c)1997-99 by H. Dietz and R. Fisher
* Converted to C and improved by Fabrice Bellard.
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -113,7 +113,7 @@ int ff_get_cpu_flags_x86(void)
if(max_ext_level >= 0x80000001){
cpuid(0x80000001, eax, ebx, ecx, ext_caps);
- if (ext_caps & (1<<31))
+ if (ext_caps & (1U<<31))
rval |= AV_CPU_FLAG_3DNOW;
if (ext_caps & (1<<30))
rval |= AV_CPU_FLAG_3DNOWEXT;
@@ -133,6 +133,15 @@ int ff_get_cpu_flags_x86(void)
rval & AV_CPU_FLAG_SSE2 && !(ecx & 0x00000040)) {
rval |= AV_CPU_FLAG_SSE2SLOW;
}
+
+ /* XOP and FMA4 use the AVX instruction coding scheme, so they can't be
+ * used unless the OS has AVX support. */
+ if (rval & AV_CPU_FLAG_AVX) {
+ if (ecx & 0x00000800)
+ rval |= AV_CPU_FLAG_XOP;
+ if (ecx & 0x00010000)
+ rval |= AV_CPU_FLAG_FMA4;
+ }
}
if (!strncmp(vendor.c, "GenuineIntel", 12)) {
diff --git a/libavutil/x86/intmath.h b/libavutil/x86/intmath.h
index a7e82b1340..f3acddc0e3 100644
--- a/libavutil/x86/intmath.h
+++ b/libavutil/x86/intmath.h
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2010 Mans Rullgard <mans@mansr.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavutil/x86/intreadwrite.h b/libavutil/x86/intreadwrite.h
index 635096e569..4061d19231 100644
--- a/libavutil/x86/intreadwrite.h
+++ b/libavutil/x86/intreadwrite.h
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2010 Alexander Strange <astrange@ithinksw.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavutil/x86/timer.h b/libavutil/x86/timer.h
index 7f51816c5a..62a111fdd3 100644
--- a/libavutil/x86/timer.h
+++ b/libavutil/x86/timer.h
@@ -1,20 +1,20 @@
/*
* copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libavcodec/x86/x86inc.asm b/libavutil/x86/x86inc.asm
index c84d5566a2..c84d5566a2 100644
--- a/libavcodec/x86/x86inc.asm
+++ b/libavutil/x86/x86inc.asm
diff --git a/libavcodec/x86/x86util.asm b/libavutil/x86/x86util.asm
index 141e96000c..c486b06425 100644
--- a/libavcodec/x86/x86util.asm
+++ b/libavutil/x86/x86util.asm
@@ -6,20 +6,20 @@
;* Authors: Loren Merritt <lorenm@u.washington.edu>
;* Holger Lubitz <holger@lubitz.org>
;*
-;* This file is part of Libav.
+;* This file is part of FFmpeg.
;*
-;* Libav is free software; you can redistribute it and/or
+;* FFmpeg 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.
;*
-;* Libav is distributed in the hope that it will be useful,
+;* FFmpeg 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
;* Lesser General Public License for more details.
;*
;* You should have received a copy of the GNU Lesser General Public
-;* License along with Libav; if not, write to the Free Software
+;* License along with FFmpeg; if not, write to the Free Software
;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
;******************************************************************************
@@ -497,10 +497,10 @@
%macro STORE_DIFFx2 8 ; add1, add2, reg1, reg2, zero, shift, source, stride
movh %3, [%7]
movh %4, [%7+%8]
- punpcklbw %3, %5
- punpcklbw %4, %5
psraw %1, %6
psraw %2, %6
+ punpcklbw %3, %5
+ punpcklbw %4, %5
paddw %3, %1
paddw %4, %2
packuswb %3, %5
@@ -528,7 +528,60 @@
%endif
%endmacro
+%macro SPLATD 2-3 0
+%if mmsize == 16
+ pshufd %1, %2, (%3)*0x55
+%else
+ pshufw %1, %2, (%3)*0x11 + ((%3)+1)*0x44
+%endif
+%endmacro
+
+%macro SPLATD_MMX 1
+ punpckldq %1, %1
+%endmacro
+
+%macro SPLATD_SSE 1
+ shufps %1, %1, 0
+%endmacro
+
+%macro SPLATD_SSE2 1
+ pshufd %1, %1, 0
+%endmacro
+
%macro CLIPW 3 ;(dst, min, max)
pmaxsw %1, %2
pminsw %1, %3
%endmacro
+
+%macro PMINSD_MMX 3 ; dst, src, tmp
+ mova %3, %2
+ pcmpgtd %3, %1
+ pxor %1, %2
+ pand %1, %3
+ pxor %1, %2
+%endmacro
+
+%macro PMAXSD_MMX 3 ; dst, src, tmp
+ mova %3, %1
+ pcmpgtd %3, %2
+ pand %1, %3
+ pandn %3, %2
+ por %1, %3
+%endmacro
+
+%macro CLIPD_MMX 3-4 ; src/dst, min, max, tmp
+ PMINSD_MMX %1, %3, %4
+ PMAXSD_MMX %1, %2, %4
+%endmacro
+
+%macro CLIPD_SSE2 3-4 ; src/dst, min (float), max (float), unused
+ cvtdq2ps %1, %1
+ minps %1, %3
+ maxps %1, %2
+ cvtps2dq %1, %1
+%endmacro
+
+%macro CLIPD_SSE41 3-4 ; src/dst, min, max, unused
+ pminsd %1, %3
+ pmaxsd %1, %2
+%endmacro
diff --git a/libavutil/x86_cpu.h b/libavutil/x86_cpu.h
index f84eba67f5..c3341c232d 100644
--- a/libavutil/x86_cpu.h
+++ b/libavutil/x86_cpu.h
@@ -1,20 +1,20 @@
/*
* copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libpostproc/Makefile b/libpostproc/Makefile
index 11de3d3235..02257420e9 100644
--- a/libpostproc/Makefile
+++ b/libpostproc/Makefile
@@ -1,3 +1,5 @@
+include $(SUBDIR)../config.mak
+
NAME = postproc
FFLIBS = avutil
diff --git a/libpostproc/postprocess.c b/libpostproc/postprocess.c
index dd50daf21e..944d581a0f 100644
--- a/libpostproc/postprocess.c
+++ b/libpostproc/postprocess.c
@@ -3,20 +3,20 @@
*
* AltiVec optimizations (C) 2004 Romain Dolbeau <romain@dolbeau.org>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or modify
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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 Libav; if not, write to the Free Software
+ * along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -95,13 +95,13 @@ unsigned postproc_version(void)
const char *postproc_configuration(void)
{
- return LIBAV_CONFIGURATION;
+ return FFMPEG_CONFIGURATION;
}
const char *postproc_license(void)
{
#define LICENSE_PREFIX "libpostproc license: "
- return LICENSE_PREFIX LIBAV_LICENSE + sizeof(LICENSE_PREFIX) - 1;
+ return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1;
}
#if HAVE_ALTIVEC_H
@@ -246,7 +246,6 @@ static inline int isVertDC_C(uint8_t src[], int stride, PPContext *c)
static inline int isHorizMinMaxOk_C(uint8_t src[], int stride, int QP)
{
int i;
-#if 1
for(i=0; i<2; i++){
if((unsigned)(src[0] - src[5] + 2*QP) > 4*QP) return 0;
src += stride;
@@ -257,19 +256,11 @@ static inline int isHorizMinMaxOk_C(uint8_t src[], int stride, int QP)
if((unsigned)(src[6] - src[3] + 2*QP) > 4*QP) return 0;
src += stride;
}
-#else
- for(i=0; i<8; i++){
- if((unsigned)(src[0] - src[7] + 2*QP) > 4*QP) return 0;
- src += stride;
- }
-#endif
return 1;
}
static inline int isVertMinMaxOk_C(uint8_t src[], int stride, int QP)
{
-#if 1
-#if 1
int x;
src+= stride*4;
for(x=0; x<BLOCK_SIZE; x+=4){
@@ -278,30 +269,7 @@ static inline int isVertMinMaxOk_C(uint8_t src[], int stride, int QP)
if((unsigned)(src[2+x + 4*stride] - src[2+x + 1*stride] + 2*QP) > 4*QP) return 0;
if((unsigned)(src[3+x + 6*stride] - src[3+x + 3*stride] + 2*QP) > 4*QP) return 0;
}
-#else
- int x;
- src+= stride*3;
- for(x=0; x<BLOCK_SIZE; x++){
- if((unsigned)(src[x + stride] - src[x + (stride<<3)] + 2*QP) > 4*QP) return 0;
- }
-#endif
- return 1;
-#else
- int x;
- src+= stride*4;
- for(x=0; x<BLOCK_SIZE; x++){
- int min=255;
- int max=0;
- int y;
- for(y=0; y<8; y++){
- int v= src[x + y*stride];
- if(v>max) max=v;
- if(v<min) min=v;
- }
- if(max-min > 2*QP) return 0;
- }
return 1;
-#endif
}
static inline int horizClassify_C(uint8_t src[], int stride, PPContext *c)
@@ -696,7 +664,11 @@ static inline void postProcess(const uint8_t src[], int srcStride, uint8_t dst[]
/* -pp Command line Help
*/
+#if LIBPOSTPROC_VERSION_INT < (52<<16)
+const char *const pp_help=
+#else
const char pp_help[] =
+#endif
"Available postprocessing filters:\n"
"Filters Options\n"
"short long name short long option Description\n"
@@ -763,7 +735,8 @@ pp_mode *pp_get_mode_by_name_and_quality(const char *name, int quality)
ppMode->maxClippedThreshold= 0.01;
ppMode->error=0;
- av_strlcpy(temp, name, GET_MODE_BUFFER_SIZE);
+ memset(temp, 0, GET_MODE_BUFFER_SIZE);
+ av_strlcpy(temp, name, GET_MODE_BUFFER_SIZE - 1);
av_log(NULL, AV_LOG_DEBUG, "pp: %s\n", name);
@@ -814,12 +787,11 @@ pp_mode *pp_get_mode_by_name_and_quality(const char *name, int quality)
int plen;
int spaceLeft;
- if(p==NULL) p= temp, *p=0; //last filter
- else p--, *p=','; //not last filter
+ p--, *p=',';
plen= strlen(p);
spaceLeft= p - temp + plen;
- if(spaceLeft + newlen >= GET_MODE_BUFFER_SIZE){
+ if(spaceLeft + newlen >= GET_MODE_BUFFER_SIZE - 1){
ppMode->error++;
break;
}
diff --git a/libpostproc/postprocess.h b/libpostproc/postprocess.h
index fe8c9b96ce..0713c47956 100644
--- a/libpostproc/postprocess.h
+++ b/libpostproc/postprocess.h
@@ -1,20 +1,20 @@
/*
* Copyright (C) 2001-2003 Michael Niedermayer (michaelni@gmx.at)
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or modify
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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 Libav; if not, write to the Free Software
+ * along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -29,8 +29,8 @@
#include "libavutil/avutil.h"
-#define LIBPOSTPROC_VERSION_MAJOR 52
-#define LIBPOSTPROC_VERSION_MINOR 0
+#define LIBPOSTPROC_VERSION_MAJOR 51
+#define LIBPOSTPROC_VERSION_MINOR 2
#define LIBPOSTPROC_VERSION_MICRO 0
#define LIBPOSTPROC_VERSION_INT AV_VERSION_INT(LIBPOSTPROC_VERSION_MAJOR, \
@@ -67,7 +67,13 @@ const char *postproc_license(void);
typedef void pp_context;
typedef void pp_mode;
+#if LIBPOSTPROC_VERSION_INT < (52<<16)
+typedef pp_context pp_context_t;
+typedef pp_mode pp_mode_t;
+extern const char *const pp_help; ///< a simple help text
+#else
extern const char pp_help[]; ///< a simple help text
+#endif
void pp_postprocess(const uint8_t * src[3], const int srcStride[3],
uint8_t * dst[3], const int dstStride[3],
diff --git a/libpostproc/postprocess_altivec_template.c b/libpostproc/postprocess_altivec_template.c
index 56d7b1660a..c53ebc0b4a 100644
--- a/libpostproc/postprocess_altivec_template.c
+++ b/libpostproc/postprocess_altivec_template.c
@@ -3,20 +3,20 @@
*
* based on code by Copyright (C) 2001-2003 Michael Niedermayer (michaelni@gmx.at)
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or modify
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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 Libav; if not, write to the Free Software
+ * along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libpostproc/postprocess_internal.h b/libpostproc/postprocess_internal.h
index 331a96b2dd..fd0c7c1374 100644
--- a/libpostproc/postprocess_internal.h
+++ b/libpostproc/postprocess_internal.h
@@ -1,20 +1,20 @@
/*
* Copyright (C) 2001-2002 Michael Niedermayer (michaelni@gmx.at)
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or modify
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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 Libav; if not, write to the Free Software
+ * along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libpostproc/postprocess_template.c b/libpostproc/postprocess_template.c
index 3b6d0f88f9..2d15ee401c 100644
--- a/libpostproc/postprocess_template.c
+++ b/libpostproc/postprocess_template.c
@@ -1,20 +1,20 @@
/*
* Copyright (C) 2001-2002 Michael Niedermayer (michaelni@gmx.at)
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or modify
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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 Libav; if not, write to the Free Software
+ * along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -25,8 +25,6 @@
#include "libavutil/x86_cpu.h"
-#define ALIGN_MASK "$-8"
-
#undef REAL_PAVGB
#undef PAVGB
#undef PMINUB
@@ -767,11 +765,10 @@ static inline void RENAME(doVertDefFilter)(uint8_t src[], int stride, PPContext
}
*/
#elif HAVE_MMX
+ DECLARE_ALIGNED(8, uint64_t, tmp)[4]; // make space for 4 8-byte vars
src+= stride*4;
__asm__ volatile(
"pxor %%mm7, %%mm7 \n\t"
- "lea -40(%%"REG_SP"), %%"REG_c" \n\t" // make space for 4 8-byte vars
- "and "ALIGN_MASK", %%"REG_c" \n\t" // align
// 0 1 2 3 4 5 6 7
// %0 %0+%1 %0+2%1 eax+2%1 %0+4%1 eax+4%1 edx+%1 edx+2%1
// %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1
@@ -813,8 +810,8 @@ static inline void RENAME(doVertDefFilter)(uint8_t src[], int stride, PPContext
"psubw %%mm3, %%mm1 \n\t" // 2H0 - 5H1 + 5H2 - H3
"psubw %%mm2, %%mm0 \n\t" // 2L0 - 5L1 + 5L2 - 2L3
"psubw %%mm3, %%mm1 \n\t" // 2H0 - 5H1 + 5H2 - 2H3
- "movq %%mm0, (%%"REG_c") \n\t" // 2L0 - 5L1 + 5L2 - 2L3
- "movq %%mm1, 8(%%"REG_c") \n\t" // 2H0 - 5H1 + 5H2 - 2H3
+ "movq %%mm0, (%3) \n\t" // 2L0 - 5L1 + 5L2 - 2L3
+ "movq %%mm1, 8(%3) \n\t" // 2H0 - 5H1 + 5H2 - 2H3
"movq (%%"REG_a", %1, 2), %%mm0 \n\t"
"movq %%mm0, %%mm1 \n\t"
@@ -823,8 +820,8 @@ static inline void RENAME(doVertDefFilter)(uint8_t src[], int stride, PPContext
"psubw %%mm0, %%mm2 \n\t" // L3 - L4
"psubw %%mm1, %%mm3 \n\t" // H3 - H4
- "movq %%mm2, 16(%%"REG_c") \n\t" // L3 - L4
- "movq %%mm3, 24(%%"REG_c") \n\t" // H3 - H4
+ "movq %%mm2, 16(%3) \n\t" // L3 - L4
+ "movq %%mm3, 24(%3) \n\t" // H3 - H4
"paddw %%mm4, %%mm4 \n\t" // 2L2
"paddw %%mm5, %%mm5 \n\t" // 2H2
"psubw %%mm2, %%mm4 \n\t" // 2L2 - L3 + L4
@@ -872,8 +869,8 @@ static inline void RENAME(doVertDefFilter)(uint8_t src[], int stride, PPContext
"psubw %%mm2, %%mm0 \n\t" // 2L4 - 5L5 + 5L6 - 2L7
"psubw %%mm3, %%mm1 \n\t" // 2H4 - 5H5 + 5H6 - 2H7
- "movq (%%"REG_c"), %%mm2 \n\t" // 2L0 - 5L1 + 5L2 - 2L3
- "movq 8(%%"REG_c"), %%mm3 \n\t" // 2H0 - 5H1 + 5H2 - 2H3
+ "movq (%3), %%mm2 \n\t" // 2L0 - 5L1 + 5L2 - 2L3
+ "movq 8(%3), %%mm3 \n\t" // 2H0 - 5H1 + 5H2 - 2H3
#if HAVE_MMX2
"movq %%mm7, %%mm6 \n\t" // 0
@@ -951,8 +948,8 @@ static inline void RENAME(doVertDefFilter)(uint8_t src[], int stride, PPContext
"psrlw $6, %%mm4 \n\t"
"psrlw $6, %%mm5 \n\t"
- "movq 16(%%"REG_c"), %%mm0 \n\t" // L3 - L4
- "movq 24(%%"REG_c"), %%mm1 \n\t" // H3 - H4
+ "movq 16(%3), %%mm0 \n\t" // L3 - L4
+ "movq 24(%3), %%mm1 \n\t" // H3 - H4
"pxor %%mm2, %%mm2 \n\t"
"pxor %%mm3, %%mm3 \n\t"
@@ -995,8 +992,8 @@ static inline void RENAME(doVertDefFilter)(uint8_t src[], int stride, PPContext
"movq %%mm0, (%0, %1) \n\t"
: "+r" (src)
- : "r" ((x86_reg)stride), "m" (c->pQPb)
- : "%"REG_a, "%"REG_c
+ : "r" ((x86_reg)stride), "m" (c->pQPb), "r"(tmp)
+ : "%"REG_a
);
#else //HAVE_MMX2 || HAVE_AMD3DNOW
const int l1= stride;
@@ -1044,6 +1041,7 @@ static inline void RENAME(doVertDefFilter)(uint8_t src[], int stride, PPContext
static inline void RENAME(dering)(uint8_t src[], int stride, PPContext *c)
{
#if HAVE_MMX2 || HAVE_AMD3DNOW
+ DECLARE_ALIGNED(8, uint64_t, tmp)[3];
__asm__ volatile(
"pxor %%mm6, %%mm6 \n\t"
"pcmpeqb %%mm7, %%mm7 \n\t"
@@ -1134,16 +1132,16 @@ FIND_MIN_MAX((%0, %1, 8))
#endif
"movq %%mm6, %%mm0 \n\t" // max
"psubb %%mm7, %%mm6 \n\t" // max - min
- "movd %%mm6, %%ecx \n\t"
- "cmpb "MANGLE(deringThreshold)", %%cl \n\t"
+ "push %4 \n\t"
+ "movd %%mm6, %k4 \n\t"
+ "cmpb "MANGLE(deringThreshold)", %b4 \n\t"
+ "pop %4 \n\t"
" jb 1f \n\t"
- "lea -24(%%"REG_SP"), %%"REG_c" \n\t"
- "and "ALIGN_MASK", %%"REG_c" \n\t"
PAVGB(%%mm0, %%mm7) // a=(max + min)/2
"punpcklbw %%mm7, %%mm7 \n\t"
"punpcklbw %%mm7, %%mm7 \n\t"
"punpcklbw %%mm7, %%mm7 \n\t"
- "movq %%mm7, (%%"REG_c") \n\t"
+ "movq %%mm7, (%4) \n\t"
"movq (%0), %%mm0 \n\t" // L10
"movq %%mm0, %%mm1 \n\t" // L10
@@ -1207,8 +1205,8 @@ FIND_MIN_MAX((%0, %1, 8))
PAVGB(t0, lx) /* (src[-1] + src[+1])/2 */\
PAVGB(sx, lx) /* (src[-1] + 2src[0] + src[+1])/4 */\
PAVGB(lx, pplx) \
- "movq " #lx ", 8(%%"REG_c") \n\t"\
- "movq (%%"REG_c"), " #lx " \n\t"\
+ "movq " #lx ", 8(%4) \n\t"\
+ "movq (%4), " #lx " \n\t"\
"psubusb " #lx ", " #t1 " \n\t"\
"psubusb " #lx ", " #t0 " \n\t"\
"psubusb " #lx ", " #sx " \n\t"\
@@ -1235,7 +1233,7 @@ FIND_MIN_MAX((%0, %1, 8))
"pandn " #dst ", " #ppsx " \n\t"\
"por " #pplx ", " #ppsx " \n\t"\
"movq " #ppsx ", " #dst " \n\t"\
- "movq 8(%%"REG_c"), " #lx " \n\t"
+ "movq 8(%4), " #lx " \n\t"
#define DERING_CORE(dst,src,ppsx,psx,sx,pplx,plx,lx,t0,t1) \
REAL_DERING_CORE(dst,src,ppsx,psx,sx,pplx,plx,lx,t0,t1)
@@ -1265,8 +1263,8 @@ DERING_CORE((%%REGd, %1, 2),(%0, %1, 8) ,%%mm0,%%mm2,%%mm4,%%mm1,%%mm3,%%mm5,
DERING_CORE((%0, %1, 8) ,(%%REGd, %1, 4),%%mm2,%%mm4,%%mm0,%%mm3,%%mm5,%%mm1,%%mm6,%%mm7)
"1: \n\t"
- : : "r" (src), "r" ((x86_reg)stride), "m" (c->pQPb), "m"(c->pQPb2)
- : "%"REG_a, "%"REG_d, "%"REG_c
+ : : "r" (src), "r" ((x86_reg)stride), "m" (c->pQPb), "m"(c->pQPb2), "q"(tmp)
+ : "%"REG_a, "%"REG_d
);
#else //HAVE_MMX2 || HAVE_AMD3DNOW
int y;
@@ -2762,10 +2760,9 @@ static av_always_inline void RENAME(do_a_deblock)(uint8_t *src, int step, int st
if(eq_mask != -1LL){
uint8_t *temp_src= src;
+ DECLARE_ALIGNED(8, uint64_t, tmp)[4]; // make space for 4 8-byte vars
__asm__ volatile(
"pxor %%mm7, %%mm7 \n\t"
- "lea -40(%%"REG_SP"), %%"REG_c" \n\t" // make space for 4 8-byte vars
- "and "ALIGN_MASK", %%"REG_c" \n\t" // align
// 0 1 2 3 4 5 6 7 8 9
// %0 eax eax+%1 eax+2%1 %0+4%1 ecx ecx+%1 ecx+2%1 %1+8%1 ecx+4%1
@@ -2806,8 +2803,8 @@ static av_always_inline void RENAME(do_a_deblock)(uint8_t *src, int step, int st
"psubw %%mm3, %%mm1 \n\t" // 2H0 - 5H1 + 5H2 - H3
"psubw %%mm2, %%mm0 \n\t" // 2L0 - 5L1 + 5L2 - 2L3
"psubw %%mm3, %%mm1 \n\t" // 2H0 - 5H1 + 5H2 - 2H3
- "movq %%mm0, (%%"REG_c") \n\t" // 2L0 - 5L1 + 5L2 - 2L3
- "movq %%mm1, 8(%%"REG_c") \n\t" // 2H0 - 5H1 + 5H2 - 2H3
+ "movq %%mm0, (%4) \n\t" // 2L0 - 5L1 + 5L2 - 2L3
+ "movq %%mm1, 8(%4) \n\t" // 2H0 - 5H1 + 5H2 - 2H3
"movq (%%"REG_a", %1, 2), %%mm0 \n\t"
"movq %%mm0, %%mm1 \n\t"
@@ -2816,8 +2813,8 @@ static av_always_inline void RENAME(do_a_deblock)(uint8_t *src, int step, int st
"psubw %%mm0, %%mm2 \n\t" // L3 - L4
"psubw %%mm1, %%mm3 \n\t" // H3 - H4
- "movq %%mm2, 16(%%"REG_c") \n\t" // L3 - L4
- "movq %%mm3, 24(%%"REG_c") \n\t" // H3 - H4
+ "movq %%mm2, 16(%4) \n\t" // L3 - L4
+ "movq %%mm3, 24(%4) \n\t" // H3 - H4
"paddw %%mm4, %%mm4 \n\t" // 2L2
"paddw %%mm5, %%mm5 \n\t" // 2H2
"psubw %%mm2, %%mm4 \n\t" // 2L2 - L3 + L4
@@ -2865,8 +2862,8 @@ static av_always_inline void RENAME(do_a_deblock)(uint8_t *src, int step, int st
"psubw %%mm2, %%mm0 \n\t" // 2L4 - 5L5 + 5L6 - 2L7
"psubw %%mm3, %%mm1 \n\t" // 2H4 - 5H5 + 5H6 - 2H7
- "movq (%%"REG_c"), %%mm2 \n\t" // 2L0 - 5L1 + 5L2 - 2L3
- "movq 8(%%"REG_c"), %%mm3 \n\t" // 2H0 - 5H1 + 5H2 - 2H3
+ "movq (%4), %%mm2 \n\t" // 2L0 - 5L1 + 5L2 - 2L3
+ "movq 8(%4), %%mm3 \n\t" // 2H0 - 5H1 + 5H2 - 2H3
#if HAVE_MMX2
"movq %%mm7, %%mm6 \n\t" // 0
@@ -2944,8 +2941,8 @@ static av_always_inline void RENAME(do_a_deblock)(uint8_t *src, int step, int st
"psrlw $6, %%mm4 \n\t"
"psrlw $6, %%mm5 \n\t"
- "movq 16(%%"REG_c"), %%mm0 \n\t" // L3 - L4
- "movq 24(%%"REG_c"), %%mm1 \n\t" // H3 - H4
+ "movq 16(%4), %%mm0 \n\t" // L3 - L4
+ "movq 24(%4), %%mm1 \n\t" // H3 - H4
"pxor %%mm2, %%mm2 \n\t"
"pxor %%mm3, %%mm3 \n\t"
@@ -2990,8 +2987,8 @@ static av_always_inline void RENAME(do_a_deblock)(uint8_t *src, int step, int st
"movq %%mm0, (%0, %1) \n\t"
: "+r" (temp_src)
- : "r" ((x86_reg)step), "m" (c->pQPb), "m"(eq_mask)
- : "%"REG_a, "%"REG_c
+ : "r" ((x86_reg)step), "m" (c->pQPb), "m"(eq_mask), "r"(tmp)
+ : "%"REG_a
);
}
/*if(step==16){
diff --git a/libswresample/Makefile b/libswresample/Makefile
new file mode 100644
index 0000000000..7435162793
--- /dev/null
+++ b/libswresample/Makefile
@@ -0,0 +1,12 @@
+include $(SUBDIR)../config.mak
+
+NAME = swresample
+FFLIBS = avutil
+
+HEADERS = swresample.h
+
+OBJS = swresample.o audioconvert.o resample2.o rematrix.o
+
+TESTPROGS = swresample_test
+
+include $(SRC_PATH)/subdir.mak
diff --git a/libswresample/audioconvert.c b/libswresample/audioconvert.c
new file mode 100644
index 0000000000..a1fa3eb10c
--- /dev/null
+++ b/libswresample/audioconvert.c
@@ -0,0 +1,113 @@
+/*
+ * audio conversion
+ * Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * audio conversion
+ * @author Michael Niedermayer <michaelni@gmx.at>
+ */
+
+#include "libavutil/avstring.h"
+#include "libavutil/avassert.h"
+#include "libavutil/libm.h"
+#include "libavutil/samplefmt.h"
+#include "audioconvert.h"
+
+
+struct AVAudioConvert {
+ int channels;
+ int fmt_pair;
+};
+
+AVAudioConvert *swr_audio_convert_alloc(enum AVSampleFormat out_fmt,
+ enum AVSampleFormat in_fmt,
+ int channels, int flags)
+{
+ AVAudioConvert *ctx;
+ ctx = av_malloc(sizeof(AVAudioConvert));
+ if (!ctx)
+ return NULL;
+ ctx->channels = channels;
+ ctx->fmt_pair = out_fmt + AV_SAMPLE_FMT_NB*in_fmt;
+ return ctx;
+}
+
+void swr_audio_convert_free(AVAudioConvert **ctx)
+{
+ av_freep(ctx);
+}
+
+int swr_audio_convert(AVAudioConvert *ctx, AudioData *out, AudioData*in, int len)
+{
+ int ch;
+
+ av_assert0(ctx->channels == out->ch_count);
+
+ //FIXME optimize common cases
+
+ for(ch=0; ch<ctx->channels; ch++){
+ const int is= (in ->planar ? 1 : in->ch_count) * in->bps;
+ const int os= (out->planar ? 1 :out->ch_count) *out->bps;
+ const uint8_t *pi= in ->ch[ch];
+ uint8_t *po= out->ch[ch];
+ uint8_t *end= po + os*len;
+ if(!po)
+ continue;
+
+#define CONV(ofmt, otype, ifmt, expr)\
+if(ctx->fmt_pair == ofmt + AV_SAMPLE_FMT_NB*ifmt){\
+ do{\
+ *(otype*)po = expr; pi += is; po += os;\
+ }while(po < end);\
+}
+
+//FIXME put things below under ifdefs so we do not waste space for cases no codec will need
+//FIXME rounding ?
+
+ CONV(AV_SAMPLE_FMT_U8 , uint8_t, AV_SAMPLE_FMT_U8 , *(const uint8_t*)pi)
+ else CONV(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_U8 , (*(const uint8_t*)pi - 0x80)<<8)
+ else CONV(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_U8 , (*(const uint8_t*)pi - 0x80)<<24)
+ else CONV(AV_SAMPLE_FMT_FLT, float , AV_SAMPLE_FMT_U8 , (*(const uint8_t*)pi - 0x80)*(1.0 / (1<<7)))
+ else CONV(AV_SAMPLE_FMT_DBL, double , AV_SAMPLE_FMT_U8 , (*(const uint8_t*)pi - 0x80)*(1.0 / (1<<7)))
+ else CONV(AV_SAMPLE_FMT_U8 , uint8_t, AV_SAMPLE_FMT_S16, (*(const int16_t*)pi>>8) + 0x80)
+ else CONV(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_S16, *(const int16_t*)pi)
+ else CONV(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_S16, *(const int16_t*)pi<<16)
+ else CONV(AV_SAMPLE_FMT_FLT, float , AV_SAMPLE_FMT_S16, *(const int16_t*)pi*(1.0 / (1<<15)))
+ else CONV(AV_SAMPLE_FMT_DBL, double , AV_SAMPLE_FMT_S16, *(const int16_t*)pi*(1.0 / (1<<15)))
+ else CONV(AV_SAMPLE_FMT_U8 , uint8_t, AV_SAMPLE_FMT_S32, (*(const int32_t*)pi>>24) + 0x80)
+ else CONV(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_S32, *(const int32_t*)pi>>16)
+ else CONV(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_S32, *(const int32_t*)pi)
+ else CONV(AV_SAMPLE_FMT_FLT, float , AV_SAMPLE_FMT_S32, *(const int32_t*)pi*(1.0 / (1U<<31)))
+ else CONV(AV_SAMPLE_FMT_DBL, double , AV_SAMPLE_FMT_S32, *(const int32_t*)pi*(1.0 / (1U<<31)))
+ else CONV(AV_SAMPLE_FMT_U8 , uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8( lrintf(*(const float*)pi * (1<<7)) + 0x80))
+ else CONV(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16( lrintf(*(const float*)pi * (1<<15))))
+ else CONV(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(const float*)pi * (1U<<31))))
+ else CONV(AV_SAMPLE_FMT_FLT, float , AV_SAMPLE_FMT_FLT, *(const float*)pi)
+ else CONV(AV_SAMPLE_FMT_DBL, double , AV_SAMPLE_FMT_FLT, *(const float*)pi)
+ else CONV(AV_SAMPLE_FMT_U8 , uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8( lrint(*(const double*)pi * (1<<7)) + 0x80))
+ else CONV(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16( lrint(*(const double*)pi * (1<<15))))
+ else CONV(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(const double*)pi * (1U<<31))))
+ else CONV(AV_SAMPLE_FMT_FLT, float , AV_SAMPLE_FMT_DBL, *(const double*)pi)
+ else CONV(AV_SAMPLE_FMT_DBL, double , AV_SAMPLE_FMT_DBL, *(const double*)pi)
+ else return -1;
+ }
+ return 0;
+}
diff --git a/libswresample/audioconvert.h b/libswresample/audioconvert.h
new file mode 100644
index 0000000000..e5fd4dfd80
--- /dev/null
+++ b/libswresample/audioconvert.h
@@ -0,0 +1,65 @@
+/*
+ * audio conversion
+ * Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
+ * Copyright (c) 2008 Peter Ross
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef SWR_AUDIOCONVERT_H
+#define SWR_AUDIOCONVERT_H
+
+/**
+ * @file
+ * Audio format conversion routines
+ */
+
+
+#include "swresample_internal.h"
+#include "libavutil/cpu.h"
+#include "libavutil/audioconvert.h"
+
+struct AVAudioConvert;
+typedef struct AVAudioConvert AVAudioConvert;
+
+/**
+ * Create an audio sample format converter context
+ * @param out_fmt Output sample format
+ * @param in_fmt Input sample format
+ * @param channels Number of channels
+ * @param flags See AV_CPU_FLAG_xx
+ * @return NULL on error
+ */
+AVAudioConvert *swr_audio_convert_alloc(enum AVSampleFormat out_fmt,
+ enum AVSampleFormat in_fmt,
+ int channels, int flags);
+
+/**
+ * Free audio sample format converter context.
+ * and set the pointer to NULL
+ */
+void swr_audio_convert_free(AVAudioConvert **ctx);
+
+/**
+ * Convert between audio sample formats
+ * @param[in] out array of output buffers for each channel. set to NULL to ignore processing of the given channel.
+ * @param[in] in array of input buffers for each channel
+ * @param len length of audio frame size (measured in samples)
+ */
+int swr_audio_convert(AVAudioConvert *ctx, AudioData *out, AudioData *in, int len);
+
+#endif /* AVCODEC_AUDIOCONVERT_H */
diff --git a/libswresample/libswresample.v b/libswresample/libswresample.v
new file mode 100644
index 0000000000..af2181179d
--- /dev/null
+++ b/libswresample/libswresample.v
@@ -0,0 +1,4 @@
+LIBSWRESAMPLE_$MAJOR {
+ global: swr_*; ff_*;
+ local: *;
+};
diff --git a/libswresample/rematrix.c b/libswresample/rematrix.c
new file mode 100644
index 0000000000..4a3ada62f4
--- /dev/null
+++ b/libswresample/rematrix.c
@@ -0,0 +1,280 @@
+/*
+ * Copyright (C) 2011 Michael Niedermayer (michaelni@gmx.at)
+ *
+ * This file is part of libswresample
+ *
+ * libswresample 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.
+ *
+ * libswresample 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with libswresample; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "swresample_internal.h"
+#include "libavutil/audioconvert.h"
+#include "libavutil/avassert.h"
+
+#define ONE (1.0)
+#define R(x) x
+#define SAMPLE float
+#define RENAME(x) x ## _float
+#include "rematrix_template.c"
+#undef SAMPLE
+#undef RENAME
+#undef R
+#undef ONE
+
+#define ONE (-32768)
+#define R(x) (((x) + 16384)>>15)
+#define SAMPLE int16_t
+#define RENAME(x) x ## _s16
+#include "rematrix_template.c"
+
+
+#define FRONT_LEFT 0
+#define FRONT_RIGHT 1
+#define FRONT_CENTER 2
+#define LOW_FREQUENCY 3
+#define BACK_LEFT 4
+#define BACK_RIGHT 5
+#define FRONT_LEFT_OF_CENTER 6
+#define FRONT_RIGHT_OF_CENTER 7
+#define BACK_CENTER 8
+#define SIDE_LEFT 9
+#define SIDE_RIGHT 10
+#define TOP_CENTER 11
+#define TOP_FRONT_LEFT 12
+#define TOP_FRONT_CENTER 13
+#define TOP_FRONT_RIGHT 14
+#define TOP_BACK_LEFT 15
+#define TOP_BACK_CENTER 16
+#define TOP_BACK_RIGHT 17
+
+static int even(int64_t layout){
+ if(!layout) return 1;
+ if(layout&(layout-1)) return 1;
+ return 0;
+}
+
+static int sane_layout(int64_t layout){
+ if(!(layout & AV_CH_LAYOUT_SURROUND)) // at least 1 front speaker
+ return 0;
+ if(!even(layout & (AV_CH_FRONT_LEFT | AV_CH_FRONT_RIGHT))) // no asymetric front
+ return 0;
+ if(!even(layout & (AV_CH_SIDE_LEFT | AV_CH_SIDE_RIGHT))) // no asymetric side
+ return 0;
+ if(!even(layout & (AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT)))
+ return 0;
+ if(!even(layout & (AV_CH_FRONT_LEFT_OF_CENTER | AV_CH_FRONT_RIGHT_OF_CENTER)))
+ return 0;
+ if(av_get_channel_layout_nb_channels(layout) >= SWR_CH_MAX)
+ return 0;
+
+ return 1;
+}
+
+int swr_rematrix_init(SwrContext *s){
+ int i, j, out_i;
+ double matrix[64][64]={{0}};
+ int64_t unaccounted= s->in_ch_layout & ~s->out_ch_layout;
+ double maxcoef=0;
+
+ for(i=0; i<64; i++){
+ if(s->in_ch_layout & s->out_ch_layout & (1LL<<i))
+ matrix[i][i]= 1.0;
+ }
+
+ if(!sane_layout(s->in_ch_layout)){
+ av_log(s, AV_LOG_ERROR, "Input channel layout isnt supported\n");
+ return AVERROR(EINVAL);
+ }
+ if(!sane_layout(s->out_ch_layout)){
+ av_log(s, AV_LOG_ERROR, "Output channel layout isnt supported\n");
+ return AVERROR(EINVAL);
+ }
+
+//FIXME implement dolby surround
+//FIXME implement full ac3
+
+
+ if(unaccounted & AV_CH_FRONT_CENTER){
+ if((s->out_ch_layout & AV_CH_LAYOUT_STEREO) == AV_CH_LAYOUT_STEREO){
+ matrix[ FRONT_LEFT][FRONT_CENTER]+= M_SQRT1_2;
+ matrix[FRONT_RIGHT][FRONT_CENTER]+= M_SQRT1_2;
+ }else
+ av_assert0(0);
+ }
+ if(unaccounted & AV_CH_LAYOUT_STEREO){
+ if(s->out_ch_layout & AV_CH_FRONT_CENTER){
+ matrix[FRONT_CENTER][ FRONT_LEFT]+= M_SQRT1_2;
+ matrix[FRONT_CENTER][FRONT_RIGHT]+= M_SQRT1_2;
+ if(s->in_ch_layout & AV_CH_FRONT_CENTER)
+ matrix[FRONT_CENTER][ FRONT_CENTER] = s->clev*sqrt(2);
+ }else
+ av_assert0(0);
+ }
+
+ if(unaccounted & AV_CH_BACK_CENTER){
+ if(s->out_ch_layout & AV_CH_BACK_LEFT){
+ matrix[ BACK_LEFT][BACK_CENTER]+= M_SQRT1_2;
+ matrix[BACK_RIGHT][BACK_CENTER]+= M_SQRT1_2;
+ }else if(s->out_ch_layout & AV_CH_SIDE_LEFT){
+ matrix[ SIDE_LEFT][BACK_CENTER]+= M_SQRT1_2;
+ matrix[SIDE_RIGHT][BACK_CENTER]+= M_SQRT1_2;
+ }else if(s->out_ch_layout & AV_CH_FRONT_LEFT){
+ matrix[ FRONT_LEFT][BACK_CENTER]+= s->slev*M_SQRT1_2;
+ matrix[FRONT_RIGHT][BACK_CENTER]+= s->slev*M_SQRT1_2;
+ }else if(s->out_ch_layout & AV_CH_FRONT_CENTER){
+ matrix[ FRONT_CENTER][BACK_CENTER]+= s->slev*M_SQRT1_2;
+ }else
+ av_assert0(0);
+ }
+ if(unaccounted & AV_CH_BACK_LEFT){
+ if(s->out_ch_layout & AV_CH_BACK_CENTER){
+ matrix[BACK_CENTER][ BACK_LEFT]+= M_SQRT1_2;
+ matrix[BACK_CENTER][BACK_RIGHT]+= M_SQRT1_2;
+ }else if(s->out_ch_layout & AV_CH_SIDE_LEFT){
+ if(s->in_ch_layout & AV_CH_SIDE_LEFT){
+ matrix[ SIDE_LEFT][ BACK_LEFT]+= M_SQRT1_2;
+ matrix[SIDE_RIGHT][BACK_RIGHT]+= M_SQRT1_2;
+ }else{
+ matrix[ SIDE_LEFT][ BACK_LEFT]+= 1.0;
+ matrix[SIDE_RIGHT][BACK_RIGHT]+= 1.0;
+ }
+ }else if(s->out_ch_layout & AV_CH_FRONT_LEFT){
+ matrix[ FRONT_LEFT][ BACK_LEFT]+= s->slev;
+ matrix[FRONT_RIGHT][BACK_RIGHT]+= s->slev;
+ }else if(s->out_ch_layout & AV_CH_FRONT_CENTER){
+ matrix[ FRONT_CENTER][BACK_LEFT ]+= s->slev*M_SQRT1_2;
+ matrix[ FRONT_CENTER][BACK_RIGHT]+= s->slev*M_SQRT1_2;
+ }else
+ av_assert0(0);
+ }
+
+ if(unaccounted & AV_CH_SIDE_LEFT){
+ if(s->out_ch_layout & AV_CH_BACK_LEFT){
+ matrix[ BACK_LEFT][ SIDE_LEFT]+= 1.0;
+ matrix[BACK_RIGHT][SIDE_RIGHT]+= 1.0;
+ }else if(s->out_ch_layout & AV_CH_BACK_CENTER){
+ matrix[BACK_CENTER][ SIDE_LEFT]+= M_SQRT1_2;
+ matrix[BACK_CENTER][SIDE_RIGHT]+= M_SQRT1_2;
+ }else if(s->out_ch_layout & AV_CH_FRONT_LEFT){
+ matrix[ FRONT_LEFT][ SIDE_LEFT]+= s->slev;
+ matrix[FRONT_RIGHT][SIDE_RIGHT]+= s->slev;
+ }else if(s->out_ch_layout & AV_CH_FRONT_CENTER){
+ matrix[ FRONT_CENTER][SIDE_LEFT ]+= s->slev*M_SQRT1_2;
+ matrix[ FRONT_CENTER][SIDE_RIGHT]+= s->slev*M_SQRT1_2;
+ }else
+ av_assert0(0);
+ }
+
+ if(unaccounted & AV_CH_FRONT_LEFT_OF_CENTER){
+ if(s->out_ch_layout & AV_CH_FRONT_LEFT){
+ matrix[ FRONT_LEFT][ FRONT_LEFT_OF_CENTER]+= 1.0;
+ matrix[FRONT_RIGHT][FRONT_RIGHT_OF_CENTER]+= 1.0;
+ }else if(s->out_ch_layout & AV_CH_FRONT_CENTER){
+ matrix[ FRONT_CENTER][ FRONT_LEFT_OF_CENTER]+= M_SQRT1_2;
+ matrix[ FRONT_CENTER][FRONT_RIGHT_OF_CENTER]+= M_SQRT1_2;
+ }else
+ av_assert0(0);
+ }
+
+ //FIXME quantize for integeres
+ for(out_i=i=0; i<64; i++){
+ double sum=0;
+ int in_i=0;
+ int ch_in=0;
+ for(j=0; j<64; j++){
+ s->matrix[out_i][in_i]= matrix[i][j];
+ s->matrix16[out_i][in_i]= lrintf(matrix[i][j] * 32768);
+ if(matrix[i][j]){
+ s->matrix_ch[out_i][++ch_in]= in_i;
+ sum += fabs(matrix[i][j]);
+ }
+ if(s->in_ch_layout & (1ULL<<j))
+ in_i++;
+ }
+ s->matrix_ch[out_i][0]= ch_in;
+ maxcoef= FFMAX(maxcoef, sum);
+ if(s->out_ch_layout & (1ULL<<i))
+ out_i++;
+ }
+ if(( s->out_sample_fmt < AV_SAMPLE_FMT_FLT
+ || s->int_sample_fmt < AV_SAMPLE_FMT_FLT) && maxcoef > 1.0){
+ for(i=0; i<SWR_CH_MAX; i++)
+ for(j=0; j<SWR_CH_MAX; j++){
+ s->matrix[i][j] /= maxcoef;
+ s->matrix16[i][j]= lrintf(s->matrix[i][j] * 32768);
+ }
+ }
+ for(i=0; i<av_get_channel_layout_nb_channels(s->out_ch_layout); i++){
+ for(j=0; j<av_get_channel_layout_nb_channels(s->in_ch_layout); j++){
+ av_log(NULL, AV_LOG_DEBUG, "%f ", s->matrix[i][j]);
+ }
+ av_log(NULL, AV_LOG_DEBUG, "\n");
+ }
+ return 0;
+}
+
+int swr_rematrix(SwrContext *s, AudioData *out, AudioData *in, int len, int mustcopy){
+ int out_i, in_i, i, j;
+
+ av_assert0(out->ch_count == av_get_channel_layout_nb_channels(s->out_ch_layout));
+ av_assert0(in ->ch_count == av_get_channel_layout_nb_channels(s-> in_ch_layout));
+
+ for(out_i=0; out_i<out->ch_count; out_i++){
+ switch(s->matrix_ch[out_i][0]){
+ case 1:
+ in_i= s->matrix_ch[out_i][1];
+ if(mustcopy || s->matrix[out_i][in_i]!=1.0){
+ if(s->int_sample_fmt == AV_SAMPLE_FMT_FLT){
+ copy_float((float *)out->ch[out_i], (const float *)in->ch[in_i], s->matrix [out_i][in_i], len);
+ }else
+ copy_s16 ((int16_t*)out->ch[out_i], (const int16_t*)in->ch[in_i], s->matrix16[out_i][in_i], len);
+ }else{
+ out->ch[out_i]= in->ch[in_i];
+ }
+ break;
+ case 2:
+ if(s->int_sample_fmt == AV_SAMPLE_FMT_FLT){
+ sum2_float((float *)out->ch[out_i], (const float *)in->ch[ s->matrix_ch[out_i][1] ], (const float *)in->ch[ s->matrix_ch[out_i][2] ],
+ s->matrix[out_i][ s->matrix_ch[out_i][1] ], s->matrix[out_i][ s->matrix_ch[out_i][2] ],
+ len);
+ }else{
+ sum2_s16 ((int16_t*)out->ch[out_i], (const int16_t*)in->ch[ s->matrix_ch[out_i][1] ], (const int16_t*)in->ch[ s->matrix_ch[out_i][2] ],
+ s->matrix16[out_i][ s->matrix_ch[out_i][1] ], s->matrix16[out_i][ s->matrix_ch[out_i][2] ],
+ len);
+ }
+ break;
+ default:
+ if(s->int_sample_fmt == AV_SAMPLE_FMT_FLT){
+ for(i=0; i<len; i++){
+ float v=0;
+ for(j=0; j<s->matrix_ch[out_i][0]; j++){
+ in_i= s->matrix_ch[out_i][1+j];
+ v+= ((float*)in->ch[in_i])[i] * s->matrix[out_i][in_i];
+ }
+ ((float*)out->ch[out_i])[i]= v;
+ }
+ }else{
+ for(i=0; i<len; i++){
+ int v=0;
+ for(j=0; j<s->matrix_ch[out_i][0]; j++){
+ in_i= s->matrix_ch[out_i][1+j];
+ v+= ((int16_t*)in->ch[in_i])[i] * s->matrix16[out_i][in_i];
+ }
+ ((int16_t*)out->ch[out_i])[i]= (v + 16384)>>15;
+ }
+ }
+ }
+ }
+ return 0;
+}
diff --git a/libswresample/rematrix_template.c b/libswresample/rematrix_template.c
new file mode 100644
index 0000000000..0c45fc9110
--- /dev/null
+++ b/libswresample/rematrix_template.c
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2011 Michael Niedermayer (michaelni@gmx.at)
+ *
+ * This file is part of libswresample
+ *
+ * libswresample 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.
+ *
+ * libswresample 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with libswresample; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+
+static void RENAME(sum2)(SAMPLE *out, const SAMPLE *in1, const SAMPLE *in2, SAMPLE coeff1, SAMPLE coeff2, int len){
+ int i;
+
+ for(i=0; i<len; i++)
+ out[i] = R(coeff1*in1[i] + coeff2*in2[i]);
+}
+
+static void RENAME(copy)(SAMPLE *out, const SAMPLE *in, SAMPLE coeff, int len){
+ if(coeff == ONE){
+ memcpy(out, in, sizeof(SAMPLE)*len);
+ }else{
+ int i;
+ for(i=0; i<len; i++)
+ out[i] = R(coeff*in[i]);
+ }
+}
+
diff --git a/libswresample/resample2.c b/libswresample/resample2.c
new file mode 100644
index 0000000000..6af2b6c661
--- /dev/null
+++ b/libswresample/resample2.c
@@ -0,0 +1,351 @@
+/*
+ * audio resampling
+ * Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * audio resampling
+ * @author Michael Niedermayer <michaelni@gmx.at>
+ */
+
+#include "libavutil/log.h"
+#include "swresample_internal.h"
+
+#ifndef CONFIG_RESAMPLE_HP
+#define FILTER_SHIFT 15
+
+#define FELEM int16_t
+#define FELEM2 int32_t
+#define FELEML int64_t
+#define FELEM_MAX INT16_MAX
+#define FELEM_MIN INT16_MIN
+#define WINDOW_TYPE 9
+#elif !defined(CONFIG_RESAMPLE_AUDIOPHILE_KIDDY_MODE)
+#define FILTER_SHIFT 30
+
+#define FELEM int32_t
+#define FELEM2 int64_t
+#define FELEML int64_t
+#define FELEM_MAX INT32_MAX
+#define FELEM_MIN INT32_MIN
+#define WINDOW_TYPE 12
+#else
+#define FILTER_SHIFT 0
+
+#define FELEM double
+#define FELEM2 double
+#define FELEML double
+#define WINDOW_TYPE 24
+#endif
+
+
+typedef struct AVResampleContext{
+ const AVClass *av_class;
+ FELEM *filter_bank;
+ int filter_length;
+ int ideal_dst_incr;
+ int dst_incr;
+ int index;
+ int frac;
+ int src_incr;
+ int compensation_distance;
+ int phase_shift;
+ int phase_mask;
+ int linear;
+ double factor;
+}AVResampleContext;
+
+/**
+ * 0th order modified bessel function of the first kind.
+ */
+static double bessel(double x){
+ double v=1;
+ double lastv=0;
+ double t=1;
+ int i;
+ static const double inv[100]={
+ 1.0/( 1* 1), 1.0/( 2* 2), 1.0/( 3* 3), 1.0/( 4* 4), 1.0/( 5* 5), 1.0/( 6* 6), 1.0/( 7* 7), 1.0/( 8* 8), 1.0/( 9* 9), 1.0/(10*10),
+ 1.0/(11*11), 1.0/(12*12), 1.0/(13*13), 1.0/(14*14), 1.0/(15*15), 1.0/(16*16), 1.0/(17*17), 1.0/(18*18), 1.0/(19*19), 1.0/(20*20),
+ 1.0/(21*21), 1.0/(22*22), 1.0/(23*23), 1.0/(24*24), 1.0/(25*25), 1.0/(26*26), 1.0/(27*27), 1.0/(28*28), 1.0/(29*29), 1.0/(30*30),
+ 1.0/(31*31), 1.0/(32*32), 1.0/(33*33), 1.0/(34*34), 1.0/(35*35), 1.0/(36*36), 1.0/(37*37), 1.0/(38*38), 1.0/(39*39), 1.0/(40*40),
+ 1.0/(41*41), 1.0/(42*42), 1.0/(43*43), 1.0/(44*44), 1.0/(45*45), 1.0/(46*46), 1.0/(47*47), 1.0/(48*48), 1.0/(49*49), 1.0/(50*50),
+ 1.0/(51*51), 1.0/(52*52), 1.0/(53*53), 1.0/(54*54), 1.0/(55*55), 1.0/(56*56), 1.0/(57*57), 1.0/(58*58), 1.0/(59*59), 1.0/(60*60),
+ 1.0/(61*61), 1.0/(62*62), 1.0/(63*63), 1.0/(64*64), 1.0/(65*65), 1.0/(66*66), 1.0/(67*67), 1.0/(68*68), 1.0/(69*69), 1.0/(70*70),
+ 1.0/(71*71), 1.0/(72*72), 1.0/(73*73), 1.0/(74*74), 1.0/(75*75), 1.0/(76*76), 1.0/(77*77), 1.0/(78*78), 1.0/(79*79), 1.0/(80*80),
+ 1.0/(81*81), 1.0/(82*82), 1.0/(83*83), 1.0/(84*84), 1.0/(85*85), 1.0/(86*86), 1.0/(87*87), 1.0/(88*88), 1.0/(89*89), 1.0/(90*90),
+ 1.0/(91*91), 1.0/(92*92), 1.0/(93*93), 1.0/(94*94), 1.0/(95*95), 1.0/(96*96), 1.0/(97*97), 1.0/(98*98), 1.0/(99*99), 1.0/(10000)
+ };
+
+ x= x*x/4;
+ for(i=0; v != lastv; i++){
+ lastv=v;
+ t *= x*inv[i];
+ v += t;
+ }
+ return v;
+}
+
+/**
+ * builds a polyphase filterbank.
+ * @param factor resampling factor
+ * @param scale wanted sum of coefficients for each filter
+ * @param type 0->cubic, 1->blackman nuttall windowed sinc, 2..16->kaiser windowed sinc beta=2..16
+ * @return 0 on success, negative on error
+ */
+static int build_filter(FELEM *filter, double factor, int tap_count, int phase_count, int scale, int type){
+ int ph, i;
+ double x, y, w;
+ double *tab = av_malloc(tap_count * sizeof(*tab));
+ const int center= (tap_count-1)/2;
+
+ if (!tab)
+ return AVERROR(ENOMEM);
+
+ /* if upsampling, only need to interpolate, no filter */
+ if (factor > 1.0)
+ factor = 1.0;
+
+ for(ph=0;ph<phase_count;ph++) {
+ double norm = 0;
+ for(i=0;i<tap_count;i++) {
+ x = M_PI * ((double)(i - center) - (double)ph / phase_count) * factor;
+ if (x == 0) y = 1.0;
+ else y = sin(x) / x;
+ switch(type){
+ case 0:{
+ const float d= -0.5; //first order derivative = -0.5
+ x = fabs(((double)(i - center) - (double)ph / phase_count) * factor);
+ if(x<1.0) y= 1 - 3*x*x + 2*x*x*x + d*( -x*x + x*x*x);
+ else y= d*(-4 + 8*x - 5*x*x + x*x*x);
+ break;}
+ case 1:
+ w = 2.0*x / (factor*tap_count) + M_PI;
+ y *= 0.3635819 - 0.4891775 * cos(w) + 0.1365995 * cos(2*w) - 0.0106411 * cos(3*w);
+ break;
+ default:
+ w = 2.0*x / (factor*tap_count*M_PI);
+ y *= bessel(type*sqrt(FFMAX(1-w*w, 0)));
+ break;
+ }
+
+ tab[i] = y;
+ norm += y;
+ }
+
+ /* normalize so that an uniform color remains the same */
+ for(i=0;i<tap_count;i++) {
+#ifdef CONFIG_RESAMPLE_AUDIOPHILE_KIDDY_MODE
+ filter[ph * tap_count + i] = tab[i] / norm;
+#else
+ filter[ph * tap_count + i] = av_clip(lrintf(tab[i] * scale / norm), FELEM_MIN, FELEM_MAX);
+#endif
+ }
+ }
+#if 0
+ {
+#define LEN 1024
+ int j,k;
+ double sine[LEN + tap_count];
+ double filtered[LEN];
+ double maxff=-2, minff=2, maxsf=-2, minsf=2;
+ for(i=0; i<LEN; i++){
+ double ss=0, sf=0, ff=0;
+ for(j=0; j<LEN+tap_count; j++)
+ sine[j]= cos(i*j*M_PI/LEN);
+ for(j=0; j<LEN; j++){
+ double sum=0;
+ ph=0;
+ for(k=0; k<tap_count; k++)
+ sum += filter[ph * tap_count + k] * sine[k+j];
+ filtered[j]= sum / (1<<FILTER_SHIFT);
+ ss+= sine[j + center] * sine[j + center];
+ ff+= filtered[j] * filtered[j];
+ sf+= sine[j + center] * filtered[j];
+ }
+ ss= sqrt(2*ss/LEN);
+ ff= sqrt(2*ff/LEN);
+ sf= 2*sf/LEN;
+ maxff= FFMAX(maxff, ff);
+ minff= FFMIN(minff, ff);
+ maxsf= FFMAX(maxsf, sf);
+ minsf= FFMIN(minsf, sf);
+ if(i%11==0){
+ av_log(NULL, AV_LOG_ERROR, "i:%4d ss:%f ff:%13.6e-%13.6e sf:%13.6e-%13.6e\n", i, ss, maxff, minff, maxsf, minsf);
+ minff=minsf= 2;
+ maxff=maxsf= -2;
+ }
+ }
+ }
+#endif
+
+ av_free(tab);
+ return 0;
+}
+
+AVResampleContext *swr_resample_init(AVResampleContext *c, int out_rate, int in_rate, int filter_size, int phase_shift, int linear, double cutoff){
+ double factor= FFMIN(out_rate * cutoff / in_rate, 1.0);
+ int phase_count= 1<<phase_shift;
+
+ if (!c || c->phase_shift != phase_shift || c->linear!=linear || c->factor != factor
+ || c->filter_length != FFMAX((int)ceil(filter_size/factor), 1)) {
+ c = av_mallocz(sizeof(AVResampleContext));
+ if (!c)
+ return NULL;
+
+ c->phase_shift = phase_shift;
+ c->phase_mask = phase_count - 1;
+ c->linear = linear;
+ c->factor = factor;
+ c->filter_length = FFMAX((int)ceil(filter_size/factor), 1);
+ c->filter_bank = av_mallocz(c->filter_length*(phase_count+1)*sizeof(FELEM));
+ if (!c->filter_bank)
+ goto error;
+ if (build_filter(c->filter_bank, factor, c->filter_length, phase_count, 1<<FILTER_SHIFT, WINDOW_TYPE))
+ goto error;
+ memcpy(&c->filter_bank[c->filter_length*phase_count+1], c->filter_bank, (c->filter_length-1)*sizeof(FELEM));
+ c->filter_bank[c->filter_length*phase_count]= c->filter_bank[c->filter_length - 1];
+ }
+
+ c->compensation_distance= 0;
+ c->src_incr= out_rate;
+ c->ideal_dst_incr= c->dst_incr= in_rate * phase_count;
+ c->index= -phase_count*((c->filter_length-1)/2);
+ c->frac= 0;
+
+ return c;
+error:
+ av_free(c->filter_bank);
+ av_free(c);
+ return NULL;
+}
+
+void swr_resample_free(AVResampleContext **c){
+ if(!*c)
+ return;
+ av_freep(&(*c)->filter_bank);
+ av_freep(c);
+}
+
+void swr_compensate(struct SwrContext *s, int sample_delta, int compensation_distance){
+ AVResampleContext *c= s->resample;
+// sample_delta += (c->ideal_dst_incr - c->dst_incr)*(int64_t)c->compensation_distance / c->ideal_dst_incr;
+ c->compensation_distance= compensation_distance;
+ c->dst_incr = c->ideal_dst_incr - c->ideal_dst_incr * (int64_t)sample_delta / compensation_distance;
+}
+
+int swr_resample(AVResampleContext *c, short *dst, const short *src, int *consumed, int src_size, int dst_size, int update_ctx){
+ int dst_index, i;
+ int index= c->index;
+ int frac= c->frac;
+ int dst_incr_frac= c->dst_incr % c->src_incr;
+ int dst_incr= c->dst_incr / c->src_incr;
+ int compensation_distance= c->compensation_distance;
+
+ if(compensation_distance == 0 && c->filter_length == 1 && c->phase_shift==0){
+ int64_t index2= ((int64_t)index)<<32;
+ int64_t incr= (1LL<<32) * c->dst_incr / c->src_incr;
+ dst_size= FFMIN(dst_size, (src_size-1-index) * (int64_t)c->src_incr / c->dst_incr);
+
+ for(dst_index=0; dst_index < dst_size; dst_index++){
+ dst[dst_index] = src[index2>>32];
+ index2 += incr;
+ }
+ frac += dst_index * dst_incr_frac;
+ index += dst_index * dst_incr;
+ index += frac / c->src_incr;
+ frac %= c->src_incr;
+ }else{
+ for(dst_index=0; dst_index < dst_size; dst_index++){
+ FELEM *filter= c->filter_bank + c->filter_length*(index & c->phase_mask);
+ int sample_index= index >> c->phase_shift;
+ FELEM2 val=0;
+
+ if(sample_index < 0){
+ for(i=0; i<c->filter_length; i++)
+ val += src[FFABS(sample_index + i) % src_size] * filter[i];
+ }else if(sample_index + c->filter_length > src_size){
+ break;
+ }else if(c->linear){
+ FELEM2 v2=0;
+ for(i=0; i<c->filter_length; i++){
+ val += src[sample_index + i] * (FELEM2)filter[i];
+ v2 += src[sample_index + i] * (FELEM2)filter[i + c->filter_length];
+ }
+ val+=(v2-val)*(FELEML)frac / c->src_incr;
+ }else{
+ for(i=0; i<c->filter_length; i++){
+ val += src[sample_index + i] * (FELEM2)filter[i];
+ }
+ }
+
+#ifdef CONFIG_RESAMPLE_AUDIOPHILE_KIDDY_MODE
+ dst[dst_index] = av_clip_int16(lrintf(val));
+#else
+ val = (val + (1<<(FILTER_SHIFT-1)))>>FILTER_SHIFT;
+ dst[dst_index] = (unsigned)(val + 32768) > 65535 ? (val>>31) ^ 32767 : val;
+#endif
+
+ frac += dst_incr_frac;
+ index += dst_incr;
+ if(frac >= c->src_incr){
+ frac -= c->src_incr;
+ index++;
+ }
+
+ if(dst_index + 1 == compensation_distance){
+ compensation_distance= 0;
+ dst_incr_frac= c->ideal_dst_incr % c->src_incr;
+ dst_incr= c->ideal_dst_incr / c->src_incr;
+ }
+ }
+ }
+ *consumed= FFMAX(index, 0) >> c->phase_shift;
+ if(index>=0) index &= c->phase_mask;
+
+ if(compensation_distance){
+ compensation_distance -= dst_index;
+ assert(compensation_distance > 0);
+ }
+ if(update_ctx){
+ c->frac= frac;
+ c->index= index;
+ c->dst_incr= dst_incr_frac + c->src_incr*dst_incr;
+ c->compensation_distance= compensation_distance;
+ }
+#if 0
+ if(update_ctx && !c->compensation_distance){
+#undef rand
+ av_resample_compensate(c, rand() % (8000*2) - 8000, 8000*2);
+av_log(NULL, AV_LOG_DEBUG, "%d %d %d\n", c->dst_incr, c->ideal_dst_incr, c->compensation_distance);
+ }
+#endif
+
+ return dst_index;
+}
+
+int swr_multiple_resample(AVResampleContext *c, AudioData *dst, int dst_size, AudioData *src, int src_size, int *consumed){
+ int i, ret= -1;
+
+ for(i=0; i<dst->ch_count; i++){
+ ret= swr_resample(c, (short*)dst->ch[i], (const short*)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count);
+ }
+
+ return ret;
+}
diff --git a/libswresample/swresample.c b/libswresample/swresample.c
new file mode 100644
index 0000000000..a03d531d0f
--- /dev/null
+++ b/libswresample/swresample.c
@@ -0,0 +1,459 @@
+/*
+ * Copyright (C) 2011 Michael Niedermayer (michaelni@gmx.at)
+ *
+ * This file is part of libswresample
+ *
+ * libswresample 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.
+ *
+ * libswresample 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with libswresample; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/opt.h"
+#include "swresample_internal.h"
+#include "audioconvert.h"
+#include "libavutil/avassert.h"
+#include "libavutil/audioconvert.h"
+
+#define C30DB M_SQRT2
+#define C15DB 1.189207115
+#define C__0DB 1.0
+#define C_15DB 0.840896415
+#define C_30DB M_SQRT1_2
+#define C_45DB 0.594603558
+#define C_60DB 0.5
+
+
+//TODO split options array out?
+#define OFFSET(x) offsetof(SwrContext,x)
+static const AVOption options[]={
+{"ich", "input channel count", OFFSET( in.ch_count ), AV_OPT_TYPE_INT, {.dbl=2}, 1, SWR_CH_MAX, 0},
+{"och", "output channel count", OFFSET(out.ch_count ), AV_OPT_TYPE_INT, {.dbl=2}, 1, SWR_CH_MAX, 0},
+{"isr", "input sample rate" , OFFSET( in_sample_rate), AV_OPT_TYPE_INT, {.dbl=48000}, 1, INT_MAX, 0},
+{"osr", "output sample rate" , OFFSET(out_sample_rate), AV_OPT_TYPE_INT, {.dbl=48000}, 1, INT_MAX, 0},
+//{"ip" , "input planar" , OFFSET( in.planar ), AV_OPT_TYPE_INT, {.dbl=0}, 0, 1, 0},
+//{"op" , "output planar" , OFFSET(out.planar ), AV_OPT_TYPE_INT, {.dbl=0}, 0, 1, 0},
+{"isf", "input sample format", OFFSET( in_sample_fmt ), AV_OPT_TYPE_INT, {.dbl=AV_SAMPLE_FMT_S16}, 0, AV_SAMPLE_FMT_NB-1+256, 0},
+{"osf", "output sample format", OFFSET(out_sample_fmt ), AV_OPT_TYPE_INT, {.dbl=AV_SAMPLE_FMT_S16}, 0, AV_SAMPLE_FMT_NB-1+256, 0},
+{"tsf", "internal sample format", OFFSET(int_sample_fmt ), AV_OPT_TYPE_INT, {.dbl=AV_SAMPLE_FMT_NONE}, -1, AV_SAMPLE_FMT_FLT, 0},
+{"icl", "input channel layout" , OFFSET( in_ch_layout), AV_OPT_TYPE_INT64, {.dbl=0}, 0, INT64_MAX, 0, "channel_layout"},
+{"ocl", "output channel layout", OFFSET(out_ch_layout), AV_OPT_TYPE_INT64, {.dbl=0}, 0, INT64_MAX, 0, "channel_layout"},
+{"clev", "center mix level" , OFFSET(clev) , AV_OPT_TYPE_FLOAT, {.dbl=C_30DB}, 0, 4, 0},
+{"slev", "sourround mix level" , OFFSET(slev) , AV_OPT_TYPE_FLOAT, {.dbl=C_30DB}, 0, 4, 0},
+{"flags", NULL , OFFSET(flags) , AV_OPT_TYPE_FLAGS, {.dbl=0}, 0, UINT_MAX, 0, "flags"},
+{"res", "force resampling", 0, AV_OPT_TYPE_CONST, {.dbl=SWR_FLAG_RESAMPLE}, INT_MIN, INT_MAX, 0, "flags"},
+
+{0}
+};
+
+static const char* context_to_name(void* ptr) {
+ return "SWR";
+}
+
+static const AVClass av_class = { "SwrContext", context_to_name, options, LIBAVUTIL_VERSION_INT, OFFSET(log_level_offset), OFFSET(log_ctx) };
+
+static int resample(SwrContext *s, AudioData *out_param, int out_count,
+ const AudioData * in_param, int in_count);
+
+SwrContext *swr_alloc(void){
+ SwrContext *s= av_mallocz(sizeof(SwrContext));
+ if(s){
+ s->av_class= &av_class;
+ av_opt_set_defaults2(s, 0, 0);
+ }
+ return s;
+}
+
+SwrContext *swr_alloc2(struct SwrContext *s, int64_t out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate,
+ int64_t in_ch_layout, enum AVSampleFormat in_sample_fmt, int in_sample_rate,
+ int log_offset, void *log_ctx){
+ if(!s) s= swr_alloc();
+ if(!s) return NULL;
+
+ s->log_level_offset= log_offset;
+ s->log_ctx= log_ctx;
+
+ av_set_int(s, "ocl", out_ch_layout);
+ av_set_int(s, "osf", out_sample_fmt);
+ av_set_int(s, "osr", out_sample_rate);
+ av_set_int(s, "icl", in_ch_layout);
+ av_set_int(s, "isf", in_sample_fmt);
+ av_set_int(s, "isr", in_sample_rate);
+
+ s-> in.ch_count= av_get_channel_layout_nb_channels(s-> in_ch_layout);
+ s->out.ch_count= av_get_channel_layout_nb_channels(s->out_ch_layout);
+ s->int_sample_fmt = AV_SAMPLE_FMT_S16;
+
+ return s;
+}
+
+
+static void free_temp(AudioData *a){
+ av_free(a->data);
+ memset(a, 0, sizeof(*a));
+}
+
+void swr_free(SwrContext **ss){
+ SwrContext *s= *ss;
+ if(s){
+ free_temp(&s->postin);
+ free_temp(&s->midbuf);
+ free_temp(&s->preout);
+ free_temp(&s->in_buffer);
+ swr_audio_convert_free(&s-> in_convert);
+ swr_audio_convert_free(&s->out_convert);
+ swr_audio_convert_free(&s->full_convert);
+ swr_resample_free(&s->resample);
+ }
+
+ av_freep(ss);
+}
+
+int swr_init(SwrContext *s){
+ s->in_buffer_index= 0;
+ s->in_buffer_count= 0;
+ s->resample_in_constraint= 0;
+ free_temp(&s->postin);
+ free_temp(&s->midbuf);
+ free_temp(&s->preout);
+ free_temp(&s->in_buffer);
+ swr_audio_convert_free(&s-> in_convert);
+ swr_audio_convert_free(&s->out_convert);
+ swr_audio_convert_free(&s->full_convert);
+
+ s-> in.planar= s-> in_sample_fmt >= 0x100;
+ s->out.planar= s->out_sample_fmt >= 0x100;
+ s-> in_sample_fmt &= 0xFF;
+ s->out_sample_fmt &= 0xFF;
+
+ if(s-> in_sample_fmt >= AV_SAMPLE_FMT_NB){
+ av_log(s, AV_LOG_ERROR, "Requested sample format %s is invalid\n", av_get_sample_fmt_name(s->in_sample_fmt));
+ return AVERROR(EINVAL);
+ }
+ if(s->out_sample_fmt >= AV_SAMPLE_FMT_NB){
+ av_log(s, AV_LOG_ERROR, "Requested sample format %s is invalid\n", av_get_sample_fmt_name(s->out_sample_fmt));
+ return AVERROR(EINVAL);
+ }
+
+ if( s->int_sample_fmt != AV_SAMPLE_FMT_S16
+ &&s->int_sample_fmt != AV_SAMPLE_FMT_FLT){
+ av_log(s, AV_LOG_ERROR, "Requested sample format %s is not supported internally, only float & S16 is supported\n", av_get_sample_fmt_name(s->int_sample_fmt));
+ return AVERROR(EINVAL);
+ }
+
+ //FIXME should we allow/support using FLT on material that doesnt need it ?
+ if(s->in_sample_fmt <= AV_SAMPLE_FMT_S16 || s->int_sample_fmt==AV_SAMPLE_FMT_S16){
+ s->int_sample_fmt= AV_SAMPLE_FMT_S16;
+ }else
+ s->int_sample_fmt= AV_SAMPLE_FMT_FLT;
+
+
+ if (s->out_sample_rate!=s->in_sample_rate || (s->flags & SWR_FLAG_RESAMPLE)){
+ s->resample = swr_resample_init(s->resample, s->out_sample_rate, s->in_sample_rate, 16, 10, 0, 0.8);
+ }else
+ swr_resample_free(&s->resample);
+ if(s->int_sample_fmt != AV_SAMPLE_FMT_S16 && s->resample){
+ av_log(s, AV_LOG_ERROR, "Resampling only supported with internal s16 currently\n"); //FIXME
+ return -1;
+ }
+
+ if(s-> in.ch_count && s-> in_ch_layout && s->in.ch_count != av_get_channel_layout_nb_channels(s-> in_ch_layout)){
+ av_log(s, AV_LOG_WARNING, "Input channel layout has a different number of channels than there actually is, ignoring layout\n");
+ s-> in_ch_layout= 0;
+ }
+
+ if(!s-> in_ch_layout)
+ s-> in_ch_layout= av_get_default_channel_layout(s->in.ch_count);
+ if(!s->out_ch_layout)
+ s->out_ch_layout= av_get_default_channel_layout(s->out.ch_count);
+
+ s->rematrix= s->out_ch_layout !=s->in_ch_layout;
+
+#define RSC 1 //FIXME finetune
+ if(!s-> in.ch_count)
+ s-> in.ch_count= av_get_channel_layout_nb_channels(s-> in_ch_layout);
+ if(!s->out.ch_count)
+ s->out.ch_count= av_get_channel_layout_nb_channels(s->out_ch_layout);
+
+av_assert0(s-> in.ch_count);
+av_assert0(s->out.ch_count);
+ s->resample_first= RSC*s->out.ch_count/s->in.ch_count - RSC < s->out_sample_rate/(float)s-> in_sample_rate - 1.0;
+
+ s-> in.bps= av_get_bits_per_sample_fmt(s-> in_sample_fmt)/8;
+ s->int_bps= av_get_bits_per_sample_fmt(s->int_sample_fmt)/8;
+ s->out.bps= av_get_bits_per_sample_fmt(s->out_sample_fmt)/8;
+
+ if(!s->resample && !s->rematrix){
+ s->full_convert = swr_audio_convert_alloc(s->out_sample_fmt,
+ s-> in_sample_fmt, s-> in.ch_count, 0);
+ return 0;
+ }
+
+ s->in_convert = swr_audio_convert_alloc(s->int_sample_fmt,
+ s-> in_sample_fmt, s-> in.ch_count, 0);
+ s->out_convert= swr_audio_convert_alloc(s->out_sample_fmt,
+ s->int_sample_fmt, s->out.ch_count, 0);
+
+
+ s->postin= s->in;
+ s->preout= s->out;
+ s->midbuf= s->in;
+ s->in_buffer= s->in;
+ if(!s->resample_first){
+ s->midbuf.ch_count= s->out.ch_count;
+ s->in_buffer.ch_count = s->out.ch_count;
+ }
+
+ s->in_buffer.bps = s->postin.bps = s->midbuf.bps = s->preout.bps = s->int_bps;
+ s->in_buffer.planar = s->postin.planar = s->midbuf.planar = s->preout.planar = 1;
+
+
+ if(s->rematrix && swr_rematrix_init(s)<0)
+ return -1;
+
+ return 0;
+}
+
+static int realloc_audio(AudioData *a, int count){
+ int i, countb;
+ AudioData old;
+
+ if(a->count >= count)
+ return 0;
+
+ count*=2;
+
+ countb= FFALIGN(count*a->bps, 32);
+ old= *a;
+
+ av_assert0(a->planar);
+ av_assert0(a->bps);
+ av_assert0(a->ch_count);
+
+ a->data= av_malloc(countb*a->ch_count);
+ if(!a->data)
+ return AVERROR(ENOMEM);
+ for(i=0; i<a->ch_count; i++){
+ a->ch[i]= a->data + i*(a->planar ? countb : a->bps);
+ if(a->planar) memcpy(a->ch[i], old.ch[i], a->count*a->bps);
+ }
+ av_free(old.data);
+ a->count= count;
+
+ return 1;
+}
+
+static void copy(AudioData *out, AudioData *in,
+ int count){
+ av_assert0(out->planar == in->planar);
+ av_assert0(out->bps == in->bps);
+ av_assert0(out->ch_count == in->ch_count);
+ if(out->planar){
+ int ch;
+ for(ch=0; ch<out->ch_count; ch++)
+ memcpy(out->ch[ch], in->ch[ch], count*out->bps);
+ }else
+ memcpy(out->ch[0], in->ch[0], count*out->ch_count*out->bps);
+}
+
+static void fill_audiodata(AudioData *out, uint8_t *in_arg [SWR_CH_MAX]){
+ int i;
+ if(out->planar){
+ for(i=0; i<out->ch_count; i++)
+ out->ch[i]= in_arg[i];
+ }else{
+ for(i=0; i<out->ch_count; i++)
+ out->ch[i]= in_arg[0] + i*out->bps;
+ }
+}
+
+int swr_convert(struct SwrContext *s, uint8_t *out_arg[SWR_CH_MAX], int out_count,
+ const uint8_t *in_arg [SWR_CH_MAX], int in_count){
+ AudioData *postin, *midbuf, *preout;
+ int ret/*, in_max*/;
+ AudioData * in= &s->in;
+ AudioData *out= &s->out;
+ AudioData preout_tmp, midbuf_tmp;
+
+ if(!s->resample){
+ if(in_count > out_count)
+ return -1;
+ out_count = in_count;
+ }
+
+ fill_audiodata(in , (void*)in_arg);
+ fill_audiodata(out, out_arg);
+
+ if(s->full_convert){
+ av_assert0(!s->resample);
+ swr_audio_convert(s->full_convert, out, in, in_count);
+ return out_count;
+ }
+
+// in_max= out_count*(int64_t)s->in_sample_rate / s->out_sample_rate + resample_filter_taps;
+// in_count= FFMIN(in_count, in_in + 2 - s->hist_buffer_count);
+
+ if((ret=realloc_audio(&s->postin, in_count))<0)
+ return ret;
+ if(s->resample_first){
+ av_assert0(s->midbuf.ch_count == s-> in.ch_count);
+ if((ret=realloc_audio(&s->midbuf, out_count))<0)
+ return ret;
+ }else{
+ av_assert0(s->midbuf.ch_count == s->out.ch_count);
+ if((ret=realloc_audio(&s->midbuf, in_count))<0)
+ return ret;
+ }
+ if((ret=realloc_audio(&s->preout, out_count))<0)
+ return ret;
+
+ postin= &s->postin;
+
+ midbuf_tmp= s->midbuf;
+ midbuf= &midbuf_tmp;
+ preout_tmp= s->preout;
+ preout= &preout_tmp;
+
+ if(s->int_sample_fmt == s-> in_sample_fmt && s->in.planar)
+ postin= in;
+
+ if(s->resample_first ? !s->resample : !s->rematrix)
+ midbuf= postin;
+
+ if(s->resample_first ? !s->rematrix : !s->resample)
+ preout= midbuf;
+
+ if(s->int_sample_fmt == s->out_sample_fmt && s->out.planar){
+ if(preout==in){
+ out_count= FFMIN(out_count, in_count); //TODO check at teh end if this is needed or redundant
+ av_assert0(s->in.planar); //we only support planar internally so it has to be, we support copying non planar though
+ copy(out, in, out_count);
+ return out_count;
+ }
+ else if(preout==postin) preout= midbuf= postin= out;
+ else if(preout==midbuf) preout= midbuf= out;
+ else preout= out;
+ }
+
+ if(in != postin){
+ swr_audio_convert(s->in_convert, postin, in, in_count);
+ }
+
+ if(s->resample_first){
+ if(postin != midbuf)
+ out_count= resample(s, midbuf, out_count, postin, in_count);
+ if(midbuf != preout)
+ swr_rematrix(s, preout, midbuf, out_count, preout==out);
+ }else{
+ if(postin != midbuf)
+ swr_rematrix(s, midbuf, postin, in_count, midbuf==out);
+ if(midbuf != preout)
+ out_count= resample(s, preout, out_count, midbuf, in_count);
+ }
+
+ if(preout != out){
+//FIXME packed doesnt need more than 1 chan here!
+ swr_audio_convert(s->out_convert, out, preout, out_count);
+ }
+ return out_count;
+}
+
+/**
+ *
+ * out may be equal in.
+ */
+static void buf_set(AudioData *out, AudioData *in, int count){
+ if(in->planar){
+ int ch;
+ for(ch=0; ch<out->ch_count; ch++)
+ out->ch[ch]= in->ch[ch] + count*out->bps;
+ }else
+ out->ch[0]= in->ch[0] + count*out->ch_count*out->bps;
+}
+
+/**
+ *
+ * @return number of samples output per channel
+ */
+static int resample(SwrContext *s, AudioData *out_param, int out_count,
+ const AudioData * in_param, int in_count){
+ AudioData in, out, tmp;
+ int ret_sum=0;
+ int border=0;
+
+ tmp=out=*out_param;
+ in = *in_param;
+
+ do{
+ int ret, size, consumed;
+ if(!s->resample_in_constraint && s->in_buffer_count){
+ buf_set(&tmp, &s->in_buffer, s->in_buffer_index);
+ ret= swr_multiple_resample(s->resample, &out, out_count, &tmp, s->in_buffer_count, &consumed);
+ out_count -= ret;
+ ret_sum += ret;
+ buf_set(&out, &out, ret);
+ s->in_buffer_count -= consumed;
+ s->in_buffer_index += consumed;
+
+ if(!in_count)
+ break;
+ if(s->in_buffer_count <= border){
+ buf_set(&in, &in, -s->in_buffer_count);
+ in_count += s->in_buffer_count;
+ s->in_buffer_count=0;
+ s->in_buffer_index=0;
+ border = 0;
+ }
+ }
+
+ if(in_count && !s->in_buffer_count){
+ s->in_buffer_index=0;
+ ret= swr_multiple_resample(s->resample, &out, out_count, &in, in_count, &consumed);
+ out_count -= ret;
+ ret_sum += ret;
+ buf_set(&out, &out, ret);
+ in_count -= consumed;
+ buf_set(&in, &in, consumed);
+ }
+
+ //TODO is this check sane considering the advanced copy avoidance below
+ size= s->in_buffer_index + s->in_buffer_count + in_count;
+ if( size > s->in_buffer.count
+ && s->in_buffer_count + in_count <= s->in_buffer_index){
+ buf_set(&tmp, &s->in_buffer, s->in_buffer_index);
+ copy(&s->in_buffer, &tmp, s->in_buffer_count);
+ s->in_buffer_index=0;
+ }else
+ if((ret=realloc_audio(&s->in_buffer, size)) < 0)
+ return ret;
+
+ if(in_count){
+ int count= in_count;
+ if(s->in_buffer_count && s->in_buffer_count+2 < count && out_count) count= s->in_buffer_count+2;
+
+ buf_set(&tmp, &s->in_buffer, s->in_buffer_index + s->in_buffer_count);
+ copy(&tmp, &in, /*in_*/count);
+ s->in_buffer_count += count;
+ in_count -= count;
+ border += count;
+ buf_set(&in, &in, count);
+ s->resample_in_constraint= 0;
+ if(s->in_buffer_count != count || in_count)
+ continue;
+ }
+ break;
+ }while(1);
+
+ s->resample_in_constraint= !!out_count;
+
+ return ret_sum;
+}
diff --git a/libswresample/swresample.h b/libswresample/swresample.h
new file mode 100644
index 0000000000..05c4f6dc01
--- /dev/null
+++ b/libswresample/swresample.h
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2011 Michael Niedermayer (michaelni@gmx.at)
+ *
+ * This file is part of libswresample
+ *
+ * libswresample 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.
+ *
+ * libswresample 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with libswresample; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef SWR_H
+#define SWR_H
+
+#include <inttypes.h>
+#include "libavutil/samplefmt.h"
+
+#define LIBSWRESAMPLE_VERSION_MAJOR 0
+#define LIBSWRESAMPLE_VERSION_MINOR 0
+#define LIBSWRESAMPLE_VERSION_MICRO 0
+
+#define SWR_CH_MAX 16
+
+#define SWR_FLAG_RESAMPLE 1///< Force resampling even if equal sample rate
+//TODO use int resample ?
+//long term TODO can we enable this dynamically?
+
+
+struct SwrContext;
+
+/**
+ * Allocate SwrContext.
+ * @see swr_init(),swr_free()
+ * @return NULL on error
+ */
+struct SwrContext *swr_alloc(void);
+
+/**
+ * Initialize context after user parameters have been set.
+ * @return negativo n error
+ */
+int swr_init(struct SwrContext *s);
+
+/**
+ * Allocate SwrContext.
+ * @see swr_init(),swr_free()
+ * @return NULL on error
+ */
+struct SwrContext *swr_alloc2(struct SwrContext *s, int64_t out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate,
+ int64_t in_ch_layout, enum AVSampleFormat in_sample_fmt, int in_sample_rate,
+ int log_offset, void *log_ctx);
+
+/**
+ * Free the given SwrContext.
+ * And set the pointer to NULL
+ */
+void swr_free(struct SwrContext **s);
+
+/**
+ * Convert audio.
+ * @param in_count Number of input samples available in one channel.
+ * @param out_count Amount of space available for output in samples per channel.
+ * @return number of samples output per channel
+ */
+int swr_convert(struct SwrContext *s, uint8_t *out[SWR_CH_MAX], int out_count,
+ const uint8_t *in [SWR_CH_MAX], int in_count);
+
+void swr_compensate(struct SwrContext *s, int sample_delta, int compensation_distance);
+
+#endif
diff --git a/libswresample/swresample_internal.h b/libswresample/swresample_internal.h
new file mode 100644
index 0000000000..3137be62da
--- /dev/null
+++ b/libswresample/swresample_internal.h
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2011 Michael Niedermayer (michaelni@gmx.at)
+ *
+ * This file is part of libswresample
+ *
+ * libswresample 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.
+ *
+ * libswresample 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with libswresample; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef SWR_INTERNAL_H
+#define SWR_INTERNAL_H
+
+#include "swresample.h"
+
+typedef struct AudioData{
+ uint8_t *ch[SWR_CH_MAX];
+ uint8_t *data;
+ int ch_count;
+ int bps;
+ int count;
+ int planar;
+} AudioData;
+
+typedef struct SwrContext { //FIXME find unused fields
+ const AVClass *av_class;
+ int log_level_offset;
+ void *log_ctx;
+ enum AVSampleFormat in_sample_fmt;
+ enum AVSampleFormat int_sample_fmt; ///<AV_SAMPLE_FMT_FLT OR AV_SAMPLE_FMT_S16
+ enum AVSampleFormat out_sample_fmt;
+ int64_t in_ch_layout;
+ int64_t out_ch_layout;
+ int in_sample_rate;
+ int out_sample_rate;
+ int flags;
+ float slev, clev;
+
+ //below are private
+ int int_bps;
+ int resample_first;
+ int rematrix; ///< flag to indicate if rematrixing is used
+
+ AudioData in, postin, midbuf, preout, out, in_buffer;
+ int in_buffer_index;
+ int in_buffer_count;
+ int resample_in_constraint;
+
+ struct AVAudioConvert *in_convert;
+ struct AVAudioConvert *out_convert;
+ struct AVAudioConvert *full_convert;
+ struct AVResampleContext *resample;
+
+ float matrix[SWR_CH_MAX][SWR_CH_MAX];
+ int16_t matrix16[SWR_CH_MAX][SWR_CH_MAX];
+ uint8_t matrix_ch[SWR_CH_MAX][SWR_CH_MAX+1];
+
+ //TODO callbacks for asm optims
+}SwrContext;
+
+struct AVResampleContext *swr_resample_init(struct AVResampleContext *, int out_rate, int in_rate, int filter_size, int phase_shift, int linear, double cutoff);
+void swr_resample_free(struct AVResampleContext **c);
+int swr_multiple_resample(struct AVResampleContext *c, AudioData *dst, int dst_size, AudioData *src, int src_size, int *consumed);
+void swr_resample_compensate(struct AVResampleContext *c, int sample_delta, int compensation_distance);
+int swr_resample(struct AVResampleContext *c, short *dst, const short *src, int *consumed, int src_size, int dst_size, int update_ctx);
+
+int swr_rematrix_init(SwrContext *s);
+int swr_rematrix(SwrContext *s, AudioData *out, AudioData *in, int len, int mustcopy);
+#endif
diff --git a/libswresample/swresample_test.c b/libswresample/swresample_test.c
new file mode 100644
index 0000000000..61e1b09367
--- /dev/null
+++ b/libswresample/swresample_test.c
@@ -0,0 +1,186 @@
+/*
+ * Copyright (C) 2011 Michael Niedermayer (michaelni@gmx.at)
+ *
+ * This file is part of libswresample
+ *
+ * libswresample 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.
+ *
+ * libswresample 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 libswresample; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/avassert.h"
+#include "libavutil/common.h"
+#include "libavutil/audioconvert.h"
+#include "swresample.h"
+#undef fprintf
+
+#define SAMPLES 1000
+
+#define ASSERT_LEVEL 2
+
+static double get(const uint8_t *a[], int ch, int index, int ch_count, enum AVSampleFormat f){
+ const uint8_t *p;
+ if(f>=0x100){
+ f&=0xFF;
+ p= a[ch];
+ }else{
+ p= a[0];
+ index= ch + index*ch_count;
+ }
+
+ switch(f){
+ case AV_SAMPLE_FMT_U8 : return ((const uint8_t*)p)[index]/255.0*2-1.0;
+ case AV_SAMPLE_FMT_S16: return ((const int16_t*)p)[index]/32767.0;
+ case AV_SAMPLE_FMT_S32: return ((const int32_t*)p)[index]/2147483647.0;
+ case AV_SAMPLE_FMT_FLT: return ((const float *)p)[index];
+ case AV_SAMPLE_FMT_DBL: return ((const double *)p)[index];
+ default: av_assert2(0);
+ }
+}
+
+static void set(uint8_t *a[], int ch, int index, int ch_count, enum AVSampleFormat f, double v){
+ uint8_t *p;
+ if(f>=0x100){
+ f&=0xFF;
+ p= a[ch];
+ }else{
+ p= a[0];
+ index= ch + index*ch_count;
+ }
+ switch(f){
+ case AV_SAMPLE_FMT_U8 : ((uint8_t*)p)[index]= (v+1.0)*255.0/2; break;
+ case AV_SAMPLE_FMT_S16: ((int16_t*)p)[index]= v*32767; break;
+ case AV_SAMPLE_FMT_S32: ((int32_t*)p)[index]= v*2147483647; break;
+ case AV_SAMPLE_FMT_FLT: ((float *)p)[index]= v; break;
+ case AV_SAMPLE_FMT_DBL: ((double *)p)[index]= v; break;
+ default: av_assert2(0);
+ }
+}
+
+uint64_t layouts[]={
+AV_CH_LAYOUT_MONO ,
+AV_CH_LAYOUT_STEREO ,
+AV_CH_LAYOUT_2_1 ,
+AV_CH_LAYOUT_SURROUND ,
+AV_CH_LAYOUT_4POINT0 ,
+AV_CH_LAYOUT_2_2 ,
+AV_CH_LAYOUT_QUAD ,
+AV_CH_LAYOUT_5POINT0 ,
+AV_CH_LAYOUT_5POINT1 ,
+AV_CH_LAYOUT_5POINT0_BACK ,
+AV_CH_LAYOUT_5POINT1_BACK ,
+AV_CH_LAYOUT_7POINT0 ,
+AV_CH_LAYOUT_7POINT1 ,
+AV_CH_LAYOUT_7POINT1_WIDE ,
+0
+};
+
+static void setup_array(uint8_t *out[SWR_CH_MAX], uint8_t *in, enum AVSampleFormat format, int samples){
+ if(format >= 0x100){
+ int i;
+ int plane_size= av_get_bytes_per_sample(format&0xFF)*samples;
+ format&=0xFF;
+ for(i=0; i<SWR_CH_MAX; i++){
+ out[i]= in + i*plane_size;
+ }
+ }else{
+ out[0]= in;
+ }
+}
+
+int main(int argc, char **argv){
+ int in_sample_rate, out_sample_rate, ch ,i, in_ch_layout_index, out_ch_layout_index, osr;
+ uint64_t in_ch_layout, out_ch_layout;
+ enum AVSampleFormat in_sample_fmt, out_sample_fmt;
+ int sample_rates[]={8000,11025,16000,22050,32000};
+ uint8_t array_in[SAMPLES*8*8];
+ uint8_t array_mid[SAMPLES*8*8*3];
+ uint8_t array_out[SAMPLES*8*8+100];
+ uint8_t *ain[SWR_CH_MAX];
+ uint8_t *aout[SWR_CH_MAX];
+ uint8_t *amid[SWR_CH_MAX];
+ int planar_in=256, planar_out=256;
+
+ struct SwrContext * forw_ctx= NULL;
+ struct SwrContext *backw_ctx= NULL;
+
+ in_sample_rate=16000;
+ for(osr=0; osr<5; osr++){
+ out_sample_rate= sample_rates[osr];
+ for(in_sample_fmt= AV_SAMPLE_FMT_U8; in_sample_fmt<=AV_SAMPLE_FMT_DBL; in_sample_fmt++){
+ for(out_sample_fmt= AV_SAMPLE_FMT_U8; out_sample_fmt<=AV_SAMPLE_FMT_DBL; out_sample_fmt++){
+ for(in_ch_layout_index=0; layouts[in_ch_layout_index]; in_ch_layout_index++){
+ in_ch_layout= layouts[in_ch_layout_index];
+ int in_ch_count= av_get_channel_layout_nb_channels(in_ch_layout);
+ for(out_ch_layout_index=0; layouts[out_ch_layout_index]; out_ch_layout_index++){
+ int out_count, mid_count;
+ out_ch_layout= layouts[out_ch_layout_index];
+ int out_ch_count= av_get_channel_layout_nb_channels(out_ch_layout);
+ fprintf(stderr, "ch %d->%d, rate:%5d->%5d, fmt:%s->%s",
+ in_ch_count, out_ch_count,
+ in_sample_rate, out_sample_rate,
+ av_get_sample_fmt_name(in_sample_fmt), av_get_sample_fmt_name(out_sample_fmt));
+ forw_ctx = swr_alloc2(forw_ctx, out_ch_layout, out_sample_fmt+planar_out, out_sample_rate,
+ in_ch_layout, in_sample_fmt+planar_in , in_sample_rate, 0, 0);
+ backw_ctx = swr_alloc2(backw_ctx,in_ch_layout, in_sample_fmt, in_sample_rate,
+ out_ch_layout, out_sample_fmt+planar_out, out_sample_rate, 0, 0);
+ if(swr_init( forw_ctx) < 0)
+ fprintf(stderr, "swr_init(->) failed\n");
+ if(swr_init(backw_ctx) < 0)
+ fprintf(stderr, "swr_init(<-) failed\n");
+ if(!forw_ctx)
+ fprintf(stderr, "Failed to init forw_cts\n");
+ if(!backw_ctx)
+ fprintf(stderr, "Failed to init backw_ctx\n");
+ //FIXME test planar
+ setup_array(ain , array_in , in_sample_fmt+planar_in , SAMPLES);
+ setup_array(amid, array_mid, out_sample_fmt+planar_out, 3*SAMPLES);
+ setup_array(aout, array_out, in_sample_fmt , SAMPLES);
+ for(ch=0; ch<in_ch_count; ch++){
+ for(i=0; i<SAMPLES; i++)
+ set(ain, ch, i, in_ch_count, in_sample_fmt+planar_in, sin(i*i*3/SAMPLES));
+ }
+ mid_count= swr_convert(forw_ctx, amid, 3*SAMPLES, ain, SAMPLES);
+ out_count= swr_convert(backw_ctx,aout, SAMPLES, amid, mid_count);
+
+ for(ch=0; ch<in_ch_count; ch++){
+ double sse, x, maxdiff=0;
+ double sum_a= 0;
+ double sum_b= 0;
+ double sum_aa= 0;
+ double sum_bb= 0;
+ double sum_ab= 0;
+ for(i=0; i<out_count; i++){
+ double a= get(ain , ch, i, in_ch_count, in_sample_fmt+planar_in);
+ double b= get(aout, ch, i, in_ch_count, in_sample_fmt);
+ sum_a += a;
+ sum_b += b;
+ sum_aa+= a*a;
+ sum_bb+= b*b;
+ sum_ab+= a*b;
+ maxdiff= FFMAX(maxdiff, FFABS(a-b));
+ }
+ x = sum_ab/sum_bb;
+ sse= sum_aa + sum_bb*x*x - 2*x*sum_ab;
+
+ fprintf(stderr, "[%f %f %f] len:%5d\n", sqrt(sse/out_count), x, maxdiff, out_count);
+ }
+ fprintf(stderr, "\n");
+ }
+ }
+ }
+ }
+ }
+
+ return 0;
+}
diff --git a/libswscale/Makefile b/libswscale/Makefile
index 57e867a1b2..942545d282 100644
--- a/libswscale/Makefile
+++ b/libswscale/Makefile
@@ -1,3 +1,5 @@
+include $(SUBDIR)../config.mak
+
NAME = swscale
FFLIBS = avutil
@@ -17,6 +19,9 @@ OBJS-$(HAVE_MMX) += x86/rgb2rgb.o \
x86/swscale_mmx.o \
x86/yuv2rgb_mmx.o
OBJS-$(HAVE_VIS) += sparc/yuv2rgb_vis.o
+OBJS-$(HAVE_YASM) += x86/scale.o
+
+$(SUBDIR)x86/swscale_mmx.o: CFLAGS += $(NOREDZONE_FLAGS)
TESTPROGS = colorspace swscale
diff --git a/libswscale/bfin/internal_bfin.S b/libswscale/bfin/internal_bfin.S
index 9f985e7824..cb8d71253c 100644
--- a/libswscale/bfin/internal_bfin.S
+++ b/libswscale/bfin/internal_bfin.S
@@ -5,20 +5,20 @@
* Blackfin video color space converter operations
* convert I420 YV12 to RGB in various formats
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libswscale/bfin/swscale_bfin.c b/libswscale/bfin/swscale_bfin.c
index 0c5f004930..870636ea05 100644
--- a/libswscale/bfin/swscale_bfin.c
+++ b/libswscale/bfin/swscale_bfin.c
@@ -3,20 +3,20 @@
*
* Blackfin software video scaler operations
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libswscale/bfin/yuv2rgb_bfin.c b/libswscale/bfin/yuv2rgb_bfin.c
index 68af522642..7a7dc7f0e6 100644
--- a/libswscale/bfin/yuv2rgb_bfin.c
+++ b/libswscale/bfin/yuv2rgb_bfin.c
@@ -4,20 +4,20 @@
* Blackfin video color space converter operations
* convert I420 YV12 to RGB in various formats
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -28,6 +28,7 @@
#include <assert.h>
#include "config.h"
#include <unistd.h>
+#include "libavutil/pixdesc.h"
#include "libswscale/rgb2rgb.h"
#include "libswscale/swscale.h"
#include "libswscale/swscale_internal.h"
@@ -197,7 +198,7 @@ SwsFunc ff_yuv2rgb_get_func_ptr_bfin(SwsContext *c)
}
av_log(c, AV_LOG_INFO, "BlackFin accelerated color space converter %s\n",
- sws_format_name (c->dstFormat));
+ av_get_pix_fmt_name(c->dstFormat));
return f;
}
diff --git a/libswscale/colorspace-test.c b/libswscale/colorspace-test.c
index 07c1cbd803..34095d8532 100644
--- a/libswscale/colorspace-test.c
+++ b/libswscale/colorspace-test.c
@@ -1,20 +1,20 @@
/*
* Copyright (C) 2002 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libswscale/mlib/yuv2rgb_mlib.c b/libswscale/mlib/yuv2rgb_mlib.c
index 526c97505c..e9f11494ee 100644
--- a/libswscale/mlib/yuv2rgb_mlib.c
+++ b/libswscale/mlib/yuv2rgb_mlib.c
@@ -3,20 +3,20 @@
*
* Copyright (C) 2003 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libswscale/options.c b/libswscale/options.c
index ecd0ecd53a..65095d5fd1 100644
--- a/libswscale/options.c
+++ b/libswscale/options.c
@@ -1,20 +1,20 @@
/*
* Copyright (C) 2001-2003 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -34,36 +34,41 @@ static const char * sws_context_to_name(void * ptr)
#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
static const AVOption options[] = {
- { "sws_flags", "scaler/cpu flags", OFFSET(flags), FF_OPT_TYPE_FLAGS, {.dbl = DEFAULT }, 0, UINT_MAX, VE, "sws_flags" },
- { "fast_bilinear", "fast bilinear", 0, FF_OPT_TYPE_CONST, {.dbl = SWS_FAST_BILINEAR }, INT_MIN, INT_MAX, VE, "sws_flags" },
- { "bilinear", "bilinear", 0, FF_OPT_TYPE_CONST, {.dbl = SWS_BILINEAR }, INT_MIN, INT_MAX, VE, "sws_flags" },
- { "bicubic", "bicubic", 0, FF_OPT_TYPE_CONST, {.dbl = SWS_BICUBIC }, INT_MIN, INT_MAX, VE, "sws_flags" },
- { "experimental", "experimental", 0, FF_OPT_TYPE_CONST, {.dbl = SWS_X }, INT_MIN, INT_MAX, VE, "sws_flags" },
- { "neighbor", "nearest neighbor", 0, FF_OPT_TYPE_CONST, {.dbl = SWS_POINT }, INT_MIN, INT_MAX, VE, "sws_flags" },
- { "area", "averaging area", 0, FF_OPT_TYPE_CONST, {.dbl = SWS_AREA }, INT_MIN, INT_MAX, VE, "sws_flags" },
- { "bicublin", "luma bicubic, chroma bilinear", 0, FF_OPT_TYPE_CONST, {.dbl = SWS_BICUBLIN }, INT_MIN, INT_MAX, VE, "sws_flags" },
- { "gauss", "gaussian", 0, FF_OPT_TYPE_CONST, {.dbl = SWS_GAUSS }, INT_MIN, INT_MAX, VE, "sws_flags" },
- { "sinc", "sinc", 0, FF_OPT_TYPE_CONST, {.dbl = SWS_SINC }, INT_MIN, INT_MAX, VE, "sws_flags" },
- { "lanczos", "lanczos", 0, FF_OPT_TYPE_CONST, {.dbl = SWS_LANCZOS }, INT_MIN, INT_MAX, VE, "sws_flags" },
- { "spline", "natural bicubic spline", 0, FF_OPT_TYPE_CONST, {.dbl = SWS_SPLINE }, INT_MIN, INT_MAX, VE, "sws_flags" },
- { "print_info", "print info", 0, FF_OPT_TYPE_CONST, {.dbl = SWS_PRINT_INFO }, INT_MIN, INT_MAX, VE, "sws_flags" },
- { "accurate_rnd", "accurate rounding", 0, FF_OPT_TYPE_CONST, {.dbl = SWS_ACCURATE_RND }, INT_MIN, INT_MAX, VE, "sws_flags" },
- { "full_chroma_int", "full chroma interpolation", 0 , FF_OPT_TYPE_CONST, {.dbl = SWS_FULL_CHR_H_INT }, INT_MIN, INT_MAX, VE, "sws_flags" },
- { "full_chroma_inp", "full chroma input", 0 , FF_OPT_TYPE_CONST, {.dbl = SWS_FULL_CHR_H_INP }, INT_MIN, INT_MAX, VE, "sws_flags" },
- { "bitexact", "", 0 , FF_OPT_TYPE_CONST, {.dbl = SWS_BITEXACT }, INT_MIN, INT_MAX, VE, "sws_flags" },
+ { "sws_flags", "scaler/cpu flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.dbl = DEFAULT }, 0, UINT_MAX, VE, "sws_flags" },
+ { "fast_bilinear", "fast bilinear", 0, AV_OPT_TYPE_CONST, {.dbl = SWS_FAST_BILINEAR }, INT_MIN, INT_MAX, VE, "sws_flags" },
+ { "bilinear", "bilinear", 0, AV_OPT_TYPE_CONST, {.dbl = SWS_BILINEAR }, INT_MIN, INT_MAX, VE, "sws_flags" },
+ { "bicubic", "bicubic", 0, AV_OPT_TYPE_CONST, {.dbl = SWS_BICUBIC }, INT_MIN, INT_MAX, VE, "sws_flags" },
+ { "experimental", "experimental", 0, AV_OPT_TYPE_CONST, {.dbl = SWS_X }, INT_MIN, INT_MAX, VE, "sws_flags" },
+ { "neighbor", "nearest neighbor", 0, AV_OPT_TYPE_CONST, {.dbl = SWS_POINT }, INT_MIN, INT_MAX, VE, "sws_flags" },
+ { "area", "averaging area", 0, AV_OPT_TYPE_CONST, {.dbl = SWS_AREA }, INT_MIN, INT_MAX, VE, "sws_flags" },
+ { "bicublin", "luma bicubic, chroma bilinear", 0, AV_OPT_TYPE_CONST, {.dbl = SWS_BICUBLIN }, INT_MIN, INT_MAX, VE, "sws_flags" },
+ { "gauss", "gaussian", 0, AV_OPT_TYPE_CONST, {.dbl = SWS_GAUSS }, INT_MIN, INT_MAX, VE, "sws_flags" },
+ { "sinc", "sinc", 0, AV_OPT_TYPE_CONST, {.dbl = SWS_SINC }, INT_MIN, INT_MAX, VE, "sws_flags" },
+ { "lanczos", "lanczos", 0, AV_OPT_TYPE_CONST, {.dbl = SWS_LANCZOS }, INT_MIN, INT_MAX, VE, "sws_flags" },
+ { "spline", "natural bicubic spline", 0, AV_OPT_TYPE_CONST, {.dbl = SWS_SPLINE }, INT_MIN, INT_MAX, VE, "sws_flags" },
+ { "print_info", "print info", 0, AV_OPT_TYPE_CONST, {.dbl = SWS_PRINT_INFO }, INT_MIN, INT_MAX, VE, "sws_flags" },
+ { "accurate_rnd", "accurate rounding", 0, AV_OPT_TYPE_CONST, {.dbl = SWS_ACCURATE_RND }, INT_MIN, INT_MAX, VE, "sws_flags" },
+ { "full_chroma_int", "full chroma interpolation", 0 , AV_OPT_TYPE_CONST, {.dbl = SWS_FULL_CHR_H_INT }, INT_MIN, INT_MAX, VE, "sws_flags" },
+ { "full_chroma_inp", "full chroma input", 0 , AV_OPT_TYPE_CONST, {.dbl = SWS_FULL_CHR_H_INP }, INT_MIN, INT_MAX, VE, "sws_flags" },
+ { "bitexact", "", 0 , AV_OPT_TYPE_CONST, {.dbl = SWS_BITEXACT }, INT_MIN, INT_MAX, VE, "sws_flags" },
- { "srcw", "source width" , OFFSET(srcW), FF_OPT_TYPE_INT, {.dbl = 16 }, 1, INT_MAX, VE },
- { "srch", "source height" , OFFSET(srcH), FF_OPT_TYPE_INT, {.dbl = 16 }, 1, INT_MAX, VE },
- { "dstw", "destination width" , OFFSET(dstW), FF_OPT_TYPE_INT, {.dbl = 16 }, 1, INT_MAX, VE },
- { "dsth", "destination height", OFFSET(dstH), FF_OPT_TYPE_INT, {.dbl = 16 }, 1, INT_MAX, VE },
- { "src_format", "source format" , OFFSET(srcFormat), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, PIX_FMT_NB-1, VE },
- { "dst_format", "destination format", OFFSET(dstFormat), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, PIX_FMT_NB-1, VE },
- { "src_range" , "source range" , OFFSET(srcRange) , FF_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, 1, VE },
- { "dst_range" , "destination range" , OFFSET(dstRange) , FF_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, 1, VE },
- { "param0" , "scaler param 0" , OFFSET(param[0]) , FF_OPT_TYPE_DOUBLE, {.dbl = SWS_PARAM_DEFAULT}, INT_MIN, INT_MAX, VE },
- { "param1" , "scaler param 1" , OFFSET(param[1]) , FF_OPT_TYPE_DOUBLE, {.dbl = SWS_PARAM_DEFAULT}, INT_MIN, INT_MAX, VE },
+ { "srcw", "source width" , OFFSET(srcW), AV_OPT_TYPE_INT, {.dbl = 16 }, 1, INT_MAX, VE },
+ { "srch", "source height" , OFFSET(srcH), AV_OPT_TYPE_INT, {.dbl = 16 }, 1, INT_MAX, VE },
+ { "dstw", "destination width" , OFFSET(dstW), AV_OPT_TYPE_INT, {.dbl = 16 }, 1, INT_MAX, VE },
+ { "dsth", "destination height", OFFSET(dstH), AV_OPT_TYPE_INT, {.dbl = 16 }, 1, INT_MAX, VE },
+ { "src_format", "source format" , OFFSET(srcFormat), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, PIX_FMT_NB-1, VE },
+ { "dst_format", "destination format", OFFSET(dstFormat), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, PIX_FMT_NB-1, VE },
+ { "src_range" , "source range" , OFFSET(srcRange) , AV_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, 1, VE },
+ { "dst_range" , "destination range" , OFFSET(dstRange) , AV_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, 1, VE },
+ { "param0" , "scaler param 0" , OFFSET(param[0]) , AV_OPT_TYPE_DOUBLE, {.dbl = SWS_PARAM_DEFAULT}, INT_MIN, INT_MAX, VE },
+ { "param1" , "scaler param 1" , OFFSET(param[1]) , AV_OPT_TYPE_DOUBLE, {.dbl = SWS_PARAM_DEFAULT}, INT_MIN, INT_MAX, VE },
{ NULL }
};
const AVClass sws_context_class = { "SWScaler", sws_context_to_name, options };
+
+const AVClass *sws_get_class(void)
+{
+ return &sws_context_class;
+}
diff --git a/libswscale/ppc/swscale_altivec.c b/libswscale/ppc/swscale_altivec.c
index 369e93b85a..076929cdaa 100644
--- a/libswscale/ppc/swscale_altivec.c
+++ b/libswscale/ppc/swscale_altivec.c
@@ -4,20 +4,20 @@
* Copyright (C) 2004 Romain Dolbeau <romain@dolbeau.org>
* based on the equivalent C code in swscale.c
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -36,13 +36,13 @@ altivec_packIntArrayToCharArray(int *val, uint8_t* dest, int dstW)
register int i;
vector unsigned int altivec_vectorShiftInt19 =
vec_add(vec_splat_u32(10), vec_splat_u32(9));
- if ((unsigned int)dest % 16) {
+ if ((uintptr_t)dest % 16) {
/* badly aligned store, we force store alignment */
/* and will handle load misalignment on val w/ vec_perm */
vector unsigned char perm1;
vector signed int v1;
for (i = 0 ; (i < dstW) &&
- (((unsigned int)dest + i) % 16) ; i++) {
+ (((uintptr_t)dest + i) % 16) ; i++) {
int t = val[i] >> 19;
dest[i] = (t < 0) ? 0 : ((t > 255) ? 255 : t);
}
@@ -92,6 +92,7 @@ altivec_packIntArrayToCharArray(int *val, uint8_t* dest, int dstW)
}
}
+//FIXME remove the usage of scratch buffers.
static void
yuv2yuvX_altivec_real(SwsContext *c,
const int16_t *lumFilter, const int16_t **lumSrc,
@@ -101,17 +102,13 @@ yuv2yuvX_altivec_real(SwsContext *c,
uint8_t *dest[4], int dstW, int chrDstW)
{
uint8_t *yDest = dest[0], *uDest = dest[1], *vDest = dest[2];
- const vector signed int vini = {(1 << 18), (1 << 18), (1 << 18), (1 << 18)};
+ const uint8_t *lumDither = c->lumDither8, *chrDither = c->chrDither8;
register int i, j;
{
DECLARE_ALIGNED(16, int, val)[dstW];
- for (i = 0; i < (dstW -7); i+=4) {
- vec_st(vini, i << 2, val);
- }
- for (; i < dstW; i++) {
- val[i] = (1 << 18);
- }
+ for (i=0; i<dstW; i++)
+ val[i] = lumDither[i & 7] << 12;
for (j = 0; j < lumFilterSize; j++) {
vector signed short l1, vLumFilter = vec_ld(j << 1, lumFilter);
@@ -155,13 +152,9 @@ yuv2yuvX_altivec_real(SwsContext *c,
DECLARE_ALIGNED(16, int, u)[chrDstW];
DECLARE_ALIGNED(16, int, v)[chrDstW];
- for (i = 0; i < (chrDstW -7); i+=4) {
- vec_st(vini, i << 2, u);
- vec_st(vini, i << 2, v);
- }
- for (; i < chrDstW; i++) {
- u[i] = (1 << 18);
- v[i] = (1 << 18);
+ for (i=0; i<chrDstW; i++) {
+ u[i] = chrDither[i & 7] << 12;
+ v[i] = chrDither[(i + 3) & 7] << 12;
}
for (j = 0; j < chrFilterSize; j++) {
@@ -249,7 +242,7 @@ static void hScale_altivec_real(SwsContext *c, int16_t *dst, int dstW,
vector unsigned char src_v1, src_vF;
vector signed short src_v, filter_v;
vector signed int val_vEven, val_s;
- if ((((int)src + srcPos)% 16) > 12) {
+ if ((((uintptr_t)src + srcPos) % 16) > 12) {
src_v1 = vec_ld(srcPos + 16, src);
}
src_vF = vec_perm(src_v0, src_v1, vec_lvsl(srcPos, src));
@@ -288,7 +281,7 @@ static void hScale_altivec_real(SwsContext *c, int16_t *dst, int dstW,
vector unsigned char src_v1, src_vF;
vector signed short src_v, filter_v;
vector signed int val_v, val_s;
- if ((((int)src + srcPos)% 16) > 8) {
+ if ((((uintptr_t)src + srcPos) % 16) > 8) {
src_v1 = vec_ld(srcPos + 16, src);
}
src_vF = vec_perm(src_v0, src_v1, vec_lvsl(srcPos, src));
@@ -374,7 +367,7 @@ static void hScale_altivec_real(SwsContext *c, int16_t *dst, int dstW,
//vector unsigned char src_v0 = vec_ld(srcPos + j, src);
vector unsigned char src_v1, src_vF;
vector signed short src_v, filter_v1R, filter_v;
- if ((((int)src + srcPos)% 16) > 8) {
+ if ((((uintptr_t)src + srcPos) % 16) > 8) {
src_v1 = vec_ld(srcPos + j + 16, src);
}
src_vF = vec_perm(src_v0, src_v1, permS);
@@ -406,8 +399,8 @@ void ff_sws_init_swScale_altivec(SwsContext *c)
if (!(av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC))
return;
- if (c->scalingBpp == 8) {
- c->hScale = hScale_altivec_real;
+ if (c->srcBpc == 8 && c->dstBpc <= 10) {
+ c->hyScale = c->hcScale = hScale_altivec_real;
}
if (!is16BPS(dstFormat) && !is9_OR_10BPS(dstFormat) &&
dstFormat != PIX_FMT_NV12 && dstFormat != PIX_FMT_NV21 &&
diff --git a/libswscale/ppc/yuv2rgb_altivec.c b/libswscale/ppc/yuv2rgb_altivec.c
index 73c02e9494..8e84c26382 100644
--- a/libswscale/ppc/yuv2rgb_altivec.c
+++ b/libswscale/ppc/yuv2rgb_altivec.c
@@ -3,20 +3,20 @@
*
* copyright (C) 2004 Marc Hoffman <marc.hoffman@analog.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -95,6 +95,7 @@ adjustment.
#include "libswscale/swscale.h"
#include "libswscale/swscale_internal.h"
#include "libavutil/cpu.h"
+#include "libavutil/pixdesc.h"
#include "yuv2rgb_altivec.h"
#undef PROFILE_THE_BEAST
@@ -298,7 +299,7 @@ static int altivec_##name (SwsContext *c, \
vector signed short R1,G1,B1; \
vector unsigned char R,G,B; \
\
- vector unsigned char *y1ivP, *y2ivP, *uivP, *vivP; \
+ const vector unsigned char *y1ivP, *y2ivP, *uivP, *vivP; \
vector unsigned char align_perm; \
\
vector signed short \
@@ -335,10 +336,10 @@ static int altivec_##name (SwsContext *c, \
\
for (j=0;j<w/16;j++) { \
\
- y1ivP = (vector unsigned char *)y1i; \
- y2ivP = (vector unsigned char *)y2i; \
- uivP = (vector unsigned char *)ui; \
- vivP = (vector unsigned char *)vi; \
+ y1ivP = (const vector unsigned char *)y1i; \
+ y2ivP = (const vector unsigned char *)y2i; \
+ uivP = (const vector unsigned char *)ui; \
+ vivP = (const vector unsigned char *)vi; \
\
align_perm = vec_lvsl (0, y1i); \
y0 = (vector unsigned char) \
@@ -720,7 +721,7 @@ ff_yuv2packedX_altivec(SwsContext *c, const int16_t *lumFilter,
static int printed_error_message;
if (!printed_error_message) {
av_log(c, AV_LOG_ERROR, "altivec_yuv2packedX doesn't support %s output\n",
- sws_format_name(c->dstFormat));
+ av_get_pix_fmt_name(c->dstFormat));
printed_error_message=1;
}
return;
@@ -795,7 +796,7 @@ ff_yuv2packedX_altivec(SwsContext *c, const int16_t *lumFilter,
default:
/* Unreachable, I think. */
av_log(c, AV_LOG_ERROR, "altivec_yuv2packedX doesn't support %s output\n",
- sws_format_name(c->dstFormat));
+ av_get_pix_fmt_name(c->dstFormat));
return;
}
diff --git a/libswscale/ppc/yuv2rgb_altivec.h b/libswscale/ppc/yuv2rgb_altivec.h
index b809fe13fe..163eba6eb7 100644
--- a/libswscale/ppc/yuv2rgb_altivec.h
+++ b/libswscale/ppc/yuv2rgb_altivec.h
@@ -4,20 +4,20 @@
* Copyright (C) 2004 Romain Dolbeau <romain@dolbeau.org>
* based on the equivalent C code in swscale.c
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libswscale/ppc/yuv2yuv_altivec.c b/libswscale/ppc/yuv2yuv_altivec.c
index 4cd02ffe1d..82c265afd2 100644
--- a/libswscale/ppc/yuv2yuv_altivec.c
+++ b/libswscale/ppc/yuv2yuv_altivec.c
@@ -4,20 +4,20 @@
* Copyright (C) 2004 Romain Dolbeau <romain@dolbeau.org>
* based on the equivalent C code in swscale.c
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libswscale/rgb2rgb.c b/libswscale/rgb2rgb.c
index 51cb600e6b..9a7f698935 100644
--- a/libswscale/rgb2rgb.c
+++ b/libswscale/rgb2rgb.c
@@ -6,20 +6,20 @@
* Written by Nick Kurshev.
* palette & YUV & runtime CPU stuff by Michael (michaelni@gmx.at)
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <inttypes.h>
diff --git a/libswscale/rgb2rgb.h b/libswscale/rgb2rgb.h
index 9d051de4f6..e3edac88d4 100644
--- a/libswscale/rgb2rgb.h
+++ b/libswscale/rgb2rgb.h
@@ -6,20 +6,20 @@
* Written by Nick Kurshev.
* YUV & runtime CPU stuff by Michael (michaelni@gmx.at)
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libswscale/rgb2rgb_template.c b/libswscale/rgb2rgb_template.c
index c02015e5b3..0734e8891b 100644
--- a/libswscale/rgb2rgb_template.c
+++ b/libswscale/rgb2rgb_template.c
@@ -7,20 +7,20 @@
* palette & YUV & runtime CPU stuff by Michael (michaelni@gmx.at)
* lot of big-endian byte order fixes by Alex Beregszaszi
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -658,6 +658,9 @@ void rgb24toyv12_c(const uint8_t *src, uint8_t *ydst, uint8_t *udst,
ydst += lumStride;
src += srcStride;
+ if(y+1 == height)
+ break;
+
for (i=0; i<chromWidth; i++) {
unsigned int b = src[6*i+0];
unsigned int g = src[6*i+1];
diff --git a/libswscale/sparc/yuv2rgb_vis.c b/libswscale/sparc/yuv2rgb_vis.c
index 2111ea8f64..cc98f04053 100644
--- a/libswscale/sparc/yuv2rgb_vis.c
+++ b/libswscale/sparc/yuv2rgb_vis.c
@@ -2,20 +2,20 @@
* VIS optimized software YUV to RGB converter
* Copyright (c) 2007 Denes Balatoni <dbalatoni@programozo.hu>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libswscale/swscale-test.c b/libswscale/swscale-test.c
index b5cf1d202e..888cbab26a 100644
--- a/libswscale/swscale-test.c
+++ b/libswscale/swscale-test.c
@@ -1,20 +1,20 @@
/*
* Copyright (C) 2003 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libswscale/swscale.c b/libswscale/swscale.c
index 14807fdc46..29b7b4c212 100644
--- a/libswscale/swscale.c
+++ b/libswscale/swscale.c
@@ -1,20 +1,20 @@
/*
* Copyright (C) 2001-2003 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -60,6 +60,7 @@ untested special converters
#include "swscale.h"
#include "swscale_internal.h"
#include "rgb2rgb.h"
+#include "libavutil/avassert.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/cpu.h"
#include "libavutil/avutil.h"
@@ -67,7 +68,6 @@ untested special converters
#include "libavutil/bswap.h"
#include "libavutil/pixdesc.h"
-#define DITHER1XBPP
#define RGB2YUV_SHIFT 15
#define BY ( (int)(0.114*219/255*(1<<RGB2YUV_SHIFT)+0.5))
@@ -182,6 +182,113 @@ DECLARE_ALIGNED(8, const uint8_t, dither_8x8_220)[8][8]={
{ 77, 23, 60, 15, 72, 21, 56, 14, },
};
#endif
+DECLARE_ALIGNED(8, const uint8_t, dither_8x8_128)[8][8] = {
+{ 36, 68, 60, 92, 34, 66, 58, 90,},
+{ 100, 4,124, 28, 98, 2,122, 26,},
+{ 52, 84, 44, 76, 50, 82, 42, 74,},
+{ 116, 20,108, 12,114, 18,106, 10,},
+{ 32, 64, 56, 88, 38, 70, 62, 94,},
+{ 96, 0,120, 24,102, 6,126, 30,},
+{ 48, 80, 40, 72, 54, 86, 46, 78,},
+{ 112, 16,104, 8,118, 22,110, 14,},
+};
+DECLARE_ALIGNED(8, const uint8_t, ff_sws_pb_64)[8] =
+{ 64, 64, 64, 64, 64, 64, 64, 64 };
+
+DECLARE_ALIGNED(8, const uint8_t, dithers)[8][8][8]={
+{
+ { 0, 1, 0, 1, 0, 1, 0, 1,},
+ { 1, 0, 1, 0, 1, 0, 1, 0,},
+ { 0, 1, 0, 1, 0, 1, 0, 1,},
+ { 1, 0, 1, 0, 1, 0, 1, 0,},
+ { 0, 1, 0, 1, 0, 1, 0, 1,},
+ { 1, 0, 1, 0, 1, 0, 1, 0,},
+ { 0, 1, 0, 1, 0, 1, 0, 1,},
+ { 1, 0, 1, 0, 1, 0, 1, 0,},
+},{
+ { 1, 2, 1, 2, 1, 2, 1, 2,},
+ { 3, 0, 3, 0, 3, 0, 3, 0,},
+ { 1, 2, 1, 2, 1, 2, 1, 2,},
+ { 3, 0, 3, 0, 3, 0, 3, 0,},
+ { 1, 2, 1, 2, 1, 2, 1, 2,},
+ { 3, 0, 3, 0, 3, 0, 3, 0,},
+ { 1, 2, 1, 2, 1, 2, 1, 2,},
+ { 3, 0, 3, 0, 3, 0, 3, 0,},
+},{
+ { 2, 4, 3, 5, 2, 4, 3, 5,},
+ { 6, 0, 7, 1, 6, 0, 7, 1,},
+ { 3, 5, 2, 4, 3, 5, 2, 4,},
+ { 7, 1, 6, 0, 7, 1, 6, 0,},
+ { 2, 4, 3, 5, 2, 4, 3, 5,},
+ { 6, 0, 7, 1, 6, 0, 7, 1,},
+ { 3, 5, 2, 4, 3, 5, 2, 4,},
+ { 7, 1, 6, 0, 7, 1, 6, 0,},
+},{
+ { 4, 8, 7, 11, 4, 8, 7, 11,},
+ { 12, 0, 15, 3, 12, 0, 15, 3,},
+ { 6, 10, 5, 9, 6, 10, 5, 9,},
+ { 14, 2, 13, 1, 14, 2, 13, 1,},
+ { 4, 8, 7, 11, 4, 8, 7, 11,},
+ { 12, 0, 15, 3, 12, 0, 15, 3,},
+ { 6, 10, 5, 9, 6, 10, 5, 9,},
+ { 14, 2, 13, 1, 14, 2, 13, 1,},
+},{
+ { 9, 17, 15, 23, 8, 16, 14, 22,},
+ { 25, 1, 31, 7, 24, 0, 30, 6,},
+ { 13, 21, 11, 19, 12, 20, 10, 18,},
+ { 29, 5, 27, 3, 28, 4, 26, 2,},
+ { 8, 16, 14, 22, 9, 17, 15, 23,},
+ { 24, 0, 30, 6, 25, 1, 31, 7,},
+ { 12, 20, 10, 18, 13, 21, 11, 19,},
+ { 28, 4, 26, 2, 29, 5, 27, 3,},
+},{
+ { 18, 34, 30, 46, 17, 33, 29, 45,},
+ { 50, 2, 62, 14, 49, 1, 61, 13,},
+ { 26, 42, 22, 38, 25, 41, 21, 37,},
+ { 58, 10, 54, 6, 57, 9, 53, 5,},
+ { 16, 32, 28, 44, 19, 35, 31, 47,},
+ { 48, 0, 60, 12, 51, 3, 63, 15,},
+ { 24, 40, 20, 36, 27, 43, 23, 39,},
+ { 56, 8, 52, 4, 59, 11, 55, 7,},
+},{
+ { 18, 34, 30, 46, 17, 33, 29, 45,},
+ { 50, 2, 62, 14, 49, 1, 61, 13,},
+ { 26, 42, 22, 38, 25, 41, 21, 37,},
+ { 58, 10, 54, 6, 57, 9, 53, 5,},
+ { 16, 32, 28, 44, 19, 35, 31, 47,},
+ { 48, 0, 60, 12, 51, 3, 63, 15,},
+ { 24, 40, 20, 36, 27, 43, 23, 39,},
+ { 56, 8, 52, 4, 59, 11, 55, 7,},
+},{
+ { 36, 68, 60, 92, 34, 66, 58, 90,},
+ { 100, 4,124, 28, 98, 2,122, 26,},
+ { 52, 84, 44, 76, 50, 82, 42, 74,},
+ { 116, 20,108, 12,114, 18,106, 10,},
+ { 32, 64, 56, 88, 38, 70, 62, 94,},
+ { 96, 0,120, 24,102, 6,126, 30,},
+ { 48, 80, 40, 72, 54, 86, 46, 78,},
+ { 112, 16,104, 8,118, 22,110, 14,},
+}};
+
+static const uint8_t flat64[8]={64,64,64,64,64,64,64,64};
+
+const uint16_t dither_scale[15][16]={
+{ 2, 3, 3, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,},
+{ 2, 3, 7, 7, 13, 13, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,},
+{ 3, 3, 4, 15, 15, 29, 57, 57, 57, 113, 113, 113, 113, 113, 113, 113,},
+{ 3, 4, 4, 5, 31, 31, 61, 121, 241, 241, 241, 241, 481, 481, 481, 481,},
+{ 3, 4, 5, 5, 6, 63, 63, 125, 249, 497, 993, 993, 993, 993, 993, 1985,},
+{ 3, 5, 6, 6, 6, 7, 127, 127, 253, 505, 1009, 2017, 4033, 4033, 4033, 4033,},
+{ 3, 5, 6, 7, 7, 7, 8, 255, 255, 509, 1017, 2033, 4065, 8129,16257,16257,},
+{ 3, 5, 6, 8, 8, 8, 8, 9, 511, 511, 1021, 2041, 4081, 8161,16321,32641,},
+{ 3, 5, 7, 8, 9, 9, 9, 9, 10, 1023, 1023, 2045, 4089, 8177,16353,32705,},
+{ 3, 5, 7, 8, 10, 10, 10, 10, 10, 11, 2047, 2047, 4093, 8185,16369,32737,},
+{ 3, 5, 7, 8, 10, 11, 11, 11, 11, 11, 12, 4095, 4095, 8189,16377,32753,},
+{ 3, 5, 7, 9, 10, 12, 12, 12, 12, 12, 12, 13, 8191, 8191,16381,32761,},
+{ 3, 5, 7, 9, 10, 12, 13, 13, 13, 13, 13, 13, 14,16383,16383,32765,},
+{ 3, 5, 7, 9, 10, 12, 14, 14, 14, 14, 14, 14, 14, 15,32767,32767,},
+{ 3, 5, 7, 9, 11, 12, 14, 15, 15, 15, 15, 15, 15, 15, 16,65535,},
+};
static av_always_inline void
yuv2yuvX16_c_template(const int16_t *lumFilter, const int32_t **lumSrc,
@@ -193,26 +300,79 @@ yuv2yuvX16_c_template(const int16_t *lumFilter, const int32_t **lumSrc,
{
//FIXME Optimize (just quickly written not optimized..)
int i;
+ int dword= output_bits == 16;
uint16_t *yDest = dest[0], *uDest = dest[1], *vDest = dest[2],
*aDest = CONFIG_SWSCALE_ALPHA ? dest[3] : NULL;
- int shift = 15 + 16 - output_bits;
+ int shift = 11 + 4*dword + 16 - output_bits - 1;
#define output_pixel(pos, val) \
if (big_endian) { \
- if (output_bits == 16) { \
- AV_WB16(pos, av_clip_uint16(val >> shift)); \
- } else { \
- AV_WB16(pos, av_clip_uintp2(val >> shift, output_bits)); \
- } \
+ AV_WB16(pos, av_clip_uint16(val >> shift)); \
} else { \
- if (output_bits == 16) { \
- AV_WL16(pos, av_clip_uint16(val >> shift)); \
- } else { \
- AV_WL16(pos, av_clip_uintp2(val >> shift, output_bits)); \
- } \
+ AV_WL16(pos, av_clip_uint16(val >> shift)); \
+ }
+ for (i = 0; i < dstW; i++) {
+ int val = 1 << (26-output_bits + 4*dword - 1);
+ int j;
+
+ for (j = 0; j < lumFilterSize; j++)
+ val += ((dword ? lumSrc[j][i] : ((int16_t**)lumSrc)[j][i]) * lumFilter[j])>>1;
+
+ output_pixel(&yDest[i], val);
+ }
+
+ if (uDest) {
+ for (i = 0; i < chrDstW; i++) {
+ int u = 1 << (26-output_bits + 4*dword - 1);
+ int v = 1 << (26-output_bits + 4*dword - 1);
+ int j;
+
+ for (j = 0; j < chrFilterSize; j++) {
+ u += ((dword ? chrUSrc[j][i] : ((int16_t**)chrUSrc)[j][i]) * chrFilter[j]) >> 1;
+ v += ((dword ? chrVSrc[j][i] : ((int16_t**)chrVSrc)[j][i]) * chrFilter[j]) >> 1;
+ }
+
+ output_pixel(&uDest[i], u);
+ output_pixel(&vDest[i], v);
+ }
+ }
+
+ if (CONFIG_SWSCALE_ALPHA && aDest) {
+ for (i = 0; i < dstW; i++) {
+ int val = 1 << (26-output_bits + 4*dword - 1);
+ int j;
+
+ for (j = 0; j < lumFilterSize; j++)
+ val += ((dword ? alpSrc[j][i] : ((int16_t**)alpSrc)[j][i]) * lumFilter[j]) >> 1;
+
+ output_pixel(&aDest[i], val);
+ }
+ }
+#undef output_pixel
+}
+
+static av_always_inline void
+yuv2yuvX10_c_template(const int16_t *lumFilter, const int16_t **lumSrc,
+ int lumFilterSize, const int16_t *chrFilter,
+ const int16_t **chrUSrc, const int16_t **chrVSrc,
+ int chrFilterSize, const int16_t **alpSrc,
+ uint16_t *dest[4], int dstW, int chrDstW,
+ int big_endian, int output_bits)
+{
+ //FIXME Optimize (just quickly written not optimized..)
+ int i;
+ uint16_t *yDest = dest[0], *uDest = dest[1], *vDest = dest[2],
+ *aDest = CONFIG_SWSCALE_ALPHA ? dest[3] : NULL;
+ int shift = 11 + 16 - output_bits;
+
+#define output_pixel(pos, val) \
+ if (big_endian) { \
+ AV_WB16(pos, av_clip_uintp2(val >> shift, output_bits)); \
+ } else { \
+ AV_WL16(pos, av_clip_uintp2(val >> shift, output_bits)); \
}
for (i = 0; i < dstW; i++) {
- int val = 1 << (30-output_bits);
+ int val = 1 << (26-output_bits);
int j;
for (j = 0; j < lumFilterSize; j++)
@@ -223,8 +383,8 @@ yuv2yuvX16_c_template(const int16_t *lumFilter, const int32_t **lumSrc,
if (uDest) {
for (i = 0; i < chrDstW; i++) {
- int u = 1 << (30-output_bits);
- int v = 1 << (30-output_bits);
+ int u = 1 << (26-output_bits);
+ int v = 1 << (26-output_bits);
int j;
for (j = 0; j < chrFilterSize; j++) {
@@ -239,7 +399,7 @@ yuv2yuvX16_c_template(const int16_t *lumFilter, const int32_t **lumSrc,
if (CONFIG_SWSCALE_ALPHA && aDest) {
for (i = 0; i < dstW; i++) {
- int val = 1 << (30-output_bits);
+ int val = 1 << (26-output_bits);
int j;
for (j = 0; j < lumFilterSize; j++)
@@ -251,7 +411,7 @@ yuv2yuvX16_c_template(const int16_t *lumFilter, const int32_t **lumSrc,
#undef output_pixel
}
-#define yuv2NBPS(bits, BE_LE, is_be) \
+#define yuv2NBPS(bits, BE_LE, is_be, yuv2yuvX_template_fn, typeX_t) \
static void yuv2yuvX ## bits ## BE_LE ## _c(SwsContext *c, const int16_t *lumFilter, \
const int16_t **_lumSrc, int lumFilterSize, \
const int16_t *chrFilter, const int16_t **_chrUSrc, \
@@ -259,21 +419,21 @@ static void yuv2yuvX ## bits ## BE_LE ## _c(SwsContext *c, const int16_t *lumFil
int chrFilterSize, const int16_t **_alpSrc, \
uint8_t *_dest[4], int dstW, int chrDstW) \
{ \
- const int32_t **lumSrc = (const int32_t **) _lumSrc, \
- **chrUSrc = (const int32_t **) _chrUSrc, \
- **chrVSrc = (const int32_t **) _chrVSrc, \
- **alpSrc = (const int32_t **) _alpSrc; \
- yuv2yuvX16_c_template(lumFilter, lumSrc, lumFilterSize, \
- chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
- alpSrc, (uint16_t **) _dest, \
- dstW, chrDstW, is_be, bits); \
-}
-yuv2NBPS( 9, BE, 1);
-yuv2NBPS( 9, LE, 0);
-yuv2NBPS(10, BE, 1);
-yuv2NBPS(10, LE, 0);
-yuv2NBPS(16, BE, 1);
-yuv2NBPS(16, LE, 0);
+ const typeX_t **lumSrc = (const typeX_t **) _lumSrc, \
+ **chrUSrc = (const typeX_t **) _chrUSrc, \
+ **chrVSrc = (const typeX_t **) _chrVSrc, \
+ **alpSrc = (const typeX_t **) _alpSrc; \
+ yuv2yuvX_template_fn(lumFilter, lumSrc, lumFilterSize, \
+ chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
+ alpSrc, (uint16_t **) _dest, \
+ dstW, chrDstW, is_be, bits); \
+}
+yuv2NBPS( 9, BE, 1, yuv2yuvX10_c_template, int16_t);
+yuv2NBPS( 9, LE, 0, yuv2yuvX10_c_template, int16_t);
+yuv2NBPS(10, BE, 1, yuv2yuvX10_c_template, int16_t);
+yuv2NBPS(10, LE, 0, yuv2yuvX10_c_template, int16_t);
+yuv2NBPS(16, BE, 1, yuv2yuvX16_c_template, int32_t);
+yuv2NBPS(16, LE, 0, yuv2yuvX16_c_template, int32_t);
static void yuv2yuvX_c(SwsContext *c, const int16_t *lumFilter,
const int16_t **lumSrc, int lumFilterSize,
@@ -285,10 +445,11 @@ static void yuv2yuvX_c(SwsContext *c, const int16_t *lumFilter,
uint8_t *yDest = dest[0], *uDest = dest[1], *vDest = dest[2],
*aDest = CONFIG_SWSCALE_ALPHA ? dest[3] : NULL;
int i;
+ const uint8_t *lumDither = c->lumDither8, *chrDither = c->chrDither8;
//FIXME Optimize (just quickly written not optimized..)
for (i=0; i<dstW; i++) {
- int val=1<<18;
+ int val = lumDither[i & 7] << 12;
int j;
for (j=0; j<lumFilterSize; j++)
val += lumSrc[j][i] * lumFilter[j];
@@ -298,8 +459,8 @@ static void yuv2yuvX_c(SwsContext *c, const int16_t *lumFilter,
if (uDest)
for (i=0; i<chrDstW; i++) {
- int u=1<<18;
- int v=1<<18;
+ int u = chrDither[i & 7] << 12;
+ int v = chrDither[(i + 3) & 7] << 12;
int j;
for (j=0; j<chrFilterSize; j++) {
u += chrUSrc[j][i] * chrFilter[j];
@@ -312,7 +473,7 @@ static void yuv2yuvX_c(SwsContext *c, const int16_t *lumFilter,
if (CONFIG_SWSCALE_ALPHA && aDest)
for (i=0; i<dstW; i++) {
- int val=1<<18;
+ int val = lumDither[i & 7] << 12;
int j;
for (j=0; j<lumFilterSize; j++)
val += alpSrc[j][i] * lumFilter[j];
@@ -329,23 +490,24 @@ static void yuv2yuv1_c(SwsContext *c, const int16_t *lumSrc,
uint8_t *yDest = dest[0], *uDest = dest[1], *vDest = dest[2],
*aDest = CONFIG_SWSCALE_ALPHA ? dest[3] : NULL;
int i;
+ const uint8_t *lumDither = c->lumDither8, *chrDither = c->chrDither8;
for (i=0; i<dstW; i++) {
- int val= (lumSrc[i]+64)>>7;
+ int val = (lumSrc[i]+ lumDither[i & 7]) >> 7;
yDest[i]= av_clip_uint8(val);
}
if (uDest)
for (i=0; i<chrDstW; i++) {
- int u=(chrUSrc[i]+64)>>7;
- int v=(chrVSrc[i]+64)>>7;
+ int u = (chrUSrc[i] + chrDither[i & 7]) >> 7;
+ int v = (chrVSrc[i] + chrDither[(i + 3) & 7]) >> 7;
uDest[i]= av_clip_uint8(u);
vDest[i]= av_clip_uint8(v);
}
if (CONFIG_SWSCALE_ALPHA && aDest)
for (i=0; i<dstW; i++) {
- int val= (alpSrc[i]+64)>>7;
+ int val = (alpSrc[i] + lumDither[i & 7]) >> 7;
aDest[i]= av_clip_uint8(val);
}
}
@@ -359,11 +521,12 @@ static void yuv2nv12X_c(SwsContext *c, const int16_t *lumFilter,
{
uint8_t *yDest = dest[0], *uDest = dest[1];
enum PixelFormat dstFormat = c->dstFormat;
+ const uint8_t *lumDither = c->lumDither8, *chrDither = c->chrDither8;
//FIXME Optimize (just quickly written not optimized..)
int i;
for (i=0; i<dstW; i++) {
- int val=1<<18;
+ int val = lumDither[i & 7] << 12;
int j;
for (j=0; j<lumFilterSize; j++)
val += lumSrc[j][i] * lumFilter[j];
@@ -376,8 +539,8 @@ static void yuv2nv12X_c(SwsContext *c, const int16_t *lumFilter,
if (dstFormat == PIX_FMT_NV12)
for (i=0; i<chrDstW; i++) {
- int u=1<<18;
- int v=1<<18;
+ int u = chrDither[i & 7] << 12;
+ int v = chrDither[(i + 3) & 7] << 12;
int j;
for (j=0; j<chrFilterSize; j++) {
u += chrUSrc[j][i] * chrFilter[j];
@@ -389,8 +552,8 @@ static void yuv2nv12X_c(SwsContext *c, const int16_t *lumFilter,
}
else
for (i=0; i<chrDstW; i++) {
- int u=1<<18;
- int v=1<<18;
+ int u = chrDither[i & 7] << 12;
+ int v = chrDither[(i + 3) & 7] << 12;
int j;
for (j=0; j<chrFilterSize; j++) {
u += chrUSrc[j][i] * chrFilter[j];
@@ -468,8 +631,8 @@ yuv2gray16_1_c_template(SwsContext *c, const int32_t *buf0,
int i;
for (i = 0; i < (dstW >> 1); i++) {
- int Y1 = buf0[i * 2 ] << 1;
- int Y2 = buf0[i * 2 + 1] << 1;
+ int Y1 = (buf0[i * 2 ]+4)>>3;
+ int Y2 = (buf0[i * 2 + 1]+4)>>3;
output_pixel(&dest[i * 2 + 0], Y1);
output_pixel(&dest[i * 2 + 1], Y2);
@@ -917,8 +1080,8 @@ yuv2rgb48_1_c_template(SwsContext *c, const int32_t *buf0,
for (i = 0; i < (dstW >> 1); i++) {
int Y1 = (buf0[i * 2] ) >> 2;
int Y2 = (buf0[i * 2 + 1]) >> 2;
- int U = (ubuf0[i] + ubuf1[i] + (-128 << 11)) >> 3;
- int V = (vbuf0[i] + vbuf1[i] + (-128 << 11)) >> 3;
+ int U = (ubuf0[i] + ubuf1[i] + (-128 << 12)) >> 3;
+ int V = (vbuf0[i] + vbuf1[i] + (-128 << 12)) >> 3;
int R, G, B;
Y1 -= c->yuv2rgb_y_offset;
@@ -989,6 +1152,7 @@ yuv2rgb_write(uint8_t *_dest, int i, int Y1, int Y2,
#define r_b ((target == PIX_FMT_RGB24) ? r : b)
#define b_r ((target == PIX_FMT_RGB24) ? b : r)
+
dest[i * 6 + 0] = r_b[Y1];
dest[i * 6 + 1] = g[Y1];
dest[i * 6 + 2] = b_r[Y1];
@@ -1136,7 +1300,8 @@ yuv2rgb_2_c_template(SwsContext *c, const int16_t *buf[2],
const int16_t *buf0 = buf[0], *buf1 = buf[1],
*ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
*vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
- *abuf0 = abuf[0], *abuf1 = abuf[1];
+ *abuf0 = hasAlpha ? abuf[0] : NULL,
+ *abuf1 = hasAlpha ? abuf[1] : NULL;
int yalpha1 = 4095 - yalpha;
int uvalpha1 = 4095 - uvalpha;
int i;
@@ -1278,9 +1443,9 @@ yuv2rgb_full_X_c_template(SwsContext *c, const int16_t *lumFilter,
for (i = 0; i < dstW; i++) {
int j;
- int Y = 0;
- int U = -128 << 19;
- int V = -128 << 19;
+ int Y = 1<<9;
+ int U = (1<<9)-(128 << 19);
+ int V = (1<<9)-(128 << 19);
int av_unused A;
int R, G, B;
@@ -1295,7 +1460,7 @@ yuv2rgb_full_X_c_template(SwsContext *c, const int16_t *lumFilter,
U >>= 10;
V >>= 10;
if (hasAlpha) {
- A = 1 << 21;
+ A = 1 << 18;
for (j = 0; j < lumFilterSize; j++) {
A += alpSrc[j][i] * lumFilter[j];
}
@@ -1338,7 +1503,6 @@ yuv2rgb_full_X_c_template(SwsContext *c, const int16_t *lumFilter,
dest[1] = B >> 22;
dest[2] = G >> 22;
dest[3] = R >> 22;
- dest += 4;
break;
case PIX_FMT_BGR24:
dest[0] = B >> 22;
@@ -1446,7 +1610,7 @@ rgb48ToUV_half_c_template(uint16_t *dstU, uint16_t *dstV,
#undef input_pixel
#define rgb48funcs(pattern, BE_LE, origin) \
-static void pattern ## 48 ## BE_LE ## ToY_c(uint8_t *_dst, const uint8_t *_src, \
+static void pattern ## 48 ## BE_LE ## ToY_c(uint8_t *_dst, const uint8_t *_src, const uint8_t *unused0, const uint8_t *unused1,\
int width, uint32_t *unused) \
{ \
const uint16_t *src = (const uint16_t *) _src; \
@@ -1455,7 +1619,7 @@ static void pattern ## 48 ## BE_LE ## ToY_c(uint8_t *_dst, const uint8_t *_src,
} \
\
static void pattern ## 48 ## BE_LE ## ToUV_c(uint8_t *_dstU, uint8_t *_dstV, \
- const uint8_t *_src1, const uint8_t *_src2, \
+ const uint8_t *unused0, const uint8_t *_src1, const uint8_t *_src2, \
int width, uint32_t *unused) \
{ \
const uint16_t *src1 = (const uint16_t *) _src1, \
@@ -1465,7 +1629,7 @@ static void pattern ## 48 ## BE_LE ## ToUV_c(uint8_t *_dstU, uint8_t *_dstV, \
} \
\
static void pattern ## 48 ## BE_LE ## ToUV_half_c(uint8_t *_dstU, uint8_t *_dstV, \
- const uint8_t *_src1, const uint8_t *_src2, \
+ const uint8_t *unused0, const uint8_t *_src1, const uint8_t *_src2, \
int width, uint32_t *unused) \
{ \
const uint16_t *src1 = (const uint16_t *) _src1, \
@@ -1484,14 +1648,14 @@ rgb48funcs(bgr, BE, PIX_FMT_BGR48BE);
(isBE(origin) ? AV_RB16(&src[(i)*2]) : AV_RL16(&src[(i)*2])))
static av_always_inline void
-rgb16_32ToY_c_template(uint8_t *dst, const uint8_t *src,
+rgb16_32ToY_c_template(int16_t *dst, const uint8_t *src,
int width, enum PixelFormat origin,
int shr, int shg, int shb, int shp,
int maskr, int maskg, int maskb,
int rsh, int gsh, int bsh, int S)
{
const int ry = RY << rsh, gy = GY << gsh, by = BY << bsh,
- rnd = 33 << (S - 1);
+ rnd = (32<<((S)-1)) + (1<<(S-7));
int i;
for (i = 0; i < width; i++) {
@@ -1500,12 +1664,12 @@ rgb16_32ToY_c_template(uint8_t *dst, const uint8_t *src,
int g = (px & maskg) >> shg;
int r = (px & maskr) >> shr;
- dst[i] = (ry * r + gy * g + by * b + rnd) >> S;
+ dst[i] = (ry * r + gy * g + by * b + rnd) >> ((S)-6);
}
}
static av_always_inline void
-rgb16_32ToUV_c_template(uint8_t *dstU, uint8_t *dstV,
+rgb16_32ToUV_c_template(int16_t *dstU, int16_t *dstV,
const uint8_t *src, int width,
enum PixelFormat origin,
int shr, int shg, int shb, int shp,
@@ -1514,7 +1678,7 @@ rgb16_32ToUV_c_template(uint8_t *dstU, uint8_t *dstV,
{
const int ru = RU << rsh, gu = GU << gsh, bu = BU << bsh,
rv = RV << rsh, gv = GV << gsh, bv = BV << bsh,
- rnd = 257 << (S - 1);
+ rnd = (256<<((S)-1)) + (1<<(S-7));
int i;
for (i = 0; i < width; i++) {
@@ -1523,13 +1687,13 @@ rgb16_32ToUV_c_template(uint8_t *dstU, uint8_t *dstV,
int g = (px & maskg) >> shg;
int r = (px & maskr) >> shr;
- dstU[i] = (ru * r + gu * g + bu * b + rnd) >> S;
- dstV[i] = (rv * r + gv * g + bv * b + rnd) >> S;
+ dstU[i] = (ru * r + gu * g + bu * b + rnd) >> ((S)-6);
+ dstV[i] = (rv * r + gv * g + bv * b + rnd) >> ((S)-6);
}
}
static av_always_inline void
-rgb16_32ToUV_half_c_template(uint8_t *dstU, uint8_t *dstV,
+rgb16_32ToUV_half_c_template(int16_t *dstU, int16_t *dstV,
const uint8_t *src, int width,
enum PixelFormat origin,
int shr, int shg, int shb, int shp,
@@ -1538,7 +1702,7 @@ rgb16_32ToUV_half_c_template(uint8_t *dstU, uint8_t *dstV,
{
const int ru = RU << rsh, gu = GU << gsh, bu = BU << bsh,
rv = RV << rsh, gv = GV << gsh, bv = BV << bsh,
- rnd = 257 << S, maskgx = ~(maskr | maskb);
+ rnd = (256U<<(S)) + (1<<(S-6)), maskgx = ~(maskr | maskb);
int i;
maskr |= maskr << 1; maskb |= maskb << 1; maskg |= maskg << 1;
@@ -1557,8 +1721,8 @@ rgb16_32ToUV_half_c_template(uint8_t *dstU, uint8_t *dstV,
}
r = (rb & maskr) >> shr;
- dstU[i] = (ru * r + gu * g + bu * b + rnd) >> (S + 1);
- dstV[i] = (rv * r + gv * g + bv * b + rnd) >> (S + 1);
+ dstU[i] = (ru * r + gu * g + bu * b + (unsigned)rnd) >> ((S)-6+1);
+ dstV[i] = (rv * r + gv * g + bv * b + (unsigned)rnd) >> ((S)-6+1);
}
}
@@ -1566,26 +1730,29 @@ rgb16_32ToUV_half_c_template(uint8_t *dstU, uint8_t *dstV,
#define rgb16_32_wrapper(fmt, name, shr, shg, shb, shp, maskr, \
maskg, maskb, rsh, gsh, bsh, S) \
-static void name ## ToY_c(uint8_t *dst, const uint8_t *src, \
+static void name ## ToY_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, \
int width, uint32_t *unused) \
{ \
- rgb16_32ToY_c_template(dst, src, width, fmt, shr, shg, shb, shp, \
+ rgb16_32ToY_c_template((int16_t*)dst, src, width, fmt, \
+ shr, shg, shb, shp, \
maskr, maskg, maskb, rsh, gsh, bsh, S); \
} \
\
static void name ## ToUV_c(uint8_t *dstU, uint8_t *dstV, \
- const uint8_t *src, const uint8_t *dummy, \
+ const uint8_t *unused0, const uint8_t *src, const uint8_t *dummy, \
int width, uint32_t *unused) \
{ \
- rgb16_32ToUV_c_template(dstU, dstV, src, width, fmt, shr, shg, shb, shp, \
+ rgb16_32ToUV_c_template((int16_t*)dstU, (int16_t*)dstV, src, width, fmt, \
+ shr, shg, shb, shp, \
maskr, maskg, maskb, rsh, gsh, bsh, S); \
} \
\
static void name ## ToUV_half_c(uint8_t *dstU, uint8_t *dstV, \
- const uint8_t *src, const uint8_t *dummy, \
+ const uint8_t *unused0, const uint8_t *src, const uint8_t *dummy, \
int width, uint32_t *unused) \
{ \
- rgb16_32ToUV_half_c_template(dstU, dstV, src, width, fmt, shr, shg, shb, shp, \
+ rgb16_32ToUV_half_c_template((int16_t*)dstU, (int16_t*)dstV, src, width, fmt, \
+ shr, shg, shb, shp, \
maskr, maskg, maskb, rsh, gsh, bsh, S); \
}
@@ -1602,71 +1769,132 @@ rgb16_32_wrapper(PIX_FMT_BGR555BE, bgr15be, 0, 0, 0, 0, 0x001F, 0x03E0, 0x7
rgb16_32_wrapper(PIX_FMT_RGB565BE, rgb16be, 0, 0, 0, 0, 0xF800, 0x07E0, 0x001F, 0, 5, 11, RGB2YUV_SHIFT+8);
rgb16_32_wrapper(PIX_FMT_RGB555BE, rgb15be, 0, 0, 0, 0, 0x7C00, 0x03E0, 0x001F, 0, 5, 10, RGB2YUV_SHIFT+7);
-static void abgrToA_c(uint8_t *dst, const uint8_t *src, int width, uint32_t *unused)
+static void gbr24pToY_c(uint16_t *dst, const uint8_t *gsrc, const uint8_t *bsrc, const uint8_t *rsrc,
+ int width, uint32_t *unused)
+{
+ int i;
+ for (i = 0; i < width; i++) {
+ unsigned int g = gsrc[i];
+ unsigned int b = bsrc[i];
+ unsigned int r = rsrc[i];
+
+ dst[i] = (RY*r + GY*g + BY*b + (0x801<<(RGB2YUV_SHIFT-7))) >> (RGB2YUV_SHIFT-6);
+ }
+}
+
+static void gbr24pToUV_c(uint16_t *dstU, uint16_t *dstV,
+ const uint8_t *gsrc, const uint8_t *bsrc, const uint8_t *rsrc,
+ int width, enum PixelFormat origin)
+{
+ int i;
+ for (i = 0; i < width; i++) {
+ unsigned int g = gsrc[i];
+ unsigned int b = bsrc[i];
+ unsigned int r = rsrc[i];
+
+ dstU[i] = (RU*r + GU*g + BU*b + (0x4001<<(RGB2YUV_SHIFT-7))) >> (RGB2YUV_SHIFT-6);
+ dstV[i] = (RV*r + GV*g + BV*b + (0x4001<<(RGB2YUV_SHIFT-7))) >> (RGB2YUV_SHIFT-6);
+ }
+}
+
+static void gbr24pToUV_half_c(uint16_t *dstU, uint16_t *dstV,
+ const uint8_t *gsrc, const uint8_t *bsrc, const uint8_t *rsrc,
+ int width, enum PixelFormat origin)
+{
+ int i;
+ for (i = 0; i < width; i++) {
+ unsigned int g = gsrc[2*i] + gsrc[2*i+1];
+ unsigned int b = bsrc[2*i] + bsrc[2*i+1];
+ unsigned int r = rsrc[2*i] + rsrc[2*i+1];
+
+ dstU[i] = (RU*r + GU*g + BU*b + (0x4001<<(RGB2YUV_SHIFT-6))) >> (RGB2YUV_SHIFT-6+1);
+ dstV[i] = (RV*r + GV*g + BV*b + (0x4001<<(RGB2YUV_SHIFT-6))) >> (RGB2YUV_SHIFT-6+1);
+ }
+}
+
+static void abgrToA_c(int16_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width, uint32_t *unused)
{
int i;
for (i=0; i<width; i++) {
- dst[i]= src[4*i];
+ dst[i]= src[4*i]<<6;
}
}
-static void rgbaToA_c(uint8_t *dst, const uint8_t *src, int width, uint32_t *unused)
+static void rgbaToA_c(int16_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width, uint32_t *unused)
{
int i;
for (i=0; i<width; i++) {
- dst[i]= src[4*i+3];
+ dst[i]= src[4*i+3]<<6;
}
}
-static void palToY_c(uint8_t *dst, const uint8_t *src, int width, uint32_t *pal)
+static void palToA_c(int16_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width, uint32_t *pal)
{
int i;
for (i=0; i<width; i++) {
int d= src[i];
- dst[i]= pal[d] & 0xFF;
+ dst[i]= (pal[d] >> 24)<<6;
}
}
-static void palToUV_c(uint8_t *dstU, uint8_t *dstV,
- const uint8_t *src1, const uint8_t *src2,
- int width, uint32_t *pal)
+static void palToY_c(int16_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, long width, uint32_t *pal)
+{
+ int i;
+ for (i=0; i<width; i++) {
+ int d= src[i];
+
+ dst[i]= (pal[d] & 0xFF)<<6;
+ }
+}
+
+static void palToUV_c(uint16_t *dstU, int16_t *dstV,
+ const uint8_t *unused0, const uint8_t *src1, const uint8_t *src2,
+ int width, uint32_t *pal)
{
int i;
assert(src1 == src2);
for (i=0; i<width; i++) {
int p= pal[src1[i]];
- dstU[i]= p>>8;
- dstV[i]= p>>16;
+ dstU[i]= (uint8_t)(p>> 8)<<6;
+ dstV[i]= (uint8_t)(p>>16)<<6;
}
}
-static void monowhite2Y_c(uint8_t *dst, const uint8_t *src,
- int width, uint32_t *unused)
+static void monowhite2Y_c(int16_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width, uint32_t *unused)
{
int i, j;
for (i=0; i<width/8; i++) {
int d= ~src[i];
for(j=0; j<8; j++)
- dst[8*i+j]= ((d>>(7-j))&1)*255;
+ dst[8*i+j]= ((d>>(7-j))&1)*16383;
+ }
+ if(width&7){
+ int d= ~src[i];
+ for(j=0; j<(width&7); j++)
+ dst[8*i+j]= ((d>>(7-j))&1)*16383;
}
}
-static void monoblack2Y_c(uint8_t *dst, const uint8_t *src,
- int width, uint32_t *unused)
+static void monoblack2Y_c(int16_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width, uint32_t *unused)
{
int i, j;
for (i=0; i<width/8; i++) {
int d= src[i];
for(j=0; j<8; j++)
- dst[8*i+j]= ((d>>(7-j))&1)*255;
+ dst[8*i+j]= ((d>>(7-j))&1)*16383;
+ }
+ if(width&7){
+ int d= src[i];
+ for(j=0; j<(width&7); j++)
+ dst[8*i+j]= ((d>>(7-j))&1)*16383;
}
}
//FIXME yuy2* can read up to 7 samples too much
-static void yuy2ToY_c(uint8_t *dst, const uint8_t *src, int width,
+static void yuy2ToY_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width,
uint32_t *unused)
{
int i;
@@ -1674,7 +1902,7 @@ static void yuy2ToY_c(uint8_t *dst, const uint8_t *src, int width,
dst[i]= src[2*i];
}
-static void yuy2ToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1,
+static void yuy2ToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *unused0, const uint8_t *src1,
const uint8_t *src2, int width, uint32_t *unused)
{
int i;
@@ -1685,7 +1913,7 @@ static void yuy2ToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1,
assert(src1 == src2);
}
-static void bswap16Y_c(uint8_t *_dst, const uint8_t *_src, int width, uint32_t *unused)
+static void bswap16Y_c(uint8_t *_dst, const uint8_t *_src, const uint8_t *unused1, const uint8_t *unused2, int width, uint32_t *unused)
{
int i;
const uint16_t *src = (const uint16_t *) _src;
@@ -1695,7 +1923,7 @@ static void bswap16Y_c(uint8_t *_dst, const uint8_t *_src, int width, uint32_t *
}
}
-static void bswap16UV_c(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *_src1,
+static void bswap16UV_c(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *unused0, const uint8_t *_src1,
const uint8_t *_src2, int width, uint32_t *unused)
{
int i;
@@ -1710,7 +1938,7 @@ static void bswap16UV_c(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *_src1,
/* This is almost identical to the previous, end exists only because
* yuy2ToY/UV)(dst, src+1, ...) would have 100% unaligned accesses. */
-static void uyvyToY_c(uint8_t *dst, const uint8_t *src, int width,
+static void uyvyToY_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width,
uint32_t *unused)
{
int i;
@@ -1718,7 +1946,7 @@ static void uyvyToY_c(uint8_t *dst, const uint8_t *src, int width,
dst[i]= src[2*i+1];
}
-static void uyvyToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1,
+static void uyvyToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *unused0, const uint8_t *src1,
const uint8_t *src2, int width, uint32_t *unused)
{
int i;
@@ -1740,14 +1968,14 @@ static av_always_inline void nvXXtoUV_c(uint8_t *dst1, uint8_t *dst2,
}
static void nv12ToUV_c(uint8_t *dstU, uint8_t *dstV,
- const uint8_t *src1, const uint8_t *src2,
+ const uint8_t *unused0, const uint8_t *src1, const uint8_t *src2,
int width, uint32_t *unused)
{
nvXXtoUV_c(dstU, dstV, src1, width);
}
static void nv21ToUV_c(uint8_t *dstU, uint8_t *dstV,
- const uint8_t *src1, const uint8_t *src2,
+ const uint8_t *unused0, const uint8_t *src1, const uint8_t *src2,
int width, uint32_t *unused)
{
nvXXtoUV_c(dstV, dstU, src1, width);
@@ -1755,7 +1983,7 @@ static void nv21ToUV_c(uint8_t *dstU, uint8_t *dstV,
#define input_pixel(pos) (isBE(origin) ? AV_RB16(pos) : AV_RL16(pos))
-static void bgr24ToY_c(uint8_t *dst, const uint8_t *src,
+static void bgr24ToY_c(int16_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2,
int width, uint32_t *unused)
{
int i;
@@ -1764,11 +1992,11 @@ static void bgr24ToY_c(uint8_t *dst, const uint8_t *src,
int g= src[i*3+1];
int r= src[i*3+2];
- dst[i]= ((RY*r + GY*g + BY*b + (33<<(RGB2YUV_SHIFT-1)))>>RGB2YUV_SHIFT);
+ dst[i]= ((RY*r + GY*g + BY*b + (32<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7)))>>(RGB2YUV_SHIFT-6));
}
}
-static void bgr24ToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1,
+static void bgr24ToUV_c(int16_t *dstU, int16_t *dstV, const uint8_t *unused0, const uint8_t *src1,
const uint8_t *src2, int width, uint32_t *unused)
{
int i;
@@ -1777,13 +2005,13 @@ static void bgr24ToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1,
int g= src1[3*i + 1];
int r= src1[3*i + 2];
- dstU[i]= (RU*r + GU*g + BU*b + (257<<(RGB2YUV_SHIFT-1)))>>RGB2YUV_SHIFT;
- dstV[i]= (RV*r + GV*g + BV*b + (257<<(RGB2YUV_SHIFT-1)))>>RGB2YUV_SHIFT;
+ dstU[i]= (RU*r + GU*g + BU*b + (256<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7)))>>(RGB2YUV_SHIFT-6);
+ dstV[i]= (RV*r + GV*g + BV*b + (256<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7)))>>(RGB2YUV_SHIFT-6);
}
assert(src1 == src2);
}
-static void bgr24ToUV_half_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1,
+static void bgr24ToUV_half_c(int16_t *dstU, int16_t *dstV, const uint8_t *unused0, const uint8_t *src1,
const uint8_t *src2, int width, uint32_t *unused)
{
int i;
@@ -1792,13 +2020,13 @@ static void bgr24ToUV_half_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1,
int g= src1[6*i + 1] + src1[6*i + 4];
int r= src1[6*i + 2] + src1[6*i + 5];
- dstU[i]= (RU*r + GU*g + BU*b + (257<<RGB2YUV_SHIFT))>>(RGB2YUV_SHIFT+1);
- dstV[i]= (RV*r + GV*g + BV*b + (257<<RGB2YUV_SHIFT))>>(RGB2YUV_SHIFT+1);
+ dstU[i]= (RU*r + GU*g + BU*b + (256<<RGB2YUV_SHIFT) + (1<<(RGB2YUV_SHIFT-6)))>>(RGB2YUV_SHIFT-5);
+ dstV[i]= (RV*r + GV*g + BV*b + (256<<RGB2YUV_SHIFT) + (1<<(RGB2YUV_SHIFT-6)))>>(RGB2YUV_SHIFT-5);
}
assert(src1 == src2);
}
-static void rgb24ToY_c(uint8_t *dst, const uint8_t *src, int width,
+static void rgb24ToY_c(int16_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width,
uint32_t *unused)
{
int i;
@@ -1807,11 +2035,11 @@ static void rgb24ToY_c(uint8_t *dst, const uint8_t *src, int width,
int g= src[i*3+1];
int b= src[i*3+2];
- dst[i]= ((RY*r + GY*g + BY*b + (33<<(RGB2YUV_SHIFT-1)))>>RGB2YUV_SHIFT);
+ dst[i]= ((RY*r + GY*g + BY*b + (32<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7)))>>(RGB2YUV_SHIFT-6));
}
}
-static void rgb24ToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1,
+static void rgb24ToUV_c(int16_t *dstU, int16_t *dstV, const uint8_t *unused0, const uint8_t *src1,
const uint8_t *src2, int width, uint32_t *unused)
{
int i;
@@ -1821,13 +2049,13 @@ static void rgb24ToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1,
int g= src1[3*i + 1];
int b= src1[3*i + 2];
- dstU[i]= (RU*r + GU*g + BU*b + (257<<(RGB2YUV_SHIFT-1)))>>RGB2YUV_SHIFT;
- dstV[i]= (RV*r + GV*g + BV*b + (257<<(RGB2YUV_SHIFT-1)))>>RGB2YUV_SHIFT;
+ dstU[i]= (RU*r + GU*g + BU*b + (256<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7)))>>(RGB2YUV_SHIFT-6);
+ dstV[i]= (RV*r + GV*g + BV*b + (256<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7)))>>(RGB2YUV_SHIFT-6);
}
}
-static void rgb24ToUV_half_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1,
- const uint8_t *src2, int width, uint32_t *unused)
+static void rgb24ToUV_half_c(int16_t *dstU, int16_t *dstV, const uint8_t *unused0, const uint8_t *src1,
+ const uint8_t *src2, int width, uint32_t *unused)
{
int i;
assert(src1==src2);
@@ -1836,25 +2064,28 @@ static void rgb24ToUV_half_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1,
int g= src1[6*i + 1] + src1[6*i + 4];
int b= src1[6*i + 2] + src1[6*i + 5];
- dstU[i]= (RU*r + GU*g + BU*b + (257<<RGB2YUV_SHIFT))>>(RGB2YUV_SHIFT+1);
- dstV[i]= (RV*r + GV*g + BV*b + (257<<RGB2YUV_SHIFT))>>(RGB2YUV_SHIFT+1);
+ dstU[i]= (RU*r + GU*g + BU*b + (256<<RGB2YUV_SHIFT) + (1<<(RGB2YUV_SHIFT-6)))>>(RGB2YUV_SHIFT-5);
+ dstV[i]= (RV*r + GV*g + BV*b + (256<<RGB2YUV_SHIFT) + (1<<(RGB2YUV_SHIFT-6)))>>(RGB2YUV_SHIFT-5);
}
}
-static void hScale16_c(SwsContext *c, int16_t *_dst, int dstW, const uint8_t *_src,
- const int16_t *filter,
- const int16_t *filterPos, int filterSize)
+static void hScale16To19_c(SwsContext *c, int16_t *_dst, int dstW, const uint8_t *_src,
+ const int16_t *filter,
+ const int16_t *filterPos, int filterSize)
{
int i;
int32_t *dst = (int32_t *) _dst;
const uint16_t *src = (const uint16_t *) _src;
int bits = av_pix_fmt_descriptors[c->srcFormat].comp[0].depth_minus1;
- int sh = (bits <= 7) ? 11 : (bits - 4);
+ int sh = bits - 4;
+
+ if((isAnyRGB(c->srcFormat) || c->srcFormat==PIX_FMT_PAL8) && av_pix_fmt_descriptors[c->srcFormat].comp[0].depth_minus1<15)
+ sh= 9;
for (i = 0; i < dstW; i++) {
int j;
int srcPos = filterPos[i];
- unsigned int val = 0;
+ int val = 0;
for (j = 0; j < filterSize; j++) {
val += src[srcPos + j] * filter[filterSize * i + j];
@@ -1864,10 +2095,34 @@ static void hScale16_c(SwsContext *c, int16_t *_dst, int dstW, const uint8_t *_s
}
}
+static void hScale16To15_c(SwsContext *c, int16_t *dst, int dstW, const uint8_t *_src,
+ const int16_t *filter,
+ const int16_t *filterPos, int filterSize)
+{
+ int i;
+ const uint16_t *src = (const uint16_t *) _src;
+ int sh = av_pix_fmt_descriptors[c->srcFormat].comp[0].depth_minus1;
+
+ if(sh<15)
+ sh= isAnyRGB(c->srcFormat) || c->srcFormat==PIX_FMT_PAL8 ? 13 : av_pix_fmt_descriptors[c->srcFormat].comp[0].depth_minus1;
+
+ for (i = 0; i < dstW; i++) {
+ int j;
+ int srcPos = filterPos[i];
+ int val = 0;
+
+ for (j = 0; j < filterSize; j++) {
+ val += src[srcPos + j] * filter[filterSize * i + j];
+ }
+ // filter=14 bit, input=16 bit, output=30 bit, >> 15 makes 15 bit
+ dst[i] = FFMIN(val >> sh, (1 << 15) - 1);
+ }
+}
+
// bilinear / bicubic scaling
-static void hScale_c(SwsContext *c, int16_t *dst, int dstW, const uint8_t *src,
- const int16_t *filter, const int16_t *filterPos,
- int filterSize)
+static void hScale8To15_c(SwsContext *c, int16_t *dst, int dstW, const uint8_t *src,
+ const int16_t *filter, const int16_t *filterPos,
+ int filterSize)
{
int i;
for (i=0; i<dstW; i++) {
@@ -1883,6 +2138,25 @@ static void hScale_c(SwsContext *c, int16_t *dst, int dstW, const uint8_t *src,
}
}
+static void hScale8To19_c(SwsContext *c, int16_t *_dst, int dstW, const uint8_t *src,
+ const int16_t *filter, const int16_t *filterPos,
+ int filterSize)
+{
+ int i;
+ int32_t *dst = (int32_t *) _dst;
+ for (i=0; i<dstW; i++) {
+ int j;
+ int srcPos= filterPos[i];
+ int val=0;
+ for (j=0; j<filterSize; j++) {
+ val += ((int)src[srcPos + j])*filter[filterSize*i + j];
+ }
+ //filter += hFilterSize;
+ dst[i] = FFMIN(val>>3, (1<<19)-1); // the cubic equation does overflow ...
+ //dst[i] = val>>7;
+ }
+}
+
//FIXME all pal and rgb srcFormats could do this convertion as well
//FIXME all scalers more complex than bilinear could do half of this transform
static void chrRangeToJpeg_c(int16_t *dstU, int16_t *dstV, int width)
@@ -1946,7 +2220,7 @@ static void lumRangeFromJpeg16_c(int16_t *_dst, int width)
int i;
int32_t *dst = (int32_t *) _dst;
for (i = 0; i < width; i++)
- dst[i] = (dst[i]*14071 + (33561947<<4))>>14;
+ dst[i] = (dst[i]*(14071/4) + (33561947<<4)/4)>>12;
}
static void hyscale_fast_c(SwsContext *c, int16_t *dst, int dstWidth,
@@ -1960,58 +2234,35 @@ static void hyscale_fast_c(SwsContext *c, int16_t *dst, int dstWidth,
dst[i]= (src[xx]<<7) + (src[xx+1] - src[xx])*xalpha;
xpos+=xInc;
}
-}
-
-static void scale8To16Rv_c(uint16_t *_dst, const uint8_t *src, int len)
-{
- int i;
- uint8_t *dst = (uint8_t *) _dst;
- for (i = len - 1; i >= 0; i--) {
- dst[i * 2] = dst[i * 2 + 1] = src[i];
- }
-}
-
-static void scale19To15Fw_c(int16_t *dst, const int32_t *src, int len)
-{
- int i;
- for (i = 0; i < len; i++) {
- dst[i] = src[i] >> 4;
- }
+ for (i=dstWidth-1; (i*xInc)>>16 >=srcW-1; i--)
+ dst[i] = src[srcW-1]*128;
}
// *** horizontal scale Y line to temp buffer
static av_always_inline void hyscale(SwsContext *c, int16_t *dst, int dstWidth,
- const uint8_t *src, int srcW, int xInc,
+ const uint8_t *src, const uint8_t *src2, const uint8_t *src3,
+ int srcW, int xInc,
const int16_t *hLumFilter,
const int16_t *hLumFilterPos, int hLumFilterSize,
uint8_t *formatConvBuffer,
uint32_t *pal, int isAlpha)
{
- void (*toYV12)(uint8_t *, const uint8_t *, int, uint32_t *) = isAlpha ? c->alpToYV12 : c->lumToYV12;
+ void (*toYV12)(uint8_t *, const uint8_t *, const uint8_t *, const uint8_t *, int, uint32_t *) = isAlpha ? c->alpToYV12 : c->lumToYV12;
void (*convertRange)(int16_t *, int) = isAlpha ? NULL : c->lumConvertRange;
if (toYV12) {
- toYV12(formatConvBuffer, src, srcW, pal);
+ toYV12(formatConvBuffer, src, src2, src3, srcW, pal);
src= formatConvBuffer;
}
- if (av_pix_fmt_descriptors[c->srcFormat].comp[0].depth_minus1 < 8 && c->scalingBpp == 16) {
- c->scale8To16Rv((uint16_t *) formatConvBuffer, src, srcW);
- src = formatConvBuffer;
- }
-
if (!c->hyscale_fast) {
- c->hScale(c, dst, dstWidth, src, hLumFilter, hLumFilterPos, hLumFilterSize);
+ c->hyScale(c, dst, dstWidth, src, hLumFilter, hLumFilterPos, hLumFilterSize);
} else { // fast bilinear upscale / crap downscale
c->hyscale_fast(c, dst, dstWidth, src, srcW, xInc);
}
if (convertRange)
convertRange(dst, dstWidth);
-
- if (av_pix_fmt_descriptors[c->dstFormat].comp[0].depth_minus1 < 8 && c->scalingBpp == 16) {
- c->scale19To15Fw(dst, (int32_t *) dst, dstWidth);
- }
}
static void hcscale_fast_c(SwsContext *c, int16_t *dst1, int16_t *dst2,
@@ -2027,43 +2278,34 @@ static void hcscale_fast_c(SwsContext *c, int16_t *dst1, int16_t *dst2,
dst2[i]=(src2[xx]*(xalpha^127)+src2[xx+1]*xalpha);
xpos+=xInc;
}
+ for (i=dstWidth-1; (i*xInc)>>16 >=srcW-1; i--) {
+ dst1[i] = src1[srcW-1]*128;
+ dst2[i] = src2[srcW-1]*128;
+ }
}
static av_always_inline void hcscale(SwsContext *c, int16_t *dst1, int16_t *dst2, int dstWidth,
- const uint8_t *src1, const uint8_t *src2,
+ const uint8_t *src0, const uint8_t *src1, const uint8_t *src2,
int srcW, int xInc, const int16_t *hChrFilter,
const int16_t *hChrFilterPos, int hChrFilterSize,
uint8_t *formatConvBuffer, uint32_t *pal)
{
if (c->chrToYV12) {
- uint8_t *buf2 = formatConvBuffer + FFALIGN(srcW * c->scalingBpp >> 3, 16);
- c->chrToYV12(formatConvBuffer, buf2, src1, src2, srcW, pal);
+ uint8_t *buf2 = formatConvBuffer + FFALIGN(srcW*2+78, 16);
+ c->chrToYV12(formatConvBuffer, buf2, src0, src1, src2, srcW, pal);
src1= formatConvBuffer;
src2= buf2;
}
- if (av_pix_fmt_descriptors[c->srcFormat].comp[0].depth_minus1 < 8 && c->scalingBpp == 16) {
- uint8_t *buf2 = (formatConvBuffer + FFALIGN(srcW * 2, 16));
- c->scale8To16Rv((uint16_t *) formatConvBuffer, src1, srcW);
- c->scale8To16Rv((uint16_t *) buf2, src2, srcW);
- src1 = formatConvBuffer;
- src2 = buf2;
- }
-
if (!c->hcscale_fast) {
- c->hScale(c, dst1, dstWidth, src1, hChrFilter, hChrFilterPos, hChrFilterSize);
- c->hScale(c, dst2, dstWidth, src2, hChrFilter, hChrFilterPos, hChrFilterSize);
+ c->hcScale(c, dst1, dstWidth, src1, hChrFilter, hChrFilterPos, hChrFilterSize);
+ c->hcScale(c, dst2, dstWidth, src2, hChrFilter, hChrFilterPos, hChrFilterSize);
} else { // fast bilinear upscale / crap downscale
c->hcscale_fast(c, dst1, dst2, dstWidth, src1, src2, srcW, xInc);
}
if (c->chrConvertRange)
c->chrConvertRange(dst1, dst2, dstWidth);
-
- if (av_pix_fmt_descriptors[c->dstFormat].comp[0].depth_minus1 < 8 && c->scalingBpp == 16) {
- c->scale19To15Fw(dst1, (int32_t *) dst1, dstWidth);
- c->scale19To15Fw(dst2, (int32_t *) dst2, dstWidth);
- }
}
static av_always_inline void
@@ -2153,7 +2395,10 @@ find_c_packed_planar_out_funcs(SwsContext *c,
*yuv2packedX = yuv2bgr24_full_X_c;
break;
}
+ if(!*yuv2packedX)
+ goto YUV_PACKED;
} else {
+ YUV_PACKED:
switch (dstFormat) {
case PIX_FMT_GRAY16BE:
*yuv2packed1 = yuv2gray16BE_1_c;
@@ -2346,6 +2591,8 @@ static int swScale(SwsContext *c, const uint8_t* src[],
const int chrSrcSliceH= -((-srcSliceH) >> c->chrSrcVSubSample);
int lastDstY;
uint32_t *pal=c->pal_yuv;
+
+ int should_dither= isNBPS(c->srcFormat) || is16BPS(c->srcFormat);
yuv2planar1_fn yuv2yuv1 = c->yuv2yuv1;
yuv2planarX_fn yuv2yuvX = c->yuv2yuvX;
yuv2packed1_fn yuv2packed1 = c->yuv2packed1;
@@ -2400,6 +2647,9 @@ static int swScale(SwsContext *c, const uint8_t* src[],
lastInChrBuf= -1;
}
+ if (!should_dither) {
+ c->chrDither8 = c->lumDither8 = ff_sws_pb_64;
+ }
lastDstY= dstY;
for (;dstY < dstH; dstY++) {
@@ -2444,17 +2694,19 @@ static int swScale(SwsContext *c, const uint8_t* src[],
//Do horizontal scaling
while(lastInLumBuf < lastLumSrcY) {
const uint8_t *src1= src[0]+(lastInLumBuf + 1 - srcSliceY)*srcStride[0];
- const uint8_t *src2= src[3]+(lastInLumBuf + 1 - srcSliceY)*srcStride[3];
+ const uint8_t *src2= src[1]+(lastInLumBuf + 1 - srcSliceY)*srcStride[1];
+ const uint8_t *src3= src[2]+(lastInLumBuf + 1 - srcSliceY)*srcStride[2];
+ const uint8_t *src4= src[3]+(lastInLumBuf + 1 - srcSliceY)*srcStride[3];
lumBufIndex++;
assert(lumBufIndex < 2*vLumBufSize);
assert(lastInLumBuf + 1 - srcSliceY < srcSliceH);
assert(lastInLumBuf + 1 - srcSliceY >= 0);
- hyscale(c, lumPixBuf[ lumBufIndex ], dstW, src1, srcW, lumXInc,
+ hyscale(c, lumPixBuf[ lumBufIndex ], dstW, src1, src2, src3, srcW, lumXInc,
hLumFilter, hLumFilterPos, hLumFilterSize,
formatConvBuffer,
pal, 0);
if (CONFIG_SWSCALE_ALPHA && alpPixBuf)
- hyscale(c, alpPixBuf[ lumBufIndex ], dstW, src2, srcW,
+ hyscale(c, alpPixBuf[ lumBufIndex ], dstW, src4, NULL, NULL, srcW,
lumXInc, hLumFilter, hLumFilterPos, hLumFilterSize,
formatConvBuffer,
pal, 1);
@@ -2463,6 +2715,7 @@ static int swScale(SwsContext *c, const uint8_t* src[],
lumBufIndex, lastInLumBuf);
}
while(lastInChrBuf < lastChrSrcY) {
+ const uint8_t *src0= src[0]+(lastInChrBuf + 1 - chrSrcSliceY)*srcStride[0];
const uint8_t *src1= src[1]+(lastInChrBuf + 1 - chrSrcSliceY)*srcStride[1];
const uint8_t *src2= src[2]+(lastInChrBuf + 1 - chrSrcSliceY)*srcStride[2];
chrBufIndex++;
@@ -2473,7 +2726,7 @@ static int swScale(SwsContext *c, const uint8_t* src[],
if (c->needs_hcscale)
hcscale(c, chrUPixBuf[chrBufIndex], chrVPixBuf[chrBufIndex],
- chrDstW, src1, src2, chrSrcW, chrXInc,
+ chrDstW, src0, src1, src2, chrSrcW, chrXInc,
hChrFilter, hChrFilterPos, hChrFilterSize,
formatConvBuffer, pal);
lastInChrBuf++;
@@ -2489,6 +2742,10 @@ static int swScale(SwsContext *c, const uint8_t* src[],
#if HAVE_MMX
updateMMXDitherTables(c, dstY, lumBufIndex, chrBufIndex, lastInLumBuf, lastInChrBuf);
#endif
+ if (should_dither) {
+ c->chrDither8 = dither_8x8_128[chrDstY & 7];
+ c->lumDither8 = dither_8x8_128[dstY & 7];
+ }
if (dstY >= dstH-2) {
// hmm looks like we can't use MMX here without overwriting this array's tail
find_c_packed_planar_out_funcs(c, &yuv2yuv1, &yuv2yuvX,
@@ -2501,6 +2758,7 @@ static int swScale(SwsContext *c, const uint8_t* src[],
const int16_t **chrUSrcPtr= (const int16_t **) chrUPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf + vChrBufSize;
const int16_t **chrVSrcPtr= (const int16_t **) chrVPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf + vChrBufSize;
const int16_t **alpSrcPtr= (CONFIG_SWSCALE_ALPHA && alpPixBuf) ? (const int16_t **) alpPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize : NULL;
+
if (isPlanarYUV(dstFormat) || dstFormat==PIX_FMT_GRAY8) { //YV12 like
const int chrSkipMask= (1<<c->chrDstVSubSample)-1;
if ((dstY&chrSkipMask) || isGray(dstFormat))
@@ -2585,15 +2843,17 @@ static av_cold void sws_init_swScale_c(SwsContext *c)
case PIX_FMT_RGB4_BYTE: c->chrToYV12 = palToUV_c; break;
#if HAVE_BIGENDIAN
case PIX_FMT_YUV444P9LE:
+ case PIX_FMT_YUV422P9LE:
case PIX_FMT_YUV420P9LE:
case PIX_FMT_YUV422P10LE:
- case PIX_FMT_YUV444P10LE:
case PIX_FMT_YUV420P10LE:
+ case PIX_FMT_YUV444P10LE:
case PIX_FMT_YUV420P16LE:
case PIX_FMT_YUV422P16LE:
case PIX_FMT_YUV444P16LE: c->chrToYV12 = bswap16UV_c; break;
#else
case PIX_FMT_YUV444P9BE:
+ case PIX_FMT_YUV422P9BE:
case PIX_FMT_YUV420P9BE:
case PIX_FMT_YUV444P10BE:
case PIX_FMT_YUV422P10BE:
@@ -2623,6 +2883,7 @@ static av_cold void sws_init_swScale_c(SwsContext *c)
case PIX_FMT_RGB565BE: c->chrToYV12 = rgb16beToUV_half_c; break;
case PIX_FMT_RGB555LE: c->chrToYV12 = rgb15leToUV_half_c; break;
case PIX_FMT_RGB555BE: c->chrToYV12 = rgb15beToUV_half_c; break;
+ case PIX_FMT_GBR24P : c->chrToYV12 = gbr24pToUV_half_c; break;
}
} else {
switch(srcFormat) {
@@ -2644,6 +2905,7 @@ static av_cold void sws_init_swScale_c(SwsContext *c)
case PIX_FMT_RGB565BE: c->chrToYV12 = rgb16beToUV_c; break;
case PIX_FMT_RGB555LE: c->chrToYV12 = rgb15leToUV_c; break;
case PIX_FMT_RGB555BE: c->chrToYV12 = rgb15beToUV_c; break;
+ case PIX_FMT_GBR24P : c->chrToYV12 = gbr24pToUV_c; break;
}
}
@@ -2652,16 +2914,18 @@ static av_cold void sws_init_swScale_c(SwsContext *c)
switch (srcFormat) {
#if HAVE_BIGENDIAN
case PIX_FMT_YUV444P9LE:
+ case PIX_FMT_YUV422P9LE:
case PIX_FMT_YUV420P9LE:
- case PIX_FMT_YUV444P10LE:
case PIX_FMT_YUV422P10LE:
case PIX_FMT_YUV420P10LE:
+ case PIX_FMT_YUV444P10LE:
case PIX_FMT_YUV420P16LE:
case PIX_FMT_YUV422P16LE:
case PIX_FMT_YUV444P16LE:
case PIX_FMT_GRAY16LE: c->lumToYV12 = bswap16Y_c; break;
#else
case PIX_FMT_YUV444P9BE:
+ case PIX_FMT_YUV422P9BE:
case PIX_FMT_YUV420P9BE:
case PIX_FMT_YUV444P10BE:
case PIX_FMT_YUV422P10BE:
@@ -2699,6 +2963,7 @@ static av_cold void sws_init_swScale_c(SwsContext *c)
case PIX_FMT_RGB48LE: c->lumToYV12 = rgb48LEToY_c; break;
case PIX_FMT_BGR48BE: c->lumToYV12 = bgr48BEToY_c; break;
case PIX_FMT_BGR48LE: c->lumToYV12 = bgr48LEToY_c; break;
+ case PIX_FMT_GBR24P : c->lumToYV12 = gbr24pToY_c ; break;
}
if (c->alpPixBuf) {
switch (srcFormat) {
@@ -2707,31 +2972,35 @@ static av_cold void sws_init_swScale_c(SwsContext *c)
case PIX_FMT_ABGR:
case PIX_FMT_ARGB: c->alpToYV12 = abgrToA_c; break;
case PIX_FMT_Y400A: c->alpToYV12 = uyvyToY_c; break;
+ case PIX_FMT_PAL8 : c->alpToYV12 = palToA_c; break;
}
}
- if (c->scalingBpp == 8) {
- c->hScale = hScale_c;
- if (c->flags & SWS_FAST_BILINEAR) {
- c->hyscale_fast = hyscale_fast_c;
- c->hcscale_fast = hcscale_fast_c;
- }
- if (c->srcRange != c->dstRange && !isAnyRGB(c->dstFormat)) {
- if (c->srcRange) {
- c->lumConvertRange = lumRangeFromJpeg_c;
- c->chrConvertRange = chrRangeFromJpeg_c;
+ if (c->srcBpc == 8) {
+ if (c->dstBpc <= 10) {
+ c->hyScale = c->hcScale = hScale8To15_c;
+ if (c->flags & SWS_FAST_BILINEAR) {
+ c->hyscale_fast = hyscale_fast_c;
+ c->hcscale_fast = hcscale_fast_c;
+ }
} else {
- c->lumConvertRange = lumRangeToJpeg_c;
- c->chrConvertRange = chrRangeToJpeg_c;
+ c->hyScale = c->hcScale = hScale8To19_c;
}
- }
} else {
- c->hScale = hScale16_c;
- c->scale19To15Fw = scale19To15Fw_c;
- c->scale8To16Rv = scale8To16Rv_c;
+ c->hyScale = c->hcScale = c->dstBpc > 10 ? hScale16To19_c : hScale16To15_c;
+ }
- if (c->srcRange != c->dstRange && !isAnyRGB(c->dstFormat)) {
+ if (c->srcRange != c->dstRange && !isAnyRGB(c->dstFormat)) {
+ if (c->dstBpc <= 10) {
+ if (c->srcRange) {
+ c->lumConvertRange = lumRangeFromJpeg_c;
+ c->chrConvertRange = chrRangeFromJpeg_c;
+ } else {
+ c->lumConvertRange = lumRangeToJpeg_c;
+ c->chrConvertRange = chrRangeToJpeg_c;
+ }
+ } else {
if (c->srcRange) {
c->lumConvertRange = lumRangeFromJpeg16_c;
c->chrConvertRange = chrRangeFromJpeg16_c;
diff --git a/libswscale/swscale.h b/libswscale/swscale.h
index 80e5eaab00..bdde675a8d 100644
--- a/libswscale/swscale.h
+++ b/libswscale/swscale.h
@@ -1,20 +1,20 @@
/*
* Copyright (C) 2001-2003 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -32,7 +32,7 @@
#include "libavutil/pixfmt.h"
#define LIBSWSCALE_VERSION_MAJOR 2
-#define LIBSWSCALE_VERSION_MINOR 0
+#define LIBSWSCALE_VERSION_MINOR 1
#define LIBSWSCALE_VERSION_MICRO 0
#define LIBSWSCALE_VERSION_INT AV_VERSION_INT(LIBSWSCALE_VERSION_MAJOR, \
@@ -55,6 +55,9 @@
#ifndef FF_API_SWS_CPU_CAPS
#define FF_API_SWS_CPU_CAPS (LIBSWSCALE_VERSION_MAJOR < 3)
#endif
+#ifndef FF_API_SWS_FORMAT_NAME
+#define FF_API_SWS_FORMAT_NAME (LIBSWSCALE_VERSION_MAJOR < 3)
+#endif
/**
* Returns the LIBSWSCALE_VERSION_INT constant.
@@ -215,7 +218,7 @@ struct SwsContext *sws_getContext(int srcW, int srcH, enum PixelFormat srcFormat
* top-bottom or bottom-top order. If slices are provided in
* non-sequential order the behavior of the function is undefined.
*
- * @param context the scaling context previously created with
+ * @param c the scaling context previously created with
* sws_getContext()
* @param srcSlice the array containing the pointers to the planes of
* the source slice
@@ -232,8 +235,9 @@ struct SwsContext *sws_getContext(int srcW, int srcH, enum PixelFormat srcFormat
* the destination image
* @return the height of the output slice
*/
-int sws_scale(struct SwsContext *context, const uint8_t* const srcSlice[], const int srcStride[],
- int srcSliceY, int srcSliceH, uint8_t* const dst[], const int dstStride[]);
+int sws_scale(struct SwsContext *c, const uint8_t* const srcSlice[],
+ const int srcStride[], int srcSliceY, int srcSliceH,
+ uint8_t* const dst[], const int dstStride[]);
/**
* @param inv_table the yuv2rgb coefficients, normally ff_yuv2rgb_coeffs[x]
@@ -350,5 +354,12 @@ void sws_convertPalette8ToPacked32(const uint8_t *src, uint8_t *dst, int num_pix
*/
void sws_convertPalette8ToPacked24(const uint8_t *src, uint8_t *dst, int num_pixels, const uint8_t *palette);
+/**
+ * Get the AVClass for swsContext. It can be used in combination with
+ * AV_OPT_SEARCH_FAKE_OBJ for examining options.
+ *
+ * @see av_opt_find().
+ */
+const AVClass *sws_get_class(void);
#endif /* SWSCALE_SWSCALE_H */
diff --git a/libswscale/swscale_internal.h b/libswscale/swscale_internal.h
index 340227dc00..c8e8685f72 100644
--- a/libswscale/swscale_internal.h
+++ b/libswscale/swscale_internal.h
@@ -1,20 +1,20 @@
/*
* Copyright (C) 2001-2003 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -37,6 +37,8 @@
#define MAX_FILTER_SIZE 256
+#define DITHER1XBPP
+
#if HAVE_BIGENDIAN
#define ALT32_CORR (-1)
#else
@@ -64,11 +66,16 @@ typedef int (*SwsFunc)(struct SwsContext *context, const uint8_t* src[],
* without any additional vertical scaling (or point-scaling).
*
* @param c SWS scaling context
- * @param lumSrc scaled luma (Y) source data, 15bit for 8bit output
- * @param chrUSrc scaled chroma (U) source data, 15bit for 8bit output
- * @param chrVSrc scaled chroma (V) source data, 15bit for 8bit output
- * @param alpSrc scaled alpha (A) source data, 15bit for 8bit output
- * @param dest pointer to the 4 output planes (Y/U/V/A)
+ * @param lumSrc scaled luma (Y) source data, 15bit for 8-10bit output,
+ * 19-bit for 16bit output (in int32_t)
+ * @param chrUSrc scaled chroma (U) source data, 15bit for 8-10bit output,
+ * 19-bit for 16bit output (in int32_t)
+ * @param chrVSrc scaled chroma (V) source data, 15bit for 8-10bit output,
+ * 19-bit for 16bit output (in int32_t)
+ * @param alpSrc scaled alpha (A) source data, 15bit for 8-10bit output,
+ * 19-bit for 16bit output (in int32_t)
+ * @param dest pointer to the 4 output planes (Y/U/V/A). For >8bit
+ * output, this is in uint16_t
* @param dstW width of dest[0], dest[3], lumSrc and alpSrc in pixels
* @param chrDstW width of dest[1], dest[2], chrUSrc and chrVSrc
*/
@@ -82,14 +89,19 @@ typedef void (*yuv2planar1_fn) (struct SwsContext *c,
*
* @param c SWS scaling context
* @param lumFilter vertical luma/alpha scaling coefficients, 12bit [0,4096]
- * @param lumSrc scaled luma (Y) source data, 15bit for 8bit output
+ * @param lumSrc scaled luma (Y) source data, 15bit for 8-10bit output,
+ * 19-bit for 16bit output (in int32_t)
* @param lumFilterSize number of vertical luma/alpha input lines to scale
* @param chrFilter vertical chroma scaling coefficients, 12bit [0,4096]
- * @param chrUSrc scaled chroma (U) source data, 15bit for 8bit output
- * @param chrVSrc scaled chroma (V) source data, 15bit for 8bit output
+ * @param chrUSrc scaled chroma (U) source data, 15bit for 8-10bit output,
+ * 19-bit for 16bit output (in int32_t)
+ * @param chrVSrc scaled chroma (V) source data, 15bit for 8-10bit output,
+ * 19-bit for 16bit output (in int32_t)
* @param chrFilterSize number of vertical chroma input lines to scale
- * @param alpSrc scaled alpha (A) source data, 15bit for 8bit output
- * @param dest pointer to the 4 output planes (Y/U/V/A)
+ * @param alpSrc scaled alpha (A) source data, 15bit for 8-10bit output,
+ * 19-bit for 16bit output (in int32_t)
+ * @param dest pointer to the 4 output planes (Y/U/V/A). For >8bit
+ * output, this is in uint16_t
* @param dstW width of dest[0], dest[3], lumSrc and alpSrc in pixels
* @param chrDstW width of dest[1], dest[2], chrUSrc and chrVSrc
*/
@@ -105,11 +117,16 @@ typedef void (*yuv2planarX_fn) (struct SwsContext *c, const int16_t *lumFilter,
* that this function may do chroma scaling, see the "uvalpha" argument.
*
* @param c SWS scaling context
- * @param lumSrc scaled luma (Y) source data, 15bit for 8bit output
- * @param chrUSrc scaled chroma (U) source data, 15bit for 8bit output
- * @param chrVSrc scaled chroma (V) source data, 15bit for 8bit output
- * @param alpSrc scaled alpha (A) source data, 15bit for 8bit output
- * @param dest pointer to the output plane
+ * @param lumSrc scaled luma (Y) source data, 15bit for 8-10bit output,
+ * 19-bit for 16bit output (in int32_t)
+ * @param chrUSrc scaled chroma (U) source data, 15bit for 8-10bit output,
+ * 19-bit for 16bit output (in int32_t)
+ * @param chrVSrc scaled chroma (V) source data, 15bit for 8-10bit output,
+ * 19-bit for 16bit output (in int32_t)
+ * @param alpSrc scaled alpha (A) source data, 15bit for 8-10bit output,
+ * 19-bit for 16bit output (in int32_t)
+ * @param dest pointer to the output plane. For 16bit output, this is
+ * uint16_t
* @param dstW width of lumSrc and alpSrc in pixels, number of pixels
* to write into dest[]
* @param uvalpha chroma scaling coefficient for the second line of chroma
@@ -132,11 +149,16 @@ typedef void (*yuv2packed1_fn) (struct SwsContext *c, const int16_t *lumSrc,
* output by doing bilinear scaling between two input lines.
*
* @param c SWS scaling context
- * @param lumSrc scaled luma (Y) source data, 15bit for 8bit output
- * @param chrUSrc scaled chroma (U) source data, 15bit for 8bit output
- * @param chrVSrc scaled chroma (V) source data, 15bit for 8bit output
- * @param alpSrc scaled alpha (A) source data, 15bit for 8bit output
- * @param dest pointer to the output plane
+ * @param lumSrc scaled luma (Y) source data, 15bit for 8-10bit output,
+ * 19-bit for 16bit output (in int32_t)
+ * @param chrUSrc scaled chroma (U) source data, 15bit for 8-10bit output,
+ * 19-bit for 16bit output (in int32_t)
+ * @param chrVSrc scaled chroma (V) source data, 15bit for 8-10bit output,
+ * 19-bit for 16bit output (in int32_t)
+ * @param alpSrc scaled alpha (A) source data, 15bit for 8-10bit output,
+ * 19-bit for 16bit output (in int32_t)
+ * @param dest pointer to the output plane. For 16bit output, this is
+ * uint16_t
* @param dstW width of lumSrc and alpSrc in pixels, number of pixels
* to write into dest[]
* @param yalpha luma/alpha scaling coefficients for the second input line.
@@ -160,14 +182,19 @@ typedef void (*yuv2packed2_fn) (struct SwsContext *c, const int16_t *lumSrc[2],
*
* @param c SWS scaling context
* @param lumFilter vertical luma/alpha scaling coefficients, 12bit [0,4096]
- * @param lumSrc scaled luma (Y) source data, 15bit for 8bit output
+ * @param lumSrc scaled luma (Y) source data, 15bit for 8-10bit output,
+ * 19-bit for 16bit output (in int32_t)
* @param lumFilterSize number of vertical luma/alpha input lines to scale
* @param chrFilter vertical chroma scaling coefficients, 12bit [0,4096]
- * @param chrUSrc scaled chroma (U) source data, 15bit for 8bit output
- * @param chrVSrc scaled chroma (V) source data, 15bit for 8bit output
+ * @param chrUSrc scaled chroma (U) source data, 15bit for 8-10bit output,
+ * 19-bit for 16bit output (in int32_t)
+ * @param chrVSrc scaled chroma (V) source data, 15bit for 8-10bit output,
+ * 19-bit for 16bit output (in int32_t)
* @param chrFilterSize number of vertical chroma input lines to scale
- * @param alpSrc scaled alpha (A) source data, 15bit for 8bit output
- * @param dest pointer to the output plane
+ * @param alpSrc scaled alpha (A) source data, 15bit for 8-10bit output,
+ * 19-bit for 16bit output (in int32_t)
+ * @param dest pointer to the output plane. For 16bit output, this is
+ * uint16_t
* @param dstW width of lumSrc and alpSrc in pixels, number of pixels
* to write into dest[]
* @param y vertical line number for this output. This does not need
@@ -207,7 +234,7 @@ typedef struct SwsContext {
enum PixelFormat srcFormat; ///< Source pixel format.
int dstFormatBpp; ///< Number of bits per pixel of the destination pixel format.
int srcFormatBpp; ///< Number of bits per pixel of the source pixel format.
- int scalingBpp;
+ int dstBpc, srcBpc;
int chrSrcHSubSample; ///< Binary logarithm of horizontal subsampling factor between luma/alpha and chroma planes in source image.
int chrSrcVSubSample; ///< Binary logarithm of vertical subsampling factor between luma/alpha and chroma planes in source image.
int chrDstHSubSample; ///< Binary logarithm of horizontal subsampling factor between luma/alpha and chroma planes in destination image.
@@ -321,6 +348,8 @@ typedef struct SwsContext {
#define ALP_MMX_FILTER_OFFSET "11*8+4*4*256*2+48"
#define UV_OFF "11*8+4*4*256*3+48"
#define UV_OFFx2 "11*8+4*4*256*3+56"
+#define DITHER16 "11*8+4*4*256*3+64"
+#define DITHER32 "11*8+4*4*256*3+80"
DECLARE_ALIGNED(8, uint64_t, redDither);
DECLARE_ALIGNED(8, uint64_t, greenDither);
@@ -343,8 +372,15 @@ typedef struct SwsContext {
DECLARE_ALIGNED(8, uint64_t, v_temp);
DECLARE_ALIGNED(8, uint64_t, y_temp);
int32_t alpMmxFilter[4*MAX_FILTER_SIZE];
+ // alignment of these values is not necessary, but merely here
+ // to maintain the same offset across x8632 and x86-64. Once we
+ // use proper offset macros in the asm, they can be removed.
DECLARE_ALIGNED(8, ptrdiff_t, uv_off); ///< offset (in pixels) between u and v planes
DECLARE_ALIGNED(8, ptrdiff_t, uv_offx2); ///< offset (in bytes) between u and v planes
+ DECLARE_ALIGNED(8, uint16_t, dither16)[8];
+ DECLARE_ALIGNED(8, uint32_t, dither32)[8];
+
+ const uint8_t *chrDither8, *lumDither8;
#if HAVE_ALTIVEC
vector signed short CY;
@@ -382,12 +418,12 @@ typedef struct SwsContext {
yuv2packed2_fn yuv2packed2;
yuv2packedX_fn yuv2packedX;
- void (*lumToYV12)(uint8_t *dst, const uint8_t *src,
+ void (*lumToYV12)(uint8_t *dst, const uint8_t *src, const uint8_t *src2, const uint8_t *src3,
int width, uint32_t *pal); ///< Unscaled conversion of luma plane to YV12 for horizontal scaler.
- void (*alpToYV12)(uint8_t *dst, const uint8_t *src,
+ void (*alpToYV12)(uint8_t *dst, const uint8_t *src, const uint8_t *src2, const uint8_t *src3,
int width, uint32_t *pal); ///< Unscaled conversion of alpha plane to YV12 for horizontal scaler.
void (*chrToYV12)(uint8_t *dstU, uint8_t *dstV,
- const uint8_t *src1, const uint8_t *src2,
+ const uint8_t *src1, const uint8_t *src2, const uint8_t *src3,
int width, uint32_t *pal); ///< Unscaled conversion of chroma planes to YV12 for horizontal scaler.
/**
* Scale one horizontal line of input data using a bilinear filter
@@ -422,14 +458,19 @@ typedef struct SwsContext {
* lines, to produce one (differently sized) line of output data.
*
* @param dst pointer to destination buffer for horizontally scaled
- * data. If the scaling depth (SwsContext->scalingBpp) is
- * 8, data will be 15bpp in 16bits (int16_t) width. If
- * scaling depth is 16, data will be 19bpp in 32bpp
- * (int32_t) width.
+ * data. If the number of bits per component of one
+ * destination pixel (SwsContext->dstBpc) is <= 10, data
+ * will be 15bpc in 16bits (int16_t) width. Else (i.e.
+ * SwsContext->dstBpc == 16), data will be 19bpc in
+ * 32bits (int32_t) width.
* @param dstW width of destination image
- * @param src pointer to source data to be scaled. If scaling depth
- * is 8, this is 8bpp in 8bpp (uint8_t) width. If scaling
- * depth is 16, this is 16bpp in 16bpp (uint16_t) depth.
+ * @param src pointer to source data to be scaled. If the number of
+ * bits per component of a source pixel (SwsContext->srcBpc)
+ * is 8, this is 8bpc in 8bits (uint8_t) width. Else
+ * (i.e. SwsContext->dstBpc > 8), this is native depth
+ * in 16bits (uint16_t) width. In other words, for 9-bit
+ * YUV input, this is 9bpc, for 10-bit YUV input, this is
+ * 10bpc, and for 16-bit RGB or YUV, this is 16bpc.
* @param filter filter coefficients to be used per output pixel for
* scaling. This contains 14bpp filtering coefficients.
* Guaranteed to contain dstW * filterSize entries.
@@ -442,22 +483,18 @@ typedef struct SwsContext {
* (and input coefficients thus padded with zeroes)
* to simplify creating SIMD code.
*/
- void (*hScale)(struct SwsContext *c, int16_t *dst, int dstW, const uint8_t *src,
- const int16_t *filter, const int16_t *filterPos,
- int filterSize);
+ /** @{ */
+ void (*hyScale)(struct SwsContext *c, int16_t *dst, int dstW, const uint8_t *src,
+ const int16_t *filter, const int16_t *filterPos,
+ int filterSize);
+ void (*hcScale)(struct SwsContext *c, int16_t *dst, int dstW, const uint8_t *src,
+ const int16_t *filter, const int16_t *filterPos,
+ int filterSize);
+ /** @} */
void (*lumConvertRange)(int16_t *dst, int width); ///< Color range conversion function for luma plane if needed.
void (*chrConvertRange)(int16_t *dst1, int16_t *dst2, int width); ///< Color range conversion function for chroma planes if needed.
- /**
- * dst[..] = (src[..] << 8) | src[..];
- */
- void (*scale8To16Rv)(uint16_t *dst, const uint8_t *src, int len);
- /**
- * dst[..] = src[..] >> 4;
- */
- void (*scale19To15Fw)(int16_t *dst, const int32_t *src, int len);
-
int needs_hcscale; ///< Set if there are chroma planes to be converted.
} SwsContext;
@@ -480,7 +517,13 @@ SwsFunc ff_yuv2rgb_init_altivec(SwsContext *c);
SwsFunc ff_yuv2rgb_get_func_ptr_bfin(SwsContext *c);
void ff_bfin_get_unscaled_swscale(SwsContext *c);
+#if FF_API_SWS_FORMAT_NAME
+/**
+ * @deprecated Use av_get_pix_fmt_name() instead.
+ */
+attribute_deprecated
const char *sws_format_name(enum PixelFormat format);
+#endif
//FIXME replace this with something faster
#define is16BPS(x) ( \
@@ -490,6 +533,10 @@ const char *sws_format_name(enum PixelFormat format);
|| (x)==PIX_FMT_BGR48LE \
|| (x)==PIX_FMT_RGB48BE \
|| (x)==PIX_FMT_RGB48LE \
+ || (x)==PIX_FMT_BGRA64BE \
+ || (x)==PIX_FMT_BGRA64LE \
+ || (x)==PIX_FMT_RGBA64BE \
+ || (x)==PIX_FMT_RGBA64LE \
|| (x)==PIX_FMT_YUV420P16LE \
|| (x)==PIX_FMT_YUV422P16LE \
|| (x)==PIX_FMT_YUV444P16LE \
@@ -497,9 +544,11 @@ const char *sws_format_name(enum PixelFormat format);
|| (x)==PIX_FMT_YUV422P16BE \
|| (x)==PIX_FMT_YUV444P16BE \
)
-#define is9_OR_10BPS(x) ( \
+#define isNBPS(x) ( \
(x)==PIX_FMT_YUV420P9LE \
|| (x)==PIX_FMT_YUV420P9BE \
+ || (x)==PIX_FMT_YUV422P9LE \
+ || (x)==PIX_FMT_YUV422P9BE \
|| (x)==PIX_FMT_YUV444P9BE \
|| (x)==PIX_FMT_YUV444P9LE \
|| (x)==PIX_FMT_YUV422P10BE \
@@ -508,7 +557,10 @@ const char *sws_format_name(enum PixelFormat format);
|| (x)==PIX_FMT_YUV444P10LE \
|| (x)==PIX_FMT_YUV420P10LE \
|| (x)==PIX_FMT_YUV420P10BE \
+ || (x)==PIX_FMT_YUV422P10LE \
+ || (x)==PIX_FMT_YUV422P10BE \
)
+#define is9_OR_10BPS isNBPS //for ronald
#define isBE(x) ((x)&1)
#define isPlanar8YUV(x) ( \
(x)==PIX_FMT_YUV410P \
@@ -524,22 +576,32 @@ const char *sws_format_name(enum PixelFormat format);
#define isPlanarYUV(x) ( \
isPlanar8YUV(x) \
|| (x)==PIX_FMT_YUV420P9LE \
+ || (x)==PIX_FMT_YUV422P9LE \
|| (x)==PIX_FMT_YUV444P9LE \
|| (x)==PIX_FMT_YUV420P10LE \
|| (x)==PIX_FMT_YUV422P10LE \
|| (x)==PIX_FMT_YUV444P10LE \
|| (x)==PIX_FMT_YUV420P16LE \
+ || (x)==PIX_FMT_YUV422P10LE \
|| (x)==PIX_FMT_YUV422P16LE \
|| (x)==PIX_FMT_YUV444P16LE \
|| (x)==PIX_FMT_YUV420P9BE \
+ || (x)==PIX_FMT_YUV422P9BE \
|| (x)==PIX_FMT_YUV444P9BE \
|| (x)==PIX_FMT_YUV420P10BE \
|| (x)==PIX_FMT_YUV422P10BE \
|| (x)==PIX_FMT_YUV444P10BE \
|| (x)==PIX_FMT_YUV420P16BE \
+ || (x)==PIX_FMT_YUV422P10BE \
|| (x)==PIX_FMT_YUV422P16BE \
|| (x)==PIX_FMT_YUV444P16BE \
)
+
+#define isPlanar(x) ( \
+ isPlanarYUV(x) \
+ || (x)==PIX_FMT_GBR24P \
+ )
+
#define isYUV(x) ( \
(x)==PIX_FMT_UYVY422 \
|| (x)==PIX_FMT_YUYV422 \
@@ -547,7 +609,7 @@ const char *sws_format_name(enum PixelFormat format);
)
#define isGray(x) ( \
(x)==PIX_FMT_GRAY8 \
- || (x)==PIX_FMT_Y400A \
+ || (x)==PIX_FMT_GRAY8A \
|| (x)==PIX_FMT_GRAY16BE \
|| (x)==PIX_FMT_GRAY16LE \
)
@@ -558,6 +620,8 @@ const char *sws_format_name(enum PixelFormat format);
#define isRGBinInt(x) ( \
(x)==PIX_FMT_RGB48BE \
|| (x)==PIX_FMT_RGB48LE \
+ || (x)==PIX_FMT_RGBA64BE \
+ || (x)==PIX_FMT_RGBA64LE \
|| (x)==PIX_FMT_RGB32 \
|| (x)==PIX_FMT_RGB32_1 \
|| (x)==PIX_FMT_RGB24 \
@@ -576,6 +640,8 @@ const char *sws_format_name(enum PixelFormat format);
#define isBGRinInt(x) ( \
(x)==PIX_FMT_BGR48BE \
|| (x)==PIX_FMT_BGR48LE \
+ || (x)==PIX_FMT_BGRA64BE \
+ || (x)==PIX_FMT_BGRA64LE \
|| (x)==PIX_FMT_BGR32 \
|| (x)==PIX_FMT_BGR32_1 \
|| (x)==PIX_FMT_BGR24 \
@@ -594,6 +660,8 @@ const char *sws_format_name(enum PixelFormat format);
#define isRGBinBytes(x) ( \
(x)==PIX_FMT_RGB48BE \
|| (x)==PIX_FMT_RGB48LE \
+ || (x)==PIX_FMT_RGBA64BE \
+ || (x)==PIX_FMT_RGBA64LE \
|| (x)==PIX_FMT_RGBA \
|| (x)==PIX_FMT_ARGB \
|| (x)==PIX_FMT_RGB24 \
@@ -601,6 +669,8 @@ const char *sws_format_name(enum PixelFormat format);
#define isBGRinBytes(x) ( \
(x)==PIX_FMT_BGR48BE \
|| (x)==PIX_FMT_BGR48LE \
+ || (x)==PIX_FMT_BGRA64BE \
+ || (x)==PIX_FMT_BGRA64LE \
|| (x)==PIX_FMT_BGRA \
|| (x)==PIX_FMT_ABGR \
|| (x)==PIX_FMT_BGR24 \
@@ -608,13 +678,19 @@ const char *sws_format_name(enum PixelFormat format);
#define isAnyRGB(x) ( \
isRGBinInt(x) \
|| isBGRinInt(x) \
+ || (x)==PIX_FMT_GBR24P \
)
#define isALPHA(x) ( \
- (x)==PIX_FMT_BGR32 \
+ (x)==PIX_FMT_BGRA64BE \
+ || (x)==PIX_FMT_BGRA64LE \
+ || (x)==PIX_FMT_RGBA64BE \
+ || (x)==PIX_FMT_RGBA64LE \
+ || (x)==PIX_FMT_BGR32 \
|| (x)==PIX_FMT_BGR32_1 \
|| (x)==PIX_FMT_RGB32 \
|| (x)==PIX_FMT_RGB32_1 \
- || (x)==PIX_FMT_Y400A \
+ || (x)==PIX_FMT_PAL8 \
+ || (x)==PIX_FMT_GRAY8A \
|| (x)==PIX_FMT_YUVA420P \
)
#define isPacked(x) ( \
@@ -622,12 +698,16 @@ const char *sws_format_name(enum PixelFormat format);
|| (x)==PIX_FMT_YUYV422 \
|| (x)==PIX_FMT_UYVY422 \
|| (x)==PIX_FMT_Y400A \
- || isAnyRGB(x) \
+ || isRGBinInt(x) \
+ || isBGRinInt(x) \
)
-#define usePal(x) ((av_pix_fmt_descriptors[x].flags & PIX_FMT_PAL) || (x) == PIX_FMT_Y400A)
+#define usePal(x) ((av_pix_fmt_descriptors[x].flags & PIX_FMT_PAL) || (x) == PIX_FMT_GRAY8A)
extern const uint64_t ff_dither4[2];
extern const uint64_t ff_dither8[2];
+extern const uint8_t dithers[8][8][8];
+extern const uint16_t dither_scale[15][16];
+
extern const AVClass sws_context_class;
diff --git a/libswscale/swscale_unscaled.c b/libswscale/swscale_unscaled.c
index 87cd655a46..fc75c7d5da 100644
--- a/libswscale/swscale_unscaled.c
+++ b/libswscale/swscale_unscaled.c
@@ -1,20 +1,20 @@
/*
* Copyright (C) 2001-2003 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -221,7 +221,7 @@ static int palToRgbWrapper(SwsContext *c, const uint8_t* src[], int srcStride[],
uint8_t *dstPtr= dst[0] + dstStride[0]*srcSliceY;
const uint8_t *srcPtr= src[0];
- if (srcFormat == PIX_FMT_Y400A) {
+ if (srcFormat == PIX_FMT_GRAY8A) {
switch (dstFormat) {
case PIX_FMT_RGB32 : conv = gray8aToPacked32; break;
case PIX_FMT_BGR32 : conv = gray8aToPacked32; break;
@@ -243,7 +243,7 @@ static int palToRgbWrapper(SwsContext *c, const uint8_t* src[], int srcStride[],
if (!conv)
av_log(c, AV_LOG_ERROR, "internal error %s -> %s converter\n",
- sws_format_name(srcFormat), sws_format_name(dstFormat));
+ av_get_pix_fmt_name(srcFormat), av_get_pix_fmt_name(dstFormat));
else {
for (i=0; i<srcSliceH; i++) {
conv(srcPtr, dstPtr, c->srcW, (uint8_t *) c->pal_rgb);
@@ -330,7 +330,7 @@ static int rgbToRgbWrapper(SwsContext *c, const uint8_t* src[], int srcStride[],
if (!conv) {
av_log(c, AV_LOG_ERROR, "internal error %s -> %s converter\n",
- sws_format_name(srcFormat), sws_format_name(dstFormat));
+ av_get_pix_fmt_name(srcFormat), av_get_pix_fmt_name(dstFormat));
} else {
const uint8_t *srcPtr= src[0];
uint8_t *dstPtr= dst[0];
@@ -340,7 +340,7 @@ static int rgbToRgbWrapper(SwsContext *c, const uint8_t* src[], int srcStride[],
if ((dstFormat == PIX_FMT_RGB32_1 || dstFormat == PIX_FMT_BGR32_1) && !isRGBA32(srcFormat))
dstPtr += ALT32_CORR;
- if (dstStride[0]*srcBpp == srcStride[0]*dstBpp && srcStride[0] > 0)
+ if (dstStride[0]*srcBpp == srcStride[0]*dstBpp && srcStride[0] > 0 && !(srcStride[0] % srcBpp))
conv(srcPtr, dstPtr + dstStride[0]*srcSliceY, srcSliceH*srcStride[0]);
else {
int i;
@@ -412,6 +412,28 @@ static int packedCopyWrapper(SwsContext *c, const uint8_t* src[], int srcStride[
return srcSliceH;
}
+#define DITHER_COPY(dst, dstStride, src, srcStride, bswap, dbswap)\
+ uint16_t scale= dither_scale[dst_depth-1][src_depth-1];\
+ int shift= src_depth-dst_depth + dither_scale[src_depth-2][dst_depth-1];\
+ for (i = 0; i < height; i++) {\
+ const uint8_t *dither= dithers[src_depth-9][i&7];\
+ for (j = 0; j < length-7; j+=8){\
+ dst[j+0] = dbswap((bswap(src[j+0]) + dither[0])*scale>>shift);\
+ dst[j+1] = dbswap((bswap(src[j+1]) + dither[1])*scale>>shift);\
+ dst[j+2] = dbswap((bswap(src[j+2]) + dither[2])*scale>>shift);\
+ dst[j+3] = dbswap((bswap(src[j+3]) + dither[3])*scale>>shift);\
+ dst[j+4] = dbswap((bswap(src[j+4]) + dither[4])*scale>>shift);\
+ dst[j+5] = dbswap((bswap(src[j+5]) + dither[5])*scale>>shift);\
+ dst[j+6] = dbswap((bswap(src[j+6]) + dither[6])*scale>>shift);\
+ dst[j+7] = dbswap((bswap(src[j+7]) + dither[7])*scale>>shift);\
+ }\
+ for (; j < length; j++)\
+ dst[j] = dbswap((bswap(src[j]) + dither[j&7])*scale>>shift);\
+ dst += dstStride;\
+ src += srcStride;\
+ }
+
+
static int planarCopyWrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY,
int srcSliceH, uint8_t* dst[], int dstStride[])
{
@@ -422,6 +444,7 @@ static int planarCopyWrapper(SwsContext *c, const uint8_t* src[], int srcStride[
int height= (plane==0 || plane==3) ? srcSliceH: -((-srcSliceH)>>c->chrDstVSubSample);
const uint8_t *srcPtr= src[plane];
uint8_t *dstPtr= dst[plane] + dstStride[plane]*y;
+ int shiftonly= plane==1 || plane==2 || (!c->srcRange && plane==0);
if (!dst[plane]) continue;
// ignore palette for GRAY8
@@ -431,141 +454,84 @@ static int planarCopyWrapper(SwsContext *c, const uint8_t* src[], int srcStride[
length*=2;
fillPlane(dst[plane], dstStride[plane], length, height, y, (plane==3) ? 255 : 128);
} else {
- if(is9_OR_10BPS(c->srcFormat)) {
+ if(isNBPS(c->srcFormat) || isNBPS(c->dstFormat)
+ || (is16BPS(c->srcFormat) != is16BPS(c->dstFormat))
+ ) {
const int src_depth = av_pix_fmt_descriptors[c->srcFormat].comp[plane].depth_minus1+1;
const int dst_depth = av_pix_fmt_descriptors[c->dstFormat].comp[plane].depth_minus1+1;
const uint16_t *srcPtr2 = (const uint16_t*)srcPtr;
+ uint16_t *dstPtr2 = (uint16_t*)dstPtr;
- if (is16BPS(c->dstFormat)) {
- uint16_t *dstPtr2 = (uint16_t*)dstPtr;
-#define COPY9_OR_10TO16(rfunc, wfunc) \
- for (i = 0; i < height; i++) { \
- for (j = 0; j < length; j++) { \
- int srcpx = rfunc(&srcPtr2[j]); \
- wfunc(&dstPtr2[j], (srcpx<<(16-src_depth)) | (srcpx>>(2*src_depth-16))); \
- } \
- dstPtr2 += dstStride[plane]/2; \
- srcPtr2 += srcStride[plane]/2; \
+ if (dst_depth == 8) {
+ if(isBE(c->srcFormat) == HAVE_BIGENDIAN){
+ DITHER_COPY(dstPtr, dstStride[plane], srcPtr2, srcStride[plane]/2, , )
+ } else {
+ DITHER_COPY(dstPtr, dstStride[plane], srcPtr2, srcStride[plane]/2, av_bswap16, )
}
- if (isBE(c->dstFormat)) {
- if (isBE(c->srcFormat)) {
- COPY9_OR_10TO16(AV_RB16, AV_WB16);
- } else {
- COPY9_OR_10TO16(AV_RL16, AV_WB16);
+ } else if (src_depth == 8) {
+ for (i = 0; i < height; i++) {
+ #define COPY816(w)\
+ if(shiftonly){\
+ for (j = 0; j < length; j++)\
+ w(&dstPtr2[j], srcPtr[j]<<(dst_depth-8));\
+ }else{\
+ for (j = 0; j < length; j++)\
+ w(&dstPtr2[j], (srcPtr[j]<<(dst_depth-8)) |\
+ (srcPtr[j]>>(2*8-dst_depth)));\
}
- } else {
- if (isBE(c->srcFormat)) {
- COPY9_OR_10TO16(AV_RB16, AV_WL16);
+ if(isBE(c->dstFormat)){
+ COPY816(AV_WB16)
} else {
- COPY9_OR_10TO16(AV_RL16, AV_WL16);
+ COPY816(AV_WL16)
}
+ dstPtr2 += dstStride[plane]/2;
+ srcPtr += srcStride[plane];
}
- } else if (is9_OR_10BPS(c->dstFormat)) {
- uint16_t *dstPtr2 = (uint16_t*)dstPtr;
-#define COPY9_OR_10TO9_OR_10(loop) \
- for (i = 0; i < height; i++) { \
- for (j = 0; j < length; j++) { \
- loop; \
- } \
- dstPtr2 += dstStride[plane]/2; \
- srcPtr2 += srcStride[plane]/2; \
- }
-#define COPY9_OR_10TO9_OR_10_2(rfunc, wfunc) \
- if (dst_depth > src_depth) { \
- COPY9_OR_10TO9_OR_10(int srcpx = rfunc(&srcPtr2[j]); \
- wfunc(&dstPtr2[j], (srcpx << 1) | (srcpx >> 9))); \
- } else if (dst_depth < src_depth) { \
- COPY9_OR_10TO9_OR_10(wfunc(&dstPtr2[j], rfunc(&srcPtr2[j]) >> 1)); \
- } else { \
- COPY9_OR_10TO9_OR_10(wfunc(&dstPtr2[j], rfunc(&srcPtr2[j]))); \
- }
- if (isBE(c->dstFormat)) {
- if (isBE(c->srcFormat)) {
- COPY9_OR_10TO9_OR_10_2(AV_RB16, AV_WB16);
- } else {
- COPY9_OR_10TO9_OR_10_2(AV_RL16, AV_WB16);
- }
- } else {
- if (isBE(c->srcFormat)) {
- COPY9_OR_10TO9_OR_10_2(AV_RB16, AV_WL16);
+ } else if (src_depth <= dst_depth) {
+ for (i = 0; i < height; i++) {
+#define COPY_UP(r,w) \
+ if(shiftonly){\
+ for (j = 0; j < length; j++){ \
+ unsigned int v= r(&srcPtr2[j]);\
+ w(&dstPtr2[j], v<<(dst_depth-src_depth));\
+ }\
+ }else{\
+ for (j = 0; j < length; j++){ \
+ unsigned int v= r(&srcPtr2[j]);\
+ w(&dstPtr2[j], (v<<(dst_depth-src_depth)) | \
+ (v>>(2*src_depth-dst_depth)));\
+ }\
+ }
+ if(isBE(c->srcFormat)){
+ if(isBE(c->dstFormat)){
+ COPY_UP(AV_RB16, AV_WB16)
+ } else {
+ COPY_UP(AV_RB16, AV_WL16)
+ }
} else {
- COPY9_OR_10TO9_OR_10_2(AV_RL16, AV_WL16);
+ if(isBE(c->dstFormat)){
+ COPY_UP(AV_RL16, AV_WB16)
+ } else {
+ COPY_UP(AV_RL16, AV_WL16)
+ }
}
+ dstPtr2 += dstStride[plane]/2;
+ srcPtr2 += srcStride[plane]/2;
}
} else {
- // FIXME Maybe dither instead.
-#define COPY9_OR_10TO8(rfunc) \
- for (i = 0; i < height; i++) { \
- for (j = 0; j < length; j++) { \
- dstPtr[j] = rfunc(&srcPtr2[j])>>(src_depth-8); \
- } \
- dstPtr += dstStride[plane]; \
- srcPtr2 += srcStride[plane]/2; \
- }
- if (isBE(c->srcFormat)) {
- COPY9_OR_10TO8(AV_RB16);
- } else {
- COPY9_OR_10TO8(AV_RL16);
- }
- }
- } else if(is9_OR_10BPS(c->dstFormat)) {
- const int dst_depth = av_pix_fmt_descriptors[c->dstFormat].comp[plane].depth_minus1+1;
- uint16_t *dstPtr2 = (uint16_t*)dstPtr;
-
- if (is16BPS(c->srcFormat)) {
- const uint16_t *srcPtr2 = (const uint16_t*)srcPtr;
-#define COPY16TO9_OR_10(rfunc, wfunc) \
- for (i = 0; i < height; i++) { \
- for (j = 0; j < length; j++) { \
- wfunc(&dstPtr2[j], rfunc(&srcPtr2[j])>>(16-dst_depth)); \
- } \
- dstPtr2 += dstStride[plane]/2; \
- srcPtr2 += srcStride[plane]/2; \
- }
- if (isBE(c->dstFormat)) {
- if (isBE(c->srcFormat)) {
- COPY16TO9_OR_10(AV_RB16, AV_WB16);
+ if(isBE(c->srcFormat) == HAVE_BIGENDIAN){
+ if(isBE(c->dstFormat) == HAVE_BIGENDIAN){
+ DITHER_COPY(dstPtr2, dstStride[plane]/2, srcPtr2, srcStride[plane]/2, , )
} else {
- COPY16TO9_OR_10(AV_RL16, AV_WB16);
+ DITHER_COPY(dstPtr2, dstStride[plane]/2, srcPtr2, srcStride[plane]/2, , av_bswap16)
}
- } else {
- if (isBE(c->srcFormat)) {
- COPY16TO9_OR_10(AV_RB16, AV_WL16);
+ }else{
+ if(isBE(c->dstFormat) == HAVE_BIGENDIAN){
+ DITHER_COPY(dstPtr2, dstStride[plane]/2, srcPtr2, srcStride[plane]/2, av_bswap16, )
} else {
- COPY16TO9_OR_10(AV_RL16, AV_WL16);
+ DITHER_COPY(dstPtr2, dstStride[plane]/2, srcPtr2, srcStride[plane]/2, av_bswap16, av_bswap16)
}
}
- } else /* 8bit */ {
-#define COPY8TO9_OR_10(wfunc) \
- for (i = 0; i < height; i++) { \
- for (j = 0; j < length; j++) { \
- const int srcpx = srcPtr[j]; \
- wfunc(&dstPtr2[j], (srcpx<<(dst_depth-8)) | (srcpx >> (16-dst_depth))); \
- } \
- dstPtr2 += dstStride[plane]/2; \
- srcPtr += srcStride[plane]; \
- }
- if (isBE(c->dstFormat)) {
- COPY8TO9_OR_10(AV_WB16);
- } else {
- COPY8TO9_OR_10(AV_WL16);
- }
- }
- } else if(is16BPS(c->srcFormat) && !is16BPS(c->dstFormat)) {
- if (!isBE(c->srcFormat)) srcPtr++;
- for (i=0; i<height; i++) {
- for (j=0; j<length; j++) dstPtr[j] = srcPtr[j<<1];
- srcPtr+= srcStride[plane];
- dstPtr+= dstStride[plane];
- }
- } else if(!is16BPS(c->srcFormat) && is16BPS(c->dstFormat)) {
- for (i=0; i<height; i++) {
- for (j=0; j<length; j++) {
- dstPtr[ j<<1 ] = srcPtr[j];
- dstPtr[(j<<1)+1] = srcPtr[j];
- }
- srcPtr+= srcStride[plane];
- dstPtr+= dstStride[plane];
}
} else if(is16BPS(c->srcFormat) && is16BPS(c->dstFormat)
&& isBE(c->srcFormat) != isBE(c->dstFormat)) {
@@ -706,7 +672,7 @@ static void reset_ptr(const uint8_t* src[], int format)
{
if(!isALPHA(format))
src[3]=NULL;
- if(!isPlanarYUV(format)) {
+ if(!isPlanar(format)) {
src[3]=src[2]=NULL;
if (!usePal(format))
@@ -733,18 +699,19 @@ static int check_image_pointers(uint8_t *data[4], enum PixelFormat pix_fmt,
* swscale wrapper, so we don't need to export the SwsContext.
* Assumes planar YUV to be in YUV order instead of YVU.
*/
-int sws_scale(SwsContext *c, const uint8_t* const src[], const int srcStride[], int srcSliceY,
- int srcSliceH, uint8_t* const dst[], const int dstStride[])
+int sws_scale(struct SwsContext *c, const uint8_t* const srcSlice[],
+ const int srcStride[], int srcSliceY, int srcSliceH,
+ uint8_t* const dst[], const int dstStride[])
{
int i;
- const uint8_t* src2[4]= {src[0], src[1], src[2], src[3]};
+ const uint8_t* src2[4]= {srcSlice[0], srcSlice[1], srcSlice[2], srcSlice[3]};
uint8_t* dst2[4]= {dst[0], dst[1], dst[2], dst[3]};
// do not mess up sliceDir if we have a "trailing" 0-size slice
if (srcSliceH == 0)
return 0;
- if (!check_image_pointers(src, c->srcFormat, srcStride)) {
+ if (!check_image_pointers(srcSlice, c->srcFormat, srcStride)) {
av_log(c, AV_LOG_ERROR, "bad src image pointers\n");
return 0;
}
@@ -763,9 +730,10 @@ int sws_scale(SwsContext *c, const uint8_t* const src[], const int srcStride[],
if (usePal(c->srcFormat)) {
for (i=0; i<256; i++) {
- int p, r, g, b,y,u,v;
+ int p, r, g, b, y, u, v, a = 0xff;
if(c->srcFormat == PIX_FMT_PAL8) {
- p=((const uint32_t*)(src[1]))[i];
+ p=((const uint32_t*)(srcSlice[1]))[i];
+ a= (p>>24)&0xFF;
r= (p>>16)&0xFF;
g= (p>> 8)&0xFF;
b= p &0xFF;
@@ -781,7 +749,7 @@ int sws_scale(SwsContext *c, const uint8_t* const src[], const int srcStride[],
r= (i>>3 )*255;
g= ((i>>1)&3)*85;
b= (i&1 )*255;
- } else if(c->srcFormat == PIX_FMT_GRAY8 || c->srcFormat == PIX_FMT_Y400A) {
+ } else if(c->srcFormat == PIX_FMT_GRAY8 || c->srcFormat == PIX_FMT_GRAY8A) {
r = g = b = i;
} else {
assert(c->srcFormat == PIX_FMT_BGR4_BYTE);
@@ -792,33 +760,33 @@ int sws_scale(SwsContext *c, const uint8_t* const src[], const int srcStride[],
y= av_clip_uint8((RY*r + GY*g + BY*b + ( 33<<(RGB2YUV_SHIFT-1)))>>RGB2YUV_SHIFT);
u= av_clip_uint8((RU*r + GU*g + BU*b + (257<<(RGB2YUV_SHIFT-1)))>>RGB2YUV_SHIFT);
v= av_clip_uint8((RV*r + GV*g + BV*b + (257<<(RGB2YUV_SHIFT-1)))>>RGB2YUV_SHIFT);
- c->pal_yuv[i]= y + (u<<8) + (v<<16);
+ c->pal_yuv[i]= y + (u<<8) + (v<<16) + (a<<24);
switch(c->dstFormat) {
case PIX_FMT_BGR32:
#if !HAVE_BIGENDIAN
case PIX_FMT_RGB24:
#endif
- c->pal_rgb[i]= r + (g<<8) + (b<<16);
+ c->pal_rgb[i]= r + (g<<8) + (b<<16) + (a<<24);
break;
case PIX_FMT_BGR32_1:
#if HAVE_BIGENDIAN
case PIX_FMT_BGR24:
#endif
- c->pal_rgb[i]= (r + (g<<8) + (b<<16)) << 8;
+ c->pal_rgb[i]= a + (r<<8) + (g<<16) + (b<<24);
break;
case PIX_FMT_RGB32_1:
#if HAVE_BIGENDIAN
case PIX_FMT_RGB24:
#endif
- c->pal_rgb[i]= (b + (g<<8) + (r<<16)) << 8;
+ c->pal_rgb[i]= a + (b<<8) + (g<<16) + (r<<24);
break;
case PIX_FMT_RGB32:
#if !HAVE_BIGENDIAN
case PIX_FMT_BGR24:
#endif
default:
- c->pal_rgb[i]= b + (g<<8) + (r<<16);
+ c->pal_rgb[i]= b + (g<<8) + (r<<16) + (a<<24);
}
}
}
@@ -830,7 +798,7 @@ int sws_scale(SwsContext *c, const uint8_t* const src[], const int srcStride[],
int dstStride2[4]= {dstStride[0], dstStride[1], dstStride[2], dstStride[3]};
reset_ptr(src2, c->srcFormat);
- reset_ptr((const uint8_t**)dst2, c->dstFormat);
+ reset_ptr((void*)dst2, c->dstFormat);
/* reset slice direction at end of frame */
if (srcSliceY + srcSliceH == c->srcH)
diff --git a/libswscale/utils.c b/libswscale/utils.c
index 9f0bb7a8b9..673dae0adc 100644
--- a/libswscale/utils.c
+++ b/libswscale/utils.c
@@ -1,23 +1,25 @@
/*
* Copyright (C) 2001-2003 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#define _SVID_SOURCE //needed for MAP_ANONYMOUS
+#define _DARWIN_C_SOURCE // needed for MAP_ANON
#include <inttypes.h>
#include <string.h>
#include <math.h>
@@ -44,6 +46,7 @@
#include "libavutil/bswap.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
+#include "libavutil/avassert.h"
unsigned swscale_version(void)
{
@@ -52,153 +55,118 @@ unsigned swscale_version(void)
const char *swscale_configuration(void)
{
- return LIBAV_CONFIGURATION;
+ return FFMPEG_CONFIGURATION;
}
const char *swscale_license(void)
{
#define LICENSE_PREFIX "libswscale license: "
- return LICENSE_PREFIX LIBAV_LICENSE + sizeof(LICENSE_PREFIX) - 1;
+ return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1;
}
#define RET 0xC3 //near return opcode for x86
-#define isSupportedIn(x) ( \
- (x)==PIX_FMT_YUV420P \
- || (x)==PIX_FMT_YUVA420P \
- || (x)==PIX_FMT_YUYV422 \
- || (x)==PIX_FMT_UYVY422 \
- || (x)==PIX_FMT_RGB48BE \
- || (x)==PIX_FMT_RGB48LE \
- || (x)==PIX_FMT_RGB32 \
- || (x)==PIX_FMT_RGB32_1 \
- || (x)==PIX_FMT_BGR48BE \
- || (x)==PIX_FMT_BGR48LE \
- || (x)==PIX_FMT_BGR24 \
- || (x)==PIX_FMT_BGR565LE \
- || (x)==PIX_FMT_BGR565BE \
- || (x)==PIX_FMT_BGR555LE \
- || (x)==PIX_FMT_BGR555BE \
- || (x)==PIX_FMT_BGR32 \
- || (x)==PIX_FMT_BGR32_1 \
- || (x)==PIX_FMT_RGB24 \
- || (x)==PIX_FMT_RGB565LE \
- || (x)==PIX_FMT_RGB565BE \
- || (x)==PIX_FMT_RGB555LE \
- || (x)==PIX_FMT_RGB555BE \
- || (x)==PIX_FMT_GRAY8 \
- || (x)==PIX_FMT_Y400A \
- || (x)==PIX_FMT_YUV410P \
- || (x)==PIX_FMT_YUV440P \
- || (x)==PIX_FMT_NV12 \
- || (x)==PIX_FMT_NV21 \
- || (x)==PIX_FMT_GRAY16BE \
- || (x)==PIX_FMT_GRAY16LE \
- || (x)==PIX_FMT_YUV444P \
- || (x)==PIX_FMT_YUV422P \
- || (x)==PIX_FMT_YUV411P \
- || (x)==PIX_FMT_YUVJ420P \
- || (x)==PIX_FMT_YUVJ422P \
- || (x)==PIX_FMT_YUVJ440P \
- || (x)==PIX_FMT_YUVJ444P \
- || (x)==PIX_FMT_PAL8 \
- || (x)==PIX_FMT_BGR8 \
- || (x)==PIX_FMT_RGB8 \
- || (x)==PIX_FMT_BGR4_BYTE \
- || (x)==PIX_FMT_RGB4_BYTE \
- || (x)==PIX_FMT_YUV440P \
- || (x)==PIX_FMT_MONOWHITE \
- || (x)==PIX_FMT_MONOBLACK \
- || (x)==PIX_FMT_YUV420P9LE \
- || (x)==PIX_FMT_YUV444P9LE \
- || (x)==PIX_FMT_YUV420P10LE \
- || (x)==PIX_FMT_YUV422P10LE \
- || (x)==PIX_FMT_YUV444P10LE \
- || (x)==PIX_FMT_YUV420P16LE \
- || (x)==PIX_FMT_YUV422P16LE \
- || (x)==PIX_FMT_YUV444P16LE \
- || (x)==PIX_FMT_YUV420P9BE \
- || (x)==PIX_FMT_YUV444P9BE \
- || (x)==PIX_FMT_YUV420P10BE \
- || (x)==PIX_FMT_YUV444P10BE \
- || (x)==PIX_FMT_YUV422P10BE \
- || (x)==PIX_FMT_YUV420P16BE \
- || (x)==PIX_FMT_YUV422P16BE \
- || (x)==PIX_FMT_YUV444P16BE \
- )
+typedef struct FormatEntry {
+ int is_supported_in, is_supported_out;
+} FormatEntry;
+
+const static FormatEntry format_entries[PIX_FMT_NB] = {
+ [PIX_FMT_YUV420P] = { 1 , 1 },
+ [PIX_FMT_YUYV422] = { 1 , 1 },
+ [PIX_FMT_RGB24] = { 1 , 1 },
+ [PIX_FMT_BGR24] = { 1 , 1 },
+ [PIX_FMT_YUV422P] = { 1 , 1 },
+ [PIX_FMT_YUV444P] = { 1 , 1 },
+ [PIX_FMT_YUV410P] = { 1 , 1 },
+ [PIX_FMT_YUV411P] = { 1 , 1 },
+ [PIX_FMT_GRAY8] = { 1 , 1 },
+ [PIX_FMT_MONOWHITE] = { 1 , 1 },
+ [PIX_FMT_MONOBLACK] = { 1 , 1 },
+ [PIX_FMT_PAL8] = { 1 , 0 },
+ [PIX_FMT_YUVJ420P] = { 1 , 1 },
+ [PIX_FMT_YUVJ422P] = { 1 , 1 },
+ [PIX_FMT_YUVJ444P] = { 1 , 1 },
+ [PIX_FMT_UYVY422] = { 1 , 1 },
+ [PIX_FMT_UYYVYY411] = { 0 , 0 },
+ [PIX_FMT_BGR8] = { 1 , 1 },
+ [PIX_FMT_BGR4] = { 0 , 1 },
+ [PIX_FMT_BGR4_BYTE] = { 1 , 1 },
+ [PIX_FMT_RGB8] = { 1 , 1 },
+ [PIX_FMT_RGB4] = { 0 , 1 },
+ [PIX_FMT_RGB4_BYTE] = { 1 , 1 },
+ [PIX_FMT_NV12] = { 1 , 1 },
+ [PIX_FMT_NV21] = { 1 , 1 },
+ [PIX_FMT_ARGB] = { 1 , 1 },
+ [PIX_FMT_RGBA] = { 1 , 1 },
+ [PIX_FMT_ABGR] = { 1 , 1 },
+ [PIX_FMT_BGRA] = { 1 , 1 },
+ [PIX_FMT_GRAY16BE] = { 1 , 1 },
+ [PIX_FMT_GRAY16LE] = { 1 , 1 },
+ [PIX_FMT_YUV440P] = { 1 , 1 },
+ [PIX_FMT_YUVJ440P] = { 1 , 1 },
+ [PIX_FMT_YUVA420P] = { 1 , 1 },
+ [PIX_FMT_RGB48BE] = { 1 , 1 },
+ [PIX_FMT_RGB48LE] = { 1 , 1 },
+ [PIX_FMT_RGBA64BE] = { 0 , 0 },
+ [PIX_FMT_RGBA64LE] = { 0 , 0 },
+ [PIX_FMT_RGB565BE] = { 1 , 1 },
+ [PIX_FMT_RGB565LE] = { 1 , 1 },
+ [PIX_FMT_RGB555BE] = { 1 , 1 },
+ [PIX_FMT_RGB555LE] = { 1 , 1 },
+ [PIX_FMT_BGR565BE] = { 1 , 1 },
+ [PIX_FMT_BGR565LE] = { 1 , 1 },
+ [PIX_FMT_BGR555BE] = { 1 , 1 },
+ [PIX_FMT_BGR555LE] = { 1 , 1 },
+ [PIX_FMT_YUV420P16LE] = { 1 , 1 },
+ [PIX_FMT_YUV420P16BE] = { 1 , 1 },
+ [PIX_FMT_YUV422P16LE] = { 1 , 1 },
+ [PIX_FMT_YUV422P16BE] = { 1 , 1 },
+ [PIX_FMT_YUV444P16LE] = { 1 , 1 },
+ [PIX_FMT_YUV444P16BE] = { 1 , 1 },
+ [PIX_FMT_RGB444LE] = { 0 , 1 },
+ [PIX_FMT_RGB444BE] = { 0 , 1 },
+ [PIX_FMT_BGR444LE] = { 0 , 1 },
+ [PIX_FMT_BGR444BE] = { 0 , 1 },
+ [PIX_FMT_Y400A] = { 1 , 0 },
+ [PIX_FMT_BGR48BE] = { 1 , 1 },
+ [PIX_FMT_BGR48LE] = { 1 , 1 },
+ [PIX_FMT_BGRA64BE] = { 0 , 0 },
+ [PIX_FMT_BGRA64LE] = { 0 , 0 },
+ [PIX_FMT_YUV420P9BE] = { 1 , 1 },
+ [PIX_FMT_YUV420P9LE] = { 1 , 1 },
+ [PIX_FMT_YUV420P10BE] = { 1 , 1 },
+ [PIX_FMT_YUV420P10LE] = { 1 , 1 },
+ [PIX_FMT_YUV422P9BE] = { 1 , 1 },
+ [PIX_FMT_YUV422P9LE] = { 1 , 1 },
+ [PIX_FMT_YUV422P10BE] = { 1 , 1 },
+ [PIX_FMT_YUV422P10LE] = { 1 , 1 },
+ [PIX_FMT_YUV444P9BE] = { 1 , 1 },
+ [PIX_FMT_YUV444P9LE] = { 1 , 1 },
+ [PIX_FMT_YUV444P10BE] = { 1 , 1 },
+ [PIX_FMT_YUV444P10LE] = { 1 , 1 },
+ [PIX_FMT_GBR24P] = { 1 , 0 },
+};
int sws_isSupportedInput(enum PixelFormat pix_fmt)
{
- return isSupportedIn(pix_fmt);
+ return (unsigned)pix_fmt < PIX_FMT_NB ?
+ format_entries[pix_fmt].is_supported_in : 0;
}
-#define isSupportedOut(x) ( \
- (x)==PIX_FMT_YUV420P \
- || (x)==PIX_FMT_YUVA420P \
- || (x)==PIX_FMT_YUYV422 \
- || (x)==PIX_FMT_UYVY422 \
- || (x)==PIX_FMT_YUV444P \
- || (x)==PIX_FMT_YUV422P \
- || (x)==PIX_FMT_YUV411P \
- || (x)==PIX_FMT_YUVJ420P \
- || (x)==PIX_FMT_YUVJ422P \
- || (x)==PIX_FMT_YUVJ440P \
- || (x)==PIX_FMT_YUVJ444P \
- || isRGBinBytes(x) \
- || isBGRinBytes(x) \
- || (x)==PIX_FMT_RGB565LE \
- || (x)==PIX_FMT_RGB565BE \
- || (x)==PIX_FMT_RGB555LE \
- || (x)==PIX_FMT_RGB555BE \
- || (x)==PIX_FMT_RGB444LE \
- || (x)==PIX_FMT_RGB444BE \
- || (x)==PIX_FMT_BGR565LE \
- || (x)==PIX_FMT_BGR565BE \
- || (x)==PIX_FMT_BGR555LE \
- || (x)==PIX_FMT_BGR555BE \
- || (x)==PIX_FMT_BGR444LE \
- || (x)==PIX_FMT_BGR444BE \
- || (x)==PIX_FMT_RGB8 \
- || (x)==PIX_FMT_BGR8 \
- || (x)==PIX_FMT_RGB4_BYTE \
- || (x)==PIX_FMT_BGR4_BYTE \
- || (x)==PIX_FMT_RGB4 \
- || (x)==PIX_FMT_BGR4 \
- || (x)==PIX_FMT_MONOBLACK \
- || (x)==PIX_FMT_MONOWHITE \
- || (x)==PIX_FMT_NV12 \
- || (x)==PIX_FMT_NV21 \
- || (x)==PIX_FMT_GRAY16BE \
- || (x)==PIX_FMT_GRAY16LE \
- || (x)==PIX_FMT_GRAY8 \
- || (x)==PIX_FMT_YUV410P \
- || (x)==PIX_FMT_YUV440P \
- || (x)==PIX_FMT_YUV420P9LE \
- || (x)==PIX_FMT_YUV420P10LE \
- || (x)==PIX_FMT_YUV420P16LE \
- || (x)==PIX_FMT_YUV422P16LE \
- || (x)==PIX_FMT_YUV444P16LE \
- || (x)==PIX_FMT_YUV420P9BE \
- || (x)==PIX_FMT_YUV420P10BE \
- || (x)==PIX_FMT_YUV420P16BE \
- || (x)==PIX_FMT_YUV422P16BE \
- || (x)==PIX_FMT_YUV444P16BE \
- )
-
int sws_isSupportedOutput(enum PixelFormat pix_fmt)
{
- return isSupportedOut(pix_fmt);
+ return (unsigned)pix_fmt < PIX_FMT_NB ?
+ format_entries[pix_fmt].is_supported_out : 0;
}
extern const int32_t ff_yuv2rgb_coeffs[8][4];
+#if FF_API_SWS_FORMAT_NAME
const char *sws_format_name(enum PixelFormat format)
{
- if ((unsigned)format < PIX_FMT_NB && av_pix_fmt_descriptors[format].name)
- return av_pix_fmt_descriptors[format].name;
- else
- return "Unknown format";
+ return av_get_pix_fmt_name(format);
}
+#endif
static double getSplineCoeff(double a, double b, double c, double d, double dist)
{
@@ -225,8 +193,8 @@ static int initFilter(int16_t **outFilter, int16_t **filterPos, int *outFilterSi
emms_c(); //FIXME this should not be required but it IS (even for non-MMX versions)
- // NOTE: the +1 is for the MMX scaler which reads over the end
- FF_ALLOC_OR_GOTO(NULL, *filterPos, (dstW+1)*sizeof(int16_t), fail);
+ // NOTE: the +3 is for the MMX(+1)/SSE(+3) scaler which reads over the end
+ FF_ALLOC_OR_GOTO(NULL, *filterPos, (dstW+3)*sizeof(int16_t), fail);
if (FFABS(xInc - 0x10000) <10) { // unscaled
int i;
@@ -314,15 +282,18 @@ static int initFilter(int16_t **outFilter, int16_t **filterPos, int *outFilterSi
if (flags & SWS_BICUBIC) {
int64_t B= (param[0] != SWS_PARAM_DEFAULT ? param[0] : 0) * (1<<24);
int64_t C= (param[1] != SWS_PARAM_DEFAULT ? param[1] : 0.6) * (1<<24);
- int64_t dd = ( d*d)>>30;
- int64_t ddd= (dd*d)>>30;
- if (d < 1LL<<30)
- coeff = (12*(1<<24)-9*B-6*C)*ddd + (-18*(1<<24)+12*B+6*C)*dd + (6*(1<<24)-2*B)*(1<<30);
- else if (d < 1LL<<31)
- coeff = (-B-6*C)*ddd + (6*B+30*C)*dd + (-12*B-48*C)*d + (8*B+24*C)*(1<<30);
- else
- coeff=0.0;
+ if (d >= 1LL<<31) {
+ coeff = 0.0;
+ } else {
+ int64_t dd = (d * d) >> 30;
+ int64_t ddd = (dd * d) >> 30;
+
+ if (d < 1LL<<30)
+ coeff = (12*(1<<24)-9*B-6*C)*ddd + (-18*(1<<24)+12*B+6*C)*dd + (6*(1<<24)-2*B)*(1<<30);
+ else
+ coeff = (-B-6*C)*ddd + (6*B+30*C)*dd + (-12*B-48*C)*d + (8*B+24*C)*(1<<30);
+ }
coeff *= fone>>(30+24);
}
/* else if (flags & SWS_X) {
@@ -512,7 +483,7 @@ static int initFilter(int16_t **outFilter, int16_t **filterPos, int *outFilterSi
// Note the +1 is for the MMX scaler which reads over the end
/* align at 16 for AltiVec (needed by hScale_altivec_real) */
- FF_ALLOCZ_OR_GOTO(NULL, *outFilter, *outFilterSize*(dstW+1)*sizeof(int16_t), fail);
+ FF_ALLOCZ_OR_GOTO(NULL, *outFilter, *outFilterSize*(dstW+3)*sizeof(int16_t), fail);
/* normalize & store in outFilter */
for (i=0; i<dstW; i++) {
@@ -532,10 +503,14 @@ static int initFilter(int16_t **outFilter, int16_t **filterPos, int *outFilterSi
}
}
- (*filterPos)[dstW]= (*filterPos)[dstW-1]; // the MMX scaler will read over the end
+ (*filterPos)[dstW+0] =
+ (*filterPos)[dstW+1] =
+ (*filterPos)[dstW+2] = (*filterPos)[dstW-1]; // the MMX/SSE scaler will read over the end
for (i=0; i<*outFilterSize; i++) {
- int j= dstW*(*outFilterSize);
- (*outFilter)[j + i]= (*outFilter)[j + i - (*outFilterSize)];
+ int k= (dstW - 1) * (*outFilterSize) + i;
+ (*outFilter)[k + 1 * (*outFilterSize)] =
+ (*outFilter)[k + 2 * (*outFilterSize)] =
+ (*outFilter)[k + 3 * (*outFilterSize)] = (*outFilter)[k];
}
ret=0;
@@ -711,7 +686,9 @@ static void getSubSampleFactors(int *h, int *v, enum PixelFormat format)
*v = av_pix_fmt_descriptors[format].log2_chroma_h;
}
-int sws_setColorspaceDetails(SwsContext *c, const int inv_table[4], int srcRange, const int table[4], int dstRange, int brightness, int contrast, int saturation)
+int sws_setColorspaceDetails(struct SwsContext *c, const int inv_table[4],
+ int srcRange, const int table[4], int dstRange,
+ int brightness, int contrast, int saturation)
{
memcpy(c->srcColorspaceTable, inv_table, sizeof(int)*4);
memcpy(c->dstColorspaceTable, table, sizeof(int)*4);
@@ -734,9 +711,11 @@ int sws_setColorspaceDetails(SwsContext *c, const int inv_table[4], int srcRange
return 0;
}
-int sws_getColorspaceDetails(SwsContext *c, int **inv_table, int *srcRange, int **table, int *dstRange, int *brightness, int *contrast, int *saturation)
+int sws_getColorspaceDetails(struct SwsContext *c, int **inv_table,
+ int *srcRange, int **table, int *dstRange,
+ int *brightness, int *contrast, int *saturation)
{
- if (isYUV(c->dstFormat) || isGray(c->dstFormat)) return -1;
+ if (!c || isYUV(c->dstFormat) || isGray(c->dstFormat)) return -1;
*inv_table = c->srcColorspaceTable;
*table = c->dstColorspaceTable;
@@ -772,7 +751,7 @@ SwsContext *sws_alloc_context(void)
int sws_init_context(SwsContext *c, SwsFilter *srcFilter, SwsFilter *dstFilter)
{
- int i;
+ int i, j;
int usesVFilter, usesHFilter;
int unscaled;
SwsFilter dummyFilter= {NULL, NULL, NULL, NULL};
@@ -780,7 +759,7 @@ int sws_init_context(SwsContext *c, SwsFilter *srcFilter, SwsFilter *dstFilter)
int srcH= c->srcH;
int dstW= c->dstW;
int dstH= c->dstH;
- int dst_stride = FFALIGN(dstW * sizeof(int16_t) + 16, 16), dst_stride_px = dst_stride >> 1;
+ int dst_stride = FFALIGN(dstW * sizeof(int16_t)+66, 16);
int flags, cpu_flags;
enum PixelFormat srcFormat= c->srcFormat;
enum PixelFormat dstFormat= c->dstFormat;
@@ -792,12 +771,12 @@ int sws_init_context(SwsContext *c, SwsFilter *srcFilter, SwsFilter *dstFilter)
unscaled = (srcW == dstW && srcH == dstH);
- if (!isSupportedIn(srcFormat)) {
- av_log(c, AV_LOG_ERROR, "%s is not supported as input pixel format\n", sws_format_name(srcFormat));
+ if (!sws_isSupportedInput(srcFormat)) {
+ av_log(c, AV_LOG_ERROR, "%s is not supported as input pixel format\n", av_get_pix_fmt_name(srcFormat));
return AVERROR(EINVAL);
}
- if (!isSupportedOut(dstFormat)) {
- av_log(c, AV_LOG_ERROR, "%s is not supported as output pixel format\n", sws_format_name(dstFormat));
+ if (!sws_isSupportedOutput(dstFormat)) {
+ av_log(c, AV_LOG_ERROR, "%s is not supported as output pixel format\n", av_get_pix_fmt_name(dstFormat));
return AVERROR(EINVAL);
}
@@ -845,19 +824,6 @@ int sws_init_context(SwsContext *c, SwsFilter *srcFilter, SwsFilter *dstFilter)
getSubSampleFactors(&c->chrDstHSubSample, &c->chrDstVSubSample, dstFormat);
// reuse chroma for 2 pixels RGB/BGR unless user wants full chroma interpolation
- if (flags & SWS_FULL_CHR_H_INT &&
- dstFormat != PIX_FMT_RGBA &&
- dstFormat != PIX_FMT_ARGB &&
- dstFormat != PIX_FMT_BGRA &&
- dstFormat != PIX_FMT_ABGR &&
- dstFormat != PIX_FMT_RGB24 &&
- dstFormat != PIX_FMT_BGR24) {
- av_log(c, AV_LOG_ERROR,
- "full chroma interpolation for destination format '%s' not yet implemented\n",
- sws_format_name(dstFormat));
- flags &= ~SWS_FULL_CHR_H_INT;
- c->flags = flags;
- }
if (isAnyRGB(dstFormat) && !(flags&SWS_FULL_CHR_H_INT)) c->chrDstHSubSample=1;
// drop some chroma lines if the user wants it
@@ -885,23 +851,29 @@ int sws_init_context(SwsContext *c, SwsFilter *srcFilter, SwsFilter *dstFilter)
if (c->swScale) {
if (flags&SWS_PRINT_INFO)
av_log(c, AV_LOG_INFO, "using unscaled %s -> %s special converter\n",
- sws_format_name(srcFormat), sws_format_name(dstFormat));
+ av_get_pix_fmt_name(srcFormat), av_get_pix_fmt_name(dstFormat));
return 0;
}
}
- c->scalingBpp = FFMAX(av_pix_fmt_descriptors[srcFormat].comp[0].depth_minus1,
- av_pix_fmt_descriptors[dstFormat].comp[0].depth_minus1) >= 8 ? 16 : 8;
- if (c->scalingBpp == 16)
+ c->srcBpc = 1 + av_pix_fmt_descriptors[srcFormat].comp[0].depth_minus1;
+ if (c->srcBpc < 8)
+ c->srcBpc = 8;
+ c->dstBpc = 1 + av_pix_fmt_descriptors[dstFormat].comp[0].depth_minus1;
+ if (c->dstBpc < 8)
+ c->dstBpc = 8;
+ if (isAnyRGB(srcFormat) || srcFormat == PIX_FMT_PAL8)
+ c->srcBpc = 16;
+ if (c->dstBpc == 16)
dst_stride <<= 1;
- FF_ALLOC_OR_GOTO(c, c->formatConvBuffer, FFALIGN(srcW, 16) * 2 * c->scalingBpp >> 3, fail);
- if (HAVE_MMX2 && cpu_flags & AV_CPU_FLAG_MMX2 && c->scalingBpp == 8) {
+ FF_ALLOC_OR_GOTO(c, c->formatConvBuffer, FFALIGN(srcW*2+78, 16) * 2, fail);
+ if (HAVE_MMX2 && cpu_flags & AV_CPU_FLAG_MMX2 && c->srcBpc == 8 && c->dstBpc <= 10) {
c->canMMX2BeUsed= (dstW >=srcW && (dstW&31)==0 && (srcW&15)==0) ? 1 : 0;
if (!c->canMMX2BeUsed && dstW >=srcW && (srcW&15)==0 && (flags&SWS_FAST_BILINEAR)) {
if (flags&SWS_PRINT_INFO)
av_log(c, AV_LOG_INFO, "output width is not a multiple of 32 -> no MMX2 scaler\n");
}
- if (usesHFilter) c->canMMX2BeUsed=0;
+ if (usesHFilter || isNBPS(c->srcFormat) || is16BPS(c->srcFormat) || isAnyRGB(c->srcFormat)) c->canMMX2BeUsed=0;
}
else
c->canMMX2BeUsed=0;
@@ -921,7 +893,7 @@ int sws_init_context(SwsContext *c, SwsFilter *srcFilter, SwsFilter *dstFilter)
c->chrXInc+= 20;
}
//we don't use the x86 asm scaler if MMX is available
- else if (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) {
+ else if (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX && c->dstBpc <= 10) {
c->lumXInc = ((srcW-2)<<16)/(dstW-2) - 20;
c->chrXInc = ((c->chrSrcW-2)<<16)/(c->chrDstW-2) - 20;
}
@@ -946,7 +918,11 @@ int sws_init_context(SwsContext *c, SwsFilter *srcFilter, SwsFilter *dstFilter)
c->chrMmx2FilterCode = av_malloc(c->chrMmx2FilterCodeSize);
#endif
+#ifdef MAP_ANONYMOUS
+ if (c->lumMmx2FilterCode == MAP_FAILED || c->chrMmx2FilterCode == MAP_FAILED)
+#else
if (!c->lumMmx2FilterCode || !c->chrMmx2FilterCode)
+#endif
return AVERROR(ENOMEM);
FF_ALLOCZ_OR_GOTO(c, c->hLumFilter , (dstW /8+8)*sizeof(int16_t), fail);
FF_ALLOCZ_OR_GOTO(c, c->hChrFilter , (c->chrDstW /4+8)*sizeof(int16_t), fail);
@@ -1023,7 +999,7 @@ int sws_init_context(SwsContext *c, SwsFilter *srcFilter, SwsFilter *dstFilter)
c->vLumBufSize= c->vLumFilterSize;
c->vChrBufSize= c->vChrFilterSize;
for (i=0; i<dstH; i++) {
- int chrI= i*c->chrDstH / dstH;
+ int chrI= (int64_t)i*c->chrDstH / dstH;
int nextSlice= FFMAX(c->vLumFilterPos[i ] + c->vLumFilterSize - 1,
((c->vChrFilterPos[chrI] + c->vChrFilterSize - 1)<<c->chrSrcVSubSample));
@@ -1045,25 +1021,32 @@ int sws_init_context(SwsContext *c, SwsFilter *srcFilter, SwsFilter *dstFilter)
//Note we need at least one pixel more at the end because of the MMX code (just in case someone wanna replace the 4000/8000)
/* align at 16 bytes for AltiVec */
for (i=0; i<c->vLumBufSize; i++) {
- FF_ALLOCZ_OR_GOTO(c, c->lumPixBuf[i+c->vLumBufSize], dst_stride+1, fail);
+ FF_ALLOCZ_OR_GOTO(c, c->lumPixBuf[i+c->vLumBufSize], dst_stride+16, fail);
c->lumPixBuf[i] = c->lumPixBuf[i+c->vLumBufSize];
}
- c->uv_off = dst_stride_px;
- c->uv_offx2 = dst_stride;
+ // 64 / c->scalingBpp is the same as 16 / sizeof(scaling_intermediate)
+ c->uv_off = (dst_stride>>1) + 64 / (c->dstBpc &~ 7);
+ c->uv_offx2 = dst_stride + 16;
for (i=0; i<c->vChrBufSize; i++) {
- FF_ALLOC_OR_GOTO(c, c->chrUPixBuf[i+c->vChrBufSize], dst_stride*2+1, fail);
+ FF_ALLOC_OR_GOTO(c, c->chrUPixBuf[i+c->vChrBufSize], dst_stride*2+32, fail);
c->chrUPixBuf[i] = c->chrUPixBuf[i+c->vChrBufSize];
- c->chrVPixBuf[i] = c->chrVPixBuf[i+c->vChrBufSize] = c->chrUPixBuf[i] + dst_stride_px;
+ c->chrVPixBuf[i] = c->chrVPixBuf[i+c->vChrBufSize] = c->chrUPixBuf[i] + (dst_stride >> 1) + 8;
}
if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
for (i=0; i<c->vLumBufSize; i++) {
- FF_ALLOCZ_OR_GOTO(c, c->alpPixBuf[i+c->vLumBufSize], dst_stride+1, fail);
+ FF_ALLOCZ_OR_GOTO(c, c->alpPixBuf[i+c->vLumBufSize], dst_stride+16, fail);
c->alpPixBuf[i] = c->alpPixBuf[i+c->vLumBufSize];
}
//try to avoid drawing green stuff between the right end and the stride end
for (i=0; i<c->vChrBufSize; i++)
- memset(c->chrUPixBuf[i], 64, dst_stride*2+1);
+ if(av_pix_fmt_descriptors[c->dstFormat].comp[0].depth_minus1 == 15){
+ av_assert0(c->dstBpc > 10);
+ for(j=0; j<dst_stride/2+1; j++)
+ ((int32_t*)(c->chrUPixBuf[i]))[j] = 1<<18;
+ } else
+ for(j=0; j<dst_stride+1; j++)
+ ((int16_t*)(c->chrUPixBuf[i]))[j] = 1<<14;
assert(c->chrDstH <= dstH);
@@ -1082,7 +1065,7 @@ int sws_init_context(SwsContext *c, SwsFilter *srcFilter, SwsFilter *dstFilter)
else av_log(c, AV_LOG_INFO, "ehh flags invalid?! ");
av_log(c, AV_LOG_INFO, "from %s to %s%s ",
- sws_format_name(srcFormat),
+ av_get_pix_fmt_name(srcFormat),
#ifdef DITHER1XBPP
dstFormat == PIX_FMT_BGR555 || dstFormat == PIX_FMT_BGR565 ||
dstFormat == PIX_FMT_RGB444BE || dstFormat == PIX_FMT_RGB444LE ||
@@ -1090,7 +1073,7 @@ int sws_init_context(SwsContext *c, SwsFilter *srcFilter, SwsFilter *dstFilter)
#else
"",
#endif
- sws_format_name(dstFormat));
+ av_get_pix_fmt_name(dstFormat));
if (HAVE_MMX2 && cpu_flags & AV_CPU_FLAG_MMX2) av_log(c, AV_LOG_INFO, "using MMX2\n");
else if (HAVE_AMD3DNOW && cpu_flags & AV_CPU_FLAG_3DNOW) av_log(c, AV_LOG_INFO, "using 3DNOW\n");
@@ -1098,72 +1081,6 @@ int sws_init_context(SwsContext *c, SwsFilter *srcFilter, SwsFilter *dstFilter)
else if (HAVE_ALTIVEC && cpu_flags & AV_CPU_FLAG_ALTIVEC) av_log(c, AV_LOG_INFO, "using AltiVec\n");
else av_log(c, AV_LOG_INFO, "using C\n");
- if (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) {
- if (c->canMMX2BeUsed && (flags&SWS_FAST_BILINEAR))
- av_log(c, AV_LOG_VERBOSE, "using FAST_BILINEAR MMX2 scaler for horizontal scaling\n");
- else {
- if (c->hLumFilterSize==4)
- av_log(c, AV_LOG_VERBOSE, "using 4-tap MMX scaler for horizontal luminance scaling\n");
- else if (c->hLumFilterSize==8)
- av_log(c, AV_LOG_VERBOSE, "using 8-tap MMX scaler for horizontal luminance scaling\n");
- else
- av_log(c, AV_LOG_VERBOSE, "using n-tap MMX scaler for horizontal luminance scaling\n");
-
- if (c->hChrFilterSize==4)
- av_log(c, AV_LOG_VERBOSE, "using 4-tap MMX scaler for horizontal chrominance scaling\n");
- else if (c->hChrFilterSize==8)
- av_log(c, AV_LOG_VERBOSE, "using 8-tap MMX scaler for horizontal chrominance scaling\n");
- else
- av_log(c, AV_LOG_VERBOSE, "using n-tap MMX scaler for horizontal chrominance scaling\n");
- }
- } else {
-#if HAVE_MMX
- av_log(c, AV_LOG_VERBOSE, "using x86 asm scaler for horizontal scaling\n");
-#else
- if (flags & SWS_FAST_BILINEAR)
- av_log(c, AV_LOG_VERBOSE, "using FAST_BILINEAR C scaler for horizontal scaling\n");
- else
- av_log(c, AV_LOG_VERBOSE, "using C scaler for horizontal scaling\n");
-#endif
- }
- if (isPlanarYUV(dstFormat)) {
- if (c->vLumFilterSize==1)
- av_log(c, AV_LOG_VERBOSE, "using 1-tap %s \"scaler\" for vertical scaling (YV12 like)\n",
- (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C");
- else
- av_log(c, AV_LOG_VERBOSE, "using n-tap %s scaler for vertical scaling (YV12 like)\n",
- (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C");
- } else {
- if (c->vLumFilterSize==1 && c->vChrFilterSize==2)
- av_log(c, AV_LOG_VERBOSE, "using 1-tap %s \"scaler\" for vertical luminance scaling (BGR)\n"
- " 2-tap scaler for vertical chrominance scaling (BGR)\n",
- (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C");
- else if (c->vLumFilterSize==2 && c->vChrFilterSize==2)
- av_log(c, AV_LOG_VERBOSE, "using 2-tap linear %s scaler for vertical scaling (BGR)\n",
- (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C");
- else
- av_log(c, AV_LOG_VERBOSE, "using n-tap %s scaler for vertical scaling (BGR)\n",
- (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C");
- }
-
- if (dstFormat==PIX_FMT_BGR24)
- av_log(c, AV_LOG_VERBOSE, "using %s YV12->BGR24 converter\n",
- (HAVE_MMX2 && cpu_flags & AV_CPU_FLAG_MMX2) ? "MMX2" :
- ((HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C"));
- else if (dstFormat==PIX_FMT_RGB32)
- av_log(c, AV_LOG_VERBOSE, "using %s YV12->BGR32 converter\n",
- (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C");
- else if (dstFormat==PIX_FMT_BGR565)
- av_log(c, AV_LOG_VERBOSE, "using %s YV12->BGR16 converter\n",
- (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C");
- else if (dstFormat==PIX_FMT_BGR555)
- av_log(c, AV_LOG_VERBOSE, "using %s YV12->BGR15 converter\n",
- (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C");
- else if (dstFormat == PIX_FMT_RGB444BE || dstFormat == PIX_FMT_RGB444LE ||
- dstFormat == PIX_FMT_BGR444BE || dstFormat == PIX_FMT_BGR444LE)
- av_log(c, AV_LOG_VERBOSE, "using %s YV12->BGR12 converter\n",
- (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C");
-
av_log(c, AV_LOG_VERBOSE, "%dx%d -> %dx%d\n", srcW, srcH, dstW, dstH);
av_log(c, AV_LOG_DEBUG, "lum srcW=%d srcH=%d dstW=%d dstH=%d xInc=%d yInc=%d\n",
c->srcW, c->srcH, c->dstW, c->dstH, c->lumXInc, c->lumYInc);
@@ -1557,7 +1474,7 @@ void sws_freeContext(SwsContext *c)
#endif /* HAVE_MMX */
av_freep(&c->yuvTable);
- av_free(c->formatConvBuffer);
+ av_freep(&c->formatConvBuffer);
av_free(c);
}
diff --git a/libswscale/x86/rgb2rgb.c b/libswscale/x86/rgb2rgb.c
index 282618c301..ed7f5adb74 100644
--- a/libswscale/x86/rgb2rgb.c
+++ b/libswscale/x86/rgb2rgb.c
@@ -6,20 +6,20 @@
* Written by Nick Kurshev.
* palette & YUV & runtime CPU stuff by Michael (michaelni@gmx.at)
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libswscale/x86/rgb2rgb_template.c b/libswscale/x86/rgb2rgb_template.c
index c255610193..baef3f8ae5 100644
--- a/libswscale/x86/rgb2rgb_template.c
+++ b/libswscale/x86/rgb2rgb_template.c
@@ -7,20 +7,20 @@
* palette & YUV & runtime CPU stuff by Michael (michaelni@gmx.at)
* lot of big-endian byte order fixes by Alex Beregszaszi
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libswscale/x86/scale.asm b/libswscale/x86/scale.asm
new file mode 100644
index 0000000000..09313b926f
--- /dev/null
+++ b/libswscale/x86/scale.asm
@@ -0,0 +1,431 @@
+;******************************************************************************
+;* x86-optimized horizontal line scaling functions
+;* Copyright (c) 2011 Ronald S. Bultje <rsbultje@gmail.com>
+;*
+;* This file is part of Libav.
+;*
+;* Libav 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.
+;*
+;* Libav 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
+;* Lesser General Public License for more details.
+;*
+;* You should have received a copy of the GNU Lesser General Public
+;* License along with Libav; if not, write to the Free Software
+;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+;******************************************************************************
+
+%include "x86inc.asm"
+%include "x86util.asm"
+
+SECTION_RODATA
+
+max_19bit_int: times 4 dd 0x7ffff
+max_19bit_flt: times 4 dd 524287.0
+minshort: times 8 dw 0x8000
+unicoeff: times 4 dd 0x20000000
+
+SECTION .text
+
+;-----------------------------------------------------------------------------
+; horizontal line scaling
+;
+; void hscale<source_width>to<intermediate_nbits>_<filterSize>_<opt>
+; (SwsContext *c, int{16,32}_t *dst,
+; int dstW, const uint{8,16}_t *src,
+; const int16_t *filter,
+; const int16_t *filterPos, int filterSize);
+;
+; Scale one horizontal line. Input is either 8-bits width or 16-bits width
+; ($source_width can be either 8, 9, 10 or 16, difference is whether we have to
+; downscale before multiplying). Filter is 14-bits. Output is either 15bits
+; (in int16_t) or 19bits (in int32_t), as given in $intermediate_nbits. Each
+; output pixel is generated from $filterSize input pixels, the position of
+; the first pixel is given in filterPos[nOutputPixel].
+;-----------------------------------------------------------------------------
+
+; SCALE_FUNC source_width, intermediate_nbits, filtersize, filtersuffix, opt, n_args, n_xmm
+%macro SCALE_FUNC 7
+cglobal hscale%1to%2_%4_%5, %6, 7, %7
+%ifdef ARCH_X86_64
+ movsxd r2, r2d
+%endif ; x86-64
+%if %2 == 19
+%if mmsize == 8 ; mmx
+ mova m2, [max_19bit_int]
+%elifidn %5, sse4
+ mova m2, [max_19bit_int]
+%else ; ssse3/sse2
+ mova m2, [max_19bit_flt]
+%endif ; mmx/sse2/ssse3/sse4
+%endif ; %2 == 19
+%if %1 == 16
+ mova m6, [minshort]
+ mova m7, [unicoeff]
+%elif %1 == 8
+ pxor m3, m3
+%endif ; %1 == 8/16
+
+%if %1 == 8
+%define movlh movd
+%define movbh movh
+%define srcmul 1
+%else ; %1 == 9-16
+%define movlh movq
+%define movbh movu
+%define srcmul 2
+%endif ; %1 == 8/9-16
+
+%ifnidn %3, X
+
+ ; setup loop
+%if %3 == 8
+ shl r2, 1 ; this allows *16 (i.e. now *8) in lea instructions for the 8-tap filter
+%define r2shr 1
+%else ; %3 == 4
+%define r2shr 0
+%endif ; %3 == 8
+ lea r4, [r4+r2*8]
+%if %2 == 15
+ lea r1, [r1+r2*(2>>r2shr)]
+%else ; %2 == 19
+ lea r1, [r1+r2*(4>>r2shr)]
+%endif ; %2 == 15/19
+ lea r5, [r5+r2*(2>>r2shr)]
+ neg r2
+
+.loop:
+%if %3 == 4 ; filterSize == 4 scaling
+ ; load 2x4 or 4x4 source pixels into m0/m1
+ movsx r0, word [r5+r2*2+0] ; filterPos[0]
+ movsx r6, word [r5+r2*2+2] ; filterPos[1]
+ movlh m0, [r3+r0*srcmul] ; src[filterPos[0] + {0,1,2,3}]
+%if mmsize == 8
+ movlh m1, [r3+r6*srcmul] ; src[filterPos[1] + {0,1,2,3}]
+%else ; mmsize == 16
+%if %1 > 8
+ movhps m0, [r3+r6*srcmul] ; src[filterPos[1] + {0,1,2,3}]
+%else ; %1 == 8
+ movd m4, [r3+r6*srcmul] ; src[filterPos[1] + {0,1,2,3}]
+%endif
+ movsx r0, word [r5+r2*2+4] ; filterPos[2]
+ movsx r6, word [r5+r2*2+6] ; filterPos[3]
+ movlh m1, [r3+r0*srcmul] ; src[filterPos[2] + {0,1,2,3}]
+%if %1 > 8
+ movhps m1, [r3+r6*srcmul] ; src[filterPos[3] + {0,1,2,3}]
+%else ; %1 == 8
+ movd m5, [r3+r6*srcmul] ; src[filterPos[3] + {0,1,2,3}]
+ punpckldq m0, m4
+ punpckldq m1, m5
+%endif ; %1 == 8 && %5 <= ssse
+%endif ; mmsize == 8/16
+%if %1 == 8
+ punpcklbw m0, m3 ; byte -> word
+ punpcklbw m1, m3 ; byte -> word
+%endif ; %1 == 8
+
+ ; multiply with filter coefficients
+%if %1 == 16 ; pmaddwd needs signed adds, so this moves unsigned -> signed, we'll
+ ; add back 0x8000 * sum(coeffs) after the horizontal add
+ psubw m0, m6
+ psubw m1, m6
+%endif ; %1 == 16
+ pmaddwd m0, [r4+r2*8+mmsize*0] ; *= filter[{0,1,..,6,7}]
+ pmaddwd m1, [r4+r2*8+mmsize*1] ; *= filter[{8,9,..,14,15}]
+
+ ; add up horizontally (4 srcpix * 4 coefficients -> 1 dstpix)
+%if mmsize == 8 ; mmx
+ movq m4, m0
+ punpckldq m0, m1
+ punpckhdq m4, m1
+ paddd m0, m4
+%elifidn %5, sse2
+ mova m4, m0
+ shufps m0, m1, 10001000b
+ shufps m4, m1, 11011101b
+ paddd m0, m4
+%else ; ssse3/sse4
+ phaddd m0, m1 ; filter[{ 0, 1, 2, 3}]*src[filterPos[0]+{0,1,2,3}],
+ ; filter[{ 4, 5, 6, 7}]*src[filterPos[1]+{0,1,2,3}],
+ ; filter[{ 8, 9,10,11}]*src[filterPos[2]+{0,1,2,3}],
+ ; filter[{12,13,14,15}]*src[filterPos[3]+{0,1,2,3}]
+%endif ; mmx/sse2/ssse3/sse4
+%else ; %3 == 8, i.e. filterSize == 8 scaling
+ ; load 2x8 or 4x8 source pixels into m0, m1, m4 and m5
+ movsx r0, word [r5+r2*1+0] ; filterPos[0]
+ movsx r6, word [r5+r2*1+2] ; filterPos[1]
+ movbh m0, [r3+ r0 *srcmul] ; src[filterPos[0] + {0,1,2,3,4,5,6,7}]
+%if mmsize == 8
+ movbh m1, [r3+(r0+4)*srcmul] ; src[filterPos[0] + {4,5,6,7}]
+ movbh m4, [r3+ r6 *srcmul] ; src[filterPos[1] + {0,1,2,3}]
+ movbh m5, [r3+(r6+4)*srcmul] ; src[filterPos[1] + {4,5,6,7}]
+%else ; mmsize == 16
+ movbh m1, [r3+ r6 *srcmul] ; src[filterPos[1] + {0,1,2,3,4,5,6,7}]
+ movsx r0, word [r5+r2*1+4] ; filterPos[2]
+ movsx r6, word [r5+r2*1+6] ; filterPos[3]
+ movbh m4, [r3+ r0 *srcmul] ; src[filterPos[2] + {0,1,2,3,4,5,6,7}]
+ movbh m5, [r3+ r6 *srcmul] ; src[filterPos[3] + {0,1,2,3,4,5,6,7}]
+%endif ; mmsize == 8/16
+%if %1 == 8
+ punpcklbw m0, m3 ; byte -> word
+ punpcklbw m1, m3 ; byte -> word
+ punpcklbw m4, m3 ; byte -> word
+ punpcklbw m5, m3 ; byte -> word
+%endif ; %1 == 8
+
+ ; multiply
+%if %1 == 16 ; pmaddwd needs signed adds, so this moves unsigned -> signed, we'll
+ ; add back 0x8000 * sum(coeffs) after the horizontal add
+ psubw m0, m6
+ psubw m1, m6
+ psubw m4, m6
+ psubw m5, m6
+%endif ; %1 == 16
+ pmaddwd m0, [r4+r2*8+mmsize*0] ; *= filter[{0,1,..,6,7}]
+ pmaddwd m1, [r4+r2*8+mmsize*1] ; *= filter[{8,9,..,14,15}]
+ pmaddwd m4, [r4+r2*8+mmsize*2] ; *= filter[{16,17,..,22,23}]
+ pmaddwd m5, [r4+r2*8+mmsize*3] ; *= filter[{24,25,..,30,31}]
+
+ ; add up horizontally (8 srcpix * 8 coefficients -> 1 dstpix)
+%if mmsize == 8
+ paddd m0, m1
+ paddd m4, m5
+ movq m1, m0
+ punpckldq m0, m4
+ punpckhdq m1, m4
+ paddd m0, m1
+%elifidn %5, sse2
+%if %1 == 8
+%define mex m6
+%else
+%define mex m3
+%endif
+ ; emulate horizontal add as transpose + vertical add
+ mova mex, m0
+ punpckldq m0, m1
+ punpckhdq mex, m1
+ paddd m0, mex
+ mova m1, m4
+ punpckldq m4, m5
+ punpckhdq m1, m5
+ paddd m4, m1
+ mova m1, m0
+ punpcklqdq m0, m4
+ punpckhqdq m1, m4
+ paddd m0, m1
+%else ; ssse3/sse4
+ ; FIXME if we rearrange the filter in pairs of 4, we can
+ ; load pixels likewise and use 2 x paddd + phaddd instead
+ ; of 3 x phaddd here, faster on older cpus
+ phaddd m0, m1
+ phaddd m4, m5
+ phaddd m0, m4 ; filter[{ 0, 1,..., 6, 7}]*src[filterPos[0]+{0,1,...,6,7}],
+ ; filter[{ 8, 9,...,14,15}]*src[filterPos[1]+{0,1,...,6,7}],
+ ; filter[{16,17,...,22,23}]*src[filterPos[2]+{0,1,...,6,7}],
+ ; filter[{24,25,...,30,31}]*src[filterPos[3]+{0,1,...,6,7}]
+%endif ; mmx/sse2/ssse3/sse4
+%endif ; %3 == 4/8
+
+%else ; %3 == X, i.e. any filterSize scaling
+
+%ifidn %4, X4
+%define r6sub 4
+%else ; %4 == X || %4 == X8
+%define r6sub 0
+%endif ; %4 ==/!= X4
+%ifdef ARCH_X86_64
+ push r12
+ movsxd r6, r6d ; filterSize
+ lea r12, [r3+(r6-r6sub)*srcmul] ; &src[filterSize&~4]
+%define src_reg r11
+%define r1x r10
+%define filter2 r12
+%else ; x86-32
+ lea r0, [r3+(r6-r6sub)*srcmul] ; &src[filterSize&~4]
+ mov r6m, r0
+%define src_reg r3
+%define r1x r1
+%define filter2 r6m
+%endif ; x86-32/64
+ lea r5, [r5+r2*2]
+%if %2 == 15
+ lea r1, [r1+r2*2]
+%else ; %2 == 19
+ lea r1, [r1+r2*4]
+%endif ; %2 == 15/19
+ movifnidn r1mp, r1
+ neg r2
+
+.loop:
+ movsx r0, word [r5+r2*2+0] ; filterPos[0]
+ movsx r1x, word [r5+r2*2+2] ; filterPos[1]
+ ; FIXME maybe do 4px/iteration on x86-64 (x86-32 wouldn't have enough regs)?
+ pxor m4, m4
+ pxor m5, m5
+ mov src_reg, r3mp
+
+.innerloop:
+ ; load 2x4 (mmx) or 2x8 (sse) source pixels into m0/m1 -> m4/m5
+ movbh m0, [src_reg+r0 *srcmul] ; src[filterPos[0] + {0,1,2,3(,4,5,6,7)}]
+ movbh m1, [src_reg+(r1x+r6sub)*srcmul] ; src[filterPos[1] + {0,1,2,3(,4,5,6,7)}]
+%if %1 == 8
+ punpcklbw m0, m3
+ punpcklbw m1, m3
+%endif ; %1 == 8
+
+ ; multiply
+%if %1 == 16 ; pmaddwd needs signed adds, so this moves unsigned -> signed, we'll
+ ; add back 0x8000 * sum(coeffs) after the horizontal add
+ psubw m0, m6
+ psubw m1, m6
+%endif ; %1 == 16
+ pmaddwd m0, [r4 ] ; filter[{0,1,2,3(,4,5,6,7)}]
+ pmaddwd m1, [r4+(r6+r6sub)*2] ; filter[filtersize+{0,1,2,3(,4,5,6,7)}]
+ paddd m4, m0
+ paddd m5, m1
+ add r4, mmsize
+ add src_reg, srcmul*mmsize/2
+ cmp src_reg, filter2 ; while (src += 4) < &src[filterSize]
+ jl .innerloop
+
+%ifidn %4, X4
+ movsx r1x, word [r5+r2*2+2] ; filterPos[1]
+ movlh m0, [src_reg+r0 *srcmul] ; split last 4 srcpx of dstpx[0]
+ sub r1x, r6 ; and first 4 srcpx of dstpx[1]
+%if %1 > 8
+ movhps m0, [src_reg+(r1x+r6sub)*srcmul]
+%else ; %1 == 8
+ movd m1, [src_reg+(r1x+r6sub)*srcmul]
+ punpckldq m0, m1
+%endif ; %1 == 8 && %5 <= ssse
+%if %1 == 8
+ punpcklbw m0, m3
+%endif ; %1 == 8
+%if %1 == 16 ; pmaddwd needs signed adds, so this moves unsigned -> signed, we'll
+ ; add back 0x8000 * sum(coeffs) after the horizontal add
+ psubw m0, m6
+%endif ; %1 == 16
+ pmaddwd m0, [r4]
+%endif ; %4 == X4
+
+ lea r4, [r4+(r6+r6sub)*2]
+
+%if mmsize == 8 ; mmx
+ movq m0, m4
+ punpckldq m4, m5
+ punpckhdq m0, m5
+ paddd m0, m4
+%else ; mmsize == 16
+%ifidn %5, sse2
+ mova m1, m4
+ punpcklqdq m4, m5
+ punpckhqdq m1, m5
+ paddd m4, m1
+%else ; ssse3/sse4
+ phaddd m4, m5
+%endif ; sse2/ssse3/sse4
+%ifidn %4, X4
+ paddd m4, m0
+%endif ; %3 == X4
+%ifidn %5, sse2
+ pshufd m4, m4, 11011000b
+ movhlps m0, m4
+ paddd m0, m4
+%else ; ssse3/sse4
+ phaddd m4, m4
+ SWAP 0, 4
+%endif ; sse2/ssse3/sse4
+%endif ; mmsize == 8/16
+%endif ; %3 ==/!= X
+
+%if %1 == 16 ; add 0x8000 * sum(coeffs), i.e. back from signed -> unsigned
+ paddd m0, m7
+%endif ; %1 == 16
+
+ ; clip, store
+ psrad m0, 14 + %1 - %2
+%ifidn %3, X
+ movifnidn r1, r1mp
+%endif ; %3 == X
+%if %2 == 15
+ packssdw m0, m0
+%ifnidn %3, X
+ movh [r1+r2*(2>>r2shr)], m0
+%else ; %3 == X
+ movd [r1+r2*2], m0
+%endif ; %3 ==/!= X
+%else ; %2 == 19
+%if mmsize == 8
+ PMINSD_MMX m0, m2, m4
+%elifidn %5, sse4
+ pminsd m0, m2
+%else ; sse2/ssse3
+ cvtdq2ps m0, m0
+ minps m0, m2
+ cvtps2dq m0, m0
+%endif ; mmx/sse2/ssse3/sse4
+%ifnidn %3, X
+ mova [r1+r2*(4>>r2shr)], m0
+%else ; %3 == X
+ movq [r1+r2*4], m0
+%endif ; %3 ==/!= X
+%endif ; %2 == 15/19
+%ifnidn %3, X
+ add r2, (mmsize<<r2shr)/4 ; both 8tap and 4tap really only do 4 pixels (or for mmx: 2 pixels)
+ ; per iteration. see "shl r2,1" above as for why we do this
+%else ; %3 == X
+ add r2, 2
+%endif ; %3 ==/!= X
+ jl .loop
+%ifnidn %3, X
+ REP_RET
+%else ; %3 == X
+%ifdef ARCH_X86_64
+ pop r12
+ RET
+%else ; x86-32
+ REP_RET
+%endif ; x86-32/64
+%endif ; %3 ==/!= X
+%endmacro
+
+; SCALE_FUNCS source_width, intermediate_nbits, opt, n_xmm
+%macro SCALE_FUNCS 4
+SCALE_FUNC %1, %2, 4, 4, %3, 6, %4
+SCALE_FUNC %1, %2, 8, 8, %3, 6, %4
+%if mmsize == 8
+SCALE_FUNC %1, %2, X, X, %3, 7, %4
+%else
+SCALE_FUNC %1, %2, X, X4, %3, 7, %4
+SCALE_FUNC %1, %2, X, X8, %3, 7, %4
+%endif
+%endmacro
+
+; SCALE_FUNCS2 opt, 8_xmm_args, 9to10_xmm_args, 16_xmm_args
+%macro SCALE_FUNCS2 4
+%ifnidn %1, sse4
+SCALE_FUNCS 8, 15, %1, %2
+SCALE_FUNCS 9, 15, %1, %3
+SCALE_FUNCS 10, 15, %1, %3
+SCALE_FUNCS 14, 15, %1, %3
+SCALE_FUNCS 16, 15, %1, %4
+%endif ; !sse4
+SCALE_FUNCS 8, 19, %1, %2
+SCALE_FUNCS 9, 19, %1, %3
+SCALE_FUNCS 10, 19, %1, %3
+SCALE_FUNCS 14, 19, %1, %3
+SCALE_FUNCS 16, 19, %1, %4
+%endmacro
+
+%ifdef ARCH_X86_32
+INIT_MMX
+SCALE_FUNCS2 mmx, 0, 0, 0
+%endif
+INIT_XMM
+SCALE_FUNCS2 sse2, 6, 7, 8
+SCALE_FUNCS2 ssse3, 6, 6, 8
+SCALE_FUNCS2 sse4, 6, 6, 8
diff --git a/libswscale/x86/swscale_mmx.c b/libswscale/x86/swscale_mmx.c
index f855a75212..815055ebc9 100644
--- a/libswscale/x86/swscale_mmx.c
+++ b/libswscale/x86/swscale_mmx.c
@@ -1,20 +1,20 @@
/*
* Copyright (C) 2001-2003 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -72,14 +72,14 @@ DECLARE_ASM_CONST(8, uint64_t, ff_bgr24toY1Coeff) = 0x0C88000040870C88ULL;
DECLARE_ASM_CONST(8, uint64_t, ff_bgr24toY2Coeff) = 0x20DE4087000020DEULL;
DECLARE_ASM_CONST(8, uint64_t, ff_rgb24toY1Coeff) = 0x20DE0000408720DEULL;
DECLARE_ASM_CONST(8, uint64_t, ff_rgb24toY2Coeff) = 0x0C88408700000C88ULL;
-DECLARE_ASM_CONST(8, uint64_t, ff_bgr24toYOffset) = 0x0008400000084000ULL;
+DECLARE_ASM_CONST(8, uint64_t, ff_bgr24toYOffset) = 0x0008010000080100ULL;
DECLARE_ASM_CONST(8, uint64_t, ff_bgr24toUV)[2][4] = {
{0x38380000DAC83838ULL, 0xECFFDAC80000ECFFULL, 0xF6E40000D0E3F6E4ULL, 0x3838D0E300003838ULL},
{0xECFF0000DAC8ECFFULL, 0x3838DAC800003838ULL, 0x38380000D0E33838ULL, 0xF6E4D0E30000F6E4ULL},
};
-DECLARE_ASM_CONST(8, uint64_t, ff_bgr24toUVOffset)= 0x0040400000404000ULL;
+DECLARE_ASM_CONST(8, uint64_t, ff_bgr24toUVOffset)= 0x0040010000400100ULL;
//MMX versions
#if HAVE_MMX
@@ -176,6 +176,43 @@ void updateMMXDitherTables(SwsContext *c, int dstY, int lumBufIndex, int chrBufI
}
}
+#define SCALE_FUNC(filter_n, from_bpc, to_bpc, opt) \
+extern void ff_hscale ## from_bpc ## to ## to_bpc ## _ ## filter_n ## _ ## opt( \
+ SwsContext *c, int16_t *data, \
+ int dstW, const uint8_t *src, \
+ const int16_t *filter, \
+ const int16_t *filterPos, int filterSize);
+
+#define SCALE_FUNCS(filter_n, opt) \
+ SCALE_FUNC(filter_n, 8, 15, opt); \
+ SCALE_FUNC(filter_n, 9, 15, opt); \
+ SCALE_FUNC(filter_n, 10, 15, opt); \
+ SCALE_FUNC(filter_n, 14, 15, opt); \
+ SCALE_FUNC(filter_n, 16, 15, opt); \
+ SCALE_FUNC(filter_n, 8, 19, opt); \
+ SCALE_FUNC(filter_n, 9, 19, opt); \
+ SCALE_FUNC(filter_n, 10, 19, opt); \
+ SCALE_FUNC(filter_n, 14, 19, opt); \
+ SCALE_FUNC(filter_n, 16, 19, opt)
+
+#define SCALE_FUNCS_MMX(opt) \
+ SCALE_FUNCS(4, opt); \
+ SCALE_FUNCS(8, opt); \
+ SCALE_FUNCS(X, opt)
+
+#define SCALE_FUNCS_SSE(opt) \
+ SCALE_FUNCS(4, opt); \
+ SCALE_FUNCS(8, opt); \
+ SCALE_FUNCS(X4, opt); \
+ SCALE_FUNCS(X8, opt)
+
+#if ARCH_X86_32
+SCALE_FUNCS_MMX(mmx);
+#endif
+SCALE_FUNCS_SSE(sse2);
+SCALE_FUNCS_SSE(ssse3);
+SCALE_FUNCS_SSE(sse4);
+
void ff_sws_init_swScale_mmx(SwsContext *c)
{
int cpu_flags = av_get_cpu_flags();
@@ -186,4 +223,58 @@ void ff_sws_init_swScale_mmx(SwsContext *c)
if (cpu_flags & AV_CPU_FLAG_MMX2)
sws_init_swScale_MMX2(c);
#endif
+
+#if HAVE_YASM
+#define ASSIGN_SCALE_FUNC2(hscalefn, filtersize, opt1, opt2) do { \
+ if (c->srcBpc == 8) { \
+ hscalefn = c->dstBpc <= 10 ? ff_hscale8to15_ ## filtersize ## _ ## opt2 : \
+ ff_hscale8to19_ ## filtersize ## _ ## opt1; \
+ } else if (c->srcBpc == 9) { \
+ hscalefn = c->dstBpc <= 10 ? ff_hscale9to15_ ## filtersize ## _ ## opt2 : \
+ ff_hscale9to19_ ## filtersize ## _ ## opt1; \
+ } else if (c->srcBpc == 10) { \
+ hscalefn = c->dstBpc <= 10 ? ff_hscale10to15_ ## filtersize ## _ ## opt2 : \
+ ff_hscale10to19_ ## filtersize ## _ ## opt1; \
+ } else if (c->srcBpc == 14 || ((c->srcFormat==PIX_FMT_PAL8||isAnyRGB(c->srcFormat)) && av_pix_fmt_descriptors[c->srcFormat].comp[0].depth_minus1<15)) { \
+ hscalefn = c->dstBpc <= 10 ? ff_hscale14to15_ ## filtersize ## _ ## opt2 : \
+ ff_hscale14to19_ ## filtersize ## _ ## opt1; \
+ } else { /* c->srcBpc == 16 */ \
+ hscalefn = c->dstBpc <= 10 ? ff_hscale16to15_ ## filtersize ## _ ## opt2 : \
+ ff_hscale16to19_ ## filtersize ## _ ## opt1; \
+ } \
+} while (0)
+#define ASSIGN_MMX_SCALE_FUNC(hscalefn, filtersize, opt1, opt2) \
+ switch (filtersize) { \
+ case 4: ASSIGN_SCALE_FUNC2(hscalefn, 4, opt1, opt2); break; \
+ case 8: ASSIGN_SCALE_FUNC2(hscalefn, 8, opt1, opt2); break; \
+ default: ASSIGN_SCALE_FUNC2(hscalefn, X, opt1, opt2); break; \
+ }
+#if ARCH_X86_32
+ if (cpu_flags & AV_CPU_FLAG_MMX) {
+ ASSIGN_MMX_SCALE_FUNC(c->hyScale, c->hLumFilterSize, mmx, mmx);
+ ASSIGN_MMX_SCALE_FUNC(c->hcScale, c->hChrFilterSize, mmx, mmx);
+ }
+#endif
+#define ASSIGN_SSE_SCALE_FUNC(hscalefn, filtersize, opt1, opt2) \
+ switch (filtersize) { \
+ case 4: ASSIGN_SCALE_FUNC2(hscalefn, 4, opt1, opt2); break; \
+ case 8: ASSIGN_SCALE_FUNC2(hscalefn, 8, opt1, opt2); break; \
+ default: if (filtersize & 4) ASSIGN_SCALE_FUNC2(hscalefn, X4, opt1, opt2); \
+ else ASSIGN_SCALE_FUNC2(hscalefn, X8, opt1, opt2); \
+ break; \
+ }
+ if (cpu_flags & AV_CPU_FLAG_SSE2) {
+ ASSIGN_SSE_SCALE_FUNC(c->hyScale, c->hLumFilterSize, sse2, sse2);
+ ASSIGN_SSE_SCALE_FUNC(c->hcScale, c->hChrFilterSize, sse2, sse2);
+ }
+ if (cpu_flags & AV_CPU_FLAG_SSSE3) {
+ ASSIGN_SSE_SCALE_FUNC(c->hyScale, c->hLumFilterSize, ssse3, ssse3);
+ ASSIGN_SSE_SCALE_FUNC(c->hcScale, c->hChrFilterSize, ssse3, ssse3);
+ }
+ if (cpu_flags & AV_CPU_FLAG_SSE4) {
+ /* Xto15 don't need special sse4 functions */
+ ASSIGN_SSE_SCALE_FUNC(c->hyScale, c->hLumFilterSize, sse4, ssse3);
+ ASSIGN_SSE_SCALE_FUNC(c->hcScale, c->hChrFilterSize, sse4, ssse3);
+ }
+#endif
}
diff --git a/libswscale/x86/swscale_template.c b/libswscale/x86/swscale_template.c
index f58ac520e1..c934c7895b 100644
--- a/libswscale/x86/swscale_template.c
+++ b/libswscale/x86/swscale_template.c
@@ -1,20 +1,20 @@
/*
* Copyright (C) 2001-2003 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -37,8 +37,8 @@
#define YSCALEYUV2YV12X(offset, dest, end, pos) \
__asm__ volatile(\
- "movq "VROUNDER_OFFSET"(%0), %%mm3 \n\t"\
- "movq %%mm3, %%mm4 \n\t"\
+ "movq "DITHER16"+0(%0), %%mm3 \n\t"\
+ "movq "DITHER16"+8(%0), %%mm4 \n\t"\
"lea " offset "(%0), %%"REG_d" \n\t"\
"mov (%%"REG_d"), %%"REG_S" \n\t"\
".p2align 4 \n\t" /* FIXME Unroll? */\
@@ -60,8 +60,8 @@
MOVNTQ(%%mm3, (%1, %3))\
"add $8, %3 \n\t"\
"cmp %2, %3 \n\t"\
- "movq "VROUNDER_OFFSET"(%0), %%mm3 \n\t"\
- "movq %%mm3, %%mm4 \n\t"\
+ "movq "DITHER16"+0(%0), %%mm3 \n\t"\
+ "movq "DITHER16"+8(%0), %%mm4 \n\t"\
"lea " offset "(%0), %%"REG_d" \n\t"\
"mov (%%"REG_d"), %%"REG_S" \n\t"\
"jb 1b \n\t"\
@@ -70,6 +70,42 @@
: "%"REG_d, "%"REG_S\
);
+#if !COMPILE_TEMPLATE_MMX2
+static av_always_inline void
+dither_8to16(SwsContext *c, const uint8_t *srcDither, int rot)
+{
+ if (rot) {
+ __asm__ volatile("pxor %%mm0, %%mm0\n\t"
+ "movq (%0), %%mm3\n\t"
+ "movq %%mm3, %%mm4\n\t"
+ "psrlq $24, %%mm3\n\t"
+ "psllq $40, %%mm4\n\t"
+ "por %%mm4, %%mm3\n\t"
+ "movq %%mm3, %%mm4\n\t"
+ "punpcklbw %%mm0, %%mm3\n\t"
+ "punpckhbw %%mm0, %%mm4\n\t"
+ "psraw $4, %%mm3\n\t"
+ "psraw $4, %%mm4\n\t"
+ "movq %%mm3, "DITHER16"+0(%1)\n\t"
+ "movq %%mm4, "DITHER16"+8(%1)\n\t"
+ :: "r"(srcDither), "r"(&c->redDither)
+ );
+ } else {
+ __asm__ volatile("pxor %%mm0, %%mm0\n\t"
+ "movq (%0), %%mm3\n\t"
+ "movq %%mm3, %%mm4\n\t"
+ "punpcklbw %%mm0, %%mm3\n\t"
+ "punpckhbw %%mm0, %%mm4\n\t"
+ "psraw $4, %%mm3\n\t"
+ "psraw $4, %%mm4\n\t"
+ "movq %%mm3, "DITHER16"+0(%1)\n\t"
+ "movq %%mm4, "DITHER16"+8(%1)\n\t"
+ :: "r"(srcDither), "r"(&c->redDither)
+ );
+ }
+}
+#endif
+
static void RENAME(yuv2yuvX)(SwsContext *c, const int16_t *lumFilter,
const int16_t **lumSrc, int lumFilterSize,
const int16_t *chrFilter, const int16_t **chrUSrc,
@@ -79,12 +115,16 @@ static void RENAME(yuv2yuvX)(SwsContext *c, const int16_t *lumFilter,
{
uint8_t *yDest = dest[0], *uDest = dest[1], *vDest = dest[2],
*aDest = CONFIG_SWSCALE_ALPHA ? dest[3] : NULL;
+ const uint8_t *lumDither = c->lumDither8, *chrDither = c->chrDither8;
if (uDest) {
- x86_reg uv_off = c->uv_off;
+ x86_reg uv_off = c->uv_offx2 >> 1;
+ dither_8to16(c, chrDither, 0);
YSCALEYUV2YV12X(CHR_MMX_FILTER_OFFSET, uDest, chrDstW, 0)
+ dither_8to16(c, chrDither, 1);
YSCALEYUV2YV12X(CHR_MMX_FILTER_OFFSET, vDest - uv_off, chrDstW + uv_off, uv_off)
}
+ dither_8to16(c, lumDither, 0);
if (CONFIG_SWSCALE_ALPHA && aDest) {
YSCALEYUV2YV12X(ALP_MMX_FILTER_OFFSET, aDest, dstW, 0)
}
@@ -95,10 +135,10 @@ static void RENAME(yuv2yuvX)(SwsContext *c, const int16_t *lumFilter,
#define YSCALEYUV2YV12X_ACCURATE(offset, dest, end, pos) \
__asm__ volatile(\
"lea " offset "(%0), %%"REG_d" \n\t"\
- "pxor %%mm4, %%mm4 \n\t"\
- "pxor %%mm5, %%mm5 \n\t"\
- "pxor %%mm6, %%mm6 \n\t"\
- "pxor %%mm7, %%mm7 \n\t"\
+ "movq "DITHER32"+0(%0), %%mm4 \n\t"\
+ "movq "DITHER32"+8(%0), %%mm5 \n\t"\
+ "movq "DITHER32"+16(%0), %%mm6 \n\t"\
+ "movq "DITHER32"+24(%0), %%mm7 \n\t"\
"mov (%%"REG_d"), %%"REG_S" \n\t"\
".p2align 4 \n\t"\
"1: \n\t"\
@@ -126,26 +166,21 @@ static void RENAME(yuv2yuvX)(SwsContext *c, const int16_t *lumFilter,
"paddd %%mm2, %%mm6 \n\t"\
"paddd %%mm0, %%mm7 \n\t"\
" jnz 1b \n\t"\
- "psrad $16, %%mm4 \n\t"\
- "psrad $16, %%mm5 \n\t"\
- "psrad $16, %%mm6 \n\t"\
- "psrad $16, %%mm7 \n\t"\
- "movq "VROUNDER_OFFSET"(%0), %%mm0 \n\t"\
+ "psrad $19, %%mm4 \n\t"\
+ "psrad $19, %%mm5 \n\t"\
+ "psrad $19, %%mm6 \n\t"\
+ "psrad $19, %%mm7 \n\t"\
"packssdw %%mm5, %%mm4 \n\t"\
"packssdw %%mm7, %%mm6 \n\t"\
- "paddw %%mm0, %%mm4 \n\t"\
- "paddw %%mm0, %%mm6 \n\t"\
- "psraw $3, %%mm4 \n\t"\
- "psraw $3, %%mm6 \n\t"\
"packuswb %%mm6, %%mm4 \n\t"\
MOVNTQ(%%mm4, (%1, %3))\
"add $8, %3 \n\t"\
"cmp %2, %3 \n\t"\
"lea " offset "(%0), %%"REG_d" \n\t"\
- "pxor %%mm4, %%mm4 \n\t"\
- "pxor %%mm5, %%mm5 \n\t"\
- "pxor %%mm6, %%mm6 \n\t"\
- "pxor %%mm7, %%mm7 \n\t"\
+ "movq "DITHER32"+0(%0), %%mm4 \n\t"\
+ "movq "DITHER32"+8(%0), %%mm5 \n\t"\
+ "movq "DITHER32"+16(%0), %%mm6 \n\t"\
+ "movq "DITHER32"+24(%0), %%mm7 \n\t"\
"mov (%%"REG_d"), %%"REG_S" \n\t"\
"jb 1b \n\t"\
:: "r" (&c->redDither),\
@@ -153,6 +188,62 @@ static void RENAME(yuv2yuvX)(SwsContext *c, const int16_t *lumFilter,
: "%"REG_a, "%"REG_d, "%"REG_S\
);
+#if !COMPILE_TEMPLATE_MMX2
+static av_always_inline void
+dither_8to32(SwsContext *c, const uint8_t *srcDither, int rot)
+{
+ if (rot) {
+ __asm__ volatile("pxor %%mm0, %%mm0\n\t"
+ "movq (%0), %%mm4\n\t"
+ "movq %%mm4, %%mm5\n\t"
+ "psrlq $24, %%mm4\n\t"
+ "psllq $40, %%mm5\n\t"
+ "por %%mm5, %%mm4\n\t"
+ "movq %%mm4, %%mm6\n\t"
+ "punpcklbw %%mm0, %%mm4\n\t"
+ "punpckhbw %%mm0, %%mm6\n\t"
+ "movq %%mm4, %%mm5\n\t"
+ "movq %%mm6, %%mm7\n\t"
+ "punpcklwd %%mm0, %%mm4\n\t"
+ "punpckhwd %%mm0, %%mm5\n\t"
+ "punpcklwd %%mm0, %%mm6\n\t"
+ "punpckhwd %%mm0, %%mm7\n\t"
+ "pslld $12, %%mm4\n\t"
+ "pslld $12, %%mm5\n\t"
+ "pslld $12, %%mm6\n\t"
+ "pslld $12, %%mm7\n\t"
+ "movq %%mm4, "DITHER32"+0(%1)\n\t"
+ "movq %%mm5, "DITHER32"+8(%1)\n\t"
+ "movq %%mm6, "DITHER32"+16(%1)\n\t"
+ "movq %%mm7, "DITHER32"+24(%1)\n\t"
+ :: "r"(srcDither), "r"(&c->redDither)
+ );
+ } else {
+ __asm__ volatile("pxor %%mm0, %%mm0\n\t"
+ "movq (%0), %%mm4\n\t"
+ "movq %%mm4, %%mm6\n\t"
+ "punpcklbw %%mm0, %%mm4\n\t"
+ "punpckhbw %%mm0, %%mm6\n\t"
+ "movq %%mm4, %%mm5\n\t"
+ "movq %%mm6, %%mm7\n\t"
+ "punpcklwd %%mm0, %%mm4\n\t"
+ "punpckhwd %%mm0, %%mm5\n\t"
+ "punpcklwd %%mm0, %%mm6\n\t"
+ "punpckhwd %%mm0, %%mm7\n\t"
+ "pslld $12, %%mm4\n\t"
+ "pslld $12, %%mm5\n\t"
+ "pslld $12, %%mm6\n\t"
+ "pslld $12, %%mm7\n\t"
+ "movq %%mm4, "DITHER32"+0(%1)\n\t"
+ "movq %%mm5, "DITHER32"+8(%1)\n\t"
+ "movq %%mm6, "DITHER32"+16(%1)\n\t"
+ "movq %%mm7, "DITHER32"+24(%1)\n\t"
+ :: "r"(srcDither), "r"(&c->redDither)
+ );
+ }
+}
+#endif
+
static void RENAME(yuv2yuvX_ar)(SwsContext *c, const int16_t *lumFilter,
const int16_t **lumSrc, int lumFilterSize,
const int16_t *chrFilter, const int16_t **chrUSrc,
@@ -162,12 +253,16 @@ static void RENAME(yuv2yuvX_ar)(SwsContext *c, const int16_t *lumFilter,
{
uint8_t *yDest = dest[0], *uDest = dest[1], *vDest = dest[2],
*aDest = CONFIG_SWSCALE_ALPHA ? dest[3] : NULL;
+ const uint8_t *lumDither = c->lumDither8, *chrDither = c->chrDither8;
if (uDest) {
- x86_reg uv_off = c->uv_off;
+ x86_reg uv_off = c->uv_offx2 >> 1;
+ dither_8to32(c, chrDither, 0);
YSCALEYUV2YV12X_ACCURATE(CHR_MMX_FILTER_OFFSET, uDest, chrDstW, 0)
+ dither_8to32(c, chrDither, 1);
YSCALEYUV2YV12X_ACCURATE(CHR_MMX_FILTER_OFFSET, vDest - uv_off, chrDstW + uv_off, uv_off)
}
+ dither_8to32(c, lumDither, 0);
if (CONFIG_SWSCALE_ALPHA && aDest) {
YSCALEYUV2YV12X_ACCURATE(ALP_MMX_FILTER_OFFSET, aDest, dstW, 0)
}
@@ -220,19 +315,21 @@ static void RENAME(yuv2yuv1_ar)(SwsContext *c, const int16_t *lumSrc,
chrVSrc + chrDstW, alpSrc + dstW
};
x86_reg counter[4]= { dstW, chrDstW, chrDstW, dstW };
+ const uint8_t *lumDither = c->lumDither8, *chrDither = c->chrDither8;
while (p--) {
if (dst[p]) {
+ int i;
+ for(i=0; i<8; i++) c->dither16[i] = (p == 2 || p == 3) ? lumDither[i] : chrDither[i];
__asm__ volatile(
"mov %2, %%"REG_a" \n\t"
- "pcmpeqw %%mm7, %%mm7 \n\t"
- "psrlw $15, %%mm7 \n\t"
- "psllw $6, %%mm7 \n\t"
+ "movq "DITHER16"+0(%3), %%mm6 \n\t"
+ "movq "DITHER16"+8(%3), %%mm7 \n\t"
".p2align 4 \n\t" /* FIXME Unroll? */
"1: \n\t"
"movq (%0, %%"REG_a", 2), %%mm0 \n\t"
"movq 8(%0, %%"REG_a", 2), %%mm1 \n\t"
- "paddsw %%mm7, %%mm0 \n\t"
+ "paddsw %%mm6, %%mm0 \n\t"
"paddsw %%mm7, %%mm1 \n\t"
"psraw $7, %%mm0 \n\t"
"psraw $7, %%mm1 \n\t"
@@ -241,7 +338,7 @@ static void RENAME(yuv2yuv1_ar)(SwsContext *c, const int16_t *lumSrc,
"add $8, %%"REG_a" \n\t"
"jnc 1b \n\t"
:: "r" (src[p]), "r" (dst[p] + counter[p]),
- "g" (-counter[p])
+ "g" (-counter[p]), "r"(&c->redDither)
: "%"REG_a
);
}
@@ -473,7 +570,7 @@ static void RENAME(yuv2rgb32_X_ar)(SwsContext *c, const int16_t *lumFilter,
{
x86_reg dummy=0;
x86_reg dstW_reg = dstW;
- x86_reg uv_off = c->uv_off << 1;
+ x86_reg uv_off = c->uv_offx2;
if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) {
YSCALEYUV2PACKEDX_ACCURATE
@@ -506,7 +603,7 @@ static void RENAME(yuv2rgb32_X)(SwsContext *c, const int16_t *lumFilter,
{
x86_reg dummy=0;
x86_reg dstW_reg = dstW;
- x86_reg uv_off = c->uv_off << 1;
+ x86_reg uv_off = c->uv_offx2;
if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) {
YSCALEYUV2PACKEDX
@@ -563,7 +660,7 @@ static void RENAME(yuv2rgb565_X_ar)(SwsContext *c, const int16_t *lumFilter,
{
x86_reg dummy=0;
x86_reg dstW_reg = dstW;
- x86_reg uv_off = c->uv_off << 1;
+ x86_reg uv_off = c->uv_offx2;
YSCALEYUV2PACKEDX_ACCURATE
YSCALEYUV2RGBX
@@ -587,7 +684,7 @@ static void RENAME(yuv2rgb565_X)(SwsContext *c, const int16_t *lumFilter,
{
x86_reg dummy=0;
x86_reg dstW_reg = dstW;
- x86_reg uv_off = c->uv_off << 1;
+ x86_reg uv_off = c->uv_offx2;
YSCALEYUV2PACKEDX
YSCALEYUV2RGBX
@@ -640,7 +737,7 @@ static void RENAME(yuv2rgb555_X_ar)(SwsContext *c, const int16_t *lumFilter,
{
x86_reg dummy=0;
x86_reg dstW_reg = dstW;
- x86_reg uv_off = c->uv_off << 1;
+ x86_reg uv_off = c->uv_offx2;
YSCALEYUV2PACKEDX_ACCURATE
YSCALEYUV2RGBX
@@ -664,7 +761,7 @@ static void RENAME(yuv2rgb555_X)(SwsContext *c, const int16_t *lumFilter,
{
x86_reg dummy=0;
x86_reg dstW_reg = dstW;
- x86_reg uv_off = c->uv_off << 1;
+ x86_reg uv_off = c->uv_offx2;
YSCALEYUV2PACKEDX
YSCALEYUV2RGBX
@@ -797,7 +894,7 @@ static void RENAME(yuv2bgr24_X_ar)(SwsContext *c, const int16_t *lumFilter,
{
x86_reg dummy=0;
x86_reg dstW_reg = dstW;
- x86_reg uv_off = c->uv_off << 1;
+ x86_reg uv_off = c->uv_offx2;
YSCALEYUV2PACKEDX_ACCURATE
YSCALEYUV2RGBX
@@ -821,7 +918,7 @@ static void RENAME(yuv2bgr24_X)(SwsContext *c, const int16_t *lumFilter,
{
x86_reg dummy=0;
x86_reg dstW_reg = dstW;
- x86_reg uv_off = c->uv_off << 1;
+ x86_reg uv_off = c->uv_offx2;
YSCALEYUV2PACKEDX
YSCALEYUV2RGBX
@@ -862,7 +959,7 @@ static void RENAME(yuv2yuyv422_X_ar)(SwsContext *c, const int16_t *lumFilter,
{
x86_reg dummy=0;
x86_reg dstW_reg = dstW;
- x86_reg uv_off = c->uv_off << 1;
+ x86_reg uv_off = c->uv_offx2;
YSCALEYUV2PACKEDX_ACCURATE
/* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
@@ -883,7 +980,7 @@ static void RENAME(yuv2yuyv422_X)(SwsContext *c, const int16_t *lumFilter,
{
x86_reg dummy=0;
x86_reg dstW_reg = dstW;
- x86_reg uv_off = c->uv_off << 1;
+ x86_reg uv_off = c->uv_offx2;
YSCALEYUV2PACKEDX
/* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
@@ -999,8 +1096,8 @@ static void RENAME(yuv2rgb32_2)(SwsContext *c, const int16_t *buf[2],
: "%r8"
);
#else
- *(const uint16_t **)(&c->u_temp)=abuf0;
- *(const uint16_t **)(&c->v_temp)=abuf1;
+ c->u_temp=(intptr_t)abuf0;
+ c->v_temp=(intptr_t)abuf1;
__asm__ volatile(
"mov %%"REG_b", "ESP_OFFSET"(%5) \n\t"
"mov %4, %%"REG_b" \n\t"
@@ -1577,7 +1674,7 @@ static void RENAME(yuv2yuyv422_1)(SwsContext *c, const int16_t *buf0,
#if !COMPILE_TEMPLATE_MMX2
//FIXME yuy2* can read up to 7 samples too much
-static void RENAME(yuy2ToY)(uint8_t *dst, const uint8_t *src,
+static void RENAME(yuy2ToY)(uint8_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2,
int width, uint32_t *unused)
{
__asm__ volatile(
@@ -1598,7 +1695,7 @@ static void RENAME(yuy2ToY)(uint8_t *dst, const uint8_t *src,
}
static void RENAME(yuy2ToUV)(uint8_t *dstU, uint8_t *dstV,
- const uint8_t *src1, const uint8_t *src2,
+ const uint8_t *unused1, const uint8_t *src1, const uint8_t *src2,
int width, uint32_t *unused)
{
__asm__ volatile(
@@ -1627,7 +1724,7 @@ static void RENAME(yuy2ToUV)(uint8_t *dstU, uint8_t *dstV,
/* This is almost identical to the previous, end exists only because
* yuy2ToY/UV)(dst, src+1, ...) would have 100% unaligned accesses. */
-static void RENAME(uyvyToY)(uint8_t *dst, const uint8_t *src,
+static void RENAME(uyvyToY)(uint8_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2,
int width, uint32_t *unused)
{
__asm__ volatile(
@@ -1647,7 +1744,7 @@ static void RENAME(uyvyToY)(uint8_t *dst, const uint8_t *src,
}
static void RENAME(uyvyToUV)(uint8_t *dstU, uint8_t *dstV,
- const uint8_t *src1, const uint8_t *src2,
+ const uint8_t *unused1, const uint8_t *src1, const uint8_t *src2,
int width, uint32_t *unused)
{
__asm__ volatile(
@@ -1701,21 +1798,21 @@ static av_always_inline void RENAME(nvXXtoUV)(uint8_t *dst1, uint8_t *dst2,
}
static void RENAME(nv12ToUV)(uint8_t *dstU, uint8_t *dstV,
- const uint8_t *src1, const uint8_t *src2,
+ const uint8_t *unused1, const uint8_t *src1, const uint8_t *src2,
int width, uint32_t *unused)
{
RENAME(nvXXtoUV)(dstU, dstV, src1, width);
}
static void RENAME(nv21ToUV)(uint8_t *dstU, uint8_t *dstV,
- const uint8_t *src1, const uint8_t *src2,
+ const uint8_t *unused1, const uint8_t *src1, const uint8_t *src2,
int width, uint32_t *unused)
{
RENAME(nvXXtoUV)(dstV, dstU, src1, width);
}
#endif /* !COMPILE_TEMPLATE_MMX2 */
-static av_always_inline void RENAME(bgr24ToY_mmx)(uint8_t *dst, const uint8_t *src,
+static av_always_inline void RENAME(bgr24ToY_mmx)(int16_t *dst, const uint8_t *src,
int width, enum PixelFormat srcFormat)
{
@@ -1756,32 +1853,31 @@ static av_always_inline void RENAME(bgr24ToY_mmx)(uint8_t *dst, const uint8_t *s
"paddd %%mm3, %%mm2 \n\t"
"paddd %%mm4, %%mm0 \n\t"
"paddd %%mm4, %%mm2 \n\t"
- "psrad $15, %%mm0 \n\t"
- "psrad $15, %%mm2 \n\t"
+ "psrad $9, %%mm0 \n\t"
+ "psrad $9, %%mm2 \n\t"
"packssdw %%mm2, %%mm0 \n\t"
- "packuswb %%mm0, %%mm0 \n\t"
- "movd %%mm0, (%1, %%"REG_a") \n\t"
- "add $4, %%"REG_a" \n\t"
+ "movq %%mm0, (%1, %%"REG_a") \n\t"
+ "add $8, %%"REG_a" \n\t"
" js 1b \n\t"
: "+r" (src)
- : "r" (dst+width), "g" ((x86_reg)-width)
+ : "r" (dst+width), "g" ((x86_reg)-2*width)
: "%"REG_a
);
}
-static void RENAME(bgr24ToY)(uint8_t *dst, const uint8_t *src,
+static void RENAME(bgr24ToY)(int16_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2,
int width, uint32_t *unused)
{
RENAME(bgr24ToY_mmx)(dst, src, width, PIX_FMT_BGR24);
}
-static void RENAME(rgb24ToY)(uint8_t *dst, const uint8_t *src,
+static void RENAME(rgb24ToY)(int16_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2,
int width, uint32_t *unused)
{
RENAME(bgr24ToY_mmx)(dst, src, width, PIX_FMT_RGB24);
}
-static av_always_inline void RENAME(bgr24ToUV_mmx)(uint8_t *dstU, uint8_t *dstV,
+static av_always_inline void RENAME(bgr24ToUV_mmx)(int16_t *dstU, int16_t *dstV,
const uint8_t *src, int width,
enum PixelFormat srcFormat)
{
@@ -1823,198 +1919,38 @@ static av_always_inline void RENAME(bgr24ToUV_mmx)(uint8_t *dstU, uint8_t *dstV,
"paddd %%mm3, %%mm2 \n\t"
"paddd %%mm3, %%mm1 \n\t"
"paddd %%mm3, %%mm4 \n\t"
- "psrad $15, %%mm0 \n\t"
- "psrad $15, %%mm2 \n\t"
- "psrad $15, %%mm1 \n\t"
- "psrad $15, %%mm4 \n\t"
+ "psrad $9, %%mm0 \n\t"
+ "psrad $9, %%mm2 \n\t"
+ "psrad $9, %%mm1 \n\t"
+ "psrad $9, %%mm4 \n\t"
"packssdw %%mm1, %%mm0 \n\t"
"packssdw %%mm4, %%mm2 \n\t"
- "packuswb %%mm0, %%mm0 \n\t"
- "packuswb %%mm2, %%mm2 \n\t"
- "movd %%mm0, (%1, %%"REG_a") \n\t"
- "movd %%mm2, (%2, %%"REG_a") \n\t"
- "add $4, %%"REG_a" \n\t"
+ "movq %%mm0, (%1, %%"REG_a") \n\t"
+ "movq %%mm2, (%2, %%"REG_a") \n\t"
+ "add $8, %%"REG_a" \n\t"
" js 1b \n\t"
: "+r" (src)
- : "r" (dstU+width), "r" (dstV+width), "g" ((x86_reg)-width), "r"(ff_bgr24toUV[srcFormat == PIX_FMT_RGB24])
+ : "r" (dstU+width), "r" (dstV+width), "g" ((x86_reg)-2*width), "r"(ff_bgr24toUV[srcFormat == PIX_FMT_RGB24])
: "%"REG_a
);
}
-static void RENAME(bgr24ToUV)(uint8_t *dstU, uint8_t *dstV,
- const uint8_t *src1, const uint8_t *src2,
+static void RENAME(bgr24ToUV)(int16_t *dstU, int16_t *dstV,
+ const uint8_t *unused1, const uint8_t *src1, const uint8_t *src2,
int width, uint32_t *unused)
{
RENAME(bgr24ToUV_mmx)(dstU, dstV, src1, width, PIX_FMT_BGR24);
assert(src1 == src2);
}
-static void RENAME(rgb24ToUV)(uint8_t *dstU, uint8_t *dstV,
- const uint8_t *src1, const uint8_t *src2,
+static void RENAME(rgb24ToUV)(int16_t *dstU, int16_t *dstV,
+ const uint8_t *unused1, const uint8_t *src1, const uint8_t *src2,
int width, uint32_t *unused)
{
assert(src1==src2);
RENAME(bgr24ToUV_mmx)(dstU, dstV, src1, width, PIX_FMT_RGB24);
}
-#if !COMPILE_TEMPLATE_MMX2
-// bilinear / bicubic scaling
-static void RENAME(hScale)(SwsContext *c, int16_t *dst, int dstW,
- const uint8_t *src, const int16_t *filter,
- const int16_t *filterPos, int filterSize)
-{
- assert(filterSize % 4 == 0 && filterSize>0);
- if (filterSize==4) { // Always true for upscaling, sometimes for down, too.
- x86_reg counter= -2*dstW;
- filter-= counter*2;
- filterPos-= counter/2;
- dst-= counter/2;
- __asm__ volatile(
-#if defined(PIC)
- "push %%"REG_b" \n\t"
-#endif
- "pxor %%mm7, %%mm7 \n\t"
- "push %%"REG_BP" \n\t" // we use 7 regs here ...
- "mov %%"REG_a", %%"REG_BP" \n\t"
- ".p2align 4 \n\t"
- "1: \n\t"
- "movzwl (%2, %%"REG_BP"), %%eax \n\t"
- "movzwl 2(%2, %%"REG_BP"), %%ebx \n\t"
- "movq (%1, %%"REG_BP", 4), %%mm1 \n\t"
- "movq 8(%1, %%"REG_BP", 4), %%mm3 \n\t"
- "movd (%3, %%"REG_a"), %%mm0 \n\t"
- "movd (%3, %%"REG_b"), %%mm2 \n\t"
- "punpcklbw %%mm7, %%mm0 \n\t"
- "punpcklbw %%mm7, %%mm2 \n\t"
- "pmaddwd %%mm1, %%mm0 \n\t"
- "pmaddwd %%mm2, %%mm3 \n\t"
- "movq %%mm0, %%mm4 \n\t"
- "punpckldq %%mm3, %%mm0 \n\t"
- "punpckhdq %%mm3, %%mm4 \n\t"
- "paddd %%mm4, %%mm0 \n\t"
- "psrad $7, %%mm0 \n\t"
- "packssdw %%mm0, %%mm0 \n\t"
- "movd %%mm0, (%4, %%"REG_BP") \n\t"
- "add $4, %%"REG_BP" \n\t"
- " jnc 1b \n\t"
-
- "pop %%"REG_BP" \n\t"
-#if defined(PIC)
- "pop %%"REG_b" \n\t"
-#endif
- : "+a" (counter)
- : "c" (filter), "d" (filterPos), "S" (src), "D" (dst)
-#if !defined(PIC)
- : "%"REG_b
-#endif
- );
- } else if (filterSize==8) {
- x86_reg counter= -2*dstW;
- filter-= counter*4;
- filterPos-= counter/2;
- dst-= counter/2;
- __asm__ volatile(
-#if defined(PIC)
- "push %%"REG_b" \n\t"
-#endif
- "pxor %%mm7, %%mm7 \n\t"
- "push %%"REG_BP" \n\t" // we use 7 regs here ...
- "mov %%"REG_a", %%"REG_BP" \n\t"
- ".p2align 4 \n\t"
- "1: \n\t"
- "movzwl (%2, %%"REG_BP"), %%eax \n\t"
- "movzwl 2(%2, %%"REG_BP"), %%ebx \n\t"
- "movq (%1, %%"REG_BP", 8), %%mm1 \n\t"
- "movq 16(%1, %%"REG_BP", 8), %%mm3 \n\t"
- "movd (%3, %%"REG_a"), %%mm0 \n\t"
- "movd (%3, %%"REG_b"), %%mm2 \n\t"
- "punpcklbw %%mm7, %%mm0 \n\t"
- "punpcklbw %%mm7, %%mm2 \n\t"
- "pmaddwd %%mm1, %%mm0 \n\t"
- "pmaddwd %%mm2, %%mm3 \n\t"
-
- "movq 8(%1, %%"REG_BP", 8), %%mm1 \n\t"
- "movq 24(%1, %%"REG_BP", 8), %%mm5 \n\t"
- "movd 4(%3, %%"REG_a"), %%mm4 \n\t"
- "movd 4(%3, %%"REG_b"), %%mm2 \n\t"
- "punpcklbw %%mm7, %%mm4 \n\t"
- "punpcklbw %%mm7, %%mm2 \n\t"
- "pmaddwd %%mm1, %%mm4 \n\t"
- "pmaddwd %%mm2, %%mm5 \n\t"
- "paddd %%mm4, %%mm0 \n\t"
- "paddd %%mm5, %%mm3 \n\t"
- "movq %%mm0, %%mm4 \n\t"
- "punpckldq %%mm3, %%mm0 \n\t"
- "punpckhdq %%mm3, %%mm4 \n\t"
- "paddd %%mm4, %%mm0 \n\t"
- "psrad $7, %%mm0 \n\t"
- "packssdw %%mm0, %%mm0 \n\t"
- "movd %%mm0, (%4, %%"REG_BP") \n\t"
- "add $4, %%"REG_BP" \n\t"
- " jnc 1b \n\t"
-
- "pop %%"REG_BP" \n\t"
-#if defined(PIC)
- "pop %%"REG_b" \n\t"
-#endif
- : "+a" (counter)
- : "c" (filter), "d" (filterPos), "S" (src), "D" (dst)
-#if !defined(PIC)
- : "%"REG_b
-#endif
- );
- } else {
- const uint8_t *offset = src+filterSize;
- x86_reg counter= -2*dstW;
- //filter-= counter*filterSize/2;
- filterPos-= counter/2;
- dst-= counter/2;
- __asm__ volatile(
- "pxor %%mm7, %%mm7 \n\t"
- ".p2align 4 \n\t"
- "1: \n\t"
- "mov %2, %%"REG_c" \n\t"
- "movzwl (%%"REG_c", %0), %%eax \n\t"
- "movzwl 2(%%"REG_c", %0), %%edx \n\t"
- "mov %5, %%"REG_c" \n\t"
- "pxor %%mm4, %%mm4 \n\t"
- "pxor %%mm5, %%mm5 \n\t"
- "2: \n\t"
- "movq (%1), %%mm1 \n\t"
- "movq (%1, %6), %%mm3 \n\t"
- "movd (%%"REG_c", %%"REG_a"), %%mm0 \n\t"
- "movd (%%"REG_c", %%"REG_d"), %%mm2 \n\t"
- "punpcklbw %%mm7, %%mm0 \n\t"
- "punpcklbw %%mm7, %%mm2 \n\t"
- "pmaddwd %%mm1, %%mm0 \n\t"
- "pmaddwd %%mm2, %%mm3 \n\t"
- "paddd %%mm3, %%mm5 \n\t"
- "paddd %%mm0, %%mm4 \n\t"
- "add $8, %1 \n\t"
- "add $4, %%"REG_c" \n\t"
- "cmp %4, %%"REG_c" \n\t"
- " jb 2b \n\t"
- "add %6, %1 \n\t"
- "movq %%mm4, %%mm0 \n\t"
- "punpckldq %%mm5, %%mm4 \n\t"
- "punpckhdq %%mm5, %%mm0 \n\t"
- "paddd %%mm0, %%mm4 \n\t"
- "psrad $7, %%mm4 \n\t"
- "packssdw %%mm4, %%mm4 \n\t"
- "mov %3, %%"REG_a" \n\t"
- "movd %%mm4, (%%"REG_a", %0) \n\t"
- "add $4, %0 \n\t"
- " jnc 1b \n\t"
-
- : "+r" (counter), "+r" (filter)
- : "m" (filterPos), "m" (dst), "m"(offset),
- "m" (src), "r" ((x86_reg)filterSize*2)
- : "%"REG_a, "%"REG_c, "%"REG_d
- );
- }
-}
-#endif /* !COMPILE_TEMPLATE_MMX2 */
-
#if COMPILE_TEMPLATE_MMX2
static void RENAME(hyscale_fast)(SwsContext *c, int16_t *dst,
int dstWidth, const uint8_t *src,
@@ -2156,9 +2092,8 @@ static av_cold void RENAME(sws_init_swScale)(SwsContext *c)
enum PixelFormat srcFormat = c->srcFormat,
dstFormat = c->dstFormat;
- if (!is16BPS(dstFormat) && !is9_OR_10BPS(dstFormat) &&
- dstFormat != PIX_FMT_NV12 && dstFormat != PIX_FMT_NV21) {
- if (!(c->flags & SWS_BITEXACT)) {
+ if (!is16BPS(dstFormat) && !is9_OR_10BPS(dstFormat) && dstFormat != PIX_FMT_NV12
+ && dstFormat != PIX_FMT_NV21 && !(c->flags & SWS_BITEXACT)) {
if (c->flags & SWS_ACCURATE_RND) {
c->yuv2yuv1 = RENAME(yuv2yuv1_ar );
c->yuv2yuvX = RENAME(yuv2yuvX_ar );
@@ -2173,7 +2108,8 @@ static av_cold void RENAME(sws_init_swScale)(SwsContext *c)
}
}
} else {
- c->yuv2yuv1 = RENAME(yuv2yuv1 );
+ int should_dither= isNBPS(c->srcFormat) || is16BPS(c->srcFormat);
+ c->yuv2yuv1 = should_dither ? RENAME(yuv2yuv1_ar ) : RENAME(yuv2yuv1 );
c->yuv2yuvX = RENAME(yuv2yuvX );
if (!(c->flags & SWS_FULL_CHR_H_INT)) {
switch (c->dstFormat) {
@@ -2186,7 +2122,6 @@ static av_cold void RENAME(sws_init_swScale)(SwsContext *c)
}
}
}
- }
if (!(c->flags & SWS_FULL_CHR_H_INT)) {
switch (c->dstFormat) {
case PIX_FMT_RGB32:
@@ -2215,11 +2150,7 @@ static av_cold void RENAME(sws_init_swScale)(SwsContext *c)
}
}
- if (c->scalingBpp == 8) {
-#if !COMPILE_TEMPLATE_MMX2
- c->hScale = RENAME(hScale );
-#endif /* !COMPILE_TEMPLATE_MMX2 */
-
+ if (c->srcBpc == 8 && c->dstBpc <= 10) {
// Use the new MMX scaler if the MMX2 one can't be used (it is faster than the x86 ASM one).
#if COMPILE_TEMPLATE_MMX2
if (c->flags & SWS_FAST_BILINEAR && c->canMMX2BeUsed)
diff --git a/libswscale/x86/yuv2rgb_mmx.c b/libswscale/x86/yuv2rgb_mmx.c
index 0eaea77485..df0e1a3726 100644
--- a/libswscale/x86/yuv2rgb_mmx.c
+++ b/libswscale/x86/yuv2rgb_mmx.c
@@ -7,20 +7,20 @@
* 1,4,8bpp support and context / deglobalize stuff
* by Michael Niedermayer (michaelni@gmx.at)
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/libswscale/x86/yuv2rgb_template.c b/libswscale/x86/yuv2rgb_template.c
index 5d1fa5b309..926e3fb9c4 100644
--- a/libswscale/x86/yuv2rgb_template.c
+++ b/libswscale/x86/yuv2rgb_template.c
@@ -4,20 +4,20 @@
* Copyright (C) 2001-2007 Michael Niedermayer
* (c) 2010 Konstantin Shishkov
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -43,17 +43,14 @@
if (h_size * depth > FFABS(dstStride[0])) \
h_size -= 8; \
\
- if (c->srcFormat == PIX_FMT_YUV422P) { \
- srcStride[1] *= 2; \
- srcStride[2] *= 2; \
- } \
+ vshift = c->srcFormat != PIX_FMT_YUV422P; \
\
__asm__ volatile ("pxor %mm4, %mm4\n\t"); \
for (y = 0; y < srcSliceH; y++) { \
uint8_t *image = dst[0] + (y + srcSliceY) * dstStride[0]; \
const uint8_t *py = src[0] + y * srcStride[0]; \
- const uint8_t *pu = src[1] + (y >> 1) * srcStride[1]; \
- const uint8_t *pv = src[2] + (y >> 1) * srcStride[2]; \
+ const uint8_t *pu = src[1] + (y >> vshift) * srcStride[1]; \
+ const uint8_t *pv = src[2] + (y >> vshift) * srcStride[2]; \
x86_reg index = -h_size / 2; \
#define YUV2RGB_INITIAL_LOAD \
@@ -188,7 +185,7 @@ static inline int RENAME(yuv420_rgb15)(SwsContext *c, const uint8_t *src[],
int srcSliceY, int srcSliceH,
uint8_t *dst[], int dstStride[])
{
- int y, h_size;
+ int y, h_size, vshift;
YUV2RGB_LOOP(2)
@@ -216,7 +213,7 @@ static inline int RENAME(yuv420_rgb16)(SwsContext *c, const uint8_t *src[],
int srcSliceY, int srcSliceH,
uint8_t *dst[], int dstStride[])
{
- int y, h_size;
+ int y, h_size, vshift;
YUV2RGB_LOOP(2)
@@ -306,7 +303,7 @@ static inline int RENAME(yuv420_rgb24)(SwsContext *c, const uint8_t *src[],
int srcSliceY, int srcSliceH,
uint8_t *dst[], int dstStride[])
{
- int y, h_size;
+ int y, h_size, vshift;
YUV2RGB_LOOP(3)
@@ -324,7 +321,7 @@ static inline int RENAME(yuv420_bgr24)(SwsContext *c, const uint8_t *src[],
int srcSliceY, int srcSliceH,
uint8_t *dst[], int dstStride[])
{
- int y, h_size;
+ int y, h_size, vshift;
YUV2RGB_LOOP(3)
@@ -368,7 +365,7 @@ static inline int RENAME(yuv420_rgb32)(SwsContext *c, const uint8_t *src[],
int srcSliceY, int srcSliceH,
uint8_t *dst[], int dstStride[])
{
- int y, h_size;
+ int y, h_size, vshift;
YUV2RGB_LOOP(4)
@@ -389,7 +386,7 @@ static inline int RENAME(yuva420_rgb32)(SwsContext *c, const uint8_t *src[],
int srcSliceY, int srcSliceH,
uint8_t *dst[], int dstStride[])
{
- int y, h_size;
+ int y, h_size, vshift;
YUV2RGB_LOOP(4)
@@ -411,7 +408,7 @@ static inline int RENAME(yuv420_bgr32)(SwsContext *c, const uint8_t *src[],
int srcSliceY, int srcSliceH,
uint8_t *dst[], int dstStride[])
{
- int y, h_size;
+ int y, h_size, vshift;
YUV2RGB_LOOP(4)
@@ -432,7 +429,7 @@ static inline int RENAME(yuva420_bgr32)(SwsContext *c, const uint8_t *src[],
int srcSliceY, int srcSliceH,
uint8_t *dst[], int dstStride[])
{
- int y, h_size;
+ int y, h_size, vshift;
YUV2RGB_LOOP(4)
diff --git a/libswscale/yuv2rgb.c b/libswscale/yuv2rgb.c
index cad09338d3..eb478e2186 100644
--- a/libswscale/yuv2rgb.c
+++ b/libswscale/yuv2rgb.c
@@ -6,20 +6,20 @@
* 1,4,8bpp support and context / deglobalize stuff
* by Michael Niedermayer (michaelni@gmx.at)
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -34,6 +34,7 @@
#include "swscale_internal.h"
#include "libavutil/cpu.h"
#include "libavutil/bswap.h"
+#include "libavutil/pixdesc.h"
extern const uint8_t dither_4x4_16[4][8];
extern const uint8_t dither_8x8_32[8][8];
@@ -521,7 +522,8 @@ SwsFunc ff_yuv2rgb_get_func_ptr(SwsContext *c)
if (t)
return t;
- av_log(c, AV_LOG_WARNING, "No accelerated colorspace conversion found from %s to %s.\n", sws_format_name(c->srcFormat), sws_format_name(c->dstFormat));
+ av_log(c, AV_LOG_WARNING, "No accelerated colorspace conversion found from %s to %s.\n",
+ av_get_pix_fmt_name(c->srcFormat), av_get_pix_fmt_name(c->dstFormat));
switch (c->dstFormat) {
case PIX_FMT_BGR48BE:
@@ -788,8 +790,8 @@ av_cold int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4], int
y_table32 = c->yuvTable;
yb = -(384<<16) - oy;
for (i = 0; i < 1024; i++) {
- uint8_t yval = av_clip_uint8((yb + 0x8000) >> 16);
- y_table32[i ] = (yval << rbase) + (needAlpha ? 0 : (255 << abase));
+ unsigned yval = av_clip_uint8((yb + 0x8000) >> 16);
+ y_table32[i ] = (yval << rbase) + (needAlpha ? 0 : (255u << abase));
y_table32[i+1024] = yval << gbase;
y_table32[i+2048] = yval << bbase;
yb += cy;
diff --git a/mt-work/email.sh b/mt-work/email.sh
new file mode 100644
index 0000000000..e5cdb72338
--- /dev/null
+++ b/mt-work/email.sh
@@ -0,0 +1,6 @@
+#!/bin/sh -v
+
+# args [where to put patches] [smtp server] [destination]
+
+git format-patch -o "$1" --inline --subject-prefix=soc --thread origin
+git send-email --no-chain-reply-to --smtp-server $2 --to $3 --dry-run "$1"
diff --git a/mt-work/mplayer.diff b/mt-work/mplayer.diff
new file mode 100644
index 0000000000..ef38063bf0
--- /dev/null
+++ b/mt-work/mplayer.diff
@@ -0,0 +1,13 @@
+diff --git a/libmpcodecs/vd_ffmpeg.c b/libmpcodecs/vd_ffmpeg.c
+index 7c68a20..135e6b1 100644
+--- a/libmpcodecs/vd_ffmpeg.c
++++ b/libmpcodecs/vd_ffmpeg.c
+@@ -280,7 +280,7 @@ static int init(sh_video_t *sh){
+ return 0;
+ }
+
+- if(vd_use_slices && (lavc_codec->capabilities&CODEC_CAP_DRAW_HORIZ_BAND) && !do_vis_debug)
++ if(vd_use_slices && (lavc_codec->capabilities&CODEC_CAP_DRAW_HORIZ_BAND) && !do_vis_debug && lavc_param_threads <= 1)
+ ctx->do_slices=1;
+
+ if(lavc_codec->capabilities&CODEC_CAP_DR1 && !do_vis_debug && lavc_codec->id != CODEC_ID_H264 && lavc_codec->id != CODEC_ID_INTERPLAY_VIDEO && lavc_codec->id != CODEC_ID_ROQ && lavc_codec->id != CODEC_ID_VP8 && lavc_codec->id != CODEC_ID_LAGARITH)
diff --git a/mt-work/raw.sh b/mt-work/raw.sh
new file mode 100644
index 0000000000..0ced88e213
--- /dev/null
+++ b/mt-work/raw.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+fn=`basename "$1"`
+for th in 1 4; do
+ time ./ffmpeg_g -threads $th -skip_loop_filter all -vsync 0 -y -t 30 -i "$1" -an -f rawvideo "raw/n-$fn-$th.yuv"
+done
+
+#for th in 1 4; do
+# time ./ffmpeg_g -threads $th -vsync 0 -y -t 30 -i "$1" -an -f rawvideo "raw/$fn-$th.yuv"
+#done
diff --git a/mt-work/test.sh b/mt-work/test.sh
new file mode 100644
index 0000000000..a88a35bfe6
--- /dev/null
+++ b/mt-work/test.sh
@@ -0,0 +1,13 @@
+#!/bin/bash
+
+fn=`basename "$1"`
+for th in 1 2 3 4; do
+ time ./ffmpeg_g -threads $th -flags2 +fast -vsync 0 -y -t 30 -i "$1" -an -f framecrc "crc/$fn-$th.txt" >/dev/null 2>&1
+done
+
+./ffmpeg_g -threads 1 -y -t 10 -i "$1" -an -f framecrc "crc/$fn-1-vsync.txt" >/dev/null 2>&1
+./ffmpeg_g -threads 3 -y -t 10 -i "$1" -an -f framecrc "crc/$fn-3-vsync.txt" >/dev/null 2>&1
+
+md5 "crc/$fn-"[1234].txt
+echo
+md5 "crc/$fn-"*vsync.txt
diff --git a/mt-work/todo.txt b/mt-work/todo.txt
new file mode 100644
index 0000000000..f64514f6fa
--- /dev/null
+++ b/mt-work/todo.txt
@@ -0,0 +1,95 @@
+Todo
+
+-- For other people
+- Multithread vc1.
+- Multithread an intra codec like mjpeg (trivial).
+- Fix mpeg1 (see below).
+- Try the first three items under Optimization.
+- Fix h264 (see below).
+- Try mpeg4 (see below).
+
+-- Bug fixes
+
+General critical:
+- Error resilience has to run before ff_report_frame_progress()
+is called. Otherwise there will be race conditions. (This might already
+work.) In general testing error paths should be done more.
+- 'make fate THREADS=2' doesn't pass. Most failures are due to
+bugs in vsync in ffmpeg.c, which are currently obscuring real failures.
+
+h264:
+- Files that aren't parsed (e.g. mp4) and contain PAFF with two
+field pictures in the same packet are not optimal. Modify the
+nals_needed check so that the second field's first slice is
+considered as needed, then uncomment the FIXME code in decode_postinit.
+Ex: http://astrange.ithinksw.net/ffmpeg/mt-samples/PAFF-Chalet-Tire.mp4
+
+mpeg4:
+- Packed B-frames need to be explicitly split up
+when frame threading is on. It's not very fast
+without this.
+- The buffer age optimization is disabled due to
+the way buffers are allocated across threads. The
+branch 'fix_buffer_age' has an attempt to fix it
+which breaks ffplay.
+- Support interlaced.
+
+mpeg1/2:
+- Seeking always prints "first frame not a keyframe"
+with threads on. Currently disabled for this reason.
+
+-- Prove correct
+
+- decode_update_progress() in h264.c
+race_checking branch has some work on h264,
+but not that function. It might be worth putting
+the branch under #ifdef DEBUG in mainline, but
+the code would have to be cleaner.
+- MPV_lowest_referenced_row() and co in mpegvideo.c
+- Same in vp3.
+
+-- Optimization
+
+- Merge h264 decode_update_progress() with loop_filter().
+Add CODEC_CAP_DRAW_HORIZ_BAND as a side effect.
+- EMU_EDGE is always set for h264 PAFF+MT
+because draw_edges() writes into the other field's
+thread's pixels. Needs an option to skip T/B fields.
+- Check update_thread_context() functions and make
+sure they only copy what they need to.
+- Try some more optimization of the "ref < 48; ref++"
+loop in h264.c await_references(), try turning the list0/list1 check
+above into a loop without being slower.
+- Support frame+slice threading at the same time
+by assigning slice_count threads for frame threads
+to use with execute(). This is simpler but unbalanced
+if only one frame thread uses any.
+
+-- Features
+
+- Support streams with width/height changing. This
+requires flushing all current frames (and buffering
+the input in the meantime), closing the codec and
+reopening it. Or don't support it.
+- Support encoding. Might need more threading primitives
+for good ratecontrol; would be nice for audio and libavfilter too.
+- Async decoding part 1: instead of trying to
+start every thread at the beginning, return a picture
+if the earliest thread is already done, but don't wait
+for it. Not sure what effect this would have.
+- Part 2: have an API that doesn't wait for the decoding
+thread, only returns EAGAIN if it's not ready. What will
+it do with the next input packet if it returns that?
+- Have an API that returns finished pictures but doesn't
+require sending new ones. Maybe allow NULL avpkt when
+not at the end of the stream.
+
+-- Samples
+
+http://astrange.ithinksw.net/ffmpeg/mt-samples/
+
+See yuvcmp.c in this directory to compare decoded samples.
+
+For debugging, try commenting out ff_thread_finish_setup calls so
+that only one thread runs at once, and then binary search+
+scatter printfs to look for differences in codec contexts.
diff --git a/mt-work/valgrind-check.sh b/mt-work/valgrind-check.sh
new file mode 100644
index 0000000000..276327a76a
--- /dev/null
+++ b/mt-work/valgrind-check.sh
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+valgrind --track-origins=yes --leak-check=full ./ffmpeg_g -threads 1 -vsync 0 -y -t 30 -i "$1" -an -f null /dev/null
+
+valgrind --track-origins=yes --leak-check=full ./ffmpeg_g -threads 3 -vsync 0 -y -t 30 -i "$1" -an -f null /dev/null
diff --git a/mt-work/yuvcmp.c b/mt-work/yuvcmp.c
new file mode 100644
index 0000000000..11585f9b4c
--- /dev/null
+++ b/mt-work/yuvcmp.c
@@ -0,0 +1,182 @@
+/*
+ * originally by Andreas Öman (andoma)
+ * some changes by Alexander Strange
+ */
+
+#include <string.h>
+#include <stdlib.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+
+int
+main(int argc, char **argv)
+{
+ int fd[2];
+ int print_pixels = 0;
+ int dump_blocks = 0;
+
+ int width;
+ int height;
+ int to_skip = 0;
+
+ if (argc < 6) {
+ fprintf(stderr, "%s [YUV file 1] [YUV file 2] width height pixelcmp|blockdump (# to skip)\n", argv[0]);
+ return 1;
+ }
+
+ width = atoi(argv[3]);
+ height = atoi(argv[4]);
+ if (argc > 6)
+ to_skip = atoi(argv[6]);
+
+ uint8_t *Y[2], *C[2][2];
+ int i, v, c, p;
+ int lsiz = width * height;
+ int csiz = width * height / 4;
+ int x, y;
+ int cwidth = width / 2;
+ int fr = to_skip;
+ int mb;
+ char *mberrors;
+ int mb_x, mb_y;
+ uint8_t *a;
+ uint8_t *b;
+ int die = 0;
+
+ print_pixels = strstr(argv[5], "pixelcmp") ? 1 : 0;
+ dump_blocks = strstr(argv[5], "blockdump") ? 1 : 0;
+
+ for(i = 0; i < 2; i++) {
+ Y[i] = malloc(lsiz);
+ C[0][i] = malloc(csiz);
+ C[1][i] = malloc(csiz);
+
+ fd[i] = open(argv[1 + i], O_RDONLY);
+ if(fd[i] == -1) {
+ perror("open");
+ exit(1);
+ }
+ fcntl(fd[i], F_NOCACHE, 1);
+
+ if (to_skip)
+ lseek(fd[i], to_skip * (lsiz + 2*csiz), SEEK_SET);
+ }
+
+ mb_x = width / 16;
+ mb_y = height / 16;
+
+ mberrors = malloc(mb_x * mb_y);
+
+ while(!die) {
+ memset(mberrors, 0, mb_x * mb_y);
+
+ printf("Loading frame %d\n", ++fr);
+
+ for(i = 0; i < 2; i++) {
+ v = read(fd[i], Y[i], lsiz);
+ if(v != lsiz) {
+ fprintf(stderr, "Unable to read Y from file %d, exiting\n", i + 1);
+ return 1;
+ }
+ }
+
+
+ for(c = 0; c < lsiz; c++) {
+ if(Y[0][c] != Y[1][c]) {
+ x = c % width;
+ y = c / width;
+
+ mb = x / 16 + (y / 16) * mb_x;
+
+ if(print_pixels)
+ printf("Luma diff 0x%02x != 0x%02x at pixel (%4d,%-4d) mb(%d,%d) #%d\n",
+ Y[0][c],
+ Y[1][c],
+ x, y,
+ x / 16,
+ y / 16,
+ mb);
+
+ mberrors[mb] |= 1;
+ }
+ }
+
+ /* Chroma planes */
+
+ for(p = 0; p < 2; p++) {
+
+ for(i = 0; i < 2; i++) {
+ v = read(fd[i], C[p][i], csiz);
+ if(v != csiz) {
+ fprintf(stderr, "Unable to read %c from file %d, exiting\n",
+ "UV"[p], i + 1);
+ return 1;
+ }
+ }
+
+ for(c = 0; c < csiz; c++) {
+ if(C[p][0][c] != C[p][1][c]) {
+ x = c % cwidth;
+ y = c / cwidth;
+
+ mb = x / 8 + (y / 8) * mb_x;
+
+ mberrors[mb] |= 2 << p;
+
+ if(print_pixels)
+
+ printf("c%c diff 0x%02x != 0x%02x at pixel (%4d,%-4d) "
+ "mb(%3d,%-3d) #%d\n",
+ p ? 'r' : 'b',
+ C[p][0][c],
+ C[p][1][c],
+
+ x, y,
+ x / 8,
+ y / 8,
+ x / 8 + y / 8 * cwidth / 8);
+ }
+ }
+ }
+
+ for(i = 0; i < mb_x * mb_y; i++) {
+ x = i % mb_x;
+ y = i / mb_x;
+
+ if(mberrors[i]) {
+ die = 1;
+
+ printf("MB (%3d,%-3d) %4d %d %c%c%c damaged\n",
+ x, y, i, mberrors[i],
+ mberrors[i] & 1 ? 'Y' : ' ',
+ mberrors[i] & 2 ? 'U' : ' ',
+ mberrors[i] & 4 ? 'V' : ' ');
+
+ if(dump_blocks) {
+ a = Y[0] + x * 16 + y * 16 * width;
+ b = Y[1] + x * 16 + y * 16 * width;
+
+ for(y = 0; y < 16; y++) {
+ printf("%c ", "TB"[y&1]);
+ for(x = 0; x < 16; x++)
+ printf("%02x%c", a[x + y * width],
+ a[x + y * width] != b[x + y * width] ? '<' : ' ');
+
+ printf("| ");
+ for(x = 0; x < 16; x++)
+ printf("%02x%c", b[x + y * width],
+ a[x + y * width] != b[x + y * width] ? '<' : ' ');
+
+ printf("\n");
+ }
+ }
+ }
+ }
+ }
+
+ return 0;
+}
diff --git a/presets/libvpx-1080p.ffpreset b/presets/libvpx-1080p.ffpreset
new file mode 100644
index 0000000000..a2accba7ff
--- /dev/null
+++ b/presets/libvpx-1080p.ffpreset
@@ -0,0 +1,17 @@
+g=120
+lag-in-frames=16
+deadline=good
+cpu-used=0
+vprofile=1
+qmax=51
+qmin=11
+slices=4
+b=2M
+
+#ignored unless using -pass 2
+maxrate=24M
+minrate=100k
+auto-alt-ref=1
+arnr-maxframes=7
+arnr-strength=5
+arnr-type=centered
diff --git a/presets/libvpx-1080p50_60.ffpreset b/presets/libvpx-1080p50_60.ffpreset
new file mode 100644
index 0000000000..3d29f9bf87
--- /dev/null
+++ b/presets/libvpx-1080p50_60.ffpreset
@@ -0,0 +1,17 @@
+g=120
+lag-in-frames=25
+deadline=good
+cpu-used=0
+vprofile=1
+qmax=51
+qmin=11
+slices=4
+b=2M
+
+#ignored unless using -pass 2
+maxrate=24M
+minrate=100k
+auto-alt-ref=1
+arnr-maxframes=7
+arnr-strength=5
+arnr-type=centered
diff --git a/presets/libvpx-360p.ffpreset b/presets/libvpx-360p.ffpreset
new file mode 100644
index 0000000000..36fd11af43
--- /dev/null
+++ b/presets/libvpx-360p.ffpreset
@@ -0,0 +1,16 @@
+g=120
+lag-in-frames=16
+deadline=good
+cpu-used=0
+vprofile=0
+qmax=63
+qmin=0
+b=768k
+
+#ignored unless using -pass 2
+maxrate=1.5M
+minrate=40k
+auto-alt-ref=1
+arnr-maxframes=7
+arnr-strength=5
+arnr-type=centered
diff --git a/presets/libvpx-720p.ffpreset b/presets/libvpx-720p.ffpreset
new file mode 100644
index 0000000000..ba7791d544
--- /dev/null
+++ b/presets/libvpx-720p.ffpreset
@@ -0,0 +1,17 @@
+g=120
+lag-in-frames=16
+deadline=good
+cpu-used=0
+vprofile=0
+qmax=51
+qmin=11
+slices=4
+b=2M
+
+#ignored unless using -pass 2
+maxrate=24M
+minrate=100k
+auto-alt-ref=1
+arnr-maxframes=7
+arnr-strength=5
+arnr-type=centered
diff --git a/presets/libvpx-720p50_60.ffpreset b/presets/libvpx-720p50_60.ffpreset
new file mode 100644
index 0000000000..b339774e78
--- /dev/null
+++ b/presets/libvpx-720p50_60.ffpreset
@@ -0,0 +1,17 @@
+g=120
+lag-in-frames=25
+deadline=good
+cpu-used=0
+vprofile=0
+qmax=51
+qmin=11
+slices=4
+b=2M
+
+#ignored unless using -pass 2
+maxrate=24M
+minrate=100k
+auto-alt-ref=1
+arnr-maxframes=7
+arnr-strength=5
+arnr-type=centered
diff --git a/presets/libx264-ipod320.ffpreset b/presets/libx264-ipod320.ffpreset
new file mode 100644
index 0000000000..6abacbd72c
--- /dev/null
+++ b/presets/libx264-ipod320.ffpreset
@@ -0,0 +1,4 @@
+vprofile=baseline
+level=13
+maxrate=768000
+bufsize=3000000
diff --git a/presets/libx264-ipod640.ffpreset b/presets/libx264-ipod640.ffpreset
new file mode 100644
index 0000000000..cda7c08752
--- /dev/null
+++ b/presets/libx264-ipod640.ffpreset
@@ -0,0 +1,4 @@
+vprofile=baseline
+level=30
+maxrate=10000000
+bufsize=10000000
diff --git a/subdir.mak b/subdir.mak
index e7c9eaafca..9ac824fd0a 100644
--- a/subdir.mak
+++ b/subdir.mak
@@ -34,17 +34,21 @@ install-libs-$(CONFIG_STATIC): install-lib$(NAME)-static
install-libs-$(CONFIG_SHARED): install-lib$(NAME)-shared
define RULES
-$(SUBDIR)%$(EXESUF): $(SUBDIR)%.o
- $$(LD) $(FFLDFLAGS) -o $$@ $$^ -l$(FULLNAME) $(FFEXTRALIBS) $$(ELIBS)
+$(EXAMPLES) $(TESTPROGS) $(TOOLS): %$(EXESUF): %.o
+ $$(LD) $(LDFLAGS) -o $$@ $$^ -l$(FULLNAME) $(FFEXTRALIBS) $$(ELIBS)
$(SUBDIR)$(SLIBNAME): $(SUBDIR)$(SLIBNAME_WITH_MAJOR)
$(Q)cd ./$(SUBDIR) && $(LN_S) $(SLIBNAME_WITH_MAJOR) $(SLIBNAME)
-$(SUBDIR)$(SLIBNAME_WITH_MAJOR): $(OBJS) $(SUBDIR)lib$(NAME).ver $(DEP_LIBS)
+$(SUBDIR)$(SLIBNAME_WITH_MAJOR): $(OBJS) $(SUBDIR)lib$(NAME).ver
$(SLIB_CREATE_DEF_CMD)
- $$(LD) $(SHFLAGS) $(FFLDFLAGS) -o $$@ $$(filter %.o,$$^) $(FFEXTRALIBS) $(EXTRAOBJS)
+ $$(LD) $(SHFLAGS) $(LDFLAGS) -o $$@ $$(filter %.o,$$^) $(FFEXTRALIBS) $(EXTRAOBJS)
$(SLIB_EXTRA_CMD)
+ifdef SUBDIR
+$(SUBDIR)$(SLIBNAME_WITH_MAJOR): $(DEP_LIBS)
+endif
+
clean::
$(RM) $(addprefix $(SUBDIR),*-example$(EXESUF) *-test$(EXESUF) $(CLEANFILES) $(CLEANSUFFIXES) $(LIBSUFFIXES)) \
$(foreach dir,$(DIRS),$(CLEANSUFFIXES:%=$(SUBDIR)$(dir)/%)) \
@@ -56,12 +60,12 @@ distclean:: clean
install-lib$(NAME)-shared: $(SUBDIR)$(SLIBNAME)
$(Q)mkdir -p "$(SHLIBDIR)"
- $$(INSTALL) -m 755 $$< "$(SHLIBDIR)/$(SLIBNAME_WITH_VERSION)"
- $(Q)cd "$(SHLIBDIR)" && \
- $(LN_S) $(SLIBNAME_WITH_VERSION) $(SLIBNAME_WITH_MAJOR)
- $(Q)cd "$(SHLIBDIR)" && \
- $(LN_S) $(SLIBNAME_WITH_VERSION) $(SLIBNAME)
- $(SLIB_INSTALL_EXTRA_CMD)
+ $$(INSTALL) -m 755 $$< "$(SHLIBDIR)/$(SLIB_INSTALL_NAME)"
+ $$(STRIP) "$(SHLIBDIR)/$(SLIB_INSTALL_NAME)"
+ $(Q)$(foreach F,$(SLIB_INSTALL_LINKS),cd "$(SHLIBDIR)" && $(LN_S) $(SLIB_INSTALL_NAME) $(F);)
+ $(if $(SLIB_INSTALL_EXTRA_SHLIB),$$(INSTALL) -m 644 $(SLIB_INSTALL_EXTRA_SHLIB:%=$(SUBDIR)%) "$(SHLIBDIR)")
+ $(if $(SLIB_INSTALL_EXTRA_LIB),$(Q)mkdir -p "$(LIBDIR)")
+ $(if $(SLIB_INSTALL_EXTRA_LIB),$$(INSTALL) -m 644 $(SLIB_INSTALL_EXTRA_LIB:%=$(SUBDIR)%) "$(LIBDIR)")
install-lib$(NAME)-static: $(SUBDIR)$(LIBNAME)
$(Q)mkdir -p "$(LIBDIR)"
@@ -80,18 +84,19 @@ uninstall-libs::
-$(RM) "$(SHLIBDIR)/$(SLIBNAME_WITH_MAJOR)" \
"$(SHLIBDIR)/$(SLIBNAME)" \
"$(SHLIBDIR)/$(SLIBNAME_WITH_VERSION)"
- -$(SLIB_UNINSTALL_EXTRA_CMD)
+ -$(RM) $(SLIB_INSTALL_EXTRA_SHLIB:%="$(SHLIBDIR)"%)
+ -$(RM) $(SLIB_INSTALL_EXTRA_LIB:%="$(LIBDIR)"%)
-$(RM) "$(LIBDIR)/$(LIBNAME)"
uninstall-headers::
- $(RM) $(addprefix "$(INCINSTDIR)/",$(HEADERS))
+ $(RM) $(addprefix "$(INCINSTDIR)/",$(HEADERS)) $(addprefix "$(INCINSTDIR)/",$(BUILT_HEADERS))
$(RM) "$(LIBDIR)/pkgconfig/lib$(NAME).pc"
- -rmdir "$(INCDIR)"
+ -rmdir "$(INCINSTDIR)"
endef
$(eval $(RULES))
-$(EXAMPLES) $(TESTPROGS): $(THIS_LIB) $(DEP_LIBS)
+$(EXAMPLES) $(TESTPROGS) $(TOOLS): $(THIS_LIB) $(DEP_LIBS)
examples: $(EXAMPLES)
testprogs: $(TESTPROGS)
diff --git a/tests/Makefile b/tests/Makefile
index 431a404219..93f07a5bce 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -4,8 +4,8 @@ AREF = fate-acodec-aref
VREF = fate-vsynth1-vref fate-vsynth2-vref
REFS = $(AREF) $(VREF)
-$(VREF): ffmpeg$(EXESUF) tests/vsynth1/00.pgm tests/vsynth2/00.pgm
-$(AREF): ffmpeg$(EXESUF) tests/data/asynth1.sw
+$(VREF): avconv$(EXESUF) tests/vsynth1/00.pgm tests/vsynth2/00.pgm
+$(AREF): avconv$(EXESUF) tests/data/asynth1.sw
ffservertest: ffserver$(EXESUF) tests/vsynth1/00.pgm tests/data/asynth1.sw
@echo
@@ -26,13 +26,11 @@ tests/data/asynth1.sw: tests/audiogen$(HOSTEXESUF)
@mkdir -p tests/data
$(M)./$< $@
-tests/data/asynth1.sw tests/vsynth%/00.pgm: TAG = GEN
-
-tests/seek_test$(EXESUF): tests/seek_test.o $(FF_DEP_LIBS)
- $(LD) $(FF_LDFLAGS) -o $@ $< $(FF_EXTRALIBS)
+tests/data/asynth-16000-1.sw: tests/audiogen$(HOSTEXESUF)
+ @mkdir -p tests/data
+ $(M)./$< $@ 16000 1
-tools/lavfi-showfiltfmts$(EXESUF): tools/lavfi-showfiltfmts.o $(FF_DEP_LIBS)
- $(LD) $(FF_LDFLAGS) -o $@ $< $(FF_EXTRALIBS)
+tests/data/asynth%.sw tests/vsynth%/00.pgm: TAG = GEN
include $(SRC_PATH)/tests/fate.mak
include $(SRC_PATH)/tests/fate2.mak
@@ -46,6 +44,7 @@ include $(SRC_PATH)/tests/fate/fft.mak
include $(SRC_PATH)/tests/fate/h264.mak
include $(SRC_PATH)/tests/fate/libavutil.mak
include $(SRC_PATH)/tests/fate/mp3.mak
+include $(SRC_PATH)/tests/fate/prores.mak
include $(SRC_PATH)/tests/fate/vorbis.mak
include $(SRC_PATH)/tests/fate/vp8.mak
@@ -60,14 +59,18 @@ FATE_SEEK = $(SEEK_TESTS:seek_%=fate-seek-%)
FATE = $(FATE_ACODEC) \
$(FATE_VCODEC) \
$(FATE_LAVF) \
- $(FATE_LAVFI) \
$(FATE_SEEK) \
+FATE-$(CONFIG_AVFILTER) += $(FATE_LAVFI)
+
+FATE += $(FATE-yes)
+
$(filter-out %-aref,$(FATE_ACODEC)): $(AREF)
-$(filter-out %-vref,$(FATE_VCODEC)): $(VREF)
+$(filter-out %-vref,$(FATE_VSYNTH1)): fate-vsynth1-vref
+$(filter-out %-vref,$(FATE_VSYNTH2)): fate-vsynth2-vref
$(FATE_LAVF): $(REFS)
$(FATE_LAVFI): $(REFS) tools/lavfi-showfiltfmts$(EXESUF)
-$(FATE_SEEK): fate-codec fate-lavf tests/seek_test$(EXESUF)
+$(FATE_SEEK): fate-codec fate-lavf libavformat/seek-test$(EXESUF)
$(FATE_ACODEC): CMD = codectest acodec
$(FATE_VSYNTH1): CMD = codectest vsynth1
@@ -84,9 +87,9 @@ fate-lavfi: $(FATE_LAVFI)
fate-seek: $(FATE_SEEK)
ifdef SAMPLES
-FATE += $(FATE_TESTS)
+FATE += $(FATE_TESTS) $(FATE_TESTS-yes)
fate-rsync:
- rsync -vaLW rsync://fate-suite.libav.org/fate-suite/ $(SAMPLES)
+ rsync -vaLW rsync://fate.ffmpeg.org/fate-suite/ $(SAMPLES)
else
fate-rsync:
@echo "use 'make fate-rsync SAMPLES=/path/to/samples' to sync the fate suite"
@@ -96,11 +99,13 @@ endif
FATE_UTILS = base64 tiny_psnr
+TOOL = ffmpeg
+
fate: $(FATE)
-$(FATE): ffmpeg$(EXESUF) $(FATE_UTILS:%=tests/%$(HOSTEXESUF))
+$(FATE): $(TOOL)$(EXESUF) $(FATE_UTILS:%=tests/%$(HOSTEXESUF))
@echo "TEST $(@:fate-%=%)"
- $(Q)$(SRC_PATH)/tests/fate-run.sh $@ "$(SAMPLES)" "$(TARGET_EXEC)" "$(TARGET_PATH)" '$(CMD)' '$(CMP)' '$(REF)' '$(FUZZ)' '$(THREADS)' '$(THREAD_TYPE)'
+ $(Q)$(SRC_PATH)/tests/fate-run.sh $@ "$(SAMPLES)" "$(TARGET_EXEC)" "$(TARGET_PATH)" '$(CMD)' '$(CMP)' '$(REF)' '$(FUZZ)' '$(THREADS)' '$(THREAD_TYPE)' '$(TOOL)'
fate-list:
@printf '%s\n' $(sort $(FATE))
@@ -108,9 +113,8 @@ fate-list:
clean:: testclean
testclean:
- $(RM) -r tests/vsynth1 tests/vsynth2 tests/data
+ $(RM) -r tests/vsynth1 tests/vsynth2 tests/data tools/lavfi-showfiltfmts$(EXESUF)
$(RM) $(CLEANSUFFIXES:%=tests/%)
- $(RM) tests/seek_test$(EXESUF) tests/seek_test.o
$(RM) $(TESTTOOLS:%=tests/%$(HOSTEXESUF))
-include $(wildcard tests/*.d)
diff --git a/tests/audiogen.c b/tests/audiogen.c
index ddd1e18028..852e04268b 100644
--- a/tests/audiogen.c
+++ b/tests/audiogen.c
@@ -4,20 +4,20 @@
*
* Copyright (c) 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/tests/base64.c b/tests/base64.c
index aad7dfb7ea..75ba8bc5d2 100644
--- a/tests/base64.c
+++ b/tests/base64.c
@@ -1,18 +1,18 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/tests/codec-regression.sh b/tests/codec-regression.sh
index ccedbdbfef..0c8ad67208 100755
--- a/tests/codec-regression.sh
+++ b/tests/codec-regression.sh
@@ -1,6 +1,6 @@
#!/bin/sh
#
-# automatic regression test for ffmpeg
+# automatic regression test for avconv
#
#
#set -x
@@ -13,10 +13,10 @@ eval do_$test=y
# generate reference for quality check
if [ -n "$do_vref" ]; then
-do_ffmpeg $raw_ref -f image2 -vcodec pgmyuv -i $raw_src -an -f rawvideo
+do_avconv $raw_ref -f image2 -vcodec pgmyuv -i $raw_src -an -f rawvideo
fi
if [ -n "$do_aref" ]; then
-do_ffmpeg $pcm_ref -ab 128k -ac 2 -ar 44100 -f s16le -i $pcm_src -f wav
+do_avconv $pcm_ref -b 128k -ac 2 -ar 44100 -f s16le -i $pcm_src -f wav
fi
if [ -n "$do_mpeg" ] ; then
@@ -58,7 +58,7 @@ do_video_decoding
# mpeg2 encoding interlaced
file=${outfile}mpeg2reuse.mpg
-do_ffmpeg $file $DEC_OPTS -me_threshold 256 -i ${target_path}/${outfile}mpeg2thread.mpg $ENC_OPTS -sameq -me_threshold 256 -mb_threshold 1024 -vcodec mpeg2video -f mpeg1video -bf 2 -flags +ildct+ilme -threads 4
+do_avconv $file $DEC_OPTS -me_threshold 256 -i ${target_path}/${outfile}mpeg2thread.mpg $ENC_OPTS -same_quant -me_threshold 256 -mb_threshold 1024 -vcodec mpeg2video -f mpeg1video -bf 2 -flags +ildct+ilme -threads 4
do_video_decoding
fi
@@ -72,6 +72,11 @@ do_video_encoding msmpeg4.avi "-qscale 10 -an -vcodec msmpeg4"
do_video_decoding
fi
+if [ -n "$do_msvideo1" ] ; then
+do_video_encoding msvideo1.avi "-an -vcodec msvideo1"
+do_video_decoding "" "-pix_fmt yuv420p"
+fi
+
if [ -n "$do_wmv1" ] ; then
do_video_encoding wmv1.avi "-qscale 10 -an -vcodec wmv1"
do_video_decoding
@@ -107,6 +112,11 @@ do_video_encoding huffyuv.avi "-an -vcodec huffyuv -pix_fmt yuv422p -sws_flags n
do_video_decoding "" "-strict -2 -pix_fmt yuv420p -sws_flags neighbor+bitexact"
fi
+if [ -n "$do_amv" ] ; then
+do_video_encoding amv.avi "-an -vcodec amv"
+do_video_decoding
+fi
+
if [ -n "$do_rc" ] ; then
do_video_encoding mpeg4-rc.avi "-b 400k -bf 2 -an -vcodec mpeg4"
do_video_decoding
@@ -151,6 +161,11 @@ do_video_encoding mjpeg.avi "-qscale 9 -an -vcodec mjpeg -pix_fmt yuvj420p"
do_video_decoding "" "-pix_fmt yuv420p"
fi
+if [ -n "$do_jpeg2000" ] ; then
+do_video_encoding jpeg2000.avi "-qscale 7 -an -vcodec j2k -strict experimental -pix_fmt rgb24"
+do_video_decoding "-vcodec j2k -strict experimental" "-pix_fmt yuv420p"
+fi
+
if [ -n "$do_ljpeg" ] ; then
do_video_encoding ljpeg.avi "-an -vcodec ljpeg -strict -1"
do_video_decoding
@@ -230,6 +245,11 @@ do_video_encoding dnxhd-720p-rd.dnxhd "-threads 4 -mbd rd -s hd720 -b 90M -pix_f
do_video_decoding "" "-s cif -pix_fmt yuv420p"
fi
+if [ -n "$do_dnxhd_720p_10bit" ] ; then
+do_video_encoding dnxhd-720p-10bit.dnxhd "-s hd720 -b 90M -pix_fmt yuv422p10 -vframes 5 -an"
+do_video_decoding "" "-s cif -pix_fmt yuv420p"
+fi
+
if [ -n "$do_svq1" ] ; then
do_video_encoding svq1.mov "-an -vcodec svq1 -qscale 3 -pix_fmt yuv410p"
do_video_decoding "" "-pix_fmt yuv420p"
@@ -240,6 +260,12 @@ do_video_encoding flashsv.flv "-an -vcodec flashsv -sws_flags neighbor+full_chro
do_video_decoding "" "-pix_fmt yuv420p -sws_flags area+accurate_rnd+bitexact"
fi
+if [ -n "$do_flashsv2" ] ; then
+do_video_encoding flashsv2.flv "-an -vcodec flashsv2 -sws_flags neighbor+full_chroma_int+accurate_rnd+bitexact -strict experimental"
+do_video_encoding flashsv2I.flv "-an -vcodec flashsv2 -sws_flags neighbor+full_chroma_int+accurate_rnd+bitexact -strict experimental -g 1"
+do_video_decoding "" "-pix_fmt yuv420p -sws_flags area+accurate_rnd+bitexact"
+fi
+
if [ -n "$do_roq" ] ; then
do_video_encoding roqav.roq "-vframes 5"
do_video_decoding "" "-pix_fmt yuv420p"
@@ -250,6 +276,11 @@ do_video_encoding qtrle.mov "-an -vcodec qtrle"
do_video_decoding "" "-pix_fmt yuv420p"
fi
+if [ -n "$do_qtrlegray" ] ; then
+do_video_encoding qtrlegray.mov "-an -vcodec qtrle -pix_fmt gray"
+do_video_decoding "" "-pix_fmt yuv420p"
+fi
+
if [ -n "$do_rgb" ] ; then
do_video_encoding rgb.avi "-an -vcodec rawvideo -pix_fmt bgr24"
do_video_decoding "" "-pix_fmt yuv420p"
@@ -273,8 +304,13 @@ do_audio_encoding ac3.rm "-vn -acodec ac3_fixed"
#$tiny_psnr $pcm_dst $pcm_ref 2 1024
fi
+if [ -n "$do_g723_1" ] ; then
+do_audio_encoding g723_1.tco "-b:a 6.3k -ac 1 -ar 8000 -acodec g723_1"
+do_audio_decoding
+fi
+
if [ -n "$do_g726" ] ; then
-do_audio_encoding g726.wav "-ab 32k -ac 1 -ar 8000 -acodec g726"
+do_audio_encoding g726.wav "-b:a 32k -ac 1 -ar 8000 -acodec g726"
do_audio_decoding
fi
@@ -315,12 +351,12 @@ fi
if [ -n "$do_wmav1" ] ; then
do_audio_encoding wmav1.asf "-acodec wmav1"
-do_ffmpeg_nomd5 $pcm_dst $DEC_OPTS -i $target_path/$file -f wav
+do_avconv_nomd5 $pcm_dst $DEC_OPTS -i $target_path/$file -f wav
$tiny_psnr $pcm_dst $pcm_ref 2 8192
fi
if [ -n "$do_wmav2" ] ; then
do_audio_encoding wmav2.asf "-acodec wmav2"
-do_ffmpeg_nomd5 $pcm_dst $DEC_OPTS -i $target_path/$file -f wav
+do_avconv_nomd5 $pcm_dst $DEC_OPTS -i $target_path/$file -f wav
$tiny_psnr $pcm_dst $pcm_ref 2 8192
fi
diff --git a/tests/copy.regression.ref b/tests/copy.regression.ref
deleted file mode 100644
index 0f62a7be75..0000000000
--- a/tests/copy.regression.ref
+++ /dev/null
@@ -1,465 +0,0 @@
-----------------
-./tests/data/a-ac3.rm
-first.nut second.nut differ: char 34, line 1
-1dd5a62b7edb3a1bcf77626af0a85bc1 first.nut
-----------------
-./tests/data/a-adpcm_ima.wav
-first.nut second.nut differ: char 34, line 1
-c95390143078f08db8a3bfba5789c2da first.nut
-----------------
-./tests/data/a-adpcm_ms.wav
-first.nut second.nut differ: char 34, line 1
-05e4d8842f4001fed506423e1a8ef963 first.nut
-----------------
-./tests/data/a-adpcm_qt.aiff
-first.nut second.nut differ: char 34, line 1
-7455d87f626f05e20030f4c93ec91e69 first.nut
-----------------
-./tests/data/a-adpcm_swf.flv
-c0402ee010a483403a655f353e184df1 first.nut
-----------------
-./tests/data/a-adpcm_yam.wav
-first.nut second.nut differ: char 34, line 1
-f861047f6c6f75cdf3ce7bb78a4003ad first.nut
-----------------
-./tests/data/a-alac.m4a
-first.nut second.nut differ: char 34, line 1
-ab152b0b01e540e74b04a807e3882083 first.nut
-----------------
-./tests/data/a-asv1.avi
-636fc0dfef1830cc51cf2c182bd4a7b2 first.nut
-----------------
-./tests/data/a-asv2.avi
-bbfc299390378c7bdbd7463434d8fcbe first.nut
-----------------
-./tests/data/a-dnxhd-1080i.mov
-first.nut second.nut differ: char 113, line 1
-037e31900e6cdf7161c2a0df23d9dc9d first.nut
-----------------
-./tests/data/a-dnxhd-720p-rd.dnxhd
-first.nut second.nut differ: char 113, line 1
-1237abac554ea9adb2a926641eec0de0 first.nut
-----------------
-./tests/data/a-dnxhd-720p.dnxhd
-first.nut second.nut differ: char 113, line 1
-6694322cefa2f482bc3dac8be22eb5d5 first.nut
-----------------
-./tests/data/a-dv.dv
-1aa367a56d31bb45f98d820121820909 first.nut
-----------------
-./tests/data/a-dv411.dv
-7ef296512960e00d96850f2606b4b683 first.nut
-----------------
-./tests/data/a-dv50.dv
-6424dd39e22a1789a8182d7e8da224a9 first.nut
-----------------
-./tests/data/a-error-mpeg4-adv.avi
-715b262e3e7c9be2b59525ba0289f30e first.nut
-----------------
-./tests/data/a-ffv1.avi
-edada4da2170ffd3386636cff67a90f0 first.nut
-----------------
-./tests/data/a-flac.flac
-d5e0a6d87034c21627afb2a904412a21 first.nut
-----------------
-./tests/data/a-flashsv.flv
-985076a8a87df1f91b34cbb81ce96217 first.nut
-----------------
-./tests/data/a-flv.flv
-6d01a0eb07c15ec3d0a70bfad0615bec first.nut
-----------------
-./tests/data/a-g726.wav
-first.nut second.nut differ: char 34, line 1
-59540b44c97b8e1eafc53ebdaeaf3eb8 first.nut
-----------------
-./tests/data/a-h261.avi
-18d47cc50e05e5c855a8aec1a5d8d9ec first.nut
-----------------
-./tests/data/a-h263.avi
-91b67a478420a30cf10c3d872f7e799b first.nut
-----------------
-./tests/data/a-h263p.avi
-1e9f108181dca2dd3bb621bb45fc5834 first.nut
-----------------
-./tests/data/a-huffyuv.avi
-62dccc2a428b561c08497f8378ea1567 first.nut
-----------------
-./tests/data/a-jpegls.avi
-35f1bb0f9b14bf3eb29134784f278c4f first.nut
-----------------
-./tests/data/a-ljpeg.avi
-45ec1072d8e55d6cfa784cc732830f3c first.nut
-----------------
-./tests/data/a-mjpeg.avi
-4e6d42fdda880661de8308cfa45652ee first.nut
-----------------
-./tests/data/a-mp2.mp2
-6c8d1a33dd994d63c68e5c9953b5cb8c first.nut
-----------------
-./tests/data/a-mpeg1.mpg
-first.nut second.nut differ: char 34, line 1
-9d444c67713ef70c06d35fd355200ed5 first.nut
-----------------
-./tests/data/a-mpeg1b.mpg
-first.nut second.nut differ: char 34, line 1
-9d444c67713ef70c06d35fd355200ed5 first.nut
-----------------
-./tests/data/a-mpeg2.mpg
-first.nut second.nut differ: char 34, line 1
-328f6a0069b76397c5ed0dcea8b69b50 first.nut
-----------------
-./tests/data/a-mpeg2.mpg
-first.nut second.nut differ: char 34, line 1
-328f6a0069b76397c5ed0dcea8b69b50 first.nut
-----------------
-./tests/data/a-mpeg2_422.mpg
-first.nut second.nut differ: char 34, line 1
-d27035bcf30801cd1bee6ac59e8f5e3e first.nut
-----------------
-./tests/data/a-mpeg2i.mpg
-first.nut second.nut differ: char 34, line 1
-c3351b79649825a6b9f62a2a1db633c1 first.nut
-----------------
-./tests/data/a-mpeg2ivlc-qprd.mpg
-first.nut second.nut differ: char 34, line 1
-d910da52fa10eb1deca10fa9443132d2 first.nut
-----------------
-./tests/data/a-mpeg2reuse.mpg
-first.nut second.nut differ: char 34, line 1
-c3351b79649825a6b9f62a2a1db633c1 first.nut
-----------------
-./tests/data/a-mpeg2thread.mpg
-first.nut second.nut differ: char 34, line 1
-c3351b79649825a6b9f62a2a1db633c1 first.nut
-----------------
-./tests/data/a-mpeg2threadivlc.mpg
-first.nut second.nut differ: char 34, line 1
-c3351b79649825a6b9f62a2a1db633c1 first.nut
-----------------
-./tests/data/a-mpeg4-Q.avi
-first.nut second.nut differ: char 34, line 1
-305bab90451e2c3b741e3aef51bc2a4c first.nut
-----------------
-./tests/data/a-mpeg4-adap.avi
-first.nut second.nut differ: char 34, line 1
-5d9315ec49c4122f6f23cf84cab5fc53 first.nut
-----------------
-./tests/data/a-mpeg4-adv.avi
-5d672bf4c2e879d6a20e349cb4dc09a6 first.nut
-----------------
-./tests/data/a-mpeg4-nr.avi
-0243b2e03115fe948f99da1ee10ae588 first.nut
-----------------
-./tests/data/a-mpeg4-qprd.avi
-first.nut second.nut differ: char 34, line 1
-5d9315ec49c4122f6f23cf84cab5fc53 first.nut
-----------------
-./tests/data/a-mpeg4-rc.avi
-first.nut second.nut differ: char 34, line 1
-5d9315ec49c4122f6f23cf84cab5fc53 first.nut
-----------------
-./tests/data/a-mpeg4-thread.avi
-first.nut second.nut differ: char 34, line 1
-6aa94d589e9e7626e51575d8a2aec6e7 first.nut
-----------------
-./tests/data/a-msmpeg4.avi
-836d432509ff22fd363237ef1dced5f3 first.nut
-----------------
-./tests/data/a-msmpeg4v2.avi
-37f253da3666fb057edecb86ed2dba39 first.nut
-----------------
-./tests/data/a-odivx.mp4
-e3bd9d8a3417abc749c489e64119dbf3 first.nut
-----------------
-./tests/data/a-pcm_alaw.wav
-first.nut second.nut differ: char 34, line 1
-22853e7806b0f0162fd5e2573e34b03c first.nut
-----------------
-./tests/data/a-pcm_f32be.au
-first.nut second.nut differ: char 34, line 1
-94cb60c3107ec509af79191e86099a0e first.nut
-----------------
-./tests/data/a-pcm_f32le.wav
-first.nut second.nut differ: char 34, line 1
-8d887b27a8531390af5b682557631986 first.nut
-----------------
-./tests/data/a-pcm_f64be.au
-first.nut second.nut differ: char 34, line 1
-e0c7b64e13bb9398a57dac60806515fb first.nut
-----------------
-./tests/data/a-pcm_f64le.wav
-first.nut second.nut differ: char 34, line 1
-9dbb9bda0c990502e910e082a008433f first.nut
-----------------
-./tests/data/a-pcm_mulaw.wav
-first.nut second.nut differ: char 34, line 1
-78c4aae32fdddaba4f9caa5683018c94 first.nut
-----------------
-./tests/data/a-pcm_s16be.mkv
-first.nut second.nut differ: char 34, line 1
-279810a0c30a06c4ab7de154e3de140d first.nut
-----------------
-./tests/data/a-pcm_s16be.mov
-first.nut second.nut differ: char 42, line 1
-0a8ede3d121f17a98e9038771eb98e1a first.nut
-----------------
-./tests/data/a-pcm_s16le.mkv
-47942f5188f8d081bcbe7fb82550b135 first.nut
-----------------
-./tests/data/a-pcm_s16le.wav
-first.nut second.nut differ: char 34, line 1
-9f868acb99ba107750f165431f95c382 first.nut
-----------------
-./tests/data/a-pcm_s24be.mov
-first.nut second.nut differ: char 34, line 1
-9c96762f631851014dec14b506091cc1 first.nut
-----------------
-./tests/data/a-pcm_s24daud.302
-60ecb7037b205e2013490fdadab9697b first.nut
-----------------
-./tests/data/a-pcm_s24le.wav
-first.nut second.nut differ: char 34, line 1
-5805a2e6e2eddede4757fd488d0d6adb first.nut
-----------------
-./tests/data/a-pcm_s32be.mov
-first.nut second.nut differ: char 34, line 1
-d6c868a1130be573bbe0cfc88913a60c first.nut
-----------------
-./tests/data/a-pcm_s32le.wav
-first.nut second.nut differ: char 34, line 1
-3e0a81669647739c490f12521f897527 first.nut
-----------------
-./tests/data/a-pcm_s8.mov
-first.nut second.nut differ: char 34, line 1
-a6fe0827966ee4515f27c7053d579229 first.nut
-----------------
-./tests/data/a-pcm_u8.wav
-first.nut second.nut differ: char 34, line 1
-f0d398fd651cdedfd7b4c5433c08fd79 first.nut
-----------------
-./tests/data/a-pcm_zork.wav
-first.nut second.nut differ: char 34, line 1
-69e40cc9266836a7101000677ee14a87 first.nut
-----------------
-./tests/data/a-roqav.roq
-first.nut second.nut differ: char 34, line 1
-0e7a57bb28054b7e319eac2ba0a4be23 first.nut
-----------------
-./tests/data/a-rv10.rm
-first.nut second.nut differ: char 34, line 1
-80f982c6bffea91ff45a9b320cb93c14 first.nut
-----------------
-./tests/data/a-rv20.rm
-first.nut second.nut differ: char 34, line 1
-5b02113c0941578ca6918215eed8a728 first.nut
-----------------
-./tests/data/a-snow.avi
-e73b88690aa491491ede5970641134ad first.nut
-----------------
-./tests/data/a-snow53.avi
-18a6b061252c8c74bd22b42a7d5b2bae first.nut
-----------------
-./tests/data/a-svq1.mov
-first.nut second.nut differ: char 197, line 1
-6bbe90d47c1763654e8388ce51ab911e first.nut
-----------------
-./tests/data/a-wmav1.asf
-first.nut second.nut differ: char 34, line 1
-c3f7bc239ff166d738b29252b47bd437 first.nut
-----------------
-./tests/data/a-wmav2.asf
-first.nut second.nut differ: char 34, line 1
-930f1824b9677f0b6b714f1c6ddcf825 first.nut
-----------------
-./tests/data/a-wmv1.avi
-206bd9985b575f61a8a580656af39beb first.nut
-----------------
-./tests/data/a-wmv2.avi
-09178a3c2b99d4f7ad1f7a761a2b803a first.nut
-----------------
-./tests/data/b-lavf-bgr24.yuv
-09178a3c2b99d4f7ad1f7a761a2b803a first.nut
-----------------
-./tests/data/b-lavf-gray.yuv
-09178a3c2b99d4f7ad1f7a761a2b803a first.nut
-----------------
-./tests/data/b-lavf-monob.yuv
-09178a3c2b99d4f7ad1f7a761a2b803a first.nut
-----------------
-./tests/data/b-lavf-monow.yuv
-09178a3c2b99d4f7ad1f7a761a2b803a first.nut
-----------------
-./tests/data/b-lavf-rgb24.yuv
-09178a3c2b99d4f7ad1f7a761a2b803a first.nut
-----------------
-./tests/data/b-lavf-rgb32.yuv
-09178a3c2b99d4f7ad1f7a761a2b803a first.nut
-----------------
-./tests/data/b-lavf-rgb555.yuv
-09178a3c2b99d4f7ad1f7a761a2b803a first.nut
-----------------
-./tests/data/b-lavf-rgb565.yuv
-09178a3c2b99d4f7ad1f7a761a2b803a first.nut
-----------------
-./tests/data/b-lavf-yuv410p.yuv
-09178a3c2b99d4f7ad1f7a761a2b803a first.nut
-----------------
-./tests/data/b-lavf-yuv411p.yuv
-09178a3c2b99d4f7ad1f7a761a2b803a first.nut
-----------------
-./tests/data/b-lavf-yuv420p.yuv
-09178a3c2b99d4f7ad1f7a761a2b803a first.nut
-----------------
-./tests/data/b-lavf-yuv422p.yuv
-09178a3c2b99d4f7ad1f7a761a2b803a first.nut
-----------------
-./tests/data/b-lavf-yuv440p.yuv
-09178a3c2b99d4f7ad1f7a761a2b803a first.nut
-----------------
-./tests/data/b-lavf-yuv444p.yuv
-09178a3c2b99d4f7ad1f7a761a2b803a first.nut
-----------------
-./tests/data/b-lavf-yuvj420p.yuv
-09178a3c2b99d4f7ad1f7a761a2b803a first.nut
-----------------
-./tests/data/b-lavf-yuvj422p.yuv
-09178a3c2b99d4f7ad1f7a761a2b803a first.nut
-----------------
-./tests/data/b-lavf-yuvj440p.yuv
-09178a3c2b99d4f7ad1f7a761a2b803a first.nut
-----------------
-./tests/data/b-lavf-yuvj444p.yuv
-09178a3c2b99d4f7ad1f7a761a2b803a first.nut
-----------------
-./tests/data/b-lavf-yuyv422.yuv
-09178a3c2b99d4f7ad1f7a761a2b803a first.nut
-----------------
-./tests/data/b-lavf.aif
-first.nut second.nut differ: char 34, line 1
-3f1d3faae1671f1cf862ddb66a5c59d1 first.nut
-----------------
-./tests/data/b-lavf.al
-e6d4b977e74a535b039a6a1dfed2dbc1 first.nut
-----------------
-./tests/data/b-lavf.asf
-first.nut second.nut differ: char 34, line 1
-57727c41b3974697c0a79cfd08515ddd first.nut
-----------------
-./tests/data/b-lavf.au
-first.nut second.nut differ: char 34, line 1
-1da12f41bc5ea1fd851e8a48b222c204 first.nut
-----------------
-./tests/data/b-lavf.avi
-a88edf9fb8e02e658ba3cae9313a3cdc first.nut
-----------------
-./tests/data/b-lavf.dv
-first.nut second.nut differ: char 34, line 1
-819018a5d91c55312ffe784e8712ac4b first.nut
-----------------
-./tests/data/b-lavf.ffm
-first.nut second.nut differ: char 34, line 1
-17f8894a05c71adb51c9a0ff1b9040bb first.nut
-----------------
-./tests/data/b-lavf.flv
-d74edb56e74e0eea748863f3aeeafa61 first.nut
-----------------
-./tests/data/b-lavf.gif
-first.nut second.nut differ: char 34, line 1
-ef9ba6bf88f44d9d326049ef2872a4d3 first.nut
-----------------
-./tests/data/b-lavf.gxf
-first.nut second.nut differ: char 44, line 1
-522957f46ba46051fd03a0868c905e54 first.nut
-----------------
-./tests/data/b-lavf.mkv
-8c9427bb75c96210d6580d9b881d9e4d first.nut
-----------------
-./tests/data/b-lavf.mmf
-first.nut second.nut differ: char 42, line 1
-298136aef02389fc5b0844995fe6ac72 first.nut
-----------------
-./tests/data/b-lavf.mov
-ce895b33ff206fafbae89fd5a8f959d2 first.nut
-----------------
-./tests/data/b-lavf.mpg
-d279e3343993267241c2fac4f4563cdb first.nut
-----------------
-./tests/data/b-lavf.mxf
-first.nut second.nut differ: char 34, line 1
-3e98a90d40986b8ea4305be06175927a first.nut
-----------------
-./tests/data/b-lavf.mxf_d10
-1ee69644165344a096ddfaaac951a0e9 first.nut
-----------------
-./tests/data/b-lavf.nut
-1426bca4c65796516a3e94b6bebc5a58 first.nut
-----------------
-./tests/data/b-lavf.ogg
-c986ce79045f2068ae1bedc2b8702884 first.nut
-----------------
-./tests/data/b-lavf.rm
-first.nut second.nut differ: char 34, line 1
-a3b2c9d3ec2c86b6d4c3bf0ed91391c3 first.nut
-----------------
-./tests/data/b-lavf.swf
-first.nut second.nut differ: char 34, line 1
-d4a5c5e6343dc17bed49397d889e0799 first.nut
-----------------
-./tests/data/b-lavf.ts
-40fd2ece0c8386d3a250943eab023795 first.nut
-----------------
-./tests/data/b-lavf.ul
-1c4c747e2e9c0fd195656359341eef76 first.nut
-----------------
-./tests/data/b-lavf.voc
-first.nut second.nut differ: char 42, line 1
-500ef42830c5bc2af849dbdcc4380f1b first.nut
-----------------
-./tests/data/b-lavf.wav
-first.nut second.nut differ: char 42, line 1
-8d4c6a79af442610ad912625c9b85d02 first.nut
-----------------
-./tests/data/b-lavf.y4m
-f42a6ff4488de306925b057ecee75b0e first.nut
-----------------
-./tests/data/b-lavf02.bmp
-first.nut second.nut differ: char 113, line 1
-02e3c782ef3a0c96e820201d4d4b8268 first.nut
-----------------
-./tests/data/b-lavf02.jpg
-61a19c3012a5aa056d8e9a589e29de2e first.nut
-----------------
-./tests/data/b-lavf02.pcx
-first.nut second.nut differ: char 113, line 1
-3c4e1b9c8d5dd2bedb8eebd1edc7a2f5 first.nut
-----------------
-./tests/data/b-lavf02.pgm
-first.nut second.nut differ: char 113, line 1
-cc36bdadd7aef501a6d5d588dec2188b first.nut
-----------------
-./tests/data/b-lavf02.ppm
-first.nut second.nut differ: char 113, line 1
-453ec690bea6c3668e2b65e0b7ad14c8 first.nut
-----------------
-./tests/data/b-lavf02.sgi
-first.nut second.nut differ: char 113, line 1
-6cdadd58aaa5ad196697352e96723e52 first.nut
-----------------
-./tests/data/b-lavf02.tga
-4144d2b4ee2948c1a16f7fc31b381be3 first.nut
-----------------
-./tests/data/b-lavf02.tiff
-first.nut second.nut differ: char 113, line 1
-237fa2da2d5f4930dae9825c9cf928a6 first.nut
-----------------
-./tests/data/b-pbmpipe.pbm
-first.nut second.nut differ: char 113, line 1
-2c65ef7188398da8a5f107b9dd5fb998 first.nut
-----------------
-./tests/data/b-pgmpipe.pgm
-first.nut second.nut differ: char 113, line 1
-b7e98248ada1e6f7170bc7fedee3825c first.nut
-----------------
-./tests/data/b-ppmpipe.ppm
-first.nut second.nut differ: char 113, line 1
-869fcefe430c35a9a8e46fd5f040b62e first.nut
diff --git a/tests/copycooker.sh b/tests/copycooker.sh
index 3118e3f842..4b5811dcf6 100755
--- a/tests/copycooker.sh
+++ b/tests/copycooker.sh
@@ -13,8 +13,8 @@ rm -f $logfile
for i in $list ; do
echo ---------------- >> $logfile
echo $i >> $logfile
- ./ffmpeg -flags +bitexact -i $i -acodec copy -vcodec copy -y first.nut
- ./ffmpeg -flags +bitexact -i first.nut -acodec copy -vcodec copy -y second.nut
+ ./ffmpeg_g -flags +bitexact -i $i -acodec copy -vcodec copy -y first.nut
+ ./ffmpeg_g -flags +bitexact -i first.nut -acodec copy -vcodec copy -y second.nut
cmp first.nut second.nut >> $logfile
md5sum first.nut >> $logfile
done
diff --git a/tests/fate-run.sh b/tests/fate-run.sh
index 10497c497e..350ff573c7 100755
--- a/tests/fate-run.sh
+++ b/tests/fate-run.sh
@@ -16,7 +16,8 @@ cmp=${6:-diff}
ref=${7:-"${base}/ref/fate/${test}"}
fuzz=$8
threads=${9:-1}
-thread_type=${10:-3}
+thread_type=${10:-frame+slice}
+tool=${11}
outdir="tests/data/fate"
outfile="${outdir}/${test}"
@@ -49,34 +50,34 @@ run(){
$target_exec $target_path/"$@"
}
-ffmpeg(){
- run ffmpeg -v 0 -threads $threads -thread_type $thread_type "$@"
+avconv(){
+ run $tool -nostats -threads $threads -thread_type $thread_type "$@"
}
framecrc(){
- ffmpeg "$@" -f framecrc -
+ avconv "$@" -f framecrc -
}
framemd5(){
- ffmpeg "$@" -f framemd5 -
+ avconv "$@" -f framemd5 -
}
crc(){
- ffmpeg "$@" -f crc -
+ avconv "$@" -f crc -
}
md5(){
- ffmpeg "$@" md5:
+ avconv "$@" md5:
}
pcm(){
- ffmpeg "$@" -vn -f s16le -
+ avconv "$@" -vn -f s16le -
}
regtest(){
t="${test#$2-}"
ref=${base}/ref/$2/$t
- ${base}/${1}-regression.sh $t $2 $3 "$target_exec" "$target_path" "$threads" "$thread_type"
+ ${base}/${1}-regression.sh $t $2 $3 "$target_exec" "$target_path" "$threads" "$thread_type" "$tool"
}
codectest(){
@@ -104,7 +105,7 @@ seektest(){
file=$(echo tests/data/$d/$file)
;;
esac
- $target_exec $target_path/tests/seek_test $target_path/$file
+ run libavformat/seek-test $target_path/$file
}
mkdir -p "$outdir"
diff --git a/tests/fate-update.sh b/tests/fate-update.sh
new file mode 100755
index 0000000000..6b4668fc03
--- /dev/null
+++ b/tests/fate-update.sh
@@ -0,0 +1,55 @@
+#! /bin/sh
+
+set -e
+
+base=$(dirname $0)
+ref="${base}/ref/fate"
+
+FATE_DB_URL="http://fate.multimedia.cx/fate-tests.sqlite.bz2"
+FATE_DB=$(mktemp fate-db.XXXXXX)
+SQL_TESTS='SELECT id,short_name,command FROM test_spec WHERE active=1 ORDER BY short_name'
+
+do_sql(){
+ sqlite3 -noheader -separator ' ' "$FATE_DB" "$@"
+}
+
+wget -q -O - "$FATE_DB_URL" | bunzip2 > "$FATE_DB"
+mkdir -p "$ref"
+exec 3>"$base/fate.mak"
+
+do_sql "$SQL_TESTS" | while read id name command; do
+ case "$name" in
+ 00-full-regression|ffmpeg-help|binsize-*) continue ;;
+ esac
+ case "$command" in
+ {MD5}*)
+ command="${command#*ffmpeg}"; command="${command% -}"
+ command="md5 $command"
+ ;;
+ {*}*) continue ;;
+ *-f\ framecrc\ -)
+ command="${command#*ffmpeg}"; command="${command% -f *}"
+ command="framecrc $command"
+ ;;
+ *-f\ framemd5\ -)
+ command="${command#*ffmpeg}"; command="${command% -f *}"
+ command="framemd5 $command"
+ ;;
+ *-f\ crc\ -)
+ command="${command#*ffmpeg}"; command="${command% -f *}"
+ command="crc $command"
+ ;;
+ *)
+ echo "Unhandled command '$command'"
+ exit 1
+ ;;
+ esac
+ command=$(echo "$command" | sed 's/\$SAMPLES_PATH/$(SAMPLES)/g')
+ command=$(echo "$command" | sed 's/ *$//')
+ do_sql "SELECT expected_stdout FROM test_spec WHERE id=$id" | awk '/./{print}' > "$ref/$name"
+ printf "FATE_TESTS += fate-${name}\n" >&3
+ printf "fate-${name}: CMD = %s\n" "$command" >&3
+done
+
+exec 3<&-
+rm -f "$FATE_DB"
diff --git a/tests/fate.mak b/tests/fate.mak
index 0e3331178b..d2e551ec6f 100644
--- a/tests/fate.mak
+++ b/tests/fate.mak
@@ -35,7 +35,7 @@ fate-bink-demux-video: CMD = framecrc -i $(SAMPLES)/bink/hol2br.bik
FATE_TESTS += fate-caf
fate-caf: CMD = crc -i $(SAMPLES)/caf/caf-pcm16.caf
FATE_TESTS += fate-cdgraphics
-fate-cdgraphics: CMD = framecrc -t 1 -i $(SAMPLES)/cdgraphics/BrotherJohn.cdg -pix_fmt rgb24
+fate-cdgraphics: CMD = framecrc -i $(SAMPLES)/cdgraphics/BrotherJohn.cdg -pix_fmt rgb24 -t 1
FATE_TESTS += fate-cljr
fate-cljr: CMD = framecrc -i $(SAMPLES)/cljr/testcljr-partial.avi
FATE_TESTS += fate-corepng
@@ -124,12 +124,16 @@ FATE_TESTS += fate-frwu
fate-frwu: CMD = framecrc -i $(SAMPLES)/frwu/frwu.avi
FATE_TESTS += fate-funcom-iss
fate-funcom-iss: CMD = md5 -i $(SAMPLES)/funcom-iss/0004010100.iss -f s16le
+FATE_TESTS += fate-g729-0
+fate-g729-0: CMD = framecrc -i $(SAMPLES)/act/REC03.act -t 10
+FATE_TESTS += fate-g729-1
+fate-g729-1: CMD = framecrc -i $(SAMPLES)/act/REC05.act -t 10
FATE_TESTS += fate-id-cin-video
fate-id-cin-video: CMD = framecrc -i $(SAMPLES)/idcin/idlog-2MB.cin -pix_fmt rgb24
FATE_TESTS += fate-idroq-video-dpcm
fate-idroq-video-dpcm: CMD = framecrc -i $(SAMPLES)/idroq/idlogo.roq
-FATE_TESTS += fate-idroq-video-encode
-fate-idroq-video-encode: CMD = md5 -t 0.2 -f image2 -vcodec pgmyuv -i $(SAMPLES)/ffmpeg-synthetic/vsynth1/%02d.pgm -sws_flags +bitexact -vf pad=512:512:80:112 -f RoQ
+FATE_TESTS-$(CONFIG_AVFILTER) += fate-idroq-video-encode
+fate-idroq-video-encode: CMD = md5 -f image2 -vcodec pgmyuv -i $(SAMPLES)/ffmpeg-synthetic/vsynth1/%02d.pgm -sws_flags +bitexact -vf pad=512:512:80:112 -f RoQ -t 0.2
FATE_TESTS += fate-iff-byterun1
fate-iff-byterun1: CMD = framecrc -i $(SAMPLES)/iff/ASH.LBM -pix_fmt rgb24
FATE_TESTS += fate-iff-fibonacci
@@ -175,7 +179,7 @@ fate-maxis-xa: CMD = md5 -i $(SAMPLES)/maxis-xa/SC2KBUG.XA -f s16le
FATE_TESTS += fate-mimic
fate-mimic: CMD = framecrc -idct simple -i $(SAMPLES)/mimic/mimic2-womanloveffmpeg.cam -vsync 0
FATE_TESTS += fate-motionpixels
-fate-motionpixels: CMD = framecrc -i $(SAMPLES)/motion-pixels/INTRO-partial.MVI -an -pix_fmt rgb24
+fate-motionpixels: CMD = framecrc -i $(SAMPLES)/motion-pixels/INTRO-partial.MVI -an -pix_fmt rgb24 -vframes 111
FATE_TESTS += fate-mpc7-demux
fate-mpc7-demux: CMD = crc -i $(SAMPLES)/musepack/inside-mp7.mpc -acodec copy
FATE_TESTS += fate-mpc8-demux
diff --git a/tests/fate.sh b/tests/fate.sh
index 9fd117c3bc..e04c8710d7 100755
--- a/tests/fate.sh
+++ b/tests/fate.sh
@@ -35,7 +35,7 @@ checkout(){
update()(
cd ${src} || return
case "$repo" in
- git:*) git pull ;;
+ git:*) git pull --quiet ;;
esac
)
@@ -70,7 +70,7 @@ fate()(
)
clean(){
- rm -r ${build} ${inst}
+ rm -rf ${build} ${inst}
}
report(){
diff --git a/tests/fate/h264.mak b/tests/fate/h264.mak
index 969bf413e4..4716d9f521 100644
--- a/tests/fate/h264.mak
+++ b/tests/fate/h264.mak
@@ -113,6 +113,10 @@ FATE_H264 = aud_mw_e \
frext-hcafr3_hhi_a \
frext-hcafr4_hhi_a \
frext-hcamff1_hhi_b \
+ frext-hi422fr10_sony_b \
+ frext-hi422fr13_sony_b \
+ frext-hi422fr1_sony_a \
+ frext-hi422fr6_sony_a \
frext-hpca_brcm_c \
frext-hpcadq_brcm_b \
frext-hpcafl_bcrm_c \
@@ -134,6 +138,13 @@ FATE_H264 = aud_mw_e \
frext-pph10i5_panasonic_a \
frext-pph10i6_panasonic_a \
frext-pph10i7_panasonic_a \
+ frext-pph422i1_panasonic_a \
+ frext-pph422i2_panasonic_a \
+ frext-pph422i3_panasonic_a \
+ frext-pph422i4_panasonic_a \
+ frext-pph422i5_panasonic_a \
+ frext-pph422i6_panasonic_a \
+ frext-pph422i7_panasonic_a \
hcbp2_hhi_a \
hcmp1_hhi_a \
ls_sva_d \
@@ -294,6 +305,10 @@ fate-h264-conformance-frext-hcafr2_hhi_a: CMD = framecrc -vsync 0 -i $(SAMPLES)/
fate-h264-conformance-frext-hcafr3_hhi_a: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/HCAFR3_HHI.264
fate-h264-conformance-frext-hcafr4_hhi_a: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/HCAFR4_HHI.264
fate-h264-conformance-frext-hcamff1_hhi_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/HCAMFF1_HHI.264
+fate-h264-conformance-frext-hi422fr10_sony_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/Hi422FR10_SONY_B.264
+fate-h264-conformance-frext-hi422fr13_sony_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/Hi422FR13_SONY_B.264 -pix_fmt yuv422p10le
+fate-h264-conformance-frext-hi422fr1_sony_a: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/Hi422FR1_SONY_A.jsv
+fate-h264-conformance-frext-hi422fr6_sony_a: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/Hi422FR6_SONY_A.jsv -pix_fmt yuv422p10le
fate-h264-conformance-frext-hpca_brcm_c: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/HPCA_BRCM_C.264
fate-h264-conformance-frext-hpcadq_brcm_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/HPCADQ_BRCM_B.264
fate-h264-conformance-frext-hpcafl_bcrm_c: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/HPCAFL_BRCM_C.264 -vsync 0
@@ -315,6 +330,13 @@ fate-h264-conformance-frext-pph10i4_panasonic_a: CMD = framecrc -vsync 0 -i $(SA
fate-h264-conformance-frext-pph10i5_panasonic_a: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/PPH10I5_Panasonic_A.264 -pix_fmt yuv420p10le
fate-h264-conformance-frext-pph10i6_panasonic_a: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/PPH10I6_Panasonic_A.264 -pix_fmt yuv420p10le
fate-h264-conformance-frext-pph10i7_panasonic_a: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/PPH10I7_Panasonic_A.264 -pix_fmt yuv420p10le
+fate-h264-conformance-frext-pph422i1_panasonic_a: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/PPH422I1_Panasonic_A.264 -pix_fmt yuv422p10le
+fate-h264-conformance-frext-pph422i2_panasonic_a: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/PPH422I2_Panasonic_A.264 -pix_fmt yuv422p10le
+fate-h264-conformance-frext-pph422i3_panasonic_a: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/PPH422I3_Panasonic_A.264 -pix_fmt yuv422p10le
+fate-h264-conformance-frext-pph422i4_panasonic_a: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/PPH422I4_Panasonic_A.264 -pix_fmt yuv422p10le
+fate-h264-conformance-frext-pph422i5_panasonic_a: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/PPH422I5_Panasonic_A.264 -pix_fmt yuv422p10le
+fate-h264-conformance-frext-pph422i6_panasonic_a: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/PPH422I6_Panasonic_A.264 -pix_fmt yuv422p10le
+fate-h264-conformance-frext-pph422i7_panasonic_a: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/PPH422I7_Panasonic_A.264 -pix_fmt yuv422p10le
fate-h264-conformance-hcbp2_hhi_a: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/HCBP2_HHI_A.264
fate-h264-conformance-hcmp1_hhi_a: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/HCMP1_HHI_A.264
fate-h264-conformance-ls_sva_d: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/LS_SVA_D.264
@@ -352,6 +374,6 @@ fate-h264-conformance-sva_fm1_e: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conf
fate-h264-conformance-sva_nl1_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/SVA_NL1_B.264
fate-h264-conformance-sva_nl2_e: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/SVA_NL2_E.264
-fate-h264-interlace-crop: CMD = framecrc -vsync 0 -vframes 3 -i $(SAMPLES)/h264/interlaced_crop.mp4
+fate-h264-interlace-crop: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264/interlaced_crop.mp4 -vframes 3
fate-h264-lossless: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264/lossless.h264
fate-h264-extreme-plane-pred: CMD = framemd5 -strict 1 -vsync 0 -i $(SAMPLES)/h264/extreme-plane-pred.h264
diff --git a/tests/fate/libavutil.mak b/tests/fate/libavutil.mak
index 4299f081ac..a65b724305 100644
--- a/tests/fate/libavutil.mak
+++ b/tests/fate/libavutil.mak
@@ -25,6 +25,10 @@ FATE_TESTS += fate-eval
fate-eval: libavutil/eval-test$(EXESUF)
fate-eval: CMD = run libavutil/eval-test
+FATE_TESTS += fate-fifo
+fate-fifo: libavutil/fifo-test$(EXESUF)
+fate-fifo: CMD = run libavutil/fifo-test
+
FATE_TESTS += fate-md5
fate-md5: libavutil/md5-test$(EXESUF)
fate-md5: CMD = run libavutil/md5-test
diff --git a/tests/fate/mp3.mak b/tests/fate/mp3.mak
index 859a4f3802..9dfa829008 100644
--- a/tests/fate/mp3.mak
+++ b/tests/fate/mp3.mak
@@ -4,32 +4,32 @@ fate-mp3-float-conf-compl: CMP = stddev
fate-mp3-float-conf-compl: REF = $(SAMPLES)/mp3-conformance/compl.pcm
FATE_MP3 += fate-mp3-float-conf-he_32khz
-fate-mp3-float-conf-he_32khz: CMD = pcm -acodec mp3float -fs 343296 -i $(SAMPLES)/mp3-conformance/he_32khz.bit
+fate-mp3-float-conf-he_32khz: CMD = pcm -acodec mp3float -i $(SAMPLES)/mp3-conformance/he_32khz.bit -fs 343296
fate-mp3-float-conf-he_32khz: CMP = stddev
fate-mp3-float-conf-he_32khz: REF = $(SAMPLES)/mp3-conformance/he_32khz.pcm
FATE_MP3 += fate-mp3-float-conf-he_44khz
-fate-mp3-float-conf-he_44khz: CMD = pcm -acodec mp3float -fs 942336 -i $(SAMPLES)/mp3-conformance/he_44khz.bit
+fate-mp3-float-conf-he_44khz: CMD = pcm -acodec mp3float -i $(SAMPLES)/mp3-conformance/he_44khz.bit -fs 942336
fate-mp3-float-conf-he_44khz: CMP = stddev
fate-mp3-float-conf-he_44khz: REF = $(SAMPLES)/mp3-conformance/he_44khz.pcm
FATE_MP3 += fate-mp3-float-conf-he_48khz
-fate-mp3-float-conf-he_48khz: CMD = pcm -acodec mp3float -fs 343296 -i $(SAMPLES)/mp3-conformance/he_48khz.bit
+fate-mp3-float-conf-he_48khz: CMD = pcm -acodec mp3float -i $(SAMPLES)/mp3-conformance/he_48khz.bit -fs 343296
fate-mp3-float-conf-he_48khz: CMP = stddev
fate-mp3-float-conf-he_48khz: REF = $(SAMPLES)/mp3-conformance/he_48khz.pcm
FATE_MP3 += fate-mp3-float-conf-hecommon
-fate-mp3-float-conf-hecommon: CMD = pcm -acodec mp3float -fs 133632 -i $(SAMPLES)/mp3-conformance/hecommon.bit
+fate-mp3-float-conf-hecommon: CMD = pcm -acodec mp3float -i $(SAMPLES)/mp3-conformance/hecommon.bit -fs 133632
fate-mp3-float-conf-hecommon: CMP = stddev
fate-mp3-float-conf-hecommon: REF = $(SAMPLES)/mp3-conformance/hecommon.pcm
FATE_MP3 += fate-mp3-float-conf-si
-fate-mp3-float-conf-si: CMD = pcm -acodec mp3float -fs 269568 -i $(SAMPLES)/mp3-conformance/si.bit
+fate-mp3-float-conf-si: CMD = pcm -acodec mp3float -i $(SAMPLES)/mp3-conformance/si.bit -fs 269568
fate-mp3-float-conf-si: CMP = stddev
fate-mp3-float-conf-si: REF = $(SAMPLES)/mp3-conformance/si.pcm
FATE_MP3 += fate-mp3-float-conf-si_block
-fate-mp3-float-conf-si_block: CMD = pcm -acodec mp3float -fs 145152 -i $(SAMPLES)/mp3-conformance/si_block.bit
+fate-mp3-float-conf-si_block: CMD = pcm -acodec mp3float -i $(SAMPLES)/mp3-conformance/si_block.bit -fs 145152
fate-mp3-float-conf-si_block: CMP = stddev
fate-mp3-float-conf-si_block: REF = $(SAMPLES)/mp3-conformance/si_block.pcm
diff --git a/tests/fate/prores.mak b/tests/fate/prores.mak
new file mode 100644
index 0000000000..17a581d5ec
--- /dev/null
+++ b/tests/fate/prores.mak
@@ -0,0 +1,15 @@
+FATE_PRORES = fate-prores-422 \
+ fate-prores-422_hq \
+ fate-prores-422_lt \
+ fate-prores-422_proxy \
+ fate-prores-alpha \
+
+FATE_TESTS += $(FATE_PRORES)
+fate-prores: $(FATE_PRORES)
+
+fate-prores-422: CMD = framecrc -flags +bitexact -vsync 0 -i $(SAMPLES)/prores/Sequence_1-Apple_ProRes_422.mov -pix_fmt yuv422p10le
+fate-prores-422_hq: CMD = framecrc -flags +bitexact -vsync 0 -i $(SAMPLES)/prores/Sequence_1-Apple_ProRes_422_HQ.mov -pix_fmt yuv422p10le
+fate-prores-422_lt: CMD = framecrc -flags +bitexact -vsync 0 -i $(SAMPLES)/prores/Sequence_1-Apple_ProRes_422_LT.mov -pix_fmt yuv422p10le
+fate-prores-422_proxy: CMD = framecrc -flags +bitexact -vsync 0 -i $(SAMPLES)/prores/Sequence_1-Apple_ProRes_422_Proxy.mov -pix_fmt yuv422p10le
+fate-prores-alpha: CMD = framecrc -flags +bitexact -vsync 0 -i $(SAMPLES)/prores/Sequence_1-Apple_ProRes_with_Alpha.mov -pix_fmt yuv444p10le
+
diff --git a/tests/fate2.mak b/tests/fate2.mak
index a743f0cd59..376a0196b6 100644
--- a/tests/fate2.mak
+++ b/tests/fate2.mak
@@ -125,13 +125,17 @@ fate-atrac3-3: CMP = oneoff
fate-atrac3-3: REF = $(SAMPLES)/atrac3/mc_sich_at3_132_small.pcm
FATE_TESTS += fate-gsm
-fate-gsm: CMD = framecrc -t 10 -i $(SAMPLES)/gsm/sample-gsm-8000.mov
+fate-gsm: CMD = framecrc -i $(SAMPLES)/gsm/sample-gsm-8000.mov -t 10
FATE_TESTS += fate-gsm-ms
fate-gsm-ms: CMD = framecrc -i $(SAMPLES)/gsm/ciao.wav
FATE_TESTS += fate-g722dec-1
-fate-g722dec-1: CMD = framecrc -ar 16000 -i $(SAMPLES)/g722/conf-adminmenu-162.g722
+fate-g722dec-1: CMD = framecrc -i $(SAMPLES)/g722/conf-adminmenu-162.g722
+
+FATE_TESTS += fate-g722enc
+fate-g722enc: tests/data/asynth-16000-1.sw
+fate-g722enc: CMD = md5 -ar 16000 -ac 1 -f s16le -i $(TARGET_PATH)/tests/data/asynth-16000-1.sw -acodec g722 -ac 1 -f g722
FATE_TESTS += fate-msmpeg4v1
fate-msmpeg4v1: CMD = framecrc -flags +bitexact -dct fastint -idct simple -i $(SAMPLES)/msmpeg4v1/mpg4.avi -an
diff --git a/tests/lavf-regression.sh b/tests/lavf-regression.sh
index d7e684032c..292845d4e4 100755
--- a/tests/lavf-regression.sh
+++ b/tests/lavf-regression.sh
@@ -14,15 +14,15 @@ eval do_$test=y
do_lavf()
{
file=${outfile}lavf.$1
- do_ffmpeg $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $DEC_OPTS -ar 44100 -f s16le -i $pcm_src $ENC_OPTS -t 1 -qscale 10 $2
- do_ffmpeg_crc $file $DEC_OPTS -i $target_path/$file $3
+ do_avconv $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $DEC_OPTS -ar 44100 -f s16le -i $pcm_src $ENC_OPTS -b:a 64k -t 1 -qscale:v 10 $2
+ do_avconv_crc $file $DEC_OPTS -i $target_path/$file $3
}
do_streamed_images()
{
file=${outfile}${1}pipe.$1
- do_ffmpeg $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src -f image2pipe $ENC_OPTS -t 1 -qscale 10
- do_ffmpeg_crc $file $DEC_OPTS -f image2pipe -i $target_path/$file
+ do_avconv $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src -f image2pipe $ENC_OPTS -t 1 -qscale 10
+ do_avconv_crc $file $DEC_OPTS -f image2pipe -i $target_path/$file
}
do_image_formats()
@@ -30,45 +30,48 @@ do_image_formats()
outfile="$datadir/images/$1/"
mkdir -p "$outfile"
file=${outfile}%02d.$1
- run_ffmpeg $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $2 $ENC_OPTS $3 -t 0.5 -y -qscale 10 $target_path/$file
+ run_avconv $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $2 $ENC_OPTS $3 -t 0.5 -y -qscale 10 $target_path/$file
do_md5sum ${outfile}02.$1
- do_ffmpeg_crc $file $DEC_OPTS $3 -i $target_path/$file
+ do_avconv_crc $file $DEC_OPTS $3 -i $target_path/$file
wc -c ${outfile}02.$1
}
do_audio_only()
{
file=${outfile}lavf.$1
- do_ffmpeg $file $DEC_OPTS $2 -ar 44100 -f s16le -i $pcm_src $ENC_OPTS -t 1 -qscale 10 $3
- do_ffmpeg_crc $file $DEC_OPTS $4 -i $target_path/$file
+ do_avconv $file $DEC_OPTS $2 -ar 44100 -f s16le -i $pcm_src $ENC_OPTS -t 1 -qscale 10 $3
+ do_avconv_crc $file $DEC_OPTS $4 -i $target_path/$file
}
if [ -n "$do_avi" ] ; then
-do_lavf avi
+do_lavf avi "-acodec mp2 -ab 64k"
fi
if [ -n "$do_asf" ] ; then
-do_lavf asf "-acodec mp2" "-r 25"
+do_lavf asf "-acodec mp2 -ab 64k" "-r 25"
fi
if [ -n "$do_rm" ] ; then
file=${outfile}lavf.rm
-do_ffmpeg $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $DEC_OPTS -ar 44100 -f s16le -i $pcm_src $ENC_OPTS -t 1 -qscale 10 -acodec ac3_fixed
+do_avconv $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $DEC_OPTS -ar 44100 -f s16le -i $pcm_src $ENC_OPTS -t 1 -qscale 10 -acodec ac3_fixed -ab 64k
# broken
-#do_ffmpeg_crc $file -i $target_path/$file
+#do_avconv_crc $file -i $target_path/$file
fi
if [ -n "$do_mpg" ] ; then
-do_lavf mpg
+do_lavf mpg "-ab 64k"
fi
if [ -n "$do_mxf" ] ; then
-do_lavf mxf "-ar 48000 -bf 2 -timecode_frame_start 264363"
-do_lavf mxf_d10 "-ar 48000 -ac 2 -r 25 -s 720x576 -vf pad=720:608:0:32 -vcodec mpeg2video -intra -flags +ildct+low_delay -dc 10 -flags2 +ivlc+non_linear_q -qscale 1 -ps 1 -qmin 1 -rc_max_vbv_use 1 -rc_min_vbv_use 1 -pix_fmt yuv422p -minrate 30000k -maxrate 30000k -b 30000k -bufsize 1200000 -top 1 -rc_init_occupancy 1200000 -qmax 12 -f mxf_d10"
+do_lavf mxf "-ar 48000 -bf 2 -timecode 02:56:14:13"
+fi
+
+if [ -n "$do_mxf_d10" ]; then
+do_lavf mxf_d10 "-ar 48000 -ac 2 -r 25 -s 720x576 -vf pad=720:608:0:32 -vcodec mpeg2video -g 0 -flags +ildct+low_delay -dc 10 -flags2 +ivlc+non_linear_q -qscale 1 -ps 1 -qmin 1 -rc_max_vbv_use 1 -rc_min_vbv_use 1 -pix_fmt yuv422p -minrate 30000k -maxrate 30000k -b 30000k -bufsize 1200000 -top 1 -rc_init_occupancy 1200000 -qmax 12 -f mxf_d10"
fi
if [ -n "$do_ts" ] ; then
-do_lavf ts
+do_lavf ts "-ab 64k"
fi
if [ -n "$do_swf" ] ; then
@@ -76,7 +79,7 @@ do_lavf swf -an
fi
if [ -n "$do_ffm" ] ; then
-do_lavf ffm
+do_lavf ffm "-ab 64k"
fi
if [ -n "$do_flv_fmt" ] ; then
@@ -84,7 +87,7 @@ do_lavf flv -an
fi
if [ -n "$do_mov" ] ; then
-do_lavf mov "-acodec pcm_alaw"
+do_lavf mov "-acodec pcm_alaw -vcodec mpeg4"
fi
if [ -n "$do_dv_fmt" ] ; then
@@ -96,19 +99,19 @@ do_lavf gxf "-ar 48000 -r 25 -s pal -ac 1"
fi
if [ -n "$do_nut" ] ; then
-do_lavf nut "-acodec mp2"
+do_lavf nut "-acodec mp2 -ab 64k"
fi
if [ -n "$do_mkv" ] ; then
-do_lavf mkv
+do_lavf mkv "-acodec mp2 -ab 64k -vcodec mpeg4"
fi
# streamed images
# mjpeg
#file=${outfile}lavf.mjpeg
-#do_ffmpeg $file -t 1 -qscale 10 -f image2 -vcodec pgmyuv -i $raw_src
-#do_ffmpeg_crc $file -i $target_path/$file
+#do_avconv $file -t 1 -qscale 10 -f image2 -vcodec pgmyuv -i $raw_src
+#do_avconv_crc $file -i $target_path/$file
if [ -n "$do_pbmpipe" ] ; then
do_streamed_images pbm
@@ -124,14 +127,14 @@ fi
if [ -n "$do_gif" ] ; then
file=${outfile}lavf.gif
-do_ffmpeg $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $ENC_OPTS -t 1 -qscale 10 -pix_fmt rgb24
-do_ffmpeg_crc $file $DEC_OPTS -i $target_path/$file -pix_fmt rgb24
+do_avconv $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $ENC_OPTS -t 1 -qscale 10 -pix_fmt rgb24
+do_avconv_crc $file $DEC_OPTS -i $target_path/$file -pix_fmt rgb24
fi
if [ -n "$do_yuv4mpeg" ] ; then
file=${outfile}lavf.y4m
-do_ffmpeg $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $ENC_OPTS -t 1 -qscale 10
-#do_ffmpeg_crc $file -i $target_path/$file
+do_avconv $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $ENC_OPTS -t 1 -qscale 10
+#do_avconv_crc $file -i $target_path/$file
fi
# image formats
@@ -224,9 +227,9 @@ conversions="yuv420p yuv422p yuv444p yuyv422 yuv410p yuv411p yuvj420p \
monob yuv440p yuvj440p"
for pix_fmt in $conversions ; do
file=${outfile}${pix_fmt}.yuv
- run_ffmpeg $DEC_OPTS -r 1 -t 1 -f image2 -vcodec pgmyuv -i $raw_src \
- $ENC_OPTS -f rawvideo -s 352x288 -pix_fmt $pix_fmt $target_path/$raw_dst
- do_ffmpeg $file $DEC_OPTS -f rawvideo -s 352x288 -pix_fmt $pix_fmt -i $target_path/$raw_dst \
+ run_avconv $DEC_OPTS -r 1 -f image2 -vcodec pgmyuv -i $raw_src \
+ $ENC_OPTS -f rawvideo -t 1 -s 352x288 -pix_fmt $pix_fmt $target_path/$raw_dst
+ do_avconv $file $DEC_OPTS -f rawvideo -s 352x288 -pix_fmt $pix_fmt -i $target_path/$raw_dst \
$ENC_OPTS -f rawvideo -s 352x288 -pix_fmt yuv444p
done
fi
diff --git a/tests/lavfi-regression.sh b/tests/lavfi-regression.sh
index 8942756697..74e53739ca 100755
--- a/tests/lavfi-regression.sh
+++ b/tests/lavfi-regression.sh
@@ -16,7 +16,7 @@ do_video_filter() {
filters=$2
shift 2
printf '%-20s' $label
- run_ffmpeg $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src \
+ run_avconv $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src \
$ENC_OPTS -vf "$filters" -vcodec rawvideo $* -f nut md5:
}
@@ -49,10 +49,10 @@ do_lavfi_pixfmts(){
out_fmts=${outfile}${1}_out_fmts
# exclude pixel formats which are not supported as input
- $ffmpeg -pix_fmts list 2>/dev/null | sed -ne '9,$p' | grep '^\..\.' | cut -d' ' -f2 | sort >$exclude_fmts
- $showfiltfmts scale | awk -F '[ \r]' '/^OUTPUT/{ print $3 }' | sort | comm -23 - $exclude_fmts >$out_fmts
+ $avconv -pix_fmts list 2>/dev/null | sed -ne '9,$p' | grep '^\..\.' | cut -d' ' -f2 | sort >$exclude_fmts
+ $showfiltfmts scale | awk -F '[ \r]' '/^OUTPUT/{ fmt=substr($3, 5); print fmt }' | sort | comm -23 - $exclude_fmts >$out_fmts
- pix_fmts=$($showfiltfmts $filter | awk -F '[ \r]' '/^INPUT/{ print $3 }' | sort | comm -12 - $out_fmts)
+ pix_fmts=$($showfiltfmts $filter $filter_args | awk -F '[ \r]' '/^INPUT/{ fmt=substr($3, 5); print fmt }' | sort | comm -12 - $out_fmts)
for pix_fmt in $pix_fmts; do
do_video_filter $pix_fmt "slicify=random,format=$pix_fmt,$filter=$filter_args" -pix_fmt $pix_fmt
done
@@ -70,7 +70,7 @@ do_lavfi_pixfmts "scale" "200:100"
do_lavfi_pixfmts "vflip" ""
if [ -n "$do_pixdesc" ]; then
- pix_fmts="$($ffmpeg -pix_fmts list 2>/dev/null | sed -ne '9,$p' | grep '^IO' | cut -d' ' -f2 | sort)"
+ pix_fmts="$($avconv -pix_fmts list 2>/dev/null | sed -ne '9,$p' | grep '^IO' | cut -d' ' -f2 | sort)"
for pix_fmt in $pix_fmts; do
do_video_filter $pix_fmt "slicify=random,format=$pix_fmt,pixdesctest" -pix_fmt $pix_fmt
done
diff --git a/tests/ref/acodec/ac3_fixed b/tests/ref/acodec/ac3_fixed
index ca8a082c75..dba2dfc5e7 100644
--- a/tests/ref/acodec/ac3_fixed
+++ b/tests/ref/acodec/ac3_fixed
@@ -1,2 +1,2 @@
-0f14801e166819dd4a58981aea36e08b *./tests/data/acodec/ac3.rm
+e7fa185030a56d9db8663ad9e38c6c94 *./tests/data/acodec/ac3.rm
98751 ./tests/data/acodec/ac3.rm
diff --git a/tests/ref/acodec/adpcm_ima_qt b/tests/ref/acodec/adpcm_ima_qt
index 6e4415660e..c1db43f1aa 100644
--- a/tests/ref/acodec/adpcm_ima_qt
+++ b/tests/ref/acodec/adpcm_ima_qt
@@ -1,4 +1,4 @@
-3c06fd2f7831e3e8735b936e23ca220c *./tests/data/acodec/adpcm_qt.aiff
+057d27978b35888776512e4e9669a63b *./tests/data/acodec/adpcm_qt.aiff
281252 ./tests/data/acodec/adpcm_qt.aiff
-9580492803ba1c1a3746367b24b751c8 *./tests/data/adpcm_ima_qt.acodec.out.wav
-stddev: 914.65 PSNR: 37.10 MAXDIFF:34026 bytes: 1058560/ 1058400
+169c40435c68d50112c9c61fc67e446d *./tests/data/adpcm_ima_qt.acodec.out.wav
+stddev: 918.61 PSNR: 37.07 MAXDIFF:34029 bytes: 1058560/ 1058400
diff --git a/tests/ref/acodec/adpcm_ima_wav b/tests/ref/acodec/adpcm_ima_wav
index 29f5836fd9..f83dbadad9 100644
--- a/tests/ref/acodec/adpcm_ima_wav
+++ b/tests/ref/acodec/adpcm_ima_wav
@@ -1,4 +1,4 @@
56b75c3a6dacedcf2ce7b0586aa33594 *./tests/data/acodec/adpcm_ima.wav
267324 ./tests/data/acodec/adpcm_ima.wav
-78a2af1c895792d0c221d127bdd48ece *./tests/data/adpcm_ima_wav.acodec.out.wav
+ddddfa47302da540abf19224202bef57 *./tests/data/adpcm_ima_wav.acodec.out.wav
stddev: 903.51 PSNR: 37.21 MAXDIFF:34026 bytes: 1061748/ 1058400
diff --git a/tests/ref/acodec/adpcm_ms b/tests/ref/acodec/adpcm_ms
index 65d2a6ca65..301bc80042 100644
--- a/tests/ref/acodec/adpcm_ms
+++ b/tests/ref/acodec/adpcm_ms
@@ -1,4 +1,4 @@
a407b87daeef5b25dfb6c5b3f519e9c1 *./tests/data/acodec/adpcm_ms.wav
268378 ./tests/data/acodec/adpcm_ms.wav
-7be370f937c51e8a967e6a3d08d5156a *./tests/data/adpcm_ms.acodec.out.wav
+22863fb278c4e0ebe9c34cb15db5dd6b *./tests/data/adpcm_ms.acodec.out.wav
stddev: 1050.01 PSNR: 35.91 MAXDIFF:29806 bytes: 1060576/ 1058400
diff --git a/tests/ref/acodec/adpcm_swf b/tests/ref/acodec/adpcm_swf
index 27a5da518c..5306dc464a 100644
--- a/tests/ref/acodec/adpcm_swf
+++ b/tests/ref/acodec/adpcm_swf
@@ -1,4 +1,4 @@
42d4639866ed4d692eaf126228a4fa2a *./tests/data/acodec/adpcm_swf.flv
269166 ./tests/data/acodec/adpcm_swf.flv
-628089745a7059ae4055c2515b6d668b *./tests/data/adpcm_swf.acodec.out.wav
+f7df69d3fe708303820f2a9d00140a5b *./tests/data/adpcm_swf.acodec.out.wav
stddev: 933.58 PSNR: 36.93 MAXDIFF:51119 bytes: 1064960/ 1058400
diff --git a/tests/ref/acodec/adpcm_yam b/tests/ref/acodec/adpcm_yam
index d7076e721c..0fd702954e 100644
--- a/tests/ref/acodec/adpcm_yam
+++ b/tests/ref/acodec/adpcm_yam
@@ -1,4 +1,4 @@
-2546d72df736b5ffa1557e8c9c9ef788 *./tests/data/acodec/adpcm_yam.wav
-266296 ./tests/data/acodec/adpcm_yam.wav
-c80c847a53a0fee17a88fa889ec34a4e *./tests/data/adpcm_yam.acodec.out.wav
+006f8dc92eb4f7bab82eded314ca1124 *./tests/data/acodec/adpcm_yam.wav
+266298 ./tests/data/acodec/adpcm_yam.wav
+c36a9d5a1e0ad57fbe9665a31373b7c1 *./tests/data/adpcm_yam.acodec.out.wav
stddev: 1247.60 PSNR: 34.41 MAXDIFF:39895 bytes: 1064960/ 1058400
diff --git a/tests/ref/acodec/alac b/tests/ref/acodec/alac
index 1f4b264b87..f03ce893d8 100644
--- a/tests/ref/acodec/alac
+++ b/tests/ref/acodec/alac
@@ -1,4 +1,4 @@
-c68f649777ab8e7c9a0f1f221451d3ad *./tests/data/acodec/alac.m4a
+b25bcc7ec3f5c19cdfc01a6bbd32edb8 *./tests/data/acodec/alac.m4a
389386 ./tests/data/acodec/alac.m4a
-95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/alac.acodec.out.wav
+64151e4bcc2b717aa5a8454d424d6a1f *./tests/data/alac.acodec.out.wav
stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400
diff --git a/tests/ref/acodec/aref b/tests/ref/acodec/aref
index 8e6773be3b..cd89a632e6 100644
--- a/tests/ref/acodec/aref
+++ b/tests/ref/acodec/aref
@@ -1,2 +1,2 @@
-95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/acodec.ref.wav
-1058444 ./tests/data/acodec.ref.wav
+64151e4bcc2b717aa5a8454d424d6a1f *./tests/data/acodec.ref.wav
+1058446 ./tests/data/acodec.ref.wav
diff --git a/tests/ref/acodec/flac b/tests/ref/acodec/flac
index e9d7cfc0a8..992a4e387b 100644
--- a/tests/ref/acodec/flac
+++ b/tests/ref/acodec/flac
@@ -1,4 +1,4 @@
151eef9097f944726968bec48649f00a *./tests/data/acodec/flac.flac
361582 ./tests/data/acodec/flac.flac
-95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/flac.acodec.out.wav
+64151e4bcc2b717aa5a8454d424d6a1f *./tests/data/flac.acodec.out.wav
stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400
diff --git a/tests/ref/acodec/g723_1 b/tests/ref/acodec/g723_1
new file mode 100644
index 0000000000..57b80dd258
--- /dev/null
+++ b/tests/ref/acodec/g723_1
@@ -0,0 +1,4 @@
+5815887898457847a7717fbe60d9cfb6 *./tests/data/acodec/g723_1.tco
+4800 ./tests/data/acodec/g723_1.tco
+5d706e32b8e8fa991f2b1a309ea5e917 *./tests/data/g723_1.acodec.out.wav
+stddev: 8507.20 PSNR: 17.73 MAXDIFF:26473 bytes: 96000/ 1058400
diff --git a/tests/ref/acodec/g726 b/tests/ref/acodec/g726
index d2dbe5048c..c519ac297e 100644
--- a/tests/ref/acodec/g726
+++ b/tests/ref/acodec/g726
@@ -1,4 +1,4 @@
-fd090ddf05cc3401cc75c4a5ace1d05a *./tests/data/acodec/g726.wav
-24052 ./tests/data/acodec/g726.wav
-74abea06027375111eeac1b2f8c7d3af *./tests/data/g726.acodec.out.wav
-stddev: 8554.55 PSNR: 17.69 MAXDIFF:29353 bytes: 95984/ 1058400
+331fcf91f4483b508059d0933af97987 *./tests/data/acodec/g726.wav
+24054 ./tests/data/acodec/g726.wav
+fac563ba7947d8fc42b4af048707c145 *./tests/data/g726.acodec.out.wav
+stddev: 8553.69 PSNR: 17.69 MAXDIFF:29353 bytes: 95984/ 1058400
diff --git a/tests/ref/acodec/mp2 b/tests/ref/acodec/mp2
index df21be2bd7..3be6c58fb1 100644
--- a/tests/ref/acodec/mp2
+++ b/tests/ref/acodec/mp2
@@ -1,5 +1,5 @@
f6eb0a205350bbd7fb1028a01c7ae8aa *./tests/data/acodec/mp2.mp2
96130 ./tests/data/acodec/mp2.mp2
-74c7b6b15a001add199619fafe4059a1 *./tests/data/mp2.acodec.out.wav
+5a669ca7321adc6ab66a3eade4035909 *./tests/data/mp2.acodec.out.wav
stddev: 9315.99 PSNR: 16.94 MAXDIFF:65388 bytes: 1059840/ 1058400
stddev: 4384.33 PSNR: 23.49 MAXDIFF:52631 bytes: 1057916/ 1058400
diff --git a/tests/ref/acodec/pcm b/tests/ref/acodec/pcm
index 033f8bc8c6..696efe1663 100644
--- a/tests/ref/acodec/pcm
+++ b/tests/ref/acodec/pcm
@@ -1,72 +1,72 @@
-89f5b8dd97e0dddbe59af0d44fd229f3 *./tests/data/acodec/pcm_alaw.wav
-529256 ./tests/data/acodec/pcm_alaw.wav
-0568b0b9a72e31559e150e7e09d301cd *./tests/data/pcm.acodec.out.wav
+ede2da07839a00c255a43129922f2c7b *./tests/data/acodec/pcm_alaw.wav
+529258 ./tests/data/acodec/pcm_alaw.wav
+f323f7551ffad91de8613f44dcb198b6 *./tests/data/pcm.acodec.out.wav
stddev: 101.67 PSNR: 56.19 MAXDIFF: 515 bytes: 1058400/ 1058400
-f443a8eeb1647ec1eeb8370c939e52d4 *./tests/data/acodec/pcm_mulaw.wav
-529256 ./tests/data/acodec/pcm_mulaw.wav
-1c3eeaa8814ebd4916780dff80ed6dc5 *./tests/data/pcm.acodec.out.wav
+0c2a55850fb46ad5385a69b15b271f10 *./tests/data/acodec/pcm_mulaw.wav
+529258 ./tests/data/acodec/pcm_mulaw.wav
+7ae8c3fc804bd574006fd547fe28980c *./tests/data/pcm.acodec.out.wav
stddev: 103.38 PSNR: 56.04 MAXDIFF: 644 bytes: 1058400/ 1058400
-b7936d7170e0efefb379349d81aed360 *./tests/data/acodec/pcm_s8.mov
+760f85fb9f4e8aba326fb44ae84c9507 *./tests/data/acodec/pcm_s8.mov
530837 ./tests/data/acodec/pcm_s8.mov
-652edf30f35ad89bf27bcc9d2f9c7b53 *./tests/data/pcm.acodec.out.wav
+651d4eb8d98dfcdda96ae6c43d8f156b *./tests/data/pcm.acodec.out.wav
stddev: 147.89 PSNR: 52.93 MAXDIFF: 255 bytes: 1058400/ 1058400
-98cadb3502dbdc99e6e077c28b1a036c *./tests/data/acodec/pcm_u8.wav
-529244 ./tests/data/acodec/pcm_u8.wav
-652edf30f35ad89bf27bcc9d2f9c7b53 *./tests/data/pcm.acodec.out.wav
+70fecbae732f81143a560c7315eda49a *./tests/data/acodec/pcm_u8.wav
+529246 ./tests/data/acodec/pcm_u8.wav
+651d4eb8d98dfcdda96ae6c43d8f156b *./tests/data/pcm.acodec.out.wav
stddev: 147.89 PSNR: 52.93 MAXDIFF: 255 bytes: 1058400/ 1058400
-c42b9c04305455250366c84e17c1023f *./tests/data/acodec/pcm_s16be.mov
+a4e18d1ca9ef5b8132a84d43625ddc47 *./tests/data/acodec/pcm_s16be.mov
1060037 ./tests/data/acodec/pcm_s16be.mov
-95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.acodec.out.wav
+64151e4bcc2b717aa5a8454d424d6a1f *./tests/data/pcm.acodec.out.wav
stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400
-95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/acodec/pcm_s16le.wav
-1058444 ./tests/data/acodec/pcm_s16le.wav
-95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.acodec.out.wav
+64151e4bcc2b717aa5a8454d424d6a1f *./tests/data/acodec/pcm_s16le.wav
+1058446 ./tests/data/acodec/pcm_s16le.wav
+64151e4bcc2b717aa5a8454d424d6a1f *./tests/data/pcm.acodec.out.wav
stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400
af717ca95eaca310772eb1238c745d1b *./tests/data/acodec/pcm_s16be.mkv
1060638 ./tests/data/acodec/pcm_s16be.mkv
-95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.acodec.out.wav
+64151e4bcc2b717aa5a8454d424d6a1f *./tests/data/pcm.acodec.out.wav
stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400
c4f51bf32fad2f7af8ea5beedb56168b *./tests/data/acodec/pcm_s16le.mkv
1060638 ./tests/data/acodec/pcm_s16le.mkv
-95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.acodec.out.wav
+64151e4bcc2b717aa5a8454d424d6a1f *./tests/data/pcm.acodec.out.wav
stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400
-07ffe7ffb78f3648b6524debdde5aec1 *./tests/data/acodec/pcm_s24be.mov
+971d2d2633e41a0326fe2d04a2d0350f *./tests/data/acodec/pcm_s24be.mov
1589237 ./tests/data/acodec/pcm_s24be.mov
-95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.acodec.out.wav
+64151e4bcc2b717aa5a8454d424d6a1f *./tests/data/pcm.acodec.out.wav
stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400
a85380fb79b0d4fff38e24ac1e34bb94 *./tests/data/acodec/pcm_s24le.wav
1587668 ./tests/data/acodec/pcm_s24le.wav
-95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.acodec.out.wav
+64151e4bcc2b717aa5a8454d424d6a1f *./tests/data/pcm.acodec.out.wav
stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400
-d7792f0343cd66fda8b50b569e2bcc48 *./tests/data/acodec/pcm_s32be.mov
+fc4f4e3e195bbde037ed31021d229f12 *./tests/data/acodec/pcm_s32be.mov
2118437 ./tests/data/acodec/pcm_s32be.mov
-95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.acodec.out.wav
+64151e4bcc2b717aa5a8454d424d6a1f *./tests/data/pcm.acodec.out.wav
stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400
da6ed80f4f40f0082577dea80827e014 *./tests/data/acodec/pcm_s32le.wav
2116868 ./tests/data/acodec/pcm_s32le.wav
-95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.acodec.out.wav
+64151e4bcc2b717aa5a8454d424d6a1f *./tests/data/pcm.acodec.out.wav
stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400
118ff3dc83c62ce9ce669eef57e55bb2 *./tests/data/acodec/pcm_f32be.au
2116824 ./tests/data/acodec/pcm_f32be.au
-95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.acodec.out.wav
+64151e4bcc2b717aa5a8454d424d6a1f *./tests/data/pcm.acodec.out.wav
stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400
46f44f86a18984a832206ab9e29a79f2 *./tests/data/acodec/pcm_f32le.wav
2116880 ./tests/data/acodec/pcm_f32le.wav
-95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.acodec.out.wav
+64151e4bcc2b717aa5a8454d424d6a1f *./tests/data/pcm.acodec.out.wav
stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400
8112296b1ed94f72f20d04b1a54850a7 *./tests/data/acodec/pcm_f64be.au
4233624 ./tests/data/acodec/pcm_f64be.au
-95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.acodec.out.wav
+64151e4bcc2b717aa5a8454d424d6a1f *./tests/data/pcm.acodec.out.wav
stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400
ba17c6d1a270e1333e981f239bf7eb45 *./tests/data/acodec/pcm_f64le.wav
4233680 ./tests/data/acodec/pcm_f64le.wav
-95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.acodec.out.wav
+64151e4bcc2b717aa5a8454d424d6a1f *./tests/data/pcm.acodec.out.wav
stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400
-8c74234928ed425b1171211a89f67ead *./tests/data/acodec/pcm_zork.wav
-529256 ./tests/data/acodec/pcm_zork.wav
-864c8c866ac25642c29a13b122c70709 *./tests/data/pcm.acodec.out.wav
+ebd38ed390ebdefe0bdf00d21bf12c6b *./tests/data/acodec/pcm_zork.wav
+529258 ./tests/data/acodec/pcm_zork.wav
+7b02646acdd063650bb3ebc444543ace *./tests/data/pcm.acodec.out.wav
stddev: 633.11 PSNR: 40.30 MAXDIFF:32768 bytes: 1058400/ 1058400
-8168a5c1343553ef027541830f2cb879 *./tests/data/acodec/pcm_s24daud.302
+1b75d5198ae789ab3c48f7024e08f4a9 *./tests/data/acodec/pcm_s24daud.302
10368730 ./tests/data/acodec/pcm_s24daud.302
-f552afadfdfcd6348a07095da6382de5 *./tests/data/pcm.acodec.out.wav
-stddev: 9416.28 PSNR: 16.85 MAXDIFF:42744 bytes: 6911796/ 1058400
+4708f86529c594e29404603c64bb208c *./tests/data/pcm.acodec.out.wav
+stddev: 8967.92 PSNR: 17.28 MAXDIFF:42548 bytes: 6911796/ 1058400
diff --git a/tests/ref/fate/aasc b/tests/ref/fate/aasc
index 7ec02ba575..07b326983d 100644
--- a/tests/ref/fate/aasc
+++ b/tests/ref/fate/aasc
@@ -21,3 +21,4 @@
0, 72000, 168000, 0x646fa087
0, 75600, 168000, 0x404450a2
0, 79200, 168000, 0x5214c456
+0, 82800, 168000, 0xe573025c
diff --git a/tests/ref/fate/cdgraphics b/tests/ref/fate/cdgraphics
index 0f9e74eec8..6391b00348 100644
--- a/tests/ref/fate/cdgraphics
+++ b/tests/ref/fate/cdgraphics
@@ -35,265 +35,266 @@
0, 10200, 194400, 0xd015dba1
0, 10500, 194400, 0x6a39f18b
0, 10800, 194400, 0x7b8cf983
-0, 11100, 194400, 0x07a20f7c
-0, 11400, 194400, 0xa63e2962
+0, 11100, 194400, 0x7b8cf983
+0, 11400, 194400, 0x07a20f7c
0, 11700, 194400, 0xa63e2962
-0, 12000, 194400, 0x2dd54447
-0, 12300, 194400, 0x90735e2d
+0, 12000, 194400, 0xa63e2962
+0, 12300, 194400, 0x2dd54447
0, 12600, 194400, 0x90735e2d
-0, 12900, 194400, 0x90d98506
-0, 13200, 194400, 0xe5b08ffb
+0, 12900, 194400, 0x90735e2d
+0, 13200, 194400, 0x90d98506
0, 13500, 194400, 0xe5b08ffb
-0, 13800, 194400, 0x7a0d95f5
-0, 14100, 194400, 0xff6bacde
+0, 13800, 194400, 0xe5b08ffb
+0, 14100, 194400, 0x7a0d95f5
0, 14400, 194400, 0xff6bacde
-0, 14700, 194400, 0xd998c2c8
-0, 15000, 194400, 0x3d1ddfab
+0, 14700, 194400, 0xff6bacde
+0, 15000, 194400, 0xd998c2c8
0, 15300, 194400, 0x3d1ddfab
-0, 15600, 194400, 0x817de4a6
-0, 15900, 194400, 0xfa3ef694
+0, 15600, 194400, 0x3d1ddfab
+0, 15900, 194400, 0x817de4a6
0, 16200, 194400, 0xfa3ef694
-0, 16500, 194400, 0x0b5bfb8f
-0, 16800, 194400, 0x00f62376
+0, 16500, 194400, 0xfa3ef694
+0, 16800, 194400, 0x0b5bfb8f
0, 17100, 194400, 0x00f62376
-0, 17400, 194400, 0x2f6b2d6c
-0, 17700, 194400, 0x40cb4752
+0, 17400, 194400, 0x00f62376
+0, 17700, 194400, 0x2f6b2d6c
0, 18000, 194400, 0x40cb4752
-0, 18300, 194400, 0xd8456435
-0, 18600, 194400, 0x459f6a2f
+0, 18300, 194400, 0x40cb4752
+0, 18600, 194400, 0xd8456435
0, 18900, 194400, 0x459f6a2f
-0, 19200, 194400, 0x9b678910
-0, 19500, 194400, 0x8791a1f7
+0, 19200, 194400, 0x459f6a2f
+0, 19500, 194400, 0x9b678910
0, 19800, 194400, 0x8791a1f7
-0, 20100, 194400, 0xdb4ac5d3
-0, 20400, 194400, 0xb223c8d0
+0, 20100, 194400, 0x8791a1f7
+0, 20400, 194400, 0xdb4ac5d3
0, 20700, 194400, 0xb223c8d0
-0, 21000, 194400, 0x4a9ce7b1
-0, 21300, 194400, 0x187eeaae
+0, 21000, 194400, 0xb223c8d0
+0, 21300, 194400, 0x4a9ce7b1
0, 21600, 194400, 0x187eeaae
-0, 21900, 194400, 0xc712f8a0
-0, 22200, 194400, 0x549c00a7
+0, 21900, 194400, 0x187eeaae
+0, 22200, 194400, 0xc712f8a0
0, 22500, 194400, 0x549c00a7
-0, 22800, 194400, 0x4d991295
-0, 23100, 194400, 0xc41b2681
+0, 22800, 194400, 0x549c00a7
+0, 23100, 194400, 0x4d991295
0, 23400, 194400, 0xc41b2681
-0, 23700, 194400, 0xed5a3077
-0, 24000, 194400, 0x85ad4463
+0, 23700, 194400, 0xc41b2681
+0, 24000, 194400, 0xed5a3077
0, 24300, 194400, 0x85ad4463
-0, 24600, 194400, 0xb98f4760
-0, 24900, 194400, 0x87ef5e49
+0, 24600, 194400, 0x85ad4463
+0, 24900, 194400, 0xb98f4760
0, 25200, 194400, 0x87ef5e49
-0, 25500, 194400, 0x830a6146
-0, 25800, 194400, 0xe33a792e
+0, 25500, 194400, 0x87ef5e49
+0, 25800, 194400, 0x830a6146
0, 26100, 194400, 0xe33a792e
-0, 26400, 194400, 0x83517a2d
-0, 26700, 194400, 0xa97e9314
+0, 26400, 194400, 0xe33a792e
+0, 26700, 194400, 0x83517a2d
0, 27000, 194400, 0xa97e9314
-0, 27300, 194400, 0x39059611
-0, 27600, 194400, 0xbf4eb9ed
+0, 27300, 194400, 0xa97e9314
+0, 27600, 194400, 0x39059611
0, 27900, 194400, 0xbf4eb9ed
-0, 28200, 194400, 0xe5afc4e2
-0, 28500, 194400, 0x35d4cdd9
+0, 28200, 194400, 0xbf4eb9ed
+0, 28500, 194400, 0xe5afc4e2
0, 28800, 194400, 0x35d4cdd9
-0, 29100, 194400, 0xb376e1c5
-0, 29400, 194400, 0x6128e3c3
+0, 29100, 194400, 0x35d4cdd9
+0, 29400, 194400, 0xb376e1c5
0, 29700, 194400, 0x6128e3c3
-0, 30000, 194400, 0x30b7f7af
-0, 30300, 194400, 0xf1effaac
+0, 30000, 194400, 0x6128e3c3
+0, 30300, 194400, 0x30b7f7af
0, 30600, 194400, 0xf1effaac
-0, 30900, 194400, 0x483914a1
-0, 31200, 194400, 0xbd48199c
+0, 30900, 194400, 0xf1effaac
+0, 31200, 194400, 0x483914a1
0, 31500, 194400, 0xbd48199c
-0, 31800, 194400, 0x382f2d88
-0, 32100, 194400, 0x5a573085
+0, 31800, 194400, 0xbd48199c
+0, 32100, 194400, 0x382f2d88
0, 32400, 194400, 0x5a573085
-0, 32700, 194400, 0x89733580
-0, 33000, 194400, 0xd1325a5b
+0, 32700, 194400, 0x5a573085
+0, 33000, 194400, 0x89733580
0, 33300, 194400, 0xd1325a5b
-0, 33600, 194400, 0x655b6253
-0, 33900, 194400, 0x55146352
+0, 33600, 194400, 0xd1325a5b
+0, 33900, 194400, 0x655b6253
0, 34200, 194400, 0x55146352
-0, 34500, 194400, 0xda527c39
-0, 34800, 194400, 0xb0cd7e37
+0, 34500, 194400, 0x55146352
+0, 34800, 194400, 0xda527c39
0, 35100, 194400, 0xb0cd7e37
-0, 35400, 194400, 0x25e7991c
-0, 35700, 194400, 0x5c22a411
+0, 35400, 194400, 0xb0cd7e37
+0, 35700, 194400, 0x25e7991c
0, 36000, 194400, 0x5c22a411
-0, 36300, 194400, 0x1e2abdf7
-0, 36600, 194400, 0x8308bff5
+0, 36300, 194400, 0x5c22a411
+0, 36600, 194400, 0x1e2abdf7
0, 36900, 194400, 0x8308bff5
-0, 37200, 194400, 0xfdbfd6de
-0, 37500, 194400, 0xd4d4d9db
+0, 37200, 194400, 0x8308bff5
+0, 37500, 194400, 0xfdbfd6de
0, 37800, 194400, 0xd4d4d9db
-0, 38100, 194400, 0xa449fbb9
-0, 38400, 194400, 0x3dcafdb7
+0, 38100, 194400, 0xd4d4d9db
+0, 38400, 194400, 0xa449fbb9
0, 38700, 194400, 0x3dcafdb7
-0, 39000, 194400, 0x6f1f01c2
-0, 39300, 194400, 0xf54a1da6
+0, 39000, 194400, 0x3dcafdb7
+0, 39300, 194400, 0x6f1f01c2
0, 39600, 194400, 0xf54a1da6
-0, 39900, 194400, 0x88d11fa4
-0, 40200, 194400, 0x59642d96
+0, 39900, 194400, 0xf54a1da6
+0, 40200, 194400, 0x88d11fa4
0, 40500, 194400, 0x59642d96
-0, 40800, 194400, 0x8ba44182
-0, 41100, 194400, 0x88f56360
+0, 40800, 194400, 0x59642d96
+0, 41100, 194400, 0x8ba44182
0, 41400, 194400, 0x88f56360
-0, 41700, 194400, 0xfb246d56
-0, 42000, 194400, 0xad128043
+0, 41700, 194400, 0x88f56360
+0, 42000, 194400, 0xfb246d56
0, 42300, 194400, 0xad128043
-0, 42600, 194400, 0x3a4f8a39
-0, 42900, 194400, 0x563d9d26
+0, 42600, 194400, 0xad128043
+0, 42900, 194400, 0x3a4f8a39
0, 43200, 194400, 0x563d9d26
-0, 43500, 194400, 0x6ff8a320
-0, 43800, 194400, 0xcdb9b70c
+0, 43500, 194400, 0x563d9d26
+0, 43800, 194400, 0x6ff8a320
0, 44100, 194400, 0xcdb9b70c
-0, 44400, 194400, 0x99c2bd06
-0, 44700, 194400, 0x4b47cef4
+0, 44400, 194400, 0xcdb9b70c
+0, 44700, 194400, 0x99c2bd06
0, 45000, 194400, 0x4b47cef4
-0, 45300, 194400, 0x10b9dce6
-0, 45600, 194400, 0xdd39f1d1
+0, 45300, 194400, 0x4b47cef4
+0, 45600, 194400, 0x10b9dce6
0, 45900, 194400, 0xdd39f1d1
-0, 46200, 194400, 0xbcf104cd
-0, 46500, 194400, 0x85ec17ba
+0, 46200, 194400, 0xdd39f1d1
+0, 46500, 194400, 0xbcf104cd
0, 46800, 194400, 0x85ec17ba
-0, 47100, 194400, 0x069219b8
-0, 47400, 194400, 0x84dd3899
+0, 47100, 194400, 0x85ec17ba
+0, 47400, 194400, 0x069219b8
0, 47700, 194400, 0x84dd3899
-0, 48000, 194400, 0xacca4190
-0, 48300, 194400, 0xcf5b5d74
+0, 48000, 194400, 0x84dd3899
+0, 48300, 194400, 0xacca4190
0, 48600, 194400, 0xcf5b5d74
-0, 48900, 194400, 0x4b8c626f
-0, 49200, 194400, 0xf0817958
+0, 48900, 194400, 0xcf5b5d74
+0, 49200, 194400, 0x4b8c626f
0, 49500, 194400, 0xf0817958
-0, 49800, 194400, 0xc0887e53
-0, 50100, 194400, 0x42e6854c
+0, 49800, 194400, 0xf0817958
+0, 50100, 194400, 0xc0887e53
0, 50400, 194400, 0x42e6854c
-0, 50700, 194400, 0x036c9140
-0, 51000, 194400, 0x0f21a62b
+0, 50700, 194400, 0x42e6854c
+0, 51000, 194400, 0x036c9140
0, 51300, 194400, 0x0f21a62b
-0, 51600, 194400, 0xcdaeaa27
-0, 51900, 194400, 0xe425bc15
+0, 51600, 194400, 0x0f21a62b
+0, 51900, 194400, 0xcdaeaa27
0, 52200, 194400, 0xe425bc15
-0, 52500, 194400, 0x8e18c20f
-0, 52800, 194400, 0x767cd5fb
+0, 52500, 194400, 0xe425bc15
+0, 52800, 194400, 0x8e18c20f
0, 53100, 194400, 0x767cd5fb
-0, 53400, 194400, 0x554ae6ea
-0, 53700, 194400, 0xeac1f9d7
+0, 53400, 194400, 0x767cd5fb
+0, 53700, 194400, 0x554ae6ea
0, 54000, 194400, 0xeac1f9d7
-0, 54300, 194400, 0x0b32fed2
-0, 54600, 194400, 0xe30c19c6
+0, 54300, 194400, 0xeac1f9d7
+0, 54600, 194400, 0x0b32fed2
0, 54900, 194400, 0xe30c19c6
-0, 55200, 194400, 0x6a8a23bc
-0, 55500, 194400, 0x26bf36a9
+0, 55200, 194400, 0xe30c19c6
+0, 55500, 194400, 0x6a8a23bc
0, 55800, 194400, 0x26bf36a9
-0, 56100, 194400, 0x1e4f3fa0
-0, 56400, 194400, 0x231f5986
+0, 56100, 194400, 0x26bf36a9
+0, 56400, 194400, 0x1e4f3fa0
0, 56700, 194400, 0x231f5986
-0, 57000, 194400, 0xf557756a
-0, 57300, 194400, 0x6bce805f
+0, 57000, 194400, 0x231f5986
+0, 57300, 194400, 0xf557756a
0, 57600, 194400, 0x6bce805f
-0, 57900, 194400, 0xcd80924d
-0, 58200, 194400, 0x65dc9f40
+0, 57900, 194400, 0x6bce805f
+0, 58200, 194400, 0xcd80924d
0, 58500, 194400, 0x65dc9f40
-0, 58800, 194400, 0x2ab7af30
-0, 59100, 194400, 0xd43cb728
+0, 58800, 194400, 0x65dc9f40
+0, 59100, 194400, 0x2ab7af30
0, 59400, 194400, 0xd43cb728
-0, 59700, 194400, 0x05d9c916
-0, 60000, 194400, 0x43cad10e
+0, 59700, 194400, 0xd43cb728
+0, 60000, 194400, 0x05d9c916
0, 60300, 194400, 0x43cad10e
-0, 60600, 194400, 0x06b5e0fe
-0, 60900, 194400, 0xa142f0ee
+0, 60600, 194400, 0x43cad10e
+0, 60900, 194400, 0x06b5e0fe
0, 61200, 194400, 0xa142f0ee
-0, 61500, 194400, 0xed7f03ea
-0, 61800, 194400, 0xf26019d4
+0, 61500, 194400, 0xa142f0ee
+0, 61800, 194400, 0xed7f03ea
0, 62100, 194400, 0xf26019d4
-0, 62400, 194400, 0x3b7f29c4
-0, 62700, 194400, 0x30282ebf
+0, 62400, 194400, 0xf26019d4
+0, 62700, 194400, 0x3b7f29c4
0, 63000, 194400, 0x30282ebf
-0, 63300, 194400, 0xaeff4aa3
-0, 63600, 194400, 0x1d355697
+0, 63300, 194400, 0x30282ebf
+0, 63600, 194400, 0xaeff4aa3
0, 63900, 194400, 0x1d355697
-0, 64200, 194400, 0x2ead6f7e
-0, 64500, 194400, 0xf1b67776
+0, 64200, 194400, 0x1d355697
+0, 64500, 194400, 0x2ead6f7e
0, 64800, 194400, 0xf1b67776
-0, 65100, 194400, 0x93b38b62
-0, 65400, 194400, 0x9469905d
+0, 65100, 194400, 0xf1b67776
+0, 65400, 194400, 0x93b38b62
0, 65700, 194400, 0x9469905d
-0, 66000, 194400, 0x27bf9756
-0, 66300, 194400, 0xd016a548
+0, 66000, 194400, 0x9469905d
+0, 66300, 194400, 0x27bf9756
0, 66600, 194400, 0xd016a548
-0, 66900, 194400, 0x6889b835
-0, 67200, 194400, 0x6a05be2f
+0, 66900, 194400, 0xd016a548
+0, 67200, 194400, 0x6889b835
0, 67500, 194400, 0x6a05be2f
-0, 67800, 194400, 0xe0a1ce1f
-0, 68100, 194400, 0x8fdbd617
+0, 67800, 194400, 0x6a05be2f
+0, 68100, 194400, 0xe0a1ce1f
0, 68400, 194400, 0x8fdbd617
-0, 68700, 194400, 0xd68fe805
-0, 69000, 194400, 0x0d1dfbf1
+0, 68700, 194400, 0x8fdbd617
+0, 69000, 194400, 0xd68fe805
0, 69300, 194400, 0x0d1dfbf1
-0, 69600, 194400, 0x0fe70bf0
-0, 69900, 194400, 0x0a8f13e8
+0, 69600, 194400, 0x0d1dfbf1
+0, 69900, 194400, 0x0fe70bf0
0, 70200, 194400, 0x0a8f13e8
-0, 70500, 194400, 0x0ca42bd0
-0, 70800, 194400, 0x6f3838c3
+0, 70500, 194400, 0x0a8f13e8
+0, 70800, 194400, 0x0ca42bd0
0, 71100, 194400, 0x6f3838c3
-0, 71400, 194400, 0x045448b3
-0, 71700, 194400, 0x764349b2
+0, 71400, 194400, 0x6f3838c3
+0, 71700, 194400, 0x045448b3
0, 72000, 194400, 0x764349b2
-0, 72300, 194400, 0xed1651aa
-0, 72600, 194400, 0xbb376398
+0, 72300, 194400, 0x764349b2
+0, 72600, 194400, 0xed1651aa
0, 72900, 194400, 0xbb376398
-0, 73200, 194400, 0xd0d5718a
-0, 73500, 194400, 0xcd977e7d
+0, 73200, 194400, 0xbb376398
+0, 73500, 194400, 0xd0d5718a
0, 73800, 194400, 0xcd977e7d
-0, 74100, 194400, 0x8cb39665
-0, 74400, 194400, 0xb935b04b
+0, 74100, 194400, 0xcd977e7d
+0, 74400, 194400, 0x8cb39665
0, 74700, 194400, 0xb935b04b
-0, 75000, 194400, 0x0292be3d
-0, 75300, 194400, 0x4f21c833
+0, 75000, 194400, 0xb935b04b
+0, 75300, 194400, 0x0292be3d
0, 75600, 194400, 0x4f21c833
-0, 75900, 194400, 0xa5c7d823
-0, 76200, 194400, 0xfb8ee01b
+0, 75900, 194400, 0x4f21c833
+0, 76200, 194400, 0xa5c7d823
0, 76500, 194400, 0xfb8ee01b
-0, 76800, 194400, 0xea53ee0d
-0, 77100, 194400, 0x803efcfe
+0, 76800, 194400, 0xfb8ee01b
+0, 77100, 194400, 0xea53ee0d
0, 77400, 194400, 0x803efcfe
-0, 77700, 194400, 0x2c0e0aff
-0, 78000, 194400, 0x3df318f1
+0, 77700, 194400, 0x803efcfe
+0, 78000, 194400, 0x2c0e0aff
0, 78300, 194400, 0x3df318f1
-0, 78600, 194400, 0xc4cb26e3
-0, 78900, 194400, 0x92a033d6
+0, 78600, 194400, 0x3df318f1
+0, 78900, 194400, 0xc4cb26e3
0, 79200, 194400, 0x92a033d6
-0, 79500, 194400, 0x1b2048c1
-0, 79800, 194400, 0x236858b1
+0, 79500, 194400, 0x92a033d6
+0, 79800, 194400, 0x1b2048c1
0, 80100, 194400, 0x236858b1
-0, 80400, 194400, 0x482f6d9c
-0, 80700, 194400, 0x9ee97891
+0, 80400, 194400, 0x236858b1
+0, 80700, 194400, 0x482f6d9c
0, 81000, 194400, 0x9ee97891
-0, 81300, 194400, 0xe0dc8683
-0, 81600, 194400, 0x461b9079
+0, 81300, 194400, 0x9ee97891
+0, 81600, 194400, 0xe0dc8683
0, 81900, 194400, 0x461b9079
-0, 82200, 194400, 0xd346a960
-0, 82500, 194400, 0xa384b554
+0, 82200, 194400, 0x461b9079
+0, 82500, 194400, 0xd346a960
0, 82800, 194400, 0xa384b554
-0, 83100, 194400, 0x3246cf3a
-0, 83400, 194400, 0xa53fe722
+0, 83100, 194400, 0xa384b554
+0, 83400, 194400, 0x3246cf3a
0, 83700, 194400, 0xa53fe722
-0, 84000, 194400, 0xe620fd0c
-0, 84300, 194400, 0xd6370414
+0, 84000, 194400, 0xa53fe722
+0, 84300, 194400, 0xe620fd0c
0, 84600, 194400, 0xd6370414
-0, 84900, 194400, 0xf57f1404
-0, 85200, 194400, 0x8c6420f7
+0, 84900, 194400, 0xd6370414
+0, 85200, 194400, 0xf57f1404
0, 85500, 194400, 0x8c6420f7
-0, 85800, 194400, 0xd4be3add
-0, 86100, 194400, 0xa8dc4ec9
+0, 85800, 194400, 0x8c6420f7
+0, 86100, 194400, 0xd4be3add
0, 86400, 194400, 0xa8dc4ec9
-0, 86700, 194400, 0xda1563b4
-0, 87000, 194400, 0xd51873a4
+0, 86700, 194400, 0xa8dc4ec9
+0, 87000, 194400, 0xda1563b4
0, 87300, 194400, 0xd51873a4
-0, 87600, 194400, 0x68588196
-0, 87900, 194400, 0x40d18e89
+0, 87600, 194400, 0xd51873a4
+0, 87900, 194400, 0x68588196
0, 88200, 194400, 0x40d18e89
-0, 88500, 194400, 0x1b75a275
-0, 88800, 194400, 0xedd1a572
+0, 88500, 194400, 0x40d18e89
+0, 88800, 194400, 0x1b75a275
0, 89100, 194400, 0xedd1a572
-0, 89400, 194400, 0x55daad6a
+0, 89400, 194400, 0xedd1a572
+0, 89700, 194400, 0x55daad6a
diff --git a/tests/ref/fate/cscd b/tests/ref/fate/cscd
index 8b89e80a10..e667984aaa 100644
--- a/tests/ref/fate/cscd
+++ b/tests/ref/fate/cscd
@@ -1,208 +1,208 @@
0, 0, 270000, 0xf90015d8
-0, 2865, 270000, 0xf90015d8
-0, 5729, 270000, 0xf90015d8
-0, 8594, 270000, 0xf90015d8
-0, 11459, 270000, 0xf90015d8
-0, 14324, 270000, 0xf90015d8
-0, 17188, 270000, 0xf90015d8
-0, 20053, 270000, 0xf90015d8
-0, 22918, 270000, 0xf90015d8
-0, 25782, 270000, 0xf90015d8
-0, 28647, 270000, 0xf90015d8
-0, 31512, 270000, 0xf90015d8
-0, 34377, 270000, 0xf90015d8
-0, 37241, 270000, 0xf90015d8
-0, 40106, 270000, 0xf90015d8
-0, 42971, 270000, 0xf90015d8
-0, 45836, 270000, 0xf90015d8
-0, 48700, 270000, 0xf90015d8
-0, 51565, 270000, 0xf90015d8
-0, 54430, 270000, 0xf90015d8
-0, 57294, 270000, 0xf90015d8
-0, 60159, 270000, 0xf90015d8
-0, 63024, 270000, 0xf90015d8
-0, 65889, 270000, 0xf90015d8
-0, 68753, 270000, 0xf90015d8
-0, 71618, 270000, 0xf90015d8
-0, 74483, 270000, 0xf90015d8
-0, 77347, 270000, 0xf90015d8
-0, 80212, 270000, 0xf90015d8
-0, 83077, 270000, 0xf90015d8
-0, 85942, 270000, 0xf90015d8
-0, 88806, 270000, 0xf90015d8
-0, 91671, 270000, 0xf90015d8
-0, 94536, 270000, 0xf90015d8
-0, 97401, 270000, 0xf90015d8
-0, 100265, 270000, 0xf90015d8
-0, 103130, 270000, 0xf90015d8
-0, 105995, 270000, 0xf90015d8
-0, 108859, 270000, 0xf90015d8
-0, 111724, 270000, 0x1f9c15d8
-0, 114589, 270000, 0x436f15d8
-0, 117454, 270000, 0xe90115d8
-0, 120318, 270000, 0xe90115d8
-0, 123183, 270000, 0x8ea215d8
-0, 126048, 270000, 0x424015d8
-0, 128912, 270000, 0x0ce315d8
-0, 131777, 270000, 0x14bc15d8
-0, 134642, 270000, 0x2a9215d8
-0, 137507, 270000, 0x233f15d8
-0, 140371, 270000, 0x764b15d8
-0, 143236, 270000, 0xf76115d8
-0, 146101, 270000, 0xbbe015d8
-0, 148966, 270000, 0x95af15d8
-0, 151830, 270000, 0x324815d8
-0, 154695, 270000, 0x311915d8
-0, 157560, 270000, 0x090ef191
-0, 160424, 270000, 0xd88974dc
-0, 163289, 270000, 0xfa7f58df
-0, 166154, 270000, 0x78f849c3
-0, 169019, 270000, 0xae174892
-0, 171883, 270000, 0x9d4e2332
-0, 174748, 270000, 0x874b09b4
-0, 177613, 270000, 0x4069fed6
-0, 180477, 270000, 0x4069fed6
-0, 183342, 270000, 0x4069fed6
-0, 186207, 270000, 0x4069fed6
-0, 189072, 270000, 0x4069fed6
-0, 191936, 270000, 0x4069fed6
-0, 194801, 270000, 0x4069fed6
-0, 197666, 270000, 0x4069fed6
-0, 200531, 270000, 0x4069fed6
-0, 203395, 270000, 0x4069fed6
-0, 206260, 270000, 0x4069fed6
-0, 209125, 270000, 0x773db046
-0, 211989, 270000, 0x773db046
-0, 214854, 270000, 0x773db046
-0, 217719, 270000, 0x773db046
-0, 220584, 270000, 0x773db046
-0, 223448, 270000, 0x773db046
-0, 226313, 270000, 0x773db046
-0, 229178, 270000, 0x773db046
-0, 232042, 270000, 0x773db046
-0, 234907, 270000, 0x773db046
-0, 237772, 270000, 0x773db046
-0, 240637, 270000, 0x773db046
-0, 243501, 270000, 0x773db046
-0, 246366, 270000, 0x773db046
-0, 249231, 270000, 0x773db046
-0, 252095, 270000, 0x773db046
-0, 254960, 270000, 0x773db046
-0, 257825, 270000, 0x17b9aec9
-0, 260690, 270000, 0x622fad4c
-0, 263554, 270000, 0xdaea3aef
-0, 266419, 270000, 0x61bb10e3
-0, 269284, 270000, 0xfc37ee0c
-0, 272149, 270000, 0x50dbd01e
-0, 275013, 270000, 0xcd66c27c
-0, 277878, 270000, 0xd13f1e4f
-0, 280743, 270000, 0xa4a2dbf5
-0, 283607, 270000, 0xf302c9ab
-0, 286472, 270000, 0x4479f7fe
-0, 289337, 270000, 0x1afe92c8
-0, 292202, 270000, 0x3007f4c3
-0, 295066, 270000, 0x5834c096
-0, 297931, 270000, 0x40109126
-0, 300796, 270000, 0x0a7b8882
-0, 303660, 270000, 0x15b8635d
-0, 306525, 270000, 0xeaa5598e
-0, 309390, 270000, 0x0b7b5489
-0, 312255, 270000, 0x0b7b5489
-0, 315119, 270000, 0x0b7b5489
-0, 317984, 270000, 0x0b7b5489
-0, 320849, 270000, 0x8f0e6eaa
-0, 323714, 270000, 0xc46fc0f2
-0, 326578, 270000, 0xadd7e605
-0, 329443, 270000, 0x9d23a056
-0, 332308, 270000, 0x365afa63
-0, 335172, 270000, 0x6ac3bda2
-0, 338037, 270000, 0x14f5daf2
-0, 340902, 270000, 0x4b3afb6a
-0, 343767, 270000, 0x1a3302e3
-0, 346631, 270000, 0x1a3302e3
-0, 349496, 270000, 0x1a3302e3
-0, 352361, 270000, 0x1a3302e3
-0, 355225, 270000, 0xc15526e2
-0, 358090, 270000, 0x3dd73006
-0, 360955, 270000, 0x60abb5bc
-0, 363820, 270000, 0xb960c27c
-0, 366684, 270000, 0x8fa4c01c
-0, 369549, 270000, 0x8fa4c01c
-0, 372414, 270000, 0x8fa4c01c
-0, 375279, 270000, 0xb20dcc38
-0, 378143, 270000, 0x03c6ad3c
-0, 381008, 270000, 0xe550b194
-0, 383873, 270000, 0xe550b194
-0, 386737, 270000, 0xe550b194
-0, 389602, 270000, 0xe550b194
-0, 392467, 270000, 0xe550b194
-0, 395332, 270000, 0xe550b194
-0, 398196, 270000, 0xe550b194
-0, 401061, 270000, 0xe550b194
-0, 403926, 270000, 0xe550b194
-0, 406790, 270000, 0xe550b194
-0, 409655, 270000, 0xe550b194
-0, 412520, 270000, 0xe550b194
-0, 415385, 270000, 0xe550b194
-0, 418249, 270000, 0xe550b194
-0, 421114, 270000, 0x4550a014
-0, 423979, 270000, 0xaf639da8
-0, 426844, 270000, 0xe4229da8
-0, 429708, 270000, 0x315d9da8
-0, 432573, 270000, 0x7e899da8
-0, 435438, 270000, 0x99b9a8a0
-0, 438302, 270000, 0x4588ac2a
-0, 441167, 270000, 0x1e79ae6e
-0, 444032, 270000, 0xa003cb14
-0, 446897, 270000, 0x03ef1bb8
-0, 449761, 270000, 0x3b3f30fc
-0, 452626, 270000, 0x4dad3525
-0, 455491, 270000, 0x5b600c12
-0, 458355, 270000, 0x75a1fab3
-0, 461220, 270000, 0xc9f7d9ad
-0, 464085, 270000, 0x9eaec58d
-0, 466950, 270000, 0xb91bc3e8
-0, 469814, 270000, 0x77bdbbfb
-0, 472679, 270000, 0x77bdbbfb
-0, 475544, 270000, 0x77bdbbfb
-0, 478408, 270000, 0x77bdbbfb
-0, 481273, 270000, 0x77bdbbfb
-0, 484138, 270000, 0x77bdbbfb
-0, 487003, 270000, 0x3d54eac2
-0, 489867, 270000, 0x3d54eac2
-0, 492732, 270000, 0x3d54eac2
-0, 495597, 270000, 0x3d54eac2
-0, 498462, 270000, 0x3d54eac2
-0, 501326, 270000, 0x3d54eac2
-0, 504191, 270000, 0x3d54eac2
-0, 507056, 270000, 0x3d54eac2
-0, 509920, 270000, 0x3d54eac2
-0, 512785, 270000, 0x3d54eac2
-0, 515650, 270000, 0x3d54eac2
-0, 518515, 270000, 0x3d54eac2
-0, 521379, 270000, 0x3d54eac2
-0, 524244, 270000, 0x3d54eac2
-0, 527109, 270000, 0x3d54eac2
-0, 529973, 270000, 0x3d54eac2
-0, 532838, 270000, 0x3d54eac2
-0, 535703, 270000, 0x3d54eac2
-0, 538568, 270000, 0x3d54eac2
-0, 541432, 270000, 0x5f3609ba
-0, 544297, 270000, 0x80921b0c
-0, 547162, 270000, 0x80921b0c
-0, 550027, 270000, 0x80921b0c
-0, 552891, 270000, 0x80921b0c
-0, 555756, 270000, 0x80921b0c
-0, 558621, 270000, 0x80921b0c
-0, 561485, 270000, 0x80921b0c
-0, 564350, 270000, 0x80921b0c
-0, 567215, 270000, 0x80921b0c
-0, 570080, 270000, 0x80921b0c
-0, 572944, 270000, 0x80921b0c
-0, 575809, 270000, 0x80921b0c
-0, 578674, 270000, 0x80921b0c
-0, 581538, 270000, 0x80921b0c
-0, 584403, 270000, 0x80921b0c
-0, 587268, 270000, 0x80921b0c
-0, 590133, 270000, 0xf0e626a8
-0, 592997, 270000, 0xf0e626a8
+0, 450, 270000, 0xf90015d8
+0, 900, 270000, 0xf90015d8
+0, 1350, 270000, 0xf90015d8
+0, 1800, 270000, 0xf90015d8
+0, 2250, 270000, 0xf90015d8
+0, 2700, 270000, 0xf90015d8
+0, 3150, 270000, 0xf90015d8
+0, 3600, 270000, 0xf90015d8
+0, 4050, 270000, 0xf90015d8
+0, 4500, 270000, 0xf90015d8
+0, 4950, 270000, 0xf90015d8
+0, 5400, 270000, 0xf90015d8
+0, 5850, 270000, 0xf90015d8
+0, 6300, 270000, 0xf90015d8
+0, 6750, 270000, 0xf90015d8
+0, 7200, 270000, 0xf90015d8
+0, 7650, 270000, 0xf90015d8
+0, 8100, 270000, 0xf90015d8
+0, 8550, 270000, 0xf90015d8
+0, 9000, 270000, 0xf90015d8
+0, 9450, 270000, 0xf90015d8
+0, 9900, 270000, 0xf90015d8
+0, 10350, 270000, 0xf90015d8
+0, 10800, 270000, 0xf90015d8
+0, 11250, 270000, 0xf90015d8
+0, 11700, 270000, 0xf90015d8
+0, 12150, 270000, 0xf90015d8
+0, 12600, 270000, 0xf90015d8
+0, 13050, 270000, 0xf90015d8
+0, 13500, 270000, 0xf90015d8
+0, 13950, 270000, 0xf90015d8
+0, 14400, 270000, 0xf90015d8
+0, 14850, 270000, 0xf90015d8
+0, 15300, 270000, 0xf90015d8
+0, 15750, 270000, 0xf90015d8
+0, 16200, 270000, 0xf90015d8
+0, 16650, 270000, 0xf90015d8
+0, 17100, 270000, 0xf90015d8
+0, 17550, 270000, 0x1f9c15d8
+0, 18000, 270000, 0x436f15d8
+0, 18450, 270000, 0xe90115d8
+0, 18900, 270000, 0xe90115d8
+0, 19350, 270000, 0x8ea215d8
+0, 19800, 270000, 0x424015d8
+0, 20250, 270000, 0x0ce315d8
+0, 20700, 270000, 0x14bc15d8
+0, 21150, 270000, 0x2a9215d8
+0, 21600, 270000, 0x233f15d8
+0, 22050, 270000, 0x764b15d8
+0, 22500, 270000, 0xf76115d8
+0, 22950, 270000, 0xbbe015d8
+0, 23400, 270000, 0x95af15d8
+0, 23850, 270000, 0x324815d8
+0, 24300, 270000, 0x311915d8
+0, 24750, 270000, 0x090ef191
+0, 25200, 270000, 0xd88974dc
+0, 25650, 270000, 0xfa7f58df
+0, 26100, 270000, 0x78f849c3
+0, 26550, 270000, 0xae174892
+0, 27000, 270000, 0x9d4e2332
+0, 27450, 270000, 0x874b09b4
+0, 27900, 270000, 0x4069fed6
+0, 28350, 270000, 0x4069fed6
+0, 28800, 270000, 0x4069fed6
+0, 29250, 270000, 0x4069fed6
+0, 29700, 270000, 0x4069fed6
+0, 30150, 270000, 0x4069fed6
+0, 30600, 270000, 0x4069fed6
+0, 31050, 270000, 0x4069fed6
+0, 31500, 270000, 0x4069fed6
+0, 31950, 270000, 0x4069fed6
+0, 32400, 270000, 0x4069fed6
+0, 32850, 270000, 0x773db046
+0, 33300, 270000, 0x773db046
+0, 33750, 270000, 0x773db046
+0, 34200, 270000, 0x773db046
+0, 34650, 270000, 0x773db046
+0, 35100, 270000, 0x773db046
+0, 35550, 270000, 0x773db046
+0, 36000, 270000, 0x773db046
+0, 36450, 270000, 0x773db046
+0, 36900, 270000, 0x773db046
+0, 37350, 270000, 0x773db046
+0, 37800, 270000, 0x773db046
+0, 38250, 270000, 0x773db046
+0, 38700, 270000, 0x773db046
+0, 39150, 270000, 0x773db046
+0, 39600, 270000, 0x773db046
+0, 40050, 270000, 0x773db046
+0, 40500, 270000, 0x17b9aec9
+0, 40950, 270000, 0x622fad4c
+0, 41400, 270000, 0xdaea3aef
+0, 41850, 270000, 0x61bb10e3
+0, 42300, 270000, 0xfc37ee0c
+0, 42750, 270000, 0x50dbd01e
+0, 43200, 270000, 0xcd66c27c
+0, 43650, 270000, 0xd13f1e4f
+0, 44100, 270000, 0xa4a2dbf5
+0, 44550, 270000, 0xf302c9ab
+0, 45000, 270000, 0x4479f7fe
+0, 45450, 270000, 0x1afe92c8
+0, 45900, 270000, 0x3007f4c3
+0, 46350, 270000, 0x5834c096
+0, 46800, 270000, 0x40109126
+0, 47250, 270000, 0x0a7b8882
+0, 47700, 270000, 0x15b8635d
+0, 48150, 270000, 0xeaa5598e
+0, 48600, 270000, 0x0b7b5489
+0, 49050, 270000, 0x0b7b5489
+0, 49500, 270000, 0x0b7b5489
+0, 49950, 270000, 0x0b7b5489
+0, 50400, 270000, 0x8f0e6eaa
+0, 50850, 270000, 0xc46fc0f2
+0, 51300, 270000, 0xadd7e605
+0, 51750, 270000, 0x9d23a056
+0, 52200, 270000, 0x365afa63
+0, 52650, 270000, 0x6ac3bda2
+0, 53100, 270000, 0x14f5daf2
+0, 53550, 270000, 0x4b3afb6a
+0, 54000, 270000, 0x1a3302e3
+0, 54450, 270000, 0x1a3302e3
+0, 54900, 270000, 0x1a3302e3
+0, 55350, 270000, 0x1a3302e3
+0, 55800, 270000, 0xc15526e2
+0, 56250, 270000, 0x3dd73006
+0, 56700, 270000, 0x60abb5bc
+0, 57150, 270000, 0xb960c27c
+0, 57600, 270000, 0x8fa4c01c
+0, 58050, 270000, 0x8fa4c01c
+0, 58500, 270000, 0x8fa4c01c
+0, 58950, 270000, 0xb20dcc38
+0, 59400, 270000, 0x03c6ad3c
+0, 59850, 270000, 0xe550b194
+0, 60300, 270000, 0xe550b194
+0, 60750, 270000, 0xe550b194
+0, 61200, 270000, 0xe550b194
+0, 61650, 270000, 0xe550b194
+0, 62100, 270000, 0xe550b194
+0, 62550, 270000, 0xe550b194
+0, 63000, 270000, 0xe550b194
+0, 63450, 270000, 0xe550b194
+0, 63900, 270000, 0xe550b194
+0, 64350, 270000, 0xe550b194
+0, 64800, 270000, 0xe550b194
+0, 65250, 270000, 0xe550b194
+0, 65700, 270000, 0xe550b194
+0, 66150, 270000, 0x4550a014
+0, 66600, 270000, 0xaf639da8
+0, 67050, 270000, 0xe4229da8
+0, 67500, 270000, 0x315d9da8
+0, 67950, 270000, 0x7e899da8
+0, 68400, 270000, 0x99b9a8a0
+0, 68850, 270000, 0x4588ac2a
+0, 69300, 270000, 0x1e79ae6e
+0, 69750, 270000, 0xa003cb14
+0, 70200, 270000, 0x03ef1bb8
+0, 70650, 270000, 0x3b3f30fc
+0, 71100, 270000, 0x4dad3525
+0, 71550, 270000, 0x5b600c12
+0, 72000, 270000, 0x75a1fab3
+0, 72450, 270000, 0xc9f7d9ad
+0, 72900, 270000, 0x9eaec58d
+0, 73350, 270000, 0xb91bc3e8
+0, 73800, 270000, 0x77bdbbfb
+0, 74250, 270000, 0x77bdbbfb
+0, 74700, 270000, 0x77bdbbfb
+0, 75150, 270000, 0x77bdbbfb
+0, 75600, 270000, 0x77bdbbfb
+0, 76050, 270000, 0x77bdbbfb
+0, 76500, 270000, 0x3d54eac2
+0, 76950, 270000, 0x3d54eac2
+0, 77400, 270000, 0x3d54eac2
+0, 77850, 270000, 0x3d54eac2
+0, 78300, 270000, 0x3d54eac2
+0, 78750, 270000, 0x3d54eac2
+0, 79200, 270000, 0x3d54eac2
+0, 79650, 270000, 0x3d54eac2
+0, 80100, 270000, 0x3d54eac2
+0, 80550, 270000, 0x3d54eac2
+0, 81000, 270000, 0x3d54eac2
+0, 81450, 270000, 0x3d54eac2
+0, 81900, 270000, 0x3d54eac2
+0, 82350, 270000, 0x3d54eac2
+0, 82800, 270000, 0x3d54eac2
+0, 83250, 270000, 0x3d54eac2
+0, 83700, 270000, 0x3d54eac2
+0, 84150, 270000, 0x3d54eac2
+0, 84600, 270000, 0x3d54eac2
+0, 85050, 270000, 0x5f3609ba
+0, 85500, 270000, 0x80921b0c
+0, 85950, 270000, 0x80921b0c
+0, 86400, 270000, 0x80921b0c
+0, 86850, 270000, 0x80921b0c
+0, 87300, 270000, 0x80921b0c
+0, 87750, 270000, 0x80921b0c
+0, 88200, 270000, 0x80921b0c
+0, 88650, 270000, 0x80921b0c
+0, 89100, 270000, 0x80921b0c
+0, 89550, 270000, 0x80921b0c
+0, 90000, 270000, 0x80921b0c
+0, 90450, 270000, 0x80921b0c
+0, 90900, 270000, 0x80921b0c
+0, 91350, 270000, 0x80921b0c
+0, 91800, 270000, 0x80921b0c
+0, 92250, 270000, 0x80921b0c
+0, 92700, 270000, 0xf0e626a8
+0, 93150, 270000, 0xf0e626a8
diff --git a/tests/ref/fate/cvid b/tests/ref/fate/cvid
index d7ebe1193d..9a85275c69 100644
--- a/tests/ref/fate/cvid
+++ b/tests/ref/fate/cvid
@@ -76,3 +76,4 @@
0, 562500, 112400, 0xe4394f1f
0, 570000, 112400, 0x8ca8649f
0, 577500, 112400, 0x804d44eb
+0, 585000, 112400, 0x3864488b
diff --git a/tests/ref/fate/duck-dk3 b/tests/ref/fate/duck-dk3
index 08c0fd1909..9aad92beed 100644
--- a/tests/ref/fate/duck-dk3
+++ b/tests/ref/fate/duck-dk3
@@ -1 +1 @@
-62fbe4db4a49cb044f57f92cce9993c5
+bb952ae86c72d461aef7583685ec0a4d
diff --git a/tests/ref/fate/eval b/tests/ref/fate/eval
index fb7a925b77..88d7e17bee 100644
--- a/tests/ref/fate/eval
+++ b/tests/ref/fate/eval
@@ -16,8 +16,11 @@ Evaluating '+PI'
Evaluating '1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)'
'1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)' -> 12.700000
-Evaluating '80G/80Gi1k'
-'80G/80Gi1k' -> nan
+Evaluating '80G/80Gi'
+'80G/80Gi' -> 0.931323
+
+Evaluating '1k'
+'1k' -> 1000.000000
Evaluating '1Gi'
'1Gi' -> 1073741824.000000
@@ -130,5 +133,32 @@ Evaluating 'ceil(123.123)'
Evaluating 'ceil(-123.123)'
'ceil(-123.123)' -> -123.000000
+Evaluating 'sqrt(1764)'
+'sqrt(1764)' -> 42.000000
+
+Evaluating 'isnan(sqrt(-1))'
+'isnan(sqrt(-1))' -> 1.000000
+
+Evaluating 'not(1)'
+'not(1)' -> 0.000000
+
+Evaluating 'not(NAN)'
+'not(NAN)' -> 0.000000
+
+Evaluating 'not(0)'
+'not(0)' -> 1.000000
+
+Evaluating 'pow(0,1.23)'
+'pow(0,1.23)' -> 0.000000
+
+Evaluating 'pow(PI,1.23)'
+'pow(PI,1.23)' -> 4.087844
+
+Evaluating 'PI^1.23'
+'PI^1.23' -> 4.087844
+
+Evaluating 'pow(-1,1.23)'
+'pow(-1,1.23)' -> nan
+
12.700000 == 12.7
0.931323 == 0.931322575
diff --git a/tests/ref/fate/feeble-dxa b/tests/ref/fate/feeble-dxa
index 9013f99118..caea4c2e2a 100644
--- a/tests/ref/fate/feeble-dxa
+++ b/tests/ref/fate/feeble-dxa
@@ -62,4 +62,3 @@
0, 171000, 921600, 0x5639e670
1, 171429, 1000, 0xa491f3ef
1, 175510, 1000, 0x2c036e18
-1, 179592, 1000, 0x52d65e2a
diff --git a/tests/ref/fate/fifo b/tests/ref/fate/fifo
new file mode 100644
index 0000000000..18a5691fee
--- /dev/null
+++ b/tests/ref/fate/fifo
@@ -0,0 +1,27 @@
+-12: 1
+-11: 2
+-10: 3
+-9: 4
+-8: 5
+-7: 6
+-6: 7
+-5: 8
+-4: 9
+-3: 10
+-2: 11
+-1: 12
+0: 0
+1: 1
+2: 2
+3: 3
+4: 4
+5: 5
+6: 6
+7: 7
+8: 8
+9: 9
+10: 10
+11: 11
+12: 12
+
+0 1 2 3 4 5 6 7 8 9 10 11 12
diff --git a/tests/ref/fate/film-cvid-pcm-stereo-8bit b/tests/ref/fate/film-cvid-pcm-stereo-8bit
index 3566b0f85a..c8d573ca33 100644
--- a/tests/ref/fate/film-cvid-pcm-stereo-8bit
+++ b/tests/ref/fate/film-cvid-pcm-stereo-8bit
@@ -1,124 +1,124 @@
0, 0, 107520, 0xa6c9fdd2
1, 0, 88192, 0x23bb50ae
0, 3000, 107520, 0x61eb28c1
-0, 6000, 107520, 0x45e20af7
+0, 6000, 107520, 0x61eb28c1
0, 9000, 107520, 0x45e20af7
-0, 12000, 107520, 0x366970fc
+0, 12000, 107520, 0x45e20af7
0, 15000, 107520, 0x366970fc
-0, 18000, 107520, 0xa392bcb3
+0, 18000, 107520, 0x366970fc
0, 21000, 107520, 0xa392bcb3
-0, 24000, 107520, 0xcf7bac98
+0, 24000, 107520, 0xa392bcb3
0, 27000, 107520, 0xcf7bac98
-0, 30000, 107520, 0x222eba53
+0, 30000, 107520, 0xcf7bac98
0, 33000, 107520, 0x222eba53
-0, 36000, 107520, 0x74e255a1
+0, 36000, 107520, 0x222eba53
0, 39000, 107520, 0x74e255a1
-0, 42000, 107520, 0xc19eec6f
+0, 42000, 107520, 0x74e255a1
1, 44996, 44112, 0x79600f01
0, 45000, 107520, 0xc19eec6f
-0, 48000, 107520, 0xa3880681
+0, 48000, 107520, 0xc19eec6f
0, 51000, 107520, 0xa3880681
-0, 54000, 107520, 0x957878db
+0, 54000, 107520, 0xa3880681
0, 57000, 107520, 0x957878db
-0, 60000, 107520, 0x18340692
+0, 60000, 107520, 0x957878db
0, 63000, 107520, 0x18340692
-0, 66000, 107520, 0x9970f24d
+0, 66000, 107520, 0x18340692
1, 67502, 44096, 0x09dbf7aa
0, 69000, 107520, 0x9970f24d
-0, 72000, 107520, 0xf08618aa
+0, 72000, 107520, 0x9970f24d
0, 75000, 107520, 0xf08618aa
-0, 78000, 107520, 0xee7324f0
+0, 78000, 107520, 0xf08618aa
0, 81000, 107520, 0xee7324f0
-0, 84000, 107520, 0xe15025b3
+0, 84000, 107520, 0xee7324f0
0, 87000, 107520, 0xe15025b3
-0, 90000, 107520, 0x8afa312e
+0, 90000, 107520, 0xe15025b3
1, 90000, 44112, 0x18fed048
0, 93000, 107520, 0x8afa312e
-0, 96000, 107520, 0x717a7d0f
+0, 96000, 107520, 0x8afa312e
0, 99000, 107520, 0x717a7d0f
-0, 102000, 107520, 0x355c6e23
+0, 102000, 107520, 0x717a7d0f
0, 105000, 107520, 0x355c6e23
-0, 108000, 107520, 0x7015a50f
+0, 108000, 107520, 0x355c6e23
0, 111000, 107520, 0x7015a50f
1, 112506, 44112, 0x030d35ef
-0, 114000, 107520, 0xcdfc1a16
+0, 114000, 107520, 0x7015a50f
0, 117000, 107520, 0xcdfc1a16
-0, 120000, 107520, 0x38d929e7
+0, 120000, 107520, 0xcdfc1a16
0, 123000, 107520, 0x38d929e7
-0, 126000, 107520, 0x52913423
+0, 126000, 107520, 0x38d929e7
0, 129000, 107520, 0x52913423
-0, 132000, 107520, 0xe2c91c10
+0, 132000, 107520, 0x52913423
0, 135000, 107520, 0xe2c91c10
1, 135012, 44112, 0xc23154d5
-0, 138000, 107520, 0x85516e9c
+0, 138000, 107520, 0xe2c91c10
0, 141000, 107520, 0x85516e9c
-0, 144000, 107520, 0xd1626030
+0, 144000, 107520, 0x85516e9c
0, 147000, 107520, 0xd1626030
-0, 150000, 107520, 0xea7b16de
+0, 150000, 107520, 0xd1626030
0, 153000, 107520, 0xea7b16de
-0, 156000, 107520, 0xa33eaa0d
+0, 156000, 107520, 0xea7b16de
1, 157518, 44064, 0xe4713ee7
0, 159000, 107520, 0xa33eaa0d
-0, 162000, 107520, 0x8e3be6a6
+0, 162000, 107520, 0xa33eaa0d
0, 165000, 107520, 0x8e3be6a6
-0, 168000, 107520, 0x14147bd6
+0, 168000, 107520, 0x8e3be6a6
0, 171000, 107520, 0x14147bd6
-0, 174000, 107520, 0x07d54bec
+0, 174000, 107520, 0x14147bd6
0, 177000, 107520, 0x07d54bec
-0, 180000, 107520, 0xe287a0a7
+0, 180000, 107520, 0x07d54bec
1, 180000, 44112, 0xddc19d91
0, 183000, 107520, 0xe287a0a7
-0, 186000, 107520, 0xc023a14d
+0, 186000, 107520, 0xe287a0a7
0, 189000, 107520, 0xc023a14d
-0, 192000, 107520, 0x2437085d
+0, 192000, 107520, 0xc023a14d
0, 195000, 107520, 0x2437085d
-0, 198000, 107520, 0x63823918
+0, 198000, 107520, 0x2437085d
0, 201000, 107520, 0x63823918
1, 202506, 44112, 0x9591522d
-0, 204000, 107520, 0xbc17e198
+0, 204000, 107520, 0x63823918
0, 207000, 107520, 0xbc17e198
-0, 210000, 107520, 0x9d99bc81
+0, 210000, 107520, 0xbc17e198
0, 213000, 107520, 0x9d99bc81
-0, 216000, 107520, 0x7e4ec71e
+0, 216000, 107520, 0x9d99bc81
0, 219000, 107520, 0x7e4ec71e
-0, 222000, 107520, 0x55b98376
+0, 222000, 107520, 0x7e4ec71e
0, 225000, 107520, 0x55b98376
1, 225012, 44112, 0x90deb013
-0, 228000, 107520, 0x356d8e9e
+0, 228000, 107520, 0x55b98376
0, 231000, 107520, 0x356d8e9e
-0, 234000, 107520, 0xf77e8a61
+0, 234000, 107520, 0x356d8e9e
0, 237000, 107520, 0xf77e8a61
-0, 240000, 107520, 0x5ae7c8c7
+0, 240000, 107520, 0xf77e8a61
0, 243000, 107520, 0x5ae7c8c7
-0, 246000, 107520, 0x8acf9322
+0, 246000, 107520, 0x5ae7c8c7
1, 247518, 44064, 0x3842d420
0, 249000, 107520, 0x8acf9322
-0, 252000, 107520, 0x40a9177e
+0, 252000, 107520, 0x8acf9322
0, 255000, 107520, 0x40a9177e
-0, 258000, 107520, 0x3e0e4d8d
+0, 258000, 107520, 0x40a9177e
0, 261000, 107520, 0x3e0e4d8d
-0, 264000, 107520, 0xd268865b
+0, 264000, 107520, 0x3e0e4d8d
0, 267000, 107520, 0xd268865b
-0, 270000, 107520, 0x89a4efeb
+0, 270000, 107520, 0xd268865b
1, 270000, 44112, 0x99c8c3d9
0, 273000, 107520, 0x89a4efeb
-0, 276000, 107520, 0x70ca2478
+0, 276000, 107520, 0x89a4efeb
0, 279000, 107520, 0x70ca2478
-0, 282000, 107520, 0xcc9ec981
+0, 282000, 107520, 0x70ca2478
0, 285000, 107520, 0xcc9ec981
-0, 288000, 107520, 0xf0648459
+0, 288000, 107520, 0xcc9ec981
0, 291000, 107520, 0xf0648459
1, 292506, 44112, 0xffaf3824
-0, 294000, 107520, 0x7e4a4cca
+0, 294000, 107520, 0xf0648459
0, 297000, 107520, 0x7e4a4cca
-0, 300000, 107520, 0xb315dc65
+0, 300000, 107520, 0x7e4a4cca
0, 303000, 107520, 0xb315dc65
-0, 306000, 107520, 0x2aecc7b4
+0, 306000, 107520, 0xb315dc65
0, 309000, 107520, 0x2aecc7b4
-0, 312000, 107520, 0x81742f51
+0, 312000, 107520, 0x2aecc7b4
0, 315000, 107520, 0x81742f51
1, 315012, 44112, 0x3dbe1aef
-0, 318000, 107520, 0x3a1d7571
+0, 318000, 107520, 0x81742f51
0, 321000, 107520, 0x3a1d7571
0, 324000, 107520, 0x3a1d7571
0, 327000, 107520, 0x3a1d7571
@@ -133,53 +133,53 @@
0, 351000, 107520, 0x3a1d7571
0, 354000, 107520, 0x3a1d7571
0, 357000, 107520, 0x3a1d7571
-0, 360000, 107520, 0xe974733e
+0, 360000, 107520, 0x3a1d7571
1, 360000, 44112, 0x9e475274
0, 363000, 107520, 0xe974733e
-0, 366000, 107520, 0x999c6fbf
+0, 366000, 107520, 0xe974733e
0, 369000, 107520, 0x999c6fbf
-0, 372000, 107520, 0x26b56b6e
+0, 372000, 107520, 0x999c6fbf
0, 375000, 107520, 0x26b56b6e
-0, 378000, 107520, 0xc9f9647b
+0, 378000, 107520, 0x26b56b6e
0, 381000, 107520, 0xc9f9647b
1, 382506, 44112, 0x541f05d4
-0, 384000, 107520, 0x6d025d00
+0, 384000, 107520, 0xc9f9647b
0, 387000, 107520, 0x6d025d00
-0, 390000, 107520, 0xf9c056c1
+0, 390000, 107520, 0x6d025d00
0, 393000, 107520, 0xf9c056c1
-0, 396000, 107520, 0xa5cc4d0b
+0, 396000, 107520, 0xf9c056c1
0, 399000, 107520, 0xa5cc4d0b
-0, 402000, 107520, 0x1a4c4236
+0, 402000, 107520, 0xa5cc4d0b
0, 405000, 107520, 0x1a4c4236
1, 405012, 44112, 0x09e39025
-0, 408000, 107520, 0xa9d538b6
+0, 408000, 107520, 0x1a4c4236
0, 411000, 107520, 0xa9d538b6
-0, 414000, 107520, 0x14682d00
+0, 414000, 107520, 0xa9d538b6
0, 417000, 107520, 0x14682d00
-0, 420000, 107520, 0x6236204f
+0, 420000, 107520, 0x14682d00
0, 423000, 107520, 0x6236204f
-0, 426000, 107520, 0x303e14aa
+0, 426000, 107520, 0x6236204f
1, 427518, 44064, 0xdc111087
0, 429000, 107520, 0x303e14aa
-0, 432000, 107520, 0x943b0837
+0, 432000, 107520, 0x303e14aa
0, 435000, 107520, 0x943b0837
-0, 438000, 107520, 0xfce5fd07
+0, 438000, 107520, 0x943b0837
0, 441000, 107520, 0xfce5fd07
-0, 444000, 107520, 0xd993f193
+0, 444000, 107520, 0xfce5fd07
0, 447000, 107520, 0xd993f193
-0, 450000, 107520, 0x4d48e7b4
+0, 450000, 107520, 0xd993f193
1, 450000, 44112, 0xb8f86e48
0, 453000, 107520, 0x4d48e7b4
-0, 456000, 107520, 0x61ccdf83
+0, 456000, 107520, 0x4d48e7b4
0, 459000, 107520, 0x61ccdf83
-0, 462000, 107520, 0xfb4fd608
+0, 462000, 107520, 0x61ccdf83
0, 465000, 107520, 0xfb4fd608
-0, 468000, 107520, 0x5efdcdb3
+0, 468000, 107520, 0xfb4fd608
0, 471000, 107520, 0x5efdcdb3
1, 472506, 44112, 0xa1e0c75c
-0, 474000, 107520, 0xb03ec886
+0, 474000, 107520, 0x5efdcdb3
0, 477000, 107520, 0xb03ec886
-0, 480000, 107520, 0xf464c343
+0, 480000, 107520, 0xb03ec886
0, 483000, 107520, 0xf464c343
0, 486000, 107520, 0xf464c343
0, 489000, 107520, 0xf464c343
@@ -204,7 +204,7 @@
0, 540000, 107520, 0xf464c343
1, 540000, 44112, 0xe0ac619f
0, 543000, 107520, 0xf464c343
-0, 546000, 107520, 0xf2b2c712
+0, 546000, 107520, 0xf464c343
0, 549000, 107520, 0xf2b2c712
0, 552000, 107520, 0xf2b2c712
0, 555000, 107520, 0xf2b2c712
@@ -213,35 +213,36 @@
1, 562506, 44112, 0xb07aa65c
0, 564000, 107520, 0xf2b2c712
0, 567000, 107520, 0xf2b2c712
-0, 570000, 107520, 0xb95e6bc8
+0, 570000, 107520, 0xf2b2c712
0, 573000, 107520, 0xb95e6bc8
-0, 576000, 107520, 0x33feee37
+0, 576000, 107520, 0xb95e6bc8
0, 579000, 107520, 0x33feee37
-0, 582000, 107520, 0x36ee3cd5
+0, 582000, 107520, 0x33feee37
0, 585000, 107520, 0x36ee3cd5
1, 585012, 44112, 0x24610ff0
-0, 588000, 107520, 0x59096471
+0, 588000, 107520, 0x36ee3cd5
0, 591000, 107520, 0x59096471
-0, 594000, 107520, 0x53b470c6
+0, 594000, 107520, 0x59096471
0, 597000, 107520, 0x53b470c6
-0, 600000, 107520, 0xdb7c64ff
+0, 600000, 107520, 0x53b470c6
0, 603000, 107520, 0xdb7c64ff
-0, 606000, 107520, 0xe5a1596a
+0, 606000, 107520, 0xdb7c64ff
1, 607518, 44064, 0x00000000
0, 609000, 107520, 0xe5a1596a
-0, 612000, 107520, 0x8c8942eb
+0, 612000, 107520, 0xe5a1596a
0, 615000, 107520, 0x8c8942eb
-0, 618000, 107520, 0x5ecc379e
+0, 618000, 107520, 0x8c8942eb
0, 621000, 107520, 0x5ecc379e
-0, 624000, 107520, 0xea09432a
+0, 624000, 107520, 0x5ecc379e
0, 627000, 107520, 0xea09432a
-0, 630000, 107520, 0xe01e6b73
+0, 630000, 107520, 0xea09432a
1, 630000, 44112, 0x00000000
0, 633000, 107520, 0xe01e6b73
-0, 636000, 107520, 0x1d13bba8
+0, 636000, 107520, 0xe01e6b73
0, 639000, 107520, 0x1d13bba8
-0, 642000, 107520, 0x3a993a6c
+0, 642000, 107520, 0x1d13bba8
0, 645000, 107520, 0x3a993a6c
-0, 648000, 107520, 0x2ede041a
+0, 648000, 107520, 0x3a993a6c
0, 651000, 107520, 0x2ede041a
1, 652506, 8800, 0x00000000
+0, 654000, 107520, 0x2ede041a
diff --git a/tests/ref/fate/fraps-v5 b/tests/ref/fate/fraps-v5
index 3fe1c49329..05fa9da37b 100644
--- a/tests/ref/fate/fraps-v5
+++ b/tests/ref/fate/fraps-v5
@@ -56,3 +56,4 @@
0, 165000, 145152, 0x80448031
0, 168000, 145152, 0xe3b1fbf7
0, 171000, 145152, 0xa00395a4
+0, 174000, 145152, 0xdf3b4fce
diff --git a/tests/ref/fate/g722enc b/tests/ref/fate/g722enc
new file mode 100644
index 0000000000..c1094565b5
--- /dev/null
+++ b/tests/ref/fate/g722enc
@@ -0,0 +1 @@
+750269cc236541df28e15da5c7b0df7a
diff --git a/tests/ref/fate/g729-0 b/tests/ref/fate/g729-0
new file mode 100644
index 0000000000..36c6634fab
--- /dev/null
+++ b/tests/ref/fate/g729-0
@@ -0,0 +1,1000 @@
+0, 0, 160, 0xbb6d5aa0
+0, 900, 160, 0x91563d8d
+0, 1800, 160, 0x10a7535b
+0, 2700, 160, 0xa4f35594
+0, 3600, 160, 0x7f8e54e0
+0, 4500, 160, 0x85275000
+0, 5400, 160, 0x00734c7b
+0, 6300, 160, 0x8a2d544d
+0, 7200, 160, 0x97dc533c
+0, 8100, 160, 0xa7064ec4
+0, 9000, 160, 0xb7984a3c
+0, 9900, 160, 0x28334db6
+0, 10800, 160, 0x5838521f
+0, 11700, 160, 0x2337502c
+0, 12600, 160, 0x4a1e4599
+0, 13500, 160, 0x0d3858a8
+0, 14400, 160, 0xa0974b46
+0, 15300, 160, 0xc3254b93
+0, 16200, 160, 0x42b75231
+0, 17100, 160, 0x93634662
+0, 18000, 160, 0x11674fa1
+0, 18900, 160, 0xf2da5414
+0, 19800, 160, 0x97754dbc
+0, 20700, 160, 0x40a24d94
+0, 21600, 160, 0x26b34ebf
+0, 22500, 160, 0x7730542f
+0, 23400, 160, 0xb45254aa
+0, 24300, 160, 0xd8d752c3
+0, 25200, 160, 0x655c4a81
+0, 26100, 160, 0xa5da4f35
+0, 27000, 160, 0xd43551a1
+0, 27900, 160, 0x72a74e7d
+0, 28800, 160, 0xdb2150b3
+0, 29700, 160, 0x972852a1
+0, 30600, 160, 0xbae14c07
+0, 31500, 160, 0x23b54d57
+0, 32400, 160, 0x2d9650a5
+0, 33300, 160, 0xaf755107
+0, 34200, 160, 0xdb054f0e
+0, 35100, 160, 0x9f084cc0
+0, 36000, 160, 0x64ca5760
+0, 36900, 160, 0x3ea24be2
+0, 37800, 160, 0x93ea503b
+0, 38700, 160, 0xb6694afa
+0, 39600, 160, 0xf94c52e7
+0, 40500, 160, 0x2b7156b8
+0, 41400, 160, 0xbbdf414c
+0, 42300, 160, 0x10cd4ac8
+0, 43200, 160, 0x39885453
+0, 44100, 160, 0xa1505568
+0, 45000, 160, 0x86124ec1
+0, 45900, 160, 0xe2ab5489
+0, 46800, 160, 0x406254bc
+0, 47700, 160, 0x09044629
+0, 48600, 160, 0xb2ed5702
+0, 49500, 160, 0xd9ee5188
+0, 50400, 160, 0x59f7592a
+0, 51300, 160, 0x8f144c08
+0, 52200, 160, 0x90394e61
+0, 53100, 160, 0x79524df7
+0, 54000, 160, 0x58044674
+0, 54900, 160, 0x73b24d90
+0, 55800, 160, 0x80e257a1
+0, 56700, 160, 0xe8ff4caf
+0, 57600, 160, 0x1db84e3e
+0, 58500, 160, 0xd7db59d9
+0, 59400, 160, 0x43244c15
+0, 60300, 160, 0x1f63558f
+0, 61200, 160, 0xf0d851c6
+0, 62100, 160, 0x76484f3a
+0, 63000, 160, 0x5746551e
+0, 63900, 160, 0x83b54cd7
+0, 64800, 160, 0x97f550a1
+0, 65700, 160, 0x77c45340
+0, 66600, 160, 0xfd7b520a
+0, 67500, 160, 0x989a4e13
+0, 68400, 160, 0x9a8551c0
+0, 69300, 160, 0xa0cb4f93
+0, 70200, 160, 0xc568536f
+0, 71100, 160, 0x6fa74a95
+0, 72000, 160, 0xd550568b
+0, 72900, 160, 0xf88f4de5
+0, 73800, 160, 0x91285517
+0, 74700, 160, 0xdb675270
+0, 75600, 160, 0x606c53f9
+0, 76500, 160, 0x43f64601
+0, 77400, 160, 0x28b94b45
+0, 78300, 160, 0x7f2347f5
+0, 79200, 160, 0x84ba55db
+0, 80100, 160, 0x3ca3477c
+0, 81000, 160, 0x57d158ba
+0, 81900, 160, 0x2c3c506d
+0, 82800, 160, 0x59b34e5f
+0, 83700, 160, 0x014f530a
+0, 84600, 160, 0x877f4f76
+0, 85500, 160, 0x97a65c5f
+0, 86400, 160, 0xf643516d
+0, 87300, 160, 0x6ccc5242
+0, 88200, 160, 0x895450bd
+0, 89100, 160, 0xe246570e
+0, 90000, 160, 0xbb9f4a0c
+0, 90900, 160, 0x60e646fe
+0, 91800, 160, 0x546f515b
+0, 92700, 160, 0xc59254f0
+0, 93600, 160, 0xcad6551f
+0, 94500, 160, 0x14e14fac
+0, 95400, 160, 0x3cf94c52
+0, 96300, 160, 0x99b14f45
+0, 97200, 160, 0xfdb14dc7
+0, 98100, 160, 0x48f359e7
+0, 99000, 160, 0x186153e3
+0, 99900, 160, 0x047d4a78
+0, 100800, 160, 0x992f462b
+0, 101700, 160, 0x4a0e504d
+0, 102600, 160, 0x1f245275
+0, 103500, 160, 0x026959a9
+0, 104400, 160, 0x648846e7
+0, 105300, 160, 0xcac94cb3
+0, 106200, 160, 0x55e551a4
+0, 107100, 160, 0x767a5315
+0, 108000, 160, 0xbfde4d2b
+0, 108900, 160, 0x29bf4613
+0, 109800, 160, 0x8a8d5394
+0, 110700, 160, 0x36f94dae
+0, 111600, 160, 0x4cbf50ba
+0, 112500, 160, 0x9af44d8b
+0, 113400, 160, 0x6e8a519e
+0, 114300, 160, 0x496348b7
+0, 115200, 160, 0x95324eb2
+0, 116100, 160, 0x5bfe5118
+0, 117000, 160, 0xa1ff4c88
+0, 117900, 160, 0x86c2500a
+0, 118800, 160, 0xc53353c5
+0, 119700, 160, 0x062f52ee
+0, 120600, 160, 0x11cf522d
+0, 121500, 160, 0x054f5855
+0, 122400, 160, 0x8c4e44e9
+0, 123300, 160, 0x4d514fda
+0, 124200, 160, 0x5726568e
+0, 125100, 160, 0x281859ad
+0, 126000, 160, 0x3f3344f8
+0, 126900, 160, 0x2cbb3ee5
+0, 127800, 160, 0xa075551c
+0, 128700, 160, 0xafb25528
+0, 129600, 160, 0x9221478a
+0, 130500, 160, 0x6cb15634
+0, 131400, 160, 0xb5cf4523
+0, 132300, 160, 0x8a7a4f2c
+0, 133200, 160, 0x278e553d
+0, 134100, 160, 0x49054ad3
+0, 135000, 160, 0x5d7449bb
+0, 135900, 160, 0x67c346a0
+0, 136800, 160, 0x5d915bf8
+0, 137700, 160, 0x671355b2
+0, 138600, 160, 0xdfa84ee6
+0, 139500, 160, 0x4c3552d0
+0, 140400, 160, 0x63a1483c
+0, 141300, 160, 0x14c151ba
+0, 142200, 160, 0xf7434d78
+0, 143100, 160, 0x1c3652c9
+0, 144000, 160, 0x035b51da
+0, 144900, 160, 0x2bf6496b
+0, 145800, 160, 0x50a14f14
+0, 146700, 160, 0x518948f8
+0, 147600, 160, 0x7e784331
+0, 148500, 160, 0x73384dce
+0, 149400, 160, 0x11015066
+0, 150300, 160, 0xacc5525c
+0, 151200, 160, 0xf75a5431
+0, 152100, 160, 0xa78e4b8a
+0, 153000, 160, 0xd07955b0
+0, 153900, 160, 0x63164a03
+0, 154800, 160, 0x952f519e
+0, 155700, 160, 0xe5764f77
+0, 156600, 160, 0xa9255738
+0, 157500, 160, 0x65d64ce5
+0, 158400, 160, 0x8ab7507c
+0, 159300, 160, 0xf5265251
+0, 160200, 160, 0xa6a84d74
+0, 161100, 160, 0xc2594fee
+0, 162000, 160, 0xdfae5056
+0, 162900, 160, 0xa5a74c11
+0, 163800, 160, 0x5fdf4a21
+0, 164700, 160, 0x11014f8d
+0, 165600, 160, 0x08d0553f
+0, 166500, 160, 0x3036520e
+0, 167400, 160, 0xee3a464e
+0, 168300, 160, 0xbfd94949
+0, 169200, 160, 0x21625176
+0, 170100, 160, 0x6c714e8d
+0, 171000, 160, 0x055a4c05
+0, 171900, 160, 0xc7f35347
+0, 172800, 160, 0x82344b60
+0, 173700, 160, 0x99854ce4
+0, 174600, 160, 0x95504ec3
+0, 175500, 160, 0xe245502a
+0, 176400, 160, 0xb0e14a4c
+0, 177300, 160, 0x09835b86
+0, 178200, 160, 0xe9495220
+0, 179100, 160, 0xce9b514f
+0, 180000, 160, 0xbaf85695
+0, 180900, 160, 0x69aa3f1d
+0, 181800, 160, 0xd6a551b8
+0, 182700, 160, 0x4eb956e6
+0, 183600, 160, 0xdd6d4e58
+0, 184500, 160, 0xba1f4814
+0, 185400, 160, 0x4a604f48
+0, 186300, 160, 0xa8995890
+0, 187200, 160, 0x3a80616b
+0, 188100, 160, 0xfb796013
+0, 189000, 160, 0x8eba5c12
+0, 189900, 160, 0xd37859b9
+0, 190800, 160, 0x19a857c8
+0, 191700, 160, 0xec0e5a16
+0, 192600, 160, 0xd5335159
+0, 193500, 160, 0x560f4de7
+0, 194400, 160, 0x06d354c8
+0, 195300, 160, 0xdade5860
+0, 196200, 160, 0x093a512c
+0, 197100, 160, 0xb37b5098
+0, 198000, 160, 0x3eea537c
+0, 198900, 160, 0xf5c94f06
+0, 199800, 160, 0x552c4bb2
+0, 200700, 160, 0xea9a5a79
+0, 201600, 160, 0xd2645494
+0, 202500, 160, 0x5ba958ea
+0, 203400, 160, 0x54b559cf
+0, 204300, 160, 0x86bf5bba
+0, 205200, 160, 0xb89b6149
+0, 206100, 160, 0x1e825314
+0, 207000, 160, 0xf0d250cc
+0, 207900, 160, 0xc7ad53ba
+0, 208800, 160, 0x320c552f
+0, 209700, 160, 0xc62756f7
+0, 210600, 160, 0xa41351f7
+0, 211500, 160, 0x27ed4e78
+0, 212400, 160, 0x8d6047bc
+0, 213300, 160, 0xa45c48d0
+0, 214200, 160, 0x14da5400
+0, 215100, 160, 0x48514dd2
+0, 216000, 160, 0xec395318
+0, 216900, 160, 0xf3c85e4a
+0, 217800, 160, 0x657a63ed
+0, 218700, 160, 0xcc975c4d
+0, 219600, 160, 0x86125dd4
+0, 220500, 160, 0x6a3f6019
+0, 221400, 160, 0x84c05aeb
+0, 222300, 160, 0xe68561f7
+0, 223200, 160, 0x7ec763ae
+0, 224100, 160, 0x91bd5792
+0, 225000, 160, 0xb9365c8e
+0, 225900, 160, 0x42d7587a
+0, 226800, 160, 0x80a45453
+0, 227700, 160, 0x9ecf50c2
+0, 228600, 160, 0xc8de5173
+0, 229500, 160, 0x776952f7
+0, 230400, 160, 0x45f856c0
+0, 231300, 160, 0x729c4d73
+0, 232200, 160, 0xfd364a18
+0, 233100, 160, 0x709e587d
+0, 234000, 160, 0x288240e5
+0, 234900, 160, 0x16a6493f
+0, 235800, 160, 0x76db596f
+0, 236700, 160, 0x16c24a51
+0, 237600, 160, 0xc55b5a8f
+0, 238500, 160, 0x19024a2e
+0, 239400, 160, 0x16514d1b
+0, 240300, 160, 0x48bb5b82
+0, 241200, 160, 0x5a6e4d80
+0, 242100, 160, 0x6d404b0f
+0, 243000, 160, 0x57bc4e4a
+0, 243900, 160, 0xc10c5381
+0, 244800, 160, 0x34bd51d9
+0, 245700, 160, 0x5dcf52b7
+0, 246600, 160, 0xf61f57a7
+0, 247500, 160, 0x4e204934
+0, 248400, 160, 0xe18b4a3f
+0, 249300, 160, 0xb81256e3
+0, 250200, 160, 0x294047b2
+0, 251100, 160, 0x3ad559df
+0, 252000, 160, 0xd28d4d86
+0, 252900, 160, 0x67b75895
+0, 253800, 160, 0x191357b0
+0, 254700, 160, 0x8016556f
+0, 255600, 160, 0x62475c86
+0, 256500, 160, 0x0c975bc9
+0, 257400, 160, 0x901c5909
+0, 258300, 160, 0x9909567d
+0, 259200, 160, 0xce715b99
+0, 260100, 160, 0xae5062b1
+0, 261000, 160, 0x5bd056d6
+0, 261900, 160, 0xe3d3555a
+0, 262800, 160, 0xc4b1555c
+0, 263700, 160, 0x39c95649
+0, 264600, 160, 0x50145d11
+0, 265500, 160, 0xc0ba5307
+0, 266400, 160, 0x182455a3
+0, 267300, 160, 0x36c24e98
+0, 268200, 160, 0x1b5b52d0
+0, 269100, 160, 0xd38352d1
+0, 270000, 160, 0x6a1d5d2a
+0, 270900, 160, 0x50f05c44
+0, 271800, 160, 0xb2365dc1
+0, 272700, 160, 0x10825934
+0, 273600, 160, 0xcb4c61c2
+0, 274500, 160, 0x578252ab
+0, 275400, 160, 0xed99596c
+0, 276300, 160, 0xdfec6305
+0, 277200, 160, 0x97e2550a
+0, 278100, 160, 0xd60a56e1
+0, 279000, 160, 0xb6c4535e
+0, 279900, 160, 0x4d2e536c
+0, 280800, 160, 0xdef85cc7
+0, 281700, 160, 0xee985a98
+0, 282600, 160, 0x006a4cdb
+0, 283500, 160, 0xd06652ad
+0, 284400, 160, 0xeeee4ed6
+0, 285300, 160, 0xcb8b586d
+0, 286200, 160, 0x2ee4556e
+0, 287100, 160, 0x6d924c01
+0, 288000, 160, 0x7ff257cc
+0, 288900, 160, 0x67df5710
+0, 289800, 160, 0x0f704f29
+0, 290700, 160, 0x19dc53a7
+0, 291600, 160, 0xfbf44bc0
+0, 292500, 160, 0x640b5718
+0, 293400, 160, 0x2bfd4b91
+0, 294300, 160, 0xaae049bf
+0, 295200, 160, 0xca3154f6
+0, 296100, 160, 0x36064f2c
+0, 297000, 160, 0x28404919
+0, 297900, 160, 0x9c944fe3
+0, 298800, 160, 0xb4214c82
+0, 299700, 160, 0x442c514d
+0, 300600, 160, 0x44434ea5
+0, 301500, 160, 0x82a05aae
+0, 302400, 160, 0x4b86510d
+0, 303300, 160, 0x46844eab
+0, 304200, 160, 0xe5455deb
+0, 305100, 160, 0x60826550
+0, 306000, 160, 0x3c5a5448
+0, 306900, 160, 0x2db860c9
+0, 307800, 160, 0x4d845b78
+0, 308700, 160, 0x81dc5e23
+0, 309600, 160, 0x78c95932
+0, 310500, 160, 0xb5be57cd
+0, 311400, 160, 0x6fa45c65
+0, 312300, 160, 0x4e085e2a
+0, 313200, 160, 0x50ee530c
+0, 314100, 160, 0x2bb85587
+0, 315000, 160, 0x6d58614e
+0, 315900, 160, 0xcf4c5d69
+0, 316800, 160, 0x3cbf5ffb
+0, 317700, 160, 0x452157d3
+0, 318600, 160, 0x3cb55cd8
+0, 319500, 160, 0x2bba5735
+0, 320400, 160, 0x36a45670
+0, 321300, 160, 0x23b85b8a
+0, 322200, 160, 0x9a255457
+0, 323100, 160, 0x4e6956f3
+0, 324000, 160, 0xa0714edc
+0, 324900, 160, 0x7dee4a3d
+0, 325800, 160, 0x86404bc9
+0, 326700, 160, 0x358c50cd
+0, 327600, 160, 0x9eda47e8
+0, 328500, 160, 0x3cfe522e
+0, 329400, 160, 0xddb95758
+0, 330300, 160, 0x1a434a83
+0, 331200, 160, 0xa8a450bb
+0, 332100, 160, 0x44e7530e
+0, 333000, 160, 0x59b5555a
+0, 333900, 160, 0x65404db1
+0, 334800, 160, 0xcac15945
+0, 335700, 160, 0x38864f17
+0, 336600, 160, 0x61114f30
+0, 337500, 160, 0x195542d8
+0, 338400, 160, 0xacbb4c69
+0, 339300, 160, 0xd0da4ab9
+0, 340200, 160, 0x563d4eb6
+0, 341100, 160, 0xd0ce503c
+0, 342000, 160, 0x8b684e15
+0, 342900, 160, 0x711541d3
+0, 343800, 160, 0xb28b5b9b
+0, 344700, 160, 0x48b145e4
+0, 345600, 160, 0x908f5606
+0, 346500, 160, 0x22c74f02
+0, 347400, 160, 0x87274716
+0, 348300, 160, 0xaa2351e6
+0, 349200, 160, 0x2df5505a
+0, 350100, 160, 0x7999525c
+0, 351000, 160, 0x728a4b73
+0, 351900, 160, 0xa67447ff
+0, 352800, 160, 0x28884a20
+0, 353700, 160, 0x3ffa5840
+0, 354600, 160, 0xd6265047
+0, 355500, 160, 0x2f1553a8
+0, 356400, 160, 0xac0653ec
+0, 357300, 160, 0x35844368
+0, 358200, 160, 0x6e1553ba
+0, 359100, 160, 0xb62a4c88
+0, 360000, 160, 0x88a04ffc
+0, 360900, 160, 0x947e525e
+0, 361800, 160, 0x3dd24f98
+0, 362700, 160, 0x942e542e
+0, 363600, 160, 0xdb985211
+0, 364500, 160, 0x615a5022
+0, 365400, 160, 0x71c04569
+0, 366300, 160, 0xbbbe4f41
+0, 367200, 160, 0x62074e0b
+0, 368100, 160, 0x2c5d56c7
+0, 369000, 160, 0x34344c18
+0, 369900, 160, 0xc57d4c22
+0, 370800, 160, 0xb273560d
+0, 371700, 160, 0x7e985229
+0, 372600, 160, 0x2dd3542d
+0, 373500, 160, 0x39645000
+0, 374400, 160, 0x1b3f4d9e
+0, 375300, 160, 0x0bbf5ed2
+0, 376200, 160, 0xc81f5608
+0, 377100, 160, 0xe82e569e
+0, 378000, 160, 0x34df537d
+0, 378900, 160, 0x53175837
+0, 379800, 160, 0xbb76517f
+0, 380700, 160, 0xd5a25737
+0, 381600, 160, 0x58eb4f3d
+0, 382500, 160, 0x8f6e51d3
+0, 383400, 160, 0x1fd85602
+0, 384300, 160, 0xef2a4ee7
+0, 385200, 160, 0x0e6e58f4
+0, 386100, 160, 0x80345497
+0, 387000, 160, 0x710150a1
+0, 387900, 160, 0x32fb51db
+0, 388800, 160, 0x7efd564c
+0, 389700, 160, 0xf6604f26
+0, 390600, 160, 0xc0954d7e
+0, 391500, 160, 0x27705072
+0, 392400, 160, 0xd26f5958
+0, 393300, 160, 0x2c2552cd
+0, 394200, 160, 0xd14056b1
+0, 395100, 160, 0x11f356d2
+0, 396000, 160, 0x93b35efd
+0, 396900, 160, 0xa6d65ae7
+0, 397800, 160, 0x95015177
+0, 398700, 160, 0x2e6157e8
+0, 399600, 160, 0xb90c5021
+0, 400500, 160, 0xf39155c9
+0, 401400, 160, 0xd6ad544b
+0, 402300, 160, 0x4b8a5b98
+0, 403200, 160, 0x90a94f2d
+0, 404100, 160, 0x46a04f3f
+0, 405000, 160, 0x542b5cd1
+0, 405900, 160, 0xebaa5710
+0, 406800, 160, 0x504854a0
+0, 407700, 160, 0xbd9d53b5
+0, 408600, 160, 0x91524fed
+0, 409500, 160, 0x9b7a582d
+0, 410400, 160, 0xa4f258cf
+0, 411300, 160, 0x46274dda
+0, 412200, 160, 0xc0335ba9
+0, 413100, 160, 0xe59c5c74
+0, 414000, 160, 0xc2ee5ab0
+0, 414900, 160, 0x3e035996
+0, 415800, 160, 0x63e25521
+0, 416700, 160, 0xc09851af
+0, 417600, 160, 0xb8225715
+0, 418500, 160, 0x74355bfb
+0, 419400, 160, 0xf4c75adf
+0, 420300, 160, 0x2f8b56cd
+0, 421200, 160, 0xb4705795
+0, 422100, 160, 0xb4b25506
+0, 423000, 160, 0xaadb54f8
+0, 423900, 160, 0xe6d158aa
+0, 424800, 160, 0xed64614f
+0, 425700, 160, 0x80195732
+0, 426600, 160, 0xa8995f0e
+0, 427500, 160, 0xdc4a520d
+0, 428400, 160, 0x071a5bae
+0, 429300, 160, 0xce1b5ae9
+0, 430200, 160, 0x85e25804
+0, 431100, 160, 0x435e555f
+0, 432000, 160, 0xe4154ef4
+0, 432900, 160, 0xeff857b4
+0, 433800, 160, 0xc9e25868
+0, 434700, 160, 0x6e6961eb
+0, 435600, 160, 0x361e45e6
+0, 436500, 160, 0xf8a94988
+0, 437400, 160, 0x9de758b3
+0, 438300, 160, 0x2e65533e
+0, 439200, 160, 0x3f89422d
+0, 440100, 160, 0x77fd56a5
+0, 441000, 160, 0x91104845
+0, 441900, 160, 0x2eeb5491
+0, 442800, 160, 0x6a5348c4
+0, 443700, 160, 0xe0954882
+0, 444600, 160, 0x7e915761
+0, 445500, 160, 0x2cb5531f
+0, 446400, 160, 0xe1dc4ecd
+0, 447300, 160, 0xbf6b4e61
+0, 448200, 160, 0x3d6b5746
+0, 449100, 160, 0xe8bd5077
+0, 450000, 160, 0xd38d5921
+0, 450900, 160, 0xfc534e38
+0, 451800, 160, 0xd361475b
+0, 452700, 160, 0x4d5152c7
+0, 453600, 160, 0xb6684d11
+0, 454500, 160, 0xd2e25864
+0, 455400, 160, 0x02ec536a
+0, 456300, 160, 0x27ac550e
+0, 457200, 160, 0xe8d44e2d
+0, 458100, 160, 0x520152c8
+0, 459000, 160, 0xace747ea
+0, 459900, 160, 0x773a4ee3
+0, 460800, 160, 0x7dd1559f
+0, 461700, 160, 0x124453a8
+0, 462600, 160, 0x04154991
+0, 463500, 160, 0x3c794d98
+0, 464400, 160, 0x309f4e47
+0, 465300, 160, 0x98c74a48
+0, 466200, 160, 0xd0c34bcc
+0, 467100, 160, 0xfa304e19
+0, 468000, 160, 0x69505201
+0, 468900, 160, 0x2e714ac7
+0, 469800, 160, 0x076654a3
+0, 470700, 160, 0xc6674e27
+0, 471600, 160, 0x1adf4dd9
+0, 472500, 160, 0x4408507e
+0, 473400, 160, 0xd2654d94
+0, 474300, 160, 0x97a65cc0
+0, 475200, 160, 0xb53251f9
+0, 476100, 160, 0xd498584b
+0, 477000, 160, 0x46a058c8
+0, 477900, 160, 0xa2f85cbd
+0, 478800, 160, 0x43b856fb
+0, 479700, 160, 0xdeb957ba
+0, 480600, 160, 0x3064580a
+0, 481500, 160, 0xe86357a5
+0, 482400, 160, 0x9b974d00
+0, 483300, 160, 0x66ee4ff3
+0, 484200, 160, 0x0b9958f7
+0, 485100, 160, 0xc3754d0a
+0, 486000, 160, 0x42314c33
+0, 486900, 160, 0x4550555f
+0, 487800, 160, 0x0f064e4c
+0, 488700, 160, 0xe569596d
+0, 489600, 160, 0x056c4751
+0, 490500, 160, 0xdc1049fc
+0, 491400, 160, 0x63c54a1e
+0, 492300, 160, 0xb402518e
+0, 493200, 160, 0xaf0d4b19
+0, 494100, 160, 0xa22b4c5b
+0, 495000, 160, 0x28084bbf
+0, 495900, 160, 0x10495224
+0, 496800, 160, 0x4cb94993
+0, 497700, 160, 0x17c15457
+0, 498600, 160, 0xbd834d6d
+0, 499500, 160, 0x6ca25235
+0, 500400, 160, 0x84b74f89
+0, 501300, 160, 0xdeef4e76
+0, 502200, 160, 0x6ab05188
+0, 503100, 160, 0xa91c4646
+0, 504000, 160, 0xad574e7d
+0, 504900, 160, 0xba264d69
+0, 505800, 160, 0xd8734dd0
+0, 506700, 160, 0x69f25581
+0, 507600, 160, 0x3b8e4ae9
+0, 508500, 160, 0xb1124607
+0, 509400, 160, 0xd78e4e4f
+0, 510300, 160, 0x05a1504f
+0, 511200, 160, 0x3e705270
+0, 512100, 160, 0x1e144b3b
+0, 513000, 160, 0xbb0b5416
+0, 513900, 160, 0xc26f5b45
+0, 514800, 160, 0x14224ab9
+0, 515700, 160, 0x2bbd4837
+0, 516600, 160, 0xd2bf4e60
+0, 517500, 160, 0xbeec506c
+0, 518400, 160, 0x2cd34d3a
+0, 519300, 160, 0x85134fc6
+0, 520200, 160, 0xdb9a4ac2
+0, 521100, 160, 0x92715256
+0, 522000, 160, 0xff395098
+0, 522900, 160, 0xa5ec560c
+0, 523800, 160, 0xce95534b
+0, 524700, 160, 0xe36f46f1
+0, 525600, 160, 0x45f74a58
+0, 526500, 160, 0x02d05440
+0, 527400, 160, 0xa005529f
+0, 528300, 160, 0xae0f3f22
+0, 529200, 160, 0x3f984eb0
+0, 530100, 160, 0xc5bd5015
+0, 531000, 160, 0xf4504c53
+0, 531900, 160, 0x7f4044c5
+0, 532800, 160, 0x82dd4bab
+0, 533700, 160, 0x7a0d5122
+0, 534600, 160, 0xd0da5271
+0, 535500, 160, 0x67d14e3e
+0, 536400, 160, 0x54564f42
+0, 537300, 160, 0x77df4e0a
+0, 538200, 160, 0x0c4a4f70
+0, 539100, 160, 0xb2944f40
+0, 540000, 160, 0xe57a52de
+0, 540900, 160, 0x7d994ed1
+0, 541800, 160, 0x9dc35763
+0, 542700, 160, 0x8d0a4da9
+0, 543600, 160, 0x0c6449a4
+0, 544500, 160, 0xc73c503a
+0, 545400, 160, 0x52904cbe
+0, 546300, 160, 0x49824c2e
+0, 547200, 160, 0xb7e14e0b
+0, 548100, 160, 0x9745548e
+0, 549000, 160, 0xdafb4c20
+0, 549900, 160, 0x1aa84d67
+0, 550800, 160, 0x64bc5033
+0, 551700, 160, 0x9e2e5a05
+0, 552600, 160, 0x69144bc5
+0, 553500, 160, 0xce1253fa
+0, 554400, 160, 0x359f4c15
+0, 555300, 160, 0xdba74ed0
+0, 556200, 160, 0xea1453b8
+0, 557100, 160, 0xccdf49d3
+0, 558000, 160, 0xeb324750
+0, 558900, 160, 0x62b14ad4
+0, 559800, 160, 0x446e50c0
+0, 560700, 160, 0x111e5151
+0, 561600, 160, 0x6be84f3a
+0, 562500, 160, 0xf5cf4e42
+0, 563400, 160, 0xcc995459
+0, 564300, 160, 0x0faf5172
+0, 565200, 160, 0x31334f66
+0, 566100, 160, 0x20ba52c0
+0, 567000, 160, 0xc7cc4975
+0, 567900, 160, 0x9e7a51ba
+0, 568800, 160, 0x52884ff1
+0, 569700, 160, 0xc7a84cfd
+0, 570600, 160, 0x5ae64c22
+0, 571500, 160, 0x68125a92
+0, 572400, 160, 0x39ed54f1
+0, 573300, 160, 0xfa0a4ad1
+0, 574200, 160, 0xe8c8590c
+0, 575100, 160, 0x5f555576
+0, 576000, 160, 0xaf7a57a1
+0, 576900, 160, 0x858257e9
+0, 577800, 160, 0x1223523e
+0, 578700, 160, 0x446954a1
+0, 579600, 160, 0xfbe952d9
+0, 580500, 160, 0xd56259ff
+0, 581400, 160, 0xc4fa4f44
+0, 582300, 160, 0x77cc57f6
+0, 583200, 160, 0x53d3573d
+0, 584100, 160, 0x085e4ff9
+0, 585000, 160, 0x7a4e5410
+0, 585900, 160, 0xb4ad5794
+0, 586800, 160, 0x71255738
+0, 587700, 160, 0x36724918
+0, 588600, 160, 0x370e5974
+0, 589500, 160, 0xb709596c
+0, 590400, 160, 0x89b05052
+0, 591300, 160, 0x74e550ce
+0, 592200, 160, 0x6e2c5a49
+0, 593100, 160, 0x4dfa5b50
+0, 594000, 160, 0x80764c70
+0, 594900, 160, 0xc1d14fc6
+0, 595800, 160, 0x53e746b3
+0, 596700, 160, 0x728350c0
+0, 597600, 160, 0x9aa6500e
+0, 598500, 160, 0x60985454
+0, 599400, 160, 0xa0c54b6f
+0, 600300, 160, 0xe3b157ea
+0, 601200, 160, 0xce86573b
+0, 602100, 160, 0x9dad5535
+0, 603000, 160, 0xb3094af9
+0, 603900, 160, 0x2d1456ed
+0, 604800, 160, 0x328248b9
+0, 605700, 160, 0x4ffb4f52
+0, 606600, 160, 0x71fe53de
+0, 607500, 160, 0x0d114e92
+0, 608400, 160, 0x37065510
+0, 609300, 160, 0x426c4c07
+0, 610200, 160, 0x58e3528b
+0, 611100, 160, 0x71674484
+0, 612000, 160, 0x45934ee1
+0, 612900, 160, 0x4e914b31
+0, 613800, 160, 0x525b4ec2
+0, 614700, 160, 0x4393563d
+0, 615600, 160, 0xb10154e9
+0, 616500, 160, 0x23b15a4d
+0, 617400, 160, 0x6d995220
+0, 618300, 160, 0xcd2949fd
+0, 619200, 160, 0x67234f75
+0, 620100, 160, 0x00cc4cdb
+0, 621000, 160, 0x97c35574
+0, 621900, 160, 0xc0855753
+0, 622800, 160, 0xf4e650a5
+0, 623700, 160, 0x95b14bc2
+0, 624600, 160, 0x04d948dc
+0, 625500, 160, 0x284d4d02
+0, 626400, 160, 0xfb0d4cd9
+0, 627300, 160, 0x0e515126
+0, 628200, 160, 0xb4055a86
+0, 629100, 160, 0x0bbe4f68
+0, 630000, 160, 0xf1b848af
+0, 630900, 160, 0x7d154853
+0, 631800, 160, 0x78225418
+0, 632700, 160, 0xfb2f523e
+0, 633600, 160, 0xa6d34ea6
+0, 634500, 160, 0xe4264e30
+0, 635400, 160, 0x113750aa
+0, 636300, 160, 0x4073529b
+0, 637200, 160, 0xd1754dda
+0, 638100, 160, 0x1b495413
+0, 639000, 160, 0x29f94cd8
+0, 639900, 160, 0x49004a53
+0, 640800, 160, 0x1fec4de4
+0, 641700, 160, 0x7d6b4670
+0, 642600, 160, 0x626c4c9f
+0, 643500, 160, 0x79265234
+0, 644400, 160, 0xab765b86
+0, 645300, 160, 0xe9ae4d26
+0, 646200, 160, 0xeee1481f
+0, 647100, 160, 0x289d5287
+0, 648000, 160, 0xb5524e8b
+0, 648900, 160, 0x7e715764
+0, 649800, 160, 0xb1b25091
+0, 650700, 160, 0xf1a946f6
+0, 651600, 160, 0x57dc51bd
+0, 652500, 160, 0x4c0b4f14
+0, 653400, 160, 0xdc1f4930
+0, 654300, 160, 0x79d75057
+0, 655200, 160, 0x22bd52df
+0, 656100, 160, 0x963a5562
+0, 657000, 160, 0x7e475303
+0, 657900, 160, 0x2c065494
+0, 658800, 160, 0xb0514720
+0, 659700, 160, 0xbc734849
+0, 660600, 160, 0xf4924e4d
+0, 661500, 160, 0xe50f44c9
+0, 662400, 160, 0x978c4ce8
+0, 663300, 160, 0x302e51c2
+0, 664200, 160, 0x262b4a60
+0, 665100, 160, 0xf95f4e99
+0, 666000, 160, 0x7465504a
+0, 666900, 160, 0xab0e5108
+0, 667800, 160, 0xbec15395
+0, 668700, 160, 0x4f2c5139
+0, 669600, 160, 0x26444deb
+0, 670500, 160, 0xee4c4b15
+0, 671400, 160, 0x8bc350e1
+0, 672300, 160, 0xd0744a5a
+0, 673200, 160, 0xfee64d9d
+0, 674100, 160, 0x234c50b6
+0, 675000, 160, 0x8592482c
+0, 675900, 160, 0x5e8b5308
+0, 676800, 160, 0x4f9848c7
+0, 677700, 160, 0x939d4faa
+0, 678600, 160, 0x797654f1
+0, 679500, 160, 0x15d24d9b
+0, 680400, 160, 0xa6e54bd2
+0, 681300, 160, 0x755e4c90
+0, 682200, 160, 0xcd334bce
+0, 683100, 160, 0xfc1746e9
+0, 684000, 160, 0x81f04dd5
+0, 684900, 160, 0x44b35080
+0, 685800, 160, 0x91e65217
+0, 686700, 160, 0x492150af
+0, 687600, 160, 0xf73e58ec
+0, 688500, 160, 0xf988538a
+0, 689400, 160, 0x0dee4c10
+0, 690300, 160, 0x2c9f4c23
+0, 691200, 160, 0x8c1e4e08
+0, 692100, 160, 0x25bb5286
+0, 693000, 160, 0xd0ed469b
+0, 693900, 160, 0x71eb50e8
+0, 694800, 160, 0x249f4d26
+0, 695700, 160, 0x9662498f
+0, 696600, 160, 0x49ee55e2
+0, 697500, 160, 0x54d9491b
+0, 698400, 160, 0x4c675649
+0, 699300, 160, 0x0e4b4b34
+0, 700200, 160, 0x776f4995
+0, 701100, 160, 0x722656b2
+0, 702000, 160, 0x081d4b6f
+0, 702900, 160, 0xf70746fe
+0, 703800, 160, 0x08b151da
+0, 704700, 160, 0x6b255328
+0, 705600, 160, 0xeb2b586a
+0, 706500, 160, 0x812b4444
+0, 707400, 160, 0x1e16533f
+0, 708300, 160, 0xc1244760
+0, 709200, 160, 0x67584d87
+0, 710100, 160, 0xde8b5726
+0, 711000, 160, 0xe96d4e3e
+0, 711900, 160, 0x41174c98
+0, 712800, 160, 0x4cdd4cd8
+0, 713700, 160, 0xfb724b64
+0, 714600, 160, 0x78f154df
+0, 715500, 160, 0x97e1476d
+0, 716400, 160, 0x6f034e7f
+0, 717300, 160, 0x93b240df
+0, 718200, 160, 0xc4d040e6
+0, 719100, 160, 0xe47744a4
+0, 720000, 160, 0x87a950ff
+0, 720900, 160, 0x7079491b
+0, 721800, 160, 0x89f0491a
+0, 722700, 160, 0x70b8467e
+0, 723600, 160, 0x20945294
+0, 724500, 160, 0x2d5c4919
+0, 725400, 160, 0x1ed44c78
+0, 726300, 160, 0x93d74a5f
+0, 727200, 160, 0x300e490e
+0, 728100, 160, 0x8249558d
+0, 729000, 160, 0x630a4f57
+0, 729900, 160, 0xdd6e475f
+0, 730800, 160, 0xf50941e5
+0, 731700, 160, 0x1fe44bea
+0, 732600, 160, 0x03be5469
+0, 733500, 160, 0x7ece4f4c
+0, 734400, 160, 0x31f953dd
+0, 735300, 160, 0x22a44b7d
+0, 736200, 160, 0x1f5e5562
+0, 737100, 160, 0x771b5688
+0, 738000, 160, 0x7d1c4d45
+0, 738900, 160, 0x6bc45cd0
+0, 739800, 160, 0x8f714c36
+0, 740700, 160, 0xfb1f4c87
+0, 741600, 160, 0x1f8a4b36
+0, 742500, 160, 0xee5c451a
+0, 743400, 160, 0xd56950ac
+0, 744300, 160, 0x529057f6
+0, 745200, 160, 0x336641fd
+0, 746100, 160, 0xa0dd5a66
+0, 747000, 160, 0x5f4b5248
+0, 747900, 160, 0xb6ef49a3
+0, 748800, 160, 0x07705f19
+0, 749700, 160, 0x3fce4bbb
+0, 750600, 160, 0xda395511
+0, 751500, 160, 0x1ecf5145
+0, 752400, 160, 0x88a547ab
+0, 753300, 160, 0x6c6849be
+0, 754200, 160, 0x979c4e97
+0, 755100, 160, 0x171854b3
+0, 756000, 160, 0x9a715283
+0, 756900, 160, 0x064e50ac
+0, 757800, 160, 0xc2fb4e94
+0, 758700, 160, 0x708146f5
+0, 759600, 160, 0x1ca45198
+0, 760500, 160, 0x332d4869
+0, 761400, 160, 0xc2ff4656
+0, 762300, 160, 0x0747552e
+0, 763200, 160, 0x0c3d4ba8
+0, 764100, 160, 0x72934dab
+0, 765000, 160, 0xbb1e5860
+0, 765900, 160, 0x526d4cea
+0, 766800, 160, 0xa4c445d6
+0, 767700, 160, 0x70cd49ba
+0, 768600, 160, 0x008c53a7
+0, 769500, 160, 0xf7174bca
+0, 770400, 160, 0x0bab4936
+0, 771300, 160, 0x59e5564d
+0, 772200, 160, 0x33045087
+0, 773100, 160, 0xde7454f0
+0, 774000, 160, 0x31184cc3
+0, 774900, 160, 0x37984bb3
+0, 775800, 160, 0xf5e052d4
+0, 776700, 160, 0x23ca4b42
+0, 777600, 160, 0xbe2a572b
+0, 778500, 160, 0x9a91538d
+0, 779400, 160, 0x8a994c40
+0, 780300, 160, 0x5dea51ee
+0, 781200, 160, 0x1b53524c
+0, 782100, 160, 0xd9e75227
+0, 783000, 160, 0x58384c3b
+0, 783900, 160, 0x4a1b53b2
+0, 784800, 160, 0xc2a3458a
+0, 785700, 160, 0x7f68502d
+0, 786600, 160, 0x85475559
+0, 787500, 160, 0xd0d25472
+0, 788400, 160, 0x4c0d4bbf
+0, 789300, 160, 0xcad352df
+0, 790200, 160, 0x17904c97
+0, 791100, 160, 0x4e774b8e
+0, 792000, 160, 0x21905952
+0, 792900, 160, 0xc2d950cd
+0, 793800, 160, 0xfdea55e6
+0, 794700, 160, 0x22ca4e37
+0, 795600, 160, 0x1143562a
+0, 796500, 160, 0xe83c583e
+0, 797400, 160, 0xba544b27
+0, 798300, 160, 0x1e8c50e4
+0, 799200, 160, 0xf7ca4d2a
+0, 800100, 160, 0x67764579
+0, 801000, 160, 0x40d74f42
+0, 801900, 160, 0x88e35360
+0, 802800, 160, 0xda3f4f5b
+0, 803700, 160, 0x19c1522f
+0, 804600, 160, 0x93ce4f78
+0, 805500, 160, 0xf65447ba
+0, 806400, 160, 0xc0bc4e5a
+0, 807300, 160, 0x4915572b
+0, 808200, 160, 0x1651460b
+0, 809100, 160, 0xffe552a5
+0, 810000, 160, 0x5bd351ab
+0, 810900, 160, 0xbbd85034
+0, 811800, 160, 0xb9ff505f
+0, 812700, 160, 0xfc104eaf
+0, 813600, 160, 0xdaa74d6c
+0, 814500, 160, 0x34b04d78
+0, 815400, 160, 0x1e924f70
+0, 816300, 160, 0x0d46512d
+0, 817200, 160, 0x0d115950
+0, 818100, 160, 0x62de55a4
+0, 819000, 160, 0x58d652ab
+0, 819900, 160, 0x1776584e
+0, 820800, 160, 0x60175a2b
+0, 821700, 160, 0x4d714c82
+0, 822600, 160, 0xe13c4ce0
+0, 823500, 160, 0x7cd15464
+0, 824400, 160, 0x6c87571a
+0, 825300, 160, 0x1abe4f07
+0, 826200, 160, 0x039d5661
+0, 827100, 160, 0x0eba5909
+0, 828000, 160, 0xa46e51ec
+0, 828900, 160, 0x9be44eb7
+0, 829800, 160, 0xe0634aad
+0, 830700, 160, 0xcd53530b
+0, 831600, 160, 0x12cd482c
+0, 832500, 160, 0x71884634
+0, 833400, 160, 0xd5845743
+0, 834300, 160, 0xacd1502c
+0, 835200, 160, 0x04795031
+0, 836100, 160, 0xf0df54b9
+0, 837000, 160, 0x43aa5155
+0, 837900, 160, 0x316a4988
+0, 838800, 160, 0xfbc64f8a
+0, 839700, 160, 0xda084e8e
+0, 840600, 160, 0x3cc34ce2
+0, 841500, 160, 0xbfc055d8
+0, 842400, 160, 0x20ef4876
+0, 843300, 160, 0x035a5660
+0, 844200, 160, 0xbc7255be
+0, 845100, 160, 0xba514f44
+0, 846000, 160, 0x868c4c9c
+0, 846900, 160, 0x83494f04
+0, 847800, 160, 0xa452521a
+0, 848700, 160, 0x2ed04f65
+0, 849600, 160, 0x2e3e592d
+0, 850500, 160, 0x82bc4763
+0, 851400, 160, 0x339950db
+0, 852300, 160, 0x5bb64eff
+0, 853200, 160, 0x347c4d85
+0, 854100, 160, 0x25e949a3
+0, 855000, 160, 0xbdf649a8
+0, 855900, 160, 0x498650f3
+0, 856800, 160, 0x2a6f4e60
+0, 857700, 160, 0x661e5697
+0, 858600, 160, 0x5d6150ca
+0, 859500, 160, 0xe7c74b8f
+0, 860400, 160, 0x1ae148da
+0, 861300, 160, 0xaeef485d
+0, 862200, 160, 0x105650c6
+0, 863100, 160, 0xc1c45376
+0, 864000, 160, 0x83c55011
+0, 864900, 160, 0x77025597
+0, 865800, 160, 0x324250b7
+0, 866700, 160, 0x5cdc570f
+0, 867600, 160, 0x292e52a1
+0, 868500, 160, 0x8d7a5090
+0, 869400, 160, 0x32fc54e4
+0, 870300, 160, 0x50984e8b
+0, 871200, 160, 0x07f442a0
+0, 872100, 160, 0xc91c4fc3
+0, 873000, 160, 0x06cf53d7
+0, 873900, 160, 0xa66c5923
+0, 874800, 160, 0xc2015120
+0, 875700, 160, 0xedfa50c4
+0, 876600, 160, 0xe4c85fb5
+0, 877500, 160, 0xcd7b4c65
+0, 878400, 160, 0xb22353c1
+0, 879300, 160, 0x298c5996
+0, 880200, 160, 0xefce51db
+0, 881100, 160, 0x6df74ee3
+0, 882000, 160, 0x7c46496b
+0, 882900, 160, 0x910a48a4
+0, 883800, 160, 0xbf504b1e
+0, 884700, 160, 0x096947e8
+0, 885600, 160, 0x4a07629d
+0, 886500, 160, 0x577b43c1
+0, 887400, 160, 0x939e4d6d
+0, 888300, 160, 0x486e48ac
+0, 889200, 160, 0x50064871
+0, 890100, 160, 0x4a255534
+0, 891000, 160, 0xc80d4618
+0, 891900, 160, 0xf18a4780
+0, 892800, 160, 0x1c274dd4
+0, 893700, 160, 0x2f3e4f7c
+0, 894600, 160, 0x44b24cc2
+0, 895500, 160, 0x89b451f4
+0, 896400, 160, 0x06515b65
+0, 897300, 160, 0xc5b857ce
+0, 898200, 160, 0xa47b47a7
+0, 899100, 160, 0xfb375448
diff --git a/tests/ref/fate/g729-1 b/tests/ref/fate/g729-1
new file mode 100644
index 0000000000..6bf05c5efd
--- /dev/null
+++ b/tests/ref/fate/g729-1
@@ -0,0 +1,1000 @@
+0, 0, 160, 0xf7e550f0
+0, 900, 160, 0x42794ea8
+0, 1800, 160, 0xfe023e42
+0, 2700, 160, 0xc1ae40e3
+0, 3600, 160, 0xee6d4bf1
+0, 4500, 160, 0x107451d7
+0, 5400, 160, 0x40cb4ba4
+0, 6300, 160, 0x90504e5e
+0, 7200, 160, 0xf6f3531d
+0, 8100, 160, 0x48664ea0
+0, 9000, 160, 0xa30458e1
+0, 9900, 160, 0x00b74aa2
+0, 10800, 160, 0x95234e49
+0, 11700, 160, 0x9cf24a94
+0, 12600, 160, 0x4f2952f4
+0, 13500, 160, 0x658353db
+0, 14400, 160, 0x98ef4d79
+0, 15300, 160, 0x765d5472
+0, 16200, 160, 0xc6e25262
+0, 17100, 160, 0x33334993
+0, 18000, 160, 0xfa104dc5
+0, 18900, 160, 0x03ee5530
+0, 19800, 160, 0x52c54e0e
+0, 20700, 160, 0xbd744638
+0, 21600, 160, 0x7775519f
+0, 22500, 160, 0xd22f499e
+0, 23400, 160, 0x26af4eec
+0, 24300, 160, 0x37474ed9
+0, 25200, 160, 0x6b19548d
+0, 26100, 160, 0x4a3449b7
+0, 27000, 160, 0x2bed5231
+0, 27900, 160, 0x556d5349
+0, 28800, 160, 0xbb6c5227
+0, 29700, 160, 0xea354b4d
+0, 30600, 160, 0xf35f4b7d
+0, 31500, 160, 0x9dcb4e9d
+0, 32400, 160, 0xc81f5ac2
+0, 33300, 160, 0xfa054cfd
+0, 34200, 160, 0x0c554e62
+0, 35100, 160, 0x7ffa5250
+0, 36000, 160, 0x7e5148ec
+0, 36900, 160, 0x95bc4d69
+0, 37800, 160, 0xf34a5644
+0, 38700, 160, 0xcaa3493d
+0, 39600, 160, 0xa44745dc
+0, 40500, 160, 0x320355c0
+0, 41400, 160, 0xbd1e5670
+0, 42300, 160, 0xfe3250cd
+0, 43200, 160, 0xce7a574c
+0, 44100, 160, 0x09b04f6e
+0, 45000, 160, 0x035759c8
+0, 45900, 160, 0x713458c7
+0, 46800, 160, 0x9a75494b
+0, 47700, 160, 0x99114fef
+0, 48600, 160, 0x129251f0
+0, 49500, 160, 0x4eb845f2
+0, 50400, 160, 0x5d064da5
+0, 51300, 160, 0x5a8e4a34
+0, 52200, 160, 0x5b784608
+0, 53100, 160, 0x1ca7546a
+0, 54000, 160, 0x327e5cbf
+0, 54900, 160, 0xd7ae4bc3
+0, 55800, 160, 0xba3f55b4
+0, 56700, 160, 0x09fe4ca7
+0, 57600, 160, 0x347248ba
+0, 58500, 160, 0xf0bf52ff
+0, 59400, 160, 0x3500507e
+0, 60300, 160, 0x30e65135
+0, 61200, 160, 0x390a5201
+0, 62100, 160, 0xf0dc5bca
+0, 63000, 160, 0x69b94f64
+0, 63900, 160, 0x6ac04cf6
+0, 64800, 160, 0xbc014cf4
+0, 65700, 160, 0x4b564eca
+0, 66600, 160, 0x33e44e85
+0, 67500, 160, 0xe39e5343
+0, 68400, 160, 0xebf64c80
+0, 69300, 160, 0x5a92562b
+0, 70200, 160, 0xe0075c88
+0, 71100, 160, 0x59bd55e8
+0, 72000, 160, 0xe6ca4ef2
+0, 72900, 160, 0xea9a4df2
+0, 73800, 160, 0xf53c4bf6
+0, 74700, 160, 0x977a4f32
+0, 75600, 160, 0xe5894eb2
+0, 76500, 160, 0x956c4c28
+0, 77400, 160, 0xdff74c3d
+0, 78300, 160, 0xace74db7
+0, 79200, 160, 0x00e74ef5
+0, 80100, 160, 0x6633560a
+0, 81000, 160, 0xd63647c5
+0, 81900, 160, 0xff144eef
+0, 82800, 160, 0xc5fe4d51
+0, 83700, 160, 0x5c244c7c
+0, 84600, 160, 0x95be50f1
+0, 85500, 160, 0x74d84b77
+0, 86400, 160, 0x1e965711
+0, 87300, 160, 0x7ae45ad7
+0, 88200, 160, 0xf9cd5920
+0, 89100, 160, 0xf0064ea9
+0, 90000, 160, 0xec645244
+0, 90900, 160, 0x8330539a
+0, 91800, 160, 0x4a5d5023
+0, 92700, 160, 0x706153d7
+0, 93600, 160, 0xd6e0520f
+0, 94500, 160, 0x0bd9586f
+0, 95400, 160, 0xc1554dec
+0, 96300, 160, 0x89be4bde
+0, 97200, 160, 0x0c2a49c0
+0, 98100, 160, 0xc18d498a
+0, 99000, 160, 0xc36147e1
+0, 99900, 160, 0x99de4d4b
+0, 100800, 160, 0x2b9d542b
+0, 101700, 160, 0x062b52c9
+0, 102600, 160, 0x9dcf542e
+0, 103500, 160, 0x641f58b9
+0, 104400, 160, 0x114c51ff
+0, 105300, 160, 0x78e04b0e
+0, 106200, 160, 0xfec74535
+0, 107100, 160, 0x71d54cd3
+0, 108000, 160, 0xee9e5289
+0, 108900, 160, 0x142354d9
+0, 109800, 160, 0x051e4ddc
+0, 110700, 160, 0x358146b8
+0, 111600, 160, 0x4dec58eb
+0, 112500, 160, 0xd0944f04
+0, 113400, 160, 0xdc025a99
+0, 114300, 160, 0x6b355402
+0, 115200, 160, 0x1c0b5a6d
+0, 116100, 160, 0xa3b34bc8
+0, 117000, 160, 0x92604eb7
+0, 117900, 160, 0x6f2f5465
+0, 118800, 160, 0xcb565361
+0, 119700, 160, 0x8bfb50a3
+0, 120600, 160, 0xf9114e99
+0, 121500, 160, 0x11065580
+0, 122400, 160, 0x903550c8
+0, 123300, 160, 0xe7aa3da8
+0, 124200, 160, 0x13f34e01
+0, 125100, 160, 0x4c3b4c0a
+0, 126000, 160, 0x08e64c60
+0, 126900, 160, 0xffcd6176
+0, 127800, 160, 0x09684f13
+0, 128700, 160, 0xd8a646b5
+0, 129600, 160, 0xc07355f0
+0, 130500, 160, 0xe836515b
+0, 131400, 160, 0x935741a5
+0, 132300, 160, 0x68f85160
+0, 133200, 160, 0x669a4ed0
+0, 134100, 160, 0xce9f4883
+0, 135000, 160, 0xd94c42de
+0, 135900, 160, 0xf1874b54
+0, 136800, 160, 0x42da46ce
+0, 137700, 160, 0xe99a4da5
+0, 138600, 160, 0x94934f16
+0, 139500, 160, 0x8571437f
+0, 140400, 160, 0xe4774dc2
+0, 141300, 160, 0x743f4f89
+0, 142200, 160, 0x3b3e50ba
+0, 143100, 160, 0x439355e9
+0, 144000, 160, 0x3e4d5178
+0, 144900, 160, 0x64595524
+0, 145800, 160, 0x42d14702
+0, 146700, 160, 0x051e4b1d
+0, 147600, 160, 0x5db84cee
+0, 148500, 160, 0x4d875136
+0, 149400, 160, 0x33b75996
+0, 150300, 160, 0xd5094d76
+0, 151200, 160, 0x6a7052b7
+0, 152100, 160, 0x77264c8f
+0, 153000, 160, 0xcf7e4ccf
+0, 153900, 160, 0x5f7c568b
+0, 154800, 160, 0x8886578b
+0, 155700, 160, 0xd33a4e52
+0, 156600, 160, 0xeefe5c23
+0, 157500, 160, 0xa9c94e38
+0, 158400, 160, 0x67845aa0
+0, 159300, 160, 0xbe91498f
+0, 160200, 160, 0x843d46e3
+0, 161100, 160, 0xbd215999
+0, 162000, 160, 0x1a2e5f2c
+0, 162900, 160, 0x6a344a63
+0, 163800, 160, 0xd80d5743
+0, 164700, 160, 0x80964879
+0, 165600, 160, 0xaafb5e35
+0, 166500, 160, 0x3b855ff3
+0, 167400, 160, 0x770b51d0
+0, 168300, 160, 0x623a5312
+0, 169200, 160, 0x0c235b56
+0, 170100, 160, 0xc8c25724
+0, 171000, 160, 0xb44650e2
+0, 171900, 160, 0xab964d47
+0, 172800, 160, 0x7aa35107
+0, 173700, 160, 0xf12d4780
+0, 174600, 160, 0x77e64f92
+0, 175500, 160, 0x34ee4fa0
+0, 176400, 160, 0x6701466b
+0, 177300, 160, 0xa79d4b4c
+0, 178200, 160, 0xbb7f557b
+0, 179100, 160, 0xaeb253c4
+0, 180000, 160, 0xe7255029
+0, 180900, 160, 0xa5f1505c
+0, 181800, 160, 0x4ae54f09
+0, 182700, 160, 0x6a2b4bc9
+0, 183600, 160, 0xf8724ea5
+0, 184500, 160, 0x4ab35317
+0, 185400, 160, 0xc8d350fb
+0, 186300, 160, 0x73a74994
+0, 187200, 160, 0x9cd1596d
+0, 188100, 160, 0x5ba16005
+0, 189000, 160, 0xb17e4fcc
+0, 189900, 160, 0x8ac958cd
+0, 190800, 160, 0x7919557f
+0, 191700, 160, 0x0be35121
+0, 192600, 160, 0xf8f752f2
+0, 193500, 160, 0xae894d40
+0, 194400, 160, 0x03d94c10
+0, 195300, 160, 0xf12c4917
+0, 196200, 160, 0x3c94534e
+0, 197100, 160, 0x111d51c3
+0, 198000, 160, 0x0a285304
+0, 198900, 160, 0xc3ac4ab1
+0, 199800, 160, 0x5576579d
+0, 200700, 160, 0x9cd04f10
+0, 201600, 160, 0x38a04bf9
+0, 202500, 160, 0xbd0d4d6d
+0, 203400, 160, 0x4db24510
+0, 204300, 160, 0x968753de
+0, 205200, 160, 0x1fa35c67
+0, 206100, 160, 0xc9c048bc
+0, 207000, 160, 0x221d629e
+0, 207900, 160, 0xbb864b0e
+0, 208800, 160, 0xe2964bcd
+0, 209700, 160, 0x20ff4b23
+0, 210600, 160, 0x01dc53e7
+0, 211500, 160, 0x522b56aa
+0, 212400, 160, 0x1e6a495a
+0, 213300, 160, 0x0dcf5731
+0, 214200, 160, 0x241f448d
+0, 215100, 160, 0xdafa55b6
+0, 216000, 160, 0x40584e43
+0, 216900, 160, 0xb73850ab
+0, 217800, 160, 0x7cff593a
+0, 218700, 160, 0x2796515a
+0, 219600, 160, 0x872c5454
+0, 220500, 160, 0xa13058e7
+0, 221400, 160, 0xd8a65261
+0, 222300, 160, 0x48a75601
+0, 223200, 160, 0xb1e7584c
+0, 224100, 160, 0x29cd53fa
+0, 225000, 160, 0xba514d84
+0, 225900, 160, 0x747f4f99
+0, 226800, 160, 0x5819526e
+0, 227700, 160, 0x10185413
+0, 228600, 160, 0x4d084cdc
+0, 229500, 160, 0x8313530b
+0, 230400, 160, 0xd26c5583
+0, 231300, 160, 0x76d749f9
+0, 232200, 160, 0x7cf847a5
+0, 233100, 160, 0xa642590c
+0, 234000, 160, 0x7fef56f2
+0, 234900, 160, 0xf6ea49b9
+0, 235800, 160, 0x6c654e89
+0, 236700, 160, 0x164f56e9
+0, 237600, 160, 0x84cf6139
+0, 238500, 160, 0x20c753ef
+0, 239400, 160, 0x3f3a485f
+0, 240300, 160, 0xee0c5f4b
+0, 241200, 160, 0x706b5313
+0, 242100, 160, 0x47da5af3
+0, 243000, 160, 0x05504b25
+0, 243900, 160, 0x584e59d8
+0, 244800, 160, 0xe9cc4e37
+0, 245700, 160, 0xf33b518a
+0, 246600, 160, 0xb9ac58b7
+0, 247500, 160, 0xed5c57f0
+0, 248400, 160, 0x4cf1579d
+0, 249300, 160, 0x96f94792
+0, 250200, 160, 0x7c455836
+0, 251100, 160, 0xad6652ce
+0, 252000, 160, 0x1ba95cab
+0, 252900, 160, 0xd86755bb
+0, 253800, 160, 0x2f9e51b4
+0, 254700, 160, 0x084e5119
+0, 255600, 160, 0x54ad5449
+0, 256500, 160, 0xff7c5b86
+0, 257400, 160, 0x29a94fff
+0, 258300, 160, 0x679c55ff
+0, 259200, 160, 0x9a415b81
+0, 260100, 160, 0x3ea5528a
+0, 261000, 160, 0x54e15d3f
+0, 261900, 160, 0x122b5c28
+0, 262800, 160, 0xdc0f4e7f
+0, 263700, 160, 0xdc304acd
+0, 264600, 160, 0xe55e5407
+0, 265500, 160, 0x8d07485f
+0, 266400, 160, 0xdc0b5333
+0, 267300, 160, 0xfaed4a90
+0, 268200, 160, 0xb0625538
+0, 269100, 160, 0x1ef3526b
+0, 270000, 160, 0xb48c48e9
+0, 270900, 160, 0x8c945190
+0, 271800, 160, 0x7f9a58b3
+0, 272700, 160, 0x55735499
+0, 273600, 160, 0xeba34a71
+0, 274500, 160, 0xbaa94a6d
+0, 275400, 160, 0x15ab484f
+0, 276300, 160, 0xdc675509
+0, 277200, 160, 0xc2e94f0e
+0, 278100, 160, 0xd7f348ac
+0, 279000, 160, 0x14884e8f
+0, 279900, 160, 0x2d274a97
+0, 280800, 160, 0x578c5834
+0, 281700, 160, 0x12074dab
+0, 282600, 160, 0x74c55067
+0, 283500, 160, 0x7c904e0f
+0, 284400, 160, 0x81d45735
+0, 285300, 160, 0x766f4d71
+0, 286200, 160, 0x9c915273
+0, 287100, 160, 0xf37f4d04
+0, 288000, 160, 0x1ac74d66
+0, 288900, 160, 0xf9b253ab
+0, 289800, 160, 0x6e0c5bb2
+0, 290700, 160, 0x603d629e
+0, 291600, 160, 0xbb674faf
+0, 292500, 160, 0x5d8d51c6
+0, 293400, 160, 0xae7350b9
+0, 294300, 160, 0xfde859ec
+0, 295200, 160, 0x900d50a4
+0, 296100, 160, 0x003551b2
+0, 297000, 160, 0xf8ae4c9d
+0, 297900, 160, 0x66ea508f
+0, 298800, 160, 0xd45b4c51
+0, 299700, 160, 0xb64451a3
+0, 300600, 160, 0x6d2a5621
+0, 301500, 160, 0x71db4d36
+0, 302400, 160, 0x06704647
+0, 303300, 160, 0x1f124cf9
+0, 304200, 160, 0x10d14b46
+0, 305100, 160, 0x421b59d8
+0, 306000, 160, 0x84ba4cae
+0, 306900, 160, 0x4fba48e1
+0, 307800, 160, 0xec294a6b
+0, 308700, 160, 0x2f1752a7
+0, 309600, 160, 0x8d665570
+0, 310500, 160, 0x586e537d
+0, 311400, 160, 0x18d54a49
+0, 312300, 160, 0xa895566d
+0, 313200, 160, 0xb9b35255
+0, 314100, 160, 0x2e194e1f
+0, 315000, 160, 0x4810594b
+0, 315900, 160, 0xb82557ee
+0, 316800, 160, 0x35d84d67
+0, 317700, 160, 0x5ee95128
+0, 318600, 160, 0x24f05747
+0, 319500, 160, 0x434d53f6
+0, 320400, 160, 0x3c894f3e
+0, 321300, 160, 0x81c34896
+0, 322200, 160, 0x7540543c
+0, 323100, 160, 0x35bc5504
+0, 324000, 160, 0x546943dc
+0, 324900, 160, 0x084d46e9
+0, 325800, 160, 0x983852ba
+0, 326700, 160, 0xefac4e15
+0, 327600, 160, 0xc9294430
+0, 328500, 160, 0xe9e74de1
+0, 329400, 160, 0x4ca1516a
+0, 330300, 160, 0x44014ceb
+0, 331200, 160, 0x1dbc5ad1
+0, 332100, 160, 0x98be4efd
+0, 333000, 160, 0x2dc75c7a
+0, 333900, 160, 0x46275852
+0, 334800, 160, 0x61c15d30
+0, 335700, 160, 0x1f605adc
+0, 336600, 160, 0xf08659ac
+0, 337500, 160, 0xb7656021
+0, 338400, 160, 0x1f4a5a72
+0, 339300, 160, 0xf8175275
+0, 340200, 160, 0xbbf4564d
+0, 341100, 160, 0x6fdc5a7d
+0, 342000, 160, 0x082f5250
+0, 342900, 160, 0x84cb55b5
+0, 343800, 160, 0x0e1a51ba
+0, 344700, 160, 0xa84e52fc
+0, 345600, 160, 0xcb5a55c9
+0, 346500, 160, 0x9ce6570d
+0, 347400, 160, 0x82b253cc
+0, 348300, 160, 0x34c4594b
+0, 349200, 160, 0xff5c5854
+0, 350100, 160, 0xd5da4ea0
+0, 351000, 160, 0xc86e5553
+0, 351900, 160, 0x7ecb55c6
+0, 352800, 160, 0xb08b5338
+0, 353700, 160, 0xd601573c
+0, 354600, 160, 0x93305092
+0, 355500, 160, 0x352d4912
+0, 356400, 160, 0xddba4d29
+0, 357300, 160, 0xc79c50b7
+0, 358200, 160, 0xe67d4e8e
+0, 359100, 160, 0xdbfd4bbc
+0, 360000, 160, 0xb2f746fb
+0, 360900, 160, 0x835b5539
+0, 361800, 160, 0x612049e9
+0, 362700, 160, 0x91a6503c
+0, 363600, 160, 0x762e4f0e
+0, 364500, 160, 0x2b2153f9
+0, 365400, 160, 0xdcfe5804
+0, 366300, 160, 0x79144cae
+0, 367200, 160, 0xd6394d99
+0, 368100, 160, 0x22395292
+0, 369000, 160, 0x50b04fa0
+0, 369900, 160, 0x846b49a5
+0, 370800, 160, 0x1f554dff
+0, 371700, 160, 0x0aa458dd
+0, 372600, 160, 0x62154dde
+0, 373500, 160, 0xe69847ac
+0, 374400, 160, 0x75855425
+0, 375300, 160, 0x49125665
+0, 376200, 160, 0xa8605945
+0, 377100, 160, 0xc02a5083
+0, 378000, 160, 0x6198537c
+0, 378900, 160, 0x90f25711
+0, 379800, 160, 0x32da51f1
+0, 380700, 160, 0x96c3474d
+0, 381600, 160, 0x82ae4579
+0, 382500, 160, 0xbabf5919
+0, 383400, 160, 0x78095772
+0, 384300, 160, 0x46964abb
+0, 385200, 160, 0x5fcb5ba3
+0, 386100, 160, 0x4a775585
+0, 387000, 160, 0xc41f53af
+0, 387900, 160, 0x457251bc
+0, 388800, 160, 0x8f864fb3
+0, 389700, 160, 0x439d526c
+0, 390600, 160, 0x5cf6503f
+0, 391500, 160, 0x90b7534f
+0, 392400, 160, 0xecc45253
+0, 393300, 160, 0x533b4ee3
+0, 394200, 160, 0x4cc44f27
+0, 395100, 160, 0x6ff35096
+0, 396000, 160, 0x141e4a80
+0, 396900, 160, 0x9e075461
+0, 397800, 160, 0xc4b55791
+0, 398700, 160, 0x40955666
+0, 399600, 160, 0x6255462f
+0, 400500, 160, 0x2cec55d6
+0, 401400, 160, 0xd71652e9
+0, 402300, 160, 0xe65e530c
+0, 403200, 160, 0xeeb9556d
+0, 404100, 160, 0x558f523e
+0, 405000, 160, 0x76e14b00
+0, 405900, 160, 0x3f9f4e9b
+0, 406800, 160, 0x0d7b492a
+0, 407700, 160, 0xdd6e51bd
+0, 408600, 160, 0x5ab353b9
+0, 409500, 160, 0x5b934f33
+0, 410400, 160, 0x36bb57a0
+0, 411300, 160, 0x455d54d3
+0, 412200, 160, 0x7e6853d7
+0, 413100, 160, 0xdcb85ed4
+0, 414000, 160, 0x3a8d5860
+0, 414900, 160, 0x5c90558f
+0, 415800, 160, 0x25504d46
+0, 416700, 160, 0x0fc55413
+0, 417600, 160, 0x98545409
+0, 418500, 160, 0x963b550e
+0, 419400, 160, 0x544a569c
+0, 420300, 160, 0x7ab65f77
+0, 421200, 160, 0x14c257e2
+0, 422100, 160, 0x6cac6262
+0, 423000, 160, 0x2f7f5091
+0, 423900, 160, 0xc2655462
+0, 424800, 160, 0xbb4b4744
+0, 425700, 160, 0x4c5f54db
+0, 426600, 160, 0x9e694ab5
+0, 427500, 160, 0xc2c95173
+0, 428400, 160, 0xf4ae553f
+0, 429300, 160, 0xb4c04ed1
+0, 430200, 160, 0xf3095128
+0, 431100, 160, 0x73b04de1
+0, 432000, 160, 0xff4951c7
+0, 432900, 160, 0x28c156bd
+0, 433800, 160, 0x17b652aa
+0, 434700, 160, 0xb9ce528b
+0, 435600, 160, 0x3cc558be
+0, 436500, 160, 0xdf385905
+0, 437400, 160, 0xe2de4fe2
+0, 438300, 160, 0xc2a6582d
+0, 439200, 160, 0xe5715bc9
+0, 440100, 160, 0x741b6416
+0, 441000, 160, 0xf9b1544f
+0, 441900, 160, 0x012e5f01
+0, 442800, 160, 0x5ab65a49
+0, 443700, 160, 0xfe1e5b1a
+0, 444600, 160, 0x370056ef
+0, 445500, 160, 0xfde45ed4
+0, 446400, 160, 0xa34f6053
+0, 447300, 160, 0x31755604
+0, 448200, 160, 0xc3415bfe
+0, 449100, 160, 0xe5dd5b58
+0, 450000, 160, 0xb6cf5295
+0, 450900, 160, 0x3d81538b
+0, 451800, 160, 0xc00255d2
+0, 452700, 160, 0xb0714f71
+0, 453600, 160, 0x9c9756ac
+0, 454500, 160, 0x4de053a0
+0, 455400, 160, 0x6706500c
+0, 456300, 160, 0x34e4511d
+0, 457200, 160, 0xe4224e3e
+0, 458100, 160, 0xdf695529
+0, 459000, 160, 0xeb1f54e0
+0, 459900, 160, 0x2870550e
+0, 460800, 160, 0x08465464
+0, 461700, 160, 0xe34150e6
+0, 462600, 160, 0xb77556e0
+0, 463500, 160, 0xb23e46ab
+0, 464400, 160, 0x83884a7b
+0, 465300, 160, 0xa0284b16
+0, 466200, 160, 0x87b749e1
+0, 467100, 160, 0x4b276444
+0, 468000, 160, 0x92f95091
+0, 468900, 160, 0x2b1056c2
+0, 469800, 160, 0xd5d5590a
+0, 470700, 160, 0x5a454fac
+0, 471600, 160, 0x0ab05b13
+0, 472500, 160, 0xd98e56ca
+0, 473400, 160, 0x183d5892
+0, 474300, 160, 0x8ba951e4
+0, 475200, 160, 0x487054ff
+0, 476100, 160, 0xc0d05562
+0, 477000, 160, 0x166c590f
+0, 477900, 160, 0x3e254cc0
+0, 478800, 160, 0xd2784ab4
+0, 479700, 160, 0x9f7b4ef6
+0, 480600, 160, 0xdd7653b6
+0, 481500, 160, 0x7ae453b7
+0, 482400, 160, 0xff6c50ec
+0, 483300, 160, 0xfa0d51a9
+0, 484200, 160, 0x29ab583b
+0, 485100, 160, 0x671d5437
+0, 486000, 160, 0x6867569f
+0, 486900, 160, 0xdd775e05
+0, 487800, 160, 0xbafa65ed
+0, 488700, 160, 0xd33f5aea
+0, 489600, 160, 0x851455a8
+0, 490500, 160, 0x044c4d45
+0, 491400, 160, 0xcd7c5d84
+0, 492300, 160, 0xd6565e61
+0, 493200, 160, 0x2f345a92
+0, 494100, 160, 0x50e05530
+0, 495000, 160, 0x787f516a
+0, 495900, 160, 0x75cd5ade
+0, 496800, 160, 0x55b558ad
+0, 497700, 160, 0x55255b01
+0, 498600, 160, 0xfc5b5945
+0, 499500, 160, 0x33914e05
+0, 500400, 160, 0x1f4a5c31
+0, 501300, 160, 0x542f4bf2
+0, 502200, 160, 0xd8b2573f
+0, 503100, 160, 0x127758b0
+0, 504000, 160, 0x18dd5a30
+0, 504900, 160, 0xe8ce61c4
+0, 505800, 160, 0x9a225b47
+0, 506700, 160, 0xd4436314
+0, 507600, 160, 0x2bf06310
+0, 508500, 160, 0x0de35e82
+0, 509400, 160, 0x76cb56f2
+0, 510300, 160, 0x65bc569b
+0, 511200, 160, 0x00a45461
+0, 512100, 160, 0xb5c55019
+0, 513000, 160, 0x5eb04b4d
+0, 513900, 160, 0xf1224c39
+0, 514800, 160, 0x4d135288
+0, 515700, 160, 0x9bc34ba7
+0, 516600, 160, 0xbde3510e
+0, 517500, 160, 0xefaf4fa4
+0, 518400, 160, 0x584950e2
+0, 519300, 160, 0x1e844e27
+0, 520200, 160, 0x38634315
+0, 521100, 160, 0x6b9b4a0b
+0, 522000, 160, 0xd491512a
+0, 522900, 160, 0x8624478c
+0, 523800, 160, 0x67ab45c7
+0, 524700, 160, 0xf78e4c53
+0, 525600, 160, 0xb1654f0d
+0, 526500, 160, 0x17bb4e96
+0, 527400, 160, 0xf3165e7c
+0, 528300, 160, 0xf7914633
+0, 529200, 160, 0x3421530f
+0, 530100, 160, 0x492e572c
+0, 531000, 160, 0xa3185319
+0, 531900, 160, 0x92d054c0
+0, 532800, 160, 0x1cc24ce1
+0, 533700, 160, 0x2ebc519e
+0, 534600, 160, 0x946b53e7
+0, 535500, 160, 0xf85c4fe6
+0, 536400, 160, 0x2974534c
+0, 537300, 160, 0xef7e4a28
+0, 538200, 160, 0x01a74c6e
+0, 539100, 160, 0x2a865674
+0, 540000, 160, 0x70474faf
+0, 540900, 160, 0x2df75014
+0, 541800, 160, 0xf1f3574e
+0, 542700, 160, 0x741b5308
+0, 543600, 160, 0xcb34513e
+0, 544500, 160, 0x7b5e50c7
+0, 545400, 160, 0x0165553b
+0, 546300, 160, 0x04b85450
+0, 547200, 160, 0x795d5873
+0, 548100, 160, 0x508859fb
+0, 549000, 160, 0xca09587d
+0, 549900, 160, 0x86a65ac8
+0, 550800, 160, 0x447353fe
+0, 551700, 160, 0x48ca54a5
+0, 552600, 160, 0x1b3e5f3e
+0, 553500, 160, 0x270a5aa2
+0, 554400, 160, 0x48a45c29
+0, 555300, 160, 0xfbf75a0b
+0, 556200, 160, 0xe65161e5
+0, 557100, 160, 0xf47c6701
+0, 558000, 160, 0xc12058bc
+0, 558900, 160, 0xdb17520c
+0, 559800, 160, 0x860455bd
+0, 560700, 160, 0xa02d56de
+0, 561600, 160, 0xf5574c7d
+0, 562500, 160, 0x500e59b3
+0, 563400, 160, 0xf0b75894
+0, 564300, 160, 0x9d454a04
+0, 565200, 160, 0x0b0554a4
+0, 566100, 160, 0x3fc34d98
+0, 567000, 160, 0x538550b8
+0, 567900, 160, 0xd84e495e
+0, 568800, 160, 0x736c4e17
+0, 569700, 160, 0xa59e5607
+0, 570600, 160, 0xe7485609
+0, 571500, 160, 0x20185a67
+0, 572400, 160, 0x9aa5576f
+0, 573300, 160, 0xed8c5d11
+0, 574200, 160, 0xecef5494
+0, 575100, 160, 0x76f75a5c
+0, 576000, 160, 0xa8fa5322
+0, 576900, 160, 0xd1945734
+0, 577800, 160, 0x817f5c82
+0, 578700, 160, 0x40756063
+0, 579600, 160, 0x524454c7
+0, 580500, 160, 0x5a776106
+0, 581400, 160, 0xd16e5d9d
+0, 582300, 160, 0x8522524c
+0, 583200, 160, 0x4a115bb9
+0, 584100, 160, 0xbf5c5c27
+0, 585000, 160, 0x48905da4
+0, 585900, 160, 0x58735040
+0, 586800, 160, 0x48635631
+0, 587700, 160, 0xf1305eaf
+0, 588600, 160, 0xd34451bd
+0, 589500, 160, 0x1a244fcf
+0, 590400, 160, 0xdb995ca0
+0, 591300, 160, 0xe38e52bb
+0, 592200, 160, 0x00715069
+0, 593100, 160, 0x72a95190
+0, 594000, 160, 0xea7d50b7
+0, 594900, 160, 0xb4094a9c
+0, 595800, 160, 0xd5284d79
+0, 596700, 160, 0x3c4349e5
+0, 597600, 160, 0x65d34e92
+0, 598500, 160, 0x67805756
+0, 599400, 160, 0x1b96502f
+0, 600300, 160, 0x395250ae
+0, 601200, 160, 0x4dc74976
+0, 602100, 160, 0x2666486e
+0, 603000, 160, 0x41924d01
+0, 603900, 160, 0x94a845f5
+0, 604800, 160, 0x1b264cf9
+0, 605700, 160, 0x63ea4aab
+0, 606600, 160, 0x9c0d4a82
+0, 607500, 160, 0x02ba4cf6
+0, 608400, 160, 0x9cd54b87
+0, 609300, 160, 0x24624c5b
+0, 610200, 160, 0x14cf54b1
+0, 611100, 160, 0xce54544b
+0, 612000, 160, 0x459b4fc9
+0, 612900, 160, 0xcc2453f1
+0, 613800, 160, 0xa4ab53bc
+0, 614700, 160, 0x92235013
+0, 615600, 160, 0xbfa257b3
+0, 616500, 160, 0xd32d51f5
+0, 617400, 160, 0x7d5d47e6
+0, 618300, 160, 0xe23d43ed
+0, 619200, 160, 0x51d8514f
+0, 620100, 160, 0x0fa04240
+0, 621000, 160, 0x233c4dce
+0, 621900, 160, 0xcd30466f
+0, 622800, 160, 0x4435546a
+0, 623700, 160, 0x3eb6445b
+0, 624600, 160, 0xcaed4ef9
+0, 625500, 160, 0xf0174da8
+0, 626400, 160, 0x60e756a0
+0, 627300, 160, 0x72ba457d
+0, 628200, 160, 0x84ce4f0f
+0, 629100, 160, 0x660d45ae
+0, 630000, 160, 0xac8446e2
+0, 630900, 160, 0xeeb153b4
+0, 631800, 160, 0x6a634c23
+0, 632700, 160, 0x890f4af8
+0, 633600, 160, 0x1d3743a7
+0, 634500, 160, 0xa37e4ee8
+0, 635400, 160, 0xb9334d56
+0, 636300, 160, 0xc1384bef
+0, 637200, 160, 0x52964f6e
+0, 638100, 160, 0xe36e57e2
+0, 639000, 160, 0x62114a53
+0, 639900, 160, 0xb1f855bb
+0, 640800, 160, 0xf0934da0
+0, 641700, 160, 0xb454494a
+0, 642600, 160, 0xb6e04b15
+0, 643500, 160, 0x933e488e
+0, 644400, 160, 0x762d5ce8
+0, 645300, 160, 0x1c4a4f85
+0, 646200, 160, 0xaaa25313
+0, 647100, 160, 0xd3655979
+0, 648000, 160, 0x8ff149e5
+0, 648900, 160, 0x5d5e51fb
+0, 649800, 160, 0x0a354c51
+0, 650700, 160, 0x79ea52ee
+0, 651600, 160, 0x306e5365
+0, 652500, 160, 0x7e03546a
+0, 653400, 160, 0x71575ddf
+0, 654300, 160, 0x08da523d
+0, 655200, 160, 0x2a2152b2
+0, 656100, 160, 0x50e55447
+0, 657000, 160, 0xf3b55758
+0, 657900, 160, 0xc29d5f12
+0, 658800, 160, 0x0c0b5778
+0, 659700, 160, 0x1b07593a
+0, 660600, 160, 0x946f562d
+0, 661500, 160, 0xcdc85636
+0, 662400, 160, 0x2421589b
+0, 663300, 160, 0x8e3b5451
+0, 664200, 160, 0xd565536a
+0, 665100, 160, 0x8d225557
+0, 666000, 160, 0xa0084e44
+0, 666900, 160, 0x85bd5413
+0, 667800, 160, 0xa4be4c3b
+0, 668700, 160, 0x332957c8
+0, 669600, 160, 0x60505225
+0, 670500, 160, 0x3d154eb3
+0, 671400, 160, 0xd85359f4
+0, 672300, 160, 0xf95b4f6b
+0, 673200, 160, 0x8bea5846
+0, 674100, 160, 0x43835a02
+0, 675000, 160, 0x340b5732
+0, 675900, 160, 0x8b6d5005
+0, 676800, 160, 0xa4995aca
+0, 677700, 160, 0x88d34efc
+0, 678600, 160, 0x078e5003
+0, 679500, 160, 0x09964b19
+0, 680400, 160, 0x2eaf5120
+0, 681300, 160, 0x52514d52
+0, 682200, 160, 0x08f84d4c
+0, 683100, 160, 0x4a9b4cc7
+0, 684000, 160, 0x947f4ca6
+0, 684900, 160, 0x086a4f32
+0, 685800, 160, 0x0e0857a6
+0, 686700, 160, 0x38145bf7
+0, 687600, 160, 0xc6e156bf
+0, 688500, 160, 0xb07853b2
+0, 689400, 160, 0xaeda5172
+0, 690300, 160, 0xc4e54d07
+0, 691200, 160, 0x0b075a61
+0, 692100, 160, 0x09f05c1f
+0, 693000, 160, 0xf5415796
+0, 693900, 160, 0xe3be584e
+0, 694800, 160, 0x6e1656f9
+0, 695700, 160, 0xd6d85599
+0, 696600, 160, 0xd9b4502e
+0, 697500, 160, 0x1186598c
+0, 698400, 160, 0x879c543d
+0, 699300, 160, 0x5b2551a3
+0, 700200, 160, 0xcf50528d
+0, 701100, 160, 0x95d059b2
+0, 702000, 160, 0x34ba5515
+0, 702900, 160, 0x7a014ba8
+0, 703800, 160, 0x27725169
+0, 704700, 160, 0x2fd14ca4
+0, 705600, 160, 0xd5ad542a
+0, 706500, 160, 0xddc24d2e
+0, 707400, 160, 0x8a4b48b4
+0, 708300, 160, 0x915e4a29
+0, 709200, 160, 0xd56d4cae
+0, 710100, 160, 0x59594eea
+0, 711000, 160, 0x87085338
+0, 711900, 160, 0xa5ee538f
+0, 712800, 160, 0xf34e5030
+0, 713700, 160, 0x6bef4da7
+0, 714600, 160, 0x05a14c52
+0, 715500, 160, 0x67bc49ce
+0, 716400, 160, 0xb18f4cff
+0, 717300, 160, 0x5d744e6d
+0, 718200, 160, 0xcb7c5973
+0, 719100, 160, 0x6df056f0
+0, 720000, 160, 0xd62c4e00
+0, 720900, 160, 0xa54d4d1e
+0, 721800, 160, 0xdaa250b0
+0, 722700, 160, 0x350e475f
+0, 723600, 160, 0x0e454bb2
+0, 724500, 160, 0xe37949ca
+0, 725400, 160, 0x551453bf
+0, 726300, 160, 0x35d04c27
+0, 727200, 160, 0x6749469d
+0, 728100, 160, 0x544752e9
+0, 729000, 160, 0xf23b4888
+0, 729900, 160, 0x6f0a5519
+0, 730800, 160, 0x808a58df
+0, 731700, 160, 0x8e674c88
+0, 732600, 160, 0xd3ab51f7
+0, 733500, 160, 0x985d500f
+0, 734400, 160, 0x734e52d8
+0, 735300, 160, 0xb0da5227
+0, 736200, 160, 0xcc7d4a21
+0, 737100, 160, 0xb1354baf
+0, 738000, 160, 0xfc8d4f9a
+0, 738900, 160, 0x6f044d82
+0, 739800, 160, 0x41e7546b
+0, 740700, 160, 0x67014682
+0, 741600, 160, 0x5516575b
+0, 742500, 160, 0x26254693
+0, 743400, 160, 0x81ce4af5
+0, 744300, 160, 0x77f152a0
+0, 745200, 160, 0x995a5096
+0, 746100, 160, 0x6114532e
+0, 747000, 160, 0x4df457f3
+0, 747900, 160, 0xbcd94804
+0, 748800, 160, 0x1e544fd2
+0, 749700, 160, 0xa70b5954
+0, 750600, 160, 0x1c77484c
+0, 751500, 160, 0xb07f4c42
+0, 752400, 160, 0x62074f1f
+0, 753300, 160, 0xf3b656a1
+0, 754200, 160, 0x65734ac0
+0, 755100, 160, 0x2a9752cd
+0, 756000, 160, 0x15ff4ef0
+0, 756900, 160, 0xabd4532c
+0, 757800, 160, 0x8a44503a
+0, 758700, 160, 0xbf4250f3
+0, 759600, 160, 0x17594ac5
+0, 760500, 160, 0x7b5e4b24
+0, 761400, 160, 0x24684cb5
+0, 762300, 160, 0xc4d54b42
+0, 763200, 160, 0xd48f58af
+0, 764100, 160, 0x0374593a
+0, 765000, 160, 0x398a5b0d
+0, 765900, 160, 0xf60855e6
+0, 766800, 160, 0x6fbb5587
+0, 767700, 160, 0x44405c2b
+0, 768600, 160, 0xa6345d70
+0, 769500, 160, 0x464557d5
+0, 770400, 160, 0x0c3153ca
+0, 771300, 160, 0x15ec50c4
+0, 772200, 160, 0xd5e559da
+0, 773100, 160, 0x999757b9
+0, 774000, 160, 0x7a5d5754
+0, 774900, 160, 0xf85b5f18
+0, 775800, 160, 0xa66d5c72
+0, 776700, 160, 0xd8f55981
+0, 777600, 160, 0xe6364f64
+0, 778500, 160, 0x528a5785
+0, 779400, 160, 0xdefe5332
+0, 780300, 160, 0x4bc4532e
+0, 781200, 160, 0x505a4eb3
+0, 782100, 160, 0xa28d589d
+0, 783000, 160, 0x092d511f
+0, 783900, 160, 0x3079591e
+0, 784800, 160, 0x2b1d5339
+0, 785700, 160, 0xf8d849d1
+0, 786600, 160, 0xadb056a6
+0, 787500, 160, 0x2ee74c4f
+0, 788400, 160, 0x35c34c9f
+0, 789300, 160, 0xb6ae53d3
+0, 790200, 160, 0x7258534e
+0, 791100, 160, 0xb76d4b1b
+0, 792000, 160, 0x99a14a0f
+0, 792900, 160, 0x88365944
+0, 793800, 160, 0x97cf4aed
+0, 794700, 160, 0x444b56f6
+0, 795600, 160, 0x1d1f4b01
+0, 796500, 160, 0x3dcd417e
+0, 797400, 160, 0xa4985140
+0, 798300, 160, 0x86f94c4d
+0, 799200, 160, 0xc3635436
+0, 800100, 160, 0x198b432b
+0, 801000, 160, 0xae5253e4
+0, 801900, 160, 0x248c4f1a
+0, 802800, 160, 0x787a45df
+0, 803700, 160, 0x5fd44cad
+0, 804600, 160, 0x68be581c
+0, 805500, 160, 0x5ff5531b
+0, 806400, 160, 0x2bcd4aa1
+0, 807300, 160, 0x0d134a7c
+0, 808200, 160, 0x28af5885
+0, 809100, 160, 0xc09f4d65
+0, 810000, 160, 0x7468552d
+0, 810900, 160, 0x82df49ac
+0, 811800, 160, 0xe3725fdc
+0, 812700, 160, 0x0ec74d11
+0, 813600, 160, 0xfc2a5355
+0, 814500, 160, 0x41df4d4f
+0, 815400, 160, 0x4ebe473d
+0, 816300, 160, 0xd8734bf2
+0, 817200, 160, 0x4acd5056
+0, 818100, 160, 0x47805700
+0, 819000, 160, 0xe4f25135
+0, 819900, 160, 0x9f195649
+0, 820800, 160, 0x8b055f64
+0, 821700, 160, 0xc4b751c8
+0, 822600, 160, 0x95e55ba4
+0, 823500, 160, 0xf0955494
+0, 824400, 160, 0xca1a47b9
+0, 825300, 160, 0x9d025711
+0, 826200, 160, 0xf6cb4a0a
+0, 827100, 160, 0xd8385b4d
+0, 828000, 160, 0x7b2852b6
+0, 828900, 160, 0x90a35643
+0, 829800, 160, 0x63105d0a
+0, 830700, 160, 0x55414083
+0, 831600, 160, 0xc94554a9
+0, 832500, 160, 0xa88f4a36
+0, 833400, 160, 0xda5d52bc
+0, 834300, 160, 0x5b3943da
+0, 835200, 160, 0xd2314755
+0, 836100, 160, 0x743c4cdc
+0, 837000, 160, 0x7c3e4dc2
+0, 837900, 160, 0x12644715
+0, 838800, 160, 0x1050480b
+0, 839700, 160, 0x73645906
+0, 840600, 160, 0x28ef4a9e
+0, 841500, 160, 0xf72440bc
+0, 842400, 160, 0x41964bda
+0, 843300, 160, 0x2afb4d9b
+0, 844200, 160, 0xf74b4c5a
+0, 845100, 160, 0xcf165e2e
+0, 846000, 160, 0x3dbb4d06
+0, 846900, 160, 0xbd9755f9
+0, 847800, 160, 0x3248581d
+0, 848700, 160, 0xc00c559d
+0, 849600, 160, 0xff6c4b0a
+0, 850500, 160, 0x154157e3
+0, 851400, 160, 0xb996499c
+0, 852300, 160, 0xe1a059ba
+0, 853200, 160, 0x98015946
+0, 854100, 160, 0x168b4ceb
+0, 855000, 160, 0x567b4f83
+0, 855900, 160, 0x903e52f8
+0, 856800, 160, 0xc0a252dc
+0, 857700, 160, 0x08cb4b70
+0, 858600, 160, 0x3d9a5be6
+0, 859500, 160, 0x904b4907
+0, 860400, 160, 0x738847b1
+0, 861300, 160, 0x10405c19
+0, 862200, 160, 0x8c134f27
+0, 863100, 160, 0xdfe34d7f
+0, 864000, 160, 0x9d0948a8
+0, 864900, 160, 0x67755611
+0, 865800, 160, 0x46734258
+0, 866700, 160, 0x76f449fa
+0, 867600, 160, 0xfad64d30
+0, 868500, 160, 0x7f4357f4
+0, 869400, 160, 0xd20e5079
+0, 870300, 160, 0xdf7857ec
+0, 871200, 160, 0x46ff4891
+0, 872100, 160, 0x1b724ffc
+0, 873000, 160, 0xdf20545a
+0, 873900, 160, 0xeb5254e0
+0, 874800, 160, 0x794b4a96
+0, 875700, 160, 0x86a15147
+0, 876600, 160, 0x30f75504
+0, 877500, 160, 0x39575354
+0, 878400, 160, 0xb6a35351
+0, 879300, 160, 0x9da34c3a
+0, 880200, 160, 0xcf2d5386
+0, 881100, 160, 0xa7f353f6
+0, 882000, 160, 0xa6e34e95
+0, 882900, 160, 0x98174400
+0, 883800, 160, 0x13685641
+0, 884700, 160, 0x99215154
+0, 885600, 160, 0x5be75237
+0, 886500, 160, 0x4cb64942
+0, 887400, 160, 0x15de4e03
+0, 888300, 160, 0x613a4fd5
+0, 889200, 160, 0xc97c4821
+0, 890100, 160, 0xbf1558f2
+0, 891000, 160, 0x651d4cf4
+0, 891900, 160, 0xbee44a56
+0, 892800, 160, 0x6cbd4c20
+0, 893700, 160, 0xcf45493d
+0, 894600, 160, 0x73e74d2a
+0, 895500, 160, 0x6a3256e4
+0, 896400, 160, 0x89ac4a68
+0, 897300, 160, 0x0d2652aa
+0, 898200, 160, 0x56ce4b78
+0, 899100, 160, 0xb7b24bcb
diff --git a/tests/ref/fate/h264-conformance-frext-hi422fr10_sony_b b/tests/ref/fate/h264-conformance-frext-hi422fr10_sony_b
new file mode 100644
index 0000000000..60c65e8da4
--- /dev/null
+++ b/tests/ref/fate/h264-conformance-frext-hi422fr10_sony_b
@@ -0,0 +1,5 @@
+0, 0, 202752, 0xffa1c502
+0, 3600, 202752, 0x51752f3c
+0, 7200, 202752, 0xe683991d
+0, 10800, 202752, 0xf70200a4
+0, 14400, 202752, 0x1a4d63ef
diff --git a/tests/ref/fate/h264-conformance-frext-hi422fr13_sony_b b/tests/ref/fate/h264-conformance-frext-hi422fr13_sony_b
new file mode 100644
index 0000000000..befd8f476d
--- /dev/null
+++ b/tests/ref/fate/h264-conformance-frext-hi422fr13_sony_b
@@ -0,0 +1,5 @@
+0, 0, 405504, 0xe0f40e71
+0, 3600, 405504, 0x9bdb5900
+0, 7200, 405504, 0x527003ca
+0, 10800, 405504, 0x1fbf8ba6
+0, 14400, 405504, 0x455e2a4e
diff --git a/tests/ref/fate/h264-conformance-frext-hi422fr1_sony_a b/tests/ref/fate/h264-conformance-frext-hi422fr1_sony_a
new file mode 100644
index 0000000000..b454a07f61
--- /dev/null
+++ b/tests/ref/fate/h264-conformance-frext-hi422fr1_sony_a
@@ -0,0 +1,5 @@
+0, 0, 202752, 0xd5a1e49f
+0, 3600, 202752, 0x08352d61
+0, 7200, 202752, 0x43f78f47
+0, 10800, 202752, 0xfb5910f4
+0, 14400, 202752, 0xd98e8739
diff --git a/tests/ref/fate/h264-conformance-frext-hi422fr6_sony_a b/tests/ref/fate/h264-conformance-frext-hi422fr6_sony_a
new file mode 100644
index 0000000000..453e7598c3
--- /dev/null
+++ b/tests/ref/fate/h264-conformance-frext-hi422fr6_sony_a
@@ -0,0 +1,5 @@
+0, 0, 405504, 0x049ab58e
+0, 3600, 405504, 0x4f6226cb
+0, 7200, 405504, 0xaa5fcb44
+0, 10800, 405504, 0xbfc09965
+0, 14400, 405504, 0xa30acb90
diff --git a/tests/ref/fate/h264-conformance-frext-pph422i1_panasonic_a b/tests/ref/fate/h264-conformance-frext-pph422i1_panasonic_a
new file mode 100644
index 0000000000..3b8a839507
--- /dev/null
+++ b/tests/ref/fate/h264-conformance-frext-pph422i1_panasonic_a
@@ -0,0 +1,10 @@
+0, 0, 3686400, 0x1f9b5bee
+0, 3600, 3686400, 0x657c3609
+0, 7200, 3686400, 0x75753934
+0, 10800, 3686400, 0xf434d8e1
+0, 14400, 3686400, 0x40679c77
+0, 18000, 3686400, 0x5734d8db
+0, 21600, 3686400, 0x4a3d8269
+0, 25200, 3686400, 0xd20b6cf6
+0, 28800, 3686400, 0x31956bca
+0, 32400, 3686400, 0xd28d9758
diff --git a/tests/ref/fate/h264-conformance-frext-pph422i2_panasonic_a b/tests/ref/fate/h264-conformance-frext-pph422i2_panasonic_a
new file mode 100644
index 0000000000..012250ef3d
--- /dev/null
+++ b/tests/ref/fate/h264-conformance-frext-pph422i2_panasonic_a
@@ -0,0 +1,10 @@
+0, 0, 3686400, 0x8b3ff360
+0, 3600, 3686400, 0x422dead1
+0, 7200, 3686400, 0xbdd0e431
+0, 10800, 3686400, 0x1e3cc216
+0, 14400, 3686400, 0x1a80b718
+0, 18000, 3686400, 0xc7e3c0a2
+0, 21600, 3686400, 0xffc99142
+0, 25200, 3686400, 0x8b3bdf1e
+0, 28800, 3686400, 0xff1bccfb
+0, 32400, 3686400, 0x781fc45b
diff --git a/tests/ref/fate/h264-conformance-frext-pph422i3_panasonic_a b/tests/ref/fate/h264-conformance-frext-pph422i3_panasonic_a
new file mode 100644
index 0000000000..253c9920ab
--- /dev/null
+++ b/tests/ref/fate/h264-conformance-frext-pph422i3_panasonic_a
@@ -0,0 +1,10 @@
+0, 0, 3686400, 0x97c36ae3
+0, 3600, 3686400, 0x6a0aa629
+0, 7200, 3686400, 0xc658d722
+0, 10800, 3686400, 0x713bc774
+0, 14400, 3686400, 0x8d0b3afe
+0, 18000, 3686400, 0x62bf24cd
+0, 21600, 3686400, 0x77e80436
+0, 25200, 3686400, 0x4f258e07
+0, 28800, 3686400, 0x8426bc53
+0, 32400, 3686400, 0xd33b58c8
diff --git a/tests/ref/fate/h264-conformance-frext-pph422i4_panasonic_a b/tests/ref/fate/h264-conformance-frext-pph422i4_panasonic_a
new file mode 100644
index 0000000000..97e36e74a9
--- /dev/null
+++ b/tests/ref/fate/h264-conformance-frext-pph422i4_panasonic_a
@@ -0,0 +1,10 @@
+0, 0, 8294400, 0xf50992f3
+0, 3600, 8294400, 0xd34cdf98
+0, 7200, 8294400, 0x76bced00
+0, 10800, 8294400, 0xf9ffd9b1
+0, 14400, 8294400, 0x303231aa
+0, 18000, 8294400, 0x0ca57c6a
+0, 21600, 8294400, 0xaa056bd5
+0, 25200, 8294400, 0x785c9a12
+0, 28800, 8294400, 0xe535750e
+0, 32400, 8294400, 0x78fd76bb
diff --git a/tests/ref/fate/h264-conformance-frext-pph422i5_panasonic_a b/tests/ref/fate/h264-conformance-frext-pph422i5_panasonic_a
new file mode 100644
index 0000000000..c9c557e24c
--- /dev/null
+++ b/tests/ref/fate/h264-conformance-frext-pph422i5_panasonic_a
@@ -0,0 +1,10 @@
+0, 0, 8294400, 0x96d051a1
+0, 3600, 8294400, 0xf3c2974e
+0, 7200, 8294400, 0xb18f3ed0
+0, 10800, 8294400, 0xb5ba9998
+0, 14400, 8294400, 0x96327a34
+0, 18000, 8294400, 0xe24d7b61
+0, 21600, 8294400, 0xc45d5a16
+0, 25200, 8294400, 0x13b4a537
+0, 28800, 8294400, 0xa81dae90
+0, 32400, 8294400, 0x2820bbe9
diff --git a/tests/ref/fate/h264-conformance-frext-pph422i6_panasonic_a b/tests/ref/fate/h264-conformance-frext-pph422i6_panasonic_a
new file mode 100644
index 0000000000..ecbcdc5fe9
--- /dev/null
+++ b/tests/ref/fate/h264-conformance-frext-pph422i6_panasonic_a
@@ -0,0 +1,10 @@
+0, 0, 8294400, 0x1b2f1079
+0, 3600, 8294400, 0x6646f91c
+0, 7200, 8294400, 0x17dc9f51
+0, 10800, 8294400, 0x4aad9b3a
+0, 14400, 8294400, 0x8a422d34
+0, 18000, 8294400, 0x8fd76d87
+0, 21600, 8294400, 0xc7c75f18
+0, 25200, 8294400, 0x4a1c2643
+0, 28800, 8294400, 0xfe225709
+0, 32400, 8294400, 0x032ad2e5
diff --git a/tests/ref/fate/h264-conformance-frext-pph422i7_panasonic_a b/tests/ref/fate/h264-conformance-frext-pph422i7_panasonic_a
new file mode 100644
index 0000000000..76177764bd
--- /dev/null
+++ b/tests/ref/fate/h264-conformance-frext-pph422i7_panasonic_a
@@ -0,0 +1,10 @@
+0, 0, 8294400, 0xaa37ceea
+0, 3600, 8294400, 0xa7546d5c
+0, 7200, 8294400, 0xf2abaace
+0, 10800, 8294400, 0x36f4d47e
+0, 14400, 8294400, 0x1cdf917d
+0, 18000, 8294400, 0xa9377ba3
+0, 21600, 8294400, 0x21c9db51
+0, 25200, 8294400, 0x07d7936e
+0, 28800, 8294400, 0x7878ab94
+0, 32400, 8294400, 0x77e40921
diff --git a/tests/ref/fate/iff-fibonacci b/tests/ref/fate/iff-fibonacci
index e452f31e6c..947f78e964 100644
--- a/tests/ref/fate/iff-fibonacci
+++ b/tests/ref/fate/iff-fibonacci
@@ -1 +1 @@
-e968a853779bb6438339e3b8d69d8d24
+e76b025238a6a27968f8644f4ccc3207
diff --git a/tests/ref/fate/lmlm4-demux b/tests/ref/fate/lmlm4-demux
index f322300eee..f3214234d7 100644
--- a/tests/ref/fate/lmlm4-demux
+++ b/tests/ref/fate/lmlm4-demux
@@ -213,335 +213,3 @@
1, 265680, 768, 0xfd6c7597
0, 267267, 1327, 0x7d15307c
1, 267840, 768, 0x8d766d40
-0, 270270, 1225, 0x1b5d0f5f
-0, 273273, 1173, 0x840efed5
-0, 276276, 1215, 0xa8e0035e
-0, 279279, 1295, 0x142918ca
-0, 282282, 1144, 0xf50cef50
-0, 285285, 1527, 0x7d13bd9d
-0, 288288, 5609, 0x1ae1921d
-0, 291291, 1303, 0xabdc264f
-0, 294294, 1419, 0x878169bf
-0, 297297, 972, 0x00c4a257
-0, 300300, 1277, 0x87d520cf
-0, 303303, 1014, 0x5946b4ee
-0, 306306, 1177, 0x124e0e23
-0, 309309, 1402, 0x8e6363cc
-0, 312312, 1171, 0x9bdaeda2
-0, 315315, 1389, 0x2db53b22
-0, 318318, 1056, 0xd1c3de3e
-0, 321321, 1320, 0x1ea142c7
-0, 324324, 1250, 0x33612229
-0, 327327, 1477, 0xb9648b48
-0, 330330, 1522, 0x5352c318
-0, 333333, 1391, 0x5e9157e0
-0, 336336, 5545, 0x569e64c1
-0, 339339, 1354, 0xdb39469e
-0, 342342, 1302, 0x79912b5d
-0, 345345, 1065, 0x4befcdd2
-0, 348348, 1408, 0x7d2f65a2
-0, 351351, 1727, 0x9cac0398
-0, 354354, 1590, 0xa321b563
-0, 357357, 1039, 0xfa35cabf
-0, 360360, 1184, 0xb332fde7
-0, 363363, 669, 0xb10e3783
-0, 366366, 784, 0x57275e09
-0, 369369, 1051, 0xe072cd33
-0, 372372, 1119, 0x635ee9ee
-0, 375375, 1147, 0x3916f981
-0, 378378, 1086, 0x306ef895
-0, 381381, 827, 0x213f7aef
-0, 384384, 5525, 0x19157827
-0, 387387, 1044, 0xb661abc5
-0, 390390, 1143, 0x032e1109
-0, 393393, 1460, 0x5a2f9503
-0, 396396, 1178, 0xd038141f
-0, 399399, 1004, 0x410ec3b2
-0, 402402, 1089, 0xc89af8c9
-0, 405405, 1367, 0x52085e0a
-0, 408408, 1115, 0x8bb2ee7f
-0, 411411, 1325, 0xc2e05647
-0, 414414, 1295, 0x213951c9
-0, 417417, 1054, 0xbb8bdaae
-0, 420420, 1210, 0x431122bd
-0, 423423, 1400, 0x47526fcc
-0, 426426, 1188, 0x19770b07
-0, 429429, 1301, 0x437161c8
-0, 432432, 5281, 0xc0c92b55
-0, 435435, 840, 0x67da7b2f
-0, 438438, 1094, 0x3fd6d944
-0, 441441, 832, 0x0eda74bc
-0, 444444, 1096, 0x3300da7b
-0, 447447, 1018, 0xa208c971
-0, 450450, 1389, 0x1167724c
-0, 453453, 1411, 0xe3be666b
-0, 456456, 1294, 0xa8f35cc6
-0, 459459, 1232, 0xfd0d20fd
-0, 462462, 1252, 0xadd83a26
-0, 465465, 844, 0xcbaf6a55
-0, 468468, 979, 0x78d9b241
-0, 471471, 1057, 0x6743e16c
-0, 474474, 776, 0xfedd6615
-0, 477477, 1158, 0xa39fee34
-0, 480480, 5288, 0x5f26ee02
-0, 483483, 1029, 0xa681bee8
-0, 486486, 1106, 0xa68dea33
-0, 489489, 844, 0x42fd83ec
-0, 492492, 779, 0xb5006759
-0, 495495, 951, 0xec13af4f
-0, 498498, 1011, 0x90e5c86e
-0, 501501, 892, 0x4db48ca4
-0, 504504, 804, 0x59bf73a7
-0, 507507, 1001, 0x10c2b3ff
-0, 510510, 879, 0x65c57eaf
-0, 513513, 1320, 0x80815836
-0, 516516, 1448, 0xaf457b3b
-0, 519519, 1168, 0x65b9f96a
-0, 522522, 1002, 0x053fafb9
-0, 525525, 1101, 0x2d30c3d5
-0, 528528, 5314, 0x87cee383
-0, 531531, 1305, 0xb19035db
-0, 534534, 1240, 0xdc6a0a65
-0, 537537, 1067, 0x9c88ba67
-0, 540540, 823, 0x2f736a43
-0, 543543, 1183, 0x2ef9f3c9
-0, 546546, 899, 0x3fcc8d11
-0, 549549, 886, 0xccec8d49
-0, 552552, 1190, 0x2d020fa1
-0, 555555, 1017, 0x0776b627
-0, 558558, 1202, 0xbdd808d5
-0, 561561, 998, 0x64c7c246
-0, 564564, 1200, 0x9d6e2289
-0, 567567, 895, 0xa8a68d80
-0, 570570, 748, 0xe61a49fb
-0, 573573, 929, 0x30168b50
-0, 576576, 5276, 0xceb2edf2
-0, 579579, 1127, 0xab43ddc3
-0, 582582, 1028, 0xaacfbff5
-0, 585585, 914, 0xb63c8fb0
-0, 588588, 1067, 0xbdacd1ed
-0, 591591, 1109, 0x6792ddec
-0, 594594, 1310, 0x71bc4da2
-0, 597597, 1098, 0xc464de9b
-0, 600600, 1018, 0x6833b875
-0, 603603, 1210, 0x44faf34b
-0, 606606, 1200, 0x9ee816f6
-0, 609609, 1461, 0xc76b7d2b
-0, 612612, 829, 0x006677e6
-0, 615615, 1145, 0xc769fb13
-0, 618618, 1292, 0xb63225f5
-0, 621621, 1252, 0x0e2a2626
-0, 624624, 5257, 0x3877eca1
-0, 627627, 952, 0x7f708d25
-0, 630630, 1125, 0x140cd81b
-0, 633633, 1095, 0x3025dade
-0, 636636, 1388, 0xd7494d4e
-0, 639639, 1124, 0x0c48ee92
-0, 642642, 1556, 0xa0749ee2
-0, 645645, 1461, 0xe5fd7d7f
-0, 648648, 903, 0x07a58303
-0, 651651, 1049, 0x4b6cd03b
-0, 654654, 1044, 0x5f47cb48
-0, 657657, 1253, 0xba281c6a
-0, 660660, 1618, 0xed7cd040
-0, 663663, 981, 0x2926b6f4
-0, 666666, 1560, 0xa0e1ab73
-0, 669669, 1479, 0x41a77e88
-0, 672672, 5222, 0xc2dbd182
-0, 675675, 925, 0x967580dd
-0, 678678, 1284, 0x5b7822e0
-0, 681681, 1512, 0xe84da1e0
-0, 684684, 1514, 0xc38bb09e
-0, 687687, 1224, 0x8752228e
-0, 690690, 1296, 0xcf053c03
-0, 693693, 1117, 0x9a81e659
-0, 696696, 1090, 0x003ed687
-0, 699699, 1196, 0x3a510937
-0, 702702, 1075, 0x05eec8d4
-0, 705705, 1048, 0x3b19cb96
-0, 708708, 944, 0xaad89770
-0, 711711, 960, 0x94649e4c
-0, 714714, 1079, 0x530ddaba
-0, 717717, 1150, 0x0339e696
-0, 720720, 5189, 0xb8dac0bf
-0, 723723, 1129, 0x3b2cd64d
-0, 726726, 962, 0xe9df9a07
-0, 729729, 1113, 0xc6ccddb2
-0, 732732, 1069, 0xf589d4a4
-0, 735735, 889, 0x5f7b8762
-0, 738738, 863, 0xe9c36be4
-0, 741741, 1021, 0xcfb5a737
-0, 744744, 1048, 0x203ac9ff
-0, 747747, 1223, 0x3e30fe35
-0, 750750, 814, 0x59c076fc
-0, 753753, 1157, 0x0dcf0bd0
-0, 756756, 1691, 0xdd030547
-0, 759759, 1700, 0x7641fb7e
-0, 762762, 1791, 0x57ac147b
-0, 765765, 2008, 0x3d4483ca
-0, 768768, 4579, 0x874aa75b
-0, 771771, 1647, 0xeddef621
-0, 774774, 1999, 0x61d4a23a
-0, 777777, 1572, 0x1c3ae6e1
-0, 780780, 1803, 0xb31c3a11
-0, 783783, 1919, 0xccbf64e3
-0, 786786, 1720, 0xa4d010e5
-0, 789789, 1721, 0x87ee0c7b
-0, 792792, 1626, 0x8211f3d0
-0, 795795, 1675, 0xef8a0b3d
-0, 798798, 1609, 0x8731ce06
-0, 801801, 1691, 0xcf24038b
-0, 804804, 1637, 0x21d8e1b2
-0, 807807, 1546, 0xc597a700
-0, 810810, 1518, 0xb944bc11
-0, 813813, 1403, 0x999e59a8
-0, 816816, 2467, 0xe69f2507
-0, 819819, 531, 0x3c7cea7e
-0, 822822, 555, 0xdf20fb22
-0, 825825, 500, 0xebeee00d
-0, 828828, 446, 0x664cc711
-0, 831831, 521, 0xf223df4b
-0, 834834, 559, 0x4dc60028
-0, 837837, 593, 0xec440ba9
-0, 840840, 557, 0xef0100b1
-0, 843843, 602, 0x7b1cfd88
-0, 846846, 566, 0x77700a1d
-0, 849849, 523, 0x3df7eb64
-0, 852852, 482, 0x5da1dba9
-0, 855855, 541, 0x9c8ff3d7
-0, 858858, 572, 0x3e1204b2
-0, 861861, 549, 0x0921fe3d
-0, 864864, 2429, 0xba4fe5a8
-0, 867867, 495, 0xc35ade54
-0, 870870, 453, 0xcc66c9dc
-0, 873873, 421, 0x3aa7ce8f
-0, 876876, 448, 0x56c6d3d7
-0, 879879, 478, 0x4131d467
-0, 882882, 497, 0xac3ce3ca
-0, 885885, 470, 0x41b9d9d3
-0, 888888, 454, 0x44c2d956
-0, 891891, 460, 0x6629db01
-0, 894894, 488, 0x6be2dd68
-0, 897897, 512, 0xda4cf116
-0, 900900, 550, 0x6e990da9
-0, 903903, 561, 0x81180e5e
-0, 906906, 689, 0xe58a5a9a
-0, 909909, 548, 0xfa1417a9
-0, 912912, 2832, 0x942495a5
-0, 915915, 610, 0x6b201ab9
-0, 918918, 1015, 0x5f36b3f9
-0, 921921, 870, 0x14e48f0c
-0, 924924, 716, 0xf4034b52
-0, 927927, 763, 0xcbf4694e
-0, 930930, 778, 0xb9396764
-0, 933933, 831, 0x31999005
-0, 936936, 877, 0xc95e977f
-0, 939939, 836, 0xb56c7d61
-0, 942942, 853, 0x2d5980cf
-0, 945945, 861, 0x25629295
-0, 948948, 897, 0x0ff78a5f
-0, 951951, 1016, 0x4dd8cdfd
-0, 954954, 1117, 0x763f06c4
-0, 957957, 984, 0xcf7bc906
-0, 960960, 2750, 0xd428962d
-0, 963963, 995, 0x5cbdd6a4
-0, 966966, 894, 0xc42b9e25
-0, 969969, 1028, 0xdf8ad906
-0, 972972, 1059, 0x4c49f0cc
-0, 975975, 1122, 0x8880eed8
-0, 978978, 1007, 0xa9b4c243
-0, 981981, 1055, 0x6051dcd6
-0, 984984, 1293, 0xc3b32fa5
-0, 987987, 1101, 0xf986f9af
-0, 990990, 1272, 0x13883127
-0, 993993, 1037, 0xb97cebff
-0, 996996, 980, 0x0931d807
-0, 999999, 928, 0xbc3eb30b
-0, 1003002, 1068, 0x62d9e8de
-0, 1006005, 852, 0x9278a49a
-0, 1009008, 2841, 0x3091d12d
-0, 1012011, 931, 0x60f6c26e
-0, 1015014, 949, 0x31b9c856
-0, 1018017, 835, 0xfe018775
-0, 1021020, 779, 0x85356cd7
-0, 1024023, 748, 0x862756bf
-0, 1027026, 768, 0x0b7d645c
-0, 1030029, 786, 0x7c196f5b
-0, 1033032, 716, 0x4e8252cc
-0, 1036035, 671, 0x0b2d3023
-0, 1039038, 708, 0x3b2b4f25
-0, 1042041, 786, 0x523d670e
-0, 1045044, 680, 0x329142ec
-0, 1048047, 703, 0x841b456c
-0, 1051050, 660, 0x5cf332f1
-0, 1054053, 681, 0xcd7b3915
-0, 1057056, 2445, 0x27660ecb
-0, 1060059, 667, 0xf3d53d2a
-0, 1063062, 652, 0xe2b037b0
-0, 1066065, 695, 0x200248fc
-0, 1069068, 659, 0x7f6434c5
-0, 1072071, 682, 0x8d243afb
-0, 1075074, 701, 0x16e6476f
-0, 1078077, 636, 0x319a3236
-0, 1081080, 679, 0x81fa41f9
-0, 1084083, 740, 0xb32850af
-0, 1087086, 694, 0xe3f832c2
-0, 1090089, 681, 0x8174353f
-0, 1093092, 757, 0xebbe5a1f
-0, 1096095, 683, 0x9b46383c
-0, 1099098, 816, 0xd41e6bdf
-0, 1102101, 1058, 0x6170d2e6
-0, 1105104, 2489, 0x58fb28e1
-0, 1108107, 804, 0xb3037da8
-0, 1111110, 1053, 0x81ffc0a8
-0, 1114113, 868, 0xf73583cb
-0, 1117116, 875, 0xfa5d85bd
-0, 1120119, 723, 0x0714418d
-0, 1123122, 670, 0xd04333a1
-0, 1126125, 854, 0x370e730d
-0, 1129128, 794, 0x3d8a5e3c
-0, 1132131, 836, 0xebe26aa7
-0, 1135134, 871, 0x1da58c5e
-0, 1138137, 827, 0xda1e6ccb
-0, 1141140, 805, 0x10ad6a44
-0, 1144143, 831, 0x826f6fc9
-0, 1147146, 832, 0xb2517364
-0, 1150149, 887, 0x11bf8a3f
-0, 1153152, 2718, 0x26a8a174
-0, 1156155, 805, 0x4d0179f9
-0, 1159158, 699, 0x176c4f45
-0, 1162161, 758, 0xc1fc5b16
-0, 1165164, 707, 0x161b4891
-0, 1168167, 733, 0x99b554c0
-0, 1171170, 671, 0xccee2f89
-0, 1174173, 762, 0xd6416c9d
-0, 1177176, 721, 0x2ad94f0c
-0, 1180179, 727, 0x6280572e
-0, 1183182, 856, 0x0a7b797e
-0, 1186185, 843, 0xc64288aa
-0, 1189188, 877, 0x6d1c945d
-0, 1192191, 780, 0x4ba464e8
-0, 1195194, 808, 0xb3087cca
-0, 1198197, 870, 0x75809930
-0, 1201200, 2919, 0x5a80f685
-0, 1204203, 1027, 0xc98add3d
-0, 1207206, 1003, 0x0d88bd54
-0, 1210209, 1189, 0xb2f91ec7
-0, 1213212, 1320, 0x5acc4db3
-0, 1216215, 1381, 0xbd585feb
-0, 1219218, 1378, 0xe1a656f0
-0, 1222221, 1398, 0x88b57a5e
-0, 1225224, 1449, 0x1c737698
-0, 1228227, 1420, 0x6f0f80cd
-0, 1231230, 1032, 0x2d16d643
-0, 1234233, 1275, 0x38844729
-0, 1237236, 1112, 0x300207ea
-0, 1240239, 1105, 0xa2b700be
-0, 1243242, 1283, 0x08d04bef
-0, 1246245, 1056, 0xf795d994
-0, 1249248, 3202, 0xebf07050
-0, 1252251, 1034, 0x1099dbe5
-0, 1255254, 922, 0x88be9edc
-0, 1258257, 1050, 0xd3d7eb96
-0, 1261260, 979, 0x8de6b302
-0, 1264263, 1053, 0x5de2eca8
diff --git a/tests/ref/fate/lossless-shortenaudio b/tests/ref/fate/lossless-shortenaudio
index 9448052733..9cdb3690e3 100644
--- a/tests/ref/fate/lossless-shortenaudio
+++ b/tests/ref/fate/lossless-shortenaudio
@@ -1 +1 @@
-9949141c405524f37ef1058b1ef4114b
+da93c50961443b88fce416ae61c8ca8a
diff --git a/tests/ref/fate/motionpixels b/tests/ref/fate/motionpixels
index e588ed3e18..fa86f7379f 100644
--- a/tests/ref/fate/motionpixels
+++ b/tests/ref/fate/motionpixels
@@ -109,4 +109,3 @@
0, 648003, 230400, 0xb343f372
0, 654003, 230400, 0xf7f1e588
0, 660003, 230400, 0x9682bdb2
-0, 666003, 230400, 0x538a3db8
diff --git a/tests/ref/fate/mpeg2-field-enc b/tests/ref/fate/mpeg2-field-enc
index 1ea05bd9b7..c8ee4cfba0 100644
--- a/tests/ref/fate/mpeg2-field-enc
+++ b/tests/ref/fate/mpeg2-field-enc
@@ -7,33 +7,34 @@
0, 21600, 622080, 0xb3b66c5c
0, 25200, 622080, 0xb3b66c5c
0, 28800, 622080, 0xb3b66c5c
-0, 32400, 622080, 0x088ec02b
-0, 36000, 622080, 0x7a36db21
-0, 39600, 622080, 0x541b286f
-0, 43200, 622080, 0xb6c3e590
-0, 46800, 622080, 0x39dbed51
-0, 50400, 622080, 0x973dc728
-0, 54000, 622080, 0xd7a4f804
-0, 57600, 622080, 0xa2484762
-0, 61200, 622080, 0x0cd268d1
-0, 64800, 622080, 0x72eb663d
-0, 68400, 622080, 0x8fdbac59
-0, 72000, 622080, 0xa6f4feb9
-0, 75600, 622080, 0xadb828c6
-0, 79200, 622080, 0xea630a63
-0, 82800, 622080, 0xa901d925
-0, 86400, 622080, 0xac5e7087
-0, 90000, 622080, 0x10274a2b
-0, 93600, 622080, 0x143d541c
-0, 97200, 622080, 0xee94c93a
-0, 100800, 622080, 0xca030208
-0, 104400, 622080, 0x26f30ead
-0, 108000, 622080, 0xfc22f32c
-0, 111600, 622080, 0x940a5ff8
-0, 115200, 622080, 0x2164f805
-0, 118800, 622080, 0xa76f5aba
-0, 122400, 622080, 0x8c311471
-0, 126000, 622080, 0xa45e1d95
-0, 129600, 622080, 0x6cc61d6c
-0, 133200, 622080, 0x6983b417
-0, 136800, 622080, 0x982363c0
+0, 32400, 622080, 0xb3b66c5c
+0, 36000, 622080, 0x088ec02b
+0, 39600, 622080, 0x7a36db21
+0, 43200, 622080, 0x541b286f
+0, 46800, 622080, 0xb6c3e590
+0, 50400, 622080, 0x39dbed51
+0, 54000, 622080, 0x973dc728
+0, 57600, 622080, 0xd7a4f804
+0, 61200, 622080, 0xa2484762
+0, 64800, 622080, 0x0cd268d1
+0, 68400, 622080, 0x72eb663d
+0, 72000, 622080, 0x8fdbac59
+0, 75600, 622080, 0xa6f4feb9
+0, 79200, 622080, 0xadb828c6
+0, 82800, 622080, 0xea630a63
+0, 86400, 622080, 0xa901d925
+0, 90000, 622080, 0xac5e7087
+0, 93600, 622080, 0x10274a2b
+0, 97200, 622080, 0x143d541c
+0, 100800, 622080, 0xee94c93a
+0, 104400, 622080, 0xca030208
+0, 108000, 622080, 0x26f30ead
+0, 111600, 622080, 0xfc22f32c
+0, 115200, 622080, 0x940a5ff8
+0, 118800, 622080, 0x2164f805
+0, 122400, 622080, 0xa76f5aba
+0, 126000, 622080, 0x8c311471
+0, 129600, 622080, 0xa45e1d95
+0, 133200, 622080, 0x6cc61d6c
+0, 136800, 622080, 0x6983b417
+0, 140400, 622080, 0x982363c0
diff --git a/tests/ref/fate/prores-422 b/tests/ref/fate/prores-422
new file mode 100644
index 0000000000..8d6f3ab517
--- /dev/null
+++ b/tests/ref/fate/prores-422
@@ -0,0 +1,2 @@
+0, 0, 8294400, 0xe8e9d448
+0, 3003, 8294400, 0xe8e9d448
diff --git a/tests/ref/fate/prores-422_hq b/tests/ref/fate/prores-422_hq
new file mode 100644
index 0000000000..8ce6937cf5
--- /dev/null
+++ b/tests/ref/fate/prores-422_hq
@@ -0,0 +1,2 @@
+0, 0, 8294400, 0x817063b0
+0, 3003, 8294400, 0x817063b0
diff --git a/tests/ref/fate/prores-422_lt b/tests/ref/fate/prores-422_lt
new file mode 100644
index 0000000000..e9d0437568
--- /dev/null
+++ b/tests/ref/fate/prores-422_lt
@@ -0,0 +1,2 @@
+0, 0, 8294400, 0xcd4ccde1
+0, 3003, 8294400, 0xcd4ccde1
diff --git a/tests/ref/fate/prores-422_proxy b/tests/ref/fate/prores-422_proxy
new file mode 100644
index 0000000000..c9e454fd61
--- /dev/null
+++ b/tests/ref/fate/prores-422_proxy
@@ -0,0 +1,2 @@
+0, 0, 8294400, 0x51d29320
+0, 3003, 8294400, 0x51d29320
diff --git a/tests/ref/fate/prores-alpha b/tests/ref/fate/prores-alpha
new file mode 100644
index 0000000000..48568ba1f3
--- /dev/null
+++ b/tests/ref/fate/prores-alpha
@@ -0,0 +1,2 @@
+0, 0, 12441600, 0x254d8f95
+0, 3003, 12441600, 0x254d8f95
diff --git a/tests/ref/fate/qt-ima4-mono b/tests/ref/fate/qt-ima4-mono
index 66767d5d30..b8fc5f99de 100644
--- a/tests/ref/fate/qt-ima4-mono
+++ b/tests/ref/fate/qt-ima4-mono
@@ -1 +1 @@
-721b51fd66c3bb3dc49dd88d404188eb
+e178ed520edf2f46492ae740d88f5815
diff --git a/tests/ref/fate/qt-ima4-stereo b/tests/ref/fate/qt-ima4-stereo
index 5e6b1237d5..84c9f46d02 100644
--- a/tests/ref/fate/qt-ima4-stereo
+++ b/tests/ref/fate/qt-ima4-stereo
@@ -1 +1 @@
-c9e4c21fb62eca34a533f3a9ad2e394a
+d22be0e193dcbba1068a1ca6ab04cf77
diff --git a/tests/ref/fate/quickdraw b/tests/ref/fate/quickdraw
index 5d6303b70d..71612122a1 100644
--- a/tests/ref/fate/quickdraw
+++ b/tests/ref/fate/quickdraw
@@ -1,2 +1,3 @@
0, 0, 921600, 0xc0e68764
0, 6000, 921600, 0x01a16629
+0, 12000, 921600, 0x01a16629
diff --git a/tests/ref/fate/real-rv40 b/tests/ref/fate/real-rv40
index 2a445d0ccb..c63c525d08 100644
--- a/tests/ref/fate/real-rv40
+++ b/tests/ref/fate/real-rv40
@@ -1,121 +1,240 @@
0, 0, 276480, 0x5f7a0d4f
-0, 7500, 276480, 0x5f7a0d4f
-0, 15000, 276480, 0x5f7a0d4f
-0, 22500, 276480, 0x5f7a0d4f
-0, 30000, 276480, 0x5f7a0d4f
-0, 37500, 276480, 0x5f7a0d4f
-0, 45000, 276480, 0x5f7a0d4f
-0, 52500, 276480, 0x5f7a0d4f
-0, 60000, 276480, 0x5f7a0d4f
-0, 67500, 276480, 0x5f7a0d4f
-0, 75000, 276480, 0x5f7a0d4f
-0, 82500, 276480, 0x5f7a0d4f
-0, 90000, 276480, 0x5f7a0d4f
-0, 97500, 276480, 0x5f7a0d4f
-0, 105000, 276480, 0x5f7a0d4f
-0, 112500, 276480, 0x5f7a0d4f
-0, 120000, 276480, 0x5f7a0d4f
-0, 127500, 276480, 0x5f7a0d4f
-0, 135000, 276480, 0x2d722f8a
-0, 142500, 276480, 0xebbb3c8f
-0, 150000, 276480, 0x8574c868
-0, 157500, 276480, 0x4ec1e418
-0, 165000, 276480, 0x95f22651
-0, 172500, 276480, 0x071d897e
-0, 180000, 276480, 0x9f7623f9
-0, 187500, 276480, 0x86d4dedf
-0, 195000, 276480, 0xc0a0be22
-0, 202500, 276480, 0xc5902aec
-0, 210000, 276480, 0xe000f066
-0, 217500, 276480, 0x0b2a48d5
-0, 225000, 276480, 0xa1565256
-0, 232500, 276480, 0x8de3ceb3
-0, 240000, 276480, 0x654b564a
-0, 247500, 276480, 0xc9c57884
-0, 255000, 276480, 0x89cdcdd4
-0, 262500, 276480, 0x3594fe61
-0, 270000, 276480, 0x9d082a81
-0, 277500, 276480, 0x4e6cd0c3
-0, 285000, 276480, 0xc129765f
-0, 292500, 276480, 0x92a04c99
-0, 300000, 276480, 0x5ca62953
-0, 307500, 276480, 0xb7e478aa
-0, 315000, 276480, 0x932735d5
-0, 322500, 276480, 0xaaa2d7aa
-0, 330000, 276480, 0xd1329996
-0, 337500, 276480, 0x6de1e34b
-0, 345000, 276480, 0x8c963c9b
-0, 352500, 276480, 0xce6eff29
-0, 360000, 276480, 0x25412f7e
-0, 367500, 276480, 0x11a5ad85
-0, 375000, 276480, 0x26ea3248
-0, 382500, 276480, 0x86c35fa4
-0, 390000, 276480, 0xa98a2d38
-0, 397500, 276480, 0xed827333
-0, 405000, 276480, 0x5d44a824
-0, 412500, 276480, 0x46d54d04
-0, 420000, 276480, 0x413fd26a
-0, 427500, 276480, 0xf0b3b71b
-0, 435000, 276480, 0x459bc06d
-0, 442500, 276480, 0x4199cd45
-0, 450000, 276480, 0xa8d35683
-0, 457500, 276480, 0x9a3e7de0
-0, 465000, 276480, 0x5a30f666
-0, 472500, 276480, 0x40152668
-0, 480000, 276480, 0x90c4d22c
-0, 487500, 276480, 0x5cbaacc9
-0, 495000, 276480, 0x72b658f1
-0, 502500, 276480, 0x0ba3dcc9
-0, 510000, 276480, 0x259ed5c1
-0, 517500, 276480, 0x7fd73a99
-0, 525000, 276480, 0x488980c5
-0, 532500, 276480, 0x1d4c96a5
-0, 540000, 276480, 0x41ced7f2
-0, 547500, 276480, 0xd62d1837
-0, 555000, 276480, 0xf5fd9d20
-0, 562500, 276480, 0x2af91fda
-0, 570000, 276480, 0x38ce229d
-0, 577500, 276480, 0xf3a712c0
-0, 585000, 276480, 0x57b111d2
-0, 592500, 276480, 0x8556b792
-0, 600000, 276480, 0xb32d0896
-0, 607500, 276480, 0x923b9937
-0, 615000, 276480, 0x0da1e7e3
-0, 622500, 276480, 0x7f172382
-0, 630000, 276480, 0x93622b88
-0, 637500, 276480, 0x2599d540
-0, 645000, 276480, 0xed20c105
-0, 652500, 276480, 0x62ce256e
-0, 660000, 276480, 0x286a04bb
-0, 667500, 276480, 0x423f7e7c
-0, 675000, 276480, 0x21fc252a
-0, 682500, 276480, 0xf8a8e8ee
-0, 690000, 276480, 0x770d4a8d
-0, 697500, 276480, 0xaa12b6fd
-0, 705000, 276480, 0xdc7221a8
-0, 712500, 276480, 0x487eeb30
-0, 720000, 276480, 0x1e74f2db
-0, 727500, 276480, 0x40ae2bc3
-0, 735000, 276480, 0x9ca9b930
-0, 742500, 276480, 0x9fb19b0f
-0, 750000, 276480, 0x7bdf836c
-0, 757500, 276480, 0x1e607ba7
-0, 765000, 276480, 0xbd96578b
-0, 772500, 276480, 0x2124bf07
-0, 780000, 276480, 0x4895e27a
-0, 787500, 276480, 0x694d76e3
-0, 795000, 276480, 0xe70df513
-0, 802500, 276480, 0xcacafe6b
-0, 810000, 276480, 0x64087748
-0, 817500, 276480, 0x571fda23
-0, 825000, 276480, 0x8c86cbe9
-0, 832500, 276480, 0xc8ea4671
-0, 840000, 276480, 0xbfb74300
-0, 847500, 276480, 0xbe1e3770
-0, 855000, 276480, 0x757a0232
-0, 862500, 276480, 0xa5f50c84
-0, 870000, 276480, 0x6d95f808
-0, 877500, 276480, 0xf002c5ca
-0, 885000, 276480, 0x1a2abb26
-0, 892500, 276480, 0x6cf69bf2
-0, 900000, 276480, 0x8f316c66
+0, 3754, 276480, 0x5f7a0d4f
+0, 7507, 276480, 0x5f7a0d4f
+0, 11261, 276480, 0x5f7a0d4f
+0, 15015, 276480, 0x5f7a0d4f
+0, 18769, 276480, 0x5f7a0d4f
+0, 22522, 276480, 0x5f7a0d4f
+0, 26276, 276480, 0x5f7a0d4f
+0, 30030, 276480, 0x5f7a0d4f
+0, 33784, 276480, 0x5f7a0d4f
+0, 37537, 276480, 0x5f7a0d4f
+0, 41291, 276480, 0x5f7a0d4f
+0, 45045, 276480, 0x5f7a0d4f
+0, 48799, 276480, 0x5f7a0d4f
+0, 52552, 276480, 0x5f7a0d4f
+0, 56306, 276480, 0x5f7a0d4f
+0, 60060, 276480, 0x5f7a0d4f
+0, 63814, 276480, 0x5f7a0d4f
+0, 67567, 276480, 0x5f7a0d4f
+0, 71321, 276480, 0x5f7a0d4f
+0, 75075, 276480, 0x5f7a0d4f
+0, 78829, 276480, 0x5f7a0d4f
+0, 82582, 276480, 0x5f7a0d4f
+0, 86336, 276480, 0x5f7a0d4f
+0, 90090, 276480, 0x5f7a0d4f
+0, 93844, 276480, 0x5f7a0d4f
+0, 97597, 276480, 0x5f7a0d4f
+0, 101351, 276480, 0x5f7a0d4f
+0, 105105, 276480, 0x5f7a0d4f
+0, 108859, 276480, 0x5f7a0d4f
+0, 112612, 276480, 0x5f7a0d4f
+0, 116366, 276480, 0x5f7a0d4f
+0, 120120, 276480, 0x5f7a0d4f
+0, 123874, 276480, 0x75641594
+0, 127627, 276480, 0x32ee3526
+0, 131381, 276480, 0xcb53479a
+0, 135135, 276480, 0x7ca9658e
+0, 138889, 276480, 0x5ce39368
+0, 142642, 276480, 0x4ec1e418
+0, 146396, 276480, 0xb3790499
+0, 150150, 276480, 0xa9f1506f
+0, 153904, 276480, 0x85cbc3b5
+0, 157657, 276480, 0x377c7b46
+0, 161411, 276480, 0x1a61d8db
+0, 165165, 276480, 0xe1de7f0a
+0, 168919, 276480, 0x756a4a2e
+0, 172672, 276480, 0xcb379547
+0, 176426, 276480, 0xbae14484
+0, 180180, 276480, 0x8e12331c
+0, 183934, 276480, 0x99c085be
+0, 187687, 276480, 0xe479ffed
+0, 191441, 276480, 0x99c82949
+0, 195195, 276480, 0xac7672dd
+0, 198949, 276480, 0x1e4fae19
+0, 202702, 276480, 0x776412ef
+0, 206456, 276480, 0x7d9b579f
+0, 210210, 276480, 0x1cd1ab29
+0, 213964, 276480, 0x58ce0f38
+0, 217717, 276480, 0x5ab69b27
+0, 221471, 276480, 0x0afad610
+0, 225225, 276480, 0x9eca3f11
+0, 228979, 276480, 0xc3db9706
+0, 232732, 276480, 0xc9c57884
+0, 236486, 276480, 0xd9fbb2cf
+0, 240240, 276480, 0xdc07f3c9
+0, 243994, 276480, 0x000b5269
+0, 247747, 276480, 0x27ff7a5d
+0, 251501, 276480, 0xd92e2017
+0, 255255, 276480, 0x18d4b27d
+0, 259009, 276480, 0x70647530
+0, 262762, 276480, 0x97612c4b
+0, 266516, 276480, 0xc9d4ac78
+0, 270270, 276480, 0x4ec4d57f
+0, 274024, 276480, 0xdf4e04d7
+0, 277777, 276480, 0xbd98f57c
+0, 281531, 276480, 0x7247ea3e
+0, 285285, 276480, 0xa5d670ec
+0, 289039, 276480, 0x5163b29b
+0, 292792, 276480, 0x99170e64
+0, 296546, 276480, 0x37f4c0b0
+0, 300300, 276480, 0x7a4f2561
+0, 304053, 276480, 0x8a4e991f
+0, 307807, 276480, 0x6a45425f
+0, 311561, 276480, 0x1f0e2bb6
+0, 315315, 276480, 0xd75482c6
+0, 319068, 276480, 0x7bf6b1ef
+0, 322822, 276480, 0x6de1e34b
+0, 326576, 276480, 0x4526c89b
+0, 330330, 276480, 0xf964e18e
+0, 334083, 276480, 0xdcaaa99a
+0, 337837, 276480, 0xd1e98808
+0, 341591, 276480, 0x556b2365
+0, 345345, 276480, 0x0cf65540
+0, 349098, 276480, 0x6e2d524e
+0, 352852, 276480, 0x22c50a3d
+0, 356606, 276480, 0x293f19af
+0, 360360, 276480, 0xf4b1c461
+0, 364113, 276480, 0x62b76407
+0, 367867, 276480, 0x51e9b3eb
+0, 371621, 276480, 0x7b910bc7
+0, 375375, 276480, 0x6dd14ca6
+0, 379128, 276480, 0x441f7afd
+0, 382882, 276480, 0xfb01efc6
+0, 386636, 276480, 0x4f73ccea
+0, 390390, 276480, 0x5ac8e06f
+0, 394143, 276480, 0x294bb441
+0, 397897, 276480, 0xe04ac45e
+0, 401651, 276480, 0xa7a38d41
+0, 405405, 276480, 0xf688a3ed
+0, 409158, 276480, 0x58f275ea
+0, 412912, 276480, 0xf0b3b71b
+0, 416666, 276480, 0x3ce773bf
+0, 420420, 276480, 0x01840548
+0, 424173, 276480, 0x674e34e4
+0, 427927, 276480, 0x41dda2d9
+0, 431681, 276480, 0xc5b60838
+0, 435435, 276480, 0x9b209f41
+0, 439188, 276480, 0xf46ba7fb
+0, 442942, 276480, 0x28b54815
+0, 446696, 276480, 0xb605a933
+0, 450450, 276480, 0x34484aff
+0, 454203, 276480, 0xaf2b5d89
+0, 457957, 276480, 0x8facba58
+0, 461711, 276480, 0xbbe3e99f
+0, 465465, 276480, 0x02162c7c
+0, 469218, 276480, 0x28a63236
+0, 472972, 276480, 0x1ad43fd7
+0, 476726, 276480, 0xe37883e5
+0, 480480, 276480, 0x2b8a89c5
+0, 484233, 276480, 0x71507bd2
+0, 487987, 276480, 0x35626022
+0, 491741, 276480, 0x461fc3e7
+0, 495495, 276480, 0xce5af1ec
+0, 499248, 276480, 0x7c1139b3
+0, 503002, 276480, 0x7fd73a99
+0, 506756, 276480, 0x4ae4c3a6
+0, 510510, 276480, 0xcb60725a
+0, 514263, 276480, 0xb52e1aa2
+0, 518017, 276480, 0xd6f82cae
+0, 521771, 276480, 0x6310e665
+0, 525525, 276480, 0xfa88a483
+0, 529278, 276480, 0xf88f75d4
+0, 533032, 276480, 0x04a8e3ee
+0, 536786, 276480, 0x54766a12
+0, 540540, 276480, 0x0b41f0d7
+0, 544293, 276480, 0xa29f5b01
+0, 548047, 276480, 0x754ceaf5
+0, 551801, 276480, 0x150c0423
+0, 555555, 276480, 0xde084059
+0, 559308, 276480, 0x5a38b4af
+0, 563062, 276480, 0xfcebc261
+0, 566816, 276480, 0x0eb9770d
+0, 570570, 276480, 0x046394ae
+0, 574323, 276480, 0x3d3ca985
+0, 578077, 276480, 0x94a03c75
+0, 581831, 276480, 0x800eea2d
+0, 585585, 276480, 0x6a841f41
+0, 589338, 276480, 0x2f98911c
+0, 593092, 276480, 0x923b9937
+0, 596846, 276480, 0xe82f8e0f
+0, 600600, 276480, 0xee82d657
+0, 604353, 276480, 0xefab7ffd
+0, 608107, 276480, 0x6b9fbc80
+0, 611861, 276480, 0x4a1ada47
+0, 615614, 276480, 0x6d4b49d7
+0, 619368, 276480, 0xe4bdbd1e
+0, 623122, 276480, 0x225a56c0
+0, 626876, 276480, 0xd4adadad
+0, 630629, 276480, 0xff4e1a8c
+0, 634383, 276480, 0xf58b1b7c
+0, 638137, 276480, 0xbaffcdcc
+0, 641891, 276480, 0x374f88f0
+0, 645644, 276480, 0x3d861ae6
+0, 649398, 276480, 0xeb6eb88f
+0, 653152, 276480, 0xdb753d35
+0, 656906, 276480, 0x9aa543af
+0, 660659, 276480, 0xb24c8016
+0, 664413, 276480, 0xea80a82e
+0, 668167, 276480, 0x2aae902a
+0, 671921, 276480, 0x5bba3cfb
+0, 675674, 276480, 0x5c6e97a9
+0, 679428, 276480, 0x9b9ee961
+0, 683182, 276480, 0xaa12b6fd
+0, 686936, 276480, 0xe9d2439f
+0, 690689, 276480, 0xbf09053c
+0, 694443, 276480, 0x50c31e73
+0, 698197, 276480, 0xdd9fb89f
+0, 701951, 276480, 0x3e4e5aec
+0, 705704, 276480, 0x0b752d28
+0, 709458, 276480, 0xaf82399a
+0, 713212, 276480, 0x7ce5f23c
+0, 716966, 276480, 0xad135d0f
+0, 720719, 276480, 0x55dadd30
+0, 724473, 276480, 0x5aaa7519
+0, 728227, 276480, 0xe45a5599
+0, 731981, 276480, 0xc8e89913
+0, 735734, 276480, 0x2f447fd3
+0, 739488, 276480, 0x704411fb
+0, 743242, 276480, 0x9d7430a1
+0, 746996, 276480, 0x24dd5fd3
+0, 750749, 276480, 0x51cb657c
+0, 754503, 276480, 0x2c230702
+0, 758257, 276480, 0x4a4f76cd
+0, 762011, 276480, 0xdcd71e88
+0, 765764, 276480, 0x87160f99
+0, 769518, 276480, 0x27f54854
+0, 773272, 276480, 0x694d76e3
+0, 777026, 276480, 0xcbe93c19
+0, 780779, 276480, 0x50742e1b
+0, 784533, 276480, 0x525463e2
+0, 788287, 276480, 0x819898f9
+0, 792041, 276480, 0x08fac755
+0, 795794, 276480, 0x35c46927
+0, 799548, 276480, 0xeeed00fc
+0, 803302, 276480, 0xb6f99ee3
+0, 807056, 276480, 0xd87f4c73
+0, 810809, 276480, 0xde97d9fd
+0, 814563, 276480, 0xefc83107
+0, 818317, 276480, 0xbb22e024
+0, 822071, 276480, 0x53a7cfcb
+0, 825824, 276480, 0xbe1fbb19
+0, 829578, 276480, 0x300f922a
+0, 833332, 276480, 0x826fc3bd
+0, 837086, 276480, 0x679aa57a
+0, 840839, 276480, 0x5497097b
+0, 844593, 276480, 0x679a53f8
+0, 848347, 276480, 0x976c9e93
+0, 852101, 276480, 0xe80f87f2
+0, 855854, 276480, 0xdc2d7c6c
+0, 859608, 276480, 0xb194656e
+0, 863362, 276480, 0xf002c5ca
+0, 867116, 276480, 0x43fc1c64
+0, 870869, 276480, 0xf62d8581
+0, 874623, 276480, 0xb243dda5
+0, 878377, 276480, 0x1700efbb
+0, 882131, 276480, 0x9ebe6ba2
+0, 885884, 276480, 0x8f316c66
+0, 889638, 276480, 0x6348ecf5
+0, 893392, 276480, 0x34b5b78a
+0, 897146, 276480, 0xcbf66922
diff --git a/tests/ref/fate/rv30 b/tests/ref/fate/rv30
index 5b43588bb4..a3c5dcfbbf 100644
--- a/tests/ref/fate/rv30
+++ b/tests/ref/fate/rv30
@@ -1,46 +1,109 @@
0, 0, 126720, 0xcefaec47
-0, 7500, 126720, 0xa416ece5
-0, 15000, 126720, 0xa416ece5
-0, 22500, 126720, 0xa416ece5
-0, 30000, 126720, 0xcc10f4b7
-0, 37500, 126720, 0xeb6fb8d7
-0, 45000, 126720, 0xda71b917
-0, 52500, 126720, 0xbb1abbb7
-0, 60000, 126720, 0x273fbc37
-0, 67500, 126720, 0x16eebbd7
-0, 75000, 126720, 0x105eb927
-0, 82500, 126720, 0x7fa3ae27
-0, 90000, 126720, 0xd115a757
-0, 97500, 126720, 0x04e7897c
-0, 105000, 126720, 0x68cfda2b
-0, 112500, 126720, 0xe572dfc9
-0, 120000, 126720, 0xbc3cc34f
-0, 127500, 126720, 0xcf8cb0e2
-0, 135000, 126720, 0x6d1c630d
-0, 142500, 126720, 0x4338e469
-0, 150000, 126720, 0x9d82ea38
-0, 157500, 126720, 0x55e0b559
-0, 165000, 126720, 0x5eefb5ef
-0, 172500, 126720, 0x4b10b746
-0, 180000, 126720, 0x8b07a1db
-0, 187500, 126720, 0x8c639b34
-0, 195000, 126720, 0x63eb0b9f
-0, 202500, 126720, 0x31c80c83
-0, 210000, 126720, 0x78495352
-0, 217500, 126720, 0x63d609c4
-0, 225000, 126720, 0xcd2a62d8
-0, 232500, 126720, 0x4aea732d
-0, 240000, 126720, 0xe3bb352c
-0, 247500, 126720, 0x4b9036ad
-0, 255000, 126720, 0x88b66e2d
-0, 262500, 126720, 0x4a8a1b16
-0, 270000, 126720, 0x2e014eac
-0, 277500, 126720, 0x83212c67
-0, 285000, 126720, 0x4937e897
-0, 292500, 126720, 0x2d38babe
-0, 300000, 126720, 0xbcb43c09
-0, 307500, 126720, 0x955ffaf4
-0, 315000, 126720, 0x3337d4a2
-0, 322500, 126720, 0xe8f58c33
-0, 330000, 126720, 0x3a7f771f
-0, 337500, 126720, 0xb67c39b9
+0, 3003, 126720, 0xa416ece5
+0, 6006, 126720, 0xa416ece5
+0, 9009, 126720, 0xa416ece5
+0, 12012, 126720, 0x60d6ed27
+0, 15015, 126720, 0x259af497
+0, 18018, 126720, 0x5e6ff4d7
+0, 21021, 126720, 0xcc10f4b7
+0, 24024, 126720, 0x763ab817
+0, 27027, 126720, 0xeb6fb8d7
+0, 30030, 126720, 0xda71b917
+0, 33033, 126720, 0x0967b8f7
+0, 36036, 126720, 0x4b62b947
+0, 39039, 126720, 0xbb1abbb7
+0, 42042, 126720, 0x273fbc37
+0, 45045, 126720, 0x16eebbd7
+0, 48048, 126720, 0x105eb927
+0, 51051, 126720, 0x7fa3ae27
+0, 54054, 126720, 0x722e99f7
+0, 57057, 126720, 0x5ac9a827
+0, 60060, 126720, 0x07beba77
+0, 63063, 126720, 0x29d6a887
+0, 66066, 126720, 0xa5caab87
+0, 69069, 126720, 0x9ca7aac7
+0, 72072, 126720, 0xb7debcd7
+0, 75075, 126720, 0xd115a757
+0, 78078, 126720, 0x6ddaef32
+0, 81081, 126720, 0xde1bb900
+0, 84084, 126720, 0xac6c071b
+0, 87087, 126720, 0x04e7897c
+0, 90090, 126720, 0x5eee050f
+0, 93093, 126720, 0xe675be59
+0, 96096, 126720, 0xdc3e0837
+0, 99099, 126720, 0x68cfda2b
+0, 102102, 126720, 0xe572dfc9
+0, 105105, 126720, 0x582fb176
+0, 108108, 126720, 0xa9477df0
+0, 111111, 126720, 0xbc3cc34f
+0, 114114, 126720, 0xcf8cb0e2
+0, 117117, 126720, 0xcff1db35
+0, 120120, 126720, 0xc6e10f9f
+0, 123123, 126720, 0x75ae61b6
+0, 126126, 126720, 0x12af3119
+0, 129129, 126720, 0x85597543
+0, 132132, 126720, 0x68c27aca
+0, 135135, 126720, 0x554fe3e4
+0, 138138, 126720, 0x72ecea95
+0, 141141, 126720, 0xf4d003d1
+0, 144144, 126720, 0x9bf6a605
+0, 147147, 126720, 0x5d00b5fe
+0, 150150, 126720, 0x93f7b040
+0, 153153, 126720, 0x0d6ad154
+0, 156156, 126720, 0x4be8b4ea
+0, 159159, 126720, 0xe39bba0d
+0, 162162, 126720, 0x9c21bad8
+0, 165165, 126720, 0xa567f25b
+0, 168168, 126720, 0x7a82663a
+0, 171171, 126720, 0x72f2a47d
+0, 174174, 126720, 0x4f639ebe
+0, 177177, 126720, 0xab0fce83
+0, 180180, 126720, 0x6cf87d39
+0, 183183, 126720, 0x534a10cc
+0, 186186, 126720, 0x6bbcf44c
+0, 189189, 126720, 0xfdca11d3
+0, 192192, 126720, 0x7e58f5a6
+0, 195195, 126720, 0x5fd753d8
+0, 198198, 126720, 0x0c735615
+0, 201201, 126720, 0x2a034ebf
+0, 204204, 126720, 0xeaf3dd0b
+0, 207207, 126720, 0x0eaf0c1b
+0, 210210, 126720, 0xce5e6794
+0, 213213, 126720, 0xf27c31c3
+0, 216216, 126720, 0xb64af168
+0, 219219, 126720, 0x14cf7974
+0, 222222, 126720, 0x1c2a513d
+0, 225225, 126720, 0xa3f515ab
+0, 228228, 126720, 0xcfd62765
+0, 231231, 126720, 0xbc513f2a
+0, 234234, 126720, 0xbc303fae
+0, 237237, 126720, 0x2f8f69b9
+0, 240240, 126720, 0x0a22cc69
+0, 243243, 126720, 0xd9f67585
+0, 246246, 126720, 0x20403001
+0, 249249, 126720, 0xf92b2a25
+0, 252252, 126720, 0x3c170aad
+0, 255255, 126720, 0x3378251f
+0, 258258, 126720, 0xb3ed5911
+0, 261261, 126720, 0x35d24ef8
+0, 264264, 126720, 0x8da30275
+0, 267267, 126720, 0xc15a3577
+0, 270270, 126720, 0xf2942f53
+0, 273273, 126720, 0x44d8304a
+0, 276276, 126720, 0xd688a932
+0, 279279, 126720, 0x0a24f256
+0, 282282, 126720, 0xfab9c45d
+0, 285285, 126720, 0x10e939ce
+0, 288288, 126720, 0x97fcaa3a
+0, 291291, 126720, 0x45464610
+0, 294294, 126720, 0xfe2e057d
+0, 297297, 126720, 0x0b6718ae
+0, 300300, 126720, 0x5284da7b
+0, 303303, 126720, 0x23efdc35
+0, 306306, 126720, 0xc387b2b3
+0, 309309, 126720, 0xc9e92bf1
+0, 312312, 126720, 0xfbf20a01
+0, 315315, 126720, 0x4d888b2e
+0, 318318, 126720, 0xdd0d74df
+0, 321321, 126720, 0x49d07aa4
+0, 324324, 126720, 0x08382b8e
diff --git a/tests/ref/fate/smacker b/tests/ref/fate/smacker
index 85c4a9817c..df88a4ae8a 100644
--- a/tests/ref/fate/smacker
+++ b/tests/ref/fate/smacker
@@ -1,5 +1,5 @@
0, 0, 192000, 0x8926d7fc
-1, 0, 47240, 0xad778a78
+1, 0, 47240, 0x9974897c
0, 6390, 192000, 0x2506d384
0, 12780, 192000, 0x9a8dc93a
0, 19170, 192000, 0x4badb7f2
@@ -15,163 +15,163 @@
0, 83070, 192000, 0x1a3d7971
0, 89460, 192000, 0xa1a65bd5
0, 95850, 192000, 0x344957b9
-1, 96408, 3128, 0x4c1564ae
+1, 96408, 3128, 0x7e4064b4
0, 102240, 192000, 0xe23b5f4e
-1, 102792, 3128, 0x34553309
+1, 102792, 3128, 0x80883301
0, 108630, 192000, 0xb5c2710b
-1, 109176, 3136, 0xb474d246
+1, 109176, 3136, 0x2ad2d341
0, 115020, 192000, 0x7a25938f
-1, 115576, 3128, 0x87b868ea
+1, 115576, 3128, 0xda8468e3
0, 121410, 192000, 0x0a84e4c9
-1, 121959, 3136, 0xf1516dc3
+1, 121959, 3136, 0x9d6f6cdf
0, 127800, 192000, 0x94209b0d
-1, 128359, 3128, 0x867563cb
+1, 128359, 3128, 0x1aaa64b5
0, 134190, 192000, 0xf940e51f
-1, 134743, 3128, 0x5200728c
+1, 134743, 3128, 0x9182728b
0, 140580, 192000, 0xb9fdec42
-1, 141127, 3136, 0xeda118a0
+1, 141127, 3136, 0xfa8e17b3
0, 146970, 192000, 0x7b04a376
-1, 147527, 3128, 0x03e2c1d6
+1, 147527, 3128, 0x0dc3c1cf
0, 153360, 192000, 0x5fe0026b
-1, 153910, 3136, 0xc3e862b6
+1, 153910, 3136, 0x0109639d
0, 159750, 192000, 0x775aca39
-1, 160310, 3128, 0x937a13be
+1, 160310, 3128, 0x6d8a12d9
0, 166140, 192000, 0xae14fb32
-1, 166694, 3128, 0x7b1b9577
+1, 166694, 3128, 0x4b9a9597
0, 172530, 192000, 0x661106e5
-1, 173078, 3136, 0x042c7113
+1, 173078, 3136, 0x9112710e
0, 178920, 192000, 0xe8658dbf
-1, 179478, 3128, 0xac48f451
+1, 179478, 3128, 0x8cccf522
0, 185310, 192000, 0x5359f0f9
-1, 185861, 3128, 0x018fbbe9
+1, 185861, 3128, 0x6594bbf3
0, 191700, 192000, 0xc1ec80f4
-1, 192245, 3136, 0xc62aa7ce
+1, 192245, 3136, 0xd878a7d5
0, 198090, 192000, 0xca53806b
-1, 198645, 3128, 0x106e3924
+1, 198645, 3128, 0xaa6e3905
0, 204480, 192000, 0xf0766b2e
-1, 205029, 3136, 0xfeb82ecc
+1, 205029, 3136, 0x2a062e04
0, 210870, 192000, 0x39962da8
-1, 211429, 3128, 0x7e7c005b
+1, 211429, 3128, 0x84e4006a
0, 217260, 192000, 0x4171c37f
-1, 217812, 3128, 0x949d3560
+1, 217812, 3128, 0x85183633
0, 223650, 192000, 0x3abf3b46
-1, 224196, 3136, 0x02bd4aff
+1, 224196, 3136, 0xb62d4b02
0, 230040, 192000, 0xecc68313
-1, 230596, 3128, 0x4aaf4715
+1, 230596, 3128, 0xe209462a
0, 236430, 192000, 0xea339baf
-1, 236980, 3136, 0x2958825f
+1, 236980, 3136, 0x57c4824b
0, 242820, 192000, 0x616b8f16
-1, 243380, 3128, 0x99a5914d
+1, 243380, 3128, 0x664a9163
0, 249210, 192000, 0xf77a8581
-1, 249763, 3128, 0xe67277a4
+1, 249763, 3128, 0xb4287874
0, 255600, 192000, 0xb315678b
-1, 256147, 3136, 0x11296973
+1, 256147, 3136, 0xde626885
0, 261990, 192000, 0x0a4a5218
-1, 262547, 3128, 0x5cc362f7
+1, 262547, 3128, 0x919763c2
0, 268380, 192000, 0x98802be4
-1, 268931, 3128, 0x0c5e6586
+1, 268931, 3128, 0xa4f664e1
0, 274770, 192000, 0xa2f0fd94
-1, 275314, 3136, 0xe940b0f9
+1, 275314, 3136, 0xa0bab0d4
0, 281160, 192000, 0x6671c84f
-1, 281714, 3128, 0x2c9292cc
+1, 281714, 3128, 0xe938939c
0, 287550, 192000, 0x38327e31
-1, 288098, 3136, 0xa807c096
+1, 288098, 3136, 0x3679bfc7
0, 293940, 192000, 0xb85d3e08
-1, 294498, 3128, 0x9d2254d8
+1, 294498, 3128, 0xc96c55c3
0, 300330, 192000, 0xdc69eba9
-1, 300882, 3128, 0xe68015b0
+1, 300882, 3128, 0x119114d6
0, 306720, 192000, 0x8955a0b3
-1, 307265, 3136, 0x65d58029
+1, 307265, 3136, 0x42f3800f
0, 313110, 192000, 0x714a548b
-1, 313665, 3128, 0xcffcc48c
+1, 313665, 3128, 0x4250c4ad
0, 319500, 192000, 0xc0471de9
-1, 320049, 3136, 0x8c704944
+1, 320049, 3136, 0x5cdd4925
0, 325890, 192000, 0x2e16e039
-1, 326449, 3128, 0x1459231d
+1, 326449, 3128, 0xa4c12360
0, 332280, 192000, 0x9fa4b033
-1, 332833, 3128, 0x7dde4839
+1, 332833, 3128, 0x849f48de
0, 338670, 192000, 0x4a0f9402
-1, 339216, 3136, 0xbb6890e2
+1, 339216, 3136, 0x6acd8ff9
0, 345060, 192000, 0x1f3e6843
-1, 345616, 3128, 0xcd9a8524
+1, 345616, 3128, 0xb2758556
0, 351450, 192000, 0x31774850
-1, 352000, 3128, 0xa244fc31
+1, 352000, 3128, 0x10f2fcb1
0, 357840, 192000, 0x9d5336a2
-1, 358384, 3136, 0x504e2bd9
+1, 358384, 3136, 0xf0f02b23
0, 364230, 192000, 0xf7de27a2
-1, 364784, 3128, 0x655858d8
+1, 364784, 3128, 0x64f759c6
0, 370620, 192000, 0x98c717ce
-1, 371167, 3136, 0x46027610
+1, 371167, 3136, 0x7ec075e3
0, 377010, 192000, 0x615b10b8
-1, 377567, 3128, 0x4192d5e3
+1, 377567, 3128, 0xf981d51e
0, 383400, 192000, 0xd5bc0e7e
-1, 383951, 3128, 0x21d2e7fe
+1, 383951, 3128, 0xc622e8b9
0, 389790, 192000, 0xd5bc0e7e
-1, 390335, 3136, 0x7c93e329
+1, 390335, 3136, 0xf632e2f8
0, 396180, 192000, 0xd5bc0e7e
-1, 396735, 3128, 0xa67718c0
+1, 396735, 3128, 0xda561864
0, 402570, 192000, 0xd5bc0e7e
-1, 403118, 3136, 0x9bb6e8a3
+1, 403118, 3136, 0x14d2e888
0, 408960, 192000, 0xd5bc0e7e
-1, 409518, 3128, 0x0933b7a6
+1, 409518, 3128, 0x015bb869
0, 415350, 192000, 0xd5bc0e7e
-1, 415902, 3128, 0x07f1fb57
+1, 415902, 3128, 0xedb1fb62
0, 421740, 192000, 0xd5bc0e7e
-1, 422286, 3136, 0x8a050cfd
+1, 422286, 3136, 0xe0560c41
0, 428130, 192000, 0xd5bc0e7e
-1, 428686, 3128, 0xdb773c0b
+1, 428686, 3128, 0x14773c9a
0, 434520, 192000, 0xd5bc0e7e
-1, 435069, 3136, 0xd1281c53
+1, 435069, 3136, 0x850f1c82
0, 440910, 192000, 0xd5bc0e7e
-1, 441469, 3128, 0x9f395324
+1, 441469, 3128, 0xb0bd5347
0, 447300, 192000, 0xd5bc0e7e
-1, 447853, 3128, 0x5f13edec
+1, 447853, 3128, 0x8f82edbf
0, 453690, 192000, 0xd5bc0e7e
-1, 454237, 3136, 0x871cbecf
+1, 454237, 3136, 0x493abee2
0, 460080, 192000, 0xd5bc0e7e
-1, 460637, 3128, 0x799eff3e
+1, 460637, 3128, 0xf5daff3f
0, 466470, 192000, 0xd5bc0e7e
-1, 467020, 3128, 0x3f902762
+1, 467020, 3128, 0x78ad2690
0, 472860, 192000, 0xd5bc0e7e
-1, 473404, 3136, 0x29f8bb04
+1, 473404, 3136, 0x490ebafc
0, 479250, 192000, 0xd5bc0e7e
-1, 479804, 3128, 0xf3523ee9
+1, 479804, 3128, 0x70333fd2
0, 485640, 192000, 0xd5bc0e7e
-1, 486188, 3136, 0x4405c435
+1, 486188, 3136, 0x8cb1c350
0, 492030, 192000, 0xd5bc0e7e
-1, 492588, 3128, 0x892957cb
+1, 492588, 3128, 0x8bd057cb
0, 498420, 192000, 0xd5bc0e7e
-1, 498971, 3128, 0xdf483dbd
+1, 498971, 3128, 0x161b3dbc
0, 504810, 192000, 0xd5bc0e7e
-1, 505355, 3136, 0x5e8ab797
+1, 505355, 3136, 0xb47fb88a
0, 511200, 192000, 0xd5bc0e7e
-1, 511755, 3128, 0x92e13820
+1, 511755, 3128, 0x474b381e
0, 517590, 192000, 0xd5bc0e7e
-1, 518139, 3136, 0xfde719b6
+1, 518139, 3136, 0x07c519bb
0, 523980, 192000, 0xd5bc0e7e
-1, 524539, 3128, 0x442f17ae
+1, 524539, 3128, 0x15b916c8
0, 530370, 192000, 0xd5bc0e7e
-1, 530922, 3128, 0x011af61f
+1, 530922, 3128, 0x0ed7f6fb
0, 536760, 192000, 0xd5bc0e7e
-1, 537306, 3136, 0x4e3e3a6d
+1, 537306, 3136, 0x54d6397b
0, 543150, 192000, 0xd5bc0e7e
-1, 543706, 3128, 0xc11242b9
+1, 543706, 3128, 0x437242bb
0, 549540, 192000, 0xd5bc0e7e
-1, 550090, 3128, 0x01415b59
+1, 550090, 3128, 0x38f05c4d
0, 555930, 192000, 0xd5bc0e7e
-1, 556473, 3136, 0x302e0e55
+1, 556473, 3136, 0x5d000e59
0, 562320, 192000, 0xd5bc0e7e
-1, 562873, 3128, 0x20522d04
+1, 562873, 3128, 0xdeab2d04
0, 568710, 192000, 0xd5bc0e7e
-1, 569257, 3136, 0x316a697d
+1, 569257, 3136, 0x77de6880
0, 575100, 192000, 0xd5bc0e7e
-1, 575657, 3128, 0x6d75ee27
+1, 575657, 3128, 0xbc87ef25
0, 581490, 192000, 0xd5bc0e7e
-1, 582041, 3128, 0xcb008ae8
+1, 582041, 3128, 0xc1638ade
0, 587880, 192000, 0xd5bc0e7e
-1, 588424, 3136, 0xd2664b51
+1, 588424, 3136, 0xcfb64a5f
0, 594270, 192000, 0xd5bc0e7e
-1, 594824, 3128, 0xdfcab728
+1, 594824, 3128, 0x90b1b826
0, 600660, 192000, 0xd5bc0e7e
1, 601208, 3136, 0x00000000
0, 607050, 192000, 0xd5bc0e7e
diff --git a/tests/ref/fate/tiertex-seq b/tests/ref/fate/tiertex-seq
index 6aa7fc7b9f..a75de4a76e 100644
--- a/tests/ref/fate/tiertex-seq
+++ b/tests/ref/fate/tiertex-seq
@@ -6,13 +6,13 @@
1, 7200, 1764, 0x95a16721
0, 10800, 98304, 0xb20c19d0
1, 10800, 1764, 0x0f0d4cb6
-0, 14400, 98304, 0x6b8538c0
+0, 14400, 98304, 0xb20c19d0
1, 14400, 1764, 0x75026779
0, 18000, 98304, 0x6b8538c0
1, 18000, 1764, 0xb4356e37
0, 21600, 98304, 0x6b8538c0
1, 21600, 1764, 0xfafa64cb
-0, 25200, 98304, 0x172207e3
+0, 25200, 98304, 0x6b8538c0
1, 25200, 1764, 0xe8fd7970
0, 28800, 98304, 0x172207e3
1, 28800, 1764, 0x666879b7
@@ -20,13 +20,13 @@
1, 32400, 1764, 0xf2cd7770
0, 36000, 98304, 0x172207e3
1, 36000, 1764, 0x54317a1c
-0, 39600, 98304, 0x63fb7dc1
+0, 39600, 98304, 0x172207e3
1, 39600, 1764, 0x9c396930
0, 43200, 98304, 0x63fb7dc1
1, 43200, 1764, 0x87115ec4
0, 46800, 98304, 0x63fb7dc1
1, 46800, 1764, 0x0c9b69b6
-0, 50400, 98304, 0x37cf1601
+0, 50400, 98304, 0x63fb7dc1
1, 50400, 1764, 0x8c3a758a
0, 54000, 98304, 0x37cf1601
1, 54000, 1764, 0x605d776a
@@ -34,7 +34,7 @@
1, 57600, 1764, 0x0556852d
0, 61200, 98304, 0x37cf1601
1, 61200, 1764, 0x7d4363f8
-0, 64800, 98304, 0x82941990
+0, 64800, 98304, 0x37cf1601
1, 64800, 1764, 0xc5cd75d0
0, 68400, 98304, 0x82941990
1, 68400, 1764, 0x3ff3646d
@@ -42,13 +42,13 @@
1, 72000, 1764, 0x10136d25
0, 75600, 98304, 0x82941990
1, 75600, 1764, 0xeb1a6cd0
-0, 79200, 98304, 0xe0a5309e
+0, 79200, 98304, 0x82941990
1, 79200, 1764, 0xef937ed1
0, 82800, 98304, 0xe0a5309e
1, 82800, 1764, 0x2d2b6f79
0, 86400, 98304, 0xe0a5309e
1, 86400, 1764, 0x6f457231
-0, 90000, 98304, 0x164cb67d
+0, 90000, 98304, 0xe0a5309e
1, 90000, 1764, 0x56267c9d
0, 93600, 98304, 0x164cb67d
1, 93600, 1764, 0xd49e79c8
@@ -56,13 +56,13 @@
1, 97200, 1764, 0xc726703d
0, 100800, 98304, 0x164cb67d
1, 100800, 1764, 0x2abf8074
-0, 104400, 98304, 0xed2189f8
+0, 104400, 98304, 0x164cb67d
1, 104400, 1764, 0xb50c556d
0, 108000, 98304, 0xed2189f8
1, 108000, 1764, 0xc1f2523c
0, 111600, 98304, 0xed2189f8
1, 111600, 1764, 0x850a6f93
-0, 115200, 98304, 0x7215e529
+0, 115200, 98304, 0xed2189f8
1, 115200, 1764, 0x8da76c31
0, 118800, 98304, 0x7215e529
1, 118800, 1764, 0xfcccdf13
@@ -70,13 +70,13 @@
1, 122400, 1764, 0x00000000
0, 126000, 98304, 0x7215e529
1, 126000, 1764, 0x00000000
-0, 129600, 98304, 0x170c783b
+0, 129600, 98304, 0x7215e529
1, 129600, 1764, 0x00000000
0, 133200, 98304, 0x170c783b
1, 133200, 1764, 0x00000000
0, 136800, 98304, 0x170c783b
1, 136800, 1764, 0x00000000
-0, 140400, 98304, 0xf6bd74c7
+0, 140400, 98304, 0x170c783b
1, 140400, 1764, 0x00000000
0, 144000, 98304, 0xf6bd74c7
1, 144000, 1764, 0x00000000
@@ -84,7 +84,7 @@
1, 147600, 1764, 0x00000000
0, 151200, 98304, 0xf6bd74c7
1, 151200, 1764, 0x00000000
-0, 154800, 98304, 0x1efd38c4
+0, 154800, 98304, 0xf6bd74c7
1, 154800, 1764, 0x00000000
0, 158400, 98304, 0x1efd38c4
1, 158400, 1764, 0x00000000
@@ -92,13 +92,13 @@
1, 162000, 1764, 0x00000000
0, 165600, 98304, 0x1efd38c4
1, 165600, 1764, 0x00000000
-0, 169200, 98304, 0x29c26bba
+0, 169200, 98304, 0x1efd38c4
1, 169200, 1764, 0x00000000
0, 172800, 98304, 0x29c26bba
1, 172800, 1764, 0x00000000
0, 176400, 98304, 0x29c26bba
1, 176400, 1764, 0x00000000
-0, 180000, 98304, 0x880a6313
+0, 180000, 98304, 0x29c26bba
1, 180000, 1764, 0x00000000
0, 183600, 98304, 0x880a6313
1, 183600, 1764, 0x00000000
@@ -106,13 +106,13 @@
1, 187200, 1764, 0x00000000
0, 190800, 98304, 0x880a6313
1, 190800, 1764, 0x00000000
-0, 194400, 98304, 0x73f5bb00
+0, 194400, 98304, 0x880a6313
1, 194400, 1764, 0x00000000
0, 198000, 98304, 0x73f5bb00
1, 198000, 1764, 0x00000000
0, 201600, 98304, 0x73f5bb00
1, 201600, 1764, 0x00000000
-0, 205200, 98304, 0xc85b19ec
+0, 205200, 98304, 0x73f5bb00
1, 205200, 1764, 0x00000000
0, 208800, 98304, 0xc85b19ec
1, 208800, 1764, 0x00000000
@@ -120,7 +120,7 @@
1, 212400, 1764, 0x00000000
0, 216000, 98304, 0xc85b19ec
1, 216000, 1764, 0x00000000
-0, 219600, 98304, 0x00000000
+0, 219600, 98304, 0xc85b19ec
1, 219600, 1764, 0x00000000
0, 223200, 98304, 0x00000000
1, 223200, 1764, 0x00000000
@@ -142,6 +142,7 @@
1, 252000, 1764, 0x00000000
0, 255600, 98304, 0x00000000
1, 255600, 1764, 0x00000000
+0, 259200, 98304, 0x00000000
1, 259200, 1764, 0x00000000
1, 262800, 1764, 0x00000000
1, 266400, 1764, 0x00000000
diff --git a/tests/ref/fate/truemotion1-15 b/tests/ref/fate/truemotion1-15
index d103f01970..d9925c73c6 100644
--- a/tests/ref/fate/truemotion1-15
+++ b/tests/ref/fate/truemotion1-15
@@ -1,218 +1,218 @@
0, 0, 161280, 0x7041748d
-1, 0, 10832, 0xe1a811fa
-1, 5527, 10832, 0xb47841f9
+1, 0, 10836, 0x2a531236
+1, 5529, 10836, 0xc58f45af
0, 6000, 161280, 0x3cc4dfb5
-1, 11053, 10832, 0x839eedf1
+1, 11057, 10836, 0x436cf135
0, 12000, 161280, 0xca3af22d
-1, 16580, 10832, 0xb48b1f60
+1, 16586, 10836, 0x3a6022cc
0, 18000, 161280, 0x23ad1d85
-1, 22106, 10832, 0x743936c0
+1, 22114, 10836, 0x57e83a4a
0, 24000, 161280, 0x9c9cf364
-1, 27633, 10832, 0xe1f039fb
+1, 27643, 10836, 0xca4b3a1b
0, 30000, 161280, 0x1551d6a8
-1, 33159, 10832, 0xef00751a
+1, 33171, 10836, 0xc3da7536
0, 36000, 161280, 0xc39f6b95
-1, 38686, 10832, 0x401ed099
+1, 38700, 10836, 0x8c57d47b
0, 42000, 161280, 0x3b036dcc
-1, 44212, 10832, 0x432a53bd
+1, 44229, 10836, 0x9a79572b
0, 48000, 161280, 0xa6fac1db
-1, 49739, 10832, 0xc4276bfd
+1, 49757, 10836, 0x7dbd6fd3
0, 54000, 161280, 0x67656b62
-1, 55265, 10832, 0x51f0fa8c
+1, 55286, 10836, 0x4454fdde
0, 60000, 161280, 0xb41f47d1
-1, 60792, 10832, 0xcebae622
+1, 60814, 10836, 0x68aae686
0, 66000, 161280, 0xc207249e
-1, 66318, 10832, 0xe9f6dc1f
-1, 71845, 10832, 0xda087fee
+1, 66343, 10836, 0x61f2df35
+1, 71871, 10836, 0xe36883c6
0, 72000, 161280, 0xbee8f843
-1, 77371, 10832, 0x67a621bb
+1, 77400, 10836, 0xefa62217
0, 78000, 161280, 0x092acf46
-1, 82898, 10832, 0xd7be207f
+1, 82929, 10836, 0x63b92479
0, 84000, 161280, 0x8d9e2680
-1, 88424, 10832, 0x19d32507
+1, 88457, 10836, 0xaf452579
0, 90000, 161280, 0x8becc20c
-1, 93951, 10832, 0xe1a3fbfa
+1, 93986, 10836, 0xdbb10001
0, 96000, 161280, 0x655e444e
-1, 99478, 10832, 0xd10df779
+1, 99514, 10836, 0xafb7f7a7
0, 102000, 161280, 0x5c112da0
-1, 105004, 10832, 0x4428e1a7
+1, 105043, 10836, 0xd4b1e591
0, 108000, 161280, 0x232fa9eb
-1, 110531, 10832, 0x7ea9b33d
+1, 110571, 10836, 0x4d44b3bb
0, 114000, 161280, 0x9721745d
-1, 116057, 10832, 0x6852a5a5
+1, 116100, 10836, 0xff2ea5b3
0, 120000, 161280, 0x92f1d880
-1, 121584, 10832, 0xfeb78863
+1, 121629, 10836, 0x214e88ad
0, 126000, 161280, 0x16233978
-1, 127110, 10832, 0xf157f928
+1, 127157, 10836, 0xde8bfc9a
0, 132000, 161280, 0x19a27e69
-1, 132637, 10832, 0x86414b3e
+1, 132686, 10836, 0xb3cc4b6a
0, 138000, 161280, 0x7b6ad73a
-1, 138163, 10832, 0x2e28cdf6
-1, 143690, 10832, 0x00212e44
+1, 138214, 10836, 0x670bce40
+1, 143743, 10836, 0xc17d31b2
0, 144000, 161280, 0xa7a674aa
-1, 149216, 10832, 0x2d7f9378
+1, 149271, 10836, 0x7bcb9392
0, 150000, 161280, 0x4e434abb
-1, 154743, 10832, 0x84cb25d7
+1, 154800, 10836, 0x230e28c9
0, 156000, 161280, 0xb96eea14
-1, 160269, 10832, 0x3aca41fa
+1, 160329, 10836, 0x42df4204
0, 162000, 161280, 0x1350188c
-1, 165796, 10832, 0x27ad34b9
+1, 165857, 10836, 0xfa9134b9
0, 168000, 161280, 0x79c6f305
-1, 171322, 10832, 0xe665144a
+1, 171386, 10836, 0x418c1844
0, 174000, 161280, 0xa9c7782d
-1, 176849, 10832, 0xf9546626
+1, 176914, 10836, 0x93ba66b6
0, 180000, 161280, 0x40a4f456
-1, 182376, 10832, 0xe71c4f22
+1, 182443, 10836, 0x264a4ffa
0, 186000, 161280, 0xaf291ed6
-1, 187902, 10832, 0x5e61869c
+1, 187971, 10836, 0x82c78a8e
0, 192000, 161280, 0xab29b4e1
-1, 193429, 10832, 0x571d2c10
+1, 193500, 10836, 0x10d22fdc
0, 198000, 161280, 0xbfcd2712
-1, 198955, 10832, 0xf0e08cd5
+1, 199029, 10836, 0x2d25906b
0, 204000, 161280, 0xff22a0d7
-1, 204482, 10832, 0x66650e49
+1, 204557, 10836, 0xa8a111fb
0, 210000, 161280, 0xb0ae88a9
-1, 210008, 10832, 0x4024deaf
-1, 215535, 10832, 0xda7bdb14
+1, 210086, 10836, 0xbd95df87
+1, 215614, 10836, 0x500ddec0
0, 216000, 161280, 0x811d1259
-1, 221061, 10832, 0xc27a342f
+1, 221143, 10836, 0x95d9350b
0, 222000, 161280, 0x593c39a1
-1, 226588, 10832, 0x574fe679
+1, 226671, 10836, 0xfa54ea1f
0, 228000, 161280, 0x5a5a97f8
-1, 232114, 10832, 0x37db464e
+1, 232200, 10836, 0x51b2467e
0, 234000, 161280, 0xa5639ecf
-1, 237641, 10832, 0xb1fa2a83
+1, 237729, 10836, 0x5d772af9
0, 240000, 161280, 0x543920c6
-1, 243167, 10832, 0x3d98d9b7
+1, 243257, 10836, 0xae25dd8d
0, 246000, 161280, 0xb41689ee
-1, 248694, 10832, 0xb7c908e2
+1, 248786, 10836, 0xe4bd0cb0
0, 252000, 161280, 0xc0ad83de
-1, 254220, 10832, 0x9f7e44d8
+1, 254314, 10836, 0xb33544f0
0, 258000, 161280, 0x9e9e7456
-1, 259747, 10832, 0xae9b8774
+1, 259843, 10836, 0xd5658b12
0, 264000, 161280, 0x777ccbfe
-1, 265273, 10832, 0x36916e3f
+1, 265371, 10836, 0xeff66e5d
0, 270000, 161280, 0x9c2df916
-1, 270800, 10832, 0xd785f5ef
+1, 270900, 10836, 0xb1fff6c5
0, 276000, 161280, 0xe0c13b35
-1, 276327, 10832, 0x2a3a5673
-1, 281853, 10832, 0x7320e379
+1, 276429, 10836, 0x84db56b5
+1, 281957, 10836, 0x0230e3c9
0, 282000, 161280, 0x39bfa5a5
-1, 287380, 10832, 0xec787be5
+1, 287486, 10836, 0xe58a7faf
0, 288000, 161280, 0x35dfb264
-1, 292906, 10832, 0xd0d13aa0
+1, 293014, 10836, 0xc4003e2a
0, 294000, 161280, 0x43018613
-1, 298433, 10832, 0x34dfcb17
+1, 298543, 10836, 0x6360cbbf
0, 300000, 161280, 0x43584b8a
-1, 303959, 10832, 0x1a9c29f1
+1, 304071, 10836, 0xc29c2a05
0, 306000, 161280, 0xa5cd230a
-1, 309486, 10832, 0x3e73dcc1
+1, 309600, 10836, 0xb294dd11
0, 312000, 161280, 0x6fe2cfb3
-1, 315012, 10832, 0x7855b053
+1, 315129, 10836, 0x4388b43b
0, 318000, 161280, 0x88a7c0db
-1, 320539, 10832, 0x5588df8f
+1, 320657, 10836, 0xdd7be367
0, 324000, 161280, 0x476f1cd2
-1, 326065, 10832, 0x6f621299
+1, 326186, 10836, 0xb9f612a9
0, 330000, 161280, 0x96401d49
-1, 331592, 10832, 0xce7f39c2
+1, 331714, 10836, 0xb64a39fe
0, 336000, 161280, 0x7d932919
-1, 337118, 10832, 0xd88e6552
+1, 337243, 10836, 0x6eba6594
0, 342000, 161280, 0x06465481
-1, 342645, 10832, 0xddc63597
+1, 342771, 10836, 0xb4af35c1
0, 348000, 161280, 0x39631520
-1, 348171, 10832, 0xe3071865
-1, 353698, 10832, 0x2a44a123
+1, 348300, 10836, 0x4e581c49
+1, 353829, 10836, 0xb062a19f
0, 354000, 161280, 0xc3fff780
-1, 359224, 10832, 0x08d85d45
+1, 359357, 10836, 0x87cd6135
0, 360000, 161280, 0xa81faf28
-1, 364751, 10832, 0x4dc5f83a
+1, 364886, 10836, 0x37bffbd6
0, 366000, 161280, 0x7a311f4f
-1, 370278, 10832, 0x89497812
+1, 370414, 10836, 0x6c797900
0, 372000, 161280, 0x52f9b931
-1, 375804, 10832, 0x9ee1db54
+1, 375943, 10836, 0x1615df36
0, 378000, 161280, 0x938cf016
-1, 381331, 10832, 0x5277d611
+1, 381471, 10836, 0xb472d9e9
0, 384000, 161280, 0xf8f6e19c
-1, 386857, 10832, 0x570a619c
+1, 387000, 10836, 0xdfff626e
0, 390000, 161280, 0xca90561b
-1, 392384, 10832, 0xa217d70f
+1, 392529, 10836, 0xffa6d771
0, 396000, 161280, 0x8594d06b
-1, 397910, 10832, 0x6f0ecbf4
+1, 398057, 10836, 0xa7f3cf96
0, 402000, 161280, 0xea32bf3b
-1, 403437, 10832, 0x2704b114
+1, 403586, 10836, 0xf556b50a
0, 408000, 161280, 0x4646111a
-1, 408963, 10832, 0xf24e679f
+1, 409114, 10836, 0x99b86b39
0, 414000, 161280, 0xee891162
-1, 414490, 10832, 0x05572099
+1, 414643, 10836, 0x886920d3
0, 420000, 161280, 0xcfc32082
-1, 420016, 10832, 0x33942d0c
-1, 425543, 10832, 0xa77ea674
+1, 420171, 10836, 0xefb0305a
+1, 425700, 10836, 0x4ab7aa32
0, 426000, 161280, 0x863c281a
-1, 431069, 10832, 0xeba663bc
+1, 431229, 10836, 0x7f106530
0, 432000, 161280, 0x01b591aa
-1, 436596, 10832, 0x1338524a
+1, 436757, 10836, 0x6461559a
0, 438000, 161280, 0x211fbc62
-1, 442122, 10832, 0x6182b0b3
+1, 442286, 10836, 0x25e3b12b
0, 444000, 161280, 0xae2bafe2
-1, 447649, 10832, 0xa410a364
+1, 447814, 10836, 0x32cfa3ba
0, 450000, 161280, 0xcfe46dca
-1, 453176, 10832, 0x2f4374b0
+1, 453343, 10836, 0x0bff78a4
0, 456000, 161280, 0xcf8fe8a3
-1, 458702, 10832, 0xf41f3a07
+1, 458871, 10836, 0xe4323d53
0, 462000, 161280, 0x3f8474eb
-1, 464229, 10832, 0x2b1c50c6
+1, 464400, 10836, 0x70b35196
0, 468000, 161280, 0x06da345a
-1, 469755, 10832, 0x3692ac89
+1, 469929, 10836, 0xf2b8b07f
0, 474000, 161280, 0xbd4d3280
-1, 475282, 10832, 0x5d6bc87e
+1, 475457, 10836, 0x826cc972
0, 480000, 161280, 0xb5e70fea
-1, 480808, 10832, 0x1b1cda0c
+1, 480986, 10836, 0x8a0fdce8
0, 486000, 161280, 0x0c99c804
-1, 486335, 10832, 0x11eaa15f
-1, 491861, 10832, 0x73c7d7ef
+1, 486514, 10836, 0xa072a503
0, 492000, 161280, 0x19841ed4
-1, 497388, 10832, 0x65d7e3be
+1, 492043, 10836, 0xd698d8e7
+1, 497571, 10836, 0xfe80e794
0, 498000, 161280, 0xf81dea50
-1, 502914, 10832, 0xb9c00688
+1, 503100, 10836, 0xdd580a5a
0, 504000, 161280, 0x7777d81c
-1, 508441, 10832, 0x0b98c125
+1, 508629, 10836, 0x121bc1bb
0, 510000, 161280, 0x0497cfd8
-1, 513967, 10832, 0x331ed413
+1, 514157, 10836, 0x8cebd7d9
0, 516000, 161280, 0x50b6eb64
-1, 519494, 10832, 0x9b68f485
+1, 519686, 10836, 0x6eaef4d7
0, 522000, 161280, 0x5071fc07
-1, 525020, 10832, 0x1b865c55
+1, 525214, 10836, 0x8f0b5d0b
0, 528000, 161280, 0xbb7527fb
-1, 530547, 10832, 0x68cef565
+1, 530743, 10836, 0x40ccf61f
0, 534000, 161280, 0x13054f1f
-1, 536073, 10832, 0x3a605f15
+1, 536271, 10836, 0xb6db5f1d
0, 540000, 161280, 0x4b78fb27
-1, 541600, 10832, 0xd72ff22e
+1, 541800, 10836, 0xa089f250
0, 546000, 161280, 0xf504968f
-1, 547127, 10832, 0x1c672b67
+1, 547329, 10836, 0xd3512f2b
0, 552000, 161280, 0x555b10b7
-1, 552653, 10832, 0xfd1a7e7e
+1, 552857, 10836, 0xfa127f74
0, 558000, 161280, 0xcc0dde40
-1, 558180, 10832, 0x9bf20ead
-1, 563706, 10832, 0x00000000
+1, 558386, 10836, 0xd6a60ead
+1, 563914, 10836, 0x00000000
0, 564000, 161280, 0xcc0dde40
-1, 569233, 10832, 0x00000000
+1, 569443, 10836, 0x00000000
0, 570000, 161280, 0x367f60c8
-1, 574759, 10832, 0x00000000
+1, 574971, 10836, 0x00000000
0, 576000, 161280, 0x367f60c8
-1, 580286, 10832, 0x00000000
+1, 580500, 10836, 0x00000000
0, 582000, 161280, 0x367f60c8
-1, 585812, 10832, 0x00000000
+1, 586029, 10836, 0x00000000
0, 588000, 161280, 0x367f60c8
-1, 591339, 10832, 0x00000000
+1, 591557, 10836, 0x00000000
0, 594000, 161280, 0x367f60c8
-1, 596865, 10832, 0x00000000
+1, 597086, 10836, 0x00000000
0, 600000, 161280, 0x367f60c8
-1, 602392, 10832, 0x00000000
+1, 602614, 10836, 0x00000000
0, 606000, 161280, 0x367f60c8
-1, 607918, 10832, 0x00000000
+1, 608143, 10836, 0x00000000
0, 612000, 161280, 0x367f60c8
-1, 613445, 10832, 0x00000000
+1, 613671, 10836, 0x00000000
0, 618000, 161280, 0x367f60c8
-1, 618971, 10832, 0x00000000
+1, 619200, 10836, 0x00000000
0, 624000, 161280, 0x367f60c8
diff --git a/tests/ref/fate/truemotion1-24 b/tests/ref/fate/truemotion1-24
index b0b1c4e44e..55576ee6ae 100644
--- a/tests/ref/fate/truemotion1-24
+++ b/tests/ref/fate/truemotion1-24
@@ -1,43 +1,44 @@
0, 0, 69120, 0x68beb30f
-1, 0, 10832, 0x1597b4c8
-1, 5527, 10832, 0xf9479f8b
+1, 0, 10836, 0xedecb6a7
+1, 5529, 10836, 0x8098a323
0, 6000, 69120, 0x3976f5cf
-1, 11053, 10832, 0x8db50e74
+1, 11057, 10836, 0xcfa1112e
0, 12000, 69120, 0xf815bc3c
-1, 16580, 10832, 0x2b33ecbb
+1, 16586, 10836, 0xe241ede4
0, 18000, 69120, 0xa7cc0ae6
-1, 22106, 10832, 0x8d0f537b
+1, 22114, 10836, 0xddf254bb
0, 24000, 69120, 0xd85ac282
-1, 27633, 10832, 0x922081c7
+1, 27643, 10836, 0xa16c8507
0, 30000, 69120, 0xf7fd7edb
-1, 33159, 10832, 0x40291f19
+1, 33171, 10836, 0xbe211f93
0, 36000, 69120, 0x433bb6f6
-1, 38686, 10832, 0x88f5271a
+1, 38700, 10836, 0x26c7283d
0, 42000, 69120, 0xdbac8bee
-1, 44212, 10832, 0x55c6bbe5
+1, 44229, 10836, 0x4d18be56
0, 48000, 69120, 0x88e2a799
-1, 49739, 10832, 0x9b51ae82
+1, 49757, 10836, 0x57b9af6f
0, 54000, 69120, 0x49617b26
-1, 55265, 10832, 0xcdf2409b
+1, 55286, 10836, 0xd5864280
0, 60000, 69120, 0xeb44ca01
-1, 60792, 10832, 0x0933b1a4
+1, 60814, 10836, 0xd582b451
0, 66000, 69120, 0x6fea37e8
-1, 66318, 10832, 0x24b77006
-1, 71845, 10832, 0xf612fa8a
+1, 66343, 10836, 0xec13731d
+1, 71871, 10836, 0xe3d4fbb8
0, 72000, 69120, 0xf55d74c7
-1, 77371, 10832, 0x99884b06
+1, 77400, 10836, 0xcbb54d18
0, 78000, 69120, 0xb5082ca7
-1, 82898, 10832, 0x3c746fbe
+1, 82929, 10836, 0xff7e7133
0, 84000, 69120, 0x5876d758
-1, 88424, 10832, 0x05f3b08a
-1, 93951, 10832, 0xa6560483
-1, 99478, 10832, 0xd98a8e19
-1, 105004, 10832, 0xf98a0b2e
-1, 110531, 10832, 0xb1039582
-1, 116057, 10832, 0x85dd5c3f
-1, 121584, 10832, 0x19fc801a
-1, 127110, 10832, 0x95805089
-1, 132637, 10832, 0x576fdec3
-1, 138163, 10832, 0x704a0905
-1, 143690, 10832, 0xf87ce1fa
-1, 149216, 10832, 0xfc0076b9
+1, 88457, 10836, 0xcc28b1a7
+0, 90000, 69120, 0x45e7dd5c
+1, 93986, 10836, 0xbf9e07a5
+1, 99514, 10836, 0x16408f38
+1, 105043, 10836, 0x2b000c9f
+1, 110571, 10836, 0x0ccd9811
+1, 116100, 10836, 0xf9575d48
+1, 121629, 10836, 0x1ee68190
+1, 127157, 10836, 0xde435373
+1, 132686, 10836, 0xd83be17a
+1, 138214, 10836, 0x9a7f0bbe
+1, 143743, 10836, 0x8709e4d3
+1, 149271, 10836, 0xde1879cb
diff --git a/tests/ref/fate/tscc-32bit b/tests/ref/fate/tscc-32bit
index dd888a85f2..b014471c14 100644
--- a/tests/ref/fate/tscc-32bit
+++ b/tests/ref/fate/tscc-32bit
@@ -11,73 +11,73 @@
0, 60000, 2359296, 0xda3ba3cf
0, 66000, 2359296, 0xda3ba3cf
0, 72000, 2359296, 0xda3ba3cf
-0, 78000, 2359296, 0x60a070fd
-0, 84000, 2359296, 0x42e5fedc
+0, 78000, 2359296, 0xda3ba3cf
+0, 84000, 2359296, 0x60a070fd
0, 90000, 2359296, 0x42e5fedc
-0, 96000, 2359296, 0x699cf990
+0, 96000, 2359296, 0x42e5fedc
0, 102000, 2359296, 0x699cf990
0, 108000, 2359296, 0x699cf990
0, 114000, 2359296, 0x699cf990
0, 120000, 2359296, 0x699cf990
0, 126000, 2359296, 0x699cf990
0, 132000, 2359296, 0x699cf990
-0, 138000, 2359296, 0x1524160c
+0, 138000, 2359296, 0x699cf990
0, 144000, 2359296, 0x1524160c
0, 150000, 2359296, 0x1524160c
0, 156000, 2359296, 0x1524160c
0, 162000, 2359296, 0x1524160c
0, 168000, 2359296, 0x1524160c
0, 174000, 2359296, 0x1524160c
-0, 180000, 2359296, 0x33df0c8c
+0, 180000, 2359296, 0x1524160c
0, 186000, 2359296, 0x33df0c8c
0, 192000, 2359296, 0x33df0c8c
0, 198000, 2359296, 0x33df0c8c
0, 204000, 2359296, 0x33df0c8c
0, 210000, 2359296, 0x33df0c8c
0, 216000, 2359296, 0x33df0c8c
-0, 222000, 2359296, 0xfe3d29f8
+0, 222000, 2359296, 0x33df0c8c
0, 228000, 2359296, 0xfe3d29f8
0, 234000, 2359296, 0xfe3d29f8
0, 240000, 2359296, 0xfe3d29f8
0, 246000, 2359296, 0xfe3d29f8
0, 252000, 2359296, 0xfe3d29f8
0, 258000, 2359296, 0xfe3d29f8
-0, 264000, 2359296, 0x1b9d197f
+0, 264000, 2359296, 0xfe3d29f8
0, 270000, 2359296, 0x1b9d197f
0, 276000, 2359296, 0x1b9d197f
0, 282000, 2359296, 0x1b9d197f
0, 288000, 2359296, 0x1b9d197f
0, 294000, 2359296, 0x1b9d197f
0, 300000, 2359296, 0x1b9d197f
-0, 306000, 2359296, 0x48c126fb
+0, 306000, 2359296, 0x1b9d197f
0, 312000, 2359296, 0x48c126fb
0, 318000, 2359296, 0x48c126fb
0, 324000, 2359296, 0x48c126fb
0, 330000, 2359296, 0x48c126fb
0, 336000, 2359296, 0x48c126fb
0, 342000, 2359296, 0x48c126fb
-0, 348000, 2359296, 0xcaa31c7c
+0, 348000, 2359296, 0x48c126fb
0, 354000, 2359296, 0xcaa31c7c
0, 360000, 2359296, 0xcaa31c7c
0, 366000, 2359296, 0xcaa31c7c
0, 372000, 2359296, 0xcaa31c7c
0, 378000, 2359296, 0xcaa31c7c
0, 384000, 2359296, 0xcaa31c7c
-0, 390000, 2359296, 0xc6a333ee
+0, 390000, 2359296, 0xcaa31c7c
0, 396000, 2359296, 0xc6a333ee
0, 402000, 2359296, 0xc6a333ee
0, 408000, 2359296, 0xc6a333ee
0, 414000, 2359296, 0xc6a333ee
0, 420000, 2359296, 0xc6a333ee
0, 426000, 2359296, 0xc6a333ee
-0, 432000, 2359296, 0xb96d1583
+0, 432000, 2359296, 0xc6a333ee
0, 438000, 2359296, 0xb96d1583
0, 444000, 2359296, 0xb96d1583
0, 450000, 2359296, 0xb96d1583
0, 456000, 2359296, 0xb96d1583
0, 462000, 2359296, 0xb96d1583
0, 468000, 2359296, 0xb96d1583
-0, 474000, 2359296, 0x878135ec
+0, 474000, 2359296, 0xb96d1583
0, 480000, 2359296, 0x878135ec
0, 486000, 2359296, 0x878135ec
0, 492000, 2359296, 0x878135ec
@@ -85,75 +85,76 @@
0, 504000, 2359296, 0x878135ec
0, 510000, 2359296, 0x878135ec
0, 516000, 2359296, 0x878135ec
-0, 522000, 2359296, 0x76922870
+0, 522000, 2359296, 0x878135ec
0, 528000, 2359296, 0x76922870
0, 534000, 2359296, 0x76922870
0, 540000, 2359296, 0x76922870
0, 546000, 2359296, 0x76922870
0, 552000, 2359296, 0x76922870
0, 558000, 2359296, 0x76922870
-0, 564000, 2359296, 0xb0e031f0
+0, 564000, 2359296, 0x76922870
0, 570000, 2359296, 0xb0e031f0
0, 576000, 2359296, 0xb0e031f0
0, 582000, 2359296, 0xb0e031f0
0, 588000, 2359296, 0xb0e031f0
0, 594000, 2359296, 0xb0e031f0
0, 600000, 2359296, 0xb0e031f0
-0, 606000, 2359296, 0xb2ef2a6e
+0, 606000, 2359296, 0xb0e031f0
0, 612000, 2359296, 0xb2ef2a6e
0, 618000, 2359296, 0xb2ef2a6e
-0, 624000, 2359296, 0x083c2474
+0, 624000, 2359296, 0xb2ef2a6e
0, 630000, 2359296, 0x083c2474
0, 636000, 2359296, 0x083c2474
0, 642000, 2359296, 0x083c2474
-0, 648000, 2359296, 0xbdfe2ef3
+0, 648000, 2359296, 0x083c2474
0, 654000, 2359296, 0xbdfe2ef3
0, 660000, 2359296, 0xbdfe2ef3
0, 666000, 2359296, 0xbdfe2ef3
0, 672000, 2359296, 0xbdfe2ef3
0, 678000, 2359296, 0xbdfe2ef3
0, 684000, 2359296, 0xbdfe2ef3
-0, 690000, 2359296, 0x934b1484
+0, 690000, 2359296, 0xbdfe2ef3
0, 696000, 2359296, 0x934b1484
0, 702000, 2359296, 0x934b1484
0, 708000, 2359296, 0x934b1484
-0, 714000, 2359296, 0x3e0d1a7e
+0, 714000, 2359296, 0x934b1484
0, 720000, 2359296, 0x3e0d1a7e
0, 726000, 2359296, 0x3e0d1a7e
-0, 732000, 2359296, 0x3ce539e8
+0, 732000, 2359296, 0x3e0d1a7e
0, 738000, 2359296, 0x3ce539e8
0, 744000, 2359296, 0x3ce539e8
0, 750000, 2359296, 0x3ce539e8
0, 756000, 2359296, 0x3ce539e8
0, 762000, 2359296, 0x3ce539e8
0, 768000, 2359296, 0x3ce539e8
-0, 774000, 2359296, 0xd46c2f69
+0, 774000, 2359296, 0x3ce539e8
0, 780000, 2359296, 0xd46c2f69
0, 786000, 2359296, 0xd46c2f69
0, 792000, 2359296, 0xd46c2f69
0, 798000, 2359296, 0xd46c2f69
0, 804000, 2359296, 0xd46c2f69
0, 810000, 2359296, 0xd46c2f69
-0, 816000, 2359296, 0x8d2933ee
+0, 816000, 2359296, 0xd46c2f69
0, 822000, 2359296, 0x8d2933ee
0, 828000, 2359296, 0x8d2933ee
0, 834000, 2359296, 0x8d2933ee
0, 840000, 2359296, 0x8d2933ee
0, 846000, 2359296, 0x8d2933ee
0, 852000, 2359296, 0x8d2933ee
-0, 858000, 2359296, 0xb6092b6d
+0, 858000, 2359296, 0x8d2933ee
0, 864000, 2359296, 0xb6092b6d
0, 870000, 2359296, 0xb6092b6d
0, 876000, 2359296, 0xb6092b6d
0, 882000, 2359296, 0xb6092b6d
0, 888000, 2359296, 0xb6092b6d
0, 894000, 2359296, 0xb6092b6d
-0, 900000, 2359296, 0xe4ef27fa
+0, 900000, 2359296, 0xb6092b6d
0, 906000, 2359296, 0xe4ef27fa
0, 912000, 2359296, 0xe4ef27fa
0, 918000, 2359296, 0xe4ef27fa
0, 924000, 2359296, 0xe4ef27fa
0, 930000, 2359296, 0xe4ef27fa
0, 936000, 2359296, 0xe4ef27fa
-0, 942000, 2359296, 0x5e5b2672
+0, 942000, 2359296, 0xe4ef27fa
0, 948000, 2359296, 0x5e5b2672
+0, 954000, 2359296, 0x5e5b2672
diff --git a/tests/ref/fate/vmnc-32bit b/tests/ref/fate/vmnc-32bit
index fa3d6a07aa..4486ff92e5 100644
--- a/tests/ref/fate/vmnc-32bit
+++ b/tests/ref/fate/vmnc-32bit
@@ -3,28 +3,28 @@
0, 36000, 3655644, 0x3c3167fd
0, 54000, 3655644, 0x87973530
0, 72000, 3655644, 0x87973530
-0, 90000, 3655644, 0x3c3167fd
+0, 90000, 3655644, 0x87973530
0, 108000, 3655644, 0x3c3167fd
-0, 126000, 3655644, 0x87973530
+0, 126000, 3655644, 0x3c3167fd
0, 144000, 3655644, 0x87973530
0, 162000, 3655644, 0x87973530
0, 180000, 3655644, 0x87973530
-0, 198000, 3655644, 0x3c3167fd
-0, 216000, 3655644, 0x87973530
+0, 198000, 3655644, 0x87973530
+0, 216000, 3655644, 0x3c3167fd
0, 234000, 3655644, 0x87973530
0, 252000, 3655644, 0x87973530
-0, 270000, 3655644, 0x4f0da763
+0, 270000, 3655644, 0x87973530
0, 288000, 3655644, 0x4f0da763
0, 306000, 3655644, 0x4f0da763
-0, 324000, 3655644, 0x66a4a763
-0, 342000, 3655644, 0xb20a7496
-0, 360000, 3655644, 0x66a4a763
+0, 324000, 3655644, 0x4f0da763
+0, 342000, 3655644, 0x66a4a763
+0, 360000, 3655644, 0xb20a7496
0, 378000, 3655644, 0x66a4a763
0, 396000, 3655644, 0x66a4a763
-0, 414000, 3655644, 0x5600644a
-0, 432000, 3655644, 0xce5880ee
+0, 414000, 3655644, 0x66a4a763
+0, 432000, 3655644, 0x5600644a
0, 450000, 3655644, 0xce5880ee
-0, 468000, 3655644, 0xa993ef3d
+0, 468000, 3655644, 0xce5880ee
0, 486000, 3655644, 0xa993ef3d
0, 504000, 3655644, 0xa993ef3d
0, 522000, 3655644, 0xa993ef3d
@@ -47,7 +47,7 @@
0, 828000, 3655644, 0xa993ef3d
0, 846000, 3655644, 0xa993ef3d
0, 864000, 3655644, 0xa993ef3d
-0, 882000, 3655644, 0x73564014
+0, 882000, 3655644, 0xa993ef3d
0, 900000, 3655644, 0x73564014
0, 918000, 3655644, 0x73564014
0, 936000, 3655644, 0x73564014
@@ -59,95 +59,95 @@
0, 1044000, 3655644, 0x73564014
0, 1062000, 3655644, 0x73564014
0, 1080000, 3655644, 0x73564014
-0, 1098000, 3655644, 0x2a6e1e8c
+0, 1098000, 3655644, 0x73564014
0, 1116000, 3655644, 0x2a6e1e8c
0, 1134000, 3655644, 0x2a6e1e8c
-0, 1152000, 3655644, 0xbae02e7c
+0, 1152000, 3655644, 0x2a6e1e8c
0, 1170000, 3655644, 0xbae02e7c
0, 1188000, 3655644, 0xbae02e7c
0, 1206000, 3655644, 0xbae02e7c
-0, 1224000, 3655644, 0x55af4a2d
+0, 1224000, 3655644, 0xbae02e7c
0, 1242000, 3655644, 0x55af4a2d
0, 1260000, 3655644, 0x55af4a2d
0, 1278000, 3655644, 0x55af4a2d
-0, 1296000, 3655644, 0x54b7ff2d
-0, 1314000, 3655644, 0x39af1aed
+0, 1296000, 3655644, 0x55af4a2d
+0, 1314000, 3655644, 0x54b7ff2d
0, 1332000, 3655644, 0x39af1aed
0, 1350000, 3655644, 0x39af1aed
0, 1368000, 3655644, 0x39af1aed
-0, 1386000, 3655644, 0xe48dd11c
+0, 1386000, 3655644, 0x39af1aed
0, 1404000, 3655644, 0xe48dd11c
0, 1422000, 3655644, 0xe48dd11c
0, 1440000, 3655644, 0xe48dd11c
0, 1458000, 3655644, 0xe48dd11c
-0, 1476000, 3655644, 0xba15c78d
+0, 1476000, 3655644, 0xe48dd11c
0, 1494000, 3655644, 0xba15c78d
0, 1512000, 3655644, 0xba15c78d
0, 1530000, 3655644, 0xba15c78d
0, 1548000, 3655644, 0xba15c78d
0, 1566000, 3655644, 0xba15c78d
0, 1584000, 3655644, 0xba15c78d
-0, 1602000, 3655644, 0x39af1aed
+0, 1602000, 3655644, 0xba15c78d
0, 1620000, 3655644, 0x39af1aed
0, 1638000, 3655644, 0x39af1aed
0, 1656000, 3655644, 0x39af1aed
0, 1674000, 3655644, 0x39af1aed
0, 1692000, 3655644, 0x39af1aed
0, 1710000, 3655644, 0x39af1aed
-0, 1728000, 3655644, 0x27f96cd8
+0, 1728000, 3655644, 0x39af1aed
0, 1746000, 3655644, 0x27f96cd8
0, 1764000, 3655644, 0x27f96cd8
0, 1782000, 3655644, 0x27f96cd8
0, 1800000, 3655644, 0x27f96cd8
0, 1818000, 3655644, 0x27f96cd8
0, 1836000, 3655644, 0x27f96cd8
-0, 1854000, 3655644, 0xf4f068dc
+0, 1854000, 3655644, 0x27f96cd8
0, 1872000, 3655644, 0xf4f068dc
0, 1890000, 3655644, 0xf4f068dc
0, 1908000, 3655644, 0xf4f068dc
0, 1926000, 3655644, 0xf4f068dc
0, 1944000, 3655644, 0xf4f068dc
0, 1962000, 3655644, 0xf4f068dc
-0, 1980000, 3655644, 0xf1c55cf5
-0, 1998000, 3655644, 0xd932633d
+0, 1980000, 3655644, 0xf4f068dc
+0, 1998000, 3655644, 0xf1c55cf5
0, 2016000, 3655644, 0xd932633d
-0, 2034000, 3655644, 0xc6e95e0a
-0, 2052000, 3655644, 0x9a63c9de
-0, 2070000, 3655644, 0xf166ad4f
-0, 2088000, 3655644, 0xe9eeba41
-0, 2106000, 3655644, 0x7e598ad7
-0, 2124000, 3655644, 0xf3bd257e
+0, 2034000, 3655644, 0xd932633d
+0, 2052000, 3655644, 0xc6e95e0a
+0, 2070000, 3655644, 0x9a63c9de
+0, 2088000, 3655644, 0xf166ad4f
+0, 2106000, 3655644, 0xe9eeba41
+0, 2124000, 3655644, 0x7e598ad7
0, 2142000, 3655644, 0xf3bd257e
0, 2160000, 3655644, 0xf3bd257e
0, 2178000, 3655644, 0xf3bd257e
0, 2196000, 3655644, 0xf3bd257e
-0, 2214000, 3655644, 0xf35b3852
+0, 2214000, 3655644, 0xf3bd257e
0, 2232000, 3655644, 0xf35b3852
0, 2250000, 3655644, 0xf35b3852
0, 2268000, 3655644, 0xf35b3852
-0, 2286000, 3655644, 0x9d553959
-0, 2304000, 3655644, 0x0a9de8e2
-0, 2322000, 3655644, 0xf2325b6c
+0, 2286000, 3655644, 0xf35b3852
+0, 2304000, 3655644, 0x9d553959
+0, 2322000, 3655644, 0x0a9de8e2
0, 2340000, 3655644, 0xf2325b6c
0, 2358000, 3655644, 0xf2325b6c
0, 2376000, 3655644, 0xf2325b6c
0, 2394000, 3655644, 0xf2325b6c
0, 2412000, 3655644, 0xf2325b6c
-0, 2430000, 3655644, 0xcf924028
+0, 2430000, 3655644, 0xf2325b6c
0, 2448000, 3655644, 0xcf924028
-0, 2466000, 3655644, 0x8dae55bc
+0, 2466000, 3655644, 0xcf924028
0, 2484000, 3655644, 0x8dae55bc
-0, 2502000, 3655644, 0x57b08ced
+0, 2502000, 3655644, 0x8dae55bc
0, 2520000, 3655644, 0x57b08ced
-0, 2538000, 3655644, 0xef89a1d8
+0, 2538000, 3655644, 0x57b08ced
0, 2556000, 3655644, 0xef89a1d8
-0, 2574000, 3655644, 0x69e5503a
+0, 2574000, 3655644, 0xef89a1d8
0, 2592000, 3655644, 0x69e5503a
-0, 2610000, 3655644, 0xc3de7b3f
+0, 2610000, 3655644, 0x69e5503a
0, 2628000, 3655644, 0xc3de7b3f
-0, 2646000, 3655644, 0x88eea64a
+0, 2646000, 3655644, 0xc3de7b3f
0, 2664000, 3655644, 0x88eea64a
-0, 2682000, 3655644, 0xe39cce1f
+0, 2682000, 3655644, 0x88eea64a
0, 2700000, 3655644, 0xe39cce1f
0, 2718000, 3655644, 0xe39cce1f
0, 2736000, 3655644, 0xe39cce1f
@@ -160,12 +160,13 @@
0, 2862000, 3655644, 0xe39cce1f
0, 2880000, 3655644, 0xe39cce1f
0, 2898000, 3655644, 0xe39cce1f
-0, 2916000, 3655644, 0xf0ed0d04
+0, 2916000, 3655644, 0xe39cce1f
0, 2934000, 3655644, 0xf0ed0d04
0, 2952000, 3655644, 0xf0ed0d04
0, 2970000, 3655644, 0xf0ed0d04
-0, 2988000, 3655644, 0x32490d3e
+0, 2988000, 3655644, 0xf0ed0d04
0, 3006000, 3655644, 0x32490d3e
0, 3024000, 3655644, 0x32490d3e
0, 3042000, 3655644, 0x32490d3e
0, 3060000, 3655644, 0x32490d3e
+0, 3078000, 3655644, 0x32490d3e
diff --git a/tests/ref/fate/vp5 b/tests/ref/fate/vp5
index bf67801a47..556d1112d7 100644
--- a/tests/ref/fate/vp5
+++ b/tests/ref/fate/vp5
@@ -244,3 +244,4 @@
0, 912161, 233472, 0x6f530ac6
0, 915915, 233472, 0x94f7466c
0, 919669, 233472, 0xa8c1d365
+0, 923423, 233472, 0xedcff050
diff --git a/tests/ref/fate/vp8-sign-bias b/tests/ref/fate/vp8-sign-bias
index 4e4f6c4b2d..db007b5385 100644
--- a/tests/ref/fate/vp8-sign-bias
+++ b/tests/ref/fate/vp8-sign-bias
@@ -1,9 +1,10 @@
0, 0, 614880, 12ce23b288485be3ddbc1db28c21517f
0, 3750, 614880, ce352e1079535ea058c0e9ad50f7cdb8
-0, 7500, 614880, 9f6bf2739a027dfd12c81586cf75d3a3
-0, 11250, 614880, 7593a85ab7790eb39d65fc53f769ed8b
-0, 15000, 614880, 52f47f1e0348f3297d9f233fb5405e8b
-0, 18750, 614880, cd51d2c200bfd66e8e1b0fd6b404570f
-0, 22500, 614880, cf535cf0a53e903cd98a9a944b72da6d
-0, 26250, 614880, 1b270fd2b56daa7892102c2885d23201
-0, 30000, 614880, ff373c0c8a4a319c84e72b1c3d76b399
+0, 7500, 614880, ce352e1079535ea058c0e9ad50f7cdb8
+0, 11250, 614880, 9f6bf2739a027dfd12c81586cf75d3a3
+0, 15000, 614880, 7593a85ab7790eb39d65fc53f769ed8b
+0, 18750, 614880, 52f47f1e0348f3297d9f233fb5405e8b
+0, 22500, 614880, cd51d2c200bfd66e8e1b0fd6b404570f
+0, 26250, 614880, cf535cf0a53e903cd98a9a944b72da6d
+0, 30000, 614880, 1b270fd2b56daa7892102c2885d23201
+0, 33750, 614880, ff373c0c8a4a319c84e72b1c3d76b399
diff --git a/tests/ref/fate/zmbv-8bit b/tests/ref/fate/zmbv-8bit
index 258147f914..75a212b3c9 100644
--- a/tests/ref/fate/zmbv-8bit
+++ b/tests/ref/fate/zmbv-8bit
@@ -273,3 +273,4 @@
0, 349284, 192000, 0xd08e49d1
0, 350568, 192000, 0xd08e49d1
0, 351852, 192000, 0xd08e49d1
+0, 353136, 192000, 0x1f34135f
diff --git a/tests/ref/lavf/dv_fmt b/tests/ref/lavf/dv_fmt
index 7406dff532..ded1cee6d2 100644
--- a/tests/ref/lavf/dv_fmt
+++ b/tests/ref/lavf/dv_fmt
@@ -1,3 +1,3 @@
-522e5e5a46b99f8ad8aabdaf3d2f1869 *./tests/data/lavf/lavf.dv
+3a6a9163a67b729b4a6b5d972ccceb97 *./tests/data/lavf/lavf.dv
3600000 ./tests/data/lavf/lavf.dv
-./tests/data/lavf/lavf.dv CRC=0x02c0af30
+./tests/data/lavf/lavf.dv CRC=0x5ce4e5e4
diff --git a/tests/ref/lavf/ffm b/tests/ref/lavf/ffm
index b89af6e3e5..f9a8f6740f 100644
--- a/tests/ref/lavf/ffm
+++ b/tests/ref/lavf/ffm
@@ -1,3 +1,3 @@
-b6acf782a38d313153b68c4ca204fc90 *./tests/data/lavf/lavf.ffm
+58a0235967d10543268184eea50a3b65 *./tests/data/lavf/lavf.ffm
376832 ./tests/data/lavf/lavf.ffm
./tests/data/lavf/lavf.ffm CRC=0xf361ed74
diff --git a/tests/ref/lavf/gif b/tests/ref/lavf/gif
index fa55d0e66e..4a4ebfb9dc 100644
--- a/tests/ref/lavf/gif
+++ b/tests/ref/lavf/gif
@@ -1,3 +1,3 @@
-98968ceb210ab260a6a7af36767b94d3 *./tests/data/lavf/lavf.gif
-2906382 ./tests/data/lavf/lavf.gif
+e6089fd4ef3b9df44090ab3650bdd810 *./tests/data/lavf/lavf.gif
+2906401 ./tests/data/lavf/lavf.gif
./tests/data/lavf/lavf.gif CRC=0xe5605ff6
diff --git a/tests/ref/lavf/gxf b/tests/ref/lavf/gxf
index 6b39c2f273..68bc9785a2 100644
--- a/tests/ref/lavf/gxf
+++ b/tests/ref/lavf/gxf
@@ -1,3 +1,3 @@
346d38d330ab5cb0caa6b5537167bc0d *./tests/data/lavf/lavf.gxf
796392 ./tests/data/lavf/lavf.gxf
-./tests/data/lavf/lavf.gxf CRC=0x345f86eb
+./tests/data/lavf/lavf.gxf CRC=0x102918fd
diff --git a/tests/ref/lavf/mov b/tests/ref/lavf/mov
index 22aac3600e..2071c5a743 100644
--- a/tests/ref/lavf/mov
+++ b/tests/ref/lavf/mov
@@ -1,3 +1,3 @@
-439684b82ccc1fdd24a23392c238ae53 *./tests/data/lavf/lavf.mov
+2e2529d01dbe42e4dd63580a351898f5 *./tests/data/lavf/lavf.mov
357681 ./tests/data/lavf/lavf.mov
./tests/data/lavf/lavf.mov CRC=0x2f6a9b26
diff --git a/tests/ref/lavf/mxf b/tests/ref/lavf/mxf
index d4bbe2f25e..73eb307081 100644
--- a/tests/ref/lavf/mxf
+++ b/tests/ref/lavf/mxf
@@ -1,6 +1,3 @@
-6e9bd63c5cadd7550ad313553ebf665f *./tests/data/lavf/lavf.mxf
+785e38ddd2466046f30aa36399b8f8fa *./tests/data/lavf/lavf.mxf
525881 ./tests/data/lavf/lavf.mxf
-./tests/data/lavf/lavf.mxf CRC=0x4ace0849
-e7168856f2b54c6272685967e707fb21 *./tests/data/lavf/lavf.mxf_d10
-5330989 ./tests/data/lavf/lavf.mxf_d10
-./tests/data/lavf/lavf.mxf_d10 CRC=0xc3f4f92e
+./tests/data/lavf/lavf.mxf CRC=0x4ace0849 \ No newline at end of file
diff --git a/tests/ref/lavf/mxf_d10 b/tests/ref/lavf/mxf_d10
new file mode 100644
index 0000000000..efeac5a2c0
--- /dev/null
+++ b/tests/ref/lavf/mxf_d10
@@ -0,0 +1,3 @@
+23177c8a72f34e243e9ffc4f6c70d3c7 *./tests/data/lavf/lavf.mxf_d10
+5330989 ./tests/data/lavf/lavf.mxf_d10
+./tests/data/lavf/lavf.mxf_d10 CRC=0x81602ff1
diff --git a/tests/ref/lavf/pixfmt b/tests/ref/lavf/pixfmt
index 186dde5ed3..bf62d9059b 100644
--- a/tests/ref/lavf/pixfmt
+++ b/tests/ref/lavf/pixfmt
@@ -16,21 +16,21 @@ e176bd14185788110e055f945de7f95f *./tests/data/pixfmt/yuvj420p.yuv
304128 ./tests/data/pixfmt/yuvj422p.yuv
c10442da177c9f1d12be3c53be6fa12c *./tests/data/pixfmt/yuvj444p.yuv
304128 ./tests/data/pixfmt/yuvj444p.yuv
-c6e0f9b5817f484b175c1ec4ffb4e9c9 *./tests/data/pixfmt/rgb24.yuv
+6bb61113e7b70eb09dbcec356122a0e2 *./tests/data/pixfmt/rgb24.yuv
304128 ./tests/data/pixfmt/rgb24.yuv
-c6e0f9b5817f484b175c1ec4ffb4e9c9 *./tests/data/pixfmt/bgr24.yuv
+6bb61113e7b70eb09dbcec356122a0e2 *./tests/data/pixfmt/bgr24.yuv
304128 ./tests/data/pixfmt/bgr24.yuv
-c6e0f9b5817f484b175c1ec4ffb4e9c9 *./tests/data/pixfmt/rgb32.yuv
+6bb61113e7b70eb09dbcec356122a0e2 *./tests/data/pixfmt/rgb32.yuv
304128 ./tests/data/pixfmt/rgb32.yuv
-66d39d464bd89ded2a124897f0a75ade *./tests/data/pixfmt/rgb565.yuv
+efa7c0337cc00c796c6df615223716f1 *./tests/data/pixfmt/rgb565.yuv
304128 ./tests/data/pixfmt/rgb565.yuv
-c894c3bd8d2631ed1964500b90a0c350 *./tests/data/pixfmt/rgb555.yuv
+0df2a477af1415a1b8fbf2a3e552bc39 *./tests/data/pixfmt/rgb555.yuv
304128 ./tests/data/pixfmt/rgb555.yuv
6be306b0cce5f8e6c271ea17fef9745b *./tests/data/pixfmt/gray.yuv
304128 ./tests/data/pixfmt/gray.yuv
-31398104d2349dd48328a6862bc6711f *./tests/data/pixfmt/monow.yuv
+6c719671e39f1bcf67b47eab98fa529b *./tests/data/pixfmt/monow.yuv
304128 ./tests/data/pixfmt/monow.yuv
-31398104d2349dd48328a6862bc6711f *./tests/data/pixfmt/monob.yuv
+6c719671e39f1bcf67b47eab98fa529b *./tests/data/pixfmt/monob.yuv
304128 ./tests/data/pixfmt/monob.yuv
00b85790df5740bab95e2559d81603a7 *./tests/data/pixfmt/yuv440p.yuv
304128 ./tests/data/pixfmt/yuv440p.yuv
diff --git a/tests/ref/lavf/ts b/tests/ref/lavf/ts
index 989f8fbfba..3b2dad1b5e 100644
--- a/tests/ref/lavf/ts
+++ b/tests/ref/lavf/ts
@@ -1,3 +1,3 @@
-d260ac0534ff2e26b44b5192fd4fdc21 *./tests/data/lavf/lavf.ts
+151774afed45b19da9b7e83613a1e72b *./tests/data/lavf/lavf.ts
406644 ./tests/data/lavf/lavf.ts
./tests/data/lavf/lavf.ts CRC=0x133216c1
diff --git a/tests/ref/lavf/wav b/tests/ref/lavf/wav
index aa6f943724..bbbacc3b7e 100644
--- a/tests/ref/lavf/wav
+++ b/tests/ref/lavf/wav
@@ -1,3 +1,3 @@
-6a3bec31d92baf52161e25179ebba315 *./tests/data/lavf/lavf.wav
-90156 ./tests/data/lavf/lavf.wav
+8854ea97f2d2172383941b001c69228b *./tests/data/lavf/lavf.wav
+90158 ./tests/data/lavf/lavf.wav
./tests/data/lavf/lavf.wav CRC=0xf1ae5536
diff --git a/tests/ref/lavfi/pixdesc b/tests/ref/lavfi/pixdesc
index 8695b1dea2..0b18dfb7da 100644
--- a/tests/ref/lavfi/pixdesc
+++ b/tests/ref/lavfi/pixdesc
@@ -1,8 +1,8 @@
abgr 037bf9df6a765520ad6d490066bf4b89
argb c442a8261c2265a07212ef0f72e35f5a
bgr24 0d0cb38ab3fa0b2ec0865c14f78b217b
-bgr48be 74dedaaacae8fd1ef46e05f78cf29d62
-bgr48le 0eb7d30801eac6058814bddd330b3c76
+bgr48be 00624e6c7ec7ab19897ba2f0a3257fe8
+bgr48le d02c235ebba7167881ca2d576497ff84
bgr4_byte 50d23cc82d9dcef2fd12adb81fb9b806
bgr555be 49f01b1f1f0c84fd9e776dd34cc3c280
bgr555le 378d6ac4223651a1adcbf94a3d0d807b
@@ -11,15 +11,15 @@ bgr565le 1dfdd03995c287e3c754b164bf26a355
bgr8 24bd566170343d06fec6fccfff5abc54
bgra 76a18a5151242fa137133f604cd624d2
gray db08f7f0751900347e6b8649e4164d21
-gray16be 7becf34ae825a3df3969bf4c6bfeb5e2
-gray16le 10bd87059b5c189f3caef2837f4f2b5c
+gray16be b44458c2254aa7a3d7b8dbf53be91979
+gray16le ecda5143f8a55fca1f6c7dfb238ddcba
monob 668ebe8b8103b9046b251b2fa8a1d88f
monow 9251497f3b0634f1165d12d5a289d943
nv12 e0af357888584d36eec5aa0f673793ef
nv21 9a3297f3b34baa038b1f37cb202b512f
rgb24 b41eba9651e1b5fe386289b506188105
-rgb48be e3bc84c9af376fb6d0f0293cc7b713a6
-rgb48le f51c0e71638a822458329abb2f4052c7
+rgb48be cc139ec1dd9451f0e049c0cb3a0c8aa2
+rgb48le 86c5608904f75360d492dbc5c9589969
rgb4_byte c93ba89b74c504e7f5ae9d9ab1546c73
rgb555be 912a62c5e53bfcbac2a0340e10973cf2
rgb555le a937a0fc764fb57dc1b3af87cba0273c
@@ -31,19 +31,27 @@ uyvy422 adcf64516a19fce44df77082bdb16291
yuv410p 2d9225153c83ee1132397d619d94d1b3
yuv411p 8b298af3e43348ca1b11eb8a3252ac6c
yuv420p eba2f135a08829387e2f698ff72a2939
-yuv420p10be 7605e266c088d0fcf68c7b27c3ceff5f
-yuv420p10le 4228ee628c6deec123a13b9784516cc7
-yuv420p16be 16c009a235cd52b74791a895423152a3
-yuv420p16le 2d59c4f1d0314a5a957a7cfc4b6fabcc
-yuv420p9be ce880fa07830e5297c22acf6e20555ce
-yuv420p9le 16543fda8f87d94a6cf857d2e8d4461a
+yuv420p10be ea2aee509286fa3d07a6c68fec9967a5
+yuv420p10le 645ef73e06de41c83a7bc724179d2ce3
+yuv420p16be ba858ff4246368c28f03152487f57ef3
+yuv420p16le de239729a4fe1d4cfa3743e006654e78
+yuv420p9be 64e36fd90573f67ac2006d103972a79b
+yuv420p9le 9ed4b1dfabc53fd9e586ff6c4c43af80
yuv422p c9bba4529821d796a6ab09f6a5fd355a
-yuv422p16be 86ad3447f97969ce095afeef81fa9abf
-yuv422p16le a53a9b451f4a81eeae33362c1bbd07f8
+yuv422p10be bdc13b630fd668b34c6fe1aae28dfc71
+yuv422p10le d0607c260a45c973e6639f4e449730ad
+yuv422p16be 4e9b3b3467aeebb6a528cee5966800ed
+yuv422p16le f87c81bf16916b64d201359be0b4b6f4
+yuv422p9be 29b71579946940a8c00fa844c9dff507
+yuv422p9le 062b7f9cbb972bf36b5bdb1a7623701a
yuv440p 5a064afe2b453bb52cdb3f176b1aa1cf
yuv444p 0a98447b78fd476aa39686da6a74fa2e
-yuv444p16be 95db370ae765dd3d10b7def14704ae73
-yuv444p16le 36b969179b5ad9d312a0d1e1cd6bc402
+yuv444p10be e65cbae7e4f1892c23defbc8e8052cf6
+yuv444p10le 767179dd82846cf00ee4c340c9c1ab74
+yuv444p16be 3ad639fff73e56f3b09dd20c335478d6
+yuv444p16le 8a7e66dc91ab7971fd24a9105ff2699b
+yuv444p9be 6ab31f4c12b533ce318ecdff83cdd054
+yuv444p9le f0606604a5c08becab6ba500124c4b7c
yuva420p a29884f3f3dfe1e00b961bc17bef3d47
yuvj420p 32eec78ba51857b16ce9b813a49b7189
yuvj422p 0dfa0ed434f73be51428758c69e082cb
diff --git a/tests/ref/lavfi/pixfmts_copy b/tests/ref/lavfi/pixfmts_copy
index 8695b1dea2..0b18dfb7da 100644
--- a/tests/ref/lavfi/pixfmts_copy
+++ b/tests/ref/lavfi/pixfmts_copy
@@ -1,8 +1,8 @@
abgr 037bf9df6a765520ad6d490066bf4b89
argb c442a8261c2265a07212ef0f72e35f5a
bgr24 0d0cb38ab3fa0b2ec0865c14f78b217b
-bgr48be 74dedaaacae8fd1ef46e05f78cf29d62
-bgr48le 0eb7d30801eac6058814bddd330b3c76
+bgr48be 00624e6c7ec7ab19897ba2f0a3257fe8
+bgr48le d02c235ebba7167881ca2d576497ff84
bgr4_byte 50d23cc82d9dcef2fd12adb81fb9b806
bgr555be 49f01b1f1f0c84fd9e776dd34cc3c280
bgr555le 378d6ac4223651a1adcbf94a3d0d807b
@@ -11,15 +11,15 @@ bgr565le 1dfdd03995c287e3c754b164bf26a355
bgr8 24bd566170343d06fec6fccfff5abc54
bgra 76a18a5151242fa137133f604cd624d2
gray db08f7f0751900347e6b8649e4164d21
-gray16be 7becf34ae825a3df3969bf4c6bfeb5e2
-gray16le 10bd87059b5c189f3caef2837f4f2b5c
+gray16be b44458c2254aa7a3d7b8dbf53be91979
+gray16le ecda5143f8a55fca1f6c7dfb238ddcba
monob 668ebe8b8103b9046b251b2fa8a1d88f
monow 9251497f3b0634f1165d12d5a289d943
nv12 e0af357888584d36eec5aa0f673793ef
nv21 9a3297f3b34baa038b1f37cb202b512f
rgb24 b41eba9651e1b5fe386289b506188105
-rgb48be e3bc84c9af376fb6d0f0293cc7b713a6
-rgb48le f51c0e71638a822458329abb2f4052c7
+rgb48be cc139ec1dd9451f0e049c0cb3a0c8aa2
+rgb48le 86c5608904f75360d492dbc5c9589969
rgb4_byte c93ba89b74c504e7f5ae9d9ab1546c73
rgb555be 912a62c5e53bfcbac2a0340e10973cf2
rgb555le a937a0fc764fb57dc1b3af87cba0273c
@@ -31,19 +31,27 @@ uyvy422 adcf64516a19fce44df77082bdb16291
yuv410p 2d9225153c83ee1132397d619d94d1b3
yuv411p 8b298af3e43348ca1b11eb8a3252ac6c
yuv420p eba2f135a08829387e2f698ff72a2939
-yuv420p10be 7605e266c088d0fcf68c7b27c3ceff5f
-yuv420p10le 4228ee628c6deec123a13b9784516cc7
-yuv420p16be 16c009a235cd52b74791a895423152a3
-yuv420p16le 2d59c4f1d0314a5a957a7cfc4b6fabcc
-yuv420p9be ce880fa07830e5297c22acf6e20555ce
-yuv420p9le 16543fda8f87d94a6cf857d2e8d4461a
+yuv420p10be ea2aee509286fa3d07a6c68fec9967a5
+yuv420p10le 645ef73e06de41c83a7bc724179d2ce3
+yuv420p16be ba858ff4246368c28f03152487f57ef3
+yuv420p16le de239729a4fe1d4cfa3743e006654e78
+yuv420p9be 64e36fd90573f67ac2006d103972a79b
+yuv420p9le 9ed4b1dfabc53fd9e586ff6c4c43af80
yuv422p c9bba4529821d796a6ab09f6a5fd355a
-yuv422p16be 86ad3447f97969ce095afeef81fa9abf
-yuv422p16le a53a9b451f4a81eeae33362c1bbd07f8
+yuv422p10be bdc13b630fd668b34c6fe1aae28dfc71
+yuv422p10le d0607c260a45c973e6639f4e449730ad
+yuv422p16be 4e9b3b3467aeebb6a528cee5966800ed
+yuv422p16le f87c81bf16916b64d201359be0b4b6f4
+yuv422p9be 29b71579946940a8c00fa844c9dff507
+yuv422p9le 062b7f9cbb972bf36b5bdb1a7623701a
yuv440p 5a064afe2b453bb52cdb3f176b1aa1cf
yuv444p 0a98447b78fd476aa39686da6a74fa2e
-yuv444p16be 95db370ae765dd3d10b7def14704ae73
-yuv444p16le 36b969179b5ad9d312a0d1e1cd6bc402
+yuv444p10be e65cbae7e4f1892c23defbc8e8052cf6
+yuv444p10le 767179dd82846cf00ee4c340c9c1ab74
+yuv444p16be 3ad639fff73e56f3b09dd20c335478d6
+yuv444p16le 8a7e66dc91ab7971fd24a9105ff2699b
+yuv444p9be 6ab31f4c12b533ce318ecdff83cdd054
+yuv444p9le f0606604a5c08becab6ba500124c4b7c
yuva420p a29884f3f3dfe1e00b961bc17bef3d47
yuvj420p 32eec78ba51857b16ce9b813a49b7189
yuvj422p 0dfa0ed434f73be51428758c69e082cb
diff --git a/tests/ref/lavfi/pixfmts_crop b/tests/ref/lavfi/pixfmts_crop
index c7b59527fb..f0b88110e6 100644
--- a/tests/ref/lavfi/pixfmts_crop
+++ b/tests/ref/lavfi/pixfmts_crop
@@ -1,8 +1,8 @@
abgr cd761690872843d1b7ab0c695393c751
argb 2ec6ef18769bcd651c2e8904d5a3ee67
bgr24 3450fd00cf1493d1ded75544d82ba3ec
-bgr48be a9a7d177cef0914d3f1d266f00dff676
-bgr48le b475d1b529ed80c728ddbacd22d35281
+bgr48be 18ca4002732f278cc9f525215c2fca41
+bgr48le 395a4c187c4e95217d089bd3df9f3654
bgr4_byte 2f6ac3cdd4676ab4e2982bdf0664945b
bgr555be d3a7c273604723adeb7e5f5dd1c4272b
bgr555le d22442fc13b464f9ba455b08df4e981f
@@ -11,11 +11,11 @@ bgr565le 891664e5a54ae5968901347da92bc5e9
bgr8 4b7159e05765bd4703180072d86423c8
bgra 395c9f706fccda721471acaa5c96c16c
gray 8c4850e66562a587a292dc728a65ea4a
-gray16be daa5a6b98fb4a280c57c57bff1a2ab5a
-gray16le 84f5ea7259073edcb893113b42213c8e
+gray16be 257b4339925b0e672f552d8c9511f2c3
+gray16le 67cf7b26cda55356cc25e0f4e42cc136
rgb24 3b90ed64b687d3dc186c6ef521dc71a8
-rgb48be b8f9fd6aaa24d75275ee2f8b8a7b9e55
-rgb48le 3e52e831a040f086c3ae983241172cce
+rgb48be e6fd353c0eb9bea889423954414bea35
+rgb48le 68a1723da11ce08b502d42e204376503
rgb4_byte 6958029f73c6cdfed4f71020d816f027
rgb555be 41a7d1836837bc90f2cae19a9c9df3b3
rgb555le eeb78f8ce6186fba55c941469e60ba67
@@ -26,15 +26,15 @@ rgba fd00b24c7597268c32759a84a1de2de4
yuv410p a9f2eaa747bf988b7bebe4f442b9c67a
yuv411p 3334d3aef8dba238658090ac172375d1
yuv420p bfea0188ddd4889787c403caae119cc7
-yuv420p16be 8365eff38b8c329aeb95fc605fa229bb
-yuv420p16le 5e8dd38d973d5854abe1ad4efad20cc1
+yuv420p16be eb2f96b638a174377f5fc42cfc849ff5
+yuv420p16le 3eae4c172d620b6d4ef2aeca403c4f54
yuv422p f2f930a91fe00d4252c4720b5ecd8961
-yuv422p16be 6647fe1c381c148f8207c988c0e22bf0
-yuv422p16le e1548c9dc51202db38a9625c8954203f
+yuv422p16be 167e4338811a7d272925a4c6417d60da
+yuv422p16le 3359395d5875d581fa1e975013d30114
yuv440p 2472417d980e395ad6843cbb8b633b29
yuv444p 1f151980486848c96bc5585ced99003e
-yuv444p16be ac3b159f8c858fcdf475a8c024ee79b6
-yuv444p16le 9a6863bfc5faee206065c11dc994bf0c
+yuv444p16be 5d0c0ea66ab43c0c590d8c2a9256e43f
+yuv444p16le 3c0a747c1b64feb0ab8dfba92f92579a
yuva420p 7536753dfbc7932560fb50c921369a0e
yuvj420p 21f891093006d42d7683b0e1d773a657
yuvj422p 9a43d474c407590ad8f213880586b45e
diff --git a/tests/ref/lavfi/pixfmts_hflip b/tests/ref/lavfi/pixfmts_hflip
index 7f4342f35c..baaf9add77 100644
--- a/tests/ref/lavfi/pixfmts_hflip
+++ b/tests/ref/lavfi/pixfmts_hflip
@@ -1,8 +1,8 @@
abgr 49468c6c9ceee5d52b08b1270a909323
argb 50ba9f16c6475530602f2983278b82d0
bgr24 cc53d2011d097972db0d22756c3699e3
-bgr48be 90374bc92471f1bd4931d71ef8b73f50
-bgr48le 696f628d0dd32121e60a0d61ac47d6e6
+bgr48be 815192d3757c66de97b0d51818acbe0f
+bgr48le 8e4184ac6eae251b4bace51dba7d790c
bgr4_byte aac987e7d1a6a96477cfc0b48a4285de
bgr555be bc07265898440116772200390d70c092
bgr555le ccee08679bac84a1f960c6c9070c5538
@@ -11,11 +11,11 @@ bgr565le 3703466e19e1b52e03a34fd244a8e8e4
bgr8 50b505a889f0428242305acb642da107
bgra 01ca21e7e6a8d1281b4553bde8e8a404
gray 03efcb4ab52a24c0af0e03cfd26c9377
-gray16be 9bcbca979601ddc4869f846f08f3d1dd
-gray16le c1b8965adcc7f847ee343149ff507073
+gray16be 632535b46edec78a6534ef18d37f2b71
+gray16le 5c24e6f847bf9a41a40760c0d15df161
rgb24 754f1722fc738590cc407ac65749bfe8
-rgb48be 2397b9d3c296ac15f8a2325a703f81c7
-rgb48le 527043c72546d8b4bb1ce2dea4b294c3
+rgb48be d690412ca5fada031b5da47b87096248
+rgb48le c901feb564232f5d0bc0eabd66dae3e7
rgb4_byte c8a3f995fcf3e0919239ea2c413ddc29
rgb555be 045ce8607d3910586f4d97481dda8632
rgb555le 8778ee0cf58ce9ad1d99a1eca9f95e87
@@ -26,15 +26,15 @@ rgba d3d0dc1ecef3ed72f26a2986d0efc204
yuv410p acb543ebbbf63eefe533e6faffc006da
yuv411p c626cf6d191139b4ca7efc0155f957f1
yuv420p 2d5c80f9ba2ddd85b2aeda3564cc7d64
-yuv420p16be 758b0c1e2113b15e7afde48da4e4d024
-yuv420p16le 480ccd951dcb806bc875d307e02e50a0
+yuv420p16be 1c4fa93d0744de3cdc6d34ab55db3fb4
+yuv420p16le 92c74f5759068c381e4a066fe7faf2e0
yuv422p 6e728f4eb9eae287c224f396d84be6ea
-yuv422p16be 9dbe0af0eb877987611cf04bfa577202
-yuv422p16le 2d8f37231110177cc5e1b61c8cb4b163
+yuv422p16be 69cf0605496c321546899a8442ee64fb
+yuv422p16le f0b443fea72f4b6f462859a73b159664
yuv440p a99e2b57ed601f39852715c9d675d0d3
yuv444p 947e47f7bb5fdccc659d19b7df2b6fc3
-yuv444p16be debc96a7ec4fec0a412f9d8995bc48a2
-yuv444p16le 5b5e1348a631fc2206bb7ff851a52687
+yuv444p16be bc7d53923cff1d7e98d24540845fb64b
+yuv444p16le 5df206a93f85ef8b77f5bdc81d9b0a0b
yuva420p d83ec0c01498189f179ec574918185f1
yuvj420p df3aaaec3bb157c3bde5f0365af30f4f
yuvj422p d113871528d510a192797af59df9c05c
diff --git a/tests/ref/lavfi/pixfmts_null b/tests/ref/lavfi/pixfmts_null
index 8695b1dea2..0b18dfb7da 100644
--- a/tests/ref/lavfi/pixfmts_null
+++ b/tests/ref/lavfi/pixfmts_null
@@ -1,8 +1,8 @@
abgr 037bf9df6a765520ad6d490066bf4b89
argb c442a8261c2265a07212ef0f72e35f5a
bgr24 0d0cb38ab3fa0b2ec0865c14f78b217b
-bgr48be 74dedaaacae8fd1ef46e05f78cf29d62
-bgr48le 0eb7d30801eac6058814bddd330b3c76
+bgr48be 00624e6c7ec7ab19897ba2f0a3257fe8
+bgr48le d02c235ebba7167881ca2d576497ff84
bgr4_byte 50d23cc82d9dcef2fd12adb81fb9b806
bgr555be 49f01b1f1f0c84fd9e776dd34cc3c280
bgr555le 378d6ac4223651a1adcbf94a3d0d807b
@@ -11,15 +11,15 @@ bgr565le 1dfdd03995c287e3c754b164bf26a355
bgr8 24bd566170343d06fec6fccfff5abc54
bgra 76a18a5151242fa137133f604cd624d2
gray db08f7f0751900347e6b8649e4164d21
-gray16be 7becf34ae825a3df3969bf4c6bfeb5e2
-gray16le 10bd87059b5c189f3caef2837f4f2b5c
+gray16be b44458c2254aa7a3d7b8dbf53be91979
+gray16le ecda5143f8a55fca1f6c7dfb238ddcba
monob 668ebe8b8103b9046b251b2fa8a1d88f
monow 9251497f3b0634f1165d12d5a289d943
nv12 e0af357888584d36eec5aa0f673793ef
nv21 9a3297f3b34baa038b1f37cb202b512f
rgb24 b41eba9651e1b5fe386289b506188105
-rgb48be e3bc84c9af376fb6d0f0293cc7b713a6
-rgb48le f51c0e71638a822458329abb2f4052c7
+rgb48be cc139ec1dd9451f0e049c0cb3a0c8aa2
+rgb48le 86c5608904f75360d492dbc5c9589969
rgb4_byte c93ba89b74c504e7f5ae9d9ab1546c73
rgb555be 912a62c5e53bfcbac2a0340e10973cf2
rgb555le a937a0fc764fb57dc1b3af87cba0273c
@@ -31,19 +31,27 @@ uyvy422 adcf64516a19fce44df77082bdb16291
yuv410p 2d9225153c83ee1132397d619d94d1b3
yuv411p 8b298af3e43348ca1b11eb8a3252ac6c
yuv420p eba2f135a08829387e2f698ff72a2939
-yuv420p10be 7605e266c088d0fcf68c7b27c3ceff5f
-yuv420p10le 4228ee628c6deec123a13b9784516cc7
-yuv420p16be 16c009a235cd52b74791a895423152a3
-yuv420p16le 2d59c4f1d0314a5a957a7cfc4b6fabcc
-yuv420p9be ce880fa07830e5297c22acf6e20555ce
-yuv420p9le 16543fda8f87d94a6cf857d2e8d4461a
+yuv420p10be ea2aee509286fa3d07a6c68fec9967a5
+yuv420p10le 645ef73e06de41c83a7bc724179d2ce3
+yuv420p16be ba858ff4246368c28f03152487f57ef3
+yuv420p16le de239729a4fe1d4cfa3743e006654e78
+yuv420p9be 64e36fd90573f67ac2006d103972a79b
+yuv420p9le 9ed4b1dfabc53fd9e586ff6c4c43af80
yuv422p c9bba4529821d796a6ab09f6a5fd355a
-yuv422p16be 86ad3447f97969ce095afeef81fa9abf
-yuv422p16le a53a9b451f4a81eeae33362c1bbd07f8
+yuv422p10be bdc13b630fd668b34c6fe1aae28dfc71
+yuv422p10le d0607c260a45c973e6639f4e449730ad
+yuv422p16be 4e9b3b3467aeebb6a528cee5966800ed
+yuv422p16le f87c81bf16916b64d201359be0b4b6f4
+yuv422p9be 29b71579946940a8c00fa844c9dff507
+yuv422p9le 062b7f9cbb972bf36b5bdb1a7623701a
yuv440p 5a064afe2b453bb52cdb3f176b1aa1cf
yuv444p 0a98447b78fd476aa39686da6a74fa2e
-yuv444p16be 95db370ae765dd3d10b7def14704ae73
-yuv444p16le 36b969179b5ad9d312a0d1e1cd6bc402
+yuv444p10be e65cbae7e4f1892c23defbc8e8052cf6
+yuv444p10le 767179dd82846cf00ee4c340c9c1ab74
+yuv444p16be 3ad639fff73e56f3b09dd20c335478d6
+yuv444p16le 8a7e66dc91ab7971fd24a9105ff2699b
+yuv444p9be 6ab31f4c12b533ce318ecdff83cdd054
+yuv444p9le f0606604a5c08becab6ba500124c4b7c
yuva420p a29884f3f3dfe1e00b961bc17bef3d47
yuvj420p 32eec78ba51857b16ce9b813a49b7189
yuvj422p 0dfa0ed434f73be51428758c69e082cb
diff --git a/tests/ref/lavfi/pixfmts_scale b/tests/ref/lavfi/pixfmts_scale
index 8901fe9132..e17544dbe6 100644
--- a/tests/ref/lavfi/pixfmts_scale
+++ b/tests/ref/lavfi/pixfmts_scale
@@ -1,49 +1,57 @@
-abgr d894cb97f6c80eb21bdbe8a4eea62d86
-argb 54346f2b2eef10919e0f247241df3b24
-bgr24 570f8d6b51a838aed022ef67535f6bdc
-bgr48be 07f7a0cc34feb3646434d47c0cec8cee
-bgr48le 9abd2c3a66088e6c9078232064eba61e
+abgr cff82561a074874027ac1cc896fd2730
+argb 756dd1eaa5baca2238ce23dbdc452684
+bgr24 e44192347a45586c6c157e3059610cd1
+bgr48be 390d3058a12a99c2b153ed7922508bea
+bgr48le 39fe06feb4ec1d9730dccc04a0cfac4c
bgr4_byte ee1d35a7baf8e9016891929a2f565c0b
-bgr555be de8901c1358834fddea060fcb3a67beb
-bgr555le 36b745067197f9ca8c1731cac51329c9
-bgr565be 922a2503767036ae9536f4f7823c04ee
-bgr565le 3a514a298c6161a071ddf9963c06509d
+bgr555be 6a2d335856db12e3ea72173d71610e21
+bgr555le 41e3e0961478dc634bf68a7bbd670cc9
+bgr565be 21077a3744c889b97032414b11232933
+bgr565le 614897eaeb422bd9a972f8ee51909be5
bgr8 7f007fa6c153a16e808a9c51605a4016
-bgra a5e7040f9a80cccd65e5acf2ca09ace5
+bgra 01cfdda1f72fcabb6c46424e27f8c519
gray d7786a7d9d99ac74230cc045cab5632c
-gray16be bba98532da29a31599df2feec3b08e3e
-gray16le 30267f127d5734c4767f3944f1729a33
-monob 88c4c050758e64d120f50c7eff694381
-monow d31772ebaa877fc2a78565937f7f9673
+gray16be a8fc0d7fea36407b5c319e3e736c7127
+gray16le 495c89186178308ef171d385bbd8bd70
+monob cb62f31b701c6e987b574974d1b31e32
+monow fd5d417ab7728acddffc06870661df61
nv12 4676d59db43d657dc12841f6bc3ab452
nv21 69c699510ff1fb777b118ebee1002f14
-rgb24 514692e28e8ff6860e415ce4fcf6eb8c
-rgb48be f18841c19fc6d9c817a3095f557b9bc5
-rgb48le 819e7b8acd8965ba57ba46198a5cc9bf
+rgb24 13ff53ebeab74dc05492836f1cfbd2c1
+rgb48be 8fac63787a711886030f8e056872b488
+rgb48le ab92f2763a2eb264c3870cc758f97149
rgb4_byte d81ffd3add95842a618eec81024f0b5c
-rgb555be 4607309f9f217d51cbb53d13b84b4537
-rgb555le a350ef1dc2c9688ed49e7ba018843795
-rgb565be 678ce231c4ea13629c1353b1df4ffbef
-rgb565le 6f4bb711238baa762d73305213f8d035
+rgb555be 491dc49ff83258ffe415289bdcfb50b2
+rgb555le bd698d86c03170c4a16607c0fd1f750f
+rgb565be 35682c17c85f307147041f23ac8092aa
+rgb565le bfa0c639d80c3c03fd0c9e5f34296a5e
rgb8 091d0170b354ef0e97312b95feb5483f
-rgba a3d362f222098a00e63867f612018659
+rgba 16873e3ac914e76116629a5ff8940ac4
uyvy422 314bd486277111a95d9369b944fa0400
yuv410p 7df8f6d69b56a8dcb6c7ee908e5018b5
yuv411p 1143e7c5cc28fe0922b051b17733bc4c
yuv420p fdad2d8df8985e3d17e73c71f713cb14
-yuv420p10be 2343beaf83fccc2ab23a590b2049d38b
-yuv420p10le 94d511d783d175f573e7be5cce75ba4d
-yuv420p16be f6ef3ba90f238b467c7e72ade927083d
-yuv420p16le faf6aab3b1c16e8afbe160686dd360e0
-yuv420p9be fdafb9ad473a559246c4cb0a1f416cd8
-yuv420p9le fccfd3c3941da635b13739f579819b5a
+yuv420p10be 6d335e75b553da590135cf8bb999610c
+yuv420p10le d510ddbabefd03ef39ec943fcb51b709
+yuv420p16be 2a75942af24fbdc1fdfe189c6e7bf589
+yuv420p16le c4264d92a7c273967a778f4f5daddbe3
+yuv420p9be ec4983b7a949c0472110a7a2c58e278a
+yuv420p9le c136dce5913a722eee44ab72cff664b2
yuv422p 918e37701ee7377d16a8a6c119c56a40
-yuv422p16be 837945d3a771366a5a72a4ed095a4f53
-yuv422p16le b8292ae9b52eb7afc3d8b93e8fd895b4
+yuv422p10be cea7ca6b0e66d6f29539885896c88603
+yuv422p10le a10c4a5837547716f13cd61918b145f9
+yuv422p16be 285993ee0c0f4f8e511ee46f93c5f38c
+yuv422p16le 61bfcee8e54465f760164f5a75d40b5e
+yuv422p9be 82494823944912f73cebc58ad2979bbd
+yuv422p9le fc69c8a21f473916a4b4225636b97e06
yuv440p 461503fdb9b90451020aa3b25ddf041c
yuv444p 81b2eba962d12e8d64f003ac56f6faf2
-yuv444p16be cc7460f76477aa4b4c33442f67c06a89
-yuv444p16le 9a5ed60d68c0a4a5155f9d376174cdf7
+yuv444p10be e9d3c8e744b8b0d8187ca092fa203fc9
+yuv444p10le 02f0a336e9da062a64df1ba487e102c5
+yuv444p16be 2677f3074d255f9dab625e9e2e092ca5
+yuv444p16le 65fa92521ef97088599ea83f9508cd5b
+yuv444p9be 9ac2643ce7f7e5c4e17c8c9fd8494d4a
+yuv444p9le 896a1cc9cccca1ba410dd53942d33cc4
yuva420p 8673a9131fb47de69788863f93a50eb7
yuvj420p 30427bd6caf5bda93a173dbebe759e09
yuvj422p fc8288f64fd149573f73cf8da05d8e6d
diff --git a/tests/ref/lavfi/pixfmts_vflip b/tests/ref/lavfi/pixfmts_vflip
index 89502d1745..c8301e380f 100644
--- a/tests/ref/lavfi/pixfmts_vflip
+++ b/tests/ref/lavfi/pixfmts_vflip
@@ -1,8 +1,8 @@
abgr 25e72e9dbd01ab00727c976d577f7be5
argb 19869bf1a5ac0b6af4d8bbe2c104533c
bgr24 89108a4ba00201f79b75b9305c42352d
-bgr48be 908b4edb525fd154a95a3744c4ab5420
-bgr48le 796c2072d6fa13a091f5c5b175417ed5
+bgr48be 2f23931844f57641f3737348182d118c
+bgr48le 4242a026012b6c135a6aa138a6d67031
bgr4_byte 407fcf564ed764c38e1d748f700ab921
bgr555be f739d2519f7e9d494359bf67a3821537
bgr555le bd7b3ec4d684dfad075d89a606cb8b74
@@ -11,15 +11,15 @@ bgr565le fdb617533e1e7ff512ea5b6b6233e738
bgr8 c60f93fd152c6903391d1fe9decd3547
bgra 7f9b799fb48544e49ce93e91d7f9fca8
gray 30d9014a9d43b5f37e7aa64be3a3ecfc
-gray16be 6b84b85d3326182fa1217e138249edc5
-gray16le 66bb8faa09dc149734aca3c768a6d4e1
+gray16be 9e8319fa0d4945e587b8c095277be8de
+gray16le 790031119f8e874d75ee6f01b4654185
monob d0cf8732677a5360b6160133043590d8
monow ff9869d067ecb94eb9d90c9750c31fea
nv12 046f00f598ce14d9854a3534a5c99114
nv21 01ea369dd2d0d3ed7451dc5c8d61497f
rgb24 eaefabc168d0b14576bab45bc1e56e1e
-rgb48be 8e347deca2902e7dc1ece261322577d8
-rgb48le 2034e485f946e4064b5fb9be09865e55
+rgb48be 62dd185862ed142283bd300eb6dbd216
+rgb48le dcb76353268bc5862194d131762220da
rgb4_byte 8c6ff02df0b06dd2d574836c3741b2a2
rgb555be 40dc33cfb5cf56aac1c5a290ac486c36
rgb555le 4f8eaad29a17e0f8e9d8ab743e76b999
@@ -31,19 +31,27 @@ uyvy422 ffbd36720c77398d9a0d03ce2625928f
yuv410p 7bfb39d7afb49d6a6173e6b23ae321eb
yuv411p 4a90048cc3a65fac150e53289700efe1
yuv420p 2e6d6062e8cad37fb3ab2c433b55f382
-yuv420p10be df97d20b3b4a10c174d4360552c4160d
-yuv420p10le 4b5249208602b941332945c926f80ae9
-yuv420p16be 539076782902664a8acf381bf4f713e8
-yuv420p16le 0f609e588e5a258644ef85170d70e030
-yuv420p9be be40ec975fb2873891643cbbbddbc3b0
-yuv420p9le 7e606310d3f5ff12badf911e8f333471
+yuv420p10be fac8e0ae5a81861cddac97ddc4100b66
+yuv420p10le cb83ed3552113e0292e30adee774359c
+yuv420p16be b6d25ba55bc1831d352f379311b42b6d
+yuv420p16le 1d7ef427b6f79a02b93948738dab5442
+yuv420p9be 9865bf5c4392b56b1c4eb4f5a3fd32f9
+yuv420p9le 0f1e371a1374d3cba2205b70cc7cac90
yuv422p d7f5cb44d9b0210d66d6a8762640ab34
-yuv422p16be 8cdfbddf2dd4c44c3efef4ee00170eba
-yuv422p16le a2f421f6a1af950544081c1797de01ae
+yuv422p10be 588fe319b96513c32e21d3e32b45447f
+yuv422p10le 11b57f2bd9661024153f3973b9090cdb
+yuv422p16be c092d083548c2a144c372a98c46875c7
+yuv422p16le c071b9397a416d51cbe339345cbcba84
+yuv422p9be 7c6f1e140b3999ee7d923854e507752a
+yuv422p9le 51f10d79c07989060dd06e767e6d7d60
yuv440p 876385e96165acf51271b20e5d85a416
yuv444p 9c3c667d1613b72d15bc6d851c5eb8f7
-yuv444p16be b092690d22f0b26360fbf5cfd739be17
-yuv444p16le 18768b4ddca92d06f9713fef467276a9
+yuv444p10be 944a4997c4edb3a8dd0f0493cfd5a1fd
+yuv444p10le 2d0947ae89ecc6a501eee6832cb27e06
+yuv444p16be 6a954614fd2a8ae0df53e4fd76937af8
+yuv444p16le 65613965fb58cc4c3cd480a68b6540ea
+yuv444p9be 6ac92b7dc9ab2fc59bee99204886899a
+yuv444p9le 85aef13a654953d3455d89770b0d74bd
yuva420p c705d1cf061d8c6580ac690b55f92276
yuvj420p 41fd02b204da0ab62452cd14b595e2e4
yuvj422p 7f6ca9bc1812cde02036d7d29a7cce43
diff --git a/tests/ref/seek/ac3_rm b/tests/ref/seek/ac3_rm
index 05772fcf98..ecf03c29a1 100644
--- a/tests/ref/seek/ac3_rm
+++ b/tests/ref/seek/ac3_rm
@@ -6,24 +6,26 @@ ret:-1 st: 0 flags:0 ts: 0.788000
ret: 0 st: 0 flags:1 ts:-0.317000
ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 271 size: 556
ret: 0 st:-1 flags:0 ts: 2.576668
-ret: 0 st: 0 flags:1 dts: 2.577000 pts: 2.577000 pos: 42397 size: 558
+ret: 0 st: 0 flags:1 dts: 2.124000 pts: 2.124000 pos: 34997 size: 558
ret:-1 st:-1 flags:1 ts: 1.470835
ret:-1 st: 0 flags:0 ts: 0.365000
ret: 0 st: 0 flags:1 ts:-0.741000
ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 271 size: 556
ret: 0 st:-1 flags:0 ts: 2.153336
-ret: 0 st: 0 flags:1 dts: 2.159000 pts: 2.159000 pos: 35567 size: 556
+ret: 0 st: 0 flags:1 dts: 2.124000 pts: 2.124000 pos: 34997 size: 558
ret:-1 st:-1 flags:1 ts: 1.047503
ret: 0 st: 0 flags:0 ts:-0.058000
ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 271 size: 556
-ret:-1 st: 0 flags:1 ts: 2.836000
+ret: 0 st: 0 flags:1 ts: 2.836000
+ret: 0 st: 0 flags:1 dts: 2.124000 pts: 2.124000 pos: 34997 size: 558
ret:-1 st:-1 flags:0 ts: 1.730004
ret:-1 st:-1 flags:1 ts: 0.624171
ret: 0 st: 0 flags:0 ts:-0.482000
ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 271 size: 556
ret: 0 st: 0 flags:1 ts: 2.413000
-ret: 0 st: 0 flags:1 dts: 2.368000 pts: 2.368000 pos: 38981 size: 558
-ret:-1 st:-1 flags:0 ts: 1.306672
+ret: 0 st: 0 flags:1 dts: 2.124000 pts: 2.124000 pos: 34997 size: 558
+ret: 0 st:-1 flags:0 ts: 1.306672
+ret: 0 st: 0 flags:1 dts:65.537000 pts:65.537000 pos: 87488 size: 6132
ret:-1 st:-1 flags:1 ts: 0.200839
ret: 0 st: 0 flags:0 ts:-0.905000
ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 271 size: 556
@@ -31,9 +33,9 @@ ret:-1 st: 0 flags:1 ts: 1.989000
ret:-1 st:-1 flags:0 ts: 0.883340
ret: 0 st:-1 flags:1 ts:-0.222493
ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 271 size: 556
-ret: 0 st: 0 flags:0 ts: 2.672000
-ret: 0 st: 0 flags:1 dts: 2.821000 pts: 2.821000 pos: 46383 size: 556
+ret:-1 st: 0 flags:0 ts: 2.672000
ret:-1 st: 0 flags:1 ts: 1.566000
-ret:-1 st:-1 flags:0 ts: 0.460008
+ret: 0 st:-1 flags:0 ts: 0.460008
+ret: 0 st: 0 flags:1 dts: 1.567000 pts: 1.567000 pos: 25889 size: 556
ret: 0 st:-1 flags:1 ts:-0.645825
ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 271 size: 556
diff --git a/tests/ref/seek/adpcm_yam_wav b/tests/ref/seek/adpcm_yam_wav
index c326470188..5cbfaed73e 100644
--- a/tests/ref/seek/adpcm_yam_wav
+++ b/tests/ref/seek/adpcm_yam_wav
@@ -1,53 +1,53 @@
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096
ret: 0 st:-1 flags:0 ts:-1.000000
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096
ret: 0 st:-1 flags:1 ts: 1.894167
-ret: 0 st: 0 flags:1 dts: 1.856009 pts: 1.856009 pos: 29752 size: 4096
+ret: 0 st: 0 flags:1 dts: 1.856009 pts: 1.856009 pos: 29754 size: 4096
ret: 0 st: 0 flags:0 ts: 0.788345
-ret: 0 st: 0 flags:1 dts: 0.831995 pts: 0.831995 pos: 13368 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.831995 pts: 0.831995 pos: 13370 size: 4096
ret: 0 st: 0 flags:1 ts:-0.317506
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096
ret: 0 st:-1 flags:0 ts: 2.576668
-ret: 0 st: 0 flags:1 dts: 2.623991 pts: 2.623991 pos: 42040 size: 4096
+ret: 0 st: 0 flags:1 dts: 2.623991 pts: 2.623991 pos: 42042 size: 4096
ret: 0 st:-1 flags:1 ts: 1.470835
-ret: 0 st: 0 flags:1 dts: 1.408005 pts: 1.408005 pos: 22584 size: 4096
+ret: 0 st: 0 flags:1 dts: 1.408005 pts: 1.408005 pos: 22586 size: 4096
ret: 0 st: 0 flags:0 ts: 0.365011
-ret: 0 st: 0 flags:1 dts: 0.383991 pts: 0.383991 pos: 6200 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.383991 pts: 0.383991 pos: 6202 size: 4096
ret: 0 st: 0 flags:1 ts:-0.740839
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096
ret: 0 st:-1 flags:0 ts: 2.153336
-ret: 0 st: 0 flags:1 dts: 2.176009 pts: 2.176009 pos: 34872 size: 4096
+ret: 0 st: 0 flags:1 dts: 2.176009 pts: 2.176009 pos: 34874 size: 4096
ret: 0 st:-1 flags:1 ts: 1.047503
-ret: 0 st: 0 flags:1 dts: 1.023991 pts: 1.023991 pos: 16440 size: 4096
+ret: 0 st: 0 flags:1 dts: 1.023991 pts: 1.023991 pos: 16442 size: 4096
ret: 0 st: 0 flags:0 ts:-0.058322
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096
ret: 0 st: 0 flags:1 ts: 2.835828
-ret: 0 st: 0 flags:1 dts: 2.816009 pts: 2.816009 pos: 45112 size: 4096
+ret: 0 st: 0 flags:1 dts: 2.816009 pts: 2.816009 pos: 45114 size: 4096
ret: 0 st:-1 flags:0 ts: 1.730004
-ret: 0 st: 0 flags:1 dts: 1.791995 pts: 1.791995 pos: 28728 size: 4096
+ret: 0 st: 0 flags:1 dts: 1.791995 pts: 1.791995 pos: 28730 size: 4096
ret: 0 st:-1 flags:1 ts: 0.624171
-ret: 0 st: 0 flags:1 dts: 0.576009 pts: 0.576009 pos: 9272 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.576009 pts: 0.576009 pos: 9274 size: 4096
ret: 0 st: 0 flags:0 ts:-0.481655
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096
ret: 0 st: 0 flags:1 ts: 2.412494
-ret: 0 st: 0 flags:1 dts: 2.368005 pts: 2.368005 pos: 37944 size: 4096
+ret: 0 st: 0 flags:1 dts: 2.368005 pts: 2.368005 pos: 37946 size: 4096
ret: 0 st:-1 flags:0 ts: 1.306672
-ret: 0 st: 0 flags:1 dts: 1.343991 pts: 1.343991 pos: 21560 size: 4096
+ret: 0 st: 0 flags:1 dts: 1.343991 pts: 1.343991 pos: 21562 size: 4096
ret: 0 st:-1 flags:1 ts: 0.200839
-ret: 0 st: 0 flags:1 dts: 0.191995 pts: 0.191995 pos: 3128 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.191995 pts: 0.191995 pos: 3130 size: 4096
ret: 0 st: 0 flags:0 ts:-0.904989
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096
ret: 0 st: 0 flags:1 ts: 1.989184
-ret: 0 st: 0 flags:1 dts: 1.983991 pts: 1.983991 pos: 31800 size: 4096
+ret: 0 st: 0 flags:1 dts: 1.983991 pts: 1.983991 pos: 31802 size: 4096
ret: 0 st:-1 flags:0 ts: 0.883340
-ret: 0 st: 0 flags:1 dts: 0.896009 pts: 0.896009 pos: 14392 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.896009 pts: 0.896009 pos: 14394 size: 4096
ret: 0 st:-1 flags:1 ts:-0.222493
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096
ret: 0 st: 0 flags:0 ts: 2.671678
-ret: 0 st: 0 flags:1 dts: 2.688005 pts: 2.688005 pos: 43064 size: 4096
+ret: 0 st: 0 flags:1 dts: 2.688005 pts: 2.688005 pos: 43066 size: 4096
ret: 0 st: 0 flags:1 ts: 1.565850
-ret: 0 st: 0 flags:1 dts: 1.536009 pts: 1.536009 pos: 24632 size: 4096
+ret: 0 st: 0 flags:1 dts: 1.536009 pts: 1.536009 pos: 24634 size: 4096
ret: 0 st:-1 flags:0 ts: 0.460008
-ret: 0 st: 0 flags:1 dts: 0.511995 pts: 0.511995 pos: 8248 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.511995 pts: 0.511995 pos: 8250 size: 4096
ret: 0 st:-1 flags:1 ts:-0.645825
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096
diff --git a/tests/ref/seek/dv411_dv b/tests/ref/seek/dv411_dv
index baaeefb2cf..d318794157 100644
--- a/tests/ref/seek/dv411_dv
+++ b/tests/ref/seek/dv411_dv
@@ -1,53 +1,53 @@
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000
ret: 0 st:-1 flags:0 ts:-1.000000
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000
ret: 0 st:-1 flags:1 ts: 1.894167
-ret: 0 st: 0 flags:1 dts: 1.880000 pts: 1.880000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 1.880000 pts: 1.880000 pos:6768000 size:144000
ret: 0 st: 0 flags:0 ts: 0.800000
-ret: 0 st: 0 flags:1 dts: 0.800000 pts: 0.800000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.800000 pts: 0.800000 pos:2880000 size:144000
ret: 0 st: 0 flags:1 ts:-0.320000
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000
ret: 0 st:-1 flags:0 ts: 2.576668
-ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos:7056000 size:144000
ret: 0 st:-1 flags:1 ts: 1.470835
-ret: 0 st: 0 flags:1 dts: 1.480000 pts: 1.480000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 1.480000 pts: 1.480000 pos:5328000 size:144000
ret: 0 st: 0 flags:0 ts: 0.360000
-ret: 0 st: 0 flags:1 dts: 0.360000 pts: 0.360000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.360000 pts: 0.360000 pos:1296000 size:144000
ret: 0 st: 0 flags:1 ts:-0.760000
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000
ret: 0 st:-1 flags:0 ts: 2.153336
-ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos:7056000 size:144000
ret: 0 st:-1 flags:1 ts: 1.047503
-ret: 0 st: 0 flags:1 dts: 1.040000 pts: 1.040000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 1.040000 pts: 1.040000 pos:3744000 size:144000
ret: 0 st: 0 flags:0 ts:-0.040000
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000
ret: 0 st: 0 flags:1 ts: 2.840000
-ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos:7056000 size:144000
ret: 0 st:-1 flags:0 ts: 1.730004
-ret: 0 st: 0 flags:1 dts: 1.720000 pts: 1.720000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 1.720000 pts: 1.720000 pos:6192000 size:144000
ret: 0 st:-1 flags:1 ts: 0.624171
-ret: 0 st: 0 flags:1 dts: 0.640000 pts: 0.640000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.640000 pts: 0.640000 pos:2304000 size:144000
ret: 0 st: 0 flags:0 ts:-0.480000
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000
ret: 0 st: 0 flags:1 ts: 2.400000
-ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos:7056000 size:144000
ret: 0 st:-1 flags:0 ts: 1.306672
-ret: 0 st: 0 flags:1 dts: 1.320000 pts: 1.320000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 1.320000 pts: 1.320000 pos:4752000 size:144000
ret: 0 st:-1 flags:1 ts: 0.200839
-ret: 0 st: 0 flags:1 dts: 0.200000 pts: 0.200000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.200000 pts: 0.200000 pos: 720000 size:144000
ret: 0 st: 0 flags:0 ts:-0.920000
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000
ret: 0 st: 0 flags:1 ts: 2.000000
-ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos:7056000 size:144000
ret: 0 st:-1 flags:0 ts: 0.883340
-ret: 0 st: 0 flags:1 dts: 0.880000 pts: 0.880000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.880000 pts: 0.880000 pos:3168000 size:144000
ret: 0 st:-1 flags:1 ts:-0.222493
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000
ret: 0 st: 0 flags:0 ts: 2.680000
-ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos:7056000 size:144000
ret: 0 st: 0 flags:1 ts: 1.560000
-ret: 0 st: 0 flags:1 dts: 1.560000 pts: 1.560000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 1.560000 pts: 1.560000 pos:5616000 size:144000
ret: 0 st:-1 flags:0 ts: 0.460008
-ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos:1728000 size:144000
ret: 0 st:-1 flags:1 ts:-0.645825
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000
diff --git a/tests/ref/seek/dv50_dv b/tests/ref/seek/dv50_dv
index 1f07e5b71f..fae6d1b225 100644
--- a/tests/ref/seek/dv50_dv
+++ b/tests/ref/seek/dv50_dv
@@ -1,53 +1,53 @@
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:288000
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:288000
ret: 0 st:-1 flags:0 ts:-1.000000
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:288000
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:288000
ret: 0 st:-1 flags:1 ts: 1.894167
-ret: 0 st: 0 flags:1 dts: 1.880000 pts: 1.880000 pos: -1 size:288000
+ret: 0 st: 0 flags:1 dts: 1.880000 pts: 1.880000 pos:13536000 size:288000
ret: 0 st: 0 flags:0 ts: 0.800000
-ret: 0 st: 0 flags:1 dts: 0.800000 pts: 0.800000 pos: -1 size:288000
+ret: 0 st: 0 flags:1 dts: 0.800000 pts: 0.800000 pos:5760000 size:288000
ret: 0 st: 0 flags:1 ts:-0.320000
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:288000
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:288000
ret: 0 st:-1 flags:0 ts: 2.576668
-ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos: -1 size:288000
+ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos:14112000 size:288000
ret: 0 st:-1 flags:1 ts: 1.470835
-ret: 0 st: 0 flags:1 dts: 1.480000 pts: 1.480000 pos: -1 size:288000
+ret: 0 st: 0 flags:1 dts: 1.480000 pts: 1.480000 pos:10656000 size:288000
ret: 0 st: 0 flags:0 ts: 0.360000
-ret: 0 st: 0 flags:1 dts: 0.360000 pts: 0.360000 pos: -1 size:288000
+ret: 0 st: 0 flags:1 dts: 0.360000 pts: 0.360000 pos:2592000 size:288000
ret: 0 st: 0 flags:1 ts:-0.760000
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:288000
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:288000
ret: 0 st:-1 flags:0 ts: 2.153336
-ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos: -1 size:288000
+ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos:14112000 size:288000
ret: 0 st:-1 flags:1 ts: 1.047503
-ret: 0 st: 0 flags:1 dts: 1.040000 pts: 1.040000 pos: -1 size:288000
+ret: 0 st: 0 flags:1 dts: 1.040000 pts: 1.040000 pos:7488000 size:288000
ret: 0 st: 0 flags:0 ts:-0.040000
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:288000
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:288000
ret: 0 st: 0 flags:1 ts: 2.840000
-ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos: -1 size:288000
+ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos:14112000 size:288000
ret: 0 st:-1 flags:0 ts: 1.730004
-ret: 0 st: 0 flags:1 dts: 1.720000 pts: 1.720000 pos: -1 size:288000
+ret: 0 st: 0 flags:1 dts: 1.720000 pts: 1.720000 pos:12384000 size:288000
ret: 0 st:-1 flags:1 ts: 0.624171
-ret: 0 st: 0 flags:1 dts: 0.640000 pts: 0.640000 pos: -1 size:288000
+ret: 0 st: 0 flags:1 dts: 0.640000 pts: 0.640000 pos:4608000 size:288000
ret: 0 st: 0 flags:0 ts:-0.480000
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:288000
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:288000
ret: 0 st: 0 flags:1 ts: 2.400000
-ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos: -1 size:288000
+ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos:14112000 size:288000
ret: 0 st:-1 flags:0 ts: 1.306672
-ret: 0 st: 0 flags:1 dts: 1.320000 pts: 1.320000 pos: -1 size:288000
+ret: 0 st: 0 flags:1 dts: 1.320000 pts: 1.320000 pos:9504000 size:288000
ret: 0 st:-1 flags:1 ts: 0.200839
-ret: 0 st: 0 flags:1 dts: 0.200000 pts: 0.200000 pos: -1 size:288000
+ret: 0 st: 0 flags:1 dts: 0.200000 pts: 0.200000 pos:1440000 size:288000
ret: 0 st: 0 flags:0 ts:-0.920000
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:288000
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:288000
ret: 0 st: 0 flags:1 ts: 2.000000
-ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos: -1 size:288000
+ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos:14112000 size:288000
ret: 0 st:-1 flags:0 ts: 0.883340
-ret: 0 st: 0 flags:1 dts: 0.880000 pts: 0.880000 pos: -1 size:288000
+ret: 0 st: 0 flags:1 dts: 0.880000 pts: 0.880000 pos:6336000 size:288000
ret: 0 st:-1 flags:1 ts:-0.222493
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:288000
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:288000
ret: 0 st: 0 flags:0 ts: 2.680000
-ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos: -1 size:288000
+ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos:14112000 size:288000
ret: 0 st: 0 flags:1 ts: 1.560000
-ret: 0 st: 0 flags:1 dts: 1.560000 pts: 1.560000 pos: -1 size:288000
+ret: 0 st: 0 flags:1 dts: 1.560000 pts: 1.560000 pos:11232000 size:288000
ret: 0 st:-1 flags:0 ts: 0.460008
-ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: -1 size:288000
+ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos:3456000 size:288000
ret: 0 st:-1 flags:1 ts:-0.645825
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:288000
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:288000
diff --git a/tests/ref/seek/dv_dv b/tests/ref/seek/dv_dv
index baaeefb2cf..d318794157 100644
--- a/tests/ref/seek/dv_dv
+++ b/tests/ref/seek/dv_dv
@@ -1,53 +1,53 @@
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000
ret: 0 st:-1 flags:0 ts:-1.000000
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000
ret: 0 st:-1 flags:1 ts: 1.894167
-ret: 0 st: 0 flags:1 dts: 1.880000 pts: 1.880000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 1.880000 pts: 1.880000 pos:6768000 size:144000
ret: 0 st: 0 flags:0 ts: 0.800000
-ret: 0 st: 0 flags:1 dts: 0.800000 pts: 0.800000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.800000 pts: 0.800000 pos:2880000 size:144000
ret: 0 st: 0 flags:1 ts:-0.320000
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000
ret: 0 st:-1 flags:0 ts: 2.576668
-ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos:7056000 size:144000
ret: 0 st:-1 flags:1 ts: 1.470835
-ret: 0 st: 0 flags:1 dts: 1.480000 pts: 1.480000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 1.480000 pts: 1.480000 pos:5328000 size:144000
ret: 0 st: 0 flags:0 ts: 0.360000
-ret: 0 st: 0 flags:1 dts: 0.360000 pts: 0.360000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.360000 pts: 0.360000 pos:1296000 size:144000
ret: 0 st: 0 flags:1 ts:-0.760000
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000
ret: 0 st:-1 flags:0 ts: 2.153336
-ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos:7056000 size:144000
ret: 0 st:-1 flags:1 ts: 1.047503
-ret: 0 st: 0 flags:1 dts: 1.040000 pts: 1.040000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 1.040000 pts: 1.040000 pos:3744000 size:144000
ret: 0 st: 0 flags:0 ts:-0.040000
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000
ret: 0 st: 0 flags:1 ts: 2.840000
-ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos:7056000 size:144000
ret: 0 st:-1 flags:0 ts: 1.730004
-ret: 0 st: 0 flags:1 dts: 1.720000 pts: 1.720000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 1.720000 pts: 1.720000 pos:6192000 size:144000
ret: 0 st:-1 flags:1 ts: 0.624171
-ret: 0 st: 0 flags:1 dts: 0.640000 pts: 0.640000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.640000 pts: 0.640000 pos:2304000 size:144000
ret: 0 st: 0 flags:0 ts:-0.480000
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000
ret: 0 st: 0 flags:1 ts: 2.400000
-ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos:7056000 size:144000
ret: 0 st:-1 flags:0 ts: 1.306672
-ret: 0 st: 0 flags:1 dts: 1.320000 pts: 1.320000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 1.320000 pts: 1.320000 pos:4752000 size:144000
ret: 0 st:-1 flags:1 ts: 0.200839
-ret: 0 st: 0 flags:1 dts: 0.200000 pts: 0.200000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.200000 pts: 0.200000 pos: 720000 size:144000
ret: 0 st: 0 flags:0 ts:-0.920000
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000
ret: 0 st: 0 flags:1 ts: 2.000000
-ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos:7056000 size:144000
ret: 0 st:-1 flags:0 ts: 0.883340
-ret: 0 st: 0 flags:1 dts: 0.880000 pts: 0.880000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.880000 pts: 0.880000 pos:3168000 size:144000
ret: 0 st:-1 flags:1 ts:-0.222493
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000
ret: 0 st: 0 flags:0 ts: 2.680000
-ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos:7056000 size:144000
ret: 0 st: 0 flags:1 ts: 1.560000
-ret: 0 st: 0 flags:1 dts: 1.560000 pts: 1.560000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 1.560000 pts: 1.560000 pos:5616000 size:144000
ret: 0 st:-1 flags:0 ts: 0.460008
-ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos:1728000 size:144000
ret: 0 st:-1 flags:1 ts:-0.645825
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000
diff --git a/tests/ref/seek/g726_wav b/tests/ref/seek/g726_wav
index b84c87c564..0e145a2722 100644
--- a/tests/ref/seek/g726_wav
+++ b/tests/ref/seek/g726_wav
@@ -1,53 +1,53 @@
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096
ret: 0 st:-1 flags:0 ts:-1.000000
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096
ret: 0 st:-1 flags:1 ts: 1.894167
-ret: 0 st: 0 flags:1 dts: 1.894000 pts: 1.894000 pos: 7632 size: 4096
+ret: 0 st: 0 flags:1 dts: 1.894000 pts: 1.894000 pos: 7634 size: 4096
ret: 0 st: 0 flags:0 ts: 0.788375
-ret: 0 st: 0 flags:1 dts: 0.788500 pts: 0.788500 pos: 3210 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.788500 pts: 0.788500 pos: 3212 size: 4096
ret: 0 st: 0 flags:1 ts:-0.317500
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096
ret: 0 st:-1 flags:0 ts: 2.576668
-ret: 0 st: 0 flags:1 dts: 2.576750 pts: 2.576750 pos: 10363 size: 4096
+ret: 0 st: 0 flags:1 dts: 2.576750 pts: 2.576750 pos: 10365 size: 4096
ret: 0 st:-1 flags:1 ts: 1.470835
-ret: 0 st: 0 flags:1 dts: 1.470750 pts: 1.470750 pos: 5939 size: 4096
+ret: 0 st: 0 flags:1 dts: 1.470750 pts: 1.470750 pos: 5941 size: 4096
ret: 0 st: 0 flags:0 ts: 0.365000
-ret: 0 st: 0 flags:1 dts: 0.365000 pts: 0.365000 pos: 1516 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.365000 pts: 0.365000 pos: 1518 size: 4096
ret: 0 st: 0 flags:1 ts:-0.740875
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096
ret: 0 st:-1 flags:0 ts: 2.153336
-ret: 0 st: 0 flags:1 dts: 2.153500 pts: 2.153500 pos: 8670 size: 4096
+ret: 0 st: 0 flags:1 dts: 2.153500 pts: 2.153500 pos: 8672 size: 4096
ret: 0 st:-1 flags:1 ts: 1.047503
-ret: 0 st: 0 flags:1 dts: 1.047500 pts: 1.047500 pos: 4246 size: 4096
+ret: 0 st: 0 flags:1 dts: 1.047500 pts: 1.047500 pos: 4248 size: 4096
ret: 0 st: 0 flags:0 ts:-0.058375
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096
ret: 0 st: 0 flags:1 ts: 2.835875
-ret: 0 st: 0 flags:1 dts: 2.835750 pts: 2.835750 pos: 11399 size: 4096
+ret: 0 st: 0 flags:1 dts: 2.835750 pts: 2.835750 pos: 11401 size: 4096
ret: 0 st:-1 flags:0 ts: 1.730004
-ret: 0 st: 0 flags:1 dts: 1.730000 pts: 1.730000 pos: 6976 size: 4096
+ret: 0 st: 0 flags:1 dts: 1.730000 pts: 1.730000 pos: 6978 size: 4096
ret: 0 st:-1 flags:1 ts: 0.624171
-ret: 0 st: 0 flags:1 dts: 0.624000 pts: 0.624000 pos: 2552 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.624000 pts: 0.624000 pos: 2554 size: 4096
ret: 0 st: 0 flags:0 ts:-0.481625
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096
ret: 0 st: 0 flags:1 ts: 2.412500
-ret: 0 st: 0 flags:1 dts: 2.412500 pts: 2.412500 pos: 9706 size: 4096
+ret: 0 st: 0 flags:1 dts: 2.412500 pts: 2.412500 pos: 9708 size: 4096
ret: 0 st:-1 flags:0 ts: 1.306672
-ret: 0 st: 0 flags:1 dts: 1.306750 pts: 1.306750 pos: 5283 size: 4096
+ret: 0 st: 0 flags:1 dts: 1.306750 pts: 1.306750 pos: 5285 size: 4096
ret: 0 st:-1 flags:1 ts: 0.200839
-ret: 0 st: 0 flags:1 dts: 0.200750 pts: 0.200750 pos: 859 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.200750 pts: 0.200750 pos: 861 size: 4096
ret: 0 st: 0 flags:0 ts:-0.905000
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096
ret: 0 st: 0 flags:1 ts: 1.989125
-ret: 0 st: 0 flags:1 dts: 1.989000 pts: 1.989000 pos: 8012 size: 4096
+ret: 0 st: 0 flags:1 dts: 1.989000 pts: 1.989000 pos: 8014 size: 4096
ret: 0 st:-1 flags:0 ts: 0.883340
-ret: 0 st: 0 flags:1 dts: 0.883500 pts: 0.883500 pos: 3590 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.883500 pts: 0.883500 pos: 3592 size: 4096
ret: 0 st:-1 flags:1 ts:-0.222493
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096
ret: 0 st: 0 flags:0 ts: 2.671625
-ret: 0 st: 0 flags:1 dts: 2.671750 pts: 2.671750 pos: 10743 size: 4096
+ret: 0 st: 0 flags:1 dts: 2.671750 pts: 2.671750 pos: 10745 size: 4096
ret: 0 st: 0 flags:1 ts: 1.565875
-ret: 0 st: 0 flags:1 dts: 1.565750 pts: 1.565750 pos: 6319 size: 4096
+ret: 0 st: 0 flags:1 dts: 1.565750 pts: 1.565750 pos: 6321 size: 4096
ret: 0 st:-1 flags:0 ts: 0.460008
-ret: 0 st: 0 flags:1 dts: 0.460000 pts: 0.460000 pos: 1896 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.460000 pts: 0.460000 pos: 1898 size: 4096
ret: 0 st:-1 flags:1 ts:-0.645825
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096
diff --git a/tests/ref/seek/lavf_asf b/tests/ref/seek/lavf_asf
index 757fd0e0bb..cebf283f4a 100644
--- a/tests/ref/seek/lavf_asf
+++ b/tests/ref/seek/lavf_asf
@@ -1,46 +1,52 @@
ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 575 size: 28487
ret: 0 st:-1 flags:0 ts:-1.000000
-ret: 0 st: 1 flags:1 dts: 0.444000 pts: 0.444000 pos: 147775 size: 209
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 575 size: 28487
ret: 0 st:-1 flags:1 ts: 1.894167
-ret: 0 st: 1 flags:1 dts: 0.960000 pts: 0.960000 pos: -1 size: 209
+ret: 0 st: 1 flags:1 dts: 0.940000 pts: 0.940000 pos: 301375 size: 209
ret: 0 st: 0 flags:0 ts: 0.788000
-ret: 0 st: 1 flags:1 dts: 0.960000 pts: 0.960000 pos: -1 size: 209
+ret: 0 st: 1 flags:1 dts: 0.940000 pts: 0.940000 pos: 301375 size: 209
ret: 0 st: 0 flags:1 ts:-0.317000
ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 575 size: 28487
-ret:-1 st: 1 flags:0 ts: 2.577000
-ret:-1 st: 1 flags:1 ts: 1.471000
+ret: 0 st: 1 flags:0 ts: 2.577000
+ret: 0 st: 1 flags:1 dts: 0.967000 pts: 0.967000 pos: 330175 size: 209
+ret: 0 st: 1 flags:1 ts: 1.471000
+ret: 0 st: 1 flags:1 dts: 0.967000 pts: 0.967000 pos: 330175 size: 209
ret: 0 st:-1 flags:0 ts: 0.365002
ret: 0 st: 1 flags:1 dts: 0.444000 pts: 0.444000 pos: 147775 size: 209
ret: 0 st:-1 flags:1 ts:-0.740831
ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 575 size: 28487
ret: 0 st: 0 flags:0 ts: 2.153000
-ret: 0 st: 1 flags:1 dts: 0.960000 pts: 0.960000 pos: -1 size: 209
+ret: 0 st: 1 flags:1 dts: 0.940000 pts: 0.940000 pos: 301375 size: 209
ret: 0 st: 0 flags:1 ts: 1.048000
-ret: 0 st: 1 flags:1 dts: 0.960000 pts: 0.960000 pos: -1 size: 209
+ret: 0 st: 1 flags:1 dts: 0.940000 pts: 0.940000 pos: 301375 size: 209
ret: 0 st: 1 flags:0 ts:-0.058000
ret: 0 st: 1 flags:1 dts: 0.000000 pts: 0.000000 pos: 29375 size: 208
-ret:-1 st: 1 flags:1 ts: 2.836000
+ret: 0 st: 1 flags:1 ts: 2.836000
+ret: 0 st: 1 flags:1 dts: 0.967000 pts: 0.967000 pos: 330175 size: 209
ret: 0 st:-1 flags:0 ts: 1.730004
-ret: 0 st: 1 flags:1 dts: 0.960000 pts: 0.960000 pos: -1 size: 209
+ret: 0 st: 1 flags:1 dts: 0.940000 pts: 0.940000 pos: 301375 size: 209
ret: 0 st:-1 flags:1 ts: 0.624171
ret: 0 st: 1 flags:1 dts: 0.444000 pts: 0.444000 pos: 147775 size: 209
ret: 0 st: 0 flags:0 ts:-0.482000
ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 575 size: 28487
ret: 0 st: 0 flags:1 ts: 2.413000
-ret: 0 st: 1 flags:1 dts: 0.960000 pts: 0.960000 pos: -1 size: 209
-ret:-1 st: 1 flags:0 ts: 1.307000
+ret: 0 st: 1 flags:1 dts: 0.940000 pts: 0.940000 pos: 301375 size: 209
+ret: 0 st: 1 flags:0 ts: 1.307000
+ret: 0 st: 1 flags:1 dts: 0.967000 pts: 0.967000 pos: 330175 size: 209
ret: 0 st: 1 flags:1 ts: 0.201000
ret: 0 st: 1 flags:1 dts: 0.183000 pts: 0.183000 pos: 70975 size: 209
ret: 0 st:-1 flags:0 ts:-0.904994
ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 575 size: 28487
ret: 0 st:-1 flags:1 ts: 1.989173
-ret: 0 st: 1 flags:1 dts: 0.960000 pts: 0.960000 pos: -1 size: 209
+ret: 0 st: 1 flags:1 dts: 0.940000 pts: 0.940000 pos: 301375 size: 209
ret: 0 st: 0 flags:0 ts: 0.883000
-ret: 0 st: 1 flags:1 dts: 0.960000 pts: 0.960000 pos: -1 size: 209
+ret: 0 st: 1 flags:1 dts: 0.940000 pts: 0.940000 pos: 301375 size: 209
ret: 0 st: 0 flags:1 ts:-0.222000
ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 575 size: 28487
-ret:-1 st: 1 flags:0 ts: 2.672000
-ret:-1 st: 1 flags:1 ts: 1.566000
+ret: 0 st: 1 flags:0 ts: 2.672000
+ret: 0 st: 1 flags:1 dts: 0.967000 pts: 0.967000 pos: 330175 size: 209
+ret: 0 st: 1 flags:1 ts: 1.566000
+ret: 0 st: 1 flags:1 dts: 0.967000 pts: 0.967000 pos: 330175 size: 209
ret: 0 st:-1 flags:0 ts: 0.460008
ret: 0 st: 1 flags:1 dts: 0.444000 pts: 0.444000 pos: 147775 size: 209
ret: 0 st:-1 flags:1 ts:-0.645825
diff --git a/tests/ref/seek/lavf_avi b/tests/ref/seek/lavf_avi
index 964f0b8b6f..6253960efd 100644
--- a/tests/ref/seek/lavf_avi
+++ b/tests/ref/seek/lavf_avi
@@ -8,27 +8,27 @@ ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 301466 size: 27864
ret:-1 st: 0 flags:1 ts:-0.320000
ret:-1 st: 1 flags:0 ts: 2.586122
ret: 0 st: 1 flags:1 ts: 1.462857
-ret: 0 st: 1 flags:1 dts: 1.018776 pts: 1.018776 pos: 329774 size: 209
+ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 301466 size: 27864
ret: 0 st:-1 flags:0 ts: 0.365002
-ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 156166 size: 27955
+ret: 0 st: 1 flags:1 dts: 0.470204 pts: 0.470204 pos: 155948 size: 209
ret:-1 st:-1 flags:1 ts:-0.740831
ret:-1 st: 0 flags:0 ts: 2.160000
ret: 0 st: 0 flags:1 ts: 1.040000
ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 301466 size: 27864
ret: 0 st: 1 flags:0 ts:-0.052245
-ret: 0 st: 1 flags:1 dts: 0.000000 pts: 0.000000 pos: 37784 size: 208
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 9908 size: 27867
ret: 0 st: 1 flags:1 ts: 2.847347
-ret: 0 st: 1 flags:1 dts: 1.018776 pts: 1.018776 pos: 329774 size: 209
+ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 301466 size: 27864
ret:-1 st:-1 flags:0 ts: 1.730004
ret: 0 st:-1 flags:1 ts: 0.624171
-ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 156166 size: 27955
+ret: 0 st: 1 flags:1 dts: 0.470204 pts: 0.470204 pos: 155948 size: 209
ret: 0 st: 0 flags:0 ts:-0.480000
ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 9908 size: 27867
ret: 0 st: 0 flags:1 ts: 2.400000
ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 301466 size: 27864
ret:-1 st: 1 flags:0 ts: 1.306122
ret: 0 st: 1 flags:1 ts: 0.208980
-ret: 0 st: 1 flags:1 dts: 0.208980 pts: 0.208980 pos: 92800 size: 209
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 9908 size: 27867
ret: 0 st:-1 flags:0 ts:-0.904994
ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 9908 size: 27867
ret: 0 st:-1 flags:1 ts: 1.989173
@@ -38,7 +38,7 @@ ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 301466 size: 27864
ret:-1 st: 0 flags:1 ts:-0.240000
ret:-1 st: 1 flags:0 ts: 2.664490
ret: 0 st: 1 flags:1 ts: 1.567347
-ret: 0 st: 1 flags:1 dts: 1.018776 pts: 1.018776 pos: 329774 size: 209
+ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 301466 size: 27864
ret: 0 st:-1 flags:0 ts: 0.460008
-ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 156166 size: 27955
+ret: 0 st: 1 flags:1 dts: 0.470204 pts: 0.470204 pos: 155948 size: 209
ret:-1 st:-1 flags:1 ts:-0.645825
diff --git a/tests/ref/seek/lavf_dv b/tests/ref/seek/lavf_dv
index 3c49749a6b..0000ff5abe 100644
--- a/tests/ref/seek/lavf_dv
+++ b/tests/ref/seek/lavf_dv
@@ -1,53 +1,53 @@
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000
ret: 0 st:-1 flags:0 ts:-1.000000
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000
ret: 0 st:-1 flags:1 ts: 1.894167
-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:3456000 size:144000
ret: 0 st: 0 flags:0 ts: 0.800000
-ret: 0 st: 0 flags:1 dts: 0.800000 pts: 0.800000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.800000 pts: 0.800000 pos:2880000 size:144000
ret: 0 st: 0 flags:1 ts:-0.320000
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000
ret: 0 st: 1 flags:0 ts: 2.576667
-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:3456000 size:144000
ret: 0 st: 1 flags:1 ts: 1.470833
-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:3456000 size:144000
ret: 0 st:-1 flags:0 ts: 0.365002
-ret: 0 st: 0 flags:1 dts: 0.360000 pts: 0.360000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.360000 pts: 0.360000 pos:1296000 size:144000
ret: 0 st:-1 flags:1 ts:-0.740831
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000
ret: 0 st: 0 flags:0 ts: 2.160000
-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:3456000 size:144000
ret: 0 st: 0 flags:1 ts: 1.040000
-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:3456000 size:144000
ret: 0 st: 1 flags:0 ts:-0.058333
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000
ret: 0 st: 1 flags:1 ts: 2.835833
-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:3456000 size:144000
ret: 0 st:-1 flags:0 ts: 1.730004
-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:3456000 size:144000
ret: 0 st:-1 flags:1 ts: 0.624171
-ret: 0 st: 0 flags:1 dts: 0.640000 pts: 0.640000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.640000 pts: 0.640000 pos:2304000 size:144000
ret: 0 st: 0 flags:0 ts:-0.480000
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000
ret: 0 st: 0 flags:1 ts: 2.400000
-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:3456000 size:144000
ret: 0 st: 1 flags:0 ts: 1.306667
-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:3456000 size:144000
ret: 0 st: 1 flags:1 ts: 0.200833
-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:3456000 size:144000
ret: 0 st:-1 flags:0 ts:-0.904994
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000
ret: 0 st:-1 flags:1 ts: 1.989173
-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:3456000 size:144000
ret: 0 st: 0 flags:0 ts: 0.880000
-ret: 0 st: 0 flags:1 dts: 0.880000 pts: 0.880000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.880000 pts: 0.880000 pos:3168000 size:144000
ret: 0 st: 0 flags:1 ts:-0.240000
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000
ret: 0 st: 1 flags:0 ts: 2.671667
-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:3456000 size:144000
ret: 0 st: 1 flags:1 ts: 1.565833
-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:3456000 size:144000
ret: 0 st:-1 flags:0 ts: 0.460008
-ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos:1728000 size:144000
ret: 0 st:-1 flags:1 ts:-0.645825
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000
diff --git a/tests/ref/seek/lavf_ffm b/tests/ref/seek/lavf_ffm
index 46cf764c88..2218d4fd85 100644
--- a/tests/ref/seek/lavf_ffm
+++ b/tests/ref/seek/lavf_ffm
@@ -4,7 +4,7 @@ ret: 0 st: 0 flags:1 dts:-0.040000 pts: 0.000000 pos: 8192 size: 24664
ret: 0 st:-1 flags:1 ts: 1.894167
ret: 0 st: 1 flags:1 dts: 0.940408 pts: 0.940408 pos: 376832 size: 209
ret: 0 st: 0 flags:0 ts: 0.788334
-ret: 0 st: 1 flags:1 dts: 0.783673 pts: 0.783673 pos: 315392 size: 209
+ret: 0 st: 1 flags:1 dts: 0.809796 pts: 0.809796 pos: 327680 size: 209
ret: 0 st: 0 flags:1 ts:-0.317499
ret: 0 st: 0 flags:1 dts:-0.040000 pts: 0.000000 pos: 8192 size: 24664
ret: 0 st: 1 flags:0 ts: 2.576668
@@ -12,7 +12,7 @@ ret: 0 st: 1 flags:1 dts: 0.940408 pts: 0.940408 pos: 376832 size: 209
ret: 0 st: 1 flags:1 ts: 1.470835
ret: 0 st: 1 flags:1 dts: 0.940408 pts: 0.940408 pos: 376832 size: 209
ret: 0 st:-1 flags:0 ts: 0.365002
-ret: 0 st: 1 flags:1 dts: 0.339592 pts: 0.339592 pos: 155648 size: 209
+ret: 0 st: 1 flags:1 dts: 0.365714 pts: 0.365714 pos: 163840 size: 209
ret: 0 st:-1 flags:1 ts:-0.740831
ret: 0 st: 0 flags:1 dts:-0.040000 pts: 0.000000 pos: 8192 size: 24664
ret: 0 st: 0 flags:0 ts: 2.153336
@@ -40,7 +40,7 @@ ret: 0 st: 0 flags:1 dts:-0.040000 pts: 0.000000 pos: 8192 size: 24664
ret: 0 st:-1 flags:1 ts: 1.989173
ret: 0 st: 1 flags:1 dts: 0.940408 pts: 0.940408 pos: 376832 size: 209
ret: 0 st: 0 flags:0 ts: 0.883340
-ret: 0 st: 0 flags:0 dts: 0.880000 pts: 0.920000 pos: 339968 size: 12307
+ret: 0 st: 1 flags:1 dts: 0.888163 pts: 0.888163 pos: 352256 size: 209
ret: 0 st: 0 flags:1 ts:-0.222493
ret: 0 st: 0 flags:1 dts:-0.040000 pts: 0.000000 pos: 8192 size: 24664
ret: 0 st: 1 flags:0 ts: 2.671674
@@ -48,6 +48,6 @@ ret: 0 st: 1 flags:1 dts: 0.940408 pts: 0.940408 pos: 376832 size: 209
ret: 0 st: 1 flags:1 ts: 1.565841
ret: 0 st: 1 flags:1 dts: 0.940408 pts: 0.940408 pos: 376832 size: 209
ret: 0 st:-1 flags:0 ts: 0.460008
-ret: 0 st: 1 flags:1 dts: 0.444082 pts: 0.444082 pos: 204800 size: 209
+ret: 0 st: 1 flags:1 dts: 0.496327 pts: 0.496327 pos: 221184 size: 209
ret: 0 st:-1 flags:1 ts:-0.645825
ret: 0 st: 0 flags:1 dts:-0.040000 pts: 0.000000 pos: 8192 size: 24664
diff --git a/tests/ref/seek/lavf_gif b/tests/ref/seek/lavf_gif
index 5da803da42..883f18761e 100644
--- a/tests/ref/seek/lavf_gif
+++ b/tests/ref/seek/lavf_gif
@@ -1,4 +1,4 @@
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:2906382
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:2906401
ret:-EINVAL st:-1 flags:0 ts:-1.000000
ret:-EINVAL st:-1 flags:1 ts: 1.894167
ret:-EINVAL st: 0 flags:0 ts: 0.800000
diff --git a/tests/ref/seek/lavf_rm b/tests/ref/seek/lavf_rm
index 188367bc90..394928086b 100644
--- a/tests/ref/seek/lavf_rm
+++ b/tests/ref/seek/lavf_rm
@@ -7,8 +7,10 @@ ret: 0 st: 0 flags:0 ts: 0.788000
ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 314982 size: 31143
ret: 0 st: 0 flags:1 ts:-0.317000
ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 398 size: 31082
-ret:-1 st: 1 flags:0 ts: 2.577000
-ret:-1 st: 1 flags:1 ts: 1.471000
+ret: 0 st: 1 flags:0 ts: 2.577000
+ret: 0 st: 1 flags:1 dts: 0.975000 pts: 0.975000 pos: 346128 size: 278
+ret: 0 st: 1 flags:1 ts: 1.471000
+ret: 0 st: 1 flags:1 dts: 0.975000 pts: 0.975000 pos: 346128 size: 278
ret: 0 st:-1 flags:0 ts: 0.365002
ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 158515 size: 31134
ret: 0 st:-1 flags:1 ts:-0.740831
@@ -19,7 +21,8 @@ ret: 0 st: 0 flags:1 ts: 1.048000
ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 314982 size: 31143
ret: 0 st: 1 flags:0 ts:-0.058000
ret: 0 st: 1 flags:1 dts: 0.000000 pts: 0.000000 pos: 31483 size: 278
-ret:-1 st: 1 flags:1 ts: 2.836000
+ret: 0 st: 1 flags:1 ts: 2.836000
+ret: 0 st: 1 flags:1 dts: 0.975000 pts: 0.975000 pos: 346128 size: 278
ret: 0 st:-1 flags:0 ts: 1.730004
ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 314982 size: 31143
ret: 0 st:-1 flags:1 ts: 0.624171
@@ -28,7 +31,8 @@ ret: 0 st: 0 flags:0 ts:-0.482000
ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 398 size: 31082
ret: 0 st: 0 flags:1 ts: 2.413000
ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 314982 size: 31143
-ret:-1 st: 1 flags:0 ts: 1.307000
+ret: 0 st: 1 flags:0 ts: 1.307000
+ret: 0 st: 1 flags:1 dts: 0.975000 pts: 0.975000 pos: 346128 size: 278
ret: 0 st: 1 flags:1 ts: 0.201000
ret: 0 st: 1 flags:1 dts: 0.174000 pts: 0.174000 pos: 78969 size: 278
ret: 0 st:-1 flags:0 ts:-0.904994
@@ -39,8 +43,10 @@ ret: 0 st: 0 flags:0 ts: 0.883000
ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 314982 size: 31143
ret: 0 st: 0 flags:1 ts:-0.222000
ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 398 size: 31082
-ret:-1 st: 1 flags:0 ts: 2.672000
-ret:-1 st: 1 flags:1 ts: 1.566000
+ret: 0 st: 1 flags:0 ts: 2.672000
+ret: 0 st: 1 flags:1 dts: 0.975000 pts: 0.975000 pos: 346128 size: 278
+ret: 0 st: 1 flags:1 ts: 1.566000
+ret: 0 st: 1 flags:1 dts: 0.975000 pts: 0.975000 pos: 346128 size: 278
ret: 0 st:-1 flags:0 ts: 0.460008
ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 158515 size: 31134
ret: 0 st:-1 flags:1 ts:-0.645825
diff --git a/tests/ref/seek/lavf_ts b/tests/ref/seek/lavf_ts
index 9ed59ef5af..0bc7a527f4 100644
--- a/tests/ref/seek/lavf_ts
+++ b/tests/ref/seek/lavf_ts
@@ -1,53 +1,53 @@
ret: 0 st: 0 flags:1 dts: 1.360000 pts: 1.400000 pos: 564 size: 24801
ret: 0 st:-1 flags:0 ts:-1.000000
-ret: 0 st: 0 flags:0 dts: 1.440000 pts: 1.480000 pos: 44932 size: 14502
+ret: 0 st: 0 flags:1 dts: 1.360000 pts: 1.400000 pos: 564 size: 24801
ret: 0 st:-1 flags:1 ts: 1.894167
-ret: 0 st: 1 flags:1 dts: 2.131433 pts: 2.131433 pos: 403636 size: 209
+ret: 0 st: 0 flags:0 dts: 1.880000 pts: 1.920000 pos: 216012 size: 17441
ret: 0 st: 0 flags:0 ts: 0.788333
-ret: 0 st: 0 flags:0 dts: 1.520000 pts: 1.560000 pos: 74260 size: 13388
+ret: 0 st: 0 flags:1 dts: 1.360000 pts: 1.400000 pos: 564 size: 24801
ret: 0 st: 0 flags:1 ts:-0.317500
ret: 0 st: 0 flags:1 dts: 1.360000 pts: 1.400000 pos: 564 size: 24801
ret: 0 st: 1 flags:0 ts: 2.576667
ret: 0 st: 1 flags:1 dts: 2.131433 pts: 2.131433 pos: 403636 size: 209
ret: 0 st: 1 flags:1 ts: 1.470833
-ret: 0 st: 0 flags:0 dts: 2.160000 pts: 2.200000 pos: 325240 size: 12679
+ret: 0 st: 1 flags:1 dts: 1.400000 pts: 1.400000 pos: 172584 size: 208
ret: 0 st:-1 flags:0 ts: 0.365002
-ret: 0 st: 0 flags:0 dts: 1.440000 pts: 1.480000 pos: 44932 size: 14502
+ret: 0 st: 0 flags:1 dts: 1.360000 pts: 1.400000 pos: 564 size: 24801
ret: 0 st:-1 flags:1 ts:-0.740831
ret: 0 st: 0 flags:1 dts: 1.360000 pts: 1.400000 pos: 564 size: 24801
ret: 0 st: 0 flags:0 ts: 2.153333
-ret: 0 st: 1 flags:1 dts: 2.131433 pts: 2.131433 pos: 403636 size: 209
+ret: 0 st: 0 flags:0 dts: 2.160000 pts: 2.200000 pos: 325240 size: 12679
ret: 0 st: 0 flags:1 ts: 1.047500
-ret: 0 st: 0 flags:0 dts: 1.680000 pts: 1.720000 pos: 130096 size: 14133
+ret: 0 st: 0 flags:1 dts: 1.360000 pts: 1.400000 pos: 564 size: 24801
ret: 0 st: 1 flags:0 ts:-0.058333
-ret: 0 st: 0 flags:0 dts: 1.440000 pts: 1.480000 pos: 44932 size: 14502
+ret: 0 st: 1 flags:1 dts: 1.400000 pts: 1.400000 pos: 172584 size: 208
ret: 0 st: 1 flags:1 ts: 2.835833
ret: 0 st: 1 flags:1 dts: 2.131433 pts: 2.131433 pos: 403636 size: 209
ret: 0 st:-1 flags:0 ts: 1.730004
-ret: 0 st: 1 flags:1 dts: 2.131433 pts: 2.131433 pos: 403636 size: 209
+ret: 0 st: 1 flags:1 dts: 1.400000 pts: 1.400000 pos: 172584 size: 208
ret: 0 st:-1 flags:1 ts: 0.624171
ret: 0 st: 0 flags:1 dts: 1.360000 pts: 1.400000 pos: 564 size: 24801
ret: 0 st: 0 flags:0 ts:-0.481667
-ret: 0 st: 0 flags:0 dts: 1.440000 pts: 1.480000 pos: 44932 size: 14502
+ret: 0 st: 0 flags:1 dts: 1.360000 pts: 1.400000 pos: 564 size: 24801
ret: 0 st: 0 flags:1 ts: 2.412500
ret: 0 st: 1 flags:1 dts: 2.131433 pts: 2.131433 pos: 403636 size: 209
ret: 0 st: 1 flags:0 ts: 1.306667
-ret: 0 st: 0 flags:0 dts: 2.080000 pts: 2.120000 pos: 294032 size: 13839
+ret: 0 st: 1 flags:1 dts: 1.400000 pts: 1.400000 pos: 172584 size: 208
ret: 0 st: 1 flags:1 ts: 0.200844
-ret: 0 st: 0 flags:1 dts: 1.360000 pts: 1.400000 pos: 564 size: 24801
+ret: 0 st: 1 flags:1 dts: 1.400000 pts: 1.400000 pos: 172584 size: 208
ret: 0 st:-1 flags:0 ts:-0.904994
-ret: 0 st: 0 flags:0 dts: 1.440000 pts: 1.480000 pos: 44932 size: 14502
+ret: 0 st: 0 flags:1 dts: 1.360000 pts: 1.400000 pos: 564 size: 24801
ret: 0 st:-1 flags:1 ts: 1.989173
-ret: 0 st: 1 flags:1 dts: 2.131433 pts: 2.131433 pos: 403636 size: 209
+ret: 0 st: 0 flags:0 dts: 1.960000 pts: 2.000000 pos: 250980 size: 13438
ret: 0 st: 0 flags:0 ts: 0.883344
-ret: 0 st: 0 flags:0 dts: 1.600000 pts: 1.640000 pos: 102836 size: 12781
+ret: 0 st: 0 flags:1 dts: 1.360000 pts: 1.400000 pos: 564 size: 24801
ret: 0 st: 0 flags:1 ts:-0.222489
ret: 0 st: 0 flags:1 dts: 1.360000 pts: 1.400000 pos: 564 size: 24801
ret: 0 st: 1 flags:0 ts: 2.671678
ret: 0 st: 1 flags:1 dts: 2.131433 pts: 2.131433 pos: 403636 size: 209
ret: 0 st: 1 flags:1 ts: 1.565844
-ret: 0 st: 0 flags:0 dts: 2.240000 pts: 2.280000 pos: 350996 size: 11307
+ret: 0 st: 1 flags:1 dts: 1.400000 pts: 1.400000 pos: 172584 size: 208
ret: 0 st:-1 flags:0 ts: 0.460008
-ret: 0 st: 0 flags:0 dts: 1.440000 pts: 1.480000 pos: 44932 size: 14502
+ret: 0 st: 0 flags:1 dts: 1.360000 pts: 1.400000 pos: 564 size: 24801
ret: 0 st:-1 flags:1 ts:-0.645825
ret: 0 st: 0 flags:1 dts: 1.360000 pts: 1.400000 pos: 564 size: 24801
diff --git a/tests/ref/seek/lavf_wav b/tests/ref/seek/lavf_wav
index b411c3c7cb..1a9cfc54c7 100644
--- a/tests/ref/seek/lavf_wav
+++ b/tests/ref/seek/lavf_wav
@@ -1,53 +1,53 @@
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096
ret: 0 st:-1 flags:0 ts:-1.000000
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096
ret: 0 st:-1 flags:1 ts: 1.894167
ret:-EOF
ret: 0 st: 0 flags:0 ts: 0.788345
-ret: 0 st: 0 flags:1 dts: 0.788345 pts: 0.788345 pos: 69576 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.788345 pts: 0.788345 pos: 69578 size: 4096
ret: 0 st: 0 flags:1 ts:-0.317506
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096
ret: 0 st:-1 flags:0 ts: 2.576668
ret:-EOF
ret: 0 st:-1 flags:1 ts: 1.470835
ret:-EOF
ret: 0 st: 0 flags:0 ts: 0.365011
-ret: 0 st: 0 flags:1 dts: 0.365011 pts: 0.365011 pos: 32238 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.365011 pts: 0.365011 pos: 32240 size: 4096
ret: 0 st: 0 flags:1 ts:-0.740839
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096
ret: 0 st:-1 flags:0 ts: 2.153336
ret:-EOF
ret: 0 st:-1 flags:1 ts: 1.047503
ret:-EOF
ret: 0 st: 0 flags:0 ts:-0.058322
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096
ret: 0 st: 0 flags:1 ts: 2.835828
ret:-EOF
ret: 0 st:-1 flags:0 ts: 1.730004
ret:-EOF
ret: 0 st:-1 flags:1 ts: 0.624171
-ret: 0 st: 0 flags:1 dts: 0.624172 pts: 0.624172 pos: 55096 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.624172 pts: 0.624172 pos: 55098 size: 4096
ret: 0 st: 0 flags:0 ts:-0.481655
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096
ret: 0 st: 0 flags:1 ts: 2.412494
ret:-EOF
ret: 0 st:-1 flags:0 ts: 1.306672
ret:-EOF
ret: 0 st:-1 flags:1 ts: 0.200839
-ret: 0 st: 0 flags:1 dts: 0.200839 pts: 0.200839 pos: 17758 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.200839 pts: 0.200839 pos: 17760 size: 4096
ret: 0 st: 0 flags:0 ts:-0.904989
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096
ret: 0 st: 0 flags:1 ts: 1.989184
ret:-EOF
ret: 0 st:-1 flags:0 ts: 0.883340
-ret: 0 st: 0 flags:1 dts: 0.883333 pts: 0.883333 pos: 77954 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.883333 pts: 0.883333 pos: 77956 size: 4096
ret: 0 st:-1 flags:1 ts:-0.222493
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096
ret: 0 st: 0 flags:0 ts: 2.671678
ret:-EOF
ret: 0 st: 0 flags:1 ts: 1.565850
ret:-EOF
ret: 0 st:-1 flags:0 ts: 0.460008
-ret: 0 st: 0 flags:1 dts: 0.460000 pts: 0.460000 pos: 40616 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.460000 pts: 0.460000 pos: 40618 size: 4096
ret: 0 st:-1 flags:1 ts:-0.645825
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096
diff --git a/tests/ref/seek/pcm_alaw_wav b/tests/ref/seek/pcm_alaw_wav
index 06f50e765e..22d95bf27f 100644
--- a/tests/ref/seek/pcm_alaw_wav
+++ b/tests/ref/seek/pcm_alaw_wav
@@ -1,53 +1,53 @@
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096
ret: 0 st:-1 flags:0 ts:-1.000000
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096
ret: 0 st:-1 flags:1 ts: 1.894167
-ret: 0 st: 0 flags:1 dts: 1.894127 pts: 1.894127 pos: 30362 size: 4096
+ret: 0 st: 0 flags:1 dts: 1.894127 pts: 1.894127 pos: 30364 size: 4096
ret: 0 st: 0 flags:0 ts: 0.788345
-ret: 0 st: 0 flags:1 dts: 0.788367 pts: 0.788367 pos: 12670 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.788367 pts: 0.788367 pos: 12672 size: 4096
ret: 0 st: 0 flags:1 ts:-0.317506
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096
ret: 0 st:-1 flags:0 ts: 2.576668
-ret: 0 st: 0 flags:1 dts: 2.576757 pts: 2.576757 pos: 41284 size: 4096
+ret: 0 st: 0 flags:1 dts: 2.576757 pts: 2.576757 pos: 41286 size: 4096
ret: 0 st:-1 flags:1 ts: 1.470835
-ret: 0 st: 0 flags:1 dts: 1.470748 pts: 1.470748 pos: 23588 size: 4096
+ret: 0 st: 0 flags:1 dts: 1.470748 pts: 1.470748 pos: 23590 size: 4096
ret: 0 st: 0 flags:0 ts: 0.365011
-ret: 0 st: 0 flags:1 dts: 0.365125 pts: 0.365125 pos: 5898 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.365125 pts: 0.365125 pos: 5900 size: 4096
ret: 0 st: 0 flags:1 ts:-0.740839
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096
ret: 0 st:-1 flags:0 ts: 2.153336
-ret: 0 st: 0 flags:1 dts: 2.153379 pts: 2.153379 pos: 34510 size: 4096
+ret: 0 st: 0 flags:1 dts: 2.153379 pts: 2.153379 pos: 34512 size: 4096
ret: 0 st:-1 flags:1 ts: 1.047503
-ret: 0 st: 0 flags:1 dts: 1.047506 pts: 1.047506 pos: 16816 size: 4096
+ret: 0 st: 0 flags:1 dts: 1.047506 pts: 1.047506 pos: 16818 size: 4096
ret: 0 st: 0 flags:0 ts:-0.058322
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096
ret: 0 st: 0 flags:1 ts: 2.835828
-ret: 0 st: 0 flags:1 dts: 2.835760 pts: 2.835760 pos: 45428 size: 4096
+ret: 0 st: 0 flags:1 dts: 2.835760 pts: 2.835760 pos: 45430 size: 4096
ret: 0 st:-1 flags:0 ts: 1.730004
-ret: 0 st: 0 flags:1 dts: 1.730000 pts: 1.730000 pos: 27736 size: 4096
+ret: 0 st: 0 flags:1 dts: 1.730000 pts: 1.730000 pos: 27738 size: 4096
ret: 0 st:-1 flags:1 ts: 0.624171
-ret: 0 st: 0 flags:1 dts: 0.624127 pts: 0.624127 pos: 10042 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.624127 pts: 0.624127 pos: 10044 size: 4096
ret: 0 st: 0 flags:0 ts:-0.481655
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096
ret: 0 st: 0 flags:1 ts: 2.412494
-ret: 0 st: 0 flags:1 dts: 2.412381 pts: 2.412381 pos: 38654 size: 4096
+ret: 0 st: 0 flags:1 dts: 2.412381 pts: 2.412381 pos: 38656 size: 4096
ret: 0 st:-1 flags:0 ts: 1.306672
-ret: 0 st: 0 flags:1 dts: 1.306757 pts: 1.306757 pos: 20964 size: 4096
+ret: 0 st: 0 flags:1 dts: 1.306757 pts: 1.306757 pos: 20966 size: 4096
ret: 0 st:-1 flags:1 ts: 0.200839
-ret: 0 st: 0 flags:1 dts: 0.200748 pts: 0.200748 pos: 3268 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.200748 pts: 0.200748 pos: 3270 size: 4096
ret: 0 st: 0 flags:0 ts:-0.904989
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096
ret: 0 st: 0 flags:1 ts: 1.989184
-ret: 0 st: 0 flags:1 dts: 1.989116 pts: 1.989116 pos: 31882 size: 4096
+ret: 0 st: 0 flags:1 dts: 1.989116 pts: 1.989116 pos: 31884 size: 4096
ret: 0 st:-1 flags:0 ts: 0.883340
-ret: 0 st: 0 flags:1 dts: 0.883379 pts: 0.883379 pos: 14190 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.883379 pts: 0.883379 pos: 14192 size: 4096
ret: 0 st:-1 flags:1 ts:-0.222493
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096
ret: 0 st: 0 flags:0 ts: 2.671678
-ret: 0 st: 0 flags:1 dts: 2.671746 pts: 2.671746 pos: 42804 size: 4096
+ret: 0 st: 0 flags:1 dts: 2.671746 pts: 2.671746 pos: 42806 size: 4096
ret: 0 st: 0 flags:1 ts: 1.565850
-ret: 0 st: 0 flags:1 dts: 1.565760 pts: 1.565760 pos: 25108 size: 4096
+ret: 0 st: 0 flags:1 dts: 1.565760 pts: 1.565760 pos: 25110 size: 4096
ret: 0 st:-1 flags:0 ts: 0.460008
-ret: 0 st: 0 flags:1 dts: 0.460000 pts: 0.460000 pos: 7416 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.460000 pts: 0.460000 pos: 7418 size: 4096
ret: 0 st:-1 flags:1 ts:-0.645825
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096
diff --git a/tests/ref/seek/pcm_mulaw_wav b/tests/ref/seek/pcm_mulaw_wav
index 06f50e765e..22d95bf27f 100644
--- a/tests/ref/seek/pcm_mulaw_wav
+++ b/tests/ref/seek/pcm_mulaw_wav
@@ -1,53 +1,53 @@
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096
ret: 0 st:-1 flags:0 ts:-1.000000
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096
ret: 0 st:-1 flags:1 ts: 1.894167
-ret: 0 st: 0 flags:1 dts: 1.894127 pts: 1.894127 pos: 30362 size: 4096
+ret: 0 st: 0 flags:1 dts: 1.894127 pts: 1.894127 pos: 30364 size: 4096
ret: 0 st: 0 flags:0 ts: 0.788345
-ret: 0 st: 0 flags:1 dts: 0.788367 pts: 0.788367 pos: 12670 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.788367 pts: 0.788367 pos: 12672 size: 4096
ret: 0 st: 0 flags:1 ts:-0.317506
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096
ret: 0 st:-1 flags:0 ts: 2.576668
-ret: 0 st: 0 flags:1 dts: 2.576757 pts: 2.576757 pos: 41284 size: 4096
+ret: 0 st: 0 flags:1 dts: 2.576757 pts: 2.576757 pos: 41286 size: 4096
ret: 0 st:-1 flags:1 ts: 1.470835
-ret: 0 st: 0 flags:1 dts: 1.470748 pts: 1.470748 pos: 23588 size: 4096
+ret: 0 st: 0 flags:1 dts: 1.470748 pts: 1.470748 pos: 23590 size: 4096
ret: 0 st: 0 flags:0 ts: 0.365011
-ret: 0 st: 0 flags:1 dts: 0.365125 pts: 0.365125 pos: 5898 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.365125 pts: 0.365125 pos: 5900 size: 4096
ret: 0 st: 0 flags:1 ts:-0.740839
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096
ret: 0 st:-1 flags:0 ts: 2.153336
-ret: 0 st: 0 flags:1 dts: 2.153379 pts: 2.153379 pos: 34510 size: 4096
+ret: 0 st: 0 flags:1 dts: 2.153379 pts: 2.153379 pos: 34512 size: 4096
ret: 0 st:-1 flags:1 ts: 1.047503
-ret: 0 st: 0 flags:1 dts: 1.047506 pts: 1.047506 pos: 16816 size: 4096
+ret: 0 st: 0 flags:1 dts: 1.047506 pts: 1.047506 pos: 16818 size: 4096
ret: 0 st: 0 flags:0 ts:-0.058322
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096
ret: 0 st: 0 flags:1 ts: 2.835828
-ret: 0 st: 0 flags:1 dts: 2.835760 pts: 2.835760 pos: 45428 size: 4096
+ret: 0 st: 0 flags:1 dts: 2.835760 pts: 2.835760 pos: 45430 size: 4096
ret: 0 st:-1 flags:0 ts: 1.730004
-ret: 0 st: 0 flags:1 dts: 1.730000 pts: 1.730000 pos: 27736 size: 4096
+ret: 0 st: 0 flags:1 dts: 1.730000 pts: 1.730000 pos: 27738 size: 4096
ret: 0 st:-1 flags:1 ts: 0.624171
-ret: 0 st: 0 flags:1 dts: 0.624127 pts: 0.624127 pos: 10042 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.624127 pts: 0.624127 pos: 10044 size: 4096
ret: 0 st: 0 flags:0 ts:-0.481655
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096
ret: 0 st: 0 flags:1 ts: 2.412494
-ret: 0 st: 0 flags:1 dts: 2.412381 pts: 2.412381 pos: 38654 size: 4096
+ret: 0 st: 0 flags:1 dts: 2.412381 pts: 2.412381 pos: 38656 size: 4096
ret: 0 st:-1 flags:0 ts: 1.306672
-ret: 0 st: 0 flags:1 dts: 1.306757 pts: 1.306757 pos: 20964 size: 4096
+ret: 0 st: 0 flags:1 dts: 1.306757 pts: 1.306757 pos: 20966 size: 4096
ret: 0 st:-1 flags:1 ts: 0.200839
-ret: 0 st: 0 flags:1 dts: 0.200748 pts: 0.200748 pos: 3268 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.200748 pts: 0.200748 pos: 3270 size: 4096
ret: 0 st: 0 flags:0 ts:-0.904989
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096
ret: 0 st: 0 flags:1 ts: 1.989184
-ret: 0 st: 0 flags:1 dts: 1.989116 pts: 1.989116 pos: 31882 size: 4096
+ret: 0 st: 0 flags:1 dts: 1.989116 pts: 1.989116 pos: 31884 size: 4096
ret: 0 st:-1 flags:0 ts: 0.883340
-ret: 0 st: 0 flags:1 dts: 0.883379 pts: 0.883379 pos: 14190 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.883379 pts: 0.883379 pos: 14192 size: 4096
ret: 0 st:-1 flags:1 ts:-0.222493
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096
ret: 0 st: 0 flags:0 ts: 2.671678
-ret: 0 st: 0 flags:1 dts: 2.671746 pts: 2.671746 pos: 42804 size: 4096
+ret: 0 st: 0 flags:1 dts: 2.671746 pts: 2.671746 pos: 42806 size: 4096
ret: 0 st: 0 flags:1 ts: 1.565850
-ret: 0 st: 0 flags:1 dts: 1.565760 pts: 1.565760 pos: 25108 size: 4096
+ret: 0 st: 0 flags:1 dts: 1.565760 pts: 1.565760 pos: 25110 size: 4096
ret: 0 st:-1 flags:0 ts: 0.460008
-ret: 0 st: 0 flags:1 dts: 0.460000 pts: 0.460000 pos: 7416 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.460000 pts: 0.460000 pos: 7418 size: 4096
ret: 0 st:-1 flags:1 ts:-0.645825
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096
diff --git a/tests/ref/seek/pcm_s16le_wav b/tests/ref/seek/pcm_s16le_wav
index 41acc98d8d..4f1ffc5acd 100644
--- a/tests/ref/seek/pcm_s16le_wav
+++ b/tests/ref/seek/pcm_s16le_wav
@@ -1,53 +1,53 @@
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096
ret: 0 st:-1 flags:0 ts:-1.000000
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096
ret: 0 st:-1 flags:1 ts: 1.894167
-ret: 0 st: 0 flags:1 dts: 1.894172 pts: 1.894172 pos: 334176 size: 4096
+ret: 0 st: 0 flags:1 dts: 1.894172 pts: 1.894172 pos: 334178 size: 4096
ret: 0 st: 0 flags:0 ts: 0.788345
-ret: 0 st: 0 flags:1 dts: 0.788345 pts: 0.788345 pos: 139108 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.788345 pts: 0.788345 pos: 139110 size: 4096
ret: 0 st: 0 flags:1 ts:-0.317506
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096
ret: 0 st:-1 flags:0 ts: 2.576668
-ret: 0 st: 0 flags:1 dts: 2.576667 pts: 2.576667 pos: 454568 size: 4096
+ret: 0 st: 0 flags:1 dts: 2.576667 pts: 2.576667 pos: 454570 size: 4096
ret: 0 st:-1 flags:1 ts: 1.470835
-ret: 0 st: 0 flags:1 dts: 1.470839 pts: 1.470839 pos: 259500 size: 4096
+ret: 0 st: 0 flags:1 dts: 1.470839 pts: 1.470839 pos: 259502 size: 4096
ret: 0 st: 0 flags:0 ts: 0.365011
-ret: 0 st: 0 flags:1 dts: 0.365011 pts: 0.365011 pos: 64432 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.365011 pts: 0.365011 pos: 64434 size: 4096
ret: 0 st: 0 flags:1 ts:-0.740839
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096
ret: 0 st:-1 flags:0 ts: 2.153336
-ret: 0 st: 0 flags:1 dts: 2.153333 pts: 2.153333 pos: 379892 size: 4096
+ret: 0 st: 0 flags:1 dts: 2.153333 pts: 2.153333 pos: 379894 size: 4096
ret: 0 st:-1 flags:1 ts: 1.047503
-ret: 0 st: 0 flags:1 dts: 1.047506 pts: 1.047506 pos: 184824 size: 4096
+ret: 0 st: 0 flags:1 dts: 1.047506 pts: 1.047506 pos: 184826 size: 4096
ret: 0 st: 0 flags:0 ts:-0.058322
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096
ret: 0 st: 0 flags:1 ts: 2.835828
-ret: 0 st: 0 flags:1 dts: 2.835828 pts: 2.835828 pos: 500284 size: 4096
+ret: 0 st: 0 flags:1 dts: 2.835828 pts: 2.835828 pos: 500286 size: 4096
ret: 0 st:-1 flags:0 ts: 1.730004
-ret: 0 st: 0 flags:1 dts: 1.730000 pts: 1.730000 pos: 305216 size: 4096
+ret: 0 st: 0 flags:1 dts: 1.730000 pts: 1.730000 pos: 305218 size: 4096
ret: 0 st:-1 flags:1 ts: 0.624171
-ret: 0 st: 0 flags:1 dts: 0.624172 pts: 0.624172 pos: 110148 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.624172 pts: 0.624172 pos: 110150 size: 4096
ret: 0 st: 0 flags:0 ts:-0.481655
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096
ret: 0 st: 0 flags:1 ts: 2.412494
-ret: 0 st: 0 flags:1 dts: 2.412494 pts: 2.412494 pos: 425608 size: 4096
+ret: 0 st: 0 flags:1 dts: 2.412494 pts: 2.412494 pos: 425610 size: 4096
ret: 0 st:-1 flags:0 ts: 1.306672
-ret: 0 st: 0 flags:1 dts: 1.306667 pts: 1.306667 pos: 230540 size: 4096
+ret: 0 st: 0 flags:1 dts: 1.306667 pts: 1.306667 pos: 230542 size: 4096
ret: 0 st:-1 flags:1 ts: 0.200839
-ret: 0 st: 0 flags:1 dts: 0.200839 pts: 0.200839 pos: 35472 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.200839 pts: 0.200839 pos: 35474 size: 4096
ret: 0 st: 0 flags:0 ts:-0.904989
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096
ret: 0 st: 0 flags:1 ts: 1.989184
-ret: 0 st: 0 flags:1 dts: 1.989184 pts: 1.989184 pos: 350936 size: 4096
+ret: 0 st: 0 flags:1 dts: 1.989184 pts: 1.989184 pos: 350938 size: 4096
ret: 0 st:-1 flags:0 ts: 0.883340
-ret: 0 st: 0 flags:1 dts: 0.883333 pts: 0.883333 pos: 155864 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.883333 pts: 0.883333 pos: 155866 size: 4096
ret: 0 st:-1 flags:1 ts:-0.222493
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096
ret: 0 st: 0 flags:0 ts: 2.671678
-ret: 0 st: 0 flags:1 dts: 2.671678 pts: 2.671678 pos: 471328 size: 4096
+ret: 0 st: 0 flags:1 dts: 2.671678 pts: 2.671678 pos: 471330 size: 4096
ret: 0 st: 0 flags:1 ts: 1.565850
-ret: 0 st: 0 flags:1 dts: 1.565850 pts: 1.565850 pos: 276260 size: 4096
+ret: 0 st: 0 flags:1 dts: 1.565850 pts: 1.565850 pos: 276262 size: 4096
ret: 0 st:-1 flags:0 ts: 0.460008
-ret: 0 st: 0 flags:1 dts: 0.460000 pts: 0.460000 pos: 81188 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.460000 pts: 0.460000 pos: 81190 size: 4096
ret: 0 st:-1 flags:1 ts:-0.645825
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096
diff --git a/tests/ref/seek/pcm_u8_wav b/tests/ref/seek/pcm_u8_wav
index afa33519d7..8348916432 100644
--- a/tests/ref/seek/pcm_u8_wav
+++ b/tests/ref/seek/pcm_u8_wav
@@ -1,53 +1,53 @@
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096
ret: 0 st:-1 flags:0 ts:-1.000000
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096
ret: 0 st:-1 flags:1 ts: 1.894167
-ret: 0 st: 0 flags:1 dts: 1.894172 pts: 1.894172 pos: 167110 size: 4096
+ret: 0 st: 0 flags:1 dts: 1.894172 pts: 1.894172 pos: 167112 size: 4096
ret: 0 st: 0 flags:0 ts: 0.788345
-ret: 0 st: 0 flags:1 dts: 0.788345 pts: 0.788345 pos: 69576 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.788345 pts: 0.788345 pos: 69578 size: 4096
ret: 0 st: 0 flags:1 ts:-0.317506
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096
ret: 0 st:-1 flags:0 ts: 2.576668
-ret: 0 st: 0 flags:1 dts: 2.576667 pts: 2.576667 pos: 227306 size: 4096
+ret: 0 st: 0 flags:1 dts: 2.576667 pts: 2.576667 pos: 227308 size: 4096
ret: 0 st:-1 flags:1 ts: 1.470835
-ret: 0 st: 0 flags:1 dts: 1.470839 pts: 1.470839 pos: 129772 size: 4096
+ret: 0 st: 0 flags:1 dts: 1.470839 pts: 1.470839 pos: 129774 size: 4096
ret: 0 st: 0 flags:0 ts: 0.365011
-ret: 0 st: 0 flags:1 dts: 0.365011 pts: 0.365011 pos: 32238 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.365011 pts: 0.365011 pos: 32240 size: 4096
ret: 0 st: 0 flags:1 ts:-0.740839
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096
ret: 0 st:-1 flags:0 ts: 2.153336
-ret: 0 st: 0 flags:1 dts: 2.153333 pts: 2.153333 pos: 189968 size: 4096
+ret: 0 st: 0 flags:1 dts: 2.153333 pts: 2.153333 pos: 189970 size: 4096
ret: 0 st:-1 flags:1 ts: 1.047503
-ret: 0 st: 0 flags:1 dts: 1.047506 pts: 1.047506 pos: 92434 size: 4096
+ret: 0 st: 0 flags:1 dts: 1.047506 pts: 1.047506 pos: 92436 size: 4096
ret: 0 st: 0 flags:0 ts:-0.058322
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096
ret: 0 st: 0 flags:1 ts: 2.835828
-ret: 0 st: 0 flags:1 dts: 2.835828 pts: 2.835828 pos: 250164 size: 4096
+ret: 0 st: 0 flags:1 dts: 2.835828 pts: 2.835828 pos: 250166 size: 4096
ret: 0 st:-1 flags:0 ts: 1.730004
-ret: 0 st: 0 flags:1 dts: 1.730000 pts: 1.730000 pos: 152630 size: 4096
+ret: 0 st: 0 flags:1 dts: 1.730000 pts: 1.730000 pos: 152632 size: 4096
ret: 0 st:-1 flags:1 ts: 0.624171
-ret: 0 st: 0 flags:1 dts: 0.624172 pts: 0.624172 pos: 55096 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.624172 pts: 0.624172 pos: 55098 size: 4096
ret: 0 st: 0 flags:0 ts:-0.481655
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096
ret: 0 st: 0 flags:1 ts: 2.412494
-ret: 0 st: 0 flags:1 dts: 2.412494 pts: 2.412494 pos: 212826 size: 4096
+ret: 0 st: 0 flags:1 dts: 2.412494 pts: 2.412494 pos: 212828 size: 4096
ret: 0 st:-1 flags:0 ts: 1.306672
-ret: 0 st: 0 flags:1 dts: 1.306667 pts: 1.306667 pos: 115292 size: 4096
+ret: 0 st: 0 flags:1 dts: 1.306667 pts: 1.306667 pos: 115294 size: 4096
ret: 0 st:-1 flags:1 ts: 0.200839
-ret: 0 st: 0 flags:1 dts: 0.200839 pts: 0.200839 pos: 17758 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.200839 pts: 0.200839 pos: 17760 size: 4096
ret: 0 st: 0 flags:0 ts:-0.904989
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096
ret: 0 st: 0 flags:1 ts: 1.989184
-ret: 0 st: 0 flags:1 dts: 1.989184 pts: 1.989184 pos: 175490 size: 4096
+ret: 0 st: 0 flags:1 dts: 1.989184 pts: 1.989184 pos: 175492 size: 4096
ret: 0 st:-1 flags:0 ts: 0.883340
-ret: 0 st: 0 flags:1 dts: 0.883333 pts: 0.883333 pos: 77954 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.883333 pts: 0.883333 pos: 77956 size: 4096
ret: 0 st:-1 flags:1 ts:-0.222493
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096
ret: 0 st: 0 flags:0 ts: 2.671678
-ret: 0 st: 0 flags:1 dts: 2.671678 pts: 2.671678 pos: 235686 size: 4096
+ret: 0 st: 0 flags:1 dts: 2.671678 pts: 2.671678 pos: 235688 size: 4096
ret: 0 st: 0 flags:1 ts: 1.565850
-ret: 0 st: 0 flags:1 dts: 1.565850 pts: 1.565850 pos: 138152 size: 4096
+ret: 0 st: 0 flags:1 dts: 1.565850 pts: 1.565850 pos: 138154 size: 4096
ret: 0 st:-1 flags:0 ts: 0.460008
-ret: 0 st: 0 flags:1 dts: 0.460000 pts: 0.460000 pos: 40616 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.460000 pts: 0.460000 pos: 40618 size: 4096
ret: 0 st:-1 flags:1 ts:-0.645825
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096
diff --git a/tests/ref/seek/pcm_zork_wav b/tests/ref/seek/pcm_zork_wav
index 06f50e765e..22d95bf27f 100644
--- a/tests/ref/seek/pcm_zork_wav
+++ b/tests/ref/seek/pcm_zork_wav
@@ -1,53 +1,53 @@
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096
ret: 0 st:-1 flags:0 ts:-1.000000
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096
ret: 0 st:-1 flags:1 ts: 1.894167
-ret: 0 st: 0 flags:1 dts: 1.894127 pts: 1.894127 pos: 30362 size: 4096
+ret: 0 st: 0 flags:1 dts: 1.894127 pts: 1.894127 pos: 30364 size: 4096
ret: 0 st: 0 flags:0 ts: 0.788345
-ret: 0 st: 0 flags:1 dts: 0.788367 pts: 0.788367 pos: 12670 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.788367 pts: 0.788367 pos: 12672 size: 4096
ret: 0 st: 0 flags:1 ts:-0.317506
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096
ret: 0 st:-1 flags:0 ts: 2.576668
-ret: 0 st: 0 flags:1 dts: 2.576757 pts: 2.576757 pos: 41284 size: 4096
+ret: 0 st: 0 flags:1 dts: 2.576757 pts: 2.576757 pos: 41286 size: 4096
ret: 0 st:-1 flags:1 ts: 1.470835
-ret: 0 st: 0 flags:1 dts: 1.470748 pts: 1.470748 pos: 23588 size: 4096
+ret: 0 st: 0 flags:1 dts: 1.470748 pts: 1.470748 pos: 23590 size: 4096
ret: 0 st: 0 flags:0 ts: 0.365011
-ret: 0 st: 0 flags:1 dts: 0.365125 pts: 0.365125 pos: 5898 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.365125 pts: 0.365125 pos: 5900 size: 4096
ret: 0 st: 0 flags:1 ts:-0.740839
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096
ret: 0 st:-1 flags:0 ts: 2.153336
-ret: 0 st: 0 flags:1 dts: 2.153379 pts: 2.153379 pos: 34510 size: 4096
+ret: 0 st: 0 flags:1 dts: 2.153379 pts: 2.153379 pos: 34512 size: 4096
ret: 0 st:-1 flags:1 ts: 1.047503
-ret: 0 st: 0 flags:1 dts: 1.047506 pts: 1.047506 pos: 16816 size: 4096
+ret: 0 st: 0 flags:1 dts: 1.047506 pts: 1.047506 pos: 16818 size: 4096
ret: 0 st: 0 flags:0 ts:-0.058322
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096
ret: 0 st: 0 flags:1 ts: 2.835828
-ret: 0 st: 0 flags:1 dts: 2.835760 pts: 2.835760 pos: 45428 size: 4096
+ret: 0 st: 0 flags:1 dts: 2.835760 pts: 2.835760 pos: 45430 size: 4096
ret: 0 st:-1 flags:0 ts: 1.730004
-ret: 0 st: 0 flags:1 dts: 1.730000 pts: 1.730000 pos: 27736 size: 4096
+ret: 0 st: 0 flags:1 dts: 1.730000 pts: 1.730000 pos: 27738 size: 4096
ret: 0 st:-1 flags:1 ts: 0.624171
-ret: 0 st: 0 flags:1 dts: 0.624127 pts: 0.624127 pos: 10042 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.624127 pts: 0.624127 pos: 10044 size: 4096
ret: 0 st: 0 flags:0 ts:-0.481655
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096
ret: 0 st: 0 flags:1 ts: 2.412494
-ret: 0 st: 0 flags:1 dts: 2.412381 pts: 2.412381 pos: 38654 size: 4096
+ret: 0 st: 0 flags:1 dts: 2.412381 pts: 2.412381 pos: 38656 size: 4096
ret: 0 st:-1 flags:0 ts: 1.306672
-ret: 0 st: 0 flags:1 dts: 1.306757 pts: 1.306757 pos: 20964 size: 4096
+ret: 0 st: 0 flags:1 dts: 1.306757 pts: 1.306757 pos: 20966 size: 4096
ret: 0 st:-1 flags:1 ts: 0.200839
-ret: 0 st: 0 flags:1 dts: 0.200748 pts: 0.200748 pos: 3268 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.200748 pts: 0.200748 pos: 3270 size: 4096
ret: 0 st: 0 flags:0 ts:-0.904989
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096
ret: 0 st: 0 flags:1 ts: 1.989184
-ret: 0 st: 0 flags:1 dts: 1.989116 pts: 1.989116 pos: 31882 size: 4096
+ret: 0 st: 0 flags:1 dts: 1.989116 pts: 1.989116 pos: 31884 size: 4096
ret: 0 st:-1 flags:0 ts: 0.883340
-ret: 0 st: 0 flags:1 dts: 0.883379 pts: 0.883379 pos: 14190 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.883379 pts: 0.883379 pos: 14192 size: 4096
ret: 0 st:-1 flags:1 ts:-0.222493
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096
ret: 0 st: 0 flags:0 ts: 2.671678
-ret: 0 st: 0 flags:1 dts: 2.671746 pts: 2.671746 pos: 42804 size: 4096
+ret: 0 st: 0 flags:1 dts: 2.671746 pts: 2.671746 pos: 42806 size: 4096
ret: 0 st: 0 flags:1 ts: 1.565850
-ret: 0 st: 0 flags:1 dts: 1.565760 pts: 1.565760 pos: 25108 size: 4096
+ret: 0 st: 0 flags:1 dts: 1.565760 pts: 1.565760 pos: 25110 size: 4096
ret: 0 st:-1 flags:0 ts: 0.460008
-ret: 0 st: 0 flags:1 dts: 0.460000 pts: 0.460000 pos: 7416 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.460000 pts: 0.460000 pos: 7418 size: 4096
ret: 0 st:-1 flags:1 ts:-0.645825
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096
diff --git a/tests/ref/seek/wmav1_asf b/tests/ref/seek/wmav1_asf
index 47c5b46621..3456e82759 100644
--- a/tests/ref/seek/wmav1_asf
+++ b/tests/ref/seek/wmav1_asf
@@ -1,6 +1,6 @@
ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 404 size: 743
ret: 0 st:-1 flags:0 ts:-1.000000
-ret: 0 st: 0 flags:1 dts: 0.186000 pts: 0.186000 pos: 3604 size: 743
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 404 size: 743
ret: 0 st:-1 flags:1 ts: 1.894167
ret: 0 st: 0 flags:1 dts: 1.858000 pts: 1.858000 pos: 32404 size: 743
ret: 0 st: 0 flags:0 ts: 0.788000
diff --git a/tests/ref/seek/wmav2_asf b/tests/ref/seek/wmav2_asf
index 7c58da2320..31e7f3e7d3 100644
--- a/tests/ref/seek/wmav2_asf
+++ b/tests/ref/seek/wmav2_asf
@@ -1,6 +1,6 @@
ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 444 size: 743
ret: 0 st:-1 flags:0 ts:-1.000000
-ret: 0 st: 0 flags:1 dts: 0.186000 pts: 0.186000 pos: 3644 size: 743
+ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 444 size: 743
ret: 0 st:-1 flags:1 ts: 1.894167
ret: 0 st: 0 flags:1 dts: 1.858000 pts: 1.858000 pos: 32444 size: 743
ret: 0 st: 0 flags:0 ts: 0.788000
diff --git a/tests/ref/vsynth1/amv/vsynth1-amv b/tests/ref/vsynth1/amv/vsynth1-amv
new file mode 100644
index 0000000000..50d14a4430
--- /dev/null
+++ b/tests/ref/vsynth1/amv/vsynth1-amv
@@ -0,0 +1,4 @@
+539c26ba470de4d72279855fcf61f5a2 *./tests/data/vsynth1/amv.avi
+1365534 ./tests/data/vsynth1/amv.avi
+27bbe70dd002ec67af0bb219fbae626a *./tests/data/amv.vsynth1.out.yuv
+stddev: 12.46 PSNR: 26.21 MAXDIFF: 97 bytes: 7603200/ 7603200
diff --git a/tests/ref/vsynth1/dnxhd_720p_10bit b/tests/ref/vsynth1/dnxhd_720p_10bit
new file mode 100644
index 0000000000..ad97b66b7d
--- /dev/null
+++ b/tests/ref/vsynth1/dnxhd_720p_10bit
@@ -0,0 +1,4 @@
+b5e24a055af02edec8674333260214fd *./tests/data/vsynth1/dnxhd-720p-10bit.dnxhd
+ 2293760 ./tests/data/vsynth1/dnxhd-720p-10bit.dnxhd
+4466ff3d73d01bbe75ea25001d379b63 *./tests/data/dnxhd_720p_10bit.vsynth1.out.yuv
+stddev: 6.27 PSNR: 32.18 MAXDIFF: 64 bytes: 760320/ 7603200
diff --git a/tests/ref/vsynth1/dv b/tests/ref/vsynth1/dv
index cb0427c558..5b55c4f357 100644
--- a/tests/ref/vsynth1/dv
+++ b/tests/ref/vsynth1/dv
@@ -1,8 +1,8 @@
-27ade3031b17214cf81c19cbf70f37d7 *./tests/data/vsynth1/dv.dv
+4d572f758b55a1756adf9f54132f3b9e *./tests/data/vsynth1/dv.dv
7200000 ./tests/data/vsynth1/dv.dv
02ac7cdeab91d4d5621e7ce96dddc498 *./tests/data/dv.vsynth1.out.yuv
stddev: 6.90 PSNR: 31.34 MAXDIFF: 76 bytes: 7603200/ 7603200
-bd67f2431db160d4bb6dcd791cea6efd *./tests/data/vsynth1/dv411.dv
+f179899efba432c6f01149c36c709092 *./tests/data/vsynth1/dv411.dv
7200000 ./tests/data/vsynth1/dv411.dv
b6640a3a572353f51284acb746eb00c4 *./tests/data/dv.vsynth1.out.yuv
stddev: 30.76 PSNR: 18.37 MAXDIFF: 205 bytes: 7603200/ 7603200
diff --git a/tests/ref/vsynth1/dv50 b/tests/ref/vsynth1/dv50
index 9ae338527d..461392e288 100644
--- a/tests/ref/vsynth1/dv50
+++ b/tests/ref/vsynth1/dv50
@@ -1,4 +1,4 @@
-26dba84f0ea895b914ef5b333d8394ac *./tests/data/vsynth1/dv50.dv
+a193c5f92bf6e74c604e759d5f4f0f94 *./tests/data/vsynth1/dv50.dv
14400000 ./tests/data/vsynth1/dv50.dv
a2ff093e93ffed10f730fa21df02fc50 *./tests/data/dv50.vsynth1.out.yuv
stddev: 1.72 PSNR: 43.38 MAXDIFF: 29 bytes: 7603200/ 7603200
diff --git a/tests/ref/vsynth1/error b/tests/ref/vsynth1/error
index bc24d5b2af..4d1e9e5b0c 100644
--- a/tests/ref/vsynth1/error
+++ b/tests/ref/vsynth1/error
@@ -1,4 +1,4 @@
7416dfd319f04044d4575dc9d1b406e1 *./tests/data/vsynth1/error-mpeg4-adv.avi
- 756836 ./tests/data/vsynth1/error-mpeg4-adv.avi
+756836 ./tests/data/vsynth1/error-mpeg4-adv.avi
79e94ba32b37759397362cbcb479d4d3 *./tests/data/error.vsynth1.out.yuv
stddev: 18.36 PSNR: 22.85 MAXDIFF: 243 bytes: 7603200/ 7603200
diff --git a/tests/ref/vsynth1/flashsv b/tests/ref/vsynth1/flashsv
index 7920193aa7..77fefe0bc0 100644
--- a/tests/ref/vsynth1/flashsv
+++ b/tests/ref/vsynth1/flashsv
@@ -1,4 +1,4 @@
97894502b4cb57aca1105b6333f72dae *./tests/data/vsynth1/flashsv.flv
14681925 ./tests/data/vsynth1/flashsv.flv
-947cb24ec45a453348ae6fe3fa278071 *./tests/data/flashsv.vsynth1.out.yuv
-stddev: 2.85 PSNR: 39.03 MAXDIFF: 49 bytes: 7603200/ 7603200
+791e1fb999deb2e4156e2286d48c4ed1 *./tests/data/flashsv.vsynth1.out.yuv
+stddev: 2.84 PSNR: 39.04 MAXDIFF: 49 bytes: 7603200/ 7603200
diff --git a/tests/ref/vsynth1/flashsv2 b/tests/ref/vsynth1/flashsv2
new file mode 100644
index 0000000000..6c43bda56e
--- /dev/null
+++ b/tests/ref/vsynth1/flashsv2
@@ -0,0 +1,6 @@
+ec13d68cbce263f589fe79bcd2e98364 *./tests/data/vsynth1/flashsv2.flv
+8406137 ./tests/data/vsynth1/flashsv2.flv
+ed28c0021768629b2675e72bf1632426 *./tests/data/vsynth1/flashsv2I.flv
+8755723 ./tests/data/vsynth1/flashsv2I.flv
+efa88d09115a2e947eff00ee435ba3f3 *./tests/data/flashsv2.vsynth1.out.yuv
+stddev: 3.47 PSNR: 37.31 MAXDIFF: 49 bytes: 7603200/ 7603200
diff --git a/tests/ref/vsynth1/jpeg2000 b/tests/ref/vsynth1/jpeg2000
new file mode 100644
index 0000000000..fa60ac2be6
--- /dev/null
+++ b/tests/ref/vsynth1/jpeg2000
@@ -0,0 +1,4 @@
+8da8ef50cccb9996f4bebbc585c4edb4 *./tests/data/vsynth1/jpeg2000.avi
+2306914 ./tests/data/vsynth1/jpeg2000.avi
+ee9b245b3b07eed90bc6f2147bbd916c *./tests/data/jpeg2000.vsynth1.out.yuv
+stddev: 5.47 PSNR: 33.37 MAXDIFF: 64 bytes: 7603200/ 7603200
diff --git a/tests/ref/vsynth1/jpegls b/tests/ref/vsynth1/jpegls
index 636f7fc556..153f9b9c0f 100644
--- a/tests/ref/vsynth1/jpegls
+++ b/tests/ref/vsynth1/jpegls
@@ -1,4 +1,4 @@
519e26bb1ac0f3db8f90b36537f2f760 *./tests/data/vsynth1/jpegls.avi
9089812 ./tests/data/vsynth1/jpegls.avi
-947cb24ec45a453348ae6fe3fa278071 *./tests/data/jpegls.vsynth1.out.yuv
-stddev: 2.85 PSNR: 39.03 MAXDIFF: 49 bytes: 7603200/ 7603200
+791e1fb999deb2e4156e2286d48c4ed1 *./tests/data/jpegls.vsynth1.out.yuv
+stddev: 2.84 PSNR: 39.04 MAXDIFF: 49 bytes: 7603200/ 7603200
diff --git a/tests/ref/vsynth1/mpeg4 b/tests/ref/vsynth1/mpeg4
index ebe2f5a613..93c13bc662 100644
--- a/tests/ref/vsynth1/mpeg4
+++ b/tests/ref/vsynth1/mpeg4
@@ -1,4 +1,4 @@
-080e75117f8142001b096cd977ba287e *./tests/data/vsynth1/odivx.mp4
+d2405fd9e350854a161f48bc63f49253 *./tests/data/vsynth1/odivx.mp4
540156 ./tests/data/vsynth1/odivx.mp4
8828a375448dc5c2215163ba70656f89 *./tests/data/mpeg4.vsynth1.out.yuv
stddev: 7.97 PSNR: 30.10 MAXDIFF: 105 bytes: 7603200/ 7603200
diff --git a/tests/ref/vsynth1/msvideo1 b/tests/ref/vsynth1/msvideo1
new file mode 100644
index 0000000000..7978258c99
--- /dev/null
+++ b/tests/ref/vsynth1/msvideo1
@@ -0,0 +1,4 @@
+267a152a73cbc5ac4694a6e3b254be34 *./tests/data/vsynth1/msvideo1.avi
+2162264 ./tests/data/vsynth1/msvideo1.avi
+c0665fac1bd896b6fe7fe0eead805bd5 *./tests/data/msvideo1.vsynth1.out.yuv
+stddev: 11.80 PSNR: 26.69 MAXDIFF: 151 bytes: 7603200/ 7603200
diff --git a/tests/ref/vsynth1/qtrle b/tests/ref/vsynth1/qtrle
index 9988897b91..d25b986184 100644
--- a/tests/ref/vsynth1/qtrle
+++ b/tests/ref/vsynth1/qtrle
@@ -1,4 +1,4 @@
d14041925ce5ec5001dc519276b1a1ab *./tests/data/vsynth1/qtrle.mov
15263232 ./tests/data/vsynth1/qtrle.mov
-243325fb2cae1a9245efd49aff936327 *./tests/data/qtrle.vsynth1.out.yuv
-stddev: 3.42 PSNR: 37.43 MAXDIFF: 48 bytes: 7603200/ 7603200
+93695a27c24a61105076ca7b1f010bbd *./tests/data/qtrle.vsynth1.out.yuv
+stddev: 3.42 PSNR: 37.44 MAXDIFF: 48 bytes: 7603200/ 7603200
diff --git a/tests/ref/vsynth1/qtrlegray b/tests/ref/vsynth1/qtrlegray
new file mode 100644
index 0000000000..686611394e
--- /dev/null
+++ b/tests/ref/vsynth1/qtrlegray
@@ -0,0 +1,4 @@
+0544350c00f33f21e29b5edd965c3f03 *./tests/data/vsynth1/qtrlegray.mov
+5113428 ./tests/data/vsynth1/qtrlegray.mov
+29def4aed035ed65d3a89f7d382fccbe *./tests/data/qtrlegray.vsynth1.out.yuv
+stddev: 25.95 PSNR: 19.85 MAXDIFF: 122 bytes: 7603200/ 7603200
diff --git a/tests/ref/vsynth1/rgb b/tests/ref/vsynth1/rgb
index 10a0a13329..1c353dae7f 100644
--- a/tests/ref/vsynth1/rgb
+++ b/tests/ref/vsynth1/rgb
@@ -1,4 +1,4 @@
05f0719cb52486d9a4beb9cfae3f2571 *./tests/data/vsynth1/rgb.avi
15213260 ./tests/data/vsynth1/rgb.avi
-243325fb2cae1a9245efd49aff936327 *./tests/data/rgb.vsynth1.out.yuv
-stddev: 3.42 PSNR: 37.43 MAXDIFF: 48 bytes: 7603200/ 7603200
+93695a27c24a61105076ca7b1f010bbd *./tests/data/rgb.vsynth1.out.yuv
+stddev: 3.42 PSNR: 37.44 MAXDIFF: 48 bytes: 7603200/ 7603200
diff --git a/tests/ref/vsynth2/amv/vsynth2-amv b/tests/ref/vsynth2/amv/vsynth2-amv
new file mode 100644
index 0000000000..94010a2f8b
--- /dev/null
+++ b/tests/ref/vsynth2/amv/vsynth2-amv
@@ -0,0 +1,4 @@
+816a4226fe7640a835139f8a44286a12 *./tests/data/vsynth2/amv.avi
+761976 ./tests/data/vsynth2/amv.avi
+f1a9e46e77934d4cc5ca9f927662c4be *./tests/data/amv.vsynth2.out.yuv
+stddev: 8.14 PSNR: 29.91 MAXDIFF: 66 bytes: 7603200/ 7603200
diff --git a/tests/ref/vsynth2/dnxhd_720p_10bit b/tests/ref/vsynth2/dnxhd_720p_10bit
new file mode 100644
index 0000000000..60c0d84a34
--- /dev/null
+++ b/tests/ref/vsynth2/dnxhd_720p_10bit
@@ -0,0 +1,4 @@
+4b57da2c0c1280469ff3579f7151c227 *./tests/data/vsynth2/dnxhd-720p-10bit.dnxhd
+ 2293760 ./tests/data/vsynth2/dnxhd-720p-10bit.dnxhd
+31a6aa8b8702e85fa3b48e73f035c4e4 *./tests/data/dnxhd_720p_10bit.vsynth2.out.yuv
+stddev: 1.35 PSNR: 45.46 MAXDIFF: 23 bytes: 760320/ 7603200
diff --git a/tests/ref/vsynth2/dv b/tests/ref/vsynth2/dv
index 676b209c58..b05dc4fffe 100644
--- a/tests/ref/vsynth2/dv
+++ b/tests/ref/vsynth2/dv
@@ -1,8 +1,8 @@
-bfa766f89bfeabc0ae1044f3954bed52 *./tests/data/vsynth2/dv.dv
+85b8d55b0b68bb3fc2e90babb580f9b7 *./tests/data/vsynth2/dv.dv
7200000 ./tests/data/vsynth2/dv.dv
7ec62bd3350a6848364669e6e1e4b9cc *./tests/data/dv.vsynth2.out.yuv
stddev: 1.71 PSNR: 43.47 MAXDIFF: 33 bytes: 7603200/ 7603200
-00a9d8683ac6826af41bcf7223fb0389 *./tests/data/vsynth2/dv411.dv
+e428508f400327aeb96969c08fb9e1b5 *./tests/data/vsynth2/dv411.dv
7200000 ./tests/data/vsynth2/dv411.dv
7f9fa421028aabb11eaf4c6513a5a843 *./tests/data/dv.vsynth2.out.yuv
stddev: 10.09 PSNR: 28.05 MAXDIFF: 60 bytes: 7603200/ 7603200
diff --git a/tests/ref/vsynth2/dv50 b/tests/ref/vsynth2/dv50
index 7e0083bfc1..cc468b8cd4 100644
--- a/tests/ref/vsynth2/dv50
+++ b/tests/ref/vsynth2/dv50
@@ -1,4 +1,4 @@
-61e31c79e8949b25c849753a0785b0d7 *./tests/data/vsynth2/dv50.dv
+0032a07167199e6f49e07fa7ed4d5f62 *./tests/data/vsynth2/dv50.dv
14400000 ./tests/data/vsynth2/dv50.dv
af3f2dd5ab62c1a1d98b07d4aeb6852f *./tests/data/dv50.vsynth2.out.yuv
stddev: 0.82 PSNR: 49.82 MAXDIFF: 12 bytes: 7603200/ 7603200
diff --git a/tests/ref/vsynth2/error b/tests/ref/vsynth2/error
index 424c54962b..a6bfcd4fe2 100644
--- a/tests/ref/vsynth2/error
+++ b/tests/ref/vsynth2/error
@@ -1,4 +1,4 @@
90e65096aa9ebafa3fe3f44a5a47cdc4 *./tests/data/vsynth2/error-mpeg4-adv.avi
- 176588 ./tests/data/vsynth2/error-mpeg4-adv.avi
+176588 ./tests/data/vsynth2/error-mpeg4-adv.avi
96baa9e4c24c837a3ba5abd8dd2cdd30 *./tests/data/error.vsynth2.out.yuv
stddev: 8.98 PSNR: 29.06 MAXDIFF: 184 bytes: 7603200/ 7603200
diff --git a/tests/ref/vsynth2/flashsv b/tests/ref/vsynth2/flashsv
index bfbb9e1c08..0b7b7d925e 100644
--- a/tests/ref/vsynth2/flashsv
+++ b/tests/ref/vsynth2/flashsv
@@ -1,4 +1,4 @@
0667077971e0cb63b5f49c580006e90e *./tests/data/vsynth2/flashsv.flv
12368953 ./tests/data/vsynth2/flashsv.flv
-592b3321994e26a990deb3a0a1415de9 *./tests/data/flashsv.vsynth2.out.yuv
-stddev: 0.65 PSNR: 51.84 MAXDIFF: 14 bytes: 7603200/ 7603200
+3a984506f1ebfc9fb73b6814cab201cc *./tests/data/flashsv.vsynth2.out.yuv
+stddev: 0.66 PSNR: 51.73 MAXDIFF: 14 bytes: 7603200/ 7603200
diff --git a/tests/ref/vsynth2/flashsv2 b/tests/ref/vsynth2/flashsv2
new file mode 100644
index 0000000000..b40988a329
--- /dev/null
+++ b/tests/ref/vsynth2/flashsv2
@@ -0,0 +1,6 @@
+6fbb1cf84d473a93035047c3a3e344ff *./tests/data/vsynth2/flashsv2.flv
+4814443 ./tests/data/vsynth2/flashsv2.flv
+d5a22183d9fe670174340a8a1847e52a *./tests/data/vsynth2/flashsv2I.flv
+5037122 ./tests/data/vsynth2/flashsv2I.flv
+8f63e24049ba1789a7f8353c695a3d99 *./tests/data/flashsv2.vsynth2.out.yuv
+stddev: 2.39 PSNR: 40.55 MAXDIFF: 21 bytes: 7603200/ 7603200
diff --git a/tests/ref/vsynth2/jpeg2000 b/tests/ref/vsynth2/jpeg2000
new file mode 100644
index 0000000000..4fc70ede5b
--- /dev/null
+++ b/tests/ref/vsynth2/jpeg2000
@@ -0,0 +1,4 @@
+b30dc1851c0fb37726d977ec1d5ad527 *./tests/data/vsynth2/jpeg2000.avi
+1151156 ./tests/data/vsynth2/jpeg2000.avi
+ec5218eec33a021945c28c72093382a5 *./tests/data/jpeg2000.vsynth2.out.yuv
+stddev: 4.54 PSNR: 34.99 MAXDIFF: 61 bytes: 7603200/ 7603200
diff --git a/tests/ref/vsynth2/jpegls b/tests/ref/vsynth2/jpegls
index e7fa2df46c..229937ec80 100644
--- a/tests/ref/vsynth2/jpegls
+++ b/tests/ref/vsynth2/jpegls
@@ -1,4 +1,4 @@
4fc53937f048c900ae6d50fda9dba206 *./tests/data/vsynth2/jpegls.avi
8334630 ./tests/data/vsynth2/jpegls.avi
-592b3321994e26a990deb3a0a1415de9 *./tests/data/jpegls.vsynth2.out.yuv
-stddev: 0.65 PSNR: 51.84 MAXDIFF: 14 bytes: 7603200/ 7603200
+3a984506f1ebfc9fb73b6814cab201cc *./tests/data/jpegls.vsynth2.out.yuv
+stddev: 0.66 PSNR: 51.73 MAXDIFF: 14 bytes: 7603200/ 7603200
diff --git a/tests/ref/vsynth2/mpeg4 b/tests/ref/vsynth2/mpeg4
index fe436e88f3..d534ec1ed1 100644
--- a/tests/ref/vsynth2/mpeg4
+++ b/tests/ref/vsynth2/mpeg4
@@ -1,4 +1,4 @@
-8ffbe8ce43fe126b12cf9621717d641b *./tests/data/vsynth2/odivx.mp4
+2e3bf184668d4807ae6df0bdceba487b *./tests/data/vsynth2/odivx.mp4
119809 ./tests/data/vsynth2/odivx.mp4
90a3577850239083a9042bef33c50e85 *./tests/data/mpeg4.vsynth2.out.yuv
stddev: 5.34 PSNR: 33.57 MAXDIFF: 83 bytes: 7603200/ 7603200
diff --git a/tests/ref/vsynth2/msvideo1 b/tests/ref/vsynth2/msvideo1
new file mode 100644
index 0000000000..f71be35278
--- /dev/null
+++ b/tests/ref/vsynth2/msvideo1
@@ -0,0 +1,4 @@
+5dddbbd6616d9be4bc0fd0c9650bd9e3 *./tests/data/vsynth2/msvideo1.avi
+1259308 ./tests/data/vsynth2/msvideo1.avi
+cd83ffcbc73573044e3aead3094229e5 *./tests/data/msvideo1.vsynth2.out.yuv
+stddev: 7.42 PSNR: 30.72 MAXDIFF: 123 bytes: 7603200/ 7603200
diff --git a/tests/ref/vsynth2/qtrle b/tests/ref/vsynth2/qtrle
index 6b2a01168e..d87a6b96ac 100644
--- a/tests/ref/vsynth2/qtrle
+++ b/tests/ref/vsynth2/qtrle
@@ -1,4 +1,4 @@
d8c1604dc46d9aa4ec0385e6722c6989 *./tests/data/vsynth2/qtrle.mov
14798419 ./tests/data/vsynth2/qtrle.mov
-b2418e0e3a9a8619b31219cbcf24dc82 *./tests/data/qtrle.vsynth2.out.yuv
-stddev: 1.26 PSNR: 46.06 MAXDIFF: 13 bytes: 7603200/ 7603200
+98d0e2854731472c5bf13d8638502d0a *./tests/data/qtrle.vsynth2.out.yuv
+stddev: 1.26 PSNR: 46.10 MAXDIFF: 13 bytes: 7603200/ 7603200
diff --git a/tests/ref/vsynth2/qtrlegray b/tests/ref/vsynth2/qtrlegray
new file mode 100644
index 0000000000..8c7b98a4bd
--- /dev/null
+++ b/tests/ref/vsynth2/qtrlegray
@@ -0,0 +1,4 @@
+55c6e5af44ece0621d1d4c91b282a544 *./tests/data/vsynth2/qtrlegray.mov
+5111417 ./tests/data/vsynth2/qtrlegray.mov
+f63b5ebdfdba750e547c25131b0a3fd1 *./tests/data/qtrlegray.vsynth2.out.yuv
+stddev: 19.42 PSNR: 22.36 MAXDIFF: 72 bytes: 7603200/ 7603200
diff --git a/tests/ref/vsynth2/rgb b/tests/ref/vsynth2/rgb
index ea83470814..bcdef36b72 100644
--- a/tests/ref/vsynth2/rgb
+++ b/tests/ref/vsynth2/rgb
@@ -1,4 +1,4 @@
f2e9c419023c743bf99aa5b2e55ad233 *./tests/data/vsynth2/rgb.avi
15213260 ./tests/data/vsynth2/rgb.avi
-b2418e0e3a9a8619b31219cbcf24dc82 *./tests/data/rgb.vsynth2.out.yuv
-stddev: 1.26 PSNR: 46.06 MAXDIFF: 13 bytes: 7603200/ 7603200
+98d0e2854731472c5bf13d8638502d0a *./tests/data/rgb.vsynth2.out.yuv
+stddev: 1.26 PSNR: 46.10 MAXDIFF: 13 bytes: 7603200/ 7603200
diff --git a/tests/regression-funcs.sh b/tests/regression-funcs.sh
index 979157bcf9..b8164843a5 100755
--- a/tests/regression-funcs.sh
+++ b/tests/regression-funcs.sh
@@ -1,6 +1,6 @@
#!/bin/sh
#
-# common regression functions for ffmpeg
+# common regression functions for avconv
#
#
@@ -10,6 +10,7 @@ raw_src_dir=$3
target_exec=$4
target_path=$5
threads=${6:-1}
+tool=$8
datadir="./tests/data"
target_datadir="${target_path}/${datadir}"
@@ -18,7 +19,7 @@ this="$test.$test_ref"
outfile="$datadir/$test_ref/"
# various files
-ffmpeg="$target_exec ${target_path}/ffmpeg"
+avconv="$target_exec ${target_path}/${tool}"
tiny_psnr="tests/tiny_psnr"
raw_src="${target_path}/$raw_src_dir/%02d.pgm"
raw_dst="$datadir/$this.out.yuv"
@@ -43,23 +44,23 @@ echov(){
. $(dirname $0)/md5.sh
-FFMPEG_OPTS="-v 0 -y"
+AVCONV_OPTS="-nostats -y"
COMMON_OPTS="-flags +bitexact -idct simple -sws_flags +accurate_rnd+bitexact"
DEC_OPTS="$COMMON_OPTS -threads $threads"
ENC_OPTS="$COMMON_OPTS -threads 1 -dct fastint"
-run_ffmpeg()
+run_avconv()
{
- $echov $ffmpeg $FFMPEG_OPTS $*
- $ffmpeg $FFMPEG_OPTS $*
+ $echov $avconv $AVCONV_OPTS $*
+ $avconv $AVCONV_OPTS $*
}
-do_ffmpeg()
+do_avconv()
{
f="$1"
shift
set -- $* ${target_path}/$f
- run_ffmpeg $*
+ run_avconv $*
do_md5sum $f
if [ $f = $raw_dst ] ; then
$tiny_psnr $f $raw_ref
@@ -70,12 +71,12 @@ do_ffmpeg()
fi
}
-do_ffmpeg_nomd5()
+do_avconv_nomd5()
{
f="$1"
shift
set -- $* ${target_path}/$f
- run_ffmpeg $*
+ run_avconv $*
if [ $f = $raw_dst ] ; then
$tiny_psnr $f $raw_ref
elif [ $f = $pcm_dst ] ; then
@@ -85,32 +86,32 @@ do_ffmpeg_nomd5()
fi
}
-do_ffmpeg_crc()
+do_avconv_crc()
{
f="$1"
shift
- run_ffmpeg $* -f crc "$target_crcfile"
+ run_avconv $* -f crc "$target_crcfile"
echo "$f $(cat $crcfile)"
}
do_video_decoding()
{
- do_ffmpeg $raw_dst $DEC_OPTS $1 -i $target_path/$file -f rawvideo $ENC_OPTS -vsync 0 $2
+ do_avconv $raw_dst $DEC_OPTS $1 -i $target_path/$file -f rawvideo $ENC_OPTS -vsync 0 $2
}
do_video_encoding()
{
file=${outfile}$1
- do_ffmpeg $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $ENC_OPTS $2
+ do_avconv $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $ENC_OPTS $2
}
do_audio_encoding()
{
file=${outfile}$1
- do_ffmpeg $file $DEC_OPTS -ac 2 -ar 44100 -f s16le -i $pcm_src -ab 128k $ENC_OPTS $2
+ do_avconv $file $DEC_OPTS -ac 2 -ar 44100 -f s16le -i $pcm_src -ab 128k $ENC_OPTS $2
}
do_audio_decoding()
{
- do_ffmpeg $pcm_dst $DEC_OPTS -i $target_path/$file -sample_fmt s16 -f wav
+ do_avconv $pcm_dst $DEC_OPTS -i $target_path/$file -sample_fmt s16 -f wav
}
diff --git a/tests/rotozoom.c b/tests/rotozoom.c
index ff817acc3b..822c2bce5e 100644
--- a/tests/rotozoom.c
+++ b/tests/rotozoom.c
@@ -3,20 +3,20 @@
*
* copyright (c) Sebastien Bechet <s.bechet@av7.net>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/tests/tiny_psnr.c b/tests/tiny_psnr.c
index 2bdb4391cf..512d47bb8e 100644
--- a/tests/tiny_psnr.c
+++ b/tests/tiny_psnr.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -52,6 +52,21 @@ uint64_t exp16_table[21]={
582360139072LL,
};
+#if 0
+// 16.16 fixpoint exp()
+static unsigned int exp16(unsigned int a){
+ int i;
+ int out= 1<<16;
+
+ for(i=19;i>=0;i--){
+ if(a&(1<<i))
+ out= (out*exp16_table[i] + (1<<15))>>16;
+ }
+
+ return out;
+}
+#endif
+
// 16.16 fixpoint log()
static int64_t log16(uint64_t a){
int i;
diff --git a/tests/videogen.c b/tests/videogen.c
index f114801a8a..4238e3f862 100644
--- a/tests/videogen.c
+++ b/tests/videogen.c
@@ -4,20 +4,20 @@
*
* Copyright (c) 2002 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/tools/build_libstagefright b/tools/build_libstagefright
new file mode 100644
index 0000000000..ada8d4e239
--- /dev/null
+++ b/tools/build_libstagefright
@@ -0,0 +1,56 @@
+#!/bin/bash
+
+if [ "$NDK" = "" ]; then
+ echo NDK variable not set, assuming ${HOME}/android-ndk
+ export NDK=${HOME}/android-ndk
+fi
+
+echo "Fetching Android system headers"
+git clone --depth=1 git://github.com/CyanogenMod/android_frameworks_base.git ../android-source/frameworks/base
+git clone --depth=1 git://github.com/CyanogenMod/android_system_core.git ../android-source/system/core
+
+echo "Fetching Android libraries for linking"
+# Libraries from any froyo/gingerbread device/emulator should work
+# fine, since the symbols used should be available on most of them.
+if [ ! -f "../update-cm-7.0.3-N1-signed.zip" ]; then
+ wget http://download.cyanogenmod.com/get/update-cm-7.0.3-N1-signed.zip -P../
+ unzip update-cm-7.0.3-N1-signed.zip system/lib/* -d../
+ mv ../system/lib ../android-libs
+ rmdir ../system
+fi
+
+
+SYSROOT=$NDK/platforms/android-9/arch-arm
+# Expand the prebuilt/* path into the correct one
+TOOLCHAIN=`echo $NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/*-x86`
+export PATH=$TOOLCHAIN/bin:$PATH
+ANDROID_SOURCE=../android-source
+ANDROID_LIBS=../android-libs
+
+rm -rf ../build/stagefright
+mkdir -p ../build/stagefright
+
+DEST=../build/stagefright
+FLAGS="--target-os=linux --cross-prefix=arm-linux-androideabi- --arch=arm --cpu=armv7-a"
+FLAGS="$FLAGS --sysroot=$SYSROOT"
+FLAGS="$FLAGS --disable-avdevice --disable-decoder=h264 --disable-decoder=h264_vdpau --enable-libstagefright-h264"
+
+EXTRA_CFLAGS="-I$ANDROID_SOURCE/frameworks/base/include -I$ANDROID_SOURCE/system/core/include"
+EXTRA_CFLAGS="$EXTRA_CFLAGS -I$ANDROID_SOURCE/frameworks/base/media/libstagefright"
+EXTRA_CFLAGS="$EXTRA_CFLAGS -I$ANDROID_SOURCE/frameworks/base/include/media/stagefright/openmax"
+EXTRA_CFLAGS="$EXTRA_CFLAGS -I$NDK/sources/cxx-stl/system/include"
+
+EXTRA_CFLAGS="$EXTRA_CFLAGS -march=armv7-a -mfloat-abi=softfp -mfpu=neon"
+EXTRA_LDFLAGS="-Wl,--fix-cortex-a8 -L$ANDROID_LIBS -Wl,-rpath-link,$ANDROID_LIBS"
+EXTRA_CXXFLAGS="-Wno-multichar -fno-exceptions -fno-rtti"
+ABI="armeabi-v7a"
+DEST="$DEST/$ABI"
+FLAGS="$FLAGS --prefix=$DEST"
+
+mkdir -p $DEST
+
+echo $FLAGS --extra-cflags="$EXTRA_CFLAGS" --extra-ldflags="$EXTRA_LDFLAGS" --extra-cxxflags="$EXTRA_CXXFLAGS" > $DEST/info.txt
+./configure $FLAGS --extra-cflags="$EXTRA_CFLAGS" --extra-ldflags="$EXTRA_LDFLAGS" --extra-cxxflags="$EXTRA_CXXFLAGS" | tee $DEST/configuration.txt
+[ $PIPESTATUS == 0 ] || exit 1
+make clean
+make -j4 || exit 1
diff --git a/tools/clean-diff b/tools/clean-diff
new file mode 100755
index 0000000000..4600702b10
--- /dev/null
+++ b/tools/clean-diff
@@ -0,0 +1,11 @@
+#!/bin/sh
+sed '/^+[^+]/!s/ /TaBBaT/g' |\
+ expand -t $(seq -s , 9 8 200) |\
+ sed 's/TaBBaT/ /g' |\
+ sed '/^+[^+]/s/ * $//' |\
+ tr -d '\015' |\
+ tr '\n' '°' |\
+ sed 's/\(@@[^@]*@@°[^@]*\)/\n\1/g' |\
+ egrep -v '@@[^@]*@@°(( [^°]*°)|([+-][[:space:]]*°)|(-[[:space:]]*([^°]*)°\+[[:space:]]*\5°))*$' |\
+ tr -d '\n' |\
+ tr '°' '\n'
diff --git a/tools/graph2dot.c b/tools/graph2dot.c
index 5ec6e204f7..766afdb050 100644
--- a/tools/graph2dot.c
+++ b/tools/graph2dot.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2008-2010 Stefano Sabatini
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -75,9 +75,10 @@ static void print_digraph(FILE *outfile, AVFilterGraph *graph)
} else if (link->type == AVMEDIA_TYPE_AUDIO) {
char buf[255];
av_get_channel_layout_string(buf, sizeof(buf), -1, link->channel_layout);
- fprintf(outfile, " [ label= \"fmt:%s sr:%"PRId64" cl:%s\" ]",
+ fprintf(outfile, " [ label= \"fmt:%s sr:%"PRId64" cl:%s tb:%d/%d\" ]",
av_get_sample_fmt_name(link->format),
- link->sample_rate, buf);
+ link->sample_rate, buf,
+ link->time_base.num, link->time_base.den);
}
fprintf(outfile, ";\n");
}
diff --git a/tools/lavfi-showfiltfmts.c b/tools/lavfi-showfiltfmts.c
index 30d472559c..a4541bac82 100644
--- a/tools/lavfi-showfiltfmts.c
+++ b/tools/lavfi-showfiltfmts.c
@@ -1,34 +1,80 @@
/*
* Copyright (c) 2009 Stefano Sabatini
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavformat/avformat.h"
#include "libavutil/pixdesc.h"
+#include "libavutil/samplefmt.h"
#include "libavfilter/avfilter.h"
+static void print_formats(AVFilterContext *filter_ctx)
+{
+ int i, j;
+
+#define PRINT_FMTS(inout, outin, INOUT) \
+ for (i = 0; i < filter_ctx->input_count; i++) { \
+ if (filter_ctx->inout##puts[i]->type == AVMEDIA_TYPE_VIDEO) { \
+ AVFilterFormats *fmts = \
+ filter_ctx->inout##puts[i]->outin##_formats; \
+ for (j = 0; j < fmts->format_count; j++) \
+ printf(#INOUT "PUT[%d] %s: fmt:%s\n", \
+ i, filter_ctx->filter->inout##puts[i].name, \
+ av_get_pix_fmt_name(fmts->formats[j])); \
+ } else if (filter_ctx->inout##puts[i]->type == AVMEDIA_TYPE_AUDIO) { \
+ AVFilterFormats *fmts; \
+ \
+ fmts = filter_ctx->inout##puts[i]->outin##_formats; \
+ for (j = 0; j < fmts->format_count; j++) \
+ printf(#INOUT "PUT[%d] %s: fmt:%s\n", \
+ i, filter_ctx->filter->inout##puts[i].name, \
+ av_get_sample_fmt_name(fmts->formats[j])); \
+ \
+ fmts = filter_ctx->inout##puts[i]->outin##_chlayouts; \
+ for (j = 0; j < fmts->format_count; j++) { \
+ char buf[256]; \
+ av_get_channel_layout_string(buf, sizeof(buf), -1, \
+ fmts->formats[j]); \
+ printf(#INOUT "PUT[%d] %s: chlayout:%s\n", \
+ i, filter_ctx->filter->inout##puts[i].name, buf); \
+ } \
+ \
+ fmts = filter_ctx->inout##puts[i]->outin##_packing; \
+ for (j = 0; j < fmts->format_count; j++) { \
+ printf(#INOUT "PUT[%d] %s: packing:%s\n", \
+ i, filter_ctx->filter->inout##puts[i].name, \
+ fmts->formats[j] == AVFILTER_PACKED ? \
+ "packed" : "planar"); \
+ } \
+ } \
+ } \
+
+ PRINT_FMTS(in, out, IN);
+ PRINT_FMTS(out, in, OUT);
+}
+
int main(int argc, char **argv)
{
AVFilter *filter;
AVFilterContext *filter_ctx;
const char *filter_name;
const char *filter_args = NULL;
- int i, j;
+ int i;
av_log_set_level(AV_LOG_DEBUG);
@@ -75,23 +121,7 @@ int main(int argc, char **argv)
else
avfilter_default_query_formats(filter_ctx);
- /* print the supported formats in input */
- for (i = 0; i < filter_ctx->input_count; i++) {
- AVFilterFormats *fmts = filter_ctx->inputs[i]->out_formats;
- for (j = 0; j < fmts->format_count; j++)
- printf("INPUT[%d] %s: %s\n",
- i, filter_ctx->filter->inputs[i].name,
- av_pix_fmt_descriptors[fmts->formats[j]].name);
- }
-
- /* print the supported formats in output */
- for (i = 0; i < filter_ctx->output_count; i++) {
- AVFilterFormats *fmts = filter_ctx->outputs[i]->in_formats;
- for (j = 0; j < fmts->format_count; j++)
- printf("OUTPUT[%d] %s: %s\n",
- i, filter_ctx->filter->outputs[i].name,
- av_pix_fmt_descriptors[fmts->formats[j]].name);
- }
+ print_formats(filter_ctx);
avfilter_free(filter_ctx);
fflush(stdout);
diff --git a/tools/patcheck b/tools/patcheck
index 19faf47b1d..00c59f8f61 100755
--- a/tools/patcheck
+++ b/tools/patcheck
@@ -18,7 +18,7 @@ echo patCHeck 1e10.0
echo This tool is intended to help a human check/review patches it is very far from
echo being free of false positives and negatives, its output are just hints of what
echo may or may not be bad. When you use it and it misses something or detects
-echo something wrong, fix it and send a patch to the libav-devel mailing list.
+echo something wrong, fix it and send a patch to the ffmpeg-dev mailing list.
echo License:GPL Autor: Michael Niedermayer
ERE_PRITYP='(unsigned *|)(char|short|long|int|long *int|short *int|void|float|double|(u|)int(8|16|32|64)_t)'
diff --git a/tools/pktdumper.c b/tools/pktdumper.c
index 80816d24b9..82f417f9f1 100644
--- a/tools/pktdumper.c
+++ b/tools/pktdumper.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2005 Francois Revol
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -89,9 +89,9 @@ int main(int argc, char **argv)
return 1;
}
- err = av_find_stream_info(fctx);
+ err = avformat_find_stream_info(fctx, NULL);
if (err < 0) {
- fprintf(stderr, "av_find_stream_info: error %d\n", err);
+ fprintf(stderr, "avformat_find_stream_info: error %d\n", err);
return 1;
}
diff --git a/tools/probetest.c b/tools/probetest.c
index 7f8d54e973..b4bb5aea9e 100644
--- a/tools/probetest.c
+++ b/tools/probetest.c
@@ -1,20 +1,20 @@
/*
* copyright (c) 2009 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/tools/qt-faststart.c b/tools/qt-faststart.c
index eefeafdfac..ace4c113c8 100644
--- a/tools/qt-faststart.c
+++ b/tools/qt-faststart.c
@@ -8,7 +8,7 @@
* is in front of the data, thus facilitating network streaming.
*
* To compile this program, start from the base directory from which you
- * are building Libav and type:
+ * are building FFmpeg and type:
* make tools/qt-faststart
* The qt-faststart program will be built in the tools/ directory. If you
* do not build the program in this manner, correct results are not
diff --git a/tools/trasher.c b/tools/trasher.c
index e099aa30d6..114eb78a68 100644
--- a/tools/trasher.c
+++ b/tools/trasher.c
@@ -1,20 +1,20 @@
/*
* Copyright (c) 2007 Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/tools/unwrap-diff b/tools/unwrap-diff
new file mode 100755
index 0000000000..ccea99b7b4
--- /dev/null
+++ b/tools/unwrap-diff
@@ -0,0 +1,2 @@
+#!/bin/sh
+tr '\n' '\001' | sed 's/\x01\x01/\x01 \x01/g' | sed 's/\x01\([^-+ @]\)/ \1/g' | tr '\001' '\n'
diff --git a/version.sh b/version.sh
index 6f72b2c2e6..8d084c2df3 100755
--- a/version.sh
+++ b/version.sh
@@ -1,11 +1,33 @@
#!/bin/sh
# check for git short hash
-revision=$(cd "$1" && git describe --always 2> /dev/null)
+if ! test "$revision"; then
+ revision=$(cd "$1" && git describe --tags --match N 2> /dev/null)
+fi
+
+# Shallow Git clones (--depth) do not have the N tag:
+# use 'git-YYYY-MM-DD-hhhhhhh'.
+test "$revision" || revision=$(cd "$1" &&
+ git log -1 --pretty=format:"git-%cd-%h" --date=short 2> /dev/null)
+
+# Snapshots from gitweb are in a directory called ffmpeg-hhhhhhh or
+# ffmpeg-HEAD-hhhhhhh.
+if [ -z "$revision" ]; then
+ srcdir=$(cd "$1" && pwd)
+ case "$srcdir" in
+ */ffmpeg-[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])
+ git_hash="${srcdir##*-}";;
+ */ffmpeg-HEAD-[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])
+ git_hash="${srcdir##*-}";;
+ esac
+fi
# no revision number found
test "$revision" || revision=$(cd "$1" && cat RELEASE 2> /dev/null)
+# Append the Git hash if we have one
+test "$revision" && test "$git_hash" && revision="$revision-$git_hash"
+
# releases extract the version number from the VERSION file
version=$(cd "$1" && cat VERSION 2> /dev/null)
test "$version" || version=$revision
@@ -17,7 +39,7 @@ if [ -z "$2" ]; then
exit
fi
-NEW_REVISION="#define LIBAV_VERSION \"$version\""
+NEW_REVISION="#define FFMPEG_VERSION \"$version\""
OLD_REVISION=$(cat version.h 2> /dev/null)
# Update version.h only on revision changes to avoid spurious rebuilds